Skip to content

Commit

Permalink
Merge branch 'feature/id-tech-formats' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-rindel committed Sep 20, 2020
2 parents 6fe4269 + b550fa3 commit e11e5fd
Show file tree
Hide file tree
Showing 20 changed files with 1,919 additions and 546 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
venv/
build/
cmake-build-debug/
cmake-build-release/
packages/
bin/
x64/
dist/
Expand All @@ -25,4 +27,4 @@ activate.sh
deactivate.bat
deactivate.ps1
deactivate.sh
environment.*.env
environment.*.env
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})

file(GLOB MDL_SRC_FILES src/mdl-to-json/*.cpp)
file(GLOB DTS_SRC_FILES src/dts-to-json/*.cpp)
file(GLOB OBJ_SRC_FILES src/dts-to-obj/*.cpp)
file(GLOB JSON_SRC_FILES src/json-to-dts/*.cpp)
file(GLOB DTS_VIEWER_SRC_FILES src/dts-viewer/*.cpp)

add_executable(mdl-to-json ${MDL_SRC_FILES})
add_executable(dts-to-json ${DTS_SRC_FILES})
add_executable(dts-to-obj ${OBJ_SRC_FILES})
add_executable(json-to-dts ${JSON_SRC_FILES})
add_executable(dts-viewer ${DTS_VIEWER_SRC_FILES})

include_directories(${CONAN_INCLUDE_DIRS})
include_directories(packages/include)
include_directories(src)

conan_target_link_libraries(mdl-to-json)
conan_target_link_libraries(dts-to-json)
conan_target_link_libraries(dts-to-obj)
conan_target_link_libraries(json-to-dts)

target_link_libraries(dts-viewer PRIVATE ${CONAN_LIBS})

if(MSVC)
target_compile_options(mdl-to-json PRIVATE /W4 /WX $<$<CONFIG:RELEASE>:/O2>)
target_compile_options(dts-to-json PRIVATE /W4 /WX $<$<CONFIG:RELEASE>:/O2>)
target_compile_options(dts-to-obj PRIVATE /W4 /WX $<$<CONFIG:RELEASE>:/O2>)
target_compile_options(json-to-dts PRIVATE /W4 /WX $<$<CONFIG:RELEASE>:/O2>)
target_compile_options(dts-viewer PRIVATE $<$<CONFIG:RELEASE>:/O2>)
else()
target_compile_options(mdl-to-json PRIVATE -Wall -Wextra -Werror -pedantic $<$<CONFIG:RELEASE>:-O3>)
target_compile_options(dts-to-json PRIVATE -Wall -Wextra -Werror -pedantic $<$<CONFIG:RELEASE>:-O3>)
target_compile_options(dts-to-obj PRIVATE -Wall -Wextra -Werror -pedantic $<$<CONFIG:RELEASE>:-O3>)
target_compile_options(json-to-dts PRIVATE -Wall -Wextra -Werror -pedantic $<$<CONFIG:RELEASE>:-O3>)
target_compile_options(dts-viewer PRIVATE $<$<CONFIG:RELEASE>:-O3>)
endif()
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ Inspired by a DTS converter for Earthsiege 2 (https://github.com/booto/convert_d

If you don't already have Conan on your system, find instructions here: https://conan.io/downloads.html

As a setup command, without any pre-built packages, run ```conan install cmake/3.17.3@/ -g virtualenv```

Then run ```activate``` or ```./activate```

To install project dependencies, use:

```conan install .``` or ```conan install . --missing``` if you system is missing precompiled packages for the dependencies.
```conan install .``` or ```conan install . --build=missing``` if you system is missing precompiled packages for the dependencies.

For debug builds use:
```conan install . -s build_type=Debug``` or ```conan install . -s build_type=Debug --build=missing```

To build the project, use:

Expand Down
18 changes: 16 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
import os

class LocalConanFile(ConanFile):
system_requires = "opengl/system"
build_requires = "cmake/3.17.3", "cppcheck_installer/2.0@bincrafters/stable"
settings = "os", "compiler", "build_type", "arch"
requires = "boost_endian/1.69.0@bincrafters/stable", "nlohmann_json/3.9.0"
requires = "toml11/3.4.0", "nlohmann_json/3.9.0", "boost_endian/1.69.0@bincrafters/stable", "imgui-sfml/2.1@bincrafters/stable", "wxwidgets/3.1.3@bincrafters/stable"
generators = "cmake", "virtualenv"
build_folder = "build"

def build(self):
self.build_folder = "build"
cmake = CMake(self)
cmake.configure()
self.run("cppcheck src --error-exitcode=1")
#self.run("cppcheck src --error-exitcode=1")
cmake.build()

def imports(self):
registry_url = "https://www.khronos.org/registry"

if not os.path.exists("packages/include/KHR/khrplatform.h"):
tools.download(f"{registry_url}/EGL/api/KHR/khrplatform.h", "packages/include/KHR/khrplatform.h")
tools.download(f"{registry_url}/OpenGL/api/GL/glext.h", "packages/include/GL/glext.h")
tools.download(f"{registry_url}/OpenGL/api/GL/glxext.h", "packages/include/GL/glxext.h")
tools.download(f"{registry_url}/OpenGL/api/GL/wgl.h", "packages/include/GL/wgl.h")
tools.download(f"{registry_url}/OpenGL/api/GL/wglext.h", "packages/include/GL/wglext.h")
tools.download(f"{registry_url}/OpenGL/api/GL/glcorearb.h", "packages/include/GL/glcorearb.h")



90 changes: 90 additions & 0 deletions src/binary_io.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ifndef DARKSTARDTSCONVERTER_BINARY_IO_HPP
#define DARKSTARDTSCONVERTER_BINARY_IO_HPP

#include <optional>
#include <array>
#include <vector>
#include <fstream>
#include <filesystem>
#include "dts_structures.hpp"
#include "endian_arithmetic.hpp"

namespace binary::io
{
template<std::size_t size>
std::array<std::byte, size> read(std::basic_ifstream<std::byte>& stream)
{
std::array<std::byte, size> dest{};

stream.read(&dest[0], size);

return dest;
}

template<typename destination_type>
destination_type read(std::basic_ifstream<std::byte>& stream)
{
destination_type dest{};

stream.read(reinterpret_cast<std::byte*>(&dest), sizeof(destination_type));

return dest;
}

template<typename destination_type>
std::vector<destination_type> read_vector(std::basic_ifstream<std::byte>& stream, std::size_t size)
{
if (size == 0)
{
return {};
}

std::vector<destination_type> dest(size);

stream.read(reinterpret_cast<std::byte*>(&dest[0]), sizeof(destination_type) * size);

return dest;
}

std::string read_string(std::basic_ifstream<std::byte>& stream, std::size_t size, std::size_t max_size = 16)
{
std::string dest(size, '\0');

stream.read(reinterpret_cast<std::byte*>(&dest[0]), size);

// There is always an embedded \0 in the
// file if the string length is less than 16 bytes.
if (size < max_size)
{
stream.seekg(1, std::ios_base::cur);
}

return dest;
}


template<std::size_t Size>
void write(std::basic_ostream<std::byte>& stream, const std::array<std::byte, Size>& value)
{
stream.write(value.data(), Size);
}

template<typename ValueType>
void write(std::basic_ostream<std::byte>& stream, const ValueType& value)
{
stream.write(reinterpret_cast<const std::byte*>(&value), sizeof(value));
}

template<typename ValueType>
void write(std::basic_ostream<std::byte>& stream, const std::vector<ValueType>& values)
{
stream.write(reinterpret_cast<const std::byte*>(values.data()), values.size() * sizeof(ValueType));
}

template<typename ValueType>
void write(std::basic_ostream<std::byte>& stream, const ValueType* value, std::size_t size)
{
stream.write(reinterpret_cast<const std::byte*>(value), size);
}
}
#endif//DARKSTARDTSCONVERTER_BINARY_IO_HPP
2 changes: 1 addition & 1 deletion src/complex_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <type_traits>
#include <nlohmann/json.hpp>
#include "json_boost.hpp"
#include "structures.hpp"
#include "dts_structures.hpp"

namespace nlohmann
{
Expand Down
Loading

0 comments on commit e11e5fd

Please sign in to comment.