mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Add single Event_UnregisterAll method, instead of having code everywhere calling Event_UnregisterXYZ
This commit is contained in:
parent
9afde7d0aa
commit
fd28ce7b27
@ -385,13 +385,7 @@ static void OnInit(void) {
|
|||||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
|
||||||
Animations_Clear();
|
|
||||||
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnPackChanged);
|
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent Animations_Component = {
|
struct IGameComponent Animations_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
OnFree /* Free */
|
Animations_Clear /* Free */
|
||||||
};
|
};
|
||||||
|
@ -977,7 +977,6 @@ static void OnFree(void) {
|
|||||||
Sounds_Free();
|
Sounds_Free();
|
||||||
Waitable_Free(music_waitable);
|
Waitable_Free(music_waitable);
|
||||||
Audio_SysFree();
|
Audio_SysFree();
|
||||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -71,10 +71,7 @@ static void OnInit(void) {
|
|||||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) { OnContextLost(NULL); }
|
||||||
OnContextLost(NULL);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent AxisLinesRenderer_Component = {
|
struct IGameComponent AxisLinesRenderer_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
|
@ -705,12 +705,8 @@ static void OnInit(void) {
|
|||||||
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
|
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
|
||||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnAtlasChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent Blocks_Component = {
|
struct IGameComponent Blocks_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
OnFree, /* Free */
|
NULL, /* Free */
|
||||||
OnReset, /* Reset */
|
OnReset, /* Reset */
|
||||||
};
|
};
|
||||||
|
@ -681,7 +681,6 @@ static void OnInit(void) {
|
|||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
FreeFontBitmap();
|
FreeFontBitmap();
|
||||||
fontBitmap.scan0 = NULL;
|
fontBitmap.scan0 = NULL;
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IGameComponent Drawer2D_Component = {
|
struct IGameComponent Drawer2D_Component = {
|
||||||
|
@ -1151,9 +1151,6 @@ static void Entities_Free(void) {
|
|||||||
if (!Entities.List[i]) continue;
|
if (!Entities.List[i]) continue;
|
||||||
Entities_Remove((EntityID)i);
|
Entities_Remove((EntityID)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
|
|
||||||
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged);
|
|
||||||
Gfx_DeleteTexture(&ShadowComponent_ShadowTex);
|
Gfx_DeleteTexture(&ShadowComponent_ShadowTex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,15 +888,6 @@ static void OnInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, OnTexturePackChanged);
|
|
||||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
|
|
||||||
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnViewDistanceChanged);
|
|
||||||
Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
|
||||||
|
|
||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
Mem_Free(Weather_Heightmap);
|
Mem_Free(Weather_Heightmap);
|
||||||
Weather_Heightmap = NULL;
|
Weather_Heightmap = NULL;
|
||||||
|
57
src/Event.c
57
src/Event.c
@ -50,6 +50,63 @@ void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callbac
|
|||||||
Logger_Abort("Attempt to unregister event handler that was not registered to begin with");
|
Logger_Abort("Attempt to unregister event handler that was not registered to begin with");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Event_UnregisterAll(void) {
|
||||||
|
EntityEvents.Added.Count = 0;
|
||||||
|
EntityEvents.Removed.Count = 0;
|
||||||
|
|
||||||
|
TabListEvents.Added.Count = 0;
|
||||||
|
TabListEvents.Changed.Count = 0;
|
||||||
|
TabListEvents.Removed.Count = 0;
|
||||||
|
|
||||||
|
TextureEvents.AtlasChanged.Count = 0;
|
||||||
|
TextureEvents.PackChanged.Count = 0;
|
||||||
|
TextureEvents.FileChanged.Count = 0;
|
||||||
|
|
||||||
|
GfxEvents.ViewDistanceChanged.Count = 0;
|
||||||
|
GfxEvents.LowVRAMDetected.Count = 0;
|
||||||
|
GfxEvents.ProjectionChanged.Count = 0;
|
||||||
|
GfxEvents.ContextLost.Count = 0;
|
||||||
|
GfxEvents.ContextRecreated.Count = 0;
|
||||||
|
|
||||||
|
UserEvents.BlockChanged.Count = 0;
|
||||||
|
UserEvents.HackPermissionsChanged.Count = 0;
|
||||||
|
UserEvents.HeldBlockChanged.Count = 0;
|
||||||
|
|
||||||
|
BlockEvents.PermissionsChanged.Count = 0;
|
||||||
|
BlockEvents.BlockDefChanged.Count = 0;
|
||||||
|
|
||||||
|
WorldEvents.NewMap.Count = 0;
|
||||||
|
WorldEvents.Loading.Count = 0;
|
||||||
|
WorldEvents.MapLoaded.Count = 0;
|
||||||
|
WorldEvents.EnvVarChanged.Count = 0;
|
||||||
|
|
||||||
|
ChatEvents.FontChanged.Count = 0;
|
||||||
|
ChatEvents.ChatReceived.Count = 0;
|
||||||
|
ChatEvents.ChatSending.Count = 0;
|
||||||
|
ChatEvents.ColCodeChanged.Count = 0;
|
||||||
|
|
||||||
|
WindowEvents.Redraw.Count = 0;
|
||||||
|
WindowEvents.Resized.Count = 0;
|
||||||
|
WindowEvents.Closing.Count = 0;
|
||||||
|
WindowEvents.FocusChanged.Count = 0;
|
||||||
|
WindowEvents.StateChanged.Count = 0;
|
||||||
|
WindowEvents.Created.Count = 0;
|
||||||
|
|
||||||
|
InputEvents.Press.Count = 0;
|
||||||
|
InputEvents.Down.Count = 0;
|
||||||
|
InputEvents.Up.Count = 0;
|
||||||
|
InputEvents.Wheel.Count = 0;
|
||||||
|
InputEvents.TextChanged.Count = 0;
|
||||||
|
|
||||||
|
PointerEvents.Moved.Count = 0;
|
||||||
|
PointerEvents.Down.Count = 0;
|
||||||
|
PointerEvents.Up.Count = 0;
|
||||||
|
PointerEvents.RawMoved.Count = 0;
|
||||||
|
|
||||||
|
NetEvents.Connected.Count = 0;
|
||||||
|
NetEvents.Disconnected.Count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Event_RaiseVoid(struct Event_Void* handlers) {
|
void Event_RaiseVoid(struct Event_Void* handlers) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < handlers->Count; i++) {
|
for (i = 0; i < handlers->Count; i++) {
|
||||||
|
@ -135,6 +135,9 @@ void Event_RaiseRawMove(struct Event_RawMove* handlers, float xDelta, float yDel
|
|||||||
#define Event_RegisterRawMove(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
|
#define Event_RegisterRawMove(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
|
||||||
#define Event_UnregisterRawMove(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
|
#define Event_UnregisterRawMove(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
|
||||||
|
|
||||||
|
/* NOTE: Event_UnregisterAll must be updated if events lists are changed */
|
||||||
|
void Event_UnregisterAll(void);
|
||||||
|
|
||||||
CC_VAR extern struct _EntityEventsList {
|
CC_VAR extern struct _EntityEventsList {
|
||||||
struct Event_Int Added; /* Entity is spawned in the current world */
|
struct Event_Int Added; /* Entity is spawned in the current world */
|
||||||
struct Event_Int Removed; /* Entity is despawned from the current world */
|
struct Event_Int Removed; /* Entity is despawned from the current world */
|
||||||
|
@ -610,13 +610,7 @@ void Game_Free(void* obj) {
|
|||||||
/* Most components will call OnContextLost in their Free functions */
|
/* Most components will call OnContextLost in their Free functions */
|
||||||
/* Set to false so components will always free managed textures too */
|
/* Set to false so components will always free managed textures too */
|
||||||
Gfx.ManagedTextures = false;
|
Gfx.ManagedTextures = false;
|
||||||
|
Event_UnregisterAll();
|
||||||
Event_UnregisterVoid(&WorldEvents.NewMap, NULL, HandleOnNewMap);
|
|
||||||
Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, HandleOnNewMapLoaded);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.LowVRAMDetected, NULL, HandleLowVRAMDetected);
|
|
||||||
|
|
||||||
Event_UnregisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
|
|
||||||
Event_UnregisterVoid(&WindowEvents.Closing, NULL, Game_Free);
|
|
||||||
|
|
||||||
for (comp = comps_head; comp; comp = comp->next) {
|
for (comp = comps_head; comp; comp = comp->next) {
|
||||||
if (comp->Free) comp->Free();
|
if (comp->Free) comp->Free();
|
||||||
|
@ -421,15 +421,6 @@ static void OnReset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged);
|
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
|
||||||
Event_UnregisterInt(&InputEvents.Press, NULL, OnKeyPress);
|
|
||||||
#ifdef CC_BUILD_TOUCH
|
|
||||||
Event_UnregisterString(&InputEvents.TextChanged, NULL, OnTextChanged);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
||||||
|
|
||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
|
@ -245,13 +245,6 @@ static void OnInit(void) {
|
|||||||
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
|
|
||||||
Event_UnregisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
|
|
||||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent HeldBlockRenderer_Component = {
|
struct IGameComponent HeldBlockRenderer_Component = {
|
||||||
OnInit, /* Init */
|
OnInit /* Init */
|
||||||
OnFree /* Free */
|
|
||||||
};
|
};
|
||||||
|
@ -791,21 +791,9 @@ static void OnInit(void) {
|
|||||||
CalcViewDists();
|
CalcViewDists();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
|
||||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, OnTerrainAtlasChanged);
|
|
||||||
Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, OnEnvVariableChanged);
|
|
||||||
Event_UnregisterVoid(&BlockEvents.BlockDefChanged, NULL, OnBlockDefinitionChanged);
|
|
||||||
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, OnVisibilityChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, OnVisibilityChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, DeleteChunks_);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Refresh_);
|
|
||||||
OnNewMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent MapRenderer_Component = {
|
struct IGameComponent MapRenderer_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
OnFree, /* Free */
|
OnNewMap, /* Free */
|
||||||
OnNewMap, /* Reset */
|
OnNewMap, /* Reset */
|
||||||
OnNewMap, /* OnNewMap */
|
OnNewMap, /* OnNewMap */
|
||||||
OnNewMapLoaded /* OnNewMapLoaded */
|
OnNewMapLoaded /* OnNewMapLoaded */
|
||||||
|
@ -2135,10 +2135,6 @@ static void OnInit(void) {
|
|||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
Models_ContextLost(NULL);
|
Models_ContextLost(NULL);
|
||||||
CustomModel_FreeAll();
|
CustomModel_FreeAll();
|
||||||
|
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnReset(void) { CustomModel_FreeAll(); }
|
static void OnReset(void) { CustomModel_FreeAll(); }
|
||||||
|
@ -608,14 +608,7 @@ static void OnInit(void) {
|
|||||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) { OnContextLost(NULL); }
|
||||||
OnContextLost(NULL);
|
|
||||||
|
|
||||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
|
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnReset(void) { rain_count = 0; terrain_count = 0; custom_count = 0; }
|
static void OnReset(void) { rain_count = 0; terrain_count = 0; custom_count = 0; }
|
||||||
|
|
||||||
|
@ -118,11 +118,7 @@ static void OnInit(void) {
|
|||||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) { OnContextLost(NULL); }
|
||||||
OnContextLost(NULL);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent PickedPosRenderer_Component = {
|
struct IGameComponent PickedPosRenderer_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
|
@ -219,15 +219,9 @@ static void OnInit(void) {
|
|||||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
|
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnReset(void) {
|
static void OnReset(void) { selections_count = 0; }
|
||||||
selections_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) { Selections_ContextLost(NULL); }
|
||||||
Selections_ContextLost(NULL);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct IGameComponent Selections_Component = {
|
struct IGameComponent Selections_Component = {
|
||||||
OnInit, /* Init */
|
OnInit, /* Init */
|
||||||
|
@ -451,10 +451,6 @@ static void OnInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, OnContextLost);
|
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
|
|
||||||
|
|
||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
Atlas2D_Free();
|
Atlas2D_Free();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user