OpenClonk
C4MassMoverSet Class Reference

#include <C4MassMover.h>

Collaboration diagram for C4MassMoverSet:
[legend]

Public Member Functions

 C4MassMoverSet ()
 
 ~C4MassMoverSet ()
 
void Copy (C4MassMoverSet &rSet)
 
void Synchronize ()
 
void Default ()
 
void Clear ()
 
void Draw ()
 
void Execute ()
 
bool Create (int32_t x, int32_t y, bool fExecute=false)
 
bool Load (C4Group &hGroup)
 
bool Save (C4Group &hGroup)
 

Public Attributes

int32_t Count
 
int32_t CreatePtr
 

Protected Member Functions

void Consolidate ()
 

Protected Attributes

C4MassMover Set [C4MassMoverChunk]
 

Detailed Description

Definition at line 37 of file C4MassMover.h.

Constructor & Destructor Documentation

◆ C4MassMoverSet()

C4MassMoverSet::C4MassMoverSet ( )

Definition at line 40 of file C4MassMover.cpp.

41 {
42  Default();
43 }

References Default().

Here is the call graph for this function:

◆ ~C4MassMoverSet()

C4MassMoverSet::~C4MassMoverSet ( )

Definition at line 45 of file C4MassMover.cpp.

46 {
47  Clear();
48 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void C4MassMoverSet::Clear ( )

Definition at line 50 of file C4MassMover.cpp.

51 {
52 
53 }

Referenced by Copy(), Load(), and ~C4MassMoverSet().

Here is the caller graph for this function:

◆ Consolidate()

void C4MassMoverSet::Consolidate ( )
protected

Definition at line 227 of file C4MassMover.cpp.

228 {
229  // Consolidate set
230  int32_t iSpot,iPtr,iConsolidated;
231  for (iSpot=-1,iPtr=0,iConsolidated=0; iPtr<C4MassMoverChunk; iPtr++)
232  {
233  // Empty: set new spot if needed
234  if (Set[iPtr].Mat==MNone)
235  {
236  if (iSpot==-1) iSpot=iPtr;
237  }
238  // Full: move down to empty spot if possible
239  else if (iSpot!=-1)
240  {
241  // Move to spot
242  Set[iSpot]=Set[iPtr];
243  Set[iPtr].Mat=MNone;
244  iConsolidated++;
245  // Advance empty spot (as far as ptr)
246  for (; iSpot<iPtr; iSpot++)
247  if (Set[iSpot].Mat==MNone)
248  break;
249  // No empty spot below ptr
250  if (iSpot==iPtr) iSpot=-1;
251  }
252  }
253  // Reset create ptr
254  CreatePtr=0;
255 }
const int32_t MNone
Definition: C4Constants.h:177
const int32_t C4MassMoverChunk
Definition: C4MassMover.h:23
int32_t Mat
Definition: C4MassMover.h:29
C4MassMover Set[C4MassMoverChunk]
Definition: C4MassMover.h:46
int32_t CreatePtr
Definition: C4MassMover.h:44

References C4MassMoverChunk, CreatePtr, C4MassMover::Mat, MNone, and Set.

Referenced by Save(), and Synchronize().

Here is the caller graph for this function:

◆ Copy()

void C4MassMoverSet::Copy ( C4MassMoverSet rSet)

Definition at line 262 of file C4MassMover.cpp.

263 {
264  Clear();
265  Count=rSet.Count;
266  CreatePtr=rSet.CreatePtr;
267  for (int32_t cnt=0; cnt<C4MassMoverChunk; cnt++) Set[cnt]=rSet.Set[cnt];
268 }
int32_t Count
Definition: C4MassMover.h:43

References C4MassMoverChunk, Clear(), Count, CreatePtr, and Set.

Referenced by C4Game::LoadScenarioSection().

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

◆ Create()

bool C4MassMoverSet::Create ( int32_t  x,
int32_t  y,
bool  fExecute = false 
)

Definition at line 70 of file C4MassMover.cpp.

71 {
72  if (Count == C4MassMoverChunk) return false;
74  {
75  C4RCMassMover rc;
76  rc.x=x; rc.y=y;
77  AddDbgRec(RCT_MMC, &rc, sizeof(rc));
78  }
79  int32_t cptr=CreatePtr;
80  do
81  {
82  cptr++;
83  if (cptr>=C4MassMoverChunk) cptr=0;
84  if (Set[cptr].Mat==MNone)
85  {
86  if (!Set[cptr].Init(x,y)) return false;
87  CreatePtr=cptr;
88  if (fExecute) Set[cptr].Execute();
89  return true;
90  }
91  }
92  while (cptr!=CreatePtr);
93  return false;
94 }
C4Config Config
Definition: C4Config.cpp:930
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
@ RCT_MMC
Definition: C4Record.h:60
int32_t DebugRec
Definition: C4Config.h:63
C4ConfigGeneral General
Definition: C4Config.h:255
bool Execute()

References AddDbgRec(), C4MassMoverChunk, Config, Count, CreatePtr, C4ConfigGeneral::DebugRec, C4MassMover::Execute(), C4Config::General, MNone, RCT_MMC, Set, C4RCMassMover::x, and C4RCMassMover::y.

Referenced by C4Landscape::CheckInstability(), and C4MassMover::Execute().

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

◆ Default()

void C4MassMoverSet::Default ( )

Definition at line 183 of file C4MassMover.cpp.

184 {
185  int32_t cnt;
186  for (cnt=0; cnt<C4MassMoverChunk; cnt++) Set[cnt].Mat=MNone;
187  Count=0;
188  CreatePtr=0;
189 }

References C4MassMoverChunk, Count, CreatePtr, MNone, and Set.

Referenced by C4MassMoverSet(), C4Game::Default(), and Load().

Here is the caller graph for this function:

◆ Draw()

void C4MassMoverSet::Draw ( )

Definition at line 96 of file C4MassMover.cpp.

97 {
98 }

◆ Execute()

void C4MassMoverSet::Execute ( )

Definition at line 55 of file C4MassMover.cpp.

56 {
57  C4MassMover *cmm;
58  // Init counts
59  Count=0;
60  // Execute & count
61  for (int32_t speed = 2; speed>0; speed--)
62  {
63  cmm = &(Set[C4MassMoverChunk-1]);
64  for (int32_t cnt = 0; cnt<C4MassMoverChunk; cnt++,cmm--)
65  if (cmm->Mat!=MNone)
66  { Count++; cmm->Execute(); }
67  }
68 }

References C4MassMoverChunk, Count, C4MassMover::Execute(), C4MassMover::Mat, MNone, and Set.

Referenced by C4Game::Execute().

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

◆ Load()

bool C4MassMoverSet::Load ( C4Group hGroup)

Definition at line 214 of file C4MassMover.cpp.

215 {
216  // clear previous
217  Clear(); Default();
218  size_t iBinSize,iMoverSize=sizeof(C4MassMover);
219  if (!hGroup.AccessEntry(C4CFN_MassMover,&iBinSize)) return false;
220  if ((iBinSize % iMoverSize)!=0) return false;
221  // load new
222  Count = iBinSize / iMoverSize;
223  if (!hGroup.Read(Set,iBinSize)) return false;
224  return true;
225 }
#define C4CFN_MassMover
Definition: C4Components.h:76
bool Read(void *buffer, size_t size) override
Definition: C4Group.cpp:1430
bool AccessEntry(const char *wildcard, size_t *size=nullptr, char *filename=nullptr, bool needs_to_be_a_group=false)
Definition: C4Group.cpp:2104

References C4Group::AccessEntry(), C4CFN_MassMover, Clear(), Count, Default(), C4Group::Read(), and Set.

Here is the call graph for this function:

◆ Save()

bool C4MassMoverSet::Save ( C4Group hGroup)

Definition at line 191 of file C4MassMover.cpp.

192 {
193  int32_t cnt;
194  // Consolidate
195  Consolidate();
196  // Recount
197  Count=0;
198  for (cnt=0; cnt<C4MassMoverChunk; cnt++)
199  if (Set[cnt].Mat!=MNone)
200  Count++;
201  // All empty: delete component
202  if (!Count)
203  {
204  hGroup.Delete(C4CFN_MassMover);
205  return true;
206  }
207  // Save set
208  if (!hGroup.Add(C4CFN_MassMover,Set,Count*sizeof(C4MassMover)))
209  return false;
210  // Success
211  return true;
212 }
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621
bool Delete(const char *files, bool recursive=false)
Definition: C4Group.cpp:1645

References C4Group::Add(), C4CFN_MassMover, C4MassMoverChunk, Consolidate(), Count, C4Group::Delete(), MNone, and Set.

Referenced by C4Game::LoadScenarioSection().

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

◆ Synchronize()

void C4MassMoverSet::Synchronize ( )

Definition at line 257 of file C4MassMover.cpp.

258 {
259  Consolidate();
260 }

References Consolidate().

Referenced by C4Game::Synchronize().

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

Member Data Documentation

◆ Count

int32_t C4MassMoverSet::Count

◆ CreatePtr

int32_t C4MassMoverSet::CreatePtr

Definition at line 44 of file C4MassMover.h.

Referenced by Consolidate(), Copy(), Create(), Default(), and C4ControlSyncCheck::Set().

◆ Set

C4MassMover C4MassMoverSet::Set[C4MassMoverChunk]
protected

Definition at line 46 of file C4MassMover.h.

Referenced by Consolidate(), Copy(), Create(), Default(), Execute(), Load(), and Save().


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