From 258c19f4115ddd25403246b5bb69575e032a1087 Mon Sep 17 00:00:00 2001
From: helixhorned <helixhorned@1a8010ca-5511-0410-912e-c29ae57300e0>
Date: Thu, 29 Mar 2012 21:17:35 +0000
Subject: [PATCH] When requesting a non-fogged identity lookup from
 makepalookup(), alias to palookup[0].

(That is, the base shade table.) Before, we allocated each palookup buffer.
For a vanilla setup, this means that we're now saving 224*32*256 ~= 1.8 megs,
which might be interesting for low-memory gadgets.

git-svn-id: https://svn.eduke32.com/eduke32@2571 1a8010ca-5511-0410-912e-c29ae57300e0
---
 polymer/eduke32/build/src/engine.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c
index c63d18701..2dda7c850 100644
--- a/polymer/eduke32/build/src/engine.c
+++ b/polymer/eduke32/build/src/engine.c
@@ -8022,7 +8022,10 @@ void uninitengine(void)
     }
 
     for (i=0; i<MAXPALOOKUPS; i++)
-        if (palookup[i] != NULL) { Bfree(palookup[i]); palookup[i] = NULL; }
+        if (palookup[i] != NULL && (i==0 || palookup[i] != palookup[0]))
+        {
+            Bfree(palookup[i]);
+        }
 
 #ifdef DYNALLOC_ARRAYS
     if (blockptr != NULL)
@@ -13424,6 +13427,12 @@ void makepalookup(int32_t palnum, const char *remapbuf, int8_t r, int8_t g, int8
 
     if (remapbuf==NULL)
     {
+        if ((r|g|b) == 0)
+        {
+            palookup[palnum] = palookup[0];  // Alias to base shade table!
+            return;
+        }
+
         if (idmap[0]==1)  // init identity map
             for (i=0; i<256; i++)
                 idmap[i] = i;
@@ -13431,7 +13440,7 @@ void makepalookup(int32_t palnum, const char *remapbuf, int8_t r, int8_t g, int8
         remapbuf = idmap;
     }
 
-    if (palookup[palnum] == NULL)
+    if (palookup[palnum] == NULL || palookup[palnum] == palookup[0])
     {
         //Allocate palookup buffer
         palookup[palnum] = Bmalloc(numshades<<8);