summaryrefslogtreecommitdiff
path: root/hammer/detailobjects.h
blob: 332c775e780630e9e1b096dd9bbb8a8791d5fc8d (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
160
161
162
163
164
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

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

#include "mathlib/mathlib.h"
#include "datamap.h"
#include "bspfile.h"
#include "builddisp.h"
#include "mapface.h"
#include "mapdisp.h"
#include "utlsymbol.h"
#include "sprite.h"
#include "studiomodel.h"

//=============================================================================
// DetailObjects:: class
//=============================================================================

class DetailObjects : public CMapPoint
{
// Comparators Functions for initialized member lists

	// Error checking.. make sure the model is valid + is a static prop
	struct StaticPropLookup_t
	{
		CUtlSymbol	m_ModelName;
		bool		m_IsValid;
	};

	// Comparator for static property sorting

	static bool StaticLess( StaticPropLookup_t const& src1, StaticPropLookup_t const& src2 )
	{
		return src1.m_ModelName < src2.m_ModelName;
	}

//-----------------------------------------------------------------------------
// Contructors / Destructors
//-----------------------------------------------------------------------------
public:
	DetailObjects() {}
	~DetailObjects();

//-----------------------------------------------------------------------------
// Internal Constants & Data Structures
//-----------------------------------------------------------------------------
protected:
	enum { DETAIL_NAME_LENGTH = 128 };

	enum DetailPropOrientation_t
	{
		DETAIL_PROP_ORIENT_NORMAL = 0,
		DETAIL_PROP_ORIENT_SCREEN_ALIGNED,
		DETAIL_PROP_ORIENT_SCREEN_ALIGNED_VERTICAL,
	};

	// NOTE: If DetailPropType_t enum changes, change CDetailModel::QuadsToDraw
	// in detailobjectsystem.cpp
	enum DetailPropType_t
	{
		DETAIL_PROP_TYPE_MODEL = 0,
		DETAIL_PROP_TYPE_SPRITE,
		DETAIL_PROP_TYPE_SHAPE_CROSS,
		DETAIL_PROP_TYPE_SHAPE_TRI,
	};

	// Information about particular detail object types
	enum
	{
		MODELFLAG_UPRIGHT = 0x1,
	};

	class DetailModel_t
	{
	public:
		DetailModel_t();
		CUtlSymbol	m_ModelName;
		float		m_Amount;
		float		m_MinCosAngle;
		float		m_MaxCosAngle;
		int			m_Flags;
		int			m_Orientation;
		int			m_Type;
		Vector2D	m_Pos[2];
		Vector2D	m_Tex[2];
		float		m_flRandomScaleStdDev;
		unsigned char m_ShapeSize;
		unsigned char m_ShapeAngle;
		unsigned char m_SwayAmount;
	};

	struct DetailObjectGroup_t
	{
		float	m_Alpha;
		CUtlVector< DetailModel_t >	m_Models;
	};

	struct DetailObject_t
	{
		CUtlSymbol m_Name;
		float	m_Density;
		CUtlVector< DetailObjectGroup_t >	m_Groups;

		bool operator==(const DetailObject_t& src ) const
		{
			return src.m_Name == m_Name;
		}
	};


//-----------------------------------------------------------------------------
// Publically callable interfaces
//-----------------------------------------------------------------------------
public:
	static void	LoadEmitDetailObjectDictionary( char const* pGameDir );
	static void	BuildAnyDetailObjects(CMapFace *);
	static void EnableBuildDetailObjects( bool bBuild );	// This is used to delay building detail objects until the
															// end of the map load. Prevents it from generating the
															// detail objects 3x more often than necessary.
	
	void Render3D( CRender3D* pRender );
	bool ShouldRenderLast(void);

//-----------------------------------------------------------------------------
// Internal Helper Functions
//-----------------------------------------------------------------------------
protected:
	static const char *FindDetailVBSPName( void );
	static void	ParseDetailObjectFile( KeyValues& keyValues );
	static void	ParseDetailGroup( int detailId, KeyValues* pGroupKeyValues );

	bool	LoadStudioModel( char const* pFileName, char const* pEntityType, CUtlBuffer& buf );
	float	ComputeDisplacementFaceArea( CMapFace *pMapFace );
	int		SelectGroup( const DetailObject_t& detail, float alpha );
	int		SelectDetail( DetailObjectGroup_t const& group );
	void	PlaceDetail( DetailModel_t const& model, const Vector& pt, const Vector& normal );
	void	EmitDetailObjectsOnFace( CMapFace *pMapFace, DetailObject_t& detail );
	void	EmitDetailObjectsOnDisplacementFace( CMapFace *pMapFace, DetailObject_t& detail );

	void	AddDetailSpriteToFace( const Vector &vecOrigin, const QAngle &vecAngles, DetailModel_t const& model, float flScale );
	void	AddDetailModelToFace( const char* pModelName, const Vector& pt, const QAngle& angles, int nOrientation );



//-----------------------------------------------------------------------------
// Protected Data Members
//-----------------------------------------------------------------------------

	static CUtlVector<DetailObject_t>			s_DetailObjectDict;		// static members?
	static bool s_bBuildDetailObjects;

	CUtlVector<CSpriteModel *>	m_DetailSprites;
	CUtlVector<StudioModel *>	m_DetailModels;
};

#endif // DETAILOBJECTS_H