Bläddra i källkod

Add Animatable class.

aster2013 11 år sedan
förälder
incheckning
5fd7363201

+ 5 - 0
Source/Engine/LuaScript/pkgs/Scene/Animatable.pkg

@@ -0,0 +1,5 @@
+$#include "Animatable.h"
+
+class Animatable : Serializable
+{
+};

+ 1 - 1
Source/Engine/LuaScript/pkgs/Scene/Component.pkg

@@ -1,6 +1,6 @@
 $#include "Component.h"
 
-class Component : public Serializable
+class Component : public Animatable
 {
     void SetEnabled(bool enable);
     void Remove();

+ 1 - 0
Source/Engine/LuaScript/pkgs/SceneLuaAPI.pkg

@@ -1,4 +1,5 @@
 $pfile "Scene/Serializable.pkg"
+$pfile "Scene/Animatable.pkg"
 $pfile "Scene/Component.pkg"
 $pfile "Scene/Node.pkg"
 $pfile "Scene/Scene.pkg"

+ 1 - 1
Source/Engine/LuaScript/pkgs/UI/UIElement.pkg

@@ -56,7 +56,7 @@ static const unsigned DD_SOURCE;
 static const unsigned DD_TARGET;
 static const unsigned DD_SOURCE_AND_TARGET;
 
-class UIElement : public Serializable
+class UIElement : public Animatable
 {
     UIElement();
     virtual ~UIElement();

+ 40 - 0
Source/Engine/Scene/Animatable.cpp

@@ -0,0 +1,40 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "Precompiled.h"
+#include "Animatable.h"
+
+#include "DebugNew.h"
+
+namespace Urho3D
+{
+
+Animatable::Animatable(Context* context) :
+    Serializable(context)
+{
+}
+
+Animatable::~Animatable()
+{
+}
+
+}

+ 45 - 0
Source/Engine/Scene/Animatable.h

@@ -0,0 +1,45 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "Serializable.h"
+
+namespace Urho3D
+{
+
+class AttributeAnimation;
+class Scene;
+
+/// Base class for animatable object
+class URHO3D_API Animatable : public Serializable
+{
+    OBJECT(Animatable);
+
+public:
+    /// Construct.
+    Animatable(Context* context);
+    /// Destruct.
+    virtual ~Animatable();
+};
+
+}

+ 4 - 4
Source/Engine/Scene/Component.cpp

@@ -33,7 +33,7 @@ namespace Urho3D
 {
 
 Component::Component(Context* context) :
-    Serializable(context),
+    Animatable(context),
     node_(0),
     id_(0),
     networkUpdate_(false),
@@ -47,7 +47,7 @@ Component::~Component()
 
 void Component::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 {
-    Serializable::OnSetAttribute(attr, src);
+    Animatable::OnSetAttribute(attr, src);
     MarkNetworkUpdate();
 }
 
@@ -60,7 +60,7 @@ bool Component::Save(Serializer& dest) const
         return false;
 
     // Write attributes
-    return Serializable::Save(dest);
+    return Animatable::Save(dest);
 }
 
 bool Component::SaveXML(XMLElement& dest) const
@@ -72,7 +72,7 @@ bool Component::SaveXML(XMLElement& dest) const
         return false;
 
     // Write attributes
-    return Serializable::SaveXML(dest);
+    return Animatable::SaveXML(dest);
 }
 
 void Component::SetEnabled(bool enable)

+ 2 - 2
Source/Engine/Scene/Component.h

@@ -22,7 +22,7 @@
 
 #pragma once
 
-#include "Serializable.h"
+#include "Animatable.h"
 
 namespace Urho3D
 {
@@ -34,7 +34,7 @@ class Scene;
 struct ComponentReplicationState;
 
 /// Base class for components. Components can be created to scene nodes.
-class URHO3D_API Component : public Serializable
+class URHO3D_API Component : public Animatable
 {
     OBJECT(Component);
     BASEOBJECT(Component);

+ 6 - 6
Source/Engine/Scene/Node.cpp

@@ -39,7 +39,7 @@ namespace Urho3D
 {
 
 Node::Node(Context* context) :
-    Serializable(context),
+    Animatable(context),
     worldTransform_(Matrix3x4::IDENTITY),
     dirty_(false),
     networkUpdate_(false),
@@ -82,7 +82,7 @@ void Node::RegisterObject(Context* context)
 
 void Node::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 {
-    Serializable::OnSetAttribute(attr, src);
+    Animatable::OnSetAttribute(attr, src);
     MarkNetworkUpdate();
 }
 
@@ -112,7 +112,7 @@ bool Node::Save(Serializer& dest) const
         return false;
 
     // Write attributes
-    if (!Serializable::Save(dest))
+    if (!Animatable::Save(dest))
         return false;
 
     // Write components
@@ -172,7 +172,7 @@ bool Node::SaveXML(XMLElement& dest) const
         return false;
 
     // Write attributes
-    if (!Serializable::SaveXML(dest))
+    if (!Animatable::SaveXML(dest))
         return false;
 
     // Write components
@@ -1136,7 +1136,7 @@ bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren
     RemoveAllComponents();
 
     // ID has been read at the parent level
-    if (!Serializable::Load(source))
+    if (!Animatable::Load(source))
         return false;
 
     unsigned numComponents = source.ReadVLE();
@@ -1179,7 +1179,7 @@ bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readC
     RemoveAllChildren();
     RemoveAllComponents();
 
-    if (!Serializable::LoadXML(source))
+    if (!Animatable::LoadXML(source))
         return false;
 
     XMLElement compElem = source.GetChild("component");

+ 2 - 2
Source/Engine/Scene/Node.h

@@ -23,7 +23,7 @@
 #pragma once
 
 #include "Matrix3x4.h"
-#include "Serializable.h"
+#include "Animatable.h"
 #include "VectorBuffer.h"
 
 namespace Urho3D
@@ -52,7 +52,7 @@ enum TransformSpace
 };
 
 /// %Scene node that may contain components and child nodes.
-class URHO3D_API Node : public Serializable
+class URHO3D_API Node : public Animatable
 {
     OBJECT(Node);
     BASEOBJECT(Node);

+ 10 - 3
Source/Engine/Script/APITemplates.h

@@ -446,10 +446,17 @@ template <class T> void RegisterSerializable(asIScriptEngine* engine, const char
     RegisterSubclass<Object, T>(engine, "Serializable", className);
 }
 
+/// Template function for registering a class derived from Animatable.
+template <class T> void RegisterAnimatable(asIScriptEngine* engine, const char* className)
+{
+    RegisterSerializable<T>(engine, className);
+    RegisterSubclass<Object, T>(engine, "Animatable", className);
+}
+
 /// Template function for registering a class derived from Component.
 template <class T> void RegisterComponent(asIScriptEngine* engine, const char* className, bool nodeRegistered = true, bool debugRendererRegistered = true)
 {
-    RegisterSerializable<T>(engine, className);
+    RegisterAnimatable<T>(engine, className);
     RegisterSubclass<Component, T>(engine, "Component", className);
     engine->RegisterObjectMethod(className, "void Remove()", asMETHODPR(T, Remove, (), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void MarkNetworkUpdate() const", asMETHODPR(T, MarkNetworkUpdate, (), void), asCALL_THISCALL);
@@ -589,7 +596,7 @@ static VariantMap& NodeGetVars(Node* ptr)
 /// Template function for registering a class derived from Node.
 template <class T> void RegisterNode(asIScriptEngine* engine, const char* className)
 {
-    RegisterSerializable<T>(engine, className);
+    RegisterAnimatable<T>(engine, className);
     RegisterSubclass<Node, T>(engine, "Node", className);
     engine->RegisterObjectMethod(className, "void SetScale(float)", asMETHODPR(T, SetScale, (float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetTransform(const Vector3&in, const Quaternion&in)", asMETHODPR(T, SetTransform, (const Vector3&, const Quaternion&), void), asCALL_THISCALL);
@@ -895,7 +902,7 @@ static XMLFile* UIElementGetDefaultStyle(UIElement* ptr)
 /// Template function for registering a class derived from UIElement.
 template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* className, bool isSprite = false)
 {
-    RegisterSerializable<T>(engine, className);
+    RegisterAnimatable<T>(engine, className);
     RegisterObjectConstructor<T>(engine, className);
     RegisterNamedObjectConstructor<T>(engine, className);
     RegisterSubclass<UIElement, T>(engine, "UIElement", className);

+ 7 - 0
Source/Engine/Script/SceneAPI.cpp

@@ -22,6 +22,7 @@
 
 #include "Precompiled.h"
 #include "APITemplates.h"
+#include "Animatable.h"
 #include "DebugRenderer.h"
 #include "PackageFile.h"
 #include "Scene.h"
@@ -46,6 +47,11 @@ static void RegisterSerializable(asIScriptEngine* engine)
     RegisterSerializable<Serializable>(engine, "Serializable");
 }
 
+static void RegisterAnimatable(asIScriptEngine* engine)
+{
+    RegisterAnimatable<Animatable>(engine, "Animatable");
+}
+
 static bool NodeSaveXML(File* file, Node* ptr)
 {
     if (file)
@@ -260,6 +266,7 @@ static void RegisterScene(asIScriptEngine* engine)
 void RegisterSceneAPI(asIScriptEngine* engine)
 {
     RegisterSerializable(engine);
+    RegisterAnimatable(engine);
     RegisterNode(engine);
     RegisterSmoothedTransform(engine);
     RegisterSplinePath(engine);

+ 3 - 3
Source/Engine/UI/UIElement.cpp

@@ -108,7 +108,7 @@ template<> LayoutMode Variant::Get<LayoutMode>() const
 XPathQuery UIElement::styleXPathQuery_("/elements/element[@type=$typeName]", "typeName:String");
 
 UIElement::UIElement(Context* context) :
-    Serializable(context),
+    Animatable(context),
     parent_(0),
     clipBorder_(IntRect::ZERO),
     priority_(0),
@@ -245,7 +245,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
     }
 
     // Then load rest of the attributes from the source
-    if (!Serializable::LoadXML(source, setInstanceDefault))
+    if (!Animatable::LoadXML(source, setInstanceDefault))
         return false;
 
     unsigned nextInternalChild = 0;
@@ -350,7 +350,7 @@ bool UIElement::SaveXML(XMLElement& dest) const
     }
 
     // Write attributes
-    if (!Serializable::SaveXML(dest))
+    if (!Animatable::SaveXML(dest))
         return false;
 
     // Write child elements

+ 2 - 2
Source/Engine/UI/UIElement.h

@@ -22,7 +22,7 @@
 
 #pragma once
 
-#include "Serializable.h"
+#include "Animatable.h"
 #include "UIBatch.h"
 #include "Vector2.h"
 #include "XMLFile.h"
@@ -111,7 +111,7 @@ class Cursor;
 class ResourceCache;
 
 /// Base class for %UI elements.
-class URHO3D_API UIElement : public Serializable
+class URHO3D_API UIElement : public Animatable
 {
     OBJECT(UIElement);
     BASEOBJECT(UIElement);