OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameResList Class Reference

#include <C4GameParameters.h>

Public Member Functions

 C4GameResList ()
 
 ~C4GameResList ()
 
C4GameResListoperator= (const C4GameResList &List)
 
int32_t getResCount () const
 
C4GameResiterRes (C4GameRes *pLast, C4Network2ResType eType=NRT_Null)
 
void Clear ()
 
bool Load (C4Group &hGroup, C4Scenario *pScenario, const char *szDefinitionFilenames)
 
C4GameResCreateByFile (C4Network2ResType eType, const char *szFile)
 
C4GameResCreateByNetRes (C4Network2Res::Ref pNetRes)
 
bool InitNetwork (C4Network2ResList *pNetResList)
 
void CalcHashes ()
 
bool RetrieveFiles ()
 
void CompileFunc (StdCompiler *pComp)
 

Protected Member Functions

void Add (C4GameRes *pRes)
 
void LoadFoldersWithLocalDefs (const char *szPath)
 

Detailed Description

Definition at line 64 of file C4GameParameters.h.

Constructor & Destructor Documentation

C4GameResList::C4GameResList ( )
inline

Definition at line 71 of file C4GameParameters.h.

71 : pResList(nullptr), iResCount(0), iResCapacity(0) {}
C4GameResList::~C4GameResList ( )
inline

Definition at line 72 of file C4GameParameters.h.

References Clear().

72 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4GameResList::Add ( C4GameRes pRes)
protected

Definition at line 337 of file C4GameParameters.cpp.

Referenced by CreateByFile(), and CreateByNetRes().

338 {
339  // Enlarge
340  if (iResCount >= iResCapacity)
341  {
342  iResCapacity += 10;
343  C4GameRes **pnResList = new C4GameRes *[iResCapacity];
344  for (int i = 0; i < iResCount; i++)
345  pnResList[i] = pResList[i];
346  pResList = pnResList;
347  }
348  // Add
349  pResList[iResCount++] = pRes;
350 }

Here is the caller graph for this function:

void C4GameResList::CalcHashes ( )

Definition at line 318 of file C4GameParameters.cpp.

Referenced by C4GameParameters::EnforceLeagueRules().

319 {
320  for (int32_t i = 0; i < iResCount; i++)
321  pResList[i]->CalcHash();
322 }

Here is the caller graph for this function:

void C4GameResList::Clear ( )

Definition at line 207 of file C4GameParameters.cpp.

Referenced by C4GameParameters::Clear(), CompileFunc(), Load(), operator=(), and ~C4GameResList().

208 {
209  // clear them
210  for (int32_t i = 0; i < iResCount; i++)
211  delete pResList[i];
212  delete [] pResList;
213  pResList = nullptr;
214  iResCount = iResCapacity = 0;
215 }

Here is the caller graph for this function:

void C4GameResList::CompileFunc ( StdCompiler pComp)

Definition at line 352 of file C4GameParameters.cpp.

References Clear(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkNamingAdapt(), mkNamingCountAdapt(), StdCompiler::Value(), and ZeroMem().

353 {
354  bool deserializing = pComp->isDeserializer();
355  // Clear previous data
356  if (deserializing) Clear();
357  // Compile resource count
358  pComp->Value(mkNamingCountAdapt(iResCount, "Resource"));
359  // Create list
360  if (deserializing)
361  {
362  pResList = new C4GameRes *[iResCapacity = iResCount];
363  ZeroMem(pResList, sizeof(*pResList) * iResCount);
364  }
365  // Compile list
366  pComp->Value(
368  mkArrayAdaptMap(pResList, iResCount, mkPtrAdaptNoNull<C4GameRes>),
369  "Resource"));
370  mkPtrAdaptNoNull<C4GameRes>(*pResList);
371 }
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:974
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:170
virtual bool isDeserializer()
Definition: StdCompiler.h:63
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:63
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:311

Here is the call graph for this function:

C4GameRes * C4GameResList::CreateByFile ( C4Network2ResType  eType,
const char *  szFile 
)

Definition at line 288 of file C4GameParameters.cpp.

References Add(), and C4GameRes::SetFile().

Referenced by Load(), and LoadFoldersWithLocalDefs().

289 {
290  // Create & set
291  C4GameRes *pRes = new C4GameRes();
292  pRes->SetFile(eType, szFile);
293  // Add to list
294  Add(pRes);
295  return pRes;
296 }
void Add(C4GameRes *pRes)
void SetFile(C4Network2ResType eType, const char *szFile)

Here is the call graph for this function:

Here is the caller graph for this function:

C4GameRes * C4GameResList::CreateByNetRes ( C4Network2Res::Ref  pNetRes)

Definition at line 298 of file C4GameParameters.cpp.

References Add(), and C4GameRes::SetNetRes().

299 {
300  // Create & set
301  C4GameRes *pRes = new C4GameRes();
302  pRes->SetNetRes(pNetRes);
303  // Add to list
304  Add(pRes);
305  return pRes;
306 }
void SetNetRes(C4Network2Res::Ref pRes)
void Add(C4GameRes *pRes)

Here is the call graph for this function:

int32_t C4GameResList::getResCount ( ) const
inline

Definition at line 76 of file C4GameParameters.h.

76 { return iResCount; }
bool C4GameResList::InitNetwork ( C4Network2ResList pNetResList)

Definition at line 308 of file C4GameParameters.cpp.

Referenced by C4Network2::HandleJoinData(), and C4GameParameters::InitNetwork().

309 {
310  // Check all resources without attached network resource object
311  for (int i = 0; i < iResCount; i++)
312  if (!pResList[i]->InitNetwork(pNetResList))
313  return false;
314  // Success
315  return true;
316 }
bool InitNetwork(C4Network2ResList *pNetResList)

Here is the caller graph for this function:

C4GameRes * C4GameResList::iterRes ( C4GameRes pLast,
C4Network2ResType  eType = NRT_Null 
)

Definition at line 194 of file C4GameParameters.cpp.

References NRT_Null.

Referenced by C4Game::InitDefs(), and C4Game::InitMaterialTexture().

195 {
196  for (int i = 0; i < iResCount; i++)
197  if (!pLast)
198  {
199  if (eType == NRT_Null || pResList[i]->getType() == eType)
200  return pResList[i];
201  }
202  else if (pLast == pResList[i])
203  pLast = nullptr;
204  return nullptr;
205 }

Here is the caller graph for this function:

bool C4GameResList::Load ( C4Group hGroup,
C4Scenario pScenario,
const char *  szDefinitionFilenames 
)

Definition at line 256 of file C4GameParameters.cpp.

References _MAX_PATH, C4CFN_Material, C4CFN_System, C4GSCnt_Material, Clear(), CreateByFile(), DirSep, C4GroupSet::FindGroup(), Game, StdStrBuf::getData(), C4Group::GetFullName(), C4Game::GroupSet, C4Scenario::Head, LoadFoldersWithLocalDefs(), NRT_Definitions, NRT_Material, NRT_System, C4SHead::Origin, C4Game::ScenarioFile, and SCopySegment().

Referenced by C4GameParameters::Load().

257 {
258  // clear any prev
259  Clear();
260  // no defs to be added? that's OK (LocalOnly)
261  if (szDefinitionFilenames && *szDefinitionFilenames)
262  {
263  // add them
264  char szSegment[_MAX_PATH+1];
265  for (int32_t cseg=0; SCopySegment(szDefinitionFilenames,cseg,szSegment,';',_MAX_PATH); ++cseg)
266  if (*szSegment)
267  CreateByFile(NRT_Definitions, szSegment);
268  }
269 
270  LoadFoldersWithLocalDefs(pScenario->Head.Origin ? pScenario->Head.Origin.getData() : hGroup.GetFullName().getData());
271 
272  // add System.ocg
274  // add all instances of Material.ocg, except those inside the scenario file
275  C4Group *pMatParentGrp = nullptr;
276  while ((pMatParentGrp = Game.GroupSet.FindGroup(C4GSCnt_Material, pMatParentGrp)))
277  if (pMatParentGrp != &Game.ScenarioFile)
278  {
279  StdStrBuf MaterialPath = pMatParentGrp->GetFullName() + DirSep C4CFN_Material;
280  CreateByFile(NRT_Material, (pMatParentGrp->GetFullName() + DirSep C4CFN_Material).getData());
281  }
282  // add global Material.ocg
283  CreateByFile(NRT_Material, C4CFN_Material);
284  // done; success
285  return true;
286 }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf Origin
Definition: C4Scenario.h:80
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:89
#define C4CFN_Material
Definition: C4Components.h:25
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
#define C4GSCnt_Material
Definition: C4GroupSet.h:36
#define _MAX_PATH
C4GameRes * CreateByFile(C4Network2ResType eType, const char *szFile)
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
C4Group ScenarioFile
Definition: C4Game.h:88
C4Group * FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false)
Definition: C4GroupSet.cpp:157
C4SHead Head
Definition: C4Scenario.h:230
void LoadFoldersWithLocalDefs(const char *szPath)
#define C4CFN_System
Definition: C4Components.h:29
#define DirSep

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameResList::LoadFoldersWithLocalDefs ( const char *  szPath)
protected

Definition at line 217 of file C4GameParameters.cpp.

References _MAX_PATH, AltDirectorySeparator, C4GSCnt_Definitions, C4GroupSet::CheckGroupContents(), C4Group::Close(), CreateByFile(), DirectorySeparator, Game, GetExtension(), C4Game::GroupSet, NRT_Definitions, C4Group::Open(), SCharPos(), SCopy(), and SEqualNoCase().

Referenced by Load().

218 {
219  // Scan path for folder names
220  int32_t iBackslash;
221  char szFoldername[_MAX_PATH+1];
222  C4Group hGroup;
223 #ifdef _WIN32
224  // Allow both backward and forward slashes when searching because the path
225  // may be given with forward slashes. We would skip loading some definitions
226  // if we didn't handle this properly and the user would have no clue what was
227  // going on. See also http://forum.openclonk.org/topic_show.pl?tid=905.
228  char control[3] = { DirectorySeparator, AltDirectorySeparator, '\0' };
229  const int32_t len = (int32_t)strlen(szPath);
230  for (int32_t iPrev=0; (iBackslash = strcspn(szPath+iPrev, control) + iPrev) < len; iPrev = iBackslash + 1)
231 #else
232  for (int32_t cnt=0; (iBackslash=SCharPos(DirectorySeparator,szPath,cnt)) > -1; cnt++)
233 #endif
234  {
235  // Get folder name
236  SCopy(szPath,szFoldername,iBackslash);
237  // Open folder
238  if (SEqualNoCase(GetExtension(szFoldername),"ocf"))
239  if (hGroup.Open(szFoldername))
240  {
241  // Check for contained defs
242  // do not, however, add them to the group set:
243  // parent folders are added by OpenScenario already!
244  int32_t iContents;
245  if ((iContents = Game.GroupSet.CheckGroupContents(hGroup, C4GSCnt_Definitions)))
246  {
247  // Add folder to list
248  CreateByFile(NRT_Definitions, szFoldername);
249  }
250  // Close folder
251  hGroup.Close();
252  }
253  }
254 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:89
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
#define C4GSCnt_Definitions
Definition: C4GroupSet.h:38
#define _MAX_PATH
#define AltDirectorySeparator
C4GameRes * CreateByFile(C4Network2ResType eType, const char *szFile)
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool Close()
Definition: C4Group.cpp:755
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
static int32_t CheckGroupContents(C4Group &rGroup, int32_t Contents)
Definition: C4GroupSet.cpp:108
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:203
#define DirectorySeparator

Here is the call graph for this function:

Here is the caller graph for this function:

C4GameResList & C4GameResList::operator= ( const C4GameResList List)

Definition at line 183 of file C4GameParameters.cpp.

References Clear().

184 {
185  Clear();
186  // Copy the list
187  iResCount = iResCapacity = List.iResCount;
188  pResList = new C4GameRes *[iResCapacity];
189  for (int i = 0; i < iResCount; i++)
190  pResList[i] = new C4GameRes(*List.pResList[i]);
191  return *this;
192 }

Here is the call graph for this function:

bool C4GameResList::RetrieveFiles ( )

Definition at line 324 of file C4GameParameters.cpp.

References C4NetResRetrieveTimeout, FormatString(), StdStrBuf::getData(), GetFilename(), C4Network2ResCore::getFileName(), C4GameRes::getResCore(), LoadResStr(), Network, and C4Network2::RetrieveRes().

Referenced by C4Game::Init().

325 {
326  // wait for all resources
327  for (int32_t i = 0; i < iResCount; i++)
328  {
329  const C4Network2ResCore &Core = *pResList[i]->getResCore();
330  StdStrBuf ResNameBuf = FormatString("%s: %s", LoadResStr("IDS_DLG_DEFINITION"), GetFilename(Core.getFileName()));
331  if (!::Network.RetrieveRes(Core, C4NetResRetrieveTimeout, ResNameBuf.getData()))
332  return false;
333  }
334  return true;
335 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
const char * getFileName() const
Definition: C4Network2Res.h:92
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const C4Network2ResCore * getResCore() const
C4Network2 Network
Definition: C4Globals.cpp:53
C4Network2Res::Ref RetrieveRes(const C4Network2ResCore &Core, int32_t iTimeout, const char *szResName, bool fWaitForCore=false)
const int C4NetResRetrieveTimeout
Definition: C4Network2.h:37
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: