Josh Engebretson 10 vuotta sitten
vanhempi
sitoutus
46fe3060a6
100 muutettua tiedostoa jossa 1191 lisäystä ja 793 poistoa
  1. 14 1
      Resources/CoreData/Shaders/GLSL/FXAA3.glsl
  2. 2 0
      Resources/CoreData/Shaders/GLSL/Samplers.glsl
  3. 2 2
      Resources/CoreData/Shaders/GLSL/TerrainBlend.glsl
  4. 13 12
      Script/TypeScript/Atomic.d.ts
  5. 16 22
      Source/Atomic/Atomic2D/AnimatedSprite2D.cpp
  6. 8 4
      Source/Atomic/Atomic2D/AnimatedSprite2D.h
  7. 17 16
      Source/Atomic/Atomic2D/Animation2D.cpp
  8. 10 5
      Source/Atomic/Atomic2D/Animation2D.h
  9. 13 12
      Source/Atomic/Atomic2D/AnimationSet2D.cpp
  10. 2 2
      Source/Atomic/Atomic2D/AnimationSet2D.h
  11. 5 9
      Source/Atomic/Atomic2D/Atomic2D.cpp
  12. 1 1
      Source/Atomic/Atomic2D/Atomic2D.h
  13. 3 2
      Source/Atomic/Atomic2D/CollisionBox2D.cpp
  14. 4 2
      Source/Atomic/Atomic2D/CollisionBox2D.h
  15. 5 4
      Source/Atomic/Atomic2D/CollisionChain2D.cpp
  16. 6 2
      Source/Atomic/Atomic2D/CollisionChain2D.h
  17. 3 2
      Source/Atomic/Atomic2D/CollisionCircle2D.cpp
  18. 3 2
      Source/Atomic/Atomic2D/CollisionCircle2D.h
  19. 3 3
      Source/Atomic/Atomic2D/CollisionEdge2D.cpp
  20. 3 2
      Source/Atomic/Atomic2D/CollisionEdge2D.h
  21. 6 5
      Source/Atomic/Atomic2D/CollisionPolygon2D.cpp
  22. 4 2
      Source/Atomic/Atomic2D/CollisionPolygon2D.h
  23. 13 12
      Source/Atomic/Atomic2D/CollisionShape2D.cpp
  24. 12 4
      Source/Atomic/Atomic2D/CollisionShape2D.h
  25. 11 7
      Source/Atomic/Atomic2D/Constraint2D.cpp
  26. 8 2
      Source/Atomic/Atomic2D/Constraint2D.h
  27. 5 4
      Source/Atomic/Atomic2D/ConstraintDistance2D.cpp
  28. 5 2
      Source/Atomic/Atomic2D/ConstraintDistance2D.h
  29. 6 5
      Source/Atomic/Atomic2D/ConstraintFriction2D.cpp
  30. 4 2
      Source/Atomic/Atomic2D/ConstraintFriction2D.h
  31. 5 4
      Source/Atomic/Atomic2D/ConstraintGear2D.cpp
  32. 4 2
      Source/Atomic/Atomic2D/ConstraintGear2D.h
  33. 6 5
      Source/Atomic/Atomic2D/ConstraintMotor2D.cpp
  34. 6 2
      Source/Atomic/Atomic2D/ConstraintMotor2D.h
  35. 4 3
      Source/Atomic/Atomic2D/ConstraintMouse2D.cpp
  36. 6 3
      Source/Atomic/Atomic2D/ConstraintMouse2D.h
  37. 7 5
      Source/Atomic/Atomic2D/ConstraintPrismatic2D.cpp
  38. 9 2
      Source/Atomic/Atomic2D/ConstraintPrismatic2D.h
  39. 12 8
      Source/Atomic/Atomic2D/ConstraintPulley2D.cpp
  40. 6 2
      Source/Atomic/Atomic2D/ConstraintPulley2D.h
  41. 5 4
      Source/Atomic/Atomic2D/ConstraintRevolute2D.cpp
  42. 8 2
      Source/Atomic/Atomic2D/ConstraintRevolute2D.h
  43. 5 4
      Source/Atomic/Atomic2D/ConstraintRope2D.cpp
  44. 4 2
      Source/Atomic/Atomic2D/ConstraintRope2D.h
  45. 4 3
      Source/Atomic/Atomic2D/ConstraintWeld2D.cpp
  46. 4 2
      Source/Atomic/Atomic2D/ConstraintWeld2D.h
  47. 7 5
      Source/Atomic/Atomic2D/ConstraintWheel2D.cpp
  48. 9 3
      Source/Atomic/Atomic2D/ConstraintWheel2D.h
  49. 13 16
      Source/Atomic/Atomic2D/Drawable2D.cpp
  50. 6 4
      Source/Atomic/Atomic2D/Drawable2D.h
  51. 6 6
      Source/Atomic/Atomic2D/ParticleEffect2D.cpp
  52. 36 2
      Source/Atomic/Atomic2D/ParticleEffect2D.h
  53. 26 21
      Source/Atomic/Atomic2D/ParticleEmitter2D.cpp
  54. 6 4
      Source/Atomic/Atomic2D/ParticleEmitter2D.h
  55. 2 2
      Source/Atomic/Atomic2D/PhysicsUtils2D.h
  56. 22 19
      Source/Atomic/Atomic2D/PhysicsWorld2D.cpp
  57. 25 8
      Source/Atomic/Atomic2D/PhysicsWorld2D.h
  58. 13 10
      Source/Atomic/Atomic2D/Renderer2D.cpp
  59. 3 1
      Source/Atomic/Atomic2D/Renderer2D.h
  60. 23 12
      Source/Atomic/Atomic2D/RigidBody2D.cpp
  61. 15 3
      Source/Atomic/Atomic2D/RigidBody2D.h
  62. 9 8
      Source/Atomic/Atomic2D/Sprite2D.cpp
  63. 4 0
      Source/Atomic/Atomic2D/Sprite2D.h
  64. 14 15
      Source/Atomic/Atomic2D/SpriteSheet2D.cpp
  65. 4 2
      Source/Atomic/Atomic2D/SpriteSheet2D.h
  66. 8 5
      Source/Atomic/Atomic2D/StaticSprite2D.cpp
  67. 8 0
      Source/Atomic/Atomic2D/StaticSprite2D.h
  68. 6 16
      Source/Atomic/Atomic2D/TileMap2D.cpp
  69. 3 4
      Source/Atomic/Atomic2D/TileMap2D.h
  70. 18 16
      Source/Atomic/Atomic2D/TileMapDefs2D.cpp
  71. 10 2
      Source/Atomic/Atomic2D/TileMapDefs2D.h
  72. 9 9
      Source/Atomic/Atomic2D/TileMapLayer2D.cpp
  73. 5 1
      Source/Atomic/Atomic2D/TileMapLayer2D.h
  74. 10 7
      Source/Atomic/Atomic2D/TmxFile2D.cpp
  75. 15 2
      Source/Atomic/Atomic2D/TmxFile2D.h
  76. 22 16
      Source/Atomic/Atomic3D/AnimatedModel.cpp
  77. 15 2
      Source/Atomic/Atomic3D/AnimatedModel.h
  78. 29 28
      Source/Atomic/Atomic3D/Animation.cpp
  79. 18 11
      Source/Atomic/Atomic3D/Animation.h
  80. 30 16
      Source/Atomic/Atomic3D/AnimationController.cpp
  81. 8 7
      Source/Atomic/Atomic3D/AnimationController.h
  82. 44 45
      Source/Atomic/Atomic3D/AnimationState.cpp
  83. 13 6
      Source/Atomic/Atomic3D/AnimationState.h
  84. 44 25
      Source/Atomic/Atomic3D/BillboardSet.cpp
  85. 11 3
      Source/Atomic/Atomic3D/BillboardSet.h
  86. 60 50
      Source/Atomic/Atomic3D/CustomGeometry.cpp
  87. 9 2
      Source/Atomic/Atomic3D/CustomGeometry.h
  88. 21 20
      Source/Atomic/Atomic3D/DecalSet.cpp
  89. 22 8
      Source/Atomic/Atomic3D/DecalSet.h
  90. 2 0
      Source/Atomic/Atomic3D/LMStaticModel.cpp
  91. 66 67
      Source/Atomic/Atomic3D/Model.cpp
  92. 27 10
      Source/Atomic/Atomic3D/Model.h
  93. 18 18
      Source/Atomic/Atomic3D/ParticleEffect.cpp
  94. 38 4
      Source/Atomic/Atomic3D/ParticleEffect.h
  95. 17 15
      Source/Atomic/Atomic3D/ParticleEmitter.cpp
  96. 6 3
      Source/Atomic/Atomic3D/ParticleEmitter.h
  97. 16 17
      Source/Atomic/Atomic3D/Skeleton.cpp
  98. 8 5
      Source/Atomic/Atomic3D/Skeleton.h
  99. 5 4
      Source/Atomic/Atomic3D/Skybox.cpp
  100. 5 5
      Source/Atomic/Atomic3D/Skybox.h

+ 14 - 1
Resources/CoreData/Shaders/GLSL/FXAA3.glsl

@@ -314,8 +314,19 @@ float CalcLuma(vec3 rgb)
 
 /*--------------------------------------------------------------------------*/
 
-#define FxaaTexTop(t, p) vec4(texture2DLod(t, p, 0.0).rgb, 1.0)
+#ifdef GL3
+
+#define FxaaTexTop(t, p) vec4(textureLod(t, p, 0.0).rgb, 1.0)
+#define LumaTop(t, p) CalcLuma(textureLod(t, p, 0.0).rgb)
+#if (FXAA_FAST_PIXEL_OFFSET == 1)
+    #define LumaOff(t, p, o, r) CalcLuma(textureLodOffset(t, p, 0.0, o).rgb)
+#else
+    #define LumaOff(t, p, o, r) CalcLuma(textureLod(t, p + (o * r), 0.0).rgb)
+#endif
 
+#else
+
+#define FxaaTexTop(t, p) vec4(texture2DLod(t, p, 0.0).rgb, 1.0)
 #define LumaTop(t, p) CalcLuma(texture2DLod(t, p, 0.0).rgb)
 #if (FXAA_FAST_PIXEL_OFFSET == 1)
     #define LumaOff(t, p, o, r) CalcLuma(texture2DLodOffset(t, p, 0.0, o).rgb)
@@ -323,6 +334,8 @@ float CalcLuma(vec3 rgb)
     #define LumaOff(t, p, o, r) CalcLuma(texture2DLod(t, p + (o * r), 0.0).rgb)
 #endif
 
+#endif
+
 /*============================================================================
 
                              FXAA3 QUALITY - PC

+ 2 - 0
Resources/CoreData/Shaders/GLSL/Samplers.glsl

@@ -29,6 +29,8 @@ uniform samplerCube sLightCubeMap;
 #define texture2DProj textureProj
 #define texture3D texture
 #define textureCube texture
+#define texture2DLod textureLod
+#define texture2DLodOffset textureLodOffset
 #endif
 
 vec3 DecodeNormal(vec4 normalInput)

+ 2 - 2
Resources/CoreData/Shaders/GLSL/TerrainBlend.glsl

@@ -10,7 +10,7 @@ varying vec2 vTexCoord;
 #ifndef GL_ES
 varying vec2 vDetailTexCoord;
 #else
-varying lowp vec2 vDetailTexCoord;
+varying mediump vec2 vDetailTexCoord;
 #endif
 
 varying vec3 vNormal;
@@ -44,7 +44,7 @@ uniform sampler2D sDetailMap3;
 #ifndef GL_ES
 uniform vec2 cDetailTiling;
 #else
-uniform lowp vec2 cDetailTiling;
+uniform mediump vec2 cDetailTiling;
 #endif
 
 void VS()

+ 13 - 12
Script/TypeScript/Atomic.d.ts

@@ -50,6 +50,7 @@ declare module Atomic {
    export var VAR_MATRIX3: VariantType;
    export var VAR_MATRIX3X4: VariantType;
    export var VAR_MATRIX4: VariantType;
+   export var VAR_DOUBLE: VariantType;
    export var MAX_VAR_TYPES: VariantType;
 
 
@@ -314,6 +315,7 @@ declare module Atomic {
    export var RAY_AABB: RayQueryLevel;
    export var RAY_OBB: RayQueryLevel;
    export var RAY_TRIANGLE: RayQueryLevel;
+   export var RAY_TRIANGLE_UV: RayQueryLevel;
 
 
    // enum LightVSVariation
@@ -1534,8 +1536,6 @@ declare module Atomic {
       getScene(): Scene;
       // Return whether is enabled.
       isEnabled(): boolean;
-      // Return whether is enabled (so JS picks it up as a property);
-      getEnabled(): boolean;
       // Return whether is effectively enabled (node is also enabled.)
       isEnabledEffective(): boolean;
       // Return component in the same scene node by type. If there are several, returns the first.
@@ -1745,7 +1745,7 @@ declare module Atomic {
       setID(id: number): void;
       // Set scene. Called by Scene.
       setScene(scene: Scene): void;
-      // Reset scene. Called by Scene.
+      // Reset scene, ID and owner. Called by Scene.
       resetScene(): void;
       // Set network position attribute.
       setNetPositionAttr(value: Vector3): void;
@@ -2510,7 +2510,6 @@ declare module Atomic {
       setNumTechniques(num: number): void;
       // Set technique.
       setTechnique(index: number, tech: Technique, qualityLevel?: number, lodDistance?: number): void;
-      // Set shader parameter animation.
       setShaderParameterAnimation(name: string, animation: ValueAnimation, wrapMode?: WrapMode, speed?: number): void;
       // Set shader parameter animation wrap mode.
       setShaderParameterAnimationWrapMode(name: string, wrapMode: WrapMode): void;
@@ -3838,14 +3837,16 @@ declare module Atomic {
       setLooped(name: string, enable: boolean): boolean;
       // Set animation speed. Return true on success.
       setSpeed(name: string, speed: number): boolean;
-      // Set animation autofade on stop (non-looped animations only.) Zero time disables. Return true on success.
+      // Set animation autofade at end (non-looped animations only.) Zero time disables. Return true on success.
       setAutoFade(name: string, fadeOutTime: number): boolean;
-      // Return whether an animation is active.
+      // Return whether an animation is active. Note that non-looping animations that are being clamped at the end also return true.
       isPlaying(name: string): boolean;
       // Return whether an animation is fading in.
       isFadingIn(name: string): boolean;
       // Return whether an animation is fading out.
       isFadingOut(name: string): boolean;
+      // Return whether an animation is at its end. Will return false if the animation is not active at all.
+      isAtEnd(name: string): boolean;
       // Return animation blending layer.
       getLayer(name: string): number;
       // Return animation start bone name, or empty string if no such animation.
@@ -4614,7 +4615,7 @@ declare module Atomic {
       getLoopMode(): LoopMode2D;
       // Return root node.
       getRootNode(): Node;
-      // Set anmiation by name.
+      // Set animation by name.
       setAnimationAttr(name: string): void;
 
    }
@@ -6871,14 +6872,13 @@ declare module Atomic {
       update(): void;
       // Set whether ALT-ENTER fullscreen toggle is enabled.
       setToggleFullscreen(enable: boolean): void;
-      // Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window. Mouse visiblility event can be suppressed-- this also recalls any unsuppressed SetMouseVisible which can be returned by ResetMouseVisible().
+      // Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window. Mouse visibility event can be suppressed-- this also recalls any unsuppressed SetMouseVisible which can be returned by ResetMouseVisible().
       setMouseVisible(enable: boolean, suppressEvent?: boolean): void;
-      // Reset last mouse visibilty that was not suppressed in SetMouseVisible.
+      // Reset last mouse visibility that was not suppressed in SetMouseVisible.
       resetMouseVisible(): void;
       // Set whether the mouse is currently being grabbed by an operation.
       setMouseGrabbed(grab: boolean): void;
       setMouseMode(mode: MouseMode): void;
-      addScreenJoystick(layoutFile?: XMLFile, styleFile?: XMLFile): number;
       // Show or hide on-screen keyboard on platforms that support it. When shown, keypresses from it are delivered as key events.
       setScreenKeyboardVisible(enable: boolean): void;
       // Set touch emulation by mouse. Only available on desktop platforms. When enabled, actual mouse events are no longer sent and the mouse cursor is forced visible.
@@ -6908,7 +6908,7 @@ declare module Atomic {
       // Check if a key is held down by scancode.
       getScancodeDown(scancode: number): boolean;
       // Check if a key has been pressed on this frame by scancode.
-      getScancodePress(scanode: number): boolean;
+      getScancodePress(scancode: number): boolean;
       // Check if a mouse button is held down.
       getMouseButtonDown(button: number): boolean;
       // Check if a mouse button has been pressed on this frame.
@@ -7636,7 +7636,7 @@ declare module Atomic {
       // Deserialize from a string. Return true if successful.
       fromString(source: string): boolean;
       // Serialize the XML content to a string.
-      toString(indendation?: string): string;
+      toString(indentation?: string): string;
       // Patch the XMLFile with another XMLFile. Based on RFC 5261.
       patch(patchFile: XMLFile): void;
 
@@ -8044,6 +8044,7 @@ declare module Atomic {
       constructor();
 
       getScriptClass(): boolean;
+      createJSComponent(): JSComponent;
       pushModule(): boolean;
 
    }

+ 16 - 22
Source/Atomic/Atomic2D/AnimatedSprite2D.cpp

@@ -20,16 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../IO/Log.h"
 #include "../Resource/ResourceCache.h"
 #include "../Scene/Scene.h"
 #include "../Scene/SceneEvents.h"
 #include "../Atomic2D/AnimatedSprite2D.h"
-#include "../Atomic2D/Animation2D.h"
 #include "../Atomic2D/AnimationSet2D.h"
 #include "../Atomic2D/Sprite2D.h"
-#include "../Atomic2D/StaticSprite2D.h"
 
 #include "../DebugNew.h"
 
@@ -68,7 +68,8 @@ void AnimatedSprite2D::RegisterObject(Context* context)
     COPY_BASE_ATTRIBUTES(StaticSprite2D);
     REMOVE_ATTRIBUTE("Sprite");
     ACCESSOR_ATTRIBUTE("Speed", GetSpeed, SetSpeed, float, 1.0f, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Animation Set", GetAnimationSetAttr, SetAnimationSetAttr, ResourceRef, ResourceRef(AnimatedSprite2D::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Animation Set", GetAnimationSetAttr, SetAnimationSetAttr, ResourceRef,
+        ResourceRef(AnimatedSprite2D::GetTypeStatic()), AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Animation", GetAnimation, SetAnimationAttr, String, String::EMPTY, AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE("Loop Mode", GetLoopMode, SetLoopMode, LoopMode2D, loopModeNames, LM_DEFAULT, AM_DEFAULT);
 }
@@ -174,26 +175,19 @@ ResourceRef AnimatedSprite2D::GetAnimationSetAttr() const
     return GetResourceRef(animationSet_, AnimationSet2D::GetTypeStatic());
 }
 
-void AnimatedSprite2D::OnNodeSet(Node* node)
+void AnimatedSprite2D::OnSceneSet(Scene* scene)
 {
-    StaticSprite2D::OnNodeSet(node);
+    StaticSprite2D::OnSceneSet(scene);
 
-    if (node)
+    if (scene)
     {
-        Scene* scene = GetScene();
-        if (scene && IsEnabledEffective())
+        if (scene == node_)
+            LOGWARNING(GetTypeName() + " should not be created to the root scene node");
+        if (IsEnabledEffective())
             SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(AnimatedSprite2D, HandleScenePostUpdate));
     }
     else
-    {
-        if (rootNode_)
-            rootNode_->Remove();
-
-        rootNode_ = 0;
-        numTracks_ = 0;
-        trackNodes_.Clear();
-        trackNodeInfos_.Clear();
-    }
+        UnsubscribeFromEvent(E_SCENEPOSTUPDATE);
 }
 
 void AnimatedSprite2D::SetAnimationAttr(const String& name)
@@ -304,7 +298,7 @@ void AnimatedSprite2D::SetAnimation(Animation2D* animation, LoopMode2D loopMode)
         {
             // Enable track node
             trackNode->SetEnabled(true);
-            
+
             // Get StaticSprite2D component
             if (track.hasSprite_)
                 staticSprite = trackNode->GetComponent<StaticSprite2D>();
@@ -364,7 +358,7 @@ void AnimatedSprite2D::UpdateAnimation(float timeStep)
     for (unsigned i = 0; i < numTracks_; ++i)
     {
         trackNodeInfos_[i].worldSpace = false;
-        
+
         const AnimationTrack2D& track = animation_->GetTrack(i);
         const Vector<AnimationKeyFrame2D>& keyFrames = track.keyFrames_;
 
@@ -392,7 +386,7 @@ void AnimatedSprite2D::UpdateAnimation(float timeStep)
             if (index < keyFrames.Size() - 1)
             {
                 const AnimationKeyFrame2D& nextKey = keyFrames[index + 1];
-                float t = (time - currKey.time_)  / (nextKey.time_ - currKey.time_);
+                float t = (time - currKey.time_) / (nextKey.time_ - currKey.time_);
                 value.transform_ = currKey.transform_.Lerp(nextKey.transform_, t, currKey.spin_);
 
                 if (trackNodeInfos_[i].hasSprite)
@@ -463,7 +457,7 @@ void AnimatedSprite2D::UpdateAnimation(float timeStep)
     }
 }
 
-void AnimatedSprite2D::CalculateTimelineWorldTransform(unsigned index)
+void AnimatedSprite2D::CalculateTimelineWorldTransform(int index)
 {
     TrackNodeInfo& info = trackNodeInfos_[index];
     if (info.worldSpace)

+ 8 - 4
Source/Atomic/Atomic2D/AnimatedSprite2D.h

@@ -70,12 +70,16 @@ public:
 
     /// Return speed.
     float GetSpeed() const { return speed_; }
+
     /// Return animation name.
     const String& GetAnimation() const { return animationName_; }
+
     /// Return animation.
     AnimationSet2D* GetAnimationSet() const;
+
     /// Return loop mode.
     LoopMode2D GetLoopMode() const { return loopMode_; }
+
     /// Return root node.
     Node* GetRootNode() const;
 
@@ -83,12 +87,12 @@ public:
     void SetAnimationSetAttr(const ResourceRef& value);
     /// Return animation set attribute.
     ResourceRef GetAnimationSetAttr() const;
-    /// Set anmiation by name.
+    /// Set animation by name.
     void SetAnimationAttr(const String& name);
 
 protected:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
     /// Recalculate the world-space bounding box.
     virtual void OnWorldBoundingBoxUpdate();
     /// Handle draw order changed.
@@ -102,7 +106,7 @@ protected:
     /// Update animation.
     void UpdateAnimation(float timeStep);
     /// Calculate time line world world transform.
-    void CalculateTimelineWorldTransform(unsigned index);
+    void CalculateTimelineWorldTransform(int index);
     /// Handle scene post update.
     void HandleScenePostUpdate(StringHash eventType, VariantMap& eventData);
 

+ 17 - 16
Source/Atomic/Atomic2D/Animation2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,10 +20,11 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../IO/Log.h"
 #include "../Atomic2D/Animation2D.h"
 #include "../Atomic2D/AnimationSet2D.h"
-#include "../IO/Log.h"
 #include "../Atomic2D/Sprite2D.h"
 
 #include "../DebugNew.h"
@@ -39,28 +40,28 @@ Transform2D::Transform2D() :
 }
 
 Transform2D::Transform2D(const Vector2& position, float angle, const Vector2& scale) :
-    position_(position), 
-    angle_(angle), 
+    position_(position),
+    angle_(angle),
     scale_(scale)
 {
 }
 
 Transform2D::Transform2D(const Transform2D& other) :
-    position_(other.position_), 
-    angle_(other.angle_), 
+    position_(other.position_),
+    angle_(other.angle_),
     scale_(other.scale_)
 {
 }
 
-Transform2D& Transform2D::operator = (const Transform2D& other)
+Transform2D& Transform2D::operator =(const Transform2D& other)
 {
-    position_ = other.position_; 
+    position_ = other.position_;
     angle_ = other.angle_;
     scale_ = other.scale_;
     return *this;
 }
 
-Transform2D Transform2D::operator * (const Transform2D& other) const
+Transform2D Transform2D::operator *(const Transform2D& other) const
 {
     float x = scale_.x_ * other.position_.x_;
     float y = scale_.y_ * other.position_.y_;
@@ -86,16 +87,16 @@ Transform2D Transform2D::Lerp(const Transform2D& other, float t, int spin) const
     if (spin > 0 && angle_ > other.angle_)
         ret.angle_ = Atomic::Lerp(angle_, other.angle_ + 360.0f, t);
     else if (spin < 0 && angle_ < other.angle_)
-        ret.angle_= Atomic::Lerp(angle_, other.angle_ - 360.0f, t);
+        ret.angle_ = Atomic::Lerp(angle_, other.angle_ - 360.0f, t);
     else
-        ret.angle_= Atomic::Lerp(angle_, other.angle_, t);
+        ret.angle_ = Atomic::Lerp(angle_, other.angle_, t);
 
     ret.scale_ = scale_.Lerp(other.scale_, t);
     return ret;
 }
 
-AnimationKeyFrame2D::AnimationKeyFrame2D() : 
-    time_(0.0f), 
+AnimationKeyFrame2D::AnimationKeyFrame2D() :
+    time_(0.0f),
     enabled_(false),
     parent_(-1),
     spin_(1),
@@ -105,9 +106,9 @@ AnimationKeyFrame2D::AnimationKeyFrame2D() :
 {
 }
 
-Animation2D::Animation2D(AnimationSet2D* animationSet) : 
+Animation2D::Animation2D(AnimationSet2D* animationSet) :
     animationSet_(animationSet),
-    length_(0.0f), 
+    length_(0.0f),
     looped_(true)
 {
 }

+ 10 - 5
Source/Atomic/Atomic2D/Animation2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -43,9 +43,9 @@ struct Transform2D
     Transform2D(const Transform2D& other);
 
     /// Assign from another transform.
-    Transform2D& operator = (const Transform2D& other);
+    Transform2D& operator =(const Transform2D& other);
     /// Multiply a transform.
-    Transform2D operator * (const Transform2D& other) const;
+    Transform2D operator *(const Transform2D& other) const;
     /// Linear interpolation with another transform.
     Transform2D Lerp(const Transform2D& other, float t, int spin) const;
 
@@ -62,7 +62,7 @@ struct AnimationKeyFrame2D
 {
     /// Construct.
     AnimationKeyFrame2D();
-    
+
     /// Time.
     float time_;
 
@@ -113,17 +113,22 @@ public:
     void SetLength(float length);
     /// Set looped.
     void SetLooped(bool looped);
-    
+
     /// Return animation set.
     AnimationSet2D* GetAnimationSet() const;
+
     /// Return name.
     const String& GetName() const { return name_; }
+
     /// Return length.
     float GetLength() const { return length_; }
+
     /// Return looped.
     bool IsLooped() const { return looped_; }
+
     /// Return number of animation tracks.
     unsigned GetNumTracks() const { return tracks_.Size(); }
+
     /// Return animation track.
     const AnimationTrack2D& GetTrack(unsigned index) const;
 

+ 13 - 12
Source/Atomic/Atomic2D/AnimationSet2D.cpp

@@ -20,13 +20,14 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/Animation2D.h"
-#include "../Atomic2D/AnimationSet2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
 #include "../Resource/ResourceCache.h"
+#include "../Atomic2D/Animation2D.h"
+#include "../Atomic2D/AnimationSet2D.h"
 #include "../Atomic2D/Sprite2D.h"
 #include "../Atomic2D/SpriteSheet2D.h"
 #include "../Resource/XMLFile.h"
@@ -102,7 +103,7 @@ Sprite2D* AnimationSet2D::GetSprite(const StringHash& hash) const
     return 0;
 }
 
-bool AnimationSet2D::BeginLoadSpriter(Deserializer &source)
+bool AnimationSet2D::BeginLoadSpriter(Deserializer& source)
 {
     spriterFile_ = new XMLFile(context_);
     if (!spriterFile_->Load(source))
@@ -150,7 +151,8 @@ bool AnimationSet2D::EndLoadSpriter()
         return false;
     }
 
-    for (XMLElement animationElem = entityElem.GetChild("animation"); animationElem; animationElem = animationElem.GetNext("animation"))
+    for (XMLElement animationElem = entityElem.GetChild("animation"); animationElem;
+         animationElem = animationElem.GetNext("animation"))
     {
         if (!LoadSpriterAnimation(animationElem))
         {
@@ -263,7 +265,7 @@ enum SpriterObjectType2D
 // Spriter timeline key.
 struct SpriterTimelineKey2D
 {
-    SpriterTimelineKey2D() : 
+    SpriterTimelineKey2D() :
         time_(0.0f),
         angle_(0.0f),
         spin_(1),
@@ -335,7 +337,8 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
 
     // Load timelines
     Vector<SpriterTimeline2D> timelines;
-    for (XMLElement timelineElem = animationElem.GetChild("timeline"); timelineElem; timelineElem = timelineElem.GetNext("timeline"))
+    for (XMLElement timelineElem = animationElem.GetChild("timeline"); timelineElem;
+         timelineElem = timelineElem.GetNext("timeline"))
     {
         SpriterTimeline2D timeline;
         timeline.name_ = timelineElem.GetAttribute("name");
@@ -358,7 +361,6 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
 
             key.angle_ = childElem.GetFloat("angle");
 
-            Vector2 scale(Vector2::ONE);
             if (childElem.HasAttribute("scale_x"))
                 key.scale_.x_ = childElem.GetFloat("scale_x");
 
@@ -369,7 +371,7 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
             {
                 int folder = childElem.GetUInt("folder");
                 int file = childElem.GetUInt("file");
-                key.sprite_ = GetSprite(StringHash((folder << 16) + file));
+                key.sprite_ = GetSprite(StringHash((unsigned)((folder << 16) + file)));
                 if (!key.sprite_)
                 {
                     LOGERROR("Could not find sprite");
@@ -427,7 +429,7 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
 
         mainlineKeys.Push(mainlineKey);
     }
-    
+
     unsigned numTimelines = timelines.Size();
     unsigned numMainlineKeys = mainlineKeys.Size();
     if (numTimelines == 0 || numMainlineKeys == 0)
@@ -450,7 +452,7 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
     {
         SpriterTimeline2D& timeline = timelines[i];
         AnimationTrack2D& track = tracks[i];
-        
+
         track.name_ = timeline.name_;
         track.hasSprite_ = timeline.type_ == SOT_SPRITE;
 
@@ -463,7 +465,6 @@ bool AnimationSet2D::LoadSpriterAnimation(const XMLElement& animationElem)
             AnimationKeyFrame2D& keyFrame = track.keyFrames_[j];
 
             keyFrame.time_ = timelineKey.time_;
-
             highestKeyTime = Max(highestKeyTime, keyFrame.time_);
 
             // Set disabled

+ 2 - 2
Source/Atomic/Atomic2D/AnimationSet2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -61,7 +61,7 @@ private:
     /// Return sprite by hash.
     Sprite2D* GetSprite(const StringHash& hash) const;
     /// Begin load scml.
-    bool BeginLoadSpriter(Deserializer &source);
+    bool BeginLoadSpriter(Deserializer& source);
     /// Finish load scml.
     bool EndLoadSpriter();
     /// Load spriter folders.

+ 5 - 9
Source/Atomic/Atomic2D/Atomic2D.cpp

@@ -1,5 +1,4 @@
-
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,7 +19,9 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
 #include "../Atomic2D/AnimatedSprite2D.h"
 #include "../Atomic2D/AnimationSet2D.h"
 #include "../Atomic2D/CollisionBox2D.h"
@@ -28,7 +29,6 @@
 #include "../Atomic2D/CollisionCircle2D.h"
 #include "../Atomic2D/CollisionEdge2D.h"
 #include "../Atomic2D/CollisionPolygon2D.h"
-#include "../Atomic2D/CollisionShape2D.h"
 #include "../Atomic2D/Constraint2D.h"
 #include "../Atomic2D/ConstraintDistance2D.h"
 #include "../Atomic2D/ConstraintFriction2D.h"
@@ -41,8 +41,6 @@
 #include "../Atomic2D/ConstraintRope2D.h"
 #include "../Atomic2D/ConstraintWeld2D.h"
 #include "../Atomic2D/ConstraintWheel2D.h"
-#include "../Core/Context.h"
-#include "../Atomic2D/Drawable2D.h"
 #include "../Atomic2D/ParticleEffect2D.h"
 #include "../Atomic2D/ParticleEmitter2D.h"
 #include "../Atomic2D/PhysicsWorld2D.h"
@@ -50,7 +48,6 @@
 #include "../Atomic2D/RigidBody2D.h"
 #include "../Atomic2D/Sprite2D.h"
 #include "../Atomic2D/SpriteSheet2D.h"
-#include "../Atomic2D/StaticSprite2D.h"
 #include "../Atomic2D/TileMap2D.h"
 #include "../Atomic2D/TileMapLayer2D.h"
 #include "../Atomic2D/TmxFile2D.h"
@@ -70,7 +67,7 @@ void RegisterAtomic2DLibrary(Context* context)
 
     Sprite2D::RegisterObject(context);
     SpriteSheet2D::RegisterObject(context);
-    
+
     // Must register objects from base to derived order
     Drawable2D::RegisterObject(context);
     StaticSprite2D::RegisterObject(context);
@@ -114,7 +111,6 @@ void RegisterAtomic2DLibrary(Context* context)
     PositionalLight2D::RegisterObject(context);
     PointLight2D::RegisterObject(context);
 
-
 }
 
 }

+ 1 - 1
Source/Atomic/Atomic2D/Atomic2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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

+ 3 - 2
Source/Atomic/Atomic2D/CollisionBox2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Atomic2D/CollisionBox2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"

+ 4 - 2
Source/Atomic/Atomic2D/CollisionBox2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API CollisionBox2D : public CollisionShape2D
 
 public:
     /// Construct.
-    CollisionBox2D(Context* scontext);
+    CollisionBox2D(Context* context);
     /// Destruct.
     virtual ~CollisionBox2D();
     /// Register object factory.
@@ -53,8 +53,10 @@ public:
 
     /// Return size.
     const Vector2& GetSize() const { return size_; }
+
     /// Return center.
     const Vector2& GetCenter() const { return center_; }
+
     /// Return angle.
     float GetAngle() const { return angle_; }
 

+ 5 - 4
Source/Atomic/Atomic2D/CollisionChain2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,12 +20,13 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
-#include "../Atomic2D/CollisionChain2D.h"
 #include "../IO/MemoryBuffer.h"
-#include "../Atomic2D/PhysicsUtils2D.h"
 #include "../IO/VectorBuffer.h"
+#include "../Atomic2D/CollisionChain2D.h"
+#include "../Atomic2D/PhysicsUtils2D.h"
 
 #include "../DebugNew.h"
 

+ 6 - 2
Source/Atomic/Atomic2D/CollisionChain2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -33,7 +33,7 @@ class ATOMIC_API CollisionChain2D : public CollisionShape2D
 
 public:
     /// Construct.
-    CollisionChain2D(Context* scontext);
+    CollisionChain2D(Context* context);
     /// Destruct.
     virtual ~CollisionChain2D();
     /// Register object factory.
@@ -52,12 +52,16 @@ public:
 
     /// Return loop.
     bool GetLoop() const { return loop_; }
+
     /// Return vertex count.
     unsigned GetVertexCount() const { return vertices_.Size(); }
+
     /// Return vertex.
     const Vector2& GetVertex(unsigned index) const { return (index < vertices_.Size()) ? vertices_[index] : Vector2::ZERO; }
+
     /// Return vertices.
     const PODVector<Vector2>& GetVertices() const { return vertices_; }
+
     /// Return vertices attribute.
     PODVector<unsigned char> GetVerticesAttr() const;
 

+ 3 - 2
Source/Atomic/Atomic2D/CollisionCircle2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Atomic2D/CollisionCircle2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"

+ 3 - 2
Source/Atomic/Atomic2D/CollisionCircle2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API CollisionCircle2D : public CollisionShape2D
 
 public:
     /// Construct.
-    CollisionCircle2D(Context* scontext);
+    CollisionCircle2D(Context* context);
     /// Destruct.
     virtual ~CollisionCircle2D();
     /// Register object factory.
@@ -49,6 +49,7 @@ public:
 
     /// Return radius.
     float GetRadius() const { return radius_; }
+
     /// Return center.
     const Vector2& GetCenter() const { return center_; }
 

+ 3 - 3
Source/Atomic/Atomic2D/CollisionEdge2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Atomic2D/CollisionEdge2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
@@ -38,7 +39,6 @@ CollisionEdge2D::CollisionEdge2D(Context* context) :
     CollisionShape2D(context),
     vertex1_(DEFAULT_VERTEX1),
     vertex2_(DEFAULT_VERTEX2)
-
 {
     Vector2 worldScale(cachedWorldScale_.x_, cachedWorldScale_.y_);
     edgeShape_.Set(ToB2Vec2(vertex1_ * worldScale), ToB2Vec2(vertex2_ * worldScale));

+ 3 - 2
Source/Atomic/Atomic2D/CollisionEdge2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API CollisionEdge2D : public CollisionShape2D
 
 public:
     /// Construct.
-    CollisionEdge2D(Context* scontext);
+    CollisionEdge2D(Context* context);
     /// Destruct.
     virtual ~CollisionEdge2D();
     /// Register object factory.
@@ -49,6 +49,7 @@ public:
 
     /// Return vertex 1.
     const Vector2& GetVertex1() const { return vertex1_; }
+
     /// Return vertex 2.
     const Vector2& GetVertex2() const { return vertex2_; }
 

+ 6 - 5
Source/Atomic/Atomic2D/CollisionPolygon2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,12 +20,13 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
-#include "../Atomic2D/CollisionPolygon2D.h"
 #include "../IO/MemoryBuffer.h"
-#include "../Atomic2D/PhysicsUtils2D.h"
 #include "../IO/VectorBuffer.h"
+#include "../Atomic2D/CollisionPolygon2D.h"
+#include "../Atomic2D/PhysicsUtils2D.h"
 
 #include "../DebugNew.h"
 
@@ -112,7 +113,7 @@ void CollisionPolygon2D::ApplyNodeWorldScale()
 void CollisionPolygon2D::RecreateFixture()
 {
     ReleaseFixture();
-    
+
     if (vertices_.Size() < 3)
         return;
 

+ 4 - 2
Source/Atomic/Atomic2D/CollisionPolygon2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API CollisionPolygon2D : public CollisionShape2D
 
 public:
     /// Construct.
-    CollisionPolygon2D(Context* scontext);
+    CollisionPolygon2D(Context* context);
     /// Destruct.
     virtual ~CollisionPolygon2D();
     /// Register object factory.
@@ -49,8 +49,10 @@ public:
 
     /// Return vertex count.
     unsigned GetVertexCount() const { return vertices_.Size(); }
+
     /// Return vertex.
     const Vector2& GetVertex(unsigned index) const { return (index < vertices_.Size()) ? vertices_[index] : Vector2::ZERO; }
+
     /// Return vertices.
     const PODVector<Vector2>& GetVertices() const { return vertices_; }
 

+ 13 - 12
Source/Atomic/Atomic2D/CollisionShape2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,14 +20,15 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/CollisionShape2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../IO/Log.h"
 #include "../Scene/Node.h"
+#include "../Scene/Scene.h"
+#include "../Atomic2D/CollisionShape2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
-#include "../Scene/Scene.h"
 
 #include "../DebugNew.h"
 
@@ -37,7 +38,7 @@ namespace Atomic
 extern const char* ATOMIC2D_CATEGORY;
 
 CollisionShape2D::CollisionShape2D(Context* context) :
-    Component(context), 
+    Component(context),
     fixture_(0),
     cachedWorldScale_(Vector3::ONE)
 {
@@ -88,7 +89,7 @@ void CollisionShape2D::SetTrigger(bool trigger)
 
     if (fixture_)
         fixture_->SetSensor(trigger);
-    
+
     MarkNetworkUpdate();
 }
 
@@ -97,11 +98,11 @@ void CollisionShape2D::SetCategoryBits(int categoryBits)
     if (fixtureDef_.filter.categoryBits == categoryBits)
         return;
 
-    fixtureDef_.filter.categoryBits = categoryBits;
+    fixtureDef_.filter.categoryBits = (uint16)categoryBits;
 
     if (fixture_)
         fixture_->SetFilterData(fixtureDef_.filter);
-    
+
     MarkNetworkUpdate();
 }
 
@@ -110,7 +111,7 @@ void CollisionShape2D::SetMaskBits(int maskBits)
     if (fixtureDef_.filter.maskBits == maskBits)
         return;
 
-    fixtureDef_.filter.maskBits = maskBits;
+    fixtureDef_.filter.maskBits = (uint16)maskBits;
 
     if (fixture_)
         fixture_->SetFilterData(fixtureDef_.filter);
@@ -123,7 +124,7 @@ void CollisionShape2D::SetGroupIndex(int groupIndex)
     if (fixtureDef_.filter.groupIndex == groupIndex)
         return;
 
-    fixtureDef_.filter.groupIndex = groupIndex;
+    fixtureDef_.filter.groupIndex = (int16)groupIndex;
 
     if (fixture_)
         fixture_->SetFilterData(fixtureDef_.filter);
@@ -263,7 +264,7 @@ Vector2 CollisionShape2D::GetMassCenter() const
 {
     if (!fixture_)
         return Vector2::ZERO;
-    
+
     b2MassData massData;
     fixture_->GetMassData(&massData);
 
@@ -303,7 +304,7 @@ void CollisionShape2D::OnMarkedDirty(Node* node)
         scene->DelayedMarkedDirty(this);
         return;
     }
-    
+
     cachedWorldScale_ = newWorldScale;
 
     if (fixture_)

+ 12 - 4
Source/Atomic/Atomic2D/CollisionShape2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "../Scene/Component.h"
+
 #include <Box2D/Box2D.h>
 
 namespace Atomic
@@ -37,7 +38,7 @@ class ATOMIC_API CollisionShape2D : public Component
 
 public:
     /// Construct.
-    CollisionShape2D(Context* scontext);
+    CollisionShape2D(Context* context);
     /// Destruct.
     virtual ~CollisionShape2D();
     /// Register object factory.
@@ -68,18 +69,25 @@ public:
 
     /// Return trigger.
     bool IsTrigger() const { return fixtureDef_.isSensor; }
+
     /// Return filter category bits.
     int GetCategoryBits() const { return fixtureDef_.filter.categoryBits; }
+
     /// Return filter mask bits.
     int GetMaskBits() const { return fixtureDef_.filter.maskBits; }
+
     /// Return filter group index.
     int GetGroupIndex() const { return fixtureDef_.filter.groupIndex; }
+
     /// Return density.
     float GetDensity() const { return fixtureDef_.density; }
+
     /// Return friction.
     float GetFriction() const { return fixtureDef_.friction; }
+
     /// Return restitution.
     float GetRestitution() const { return fixtureDef_.restitution; }
+
     /// Return mass.
     float GetMass() const;
     /// Return inertia.
@@ -88,7 +96,7 @@ public:
     Vector2 GetMassCenter() const;
 
     /// Return fixture.
-    b2Fixture* GetFixture() const { return fixture_;}
+    b2Fixture* GetFixture() const { return fixture_; }
 
 protected:
     /// Handle node being assigned.
@@ -97,7 +105,7 @@ protected:
     virtual void OnMarkedDirty(Node* node);
     /// Apply Node world scale.
     virtual void ApplyNodeWorldScale() = 0;
-    
+
     /// Rigid body.
     WeakPtr<RigidBody2D> rigidBody_;
     /// Fixture def.

+ 11 - 7
Source/Atomic/Atomic2D/Constraint2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/Constraint2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../IO/Log.h"
 #include "../Scene/Node.h"
+#include "../Scene/Scene.h"
+#include "../Atomic2D/Constraint2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 #include "../Atomic2D/PhysicsWorld2D.h"
-#include "../Scene/Scene.h"
 
 #include "../DebugNew.h"
 
@@ -126,9 +127,6 @@ void Constraint2D::OnNodeSet(Node* node)
 
     if (node)
     {
-        Scene* scene = GetScene();
-        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
-
         ownerBody_ = node->GetComponent<RigidBody2D>();
         if (!ownerBody_)
         {
@@ -138,6 +136,12 @@ void Constraint2D::OnNodeSet(Node* node)
     }
 }
 
+void Constraint2D::OnSceneSet(Scene* scene)
+{
+    if (scene)
+        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
+}
+
 void Constraint2D::InitializeJointDef(b2JointDef* jointDef)
 {
     jointDef->bodyA = ownerBody_->GetBody();

+ 8 - 2
Source/Atomic/Atomic2D/Constraint2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "../Scene/Component.h"
+
 #include <Box2D/Box2D.h>
 
 namespace Atomic
@@ -38,7 +39,7 @@ class ATOMIC_API Constraint2D : public Component
 
 public:
     /// Construct.
-    Constraint2D(Context* scontext);
+    Constraint2D(Context* context);
     /// Destruct.
     virtual ~Constraint2D();
     /// Register object factory.
@@ -60,10 +61,13 @@ public:
 
     /// Return owner body.
     RigidBody2D* GetOwnerBody() const { return ownerBody_; }
+
     /// Return other body.
     RigidBody2D* GetOtherBody() const { return otherBody_; }
+
     /// Return collide connected.
     bool GetCollideConnected() const { return collideConnected_; }
+
     /// Return attached constraint (for gear).
     Constraint2D* GetAttachedConstraint() const { return attachedConstraint_; }
 
@@ -73,6 +77,8 @@ public:
 protected:
     /// Handle node being assigned.
     virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
     /// Return joint def.
     virtual b2JointDef* GetJointDef() { return 0; };
     /// Recreate joint.

+ 5 - 4
Source/Atomic/Atomic2D/ConstraintDistance2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintDistance2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintDistance2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -46,7 +47,7 @@ ConstraintDistance2D::~ConstraintDistance2D()
 void ConstraintDistance2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintDistance2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Owner Body Anchor", GetOwnerBodyAnchor, SetOwnerBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);

+ 5 - 2
Source/Atomic/Atomic2D/ConstraintDistance2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintDistance2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintDistance2D(Context* scontext);
+    ConstraintDistance2D(Context* context);
     /// Destruct.
     virtual ~ConstraintDistance2D();
     /// Register object factory.
@@ -51,10 +51,13 @@ public:
 
     /// Return owner body anchor.
     const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
+
     /// Return other body anchor.
     const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
+
     /// Return frequency Hz.
     float GetFrequencyHz() const { return jointDef_.frequencyHz; }
+
     /// Return damping ratio.
     float GetDampingRatio() const { return jointDef_.dampingRatio; }
 

+ 6 - 5
Source/Atomic/Atomic2D/ConstraintFriction2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintFriction2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintFriction2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -45,7 +46,7 @@ ConstraintFriction2D::~ConstraintFriction2D()
 void ConstraintFriction2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintFriction2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Anchor", GetAnchor, SetAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Max Force", GetMaxForce, SetMaxForce, float, 0.0f, AM_DEFAULT);
@@ -97,7 +98,7 @@ b2JointDef* ConstraintFriction2D::GetJointDef()
     if (!bodyA || !bodyB)
         return 0;
 
-    jointDef_.Initialize(bodyA, bodyB, ToB2Vec2(anchor_));    
+    jointDef_.Initialize(bodyA, bodyB, ToB2Vec2(anchor_));
 
     return &jointDef_;
 }

+ 4 - 2
Source/Atomic/Atomic2D/ConstraintFriction2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintFriction2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintFriction2D(Context* scontext);
+    ConstraintFriction2D(Context* context);
     /// Destruct.
     virtual ~ConstraintFriction2D();
     /// Register object factory.
@@ -49,8 +49,10 @@ public:
 
     /// Return anchor.
     const Vector2& GetAnchor() const { return anchor_; }
+
     /// Set max force.
     float GetMaxForce() const { return jointDef_.maxForce; }
+
     /// Set max torque.
     float GetMaxTorque() const { return jointDef_.maxTorque; }
 

+ 5 - 4
Source/Atomic/Atomic2D/ConstraintGear2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintGear2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintGear2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -116,7 +117,7 @@ b2JointDef* ConstraintGear2D::GetJointDef()
     InitializeJointDef(&jointDef_);
     jointDef_.joint1 = jointA;
     jointDef_.joint2 = jointB;
-    
+
     return &jointDef_;
 }
 

+ 4 - 2
Source/Atomic/Atomic2D/ConstraintGear2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintGear2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintGear2D(Context* scontext);
+    ConstraintGear2D(Context* context);
     /// Destruct.
     virtual ~ConstraintGear2D();
     /// Register object factory.
@@ -49,8 +49,10 @@ public:
 
     /// Return owner constraint.
     Constraint2D* GetOwnerConstraint() const { return ownerConstraint_; }
+
     /// Return other constraint.
     Constraint2D* GetOtherConstraint() const { return otherConstraint_; }
+
     /// Return ratio.
     float GetRatio() const { return jointDef_.ratio; }
 

+ 6 - 5
Source/Atomic/Atomic2D/ConstraintMotor2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintMotor2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintMotor2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -45,7 +46,7 @@ ConstraintMotor2D::~ConstraintMotor2D()
 void ConstraintMotor2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintMotor2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Linear Offset", GetLinearOffset, SetLinearOffset, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Angular Offset", GetAngularOffset, SetAngularOffset, float, 0.0f, AM_DEFAULT);
@@ -61,7 +62,7 @@ void ConstraintMotor2D::SetLinearOffset(const Vector2& linearOffset)
         return;
 
     linearOffset_ = linearOffset;
-    
+
     RecreateJoint();
     MarkNetworkUpdate();
 }

+ 6 - 2
Source/Atomic/Atomic2D/ConstraintMotor2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintMotor2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintMotor2D(Context* scontext);
+    ConstraintMotor2D(Context* context);
     /// Destruct.
     virtual ~ConstraintMotor2D();
     /// Register object factory.
@@ -53,12 +53,16 @@ public:
 
     /// Return linear offset.
     const Vector2& GetLinearOffset() const { return linearOffset_; }
+
     /// Return angular offset.
     float GetAngularOffset() const { return jointDef_.angularOffset; }
+
     /// Return max force.
     float GetMaxForce() const { return jointDef_.maxForce; }
+
     /// Return max torque.
     float GetMaxTorque() const { return jointDef_.maxTorque; }
+
     /// Return correction factor.
     float GetCorrectionFactor() const { return jointDef_.correctionFactor; }
 

+ 4 - 3
Source/Atomic/Atomic2D/ConstraintMouse2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintMouse2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintMouse2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 

+ 6 - 3
Source/Atomic/Atomic2D/ConstraintMouse2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintMouse2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintMouse2D(Context* scontext);
+    ConstraintMouse2D(Context* context);
     /// Destruct.
     virtual ~ConstraintMouse2D();
     /// Register object factory.
@@ -51,10 +51,13 @@ public:
 
     /// Return target.
     const Vector2& GetTarget() const { return target_; }
+
     /// Return max force.
     float GetMaxForce() const { return jointDef_.maxForce; }
+
     /// Return frequency Hz.
     float GetFrequencyHz() const { return jointDef_.frequencyHz; }
+
     /// Return damping ratio.
     float GetDampingRatio() const { return jointDef_.dampingRatio; }
 
@@ -63,7 +66,7 @@ private:
     virtual b2JointDef* GetJointDef();
 
     /// Box2D joint def.
-    b2MouseJointDef jointDef_; 
+    b2MouseJointDef jointDef_;
     /// Target.
     Vector2 target_;
     /// Target setted.

+ 7 - 5
Source/Atomic/Atomic2D/ConstraintPrismatic2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintPrismatic2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintPrismatic2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -39,13 +40,13 @@ ConstraintPrismatic2D::ConstraintPrismatic2D(Context* context) :
 }
 
 ConstraintPrismatic2D::~ConstraintPrismatic2D()
-{    
+{
 }
 
 void ConstraintPrismatic2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintPrismatic2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Anchor", GetAnchor, SetAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Axis", GetAxis, SetAxis, Vector2, Vector2::RIGHT, AM_DEFAULT);
@@ -57,6 +58,7 @@ void ConstraintPrismatic2D::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("Motor Speed", GetMotorSpeed, SetMotorSpeed, float, 0.7f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Constraint2D);
 }
+
 void ConstraintPrismatic2D::SetAnchor(const Vector2& anchor)
 {
     if (anchor == anchor_)

+ 9 - 2
Source/Atomic/Atomic2D/ConstraintPrismatic2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintPrismatic2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintPrismatic2D(Context* scontext);
+    ConstraintPrismatic2D(Context* context);
     /// Destruct.
     virtual ~ConstraintPrismatic2D();
     /// Register object factory.
@@ -59,18 +59,25 @@ public:
 
     /// Return anchor.
     const Vector2& GetAnchor() const { return anchor_; }
+
     /// Return axis.
     const Vector2& GetAxis() const { return axis_; }
+
     /// Return enable limit.
     bool GetEnableLimit() const { return jointDef_.enableLimit; }
+
     /// Return lower translation.
     float GetLowerTranslation() const { return jointDef_.lowerTranslation; }
+
     /// Return upper translation.
     float GetUpperTranslation() const { return jointDef_.upperTranslation; }
+
     /// Return enable motor.
     bool GetEnableMotor() const { return jointDef_.enableMotor; }
+
     /// Return maxmotor force.
     float GetMaxMotorForce() const { return jointDef_.maxMotorForce; }
+
     /// Return motor speed.
     float GetMotorSpeed() const { return jointDef_.motorSpeed; }
 

+ 12 - 8
Source/Atomic/Atomic2D/ConstraintPulley2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintPulley2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintPulley2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -48,12 +49,14 @@ ConstraintPulley2D::~ConstraintPulley2D()
 void ConstraintPulley2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintPulley2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Owner Body Ground Anchor", GetOwnerBodyGroundAnchor, SetOwnerBodyGroundAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Other Body Ground Anchor", GetOtherBodyGroundAnchor, SetOtherBodyGroundAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Owner Body Ground Anchor", GetOwnerBodyGroundAnchor, SetOwnerBodyGroundAnchor, Vector2, Vector2::ZERO,
+        AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Other Body Ground Anchor", GetOtherBodyGroundAnchor, SetOtherBodyGroundAnchor, Vector2, Vector2::ZERO,
+        AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Owner Body Anchor", GetOwnerBodyAnchor, SetOwnerBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);    
+    ACCESSOR_ATTRIBUTE("Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Ratio", GetRatio, SetRatio, float, 0.0f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Constraint2D);
 }
@@ -123,7 +126,8 @@ b2JointDef* ConstraintPulley2D::GetJointDef()
     if (!bodyA || !bodyB)
         return 0;
 
-    jointDef_.Initialize(bodyA, bodyB, ToB2Vec2(ownerBodyGroundAnchor_), ToB2Vec2(otherBodyGroundAnchor_), ToB2Vec2(ownerBodyAnchor_), ToB2Vec2(otherBodyAnchor_), jointDef_.ratio);
+    jointDef_.Initialize(bodyA, bodyB, ToB2Vec2(ownerBodyGroundAnchor_), ToB2Vec2(otherBodyGroundAnchor_),
+        ToB2Vec2(ownerBodyAnchor_), ToB2Vec2(otherBodyAnchor_), jointDef_.ratio);
 
     return &jointDef_;
 }

+ 6 - 2
Source/Atomic/Atomic2D/ConstraintPulley2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintPulley2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintPulley2D(Context* scontext);
+    ConstraintPulley2D(Context* context);
     /// Destruct.
     virtual ~ConstraintPulley2D();
     /// Register object factory.
@@ -53,12 +53,16 @@ public:
 
     /// Return owner body ground anchor.
     const Vector2& GetOwnerBodyGroundAnchor() const { return ownerBodyGroundAnchor_; }
+
     /// return other body ground anchor.
     const Vector2& GetOtherBodyGroundAnchor() const { return otherBodyGroundAnchor_; }
+
     /// Return owner body anchor.
     const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
+
     /// Return other body anchor.
     const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
+
     /// Return ratio.
     float GetRatio() const { return jointDef_.ratio; }
 

+ 5 - 4
Source/Atomic/Atomic2D/ConstraintRevolute2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintRevolute2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintRevolute2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -44,7 +45,7 @@ ConstraintRevolute2D::~ConstraintRevolute2D()
 void ConstraintRevolute2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintRevolute2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Anchor", GetAnchor, SetAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Enable Limit", GetEnableLimit, SetEnableLimit, bool, false, AM_DEFAULT);

+ 8 - 2
Source/Atomic/Atomic2D/ConstraintRevolute2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintRevolute2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintRevolute2D(Context* scontext);
+    ConstraintRevolute2D(Context* context);
     /// Destruct.
     virtual ~ConstraintRevolute2D();
     /// Register object factory.
@@ -57,16 +57,22 @@ public:
 
     /// Return anchor.
     const Vector2& GetAnchor() const { return anchor_; }
+
     /// Return enable limit.
     bool GetEnableLimit() const { return jointDef_.enableLimit; }
+
     /// Return lower angle.
     float GetLowerAngle() const { return jointDef_.lowerAngle; }
+
     /// Return upper angle.
     float GetUpperAngle() const { return jointDef_.upperAngle; }
+
     /// Return enable motor.
     bool GetEnableMotor() const { return jointDef_.enableMotor; }
+
     /// Return motor speed.
     float GetMotorSpeed() const { return jointDef_.motorSpeed; }
+
     /// Return max motor torque.
     float GetMaxMotorTorque() const { return jointDef_.maxMotorTorque; }
 

+ 5 - 4
Source/Atomic/Atomic2D/ConstraintRope2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintRope2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintRope2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -46,7 +47,7 @@ ConstraintRope2D::~ConstraintRope2D()
 void ConstraintRope2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintRope2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Owner Body Anchor", GetOwnerBodyAnchor, SetOwnerBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Other Body Anchor", GetOtherBodyAnchor, SetOtherBodyAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);

+ 4 - 2
Source/Atomic/Atomic2D/ConstraintRope2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintRope2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintRope2D(Context* scontext);
+    ConstraintRope2D(Context* context);
     /// Destruct.
     virtual ~ConstraintRope2D();
     /// Register object factory.
@@ -49,8 +49,10 @@ public:
 
     /// Return owner body anchor.
     const Vector2& GetOwnerBodyAnchor() const { return ownerBodyAnchor_; }
+
     /// Return other body anchor.
     const Vector2& GetOtherBodyAnchor() const { return otherBodyAnchor_; }
+
     /// Return max length.
     float GetMaxLength() const { return jointDef_.maxLength; }
 

+ 4 - 3
Source/Atomic/Atomic2D/ConstraintWeld2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintWeld2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintWeld2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 

+ 4 - 2
Source/Atomic/Atomic2D/ConstraintWeld2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintWeld2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintWeld2D(Context* scontext);
+    ConstraintWeld2D(Context* context);
     /// Destruct.
     virtual ~ConstraintWeld2D();
     /// Register object factory.
@@ -49,8 +49,10 @@ public:
 
     /// Return anchor.
     const Vector2& GetAnchor() const { return anchor_; }
+
     /// Return frequency Hz.
     float GetFrequencyHz() const { return jointDef_.frequencyHz; }
+
     /// Return damping ratio.
     float GetDampingRatio() const { return jointDef_.dampingRatio; }
 

+ 7 - 5
Source/Atomic/Atomic2D/ConstraintWheel2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,9 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/ConstraintWheel2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Atomic2D/ConstraintWheel2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 
@@ -45,7 +46,7 @@ ConstraintWheel2D::~ConstraintWheel2D()
 void ConstraintWheel2D::RegisterObject(Context* context)
 {
     context->RegisterFactory<ConstraintWheel2D>();
-    
+
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Anchor", GetAnchor, SetAnchor, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Axis", GetAxis, SetAxis, Vector2, Vector2::RIGHT, AM_DEFAULT);
@@ -56,6 +57,7 @@ void ConstraintWheel2D::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("Damping Ratio", GetDampingRatio, SetDampingRatio, float, 0.7f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Constraint2D);
 }
+
 void ConstraintWheel2D::SetAnchor(const Vector2& anchor)
 {
     if (anchor == anchor_)
@@ -143,7 +145,7 @@ b2JointDef* ConstraintWheel2D::GetJointDef()
     b2Body* bodyB = otherBody_->GetBody();
     if (!bodyA || !bodyB)
         return 0;
-    
+
     jointDef_.Initialize(bodyA, bodyB, ToB2Vec2(anchor_), ToB2Vec2(axis_));
 
     return &jointDef_;

+ 9 - 3
Source/Atomic/Atomic2D/ConstraintWheel2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -34,7 +34,7 @@ class ATOMIC_API ConstraintWheel2D : public Constraint2D
 
 public:
     /// Construct.
-    ConstraintWheel2D(Context* scontext);
+    ConstraintWheel2D(Context* context);
     /// Destruct.
     virtual ~ConstraintWheel2D();
     /// Register object factory.
@@ -57,19 +57,25 @@ public:
 
     /// Return anchor.
     const Vector2& GetAnchor() const { return anchor_; }
+
     /// Return axis.
     const Vector2& GetAxis() const { return axis_; }
+
     /// Return enable motor.
     bool GetEnableMotor() const { return jointDef_.enableMotor; }
+
     /// Return maxMotor torque.
     float GetMaxMotorTorque() const { return jointDef_.maxMotorTorque; }
+
     /// Return motor speed.
     float GetMotorSpeed() const { return jointDef_.motorSpeed; }
+
     /// Return frequency Hz.
     float GetFrequencyHz() const { return jointDef_.frequencyHz; }
+
     /// Return damping ratio.
     float GetDampingRatio() const { return jointDef_.dampingRatio; }
-   
+
 private:
     /// Return joint def.
     virtual b2JointDef* GetJointDef();

+ 13 - 16
Source/Atomic/Atomic2D/Drawable2D.cpp

@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Graphics/Camera.h"
 #include "../Graphics/Material.h"
@@ -36,7 +37,8 @@ namespace Atomic
 
 const float PIXEL_SIZE = 0.01f;
 
-SourceBatch2D::SourceBatch2D() : drawOrder_(0)
+SourceBatch2D::SourceBatch2D() :
+    drawOrder_(0)
 {
 }
 
@@ -87,7 +89,7 @@ void Drawable2D::SetOrderInLayer(int orderInLayer)
         return;
 
     orderInLayer_ = orderInLayer;
-    
+
     OnDrawOrderChanged();
     MarkNetworkUpdate();
 }
@@ -100,21 +102,16 @@ const Vector<SourceBatch2D>& Drawable2D::GetSourceBatches()
     return sourceBatches_;
 }
 
-void Drawable2D::OnNodeSet(Node* node)
+void Drawable2D::OnSceneSet(Scene* scene)
 {
-    // Do not call Drawable::OnNodeSet(node)
-    if (node)
+    // Do not call Drawable::OnSceneSet(node), as 2D drawable components should not be added to the octree
+    // but are instead rendered through Renderer2D
+    if (scene)
     {
-        Scene* scene = GetScene();
-        if (scene)
-        {
-            renderer_ = scene->GetOrCreateComponent<Renderer2D>();
+        renderer_ = scene->GetOrCreateComponent<Renderer2D>();
 
-            if (IsEnabledEffective())
-                renderer_->AddDrawable(this);
-        }
-
-        node->AddListener(this);
+        if (IsEnabledEffective())
+            renderer_->AddDrawable(this);
     }
     else
     {
@@ -130,4 +127,4 @@ void Drawable2D::OnMarkedDirty(Node* node)
     sourceBatchesDirty_ = true;
 }
 
-}
+}

+ 6 - 4
Source/Atomic/Atomic2D/Drawable2D.h

@@ -80,9 +80,10 @@ public:
     void SetLayer(int layer);
     /// Set order in layer.
     void SetOrderInLayer(int orderInLayer);
-    
+
     /// Return layer.
     int GetLayer() const { return layer_; }
+
     /// Return order in layer.
     int GetOrderInLayer() const { return orderInLayer_; }
 
@@ -90,17 +91,18 @@ public:
     const Vector<SourceBatch2D>& GetSourceBatches();
 
 protected:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
     /// Handle node transform being dirtied.
     virtual void OnMarkedDirty(Node* node);
     /// Handle draw order changed.
     virtual void OnDrawOrderChanged() = 0;
     /// Update source batches.
     virtual void UpdateSourceBatches() = 0;
+
     /// Return draw order by layer and order in layer.
     int GetDrawOrder() const { return (layer_ << 20) + (orderInLayer_ << 10); }
-  
+
     /// Layer.
     int layer_;
     /// Order in layer.

+ 6 - 6
Source/Atomic/Atomic2D/ParticleEffect2D.cpp

@@ -20,15 +20,15 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
-#include "../Atomic2D/ParticleEffect2D.h"
 #include "../Resource/ResourceCache.h"
-#include "../Core/StringUtils.h"
-#include "../Atomic2D/Sprite2D.h"
 #include "../Resource/XMLFile.h"
+#include "../Atomic2D/ParticleEffect2D.h"
+#include "../Atomic2D/Sprite2D.h"
 
 #include "../DebugNew.h"
 
@@ -212,7 +212,7 @@ bool ParticleEffect2D::EndLoad()
 
         loadSpriteName_.Clear();
     }
-    
+
     return true;
 }
 
@@ -506,7 +506,7 @@ void ParticleEffect2D::WriteColor(XMLElement& element, const String& name, const
     child.SetFloat("alpha", color.a_);
 }
 
-void ParticleEffect2D::WriteVector2(XMLElement& element,const String& name,const Vector2& value) const
+void ParticleEffect2D::WriteVector2(XMLElement& element, const String& name, const Vector2& value) const
 {
     XMLElement child = element.CreateChild(name);
     child.SetFloat("x", value.x_);

+ 36 - 2
Source/Atomic/Atomic2D/ParticleEffect2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../Resource/Resource.h"
 #include "../Graphics/GraphicsDefs.h"
+#include "../Resource/Resource.h"
 
 namespace Atomic
 {
@@ -131,72 +131,106 @@ public:
 
     /// Return sprite.
     Sprite2D* GetSprite() const { return sprite_; }
+
     /// Return source position variance.
     const Vector2& GetSourcePositionVariance() const { return sourcePositionVariance_; }
+
     /// Return speed.
     float GetSpeed() const { return speed_; }
+
     /// Return speed variance.
     float GetSpeedVariance() const { return speedVariance_; }
+
     /// Return particle lifespan.
     float GetParticleLifeSpan() const { return particleLifeSpan_; }
+
     /// Return particle lifespan variance.
     float GetParticleLifespanVariance() const { return particleLifespanVariance_; }
+
     /// Return angle.
     float GetAngle() const { return angle_; }
+
     /// Return angle variance.
     float GetAngleVariance() const { return angleVariance_; }
+
     /// Return gravity.
     const Vector2& GetGravity() const { return gravity_; }
+
     /// Return radial acceleration.
     float GetRadialAcceleration() const { return radialAcceleration_; }
+
     /// Return tangential acceleration.
     float GetTangentialAcceleration() const { return tangentialAcceleration_; }
+
     /// Return radial acceleration variance.
     float GetRadialAccelVariance() const { return radialAccelVariance_; }
+
     /// Return tangential acceleration variance.
     float GetTangentialAccelVariance() const { return tangentialAccelVariance_; }
+
     /// Return start color.
     const Color& GetStartColor() const { return startColor_; }
+
     /// Return start color variance.
     const Color& GetStartColorVariance() const { return startColorVariance_; }
+
     /// Return finish color.
     const Color& GetFinishColor() const { return finishColor_; }
+
     /// Return finish color variance.
     const Color& GetFinishColorVariance() const { return finishColorVariance_; }
+
     /// Return max particles.
     int GetMaxParticles() const { return maxParticles_; }
+
     /// Return start particle size.
     float GetStartParticleSize() const { return startParticleSize_; }
+
     /// Return start particle size variance.
     float GetStartParticleSizeVariance() const { return startParticleSizeVariance_; }
+
     /// Return finish particle size.
     float GetFinishParticleSize() const { return finishParticleSize_; }
+
     /// Return finish particle size variance.
     float GetFinishParticleSizeVariance() const { return FinishParticleSizeVariance_; }
+
     /// Return duration.
     float GetDuration() const { return duration_; }
+
     /// Return emitter type.
     EmitterType2D GetEmitterType() const { return emitterType_; }
+
     /// Return max radius.
     float GetMaxRadius() const { return maxRadius_; }
+
     /// Return max radius variance.
     float GetMaxRadiusVariance() const { return maxRadiusVariance_; }
+
     /// Return min radius.
     float GetMinRadius() const { return minRadius_; }
+
     /// Return min radius variance.
     float GetMinRadiusVariance() const { return minRadiusVariance_; }
+
     /// Return rotate per second.
     float GetRotatePerSecond() const { return rotatePerSecond_; }
+
     /// Return rotate per second variance.
     float GetRotatePerSecondVariance() const { return rotatePerSecondVariance_; }
+
     /// Return blend mode.
     BlendMode GetBlendMode() const { return blendMode_; }
+
     /// Return rotation start.
     float GetRotationStart() const { return rotationStart_; }
+
     /// Return rotation start variance.
     float GetRotationStartVariance() const { return rotationStartVariance_; }
+
     /// Return rotation end.
     float GetRotationEnd() const { return rotationEnd_; }
+
     /// Return rotation end variance.
     float GetRotationEndVariance() const { return rotationEndVariance_; }
 

+ 26 - 21
Source/Atomic/Atomic2D/ParticleEmitter2D.cpp

@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Graphics/Camera.h"
 #include "../Graphics/Material.h"
@@ -62,8 +63,10 @@ void ParticleEmitter2D::RegisterObject(Context* context)
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable2D);
-    MIXED_ACCESSOR_ATTRIBUTE("Particle Effect", GetParticleEffectAttr, SetParticleEffectAttr, ResourceRef, ResourceRef(ParticleEffect2D::GetTypeStatic()), AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Sprite ", GetSpriteAttr, SetSpriteAttr, ResourceRef, ResourceRef(Sprite2D::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Particle Effect", GetParticleEffectAttr, SetParticleEffectAttr, ResourceRef,
+        ResourceRef(ParticleEffect2D::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Sprite ", GetSpriteAttr, SetSpriteAttr, ResourceRef, ResourceRef(Sprite2D::GetTypeStatic()),
+        AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE("Blend Mode", GetBlendMode, SetBlendMode, BlendMode, blendModeNames, BLEND_ALPHA, AM_DEFAULT);
 }
 
@@ -94,7 +97,7 @@ void ParticleEmitter2D::SetEffect(ParticleEffect2D* model)
 
     SetSprite(effect_->GetSprite());
     SetBlendMode(effect_->GetBlendMode());
-    SetMaxParticles(effect_->GetMaxParticles());
+    SetMaxParticles((unsigned)effect_->GetMaxParticles());
 
     emitParticleTime_ = 0.0f;
     emissionTime_ = effect_->GetDuration();
@@ -124,7 +127,7 @@ void ParticleEmitter2D::SetBlendMode(BlendMode blendMode)
 
 void ParticleEmitter2D::SetMaxParticles(unsigned maxParticles)
 {
-    maxParticles = Max(maxParticles, 1);
+    maxParticles = (unsigned)Max(maxParticles, 1);
 
     particles_.Resize(maxParticles);
     sourceBatches_[0].vertices_.Reserve(maxParticles * 4);
@@ -165,16 +168,14 @@ ResourceRef ParticleEmitter2D::GetSpriteAttr() const
     return Sprite2D::SaveToResourceRef(sprite_);
 }
 
-void ParticleEmitter2D::OnNodeSet(Node* node)
+void ParticleEmitter2D::OnSceneSet(Scene* scene)
 {
-    Drawable2D::OnNodeSet(node);
+    Drawable2D::OnSceneSet(scene);
 
-    if (node)
-    {
-        Scene* scene = GetScene();
-        if (scene && IsEnabledEffective())
-            SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(ParticleEmitter2D, HandleScenePostUpdate));
-    }
+    if (scene && IsEnabledEffective())
+        SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(ParticleEmitter2D, HandleScenePostUpdate));
+    else if (!scene)
+        UnsubscribeFromEvent(E_SCENEPOSTUPDATE);
 }
 
 void ParticleEmitter2D::OnWorldBoundingBoxUpdate()
@@ -241,7 +242,7 @@ void ParticleEmitter2D::UpdateSourceBatches()
         vertex2.position_ = Vector3(p.position_.x_ + sub, p.position_.y_ + add, 0.0f);
         vertex3.position_ = Vector3(p.position_.x_ + add, p.position_.y_ - sub, 0.0f);
 
-        vertex0.color_ = vertex1.color_ = vertex2.color_  = vertex3.color_ = p.color_.ToUInt();
+        vertex0.color_ = vertex1.color_ = vertex2.color_ = vertex3.color_ = p.color_.ToUInt();
 
         vertices.Push(vertex0);
         vertices.Push(vertex1);
@@ -254,7 +255,7 @@ void ParticleEmitter2D::UpdateSourceBatches()
 
 void ParticleEmitter2D::UpdateMaterial()
 {
-    if (sprite_)
+    if (sprite_ && renderer_)
         sourceBatches_[0].material_ = renderer_->GetMaterial(sprite_->GetTexture(), blendMode_);
     else
         sourceBatches_[0].material_ = 0;
@@ -349,17 +350,21 @@ bool ParticleEmitter2D::EmitParticle(const Vector3& worldPosition, float worldAn
     particle.emitRadiusDelta_ = (minRadius - maxRadius) * invLifespan;
     particle.emitRotation_ = worldAngle + effect_->GetAngle() + effect_->GetAngleVariance() * Random(-1.0f, 1.0f);
     particle.emitRotationDelta_ = effect_->GetRotatePerSecond() + effect_->GetRotatePerSecondVariance() * Random(-1.0f, 1.0f);
-    particle.radialAcceleration_ = worldScale * (effect_->GetRadialAcceleration() + effect_->GetRadialAccelVariance() * Random(-1.0f, 1.0f));
-    particle.tangentialAcceleration_ = worldScale * (effect_->GetTangentialAcceleration() + effect_->GetTangentialAccelVariance() * Random(-1.0f, 1.0f));
-
-    float startSize = worldScale * Max(0.1f, effect_->GetStartParticleSize() + effect_->GetStartParticleSizeVariance() * Random(-1.0f, 1.0f));
-    float finishSize = worldScale * Max(0.1f, effect_->GetFinishParticleSize() + effect_->GetFinishParticleSizeVariance() * Random(-1.0f, 1.0f));
+    particle.radialAcceleration_ =
+        worldScale * (effect_->GetRadialAcceleration() + effect_->GetRadialAccelVariance() * Random(-1.0f, 1.0f));
+    particle.tangentialAcceleration_ =
+        worldScale * (effect_->GetTangentialAcceleration() + effect_->GetTangentialAccelVariance() * Random(-1.0f, 1.0f));
+
+    float startSize =
+        worldScale * Max(0.1f, effect_->GetStartParticleSize() + effect_->GetStartParticleSizeVariance() * Random(-1.0f, 1.0f));
+    float finishSize =
+        worldScale * Max(0.1f, effect_->GetFinishParticleSize() + effect_->GetFinishParticleSizeVariance() * Random(-1.0f, 1.0f));
     particle.size_ = startSize;
     particle.sizeDelta_ = (finishSize - startSize) * invLifespan;
 
     particle.color_ = effect_->GetStartColor() + effect_->GetStartColorVariance() * Random(-1.0f, 1.0f);
     Color endColor = effect_->GetFinishColor() + effect_->GetFinishColorVariance() * Random(-1.0f, 1.0f);
-    particle.colorDelta_= (endColor - particle.color_) * invLifespan;
+    particle.colorDelta_ = (endColor - particle.color_) * invLifespan;
 
     particle.rotation_ = worldAngle + effect_->GetRotationStart() + effect_->GetRotationStartVariance() * Random(-1.0f, 1.0f);
     float endRotation = worldAngle + effect_->GetRotationEnd() + effect_->GetRotationEndVariance() * Random(-1.0f, 1.0f);

+ 6 - 4
Source/Atomic/Atomic2D/ParticleEmitter2D.h

@@ -31,7 +31,7 @@ class ParticleEffect2D;
 class Sprite2D;
 
 /// 2D particle.
- struct Particle2D
+struct Particle2D
 {
     /// Time to live.
     float timeToLive_;
@@ -87,7 +87,7 @@ public:
 
     /// Handle enabled/disabled state change.
     virtual void OnSetEnabled();
-    
+
     /// Set particle effect.
     void SetEffect(ParticleEffect2D* effect);
     /// Set sprite.
@@ -101,8 +101,10 @@ public:
     ParticleEffect2D* GetEffect() const;
     /// Return sprite.
     Sprite2D* GetSprite() const;
+
     /// Return blend mode.
     BlendMode GetBlendMode() const { return blendMode_; }
+
     /// Return max particles.
     unsigned GetMaxParticles() const { return particles_.Size(); }
 
@@ -116,8 +118,8 @@ public:
     ResourceRef GetSpriteAttr() const;
 
 private:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
     /// Recalculate the world-space bounding box.
     virtual void OnWorldBoundingBoxUpdate();
     /// Handle draw order changed.

+ 2 - 2
Source/Atomic/Atomic2D/PhysicsUtils2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -63,7 +63,7 @@ inline bool operator == (const b2Vec2& left, const b2Vec2& right)
 }
 */
 
-inline bool operator != (const b2Vec2& left, const b2Vec2& right)
+inline bool operator !=(const b2Vec2& left, const b2Vec2& right)
 {
     return left.x != right.x || left.y != right.y;
 }

+ 22 - 19
Source/Atomic/Atomic2D/PhysicsWorld2D.cpp

@@ -20,20 +20,20 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Graphics/DebugRenderer.h"
 #include "../Graphics/Graphics.h"
+#include "../Graphics/Renderer.h"
 #include "../IO/Log.h"
+#include "../Scene/Scene.h"
+#include "../Scene/SceneEvents.h"
 #include "../Atomic2D/PhysicsEvents2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/PhysicsWorld2D.h"
-#include "../Core/Profiler.h"
-#include "../Graphics/Renderer.h"
 #include "../Atomic2D/RigidBody2D.h"
-#include "../Scene/Scene.h"
-#include "../Scene/SceneEvents.h"
-#include "../Graphics/Viewport.h"
 
 #include "../DebugNew.h"
 
@@ -94,8 +94,10 @@ void PhysicsWorld2D::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("Sub Stepping", GetSubStepping, SetSubStepping, bool, false, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Gravity", GetGravity, SetGravity, Vector2, DEFAULT_GRAVITY, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Auto Clear Forces", GetAutoClearForces, SetAutoClearForces, bool, false, AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Velocity Iterations", GetVelocityIterations, SetVelocityIterations, int, DEFAULT_VELOCITY_ITERATIONS, AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Position Iterations", GetPositionIterations, SetPositionIterations, int, DEFAULT_POSITION_ITERATIONS, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Velocity Iterations", GetVelocityIterations, SetVelocityIterations, int, DEFAULT_VELOCITY_ITERATIONS,
+        AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Position Iterations", GetPositionIterations, SetPositionIterations, int, DEFAULT_POSITION_ITERATIONS,
+        AM_DEFAULT);
 }
 
 void PhysicsWorld2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
@@ -397,7 +399,8 @@ protected:
     unsigned collisionMask_;
 };
 
-void PhysicsWorld2D::Raycast(PODVector<PhysicsRaycastResult2D>& results, const Vector2& startPoint, const Vector2& endPoint, unsigned collisionMask)
+void PhysicsWorld2D::Raycast(PODVector<PhysicsRaycastResult2D>& results, const Vector2& startPoint, const Vector2& endPoint,
+    unsigned collisionMask)
 {
     results.Clear();
 
@@ -428,7 +431,7 @@ public:
         if ((fixture->GetFilterData().maskBits & collisionMask_) == 0)
             return true;
 
-        float distance = (ToVector2(point)- startPoint_).Length();
+        float distance = (ToVector2(point) - startPoint_).Length();
         if (distance < minDistance_)
         {
             minDistance_ = distance;
@@ -453,7 +456,8 @@ private:
     float minDistance_;
 };
 
-void PhysicsWorld2D::RaycastSingle(PhysicsRaycastResult2D& result, const Vector2& startPoint, const Vector2& endPoint, unsigned collisionMask)
+void PhysicsWorld2D::RaycastSingle(PhysicsRaycastResult2D& result, const Vector2& startPoint, const Vector2& endPoint,
+    unsigned collisionMask)
 {
     result.body_ = 0;
 
@@ -520,7 +524,7 @@ RigidBody2D* PhysicsWorld2D::GetRigidBody(const Vector2& point, unsigned collisi
 RigidBody2D* PhysicsWorld2D::GetRigidBody(int screenX, int screenY, unsigned collisionMask)
 {
     Renderer* renderer = GetSubsystem<Renderer>();
-    for (unsigned i = 0; i  < renderer->GetNumViewports(); ++i)
+    for (unsigned i = 0; i < renderer->GetNumViewports(); ++i)
     {
         Viewport* viewport = renderer->GetViewport(i);
         // Find a viewport with same scene
@@ -603,14 +607,13 @@ bool PhysicsWorld2D::GetAutoClearForces() const
     return world_->GetAutoClearForces();
 }
 
-void PhysicsWorld2D::OnNodeSet(Node* node)
+void PhysicsWorld2D::OnSceneSet(Scene* scene)
 {
     // Subscribe to the scene subsystem update, which will trigger the physics simulation step
-    if (node)
-    {
-        scene_ = GetScene();
-        SubscribeToEvent(node, E_SCENESUBSYSTEMUPDATE, HANDLER(PhysicsWorld2D, HandleSceneSubsystemUpdate));
-    }
+    if (scene)
+        SubscribeToEvent(scene, E_SCENESUBSYSTEMUPDATE, HANDLER(PhysicsWorld2D, HandleSceneSubsystemUpdate));
+    else
+        UnsubscribeFromEvent(E_SCENESUBSYSTEMUPDATE);
 }
 
 void PhysicsWorld2D::HandleSceneSubsystemUpdate(StringHash eventType, VariantMap& eventData)
@@ -644,7 +647,7 @@ void PhysicsWorld2D::SendBeginContactEvents()
 
 void PhysicsWorld2D::SendEndContactEvents()
 {
-   if (endContactInfos_.Empty())
+    if (endContactInfos_.Empty())
         return;
 
     using namespace PhysicsEndContact2D;

+ 25 - 8
Source/Atomic/Atomic2D/PhysicsWorld2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "../Scene/Component.h"
+
 #include <Box2D/Box2D.h>
 
 namespace Atomic
@@ -35,12 +36,16 @@ class RigidBody2D;
 struct ATOMIC_API PhysicsRaycastResult2D
 {
     /// Construct with defaults.
-    PhysicsRaycastResult2D() : body_(0)
+    PhysicsRaycastResult2D() :
+        body_(0)
     {
     }
 
     /// Test for inequality, added to prevent GCC from complaining.
-    bool operator != (const PhysicsRaycastResult2D& rhs) const { return position_ != rhs.position_ || normal_ != rhs.normal_ || distance_ != rhs.distance_ || body_ != rhs.body_; }
+    bool operator !=(const PhysicsRaycastResult2D& rhs) const
+    {
+        return position_ != rhs.position_ || normal_ != rhs.normal_ || distance_ != rhs.distance_ || body_ != rhs.body_;
+    }
 
     /// Hit worldspace position.
     Vector2 position_;
@@ -59,7 +64,7 @@ class ATOMIC_API PhysicsWorld2D : public Component, public b2ContactListener, pu
 
 public:
     /// Construct.
-    PhysicsWorld2D(Context* scontext);
+    PhysicsWorld2D(Context* context);
     /// Destruct.
     virtual ~PhysicsWorld2D();
     /// Register object factory.
@@ -124,9 +129,11 @@ public:
     void RemoveRigidBody(RigidBody2D* rigidBody);
 
     /// Perform a physics world raycast and return all hits.
-    void Raycast(PODVector<PhysicsRaycastResult2D>& results, const Vector2& startPoint, const Vector2& endPoint, unsigned collisionMask = M_MAX_UNSIGNED);
+    void Raycast(PODVector<PhysicsRaycastResult2D>& results, const Vector2& startPoint, const Vector2& endPoint,
+        unsigned collisionMask = M_MAX_UNSIGNED);
     /// Perform a physics world raycast and return the closest hit.
-    void RaycastSingle(PhysicsRaycastResult2D& result, const Vector2& startPoint, const Vector2& endPoint, unsigned collisionMask = M_MAX_UNSIGNED);
+    void RaycastSingle(PhysicsRaycastResult2D& result, const Vector2& startPoint, const Vector2& endPoint,
+        unsigned collisionMask = M_MAX_UNSIGNED);
     /// Return rigid body at point.
     RigidBody2D* GetRigidBody(const Vector2& point, unsigned collisionMask = M_MAX_UNSIGNED);
     /// Return rigid body at screen point.
@@ -136,14 +143,19 @@ public:
 
     /// Return draw shape.
     bool GetDrawShape() const { return (m_drawFlags & e_shapeBit) != 0; }
+
     /// Return draw joint.
     bool GetDrawJoint() const { return (m_drawFlags & e_jointBit) != 0; }
+
     /// Return draw aabb.
     bool GetDrawAabb() const { return (m_drawFlags & e_aabbBit) != 0; }
+
     /// Return draw pair.
     bool GetDrawPair() const { return (m_drawFlags & e_pairBit) != 0; }
+
     /// Return draw center of mass.
     bool GetDrawCenterOfMass() const { return (m_drawFlags & e_centerOfMassBit) != 0; }
+
     /// Return allow sleeping.
     bool GetAllowSleeping() const;
     /// Return warm starting.
@@ -154,23 +166,28 @@ public:
     bool GetSubStepping() const;
     /// Return auto clear forces.
     bool GetAutoClearForces() const;
+
     /// Return gravity.
     const Vector2& GetGravity() const { return gravity_; }
+
     /// Return velocity iterations.
     int GetVelocityIterations() const { return velocityIterations_; }
+
     /// Return position iterations.
     int GetPositionIterations() const { return positionIterations_; }
 
     /// Return the Box2D physics world.
     b2World* GetWorld() { return world_; }
+
     /// Set node dirtying to be disregarded.
     void SetApplyingTransforms(bool enable) { applyingTransforms_ = enable; }
+
     /// Return whether node dirtying should be disregarded.
     bool IsApplyingTransforms() const { return applyingTransforms_; }
 
 protected:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
 
 private:
     /// Handle the scene subsystem update event, step simulation here.

+ 13 - 10
Source/Atomic/Atomic2D/Renderer2D.cpp

@@ -20,8 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Container/Sort.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Core/Profiler.h"
 #include "../Core/WorkQueue.h"
@@ -50,10 +50,11 @@ extern const char* blendModeNames[];
 
 static const unsigned MASK_VERTEX2D = MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1;
 
-ViewBatchInfo2D::ViewBatchInfo2D() : vertexBufferUpdateFrameNumber_(0),
+ViewBatchInfo2D::ViewBatchInfo2D() :
+    vertexBufferUpdateFrameNumber_(0),
     indexCount_(0),
     vertexCount_(0),
-    batchUpdatedFrameNumber_(0), 
+    batchUpdatedFrameNumber_(0),
     batchCount_(0)
 {
 }
@@ -131,7 +132,7 @@ void Renderer2D::UpdateGeometry(const FrameInfo& frame)
     for (HashMap<Camera*, ViewBatchInfo2D>::ConstIterator i = viewBatchInfos_.Begin(); i != viewBatchInfos_.End(); ++i)
     {
         if (i->second_.batchUpdatedFrameNumber_ == frame_.frameNumber_)
-            indexCount = Max((int)indexCount, (int)i->second_.indexCount_);
+            indexCount = (unsigned)Max((int)indexCount, (int)i->second_.indexCount_);
     }
 
     // Fill index buffer
@@ -312,6 +313,7 @@ SharedPtr<Material> Renderer2D::CreateMaterial(Texture2D* texture, BlendMode ble
 
     return newMaterial;
 }
+
 void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex)
 {
     Renderer2D* renderer = reinterpret_cast<Renderer2D*>(item->aux_);
@@ -354,7 +356,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
         WorkQueue* queue = GetSubsystem<WorkQueue>();
         int numWorkItems = queue->GetNumThreads() + 1; // Worker threads + main thread
         int drawablesPerItem = drawables_.Size() / numWorkItems;
-        
+
         PODVector<Drawable2D*>::Iterator start = drawables_.Begin();
         for (int i = 0; i < numWorkItems; ++i)
         {
@@ -366,11 +368,11 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
             PODVector<Drawable2D*>::Iterator end = drawables_.End();
             if (i < numWorkItems - 1 && end - start > drawablesPerItem)
                 end = start + drawablesPerItem;
-            
+
             item->start_ = &(*start);
             item->end_ = &(*end);
             queue->AddWorkItem(item);
-            
+
             start = end;
         }
 
@@ -378,7 +380,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
     }
 
     ViewBatchInfo2D& viewBatchInfo = viewBatchInfos_[camera];
-    
+
     // Create vertex buffer
     if (!viewBatchInfo.vertexBuffer_)
         viewBatchInfo.vertexBuffer_ = new VertexBuffer(context_);
@@ -495,7 +497,8 @@ void Renderer2D::UpdateViewBatchInfo(ViewBatchInfo2D& viewBatchInfo, Camera* cam
     viewBatchInfo.batchUpdatedFrameNumber_ = frame_.frameNumber_;
 }
 
-void Renderer2D::AddViewBatch(ViewBatchInfo2D& viewBatchInfo, Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount)
+void Renderer2D::AddViewBatch(ViewBatchInfo2D& viewBatchInfo, Material* material, unsigned indexStart, unsigned indexCount,
+    unsigned vertexStart, unsigned vertexCount)
 {
     if (!material || indexCount == 0 || vertexCount == 0)
         return;

+ 3 - 1
Source/Atomic/Atomic2D/Renderer2D.h

@@ -111,7 +111,9 @@ private:
     /// Update view batch info.
     void UpdateViewBatchInfo(ViewBatchInfo2D& viewBatchInfo, Camera* camera);
     /// Add view batch.
-    void AddViewBatch(ViewBatchInfo2D& viewBatchInfo, Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount);
+    void AddViewBatch
+        (ViewBatchInfo2D& viewBatchInfo, Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart,
+            unsigned vertexCount);
 
     /// Index buffer.
     SharedPtr<IndexBuffer> indexBuffer_;

+ 23 - 12
Source/Atomic/Atomic2D/RigidBody2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/CollisionShape2D.h"
-#include "../Atomic2D/Constraint2D.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../IO/Log.h"
+#include "../Scene/Scene.h"
+#include "../Atomic2D/CollisionShape2D.h"
+#include "../Atomic2D/Constraint2D.h"
 #include "../Atomic2D/PhysicsUtils2D.h"
 #include "../Atomic2D/PhysicsWorld2D.h"
 #include "../Atomic2D/RigidBody2D.h"
-#include "../Scene/Scene.h"
 
 #include "../DebugNew.h"
 
@@ -87,7 +88,6 @@ void RigidBody2D::RegisterObject(Context* context)
     MIXED_ACCESSOR_ATTRIBUTE("Linear Velocity", GetLinearVelocity, SetLinearVelocity, Vector2, Vector2::ZERO, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Angular Velocity", GetAngularVelocity, SetAngularVelocity, float, 0.0f, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("CastShadows", GetCastShadows, SetCastShadows, bool, true, AM_DEFAULT);
-
 }
 
 
@@ -168,7 +168,7 @@ void RigidBody2D::SetUseFixtureMass(bool useFixtureMass)
 
     if (body_)
     {
-       if (useFixtureMass_)
+        if (useFixtureMass_)
             body_->ResetMassData();
         else
             body_->SetMassData(&massData_);
@@ -350,7 +350,7 @@ void RigidBody2D::CreateBody()
 
     for (unsigned i = 0; i < constraints_.Size(); ++i)
     {
-            if (constraints_[i])
+        if (constraints_[i])
             constraints_[i]->CreateJoint();
     }
 }
@@ -476,17 +476,28 @@ float RigidBody2D::GetAngularVelocity() const
 
 void RigidBody2D::OnNodeSet(Node* node)
 {
-    Component::OnNodeSet(node);
-
     if (node)
-    {
         node->AddListener(this);
-        Scene* scene = GetScene();
+}
+
+void RigidBody2D::OnSceneSet(Scene* scene)
+{
+    if (scene)
+    {
         physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
 
         CreateBody();
         physicsWorld_->AddRigidBody(this);
     }
+    else
+    {
+        if (physicsWorld_)
+        {
+            ReleaseBody();
+            physicsWorld_->RemoveRigidBody(this);
+            physicsWorld_.Reset();
+        }
+    }
 }
 
 void RigidBody2D::OnMarkedDirty(Node* node)

+ 15 - 3
Source/Atomic/Atomic2D/RigidBody2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -23,6 +23,7 @@
 #pragma once
 
 #include "../Scene/Component.h"
+
 #include <Box2D/Box2D.h>
 
 namespace Atomic
@@ -47,7 +48,7 @@ class ATOMIC_API RigidBody2D : public Component
 
 public:
     /// Construct.
-    RigidBody2D(Context* scontext);
+    RigidBody2D(Context* context);
     /// Destruct.
     virtual ~RigidBody2D();
     /// Register object factory.
@@ -85,7 +86,7 @@ public:
     /// Set angular velocity.
     void SetAngularVelocity(float angularVelocity);
     /// Apply force.
-    void ApplyForce(const Vector2& force, const Vector2& point,  bool wake);
+    void ApplyForce(const Vector2& force, const Vector2& point, bool wake);
     /// Apply force to center.
     void ApplyForceToCenter(const Vector2& force, bool wake);
     /// Apply Torque.
@@ -113,26 +114,35 @@ public:
 
     /// Return body type.
     BodyType2D GetBodyType() const { return (BodyType2D)bodyDef_.type; }
+
     /// Return Mass.
     float GetMass() const;
     /// Return inertia.
     float GetInertia() const;
     /// Return mass center.
     Vector2 GetMassCenter() const;
+
     /// Return use fixture mass.
     bool GetUseFixtureMass() const { return useFixtureMass_; }
+
     /// Return linear damping.
     float GetLinearDamping() const { return bodyDef_.linearDamping; }
+
     /// Return angular damping.
     float GetAngularDamping() const { return bodyDef_.angularDamping; }
+
     /// Return allow sleep.
     bool IsAllowSleep() const { return bodyDef_.allowSleep; }
+
     /// Return fixed rotation.
     bool IsFixedRotation() const { return bodyDef_.fixedRotation; }
+
     /// Return bullet.
     bool IsBullet() const { return bodyDef_.bullet; }
+
     /// Return gravity scale.
     float GetGravityScale() const { return bodyDef_.gravityScale; }
+
     /// Return awake.
     bool IsAwake() const;
     /// Return linear velocity.
@@ -150,6 +160,8 @@ public:
 private:
     /// Handle node being assigned.
     virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
     /// Handle node transform being dirtied.
     virtual void OnMarkedDirty(Node* node);
 

+ 9 - 8
Source/Atomic/Atomic2D/Sprite2D.cpp

@@ -20,14 +20,15 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Graphics/Texture2D.h"
 #include "../IO/Deserializer.h"
 #include "../Resource/ResourceCache.h"
 #include "../Atomic2D/Drawable2D.h"
 #include "../Atomic2D/Sprite2D.h"
 #include "../Atomic2D/SpriteSheet2D.h"
-#include "../Graphics/Texture2D.h"
 
 #include "../DebugNew.h"
 
@@ -35,7 +36,7 @@ namespace Atomic
 {
 
 Sprite2D::Sprite2D(Context* context) :
-    Resource(context), 
+    Resource(context),
     hotSpot_(0.5f, 0.5f),
     offset_(0, 0)
 {
@@ -56,7 +57,7 @@ bool Sprite2D::BeginLoad(Deserializer& source)
 {
     if (GetName().Empty())
         SetName(source.GetName());
-    
+
     // Reload
     if (texture_)
         loadTexture_ = texture_;
@@ -75,7 +76,7 @@ bool Sprite2D::BeginLoad(Deserializer& source)
         loadTexture_.Reset();
         return false;
     }
-    
+
     return true;
 }
 
@@ -87,7 +88,7 @@ bool Sprite2D::EndLoad()
     {
         success = true;
         SetTexture(loadTexture_);
-        
+
         if (texture_)
             SetRectangle(IntRect(0, 0, texture_->GetWidth(), texture_->GetHeight()));
     }
@@ -138,7 +139,7 @@ bool Sprite2D::GetDrawRectangle(Rect& rect, const Vector2& hotSpot, bool flipX,
         return false;
 
     float width = (float)rectangle_.Width() * PIXEL_SIZE;
-    float height = (float)rectangle_.Height() * PIXEL_SIZE;        
+    float height = (float)rectangle_.Height() * PIXEL_SIZE;
 
     float hotSpotX = flipX ? (1.0f - hotSpot.x_) : hotSpot.x_;
     float hotSpotY = flipY ? (1.0f - hotSpot.y_) : hotSpot.y_;
@@ -174,7 +175,7 @@ bool Sprite2D::GetTextureRectangle(Rect& rect, bool flipX, bool flipY) const
 
     if (flipX)
         Swap(rect.min_.x_, rect.max_.x_);
-    
+
     if (flipY)
         Swap(rect.min_.y_, rect.max_.y_);
 

+ 4 - 0
Source/Atomic/Atomic2D/Sprite2D.h

@@ -61,12 +61,16 @@ public:
 
     /// Return texture.
     Texture2D* GetTexture() const { return texture_; }
+
     /// Return rectangle.
     const IntRect& GetRectangle() const { return rectangle_; }
+
     /// Return hot spot.
     const Vector2& GetHotSpot() const { return hotSpot_; }
+
     /// Return offset.
     const IntVector2& GetOffset() const { return offset_; }
+
     /// Return sprite sheet.
     SpriteSheet2D* GetSpriteSheet() const { return spriteSheet_; }
 

+ 14 - 15
Source/Atomic/Atomic2D/SpriteSheet2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,18 +20,18 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Graphics/Texture2D.h"
 #include "../IO/Deserializer.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
 #include "../Resource/PListFile.h"
 #include "../Resource/ResourceCache.h"
-#include "../IO/Serializer.h"
+#include "../Resource/XMLFile.h"
 #include "../Atomic2D/Sprite2D.h"
 #include "../Atomic2D/SpriteSheet2D.h"
-#include "../Graphics/Texture2D.h"
-#include "../Resource/XMLFile.h"
 
 #include "../DebugNew.h"
 
@@ -123,9 +123,9 @@ bool SpriteSheet2D::BeginLoadFromPListFile(Deserializer& source)
     SetMemoryUse(source.GetSize());
 
     const PListValueMap& root = loadPListFile_->GetRoot();
-    const PListValueMap& metadata = root["metadata"].GetValueMap();
-    const String& textureFileName = metadata["realTextureFileName"].GetString();
-    
+    const PListValueMap& metadata = root["metadata"]->GetValueMap();
+    const String& textureFileName = metadata["realTextureFileName"]->GetString();
+
     // If we're async loading, request the texture now. Finish during EndLoad().
     loadTextureName_ = GetParentPath(GetName()) + textureFileName;
     if (GetAsyncLoadState() == ASYNC_LOADING)
@@ -147,32 +147,31 @@ bool SpriteSheet2D::EndLoadFromPListFile()
     }
 
     const PListValueMap& root = loadPListFile_->GetRoot();
-
-    const PListValueMap& frames = root["frames"].GetValueMap();
+    const PListValueMap& frames = root["frames"]->GetValueMap();
     for (PListValueMap::ConstIterator i = frames.Begin(); i != frames.End(); ++i)
     {
         String name = i->first_.Split('.')[0];
 
         const PListValueMap& frameInfo = i->second_.GetValueMap();
-        if (frameInfo["rotated"].GetBool())
+        if (frameInfo["rotated"]->GetBool())
         {
             LOGWARNING("Rotated sprite is not support now");
             continue;
         }
 
-        IntRect rectangle = frameInfo["frame"].GetIntRect();
+        IntRect rectangle = frameInfo["frame"]->GetIntRect();
         Vector2 hotSpot(0.5f, 0.5f);
         IntVector2 offset(0, 0);
 
-        IntRect sourceColorRect = frameInfo["sourceColorRect"].GetIntRect();
+        IntRect sourceColorRect = frameInfo["sourceColorRect"]->GetIntRect();
         if (sourceColorRect.left_ != 0 && sourceColorRect.top_ != 0)
         {
             offset.x_ = -sourceColorRect.left_;
             offset.y_ = -sourceColorRect.top_;
 
-            IntVector2 sourceSize = frameInfo["sourceSize"].GetIntVector2();
+            IntVector2 sourceSize = frameInfo["sourceSize"]->GetIntVector2();
             hotSpot.x_ = ((float)offset.x_ + sourceSize.x_ / 2) / rectangle.Width();
-            hotSpot.y_ = 1.0f - ((float)offset.y_ + sourceSize.y_/ 2) / rectangle.Height();
+            hotSpot.y_ = 1.0f - ((float)offset.y_ + sourceSize.y_ / 2) / rectangle.Height();
         }
 
         DefineSprite(name, rectangle, hotSpot, offset);

+ 4 - 2
Source/Atomic/Atomic2D/SpriteSheet2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -52,10 +52,12 @@ public:
 
     /// Return texture.
     Texture2D* GetTexture() const { return texture_; }
+
     /// Return sprite.
     Sprite2D* GetSprite(const String& name) const;
     /// Define sprite.
-    void DefineSprite(const String& name, const IntRect& rectangle, const Vector2& hotSpot = Vector2(0.5f, 0.5f), const IntVector2& offset = IntVector2::ZERO);
+    void DefineSprite(const String& name, const IntRect& rectangle, const Vector2& hotSpot = Vector2(0.5f, 0.5f),
+        const IntVector2& offset = IntVector2::ZERO);
 
     /// Return sprite mapping.
     const HashMap<String, SharedPtr<Sprite2D> >& GetSpriteMapping() const { return spriteMapping_; }

+ 8 - 5
Source/Atomic/Atomic2D/StaticSprite2D.cpp

@@ -20,7 +20,8 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Texture2D.h"
@@ -60,12 +61,14 @@ void StaticSprite2D::RegisterObject(Context* context)
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable2D);
-    MIXED_ACCESSOR_ATTRIBUTE("Sprite", GetSpriteAttr, SetSpriteAttr, ResourceRef, ResourceRef(Sprite2D::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Sprite", GetSpriteAttr, SetSpriteAttr, ResourceRef, ResourceRef(Sprite2D::GetTypeStatic()),
+        AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE("Blend Mode", GetBlendMode, SetBlendMode, BlendMode, blendModeNames, BLEND_ALPHA, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Flip X", GetFlipX, SetFlipX, bool, false, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Flip Y", GetFlipY, SetFlipY, bool, false, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Color", GetColor, SetColor, Color, Color::WHITE, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Custom material", GetCustomMaterialAttr, SetCustomMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Custom material", GetCustomMaterialAttr, SetCustomMaterialAttr, ResourceRef,
+        ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
 }
 
 void StaticSprite2D::SetSprite(Sprite2D* sprite)
@@ -262,7 +265,7 @@ void StaticSprite2D::UpdateSourceBatches()
     Rect textureRect;
     if (!sprite_->GetTextureRectangle(textureRect, flipX_, flipY_))
         return;
-    
+
     /*
     V1---------V2
     |         / |
@@ -289,7 +292,7 @@ void StaticSprite2D::UpdateSourceBatches()
     vertex2.uv_ = textureRect.max_;
     vertex3.uv_ = Vector2(textureRect.max_.x_, textureRect.min_.y_);
 
-    vertex0.color_ = vertex1.color_ = vertex2.color_  = vertex3.color_ = color_.ToUInt();
+    vertex0.color_ = vertex1.color_ = vertex2.color_ = vertex3.color_ = color_.ToUInt();
 
     vertices.Push(vertex0);
     vertices.Push(vertex1);

+ 8 - 0
Source/Atomic/Atomic2D/StaticSprite2D.h

@@ -65,20 +65,28 @@ public:
 
     /// Return sprite.
     Sprite2D* GetSprite() const;
+
     /// Return blend mode.
     BlendMode GetBlendMode() const { return blendMode_; }
+
     /// Return flip X.
     bool GetFlipX() const { return flipX_; }
+
     /// Return flip Y.
     bool GetFlipY() const { return flipY_; }
+
     /// Return color.
     const Color& GetColor() const { return color_; }
+
     /// Return alpha.
     float GetAlpha() const { return color_.a_; }
+
     /// Return use hot spot.
     bool GetUseHotSpot() const { return useHotSpot_; }
+
     /// Return hot spot.
     const Vector2& GetHotSpot() const { return hotSpot_; }
+
     /// Return custom material.
     Material* GetCustomMaterial() const;
 

+ 6 - 16
Source/Atomic/Atomic2D/TileMap2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,11 +20,12 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Graphics/DebugRenderer.h"
-#include "../Scene/Node.h"
 #include "../Resource/ResourceCache.h"
+#include "../Scene/Node.h"
 #include "../Scene/Scene.h"
 #include "../Atomic2D/TileMap2D.h"
 #include "../Atomic2D/TileMapLayer2D.h"
@@ -52,7 +53,8 @@ void TileMap2D::RegisterObject(Context* context)
     context->RegisterFactory<TileMap2D>(ATOMIC2D_CATEGORY);
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Tmx File", GetTmxFileAttr, SetTmxFileAttr, ResourceRef, ResourceRef(TmxFile2D::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Tmx File", GetTmxFileAttr, SetTmxFileAttr, ResourceRef, ResourceRef(TmxFile2D::GetTypeStatic()),
+        AM_DEFAULT);
 }
 
 void TileMap2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
@@ -187,16 +189,4 @@ ResourceRef TileMap2D::GetTmxFileAttr() const
     return GetResourceRef(tmxFile_, TmxFile2D::GetTypeStatic());
 }
 
-void TileMap2D::OnNodeSet(Node* node)
-{
-    if (!node)
-    {
-        if (rootNode_)
-            rootNode_->Remove();
-
-        rootNode_ = 0;
-        layers_.Clear();
-    }
-}
-
 }

+ 3 - 4
Source/Atomic/Atomic2D/TileMap2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -54,11 +54,13 @@ public:
 
     /// Return tmx file.
     TmxFile2D* GetTmxFile() const;
+
     /// Return information.
     const TileMapInfo2D& GetInfo() const { return info_; }
 
     /// Return number of layers.
     unsigned GetNumLayers() const { return layers_.Size(); }
+
     /// Return tile map layer at index.
     TileMapLayer2D* GetLayer(unsigned index) const;
 
@@ -75,9 +77,6 @@ public:
     ResourceRef GetTmxFileAttr() const;
 
 private:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
-
     /// Tmx file.
     SharedPtr<TmxFile2D> tmxFile_;
     /// Tile map information.

+ 18 - 16
Source/Atomic/Atomic2D/TileMapDefs2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,17 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic2D/TileMapDefs2D.h"
-#include "../Atomic2D/TmxFile2D.h"
+#include "../Precompiled.h"
+
 #include "../Resource/XMLElement.h"
+#include "../Atomic2D/TileMapDefs2D.h"
 #include "../Atomic2D/CollisionBox2D.h"
-#include "../Scene/Node.h"
 
 #include "../DebugNew.h"
 
+#include "../Scene/Node.h"
+#include "../Atomic2D/TmxFile2D.h"
+
 namespace Atomic
 {
 extern ATOMIC_API const float PIXEL_SIZE;
@@ -53,7 +55,8 @@ Vector2 TileMapInfo2D::ConvertPosition(const Vector2& position) const
     case O_ISOMETRIC:
         {
             Vector2 index = position * PIXEL_SIZE / tileHeight_;
-            return Vector2((width_ + index.x_ - index.y_) * tileWidth_ * 0.5f, (height_ * 2.0f - index.x_ - index.y_) * tileHeight_ * 0.5f);
+            return Vector2((width_ + index.x_ - index.y_) * tileWidth_ * 0.5f,
+                (height_ * 2.0f - index.x_ - index.y_) * tileHeight_ * 0.5f);
         }
 
     case O_STAGGERED:
@@ -78,7 +81,7 @@ Vector2 TileMapInfo2D::TileIndexToPosition(int x, int y) const
         if (y % 2 == 0)
             return Vector2(x * tileWidth_, (height_ - 1 - y) * 0.5f * tileHeight_);
         else
-            return Vector2((x + 0.5f) * tileWidth_, (height_ - 1 - y)  * 0.5f * tileHeight_);
+            return Vector2((x + 0.5f) * tileWidth_, (height_ - 1 - y) * 0.5f * tileHeight_);
 
     case O_ORTHOGONAL:
     default:
@@ -93,12 +96,12 @@ bool TileMapInfo2D::PositionToTileIndex(int& x, int& y, const Vector2& position)
     switch (orientation_)
     {
     case O_ISOMETRIC:
-        {
-            int x_sub_y = (int)(position.x_ * 2.0f / tileWidth_ + 1 - width_);
-            int x_add_y = (int)(height_ * 2.0f - position.y_ * 2.0f / tileHeight_ - 2.0f);
-            x = (x_sub_y - x_add_y) / 2;
-            y = (x_sub_y - x_add_y) / 2;
-        }
+    {
+        int x_sub_y = (int)(position.x_ * 2.0f / tileWidth_ + 1 - width_);
+        int x_add_y = (int)(height_ * 2.0f - position.y_ * 2.0f / tileHeight_ - 2.0f);
+        x = (x_sub_y - x_add_y) / 2;
+        y = (x_sub_y - x_add_y) / 2;
+    }
         break;
 
     case O_STAGGERED:
@@ -150,8 +153,8 @@ const String& PropertySet2D::GetProperty(const String& name) const
     return i->second_;
 }
 
-Tile2D::Tile2D() : 
-    gid_(0) 
+Tile2D::Tile2D() :
+    gid_(0)
 {
 }
 
@@ -164,7 +167,6 @@ TmxObjectGroup2D* Tile2D::GetObjectGroup() const
 {
     return objectGroup_;
 }
-
 bool Tile2D::HasProperty(const String& name) const
 {
     if (!propertySet_)

+ 10 - 2
Source/Atomic/Atomic2D/TileMapDefs2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -44,7 +44,7 @@ enum Orientation2D
     O_STAGGERED
 };
 
-/// Tile map infomation.
+/// Tile map information.
 struct ATOMIC_API TileMapInfo2D
 {
     /// Orientation.
@@ -128,6 +128,7 @@ public:
 
     /// Return gid.
     int GetGid() const { return gid_; }
+
     /// Return sprite.
     Sprite2D* GetSprite() const;
 
@@ -161,20 +162,27 @@ public:
 
     /// Return type.
     TileMapObjectType2D GetObjectType() const { return objectType_; }
+
     /// Return name.
     const String& GetName() const { return name_; }
+
     /// Return type.
     const String& GetType() const { return type_; }
+
     /// Return position.
     const Vector2& GetPosition() const { return position_; }
+
     /// Return size (for rectangle and ellipse).
     const Vector2& GetSize() const { return size_; }
+
     /// Return number of points (use for script).
     unsigned GetNumPoints() const;
     /// Return point at index (use for script).
     const Vector2& GetPoint(unsigned index) const;
+
     /// Return tile Gid.
     int GetTileGid() const { return gid_; }
+
     /// Return tile sprite.
     Sprite2D* GetTileSprite() const;
     /// Return has property.

+ 9 - 9
Source/Atomic/Atomic2D/TileMapLayer2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,17 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
 #include "../Graphics/DebugRenderer.h"
-#include "../Scene/Node.h"
 #include "../Resource/ResourceCache.h"
+#include "../Scene/Node.h"
 #include "../Atomic2D/StaticSprite2D.h"
 #include "../Atomic2D/TileMap2D.h"
 #include "../Atomic2D/TileMapLayer2D.h"
 #include "../Atomic2D/TmxFile2D.h"
+
 #include "../Atomic2D/RigidBody2D.h"
 
 #include "../DebugNew.h"
@@ -106,8 +108,7 @@ void TileMapLayer2D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
                 }
                 break;
 
-            default:
-                break;
+            default: break;
             }
         }
     }
@@ -219,12 +220,12 @@ TileMapLayerType2D TileMapLayer2D::GetLayerType() const
 
 int TileMapLayer2D::GetWidth() const
 {
-    return tmxLayer_ ? tmxLayer_->GetWidth(): 0;
+    return tmxLayer_ ? tmxLayer_->GetWidth() : 0;
 }
 
 int TileMapLayer2D::GetHeight() const
 {
-    return tmxLayer_ ? tmxLayer_->GetHeight(): 0;
+    return tmxLayer_ ? tmxLayer_->GetHeight() : 0;
 }
 
 Tile2D* TileMapLayer2D::GetTile(int x, int y) const
@@ -290,7 +291,7 @@ void TileMapLayer2D::SetTileLayer(const TmxTileLayer2D* tileLayer)
 
     int width = tileLayer->GetWidth();
     int height = tileLayer->GetHeight();
-    nodes_.Resize(width * height);
+    nodes_.Resize((unsigned)(width * height));
 
     const TileMapInfo2D& info = tileMap_->GetInfo();
     for (int y = 0; y < height; ++y)
@@ -400,5 +401,4 @@ const String& TileMapLayer2D::GetName() const
 
     return none;
 }
-
 }

+ 5 - 1
Source/Atomic/Atomic2D/TileMapLayer2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -61,12 +61,16 @@ public:
 
     /// Return tile map.
     TileMap2D* GetTileMap() const;
+
     /// Return tmx layer.
     const TmxLayer2D* GetTmxLayer() const { return tmxLayer_; }
+
     /// Return draw order.
     int GetDrawOrder() const { return drawOrder_; }
+
     /// Return visible.
     bool IsVisible() const { return visible_; }
+
     /// Return has property
     bool HasProperty(const String& name) const;
     /// Return property.

+ 10 - 7
Source/Atomic/Atomic2D/TmxFile2D.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Graphics/Texture2D.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
 #include "../Resource/ResourceCache.h"
+#include "../Resource/XMLFile.h"
 #include "../Atomic2D/Sprite2D.h"
-#include "../Graphics/Texture2D.h"
 #include "../Atomic2D/TmxFile2D.h"
-#include "../Resource/XMLFile.h"
 
 #include "../DebugNew.h"
 
@@ -107,7 +108,7 @@ bool TmxTileLayer2D::Load(const XMLElement& element, const TileMapInfo2D& info)
     }
 
     XMLElement tileElem = dataElem.GetChild("tile");
-    tiles_.Resize(width_ * height_);
+    tiles_.Resize((unsigned)(width_ * height_));
 
     for (int y = 0; y < height_; ++y)
     {
@@ -352,7 +353,8 @@ bool TmxFile2D::BeginLoad(Deserializer& source)
 
                 tsxXMLFiles_[source] = tsxXMLFile;
 
-                String textureFilePath = GetParentPath(GetName()) + tsxXMLFile->GetRoot("tileset").GetChild("image").GetAttribute("source");
+                String textureFilePath =
+                    GetParentPath(GetName()) + tsxXMLFile->GetRoot("tileset").GetChild("image").GetAttribute("source");
                 GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(textureFilePath, true, this);
             }
             else
@@ -362,7 +364,8 @@ bool TmxFile2D::BeginLoad(Deserializer& source)
             }
         }
 
-        for (XMLElement imageLayerElem = rootElem.GetChild("imagelayer"); imageLayerElem; imageLayerElem = imageLayerElem.GetNext("imagelayer"))
+        for (XMLElement imageLayerElem = rootElem.GetChild("imagelayer"); imageLayerElem;
+             imageLayerElem = imageLayerElem.GetNext("imagelayer"))
         {
             String textureFilePath = GetParentPath(GetName()) + imageLayerElem.GetChild("image").GetAttribute("source");
             GetSubsystem<ResourceCache>()->BackgroundLoadResource<Texture2D>(textureFilePath, true, this);

+ 15 - 2
Source/Atomic/Atomic2D/TmxFile2D.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -43,16 +43,22 @@ public:
 
     /// Return tmx file.
     TmxFile2D* GetTmxFile() const;
+
     /// Return type.
     TileMapLayerType2D GetType() const { return type_; }
+
     /// Return name.
     const String& GetName() const { return name_; }
+
     /// Return width.
     int GetWidth() const { return width_; }
+
     /// Return height.
     int GetHeight() const { return height_; }
+
     /// Return is visible.
     bool IsVisible() const { return visible_; }
+
     /// Return has property (use for script).
     bool HasProperty(const String& name) const;
     /// Return property value (use for script).
@@ -105,8 +111,10 @@ public:
 
     /// Load from XML element.
     bool Load(const XMLElement& element, const TileMapInfo2D& info, bool local = false);
+
     /// Return number of objects.
     unsigned GetNumObjects() const { return objects_.Size(); }
+
     /// Return tile map object at index.
     TileMapObject2D* GetObject(unsigned index) const;
 
@@ -123,10 +131,13 @@ public:
 
     /// Load from XML element.
     bool Load(const XMLElement& element, const TileMapInfo2D& info);
+
     /// Return position.
     const Vector2& GetPosition() const { return position_; }
+
     /// Return source.
     const String& GetSource() const { return source_; }
+
     /// Return sprite.
     Sprite2D* GetSprite() const;
 
@@ -159,14 +170,17 @@ public:
 
     /// Return information.
     const TileMapInfo2D& GetInfo() const { return info_; }
+
     /// Return tile sprite by gid, if not exist return 0.
     Sprite2D* GetTileSprite(int gid) const;
     /// Return tile property set by gid, if not exist return 0.
     PropertySet2D* GetTilePropertySet(int gid) const;
     /// Return tile object group by gid, if not exist return 0.
     TmxObjectGroup2D* GetTileObjectGroup(int gid) const;
+
     /// Return number of layers.
     unsigned GetNumLayers() const { return layers_.Size(); }
+
     /// Return layer at index.
     const TmxLayer2D* GetLayer(unsigned index) const;
 
@@ -190,7 +204,6 @@ private:
     HashMap<int, SharedPtr<PropertySet2D> > gidToPropertySetMapping_;
     /// Gid to tile objectgroup  mapping.
     HashMap<int, SharedPtr<TmxObjectGroup2D> > gidToObjectGroupMapping_;
-
     /// Layers.
     Vector<TmxLayer2D*> layers_;
 };

+ 22 - 16
Source/Atomic/Atomic3D/AnimatedModel.cpp

@@ -20,27 +20,27 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Atomic3D/AnimatedModel.h"
 #include "../Atomic3D/Animation.h"
 #include "../Atomic3D/AnimationState.h"
 #include "../Graphics/Batch.h"
 #include "../Graphics/Camera.h"
-#include "../Core/Context.h"
 #include "../Graphics/DebugRenderer.h"
 #include "../Graphics/DrawableEvents.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/IndexBuffer.h"
-#include "../IO/Log.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Octree.h"
-#include "../Core/Profiler.h"
+#include "../Graphics/VertexBuffer.h"
+#include "../IO/Log.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/ResourceEvents.h"
 #include "../Scene/Scene.h"
-#include "../Container/Sort.h"
-#include "../Graphics/VertexBuffer.h"
 
 #include "../DebugNew.h"
 
@@ -95,7 +95,8 @@ void AnimatedModel::RegisterObject(Context* context)
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     MIXED_ACCESSOR_ATTRIBUTE("Model", GetModelAttr, SetModelAttr, ResourceRef, ResourceRef(Model::GetTypeStatic()), AM_DEFAULT);
-    ACCESSOR_ATTRIBUTE("Material", GetMaterialsAttr, SetMaterialsAttr, ResourceRefList, ResourceRefList(Material::GetTypeStatic()), AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Material", GetMaterialsAttr, SetMaterialsAttr, ResourceRefList, ResourceRefList(Material::GetTypeStatic()),
+        AM_DEFAULT);
     ATTRIBUTE("Is Occluder", bool, occluder_, false, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
     ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
@@ -105,9 +106,12 @@ void AnimatedModel::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("LOD Bias", GetLodBias, SetLodBias, float, 1.0f, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable);
-    MIXED_ACCESSOR_ATTRIBUTE("Bone Animation Enabled", GetBonesEnabledAttr, SetBonesEnabledAttr, VariantVector, Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
-    MIXED_ACCESSOR_ATTRIBUTE("Animation States", GetAnimationStatesAttr, SetAnimationStatesAttr, VariantVector, Variant::emptyVariantVector, AM_FILE);
-    ACCESSOR_ATTRIBUTE("Morphs", GetMorphsAttr, SetMorphsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_DEFAULT | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Bone Animation Enabled", GetBonesEnabledAttr, SetBonesEnabledAttr, VariantVector,
+        Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Animation States", GetAnimationStatesAttr, SetAnimationStatesAttr, VariantVector,
+        Variant::emptyVariantVector, AM_FILE);
+    ACCESSOR_ATTRIBUTE("Morphs", GetMorphsAttr, SetMorphsAttr, PODVector<unsigned char>, Variant::emptyBuffer,
+        AM_DEFAULT | AM_NOEDIT);
 }
 
 bool AnimatedModel::Load(Deserializer& source, bool setInstanceDefault)
@@ -335,7 +339,8 @@ void AnimatedModel::SetModel(Model* model, bool createBones)
             newMorph.nameHash_ = morphs[i].nameHash_;
             newMorph.weight_ = 0.0f;
             newMorph.buffers_ = morphs[i].buffers_;
-            for (HashMap<unsigned, VertexBufferMorph>::ConstIterator j = morphs[i].buffers_.Begin(); j != morphs[i].buffers_.End(); ++j)
+            for (HashMap<unsigned, VertexBufferMorph>::ConstIterator j = morphs[i].buffers_.Begin();
+                 j != morphs[i].buffers_.End(); ++j)
                 morphElementMask_ |= j->second_.elementMask_;
             morphs_.Push(newMorph);
         }
@@ -666,7 +671,7 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
             for (unsigned i = 0; i < destBones.Size(); ++i)
             {
                 if (destBones[i].node_ && destBones[i].name_ == srcBones[i].name_ && destBones[i].parentIndex_ ==
-                    srcBones[i].parentIndex_)
+                                                                                     srcBones[i].parentIndex_)
                 {
                     // If compatible, just copy the values and retain the old node and animated status
                     Node* boneNode = destBones[i].node_;
@@ -795,7 +800,7 @@ void AnimatedModel::SetAnimationStatesAttr(const VariantVector& value)
             newState->SetLooped(value[index++].GetBool());
             newState->SetWeight(value[index++].GetFloat());
             newState->SetTime(value[index++].GetFloat());
-            newState->SetLayer(value[index++].GetInt());
+            newState->SetLayer((unsigned char)value[index++].GetInt());
         }
         else
         {
@@ -1066,7 +1071,8 @@ void AnimatedModel::CloneGeometries()
     MarkMorphsDirty();
 }
 
-void AnimatedModel::CopyMorphVertices(void* destVertexData, void* srcVertexData, unsigned vertexCount, VertexBuffer* destBuffer, VertexBuffer* srcBuffer)
+void AnimatedModel::CopyMorphVertices(void* destVertexData, void* srcVertexData, unsigned vertexCount, VertexBuffer* destBuffer,
+    VertexBuffer* srcBuffer)
 {
     unsigned mask = destBuffer->GetElementMask() & srcBuffer->GetElementMask();
     unsigned normalOffset = srcBuffer->GetElementOffset(ELEMENT_NORMAL);
@@ -1293,7 +1299,8 @@ void AnimatedModel::UpdateMorphs()
     morphsDirty_ = false;
 }
 
-void AnimatedModel::ApplyMorph(VertexBuffer* buffer, void* destVertexData, unsigned morphRangeStart, const VertexBufferMorph& morph, float weight)
+void AnimatedModel::ApplyMorph(VertexBuffer* buffer, void* destVertexData, unsigned morphRangeStart, const VertexBufferMorph& morph,
+    float weight)
 {
     unsigned elementMask = morph.elementMask_ & buffer->GetElementMask();
     unsigned vertexCount = morph.vertexCount_;
@@ -1350,5 +1357,4 @@ void AnimatedModel::SetBoneCreationEnabled(bool enabled)
 {
     boneCreationEnabled_ = enabled;
 }
-
 }

+ 15 - 2
Source/Atomic/Atomic3D/AnimatedModel.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -97,10 +97,13 @@ public:
 
     /// Return skeleton.
     Skeleton& GetSkeleton() { return skeleton_; }
+
     /// Return all animation states.
     const Vector<SharedPtr<AnimationState> >& GetAnimationStates() const { return animationStates_; }
+
     /// Return number of animation states.
     unsigned GetNumAnimationStates() const { return animationStates_.Size(); }
+
     /// Return animation state by animation pointer.
     AnimationState* GetAnimationState(Animation* animation) const;
     /// Return animation state by animation name.
@@ -109,22 +112,29 @@ public:
     AnimationState* GetAnimationState(const StringHash animationNameHash) const;
     /// Return animation state by index.
     AnimationState* GetAnimationState(unsigned index) const;
+
     /// Return animation LOD bias.
     float GetAnimationLodBias() const { return animationLodBias_; }
+
     /// Return whether to update animation when not visible.
     bool GetUpdateInvisible() const { return updateInvisible_; }
+
     /// Return all vertex morphs.
     const Vector<ModelMorph>& GetMorphs() const { return morphs_; }
+
     /// Return all morph vertex buffers.
     const Vector<SharedPtr<VertexBuffer> >& GetMorphVertexBuffers() const { return morphVertexBuffers_; }
+
     /// Return number of vertex morphs.
     unsigned GetNumMorphs() const { return morphs_.Size(); }
+
     /// Return vertex morph weight by index.
     float GetMorphWeight(unsigned index) const;
     /// Return vertex morph weight by name.
     float GetMorphWeight(const String& name) const;
     /// Return vertex morph weight by name hash.
     float GetMorphWeight(StringHash nameHash) const;
+
     /// Return whether is the master (first) animated model.
     bool IsMaster() const { return isMaster_; }
 
@@ -144,8 +154,10 @@ public:
     VariantVector GetAnimationStatesAttr() const;
     /// Return morphs attribute.
     const PODVector<unsigned char>& GetMorphsAttr() const;
+
     /// Return per-geometry bone mappings.
     const Vector<PODVector<unsigned> >& GetGeometryBoneMappings() const { return geometryBoneMappings_; }
+
     /// Return per-geometry skin matrices. If empty, uses global skinning
     const Vector<PODVector<Matrix3x4> >& GetGeometrySkinMatrices() const { return geometrySkinMatrices_; }
 
@@ -188,7 +200,8 @@ private:
     /// Reapply all vertex morphs.
     void UpdateMorphs();
     /// Apply a vertex morph.
-    void ApplyMorph(VertexBuffer* buffer, void* destVertexData, unsigned morphRangeStart, const VertexBufferMorph& morph, float weight);
+    void ApplyMorph
+        (VertexBuffer* buffer, void* destVertexData, unsigned morphRangeStart, const VertexBufferMorph& morph, float weight);
     /// Handle model reload finished.
     void HandleModelReloadFinished(StringHash eventType, VariantMap& eventData);
 

+ 29 - 28
Source/Atomic/Atomic3D/Animation.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../Atomic3D/Animation.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Core/Profiler.h"
+#include "../Atomic3D/Animation.h"
 #include "../IO/Deserializer.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
-#include "../Core/Profiler.h"
-#include "../Resource/ResourceCache.h"
 #include "../IO/Serializer.h"
+#include "../Resource/ResourceCache.h"
 #include "../Resource/XMLFile.h"
 
 #include "../DebugNew.h"
@@ -45,14 +46,14 @@ void AnimationTrack::GetKeyFrameIndex(float time, unsigned& index) const
 {
     if (time < 0.0f)
         time = 0.0f;
-    
+
     if (index >= keyFrames_.Size())
         index = keyFrames_.Size() - 1;
-    
+
     // Check for being too far ahead
     while (index && time < keyFrames_[index].time_)
         --index;
-    
+
     // Check for being too far behind
     while (index < keyFrames_.Size() - 1 && time >= keyFrames_[index + 1].time_)
         ++index;
@@ -76,24 +77,24 @@ void Animation::RegisterObject(Context* context)
 bool Animation::BeginLoad(Deserializer& source)
 {
     unsigned memoryUse = sizeof(Animation);
-    
+
     // Check ID
     if (source.ReadFileID() != "UANI")
     {
         LOGERROR(source.GetName() + " is not a valid animation file");
         return false;
     }
-    
+
     // Read name and length
     animationName_ = source.ReadString();
     animationNameHash_ = animationName_;
     length_ = source.ReadFloat();
     tracks_.Clear();
-    
+
     unsigned tracks = source.ReadUInt();
     tracks_.Resize(tracks);
     memoryUse += tracks * sizeof(AnimationTrack);
-    
+
     // Read tracks
     for (unsigned i = 0; i < tracks; ++i)
     {
@@ -101,11 +102,11 @@ bool Animation::BeginLoad(Deserializer& source)
         newTrack.name_ = source.ReadString();
         newTrack.nameHash_ = newTrack.name_;
         newTrack.channelMask_ = source.ReadUByte();
-        
+
         unsigned keyFrames = source.ReadUInt();
         newTrack.keyFrames_.Resize(keyFrames);
         memoryUse += keyFrames * sizeof(AnimationKeyFrame);
-        
+
         // Read keyframes of the track
         for (unsigned j = 0; j < keyFrames; ++j)
         {
@@ -119,11 +120,11 @@ bool Animation::BeginLoad(Deserializer& source)
                 newKeyFrame.scale_ = source.ReadVector3();
         }
     }
-    
+
     // Optionally read triggers from an XML file
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     String xmlName = ReplaceExtension(GetName(), ".xml");
-    
+
     SharedPtr<XMLFile> file(cache->GetTempResource<XMLFile>(xmlName, false));
     if (file)
     {
@@ -135,13 +136,13 @@ bool Animation::BeginLoad(Deserializer& source)
                 AddTrigger(triggerElem.GetFloat("normalizedtime"), true, triggerElem.GetVariant());
             else if (triggerElem.HasAttribute("time"))
                 AddTrigger(triggerElem.GetFloat("time"), false, triggerElem.GetVariant());
-            
+
             triggerElem = triggerElem.GetNext("trigger");
         }
 
         memoryUse += triggers_.Size() * sizeof(AnimationTriggerPoint);
     }
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -152,7 +153,7 @@ bool Animation::Save(Serializer& dest) const
     dest.WriteFileID("UANI");
     dest.WriteString(animationName_);
     dest.WriteFloat(length_);
-    
+
     // Write tracks
     dest.WriteUInt(tracks_.Size());
     for (unsigned i = 0; i < tracks_.Size(); ++i)
@@ -161,7 +162,7 @@ bool Animation::Save(Serializer& dest) const
         dest.WriteString(track.name_);
         dest.WriteUByte(track.channelMask_);
         dest.WriteUInt(track.keyFrames_.Size());
-        
+
         // Write keyframes of the track
         for (unsigned j = 0; j < track.keyFrames_.Size(); ++j)
         {
@@ -175,7 +176,7 @@ bool Animation::Save(Serializer& dest) const
                 dest.WriteVector3(keyFrame.scale_);
         }
     }
-    
+
     // If triggers have been defined, write an XML file for them
     if (triggers_.Size())
     {
@@ -183,24 +184,24 @@ bool Animation::Save(Serializer& dest) const
         if (destFile)
         {
             String xmlName = ReplaceExtension(destFile->GetName(), ".xml");
-            
+
             SharedPtr<XMLFile> xml(new XMLFile(context_));
             XMLElement rootElem = xml->CreateRoot("animation");
-            
+
             for (unsigned i = 0; i < triggers_.Size(); ++i)
             {
                 XMLElement triggerElem = rootElem.CreateChild("trigger");
                 triggerElem.SetFloat("time", triggers_[i].time_);
                 triggerElem.SetVariant(triggers_[i].data_);
             }
-            
+
             File xmlFile(context_, xmlName, FILE_WRITE);
             xml->Save(xmlFile);
         }
         else
             LOGWARNING("Can not save animation trigger data when not saving into a file");
     }
-    
+
     return true;
 }
 
@@ -226,7 +227,7 @@ void Animation::AddTrigger(float time, bool timeIsNormalized, const Variant& dat
     newTrigger.time_ = timeIsNormalized ? time * length_ : time;
     newTrigger.data_ = data;
     triggers_.Push(newTrigger);
-    
+
     Sort(triggers_.Begin(), triggers_.End(), CompareTriggers);
 }
 
@@ -258,7 +259,7 @@ const AnimationTrack* Animation::GetTrack(const String& name) const
         if (i->name_ == name)
             return &(*i);
     }
-    
+
     return 0;
 }
 
@@ -269,7 +270,7 @@ const AnimationTrack* Animation::GetTrack(StringHash nameHash) const
         if (i->nameHash_ == nameHash)
             return &(*i);
     }
-    
+
     return 0;
 }
 

+ 18 - 11
Source/Atomic/Atomic3D/Animation.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -22,10 +22,10 @@
 
 #pragma once
 
-#include "../Math/Quaternion.h"
-#include "../Resource/Resource.h"
 #include "../Container/Ptr.h"
+#include "../Math/Quaternion.h"
 #include "../Math/Vector3.h"
+#include "../Resource/Resource.h"
 
 namespace Atomic
 {
@@ -48,7 +48,7 @@ struct AnimationTrack
 {
     /// Return keyframe index based on time and previous index.
     void GetKeyFrameIndex(float time, unsigned& index) const;
-    
+
     /// Bone name.
     String name_;
     /// Bone name hash.
@@ -67,7 +67,7 @@ struct AnimationTriggerPoint
         time_(0.0f)
     {
     }
-    
+
     /// Trigger time.
     float time_;
     /// Trigger data.
@@ -82,7 +82,7 @@ static const unsigned char CHANNEL_SCALE = 0x4;
 class ATOMIC_API Animation : public Resource
 {
     OBJECT(Animation);
-    
+
 public:
     /// Construct.
     Animation(Context* context);
@@ -90,12 +90,12 @@ public:
     virtual ~Animation();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Save resource. Return true if successful.
     virtual bool Save(Serializer& dest) const;
-    
+
     /// Set animation name.
     void SetAnimationName(const String& name);
     /// Set animation length.
@@ -110,28 +110,35 @@ public:
     void RemoveAllTriggers();
     /// Resize trigger point vector.
     void SetNumTriggers(unsigned num);
-    
+
     /// Return animation name.
     const String& GetAnimationName() const { return animationName_; }
+
     /// Return animation name hash.
     StringHash GetAnimationNameHash() const { return animationNameHash_; }
+
     /// Return animation length.
     float GetLength() const { return length_; }
+
     /// Return all animation tracks.
     const Vector<AnimationTrack>& GetTracks() const { return tracks_; }
+
     /// Return number of animation tracks.
     unsigned GetNumTracks() const { return tracks_.Size(); }
+
     /// Return animation track by index.
     const AnimationTrack* GetTrack(unsigned index) const;
     /// Return animation track by bone name.
     const AnimationTrack* GetTrack(const String& name) const;
     /// Return animation track by bone name hash.
     const AnimationTrack* GetTrack(StringHash nameHash) const;
+
     /// Return animation trigger points.
     const Vector<AnimationTriggerPoint>& GetTriggers() const { return triggers_; }
+
     /// Return number of animation trigger points.
-    unsigned GetNumTriggers() const {return triggers_.Size(); }
-    
+    unsigned GetNumTriggers() const { return triggers_.Size(); }
+
 private:
     /// Animation name.
     String animationName_;

+ 30 - 16
Source/Atomic/Atomic3D/AnimationController.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,15 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Atomic3D/AnimatedModel.h"
 #include "../Atomic3D/Animation.h"
 #include "../Atomic3D/AnimationController.h"
 #include "../Atomic3D/AnimationState.h"
-#include "../Core/Context.h"
 #include "../IO/Log.h"
 #include "../IO/MemoryBuffer.h"
-#include "../Core/Profiler.h"
 #include "../Resource/ResourceCache.h"
 #include "../Scene/Scene.h"
 #include "../Scene/SceneEvents.h"
@@ -64,11 +65,15 @@ void AnimationController::RegisterObject(Context* context)
     context->RegisterFactory<AnimationController>(LOGIC_CATEGORY);
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Animations", GetAnimationsAttr, SetAnimationsAttr, VariantVector, Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
-    ACCESSOR_ATTRIBUTE("Network Animations", GetNetAnimationsAttr, SetNetAnimationsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_NET | AM_LATESTDATA | AM_NOEDIT);
-    MIXED_ACCESSOR_ATTRIBUTE("Node Animation States", GetNodeAnimationStatesAttr, SetNodeAnimationStatesAttr, VariantVector, Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Animations", GetAnimationsAttr, SetAnimationsAttr, VariantVector, Variant::emptyVariantVector,
+        AM_FILE | AM_NOEDIT);
+    ACCESSOR_ATTRIBUTE("Network Animations", GetNetAnimationsAttr, SetNetAnimationsAttr, PODVector<unsigned char>,
+        Variant::emptyBuffer, AM_NET | AM_LATESTDATA | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Node Animation States", GetNodeAnimationStatesAttr, SetNodeAnimationStatesAttr, VariantVector,
+        Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
 
     ACCESSOR_ATTRIBUTE("Animation Resources", GetAnimationResourcesAttr, SetAnimationResourcesAttr, ResourceRefList, ResourceRefList(Animation::GetTypeStatic()), AM_FILE | AM_NOEDIT);
+
 }
 
 void AnimationController::OnSetEnabled()
@@ -427,13 +432,24 @@ bool AnimationController::IsFadingOut(const String& name) const
         return false;
 
     return (animations_[index].fadeTime_ && animations_[index].targetWeight_ < state->GetWeight())
-        || (!state->IsLooped() && state->GetTime() >= state->GetLength() && animations_[index].autoFadeTime_);
+           || (!state->IsLooped() && state->GetTime() >= state->GetLength() && animations_[index].autoFadeTime_);
+}
+
+bool AnimationController::IsAtEnd(const String& name) const
+{
+    unsigned index;
+    AnimationState* state;
+    FindAnimation(name, index, state);
+    if (index == M_MAX_UNSIGNED || !state)
+        return false;
+    else
+        return state->GetTime() >= state->GetLength();
 }
 
 unsigned char AnimationController::GetLayer(const String& name) const
 {
     AnimationState* state = GetAnimationState(name);
-    return state ? state->GetLayer() : 0;
+    return (unsigned char)(state ? state->GetLayer() : 0);
 }
 
 Bone* AnimationController::GetStartBone(const String& name) const
@@ -764,14 +780,12 @@ VariantVector AnimationController::GetNodeAnimationStatesAttr() const
     return ret;
 }
 
-void AnimationController::OnNodeSet(Node* node)
+void AnimationController::OnSceneSet(Scene* scene)
 {
-    if (node)
-    {
-        Scene* scene = GetScene();
-        if (scene && IsEnabledEffective())
-            SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(AnimationController, HandleScenePostUpdate));
-    }
+    if (scene && IsEnabledEffective())
+        SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(AnimationController, HandleScenePostUpdate));
+    else if (!scene)
+        UnsubscribeFromEvent(E_SCENEPOSTUPDATE);
 }
 
 AnimationState* AnimationController::AddAnimationState(Animation* animation)

+ 8 - 7
Source/Atomic/Atomic3D/AnimationController.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -22,8 +22,8 @@
 
 #pragma once
 
-#include "../Scene/Component.h"
 #include "../IO/VectorBuffer.h"
+#include "../Scene/Component.h"
 
 namespace Atomic
 {
@@ -122,15 +122,17 @@ public:
     bool SetLooped(const String& name, bool enable);
     /// Set animation speed. Return true on success.
     bool SetSpeed(const String& name, float speed);
-    /// Set animation autofade on stop (non-looped animations only.) Zero time disables. Return true on success.
+    /// Set animation autofade at end (non-looped animations only.) Zero time disables. Return true on success.
     bool SetAutoFade(const String& name, float fadeOutTime);
 
-    /// Return whether an animation is active.
+    /// Return whether an animation is active. Note that non-looping animations that are being clamped at the end also return true.
     bool IsPlaying(const String& name) const;
     /// Return whether an animation is fading in.
     bool IsFadingIn(const String& name) const;
     /// Return whether an animation is fading out.
     bool IsFadingOut(const String& name) const;
+    /// Return whether an animation is at its end. Will return false if the animation is not active at all.
+    bool IsAtEnd(const String& name) const;
     /// Return animation blending layer.
     unsigned char GetLayer(const String& name) const;
     /// Return animation start bone, or null if no such animation.
@@ -178,10 +180,9 @@ public:
     void ClearAnimationResources();
     void SetAnimationResourcesAttr(const ResourceRefList& value);
     const ResourceRefList& GetAnimationResourcesAttr() const;
-
 protected:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
 
 private:
     /// Add an animation state either to AnimatedModel or as a node animation.

+ 44 - 45
Source/Atomic/Atomic3D/AnimationState.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,14 +20,13 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Atomic3D/AnimatedModel.h"
 #include "../Atomic3D/Animation.h"
 #include "../Atomic3D/AnimationState.h"
-#include "../IO/Deserializer.h"
 #include "../Graphics/DrawableEvents.h"
 #include "../IO/Log.h"
-#include "../IO/Serializer.h"
 
 #include "../DebugNew.h"
 
@@ -75,7 +74,7 @@ AnimationState::AnimationState(Node* node, Animation* animation) :
         {
             const Vector<AnimationTrack>& tracks = animation_->GetTracks();
             stateTracks_.Clear();
-            
+
             for (unsigned i = 0; i < tracks.Size(); ++i)
             {
                 const StringHash& nameHash = tracks[i].nameHash_;
@@ -109,7 +108,7 @@ void AnimationState::SetStartBone(Bone* startBone)
 {
     if (!model_ || !animation_)
         return;
-    
+
     Skeleton& skeleton = model_->GetSkeleton();
     if (!startBone)
     {
@@ -118,28 +117,28 @@ void AnimationState::SetStartBone(Bone* startBone)
             return;
         startBone = rootBone;
     }
-    
+
     // Do not reassign if the start bone did not actually change, and we already have valid bone nodes
     if (startBone == startBone_ && !stateTracks_.Empty())
         return;
-    
+
     startBone_ = startBone;
-    
+
     const Vector<AnimationTrack>& tracks = animation_->GetTracks();
     stateTracks_.Clear();
-    
+
     if (!startBone->node_)
         return;
-    
+
     for (unsigned i = 0; i < tracks.Size(); ++i)
     {
         AnimationStateTrack stateTrack;
         stateTrack.track_ = &tracks[i];
-        
+
         // Include those tracks that are either the start bone itself, or its children
         Bone* trackBone = 0;
         const StringHash& nameHash = tracks[i].nameHash_;
-        
+
         if (nameHash == startBone->nameHash_)
             trackBone = startBone;
         else
@@ -148,7 +147,7 @@ void AnimationState::SetStartBone(Bone* startBone)
             if (trackBoneNode)
                 trackBone = skeleton.GetBone(nameHash);
         }
-        
+
         if (trackBone && trackBone->node_)
         {
             stateTrack.bone_ = trackBone;
@@ -156,7 +155,7 @@ void AnimationState::SetStartBone(Bone* startBone)
             stateTracks_.Push(stateTrack);
         }
     }
-    
+
     model_->MarkAnimationDirty();
 }
 
@@ -183,7 +182,7 @@ void AnimationState::SetTime(float time)
 {
     if (!animation_)
         return;
-    
+
     time = Clamp(time, 0.0f, animation_->GetLength());
     if (time != time_)
     {
@@ -197,16 +196,16 @@ void AnimationState::SetBoneWeight(unsigned index, float weight, bool recursive)
 {
     if (index >= stateTracks_.Size())
         return;
-    
+
     weight = Clamp(weight, 0.0f, 1.0f);
-    
+
     if (weight != stateTracks_[index].weight_)
     {
         stateTracks_[index].weight_ = weight;
         if (model_)
             model_->MarkAnimationDirty();
     }
-    
+
     if (recursive)
     {
         Node* boneNode = stateTracks_[index].node_;
@@ -237,7 +236,7 @@ void AnimationState::AddWeight(float delta)
 {
     if (delta == 0.0f)
         return;
-    
+
     SetWeight(GetWeight() + delta);
 }
 
@@ -245,11 +244,11 @@ void AnimationState::AddTime(float delta)
 {
     if (!animation_ || (!model_ && !node_))
         return;
-    
+
     float length = animation_->GetLength();
     if (delta == 0.0f || length == 0.0f)
         return;
-    
+
     float oldTime = GetTime();
     float time = oldTime + delta;
     if (looped_)
@@ -259,14 +258,14 @@ void AnimationState::AddTime(float delta)
         while (time < 0.0f)
             time += length;
     }
-    
+
     SetTime(time);
-    
+
     // Process animation triggers
     if (animation_->GetNumTriggers())
     {
         bool wrap = false;
-        
+
         if (delta > 0.0f)
         {
             if (oldTime > time)
@@ -285,20 +284,20 @@ void AnimationState::AddTime(float delta)
         }
         if (oldTime > time)
             Swap(oldTime, time);
-        
+
         const Vector<AnimationTriggerPoint>& triggers = animation_->GetTriggers();
         for (Vector<AnimationTriggerPoint>::ConstIterator i = triggers.Begin(); i != triggers.End(); ++i)
         {
             float frameTime = i->time_;
             if (looped_ && wrap)
                 frameTime = fmodf(frameTime, length);
-            
+
             if (oldTime <= frameTime && time > frameTime)
             {
                 using namespace AnimationTrigger;
-                
+
                 Node* senderNode = model_ ? model_->GetNode() : node_;
-                
+
                 VariantMap& eventData = senderNode->GetEventDataMap();
                 eventData[P_NODE] = senderNode;
                 eventData[P_NAME] = animation_->GetAnimationName();
@@ -358,7 +357,7 @@ unsigned AnimationState::GetTrackIndex(const String& name) const
         if (node && node->GetName() == name)
             return i;
     }
-    
+
     return M_MAX_UNSIGNED;
 }
 
@@ -394,7 +393,7 @@ void AnimationState::Apply()
 {
     if (!animation_ || !IsEnabled())
         return;
-    
+
     if (model_)
         ApplyToModel();
     else
@@ -407,11 +406,11 @@ void AnimationState::ApplyToModel()
     {
         AnimationStateTrack& stateTrack = *i;
         float finalWeight = weight_ * stateTrack.weight_;
-        
+
         // Do not apply if zero effective weight or the bone has animation disabled
         if (Equals(finalWeight, 0.0f) || !stateTrack.bone_->animated_)
             continue;
-        
+
         if (Equals(finalWeight, 1.0f))
             ApplyTrackFullWeightSilent(stateTrack);
         else
@@ -430,13 +429,13 @@ void AnimationState::ApplyTrackFullWeight(AnimationStateTrack& stateTrack)
 {
     const AnimationTrack* track = stateTrack.track_;
     Node* node = stateTrack.node_;
-    
+
     if (track->keyFrames_.Empty() || !node)
         return;
-    
+
     unsigned& frame = stateTrack.keyFrame_;
     track->GetKeyFrameIndex(time_, frame);
-    
+
     // Check if next frame to interpolate to is valid, or if wrapping is needed (looping animation only)
     unsigned nextFrame = frame + 1;
     bool interpolate = true;
@@ -450,10 +449,10 @@ void AnimationState::ApplyTrackFullWeight(AnimationStateTrack& stateTrack)
         else
             nextFrame = 0;
     }
-    
+
     const AnimationKeyFrame* keyFrame = &track->keyFrames_[frame];
     unsigned char channelMask = track->channelMask_;
-    
+
     if (!interpolate)
     {
         // No interpolation, full weight
@@ -471,7 +470,7 @@ void AnimationState::ApplyTrackFullWeight(AnimationStateTrack& stateTrack)
         if (timeInterval < 0.0f)
             timeInterval += animation_->GetLength();
         float t = timeInterval > 0.0f ? (time_ - keyFrame->time_) / timeInterval : 1.0f;
-        
+
         // Interpolation, full weight
         if (channelMask & CHANNEL_POSITION)
             node->SetPosition(keyFrame->position_.Lerp(nextKeyFrame->position_, t));
@@ -542,13 +541,13 @@ void AnimationState::ApplyTrackBlendedSilent(AnimationStateTrack& stateTrack, fl
 {
     const AnimationTrack* track = stateTrack.track_;
     Node* node = stateTrack.node_;
-    
+
     if (track->keyFrames_.Empty() || !node)
         return;
-    
+
     unsigned& frame = stateTrack.keyFrame_;
     track->GetKeyFrameIndex(time_, frame);
-    
+
     // Check if next frame to interpolate to is valid, or if wrapping is needed (looping animation only)
     unsigned nextFrame = frame + 1;
     bool interpolate = true;
@@ -562,10 +561,10 @@ void AnimationState::ApplyTrackBlendedSilent(AnimationStateTrack& stateTrack, fl
         else
             nextFrame = 0;
     }
-    
+
     const AnimationKeyFrame* keyFrame = &track->keyFrames_[frame];
     unsigned char channelMask = track->channelMask_;
-    
+
     if (!interpolate)
     {
         // No interpolation, blend between old transform & animation
@@ -583,7 +582,7 @@ void AnimationState::ApplyTrackBlendedSilent(AnimationStateTrack& stateTrack, fl
         if (timeInterval < 0.0f)
             timeInterval += animation_->GetLength();
         float t = timeInterval > 0.0f ? (time_ - keyFrame->time_) / timeInterval : 1.0f;
-        
+
         // Interpolation, blend between old transform & animation
         if (channelMask & CHANNEL_POSITION)
         {

+ 13 - 6
Source/Atomic/Atomic3D/AnimationState.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -43,7 +43,7 @@ struct AnimationStateTrack
     AnimationStateTrack();
     /// Destruct
     ~AnimationStateTrack();
-    
+
     /// Animation track.
     const AnimationTrack* track_;
     /// Bone pointer.
@@ -66,7 +66,7 @@ public:
     AnimationState(Node* node, Animation* animation);
     /// Destruct.
     ~AnimationState();
-    
+
     /// Set start bone. Not supported in node animation mode. Resets any assigned per-bone weights.
     void SetStartBone(Bone* bone);
     /// Set looping enabled/disabled.
@@ -87,9 +87,10 @@ public:
     void AddTime(float delta);
     /// Set blending layer.
     void SetLayer(unsigned char layer);
-    
+
     /// Return animation.
     Animation* GetAnimation() const { return animation_; }
+
     /// Return animated model this state belongs to (model mode.)
     AnimatedModel* GetModel() const;
     /// Return root scene node this state controls (node hierarchy mode.)
@@ -108,22 +109,28 @@ public:
     unsigned GetTrackIndex(const String& name) const;
     /// Return track index by bone name hash, or M_MAX_UNSIGNED if not found.
     unsigned GetTrackIndex(StringHash nameHash) const;
+
     /// Return whether weight is nonzero.
     bool IsEnabled() const { return weight_ > 0.0f; }
+
     /// Return whether looped.
     bool IsLooped() const { return looped_; }
+
     /// Return blending weight.
     float GetWeight() const { return weight_; }
+
     /// Return time position.
     float GetTime() const { return time_; }
+
     /// Return animation length.
     float GetLength() const;
+
     /// Return blending layer.
     unsigned char GetLayer() const { return layer_; }
-    
+
     /// Apply the animation at the current time position.
     void Apply();
-    
+
 private:
     /// Apply animation to a skeleton. Transform changes are applied silently, so the model needs to dirty its root model afterward.
     void ApplyToModel();

+ 44 - 25
Source/Atomic/Atomic3D/BillboardSet.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,22 +20,22 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Graphics/Batch.h"
 #include "../Atomic3D/BillboardSet.h"
 #include "../Graphics/Camera.h"
-#include "../Core/Context.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/IndexBuffer.h"
 #include "../Graphics/Material.h"
-#include "../IO/MemoryBuffer.h"
-#include "../Scene/Node.h"
 #include "../Graphics/OctreeQuery.h"
-#include "../Core/Profiler.h"
-#include "../Resource/ResourceCache.h"
-#include "../Container/Sort.h"
 #include "../Graphics/VertexBuffer.h"
+#include "../IO/MemoryBuffer.h"
+#include "../Resource/ResourceCache.h"
+#include "../Scene/Node.h"
 
 #include "../DebugNew.h"
 
@@ -97,7 +97,8 @@ void BillboardSet::RegisterObject(Context* context)
     context->RegisterFactory<BillboardSet>(GEOMETRY_CATEGORY);
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()),
+        AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Relative Position", IsRelative, SetRelative, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Relative Scale", IsScaled, SetScaled, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Sort By Distance", IsSorted, SetSorted, bool, false, AM_DEFAULT);
@@ -108,8 +109,10 @@ void BillboardSet::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable);
-    MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector, AM_FILE);
-    ACCESSOR_ATTRIBUTE("Network Billboards", GetNetBillboardsAttr, SetNetBillboardsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_NET | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector,
+        AM_FILE);
+    ACCESSOR_ATTRIBUTE("Network Billboards", GetNetBillboardsAttr, SetNetBillboardsAttr, PODVector<unsigned char>,
+        Variant::emptyBuffer, AM_NET | AM_NOEDIT);
 }
 
 void BillboardSet::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
@@ -163,13 +166,13 @@ void BillboardSet::UpdateBatches(const FrameInfo& frame)
         sortThisFrame_ = false;
         sortFrameNumber_ = frame.frameNumber_;
     }
-    
+
     Vector3 worldPos = node_->GetWorldPosition();
     Vector3 offset = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
     // Sort if position relative to camera has changed
     if (offset != previousOffset_ & sorted_)
         sortThisFrame_ = true;
-    
+
     distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
 
     // Calculate scaled distance for animation LOD
@@ -196,7 +199,7 @@ void BillboardSet::UpdateGeometry(const FrameInfo& frame)
 
     if (bufferDirty_ || sortThisFrame_ || vertexBuffer_->IsDataLost())
         UpdateVertexBuffer(frame);
-    
+
     // If using camera facing, re-update the rotation for the current view now
     if (faceCameraMode_ != FC_NONE)
     {
@@ -433,8 +436,12 @@ void BillboardSet::UpdateBufferSize()
     unsigned vertexIndex = 0;
     while (numBillboards--)
     {
-        dest[0] = vertexIndex; dest[1] = vertexIndex + 1; dest[2] = vertexIndex + 2;
-        dest[3] = vertexIndex + 2; dest[4] = vertexIndex + 3; dest[5] = vertexIndex;
+        dest[0] = (unsigned short)vertexIndex;
+        dest[1] = (unsigned short)(vertexIndex + 1);
+        dest[2] = (unsigned short)(vertexIndex + 2);
+        dest[3] = (unsigned short)(vertexIndex + 2);
+        dest[4] = (unsigned short)(vertexIndex + 3);
+        dest[5] = (unsigned short)vertexIndex;
 
         dest += 6;
         vertexIndex += 4;
@@ -502,7 +509,7 @@ void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
         // Store the "last sorted position" now
         previousOffset_ = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
     }
-    
+
     float* dest = (float*)vertexBuffer_->Lock(0, enabledBillboards * 4, true);
     if (!dest)
         return;
@@ -520,27 +527,39 @@ void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
         rotationMatrix[1][0] = -rotationMatrix[0][1];
         rotationMatrix[1][1] = rotationMatrix[0][0];
 
-        dest[0] = billboard.position_.x_; dest[1] = billboard.position_.y_; dest[2] = billboard.position_.z_;
+        dest[0] = billboard.position_.x_;
+        dest[1] = billboard.position_.y_;
+        dest[2] = billboard.position_.z_;
         ((unsigned&)dest[3]) = color;
-        dest[4] = billboard.uv_.min_.x_; dest[5] = billboard.uv_.min_.y_;
+        dest[4] = billboard.uv_.min_.x_;
+        dest[5] = billboard.uv_.min_.y_;
         dest[6] = -size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
         dest[7] = -size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
 
-        dest[8] = billboard.position_.x_; dest[9] = billboard.position_.y_; dest[10] = billboard.position_.z_;
+        dest[8] = billboard.position_.x_;
+        dest[9] = billboard.position_.y_;
+        dest[10] = billboard.position_.z_;
         ((unsigned&)dest[11]) = color;
-        dest[12] = billboard.uv_.max_.x_; dest[13] = billboard.uv_.min_.y_;
+        dest[12] = billboard.uv_.max_.x_;
+        dest[13] = billboard.uv_.min_.y_;
         dest[14] = size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
         dest[15] = size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
 
-        dest[16] = billboard.position_.x_; dest[17] = billboard.position_.y_; dest[18] = billboard.position_.z_;
+        dest[16] = billboard.position_.x_;
+        dest[17] = billboard.position_.y_;
+        dest[18] = billboard.position_.z_;
         ((unsigned&)dest[19]) = color;
-        dest[20] = billboard.uv_.max_.x_; dest[21] = billboard.uv_.max_.y_;
+        dest[20] = billboard.uv_.max_.x_;
+        dest[21] = billboard.uv_.max_.y_;
         dest[22] = size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
         dest[23] = size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
 
-        dest[24] = billboard.position_.x_; dest[25] = billboard.position_.y_; dest[26] = billboard.position_.z_;
+        dest[24] = billboard.position_.x_;
+        dest[25] = billboard.position_.y_;
+        dest[26] = billboard.position_.z_;
         ((unsigned&)dest[27]) = color;
-        dest[28] = billboard.uv_.min_.x_; dest[29] = billboard.uv_.max_.y_;
+        dest[28] = billboard.uv_.min_.x_;
+        dest[29] = billboard.uv_.max_.y_;
         dest[30] = -size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
         dest[31] = -size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
 

+ 11 - 3
Source/Atomic/Atomic3D/BillboardSet.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -22,11 +22,11 @@
 
 #pragma once
 
-#include "../Math/Color.h"
 #include "../Graphics/Drawable.h"
+#include "../IO/VectorBuffer.h"
+#include "../Math/Color.h"
 #include "../Math/Matrix3x4.h"
 #include "../Math/Rect.h"
-#include "../IO/VectorBuffer.h"
 
 namespace Atomic
 {
@@ -96,20 +96,28 @@ public:
 
     /// Return material.
     Material* GetMaterial() const;
+
     /// Return number of billboards.
     unsigned GetNumBillboards() const { return billboards_.Size(); }
+
     /// Return all billboards.
     PODVector<Billboard>& GetBillboards() { return billboards_; }
+
     /// Return billboard by index.
     Billboard* GetBillboard(unsigned index);
+
     /// Return whether billboards are relative to the scene node.
     bool IsRelative() const { return relative_; }
+
     /// Return whether scene node scale affects billboards' size.
     bool IsScaled() const { return scaled_; }
+
     /// Return whether billboards are sorted.
     bool IsSorted() const { return sorted_; }
+
     /// Return how the billboards rotate in relation to the camera.
     FaceCameraMode GetFaceCameraMode() const { return faceCameraMode_; }
+
     /// Return animation LOD bias.
     float GetAnimationLodBias() const { return animationLodBias_; }
 

+ 60 - 50
Source/Atomic/Atomic3D/CustomGeometry.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,22 +20,22 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Graphics/Batch.h"
 #include "../Graphics/Camera.h"
-#include "../Core/Context.h"
 #include "../Atomic3D/CustomGeometry.h"
 #include "../Graphics/Geometry.h"
-#include "../IO/Log.h"
 #include "../Graphics/Material.h"
-#include "../IO/MemoryBuffer.h"
-#include "../Scene/Node.h"
 #include "../Graphics/OcclusionBuffer.h"
 #include "../Graphics/OctreeQuery.h"
-#include "../Core/Profiler.h"
-#include "../Resource/ResourceCache.h"
-#include "../IO/VectorBuffer.h"
 #include "../Graphics/VertexBuffer.h"
+#include "../IO/Log.h"
+#include "../IO/MemoryBuffer.h"
+#include "../Resource/ResourceCache.h"
+#include "../Scene/Node.h"
 
 #include "../DebugNew.h"
 
@@ -66,8 +66,10 @@ void CustomGeometry::RegisterObject(Context* context)
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     ATTRIBUTE("Dynamic Vertex Buffer", bool, dynamic_, false, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Geometry Data", GetGeometryDataAttr, SetGeometryDataAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_FILE|AM_NOEDIT);
-    ACCESSOR_ATTRIBUTE("Materials", GetMaterialsAttr, SetMaterialsAttr, ResourceRefList, ResourceRefList(Material::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Geometry Data", GetGeometryDataAttr, SetGeometryDataAttr, PODVector<unsigned char>,
+        Variant::emptyBuffer, AM_FILE | AM_NOEDIT);
+    ACCESSOR_ATTRIBUTE("Materials", GetMaterialsAttr, SetMaterialsAttr, ResourceRefList, ResourceRefList(Material::GetTypeStatic()),
+        AM_DEFAULT);
     ATTRIBUTE("Is Occluder", bool, occluder_, false, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
     ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
@@ -89,43 +91,49 @@ void CustomGeometry::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQ
 
     case RAY_OBB:
     case RAY_TRIANGLE:
-        Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
-        Ray localRay = query.ray_.Transformed(inverse);
-        float distance = localRay.HitDistance(boundingBox_);
-        Vector3 normal = -query.ray_.direction_;
-
-        if (level == RAY_TRIANGLE && distance < query.maxDistance_)
         {
-            distance = M_INFINITY;
+            Matrix3x4 inverse(node_->GetWorldTransform().Inverse());
+            Ray localRay = query.ray_.Transformed(inverse);
+            float distance = localRay.HitDistance(boundingBox_);
+            Vector3 normal = -query.ray_.direction_;
 
-            for (unsigned i = 0; i < batches_.Size(); ++i)
+            if (level == RAY_TRIANGLE && distance < query.maxDistance_)
             {
-                Geometry* geometry = batches_[i].geometry_;
-                if (geometry)
+                distance = M_INFINITY;
+
+                for (unsigned i = 0; i < batches_.Size(); ++i)
                 {
-                    Vector3 geometryNormal;
-                    float geometryDistance = geometry->GetHitDistance(localRay, &geometryNormal);
-                    if (geometryDistance < query.maxDistance_ && geometryDistance < distance)
+                    Geometry* geometry = batches_[i].geometry_;
+                    if (geometry)
                     {
-                        distance = geometryDistance;
-                        normal = (node_->GetWorldTransform() * Vector4(geometryNormal, 0.0f)).Normalized();
+                        Vector3 geometryNormal;
+                        float geometryDistance = geometry->GetHitDistance(localRay, &geometryNormal);
+                        if (geometryDistance < query.maxDistance_ && geometryDistance < distance)
+                        {
+                            distance = geometryDistance;
+                            normal = (node_->GetWorldTransform() * Vector4(geometryNormal, 0.0f)).Normalized();
+                        }
                     }
                 }
             }
-        }
 
-        if (distance < query.maxDistance_)
-        {
-            RayQueryResult result;
-            result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
-            result.normal_ = normal;
-            result.distance_ = distance;
-            result.drawable_ = this;
-            result.node_ = node_;
-            result.subObject_ = M_MAX_UNSIGNED;
-            results.Push(result);
+            if (distance < query.maxDistance_)
+            {
+                RayQueryResult result;
+                result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
+                result.normal_ = normal;
+                result.distance_ = distance;
+                result.drawable_ = this;
+                result.node_ = node_;
+                result.subObject_ = M_MAX_UNSIGNED;
+                results.Push(result);
+            }
         }
         break;
+
+    case RAY_TRIANGLE_UV:
+        LOGWARNING("RAY_TRIANGLE_UV query level is not supported for CustomGeometry component");
+        break;
     }
 }
 
@@ -188,7 +196,8 @@ bool CustomGeometry::DrawOcclusion(OcclusionBuffer* buffer)
             continue;
 
         // Draw and check for running out of triangles
-        success = buffer->Draw(node_->GetWorldTransform(), vertexData, vertexSize, geometry->GetVertexStart(), geometry->GetVertexCount());
+        success = buffer->Draw(node_->GetWorldTransform(), vertexData, vertexSize, geometry->GetVertexStart(),
+            geometry->GetVertexCount());
 
         if (!success)
             break;
@@ -291,7 +300,8 @@ void CustomGeometry::DefineTangent(const Vector4& tangent)
     elementMask_ |= MASK_TANGENT;
 }
 
-void CustomGeometry::DefineGeometry(unsigned index, PrimitiveType type, unsigned numVertices, bool hasNormals, bool hasColors, bool hasTexCoords, bool hasTangents)
+void CustomGeometry::DefineGeometry(unsigned index, PrimitiveType type, unsigned numVertices, bool hasNormals, bool hasColors,
+    bool hasTexCoords, bool hasTangents)
 {
     if (index > geometries_.Size())
     {
@@ -432,7 +442,7 @@ Material* CustomGeometry::GetMaterial(unsigned index) const
 CustomGeometryVertex* CustomGeometry::GetVertex(unsigned geometryIndex, unsigned vertexNum)
 {
     return (geometryIndex < vertices_.Size() && vertexNum < vertices_[geometryIndex].Size()) ?
-        &vertices_[geometryIndex][vertexNum] : (CustomGeometryVertex*)0;
+           &vertices_[geometryIndex][vertexNum] : (CustomGeometryVertex*)0;
 }
 
 void CustomGeometry::SetGeometryDataAttr(const PODVector<unsigned char>& value)
@@ -453,15 +463,15 @@ void CustomGeometry::SetGeometryDataAttr(const PODVector<unsigned char>& value)
 
         for (unsigned j = 0; j < numVertices; ++j)
         {
-             if (elementMask_ & MASK_POSITION)
+            if (elementMask_ & MASK_POSITION)
                 vertices_[i][j].position_ = buffer.ReadVector3();
-             if (elementMask_ & MASK_NORMAL)
+            if (elementMask_ & MASK_NORMAL)
                 vertices_[i][j].normal_ = buffer.ReadVector3();
-             if (elementMask_ & MASK_COLOR)
+            if (elementMask_ & MASK_COLOR)
                 vertices_[i][j].color_ = buffer.ReadUInt();
-             if (elementMask_ & MASK_TEXCOORD1)
+            if (elementMask_ & MASK_TEXCOORD1)
                 vertices_[i][j].texCoord_ = buffer.ReadVector2();
-             if (elementMask_ & MASK_TANGENT)
+            if (elementMask_ & MASK_TANGENT)
                 vertices_[i][j].tangent_ = buffer.ReadVector4();
         }
     }
@@ -491,15 +501,15 @@ PODVector<unsigned char> CustomGeometry::GetGeometryDataAttr() const
 
         for (unsigned j = 0; j < numVertices; ++j)
         {
-             if (elementMask_ & MASK_POSITION)
+            if (elementMask_ & MASK_POSITION)
                 ret.WriteVector3(vertices_[i][j].position_);
-             if (elementMask_ & MASK_NORMAL)
+            if (elementMask_ & MASK_NORMAL)
                 ret.WriteVector3(vertices_[i][j].normal_);
-             if (elementMask_ & MASK_COLOR)
+            if (elementMask_ & MASK_COLOR)
                 ret.WriteUInt(vertices_[i][j].color_);
-             if (elementMask_ & MASK_TEXCOORD1)
+            if (elementMask_ & MASK_TEXCOORD1)
                 ret.WriteVector2(vertices_[i][j].texCoord_);
-             if (elementMask_ & MASK_TANGENT)
+            if (elementMask_ & MASK_TANGENT)
                 ret.WriteVector4(vertices_[i][j].tangent_);
         }
     }

+ 9 - 2
Source/Atomic/Atomic3D/CustomGeometry.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -85,7 +85,9 @@ public:
     /// Define a vertex tangent.
     void DefineTangent(const Vector4& tangent);
     /// Set the primitive type, number of vertices and elements in a geometry, after which the vertices can be edited with GetVertex(). An alternative to BeginGeometry() / DefineVertex().
-    void DefineGeometry(unsigned index, PrimitiveType type, unsigned numVertices, bool hasNormals, bool hasColors, bool hasTexCoords, bool hasTangents);
+    void DefineGeometry
+        (unsigned index, PrimitiveType type, unsigned numVertices, bool hasNormals, bool hasColors, bool hasTexCoords,
+            bool hasTangents);
     /// Update vertex buffer and calculate the bounding box. Call after finishing defining geometry.
     void Commit();
     /// Set material on all geometries.
@@ -95,14 +97,19 @@ public:
 
     /// Return number of geometries.
     unsigned GetNumGeometries() const { return geometries_.Size(); }
+
     /// Return number of vertices in a geometry.
     unsigned GetNumVertices(unsigned index) const;
+
     /// Return whether vertex buffer dynamic mode is enabled.
     bool IsDynamic() const { return dynamic_; }
+
     /// Return material by geometry index.
     Material* GetMaterial(unsigned index = 0) const;
+
     /// Return all vertices. These can be edited; calling Commit() updates the vertex buffer.
     Vector<PODVector<CustomGeometryVertex> >& GetVertices() { return vertices_; }
+
     /// Return a vertex in a geometry for editing, or null if out of bounds. After the edits are finished, calling Commit() updates  the vertex buffer.
     CustomGeometryVertex* GetVertex(unsigned geometryIndex, unsigned vertexNum);
 

+ 21 - 20
Source/Atomic/Atomic3D/DecalSet.cpp

@@ -20,26 +20,25 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Atomic3D/AnimatedModel.h"
 #include "../Graphics/Batch.h"
 #include "../Graphics/Camera.h"
-#include "../Core/Context.h"
 #include "../Atomic3D/DecalSet.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/IndexBuffer.h"
-#include "../IO/Log.h"
 #include "../Graphics/Material.h"
+#include "../Graphics/Tangent.h"
+#include "../Graphics/VertexBuffer.h"
+#include "../IO/Log.h"
 #include "../IO/MemoryBuffer.h"
-#include "../Scene/Node.h"
-#include "../Core/Profiler.h"
 #include "../Resource/ResourceCache.h"
 #include "../Scene/Scene.h"
 #include "../Scene/SceneEvents.h"
-#include "../Graphics/Tangent.h"
-#include "../IO/VectorBuffer.h"
-#include "../Graphics/VertexBuffer.h"
 
 #include "../DebugNew.h"
 
@@ -55,7 +54,7 @@ static const unsigned DEFAULT_MAX_VERTICES = 512;
 static const unsigned DEFAULT_MAX_INDICES = 1024;
 static const unsigned STATIC_ELEMENT_MASK = MASK_POSITION | MASK_NORMAL | MASK_TEXCOORD1 | MASK_TANGENT;
 static const unsigned SKINNED_ELEMENT_MASK = MASK_POSITION | MASK_NORMAL | MASK_TEXCOORD1 | MASK_TANGENT | MASK_BLENDWEIGHTS |
-    MASK_BLENDINDICES;
+                                             MASK_BLENDINDICES;
 
 static DecalVertex ClipEdge(const DecalVertex& v0, const DecalVertex& v1, float d0, float d1, bool skinned)
 {
@@ -92,7 +91,7 @@ static DecalVertex ClipEdge(const DecalVertex& v0, const DecalVertex& v1, float
 
 static void ClipPolygon(PODVector<DecalVertex>& dest, const PODVector<DecalVertex>& src, const Plane& plane, bool skinned)
 {
-    unsigned last;
+    unsigned last = 0;
     float lastDistance = 0.0f;
     dest.Clear();
 
@@ -131,12 +130,12 @@ void Decal::AddVertex(const DecalVertex& vertex)
     {
         if (vertex.position_.Equals(vertices_[i].position_) && vertex.normal_.Equals(vertices_[i].normal_))
         {
-            indices_.Push(i);
+            indices_.Push((unsigned short)i);
             return;
         }
     }
 
-    unsigned short newIndex = vertices_.Size();
+    unsigned short newIndex = (unsigned short)vertices_.Size();
     vertices_.Push(vertex);
     indices_.Push(newIndex);
 }
@@ -181,13 +180,15 @@ void DecalSet::RegisterObject(Context* context)
     context->RegisterFactory<DecalSet>(GEOMETRY_CATEGORY);
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()),
+        AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Max Vertices", GetMaxVertices, SetMaxVertices, unsigned, DEFAULT_MAX_VERTICES, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Max Indices", GetMaxIndices, SetMaxIndices, unsigned, DEFAULT_MAX_INDICES, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable);
-    MIXED_ACCESSOR_ATTRIBUTE("Decals", GetDecalsAttr, SetDecalsAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_FILE | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Decals", GetDecalsAttr, SetDecalsAttr, PODVector<unsigned char>, Variant::emptyBuffer,
+        AM_FILE | AM_NOEDIT);
 }
 
 void DecalSet::ApplyAttributes()
@@ -253,7 +254,7 @@ void DecalSet::SetMaterial(Material* material)
 void DecalSet::SetMaxVertices(unsigned num)
 {
     // Never expand to 32 bit indices
-    num = Clamp((int)num, MIN_VERTICES, MAX_VERTICES);
+    num = (unsigned)Clamp((int)num, MIN_VERTICES, MAX_VERTICES);
 
     if (num != maxVertices_)
     {
@@ -330,8 +331,8 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu
                 continue;
 
             // Represent the decal as a sphere, try to find the biggest colliding bone
-            Sphere decalSphere(bone->node_->GetWorldTransform().Inverse() * worldPosition, 0.5f * size /
-                bone->node_->GetWorldScale().Length());
+            Sphere decalSphere
+                (bone->node_->GetWorldTransform().Inverse() * worldPosition, 0.5f * size / bone->node_->GetWorldScale().Length());
 
             if (bone->collisionMask_ & BONECOLLISION_BOX)
             {
@@ -422,14 +423,14 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu
     if (newDecal.vertices_.Size() > maxVertices_)
     {
         LOGWARNING("Can not add decal, vertex count " + String(newDecal.vertices_.Size()) + " exceeds maximum " +
-            String(maxVertices_));
+                   String(maxVertices_));
         decals_.Pop();
         return false;
     }
     if (newDecal.indices_.Size() > maxIndices_)
     {
         LOGWARNING("Can not add decal, index count " + String(newDecal.indices_.Size()) + " exceeds maximum " +
-            String(maxIndices_));
+                   String(maxIndices_));
         decals_.Pop();
         return false;
     }
@@ -933,7 +934,7 @@ bool DecalSet::GetBones(Drawable* target, unsigned batchIndex, const float* blen
                 }
             }
 
-            newBlendIndices[i] = index;
+            newBlendIndices[i] = (unsigned char)index;
         }
         else
             newBlendIndices[i] = 0;

+ 22 - 8
Source/Atomic/Atomic3D/DecalSet.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -22,10 +22,10 @@
 
 #pragma once
 
-#include "../Graphics/Drawable.h"
-#include "../Math/Frustum.h"
 #include "../Container/List.h"
+#include "../Graphics/Drawable.h"
 #include "../Atomic3D/Skeleton.h"
+#include "../Math/Frustum.h"
 
 namespace Atomic
 {
@@ -134,7 +134,9 @@ public:
     /// Set maximum number of decal vertex indices.
     void SetMaxIndices(unsigned num);
     /// Add a decal at world coordinates, using a target drawable's geometry for reference. If the decal needs to move with the target, the decal component should be created to the target's node. Return true if successful.
-    bool AddDecal(Drawable* target, const Vector3& worldPosition, const Quaternion& worldRotation, float size, float aspectRatio, float depth, const Vector2& topLeftUV, const Vector2& bottomRightUV, float timeToLive = 0.0f, float normalCutoff = 0.1f, unsigned subGeometry = M_MAX_UNSIGNED);
+    bool AddDecal(Drawable* target, const Vector3& worldPosition, const Quaternion& worldRotation, float size, float aspectRatio,
+        float depth, const Vector2& topLeftUV, const Vector2& bottomRightUV, float timeToLive = 0.0f, float normalCutoff = 0.1f,
+        unsigned subGeometry = M_MAX_UNSIGNED);
     /// Remove n oldest decals.
     void RemoveDecals(unsigned num);
     /// Remove all decals.
@@ -142,14 +144,19 @@ public:
 
     /// Return material.
     Material* GetMaterial() const;
+
     /// Return number of decals.
     unsigned GetNumDecals() const { return decals_.Size(); }
+
     /// Retur number of vertices in the decals.
     unsigned GetNumVertices() const { return numVertices_; }
+
     /// Retur number of vertex indices in the decals.
     unsigned GetNumIndices() const { return numIndices_; }
+
     /// Return maximum number of decal vertices.
     unsigned GetMaxVertices() const { return maxVertices_; }
+
     /// Return maximum number of decal vertex indices.
     unsigned GetMaxIndices() const { return maxIndices_; }
 
@@ -170,13 +177,20 @@ protected:
 
 private:
     /// Get triangle faces from the target geometry.
-    void GetFaces(Vector<PODVector<DecalVertex> >& faces, Drawable* target, unsigned batchIndex, const Frustum& frustum, const Vector3& decalNormal, float normalCutoff);
+    void GetFaces(Vector<PODVector<DecalVertex> >& faces, Drawable* target, unsigned batchIndex, const Frustum& frustum,
+        const Vector3& decalNormal, float normalCutoff);
     /// Get triangle face from the target geometry.
-    void GetFace(Vector<PODVector<DecalVertex> >& faces, Drawable* target, unsigned batchIndex, unsigned i0, unsigned i1, unsigned i2, const unsigned char* positionData, const unsigned char* normalData, const unsigned char* skinningData, unsigned positionStride, unsigned normalStride, unsigned skinningStride, const Frustum& frustum, const Vector3& decalNormal, float normalCutoff);
+    void GetFace
+        (Vector<PODVector<DecalVertex> >& faces, Drawable* target, unsigned batchIndex, unsigned i0, unsigned i1, unsigned i2,
+            const unsigned char* positionData, const unsigned char* normalData, const unsigned char* skinningData,
+            unsigned positionStride, unsigned normalStride, unsigned skinningStride, const Frustum& frustum,
+            const Vector3& decalNormal, float normalCutoff);
     /// Get bones referenced by skinning data and remap the skinning indices. Return true if successful.
-    bool GetBones(Drawable* target, unsigned batchIndex, const float* blendWeights, const unsigned char* blendIndices, unsigned char* newBlendIndices);
+    bool GetBones(Drawable* target, unsigned batchIndex, const float* blendWeights, const unsigned char* blendIndices,
+        unsigned char* newBlendIndices);
     /// Calculate UV coordinates for the decal.
-    void CalculateUVs(Decal& decal, const Matrix3x4& view, const Matrix4& projection, const Vector2& topLeftUV, const Vector2& bottomRightUV);
+    void CalculateUVs
+        (Decal& decal, const Matrix3x4& view, const Matrix4& projection, const Vector2& topLeftUV, const Vector2& bottomRightUV);
     /// Transform decal's vertices from the target geometry to the decal set local space.
     void TransformVertices(Decal& decal, const Matrix3x4& transform);
     /// Remove a decal by iterator and return iterator to the next decal.

+ 2 - 0
Source/Atomic/Atomic3D/LMStaticModel.cpp

@@ -74,6 +74,7 @@ ResourceRef LMStaticModel::GetLightmapTextureAttr() const
 
 void LMStaticModel::UpdateBatches(const FrameInfo& frame)
 {
+    /*
     StaticModel::UpdateBatches(frame);
 
     if (batches_.Size() > 1)
@@ -95,6 +96,7 @@ void LMStaticModel::UpdateBatches(const FrameInfo& frame)
             batches_[0].material_ = lightmapMaterial_;
 
     }
+    */
 
 }
 

+ 66 - 67
Source/Atomic/Atomic3D/Model.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,19 +20,16 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
-#include "../IO/Deserializer.h"
+#include "../Core/Profiler.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/IndexBuffer.h"
-#include "../IO/Log.h"
 #include "../Atomic3D/Model.h"
-#include "../Core/Profiler.h"
 #include "../Graphics/Graphics.h"
-#include "../IO/Serializer.h"
 #include "../Graphics/VertexBuffer.h"
-
-#include <cstring>
+#include "../IO/Log.h"
 
 #include "../DebugNew.h"
 
@@ -81,14 +78,14 @@ bool Model::BeginLoad(Deserializer& source)
         LOGERROR(source.GetName() + " is not a valid model file");
         return false;
     }
-    
+
     geometries_.Clear();
     geometryBoneMappings_.Clear();
     geometryCenters_.Clear();
     morphs_.Clear();
     vertexBuffers_.Clear();
     indexBuffers_.Clear();
-    
+
     unsigned memoryUse = sizeof(Model);
     bool async = GetAsyncLoadState() == ASYNC_LOADING;
 
@@ -104,7 +101,7 @@ bool Model::BeginLoad(Deserializer& source)
         unsigned elementMask = source.ReadUInt();
         morphRangeStarts_[i] = source.ReadUInt();
         morphRangeCounts_[i] = source.ReadUInt();
-        
+
         SharedPtr<VertexBuffer> buffer(new VertexBuffer(context_));
         unsigned vertexSize = VertexBuffer::GetVertexSize(elementMask);
 
@@ -140,7 +137,7 @@ bool Model::BeginLoad(Deserializer& source)
     {
         unsigned indexCount = source.ReadUInt();
         unsigned indexSize = source.ReadUInt();
-        
+
         SharedPtr<IndexBuffer> buffer(new IndexBuffer(context_));
 
         // Prepare index buffer data to be uploaded during EndLoad()
@@ -166,7 +163,7 @@ bool Model::BeginLoad(Deserializer& source)
         memoryUse += sizeof(IndexBuffer) + indexCount * indexSize;
         indexBuffers_.Push(buffer);
     }
-    
+
     // Read geometries
     unsigned numGeometries = source.ReadUInt();
     geometries_.Reserve(numGeometries);
@@ -181,22 +178,22 @@ bool Model::BeginLoad(Deserializer& source)
         for (unsigned j = 0; j < boneMappingCount; ++j)
             boneMapping[j] = source.ReadUInt();
         geometryBoneMappings_.Push(boneMapping);
-        
+
         unsigned numLodLevels = source.ReadUInt();
         Vector<SharedPtr<Geometry> > geometryLodLevels;
         geometryLodLevels.Reserve(numLodLevels);
         loadGeometries_[i].Resize(numLodLevels);
-        
+
         for (unsigned j = 0; j < numLodLevels; ++j)
         {
             float distance = source.ReadFloat();
             PrimitiveType type = (PrimitiveType)source.ReadUInt();
-            
+
             unsigned vbRef = source.ReadUInt();
             unsigned ibRef = source.ReadUInt();
             unsigned indexStart = source.ReadUInt();
             unsigned indexCount = source.ReadUInt();
-            
+
             if (vbRef >= vertexBuffers_.Size())
             {
                 LOGERROR("Vertex buffer index out of bounds");
@@ -213,7 +210,7 @@ bool Model::BeginLoad(Deserializer& source)
                 loadGeometries_.Clear();
                 return false;
             }
-            
+
             SharedPtr<Geometry> geometry(new Geometry(context_));
             geometry->SetLodDistance(distance);
 
@@ -227,30 +224,30 @@ bool Model::BeginLoad(Deserializer& source)
             geometryLodLevels.Push(geometry);
             memoryUse += sizeof(Geometry);
         }
-        
+
         geometries_.Push(geometryLodLevels);
     }
-    
+
     // Read morphs
     unsigned numMorphs = source.ReadUInt();
     morphs_.Reserve(numMorphs);
     for (unsigned i = 0; i < numMorphs; ++i)
     {
         ModelMorph newMorph;
-        
+
         newMorph.name_ = source.ReadString();
         newMorph.nameHash_ = newMorph.name_;
         newMorph.weight_ = 0.0f;
         unsigned numBuffers = source.ReadUInt();
-        
+
         for (unsigned j = 0; j < numBuffers; ++j)
         {
             VertexBufferMorph newBuffer;
             unsigned bufferIndex = source.ReadUInt();
-            
+
             newBuffer.elementMask_ = source.ReadUInt();
             newBuffer.vertexCount_ = source.ReadUInt();
-            
+
             // Base size: size of each vertex index
             unsigned vertexSize = sizeof(unsigned);
             // Add size of individual elements
@@ -262,31 +259,31 @@ bool Model::BeginLoad(Deserializer& source)
                 vertexSize += sizeof(Vector3);
             newBuffer.dataSize_ = newBuffer.vertexCount_ * vertexSize;
             newBuffer.morphData_ = new unsigned char[newBuffer.dataSize_];
-            
+
             source.Read(&newBuffer.morphData_[0], newBuffer.vertexCount_ * vertexSize);
-            
+
             newMorph.buffers_[bufferIndex] = newBuffer;
             memoryUse += sizeof(VertexBufferMorph) + newBuffer.vertexCount_ * vertexSize;
         }
-        
+
         morphs_.Push(newMorph);
         memoryUse += sizeof(ModelMorph);
     }
-    
+
     // Read skeleton
     skeleton_.Load(source);
     memoryUse += skeleton_.GetNumBones() * sizeof(Bone);
-    
+
     // Read bounding box
     boundingBox_ = source.ReadBoundingBox();
-    
+
     // Read geometry centers
     for (unsigned i = 0; i < geometries_.Size() && !source.IsEof(); ++i)
         geometryCenters_.Push(source.ReadVector3());
     while (geometryCenters_.Size() < geometries_.Size())
         geometryCenters_.Push(Vector3::ZERO);
     memoryUse += sizeof(Vector3) * geometries_.Size();
-    
+
     SetMemoryUse(memoryUse);
     return true;
 }
@@ -343,7 +340,7 @@ bool Model::Save(Serializer& dest) const
     // Write ID
     if (!dest.WriteFileID("UMDL"))
         return false;
-    
+
     // Write vertex buffers
     dest.WriteUInt(vertexBuffers_.Size());
     for (unsigned i = 0; i < vertexBuffers_.Size(); ++i)
@@ -372,7 +369,7 @@ bool Model::Save(Serializer& dest) const
         dest.WriteUInt(geometryBoneMappings_[i].Size());
         for (unsigned j = 0; j < geometryBoneMappings_[i].Size(); ++j)
             dest.WriteUInt(geometryBoneMappings_[i][j]);
-        
+
         // Write the LOD levels
         dest.WriteUInt(geometries_[i].Size());
         for (unsigned j = 0; j < geometries_[i].Size(); ++j)
@@ -386,22 +383,22 @@ bool Model::Save(Serializer& dest) const
             dest.WriteUInt(geometry->GetIndexCount());
         }
     }
-    
+
     // Write morphs
     dest.WriteUInt(morphs_.Size());
     for (unsigned i = 0; i < morphs_.Size(); ++i)
     {
         dest.WriteString(morphs_[i].name_);
         dest.WriteUInt(morphs_[i].buffers_.Size());
-        
+
         // Write morph vertex buffers
-        for (HashMap<unsigned int, VertexBufferMorph>::ConstIterator j = morphs_[i].buffers_.Begin();
-            j != morphs_[i].buffers_.End(); ++j)
+        for (HashMap<unsigned, VertexBufferMorph>::ConstIterator j = morphs_[i].buffers_.Begin();
+             j != morphs_[i].buffers_.End(); ++j)
         {
             dest.WriteUInt(j->first_);
             dest.WriteUInt(j->second_.elementMask_);
             dest.WriteUInt(j->second_.vertexCount_);
-            
+
             // Base size: size of each vertex index
             unsigned vertexSize = sizeof(unsigned);
             // Add size of individual elements
@@ -411,21 +408,21 @@ bool Model::Save(Serializer& dest) const
                 vertexSize += sizeof(Vector3);
             if (j->second_.elementMask_ & MASK_TANGENT)
                 vertexSize += sizeof(Vector3);
-            
+
             dest.Write(j->second_.morphData_.Get(), vertexSize * j->second_.vertexCount_);
         }
     }
-    
+
     // Write skeleton
     skeleton_.Save(dest);
-    
+
     // Write bounding box
     dest.WriteBoundingBox(boundingBox_);
-    
+
     // Write geometry centers
     for (unsigned i = 0; i < geometryCenters_.Size(); ++i)
         dest.WriteVector3(geometryCenters_[i]);
-    
+
     return true;
 }
 
@@ -434,7 +431,8 @@ void Model::SetBoundingBox(const BoundingBox& box)
     boundingBox_ = box;
 }
 
-bool Model::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& morphRangeStarts, const PODVector<unsigned>& morphRangeCounts)
+bool Model::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& morphRangeStarts,
+    const PODVector<unsigned>& morphRangeCounts)
 {
     for (unsigned i = 0; i < buffers.Size(); ++i)
     {
@@ -449,18 +447,18 @@ bool Model::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, co
             return false;
         }
     }
-    
+
     vertexBuffers_ = buffers;
     morphRangeStarts_.Resize(buffers.Size());
     morphRangeCounts_.Resize(buffers.Size());
-    
+
     // If morph ranges are not specified for buffers, assume to be zero
     for (unsigned i = 0; i < buffers.Size(); ++i)
     {
         morphRangeStarts_[i] = i < morphRangeStarts.Size() ? morphRangeStarts[i] : 0;
         morphRangeCounts_[i] = i < morphRangeCounts.Size() ? morphRangeCounts[i] : 0;
     }
-    
+
     return true;
 }
 
@@ -479,7 +477,7 @@ bool Model::SetIndexBuffers(const Vector<SharedPtr<IndexBuffer> >& buffers)
             return false;
         }
     }
-    
+
     indexBuffers_ = buffers;
     return true;
 }
@@ -489,7 +487,7 @@ void Model::SetNumGeometries(unsigned num)
     geometries_.Resize(num);
     geometryBoneMappings_.Resize(num);
     geometryCenters_.Resize(num);
-    
+
     // For easier creation of from-scratch geometry, ensure that all geometries start with at least 1 LOD level (0 makes no sense)
     for (unsigned i = 0; i < geometries_.Size(); ++i)
     {
@@ -510,7 +508,7 @@ bool Model::SetNumGeometryLodLevels(unsigned index, unsigned num)
         LOGERROR("Zero LOD levels not allowed");
         return false;
     }
-    
+
     geometries_[index].Resize(num);
     return true;
 }
@@ -527,7 +525,7 @@ bool Model::SetGeometry(unsigned index, unsigned lodLevel, Geometry* geometry)
         LOGERROR("LOD level index out of bounds");
         return false;
     }
-    
+
     geometries_[index][lodLevel] = geometry;
     return true;
 }
@@ -539,7 +537,7 @@ bool Model::SetGeometryCenter(unsigned index, const Vector3& center)
         LOGERROR("Geometry index out of bounds");
         return false;
     }
-    
+
     geometryCenters_[index] = center;
     return true;
 }
@@ -571,14 +569,14 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
     ret->morphs_ = morphs_;
     ret->morphRangeStarts_ = morphRangeStarts_;
     ret->morphRangeCounts_ = morphRangeCounts_;
-    
+
     // Deep copy vertex/index buffers
     HashMap<VertexBuffer*, VertexBuffer*> vbMapping;
     for (Vector<SharedPtr<VertexBuffer> >::ConstIterator i = vertexBuffers_.Begin(); i != vertexBuffers_.End(); ++i)
     {
         VertexBuffer* origBuffer = *i;
         SharedPtr<VertexBuffer> cloneBuffer;
-        
+
         if (origBuffer)
         {
             cloneBuffer = new VertexBuffer(context_);
@@ -599,17 +597,18 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
 
         ret->vertexBuffers_.Push(cloneBuffer);
     }
-    
+
     HashMap<IndexBuffer*, IndexBuffer*> ibMapping;
     for (Vector<SharedPtr<IndexBuffer> >::ConstIterator i = indexBuffers_.Begin(); i != indexBuffers_.End(); ++i)
     {
         IndexBuffer* origBuffer = *i;
         SharedPtr<IndexBuffer> cloneBuffer;
-        
+
         if (origBuffer)
         {
             cloneBuffer = new IndexBuffer(context_);
-            cloneBuffer->SetSize(origBuffer->GetIndexCount(), origBuffer->GetIndexSize() == sizeof(unsigned), origBuffer->IsDynamic());
+            cloneBuffer->SetSize(origBuffer->GetIndexCount(), origBuffer->GetIndexSize() == sizeof(unsigned),
+                origBuffer->IsDynamic());
             cloneBuffer->SetShadowed(origBuffer->IsShadowed());
             if (origBuffer->IsShadowed())
                 cloneBuffer->SetData(origBuffer->GetShadowData());
@@ -626,7 +625,7 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
 
         ret->indexBuffers_.Push(cloneBuffer);
     }
-    
+
     // Deep copy all the geometry LOD levels and refer to the copied vertex/index buffers
     ret->geometries_.Resize(geometries_.Size());
     for (unsigned i = 0; i < geometries_.Size(); ++i)
@@ -636,7 +635,7 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
         {
             SharedPtr<Geometry> cloneGeometry;
             Geometry* origGeometry = geometries_[i][j];
-            
+
             if (origGeometry)
             {
                 cloneGeometry = new Geometry(context_);
@@ -651,12 +650,12 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
                     origGeometry->GetIndexCount(), origGeometry->GetVertexStart(), origGeometry->GetVertexCount(), false);
                 cloneGeometry->SetLodDistance(origGeometry->GetLodDistance());
             }
-            
+
             ret->geometries_[i][j] = cloneGeometry;
         }
     }
-    
-    
+
+
     // Deep copy the morph data (if any) to allow modifying it
     for (Vector<ModelMorph>::Iterator i = ret->morphs_.Begin(); i != ret->morphs_.End(); ++i)
     {
@@ -672,9 +671,9 @@ SharedPtr<Model> Model::Clone(const String& cloneName) const
             }
         }
     }
-    
+
     ret->SetMemoryUse(GetMemoryUse());
-    
+
     return ret;
 }
 
@@ -687,10 +686,10 @@ Geometry* Model::GetGeometry(unsigned index, unsigned lodLevel) const
 {
     if (index >= geometries_.Size() || geometries_[index].Empty())
         return 0;
-    
+
     if (lodLevel >= geometries_[index].Size())
         lodLevel = geometries_[index].Size() - 1;
-    
+
     return geometries_[index][lodLevel];
 }
 
@@ -711,7 +710,7 @@ const ModelMorph* Model::GetMorph(StringHash nameHash) const
         if (i->nameHash_ == nameHash)
             return &(*i);
     }
-    
+
     return 0;
 }
 

+ 27 - 10
Source/Atomic/Atomic3D/Model.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -23,11 +23,11 @@
 #pragma once
 
 #include "../Container/ArrayPtr.h"
-#include "../Math/BoundingBox.h"
+#include "../Container/Ptr.h"
 #include "../Graphics/GraphicsDefs.h"
 #include "../Atomic3D/Skeleton.h"
+#include "../Math/BoundingBox.h"
 #include "../Resource/Resource.h"
-#include "../Container/Ptr.h"
 
 namespace Atomic
 {
@@ -108,7 +108,7 @@ struct GeometryDesc
 class ATOMIC_API Model : public Resource
 {
     OBJECT(Model);
-    
+
 public:
     /// Construct.
     Model(Context* context);
@@ -116,18 +116,19 @@ public:
     virtual ~Model();
     /// Register object factory.
     static void RegisterObject(Context* context);
-    
+
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     virtual bool BeginLoad(Deserializer& source);
     /// Finish resource loading. Always called from the main thread. Return true if successful.
     virtual bool EndLoad();
     /// Save resource. Return true if successful.
     virtual bool Save(Serializer& dest) const;
-    
+
     /// Set local-space bounding box.
     void SetBoundingBox(const BoundingBox& box);
     /// Set vertex buffers and their morph ranges.
-    bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& morphRangeStarts, const PODVector<unsigned>& morphRangeCounts);
+    bool SetVertexBuffers(const Vector<SharedPtr<VertexBuffer> >& buffers, const PODVector<unsigned>& morphRangeStarts,
+        const PODVector<unsigned>& morphRangeCounts);
     /// Set index buffers.
     bool SetIndexBuffers(const Vector<SharedPtr<IndexBuffer> >& buffers);
     /// Set number of geometries.
@@ -146,33 +147,49 @@ public:
     void SetMorphs(const Vector<ModelMorph>& morphs);
     /// Clone the model. The geometry data is deep-copied and can be modified in the clone without affecting the original.
     SharedPtr<Model> Clone(const String& cloneName = String::EMPTY) const;
-    
+
     /// Return bounding box.
     const BoundingBox& GetBoundingBox() const { return boundingBox_; }
+
     /// Return skeleton.
     Skeleton& GetSkeleton() { return skeleton_; }
+
     /// Return vertex buffers.
     const Vector<SharedPtr<VertexBuffer> >& GetVertexBuffers() const { return vertexBuffers_; }
+
     /// Return index buffers.
     const Vector<SharedPtr<IndexBuffer> >& GetIndexBuffers() const { return indexBuffers_; }
+
     /// Return number of geometries.
     unsigned GetNumGeometries() const { return geometries_.Size(); }
+
     /// Return number of LOD levels in geometry.
     unsigned GetNumGeometryLodLevels(unsigned index) const;
+
     /// Return geometry pointers.
     const Vector<Vector<SharedPtr<Geometry> > >& GetGeometries() const { return geometries_; }
+
     /// Return geometry center points.
     const PODVector<Vector3>& GetGeometryCenters() const { return geometryCenters_; }
+
     /// Return geometry by index and LOD level. The LOD level is clamped if out of range.
     Geometry* GetGeometry(unsigned index, unsigned lodLevel) const;
+
     /// Return geometry center by index.
-    const Vector3& GetGeometryCenter(unsigned index) const { return index < geometryCenters_.Size() ? geometryCenters_[index] : Vector3::ZERO; }
+    const Vector3& GetGeometryCenter(unsigned index) const
+    {
+        return index < geometryCenters_.Size() ? geometryCenters_[index] : Vector3::ZERO;
+    }
+
     /// Return geometery bone mappings.
     const Vector<PODVector<unsigned> >& GetGeometryBoneMappings() const { return geometryBoneMappings_; }
+
     /// Return vertex morphs.
     const Vector<ModelMorph>& GetMorphs() const { return morphs_; }
+
     /// Return number of vertex morphs.
     unsigned GetNumMorphs() const { return morphs_.Size(); }
+
     /// Return vertex morph by index.
     const ModelMorph* GetMorph(unsigned index) const;
     /// Return vertex morph by name.
@@ -183,7 +200,7 @@ public:
     unsigned GetMorphRangeStart(unsigned bufferIndex) const;
     /// Return vertex buffer morph range vertex count.
     unsigned GetMorphRangeCount(unsigned bufferIndex) const;
-    
+
 private:
     /// Bounding box.
     BoundingBox boundingBox_;

+ 18 - 18
Source/Atomic/Atomic3D/ParticleEffect.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,11 +20,12 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
-#include "../IO/Log.h"
 #include "../Graphics/Material.h"
 #include "../Atomic3D/ParticleEffect.h"
+#include "../IO/Log.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/XMLFile.h"
 
@@ -150,7 +151,7 @@ bool ParticleEffect::BeginLoad(Deserializer& source)
     }
 
     if (rootElem.HasChild("numparticles"))
-        SetNumParticles(rootElem.GetChild("numparticles").GetInt("value"));
+        SetNumParticles((unsigned)rootElem.GetChild("numparticles").GetInt("value"));
 
     if (rootElem.HasChild("updateinvisible"))
         updateInvisible_ = rootElem.GetChild("updateinvisible").GetBool("enable");
@@ -254,7 +255,8 @@ bool ParticleEffect::BeginLoad(Deserializer& source)
     if (rootElem.HasChild("colorfade"))
     {
         Vector<ColorFrame> fades;
-        for (XMLElement colorFadeElem = rootElem.GetChild("colorfade"); colorFadeElem; colorFadeElem = colorFadeElem.GetNext("colorfade"))
+        for (XMLElement colorFadeElem = rootElem.GetChild("colorfade"); colorFadeElem;
+             colorFadeElem = colorFadeElem.GetNext("colorfade"))
             fades.Push(ColorFrame(colorFadeElem.GetColor("color"), colorFadeElem.GetFloat("time")));
 
         SetColorFrames(fades);
@@ -339,7 +341,7 @@ bool ParticleEffect::Load(const XMLElement& source)
     }
 
     if (source.HasChild("numparticles"))
-        SetNumParticles(source.GetChild("numparticles").GetInt("value"));
+        SetNumParticles((unsigned)source.GetChild("numparticles").GetInt("value"));
 
     if (source.HasChild("updateinvisible"))
         updateInvisible_ = source.GetChild("updateinvisible").GetBool("enable");
@@ -443,7 +445,8 @@ bool ParticleEffect::Load(const XMLElement& source)
     if (source.HasChild("colorfade"))
     {
         Vector<ColorFrame> fades;
-        for (XMLElement colorFadeElem = source.GetChild("colorfade"); colorFadeElem; colorFadeElem = colorFadeElem.GetNext("colorfade"))
+        for (XMLElement colorFadeElem = source.GetChild("colorfade"); colorFadeElem;
+             colorFadeElem = colorFadeElem.GetNext("colorfade"))
             fades.Push(ColorFrame(colorFadeElem.GetColor("color"), colorFadeElem.GetFloat("time")));
 
         SetColorFrames(fades);
@@ -590,7 +593,7 @@ void ParticleEffect::SetMaterial(Material* material)
 
 void ParticleEffect::SetNumParticles(unsigned num)
 {
-    numParticles_ = Max(0, num);
+    numParticles_ = (unsigned)Max(0, num);
 }
 
 void ParticleEffect::SetUpdateInvisible(bool enable)
@@ -763,7 +766,7 @@ void ParticleEffect::RemoveColorFrame(unsigned index)
 {
     unsigned s = colorFrames_.Size();
 
-    for (unsigned i = index; i < s - 1 ; i++)
+    for (unsigned i = index; i < s - 1; i++)
     {
         colorFrames_[i].color_ = colorFrames_[i + 1].color_;
         colorFrames_[i].time_ = colorFrames_[i + 1].time_;
@@ -780,7 +783,7 @@ void ParticleEffect::SetColorFrames(const Vector<ColorFrame>& colorFrames)
 void ParticleEffect::SetColorFrame(unsigned index, const ColorFrame& colorFrame)
 {
     if (colorFrames_.Size() < index + 1)
-         colorFrames_.Resize(index + 1);
+        colorFrames_.Resize(index + 1);
     colorFrames_[index] = colorFrame;
 }
 
@@ -788,7 +791,7 @@ void ParticleEffect::SetNumColorFrames(unsigned number)
 {
     unsigned s = colorFrames_.Size();
     if (s != number)
-         colorFrames_.Resize(number);
+        colorFrames_.Resize(number);
 }
 
 void ParticleEffect::SortColorFrames()
@@ -833,7 +836,7 @@ void ParticleEffect::RemoveTextureFrame(unsigned index)
 {
     unsigned s = textureFrames_.Size();
 
-    for (unsigned i = index; i < s - 1 ; i++)
+    for (unsigned i = index; i < s - 1; i++)
     {
         textureFrames_[i].uv_ = textureFrames_[i + 1].uv_;
         textureFrames_[i].time_ = textureFrames_[i + 1].time_;
@@ -858,7 +861,7 @@ void ParticleEffect::SetNumTextureFrames(unsigned number)
 {
     unsigned s = textureFrames_.Size();
     if (s != number)
-         textureFrames_.Resize(number);
+        textureFrames_.Resize(number);
 }
 
 void ParticleEffect::SortTextureFrames()
@@ -881,11 +884,8 @@ const TextureFrame* ParticleEffect::GetTextureFrame(unsigned index) const
 
 Vector3 ParticleEffect::GetRandomDirection() const
 {
-    return Vector3(
-        Lerp(directionMin_.x_, directionMax_.x_, Random(1.0f)),
-        Lerp(directionMin_.y_, directionMax_.y_, Random(1.0f)),
-        Lerp(directionMin_.z_, directionMax_.z_, Random(1.0f))
-        );
+    return Vector3(Lerp(directionMin_.x_, directionMax_.x_, Random(1.0f)), Lerp(directionMin_.y_, directionMax_.y_, Random(1.0f)),
+        Lerp(directionMin_.z_, directionMax_.z_, Random(1.0f)));
 }
 
 Vector2 ParticleEffect::GetRandomSize() const

+ 38 - 4
Source/Atomic/Atomic3D/ParticleEffect.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -117,7 +117,7 @@ public:
     virtual bool EndLoad();
     /// Save resource. Return true if successful.
     virtual bool Save(Serializer& dest) const;
-    
+
     /// Save resource to XMLElement. Return true if successful.
     bool Save(XMLElement& dest) const;
     /// Load resource from XMLElement synchronously. Return true if successful.
@@ -175,7 +175,7 @@ public:
     /// Set particle minimum rotation speed.
     void SetMinRotationSpeed(float speed);
     /// Set particle maximum rotation speed.
-    void SetMaxRotationSpeed(float speed);    
+    void SetMaxRotationSpeed(float speed);
     /// Set particle size additive modifier.
     void SetSizeAdd(float sizeAdd);
     /// Set particle size multiplicative modifier.
@@ -213,72 +213,106 @@ public:
 
     /// Return material.
     Material* GetMaterial() const { return material_; }
+
     /// Return maximum number of particles.
     unsigned GetNumParticles() const { return numParticles_; }
+
     /// Return whether to update when particles are not visible.
     bool GetUpdateInvisible() const { return updateInvisible_; }
+
     /// Return whether billboards are relative to the scene node.
     bool IsRelative() const { return relative_; }
+
     /// Return whether scene node scale affects billboards' size.
     bool IsScaled() const { return scaled_; }
+
     /// Return whether billboards are sorted.
     bool IsSorted() const { return sorted_; }
+
     /// Return animation Lod bias.
     float GetAnimationLodBias() const { return animationLodBias_; }
+
     /// Return emitter type.
     EmitterType GetEmitterType() const { return emitterType_; }
+
     /// Return emitter size.
     const Vector3& GetEmitterSize() const { return emitterSize_; }
+
     /// Return negative direction limit.
     const Vector3& GetMinDirection() const { return directionMin_; }
+
     /// Return positive direction limit.
     const Vector3& GetMaxDirection() const { return directionMax_; }
+
     /// Return constant force acting on particles.
     const Vector3& GetConstantForce() const { return constantForce_; }
+
     /// Return particle velocity damping force.
     float GetDampingForce() const { return dampingForce_; }
+
     /// Return emission active period length (0 = infinite.)
     float GetActiveTime() const { return activeTime_; }
+
     /// Return emission inactive period length (0 = infinite.)
     float GetInactiveTime() const { return inactiveTime_; }
+
     /// Return minimum emission rate.
     float GetMinEmissionRate() const { return emissionRateMin_; }
+
     /// Return maximum emission rate.
     float GetMaxEmissionRate() const { return emissionRateMax_; }
+
     /// Return particle minimum size.
     const Vector2& GetMinParticleSize() const { return sizeMin_; }
+
     /// Return particle maximum size.
     const Vector2& GetMaxParticleSize() const { return sizeMax_; }
+
     /// Return particle minimum time to live.
     float GetMinTimeToLive() const { return timeToLiveMin_; }
+
     /// Return particle maximum time to live.
     float GetMaxTimeToLive() const { return timeToLiveMax_; }
+
     /// Return particle minimum velocity.
     float GetMinVelocity() const { return velocityMin_; }
+
     /// Return particle maximum velocity.
     float GetMaxVelocity() const { return velocityMax_; }
+
     /// Return particle minimum rotation.
     float GetMinRotation() const { return rotationMin_; }
+
     /// Return particle maximum rotation.
     float GetMaxRotation() const { return rotationMax_; }
+
     /// Return particle minimum rotation speed.
     float GetMinRotationSpeed() const { return rotationSpeedMin_; }
+
     /// Return particle maximum rotation speed.
-    float GetMaxRotationSpeed() const { return rotationSpeedMax_; }   
+    float GetMaxRotationSpeed() const { return rotationSpeedMax_; }
+
     /// Return particle size additive modifier.
     float GetSizeAdd() const { return sizeAdd_; }
+
     /// Return particle size multiplicative modifier.
     float GetSizeMul() const { return sizeMul_; }
+
     /// Return all color animation frames.
     const Vector<ColorFrame>& GetColorFrames() const { return colorFrames_; }
+
     /// Return number of color animation frames.
     unsigned GetNumColorFrames() const { return colorFrames_.Size(); }
+
     /// Return a color animation frame, or null if outside range.
     const ColorFrame* GetColorFrame(unsigned index) const;
+
     /// Return all texture animation frames.
     const Vector<TextureFrame>& GetTextureFrames() const { return textureFrames_; }
+
     /// Return number of texture animation frames.
     unsigned GetNumTextureFrames() const { return textureFrames_.Size(); }
+
     /// Return a texture animation frame, or null if outside range.
     const TextureFrame* GetTextureFrame(unsigned index) const;
 

+ 17 - 15
Source/Atomic/Atomic3D/ParticleEmitter.cpp

@@ -20,11 +20,12 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
 #include "../Core/Context.h"
+#include "../Core/Profiler.h"
 #include "../Atomic3D/ParticleEffect.h"
 #include "../Atomic3D/ParticleEmitter.h"
-#include "../Core/Profiler.h"
 #include "../Resource/ResourceCache.h"
 #include "../Resource/ResourceEvents.h"
 #include "../Scene/Scene.h"
@@ -59,7 +60,8 @@ void ParticleEmitter::RegisterObject(Context* context)
     context->RegisterFactory<ParticleEmitter>(GEOMETRY_CATEGORY);
 
     ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Effect", GetEffectAttr, SetEffectAttr, ResourceRef, ResourceRef(ParticleEffect::GetTypeStatic()), AM_DEFAULT);
+    MIXED_ACCESSOR_ATTRIBUTE("Effect", GetEffectAttr, SetEffectAttr, ResourceRef, ResourceRef(ParticleEffect::GetTypeStatic()),
+        AM_DEFAULT);
     ENUM_ATTRIBUTE("Face Camera Mode", faceCameraMode_, faceCameraModeNames, FC_ROTATE_XYZ, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
     ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
@@ -70,8 +72,10 @@ void ParticleEmitter::RegisterObject(Context* context)
     ATTRIBUTE("Period Timer", float, periodTimer_, 0.0f, AM_FILE | AM_NOEDIT);
     ATTRIBUTE("Emission Timer", float, emissionTimer_, 0.0f, AM_FILE | AM_NOEDIT);
     COPY_BASE_ATTRIBUTES(Drawable);
-    MIXED_ACCESSOR_ATTRIBUTE("Particles", GetParticlesAttr, SetParticlesAttr, VariantVector, Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
-    MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetParticleBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector, AM_FILE | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Particles", GetParticlesAttr, SetParticlesAttr, VariantVector, Variant::emptyVariantVector,
+        AM_FILE | AM_NOEDIT);
+    MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetParticleBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector,
+        AM_FILE | AM_NOEDIT);
     ATTRIBUTE("Serialize Particles", bool, serializeParticles_, true, AM_FILE);
 }
 
@@ -354,8 +358,8 @@ void ParticleEmitter::SetParticlesAttr(const VariantVector& value)
         i->timeToLive_ = value[index++].GetFloat();
         i->scale_ = value[index++].GetFloat();
         i->rotationSpeed_ = value[index++].GetFloat();
-        i->colorIndex_ = value[index++].GetInt();
-        i->texIndex_ = value[index++].GetInt();
+        i->colorIndex_ = (unsigned)value[index++].GetInt();
+        i->texIndex_ = (unsigned)value[index++].GetInt();
     }
 }
 
@@ -409,16 +413,14 @@ VariantVector ParticleEmitter::GetParticleBillboardsAttr() const
     return ret;
 }
 
-void ParticleEmitter::OnNodeSet(Node* node)
+void ParticleEmitter::OnSceneSet(Scene* scene)
 {
-    BillboardSet::OnNodeSet(node);
+    BillboardSet::OnSceneSet(scene);
 
-    if (node)
-    {
-        Scene* scene = GetScene();
-        if (scene && IsEnabledEffective())
-            SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(ParticleEmitter, HandleScenePostUpdate));
-    }
+    if (scene && IsEnabledEffective())
+        SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(ParticleEmitter, HandleScenePostUpdate));
+    else if (!scene)
+         UnsubscribeFromEvent(E_SCENEPOSTUPDATE);
 }
 
 bool ParticleEmitter::EmitNewParticle()

+ 6 - 3
Source/Atomic/Atomic3D/ParticleEmitter.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -87,10 +87,13 @@ public:
 
     /// Return particle effect.
     ParticleEffect* GetEffect() const { return effect_; }
+
     /// Return maximum number of particles.
     unsigned GetNumParticles() const { return particles_.Size(); }
+
     /// Return whether is currently emitting.
     bool IsEmitting() const { return emitting_; }
+
     /// Return whether particles are to be serialized.
     bool GetSerializeParticles() const { return serializeParticles_; }
 
@@ -106,8 +109,8 @@ public:
     VariantVector GetParticleBillboardsAttr() const;
 
 protected:
-    /// Handle node being assigned.
-    virtual void OnNodeSet(Node* node);
+    /// Handle scene being assigned.
+    virtual void OnSceneSet(Scene* scene);
 
     /// Create a new particle. Return true if there was room.
     bool EmitNewParticle();

+ 16 - 17
Source/Atomic/Atomic3D/Skeleton.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,11 +20,10 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
-#include "../IO/Deserializer.h"
-#include "../IO/Log.h"
-#include "../IO/Serializer.h"
+#include "../Precompiled.h"
+
 #include "../Atomic3D/Skeleton.h"
+#include "../IO/Log.h"
 
 #include "../DebugNew.h"
 
@@ -43,13 +42,13 @@ Skeleton::~Skeleton()
 bool Skeleton::Load(Deserializer& source)
 {
     ClearBones();
-    
+
     if (source.IsEof())
         return false;
-    
+
     unsigned bones = source.ReadUInt();
     bones_.Reserve(bones);
-    
+
     for (unsigned i = 0; i < bones; ++i)
     {
         Bone newBone;
@@ -60,20 +59,20 @@ bool Skeleton::Load(Deserializer& source)
         newBone.initialRotation_ = source.ReadQuaternion();
         newBone.initialScale_ = source.ReadVector3();
         source.Read(&newBone.offsetMatrix_.m00_, sizeof(Matrix3x4));
-        
+
         // Read bone collision data
         newBone.collisionMask_ = source.ReadUByte();
         if (newBone.collisionMask_ & BONECOLLISION_SPHERE)
             newBone.radius_ = source.ReadFloat();
         if (newBone.collisionMask_ & BONECOLLISION_BOX)
             newBone.boundingBox_ = source.ReadBoundingBox();
-        
+
         if (newBone.parentIndex_ == i)
             rootBoneIndex_ = i;
-        
+
         bones_.Push(newBone);
     }
-    
+
     return true;
 }
 
@@ -81,7 +80,7 @@ bool Skeleton::Save(Serializer& dest) const
 {
     if (!dest.WriteUInt(bones_.Size()))
         return false;
-    
+
     for (unsigned i = 0; i < bones_.Size(); ++i)
     {
         const Bone& bone = bones_[i];
@@ -91,7 +90,7 @@ bool Skeleton::Save(Serializer& dest) const
         dest.WriteQuaternion(bone.initialRotation_);
         dest.WriteVector3(bone.initialScale_);
         dest.Write(bone.offsetMatrix_.Data(), sizeof(Matrix3x4));
-        
+
         // Collision info
         dest.WriteUByte(bone.collisionMask_);
         if (bone.collisionMask_ & BONECOLLISION_SPHERE)
@@ -99,14 +98,14 @@ bool Skeleton::Save(Serializer& dest) const
         if (bone.collisionMask_ & BONECOLLISION_BOX)
             dest.WriteBoundingBox(bone.boundingBox_);
     }
-    
+
     return true;
 }
 
 void Skeleton::Define(const Skeleton& src)
 {
     ClearBones();
-    
+
     bones_ = src.bones_;
     // Make sure we clear node references, if they exist
     // (AnimatedModel will create new nodes on its own)
@@ -175,7 +174,7 @@ Bone* Skeleton::GetBone(StringHash nameHash)
         if (i->nameHash_ == nameHash)
             return &(*i);
     }
-    
+
     return 0;
 }
 

+ 8 - 5
Source/Atomic/Atomic3D/Skeleton.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -50,7 +50,7 @@ struct Bone
         radius_(0.0f)
     {
     }
-    
+
     /// Bone name.
     String name_;
     /// Bone name hash.
@@ -85,7 +85,7 @@ public:
     Skeleton();
     /// Destruct.
     ~Skeleton();
-    
+
     /// Read from a stream. Return true if successful.
     bool Load(Deserializer& source);
     /// Write to a stream. Return true if successful.
@@ -98,13 +98,16 @@ public:
     void ClearBones();
     /// Reset all animating bones to initial positions.
     void Reset();
-    
+
     /// Return all bones.
     const Vector<Bone>& GetBones() const { return bones_; }
+
     /// Return modifiable bones.
     Vector<Bone>& GetModifiableBones() { return bones_; }
+
     /// Return number of bones.
     unsigned GetNumBones() const { return bones_.Size(); }
+
     /// Return root bone.
     Bone* GetRootBone();
     /// Return bone by index.
@@ -115,7 +118,7 @@ public:
     Bone* GetBone(const char* boneName);
     /// Return bone by name hash.
     Bone* GetBone(StringHash boneNameHash);
-    
+
     /// Reset all animating bones to initial positions without marking the nodes dirty. Requires the node dirtying to be performed later.
     void ResetSilent();
 

+ 5 - 4
Source/Atomic/Atomic3D/Skybox.cpp

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -20,12 +20,13 @@
 // THE SOFTWARE.
 //
 
-#include "Precompiled.h"
+#include "../Precompiled.h"
+
+#include "../Core/Context.h"
 #include "../Graphics/Batch.h"
 #include "../Graphics/Camera.h"
-#include "../Core/Context.h"
-#include "../Scene/Node.h"
 #include "../Atomic3D/Skybox.h"
+#include "../Scene/Node.h"
 
 #include "../DebugNew.h"
 

+ 5 - 5
Source/Atomic/Atomic3D/Skybox.h

@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2008-2014 the Urho3D project.
+// Copyright (c) 2008-2015 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
@@ -31,7 +31,7 @@ namespace Atomic
 class ATOMIC_API Skybox : public StaticModel
 {
     OBJECT(Skybox);
-    
+
 public:
     /// Construct.
     Skybox(Context* context);
@@ -39,16 +39,16 @@ public:
     virtual ~Skybox();
     /// Register object factory. StaticModel must be registered first.
     static void RegisterObject(Context* context);
-    
+
     /// Process octree raycast. May be called from a worker thread.
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
-    
+
 protected:
     /// Recalculate the world-space bounding box.
     virtual void OnWorldBoundingBoxUpdate();
-    
+
     /// Custom world transform per camera.
     HashMap<Camera*, Matrix3x4> customWorldTransforms_;
     /// Last frame counter for knowing when to erase the custom world transforms of previous frame.

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä