Changed dp so the new vm fits in.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 7 Oct 2003 06:19:14 +0000 (06:19 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 7 Oct 2003 06:19:14 +0000 (06:19 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3543 d7cf8633-e32d-0410-b094-e92efae38249

14 files changed:
cl_parse.c
cl_screen.c
cl_screen.h
gl_draw.c
host.c
keys.c
menu.c
menu.h
pr_edict.c
quakedef.h
sbar.c
snd_win.c
ui.c
vid_wgl.c

index ee94244..9095337 100644 (file)
@@ -807,6 +807,7 @@ void CL_ParseClientdata (int bits)
        cl.stats[STAT_CELLS] = MSG_ReadByte();
 
        i = MSG_ReadByte ();
+
        if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE)
                i = (1<<i);
        // GAME_NEXUIZ hud needs weapon change time
index c916aaf..d6f522c 100644 (file)
@@ -938,6 +938,14 @@ void CL_SetupScreenSize(void)
        vid.conwidth = vid_conwidth.integer;
        vid.conheight = vid_conheight.integer;
 
+/*     if (vid.realheight > 240)
+       {
+               vid.conheight = (vid.realheight - 240) * scr_2dresolution.value + 240;
+               vid.conheight = bound(240, vid.conheight, vid.realheight);
+       }
+       else
+               vid.conheight = 240;*/
+
        SCR_SetUpToDrawConsole();
 
        // determine size of refresh window
@@ -984,9 +992,9 @@ void CL_UpdateScreen(void)
                        SHOWLMP_drawall();
                        SCR_CheckDrawCenterString();
                }
-               ui_draw();
+               MR_Draw();
                CL_DrawVideo();
-               M_Draw();
+               ui_draw();
                if (cls.signon == SIGNONS)
                {
                        R_TimeReport("2d");
index 881f5b5..b289d39 100644 (file)
@@ -33,6 +33,7 @@ drawqueuemesh_t;
 
 #define DRAWFLAG_ADDITIVE 1
 #define DRAWFLAG_MODULATE 2
+#define DRAWFLAG_2XMODULATE 3
 
 // clear the draw queue
 void DrawQ_Clear(void);
index 3e0d58d..775a150 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -427,11 +427,13 @@ void R_DrawQueue(void)
        {
                dq = (drawqueue_t *)(r_refdef.drawqueue + pos);
                color = dq->color;
-
-               if(dq->flags & DRAWFLAG_ADDITIVE)
+               
+               if(dq->flags == DRAWFLAG_ADDITIVE)
                        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
-               else if(dq->flags & DRAWFLAG_MODULATE)
+               else if(dq->flags == DRAWFLAG_MODULATE)
                        GL_BlendFunc(GL_DST_COLOR, GL_ZERO);
+               else if(dq->flags == DRAWFLAG_2XMODULATE)
+                       GL_BlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
                else
                        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
diff --git a/host.c b/host.c
index 0f083e9..af56f26 100644 (file)
--- a/host.c
+++ b/host.c
@@ -166,6 +166,11 @@ void Host_Error (const char *error, ...)
 
        PR_Crash();
 
+       //PRVM_Crash(); // crash current prog
+
+       // crash all prvm progs
+       PRVM_CrashAll();
+
        if (sv.active)
                Host_ShutdownServer (false);
 
@@ -819,6 +824,7 @@ void Host_Frame (float time)
 //============================================================================
 
 void Render_Init(void);
+void M_Scipt_Init ();
 
 /*
 ====================
@@ -848,8 +854,9 @@ void Host_Init (void)
        Key_Init();
        Con_Init();
        Chase_Init();
-       M_Init();
        PR_Init();
+       PRVM_Init();
+       MR_Init();
        Mod_Init();
        NetConn_Init();
        SV_Init();
@@ -905,6 +912,13 @@ void Host_Shutdown(void)
        }
        isdown = true;
 
+       // Shutdown menu
+       MR_Shutdown;
+
+       // AK shutdown PRVM
+       // AK hmm, no PRVM_Shutdown(); yet
+       
+
        Host_WriteConfiguration ();
 
        CDAudio_Shutdown ();
diff --git a/keys.c b/keys.c
index e89ff17..1ef992d 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -836,10 +836,10 @@ void Key_Event (int key, qboolean down)
                        Key_Message (key);
                        break;
                case key_menu:
-                       M_Keydown (key);
+                       MR_Keydown (key);
                        break;
                case key_game:
-                       M_ToggleMenu_f ();
+                       MR_ToggleMenu_f ();
                        break;
                default:
                        Sys_Error ("Bad key_dest");
@@ -866,11 +866,15 @@ void Key_Event (int key, qboolean down)
                }
        }
 
-       if (key_consoleactive && consolekeys[key])
+       // AK What the fuck ?!?
+       // AK Changed so the code does what the comments tell 
+       // 
+       // 1. if console is active or not, always send the up events
+       if (key_consoleactive && consolekeys[key] && down)
        {
                // console only wants key down events
-               if (!down)
-                       return;
+               //if (!down)
+               //      return;
 
                // FIXME: this does not support non-QWERTY keyboards
                if (shift_down)
@@ -951,7 +955,7 @@ void Key_Event (int key, qboolean down)
                        Key_Message (key);
                        break;
                case key_menu:
-                       M_Keydown (key);
+                       MR_Keydown (key);
                        break;
 
                case key_game:
diff --git a/menu.c b/menu.c
index 7ca4c02..92307bd 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "image.h"
 
+#include "mprogdefs.h"
 
 #define TYPE_DEMO 1
 #define TYPE_GAME 2
@@ -3480,9 +3481,20 @@ void M_ServerList_Key(int k)
 //=============================================================================
 /* Menu Subsystem */
 
+void M_Keydown(int key);
+void M_Draw(void);
+void M_ToggleMenu_f(void);
+void M_Shutdown(void);
 
 void M_Init (void)
 {
+       // set menu router function pointer
+       MR_Keydown = M_Keydown;
+       MR_Draw = M_Draw;
+       MR_ToggleMenu_f = M_ToggleMenu_f;
+       MR_Shutdown = M_Shutdown;
+
+       // init
        menu_mempool = Mem_AllocPool("Menu");
        menuplyr_load = true;
        menuplyr_pixels = NULL;
@@ -3567,6 +3579,7 @@ void M_Draw (void)
 {
        if (key_dest != key_menu)
                m_state = m_none;
+
        if (m_state == m_none)
                return;
 
@@ -3731,3 +3744,160 @@ void M_Keydown (int key)
        }
 }
 
+void M_Shutdown(void)
+{
+}
+
+//============================================================================
+// Menu prog handling
+mfunction_t *PRVM_ED_FindFunction(const char *);
+
+#define M_F_INIT               "m_init"
+#define M_F_KEYDOWN            "m_keydown"
+#define M_F_DRAW               "m_draw"
+#define M_F_TOGGLE             "m_toggle"
+#define M_F_SHUTDOWN   "m_shutdown"
+
+static char *m_required_func[] = {
+M_F_INIT,
+M_F_KEYDOWN,
+M_F_DRAW,
+M_F_TOGGLE,
+M_F_SHUTDOWN,
+};
+
+static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
+
+static func_t m_draw,m_keydown;
+
+void MP_Error(void)
+{
+       // fall back to the normal menu
+
+       // say it
+       Con_Printf("Falling back to normal menu.\n Error :");
+       
+       // init the normal menu now -> this will also correct the menu router pointers
+       M_Init();
+}
+
+void MP_Keydown (int key)
+{
+       PRVM_Begin;
+       PRVM_SetProg(PRVM_MENUPROG);
+
+       // pass key
+       prog->globals[OFS_PARM0] = (float) key;
+       PRVM_ExecuteProgram(m_keydown, M_F_KEYDOWN"(float key) required\n");
+
+       PRVM_End;
+}
+void MP_Draw (void)
+{
+       PRVM_Begin;
+       PRVM_SetProg(PRVM_MENUPROG);
+       
+       PRVM_ExecuteProgram(m_draw,"");
+
+       PRVM_End;
+}
+
+void MP_ToggleMenu_f (void)
+{
+       PRVM_Begin;
+       PRVM_SetProg(PRVM_MENUPROG);
+
+       PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_TOGGLE) - prog->functions),"");
+
+       PRVM_End;
+}
+
+void MP_Shutdown (void)
+{
+       PRVM_Begin;
+       PRVM_SetProg(PRVM_MENUPROG);
+
+       PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_SHUTDOWN) - prog->functions),"");
+
+       // reset key_dest
+       key_dest = key_game;
+
+       // AK not using this cause Im not sure whether this is useful at all instead :
+/*     // free mempools
+       Mem_FreePool(prog->edicts_mempool);
+       Mem_FreePool(prog->edictstring_mempool);
+       Mem_FreePool(prog->progs_mempool);*/
+       PRVM_ResetProg();
+
+       PRVM_End;
+}
+
+void MP_Init (void)
+{
+       MR_Keydown = MP_Keydown;
+       MR_Draw = MP_Draw;
+       MR_ToggleMenu_f = MP_ToggleMenu_f;
+       MR_Shutdown = MP_Shutdown;
+       
+       PRVM_Begin;
+       PRVM_InitProg(PRVM_MENUPROG);
+       
+       prog->crc = M_PROGHEADER_CRC;
+       prog->edictprivate_size = 0; // no private struct used
+       prog->name = M_NAME;
+       prog->limit_edicts = M_MAX_EDICTS;
+       prog->extensionstring = vm_m_extensions;
+       prog->builtins = vm_m_builtins;
+       prog->numbuiltins = vm_m_numbuiltins;
+       prog->init_cmd = VM_M_Cmd_Init;
+       prog->reset_cmd = VM_M_Cmd_Reset;
+       prog->error_cmd = MP_Error;
+       
+       // allocate the mempools
+       prog->edicts_mempool = Mem_AllocPool(M_NAME " edicts mempool");
+       prog->edictstring_mempool = Mem_AllocPool( M_NAME " edict string mempool");
+       prog->progs_mempool = Mem_AllocPool(M_PROG_FILENAME);
+       
+       PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func);
+
+       // set m_draw and m_keydown
+       m_draw = (func_t) (PRVM_ED_FindFunction(M_F_DRAW) - prog->functions);
+       m_keydown = (func_t) (PRVM_ED_FindFunction(M_F_KEYDOWN) - prog->functions);
+       
+       // call the prog init
+       PRVM_ExecuteProgram((func_t) (PRVM_ED_FindFunction(M_F_INIT) - prog->functions),"");
+       
+       PRVM_End;
+}
+
+//============================================================================
+// Menu router
+
+static cvar_t forceqmenu = { 0, "forceqmenu", "0" };
+
+void MR_ChooseInit(void)
+{
+       if(!FS_FileExists(M_PROG_FILENAME) || forceqmenu.integer)
+               M_Init();
+       else
+               MP_Init();
+}
+
+void MR_Restart_f(void)
+{
+       MR_Shutdown ();
+       MR_ChooseInit ();
+}
+
+void MR_Init()
+{
+       // set router console commands
+       Cvar_RegisterVariable (&forceqmenu);
+       Cmd_AddCommand ("menu_restart",MR_Restart_f);
+
+       MR_ChooseInit ();
+}
+
+
+
+
diff --git a/menu.h b/menu.h
index e45af43..8bee52f 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -21,6 +21,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #ifndef MENU_H
 #define MENU_H
 
+#define M_PROG_FILENAME "menu.dat"
+#define M_NAME "MENU"
+#define M_MAX_EDICTS   (1 << 11) // should be enough for a menu
+
 enum m_state_e {
        m_none,
        m_main,
@@ -45,13 +49,31 @@ enum m_state_e {
 extern enum m_state_e m_state;
 extern char m_return_reason[32];
 
-//
-// menus
+/*
+// hard-coded menus
 //
 void M_Init (void);
 void M_Keydown (int key);
 void M_Draw (void);
 void M_ToggleMenu_f (void);
 
+//
+// menu prog menu
+//
+void MP_Init (void);
+void MP_Keydown (int key);
+void MP_Draw (void);
+void MP_ToggleMenu_f (void);
+void MP_Shutdown (void);*/
+
+//
+// menu router
+//
+void MR_Init (void);
+void MR_Restart_f (void);
+void (*MR_Keydown) (int key);
+void (*MR_Draw) (void);
+void (*MR_ToggleMenu_f) (void);
+void (*MR_Shutdown) (void);
 #endif
 
index b2264f5..efb16b5 100644 (file)
@@ -380,7 +380,7 @@ PR_ValueString
 Returns a string describing *data in a type specific manner
 =============
 */
-int NoCrash_NUM_FOR_EDICT(edict_t *e);
+//int NoCrash_NUM_FOR_EDICT(edict_t *e);
 char *PR_ValueString (etype_t type, eval_t *val)
 {
        static char line[1024]; // LordHavoc: enlarged a bit (was 256)
index 7ea3acb..14b431e 100644 (file)
@@ -202,6 +202,7 @@ extern char *buildstring;
 #include "client.h"
 #include "render.h"
 #include "progs.h"
+#include "progsvm.h"
 #include "server.h"
 
 #include "input.h"
diff --git a/sbar.c b/sbar.c
index f98d4de..af976c7 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -122,14 +122,11 @@ void sbar_start(void)
        int i;
 
        numsbarpics = 0;
-
+               
        sb_disc = Sbar_NewPic("gfx/disc");
 
        for (i = 0;i < 10;i++)
-       {
                sb_nums[0][i] = Sbar_NewPic (va("gfx/num_%i",i));
-               sb_nums[1][i] = Sbar_NewPic (va("gfx/anum_%i",i));
-       }
 
        sb_nums[0][10] = Sbar_NewPic ("gfx/num_minus");
        sb_nums[1][10] = Sbar_NewPic ("gfx/anum_minus");
@@ -137,19 +134,19 @@ void sbar_start(void)
        sb_colon = Sbar_NewPic ("gfx/num_colon");
        sb_slash = Sbar_NewPic ("gfx/num_slash");
 
-       //AK NEX uses its own hud
+       //AK NX uses its own hud
        if(gamemode == GAME_NEXUIZ)
        {
                sb_ammo[0] = Sbar_NewPic ("gfx/sb_shells");
                sb_ammo[1] = Sbar_NewPic ("gfx/sb_bullets");
                sb_ammo[2] = Sbar_NewPic ("gfx/sb_rocket");
                sb_ammo[3] = Sbar_NewPic ("gfx/sb_cells");
-
+               
                sb_items[2] = Sbar_NewPic ("gfx/sb_slowmo");
                sb_items[3] = Sbar_NewPic ("gfx/sb_invinc");
                sb_items[4] = Sbar_NewPic ("gfx/sb_energy");
                sb_items[5] = Sbar_NewPic ("gfx/sb_str");
-
+               
                sb_sbar = Sbar_NewPic("gfx/sbar");
                sb_sbar_overlay = Sbar_NewPic("gfx/sbar_overlay");
 
@@ -157,7 +154,7 @@ void sbar_start(void)
                        sb_weapons[0][i] = Sbar_NewPic(va("gfx/inv_weapon%i",i));
 
                return;
-       }
+       }       
 
        sb_weapons[0][0] = Sbar_NewPic ("gfx/inv_shotgun");
        sb_weapons[0][1] = Sbar_NewPic ("gfx/inv_sshotgun");
@@ -365,6 +362,39 @@ void Sbar_DrawNum (int x, int y, int num, int digits, int color)
 
                Sbar_DrawPic (x, y, sb_nums[color][frame]);
                x += 24;
+
+               ptr++;
+       }
+}
+
+/*
+=============
+Sbar_DrawXNum
+=============
+*/
+
+void Sbar_DrawXNum (int x, int y, int num, int digits, int lettersize, float r, float g, float b, float a, int flags)
+{
+       char str[32], *ptr;
+       int l, frame;
+       
+       l = sprintf(str, "%i", num);
+       ptr = str;
+       if (l > digits)
+               ptr += (l-digits);
+       if (l < digits)
+               x += (digits-l) * lettersize;
+               
+       while (*ptr)
+       {
+               if (*ptr == '-')
+                       frame = STAT_MINUS;
+               else
+                       frame = *ptr -'0';
+               
+               DrawQ_Pic (sbar_x + x, sbar_y + y, sb_nums[0][frame]->name,lettersize,lettersize,r,g,b,a,flags);
+               x += lettersize;
+
                ptr++;
        }
 }
@@ -821,7 +851,7 @@ void Sbar_Draw (void)
 {
        if (scr_con_current == vid.conheight)
                return;         // console is full screen
-
+       
        if (cl.intermission == 1)
        {
                Sbar_IntermissionOverlay();
@@ -837,45 +867,60 @@ void Sbar_Draw (void)
        {
                sbar_y = vid.conheight - 47;
                sbar_x = (vid.conwidth - 640)/2;
-
-               if (sb_lines > 24)
-                       Sbar_DrawFrags ();
-
+               
+               if (sb_lines)
+               {
+                       Sbar_DrawInventory(); 
+                       if (!cl.islocalgame)
+                               Sbar_DrawFrags ();
+               }
+               
                if (sb_showscores || cl.stats[STAT_HEALTH] <= 0)
                {
-                       if (gamemode != GAME_GOODVSBAD2)
-                               Sbar_DrawAlphaPic (0, 0, sb_scorebar, 0.4);
+                       Sbar_DrawAlphaPic (0, 0, sb_scorebar, 0.4);
                        Sbar_DrawScoreboard ();
                }
                else if (sb_lines)
                {
                        Sbar_DrawPic (0, 0, sb_sbar);
-
+                       
                        // special items
                        if (cl.items & IT_INVULNERABILITY)
                        {
-                               Sbar_DrawNum (24, 0, 666, 3, 1);
+                               Sbar_DrawNum (36, 0, 666, 3, 1);
                                Sbar_DrawPic (0, 0, sb_disc);
                        }
 
                        // armor
-                       Sbar_DrawNum ((340-3*24), 12, cl.stats[STAT_ARMOR], 3, cl.stats[STAT_ARMOR] <= 25);
-
+                       Sbar_DrawXNum ((340-3*24), 12, cl.stats[STAT_ARMOR], 3, 24, 0.6,0.7,0.8,1,0);
+                       
                        // health
-                       Sbar_DrawNum ((154-3*24), 12, cl.stats[STAT_HEALTH], 3, cl.stats[STAT_HEALTH] <= 25);
-
-                       if (cl.items & NEX_IT_SHELLS)
-                               Sbar_DrawPic (519, 0, sb_ammo[0]);
-                       else if (cl.items & NEX_IT_BULLETS)
-                               Sbar_DrawPic (519, 0, sb_ammo[1]);
-                       else if (cl.items & NEX_IT_ROCKETS)
-                               Sbar_DrawPic (519, 0, sb_ammo[2]);
-                       else if (cl.items & NEX_IT_CELLS)
-                               Sbar_DrawPic (519, 0, sb_ammo[3]);
-
-                       Sbar_DrawNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, cl.stats[STAT_AMMO] <= 10);
+                       if(cl.stats[STAT_HEALTH] > 100)
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,1,1,1,1,0);
+                       else if(cl.stats[STAT_HEALTH] <= 25 && cl.time - (int)cl.time > 0.5)
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,0.7,0,0,1,0);
+                       else    
+                               Sbar_DrawXNum((154-3*24),12,cl.stats[STAT_HEALTH],3,24,0.6,0.7,0.8,1,0);
+
+                       // AK dont draw ammo for the laser
+                       if(cl.stats[STAT_ACTIVEWEAPON] != 12)
+                       {
+                               if (cl.items & NEX_IT_SHELLS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[0]);
+                               else if (cl.items & NEX_IT_BULLETS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[1]);
+                               else if (cl.items & NEX_IT_ROCKETS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[2]);
+                               else if (cl.items & NEX_IT_CELLS)
+                                       Sbar_DrawPic (519, 0, sb_ammo[3]);
+                               
+                               if(cl.stats[STAT_AMMO] <= 10) 
+                                       Sbar_DrawXNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, 24, 0.7, 0,0,1,0);
+                               else
+                                       Sbar_DrawXNum ((519-3*24), 12, cl.stats[STAT_AMMO], 3, 24, 0.6, 0.7,0.8,1,0);
+                               
+                       }
 
-                       //Sbar_DrawAlphaPic(0,0,sb_sbar_overlay,0.5);
                        DrawQ_Pic(sbar_x,sbar_y,sb_sbar_overlay->name,0,0,1,1,1,1,DRAWFLAG_MODULATE);
                }
        }
@@ -988,7 +1033,6 @@ void Sbar_Draw (void)
                }
        }
 
-
        if (vid.conwidth > 320 && cl.gametype == GAME_DEATHMATCH)
                Sbar_MiniDeathmatchOverlay ();
 
@@ -1051,8 +1095,13 @@ void Sbar_MiniDeathmatchOverlay (void)
        int i, x, y, numlines;
 
        // decide where to print
-       x = 324;
-       y = vid.conheight - sb_lines;
+       x = 0;
+       // AK Nex wants its scores on the upper left
+       if(gamemode == GAME_NEXUIZ)
+               y = 0; 
+       else
+               y = vid.conheight - sb_lines;
+
        numlines = (vid.conheight - y) / 8;
        // give up if there isn't room
        if (x + (6 + 15) * 8 > vid.conwidth || numlines < 1)
index 23c9009..694cd0d 100644 (file)
--- a/snd_win.c
+++ b/snd_win.c
@@ -681,7 +681,9 @@ void SNDDMA_Submit(void)
        {
                if ( snd_completed == snd_sent )
                {
+#ifndef AKVERSION
                        Con_DPrintf ("Sound overrun\n");
+#endif 
                        break;
                }
 
diff --git a/ui.c b/ui.c
index 82fccb5..bb9398e 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -23,7 +23,7 @@ static ui_item_t *ui_keyrealitem;
 static ui_t *ui_list[MAX_UI_COUNT];
 
 static void ui_start(void)
-{
+{      
        ui_mouse_x = vid.conwidth * 0.5;
        ui_mouse_y = vid.conheight * 0.5;
        ui_alive = true;
@@ -45,6 +45,7 @@ void ui_init(void)
        uimempool = Mem_AllocPool("UI");
 
        Cvar_RegisterVariable(&ui_showname);
+
        R_RegisterModule("UI", ui_start, ui_shutdown, ui_newmap);
 }
 
index 31507a4..358993b 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -976,6 +976,9 @@ void VID_Shutdown (void)
        HGLRC hRC = 0;
        HDC hDC = 0;
 
+       if(vid_initialized == false)
+               return;
+
        VID_RestoreSystemGamma();
 
        vid_initialized = false;