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 {
29 int32_t Pix2Mat[C4M_MaxTexIndex], Pix2Dens[C4M_MaxTexIndex], Pix2Place[C4M_MaxTexIndex];
30 bool Pix2Light[C4M_MaxTexIndex];
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
C4Landscape()36 C4Landscape::C4Landscape() : p(new P) {}
~C4Landscape()37 C4Landscape::~C4Landscape() {}
FindMatSlide(int &,int &,int,int,int) const38 bool C4Landscape::FindMatSlide(int&, int&, int, int, int) const { return false; }
ExtractMaterial(int32_t,int32_t,bool)39 int32_t C4Landscape::ExtractMaterial(int32_t, int32_t, bool) { return 0; }
InsertMaterial(int32_t,int32_t *,int32_t *,int32_t,int32_t,bool)40 bool C4Landscape::InsertMaterial(int32_t, int32_t *, int32_t *, int32_t, int32_t, bool) { return false; }
Incinerate(int32_t,int32_t,int32_t)41 bool C4Landscape::Incinerate(int32_t, int32_t, int32_t) { return false; }
ClearPix(int32_t,int32_t)42 bool C4Landscape::ClearPix(int32_t, int32_t) { return false; }
CheckInstabilityRange(int32_t,int32_t)43 void C4Landscape::CheckInstabilityRange(int32_t, int32_t) {}
44
GetDensity(int32_t x,int32_t y) const45 int32_t C4Landscape::GetDensity(int32_t x, int32_t y) const { return p->Pix2Dens[GetPix(x, y)]; }
GetPixDensity(BYTE byPix) const46 int32_t C4Landscape::GetPixDensity(BYTE byPix) const { return p->Pix2Dens[byPix]; }
GetGravity() const47 C4Real C4Landscape::GetGravity() const { return C4REAL100(20); }
GetMat(int32_t x,int32_t y) const48 int32_t C4Landscape::GetMat(int32_t x, int32_t y) const { return p->Pix2Mat[GetPix(x, y)]; }
49
GetPix(int32_t x,int32_t y) const50 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
PixCol2Mat(BYTE pixc)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
HandleTexMapUpdate()70 void C4Landscape::HandleTexMapUpdate()
71 {
72 UpdatePixMaps();
73 }
74
UpdatePixMaps()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 }
86