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 / Managing U.D.T.s for size and speed of processing

Author
Message
Devonps
16
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 30th Aug 2011 15:12
I've come across a potential issue that I believe will slow my game down and would like some thoughts on how to manage it.

My game (a roguelike) creates effects that last many turns or are delayed for x turns then activate, for example damage over time. I currently manage these effects via a U.D.T. which has an element named TurnsRemaining.

Once the effect has expired (i.e. TurnsRemaining=0) I...well currently I don't do anything and that's my issue, I'm not sure how to manage the size of the U.D.T. array during the life span of the current game session.

How do I delete/remove an entry but still remain the integrity of the UDT/array? I'm concerned with blank entries within the array slowing the game down.

I should add that speed is my main concern here as the processing between each game turn should be as quick as possible.

Hope someone can help/advise me.

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
Mugen Wizardry
User Banned
Posted: 30th Aug 2011 15:16
Timer based movement for ALL speeds in the entire game, my friend =D

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Aug 2011 15:31
Timer based movement is not needed in a turn-based game.

@Devonps,
It depends on whether or not the place of the element in the array is important or not.

If not, then you can move the last item from the array into the expired slot, or delete the array item.

If it is important, then rather than automatically expanding the array, look for an expired array first.

TBH, it doesn't sound like your array will be growing very large if you reuse existing expired elements, so that will probably do the job.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Aug 2011 18:03
If you're going to delete an element only to recreate an element a bit later you probably shouldn't delete elements at all. Just pick a specific number of turns that will cover enough turns for your game and leave the array intact.

You may be doing this already but one of the cool commands in IanMs Matrix 1 Utilities Plugin that's perfect for what you're doing is the ROTATE ARRAY command. You can just focus on one element in the array and rotate the array as each turn is done.



If you don't already have IanMs Matrix 1 Utilities Plugin then you're not one of the cool kids... but you can join us cool kids right now by clicking on IanMs signature link above.

Devonps
16
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 30th Aug 2011 18:08
@IanM
Placement in the array is not important. What's important is to keep the processing as efficient as possible so having dead or inactive entries in the array will (to me) slow things down as the array grows.

I'm hoping to key everything on the ID element of the UDT rather than the array index so I think deleting the array item may be the most efficient way to move forward.

Quote: "TBH, it doesn't sound like your array will be growing very large if you reuse existing expired elements, so that will probably do the job."


Actually I'm not too sure of the final size of the array as I intend to have many different "over time" effects, e.g. time, weather, spell buffs/debuffs, food enhancements, and so on.

Thanks for the help/advice.

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
Devonps
16
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 30th Aug 2011 18:11
@Grog - seems our posts crossed. I have Ian's plug-ins but have never used the ROTATE ARRAY command, I'll have a look at it and see if it's what I need.

Thanks,

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Aug 2011 19:09 Edited at: 30th Aug 2011 19:26
What I mean by 'it doesn't sound like your array will be growing very large' is 'low thousands of items'.

ROTATE ARRAY is actually unnecessary in this instance - it's far too heavy-weight for what you really want, which is SWAP ARRAY ITEMS.

If you have a variable alongside your array that records the top item, then deleting an item from the array is equivalent to swapping that item with the top item, then decreasing the variable by 1 - that's faster than deleting from the array, or rotating everything down by 1.

Inserting an item then becomes an increment of the variable, then checking if the variable is beyond the end of the array. If this is the case, you then expand the array by a number of items (ARRAY INSERT AT BOTTOM array(), number_of_items). The variable now points at your newly allocated item which you can populate as needed.

You could also avoid the variable, as arrays (in their guise a lists) also have a 'current pointer'.

I don't know what this technique is called by everyone else, but I label it a 'combined in-use/free list'. I'll see if I can locate some example code.

[edit]
Example code here (using the 'current pointer'):


Bluespark
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 30th Aug 2011 22:51
Very nice!
Devonps
16
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 5th Sep 2011 10:57
Hi,

Thanks for the code - I'll hopefully get time to take a look this week.

Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!

Login to post a reply

Server time is: 2026-07-10 10:19:58
Your offset time is: 2026-07-10 10:19:58