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 / Resource ID Management for Objects, Textures, Etc.

Author
Message
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 25th Oct 2016 14:39
When I started digging deeper with DBPro, the one thing I noticed is it is a bit hard to keep track with the object ID system which you would assign separately on objects, camera, textures and other stuff.

So I was wondering if there's an easy way to get around this. I found an old resource that sort of offers that functionality but it's now a broken link.

I would appreciate any info or tips on this part.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 25th Oct 2016 16:44 Edited at: 25th Oct 2016 16:58
Not built in, but Matrix 1 provides some useful commands to help:

find free object() /find free image() / find free {whatever}()

And

generate guid$()


I set up a custom media module that will handle locating an available resource number, determine if the object should be loaded, cloned, or instanced, or for images, if it is already loaded just return the existing image number, and will generate a guid string to identify it.

Basically, everything that is loaded gets tracked in media arrays storing file name, guid, object/image/sound etc number.

I then have getter functions which return a reference to the data along these lines:

Media_loadObject (filepath, canInstance)
Media_getObjectByID (guid)
Media_getObjectByNum (objNum)
Media_getObjectsByFile (filepath)
Media_replaceObject (oldguid, newFilepath)

The actual module/functions/data returns are a bit more detailed,but that should give you an idea of the work flow

Ideally, you should never need to know specifically what image number, object number etc a resource is using, just store them to more abstract variables and only worry aboot the actual value when viewing a log or debug output for trouble shooting


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Kuper
16
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 25th Oct 2016 18:12
@punkyb
maybe im wrong but this was called Darkdata plugin
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 25th Oct 2016 20:59
If you are looking to make sure you always get an available image/sprite/object/etc., I simply call a function to find the next one. CurrImage and CurrObj in the examples are globals, of course.




So many games to code.....so little time.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 25th Oct 2016 21:57
@Ortu

Thanks, I tried the Matrix1 find free and it's really handy. So my next problem is and I'm sure you already have this in your resource manager, how do you loop say a group of objects. Will it be slower since you have not keep track of it. Usually you jot down the range of a particular set say 10 to 20?

@Kuper

It looks more like a database type and perhaps I can't ask or use anything now that I cannot get hold of, which I'm thinking another discontinued product/plugin?
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 25th Oct 2016 22:13 Edited at: 25th Oct 2016 22:21
Nice solution there LBFN. I think I'll try this one out and see if it works out for me. Again, as I have asked Ortu about keeping track of ids, how do you query the range for say a particular set when reiterating through them? because it would be the same way that you'll have to look for the start id and end id range of a group.

I have used other basic compilers before and I'm wondering why FOR EACH is not included in the core language set, this would be critical for something like this since DBP supports TYPES, which I think goes hand in hand.



Maybe there's an alternative for DBP to manage or reiterate this? I would like to know the best approach.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 25th Oct 2016 22:30
So I found the closest thing, but it says it's slower than FOR LOOP



This would probably suffice but any other solutions?
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 26th Oct 2016 00:07
Next array index is indeed much slower, use

For i = 0 to array count (myArray ())
myArray (i)
Next i

You have to be careful with changing the size of the array with this method, I will flag indices for deletion then do a garbage collection afterwards.

When grouping things, id say don't group based on object numbers.

If you have a group of characters, group them in a characters array as a type of character, which includes object number or ID etc, during a character update, iterate the character array and you have access to each characters object through the character array data without needing to know anything about its object number.


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 26th Oct 2016 00:10
Ok thanks. So how do you iterate a group without knowing the object number? Can you give a simple example? because that's what I'm trying to find out in DBPro.

Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 26th Oct 2016 00:22 Edited at: 26th Oct 2016 01:41
Oops double post


A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 26th Oct 2016 01:09
Hey Ortu thanks, but I think you double posted your comment there. Anyway, I'm just gonna have a look at other snippets and see what's the most commonly used method.

If you still have some tips I'd appreciate it and would like to know.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 26th Oct 2016 02:27 Edited at: 26th Oct 2016 02:28
sorry about that, not sure what happened there.

Here, this isnt tested but should give you an idea of what I mean



A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 26th Oct 2016 11:45
Thanks Ortu!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 26th Oct 2016 12:06
I try to avoid those loop functions searching for IDs, since they can become a slowdown in certain situations, when a lot of different objects can be loaded.

To maintain control over the 'occupied' IDs, I use some basic algebra to ensure that the IDs are fixed and set at design time, something like this:



Use the multiply operation (Object ID * Vectorial Space) to obtain unique IDs (that is, generate an algebraic 'vector space'). An offset like for example, 1000+, can be used for obtaining the IDs of different types of objects and their textures.

That way I control all IDs being used all along the execution, and also I'm able to control them in an Excel spreadsheet.
For example, each time that a texture is missing, I know exactly which ID has not been loaded.

Just my way, maybe you find it interesting.

As a side comment, lower IDs seemed to perform better than higher ones, but I use offsets up to 800000 at DGDK and there is no performance hit so far.

punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 26th Oct 2016 12:28 Edited at: 26th Oct 2016 12:29
Ok, Thanks Morcilla. Good notes.

Login to post a reply

Server time is: 2024-04-18 03:19:56
Your offset time is: 2024-04-18 03:19:56