Page 1 of 1

Storing and Controlling Actors

PostPosted: Fri Sep 18, 2009 6:26 pm
by DST
I am looking for more information about Actor*.

1st - can you store an actor permanently? If so, where would you store them?

2nd - can you store actors in an array? If so, is there any kind of vector or dynamic list class that can change sizes on the fly?

Re: Storing and Controlling Actors

PostPosted: Mon Sep 21, 2009 12:56 pm
by makslane
You can store the pointer to an actor, and you can use an array of pointers like:

Code: Select all
Actor **myactors;


But you need to control the allocation of the array:

Code: Select all
myactors = (Actor **)malloc(MAX_ACTORS*sizeof(Actor**));


Where MAX_ACTORS can be defined by you.
Other way is use some data struct, like a linked list to make more good use of the memory (you only alloc what you need).

In any case, you need to update the array when an actor is destroyed (In the Destroy Actor event).
You need to get a pointer to the event actor:

Code: Select all
Actor *eventActor = getclone(clone name of the event actor);


And update the array:

Code: Select all
RemoveActorFromMyArray(eventActor);


What you will do in the RemoveActorFromMyArray function depends of the data structure used.
If you have used an array, you need to scan the array until get a entry thats have the eventActor pointer and make this entry NULL.
If you have used a map (hash tables, ...) you can make this process faster!

Re: Storing and Controlling Actors

PostPosted: Tue Sep 22, 2009 12:20 am
by Bee-Ant
Umm,so one pointer for one actor?
What if we have 50x50 array?

Re: Storing and Controlling Actors

PostPosted: Tue Sep 22, 2009 12:27 pm
by makslane
One pointer array for all actors.