A lightweight C++14 parsing library for tmx map files created with the Tiled map editor

Overview

tmxlite

Github Actions

Description

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) 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.

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.

Other Features

As well as full support for maps up to version 1.0, tmxlite also supports these features found in newer versions of the tmx specification:

  • 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.
  • 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.

Building

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.

Quick Start

There is a getting started page on the Github wiki here.

Examples

Check out the following examples:

API Documentation

Doxygen generated API documentation can be found online here or generated with doxygen using the doxy file in the tmxlite/documentation/ directory.

Important information

tmxlite uses pugixml and miniz which are included in the repository.


(c)Matt Marchant & contributors 2016 - 2021 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:

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.

Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

This notice may not be removed or altered from any source distribution.


A big thanks goes to all who have contributed to tmxlite via the github community.

Issues
  • Error during build

    Error during build

    When I try to build my SFML project with tmxlite, I get the following error:

    [email protected]:~/Documents/CPPGame/src$ make build-and-run 
    g++ -c main.cpp
    g++ main.o -o game -lsfml-graphics -lsfml-window -lsfml-system
    /usr/bin/ld: main.o: warning: relocation against `_ZTVN3tmx11ObjectGroupE' in read-only section `.text._ZN3tmx11ObjectGroupD2Ev[_ZN3tmx11ObjectGroupD5Ev]'
    /usr/bin/ld: main.o: in function `main':
    main.cpp:(.text+0x117): undefined reference to `tmx::Map::Map()'
    /usr/bin/ld: main.cpp:(.text+0x15c): undefined reference to `tmx::Map::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /usr/bin/ld: main.o: in function `tmx::Tileset::Tile::Tile()':
    main.cpp:(.text._ZN3tmx7Tileset4TileC2Ev[_ZN3tmx7Tileset4TileC5Ev]+0x66): undefined reference to `tmx::ObjectGroup::ObjectGroup()'
    /usr/bin/ld: main.o: in function `MapLayer::Chunk::ChunkArray::ChunkArray(sf::Texture const&, tmx::Tileset const&)':
    main.cpp:(.text._ZN8MapLayer5Chunk10ChunkArrayC2ERKN2sf7TextureERKN3tmx7TilesetE[_ZN8MapLayer5Chunk10ChunkArrayC5ERKN2sf7TextureERKN3tmx7TilesetE]+0xe5): undefined reference to `tmx::Tileset::getLastGID() const'
    /usr/bin/ld: main.o: in function `tmx::ObjectGroup::ObjectGroup(tmx::ObjectGroup const&)':
    main.cpp:(.text._ZN3tmx11ObjectGroupC2ERKS0_[_ZN3tmx11ObjectGroupC5ERKS0_]+0x2b): undefined reference to `vtable for tmx::ObjectGroup'
    /usr/bin/ld: main.o: in function `tmx::ObjectGroup::~ObjectGroup()':
    main.cpp:(.text._ZN3tmx11ObjectGroupD2Ev[_ZN3tmx11ObjectGroupD5Ev]+0x13): undefined reference to `vtable for tmx::ObjectGroup'
    /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:6: build-and-run] Error 1
    

    The error suggests that it compiles okay, but there is an issue with linking.

    Here is the snippet from my Makefile that I am using to compile and run my game:

    	g++ -c main.cpp
    	g++ main.o -o game -lsfml-graphics -lsfml-window -lsfml-system
    	./game```
    	
    Is there something I have to change in the Makefile, or is the issue related to my code (I based the code off of the SFMLExample/main.cpp file).
    
    Thanks
    opened by iSaluki 12
  • Getting two compile errors: `error C2610` upon building project

    Getting two compile errors: `error C2610` upon building project

    I'm getting the following errors upon building my project in Visual Studio:

    ..\include\tmxlite\map.hpp(98): error C2610: 'tmx::Map::Map(tmx::Map &&)' : is not a special member function which can be defaulted
    ..\include\tmxlite\map.hpp(99): error C2610: 'tmx::Map &tmx::Map::operator =(tmx::Map &&)' : is not a special member function which can be defaulted
    

    Here are lines 98 and 99 of Map.hpp, respectively:

    Map(Map&&) = default;
    Map& operator = (Map&&) = default;
    

    Are you able to provide some insight into why I'm getting these errors? Thank you!

    opened by MrHallows 10
  • Linker errors when installing

    Linker errors when installing

    Hey, I'm trying to install tmxlite but I'm not that experienced with adding multiple libraries to a project and making them all work together.

    I added the tmxlite include to the Additional Include Directories, the "Debug Static" folder from the binaries to the Additional Library Directories and listed the libtmxlite-s-d.lib under additional dependencies.

    I also added all the SFML Directories in the same way I usually add them to a project ( linked against the static debug libraries ).

    I made a solution with a new project, added the main.cpp and SFMLOrthogonalLayer.hpp from the SFML example folder and tried to compile it.

    However when I try to do that I get a bunch of linking errors, one of which I found especially suspicious : Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in main.obj TmxLite

    I tried changing the runtime library under code generation to MD_d but then I get it the other way around ! Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj

    Do you have any idea how I could solve this ? I think this might be the result of me linking the wrong kind of SFML/tmxlite files together but both the SFML libraries I linked and the tmxlite ones are static libraries. Any ideas what's going on ?

    opened by fishyperil 9
  • Add meson build scripts

    Add meson build scripts

    This should be pretty equivalent to the existing cmake files. Configuring is done normally as meson setup <path_to_tmxlite_source>, which will default to a release build, or passing -Dbuildtype=debug for a debug build. Other options are in meson_options.txt and are the same as the cmake ones, just lower case to match meson's style.

    With this change tmxlite can be easily used as a subproject from other meson projects, ie: subproject('tmxlite')

    opened by KingDuckZ 7
  • LNK 2019 error unresolved external symbol

    LNK 2019 error unresolved external symbol

    I am trying to use tmxlite for the first time and I keep getting this error:

    LNK2019 unresolved external symbol _mz_inflateInit referenced in function "bool __cdecl tmx::decompress(char const *,class std::vector<unsigned char,class std::allocator > &,int,int)" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@[email protected])

    I'm using Visual Studio 2017.

    I am using the SFML example from the download:

    #include <SFML/Graphics/RenderWindow.hpp>
    #include <SFML/Window/Event.hpp>
    
    #include <tmxlite/Map.hpp>
    
    #include "SFMLOrthogonalLayer.hpp"
    
    int main()
    {
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    
        tmx::Map map;
        map.load("assets/demo.tmx");
    
        MapLayer layerZero(map, 0);
        MapLayer layerOne(map, 1);
        MapLayer layerTwo(map, 2);
    
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }
    
            window.clear(sf::Color::Black);
            window.draw(layerZero);
            window.draw(layerOne);
            window.draw(layerTwo);
            window.display();
        }
    
        return 0;
    }
    

    Can you explain a bit more in detail how to get it up and running with VS Community 2017?

    opened by andrewr1991 6
  • Crash on object layer load

    Crash on object layer load

    Whenever I try to load any map, it crashes with the following error on Map map; map.load("map.tmx");: Unhandled exception at 0x749B08B2 in tmx.exe: Microsoft C++ exception: std::out_of_range at memory location 0x00739550. occurred Map loads and renders fine in the older sfml-tmxloader library. Running Visual Studio 2017 15.4.2 on Windows 10. Tried both using the pre-compiled binaries, compiled my own and included the source code directly, all crashes.

    bug 
    opened by kraxarn 6
  • Tilesets not loading tiles

    Tilesets not loading tiles

    I'm trying to parse a map using tmxlite, and I'm having trouble with tilesets. This is my code:

    const auto &tilesets = map.getTilesets();
    for(const auto &tileset : tilesets)
    {
        this->TilesetDump(tileset);
    }
    
    
    void Parser::TilesetDump(const tmx::Tileset tileset)
    {
        std::vector<tmx::Tileset::Tile> tiles = tileset.getTiles();
    
        std::cout << "    Tileset: " << tileset.getName() << std::endl;
        std::cout << "        Tile count: " << (unsigned)tileset.getTileCount() << std::endl;
        std::cout << "        Tile count 2: " << (unsigned)tiles.size() << std::endl;
        std::cout << "        Image path: " << tileset.getImagePath() << std::endl;
        std::cout << "        First GID: " << (unsigned)tileset.getFirstGID() << std::endl;
        std::cout << "        Last GID: " << (unsigned)tileset.getLastGID() << std::endl;
    }
    

    This is the output:

        Tileset: greendale_interior
            Tile count: 0
            Tile count 2: 0
            Image path: /home/tim/projects/hawkthorne-journey/src/images/tilesets/greendale-interior.png
            First GID: 1
    test-program: /home/tim/the-seed/projects/tmxlite/tmxlite/src/Tileset.cpp:229: uint32_t tmx::Tileset::getLastGID() const: Assertion `!m_tiles.empty()' failed.
    Aborted
    

    The image path is correct but for some reason I can't access the tiles. Is there something I need to do manually to load the image?

    opened by timschwartz 5
  • New properties constructor + property map

    New properties constructor + property map

    Two more proposals related to properties ^^

    1. In the map.tmx, properties are in a std::vector but a real use case is a std::map<std::string, tmx::Property> (access by name). Is it possible to de something like that ? Should eventually manage the duplicate, but that's the only edge case I see.

    2. Property do not has a constructor from C++ type. For my personal use for example, I store a map for property with default values but I must use workaround with a std::variant because Property can only be constructed from xml, I just replicate Property but with modiable content. Is it possible to support construction from float, int, std::string, etc ?

    Thanks!

    opened by Eren121 5
  • Crashes loading tmx files from version 1.4.0

    Crashes loading tmx files from version 1.4.0

    Worked perfectly with the same tmx file from version 1.3.x but crashes when saved with 1.4.0.

    if (name == "tileset") { m_tilesets.emplace_back(m_workingDirectory); m_tilesets.back().parse(node, this); }

    It crashes in the parse function.

    opened by ralf-zenker 5
  • Add support for <group> layer tags

    Add support for layer tags

    This is a start for supporting the <group> tag added in version 1.0 of the TMX format. Let me know if my approach here doesn't make sense, or if I'm missing something major.

    I ran the parse test and it seems to still be working, but I would like to update it to include nested layers within layer groups to make sure everything is functioning.

    opened by Grant1219 5
  • better support for SFML on Android

    better support for SFML on Android

    Hi,

    This commit enables compiling with android NDKs older than 13b, since the need for c++14 was removed altogether ("make_unique< T >" replaced with "unique_ptr< T >(new T())" whis is the same acc. to http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique ), this is advantageous because you (or, at least me) currently cannot reliably compile working SFML binaries in a real-life project with any NDK > 10 with compiler set to 14 (c++14 can cause many strange effects when mixed with old C/CPP code and/or dependencies, sometimes).

    The rendering of tiles in the SFMLOrthogonalLayer.hpp example on android didn't work, due to use of the vertex type "Quad" (which Androids OpenGL can't handle), and has been fixed by replacing Quads with two Triangles everywhere (see https://github.com/SFML/SFML/issues/1336#issuecomment-354653915).

    The logger has been extended to now also log to Androids logging facility.

    "m_chunkSize" in the SFMLOrthogonalLayer.hpp example has been increased to 4096x4096 since this results in no rendering errors (empirically tested, no explanation).

    BTW: opening tmx files directly from the "assets" virtual directory on Android does not work - you will need to load them from external media using absolute paths instead (or temporarily copy the files from "assets" to the local cache folder using JNI at runtime, and open them from there, once they reside in a proper file system).

    have fun!

    opened by DennisSc 5
  • Compiler error on SFMLOrthogonalLayer.hpp

    Compiler error on SFMLOrthogonalLayer.hpp

    Is it just me or is anyone else experiencing this issue? I'm on VS 19 Community Edition.

    Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
    Error (active)	E0349	no operator "==" matches these operands	tmxlite_test	C:\Users\Rohan\source\repos\tmxlite_test\MapLayer.h	141
    operand types are: const tmx::Tileset::Tile::Animation::Frame == tmx::Tileset::Tile::Animation::Frame
    
    
    Severity	Code	Description	Project	File	Line	Suppression State
    Error	C2678	binary '==': no operator found which takes a left-hand operand of type 'const tmx::Tileset::Tile::Animation::Frame' (or there is no acceptable conversion)	tmxlite_test	C:\Users\rohanharikr\source\repos\tmxlite_test\MapLayer.h	141	
    
    
    opened by rohanharikr 4
  • Allow to use external miniz & pugixml

    Allow to use external miniz & pugixml

    It would be nice to be able to use externally installed miniz & pugixml, vendoring is bad for package managers (ODR violation).

    • Move miniz & pugixml files in specific folders (vendor/miniz & vendor/pugixml for example)
    • edit most cpp files with #include <pugixml.hpp> instead of #include "detail/pugixml.hpp" (this modification is tedious for package managers)
    • Add 2 options in Meson & CMake files, like TMXLLITE_EXTERNAL_MINIZ and TMXLLITE_EXTERNAL_PUGIXML
    • Depending on option values, inject vendored deps or find & inject external deps.
    enhancement Library 
    opened by SpaceIm 1
  • Add improved file loading API (feedback wanted)

    Add improved file loading API (feedback wanted)

    By default tmxlite uses fstream to open tmx files. As noted in #76 this does not work on android, the current work-around being loading the entire file into a string and passing to Map::loadFromString().

    In #80 it is also noted that there is currently no support for zstd compressed maps as this requires including external dependencies.

    The idea then is to create an API for tmxlite which allows a user to define a file loading mechanism of their choice. tmxlite itself could include file loading functions for android, for example, as well as optional file loaders for zstd and other potential sources such as PhysFS.

    If anyone has any feedback on this idea, or ideas for API design, please comment! The current thinking would be similar to that of SFML's InputStream.

    enhancement help wanted Library 
    opened by fallahn 0
  • zstd compression is not supported

    zstd compression is not supported

    As mentioned in #70 from version 1.4.0 Tiled introduces zstd compression as an option for base64 encoded maps. tmxlite currently doesn't support the compression format as it cannot be decompressed by miniz.

    The current fix is to switch the format of Tiled maps from zstd compression to zlib compression.

    bug Library 
    opened by fallahn 0
Releases(v1.3.1)
Owner
Matt Styles
Bald.
Matt Styles
This Repository is created to help fellow coders learn open source contributions. This Repository is created for Hacktoberfest 2021

Hacktoberfest 2021 Follow the README below to get started! This Repository is created to help fellow coders learn open source contributions This Repos

Somesh Debnath 7 Apr 26, 2022
Just a basic mini library for parsing simple files that only have variables written and with Lua extension.

C++ Parser Lua file config Just a basic mini library for parsing simple files that only have variables written and with Lua extension. Note: At the mo

Marcos Oliveira 3 Dec 26, 2021
A fantasy map generator based on Martin O'Leary's "Generating fantasy map" notes

Fantasy Map Generator This program is an implementation of a fantasy map generator written in C++ based on the methods described in Martin O'Leary's "

Ryan Guy 613 Jul 31, 2022
Jaws is an invisible programming language! Inject invisible code into other languages and files! Created for security research -- see blog post

Jaws is an invisible interpreted programming language that was created for antivirus research. Since Jaws code is composed entirely of whitespace char

C.J. May 207 Jul 30, 2022
Library of useful C++ snippets and reusable classes I've created as I build out Arduino Uno and ESP32 projects.

Arduino Snippets Library of useful C++ snippets and reusable classes I've created as I build out Arduino Uno and ESP32 projects. Button A simple butto

Max Lynch 7 Feb 5, 2022
Repository created to store a C function library to use in 42 School

Libft of 42. Make with ❤︎ for Luiz Cezario ?? Index What's this Repo? List of Functions Technologies How to Run Find a Bug? Or somenthing need to chan

Luiz lima cezario 8 Feb 20, 2022
ApeX is a static library for C++ software. Originally it was created to make C++ studying easier,

ApeX is a static library for C++ software. Originally it was created to make C++ studying easier, so it has functions to complete common tasks with just one line of code. But who knows, maybe this library will get bigger some day

null 0 Jan 18, 2022
This program converts ASCII STL files to RT files for miniRT.

STL to RT This program converts ASCII STL files to RT files for miniRT. Input the ASCII STL file to the standard input and output the RT file from the

null 5 Mar 29, 2021
Use DOS object files (OMF) as patch files

omfpatch - Use Intel/Microsoft .OBJ files as binary diffs Overview This tool makes it possible to use MASM / TASM / JWasm / nasm as tool to write patc

Michael Karcher 2 Jan 30, 2022
Creates 3D lithophanes from image files, exports them to stl files, ready for slicing and 3D printing.

LithoMaker Creates 3D lithophanes from PNG image files and exports them to STL files, ready for slicing and 3D printing. Download the latest release h

Lars Muldjord 13 Jun 29, 2022
Parsing Expression Grammar Template Library

Welcome to the PEGTL The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++ header-only parser combinator library for creati

The Art of C++ 1.6k Aug 8, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

e_t 7 Apr 14, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

e_t 7 Apr 14, 2022
An 802.11 Frame Generation and Parsing Library in C

libwifi 802.11 Parsing / Generation library Build Status OS Architecture Linux x86_64 What is this? libwifi is a C library with a permissive license f

null 29 Aug 8, 2022
ZSV/lib: a fast CSV parsing library and standalone utility

Please note: this code is still alpha / pre-production. Everything here should be considered preliminary. If you like ZSVlib, please give it a star! Z

null 64 Jul 9, 2022
A C/C++ library for parsing and evaluation of arithmetic expressions.

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. Functions accessibe from main() Function Argument(s) Return Value ceval_res

e_t 4 Jul 20, 2022
This project contains a library for C++ AST parsing, metaprogramming and reflection

Meta C++ This project contains a library for C++ AST parsing, metaprogramming and reflection. Also included is a tool for generating the necessary met

Keith Hammond 75 Jun 26, 2022
A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API

Wall-E-Sim A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API This is a simuation of SRA's Wall-E bo

Anushree Sabnis 19 Jul 3, 2022
It is a basic calculator created by me in Pure C++

Basic-Calculator It is a basic calculator created by me in C++ If you find any bug then let me know How to use: 1. Enter first value it ask 2. Enter s

ryan 2 Dec 21, 2021