diff --git a/src/Audio.c b/src/Audio.c index 734ea73bf..2a61726be 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -12,7 +12,9 @@ #include "Chat.h" #include "Stream.h" +int Audio_SoundsVolume, Audio_MusicVolume; static StringsBuffer files; + static void Volume_Mix16(int16_t* samples, int count, int volume) { int i; @@ -207,7 +209,6 @@ CC_NOINLINE static void Sounds_Fail(ReturnCode res) { Chat_LogError(res, "playing sounds"); Chat_AddRaw("&cDisabling sounds"); Audio_SetSounds(0); - Game_SoundsVolume = 0; } static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct AudioFormat* fmt, int volume) { @@ -249,12 +250,12 @@ static void Sounds_Play(uint8_t type, struct Soundboard* board) { int i, volume; ReturnCode res; - if (type == SOUND_NONE || Game_SoundsVolume == 0) return; + if (type == SOUND_NONE || !Audio_SoundsVolume == 0) return; snd = Soundboard_PickRandom(board, type); if (!snd) return; fmt = snd->Format; - volume = Game_SoundsVolume; + volume = Audio_SoundsVolume; outputs = fmt.Channels == 1 ? monoOutputs : stereoOutputs; if (board == &digBoard) { @@ -334,6 +335,7 @@ static void Sounds_Free(void) { void Audio_SetSounds(int volume) { if (volume) Sounds_Init(); else Sounds_Free(); + Audio_SoundsVolume = volume; } void Audio_PlayDigSound(uint8_t type) { Sounds_Play(type, &digBoard); } @@ -359,7 +361,7 @@ static ReturnCode Music_Buffer(int i, int16_t* data, int maxSamples, struct Vorb cur = &data[samples]; samples += Vorbis_OutputFrame(ctx, cur); } - if (Game_MusicVolume < 100) { Volume_Mix16(data, samples, Game_MusicVolume); } + if (Audio_MusicVolume < 100) { Volume_Mix16(data, samples, Audio_MusicVolume); } res2 = Audio_BufferData(music_out, i, data, samples * 2); if (res2) { music_pendingStop = true; return res2; } @@ -481,7 +483,7 @@ static void Music_RunLoop(void) { if (res) { Chat_AddRaw("&cDisabling music"); - Game_MusicVolume = 0; + Audio_MusicVolume = 0; } Audio_StopAndFree(music_out); @@ -510,6 +512,7 @@ static void Music_Free(void) { void Audio_SetMusic(int volume) { if (volume) Music_Init(); else Music_Free(); + Audio_MusicVolume = volume; } @@ -532,15 +535,17 @@ static void AudioManager_FilesCallback(const String* path, void* obj) { static void AudioManager_Init(void) { const static String path = String_FromConst("audio"); + int volume; + if (Directory_Exists(&path)) { Directory_Enum(&path, NULL, AudioManager_FilesCallback); } music_waitable = Waitable_Create(); - Game_MusicVolume = AudioManager_GetVolume(OPT_MUSIC_VOLUME, OPT_USE_MUSIC); - Audio_SetMusic(Game_MusicVolume); - Game_SoundsVolume = AudioManager_GetVolume(OPT_SOUND_VOLUME, OPT_USE_SOUND); - Audio_SetSounds(Game_SoundsVolume); + volume = AudioManager_GetVolume(OPT_MUSIC_VOLUME, OPT_USE_MUSIC); + Audio_SetMusic(volume); + volume = AudioManager_GetVolume(OPT_SOUND_VOLUME, OPT_USE_SOUND); + Audio_SetSounds(volume); Event_RegisterBlock(&UserEvents_BlockChanged, NULL, Audio_PlayBlockSound); } diff --git a/src/Audio.h b/src/Audio.h index fa74de73e..785851ea5 100644 --- a/src/Audio.h +++ b/src/Audio.h @@ -5,7 +5,13 @@ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ struct IGameComponent; -extern struct IGameComponent Audio_Component; +extern struct IGameComponent Audio_Component; +/* Volume sounds are played at, from 0-100. */ +/* NOTE: Use Audio_SetSounds, don't change this directly. */ +extern int Audio_SoundsVolume; +/* Volume music is played at, from 0-100. */ +/* NOTE: Use Audio_SetMusic, don't change this directly. */ +extern int Audio_MusicVolume; void Audio_SetMusic(int volume); void Audio_SetSounds(int volume); diff --git a/src/Block.c b/src/Block.c index 494abb006..3a456b479 100644 --- a/src/Block.c +++ b/src/Block.c @@ -561,6 +561,7 @@ void Block_UpdateCulling(BlockID block) { /*########################################################################################################################* *-------------------------------------------------------AutoRotate--------------------------------------------------------* *#########################################################################################################################*/ +bool AutoRotate_Enabled; static BlockID AutoRotate_Find(BlockID block, const String* name, const char* suffix) { String str; char strBuffer[STRING_SIZE * 2]; int rotated; @@ -689,6 +690,8 @@ static void Blocks_Init(void) { Block_CanPlace[block] = true; Block_CanDelete[block] = true; } + + AutoRotate_Enabled = true; Blocks_Reset(); Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, Blocks_AtlasChanged); diff --git a/src/Block.h b/src/Block.h index c309c2c42..3622bfdcd 100644 --- a/src/Block.h +++ b/src/Block.h @@ -113,9 +113,15 @@ void Block_SetTex(TextureLoc texLoc, Face face, BlockID blockId); #define Block_GetTex(block, face) Block_Textures[(block) * FACE_COUNT + (face)] bool Block_IsFaceHidden(BlockID block, BlockID other, Face face); +/* Updates culling data of all blocks. */ void Block_UpdateAllCulling(void); +/* Updates culling data just for this block. */ +/* This includes whether block can be stretched, and visibility with other blocks. */ void Block_UpdateCulling(BlockID block); +/* Whether blocks can be automatically rotated. */ +extern bool AutoRotate_Enabled; /* Attempts to find the rotated block based on the user's orientation and offset on selected block. */ +/* If no rotated block is found, returns given block. */ BlockID AutoRotate_RotateBlock(BlockID block); #endif diff --git a/src/Builder.c b/src/Builder.c index 5f5886b1d..96d9168dc 100644 --- a/src/Builder.c +++ b/src/Builder.c @@ -6,7 +6,6 @@ #include "Platform.h" #include "MapRenderer.h" #include "Graphics.h" -#include "ErrorHandler.h" #include "Drawer.h" #include "ExtMath.h" #include "BlockID.h" @@ -14,6 +13,7 @@ #include "PackedCol.h" #include "TexturePack.h" #include "VertexStructs.h" +#include "Options.h" int Builder_SidesLevel, Builder_EdgeLevel; /* Packs an index into the 16x16x16 count array. Coordinates range from 0 to 15. */ @@ -486,20 +486,6 @@ static void Builder_DrawSprite(int count) { part->sOffset += 4; } -void Builder_Init(void) { - Builder_Offsets[FACE_XMIN] = -1; - Builder_Offsets[FACE_XMAX] = 1; - Builder_Offsets[FACE_ZMIN] = -EXTCHUNK_SIZE; - Builder_Offsets[FACE_ZMAX] = EXTCHUNK_SIZE; - Builder_Offsets[FACE_YMIN] = -EXTCHUNK_SIZE_2; - Builder_Offsets[FACE_YMAX] = EXTCHUNK_SIZE_2; -} - -void Builder_OnNewMapLoaded(void) { - Builder_SidesLevel = max(0, Env_SidesHeight); - Builder_EdgeLevel = max(0, Env_EdgeHeight); -} - /*########################################################################################################################* *--------------------------------------------------Normal mesh builder----------------------------------------------------* @@ -1208,3 +1194,32 @@ void AdvBuilder_SetActive(void) { Builder_RenderBlock = Adv_RenderBlock; Builder_PreStretchTiles = Adv_PreStretchTiles; } + + +/*########################################################################################################################* +*---------------------------------------------------Builder interface-----------------------------------------------------* +*#########################################################################################################################*/ +bool Builder_SmoothLighting; +void Builder_ApplyActive(void) { + if (Builder_SmoothLighting) { + AdvBuilder_SetActive(); + } else { + NormalBuilder_SetActive(); + } +} + +void Builder_Init(void) { + Builder_Offsets[FACE_XMIN] = -1; + Builder_Offsets[FACE_XMAX] = 1; + Builder_Offsets[FACE_ZMIN] = -EXTCHUNK_SIZE; + Builder_Offsets[FACE_ZMAX] = EXTCHUNK_SIZE; + Builder_Offsets[FACE_YMIN] = -EXTCHUNK_SIZE_2; + Builder_Offsets[FACE_YMAX] = EXTCHUNK_SIZE_2; + + Builder_SmoothLighting = Options_GetBool(OPT_SMOOTH_LIGHTING, false); +} + +void Builder_OnNewMapLoaded(void) { + Builder_SidesLevel = max(0, Env_SidesHeight); + Builder_EdgeLevel = max(0, Env_EdgeHeight); +} \ No newline at end of file diff --git a/src/Builder.h b/src/Builder.h index 53f44492c..f45de6085 100644 --- a/src/Builder.h +++ b/src/Builder.h @@ -11,11 +11,15 @@ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 struct ChunkInfo; extern int Builder_SidesLevel, Builder_EdgeLevel; +/* Whether smooth/advanced lighting mesh builder is used. */ +extern bool Builder_SmoothLighting; void Builder_Init(void); void Builder_OnNewMapLoaded(void); +/* Builds the vertices mesh for the given chunk. */ void Builder_MakeChunk(struct ChunkInfo* info); void NormalBuilder_SetActive(void); void AdvBuilder_SetActive(void); +void Builder_ApplyActive(void); #endif diff --git a/src/Camera.c b/src/Camera.c index ad051ad07..c5a307568 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -8,11 +8,15 @@ #include "Entity.h" #include "Input.h" +int Camera_Sensitivity; +bool Camera_Smooth, Camera_Clipping, Camera_Invert; + struct Matrix Camera_TiltM; float Camera_BobbingVer, Camera_BobbingHor; Vector3 Camera_CurrentPos; struct Camera* Camera_Active; +static struct PickedPos cameraClipPos; static Vector2 cam_rotOffset; static bool cam_isForwardThird; @@ -62,11 +66,11 @@ static void PerspectiveCamera_RegrabMouse(void) { #define CAMERA_ADJUST 0.025f static Vector2 PerspectiveCamera_GetMouseDelta(void) { - float sensitivity = CAMERA_SENSI_FACTOR * Game_MouseSensitivity; + float sensitivity = CAMERA_SENSI_FACTOR * Camera_Sensitivity; static float speedX, speedY; Vector2 v; - if (Game_SmoothCamera) { + if (Camera_Smooth) { speedX += cam_delta.X * CAMERA_ADJUST; speedX *= CAMERA_SLIPPERY; speedY += cam_delta.Y * CAMERA_ADJUST; @@ -77,7 +81,7 @@ static Vector2 PerspectiveCamera_GetMouseDelta(void) { } v.X = speedX * sensitivity; v.Y = speedY * sensitivity; - if (Game_InvertMouse) v.Y = -v.Y; + if (Camera_Invert) v.Y = -v.Y; return v; } @@ -202,8 +206,8 @@ static Vector3 ThirdPersonCamera_GetPosition(float t) { dir = Vector3_GetDirVector(rot.X, rot.Y); Vector3_Negate(&dir, &dir); - Picking_ClipCameraPos(target, dir, dist, &Game_CameraClipPos); - return Game_CameraClipPos.Intersect; + Picking_ClipCameraPos(target, dir, dist, &cameraClipPos); + return cameraClipPos.Intersect; } static bool ThirdPersonCamera_Zoom(float amount) { @@ -238,6 +242,10 @@ void Camera_Init(void) { Camera_ThirdPerson.Next = &Camera_ForwardThird; Camera_ForwardThird.Next = &Camera_FirstPerson; Camera_Active = &Camera_FirstPerson; + + Camera_Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 30); + Camera_Clipping = Options_GetBool(OPT_CAMERA_CLIPPING, true); + Camera_Invert = Options_GetBool(OPT_INVERT_MOUSE, false); } void Camera_CycleActive(void) { diff --git a/src/Camera.h b/src/Camera.h index bb59b2adf..acddb6ffc 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -8,11 +8,20 @@ struct PickedPos; struct Camera; +/* How sensitive camera is to movements of mouse. */ +extern int Camera_Sensitivity; +/* Whether smooth/cinematic camera mode is used. */ +extern bool Camera_Smooth; +/* Whether third person camera clip against blocks. */ +extern bool Camera_Clipping; +/* Whether to invert vertical mouse movement. */ +extern bool Camera_Invert; + /* Tilt effect applied to the camera. */ extern struct Matrix Camera_TiltM; /* Bobbing offset of camera from player's eye. */ extern float Camera_BobbingVer, Camera_BobbingHor; -/* Cached position the camera is at */ +/* Cached position the camera is at. */ extern Vector3 Camera_CurrentPos; struct Camera { diff --git a/src/Chat.c b/src/Chat.c index 69a00b7de..9fcd5e51f 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -358,7 +358,7 @@ static void RenderTypeCommand_Execute(const String* args, int argsCount) { Chat_AddRaw("&e/client: &cYou didn't specify a new render type."); return; } - flags = Game_CalcRenderType(&args[0]); + flags = EnvRenderer_CalcFlags(&args[0]); if (flags >= 0) { EnvRenderer_UseLegacyMode( flags & 1); EnvRenderer_UseMinimalMode(flags & 2); diff --git a/src/Chat.h b/src/Chat.h index eb296877b..bbda22dc1 100644 --- a/src/Chat.h +++ b/src/Chat.h @@ -44,7 +44,7 @@ struct ChatCommand { struct ChatCommand* Next; /* Next command in linked-list of client commands */ }; /* Registers a client-side command, allowing it to be used with /client [cmd name] */ -CC_EXPORT void Commands_Register(struct ChatCommand* cmd); +CC_API void Commands_Register(struct ChatCommand* cmd); /* Sets the name of log file (no .txt, so e.g. just "singleplayer") */ /* NOTE: This can only be set once. */ @@ -52,13 +52,13 @@ void Chat_SetLogName(const String* name); /* Sends a chat message, raising ChatEvents_ChatSending event. */ /* NOTE: /client is always interpreted as client-side commands. */ /* In multiplayer this is sent to the server, in singleplayer just Chat_Add. */ -CC_EXPORT void Chat_Send(const String* text, bool logUsage); +CC_API void Chat_Send(const String* text, bool logUsage); /* Shorthand for Chat_AddOf(str, MSG_TYPE_NORMAL) */ -CC_EXPORT void Chat_Add(const String* text); +CC_API void Chat_Add(const String* text); /* Adds a chat message, raising ChatEvents_ChatReceived event. */ /* MSG_TYPE_NORMAL is usually used for player chat and command messages. */ /* Other message types are usually used for info/status messages. */ -CC_EXPORT void Chat_AddOf(const String* text, MsgType type); +CC_API void Chat_AddOf(const String* text, MsgType type); /* Shorthand for Chat_AddOf(String_FromReadonly(raw), MSG_TYPE_NORMAL) */ void Chat_AddRaw(const char* raw); diff --git a/src/Core.h b/src/Core.h index 385839d04..c7a79447e 100644 --- a/src/Core.h +++ b/src/Core.h @@ -22,19 +22,19 @@ typedef signed __int64 int64_t; #define CC_INLINE inline #define CC_NOINLINE __declspec(noinline) #define CC_ALIGN_HINT(x) __declspec(align(x)) -#ifndef CC_EXPORT -#define CC_EXPORT __declspec(dllexport, noinline) +#ifndef CC_API +#define CC_API __declspec(dllexport, noinline) #endif #elif __GNUC__ #include #define CC_INLINE inline #define CC_NOINLINE __attribute__((noinline)) #define CC_ALIGN_HINT(x) __attribute__((aligned(x))) -#ifndef CC_EXPORT +#ifndef CC_API #ifdef _WIN32 -#define CC_EXPORT __attribute__((dllexport, noinline)) +#define CC_API __attribute__((dllexport, noinline)) #else -#define CC_EXPORT __attribute__((visibility("default"), noinline)) +#define CC_API __attribute__((visibility("default"), noinline)) #endif #endif #else diff --git a/src/Deflate.h b/src/Deflate.h index ec4c742a1..a38cfed50 100644 --- a/src/Deflate.h +++ b/src/Deflate.h @@ -66,14 +66,14 @@ struct InflateState { }; /* Initialises DEFLATE decompressor state to defaults. */ -CC_EXPORT void Inflate_Init(struct InflateState* state, struct Stream* source); +CC_API void Inflate_Init(struct InflateState* state, struct Stream* source); /* Attempts to decompress all currently pending data. */ /* NOTE: This is a low level call - usually you should use Inflate_MakeStream. */ void Inflate_Process(struct InflateState* state); /* Deompresses input data read from another stream using DEFLATE. Read only stream. */ /* NOTE: This only uncompresses pure DEFLATE compressed data. */ /* If data starts with a GZIP or ZLIB header, use GZipHeader_Read or ZLibHeader_Read to first skip it. */ -CC_EXPORT void Inflate_MakeStream(struct Stream* stream, struct InflateState* state, struct Stream* underlying); +CC_API void Inflate_MakeStream(struct Stream* stream, struct InflateState* state, struct Stream* underlying); #define DEFLATE_BUFFER_SIZE 16384 @@ -97,17 +97,17 @@ struct DeflateState { }; /* Compresses input data using DEFLATE, then writes compressed output to another stream. Write only stream. */ /* DEFLATE compression is pure compressed data, there is no header or footer. */ -CC_EXPORT void Deflate_MakeStream(struct Stream* stream, struct DeflateState* state, struct Stream* underlying); +CC_API void Deflate_MakeStream(struct Stream* stream, struct DeflateState* state, struct Stream* underlying); struct GZipState { struct DeflateState Base; uint32_t Crc32, Size; }; /* Compresses input data using GZIP, then writes compressed output to another stream. Write only stream. */ /* GZIP compression is GZIP header, followed by DEFLATE compressed data, followed by GZIP footer. */ -CC_EXPORT void GZip_MakeStream(struct Stream* stream, struct GZipState* state, struct Stream* underlying); +CC_API void GZip_MakeStream(struct Stream* stream, struct GZipState* state, struct Stream* underlying); struct ZLibState { struct DeflateState Base; uint32_t Adler32; }; /* Compresses input data using ZLIB, then writes compressed output to another stream. Write only stream. */ /* ZLIB compression is ZLIB header, followed by DEFLATE compressed data, followed by ZLIB footer. */ -CC_EXPORT void ZLib_MakeStream(struct Stream* stream, struct ZLibState* state, struct Stream* underlying); +CC_API void ZLib_MakeStream(struct Stream* stream, struct ZLibState* state, struct Stream* underlying); /* Minimal data needed to describe an entry in a .zip archive. */ struct ZipEntry { uint32_t CompressedSize, UncompressedSize, LocalHeaderOffset, Crc32; }; @@ -130,8 +130,8 @@ struct ZipState { }; /* Initialises .zip archive reader state to defaults. */ -CC_EXPORT void Zip_Init(struct ZipState* state, struct Stream* input); +CC_API void Zip_Init(struct ZipState* state, struct Stream* input); /* Reads and processes the entries in a .zip archive. */ /* NOTE: Must have been initialised with Zip_Init first. */ -CC_EXPORT ReturnCode Zip_Extract(struct ZipState* state); +CC_API ReturnCode Zip_Extract(struct ZipState* state); #endif diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 962908a20..580dd4a1a 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -178,6 +178,25 @@ void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend, } } +void Gradient_Tint(Bitmap* bmp, uint8_t tintA, uint8_t tintB, + int x, int y, int width, int height) { + BitmapCol* row; + uint8_t tint; + int xx, yy; + if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return; + + for (yy = 0; yy < height; yy++) { + row = Bitmap_GetRow(bmp, y + yy) + x; + tint = (uint8_t)Math_Lerp(tintA, tintB, (float)yy / height); + + for (xx = 0; xx < width; xx++) { + row[xx].B = (row[xx].B * tint) / 255; + row[xx].G = (row[xx].G * tint) / 255; + row[xx].R = (row[xx].R * tint) / 255; + } + } +} + void Drawer2D_BmpIndexed(Bitmap* bmp, int x, int y, int size, uint8_t* indices, BitmapCol* palette) { BitmapCol* row; @@ -201,27 +220,20 @@ void Drawer2D_BmpIndexed(Bitmap* bmp, int x, int y, int size, void Drawer2D_BmpScaled(Bitmap* dst, int x, int y, int width, int height, Bitmap* src, int srcX, int srcY, int srcWidth, int srcHeight, - int scaleWidth, int scaleHeight, uint8_t tintA, uint8_t tintB) { - BitmapCol* dstRow, col; + int scaleWidth, int scaleHeight) { + BitmapCol* dstRow; BitmapCol* srcRow; int xx, yy; int scaledX, scaledY; - uint8_t tint; for (yy = 0; yy < height; yy++) { scaledY = (y + yy) * srcHeight / scaleHeight; srcRow = Bitmap_GetRow(src, srcY + (scaledY % srcHeight)); dstRow = Bitmap_GetRow(dst, y + yy) + x; - tint = (uint8_t)Math_Lerp(tintA, tintB, (float)yy / height); for (xx = 0; xx < width; xx++) { - scaledX = (x + xx) * srcWidth / scaleWidth; - col = srcRow[srcX + (scaledX % srcWidth)]; - - dstRow[xx].B = (col.B * tint) / 255; - dstRow[xx].G = (col.G * tint) / 255; - dstRow[xx].R = (col.R * tint) / 255; - dstRow[xx].A = col.A; + scaledX = (x + xx) * srcWidth / scaleWidth; + dstRow[xx] = srcRow[srcX + (scaledX % srcWidth)]; } } } diff --git a/src/Drawer2D.h b/src/Drawer2D.h index a2ab7fd78..8c1646c48 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -46,6 +46,10 @@ void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b, /* Note that this only blends RGB, A is not blended. */ void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend, int x, int y, int width, int height); +/* Tints the given area, linearly interpolating from a to b. */ +/* Note that this only tints RGB, A is not tinted. */ +void Gradient_Tint(Bitmap* bmp, uint8_t tintA, uint8_t tintB, + int x, int y, int width, int height); /* Fills the given area using pixels from an indexed bitmap. */ /* TODO: Currently this only handles square areas. */ @@ -53,11 +57,9 @@ void Drawer2D_BmpIndexed(Bitmap* bmp, int x, int y, int size, uint8_t* indices, BitmapCol* palette); /* Fills the given area using pixels from a region in the source bitmap, by repeatedly tiling the region. */ /* The pixels from the region are then scaled upwards or downwards depending on scale width and height. */ -/* The pixels are then tinted, with the tint factor a linear interpolation from tintA to tintB. */ -/* TODO: Bitmap tinting should be separate function. */ void Drawer2D_BmpScaled(Bitmap* dst, int x, int y, int width, int height, Bitmap* src, int srcX, int srcY, int srcWidth, int srcHeight, - int scaleWidth, int scaleHeight, uint8_t tintA, uint8_t tintB); + int scaleWidth, int scaleHeight); /* Fills the given area using pixels from a region in the source bitmap, by repeatedly tiling the region. */ /* For example, if area was 12x5 and region was 5x5, region gets drawn at (0,0), (5,0), (10,0) */ /* NOTE: The tiling origin is at (0, 0) not at (x, y) */ diff --git a/src/EnvRenderer.c b/src/EnvRenderer.c index 1cf251d50..a94aaa7df 100644 --- a/src/EnvRenderer.c +++ b/src/EnvRenderer.c @@ -835,6 +835,15 @@ void EnvRenderer_UseMinimalMode(bool minimal) { EnvRenderer_ContextRecreated(NULL); } +int EnvRenderer_CalcFlags(const String* mode) { + if (String_CaselessEqualsConst(mode, "legacyfast")) return ENV_LEGACY | ENV_MINIMAL; + if (String_CaselessEqualsConst(mode, "legacy")) return ENV_LEGACY; + if (String_CaselessEqualsConst(mode, "normal")) return 0; + if (String_CaselessEqualsConst(mode, "normalfast")) return ENV_MINIMAL; + + return -1; +} + static void EnvRenderer_FileChanged(void* obj, struct Stream* src, const String* name) { if (String_CaselessEqualsConst(name, "clouds.png")) { @@ -896,10 +905,10 @@ static void EnvRenderer_Init(void) { int flags; Options_UNSAFE_Get(OPT_RENDER_TYPE, &renderType); - flags = Game_CalcRenderType(&renderType); + flags = EnvRenderer_CalcFlags(&renderType); if (flags == -1) flags = 0; - EnvRenderer_Legacy = (flags & 1); - EnvRenderer_Minimal = (flags & 2); + EnvRenderer_Legacy = flags & ENV_LEGACY; + EnvRenderer_Minimal = flags & ENV_MINIMAL; Event_RegisterEntry(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged); Event_RegisterVoid(&TextureEvents_PackChanged, NULL, EnvRenderer_TexturePackChanged); diff --git a/src/EnvRenderer.h b/src/EnvRenderer.h index 822e839f3..e31bcacea 100644 --- a/src/EnvRenderer.h +++ b/src/EnvRenderer.h @@ -1,12 +1,15 @@ #ifndef CC_ENVRENDERER_H #define CC_ENVRENDERER_H -#include "Core.h" +#include "String.h" /* Renders environment of the map. (clouds, sky, fog, map sides/edges, skybox, rain/snow) Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ struct IGameComponent; extern struct IGameComponent EnvRenderer_Component; +#define ENV_LEGACY 1 +#define ENV_MINIMAL 2 + void EnvRenderer_RenderSky(double deltaTime); void EnvRenderer_RenderClouds(double deltaTime); void EnvRenderer_UpdateFog(void); @@ -23,4 +26,7 @@ void EnvRenderer_RenderWeather(double deltaTime); extern bool EnvRenderer_Legacy, EnvRenderer_Minimal; void EnvRenderer_UseMinimalMode(bool minimal); void EnvRenderer_UseLegacyMode(bool legacy); +/* Calculates mode flags for the given mode. */ +/* mode can be: normal, normalfast, legacy, legacyfast */ +CC_NOINLINE int EnvRenderer_CalcFlags(const String* mode); #endif diff --git a/src/Formats.h b/src/Formats.h index a25dfc626..296e766ff 100644 --- a/src/Formats.h +++ b/src/Formats.h @@ -10,10 +10,10 @@ struct Stream; typedef ReturnCode (*IMapImporter)(struct Stream* stream); /* Attempts to find the suitable importer based on filename. */ /* Returns NULL if no match found. */ -CC_EXPORT IMapImporter Map_FindImporter(const String* path); +CC_API IMapImporter Map_FindImporter(const String* path); /* Attempts to import the map from the given file. */ /* NOTE: Uses Map_FindImporter to import based on filename. */ -CC_EXPORT void Map_LoadFrom(const String* path); +CC_API void Map_LoadFrom(const String* path); /* Imports a world from a .lvl MCSharp server map file. */ /* Used by MCSharp/MCLawl/MCForge/MCDzienny/MCGalaxy. */ diff --git a/src/Game.c b/src/Game.c index 3fb2b09ff..158399305 100644 --- a/src/Game.c +++ b/src/Game.c @@ -36,31 +36,23 @@ int Game_Width, Game_Height; double Game_Time; int Game_ChunkUpdates, Game_Port; -bool Game_CameraClipping, Game_UseCPEBlocks; +bool Game_UseCPEBlocks; -struct PickedPos Game_SelectedPos, Game_CameraClipPos; +struct PickedPos Game_SelectedPos; int Game_ViewDistance, Game_MaxViewDistance, Game_UserViewDistance; int Game_Fov, Game_DefaultFov, Game_ZoomFov; float game_limitMs; int Game_FpsLimit, Game_Vertices; bool Game_ShowAxisLines, Game_SimpleArmsAnim; -bool Game_ClassicArmModel, Game_InvertMouse; +bool Game_ClassicArmModel; -int Game_MouseSensitivity, Game_ChatLines; -bool Game_TabAutocomplete, Game_UseClassicGui; -bool Game_UseClassicTabList, Game_UseClassicOptions; bool Game_ClassicMode, Game_ClassicHacks; bool Game_AllowCustomBlocks, Game_UseCPE; -bool Game_AllowServerTextures, Game_SmoothLighting; -bool Game_AutoRotate; -bool Game_SmoothCamera, Game_ClickableChat; -bool Game_HideGui, Game_ShowFPS; +bool Game_AllowServerTextures; -bool Game_ViewBobbing, Game_ShowBlockInHand; -int Game_SoundsVolume, Game_MusicVolume; +bool Game_ViewBobbing, Game_HideGui; bool Game_BreakableLiquids, Game_ScreenshotRequested; -int Game_MaxChunkUpdates; float Game_RawHotbarScale, Game_RawChatScale, Game_RawInventoryScale; static struct ScheduledTask Game_Tasks[6]; @@ -271,22 +263,13 @@ bool Game_ValidateBitmap(const String* file, Bitmap* bmp) { if (!Math_IsPowOf2(bmp->Width) || !Math_IsPowOf2(bmp->Height)) { Chat_Add1("&cUnable to use %s from the texture pack.", file); - Chat_Add2("&c Its size is (%i,%i), which is not power of two dimensions.", + Chat_Add2("&c Its size is (%i,%i), which is not a power of two size.", &bmp->Width, &bmp->Height); return false; } return true; } -int Game_CalcRenderType(const String* type) { - if (String_CaselessEqualsConst(type, "legacyfast")) return 0x03; - if (String_CaselessEqualsConst(type, "legacy")) return 0x01; - if (String_CaselessEqualsConst(type, "normal")) return 0x00; - if (String_CaselessEqualsConst(type, "normalfast")) return 0x02; - - return -1; -} - void Game_UpdateClientSize(void) { Size2D size = Window_ClientSize; Game_Width = max(size.Width, 1); @@ -365,9 +348,7 @@ static void Game_LoadOptions(void) { Game_UseCPE = Options_GetBool(OPT_CPE, true); Game_SimpleArmsAnim = Options_GetBool(OPT_SIMPLE_ARMS_ANIM, false); Game_ClassicArmModel = Options_GetBool(OPT_CLASSIC_ARM_MODEL, Game_ClassicMode); - - Game_ViewBobbing = Options_GetBool(OPT_VIEW_BOBBING, true); - Game_SmoothLighting = Options_GetBool(OPT_SMOOTH_LIGHTING, false); + Game_ViewBobbing = Options_GetBool(OPT_VIEW_BOBBING, true); method = Options_GetEnum(OPT_FPS_LIMIT, 0, FpsLimit_Names, FPS_LIMIT_COUNT); Game_SetFpsLimit(method); @@ -378,14 +359,11 @@ static void Game_LoadOptions(void) { Game_Fov = Game_DefaultFov; Game_ZoomFov = Game_DefaultFov; Game_BreakableLiquids = !Game_ClassicMode && Options_GetBool(OPT_MODIFIABLE_LIQUIDS, false); - Game_CameraClipping = Options_GetBool(OPT_CAMERA_CLIPPING, true); - Game_MaxChunkUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30); - Game_AllowServerTextures = Options_GetBool(OPT_SERVER_TEXTURES, true); - Game_MouseSensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 30); - Game_ShowBlockInHand = Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true); - Game_InvertMouse = Options_GetBool(OPT_INVERT_MOUSE, false); + Game_RawInventoryScale = Options_GetFloat(OPT_INVENTORY_SCALE, 0.25f, 5.0f, 1.0f); + Game_RawHotbarScale = Options_GetFloat(OPT_HOTBAR_SCALE, 0.25f, 5.0f, 1.0f); + Game_RawChatScale = Options_GetFloat(OPT_CHAT_SCALE, 0.35f, 5.0f, 1.0f); /* TODO: Do we need to support option to skip SSL */ /*bool skipSsl = Options_GetBool("skip-ssl-check", false); if (skipSsl) { @@ -394,23 +372,8 @@ static void Game_LoadOptions(void) { }*/ } -static void Game_LoadGuiOptions(void) { - Game_ChatLines = Options_GetInt(OPT_CHATLINES, 0, 30, 12); - Game_ClickableChat = Options_GetBool(OPT_CLICKABLE_CHAT, false); - Game_RawInventoryScale = Options_GetFloat(OPT_INVENTORY_SCALE, 0.25f, 5.0f, 1.0f); - Game_RawHotbarScale = Options_GetFloat(OPT_HOTBAR_SCALE, 0.25f, 5.0f, 1.0f); - Game_RawChatScale = Options_GetFloat(OPT_CHAT_SCALE, 0.35f, 5.0f, 1.0f); - Game_ShowFPS = Options_GetBool(OPT_SHOW_FPS, true); - - Game_UseClassicGui = Options_GetBool(OPT_CLASSIC_GUI, true) || Game_ClassicMode; - Game_UseClassicTabList = Options_GetBool(OPT_CLASSIC_TABLIST, false) || Game_ClassicMode; - Game_UseClassicOptions = Options_GetBool(OPT_CLASSIC_OPTIONS, false) || Game_ClassicMode; - - Game_TabAutocomplete = Options_GetBool(OPT_TAB_AUTOCOMPLETE, false); -} - void Game_Free(void* obj); -void Game_Load(void) { +static void Game_Load(void) { String title; char titleBuffer[STRING_SIZE]; struct IGameComponent* comp; @@ -418,7 +381,6 @@ void Game_Load(void) { Game_MaxViewDistance = 32768; Game_UserViewDistance = 512; Game_Fov = 70; - Game_AutoRotate = true; Gfx_Init(); Gfx_SetVSync(true); @@ -427,7 +389,6 @@ void Game_Load(void) { Game_UpdateClientSize(); Game_LoadOptions(); - Game_LoadGuiOptions(); Event_RegisterVoid(&WorldEvents_NewMap, NULL, Game_OnNewMapCore); Event_RegisterVoid(&WorldEvents_MapLoaded, NULL, Game_OnNewMapLoadedCore); diff --git a/src/Game.h b/src/Game.h index c9ad24cc0..6fce93d2f 100644 --- a/src/Game.h +++ b/src/Game.h @@ -10,13 +10,13 @@ struct DisplayDevice; struct Stream; +/* Width and height of the window. (1 at minimum) */ extern int Game_Width, Game_Height; /* Total time (in seconds) the game has been running for. */ extern double Game_Time; +/* Number of chunks updated within last second. Resets to 0 after every second. */ extern int Game_ChunkUpdates; -extern bool Game_CameraClipping; extern struct PickedPos Game_SelectedPos; -extern struct PickedPos Game_CameraClipPos; extern bool Game_UseCPEBlocks; extern String Game_Username; @@ -35,35 +35,19 @@ extern int Game_FpsLimit; extern bool Game_ShowAxisLines; extern bool Game_SimpleArmsAnim; extern bool Game_ClassicArmModel; -extern bool Game_InvertMouse; extern int Game_Vertices; -extern int Game_MouseSensitivity; -extern bool Game_TabAutocomplete; -extern bool Game_UseClassicGui; -extern bool Game_UseClassicTabList; -extern bool Game_UseClassicOptions; extern bool Game_ClassicMode; extern bool Game_ClassicHacks; #define Game_PureClassic (Game_ClassicMode && !Game_ClassicHacks) extern bool Game_AllowCustomBlocks; extern bool Game_UseCPE; extern bool Game_AllowServerTextures; -extern bool Game_SmoothLighting; -extern bool Game_AutoRotate; -extern bool Game_SmoothCamera; -extern int Game_ChatLines; -extern bool Game_ClickableChat; -extern bool Game_HideGui; -extern bool Game_ShowFPS; extern bool Game_ViewBobbing; -extern bool Game_ShowBlockInHand; -extern int Game_SoundsVolume; -extern int Game_MusicVolume; extern bool Game_BreakableLiquids; -extern int Game_MaxChunkUpdates; extern bool Game_ScreenshotRequested; +extern bool Game_HideGui; extern float Game_RawHotbarScale, Game_RawChatScale, Game_RawInventoryScale; float Game_Scale(float value); @@ -71,9 +55,13 @@ float Game_GetHotbarScale(void); float Game_GetInventoryScale(void); float Game_GetChatScale(void); +/* Retrieves the filename of the default texture pack used. */ +/* NOTE: Returns default.zip if classic mode or selected pack does not exist. */ void Game_GetDefaultTexturePack(String* texPack); +/* Sets the filename of the default texture pack used. */ void Game_SetDefaultTexturePack(const String* texPack); +/* Attempts to change the terrain atlas. (bitmap containing textures for all blocks) */ bool Game_ChangeTerrainAtlas(Bitmap* atlas); void Game_SetViewDistance(int distance); void Game_UserSetViewDistance(int distance); @@ -83,17 +71,21 @@ void Game_Reset(void); /* Sets the block in the map at the given coordinates, then updates state associated with the block. */ /* (updating state means recalculating light, redrawing chunk block is in, etc) */ /* NOTE: This does NOT notify the server, use Game_ChangeBlock for that. */ -CC_EXPORT void Game_UpdateBlock(int x, int y, int z, BlockID block); +CC_API void Game_UpdateBlock(int x, int y, int z, BlockID block); /* Calls Game_UpdateBlock, then informs server connection of the block change. */ /* In multiplayer this is sent to the server, in singleplayer just activates physics. */ -CC_EXPORT void Game_ChangeBlock(int x, int y, int z, BlockID block); +CC_API void Game_ChangeBlock(int x, int y, int z, BlockID block); bool Game_CanPick(BlockID block); bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* file, uint8_t* skinType); -bool Game_ValidateBitmap(const String* file, Bitmap* bmp); -int Game_CalcRenderType(const String* type); +/* Checks that the given bitmap can be loaded into a native gfx texture. */ +/* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */ +bool Game_ValidateBitmap(const String* file, Bitmap* bmp);/* Calculates Game_Width and Game_Height. */ void Game_UpdateClientSize(void); +/* Sets the strategy/method used to limit frames per second. */ void Game_SetFpsLimit(enum FpsLimit method); +/* Returns max time process sleeps for when limiting frames using the given method. */ float Game_CalcLimitMillis(enum FpsLimit method); +/* Runs the main game loop until the window is closed. */ void Game_Run(int width, int height, const String* title); #endif diff --git a/src/Gui.c b/src/Gui.c index a292dc9e6..e85be65b4 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -12,6 +12,10 @@ #include "Platform.h" #include "Bitmap.h" +bool Gui_ClassicTexture, Gui_ClassicTabList, Gui_ClassicMenu; +int Gui_Chatlines; +bool Gui_ClickableChat, Gui_TabAutocomplete, Gui_ShowFPS; + GfxResourceID Gui_GuiTex, Gui_GuiClassicTex, Gui_IconsTex; struct Screen* Gui_Status; struct Screen* Gui_HUD; @@ -88,6 +92,18 @@ CC_NOINLINE static void Gui_RecreateScreen(struct Screen* screen) { Elem_Recreate(screen); } +static void Gui_LoadOptions(void) { + Gui_Chatlines = Options_GetInt(OPT_CHATLINES, 0, 30, 12); + Gui_ClickableChat = Options_GetBool(OPT_CLICKABLE_CHAT, false); + Gui_TabAutocomplete = Options_GetBool(OPT_TAB_AUTOCOMPLETE, false); + + Gui_ClassicTexture = Options_GetBool(OPT_CLASSIC_GUI, true) || Game_ClassicMode; + Gui_ClassicTabList = Options_GetBool(OPT_CLASSIC_TABLIST, false) || Game_ClassicMode; + Gui_ClassicMenu = Options_GetBool(OPT_CLASSIC_OPTIONS, false) || Game_ClassicMode; + + Gui_ShowFPS = Options_GetBool(OPT_SHOW_FPS, true); +} + static void Gui_FontChanged(void* obj) { Gui_RecreateScreen(Gui_Active); Gui_RecreateScreen(Gui_Status); @@ -107,9 +123,10 @@ static void Gui_FileChanged(void* obj, struct Stream* stream, const String* name static void Gui_Init(void) { Event_RegisterVoid(&ChatEvents_FontChanged, NULL, Gui_FontChanged); Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Gui_FileChanged); + Gui_LoadOptions(); + Gui_Status = StatusScreen_MakeInstance(); Gui_HUD = HUDScreen_MakeInstance(); - Elem_Init(Gui_Status); Elem_Init(Gui_HUD); } diff --git a/src/Gui.h b/src/Gui.h index ec54ec74d..961d3706d 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -17,6 +17,21 @@ struct IGameComponent; struct GuiElem; extern struct IGameComponent Gui_Component; +/* Whether vanilla MineCraft Classic gui texture is used. */ +extern bool Gui_ClassicTexture; +/* Whether tab list is laid out like vanilla MineCraft Classic. */ +extern bool Gui_ClassicTabList; +/* Whether menus are laid out like vanilla MineCraft Classic. */ +extern bool Gui_ClassicMenu; +/* Maximum number of visible chatlines on screen. Can be 0. */ +extern int Gui_Chatlines; +/* Whether clicking on a chatline inserts it into chat input. */ +extern bool Gui_ClickableChat; +/* Whether pressing tab in chat input attempts to autocomplete player names. */ +extern bool Gui_TabAutocomplete; +/* Whether FPS counter (and other info) is shown in top left. */ +extern bool Gui_ShowFPS; + #define GuiElemVTABLE_Layout() \ void (*Init)(void* elem); \ void (*Render)(void* elem, double delta); \ @@ -42,10 +57,10 @@ struct ScreenVTABLE { Event_Void_Callback ContextRecreated; }; #define Screen_Layout struct ScreenVTABLE* VTABLE; \ - bool HandlesAllInput; /* Whether this screen handles all input. Prevents user interacting with the world */ \ - bool BlocksWorld; /* Whether this screen completely and opaquely covers the game world behind it */ \ - bool HidesHUD; /* Whether this screen hides the normal in-game HUD */ \ - bool RenderHUDOver; /* Whether the normal in-game HUD should be drawn over the top of this screen */ + bool HandlesAllInput; /* Whether this screen handles all input. Prevents user interacting with the world. */ \ + bool BlocksWorld; /* Whether this screen completely and opaquely covers the game world behind it. */ \ + bool HidesHUD; /* Whether this screen hides the normal in-game HUD. */ \ + bool RenderHUDOver; /* Whether the normal in-game HUD should be drawn over the top of this screen. */ /* Represents a container of widgets and other 2D elements. May cover entire window. */ struct Screen { Screen_Layout }; @@ -85,11 +100,11 @@ extern int Gui_OverlaysCount; int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen); bool Gui_Contains(int recX, int recY, int width, int height, int x, int y); -/* Gets the screen that the user is currently interacting with. -This means if an overlay is active, it will be over the top of other screens. */ +/* Gets the screen that the user is currently interacting with. */ +/* This means if an overlay is active, it will be over the top of other screens. */ struct Screen* Gui_GetActiveScreen(void); -/* Gets the non-overlay screen that the user is currently interacting with. -This means if an overlay is active, it will return the screen under it. */ +/* Gets the non-overlay screen that the user is currently interacting with. */ +/* This means if an overlay is active, the screen under it is returned. */ struct Screen* Gui_GetUnderlyingScreen(void); CC_NOINLINE void Gui_FreeActive(void); diff --git a/src/HeldBlockRenderer.c b/src/HeldBlockRenderer.c index b3132121e..e4222ae4f 100644 --- a/src/HeldBlockRenderer.c +++ b/src/HeldBlockRenderer.c @@ -10,6 +10,7 @@ #include "Model.h" #include "GameStructs.h" +bool HeldBlockRenderer_Show; static BlockID held_block; static struct Entity held_entity; static struct Matrix held_blockProjection; @@ -209,7 +210,7 @@ static void HeldBlockRenderer_DoAnimation(double delta, float lastSwingY) { void HeldBlockRenderer_Render(double delta) { float lastSwingY; struct Matrix view; - if (!Game_ShowBlockInHand) return; + if (!HeldBlockRenderer_Show) return; lastSwingY = held_swingY; held_swingY = 0.0f; @@ -234,10 +235,12 @@ struct EntityVTABLE heldEntity_VTABLE = { }; static void HeldBlockRenderer_Init(void) { Entity_Init(&held_entity); - held_entity.VTABLE = &heldEntity_VTABLE; + held_entity.VTABLE = &heldEntity_VTABLE; held_entity.NoShade = true; - held_lastBlock = Inventory_SelectedBlock; + HeldBlockRenderer_Show = Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true); + held_lastBlock = Inventory_SelectedBlock; + Event_RegisterVoid(&GfxEvents_ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged); Event_RegisterVoid(&UserEvents_HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim); Event_RegisterBlock(&UserEvents_BlockChanged, NULL, HeldBlockRenderer_BlockChanged); diff --git a/src/HeldBlockRenderer.h b/src/HeldBlockRenderer.h index 9c36367fa..1467d93dd 100644 --- a/src/HeldBlockRenderer.h +++ b/src/HeldBlockRenderer.h @@ -6,6 +6,8 @@ */ struct IGameComponent; extern struct IGameComponent HeldBlockRenderer_Component; +/* Whether held block/arm should be shown at all. */ +extern bool HeldBlockRenderer_Show; void HeldBlockRenderer_ClickAnim(bool digging); void HeldBlockRenderer_Render(double delta); diff --git a/src/InputHandler.c b/src/InputHandler.c index 8da631e4e..b16d0b5b7 100644 --- a/src/InputHandler.c +++ b/src/InputHandler.c @@ -146,7 +146,7 @@ static bool InputHandler_HandleNonClassicKey(Key key) { if (key == KeyBind_Get(KEYBIND_HIDE_GUI)) { Game_HideGui = !Game_HideGui; } else if (key == KeyBind_Get(KEYBIND_SMOOTH_CAMERA)) { - InputHandler_Toggle(key, &Game_SmoothCamera, + InputHandler_Toggle(key, &Camera_Smooth, " &eSmooth camera is &aenabled", " &eSmooth camera is &cdisabled"); } else if (key == KeyBind_Get(KEYBIND_AXIS_LINES)) { @@ -154,13 +154,13 @@ static bool InputHandler_HandleNonClassicKey(Key key) { " &eAxis lines (&4X&e, &2Y&e, &1Z&e) now show", " &eAxis lines no longer show"); } else if (key == KeyBind_Get(KEYBIND_AUTOROTATE)) { - InputHandler_Toggle(key, &Game_AutoRotate, + InputHandler_Toggle(key, &AutoRotate_Enabled, " &eAuto rotate is &aenabled", " &eAuto rotate is &cdisabled"); } else if (key == KeyBind_Get(KEYBIND_THIRD_PERSO)) { Camera_CycleActive(); } else if (key == KeyBind_Get(KEYBIND_DROP_BLOCK)) { - if (Inventory_CanChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) { + if (Inventory_CheckChangeSelected() && Inventory_SelectedBlock != BLOCK_AIR) { /* Don't assign SelectedIndex directly, because we don't want held block switching positions if they already have air in their inventory hotbar. */ Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR); @@ -183,7 +183,7 @@ static bool InputHandler_HandleCoreKey(Key key) { struct Screen* active = Gui_GetActiveScreen(); if (key == KeyBind_Get(KEYBIND_HIDE_FPS)) { - Game_ShowFPS = !Game_ShowFPS; + Gui_ShowFPS = !Gui_ShowFPS; } else if (key == KeyBind_Get(KEYBIND_FULLSCREEN)) { int state = Window_GetWindowState(); if (state != WINDOW_STATE_MAXIMISED) { @@ -191,8 +191,8 @@ static bool InputHandler_HandleCoreKey(Key key) { Window_SetWindowState(fullscreen ? WINDOW_STATE_NORMAL : WINDOW_STATE_FULLSCREEN); } } else if (key == KeyBind_Get(KEYBIND_FOG)) { - int16_t* viewDists = Game_UseClassicOptions ? input_classicViewDists : input_normViewDists; - int count = Game_UseClassicOptions ? Array_Elems(input_classicViewDists) : Array_Elems(input_normViewDists); + int16_t* viewDists = Gui_ClassicMenu ? input_classicViewDists : input_normViewDists; + int count = Gui_ClassicMenu ? Array_Elems(input_classicViewDists) : Array_Elems(input_normViewDists); if (Key_IsShiftPressed()) { InputHandler_CycleDistanceBackwards(viewDists, count); @@ -335,7 +335,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) InputHandler_ButtonStateChanged(MOUSE_MIDDLE, middle); } - if (Gui_GetActiveScreen()->HandlesAllInput || !Inventory_CanPick) return; + if (Gui_GetActiveScreen()->HandlesAllInput || !Inventory_CanUse) return; if (left) { /* always play delete animations, even if we aren't picking a block */ @@ -355,7 +355,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) old = World_GetBlock(p.X, p.Y, p.Z); block = Inventory_SelectedBlock; - if (Game_AutoRotate) { block = AutoRotate_RotateBlock(block); } + if (AutoRotate_Enabled) block = AutoRotate_RotateBlock(block); if (Game_CanPick(old) || !Block_CanPlace[block]) return; /* air-ish blocks can only replace over other air-ish blocks */ @@ -371,7 +371,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right) cur = World_GetBlock(p.X, p.Y, p.Z); if (Block_Draw[cur] == DRAW_GAS) return; if (!(Block_CanPlace[cur] || Block_CanDelete[cur])) return; - if (!Inventory_CanChangeSelected() || Inventory_SelectedBlock == cur) return; + if (!Inventory_CheckChangeSelected() || Inventory_SelectedBlock == cur) return; /* Is the currently selected block an empty slot? */ if (Inventory_SelectedBlock == BLOCK_AIR) { @@ -404,7 +404,7 @@ static void InputHandler_MouseWheel(void* obj, float delta) { hotbar = Key_IsAltPressed() || Key_IsControlPressed() || Key_IsShiftPressed(); if (!hotbar && Camera_Active->Zoom(delta)) return; - if (InputHandler_DoFovZoom(delta) || !Inventory_CanChangeHeldBlock) return; + if (InputHandler_DoFovZoom(delta) || !Inventory_CanChangeSelected) return; widget = HUDScreen_GetHotbar(Gui_HUD); Elem_HandlesMouseScroll(widget, delta); diff --git a/src/Inventory.c b/src/Inventory.c index e76b8a271..afa24db99 100644 --- a/src/Inventory.c +++ b/src/Inventory.c @@ -11,10 +11,10 @@ BlockID Inventory_Map[BLOCK_COUNT]; int Inventory_SelectedIndex; int Inventory_Offset; -bool Inventory_CanChangeHeldBlock, Inventory_CanPick; +bool Inventory_CanChangeSelected, Inventory_CanUse; -bool Inventory_CanChangeSelected(void) { - if (!Inventory_CanChangeHeldBlock) { +bool Inventory_CheckChangeSelected(void) { + if (!Inventory_CanChangeSelected) { Chat_AddRaw("&cThe server has forbidden you from changing your held block."); return false; } @@ -22,20 +22,20 @@ bool Inventory_CanChangeSelected(void) { } void Inventory_SetSelectedIndex(int index) { - if (!Inventory_CanChangeSelected()) return; + if (!Inventory_CheckChangeSelected()) return; Inventory_SelectedIndex = index; Event_RaiseVoid(&UserEvents_HeldBlockChanged); } -void Inventory_SetOffset(int offset) { - if (!Inventory_CanChangeSelected() || Game_ClassicMode) return; - Inventory_Offset = offset; +void Inventory_SetHotbarIndex(int index) { + if (!Inventory_CheckChangeSelected() || Game_ClassicMode) return; + Inventory_Offset = index * INVENTORY_BLOCKS_PER_HOTBAR; Event_RaiseVoid(&UserEvents_HeldBlockChanged); } void Inventory_SetSelectedBlock(BlockID block) { int i; - if (!Inventory_CanChangeSelected()) return; + if (!Inventory_CheckChangeSelected()) return; /* Swap with the current, if the new block is already in the hotbar */ for (i = 0; i < INVENTORY_BLOCKS_PER_HOTBAR; i++) { @@ -74,7 +74,7 @@ static BlockID Inventory_DefaultMapping(int slot) { return BLOCK_AIR; } -void Inventory_SetDefaultMapping(void) { +void Inventory_ApplyDefaultMapping(void) { int slot; for (slot = 0; slot < Array_Elems(Inventory_Map); slot++) { Inventory_Map[slot] = Inventory_DefaultMapping(slot); @@ -106,9 +106,9 @@ void Inventory_Remove(BlockID block) { *--------------------------------------------------Inventory component----------------------------------------------------* *#########################################################################################################################*/ static void Inventory_Reset(void) { - Inventory_SetDefaultMapping(); - Inventory_CanChangeHeldBlock = true; - Inventory_CanPick = true; + Inventory_ApplyDefaultMapping(); + Inventory_CanChangeSelected = true; + Inventory_CanUse = true; } static void Inventory_Init(void) { diff --git a/src/Inventory.h b/src/Inventory.h index 710161f22..f06a6f842 100644 --- a/src/Inventory.h +++ b/src/Inventory.h @@ -11,24 +11,44 @@ extern struct IGameComponent Inventory_Component; #define INVENTORY_BLOCKS_PER_HOTBAR 9 #define INVENTORY_HOTBARS 9 -/* Stores the blocks for all hotbars. */ +/* Stores the currently bound blocks for all hotbars. */ extern BlockID Inventory_Table[INVENTORY_HOTBARS * INVENTORY_BLOCKS_PER_HOTBAR]; /* Mapping of indices in inventory menu to block IDs. */ extern BlockID Inventory_Map[BLOCK_COUNT]; +/* Currently selected index within a hotbar. */ extern int Inventory_SelectedIndex; +/* Currently selected hotbar. */ extern int Inventory_Offset; +/* Gets the block at the nth index in the current hotbar. */ #define Inventory_Get(idx) (Inventory_Table[Inventory_Offset + (idx)]) +/* Sets the block at the nth index in the current hotbar. */ #define Inventory_Set(idx, block) Inventory_Table[Inventory_Offset + (idx)] = block +/* Gets the currently selected block. */ #define Inventory_SelectedBlock Inventory_Get(Inventory_SelectedIndex) -extern bool Inventory_CanChangeHeldBlock, Inventory_CanPick; +/* Whether the user is allowed to change selected/held block. */ +extern bool Inventory_CanChangeSelected; +/* Whether the user can use the inventory at all. */ +/* NOTE: false prevents the user from deleting/picking/placing blocks. */ +extern bool Inventory_CanUse; -bool Inventory_CanChangeSelected(void); +/* Checks if the user can change their selected/held block. */ +/* NOTE: Shows a message in chat if they are unable to. */ +bool Inventory_CheckChangeSelected(void); +/* Attempts to set the currently selected index in a hotbar. */ void Inventory_SetSelectedIndex(int index); -void Inventory_SetOffset(int offset); +/* Attempts to set the currently active hotbar. */ +void Inventory_SetHotbarIndex(int index); +/* Attempts to set the block for the selected index in the current hotbar. */ +/* NOTE: If another slot is already this block, the selected index is instead changed. */ void Inventory_SetSelectedBlock(BlockID block); -void Inventory_SetDefaultMapping(void); +/* Sets all slots to contain their default associated block. */ +/* NOTE: The order of default blocks may not be in order of ID. */ +void Inventory_ApplyDefaultMapping(void); +/* Inserts the given block at its default slot in the inventory. */ +/* NOTE: Replaces (doesn't move) the block that was at that slot before. */ void Inventory_AddDefault(BlockID block); +/* Removes any slots with the given block from the inventory. */ void Inventory_Remove(BlockID block); #endif diff --git a/src/Launcher.c b/src/Launcher.c index 7cf599551..89cd2a870 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -369,10 +369,15 @@ static void Launcher_LoadTextures(Bitmap* bmp) { /* Precompute the scaled background */ Drawer2D_BmpScaled(&terrainBmp, TILESIZE, 0, TILESIZE, TILESIZE, bmp, 2 * tileSize, 0, tileSize, tileSize, - TILESIZE, TILESIZE, 128, 64); + TILESIZE, TILESIZE); Drawer2D_BmpScaled(&terrainBmp, 0, 0, TILESIZE, TILESIZE, bmp, 1 * tileSize, 0, tileSize, tileSize, - TILESIZE, TILESIZE, 96, 96); + TILESIZE, TILESIZE); + + Gradient_Tint(&terrainBmp, 128, 64, + TILESIZE, 0, TILESIZE, TILESIZE); + Gradient_Tint(&terrainBmp, 96, 96, + 0, 0, TILESIZE, TILESIZE); } static void Launcher_ProcessZipEntry(const String* path, struct Stream* data, struct ZipEntry* entry) { diff --git a/src/MapRenderer.c b/src/MapRenderer.c index 00016a113..65122f324 100644 --- a/src/MapRenderer.c +++ b/src/MapRenderer.c @@ -16,6 +16,7 @@ int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ; int MapRenderer_1DUsedCount, MapRenderer_ChunksCount; +int MapRenderer_MaxUpdates; struct ChunkPartInfo* MapRenderer_PartsNormal; struct ChunkPartInfo* MapRenderer_PartsTranslucent; @@ -517,7 +518,7 @@ static void MapRenderer_UpdateChunks(double delta) { /* Build more chunks if 30 FPS or over, otherwise slowdown */ chunksTarget += delta < CHUNK_TARGET_TIME ? 1 : -1; - Math_Clamp(chunksTarget, 4, Game_MaxChunkUpdates); + Math_Clamp(chunksTarget, 4, MapRenderer_MaxUpdates); p = &LocalPlayer_Instance; samePos = Vector3_Equals(&Camera_CurrentPos, &lastCamPos) @@ -718,14 +719,6 @@ static void MapRenderer_RecalcVisibility_(void* obj) { lastCamPos = Vector3_BigP static void MapRenderer_DeleteChunks_(void* obj) { MapRenderer_DeleteChunks(); } static void MapRenderer_Refresh_(void* obj) { MapRenderer_Refresh(); } -void MapRenderer_ApplyMeshBuilder(void) { - if (Game_SmoothLighting) { - AdvBuilder_SetActive(); - } else { - NormalBuilder_SetActive(); - } -} - static void MapRenderer_OnNewMap(void) { Game_ChunkUpdates = 0; MapRenderer_DeleteChunks(); @@ -770,7 +763,10 @@ static void MapRenderer_Init(void) { /* This = 87 fixes map being invisible when no textures */ MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */ chunkPos = Vector3I_MaxValue(); - MapRenderer_ApplyMeshBuilder(); + MapRenderer_MaxUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30); + + Builder_Init(); + Builder_ApplyActive(); } static void MapRenderer_Free(void) { diff --git a/src/MapRenderer.h b/src/MapRenderer.h index 048f79553..0c65e2535 100644 --- a/src/MapRenderer.h +++ b/src/MapRenderer.h @@ -18,6 +18,8 @@ extern int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ; extern int MapRenderer_1DUsedCount; /* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */ extern int MapRenderer_ChunksCount; +/* Maximum number of chunk updates that can be performed in a frame. */ +extern int MapRenderer_MaxUpdates; /* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) parts in the buffer, with parts for 'normal' buffer being in lower half. */ @@ -86,9 +88,8 @@ void MapRenderer_DeleteChunk(struct ChunkInfo* info); void MapRenderer_BuildChunk(struct ChunkInfo* info, int* chunkUpdates); /* Refreshes chunks on the border of the map. */ -/* NOTE: Only refreshes chunks whose y is less than 'maxHeight'. */ +/* NOTE: Only refreshes border chunks whose y is less than 'maxHeight'. */ void MapRenderer_RefreshBorders(int maxHeight); /* Deletes all chunks and resets internal state. */ void MapRenderer_Refresh(void); -void MapRenderer_ApplyMeshBuilder(void); #endif diff --git a/src/Menus.c b/src/Menus.c index 1aa5a3dc2..d461eb093 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -18,7 +18,6 @@ #include "Block.h" #include "World.h" #include "Formats.h" -#include "ErrorHandler.h" #include "BlockPhysics.h" #include "MapRenderer.h" #include "TexturePack.h" @@ -27,6 +26,7 @@ #include "Gui.h" #include "Deflate.h" #include "Stream.h" +#include "Builder.h" #define MenuBase_Layout Screen_Layout struct Widget** Widgets; int WidgetsCount; struct Menu { MenuBase_Layout }; @@ -184,7 +184,7 @@ static void Menu_Input(void* s, int i, struct MenuInputWidget* input, int width, } static void Menu_Back(void* s, int i, struct ButtonWidget* btn, const char* label, const FontDesc* font, Widget_LeftClick onClick) { - int width = Game_UseClassicOptions ? 400 : 200; + int width = Gui_ClassicMenu ? 400 : 200; String msg = String_FromReadonly(label); Menu_Button(s, i, btn, width, &msg, font, onClick, ANCHOR_CENTRE, ANCHOR_MAX, 0, 25); } @@ -614,7 +614,7 @@ static void PauseScreen_Game(void* a, void* b) { Gui_CloseActive(); } static void PauseScreen_CheckHacksAllowed(void* screen) { struct PauseScreen* s = screen; - if (Game_UseClassicOptions) return; + if (Gui_ClassicMenu) return; s->Buttons[4].Disabled = !LocalPlayer_Instance.Hacks.CanAnyHacks; /* select texture pack */ } @@ -622,7 +622,7 @@ static void PauseScreen_ContextRecreated(void* screen) { const static String quitMsg = String_FromConst("Quit game"); struct PauseScreen* s = screen; - if (Game_UseClassicOptions) { + if (Gui_ClassicMenu) { PauseScreen_MakeClassic(s, 0, -100, "Options...", Menu_SwitchClassicOptions); PauseScreen_MakeClassic(s, 1, -50, "Generate new level...", Menu_SwitchClassicGenLevel); PauseScreen_MakeClassic(s, 2, 0, "Load level...", Menu_SwitchLoadLevel); @@ -1656,7 +1656,7 @@ static int KeyBindingsScreen_MakeWidgets(struct KeyBindingsScreen* s, int y, int Menu_Label(s, i, &s->Title, &titleText, &s->TitleFont, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -180); i++; - backClick = Game_UseClassicOptions ? Menu_SwitchClassicOptions : Menu_SwitchOptions; + backClick = Gui_ClassicMenu ? Menu_SwitchClassicOptions : Menu_SwitchOptions; Menu_Back(s, i, &s->Back, "Done", &s->TitleFont, backClick); i++; if (!s->LeftPage && !s->RightPage) return i; @@ -2177,15 +2177,14 @@ struct Screen* MenuOptionsScreen_MakeInstance(struct Widget** widgets, int count enum ViewDist { VIEW_TINY, VIEW_SHORT, VIEW_NORMAL, VIEW_FAR, VIEW_COUNT }; const char* ViewDist_Names[VIEW_COUNT] = { "TINY", "SHORT", "NORMAL", "FAR" }; -static void ClassicOptionsScreen_GetMusic(String* v) { Menu_GetBool(v, Game_MusicVolume > 0); } +static void ClassicOptionsScreen_GetMusic(String* v) { Menu_GetBool(v, Audio_MusicVolume > 0); } static void ClassicOptionsScreen_SetMusic(const String* v) { - Game_MusicVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0; - Audio_SetMusic(Game_MusicVolume); - Options_SetInt(OPT_MUSIC_VOLUME, Game_MusicVolume); + Audio_SetMusic(String_CaselessEqualsConst(v, "ON") ? 100 : 0); + Options_SetInt(OPT_MUSIC_VOLUME, Audio_MusicVolume); } -static void ClassicOptionsScreen_GetInvert(String* v) { Menu_GetBool(v, Game_InvertMouse); } -static void ClassicOptionsScreen_SetInvert(const String* v) { Game_InvertMouse = Menu_SetBool(v, OPT_INVERT_MOUSE); } +static void ClassicOptionsScreen_GetInvert(String* v) { Menu_GetBool(v, Camera_Invert); } +static void ClassicOptionsScreen_SetInvert(const String* v) { Camera_Invert = Menu_SetBool(v, OPT_INVERT_MOUSE); } static void ClassicOptionsScreen_GetViewDist(String* v) { if (Game_ViewDistance >= 512) { @@ -2209,15 +2208,14 @@ static void ClassicOptionsScreen_SetPhysics(const String* v) { Physics_SetEnabled(Menu_SetBool(v, OPT_BLOCK_PHYSICS)); } -static void ClassicOptionsScreen_GetSounds(String* v) { Menu_GetBool(v, Game_SoundsVolume > 0); } +static void ClassicOptionsScreen_GetSounds(String* v) { Menu_GetBool(v, Audio_SoundsVolume > 0); } static void ClassicOptionsScreen_SetSounds(const String* v) { - Game_SoundsVolume = String_CaselessEqualsConst(v, "ON") ? 100 : 0; - Audio_SetSounds(Game_SoundsVolume); - Options_SetInt(OPT_SOUND_VOLUME, Game_SoundsVolume); + Audio_SetSounds(String_CaselessEqualsConst(v, "ON") ? 100 : 0); + Options_SetInt(OPT_SOUND_VOLUME, Audio_SoundsVolume); } -static void ClassicOptionsScreen_GetShowFPS(String* v) { Menu_GetBool(v, Game_ShowFPS); } -static void ClassicOptionsScreen_SetShowFPS(const String* v) { Game_ShowFPS = Menu_SetBool(v, OPT_SHOW_FPS); } +static void ClassicOptionsScreen_GetShowFPS(String* v) { Menu_GetBool(v, Gui_ShowFPS); } +static void ClassicOptionsScreen_SetShowFPS(const String* v) { Gui_ShowFPS = Menu_SetBool(v, OPT_SHOW_FPS); } static void ClassicOptionsScreen_GetViewBob(String* v) { Menu_GetBool(v, Game_ViewBobbing); } static void ClassicOptionsScreen_SetViewBob(const String* v) { Game_ViewBobbing = Menu_SetBool(v, OPT_VIEW_BOBBING); } @@ -2388,10 +2386,10 @@ struct Screen* EnvSettingsScreen_MakeInstance(void) { static void GraphicsOptionsScreen_GetViewDist(String* v) { String_AppendInt(v, Game_ViewDistance); } static void GraphicsOptionsScreen_SetViewDist(const String* v) { Game_UserSetViewDistance(Menu_Int(v)); } -static void GraphicsOptionsScreen_GetSmooth(String* v) { Menu_GetBool(v, Game_SmoothLighting); } +static void GraphicsOptionsScreen_GetSmooth(String* v) { Menu_GetBool(v, Builder_SmoothLighting); } static void GraphicsOptionsScreen_SetSmooth(const String* v) { - Game_SmoothLighting = Menu_SetBool(v, OPT_SMOOTH_LIGHTING); - MapRenderer_ApplyMeshBuilder(); + Builder_SmoothLighting = Menu_SetBool(v, OPT_SMOOTH_LIGHTING); + Builder_ApplyActive(); MapRenderer_Refresh(); } @@ -2490,8 +2488,8 @@ static void GuiOptionsScreen_SetShadows(const String* v) { Menu_HandleFontChange((struct Screen*)&MenuOptionsScreen_Instance); } -static void GuiOptionsScreen_GetShowFPS(String* v) { Menu_GetBool(v, Game_ShowFPS); } -static void GuiOptionsScreen_SetShowFPS(const String* v) { Game_ShowFPS = Menu_SetBool(v, OPT_SHOW_FPS); } +static void GuiOptionsScreen_GetShowFPS(String* v) { Menu_GetBool(v, Gui_ShowFPS); } +static void GuiOptionsScreen_SetShowFPS(const String* v) { Gui_ShowFPS = Menu_SetBool(v, OPT_SHOW_FPS); } static void GuiOptionsScreen_SetScale(const String* v, float* target, const char* optKey) { *target = Menu_Float(v); @@ -2505,18 +2503,18 @@ static void GuiOptionsScreen_SetHotbar(const String* v) { GuiOptionsScreen_SetSc static void GuiOptionsScreen_GetInventory(String* v) { String_AppendFloat(v, Game_RawInventoryScale, 1); } static void GuiOptionsScreen_SetInventory(const String* v) { GuiOptionsScreen_SetScale(v, &Game_RawInventoryScale, OPT_INVENTORY_SCALE); } -static void GuiOptionsScreen_GetTabAuto(String* v) { Menu_GetBool(v, Game_TabAutocomplete); } -static void GuiOptionsScreen_SetTabAuto(const String* v) { Game_TabAutocomplete = Menu_SetBool(v, OPT_TAB_AUTOCOMPLETE); } +static void GuiOptionsScreen_GetTabAuto(String* v) { Menu_GetBool(v, Gui_TabAutocomplete); } +static void GuiOptionsScreen_SetTabAuto(const String* v) { Gui_TabAutocomplete = Menu_SetBool(v, OPT_TAB_AUTOCOMPLETE); } -static void GuiOptionsScreen_GetClickable(String* v) { Menu_GetBool(v, Game_ClickableChat); } -static void GuiOptionsScreen_SetClickable(const String* v) { Game_ClickableChat = Menu_SetBool(v, OPT_CLICKABLE_CHAT); } +static void GuiOptionsScreen_GetClickable(String* v) { Menu_GetBool(v, Gui_ClickableChat); } +static void GuiOptionsScreen_SetClickable(const String* v) { Gui_ClickableChat = Menu_SetBool(v, OPT_CLICKABLE_CHAT); } static void GuiOptionsScreen_GetChatScale(String* v) { String_AppendFloat(v, Game_RawChatScale, 1); } static void GuiOptionsScreen_SetChatScale(const String* v) { GuiOptionsScreen_SetScale(v, &Game_RawChatScale, OPT_CHAT_SCALE); } -static void GuiOptionsScreen_GetChatlines(String* v) { String_AppendInt(v, Game_ChatLines); } +static void GuiOptionsScreen_GetChatlines(String* v) { String_AppendInt(v, Gui_Chatlines); } static void GuiOptionsScreen_SetChatlines(const String* v) { - Game_ChatLines = Menu_Int(v); + Gui_Chatlines = Menu_Int(v); Options_Set(OPT_CHATLINES, v); Gui_RefreshHud(); } @@ -2593,9 +2591,9 @@ static void HacksSettingsScreen_SetSpeed(const String* v) { Options_Set(OPT_SPEED_FACTOR, v); } -static void HacksSettingsScreen_GetClipping(String* v) { Menu_GetBool(v, Game_CameraClipping); } +static void HacksSettingsScreen_GetClipping(String* v) { Menu_GetBool(v, Camera_Clipping); } static void HacksSettingsScreen_SetClipping(const String* v) { - Game_CameraClipping = Menu_SetBool(v, OPT_CAMERA_CLIPPING); + Camera_Clipping = Menu_SetBool(v, OPT_CAMERA_CLIPPING); } static void HacksSettingsScreen_GetJump(String* v) { String_AppendFloat(v, LocalPlayer_JumpHeight(), 3); } @@ -2739,18 +2737,16 @@ struct Screen* HacksSettingsScreen_MakeInstance(void) { static void MiscOptionsScreen_GetReach(String* v) { String_AppendFloat(v, LocalPlayer_Instance.ReachDistance, 2); } static void MiscOptionsScreen_SetReach(const String* v) { LocalPlayer_Instance.ReachDistance = Menu_Float(v); } -static void MiscOptionsScreen_GetMusic(String* v) { String_AppendInt(v, Game_MusicVolume); } +static void MiscOptionsScreen_GetMusic(String* v) { String_AppendInt(v, Audio_MusicVolume); } static void MiscOptionsScreen_SetMusic(const String* v) { - Game_MusicVolume = Menu_Int(v); Options_Set(OPT_MUSIC_VOLUME, v); - Audio_SetMusic(Game_MusicVolume); + Audio_SetMusic(Menu_Int(v)); } -static void MiscOptionsScreen_GetSounds(String* v) { String_AppendInt(v, Game_SoundsVolume); } +static void MiscOptionsScreen_GetSounds(String* v) { String_AppendInt(v, Audio_SoundsVolume); } static void MiscOptionsScreen_SetSounds(const String* v) { - Game_SoundsVolume = Menu_Int(v); Options_Set(OPT_SOUND_VOLUME, v); - Audio_SetSounds(Game_SoundsVolume); + Audio_SetSounds(Menu_Int(v)); } static void MiscOptionsScreen_GetViewBob(String* v) { Menu_GetBool(v, Game_ViewBobbing); } @@ -2764,12 +2760,12 @@ static void MiscOptionsScreen_SetPhysics(const String* v) { static void MiscOptionsScreen_GetAutoClose(String* v) { Menu_GetBool(v, Options_GetBool(OPT_AUTO_CLOSE_LAUNCHER, false)); } static void MiscOptionsScreen_SetAutoClose(const String* v) { Menu_SetBool(v, OPT_AUTO_CLOSE_LAUNCHER); } -static void MiscOptionsScreen_GetInvert(String* v) { Menu_GetBool(v, Game_InvertMouse); } -static void MiscOptionsScreen_SetInvert(const String* v) { Game_InvertMouse = Menu_SetBool(v, OPT_INVERT_MOUSE); } +static void MiscOptionsScreen_GetInvert(String* v) { Menu_GetBool(v, Camera_Invert); } +static void MiscOptionsScreen_SetInvert(const String* v) { Camera_Invert = Menu_SetBool(v, OPT_INVERT_MOUSE); } -static void MiscOptionsScreen_GetSensitivity(String* v) { String_AppendInt(v, Game_MouseSensitivity); } +static void MiscOptionsScreen_GetSensitivity(String* v) { String_AppendInt(v, Camera_Sensitivity); } static void MiscOptionsScreen_SetSensitivity(const String* v) { - Game_MouseSensitivity = Menu_Int(v); + Camera_Sensitivity = Menu_Int(v); Options_Set(OPT_SENSITIVITY, v); } @@ -2835,14 +2831,14 @@ static void NostalgiaScreen_SetAnim(const String* v) { Options_SetBool(OPT_SIMPLE_ARMS_ANIM, Game_SimpleArmsAnim); } -static void NostalgiaScreen_GetGui(String* v) { Menu_GetBool(v, Game_UseClassicGui); } -static void NostalgiaScreen_SetGui(const String* v) { Game_UseClassicGui = Menu_SetBool(v, OPT_CLASSIC_GUI); } +static void NostalgiaScreen_GetGui(String* v) { Menu_GetBool(v, Gui_ClassicTexture); } +static void NostalgiaScreen_SetGui(const String* v) { Gui_ClassicTexture = Menu_SetBool(v, OPT_CLASSIC_GUI); } -static void NostalgiaScreen_GetList(String* v) { Menu_GetBool(v, Game_UseClassicTabList); } -static void NostalgiaScreen_SetList(const String* v) { Game_UseClassicTabList = Menu_SetBool(v, OPT_CLASSIC_TABLIST); } +static void NostalgiaScreen_GetList(String* v) { Menu_GetBool(v, Gui_ClassicTabList); } +static void NostalgiaScreen_SetList(const String* v) { Gui_ClassicTabList = Menu_SetBool(v, OPT_CLASSIC_TABLIST); } -static void NostalgiaScreen_GetOpts(String* v) { Menu_GetBool(v, Game_UseClassicOptions); } -static void NostalgiaScreen_SetOpts(const String* v) { Game_UseClassicOptions = Menu_SetBool(v, OPT_CLASSIC_OPTIONS); } +static void NostalgiaScreen_GetOpts(String* v) { Menu_GetBool(v, Gui_ClassicMenu); } +static void NostalgiaScreen_SetOpts(const String* v) { Gui_ClassicMenu = Menu_SetBool(v, OPT_CLASSIC_OPTIONS); } static void NostalgiaScreen_GetCustom(String* v) { Menu_GetBool(v, Game_AllowCustomBlocks); } static void NostalgiaScreen_SetCustom(const String* v) { Game_AllowCustomBlocks = Menu_SetBool(v, OPT_CUSTOM_BLOCKS); } @@ -2854,7 +2850,7 @@ static void NostalgiaScreen_GetTexs(String* v) { Menu_GetBool(v, Game_AllowServe static void NostalgiaScreen_SetTexs(const String* v) { Game_AllowServerTextures = Menu_SetBool(v, OPT_SERVER_TEXTURES); } static void NostalgiaScreen_SwitchBack(void* a, void* b) { - if (Game_UseClassicOptions) { Menu_SwitchPause(a, b); } else { Menu_SwitchOptions(a, b); } + if (Gui_ClassicMenu) { Menu_SwitchPause(a, b); } else { Menu_SwitchOptions(a, b); } } static void NostalgiaScreen_ContextRecreated(void* screen) { @@ -3112,7 +3108,7 @@ static void UrlWarningOverlay_OpenUrl(void* screen, void* b) { static void UrlWarningOverlay_AppendUrl(void* screen, void* b) { struct UrlWarningOverlay* s = screen; Gui_FreeOverlay(s); - if (Game_ClickableChat) { HUDScreen_AppendInput(Gui_HUD, &s->Url); } + if (Gui_ClickableChat) { HUDScreen_AppendInput(Gui_HUD, &s->Url); } } static void UrlWarningOverlay_ContextRecreated(void* screen) { diff --git a/src/Model.h b/src/Model.h index efc32a9b9..832bbe3b2 100644 --- a/src/Model.h +++ b/src/Model.h @@ -107,15 +107,15 @@ extern VertexP3fT2fC4b Model_Vertices[MODEL_MAX_VERTICES]; extern struct Model* Human_ModelPtr; /* Returns pointer to model whose name caselessly matches given name. */ -CC_EXPORT struct Model* Model_Get(const String* name); +CC_API struct Model* Model_Get(const String* name); /* Returns index of cached texture whose name caselessly matches given name. */ -CC_EXPORT struct ModelTex* Model_GetTexture(const String* name); +CC_API struct ModelTex* Model_GetTexture(const String* name); /* Adds a model to the list of models. (e.g. "skeleton") */ /* Models can be applied to entities to change their appearance. Use Entity_SetModel for that. */ -CC_EXPORT void Model_Register(struct Model* model); +CC_API void Model_Register(struct Model* model); /* Adds a texture to the list of model textures. (e.g. "skeleton.png") */ /* Model textures are automatically loaded from texture packs. Used as a 'default skin' for models. */ -CC_EXPORT void Model_RegisterTexture(struct ModelTex* tex); +CC_API void Model_RegisterTexture(struct ModelTex* tex); /* Describes data for a box being built. */ struct BoxDesc { diff --git a/src/Options.h b/src/Options.h index c8d3f392c..a798b603a 100644 --- a/src/Options.h +++ b/src/Options.h @@ -80,27 +80,27 @@ void Options_Free(void); /* Returns whether the option was actually found. */ STRING_REF bool Options_UNSAFE_Get(const char* keyRaw, String* value); /* Returns value of given option, or defalt value if not found. */ -CC_EXPORT void Options_Get(const char* key, String* value, const char* defValue); +CC_API void Options_Get(const char* key, String* value, const char* defValue); /* Returns value of given option as an integer, or defalt value if could not be converted. */ -CC_EXPORT int Options_GetInt(const char* key, int min, int max, int defValue); +CC_API int Options_GetInt(const char* key, int min, int max, int defValue); /* Returns value of given option as a bool, or defalt value if could not be converted. */ -CC_EXPORT bool Options_GetBool(const char* key, bool defValue); +CC_API bool Options_GetBool(const char* key, bool defValue); /* Returns value of given option as a float, or defalt value if could not be converted. */ -CC_EXPORT float Options_GetFloat(const char* key, float min, float max, float defValue); +CC_API float Options_GetFloat(const char* key, float min, float max, float defValue); /* Returns value of given option as an integer, or defalt value if could not be converted. */ /* NOTE: Conversion is done by going through all elements of names, returning index of a match. */ -CC_EXPORT int Options_GetEnum(const char* key, int defValue, const char** names, int namesCount); +CC_API int Options_GetEnum(const char* key, int defValue, const char** names, int namesCount); /* Sets value of given option to either "true" or "false". */ -CC_EXPORT void Options_SetBool(const char* keyRaw, bool value); +CC_API void Options_SetBool(const char* keyRaw, bool value); /* Sets value of given option to given integer converted to a string. */ -CC_EXPORT void Options_SetInt(const char* keyRaw, int value); +CC_API void Options_SetInt(const char* keyRaw, int value); /* Sets value of given option to given string. */ -CC_EXPORT void Options_Set(const char* keyRaw, const String* value); +CC_API void Options_Set(const char* keyRaw, const String* value); /* Sets value of given option to given string. */ -CC_EXPORT void Options_SetString(const String* key, const String* value); +CC_API void Options_SetString(const String* key, const String* value); /* Loads options from disc. Leaves options changed in this session alone. */ -CC_EXPORT void Options_Load(void); +CC_API void Options_Load(void); /* Saves all options to disc. */ -CC_EXPORT void Options_Save(void); +CC_API void Options_Save(void); #endif diff --git a/src/PacketHandlers.c b/src/PacketHandlers.c index c780c8fe4..744255605 100644 --- a/src/PacketHandlers.c +++ b/src/PacketHandlers.c @@ -964,10 +964,10 @@ static void CPE_HoldThis(uint8_t* data) { Handlers_ReadBlock(data, block); canChange = *data == 0; - Inventory_CanChangeHeldBlock = true; + Inventory_CanChangeSelected = true; Inventory_SetSelectedBlock(block); - Inventory_CanChangeHeldBlock = canChange; - Inventory_CanPick = block != BLOCK_AIR; + Inventory_CanChangeSelected = canChange; + Inventory_CanUse = block != BLOCK_AIR; } static void CPE_SetTextHotkey(uint8_t* data) { diff --git a/src/Picking.c b/src/Picking.c index 8e898736b..d47e21e53 100644 --- a/src/Picking.c +++ b/src/Picking.c @@ -7,6 +7,7 @@ #include "Funcs.h" #include "Block.h" #include "ErrorHandler.h" +#include "Camera.h" static float pickedPos_dist; static void PickedPos_TestAxis(struct PickedPos* pos, float dAxis, Face fAxis) { @@ -240,7 +241,7 @@ void Picking_CalculatePickedBlock(Vector3 origin, Vector3 dir, float reach, stru } void Picking_ClipCameraPos(Vector3 origin, Vector3 dir, float reach, struct PickedPos* pos) { - bool noClip = !Game_CameraClipping || LocalPlayer_Instance.Hacks.Noclip; + bool noClip = !Camera_Clipping || LocalPlayer_Instance.Hacks.Noclip; if (noClip || !Picking_RayTrace(origin, dir, reach, pos, Picking_ClipCamera)) { PickedPos_SetAsInvalid(pos); Vector3_Mul1(&pos->Intersect, &dir, reach); /* intersect = dir * reach */ diff --git a/src/Platform.h b/src/Platform.h index 963efd4c4..5758be1dc 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -52,7 +52,7 @@ void GraphicsMode_MakeDefault(struct GraphicsMode* m); /* Encodes a string in platform specific format. (e.g. unicode on windows, UTF8 on linux) */ /* NOTE: Only useful for platform specific function calls - do NOT try to interpret the data. Returns the number of bytes written, excluding trailing NULL terminator. */ -CC_EXPORT int Platform_ConvertString(void* data, const String* src); +CC_API int Platform_ConvertString(void* data, const String* src); /* Initalises the platform specific state. */ void Platform_Init(void); /* Frees the platform specific state. */ @@ -65,24 +65,24 @@ void Platform_Exit(ReturnCode code); int Platform_GetCommandLineArgs(int argc, STRING_REF const char** argv, String* args); /* Starts the given program with the given arguments. */ -CC_EXPORT ReturnCode Platform_StartProcess(const String* path, const String* args); +CC_API ReturnCode Platform_StartProcess(const String* path, const String* args); /* Starts the platform-specific program to open the given url or filename. */ /* For example, provide a http:// url to open a website in the user's web browser. */ -CC_EXPORT ReturnCode Platform_StartOpen(const String* args); +CC_API ReturnCode Platform_StartOpen(const String* args); /* Attempts to load the native dynamic library from the given path. */ -CC_EXPORT ReturnCode Platform_LoadLibrary(const String* path, void** lib); +CC_API ReturnCode Platform_LoadLibrary(const String* path, void** lib); /* Attempts to get the address of the symbol in the given dynamic library. */ /* NOTE: Do NOT use this to load OpenGL functions, use GLContext_GetAddress. */ -CC_EXPORT ReturnCode Platform_GetSymbol(void* lib, const char* name, void** symbol); +CC_API ReturnCode Platform_GetSymbol(void* lib, const char* name, void** symbol); /* Allocates a block of memory, with undetermined contents. Exits process on allocation failure. */ -CC_EXPORT void* Mem_Alloc(uint32_t numElems, uint32_t elemsSize, const char* place); +CC_API void* Mem_Alloc(uint32_t numElems, uint32_t elemsSize, const char* place); /* Allocates a block of memory, with contents of all 0. Exits process on allocation failure. */ -CC_EXPORT void* Mem_AllocCleared(uint32_t numElems, uint32_t elemsSize, const char* place); +CC_API void* Mem_AllocCleared(uint32_t numElems, uint32_t elemsSize, const char* place); /* Reallocates a block of memory, with undetermined contents. Exits process on reallocation failure. */ -CC_EXPORT void* Mem_Realloc(void* mem, uint32_t numElems, uint32_t elemsSize, const char* place); +CC_API void* Mem_Realloc(void* mem, uint32_t numElems, uint32_t elemsSize, const char* place); /* Frees an allocated a block of memory. Does nothing when passed NULL. */ -CC_EXPORT void Mem_Free(void* mem); +CC_API void Mem_Free(void* mem); /* Sets the contents of a block of memory to the given value. */ void Mem_Set(void* dst, uint8_t value, uint32_t numBytes); /* Copies a block of memory to another block. NOTE: These blocks MUST NOT overlap. */ @@ -144,43 +144,43 @@ ReturnCode File_Position(FileHandle file, uint32_t* pos); ReturnCode File_Length(FileHandle file, uint32_t* len); /* Blocks the current thread for the given number of milliseconds. */ -CC_EXPORT void Thread_Sleep(uint32_t milliseconds); +CC_API void Thread_Sleep(uint32_t milliseconds); typedef void Thread_StartFunc(void); /* Starts a new thread, optionally immediately detaching it. (See Thread_Detach) */ -CC_EXPORT void* Thread_Start(Thread_StartFunc* func, bool detach); +CC_API void* Thread_Start(Thread_StartFunc* func, bool detach); /* Frees the platform specific persistent data associated with the thread. */ /* NOTE: You must either detach or join threads, as this data otherwise leaks. */ -CC_EXPORT void Thread_Detach(void* handle); +CC_API void Thread_Detach(void* handle); /* Blocks the current thread, until the given thread has finished. */ /* NOTE: Once a thread has been detached, you can no longer use this method. */ -CC_EXPORT void Thread_Join(void* handle); +CC_API void Thread_Join(void* handle); /* Allocates a new mutex. (used to synchronise access to a shared resource) */ -CC_EXPORT void* Mutex_Create(void); +CC_API void* Mutex_Create(void); /* Frees an allocated mutex. */ -CC_EXPORT void Mutex_Free(void* handle); +CC_API void Mutex_Free(void* handle); /* Locks the given mutex, blocking other threads from entering. */ -CC_EXPORT void Mutex_Lock(void* handle); +CC_API void Mutex_Lock(void* handle); /* Unlocks the given mutex, allowing other threads to enter. */ -CC_EXPORT void Mutex_Unlock(void* handle); +CC_API void Mutex_Unlock(void* handle); /* Allocates a new waitable. (used to conditionally wake-up a blocked thread) */ -CC_EXPORT void* Waitable_Create(void); +CC_API void* Waitable_Create(void); /* Frees an allocated waitable. */ -CC_EXPORT void Waitable_Free(void* handle); +CC_API void Waitable_Free(void* handle); /* Signals a waitable, waking up blocked threads. */ -CC_EXPORT void Waitable_Signal(void* handle); +CC_API void Waitable_Signal(void* handle); /* Blocks the calling thread until the waitable gets signalled. */ -CC_EXPORT void Waitable_Wait(void* handle); +CC_API void Waitable_Wait(void* handle); /* Blocks the calling thread until the waitable gets signalled, or milliseconds delay passes. */ -CC_EXPORT void Waitable_WaitFor(void* handle, uint32_t milliseconds); +CC_API void Waitable_WaitFor(void* handle, uint32_t milliseconds); /* Gets the list of all supported font names on this platform. */ -CC_EXPORT void Font_GetNames(StringsBuffer* buffer); +CC_API void Font_GetNames(StringsBuffer* buffer); /* Allocates a new font from the given arguments. */ -CC_EXPORT void Font_Make(FontDesc* desc, const String* fontName, int size, int style); +CC_API void Font_Make(FontDesc* desc, const String* fontName, int size, int style); /* Frees an allocated font. */ -CC_EXPORT void Font_Free(FontDesc* desc); +CC_API void Font_Free(FontDesc* desc); /* Measures width of the given text when drawn with the given font. */ int Platform_TextWidth(struct DrawTextArgs* args); /* Measures height of any text when drawn with the given font. */ diff --git a/src/Screens.c b/src/Screens.c index 1eae67d37..7c665a487 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -424,11 +424,11 @@ static void StatusScreen_Render(void* screen, double delta) { /* TODO: If Game_ShowFps is off and not classic mode, we should just return here */ Gfx_SetTexturing(true); - if (Game_ShowFPS) Elem_Render(&s->Line1, delta); + if (Gui_ShowFPS) Elem_Render(&s->Line1, delta); if (Game_ClassicMode) { Elem_Render(&s->Line2, delta); - } else if (!Gui_Active && Game_ShowFPS) { + } else if (!Gui_Active && Gui_ShowFPS) { if (StatusScreen_HacksChanged(s)) { StatusScreen_UpdateHackState(s); } StatusScreen_DrawPosition(s); Elem_Render(&s->Line2, delta); @@ -747,7 +747,7 @@ static void ChatScreen_ResetChat(struct ChatScreen* s) { int i; Elem_TryFree(&s->Chat); - for (i = s->ChatIndex; i < s->ChatIndex + Game_ChatLines; i++) { + for (i = s->ChatIndex; i < s->ChatIndex + Gui_Chatlines; i++) { if (i >= 0 && i < Chat_Log.Count) { msg = StringsBuffer_UNSAFE_Get(&Chat_Log, i); TextGroupWidget_PushUpAndReplaceLast(&s->Chat, &msg); @@ -776,7 +776,7 @@ static void ChatScreen_ConstructWidgets(struct ChatScreen* s) { Widget_SetLocation(&s->BottomRight, ANCHOR_MAX, ANCHOR_MAX, 0, yOffset); Elem_Init(&s->BottomRight); - ChatScreen_MakeGroup(&s->Chat, Game_ChatLines, s->Chat_Textures, s->Chat_Buffer); + ChatScreen_MakeGroup(&s->Chat, Gui_Chatlines, s->Chat_Textures, s->Chat_Buffer); Widget_SetLocation(&s->Chat, ANCHOR_MIN, ANCHOR_MAX, 10, yOffset); Elem_Init(&s->Chat); @@ -791,7 +791,7 @@ static void ChatScreen_ConstructWidgets(struct ChatScreen* s) { static void ChatScreen_SetInitialMessages(struct ChatScreen* s) { int i; - s->ChatIndex = Chat_Log.Count - Game_ChatLines; + s->ChatIndex = Chat_Log.Count - Gui_Chatlines; ChatScreen_ResetChat(s); TextGroupWidget_SetText(&s->Status, 2, &Chat_Status[0]); @@ -895,7 +895,7 @@ static void ChatElem_Recreate(struct TextGroupWidget* group, char code) { } static int ChatScreen_ClampIndex(int index) { - int maxIndex = Chat_Log.Count - Game_ChatLines; + int maxIndex = Chat_Log.Count - Gui_Chatlines; int minIndex = min(0, maxIndex); Math_Clamp(index, minIndex, maxIndex); return index; @@ -932,15 +932,15 @@ static bool ChatScreen_KeyDown(void* screen, Key key) { SpecialInputWidget_SetActive(&s->AltText, false); /* Reset chat when user has scrolled up in chat history */ - defaultIndex = Chat_Log.Count - Game_ChatLines; + defaultIndex = Chat_Log.Count - Gui_Chatlines; if (s->ChatIndex != defaultIndex) { s->ChatIndex = ChatScreen_ClampIndex(defaultIndex); ChatScreen_ResetChat(s); } } else if (key == KEY_PAGEUP) { - ChatScreen_ScrollHistoryBy(s, -Game_ChatLines); + ChatScreen_ScrollHistoryBy(s, -Gui_Chatlines); } else if (key == KEY_PAGEDOWN) { - ChatScreen_ScrollHistoryBy(s, +Game_ChatLines); + ChatScreen_ScrollHistoryBy(s, +Gui_Chatlines); } else { Elem_HandlesKeyDown(&s->Input.Base, key); ChatScreen_UpdateAltTextY(s); @@ -1022,7 +1022,7 @@ static bool ChatScreen_MouseDown(void* screen, int x, int y, MouseButton btn) { if (Utils_IsUrlPrefix(&text, 0)) { overlay = UrlWarningOverlay_MakeInstance(&text); Gui_ShowOverlay(overlay, false); - } else if (Game_ClickableChat) { + } else if (Gui_ClickableChat) { InputWidget_AppendString(&s->Input.Base, &text); } return true; @@ -1054,10 +1054,10 @@ static void ChatScreen_ChatReceived(void* screen, const String* msg, int type) { if (type == MSG_TYPE_NORMAL) { s->ChatIndex++; - if (!Game_ChatLines) return; + if (!Gui_Chatlines) return; chatMsg = *msg; - i = s->ChatIndex + (Game_ChatLines - 1); + i = s->ChatIndex + (Gui_Chatlines - 1); if (i < Chat_Log.Count) { chatMsg = StringsBuffer_UNSAFE_Get(&Chat_Log, i); } TextGroupWidget_PushUpAndReplaceLast(&s->Chat, &chatMsg); @@ -1234,7 +1234,7 @@ static void HUDScreen_ContextRecreated(void* screen) { Elem_Init(&s->Hotbar); if (!s->WasShowingList) return; - extended = ServerConnection_SupportsExtPlayerList && !Game_UseClassicTabList; + extended = ServerConnection_SupportsExtPlayerList && !Gui_ClassicTabList; PlayerListWidget_Create(&s->PlayerList, &s->PlayerFont, !extended); s->ShowingList = true; @@ -1258,7 +1258,7 @@ static bool HUDScreen_KeyPress(void* screen, char keyChar) { static bool HUDScreen_KeyDown(void* screen, Key key) { struct HUDScreen* s = screen; Key playerListKey = KeyBind_Get(KEYBIND_PLAYER_LIST); - bool handles = playerListKey != KEY_TAB || !Game_TabAutocomplete || !s->Chat->HandlesAllInput; + bool handles = playerListKey != KEY_TAB || !Gui_TabAutocomplete || !s->Chat->HandlesAllInput; if (key == playerListKey && handles) { if (!s->ShowingList && !ServerConnection_IsSinglePlayer) { diff --git a/src/Stream.h b/src/Stream.h index 03d2dd158..f114dc566 100644 --- a/src/Stream.h +++ b/src/Stream.h @@ -50,20 +50,20 @@ void Stream_Init(struct Stream* s); ReturnCode Stream_DefaultReadU8(struct Stream* s, uint8_t* data); /* Wrapper for File_Open() then Stream_FromFile() */ -CC_EXPORT ReturnCode Stream_OpenFile(struct Stream* s, const String* path); +CC_API ReturnCode Stream_OpenFile(struct Stream* s, const String* path); /* Wrapper for File_Create() then Stream_FromFile() */ -CC_EXPORT ReturnCode Stream_CreateFile(struct Stream* s, const String* path); +CC_API ReturnCode Stream_CreateFile(struct Stream* s, const String* path); /* Wraps a file, allowing reading from/writing to/seeking in the file. */ -CC_EXPORT void Stream_FromFile(struct Stream* s, FileHandle file); +CC_API void Stream_FromFile(struct Stream* s, FileHandle file); /* Wraps another Stream, only allows reading up to 'len' bytes from the wrapped stream. */ -CC_EXPORT void Stream_ReadonlyPortion(struct Stream* s, struct Stream* source, uint32_t len); +CC_API void Stream_ReadonlyPortion(struct Stream* s, struct Stream* source, uint32_t len); /* Wraps a block of memory, allowing reading from and seeking in the block. */ -CC_EXPORT void Stream_ReadonlyMemory(struct Stream* s, void* data, uint32_t len); +CC_API void Stream_ReadonlyMemory(struct Stream* s, void* data, uint32_t len); /* Wraps a block of memory, allowing writing to and seeking in the block. */ -CC_EXPORT void Stream_WriteonlyMemory(struct Stream* s, void* data, uint32_t len); +CC_API void Stream_WriteonlyMemory(struct Stream* s, void* data, uint32_t len); /* Wraps another Stream, reading through an intermediary buffer. (Useful for files, since each read call is expensive) */ -CC_EXPORT void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, void* data, uint32_t size); +CC_API void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, void* data, uint32_t size); /* Reads a little-endian 16 bit unsigned integer from memory. */ uint16_t Stream_GetU16_LE(const uint8_t* data); @@ -87,7 +87,7 @@ ReturnCode Stream_ReadU32_BE(struct Stream* s, uint32_t* value); /* Reads a line of UTF8 encoded character from the stream. */ /* NOTE: Reads one byte at a time. May want to use Stream_ReadonlyBuffered. */ -CC_EXPORT ReturnCode Stream_ReadLine(struct Stream* s, String* text); +CC_API ReturnCode Stream_ReadLine(struct Stream* s, String* text); /* Writes a line of UTF8 encoded text to the stream. */ -CC_EXPORT ReturnCode Stream_WriteLine(struct Stream* s, String* text); +CC_API ReturnCode Stream_WriteLine(struct Stream* s, String* text); #endif diff --git a/src/Widgets.c b/src/Widgets.c index 7dca63933..8445ed3ac 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -126,7 +126,7 @@ static void ButtonWidget_Render(void* widget, double delta) { back = w->Active ? Button_SelectedTex : Button_ShadowTex; if (w->Disabled) back = Button_DisabledTex; - back.ID = Game_UseClassicGui ? Gui_GuiClassicTex : Gui_GuiTex; + back.ID = Gui_ClassicTexture ? Gui_GuiClassicTex : Gui_GuiTex; back.X = w->X; back.Width = w->Width; back.Y = w->Y; back.Height = w->Height; @@ -323,7 +323,7 @@ static void HotbarWidget_RenderHotbarOutline(struct HotbarWidget* w) { float width; int i, x; - tex = Game_UseClassicGui ? Gui_GuiClassicTex : Gui_GuiTex; + tex = Gui_ClassicTexture ? Gui_GuiClassicTex : Gui_GuiTex; w->BackTex.ID = tex; Texture_Render(&w->BackTex); @@ -419,7 +419,7 @@ static bool HotbarWidget_KeyDown(void* widget, Key key) { index = key - KEY_1; if (KeyBind_IsPressed(KEYBIND_HOTBAR_SWITCH)) { /* Pick from first to ninth row */ - Inventory_SetOffset(index * INVENTORY_BLOCKS_PER_HOTBAR); + Inventory_SetHotbarIndex(index); w->AltHandled = true; } else { Inventory_SetSelectedIndex(index); @@ -443,7 +443,7 @@ static bool HotbarWidget_KeyUp(void* widget, Key key) { /* Alternate between first and second row */ index = Inventory_Offset == 0 ? 1 : 0; - Inventory_SetOffset(index * INVENTORY_BLOCKS_PER_HOTBAR); + Inventory_SetHotbarIndex(index); return true; } @@ -479,7 +479,7 @@ static bool HotbarWidget_MouseScroll(void* widget, float delta) { if (KeyBind_IsPressed(KEYBIND_HOTBAR_SWITCH)) { index = Inventory_Offset / INVENTORY_BLOCKS_PER_HOTBAR; index = HotbarWidget_ScrolledIndex(w, delta, index, 1); - Inventory_SetOffset(index * INVENTORY_BLOCKS_PER_HOTBAR); + Inventory_SetHotbarIndex(index); w->AltHandled = true; } else { index = HotbarWidget_ScrolledIndex(w, delta, Inventory_SelectedIndex, -1); diff --git a/src/Window.h b/src/Window.h index f13f0f3f3..b8881d26f 100644 --- a/src/Window.h +++ b/src/Window.h @@ -105,7 +105,7 @@ so setting invisible multiple times means you must then set visible multiple tim void Window_SetCursorVisible(bool visible); /* Shows a dialog box window. */ -CC_EXPORT void Window_ShowDialog(const char* title, const char* msg); +CC_API void Window_ShowDialog(const char* title, const char* msg); /* Initialises the internal state for being able to set window's pixels. */ /* NOTE: Do not manually free bmp->Scan0 - it may be allocated by system. */ /* NOTE: This function must also be called whenever the window is resized. */ diff --git a/src/World.h b/src/World.h index fd20b436d..b0f6c0a0a 100644 --- a/src/World.h +++ b/src/World.h @@ -24,11 +24,11 @@ extern uint8_t World_Uuid[16]; extern String World_TextureUrl; /* Frees the blocks array, sets dimensions to 0, resets environment to default. */ -CC_EXPORT void World_Reset(void); +CC_API void World_Reset(void); /* Sets the blocks array and dimensions of the map. */ /* May also sets some environment settings like border/clouds height, if they are -1 */ /* NOTE: Exits the game if size vs dimensions are inconsistent. */ -CC_EXPORT void World_SetNewMap(BlockRaw* blocks, int blocksSize, int width, int height, int length); +CC_API void World_SetNewMap(BlockRaw* blocks, int blocksSize, int width, int height, int length); #ifdef EXTENDED_BLOCKS extern int Block_IDMask; @@ -82,51 +82,51 @@ extern PackedCol Env_DefaultSunCol, Env_DefaultShadowCol; /* Resets all environment settings to default. */ /* NOTE: Unlike Env_Set functions, DOES NOT raise EnvVarChanged event. */ -CC_EXPORT void Env_Reset(void); +CC_API void Env_Reset(void); /* Sets the edge/horizon block. (default water) */ -CC_EXPORT void Env_SetEdgeBlock(BlockID block); +CC_API void Env_SetEdgeBlock(BlockID block); /* Sets the sides/border block. (default bedrock) */ -CC_EXPORT void Env_SetSidesBlock(BlockID block); +CC_API void Env_SetSidesBlock(BlockID block); /* Sets the edge/horizon height. (default height/2) */ -CC_EXPORT void Env_SetEdgeHeight(int height); +CC_API void Env_SetEdgeHeight(int height); /* Sets offset of sides/border from horizon. (default -2) */ -CC_EXPORT void Env_SetSidesOffset(int offset); +CC_API void Env_SetSidesOffset(int offset); /* Sets clouds height. (default height+2)*/ -CC_EXPORT void Env_SetCloudsHeight(int height); +CC_API void Env_SetCloudsHeight(int height); /* Sets how fast clouds move. (default 1) */ /* Negative speeds move in opposite direction. */ -CC_EXPORT void Env_SetCloudsSpeed(float speed); +CC_API void Env_SetCloudsSpeed(float speed); /* Sets how fast rain/snow falls. (default 1) */ /* Negative speeds makes rain/snow fall upwards. */ -CC_EXPORT void Env_SetWeatherSpeed(float speed); +CC_API void Env_SetWeatherSpeed(float speed); /* Sets how quickly rain/snow fades over distance. (default 1) */ -CC_EXPORT void Env_SetWeatherFade(float rate); +CC_API void Env_SetWeatherFade(float rate); /* Sets the weather of the map. (default sun) */ /* Can be sun/rain/snow, see WEATHER_ enum. */ -CC_EXPORT void Env_SetWeather(int weather); +CC_API void Env_SetWeather(int weather); /* Sets whether exponential/smooth fog is used. (default false) */ -CC_EXPORT void Env_SetExpFog(bool expFog); +CC_API void Env_SetExpFog(bool expFog); /* Sets how quickly skybox rotates/spins horizontally. (default 0) */ /* speed is in rotations/second, so '2' completes two full spins per second. */ -CC_EXPORT void Env_SetSkyboxHorSpeed(float speed); +CC_API void Env_SetSkyboxHorSpeed(float speed); /* Sets how quickly skybox rotates/spins vertically. (default 0) */ /* speed is in rotations/second, so '2' completes two full spins per second. */ -CC_EXPORT void Env_SetSkyboxVerSpeed(float speed); +CC_API void Env_SetSkyboxVerSpeed(float speed); /* Sets colour of the sky above clouds. (default #99CCFF) */ -CC_EXPORT void Env_SetSkyCol(PackedCol col); +CC_API void Env_SetSkyCol(PackedCol col); /* Sets base colour of the horizon fog. (default #FFFFFF) */ /* Actual fog colour is blended between sky and fog colours, based on view distance. */ -CC_EXPORT void Env_SetFogCol(PackedCol col); +CC_API void Env_SetFogCol(PackedCol col); /* Sets colour of the clouds and skybox. (default #FFFFFF) */ -CC_EXPORT void Env_SetCloudsCol(PackedCol col); +CC_API void Env_SetCloudsCol(PackedCol col); /* Sets colour of sunlight. (default #FFFFFF) */ /* This is the colour used for lighting when not underground. */ -CC_EXPORT void Env_SetSunCol(PackedCol col); +CC_API void Env_SetSunCol(PackedCol col); /* Sets colour of shadow. (default #9B9B9B) */ /* This is the colour used for lighting when underground. */ -CC_EXPORT void Env_SetShadowCol(PackedCol col); +CC_API void Env_SetShadowCol(PackedCol col); #define RESPAWN_NOT_FOUND -100000.0f /* Finds the highest Y coordinate of any solid block that intersects the given bounding box */