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

#include <C4GameParameters.h>

Public Member Functions

 C4GameResList ()=default
 
 ~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 ( )
default
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 335 of file C4GameParameters.cpp.

Referenced by CreateByFile(), and CreateByNetRes().

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

Here is the caller graph for this function:

void C4GameResList::CalcHashes ( )

Definition at line 316 of file C4GameParameters.cpp.

Referenced by C4GameParameters::EnforceLeagueRules().

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

Here is the caller graph for this function:

void C4GameResList::Clear ( )

Definition at line 205 of file C4GameParameters.cpp.

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

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

Here is the caller graph for this function:

void C4GameResList::CompileFunc ( StdCompiler pComp)

Definition at line 350 of file C4GameParameters.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 286 of file C4GameParameters.cpp.

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

Referenced by Load(), and LoadFoldersWithLocalDefs().

287 {
288  // Create & set
289  C4GameRes *pRes = new C4GameRes();
290  pRes->SetFile(eType, szFile);
291  // Add to list
292  Add(pRes);
293  return pRes;
294 }
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 296 of file C4GameParameters.cpp.

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

297 {
298  // Create & set
299  C4GameRes *pRes = new C4GameRes();
300  pRes->SetNetRes(pNetRes);
301  // Add to list
302  Add(pRes);
303  return pRes;
304 }
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 306 of file C4GameParameters.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 192 of file C4GameParameters.cpp.

References NRT_Null.

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

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

Here is the caller graph for this function:

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

Definition at line 254 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().

255 {
256  // clear any prev
257  Clear();
258  // no defs to be added? that's OK (LocalOnly)
259  if (szDefinitionFilenames && *szDefinitionFilenames)
260  {
261  // add them
262  char szSegment[_MAX_PATH+1];
263  for (int32_t cseg=0; SCopySegment(szDefinitionFilenames,cseg,szSegment,';',_MAX_PATH); ++cseg)
264  if (*szSegment)
265  CreateByFile(NRT_Definitions, szSegment);
266  }
267 
268  LoadFoldersWithLocalDefs(pScenario->Head.Origin ? pScenario->Head.Origin.getData() : hGroup.GetFullName().getData());
269 
270  // add System.ocg
272  // add all instances of Material.ocg, except those inside the scenario file
273  C4Group *pMatParentGrp = nullptr;
274  while ((pMatParentGrp = Game.GroupSet.FindGroup(C4GSCnt_Material, pMatParentGrp)))
275  if (pMatParentGrp != &Game.ScenarioFile)
276  {
277  StdStrBuf MaterialPath = pMatParentGrp->GetFullName() + DirSep C4CFN_Material;
278  CreateByFile(NRT_Material, (pMatParentGrp->GetFullName() + DirSep C4CFN_Material).getData());
279  }
280  // add global Material.ocg
281  CreateByFile(NRT_Material, C4CFN_Material);
282  // done; success
283  return true;
284 }
const char * getData() const
Definition: StdBuf.h:442
StdCopyStrBuf Origin
Definition: C4Scenario.h:80
C4Game Game
Definition: C4Globals.cpp:52
C4GroupSet GroupSet
Definition: C4Game.h:87
#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:251
#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:86
C4Group * FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false)
Definition: C4GroupSet.cpp:155
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 215 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().

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

References Clear().

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

Here is the call graph for this function:

bool C4GameResList::RetrieveFiles ( )

Definition at line 322 of file C4GameParameters.cpp.

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

Referenced by C4Game::Init().

323 {
324  // wait for all resources
325  for (int32_t i = 0; i < iResCount; i++)
326  {
327  const C4Network2ResCore &Core = *pResList[i]->getResCore();
328  StdStrBuf ResNameBuf = FormatString("%s: %s", LoadResStr("IDS_DLG_DEFINITION"), GetFilename(Core.getFileName()));
329  if (!::Network.RetrieveRes(Core, C4NetResRetrieveTimeout, ResNameBuf.getData()))
330  return false;
331  }
332  return true;
333 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:45
const char * getData() const
Definition: StdBuf.h:442
const char * getFileName() const
Definition: C4Network2Res.h:94
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:270

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: