From 9d6836478156fb4be8e39409714c34db0ff62f21 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 13 Jun 2020 11:13:41 +1000 Subject: [PATCH] Combine GameStructs.h into Game.h Also breaks all plugin source code, sorry about that --- doc/plugin-dev.md | 4 ++-- src/Audio.c | 1 - src/AxisLinesRenderer.c | 1 - src/Block.c | 1 - src/Builder.c | 1 - src/Chat.c | 1 - src/Drawer2D.c | 1 - src/Entity.c | 1 - src/EnvRenderer.c | 1 - src/Game.c | 1 - src/Game.h | 36 +++++++++++++++++++++++++++++++++++- src/GameStructs.h | 41 ----------------------------------------- src/Gui.c | 1 - src/HeldBlockRenderer.c | 1 - src/Http.c | 2 +- src/Inventory.c | 1 - src/Launcher.c | 1 - src/Lighting.c | 2 +- src/MapRenderer.c | 1 - src/Model.c | 1 - src/Particle.c | 1 - src/PickedPosRenderer.c | 1 - src/Protocol.c | 1 - src/SelectionBox.c | 1 - src/Server.c | 1 - src/TexturePack.c | 1 - 26 files changed, 39 insertions(+), 67 deletions(-) delete mode 100644 src/GameStructs.h diff --git a/doc/plugin-dev.md b/doc/plugin-dev.md index d41e9117f..b689f1855 100644 --- a/doc/plugin-dev.md +++ b/doc/plugin-dev.md @@ -36,7 +36,7 @@ Here's the idea for a basic plugin that shows "Hello world" in chat when the gam ### Basic plugin boilerplate ```C #include "src/Chat.h" -#include "src/GameStructs.h" +#include "src/Game.h" #ifdef CC_BUILD_WIN #define CC_API __declspec(dllimport) @@ -66,7 +66,7 @@ When writing plugins with C++, game headers must be surroundined with `extern "C ```C extern "C" { #include "src/Chat.h" -#include "src/GameStructs.h" +#include "src/Game.h" } ``` Otherwise you will get obscure `Undefined reference` errors when compiling. diff --git a/src/Audio.c b/src/Audio.c index a09c0555d..3532be862 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -5,7 +5,6 @@ #include "ExtMath.h" #include "Funcs.h" #include "Game.h" -#include "GameStructs.h" #include "Errors.h" #include "Vorbis.h" #include "Chat.h" diff --git a/src/AxisLinesRenderer.c b/src/AxisLinesRenderer.c index aedb70ef1..dbd86cec8 100644 --- a/src/AxisLinesRenderer.c +++ b/src/AxisLinesRenderer.c @@ -6,7 +6,6 @@ #include "Camera.h" #include "Event.h" #include "Entity.h" -#include "GameStructs.h" cc_bool AxisLinesRenderer_Enabled; static GfxResourceID axisLines_vb; diff --git a/src/Block.c b/src/Block.c index bdc5aae71..f708a6770 100644 --- a/src/Block.c +++ b/src/Block.c @@ -7,7 +7,6 @@ #include "Inventory.h" #include "Event.h" #include "Platform.h" -#include "GameStructs.h" struct _BlockLists Blocks; diff --git a/src/Builder.c b/src/Builder.c index e0ea592ca..5f26898b6 100644 --- a/src/Builder.c +++ b/src/Builder.c @@ -14,7 +14,6 @@ #include "TexturePack.h" #include "Game.h" #include "Options.h" -#include "GameStructs.h" int Builder_SidesLevel, Builder_EdgeLevel; /* Packs an index into the 16x16x16 count array. Coordinates range from 0 to 15. */ diff --git a/src/Chat.c b/src/Chat.c index 934230447..32be44a23 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -13,7 +13,6 @@ #include "Funcs.h" #include "Block.h" #include "EnvRenderer.h" -#include "GameStructs.h" #include "Utils.h" #include "TexturePack.h" #include "Options.h" diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 3876983ed..1f0795e83 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -12,7 +12,6 @@ #include "Errors.h" #include "Window.h" #include "Options.h" -#include "GameStructs.h" cc_bool Drawer2D_BitmappedText; cc_bool Drawer2D_BlackTextShadows; diff --git a/src/Entity.c b/src/Entity.c index 3b5514705..9a9c9b3c4 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -21,7 +21,6 @@ #include "Logger.h" #include "Options.h" #include "Errors.h" -#include "GameStructs.h" const char* const NameMode_Names[NAME_MODE_COUNT] = { "None", "Hovered", "All", "AllHovered", "AllUnscaled" }; const char* const ShadowMode_Names[SHADOW_MODE_COUNT] = { "None", "SnapToBlock", "Circle", "CircleAll" }; diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index c2d518456..419db6158 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -17,7 +17,6 @@ #include "Camera.h" #include "Particle.h" #include "Options.h" -#include "GameStructs.h" cc_bool EnvRenderer_Legacy, EnvRenderer_Minimal; diff --git a/src/Game.c b/src/Game.c index b24c68699..ea39b13b1 100644 --- a/src/Game.c +++ b/src/Game.c @@ -33,7 +33,6 @@ #include "Audio.h" #include "Stream.h" #include "Builder.h" -#include "GameStructs.h" #include "Protocol.h" struct _GameData Game; diff --git a/src/Game.h b/src/Game.h index 9f0f3c658..6655ca72f 100644 --- a/src/Game.h +++ b/src/Game.h @@ -3,7 +3,7 @@ #include "Picking.h" #include "String.h" #include "Bitmap.h" -/* Represents the game. +/* Represents the game and related structures. Copyright 2014-2019 ClassiCube | Licensed under BSD-3 */ @@ -82,4 +82,38 @@ void Game_SetFpsLimit(int method); /* Runs the main game loop until the window is closed. */ void Game_Run(int width, int height, const String* title); + +/* Represents a game component. */ +struct IGameComponent; +struct IGameComponent { + /* Called when the game is being loaded. */ + void(*Init)(void); + /* Called when the component is being freed. (e.g. due to game being closed) */ + void(*Free)(void); + /* Called to reset the component's state. (e.g. reconnecting to server) */ + void(*Reset)(void); + /* Called to update the component's state when the user begins loading a new map. */ + void(*OnNewMap)(void); + /* Called to update the component's state when the user has finished loading a new map. */ + void(*OnNewMapLoaded)(void); + /* Next component in linked list of components. */ + struct IGameComponent* next; +}; +/* Adds a component to linked list of components. (always at end) */ +CC_NOINLINE void Game_AddComponent(struct IGameComponent* comp); + +/* Represents a task that periodically runs on the main thread every specified interval. */ +struct ScheduledTask; +struct ScheduledTask { + /* How long (in seconds) has elapsed since callback was last invoked */ + double Accumulator; + /* How long (in seconds) between invocations of the callback */ + double Interval; + /* Callback function that is periodically invoked */ + void (*Callback)(struct ScheduledTask* task); +}; + +typedef void (*ScheduledTaskCallback)(struct ScheduledTask* task); +/* Adds a component to list of scheduled tasks. (always at end) */ +CC_NOINLINE int ScheduledTask_Add(double interval, ScheduledTaskCallback callback); #endif diff --git a/src/GameStructs.h b/src/GameStructs.h deleted file mode 100644 index 0af241ed7..000000000 --- a/src/GameStructs.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CC_GAMESTRUCTS_H -#define CC_GAMESTRUCTS_H -#include "Core.h" -/* Represents Game related structures. - Copyright 2014-2019 ClassiCube | Licensed under BSD-3 -*/ -struct IGameComponent; - -/* Represents a game component. */ -struct IGameComponent { - /* Called when the game is being loaded. */ - void (*Init)(void); - /* Called when the component is being freed. (e.g. due to game being closed) */ - void (*Free)(void); - /* Called to reset the component's state. (e.g. reconnecting to server) */ - void (*Reset)(void); - /* Called to update the component's state when the user begins loading a new map. */ - void (*OnNewMap)(void); - /* Called to update the component's state when the user has finished loading a new map. */ - void (*OnNewMapLoaded)(void); - /* Next component in linked list of components. */ - struct IGameComponent* next; -}; -/* Adds a component to linked list of components. (always at end) */ -CC_NOINLINE void Game_AddComponent(struct IGameComponent* comp); - -/* Represents a task that periodically runs on the main thread every specified interval. */ -struct ScheduledTask; -struct ScheduledTask { - /* How long (in seconds) has elapsed since callback was last invoked */ - double Accumulator; - /* How long (in seconds) between invocations of the callback */ - double Interval; - /* Callback function that is periodically invoked */ - void (*Callback)(struct ScheduledTask* task); -}; - -typedef void (*ScheduledTaskCallback)(struct ScheduledTask* task); -/* Adds a component to list of scheduled tasks. (always at end) */ -CC_NOINLINE int ScheduledTask_Add(double interval, ScheduledTaskCallback callback); -#endif diff --git a/src/Gui.c b/src/Gui.c index 6c3591534..1d4fd64e4 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -12,7 +12,6 @@ #include "Platform.h" #include "Bitmap.h" #include "Options.h" -#include "GameStructs.h" #include "Funcs.h" cc_bool Gui_ClassicTexture, Gui_ClassicTabList, Gui_ClassicMenu, Gui_ClassicChat; diff --git a/src/HeldBlockRenderer.c b/src/HeldBlockRenderer.c index eae9897ad..ba527f18d 100644 --- a/src/HeldBlockRenderer.c +++ b/src/HeldBlockRenderer.c @@ -8,7 +8,6 @@ #include "Event.h" #include "Entity.h" #include "Model.h" -#include "GameStructs.h" #include "Options.h" cc_bool HeldBlockRenderer_Show; diff --git a/src/Http.c b/src/Http.c index 4d0e69175..04797af65 100644 --- a/src/Http.c +++ b/src/Http.c @@ -3,7 +3,7 @@ #include "Funcs.h" #include "Logger.h" #include "Stream.h" -#include "GameStructs.h" +#include "Game.h" void HttpRequest_Free(struct HttpRequest* request) { Mem_Free(request->data); diff --git a/src/Inventory.c b/src/Inventory.c index 191fc4419..2167a56fc 100644 --- a/src/Inventory.c +++ b/src/Inventory.c @@ -4,7 +4,6 @@ #include "Block.h" #include "Event.h" #include "Chat.h" -#include "GameStructs.h" struct _InventoryData Inventory; diff --git a/src/Launcher.c b/src/Launcher.c index 5660fbcae..4838de87a 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -9,7 +9,6 @@ #include "Utils.h" #include "Input.h" #include "Window.h" -#include "GameStructs.h" #include "Event.h" #include "Http.h" #include "ExtMath.h" diff --git a/src/Lighting.c b/src/Lighting.c index 51af599ef..cd5516c11 100644 --- a/src/Lighting.c +++ b/src/Lighting.c @@ -6,7 +6,7 @@ #include "World.h" #include "Logger.h" #include "Event.h" -#include "GameStructs.h" +#include "Game.h" cc_int16* Lighting_Heightmap; #define HEIGHT_UNCALCULATED Int16_MaxValue diff --git a/src/MapRenderer.c b/src/MapRenderer.c index 8bd27af71..7e7b0d110 100644 --- a/src/MapRenderer.c +++ b/src/MapRenderer.c @@ -14,7 +14,6 @@ #include "Utils.h" #include "World.h" #include "Options.h" -#include "GameStructs.h" int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ; int MapRenderer_1DUsedCount, MapRenderer_ChunksCount; diff --git a/src/Model.c b/src/Model.c index cc04b4eea..91e10f24f 100644 --- a/src/Model.c +++ b/src/Model.c @@ -13,7 +13,6 @@ #include "Stream.h" #include "Funcs.h" #include "Options.h" -#include "GameStructs.h" struct _ModelsData Models; diff --git a/src/Particle.c b/src/Particle.c index 381442c9f..d8aa9f8bc 100644 --- a/src/Particle.c +++ b/src/Particle.c @@ -9,7 +9,6 @@ #include "Funcs.h" #include "Game.h" #include "Event.h" -#include "GameStructs.h" /*########################################################################################################################* diff --git a/src/PickedPosRenderer.c b/src/PickedPosRenderer.c index 85a320e6d..e8c88c788 100644 --- a/src/PickedPosRenderer.c +++ b/src/PickedPosRenderer.c @@ -6,7 +6,6 @@ #include "Picking.h" #include "Funcs.h" #include "Camera.h" -#include "GameStructs.h" static GfxResourceID pickedPos_vb; #define PICKEDPOS_NUM_VERTICES (16 * 6) diff --git a/src/Protocol.c b/src/Protocol.c index 6306e6dd2..a1531046b 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -25,7 +25,6 @@ #include "Camera.h" #include "Window.h" #include "Particle.h" -#include "GameStructs.h" cc_uint16 Net_PacketSizes[OPCODE_COUNT]; Net_Handler Net_Handlers[OPCODE_COUNT]; diff --git a/src/SelectionBox.c b/src/SelectionBox.c index e0454063f..9347e2fde 100644 --- a/src/SelectionBox.c +++ b/src/SelectionBox.c @@ -5,7 +5,6 @@ #include "Funcs.h" #include "Game.h" #include "Camera.h" -#include "GameStructs.h" /* Data for a selection box. */ struct SelectionBox { diff --git a/src/Server.c b/src/Server.c index cb7617703..7b61953ea 100644 --- a/src/Server.c +++ b/src/Server.c @@ -21,7 +21,6 @@ #include "Protocol.h" #include "Inventory.h" #include "Platform.h" -#include "GameStructs.h" static char nameBuffer[STRING_SIZE]; static char motdBuffer[STRING_SIZE]; diff --git a/src/TexturePack.c b/src/TexturePack.c index ce7071888..d45ba791b 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -17,7 +17,6 @@ #include "Chat.h" #include "Options.h" #include "Logger.h" -#include "GameStructs.h" #define LIQUID_ANIM_MAX 64 #define WATER_TEX_LOC 14