Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / need help for creating a cell positioning system.

Author
Message
PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 24th Feb 2008 13:40 Edited at: 24th Feb 2008 13:41
I have a big terrain thats split into 136 objects (cells) as i like to call them. I have been trying to figure out of a good system to give each of these cells their unique position on the X,Z coordinate plane.

The best thing i came up with that works is just manually check if a certain cell exists and if it does, place it in a certain spot on the X,Z plane. And write the same procedure for each 136 cells. It Works but very inefficiently. If its looking for a cell thats in the end of the list, it will have to check many other objects before it gets to the one its looking for.

I have been trying to think of a good system and the best thing i Have is only a theory which i am not sure if its possible in DB.
The theory i have revolves around associating an object number with X,Z coordinates. After much pondering i figured this would work best if you one object would have 2 numbers to define it instead of one.

does anyone have any ideas that will point me in the right direction?

thanks

dont hate people who rip you off,cheat and get away with it, learn from them
Link102
21
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 24th Feb 2008 15:01
I'm not really sure what you want to do with this code. Do you want the player to find a certain object or just make a matrix filled with objects
if the latter, it's easy

this won't work, becouse you have to fill in the variables and the blanks

PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 24th Feb 2008 15:56 Edited at: 24th Feb 2008 16:11
the <object nr> in your code means object number right?


there is one more thing i need to know that will possibly help me with this problem.

is there a way to define an object before it exists? maybe like a variable that can be used to load an object?

[edit]

another question.
this probably wont work because i tried it already. object numbers cannot be negative right?

[edit2]
i want to explain in a more simple/broad way of what i am trying to do.

I have a big terrain that i split into 136 parts
based on the location of the player, the program needs to figure out which object (piece of the terrain) to load and where will it place the loaded object.

dont hate people who rip you off,cheat and get away with it, learn from them
Link102
21
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 24th Feb 2008 17:34
yes just replace <object nr> with "obj"

to see if an object already exists use "object exist()" in an if statement, you can find it in the help files under basic 3d

object numbers cannot be negative, they range from 1 to 65535

guessing from the 136 parts I reccon they are not square and ordered in a matrix fasion. I could give you some suggestions, but I wouln't know if it is the best to solve this problem. So if anyone else has a good solution...

PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 24th Feb 2008 21:23 Edited at: 24th Feb 2008 21:27
Quote: "guessing from the 136 parts I reccon they are not square and ordered in a matrix fasion. I could give you some suggestions, but I wouln't know if it is the best to solve this problem. So if anyone else has a good solution...
"


actually yes they are ordered. They are the whole thing is a big square area divided by 16x16 objects (i made a mistake earlier, 16x16 totals up to 256 objects that i should have).

i do not like calling it a matrix because they are actually .x meshes and i don't want to confuse myself or anyone else by making them think i use matrixes.

can object numbers be decimals?

dont hate people who rip you off,cheat and get away with it, learn from them
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2008 22:50 Edited at: 24th Feb 2008 22:53
Since the objects are positioned in a square it is easy to position them, the object number defines its position.

i.e. If you had a 10x10 square then objects 1 to 10 would be on line 0 and object 11 would be the first on line 1.

To position the objects in this autonomous fashion you need to define the width of your grid. Divide the object number by the width (returning an integer) and you'll get the row number for the object, subtract the object number from the row number (multiplied by the width) and you'll get it's column number.
You may have seen a problem here; because you can't have an object 0 the first object must be object 1, therefore the tenth object is object 10, which unfortunately is divisible by 10 and would be placed on row 1 instead of row 0. Don't worry about that, just remember to minus 1 from the object number before you work out the position, then you have objects "0-9" on the first row
Here's an example that better explains my gibberish


PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 24th Feb 2008 23:17
Thanks Obese, I actually had a concept similar to the one you explained to me I never got around to fully understanding since i gave up on it. The reason for this is I wanted to come up with something that has ability to place terrain in negative grid pieces as well so i will have room for possible expansion of my world later on. but i dont see how thats possible with this system. But if there is nothing i can do about it, i guess this would be a good system. I figured with this system i can stuff more room by moving the terrain over several thousand units.

dont hate people who rip you off,cheat and get away with it, learn from them
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Feb 2008 23:33
@Pagan
You could offset the grid to anywhere in 3D space, you could even duplicate the grid several times in different positions.

Did you understand my idea? I don't feel like I explained it too well.
The key is in the width and finding the Z position from it.

e.g.
width=10
15/10=1.5
1.5 as integer = 1
15 - 1*10 = 5

so object 15 is positioned at 10(row*width),5.

PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 24th Feb 2008 23:53
Yes, i understand, i have the same thing in mind. the problem with this is the terrain editor that use allows me to export large terrains in pieces. It automatically names each piece according to its coordinate. If i want to keep things organized i will have to rename each piece according to its new coordinate.

so if i have a 16x16 plane,i move it over to the right so i can put another 16x16 plane there. the older plane will need to be changed, so the old (1,1) area will now need to be changed to a (17,1) area since a new (1,1)area exists.

i am afraid i will need to go through every file and rename it.

dont hate people who rip you off,cheat and get away with it, learn from them
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Feb 2008 02:18
You wont need to rename files, just add in an offset in DB, all you have to do is offset when you position and offset when you are doing checks.

PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 25th Feb 2008 03:44
well, i guess you are right, i can offset the old map and load the pieces of a new map from a different folder,

will be tricky to keep track of since the files by default are named (when exported) as for eg area 1,1 and in the game offset its position to 1,17

dont hate people who rip you off,cheat and get away with it, learn from them
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Feb 2008 03:56 Edited at: 25th Feb 2008 03:57
Quote: "will be tricky to keep track of since the files by default are named (when exported) as for eg area 1,1"

ooh, didn't realise the files had 2D coordinate names.
If I were you I'd hard-code them in, if there's a lot you might have to rename unless you work out a clever way of doing it.

Renaming wouldn't be too hard, a bit of string manipulation and scaling on the Z co-ords.

PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 25th Feb 2008 04:33 Edited at: 25th Feb 2008 05:16
I knew it would come to strings, i hate strings.
i cam probably manage by loading each 16x16 landscape from a different folder, and offsetting it wherever i need and giving each object a different name.

[EDIT]

one more thing that i need to resolve. Thanks for the cube code Obese, Even though i had the general idea of this function, i just couldn't think of a mathematical procedure that you showed me (i am not good at algebra)

making computer cubes is one thing, but loading objects is another.

suppose the program knows that if object 134 exists, it needs to be placed at coordinates 4,5 (just an example) how will it know which one out of the 256 files to load and take place of object 134?

this one i seriously have no idea about. I will need some way to define objects or directories before they exist

object 134 = load object "game/data/cell(4,5).x"134

dont hate people who rip you off,cheat and get away with it, learn from them
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Feb 2008 07:57 Edited at: 25th Feb 2008 07:59
I don't understand why there would have to be any renaming. Aren't the grid squares always relative to each other? Isn't 1,1 always next to 2,1?

If all the grids are the same size, you only need to know the distance from the center of any given grid to either the grid above/below or right/left. Lets say you always have only 9 objects loaded at a time and you always start your player on the center grid of those 9. Let's say the player is moving in the +z direction (north we'll say). Once the player crosses the distance from the center of the current grid to the border of the north grid, hide or delete all three grids 2 squares south and load the next 3 grids north of the grid you just landed on. This always keeps a 3 by 3 area of terrain around the player. You do the same thing for going left or right. Like OBese said, you can place the grids anywhere in 3d space, their names shouldn't have anything to do with it, if anything they are helpful in determining which grids to load and delete.

In fact, once you reach an edge, the final tier in the terrain, you can wrap the terrain around using this method for an endless world.

Enjoy your day.
PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 25th Feb 2008 08:53 Edited at: 25th Feb 2008 09:04
@ latch

Great minds think alike man!
what you just said, is exactly what i am trying to accomplish.

about the renaming the terrain coordinates
because my terrain editor exports a terrain in pieces (divides it into 16x16 squares) by default it labels the exported .x files (on which the pieces of the terrain are stored). The names for each file are given according to the coordinates of the 16x16 grid on which the terrain was made, so eg: "area(3,5).x, area(2,1).x" The 256 files will e names from (1,1) to (16,16). This is very convenient at first since the filenames go together with where i am going to position the terrain grid in the game. But in case i decide to expand my world I will have to make another terrain 16x16 squares big, and they will have the same filenames as the first terrain i created. To keep better track if my terrain It would be better to rename the .x files according to where i will place them in the game. So if i already have a 16x16 terrain and want to add another one to the right of it, i will have to rename the file labeled (1,1) to (17,1) because in the game the area labeled (1,1) is actually placed in the area 17,1 of the games coordinate plane.

Don't get me started on the problems i will run into if i try to place terrain into negative spaces.

Quote: "object numbers cannot be negative, they range from 1 to 65535"


about the range of objects from 1 to 65535, thats not right. I just tested this theory by making an object number 9999999

any object under 7 digits is possible.

dont hate people who rip you off,cheat and get away with it, learn from them
Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 25th Feb 2008 10:59
Quote: "about the range of objects from 1 to 65535, thats not right. I just tested this theory by making an object number 9999999"

You must have magic powers then! What is the code you used to test this with?

Oh I see. I didn't understand the expansion part and all of the files would be named the same. If you try to write a second terrain of 16x16, does the program ask you if you want to replace the existing files or does it give you a save as option?

Well, if you store another set of grids in another directory, say direct1 is the first set, direct2 is the second set etc. , you can use a simple batch file to rename all of the files. Maybe you want to rename the next 16 grids on the east or right side of the last:

rename <path>\*.x *e.x

It will have the same convention (1,1) but will have the addition of an e so you know they go on the east side of the original set of grids: (1,1)e.x

A batch file is a text file that ends in .bat and runs DOS file commands. It's run just like an exe - by just executing the batch file.

Enjoy your day.
PAGAN_old
20
Years of Service
User Offline
Joined: 28th Jan 2006
Location: Capital of the Evil Empire
Posted: 25th Feb 2008 11:17
Quote: "You must have magic powers then! What is the code you used to test this with?"


well i used the the game i am working on right now. infact i just moved some of my objects such as player=object 1, sky=object 2 etc to objects like 9999999, 9999998 etc because i needed to free up objects 1-256 for the terrain

Quote: "If you try to write a second terrain of 16x16, does the program ask you if you want to replace the existing files or does it give you a save as option?"

save system works just like any other program the only difference is it adds the coordinates to the label. so if you name a new terrain the same name as the old one and export it to the same folder, you will overwrite it

Dude! a batch file, i would have never thought of that, thanks!

dont hate people who rip you off,cheat and get away with it, learn from them

Login to post a reply

Server time is: 2026-07-07 12:28:32
Your offset time is: 2026-07-07 12:28:32