mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
Compare commits
3 Commits
849ff6bcc8
...
8961343558
| Author | SHA1 | Date | |
|---|---|---|---|
| 8961343558 | |||
| f8a6b976c9 | |||
| a7617f3a3a |
@@ -1,17 +1,41 @@
|
|||||||
project(tmxlite VERSION 1.3.1)
|
project(tmxlite VERSION 1.3.1)
|
||||||
|
|
||||||
# includes the list of source files in the src directory
|
add_library(${PROJECT_NAME} STATIC
|
||||||
set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
include/tmxlite/Config.hpp
|
||||||
file(GLOB PROJECT_SRC ${PROJECT_DIR}/*.cpp)
|
include/tmxlite/FreeFuncs.hpp
|
||||||
file(GLOB PROJECT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/*.hpp)
|
include/tmxlite/ImageLayer.hpp
|
||||||
file(GLOB PROJECT_HEADERS_INL ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/*.inl)
|
include/tmxlite/Layer.hpp
|
||||||
file(GLOB PROJECT_HEADERS_DETAIL ${CMAKE_CURRENT_SOURCE_DIR}/include/tmxlite/detail/*.hpp)
|
include/tmxlite/LayerGroup.hpp
|
||||||
list(APPEND PROJECT_SRC ${PROJECT_HEADERS} ${PROJECT_HEADERS_INL} ${PROJECT_HEADERS_DETAIL})
|
include/tmxlite/Map.hpp
|
||||||
|
include/tmxlite/Object.hpp
|
||||||
|
include/tmxlite/ObjectGroup.hpp
|
||||||
|
include/tmxlite/ObjectTypes.hpp
|
||||||
|
include/tmxlite/Property.hpp
|
||||||
|
include/tmxlite/TileLayer.hpp
|
||||||
|
include/tmxlite/Tileset.hpp
|
||||||
|
include/tmxlite/Types.hpp
|
||||||
|
include/tmxlite/Types.inl
|
||||||
|
include/tmxlite/detail/Log.hpp
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} STATIC ${PROJECT_SRC})
|
src/FreeFuncs.cpp
|
||||||
|
src/ImageLayer.cpp
|
||||||
|
src/Map.cpp
|
||||||
|
src/Object.cpp
|
||||||
|
src/ObjectGroup.cpp
|
||||||
|
src/Property.cpp
|
||||||
|
src/TileLayer.cpp
|
||||||
|
src/LayerGroup.cpp
|
||||||
|
src/Tileset.cpp
|
||||||
|
src/ObjectTypes.cpp)
|
||||||
|
|
||||||
|
if (NOT USE_ZLIB)
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE
|
||||||
|
include/tmxlite/detail/gzip.hpp
|
||||||
|
src/detail/gzip.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
CXX_STANDARD 14
|
CXX_STANDARD 20
|
||||||
CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/detail/Android.hpp>
|
#include "tmxlite/detail/Log.hpp"
|
||||||
#include <tmxlite/detail/Log.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -96,17 +95,8 @@ namespace tmx
|
|||||||
outPath = outPath.substr(0, result);
|
outPath = outPath.substr(0, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// this does only work on windows
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
return outPath + '/' + path;
|
return outPath + '/' + path;
|
||||||
#endif
|
|
||||||
|
|
||||||
// todo: make resolveFilePath work with subfolders on
|
|
||||||
// android - currently only the root folder is working
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
return path;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::string getFilePath(const std::string& path)
|
static inline std::string getFilePath(const std::string& path)
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Layer.hpp>
|
#include "tmxlite/Layer.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
namespace tmx
|
namespace tmx
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ namespace tmx
|
|||||||
const Colour& getTransparencyColour() const { return m_transparencyColour; }
|
const Colour& getTransparencyColour() const { return m_transparencyColour; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns true if the image used by this layer specifically states a
|
\brief Returns true if the image used by this layer specifically states a
|
||||||
colour to use as transparency
|
colour to use as transparency
|
||||||
*/
|
*/
|
||||||
bool hasTransparency() const { return m_hasTransparency; }
|
bool hasTransparency() const { return m_hasTransparency; }
|
||||||
@@ -70,13 +70,13 @@ namespace tmx
|
|||||||
const Vector2u& getImageSize() const { return m_imageSize; }
|
const Vector2u& getImageSize() const { return m_imageSize; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns true if the image drawn by this layer is repeated along
|
\brief Returns true if the image drawn by this layer is repeated along
|
||||||
the X axis.
|
the X axis.
|
||||||
*/
|
*/
|
||||||
bool hasRepeatX() const { return m_hasRepeatX; }
|
bool hasRepeatX() const { return m_hasRepeatX; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns true if the image drawn by this layer is repeated along
|
\brief Returns true if the image drawn by this layer is repeated along
|
||||||
the Y axis.
|
the Y axis.
|
||||||
*/
|
*/
|
||||||
bool hasRepeatY() const { return m_hasRepeatY; }
|
bool hasRepeatY() const { return m_hasRepeatY; }
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Property.hpp>
|
#include "tmxlite/Property.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Layer.hpp>
|
#include "tmxlite/Layer.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -83,4 +83,4 @@ namespace tmx
|
|||||||
assert(getType() == Type::Group);
|
assert(getType() == Type::Group);
|
||||||
return *static_cast<const LayerGroup*>(this);
|
return *static_cast<const LayerGroup*>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Tileset.hpp>
|
#include "tmxlite/Tileset.hpp"
|
||||||
#include <tmxlite/Layer.hpp>
|
#include "tmxlite/Layer.hpp"
|
||||||
#include <tmxlite/Property.hpp>
|
#include "tmxlite/Property.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
#include <tmxlite/Object.hpp>
|
#include "tmxlite/Object.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -45,13 +45,13 @@ namespace tmx
|
|||||||
*/
|
*/
|
||||||
struct TMXLITE_EXPORT_API Version
|
struct TMXLITE_EXPORT_API Version
|
||||||
{
|
{
|
||||||
//major/minor are apparently reserved by gcc
|
//major/minor are apparently reserved by gcc
|
||||||
std::uint16_t upper;
|
std::uint16_t upper;
|
||||||
std::uint16_t lower;
|
std::uint16_t lower;
|
||||||
Version(std::uint16_t maj = 0, std::uint16_t min = 0)
|
Version(std::uint16_t maj = 0, std::uint16_t min = 0)
|
||||||
: upper(maj), lower(min) {}
|
: upper(maj), lower(min) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Orientation
|
enum class Orientation
|
||||||
{
|
{
|
||||||
Orthogonal,
|
Orthogonal,
|
||||||
@@ -93,7 +93,7 @@ namespace tmx
|
|||||||
class TMXLITE_EXPORT_API Map final
|
class TMXLITE_EXPORT_API Map final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Map();
|
Map();
|
||||||
~Map() = default;
|
~Map() = default;
|
||||||
Map(const Map&) = delete;
|
Map(const Map&) = delete;
|
||||||
@@ -203,7 +203,7 @@ namespace tmx
|
|||||||
/*!
|
/*!
|
||||||
\brief Returns a vector of Property objects loaded by the map
|
\brief Returns a vector of Property objects loaded by the map
|
||||||
*/
|
*/
|
||||||
const std::vector<Property>& getProperties() const { return m_properties; }
|
const std::vector<Property>& getProperties() const { return m_properties; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns a Hashmap of all animated tiles accessible by TileID
|
\brief Returns a Hashmap of all animated tiles accessible by TileID
|
||||||
@@ -279,4 +279,4 @@ namespace tmx
|
|||||||
//on load failure
|
//on load failure
|
||||||
bool reset();
|
bool reset();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Property.hpp>
|
#include "tmxlite/Property.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -70,13 +70,13 @@ namespace tmx
|
|||||||
|
|
||||||
std::string content; //!< actual string content
|
std::string content; //!< actual string content
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Objects are stored in ObjectGroup layers.
|
\brief Objects are stored in ObjectGroup layers.
|
||||||
Objects may be rectangular, elliptical, polygonal or
|
Objects may be rectangular, elliptical, polygonal or
|
||||||
a polyline. Rectangular and elliptical Objects have their
|
a polyline. Rectangular and elliptical Objects have their
|
||||||
size determined via the AABB, whereas polygon and polyline
|
size determined via the AABB, whereas polygon and polyline
|
||||||
shapes are defined by a list of points. Objects are
|
shapes are defined by a list of points. Objects are
|
||||||
rectangular by default. Since version 1.0 Objects also
|
rectangular by default. Since version 1.0 Objects also
|
||||||
support Text nodes.
|
support Text nodes.
|
||||||
*/
|
*/
|
||||||
@@ -105,12 +105,12 @@ namespace tmx
|
|||||||
\brief Returns the unique ID of the Object
|
\brief Returns the unique ID of the Object
|
||||||
*/
|
*/
|
||||||
std::uint32_t getUID() const { return m_UID; }
|
std::uint32_t getUID() const { return m_UID; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the name of the Object
|
\brief Returns the name of the Object
|
||||||
*/
|
*/
|
||||||
const std::string& getName() const { return m_name; }
|
const std::string& getName() const { return m_name; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the type (equal to class) of the Object, as defined in the editor Tiled < 1.9
|
\brief Returns the type (equal to class) of the Object, as defined in the editor Tiled < 1.9
|
||||||
*/
|
*/
|
||||||
@@ -125,7 +125,7 @@ namespace tmx
|
|||||||
\brief Returns the position of the Object in pixels
|
\brief Returns the position of the Object in pixels
|
||||||
*/
|
*/
|
||||||
const Vector2f& getPosition() const { return m_position; }
|
const Vector2f& getPosition() const { return m_position; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the global Axis Aligned Bounding Box.
|
\brief Returns the global Axis Aligned Bounding Box.
|
||||||
The AABB is positioned via the left and top properties, and
|
The AABB is positioned via the left and top properties, and
|
||||||
@@ -133,19 +133,19 @@ namespace tmx
|
|||||||
the shape of the Object if it is rectangular or elliptical.
|
the shape of the Object if it is rectangular or elliptical.
|
||||||
*/
|
*/
|
||||||
const FloatRect& getAABB() const { return m_AABB; }
|
const FloatRect& getAABB() const { return m_AABB; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the rotation of the Object in degrees clockwise
|
\brief Returns the rotation of the Object in degrees clockwise
|
||||||
*/
|
*/
|
||||||
float getRotation() const { return m_rotation; }
|
float getRotation() const { return m_rotation; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the global tile ID associated with the Object
|
\brief Returns the global tile ID associated with the Object
|
||||||
if there is one. This is used to draw the Object (and therefore
|
if there is one. This is used to draw the Object (and therefore
|
||||||
the Object must be rectangular)
|
the Object must be rectangular)
|
||||||
*/
|
*/
|
||||||
std::uint32_t getTileID() const { return m_tileID; }
|
std::uint32_t getTileID() const { return m_tileID; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the flip flags if the objects uses a TileID to
|
\brief Returns the flip flags if the objects uses a TileID to
|
||||||
draw it.
|
draw it.
|
||||||
@@ -157,12 +157,12 @@ namespace tmx
|
|||||||
\brief Returns whether or not the Object is visible
|
\brief Returns whether or not the Object is visible
|
||||||
*/
|
*/
|
||||||
bool visible() const { return m_visible; }
|
bool visible() const { return m_visible; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the Shape type of the Object
|
\brief Returns the Shape type of the Object
|
||||||
*/
|
*/
|
||||||
Shape getShape() const { return m_shape; }
|
Shape getShape() const { return m_shape; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns a reference to the vector of points which
|
\brief Returns a reference to the vector of points which
|
||||||
make up the Object. If the Object is rectangular or elliptical
|
make up the Object. If the Object is rectangular or elliptical
|
||||||
@@ -170,7 +170,7 @@ namespace tmx
|
|||||||
relative to the object position.
|
relative to the object position.
|
||||||
*/
|
*/
|
||||||
const std::vector<Vector2f>& getPoints() const { return m_points; }
|
const std::vector<Vector2f>& getPoints() const { return m_points; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns a reference to the vector of properties belonging to
|
\brief Returns a reference to the vector of properties belonging to
|
||||||
the Object.
|
the Object.
|
||||||
@@ -188,7 +188,7 @@ namespace tmx
|
|||||||
Text& getText() { return m_textData; }
|
Text& getText() { return m_textData; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the tileset name used by this object if it is derived
|
\brief Returns the tileset name used by this object if it is derived
|
||||||
from a template, else returns an empty string.
|
from a template, else returns an empty string.
|
||||||
If the string is not empty use it to index the unordered_map returned
|
If the string is not empty use it to index the unordered_map returned
|
||||||
by Map::getTemplateTilesets()
|
by Map::getTemplateTilesets()
|
||||||
@@ -218,4 +218,4 @@ namespace tmx
|
|||||||
void parseText(const pugi::xml_node&);
|
void parseText(const pugi::xml_node&);
|
||||||
void parseTemplate(const std::string&, Map*);
|
void parseTemplate(const std::string&, Map*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Layer.hpp>
|
#include "tmxlite/Layer.hpp"
|
||||||
#include <tmxlite/Object.hpp>
|
#include "tmxlite/Object.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -96,4 +96,4 @@ namespace tmx
|
|||||||
assert(getType() == Type::Object);
|
assert(getType() == Type::Object);
|
||||||
return *static_cast<const ObjectGroup*>(this);
|
return *static_cast<const ObjectGroup*>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Property.hpp>
|
#include "tmxlite/Property.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -83,4 +83,4 @@ namespace tmx
|
|||||||
//on load failure
|
//on load failure
|
||||||
bool reset();
|
bool reset();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@@ -43,14 +43,14 @@ namespace tmx
|
|||||||
/*!
|
/*!
|
||||||
\brief Represents a custom property.
|
\brief Represents a custom property.
|
||||||
Tiles, objects and layers of a tmx map may have custom
|
Tiles, objects and layers of a tmx map may have custom
|
||||||
properties assigned to them. This class represents a
|
properties assigned to them. This class represents a
|
||||||
single property and provides access to its value, the
|
single property and provides access to its value, the
|
||||||
type of which can be determined with getType()
|
type of which can be determined with getType()
|
||||||
*/
|
*/
|
||||||
class TMXLITE_EXPORT_API Property final
|
class TMXLITE_EXPORT_API Property final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum class Type
|
enum class Type
|
||||||
{
|
{
|
||||||
Boolean,
|
Boolean,
|
||||||
@@ -62,7 +62,7 @@ namespace tmx
|
|||||||
Object,
|
Object,
|
||||||
Undef
|
Undef
|
||||||
};
|
};
|
||||||
|
|
||||||
Property();
|
Property();
|
||||||
|
|
||||||
static Property fromBoolean(bool value);
|
static Property fromBoolean(bool value);
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Layer.hpp>
|
#include "tmxlite/Layer.hpp"
|
||||||
#include <tmxlite/Types.hpp>
|
#include "tmxlite/Types.hpp"
|
||||||
|
|
||||||
namespace tmx
|
namespace tmx
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ namespace tmx
|
|||||||
Vertical = 0x4,
|
Vertical = 0x4,
|
||||||
Diagonal = 0x2
|
Diagonal = 0x2
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit TileLayer(std::size_t);
|
explicit TileLayer(std::size_t);
|
||||||
|
|
||||||
Type getType() const override { return Layer::Type::Tile; }
|
Type getType() const override { return Layer::Type::Tile; }
|
||||||
@@ -113,4 +113,4 @@ namespace tmx
|
|||||||
assert(getType() == Type::Tile);
|
assert(getType() == Type::Tile);
|
||||||
return *static_cast<const TileLayer*>(this);
|
return *static_cast<const TileLayer*>(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
#include <tmxlite/Property.hpp>
|
#include "tmxlite/Property.hpp"
|
||||||
#include <tmxlite/ObjectGroup.hpp>
|
#include "tmxlite/ObjectGroup.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -101,7 +101,7 @@ namespace tmx
|
|||||||
Vector2u imagePosition;
|
Vector2u imagePosition;
|
||||||
std::string className;
|
std::string className;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Terrain information with which one
|
\brief Terrain information with which one
|
||||||
or more tiles may be associated.
|
or more tiles may be associated.
|
||||||
@@ -247,7 +247,7 @@ namespace tmx
|
|||||||
/*!
|
/*!
|
||||||
\brief Checks if a tiled ID is in the range of the first ID and the last ID
|
\brief Checks if a tiled ID is in the range of the first ID and the last ID
|
||||||
\param id Tile ID
|
\param id Tile ID
|
||||||
\return
|
\return
|
||||||
*/
|
*/
|
||||||
bool hasTile(std::uint32_t id) const { return id >= m_firstGID && id <= getLastGID(); };
|
bool hasTile(std::uint32_t id) const { return id >= m_firstGID && id <= getLastGID(); };
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ source distribution.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <tmxlite/Config.hpp>
|
#include "tmxlite/Config.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@@ -147,4 +147,4 @@ std::ostream& operator << (std::ostream& os, const tmx::Rectangle<T>& t)
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator << (std::ostream& os, const tmx::Colour& c);
|
std::ostream& operator << (std::ostream& os, const tmx::Colour& c);
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
/*********************************************************************
|
|
||||||
Matt Marchant 2016
|
|
||||||
http://trederia.blogspot.com
|
|
||||||
|
|
||||||
tmxlite - Zlib license.
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or
|
|
||||||
implied warranty. In no event will the authors be held
|
|
||||||
liable for any damages arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute
|
|
||||||
it freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented;
|
|
||||||
you must not claim that you wrote the original software.
|
|
||||||
If you use this software in a product, an acknowledgment
|
|
||||||
in the product documentation would be appreciated but
|
|
||||||
is not required.
|
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such,
|
|
||||||
and must not be misrepresented as being the original software.
|
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any
|
|
||||||
source distribution.
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
#ifndef ANDROID_INC_HPP_
|
|
||||||
#define ANDROID_INC_HPP_
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
std::string to_string(T value)
|
|
||||||
{
|
|
||||||
std::ostringstream os;
|
|
||||||
os << value;
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define STOI(str) std::strtol(str.c_str(), 0, 10)
|
|
||||||
#else
|
|
||||||
#define STOI(str) std::stoi(str)
|
|
||||||
|
|
||||||
#endif // __ANDROID__
|
|
||||||
#endif // ANDROID_INC_HPP_
|
|
||||||
@@ -43,18 +43,6 @@ source distribution.
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif //_MSC_VER
|
#endif //_MSC_VER
|
||||||
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
#include <android/log.h>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#define LOG_TAG "TMXlite-Debug"
|
|
||||||
//#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
|
||||||
|
|
||||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
|
||||||
#endif // __ANDROID__
|
|
||||||
|
|
||||||
namespace tmx
|
namespace tmx
|
||||||
{
|
{
|
||||||
/*!
|
/*!
|
||||||
@@ -105,23 +93,10 @@ namespace tmx
|
|||||||
{
|
{
|
||||||
if (type == Type::Error)
|
if (type == Type::Error)
|
||||||
{
|
{
|
||||||
#ifdef __ANDROID__
|
|
||||||
|
|
||||||
int outstringLength = outstring.length();
|
|
||||||
char outstring_chararray[outstringLength+1];
|
|
||||||
std::strcpy(outstring_chararray, outstring.c_str());
|
|
||||||
LOGE("%s",outstring_chararray);
|
|
||||||
#endif
|
|
||||||
std::cerr << outstring << std::endl;
|
std::cerr << outstring << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef __ANDROID__
|
|
||||||
int outstringLength = outstring.length();
|
|
||||||
char outstring_chararray[outstringLength+1];
|
|
||||||
std::strcpy(outstring_chararray, outstring.c_str());
|
|
||||||
LOGI("%s", outstring_chararray);
|
|
||||||
#endif
|
|
||||||
std::cout << outstring << std::endl;
|
std::cout << outstring << std::endl;
|
||||||
}
|
}
|
||||||
const std::size_t maxBuffer = 30;
|
const std::size_t maxBuffer = 30;
|
||||||
@@ -140,13 +115,11 @@ namespace tmx
|
|||||||
std::ofstream file("output.log", std::ios::app);
|
std::ofstream file("output.log", std::ios::app);
|
||||||
if (file.good())
|
if (file.good())
|
||||||
{
|
{
|
||||||
#ifndef __ANDROID__
|
|
||||||
std::time_t time = std::time(nullptr);
|
std::time_t time = std::time(nullptr);
|
||||||
auto tm = *std::localtime(&time);
|
auto tm = *std::localtime(&time);
|
||||||
//put_time isn't implemented by the ndk versions of the stl
|
//put_time isn't implemented by the ndk versions of the stl
|
||||||
file.imbue(std::locale());
|
file.imbue(std::locale());
|
||||||
file << std::put_time(&tm, "%d/%m/%y-%H:%M:%S: ");
|
file << std::put_time(&tm, "%d/%m/%y-%H:%M:%S: ");
|
||||||
#endif //__ANDROID__
|
|
||||||
file << outstring << std::endl;
|
file << outstring << std::endl;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|||||||
39
ext/tmxlite/include/tmxlite/detail/gzip.hpp
Normal file
39
ext/tmxlite/include/tmxlite/detail/gzip.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// gzip.hpp - portable memory miniz based gzip reader
|
||||||
|
// SPDX-License-Identifier: Zlib
|
||||||
|
// SPDX-FileCopyrightText: (c) 2024 a dinosaur
|
||||||
|
|
||||||
|
#ifndef GZIP_HPP
|
||||||
|
#define GZIP_HPP
|
||||||
|
|
||||||
|
#include "miniz.h"
|
||||||
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
|
||||||
|
class GZipReader
|
||||||
|
{
|
||||||
|
static constexpr uint8_t
|
||||||
|
FTEXT = 1, FHCRC = 1<<1, FEXTRA = 1<<2, FNAME = 1<<3, FCOMMENT = 1<<4;
|
||||||
|
|
||||||
|
static constexpr uint8_t XFL_BEST = 2, XFL_FASTEST = 4;
|
||||||
|
|
||||||
|
tinfl_decompressor mState;
|
||||||
|
std::span<const uint8_t>::iterator mIt;
|
||||||
|
|
||||||
|
size_t mSourceLen, mBytesRead;
|
||||||
|
uint32_t mModificationTime, mCrc, mInputSize, mComputedCrc;
|
||||||
|
uint16_t crc16;
|
||||||
|
uint8_t mFlags, mXflags, mOsId;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GZipReader() noexcept;
|
||||||
|
|
||||||
|
constexpr size_t SourceLength() const noexcept { return mSourceLen; }
|
||||||
|
constexpr uint32_t OutputLength() const noexcept { return mInputSize; }
|
||||||
|
|
||||||
|
bool OpenMemory(const std::span<const uint8_t> source) noexcept;
|
||||||
|
bool Read(std::span<uint8_t> out) noexcept;
|
||||||
|
bool Check() const noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif//GZIP_HPP
|
||||||
@@ -25,15 +25,14 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
#include "tmxlite/Types.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
#ifndef USE_ZLIB
|
#ifndef USE_ZLIB
|
||||||
#include "miniz.h"
|
# include "miniz.h"
|
||||||
#else
|
#else
|
||||||
#include <zlib.h>
|
# include <zlib.h>
|
||||||
#endif
|
#endif
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
#include <tmxlite/Types.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::size_t inSize, std::size_t expectedSize)
|
bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::size_t inSize, std::size_t expectedSize)
|
||||||
@@ -59,7 +58,7 @@ bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::
|
|||||||
stream.next_out = (Bytef*)byteArray.data();
|
stream.next_out = (Bytef*)byteArray.data();
|
||||||
stream.avail_out = static_cast<unsigned int>(expectedSize);
|
stream.avail_out = static_cast<unsigned int>(expectedSize);
|
||||||
|
|
||||||
//we'd prefer to use inflateInit2 but it appears
|
//we'd prefer to use inflateInit2 but it appears
|
||||||
//to be incorrect in miniz. This is fine for zlib
|
//to be incorrect in miniz. This is fine for zlib
|
||||||
//compressed data, but gzip compressed streams
|
//compressed data, but gzip compressed streams
|
||||||
//will fail to inflate.
|
//will fail to inflate.
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/ImageLayer.hpp"
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <tmxlite/ImageLayer.hpp>
|
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,14 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/LayerGroup.hpp"
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
#include "tmxlite/ObjectGroup.hpp"
|
||||||
|
#include "tmxlite/ImageLayer.hpp"
|
||||||
|
#include "tmxlite/TileLayer.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <tmxlite/LayerGroup.hpp>
|
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
#include <tmxlite/ObjectGroup.hpp>
|
|
||||||
#include <tmxlite/ImageLayer.hpp>
|
|
||||||
#include <tmxlite/TileLayer.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
|
|||||||
@@ -25,16 +25,15 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include "tmxlite/Map.hpp"
|
||||||
#include <tmxlite/Map.hpp>
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
#include "tmxlite/ObjectGroup.hpp"
|
||||||
#include <tmxlite/ObjectGroup.hpp>
|
#include "tmxlite/ImageLayer.hpp"
|
||||||
#include <tmxlite/ImageLayer.hpp>
|
#include "tmxlite/TileLayer.hpp"
|
||||||
#include <tmxlite/TileLayer.hpp>
|
#include "tmxlite/LayerGroup.hpp"
|
||||||
#include <tmxlite/LayerGroup.hpp>
|
#include "tmxlite/detail/Log.hpp"
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
#include <tmxlite/detail/Android.hpp>
|
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
@@ -136,8 +135,8 @@ bool Map::parseMapNode(const pugi::xml_node& mapNode)
|
|||||||
return reset();
|
return reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_version.upper = STOI(attribString.substr(0, pointPos));
|
m_version.upper = std::stoi(attribString.substr(0, pointPos));
|
||||||
m_version.lower = STOI(attribString.substr(pointPos + 1));
|
m_version.lower = std::stoi(attribString.substr(pointPos + 1));
|
||||||
|
|
||||||
m_class = mapNode.attribute("class").as_string();
|
m_class = mapNode.attribute("class").as_string();
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include "tmxlite/Object.hpp"
|
||||||
#include <tmxlite/Object.hpp>
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
#include "tmxlite/Map.hpp"
|
||||||
#include <tmxlite/Map.hpp>
|
#include "tmxlite/Tileset.hpp"
|
||||||
#include <tmxlite/Tileset.hpp>
|
#include "tmxlite/detail/Log.hpp"
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
@@ -65,7 +65,7 @@ void Object::parse(const pugi::xml_node& node, Map* map)
|
|||||||
{
|
{
|
||||||
m_class = node.attribute("class").as_string();
|
m_class = node.attribute("class").as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_position.x = node.attribute("x").as_float();
|
m_position.x = node.attribute("x").as_float();
|
||||||
m_AABB.left = m_position.x;
|
m_AABB.left = m_position.x;
|
||||||
m_position.y = node.attribute("y").as_float();
|
m_position.y = node.attribute("y").as_float();
|
||||||
@@ -272,7 +272,7 @@ void Object::parseTemplate(const std::string& path, Map* map)
|
|||||||
{
|
{
|
||||||
m_AABB.height = obj.m_AABB.height;
|
m_AABB.height = obj.m_AABB.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tilesetName = obj.m_tilesetName;
|
m_tilesetName = obj.m_tilesetName;
|
||||||
|
|
||||||
if (m_name.empty())
|
if (m_name.empty())
|
||||||
@@ -313,7 +313,7 @@ void Object::parseTemplate(const std::string& path, Map* map)
|
|||||||
//compare properties and only copy ones that don't exist
|
//compare properties and only copy ones that don't exist
|
||||||
for (const auto& p : obj.m_properties)
|
for (const auto& p : obj.m_properties)
|
||||||
{
|
{
|
||||||
auto result = std::find_if(m_properties.begin(), m_properties.end(),
|
auto result = std::find_if(m_properties.begin(), m_properties.end(),
|
||||||
[&p](const Property& a)
|
[&p](const Property& a)
|
||||||
{
|
{
|
||||||
return a.getName() == p.getName();
|
return a.getName() == p.getName();
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
#include "tmxlite/ObjectGroup.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
#include <tmxlite/ObjectGroup.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
#include "tmxlite/ObjectTypes.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
#include <tmxlite/ObjectTypes.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
|
#include "tmxlite/Property.hpp"
|
||||||
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <tmxlite/Property.hpp>
|
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,18 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
|
||||||
#include <zstd.h>
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "tmxlite/FreeFuncs.hpp"
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
#include "tmxlite/TileLayer.hpp"
|
#include "tmxlite/TileLayer.hpp"
|
||||||
#include "tmxlite/detail/Log.hpp"
|
#include "tmxlite/detail/Log.hpp"
|
||||||
|
#ifndef USE_ZLIB
|
||||||
|
# include "tmxlite/detail/gzip.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
|
#include <zstd.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
|
|
||||||
@@ -139,8 +144,18 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
|
|||||||
break;
|
break;
|
||||||
case CompressionType::GZip:
|
case CompressionType::GZip:
|
||||||
#ifndef USE_ZLIB
|
#ifndef USE_ZLIB
|
||||||
Logger::log("Library must be built with USE_ZLIB for GZip compression", Logger::Type::Error);
|
{
|
||||||
return {};
|
byteData.resize(expectedSize);
|
||||||
|
const auto source = std::span(reinterpret_cast<const uint8_t*>(dataString.data()), dataString.size());
|
||||||
|
|
||||||
|
GZipReader reader;
|
||||||
|
if (!reader.OpenMemory(source) || !reader.Read(byteData) || !reader.Check())
|
||||||
|
{
|
||||||
|
LOG("Failed to decompress layer data, node skipped.", Logger::Type::Error);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
//[[fallthrough]];
|
//[[fallthrough]];
|
||||||
case CompressionType::Zlib:
|
case CompressionType::Zlib:
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ and must not be misrepresented as being the original software.
|
|||||||
source distribution.
|
source distribution.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include "tmxlite/Tileset.hpp"
|
||||||
#include <tmxlite/Tileset.hpp>
|
#include "tmxlite/FreeFuncs.hpp"
|
||||||
#include <tmxlite/FreeFuncs.hpp>
|
#include "tmxlite/detail/Log.hpp"
|
||||||
#include <tmxlite/detail/Log.hpp>
|
|
||||||
|
|
||||||
|
#include <pugixml.hpp>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
using namespace tmx;
|
using namespace tmx;
|
||||||
@@ -59,7 +59,7 @@ void Tileset::parse(pugi::xml_node node, Map* map)
|
|||||||
Logger::log(attribString + ": not a tileset node! Node will be skipped.", Logger::Type::Warning);
|
Logger::log(attribString + ": not a tileset node! Node will be skipped.", Logger::Type::Warning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_firstGID = node.attribute("firstgid").as_int();
|
m_firstGID = node.attribute("firstgid").as_int();
|
||||||
if (m_firstGID == 0)
|
if (m_firstGID == 0)
|
||||||
{
|
{
|
||||||
@@ -237,7 +237,7 @@ const Tileset::Tile* Tileset::getTile(std::uint32_t id) const
|
|||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//corrects the ID. Indices and IDs are different.
|
//corrects the ID. Indices and IDs are different.
|
||||||
id -= m_firstGID;
|
id -= m_firstGID;
|
||||||
id = m_tileIndex[id];
|
id = m_tileIndex[id];
|
||||||
@@ -368,12 +368,12 @@ void Tileset::parseTileNode(const pugi::xml_node& node, Map* map)
|
|||||||
{
|
{
|
||||||
tile.className = node.attribute("class").as_string();
|
tile.className = node.attribute("class").as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//by default we set the tile's values as in an Image tileset
|
//by default we set the tile's values as in an Image tileset
|
||||||
tile.imagePath = m_imagePath;
|
tile.imagePath = m_imagePath;
|
||||||
tile.imageSize = m_tileSize;
|
tile.imageSize = m_tileSize;
|
||||||
|
|
||||||
if (m_columnCount != 0)
|
if (m_columnCount != 0)
|
||||||
{
|
{
|
||||||
std::uint32_t rowIndex = tile.ID % m_columnCount;
|
std::uint32_t rowIndex = tile.ID % m_columnCount;
|
||||||
std::uint32_t columnIndex = tile.ID / m_columnCount;
|
std::uint32_t columnIndex = tile.ID / m_columnCount;
|
||||||
|
|||||||
125
ext/tmxlite/src/detail/gzip.cpp
Normal file
125
ext/tmxlite/src/detail/gzip.cpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
// gzip.cpp - portable memory miniz based gzip reader
|
||||||
|
// SPDX-License-Identifier: Zlib
|
||||||
|
// SPDX-FileCopyrightText: (c) 2024 a dinosaur
|
||||||
|
|
||||||
|
#include "tmxlite/detail/gzip.hpp"
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
|
||||||
|
GZipReader::GZipReader() noexcept :
|
||||||
|
mSourceLen(0), mBytesRead(0),
|
||||||
|
mModificationTime(0), mCrc(0), mInputSize(0), mComputedCrc(0),
|
||||||
|
crc16(0), mFlags(0), mXflags(0), mOsId(0)
|
||||||
|
{
|
||||||
|
tinfl_init(&mState);
|
||||||
|
mComputedCrc = static_cast<uint32_t>(mz_crc32(0, nullptr, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GZipReader::OpenMemory(const std::span<const uint8_t> source) noexcept
|
||||||
|
{
|
||||||
|
if (source.size() < 20)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto it = std::cbegin(source), end = std::cend(source);
|
||||||
|
|
||||||
|
constexpr uint8_t magic[2] = { 0x1F, 0x8B };
|
||||||
|
if (*it++ != magic[0] || *it++ != magic[1])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
constexpr uint8_t CM_DEFLATE = 8;
|
||||||
|
uint8_t compression = *it++;
|
||||||
|
if (compression != CM_DEFLATE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mFlags = *it++;
|
||||||
|
mModificationTime = *it++;
|
||||||
|
mModificationTime |= *it++ << 8;
|
||||||
|
mModificationTime |= *it++ << 16;
|
||||||
|
mModificationTime |= *it++ << 24;
|
||||||
|
mXflags = *it++;
|
||||||
|
mOsId = *it++;
|
||||||
|
|
||||||
|
if (mFlags & FEXTRA)
|
||||||
|
{
|
||||||
|
// Skip "extra" field
|
||||||
|
if (it + 2 >= end)
|
||||||
|
return false;
|
||||||
|
uint16_t extraLen = *it++;
|
||||||
|
extraLen = *it++ << 8;
|
||||||
|
if (it + extraLen >= end)
|
||||||
|
return false;
|
||||||
|
it += extraLen;
|
||||||
|
}
|
||||||
|
if (mFlags & FNAME)
|
||||||
|
{
|
||||||
|
// Skip null-terminated name string
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (++it == end)
|
||||||
|
return false;
|
||||||
|
} while (*it != '\0');
|
||||||
|
if (++it == end)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mFlags & FCOMMENT)
|
||||||
|
{
|
||||||
|
// Skip null-terminated comment string
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (++it == end)
|
||||||
|
return false;
|
||||||
|
} while (*it != '\0');
|
||||||
|
if (++it == end)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mFlags & FHCRC)
|
||||||
|
{
|
||||||
|
if (it + 2 >= end)
|
||||||
|
return false;
|
||||||
|
crc16 = *it++;
|
||||||
|
crc16 |= *it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
mIt = it;
|
||||||
|
mSourceLen = end - it - 8;
|
||||||
|
|
||||||
|
it += mSourceLen;
|
||||||
|
mCrc = *it++;
|
||||||
|
mCrc |= *it++ << 8;
|
||||||
|
mCrc |= *it++ << 16;
|
||||||
|
mCrc |= *it++ << 24;
|
||||||
|
mInputSize = *it++;
|
||||||
|
mInputSize |= *it++ << 8;
|
||||||
|
mInputSize |= *it++ << 16;
|
||||||
|
mInputSize |= *it++ << 24;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GZipReader::Read(std::span<uint8_t> out) noexcept
|
||||||
|
{
|
||||||
|
size_t outLen = out.size();
|
||||||
|
auto res = tinfl_decompress(&mState,
|
||||||
|
static_cast<const mz_uint8*>(&*mIt), &mSourceLen,
|
||||||
|
static_cast<mz_uint8*>(out.data()), static_cast<mz_uint8*>(out.data()), &outLen,
|
||||||
|
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
|
||||||
|
if (res != TINFL_STATUS_DONE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
mIt += outLen;
|
||||||
|
mBytesRead += outLen;
|
||||||
|
mComputedCrc = static_cast<uint32_t>(mz_crc32(static_cast<mz_ulong>(mComputedCrc), out.data(), outLen));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GZipReader::Check() const noexcept
|
||||||
|
{
|
||||||
|
if (mComputedCrc != mCrc)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (static_cast<uint32_t>(mBytesRead & UINT32_MAX) != mInputSize)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user