OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
landscape-handle.cpp
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include "C4Include.h"
17 #include <array>
18 
19 #include "graphics/CSurface8.h"
20 #include "landscape/C4Landscape.h"
21 #include "landscape/C4Texture.h"
22 
23 /* This is a small part of the implementation of C4Landscape for what is
24  * required by mape. We cannot link the full implementation since it would
25  * introduce a dependency on C4Game, and therefore the rest of the engine. */
26 
27 struct C4Landscape::P
28 {
31  mutable std::array<std::unique_ptr<uint8_t[]>, C4M_MaxTexIndex> BridgeMatConversion;
32  int32_t Width = 0, Height = 0;
33  std::unique_ptr<CSurface8> Surface8;
34 };
35 
36 C4Landscape::C4Landscape() : p(new P) {}
38 bool C4Landscape::FindMatSlide(int&, int&, int, int, int) const { return false; }
39 int32_t C4Landscape::ExtractMaterial(int32_t, int32_t, bool) { return 0; }
40 bool C4Landscape::InsertMaterial(int32_t, int32_t *, int32_t *, int32_t, int32_t, bool) { return false; }
41 bool C4Landscape::Incinerate(int32_t, int32_t, int32_t) { return false; }
42 bool C4Landscape::ClearPix(int32_t, int32_t) { return false; }
43 void C4Landscape::CheckInstabilityRange(int32_t, int32_t) {}
44 
45 int32_t C4Landscape::GetDensity(int32_t x, int32_t y) const { return p->Pix2Dens[GetPix(x, y)]; }
46 int32_t C4Landscape::GetPixDensity(BYTE byPix) const { return p->Pix2Dens[byPix]; }
47 C4Real C4Landscape::GetGravity() const { return C4REAL100(20); }
48 int32_t C4Landscape::GetMat(int32_t x, int32_t y) const { return p->Pix2Mat[GetPix(x, y)]; }
49 
50 BYTE C4Landscape::GetPix(int32_t x, int32_t y) const // get landscape pixel (bounds checked)
51 {
52  extern BYTE MCVehic;
53  // Border checks
54  if (x < 0 || x >= p->Width) return MCVehic;
55  if (y < 0 || y >= p->Height) return MCVehic;
56  return p->Surface8->_GetPix(x, y);
57 }
58 
59 int32_t PixCol2Mat(BYTE pixc)
60 {
61  // Get texture
62  int32_t iTex = PixCol2Tex(pixc);
63  if (!iTex) return MNone;
64  // Get material-texture mapping
65  const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
66  // Return material
67  return pTex ? pTex->GetMaterialIndex() : MNone;
68 }
69 
71 {
72  UpdatePixMaps();
73 }
74 
75 void C4Landscape::UpdatePixMaps() // Copied from C4Landscape.cpp
76 {
77  int32_t i;
78  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Mat[i] = PixCol2Mat(i);
79  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Dens[i] = MatDensity(p->Pix2Mat[i]);
80  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Place[i] = MatValid(p->Pix2Mat[i]) ? ::MaterialMap.Map[p->Pix2Mat[i]].Placement : 0;
81  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Light[i] = MatValid(p->Pix2Mat[i]) && (::MaterialMap.Map[p->Pix2Mat[i]].Light>0);
82  p->Pix2Place[0] = 0;
83  // clear bridge mat conversion buffers
84  std::fill(p->BridgeMatConversion.begin(), p->BridgeMatConversion.end(), nullptr);
85 }
int32_t GetMaterialIndex() const
Definition: C4Texture.h:62
std::unique_ptr< CSurface8 > Surface8
Definition: C4Landscape.cpp:54
bool Incinerate(int32_t x, int32_t y, int32_t cause_player)
int32_t Pix2Dens[C4M_MaxTexIndex]
Definition: C4Landscape.cpp:60
int32_t Pix2Place[C4M_MaxTexIndex]
Definition: C4Landscape.cpp:60
void HandleTexMapUpdate()
C4Material * Map
Definition: C4Material.h:169
C4Real C4REAL100(int x)
Definition: C4Real.h:267
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
Definition: C4Texture.h:48
int32_t PixCol2Mat(BYTE pixc)
Definition: C4Real.h:58
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
const int32_t MNone
Definition: C4Constants.h:178
int32_t GetDensity(int32_t x, int32_t y) const
int32_t Light
Definition: C4Material.h:113
void CheckInstabilityRange(int32_t tx, int32_t ty)
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
BYTE MCVehic
Definition: C4Material.cpp:37
void UpdatePixMaps()
BYTE GetPix(int32_t x, int32_t y) const
C4Real GetGravity() const
int32_t GetMat(int32_t x, int32_t y) const
bool FindMatSlide(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
int32_t ExtractMaterial(int32_t fx, int32_t fy, bool distant_first)
int32_t GetPixDensity(BYTE byPix) const
bool Pix2Light[C4M_MaxTexIndex]
Definition: C4Landscape.cpp:61
int32_t Placement
Definition: C4Material.h:112
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
bool ClearPix(int32_t tx, int32_t ty)
std::array< std::unique_ptr< uint8_t[]>, C4M_MaxTexIndex > BridgeMatConversion
Definition: C4Landscape.cpp:65
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t Pix2Mat[C4M_MaxTexIndex]
Definition: C4Landscape.cpp:60
int32_t PixCol2Tex(BYTE pixc)
Definition: C4Landscape.h:213