Skip to content

Commit

Permalink
Add zlib compression plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Jul 8, 2024
1 parent 72b8344 commit f2743b5
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
working-directory: ./build/debug
run: ./tactile-core-test

- name: Run Zlib compression tests
working-directory: ./build/debug
run: ./tactile-zlib-compression-test

- name: Run Zstd compression tests
working-directory: ./build/debug
run: ./tactile-zstd-compression-test
4 changes: 4 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jobs:
working-directory: ./build/debug
run: ./tactile-core-test

- name: Run Zlib compression tests
working-directory: ./build/debug
run: ./tactile-zlib-compression-test

- name: Run Zstd compression tests
working-directory: ./build/debug
run: ./tactile-zstd-compression-test
5 changes: 5 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ jobs:
shell: cmd
run: tactile-core-test.exe

- name: Run Zlib compression tests
working-directory: ./build/debug
shell: cmd
run: tactile-zlib-compression-test.exe

- name: Run Zstd compression tests
working-directory: ./build/debug
shell: cmd
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_subdirectory("source/proto")
add_subdirectory("source/base")
add_subdirectory("source/core")
add_subdirectory("source/runtime")
add_subdirectory("source/zlib_compression")
add_subdirectory("source/zstd_compression")
add_subdirectory("source/main")

Expand Down
3 changes: 0 additions & 3 deletions source/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ target_sources(tactile-core
"${PROJECT_SOURCE_DIR}/inc/tactile/core/event/viewport_events.hpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/core/io/compress/compression_error.hpp"
"${PROJECT_SOURCE_DIR}/src/tactile/core/io/compress/compression_error.cpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/core/io/compress/zlib_compression_provider.hpp"
"${PROJECT_SOURCE_DIR}/src/tactile/core/io/compress/zlib_compression_provider.cpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/core/io/save/ir.hpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/core/io/save/save_format.hpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/core/io/save/save_format_id.hpp"
Expand Down Expand Up @@ -285,5 +283,4 @@ target_link_libraries(tactile-core
SDL2::SDL2
protobuf::libprotobuf
tinyfiledialogs::tinyfiledialogs
ZLIB::ZLIB
)
1 change: 0 additions & 1 deletion source/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ target_sources(tactile-core-test
"${PROJECT_SOURCE_DIR}/src/debug/validation_test.cpp"
"${PROJECT_SOURCE_DIR}/src/entity/registry_test.cpp"
"${PROJECT_SOURCE_DIR}/src/event/event_dispatcher_test.cpp"
"${PROJECT_SOURCE_DIR}/src/io/compress/compression_provider_test.cpp"
"${PROJECT_SOURCE_DIR}/src/io/save/save_format_id_test.cpp"
"${PROJECT_SOURCE_DIR}/src/io/ini_test.cpp"
"${PROJECT_SOURCE_DIR}/src/layer/group_layer_test.cpp"
Expand Down
68 changes: 0 additions & 68 deletions source/core/test/src/io/compress/compression_provider_test.cpp

This file was deleted.

1 change: 1 addition & 0 deletions source/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ target_include_directories(tactile-runtime
target_compile_definitions(tactile-runtime
PRIVATE
"TACTILE_BUILDING_RUNTIME"
"TACTILE_ENABLE_ZLIB_COMPRESSION"
"TACTILE_ENABLE_ZSTD_COMPRESSION"
"TACTILE_ENABLE_OPENGL_RENDERER"
)
Expand Down
32 changes: 32 additions & 0 deletions source/zlib_compression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
project(tactile-zlib-compression CXX)

add_library(tactile-zlib-compression SHARED EXCLUDE_FROM_ALL)
add_library(tactile::zlib_compression ALIAS tactile-zlib-compression)

target_sources(tactile-zlib-compression
PRIVATE
"${PROJECT_SOURCE_DIR}/inc/tactile/zlib_compression/api.hpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/zlib_compression/zlib_compression_plugin.hpp"
"${PROJECT_SOURCE_DIR}/src/tactile/zlib_compression/zlib_compression_plugin.cpp"
"${PROJECT_SOURCE_DIR}/inc/tactile/zlib_compression/zlib_compressor.hpp"
"${PROJECT_SOURCE_DIR}/src/tactile/zlib_compression/zlib_compressor.cpp"
)

tactile_prepare_target(tactile-zlib-compression)

target_include_directories(tactile-zlib-compression PUBLIC "${PROJECT_SOURCE_DIR}/inc")

target_compile_definitions(tactile-zlib-compression PRIVATE "TACTILE_BUILDING_ZLIB_COMPRESSION")

target_link_libraries(tactile-zlib-compression
PUBLIC
tactile::base
tactile::runtime

PRIVATE
ZLIB::ZLIB
)

if (TACTILE_BUILD_TESTS MATCHES "ON")
add_subdirectory(test)
endif ()
11 changes: 11 additions & 0 deletions source/zlib_compression/inc/tactile/zlib_compression/api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/base/prelude.hpp"

#ifdef TACTILE_BUILDING_ZLIB_COMPRESSION
#define TACTILE_ZLIB_API TACTILE_DLL_EXPORT
#else
#define TACTILE_ZLIB_API TACTILE_DLL_IMPORT
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/base/container/smart_ptr.hpp"
#include "tactile/base/prelude.hpp"
#include "tactile/runtime/plugin.hpp"
#include "tactile/zlib_compression/api.hpp"
#include "tactile/zlib_compression/zlib_compressor.hpp"

namespace tactile {

/**
* Manages the Zlib compression plugin.
*/
class TACTILE_ZLIB_API ZlibCompressionPlugin final : public IPlugin
{
public:
void load(Runtime& runtime) override;

void unload(Runtime& runtime) override;

private:
Unique<ZlibCompressor> mCompressor {};
};

extern "C"
{
TACTILE_ZLIB_API auto tactile_make_plugin() -> IPlugin*;
TACTILE_ZLIB_API void tactile_free_plugin(IPlugin* plugin);
}

} // namespace tactile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once

#include "tactile/base/io/compress/compression_provider.hpp"
#include "tactile/base/prelude.hpp"
#include "tactile/zlib_compression/api.hpp"

namespace tactile {

Expand All @@ -11,7 +13,8 @@ namespace tactile {
*
* \see https://github.com/madler/zlib
*/
class ZlibCompressionProvider final : public ICompressionProvider {
class TACTILE_ZLIB_API ZlibCompressor final : public ICompressionProvider
{
public:
[[nodiscard]]
auto compress(ByteSpan input_data) const -> Result<ByteStream> override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/zlib_compression/zlib_compression_plugin.hpp"

#include <new> // nothrow

#include "tactile/runtime/runtime.hpp"

namespace tactile {

void ZlibCompressionPlugin::load(Runtime& runtime)
{
mCompressor = std::make_unique<ZlibCompressor>();
runtime.set_compression_provider(CompressionType::kZlib, mCompressor.get());
}

void ZlibCompressionPlugin::unload(Runtime& runtime)
{
runtime.set_compression_provider(CompressionType::kZlib, nullptr);
mCompressor.reset();
}

auto tactile_make_plugin() -> IPlugin*
{
return new (std::nothrow) ZlibCompressionPlugin {};
}

void tactile_free_plugin(IPlugin* plugin)
{
delete plugin;
}

} // namespace tactile
Loading

0 comments on commit f2743b5

Please sign in to comment.