Procházet zdrojové kódy

Added ID code to binary scenes.
Re-added application post-update event. Currently used by UI.

Lasse Öörni před 14 roky
rodič
revize
74993d525e

+ 6 - 0
Engine/Core/CoreEvents.h

@@ -38,6 +38,12 @@ EVENT(E_UPDATE, Update)
     PARAM(P_TIMESTEP, TimeStep);          // float
 }
 
+/// Application-wide logic post-update event
+EVENT(E_POSTUPDATE, PostUpdate)
+{
+    PARAM(P_TIMESTEP, TimeStep);          // float
+}
+
 /// Render update event
 EVENT(E_RENDERUPDATE, RenderUpdate)
 {

+ 3 - 0
Engine/Core/Timer.cpp

@@ -83,6 +83,9 @@ void Time::BeginFrame(unsigned mSec)
         eventData[P_TIMESTEP] = timeStep_;
         SendEvent(E_UPDATE, eventData);
         
+        // Logic post-update event
+        SendEvent(E_POSTUPDATE, eventData);
+        
         // Rendering update event
         SendEvent(E_RENDERUPDATE, eventData);
         

+ 20 - 0
Engine/Scene/Scene.cpp

@@ -26,6 +26,7 @@
 #include "Context.h"
 #include "CoreEvents.h"
 #include "File.h"
+#include "Log.h"
 #include "Profiler.h"
 #include "Scene.h"
 #include "SceneEvents.h"
@@ -60,6 +61,13 @@ void Scene::RegisterObject(Context* context)
 
 bool Scene::Load(Deserializer& source)
 {
+    // Check ID
+    if (source.ReadID() != "USCN")
+    {
+        LOGERROR(source.GetName() + " is not a valid scene file");
+        return false;
+    }
+    
     // Load the whole scene, then perform post-load if successfully loaded
     /// \todo Async loading support
     if (Node::Load(source))
@@ -71,6 +79,18 @@ bool Scene::Load(Deserializer& source)
         return false;
 }
 
+bool Scene::Save(Serializer& dest)
+{
+    // Write ID first
+    if (!dest.WriteID("USCN"))
+    {
+        LOGERROR("Could not save scene, writing to stream failed");
+        return false;
+    }
+    
+    return Node::Save(dest);
+}
+
 bool Scene::LoadXML(const XMLElement& source)
 {
     // Load the whole scene, then perform post-load if successfully loaded

+ 2 - 0
Engine/Scene/Scene.h

@@ -42,6 +42,8 @@ public:
     
     /// Load from binary data. Return true if successful
     virtual bool Load(Deserializer& source);
+    /// Save to binary data. Return true if successful
+    virtual bool Save(Serializer& dest);
     /// Load from XML data. Return true if successful
     virtual bool LoadXML(const XMLElement& source);
     

+ 3 - 3
Engine/UI/UI.cpp

@@ -75,7 +75,7 @@ UI::UI(Context* context) :
     SubscribeToEvent(E_MOUSEWHEEL, HANDLER(UI, HandleMouseWheel));
     SubscribeToEvent(E_KEYDOWN, HANDLER(UI, HandleKeyDown));
     SubscribeToEvent(E_CHAR, HANDLER(UI, HandleChar));
-    SubscribeToEvent(E_UPDATE, HANDLER(UI, HandleUpdate));
+    SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate));
     SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate));
     
     // Try to initialize right now, but skip if screen mode is not yet set
@@ -774,11 +774,11 @@ void UI::HandleChar(StringHash eventType, VariantMap& eventData)
         element->OnChar(eventData[P_CHAR].GetInt(), mouseButtons_, qualifiers_);
 }
 
-void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
+void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
 {
     if (initialized_)
     {
-        using namespace Update;
+        using namespace PostUpdate;
         
         Update(eventData[P_TIMESTEP].GetFloat());
     }

+ 5 - 5
Engine/UI/UI.h

@@ -51,9 +51,9 @@ public:
     void SetFocusElement(UIElement* element);
     /// Clear the UI (excluding the cursor)
     void Clear();
-    /// Update the UI logic. Called by handleUpdate()
+    /// Update the UI logic. Called by HandlePostUpdate()
     void Update(float timeStep);
-    /// Update the UI for rendering. Called by handleRenderUpdate()
+    /// Update the UI for rendering. Called by HandlePostRenderUpdate()
     void RenderUpdate();
     /// Render the UI
     void Render();
@@ -82,7 +82,7 @@ public:
 private:
     /// Initialize when screen mode initially set
     void Initialize();
-    /// Update UI elements and generate batches for UI rendering
+    /// Update UI element logic recursively
     void Update(float timeStep, UIElement* element);
     /// Generate batches from an UI element recursively
     void GetBatches(UIElement* element, IntRect currentScissor);
@@ -104,8 +104,8 @@ private:
     void HandleKeyDown(StringHash eventType, VariantMap& eventData);
     /// Handle character event
     void HandleChar(StringHash eventType, VariantMap& eventData);
-    /// Handle logic update event
-    void HandleUpdate(StringHash eventType, VariantMap& eventData);
+    /// Handle logic post-update event
+    void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
     /// Handle render update event
     void HandleRenderUpdate(StringHash eventType, VariantMap& eventData);