Browse Source

Move tile object define to TileMapDefs2D. Add half pixel offset in Direct3D mode.

aster2013 11 years ago
parent
commit
b81d08ba21

+ 8 - 0
Source/Engine/Urho2D/StaticSprite2D.cpp

@@ -186,10 +186,18 @@ void StaticSprite2D::UpdateVertices()
         hotSpotY = flipY_ ? (1.0f - hotSpot.y_) : hotSpot.y_;
     }
 
+#ifdef URHO3D_OPENGL
     float leftX = -width * hotSpotX;
     float rightX = width * (1.0f - hotSpotX);
     float bottomY = -height * hotSpotY;
     float topY = height * (1.0f - hotSpotY);
+#else
+    const float halfPixelOffset = 0.5f * PIXEL_SIZE;
+    float leftX = -width * hotSpotX + halfPixelOffset;
+    float rightX = width * (1.0f - hotSpotX) + halfPixelOffset;
+    float bottomY = -height * hotSpotY + halfPixelOffset;
+    float topY = height * (1.0f - hotSpotY) + halfPixelOffset;
+#endif
 
     const Matrix3x4& worldTransform = node_->GetWorldTransform();
 

+ 1 - 10
Source/Engine/Urho2D/TileMap2D.cpp

@@ -81,7 +81,7 @@ void TileMap2D::SetTmxFile(TmxFile2D* tmxFile)
 
         SharedPtr<TileMapLayer2D> layer(layerNode->CreateComponent<TileMapLayer2D>());
         layer->SetTmxLayer(tmxLayer);
-        layer->SetDrawOrder(i);
+        layer->SetDrawOrder(i * 10);
 
         layers_[i] = layer;
     }
@@ -121,15 +121,6 @@ TileMapLayer2D* TileMap2D::GetLayer(unsigned index) const
     return layers_[index];
 }
 
-TileMapLayer2D* TileMap2D::GetLayerByName(const String& name) const
-{
-    for (unsigned i = 0; i < layers_.Size(); ++i)
-        if (name == layers_[i]->GetName())
-            return layers_[i];
-
-    return 0;
-}
-
 void TileMap2D::SetTmxFileAttr(ResourceRef value)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();

+ 1 - 3
Source/Engine/Urho2D/TileMap2D.h

@@ -60,9 +60,7 @@ public:
     unsigned GetNumLayers() const { return layers_.Size(); }
     /// Return tile map layer at index.
     TileMapLayer2D* GetLayer(unsigned index) const;
-    /// Return tile map layer by name.
-    TileMapLayer2D* GetLayerByName(const String& name) const;
-    
+
     /// Set tile map file attribute.
     void SetTmxFileAttr(ResourceRef value);
     /// Return tile map file attribute.

+ 122 - 0
Source/Engine/Urho2D/TileMapDefs2D.cpp

@@ -0,0 +1,122 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "Precompiled.h"
+#include "TileMapDefs2D.h"
+#include "XMLElement.h"
+
+#include "DebugNew.h"
+
+namespace Urho3D
+{
+
+PropertySet2D::PropertySet2D()
+{
+}
+
+PropertySet2D::~PropertySet2D()
+{
+}
+
+void PropertySet2D::Load(const XMLElement& element)
+{
+    assert(element.GetName() == "properties");
+    for (XMLElement propertyElem = element.GetChild("property"); propertyElem; propertyElem = propertyElem.GetNext("property"))
+        nameToValueMapping_[propertyElem.GetAttribute("name")] = propertyElem.GetAttribute("value");
+}
+
+bool PropertySet2D::HasProperty(const String& name) const
+{
+    return nameToValueMapping_.Find(name) != nameToValueMapping_.End();
+}
+
+const String& PropertySet2D::GetProperty(const String& name) const
+{
+    HashMap<String, String>::ConstIterator i = nameToValueMapping_.Find(name);
+    if (i == nameToValueMapping_.End())
+        return String::EMPTY;
+
+    return i->second_;
+}
+
+Tile2D::Tile2D() : 
+    gid_(0) 
+{
+}
+
+Sprite2D* Tile2D::GetSprite() const
+{
+    return sprite_;
+}
+
+bool Tile2D::HasProperty(const String& name) const
+{
+    if (!propertySet_)
+        return false;
+    return propertySet_->HasProperty(name);
+}
+
+const String& Tile2D::GetProperty(const String& name) const
+{
+    if (!propertySet_)
+        return String::EMPTY;
+
+    return propertySet_->GetProperty(name);
+}
+
+TileObject2D::TileObject2D()
+{
+}
+
+unsigned TileObject2D::GetNumPoints() const
+{
+    return points_.Size();
+}
+
+const Vector2& TileObject2D::GetPoint(unsigned index) const
+{
+    if (index >= points_.Size())
+        return Vector2::ZERO;
+
+    return points_[index];
+}
+
+Sprite2D* TileObject2D::GetTileSprite() const
+{
+    return sprite_;
+}
+
+bool TileObject2D::HasProperty(const String& name) const
+{
+    if (!propertySet_)
+        return false;
+    return propertySet_->HasProperty(name);
+}
+
+const String& TileObject2D::GetProperty(const String& name) const
+{
+    if (!propertySet_)
+        return String::EMPTY;
+    return propertySet_->GetProperty(name);
+}
+
+}

+ 154 - 0
Source/Engine/Urho2D/TileMapDefs2D.h

@@ -0,0 +1,154 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "RefCounted.h"
+#include "Sprite2D.h"
+
+namespace Urho3D
+{
+
+class XMLElement;
+
+/// Tile map layer type.
+enum TileMapLayerType2D
+{
+    /// Tile layer.
+    LT_TILE_LAYER = 0,
+    /// Object group.
+    LT_OBJECT_GROUP,
+    /// Image layer.
+    LT_IMAGE_LAYER,
+    /// Invalid.
+    LT_INVALID = 0xffff
+};
+
+/// Tile object type.
+enum TileObjectType2D
+{
+    /// Rectangle.
+    OT_RECTANGLE = 0,
+    /// Ellipse.
+    OT_ELLIPSE,
+    /// Polygon.
+    OT_POLYGON,
+    /// Polyline.
+    OT_POLYLINE,
+    /// Tile.
+    OT_TILE,
+    /// Invalid.
+    OT_INVALID = 0xffff
+};
+
+/// Property set.
+class URHO3D_API PropertySet2D : public RefCounted
+{
+public:
+    PropertySet2D();
+    virtual ~PropertySet2D();
+
+    /// Load from XML element.
+    void Load(const XMLElement& element);
+    /// Return has property.
+    bool HasProperty(const String& name) const;
+    /// Return property value.
+    const String& GetProperty(const String& name) const;
+
+protected:
+    /// Property name to property value mapping.
+    HashMap<String, String> nameToValueMapping_;
+};
+
+/// Tile define.
+class URHO3D_API Tile2D : public RefCounted
+{
+public:
+    /// Construct.
+    Tile2D();
+
+    /// Return gid.
+    int GetGid() const { return gid_; }
+    /// Return sprite.
+    Sprite2D* GetSprite() const;
+    /// Return has property.
+    bool HasProperty(const String& name) const;
+    /// Return property.
+    const String& GetProperty(const String& name) const;
+
+private:
+    friend class TmxTileLayer2D;
+
+    /// Gid.
+    int gid_;
+    /// Sprite.
+    SharedPtr<Sprite2D> sprite_;
+    /// Property set.
+    SharedPtr<PropertySet2D> propertySet_;
+};
+
+/// Tile map object.
+class URHO3D_API TileObject2D : public RefCounted
+{
+public:
+    TileObject2D();
+
+    /// Return type.
+    TileObjectType2D 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.
+    bool HasProperty(const String& name) const;
+    /// Return property value.
+    const String& GetProperty(const String& name) const;
+
+private:
+    friend class TmxObjectGroup2D;
+
+    /// Object type.
+    TileObjectType2D type_;
+    /// Position.
+    Vector2 position_;
+    /// Size (for rectangle and ellipse).
+    Vector2 size_;
+    /// Points(for polygon and polyline).
+    Vector<Vector2> points_;
+    /// Gid (for tile).
+    int gid_;
+    /// Sprite (for tile).
+    SharedPtr<Sprite2D> sprite_;
+    /// Property set.
+    SharedPtr<PropertySet2D> propertySet_;
+};
+
+
+}

+ 26 - 26
Source/Engine/Urho2D/TileMapLayer2D.cpp

@@ -22,12 +22,12 @@
 
 #include "Precompiled.h"
 #include "Context.h"
+#include "Node.h"
 #include "ResourceCache.h"
+#include "StaticSprite2D.h"
 #include "TileMapLayer2D.h"
-#include "TmxFile2D.h"
 #include "TileMapLayer2D.h"
-#include "Node.h"
-#include "StaticSprite2D.h"
+#include "TmxFile2D.h"
 
 #include "DebugNew.h"
 
@@ -129,11 +129,6 @@ void TileMapLayer2D::SetVisible(bool visible)
     }
 }
 
-const String& TileMapLayer2D::GetName() const
-{
-    return tmxLayer_ ? tmxLayer_->GetName() : String::EMPTY;
-}
-
 int TileMapLayer2D::GetWidth() const
 {
     return tmxLayer_ ? tmxLayer_->GetWidth(): 0;
@@ -159,7 +154,7 @@ const String& TileMapLayer2D::GetProperty(const String& name) const
     return tmxLayer_->GetProperty(name);
 }
 
-TmxLayerType2D TileMapLayer2D::GetLayerType() const
+TileMapLayerType2D TileMapLayer2D::GetLayerType() const
 {
     return tmxLayer_ ? tmxLayer_->GetType() : LT_INVALID;
 }
@@ -175,7 +170,7 @@ Node* TileMapLayer2D::GetTileNode(int x, int y) const
     return nodes_[y * tileLayer_->GetWidth() + x];
 }
 
-const Tile2D* TileMapLayer2D::GetTile(int x, int y) const
+Tile2D* TileMapLayer2D::GetTile(int x, int y) const
 {
     if (!tileLayer_)
         return 0;
@@ -183,10 +178,18 @@ const Tile2D* TileMapLayer2D::GetTile(int x, int y) const
     return tileLayer_->GetTile(x, y);
 }
 
+unsigned TileMapLayer2D::GetNumObjectNodes() const
+{
+    if (!objectGroup_)
+        return 0;
+
+    return nodes_.Size();
+}
+
 Node* TileMapLayer2D::GetObjectNode(unsigned index) const
 {
     if (!objectGroup_)
-        return false;
+        return 0;
 
     if (index >= nodes_.Size())
         return 0;
@@ -202,7 +205,7 @@ unsigned TileMapLayer2D::GetNumObjects() const
     return objectGroup_->GetNumObjects();
 }
 
-const TileObject2D* TileMapLayer2D::GetObject(unsigned index) const
+TileObject2D* TileMapLayer2D::GetObject(unsigned index) const
 {
     if (objectGroup_)
         return 0;
@@ -243,7 +246,7 @@ void TileMapLayer2D::SetTileLayer(const TmxTileLayer2D* tileLayer)
 
             SharedPtr<Node> tileNode(GetNode()->CreateChild("Tile"));
             tileNode->SetTemporary(true);
-            tileNode->SetPosition(Vector3(x * tileWidth, y * tileHeight, 0.0f));
+            tileNode->SetPosition(Vector3((x + 0.5f) * tileWidth, (y + 0.5f) * tileHeight, 0.0f));
 
             StaticSprite2D* staticSprite = tileNode->CreateComponent<StaticSprite2D>();
             staticSprite->SetSprite(tile->GetSprite());
@@ -260,30 +263,27 @@ void TileMapLayer2D::SetObjectGroup(const TmxObjectGroup2D* objectGroup)
     objectGroup_ = objectGroup;
 
     TmxFile2D* tmxFile = objectGroup->GetTmxFile();
+    nodes_.Resize(objectGroup->GetNumObjects());
 
     for (unsigned i = 0; i < objectGroup->GetNumObjects(); ++i)
     {
         const TileObject2D* object = objectGroup->GetObject(i);
 
+        // Create dummy node for all object
         SharedPtr<Node> objectNode(GetNode()->CreateChild("Object"));
         objectNode->SetTemporary(true);
         objectNode->SetPosition(object->GetPosition());
 
-        // Set object data
-        objectNode->SetVar("ObjectData", (void*)&object);
-
-        if (object->GetType() == OT_TILE)
+        // If object is tile, create static sprite component
+        if (object->GetType() == OT_TILE && object->GetTileGid() && object->GetTileSprite())
         {
-            if (object->GetTileGid() && object->GetTileSprite())
-            {
-                StaticSprite2D* staticSprite = objectNode->CreateComponent<StaticSprite2D>();
-                staticSprite->SetSprite(object->GetTileSprite());
-                staticSprite->SetLayer(drawOrder_);
-                staticSprite->SetOrderInLayer((int)((10.0f - object->GetPosition().y_) * 100.0f));
-            }
+            StaticSprite2D* staticSprite = objectNode->CreateComponent<StaticSprite2D>();
+            staticSprite->SetSprite(object->GetTileSprite());
+            staticSprite->SetLayer(drawOrder_);
+            staticSprite->SetOrderInLayer((int)((10.0f - object->GetPosition().y_) * 100));
         }
-        
-        nodes_.Push(objectNode);
+
+        nodes_[i] = objectNode;
     }
 }
 

+ 15 - 12
Source/Engine/Urho2D/TileMapLayer2D.h

@@ -23,12 +23,16 @@
 #pragma once
 
 #include "Component.h"
-#include "TmxFile2D.h"
+#include "TileMapDefs2D.h"
 
 namespace Urho3D
 {
 
 class Node;
+class Sprite2D;
+class TmxImageLayer2D;
+class TmxLayer2D;
+class TmxTileLayer2D;
 
 /// Tile map component.
 class URHO3D_API TileMapLayer2D : public Component
@@ -56,8 +60,6 @@ public:
     int GetDrawOrder() const { return drawOrder_; }
     /// Return visible.
     bool IsVisible() const { return visible_; }
-    /// Return name.
-    const String& GetName() const;
     /// Return width.
     int GetWidth() const;
     /// Return height.
@@ -66,22 +68,23 @@ public:
     bool HasProperty(const String& name) const;
     /// Return property.
     const String& GetProperty(const String& name) const;
-
     /// Return layer type.
-    TmxLayerType2D GetLayerType() const;
+    TileMapLayerType2D GetLayerType() const;
 
     /// Return tile node (for tile layer only).
     Node* GetTileNode(int x, int y) const;
     /// Return tile (for tile layer only).
-    const Tile2D* GetTile(int x, int y) const;
-    
-    /// Return tile node (for object group only).
+    Tile2D* GetTile(int x, int y) const;
+
+    /// Return number of object nodes (for object group only).
+    unsigned GetNumObjectNodes() const;
+    /// Return object node (for object group only).
     Node* GetObjectNode(unsigned index) const;
-    /// Return number of tile nodes (for object group only).
+    /// Return number of objects (for object group only).
     unsigned GetNumObjects() const;
     /// Return object (for object group only).
-    const TileObject2D* GetObject(unsigned index) const;
-
+    TileObject2D* GetObject(unsigned index) const;
+    
     /// Return image node (for image layer only).
     Node* GetImageNode() const;
 
@@ -105,7 +108,7 @@ private:
     int drawOrder_;
     /// Visible.
     bool visible_;
-    /// Tile or image nodes.
+    /// Tile node or image nodes.
     Vector<SharedPtr<Node> > nodes_;
 };
 

+ 24 - 118
Source/Engine/Urho2D/TmxFile2D.cpp

@@ -21,7 +21,6 @@
 //
 
 #include "Precompiled.h"
-#include "Animation2D.h"
 #include "Context.h"
 #include "FileSystem.h"
 #include "Log.h"
@@ -38,97 +37,7 @@ namespace Urho3D
 
 extern const float PIXEL_SIZE;
 
-Properties2D::Properties2D()
-{
-}
-
-Properties2D::~Properties2D()
-{
-}
-
-void Properties2D::Load(const XMLElement& element)
-{
-    assert(element.GetName() == "properties");
-    for (XMLElement propertyElem = element.GetChild("property"); propertyElem; propertyElem = propertyElem.GetNext("property"))
-        properties_[propertyElem.GetAttribute("name")] = propertyElem.GetAttribute("value");
-}
-
-bool Properties2D::HasProperty(const String& name) const
-{
-    return properties_.Find(name) != properties_.End();
-}
-
-const String& Properties2D::GetProperty(const String& name) const
-{
-    HashMap<String, String>::ConstIterator i = properties_.Find(name);
-    if (i == properties_.End())
-        return String::EMPTY;
-
-    return i->second_;
-}
-
-Tile2D::Tile2D() : 
-    gid_(0) 
-{
-}
-
-Sprite2D* Tile2D::GetSprite() const
-{
-    return sprite_;
-}
-
-bool Tile2D::HasProperty(const String& name) const
-{
-    if (!properties_)
-        return false;
-    return properties_->HasProperty(name);
-}
-
-const String& Tile2D::GetProperty(const String& name) const
-{
-    if (!properties_)
-        return String::EMPTY;
-
-    return properties_->GetProperty(name);
-}
-
-TileObject2D::TileObject2D()
-{
-}
-
-unsigned TileObject2D::GetNumPoints() const
-{
-    return points_.Size();
-}
-
-const Vector2& TileObject2D::GetPoint(unsigned index) const
-{
-    if (index >= points_.Size())
-        return Vector2::ZERO;
-
-    return points_[index];
-}
-
-Sprite2D* TileObject2D::GetTileSprite() const
-{
-    return sprite_;
-}
-
-bool TileObject2D::HasProperty(const String& name) const
-{
-    if (!properties_)
-        return false;
-    return properties_->HasProperty(name);
-}
-
-const String& TileObject2D::GetProperty(const String& name) const
-{
-    if (!properties_)
-        return String::EMPTY;
-    return properties_->GetProperty(name);
-}
-
-TmxLayer2D::TmxLayer2D(TmxFile2D* tmxFile, TmxLayerType2D type) :
+TmxLayer2D::TmxLayer2D(TmxFile2D* tmxFile, TileMapLayerType2D type) :
     tmxFile_(tmxFile),
     type_(type)
 {
@@ -146,16 +55,16 @@ TmxFile2D* TmxLayer2D::GetTmxFile() const
 
 bool TmxLayer2D::HasProperty(const String& name) const
 {
-    if (!properties_)
+    if (!propertySet_)
         return false;
-    return properties_->HasProperty(name);
+    return propertySet_->HasProperty(name);
 }
 
 const String& TmxLayer2D::GetProperty(const String& name) const
 {
-    if (!properties_)
+    if (!propertySet_)
         return String::EMPTY;
-    return properties_->GetProperty(name);
+    return propertySet_->GetProperty(name);
 }
 
 void TmxLayer2D::LoadInfo(const XMLElement& element)
@@ -169,10 +78,10 @@ void TmxLayer2D::LoadInfo(const XMLElement& element)
         visible_ = true;
 }
 
-void TmxLayer2D::LoadProperties(const XMLElement& element)
+void TmxLayer2D::LoadPropertySet(const XMLElement& element)
 {
-    properties_ = new Properties2D();
-    properties_->Load(element);
+    propertySet_ = new PropertySet2D();
+    propertySet_->Load(element);
 }
 
 TmxTileLayer2D::TmxTileLayer2D(TmxFile2D* tmxFile) :
@@ -214,7 +123,7 @@ bool TmxTileLayer2D::Load(const XMLElement& element)
                 SharedPtr<Tile2D> tile(new Tile2D());
                 tile->gid_ = gid;
                 tile->sprite_ = tmxFile_->GetTileSprite(gid);
-                tile->properties_ = tmxFile_->GetTileProperties(gid);
+                tile->propertySet_ = tmxFile_->GetTilePropertySet(gid);
                 tiles_[y * width_ + x] = tile;
             }
 
@@ -223,7 +132,7 @@ bool TmxTileLayer2D::Load(const XMLElement& element)
     }
 
     if (element.HasChild("properties"))
-        LoadProperties(element.GetChild("properties"));
+        LoadPropertySet(element.GetChild("properties"));
     
     return true;
 }
@@ -296,20 +205,19 @@ bool TmxObjectGroup2D::Load(const XMLElement& element)
 
         if (objectElem.HasChild("properties"))
         {
-            object->properties_ = new Properties2D();
-            object->properties_->Load(objectElem.GetChild("properties"));
+            object->propertySet_ = new PropertySet2D();
+            object->propertySet_->Load(objectElem.GetChild("properties"));
         }
 
         objects_.Push(object);
     }
 
     if (element.HasChild("properties"))
-        LoadProperties(element.GetChild("properties"));
+        LoadPropertySet(element.GetChild("properties"));
 
     return true;
 }
 
-
 TileObject2D* TmxObjectGroup2D::GetObject(unsigned index) const
 {
     if (index >= objects_.Size())
@@ -348,7 +256,7 @@ bool TmxImageLayer2D::Load(const XMLElement& element)
     sprite_->SetHotSpot(Vector2(0.0f, 1.0f));
 
     if (element.HasChild("properties"))
-        LoadProperties(element.GetChild("properties"));
+        LoadPropertySet(element.GetChild("properties"));
 
     return true;
 }
@@ -486,17 +394,17 @@ bool TmxFile2D::EndLoad()
 
 Sprite2D* TmxFile2D::GetTileSprite(int gid) const
 {
-    HashMap<int, SharedPtr<Sprite2D> >::ConstIterator i = tileSprites_.Find(gid);
-    if (i == tileSprites_.End())
+    HashMap<int, SharedPtr<Sprite2D> >::ConstIterator i = gidToSpriteMapping_.Find(gid);
+    if (i == gidToSpriteMapping_.End())
         return 0;
 
     return i->second_;
 }
 
-Properties2D* TmxFile2D::GetTileProperties(int gid) const
+PropertySet2D* TmxFile2D::GetTilePropertySet(int gid) const
 {
-    HashMap<int, SharedPtr<Properties2D> >::ConstIterator i = tileProperties_.Find(gid);
-    if (i == tileProperties_.End())
+    HashMap<int, SharedPtr<PropertySet2D> >::ConstIterator i = gidToPropertySetMapping_.Find(gid);
+    if (i == gidToPropertySetMapping_.End())
         return 0;
     return i->second_;
 }
@@ -539,10 +447,8 @@ bool TmxFile2D::LoadTileSet(const XMLElement& element)
             SharedPtr<Sprite2D> sprite(new Sprite2D(context_));
             sprite->SetTexture(texture);
             sprite->SetRectangle(IntRect(x, y, x + tileWidth, y + tileHeight));
-            // Set hot spot at left bottom
-            sprite->SetHotSpot(Vector2(0.0f, 0.0f));
-
-            tileSprites_[gid++] = sprite;
+            
+            gidToSpriteMapping_[gid++] = sprite;
         }
     }
 
@@ -550,9 +456,9 @@ bool TmxFile2D::LoadTileSet(const XMLElement& element)
     {
         if (tileElem.HasChild("properties"))
         {
-            SharedPtr<Properties2D> properties(new Properties2D());
-            properties->Load(tileElem.GetChild("properties"));
-            tileProperties_[firstgid + tileElem.GetInt("id")] = properties;
+            SharedPtr<PropertySet2D> propertySet(new PropertySet2D());
+            propertySet->Load(tileElem.GetChild("properties"));
+            gidToPropertySetMapping_[firstgid + tileElem.GetInt("id")] = propertySet;
         }
     }
 

+ 13 - 132
Source/Engine/Urho2D/TmxFile2D.h

@@ -23,8 +23,7 @@
 #pragma once
 
 #include "Resource.h"
-#include "Ptr.h"
-#include "Sprite2D.h"
+#include "TileMapDefs2D.h"
 
 namespace Urho3D
 {
@@ -35,135 +34,17 @@ class TmxFile2D;
 class XMLElement;
 class XMLFile;
 
-/// Peroperies.
-class URHO3D_API Properties2D : public RefCounted
-{
-public:
-    Properties2D();
-    virtual ~Properties2D();
-
-    /// Load from XML element.
-    void Load(const XMLElement& element);
-    /// Return has property (use for script).
-    bool HasProperty(const String& name) const;
-    /// Return property value (use for script).
-    const String& GetProperty(const String& name) const;
-
-protected:
-    /// Property name to value mapping.
-    HashMap<String, String> properties_;
-};
-
-/// Tile define.
-class URHO3D_API Tile2D : public RefCounted
-{
-public:
-    /// Construct.
-    Tile2D();
-
-    /// Return gid.
-    int GetGid() const { return gid_; }
-    /// Return sprite.
-    Sprite2D* GetSprite() const;
-    /// Return has property.
-    bool HasProperty(const String& name) const;
-    /// Return property.
-    const String& GetProperty(const String& name) const;
-
-private:
-    friend class TmxTileLayer2D;
-    /// Gid.
-    int gid_;
-    /// Sprite.
-    SharedPtr<Sprite2D> sprite_;
-    /// Properties.
-    SharedPtr<Properties2D> properties_;
-};
-
-/// Tile object type.
-enum TileObjectType2D
-{
-    /// Rectangle.
-    OT_RECTANGLE = 0,
-    /// Ellipse.
-    OT_ELLIPSE,
-    /// Polygon.
-    OT_POLYGON,
-    /// Polyline.
-    OT_POLYLINE,
-    /// Tile.
-    OT_TILE,
-    /// Invalid.
-    OT_INVALID = 0xffff
-};
-
-/// Tile map object.
-class URHO3D_API TileObject2D : public RefCounted
-{
-public:
-    TileObject2D();
-
-    /// Return type.
-    TileObjectType2D 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.
-    bool HasProperty(const String& name) const;
-    /// Return property value.
-    const String& GetProperty(const String& name) const;
-
-private:
-    friend class TmxObjectGroup2D;
-    /// Object type.
-    TileObjectType2D type_;
-    /// Position.
-    Vector2 position_;
-    /// Size (for rectangle and ellipse).
-    Vector2 size_;
-    /// Points(for polygon and polyline).
-    Vector<Vector2> points_;
-    /// Gid (for tile).
-    int gid_;
-    /// Sprite (for tile).
-    SharedPtr<Sprite2D> sprite_;
-    /// Properties.
-    SharedPtr<Properties2D> properties_;
-};
-
-/// Tmx layer type.
-enum TmxLayerType2D
-{
-    /// Tile layer.
-    LT_TILE_LAYER = 0,
-    /// Object group.
-    LT_OBJECT_GROUP,
-    /// Image layer.
-    LT_IMAGE_LAYER,
-    /// Invalid.
-    LT_INVALID = 0xffff
-};
-
 /// Tmx layer.
 class TmxLayer2D : public RefCounted
 {
 public:
-    TmxLayer2D(TmxFile2D* tmxFile, TmxLayerType2D type);
+    TmxLayer2D(TmxFile2D* tmxFile, TileMapLayerType2D type);
     virtual ~TmxLayer2D();
 
     /// Return tmx file.
     TmxFile2D* GetTmxFile() const;
     /// Return type.
-    TmxLayerType2D GetType() const { return type_; }
+    TileMapLayerType2D GetType() const { return type_; }
     /// Return name.
     const String& GetName() const { return name_; }
     /// Return width.
@@ -181,13 +62,13 @@ public:
 protected:
     /// Load layer info.
     void LoadInfo(const XMLElement& element);
-    /// Load properties.
-    void LoadProperties(const XMLElement& element);
+    /// Load property set.
+    void LoadPropertySet(const XMLElement& element);
 
     /// Tmx file.
     WeakPtr<TmxFile2D> tmxFile_;
     /// Layer type.
-    TmxLayerType2D type_;
+    TileMapLayerType2D type_;
     /// Name.
     String name_;
     /// Width.
@@ -196,8 +77,8 @@ protected:
     int height_;
     /// Visible.
     bool visible_;
-    /// Properties.
-    SharedPtr<Properties2D> properties_;
+    /// Property set.
+    SharedPtr<PropertySet2D> propertySet_;
 };
 
 /// Tmx tile layer.
@@ -282,8 +163,8 @@ public:
     float GetTileHeight() const { return tileHeight_; }
     /// Return tile sprite by gid, if not exist return 0.
     Sprite2D* GetTileSprite(int gid) const;
-    /// Return tile properties by gid, if not exist return 0.
-    Properties2D* GetTileProperties(int gid) const;
+    /// Return tile property set by gid, if not exist return 0.
+    PropertySet2D* GetTilePropertySet(int gid) const;
     /// Return number of layers.
     unsigned GetNumLayers() const { return layers_.Size(); }
     /// Return layer at index.
@@ -306,9 +187,9 @@ private:
     /// Tile set textures.
     Vector<SharedPtr<Texture2D> > tileSetTextures_;
     /// Gid to tile sprite mapping.
-    HashMap<int, SharedPtr<Sprite2D> > tileSprites_;
-    /// Gid to tile properties mapping.
-    HashMap<int, SharedPtr<Properties2D> > tileProperties_;
+    HashMap<int, SharedPtr<Sprite2D> > gidToSpriteMapping_;
+    /// Gid to tile property set mapping.
+    HashMap<int, SharedPtr<PropertySet2D> > gidToPropertySetMapping_;
     /// Layers.
     Vector<TmxLayer2D*> layers_;
 };