Paste will expire never.
- #pragma once
- #include "Helpers.h"
- namespace Core
- {
- #define NULL_PRIME_NAME "ERROR_NAME"
- #define NULL_PRIME_TYPE "ERROR_TYPE"
- #define NULL_PARENT_NAME "NO_PARENT"
- #define ROOT_PARENT_NAME "ROOT_PARENT" //using for disable subscribe
- class CoreExport SubscribeParams : virtual public Params
- {
- public:
- /*! name of parent essence */
- string parent;
- /*! if true, child receives parent's position */
- bool position;
- /*! if true, child receives parent's orientation */
- bool orientation;
- NEW_PARAMS(SubscribeParams)
- {
- REG_PARAMETER(parent, NULL_PARENT_NAME)
- REG_PARAMETER(position, true)
- REG_PARAMETER(orientation, true)
- }
- };
- class CoreExport PrimeParams : virtual public Params
- {
- public:
- /*! self name */
- string name;
- /*! self pantronymic */
- string pantronymic;
- /*! self type */
- string type;
- /*! self position */
- vector3 position;
- /*! self orientation */
- quaternion orientation;
- /*! true, if essence is dynamic */
- bool dynamic;
- /*! parent name, auto-subscribe at creation time, must be in location before */
- SubscribeParams subscribe_params;
- NEW_PARAMS(PrimeParams)
- {
- REG_PARAMETER(name,NULL_PRIME_NAME)
- REG_PARAMETER(pantronymic, NULL_STRING)
- REG_PARAMETER(type,NULL_PRIME_TYPE)
- REG_PARAMETER(position,vector3(0,0,0))
- REG_PARAMETER(orientation, quaternion(1,0,0,0))
- REG_PARAMETER(dynamic, true)
- REG_PARAMETER(subscribe_params)
- }
- };
- class CoreExport Prime : public ScriptRef
- {
- public:
- /*! level of name*/
- enum PrimeNameLevel
- {
- PNL_FULL, //FIRSTNAME + PANTRONYMIC
- PNL_FIRSTNAME,
- PNL_PANTRONYMIC
- };
- /*! constructor */
- Prime(PrimeParams*);
- /*! destructor */
- virtual ~Prime();
- /*! returns FULL name */
- const string& getName();
- /*! returns name by level */
- const string& getName(PrimeNameLevel level);
- /*! returns parent name */
- const string& getParentName();
- /*! returns type */
- const string& getType();
- /*! return current params */
- PrimeParams* getParams();
- /*! write full params string to log */
- void logParams();
- /*! simply update */
- virtual void update(float);
- /*! returns true if dynamic */
- bool isDynamic();
- /*! subscribe to essence (subscribe params in string) */
- void subscribe(const string& params);
- /*! subscribe to essence (subscribe params separated) */
- void subscribe(Prime* pr, bool position = true, bool orientation = true);
- /*! unsubscribe and clear offset */
- void unsubscribe();
- /*! returns true if subscribed */
- bool isSubscribed();
- /*! unsubscribe from existing parent and re-subscribe to location by position */
- void resubscribeToLocation();
- /*! prime vector define */
- typedef std::vector<Prime*> essence_vector;
- /*! return childs list */
- essence_vector getChilds();
- /*! sets position */
- virtual void setPosition(const vector3&);
- /*! return current position */
- virtual const vector3& getPosition();
- /*! sets orientation */
- virtual void setOrientation(const quaternion&);
- /*! return current orientation */
- virtual const quaternion& getOrientation();
- /*! sets offset position (using only if object is subscribed) */
- void setOffsetPosition(const vector3&);
- /*! return offset position (using only if object is subscribed) */
- const vector3& getOffsetPosition();
- /*! sets offset orientation (using only if object is subscribed) */
- void setOffsetOrientation(const quaternion&);
- /*! return offset orientation (using only if object is subscribed) */
- const quaternion& getOffsetOrientation();
- /*! sets global offset orientation (using only if object is subscribed) */
- void setGlobalOffsetOrientation(const quaternion&);
- /*! return global offset orientation (using only if object is subscribed) */
- const quaternion& getGlobalOffsetOrientation();
- /*! register essence in script, for taking effect function must be overloaded in derived essence,
- this function calls automatically with essence registration */
- static void registerInScript();
- protected:
- /*! self name */
- string mName;
- /*! all params - using for creating\saving\loading */
- PrimeParams* mParams;
- /*! parent (if it is subscribed) */
- Prime* mParent;
- /*! offset parent position */
- vector3 offset_position;
- /*! offset parent orientation */
- quaternion offset_orientation;
- /*! offset global orientation */
- quaternion offset_global_orientation;
- /*! recalculate offset position\orientation (using only if object is subscribed) */
- void recalculateOffset(vector3 self_pos, quaternion self_ori);
- private:
- /*! add child */
- void addChild(Prime*);
- /*! remove child */
- void removeChild(Prime*);
- /*! childs */
- essence_vector mChilds;
- };
- typedef Prime* (*createEssenceFunc)(const string&);
- template <typename E,typename P> Prime* createEssenceCreationFunc(const string& str)
- {
- return new E(new P(str));
- };
- };//namespace Core