aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/fgdlib/gamedata.h
blob: cf8b5be12db85897a8046eaa22a9b515248d2ac5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef GAMEDATA_H
#define GAMEDATA_H
#ifdef _WIN32
#pragma once
#endif

#pragma warning(push, 1)
#pragma warning(disable:4701 4702 4530)
#include <fstream>
#pragma warning(pop)
#include "TokenReader.h"
#include "GDClass.h"
#include "InputOutput.h"
#include "UtlString.h"
#include "utlvector.h"


class MDkeyvalue;
class GameData;
class KeyValues;

enum TEXTUREFORMAT;


typedef void (*GameDataMessageFunc_t)(int level, PRINTF_FORMAT_STRING const char *fmt, ...);

// FGD-based AutoMaterialExclusion data

struct FGDMatExlcusions_s
{
	char szDirectory[MAX_PATH];		// Where we store the material exclusion directories
	bool bUserGenerated;			// If the user specified this ( default:  false -- FGD defined )
};

// FGD-based AutoVisGroup data

struct FGDVisGroupsBaseClass_s
{
	char szClass[MAX_PATH];				// i.e. Scene Logic, Sounds, etc   "Custom\Point Entities\Lights"
	CUtlStringList szEntities;			// i.e. func_viscluster
};

struct FGDAutoVisGroups_s
{
	char szParent[MAX_PATH];								// i.e. Custom, SFM, etc
	CUtlVector< FGDVisGroupsBaseClass_s >	m_Classes;		// i.e. Scene Logic, Sounds, etc
};

#define MAX_DIRECTORY_SIZE	32


//-----------------------------------------------------------------------------
// Purpose: Contains the set of data that is loaded from a single FGD file.
//-----------------------------------------------------------------------------
class GameData
{
	public:
		typedef enum
		{
			NAME_FIXUP_PREFIX = 0,
			NAME_FIXUP_POSTFIX,
			NAME_FIXUP_NONE
		} TNameFixup;

		GameData();
		~GameData();

		BOOL Load(const char *pszFilename);

		GDclass *ClassForName(const char *pszName, int *piIndex = NULL);

		void ClearData();

		inline int GetMaxMapCoord(void);
		inline int GetMinMapCoord(void);

		inline int GetClassCount();
		inline GDclass *GetClass(int nIndex);

		GDclass *BeginInstanceRemap( const char *pszClassName, const char *pszInstancePrefix, Vector &Origin, QAngle &Angle );
		bool	RemapKeyValue( const char *pszKey, const char *pszInValue, char *pszOutValue, TNameFixup NameFixup );
		bool	RemapNameField( const char *pszInValue, char *pszOutValue, TNameFixup NameFixup );
		bool	LoadFGDMaterialExclusions( TokenReader &tr );
		bool	LoadFGDAutoVisGroups( TokenReader &tr );
		

		CUtlVector< FGDMatExlcusions_s >	m_FGDMaterialExclusions;

		CUtlVector< FGDAutoVisGroups_s >	m_FGDAutoVisGroups;

	private:

		bool ParseMapSize(TokenReader &tr);

		CUtlVector<GDclass *> m_Classes;

		int m_nMinMapCoord;		// Min & max map bounds as defined by the FGD.
		int m_nMaxMapCoord;

		// Instance Remapping
		Vector		m_InstanceOrigin;			// the origin offset of the instance
		QAngle		m_InstanceAngle;			// the rotation of the the instance
		matrix3x4_t	m_InstanceMat;				// matrix of the origin and rotation of rendering
		char		m_InstancePrefix[ 128 ];	// the prefix used for the instance name remapping
		GDclass		*m_InstanceClass;			// the entity class that is being remapped
};


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline int GameData::GetClassCount()
{
	return m_Classes.Count();
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline GDclass *GameData::GetClass(int nIndex)
{
	if (nIndex >= m_Classes.Count())
		return NULL;
		
	return m_Classes.Element(nIndex);
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
int GameData::GetMinMapCoord(void)
{
	return m_nMinMapCoord;
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
int GameData::GetMaxMapCoord(void)
{
	return m_nMaxMapCoord;
}


void GDSetMessageFunc(GameDataMessageFunc_t pFunc);
bool GDError(TokenReader &tr, PRINTF_FORMAT_STRING const char *error, ...);
bool GDSkipToken(TokenReader &tr, trtoken_t ttexpecting = TOKENNONE, const char *pszExpecting = NULL);
bool GDGetToken(TokenReader &tr, char *pszStore, int nSize, trtoken_t ttexpecting = TOKENNONE, const char *pszExpecting = NULL);
bool GDGetTokenDynamic(TokenReader &tr, char **pszStore, trtoken_t ttexpecting, const char *pszExpecting = NULL);


#endif // GAMEDATA_H