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.

Newcomers DBPro Corner / Creating an array of 3d objects.

Author
Message
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 9th Oct 2008 07:00
I want to create an array of references to my 3d objects, so that I can store "levels", or "lists" if you will, of the objects for loading and saving, collision checks, physics, and so on.

However, none of the Load Object or Make Object Box commands pass back any values, meaning the following won't work:



Surely there is a way to "sort" my objects into several array or lists so I can seperate the player objects from the ground in the levels when I loop through objects? Currently I only know of the DB object id numbers, which don't help seperate them into types. Also, I'm pretty sure the id numbers don't go into infinity, thus in a game where objects can dissapear or come back(like an editor, for example), constantly calling higher ids for creating objects will eventually crash the system, won't it?

Basically, I'd like to load and edit objects using an "Object Based" system of editing, while keeping things like the player, camera, and projectiles seperate from the level objects themselves. Surely there is a way to do this?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Oct 2008 11:00
Put your object numbers in a typed array, along with any other information you want to store about them.

Quote: "Also, I'm pretty sure the id numbers don't go into infinity, thus in a game where objects can dissapear or come back(like an editor, for example), constantly calling higher ids for creating objects will eventually crash the system, won't it?"

It's up to you to manage the object IDs. Alternatively, use IanM's FIND FREE OBJECT() command in the Matrix1 Utils DLLs

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 9th Oct 2008 16:51 Edited at: 9th Oct 2008 16:56
Or you can write your own free object function like this:



Then store the object number returned by the function in your array.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Oct 2008 19:51
We've all seen that code many times before.

Cash had another method where he doesn't reuse object id's, but simply continues counting ever upwards (and also as 300happy was alluding to).

However, I've just written a piece of code that times all three methods:


On my machine, sixty's code is the slowest, and gets worse as the number of objects increases. Cash's code stays constant, but of course doesn't reuse object ids. My code stays constant and does reuse object ids.

The slight shocker is that my function is on average, fastest - I expected mine to be slightly slower than cash's.
Quote: "
Surely there is a way to "sort" my objects into several array or lists so I can seperate the player objects from the ground in the levels when I loop through objects?"

Yes, in the same plug-in that provides the FIND FREE OBJECT function, there's additional functionality to assign objects to different groups, and to loop through them. You can see a small example of this in the code I posted which loops through all objects:


The code to loop through an object group is identical, except for using the FIRST OBJECT IN GROUP/NEXT OBJECT IN GROUP functions.

300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 10th Oct 2008 04:34
Err, you all lost me. Which isn't hard to do.

All this code does is store a seperate array of id numbers, right?

What I am trying to do is come up with a way to store the physical 3d objects in an array object. Umm, that made no sense...let me see if I can rephrase it.

Here we have my array object:

LevelArray

Inside the array object I want to store the bricks/decor/floors/walls/ect of a level. So if I made a wall, I'd store the object, or whatever memory reference dbpro is using to store all it's values for where and what the object looks like, inside my array, like so:

LevelArray(1[or any number]) = The 3d object in memory.

That way, to save the whole level, I can simply dump the array to a file, and to restore it, I can load the file back into the array. Doing so would also restore the 3d objects to the world, in theory, since it's all just objects in an array anyway.

Err, right?

From what you are telling me, it sounds like DBpro can't store it's 3d object type inside arrays, even though they all clearly have ids and such like normal array entries. If so...this is going to get way too messy.

Then again, it's all geek to me.

What I am trying to do is get a system of level storage like what Super Mario 64 uses. SM64 stores each level as a list of objects, that's why each spinning platform or falling block looks the same in game, because they actually are all just number X object as far as the physics and code is concerned. This system makes designing new levels and areas much less memory intensive, because instead of modeling the whole physical level, the designers simply store "lists" of objects needed to build the level. Instructions for assembly, if you will.

Of course, this is only helpful if I can somehow actually store the physical 3d objects properties in the array in the first place. If I have to make my own types just to fill the array with the object's properties DBpro is storing, I might as well be coding all the 3d object physics and display code from scratch. It doesn't make sense to store the numbers/values for each object twice in memory if only one is visible anyway.

Maybe I'm just too confused by all this code stuff. I just don't understand why I need all the above just to store an object that is already in DBpro's 3d memory space in an array instead of in DBpro's raw id values.

Is there a tutorial on how to go about making a basic 3d platformer, you know, with basic collision, camera, and level pickups that can easily be placed instead of being hard coded into the system? Every tutorial I've found has either had the level prebuilt(with no interactivity), or built hard coded into the app. It's really hard to grasp how to build a system for a 3d platforming game without any examples.

I took the fps tutorial in the book, but it didn't really help explain things, as my outcome had certain differences to what the tutorial said should happen. (my player is like, an inch high, for example, and I still have no idea how to spawn multiple objects, as the example only allows one bullet and such.)

Sorry for rambling, it's just I've been at this for over two months now and still have not been able to code even a simple grid based FPS game control without getting rather unhelpful "Invalid code" errors, and the documentation isn't very clear on how to use the commands together. It tells what the command does, but not how to use them with others, except for it's rather bloated examples that do something with random values or whatever(they don't explain any of the stuff that is actually running them, so I don't know how it's supposed to help with the commands themselves.)

In flash actionscript, I can declare an array and store movie clip objects inside that array, creating and deleting them as needed, and then by deleating the whole array I can clear all of the movie clips out of memory as well. I guess I just don't understand what's different with the DBpro arrays, or why the creating object commands don't actually pass back the object they just spawned to anywhere.
pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 10th Oct 2008 10:37 Edited at: 10th Oct 2008 10:42
I suppose that you understand DBP programming.
I say, and you read a source code.
A source code is a document of a programmer.
-
Do you know "TRosettaStone"?
It is a book explaining the inside of TombRaider.
You must make a book similar to this.
-
Do you have a good example of DBP?
You read a code of "Dark AI 3D Demo".
And read a source code of FPSC.
These explain how to write code to you.
-
Do you want to know how to make maps?
Read a gameFx command in help file of U70.
There says it about how to make FPSC maps, a door, portal, many rooms.
-
I pray for your good luck.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Oct 2008 11:52
@300happy,
An object is an object, not a variable that can be stored in an array. You provide it with a handle (which is just a number), and it will then use that number to refer to the internal data related to that object. If you lose track of the number, DBPro won't run around after you and garbage collect the object - it will just stay where you last placed it in the world.

The reason I raised the object grouping stuff in the plug-in was that you can use this to aid you. For example, you can load your walls, floors and other immovable stuff and assign them all to a group. You can then load interactive objects and assign them to another group.

You can record the objects filename during load time - these can be implemented either using array (object number as the array index), by storing the filename in the limb name of limb 0 on the object, or even by lookup table (those last two can be done using more of my plug-ins).

To save, you can open a file, loop through the objects in the immovable object group and write their filenames, positions and rotations to the file. You can loop through the interactive objects and write their properties to the file. Loading is the same in reverse - open the file read through the file loading the objects and their properties as you go.

Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 10th Oct 2008 12:19
I followed the level editor tutorial for the Bruce Lee game in one of the newletters and did something very similar in my level editor.

I choose which object I want to place, click on the screen to place it, and store the X,Y,Z location, as well as a number that represents what type of object it is (tree, house, tank and so-on) to an array.

I then loop through the array and write all the details into a file. When I read the file in I look at the object type field to decide what to do with the object when I load it up.
Would be simple enough to add a group descriptor as well of 'non-destructible scenary', 'destructable sceneary' and 'enemy'.
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 10th Oct 2008 21:49
Ok, so it sounds like I need to create a system of functions that manage a seperate array of stuff, and then build a level out of that data using a "build level" function.

I'm still not sure what the difference is between the 3d physical objects and variables. I mean, DB has to have the object stored in some kind of variable, otherwise the object id wouldn't work in the first place. But whatever, maybe DB's internal stuff can't be accessed by my compiled code or it's memory is seperated or some big heady answer like that. O_o

On a totally unrelated note, how do I use plugins for DBpro, and where do I get them/set them up? I've never tried using a plug in before, and the documentation doesn't say anything from what I can find in the manual. -_-

It looks like I'll need to code a couple template projects before making anything playable, since every project I have on paper will need this object handling code. (They all are different games, but generally need a 3d world stored and sorted by objects instead of models)

pcRaider: Where can I get or view the source to FPSC? I don't want to buy it since I won't be using it for anything(none of my projects are FPS, or grid based, or even use FPS cameras, so it would be extremely clunky at best.). Is there a similar system I can look at?

I'll try my hand at getting some sort of editor system up and running over the next few days(probably just storing and loading cubes would be a great start). I've got a lot of other things going on(including a commercial game in flash, thus my knowledge of actionscript), so I only have about an hour a day at most to learn DBpro. Which is probably part of why I'm so confused, since most of that time is spent looking over the user manual and getting lost in the differences between Basic and Actionscript.
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 10th Oct 2008 22:53
Huzza! After some major tweaking, I have gotten a basic 3d screen with a wireframe "cursor" controlled along four axis(haven't thought of controls for the other axis yet). I can use this object to place objects in the level.

I'm now trying to figure out a way to display stuff on top of the 3d window. I need to basically make a HUD of some sort, with things like the current tool, position in 3d space, you know, useful numbers so the editor isn't so mysterious floaty like.

Only, the print text commands don't work well over a 3d window, and look like a mess anyway. So I'm stuck again at another mental blockade.

How would you people make a quick but functional display of data/changing numbers in the 3d window? I basically need a concept or some commands to start working with, as I have no clue where to begin or what works(evidently the print command doesn't, and there's no notes in the manual about how to get around the problem, they just assume you already know other ways to display text).
Bursar
16
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 11th Oct 2008 00:06 Edited at: 11th Oct 2008 00:07
Two options that I can think of. One is to use Draw Sprites Last and a bitmap font (try Scraggle's to start with), the other is write your text to the screen, capture it, and then use it to texture a plain which you put on the screen as a standard 3D object. I won't pretend to know to do the capturing bit though.
300happy
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Indiana, USA
Posted: 11th Oct 2008 04:18
I'll probably use the bitmap font option then. I don't see any use for 3d sprites anyway, since I can just use a double sided polygon with transparent texture for any "prop" or "explosion" effects. Such a setting will help later when I'm making the game pause menus anyway.

I have been trying to download Scraggle's text tutorial, but the zip file I keep getting from the server is 0k in size and invalid(not that I'm surprised with that size reading). I don't think the site is working.

I've got a busy weekend, so chances are I won't be able to touch this till next monday anyway. I'll catch up on everyone's posts then.

Login to post a reply

Server time is: 2024-11-25 16:38:20
Your offset time is: 2024-11-25 16:38:20