Improve event API

This commit is contained in:
UnknownShadow200 2018-12-27 08:36:50 +11:00
parent a52f45a5ca
commit a89acea84d
36 changed files with 351 additions and 389 deletions

View File

@ -546,14 +546,14 @@ static void AudioManager_Init(void) {
Audio_SetMusic(volume); Audio_SetMusic(volume);
volume = AudioManager_GetVolume(OPT_SOUND_VOLUME, OPT_USE_SOUND); volume = AudioManager_GetVolume(OPT_SOUND_VOLUME, OPT_USE_SOUND);
Audio_SetSounds(volume); Audio_SetSounds(volume);
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, Audio_PlayBlockSound); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
} }
static void AudioManager_Free(void) { static void AudioManager_Free(void) {
Music_Free(); Music_Free();
Sounds_Free(); Sounds_Free();
Waitable_Free(music_waitable); Waitable_Free(music_waitable);
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, Audio_PlayBlockSound); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
} }
struct IGameComponent Audio_Component = { struct IGameComponent Audio_Component = {

View File

@ -65,12 +65,12 @@ static void AxisLinesRenderer_ContextLost(void* obj) {
} }
static void AxisLinesRenderer_Init(void) { static void AxisLinesRenderer_Init(void) {
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, AxisLinesRenderer_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, AxisLinesRenderer_ContextLost);
} }
static void AxisLinesRenderer_Free(void) { static void AxisLinesRenderer_Free(void) {
AxisLinesRenderer_ContextLost(NULL); AxisLinesRenderer_ContextLost(NULL);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, AxisLinesRenderer_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, AxisLinesRenderer_ContextLost);
} }
struct IGameComponent AxisLinesRenderer_Component = { struct IGameComponent AxisLinesRenderer_Component = {

View File

@ -198,7 +198,7 @@ void Block_DefineCustom(BlockID block) {
Inventory_AddDefault(block); Inventory_AddDefault(block);
Block_SetCustomDefined(block, true); Block_SetCustomDefined(block, true);
Event_RaiseVoid(&BlockEvents_BlockDefChanged); Event_RaiseVoid(&BlockEvents.BlockDefChanged);
} }
static void Block_RecalcIsLiquid(BlockID b) { static void Block_RecalcIsLiquid(BlockID b) {
@ -693,7 +693,7 @@ static void Blocks_Init(void) {
AutoRotate_Enabled = true; AutoRotate_Enabled = true;
Blocks_Reset(); Blocks_Reset();
Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, Blocks_AtlasChanged); Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, Blocks_AtlasChanged);
Block_CanPlace[BLOCK_AIR] = false; Block_CanDelete[BLOCK_AIR] = false; Block_CanPlace[BLOCK_AIR] = false; Block_CanDelete[BLOCK_AIR] = false;
Block_CanPlace[BLOCK_LAVA] = false; Block_CanDelete[BLOCK_LAVA] = false; Block_CanPlace[BLOCK_LAVA] = false; Block_CanDelete[BLOCK_LAVA] = false;
@ -704,7 +704,7 @@ static void Blocks_Init(void) {
} }
static void Blocks_Free(void) { static void Blocks_Free(void) {
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, Blocks_AtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, Blocks_AtlasChanged);
} }
struct IGameComponent Blocks_Component = { struct IGameComponent Blocks_Component = {

View File

@ -514,7 +514,7 @@ static void Physics_HandleTnt(int index, BlockID block) {
} }
void Physics_Init(void) { void Physics_Init(void) {
Event_RegisterVoid(&WorldEvents_MapLoaded, NULL, Physics_OnNewMapLoaded); Event_RegisterVoid(&WorldEvents.MapLoaded, NULL, Physics_OnNewMapLoaded);
Physics_Enabled = Options_GetBool(OPT_BLOCK_PHYSICS, true); Physics_Enabled = Options_GetBool(OPT_BLOCK_PHYSICS, true);
TickQueue_Init(&physics_lavaQ); TickQueue_Init(&physics_lavaQ);
TickQueue_Init(&physics_waterQ); TickQueue_Init(&physics_waterQ);
@ -557,7 +557,7 @@ void Physics_Init(void) {
} }
void Physics_Free(void) { void Physics_Free(void) {
Event_UnregisterVoid(&WorldEvents_MapLoaded, NULL, Physics_OnNewMapLoaded); Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, Physics_OnNewMapLoaded);
} }
void Physics_Tick(void) { void Physics_Tick(void) {

View File

@ -177,7 +177,7 @@ void Chat_AddRaw(const char* raw) {
void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); } void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }
void Chat_AddOf(const String* text, MsgType type) { void Chat_AddOf(const String* text, MsgType type) {
Event_RaiseChat(&ChatEvents_ChatReceived, text, type); Event_RaiseChat(&ChatEvents.ChatReceived, text, type);
if (type == MSG_TYPE_NORMAL) { if (type == MSG_TYPE_NORMAL) {
StringsBuffer_Add(&Chat_Log, text); StringsBuffer_Add(&Chat_Log, text);
@ -476,7 +476,7 @@ static void CuboidCommand_BlockChanged(void* obj, Vector3I coords, BlockID old,
CuboidCommand_DoCuboid(); CuboidCommand_DoCuboid();
if (!cuboid_persist) { if (!cuboid_persist) {
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, CuboidCommand_BlockChanged); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, CuboidCommand_BlockChanged);
cuboid_hooked = false; cuboid_hooked = false;
Chat_AddOf(&String_Empty, MSG_TYPE_CLIENTSTATUS_1); Chat_AddOf(&String_Empty, MSG_TYPE_CLIENTSTATUS_1);
} else { } else {
@ -488,7 +488,7 @@ static void CuboidCommand_BlockChanged(void* obj, Vector3I coords, BlockID old,
static void CuboidCommand_Execute(const String* args, int argsCount) { static void CuboidCommand_Execute(const String* args, int argsCount) {
if (cuboid_hooked) { if (cuboid_hooked) {
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, CuboidCommand_BlockChanged); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, CuboidCommand_BlockChanged);
cuboid_hooked = false; cuboid_hooked = false;
} }
@ -503,7 +503,7 @@ static void CuboidCommand_Execute(const String* args, int argsCount) {
} }
Chat_AddOf(&cuboid_msg, MSG_TYPE_CLIENTSTATUS_1); Chat_AddOf(&cuboid_msg, MSG_TYPE_CLIENTSTATUS_1);
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, CuboidCommand_BlockChanged); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, CuboidCommand_BlockChanged);
cuboid_hooked = true; cuboid_hooked = true;
} }
@ -554,7 +554,7 @@ static struct ChatCommand TeleportCommand_Instance = {
*#########################################################################################################################*/ *#########################################################################################################################*/
void Chat_Send(const String* text, bool logUsage) { void Chat_Send(const String* text, bool logUsage) {
if (!text->length) return; if (!text->length) return;
Event_RaiseChat(&ChatEvents_ChatSending, text, 0); Event_RaiseChat(&ChatEvents.ChatSending, text, 0);
if (logUsage) StringsBuffer_Add(&Chat_InputLog, text); if (logUsage) StringsBuffer_Add(&Chat_InputLog, text);
if (Commands_IsCommandPrefix(text)) { if (Commands_IsCommandPrefix(text)) {

View File

@ -49,13 +49,13 @@ CC_API void Commands_Register(struct ChatCommand* cmd);
/* Sets the name of log file (no .txt, so e.g. just "singleplayer") */ /* Sets the name of log file (no .txt, so e.g. just "singleplayer") */
/* NOTE: This can only be set once. */ /* NOTE: This can only be set once. */
void Chat_SetLogName(const String* name); void Chat_SetLogName(const String* name);
/* Sends a chat message, raising ChatEvents_ChatSending event. */ /* Sends a chat message, raising ChatEvents.ChatSending event. */
/* NOTE: /client is always interpreted as client-side commands. */ /* NOTE: /client is always interpreted as client-side commands. */
/* In multiplayer this is sent to the server, in singleplayer just Chat_Add. */ /* In multiplayer this is sent to the server, in singleplayer just Chat_Add. */
CC_API void Chat_Send(const String* text, bool logUsage); CC_API void Chat_Send(const String* text, bool logUsage);
/* Shorthand for Chat_AddOf(str, MSG_TYPE_NORMAL) */ /* Shorthand for Chat_AddOf(str, MSG_TYPE_NORMAL) */
CC_API void Chat_Add(const String* text); CC_API void Chat_Add(const String* text);
/* Adds a chat message, raising ChatEvents_ChatReceived event. */ /* Adds a chat message, raising ChatEvents.ChatReceived event. */
/* MSG_TYPE_NORMAL is usually used for player chat and command messages. */ /* MSG_TYPE_NORMAL is usually used for player chat and command messages. */
/* Other message types are usually used for info/status messages. */ /* Other message types are usually used for info/status messages. */
CC_API void Chat_AddOf(const String* text, MsgType type); CC_API void Chat_AddOf(const String* text, MsgType type);

View File

@ -683,7 +683,7 @@ static void Drawer2D_TextureChanged(void* obj, struct Stream* src, const String*
Mem_Free(bmp.Scan0); Mem_Free(bmp.Scan0);
} else { } else {
Drawer2D_SetFontBitmap(&bmp); Drawer2D_SetFontBitmap(&bmp);
Event_RaiseVoid(&ChatEvents_FontChanged); Event_RaiseVoid(&ChatEvents.FontChanged);
} }
} }
@ -721,12 +721,12 @@ static void Drawer2D_Init(void) {
} }
Drawer2D_CheckFont(); Drawer2D_CheckFont();
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Drawer2D_TextureChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Drawer2D_TextureChanged);
} }
static void Drawer2D_Free(void) { static void Drawer2D_Free(void) {
Drawer2D_FreeFontBitmap(); Drawer2D_FreeFontBitmap();
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Drawer2D_TextureChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Drawer2D_TextureChanged);
} }
struct IGameComponent Drawer2D_Component = { struct IGameComponent Drawer2D_Component = {

View File

@ -326,7 +326,7 @@ static void Entities_ChatFontChanged(void* obj) {
} }
void Entities_Remove(EntityID id) { void Entities_Remove(EntityID id) {
Event_RaiseInt(&EntityEvents_Removed, id); Event_RaiseInt(&EntityEvents.Removed, id);
Entities_List[id]->VTABLE->Despawn(Entities_List[id]); Entities_List[id]->VTABLE->Despawn(Entities_List[id]);
Entities_List[id] = NULL; Entities_List[id] = NULL;
} }
@ -1105,9 +1105,9 @@ void NetPlayer_Init(struct NetPlayer* p, const String* displayName, const String
*--------------------------------------------------------Entities---------------------------------------------------------* *--------------------------------------------------------Entities---------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Entities_Init(void) { static void Entities_Init(void) {
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Entities_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Entities_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Entities_ContextRecreated);
Event_RegisterVoid(&ChatEvents_FontChanged, NULL, Entities_ChatFontChanged); Event_RegisterVoid(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged);
Entities_NameMode = Options_GetEnum(OPT_NAMES_MODE, NAME_MODE_HOVERED, Entities_NameMode = Options_GetEnum(OPT_NAMES_MODE, NAME_MODE_HOVERED,
NameMode_Names, Array_Elems(NameMode_Names)); NameMode_Names, Array_Elems(NameMode_Names));
@ -1128,9 +1128,9 @@ static void Entities_Free(void) {
Entities_Remove((EntityID)i); Entities_Remove((EntityID)i);
} }
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Entities_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Entities_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Entities_ContextRecreated);
Event_UnregisterVoid(&ChatEvents_FontChanged, NULL, Entities_ChatFontChanged); Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged);
if (ShadowComponent_ShadowTex) { if (ShadowComponent_ShadowTex) {
Gfx_DeleteTexture(&ShadowComponent_ShadowTex); Gfx_DeleteTexture(&ShadowComponent_ShadowTex);

View File

@ -291,7 +291,7 @@ void HacksComp_UpdateState(struct HacksComp* hacks) {
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks); hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
HacksComp_CheckConsistency(hacks); HacksComp_CheckConsistency(hacks);
Event_RaiseVoid(&UserEvents_HackPermissionsChanged); Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
} }

View File

@ -906,27 +906,27 @@ static void EnvRenderer_Init(void) {
EnvRenderer_Legacy = flags & ENV_LEGACY; EnvRenderer_Legacy = flags & ENV_LEGACY;
EnvRenderer_Minimal = flags & ENV_MINIMAL; EnvRenderer_Minimal = flags & ENV_MINIMAL;
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, EnvRenderer_FileChanged);
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, EnvRenderer_TexturePackChanged); Event_RegisterVoid(&TextureEvents.PackChanged, NULL, EnvRenderer_TexturePackChanged);
Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged); Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged); Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
Event_RegisterInt(&WorldEvents_EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged); Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, EnvRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, EnvRenderer_ContextRecreated);
Game_SetViewDistance(Game_UserViewDistance); Game_SetViewDistance(Game_UserViewDistance);
} }
static void EnvRenderer_Free(void) { static void EnvRenderer_Free(void) {
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, EnvRenderer_FileChanged);
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, EnvRenderer_TexturePackChanged); Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, EnvRenderer_TexturePackChanged);
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged); Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
Event_UnregisterInt(&WorldEvents_EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged); Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, EnvRenderer_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, EnvRenderer_ContextRecreated);
EnvRenderer_ContextLost(NULL); EnvRenderer_ContextLost(NULL);
Mem_Free(Weather_Heightmap); Mem_Free(Weather_Heightmap);

View File

@ -1,58 +1,19 @@
#include "Event.h" #include "Event.h"
#include "Logger.h" #include "Logger.h"
struct Event_Int EntityEvents_Added; struct _EntityEventsList EntityEvents;
struct Event_Int EntityEvents_Removed; struct _TabListEventsList TabListEvents;
struct Event_Int TabListEvents_Added; struct _TextureEventsList TextureEvents;
struct Event_Int TabListEvents_Changed; struct _GfxEventsList GfxEvents;
struct Event_Int TabListEvents_Removed; struct _UserEventsList UserEvents;
struct _BlockEventsList BlockEvents;
struct _WorldEventsList WorldEvents;
struct _ChatEventsList ChatEvents;
struct _WindowEventsList WindowEvents;
struct _KeyEventsList KeyEvents;
struct _MouseEventsList MouseEvents;
struct Event_Void TextureEvents_AtlasChanged; void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
struct Event_Void TextureEvents_PackChanged;
struct Event_Entry TextureEvents_FileChanged;
struct Event_Void GfxEvents_ViewDistanceChanged;
struct Event_Void GfxEvents_LowVRAMDetected;
struct Event_Void GfxEvents_ProjectionChanged;
struct Event_Void GfxEvents_ContextLost;
struct Event_Void GfxEvents_ContextRecreated;
struct Event_Block UserEvents_BlockChanged;
struct Event_Void UserEvents_HackPermissionsChanged;
struct Event_Void UserEvents_HeldBlockChanged;
struct Event_Void BlockEvents_PermissionsChanged;
struct Event_Void BlockEvents_BlockDefChanged;
struct Event_Void WorldEvents_NewMap;
struct Event_Float WorldEvents_Loading;
struct Event_Void WorldEvents_MapLoaded;
struct Event_Int WorldEvents_EnvVarChanged;
struct Event_Void ChatEvents_FontChanged;
struct Event_Chat ChatEvents_ChatReceived;
struct Event_Chat ChatEvents_ChatSending;
struct Event_Int ChatEvents_ColCodeChanged;
struct Event_Void WindowEvents_Redraw;
struct Event_Void WindowEvents_Moved;
struct Event_Void WindowEvents_Resized;
struct Event_Void WindowEvents_Closing;
struct Event_Void WindowEvents_Closed;
struct Event_Void WindowEvents_VisibilityChanged;
struct Event_Void WindowEvents_FocusChanged;
struct Event_Void WindowEvents_StateChanged;
struct Event_Int KeyEvents_Press;
struct Event_Int KeyEvents_Down;
struct Event_Int KeyEvents_Up;
struct Event_MouseMove MouseEvents_Moved;
struct Event_Int MouseEvents_Down;
struct Event_Int MouseEvents_Up;
struct Event_Float MouseEvents_Wheel;
static void Event_RegisterImpl(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
int i; int i;
for (i = 0; i < handlers->Count; i++) { for (i = 0; i < handlers->Count; i++) {
if (handlers->Handlers[i] == handler && handlers->Objs[i] == obj) { if (handlers->Handlers[i] == handler && handlers->Objs[i] == obj) {
@ -69,7 +30,7 @@ static void Event_RegisterImpl(struct Event_Void* handlers, void* obj, Event_Voi
} }
} }
static void Event_UnregisterImpl(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) { void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
int i, j; int i, j;
for (i = 0; i < handlers->Count; i++) { for (i = 0; i < handlers->Count; i++) {
if (handlers->Handlers[i] != handler || handlers->Objs[i] != obj) continue; if (handlers->Handlers[i] != handler || handlers->Objs[i] != obj) continue;
@ -94,12 +55,6 @@ void Event_RaiseVoid(struct Event_Void* handlers) {
handlers->Handlers[i](handlers->Objs[i]); handlers->Handlers[i](handlers->Objs[i]);
} }
} }
void Event_RegisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
Event_RegisterImpl(handlers, obj, handler);
}
void Event_UnregisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
Event_UnregisterImpl(handlers, obj, handler);
}
void Event_RaiseInt(struct Event_Int* handlers, int arg) { void Event_RaiseInt(struct Event_Int* handlers, int arg) {
int i; int i;
@ -107,12 +62,6 @@ void Event_RaiseInt(struct Event_Int* handlers, int arg) {
handlers->Handlers[i](handlers->Objs[i], arg); handlers->Handlers[i](handlers->Objs[i], arg);
} }
} }
void Event_RegisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_RaiseFloat(struct Event_Float* handlers, float arg) { void Event_RaiseFloat(struct Event_Float* handlers, float arg) {
int i; int i;
@ -120,13 +69,6 @@ void Event_RaiseFloat(struct Event_Float* handlers, float arg) {
handlers->Handlers[i](handlers->Objs[i], arg); handlers->Handlers[i](handlers->Objs[i], arg);
} }
} }
void Event_RegisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const String* name) { void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const String* name) {
int i; int i;
@ -134,12 +76,6 @@ void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const
handlers->Handlers[i](handlers->Objs[i], stream, name); handlers->Handlers[i](handlers->Objs[i], stream, name);
} }
} }
void Event_RegisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_RaiseBlock(struct Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block) { void Event_RaiseBlock(struct Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block) {
int i; int i;
@ -147,12 +83,6 @@ void Event_RaiseBlock(struct Event_Block* handlers, Vector3I coords, BlockID old
handlers->Handlers[i](handlers->Objs[i], coords, oldBlock, block); handlers->Handlers[i](handlers->Objs[i], coords, oldBlock, block);
} }
} }
void Event_RegisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_RaiseMouseMove(struct Event_MouseMove* handlers, int xDelta, int yDelta) { void Event_RaiseMouseMove(struct Event_MouseMove* handlers, int xDelta, int yDelta) {
int i; int i;
@ -160,12 +90,6 @@ void Event_RaiseMouseMove(struct Event_MouseMove* handlers, int xDelta, int yDel
handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta); handlers->Handlers[i](handlers->Objs[i], xDelta, yDelta);
} }
} }
void Event_RegisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_RaiseChat(struct Event_Chat* handlers, const String* msg, int msgType) { void Event_RaiseChat(struct Event_Chat* handlers, const String* msg, int msgType) {
int i; int i;
@ -173,9 +97,3 @@ void Event_RaiseChat(struct Event_Chat* handlers, const String* msg, int msgType
handlers->Handlers[i](handlers->Objs[i], msg, msgType); handlers->Handlers[i](handlers->Objs[i], msg, msgType);
} }
} }
void Event_RegisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler) {
Event_RegisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}
void Event_UnregisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler) {
Event_UnregisterImpl((struct Event_Void*)handlers, obj, (Event_Void_Callback)handler);
}

View File

@ -2,11 +2,11 @@
#define CC_EVENT_H #define CC_EVENT_H
#include "String.h" #include "String.h"
#include "Vectors.h" #include "Vectors.h"
/* Helper method for managing events, and contains all events. /* Helper methods for using events, and contains all events.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/ */
/* Maximum number of event handlers that can be registered. */ /* Max callbacks that can be registered for an event. */
#define EVENT_MAX_CALLBACKS 32 #define EVENT_MAX_CALLBACKS 32
struct Stream; struct Stream;
@ -52,82 +52,126 @@ struct Event_Chat {
void* Objs[EVENT_MAX_CALLBACKS]; int Count; void* Objs[EVENT_MAX_CALLBACKS]; int Count;
}; };
void Event_RaiseVoid(struct Event_Void* handlers); /* Registers a callback function for the given event. */
void Event_RegisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler); /* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
void Event_UnregisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler); CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
/* Unregisters a callback function for the given event. */
/* NOTE: Trying to unregister a non-registered callback will terminate the game. */
CC_API void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
#define Event_RegisterMacro(handlers, obj, handler) Event_Register((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
#define Event_UnregisterMacro(handlers, obj, handler) Event_Unregister((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
void Event_RaiseInt(struct Event_Int* handlers, int arg); /* Calls all registered callback for an event with no arguments. */
void Event_RegisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler); CC_API void Event_RaiseVoid(struct Event_Void* handlers);
void Event_UnregisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler); #define Event_RegisterVoid(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
#define Event_UnregisterVoid(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
void Event_RaiseFloat(struct Event_Float* handlers, float arg); /* Calls all registered callback for an event which has an int argument. */
void Event_RegisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler); /* NOTE: The actual argument "type" may be char, Key, uint8_t etc */
void Event_UnregisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler); CC_API void Event_RaiseInt(struct Event_Int* handlers, int arg);
#define Event_RegisterInt(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
#define Event_UnregisterInt(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
/* Calls all registered callbacks for an event which has a float argument. */
CC_API void Event_RaiseFloat(struct Event_Float* handlers, float arg);
#define Event_RegisterFloat(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
#define Event_UnregisterFloat(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
/* Calls all registered callbacks for an event which has data stream and name argumenst. */
/* This is (currently) only used for processing entries from default.zip */
void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const String* name); void Event_RaiseEntry(struct Event_Entry* handlers, struct Stream* stream, const String* name);
void Event_RegisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler); #define Event_RegisterEntry(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
void Event_UnregisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler); #define Event_UnregisterEntry(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
/* Calls all registered callbacks for an event which takes block change arguments. */
/* These are the coordinates/location of the change, block there before, block there now. */
void Event_RaiseBlock(struct Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block); void Event_RaiseBlock(struct Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block);
void Event_RegisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler); #define Event_RegisterBlock(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
void Event_UnregisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler); #define Event_UnregisterBlock(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
/* Calls all registered callbacks for an event which has mouse movement arguments. */
/* This is simply delta since last move. Use Mouse_X and Mouse_Y to get the mouse position. */
void Event_RaiseMouseMove(struct Event_MouseMove* handlers, int xDelta, int yDelta); void Event_RaiseMouseMove(struct Event_MouseMove* handlers, int xDelta, int yDelta);
void Event_RegisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler); #define Event_RegisterMouseMove(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
void Event_UnregisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler); #define Event_UnregisterMouseMove(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
/* Calls all registered callbacks for an event which has chat message type and contents. */
/* See MsgType enum in Chat.h for what types of messages there are. */
void Event_RaiseChat(struct Event_Chat* handlers, const String* msg, int msgType); void Event_RaiseChat(struct Event_Chat* handlers, const String* msg, int msgType);
void Event_RegisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler); #define Event_RegisterChat(handlers, obj, handler) Event_RegisterMacro(handlers, obj, handler)
void Event_UnregisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler); #define Event_UnregisterChat(handlers, obj, handler) Event_UnregisterMacro(handlers, obj, handler)
extern struct Event_Int EntityEvents_Added; /* Entity is spawned in the current world */ extern struct _EntityEventsList {
extern struct Event_Int EntityEvents_Removed; /* Entity is despawned from the current world */ struct Event_Int Added; /* Entity is spawned in the current world */
extern struct Event_Int TabListEvents_Added; /* Tab list entry is created */ struct Event_Int Removed; /* Entity is despawned from the current world */
extern struct Event_Int TabListEvents_Changed; /* Tab list entry is modified */ } EntityEvents;
extern struct Event_Int TabListEvents_Removed; /* Tab list entry is removed */
extern struct Event_Void TextureEvents_AtlasChanged; /* Terrain atlas (terrain.png) is changed */ extern struct _TabListEventsList {
extern struct Event_Void TextureEvents_PackChanged; /* Texture pack is changed */ struct Event_Int Added; /* Tab list entry is created */
extern struct Event_Entry TextureEvents_FileChanged; /* File in a texture pack is changed (terrain.png, rain.png) */ struct Event_Int Changed; /* Tab list entry is modified */
struct Event_Int Removed; /* Tab list entry is removed */
} TabListEvents;
extern struct Event_Void GfxEvents_ViewDistanceChanged; /* View/fog distance is changed */ extern struct _TextureEventsList {
extern struct Event_Void GfxEvents_LowVRAMDetected; /* Insufficient VRAM detected, need to free some GPU resources */ struct Event_Void AtlasChanged; /* Terrain atlas (terrain.png) is changed */
extern struct Event_Void GfxEvents_ProjectionChanged; /* Projection matrix has changed */ struct Event_Void PackChanged; /* Texture pack is changed */
extern struct Event_Void GfxEvents_ContextLost; /* Context is destroyed after having been previously created */ struct Event_Entry FileChanged; /* File in a texture pack is changed (terrain.png, rain.png) */
extern struct Event_Void GfxEvents_ContextRecreated; /* Context is recreated after having been previously lost */ } TextureEvents;
extern struct Event_Block UserEvents_BlockChanged; /* User changes a block */ extern struct _GfxEventsList {
extern struct Event_Void UserEvents_HackPermissionsChanged; /* Hack permissions of the player changes */ struct Event_Void ViewDistanceChanged; /* View/fog distance is changed */
extern struct Event_Void UserEvents_HeldBlockChanged; /* Held block in hotbar changes */ struct Event_Void LowVRAMDetected; /* Insufficient VRAM detected, need to free some GPU resources */
struct Event_Void ProjectionChanged; /* Projection matrix has changed */
struct Event_Void ContextLost; /* Context is destroyed after having been previously created */
struct Event_Void ContextRecreated; /* Context is recreated after having been previously lost */
} GfxEvents;
extern struct Event_Void BlockEvents_PermissionsChanged; /* Block permissions (can place/delete) for a block changes */ extern struct _UserEventsList {
extern struct Event_Void BlockEvents_BlockDefChanged; /* Block definition is changed or removed */ struct Event_Block BlockChanged; /* User changes a block */
struct Event_Void HackPermissionsChanged; /* Hack permissions of the player changes */
struct Event_Void HeldBlockChanged; /* Held block in hotbar changes */
} UserEvents;
extern struct Event_Void WorldEvents_NewMap; /* Player begins loading a new world */ extern struct _BlockEventsList {
extern struct Event_Float WorldEvents_Loading; /* Portion of world is decompressed/generated (Arg is progress from 0-1) */ struct Event_Void PermissionsChanged; /* Block permissions (can place/delete) for a block changes */
extern struct Event_Void WorldEvents_MapLoaded; /* New world has finished loading, player can now interact with it */ struct Event_Void BlockDefChanged; /* Block definition is changed or removed */
extern struct Event_Int WorldEvents_EnvVarChanged; /* World environment variable changed by player/CPE/WoM config */ } BlockEvents;
extern struct Event_Void ChatEvents_FontChanged; /* User changes whether system chat font used, and when the bitmapped font texture changes */ extern struct _WorldEventsList {
extern struct Event_Chat ChatEvents_ChatReceived; /* Raised when message is being added to chat */ struct Event_Void NewMap; /* Player begins loading a new world */
extern struct Event_Chat ChatEvents_ChatSending; /* Raised when user sends a message */ struct Event_Float Loading; /* Portion of world is decompressed/generated (Arg is progress from 0-1) */
extern struct Event_Int ChatEvents_ColCodeChanged; /* Raised when a colour code changes */ struct Event_Void MapLoaded; /* New world has finished loading, player can now interact with it */
struct Event_Int EnvVarChanged; /* World environment variable changed by player/CPE/WoM config */
} WorldEvents;
extern struct Event_Void WindowEvents_Redraw; /* Window contents invalidated, should be redrawn */ extern struct _ChatEventsList {
extern struct Event_Void WindowEvents_Moved; /* Window is moved */ struct Event_Void FontChanged; /* User changes whether system chat font used, and when the bitmapped font texture changes */
extern struct Event_Void WindowEvents_Resized; /* Window is resized */ struct Event_Chat ChatReceived; /* Raised when message is being added to chat */
extern struct Event_Void WindowEvents_Closing; /* Window is about to close */ struct Event_Chat ChatSending; /* Raised when user sends a message */
extern struct Event_Void WindowEvents_Closed; /* Window has closed */ struct Event_Int ColCodeChanged; /* Raised when a colour code changes */
extern struct Event_Void WindowEvents_VisibilityChanged; /* Visibility of the window changed */ } ChatEvents;
extern struct Event_Void WindowEvents_FocusChanged; /* Focus of the window changed */
extern struct Event_Void WindowEvents_StateChanged; /* WindowState of the window changed */
extern struct Event_Int KeyEvents_Press; /* Raised when a character is typed. Arg is a character */ extern struct _WindowEventsList {
extern struct Event_Int KeyEvents_Down; /* Raised when a key is pressed. Arg is a member of Key enumeration */ struct Event_Void Redraw; /* Window contents invalidated, should be redrawn */
extern struct Event_Int KeyEvents_Up; /* Raised when a key is released. Arg is a member of Key enumeration */ struct Event_Void Moved; /* Window is moved */
struct Event_Void Resized; /* Window is resized */
struct Event_Void Closing; /* Window is about to close */
struct Event_Void Closed; /* Window has closed */
struct Event_Void VisibilityChanged; /* Visibility of the window changed */
struct Event_Void FocusChanged; /* Focus of the window changed */
struct Event_Void StateChanged; /* WindowState of the window changed */
} WindowEvents;
extern struct Event_MouseMove MouseEvents_Moved; /* Mouse position is changed (Arg is delta from last position) */ struct _KeyEventsList {
extern struct Event_Int MouseEvents_Down; /* Mouse button is pressed (Arg is MouseButton member) */ struct Event_Int Press; /* Raised when a character is typed. Arg is a character */
extern struct Event_Int MouseEvents_Up; /* Mouse button is released (Arg is MouseButton member) */ struct Event_Int Down; /* Raised when a key is pressed. Arg is a member of Key enumeration */
extern struct Event_Float MouseEvents_Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */ struct Event_Int Up; /* Raised when a key is released. Arg is a member of Key enumeration */
} KeyEvents;
extern struct _MouseEventsList {
struct Event_MouseMove Moved; /* Mouse position is changed (Arg is delta from last position) */
struct Event_Int Down; /* Mouse button is pressed (Arg is MouseButton member) */
struct Event_Int Up; /* Mouse button is released (Arg is MouseButton member) */
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
} MouseEvents;
#endif #endif

View File

@ -60,7 +60,7 @@ void Map_LoadFrom(const String* path) {
ReturnCode res; ReturnCode res;
World_Reset(); World_Reset();
Event_RaiseVoid(&WorldEvents_NewMap); Event_RaiseVoid(&WorldEvents.NewMap);
Game_Reset(); Game_Reset();
res = Stream_OpenFile(&stream, path); res = Stream_OpenFile(&stream, path);
@ -76,7 +76,7 @@ void Map_LoadFrom(const String* path) {
if (res) { Logger_Warn2(res, "closing", path); } if (res) { Logger_Warn2(res, "closing", path); }
World_SetNewMap(World_Blocks, World_BlocksSize, World_Width, World_Height, World_Length); World_SetNewMap(World_Blocks, World_BlocksSize, World_Width, World_Height, World_Length);
Event_RaiseVoid(&WorldEvents_MapLoaded); Event_RaiseVoid(&WorldEvents.MapLoaded);
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnRotY, p->SpawnHeadX, false); LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnRotY, p->SpawnHeadX, false);
p->Base.VTABLE->SetLocation(&p->Base, &update, false); p->Base.VTABLE->SetLocation(&p->Base, &update, false);
@ -527,7 +527,7 @@ static void Cw_Callback_4(struct NbtTag* tag) {
Block_DefineCustom(id); Block_DefineCustom(id);
Block_CanPlace[id] = true; Block_CanPlace[id] = true;
Block_CanDelete[id] = true; Block_CanDelete[id] = true;
Event_RaiseVoid(&BlockEvents_PermissionsChanged); Event_RaiseVoid(&BlockEvents.PermissionsChanged);
cw_curID = 0; cw_curID = 0;
} }

View File

@ -148,7 +148,7 @@ bool Game_ChangeTerrainAtlas(Bitmap* atlas) {
Atlas_Free(); Atlas_Free();
Atlas_Update(atlas); Atlas_Update(atlas);
Event_RaiseVoid(&TextureEvents_AtlasChanged); Event_RaiseVoid(&TextureEvents.AtlasChanged);
return true; return true;
} }
@ -157,7 +157,7 @@ void Game_SetViewDistance(int distance) {
if (distance == Game_ViewDistance) return; if (distance == Game_ViewDistance) return;
Game_ViewDistance = distance; Game_ViewDistance = distance;
Event_RaiseVoid(&GfxEvents_ViewDistanceChanged); Event_RaiseVoid(&GfxEvents.ViewDistanceChanged);
Game_UpdateProjection(); Game_UpdateProjection();
} }
@ -172,12 +172,12 @@ void Game_UpdateProjection(void) {
Camera_Active->GetProjection(&Gfx_Projection); Camera_Active->GetProjection(&Gfx_Projection);
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection); Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection);
Event_RaiseVoid(&GfxEvents_ProjectionChanged); Event_RaiseVoid(&GfxEvents.ProjectionChanged);
} }
void Game_Disconnect(const String* title, const String* reason) { void Game_Disconnect(const String* title, const String* reason) {
World_Reset(); World_Reset();
Event_RaiseVoid(&WorldEvents_NewMap); Event_RaiseVoid(&WorldEvents.NewMap);
Gui_FreeActive(); Gui_FreeActive();
Gui_SetActive(DisconnectScreen_MakeInstance(title, reason)); Gui_SetActive(DisconnectScreen_MakeInstance(title, reason));
Game_Reset(); Game_Reset();
@ -438,13 +438,13 @@ static void Game_Load(void) {
Game_UpdateClientSize(); Game_UpdateClientSize();
Game_LoadOptions(); Game_LoadOptions();
Event_RegisterVoid(&WorldEvents_NewMap, NULL, Game_OnNewMapCore); Event_RegisterVoid(&WorldEvents.NewMap, NULL, Game_OnNewMapCore);
Event_RegisterVoid(&WorldEvents_MapLoaded, NULL, Game_OnNewMapLoadedCore); Event_RegisterVoid(&WorldEvents.MapLoaded, NULL, Game_OnNewMapLoadedCore);
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Game_TextureChangedCore); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Game_TextureChangedCore);
Event_RegisterVoid(&GfxEvents_LowVRAMDetected, NULL, Game_OnLowVRAMDetected); Event_RegisterVoid(&GfxEvents.LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
Event_RegisterVoid(&WindowEvents_Resized, NULL, Game_OnResize); Event_RegisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
Event_RegisterVoid(&WindowEvents_Closed, NULL, Game_Free); Event_RegisterVoid(&WindowEvents.Closed, NULL, Game_Free);
TextureCache_Init(); TextureCache_Init();
/* TODO: Survival vs Creative game mode */ /* TODO: Survival vs Creative game mode */
@ -683,13 +683,13 @@ void Game_Free(void* obj) {
struct IGameComponent* comp; struct IGameComponent* comp;
Atlas_Free(); Atlas_Free();
Event_UnregisterVoid(&WorldEvents_NewMap, NULL, Game_OnNewMapCore); Event_UnregisterVoid(&WorldEvents.NewMap, NULL, Game_OnNewMapCore);
Event_UnregisterVoid(&WorldEvents_MapLoaded, NULL, Game_OnNewMapLoadedCore); Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, Game_OnNewMapLoadedCore);
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Game_TextureChangedCore); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Game_TextureChangedCore);
Event_UnregisterVoid(&GfxEvents_LowVRAMDetected, NULL, Game_OnLowVRAMDetected); Event_UnregisterVoid(&GfxEvents.LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
Event_UnregisterVoid(&WindowEvents_Resized, NULL, Game_OnResize); Event_UnregisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
Event_UnregisterVoid(&WindowEvents_Closed, NULL, Game_Free); Event_UnregisterVoid(&WindowEvents.Closed, 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();
@ -713,7 +713,7 @@ void Game_Run(int width, int height, const String* title) {
Window_SetVisible(true); Window_SetVisible(true);
Game_Load(); Game_Load();
Event_RaiseVoid(&WindowEvents_Resized); Event_RaiseVoid(&WindowEvents.Resized);
lastRender = Stopwatch_Measure(); lastRender = Stopwatch_Measure();
for (;;) { for (;;) {

View File

@ -61,7 +61,7 @@ void Gfx_LoseContext(const char* reason) {
Gfx_LostContext = true; Gfx_LostContext = true;
Platform_Log1("Lost graphics context: %c", reason); Platform_Log1("Lost graphics context: %c", reason);
Event_RaiseVoid(&GfxEvents_ContextLost); Event_RaiseVoid(&GfxEvents.ContextLost);
Gfx_FreeDefaultResources(); Gfx_FreeDefaultResources();
} }
@ -69,7 +69,7 @@ void Gfx_RecreateContext(void) {
Gfx_LostContext = false; Gfx_LostContext = false;
Platform_LogConst("Recreating graphics context"); Platform_LogConst("Recreating graphics context");
Event_RaiseVoid(&GfxEvents_ContextRecreated); Event_RaiseVoid(&GfxEvents.ContextRecreated);
Gfx_InitDefaultResources(); Gfx_InitDefaultResources();
} }
@ -733,7 +733,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
if (!res) break; if (!res) break;
if (res != D3DERR_OUTOFVIDEOMEMORY) Logger_Abort2(res, "D3D9_CreateVb"); if (res != D3DERR_OUTOFVIDEOMEMORY) Logger_Abort2(res, "D3D9_CreateVb");
Event_RaiseVoid(&GfxEvents_LowVRAMDetected); Event_RaiseVoid(&GfxEvents.LowVRAMDetected);
} }
D3D9_SetVbData(vbuffer, vertices, size, "D3D9_CreateVb - Lock", "D3D9_CreateVb - Unlock", 0); D3D9_SetVbData(vbuffer, vertices, size, "D3D9_CreateVb - Lock", "D3D9_CreateVb - Unlock", 0);

View File

@ -30,16 +30,16 @@ void Gui_DefaultRecreate(void* elem) {
void Screen_CommonInit(void* screen) { void Screen_CommonInit(void* screen) {
struct Screen* s = screen; struct Screen* s = screen;
Event_RegisterVoid(&GfxEvents_ContextLost, s, s->VTABLE->ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, s, s->VTABLE->ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, s, s->VTABLE->ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, s, s->VTABLE->ContextRecreated);
if (Gfx_LostContext) return; if (Gfx_LostContext) return;
s->VTABLE->ContextRecreated(s); s->VTABLE->ContextRecreated(s);
} }
void Screen_CommonFree(void* screen) { struct Screen* s = screen; void Screen_CommonFree(void* screen) { struct Screen* s = screen;
Event_UnregisterVoid(&GfxEvents_ContextLost, s, s->VTABLE->ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, s, s->VTABLE->ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, s, s->VTABLE->ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, s, s->VTABLE->ContextRecreated);
s->VTABLE->ContextLost(s); s->VTABLE->ContextLost(s);
} }
@ -121,8 +121,8 @@ static void Gui_FileChanged(void* obj, struct Stream* stream, const String* name
} }
static void Gui_Init(void) { static void Gui_Init(void) {
Event_RegisterVoid(&ChatEvents_FontChanged, NULL, Gui_FontChanged); Event_RegisterVoid(&ChatEvents.FontChanged, NULL, Gui_FontChanged);
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Gui_FileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Gui_FileChanged);
Gui_LoadOptions(); Gui_LoadOptions();
Gui_Status = StatusScreen_MakeInstance(); Gui_Status = StatusScreen_MakeInstance();
@ -140,8 +140,8 @@ static void Gui_Reset(void) {
} }
static void Gui_Free(void) { static void Gui_Free(void) {
Event_UnregisterVoid(&ChatEvents_FontChanged, NULL, Gui_FontChanged); Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Gui_FontChanged);
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Gui_FileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Gui_FileChanged);
Gui_CloseActive(); Gui_CloseActive();
Elem_TryFree(Gui_Status); Elem_TryFree(Gui_Status);
Elem_TryFree(Gui_HUD); Elem_TryFree(Gui_HUD);

View File

@ -241,15 +241,15 @@ static void HeldBlockRenderer_Init(void) {
HeldBlockRenderer_Show = Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true); HeldBlockRenderer_Show = Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true);
held_lastBlock = Inventory_SelectedBlock; held_lastBlock = Inventory_SelectedBlock;
Event_RegisterVoid(&GfxEvents_ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged); Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
Event_RegisterVoid(&UserEvents_HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim); Event_RegisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, HeldBlockRenderer_BlockChanged); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
} }
static void HeldBlockRenderer_Free(void) { static void HeldBlockRenderer_Free(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 = {

View File

@ -72,9 +72,9 @@ void Key_SetPressed(Key key, bool pressed) {
Key_Pressed[key] = pressed; Key_Pressed[key] = pressed;
if (pressed) { if (pressed) {
Event_RaiseInt(&KeyEvents_Down, key); Event_RaiseInt(&KeyEvents.Down, key);
} else { } else {
Event_RaiseInt(&KeyEvents_Up, key); Event_RaiseInt(&KeyEvents.Up, key);
} }
} }
@ -98,22 +98,22 @@ void Mouse_SetPressed(MouseButton btn, bool pressed) {
Mouse_Pressed[btn] = pressed; Mouse_Pressed[btn] = pressed;
if (pressed) { if (pressed) {
Event_RaiseInt(&MouseEvents_Down, btn); Event_RaiseInt(&MouseEvents.Down, btn);
} else { } else {
Event_RaiseInt(&MouseEvents_Up, btn); Event_RaiseInt(&MouseEvents.Up, btn);
} }
} }
void Mouse_SetWheel(float wheel) { void Mouse_SetWheel(float wheel) {
float delta = wheel - Mouse_Wheel; float delta = wheel - Mouse_Wheel;
Mouse_Wheel = wheel; Mouse_Wheel = wheel;
Event_RaiseFloat(&MouseEvents_Wheel, delta); Event_RaiseFloat(&MouseEvents.Wheel, delta);
} }
void Mouse_SetPosition(int x, int y) { void Mouse_SetPosition(int x, int y) {
int deltaX = x - Mouse_X, deltaY = y - Mouse_Y; int deltaX = x - Mouse_X, deltaY = y - Mouse_Y;
Mouse_X = x; Mouse_Y = y; Mouse_X = x; Mouse_Y = y;
Event_RaiseMouseMove(&MouseEvents_Moved, deltaX, deltaY); Event_RaiseMouseMove(&MouseEvents.Moved, deltaX, deltaY);
} }

View File

@ -80,10 +80,10 @@ extern const char* Key_Names[KEY_COUNT];
/* Pressed state of each keyboard button. Use Key_SetPressed to change. */ /* Pressed state of each keyboard button. Use Key_SetPressed to change. */
extern bool Key_Pressed[KEY_COUNT]; extern bool Key_Pressed[KEY_COUNT];
/* Sets the pressed state of a keyboard button. */ /* Sets the pressed state of a keyboard button. */
/* Raises KeyEvents_Up or KeyEvents_Down if state differs, or Key_KeyRepeat is on. */ /* Raises KeyEvents.Up or KeyEvents.Down if state differs, or Key_KeyRepeat is on. */
void Key_SetPressed(Key key, bool pressed); void Key_SetPressed(Key key, bool pressed);
/* Resets all keys to not pressed state. */ /* Resets all keys to not pressed state. */
/* Raises KeyEvents_Up for each previously pressed key. */ /* Raises KeyEvents.Up for each previously pressed key. */
void Key_Clear(void); void Key_Clear(void);
@ -100,11 +100,11 @@ extern int Mouse_X, Mouse_Y;
/* Pressed state of each mouse button. Use Mouse_SetPressed to change. */ /* Pressed state of each mouse button. Use Mouse_SetPressed to change. */
extern bool Mouse_Pressed[MOUSE_COUNT]; extern bool Mouse_Pressed[MOUSE_COUNT];
/* Sets the pressed state of a mouse button. */ /* Sets the pressed state of a mouse button. */
/* Raises MouseEvents_Up or MouseEvents_Down if state differs. */ /* Raises MouseEvents.Up or MouseEvents.Down if state differs. */
void Mouse_SetPressed(MouseButton btn, bool pressed); void Mouse_SetPressed(MouseButton btn, bool pressed);
/* Sets wheel position of the mouse, always raising MouseEvents_Wheel. */ /* Sets wheel position of the mouse, always raising MouseEvents.Wheel. */
void Mouse_SetWheel(float wheel); void Mouse_SetWheel(float wheel);
/* Sets X and Y position of the mouse, always raising MouseEvents_Moved. */ /* Sets X and Y position of the mouse, always raising MouseEvents.Moved. */
void Mouse_SetPosition(int x, int y); void Mouse_SetPosition(int x, int y);

View File

@ -164,7 +164,7 @@ static bool InputHandler_HandleNonClassicKey(Key key) {
/* Don't assign SelectedIndex directly, because we don't want held block /* Don't assign SelectedIndex directly, because we don't want held block
switching positions if they already have air in their inventory hotbar. */ switching positions if they already have air in their inventory hotbar. */
Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR); Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR);
Event_RaiseVoid(&UserEvents_HeldBlockChanged); Event_RaiseVoid(&UserEvents.HeldBlockChanged);
} }
} else if (key == KeyBind_Get(KEYBIND_IDOVERLAY)) { } else if (key == KeyBind_Get(KEYBIND_IDOVERLAY)) {
if (Gui_OverlaysCount) return true; if (Gui_OverlaysCount) return true;
@ -348,7 +348,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
if (Block_Draw[old] == DRAW_GAS || !Block_CanDelete[old]) return; if (Block_Draw[old] == DRAW_GAS || !Block_CanDelete[old]) return;
Game_ChangeBlock(p.X, p.Y, p.Z, BLOCK_AIR); Game_ChangeBlock(p.X, p.Y, p.Z, BLOCK_AIR);
Event_RaiseBlock(&UserEvents_BlockChanged, p, old, BLOCK_AIR); Event_RaiseBlock(&UserEvents.BlockChanged, p, old, BLOCK_AIR);
} else if (right) { } else if (right) {
p = Game_SelectedPos.TranslatedPos; p = Game_SelectedPos.TranslatedPos;
if (!Game_SelectedPos.Valid || !World_IsValidPos_3I(p)) return; if (!Game_SelectedPos.Valid || !World_IsValidPos_3I(p)) return;
@ -363,7 +363,7 @@ void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right)
if (!InputHandler_CheckIsFree(block)) return; if (!InputHandler_CheckIsFree(block)) return;
Game_ChangeBlock(p.X, p.Y, p.Z, block); Game_ChangeBlock(p.X, p.Y, p.Z, block);
Event_RaiseBlock(&UserEvents_BlockChanged, p, old, block); Event_RaiseBlock(&UserEvents.BlockChanged, p, old, block);
} else if (middle) { } else if (middle) {
p = Game_SelectedPos.BlockPos; p = Game_SelectedPos.BlockPos;
if (!World_IsValidPos_3I(p)) return; if (!World_IsValidPos_3I(p)) return;
@ -500,13 +500,13 @@ static void InputHandler_KeyPress(void* obj, int keyChar) {
} }
void InputHandler_Init(void) { void InputHandler_Init(void) {
Event_RegisterFloat(&MouseEvents_Wheel, NULL, InputHandler_MouseWheel); Event_RegisterFloat(&MouseEvents.Wheel, NULL, InputHandler_MouseWheel);
Event_RegisterMouseMove(&MouseEvents_Moved, NULL, InputHandler_MouseMove); Event_RegisterMouseMove(&MouseEvents.Moved, NULL, InputHandler_MouseMove);
Event_RegisterInt(&MouseEvents_Down, NULL, InputHandler_MouseDown); Event_RegisterInt(&MouseEvents.Down, NULL, InputHandler_MouseDown);
Event_RegisterInt(&MouseEvents_Up, NULL, InputHandler_MouseUp); Event_RegisterInt(&MouseEvents.Up, NULL, InputHandler_MouseUp);
Event_RegisterInt(&KeyEvents_Down, NULL, InputHandler_KeyDown); Event_RegisterInt(&KeyEvents.Down, NULL, InputHandler_KeyDown);
Event_RegisterInt(&KeyEvents_Up, NULL, InputHandler_KeyUp); Event_RegisterInt(&KeyEvents.Up, NULL, InputHandler_KeyUp);
Event_RegisterInt(&KeyEvents_Press, NULL, InputHandler_KeyPress); Event_RegisterInt(&KeyEvents.Press, NULL, InputHandler_KeyPress);
KeyBind_Init(); KeyBind_Init();
Hotkeys_Init(); Hotkeys_Init();

View File

@ -24,13 +24,13 @@ bool Inventory_CheckChangeSelected(void) {
void Inventory_SetSelectedIndex(int index) { void Inventory_SetSelectedIndex(int index) {
if (!Inventory_CheckChangeSelected()) return; if (!Inventory_CheckChangeSelected()) return;
Inventory_SelectedIndex = index; Inventory_SelectedIndex = index;
Event_RaiseVoid(&UserEvents_HeldBlockChanged); Event_RaiseVoid(&UserEvents.HeldBlockChanged);
} }
void Inventory_SetHotbarIndex(int index) { void Inventory_SetHotbarIndex(int index) {
if (!Inventory_CheckChangeSelected() || Game_ClassicMode) return; if (!Inventory_CheckChangeSelected() || Game_ClassicMode) return;
Inventory_Offset = index * INVENTORY_BLOCKS_PER_HOTBAR; Inventory_Offset = index * INVENTORY_BLOCKS_PER_HOTBAR;
Event_RaiseVoid(&UserEvents_HeldBlockChanged); Event_RaiseVoid(&UserEvents.HeldBlockChanged);
} }
void Inventory_SetSelectedBlock(BlockID block) { void Inventory_SetSelectedBlock(BlockID block) {
@ -45,7 +45,7 @@ void Inventory_SetSelectedBlock(BlockID block) {
} }
Inventory_Set(Inventory_SelectedIndex, block); Inventory_Set(Inventory_SelectedIndex, block);
Event_RaiseVoid(&UserEvents_HeldBlockChanged); Event_RaiseVoid(&UserEvents.HeldBlockChanged);
} }
const static uint8_t inv_classicTable[] = { const static uint8_t inv_classicTable[] = {

View File

@ -167,17 +167,17 @@ static void Launcher_Display(void) {
static void Launcher_Init(void) { static void Launcher_Init(void) {
BitmapCol col = BITMAPCOL_CONST(125, 125, 125, 255); BitmapCol col = BITMAPCOL_CONST(125, 125, 125, 255);
Event_RegisterVoid(&WindowEvents_Resized, NULL, Launcher_OnResize); Event_RegisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize);
Event_RegisterVoid(&WindowEvents_StateChanged, NULL, Launcher_OnResize); Event_RegisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize);
Event_RegisterVoid(&WindowEvents_FocusChanged, NULL, Launcher_MaybeRedraw); Event_RegisterVoid(&WindowEvents.FocusChanged, NULL, Launcher_MaybeRedraw);
Event_RegisterVoid(&WindowEvents_Redraw, NULL, Launcher_ReqeustRedraw); Event_RegisterVoid(&WindowEvents.Redraw, NULL, Launcher_ReqeustRedraw);
Event_RegisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown); Event_RegisterInt(&KeyEvents.Down, NULL, Launcher_KeyDown);
Event_RegisterInt(&KeyEvents_Press, NULL, Launcher_KeyPress); Event_RegisterInt(&KeyEvents.Press, NULL, Launcher_KeyPress);
Event_RegisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown); Event_RegisterInt(&MouseEvents.Down, NULL, Launcher_MouseDown);
Event_RegisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp); Event_RegisterInt(&MouseEvents.Up, NULL, Launcher_MouseUp);
Event_RegisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove); Event_RegisterMouseMove(&MouseEvents.Moved, NULL, Launcher_MouseMove);
Event_RegisterFloat(&MouseEvents_Wheel, NULL, Launcher_MouseWheel); Event_RegisterFloat(&MouseEvents.Wheel, NULL, Launcher_MouseWheel);
Drawer2D_MakeFont(&logoFont, 32, FONT_STYLE_NORMAL); Drawer2D_MakeFont(&logoFont, 32, FONT_STYLE_NORMAL);
Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_STYLE_BOLD); Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_STYLE_BOLD);
@ -191,17 +191,17 @@ static void Launcher_Init(void) {
static void Launcher_Free(void) { static void Launcher_Free(void) {
int i; int i;
Event_UnregisterVoid(&WindowEvents_Resized, NULL, Launcher_OnResize); Event_UnregisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize);
Event_UnregisterVoid(&WindowEvents_StateChanged, NULL, Launcher_OnResize); Event_UnregisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize);
Event_UnregisterVoid(&WindowEvents_FocusChanged, NULL, Launcher_MaybeRedraw); Event_UnregisterVoid(&WindowEvents.FocusChanged, NULL, Launcher_MaybeRedraw);
Event_UnregisterVoid(&WindowEvents_Redraw, NULL, Launcher_ReqeustRedraw); Event_UnregisterVoid(&WindowEvents.Redraw, NULL, Launcher_ReqeustRedraw);
Event_UnregisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown); Event_UnregisterInt(&KeyEvents.Down, NULL, Launcher_KeyDown);
Event_UnregisterInt(&KeyEvents_Press, NULL, Launcher_KeyPress); Event_UnregisterInt(&KeyEvents.Press, NULL, Launcher_KeyPress);
Event_UnregisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown); Event_UnregisterInt(&MouseEvents.Down, NULL, Launcher_MouseDown);
Event_UnregisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp); Event_UnregisterInt(&MouseEvents.Up, NULL, Launcher_MouseUp);
Event_UnregisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove); Event_UnregisterMouseMove(&MouseEvents.Moved, NULL, Launcher_MouseMove);
Event_UnregisterFloat(&MouseEvents_Wheel, NULL, Launcher_MouseWheel); Event_UnregisterFloat(&MouseEvents.Wheel, NULL, Launcher_MouseWheel);
for (i = 0; i < FetchFlagsTask.NumDownloaded; i++) { for (i = 0; i < FetchFlagsTask.NumDownloaded; i++) {
Mem_Free(FetchFlagsTask.Bitmaps[i].Scan0); Mem_Free(FetchFlagsTask.Bitmaps[i].Scan0);

View File

@ -751,14 +751,14 @@ static void MapRenderer_OnNewMapLoaded(void) {
} }
static void MapRenderer_Init(void) { static void MapRenderer_Init(void) {
Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged); Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
Event_RegisterInt(&WorldEvents_EnvVarChanged, NULL, MapRenderer_EnvVariableChanged); Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
Event_RegisterVoid(&BlockEvents_BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged); Event_RegisterVoid(&BlockEvents.BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_); Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
Event_RegisterVoid(&GfxEvents_ProjectionChanged, NULL, MapRenderer_RecalcVisibility_); Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, MapRenderer_DeleteChunks_); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, MapRenderer_Refresh_); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_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(); */
@ -770,14 +770,14 @@ static void MapRenderer_Init(void) {
} }
static void MapRenderer_Free(void) { static void MapRenderer_Free(void) {
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged); Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
Event_UnregisterInt(&WorldEvents_EnvVarChanged, NULL, MapRenderer_EnvVariableChanged); Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
Event_UnregisterVoid(&BlockEvents_BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged); Event_UnregisterVoid(&BlockEvents.BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_); Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
Event_UnregisterVoid(&GfxEvents_ProjectionChanged, NULL, MapRenderer_RecalcVisibility_); Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, MapRenderer_DeleteChunks_); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, MapRenderer_Refresh_); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_Refresh_);
MapRenderer_OnNewMap(); MapRenderer_OnNewMap();
} }

View File

@ -312,7 +312,7 @@ static void Menu_Remove(void* screen, int i) {
} }
static void Menu_HandleFontChange(struct Screen* s) { static void Menu_HandleFontChange(struct Screen* s) {
Event_RaiseVoid(&ChatEvents_FontChanged); Event_RaiseVoid(&ChatEvents.FontChanged);
Elem_Recreate(s); Elem_Recreate(s);
Gui_RefreshHud(); Gui_RefreshHud();
Elem_HandlesMouseMove(s, Mouse_X, Mouse_Y); Elem_HandlesMouseMove(s, Mouse_X, Mouse_Y);
@ -659,13 +659,13 @@ static void PauseScreen_ContextRecreated(void* screen) {
static void PauseScreen_Init(void* screen) { static void PauseScreen_Init(void* screen) {
struct PauseScreen* s = screen; struct PauseScreen* s = screen;
MenuScreen_Init(s); MenuScreen_Init(s);
Event_RegisterVoid(&UserEvents_HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed); Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
} }
static void PauseScreen_Free(void* screen) { static void PauseScreen_Free(void* screen) {
struct PauseScreen* s = screen; struct PauseScreen* s = screen;
MenuScreen_Free(s); MenuScreen_Free(s);
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed); Event_UnregisterVoid(&UserEvents.HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
} }
static struct ScreenVTABLE PauseScreen_VTABLE = { static struct ScreenVTABLE PauseScreen_VTABLE = {
@ -738,13 +738,13 @@ static void OptionsGroupScreen_ContextRecreated(void* screen) {
static void OptionsGroupScreen_Init(void* screen) { static void OptionsGroupScreen_Init(void* screen) {
struct OptionsGroupScreen* s = screen; struct OptionsGroupScreen* s = screen;
MenuScreen_Init(s); MenuScreen_Init(s);
Event_RegisterVoid(&UserEvents_HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed); Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed);
} }
static void OptionsGroupScreen_Free(void* screen) { static void OptionsGroupScreen_Free(void* screen) {
struct OptionsGroupScreen* s = screen; struct OptionsGroupScreen* s = screen;
MenuScreen_Free(s); MenuScreen_Free(s);
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed); Event_UnregisterVoid(&UserEvents.HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed);
} }
static bool OptionsGroupScreen_MouseMove(void* screen, int x, int y) { static bool OptionsGroupScreen_MouseMove(void* screen, int x, int y) {
@ -2668,13 +2668,13 @@ static void HacksSettingsScreen_CheckHacksAllowed(void* screen) {
static void HacksSettingsScreen_ContextLost(void* screen) { static void HacksSettingsScreen_ContextLost(void* screen) {
struct MenuOptionsScreen* s = screen; struct MenuOptionsScreen* s = screen;
MenuOptionsScreen_ContextLost(s); MenuOptionsScreen_ContextLost(s);
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed); Event_UnregisterVoid(&UserEvents.HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);
} }
static void HacksSettingsScreen_ContextRecreated(void* screen) { static void HacksSettingsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = screen; struct MenuOptionsScreen* s = screen;
struct Widget** widgets = s->Widgets; struct Widget** widgets = s->Widgets;
Event_RegisterVoid(&UserEvents_HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed); Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);
MenuOptionsScreen_Make(s, 0, -1, -150, "Hacks enabled", MenuOptionsScreen_Bool, MenuOptionsScreen_Make(s, 0, -1, -150, "Hacks enabled", MenuOptionsScreen_Bool,
HacksSettingsScreen_GetHacks, HacksSettingsScreen_SetHacks); HacksSettingsScreen_GetHacks, HacksSettingsScreen_SetHacks);

View File

@ -1677,9 +1677,9 @@ void Models_Init(void) {
Model_RegisterDefaultModels(); Model_RegisterDefaultModels();
Models_ContextRecreated(NULL); Models_ContextRecreated(NULL);
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Models_TextureChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Models_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Models_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
} }
void Models_Free(void) { void Models_Free(void) {
@ -1690,9 +1690,9 @@ void Models_Free(void) {
} }
Models_ContextLost(NULL); Models_ContextLost(NULL);
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Models_TextureChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Models_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Models_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
} }
struct IGameComponent Models_Component = { struct IGameComponent Models_Component = {

View File

@ -125,16 +125,16 @@ static void Handlers_AddTablistEntry(EntityID id, const String* playerName, cons
|| !String_Equals(groupName, &oldGroupName) || groupRank != oldGroupRank; || !String_Equals(groupName, &oldGroupName) || groupRank != oldGroupRank;
if (changed) { if (changed) {
TabList_Set(id, playerName, listName, groupName, groupRank); TabList_Set(id, playerName, listName, groupName, groupRank);
Event_RaiseInt(&TabListEvents_Changed, id); Event_RaiseInt(&TabListEvents.Changed, id);
} }
} else { } else {
TabList_Set(id, playerName, listName, groupName, groupRank); TabList_Set(id, playerName, listName, groupName, groupRank);
Event_RaiseInt(&TabListEvents_Added, id); Event_RaiseInt(&TabListEvents.Added, id);
} }
} }
static void Handlers_RemoveTablistEntry(EntityID id) { static void Handlers_RemoveTablistEntry(EntityID id) {
Event_RaiseInt(&TabListEvents_Removed, id); Event_RaiseInt(&TabListEvents.Removed, id);
TabList_Remove(id); TabList_Remove(id);
} }
@ -165,7 +165,7 @@ static void Handlers_AddEntity(uint8_t* data, EntityID id, const String* display
NetPlayer_Init(pl, displayName, skinName); NetPlayer_Init(pl, displayName, skinName);
Entities_List[id] = &pl->Base; Entities_List[id] = &pl->Base;
Event_RaiseInt(&EntityEvents_Added, id); Event_RaiseInt(&EntityEvents.Added, id);
} else { } else {
p = &LocalPlayer_Instance; p = &LocalPlayer_Instance;
p->Base.VTABLE->Despawn(&p->Base); p->Base.VTABLE->Despawn(&p->Base);
@ -407,7 +407,7 @@ static void Classic_Ping(uint8_t* data) { }
static void Classic_StartLoading(void) { static void Classic_StartLoading(void) {
World_Reset(); World_Reset();
Event_RaiseVoid(&WorldEvents_NewMap); Event_RaiseVoid(&WorldEvents.NewMap);
Stream_ReadonlyMemory(&map_part, NULL, 0); Stream_ReadonlyMemory(&map_part, NULL, 0);
classic_prevScreen = Gui_Active; classic_prevScreen = Gui_Active;
@ -506,7 +506,7 @@ static void Classic_LevelDataChunk(uint8_t* data) {
} }
progress = !map_blocks ? 0.0f : (float)map_index / map_volume; progress = !map_blocks ? 0.0f : (float)map_index / map_volume;
Event_RaiseFloat(&WorldEvents_Loading, progress); Event_RaiseFloat(&WorldEvents.Loading, progress);
} }
static void Classic_LevelFinalise(uint8_t* data) { static void Classic_LevelFinalise(uint8_t* data) {
@ -534,7 +534,7 @@ static void Classic_LevelFinalise(uint8_t* data) {
} }
#endif #endif
Event_RaiseVoid(&WorldEvents_MapLoaded); Event_RaiseVoid(&WorldEvents.MapLoaded);
WoM_CheckSendWomID(); WoM_CheckSendWomID();
map_blocks = NULL; map_blocks = NULL;
@ -954,7 +954,7 @@ static void CPE_CustomBlockLevel(uint8_t* data) {
CPE_WriteCustomBlockLevel(1); CPE_WriteCustomBlockLevel(1);
Net_SendPacket(); Net_SendPacket();
Game_UseCPEBlocks = true; Game_UseCPEBlocks = true;
Event_RaiseVoid(&BlockEvents_PermissionsChanged); Event_RaiseVoid(&BlockEvents.PermissionsChanged);
} }
static void CPE_HoldThis(uint8_t* data) { static void CPE_HoldThis(uint8_t* data) {
@ -1100,7 +1100,7 @@ static void CPE_SetBlockPermission(uint8_t* data) {
Block_CanPlace[block] = *data++ != 0; Block_CanPlace[block] = *data++ != 0;
Block_CanDelete[block] = *data++ != 0; Block_CanDelete[block] = *data++ != 0;
Event_RaiseVoid(&BlockEvents_PermissionsChanged); Event_RaiseVoid(&BlockEvents.PermissionsChanged);
} }
static void CPE_ChangeModel(uint8_t* data) { static void CPE_ChangeModel(uint8_t* data) {
@ -1157,7 +1157,7 @@ static void CPE_HackControl(uint8_t* data) {
} }
physics->ServerJumpVel = physics->JumpVel; physics->ServerJumpVel = physics->JumpVel;
Event_RaiseVoid(&UserEvents_HackPermissionsChanged); Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
} }
static void CPE_ExtAddEntity2(uint8_t* data) { static void CPE_ExtAddEntity2(uint8_t* data) {
@ -1227,7 +1227,7 @@ static void CPE_SetTextColor(uint8_t* data) {
if (code == '%' || code == '&') return; if (code == '%' || code == '&') return;
Drawer2D_Cols[code] = c; Drawer2D_Cols[code] = c;
Event_RaiseInt(&ChatEvents_ColCodeChanged, code); Event_RaiseInt(&ChatEvents.ColCodeChanged, code);
} }
static void CPE_SetMapEnvUrl(uint8_t* data) { static void CPE_SetMapEnvUrl(uint8_t* data) {
@ -1507,7 +1507,7 @@ static void BlockDefs_UndefineBlock(uint8_t* data) {
if (block < BLOCK_CPE_COUNT) { Inventory_AddDefault(block); } if (block < BLOCK_CPE_COUNT) { Inventory_AddDefault(block); }
Block_SetCustomDefined(block, false); Block_SetCustomDefined(block, false);
Event_RaiseVoid(&BlockEvents_BlockDefChanged); Event_RaiseVoid(&BlockEvents.BlockDefChanged);
} }
static void BlockDefs_DefineBlockExt(uint8_t* data) { static void BlockDefs_DefineBlockExt(uint8_t* data) {

View File

@ -471,20 +471,20 @@ static void Particles_Init(void) {
Random_InitFromCurrentTime(&rnd); Random_InitFromCurrentTime(&rnd);
Particles_ContextRecreated(NULL); Particles_ContextRecreated(NULL);
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, Particles_BreakBlockEffect_Handler); Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Particles_FileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Particles_FileChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Particles_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Particles_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Particles_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Particles_ContextRecreated);
} }
static void Particles_Free(void) { static void Particles_Free(void) {
Gfx_DeleteTexture(&Particles_TexId); Gfx_DeleteTexture(&Particles_TexId);
Particles_ContextLost(NULL); Particles_ContextLost(NULL);
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, Particles_BreakBlockEffect_Handler); Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Particles_FileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Particles_FileChanged);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Particles_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Particles_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Particles_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Particles_ContextRecreated);
} }
static void Particles_Reset(void) { rain_count = 0; terrain_count = 0; } static void Particles_Reset(void) { rain_count = 0; terrain_count = 0; }

View File

@ -111,14 +111,14 @@ static void PickedPosRenderer_ContextRecreated(void* obj) {
static void PickedPosRenderer_Init(void) { static void PickedPosRenderer_Init(void) {
PickedPosRenderer_ContextRecreated(NULL); PickedPosRenderer_ContextRecreated(NULL);
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, PickedPosRenderer_ContextLost); Event_RegisterVoid(&GfxEvents.ContextLost, NULL, PickedPosRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, PickedPosRenderer_ContextRecreated); Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
} }
static void PickedPosRenderer_Free(void) { static void PickedPosRenderer_Free(void) {
PickedPosRenderer_ContextLost(NULL); PickedPosRenderer_ContextLost(NULL);
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, PickedPosRenderer_ContextLost); Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, PickedPosRenderer_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, PickedPosRenderer_ContextRecreated); Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
} }
struct IGameComponent PickedPosRenderer_Component = { struct IGameComponent PickedPosRenderer_Component = {

View File

@ -150,8 +150,8 @@ static void InventoryScreen_Init(void* screen) {
Key_KeyRepeat = true; Key_KeyRepeat = true;
Screen_CommonInit(s); Screen_CommonInit(s);
Event_RegisterVoid(&BlockEvents_PermissionsChanged, s, InventoryScreen_OnBlockChanged); Event_RegisterVoid(&BlockEvents.PermissionsChanged, s, InventoryScreen_OnBlockChanged);
Event_RegisterVoid(&BlockEvents_BlockDefChanged, s, InventoryScreen_OnBlockChanged); Event_RegisterVoid(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
} }
static void InventoryScreen_Render(void* screen, double delta) { static void InventoryScreen_Render(void* screen, double delta) {
@ -171,8 +171,8 @@ static void InventoryScreen_Free(void* screen) {
Key_KeyRepeat = false; Key_KeyRepeat = false;
Screen_CommonFree(s); Screen_CommonFree(s);
Event_UnregisterVoid(&BlockEvents_PermissionsChanged, s, InventoryScreen_OnBlockChanged); Event_UnregisterVoid(&BlockEvents.PermissionsChanged, s, InventoryScreen_OnBlockChanged);
Event_UnregisterVoid(&BlockEvents_BlockDefChanged, s, InventoryScreen_OnBlockChanged); Event_UnregisterVoid(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
} }
static bool InventoryScreen_KeyDown(void* screen, Key key) { static bool InventoryScreen_KeyDown(void* screen, Key key) {
@ -568,7 +568,7 @@ static void LoadingScreen_Init(void* screen) {
Screen_CommonInit(s); Screen_CommonInit(s);
Gfx_SetFog(false); Gfx_SetFog(false);
Event_RegisterFloat(&WorldEvents_Loading, s, LoadingScreen_MapLoading); Event_RegisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
} }
#define PROG_BAR_WIDTH 200 #define PROG_BAR_WIDTH 200
@ -599,7 +599,7 @@ static void LoadingScreen_Free(void* screen) {
struct LoadingScreen* s = screen; struct LoadingScreen* s = screen;
Font_Free(&s->Font); Font_Free(&s->Font);
Screen_CommonFree(s); Screen_CommonFree(s);
Event_UnregisterFloat(&WorldEvents_Loading, s, LoadingScreen_MapLoading); Event_UnregisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
} }
static struct ScreenVTABLE LoadingScreen_VTABLE = { static struct ScreenVTABLE LoadingScreen_VTABLE = {
@ -632,7 +632,7 @@ struct Screen* LoadingScreen_UNSAFE_RawPointer = (struct Screen*)&LoadingScreen_
*#########################################################################################################################*/ *#########################################################################################################################*/
static void GeneratingScreen_Init(void* screen) { static void GeneratingScreen_Init(void* screen) {
World_Reset(); World_Reset();
Event_RaiseVoid(&WorldEvents_NewMap); Event_RaiseVoid(&WorldEvents.NewMap);
Gen_Done = false; Gen_Done = false;
LoadingScreen_Init(screen); LoadingScreen_Init(screen);
@ -666,7 +666,7 @@ static void GeneratingScreen_EndGeneration(void) {
p->Base.VTABLE->SetLocation(&p->Base, &update, false); p->Base.VTABLE->SetLocation(&p->Base, &update, false);
Camera_CurrentPos = Camera_Active->GetPosition(0.0f); Camera_CurrentPos = Camera_Active->GetPosition(0.0f);
Event_RaiseVoid(&WorldEvents_MapLoaded); Event_RaiseVoid(&WorldEvents.MapLoaded);
} }
static void GeneratingScreen_Render(void* screen, double delta) { static void GeneratingScreen_Render(void* screen, double delta) {
@ -1117,8 +1117,8 @@ static void ChatScreen_Init(void* screen) {
Drawer2D_MakeFont(&s->AnnouncementFont, largeSize, FONT_STYLE_NORMAL); Drawer2D_MakeFont(&s->AnnouncementFont, largeSize, FONT_STYLE_NORMAL);
Screen_CommonInit(s); Screen_CommonInit(s);
Event_RegisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived); Event_RegisterChat(&ChatEvents.ChatReceived, s, ChatScreen_ChatReceived);
Event_RegisterInt(&ChatEvents_ColCodeChanged, s, ChatScreen_ColCodeChanged); Event_RegisterInt(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
} }
static void ChatScreen_Render(void* screen, double delta) { static void ChatScreen_Render(void* screen, double delta) {
@ -1176,8 +1176,8 @@ static void ChatScreen_Free(void* screen) {
Font_Free(&s->AnnouncementFont); Font_Free(&s->AnnouncementFont);
Screen_CommonFree(s); Screen_CommonFree(s);
Event_UnregisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived); Event_UnregisterChat(&ChatEvents.ChatReceived, s, ChatScreen_ChatReceived);
Event_UnregisterInt(&ChatEvents_ColCodeChanged, s, ChatScreen_ColCodeChanged); Event_UnregisterInt(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
} }
static struct ScreenVTABLE ChatScreen_VTABLE = { static struct ScreenVTABLE ChatScreen_VTABLE = {

View File

@ -208,8 +208,8 @@ void Selections_Render(double delta) {
*--------------------------------------------------Selections component---------------------------------------------------* *--------------------------------------------------Selections component---------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Selections_Init(void) { static void Selections_Init(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 Selections_Reset(void) {
@ -218,8 +218,8 @@ static void Selections_Reset(void) {
static void Selections_Free(void) { static void Selections_Free(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 = {

View File

@ -158,7 +158,7 @@ static void SPConnection_BeginConnect(void) {
Block_CanPlace[i] = true; Block_CanPlace[i] = true;
Block_CanDelete[i] = true; Block_CanDelete[i] = true;
} }
Event_RaiseVoid(&BlockEvents_PermissionsChanged); Event_RaiseVoid(&BlockEvents.PermissionsChanged);
/* For when user drops a map file onto ClassiCube.exe */ /* For when user drops a map file onto ClassiCube.exe */
path = Game_Username; path = Game_Username;
@ -274,7 +274,7 @@ static TimeMS net_connectTimeout;
static void ServerConnection_Free(void); static void ServerConnection_Free(void);
static void MPConnection_FinishConnect(void) { static void MPConnection_FinishConnect(void) {
net_connecting = false; net_connecting = false;
Event_RaiseFloat(&WorldEvents_Loading, 0.0f); Event_RaiseFloat(&WorldEvents.Loading, 0.0f);
net_readCurrent = net_readBuffer; net_readCurrent = net_readBuffer;
ServerConnection_WriteBuffer = net_writeBuffer; ServerConnection_WriteBuffer = net_writeBuffer;
@ -320,7 +320,7 @@ static void MPConnection_TickConnect(void) {
MPConnection_FailConnect(0); MPConnection_FailConnect(0);
} else { } else {
int leftMS = (int)(net_connectTimeout - now); int leftMS = (int)(net_connectTimeout - now);
Event_RaiseFloat(&WorldEvents_Loading, (float)leftMS / NET_TIMEOUT_MS); Event_RaiseFloat(&WorldEvents.Loading, (float)leftMS / NET_TIMEOUT_MS);
} }
} }

View File

@ -369,14 +369,14 @@ static void Animations_FileChanged(void* obj, struct Stream* stream, const Strin
static void Animations_Init(void) { static void Animations_Init(void) {
ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick); ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick);
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, Animations_PackChanged); Event_RegisterVoid(&TextureEvents.PackChanged, NULL, Animations_PackChanged);
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Animations_FileChanged); Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Animations_FileChanged);
} }
static void Animations_Free(void) { static void Animations_Free(void) {
Animations_Clear(); Animations_Clear();
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, Animations_PackChanged); Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, Animations_PackChanged);
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Animations_FileChanged); Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Animations_FileChanged);
} }
struct IGameComponent Animations_Component = { struct IGameComponent Animations_Component = {
@ -625,13 +625,13 @@ void TextureCache_SetLastModified(const String* url, const TimeMS* lastModified)
static ReturnCode TexturePack_ProcessZipEntry(const String* path, struct Stream* stream, struct ZipState* s) { static ReturnCode TexturePack_ProcessZipEntry(const String* path, struct Stream* stream, struct ZipState* s) {
String name = *path; String name = *path;
Utils_UNSAFE_GetFilename(&name); Utils_UNSAFE_GetFilename(&name);
Event_RaiseEntry(&TextureEvents_FileChanged, stream, &name); Event_RaiseEntry(&TextureEvents.FileChanged, stream, &name);
return 0; return 0;
} }
static ReturnCode TexturePack_ExtractZip(struct Stream* stream) { static ReturnCode TexturePack_ExtractZip(struct Stream* stream) {
struct ZipState state; struct ZipState state;
Event_RaiseVoid(&TextureEvents_PackChanged); Event_RaiseVoid(&TextureEvents.PackChanged);
if (Gfx_LostContext) return 0; if (Gfx_LostContext) return 0;
Zip_Init(&state, stream); Zip_Init(&state, stream);
@ -662,7 +662,7 @@ ReturnCode TexturePack_ExtractTerrainPng(struct Stream* stream) {
ReturnCode res = Png_Decode(&bmp, stream); ReturnCode res = Png_Decode(&bmp, stream);
if (!res) { if (!res) {
Event_RaiseVoid(&TextureEvents_PackChanged); Event_RaiseVoid(&TextureEvents.PackChanged);
if (Game_ChangeTerrainAtlas(&bmp)) return 0; if (Game_ChangeTerrainAtlas(&bmp)) return 0;
} }

View File

@ -54,7 +54,7 @@ extern GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES];
#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */ #define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */
/* Loads the given atlas and converts it into an array of 1D atlases. */ /* Loads the given atlas and converts it into an array of 1D atlases. */
/* NOTE: Use Game_ChangeTerrainAtlas to change atlas, because that raises TextureEvents_AtlasChanged */ /* NOTE: Use Game_ChangeTerrainAtlas to change atlas, because that raises TextureEvents.AtlasChanged */
void Atlas_Update(Bitmap* bmp); void Atlas_Update(Bitmap* bmp);
/* Loads the given tile into a new separate texture. */ /* Loads the given tile into a new separate texture. */
GfxResourceID Atlas_LoadTile(TextureLoc texLoc); GfxResourceID Atlas_LoadTile(TextureLoc texLoc);

View File

@ -2146,9 +2146,9 @@ static void PlayerListWidget_Init(void* widget) {
TextWidget_Create(&w->Title, &title, &w->Font); TextWidget_Create(&w->Title, &title, &w->Font);
Widget_SetLocation(&w->Title, ANCHOR_CENTRE, ANCHOR_MIN, 0, 0); Widget_SetLocation(&w->Title, ANCHOR_CENTRE, ANCHOR_MIN, 0, 0);
Event_RegisterInt(&TabListEvents_Added, w, PlayerListWidget_TabEntryAdded); Event_RegisterInt(&TabListEvents.Added, w, PlayerListWidget_TabEntryAdded);
Event_RegisterInt(&TabListEvents_Changed, w, PlayerListWidget_TabEntryChanged); Event_RegisterInt(&TabListEvents.Changed, w, PlayerListWidget_TabEntryChanged);
Event_RegisterInt(&TabListEvents_Removed, w, PlayerListWidget_TabEntryRemoved); Event_RegisterInt(&TabListEvents.Removed, w, PlayerListWidget_TabEntryRemoved);
} }
static void PlayerListWidget_Render(void* widget, double delta) { static void PlayerListWidget_Render(void* widget, double delta) {
@ -2188,9 +2188,9 @@ static void PlayerListWidget_Free(void* widget) {
} }
Elem_TryFree(&w->Title); Elem_TryFree(&w->Title);
Event_UnregisterInt(&TabListEvents_Added, w, PlayerListWidget_TabEntryAdded); Event_UnregisterInt(&TabListEvents.Added, w, PlayerListWidget_TabEntryAdded);
Event_UnregisterInt(&TabListEvents_Changed, w, PlayerListWidget_TabEntryChanged); Event_UnregisterInt(&TabListEvents.Changed, w, PlayerListWidget_TabEntryChanged);
Event_UnregisterInt(&TabListEvents_Removed, w, PlayerListWidget_TabEntryRemoved); Event_UnregisterInt(&TabListEvents.Removed, w, PlayerListWidget_TabEntryRemoved);
} }
static struct WidgetVTABLE PlayerListWidget_VTABLE = { static struct WidgetVTABLE PlayerListWidget_VTABLE = {

View File

@ -182,12 +182,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
Window_Focused = LOWORD(wParam) != 0; Window_Focused = LOWORD(wParam) != 0;
if (Window_Focused != wasFocused) { if (Window_Focused != wasFocused) {
Event_RaiseVoid(&WindowEvents_FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
break; break;
case WM_ERASEBKGND: case WM_ERASEBKGND:
Event_RaiseVoid(&WindowEvents_Redraw); Event_RaiseVoid(&WindowEvents.Redraw);
return 1; return 1;
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
@ -197,7 +197,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
if (pos->x != Window_Bounds.X || pos->y != Window_Bounds.Y) { if (pos->x != Window_Bounds.X || pos->y != Window_Bounds.Y) {
Window_Bounds.X = pos->x; Window_Bounds.Y = pos->y; Window_Bounds.X = pos->x; Window_Bounds.Y = pos->y;
Event_RaiseVoid(&WindowEvents_Moved); Event_RaiseVoid(&WindowEvents.Moved);
} }
if (pos->cx != Window_Bounds.Width || pos->cy != Window_Bounds.Height) { if (pos->cx != Window_Bounds.Width || pos->cy != Window_Bounds.Height) {
@ -209,7 +209,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING); SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
if (suppress_resize <= 0) { if (suppress_resize <= 0) {
Event_RaiseVoid(&WindowEvents_Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
} }
} break; } break;
@ -236,14 +236,14 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
if (new_state != win_state) { if (new_state != win_state) {
win_state = new_state; win_state = new_state;
Event_RaiseVoid(&WindowEvents_StateChanged); Event_RaiseVoid(&WindowEvents.StateChanged);
} }
} break; } break;
case WM_CHAR: case WM_CHAR:
if (Convert_TryUnicodeToCP437((Codepoint)wParam, &keyChar)) { if (Convert_TryUnicodeToCP437((Codepoint)wParam, &keyChar)) {
Event_RaiseInt(&KeyEvents_Press, keyChar); Event_RaiseInt(&KeyEvents.Press, keyChar);
} }
break; break;
@ -356,7 +356,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
} break; } break;
case WM_CLOSE: case WM_CLOSE:
Event_RaiseVoid(&WindowEvents_Closing); Event_RaiseVoid(&WindowEvents.Closing);
Window_Destroy(); Window_Destroy();
break; break;
@ -364,7 +364,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
Window_Exists = false; Window_Exists = false;
UnregisterClass(CC_WIN_CLASSNAME, win_instance); UnregisterClass(CC_WIN_CLASSNAME, win_instance);
if (win_DC) ReleaseDC(win_handle, win_DC); if (win_DC) ReleaseDC(win_handle, win_DC);
Event_RaiseVoid(&WindowEvents_Closed); Event_RaiseVoid(&WindowEvents.Closed);
break; break;
} }
return DefWindowProc(handle, message, wParam, lParam); return DefWindowProc(handle, message, wParam, lParam);
@ -896,7 +896,7 @@ static void Window_RefreshBounds(XEvent* e) {
if (loc.X != Window_Bounds.X || loc.Y != Window_Bounds.Y) { if (loc.X != Window_Bounds.X || loc.Y != Window_Bounds.Y) {
Window_Bounds.X = loc.X; Window_Bounds.Y = loc.Y; Window_Bounds.X = loc.X; Window_Bounds.Y = loc.Y;
Event_RaiseVoid(&WindowEvents_Moved); Event_RaiseVoid(&WindowEvents.Moved);
} }
/* Note: width and height denote the internal (client) size. /* Note: width and height denote the internal (client) size.
@ -907,7 +907,7 @@ static void Window_RefreshBounds(XEvent* e) {
if (size.Width != Window_Bounds.Width || size.Height != Window_Bounds.Height) { if (size.Width != Window_Bounds.Width || size.Height != Window_Bounds.Height) {
Window_ClientSize.Width = e->xconfigure.width; Window_Bounds.Width = size.Width; Window_ClientSize.Width = e->xconfigure.width; Window_Bounds.Width = size.Width;
Window_ClientSize.Height = e->xconfigure.height; Window_Bounds.Height = size.Height; Window_ClientSize.Height = e->xconfigure.height; Window_Bounds.Height = size.Height;
Event_RaiseVoid(&WindowEvents_Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
} }
@ -1194,18 +1194,18 @@ void Window_ProcessEvents(void) {
win_visible = e.type == MapNotify; win_visible = e.type == MapNotify;
if (win_visible != wasVisible) { if (win_visible != wasVisible) {
Event_RaiseVoid(&WindowEvents_VisibilityChanged); Event_RaiseVoid(&WindowEvents.VisibilityChanged);
} }
break; break;
case ClientMessage: case ClientMessage:
if (!win_isExiting && e.xclient.data.l[0] == wm_destroy) { if (!win_isExiting && e.xclient.data.l[0] == wm_destroy) {
Platform_LogConst("Exit message received."); Platform_LogConst("Exit message received.");
Event_RaiseVoid(&WindowEvents_Closing); Event_RaiseVoid(&WindowEvents.Closing);
win_isExiting = true; win_isExiting = true;
Window_Destroy(); Window_Destroy();
Event_RaiseVoid(&WindowEvents_Closed); Event_RaiseVoid(&WindowEvents.Closed);
} break; } break;
case DestroyNotify: case DestroyNotify:
@ -1219,7 +1219,7 @@ void Window_ProcessEvents(void) {
case Expose: case Expose:
if (e.xexpose.count == 0) { if (e.xexpose.count == 0) {
Event_RaiseVoid(&WindowEvents_Redraw); Event_RaiseVoid(&WindowEvents.Redraw);
} }
break; break;
@ -1233,7 +1233,7 @@ void Window_ProcessEvents(void) {
char raw; int i; char raw; int i;
for (i = 0; i < status; i++) { for (i = 0; i < status; i++) {
if (!Convert_TryUnicodeToCP437((uint8_t)data[i], &raw)) continue; if (!Convert_TryUnicodeToCP437((uint8_t)data[i], &raw)) continue;
Event_RaiseInt(&KeyEvents_Press, raw); Event_RaiseInt(&KeyEvents.Press, raw);
} }
} break; } break;
@ -1273,7 +1273,7 @@ void Window_ProcessEvents(void) {
Window_Focused = e.type == FocusIn; Window_Focused = e.type == FocusIn;
if (Window_Focused != wasFocused) { if (Window_Focused != wasFocused) {
Event_RaiseVoid(&WindowEvents_FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
/* TODO: Keep track of keyboard when focus is lost */ /* TODO: Keep track of keyboard when focus is lost */
if (!Window_Focused) Key_Clear(); if (!Window_Focused) Key_Clear();
@ -1288,7 +1288,7 @@ void Window_ProcessEvents(void) {
case PropertyNotify: case PropertyNotify:
if (e.xproperty.atom == net_wm_state) { if (e.xproperty.atom == net_wm_state) {
Event_RaiseVoid(&WindowEvents_StateChanged); Event_RaiseVoid(&WindowEvents.StateChanged);
} }
/*if (e.xproperty.atom == net_frame_extents) { /*if (e.xproperty.atom == net_frame_extents) {
@ -1886,9 +1886,9 @@ static void Window_UpdateWindowState(void) {
break; break;
} }
Event_RaiseVoid(&WindowEvents_StateChanged); Event_RaiseVoid(&WindowEvents.StateChanged);
Window_UpdateSize(); Window_UpdateSize();
Event_RaiseVoid(&WindowEvents_Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
OSStatus Window_ProcessKeyboardEvent(EventHandlerCallRef inCaller, EventRef inEvent, void* userData) { OSStatus Window_ProcessKeyboardEvent(EventHandlerCallRef inCaller, EventRef inEvent, void* userData) {
@ -1929,7 +1929,7 @@ OSStatus Window_ProcessKeyboardEvent(EventHandlerCallRef inCaller, EventRef inEv
/* TODO: Should we be using kEventTextInputUnicodeForKeyEvent for this */ /* TODO: Should we be using kEventTextInputUnicodeForKeyEvent for this */
/* Look at documentation for kEventRawKeyRepeat */ /* Look at documentation for kEventRawKeyRepeat */
if (!Convert_TryUnicodeToCP437((uint8_t)charCode, &raw)) return 0; if (!Convert_TryUnicodeToCP437((uint8_t)charCode, &raw)) return 0;
Event_RaiseInt(&KeyEvents_Press, raw); Event_RaiseInt(&KeyEvents.Press, raw);
return 0; return 0;
case kEventRawKeyUp: case kEventRawKeyUp:
@ -1962,12 +1962,12 @@ OSStatus Window_ProcessWindowEvent(EventHandlerCallRef inCaller, EventRef inEven
switch (GetEventKind(inEvent)) { switch (GetEventKind(inEvent)) {
case kEventWindowClose: case kEventWindowClose:
Event_RaiseVoid(&WindowEvents_Closing); Event_RaiseVoid(&WindowEvents.Closing);
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowClosed: case kEventWindowClosed:
Window_Exists = false; Window_Exists = false;
Event_RaiseVoid(&WindowEvents_Closed); Event_RaiseVoid(&WindowEvents.Closed);
return 0; return 0;
case kEventWindowBoundsChanged: case kEventWindowBoundsChanged:
@ -1976,18 +1976,18 @@ OSStatus Window_ProcessWindowEvent(EventHandlerCallRef inCaller, EventRef inEven
Window_UpdateSize(); Window_UpdateSize();
if (width != Window_ClientSize.Width || height != Window_ClientSize.Height) { if (width != Window_ClientSize.Width || height != Window_ClientSize.Height) {
Event_RaiseVoid(&WindowEvents_Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowActivated: case kEventWindowActivated:
Window_Focused = true; Window_Focused = true;
Event_RaiseVoid(&WindowEvents_FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowDeactivated: case kEventWindowDeactivated:
Window_Focused = false; Window_Focused = false;
Event_RaiseVoid(&WindowEvents_FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
return eventNotHandledErr; return eventNotHandledErr;
} }
return eventNotHandledErr; return eventNotHandledErr;
@ -2297,7 +2297,7 @@ void Window_SetClientSize(int width, int height) {
} }
void Window_Close(void) { void Window_Close(void) {
Event_RaiseVoid(&WindowEvents_Closed); Event_RaiseVoid(&WindowEvents.Closed);
/* TODO: Does this raise the event twice? */ /* TODO: Does this raise the event twice? */
Window_Destroy(); Window_Destroy();
} }

View File

@ -131,10 +131,10 @@ bool World_IsValidPos_3I(Vector3I p) {
*-------------------------------------------------------Environment-------------------------------------------------------* *-------------------------------------------------------Environment-------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
#define Env_Set(src, dst, var) \ #define Env_Set(src, dst, var) \
if (src != dst) { dst = src; Event_RaiseInt(&WorldEvents_EnvVarChanged, var); } if (src != dst) { dst = src; Event_RaiseInt(&WorldEvents.EnvVarChanged, var); }
#define Env_SetCol(src, dst, var)\ #define Env_SetCol(src, dst, var)\
if (!PackedCol_Equals(src, dst)) { dst = src; Event_RaiseInt(&WorldEvents_EnvVarChanged, var); } if (!PackedCol_Equals(src, dst)) { dst = src; Event_RaiseInt(&WorldEvents.EnvVarChanged, var); }
const char* Weather_Names[3] = { "Sunny", "Rainy", "Snowy" }; const char* Weather_Names[3] = { "Sunny", "Rainy", "Snowy" };