From ba5e77e02152408b6d0ffb2cba467f0df815388e Mon Sep 17 00:00:00 2001
From: Randy Heit <rheit@zdoom.fake>
Date: Sun, 28 Jan 2007 03:17:02 +0000
Subject: [PATCH] - Fixed: Since FMemLump is now implemented on top of FString,
 it never   contains a NULL point, so the GetMem() method should fake it by  
 returning NULL when the string is empty. Reverted p_xlat.cpp to its   old
 revision.

SVN r465 (trunk)
---
 docs/rh-log.txt |  6 ++++++
 src/p_xlat.cpp  | 32 ++++++++------------------------
 src/w_wad.h     |  3 ++-
 3 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index ce238f6f8..287da5553 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,3 +1,9 @@
+January 27, 2007
+- Fixed: Since FMemLump is now implemented on top of FString, it never
+  contains a NULL point, so the GetMem() method should fake it by
+  returning NULL when the string is empty. Reverted p_xlat.cpp to its
+  old revision.
+
 January 26, 2007 (Changes by Graf Zahl)
 - Fixed: The rewrite of FMemLump broke the non-standard use of it in 
   P_TranslateLinedefs.
diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp
index 2cf2e1eb0..f9d81d945 100644
--- a/src/p_xlat.cpp
+++ b/src/p_xlat.cpp
@@ -48,7 +48,6 @@
 #include "w_wad.h"
 #include "sc_man.h"
 #include "cmdlib.h"
-#include "i_system.h"
 
 // define names for the TriggerType field of the general linedefs
 
@@ -64,17 +63,10 @@ typedef enum
 	PushMany,
 } triggertype_e;
 
-
-BYTE *tlatetab;
-
-static void Freetlate()
-{
-	if (tlatetab != NULL) delete [] tlatetab;
-	tlatetab = NULL;
-}
-
 void P_TranslateLineDef (line_t *ld, maplinedef_t *mld)
 {
+	static FMemLump tlatebase;
+	const BYTE *tlate;
 	short special = LittleShort(mld->special);
 	short tag = LittleShort(mld->tag);
 	DWORD flags = LittleShort(mld->flags);
@@ -129,31 +121,23 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld)
 		return;
 	}
 
-	if (tlatetab == NULL)
+	// The translation lump is cached across calls to P_TranslateLineDef.
+	if (tlatebase.GetMem() == NULL)
 	{
-		const char *lumpname;
-		int lumpnum, lumplen;
 		if (gameinfo.gametype == GAME_Doom)
 		{
-			lumpname = "DOOMX";
+			tlatebase = Wads.ReadLump ("DOOMX");
 		}
 		else if (gameinfo.gametype == GAME_Strife)
 		{
-			lumpname = "STRIFEX";
+			tlatebase = Wads.ReadLump ("STRIFEX");
 		}
 		else
 		{
-			lumpname = "HERETICX";
+			tlatebase = Wads.ReadLump ("HERETICX");
 		}
-
-		lumpnum = Wads.GetNumForName (lumpname);
-		lumplen = Wads.LumpLength(lumpnum);
-
-		tlatetab = new BYTE[lumplen];
-		Wads.ReadLump(lumpnum, tlatetab);
-		atterm(Freetlate);
 	}
-	BYTE *tlate = tlatetab;
+	tlate = (const BYTE *)tlatebase.GetMem();
 
 	// Check if this is a regular linetype
 	if (tlate[0] == 'N' && tlate[1] == 'O' && tlate[2] == 'R' && tlate[3] == 'M')
diff --git a/src/w_wad.h b/src/w_wad.h
index f92ddba90..29177e9fb 100644
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -132,7 +132,8 @@ public:
 	FMemLump (const FMemLump &copy);
 	FMemLump &operator= (const FMemLump &copy);
 	~FMemLump ();
-	void *GetMem () { return (void *)Block.GetChars(); }
+	void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); }
+	unsigned int GetSize () { return Block.Len(); }
 
 private:
 	FMemLump (const FString &source);