forked from perilouswithadollarsign/cstrike15_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapgroup.cpp
177 lines (144 loc) · 4.63 KB
/
mapgroup.cpp
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
165
166
167
168
169
170
171
172
173
174
175
176
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include "MapDefs.h"
#include "MapGroup.h"
#include "SaveInfo.h"
#include "hammer.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
IMPLEMENT_MAPCLASS(CMapGroup)
//-----------------------------------------------------------------------------
// Purpose: Sets the new child's color to our own.
// Input : pChild - Object being added to this group.
//-----------------------------------------------------------------------------
void CMapGroup::AddChild(CMapClass *pChild)
{
pChild->SetRenderColor(r,g,b);
CMapClass::AddChild(pChild);
Vector2D mins, maxs;
GetRenderLogicalBox(mins, maxs);
m_vecLogicalPosition = ( mins + maxs ) / 2;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pobj -
// Output : CMapClass *
//-----------------------------------------------------------------------------
CMapClass *CMapGroup::CopyFrom(CMapClass *pobj, bool bUpdateDependencies)
{
return(CMapClass::CopyFrom(pobj, bUpdateDependencies));
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : CMapClass *
//-----------------------------------------------------------------------------
CMapClass *CMapGroup::Copy(bool bUpdateDependencies)
{
CMapGroup *pNew = new CMapGroup;
return(pNew->CopyFrom(this, bUpdateDependencies));
}
//-----------------------------------------------------------------------------
// Purpose: Returns a string describing this group.
//-----------------------------------------------------------------------------
const char* CMapGroup::GetDescription(void)
{
static char szBuf[128];
sprintf(szBuf, "group of %d objects", m_Children.Count());
return(szBuf);
}
void CMapGroup::SetLogicalPosition( const Vector2D &vecPosition )
{
if ( ( m_vecLogicalPosition.x != COORD_NOTINIT )
&& ( m_vecLogicalPosition.y != COORD_NOTINIT )
&& ( vecPosition != m_vecLogicalPosition ) )
{
Vector2D vecDelta = vecPosition - m_vecLogicalPosition;
FOR_EACH_OBJ( m_Children, pos )
{
CMapClass *pobj = m_Children[pos];
// update logical bounds
pobj->SetLogicalPosition( pobj->GetLogicalPosition() + vecDelta );
}
}
m_vecLogicalPosition = vecPosition;
}
const Vector2D& CMapGroup::GetLogicalPosition()
{
return m_vecLogicalPosition;
}
void CMapGroup::GetRenderLogicalBox( Vector2D &mins, Vector2D &maxs )
{
mins.Init( COORD_NOTINIT, COORD_NOTINIT );
maxs.Init( -COORD_NOTINIT, -COORD_NOTINIT );
FOR_EACH_OBJ( m_Children, pos )
{
CMapClass *pobj = m_Children[pos];
// update logical bounds
Vector2D logicalMins,logicalMaxs;
pobj->GetRenderLogicalBox( logicalMins, logicalMaxs );
mins = mins.Min(logicalMins);
maxs = maxs.Max(logicalMaxs);
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pFile -
// Output : ChunkFileResult_t
//-----------------------------------------------------------------------------
ChunkFileResult_t CMapGroup::LoadVMF(CChunkFile *pFile)
{
CChunkHandlerMap Handlers;
Handlers.AddHandler("editor", (ChunkHandler_t)CMapClass::LoadEditorCallback, this);
pFile->PushHandlers(&Handlers);
ChunkFileResult_t eResult = pFile->ReadChunk((KeyHandler_t)CMapClass::LoadEditorKeyCallback, this);
pFile->PopHandlers();
return(eResult);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pFile -
// Output : ChunkFileResult_t
//-----------------------------------------------------------------------------
ChunkFileResult_t CMapGroup::SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo)
{
//
// Check rules before saving this object.
//
if (!pSaveInfo->ShouldSaveObject(this))
{
return(ChunkFile_Ok);
}
ChunkFileResult_t eResult = pFile->BeginChunk("group");
//
// Save the group's ID.
//
if (eResult == ChunkFile_Ok)
{
eResult = pFile->WriteKeyValueInt("id", GetID());
}
if (eResult == ChunkFile_Ok)
{
eResult = CMapClass::SaveVMF(pFile, pSaveInfo);
}
if (eResult == ChunkFile_Ok)
{
eResult = pFile->EndChunk();
}
return(eResult);
}
//-----------------------------------------------------------------------------
// Purpose: Groups don't accept visgroups themselves, they
// Input : *pVisGroup -
//-----------------------------------------------------------------------------
void CMapGroup::AddVisGroup(CVisGroup *pVisGroup)
{
FOR_EACH_OBJ( m_Children, pos )
{
m_Children[pos]->AddVisGroup( pVisGroup );
}
}