Skip to content

Commit 87c3b46

Browse files
authored
Merge pull request fallahn#120 from fallahn/feature
Allow linking to external pugixml and zlib libraries
2 parents fcc4979 + 782b139 commit 87c3b46

24 files changed

Lines changed: 261 additions & 62 deletions

ParseTest/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,5 @@ else()
3737
add_executable(${PROJECT_NAME} ${PROJECT_SRC})
3838
endif()
3939

40-
target_include_directories(${PROJECT_NAME}
41-
${CMAKE_CURRENT_BINARY_DIR})
4240
target_link_libraries(${PROJECT_NAME}
43-
${TMXLITE_LIBRARIES})
44-
45-
#install executable
46-
install(TARGETS ${PROJECT_NAME}
47-
RUNTIME DESTINATION .)
48-
49-
#install game data
50-
install(DIRECTORY assets
51-
DESTINATION .)
41+
${TMXLITE_LIBRARIES})

ParseTest/ParseTest.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<Optimization>Disabled</Optimization>
8989
<SDLCheck>true</SDLCheck>
9090
<AdditionalIncludeDirectories>..\tmxlite\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
91-
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
91+
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);PAUSE_AT_END</PreprocessorDefinitions>
9292
</ClCompile>
9393
<Link>
9494
<AdditionalLibraryDirectories>..\tmxlite\x64\bin\DebugStatic;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
@@ -123,6 +123,7 @@
123123
<IntrinsicFunctions>true</IntrinsicFunctions>
124124
<SDLCheck>true</SDLCheck>
125125
<AdditionalIncludeDirectories>..\tmxlite\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
126+
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);PAUSE_AT_END</PreprocessorDefinitions>
126127
</ClCompile>
127128
<Link>
128129
<EnableCOMDATFolding>true</EnableCOMDATFolding>

ParseTest/src/main.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ source distribution.
3131
#include <tmxlite/TileLayer.hpp>
3232

3333
#include <iostream>
34+
#include <array>
35+
#include <string>
36+
37+
namespace
38+
{
39+
const std::array<std::string, 4u> LayerStrings =
40+
{
41+
std::string("Tile"),
42+
std::string("Object"),
43+
std::string("Image"),
44+
std::string("Group"),
45+
};
46+
}
3447

3548
int main()
3649
{
@@ -43,6 +56,10 @@ int main()
4356
{
4457
std::cout << "Map is infinite.\n";
4558
}
59+
else
60+
{
61+
std::cout << "Map Dimensions: " << map.getBounds() << std::endl;
62+
}
4663

4764
const auto& mapProperties = map.getProperties();
4865
std::cout << "Map has " << mapProperties.size() << " properties" << std::endl;
@@ -59,7 +76,9 @@ int main()
5976
for (const auto& layer : layers)
6077
{
6178
std::cout << "Found Layer: " << layer->getName() << std::endl;
62-
std::cout << "Layer Type: " << int(layer->getType()) << std::endl;
79+
std::cout << "Layer Type: " << LayerStrings[static_cast<std::int32_t>(layer->getType())] << std::endl;
80+
std::cout << "Layer Dimensions: " << layer->getSize() << std::endl;
81+
std::cout << "Layer Tint: " << layer->getTintColour() << std::endl;
6382

6483
if (layer->getType() == tmx::Layer::Type::Group)
6584
{
@@ -69,7 +88,9 @@ int main()
6988
for (const auto& sublayer : sublayers)
7089
{
7190
std::cout << "Found Layer: " << sublayer->getName() << std::endl;
72-
std::cout << "Layer Type: " << int(sublayer->getType()) << std::endl;
91+
std::cout << "Sub-layer Type: " << LayerStrings[static_cast<std::int32_t>(sublayer->getType())] << std::endl;
92+
std::cout << "Sub-layer Dimensions: " << sublayer->getSize() << std::endl;
93+
std::cout << "Sub-layer Tint: " << sublayer->getTintColour() << std::endl;
7394

7495
if (sublayer->getType() == tmx::Layer::Type::Object)
7596
{

meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ if cpp.get_argument_syntax() == 'msvc'
5050
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: ['cpp', 'c'])
5151
endif
5252

53+
if get_option('use_extlibs')
54+
add_project_arguments('-DUSE_EXTLIBS', language: ['cpp', 'c'])
55+
zdep = dependency('zlib', version : '>=1.2.8', required: true)
56+
pugidep = dependency('pugixml', required: true)
57+
endif
58+
5359
subdir('tmxlite')
5460
if get_option('build_examples')
5561
subdir('OpenGLExample')

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
option('use_rtti', type: 'boolean', value: true, description: 'Use run time type information?', yield: true)
22
option('project_static_runtime', type: 'boolean', value: false, description: 'Use statically linked standard/runtime libraries?', yield: true)
3+
option('use_extlibs', type: 'boolean', value: false, description: 'Use external pugixml and zlib libraries instead of the included source?', yield: true)
34
option('build_examples', type: 'boolean', value: false)
45
option('build_tests', type: 'boolean', value: false)
56
option('pause_test', type: 'boolean', value: true, description: 'Wait for user input after tests have finished running')

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tmxlite
44
[![Github Actions](https://github.com/fallahn/tmxlite/actions/workflows/cmake.yml/badge.svg)](https://github.com/fallahn/tmxlite/actions)
55

66
#### Description
7-
A lightweight C++14 parsing library for tmx map files created with the Tiled map editor. Requires no external linking, all dependencies are included. Fully supports tmx maps up to 1.0 (see [here](https://doc.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-0)) with CSV, zlib and base64 compression. Also supports some features of newer map versions (see below). The parser is renderer agnostic, and is cross platform on Windows, linux and OS X. It has also been successfully built for Android too.
7+
A lightweight C++14 parsing library for tmx map files created with the Tiled map editor. Requires no external linking, all dependencies are included. Fully supports tmx maps up to 1.0 (see [here](https://doc.mapeditor.org/en/stable/reference/tmx-changelog/#tiled-1-0)) with CSV, zlib and base64 compression. Also supports some features of newer map versions (see below). The parser is renderer agnostic, and is cross platform on Windows, linux and macOS. It has also been successfully built for Android too.
88

99
As the library contains no specific rendering functions some example projects are included, along with the relevant CMake files. These are meant mostly for guidance and are not 100% optimised, but should get you off on the right foot when using libraries such as SFML or SDL2/OpenGL. Examples for any specific rendering library are welcome via a pull request.
1010

@@ -13,6 +13,8 @@ As well as full support for maps up to version 1.0, tmxlite also supports these
1313

1414
* Object Templates - Templates (and any associated tile sets) are automatically loaded and parsed if found. Object properties are transparently handled so that objects can be read from an `ObjectGroup` as if they were unique instances. If an `Object` uses a templated tileset then `Object::getTilsetName()` will contain a non-empty string which can be used as a key with `Map::getTemplateTilesets()` to retrieve the associated tileset data.
1515
* Infinite Maps - Maps with the 'infinite' flag set, and saved in either CSV or base64 (compressed and uncompressed) format are supported. A `TileLayer` will return an empty Tile vector in these cases, and tile ID data can be retrieved instead with `TileLayer::getChunks()` which returns a vector of chunk data that makes up the tile layer.
16+
* Parallax layers - the parallax offset property of layers is parsed, as well as each map's parallax origin, if they exist
17+
* Layer tint colours
1618

1719
#### Building
1820
Either use the included Visual Studio project file if you are on Windows or the CMake file to generate project files for your compiler of choice. tmxlite can be built as both static or shared libraries, or simply include the source files in your own project.
@@ -30,11 +32,11 @@ Doxygen generated API documentation can be found online [here](https://codedocs.
3032
using the doxy file in the tmxlite/documentation/ directory.
3133

3234
#### Important information
33-
tmxlite uses [pugixml](https://pugixml.org/) and [miniz](https://github.com/richgel999/miniz) which are included in the repository.
35+
tmxlite uses [pugixml](https://pugixml.org/) and [miniz](https://github.com/richgel999/miniz) which are included in the repository, although external zlib and pugixml libraries can be used. Add `-DUSE_EXTLIBS` to your compiler's definitions or when configuring CMake set `USE_EXTLIBS` to TRUE.
3436

3537
***
3638

37-
(c)Matt Marchant & contributors 2016 - 2021
39+
(c)Matt Marchant & contributors 2016 - 2023
3840
http://trederia.blogspot.com
3941

4042
tmxlite - Zlib license.

tmxlite/CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.1)
22
project(tmxlite VERSION 1.3.1)
33
SET(PROJECT_NAME tmxlite)
44

@@ -13,6 +13,8 @@ SET(PROJECT_STATIC_RUNTIME FALSE CACHE BOOL "Use statically linked standard/runt
1313

1414
SET(USE_RTTI TRUE CACHE BOOL "Use run time type information?")
1515

16+
SET(USE_EXTLIBS FALSE CACHE BOOL "Use external zlib and pugixml libraries instead of the included source?")
17+
1618
if(USE_RTTI)
1719
if(CMAKE_COMPILER_IS_GNUCXX OR APPLE)
1820
if(PROJECT_STATIC_RUNTIME)
@@ -57,6 +59,22 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
5759
SET(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
5860
include(${PROJECT_DIR}/CMakeLists.txt)
5961

62+
#if we want external zip and xml libs find them and tell the compiler
63+
if(USE_EXTLIBS)
64+
add_definitions(-DUSE_EXTLIBS)
65+
66+
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
67+
68+
find_package(ZLIB REQUIRED)
69+
find_package(PUGIXML REQUIRED)
70+
71+
include_directories(${ZLIB_INCLUDE_DIRS} ${PUGIXML_INCLUDE_DIR})
72+
73+
else()
74+
#add miniz and pugixml from source
75+
SET(PROJECT_SRC ${PROJECT_SRC} ${LIB_SRC})
76+
endif()
77+
6078
if(WIN32)
6179
if(TMXLITE_STATIC_LIB)
6280
add_library(${PROJECT_NAME} STATIC ${PROJECT_SRC})
@@ -71,6 +89,10 @@ else()
7189
endif()
7290
endif()
7391

92+
if(USE_EXTLIBS)
93+
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES} ${PUGIXML_LIBRARY})
94+
endif()
95+
7496
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tmxlite.pc.in ${CMAKE_CURRENT_BINARY_DIR}/tmxlite.pc
7597
@ONLY)
7698

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
find_path(PUGIXML_INCLUDE_DIR NAMES pugixml.hpp)
2+
find_library(PUGIXML_LIBRARY NAMES pugixml)
3+
4+
include(FindPackageHandleStandardArgs)
5+
find_package_handle_standard_args(PUGIXML DEFAULT_MSG
6+
PUGIXML_LIBRARY PUGIXML_INCLUDE_DIR)
7+
8+
mark_as_advanced(PUGIXML_INCLUDE_DIR
9+
PUGIXML_LIBRARY)
10+

tmxlite/include/tmxlite/Layer.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*********************************************************************
2-
Matt Marchant 2016 - 2022
2+
Matt Marchant 2016 - 2023
33
http://trederia.blogspot.com
44
55
tmxlite - Zlib license.
@@ -121,6 +121,17 @@ namespace tmx
121121
*/
122122
const Vector2i& getOffset() const { return m_offset; }
123123

124+
/*!
125+
\brief Returns the parallax factor
126+
*/
127+
const Vector2f& getParallaxFactor() const { return m_parallaxFactor; }
128+
129+
/*!
130+
\brief Returns the tint colour of the layer.
131+
Defaults to 0xFFFFFFFF - pure white
132+
*/
133+
Colour getTintColour() const { return m_tintColour; }
134+
124135
/*!
125136
\brief Returns the size of the layer, in pixels.
126137
This will be the same as the map size for fixed size maps.
@@ -138,6 +149,8 @@ namespace tmx
138149
void setOpacity(float opacity) { m_opacity = opacity; }
139150
void setVisible(bool visible) { m_visible = visible; }
140151
void setOffset(std::int32_t x, std::int32_t y) { m_offset = Vector2i(x, y); }
152+
void setParallaxFactor(float x, float y) { m_parallaxFactor.x = x; m_parallaxFactor.y = y; }
153+
void setTintColour(Colour c) { m_tintColour = c; }
141154
void setSize(std::uint32_t width, std::uint32_t height) { m_size = Vector2u(width, height); }
142155
void addProperty(const pugi::xml_node& node) { m_properties.emplace_back(); m_properties.back().parse(node); }
143156

@@ -146,6 +159,8 @@ namespace tmx
146159
float m_opacity;
147160
bool m_visible;
148161
Vector2i m_offset;
162+
Vector2f m_parallaxFactor;
163+
Colour m_tintColour = { 255,255,255,255 };
149164
Vector2u m_size;
150165

151166
std::vector<Property> m_properties;

tmxlite/include/tmxlite/Map.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace tmx
8888
class before calling load() providing a path to the *.tmx file to be
8989
loaded. Then layers or objects can be requested from the Map class
9090
to be interpreted as needed.
91+
\see https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#map
9192
*/
9293
class TMXLITE_EXPORT_API Map final
9394
{
@@ -234,6 +235,10 @@ namespace tmx
234235
*/
235236
bool isInfinite() const { return m_infinite; }
236237

238+
/*
239+
\brief Returns the origin of each layer's parallax offset value
240+
*/
241+
Vector2f getParallaxOrigin() const { return m_parallaxOrigin; }
237242

238243
private:
239244
Version m_version;
@@ -248,6 +253,8 @@ namespace tmx
248253
StaggerAxis m_staggerAxis;
249254
StaggerIndex m_staggerIndex;
250255

256+
Vector2f m_parallaxOrigin;
257+
251258
Colour m_backgroundColour;
252259

253260
std::string m_workingDirectory;

0 commit comments

Comments
 (0)