The meat of ResourceManager
bjectManager has been completed. There are still some bugs, optimizations, and basic features to add/finish, but the most important code for ResourceManager
bjectManager has been finished. This code loads and organizes objects loaded into a game so you don't need to keep track of ID numbers used by DarkBasic to manipulate objects. When you need an object for use in the world, you just invoke the function AddWorldObject with the proper parameters and voila! you have an object set up in the world for your use. You can now reference this object by its unique name (the name you gave it when you invoked AddWorldObject) whenever you need to manipulate it.
In order to manipulate an object you would do something like the following:
position object NamedObjectId("testobject"), 100, 0, 42
Every time you need to use a DarkBasic command that requires one or more object IDs you use the function NamedObjectId to return the specified object's ID number. In the above example the object name is "testobject".
In the above screenshot we see a tank in the middle of a boulder strewn desert plain. There are about 80 boulders total in the scene, all placed and oriented randomly. The code I used to accomplish this is as follows:
for a = 1 to 80
xsgn = rnd(10)
zsgn = rnd(10)
xpos# = rnd(1000)
if xsgn < 5
xpos# = -xpos#
endif
zpos# = rnd(1000)
if zsgn < 5
zpos# = -zpos#
endif
yrot# = rnd(360)
AddWorldObject("Tank", "Buffalo Rock", "Buffalo Rock " + str$(a + 1), xpos#,0,zpos#,0,yrot#,0,0,0)
next a
Note that each boulder has the same name followed by a unique number. Whenever you need to manipulate a boulder, you would use its full name, such as "Buffalo Rock 51". When an object is added to the world ResourceManager checks to see if the object type you are requesting is already loaded into memory. If it isn't it loads it from disk and kept as a seperate "source object". Each time a new object of the same type is added to the world this source object is cloned and placed according to what was specified on invocation of AddWorldObject.
Again, this is just the SKELETON of what I am working on - some of the functions included in the code are not used in the example and/or are still being coded, and don't work properly when invoked. A lot of this code is also poorly organized and commented at the moment. I typed all this in a hurry so I'm sure there are things that are unclear.
I hope this code is useful to someone, and please give me your questions, comments or suggestions. Thanks for reading my spaghetti code!