From 1c3d8fb72e7fcd3a26d75ad3a23fc6f41ab7be63 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 28 Jul 2024 23:33:22 +1000 Subject: [PATCH] Simplify writing plugins in C++ slightly --- doc/plugin-dev.md | 11 +---------- src/Animations.h | 4 ++++ src/Audio.c | 4 ++-- src/Audio.h | 4 ++++ src/AxisLinesRenderer.h | 3 +++ src/Bitmap.c | 4 ++-- src/Bitmap.h | 4 ++++ src/Block.h | 4 ++++ src/BlockID.h | 3 +++ src/BlockPhysics.h | 4 ++++ src/Builder.h | 4 ++++ src/Camera.h | 4 ++++ src/Chat.h | 4 ++++ src/Commands.h | 4 ++++ src/Core.h | 9 +++++++++ src/Deflate.h | 4 ++++ src/Drawer.h | 4 ++++ src/Drawer2D.h | 4 ++++ src/Entity.h | 4 ++++ src/EntityComponents.h | 4 ++++ src/EntityRenderers.h | 3 +++ src/EnvRenderer.h | 4 ++++ src/Event.h | 4 ++++ src/ExtMath.h | 4 ++++ src/Formats.h | 4 ++++ src/Funcs.h | 4 ++++ src/Game.h | 4 ++++ src/Generator.h | 4 ++++ src/Graphics.h | 4 ++++ src/Gui.h | 4 ++++ src/HeldBlockRenderer.h | 4 ++++ src/Http.h | 4 ++++ src/Input.h | 4 ++++ src/InputHandler.h | 4 ++++ src/Inventory.h | 4 ++++ src/IsometricDrawer.h | 4 ++++ src/LBackend.h | 4 ++++ src/LScreens.h | 4 ++++ src/LWeb.h | 4 ++++ src/LWidgets.h | 4 ++++ src/Launcher.h | 4 ++++ src/Lighting.h | 3 +++ src/Logger.h | 4 ++++ src/MapRenderer.h | 4 ++++ src/MenuOptions.c | 4 +++- src/Menus.h | 4 ++++ src/Model.h | 3 +++ src/Options.h | 4 ++++ src/PackedCol.h | 4 ++++ src/Particle.h | 4 ++++ src/Physics.h | 4 ++++ src/Picking.h | 4 ++++ src/Platform.h | 4 ++++ src/Protocol.h | 4 ++++ src/Queue.h | 3 +++ src/Resources.h | 4 ++++ src/SSL.h | 4 ++++ src/Screens.h | 4 ++++ src/SelOutlineRenderer.h | 4 ++++ src/SelectionBox.h | 4 ++++ src/Server.h | 4 ++++ src/Stream.h | 4 ++++ src/String.h | 26 +++++++++++++++----------- src/SystemFonts.h | 4 ++++ src/TexturePack.h | 4 ++++ src/Utils.h | 4 ++++ src/Vectors.h | 4 ++++ src/Vorbis.h | 4 ++++ src/Widgets.h | 4 ++++ src/Window.h | 3 +++ src/Window_X11.c | 10 +++++----- src/World.h | 4 ++++ 72 files changed, 290 insertions(+), 31 deletions(-) diff --git a/doc/plugin-dev.md b/doc/plugin-dev.md index 99ca1e414..9ca2da3c7 100644 --- a/doc/plugin-dev.md +++ b/doc/plugin-dev.md @@ -64,15 +64,6 @@ All plugins require this boilerplate, so feel free to copy and paste it. --- ### Writing plugins in C++ -When including headers from ClassiCube, they **must** be surrounded with `extern "C"`, i.e. -```C -extern "C" { -#include "src/Chat.h" -#include "src/Game.h" -#include "src/String.h" -} -``` -Otherwise you will get obscure `Undefined reference` errors when compiling. Exported plugin functions **must** be surrounded with `extern "C"`, i.e. ```C @@ -259,4 +250,4 @@ This is somewhat tedious to do - see [here](https://github.com/ClassiCube/Classi If you **ONLY** use code from the game (no external libraries and no C standard library functions): * You can add `-nostartfiles -Wl,--entry=0` to the compile flags to reduce the DLL size (e.g from 11 to 4 kb) -This isn't necessary to do though, and plugin DLLs work completely fine without doing this. \ No newline at end of file +This isn't necessary to do though, and plugin DLLs work completely fine without doing this. diff --git a/src/Animations.h b/src/Animations.h index a6c7dd074..f3a944c85 100644 --- a/src/Animations.h +++ b/src/Animations.h @@ -1,10 +1,14 @@ #ifndef CC_ANIMATIONS_H #define CC_ANIMATIONS_H +#include "Core.h" /* Contains everything relating to texture animations (including default water/lava ones) Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER struct IGameComponent; extern struct IGameComponent Animations_Component; + +CC_END_HEADER #endif diff --git a/src/Audio.c b/src/Audio.c index 305a93829..1db64d881 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -93,7 +93,7 @@ static cc_result Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) { size -= WAV_FMT_SIZE; } else if (fourCC == WAV_FourCC('d','a','t','a')) { if ((res = Audio_AllocChunks(size, &snd->chunk, 1))) return res; - res = Stream_Read(stream, snd->chunk.data, size); + res = Stream_Read(stream, (cc_uint8*)snd->chunk.data, size); #ifdef CC_BUILD_BIGENDIAN Utils_SwapEndian16((cc_int16*)snd->chunk.data, size / 2); @@ -336,7 +336,7 @@ static cc_result Music_Buffer(struct AudioChunk* chunk, int maxSamples, struct V int samples = 0; cc_int16* cur; cc_result res = 0, res2; - cc_int16* data = chunk->data; + cc_int16* data = (cc_int16*)chunk->data; while (samples < maxSamples) { if ((res = Vorbis_DecodeFrame(ctx))) break; diff --git a/src/Audio.h b/src/Audio.h index 77d09a269..390c01898 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -4,6 +4,8 @@ /* Manages playing sound and music. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER + struct IGameComponent; extern struct IGameComponent Audio_Component; struct AudioContext; @@ -87,4 +89,6 @@ void Audio_Warn(cc_result res, const char* action); cc_result AudioPool_Play(struct AudioData* data); void AudioPool_Close(void); + +CC_END_HEADER #endif diff --git a/src/AxisLinesRenderer.h b/src/AxisLinesRenderer.h index 7e3a1ca06..322f9f371 100644 --- a/src/AxisLinesRenderer.h +++ b/src/AxisLinesRenderer.h @@ -4,6 +4,7 @@ /* Renders 3 lines showing direction of each axis. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER struct IGameComponent; extern struct IGameComponent AxisLinesRenderer_Component; @@ -11,4 +12,6 @@ extern struct IGameComponent AxisLinesRenderer_Component; extern cc_bool AxisLinesRenderer_Enabled; void AxisLinesRenderer_Render(void); + +CC_END_HEADER #endif diff --git a/src/Bitmap.c b/src/Bitmap.c index 51dc9cf8f..576f99837 100644 --- a/src/Bitmap.c +++ b/src/Bitmap.c @@ -408,7 +408,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) { scanlineSize = ((samplesPerPixel[colorspace] * bitsPerSample * bmp->width) + 7) >> 3; scanlineBytes = scanlineSize + 1; /* Add 1 byte for filter byte of each scanline */ - data = Mem_TryAlloc(bmp->height, max(scanlineBytes, bmp->width * 4)); + data = (cc_uint8*)Mem_TryAlloc(bmp->height, max(scanlineBytes, bmp->width * 4)); bmp->scan0 = (BitmapCol*)data; if (!bmp->scan0) return ERR_OUT_OF_MEMORY; @@ -729,7 +729,7 @@ cc_result Png_Encode(struct Bitmap* bmp, struct Stream* stream, Png_RowGetter getRow, cc_bool alpha, void* ctx) { cc_result res; /* Add 1 for scanline filter type byter */ - cc_uint8* buffer = Mem_TryAlloc(3, bmp->width * 4 + 1); + cc_uint8* buffer = (cc_uint8*)Mem_TryAlloc(3, bmp->width * 4 + 1); if (!buffer) return ERR_NOT_SUPPORTED; res = Png_EncodeCore(bmp, stream, buffer, getRow, alpha, ctx); diff --git a/src/Bitmap.h b/src/Bitmap.h index d04bac5bf..48cf2ba21 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -4,6 +4,8 @@ /* Represents a 2D array of pixels. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER + struct Stream; #if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID || defined CC_BUILD_PSP || defined CC_BUILD_PSVITA || defined CC_BUILD_PS2 @@ -140,4 +142,6 @@ CC_API cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream); /* if alpha is non-zero, RGBA channels are saved, otherwise only RGB channels are. */ cc_result Png_Encode(struct Bitmap* bmp, struct Stream* stream, Png_RowGetter getRow, cc_bool alpha, void* ctx); + +CC_END_HEADER #endif diff --git a/src/Block.h b/src/Block.h index 370e44140..b3bd4272d 100644 --- a/src/Block.h +++ b/src/Block.h @@ -8,6 +8,8 @@ Also performs automatic rotation of directional blocks. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER + struct IGameComponent; extern struct IGameComponent Blocks_Component; @@ -151,4 +153,6 @@ extern cc_bool AutoRotate_Enabled; BlockID AutoRotate_RotateBlock(BlockID block); /* Returns non 0 if both blocks belong to the same autorotate group */ cc_bool AutoRotate_BlocksShareGroup(BlockID block, BlockID blockOther); + +CC_END_HEADER #endif diff --git a/src/BlockID.h b/src/BlockID.h index f3a580f52..312bf7c3b 100644 --- a/src/BlockID.h +++ b/src/BlockID.h @@ -4,6 +4,7 @@ /* List of all core/standard block IDs Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ +CC_BEGIN_HEADER enum BLOCKID { /* Classic blocks */ @@ -88,4 +89,6 @@ enum BLOCKID { #endif BLOCK_COUNT = (BLOCK_MAX_DEFINED + 1) }; + +CC_END_HEADER #endif diff --git a/src/BlockPhysics.h b/src/BlockPhysics.h index dda8462b2..b269331ee 100644 --- a/src/BlockPhysics.h +++ b/src/BlockPhysics.h @@ -1,6 +1,8 @@ #ifndef CC_BLOCKPHYSICS_H #define CC_BLOCKPHYSICS_H #include "Core.h" +CC_BEGIN_HEADER + /* Implements simple block physics. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -26,4 +28,6 @@ void Physics_OnBlockChanged(int x, int y, int z, BlockID old, BlockID now); void Physics_Init(void); void Physics_Free(void); void Physics_Tick(void); + +CC_END_HEADER #endif diff --git a/src/Builder.h b/src/Builder.h index 6c43c727f..b105f2aff 100644 --- a/src/Builder.h +++ b/src/Builder.h @@ -1,6 +1,8 @@ #ifndef CC_BUILDER_H #define CC_BUILDER_H #include "Core.h" +CC_BEGIN_HEADER + /* Converts a 16x16x16 chunk into a mesh of vertices NormalMeshBuilder: @@ -21,4 +23,6 @@ extern cc_bool Builder_SmoothLighting; void Builder_MakeChunk(struct ChunkInfo* info); void Builder_ApplyActive(void); + +CC_END_HEADER #endif diff --git a/src/Camera.h b/src/Camera.h index 0afef30ef..871749a29 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -1,6 +1,8 @@ #ifndef CC_CAMERA_H #define CC_CAMERA_H #include "Vectors.h" +CC_BEGIN_HEADER + /* Represents a camera, may be first or third person Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -82,4 +84,6 @@ void Camera_CheckFocus(void); void Camera_UpdateProjection(void); void Camera_SetFov(int fov); void Camera_KeyLookUpdate(float delta); + +CC_END_HEADER #endif diff --git a/src/Chat.h b/src/Chat.h index c4366bfef..49f24f76e 100644 --- a/src/Chat.h +++ b/src/Chat.h @@ -1,6 +1,8 @@ #ifndef CC_CHAT_H #define CC_CHAT_H #include "Core.h" +CC_BEGIN_HEADER + /* Manages sending, adding, logging and handling chat. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -71,4 +73,6 @@ CC_API void Chat_Add1(const char* format, const void* a1); CC_API void Chat_Add2(const char* format, const void* a1, const void* a2); CC_API void Chat_Add3(const char* format, const void* a1, const void* a2, const void* a3); CC_API void Chat_Add4(const char* format, const void* a1, const void* a2, const void* a3, const void* a4); + +CC_END_HEADER #endif diff --git a/src/Commands.h b/src/Commands.h index e5a356fae..f89a3a804 100644 --- a/src/Commands.h +++ b/src/Commands.h @@ -1,6 +1,8 @@ #ifndef CC_COMMANDS_H #define CC_COMMANDS_H #include "Core.h" +CC_BEGIN_HEADER + /* Executes actions in response to certain chat input Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -28,4 +30,6 @@ struct ChatCommand { /* Registers a client-side command, allowing it to be used with /client [cmd name] */ CC_API void Commands_Register( struct ChatCommand* cmd); typedef void (*FP_Commands_Register)(struct ChatCommand* cmd); + +CC_END_HEADER #endif diff --git a/src/Core.h b/src/Core.h index c42eb3e74..85117dfbe 100644 --- a/src/Core.h +++ b/src/Core.h @@ -511,5 +511,14 @@ struct Texture { short x, y; cc_uint16 width, height; TextureRec uv; }; + +#ifdef __cplusplus + #define CC_BEGIN_HEADER extern "C" { + #define CC_END_HEADER } +#else + #define CC_BEGIN_HEADER + #define CC_END_HEADER +#endif + #endif diff --git a/src/Deflate.h b/src/Deflate.h index 4207cfc30..9cfc99158 100644 --- a/src/Deflate.h +++ b/src/Deflate.h @@ -1,6 +1,8 @@ #ifndef CC_DEFLATE_H #define CC_DEFLATE_H #include "Core.h" +CC_BEGIN_HEADER + /* Decodes data compressed using DEFLATE in a streaming manner. Partially based off information from https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way @@ -135,4 +137,6 @@ typedef cc_bool (*Zip_SelectEntry)(const cc_string* path); cc_result Zip_Extract(struct Stream* source, Zip_SelectEntry selector, Zip_ProcessEntry processor, struct ZipEntry* entries, int maxEntries); + +CC_END_HEADER #endif diff --git a/src/Drawer.h b/src/Drawer.h index e91d8bb79..cb44ce7ef 100644 --- a/src/Drawer.h +++ b/src/Drawer.h @@ -2,6 +2,8 @@ #define CC_DRAWER_H #include "PackedCol.h" #include "Vectors.h" +CC_BEGIN_HEADER + /* Draws the vertices for a cuboid region Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -35,4 +37,6 @@ CC_API void Drawer_ZMax(int count, PackedCol col, TextureLoc texLoc, struct Vert CC_API void Drawer_YMin(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices); /* Draws maximum Y face of the cuboid. (i.e. at Y2) */ CC_API void Drawer_YMax(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices); + +CC_END_HEADER #endif diff --git a/src/Drawer2D.h b/src/Drawer2D.h index 792902141..421c9f2ae 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -2,6 +2,8 @@ #define CC_DRAWER2D_H #include "Bitmap.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Performs a variety of drawing operations on bitmaps, and converts bitmaps into textures. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -126,4 +128,6 @@ cc_bool Font_SetBitmapAtlas(struct Bitmap* bmp); void Font_SetPadding(struct FontDesc* desc, int amount); /* Initialises the given font for drawing bitmapped text using default.png */ void Font_MakeBitmapped(struct FontDesc* desc, int size, int flags); + +CC_END_HEADER #endif diff --git a/src/Entity.h b/src/Entity.h index 50a374620..f33117fad 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -5,6 +5,8 @@ #include "Constants.h" #include "PackedCol.h" #include "String.h" +CC_BEGIN_HEADER + /* Represents an in-game entity. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -256,4 +258,6 @@ cc_bool LocalPlayer_CheckCanZoom(struct LocalPlayer* p); /* Moves local player back to spawn point. */ void LocalPlayers_MoveToSpawn(struct LocationUpdate* update); void LocalPlayer_CalcDefaultSpawn(struct LocalPlayer* p, struct LocationUpdate* update); + +CC_END_HEADER #endif diff --git a/src/EntityComponents.h b/src/EntityComponents.h index 9b1d0dc2c..00157184b 100644 --- a/src/EntityComponents.h +++ b/src/EntityComponents.h @@ -2,6 +2,8 @@ #define CC_ENTITY_COMPONENTS_H #include "Vectors.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Various components for entities. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -133,4 +135,6 @@ void PhysicsComp_DoEntityPush(struct Entity* entity); /* Entity component that plays block step sounds */ void SoundComp_Tick(struct LocalPlayer* p, cc_bool wasOnGround); + +CC_END_HEADER #endif diff --git a/src/EntityRenderers.h b/src/EntityRenderers.h index ab46eee46..28f3287e0 100644 --- a/src/EntityRenderers.h +++ b/src/EntityRenderers.h @@ -1,6 +1,8 @@ #ifndef CC_ENTITYRENDERERS_H #define CC_ENTITYRENDERERS_H #include "Core.h" +CC_BEGIN_HEADER + /* Renders supporting objects for entities (shadows and names) Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -18,4 +20,5 @@ void EntityNames_Render(void); /* Renders hovered entity name tags (these appears through blocks) */ void EntityNames_RenderHovered(void); +CC_END_HEADER #endif diff --git a/src/EnvRenderer.h b/src/EnvRenderer.h index b27344178..926277977 100644 --- a/src/EnvRenderer.h +++ b/src/EnvRenderer.h @@ -1,6 +1,8 @@ #ifndef CC_ENVRENDERER_H #define CC_ENVRENDERER_H #include "Core.h" +CC_BEGIN_HEADER + /* Renders environment of the map (clouds, sky, fog, map sides/edges, skybox, rain/snow) Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -44,4 +46,6 @@ void EnvRenderer_SetMode(int flags); /* Calculates mode flags for the given mode. */ /* mode can be: normal, normalfast, legacy, legacyfast */ CC_NOINLINE int EnvRenderer_CalcFlags(const cc_string* mode); + +CC_END_HEADER #endif diff --git a/src/Event.h b/src/Event.h index c8c4f3e24..e853ebe25 100644 --- a/src/Event.h +++ b/src/Event.h @@ -1,6 +1,8 @@ #ifndef CC_EVENT_H #define CC_EVENT_H #include "Vectors.h" +CC_BEGIN_HEADER + /* Helper methods for using events, and contains all events. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -223,4 +225,6 @@ CC_VAR extern struct _NetEventsList { struct Event_Void Disconnected; /* Connection to the server was lost */ struct Event_PluginMessage PluginMessageReceived; /* Received a PluginMessage packet from the server */ } NetEvents; + +CC_END_HEADER #endif diff --git a/src/ExtMath.h b/src/ExtMath.h index d1c840fbe..ef218fc97 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -1,6 +1,8 @@ #ifndef CC_MATH_H #define CC_MATH_H #include "Core.h" +CC_BEGIN_HEADER + /* Simple math functions and constants. Also implements a RNG algorithm, based on Java's implementation from https://docs.oracle.com/javase/7/docs/api/java/util/Random.html Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -75,4 +77,6 @@ CC_API float Random_Float(RNGState* rnd); static CC_INLINE int Random_Range(RNGState* rnd, int min, int max) { return min + Random_Next(rnd, max - min); } + +CC_END_HEADER #endif diff --git a/src/Formats.h b/src/Formats.h index d81df522f..cad6593e0 100644 --- a/src/Formats.h +++ b/src/Formats.h @@ -1,6 +1,8 @@ #ifndef CC_MAPFORMATS_H #define CC_MAPFORMATS_H #include "Core.h" +CC_BEGIN_HEADER + /* Imports/exports a world and associated metadata from/to a particular map file format. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -36,4 +38,6 @@ cc_result Schematic_Save(struct Stream* stream); /* Exports a world to a .dat Classic map file */ /* Used by MineCraft Classic */ cc_result Dat_Save(struct Stream* stream); + +CC_END_HEADER #endif diff --git a/src/Funcs.h b/src/Funcs.h index 1edd33549..f385b635b 100644 --- a/src/Funcs.h +++ b/src/Funcs.h @@ -1,6 +1,8 @@ #ifndef CC_FUNCS_H #define CC_FUNCS_H #include "Core.h" +CC_BEGIN_HEADER + /* Simple function implementations NOTE: doing min(x++, y) etc will increment x twice! @@ -49,4 +51,6 @@ while (cur) {\ tail = cur;\ cur = cur->next;\ } + +CC_END_HEADER #endif diff --git a/src/Game.h b/src/Game.h index 83a9c39e3..cdc290632 100644 --- a/src/Game.h +++ b/src/Game.h @@ -1,6 +1,8 @@ #ifndef CC_GAME_H #define CC_GAME_H #include "Core.h" +CC_BEGIN_HEADER + /* Represents the game and related structures. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -159,4 +161,6 @@ struct ScheduledTask { typedef void (*ScheduledTaskCallback)(struct ScheduledTask* task); /* Adds a task to list of scheduled tasks. (always at end) */ CC_API int ScheduledTask_Add(double interval, ScheduledTaskCallback callback); + +CC_END_HEADER #endif diff --git a/src/Generator.h b/src/Generator.h index 8614cb797..1542fc958 100644 --- a/src/Generator.h +++ b/src/Generator.h @@ -2,6 +2,8 @@ #define CC_MAP_GEN_H #include "ExtMath.h" #include "Vectors.h" +CC_BEGIN_HEADER + /* Implements flatgrass map generator, and original classic vanilla map generation (with perlin noise) Based on: https://github.com/ClassiCube/ClassiCube/wiki/Minecraft-Classic-map-generation-algorithm Thanks to Jerralish for originally reverse engineering classic's algorithm, then preparing a high level overview of the algorithm. @@ -41,4 +43,6 @@ cc_bool TreeGen_CanGrow(int treeX, int treeY, int treeZ, int treeHeight); /* Generates the blocks (and their positions in the world) that actually make up a tree. */ /* Returns the number of blocks generated, which will be <= TREE_MAX_COUNT */ int TreeGen_Grow(int treeX, int treeY, int treeZ, int height, IVec3* coords, BlockRaw* blocks); + +CC_END_HEADER #endif diff --git a/src/Graphics.h b/src/Graphics.h index aa1495a69..c5600e8b2 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -2,6 +2,8 @@ #define CC_GFXAPI_H #include "Vectors.h" #include "PackedCol.h" +CC_BEGIN_HEADER + /* Abstracts a 3D graphics rendering API Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -314,4 +316,6 @@ void Gfx_RestoreAlphaState(cc_uint8 draw); void Texture_Render(const struct Texture* tex); /* Binds then renders the given texture */ void Texture_RenderShaded(const struct Texture* tex, PackedCol shadeColor); + +CC_END_HEADER #endif diff --git a/src/Gui.h b/src/Gui.h index dcf13dece..9d6353d18 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -1,6 +1,8 @@ #ifndef CC_GUI_H #define CC_GUI_H #include "Core.h" +CC_BEGIN_HEADER + /* Describes and manages 2D GUI elements on screen. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -304,4 +306,6 @@ void TextAtlas_AddInt(struct TextAtlas* atlas, int value, struct VertexTextured* #define Widget_BuildMesh(widget, vertices) (widget)->VTABLE->BuildMesh(widget, vertices) #define Widget_Render2(widget, offset) (widget)->VTABLE->Render2(widget, offset) #define Widget_Layout(widget) (widget)->VTABLE->Reposition(widget) + +CC_END_HEADER #endif diff --git a/src/HeldBlockRenderer.h b/src/HeldBlockRenderer.h index 8fa7a807c..1653f4233 100644 --- a/src/HeldBlockRenderer.h +++ b/src/HeldBlockRenderer.h @@ -1,6 +1,8 @@ #ifndef CC_HELDBLOCKRENDERER_H #define CC_HELDBLOCKRENDERER_H #include "Core.h" +CC_BEGIN_HEADER + /* Renders the held block/arm at bottom right of game Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -12,4 +14,6 @@ extern cc_bool HeldBlockRenderer_Show; void HeldBlockRenderer_ClickAnim(cc_bool digging); void HeldBlockRenderer_Render(float delta); + +CC_END_HEADER #endif diff --git a/src/Http.h b/src/Http.h index d3618c4e6..98f4866c7 100644 --- a/src/Http.h +++ b/src/Http.h @@ -2,6 +2,8 @@ #define CC_HTTP_H #include "Constants.h" #include "Core.h" +CC_BEGIN_HEADER + /* Aysnchronously performs http GET, HEAD, and POST requests Typically this is used to download skins, texture packs, etc @@ -87,4 +89,6 @@ int Http_CheckProgress(int reqID); void Http_ClearPending(void); void Http_LogError(const char* action, const struct HttpRequest* item); + +CC_END_HEADER #endif diff --git a/src/Input.h b/src/Input.h index 57c852207..6813a6e3e 100644 --- a/src/Input.h +++ b/src/Input.h @@ -1,6 +1,8 @@ #ifndef CC_INPUT_H #define CC_INPUT_H #include "Core.h" +CC_BEGIN_HEADER + /* Manages input state and raising input related events Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -258,4 +260,6 @@ void InputBind_Set(InputBind binding, int btn, const struct InputDevice* device) void InputBind_Reset(InputBind binding, const struct InputDevice* device); /* Loads the bindings for the given device from either options or its defaults */ void InputBind_Load(const struct InputDevice* device); + +CC_END_HEADER #endif diff --git a/src/InputHandler.h b/src/InputHandler.h index abde5217c..8cef9a214 100644 --- a/src/InputHandler.h +++ b/src/InputHandler.h @@ -1,6 +1,8 @@ #ifndef CC_INPUTHANDLER_H #define CC_INPUTHANDLER_H #include "Input.h" +CC_BEGIN_HEADER + /* Manages base game input handling Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -63,4 +65,6 @@ extern BindTriggered Bind_OnTriggered[BIND_COUNT]; extern BindReleased Bind_OnReleased[BIND_COUNT]; /* Whether the given input binding is activated by one or more devices */ extern cc_uint8 Bind_IsTriggered[BIND_COUNT]; + +CC_END_HEADER #endif diff --git a/src/Inventory.h b/src/Inventory.h index 30c5f02d2..2353739a1 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -2,6 +2,8 @@ #define CC_INVENTORY_H #include "Core.h" #include "BlockID.h" +CC_BEGIN_HEADER + /* Manages inventory hotbar, and ordering of blocks in the inventory menu. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -60,4 +62,6 @@ void Inventory_ResetMapping(void); void Inventory_AddDefault(BlockID block); /* Removes any slots with the given block from the inventory. */ void Inventory_Remove(BlockID block); + +CC_END_HEADER #endif diff --git a/src/IsometricDrawer.h b/src/IsometricDrawer.h index b3c8d4e15..eb9f3ba11 100644 --- a/src/IsometricDrawer.h +++ b/src/IsometricDrawer.h @@ -1,6 +1,8 @@ #ifndef CC_ISOMETRICDRAWER_H #define CC_ISOMETRICDRAWER_H #include "Core.h" +CC_BEGIN_HEADER + /* Draws 2D isometric blocks for the hotbar and inventory UIs. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -17,4 +19,6 @@ void IsometricDrawer_AddBatch(BlockID block, float size, float x, float y); int IsometricDrawer_EndBatch(void); /* Draws the buffered vertices */ void IsometricDrawer_Render(int count, int offset, int* state); + +CC_END_HEADER #endif diff --git a/src/LBackend.h b/src/LBackend.h index 2384178c8..f75995299 100644 --- a/src/LBackend.h +++ b/src/LBackend.h @@ -1,6 +1,8 @@ #ifndef CC_LBACKEND_H #define CC_LBACKEND_H #include "Core.h" +CC_BEGIN_HEADER + /* Abstracts the gui drawing backend for the Launcher Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -83,4 +85,6 @@ void LBackend_TableDraw(struct LTable* w); void LBackend_TableMouseDown(struct LTable* w, int idx); void LBackend_TableMouseUp(struct LTable* w, int idx); void LBackend_TableMouseMove(struct LTable* w, int idx); + +CC_END_HEADER #endif diff --git a/src/LScreens.h b/src/LScreens.h index d281b623d..0a79b9636 100644 --- a/src/LScreens.h +++ b/src/LScreens.h @@ -1,6 +1,8 @@ #ifndef CC_LSCREENS_H #define CC_LSCREENS_H #include "Core.h" +CC_BEGIN_HEADER + /* Implements all of the screens/menus in the launcher Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -50,4 +52,6 @@ void ServersScreen_SetActive(void); void SettingsScreen_SetActive(void); void ThemesScreen_SetActive(void); void UpdatesScreen_SetActive(void); + +CC_END_HEADER #endif diff --git a/src/LWeb.h b/src/LWeb.h index bc15e5ad2..b70bb2985 100644 --- a/src/LWeb.h +++ b/src/LWeb.h @@ -2,6 +2,8 @@ #define CC_LWEB_H #include "Bitmap.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Implements asynchronous web tasks for the launcher. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -133,4 +135,6 @@ void Flags_Free(void); void Session_Load(void); void Session_Save(void); + +CC_END_HEADER #endif diff --git a/src/LWidgets.h b/src/LWidgets.h index 5ffc7f6a5..7dbb131ab 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -2,6 +2,8 @@ #define CC_LWIDGETS_H #include "Bitmap.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Describes and manages individual 2D GUI elements in the launcher. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -250,4 +252,6 @@ void LTable_SetSelectedTo(struct LTable* w, int index); void LTable_RowClick(struct LTable* w, int row); /* Works out the background color of the given row */ BitmapCol LTable_RowColor(int row, cc_bool selected, cc_bool featured); + +CC_END_HEADER #endif diff --git a/src/Launcher.h b/src/Launcher.h index 3201fcf21..86abdf9c8 100644 --- a/src/Launcher.h +++ b/src/Launcher.h @@ -1,6 +1,8 @@ #ifndef CC_LAUNCHER_H #define CC_LAUNCHER_H #include "Bitmap.h" +CC_BEGIN_HEADER + /* Implements the launcher part of the game. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -78,4 +80,6 @@ cc_bool Launcher_StartGame(const cc_string* user, const cc_string* mppass, const /* Prints information about a http error to dst. (for status widget) */ /* If req->result is non-zero, also displays a dialog box on-screen. */ void Launcher_DisplayHttpError(struct HttpRequest* req, const char* action, cc_string* dst); + +CC_END_HEADER #endif diff --git a/src/Lighting.h b/src/Lighting.h index 20344d7a6..ffd0bda02 100644 --- a/src/Lighting.h +++ b/src/Lighting.h @@ -1,6 +1,8 @@ #ifndef CC_WORLDLIGHTING_H #define CC_WORLDLIGHTING_H #include "PackedCol.h" +CC_BEGIN_HEADER + /* Abstracts lighting of blocks in the world Built-in lighting engines: @@ -85,4 +87,5 @@ cc_bool ClassicLighting_IsLit(int x, int y, int z); cc_bool ClassicLighting_IsLit_Fast(int x, int y, int z); void ClassicLighting_OnBlockChanged(int x, int y, int z, BlockID oldBlock, BlockID newBlock); +CC_END_HEADER #endif diff --git a/src/Logger.h b/src/Logger.h index 05c8daef0..79cacf6c8 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -1,6 +1,8 @@ #ifndef CC_LOGGER_H #define CC_LOGGER_H #include "Core.h" +CC_BEGIN_HEADER + /* Logs warnings/errors and also abstracts platform specific logging for fatal errors Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -55,4 +57,6 @@ void Logger_Abort(const char* raw_msg); /* Typically used to abort due to an unrecoverable error. (e.g. out of memory) */ CC_NOINLINE void Logger_Abort2(cc_result result, const char* raw_msg); void Logger_FailToStart(const char* raw_msg); + +CC_END_HEADER #endif diff --git a/src/MapRenderer.h b/src/MapRenderer.h index 9af6528b1..d708e03ae 100644 --- a/src/MapRenderer.h +++ b/src/MapRenderer.h @@ -2,6 +2,8 @@ #define CC_MAPRENDERER_H #include "Core.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Renders the blocks of the world by subdividing it into chunks. Also manages the process of building/deleting chunk meshes. Also sorts chunks so nearest chunks are rendered first, and calculates chunk visibility. @@ -75,4 +77,6 @@ void MapRenderer_RefreshChunk(int cx, int cy, int cz); void MapRenderer_OnBlockChanged(int x, int y, int z, BlockID block); /* Deletes all chunks and resets internal state. */ void MapRenderer_Refresh(void); + +CC_END_HEADER #endif diff --git a/src/MenuOptions.c b/src/MenuOptions.c index 2a2b51fb7..ac4a3d1c7 100644 --- a/src/MenuOptions.c +++ b/src/MenuOptions.c @@ -1299,12 +1299,14 @@ static void NF_SetCPE(cc_bool v) { static void NostalgiaScreen_Version(void* screen, void* widget) { struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen; + struct ButtonWidget* btn = (struct ButtonWidget*)widget; + int ver = Game_Version.Version - 1; if (ver < VERSION_0017) ver = VERSION_0030; Options_SetInt(OPT_GAME_VERSION, ver); GameVersion_Load(); - MenuOptionsScreen_Update(s, widget); + MenuOptionsScreen_Update(s, btn); } static void NF_GetVersion(struct ButtonWidget* btn, cc_string* v) { diff --git a/src/Menus.h b/src/Menus.h index a40630249..d4574d473 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -2,6 +2,8 @@ #define CC_MENUS_H #include "Gui.h" #include "PackedCol.h" +CC_BEGIN_HEADER + /* Contains all 2D menu screen implementations. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -100,4 +102,6 @@ typedef void (*Button_SetNum)(const cc_string* v); void MenuOptionsScreen_AddNum(struct MenuOptionsScreen* s, const char* name, float minValue, float maxValue, float defaultValue, Button_GetNum getValue, Button_SetNum setValue, const char* desc); + +CC_END_HEADER #endif diff --git a/src/Model.h b/src/Model.h index d6ca60c6e..432878900 100644 --- a/src/Model.h +++ b/src/Model.h @@ -4,6 +4,8 @@ #include "PackedCol.h" #include "Constants.h" #include "Physics.h" +CC_BEGIN_HEADER + /* Contains various structs and methods for an entity model. Also contains a list of models and default textures for those models. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -298,4 +300,5 @@ void CustomModel_BuildPart(struct CustomModel* cm, struct CustomModelPartDef* pa void CustomModel_Register(struct CustomModel* cm); void CustomModel_Undefine(struct CustomModel* cm); +CC_END_HEADER #endif diff --git a/src/Options.h b/src/Options.h index 3c5d5e7aa..62f97bea9 100644 --- a/src/Options.h +++ b/src/Options.h @@ -1,6 +1,8 @@ #ifndef CC_OPTIONS_H #define CC_OPTIONS_H #include "Core.h" +CC_BEGIN_HEADER + /* Manages loading and saving options Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -155,4 +157,6 @@ void Options_SetSecure(const char* opt, const cc_string* data); /* Attempts to securely decode an option. */ /* NOTE: Not all platforms support secure saving. */ void Options_GetSecure(const char* opt, cc_string* data); + +CC_END_HEADER #endif diff --git a/src/PackedCol.h b/src/PackedCol.h index 1290804ef..a9aca4ab2 100644 --- a/src/PackedCol.h +++ b/src/PackedCol.h @@ -1,6 +1,8 @@ #ifndef CC_PACKEDCOL_H #define CC_PACKEDCOL_H #include "Core.h" +CC_BEGIN_HEADER + /* Manipulates a packed 32 bit RGBA colour, in a format suitable for the native 3D graphics API vertex colours. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -61,4 +63,6 @@ CC_NOINLINE cc_bool PackedCol_TryParseHex(const cc_string* str, cc_uint8* rgb); #define PACKEDCOL_SHADE_YMIN 0.5f /* Retrieves shaded colours for ambient block face lighting */ void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yMin); + +CC_END_HEADER #endif diff --git a/src/Particle.h b/src/Particle.h index f2388129c..2a873fcc5 100644 --- a/src/Particle.h +++ b/src/Particle.h @@ -2,6 +2,8 @@ #define CC_PARTICLE_H #include "Vectors.h" #include "PackedCol.h" +CC_BEGIN_HEADER + /* Represents particle effects, and manages rendering and spawning particles Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -43,4 +45,6 @@ void Particles_Render(float t); void Particles_BreakBlockEffect(IVec3 coords, BlockID oldBlock, BlockID block); void Particles_RainSnowEffect(float x, float y, float z); void Particles_CustomEffect(int effectID, float x, float y, float z, float originX, float originY, float originZ); + +CC_END_HEADER #endif diff --git a/src/Physics.h b/src/Physics.h index 7dc080100..66b9af4b5 100644 --- a/src/Physics.h +++ b/src/Physics.h @@ -1,6 +1,8 @@ #ifndef CC_PHYSICS_H #define CC_PHYSICS_H #include "Vectors.h" +CC_BEGIN_HEADER + /* Provides various physics related structs and methods such as: - An axis aligned bounding box, and various methods related to them. @@ -38,4 +40,6 @@ extern struct SearcherState* Searcher_States; int Searcher_FindReachableBlocks(struct Entity* entity, struct AABB* entityBB, struct AABB* entityExtentBB); void Searcher_CalcTime(Vec3* vel, struct AABB *entityBB, struct AABB* blockBB, float* tx, float* ty, float* tz); void Searcher_Free(void); + +CC_END_HEADER #endif diff --git a/src/Picking.h b/src/Picking.h index 280a29fb0..65b809700 100644 --- a/src/Picking.h +++ b/src/Picking.h @@ -1,6 +1,8 @@ #ifndef CC_PICKING_H #define CC_PICKING_H #include "Vectors.h" +CC_BEGIN_HEADER + /* Provides ray tracer functionality for calculating picking/selecting intersection e.g. calculating block selected in the world by the user, clipping the camera @@ -43,4 +45,6 @@ void RayTracer_Step(struct RayTracer* t); or not being able to find a suitable candiate within the given reach distance.*/ void Picking_CalcPickedBlock(const Vec3* origin, const Vec3* dir, float reach, struct RayTracer* t); void Picking_ClipCameraPos(const Vec3* origin, const Vec3* dir, float reach, struct RayTracer* t); + +CC_END_HEADER #endif diff --git a/src/Platform.h b/src/Platform.h index 5ca1e5d9b..b2df2b845 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -1,6 +1,8 @@ #ifndef CC_PLATFORM_H #define CC_PLATFORM_H #include "Core.h" +CC_BEGIN_HEADER + /* Abstracts platform specific memory management, I/O, etc Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -348,4 +350,6 @@ void JavaCall_String_String(const char* name, const cc_string* arg, cc_string* d /* Calls a static method in the activity class that returns a jobject */ #define JavaSCall_Obj(env, method, args) (*env)->CallStaticObjectMethodA(env,App_Class, method, args) #endif + +CC_END_HEADER #endif diff --git a/src/Protocol.h b/src/Protocol.h index 4141fb60e..34b2ce112 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -1,6 +1,8 @@ #ifndef CC_PROTOCOL_H #define CC_PROTOCOL_H #include "Vectors.h" +CC_BEGIN_HEADER + /* Implements network protocols for original classic, CPE, and WoM textures Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -72,4 +74,6 @@ void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct /* Send a PluginMessage to the server; data must contain 64 bytes. */ CC_API void CPE_SendPluginMessage(cc_uint8 channel, cc_uint8* data); + +CC_END_HEADER #endif diff --git a/src/Queue.h b/src/Queue.h index 9e401e632..4aebac5ad 100644 --- a/src/Queue.h +++ b/src/Queue.h @@ -1,6 +1,7 @@ #ifndef CC_QUEUE_H #define CC_QUEUE_H #include "Core.h" +CC_BEGIN_HEADER struct Queue { cc_uint8* entries; /* Buffer holding the bytes of the queue */ @@ -18,4 +19,6 @@ void Queue_Enqueue(struct Queue* queue, void* item); void* Queue_Dequeue(struct Queue* queue); /* Frees the memory of the queue and resets the members to 0. */ void Queue_Clear(struct Queue* queue); + +CC_END_HEADER #endif diff --git a/src/Resources.h b/src/Resources.h index 4e629e55d..98764c760 100644 --- a/src/Resources.h +++ b/src/Resources.h @@ -1,6 +1,8 @@ #ifndef CC_RESOURCES_H #define CC_RESOURCES_H #include "Core.h" +CC_BEGIN_HEADER + /* Implements checking, fetching, and patching the default game assets. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -34,4 +36,6 @@ void Fetcher_Run(void); /* Checks if any resources have finished downloading. */ /* If any have, performs required patching and saving. */ void Fetcher_Update(void); + +CC_END_HEADER #endif diff --git a/src/SSL.h b/src/SSL.h index 3865d55d4..867742349 100644 --- a/src/SSL.h +++ b/src/SSL.h @@ -1,6 +1,8 @@ #ifndef CC_SSL_H #define CC_SSL_H #include "Platform.h" +CC_BEGIN_HEADER + /* Wraps a socket connection in a TLS/SSL connection Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -13,4 +15,6 @@ cc_result SSL_Init(cc_socket socket, const cc_string* host, void** ctx); cc_result SSL_Read(void* ctx, cc_uint8* data, cc_uint32 count, cc_uint32* read); cc_result SSL_WriteAll(void* ctx, const cc_uint8* data, cc_uint32 count); cc_result SSL_Free(void* ctx); + +CC_END_HEADER #endif diff --git a/src/Screens.h b/src/Screens.h index 5b4fff0aa..9ea465027 100644 --- a/src/Screens.h +++ b/src/Screens.h @@ -1,6 +1,8 @@ #ifndef CC_SCREENS_H #define CC_SCREENS_H #include "Core.h" +CC_BEGIN_HEADER + /* Contains all 2D non-menu screen implementations. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -44,4 +46,6 @@ void ChatScreen_OpenInput(const cc_string* text); void ChatScreen_AppendInput(const cc_string* text); /* Sets number of visible lines in the main chat widget. */ void ChatScreen_SetChatlines(int lines); + +CC_END_HEADER #endif diff --git a/src/SelOutlineRenderer.h b/src/SelOutlineRenderer.h index 7a039be69..b4a37b464 100644 --- a/src/SelOutlineRenderer.h +++ b/src/SelOutlineRenderer.h @@ -1,6 +1,8 @@ #ifndef CC_SELOUTLINERENDERER_H #define CC_SELOUTLINERENDERER_H #include "Core.h" +CC_BEGIN_HEADER + /* Renders an outline around the block the player is looking at. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -9,4 +11,6 @@ struct IGameComponent; extern struct IGameComponent SelOutlineRenderer_Component; void SelOutlineRenderer_Render(struct RayTracer* selected, cc_bool dirty); + +CC_END_HEADER #endif diff --git a/src/SelectionBox.h b/src/SelectionBox.h index d5149ebf8..386abed75 100644 --- a/src/SelectionBox.h +++ b/src/SelectionBox.h @@ -2,6 +2,8 @@ #define CC_SELECTIONBOX_H #include "Vectors.h" #include "PackedCol.h" +CC_BEGIN_HEADER + /* Describes a selection box, and contains methods related to the selection box. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -13,4 +15,6 @@ void Selections_Render(void); CC_API void Selections_Add(cc_uint8 id, const IVec3* p1, const IVec3* p2, PackedCol color); /* Removes the selection box with the givne ID */ CC_API void Selections_Remove(cc_uint8 id); + +CC_END_HEADER #endif diff --git a/src/Server.h b/src/Server.h index d17360999..1a6580204 100644 --- a/src/Server.h +++ b/src/Server.h @@ -1,6 +1,8 @@ #ifndef CC_SERVERCONNECTION_H #define CC_SERVERCONNECTION_H #include "Core.h" +CC_BEGIN_HEADER + /* Represents a connection to either a multiplayer or an internal singleplayer server Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -71,4 +73,6 @@ void Server_RetrieveTexturePack(const cc_string* url); /* Path of map to automatically load in singleplayer */ extern cc_string SP_AutoloadMap; + +CC_END_HEADER #endif diff --git a/src/Stream.h b/src/Stream.h index fb8dbc99a..ff3be7257 100644 --- a/src/Stream.h +++ b/src/Stream.h @@ -2,6 +2,8 @@ #define CC_STREAM_H #include "Constants.h" #include "Platform.h" +CC_BEGIN_HEADER + /* Defines an abstract way of reading and writing data in a streaming manner. Also provides common helper methods for reading/writing data to/from streams. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -98,4 +100,6 @@ cc_result Stream_ReadU32_BE(struct Stream* s, cc_uint32* value); CC_API cc_result Stream_ReadLine(struct Stream* s, cc_string* text); /* Writes a line of UTF8 encoded text to the stream. */ CC_API cc_result Stream_WriteLine(struct Stream* s, cc_string* text); + +CC_END_HEADER #endif diff --git a/src/String.h b/src/String.h index 7f1f2df7d..55075dcf1 100644 --- a/src/String.h +++ b/src/String.h @@ -1,6 +1,8 @@ #ifndef CC_STRING_H #define CC_STRING_H #include "Core.h" +CC_BEGIN_HEADER + /* Provides various string related operations Also provides conversions betweens strings and numbers @@ -156,17 +158,17 @@ typedef int (*FP_String_CaselessEnds)(const cc_string* str, const cc_string* sub CC_API int String_Compare(const cc_string* a, const cc_string* b); /* String_Format is provided for formatting strings (similiar to printf) -Supported specifiers for string formatting: - TYPE | ARGUMENT | EXAMPLE -%b | cc_uint8 | format(%b, 46) = "46" -%i | int | format(%i, -5) = "-5" -%f[0-9] | float | format(%f2, 321.3519) = "321.35" -%p[0-9] | int | format(%p3, 5) = "005" -%t | cc_bool | format(%t, 1) = "true" -%c | char* | format(%c, "ABCD") = "ABCD" -%s | cc_string | format(%s, {"ABCD", 2, 4}) = "AB" -%r | char | format(%r, 47) = "\" -%x | cc_uintptr| format(%x, 31) = "000000000000002F" +Supported specifiers for string formatting: + TYPE | ARGUMENT | EXAMPLE +%b | cc_uint8 | format(%b, 46) = "46" +%i | int | format(%i, -5) = "-5" +%f[0-9] | float | format(%f2, 321.3519) = "321.35" +%p[0-9] | int | format(%p3, 5) = "005" +%t | cc_bool | format(%t, 1) = "true" +%c | char* | format(%c, "ABCD") = "ABCD" +%s | cc_string | format(%s, {"ABCD", 2, 4}) = "AB" +%r | char | format(%r, 47) = "\" +%x | cc_uintptr| format(%x, 31) = "000000000000002F" %h | cc_uint32 | format(%h, 11) = "0000000B" */ @@ -270,4 +272,6 @@ void WordWrap_GetCoords(int index, const cc_string* lines, int numLines, int* co int WordWrap_GetBackLength(const cc_string* text, int index); /* Returns number of characters from current character to start of next word. */ int WordWrap_GetForwardLength(const cc_string* text, int index); + +CC_END_HEADER #endif diff --git a/src/SystemFonts.h b/src/SystemFonts.h index 2d666389b..79b47aa13 100644 --- a/src/SystemFonts.h +++ b/src/SystemFonts.h @@ -1,6 +1,8 @@ #ifndef CC_SYSTEMFONTS_H #define CC_SYSTEMFONTS_H #include "Core.h" +CC_BEGIN_HEADER + /* Manages loading and drawing platform specific system fonts Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -40,4 +42,6 @@ CC_API void SysFonts_GetNames(struct StringsBuffer* buffer); /* NOTE: If this file has been decoded before (fontscache.txt), does nothing */ cc_result SysFonts_Register(const cc_string* path, SysFont_RegisterCallback callback); void SysFonts_SaveCache(void); + +CC_END_HEADER #endif diff --git a/src/TexturePack.h b/src/TexturePack.h index b98c87fe6..a2883d727 100644 --- a/src/TexturePack.h +++ b/src/TexturePack.h @@ -1,6 +1,8 @@ #ifndef CC_TEXPACKS_H #define CC_TEXPACKS_H #include "Bitmap.h" +CC_BEGIN_HEADER + /* Contains everything relating to texture packs - Extracting the textures from a .zip archive @@ -113,4 +115,6 @@ struct TextureEntry { struct TextureEntry* next; }; void TextureEntry_Register(struct TextureEntry* entry); + +CC_END_HEADER #endif diff --git a/src/Utils.h b/src/Utils.h index 09fc54adb..885b035e5 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -1,6 +1,8 @@ #ifndef CC_UTILS_H #define CC_UTILS_H #include "Core.h" +CC_BEGIN_HEADER + /* Provides various utility functions Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -77,4 +79,6 @@ CC_NOINLINE int EntryList_Find(struct StringsBuffer* list, const cc_string* key, cc_bool DirectUrl_Claims(const cc_string* STRING_REF input, cc_string* addr, cc_string* user, cc_string* mppass); cc_bool DirectUrl_ExtractAddress(const cc_string* STRING_REF addr, cc_string* ip, cc_string* port, int* portNum); + +CC_END_HEADER #endif diff --git a/src/Vectors.h b/src/Vectors.h index 7cefe0c88..13bfd8506 100644 --- a/src/Vectors.h +++ b/src/Vectors.h @@ -2,6 +2,8 @@ #define CC_VECTORS_H #include "Core.h" #include "Constants.h" +CC_BEGIN_HEADER + /* Represents 2 and 3 component vectors, and 4 x 4 matrix Frustum culling sourced from http://www.crownandcutlass.com/features/technicaldetails/frustum.html @@ -136,4 +138,6 @@ cc_bool FrustumCulling_SphereInFrustum(float x, float y, float z, float radius); /* Calculates the clipping planes from the combined modelview and projection matrices */ /* Matrix_Mul(&clip, modelView, projection); */ void FrustumCulling_CalcFrustumEquations(struct Matrix* clip); + +CC_END_HEADER #endif diff --git a/src/Vorbis.h b/src/Vorbis.h index b37437ad7..7df52844f 100644 --- a/src/Vorbis.h +++ b/src/Vorbis.h @@ -1,6 +1,8 @@ #ifndef CC_VORBIS_H #define CC_VORBIS_H #include "Core.h" +CC_BEGIN_HEADER + /* Decodes ogg vorbis audio into 16 bit PCM samples Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -66,4 +68,6 @@ cc_result Vorbis_DecodeHeaders(struct VorbisState* ctx); cc_result Vorbis_DecodeFrame(struct VorbisState* ctx); /* Produces final interleaved audio samples for the current frame. */ int Vorbis_OutputFrame(struct VorbisState* ctx, cc_int16* data); + +CC_END_HEADER #endif diff --git a/src/Widgets.h b/src/Widgets.h index bfb59d443..1afde7274 100644 --- a/src/Widgets.h +++ b/src/Widgets.h @@ -6,6 +6,8 @@ #include "Entity.h" #include "Inventory.h" #include "IsometricDrawer.h" +CC_BEGIN_HEADER + /* Contains all 2D widget implementations. Copyright 2014-2023 ClassiCube | Licensed under BSD-3 */ @@ -312,4 +314,6 @@ struct ThumbstickWidget { void ThumbstickWidget_Init(struct ThumbstickWidget* w); void ThumbstickWidget_GetMovement(struct ThumbstickWidget* w, float* xMoving, float* zMoving); #endif + +CC_END_HEADER #endif diff --git a/src/Window.h b/src/Window.h index 528ad12fd..f73b94161 100644 --- a/src/Window.h +++ b/src/Window.h @@ -1,6 +1,8 @@ #ifndef CC_WINDOW_H #define CC_WINDOW_H #include "Core.h" +CC_BEGIN_HEADER + /* Abstracts interaction with a windowing system (creating window, moving cursor, etc) Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -260,4 +262,5 @@ void GLContext_SetVSync(cc_bool vsync); void GLContext_GetApiInfo(cc_string* info); #endif +CC_END_HEADER #endif diff --git a/src/Window_X11.c b/src/Window_X11.c index f401fbb06..55581ae96 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -397,11 +397,11 @@ static void DoCreateWindow(int width, int height) { /* So right name appears in e.g. Ubuntu Unity launchbar */ XClassHint hint = { 0 }; #ifdef CC_BUILD_FLATPAK - hint.res_name = "net.classicube.flatpak.client"; - hint.res_class = "net.classicube.flatpak.client"; + hint.res_name = (char*)"net.classicube.flatpak.client"; + hint.res_class = (char*)"net.classicube.flatpak.client"; #else - hint.res_name = GAME_APP_TITLE; - hint.res_class = GAME_APP_TITLE; + hint.res_name = (char*)GAME_APP_TITLE; + hint.res_class = (char*)GAME_APP_TITLE; #endif XSetClassHint(win_display, win, &hint); ApplyIcon(win); @@ -1160,7 +1160,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { fb_data = fb_fast ? bmp->scan0 : Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window blit"); fb_image = XCreateImage(win_display, win_visual.visual, - win_visual.depth, ZPixmap, 0, fb_data, + win_visual.depth, ZPixmap, 0, (char*)fb_data, width, height, 32, 0); } diff --git a/src/World.h b/src/World.h index 1f98c148f..bbfd09921 100644 --- a/src/World.h +++ b/src/World.h @@ -2,6 +2,8 @@ #define CC_WORLD_H #include "Vectors.h" #include "PackedCol.h" +CC_BEGIN_HEADER + /* Represents a fixed size 3D array of blocks and associated metadata Copyright 2014-2023 ClassiCube | Licensed under BSD-3 @@ -214,4 +216,6 @@ float Respawn_HighestSolidY(struct AABB* bb); /* Finds a suitable initial spawn position for the entity. */ /* Works by iterating downwards from top of world until solid ground is found. */ Vec3 Respawn_FindSpawnPosition(float x, float z, Vec3 modelSize); + +CC_END_HEADER #endif