Skip to content

Commit

Permalink
Refactor multiplatform calls
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmacha committed Jun 29, 2023
1 parent e26c871 commit 7a193e5
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 95 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
set(PROJECT_VERSION "0.0.2")
set(PROJECT_VERSION "0.0.4")
if(DEFINED ENV{PROJECT_VERSION})
set(PROJECT_VERSION "$ENV{PROJECT_VERSION}")
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Download `zBassMusic.vdf` and place it inside `<GOTHIC_ROOT>/Data` with Union in
```cpp
instance SYS_MENU(C_MUSICTHEME_DEF)
{
// wav file will load and play instead of .sgt
file = "modern_audio_file.wav";
// wav file will load and play instead of .sgt
file = "modern_audio_file.wav";
// file = "gamestart.sgt";
transtype = TRANSITION_TYPE_NONE;
transsubtype = TRANSITION_SUB_TYPE_BEAT;
Expand Down
12 changes: 11 additions & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Options reference (.ini)
```
```ini
[BASSMUSIC]

; Transition time between audio themes in miliseconds
TransitionTime = 2000.0

; Disable reverb effect globally
ForceDisableReverb = false

; Force fade-in fade-out transition even if theme doesn't specify it
ForceFadeTransition = false

; Creates C_MUSICTHEME class in main parser to make it easier to use scriptable interface.
; It does not provide any coop with music parser.
CreateMainParserCMusicTheme = true

; Logger level for Union console (DEBUG, INFO, WARN, ERROR, OFF)
LoggerLevelUnion=INFO

; Logger level for ZSpy console (DEBUG, INFO, WARN, ERROR, OFF)
LoggerLevelZSpy=DEBUG
```
4 changes: 2 additions & 2 deletions docs/transitions-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ zBassMusic can transition between music themes using simple fade-out and fade-in

To use transitions, at least one must be true:
* **C_MUSICTHEME.transtype == zMUS_TR_INTRO (5)**: theme will use fade-in
* **C_MUSICTHEME.transtype == zMUS_TR_END (5)**: theme will use fade-out
* **C_MUSICTHEME.transtype == zMUS_TR_ENDANDINTRO (5)**: theme will use both fade-in and fade-out
* **C_MUSICTHEME.transtype == zMUS_TR_END (6)**: theme will use fade-out
* **C_MUSICTHEME.transtype == zMUS_TR_ENDANDINTRO (7)**: theme will use both fade-in and fade-out
* **BASSMUSIC.ForceFadeTransition** ini is set true, all themes will use both fade-in and fade-out

Transition time can be set by **BASSMUSIC.TransitionTime** ini option.
Expand Down
34 changes: 0 additions & 34 deletions plugin/src/Gothic/Externals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ namespace GOTHIC_NAMESPACE

void DefineExternals()
{
if (GetGameVersion() != ENGINE)
{
return;
}

parser->DefineExternalVar("BassMusic_ActiveThemeFilename", &Globals->BassMusic_ActiveThemeFilename, zPAR_TYPE_STRING, 1);
parser->DefineExternalVar("BassMusic_ActiveThemeID", &Globals->BassMusic_ActiveThemeID, zPAR_TYPE_STRING, 1);
parser->DefineExternalVar("BassMusic_EventThemeFilename", &Globals->BassMusic_EventThemeFilename, zPAR_TYPE_STRING, 1);
Expand All @@ -99,33 +94,4 @@ namespace GOTHIC_NAMESPACE
parser->AddClassOffset(Globals->CMusicThemeClass, reinterpret_cast<int>(&theme.dScriptEnd) - reinterpret_cast<int>(&theme.fileName));
}
}

void InitInstances()
{
if (GetGameVersion() != ENGINE)
{
return;
}

if (NH::Bass::Options.CreateMainParserCMusicTheme)
{
//const int classIndex = parser->GetIndex(Globals->CMusicThemeClass);
//if (classIndex < 0)
//{
// return;
//}
//int position = 0;
//while (position >= 0)
//{
// position = parser->GetInstance(classIndex, position + 1);
// if(position > 0) {
// const zCPar_Symbol* sym = parser->GetSymbol(position);
// if (sym->type == zPAR_TYPE_INSTANCE) {
// zCMusicTheme* musicTheme = zNEW(zCMusicTheme);
// parser->CreateInstance(position, musicTheme);
// }
// }
//}
}
}
}
13 changes: 8 additions & 5 deletions plugin/src/Gothic/Options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ namespace GOTHIC_NAMESPACE
{
void ApplyOptions()
{
if (GetGameVersion() != ENGINE)
{
return;
}

NH::Bass::Options.TransitionTime = zoptions->ReadReal("BASSMUSIC", "TransitionTime", 2000.0f);
NH::Bass::Options.ForceDisableReverb = zoptions->ReadBool("BASSMUSIC", "ForceDisableReverb", false);
NH::Bass::Options.ForceFadeTransition = zoptions->ReadBool("BASSMUSIC", "ForceFadeTransition", false);
NH::Bass::Options.CreateMainParserCMusicTheme = zoptions->ReadBool("BASSMUSIC", "CreateMainParserCMusicTheme", true);
{
char* value = zoptions->ReadString("BASSMUSIC", "LoggerLevelUnion", "INFO").ToChar();
NH::Bass::Options.LoggerLevelUnion = Union::StringUTF8(value);
}
{
char* value = zoptions->ReadString("BASSMUSIC", "LoggerLevelZSpy", "DEBUG").ToChar();
NH::Bass::Options.LoggerLevelZSpy = Union::StringUTF8(value);
}
}
}
4 changes: 4 additions & 0 deletions plugin/src/NH/BassOptions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <Union/String.h>

namespace NH
{
namespace Bass
Expand All @@ -10,6 +12,8 @@ namespace NH
bool ForceDisableReverb = false;
bool ForceFadeTransition = false;
bool CreateMainParserCMusicTheme = true;
Union::StringUTF8 LoggerLevelUnion = "INFO";
Union::StringUTF8 LoggerLevelZSpy = "DEBUG";
};

extern BassOptions Options;
Expand Down
69 changes: 40 additions & 29 deletions plugin/src/NH/Union.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,55 @@
#include "Union.h"
#include <ZenGin/zGothicAPI.h>
#include <NH/BassOptions.h>

namespace NH
{
namespace Log
{
inline bool ShouldLog(Level level, Union::StringUTF8 config)
{
if (level == Level::DEBUG) return config == "DEBUG";
if (level == Level::INFO) return config == "DEBUG" || config == "INFO";
if (level == Level::WARN) return config == "DEBUG" || config == "INFO" || config == "WARN";
if (level == Level::ERROR) return config == "DEBUG" || config == "INFO" || config == "WARN" || config == "ERROR";
return false;
}

void Message(Level level, Union::StringUTF8 channel, Union::StringUTF8 message)
{
Union::StringUTF8 output = "";
switch (level)
{
case Level::DEBUG:
output = Union::StringUTF8::Format("\x1B[1;97;45mzBassMusic DEBUG \x1B[0m\x1B[95m %s: %s", channel, message);
break;
case Level::INFO:
output = Union::StringUTF8::Format("\x1B[1m\x1B[37m\x1B[44mzBassMusic INFO \x1B[0m\x1B[94m %s: %s", channel, message);
break;
case Level::WARN:
output = Union::StringUTF8::Format("\x1B[1m\x1B[37m\x1B[43mzBassMusic WARN \x1B[0m\x1B[93m %s: %s", channel, message);
break;
case Level::ERROR:
output = Union::StringUTF8::Format("\x1B[1m\x1B[97m\x1B[41mzBassMusic ERROR \x1B[0m\x1B[91m %s: %s", channel, message);
break;
if (ShouldLog(level, NH::Bass::Options.LoggerLevelUnion)) {
Union::StringUTF8 output = "";
switch (level)
{
case Level::DEBUG:
output = Union::StringUTF8::Format("\x1B[1;97;45mzBassMusic DEBUG \x1B[0m\x1B[95m %s: %s", channel, message);
break;
case Level::INFO:
output = Union::StringUTF8::Format("\x1B[1m\x1B[37m\x1B[44mzBassMusic INFO \x1B[0m\x1B[94m %s: %s", channel, message);
break;
case Level::WARN:
output = Union::StringUTF8::Format("\x1B[1m\x1B[37m\x1B[43mzBassMusic WARN \x1B[0m\x1B[93m %s: %s", channel, message);
break;
case Level::ERROR:
output = Union::StringUTF8::Format("\x1B[1m\x1B[97m\x1B[41mzBassMusic ERROR \x1B[0m\x1B[91m %s: %s", channel, message);
break;
}
output.StdPrintLine();
}
output.StdPrintLine();

#ifdef __G1
if (GetGameVersion() == Engine_G1)
{
auto msg = Gothic_I_Classic::zSTRING("B:\tBASSMUSIC: ") + Gothic_I_Classic::zSTRING(channel.ToChar()) + Gothic_I_Classic::zSTRING(": ") + Gothic_I_Classic::zSTRING(message.ToChar());
Gothic_I_Classic::zerr->Message(msg);
}
#endif
#ifdef __G2A
if (GetGameVersion() == Engine_G2A)
{
auto msg = Gothic_II_Addon::zSTRING("B:\tBASSMUSIC: ") + Gothic_II_Addon::zSTRING(channel.ToChar()) + Gothic_II_Addon::zSTRING(": ") + Gothic_II_Addon::zSTRING(message.ToChar());
Gothic_II_Addon::zerr->Message(msg);
if (ShouldLog(level, NH::Bass::Options.LoggerLevelZSpy)) {
if (GetGameVersion() == Engine_G1)
{
auto msg = Gothic_I_Classic::zSTRING("B:\tBASSMUSIC: ") + Gothic_I_Classic::zSTRING(channel.ToChar()) + Gothic_I_Classic::zSTRING(": ") + Gothic_I_Classic::zSTRING(message.ToChar());
Gothic_I_Classic::zerr->Message(msg);
}

if (GetGameVersion() == Engine_G2A)
{
auto msg = Gothic_II_Addon::zSTRING("B:\tBASSMUSIC: ") + Gothic_II_Addon::zSTRING(channel.ToChar()) + Gothic_II_Addon::zSTRING(": ") + Gothic_II_Addon::zSTRING(message.ToChar());
Gothic_II_Addon::zerr->Message(msg);
}
}
#endif
}
}
}
39 changes: 18 additions & 21 deletions plugin/src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@ HOOKSPACE(Gothic_II_Addon, GetGameVersion() == ENGINE);
HOOKSPACE(Global, true);

EXTERN_C_START
__declspec(dllexport) void Game_Init() {
#ifdef __G1
Gothic_I_Classic::InitInstances();
#endif
#ifdef __G2A
Gothic_II_Addon::InitInstances();
#endif
}

__declspec(dllexport) void Game_ApplyOptions() {
#ifdef __G1
Gothic_I_Classic::ApplyOptions();
#endif
#ifdef __G2A
Gothic_II_Addon::ApplyOptions();
#endif
switch (GetGameVersion())
{
case Engine_G1:
Gothic_I_Classic::ApplyOptions();
break;
case Engine_G2A:
Gothic_II_Addon::ApplyOptions();
break;
}
}

__declspec(dllexport) void Game_DefineExternals() {
#ifdef __G1
Gothic_I_Classic::DefineExternals();
#endif
#ifdef __G2A
Gothic_II_Addon::DefineExternals();
#endif
switch (GetGameVersion())
{
case Engine_G1:
Gothic_I_Classic::DefineExternals();
break;
case Engine_G2A:
Gothic_II_Addon::DefineExternals();
break;
}
}
EXTERN_C_END

0 comments on commit 7a193e5

Please sign in to comment.