]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Fast commit before Im off for 10 days. Please correct/undo my commit if it breaks...
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Dec 2003 12:12:03 +0000 (12:12 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 23 Dec 2003 12:12:03 +0000 (12:12 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3749 d7cf8633-e32d-0410-b094-e92efae38249

cl_screen.c
gl_rmain.c
host.c
keys.c
todo
ui.c
ui.h
vid_glx.c
vid_wgl.c
zone.c
zone.h

index 8bc1084ff261f9c4376f5293e15e1843d04b53d1..b8038ba79cd22f6b3e7fad775fd17556d7bf5560 100644 (file)
@@ -1020,8 +1020,9 @@ void CL_UpdateScreen(void)
                        SCR_CheckDrawCenterString();
                }
                MR_Draw();
+               UI_Callback_Draw();
                CL_DrawVideo();
-               ui_draw();
+               //ui_draw();
                if (cls.signon == SIGNONS)
                {
                        R_TimeReport("2d");
index 0efd3974b7108f032bef53afcfe24563a230fa76..952078c1b60a0e3e9eb8d27b93eca6f93fafc3c1 100644 (file)
@@ -337,7 +337,8 @@ void Render_Init(void)
        R_Light_Init();
        R_Particles_Init();
        R_Explosion_Init();
-       ui_init();
+       //ui_init();
+       UI_Init();
        Sbar_Init();
        R_LightningBeams_Init();
 }
diff --git a/host.c b/host.c
index 119a7aa5e3ee889237d02afe12394c86d72718d7..69e980f1217a76fc0ae0aa36596bebff53c1a7d4 100644 (file)
--- a/host.c
+++ b/host.c
@@ -755,7 +755,7 @@ void _Host_Frame (float time)
                CL_ReadFromServer();
        }
 
-       ui_update();
+       //ui_update();
 
        CL_VideoFrame();
 
diff --git a/keys.c b/keys.c
index 7b10bfbfa404afdcb91f19c308c212383c72b23a..fab2478bd327e31b0ca903046968f002d341175e 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -812,7 +812,10 @@ void Key_Event (int key, char ascii, qboolean down)
                        MR_ToggleMenu_f ();
                        break;
                default:
-                       Sys_Error ("Bad key_dest");
+                       if(UI_Callback_IsSlotUsed(key_dest - 3))
+                               UI_Callback_KeyDown (key, ascii);
+                       else
+                               Sys_Error ("Bad key_dest");
                }
                return;
        }
@@ -908,7 +911,10 @@ void Key_Event (int key, char ascii, qboolean down)
                        Key_Console (key, ascii);
                        break;
                default:
-                       Sys_Error ("Bad key_dest");
+                       if(UI_Callback_IsSlotUsed(key_dest - 3))
+                               UI_Callback_KeyDown (key, ascii);
+                       else
+                               Sys_Error ("Bad key_dest");
                }
        }
 }
diff --git a/todo b/todo
index e0654f60b7be6e322b5cffc626c1ab0ec66ff762..17f54fba8de83150f3e6878a392d7171f7cc022a 100644 (file)
--- a/todo
+++ b/todo
@@ -73,7 +73,6 @@ f darkplaces: change particle() macro in cl_particles.c to have a do{}while(0) t
 0 darkplaces: check for out of bounds lump data ranges in maps (FrikaC)
 0 darkplaces: check for truncated sound files (FrikaC)
 0 darkplaces: cl_particles_maximum cvar (default 32768) which would change number of particles allowed at once (TheBeast)
-0 darkplaces: clean up the DrawQ_ blendfunc handling, instead of taking DRAWFLAG_ADDITIVE they should take blendfunc values (Black)
 0 darkplaces: client colors are being reset to "15 15" each level in prydon gate? (FrikaC)
 0 darkplaces: darkplaces-glx -path transfusion crashes, fix the crash even though it's not going to work anyway (Todd)
 0 darkplaces: delay "connect" and "playdemo" and "timedemo" until after video init to cause quicker video startup (KrimZon)
@@ -283,7 +282,8 @@ d darkplaces: q1bsp trace bug: scrags frequently fly through ceilings - this nee
 4 darkplaces: figure out what is wrong with dedicated server console on win32 and fix it (and tell willis@deathmask.net)
 4 darkplaces: ingame mod switching
 4 darkplaces: make hqbsp save mip textures to bsp if tga textures are found
-4 darkplaces: memory pool nesting, allowing pools of pools to be batch freed (Vicious)
+-n darkplaces: memory pool nesting, allowing pools of pools to be batch freed (Vicious)
+4 darkplaces: use the memory pool nesting feature ! (Black[,Vicious])
 4 darkplaces: rewrite sound system! (FrikaC, Static_Fiend, SeienAbunae)
 4 darkplaces: use getaddrinfo to support ipv6, add support for winsock2 (or require it), check if winsock2 has ipv6 functions (getaddrinfo)... (|Rain|)
 4 dpzoo: a drivable vehicle (using same technique as remote cameras, plus DP_SV_READCLIENTINPUT)
diff --git a/ui.c b/ui.c
index bb9398e2cbd9ccca67776e574bc4ba44405c5c6a..661ae30e2f5c76035e201eb170c26d1736e4b6de 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -1,7 +1,7 @@
 
 #include "quakedef.h"
 
-cvar_t ui_showname = {0, "ui_showname", "0"};
+/*cvar_t ui_showname = {0, "ui_showname", "0"};
 
 #define ITEM_CLICKABLE 1
 #define ITEM_DRAWABLE 2
@@ -407,5 +407,146 @@ void ui_draw(void)
 
                DrawQ_Pic(ui_mouse_x, ui_mouse_y, "ui/mousepointer.tga", 0, 0, 1, 1, 1, 1, 0);
        }
+}*/
+
+#define FRAME_THICKNESS        2
+#define FRAME_COLOR1   0.2, 0.2, 0.5, 0, 0
+#define FRAME_COLOR2   0, 0, 0, 0.6, 0
+#define TEXT_FONTSIZE  10, 10
+
+static void UIG_DrawFrame(float x, float y, float w, float h)
+{
+       // bottom
+       DrawQ_Fill(x - FRAME_THICKNESS, y - FRAME_THICKNESS, w + 2 * FRAME_THICKNESS, FRAME_THICKNESS, FRAME_COLOR1);
+       // top
+       DrawQ_Fill(x - FRAME_THICKNESS, y + h, w + 2 * FRAME_THICKNESS, FRAME_THICKNESS, FRAME_COLOR1);
+       // left
+       DrawQ_Fill(x - FRAME_THICKNESS, y, FRAME_THICKNESS, h, FRAME_COLOR1);
+       // right
+       DrawQ_Fill(x + w, y, FRAME_THICKNESS, h, FRAME_COLOR1);
+       // area
+       DrawQ_Fill(x, y, w, h, FRAME_COLOR2);
+} 
+
+static void UIG_DrawText(const char *text, float x, float y, float w, float h, float r, float g, float b, float a, float f)
+{
+       if(w != 0 && h != 0)
+               DrawQ_SetClipArea(x, y, w, h);
+       DrawQ_String(x, y, text, 0, TEXT_FONTSIZE, r, g, b, a , f);
+       if(w != 0 && h != 0)    
+               DrawQ_ResetClipArea();
+}
+
+void UI_Init(void)
+{
+}
+
+void UI_Key(ui_itemlist_t list, int key, int ascii)
+{
+}
+
+void UI_Draw(ui_itemlist_t list)
+{
+}
+
+void UI_SetFocus(ui_itemlist_t list, ui_item_t item)
+{
+}
+
+void UI_SetNeighbors(ui_item_t left, ui_item_t right, ui_item_t up, ui_item_t down)
+{
+}
+
+// item stuff
+ui_item_t UI_CreateButton(const char *caption, float x, float y, void(*action)(ui_item_t))
+{
+       return NULL;
+}
+
+ui_item_t UI_CreateLabel(const char *caption, float x, float y)
+{
+       return NULL;
+}
+
+ui_item_t UI_CreateText(const char *caption, float x, float y, const char *allowed, int maxlen, int scrolllen)
+{
+       return NULL;
+}
+
+void UI_FreeItem(ui_item_t item)
+{
+}
+
+const char* UI_GetCaption(ui_item_t item)
+{
 }
 
+void UI_SetCaption(ui_item_t item, const char * caption)
+{
+}
+
+// itemlist stuff
+ui_itemlist_t UI_CreateItemList(float x, float y)
+{
+       return NULL;
+}
+
+void UI_FreeItemList(ui_itemlist_t list)
+{
+}
+
+void UI_AddItem(ui_itemlist_t list, ui_item_t item)
+{
+}
+
+// AK: callback system stuff
+static ui_callback_t ui_callback_list[UI_MAX_CALLBACK_COUNT];
+
+void UI_Callback_Init(void)
+{
+       memset(ui_callback_list, 0, sizeof(ui_callback_list));
+}
+
+int  UI_Callback_GetFreeSlot(void)
+{
+       int i;
+       for(i = 0; ui_callback_list[i].flag & UI_SLOTUSED && i < UI_MAX_CALLBACK_COUNT; i++);
+
+       if(i == UI_MAX_CALLBACK_COUNT)
+               return -1;
+       else
+               return i;
+}
+
+int UI_Callback_IsSlotUsed(int slotnr)
+{
+       if(slotnr < 0 || slotnr >= UI_MAX_CALLBACK_COUNT)
+               return false;
+       return (ui_callback_list[slotnr].flag & UI_SLOTUSED);
+}
+
+void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void))
+{
+       ui_callback_list[slotnr].flag = UI_SLOTUSED;
+       ui_callback_list[slotnr].draw = drawf;
+       ui_callback_list[slotnr].keydown = keydownf;
+}
+
+void UI_Callback_ResetSlot(int slotnr)
+{
+       ui_callback_list[slotnr].flag = 0;
+}
+
+void UI_Callback_Draw(void)
+{
+       int i;
+       for(i = 0; i < UI_MAX_CALLBACK_COUNT; i++)
+               if(ui_callback_list[i].flag & UI_SLOTUSED && ui_callback_list[i].draw)
+                       ui_callback_list[i].draw();
+}
+
+void UI_Callback_KeyDown(int num, char ascii)
+{
+       if(ui_callback_list[key_dest - 3].flag & UI_SLOTUSED && ui_callback_list[key_dest - 3].keydown)
+               ui_callback_list[key_dest - 3].keydown(num, ascii);
+}
\ No newline at end of file
diff --git a/ui.h b/ui.h
index 91f9de8ff4a959f985f8991d3e52bae5d50e918c..b73c6e40d744d7873e593b7052747c9195f1f77a 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -1,7 +1,7 @@
 
 #ifndef UI_H
 #define UI_H
-
+/*
 // these defines and structures are for internal use only
 // (ui_t is passed around by users of the system, but should not be altered)
 #define MAX_UI_COUNT 16
@@ -78,7 +78,58 @@ void ui_item_remove(ui_t *ui, char *basename, int number);
 // checks if a panel is enabled
 int ui_uiactive(ui_t *ui);
 // enables/disables a panel on the screen
-void ui_activate(ui_t *ui, int yes);
+void ui_activate(ui_t *ui, int yes);*/
+
+// AK: new passive ui (like the menu stuff)
+#define UI_TEXT_DEFAULT_LENGTH 255
+typedef void * ui_item_t;
+typedef void * ui_itemlist_t;
+
+void UI_Init(void);
+
+void UI_Key(ui_itemlist_t, int key, int ascii);
+void UI_Draw(ui_itemlist_t);
+
+void UI_SetFocus(ui_itemlist_t, ui_item_t);
+void UI_SetNeighbors(ui_item_t left, ui_item_t right, ui_item_t up, ui_item_t down);
+
+// item stuff
+ui_item_t UI_CreateButton(const char *caption, float x, float y, void(*action)(ui_item_t)); 
+ui_item_t UI_CreateLabel(const char *caption, float x, float y);
+ui_item_t UI_CreateText(const char *caption, float x, float y, const char *allowed, int maxlen, int scrolllen);
+void UI_FreeItem(ui_item_t);
+
+const char* UI_GetCaption(ui_item_t);
+void UI_SetCaption(ui_item_t, const char *);
+
+// itemlist stuff
+ui_itemlist_t UI_CreateItemList(float x, float y);
+void UI_FreeItemList(ui_itemlist_t);
+
+void UI_AddItem(ui_itemlist_t, ui_item_t);
+
+// AK: new callback system
+#define UI_MAX_CALLBACK_COUNT 10
+
+#define UI_SLOTUSED    1
+typedef struct ui_callback_s
+{
+       unsigned int flag;
+       void (*keydown) (int num, char ascii);
+       void (*draw)    (void);
+} ui_callback_t;
+
+// functions which should be used
+void UI_Callback_Init(void);
+void UI_Callback_Reset(void);
+
+void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void));
+void UI_Callback_ResetSlot(int slotnr);
+int  UI_Callback_GetFreeSlot(void);
+int     UI_Callback_IsSlotUsed(int slotnr);
+
+void UI_Callback_Draw(void);
+void UI_Callback_KeyDown(int num, char ascii);
 
 #endif
 
index 4135f726b00bbe224a40e6edcb4c5c0edf7b1306..86eb757d2a7042c3956c691d470c98ab5a104f20 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -348,8 +348,8 @@ static void HandleEvents(void)
                                        p_mouse_y = event.xmotion.y;
                                }
                        }
-                       else
-                               ui_mouseupdate(event.xmotion.x, event.xmotion.y);
+                       //else
+                       //      ui_mouseupdate(event.xmotion.x, event.xmotion.y);
                        break;
 
                case ButtonPress:
index 049258ecdebc4e20d9f36464a3e2f1050c21108b..e23b1bc7ca84849d3d06363a4ea7b4bbfcc2f2ed 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -1313,7 +1313,7 @@ void IN_MouseMove (usercmd_t *cmd)
        if (!mouseactive)
        {
                GetCursorPos (&current_pos);
-               ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
+               //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
                in_mouse_x = in_mouse_y = 0;
                return;
        }
diff --git a/zone.c b/zone.c
index e20b42035b499d1eb5d610c63daf920a45ce7c55..da47317837585bac23fce699934c5aed92785cb0 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -204,7 +204,7 @@ void _Mem_Free(void *data, const char *filename, int fileline)
 #endif
 }
 
-mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline)
+mempool_t *_Mem_AllocPool(const char *name, mempool_t *parent, const char *filename, int fileline)
 {
        mempool_t *pool;
        pool = malloc(sizeof(mempool_t));
@@ -219,6 +219,7 @@ mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline)
        pool->totalsize = 0;
        pool->realsize = sizeof(mempool_t);
        strlcpy (pool->name, name, sizeof (pool->name));
+       pool->parent = parent;
        pool->next = poolchain;
        poolchain = pool;
        return pool;
@@ -226,7 +227,8 @@ mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline)
 
 void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline)
 {
-       mempool_t **chainaddress;
+       mempool_t **chainaddress, *iter, *temp;
+       
        if (*pool)
        {
                if ((*pool)->sentinel1 != MEMHEADER_SENTINEL1)
@@ -243,6 +245,11 @@ void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline)
                while ((*pool)->chain)
                        Mem_Free((void *)((qbyte *) (*pool)->chain + sizeof(memheader_t)));
 
+               // free child pools, too
+               for(iter = poolchain; iter; temp = iter = iter->next)
+                       if(iter->parent == *pool)
+                               _Mem_FreePool(&temp, filename, fileline);
+               
                // free the pool itself
                memset(*pool, 0xBF, sizeof(mempool_t));
                free(*pool);
@@ -252,6 +259,8 @@ void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline)
 
 void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline)
 {
+       mempool_t *chainaddress;
+       
        if (pool == NULL)
                Sys_Error("Mem_EmptyPool: pool == NULL (emptypool at %s:%i)", filename, fileline);
        if (pool->sentinel1 != MEMHEADER_SENTINEL1)
@@ -262,6 +271,12 @@ void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline)
        // free memory owned by the pool
        while (pool->chain)
                Mem_Free((void *)((qbyte *) pool->chain + sizeof(memheader_t)));
+
+       // empty child pools, too
+       for(chainaddress = poolchain; chainaddress; chainaddress = chainaddress->next)
+               if(chainaddress->parent == pool)
+                       _Mem_EmptyPool(chainaddress, filename, fileline);
+
 }
 
 void _Mem_CheckSentinels(void *data, const char *filename, int fileline)
@@ -403,6 +418,7 @@ void Memory_Init (void)
 {
        tempmempool = Mem_AllocPool("Temporary Memory");
        zonemempool = Mem_AllocPool("Zone");
+       poolchain = NULL;
 }
 
 void Memory_Init_Commands (void)
diff --git a/zone.h b/zone.h
index 36ef32657bc3917dc7b7d9b3e59189ca52f5af62..f49f14712d881ceabe5f0998c7e4d6d71dcdf282 100644 (file)
--- a/zone.h
+++ b/zone.h
@@ -103,6 +103,8 @@ typedef struct mempool_s
        char name[POOLNAMESIZE];
        // linked into global mempool list
        struct mempool_s *next;
+       // parent object (used for nested memory pools)
+       struct mempool_s *parent;
        // file name and line where Mem_AllocPool was called
        const char *filename;
        int fileline;
@@ -115,13 +117,14 @@ mempool_t;
 #define Mem_Free(mem) _Mem_Free(mem, __FILE__, __LINE__)
 #define Mem_CheckSentinels(data) _Mem_CheckSentinels(data, __FILE__, __LINE__)
 #define Mem_CheckSentinelsGlobal() _Mem_CheckSentinelsGlobal(__FILE__, __LINE__)
-#define Mem_AllocPool(name) _Mem_AllocPool(name, __FILE__, __LINE__)
+#define Mem_AllocPool(name) _Mem_AllocPool(name, NULL, __FILE__, __LINE__)
+#define Mem_AllocNestedPool(name, parent) _Mem_AllocPool(name, (parent), __FILE__, __LINE__)
 #define Mem_FreePool(pool) _Mem_FreePool(pool, __FILE__, __LINE__)
 #define Mem_EmptyPool(pool) _Mem_EmptyPool(pool, __FILE__, __LINE__)
 
 void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline);
 void _Mem_Free(void *data, const char *filename, int fileline);
-mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline);
+mempool_t *_Mem_AllocPool(const char *name, mempool_t *parent, const char *filename, int fileline);
 void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline);
 void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline);
 void _Mem_CheckSentinels(void *data, const char *filename, int fileline);