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.

Code Snippets / [DBP] Arrays in Types

Author
Message
Mr Kohlenstoff
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 3rd Dec 2007 18:17 Edited at: 3rd Dec 2007 19:20
Hello...

I'm not sure if something like this has been posted before, but I couldn't find anything apart from tons of "Is it possible to make Arrays in Types??"-Threads.
Today I wrote some functions to create something like "virtual static arrays" or so, so arrays with fixed size, atm. just for integer-values. It is of course slower than the dbp-array-commands. Without debugging it is ~4 times slower (With debugging ~15 times slower, but release-versions usually shouldn't need debugging-stuff like this..), so needs e.g. 40ms instead of 10 for a million array-changes, but it's still much faster than using strings.
I'm not sure if it's faster than using another array for additional information, which was what I have done always before, but at least it should be much easier.

Before I post the functions a small description how it works:

You can create an array with "va_MakeArray(Element_Count)". The function will use free memory to store elements 0 to Element_Count as integers (so in fact (Elemnent_Count+1)*4 bytes). Also the function returns a handle which represents the array you just created. So the biggest difference from DBP-Arrays is, that they don't have a name, but an ID.
You can change an array-element by using "va_Set(ArrayID,Element,Value)". Use "va_Value(ArrayID,Element)" to get an array-value.
Arrays can be deleted with "va_DeleteArray(ArrayID)".
After an array is created it's values aren't changed, so they seem very random. To change that use va_ClearArray(ArrayID), which sets all values to 0, or va_FillArray(ArrayID,Value), which overwrites all elements with 'Value'.

Functions:





Small example:



Comments appreciated.. have fun.

Btw.. you might use it in your project, would be kind if you mentioned my name, but you don't have to.. were just 10 minutes of work.


Edit: I didn't post an example of 'Arrays in types', but will do as soon as I've written one.

Edit2: Here's the new example. It doesn't really do anything useful but shows how the method works.



TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 3rd Dec 2007 19:47
Mr Kohlenstoff I commend your effort, however, could you not achieve the same function with a multidimensional array?



Login to post a reply

Server time is: 2024-11-22 13:16:06
Your offset time is: 2024-11-22 13:16:06