]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - menu.c
cd audio now tied to sound system
[xonotic/darkplaces.git] / menu.c
diff --git a/menu.c b/menu.c
index eb9165994c2a57dcd372b99f5056801384c0e5fc..24f1e0983d4403f0933405f377979d1f246e233d 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
@@ -683,7 +684,7 @@ void M_ScanSaves (void)
                str = FS_Getline (f);
                sscanf (str, "%i\n", &version);
                str = FS_Getline (f);
-               strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
+               strlcpy (m_filenames[i], str, sizeof (m_filenames[i]));
 
        // change _ back to space
                for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
@@ -1430,7 +1431,7 @@ void M_Menu_Options_Effects_AdjustSliders (int dir)
        else if (options_effects_cursor == optnum++)
                Cvar_SetValueQuick (&r_waterscroll, bound(0, r_waterscroll.value + dir * 0.5, 10));
        else if (options_effects_cursor == optnum++)
-               Cvar_SetValueQuick (&r_watershader, !r_watershader.integer);
+               Cvar_SetValueQuick (&r_watershader, bound(0, r_watershader.value + dir * 0.25, 10));
 }
 
 void M_Options_Effects_Draw (void)
@@ -1468,7 +1469,7 @@ void M_Options_Effects_Draw (void)
        M_Options_PrintCheckbox("   Model Interpolation", true, r_lerpmodels.integer);
        M_Options_PrintCheckbox("  Sprite Interpolation", true, r_lerpsprites.integer);
        M_Options_PrintSlider(  "        Water Movement", true, r_waterscroll.value, 0, 10);
-       M_Options_PrintCheckbox(" GeForce3 Water Shader", true, r_watershader.integer);
+       M_Options_PrintSlider(  " GeForce3 Water Shader", true, r_watershader.value, 0, 10);
 }
 
 
@@ -2135,10 +2136,10 @@ void M_Keys_Key (int k)
 //=============================================================================
 /* VIDEO MENU */
 
-#define VIDEO_ITEMS 5
+#define VIDEO_ITEMS 4
 
 int video_cursor = 0;
-int video_cursor_table[] = {56, 68, 80, 92, 116};
+int video_cursor_table[] = {56, 68, 80, 100};
 // note: if modes are added to the beginning of this list, update the
 // video_resolution = x; in M_Menu_Video_f below
 unsigned short video_resolutions[][2] = {{320,240}, {400,300}, {512,384}, {640,480}, {800,600}, {1024,768}, {1152,864}, {1280,960}, {1280,1024}, {1600,1200}, {1792,1344}, {1920,1440}, {2048,1536}};
@@ -2148,7 +2149,6 @@ extern int current_vid_fullscreen;
 extern int current_vid_width;
 extern int current_vid_height;
 extern int current_vid_bitsperpixel;
-extern int current_vid_stencil;
 
 
 void M_Menu_Video_f (void)
@@ -2200,12 +2200,8 @@ void M_Video_Draw (void)
        M_Print(16, video_cursor_table[2], "            Fullscreen");
        M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer);
 
-       // Stencil
-       M_Print(16, video_cursor_table[3], "               Stencil");
-       M_DrawCheckbox(220, video_cursor_table[3], vid_stencil.integer);
-
        // "Apply" button
-       M_Print(220, video_cursor_table[4], "Apply");
+       M_Print(220, video_cursor_table[3], "Apply");
 
        // Cursor
        M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
@@ -2241,9 +2237,6 @@ void M_Menu_Video_AdjustSliders (int dir)
                case 2:
                        Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
                        break;
-               case 3:
-                       Cvar_SetValueQuick (&vid_stencil, !vid_stencil.integer);
-                       break;
        }
 }
 
@@ -2258,7 +2251,6 @@ void M_Video_Key (int key)
                        Cvar_SetValueQuick(&vid_width, current_vid_width);
                        Cvar_SetValueQuick(&vid_height, current_vid_height);
                        Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel);
-                       Cvar_SetValueQuick(&vid_stencil, current_vid_stencil);
 
                        S_LocalSound ("misc/menu1.wav");
                        M_Menu_Options_f ();
@@ -3480,9 +3472,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 +3570,7 @@ void M_Draw (void)
 {
        if (key_dest != key_menu)
                m_state = m_none;
+
        if (m_state == m_none)
                return;
 
@@ -3731,3 +3735,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 ();
+}
+
+
+
+