mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 10:02:08 -05:00
Improve event API
This commit is contained in:
parent
a52f45a5ca
commit
a89acea84d
36 changed files with 351 additions and 389 deletions
|
@ -546,14 +546,14 @@ static void AudioManager_Init(void) {
|
|||
Audio_SetMusic(volume);
|
||||
volume = AudioManager_GetVolume(OPT_SOUND_VOLUME, OPT_USE_SOUND);
|
||||
Audio_SetSounds(volume);
|
||||
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, Audio_PlayBlockSound);
|
||||
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
|
||||
}
|
||||
|
||||
static void AudioManager_Free(void) {
|
||||
Music_Free();
|
||||
Sounds_Free();
|
||||
Waitable_Free(music_waitable);
|
||||
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, Audio_PlayBlockSound);
|
||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, Audio_PlayBlockSound);
|
||||
}
|
||||
|
||||
struct IGameComponent Audio_Component = {
|
||||
|
|
|
@ -65,12 +65,12 @@ static void AxisLinesRenderer_ContextLost(void* obj) {
|
|||
}
|
||||
|
||||
static void AxisLinesRenderer_Init(void) {
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, AxisLinesRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, AxisLinesRenderer_ContextLost);
|
||||
}
|
||||
|
||||
static void AxisLinesRenderer_Free(void) {
|
||||
AxisLinesRenderer_ContextLost(NULL);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, AxisLinesRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, AxisLinesRenderer_ContextLost);
|
||||
}
|
||||
|
||||
struct IGameComponent AxisLinesRenderer_Component = {
|
||||
|
|
|
@ -198,7 +198,7 @@ void Block_DefineCustom(BlockID block) {
|
|||
|
||||
Inventory_AddDefault(block);
|
||||
Block_SetCustomDefined(block, true);
|
||||
Event_RaiseVoid(&BlockEvents_BlockDefChanged);
|
||||
Event_RaiseVoid(&BlockEvents.BlockDefChanged);
|
||||
}
|
||||
|
||||
static void Block_RecalcIsLiquid(BlockID b) {
|
||||
|
@ -693,7 +693,7 @@ static void Blocks_Init(void) {
|
|||
|
||||
AutoRotate_Enabled = true;
|
||||
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_LAVA] = false; Block_CanDelete[BLOCK_LAVA] = false;
|
||||
|
@ -704,7 +704,7 @@ static void Blocks_Init(void) {
|
|||
}
|
||||
|
||||
static void Blocks_Free(void) {
|
||||
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, Blocks_AtlasChanged);
|
||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, Blocks_AtlasChanged);
|
||||
}
|
||||
|
||||
struct IGameComponent Blocks_Component = {
|
||||
|
|
|
@ -514,7 +514,7 @@ static void Physics_HandleTnt(int index, BlockID block) {
|
|||
}
|
||||
|
||||
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);
|
||||
TickQueue_Init(&physics_lavaQ);
|
||||
TickQueue_Init(&physics_waterQ);
|
||||
|
@ -557,7 +557,7 @@ void Physics_Init(void) {
|
|||
}
|
||||
|
||||
void Physics_Free(void) {
|
||||
Event_UnregisterVoid(&WorldEvents_MapLoaded, NULL, Physics_OnNewMapLoaded);
|
||||
Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, Physics_OnNewMapLoaded);
|
||||
}
|
||||
|
||||
void Physics_Tick(void) {
|
||||
|
|
10
src/Chat.c
10
src/Chat.c
|
@ -177,7 +177,7 @@ void Chat_AddRaw(const char* raw) {
|
|||
void Chat_Add(const String* text) { Chat_AddOf(text, MSG_TYPE_NORMAL); }
|
||||
|
||||
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) {
|
||||
StringsBuffer_Add(&Chat_Log, text);
|
||||
|
@ -476,7 +476,7 @@ static void CuboidCommand_BlockChanged(void* obj, Vector3I coords, BlockID old,
|
|||
CuboidCommand_DoCuboid();
|
||||
|
||||
if (!cuboid_persist) {
|
||||
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, CuboidCommand_BlockChanged);
|
||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, CuboidCommand_BlockChanged);
|
||||
cuboid_hooked = false;
|
||||
Chat_AddOf(&String_Empty, MSG_TYPE_CLIENTSTATUS_1);
|
||||
} else {
|
||||
|
@ -488,7 +488,7 @@ static void CuboidCommand_BlockChanged(void* obj, Vector3I coords, BlockID old,
|
|||
|
||||
static void CuboidCommand_Execute(const String* args, int argsCount) {
|
||||
if (cuboid_hooked) {
|
||||
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, CuboidCommand_BlockChanged);
|
||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, CuboidCommand_BlockChanged);
|
||||
cuboid_hooked = false;
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ static void CuboidCommand_Execute(const String* args, int argsCount) {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -554,7 +554,7 @@ static struct ChatCommand TeleportCommand_Instance = {
|
|||
*#########################################################################################################################*/
|
||||
void Chat_Send(const String* text, bool logUsage) {
|
||||
if (!text->length) return;
|
||||
Event_RaiseChat(&ChatEvents_ChatSending, text, 0);
|
||||
Event_RaiseChat(&ChatEvents.ChatSending, text, 0);
|
||||
if (logUsage) StringsBuffer_Add(&Chat_InputLog, text);
|
||||
|
||||
if (Commands_IsCommandPrefix(text)) {
|
||||
|
|
|
@ -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") */
|
||||
/* NOTE: This can only be set once. */
|
||||
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. */
|
||||
/* In multiplayer this is sent to the server, in singleplayer just Chat_Add. */
|
||||
CC_API void Chat_Send(const String* text, bool logUsage);
|
||||
/* Shorthand for Chat_AddOf(str, MSG_TYPE_NORMAL) */
|
||||
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. */
|
||||
/* Other message types are usually used for info/status messages. */
|
||||
CC_API void Chat_AddOf(const String* text, MsgType type);
|
||||
|
|
|
@ -683,7 +683,7 @@ static void Drawer2D_TextureChanged(void* obj, struct Stream* src, const String*
|
|||
Mem_Free(bmp.Scan0);
|
||||
} else {
|
||||
Drawer2D_SetFontBitmap(&bmp);
|
||||
Event_RaiseVoid(&ChatEvents_FontChanged);
|
||||
Event_RaiseVoid(&ChatEvents.FontChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -721,12 +721,12 @@ static void Drawer2D_Init(void) {
|
|||
}
|
||||
|
||||
Drawer2D_CheckFont();
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Drawer2D_TextureChanged);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Drawer2D_TextureChanged);
|
||||
}
|
||||
|
||||
static void Drawer2D_Free(void) {
|
||||
Drawer2D_FreeFontBitmap();
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Drawer2D_TextureChanged);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Drawer2D_TextureChanged);
|
||||
}
|
||||
|
||||
struct IGameComponent Drawer2D_Component = {
|
||||
|
|
14
src/Entity.c
14
src/Entity.c
|
@ -326,7 +326,7 @@ static void Entities_ChatFontChanged(void* obj) {
|
|||
}
|
||||
|
||||
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] = NULL;
|
||||
}
|
||||
|
@ -1105,9 +1105,9 @@ void NetPlayer_Init(struct NetPlayer* p, const String* displayName, const String
|
|||
*--------------------------------------------------------Entities---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void Entities_Init(void) {
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Entities_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Entities_ContextRecreated);
|
||||
Event_RegisterVoid(&ChatEvents_FontChanged, NULL, Entities_ChatFontChanged);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Entities_ContextRecreated);
|
||||
Event_RegisterVoid(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged);
|
||||
|
||||
Entities_NameMode = Options_GetEnum(OPT_NAMES_MODE, NAME_MODE_HOVERED,
|
||||
NameMode_Names, Array_Elems(NameMode_Names));
|
||||
|
@ -1128,9 +1128,9 @@ static void Entities_Free(void) {
|
|||
Entities_Remove((EntityID)i);
|
||||
}
|
||||
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Entities_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Entities_ContextRecreated);
|
||||
Event_UnregisterVoid(&ChatEvents_FontChanged, NULL, Entities_ChatFontChanged);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Entities_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Entities_ContextRecreated);
|
||||
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Entities_ChatFontChanged);
|
||||
|
||||
if (ShadowComponent_ShadowTex) {
|
||||
Gfx_DeleteTexture(&ShadowComponent_ShadowTex);
|
||||
|
|
|
@ -291,7 +291,7 @@ void HacksComp_UpdateState(struct HacksComp* hacks) {
|
|||
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
|
||||
|
||||
HacksComp_CheckConsistency(hacks);
|
||||
Event_RaiseVoid(&UserEvents_HackPermissionsChanged);
|
||||
Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -906,27 +906,27 @@ static void EnvRenderer_Init(void) {
|
|||
EnvRenderer_Legacy = flags & ENV_LEGACY;
|
||||
EnvRenderer_Minimal = flags & ENV_MINIMAL;
|
||||
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, EnvRenderer_TexturePackChanged);
|
||||
Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_RegisterVoid(&TextureEvents.PackChanged, NULL, EnvRenderer_TexturePackChanged);
|
||||
Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
|
||||
|
||||
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
|
||||
Event_RegisterInt(&WorldEvents_EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
|
||||
Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
|
||||
Game_SetViewDistance(Game_UserViewDistance);
|
||||
}
|
||||
|
||||
static void EnvRenderer_Free(void) {
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, EnvRenderer_TexturePackChanged);
|
||||
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, EnvRenderer_TexturePackChanged);
|
||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, EnvRenderer_TerrainAtlasChanged);
|
||||
|
||||
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
|
||||
Event_UnregisterInt(&WorldEvents_EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, EnvRenderer_ViewDistanceChanged);
|
||||
Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, EnvRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
|
||||
EnvRenderer_ContextLost(NULL);
|
||||
Mem_Free(Weather_Heightmap);
|
||||
|
|
108
src/Event.c
108
src/Event.c
|
@ -1,58 +1,19 @@
|
|||
#include "Event.h"
|
||||
#include "Logger.h"
|
||||
|
||||
struct Event_Int EntityEvents_Added;
|
||||
struct Event_Int EntityEvents_Removed;
|
||||
struct Event_Int TabListEvents_Added;
|
||||
struct Event_Int TabListEvents_Changed;
|
||||
struct Event_Int TabListEvents_Removed;
|
||||
struct _EntityEventsList EntityEvents;
|
||||
struct _TabListEventsList TabListEvents;
|
||||
struct _TextureEventsList TextureEvents;
|
||||
struct _GfxEventsList GfxEvents;
|
||||
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;
|
||||
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) {
|
||||
void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) {
|
||||
int i;
|
||||
for (i = 0; i < handlers->Count; i++) {
|
||||
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;
|
||||
for (i = 0; i < handlers->Count; i++) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
int i;
|
||||
|
@ -107,12 +62,6 @@ void Event_RaiseInt(struct Event_Int* handlers, int 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) {
|
||||
int i;
|
||||
|
@ -120,13 +69,6 @@ void Event_RaiseFloat(struct Event_Float* handlers, float 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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
164
src/Event.h
164
src/Event.h
|
@ -2,11 +2,11 @@
|
|||
#define CC_EVENT_H
|
||||
#include "String.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
|
||||
*/
|
||||
|
||||
/* Maximum number of event handlers that can be registered. */
|
||||
/* Max callbacks that can be registered for an event. */
|
||||
#define EVENT_MAX_CALLBACKS 32
|
||||
struct Stream;
|
||||
|
||||
|
@ -52,82 +52,126 @@ struct Event_Chat {
|
|||
void* Objs[EVENT_MAX_CALLBACKS]; int Count;
|
||||
};
|
||||
|
||||
void Event_RaiseVoid(struct Event_Void* handlers);
|
||||
void Event_RegisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||
void Event_UnregisterVoid(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||
/* Registers a callback function for the given event. */
|
||||
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
||||
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);
|
||||
void Event_RegisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler);
|
||||
void Event_UnregisterInt(struct Event_Int* handlers, void* obj, Event_Int_Callback handler);
|
||||
/* Calls all registered callback for an event with no arguments. */
|
||||
CC_API void Event_RaiseVoid(struct Event_Void* handlers);
|
||||
#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);
|
||||
void Event_RegisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler);
|
||||
void Event_UnregisterFloat(struct Event_Float* handlers, void* obj, Event_Float_Callback handler);
|
||||
/* Calls all registered callback for an event which has an int argument. */
|
||||
/* NOTE: The actual argument "type" may be char, Key, uint8_t etc */
|
||||
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_RegisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler);
|
||||
void Event_UnregisterEntry(struct Event_Entry* handlers, void* obj, Event_Entry_Callback handler);
|
||||
#define Event_RegisterEntry(handlers, obj, handler) Event_RegisterMacro(handlers, obj, 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_RegisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler);
|
||||
void Event_UnregisterBlock(struct Event_Block* handlers, void* obj, Event_Block_Callback handler);
|
||||
#define Event_RegisterBlock(handlers, obj, handler) Event_RegisterMacro(handlers, obj, 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_RegisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler);
|
||||
void Event_UnregisterMouseMove(struct Event_MouseMove* handlers, void* obj, Event_MouseMove_Callback handler);
|
||||
#define Event_RegisterMouseMove(handlers, obj, handler) Event_RegisterMacro(handlers, obj, 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_RegisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler);
|
||||
void Event_UnregisterChat(struct Event_Chat* handlers, void* obj, Event_Chat_Callback handler);
|
||||
#define Event_RegisterChat(handlers, obj, handler) Event_RegisterMacro(handlers, obj, 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 Event_Int EntityEvents_Removed; /* Entity is despawned from the current world */
|
||||
extern struct Event_Int TabListEvents_Added; /* Tab list entry is created */
|
||||
extern struct Event_Int TabListEvents_Changed; /* Tab list entry is modified */
|
||||
extern struct Event_Int TabListEvents_Removed; /* Tab list entry is removed */
|
||||
extern struct _EntityEventsList {
|
||||
struct Event_Int Added; /* Entity is spawned in the current world */
|
||||
struct Event_Int Removed; /* Entity is despawned from the current world */
|
||||
} EntityEvents;
|
||||
|
||||
extern struct Event_Void TextureEvents_AtlasChanged; /* Terrain atlas (terrain.png) is changed */
|
||||
extern struct Event_Void TextureEvents_PackChanged; /* Texture pack is changed */
|
||||
extern struct Event_Entry TextureEvents_FileChanged; /* File in a texture pack is changed (terrain.png, rain.png) */
|
||||
extern struct _TabListEventsList {
|
||||
struct Event_Int Added; /* Tab list entry is created */
|
||||
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 Event_Void GfxEvents_LowVRAMDetected; /* Insufficient VRAM detected, need to free some GPU resources */
|
||||
extern struct Event_Void GfxEvents_ProjectionChanged; /* Projection matrix has changed */
|
||||
extern struct Event_Void GfxEvents_ContextLost; /* Context is destroyed after having been previously created */
|
||||
extern struct Event_Void GfxEvents_ContextRecreated; /* Context is recreated after having been previously lost */
|
||||
extern struct _TextureEventsList {
|
||||
struct Event_Void AtlasChanged; /* Terrain atlas (terrain.png) is changed */
|
||||
struct Event_Void PackChanged; /* Texture pack is changed */
|
||||
struct Event_Entry FileChanged; /* File in a texture pack is changed (terrain.png, rain.png) */
|
||||
} TextureEvents;
|
||||
|
||||
extern struct Event_Block UserEvents_BlockChanged; /* User changes a block */
|
||||
extern struct Event_Void UserEvents_HackPermissionsChanged; /* Hack permissions of the player changes */
|
||||
extern struct Event_Void UserEvents_HeldBlockChanged; /* Held block in hotbar changes */
|
||||
extern struct _GfxEventsList {
|
||||
struct Event_Void ViewDistanceChanged; /* View/fog distance is changed */
|
||||
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 Event_Void BlockEvents_BlockDefChanged; /* Block definition is changed or removed */
|
||||
extern struct _UserEventsList {
|
||||
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 Event_Float WorldEvents_Loading; /* Portion of world is decompressed/generated (Arg is progress from 0-1) */
|
||||
extern struct Event_Void WorldEvents_MapLoaded; /* New world has finished loading, player can now interact with it */
|
||||
extern struct Event_Int WorldEvents_EnvVarChanged; /* World environment variable changed by player/CPE/WoM config */
|
||||
extern struct _BlockEventsList {
|
||||
struct Event_Void PermissionsChanged; /* Block permissions (can place/delete) for a block changes */
|
||||
struct Event_Void BlockDefChanged; /* Block definition is changed or removed */
|
||||
} BlockEvents;
|
||||
|
||||
extern struct Event_Void ChatEvents_FontChanged; /* User changes whether system chat font used, and when the bitmapped font texture changes */
|
||||
extern struct Event_Chat ChatEvents_ChatReceived; /* Raised when message is being added to chat */
|
||||
extern struct Event_Chat ChatEvents_ChatSending; /* Raised when user sends a message */
|
||||
extern struct Event_Int ChatEvents_ColCodeChanged; /* Raised when a colour code changes */
|
||||
extern struct _WorldEventsList {
|
||||
struct Event_Void NewMap; /* Player begins loading a new world */
|
||||
struct Event_Float Loading; /* Portion of world is decompressed/generated (Arg is progress from 0-1) */
|
||||
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 Event_Void WindowEvents_Moved; /* Window is moved */
|
||||
extern struct Event_Void WindowEvents_Resized; /* Window is resized */
|
||||
extern struct Event_Void WindowEvents_Closing; /* Window is about to close */
|
||||
extern struct Event_Void WindowEvents_Closed; /* Window has closed */
|
||||
extern struct Event_Void WindowEvents_VisibilityChanged; /* Visibility of the window changed */
|
||||
extern struct Event_Void WindowEvents_FocusChanged; /* Focus of the window changed */
|
||||
extern struct Event_Void WindowEvents_StateChanged; /* WindowState of the window changed */
|
||||
extern struct _ChatEventsList {
|
||||
struct Event_Void FontChanged; /* User changes whether system chat font used, and when the bitmapped font texture changes */
|
||||
struct Event_Chat ChatReceived; /* Raised when message is being added to chat */
|
||||
struct Event_Chat ChatSending; /* Raised when user sends a message */
|
||||
struct Event_Int ColCodeChanged; /* Raised when a colour code changes */
|
||||
} ChatEvents;
|
||||
|
||||
extern struct Event_Int KeyEvents_Press; /* Raised when a character is typed. Arg is a character */
|
||||
extern struct Event_Int KeyEvents_Down; /* Raised when a key is pressed. Arg is a member of Key enumeration */
|
||||
extern struct Event_Int KeyEvents_Up; /* Raised when a key is released. Arg is a member of Key enumeration */
|
||||
extern struct _WindowEventsList {
|
||||
struct Event_Void Redraw; /* Window contents invalidated, should be redrawn */
|
||||
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) */
|
||||
extern struct Event_Int MouseEvents_Down; /* Mouse button is pressed (Arg is MouseButton member) */
|
||||
extern struct Event_Int MouseEvents_Up; /* Mouse button is released (Arg is MouseButton member) */
|
||||
extern struct Event_Float MouseEvents_Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
||||
struct _KeyEventsList {
|
||||
struct Event_Int Press; /* Raised when a character is typed. Arg is a character */
|
||||
struct Event_Int Down; /* Raised when a key is pressed. Arg is a member of Key enumeration */
|
||||
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
|
||||
|
|
|
@ -60,7 +60,7 @@ void Map_LoadFrom(const String* path) {
|
|||
ReturnCode res;
|
||||
|
||||
World_Reset();
|
||||
Event_RaiseVoid(&WorldEvents_NewMap);
|
||||
Event_RaiseVoid(&WorldEvents.NewMap);
|
||||
Game_Reset();
|
||||
|
||||
res = Stream_OpenFile(&stream, path);
|
||||
|
@ -76,7 +76,7 @@ void Map_LoadFrom(const String* path) {
|
|||
if (res) { Logger_Warn2(res, "closing", path); }
|
||||
|
||||
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);
|
||||
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
||||
|
@ -527,7 +527,7 @@ static void Cw_Callback_4(struct NbtTag* tag) {
|
|||
Block_DefineCustom(id);
|
||||
Block_CanPlace[id] = true;
|
||||
Block_CanDelete[id] = true;
|
||||
Event_RaiseVoid(&BlockEvents_PermissionsChanged);
|
||||
Event_RaiseVoid(&BlockEvents.PermissionsChanged);
|
||||
|
||||
cw_curID = 0;
|
||||
}
|
||||
|
|
34
src/Game.c
34
src/Game.c
|
@ -148,7 +148,7 @@ bool Game_ChangeTerrainAtlas(Bitmap* atlas) {
|
|||
Atlas_Free();
|
||||
Atlas_Update(atlas);
|
||||
|
||||
Event_RaiseVoid(&TextureEvents_AtlasChanged);
|
||||
Event_RaiseVoid(&TextureEvents.AtlasChanged);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ void Game_SetViewDistance(int distance) {
|
|||
if (distance == Game_ViewDistance) return;
|
||||
Game_ViewDistance = distance;
|
||||
|
||||
Event_RaiseVoid(&GfxEvents_ViewDistanceChanged);
|
||||
Event_RaiseVoid(&GfxEvents.ViewDistanceChanged);
|
||||
Game_UpdateProjection();
|
||||
}
|
||||
|
||||
|
@ -172,12 +172,12 @@ void Game_UpdateProjection(void) {
|
|||
Camera_Active->GetProjection(&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) {
|
||||
World_Reset();
|
||||
Event_RaiseVoid(&WorldEvents_NewMap);
|
||||
Event_RaiseVoid(&WorldEvents.NewMap);
|
||||
Gui_FreeActive();
|
||||
Gui_SetActive(DisconnectScreen_MakeInstance(title, reason));
|
||||
Game_Reset();
|
||||
|
@ -438,13 +438,13 @@ static void Game_Load(void) {
|
|||
Game_UpdateClientSize();
|
||||
Game_LoadOptions();
|
||||
|
||||
Event_RegisterVoid(&WorldEvents_NewMap, NULL, Game_OnNewMapCore);
|
||||
Event_RegisterVoid(&WorldEvents_MapLoaded, NULL, Game_OnNewMapLoadedCore);
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Game_TextureChangedCore);
|
||||
Event_RegisterVoid(&GfxEvents_LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
|
||||
Event_RegisterVoid(&WorldEvents.NewMap, NULL, Game_OnNewMapCore);
|
||||
Event_RegisterVoid(&WorldEvents.MapLoaded, NULL, Game_OnNewMapLoadedCore);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Game_TextureChangedCore);
|
||||
Event_RegisterVoid(&GfxEvents.LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
|
||||
|
||||
Event_RegisterVoid(&WindowEvents_Resized, NULL, Game_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents_Closed, NULL, Game_Free);
|
||||
Event_RegisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents.Closed, NULL, Game_Free);
|
||||
|
||||
TextureCache_Init();
|
||||
/* TODO: Survival vs Creative game mode */
|
||||
|
@ -683,13 +683,13 @@ void Game_Free(void* obj) {
|
|||
struct IGameComponent* comp;
|
||||
Atlas_Free();
|
||||
|
||||
Event_UnregisterVoid(&WorldEvents_NewMap, NULL, Game_OnNewMapCore);
|
||||
Event_UnregisterVoid(&WorldEvents_MapLoaded, NULL, Game_OnNewMapLoadedCore);
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Game_TextureChangedCore);
|
||||
Event_UnregisterVoid(&GfxEvents_LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
|
||||
Event_UnregisterVoid(&WorldEvents.NewMap, NULL, Game_OnNewMapCore);
|
||||
Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, Game_OnNewMapLoadedCore);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Game_TextureChangedCore);
|
||||
Event_UnregisterVoid(&GfxEvents.LowVRAMDetected, NULL, Game_OnLowVRAMDetected);
|
||||
|
||||
Event_UnregisterVoid(&WindowEvents_Resized, NULL, Game_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents_Closed, NULL, Game_Free);
|
||||
Event_UnregisterVoid(&WindowEvents.Resized, NULL, Game_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents.Closed, NULL, Game_Free);
|
||||
|
||||
for (comp = comps_head; comp; comp = comp->Next) {
|
||||
if (comp->Free) comp->Free();
|
||||
|
@ -713,7 +713,7 @@ void Game_Run(int width, int height, const String* title) {
|
|||
Window_SetVisible(true);
|
||||
|
||||
Game_Load();
|
||||
Event_RaiseVoid(&WindowEvents_Resized);
|
||||
Event_RaiseVoid(&WindowEvents.Resized);
|
||||
|
||||
lastRender = Stopwatch_Measure();
|
||||
for (;;) {
|
||||
|
|
|
@ -61,7 +61,7 @@ void Gfx_LoseContext(const char* reason) {
|
|||
Gfx_LostContext = true;
|
||||
Platform_Log1("Lost graphics context: %c", reason);
|
||||
|
||||
Event_RaiseVoid(&GfxEvents_ContextLost);
|
||||
Event_RaiseVoid(&GfxEvents.ContextLost);
|
||||
Gfx_FreeDefaultResources();
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ void Gfx_RecreateContext(void) {
|
|||
Gfx_LostContext = false;
|
||||
Platform_LogConst("Recreating graphics context");
|
||||
|
||||
Event_RaiseVoid(&GfxEvents_ContextRecreated);
|
||||
Event_RaiseVoid(&GfxEvents.ContextRecreated);
|
||||
Gfx_InitDefaultResources();
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count) {
|
|||
if (!res) break;
|
||||
|
||||
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);
|
||||
|
|
16
src/Gui.c
16
src/Gui.c
|
@ -30,16 +30,16 @@ void Gui_DefaultRecreate(void* elem) {
|
|||
|
||||
void Screen_CommonInit(void* screen) {
|
||||
struct Screen* s = screen;
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, s, s->VTABLE->ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, s, s->VTABLE->ContextRecreated);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, s, s->VTABLE->ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, s, s->VTABLE->ContextRecreated);
|
||||
|
||||
if (Gfx_LostContext) return;
|
||||
s->VTABLE->ContextRecreated(s);
|
||||
}
|
||||
|
||||
void Screen_CommonFree(void* screen) { struct Screen* s = screen;
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, s, s->VTABLE->ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, s, s->VTABLE->ContextRecreated);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, s, s->VTABLE->ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, s, s->VTABLE->ContextRecreated);
|
||||
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) {
|
||||
Event_RegisterVoid(&ChatEvents_FontChanged, NULL, Gui_FontChanged);
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Gui_FileChanged);
|
||||
Event_RegisterVoid(&ChatEvents.FontChanged, NULL, Gui_FontChanged);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Gui_FileChanged);
|
||||
Gui_LoadOptions();
|
||||
|
||||
Gui_Status = StatusScreen_MakeInstance();
|
||||
|
@ -140,8 +140,8 @@ static void Gui_Reset(void) {
|
|||
}
|
||||
|
||||
static void Gui_Free(void) {
|
||||
Event_UnregisterVoid(&ChatEvents_FontChanged, NULL, Gui_FontChanged);
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Gui_FileChanged);
|
||||
Event_UnregisterVoid(&ChatEvents.FontChanged, NULL, Gui_FontChanged);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Gui_FileChanged);
|
||||
Gui_CloseActive();
|
||||
Elem_TryFree(Gui_Status);
|
||||
Elem_TryFree(Gui_HUD);
|
||||
|
|
|
@ -241,15 +241,15 @@ static void HeldBlockRenderer_Init(void) {
|
|||
HeldBlockRenderer_Show = Options_GetBool(OPT_SHOW_BLOCK_IN_HAND, true);
|
||||
held_lastBlock = Inventory_SelectedBlock;
|
||||
|
||||
Event_RegisterVoid(&GfxEvents_ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
|
||||
Event_RegisterVoid(&UserEvents_HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
|
||||
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
||||
Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
|
||||
Event_RegisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
|
||||
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
||||
}
|
||||
|
||||
static void HeldBlockRenderer_Free(void) {
|
||||
Event_UnregisterVoid(&GfxEvents_ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
|
||||
Event_UnregisterVoid(&UserEvents_HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
|
||||
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
||||
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, HeldBlockRenderer_ProjectionChanged);
|
||||
Event_UnregisterVoid(&UserEvents.HeldBlockChanged, NULL, HeldBlockRenderer_DoSwitchBlockAnim);
|
||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, HeldBlockRenderer_BlockChanged);
|
||||
}
|
||||
|
||||
struct IGameComponent HeldBlockRenderer_Component = {
|
||||
|
|
12
src/Input.c
12
src/Input.c
|
@ -72,9 +72,9 @@ void Key_SetPressed(Key key, bool pressed) {
|
|||
Key_Pressed[key] = pressed;
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInt(&KeyEvents_Down, key);
|
||||
Event_RaiseInt(&KeyEvents.Down, key);
|
||||
} 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;
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInt(&MouseEvents_Down, btn);
|
||||
Event_RaiseInt(&MouseEvents.Down, btn);
|
||||
} else {
|
||||
Event_RaiseInt(&MouseEvents_Up, btn);
|
||||
Event_RaiseInt(&MouseEvents.Up, btn);
|
||||
}
|
||||
}
|
||||
|
||||
void Mouse_SetWheel(float wheel) {
|
||||
float delta = wheel - Mouse_Wheel;
|
||||
Mouse_Wheel = wheel;
|
||||
Event_RaiseFloat(&MouseEvents_Wheel, delta);
|
||||
Event_RaiseFloat(&MouseEvents.Wheel, delta);
|
||||
}
|
||||
|
||||
void Mouse_SetPosition(int x, int y) {
|
||||
int deltaX = x - Mouse_X, deltaY = y - Mouse_Y;
|
||||
Mouse_X = x; Mouse_Y = y;
|
||||
Event_RaiseMouseMove(&MouseEvents_Moved, deltaX, deltaY);
|
||||
Event_RaiseMouseMove(&MouseEvents.Moved, deltaX, deltaY);
|
||||
}
|
||||
|
||||
|
||||
|
|
10
src/Input.h
10
src/Input.h
|
@ -80,10 +80,10 @@ extern const char* Key_Names[KEY_COUNT];
|
|||
/* Pressed state of each keyboard button. Use Key_SetPressed to change. */
|
||||
extern bool Key_Pressed[KEY_COUNT];
|
||||
/* 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);
|
||||
/* 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);
|
||||
|
||||
|
||||
|
@ -100,11 +100,11 @@ extern int Mouse_X, Mouse_Y;
|
|||
/* Pressed state of each mouse button. Use Mouse_SetPressed to change. */
|
||||
extern bool Mouse_Pressed[MOUSE_COUNT];
|
||||
/* 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);
|
||||
/* 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);
|
||||
/* 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);
|
||||
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ static bool InputHandler_HandleNonClassicKey(Key key) {
|
|||
/* Don't assign SelectedIndex directly, because we don't want held block
|
||||
switching positions if they already have air in their inventory hotbar. */
|
||||
Inventory_Set(Inventory_SelectedIndex, BLOCK_AIR);
|
||||
Event_RaiseVoid(&UserEvents_HeldBlockChanged);
|
||||
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
|
||||
}
|
||||
} else if (key == KeyBind_Get(KEYBIND_IDOVERLAY)) {
|
||||
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;
|
||||
|
||||
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) {
|
||||
p = Game_SelectedPos.TranslatedPos;
|
||||
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;
|
||||
|
||||
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) {
|
||||
p = Game_SelectedPos.BlockPos;
|
||||
if (!World_IsValidPos_3I(p)) return;
|
||||
|
@ -500,13 +500,13 @@ static void InputHandler_KeyPress(void* obj, int keyChar) {
|
|||
}
|
||||
|
||||
void InputHandler_Init(void) {
|
||||
Event_RegisterFloat(&MouseEvents_Wheel, NULL, InputHandler_MouseWheel);
|
||||
Event_RegisterMouseMove(&MouseEvents_Moved, NULL, InputHandler_MouseMove);
|
||||
Event_RegisterInt(&MouseEvents_Down, NULL, InputHandler_MouseDown);
|
||||
Event_RegisterInt(&MouseEvents_Up, NULL, InputHandler_MouseUp);
|
||||
Event_RegisterInt(&KeyEvents_Down, NULL, InputHandler_KeyDown);
|
||||
Event_RegisterInt(&KeyEvents_Up, NULL, InputHandler_KeyUp);
|
||||
Event_RegisterInt(&KeyEvents_Press, NULL, InputHandler_KeyPress);
|
||||
Event_RegisterFloat(&MouseEvents.Wheel, NULL, InputHandler_MouseWheel);
|
||||
Event_RegisterMouseMove(&MouseEvents.Moved, NULL, InputHandler_MouseMove);
|
||||
Event_RegisterInt(&MouseEvents.Down, NULL, InputHandler_MouseDown);
|
||||
Event_RegisterInt(&MouseEvents.Up, NULL, InputHandler_MouseUp);
|
||||
Event_RegisterInt(&KeyEvents.Down, NULL, InputHandler_KeyDown);
|
||||
Event_RegisterInt(&KeyEvents.Up, NULL, InputHandler_KeyUp);
|
||||
Event_RegisterInt(&KeyEvents.Press, NULL, InputHandler_KeyPress);
|
||||
|
||||
KeyBind_Init();
|
||||
Hotkeys_Init();
|
||||
|
|
|
@ -24,13 +24,13 @@ bool Inventory_CheckChangeSelected(void) {
|
|||
void Inventory_SetSelectedIndex(int index) {
|
||||
if (!Inventory_CheckChangeSelected()) return;
|
||||
Inventory_SelectedIndex = index;
|
||||
Event_RaiseVoid(&UserEvents_HeldBlockChanged);
|
||||
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
|
||||
}
|
||||
|
||||
void Inventory_SetHotbarIndex(int index) {
|
||||
if (!Inventory_CheckChangeSelected() || Game_ClassicMode) return;
|
||||
Inventory_Offset = index * INVENTORY_BLOCKS_PER_HOTBAR;
|
||||
Event_RaiseVoid(&UserEvents_HeldBlockChanged);
|
||||
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
|
||||
}
|
||||
|
||||
void Inventory_SetSelectedBlock(BlockID block) {
|
||||
|
@ -45,7 +45,7 @@ void Inventory_SetSelectedBlock(BlockID block) {
|
|||
}
|
||||
|
||||
Inventory_Set(Inventory_SelectedIndex, block);
|
||||
Event_RaiseVoid(&UserEvents_HeldBlockChanged);
|
||||
Event_RaiseVoid(&UserEvents.HeldBlockChanged);
|
||||
}
|
||||
|
||||
const static uint8_t inv_classicTable[] = {
|
||||
|
|
|
@ -167,17 +167,17 @@ static void Launcher_Display(void) {
|
|||
static void Launcher_Init(void) {
|
||||
BitmapCol col = BITMAPCOL_CONST(125, 125, 125, 255);
|
||||
|
||||
Event_RegisterVoid(&WindowEvents_Resized, NULL, Launcher_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents_StateChanged, NULL, Launcher_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents_FocusChanged, NULL, Launcher_MaybeRedraw);
|
||||
Event_RegisterVoid(&WindowEvents_Redraw, NULL, Launcher_ReqeustRedraw);
|
||||
Event_RegisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize);
|
||||
Event_RegisterVoid(&WindowEvents.FocusChanged, NULL, Launcher_MaybeRedraw);
|
||||
Event_RegisterVoid(&WindowEvents.Redraw, NULL, Launcher_ReqeustRedraw);
|
||||
|
||||
Event_RegisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown);
|
||||
Event_RegisterInt(&KeyEvents_Press, NULL, Launcher_KeyPress);
|
||||
Event_RegisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown);
|
||||
Event_RegisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp);
|
||||
Event_RegisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove);
|
||||
Event_RegisterFloat(&MouseEvents_Wheel, NULL, Launcher_MouseWheel);
|
||||
Event_RegisterInt(&KeyEvents.Down, NULL, Launcher_KeyDown);
|
||||
Event_RegisterInt(&KeyEvents.Press, NULL, Launcher_KeyPress);
|
||||
Event_RegisterInt(&MouseEvents.Down, NULL, Launcher_MouseDown);
|
||||
Event_RegisterInt(&MouseEvents.Up, NULL, Launcher_MouseUp);
|
||||
Event_RegisterMouseMove(&MouseEvents.Moved, NULL, Launcher_MouseMove);
|
||||
Event_RegisterFloat(&MouseEvents.Wheel, NULL, Launcher_MouseWheel);
|
||||
|
||||
Drawer2D_MakeFont(&logoFont, 32, FONT_STYLE_NORMAL);
|
||||
Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_STYLE_BOLD);
|
||||
|
@ -191,17 +191,17 @@ static void Launcher_Init(void) {
|
|||
|
||||
static void Launcher_Free(void) {
|
||||
int i;
|
||||
Event_UnregisterVoid(&WindowEvents_Resized, NULL, Launcher_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents_StateChanged, NULL, Launcher_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents_FocusChanged, NULL, Launcher_MaybeRedraw);
|
||||
Event_UnregisterVoid(&WindowEvents_Redraw, NULL, Launcher_ReqeustRedraw);
|
||||
Event_UnregisterVoid(&WindowEvents.Resized, NULL, Launcher_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents.StateChanged, NULL, Launcher_OnResize);
|
||||
Event_UnregisterVoid(&WindowEvents.FocusChanged, NULL, Launcher_MaybeRedraw);
|
||||
Event_UnregisterVoid(&WindowEvents.Redraw, NULL, Launcher_ReqeustRedraw);
|
||||
|
||||
Event_UnregisterInt(&KeyEvents_Down, NULL, Launcher_KeyDown);
|
||||
Event_UnregisterInt(&KeyEvents_Press, NULL, Launcher_KeyPress);
|
||||
Event_UnregisterInt(&MouseEvents_Down, NULL, Launcher_MouseDown);
|
||||
Event_UnregisterInt(&MouseEvents_Up, NULL, Launcher_MouseUp);
|
||||
Event_UnregisterMouseMove(&MouseEvents_Moved, NULL, Launcher_MouseMove);
|
||||
Event_UnregisterFloat(&MouseEvents_Wheel, NULL, Launcher_MouseWheel);
|
||||
Event_UnregisterInt(&KeyEvents.Down, NULL, Launcher_KeyDown);
|
||||
Event_UnregisterInt(&KeyEvents.Press, NULL, Launcher_KeyPress);
|
||||
Event_UnregisterInt(&MouseEvents.Down, NULL, Launcher_MouseDown);
|
||||
Event_UnregisterInt(&MouseEvents.Up, NULL, Launcher_MouseUp);
|
||||
Event_UnregisterMouseMove(&MouseEvents.Moved, NULL, Launcher_MouseMove);
|
||||
Event_UnregisterFloat(&MouseEvents.Wheel, NULL, Launcher_MouseWheel);
|
||||
|
||||
for (i = 0; i < FetchFlagsTask.NumDownloaded; i++) {
|
||||
Mem_Free(FetchFlagsTask.Bitmaps[i].Scan0);
|
||||
|
|
|
@ -751,14 +751,14 @@ static void MapRenderer_OnNewMapLoaded(void) {
|
|||
}
|
||||
|
||||
static void MapRenderer_Init(void) {
|
||||
Event_RegisterVoid(&TextureEvents_AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
|
||||
Event_RegisterInt(&WorldEvents_EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&BlockEvents_BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
|
||||
Event_RegisterVoid(&TextureEvents.AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
|
||||
Event_RegisterInt(&WorldEvents.EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&BlockEvents.BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
|
||||
|
||||
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_RegisterVoid(&GfxEvents_ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, MapRenderer_DeleteChunks_);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, MapRenderer_Refresh_);
|
||||
Event_RegisterVoid(&GfxEvents.ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_RegisterVoid(&GfxEvents.ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_Refresh_);
|
||||
|
||||
/* This = 87 fixes map being invisible when no textures */
|
||||
MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */
|
||||
|
@ -770,14 +770,14 @@ static void MapRenderer_Init(void) {
|
|||
}
|
||||
|
||||
static void MapRenderer_Free(void) {
|
||||
Event_UnregisterVoid(&TextureEvents_AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
|
||||
Event_UnregisterInt(&WorldEvents_EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&BlockEvents_BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
|
||||
Event_UnregisterVoid(&TextureEvents.AtlasChanged, NULL, MapRenderer_TerrainAtlasChanged);
|
||||
Event_UnregisterInt(&WorldEvents.EnvVarChanged, NULL, MapRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&BlockEvents.BlockDefChanged, NULL, MapRenderer_BlockDefinitionChanged);
|
||||
|
||||
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_UnregisterVoid(&GfxEvents_ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, MapRenderer_DeleteChunks_);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, MapRenderer_Refresh_);
|
||||
Event_UnregisterVoid(&GfxEvents.ViewDistanceChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_UnregisterVoid(&GfxEvents.ProjectionChanged, NULL, MapRenderer_RecalcVisibility_);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, MapRenderer_DeleteChunks_);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, MapRenderer_Refresh_);
|
||||
|
||||
MapRenderer_OnNewMap();
|
||||
}
|
||||
|
|
14
src/Menus.c
14
src/Menus.c
|
@ -312,7 +312,7 @@ static void Menu_Remove(void* screen, int i) {
|
|||
}
|
||||
|
||||
static void Menu_HandleFontChange(struct Screen* s) {
|
||||
Event_RaiseVoid(&ChatEvents_FontChanged);
|
||||
Event_RaiseVoid(&ChatEvents.FontChanged);
|
||||
Elem_Recreate(s);
|
||||
Gui_RefreshHud();
|
||||
Elem_HandlesMouseMove(s, Mouse_X, Mouse_Y);
|
||||
|
@ -659,13 +659,13 @@ static void PauseScreen_ContextRecreated(void* screen) {
|
|||
static void PauseScreen_Init(void* screen) {
|
||||
struct PauseScreen* s = screen;
|
||||
MenuScreen_Init(s);
|
||||
Event_RegisterVoid(&UserEvents_HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
|
||||
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
|
||||
}
|
||||
|
||||
static void PauseScreen_Free(void* screen) {
|
||||
struct PauseScreen* s = screen;
|
||||
MenuScreen_Free(s);
|
||||
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
|
||||
Event_UnregisterVoid(&UserEvents.HackPermissionsChanged, s, PauseScreen_CheckHacksAllowed);
|
||||
}
|
||||
|
||||
static struct ScreenVTABLE PauseScreen_VTABLE = {
|
||||
|
@ -738,13 +738,13 @@ static void OptionsGroupScreen_ContextRecreated(void* screen) {
|
|||
static void OptionsGroupScreen_Init(void* screen) {
|
||||
struct OptionsGroupScreen* s = screen;
|
||||
MenuScreen_Init(s);
|
||||
Event_RegisterVoid(&UserEvents_HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed);
|
||||
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, OptionsGroupScreen_CheckHacksAllowed);
|
||||
}
|
||||
|
||||
static void OptionsGroupScreen_Free(void* screen) {
|
||||
struct OptionsGroupScreen* s = screen;
|
||||
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) {
|
||||
|
@ -2668,13 +2668,13 @@ static void HacksSettingsScreen_CheckHacksAllowed(void* screen) {
|
|||
static void HacksSettingsScreen_ContextLost(void* screen) {
|
||||
struct MenuOptionsScreen* s = screen;
|
||||
MenuOptionsScreen_ContextLost(s);
|
||||
Event_UnregisterVoid(&UserEvents_HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);
|
||||
Event_UnregisterVoid(&UserEvents.HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);
|
||||
}
|
||||
|
||||
static void HacksSettingsScreen_ContextRecreated(void* screen) {
|
||||
struct MenuOptionsScreen* s = screen;
|
||||
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,
|
||||
HacksSettingsScreen_GetHacks, HacksSettingsScreen_SetHacks);
|
||||
|
|
12
src/Model.c
12
src/Model.c
|
@ -1677,9 +1677,9 @@ void Models_Init(void) {
|
|||
Model_RegisterDefaultModels();
|
||||
Models_ContextRecreated(NULL);
|
||||
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Models_TextureChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Models_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Models_ContextRecreated);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
|
||||
}
|
||||
|
||||
void Models_Free(void) {
|
||||
|
@ -1690,9 +1690,9 @@ void Models_Free(void) {
|
|||
}
|
||||
Models_ContextLost(NULL);
|
||||
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Models_TextureChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Models_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Models_ContextRecreated);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
|
||||
}
|
||||
|
||||
struct IGameComponent Models_Component = {
|
||||
|
|
|
@ -125,16 +125,16 @@ static void Handlers_AddTablistEntry(EntityID id, const String* playerName, cons
|
|||
|| !String_Equals(groupName, &oldGroupName) || groupRank != oldGroupRank;
|
||||
if (changed) {
|
||||
TabList_Set(id, playerName, listName, groupName, groupRank);
|
||||
Event_RaiseInt(&TabListEvents_Changed, id);
|
||||
Event_RaiseInt(&TabListEvents.Changed, id);
|
||||
}
|
||||
} else {
|
||||
TabList_Set(id, playerName, listName, groupName, groupRank);
|
||||
Event_RaiseInt(&TabListEvents_Added, id);
|
||||
Event_RaiseInt(&TabListEvents.Added, id);
|
||||
}
|
||||
}
|
||||
|
||||
static void Handlers_RemoveTablistEntry(EntityID id) {
|
||||
Event_RaiseInt(&TabListEvents_Removed, id);
|
||||
Event_RaiseInt(&TabListEvents.Removed, 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);
|
||||
Entities_List[id] = &pl->Base;
|
||||
Event_RaiseInt(&EntityEvents_Added, id);
|
||||
Event_RaiseInt(&EntityEvents.Added, id);
|
||||
} else {
|
||||
p = &LocalPlayer_Instance;
|
||||
p->Base.VTABLE->Despawn(&p->Base);
|
||||
|
@ -407,7 +407,7 @@ static void Classic_Ping(uint8_t* data) { }
|
|||
|
||||
static void Classic_StartLoading(void) {
|
||||
World_Reset();
|
||||
Event_RaiseVoid(&WorldEvents_NewMap);
|
||||
Event_RaiseVoid(&WorldEvents.NewMap);
|
||||
Stream_ReadonlyMemory(&map_part, NULL, 0);
|
||||
|
||||
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;
|
||||
Event_RaiseFloat(&WorldEvents_Loading, progress);
|
||||
Event_RaiseFloat(&WorldEvents.Loading, progress);
|
||||
}
|
||||
|
||||
static void Classic_LevelFinalise(uint8_t* data) {
|
||||
|
@ -534,7 +534,7 @@ static void Classic_LevelFinalise(uint8_t* data) {
|
|||
}
|
||||
#endif
|
||||
|
||||
Event_RaiseVoid(&WorldEvents_MapLoaded);
|
||||
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
||||
WoM_CheckSendWomID();
|
||||
|
||||
map_blocks = NULL;
|
||||
|
@ -954,7 +954,7 @@ static void CPE_CustomBlockLevel(uint8_t* data) {
|
|||
CPE_WriteCustomBlockLevel(1);
|
||||
Net_SendPacket();
|
||||
Game_UseCPEBlocks = true;
|
||||
Event_RaiseVoid(&BlockEvents_PermissionsChanged);
|
||||
Event_RaiseVoid(&BlockEvents.PermissionsChanged);
|
||||
}
|
||||
|
||||
static void CPE_HoldThis(uint8_t* data) {
|
||||
|
@ -1100,7 +1100,7 @@ static void CPE_SetBlockPermission(uint8_t* data) {
|
|||
|
||||
Block_CanPlace[block] = *data++ != 0;
|
||||
Block_CanDelete[block] = *data++ != 0;
|
||||
Event_RaiseVoid(&BlockEvents_PermissionsChanged);
|
||||
Event_RaiseVoid(&BlockEvents.PermissionsChanged);
|
||||
}
|
||||
|
||||
static void CPE_ChangeModel(uint8_t* data) {
|
||||
|
@ -1157,7 +1157,7 @@ static void CPE_HackControl(uint8_t* data) {
|
|||
}
|
||||
|
||||
physics->ServerJumpVel = physics->JumpVel;
|
||||
Event_RaiseVoid(&UserEvents_HackPermissionsChanged);
|
||||
Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
|
||||
}
|
||||
|
||||
static void CPE_ExtAddEntity2(uint8_t* data) {
|
||||
|
@ -1227,7 +1227,7 @@ static void CPE_SetTextColor(uint8_t* data) {
|
|||
if (code == '%' || code == '&') return;
|
||||
|
||||
Drawer2D_Cols[code] = c;
|
||||
Event_RaiseInt(&ChatEvents_ColCodeChanged, code);
|
||||
Event_RaiseInt(&ChatEvents.ColCodeChanged, code);
|
||||
}
|
||||
|
||||
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); }
|
||||
|
||||
Block_SetCustomDefined(block, false);
|
||||
Event_RaiseVoid(&BlockEvents_BlockDefChanged);
|
||||
Event_RaiseVoid(&BlockEvents.BlockDefChanged);
|
||||
}
|
||||
|
||||
static void BlockDefs_DefineBlockExt(uint8_t* data) {
|
||||
|
|
|
@ -471,20 +471,20 @@ static void Particles_Init(void) {
|
|||
Random_InitFromCurrentTime(&rnd);
|
||||
Particles_ContextRecreated(NULL);
|
||||
|
||||
Event_RegisterBlock(&UserEvents_BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Particles_FileChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Particles_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Particles_ContextRecreated);
|
||||
Event_RegisterBlock(&UserEvents.BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Particles_FileChanged);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Particles_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Particles_ContextRecreated);
|
||||
}
|
||||
|
||||
static void Particles_Free(void) {
|
||||
Gfx_DeleteTexture(&Particles_TexId);
|
||||
Particles_ContextLost(NULL);
|
||||
|
||||
Event_UnregisterBlock(&UserEvents_BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Particles_FileChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Particles_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Particles_ContextRecreated);
|
||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, Particles_BreakBlockEffect_Handler);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Particles_FileChanged);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Particles_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Particles_ContextRecreated);
|
||||
}
|
||||
|
||||
static void Particles_Reset(void) { rain_count = 0; terrain_count = 0; }
|
||||
|
|
|
@ -111,14 +111,14 @@ static void PickedPosRenderer_ContextRecreated(void* obj) {
|
|||
|
||||
static void PickedPosRenderer_Init(void) {
|
||||
PickedPosRenderer_ContextRecreated(NULL);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, PickedPosRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, PickedPosRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
static void PickedPosRenderer_Free(void) {
|
||||
PickedPosRenderer_ContextLost(NULL);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, PickedPosRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, PickedPosRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, PickedPosRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
struct IGameComponent PickedPosRenderer_Component = {
|
||||
|
|
|
@ -150,8 +150,8 @@ static void InventoryScreen_Init(void* screen) {
|
|||
Key_KeyRepeat = true;
|
||||
Screen_CommonInit(s);
|
||||
|
||||
Event_RegisterVoid(&BlockEvents_PermissionsChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_RegisterVoid(&BlockEvents_BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_RegisterVoid(&BlockEvents.PermissionsChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_RegisterVoid(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
||||
}
|
||||
|
||||
static void InventoryScreen_Render(void* screen, double delta) {
|
||||
|
@ -171,8 +171,8 @@ static void InventoryScreen_Free(void* screen) {
|
|||
Key_KeyRepeat = false;
|
||||
Screen_CommonFree(s);
|
||||
|
||||
Event_UnregisterVoid(&BlockEvents_PermissionsChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_UnregisterVoid(&BlockEvents_BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_UnregisterVoid(&BlockEvents.PermissionsChanged, s, InventoryScreen_OnBlockChanged);
|
||||
Event_UnregisterVoid(&BlockEvents.BlockDefChanged, s, InventoryScreen_OnBlockChanged);
|
||||
}
|
||||
|
||||
static bool InventoryScreen_KeyDown(void* screen, Key key) {
|
||||
|
@ -568,7 +568,7 @@ static void LoadingScreen_Init(void* screen) {
|
|||
Screen_CommonInit(s);
|
||||
|
||||
Gfx_SetFog(false);
|
||||
Event_RegisterFloat(&WorldEvents_Loading, s, LoadingScreen_MapLoading);
|
||||
Event_RegisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
|
||||
}
|
||||
|
||||
#define PROG_BAR_WIDTH 200
|
||||
|
@ -599,7 +599,7 @@ static void LoadingScreen_Free(void* screen) {
|
|||
struct LoadingScreen* s = screen;
|
||||
Font_Free(&s->Font);
|
||||
Screen_CommonFree(s);
|
||||
Event_UnregisterFloat(&WorldEvents_Loading, s, LoadingScreen_MapLoading);
|
||||
Event_UnregisterFloat(&WorldEvents.Loading, s, LoadingScreen_MapLoading);
|
||||
}
|
||||
|
||||
static struct ScreenVTABLE LoadingScreen_VTABLE = {
|
||||
|
@ -632,7 +632,7 @@ struct Screen* LoadingScreen_UNSAFE_RawPointer = (struct Screen*)&LoadingScreen_
|
|||
*#########################################################################################################################*/
|
||||
static void GeneratingScreen_Init(void* screen) {
|
||||
World_Reset();
|
||||
Event_RaiseVoid(&WorldEvents_NewMap);
|
||||
Event_RaiseVoid(&WorldEvents.NewMap);
|
||||
Gen_Done = false;
|
||||
LoadingScreen_Init(screen);
|
||||
|
||||
|
@ -666,7 +666,7 @@ static void GeneratingScreen_EndGeneration(void) {
|
|||
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
||||
|
||||
Camera_CurrentPos = Camera_Active->GetPosition(0.0f);
|
||||
Event_RaiseVoid(&WorldEvents_MapLoaded);
|
||||
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
||||
}
|
||||
|
||||
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);
|
||||
Screen_CommonInit(s);
|
||||
|
||||
Event_RegisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived);
|
||||
Event_RegisterInt(&ChatEvents_ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
Event_RegisterChat(&ChatEvents.ChatReceived, s, ChatScreen_ChatReceived);
|
||||
Event_RegisterInt(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
}
|
||||
|
||||
static void ChatScreen_Render(void* screen, double delta) {
|
||||
|
@ -1176,8 +1176,8 @@ static void ChatScreen_Free(void* screen) {
|
|||
Font_Free(&s->AnnouncementFont);
|
||||
Screen_CommonFree(s);
|
||||
|
||||
Event_UnregisterChat(&ChatEvents_ChatReceived, s, ChatScreen_ChatReceived);
|
||||
Event_UnregisterInt(&ChatEvents_ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
Event_UnregisterChat(&ChatEvents.ChatReceived, s, ChatScreen_ChatReceived);
|
||||
Event_UnregisterInt(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
}
|
||||
|
||||
static struct ScreenVTABLE ChatScreen_VTABLE = {
|
||||
|
|
|
@ -208,8 +208,8 @@ void Selections_Render(double delta) {
|
|||
*--------------------------------------------------Selections component---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void Selections_Init(void) {
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, Selections_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, Selections_ContextRecreated);
|
||||
Event_RegisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
|
||||
}
|
||||
|
||||
static void Selections_Reset(void) {
|
||||
|
@ -218,8 +218,8 @@ static void Selections_Reset(void) {
|
|||
|
||||
static void Selections_Free(void) {
|
||||
Selections_ContextLost(NULL);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, Selections_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, Selections_ContextRecreated);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Selections_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Selections_ContextRecreated);
|
||||
}
|
||||
|
||||
struct IGameComponent Selections_Component = {
|
||||
|
|
|
@ -158,7 +158,7 @@ static void SPConnection_BeginConnect(void) {
|
|||
Block_CanPlace[i] = true;
|
||||
Block_CanDelete[i] = true;
|
||||
}
|
||||
Event_RaiseVoid(&BlockEvents_PermissionsChanged);
|
||||
Event_RaiseVoid(&BlockEvents.PermissionsChanged);
|
||||
|
||||
/* For when user drops a map file onto ClassiCube.exe */
|
||||
path = Game_Username;
|
||||
|
@ -274,7 +274,7 @@ static TimeMS net_connectTimeout;
|
|||
static void ServerConnection_Free(void);
|
||||
static void MPConnection_FinishConnect(void) {
|
||||
net_connecting = false;
|
||||
Event_RaiseFloat(&WorldEvents_Loading, 0.0f);
|
||||
Event_RaiseFloat(&WorldEvents.Loading, 0.0f);
|
||||
net_readCurrent = net_readBuffer;
|
||||
ServerConnection_WriteBuffer = net_writeBuffer;
|
||||
|
||||
|
@ -320,7 +320,7 @@ static void MPConnection_TickConnect(void) {
|
|||
MPConnection_FailConnect(0);
|
||||
} else {
|
||||
int leftMS = (int)(net_connectTimeout - now);
|
||||
Event_RaiseFloat(&WorldEvents_Loading, (float)leftMS / NET_TIMEOUT_MS);
|
||||
Event_RaiseFloat(&WorldEvents.Loading, (float)leftMS / NET_TIMEOUT_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -369,14 +369,14 @@ static void Animations_FileChanged(void* obj, struct Stream* stream, const Strin
|
|||
|
||||
static void Animations_Init(void) {
|
||||
ScheduledTask_Add(GAME_DEF_TICKS, Animations_Tick);
|
||||
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, Animations_PackChanged);
|
||||
Event_RegisterEntry(&TextureEvents_FileChanged, NULL, Animations_FileChanged);
|
||||
Event_RegisterVoid(&TextureEvents.PackChanged, NULL, Animations_PackChanged);
|
||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, Animations_FileChanged);
|
||||
}
|
||||
|
||||
static void Animations_Free(void) {
|
||||
Animations_Clear();
|
||||
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, Animations_PackChanged);
|
||||
Event_UnregisterEntry(&TextureEvents_FileChanged, NULL, Animations_FileChanged);
|
||||
Event_UnregisterVoid(&TextureEvents.PackChanged, NULL, Animations_PackChanged);
|
||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Animations_FileChanged);
|
||||
}
|
||||
|
||||
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) {
|
||||
String name = *path;
|
||||
Utils_UNSAFE_GetFilename(&name);
|
||||
Event_RaiseEntry(&TextureEvents_FileChanged, stream, &name);
|
||||
Event_RaiseEntry(&TextureEvents.FileChanged, stream, &name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ReturnCode TexturePack_ExtractZip(struct Stream* stream) {
|
||||
struct ZipState state;
|
||||
Event_RaiseVoid(&TextureEvents_PackChanged);
|
||||
Event_RaiseVoid(&TextureEvents.PackChanged);
|
||||
if (Gfx_LostContext) return 0;
|
||||
|
||||
Zip_Init(&state, stream);
|
||||
|
@ -662,7 +662,7 @@ ReturnCode TexturePack_ExtractTerrainPng(struct Stream* stream) {
|
|||
ReturnCode res = Png_Decode(&bmp, stream);
|
||||
|
||||
if (!res) {
|
||||
Event_RaiseVoid(&TextureEvents_PackChanged);
|
||||
Event_RaiseVoid(&TextureEvents.PackChanged);
|
||||
if (Game_ChangeTerrainAtlas(&bmp)) return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ extern GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES];
|
|||
#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */
|
||||
|
||||
/* 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);
|
||||
/* Loads the given tile into a new separate texture. */
|
||||
GfxResourceID Atlas_LoadTile(TextureLoc texLoc);
|
||||
|
|
|
@ -2146,9 +2146,9 @@ static void PlayerListWidget_Init(void* widget) {
|
|||
TextWidget_Create(&w->Title, &title, &w->Font);
|
||||
Widget_SetLocation(&w->Title, ANCHOR_CENTRE, ANCHOR_MIN, 0, 0);
|
||||
|
||||
Event_RegisterInt(&TabListEvents_Added, w, PlayerListWidget_TabEntryAdded);
|
||||
Event_RegisterInt(&TabListEvents_Changed, w, PlayerListWidget_TabEntryChanged);
|
||||
Event_RegisterInt(&TabListEvents_Removed, w, PlayerListWidget_TabEntryRemoved);
|
||||
Event_RegisterInt(&TabListEvents.Added, w, PlayerListWidget_TabEntryAdded);
|
||||
Event_RegisterInt(&TabListEvents.Changed, w, PlayerListWidget_TabEntryChanged);
|
||||
Event_RegisterInt(&TabListEvents.Removed, w, PlayerListWidget_TabEntryRemoved);
|
||||
}
|
||||
|
||||
static void PlayerListWidget_Render(void* widget, double delta) {
|
||||
|
@ -2188,9 +2188,9 @@ static void PlayerListWidget_Free(void* widget) {
|
|||
}
|
||||
|
||||
Elem_TryFree(&w->Title);
|
||||
Event_UnregisterInt(&TabListEvents_Added, w, PlayerListWidget_TabEntryAdded);
|
||||
Event_UnregisterInt(&TabListEvents_Changed, w, PlayerListWidget_TabEntryChanged);
|
||||
Event_UnregisterInt(&TabListEvents_Removed, w, PlayerListWidget_TabEntryRemoved);
|
||||
Event_UnregisterInt(&TabListEvents.Added, w, PlayerListWidget_TabEntryAdded);
|
||||
Event_UnregisterInt(&TabListEvents.Changed, w, PlayerListWidget_TabEntryChanged);
|
||||
Event_UnregisterInt(&TabListEvents.Removed, w, PlayerListWidget_TabEntryRemoved);
|
||||
}
|
||||
|
||||
static struct WidgetVTABLE PlayerListWidget_VTABLE = {
|
||||
|
|
52
src/Window.c
52
src/Window.c
|
@ -182,12 +182,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
Window_Focused = LOWORD(wParam) != 0;
|
||||
|
||||
if (Window_Focused != wasFocused) {
|
||||
Event_RaiseVoid(&WindowEvents_FocusChanged);
|
||||
Event_RaiseVoid(&WindowEvents.FocusChanged);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
Event_RaiseVoid(&WindowEvents_Redraw);
|
||||
Event_RaiseVoid(&WindowEvents.Redraw);
|
||||
return 1;
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
@ -209,7 +209,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
|
||||
|
||||
if (suppress_resize <= 0) {
|
||||
Event_RaiseVoid(&WindowEvents_Resized);
|
||||
Event_RaiseVoid(&WindowEvents.Resized);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -236,14 +236,14 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
|
||||
if (new_state != win_state) {
|
||||
win_state = new_state;
|
||||
Event_RaiseVoid(&WindowEvents_StateChanged);
|
||||
Event_RaiseVoid(&WindowEvents.StateChanged);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
||||
case WM_CHAR:
|
||||
if (Convert_TryUnicodeToCP437((Codepoint)wParam, &keyChar)) {
|
||||
Event_RaiseInt(&KeyEvents_Press, keyChar);
|
||||
Event_RaiseInt(&KeyEvents.Press, keyChar);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -356,7 +356,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
} break;
|
||||
|
||||
case WM_CLOSE:
|
||||
Event_RaiseVoid(&WindowEvents_Closing);
|
||||
Event_RaiseVoid(&WindowEvents.Closing);
|
||||
Window_Destroy();
|
||||
break;
|
||||
|
||||
|
@ -364,7 +364,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||
Window_Exists = false;
|
||||
UnregisterClass(CC_WIN_CLASSNAME, win_instance);
|
||||
if (win_DC) ReleaseDC(win_handle, win_DC);
|
||||
Event_RaiseVoid(&WindowEvents_Closed);
|
||||
Event_RaiseVoid(&WindowEvents.Closed);
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
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.
|
||||
|
@ -907,7 +907,7 @@ static void Window_RefreshBounds(XEvent* e) {
|
|||
if (size.Width != Window_Bounds.Width || size.Height != Window_Bounds.Height) {
|
||||
Window_ClientSize.Width = e->xconfigure.width; Window_Bounds.Width = size.Width;
|
||||
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;
|
||||
|
||||
if (win_visible != wasVisible) {
|
||||
Event_RaiseVoid(&WindowEvents_VisibilityChanged);
|
||||
Event_RaiseVoid(&WindowEvents.VisibilityChanged);
|
||||
}
|
||||
break;
|
||||
|
||||
case ClientMessage:
|
||||
if (!win_isExiting && e.xclient.data.l[0] == wm_destroy) {
|
||||
Platform_LogConst("Exit message received.");
|
||||
Event_RaiseVoid(&WindowEvents_Closing);
|
||||
Event_RaiseVoid(&WindowEvents.Closing);
|
||||
|
||||
win_isExiting = true;
|
||||
Window_Destroy();
|
||||
Event_RaiseVoid(&WindowEvents_Closed);
|
||||
Event_RaiseVoid(&WindowEvents.Closed);
|
||||
} break;
|
||||
|
||||
case DestroyNotify:
|
||||
|
@ -1219,7 +1219,7 @@ void Window_ProcessEvents(void) {
|
|||
|
||||
case Expose:
|
||||
if (e.xexpose.count == 0) {
|
||||
Event_RaiseVoid(&WindowEvents_Redraw);
|
||||
Event_RaiseVoid(&WindowEvents.Redraw);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1233,7 +1233,7 @@ void Window_ProcessEvents(void) {
|
|||
char raw; int i;
|
||||
for (i = 0; i < status; i++) {
|
||||
if (!Convert_TryUnicodeToCP437((uint8_t)data[i], &raw)) continue;
|
||||
Event_RaiseInt(&KeyEvents_Press, raw);
|
||||
Event_RaiseInt(&KeyEvents.Press, raw);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -1273,7 +1273,7 @@ void Window_ProcessEvents(void) {
|
|||
Window_Focused = e.type == FocusIn;
|
||||
|
||||
if (Window_Focused != wasFocused) {
|
||||
Event_RaiseVoid(&WindowEvents_FocusChanged);
|
||||
Event_RaiseVoid(&WindowEvents.FocusChanged);
|
||||
}
|
||||
/* TODO: Keep track of keyboard when focus is lost */
|
||||
if (!Window_Focused) Key_Clear();
|
||||
|
@ -1288,7 +1288,7 @@ void Window_ProcessEvents(void) {
|
|||
|
||||
case PropertyNotify:
|
||||
if (e.xproperty.atom == net_wm_state) {
|
||||
Event_RaiseVoid(&WindowEvents_StateChanged);
|
||||
Event_RaiseVoid(&WindowEvents.StateChanged);
|
||||
}
|
||||
|
||||
/*if (e.xproperty.atom == net_frame_extents) {
|
||||
|
@ -1886,9 +1886,9 @@ static void Window_UpdateWindowState(void) {
|
|||
break;
|
||||
}
|
||||
|
||||
Event_RaiseVoid(&WindowEvents_StateChanged);
|
||||
Event_RaiseVoid(&WindowEvents.StateChanged);
|
||||
Window_UpdateSize();
|
||||
Event_RaiseVoid(&WindowEvents_Resized);
|
||||
Event_RaiseVoid(&WindowEvents.Resized);
|
||||
}
|
||||
|
||||
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 */
|
||||
/* Look at documentation for kEventRawKeyRepeat */
|
||||
if (!Convert_TryUnicodeToCP437((uint8_t)charCode, &raw)) return 0;
|
||||
Event_RaiseInt(&KeyEvents_Press, raw);
|
||||
Event_RaiseInt(&KeyEvents.Press, raw);
|
||||
return 0;
|
||||
|
||||
case kEventRawKeyUp:
|
||||
|
@ -1962,12 +1962,12 @@ OSStatus Window_ProcessWindowEvent(EventHandlerCallRef inCaller, EventRef inEven
|
|||
|
||||
switch (GetEventKind(inEvent)) {
|
||||
case kEventWindowClose:
|
||||
Event_RaiseVoid(&WindowEvents_Closing);
|
||||
Event_RaiseVoid(&WindowEvents.Closing);
|
||||
return eventNotHandledErr;
|
||||
|
||||
case kEventWindowClosed:
|
||||
Window_Exists = false;
|
||||
Event_RaiseVoid(&WindowEvents_Closed);
|
||||
Event_RaiseVoid(&WindowEvents.Closed);
|
||||
return 0;
|
||||
|
||||
case kEventWindowBoundsChanged:
|
||||
|
@ -1976,18 +1976,18 @@ OSStatus Window_ProcessWindowEvent(EventHandlerCallRef inCaller, EventRef inEven
|
|||
Window_UpdateSize();
|
||||
|
||||
if (width != Window_ClientSize.Width || height != Window_ClientSize.Height) {
|
||||
Event_RaiseVoid(&WindowEvents_Resized);
|
||||
Event_RaiseVoid(&WindowEvents.Resized);
|
||||
}
|
||||
return eventNotHandledErr;
|
||||
|
||||
case kEventWindowActivated:
|
||||
Window_Focused = true;
|
||||
Event_RaiseVoid(&WindowEvents_FocusChanged);
|
||||
Event_RaiseVoid(&WindowEvents.FocusChanged);
|
||||
return eventNotHandledErr;
|
||||
|
||||
case kEventWindowDeactivated:
|
||||
Window_Focused = false;
|
||||
Event_RaiseVoid(&WindowEvents_FocusChanged);
|
||||
Event_RaiseVoid(&WindowEvents.FocusChanged);
|
||||
return eventNotHandledErr;
|
||||
}
|
||||
return eventNotHandledErr;
|
||||
|
@ -2297,7 +2297,7 @@ void Window_SetClientSize(int width, int height) {
|
|||
}
|
||||
|
||||
void Window_Close(void) {
|
||||
Event_RaiseVoid(&WindowEvents_Closed);
|
||||
Event_RaiseVoid(&WindowEvents.Closed);
|
||||
/* TODO: Does this raise the event twice? */
|
||||
Window_Destroy();
|
||||
}
|
||||
|
|
|
@ -131,10 +131,10 @@ bool World_IsValidPos_3I(Vector3I p) {
|
|||
*-------------------------------------------------------Environment-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#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)\
|
||||
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" };
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue