shithub: choc

Download patch

ref: 0f9690eb41e0aecbc6cee2d6c335b9dfbf0e02bf
parent: 5c11c607b88b4c7390b7636d58132f38edfeab12
author: Simon Howard <fraggle@gmail.com>
date: Mon Jul 25 16:41:59 EDT 2005

Port timer code to SDL

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 28

--- a/TODO
+++ b/TODO
@@ -1,6 +1,6 @@
 To do:
 
-* Port sound+timer code to SDL
+* Port sound code to SDL
 * Startup messages
 * Fix Final Doom, Ultimate Doom, IWAD selection in general
 * Check quit messages selected correctly
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_system.c 22 2005-07-23 19:42:56Z fraggle $
+// $Id: i_system.c 28 2005-07-25 20:41:59Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.5  2005/07/25 20:41:59  fraggle
+// Port timer code to SDL
+//
 // Revision 1.4  2005/07/23 19:42:56  fraggle
 // Startup messages as in the DOS exes
 //
@@ -40,7 +43,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_system.c 22 2005-07-23 19:42:56Z fraggle $";
+rcsid[] = "$Id: i_system.c 28 2005-07-25 20:41:59Z fraggle $";
 
 
 #include <stdlib.h>
@@ -48,8 +51,7 @@
 #include <string.h>
 
 #include <stdarg.h>
-#include <sys/time.h>
-#include <unistd.h>
+#include <SDL.h>
 
 #include "doomdef.h"
 #include "m_misc.h"
@@ -107,16 +109,17 @@
 //
 int  I_GetTime (void)
 {
-    struct timeval	tp;
-    struct timezone	tzp;
-    int			newtics;
-    static int		basetime=0;
-  
-    gettimeofday(&tp, &tzp);
-    if (!basetime)
-	basetime = tp.tv_sec;
-    newtics = (tp.tv_sec-basetime)*TICRATE + tp.tv_usec*TICRATE/1000000;
-    return newtics;
+    static Uint32 basetime = 0;
+    Uint32 ticks;
+
+    ticks = SDL_GetTicks();
+
+    if (basetime == 0)
+        basetime = ticks;
+
+    ticks -= basetime;
+
+    return (ticks * 35) / 1000;    
 }
 
 
@@ -127,7 +130,10 @@
 void I_Init (void)
 {
     I_InitSound();
-    //  I_InitGraphics();
+
+    // initialise timer
+
+    SDL_Init(SDL_INIT_TIMER);
 }
 
 //
@@ -145,23 +151,17 @@
 
 void I_WaitVBL(int count)
 {
-#ifdef SGI
-    sginap(1);                                           
-#else
-#ifdef SUN
-    sleep(0);
-#else
-    usleep (count * (1000000/70) );                                
-#endif
-#endif
+    SDL_Delay((count * 1000) / 70);
 }
 
 void I_BeginRead(void)
 {
+    // display "reading" disk
 }
 
 void I_EndRead(void)
 {
+    // remove "reading" disk
 }
 
 byte*	I_AllocLow(int length)