summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--src/i_system.c105
-rw-r--r--src/w_file_win32.c2
-rw-r--r--src/z_native.c5
-rw-r--r--src/z_zone.c5
-rw-r--r--src/z_zone.h2
6 files changed, 99 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index 42071458..2d6db773 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@
devices (eg. PDAs/embedded devices)
* The textscreen library now has a scrollable pane widget.
* Doxygen documentation was added for the textscreen library.
+ * The "join game" window in the setup tool now has an option
+ to automatically join a game on the local network.
Compatibility:
* The A_BossDeath behavior in v1.9 emulation mode was fixed
diff --git a/src/i_system.c b/src/i_system.c
index c6deb905..cd8ddcee 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -55,9 +55,9 @@
#include "w_wad.h"
#include "z_zone.h"
-#define MIN_RAM 4 /* MiB */
+#define DEFAULT_RAM 16 /* MiB */
+#define MIN_RAM 4 /* MiB */
-int mb_used = 16;
typedef struct atexit_listentry_s atexit_listentry_t;
@@ -88,26 +88,59 @@ void I_Tactile(int on, int off, int total)
{
}
-byte *I_ZoneBase (int *size)
+#ifdef _WIN32_WCE
+
+// Windows CE-specific auto-allocation function that allocates the zone
+// size based on the amount of memory reported free by the OS.
+
+static byte *AutoAllocMemory(int *size, int default_ram, int min_ram)
{
+ MEMORYSTATUS memory_status;
byte *zonemem;
- int min_ram = MIN_RAM;
- int p;
+ size_t available;
- //!
- // @arg <mb>
- //
- // Specify the heap size, in MiB (default 16).
- //
+ // Get available physical RAM. We leave one megabyte extra free
+ // for the OS to keep running (my PDA becomes unstable if too
+ // much RAM is allocated)
- p = M_CheckParm("-mb");
+ GlobalMemoryStatus(&memory_status);
+ available = memory_status.dwAvailPhys - 2 * 1024 * 1024;
- if (p > 0)
+ // Limit to default_ram if we have more than that available:
+
+ if (available > default_ram * 1024 * 1024)
+ {
+ available = default_ram * 1024 * 1024;
+ }
+
+ if (available < min_ram * 1024 * 1024)
{
- mb_used = atoi(myargv[p+1]);
- min_ram = mb_used;
+ I_Error("Unable to allocate %i MiB of RAM for zone", min_ram);
}
+ // Allocate zone:
+
+ *size = available;
+ zonemem = malloc(*size);
+
+ if (zonemem == NULL)
+ {
+ I_Error("Failed when allocating %i bytes", *size);
+ }
+
+ return zonemem;
+}
+
+#else
+
+// Zone memory auto-allocation function that allocates the zone size
+// by trying progressively smaller zone sizes until one is found that
+// works.
+
+static byte *AutoAllocMemory(int *size, int default_ram, int min_ram)
+{
+ byte *zonemem;
+
// 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
@@ -119,28 +152,58 @@ byte *I_ZoneBase (int *size)
{
// We need a reasonable minimum amount of RAM to start.
- if (mb_used < min_ram)
+ if (default_ram < min_ram)
{
- I_Error("Unable to allocate %i MiB of RAM for zone", mb_used);
+ I_Error("Unable to allocate %i MiB of RAM for zone", default_ram);
}
// Try to allocate the zone memory.
- *size = mb_used * 1024 * 1024;
+ *size = default_ram * 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)
+ // that is acceptable.
if (zonemem == NULL)
{
- mb_used -= 2;
+ default_ram -= 1;
}
}
+ return zonemem;
+}
+
+#endif
+
+byte *I_ZoneBase (int *size)
+{
+ byte *zonemem;
+ int min_ram, default_ram;
+ int p;
+
+ //!
+ // @arg <mb>
+ //
+ // Specify the heap size, in MiB (default 16).
+ //
+
+ p = M_CheckParm("-mb");
+
+ if (p > 0)
+ {
+ default_ram = atoi(myargv[p+1]);
+ min_ram = default_ram;
+ }
+ else
+ {
+ default_ram = DEFAULT_RAM;
+ min_ram = MIN_RAM;
+ }
+
+ zonemem = AutoAllocMemory(size, default_ram, min_ram);
+
printf("zone memory: %p, %x allocated for zone\n",
zonemem, *size);
diff --git a/src/w_file_win32.c b/src/w_file_win32.c
index ec17cf6c..9e5d963f 100644
--- a/src/w_file_win32.c
+++ b/src/w_file_win32.c
@@ -28,6 +28,8 @@
#ifdef _WIN32
+#include <stdio.h>
+
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
diff --git a/src/z_native.c b/src/z_native.c
index 7d31bc6c..ac618222 100644
--- a/src/z_native.c
+++ b/src/z_native.c
@@ -484,3 +484,8 @@ int Z_FreeMemory(void)
return -1;
}
+unsigned int Z_ZoneSize(void)
+{
+ return 0;
+}
+
diff --git a/src/z_zone.c b/src/z_zone.c
index 54a5ffc5..a3900f5b 100644
--- a/src/z_zone.c
+++ b/src/z_zone.c
@@ -473,3 +473,8 @@ int Z_FreeMemory (void)
return free;
}
+unsigned int Z_ZoneSize(void)
+{
+ return mainzone->size;
+}
+
diff --git a/src/z_zone.h b/src/z_zone.h
index 44eb365b..a00630cf 100644
--- a/src/z_zone.h
+++ b/src/z_zone.h
@@ -67,7 +67,7 @@ void Z_FileDumpHeap (FILE *f);
void Z_CheckHeap (void);
void Z_ChangeTag2 (void *ptr, int tag, char *file, int line);
int Z_FreeMemory (void);
-
+unsigned int Z_ZoneSize(void);
//
// This is used to get the local FILE:LINE info from CPP