From 74f12f3f2bb6cafc25ba1e943d01583b1ac0d766 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Thu, 22 May 2025 14:52:20 -0300 Subject: rename `main.hh` to `common.hh` --- src/common.hh | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/config.hh | 2 +- src/connection.hh | 2 +- src/containers.hh | 2 +- src/creature.hh | 2 +- src/enums.hh | 2 +- src/main.cc | 2 +- src/main.hh | 136 --------------------------------------------------- src/map.hh | 2 +- src/monster.hh | 2 +- src/player.hh | 2 +- src/script.hh | 2 +- src/shm.cc | 2 +- src/skill.hh | 2 +- src/thread.hh | 2 +- src/time.cc | 2 +- src/util.cc | 2 +- 17 files changed, 157 insertions(+), 151 deletions(-) create mode 100644 src/common.hh delete mode 100644 src/main.hh (limited to 'src') diff --git a/src/common.hh b/src/common.hh new file mode 100644 index 0000000..b057465 --- /dev/null +++ b/src/common.hh @@ -0,0 +1,142 @@ +#ifndef TIBIA_COMMON_HH_ +#define TIBIA_COMMON_HH_ 1 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uintptr_t uintptr; +typedef size_t usize; + +#define STATIC_ASSERT(expr) static_assert((expr), "static assertion failed: " #expr) +#define NARRAY(arr) (sizeof(arr) / sizeof(arr[0])) +#define ISPOW2(x) ((x) != 0 && ((x) & ((x) - 1)) == 0) +#define KB(x) ((usize)(x) << 10) +#define MB(x) ((usize)(x) << 20) +#define GB(x) ((usize)(x) << 30) + +// TODO(fusion): We might not actually compile the output for the decompilation +// step but if we did, we'd need to make sure we're compiling in 32 bits mode. +STATIC_ASSERT(sizeof(bool) == 1); +STATIC_ASSERT(sizeof(int) == 4); +//STATIC_ASSERT(sizeof(void*) == 4); + +#if !OS_WINDOWS && !OS_LINUX +# if defined(_WIN32) +# define OS_WINDOWS 1 +# elif defined(__linux__) || defined(__gnu_linux__) +# define OS_LINUX 1 +# else +# error "Operating system not supported." +# endif +#endif + +#if !COMPILER_MSVC && !COMPILER_GCC && !COMPILER_CLANG +# if defined(_MSC_VER) +# define COMPILER_MSVC 1 +# elif defined(__GNUC__) +# define COMPILER_GCC 1 +# elif defined(__clang__) +# define COMPILER_CLANG 1 +# endif +#endif + +// NOTE(fusion): Compiler attributes. +#if COMPILER_GCC || COMPILER_CLANG +# define ATTR_FALLTHROUGH __attribute__((fallthrough)) +# define ATTR_PRINTF(x, y) __attribute__((format(printf, x, y))) +#else +# define ATTR_FALLTHROUGH +# define ATTR_PRINTF(x, y) +#endif + +#if COMPILER_MSVC +# define TRAP() __debugbreak(); +#elif COMPILER_GCC || COMPILER_CLANG +# define TRAP() __builtin_trap() +#else +# define TRAP() abort() +#endif + +#define ASSERT_ALWAYS(expr) if(!(expr)) { TRAP(); } +#if BUILD_DEBUG +# define ASSERT(expr) ASSERT_ALWAYS(expr) +#else +# define ASSERT(expr) ((void)(expr)) +#endif + +// TODO(fusion): We should re-implement the multi-process structure used by the +// original code but only for reference. Making it compile on Windows shouldn't +// be too difficult either. Overall this design is outdated and should be reviewed. +// Nevertheless, we should focus on getting it working as intended, on the target +// platform (which is Linux 32-bits) before attempting to refine it. +//STATIC_ASSERT(OS_LINUX); +//#include +typedef int pid_t; +// + +// shm.cc +// ============================================================================= +void StartGame(void); +void CloseGame(void); +void EndGame(void); +bool LoginAllowed(void); +bool GameRunning(void); +bool GameStarting(void); +bool GameEnding(void); +pid_t GetGameThreadPID(void); +int GetPrintlogPosition(void); +char *GetPrintlogLine(int Line); +void IncrementObjectCounter(void); +void DecrementObjectCounter(void); +uint32 GetObjectCounter(void); +void IncrementPlayersOnline(void); +void DecrementPlayersOnline(void); +int GetPlayersOnline(void); +void IncrementNewbiesOnline(void); +void DecrementNewbiesOnline(void); +int GetNewbiesOnline(void); +void SetRoundNr(uint32 RoundNr); +uint32 GetRoundNr(void); +void SetCommand(int Command, char *Text); +int GetCommand(void); +char *GetCommandBuffer(void); +void InitSHM(bool Verbose); +void ExitSHM(void); +void InitSHMExtern(bool Verbose); +void ExitSHMExtern(void); + +// time.cc +// ============================================================================= +extern uint32 RoundNr; +extern uint32 ServerMilliseconds; + +void GetRealTime(int *Hour, int *Minute); +void GetTime(int *Hour, int *Minute); +void GetDate(int *Year, int *Cycle, int *Day); +void GetAmbiente(int *Brightness, int *Color); +uint32 GetRoundAtTime(int Hour, int Minute); +uint32 GetRoundForNextMinute(void); + +// util.cc +// ============================================================================= +typedef void TErrorFunction(const char *Text); +typedef void TPrintFunction(int Level, const char *Text); +void SetErrorFunction(TErrorFunction *Function); +void SetPrintFunction(TPrintFunction *Function); +void error(char *Text, ...) ATTR_PRINTF(1, 2); +void print(int Level, char *Text, ...) ATTR_PRINTF(1, 2); + +// + +#endif //TIBIA_COMMON_HH_ diff --git a/src/config.hh b/src/config.hh index c2f1e14..dea3ce1 100644 --- a/src/config.hh +++ b/src/config.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_CONFIG_HH_ #define TIBIA_CONFIG_HH_ 1 -#include "main.hh" +#include "common.hh" #include "enums.hh" struct TDatabaseSettings { diff --git a/src/connection.hh b/src/connection.hh index 724ac91..2eafcde 100644 --- a/src/connection.hh +++ b/src/connection.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_CONNECTION_HH_ #define TIBIA_CONNECTION_HH_ 1 -#include "main.hh" +#include "common.hh" #include "enums.hh" struct TConnection; diff --git a/src/containers.hh b/src/containers.hh index f249c81..8000d3c 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_CONTAINERS_HH_ #define TIBIA_CONTAINERS_HH_ 1 -#include "main.hh" +#include "common.hh" // NOTE(fusion): What the actual fuck. This is an ever growing dynamic array // with each access through `operator()` growing it to make sure the requested diff --git a/src/creature.hh b/src/creature.hh index 2b19836..a147091 100644 --- a/src/creature.hh +++ b/src/creature.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_CREATURE_HH_ #define TIBIA_CREATURE_HH_ 1 -#include "main.hh" +#include "common.hh" #include "connection.hh" #include "containers.hh" #include "skill.hh" diff --git a/src/enums.hh b/src/enums.hh index bc3dab0..d4ba042 100644 --- a/src/enums.hh +++ b/src/enums.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_ENUMS_HH_ #define TIBIA_ENUMS_HH_ 1 -#include "main.hh" +#include "common.hh" // TODO(fusion): Probably cleanup these names? Prefix values? Its crazy that // there are no collision problems (possibly yet). diff --git a/src/main.cc b/src/main.cc index a930aef..1efdf4a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,4 @@ -#include "main.hh" +#include "common.hh" #include "config.hh" #include diff --git a/src/main.hh b/src/main.hh deleted file mode 100644 index 7aa329a..0000000 --- a/src/main.hh +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef TIBIA_MAIN_HH_ -#define TIBIA_MAIN_HH_ 1 - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uintptr_t uintptr; -typedef size_t usize; - -#define STATIC_ASSERT(expr) static_assert((expr), "static assertion failed: " #expr) -#define NARRAY(arr) (sizeof(arr) / sizeof(arr[0])) -#define ISPOW2(x) ((x) != 0 && ((x) & ((x) - 1)) == 0) -#define KB(x) ((usize)(x) << 10) -#define MB(x) ((usize)(x) << 20) -#define GB(x) ((usize)(x) << 30) - -// TODO(fusion): We might not actually compile the output for the decompilation -// step but if we did, we'd need to make sure we're compiling in 32 bits mode. -STATIC_ASSERT(sizeof(bool) == 1); -STATIC_ASSERT(sizeof(int) == 4); -//STATIC_ASSERT(sizeof(void*) == 4); - -#if !OS_WINDOWS && !OS_LINUX -# if defined(_WIN32) -# define OS_WINDOWS 1 -# elif defined(__linux__) || defined(__gnu_linux__) -# define OS_LINUX 1 -# else -# error "Operating system not supported." -# endif -#endif - -#if !COMPILER_MSVC && !COMPILER_GCC && !COMPILER_CLANG -# if defined(_MSC_VER) -# define COMPILER_MSVC 1 -# elif defined(__GNUC__) -# define COMPILER_GCC 1 -# elif defined(__clang__) -# define COMPILER_CLANG 1 -# endif -#endif - -// NOTE(fusion): Compiler attributes. -#if COMPILER_GCC || COMPILER_CLANG -# define ATTR_FALLTHROUGH __attribute__((fallthrough)) -# define ATTR_PRINTF(x, y) __attribute__((format(printf, x, y))) -#else -# define ATTR_FALLTHROUGH -# define ATTR_PRINTF(x, y) -#endif - -#if COMPILER_MSVC -# define TRAP() __debugbreak(); -#elif COMPILER_GCC || COMPILER_CLANG -# define TRAP() __builtin_trap() -#else -# define TRAP() abort() -#endif - -#define ASSERT_ALWAYS(expr) if(!(expr)) { TRAP(); } -#if BUILD_DEBUG -# define ASSERT(expr) ASSERT_ALWAYS(expr) -#else -# define ASSERT(expr) ((void)(expr)) -#endif - -// TODO(fusion): We should re-implement the multi-process structure used by the -// original code but only for reference. Making it compile on Windows shouldn't -// be too difficult either. Overall this design is outdated and should be reviewed. -// Nevertheless, we should focus on getting it working as intended, on the target -// platform (which is Linux 32-bits) before attempting to refine it. -//STATIC_ASSERT(OS_LINUX); -//#include -typedef int pid_t; -// - -// shm.cc -void StartGame(void); -void CloseGame(void); -void EndGame(void); -bool LoginAllowed(void); -bool GameRunning(void); -bool GameStarting(void); -bool GameEnding(void); -pid_t GetGameThreadPID(void); -int GetPrintlogPosition(void); -char *GetPrintlogLine(int Line); -void IncrementObjectCounter(void); -void DecrementObjectCounter(void); -uint32 GetObjectCounter(void); -void IncrementPlayersOnline(void); -void DecrementPlayersOnline(void); -int GetPlayersOnline(void); -void IncrementNewbiesOnline(void); -void DecrementNewbiesOnline(void); -int GetNewbiesOnline(void); -void SetRoundNr(uint32 RoundNr); -uint32 GetRoundNr(void); -void SetCommand(int Command, char *Text); -int GetCommand(void); -char *GetCommandBuffer(void); -void InitSHM(bool Verbose); -void ExitSHM(void); -void InitSHMExtern(bool Verbose); -void ExitSHMExtern(void); - -// time.cc -extern uint32 RoundNr; -extern uint32 ServerMilliseconds; -void GetRealTime(int *Hour, int *Minute); -void GetTime(int *Hour, int *Minute); -void GetDate(int *Year, int *Cycle, int *Day); -void GetAmbiente(int *Brightness, int *Color); -uint32 GetRoundAtTime(int Hour, int Minute); -uint32 GetRoundForNextMinute(void); - -// util.cc -typedef void TErrorFunction(const char *Text); -typedef void TPrintFunction(int Level, const char *Text); -void SetErrorFunction(TErrorFunction *Function); -void SetPrintFunction(TPrintFunction *Function); -void error(char *Text, ...) ATTR_PRINTF(1, 2); -void print(int Level, char *Text, ...) ATTR_PRINTF(1, 2); - -#endif //TIBIA_MAIN_HH_ diff --git a/src/map.hh b/src/map.hh index 7bef02b..298d190 100644 --- a/src/map.hh +++ b/src/map.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_MAP_HH_ #define TIBIA_MAP_HH_ 1 -#include "main.hh" +#include "common.hh" // TODO(fusion): I'm not sure whether to put these. diff --git a/src/monster.hh b/src/monster.hh index 7e18f48..b9bd27e 100644 --- a/src/monster.hh +++ b/src/monster.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_MONSTER_HH_ #define TIBIA_MONSTER_HH_ 1 -#include "main.hh" +#include "common.hh" #include "creature.hh" #include "containers.hh" #include "enums.hh" diff --git a/src/player.hh b/src/player.hh index 0a3f583..f0c4a82 100644 --- a/src/player.hh +++ b/src/player.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_PLAYER_HH_ #define TIBIA_PLAYER_HH_ 1 -#include "main.hh" +#include "common.hh" #include "creature.hh" #include "containers.hh" diff --git a/src/script.hh b/src/script.hh index 5b63f56..0a83196 100644 --- a/src/script.hh +++ b/src/script.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_SCRIPT_HH_ #define TIBIA_SCRIPT_HH_ 1 -#include "main.hh" +#include "common.hh" #include "enums.hh" struct TReadScriptFile { diff --git a/src/shm.cc b/src/shm.cc index 5cd4a52..c26638f 100644 --- a/src/shm.cc +++ b/src/shm.cc @@ -1,4 +1,4 @@ -#include "main.hh" +#include "common.hh" // NOTE(fusion): This looks like an interface to external tools. Looking at the // `bin` directory this program was in, there are other programs that probably diff --git a/src/skill.hh b/src/skill.hh index c3beff6..353eb7d 100644 --- a/src/skill.hh +++ b/src/skill.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_SKILL_HH_ #define TIBIA_SKILL_HH_ 1 -#include "main.hh" +#include "common.hh" struct TCreature; diff --git a/src/thread.hh b/src/thread.hh index a3b0d04..825b330 100644 --- a/src/thread.hh +++ b/src/thread.hh @@ -1,7 +1,7 @@ #ifndef TIBIA_THREAD_HH_ #define TIBIA_THREAD_HH_ 1 -#include "main.hh" +#include "common.hh" #include typedef pthread_t ThreadHandle; diff --git a/src/time.cc b/src/time.cc index 89325ba..4e743ed 100644 --- a/src/time.cc +++ b/src/time.cc @@ -1,4 +1,4 @@ -#include "main.hh" +#include "common.hh" // IMPORTANT(fusion): `RoundNr` is just the number of seconds since startup which // is why `GetRoundAtTime` and `GetRoundForNextMinute` straight up uses it as diff --git a/src/util.cc b/src/util.cc index 4f74c80..74c1bf5 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,4 +1,4 @@ -#include "main.hh" +#include "common.hh" static void (*ErrorFunction)(const char *Text) = NULL; static void (*PrintFunction)(int Level, const char *Text) = NULL; -- cgit v1.2.3