Add World.Loaded variable

This commit is contained in:
UnknownShadow200 2020-03-31 18:31:50 +11:00
parent 0654dc0f41
commit f7dae6bc72
6 changed files with 17 additions and 7 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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);