From 2d53ead74e51578d176ad03142fefcfc0eb8409d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 19 Feb 2019 22:58:03 +1100 Subject: [PATCH] minor code cleanup --- src/BlockPhysics.c | 2 +- src/ClassiCube.vcxproj | 4 +- src/ClassiCube.vcxproj.filters | 12 ++-- src/Formats.c | 98 +++++++++++++++++++++++++---- src/{MapGenerator.c => Generator.c} | 9 +-- src/{MapGenerator.h => Generator.h} | 0 src/Menus.c | 2 +- src/Screens.c | 2 +- src/Server.c | 2 +- src/Window.c | 2 - 10 files changed, 100 insertions(+), 33 deletions(-) rename src/{MapGenerator.c => Generator.c} (96%) rename src/{MapGenerator.h => Generator.h} (100%) diff --git a/src/BlockPhysics.c b/src/BlockPhysics.c index 63b7ba621..6d7c1e8ca 100644 --- a/src/BlockPhysics.c +++ b/src/BlockPhysics.c @@ -7,7 +7,7 @@ #include "Block.h" #include "Lighting.h" #include "Options.h" -#include "MapGenerator.h" +#include "Generator.h" #include "Platform.h" #include "Game.h" #include "Logger.h" diff --git a/src/ClassiCube.vcxproj b/src/ClassiCube.vcxproj index 75af24079..3079b7669 100644 --- a/src/ClassiCube.vcxproj +++ b/src/ClassiCube.vcxproj @@ -222,7 +222,7 @@ - + @@ -278,7 +278,7 @@ - + diff --git a/src/ClassiCube.vcxproj.filters b/src/ClassiCube.vcxproj.filters index 7d5042421..e19df5680 100644 --- a/src/ClassiCube.vcxproj.filters +++ b/src/ClassiCube.vcxproj.filters @@ -276,9 +276,6 @@ Header Files - - Header Files\Map - Header Files\Entities @@ -318,6 +315,9 @@ Header Files\Network + + Header Files\Map + @@ -449,9 +449,6 @@ Source Files\Platform - - Source Files\Map - Source Files\Entities @@ -554,5 +551,8 @@ Source Files\Network + + Source Files\Map + \ No newline at end of file diff --git a/src/Formats.c b/src/Formats.c index f1ccd849c..6dee928b1 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -22,10 +22,7 @@ *#########################################################################################################################*/ static ReturnCode Map_ReadBlocks(struct Stream* stream) { World.Volume = World.Width * World.Length * World.Height; - World.Blocks = Mem_Alloc(World.Volume, 1, "map blocks"); -#ifdef EXTENDED_BLOCKS - World.Blocks2 = World.Blocks; -#endif + World.Blocks = Mem_Alloc(World.Volume, 1, "map blocks"); return Stream_Read(stream, World.Blocks, World.Volume); } @@ -88,6 +85,19 @@ void Map_LoadFrom(const String* path) { *#########################################################################################################################*/ #define LVL_CUSTOMTILE 163 #define LVL_CHUNKSIZE 16 +/* MCSharp* format is a GZIP compressed binary map format. All metadata is discarded. + U16 "Identifier" (must be 1874) + U16 "Width", "Length", "Height" + U16 "SpawnX", "SpawnZ", "SpawnY" + U8 "Yaw", "Pitch" + U16 "Build permissions" (ignored) + U8* "Blocks" + + -- this data is only in MCGalaxy maps + U8 "Identifier" (0xBD for 'block definitions', i.e. custom blocks) + U8* "Data" (16x16x16 sparsely allocated chunks) +}*/ + const static uint8_t Lvl_table[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, @@ -202,6 +212,20 @@ ReturnCode Lvl_Load(struct Stream* stream) { /*########################################################################################################################* *----------------------------------------------------fCraft map format----------------------------------------------------* *#########################################################################################################################*/ +/* fCraft* format is a binary map format. All metadata is discarded. + U32 "Identifier" (must be FC2AF40) + U8 "Revision" (only '13' supported) + U16 "Width", "Height", "Length" + U32 "SpawnX", "SpawnY", "SpawnZ" + U8 "Yaw", "Pitch" + U32 "DateModified", "DateCreated" (ignored) + U8* "UUID" + U8 "Layers" (only maps with 1 layer supported) + U8* "LayersInfo" (ignored, assumes only layer is map blocks) + U32 "MetaCount" + METADATA { STR "Group", "Key", "Value" } + U8* "Blocks" +}*/ static ReturnCode Fcm_ReadString(struct Stream* stream) { uint8_t data[2]; int len; @@ -421,6 +445,46 @@ static ReturnCode Nbt_ReadTag(uint8_t typeId, bool readTagName, struct Stream* s /*########################################################################################################################* *--------------------------------------------------ClassicWorld format----------------------------------------------------* *#########################################################################################################################*/ +/* ClassicWorld is a NBT tag based map format. Tags not listed below are discarded. +COMPOUND "ClassicWorld" { + U8* "UUID" + U16 "X", "Y", "Z" + COMPOUND "Spawn" { + I16 "X", "Y", "Z" + U8 "H", "P" + } + U8* "BlockArray" (lower 8 bits, required) + U8* "BlockArray2" (upper 8 bits, optional) + COMPOUND "Metadata" { + COMPOUND "CPE" { + COMPOUND "ClickDistance" { U16 "Reach" } + COMPOUND "EnvWeatherType" { U8 "WeatherType" } + COMPOUND "EnvMapAppearance" { + U8 "SideBlock", "EdgeBlock" + I16 "SidesLevel" + STR "TextureURL" + } + COMPOUND "EnvColors" { + COMPOUND "Sky" { U16 "R", "G", "B" } + COMPOUND "Cloud" { U16 "R", "G", "B" } + COMPOUND "Fog" { U16 "R", "G", "B" } + COMPOUND "Sunlight" { U16 "R", "G", "B" } + COMPOUND "Ambient" { U16 "R", "G", "B" } + } + COMPOUND "BlockDefinitions" { + COMPOUND "Block_XYZ" { (name must start with 'Block') + U8 "ID", U16 "ID2" + STR "Name" + F32 "Speed" + U8 "CollideType", "BlockDraw" + U8 "TransmitsLight", "FullBright" + U8 "Shape" , "WalkSound" + U8* "Textures", "Fog", "Coords" + } + } + } + } +}*/ static void* Cw_GetBlocks(struct NbtTag* tag) { void* ptr; if (NbtTag_IsSmall(tag)) { @@ -447,9 +511,6 @@ static void Cw_Callback_1(struct NbtTag* tag) { if (IsTag(tag, "BlockArray")) { World.Volume = tag->DataSize; World.Blocks = Cw_GetBlocks(tag); -#ifdef EXTENDED_BLOCKS - World.Blocks2 = World.Blocks; -#endif } #ifdef EXTENDED_BLOCKS if (IsTag(tag, "BlockArray2")) World_SetMapUpper(Cw_GetBlocks(tag)); @@ -662,6 +723,24 @@ ReturnCode Cw_Load(struct Stream* stream) { /*########################################################################################################################* *-------------------------------------------------Minecraft .dat format---------------------------------------------------* *#########################################################################################################################*/ +/* ClassicWorld is a NBT tag based map format. Tags not listed below are discarded. + Stream BlockData BlockDataTiny BlockDataLong +|--------------| |---------------| |---------------| |---------------| +| U16 Magic | |>BlockDataTiny | | TC_BLOCKDATA | | TC_BLOCKLONG | +| U16 Version | |>BlockDataLong | | U8 Size | | U32 Size | +| Content[var] | |_______________| | U8 Data[size] | | U8 Data[size] | +|______________| |_______________| |_______________| + + Content +|--------------| |--------------| +| >BlockData | | >NewString | +| >Object | | >TC_RESET | +|______________| | >TC_NULL | +| >PrevObject | +| >NewClass | +| >NewEnum | + +}*/ enum JTypeCode { TC_NULL = 0x70, TC_REFERENCE = 0x71, TC_CLASSDESC = 0x72, TC_OBJECT = 0x73, TC_STRING = 0x74, TC_ARRAY = 0x75, TC_ENDBLOCKDATA = 0x78 @@ -852,10 +931,7 @@ ReturnCode Dat_Load(struct Stream* stream) { World.Height = Dat_I32(field); } else if (String_CaselessEqualsConst(&fieldName, "blocks")) { if (field->Type != JFIELD_ARRAY) Logger_Abort("Blocks field must be Array"); - World.Blocks = field->Value.Array.Ptr; -#ifdef EXTENDED_BLOCKS - World.Blocks2 = World.Blocks; -#endif + World.Blocks = field->Value.Array.Ptr; World.Volume = field->Value.Array.Size; } else if (String_CaselessEqualsConst(&fieldName, "xSpawn")) { p->Spawn.X = (float)Dat_I32(field); diff --git a/src/MapGenerator.c b/src/Generator.c similarity index 96% rename from src/MapGenerator.c rename to src/Generator.c index 18ca540cf..a177c4545 100644 --- a/src/MapGenerator.c +++ b/src/Generator.c @@ -1,6 +1,5 @@ -#include "MapGenerator.h" +#include "Generator.h" #include "BlockID.h" -#include "Logger.h" #include "ExtMath.h" #include "Funcs.h" #include "Platform.h" @@ -184,12 +183,6 @@ static void NotchyGen_FillOblateSpheroid(int x, int y, int z, float radius, Bloc } } -#define Stack_Push(index)\ -stack[stack_size++] = index;\ -if (stack_size == stack_limit) {\ - Logger_Abort("NotchyGen_FloodFail - stack limit hit");\ -} - #define STACK_FAST 8192 static void NotchyGen_FloodFill(int index, BlockRaw block) { int32_t* stack; diff --git a/src/MapGenerator.h b/src/Generator.h similarity index 100% rename from src/MapGenerator.h rename to src/Generator.h diff --git a/src/Menus.c b/src/Menus.c index aa0df91d1..786463c36 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -8,7 +8,7 @@ #include "Graphics.h" #include "Funcs.h" #include "Model.h" -#include "MapGenerator.h" +#include "Generator.h" #include "Server.h" #include "Chat.h" #include "ExtMath.h" diff --git a/src/Screens.c b/src/Screens.c index 741228642..013796c1d 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -9,7 +9,7 @@ #include "Funcs.h" #include "TexturePack.h" #include "Model.h" -#include "MapGenerator.h" +#include "Generator.h" #include "Server.h" #include "Chat.h" #include "ExtMath.h" diff --git a/src/Server.c b/src/Server.c index 9ebfd1a6d..61f8a0fa8 100644 --- a/src/Server.c +++ b/src/Server.c @@ -12,7 +12,7 @@ #include "Gui.h" #include "Screens.h" #include "Formats.h" -#include "MapGenerator.h" +#include "Generator.h" #include "World.h" #include "Camera.h" #include "TexturePack.h" diff --git a/src/Window.c b/src/Window.c index 8b6a44638..650550b51 100644 --- a/src/Window.c +++ b/src/Window.c @@ -699,7 +699,6 @@ static Window win_rootWin; static Window win_handle; static XVisualInfo win_visual; static int borderLeft, borderRight, borderTop, borderBottom; -static bool win_isExiting; static Atom wm_destroy, net_wm_state; static Atom net_wm_state_minimized; @@ -963,7 +962,6 @@ void Window_SetClipboardText(const String* value) { XSetSelectionOwner(win_display, xa_clipboard, win_handle, 0); } -static bool win_visible; bool Window_GetVisible(void) { XWindowAttributes attr; XGetWindowAttributes(win_display, win_handle, &attr);