From bf2e9460b1c8ae1d7b6792ef2df986e8f3c2cf86 Mon Sep 17 00:00:00 2001 From: black Date: Tue, 23 Dec 2003 12:12:03 +0000 Subject: [PATCH] Fast commit before Im off for 10 days. Please correct/undo my commit if it breaks something, I havent had time to test everything perfectly but Im hoping that everything works. Merry Christmas everybody ! git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3749 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_screen.c | 3 +- gl_rmain.c | 3 +- host.c | 2 +- keys.c | 10 +++- todo | 4 +- ui.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++- ui.h | 55 +++++++++++++++++++- vid_glx.c | 4 +- vid_wgl.c | 2 +- zone.c | 20 +++++++- zone.h | 7 ++- 11 files changed, 236 insertions(+), 17 deletions(-) diff --git a/cl_screen.c b/cl_screen.c index 8bc1084f..b8038ba7 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -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"); diff --git a/gl_rmain.c b/gl_rmain.c index 0efd3974..952078c1 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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 119a7aa5..69e980f1 100644 --- 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 7b10bfbf..fab2478b 100644 --- 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 e0654f60..17f54fba 100644 --- 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 bb9398e2..661ae30e 100644 --- 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 91f9de8f..b73c6e40 100644 --- 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 diff --git a/vid_glx.c b/vid_glx.c index 4135f726..86eb757d 100644 --- 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: diff --git a/vid_wgl.c b/vid_wgl.c index 049258ec..e23b1bc7 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -1313,7 +1313,7 @@ void IN_MouseMove (usercmd_t *cmd) if (!mouseactive) { GetCursorPos (¤t_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 e20b4203..da473178 100644 --- 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 36ef3265..f49f1471 100644 --- 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); -- 2.39.2