From 3f8d0d5d2e0fb15b261149b526c54f3d6d707470 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 5 Dec 2018 23:17:54 +1100 Subject: [PATCH] Added CMake build. Code changes to support Linux. Updated documentation & README.md, which were sorely out of date. Updated copyrights. *yawn* --- CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 33 ++++++++++++++++++++++++--------- inc/XGetopt.h | 1 - src/XGetopt.cpp | 7 ------- src/base64.cpp | 4 ++-- src/tmx2gba.cpp | 22 ++++++++++++++++++---- src/tmxreader.h | 2 +- 7 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bd714db --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +# tmx2gba - CMakeLists.txt +# Copyright (C) 2018 Nicholas Curtis (a dinosaur) +# +# 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. + +cmake_minimum_required(VERSION 3.10) +project(tmx2gba) + +set(CMAKE_CXX_STANDARD 11) + +include_directories(inc) +set(SOURCES + src/tmx2gba.cpp + src/tmxlayer.cpp src/tmxlayer.h + src/tmxobject.cpp src/tmxobject.h + src/tmxreader.cpp src/tmxreader.h + src/tmxtileset.cpp src/tmxtileset.h + + src/base64.cpp inc/base64.h + inc/miniz.h + + inc/rapidxml/rapidxml.hpp + inc/rapidxml/rapidxml_iterators.hpp + inc/rapidxml/rapidxml_print.hpp + inc/rapidxml/rapidxml_utils.hpp) + +if (MSVC) + set(SOURCES ${SOURCES} src/XGetopt.cpp inc/XGetopt.h) +endif() + +add_executable(tmx2gba ${SOURCES}) diff --git a/README.md b/README.md index 5486d37..71bb795 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # tmx2gba # -tmx2gba is a simple command line utility that converts Tiled (http://www.mapeditor.org/) .tmx maps to Game Boy Advance compatible charmaps. -Originally developed for my own personal use, I've thrown it up on glorious Github in case this is of use to anyone else. +tmx2gba is a simple command line utility that converts [Tiled](http://www.mapeditor.org/) .tmx maps to Game Boy Advance compatible charmaps. +Originally developed for my own personal use, I've thrown it up on glorious Github/Gitlab/whatever in case this is of use to anyone else. If you find a bug, please open an issue. @@ -18,25 +18,40 @@ tmx2gba [-h] [-r offset] [-lyc name] [-p 0-15] <-i inpath> <-o outpath> ``` Command | Required | Notes -------------|----------|------------------------------------------------------------- +------------|----------|---------------------------------------------------------------------- -h | N/A | Display help & command info. -l (name) | No | Name of layer to use (default first layer in TMX). -y (name) | No | Layer for palette mappings. -c (name) | No | Output a separate 8bit collision map of the specified layer. -r (offset) | No | Offset tile indices (default 0). -p (0-15) | No | Select which palette to use for 4-bit tilesets. +-m (name;id)| No | Map an object name to an ID, will enable object exports. -i (path) | *Yes* | Path to input TMX file. -o (path) | *Yes* | Path to output files. +-f | No | Command line instructions list for easy integration with buildscripts + +### How do I build it? ### + +Dependencies for building are CMake 3.x and a C++11 compliant compiler, +all other dependencies are in-tree so you should be able to build with: +```bash +mkdir build && cd build +cmake .. +make +``` + +Optionally, to make it convenient for my dkp projects: +```bash +sudo cp tmx2gba $DEVKITPRO/tools/bin/tmx2gba +``` ### Todo list ### * Add support for multi-SBB prepared charmaps. -* Test on & write Makefile for Linux. -* Export to C/ASM with width/height info. +* Test CMakeLists for Windows compatibility. * Check if this works for NDS as well. -* Implement some kind of grit-style parameters file for easy integration into buildscripts. -* Revamp command line arguments. * Compression support. -* Refactor & Fix bugs. +* Prehaps use GNU style getopt_long? +* Refactor & Fix bugs. *(duh)* ### License ### tmx2gba is licensed under the zlib license. @@ -45,7 +60,7 @@ René Nyffenegger's base64.cpp is licensed under the zlib license. XGetopt & miniz are both public domain software. ``` - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015-2018 Nicholas Curtis (a dinosaur) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/inc/XGetopt.h b/inc/XGetopt.h index 64eb376..3a64486 100644 --- a/inc/XGetopt.h +++ b/inc/XGetopt.h @@ -18,7 +18,6 @@ extern int optind; extern char *optarg, *next; -void getoptClear (); int getopt(int argc, char *argv[], char *optstring); #endif //XGETOPT_H diff --git a/src/XGetopt.cpp b/src/XGetopt.cpp index 092f7c2..aeee4a7 100644 --- a/src/XGetopt.cpp +++ b/src/XGetopt.cpp @@ -149,13 +149,6 @@ char *optarg; // global argument pointer char *next; int optind = 0; // global argv index -void getoptClear () -{ - optarg = nullptr; - next = nullptr; - optind = 0; -} - int getopt(int argc, char *argv[], char *optstring) { if (optind == 0) diff --git a/src/base64.cpp b/src/base64.cpp index 56b9225..2a863d1 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -1,7 +1,7 @@ /* base64.cpp and base64.h - Copyright (C) 2004-2008 René Nyffenegger + Copyright (C) 2004-2008 René Nyffenegger This source code is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages @@ -21,7 +21,7 @@ 3. This notice may not be removed or altered from any source distribution. - René Nyffenegger rene.nyffenegger@adp-gmbh.ch + René Nyffenegger rene.nyffenegger@adp-gmbh.ch */ diff --git a/src/tmx2gba.cpp b/src/tmx2gba.cpp index dd42596..bc5f1d9 100644 --- a/src/tmx2gba.cpp +++ b/src/tmx2gba.cpp @@ -1,6 +1,6 @@ /* tmx2gba.cpp - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015-2018 Nicholas Curtis (a dinosaur) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -31,7 +31,12 @@ #include #include #include -#include + +#ifdef _MSC_VER + #include +#else + #include +#endif using std::cout; using std::cerr; @@ -58,7 +63,7 @@ static const string g_strHelpFull = R"( -m -- Map an object name to an ID, will enable object exports. -i ----- Path to input TMX file. -o ----- Path to output files. --f ----- Specify a file to use for flags, will override any options specified in the cmd line.)"; +-f ----- Specify a file to use for flags, will override any options specified on the command line.)"; struct SParams { @@ -72,10 +77,19 @@ struct SParams bool objExport = false; }; +void GetoptClear () +{ + optarg = nullptr; + optind = 0; +#ifdef _MSC_VER + next = nullptr; +#endif +} + void ParseArgs ( int argc, char** argv, SParams* params ) { char cOption; - getoptClear (); + GetoptClear (); while ( ( cOption = (char)getopt ( argc, argv, "hr:l:c:p:y:m:i:o:f:" ) ) > 0 ) { switch ( cOption ) diff --git a/src/tmxreader.h b/src/tmxreader.h index 5054695..f5c8d9a 100644 --- a/src/tmxreader.h +++ b/src/tmxreader.h @@ -5,11 +5,11 @@ #include #include #include +#include class CTmxTileset; class CTmxLayer; class CTmxObject; -namespace rapidxml { template class xml_node; } class CTmxReader {