Skip to content

Commit

Permalink
#49 Include union-api and gothic-api using FetchContent, enable /W4 /…
Browse files Browse the repository at this point in the history
…WX flags
  • Loading branch information
piotrmacha committed Oct 19, 2024
1 parent 7d5934a commit 07e75a3
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 73 deletions.
8 changes: 0 additions & 8 deletions .gitmodules

This file was deleted.

37 changes: 27 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ project(zBassMusic VERSION ${PROJECT_VERSION_CMAKE})

option(BUILD_VDF "Build .VDF file with plugin" ON)

set(UNION_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/union-api")
set(GOTHIC_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/gothic-api")
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BASS_DIR "${CMAKE_SOURCE_DIR}/dependencies/bass")
set(VDF_DIR "${CMAKE_SOURCE_DIR}/vdf")
set(GOTHIC_USERAPI_DIR "${CMAKE_SOURCE_DIR}/gothic-userapi")
Expand All @@ -17,8 +16,24 @@ if (${CMAKE_BUILD_RELEASE_PDB})
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif ()

include(cmake/union-api.cmake)
include(cmake/gothic-api.cmake)
include(FetchContent)
set(GOTHIC_API_G1 ON)
set(GOTHIC_API_G1A ON)
set(GOTHIC_API_G2 ON)
set(GOTHIC_API_G2A ON)
FetchContent_Declare(
union-api
GIT_REPOSITORY https://gitlab.com/union-framework/union-api.git
GIT_TAG ede619be94cb6a7349c43b6678748ad1113a8c56
)
FetchContent_Declare(
gothic-api
GIT_REPOSITORY https://gitlab.com/union-framework/gothic-api.git
GIT_TAG ba0894b136eda163209ef58a7dad07103cb2ed10
)
FetchContent_MakeAvailable(union-api)
FetchContent_MakeAvailable(gothic-api)

include(cmake/bass.cmake)

add_library(plugin SHARED)
Expand All @@ -35,16 +50,19 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${CMAKE_CURRENT_BINA
configure_file("${CMAKE_SOURCE_DIR}/vdf/script.vdfs.in" "${CMAKE_BINARY_DIR}/script.vdfs")
configure_file("${CMAKE_SOURCE_DIR}/src/BuildInfo.h.in" "${CMAKE_BINARY_DIR}/src/BuildInfo.h" @ONLY)

file(GLOB_RECURSE PLUGIN_SOURCES "src/**.cpp" "${UNION_API_DIR}/union-api/Union/Memory.cpp")
file(GLOB_RECURSE PLUGIN_SOURCES "src/**.cpp")
target_sources(plugin PRIVATE ${PLUGIN_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/version.rc")

add_compile_options(plugin PRIVATE /W4 /WX)
target_compile_definitions(plugin PRIVATE _UNION_API_DLL __G1 __G1A __G2 __G2A)
target_compile_options(plugin PRIVATE
/W4 /WX /permissive- /Zc:__cplusplus /Zc:preprocessor /utf-8
/experimental:external /external:W0 /external:anglebrackets /external:templates-
/external:I ${CMAKE_BINARY_DIR}/_deps
)

target_include_directories(plugin PRIVATE "src/" "${CMAKE_BINARY_DIR}/src/")
target_link_libraries(plugin PRIVATE union-api gothic-api bass_all)
target_link_libraries(plugin PRIVATE union_api_lib gothic_api bass_all)

install(FILES $<TARGET_RUNTIME_DLLS:plugin> "${CMAKE_BINARY_DIR}/zBassMusic.dll" TYPE BIN)
install(FILES $<TARGET_RUNTIME_DLLS:plugin> "${CMAKE_BINARY_DIR}/UnionAPI.dll" TYPE BIN)
if (${BUILD_VDF})
install(FILES "${CMAKE_BINARY_DIR}/script.vdfs" DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(SCRIPT "${VDF_DIR}/vdf.cmake")
Expand All @@ -70,7 +88,6 @@ endif ()
if (DEFINED ENV{COPY_DLL_TARGET})
add_custom_target(copy_dll ALL
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/zBassMusic.dll" "$ENV{COPY_DLL_TARGET}/Autorun/zBassMusic.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/UnionAPI.dll" "$ENV{COPY_DLL_TARGET}/Autorun/UnionAPI.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bass.dll" "$ENV{COPY_DLL_TARGET}/bass.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassmidi.dll" "$ENV{COPY_DLL_TARGET}/bassmidi.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassopus.dll" "$ENV{COPY_DLL_TARGET}/bassopus.dll"
Expand Down
8 changes: 0 additions & 8 deletions cmake/gothic-api.cmake

This file was deleted.

20 changes: 0 additions & 20 deletions cmake/union-api.cmake

This file was deleted.

1 change: 0 additions & 1 deletion dependencies/gothic-api
Submodule gothic-api deleted from 102f42
1 change: 0 additions & 1 deletion dependencies/union-api
Submodule union-api deleted from f492eb
6 changes: 3 additions & 3 deletions src/Gothic/BassLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ namespace GOTHIC_NAMESPACE

ForEachClass<BassMusicTheme>(
Globals->BassMusicThemeClassName,
[&]() { return m_BassThemeInstances.emplace_back(new BassMusicTheme{}); },
[&](const BassMusicTheme* input, const zCPar_Symbol* symbol) {
[&] { return m_BassThemeInstances.emplace_back(new BassMusicTheme{}); },
[&](const BassMusicTheme* input, [[maybe_unused]] const zCPar_Symbol* symbol) {
const auto theme = std::make_shared<NH::Bass::MusicTheme>(input->Name.ToChar());
theme->SetAudioEffects(NH::Bass::AudioFile::DEFAULT, []([[maybe_unused]] const NH::Bass::AudioEffects& effects) {});
for (auto zones = NH::String(input->Zones.ToChar()).Split(","); auto& zone: zones)
Expand All @@ -134,7 +134,7 @@ namespace GOTHIC_NAMESPACE

ForEachClass<BassMusicThemeAudio>(
Globals->BassMusicThemeAudioClassName,
[&]() { return m_BassThemeAudioInstances.emplace_back(new BassMusicThemeAudio{}); },
[&] { return m_BassThemeAudioInstances.emplace_back(new BassMusicThemeAudio{}); },
[&](const BassMusicThemeAudio* input, const zCPar_Symbol* symbol) {
const std::shared_ptr<NH::Bass::MusicTheme> theme = NH::Bass::Engine::GetInstance()->GetMusicManager().GetTheme(input->Theme.ToChar());
if (!theme) {
Expand Down
20 changes: 10 additions & 10 deletions src/Gothic/CMusicSys_Bass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace GOTHIC_NAMESPACE
{
namespace BassEvent
{
inline void Event_OnEnd(const NH::Bass::Event& event, void* userData)
inline void Event_OnEnd(const NH::Bass::Event& event, [[maybe_unused]] void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnEnd");

Expand All @@ -20,7 +20,7 @@ namespace GOTHIC_NAMESPACE
}
}

inline void Event_OnTransition(const NH::Bass::Event& event, void* userData)
inline void Event_OnTransition(const NH::Bass::Event& event, [[maybe_unused]] void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnTransition");

Expand All @@ -38,7 +38,7 @@ namespace GOTHIC_NAMESPACE
}
}

inline void Event_OnChange(const NH::Bass::Event& event, void* userData)
inline void Event_OnChange(const NH::Bass::Event& event, [[maybe_unused]] void* userData)
{
static NH::Logger* log = NH::CreateLogger("zBassMusic::Event_OnChange");

Expand Down Expand Up @@ -72,14 +72,14 @@ namespace GOTHIC_NAMESPACE
{
static constexpr std::string_view validExt{ ".sgt" };

if (file.Length() < validExt.size())
if (static_cast<uint32_t>(file.Length()) < validExt.size())
{
return false;
}

const auto fileLen = static_cast<size_t>(file.Length());
const auto extStart = fileLen - validExt.size();
const std::string_view fileExt{ std::next(file.ToChar(), static_cast<uint32_t>(extStart)), validExt.size() };
const std::string_view fileExt{ std::next(file.ToChar(), extStart), validExt.size() };

auto toLowerSimple = [](const char t_char)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace GOTHIC_NAMESPACE
}
}

void PlayTheme(zCMusicTheme* theme, float const& volume, zTMus_TransType const& transition, zTMus_TransSubType const& subTransition) override
void PlayTheme(zCMusicTheme* theme, float const& themeVolume, zTMus_TransType const& transition, zTMus_TransSubType const& subTransition) override
{
if (theme == nullptr) {
log->Error("PlayTheme illegal argument: theme == nullptr");
Expand All @@ -190,7 +190,7 @@ namespace GOTHIC_NAMESPACE
{
m_BassEngine->StopMusic();
m_ActiveTheme = theme;
m_DirectMusic->PlayTheme(theme, volume, transition, subTransition);
m_DirectMusic->PlayTheme(theme, themeVolume, transition, subTransition);
return;
}

Expand Down Expand Up @@ -231,10 +231,10 @@ namespace GOTHIC_NAMESPACE
return m_BassEngine->GetVolume();
}

void SetVolume(const float volume) override
void SetVolume(const float masterVolume) override
{
m_BassEngine->SetVolume(volume);
m_DirectMusic->SetVolume(volume);
m_BassEngine->SetVolume(masterVolume);
m_DirectMusic->SetVolume(masterVolume);
}

int IsAvailable(zSTRING const& id) override
Expand Down
12 changes: 6 additions & 6 deletions src/NH/Bass/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace NH::Bass

void Channel::OnPosition(const double position, const std::function<void()>& callback)
{
const size_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position);
const int64_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position);
BASS_ChannelSetSync(m_Stream, BASS_SYNC_POS, positionBytes, OnPositionSyncCallFunction, new OnSyncPosition{m_Stream, callback});
}

Expand All @@ -89,7 +89,7 @@ namespace NH::Bass
void Channel::BeforeAudioEnds(const double aheadSeconds, const std::function<void(double)>& onFinish)
{
const double position = Length() - aheadSeconds;
const size_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position);
const int64_t positionBytes = BASS_ChannelSeconds2Bytes(m_Stream, position);
BASS_ChannelSetSync(m_Stream, BASS_SYNC_POS, positionBytes, BeforeAudioEndsSyncCallFunction, new OnSyncBeforeAudioEndsData{m_Stream, onFinish});
}

Expand Down Expand Up @@ -131,29 +131,29 @@ namespace NH::Bass
return -1;
}

void Channel::OnPositionSyncCallFunction(HSYNC, const DWORD channel, DWORD data, void* userData)
void Channel::OnPositionSyncCallFunction(HSYNC, const DWORD channel, [[maybe_unused]] DWORD data, void* userData)
{
const auto* payload = static_cast<OnSyncWhenAudioEndsData*>(userData);
if (channel != payload->Channel) return;
if (payload->Function) { payload->Function(); }
else { CreateLogger("HSYNC::OnPositionSyncCallFunction")->Error("onFinish is nullptr"); }
}

void Channel::OnSlideVolumeSyncCallFunction(HSYNC, DWORD channel, DWORD data, void* userData)
void Channel::OnSlideVolumeSyncCallFunction(HSYNC, [[maybe_unused]] DWORD channel, [[maybe_unused]] DWORD data, void* userData)
{
if (const auto* onFinish = static_cast<std::function<void()>*>(userData)) { (*onFinish)(); }
else { CreateLogger("HSYNC::OnSlideVolumeSyncCallFunction")->Error("onFinish is nullptr"); }
}

void Channel::OnAudioEndSyncCallFunction(HSYNC, const DWORD channel, DWORD data, void* userData)
void Channel::OnAudioEndSyncCallFunction(HSYNC, const DWORD channel, [[maybe_unused]] DWORD data, void* userData)
{
const auto* payload = static_cast<OnSyncWhenAudioEndsData*>(userData);
if (channel != payload->Channel) return;
if (payload->Function) { payload->Function(); }
else { CreateLogger("HSYNC::OnAudioEndSyncCallFunction")->Error("onFinish is nullptr"); }
}

void Channel::BeforeAudioEndsSyncCallFunction(HSYNC, const DWORD channel, DWORD data, void* userData)
void Channel::BeforeAudioEndsSyncCallFunction(HSYNC, const DWORD channel, [[maybe_unused]] DWORD data, void* userData)
{
const auto* payload = static_cast<OnSyncBeforeAudioEndsData*>(userData);
if (channel != payload->Channel) return;
Expand Down
2 changes: 1 addition & 1 deletion src/NH/Bass/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace NH::Bass

m_CommandQueue.Update(*this);

BASS_Update(delta);
BASS_Update(static_cast<int32_t>(delta));
GetEM().Update();
}

Expand Down
6 changes: 3 additions & 3 deletions src/NH/Bass/MusicTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ namespace NH::Bass

std::shared_ptr<IChannel> MusicTheme::GetAcquiredChannel() const
{
for (const auto& channel: m_AcquiredChannels)
if (m_AcquiredChannels.size() > 0)
{
return channel;
return m_AcquiredChannels[0];
}
return {};
}
Expand All @@ -356,7 +356,7 @@ namespace NH::Bass
std::string MusicTheme::ToString() const
{
std::string result = "MusicTheme{ \n\tName: " + m_Name + ", \n\tAudioFiles: {\n";
int i = 0;
size_t i = 0;
for (auto& [type, audioFile]: m_AudioFiles)
{
result += "\t\t" + type + ": " + String(audioFile.ToString().c_str()).Replace("\n", "\n\tt").ToChar();
Expand Down
2 changes: 1 addition & 1 deletion src/NH/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace NH
template<class T>
T* GetAdapter() const
{
for (int i = 0; i < m_Adapters.GetCount(); i++)
for (size_t i = 0; i < m_Adapters.GetCount(); i++)
{
ILoggerAdapter* adapter = m_Adapters[i];
if (T* ptr = dynamic_cast<T*>(adapter))
Expand Down
1 change: 0 additions & 1 deletion vdf/vdf.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
file(MAKE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
file(COPY "${CMAKE_INSTALL_PREFIX}/bin/zBassMusic.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
file(COPY "${CMAKE_INSTALL_PREFIX}/bin/UnionAPI.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
file(COPY "${CMAKE_INSTALL_PREFIX}/bin/bass.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
file(COPY "${CMAKE_INSTALL_PREFIX}/bin/bassmidi.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
file(COPY "${CMAKE_INSTALL_PREFIX}/bin/bassflac.dll" DESTINATION "${CMAKE_INSTALL_PREFIX}/vdf/System/Autorun")
Expand Down

0 comments on commit 07e75a3

Please sign in to comment.