summaryrefslogtreecommitdiff
path: root/hammer/updatehint.cpp
blob: 101735692005387518226f2e26846a7551cfe715 (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
165
166
167
168
169
170
171
172
173
174
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: An object that is used, when modifying the state of the document,
//			to collect information about what objects changed and how they changed.
//			This aggregate info is then passed to CMapDoc::UpdateObjects which performs
//			post processing and view updates.
//
// $NoKeywords: $
//=============================================================================//


//-----------------------------------------------------------------------------
// Purpose: Iterates the list of updated objects.
//-----------------------------------------------------------------------------
POSITION CUpdateHint::GetHeadPosition(int nIndex)
{
	return(m_NotifyList[nIndex].Objects.GetHeadPosition());
}


//-----------------------------------------------------------------------------
// Purpose: Iterates the list of updated objects.
//-----------------------------------------------------------------------------
CMapClass *CUpdateHint::GetNext(POSITION &pos)
{
	return(m_NotifyList[nIndex].Objects.GetNext(pos));
}


//-----------------------------------------------------------------------------
// Purpose: Returns the notification code for this update.
//-----------------------------------------------------------------------------
int CUpdateHint::GetNotifyCode(void)
{
	return(m_NotifyList[nIndex].nCode);
}


//-----------------------------------------------------------------------------
// Purpose: Returns the current update region.
//-----------------------------------------------------------------------------
BoundBox const &CUpdateHint::GetUpdateRegion(void)
{
	return(m_UpdateRegion);
}


//-----------------------------------------------------------------------------
// Purpose: Prepares to update an object.
// Input  : pObject - Object that will be updated.
//-----------------------------------------------------------------------------
void CUpdateHint::PreUpdateObject(CMapClass *pObject)
{
	if (pObject != NULL)
	{
		CMapObjectList TempList;
		TempList.AddTail(pObject);
		PreUpdateObjects(&TempList);
	}
	else
	{
		PreUpdateObjects(NULL);
	}
}


//-----------------------------------------------------------------------------
// Purpose: Prepares to update the list of objects.
// Input  : pObjects - List of objects, NULL if none.
//-----------------------------------------------------------------------------
void CUpdateHint::PreUpdateObjects(CMapObjectList *pObjects)
{
	if (pObjects != NULL)
	{
		POSITION pos = pObjects->GetHeadPosition();
		while (pos != NULL)
		{
			CMapClass *pObject = pObjects->GetNext(pos);
			if (pObject != NULL)
			{
				m_UpdateRegion.UpdateBounds(pObject);
			}
		}
	}
}


//-----------------------------------------------------------------------------
// Purpose: Prepares to update an object.
// Input  : pObject - Object that will be updated.
//-----------------------------------------------------------------------------
void CUpdateHint::PostUpdateObject(CMapClass *pObject, int nNotifyCode)
{
	if (pObject != NULL)
	{
		CMapObjectList TempList;
		TempList.AddTail(pObject);
		PostUpdateObjects(&TempList, nNotifyCode);
	}
	else
	{
		PostUpdateObjects(NULL, nNotifyCode);
	}
}


//-----------------------------------------------------------------------------
// Purpose: Prepares to update the list of objects.
// Input  : pObjects - List of objects, NULL if none.
//-----------------------------------------------------------------------------
void CUpdateHint::PostUpdateObjects(CMapObjectList *pObjects, int nNotifyCode)
{
	int nIndex = 0;
	bool bFound = false;
		
	while (!bFound && (nIndex < m_ListEntries))
	{
		if (m_NotifyList[nIndex].nCode == nNotifyCode)
		{
			bFound = true;
		}
		else
		{
			nIndex++;
		}
	}

	if ((!bFound && (nIndex < MAX_NOTIFY_CODES))
	{
		if (nIndex < MAX_NOTIFY_CODES)
		{
			m_ListEntries++;
		}
	}
	else
	{
		ASSERT(nIndex < MAX_NOTIFY_CODES);
		return;
	}

	m_NotifyList[nIndex].Objects.AddTail(pObjects);

	if (pObjects != NULL)
	{
		POSITION pos = pObjects->GetHeadPosition();
		while (pos != NULL)
		{
			CMapClass *pObject = pObjects->GetNext(pos);
			if (pObject != NULL)
			{
				m_UpdateRegion.UpdateBounds(pObject);
			}
		}
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CUpdateHint::Reset(void)
{
	m_Objects.RemoveAll();
	m_UpdateRegion.ResetBounds();
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CUpdateHint::UpdateBounds(BoundBox &bbox)
{
	m_UpdateRegion.UpdateBounds(&bbox);
}