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 / Advice for Object Creation

Author
Message
Bulleyes
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 17th Dec 2002 06:46
Hi,

I came from a C++ background. Usually in C++, I manipulate the "dynamic" objects creation/destruction using NEW and DELETE operator. I just need to specifiy an object type (class), and it will return an instance reference to it.

I am wondering how DBpro programmer create object in their game dynamically. Unlike C++, DBpro create each object by specifiying a numerical reference; C++ return an object reference.

In C++, if there are number of objects of different type, I will just store it in several array with different type (class). The array is not restricted to a fixed size, it can "grow".

What I am currently do in DBpro initially is, whenever I want to create an object dynamically, I just create a FOR loop from 1 to 65535 and look for an empty slot using OBJECT EXIST command. Then I realize by using this, I have no way to identify the object type later, i.e. how do I know Object 1 is Enemy Ship A, Object 4 is Capital Ship #2, and so on.

Then I try a different approach. I allocate a range of numbers of each object type, i.e. 1 to 100 for Enemy type A, 110 to 200 to Ship Type B, and so on. Whenever I want to create a new ship in the game dynamically, I just go through the appropriate range depends on the type, and look for a empty slot by using OBJECT EXIST command.

How about you guys? How do you manage and manipulate your objects in your game via DBpro?

Thanks!
Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
Kangaroo2
21
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 17th Dec 2002 17:13
Normally in the kind of games I make, this isn't needed. But when it is I use a for next loop like you suggested and then set a variable so I know which object number it is. Or sometimes I get db to make a txt file on the hard drive and keep adding to it or reading to it.

I don't know if there's a more efficient way to do it, but it works for me

* If the apocalypse comes, email me *
UberTuba
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 17th Dec 2002 22:34
I would load all the ships i could need (100 say) and then store all the object data i need (frame angle pos,etc.)in an array,then check through it to see if the ships are not dead and then create and move each one i need from the 100 stored in memory.

Life is a terminal disease.
You never survive it.
Kangaroo2
21
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 18th Dec 2002 00:33
Yes so do I, I thought he was asking about the possibility of having an unspecified/unlimited (within the limit obv) number of objects

* If the apocalypse comes, email me *
Bulleyes
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Cyberjaya, Malaysia
Posted: 18th Dec 2002 05:25
in a way that is closer to OO manner, I am thinking of creating a structure that store all the object properties, e.g. speed, dead status, etc. including the object number, then declare the structure as an array.

What do u guys think about this approach?

Bad Nose Entertainment - Where games are forged from the flames of talent and passion.

http://www.badnose.com/
SonicBoom
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 18th Dec 2002 06:51
I use a global MasterObjNo(n) & MasterImageNo(n) array to allocate numbers, incrementing it each time I use it. If I need a "handle" back to the object later I have another Global array like PlayerObjNo(n), PlanesObjNo(n) etc which I assign at creation time.

With DB1 I'd create "objects" or types using 3d arrays, declaring constant global arrays like XPos(1), XVel(1) etc to use as properties. Something like this:
Player(PlayerObjNo(0), XPos(0)) = 15

Also means transfering all object data to the REAL objects:
Object position x(PlayerObjNo(0)) = Player(PlayerObjNo(0), XPos(0))

Of course using Types in DBPro makes it easier
Kangaroo2
21
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 18th Dec 2002 20:28
Yes that would do it

* If the apocalypse comes, email me *
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 19th Dec 2002 14:15
In my case i wish to be able to load several objects because i am creating an rts game. What i do is create a new type for each object that i need to use:

type unit

object as integer
blah blah
end type

so all the details about each unit could be stored in 1 variable or all the details about all of the units could be stored within 1 array.

If you forget one little thing i shall have you shaved sterilised and destroyed: Jeffrey Goines
Barliesque
21
Years of Service
User Offline
Joined: 10th Nov 2002
Location: Los Angeles
Posted: 20th Dec 2002 03:38
When assigning object numbers (or image/sound/memblock/etc. numbers) I use a simple library of functions I set up for myself, following this pattern:



Before you ask, I can no longer remember why I decided it was best to start at the maximum end of numbers and count backwards, but I'm sure I was being awfully clever.

Login to post a reply

Server time is: 2024-05-02 02:47:38
Your offset time is: 2024-05-02 02:47:38