AnoPlib - Animlets are not Particles library
|
Template-based realisation of the AnoPsystemBase. More...
#include <AnoP.h>
Public Member Functions | |
void | addAnimlet (T &animlet) throw () |
Adds an animlet to the list of those to render. | |
AnoPsystem (unsigned int bufSize=10) throw () | |
Constructor. | |
void | renderAll (unsigned int timeDiff, void *const something) |
Renders all stored animlets, passing the given values to these. | |
~AnoPsystem () throw () | |
Destructor. | |
Methods to override by realisation | |
virtual void | preRender () throw () |
Called before rendering the stored animlets. | |
virtual void | postRender () throw () |
Called after rendering the stored animlets. | |
virtual bool | render (T &which, unsigned int timeDiff, void *const something) throw () |
Called for rendering a single animlet. | |
virtual bool | deleteAnimlet (T &which) throw () |
Animlet deletion callback. | |
Protected Attributes | |
T * | myAnimletBuffer |
The allocated animlets. | |
unsigned int | myAnimletNumber |
The number of currently running animlets. | |
unsigned int | myBufferSize |
The number of allocated animlets. |
Template-based realisation of the AnoPsystemBase.
AnoP::AnoPsystem< T >::AnoPsystem | ( | unsigned int | bufSize = 10 | ) | throw () [inline] |
Constructor.
[in] | bufSize | The initial buffer size |
Definition at line 68 of file AnoP.h.
: myAnimletNumber(0), myBufferSize(bufSize), myAnimletBuffer(new T[bufSize]) { }
AnoP::AnoPsystem< T >::~AnoPsystem | ( | ) | throw () [inline] |
void AnoP::AnoPsystem< T >::addAnimlet | ( | T & | animlet | ) | throw () [inline] |
Adds an animlet to the list of those to render.
animlet The animlet to add
Definition at line 112 of file AnoP.h.
Referenced by main().
{ if(myAnimletNumber==myBufferSize) { int add = 10; T *newBuffer = new T[myBufferSize+add]; memcpy(newBuffer, myAnimletBuffer, sizeof(T)*myBufferSize); std::swap(myAnimletBuffer, newBuffer); myBufferSize += add; delete[] newBuffer; } myAnimletBuffer[myAnimletNumber] = animlet; ++myAnimletNumber; }
virtual bool AnoP::AnoPsystem< T >::deleteAnimlet | ( | T & | which | ) | throw () [inline, virtual] |
Animlet deletion callback.
If this callback returns true, the animlet is removed from the list of animlets to render. In the case any memory shall be freed, this method is reponsible for doing this.
Nonetheless, there may be some reason for not deleting the animlet but reinitialise it. This can be done in this method, too. false should be returned then, so that the animlet stays in the list of animlets to render.
[in] | which | The animlet to delete |
Definition at line 171 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::renderAll().
{ return true; }
virtual void AnoP::AnoPsystem< T >::postRender | ( | ) | throw () [inline, virtual] |
Called after rendering the stored animlets.
This method is meant to do any kind of cleaning up; does nothing per default.
Definition at line 142 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::renderAll().
{}
virtual void AnoP::AnoPsystem< T >::preRender | ( | ) | throw () [inline, virtual] |
Called before rendering the stored animlets.
This method is meant to do any kind of initialisation; does nothing per default.
Reimplemented in AnoPemergency1, AnoPflashlight1, AnoPwavelogo1, AnoPwavepropagation1, AnoPstarfield1, and AnoPtentacle1.
Definition at line 134 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::renderAll().
{}
virtual bool AnoP::AnoPsystem< T >::render | ( | T & | which, |
unsigned int | timeDiff, | ||
void *const | something | ||
) | throw () [inline, virtual] |
Called for rendering a single animlet.
This method should do the rendering/animation and return whether the animlet shall be kept (true) or not (false).
[in] | which | The animlet to render |
[in] | timeDiff | The time since last call |
[in] | something | Something else |
Reimplemented in AnoPemergency1, AnoPflashlight1, AnoPtentacle1, AnoPwavelogo1, AnoPstarfield1, and AnoPwavepropagation1.
Definition at line 155 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::renderAll().
{ return false; }
void AnoP::AnoPsystem< T >::renderAll | ( | unsigned int | timeDiff, |
void *const | something | ||
) | [inline, virtual] |
Renders all stored animlets, passing the given values to these.
At first "preRender" is called.
Then, for each stored animlet the "render" method is called, passing the current animlet, the given time since last call, and the given additional data. In the case "render" returns false, "deleteAnimlet" is called. If "deleteAnimlet" returns true, the animlet is removed.
At the end "postRender" is called.
[in] | timeDiff | Assumed to be the time since last call |
[in] | something | Further thing that will be passed during the rendering |
Implements AnoP::AnoPsystemBase.
Definition at line 91 of file AnoP.h.
{ preRender(); for(unsigned int i=0; i<myAnimletNumber; ) { T &animlet = myAnimletBuffer[i]; if(render(animlet, timeDiff, something)) { ++i; continue; } // animlet dies... if(deleteAnimlet(animlet)) { myAnimletBuffer[i] = myAnimletBuffer[myAnimletNumber-1]; --myAnimletNumber; } } postRender(); }
T* AnoP::AnoPsystem< T >::myAnimletBuffer [protected] |
The allocated animlets.
Definition at line 183 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::addAnimlet(), and AnoP::AnoPsystem< wireless1Struct >::renderAll().
unsigned int AnoP::AnoPsystem< T >::myAnimletNumber [protected] |
The number of currently running animlets.
Definition at line 177 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::addAnimlet(), and AnoP::AnoPsystem< wireless1Struct >::renderAll().
unsigned int AnoP::AnoPsystem< T >::myBufferSize [protected] |
The number of allocated animlets.
Definition at line 180 of file AnoP.h.
Referenced by AnoP::AnoPsystem< wireless1Struct >::addAnimlet().