Scene.pkg 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. $#include "Scene.h"
  2. static const unsigned FIRST_REPLICATED_ID;
  3. static const unsigned LAST_REPLICATED_ID;
  4. static const unsigned FIRST_LOCAL_ID;
  5. static const unsigned LAST_LOCAL_ID;
  6. /// Root scene node, represents the whole scene.
  7. class Scene : public Node
  8. {
  9. public:
  10. /// Construct.
  11. Scene(Context* context);
  12. /// Destruct.
  13. virtual ~Scene();
  14. /// Load from a binary file asynchronously. Return true if started successfully.
  15. bool LoadAsync(File* file);
  16. /// Load from an XML file asynchronously. Return true if started successfully.
  17. bool LoadAsyncXML(File* file);
  18. /// Stop asynchronous loading.
  19. void StopAsyncLoading();
  20. /// Clear.
  21. void Clear();
  22. /// Enable or disable scene update.
  23. void SetUpdateEnabled(bool enable);
  24. /// Set update time scale. 1.0 = real time (default.)
  25. void SetTimeScale(float scale);
  26. /// Set elapsed time in seconds. This can be used to prevent inaccuracy in the timer if the scene runs for a long time.
  27. void SetElapsedTime(float time);
  28. /// Set network client motion smoothing constant.
  29. void SetSmoothingConstant(float constant);
  30. /// Set network client motion smoothing snap threshold.
  31. void SetSnapThreshold(float threshold);
  32. /// Return node from the whole scene by ID, or null if not found.
  33. Node* GetNode(unsigned id) const;
  34. /// Return component from the whole scene by ID, or null if not found.
  35. Component* GetComponent(unsigned id) const;
  36. /// Return whether updates are enabled.
  37. bool IsUpdateEnabled() const { return updateEnabled_; }
  38. /// Return asynchronous loading flag.
  39. bool IsAsyncLoading() const { return asyncLoading_; }
  40. /// Return asynchronous loading progress between 0.0 and 1.0, or 1.0 if not in progress.
  41. float GetAsyncProgress() const;
  42. /// Return source file name.
  43. const String& GetFileName() const { return fileName_; }
  44. /// Return source file checksum.
  45. unsigned GetChecksum() const { return checksum_; }
  46. /// Return update time scale.
  47. float GetTimeScale() const { return timeScale_; }
  48. /// Return elapsed time in seconds.
  49. float GetElapsedTime() const { return elapsedTime_; }
  50. /// Return motion smoothing constant.
  51. float GetSmoothingConstant() const { return smoothingConstant_; }
  52. /// Return motion smoothing snap threshold.
  53. float GetSnapThreshold() const { return snapThreshold_; }
  54. /// Return a node user variable name, or empty if not registered.
  55. const String& GetVarName(ShortStringHash hash) const;
  56. /// Update scene. Called by HandleUpdate.
  57. void Update(float timeStep);
  58. /// Begin a threaded update. During threaded update components can choose to delay dirty processing.
  59. void BeginThreadedUpdate();
  60. /// End a threaded update. Notify components that marked themselves for delayed dirty processing.
  61. void EndThreadedUpdate();
  62. /// Add a component to the delayed dirty notify queue. Is thread-safe.
  63. void DelayedMarkedDirty(Component* component);
  64. /// Return threaded update flag.
  65. bool IsThreadedUpdate() const { return threadedUpdate_; }
  66. /// Get free node ID, either non-local or local.
  67. unsigned GetFreeNodeID(CreateMode mode);
  68. /// Get free component ID, either non-local or local.
  69. unsigned GetFreeComponentID(CreateMode mode);
  70. /// Node added. Assign scene pointer and add to ID map.
  71. void NodeAdded(Node* node);
  72. /// Node removed. Remove from ID map.
  73. void NodeRemoved(Node* node);
  74. /// Component added. Add to ID map.
  75. void ComponentAdded(Component* component);
  76. /// Component removed. Remove from ID map.
  77. void ComponentRemoved(Component* component);
  78. /// Set node user variable reverse mappings.
  79. void SetVarNamesAttr(String value);
  80. /// Return node user variable reverse mappings.
  81. String GetVarNamesAttr() const;
  82. /// Prepare network update by comparing attributes and marking replication states dirty as necessary.
  83. void PrepareNetworkUpdate();
  84. /// Clean up all references to a network connection that is about to be removed.
  85. void CleanupConnection(Connection* connection);
  86. /// Mark a node for attribute check on the next network update.
  87. void MarkNetworkUpdate(Node* node);
  88. /// Mark a comoponent for attribute check on the next network update.
  89. void MarkNetworkUpdate(Component* component);
  90. /// Mark a node dirty in scene replication states. The node does not need to have own replication state yet.
  91. void MarkReplicationDirty(Node* node);
  92. };
  93. Scene* NewScene(Context* context);
  94. void Delete(Scene* scene);
  95. ${
  96. static Scene* NewScene(Context* context)
  97. {
  98. return new Scene(context);
  99. }
  100. static void Delete(Scene* scene)
  101. {
  102. delete scene;
  103. }
  104. $}