07-23-2001 Matt Hargett <[EMAIL PROTECTED]>
* main.c: Get rid of sched_yield remnants and use
sci_sched_yield().
* scriptdebug.c: Ditto.
* kernel.c (kGetTime): Check return value of
timeBeginPeriod/timeEndPeriod. Properly wrap all time
calls.
* tools.c (sci_gettime): Ditto.
* dd_driver.cpp: Remove Win32_usleep. Call Sleep instead.
* graphics_ddraw.c: Ditto.
* sdl_driver.c: Remove winsock2.h include.
* soundserver_sdl.c (sounds_sdl_get_command): Change Sleep(0)
to Sleep(1).
* freesci.def: Get rid of deprecated functions.
NOTE: CPU usage on win32 is no longer 100%, thanks to the Sleep change in
the SDL soundserver. This also means timers are now always accurate within
1ms on my K6-3+ 550mhz! I still get the occasional slow sound, but very
very rarely at this point.
A new binary build is up @
http://www.clock.org/~matt/tmp/freesci-win32.zip
for anyone who wants to test.
--
http://www.clock.org/~matt
-- Attached file included as plaintext by Listar --
-- File: freesci.diff
? freesci/bin
? freesci/src/win32/freesci.ncb
? freesci/src/win32/scidisasm_Debug
? freesci/src/win32/fsci_dll_Debug
? freesci/src/win32/fsci_dll.plg
? freesci/src/win32/Debug
? freesci/src/win32/Release
? freesci/src/win32/freesci.plg
? freesci/src/win32/sciv_Release
? freesci/src/win32/sciv.plg
? freesci/src/win32/fsci_dll_Release
? freesci/src/win32/freesci_instr
? freesci/src/win32/fsci_dll.dsp
? freesci/src/win32/freesci.opt
Index: freesci/src/main.c
===================================================================
RCS file: /home/cvs/freesci/src/main.c,v
retrieving revision 1.115
diff -u -p -r1.115 main.c
--- freesci/src/main.c 2001/07/21 22:32:43 1.115
+++ freesci/src/main.c 2001/07/24 04:33:31
@@ -40,9 +40,6 @@
#ifdef HAVE_FORK
# include <sys/wait.h>
#endif
-#ifdef HAVE_SCHED_YIELD
-# include <sched.h>
-#endif /* HAVE_SCHED_YIELD */
#ifdef _MSC_VER
#define extern __declspec(dllimport) extern
@@ -73,15 +70,14 @@
#ifdef _WIN32
-#include <direct.h>
-#define PATH_MAX 255
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#define sleep Sleep
-#define strcasecmp stricmp
+# include <direct.h>
+# define PATH_MAX 255
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# define sleep Sleep
+# define strcasecmp stricmp
#endif
-
#define ACTION_PLAY 0
#define ACTION_LIST_SAVEGAMES 1
@@ -757,24 +753,24 @@ int
main(int argc, char** argv)
{
config_entry_t *active_conf = NULL;
- config_entry_t *confs = NULL;
+ config_entry_t *confs = NULL;
cl_options_t cl_options;
- int conf_entries = -1; /* Number of config entries */
- int conf_nr = -1; /* Element of conf to use */
+ int conf_entries = -1; /* Number of config
+entries */
+ int conf_nr = -1; /* Element of
+conf to use */
int errc;
FILE *console_logfile = NULL;
- char startdir[PATH_MAX+1];
- char resource_dir[PATH_MAX+1];
- char work_dir[PATH_MAX+1];
+ char startdir[PATH_MAX+1] = {0};
+ char resource_dir[PATH_MAX+1] = {0};
+ char work_dir[PATH_MAX+1] = {0};
char *gfx_driver_name = NULL;
char *midiout_driver_name = NULL;
char *midi_device_name = NULL;
- char *game_name = NULL;
- char *savegame_name = NULL;
+ char *game_name = NULL;
+ char *savegame_name = NULL;
sci_version_t version = 0;
gfx_driver_t *gfx_driver = NULL;
sound_server_t *sound_server = NULL;
- char *module_path = SCI_DEFAULT_MODULE_PATH;
+ char *module_path = SCI_DEFAULT_MODULE_PATH;
game_name = parse_arguments(argc, argv, &cl_options, &savegame_name);
@@ -835,8 +831,9 @@ main(int argc, char** argv)
init_console();
- sciprintf("FreeSCI, version "VERSION"\n");
-
+
+ sciprintf("FreeSCI, version "VERSION"\n");
+
gamestate = malloc(sizeof(state_t));
if (init_gamestate(gamestate, version))
Index: freesci/src/engine/kernel.c
===================================================================
RCS file: /home/cvs/freesci/src/engine/kernel.c,v
retrieving revision 1.27
diff -u -p -r1.27 kernel.c
--- freesci/src/engine/kernel.c 2001/07/22 10:16:36 1.27
+++ freesci/src/engine/kernel.c 2001/07/24 04:33:31
@@ -501,15 +501,17 @@ kGetTime(state_t *s, int funct_nr, int a
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT
| KERNEL_OPT_FLAG_GOT_2NDEVENT);
- the_time = time(NULL);
#ifdef _WIN32
- timeBeginPeriod(0);
+ if (TIMERR_NOERROR != timeBeginPeriod(1))
+ {
+ fprintf(stderr, "timeBeginPeriod(1) failed in kGetTime!\n");
+ }
#endif _WIN32
-
+ the_time = time(NULL);
loc_time = localtime(&the_time);
#ifdef _WIN32
- timeEndPeriod(0);
+ timeEndPeriod(1);
#endif _WIN32
if (s->version<SCI_VERSION_FTU_NEW_GETTIME) { /* Use old semantics */
Index: freesci/src/engine/scriptdebug.c
===================================================================
RCS file: /home/cvs/freesci/src/engine/scriptdebug.c,v
retrieving revision 1.59
diff -u -p -r1.59 scriptdebug.c
--- freesci/src/engine/scriptdebug.c 2001/07/21 22:32:43 1.59
+++ freesci/src/engine/scriptdebug.c 2001/07/24 04:33:33
@@ -1865,14 +1865,8 @@ c_snd(state_t *s)
return 1;
}
-#ifdef HAVE_SCHED_YIELD
- sched_yield();
-#endif
-#ifdef HAVE_USLEEP
- usleep(350000);
-#else
- sleep(1);
-#endif
+ sci_sched_yield();
+
process_sound_events(s);
return 0;
}
@@ -1917,6 +1911,7 @@ c_sndmap(state_t *s)
sci_sched_yield();
gfxop_usleep(s->gfx_state, 350000);
+
process_sound_events(s);
return 0;
}
Index: freesci/src/gfx/drivers/dd_driver.cpp
===================================================================
RCS file: /home/cvs/freesci/src/gfx/drivers/dd_driver.cpp,v
retrieving revision 1.3
diff -u -p -r1.3 dd_driver.cpp
--- freesci/src/gfx/drivers/dd_driver.cpp 2001/07/12 17:26:59 1.3
+++ freesci/src/gfx/drivers/dd_driver.cpp 2001/07/24 04:33:34
@@ -760,30 +760,11 @@ MsgWait (int WaitTime)
} while(1);
}
-static void
-Win32_usleep (long usec)
-{
- LARGE_INTEGER lFrequency;
- LARGE_INTEGER lEndTime;
- LARGE_INTEGER lCurTime;
-
- QueryPerformanceFrequency (&lFrequency);
- if (lFrequency.QuadPart)
- {
- QueryPerformanceCounter (&lEndTime);
- lEndTime.QuadPart += (LONGLONG) usec * lFrequency.QuadPart / 1000000;
- do
- {
- QueryPerformanceCounter (&lCurTime);
- } while (lCurTime.QuadPart < lEndTime.QuadPart);
- }
-}
-
int
dd_usleep(gfx_driver_t* drv, int usec)
{
if (usec < 1000)
- Win32_usleep (usec);
+ Sleep(usec / 1000);
else
MsgWait (usec / 1000);
Index: freesci/src/gfx/drivers/sdl_driver.c
===================================================================
RCS file: /home/cvs/freesci/src/gfx/drivers/sdl_driver.c,v
retrieving revision 1.39
diff -u -p -r1.39 sdl_driver.c
--- freesci/src/gfx/drivers/sdl_driver.c 2001/07/22 13:42:32 1.39
+++ freesci/src/gfx/drivers/sdl_driver.c 2001/07/24 04:33:34
@@ -32,7 +32,6 @@
# include <sys/time.h>
# include <SDL/SDL.h>
#else
-# include <winsock2.h>
# include <SDL.h>
#endif
Index: freesci/src/graphics/graphics_ddraw.c
===================================================================
RCS file: /home/cvs/freesci/src/graphics/graphics_ddraw.c,v
retrieving revision 1.17
diff -u -p -r1.17 graphics_ddraw.c
--- freesci/src/graphics/graphics_ddraw.c 2000/06/03 06:20:08 1.17
+++ freesci/src/graphics/graphics_ddraw.c 2001/07/24 04:33:35
@@ -658,33 +658,12 @@ MsgWait (int WaitTime)
}
void
-Win32_usleep (long usec)
-{
- /* [DJ] I don't think that message pumping should be done in a function
- which is supposed to work with microsecond precision. */
- LARGE_INTEGER lFrequency;
- LARGE_INTEGER lEndTime;
- LARGE_INTEGER lCurTime;
-
- QueryPerformanceFrequency (&lFrequency);
- if (lFrequency.QuadPart)
- {
- QueryPerformanceCounter (&lEndTime);
- lEndTime.QuadPart += (LONGLONG) usec * lFrequency.QuadPart / 1000000;
- do
- {
- QueryPerformanceCounter (&lCurTime);
- } while (lCurTime.QuadPart < lEndTime.QuadPart);
- }
-}
-
-void
ddraw_wait (state_t *s, long usec)
{
/* For short waits, use high-precision, high-CPU-load wait. For longer
waits, use low-precision, low-CPU-load wait. */
if (usec <= 1000)
- Win32_usleep (usec);
+ Sleep(usec / 1000);
else
MsgWait (usec / 1000);
}
Index: freesci/src/scicore/tools.c
===================================================================
RCS file: /home/cvs/freesci/src/scicore/tools.c,v
retrieving revision 1.28
diff -u -p -r1.28 tools.c
--- freesci/src/scicore/tools.c 2001/07/13 17:03:56 1.28
+++ freesci/src/scicore/tools.c 2001/07/24 04:33:36
@@ -222,11 +222,14 @@ void sci_gettime(int *seconds, int *usec
{
DWORD tm;
- timeBeginPeriod(0);
+ if (TIMERR_NOERROR != timeBeginPeriod(1))
+ {
+ fprintf(stderr, "timeBeginPeriod(1) failed in sci_gettime\n");
+ }
tm = timeGetTime();
- timeEndPeriod(0);
+ timeEndPeriod(1);
*seconds = tm/1000;
*useconds = tm*1000;
Index: freesci/src/sound/soundserver_sdl.c
===================================================================
RCS file: /home/cvs/freesci/src/sound/soundserver_sdl.c,v
retrieving revision 1.25
diff -u -p -r1.25 soundserver_sdl.c
--- freesci/src/sound/soundserver_sdl.c 2001/06/07 19:19:00 1.25
+++ freesci/src/sound/soundserver_sdl.c 2001/07/24 04:33:36
@@ -189,7 +189,7 @@ sound_sdl_get_command(GTimeVal *wait_tvp
if (!sound_eq_peek_event(&inqueue)) {
#ifdef _MSC_VER
- Sleep(0);
+ Sleep(1);
#else
usleep(0);
#endif
Index: freesci/src/win32/freesci.def
===================================================================
RCS file: /home/cvs/freesci/src/win32/freesci.def,v
retrieving revision 1.8
diff -u -p -r1.8 freesci.def
--- freesci/src/win32/freesci.def 2001/06/14 21:13:07 1.8
+++ freesci/src/win32/freesci.def 2001/07/24 04:33:36
@@ -30,8 +30,6 @@ EXPORTS
formats DATA
; sci_color_mode DATA
sci_version DATA
-; makeMIDI0
-; mapMIDIInstruments
script_dissect
set_debug_mode
_debug_get_input DATA
@@ -59,19 +57,10 @@ EXPORTS
SCI_Version_Types DATA
Resource_Types DATA
resource_type_suffixes DATA
-; g_strcasecmp
- ; g_free
loadObjects
printObject
makeMIDI0
mapMIDIInstruments
- ;using_history DATA
- ;add_history
- ;readline
- ;optind DATA
- ;optarg DATA
- ;getopt
- ;getopt_long
gfxop_init
gfxop_exit
@@ -104,5 +93,6 @@ EXPORTS
game_restore
sci_find_next
sci_sched_yield
+ sci_gettime