Skip to content

Commit ce955f3

Browse files
committedJul 8, 2013
Decoration: Handle facedir and wallmounted param2types with schematic rotation
1 parent c813a3c commit ce955f3

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed
 

‎src/mapgen.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ Decoration::~Decoration() {
237237

238238

239239
void Decoration::resolveNodeNames(INodeDefManager *ndef) {
240+
this->ndef = ndef;
241+
240242
if (c_place_on == CONTENT_IGNORE)
241243
c_place_on = ndef->getId(place_on_name);
242244
}
@@ -553,7 +555,7 @@ std::string DecoSchematic::getName() {
553555

554556

555557
void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
556-
int rot, bool force_placement) {
558+
Rotation rot, bool force_placement) {
557559
int xstride = 1;
558560
int ystride = size.X;
559561
int zstride = size.X * size.Y;
@@ -594,7 +596,7 @@ void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
594596
u32 vi = vm->m_area.index(p.X + x, p.Y + y, p.Z + z);
595597
if (!vm->m_area.contains(vi))
596598
continue;
597-
599+
598600
if (schematic[i].getContent() == CONTENT_IGNORE)
599601
continue;
600602

@@ -609,6 +611,9 @@ void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
609611

610612
vm->m_data[vi] = schematic[i];
611613
vm->m_data[vi].param1 = 0;
614+
615+
if (rot)
616+
vm->m_data[vi].rotateAlongYAxis(ndef, rot);
612617
}
613618
}
614619
}

‎src/mapgen.h

+4-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "irrlichttypes_extrabloated.h"
2424
#include "util/container.h" // UniqueQueue
2525
#include "gamedef.h"
26+
#include "nodedef.h"
2627
#include "mapnode.h"
2728
#include "noise.h"
2829
#include "settings.h"
@@ -63,7 +64,6 @@ class EmergeManager;
6364
class MapBlock;
6465
class ManualMapVoxelManipulator;
6566
class VoxelManipulator;
66-
class INodeDefManager;
6767
struct BlockMakeData;
6868
class VoxelArea;
6969
class Map;
@@ -216,6 +216,8 @@ struct CutoffData {
216216

217217
class Decoration {
218218
public:
219+
INodeDefManager *ndef;
220+
219221
int mapseed;
220222
std::string place_on_name;
221223
content_t c_place_on;
@@ -262,14 +264,6 @@ class DecoSimple : public Decoration {
262264

263265
#define MTSCHEM_FILE_SIGNATURE 0x4d54534d // 'MTSM'
264266

265-
enum Rotation {
266-
ROTATE_0,
267-
ROTATE_90,
268-
ROTATE_180,
269-
ROTATE_270,
270-
ROTATE_RAND,
271-
};
272-
273267
class DecoSchematic : public Decoration {
274268
public:
275269
std::string filename;
@@ -291,7 +285,7 @@ class DecoSchematic : public Decoration {
291285
virtual std::string getName();
292286

293287
void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
294-
int rot, bool force_placement);
288+
Rotation rot, bool force_placement);
295289

296290
bool loadSchematicFile();
297291
void saveSchematicFile(INodeDefManager *ndef);

‎src/mapnode.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include <string>
2929
#include <sstream>
3030

31+
static const Rotation wallmounted_to_rot[] = {
32+
ROTATE_0, ROTATE_180, ROTATE_90, ROTATE_270
33+
};
34+
static const u8 rot_to_wallmounted[] = {
35+
2, 4, 3, 5
36+
};
37+
38+
3139
/*
3240
MapNode
3341
*/
@@ -132,6 +140,24 @@ v3s16 MapNode::getWallMountedDir(INodeDefManager *nodemgr) const
132140
}
133141
}
134142

143+
void MapNode::rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot) {
144+
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
145+
146+
if (cpt2 == CPT2_FACEDIR) {
147+
u8 newrot = param2 & 3;
148+
param2 &= ~3;
149+
param2 |= (newrot + rot) & 3;
150+
} else if (cpt2 == CPT2_WALLMOUNTED) {
151+
u8 wmountface = (param2 & 7);
152+
if (wmountface <= 1)
153+
return;
154+
155+
Rotation oldrot = wallmounted_to_rot[wmountface - 2];
156+
param2 &= ~7;
157+
param2 |= rot_to_wallmounted[(oldrot + rot) & 3];
158+
}
159+
}
160+
135161
static std::vector<aabb3f> transformNodeBox(const MapNode &n,
136162
const NodeBox &nodebox, INodeDefManager *nodemgr)
137163
{

‎src/mapnode.h

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ enum LightBank
6161
LIGHTBANK_NIGHT
6262
};
6363

64+
/*
65+
Simple rotation enum.
66+
*/
67+
enum Rotation {
68+
ROTATE_0,
69+
ROTATE_90,
70+
ROTATE_180,
71+
ROTATE_270,
72+
ROTATE_RAND,
73+
};
74+
6475
/*
6576
Masks for MapNode.param2 of flowing liquids
6677
*/
@@ -181,6 +192,8 @@ struct MapNode
181192
u8 getFaceDir(INodeDefManager *nodemgr) const;
182193
u8 getWallMounted(INodeDefManager *nodemgr) const;
183194
v3s16 getWallMountedDir(INodeDefManager *nodemgr) const;
195+
196+
void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot);
184197

185198
/*
186199
Gets list of node boxes (used for rendering (NDT_NODEBOX)

0 commit comments

Comments
 (0)
Please sign in to comment.