shithub: choc

Download patch

ref: 1462115f79d53521e43f7b77c0dde4ed4e6410d5
parent: 04911de6b34fe139214d7cc2893d2b1e8eb6ac44
parent: 63b550c068ccdbe23b269cc20593db868fcac8a7
author: Simon Howard <fraggle@gmail.com>
date: Mon Jul 13 19:36:48 EDT 2009

Merge from trunk.

Subversion-branch: /branches/raven-branch
Subversion-revision: 1626

--- 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
--- 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 @@
 {
 }
 
-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)
     {
-        mb_used = atoi(myargv[p+1]);
-        min_ram = mb_used;
+        available = default_ram * 1024 * 1024;
     }
 
+    if (available < min_ram * 1024 * 1024)
+    {
+        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,27 +152,57 @@
     {
         // 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);
--- 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>
 
--- a/src/z_native.c
+++ b/src/z_native.c
@@ -484,3 +484,8 @@
     return -1;
 }
 
+unsigned int Z_ZoneSize(void)
+{
+    return 0;
+}
+
--- a/src/z_zone.c
+++ b/src/z_zone.c
@@ -473,3 +473,8 @@
     return free;
 }
 
+unsigned int Z_ZoneSize(void)
+{
+    return mainzone->size;
+}
+
--- a/src/z_zone.h
+++ b/src/z_zone.h
@@ -67,7 +67,7 @@
 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