- Made improvements so that the FOptionalMapinfoData class is easier to use.

SVN r1401 (trunk)
This commit is contained in:
Christoph Oelckers 2009-02-04 23:45:26 +00:00
parent b387752f2f
commit 84c5c7d38e
2 changed files with 34 additions and 3 deletions

View file

@ -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 February 3, 2009
- Moved the MF_INCHASE recursion check from A_Look() into A_Chase(). This - 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 lets A_Look() always put the actor into its see state. This problem could

View file

@ -212,9 +212,6 @@ class DScroller;
class FScanner; class FScanner;
struct level_info_t; struct level_info_t;
typedef void (*MIParseFunc)(FScanner &sc, level_info_t *info);
void AddOptionalMapinfoParser(const char *keyword, MIParseFunc parsefunc);
struct FOptionalMapinfoData struct FOptionalMapinfoData
{ {
@ -225,6 +222,18 @@ struct FOptionalMapinfoData
virtual FOptionalMapinfoData *Clone() const = 0; 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<FName, FOptionalMapinfoDataPtr> FOptData;
struct level_info_t struct level_info_t
{ {
char mapname[9]; char mapname[9];
@ -278,6 +287,8 @@ struct level_info_t
float teamdamage; float teamdamage;
FOptData optdata;
TArray<FSpecialAction> specialactions; TArray<FSpecialAction> specialactions;
level_info_t() level_info_t()
@ -296,6 +307,23 @@ struct level_info_t
void ClearDefered(); void ClearDefered();
level_info_t *CheckLevelRedirect (); level_info_t *CheckLevelRedirect ();
template<class T>
T *GetOptData(FName id, bool create = true)
{
FOptionalMapinfoDataPtr *pdat = optdata.CheckKey(id);
if (pdat != NULL)
{
return static_cast<T*>(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. // [RH] These get zeroed every tic and are updated by thinkers.