Scene.pkg 4.7 KB

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