Archived

This topic is now archived and is closed to further replies.

good way to handle complex DMA

This topic is 5129 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I want to make a simple effects handling thing for this one console project (that will later be ported onto a 2d tile based game). Basically there''s a struct like struct effect { short type; short color; BYTE direction; int duration; }; something like that, and basically I want a way to be able to dynamically allocate effects without leaving holes. Like for example 10 effects are running, then effect 7 finishes, and it is removed, and all the effects after it are moved back one. Is there a convienient way to do this or I am going to have to code it all from scratch? I mean I know how to go about doing it with a class, but I dont want to recode something

Share this post


Link to post
Share on other sites
Dear Drekkar

What you seem to need is a stack where you can push and pop elements.
But if get it right:
What you want to do is remove the unused from memory ? And this is a realtime thing ?
Well, doing many changes to memory (deallocating and allocating) is, in my oppinion, not a good idea. That takes time.

What I usually do is, that I make a list that allocated at creation. This may make sense:

struct ListEntry
{
float Data;
bool InUse;
};

class TheList
{
ListEntry *m_pList;
int m_ListSize;

TheList() //Constructor:
{
m_pList = 0;
m_ListSize = 0;
};

void Create(int NumberOfEntries)
{
if(m_pList!=0)
{
delete m_pList;
m_pList = 0;
}

m_pList = new ListEntry[NumberOfEntries];
m_ListSize = NumberOfEntries;
}
}


I hope it makes sense.
This sollution always works for me. It´s fast and does not use much memory. It´s easy to find am entry to add data to: Simply just search through untill there pops up an entry that´s not in use.

Tue

Share this post


Link to post
Share on other sites