summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/i_system.c50
-rw-r--r--src/i_video.c11
-rw-r--r--src/setup/execute.c143
3 files changed, 166 insertions, 38 deletions
diff --git a/src/i_system.c b/src/i_system.c
index 0ec8e185..c6deb905 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -55,6 +55,8 @@
#include "w_wad.h"
#include "z_zone.h"
+#define MIN_RAM 4 /* MiB */
+
int mb_used = 16;
typedef struct atexit_listentry_s atexit_listentry_t;
@@ -86,8 +88,10 @@ void I_Tactile(int on, int off, int total)
{
}
-int I_GetHeapSize (void)
+byte *I_ZoneBase (int *size)
{
+ byte *zonemem;
+ int min_ram = MIN_RAM;
int p;
//!
@@ -97,28 +101,46 @@ int I_GetHeapSize (void)
//
p = M_CheckParm("-mb");
-
+
if (p > 0)
{
mb_used = atoi(myargv[p+1]);
+ min_ram = mb_used;
}
-
- return mb_used*1024*1024;
-}
-
-byte *I_ZoneBase (int *size)
-{
- byte *zonemem;
- *size = I_GetHeapSize();
+ // Allocate the zone memory. This loop tries progressively smaller
+ // zone sizes until a size is found that can be allocated.
+ // If we used the -mb command line parameter, only the parameter
+ // provided is accepted.
- zonemem = malloc(*size);
+ zonemem = NULL;
- if (zonemem == NULL)
+ while (zonemem == NULL)
{
- I_Error("Failed to allocate %i bytes for zone memory", *size);
+ // We need a reasonable minimum amount of RAM to start.
+
+ if (mb_used < min_ram)
+ {
+ I_Error("Unable to allocate %i MiB of RAM for zone", mb_used);
+ }
+
+ // Try to allocate the zone memory.
+
+ *size = mb_used * 1024 * 1024;
+
+ zonemem = malloc(*size);
+
+ // Failed to allocate? Reduce zone size until we reach a size
+ // that is acceptable. We decrease by 2 MiB at a time to ensure
+ // that there is 1-2 MiB still free on the system (my Windows
+ // Mobile PDA becomes unstable if very low on memory)
+
+ if (zonemem == NULL)
+ {
+ mb_used -= 2;
+ }
}
-
+
printf("zone memory: %p, %x allocated for zone\n",
zonemem, *size);
diff --git a/src/i_video.c b/src/i_video.c
index a938b1f8..6f82e60a 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -662,13 +662,20 @@ void I_GetEvent(void)
event.data1 = TranslateKey(&sdlevent.key.keysym);
event.data2 = GetTypedChar(&sdlevent);
- D_PostEvent(&event);
+ if (event.data1 != 0)
+ {
+ D_PostEvent(&event);
+ }
break;
case SDL_KEYUP:
event.type = ev_keyup;
event.data1 = TranslateKey(&sdlevent.key.keysym);
- D_PostEvent(&event);
+
+ if (event.data1 != 0)
+ {
+ D_PostEvent(&event);
+ }
break;
/*
diff --git a/src/setup/execute.c b/src/setup/execute.c
index 1b510f2e..18a07156 100644
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -29,11 +29,13 @@
#include <sys/types.h>
#if defined(_WIN32_WCE)
-
#include "libc_wince.h"
+#endif
-#elif defined(_WIN32)
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#include <process.h>
#else
@@ -66,7 +68,6 @@ static char *TempFile(char *s)
char *tempdir;
#ifdef _WIN32
-
// Check the TEMP environment variable to find the location.
tempdir = getenv("TEMP");
@@ -134,28 +135,131 @@ void AddCmdLineParameter(execute_context_t *context, char *s, ...)
fprintf(context->stream, "\n");
}
-#if defined(_WIN32_WCE)
+#if defined(_WIN32)
+
+// Wait for the specified process to exit. Returns the exit code.
-static int ExecuteCommand(const char **argv)
+static unsigned int WaitForProcessExit(HANDLE subprocess)
{
- // Windows CE version.
- // TODO
- return 0;
+ DWORD exit_code;
+
+ for (;;)
+ {
+ WaitForSingleObject(subprocess, INFINITE);
+
+ if (!GetExitCodeProcess(subprocess, &exit_code))
+ {
+ return -1;
+ }
+
+ if (exit_code != STILL_ACTIVE)
+ {
+ return exit_code;
+ }
+ }
}
-#elif defined(_WIN32)
+static wchar_t *GetFullExePath(const char *program)
+{
+ wchar_t *result;
+ unsigned int path_len;
+ char *sep;
+
+ // Find the full path to the EXE to execute, by taking the path
+ // to this program and concatenating the EXE name:
+
+ sep = strrchr(myargv[0], DIR_SEPARATOR);
+
+ if (sep == NULL)
+ {
+ path_len = 0;
+ result = calloc(strlen(program) + 1, sizeof(wchar_t));
+ }
+ else
+ {
+ path_len = sep - myargv[0] + 1;
+
+ result = calloc(path_len + strlen(program) + 1,
+ sizeof(wchar_t));
+ MultiByteToWideChar(CP_OEMCP, 0,
+ myargv[0], path_len,
+ result, path_len);
+ }
-static int ExecuteCommand(const char **argv)
+ MultiByteToWideChar(CP_OEMCP, 0,
+ program, strlen(program) + 1,
+ result + path_len, strlen(program) + 1);
+
+ return result;
+}
+
+// Convert command line argument to wchar_t string and add surrounding
+// "" quotes:
+
+static wchar_t *GetPaddedWideArg(const char *arg)
+{
+ wchar_t *result;
+ unsigned int len = strlen(arg);
+
+ // Convert the command line arg to a wide char string:
+
+ result = calloc(len + 3, sizeof(wchar_t));
+ MultiByteToWideChar(CP_OEMCP, 0,
+ arg, len + 1,
+ result + 1, len + 1);
+
+ // Surrounding quotes:
+
+ result[0] = '"';
+ result[len + 1] = '"';
+ result[len + 2] = 0;
+
+ return result;
+}
+
+static int ExecuteCommand(const char *program, const char *arg)
{
- return _spawnv(_P_WAIT, argv[0], argv);
+ PROCESS_INFORMATION proc_info;
+ wchar_t *exe_path;
+ wchar_t *warg;
+ int result = 0;
+
+ exe_path = GetFullExePath(program);
+ warg = GetPaddedWideArg(arg);
+
+ // Invoke the program:
+
+ memset(&proc_info, 0, sizeof(proc_info));
+
+ if (!CreateProcessW(exe_path, warg,
+ NULL, NULL, FALSE, 0, NULL, NULL, NULL,
+ &proc_info))
+ {
+ result = -1;
+ }
+ else
+ {
+ // Wait for the process to finish, and save the exit code.
+
+ result = WaitForProcessExit(proc_info.hProcess);
+
+ CloseHandle(proc_info.hProcess);
+ CloseHandle(proc_info.hThread);
+ }
+
+ free(exe_path);
+ free(warg);
+
+ return result;
}
#else
-static int ExecuteCommand(const char **argv)
+static int ExecuteCommand(const char *program, const char *arg)
{
pid_t childpid;
int result;
+ const char *argv[] = { program, arg, NULL };
childpid = fork();
@@ -189,7 +293,6 @@ static int ExecuteCommand(const char **argv)
int ExecuteDoom(execute_context_t *context)
{
- const char *argv[3];
char *response_file_arg;
int result;
@@ -200,17 +303,13 @@ int ExecuteDoom(execute_context_t *context)
response_file_arg = malloc(strlen(context->response_file) + 2);
sprintf(response_file_arg, "@%s", context->response_file);
- argv[0] = GetExecutableName();
- argv[1] = response_file_arg;
- argv[2] = NULL;
-
// Run Doom
- result = ExecuteCommand(argv);
+ result = ExecuteCommand(GetExecutableName(), response_file_arg);
free(response_file_arg);
-
- // Destroy context
+
+ // Destroy context
remove(context->response_file);
free(context->response_file);
free(context);
@@ -245,8 +344,8 @@ static void TestCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(data))
exec = NewExecuteContext();
AddCmdLineParameter(exec, "-testcontrols");
- AddCmdLineParameter(exec, "-config %s", main_cfg);
- AddCmdLineParameter(exec, "-extraconfig %s", extra_cfg);
+ AddCmdLineParameter(exec, "-config \"%s\"", main_cfg);
+ AddCmdLineParameter(exec, "-extraconfig \"%s\"", extra_cfg);
ExecuteDoom(exec);
TXT_CloseWindow(testwindow);