diff --git a/src/Game.c b/src/Game.c index 23a17b94c..6ad986fab 100644 --- a/src/Game.c +++ b/src/Game.c @@ -184,8 +184,7 @@ void Game_Disconnect(const String* title, const String* reason) { void Game_Reset(void) { struct IGameComponent* comp; - World_Reset(); - Event_RaiseVoid(&WorldEvents.NewMap); + World_NewMap(); if (World_TextureUrl.length) { World_TextureUrl.length = 0; diff --git a/src/Menus.c b/src/Menus.c index 717edd3cb..74d2af8be 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -178,7 +178,7 @@ static void Menu_Remove(void* screen, int i) { } static void Menu_BeginGen(int width, int height, int length) { - World_Reset(); + World_NewMap(); World_SetDimensions(width, height, length); GeneratingScreen_Show(); } diff --git a/src/Protocol.c b/src/Protocol.c index c768eb97e..3be254877 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -424,8 +424,7 @@ static void MapState_Read(struct MapState* m) { } static void Classic_StartLoading(void) { - World_Reset(); - Event_RaiseVoid(&WorldEvents.NewMap); + World_NewMap(); Stream_ReadonlyMemory(&map_part, NULL, 0); LoadingScreen_Show(&Server.Name, &Server.MOTD); diff --git a/src/Screens.c b/src/Screens.c index 60b913eae..39a7a0587 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1346,7 +1346,6 @@ struct Screen* LoadingScreen_UNSAFE_RawPointer = (struct Screen*)&LoadingScreen; static void GeneratingScreen_Init(void* screen) { Gen_Done = false; LoadingScreen_Init(screen); - Event_RaiseVoid(&WorldEvents.NewMap); Gen_Blocks = (BlockRaw*)Mem_TryAlloc(World.Volume, 1); if (!Gen_Blocks) { diff --git a/src/World.c b/src/World.c index e73ccffdf..fd0553f7e 100644 --- a/src/World.c +++ b/src/World.c @@ -49,6 +49,12 @@ void World_Reset(void) { Env_Reset(); } +void World_NewMap(void) { + World_Reset(); + World.Loaded = false; + Event_RaiseVoid(&WorldEvents.NewMap); +} + void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) { World_SetDimensions(width, height, length); World.Blocks = blocks; @@ -65,6 +71,7 @@ void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) { if (Env.EdgeHeight == -1) { Env.EdgeHeight = height / 2; } if (Env.CloudsHeight == -1) { Env.CloudsHeight = height + 2; } GenerateNewUuid(); + World.Loaded = true; } CC_NOINLINE void World_SetDimensions(int width, int height, int length) { diff --git a/src/World.h b/src/World.h index 6907b62b5..c8ad8d782 100644 --- a/src/World.h +++ b/src/World.h @@ -39,11 +39,17 @@ CC_VAR extern struct _WorldData { /* e.g. this will be 255 if only 8 bit blocks are used */ int IDMask; #endif + /* Whether the world has finished loading/generating. */ + /* NOTE: Blocks may still be NULL. (e.g. error during loading) */ + cc_bool Loaded; } World; extern String World_TextureUrl; /* Frees the blocks array, sets dimensions to 0, resets environment to default. */ -CC_API void World_Reset(void); +void World_Reset(void); +/* Sets up state and raises WorldEvents.NewMap event */ +/* NOTE: This implicitly calls World_Reset. */ +CC_API void World_NewMap(void); /* Sets the blocks array and dimensions of the map. */ /* May also sets some environment settings like border/clouds height, if they are -1 */ CC_API void World_SetNewMap(BlockRaw* blocks, int width, int height, int length);