Browse Source

Add fixed pixel size (user don't need change the value).

aster2013 11 years ago
parent
commit
130551f4d8

+ 2 - 2
Bin/Data/LuaScripts/24_Urho2DSprite.lua

@@ -44,8 +44,8 @@ function CreateScene()
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
 
-    local width = graphics.width / scene_.pixelsPerUnit
-    local height = graphics.height / scene_.pixelsPerUnit
+    local width = graphics.width * PIXEL_SIZE
+    local height = graphics.height * PIXEL_SIZE
     camera:SetOrthoSize(Vector2(width, height))
 
     local sprite = cache:GetResource("Sprite2D", "Urho2D/Aster.png")

+ 1 - 1
Bin/Data/LuaScripts/25_Urho2DParticle.lua

@@ -45,7 +45,7 @@ function CreateScene()
     cameraNode.position = Vector3(0.0, 0.0, -10.0)
     local camera = cameraNode:CreateComponent("Camera")
     camera.orthographic = true
-    camera:SetOrthoSize(Vector2(graphics.width, graphics.height) / scene_.pixelsPerUnit)
+    camera:SetOrthoSize(Vector2(graphics.width, graphics.height) * PIXEL_SIZE)
 
     local particleModel = cache:GetResource("ParticleModel2D", "Urho2D/LavaFlow.plist")
     if particleModel == nil then

+ 4 - 4
Bin/Data/Scripts/24_Urho2DSprite.as

@@ -47,8 +47,8 @@ void CreateScene()
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
 
-    uint width = graphics.width / scene_.pixelsPerUnit;
-    uint height = graphics.height / scene_.pixelsPerUnit;
+    uint width = graphics.width * PIXEL_SIZE;
+    uint height = graphics.height * PIXEL_SIZE;
     camera.SetOrthoSize(Vector2(width, height));
 
     Sprite2D@ sprite = cache.GetResource("Sprite2D", "Urho2D/Aster.png");
@@ -166,8 +166,8 @@ void HandleUpdate(StringHash eventType, VariantMap& eventData)
     // Move the camera, scale movement with time step
     MoveCamera(timeStep);
 
-    float halfWidth = graphics.width * 0.5f / scene_.pixelsPerUnit;
-    float halfHeight = graphics.height * 0.5f / scene_.pixelsPerUnit;
+    float halfWidth = graphics.width * 0.5f * PIXEL_SIZE;
+    float halfHeight = graphics.height * 0.5f * PIXEL_SIZE;
 
     // Go through all sprites
     for (uint i = 0; i < spriteNodes.length; ++i)

+ 1 - 1
Bin/Data/Scripts/25_Urho2DParticle.as

@@ -49,7 +49,7 @@ void CreateScene()
 
     Camera@ camera = cameraNode.CreateComponent("Camera");
     camera.orthographic = true;
-    camera.SetOrthoSize(Vector2(graphics.width, graphics.height) / scene_.pixelsPerUnit);
+    camera.SetOrthoSize(Vector2(graphics.width, graphics.height) * PIXEL_SIZE);
 
     ParticleModel2D@ particleModel = cache.GetResource("ParticleModel2D", "Urho2D/LavaFlow.plist");
     if (particleModel is null)

+ 0 - 1
Source/Engine/LuaScript/pkgs/Core/Spline.pkg

@@ -13,7 +13,6 @@ class Spline
     
     void operator = (const Spline& rhs);
     bool operator == (const Spline& rhs) const;
-    bool operator != (const Spline& rhs) const;
     
     Variant GetPoint(float f) const;
     

+ 0 - 3
Source/Engine/LuaScript/pkgs/Scene/Scene.pkg

@@ -32,7 +32,6 @@ class Scene : public Node
     void SetUpdateEnabled(bool enable);
     void SetTimeScale(float scale);
     void SetElapsedTime(float time);
-    void SetPixelsPerUnit(float pixelsPerUnit);
     void SetSmoothingConstant(float constant);
     void SetSnapThreshold(float threshold);
     
@@ -46,7 +45,6 @@ class Scene : public Node
     unsigned GetChecksum() const;
     float GetTimeScale() const;
     float GetElapsedTime() const;
-    float GetPixelsPerUnit() const;
     float GetSmoothingConstant() const;
     float GetSnapThreshold() const;
     const String GetVarName(ShortStringHash hash) const;
@@ -77,7 +75,6 @@ class Scene : public Node
     tolua_readonly tolua_property__get_set unsigned checksum;
     tolua_property__get_set float timeScale;
     tolua_property__get_set float elapsedTime;
-    tolua_property__get_set float pixelsPerUnit;
     tolua_property__get_set float smoothingConstant;
     tolua_property__get_set float snapThreshold;
     tolua_readonly tolua_property__is_set bool threadedUpdate;

+ 3 - 1
Source/Engine/LuaScript/pkgs/Urho2D/Drawable2D.pkg

@@ -2,6 +2,8 @@ $#include "Drawable2D.h"
 
 enum BlendMode {};
 
+const float PIXEL_SIZE;
+
 class Drawable2D : public Drawable
 {
 public:
@@ -19,4 +21,4 @@ public:
     tolua_property__get_set Material* material;
     tolua_property__get_set BlendMode blendMode;
     tolua_property__get_set float zValue;
-};
+};

+ 0 - 12
Source/Engine/Scene/Node.cpp

@@ -23,7 +23,6 @@
 #include "Precompiled.h"
 #include "Component.h"
 #include "Context.h"
-#include "Drawable2D.h"
 #include "Log.h"
 #include "MemoryBuffer.h"
 #include "Profiler.h"
@@ -1275,17 +1274,6 @@ void Node::MarkReplicationDirty()
     }
 }
 
-void Node::MarkAllDrawable2DDirty(bool markWorldBoundingBoxDirty)
-{
-    PODVector<Drawable2D*> drawables;
-    GetDerivedComponents<Drawable2D>(drawables);
-    for (PODVector<Drawable2D*>::Iterator i = drawables.Begin(); i != drawables.End(); ++i)
-        (*i)->MarkDirty(markWorldBoundingBoxDirty);
-
-    for (Vector<SharedPtr<Node> >::Iterator i = children_.Begin(); i != children_.End(); ++i)
-        (*i)->MarkAllDrawable2DDirty(markWorldBoundingBoxDirty);
-}
-
 Node* Node::CreateChild(unsigned id, CreateMode mode)
 {
     SharedPtr<Node> newNode(new Node(context_));

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

@@ -361,8 +361,6 @@ public:
     void MarkNetworkUpdate();
     /// Mark node dirty in scene replication states.
     void MarkReplicationDirty();
-    /// Mark all Drawable2D components attached to this node and its child nodes dirty.
-    void MarkAllDrawable2DDirty(bool markWorldBoundingBoxDirty = true);
     /// Create a child node with specific ID.
     Node* CreateChild(unsigned id, CreateMode mode);
     /// Add a pre-created component.

+ 0 - 14
Source/Engine/Scene/Scene.cpp

@@ -48,7 +48,6 @@ const char* SUBSYSTEM_CATEGORY = "Subsystem";
 
 static const int ASYNC_LOAD_MIN_FPS = 30;
 static const int ASYNC_LOAD_MAX_MSEC = (int)(1000.0f / ASYNC_LOAD_MIN_FPS);
-static const float DEFAULT_PIXELS_PER_UNIT_2D = 100.0f;
 static const float DEFAULT_SMOOTHING_CONSTANT = 50.0f;
 static const float DEFAULT_SNAP_THRESHOLD = 5.0f;
 
@@ -61,7 +60,6 @@ Scene::Scene(Context* context) :
     checksum_(0),
     timeScale_(1.0f),
     elapsedTime_(0),
-    pixelsPerUnit_(DEFAULT_PIXELS_PER_UNIT_2D),
     smoothingConstant_(DEFAULT_SMOOTHING_CONSTANT),
     snapThreshold_(DEFAULT_SNAP_THRESHOLD),
     updateEnabled_(true),
@@ -98,7 +96,6 @@ void Scene::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE(Scene, VAR_FLOAT, "Smoothing Constant", GetSmoothingConstant, SetSmoothingConstant, float, DEFAULT_SMOOTHING_CONSTANT, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Scene, VAR_FLOAT, "Snap Threshold", GetSnapThreshold, SetSnapThreshold, float, DEFAULT_SNAP_THRESHOLD, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE(Scene, VAR_FLOAT, "Elapsed Time", GetElapsedTime, SetElapsedTime, float, 0.0f, AM_FILE);
-    ACCESSOR_ATTRIBUTE(Scene, VAR_FLOAT, "Pixels per Unit (2D)", GetPixelsPerUnit, SetPixelsPerUnit, float, DEFAULT_PIXELS_PER_UNIT_2D, AM_DEFAULT);
     ATTRIBUTE(Scene, VAR_INT, "Next Replicated Node ID", replicatedNodeID_, FIRST_REPLICATED_ID, AM_FILE | AM_NOEDIT);
     ATTRIBUTE(Scene, VAR_INT, "Next Replicated Component ID", replicatedComponentID_, FIRST_REPLICATED_ID, AM_FILE | AM_NOEDIT);
     ATTRIBUTE(Scene, VAR_INT, "Next Local Node ID", localNodeID_, FIRST_LOCAL_ID, AM_FILE | AM_NOEDIT);
@@ -435,17 +432,6 @@ void Scene::SetElapsedTime(float time)
     elapsedTime_ = time;
 }
 
-void Scene::SetPixelsPerUnit(float pixelsPerUnit)
-{
-    if (pixelsPerUnit == pixelsPerUnit_)
-        return;
-
-    pixelsPerUnit_ = Max(pixelsPerUnit, 1.0f);
-
-    MarkAllDrawable2DDirty();
-    Node::MarkNetworkUpdate();
-}
-
 void Scene::AddRequiredPackageFile(PackageFile* package)
 {
     // Do not add packages that failed to load

+ 0 - 6
Source/Engine/Scene/Scene.h

@@ -103,8 +103,6 @@ public:
     void SetTimeScale(float scale);
     /// Set elapsed time in seconds. This can be used to prevent inaccuracy in the timer if the scene runs for a long time.
     void SetElapsedTime(float time);
-    /// Set 2D pixels per unit. This represents the number of pixels would be used by Drawable2D class per coordinate unit.
-    void SetPixelsPerUnit(float pixelsPerUnit);
     /// Set network client motion smoothing constant.
     void SetSmoothingConstant(float constant);
     /// Set network client motion smoothing snap threshold.
@@ -138,8 +136,6 @@ public:
     float GetTimeScale() const { return timeScale_; }
     /// Return elapsed time in seconds.
     float GetElapsedTime() const { return elapsedTime_; }
-    /// Return 2D pixels per unit. This represents the number of pixels would be used by Drawable2D class per coordinate unit.
-    float GetPixelsPerUnit() const { return pixelsPerUnit_; }
     /// Return motion smoothing constant.
     float GetSmoothingConstant() const { return smoothingConstant_; }
     /// Return motion smoothing snap threshold.
@@ -240,8 +236,6 @@ private:
     float timeScale_;
     /// Elapsed time accumulator.
     float elapsedTime_;
-    /// 2D pixels per unit.
-    float pixelsPerUnit_;
     /// Motion smoothing constant.
     float smoothingConstant_;
     /// Motion smoothing snap threshold.

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

@@ -233,8 +233,6 @@ static void RegisterScene(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Scene", "float get_timeScale() const", asMETHOD(Scene, GetTimeScale), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void set_elapsedTime(float)", asMETHOD(Scene, SetElapsedTime), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "float get_elapsedTime() const", asMETHOD(Scene, GetElapsedTime), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Scene", "void set_pixelsPerUnit(float)", asMETHOD(Scene, SetPixelsPerUnit), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Scene", "float get_pixelsPerUnit() const", asMETHOD(Scene, GetPixelsPerUnit), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void set_smoothingConstant(float)", asMETHOD(Scene, SetSmoothingConstant), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "float get_smoothingConstant() const", asMETHOD(Scene, GetSmoothingConstant), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "void set_snapThreshold(float)", asMETHOD(Scene, SetSnapThreshold), asCALL_THISCALL);

+ 2 - 0
Source/Engine/Script/Urho2DAPI.cpp

@@ -75,6 +75,8 @@ template <class T> void RegisterDrawable2D(asIScriptEngine* engine, const char*
 
 static void RegisterDrawable2D(asIScriptEngine* engine)
 {
+    engine->RegisterGlobalProperty("const float PIXEL_SIZE", (void*)&PIXEL_SIZE);
+    
     RegisterDrawable2D<Drawable2D>(engine, "Drawable2D");
 }
 

+ 1 - 0
Source/Engine/Urho2D/Drawable2D.cpp

@@ -40,6 +40,7 @@
 namespace Urho3D
 {
 
+const float PIXEL_SIZE = 0.01f;
 extern const char* blendModeNames[];
 
 Drawable2D::Drawable2D(Context* context) :

+ 3 - 0
Source/Engine/Urho2D/Drawable2D.h

@@ -30,6 +30,9 @@ namespace Urho3D
 
 class VertexBuffer;
 
+/// Pixel size (equal 0.01f).
+extern URHO3D_API const float PIXEL_SIZE;
+
 /// Base class for 2D visible components.
 class URHO3D_API Drawable2D : public Drawable
 {

+ 1 - 1
Source/Engine/Urho2D/ParticleEmitter2D.cpp

@@ -87,7 +87,7 @@ void ParticleEmitter2D::Update(const FrameInfo& frame)
 
     float timeStep = frame.timeStep_;
     Vector3 worldPosition = GetNode()->GetWorldPosition();
-    float worldScale = GetNode()->GetWorldScale().x_ / GetScene()->GetPixelsPerUnit();
+    float worldScale = GetNode()->GetWorldScale().x_ * PIXEL_SIZE;
 
     unsigned particleIndex = 0;
     while (particleIndex < numParticles_)

+ 2 - 3
Source/Engine/Urho2D/StaticSprite2D.cpp

@@ -124,9 +124,8 @@ void StaticSprite2D::UpdateVertices()
     Vertex2D vertex2;
     Vertex2D vertex3;
 
-    float pixelsPerUnit = scene->GetPixelsPerUnit();
-    float width = (float)rectangle_.Width() / pixelsPerUnit;     // Compute width and height in pixels
-    float height = (float)rectangle_.Height() / pixelsPerUnit;
+    float width = (float)rectangle_.Width() * PIXEL_SIZE;     // Compute width and height in pixels
+    float height = (float)rectangle_.Height() * PIXEL_SIZE;
 
     const Vector2& hotSpot = sprite_->GetHotSpot();
     float hotSpotX = flipX_ ? (1.0f - hotSpot.x_) : hotSpot.x_;

+ 4 - 4
Source/Samples/24_Urho2DSprite/Urho2DSprite.cpp

@@ -84,8 +84,8 @@ void Urho2DSprite::CreateScene()
     camera->SetOrthographic(true);
 
     Graphics* graphics = GetSubsystem<Graphics>();
-    float width = (float)graphics->GetWidth() / scene_->GetPixelsPerUnit();
-    float height = (float)graphics->GetHeight() / scene_->GetPixelsPerUnit();
+    float width = (float)graphics->GetWidth() * PIXEL_SIZE;
+    float height = (float)graphics->GetHeight() * PIXEL_SIZE;
     camera->SetOrthoSize(Vector2(width, height));
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
@@ -212,8 +212,8 @@ void Urho2DSprite::HandleUpdate(StringHash eventType, VariantMap& eventData)
     MoveCamera(timeStep);
 
     Graphics* graphics = GetSubsystem<Graphics>();
-    float halfWidth = (float)graphics->GetWidth() * 0.5f / scene_->GetPixelsPerUnit();
-    float halfHeight = (float)graphics->GetHeight() * 0.5f / scene_->GetPixelsPerUnit();
+    float halfWidth = (float)graphics->GetWidth() * 0.5f * PIXEL_SIZE;
+    float halfHeight = (float)graphics->GetHeight() * 0.5f * PIXEL_SIZE;
 
     for (unsigned i = 0; i < spriteNodes_.Size(); ++i)
     {

+ 1 - 1
Source/Samples/25_Urho2DParticle/Urho2DParticle.cpp

@@ -82,7 +82,7 @@ void Urho2DParticle::CreateScene()
     camera->SetOrthographic(true);
 
     Graphics* graphics = GetSubsystem<Graphics>();
-    camera->SetOrthoSize(Vector2((float)graphics->GetWidth(), (float)graphics->GetHeight()) / scene_->GetPixelsPerUnit());
+    camera->SetOrthoSize(Vector2((float)graphics->GetWidth(), (float)graphics->GetHeight()) * PIXEL_SIZE);
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     ParticleModel2D* particleModel = cache->GetResource<ParticleModel2D>("Urho2D/LavaFlow.plist");