Object.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /******************************************************************************
  2. Use 'Object' to create custom object templates in the Editor.
  3. They will be used for creation of the actual game objects 'Game.Obj'.
  4. /******************************************************************************/
  5. #if EE_PRIVATE
  6. enum OBJ_FLAG // Object Flag
  7. {
  8. OBJ_OVR_SCALE =1<<0, // override default scale
  9. OBJ_OVR_MESH =1<<1, // override default mesh
  10. OBJ_OVR_MESH_VARIATION=1<<2, // override default mesh variation
  11. OBJ_OVR_ALIGN =1<<3, // override default align
  12. OBJ_OVR_PHYS =1<<4, // override default phys
  13. OBJ_OVR_TYPE =1<<5, // override default type
  14. OBJ_OVR_ACCESS =1<<6, // override default access mode
  15. OBJ_OVR_PATH =1<<7, // override default path
  16. OBJ_OVR_CONST =1<<8, // override default const
  17. OBJ_CONST =1<<9, // const
  18. };
  19. #endif
  20. enum OBJ_ACCESS : Byte // object access mode
  21. {
  22. OBJ_ACCESS_CUSTOM , // object can be accessed and modified during the game any modifications will be saved in SaveGame, this is suited for all dynamic objects which require custom class
  23. OBJ_ACCESS_TERRAIN, // object can't be accessed, it will be embedded into the terrain and rendered as static mesh , this is suited for all static objects which don't require custom class, these objects are managed completely by the engine
  24. OBJ_ACCESS_GRASS , // works like OBJ_ACCESS_TERRAIN however it is optimized for instanced grass rendering, additionaly objects of this mode can be controlled by D.grass methods
  25. OBJ_ACCESS_OVERLAY, // works like OBJ_ACCESS_TERRAIN however it will generate a mesh overlay on the terrain using objects material
  26. OBJ_ACCESS_NUM , // number of access modes
  27. };
  28. enum OBJ_PATH : Byte // object path mesh mode
  29. {
  30. OBJ_PATH_CREATE, // create path mesh from this object
  31. OBJ_PATH_IGNORE, // don't create path mesh from this object
  32. OBJ_PATH_BLOCK , // fully block path mesh from this object
  33. OBJ_PATH_NUM , // number of path modes
  34. };
  35. /******************************************************************************/
  36. DECLARE_CACHE(Object, Objects, ObjectPtr); // 'Objects' cache storing 'Object' objects which can be accessed by 'ObjectPtr' pointer
  37. /******************************************************************************/
  38. struct Object // Object Parameters - they're created in the Editor and are used for creating typical Game Objects 'Game.Obj'
  39. {
  40. // members
  41. Matrix matrix ; // matrix, its scale determines object's scale
  42. Memc<Param> params ; // parameters
  43. Memc<Object> sub_objs; // sub-objects
  44. // manage
  45. Object& del ( ); // delete manually
  46. Object& create(C Object &src); // create from 'src'
  47. // get / set
  48. Matrix matrixFinal()C; // get final matrix ('matrix' adjusted by 'align'), its scale determines object's scale
  49. Vec centerFinal()C; // get final matrix center
  50. ObjectPtr firstStored( ) ; // get first object (starting from self to its all bases) which is stored in the cache (which means that it's a project element and not dynamically created), this will iterate through object and all of its bases and return the first one which is stored in the cache, null on fail
  51. Bool hasBase (C UID &base_id)C; // check if this object or one of its bases have 'base_id' base
  52. void base ( C ObjectPtr &base ); C ObjectPtr & base ()C {return _base ;} // set/get base object
  53. void type (Bool custom, C UID &type =UIDZero ); C UID & type ()C {return _type ;} // set/get object type (OBJ_TYPE 'ObjType' enum element ID), 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to false then base value will be used)
  54. void access (Bool custom, OBJ_ACCESS access=OBJ_ACCESS_TERRAIN); OBJ_ACCESS access ()C {return _access ;} // set/get object access mode (OBJ_ACCESS ), 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to false then base value will be used)
  55. void path (Bool custom, OBJ_PATH path =OBJ_PATH_CREATE ); OBJ_PATH path ()C {return _path ;} // set/get object path mode (OBJ_PATH ), 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to false then base value will be used)
  56. void mesh (Bool custom, C MeshPtr &mesh =null ); C MeshPtr & mesh ()C {return _mesh ;} // set/get mesh , 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to false then base value will be used)
  57. void meshVariationID(Bool custom, UInt id =0 ); UInt meshVariationID ()C {return _mesh_variation_id;} // set/get mesh variation ID , 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to false then base value will be used), based on this value, 'meshVariationIndex' can be obtained. This ID is the unique ID of the mesh variation - 'Mesh.variationID'. It should not be passed to the 'SetVariation' function, instead please use 'meshVariationIndex' for that.
  58. Int meshVariationIndex()C; // get mesh variation index based on variation ID , you can use this index for 'SetVariation' function before drawing the mesh
  59. void phys (Bool custom, C PhysBodyPtr &phys =null ); C PhysBodyPtr& phys ()C {return _phys ;} // set/get physical body , 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to then false base value will be used)
  60. void constant (Bool custom, Bool on =false ); Bool constant ()C; // set/get object constant mode , 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to then false base value will be used), this is special modifier for OBJ_ACCESS_CUSTOM access specifying that the object is always constant (never changes) and should not be saved in SaveGame, but should always created as new object from its default parameters (this reduces SaveGame size)
  61. void scale (Bool custom, C Vec &scale =1 ); Flt scale ()C; // set/get object scale , 'custom'=if override base defaults and set custom value (when set to true then custom value will be used, if set to then false base value will be used)
  62. Vec scale3 ()C; // get object scale in 3 dimensions
  63. Bool customType ()C; // if this object uses custom type (if 'custom' was set to true when setting the value)
  64. Bool customAccess ()C; // if this object uses custom access (if 'custom' was set to true when setting the value)
  65. Bool customPath ()C; // if this object uses custom path (if 'custom' was set to true when setting the value)
  66. Bool customMesh ()C; // if this object uses custom mesh (if 'custom' was set to true when setting the value)
  67. Bool customMeshVariation ()C; // if this object uses custom mesh variation (if 'custom' was set to true when setting the value)
  68. Bool customMeshVariationAny()C; // if this object or any of its bases use custom mesh variation (if 'custom' was set to true when setting the value)
  69. Bool customPhys ()C; // if this object uses custom phys (if 'custom' was set to true when setting the value)
  70. Bool customConstant ()C; // if this object uses custom constant (if 'custom' was set to true when setting the value)
  71. Bool customScale ()C; // if this object uses custom scale (if 'custom' was set to true when setting the value)
  72. Bool customAlign ()C; // if this object uses custom align (if 'custom' was set to true when setting the value)
  73. // params
  74. Param * findParam (C Str &name) ; // find parameter by name, first local parameters are searched, if not found then bases are searched recursively, null on fail !! each objects parameters are required to be sorted according to their name !!
  75. C Param * findParam (C Str &name)C; // find parameter by name, first local parameters are searched, if not found then bases are searched recursively, null on fail !! each objects parameters are required to be sorted according to their name !!
  76. Param & getParam (C Str &name) ; // get parameter by name, first local parameters are searched, if not found then bases are searched recursively, Exit on fail !! each objects parameters are required to be sorted according to their name !!
  77. C Param & getParam (C Str &name)C; // get parameter by name, first local parameters are searched, if not found then bases are searched recursively, Exit on fail !! each objects parameters are required to be sorted according to their name !!
  78. Object& sortParams( ) ; // sort parameters according to their names, this needs to be called after manual adding/removing custom parameters (this is needed for using 'findParam getParam' methods which assume that parameters are sorted)
  79. // alignment
  80. ALIGN_TYPE alignX()C; // get x alignment
  81. ALIGN_TYPE alignY()C; // get y alignment
  82. ALIGN_TYPE alignZ()C; // get z alignment
  83. void align (Bool custom, ALIGN_TYPE x=ALIGN_NONE, ALIGN_TYPE y=ALIGN_NONE, ALIGN_TYPE z=ALIGN_NONE); // set alignment
  84. // operations
  85. Object& updateBase(); // update members according to base (you should call this if base members were changed)
  86. #if EE_PRIVATE
  87. Object& updateBaseSelf(); // update members according to base (of self only, without sub objects)
  88. #endif
  89. // io
  90. Bool save(C Str &name)C; // save, false on fail
  91. Bool load(C Str &name) ; // load, false on fail
  92. Bool save(File &f, CChar *path=null)C; // save, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  93. Bool load(File &f, CChar *path=null) ; // load, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  94. #if EE_PRIVATE
  95. Bool saveData(File &f, CChar *path=null)C; // save, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  96. Bool loadData(File &f, CChar *path=null) ; // load, 'path'=path at which resource is located (this is needed so that the sub-resources can be accessed with relative path), false on fail
  97. void zero();
  98. #endif
  99. // compare
  100. Bool operator==(C Object &obj)C; // if equal
  101. Bool operator!=(C Object &obj)C {return !(T==obj);} // if not equal
  102. Object();
  103. #if !EE_PRIVATE
  104. private:
  105. #endif
  106. UShort _flag;
  107. Byte _align;
  108. OBJ_ACCESS _access;
  109. OBJ_PATH _path;
  110. UID _type;
  111. ObjectPtr _base;
  112. MeshPtr _mesh;
  113. UInt _mesh_variation_id;
  114. PhysBodyPtr _phys;
  115. };
  116. /******************************************************************************/
  117. extern Enum ObjType; // OBJ_TYPE enum responsible for object type management
  118. /******************************************************************************/
  119. #if EE_PRIVATE
  120. void ShutObj();
  121. #endif
  122. /******************************************************************************/