Consistently use OnInit/OnFree/OnReset everywhere

This commit is contained in:
UnknownShadow200 2020-07-27 18:32:01 +10:00
parent b60cfbb856
commit 8bcbad56f6
20 changed files with 130 additions and 132 deletions

View File

@ -379,19 +379,19 @@ static void OnFileChanged(void* obj, struct Stream* stream, const String* name)
} }
} }
static void Animations_Init(void) { static void OnInit(void) {
ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick); ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick);
Event_RegisterVoid(&TextureEvents.PackChanged, NULL, OnPackChanged); Event_RegisterVoid(&TextureEvents.PackChanged, NULL, OnPackChanged);
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
} }
static void Animations_Free(void) { static void OnFree(void) {
Animations_Clear(); Animations_Clear();
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnPackChanged); Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnPackChanged);
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
} }
struct IGameComponent Animations_Component = { struct IGameComponent Animations_Component = {
Animations_Init, /* Init */ OnInit, /* Init */
Animations_Free /* Free */ OnFree /* Free */
}; };

View File

@ -954,7 +954,7 @@ static void Audio_FilesCallback(const String* path, void* obj) {
StringsBuffer_Add(&files, &relPath); StringsBuffer_Add(&files, &relPath);
} }
static void Audio_Init(void) { static void OnInit(void) {
static const String path = String_FromConst("audio"); static const String path = String_FromConst("audio");
int volume; int volume;
@ -972,7 +972,7 @@ static void Audio_Init(void) {
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
} }
static void Audio_Free(void) { static void OnFree(void) {
Music_Free(); Music_Free();
Sounds_Free(); Sounds_Free();
Waitable_Free(music_waitable); Waitable_Free(music_waitable);
@ -982,6 +982,6 @@ static void Audio_Free(void) {
#endif #endif
struct IGameComponent Audio_Component = { struct IGameComponent Audio_Component = {
Audio_Init, /* Init */ OnInit, /* Init */
Audio_Free /* Free */ OnFree /* Free */
}; };

View File

@ -67,16 +67,16 @@ static void OnContextLost(void* obj) {
Gfx_DeleteDynamicVb(&axisLines_vb); Gfx_DeleteDynamicVb(&axisLines_vb);
} }
static void AxisLinesRenderer_Init(void) { static void OnInit(void) {
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
} }
static void AxisLinesRenderer_Free(void) { static void OnFree(void) {
OnContextLost(NULL); OnContextLost(NULL);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
} }
struct IGameComponent AxisLinesRenderer_Component = { struct IGameComponent AxisLinesRenderer_Component = {
AxisLinesRenderer_Init, /* Init */ OnInit, /* Init */
AxisLinesRenderer_Free, /* Free */ OnFree, /* Free */
}; };

View File

@ -672,7 +672,7 @@ BlockID AutoRotate_RotateBlock(BlockID block) {
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------Blocks component-----------------------------------------------------* *----------------------------------------------------Blocks component-----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Blocks_Reset(void) { static void OnReset(void) {
int i, block; int i, block;
for (i = 0; i < Array_Elems(definedCustomBlocks); i++) { for (i = 0; i < Array_Elems(definedCustomBlocks); i++) {
definedCustomBlocks[i] = 0; definedCustomBlocks[i] = 0;
@ -686,7 +686,7 @@ static void Blocks_Reset(void) {
} }
static void OnAtlasChanged(void* obj) { Block_RecalculateAllSpriteBB(); } static void OnAtlasChanged(void* obj) { Block_RecalculateAllSpriteBB(); }
static void Blocks_Init(void) { static void OnInit(void) {
int block; int block;
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) { for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
Blocks.CanPlace[block] = true; Blocks.CanPlace[block] = true;
@ -694,7 +694,7 @@ static void Blocks_Init(void) {
} }
AutoRotate_Enabled = true; AutoRotate_Enabled = true;
Blocks_Reset(); OnReset();
Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, OnAtlasChanged); Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, OnAtlasChanged);
Blocks.CanPlace[BLOCK_AIR] = false; Blocks.CanDelete[BLOCK_AIR] = false; Blocks.CanPlace[BLOCK_AIR] = false; Blocks.CanDelete[BLOCK_AIR] = false;
@ -705,12 +705,12 @@ static void Blocks_Init(void) {
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false; Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
} }
static void Blocks_Free(void) { static void OnFree(void) {
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnAtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnAtlasChanged);
} }
struct IGameComponent Blocks_Component = { struct IGameComponent Blocks_Component = {
Blocks_Init, /* Init */ OnInit, /* Init */
Blocks_Free, /* Free */ OnFree, /* Free */
Blocks_Reset, /* Reset */ OnReset, /* Reset */
}; };

View File

@ -1271,7 +1271,7 @@ void Builder_ApplyActive(void) {
} }
} }
static void Builder_Init(void) { static void OnInit(void) {
Builder_Offsets[FACE_XMIN] = -1; Builder_Offsets[FACE_XMIN] = -1;
Builder_Offsets[FACE_XMAX] = 1; Builder_Offsets[FACE_XMAX] = 1;
Builder_Offsets[FACE_ZMIN] = -EXTCHUNK_SIZE; Builder_Offsets[FACE_ZMIN] = -EXTCHUNK_SIZE;
@ -1283,15 +1283,15 @@ static void Builder_Init(void) {
Builder_ApplyActive(); Builder_ApplyActive();
} }
static void Builder_OnNewMapLoaded(void) { static void OnNewMapLoaded(void) {
Builder_SidesLevel = max(0, Env_SidesHeight); Builder_SidesLevel = max(0, Env_SidesHeight);
Builder_EdgeLevel = max(0, Env.EdgeHeight); Builder_EdgeLevel = max(0, Env.EdgeHeight);
} }
struct IGameComponent Builder_Component = { struct IGameComponent Builder_Component = {
Builder_Init, /* Init */ OnInit, /* Init */
NULL, /* Free */ NULL, /* Free */
NULL, /* Reset */ NULL, /* Reset */
NULL, /* OnNewMap */ NULL, /* OnNewMap */
Builder_OnNewMapLoaded /* OnNewMapLoaded */ OnNewMapLoaded /* OnNewMapLoaded */
}; };

View File

@ -599,7 +599,7 @@ void Chat_Send(const String* text, cc_bool logUsage) {
} }
} }
static void Chat_Init(void) { static void OnInit(void) {
Commands_Register(&GpuInfoCommand); Commands_Register(&GpuInfoCommand);
Commands_Register(&HelpCommand); Commands_Register(&HelpCommand);
Commands_Register(&RenderTypeCommand); Commands_Register(&RenderTypeCommand);
@ -614,7 +614,7 @@ static void Chat_Init(void) {
#endif #endif
} }
static void Chat_Reset(void) { static void OnReset(void) {
CloseLogFile(); CloseLogFile();
ResetLogFile(); ResetLogFile();
@ -628,7 +628,7 @@ static void Chat_Reset(void) {
Chat_AddOf(&String_Empty, MSG_TYPE_BOTTOMRIGHT_3); Chat_AddOf(&String_Empty, MSG_TYPE_BOTTOMRIGHT_3);
} }
static void Chat_Free(void) { static void OnFree(void) {
CloseLogFile(); CloseLogFile();
cmds_head = NULL; cmds_head = NULL;
@ -641,7 +641,7 @@ static void Chat_Free(void) {
} }
struct IGameComponent Chat_Component = { struct IGameComponent Chat_Component = {
Chat_Init, /* Init */ OnInit, /* Init */
Chat_Free, /* Free */ OnFree, /* Free */
Chat_Reset /* Reset */ OnReset /* Reset */
}; };

View File

@ -636,7 +636,7 @@ static void InitHexEncodedCol(int i, int hex, cc_uint8 lo, cc_uint8 hi) {
255); 255);
} }
static void Drawer2D_Reset(void) { static void OnReset(void) {
int i; int i;
for (i = 0; i < DRAWER2D_MAX_COLS; i++) { for (i = 0; i < DRAWER2D_MAX_COLS; i++) {
Drawer2D_Cols[i] = 0; Drawer2D_Cols[i] = 0;
@ -666,8 +666,8 @@ static void OnFileChanged(void* obj, struct Stream* src, const String* name) {
} }
} }
static void Drawer2D_Init(void) { static void OnInit(void) {
Drawer2D_Reset(); OnReset();
Drawer2D_BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false); Drawer2D_BitmappedText = Game_ClassicMode || !Options_GetBool(OPT_USE_CHAT_FONT, false);
Drawer2D_BlackTextShadows = Options_GetBool(OPT_BLACK_TEXT, false); Drawer2D_BlackTextShadows = Options_GetBool(OPT_BLACK_TEXT, false);
@ -678,16 +678,16 @@ static void Drawer2D_Init(void) {
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
} }
static void Drawer2D_Free(void) { static void OnFree(void) {
FreeFontBitmap(); FreeFontBitmap();
fontBitmap.scan0 = NULL; fontBitmap.scan0 = NULL;
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
} }
struct IGameComponent Drawer2D_Component = { struct IGameComponent Drawer2D_Component = {
Drawer2D_Init, /* Init */ OnInit, /* Init */
Drawer2D_Free, /* Free */ OnFree, /* Free */
Drawer2D_Reset, /* Reset */ OnReset, /* Reset */
}; };

View File

@ -865,7 +865,7 @@ static void OnEnvVariableChanged(void* obj, int envVar) {
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------EnvRenderer component--------------------------------------------------* *--------------------------------------------------EnvRenderer component--------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void EnvRenderer_Init(void) { static void OnInit(void) {
String renderType; String renderType;
int flags; int flags;
Options_UNSAFE_Get(OPT_RENDER_TYPE, &renderType); Options_UNSAFE_Get(OPT_RENDER_TYPE, &renderType);
@ -887,7 +887,7 @@ static void EnvRenderer_Init(void) {
Game_SetViewDistance(Game_UserViewDistance); Game_SetViewDistance(Game_UserViewDistance);
} }
static void EnvRenderer_Free(void) { static void OnFree(void) {
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnTexturePackChanged); Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnTexturePackChanged);
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
@ -902,7 +902,7 @@ static void EnvRenderer_Free(void) {
Weather_Heightmap = NULL; Weather_Heightmap = NULL;
} }
static void EnvRenderer_Reset(void) { static void OnReset(void) {
Gfx_SetFog(false); Gfx_SetFog(false);
DeleteVbs(); DeleteVbs();
@ -911,12 +911,12 @@ static void EnvRenderer_Reset(void) {
lastPos = IVec3_MaxValue(); lastPos = IVec3_MaxValue();
} }
static void EnvRenderer_OnNewMapLoaded(void) { OnContextRecreated(NULL); } static void OnNewMapLoaded(void) { OnContextRecreated(NULL); }
struct IGameComponent EnvRenderer_Component = { struct IGameComponent EnvRenderer_Component = {
EnvRenderer_Init, /* Init */ OnInit, /* Init */
EnvRenderer_Free, /* Free */ OnFree, /* Free */
EnvRenderer_Reset, /* Reset */ OnReset, /* Reset */
EnvRenderer_Reset, /* OnNewMap */ OnReset, /* OnNewMap */
EnvRenderer_OnNewMapLoaded /* OnNewMapLoaded */ OnNewMapLoaded /* OnNewMapLoaded */
}; };

View File

@ -402,7 +402,7 @@ static void OnContextLost(void* obj) {
Gfx_DeleteTexture(&Gui_IconsTex); Gfx_DeleteTexture(&Gui_IconsTex);
} }
static void Gui_Init(void) { static void OnInit(void) {
Event_RegisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged); Event_RegisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged);
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
@ -415,11 +415,11 @@ static void Gui_Init(void) {
Gui_ShowDefault(); Gui_ShowDefault();
} }
static void Gui_Reset(void) { static void OnReset(void) {
/* TODO:Should we reset all screens here.. ? */ /* TODO:Should we reset all screens here.. ? */
} }
static void Gui_Free(void) { static void OnFree(void) {
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged); Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged);
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
@ -432,13 +432,13 @@ static void Gui_Free(void) {
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]); while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
OnContextLost(NULL); OnContextLost(NULL);
Gui_Reset(); OnReset();
} }
struct IGameComponent Gui_Component = { struct IGameComponent Gui_Component = {
Gui_Init, /* Init */ OnInit, /* Init */
Gui_Free, /* Free */ OnFree, /* Free */
Gui_Reset, /* Reset */ OnReset, /* Reset */
NULL, /* OnNewMap */ NULL, /* OnNewMap */
NULL, /* OnNewMapLoaded */ NULL, /* OnNewMapLoaded */
}; };

View File

@ -232,7 +232,7 @@ static const struct EntityVTABLE heldEntity_VTABLE = {
NULL, NULL, NULL, HeldBlockRenderer_GetCol, NULL, NULL, NULL, HeldBlockRenderer_GetCol,
NULL, NULL NULL, NULL
}; };
static void HeldBlockRenderer_Init(void) { static void OnInit(void) {
Entity_Init(&held_entity); Entity_Init(&held_entity);
held_entity.VTABLE = &heldEntity_VTABLE; held_entity.VTABLE = &heldEntity_VTABLE;
held_entity.NoShade = true; held_entity.NoShade = true;
@ -245,13 +245,13 @@ static void HeldBlockRenderer_Init(void) {
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
} }
static void HeldBlockRenderer_Free(void) { static void OnFree(void) {
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged); Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
Event_UnregisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim); Event_UnregisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
} }
struct IGameComponent HeldBlockRenderer_Component = { struct IGameComponent HeldBlockRenderer_Component = {
HeldBlockRenderer_Init, /* Init */ OnInit, /* Init */
HeldBlockRenderer_Free /* Free */ OnFree /* Free */
}; };

View File

@ -1104,7 +1104,7 @@ void Http_UrlEncodeUtf8(String* dst, const String* src) {
/*########################################################################################################################* /*########################################################################################################################*
*-----------------------------------------------------Http component------------------------------------------------------* *-----------------------------------------------------Http component------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Http_Init(void) { static void OnInit(void) {
#ifdef CC_BUILD_ANDROID #ifdef CC_BUILD_ANDROID
if (workerThread) return; if (workerThread) return;
#endif #endif
@ -1122,7 +1122,7 @@ static void Http_Init(void) {
#endif #endif
} }
static void Http_Free(void) { static void OnFree(void) {
http_terminate = true; http_terminate = true;
Http_ClearPending(); Http_ClearPending();
#ifndef CC_BUILD_WEB #ifndef CC_BUILD_WEB
@ -1140,7 +1140,7 @@ static void Http_Free(void) {
} }
struct IGameComponent Http_Component = { struct IGameComponent Http_Component = {
Http_Init, /* Init */ OnInit, /* Init */
Http_Free, /* Free */ OnFree, /* Free */
Http_ClearPending /* Reset */ Http_ClearPending /* Reset */
}; };

View File

@ -117,14 +117,14 @@ void Inventory_Remove(BlockID block) {
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------Inventory component----------------------------------------------------* *--------------------------------------------------Inventory component----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Inventory_Reset(void) { static void OnReset(void) {
Inventory_ResetMapping(); Inventory_ResetMapping();
Inventory.CanChangeSelected = true; Inventory.CanChangeSelected = true;
} }
static void Inventory_Init(void) { static void OnInit(void) {
BlockID* inv = Inventory.Table; BlockID* inv = Inventory.Table;
Inventory_Reset(); OnReset();
Inventory.BlocksPerRow = Game_ClassicMode ? 9 : 10; Inventory.BlocksPerRow = Game_ClassicMode ? 9 : 10;
inv[0] = BLOCK_STONE; inv[1] = BLOCK_COBBLE; inv[2] = BLOCK_BRICK; inv[0] = BLOCK_STONE; inv[1] = BLOCK_COBBLE; inv[2] = BLOCK_BRICK;
@ -133,7 +133,7 @@ static void Inventory_Init(void) {
} }
struct IGameComponent Inventory_Component = { struct IGameComponent Inventory_Component = {
Inventory_Init, /* Init */ OnInit, /* Init */
NULL, /* Free */ NULL, /* Free */
Inventory_Reset, /* Reset */ OnReset, /* Reset */
}; };

View File

@ -352,20 +352,20 @@ void Lighting_LightHint(int startX, int startZ) {
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------Lighting component----------------------------------------------------* *---------------------------------------------------Lighting component----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Lighting_Reset(void) { static void OnReset(void) {
Mem_Free(Lighting_Heightmap); Mem_Free(Lighting_Heightmap);
Lighting_Heightmap = NULL; Lighting_Heightmap = NULL;
} }
static void Lighting_OnNewMapLoaded(void) { static void OnNewMapLoaded(void) {
Lighting_Heightmap = (cc_int16*)Mem_Alloc(World.Width * World.Length, 2, "lighting heightmap"); Lighting_Heightmap = (cc_int16*)Mem_Alloc(World.Width * World.Length, 2, "lighting heightmap");
Lighting_Refresh(); Lighting_Refresh();
} }
struct IGameComponent Lighting_Component = { struct IGameComponent Lighting_Component = {
NULL, /* Init */ NULL, /* Init */
Lighting_Reset, /* Free */ OnReset, /* Free */
Lighting_Reset, /* Reset */ OnReset, /* Reset */
Lighting_Reset, /* OnNewMap */ OnReset, /* OnNewMap */
Lighting_OnNewMapLoaded /* OnNewMapLoaded */ OnNewMapLoaded /* OnNewMapLoaded */
}; };

View File

@ -741,10 +741,10 @@ static void OnVisibilityChanged(void* obj) {
lastCamPos = Vec3_BigPos(); lastCamPos = Vec3_BigPos();
CalcViewDists(); CalcViewDists();
} }
static void MapRenderer_DeleteChunks_(void* obj) { DeleteChunks(); } static void DeleteChunks_(void* obj) { DeleteChunks(); }
static void MapRenderer_Refresh_(void* obj) { MapRenderer_Refresh(); } static void Refresh_(void* obj) { MapRenderer_Refresh(); }
static void MapRenderer_OnNewMap(void) { static void OnNewMap(void) {
Game.ChunkUpdates = 0; Game.ChunkUpdates = 0;
DeleteChunks(); DeleteChunks();
ResetPartCounts(); ResetPartCounts();
@ -754,7 +754,7 @@ static void MapRenderer_OnNewMap(void) {
FreeParts(); FreeParts();
} }
static void MapRenderer_OnNewMapLoaded(void) { static void OnNewMapLoaded(void) {
int count; int count;
MapRenderer_ChunksX = (World.Width + CHUNK_MAX) >> CHUNK_SHIFT; MapRenderer_ChunksX = (World.Width + CHUNK_MAX) >> CHUNK_SHIFT;
MapRenderer_ChunksY = (World.Height + CHUNK_MAX) >> CHUNK_SHIFT; MapRenderer_ChunksY = (World.Height + CHUNK_MAX) >> CHUNK_SHIFT;
@ -774,15 +774,15 @@ static void MapRenderer_OnNewMapLoaded(void) {
lastCamPos = Vec3_BigPos(); lastCamPos = Vec3_BigPos();
} }
static void MapRenderer_Init(void) { static void OnInit(void) {
Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged); Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged); Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged);
Event_RegisterVoid(&BlockEvents.BlockDefChanged, NULL, OnBlockDefinitionChanged); Event_RegisterVoid(&BlockEvents.BlockDefChanged, NULL, OnBlockDefinitionChanged);
Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnVisibilityChanged); Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnVisibilityChanged);
Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, OnVisibilityChanged); Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, OnVisibilityChanged);
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, DeleteChunks_);
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_Refresh_); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Refresh_);
/* This = 87 fixes map being invisible when no textures */ /* This = 87 fixes map being invisible when no textures */
MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */ MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */
@ -791,23 +791,22 @@ static void MapRenderer_Init(void) {
CalcViewDists(); CalcViewDists();
} }
static void MapRenderer_Free(void) { static void OnFree(void) {
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged); Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged);
Event_UnregisterVoid(&BlockEvents.BlockDefChanged, NULL, OnBlockDefinitionChanged); Event_UnregisterVoid(&BlockEvents.BlockDefChanged, NULL, OnBlockDefinitionChanged);
Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnVisibilityChanged); Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnVisibilityChanged);
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, OnVisibilityChanged); Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, OnVisibilityChanged);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, DeleteChunks_);
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_Refresh_); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Refresh_);
OnNewMap();
MapRenderer_OnNewMap();
} }
struct IGameComponent MapRenderer_Component = { struct IGameComponent MapRenderer_Component = {
MapRenderer_Init, /* Init */ OnInit, /* Init */
MapRenderer_Free, /* Free */ OnFree, /* Free */
MapRenderer_OnNewMap, /* Reset */ OnNewMap, /* Reset */
MapRenderer_OnNewMap, /* OnNewMap */ OnNewMap, /* OnNewMap */
MapRenderer_OnNewMapLoaded /* OnNewMapLoaded */ OnNewMapLoaded /* OnNewMapLoaded */
}; };

View File

@ -2086,8 +2086,7 @@ static struct Model* SkinnedCubeModel_GetInstance(void) {
/*########################################################################################################################* /*########################################################################################################################*
*-------------------------------------------------------Model component---------------------------------------------------* *-------------------------------------------------------Model component---------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void RegisterDefaultModels(void) {
static void Model_RegisterDefaultModels(void) {
Model_RegisterTexture(&human_tex); Model_RegisterTexture(&human_tex);
Model_RegisterTexture(&chicken_tex); Model_RegisterTexture(&chicken_tex);
Model_RegisterTexture(&creeper_tex); Model_RegisterTexture(&creeper_tex);
@ -2120,11 +2119,11 @@ static void Model_RegisterDefaultModels(void) {
Model_Register(SkinnedCubeModel_GetInstance()); Model_Register(SkinnedCubeModel_GetInstance());
} }
static void Models_Init(void) { static void OnInit(void) {
Models.Vertices = defaultVertices; Models.Vertices = defaultVertices;
Models.MaxVertices = Array_Elems(defaultVertices); Models.MaxVertices = Array_Elems(defaultVertices);
Model_RegisterDefaultModels(); RegisterDefaultModels();
Models_ContextRecreated(NULL); Models_ContextRecreated(NULL);
Models.ClassicArms = Options_GetBool(OPT_CLASSIC_ARM_MODEL, Game_ClassicMode); Models.ClassicArms = Options_GetBool(OPT_CLASSIC_ARM_MODEL, Game_ClassicMode);
@ -2133,7 +2132,7 @@ static void Models_Init(void) {
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
} }
static void Models_Free(void) { static void OnFree(void) {
Models_ContextLost(NULL); Models_ContextLost(NULL);
CustomModel_FreeAll(); CustomModel_FreeAll();
@ -2142,10 +2141,10 @@ static void Models_Free(void) {
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
} }
static void Models_Reset(void) { CustomModel_FreeAll(); } static void OnReset(void) { CustomModel_FreeAll(); }
struct IGameComponent Models_Component = { struct IGameComponent Models_Component = {
Models_Init, /* Init */ OnInit, /* Init */
Models_Free, /* Free */ OnFree, /* Free */
Models_Reset, /* Reset */ OnReset, /* Reset */
}; };

View File

@ -597,7 +597,7 @@ static void OnFileChanged(void* obj, struct Stream* stream, const String* name)
} }
} }
static void Particles_Init(void) { static void OnInit(void) {
ScheduledTask_Add(GAME_DEF_TICKS, Particles_Tick); ScheduledTask_Add(GAME_DEF_TICKS, Particles_Tick);
Random_SeedFromCurrentTime(&rnd); Random_SeedFromCurrentTime(&rnd);
OnContextRecreated(NULL); OnContextRecreated(NULL);
@ -608,7 +608,7 @@ static void Particles_Init(void) {
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
} }
static void Particles_Free(void) { static void OnFree(void) {
OnContextLost(NULL); OnContextLost(NULL);
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
@ -617,11 +617,11 @@ static void Particles_Free(void) {
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
} }
static void Particles_Reset(void) { rain_count = 0; terrain_count = 0; custom_count = 0; } static void OnReset(void) { rain_count = 0; terrain_count = 0; custom_count = 0; }
struct IGameComponent Particles_Component = { struct IGameComponent Particles_Component = {
Particles_Init, /* Init */ OnInit, /* Init */
Particles_Free, /* Free */ OnFree, /* Free */
Particles_Reset, /* Reset */ OnReset, /* Reset */
Particles_Reset /* OnNewMap */ OnReset /* OnNewMap */
}; };

View File

@ -112,19 +112,19 @@ static void OnContextRecreated(void* obj) {
pickedPos_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_COLOURED, PICKEDPOS_NUM_VERTICES); pickedPos_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_COLOURED, PICKEDPOS_NUM_VERTICES);
} }
static void PickedPosRenderer_Init(void) { static void OnInit(void) {
OnContextRecreated(NULL); OnContextRecreated(NULL);
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
} }
static void PickedPosRenderer_Free(void) { static void OnFree(void) {
OnContextLost(NULL); OnContextLost(NULL);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
} }
struct IGameComponent PickedPosRenderer_Component = { struct IGameComponent PickedPosRenderer_Component = {
PickedPosRenderer_Init, /* Init */ OnInit, /* Init */
PickedPosRenderer_Free, /* Free */ OnFree, /* Free */
}; };

View File

@ -214,24 +214,24 @@ void Selections_Render(void) {
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------Selections component---------------------------------------------------* *--------------------------------------------------Selections component---------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Selections_Init(void) { static void OnInit(void) {
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost);
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
} }
static void Selections_Reset(void) { static void OnReset(void) {
selections_count = 0; selections_count = 0;
} }
static void Selections_Free(void) { static void OnFree(void) {
Selections_ContextLost(NULL); Selections_ContextLost(NULL);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost);
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
} }
struct IGameComponent Selections_Component = { struct IGameComponent Selections_Component = {
Selections_Init, /* Init */ OnInit, /* Init */
Selections_Free, /* Free */ OnFree, /* Free */
Selections_Reset, /* Reset */ OnReset, /* Reset */
Selections_Reset /* OnNewMap */ OnReset /* OnNewMap */
}; };

View File

@ -242,7 +242,7 @@ static cc_bool net_connecting;
static double net_connectTimeout; static double net_connectTimeout;
#define NET_TIMEOUT_SECS 15 #define NET_TIMEOUT_SECS 15
static void Server_Free(void); static void OnFree(void);
static void MPConnection_FinishConnect(void) { static void MPConnection_FinishConnect(void) {
net_connecting = false; net_connecting = false;
Event_RaiseVoid(&NetEvents.Connected); Event_RaiseVoid(&NetEvents.Connected);
@ -270,7 +270,7 @@ static void MPConnection_FailConnect(cc_result result) {
String_Format2(&msg, "Failed to connect to %s:%i", &Server.IP, &Server.Port); String_Format2(&msg, "Failed to connect to %s:%i", &Server.IP, &Server.Port);
Game_Disconnect(&msg, &reason); Game_Disconnect(&msg, &reason);
Server_Free(); OnFree();
} }
static void MPConnection_TickConnect(void) { static void MPConnection_TickConnect(void) {
@ -491,7 +491,7 @@ static void MPConnection_Init(void) {
} }
static void Server_OnNewMap(void) { static void OnNewMap(void) {
int i; int i;
if (Server.IsSinglePlayer) return; if (Server.IsSinglePlayer) return;
@ -501,14 +501,14 @@ static void Server_OnNewMap(void) {
} }
} }
static void Server_Reset(void) { static void OnReset(void) {
if (Server.IsSinglePlayer) return; if (Server.IsSinglePlayer) return;
net_writeFailed = false; net_writeFailed = false;
Server_Free(); OnFree();
} }
static void Server_Init(void) { static void OnInit(void) {
String_InitArray(Server.Name, nameBuffer); String_InitArray(Server.Name, nameBuffer);
String_InitArray(Server.MOTD, motdBuffer); String_InitArray(Server.MOTD, motdBuffer);
String_InitArray(Server.AppName, appBuffer); String_InitArray(Server.AppName, appBuffer);
@ -523,7 +523,7 @@ static void Server_Init(void) {
String_AppendConst(&Server.AppName, GAME_APP_NAME); String_AppendConst(&Server.AppName, GAME_APP_NAME);
} }
static void Server_Free(void) { static void OnFree(void) {
if (Server.IsSinglePlayer) { if (Server.IsSinglePlayer) {
Physics_Free(); Physics_Free();
} else { } else {
@ -534,8 +534,8 @@ static void Server_Free(void) {
} }
struct IGameComponent Server_Component = { struct IGameComponent Server_Component = {
Server_Init, /* Init */ OnInit, /* Init */
Server_Free, /* Free */ OnFree, /* Free */
Server_Reset, /* Reset */ OnReset, /* Reset */
Server_OnNewMap /* OnNewMap */ OnNewMap /* OnNewMap */
}; };

View File

@ -443,7 +443,7 @@ static void OnContextRecreated(void* obj) {
if (!Gfx.ManagedTextures) TexturePack_ExtractCurrent(true); if (!Gfx.ManagedTextures) TexturePack_ExtractCurrent(true);
} }
static void Textures_Init(void) { static void OnInit(void) {
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
@ -452,7 +452,7 @@ static void Textures_Init(void) {
TextureCache_Init(); TextureCache_Init();
} }
static void Textures_Free(void) { static void OnFree(void) {
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
@ -462,6 +462,6 @@ static void Textures_Free(void) {
} }
struct IGameComponent Textures_Component = { struct IGameComponent Textures_Component = {
Textures_Init, /* Init */ OnInit, /* Init */
Textures_Free /* Free */ OnFree /* Free */
}; };