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

#include <C4PXS.h>

Collaboration diagram for C4PXSSystem:
[legend]

Public Member Functions

 C4PXSSystem ()
 
 ~C4PXSSystem ()
 
void Delete (C4PXS *pPXS)
 
void Default ()
 
void Clear ()
 
void Execute ()
 
void Draw (C4TargetFacet &cgo)
 
void Synchronize ()
 
void SyncClearance ()
 
void Cast (int32_t mat, int32_t num, int32_t tx, int32_t ty, int32_t level)
 
bool Create (int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
 
bool Load (C4Group &hGroup)
 
bool Save (C4Group &hGroup)
 
int32_t GetCount () const
 
int32_t GetCount (int32_t mat) const
 
int32_t GetCount (int32_t mat, int32_t x, int32_t y, int32_t wdt, int32_t hgt) const
 

Public Attributes

int32_t Count
 

Protected Member Functions

C4PXSNew ()
 

Protected Attributes

C4PXSChunk [PXSMaxChunk]
 
size_t iChunkPXS [PXSMaxChunk]
 

Detailed Description

Definition at line 39 of file C4PXS.h.

Constructor & Destructor Documentation

C4PXSSystem::C4PXSSystem ( )

Definition at line 149 of file C4PXS.cpp.

References Default().

150 {
151  Default();
152 }
void Default()
Definition: C4PXS.cpp:159

Here is the call graph for this function:

C4PXSSystem::~C4PXSSystem ( )

Definition at line 154 of file C4PXS.cpp.

References Clear().

155 {
156  Clear();
157 }
void Clear()
Definition: C4PXS.cpp:169

Here is the call graph for this function:

Member Function Documentation

void C4PXSSystem::Cast ( int32_t  mat,
int32_t  num,
int32_t  tx,
int32_t  ty,
int32_t  level 
)

Definition at line 356 of file C4PXS.cpp.

References Create(), itofix(), and Random().

Referenced by C4Landscape::P::BlastMaterial2Objects().

357 {
358  int32_t cnt;
359  for (cnt=0; cnt<num; cnt++)
360  {
361  // Must do these calculation steps separately, because the order of
362  // invokations of Random() is not defined if they're used as parameters
363  C4Real xdir = itofix(Random(level+1)-level/2); xdir/=10;
364  C4Real ydir = itofix(Random(level+1)-level); ydir/=10;
365  Create(mat,
366  itofix(tx),itofix(ty),
367  xdir,
368  ydir);
369  }
370 }
uint32_t Random()
Definition: C4Random.cpp:43
bool Create(int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
Definition: C4PXS.cpp:205
Definition: C4Real.h:58
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXSSystem::Clear ( )

Definition at line 169 of file C4PXS.cpp.

References Chunk, iChunkPXS, and PXSMaxChunk.

Referenced by C4Game::Clear(), C4Game::InitGame(), Load(), and ~C4PXSSystem().

170 {
171  for (unsigned int cnt=0; cnt<PXSMaxChunk; cnt++)
172  {
173  if (Chunk[cnt]) delete [] Chunk[cnt];
174  Chunk[cnt]=nullptr;
175  iChunkPXS[cnt]=0;
176  }
177 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
const size_t PXSMaxChunk
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the caller graph for this function:

bool C4PXSSystem::Create ( int32_t  mat,
C4Real  ix,
C4Real  iy,
C4Real  ixdir = Fix0,
C4Real  iydir = Fix0 
)

Definition at line 205 of file C4PXS.cpp.

References C4PXS::Mat, MatValid(), New(), C4PXS::x, C4PXS::xdir, C4PXS::y, and C4PXS::ydir.

Referenced by Cast(), C4Landscape::CheckInstability(), C4Landscape::InsertMaterial(), C4MaterialMap::mrfConvert(), and C4Landscape::P::ShakeFreePix().

206 {
207  C4PXS *pxp;
208  if (!MatValid(mat)) return false;
209  if (!(pxp=New())) return false;
210  pxp->Mat=mat;
211  pxp->x=ix; pxp->y=iy;
212  pxp->xdir=ixdir; pxp->ydir=iydir;
213  return true;
214 }
C4PXS * New()
Definition: C4PXS.cpp:179
Definition: C4PXS.h:25
C4Real y
Definition: C4PXS.h:31
C4Real ydir
Definition: C4PXS.h:31
int32_t Mat
Definition: C4PXS.h:30
C4Real xdir
Definition: C4PXS.h:31
C4Real x
Definition: C4PXS.h:31
bool MatValid(int32_t mat)
Definition: C4Material.h:210

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXSSystem::Default ( )

Definition at line 159 of file C4PXS.cpp.

References Chunk, Count, iChunkPXS, and PXSMaxChunk.

Referenced by C4PXSSystem(), and C4Game::Default().

160 {
161  Count=0;
162  for (unsigned int cnt=0; cnt<PXSMaxChunk; cnt++)
163  {
164  Chunk[cnt]=nullptr;
165  iChunkPXS[cnt]=0;
166  }
167 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
const size_t PXSMaxChunk
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48
int32_t Count
Definition: C4PXS.h:45

Here is the caller graph for this function:

void C4PXSSystem::Delete ( C4PXS pPXS)

Definition at line 485 of file C4PXS.cpp.

References Chunk, iChunkPXS, PXSChunkSize, and PXSMaxChunk.

Referenced by C4PXS::Deactivate().

486 {
487  // find chunk
488  unsigned int cnt;
489  for (cnt = 0; cnt < PXSMaxChunk; cnt++)
490  if (Chunk[cnt] && iChunkPXS[cnt])
491  if (pPXS >= Chunk[cnt] && pPXS < Chunk[cnt] + PXSChunkSize)
492  break;
493  // decrease pxs counter
494  if (cnt < PXSMaxChunk)
495  iChunkPXS[cnt]--;
496 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
const size_t PXSMaxChunk
Definition: C4PXS.h:37
const size_t PXSChunkSize
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the caller graph for this function:

void C4PXSSystem::Draw ( C4TargetFacet cgo)

Definition at line 240 of file C4PXS.cpp.

References Abs(), Chunk, C4BltVertex::color, Config, C4Rect::Contains(), DwTo4UB(), C4Rect::Enlarge(), fixtof(), fixtoi(), C4BltVertex::ftx, C4BltVertex::fty, CStdPalette::GetClr(), C4Landscape::GetPal(), C4Facet::GetPhaseNum(), C4Config::Graphics, C4Surface::Hgt, C4Facet::Hgt, iChunkPXS, Landscape, C4MaterialMap::Map, C4PXS::Mat, Mat2PixColDefault(), MaterialMap, MNone, pDraw, C4Draw::PerformMultiLines(), C4Draw::PerformMultiPix(), C4Draw::PerformMultiTris(), PXSChunkSize, C4Material::PXSFace, C4ConfigGraphics::PXSGfx, C4MaterialCore::PXSGfxRt, C4MaterialCore::PXSGfxSize, PXSMaxChunk, C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4Surface::texture, C4BltVertex::tx, C4TargetRect::tx, C4BltVertex::ty, C4TargetRect::ty, C4Surface::Wdt, C4Facet::Wdt, C4PXS::x, C4Facet::X, C4PXS::xdir, C4PXS::y, C4Facet::Y, C4PXS::ydir, and z.

Referenced by C4Viewport::Draw().

241 {
242  // Draw PXS in this region
243  C4Rect VisibleRect(cgo.TargetX, cgo.TargetY, cgo.Wdt, cgo.Hgt);
244  VisibleRect.Enlarge(20);
245 
246  // Go through all PXS and build vertex arrays. The vertex arrays are
247  // then submitted to the GL in one go.
248  std::vector<C4BltVertex> pixVtx;
249  std::vector<C4BltVertex> lineVtx;
250  std::map<int, std::vector<C4BltVertex> > bltVtx;
251  // TODO: reserve some space to avoid too many allocations
252  // TODO: keep vertex mem allocated between draw invocations
253 
254  float cgox = cgo.X - cgo.TargetX, cgoy = cgo.Y - cgo.TargetY;
255  // First pass: draw simple PXS (lines/pixels)
256  unsigned int cnt;
257  for (cnt=0; cnt < PXSMaxChunk; cnt++)
258  {
259  if (Chunk[cnt] && iChunkPXS[cnt])
260  {
261  C4PXS *pxp = Chunk[cnt];
262  for (unsigned int cnt2 = 0; cnt2 < PXSChunkSize; cnt2++, pxp++)
263  if (pxp->Mat != MNone && VisibleRect.Contains(fixtoi(pxp->x), fixtoi(pxp->y)))
264  {
265  C4Material *pMat = &::MaterialMap.Map[pxp->Mat];
266  const DWORD dwMatClr = ::Landscape.GetPal()->GetClr((BYTE) (Mat2PixColDefault(pxp->Mat)));
267  if(pMat->PXSFace.Surface)
268  {
269  int32_t pnx, pny;
270  pMat->PXSFace.GetPhaseNum(pnx, pny);
271  int32_t fcWdt = pMat->PXSFace.Wdt;
272  int32_t fcHgt = pMat->PXSFace.Hgt;
273  // calculate draw width and tile to use (random-ish)
274  uint32_t size = (1103515245 * (cnt * PXSChunkSize + cnt2) + 12345) >> 3;
275  float z = pMat->PXSGfxSize * (0.625f + 0.05f * int(size % 16));
276  pny = (cnt2 / pnx) % pny; pnx = cnt2 % pnx;
277 
278  const float w = z;
279  const float h = z * fcHgt / fcWdt;
280  const float x1 = fixtof(pxp->x) + cgox + z * pMat->PXSGfxRt.tx / fcWdt;
281  const float y1 = fixtof(pxp->y) + cgoy + z * pMat->PXSGfxRt.ty / fcHgt;
282  const float x2 = x1 + w;
283  const float y2 = y1 + h;
284 
285  const float sfcWdt = pMat->PXSFace.Surface->Wdt;
286  const float sfcHgt = pMat->PXSFace.Surface->Hgt;
287 
288  C4BltVertex vtx[6];
289  vtx[0].tx = (pnx + 0.f) * fcWdt / sfcWdt; vtx[0].ty = (pny + 0.f) * fcHgt / sfcHgt;
290  vtx[0].ftx = x1; vtx[0].fty = y1;
291  vtx[1].tx = (pnx + 1.f) * fcWdt / sfcWdt; vtx[1].ty = (pny + 0.f) * fcHgt / sfcHgt;
292  vtx[1].ftx = x2; vtx[1].fty = y1;
293  vtx[2].tx = (pnx + 1.f) * fcWdt / sfcWdt; vtx[2].ty = (pny + 1.f) * fcHgt / sfcHgt;
294  vtx[2].ftx = x2; vtx[2].fty = y2;
295  vtx[3].tx = (pnx + 0.f) * fcWdt / sfcWdt; vtx[3].ty = (pny + 1.f) * fcHgt / sfcHgt;
296  vtx[3].ftx = x1; vtx[3].fty = y2;
297  DwTo4UB(0xFFFFFFFF, vtx[0].color);
298  DwTo4UB(0xFFFFFFFF, vtx[1].color);
299  DwTo4UB(0xFFFFFFFF, vtx[2].color);
300  DwTo4UB(0xFFFFFFFF, vtx[3].color);
301  vtx[4] = vtx[2];
302  vtx[5] = vtx[0];
303 
304  std::vector<C4BltVertex>& vec = bltVtx[pxp->Mat];
305  vec.push_back(vtx[0]);
306  vec.push_back(vtx[1]);
307  vec.push_back(vtx[2]);
308  vec.push_back(vtx[3]);
309  vec.push_back(vtx[4]);
310  vec.push_back(vtx[5]);
311  }
312  else
313  {
314  // old-style: unicolored pixels or lines
315  if (fixtoi(pxp->xdir) || fixtoi(pxp->ydir))
316  {
317  // lines for stuff that goes whooosh!
318  int len = fixtoi(Abs(pxp->xdir) + Abs(pxp->ydir));
319  const DWORD dwMatClrLen = uint32_t(std::max<int>(dwMatClr >> 24, 195 - (195 - (dwMatClr >> 24)) / len)) << 24 | (dwMatClr & 0xffffff);
320  C4BltVertex begin, end;
321  begin.ftx = fixtof(pxp->x - pxp->xdir) + cgox; begin.fty = fixtof(pxp->y - pxp->ydir) + cgoy;
322  end.ftx = fixtof(pxp->x) + cgox; end.fty = fixtof(pxp->y) + cgoy;
323  DwTo4UB(dwMatClrLen, begin.color);
324  DwTo4UB(dwMatClrLen, end.color);
325  lineVtx.push_back(begin);
326  lineVtx.push_back(end);
327  }
328  else
329  {
330  // single pixels for slow stuff
331  C4BltVertex vtx;
332  vtx.ftx = fixtof(pxp->x) + cgox;
333  vtx.fty = fixtof(pxp->y) + cgoy;
334  DwTo4UB(dwMatClr, vtx.color);
335  pixVtx.push_back(vtx);
336  }
337  }
338  }
339  }
340  }
341 
342  if(!pixVtx.empty()) pDraw->PerformMultiPix(cgo.Surface, &pixVtx[0], pixVtx.size(), nullptr);
343  if(!lineVtx.empty()) pDraw->PerformMultiLines(cgo.Surface, &lineVtx[0], lineVtx.size(), 1.0f, nullptr);
344 
345  // PXS graphics disabled?
346  if (!Config.Graphics.PXSGfx)
347  return;
348 
349  for(std::map<int, std::vector<C4BltVertex> >::const_iterator iter = bltVtx.begin(); iter != bltVtx.end(); ++iter)
350  {
351  C4Material *pMat = &::MaterialMap.Map[iter->first];
352  pDraw->PerformMultiTris(cgo.Surface, &iter->second[0], iter->second.size(), nullptr, pMat->PXSFace.Surface->texture.get(), nullptr, nullptr, 0, nullptr);
353  }
354 }
float fty
Definition: C4Draw.h:64
C4Config Config
Definition: C4Config.cpp:833
float Y
Definition: C4Facet.h:118
#define z
int Wdt
Definition: C4Surface.h:65
float tx
Definition: C4Draw.h:62
C4TargetRect PXSGfxRt
Definition: C4Material.h:117
unsigned char color[4]
Definition: C4Draw.h:63
bool GetPhaseNum(int32_t &rX, int32_t &rY)
Definition: C4Facet.cpp:472
C4Material * Map
Definition: C4Material.h:169
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
Definition: C4Rect.h:27
uint8_t BYTE
float ty
Definition: C4Draw.h:62
C4Real y
Definition: C4PXS.h:31
int Hgt
Definition: C4Surface.h:65
virtual void PerformMultiTris(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, const C4BltTransform *pTransform, C4TexRef *pTex, C4TexRef *pOverlay, C4TexRef *pNormal, DWORD dwOverlayClrMod, C4ShaderCall *shader_call)=0
DWORD GetClr(BYTE byCol)
Definition: StdColors.h:186
C4ConfigGraphics Graphics
Definition: C4Config.h:253
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
C4Real ydir
Definition: C4PXS.h:31
const int32_t MNone
Definition: C4Constants.h:178
virtual void PerformMultiPix(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call)=0
C4Landscape Landscape
int32_t tx
Definition: C4Rect.h:79
C4Draw * pDraw
Definition: C4Draw.cpp:42
int32_t ty
Definition: C4Rect.h:79
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
int32_t PXSGfx
Definition: C4Config.h:109
const size_t PXSChunkSize
Definition: C4PXS.h:37
int32_t PXSGfxSize
Definition: C4Material.h:118
std::unique_ptr< C4TexRef > texture
Definition: C4Surface.h:78
float TargetX
Definition: C4Facet.h:165
float Hgt
Definition: C4Facet.h:118
C4Real xdir
Definition: C4PXS.h:31
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
CStdPalette * GetPal() const
C4Real x
Definition: C4PXS.h:31
float ftx
Definition: C4Draw.h:64
float fixtof(const C4Fixed &x)
Definition: C4Real.h:257
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
T Abs(T val)
Definition: Standard.h:42
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
uint32_t DWORD
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Facet PXSFace
Definition: C4Material.h:157
float Wdt
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXSSystem::Execute ( )

Definition at line 216 of file C4PXS.cpp.

References Chunk, Count, C4PXS::Execute(), iChunkPXS, C4PXS::Mat, MNone, PXSChunkSize, and PXSMaxChunk.

Referenced by C4Game::Execute().

217 {
218  // Execute all chunks
219  Count=0;
220  for (unsigned int cchunk=0; cchunk<PXSMaxChunk; cchunk++)
221  if (Chunk[cchunk])
222  {
223  // empty chunk?
224  if (!iChunkPXS[cchunk])
225  { delete [] Chunk[cchunk]; Chunk[cchunk]=nullptr; }
226  else
227  {
228  // Execute chunk pxs, check for empty
229  C4PXS *pxp = Chunk[cchunk];
230  for (unsigned int cnt2=0; cnt2<PXSChunkSize; cnt2++,pxp++)
231  if (pxp->Mat!=MNone)
232  {
233  pxp->Execute();
234  Count++;
235  }
236  }
237  }
238 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
const int32_t MNone
Definition: C4Constants.h:178
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
const size_t PXSChunkSize
Definition: C4PXS.h:37
void Execute()
Definition: C4PXS.cpp:33
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48
int32_t Count
Definition: C4PXS.h:45

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4PXSSystem::GetCount ( ) const
inline

Definition at line 61 of file C4PXS.h.

References Count.

61 { return Count; } // count all PXS
int32_t Count
Definition: C4PXS.h:45
int32_t C4PXSSystem::GetCount ( int32_t  mat) const

Definition at line 498 of file C4PXS.cpp.

References Chunk, iChunkPXS, C4PXS::Mat, PXSChunkSize, and PXSMaxChunk.

499 {
500  // count PXS of given material
501  int32_t result = 0;
502  for (size_t cnt = 0; cnt < PXSMaxChunk; cnt++) if (Chunk[cnt] && iChunkPXS[cnt])
503  {
504  C4PXS *pxp = Chunk[cnt];
505  for (size_t cnt2 = 0; cnt2 < PXSChunkSize; cnt2++, pxp++) if (pxp->Mat == mat) ++result;
506  }
507  return result;
508 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
const size_t PXSChunkSize
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48
int32_t C4PXSSystem::GetCount ( int32_t  mat,
int32_t  x,
int32_t  y,
int32_t  wdt,
int32_t  hgt 
) const

Definition at line 510 of file C4PXS.cpp.

References Chunk, iChunkPXS, Inside(), C4PXS::Mat, MNone, PXSChunkSize, PXSMaxChunk, C4PXS::x, and C4PXS::y.

511 {
512  // count PXS of given material in given area
513  int32_t result = 0;
514  for (size_t cnt = 0; cnt < PXSMaxChunk; cnt++) if (Chunk[cnt] && iChunkPXS[cnt])
515  {
516  C4PXS *pxp = Chunk[cnt];
517  for (size_t cnt2 = 0; cnt2 < PXSChunkSize; cnt2++, pxp++)
518  if (pxp->Mat != MNone)
519  if (pxp->Mat == mat || mat == MNone)
520  if (Inside(pxp->x, x, x + wdt - 1) && Inside(pxp->y, y, y + hgt - 1)) ++result;
521  }
522  return result;
523 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
C4Real y
Definition: C4PXS.h:31
const int32_t MNone
Definition: C4Constants.h:178
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
const size_t PXSChunkSize
Definition: C4PXS.h:37
C4Real x
Definition: C4PXS.h:31
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the call graph for this function:

bool C4PXSSystem::Load ( C4Group hGroup)

Definition at line 414 of file C4PXS.cpp.

References C4Group::AccessEntry(), C4CFN_PXS, Chunk, Clear(), FLOAT_TO_FIXED(), iChunkPXS, C4PXS::Mat, MNone, PXSChunkSize, PXSMaxChunk, C4Group::Read(), C4PXS::x, C4PXS::xdir, C4PXS::y, and C4PXS::ydir.

Referenced by C4Game::InitGame().

415 {
416  // load new
417  size_t iBinSize,iChunkNum,cnt2;
418  size_t iChunkSize = PXSChunkSize * sizeof(C4PXS);
419  if (!hGroup.AccessEntry(C4CFN_PXS,&iBinSize)) return false;
420  // clear previous
421  Clear();
422  // using C4Real or float?
423  int32_t iNumForm = 1;
424  if (iBinSize % iChunkSize == 4)
425  {
426  if (!hGroup.Read(&iNumForm, sizeof (iNumForm))) return false;
427  if (!Inside<int32_t>(iNumForm, 1, 2)) return false;
428  iBinSize -= 4;
429  }
430  // old pxs-files have no tag for the number format
431  else if (iBinSize % iChunkSize != 0) return false;
432  // calc chunk count
433  iChunkNum = iBinSize / iChunkSize;
434  if (iChunkNum > PXSMaxChunk) return false;
435  for (uint32_t cnt=0; cnt<iChunkNum; cnt++)
436  {
437  if (!(Chunk[cnt]=new C4PXS[PXSChunkSize])) return false;
438  if (!hGroup.Read(Chunk[cnt],iChunkSize)) return false;
439  // count the PXS, Peter!
440  // convert num format, if neccessary
441  C4PXS *pxp; iChunkPXS[cnt]=0;
442  for (cnt2=0,pxp=Chunk[cnt]; cnt2<PXSChunkSize; cnt2++,pxp++)
443  if (pxp->Mat != MNone)
444  {
445  ++iChunkPXS[cnt];
446  // convert number format
447 #ifdef C4REAL_USE_FIXNUM
448  if (iNumForm == 2) { FLOAT_TO_FIXED(&pxp->x); FLOAT_TO_FIXED(&pxp->y); FLOAT_TO_FIXED(&pxp->xdir); FLOAT_TO_FIXED(&pxp->ydir); }
449 #else
450  if (iNumForm == 1) { FIXED_TO_FLOAT(&pxp->x); FIXED_TO_FLOAT(&pxp->y); FIXED_TO_FLOAT(&pxp->xdir); FIXED_TO_FLOAT(&pxp->ydir); }
451 #endif
452  }
453  }
454  return true;
455 }
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
C4Real y
Definition: C4PXS.h:31
C4Real ydir
Definition: C4PXS.h:31
const int32_t MNone
Definition: C4Constants.h:178
void Clear()
Definition: C4PXS.cpp:169
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
const size_t PXSChunkSize
Definition: C4PXS.h:37
C4Real xdir
Definition: C4PXS.h:31
C4Real x
Definition: C4PXS.h:31
#define C4CFN_PXS
Definition: C4Components.h:75
void FLOAT_TO_FIXED(C4Real *pVal)
Definition: C4Real.h:318
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48
bool Read(void *pBuffer, size_t iSize) override
Definition: C4Group.cpp:1125

Here is the call graph for this function:

Here is the caller graph for this function:

C4PXS * C4PXSSystem::New ( )
protected

Definition at line 179 of file C4PXS.cpp.

References Chunk, iChunkPXS, C4PXS::Mat, MNone, PXSChunkSize, and PXSMaxChunk.

Referenced by Create().

180 {
181  unsigned int cnt,cnt2;
182  C4PXS *pxp;
183  // Check chunks for available space
184  for (cnt=0; cnt<PXSMaxChunk; cnt++)
185  {
186  // Create new chunk if necessary
187  if (!Chunk[cnt])
188  {
189  if (!(Chunk[cnt]=new C4PXS[PXSChunkSize])) return nullptr;
190  iChunkPXS[cnt] = 0;
191  }
192  // Check this chunk for space
193  if (iChunkPXS[cnt] < PXSChunkSize)
194  for (cnt2=0,pxp=Chunk[cnt]; cnt2<PXSChunkSize; cnt2++,pxp++)
195  if (pxp->Mat==MNone)
196  {
197  // count them
198  iChunkPXS[cnt]++;
199  return pxp;
200  }
201  }
202  return nullptr;
203 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
const int32_t MNone
Definition: C4Constants.h:178
const size_t PXSMaxChunk
Definition: C4PXS.h:37
int32_t Mat
Definition: C4PXS.h:30
const size_t PXSChunkSize
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the caller graph for this function:

bool C4PXSSystem::Save ( C4Group hGroup)

Definition at line 372 of file C4PXS.cpp.

References C4Config::AtTempPath(), C4CFN_PXS, C4CFN_TempPXS, Chunk, CStdFile::Close(), Config, CStdFile::Create(), C4Group::Delete(), iChunkPXS, C4Group::Move(), PXSChunkSize, PXSMaxChunk, and CStdFile::Write().

Referenced by C4Game::LoadScenarioSection().

373 {
374  unsigned int cnt;
375 
376  // Check used chunk count
377  int32_t iChunks=0;
378  for (cnt=0; cnt<PXSMaxChunk; cnt++)
379  if (Chunk[cnt] && iChunkPXS[cnt])
380  iChunks++;
381  if (!iChunks)
382  {
383  hGroup.Delete(C4CFN_PXS);
384  return true;
385  }
386 
387  // Save chunks to temp file
388  CStdFile hTempFile;
389  if (!hTempFile.Create(Config.AtTempPath(C4CFN_TempPXS)))
390  return false;
391 #ifdef C4REAL_USE_FIXNUM
392  int32_t iNumFormat = 1;
393 #else
394  int32_t iNumFormat = 2;
395 #endif
396  if (!hTempFile.Write(&iNumFormat, sizeof (iNumFormat)))
397  return false;
398  for (cnt=0; cnt<PXSMaxChunk; cnt++)
399  if (Chunk[cnt]) // must save all chunks in order to keep order consistent on all clients
400  if (!hTempFile.Write(Chunk[cnt],PXSChunkSize * sizeof(C4PXS)))
401  return false;
402 
403  if (!hTempFile.Close())
404  return false;
405 
406  // Move temp file to group
407  if (!hGroup.Move( Config.AtTempPath(C4CFN_TempPXS),
408  C4CFN_PXS ))
409  return false;
410 
411  return true;
412 }
bool Close(StdBuf **ppMemory=nullptr)
Definition: CStdFile.cpp:151
C4Config Config
Definition: C4Config.cpp:833
bool Create(const char *szFileName, bool fCompressed=false, bool fExecutable=false, bool fMemory=false)
Definition: CStdFile.cpp:49
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
bool Write(const void *pBuffer, int iSize)
Definition: CStdFile.cpp:240
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
const size_t PXSMaxChunk
Definition: C4PXS.h:37
const size_t PXSChunkSize
Definition: C4PXS.h:37
#define C4CFN_PXS
Definition: C4Components.h:75
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
#define C4CFN_TempPXS
Definition: C4Components.h:158
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

void C4PXSSystem::SyncClearance ( )

Definition at line 462 of file C4PXS.cpp.

References Chunk, iChunkPXS, and PXSMaxChunk.

Referenced by C4Game::SyncClearance().

463 {
464  // consolidate chunks; remove empty chunks
465  C4PXS **pDestChunk = Chunk;
466  int32_t iDestChunk = 0;
467  for (unsigned int cnt=0; cnt<PXSMaxChunk; cnt++)
468  {
469  if (Chunk[cnt])
470  {
471  if (iChunkPXS[cnt])
472  {
473  *pDestChunk++ = Chunk[cnt];
474  iChunkPXS[iDestChunk++] = iChunkPXS[cnt];
475  }
476  else
477  {
478  delete [] Chunk[cnt];
479  Chunk[cnt] = nullptr;
480  }
481  }
482  }
483 }
C4PXS * Chunk[PXSMaxChunk]
Definition: C4PXS.h:47
Definition: C4PXS.h:25
const size_t PXSMaxChunk
Definition: C4PXS.h:37
size_t iChunkPXS[PXSMaxChunk]
Definition: C4PXS.h:48

Here is the caller graph for this function:

void C4PXSSystem::Synchronize ( )

Definition at line 457 of file C4PXS.cpp.

References Count.

Referenced by C4Game::Synchronize().

458 {
459  Count=0;
460 }
int32_t Count
Definition: C4PXS.h:45

Here is the caller graph for this function:

Member Data Documentation

C4PXS* C4PXSSystem::Chunk[PXSMaxChunk]
protected

Definition at line 47 of file C4PXS.h.

Referenced by Clear(), Default(), Delete(), Draw(), Execute(), GetCount(), Load(), New(), Save(), and SyncClearance().

int32_t C4PXSSystem::Count

Definition at line 45 of file C4PXS.h.

Referenced by Default(), Execute(), GetCount(), C4ControlSyncCheck::Set(), and Synchronize().

size_t C4PXSSystem::iChunkPXS[PXSMaxChunk]
protected

Definition at line 48 of file C4PXS.h.

Referenced by Clear(), Default(), Delete(), Draw(), Execute(), GetCount(), Load(), New(), Save(), and SyncClearance().


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