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 Professional Discussion / Manage properties (physics, AI) using single UDT or use multiple UDTs with pointers?

Author
Message
pdq
19
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 29th Aug 2007 18:05 Edited at: 29th Aug 2007 18:07
I use Dark Physics and Dark AI. I am trying to figure out the best way to store and manage physics and AI properties. For example, is it better to store ALL properties in a single UDT. Or make separate UDTs(object, physics, AI) and then use pointers?

Below is a simple example. Which code - in the long run - will be better to use:



or



I know the first example is alot shorter; however, if I want the freedom to continue to add more and more properties and then manage them, which code would be the wisest choice?

THX
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Aug 2007 18:12
If you want multiple ships with the same Physics model, then you could normalise the data with multiple UDTs. But if you want even the slightest differences (which would add more realism and more randomness) then you would need to save each separately. Even then, it would be easier to create a generic Physics UDT that could be attached to different object types.

I don't think data size is an issue. It's more a case of ease-of-programming and readability.

pdq
19
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 29th Aug 2007 21:11 Edited at: 29th Aug 2007 21:17
Thanks BatVink for replying. Actually the "Object" UDT will be used for all game objects (decorations, bullets, vehicles, characters...)Each object will have a dboID (dark basics object ID)

The logic I am thinking about using is below:

Object -> DYNAMIC? -> YES
-> add to Update()
-> physics? -> yes -> add to Physics()
-> AI? -> yes -> add to AI()


-------------------------> NO
-> physics? -> yes -> static rigid body


---------> ANIMATION? -> YES
-> add to Animation()


The idea is that dynamic objects will access the Physics() array for data. If the object is AI controlled it will access the AI() array.

All dynamic objects are added to an Update() array.

This is the logic I think I am going to use instead of trying to store all the data under a single Object UDT, the object only accesses the other generic UDTs that applies to it (Physics(), AI(), Animation(), Light()...)

Any other thoughts you are anyone else has would be great!

And if anyone knows of any great threads or websites that discusses this approach as well as other approaches to program design would also be great!

THX
sp3ng
20
Years of Service
User Offline
Joined: 15th Jan 2006
Location:
Posted: 30th Aug 2007 10:42
you could also do this



Add Me
TinTin
20
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 30th Aug 2007 11:48
Yup I'd go with sp3ng on that one...

UDT's are the way to go...

Go Create...

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
pdq
19
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 30th Aug 2007 21:43
TinTin and sp3ng, I thought about doing what your saying; however, what I want to do is make a "generic" Object UDT. For example lets say that I am going to make two object classes a ship and a missile. The Ship will have both physics and AI where as the missile will only have physics.

Now I could:




Or I could:



Now during the game loop

For the ship:
Object(0).aiID -> AI()
Object(0).phyID -> Physics()

For the missile:
Object(1).phyID -> Physics()

The idea is that I am not limited to having to implicitly declare a ship or missile. But a declared Object can be anything and its behavior is simply defined by its physics and/or AI, of which the attributes (including its filename) can be imported by way of scripts and stored in physics() and AI().

Does any of what I am saying make sense?
TinTin
20
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 31st Aug 2007 13:16 Edited at: 31st Aug 2007 13:22
You could have an all singing and dancing super UDT that will hold every piece of info relating to any object in your game but, IMO, it's much easier to read Ship(1).PhyID than trying to figure out what Object(1).PhyID is halfway though a program.

Most people would have different UDT's for different types of objects, although these UDT's can have nested UDT's that are common.. (see below for a 3D point UDT)
Type tP3D
X as float
Y as float
Z as float
EndType
The above TYPE can be used to declare positions, angles, vectors etc... all in 3D. so...
Type tObj
Pos as tP3D
Ang as tP3D
Vec as tP3D
EndType
The difficult part is writing generic functions to fill/extract the data stored within the UDT's and the only limitation is the inability to have arrays in the UDT, (no Dim X(10) as integer etc.) which is a bummer.

Now if you intend nesting these UDT's for Physics, AI etc all in one super UDT, it would be wise to include a boolean value that gets set if that particular function is active. So if an object doesn't use AI then the AI.Active would be false and when your main loop processes this AI on all the objects the first thing it checks is to see if it's Active for the current object and exits if not.

It all makes sense, Everyone has different approaches and solutions to the same problems. It's best to take a path that you are most comfortable with and to addapt it to suit the application.

Hope this helps..

Go Create..

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
pdq
19
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 3rd Sep 2007 03:54
Thanks again TinTin.

Sorry I did not post earlier, I have been away this weekend.

I was planning on using boolean values - as you mentionesd - to set an object's AI and/or physics.

Quote: "
It's best to take a path that you are most comfortable with and to addapt it to suit the application.
"


Ands that is exactly my problem, I am trying to come up with a flexible programming solution that will allow me to build various types of games.

I think I am going to move on with this strategy.

Login to post a reply

Server time is: 2026-06-11 14:46:38
Your offset time is: 2026-06-11 14:46:38