]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen_singlenode.cpp
Increase performance of getLight() by at least 2x
[dragonfireclient.git] / src / mapgen_singlenode.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "mapgen_singlenode.h"
21 #include "voxel.h"
22 #include "mapblock.h"
23 #include "mapnode.h"
24 #include "map.h"
25 #include "nodedef.h"
26 #include "voxelalgorithms.h"
27 #include "profiler.h"
28 #include "emerge.h"
29
30 //////////////////////// Mapgen Singlenode parameter read/write
31
32 void MapgenSinglenodeParams::readParams(Settings *settings) {
33 }
34
35
36 void MapgenSinglenodeParams::writeParams(Settings *settings) {
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40
41 MapgenSinglenode::MapgenSinglenode(int mapgenid,
42         MapgenParams *params, EmergeManager *emerge)
43         : Mapgen(mapgenid, params, emerge)
44 {
45         flags = params->flags;
46
47         INodeDefManager *ndef = emerge->ndef;
48
49         c_node = ndef->getId("mapgen_singlenode");
50         if (c_node == CONTENT_IGNORE)
51                 c_node = CONTENT_AIR;
52 }
53
54
55 MapgenSinglenode::~MapgenSinglenode() {
56 }
57
58 //////////////////////// Map generator
59
60 void MapgenSinglenode::makeChunk(BlockMakeData *data) {
61         assert(data->vmanip);
62         assert(data->nodedef);
63         assert(data->blockpos_requested.X >= data->blockpos_min.X &&
64                    data->blockpos_requested.Y >= data->blockpos_min.Y &&
65                    data->blockpos_requested.Z >= data->blockpos_min.Z);
66         assert(data->blockpos_requested.X <= data->blockpos_max.X &&
67                    data->blockpos_requested.Y <= data->blockpos_max.Y &&
68                    data->blockpos_requested.Z <= data->blockpos_max.Z);
69
70         this->generating = true;
71         this->vm   = data->vmanip;
72         this->ndef = data->nodedef;
73
74         v3s16 blockpos_min = data->blockpos_min;
75         v3s16 blockpos_max = data->blockpos_max;
76
77         // Area of central chunk
78         v3s16 node_min = blockpos_min*MAP_BLOCKSIZE;
79         v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);
80
81         MapNode n_node(c_node);
82
83         for (s16 z = node_min.Z; z <= node_max.Z; z++)
84         for (s16 y = node_min.Y; y <= node_max.Y; y++) {
85                 u32 i = vm->m_area.index(node_min.X, y, z);
86                 for (s16 x = node_min.X; x <= node_max.X; x++) {
87                         if (vm->m_data[i].getContent() == CONTENT_IGNORE)
88                                 vm->m_data[i] = n_node;
89                         i++;
90                 }
91         }
92
93         // Add top and bottom side of water to transforming_liquid queue
94         updateLiquid(&data->transforming_liquid, node_min, node_max);
95
96         // Calculate lighting
97         if (flags & MG_LIGHT)
98                 calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
99                                          node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
100
101         this->generating = false;
102 }
103
104 int MapgenSinglenode::getGroundLevelAtPoint(v2s16 p) {
105         return 0;
106 }
107