OpenClonk
C4GameRes Class Reference

#include <C4GameParameters.h>

Public Member Functions

 C4GameRes ()
 
 C4GameRes (const C4GameRes &Res)
 
 ~C4GameRes ()
 
C4GameResoperator= (const C4GameRes &Res)
 
C4Network2ResType getType () const
 
const char * getFile () const
 
bool isPresent () const
 
const C4Network2ResCoregetResCore () const
 
C4Network2Res::Ref getNetRes () const
 
void SetFile (C4Network2ResType eType, const char *szFile)
 
void SetResCore (C4Network2ResCore *pResCore)
 
void SetNetRes (C4Network2Res::Ref pRes)
 
bool Publish (C4Network2ResList *pResList)
 
bool Load (C4Network2ResList *pResList)
 
bool InitNetwork (C4Network2ResList *pResList)
 
void CalcHash ()
 
void Clear ()
 
void CompileFunc (StdCompiler *pComp)
 

Friends

class C4GameResList
 

Detailed Description

Definition at line 26 of file C4GameParameters.h.

Constructor & Destructor Documentation

◆ C4GameRes() [1/2]

C4GameRes::C4GameRes ( )

Definition at line 28 of file C4GameParameters.cpp.

29  : pNetRes(nullptr)
30 {
31 
32 }

◆ C4GameRes() [2/2]

C4GameRes::C4GameRes ( const C4GameRes Res)

Definition at line 34 of file C4GameParameters.cpp.

35  : eType(Res.getType()), File(Res.getFile()), pResCore(Res.getResCore()), pNetRes(Res.getNetRes())
36 {
37  if (pResCore && !pNetRes)
38  pResCore = new C4Network2ResCore(*pResCore);
39 }
C4Network2Res::Ref getNetRes() const
C4Network2ResType getType() const
const char * getFile() const
const C4Network2ResCore * getResCore() const

◆ ~C4GameRes()

C4GameRes::~C4GameRes ( )

Definition at line 42 of file C4GameParameters.cpp.

43 {
44  Clear();
45 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ CalcHash()

void C4GameRes::CalcHash ( )

Definition at line 173 of file C4GameParameters.cpp.

174 {
175  if (!pNetRes) return;
176  pNetRes->CalculateSHA();
177 }

References C4Network2Res::CalculateSHA().

Referenced by C4GameParameters::EnforceLeagueRules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4GameRes::Clear ( )

Definition at line 59 of file C4GameParameters.cpp.

60 {
61  eType = NRT_Null;
62  File.Clear();
63  if (pResCore && !pNetRes)
64  delete pResCore;
65  pResCore = nullptr;
66  pNetRes = nullptr;
67 }
@ NRT_Null
Definition: C4Network2Res.h:42
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear(), and NRT_Null.

Referenced by C4GameParameters::Clear(), CompileFunc(), operator=(), SetNetRes(), and ~C4GameRes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4GameRes::CompileFunc ( StdCompiler pComp)

Definition at line 92 of file C4GameParameters.cpp.

93 {
94  bool deserializing = pComp->isDeserializer();
95  // Clear previous data for compiling
96  if (deserializing) Clear();
97  // Core is needed to decompile something meaningful
98  if (!deserializing) assert(pResCore);
99  // De-/Compile core
100  pComp->Value(mkPtrAdaptNoNull(const_cast<C4Network2ResCore * &>(pResCore)));
101  // Compile: Set type accordingly
102  if (deserializing)
103  eType = pResCore->getType();
104 }
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:638
C4Network2ResType getType() const
Definition: C4Network2Res.h:84
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

References Clear(), C4Network2ResCore::getType(), StdCompiler::isDeserializer(), mkPtrAdaptNoNull(), and StdCompiler::Value().

Here is the call graph for this function:

◆ getFile()

const char* C4GameRes::getFile ( ) const
inline

Definition at line 44 of file C4GameParameters.h.

44 { return File.getData(); }
const char * getData() const
Definition: StdBuf.h:442

References StdStrBuf::getData().

Referenced by C4Game::InitDefs(), C4Game::InitMaterialTexture(), InitNetwork(), operator=(), and C4Record::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNetRes()

C4Network2Res::Ref C4GameRes::getNetRes ( ) const
inline

Definition at line 47 of file C4GameParameters.h.

47 { return pNetRes; }

Referenced by InitNetwork(), and operator=().

Here is the caller graph for this function:

◆ getResCore()

const C4Network2ResCore* C4GameRes::getResCore ( ) const
inline

Definition at line 46 of file C4GameParameters.h.

46 { return pResCore; }

Referenced by operator=(), C4MessageInput::ProcessCommand(), C4GameResList::RetrieveFiles(), and C4Network2::RetrieveScenario().

Here is the caller graph for this function:

◆ getType()

C4Network2ResType C4GameRes::getType ( ) const
inline

Definition at line 43 of file C4GameParameters.h.

43 { return eType; }

Referenced by operator=().

Here is the caller graph for this function:

◆ InitNetwork()

bool C4GameRes::InitNetwork ( C4Network2ResList pResList)

Definition at line 135 of file C4GameParameters.cpp.

136 {
137  // Already initialized?
138  if (getNetRes())
139  return true;
140  // Present? [Host]
141  if (isPresent())
142  {
143  // Publish on network
144  if (!Publish(pNetResList))
145  {
146  LogFatal(FormatString(LoadResStr("IDS_NET_NOFILEPUBLISH"), getFile()).getData());
147  return false;
148  }
149  }
150  // Got a core? [Client]
151  else if (pResCore)
152  {
153  // Search/Load it
154  if (!Load(pNetResList))
155  {
156  // Give some hints to why this might happen.
157  const char *szFilename = pResCore->getFileName();
158  if (!pResCore->isLoadable())
159  if (pResCore->getType() == NRT_System)
160  LogFatal(FormatString(LoadResStr("IDS_NET_NOSAMESYSTEM"), szFilename).getData());
161  else
162  LogFatal(FormatString(LoadResStr("IDS_NET_NOSAMEANDTOOLARGE"), szFilename).getData());
163  // Should not happen
164  else
165  LogFatal(FormatString(LoadResStr("IDS_NET_NOVALIDCORE"), szFilename).getData());
166  return false;
167  }
168  }
169  // Okay
170  return true;
171 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:239
@ NRT_System
Definition: C4Network2Res.h:47
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
bool isPresent() const
bool Load(C4Network2ResList *pResList)
bool Publish(C4Network2ResList *pResList)
const char * getFileName() const
Definition: C4Network2Res.h:94
bool isLoadable() const
Definition: C4Network2Res.h:88

References FormatString(), getFile(), C4Network2ResCore::getFileName(), getNetRes(), C4Network2ResCore::getType(), C4Network2ResCore::isLoadable(), isPresent(), Load(), LoadResStr(), LogFatal(), NRT_System, and Publish().

Referenced by C4GameParameters::InitNetwork().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPresent()

bool C4GameRes::isPresent ( ) const
inline

Definition at line 45 of file C4GameParameters.h.

45 { return !! File; }

Referenced by InitNetwork(), and Publish().

Here is the caller graph for this function:

◆ Load()

bool C4GameRes::Load ( C4Network2ResList pResList)

Definition at line 122 of file C4GameParameters.cpp.

123 {
124  assert(pResCore);
125  // Already present?
126  if (pNetRes) return true;
127  // Add to network resource list
128  C4Network2Res::Ref pNetRes = pNetResList->AddByCore(*pResCore);
129  if (!pNetRes) return false;
130  // Set resource
131  SetNetRes(pNetRes);
132  return true;
133 }
void SetNetRes(C4Network2Res::Ref pRes)

References C4Network2ResList::AddByCore(), and SetNetRes().

Referenced by InitNetwork().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

C4GameRes & C4GameRes::operator= ( const C4GameRes Res)

Definition at line 47 of file C4GameParameters.cpp.

48 {
49  Clear();
50  eType = Res.getType();
51  File = Res.getFile();
52  pResCore = Res.getResCore();
53  pNetRes = Res.getNetRes();
54  if (pResCore && !pNetRes)
55  pResCore = new C4Network2ResCore(*pResCore);
56  return *this;
57 }

References Clear(), getFile(), getNetRes(), getResCore(), and getType().

Here is the call graph for this function:

◆ Publish()

bool C4GameRes::Publish ( C4Network2ResList pResList)

Definition at line 106 of file C4GameParameters.cpp.

107 {
108  assert(isPresent());
109  // Already present?
110  if (pNetRes) return true;
111  // determine whether it's loadable
112  bool fAllowUnloadable = false;
113  if (eType == NRT_Definitions) fAllowUnloadable = true;
114  // Add to network resource list
115  C4Network2Res::Ref pNetRes = pNetResList->AddByFile(File.getData(), false, eType, -1, nullptr, fAllowUnloadable);
116  if (!pNetRes) return false;
117  // Set resource
118  SetNetRes(pNetRes);
119  return true;
120 }
@ NRT_Definitions
Definition: C4Network2Res.h:46

References C4Network2ResList::AddByFile(), StdStrBuf::getData(), isPresent(), NRT_Definitions, and SetNetRes().

Referenced by InitNetwork().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFile()

void C4GameRes::SetFile ( C4Network2ResType  eType,
const char *  szFile 
)

Definition at line 69 of file C4GameParameters.cpp.

70 {
71  assert(!pNetRes && !pResCore);
72  eType = enType;
73  File = sznFile;
74 }

Referenced by C4GameResList::CreateByFile(), and C4GameParameters::Load().

Here is the caller graph for this function:

◆ SetNetRes()

void C4GameRes::SetNetRes ( C4Network2Res::Ref  pRes)

Definition at line 83 of file C4GameParameters.cpp.

84 {
85  Clear();
86  pNetRes = pnNetRes;
87  eType = pNetRes->getType();
88  File = pNetRes->getFile();
89  pResCore = &pNetRes->getCore();
90 }
const char * getFile() const
const C4Network2ResCore & getCore() const
C4Network2ResType getType() const

References Clear(), C4Network2Res::getCore(), C4Network2Res::getFile(), and C4Network2Res::getType().

Referenced by C4GameResList::CreateByNetRes(), Load(), and Publish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetResCore()

void C4GameRes::SetResCore ( C4Network2ResCore pResCore)

Definition at line 76 of file C4GameParameters.cpp.

77 {
78  assert(!pNetRes);
79  pResCore = pnResCore;
80  eType = pResCore->getType();
81 }

References C4Network2ResCore::getType().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ C4GameResList

friend class C4GameResList
friend

Definition at line 28 of file C4GameParameters.h.


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