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

#include <C4SolidMask.h>

Collaboration diagram for C4SolidMask:
[legend]

Classes

class  DensityProvider
 

Public Member Functions

void Put (bool fCauseInstability, C4TargetRect *pClipRect, bool fRestoreAttachment)
 
void Remove (bool fBackupAttachment)
 
void Draw (C4TargetFacet &cgo)
 
bool IsPut ()
 
 C4SolidMask (C4Object *pForObject)
 
 ~C4SolidMask ()
 
void SetHalfVehicle (bool set)
 

Static Public Member Functions

static bool CheckConsistency ()
 
static void RemoveSolidMasks ()
 
static void PutSolidMasks ()
 
static CSurface8LoadMaskFromFile (class C4Group &hGroup, const char *szFilename)
 

Public Attributes

C4SolidMaskPrev
 
C4SolidMaskNext
 

Static Public Attributes

static C4SolidMaskFirst = 0
 
static C4SolidMaskLast = 0
 

Protected Member Functions

void RemoveTemporary (C4Rect where)
 
void PutTemporary (C4Rect where)
 
void Repair (C4Rect where)
 

Protected Attributes

bool MaskPut
 
int MaskPutRotation
 
int MatBuffPitch
 
C4Real MaskRemovalX
 
int32_t MaskRemovalY
 
class C4Object ** ppAttachingObjects
 
int iAttachingObjectsCount
 
int iAttachingObjectsCapacity
 
C4TargetRect MaskPutRect
 
BYTEpSolidMaskMatBuff
 
BYTE MaskMaterial
 
C4ObjectpForObject
 

Friends

class C4Landscape
 
class DensityProvider
 

Detailed Description

Definition at line 25 of file C4SolidMask.h.

Constructor & Destructor Documentation

C4SolidMask::C4SolidMask ( C4Object pForObject)

Definition at line 409 of file C4SolidMask.cpp.

References First, Fix0, C4Rect::Hgt, iAttachingObjectsCapacity, iAttachingObjectsCount, Last, MaskMaterial, MaskPut, MaskPutRotation, MaskRemovalX, MaskRemovalY, MatBuffPitch, MCVehic, Next, ppAttachingObjects, Prev, pSolidMaskMatBuff, C4Object::SolidMask, and C4Rect::Wdt.

409  : pForObject(pForObject)
410 {
411  // zero fields
412  MaskPut=false;
413  MaskPutRotation=0;
414  MaskRemovalX = Fix0;
415  MaskRemovalY = 0;
416  ppAttachingObjects=nullptr;
419  // Update linked list
420  Next = 0;
421  Prev = Last;
422  Last = this;
423  if (Prev) Prev->Next = this;
424  else First = this;
425  // create mat buff to store the material replaced by the solid mask
426  // the upper left corner is here the [objpos]+rot([shapexy]+[targetxy]+[realWH]/2)-maxWH/2
427  MatBuffPitch = (int) sqrt(double(pForObject->SolidMask.Wdt * pForObject->SolidMask.Wdt + pForObject->SolidMask.Hgt * pForObject->SolidMask.Hgt))+1;
428  if (!(pSolidMaskMatBuff= new BYTE [MatBuffPitch * MatBuffPitch] )) return;
429  memset(pSolidMaskMatBuff, 0, MatBuffPitch * MatBuffPitch);
430 }
int MaskPutRotation
Definition: C4SolidMask.h:29
int MatBuffPitch
Definition: C4SolidMask.h:30
int iAttachingObjectsCapacity
Definition: C4SolidMask.h:38
int iAttachingObjectsCount
Definition: C4SolidMask.h:38
C4Object * pForObject
Definition: C4SolidMask.h:46
uint8_t BYTE
int32_t Wdt
Definition: C4Rect.h:32
BYTE MCVehic
Definition: C4Material.cpp:38
class C4Object ** ppAttachingObjects
Definition: C4SolidMask.h:37
static C4SolidMask * First
Definition: C4SolidMask.h:72
C4Real MaskRemovalX
Definition: C4SolidMask.h:34
int32_t Hgt
Definition: C4Rect.h:32
bool MaskPut
Definition: C4SolidMask.h:28
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
C4SolidMask * Prev
Definition: C4SolidMask.h:74
C4TargetRect SolidMask
Definition: C4Object.h:150
static C4SolidMask * Last
Definition: C4SolidMask.h:73
BYTE MaskMaterial
Definition: C4SolidMask.h:44
C4SolidMask * Next
Definition: C4SolidMask.h:75
const C4Real Fix0
Definition: C4Real.h:312
int32_t MaskRemovalY
Definition: C4SolidMask.h:35
C4SolidMask::~C4SolidMask ( )

Definition at line 432 of file C4SolidMask.cpp.

References First, Last, Next, ppAttachingObjects, Prev, pSolidMaskMatBuff, and Remove().

433 {
434  Remove(false);
435  // Update linked list
436  if (Next) Next->Prev = Prev;
437  if (Prev) Prev->Next = Next;
438  if (First == this) First = Next;
439  if (Last == this) Last = Prev;
440  delete [] pSolidMaskMatBuff;
441  delete [] ppAttachingObjects;
442 }
void Remove(bool fBackupAttachment)
class C4Object ** ppAttachingObjects
Definition: C4SolidMask.h:37
static C4SolidMask * First
Definition: C4SolidMask.h:72
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
C4SolidMask * Prev
Definition: C4SolidMask.h:74
static C4SolidMask * Last
Definition: C4SolidMask.h:73
C4SolidMask * Next
Definition: C4SolidMask.h:75

Here is the call graph for this function:

Member Function Documentation

bool C4SolidMask::CheckConsistency ( )
static

Definition at line 469 of file C4SolidMask.cpp.

References C4Landscape::GetHeight(), C4Landscape::GetMatCount(), C4Landscape::GetWidth(), Landscape, MVehic, Next, Prev, RemoveTemporary(), and SOLIDMASK_DEBUG.

Referenced by C4Landscape::DoRelights(), C4Landscape::P::FinishChange(), Put(), and Remove().

470 {
471  if (!SOLIDMASK_DEBUG)
472  return true;
473 
474  C4Rect SolidMaskRect(0,0,::Landscape.GetWidth(),::Landscape.GetHeight());
475  C4SolidMask *pSolid;
476  for (pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
477  {
478  pSolid->RemoveTemporary(SolidMaskRect);
479  }
480  assert(!::Landscape.GetMatCount(MVehic));
481  // Restore Solidmasks
482  for (pSolid = C4SolidMask::First; pSolid; pSolid = pSolid->Next)
483  {
484  pSolid->PutTemporary(SolidMaskRect);
485  }
486  return true;
487 }
constexpr bool SOLIDMASK_DEBUG
Definition: C4Include.h:39
Definition: C4Rect.h:29
int32_t GetMatCount(int material) const
void RemoveTemporary(C4Rect where)
C4Landscape Landscape
int32_t MVehic
Definition: C4Material.cpp:37
int32_t GetHeight() const
static C4SolidMask * First
Definition: C4SolidMask.h:72
C4SolidMask * Prev
Definition: C4SolidMask.h:74
static C4SolidMask * Last
Definition: C4SolidMask.h:73
int32_t GetWidth() const
C4SolidMask * Next
Definition: C4SolidMask.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::Draw ( C4TargetFacet cgo)

Definition at line 331 of file C4SolidMask.cpp.

References C4Facet::DrawX(), C4Facet::DrawXR(), C4DefGraphics::GetBitmap(), C4Object::GetGraphics(), C4Object::GetX(), C4Object::GetY(), C4Rect::Hgt, C4Facet::Hgt, MaskPut, MaskPutRotation, pForObject, C4Facet::Set(), C4Object::Shape, C4Object::SolidMask, C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Facet::Wdt, C4Rect::x, C4Facet::X, C4Rect::y, and C4Facet::Y.

Referenced by C4Object::DrawSolidMask().

332 {
333  // only if put
334  if (!MaskPut) return;
335  // set topface facet
337  // draw it
338  if (MaskPutRotation)
340  else
342 }
int32_t GetY() const
Definition: C4Object.h:287
int MaskPutRotation
Definition: C4SolidMask.h:29
float Y
Definition: C4Facet.h:120
C4Object * pForObject
Definition: C4SolidMask.h:46
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
void DrawX(C4Surface *sfcTarget, float iX, float iY, float iWdt, float iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0) const
Definition: C4Facet.cpp:358
C4Surface * GetBitmap(DWORD dwClr=0)
C4DefGraphics * GetGraphics() const
Definition: C4Object.h:340
int32_t GetX() const
Definition: C4Object.h:286
int32_t tx
Definition: C4Rect.h:81
int32_t ty
Definition: C4Rect.h:81
int32_t x
Definition: C4Rect.h:32
float TargetX
Definition: C4Facet.h:167
float Hgt
Definition: C4Facet.h:120
void DrawXR(C4Surface *sfcTarget, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iPhaseX=0, int32_t iPhaseY=0, int32_t r=0)
Definition: C4Facet.cpp:238
int32_t Hgt
Definition: C4Rect.h:32
C4Shape Shape
Definition: C4Object.h:148
C4Surface * Surface
Definition: C4Facet.h:119
bool MaskPut
Definition: C4SolidMask.h:28
float TargetY
Definition: C4Facet.h:167
C4TargetRect SolidMask
Definition: C4Object.h:150
float Wdt
Definition: C4Facet.h:120
float X
Definition: C4Facet.h:120

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4SolidMask::IsPut ( )
inline

Definition at line 81 of file C4SolidMask.h.

References MaskPut.

81 { return MaskPut; }
bool MaskPut
Definition: C4SolidMask.h:28
CSurface8 * C4SolidMask::LoadMaskFromFile ( class C4Group hGroup,
const char *  szFilename 
)
static

Definition at line 489 of file C4SolidMask.cpp.

References StdBuf::getMData(), CPNGFile::GetPix(), StdBuf::getSize(), CPNGFile::iHgt, CPNGFile::iWdt, CPNGFile::Load(), C4Group::LoadEntry(), and CSurface8::SetPix().

490 {
491  // Construct SolidMask surface from PNG bitmap:
492  // All pixels that are more than 50% transparent are not solid
493  CPNGFile png;
494  StdBuf png_buf;
495  if (!hGroup.LoadEntry(szFilename, &png_buf)) return nullptr; // error messages done by caller
496  if (!png.Load((BYTE*)png_buf.getMData(), png_buf.getSize())) return nullptr;
497  CSurface8 *result = new CSurface8(png.iWdt, png.iHgt);
498  for (size_t y=0u; y<png.iHgt; ++y)
499  for (size_t x=0u; x<png.iWdt; ++x)
500  result->SetPix(x,y,((png.GetPix(x,y)>>24)<128) ? 0x00 : 0xff);
501  return result;
502 }
Definition: StdBuf.h:37
DWORD GetPix(int iX, int iY)
Definition: StdPNG.cpp:173
uint8_t BYTE
size_t getSize() const
Definition: StdBuf.h:109
unsigned long iHgt
Definition: StdPNG.h:44
unsigned long iWdt
Definition: StdPNG.h:44
void SetPix(int iX, int iY, BYTE byCol)
Definition: CSurface8.h:37
bool Load(BYTE *pFile, int iSize)
Definition: StdPNG.cpp:153
void * getMData()
Definition: StdBuf.h:108

Here is the call graph for this function:

void C4SolidMask::Put ( bool  fCauseInstability,
C4TargetRect pClipRect,
bool  fRestoreAttachment 
)

Definition at line 33 of file C4SolidMask.cpp.

References C4Landscape::_GetPix(), CSurface8::Bits, CheckConsistency(), C4TargetRect::ClipBy(), C4Shape::ContactCheck(), C4Object::Contained, Cos(), C4Object::Def, Fix0, fixtoi(), C4Game::FrameCounter, Game, C4Object::GetFixedX(), C4Object::GetFixedY(), C4Landscape::GetHeight(), C4Landscape::GetPix(), C4Object::GetR(), C4Object::GetSolidMaskPlane(), C4Landscape::GetWidth(), C4Object::GetX(), C4Object::GetY(), C4Rect::Hgt, iAttachingObjectsCount, C4Object::iLastAttachMovementFrame, C4Object::IsMoveableBySolidMask(), IsSomeVehicle(), itofix(), Landscape, MaskMaterial, MaskPut, MaskPutRect, MaskPutRotation, MaskRemovalX, MaskRemovalY, MatBuffPitch, MCVehic, C4Object::MovePosition(), pForObject, CSurface8::Pitch, ppAttachingObjects, C4Def::pSolidMask, pSolidMaskMatBuff, C4Landscape::SetPix2(), C4Def::Shape, C4Object::Shape, Sin(), C4Object::SolidMask, C4Landscape::Transparent, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by C4Object::UpdateSolidMask().

34 {
35  // If not put, put mask to background,
36  // storing background pixels in cSolidMask.
37 
38  // No mask
40  // Contained
41  if (pForObject->Contained) { iAttachingObjectsCount = 0; return; }
42  // Mask is put
43  if (fCauseInstability) CheckConsistency();
44 
45  bool RegularPut;
46  if (!pClipRect)
47  {
48  // Regular Put: Update MaskPutRect and MaskPutRotation
50  pClipRect = &MaskPutRect;
51  RegularPut = true;
52  }
53  else
54  {
55  // Reput by C4SolidMask::Remove
56  // Don't change MaskPutRotation or MaskPutRect
57  // Intersect ClipRect with the MaskPutRect
58  if (!pClipRect->ClipBy(MaskPutRect)) return;
59  RegularPut = false;
60  }
61  // Get mask surface
62  CSurface8 *pSolidMask = pForObject->Def->pSolidMask;
63  // Put mask pixels
64  int xcnt,ycnt,iTx,iTy;
65  BYTE byPixel;
66  // not rotated?
67  if (!MaskPutRotation)
68  {
69  // calc put rect
70  if (RegularPut)
71  {
72  int ox, oy;
75  MaskPutRect.x = ox;
76  if (MaskPutRect.x < 0) { MaskPutRect.tx = -MaskPutRect.x; MaskPutRect.x = 0; }
77  else MaskPutRect.tx = 0;
78  MaskPutRect.y = oy;
79  if (MaskPutRect.y < 0) { MaskPutRect.ty = -MaskPutRect.y; MaskPutRect.y = 0; }
80  else MaskPutRect.ty = 0;
81  MaskPutRect.Wdt = std::min<int32_t>(ox + pForObject->SolidMask.Wdt, ::Landscape.GetWidth()) - MaskPutRect.x;
82  MaskPutRect.Hgt = std::min<int32_t>(oy + pForObject->SolidMask.Hgt, ::Landscape.GetHeight()) - MaskPutRect.y;
83  }
84  // fill rect with mask
85  for (ycnt=0; ycnt<pClipRect->Hgt; ++ycnt)
86  {
87  BYTE *pPix=pSolidMask->Bits + (ycnt+pClipRect->ty+pForObject->SolidMask.y)*pSolidMask->Pitch + pClipRect->tx + pForObject->SolidMask.x;
88  for (xcnt=0; xcnt<pClipRect->Wdt; ++xcnt,++pPix)
89  {
90  if (*pPix)
91  {
92  // solid mask present here
93  // calc position in landscape
94  iTx=pClipRect->x+xcnt; iTy=pClipRect->y+ycnt;
95  // is background mat to be stored? always do this in the given rect
96  if (!MaskPut)
97  {
98  // get background pixel
99  byPixel=::Landscape.GetPix(iTx,iTy);
100  // store it. If MCVehic, also store in initial put, but won't be used in restore
101  // do not overwrite current value in re-put issued by SolidMask-remover
102  if (!IsSomeVehicle(byPixel) || RegularPut)
103  pSolidMaskMatBuff[(ycnt+pClipRect->ty)*MatBuffPitch+xcnt+pClipRect->tx]=byPixel;
104  }
105  // and set mask
107  }
108  else
109  // no SolidMask: mark buffer as unused here
110  if (!MaskPut)
111  pSolidMaskMatBuff[(ycnt+pClipRect->ty)*MatBuffPitch+xcnt+pClipRect->tx]=MCVehic;
112  }
113  }
114  }
115  else
116  {
117  // calc matrix for given rotation
119  Mb1 = Sin(itofix(-MaskPutRotation)), Mb2 = Cos(itofix(-MaskPutRotation));
120  // get upper-left corner of landscape copy rect
121  int centerx = pForObject->Def->Shape.x + pForObject->SolidMask.tx + pForObject->SolidMask.Wdt / 2;
122  int centery = pForObject->Def->Shape.y + pForObject->SolidMask.ty + pForObject->SolidMask.Hgt / 2;
123  int xstart = pForObject->GetX() + fixtoi(Ma1 * itofix(centerx) - Ma2 * itofix(centery)) - MatBuffPitch / 2;
124  int ystart = pForObject->GetY() + fixtoi(-Mb1 * itofix(centerx) + Mb2 * itofix(centery)) - MatBuffPitch / 2;
125  // store put rect
126  if (RegularPut)
127  {
128  MaskPutRect.x = xstart;
130  else { MaskPutRect.tx = 0; MaskPutRect.Wdt = 0; }
131  MaskPutRect.y = ystart;
133  else { MaskPutRect.ty = 0; MaskPutRect.Hgt = 0; }
134  MaskPutRect.Wdt = std::min<int32_t>(xstart + MatBuffPitch, ::Landscape.GetWidth()) - MaskPutRect.x;
135  MaskPutRect.Hgt = std::min<int32_t>(ystart + MatBuffPitch, ::Landscape.GetHeight()) - MaskPutRect.y;
136  }
137  // go through clipping rect
138  const C4Real y0 = itofix(pClipRect->ty - MatBuffPitch/2);
139  const C4Real x0 = itofix(pClipRect->tx - MatBuffPitch/2);
140  iTy=pClipRect->y;
141  int32_t w = pForObject->SolidMask.Wdt;
142  int32_t h = pForObject->SolidMask.Hgt;
143  int32_t mx0 = pForObject->SolidMask.x;
144  int32_t my0 = pForObject->SolidMask.y;
145  C4Real ya = y0 * Ma2;
146  C4Real yb = y0 * Mb2;
147  for (ycnt = 0; ycnt < pClipRect->Hgt; ycnt++)
148  {
149  iTx=pClipRect->x;
150  int i = (ycnt + pClipRect->ty) * MatBuffPitch + pClipRect->tx;
151  C4Real xa = x0 * Ma1;
152  C4Real xb = x0 * Mb1;
153  for (xcnt = 0; xcnt < pClipRect->Wdt; xcnt++)
154  {
155  // calc position in solidmask buffer
156  int32_t iMx = fixtoi(xa + ya) + w / 2;
157  int32_t iMy = fixtoi(xb + yb) + h / 2;
158  // in bounds? and solidmask?
159  if (iMx >= 0 && iMy >= 0 && iMx < w && iMy < h && pSolidMask->_GetPix(iMx+mx0, iMy+my0))
160  {
161  // is background mat to be stored?
162  if (!MaskPut)
163  {
164  // get background pixel
165  byPixel=::Landscape._GetPix(iTx,iTy);
166  // store it. If MCVehic, also store in initial put, but won't be used in restore
167  // do not overwrite current value in re-put issued by SolidMask-remover
168  if (!IsSomeVehicle(byPixel) || RegularPut)
169  pSolidMaskMatBuff[i + xcnt] = byPixel;
170  }
171  // set mask pix
173  }
174  else if (!MaskPut)
175  // mark pix as unused in buf
176  pSolidMaskMatBuff[i+xcnt] = MCVehic;
177  xa += Ma1; xb += Mb1;
178  ++iTx;
179  }
180  ya += Ma2; yb += Mb2;
181  ++iTy;
182  }
183  }
184  // Store mask put status
185  MaskPut=true;
186  // restore attached object positions if moved
187  if (fRestoreAttachment && iAttachingObjectsCount)
188  {
190  int32_t dy = pForObject->GetY() - MaskRemovalY;
191  if (dx != Fix0 || dy != 0)
192  for (int i = 0; i < iAttachingObjectsCount; ++i)
193  {
194  C4Object *pObj = ppAttachingObjects[i];
196  if (!pObj->Shape.ContactCheck(fixtoi(pObj->GetFixedX()+dx), fixtoi(pObj->GetFixedY()+dy)))
198  {
200  pObj->MovePosition(dx, itofix(dy));
201  }
202  }
203  iAttachingObjectsCount = 0;
204  }
205 
206  if (fCauseInstability) CheckConsistency();
207 }
int32_t GetY() const
Definition: C4Object.h:287
BYTE _GetPix(int32_t x, int32_t y) const
C4Real GetFixedY() const
Definition: C4Object.h:290
int MaskPutRotation
Definition: C4SolidMask.h:29
int MatBuffPitch
Definition: C4SolidMask.h:30
void MovePosition(int32_t dx, int32_t dy)
Definition: C4Movement.cpp:523
static bool CheckConsistency()
C4Game Game
Definition: C4Globals.cpp:52
CSurface8 * pSolidMask
Definition: C4Def.h:195
BYTE * Bits
Definition: CSurface8.h:30
int iAttachingObjectsCount
Definition: C4SolidMask.h:38
C4Object * pForObject
Definition: C4SolidMask.h:46
uint8_t BYTE
C4TargetRect MaskPutRect
Definition: C4SolidMask.h:40
Definition: C4Real.h:58
int32_t Wdt
Definition: C4Rect.h:32
int32_t FrameCounter
Definition: C4Game.h:130
C4Shape Shape
Definition: C4Def.h:106
C4Def * Def
Definition: C4Object.h:143
int32_t y
Definition: C4Rect.h:32
int Pitch
Definition: CSurface8.h:28
int32_t GetR() const
Definition: C4Object.h:288
C4Landscape Landscape
bool ClipBy(C4TargetRect &rClip)
Definition: C4Rect.cpp:51
BYTE MCVehic
Definition: C4Material.cpp:38
C4Real GetFixedX() const
Definition: C4Object.h:289
int32_t GetX() const
Definition: C4Object.h:286
int32_t tx
Definition: C4Rect.h:81
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
BYTE GetPix(int32_t x, int32_t y) const
int32_t ty
Definition: C4Rect.h:81
bool IsMoveableBySolidMask(int ComparisonPlane) const
Definition: C4Object.cpp:4801
class C4Object ** ppAttachingObjects
Definition: C4SolidMask.h:37
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
int32_t x
Definition: C4Rect.h:32
int32_t GetHeight() const
int32_t GetSolidMaskPlane() const
Definition: C4Object.cpp:4902
C4Real MaskRemovalX
Definition: C4SolidMask.h:34
int32_t iLastAttachMovementFrame
Definition: C4Object.h:127
C4ObjectPtr Contained
Definition: C4Object.h:144
int32_t Hgt
Definition: C4Rect.h:32
bool IsSomeVehicle(BYTE mat)
Definition: C4Material.h:228
C4Real Sin(const C4Real &fAngle)
Definition: C4Real.h:265
C4Shape Shape
Definition: C4Object.h:148
bool MaskPut
Definition: C4SolidMask.h:28
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
C4TargetRect SolidMask
Definition: C4Object.h:150
static const uint8_t Transparent
Definition: C4Landscape.h:51
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Real Cos(const C4Real &fAngle)
Definition: C4Real.h:266
BYTE MaskMaterial
Definition: C4SolidMask.h:44
int32_t GetWidth() const
const C4Real Fix0
Definition: C4Real.h:312
int32_t MaskRemovalY
Definition: C4SolidMask.h:35
bool ContactCheck(int32_t cx, int32_t cy, uint32_t *border_hack_contacts=0, bool collide_halfvehic=false)
Definition: C4Shape.cpp:352

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::PutSolidMasks ( )
static

Definition at line 454 of file C4SolidMask.cpp.

References First, C4Landscape::GetHeight(), C4Landscape::GetWidth(), Landscape, Next, and PutTemporary().

Referenced by C4Game::ReloadDef(), C4Landscape::Save(), and C4Landscape::SaveDiff().

455 {
456  C4Rect SolidMaskRect(0,0,::Landscape.GetWidth(),::Landscape.GetHeight());
457  C4SolidMask *pSolid;
458  // Restore Solidmasks
459  for (pSolid = C4SolidMask::First; pSolid; pSolid = pSolid->Next)
460  {
461  pSolid->PutTemporary(SolidMaskRect);
462  }
463 }
void PutTemporary(C4Rect where)
Definition: C4Rect.h:29
C4Landscape Landscape
int32_t GetHeight() const
static C4SolidMask * First
Definition: C4SolidMask.h:72
int32_t GetWidth() const
C4SolidMask * Next
Definition: C4SolidMask.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::PutTemporary ( C4Rect  where)
protected

Definition at line 366 of file C4SolidMask.cpp.

References C4Landscape::_SetPix2Tmp(), C4Landscape::GetPix(), C4Rect::Hgt, C4Rect::Intersect(), Landscape, MaskMaterial, MaskPut, MaskPutRect, MatBuffPitch, MCVehic, pSolidMaskMatBuff, C4Landscape::Transparent, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by C4Landscape::DoRelights(), and PutSolidMasks().

367 {
368  if (!MaskPut || !pSolidMaskMatBuff) return;
369  where.Intersect(MaskPutRect);
370  // reput vehicle pixels
371  for (int y = where.y; y < where.y + where.Hgt; ++y)
372  {
373  for (int x = where.x; x < where.x + where.Wdt; ++x)
374  {
376  // only if mask was used here
377  if (*pPix != MCVehic)
378  {
379  // put
380  assert(::Landscape.GetPix(x,y)==*pPix);
382  }
383  }
384  }
385 }
int MatBuffPitch
Definition: C4SolidMask.h:30
void _SetPix2Tmp(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
uint8_t BYTE
C4TargetRect MaskPutRect
Definition: C4SolidMask.h:40
void Intersect(const C4Rect &r2)
Definition: C4Rect.cpp:100
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
C4Landscape Landscape
BYTE MCVehic
Definition: C4Material.cpp:38
int32_t tx
Definition: C4Rect.h:81
BYTE GetPix(int32_t x, int32_t y) const
int32_t ty
Definition: C4Rect.h:81
int32_t x
Definition: C4Rect.h:32
int32_t Hgt
Definition: C4Rect.h:32
bool MaskPut
Definition: C4SolidMask.h:28
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
static const uint8_t Transparent
Definition: C4Landscape.h:51
BYTE MaskMaterial
Definition: C4SolidMask.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::Remove ( bool  fBackupAttachment)

Definition at line 242 of file C4SolidMask.cpp.

References C4Landscape::_GetPix(), C4Landscape::_SetPix2(), CheckConsistency(), C4Landscape::CheckInstabilityRange(), CNAT_Bottom, DensityProvider, C4LArea::FirstObjectShapes(), C4Object::GetFixedX(), C4Object::GetSolidMaskPlane(), C4Object::GetY(), C4Rect::Hgt, iAttachingObjectsCapacity, iAttachingObjectsCount, C4Object::IsMoveableBySolidMask(), IsSomeVehicle(), Landscape, Last, MaskPut, MaskPutRect, MaskRemovalX, MaskRemovalY, MatBuffPitch, MCVehic, C4LArea::NextObjectShapes(), Objects, pForObject, ppAttachingObjects, Prev, pSolidMaskMatBuff, C4GameObjects::Sectors, C4TargetRect::Set(), C4Landscape::Transparent, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by C4Object::DoMotion(), C4Object::DoMovement(), C4Object::MovePosition(), C4Object::SetRotation(), C4Object::UpdateSolidMask(), and ~C4SolidMask().

243 {
244  // If put, restore background pixels from buffer
245 
246  // Not put
247  if (!MaskPut || !pSolidMaskMatBuff) return;
248 
250 
251  // reput background pixels
252  for (int ycnt=0; ycnt<MaskPutRect.Hgt; ++ycnt)
253  {
255  for (int xcnt=0; xcnt<MaskPutRect.Wdt; ++xcnt,++pPix)
256  // only if mask was used here
257  if (*pPix != MCVehic)
258  {
259  // calc position in landscape
260  int iTx=MaskPutRect.x+xcnt; int iTy=MaskPutRect.y+ycnt;
261  // restore pixel here
262  // The pPix-check ensures that only pixels that hads been overwritten by this SolidMask are restored
263  // Non-SolidMask-pixels should not happen here, because all relevant landscape change routines should
264  // temp remove SolidMasks before
265  assert(IsSomeVehicle(::Landscape._GetPix(iTx,iTy)));
266  if (IsSomeVehicle(::Landscape._GetPix(iTx, iTy)))
267  ::Landscape._SetPix2(iTx, iTy, *pPix, ::Landscape.Transparent);
268  // Instability
270  }
271  }
272  // Mask not put flag
273  MaskPut=false;
274  // update surrounding masks in that range
275  C4TargetRect ClipRect;
276  for (C4SolidMask *pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
277  if (pSolid->MaskPut) if (pSolid->MaskPutRect.Overlap(MaskPutRect))
278  {
279  // set clipping rect for all calls, since they may modify it
281  // doubled solidmask-pixels have just been removed in the clipped area!
282  pSolid->MaskPut = false;
283  // re-put the solidmask
284  pSolid->Put(false, &ClipRect, false);
285  }
286 
287  // backup attachment if desired: Backup old pos and all objects that attach to or lie on the SolidMask
288  if (fBackupAttachment)
289  {
293  // Search in area slightly larger than SolidMask because objects might have vertices slightly outside their shape
295  C4LSector *pSct;
296  for (C4ObjectList *pLst=SolidArea.FirstObjectShapes(&pSct); pLst; pLst=SolidArea.NextObjectShapes(pLst, &pSct))
297  for (C4Object *pObj : *pLst)
298  if (pObj && pObj != pForObject && pObj->IsMoveableBySolidMask(pForObject->GetSolidMaskPlane()) && !pObj->Shape.CheckContact(pObj->GetX(),pObj->GetY()))
299  {
300  // avoid duplicate that may be found due to sector overlaps
301  bool has_dup = false;
302  for (int32_t i_dup = 0; i_dup < iAttachingObjectsCount; ++i_dup)
303  if (ppAttachingObjects[i_dup] == pObj)
304  {
305  has_dup = true;
306  break;
307  }
308  if (has_dup) continue;
309  // check for any contact to own SolidMask - attach-directions, bottom - "stuck" (CNAT_Center) is ignored, because that causes problems with things being stuck in basements :(
310  int iVtx = 0;
311  for (; iVtx < pObj->Shape.VtxNum; ++iVtx)
312  if (pObj->Shape.GetVertexContact(iVtx, pObj->Action.t_attach | CNAT_Bottom, pObj->GetX(), pObj->GetY(), DensityProvider(pForObject, *this)))
313  break;
314  if (iVtx == pObj->Shape.VtxNum) continue; // no contact
315  // contact: Add object to list
316  if (iAttachingObjectsCapacity == iAttachingObjectsCount)
317  {
319  C4Object **ppNewAttachingObjects = new C4Object *[iAttachingObjectsCapacity];
320  if (iAttachingObjectsCount) memcpy(ppNewAttachingObjects, ppAttachingObjects, sizeof(C4Object *) * iAttachingObjectsCount);
321  delete [] ppAttachingObjects;
322  ppAttachingObjects = ppNewAttachingObjects;
323  }
324  ppAttachingObjects[iAttachingObjectsCount++] = pObj;
325  }
326  }
327 
329 }
int32_t GetY() const
Definition: C4Object.h:287
BYTE _GetPix(int32_t x, int32_t y) const
int MatBuffPitch
Definition: C4SolidMask.h:30
static bool CheckConsistency()
int iAttachingObjectsCapacity
Definition: C4SolidMask.h:38
int iAttachingObjectsCount
Definition: C4SolidMask.h:38
C4Object * pForObject
Definition: C4SolidMask.h:46
uint8_t BYTE
C4TargetRect MaskPutRect
Definition: C4SolidMask.h:40
friend class DensityProvider
Definition: C4SolidMask.h:68
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
C4Landscape Landscape
void CheckInstabilityRange(int32_t tx, int32_t ty)
BYTE MCVehic
Definition: C4Material.cpp:38
C4Real GetFixedX() const
Definition: C4Object.h:289
int32_t tx
Definition: C4Rect.h:81
int32_t ty
Definition: C4Rect.h:81
bool IsMoveableBySolidMask(int ComparisonPlane) const
Definition: C4Object.cpp:4801
class C4Object ** ppAttachingObjects
Definition: C4SolidMask.h:37
C4LSectors Sectors
Definition: C4GameObjects.h:42
int32_t x
Definition: C4Rect.h:32
int32_t GetSolidMaskPlane() const
Definition: C4Object.cpp:4902
C4Real MaskRemovalX
Definition: C4SolidMask.h:34
int32_t Hgt
Definition: C4Rect.h:32
bool IsSomeVehicle(BYTE mat)
Definition: C4Material.h:228
bool MaskPut
Definition: C4SolidMask.h:28
void Set(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iTX, int32_t iTY)
Definition: C4Rect.cpp:45
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
C4SolidMask * Prev
Definition: C4SolidMask.h:74
static const uint8_t Transparent
Definition: C4Landscape.h:51
static C4SolidMask * Last
Definition: C4SolidMask.h:73
const BYTE CNAT_Bottom
Definition: C4Constants.h:113
C4GameObjects Objects
Definition: C4Globals.cpp:48
bool _SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
int32_t MaskRemovalY
Definition: C4SolidMask.h:35

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::RemoveSolidMasks ( )
static

Definition at line 444 of file C4SolidMask.cpp.

References C4Landscape::GetHeight(), C4Landscape::GetWidth(), Landscape, Last, Prev, and RemoveTemporary().

Referenced by C4Game::ReloadDef(), C4Landscape::Save(), and C4Landscape::SaveDiff().

445 {
446  C4Rect SolidMaskRect(0,0,::Landscape.GetWidth(),::Landscape.GetHeight());
447  C4SolidMask *pSolid;
448  for (pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
449  {
450  pSolid->RemoveTemporary(SolidMaskRect);
451  }
452 }
Definition: C4Rect.h:29
void RemoveTemporary(C4Rect where)
C4Landscape Landscape
int32_t GetHeight() const
C4SolidMask * Prev
Definition: C4SolidMask.h:74
static C4SolidMask * Last
Definition: C4SolidMask.h:73
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::RemoveTemporary ( C4Rect  where)
protected

Definition at line 345 of file C4SolidMask.cpp.

References C4Landscape::_SetPix2Tmp(), C4Landscape::GetPix(), C4Rect::Hgt, C4Rect::Intersect(), IsSomeVehicle(), Landscape, MaskPut, MaskPutRect, MatBuffPitch, MCVehic, pSolidMaskMatBuff, C4Landscape::Transparent, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by CheckConsistency(), C4Landscape::DoRelights(), and RemoveSolidMasks().

346 {
347  if (!MaskPut || !pSolidMaskMatBuff) return;
348  where.Intersect(MaskPutRect);
349  // reput background pixels
350  for (int y = where.y; y < where.y + where.Hgt; ++y)
351  {
352  for (int x = where.x; x < where.x + where.Wdt; ++x)
353  {
355  // only if mask was used here
356  if (*pPix != MCVehic) //
357  {
358  // restore
359  assert(IsSomeVehicle(::Landscape.GetPix(x,y)));
361  }
362  }
363  }
364 }
int MatBuffPitch
Definition: C4SolidMask.h:30
void _SetPix2Tmp(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
uint8_t BYTE
C4TargetRect MaskPutRect
Definition: C4SolidMask.h:40
void Intersect(const C4Rect &r2)
Definition: C4Rect.cpp:100
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
C4Landscape Landscape
BYTE MCVehic
Definition: C4Material.cpp:38
int32_t tx
Definition: C4Rect.h:81
BYTE GetPix(int32_t x, int32_t y) const
int32_t ty
Definition: C4Rect.h:81
int32_t x
Definition: C4Rect.h:32
int32_t Hgt
Definition: C4Rect.h:32
bool IsSomeVehicle(BYTE mat)
Definition: C4Material.h:228
bool MaskPut
Definition: C4SolidMask.h:28
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
static const uint8_t Transparent
Definition: C4Landscape.h:51

Here is the call graph for this function:

Here is the caller graph for this function:

void C4SolidMask::Repair ( C4Rect  where)
protected

Definition at line 387 of file C4SolidMask.cpp.

References C4Landscape::GetPix(), C4Rect::Hgt, C4Rect::Intersect(), Landscape, MaskMaterial, MaskPut, MaskPutRect, MatBuffPitch, MCVehic, pSolidMaskMatBuff, C4Landscape::SetPix2(), C4Landscape::Transparent, C4TargetRect::tx, C4TargetRect::ty, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

388 {
389  if (!MaskPut || !pSolidMaskMatBuff) return;
390  where.Intersect(MaskPutRect);
391  // reput vehicle pixels
392  for (int y = where.y; y < where.y + where.Hgt; ++y)
393  {
394  for (int x = where.x; x < where.x + where.Wdt; ++x)
395  {
397  // only if mask was used here
398  if (*pPix != MCVehic)
399  {
400  // record changed landscape in MatBuff
401  *pPix = ::Landscape.GetPix(x,y);
402  // put
404  }
405  }
406  }
407 }
int MatBuffPitch
Definition: C4SolidMask.h:30
uint8_t BYTE
C4TargetRect MaskPutRect
Definition: C4SolidMask.h:40
void Intersect(const C4Rect &r2)
Definition: C4Rect.cpp:100
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
C4Landscape Landscape
BYTE MCVehic
Definition: C4Material.cpp:38
int32_t tx
Definition: C4Rect.h:81
BYTE GetPix(int32_t x, int32_t y) const
int32_t ty
Definition: C4Rect.h:81
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
int32_t x
Definition: C4Rect.h:32
int32_t Hgt
Definition: C4Rect.h:32
bool MaskPut
Definition: C4SolidMask.h:28
BYTE * pSolidMaskMatBuff
Definition: C4SolidMask.h:42
static const uint8_t Transparent
Definition: C4Landscape.h:51
BYTE MaskMaterial
Definition: C4SolidMask.h:44

Here is the call graph for this function:

void C4SolidMask::SetHalfVehicle ( bool  set)

Definition at line 504 of file C4SolidMask.cpp.

References MaskMaterial, MCHalfVehic, and MCVehic.

Referenced by C4Object::SetHalfVehicleSolidMask().

505 {
506  MaskMaterial = set ? MCHalfVehic : MCVehic;
507  // TODO: Redraw
508 }
BYTE MCHalfVehic
Definition: C4Material.cpp:39
BYTE MCVehic
Definition: C4Material.cpp:38
BYTE MaskMaterial
Definition: C4SolidMask.h:44

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Landscape
friend

Definition at line 67 of file C4SolidMask.h.

friend class DensityProvider
friend

Definition at line 68 of file C4SolidMask.h.

Referenced by Remove().

Member Data Documentation

C4SolidMask * C4SolidMask::First = 0
static
int C4SolidMask::iAttachingObjectsCapacity
protected

Definition at line 38 of file C4SolidMask.h.

Referenced by C4SolidMask(), and Remove().

int C4SolidMask::iAttachingObjectsCount
protected

Definition at line 38 of file C4SolidMask.h.

Referenced by C4SolidMask(), Put(), and Remove().

C4SolidMask * C4SolidMask::Last = 0
static
BYTE C4SolidMask::MaskMaterial
protected

Definition at line 44 of file C4SolidMask.h.

Referenced by C4SolidMask(), Put(), PutTemporary(), Repair(), and SetHalfVehicle().

bool C4SolidMask::MaskPut
protected

Definition at line 28 of file C4SolidMask.h.

Referenced by C4SolidMask(), Draw(), IsPut(), Put(), PutTemporary(), Remove(), RemoveTemporary(), and Repair().

C4TargetRect C4SolidMask::MaskPutRect
protected
int C4SolidMask::MaskPutRotation
protected

Definition at line 29 of file C4SolidMask.h.

Referenced by C4SolidMask(), Draw(), C4SolidMask::DensityProvider::GetDensity(), and Put().

C4Real C4SolidMask::MaskRemovalX
protected

Definition at line 34 of file C4SolidMask.h.

Referenced by C4SolidMask(), Put(), and Remove().

int32_t C4SolidMask::MaskRemovalY
protected

Definition at line 35 of file C4SolidMask.h.

Referenced by C4SolidMask(), Put(), and Remove().

int C4SolidMask::MatBuffPitch
protected
C4Object* C4SolidMask::pForObject
protected

Definition at line 46 of file C4SolidMask.h.

Referenced by Draw(), C4SolidMask::DensityProvider::GetDensity(), Put(), and Remove().

class C4Object** C4SolidMask::ppAttachingObjects
protected

Definition at line 37 of file C4SolidMask.h.

Referenced by C4SolidMask(), Put(), Remove(), and ~C4SolidMask().

BYTE* C4SolidMask::pSolidMaskMatBuff
protected

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