]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
HUD: initialize with registry 236/head
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 8 Oct 2015 04:54:42 +0000 (15:54 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 8 Oct 2015 04:54:42 +0000 (15:54 +1100)
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/hud_config.qc
qcsrc/client/main.qc
qcsrc/client/view.qc

index b229917249f2347a611805fa67f12fa815569a11..dbae62cbdef08c40cde94676b407e014673e5169 100644 (file)
@@ -4465,7 +4465,7 @@ void HUD_CenterPrint (void)
                        reset_centerprint_messages();
                if (time > hud_configure_cp_generation_time)
                {
-                       if(HUD_PANEL(CENTERPRINT) == highlightedPanel)
+                       if(highlightedPanel == HUD_PANEL(CENTERPRINT))
                        {
                                float r;
                                r = random();
@@ -4800,18 +4800,18 @@ void HUD_Main (void)
 
        // cache the panel order into the panel_order array
        if(autocvar__hud_panelorder != hud_panelorder_prev) {
-               for(i = 0; i < HUD_PANEL_NUM; ++i)
+               for(i = 0; i < hud_panels_COUNT; ++i)
                        panel_order[i] = -1;
                string s = "";
                int p_num;
                bool warning = false;
                int argc = tokenize_console(autocvar__hud_panelorder);
-               if (argc > HUD_PANEL_NUM)
+               if (argc > hud_panels_COUNT)
                        warning = true;
                //first detect wrong/missing panel numbers
-               for(i = 0; i < HUD_PANEL_NUM; ++i) {
+               for(i = 0; i < hud_panels_COUNT; ++i) {
                        p_num = stoi(argv(i));
-                       if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
+                       if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
                                if (panel_order[p_num] == -1) //found for the first time?
                                        s = strcat(s, ftos(p_num), " ");
                                panel_order[p_num] = 1; //mark as found
@@ -4819,7 +4819,7 @@ void HUD_Main (void)
                        else
                                warning = true;
                }
-               for(i = 0; i < HUD_PANEL_NUM; ++i) {
+               for(i = 0; i < hud_panels_COUNT; ++i) {
                        if (panel_order[i] == -1) {
                                warning = true;
                                s = strcat(s, ftos(i), " "); //add missing panel number
@@ -4835,15 +4835,15 @@ void HUD_Main (void)
 
                //now properly set panel_order
                tokenize_console(s);
-               for(i = 0; i < HUD_PANEL_NUM; ++i) {
+               for(i = 0; i < hud_panels_COUNT; ++i) {
                        panel_order[i] = stof(argv(i));
                }
        }
 
        hud_draw_maximized = 0;
        // draw panels in the order specified by panel_order array
-       for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
-               HUD_Panel_Draw(hud_panel[panel_order[i]]);
+       for(i = hud_panels_COUNT - 1; i >= 0; --i)
+               HUD_Panel_Draw(hud_panels[panel_order[i]]);
 
        hud_draw_maximized = 1; // panels that may be maximized must check this var
        // draw maximized panels on top
index ebde4b12b8c4e81abca18085b68c31afea751b26..224b3fbe09de952c31bca79898d525eca73db2f8 100644 (file)
@@ -3,13 +3,21 @@
 
 #include "../common/weapons/all.qh"
 
-const int HUD_PANEL_MAX = 24;
-entity hud_panel[HUD_PANEL_MAX];
-const int HUD_PANEL_FIRST = 0;
-int HUD_PANEL_NUM;
-int HUD_PANEL_LAST;
+REGISTRY(hud_panels, 24)
+REGISTER_REGISTRY(Registerhud_panels)
 
-int panel_order[HUD_PANEL_MAX];
+#define REGISTER_HUD_PANEL(id, draw_func, name, showflags) \
+       void draw_func(); \
+       REGISTER(Registerhud_panels, HUD_PANEL, hud_panels, id, m_id, new(hud_panel)) { \
+               this.panel_id = this.m_id; \
+               this.panel_draw = draw_func; \
+               this.panel_name = #name; \
+               this.panel_showflags = showflags; \
+       }
+
+#define HUD_PANEL(NAME) HUD_PANEL_##NAME
+
+int panel_order[hud_panels_MAX];
 string hud_panelorder_prev;
 
 bool hud_draw_maximized;
@@ -156,55 +164,31 @@ int prev_p_health, prev_p_armor;
 
 void HUD_ItemsTime();
 
-#define HUD_PANELS(HUD_PANEL) \
-       HUD_PANEL(WEAPONS      , HUD_Weapons      , weapons,        PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(AMMO         , HUD_Ammo         , ammo,           PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(POWERUPS     , HUD_Powerups     , powerups,       PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(HEALTHARMOR  , HUD_HealthArmor  , healtharmor,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(NOTIFY       , HUD_Notify       , notify,         PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(TIMER        , HUD_Timer        , timer,          PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(RADAR        , HUD_Radar        , radar,          PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(SCORE        , HUD_Score        , score,          PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(RACETIMER    , HUD_RaceTimer    , racetimer,      PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(VOTE         , HUD_Vote         , vote,           PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(MODICONS     , HUD_ModIcons     , modicons,       PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(PRESSEDKEYS  , HUD_PressedKeys  , pressedkeys,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(CHAT         , HUD_Chat         , chat,           PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(ENGINEINFO   , HUD_EngineInfo   , engineinfo,     PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages,   PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(PHYSICS      , HUD_Physics      , physics,        PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(CENTERPRINT  , HUD_CenterPrint  , centerprint,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard ,minigameboard, PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_STATUS,HUD_MinigameStatus,minigamestatus,PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_HELP,  HUD_MinigameHelp  ,minigamehelp,  PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_MENU,  HUD_MinigameMenu  ,minigamemenu,  PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(MAPVOTE      ,  MapVote_Draw      ,mapvote,       PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(ITEMSTIME    ,  HUD_ItemsTime     ,itemstime,     PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(QUICKMENU    , HUD_QuickMenu    , quickmenu,      PANEL_SHOW_MAINGAME ) \
-       // always add new panels to the end of list
-
-
-#define HUD_PANEL(NAME, draw_func, name, showflags)                                                                                                                                                    \
-       int HUD_PANEL_##NAME;                                                                                                                                                                                   \
-       void draw_func(void);                                                                                                                                                                                   \
-       void RegisterHUD_Panel_##NAME() {                                                                                                                                                               \
-               HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM;                                                                                                                      \
-               entity hud_panelent = spawn();                                                                                                                                                          \
-               hud_panel[HUD_PANEL_##NAME] = hud_panelent;                                                                                                                             \
-               hud_panelent.classname = "hud_panel";                                                                                                                                           \
-               hud_panelent.panel_name = #name;                                                                                                                                                        \
-               hud_panelent.panel_id = HUD_PANEL_##NAME;                                                                                                                                       \
-               hud_panelent.panel_draw = draw_func;                                                                                                                                            \
-               hud_panelent.panel_showflags = showflags;                                                                                                                                       \
-               HUD_PANEL_NUM++;                                                                                                                                                                                        \
-       }                                                                                                                                                                                                                               \
-       ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME)
-
-HUD_PANELS(HUD_PANEL)
-#undef HUD_PANEL
-
-#define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
-
+REGISTER_HUD_PANEL(WEAPONS,         HUD_Weapons,        weapons,        PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(AMMO,            HUD_Ammo,           ammo,           PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(POWERUPS,        HUD_Powerups,       powerups,       PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(HEALTHARMOR,     HUD_HealthArmor,    healtharmor,    PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(NOTIFY,          HUD_Notify,         notify,         PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(TIMER,           HUD_Timer,          timer,          PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(RADAR,           HUD_Radar,          radar,          PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(SCORE,           HUD_Score,          score,          PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(RACETIMER,       HUD_RaceTimer,      racetimer,      PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(VOTE,            HUD_Vote,           vote,           PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(MODICONS,        HUD_ModIcons,       modicons,       PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(PRESSEDKEYS,     HUD_PressedKeys,    pressedkeys,    PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(CHAT,            HUD_Chat,           chat,           PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(ENGINEINFO,      HUD_EngineInfo,     engineinfo,     PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(INFOMESSAGES,    HUD_InfoMessages,   infomessages,   PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(PHYSICS,         HUD_Physics,        physics,        PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(CENTERPRINT,     HUD_CenterPrint,    centerprint,    PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(MINIGAME_BOARD,  HUD_MinigameBoard,  minigameboard,  PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_STATUS, HUD_MinigameStatus, minigamestatus, PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_HELP,   HUD_MinigameHelp,   minigamehelp,   PANEL_SHOW_MINIGAME)
+REGISTER_HUD_PANEL(MINIGAME_MENU,   HUD_MinigameMenu,   minigamemenu,   PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(MAPVOTE,         MapVote_Draw,       mapvote,        PANEL_SHOW_ALWAYS  )
+REGISTER_HUD_PANEL(ITEMSTIME,       HUD_ItemsTime,      itemstime,      PANEL_SHOW_MAINGAME)
+REGISTER_HUD_PANEL(QUICKMENU,       HUD_QuickMenu,      quickmenu,      PANEL_SHOW_MAINGAME)
+// always add new panels to the end of list
 
 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
 // ----------------------
index 0216a43b087b6b0352148f12ac95ba41a8cc1a7d..2cdb9fcf4de9105cd47c8e1cf5994ba58459eacb 100644 (file)
@@ -59,10 +59,9 @@ void HUD_Panel_ExportCfg(string cfgname)
                HUD_Write("\n");
 
                // common cvars for all panels
-               int i;
-               for (i = 0; i < HUD_PANEL_NUM; ++i)
+               for (int i = 0; i < hud_panels_COUNT; ++i)
                {
-                       panel = hud_panel[i];
+                       panel = hud_panels[i];
 
                        HUD_Write_PanelCvar_n("");
                        HUD_Write_PanelCvar_q("_pos");
@@ -73,7 +72,7 @@ void HUD_Panel_ExportCfg(string cfgname)
                        HUD_Write_PanelCvar_q("_bg_alpha");
                        HUD_Write_PanelCvar_q("_bg_border");
                        HUD_Write_PanelCvar_q("_bg_padding");
-                       switch(i) {
+                       switch(panel) {
                                case HUD_PANEL_WEAPONS:
                                        HUD_Write_PanelCvar_q("_accuracy");
                                        HUD_Write_PanelCvar_q("_label");
@@ -240,8 +239,8 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize)
        vector myCenter, targCenter;
        vector myTarget = myPos;
        int i;
-       for (i = 0; i < HUD_PANEL_NUM; ++i) {
-               panel = hud_panel[i];
+       for (i = 0; i < hud_panels_COUNT; ++i) {
+               panel = hud_panels[i];
                if(panel == HUD_PANEL(MAPVOTE)) continue;
                if(panel == highlightedPanel) continue;
                HUD_Panel_UpdatePosSize();
@@ -337,8 +336,8 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
        vector dist;
        float ratio = mySize.x/mySize.y;
        int i;
-       for (i = 0; i < HUD_PANEL_NUM; ++i) {
-               panel = hud_panel[i];
+       for (i = 0; i < hud_panels_COUNT; ++i) {
+               panel = hud_panels[i];
                if(panel == HUD_PANEL(MAPVOTE)) continue;
                if(panel == highlightedPanel) continue;
                HUD_Panel_UpdatePosSize();
@@ -639,7 +638,7 @@ void HUD_Panel_Arrow_Action(float nPrimary)
 }
 
 void HUD_Panel_EnableMenu();
-entity tab_panels[HUD_PANEL_MAX];
+entity tab_panels[hud_panels_MAX];
 entity tab_panel;
 vector tab_panel_pos;
 float tab_backward;
@@ -647,7 +646,7 @@ void HUD_Panel_FirstInDrawQ(float id);
 void reset_tab_panels()
 {
        int i;
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
+       for(i = 0; i < hud_panels_COUNT; ++i)
                tab_panels[i] = world;
 }
 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
@@ -788,9 +787,9 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
                k=0;
                while(++k)
                {
-                       for(i = 0; i < HUD_PANEL_NUM; ++i)
+                       for(i = 0; i < hud_panels_COUNT; ++i)
                        {
-                               panel = hud_panel[i];
+                               panel = hud_panels[i];
                                if(panel == HUD_PANEL(MAPVOTE))
                                        continue;
                                if (panel == tab_panels[i] || panel == starting_panel)
@@ -934,12 +933,12 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
 float HUD_Panel_Check_Mouse_Pos(float allow_move)
 {
        int i, j = 0;
-       while(j < HUD_PANEL_NUM)
+       while(j < hud_panels_COUNT)
        {
                i = panel_order[j];
                j += 1;
 
-               panel = hud_panel[i];
+               panel = hud_panels[i];
                if(panel == HUD_PANEL(MAPVOTE)) continue;
                HUD_Panel_UpdatePosSize();
 
@@ -980,7 +979,7 @@ void HUD_Panel_FirstInDrawQ(float id)
        int i;
        int place = -1;
        // find out where in the array our current id is, save into place
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
+       for(i = 0; i < hud_panels_COUNT; ++i)
        {
                if(panel_order[i] == id)
                {
@@ -990,7 +989,7 @@ void HUD_Panel_FirstInDrawQ(float id)
        }
        // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
        if(place == -1)
-               place = HUD_PANEL_NUM - 1;
+               place = hud_panels_COUNT - 1;
 
        // move all ids up by one step in the array until "place"
        for(i = place; i > 0; --i)
@@ -1002,7 +1001,7 @@ void HUD_Panel_FirstInDrawQ(float id)
 
        // let's save them into the cvar by some strcat trickery
        string s = "";
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
+       for(i = 0; i < hud_panels_COUNT; ++i)
        {
                s = strcat(s, ftos(panel_order[i]), " ");
        }
@@ -1016,12 +1015,12 @@ void HUD_Panel_Highlight(float allow_move)
 {
        int i, j = 0;
 
-       while(j < HUD_PANEL_NUM)
+       while(j < hud_panels_COUNT)
        {
                i = panel_order[j];
                j += 1;
 
-               panel = hud_panel[i];
+               panel = hud_panels[i];
                if(panel == HUD_PANEL(MAPVOTE))
                        continue;
                HUD_Panel_UpdatePosSize();
@@ -1031,7 +1030,7 @@ void HUD_Panel_Highlight(float allow_move)
                // move
                if(allow_move && mousepos.x > panel_pos.x && mousepos.y > panel_pos.y && mousepos.x < panel_pos.x + panel_size.x && mousepos.y < panel_pos.y + panel_size.y)
                {
-                       highlightedPanel = hud_panel[i];
+                       highlightedPanel = hud_panels[i];
                        HUD_Panel_FirstInDrawQ(i);
                        highlightedAction = 1;
                        panel_click_distance = mousepos - panel_pos;
@@ -1040,7 +1039,7 @@ void HUD_Panel_Highlight(float allow_move)
                // resize from topleft border
                else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + 0.5 * panel_size.y)
                {
-                       highlightedPanel = hud_panel[i];
+                       highlightedPanel = hud_panels[i];
                        HUD_Panel_FirstInDrawQ(i);
                        highlightedAction = 2;
                        resizeCorner = 1;
@@ -1051,7 +1050,7 @@ void HUD_Panel_Highlight(float allow_move)
                // resize from topright border
                else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y - border && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + 0.5 * panel_size.y)
                {
-                       highlightedPanel = hud_panel[i];
+                       highlightedPanel = hud_panels[i];
                        HUD_Panel_FirstInDrawQ(i);
                        highlightedAction = 2;
                        resizeCorner = 2;
@@ -1063,7 +1062,7 @@ void HUD_Panel_Highlight(float allow_move)
                // resize from bottomleft border
                else if(mousepos.x >= panel_pos.x - border && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + 0.5 * panel_size.x && mousepos.y <= panel_pos.y + panel_size.y + border)
                {
-                       highlightedPanel = hud_panel[i];
+                       highlightedPanel = hud_panels[i];
                        HUD_Panel_FirstInDrawQ(i);
                        highlightedAction = 2;
                        resizeCorner = 3;
@@ -1075,7 +1074,7 @@ void HUD_Panel_Highlight(float allow_move)
                // resize from bottomright border
                else if(mousepos.x >= panel_pos.x + 0.5 * panel_size.x && mousepos.y >= panel_pos.y + 0.5 * panel_size.y && mousepos.x <= panel_pos.x + panel_size.x + border && mousepos.y <= panel_pos.y + panel_size.y + border)
                {
-                       highlightedPanel = hud_panel[i];
+                       highlightedPanel = hud_panels[i];
                        HUD_Panel_FirstInDrawQ(i);
                        highlightedAction = 2;
                        resizeCorner = 4;
@@ -1249,8 +1248,8 @@ void HUD_Configure_Frame()
                        if(autocvar_hud_cursormode)
                                setcursormode(1);
                        hudShiftState = 0;
-                       for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
-                               hud_panel[panel_order[i]].update_time = time;
+                       for(i = hud_panels_COUNT - 1; i >= 0; --i)
+                               hud_panels[panel_order[i]].update_time = time;
                }
 
                // NOTE this check is necessary because _menu_alpha isn't updated the frame the menu gets enabled
index bb60a917d5f19a216d4f550bccdee78ca6b92b9a..ff9fe0f7f96c7e190319df7984794693867ef55b 100644 (file)
@@ -150,7 +150,6 @@ void CSQC_Init(void)
        static_init();
        CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
        CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
-       CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
 
        // precaches
 
index 381ead7869362d94bc98025544a1af291efccaab..3bb5585f35931ce09cd01f96c4be1741f725fd82 100644 (file)
@@ -1027,7 +1027,6 @@ void CSQC_UpdateView(float w, float h)
        entity e;
        float fov;
        float f;
-       int i;
        vector vf_size, vf_min;
        float a;
 
@@ -1078,8 +1077,7 @@ void CSQC_UpdateView(float w, float h)
        if(myteam != prev_myteam)
        {
                myteamcolors = colormapPaletteColor(myteam, 1);
-               for(i = 0; i < HUD_PANEL_NUM; ++i)
-                       hud_panel[i].update_time = time;
+               FOREACH(hud_panels, true, LAMBDA(it.update_time = time));
                prev_myteam = myteam;
        }