From 399e73e861d65ea04685712b71c4954c6291d0df Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 13 Feb 2019 21:21:21 +1100 Subject: [PATCH] add connected/disconnected events for plugins --- src/Event.c | 1 + src/Event.h | 5 +++++ src/Game.c | 2 ++ src/Server.c | 4 +++- src/Window.c | 4 ++-- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Event.c b/src/Event.c index 8989fb0dc..88a6ab20a 100644 --- a/src/Event.c +++ b/src/Event.c @@ -12,6 +12,7 @@ struct _ChatEventsList ChatEvents; struct _WindowEventsList WindowEvents; struct _KeyEventsList KeyEvents; struct _MouseEventsList MouseEvents; +struct _NetEventsList NetEvents; void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler) { int i; diff --git a/src/Event.h b/src/Event.h index f953811ba..fcac15e41 100644 --- a/src/Event.h +++ b/src/Event.h @@ -187,4 +187,9 @@ CC_VAR extern struct _MouseEventsList { 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; + +CC_VAR extern struct _NetEventsList { + struct Event_Void Connected; /* Connection to a server was established. */ + struct Event_Void Disconnected; /* Connection to the server was lost. */ +} NetEvents; #endif diff --git a/src/Game.c b/src/Game.c index 15847fa76..1c4932c27 100644 --- a/src/Game.c +++ b/src/Game.c @@ -168,8 +168,10 @@ void Game_UpdateProjection(void) { } void Game_Disconnect(const String* title, const String* reason) { + Event_RaiseVoid(&NetEvents.Disconnected); World_Reset(); Event_RaiseVoid(&WorldEvents.NewMap); + Gui_FreeActive(); Gui_SetActive(DisconnectScreen_MakeInstance(title, reason)); Game_Reset(); diff --git a/src/Server.c b/src/Server.c index af5939876..9ebfd1a6d 100644 --- a/src/Server.c +++ b/src/Server.c @@ -265,8 +265,10 @@ static TimeMS net_connectTimeout; static void Server_Free(void); static void MPConnection_FinishConnect(void) { net_connecting = false; + Event_RaiseVoid(&NetEvents.Connected); Event_RaiseFloat(&WorldEvents.Loading, 0.0f); - net_readCurrent = net_readBuffer; + + net_readCurrent = net_readBuffer; Server.WriteBuffer = net_writeBuffer; Handlers_Reset(); diff --git a/src/Window.c b/src/Window.c index 47825dc83..dad55edba 100644 --- a/src/Window.c +++ b/src/Window.c @@ -58,7 +58,7 @@ static Rect2D prev_bounds; /* Used to restore previous size when leaving fullscr /*########################################################################################################################* *-----------------------------------------------------Private details-----------------------------------------------------* *#########################################################################################################################*/ -static uint8_t key_map[14 * 16] = { +const static uint8_t key_map[14 * 16] = { 0, 0, 0, 0, 0, 0, 0, 0, KEY_BACKSPACE, KEY_TAB, 0, 0, 0, KEY_ENTER, 0, 0, 0, 0, 0, KEY_PAUSE, KEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, KEY_ESCAPE, 0, 0, 0, 0, KEY_SPACE, KEY_PAGEUP, KEY_PAGEDOWN, KEY_END, KEY_HOME, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, 0, KEY_PRINTSCREEN, 0, KEY_PRINTSCREEN, KEY_INSERT, KEY_DELETE, 0, @@ -1739,7 +1739,7 @@ static bool ctx_pendingWindowed, ctx_pendingFullscreen; *-----------------------------------------------------Private details-----------------------------------------------------* *#########################################################################################################################*/ /* Sourced from https://www.meandmark.com/keycodes.html */ -static uint8_t key_map[8 * 16] = { +const static uint8_t key_map[8 * 16] = { 'A', 'S', 'D', 'F', 'H', 'G', 'Z', 'X', 'C', 'V', 0, 'B', 'Q', 'W', 'E', 'R', 'Y', 'T', '1', '2', '3', '4', '6', '5', KEY_PLUS, '9', '7', KEY_MINUS, '8', '0', KEY_RBRACKET, 'O', 'U', KEY_LBRACKET, 'I', 'P', KEY_ENTER, 'L', 'J', KEY_QUOTE, 'K', KEY_SEMICOLON, KEY_BACKSLASH, KEY_COMMA, KEY_SLASH, 'N', 'M', KEY_PERIOD,