AnoPlib - Animlets are not Particles library
 All Data Structures Namespaces Files Functions Variables
AnoP::AnoPsystem< T > Class Template Reference

Template-based realisation of the AnoPsystemBase. More...

#include <AnoP.h>

Inheritance diagram for AnoP::AnoPsystem< T >:
AnoP::AnoPsystemBase

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.

Detailed Description

template<class T>
class AnoP::AnoPsystem< T >

Template-based realisation of the AnoPsystemBase.

Definition at line 63 of file AnoP.h.


Constructor & Destructor Documentation

template<class T>
AnoP::AnoPsystem< T >::AnoPsystem ( unsigned int  bufSize = 10) throw () [inline]

Constructor.

Parameters:
[in]bufSizeThe initial buffer size

Definition at line 68 of file AnoP.h.

                                                    :
            myAnimletNumber(0), myBufferSize(bufSize), myAnimletBuffer(new T[bufSize])
            { }
template<class T>
AnoP::AnoPsystem< T >::~AnoPsystem ( ) throw () [inline]

Destructor.

Definition at line 74 of file AnoP.h.

{ }

Member Function Documentation

template<class T>
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;
        }
template<class T>
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.

Parameters:
[in]whichThe animlet to delete

Definition at line 171 of file AnoP.h.

Referenced by AnoP::AnoPsystem< wireless1Struct >::renderAll().

{ return true; }
template<class T>
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().

{}
template<class T>
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().

{}
template<class T>
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).

Parameters:
[in]whichThe animlet to render
[in]timeDiffThe time since last call
[in]somethingSomething else
Returns:
Whether the animlet shall be kept

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; }
template<class T>
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.

Parameters:
[in]timeDiffAssumed to be the time since last call
[in]somethingFurther 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();
        }

Field Documentation

template<class T>
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().

template<class T>
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().

template<class T>
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().


The documentation for this class was generated from the following file: