foxygit / doom Log in
commit 90da953b2310151b5a56f3ea78d8528100fd1fa0
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Sep 6 20:18:50 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Sep 6 20:18:50 2008 +0000

    Remove dependencies of i_video.c on doom/ code.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1205
---
 src/doom/d_main.c   | 30 ++++++++++++++++----
 src/doom/doomstat.h |  3 --
 src/doom/g_game.c   |  8 ------
 src/i_system.c      |  2 +-
 src/i_video.c       | 80 +++++++++++++++++++++++++++++++++++++----------------
 src/i_video.h       |  9 +++++-
 src/net_gui.c       |  2 +-
 7 files changed, 91 insertions(+), 43 deletions(-)

diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 6a6ab57d..a7fed952 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -107,11 +107,6 @@ boolean         fastparm;	// checkparm of -fast
 boolean		singletics = false; // debug flag to cancel adaptiveness


-// If true, game is running as a screensaver
-
-boolean         screensaver_mode = false;
-
-
 //extern int soundVolume;
 //extern  int	sfxVolume;
 //extern  int	musicVolume;
@@ -340,7 +335,28 @@ void D_Display (void)
     } while (!done);
 }

+//
+// D_GrabMouseCallback
+//
+// Called to determine whether to grab the mouse pointer
+//

+boolean D_GrabMouseCallback(void)
+{
+    // Drone players don't need mouse focus
+
+    if (drone)
+        return false;
+
+    // when menu is active or game is paused, release the mouse
+
+    if (menuactive || paused)
+        return false;
+
+    // only grab mouse when playing levels (but not demos)
+
+    return (gamestate == GS_LEVEL) && !demoplayback;
+}

 //
 //  D_DoomLoop
@@ -363,6 +379,8 @@ void D_DoomLoop (void)
     TryRunTics();

     I_InitGraphics ();
+    I_SetGrabMouseCallback(D_GrabMouseCallback);
+    I_SetWindowTitle(gamedescription);

     R_ExecuteSetViewSize();

@@ -868,6 +886,8 @@ void D_DoomMain (void)

     devparm = M_CheckParm ("-devparm");

+    I_DisplayFPSDots(devparm);
+
     //!
     // @category net
     // @vanilla
diff --git a/src/doom/doomstat.h b/src/doom/doomstat.h
index 4fc174cd..2207fb25 100644
--- a/src/doom/doomstat.h
+++ b/src/doom/doomstat.h
@@ -55,8 +55,6 @@ extern  boolean	fastparm;	// checkparm of -fast
 extern  boolean	devparm;	// DEBUG: launched with -devparm


-extern  boolean screensaver_mode;    // game running as a screensaver?
-
 // -----------------------------------------------------
 // Game Mode - identify IWAD as shareware, retail etc.
 //
@@ -147,7 +145,6 @@ extern  boolean	paused;		// Game Pause?
 extern  boolean		viewactive;

 extern  boolean		nodrawers;
-extern  boolean		noblit;

 extern	int		viewwindowx;
 extern	int		viewwindowy;
diff --git a/src/doom/g_game.c b/src/doom/g_game.c
index 978f38ee..defcf368 100644
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -122,7 +122,6 @@ boolean         usergame;               // ok to save / end game

 boolean         timingdemo;             // if true, exit with report on completion
 boolean         nodrawers;              // for comparative timing purposes
-boolean         noblit;                 // for comparative timing purposes
 int             starttime;          	// for comparative timing purposes

 boolean         viewactive;
@@ -2056,13 +2055,6 @@ void G_TimeDemo (char* name)

     nodrawers = M_CheckParm ("-nodraw");

-    //!
-    // @vanilla
-    //
-    // Disable blitting the screen.
-    //
-
-    noblit = M_CheckParm ("-noblit");
     timingdemo = true;
     singletics = true;

diff --git a/src/i_system.c b/src/i_system.c
index cbf9760a..218acc59 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -145,7 +145,7 @@ void I_Endoom(void)

     // Make sure the new window has the right title and icon

-    I_SetWindowCaption();
+    I_SetWindowTitle("Exit screen");
     I_SetWindowIcon();

     // Write the data to the screen memory
diff --git a/src/i_video.c b/src/i_video.c
index cbfc4b4c..dc4a249e 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -36,8 +36,6 @@
 #include "deh_main.h"
 #include "doomtype.h"
 #include "doomkeys.h"
-#include "doomstat.h"
-#include "d_main.h"
 #include "i_joystick.h"
 #include "i_system.h"
 #include "i_swap.h"
@@ -46,7 +44,6 @@
 #include "i_scale.h"
 #include "m_argv.h"
 #include "s_sound.h"
-#include "sounds.h"
 #include "v_video.h"
 #include "w_wad.h"
 #include "z_zone.h"
@@ -137,11 +134,30 @@ int startup_delay = 1000;

 int grabmouse = true;

+// If true, game is running as a screensaver
+
+boolean screensaver_mode = false;
+
 // Flag indicating whether the screen is currently visible:
 // when the screen isnt visible, don't render the screen

 boolean screenvisible;

+// If true, we display dots at the bottom of the screen to
+// indicate FPS.
+
+static boolean display_fps_dots;
+
+// If this is true, the screen is rendered but not blitted to the
+// video buffer.
+
+static boolean noblit;
+
+// Callback function to invoke to determine whether to grab the
+// mouse pointer.
+
+static grabmouse_callback_t grabmouse_callback = NULL;
+
 // disk image data and background overwritten by the disk to be
 // restored by EndRead

@@ -199,24 +215,34 @@ static boolean MouseShouldBeGrabbed()
     if (!usemouse || nomouse)
         return false;

-    // Drone players don't need mouse focus
-
-    if (drone)
-        return false;
-
     // if we specify not to grab the mouse, never grab

     if (!grabmouse)
         return false;

-    // when menu is active or game is paused, release the mouse
-
-    if (menuactive || paused)
-        return false;
+    // Invoke the grabmouse callback function to determine whether
+    // the mouse should be grabbed

-    // only grab mouse when playing levels (but not demos)
+    if (grabmouse_callback != NULL)
+    {
+        return grabmouse_callback();
+    }
+    else
+    {
+        return true;
+    }
+}

-    return (gamestate == GS_LEVEL) && !demoplayback;
+void I_SetGrabMouseCallback(grabmouse_callback_t func)
+{
+    grabmouse_callback = func;
+}
+
+// Set the variable controlling FPS dots.
+
+void I_DisplayFPSDots(boolean dots_on)
+{
+    display_fps_dots = dots_on;
 }

 // Update the value of window_focused when we get a focus event
@@ -520,11 +546,13 @@ void I_GetEvent(void)
 		}
                 break;

+/* TODO
             case SDL_QUIT:
                 // bring up the "quit doom?" prompt
                 S_StartSound(NULL,sfx_swtchn);
                 M_QuitDOOM(0);
                 break;
+                */

             case SDL_ACTIVEEVENT:
                 // need to update our focus state
@@ -771,9 +799,9 @@ void I_FinishUpdate (void)
         return;

     // draws little dots on the bottom of the screen
-    if (devparm)
-    {

+    if (display_fps_dots)
+    {
 	i = I_GetTime();
 	tics = i - lasttic;
 	lasttic = i;
@@ -783,7 +811,6 @@ void I_FinishUpdate (void)
 	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
 	for ( ; i<20*4 ; i+=4)
 	    screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
-
     }

     // draw to screen
@@ -832,16 +859,16 @@ void I_SetPalette (byte *doompalette)
 }

 //
-// Set the window caption
+// Set the window title
 //

-void I_SetWindowCaption(void)
+void I_SetWindowTitle(char *title)
 {
     char *buf;

-    buf = Z_Malloc(strlen(gamedescription) + strlen(PACKAGE_STRING) + 10,
+    buf = Z_Malloc(strlen(title) + strlen(PACKAGE_STRING) + 5,
                    PU_STATIC, NULL);
-    sprintf(buf, "%s - %s", gamedescription, PACKAGE_STRING);
+    sprintf(buf, "%s - %s", title, PACKAGE_STRING);

     SDL_WM_SetCaption(buf, NULL);

@@ -1168,6 +1195,14 @@ static void CheckCommandLine(void)
 {
     int i;

+    //!
+    // @vanilla
+    //
+    // Disable blitting the screen.
+    //
+
+    noblit = M_CheckParm ("-noblit");
+
     //!
     // @category video
     //
@@ -1514,9 +1549,6 @@ void I_InitGraphics(void)
     I_SetPalette(doompal);
     SDL_SetColors(screen, palette, 0, 256);

-    // Setup title and icon
-
-    I_SetWindowCaption();
     I_SetWindowIcon();

     CreateCursors();
diff --git a/src/i_video.h b/src/i_video.h
index 3e871d5c..f95adc96 100644
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -69,6 +69,8 @@ typedef struct
     boolean poor_quality;
 } screen_mode_t;

+typedef boolean (*grabmouse_callback_t)(void);
+
 // Called by D_DoomMain,
 // determines the hardware configuration
 // and sets up the video mode
@@ -91,10 +93,13 @@ void I_ReadScreen (byte* scr);
 void I_BeginRead (void);
 void I_EndRead (void);

-void I_SetWindowCaption(void);
+void I_SetWindowTitle(char *title);
 void I_SetWindowIcon(void);

 void I_CheckIsScreensaver(void);
+void I_SetGrabMouseCallback(grabmouse_callback_t func);
+
+void I_DisplayFPSDots(boolean dots_on);

 extern char *video_driver;
 extern int autoadjust_video_settings;
@@ -107,6 +112,8 @@ extern float mouse_acceleration;
 extern int mouse_threshold;
 extern int startup_delay;
 extern int vanilla_keyboard_mapping;
+extern boolean screensaver_mode;
+

 #endif

diff --git a/src/net_gui.c b/src/net_gui.c
index 4cbe0699..f85b6a48 100644
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -267,7 +267,7 @@ void NET_WaitForStart(void)
         exit(-1);
     }

-    I_SetWindowCaption();
+    I_SetWindowTitle("Waiting for game start");
     I_SetWindowIcon();

     BuildGUI();