Skip to content

Commit

Permalink
refactor(v2): step 2: api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Sep 24, 2023
1 parent b9e4fa1 commit 83ce81f
Show file tree
Hide file tree
Showing 151 changed files with 11,411 additions and 9,651 deletions.
251 changes: 108 additions & 143 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,153 +1,123 @@
cmake_minimum_required(VERSION 3.10)
include(CheckIncludeFiles)
project(phoenix VERSION 1.1.1)
project(ZenKit VERSION 2.0.0)
include(support/BuildSupport.cmake)

set(CMAKE_CXX_STANDARD 17)
set(PHOENIX_LOG_LEVEL 3 CACHE STRING "The logging level to use for phoenix. Set to 4, 3, 2, or 1 for DEBUG, INFO, WARN or ERROR respectively")

option(PHOENIX_BUILD_EXAMPLES "Build example code" OFF)
option(PHOENIX_BUILD_TESTS "Build tests" ON)
option(PHOENIX_BUILD_SHARED "Build phoenix as a shared library" OFF)
option(PHOENIX_DISABLE_SANITIZERS "Build without sanitizers in debug mode" OFF)
option(PHOENIX_INSTALL "Configure phoenix for cmake install" ON)
option(ZK_BUILD_EXAMPLES "ZenKit: Build the examples." OFF)
option(ZK_BUILD_TESTS "ZenKit: Build the test suite." ON)
option(ZK_BUILD_SHARED "ZenKit: Build a shared library." OFF)

set(PHOENIX_DEBUG_POSTFIX d CACHE STRING "Debug library postfix.")

if (MSVC)
# enable all warnings
set(PHOENIX_CXX_FLAGS "/W4")

# in debug mode, enable sanitizers
if (${CMAKE_BUILD_TYPE} MATCHES "Debug" AND NOT ${PHOENIX_DISABLE_SANITIZERS})
set(PHOENIX_CXX_FLAGS ${PHOENIX_CXX_FLAGS} "/fsanitize=address")
endif ()
else ()
# enable all warnings
set(PHOENIX_CXX_FLAGS -Wall -Wextra -Werror -Wconversion -Wshadow -Wpedantic)

# in debug mode, enable sanitizers; note: MinGW does not seem to understand sanitizers on Windows
if (${CMAKE_BUILD_TYPE} MATCHES "Debug" AND NOT ${PHOENIX_DISABLE_SANITIZERS} AND NOT WIN32)
set(PHOENIX_CXX_FLAGS ${PHOENIX_CXX_FLAGS} -fsanitize=address -fsanitize=undefined)

# when not compiling for MacOS, enable leak sanitizer
if (NOT APPLE)
set(PHOENIX_CXX_FLAGS ${PHOENIX_CXX_FLAGS} -fsanitize=leak)
endif ()
endif ()

# in debug mode on Clang to get proper debugging support, add -fstandalone-debug
if (${CMAKE_BUILD_TYPE} MATCHES "Debug" AND ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(PHOENIX_CXX_FLAGS ${PHOENIX_CXX_FLAGS} -fstandalone-debug)
endif ()
endif ()
option(ZK_ENABLE_ASAN "ZenKit: Enable sanitizers in debug builds." ON)
option(ZK_ENABLE_DEPRECATION "ZenKit: Enable deprecation warnings." ON)
option(ZK_ENABLE_INSTALL "ZenKit: Enable CMake install target creation." ON)

add_subdirectory(vendor)

# add log level definition
set(PHOENIX_DEFINES PHOENIX_LOG_LEVEL=${PHOENIX_LOG_LEVEL})

# find all header files; required for them to show up properly in VisualStudio
file(GLOB_RECURSE PHOENIX_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.hh")

set(PHOENIX_SOURCES
source/animation.cc
source/archive.cc
source/archive/archive_ascii.cc
source/archive/archive_binary.cc
source/archive/archive_binsafe.cc
file(GLOB_RECURSE _ZK_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/**/*.hh")

list(APPEND _ZK_SOURCES
source/buffer.cc
source/font.cc
source/material.cc
source/math.cc
source/mesh.cc
source/messages.cc
source/model.cc
source/model_hierarchy.cc
source/model_mesh.cc
source/model_script.cc
source/model_script_dsl.cc
source/morph_mesh.cc
source/phoenix.cc
source/proto_mesh.cc
source/save_game.cc
source/script.cc
source/softskin_mesh.cc
source/texture.cc
source/vdfs.cc
source/Vfs.cc
source/vobs/camera.cc
source/vobs/light.cc
source/vobs/misc.cc
source/vobs/mob.cc
source/vobs/sound.cc
source/vobs/trigger.cc
source/vobs/vob.cc
source/vobs/zone.cc
source/vm.cc
source/world.cc
source/world/bsp_tree.cc
source/world/vob_tree.cc
source/world/way_net.cc)

set(PHOENIX_EXTENSIONS
source/ext/dds_convert.cc
source/ext/daedalus_classes.cc)

set(PHOENIX_TESTS
tests/test_animation.cc
tests/test_archive.cc
tests/test_buffer.cc
tests/test_font.cc
tests/test_material.cc
tests/test_messages.cc
tests/test_model.cc
tests/test_model_hierarchy.cc
tests/test_model_mesh.cc
tests/test_model_script.cc
tests/test_morph_mesh.cc
tests/test_proto_mesh.cc
tests/test_save_game.cc
tests/test_script.cc
tests/test_texture.cc

src/world/BspTree.cc
src/world/VobTree.cc
src/world/WayNet.cc

src/vobs/Camera.cc
src/vobs/Light.cc
src/vobs/Misc.cc
src/vobs/MovableObject.cc
src/vobs/Sound.cc
src/vobs/Trigger.cc
src/vobs/VirtualObject.cc
src/vobs/Zone.cc

src/addon/daedalus.cc
src/addon/texcvt.cc

src/archive/ArchiveAscii.cc
src/archive/ArchiveBinary.cc
src/archive/ArchiveBinsafe.cc

src/Archive.cc
src/Boxes.cc
src/CutsceneLibrary.cc
src/DaedalusScript.cc
src/Date.cc
src/DaedalusVm.cc
src/Error.cc
src/Font.cc
src/Logger.cc
src/Material.cc
src/Mesh.cc
src/Misc.cc
src/Model.cc
src/ModelAnimation.cc
src/ModelHierarchy.cc
src/ModelMesh.cc
src/ModelScript.cc
src/ModelScriptDsl.cc
src/MorphMesh.cc
src/MultiResolutionMesh.cc
src/SaveGame.cc
src/SoftSkinMesh.cc
src/Stream.cc
src/Texture.cc
src/Vfs.cc
src/World.cc
)

list(APPEND _ZK_TESTS
tests/TestArchive.cc
tests/TestCutsceneLibrary.cc
tests/TestDaedalusScript.cc
tests/TestFont.cc
tests/TestMaterial.cc
tests/TestModel.cc
tests/TestModelAnimation.cc
tests/TestModelHierarchy.cc
tests/TestModelMesh.cc
tests/TestModelScript.cc
tests/TestMorphMesh.cc
tests/TestMultiResolutionMesh.cc
tests/TestSaveGame.cc
tests/TestStream.cc
tests/TestTexture.cc
tests/TestVfs.cc
tests/test_vobs_g1.cc
tests/test_vobs_g2.cc
tests/test_world.cc)

# add the phoenix library definition
if (BUILD_SHARED_LIBS AND PHOENIX_BUILD_SHARED)
add_library(phoenix SHARED)
set_target_properties(phoenix PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
tests/TestVobsG1.cc
tests/TestVobsG2.cc
tests/TestWorld.cc
)

if (BUILD_SHARED_LIBS AND ZK_BUILD_SHARED)
add_library(zenkit SHARED)
set_target_properties(zenkit PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1)
target_compile_definitions(zenkit PRIVATE ZKDYN=1)
else ()
add_library(phoenix STATIC)
set(PHOENIX_DEFINES ${PHOENIX_DEFINES} PHOENIX_STATIC=1)
set_target_properties(phoenix PROPERTIES COMPILE_FLAGS "-DPHOENIX_STATIC=1")
add_library(zenkit STATIC)
endif ()

target_sources(phoenix PRIVATE ${PHOENIX_SOURCES} ${PHOENIX_EXTENSIONS} ${PHOENIX_HEADERS})
target_include_directories(phoenix PUBLIC include)

# Apps using phoenix will also need to link to glm, fmt and squish to avoid missing symbols
target_link_libraries(phoenix
PUBLIC glm::glm_static squish
PRIVATE mio)

target_compile_definitions(phoenix PUBLIC ${PHOENIX_DEFINES} PRIVATE PHOENIX_EXPORTS=1)
target_compile_options(phoenix PRIVATE ${PHOENIX_CXX_FLAGS})

if (NOT MSVC)
target_link_options(phoenix PUBLIC ${PHOENIX_CXX_FLAGS})
if (NOT ZK_ENABLE_DEPRECATION)
target_compile_definitions(zenkit PUBLIC ZKNO_REM=1)
endif ()

set_target_properties(phoenix PROPERTIES
DEBUG_POSTFIX "${PHOENIX_DEBUG_POSTFIX}"
VERSION ${PROJECT_VERSION})
bs_select_cflags(${ZK_ENABLE_ASAN} _ZK_COMPILE_FLAGS _ZK_LINK_FLAGS)

target_sources(zenkit PRIVATE ${_ZK_SOURCES} ${_ZK_HEADERS})
target_include_directories(zenkit PUBLIC include)
target_compile_definitions(zenkit PRIVATE _ZKEXPORT=1)
target_compile_options(zenkit PRIVATE ${_ZK_COMPILE_FLAGS})
target_link_options(zenkit PUBLIC ${_ZK_LINK_FLAGS})
target_link_libraries(zenkit PUBLIC glm::glm_static squish mio)
set_target_properties(zenkit PROPERTIES DEBUG_POSTFIX "d" VERSION ${PROJECT_VERSION})

if (PHOENIX_INSTALL)
install(TARGETS phoenix ARCHIVE LIBRARY RUNTIME)
if (ZK_ENABLE_INSTALL)
install(TARGETS zenkit ARCHIVE LIBRARY RUNTIME)
install(DIRECTORY "include/phoenix" TYPE INCLUDE)
install(DIRECTORY "include/zenkit" TYPE INCLUDE)

if (NOT PHOENIX_BUILD_SHARED)
if (NOT ZK_BUILD_SHARED)
# For static linking we'll need to provide the dependency static libraries
install(DIRECTORY "${glm_SOURCE_DIR}/glm" TYPE INCLUDE FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl" PATTERN "*.h")

Expand All @@ -158,24 +128,19 @@ if (PHOENIX_INSTALL)
endif ()

# when building tests, create a test executable and load it into CTest
if (PHOENIX_BUILD_TESTS AND CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if (ZK_BUILD_TESTS AND CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
enable_testing()
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)

add_executable(phoenix-tests ${PHOENIX_TESTS})
target_link_libraries(phoenix-tests PRIVATE phoenix doctest_with_main)
target_compile_options(phoenix-tests PRIVATE ${PHOENIX_CXX_FLAGS})

if (NOT MSVC)
target_compile_options(phoenix-tests PRIVATE -Wno-overloaded-shift-op-parentheses -Wno-deprecated-declarations)
endif ()

target_link_options(phoenix-tests PRIVATE ${PHOENIX_CXX_FLAGS})
add_executable(test-zenkit ${_ZK_TESTS})
target_link_libraries(test-zenkit PRIVATE zenkit doctest_with_main)
target_compile_options(test-zenkit PRIVATE ${_ZK_COMPILE_FLAGS})
target_link_options(test-zenkit PUBLIC ${_ZK_LINK_FLAGS})

doctest_discover_tests(phoenix-tests EXTRA_ARGS -tse=messages,script,world WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/tests)
doctest_discover_tests(test-zenkit EXTRA_ARGS -tse=CutsceneLibrary,DaedalusScript,World WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/tests)
endif ()

# when building examples, include the subdirectory
if (PHOENIX_BUILD_EXAMPLES)
if (ZK_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
add_executable(load_vdf load_vdf.cc)
target_link_libraries(load_vdf PRIVATE phoenix)
target_link_libraries(load_vdf PRIVATE zenkit)

add_executable(load_zen load_zen.cc)
target_link_libraries(load_zen PRIVATE phoenix)
target_link_libraries(load_zen PRIVATE zenkit)

add_executable(run_interpreter run_interpreter.cc)
target_link_libraries(run_interpreter PRIVATE phoenix)
target_link_libraries(run_interpreter PRIVATE zenkit)

set_target_properties(load_vdf load_zen run_interpreter
PROPERTIES
Expand Down
22 changes: 9 additions & 13 deletions examples/load_vdf.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright © 2022 Luis Michaelis <[email protected]>
// Copyright © 2022-2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#include <phoenix/vdfs.hh>
#include <zenkit/Vfs.hh>

#include <iostream>

void print_entries(const std::set<phoenix::vdf_entry, phoenix::vdf_entry_comparator>& entries) {
void print_entries(const std::set<zenkit::VfsNode, zenkit::VfsNodeComparator>& entries) {
for (auto& e : entries) {
if (e.is_directory()) {
print_entries(e.children);
if (e.type() == zenkit::VfsNodeType::DIRECTORY) {
print_entries(e.children());
} else {
std::cout << " " << e.name << ": " << e.size << " bytes\n";
std::cout << e.name() << "\n";
}
}
}
Expand All @@ -20,12 +20,8 @@ int main(int argc, char** argv) {
return -1;
}

auto vdf = phoenix::vdf_file::open(argv[1]);
auto& header = vdf.header;

std::cout << "Description: " << header.comment << "\n"
<< "Timestamp (Unix): " << header.timestamp << "\nEntries:\n";

print_entries(vdf.entries);
zenkit::Vfs vfs {};
vfs.mount_disk(argv[1]);
print_entries(vfs.root().children());
return 0;
}
2 changes: 1 addition & 1 deletion examples/load_zen.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Luis Michaelis <[email protected]>
// Copyright © 2022-2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#include <phoenix/archive.hh>

Expand Down
6 changes: 5 additions & 1 deletion examples/run_interpreter.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright © 2022 Luis Michaelis <[email protected]>
// Copyright © 2022-2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#include <phoenix/ext/daedalus_classes.hh>
#include <phoenix/script.hh>
#include <phoenix/vm.hh>
#include <zenkit/Logger.hh>

#include <iostream>

Expand All @@ -11,6 +13,8 @@ int main(int argc, char** argv) {
return -1;
}

zenkit::Logger::set_default(zenkit::LogLevel::DEBUG);

phoenix::vm vm {phoenix::script::parse(argv[1])};
phoenix::register_all_script_classes(vm); // needed for Gothic scripts

Expand Down
17 changes: 17 additions & 0 deletions include/phoenix/Vfs.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © 2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#pragma once
#include "zenkit/Vfs.hh"

namespace phoenix {
using VfsBrokenDiskError ZKREM("renamed to zenkit::VfsBrokenDiskError") = zenkit::VfsBrokenDiskError;
using VfsFileExistsError ZKREM("renamed to zenkit::VfsFileExistsError") = zenkit::VfsFileExistsError;
using VfsNotFoundError ZKREM("renamed to zenkit::VfsNotFoundError") = zenkit::VfsNotFoundError;
using VfsNodeType ZKREM("renamed to zenkit::VfsNodeType") = zenkit::VfsNodeType;
using VfsFileDescriptor ZKREM("renamed to zenkit::VfsFileDescriptor") = zenkit::VfsFileDescriptor;
using VfsNode ZKREM("renamed to zenkit::VfsNode") = zenkit::VfsNode;
using VfsNodeComparator ZKREM("renamed to zenkit::VfsNodeComparator") = zenkit::VfsNodeComparator;
using VfsNode ZKREM("renamed to zenkit::VfsNode") = zenkit::VfsNode;
using VfsOverwriteBehavior ZKREM("renamed to zenkit::VfsOverwriteBehavior") = zenkit::VfsOverwriteBehavior;
using Vfs ZKREM("renamed to zenkit::Vfs") = zenkit::Vfs;
} // namespace phoenix
11 changes: 11 additions & 0 deletions include/phoenix/animation.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright © 2023 GothicKit Contributors.
// SPDX-License-Identifier: MIT
#pragma once
#include "zenkit/ModelAnimation.hh"

namespace phoenix {
using animation ZKREM("renamed to zenkit::Animation") = zenkit::ModelAnimation;
using animation_sample ZKREM("renamed to zenkit::AnimationSample") = zenkit::AnimationSample;
using animation_event ZKREM("renamed to zenkit::AnimationEvent") = zenkit::AnimationEvent;
using animation_event_type ZKREM("renamed to zenkit::AnimationEventType") = zenkit::AnimationEventType;
} // namespace phoenix
Loading

0 comments on commit 83ce81f

Please sign in to comment.