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 28 of file C4GameParameters.cpp.

29  : pNetRes(nullptr)
30 {
31 
32 }
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 }
const C4Network2ResCore * getResCore() const
const char * getFile() const
C4Network2Res::Ref getNetRes() const
C4Network2ResType getType() const
C4GameRes::~C4GameRes ( )

Definition at line 42 of file C4GameParameters.cpp.

References Clear().

43 {
44  Clear();
45 }

Here is the call graph for this function:

Member Function Documentation

void C4GameRes::CalcHash ( )

Definition at line 173 of file C4GameParameters.cpp.

References C4Network2Res::CalculateSHA().

Referenced by C4GameParameters::EnforceLeagueRules().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameRes::Clear ( )

Definition at line 59 of file C4GameParameters.cpp.

References StdStrBuf::Clear(), and NRT_Null.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameRes::CompileFunc ( StdCompiler pComp)

Definition at line 92 of file C4GameParameters.cpp.

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

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:606
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
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:442

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 135 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().

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 * getData() const
Definition: StdBuf.h:442
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:227
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:270

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 122 of file C4GameParameters.cpp.

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

Referenced by InitNetwork().

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)

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 47 of file C4GameParameters.cpp.

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

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 }
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 106 of file C4GameParameters.cpp.

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

Referenced by InitNetwork().

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 }
const char * getData() const
Definition: StdBuf.h:442
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 69 of file C4GameParameters.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 83 of file C4GameParameters.cpp.

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

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

84 {
85  Clear();
86  pNetRes = pnNetRes;
87  eType = pNetRes->getType();
88  File = pNetRes->getFile();
89  pResCore = &pNetRes->getCore();
90 }
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 76 of file C4GameParameters.cpp.

References C4Network2ResCore::getType().

77 {
78  assert(!pNetRes);
79  pResCore = pnResCore;
80  eType = pResCore->getType();
81 }
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: