-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCvDllPathFinderUpdate.cpp
190 lines (182 loc) · 5.59 KB
/
CvDllPathFinderUpdate.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* -------------------------------------------------------------------------------------------------------
© 1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
Sid Meier's Civilization V, Civ, Civilization, 2K Games, Firaxis Games, Take-Two Interactive Software
and their respective logos are all trademarks of Take-Two interactive Software, Inc.
All other marks and trademarks are the property of their respective owners.
All rights reserved.
------------------------------------------------------------------------------------------------------- */
#include "CvGameCoreDLLPCH.h"
#include "CvDllPathFinderUpdate.h"
#include "CvDllContext.h"
CvDllPathFinderUpdate::CvDllPathFinderUpdate(int iX, int iY, int iTurnNumber)
: m_iX(iX)
, m_iY(iY)
, m_iTurnNumber(iTurnNumber)
, m_uiRefCount(1)
{
}
//------------------------------------------------------------------------------
CvDllPathFinderUpdate::~CvDllPathFinderUpdate()
{
}
//------------------------------------------------------------------------------
void* CvDllPathFinderUpdate::QueryInterface(GUID guidInterface)
{
if( guidInterface == ICvUnknown::GetInterfaceId() ||
guidInterface == ICvPathFinderUpdate1::GetInterfaceId())
{
IncrementReference();
return this;
}
return NULL;
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdate::IncrementReference()
{
++m_uiRefCount;
return m_uiRefCount;
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdate::DecrementReference()
{
if(m_uiRefCount == 1)
{
delete this;
return 0;
}
else
{
--m_uiRefCount;
return m_uiRefCount;
}
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdate::GetReferenceCount()
{
return m_uiRefCount;
}
//------------------------------------------------------------------------------
void CvDllPathFinderUpdate::Destroy()
{
DecrementReference();
}
//------------------------------------------------------------------------------
void CvDllPathFinderUpdate::operator delete(void* p)
{
CvDllGameContext::Free(p);
}
//------------------------------------------------------------------------------
void* CvDllPathFinderUpdate::operator new(size_t bytes)
{
return CvDllGameContext::Allocate(bytes);
}
//------------------------------------------------------------------------------
int CvDllPathFinderUpdate::GetX() const
{
return m_iX;
}
//------------------------------------------------------------------------------
int CvDllPathFinderUpdate::GetY() const
{
return m_iY;
}
//------------------------------------------------------------------------------
int CvDllPathFinderUpdate::GetTurnNumber() const
{
return m_iTurnNumber;
}
//------------------------------------------------------------------------------
CvDllPathFinderUpdateList::CvDllPathFinderUpdateList(const std::vector<CvDllPathFinderUpdateListData>& updates)
: m_uiRefCount(1)
, m_updates(updates.begin(), updates.end())
, m_iIndex(-1)
{
}
//------------------------------------------------------------------------------
CvDllPathFinderUpdateList::~CvDllPathFinderUpdateList()
{
}
//------------------------------------------------------------------------------
void* CvDllPathFinderUpdateList::QueryInterface(GUID guidInterface)
{
if( guidInterface == ICvUnknown::GetInterfaceId() ||
guidInterface == ICvEnumerator::GetInterfaceId())
{
IncrementReference();
return this;
}
return NULL;
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdateList::IncrementReference()
{
++m_uiRefCount;
return m_uiRefCount;
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdateList::DecrementReference()
{
if(m_uiRefCount == 1)
{
delete this;
return 0;
}
else
{
--m_uiRefCount;
return m_uiRefCount;
}
}
//------------------------------------------------------------------------------
unsigned int CvDllPathFinderUpdateList::GetReferenceCount()
{
return m_uiRefCount;
}
//------------------------------------------------------------------------------
void CvDllPathFinderUpdateList::Destroy()
{
DecrementReference();
}
//------------------------------------------------------------------------------
void CvDllPathFinderUpdateList::operator delete(void* p)
{
CvDllGameContext::Free(p);
}
//------------------------------------------------------------------------------
void* CvDllPathFinderUpdateList::operator new(size_t bytes)
{
return CvDllGameContext::Allocate(bytes);
}
//------------------------------------------------------------------------------
bool CvDllPathFinderUpdateList::MoveNext()
{
if (m_iIndex == -1) // In the uninitialized state?
{
if (!m_updates.empty()) // Any in the list?
{
m_iIndex = 0; // then we can start
return true;
}
else
return false; // Nope, just leave as -1 and return false
}
if((size_t)m_iIndex < m_updates.size())
m_iIndex++;
return (size_t)m_iIndex < m_updates.size();
}
//------------------------------------------------------------------------------
void CvDllPathFinderUpdateList::Reset()
{
m_iIndex = -1;
}
//------------------------------------------------------------------------------
ICvUnknown* CvDllPathFinderUpdateList::GetCurrent()
{
if(m_iIndex > -1 && (size_t)m_iIndex < m_updates.size())
{
const CvDllPathFinderUpdateListData& data = m_updates[m_iIndex];
return new CvDllPathFinderUpdate(data.iX, data.iY, data.iTurnNumber);
}
return NULL;
}
//------------------------------------------------------------------------------