v 0. Pasted by Anonymous as cpp at 2011-04-03 16:13:08 MSK and set expiration to never.

Paste will expire never.

  1. #pragma once
  2.  
  3.  
  4.  
  5. #include "Helpers.h"
  6.  
  7.  
  8.  
  9. namespace Core
  10.  
  11. {
  12.  
  13.  
  14.  
  15. #define NULL_PRIME_NAME   "ERROR_NAME"
  16.  
  17. #define NULL_PRIME_TYPE   "ERROR_TYPE"
  18.  
  19. #define NULL_PARENT_NAME  "NO_PARENT"
  20.  
  21. #define ROOT_PARENT_NAME  "ROOT_PARENT" //using for disable subscribe
  22.  
  23.  
  24.  
  25. class CoreExport SubscribeParams : virtual public Params
  26.  
  27. {
  28.  
  29. public:
  30.  
  31.     /*! name of parent essence */
  32.  
  33.     string parent;
  34.  
  35.  
  36.  
  37.     /*! if true, child receives parent's position */
  38.  
  39.     bool position;
  40.  
  41.  
  42.  
  43.     /*! if true, child receives parent's orientation */
  44.  
  45.     bool orientation;
  46.  
  47.  
  48.  
  49.     NEW_PARAMS(SubscribeParams)
  50.  
  51.     {
  52.  
  53.         REG_PARAMETER(parent, NULL_PARENT_NAME)
  54.  
  55.         REG_PARAMETER(position, true)
  56.  
  57.         REG_PARAMETER(orientation, true)
  58.  
  59.     }
  60.  
  61. };
  62.  
  63.  
  64.  
  65. class CoreExport PrimeParams : virtual public Params
  66.  
  67. {
  68.  
  69. public:
  70.  
  71.     /*! self name */
  72.  
  73.     string  name;
  74.  
  75.  
  76.  
  77.     /*! self pantronymic */
  78.  
  79.     string  pantronymic;
  80.  
  81.  
  82.  
  83.     /*! self type */
  84.  
  85.     string  type;
  86.  
  87.  
  88.  
  89.     /*! self position */
  90.  
  91.     vector3 position;
  92.  
  93.  
  94.  
  95.     /*! self orientation */
  96.  
  97.     quaternion  orientation;
  98.  
  99.  
  100.  
  101.     /*! true, if essence is dynamic */
  102.  
  103.     bool dynamic;
  104.  
  105.  
  106.  
  107.     /*! parent name, auto-subscribe at creation time, must be in location before */
  108.  
  109.     SubscribeParams subscribe_params;
  110.  
  111.  
  112.  
  113.     NEW_PARAMS(PrimeParams)
  114.  
  115.     {
  116.  
  117.         REG_PARAMETER(name,NULL_PRIME_NAME)
  118.  
  119.         REG_PARAMETER(pantronymic, NULL_STRING)
  120.  
  121.         REG_PARAMETER(type,NULL_PRIME_TYPE)
  122.  
  123.         REG_PARAMETER(position,vector3(0,0,0))
  124.  
  125.         REG_PARAMETER(orientation, quaternion(1,0,0,0))
  126.  
  127.         REG_PARAMETER(dynamic, true)
  128.  
  129.         REG_PARAMETER(subscribe_params)
  130.  
  131.     }
  132.  
  133. };
  134.  
  135.  
  136.  
  137. class CoreExport Prime : public ScriptRef
  138.  
  139. {
  140.  
  141. public:
  142.  
  143.     /*! level of name*/
  144.  
  145.     enum PrimeNameLevel
  146.  
  147.     {
  148.  
  149.         PNL_FULL, //FIRSTNAME + PANTRONYMIC
  150.  
  151.         PNL_FIRSTNAME,
  152.  
  153.         PNL_PANTRONYMIC
  154.  
  155.     };
  156.  
  157.  
  158.  
  159.     /*! constructor */
  160.  
  161.     Prime(PrimeParams*);
  162.  
  163.  
  164.  
  165.     /*! destructor */
  166.  
  167.     virtual ~Prime();
  168.  
  169.  
  170.  
  171.     /*! returns FULL name */
  172.  
  173.     const string& getName();
  174.  
  175.  
  176.  
  177.     /*! returns name by level */
  178.  
  179.     const string& getName(PrimeNameLevel level);
  180.  
  181.  
  182.  
  183.     /*! returns parent name */
  184.  
  185.     const string& getParentName();
  186.  
  187.  
  188.  
  189.     /*! returns type */
  190.  
  191.     const string& getType();
  192.  
  193.    
  194.  
  195.     /*! return current params */
  196.  
  197.     PrimeParams* getParams();
  198.  
  199.  
  200.  
  201.     /*! write full params string to log */
  202.  
  203.     void logParams();
  204.  
  205.  
  206.  
  207.     /*! simply update */
  208.  
  209.     virtual void update(float);
  210.  
  211.    
  212.  
  213.     /*! returns true if dynamic */
  214.  
  215.     bool isDynamic();
  216.  
  217.  
  218.  
  219.     /*! subscribe to essence (subscribe params in string) */
  220.  
  221.     void subscribe(const string& params);
  222.  
  223.  
  224.  
  225.     /*! subscribe to essence (subscribe params separated) */
  226.  
  227.     void subscribe(Prime* pr, bool position = true, bool orientation = true);
  228.  
  229.  
  230.  
  231.     /*! unsubscribe and clear offset */
  232.  
  233.     void unsubscribe();
  234.  
  235.    
  236.  
  237.     /*! returns true if subscribed */
  238.  
  239.     bool isSubscribed();
  240.  
  241.  
  242.  
  243.     /*! unsubscribe from existing parent and re-subscribe to location by position */
  244.  
  245.     void resubscribeToLocation();
  246.  
  247.  
  248.  
  249.     /*! prime vector define */
  250.  
  251.     typedef std::vector<Prime*> essence_vector;
  252.  
  253.  
  254.  
  255.     /*! return childs list */
  256.  
  257.     essence_vector getChilds();
  258.  
  259.  
  260.  
  261.     /*! sets position */
  262.  
  263.     virtual void setPosition(const vector3&);
  264.  
  265.  
  266.  
  267.     /*! return current position */
  268.  
  269.     virtual const vector3&  getPosition()
  270.  
  271.  
  272.  
  273.     /*! sets orientation */
  274.  
  275.     virtual void setOrientation(const quaternion&);
  276.  
  277.  
  278.  
  279.     /*! return current orientation */
  280.  
  281.     virtual const quaternion& getOrientation();
  282.  
  283.  
  284.  
  285.     /*! sets offset position (using only if object is subscribed) */
  286.  
  287.     void  setOffsetPosition(const vector3&);
  288.  
  289.  
  290.  
  291.     /*! return offset position (using only if object is subscribed) */
  292.  
  293.     const vector3& getOffsetPosition();
  294.  
  295.  
  296.  
  297.     /*! sets offset orientation (using only if object is subscribed) */
  298.  
  299.     void  setOffsetOrientation(const quaternion&);
  300.  
  301.  
  302.  
  303.     /*! return offset orientation (using only if object is subscribed) */
  304.  
  305.     const quaternion& getOffsetOrientation();
  306.  
  307.  
  308.  
  309.     /*! sets global offset orientation (using only if object is subscribed) */
  310.  
  311.     void  setGlobalOffsetOrientation(const quaternion&);
  312.  
  313.  
  314.  
  315.     /*! return global offset orientation (using only if object is subscribed) */
  316.  
  317.     const quaternion& getGlobalOffsetOrientation();
  318.  
  319.  
  320.  
  321.     /*! register essence in script, for taking effect function must be overloaded in derived essence,
  322.     this function calls automatically with essence registration */
  323.  
  324.     static void registerInScript();
  325.  
  326.  
  327.  
  328. protected:
  329.  
  330.     /*! self name */
  331.  
  332.     string mName;
  333.  
  334.  
  335.  
  336.     /*! all params - using for creating\saving\loading */
  337.  
  338.     PrimeParams* mParams;
  339.  
  340.  
  341.  
  342.     /*! parent (if it is subscribed) */
  343.  
  344.     Prime* mParent;
  345.  
  346.  
  347.  
  348.     /*! offset parent position */
  349.  
  350.     vector3    offset_position;
  351.  
  352.  
  353.  
  354.     /*! offset parent orientation */
  355.  
  356.     quaternion offset_orientation;
  357.  
  358.  
  359.  
  360.     /*! offset global orientation */
  361.  
  362.     quaternion offset_global_orientation;
  363.  
  364.  
  365.  
  366.     /*! recalculate offset position\orientation (using only if object is subscribed) */
  367.  
  368.     void recalculateOffset(vector3 self_pos, quaternion self_ori);
  369.  
  370.  
  371.  
  372. private:
  373.  
  374.     /*! add child */
  375.  
  376.     void addChild(Prime*);
  377.  
  378.  
  379.  
  380.     /*! remove child */
  381.  
  382.     void removeChild(Prime*);
  383.  
  384.  
  385.  
  386.     /*! childs */
  387.  
  388.     essence_vector mChilds;
  389.  
  390. };
  391.  
  392.  
  393.  
  394. typedef Prime* (*createEssenceFunc)(const string&);
  395.  
  396.  
  397.  
  398. template <typename E,typename P> Prime* createEssenceCreationFunc(const string& str)
  399.  
  400. {
  401.  
  402.     return new E(new P(str));
  403.  
  404. };
  405.  
  406.  
  407.  
  408. };//namespace Core
  409.