OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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::C4GameRes ( )

Definition at line 30 of file C4GameParameters.cpp.

31  : eType(NRT_Null), pResCore(nullptr), pNetRes(nullptr)
32 {
33 
34 }
C4GameRes::C4GameRes ( const C4GameRes Res)

Definition at line 36 of file C4GameParameters.cpp.

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

Definition at line 44 of file C4GameParameters.cpp.

References Clear().

45 {
46  Clear();
47 }

Here is the call graph for this function:

Member Function Documentation

void C4GameRes::CalcHash ( )

Definition at line 175 of file C4GameParameters.cpp.

References C4Network2Res::CalculateSHA().

Referenced by C4GameParameters::EnforceLeagueRules().

176 {
177  if (!pNetRes) return;
178  pNetRes->CalculateSHA();
179 }

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameRes::Clear ( )

Definition at line 61 of file C4GameParameters.cpp.

References StdStrBuf::Clear(), and NRT_Null.

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

62 {
63  eType = NRT_Null;
64  File.Clear();
65  if (pResCore && !pNetRes)
66  delete pResCore;
67  pResCore = nullptr;
68  pNetRes = nullptr;
69 }
void Clear()
Definition: StdBuf.h:474

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameRes::CompileFunc ( StdCompiler pComp)

Definition at line 94 of file C4GameParameters.cpp.

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

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

Here is the call graph for this function:

const char* C4GameRes::getFile ( ) const
inline

Definition at line 44 of file C4GameParameters.h.

References StdStrBuf::getData().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 47 of file C4GameParameters.h.

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

47 { return pNetRes; }

Here is the caller graph for this function:

const C4Network2ResCore* C4GameRes::getResCore ( ) const
inline

Definition at line 46 of file C4GameParameters.h.

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

46 { return pResCore; }

Here is the caller graph for this function:

C4Network2ResType C4GameRes::getType ( ) const
inline

Definition at line 43 of file C4GameParameters.h.

Referenced by operator=().

43 { return eType; }

Here is the caller graph for this function:

bool C4GameRes::InitNetwork ( C4Network2ResList pResList)

Definition at line 137 of file C4GameParameters.cpp.

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

Referenced by C4GameParameters::InitNetwork().

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

bool C4GameRes::isPresent ( ) const
inline

Definition at line 45 of file C4GameParameters.h.

Referenced by InitNetwork(), and Publish().

45 { return !! File; }

Here is the caller graph for this function:

bool C4GameRes::Load ( C4Network2ResList pResList)

Definition at line 124 of file C4GameParameters.cpp.

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

Referenced by InitNetwork().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 49 of file C4GameParameters.cpp.

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

50 {
51  Clear();
52  eType = Res.getType();
53  File = Res.getFile();
54  pResCore = Res.getResCore();
55  pNetRes = Res.getNetRes();
56  if (pResCore && !pNetRes)
57  pResCore = new C4Network2ResCore(*pResCore);
58  return *this;
59 }
const C4Network2ResCore * getResCore() const
const char * getFile() const
C4Network2Res::Ref getNetRes() const
C4Network2ResType getType() const

Here is the call graph for this function:

bool C4GameRes::Publish ( C4Network2ResList pResList)

Definition at line 108 of file C4GameParameters.cpp.

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

Referenced by InitNetwork().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 71 of file C4GameParameters.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 85 of file C4GameParameters.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameRes::SetResCore ( C4Network2ResCore pResCore)

Definition at line 78 of file C4GameParameters.cpp.

References C4Network2ResCore::getType().

79 {
80  assert(!pNetRes);
81  pResCore = pnResCore;
82  eType = pResCore->getType();
83 }
C4Network2ResType getType() const
Definition: C4Network2Res.h:84

Here is the call graph for this function:

Friends And Related Function Documentation

friend class C4GameResList
friend

Definition at line 28 of file C4GameParameters.h.


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