]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make minigames use the registry system
authorMario <zacjardine@y7mail.com>
Sun, 27 Sep 2015 08:33:01 +0000 (18:33 +1000)
committerMario <zacjardine@y7mail.com>
Sun, 27 Sep 2015 08:33:46 +0000 (18:33 +1000)
17 files changed:
qcsrc/client/main.qc
qcsrc/common/minigames/cl_minigames.qc
qcsrc/common/minigames/cl_minigames.qh
qcsrc/common/minigames/cl_minigames_hud.qc
qcsrc/common/minigames/minigame/all.qh
qcsrc/common/minigames/minigame/c4.qc
qcsrc/common/minigames/minigame/nmm.qc
qcsrc/common/minigames/minigame/pong.qc
qcsrc/common/minigames/minigame/pp.qc
qcsrc/common/minigames/minigame/ps.qc
qcsrc/common/minigames/minigame/snake.qc
qcsrc/common/minigames/minigame/ttt.qc
qcsrc/common/minigames/minigames.qc
qcsrc/common/minigames/minigames.qh
qcsrc/common/minigames/sv_minigames.qc
qcsrc/common/minigames/sv_minigames.qh
qcsrc/server/g_world.qc

index 5dec3202fc89d902b72ea4e132de753c14eb2242..ca31f32f71bf7b5afb82bb487a650653d1da108d 100644 (file)
@@ -151,8 +151,6 @@ void CSQC_Init(void)
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
        CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
 
-       initialize_minigames();
-
        // precaches
 
        Projectile_Precache();
index f896696821d3603d3a6f0a3f08c2596887846e73..38614c7d4629481c9c8fafeb6b029b533e263491 100644 (file)
@@ -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);
index a839b1106194a7156bd56d669f4aefc720686cba..76d10986405891fa3d8e902983d33ce5ed6e0bb9 100644 (file)
@@ -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
index 11470ec136acc3929cbd6721a720f8356e06d822..b0dba86c1ed9525cddb9f6f29b7818b3a9931c06 100644 (file)
@@ -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;
-               }
+               }));
        }
 }
 
index 0bc61357b8a53f348f28dc6d2366af640c21089b..d3874e7aa77cb42b79bc8c42230982cb0a4781f6 100644 (file)
@@ -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
index 31388d0f38a3b6457868fd3609e6cf77967f676b..98020972a742ee5a59e4eef24e69a7a483f6e69c 100644 (file)
@@ -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
index 2bd4a4267fa22484af7dd6549711105b723272d6..1e4da05075ad20c76b11587a69f4a2e5b3105782 100644 (file)
@@ -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
index e295c7cd64ec867ac56af8813d0517262feb0fb8..540f7ecf2f1d506b30a28e98f045c3783f9c4e0e 100644 (file)
@@ -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
index 01b257a82a94b4a17cbf9fdc763bcc2e03f1b5cf..efce0e66b6be5030a96beb0446cdd2c3378a4b66 100644 (file)
@@ -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
index 2b8de29920a416d687298b036769c2313de8141e..54be75cd46f51ba2c62756d99ec8716cb6764fd0 100644 (file)
@@ -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
index 16b28374eb925b1302697760d0d3bb5c093f1df1..c7bf6ae59b8c1db0a1572d00c2ef96c6705df5bc 100644 (file)
@@ -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
index f2253c2a4b7c2da56fc7489a65b9829ac5389152..8c5005ed259f301e924a19c781ec2080db2e064a 100644 (file)
@@ -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
index c2392ae0e0a733bd154e56ca7bdb6cd1a7075ab5..6a24d37ad8033a17036e671a0e0de5dacc8dcadb 100644 (file)
@@ -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;
 }
 
index 536ac5018753af104d1cbb34fc3300efcdc6a506..7425149f389d9b484c38d089ebef97c2b750f6df 100644 (file)
@@ -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
index d0b35c5a883b6979f71029fe6c4aa8db28f10ee2..36c54c18d6858a595a834ad7c726f9c0710eade2 100644 (file)
@@ -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" )
index 246440d39e5d0f84f03f06c0353033f03f5f4967..43b392f743a843caf5ecf26be5996be40a431536 100644 (file)
@@ -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
index b5a2806d76d7a5756ad55a656c29951f8dd23514..e17e7adbcff7dd162f345a89a84e2b0b4e9bf8ad 100644 (file)
@@ -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();