mirror of
https://github.com/ScrelliCopter/tmx2gba.git
synced 2025-02-21 03:29:25 +11:00
Compare commits
11 Commits
57455e0b73
...
github-tra
| Author | SHA1 | Date | |
|---|---|---|---|
| b9c56ce5a7 | |||
| 0b635ebe87 | |||
| 5d5dda81c9 | |||
| 417bc11fae | |||
| 696057b5e6 | |||
| 17de8ac3ec | |||
| db1de4ba8e | |||
| f4930668ee | |||
| 5e466598ea | |||
| e2a69bf433 | |||
| d59fb39857 |
48
.github/workflows/cmake.yml
vendored
48
.github/workflows/cmake.yml
vendored
@@ -2,36 +2,46 @@ name: CMake
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "master" ]
|
branches: [ "master" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
ARTIFACT_NAME: tmx2gba
|
||||||
BUILD_TYPE: Release
|
BUILD_TYPE: RelWithDebInfo
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
|
strategy:
|
||||||
# You can convert this to a matrix build if you need cross-platform coverage.
|
matrix:
|
||||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
|
config:
|
||||||
runs-on: ubuntu-latest
|
- { name: "MacOS 13.0 Universal", os: macos-13, artifact: macos-universal, arch: arm64;x86_64 }
|
||||||
|
- { name: "Windows MSVC x86", os: windows-latest, artifact: windows-x86, arch: x86 }
|
||||||
|
- { name: "Windows MSVC x64", os: windows-latest, artifact: windows-x64 }
|
||||||
|
- { name: "Windows MSVC ARM64", os: windows-latest, artifact: windows-arm64, arch: amd64_arm64 }
|
||||||
|
- { name: "Ubuntu", artifact: "linux", os: ubuntu-latest }
|
||||||
|
runs-on: ${{matrix.config.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
# Since ninja isn't used it will take less time if this step is skipped
|
||||||
|
- uses: lukka/get-cmake@latest
|
||||||
|
if: ${{!startsWith(matrix.config.os, 'windows')}}
|
||||||
|
- uses: TheMrMilchmann/setup-msvc-dev@v3
|
||||||
|
if: ${{startsWith(matrix.config.os, 'windows')}}
|
||||||
|
with:
|
||||||
|
arch: ${{matrix.config.arch && matrix.config.arch || 'x64'}}
|
||||||
|
|
||||||
- name: Configure CMake
|
- name: Configure CMake
|
||||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
|
run: >-
|
||||||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
|
cmake -B build
|
||||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
-G "${{startsWith(matrix.config.os, 'windows') && 'NMake Makefiles' || 'Ninja'}}"
|
||||||
|
${{(startsWith(matrix.config.os, 'macos') && matrix.config.arch) && format('-DCMAKE_OSX_ARCHITECTURES="{0}"', matrix.config.arch) || ''}}
|
||||||
|
${{matrix.config.extra}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
# Build your program with the given configuration
|
run: cmake --build build --config ${{env.BUILD_TYPE}}
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
working-directory: ${{github.workspace}}/build
|
|
||||||
# Execute tests defined by the CMake configuration.
|
|
||||||
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
|
|
||||||
run: ctest -C ${{env.BUILD_TYPE}}
|
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{env.ARTIFACT_NAME}}-${{matrix.config.artifact}}
|
||||||
|
path: build/src/${{env.ARTIFACT_NAME}}${{startsWith(matrix.config.os, 'windows') && '.exe' || ''}}
|
||||||
|
|||||||
15
.gitignore
vendored
15
.gitignore
vendored
@@ -1,23 +1,13 @@
|
|||||||
# Compiled Object files
|
# Compiled Object files
|
||||||
*.slo
|
|
||||||
*.lo
|
|
||||||
*.o
|
*.o
|
||||||
*.obj
|
*.obj
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Compiled Dynamic libraries
|
# Compiled Dynamic libraries
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
*.dll
|
*.dll
|
||||||
|
|
||||||
# Fortran module files
|
|
||||||
*.mod
|
|
||||||
|
|
||||||
# Compiled Static libraries
|
# Compiled Static libraries
|
||||||
*.lai
|
|
||||||
*.la
|
*.la
|
||||||
*.a
|
*.a
|
||||||
*.lib
|
*.lib
|
||||||
@@ -41,6 +31,11 @@ Release/
|
|||||||
# CMake Rubbish
|
# CMake Rubbish
|
||||||
build/
|
build/
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
|
xcode/
|
||||||
|
|
||||||
|
# OS Rubbish
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
# Some files I used for testing
|
# Some files I used for testing
|
||||||
*.tmx
|
*.tmx
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
cmake_minimum_required(VERSION "3.15" FATAL_ERROR)
|
||||||
project(tmx2gba)
|
project(tmx2gba VERSION "0.3")
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
option(TMX2GBA_DKP_INSTALL "Install into DEVKITPRO prefix" OFF)
|
option(TMX2GBA_DKP_INSTALL "Install into DEVKITPRO prefix" OFF)
|
||||||
option(ASAN "Enable address sanitiser" OFF)
|
option(ASAN "Enable address sanitiser" OFF)
|
||||||
|
|
||||||
# C++20 & C99
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
|
||||||
|
|
||||||
# Enable strong warnings
|
|
||||||
if (MSVC)
|
|
||||||
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
||||||
string(REPLACE "/W3" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
|
||||||
else()
|
|
||||||
add_compile_options(-Wall)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (ASAN)
|
if (ASAN)
|
||||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||||
add_link_options(-fsanitize=address -shared-libasan)
|
add_link_options(-fsanitize=address -shared-libasan)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ tmx2gba [-h] [-r offset] [-lyc name] [-p 0-15] <-i inpath> <-o outpath>
|
|||||||
| Command | Required | Notes |
|
| Command | Required | Notes |
|
||||||
|--------------|----------|-----------------------------------------------------------------------|
|
|--------------|----------|-----------------------------------------------------------------------|
|
||||||
| -h | N/A | Display help & command info. |
|
| -h | N/A | Display help & command info. |
|
||||||
|
| -v | No | Display version & quit. |
|
||||||
| -l (name) | No | Name of layer to use (default first layer in TMX). |
|
| -l (name) | No | Name of layer to use (default first layer in TMX). |
|
||||||
| -y (name) | No | Layer for palette mappings. |
|
| -y (name) | No | Layer for palette mappings. |
|
||||||
| -c (name) | No | Output a separate 8bit collision map of the specified layer. |
|
| -c (name) | No | Output a separate 8bit collision map of the specified layer. |
|
||||||
|
|||||||
@@ -4,8 +4,21 @@ add_executable(tmx2gba
|
|||||||
tmxobject.hpp
|
tmxobject.hpp
|
||||||
tmxreader.hpp tmxreader.cpp
|
tmxreader.hpp tmxreader.cpp
|
||||||
tmxtileset.hpp
|
tmxtileset.hpp
|
||||||
|
swriter.hpp swriter.cpp
|
||||||
|
headerwriter.hpp headerwriter.cpp
|
||||||
tmx2gba.cpp)
|
tmx2gba.cpp)
|
||||||
|
|
||||||
|
set_target_properties(tmx2gba PROPERTIES
|
||||||
|
# C++20 & C99
|
||||||
|
CXX_STANDARD 20
|
||||||
|
C_STANDARD 99)
|
||||||
|
|
||||||
|
# Enable strong warnings
|
||||||
|
target_compile_options(tmx2gba PRIVATE
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/Wall>
|
||||||
|
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall -Wextra -pedantic>
|
||||||
|
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Weverything -Wno-c++98-compat>)
|
||||||
|
|
||||||
target_link_libraries(tmx2gba
|
target_link_libraries(tmx2gba
|
||||||
External::base64
|
External::base64
|
||||||
External::miniz
|
External::miniz
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/* argparse.cpp - Copyright (C) 2024 a dinosaur (zlib, see COPYING.txt) */
|
/* argparse.cpp - Copyright (C) 2024 a dinosaur (zlib, see COPYING.txt) */
|
||||||
|
|
||||||
#include "argparse.hpp"
|
#include "argparse.hpp"
|
||||||
#include <iomanip>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +207,7 @@ bool ArgParse::ReadParamFile(std::vector<std::string>& tokens, std::istream& fil
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
quoteStr.push_back(c);
|
quoteStr.push_back(static_cast<char>(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,18 +16,18 @@ namespace ArgParse
|
|||||||
{
|
{
|
||||||
struct Option
|
struct Option
|
||||||
{
|
{
|
||||||
char flag;
|
|
||||||
bool required;
|
|
||||||
const char* argumentName;
|
const char* argumentName;
|
||||||
const char* helpString;
|
const char* helpString;
|
||||||
|
char flag;
|
||||||
|
bool required;
|
||||||
|
|
||||||
static constexpr Option Optional(char flag, const char* name, const char* help)
|
static constexpr Option Optional(char flag, const char* name, const char* help)
|
||||||
{
|
{
|
||||||
return { flag, false, name, help };
|
return { name, help, flag, false };
|
||||||
}
|
}
|
||||||
static constexpr Option Required(char flag, const char* name, const char* help)
|
static constexpr Option Required(char flag, const char* name, const char* help)
|
||||||
{
|
{
|
||||||
return { flag, true, name, help };
|
return { name, help, flag, false };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,8 +35,7 @@ namespace ArgParse
|
|||||||
{
|
{
|
||||||
const std::vector<Option> options;
|
const std::vector<Option> options;
|
||||||
|
|
||||||
inline constexpr Options(const std::initializer_list<Option>&& rhs)
|
inline Options(const std::initializer_list<Option>&& rhs) : options(rhs) {}
|
||||||
: options(std::move(rhs)) {}
|
|
||||||
|
|
||||||
void ShowShortUsage(const std::string_view name, std::ostream& out) const;
|
void ShowShortUsage(const std::string_view name, std::ostream& out) const;
|
||||||
void ShowHelpUsage(const std::string_view name, std::ostream& out) const;
|
void ShowHelpUsage(const std::string_view name, std::ostream& out) const;
|
||||||
@@ -67,10 +66,10 @@ namespace ArgParse
|
|||||||
|
|
||||||
class ParserState
|
class ParserState
|
||||||
{
|
{
|
||||||
bool expectArg = false;
|
|
||||||
int flagChar;
|
|
||||||
HandleOption handler;
|
HandleOption handler;
|
||||||
const Options& options;
|
const Options& options;
|
||||||
|
int flagChar;
|
||||||
|
bool expectArg = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParserState(HandleOption handler, const Options& options) noexcept
|
ParserState(HandleOption handler, const Options& options) noexcept
|
||||||
@@ -99,7 +98,7 @@ namespace ArgParse
|
|||||||
ParserState state(handler, options);
|
ParserState state(handler, options);
|
||||||
for (auto arg : args)
|
for (auto arg : args)
|
||||||
{
|
{
|
||||||
ParseErr err;
|
ParseErr err = ParseErr::UNEXPECTED;
|
||||||
switch (state.Next(arg))
|
switch (state.Next(arg))
|
||||||
{
|
{
|
||||||
case ParseCtrl::CONTINUE: continue;
|
case ParseCtrl::CONTINUE: continue;
|
||||||
|
|||||||
93
src/headerwriter.cpp
Normal file
93
src/headerwriter.cpp
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/* headerwriter.cpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
|
||||||
|
|
||||||
|
#include "headerwriter.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T> static constexpr std::string_view DatType();
|
||||||
|
template <> constexpr std::string_view DatType<uint8_t>() { return "unsigned char"; }
|
||||||
|
template <> constexpr std::string_view DatType<uint16_t>() { return "unsigned short"; }
|
||||||
|
template <> constexpr std::string_view DatType<uint32_t>() { return "unsigned int"; }
|
||||||
|
|
||||||
|
void HeaderWriter::WriteSize(int width, int height)
|
||||||
|
{
|
||||||
|
stream << std::endl;
|
||||||
|
WriteDefine(mName + "Width", width);
|
||||||
|
WriteDefine(mName + "Height", height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteCharacterMap(const std::span<uint16_t> charData)
|
||||||
|
{
|
||||||
|
stream << std::endl;
|
||||||
|
WriteDefine(mName + "TilesLen", charData.size() * 2);
|
||||||
|
WriteSymbol(mName + "Tiles", DatType<uint16_t>(), charData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteCollision(const std::span<uint8_t> collisionData)
|
||||||
|
{
|
||||||
|
stream << std::endl;
|
||||||
|
WriteDefine(mName + "CollisionLen", collisionData.size());
|
||||||
|
WriteSymbol(mName + "Collision", DatType<uint8_t>(), collisionData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteObjects(const std::span<uint32_t> objData)
|
||||||
|
{
|
||||||
|
stream << std::endl;
|
||||||
|
WriteDefine(mName + "ObjCount", objData.size() / 3);
|
||||||
|
WriteDefine(mName + "ObjdatLen", objData.size() * sizeof(int));
|
||||||
|
WriteSymbol(mName + "Objdat", DatType<uint32_t>(), objData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static std::string GuardName(const std::string_view name)
|
||||||
|
{
|
||||||
|
auto upper = std::string(name);
|
||||||
|
for (auto& c: upper)
|
||||||
|
c = static_cast<char>(toupper(c));
|
||||||
|
return "TMX2GBA_" + upper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HeaderWriter::WriteGuardStart()
|
||||||
|
{
|
||||||
|
const std::string guard = GuardName(mName);
|
||||||
|
stream << "#ifndef " << guard << std::endl;
|
||||||
|
stream << "#define " << guard << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteGuardEnd()
|
||||||
|
{
|
||||||
|
const std::string guard = GuardName(mName);
|
||||||
|
stream << std::endl << "#endif//" << guard << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HeaderWriter::~HeaderWriter()
|
||||||
|
{
|
||||||
|
if (stream.is_open())
|
||||||
|
{
|
||||||
|
WriteGuardEnd();
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool HeaderWriter::Open(const std::filesystem::path& path, const std::string_view name)
|
||||||
|
{
|
||||||
|
mName = name;
|
||||||
|
stream.open(path);
|
||||||
|
if (!stream.is_open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
WriteGuardStart();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteDefine(const std::string_view name, const std::string_view value)
|
||||||
|
{
|
||||||
|
stream << "#define " << name << " " << value << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HeaderWriter::WriteSymbol(const std::string_view name, const std::string_view type, std::size_t count)
|
||||||
|
{
|
||||||
|
stream << "extern const " << type << " " << name << "[" << count << "];" << std::endl;
|
||||||
|
}
|
||||||
46
src/headerwriter.hpp
Normal file
46
src/headerwriter.hpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/* headerwriter.hpp - Copyright (C) 2015-2024 a dinosaur (zlib, see COPYING.txt) */
|
||||||
|
|
||||||
|
#ifndef HEADERWRITER_HPP
|
||||||
|
#define HEADERWRITER_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <span>
|
||||||
|
#include <concepts>
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept NumericType = std::integral<T> || std::floating_point<T>;
|
||||||
|
|
||||||
|
class HeaderWriter
|
||||||
|
{
|
||||||
|
std::ofstream stream;
|
||||||
|
std::string mName;
|
||||||
|
|
||||||
|
void WriteGuardStart();
|
||||||
|
void WriteGuardEnd();
|
||||||
|
|
||||||
|
public:
|
||||||
|
~HeaderWriter();
|
||||||
|
|
||||||
|
[[nodiscard]] bool Open(const std::filesystem::path& path, const std::string_view name);
|
||||||
|
|
||||||
|
void WriteDefine(const std::string_view name, const std::string_view value);
|
||||||
|
void WriteSymbol(const std::string_view name, const std::string_view type, std::size_t count);
|
||||||
|
|
||||||
|
template <NumericType T>
|
||||||
|
void WriteDefine(const std::string_view name, T value)
|
||||||
|
{
|
||||||
|
WriteDefine(name, std::to_string(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteSize(int width, int height);
|
||||||
|
void WriteCharacterMap(const std::span<uint16_t> charData);
|
||||||
|
void WriteCollision(const std::span<uint8_t> collisionData);
|
||||||
|
void WriteObjects(const std::span<uint32_t> objData);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif//HEADERWRITER_HPP
|
||||||
163
src/swriter.cpp
Normal file
163
src/swriter.cpp
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
/* swwriter.cpp - Copyright (C) 2024 a dinosaur (zlib, see COPYING.txt) */
|
||||||
|
|
||||||
|
#include "swriter.hpp"
|
||||||
|
#include <type_traits>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
#define GNU_STYLE 0
|
||||||
|
#define MASM_STYLE 1
|
||||||
|
|
||||||
|
#define HEX_STYLE GNU_STYLE
|
||||||
|
|
||||||
|
|
||||||
|
static inline constexpr char HexU(uint8_t h) { return "0123456789ABCDEF"[h >> 4]; }
|
||||||
|
static inline constexpr char HexL(uint8_t l) { return "0123456789ABCDEF"[l & 15]; }
|
||||||
|
|
||||||
|
#if HEX_STYLE == GNU_STYLE
|
||||||
|
template <typename T> static void CHex(std::ostream& s, T x);
|
||||||
|
template <> void CHex(std::ostream& s, uint8_t x)
|
||||||
|
{
|
||||||
|
if (x > 9) s << "0x";
|
||||||
|
if (x > 15) s << HexU(x);
|
||||||
|
s << HexL(x);
|
||||||
|
}
|
||||||
|
template <> void CHex(std::ostream& s, uint16_t x)
|
||||||
|
{
|
||||||
|
if (x > 9) s << "0x";
|
||||||
|
if (x > 4095) s << HexU(static_cast<uint8_t>(x >> 8));
|
||||||
|
if (x > 255) s << HexL(static_cast<uint8_t>(x >> 8));
|
||||||
|
if (x > 15) s << HexU(static_cast<uint8_t>(x));
|
||||||
|
s << HexL(static_cast<uint8_t>(x));
|
||||||
|
}
|
||||||
|
template <> void CHex(std::ostream& s, uint32_t x)
|
||||||
|
{
|
||||||
|
if (x > 9) s << "0x";
|
||||||
|
if (x > 0xFFFFFFF) s << HexU(static_cast<uint8_t>(x >> 24));
|
||||||
|
if (x > 0xFFFFFF) s << HexL(static_cast<uint8_t>(x >> 24));
|
||||||
|
if (x > 0xFFFFF) s << HexU(static_cast<uint8_t>(x >> 16));
|
||||||
|
if (x > 65535) s << HexL(static_cast<uint8_t>(x >> 16));
|
||||||
|
if (x > 4095) s << HexU(static_cast<uint8_t>(x >> 8));
|
||||||
|
if (x > 255) s << HexL(static_cast<uint8_t>(x >> 8));
|
||||||
|
if (x > 15) s << HexU(static_cast<uint8_t>(x));
|
||||||
|
s << HexL(static_cast<uint8_t>(x));
|
||||||
|
}
|
||||||
|
#elif HEX_STYLE == MASM_STYLE
|
||||||
|
template <typename T> static void MHex(std::ostream& s, T x);
|
||||||
|
template <> void MHex(std::ostream& s, uint8_t x)
|
||||||
|
{
|
||||||
|
if (x > 159) s << "0";
|
||||||
|
if (x > 15) s << HexU(x); else if (x > 9) s << "0";
|
||||||
|
s << HexL(x);
|
||||||
|
if (x > 9) s << "h";
|
||||||
|
}
|
||||||
|
template <> void MHex(std::ostream& s, uint16_t x)
|
||||||
|
{
|
||||||
|
if (x > 40959) s << "0";
|
||||||
|
if (x > 4095) s << HexU(static_cast<uint8_t>(x >> 8)); else if (x > 2559) s << "0";
|
||||||
|
if (x > 255) s << HexL(static_cast<uint8_t>(x >> 8)); else if (x > 159) s << "0";
|
||||||
|
if (x > 15) s << HexU(static_cast<uint8_t>(x)); else if (x > 9) s << "0";
|
||||||
|
s << HexL(static_cast<uint8_t>(x));
|
||||||
|
if (x > 9) s << "h";
|
||||||
|
}
|
||||||
|
template <> void MHex(std::ostream& s, uint32_t x)
|
||||||
|
{
|
||||||
|
if (x > 0x9FFFFFFF) s << "0";
|
||||||
|
if (x > 0xFFFFFFF) s << HexU(static_cast<uint8_t>(x >> 24)); else if (x > 0x9FFFFFF) s << "0";
|
||||||
|
if (x > 0xFFFFFF) s << HexL(static_cast<uint8_t>(x >> 24)); else if (x > 0x9FFFFF) s << "0";
|
||||||
|
if (x > 0xFFFFF) s << HexU(static_cast<uint8_t>(x >> 16)); else if (x > 655359) s << "0";
|
||||||
|
if (x > 65535) s << HexL(static_cast<uint8_t>(x >> 16)); else if (x > 40959) s << "0";
|
||||||
|
if (x > 4095) s << HexU(static_cast<uint8_t>(x >> 8)); else if (x > 2559) s << "0";
|
||||||
|
if (x > 255) s << HexL(static_cast<uint8_t>(x >> 8)); else if (x > 159) s << "0";
|
||||||
|
if (x > 15) s << HexU(static_cast<uint8_t>(x)); else if (x > 9) s << "0";
|
||||||
|
s << HexL(static_cast<uint8_t>(x));
|
||||||
|
if (x > 9) s << "h";
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# error "Unknown hex style"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T> static constexpr const std::string_view DataType();
|
||||||
|
template <> constexpr const std::string_view DataType<uint8_t>() { return ".byte"; }
|
||||||
|
template <> constexpr const std::string_view DataType<uint16_t>() { return ".hword"; }
|
||||||
|
template <> constexpr const std::string_view DataType<uint32_t>() { return ".word"; }
|
||||||
|
|
||||||
|
template <typename I>
|
||||||
|
static void WriteArrayDetail(std::ostream& s, const I beg, const I end, int perCol)
|
||||||
|
{
|
||||||
|
typedef typename std::iterator_traits<I>::value_type Element;
|
||||||
|
|
||||||
|
int col = 0;
|
||||||
|
for (auto it = beg;;)
|
||||||
|
{
|
||||||
|
if (col == 0)
|
||||||
|
s << "\t" << DataType<Element>() << " ";
|
||||||
|
|
||||||
|
const Element e = *it;
|
||||||
|
#if HEX_STYLE == MASM_STYLE
|
||||||
|
MHex(s, e);
|
||||||
|
#elif HEX_STYLE == GNU_STYLE
|
||||||
|
CHex(s, e);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (++it == end)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (++col < perCol)
|
||||||
|
{
|
||||||
|
s << ",";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s << std::endl;
|
||||||
|
col = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SWriter::WriteSymbol(const std::string_view suffix)
|
||||||
|
{
|
||||||
|
if (writes++ != 0)
|
||||||
|
stream << std::endl;
|
||||||
|
stream << "\t.section .rodata" << std::endl;
|
||||||
|
stream << "\t.align 2" << std::endl;
|
||||||
|
stream << "\t.global " << mName << suffix << std::endl;
|
||||||
|
stream << "\t.hidden " << mName << suffix << std::endl;
|
||||||
|
stream << mName << suffix << ":" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SWriter::WriteArray(const std::string_view suffix, std::span<uint8_t> data, int numCols)
|
||||||
|
{
|
||||||
|
WriteSymbol(suffix);
|
||||||
|
WriteArrayDetail(stream, data.begin(), data.end(), numCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SWriter::WriteArray(const std::string_view suffix, std::span<uint16_t> data, int numCols)
|
||||||
|
{
|
||||||
|
WriteSymbol(suffix);
|
||||||
|
WriteArrayDetail(stream, data.begin(), data.end(), numCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SWriter::WriteArray(const std::string_view suffix, std::span<uint32_t> data, int numCols)
|
||||||
|
{
|
||||||
|
WriteSymbol(suffix);
|
||||||
|
WriteArrayDetail(stream, data.begin(), data.end(), numCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWriter::~SWriter()
|
||||||
|
{
|
||||||
|
if (stream.is_open())
|
||||||
|
{
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SWriter::Open(const std::filesystem::path& path, const std::string_view name)
|
||||||
|
{
|
||||||
|
mName = name;
|
||||||
|
stream.open(path);
|
||||||
|
return stream.is_open();
|
||||||
|
}
|
||||||
32
src/swriter.hpp
Normal file
32
src/swriter.hpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* swwriter.hpp - Copyright (C) 2024 a dinosaur (zlib, see COPYING.txt) */
|
||||||
|
|
||||||
|
#ifndef SWRITER_HPP
|
||||||
|
#define SWRITER_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <span>
|
||||||
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
class SWriter
|
||||||
|
{
|
||||||
|
std::ofstream stream;
|
||||||
|
std::string mName;
|
||||||
|
int writes = 0;
|
||||||
|
|
||||||
|
void WriteSymbol(const std::string_view suffix);
|
||||||
|
|
||||||
|
public:
|
||||||
|
~SWriter();
|
||||||
|
|
||||||
|
bool Open(const std::filesystem::path& path, const std::string_view name);
|
||||||
|
|
||||||
|
void WriteArray(const std::string_view suffix, std::span<uint8_t> data, int numCols = 16);
|
||||||
|
void WriteArray(const std::string_view suffix, std::span<uint16_t> data, int numCols = 16);
|
||||||
|
void WriteArray(const std::string_view suffix, std::span<uint32_t> data, int numCols = 16);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif//SWRITER_HPP
|
||||||
167
src/tmx2gba.cpp
167
src/tmx2gba.cpp
@@ -4,16 +4,18 @@
|
|||||||
#include "tmxreader.hpp"
|
#include "tmxreader.hpp"
|
||||||
#include "tmxlayer.hpp"
|
#include "tmxlayer.hpp"
|
||||||
#include "tmxobject.hpp"
|
#include "tmxobject.hpp"
|
||||||
|
#include "headerwriter.hpp"
|
||||||
|
#include "swriter.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cstdint>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
static const char* versionStr = "tmx2gba version 0.3, (c) 2015-2022 a dinosaur";
|
||||||
|
|
||||||
struct Arguments
|
struct Arguments
|
||||||
{
|
{
|
||||||
bool help = false;
|
bool help = false, showVersion = false;
|
||||||
std::string inPath, outPath;
|
std::string inPath, outPath;
|
||||||
std::string layer, collisionlay, paletteLay;
|
std::string layer, collisionlay, paletteLay;
|
||||||
std::string flagFile;
|
std::string flagFile;
|
||||||
@@ -27,6 +29,7 @@ using ArgParse::Option;
|
|||||||
static const ArgParse::Options options =
|
static const ArgParse::Options options =
|
||||||
{
|
{
|
||||||
Option::Optional('h', nullptr, "Display this help & command info"),
|
Option::Optional('h', nullptr, "Display this help & command info"),
|
||||||
|
Option::Optional('v', nullptr, "Display version & quit"),
|
||||||
Option::Optional('l', "name", "Name of layer to use (default first layer in TMX)"),
|
Option::Optional('l', "name", "Name of layer to use (default first layer in TMX)"),
|
||||||
Option::Optional('y', "name", "Layer for palette mappings"),
|
Option::Optional('y', "name", "Layer for palette mappings"),
|
||||||
Option::Optional('c', "name", "Output a separate 8bit collision map of the specified layer"),
|
Option::Optional('c', "name", "Output a separate 8bit collision map of the specified layer"),
|
||||||
@@ -50,6 +53,7 @@ bool ParseArgs(int argc, char** argv, Arguments& params)
|
|||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
case 'h': params.help = true; return ParseCtrl::QUIT_EARLY;
|
case 'h': params.help = true; return ParseCtrl::QUIT_EARLY;
|
||||||
|
case 'v': params.showVersion = true; return ParseCtrl::QUIT_EARLY;
|
||||||
case 'l': params.layer = arg; return ParseCtrl::CONTINUE;
|
case 'l': params.layer = arg; return ParseCtrl::CONTINUE;
|
||||||
case 'c': params.collisionlay = arg; return ParseCtrl::CONTINUE;
|
case 'c': params.collisionlay = arg; return ParseCtrl::CONTINUE;
|
||||||
case 'y': params.paletteLay = arg; return ParseCtrl::CONTINUE;
|
case 'y': params.paletteLay = arg; return ParseCtrl::CONTINUE;
|
||||||
@@ -63,14 +67,14 @@ bool ParseArgs(int argc, char** argv, Arguments& params)
|
|||||||
default: return ParseCtrl::QUIT_ERR_UNKNOWN;
|
default: return ParseCtrl::QUIT_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::invalid_argument const& e) { return ParseCtrl::QUIT_ERR_INVALID; }
|
catch (std::invalid_argument const&) { return ParseCtrl::QUIT_ERR_INVALID; }
|
||||||
catch (std::out_of_range const& e) { return ParseCtrl::QUIT_ERR_RANGE; }
|
catch (std::out_of_range const&) { return ParseCtrl::QUIT_ERR_RANGE; }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!parser.Parse(std::span(argv + 1, argc - 1)))
|
if (!parser.Parse(std::span(argv + 1, argc - 1)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (params.help)
|
if (params.help || params.showVersion)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!params.flagFile.empty())
|
if (!params.flagFile.empty())
|
||||||
@@ -113,43 +117,6 @@ bool ParseArgs(int argc, char** argv, Arguments& params)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> constexpr const char* DatType();
|
|
||||||
template <> constexpr const char* DatType<uint8_t>() { return ".byte"; }
|
|
||||||
template <> constexpr const char* DatType<uint16_t>() { return ".hword"; }
|
|
||||||
template <> constexpr const char* DatType<uint32_t>() { return ".word"; }
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void WriteArray(std::ofstream& aOut, const std::vector<T>& aDat, int aPerCol = 16)
|
|
||||||
{
|
|
||||||
int col = 0;
|
|
||||||
|
|
||||||
aOut.setf(std::ios::hex, std::ios::basefield);
|
|
||||||
aOut.setf(std::ios::showbase);
|
|
||||||
|
|
||||||
size_t i = 0;
|
|
||||||
for (T element : aDat)
|
|
||||||
{
|
|
||||||
if (col == 0)
|
|
||||||
aOut << "\t" << DatType<T>() << " ";
|
|
||||||
|
|
||||||
aOut << std::hex << (int)element;
|
|
||||||
|
|
||||||
if (i < aDat.size() - 1)
|
|
||||||
{
|
|
||||||
if (++col < aPerCol)
|
|
||||||
{
|
|
||||||
aOut << ",";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
aOut << "" << std::endl;
|
|
||||||
col = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -161,6 +128,11 @@ int main(int argc, char** argv)
|
|||||||
options.ShowHelpUsage(argv[0], std::cout);
|
options.ShowHelpUsage(argv[0], std::cout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (p.showVersion)
|
||||||
|
{
|
||||||
|
std::cout << versionStr << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Object mappings
|
// Object mappings
|
||||||
std::map<std::string, uint32_t> objMapping;
|
std::map<std::string, uint32_t> objMapping;
|
||||||
@@ -172,7 +144,7 @@ int main(int argc, char** argv)
|
|||||||
if (splitter == std::string::npos)
|
if (splitter == std::string::npos)
|
||||||
{
|
{
|
||||||
std::cerr << "Malformed mapping (missing a splitter)." << std::endl;
|
std::cerr << "Malformed mapping (missing a splitter)." << std::endl;
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -195,7 +167,7 @@ int main(int argc, char** argv)
|
|||||||
if (!fin.is_open())
|
if (!fin.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open input file." << std::endl;
|
std::cerr << "Failed to open input file." << std::endl;
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
tmx.Open(fin);
|
tmx.Open(fin);
|
||||||
|
|
||||||
@@ -203,7 +175,7 @@ int main(int argc, char** argv)
|
|||||||
if (tmx.GetLayerCount() == 0)
|
if (tmx.GetLayerCount() == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "No layers found." << std::endl;
|
std::cerr << "No layers found." << std::endl;
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
const TmxLayer* layerGfx = p.layer.empty()
|
const TmxLayer* layerGfx = p.layer.empty()
|
||||||
? tmx.GetLayer(0)
|
? tmx.GetLayer(0)
|
||||||
@@ -218,45 +190,42 @@ int main(int argc, char** argv)
|
|||||||
if (layerGfx == nullptr)
|
if (layerGfx == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "Input layer not found." << std::endl;
|
std::cerr << "Input layer not found." << std::endl;
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open output files
|
// Get name from file
|
||||||
std::ofstream foutS(p.outPath + ".s");
|
//TODO: properly sanitise
|
||||||
std::ofstream foutH(p.outPath + ".h");
|
int slashPos = std::max(
|
||||||
if (!foutS.is_open() || !foutH.is_open())
|
static_cast<int>(p.outPath.find_last_of('/')),
|
||||||
{
|
static_cast<int>(p.outPath.find_last_of('\\')));
|
||||||
std::cerr << "Failed to create output file(s).";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slashPos = std::max((int)p.outPath.find_last_of('/'), (int)p.outPath.find_last_of('\\'));
|
|
||||||
std::string name = p.outPath;
|
std::string name = p.outPath;
|
||||||
if (slashPos != -1)
|
if (slashPos != -1)
|
||||||
name = name.substr(slashPos + 1);
|
name = name.substr(slashPos + 1);
|
||||||
|
|
||||||
// Write header guards
|
// Open output files
|
||||||
std::string guard = "TMX2GBA_" + name;
|
SWriter outS; HeaderWriter outH;
|
||||||
for (auto& c: guard)
|
if (!outS.Open(p.outPath + ".s", name))
|
||||||
c = static_cast<char>(toupper(c));
|
{
|
||||||
foutH << "#ifndef " << guard << std::endl;
|
std::cerr << "Failed to create output file \"" << p.outPath << ".s\".";
|
||||||
foutH << "#define " << guard << std::endl;
|
return 1;
|
||||||
foutH << std::endl;
|
}
|
||||||
foutH << "#define " << name << "Width " << tmx.GetWidth() << std::endl;
|
if (!outH.Open(p.outPath + ".h", name))
|
||||||
foutH << "#define " << name << "Height " << tmx.GetHeight() << std::endl;
|
{
|
||||||
foutH << std::endl;
|
std::cerr << "Failed to create output file \"" << p.outPath << ".h\".";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to GBA-friendly charmap data
|
// Convert to GBA-friendly charmap data
|
||||||
const uint32_t* gfxTiles = layerGfx->GetData();
|
const uint32_t* gfxTiles = layerGfx->GetData();
|
||||||
const uint32_t* palTiles = (layerPal == nullptr) ? nullptr : layerPal->GetData();
|
const uint32_t* palTiles = (layerPal == nullptr) ? nullptr : layerPal->GetData();
|
||||||
std::vector<uint16_t> charDat;
|
std::vector<uint16_t> charDat;
|
||||||
size_t numTiles = static_cast<size_t>(layerGfx->GetWidth()) * static_cast<size_t>(layerGfx->GetHeight());
|
const size_t numTiles = static_cast<size_t>(layerGfx->GetWidth()) * static_cast<size_t>(layerGfx->GetHeight());
|
||||||
charDat.reserve(numTiles);
|
charDat.reserve(numTiles);
|
||||||
for (size_t i = 0; i < numTiles; ++i)
|
for (size_t i = 0; i < numTiles; ++i)
|
||||||
{
|
{
|
||||||
uint32_t read = (*gfxTiles++);
|
uint32_t read = (*gfxTiles++);
|
||||||
|
|
||||||
uint16_t tile = (uint16_t)std::max<int32_t>(0, tmx.LidFromGid(read & ~TmxLayer::FLIP_MASK) + p.offset);
|
uint16_t tile = std::max(0, static_cast<int>(tmx.LidFromGid(read & ~TmxLayer::FLIP_MASK)) + p.offset);
|
||||||
uint8_t flags = 0x0;
|
uint8_t flags = 0x0;
|
||||||
|
|
||||||
// Get flipped!
|
// Get flipped!
|
||||||
@@ -275,29 +244,21 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write out charmap
|
// Write out charmap
|
||||||
foutH << "#define " << name << "TilesLen " << charDat.size() * 2 << std::endl;
|
outH.WriteSize(tmx.GetWidth(), tmx.GetHeight());
|
||||||
foutH << "extern const unsigned short " << name << "Tiles[" << charDat.size() << "];" << std::endl;
|
outH.WriteCharacterMap(charDat);
|
||||||
foutH << std::endl;
|
outS.WriteArray("Tiles", charDat);
|
||||||
|
|
||||||
foutS << "\t.section .rodata" << std::endl;
|
|
||||||
foutS << "\t.align 2" << std::endl;
|
|
||||||
foutS << "\t.global " << name << "Tiles" << std::endl;
|
|
||||||
foutS << "\t.hidden " << name << "Tiles" << std::endl;
|
|
||||||
foutS << name << "Tiles" << ":" << std::endl;
|
|
||||||
WriteArray<uint16_t>(foutS, charDat);
|
|
||||||
foutS << std::endl;
|
|
||||||
|
|
||||||
// Convert collision map & write it out
|
// Convert collision map & write it out
|
||||||
if (layerCls != nullptr)
|
if (layerCls != nullptr)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> vucCollisionDat;
|
std::vector<uint8_t> collisionDat;
|
||||||
vucCollisionDat.reserve(layerCls->GetWidth() * layerCls->GetHeight());
|
collisionDat.reserve(layerCls->GetWidth() * layerCls->GetHeight());
|
||||||
|
|
||||||
gfxTiles = layerCls->GetData();
|
gfxTiles = layerCls->GetData();
|
||||||
for (int i = 0; i < layerCls->GetWidth() * layerCls->GetHeight(); ++i)
|
for (int i = 0; i < layerCls->GetWidth() * layerCls->GetHeight(); ++i)
|
||||||
{
|
{
|
||||||
uint8_t ucTile = (uint8_t)tmx.LidFromGid((*gfxTiles++) & ~TmxLayer::FLIP_MASK);
|
uint8_t ucTile = static_cast<uint8_t>(tmx.LidFromGid((*gfxTiles++) & ~TmxLayer::FLIP_MASK));
|
||||||
vucCollisionDat.push_back(ucTile);
|
collisionDat.push_back(ucTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to nicely append "_collision" to the output name
|
// Try to nicely append "_collision" to the output name
|
||||||
@@ -309,18 +270,8 @@ int main(int argc, char** argv)
|
|||||||
path = p.outPath + "_collision";
|
path = p.outPath + "_collision";
|
||||||
|
|
||||||
// Write collision
|
// Write collision
|
||||||
foutH << "#define " << name << "CollisionLen " << vucCollisionDat.size() << std::endl;
|
outH.WriteCollision(collisionDat);
|
||||||
foutH << "extern const unsigned char " << name << "Collision[" << vucCollisionDat.size() << "];" << std::endl;
|
outS.WriteArray("Collision", collisionDat, 32);
|
||||||
foutH << std::endl;
|
|
||||||
|
|
||||||
foutS << std::endl;
|
|
||||||
foutS << "\t.section .rodata" << std::endl;
|
|
||||||
foutS << "\t.align 2" << std::endl;
|
|
||||||
foutS << "\t.global " << name << "Collision" << std::endl;
|
|
||||||
foutS << "\t.hidden " << name << "Collision" << std::endl;
|
|
||||||
foutS << name << "Collision" << ":" << std::endl;
|
|
||||||
WriteArray<uint8_t>(foutS, vucCollisionDat);
|
|
||||||
foutS << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p.objMappings.empty())
|
if (!p.objMappings.empty())
|
||||||
@@ -336,30 +287,14 @@ int main(int argc, char** argv)
|
|||||||
float x, y;
|
float x, y;
|
||||||
obj->GetPos(x, y);
|
obj->GetPos(x, y);
|
||||||
objDat.push_back(it->second);
|
objDat.push_back(it->second);
|
||||||
objDat.push_back((int)(x * 256.0f));
|
objDat.push_back(static_cast<int>(x * 256.0f));
|
||||||
objDat.push_back((int)(y * 256.0f));
|
objDat.push_back(static_cast<int>(y * 256.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write objects
|
// Write objects
|
||||||
foutH << "#define " << name << "ObjCount " << objDat.size() / 3 << std::endl;
|
outH.WriteObjects(objDat);
|
||||||
foutH << "#define " << name << "ObjdatLen " << objDat.size() * sizeof(int) << std::endl;
|
outS.WriteArray("Objdat", objDat);
|
||||||
foutH << "extern const unsigned int " << name << "Objdat[" << objDat.size() << "];" << std::endl;
|
|
||||||
foutH << std::endl;
|
|
||||||
|
|
||||||
foutS << std::endl;
|
|
||||||
foutS << "\t.section .rodata" << std::endl;
|
|
||||||
foutS << "\t.align 2" << std::endl;
|
|
||||||
foutS << "\t.global " << name << "Objdat" << std::endl;
|
|
||||||
foutS << "\t.hidden " << name << "Objdat" << std::endl;
|
|
||||||
foutS << name << "Objdat" << ":" << std::endl;
|
|
||||||
WriteArray<uint32_t>(foutS, objDat);
|
|
||||||
foutS << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foutH << "#endif//" << guard << std::endl;
|
|
||||||
|
|
||||||
foutH.close();
|
|
||||||
foutS.close();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ bool TmxReader::DecodeMap(uint32_t* aOut, size_t aOutSize, const std::string& aB
|
|||||||
// Decompress compressed data
|
// Decompress compressed data
|
||||||
auto dstSize = static_cast<mz_ulong>(aOutSize);
|
auto dstSize = static_cast<mz_ulong>(aOutSize);
|
||||||
int res = uncompress(
|
int res = uncompress(
|
||||||
(unsigned char*)aOut,
|
reinterpret_cast<unsigned char*>(aOut),
|
||||||
&dstSize,
|
&dstSize,
|
||||||
reinterpret_cast<const unsigned char*>(decoded.data()),
|
reinterpret_cast<const unsigned char*>(decoded.data()),
|
||||||
static_cast<mz_ulong>(decoded.size()));
|
static_cast<mz_ulong>(decoded.size()));
|
||||||
@@ -172,7 +172,7 @@ void TmxReader::Open(std::istream& aIn)
|
|||||||
|
|
||||||
// Parse document
|
// Parse document
|
||||||
rapidxml::xml_document<> xDoc;
|
rapidxml::xml_document<> xDoc;
|
||||||
xDoc.parse<0>((char*)strXml.c_str());
|
xDoc.parse<0>(const_cast<char*>(strXml.c_str()));
|
||||||
|
|
||||||
// Get map node
|
// Get map node
|
||||||
auto xMap = xDoc.first_node("map");
|
auto xMap = xDoc.first_node("map");
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ private:
|
|||||||
std::string mName;
|
std::string mName;
|
||||||
std::string mSource;
|
std::string mSource;
|
||||||
uint32_t mFirstGid;
|
uint32_t mFirstGid;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//TMXTILESET_HPP
|
#endif//TMXTILESET_HPP
|
||||||
|
|||||||
Reference in New Issue
Block a user