From: Mario Date: Sun, 27 Sep 2015 08:33:01 +0000 (+1000) Subject: Make minigames use the registry system X-Git-Tag: xonotic-v0.8.2~1899 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=13b3855f3bb15ac77e0cf442158b2f005f8256ec;p=xonotic%2Fxonotic-data.pk3dir.git Make minigames use the registry system --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 5dec3202f..ca31f32f7 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -151,8 +151,6 @@ void CSQC_Init(void) CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels); - initialize_minigames(); - // precaches Projectile_Precache(); diff --git a/qcsrc/common/minigames/cl_minigames.qc b/qcsrc/common/minigames/cl_minigames.qc index f89669682..38614c7d4 100644 --- a/qcsrc/common/minigames/cl_minigames.qc +++ b/qcsrc/common/minigames/cl_minigames.qc @@ -42,27 +42,6 @@ bool minigame_hud_mouse_in(vector pos, vector sz) mousepos_y >= pos_y && mousepos_y < pos_y + sz_y ; } -void initialize_minigames() -{ - entity last_minig = world; - entity minig; - #define MINIGAME(name,nicename) \ - minig = spawn(); \ - minig.classname = "minigame_descriptor"; \ - minig.netname = strzone(strtolower(#name)); \ - minig.message = nicename; \ - minig.minigame_hud_board = name##_hud_board; \ - minig.minigame_hud_status = name##_hud_status; \ - minig.minigame_event = name##_client_event; \ - if ( !last_minig ) minigame_descriptors = minig; \ - else last_minig.list_next = minig; \ - last_minig = minig; - - REGISTERED_MINIGAMES - - #undef MINIGAME -} - string minigame_texture_skin(string skinname, string name) { return sprintf("gfx/hud/%s/minigames/%s", skinname, name); diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh index a839b1106..76d109864 100644 --- a/qcsrc/common/minigames/cl_minigames.qh +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -79,9 +79,6 @@ string minigame_texture(string name); // For minigame_player: player server slot, don't use for anything else .float minigame_playerslot; -// register all minigames -void initialize_minigames(); - // client-side minigame session cleanup void deactivate_minigame(); @@ -118,4 +115,25 @@ void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_ar entityvar=world; \ while( (entityvar = findentity(entityvar,owner,active_minigame)) ) + +void RegisterMinigames(); +const int MINIGAMES_MAX = 24; +entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last; +int MINIGAMES_COUNT; +#define REGISTER_MINIGAME(name,nicename) \ + REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \ + void name##_hud_board(vector, vector); \ + void name##_hud_status(vector, vector); \ + int name##_client_event(entity, string, ...); \ + REGISTER_INIT_POST(MINIGAME, name) { \ + this.classname = "minigame_descriptor"; \ + this.netname = strzone(strtolower(#name)); \ + this.message = nicename; \ + this.minigame_hud_board = name##_hud_board; \ + this.minigame_hud_status = name##_hud_status; \ + this.minigame_event = name##_client_event; \ + } \ + REGISTER_INIT(MINIGAME, name) +REGISTER_REGISTRY(RegisterMinigames) + #endif diff --git a/qcsrc/common/minigames/cl_minigames_hud.qc b/qcsrc/common/minigames/cl_minigames_hud.qc index 11470ec13..b0dba86c1 100644 --- a/qcsrc/common/minigames/cl_minigames_hud.qc +++ b/qcsrc/common/minigames/cl_minigames_hud.qc @@ -211,18 +211,17 @@ void HUD_MinigameMenu_ClickCreate() {SELFPARAM(); if ( HUD_MinigameMenu_Click_ExpandCollapse() ) { - entity e; entity curr; entity prev = self; - for ( e = minigame_descriptors; e != world; e = e.list_next ) + FOREACH(MINIGAMES, true, LAMBDA( { curr = HUD_MinigameMenu_SpawnSubEntry( - e.message, HUD_MinigameMenu_ClickCreate_Entry, self ); - curr.netname = e.netname; - curr.model = strzone(minigame_texture(strcat(e.netname,"/icon"))); + it.message, HUD_MinigameMenu_ClickCreate_Entry, self ); + curr.netname = it.netname; + curr.model = strzone(minigame_texture(strcat(it.netname,"/icon"))); HUD_MinigameMenu_InsertEntry( curr, prev ); prev = curr; - } + })); } } diff --git a/qcsrc/common/minigames/minigame/all.qh b/qcsrc/common/minigames/minigame/all.qh index 0bc61357b..d3874e7aa 100644 --- a/qcsrc/common/minigames/minigame/all.qh +++ b/qcsrc/common/minigames/minigame/all.qh @@ -69,22 +69,6 @@ that .owner is set to the minigame session entity and .minigame_autoclean is tru #include "pp.qc" #include "snake.qc" -/** - * Registration: - * MINIGAME(id,"Name") - * id (QuakeC symbol) Game identifier, used to find the functions explained above - * "Name"(String) Human readable name for the game, shown in the UI - */ -#define REGISTERED_MINIGAMES \ - MINIGAME(nmm, "Nine Men's Morris") \ - MINIGAME(ttt, "Tic Tac Toe") \ - MINIGAME(pong,"Pong") \ - MINIGAME(c4, "Connect Four") \ - MINIGAME(ps, "Peg Solitaire") \ - MINIGAME(pp, "Push-Pull") \ - MINIGAME(snake,"Snake") \ - /*empty line*/ - /** * Set up automatic entity read/write functionality * To ensure that everything is handled automatically, spawn on the server using msle_spawn diff --git a/qcsrc/common/minigames/minigame/c4.qc b/qcsrc/common/minigames/minigame/c4.qc index 31388d0f3..98020972a 100644 --- a/qcsrc/common/minigames/minigame/c4.qc +++ b/qcsrc/common/minigames/minigame/c4.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(c4, "Connect Four"); + const float C4_TURN_PLACE = 0x0100; // player has to place a piece on the board const float C4_TURN_WIN = 0x0200; // player has won const float C4_TURN_DRAW = 0x0400; // no moves are possible diff --git a/qcsrc/common/minigames/minigame/nmm.qc b/qcsrc/common/minigames/minigame/nmm.qc index 2bd4a4267..1e4da0507 100644 --- a/qcsrc/common/minigames/minigame/nmm.qc +++ b/qcsrc/common/minigames/minigame/nmm.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(nmm, "Nine Men's Morris"); + const int NMM_TURN_PLACE = 0x0100; // player has to place a piece on the board const int NMM_TURN_MOVE = 0x0200; // player has to move a piece by one tile const int NMM_TURN_FLY = 0x0400; // player has to move a piece anywhere diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index e295c7cd6..540f7ecf2 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(pong, "Pong"); + // minigame flags const int PONG_STATUS_WAIT = 0x0010; // waiting for players to join const int PONG_STATUS_PLAY = 0x0020; // playing diff --git a/qcsrc/common/minigames/minigame/pp.qc b/qcsrc/common/minigames/minigame/pp.qc index 01b257a82..efce0e66b 100644 --- a/qcsrc/common/minigames/minigame/pp.qc +++ b/qcsrc/common/minigames/minigame/pp.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(pp, "Push-Pull"); + const int PP_TURN_PLACE = 0x0100; // player has to place a piece on the board const int PP_TURN_WIN = 0x0200; // player has won const int PP_TURN_DRAW = 0x0400; // players have equal scores diff --git a/qcsrc/common/minigames/minigame/ps.qc b/qcsrc/common/minigames/minigame/ps.qc index 2b8de2992..54be75cd4 100644 --- a/qcsrc/common/minigames/minigame/ps.qc +++ b/qcsrc/common/minigames/minigame/ps.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(ps, "Peg Solitaire"); + const float PS_TURN_MOVE = 0x0100; // player has to click on a piece on the board const float PS_TURN_WIN = 0x0200; // player has won const float PS_TURN_DRAW = 0x0400; // player can make no more moves diff --git a/qcsrc/common/minigames/minigame/snake.qc b/qcsrc/common/minigames/minigame/snake.qc index 16b28374e..c7bf6ae59 100644 --- a/qcsrc/common/minigames/minigame/snake.qc +++ b/qcsrc/common/minigames/minigame/snake.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(snake, "Snake"); + const float SNAKE_TURN_MOVE = 0x0100; // the snake is moving, player must control it const float SNAKE_TURN_LOSS = 0x0200; // they did it?! const float SNAKE_TURN_WAIT = 0x0400; // the snake is waiting for the player to make their first move and begin the game diff --git a/qcsrc/common/minigames/minigame/ttt.qc b/qcsrc/common/minigames/minigame/ttt.qc index f2253c2a4..8c5005ed2 100644 --- a/qcsrc/common/minigames/minigame/ttt.qc +++ b/qcsrc/common/minigames/minigame/ttt.qc @@ -1,3 +1,5 @@ +REGISTER_MINIGAME(ttt, "Tic Tac Toe"); + const int TTT_TURN_PLACE = 0x0100; // player has to place a piece on the board const int TTT_TURN_WIN = 0x0200; // player has won const int TTT_TURN_DRAW = 0x0400; // no moves are possible diff --git a/qcsrc/common/minigames/minigames.qc b/qcsrc/common/minigames/minigames.qc index c2392ae0e..6a24d37ad 100644 --- a/qcsrc/common/minigames/minigames.qc +++ b/qcsrc/common/minigames/minigames.qc @@ -2,10 +2,11 @@ entity minigame_get_descriptor(string id) { - entity e; - for ( e = minigame_descriptors; e != world; e = e.list_next ) - if ( e.netname == id ) - return e; + FOREACH(MINIGAMES, true, LAMBDA( + { + if(it.netname == id) + return it; + })); return world; } diff --git a/qcsrc/common/minigames/minigames.qh b/qcsrc/common/minigames/minigames.qh index 536ac5018..7425149f3 100644 --- a/qcsrc/common/minigames/minigames.qh +++ b/qcsrc/common/minigames/minigames.qh @@ -1,8 +1,6 @@ #ifndef MINIGAMES_H #define MINIGAMES_H -entity minigame_descriptors; - // previous node in a doubly linked list .entity list_prev; // next node in a linked list diff --git a/qcsrc/common/minigames/sv_minigames.qc b/qcsrc/common/minigames/sv_minigames.qc index d0b35c5a8..36c54c18d 100644 --- a/qcsrc/common/minigames/sv_minigames.qc +++ b/qcsrc/common/minigames/sv_minigames.qc @@ -273,25 +273,6 @@ void end_minigames() } } -void initialize_minigames() -{ - entity last_minig = world; - entity minig; - #define MINIGAME(name,nicename) \ - minig = spawn(); \ - minig.classname = "minigame_descriptor"; \ - minig.netname = #name; \ - minig.message = nicename; \ - minig.minigame_event = name##_server_event; \ - if ( !last_minig ) minigame_descriptors = minig; \ - else last_minig.list_next = minig; \ - last_minig = minig; - - REGISTERED_MINIGAMES - - #undef MINIGAME -} - string invite_minigame(entity inviter, entity player) { if ( !inviter || !inviter.active_minigame ) @@ -369,9 +350,10 @@ void ClientCommand_minigame(int request, int argc, string command) } else if ( minig_cmd == "list" ) { - entity e; - for ( e = minigame_descriptors; e != world; e = e.list_next ) - sprint(self,e.netname," (",e.message,") ","\n"); + FOREACH(MINIGAMES, true, LAMBDA( + { + sprint(self,it.netname," (",it.message,") ","\n"); + })); return; } else if ( minig_cmd == "list-sessions" ) diff --git a/qcsrc/common/minigames/sv_minigames.qh b/qcsrc/common/minigames/sv_minigames.qh index 246440d39..43b392f74 100644 --- a/qcsrc/common/minigames/sv_minigames.qh +++ b/qcsrc/common/minigames/sv_minigames.qh @@ -1,9 +1,6 @@ #ifndef SV_MINIGAMES_H #define SV_MINIGAMES_H -/// Initialize the minigame system -void initialize_minigames(); - /// Create a new minigame session /// \return minigame session entity entity start_minigame(entity player, string minigame ); @@ -49,4 +46,20 @@ entity minigame_sessions; bool minigame_SendEntity(entity to, int sf); +void RegisterMinigames(); +const int MINIGAMES_MAX = 24; +entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last; +int MINIGAMES_COUNT; +#define REGISTER_MINIGAME(name,nicename) \ + REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \ + int name##_server_event(entity, string, ...); \ + REGISTER_INIT_POST(MINIGAME, name) { \ + this.classname = "minigame_descriptor"; \ + this.netname = strzone(strtolower(#name)); \ + this.message = nicename; \ + this.minigame_event = name##_server_event; \ + } \ + REGISTER_INIT(MINIGAME, name) +REGISTER_REGISTRY(RegisterMinigames) + #endif diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index b5a2806d7..e17e7adbc 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -608,8 +608,6 @@ void spawnfunc_worldspawn (void) CALL_ACCUMULATED_FUNCTION(RegisterNotifications); CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes); - initialize_minigames(); - ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid)); TemporaryDB = db_create();