From 84c5c7d38ee4a88697cdbc4b44375f587fff66ba Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 4 Feb 2009 23:45:26 +0000 Subject: [PATCH] - Made improvements so that the FOptionalMapinfoData class is easier to use. SVN r1401 (trunk) --- docs/rh-log.txt | 3 +++ src/g_level.h | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 767e3a3b2..98f102e16 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,6 @@ +February 5, 2009 (Changes by Graf Zahl) +- Made improvements so that the FOptionalMapinfoData class is easier to use. + February 3, 2009 - Moved the MF_INCHASE recursion check from A_Look() into A_Chase(). This lets A_Look() always put the actor into its see state. This problem could diff --git a/src/g_level.h b/src/g_level.h index 593bd3423..48db7b197 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -212,9 +212,6 @@ class DScroller; class FScanner; struct level_info_t; -typedef void (*MIParseFunc)(FScanner &sc, level_info_t *info); - -void AddOptionalMapinfoParser(const char *keyword, MIParseFunc parsefunc); struct FOptionalMapinfoData { @@ -225,6 +222,18 @@ struct FOptionalMapinfoData virtual FOptionalMapinfoData *Clone() const = 0; }; +struct FOptionalMapinfoDataPtr +{ + FOptionalMapinfoData *Ptr; + + FOptionalMapinfoDataPtr() throw() : Ptr(NULL) {} + ~FOptionalMapinfoDataPtr() { if (Ptr!=NULL) delete Ptr; } + FOptionalMapinfoDataPtr(const FOptionalMapinfoDataPtr &p) throw() : Ptr(p.Ptr->Clone()) {} + FOptionalMapinfoDataPtr &operator= (FOptionalMapinfoDataPtr &p) throw() { Ptr = p.Ptr->Clone(); return *this; } +}; + +typedef TMap FOptData; + struct level_info_t { char mapname[9]; @@ -278,6 +287,8 @@ struct level_info_t float teamdamage; + FOptData optdata; + TArray specialactions; level_info_t() @@ -296,6 +307,23 @@ struct level_info_t void ClearDefered(); level_info_t *CheckLevelRedirect (); + template + T *GetOptData(FName id, bool create = true) + { + FOptionalMapinfoDataPtr *pdat = optdata.CheckKey(id); + + if (pdat != NULL) + { + return static_cast(pdat->Ptr); + } + else if (create) + { + T *newobj = new T; + optdata[id].Ptr = newobj; + return newobj; + } + else return NULL; + } }; // [RH] These get zeroed every tic and are updated by thinkers.