506 changes: 253 additions & 253 deletions src/guiPauseMenu.cpp

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions src/guiPauseMenu.h
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef GUIPAUSEMENU_HEADER
#define GUIPAUSEMENU_HEADER

#include "irrlichttypes_extrabloated.h"
#include "modalMenu.h"

class IGameCallback
{
public:
virtual void exitToOS() = 0;
virtual void disconnect() = 0;
virtual void changePassword() = 0;
};

class GUIPauseMenu : public GUIModalMenu
{
public:
GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IGameCallback *gamecallback,
IMenuManager *menumgr,
bool simple_singleplayer_mode);
~GUIPauseMenu();

void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);

void drawMenu();

bool OnEvent(const SEvent& event);

private:
IGameCallback *m_gamecallback;
bool m_simple_singleplayer_mode;
};

#endif

/*
Minetest-c55
Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef GUIPAUSEMENU_HEADER
#define GUIPAUSEMENU_HEADER

#include "irrlichttypes_extrabloated.h"
#include "modalMenu.h"

class IGameCallback
{
public:
virtual void exitToOS() = 0;
virtual void disconnect() = 0;
virtual void changePassword() = 0;
};

class GUIPauseMenu : public GUIModalMenu
{
public:
GUIPauseMenu(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IGameCallback *gamecallback,
IMenuManager *menumgr,
bool simple_singleplayer_mode);
~GUIPauseMenu();

void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);

void drawMenu();

bool OnEvent(const SEvent& event);

private:
IGameCallback *m_gamecallback;
bool m_simple_singleplayer_mode;
};

#endif

47 changes: 33 additions & 14 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ void Map::removeNodeTimer(v3s16 p)
ServerMap
*/

ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
Map(dout_server, gamedef),
m_seed(0),
m_map_metadata_changed(true),
Expand All @@ -2004,19 +2004,24 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
{
verbosestream<<__FUNCTION_NAME<<std::endl;

m_emerge = emerge;

//m_chunksize = 8; // Takes a few seconds

if (g_settings->get("fixed_map_seed").empty())
{
m_seed = (((u64)(myrand()%0xffff)<<0)
+ ((u64)(myrand()%0xffff)<<16)
+ ((u64)(myrand()%0xffff)<<32)
+ ((u64)(myrand()%0xffff)<<48));
+ ((u64)(myrand()&0xffff)<<48));
}
else
{
m_seed = g_settings->getU64("fixed_map_seed");
}
emerge->seed = m_seed;
emerge->water_level = g_settings->getS16("default_water_level");
//<set noiseparams here>

/*
Experimental and debug stuff
Expand Down Expand Up @@ -2136,7 +2141,7 @@ ServerMap::~ServerMap()
#endif
}

void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
void ServerMap::initBlockMake(BlockMakeData *data, v3s16 blockpos)
{
bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
if(enable_mapgen_debug_info)
Expand Down Expand Up @@ -2208,7 +2213,7 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
Refer to the map generator heuristics.
*/
bool ug = mapgen::block_is_underground(data->seed, p);
bool ug = m_emerge->isBlockUnderground(p);
block->setIsUnderground(ug);
}

Expand Down Expand Up @@ -2243,7 +2248,7 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos)
// Data is ready now.
}

MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
core::map<v3s16, MapBlock*> &changed_blocks)
{
v3s16 blockpos_min = data->blockpos_min;
Expand Down Expand Up @@ -2483,6 +2488,7 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d)
return sector;
}

#if 0
/*
This is a quick-hand function for calling makeBlock().
*/
Expand Down Expand Up @@ -2518,15 +2524,16 @@ MapBlock * ServerMap::generateBlock(
/*
Create block make data
*/
mapgen::BlockMakeData data;
BlockMakeData data;
initBlockMake(&data, p);

/*
Generate block
*/
{
TimeTaker t("mapgen::make_block()");
mapgen::make_block(&data);
mapgen->makeChunk(&data);
//mapgen::make_block(&data);

if(enable_mapgen_debug_info == false)
t.stop(true); // Hide output
Expand Down Expand Up @@ -2595,6 +2602,7 @@ MapBlock * ServerMap::generateBlock(

return block;
}
#endif

MapBlock * ServerMap::createBlock(v3s16 p)
{
Expand Down Expand Up @@ -2656,14 +2664,15 @@ MapBlock * ServerMap::createBlock(v3s16 p)
}
// Create blank
block = sector->createBlankBlock(block_y);

return block;
}

MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
{
DSTACKF("%s: p=(%d,%d,%d), allow_generate=%d",
DSTACKF("%s: p=(%d,%d,%d), create_blank=%d",
__FUNCTION_NAME,
p.X, p.Y, p.Z, allow_generate);
p.X, p.Y, p.Z, create_blank);

{
MapBlock *block = getBlockNoCreateNoEx(p);
Expand All @@ -2677,7 +2686,13 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
return block;
}

if(allow_generate)
if (create_blank) {
ServerMapSector *sector = createSector(v2s16(p.X, p.Z));
MapBlock *block = sector->createBlankBlock(p.Y);

return block;
}
/*if(allow_generate)
{
core::map<v3s16, MapBlock*> modified_blocks;
MapBlock *block = generateBlock(p, modified_blocks);
Expand All @@ -2700,7 +2715,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool allow_generate)
return block;
}
}
}*/

return NULL;
}
Expand Down Expand Up @@ -2742,7 +2757,7 @@ s16 ServerMap::findGroundLevel(v2s16 p2d)
Determine from map generator noise functions
*/

s16 level = mapgen::find_ground_level_from_noise(m_seed, p2d, 1);
s16 level = m_emerge->getGroundLevelAtPoint(p2d);
return level;

//double level = base_rock_level_2d(m_seed, p2d) + AVERAGE_MUD_AMOUNT;
Expand Down Expand Up @@ -3062,6 +3077,7 @@ void ServerMap::saveMapMeta()

Settings params;
params.setU64("seed", m_seed);
params.setS16("water_level", m_emerge->water_level);

params.writeLines(os);

Expand Down Expand Up @@ -3100,8 +3116,11 @@ void ServerMap::loadMapMeta()
break;
params.parseConfigLine(line);
}

m_seed = params.getU64("seed");
m_emerge->seed = m_seed;
m_emerge->water_level = params.getS16("water_level");
//m_emerge->np = ;

verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
}
Expand Down
22 changes: 11 additions & 11 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapnode.h"
#include "constants.h"
#include "voxel.h"
#include "mapgen.h" //for BlockMakeData and EmergeManager
#include "modifiedstate.h"
#include "util/container.h"
#include "nodetimer.h"
Expand All @@ -46,9 +47,6 @@ class NodeMetadata;
class IGameDef;
class IRollbackReportSink;

namespace mapgen{
struct BlockMakeData;
};

/*
MapEditEvent
Expand Down Expand Up @@ -360,7 +358,7 @@ class ServerMap : public Map
/*
savedir: directory to which map data should be saved
*/
ServerMap(std::string savedir, IGameDef *gamedef);
ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge);
~ServerMap();

s32 mapType() const
Expand All @@ -379,15 +377,15 @@ class ServerMap : public Map
/*
Blocks are generated by using these and makeBlock().
*/
void initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos);
MapBlock* finishBlockMake(mapgen::BlockMakeData *data,
void initBlockMake(BlockMakeData *data, v3s16 blockpos);
MapBlock* finishBlockMake(BlockMakeData *data,
core::map<v3s16, MapBlock*> &changed_blocks);

// A non-threaded wrapper to the above
MapBlock * generateBlock(
// A non-threaded wrapper to the above - DEFUNCT
/* MapBlock * generateBlock(
v3s16 p,
core::map<v3s16, MapBlock*> &modified_blocks
);
);*/

/*
Get a block from somewhere.
Expand All @@ -400,9 +398,10 @@ class ServerMap : public Map
Forcefully get a block from somewhere.
- Memory
- Load from disk
- Generate
- Create blank filled with CONTENT_IGNORE
*/
MapBlock * emergeBlock(v3s16 p, bool allow_generate=true);
MapBlock * emergeBlock(v3s16 p, bool create_blank=true);

// Helper for placing objects on ground level
s16 findGroundLevel(v2s16 p2d);
Expand Down Expand Up @@ -479,6 +478,7 @@ class ServerMap : public Map

u64 getSeed(){ return m_seed; }

EmergeManager *m_emerge;
private:
// Seed used for all kinds of randomness in generation
u64 m_seed;
Expand Down
442 changes: 367 additions & 75 deletions src/mapgen.cpp

Large diffs are not rendered by default.

120 changes: 114 additions & 6 deletions src/mapgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,121 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "irrlichttypes_extrabloated.h"
#include "util/container.h" // UniqueQueue
#include "gamedef.h"
#include "mapnode.h"
#include "noise.h"

struct BlockMakeData;
class BiomeDefManager;
class Biome;

//struct BlockMakeData;
class MapBlock;
class ManualMapVoxelManipulator;
class INodeDefManager;

struct BlockMakeData {
bool no_op;
ManualMapVoxelManipulator *vmanip;
u64 seed;
v3s16 blockpos_min;
v3s16 blockpos_max;
v3s16 blockpos_requested;
UniqueQueue<v3s16> transforming_liquid;
INodeDefManager *nodedef;

BlockMakeData();
~BlockMakeData();
};

class Mapgen {
public:
BlockMakeData *data;
ManualMapVoxelManipulator *vmanip;
INodeDefManager *ndef;
BiomeDefManager *biomedef;

int ystride;
int zstride;

v3s16 csize;
int seed;
int water_level;

Noise *noise_terrain;
Noise *noise_bgroup;
Noise *noise_heat;
Noise *noise_humidity;

v3s16 node_min;
v3s16 node_max;

float *map_terrain;
float *map_bgroup;
float *map_heat;
float *map_humidity;

bool generating;
int id;

NoiseParams *np_terrain;
NoiseParams *np_bgroup;
NoiseParams *np_heat;
NoiseParams *np_humidity;

//should these be broken off into a "commonly used nodes" class?
MapNode n_air;
MapNode n_water;
MapNode n_lava;

Mapgen(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0);
Mapgen(BiomeDefManager *biomedef, int mapgenid, u64 seed,
NoiseParams *np_terrain, NoiseParams *np_bgroup,
NoiseParams *np_heat, NoiseParams *np_humidity);
void initMapgen(BiomeDefManager *biomedef, int mapgenid, u64 seed,
NoiseParams *np_terrain, NoiseParams *np_bgroup,
NoiseParams *np_heat, NoiseParams *np_humidity);
~Mapgen();

void makeChunk(BlockMakeData *data);
void updateLiquid(v3s16 node_min, v3s16 node_max);
void updateLighting(v3s16 node_min, v3s16 node_max);

//Legacy functions for Farmesh (pending removal)
static bool get_have_beach(u64 seed, v2s16 p2d);
static double tree_amount_2d(u64 seed, v2s16 p);
static s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
};

class EmergeManager {
public:
//settings
u64 seed;
int water_level;
NoiseParams *np_terrain;
NoiseParams *np_bgroup;
NoiseParams *np_heat;
NoiseParams *np_humidity;

//biome manager
BiomeDefManager *biomedef;

//mapgen objects here

EmergeManager(IGameDef *gamedef);
~EmergeManager();
void addBlockToQueue();



//mapgen helper methods
Biome *getBiomeAtPoint(v3s16 p);
int getGroundLevelAtPoint(v2s16 p);
bool isBlockUnderground(v3s16 blockpos);
u32 getBlockSeed(v3s16 p);
};


/*
namespace mapgen
{
// Finds precise ground level at any position
Expand All @@ -41,10 +150,9 @@ namespace mapgen
// Main map generation routine
void make_block(BlockMakeData *data);

/*
These are used by FarMesh
*/
//These are used by FarMesh
bool get_have_beach(u64 seed, v2s16 p2d);
double tree_amount_2d(u64 seed, v2s16 p);
Expand All @@ -64,6 +172,6 @@ namespace mapgen
};
}; // namespace mapgen

*/
#endif

10 changes: 5 additions & 5 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void NodeBox::deSerialize(std::istream &is)
/*
TileDef
*/

void TileDef::serialize(std::ostream &os) const
{
writeU8(os, 0); // version
Expand Down Expand Up @@ -173,7 +173,7 @@ void ContentFeatures::reset()
has_after_destruct = false;
/*
Actual data
NOTE: Most of this is always overridden by the default values given
in builtin.lua
*/
Expand Down Expand Up @@ -354,7 +354,7 @@ class CNodeDefManager: public IWritableNodeDefManager
ContentFeatures &f = m_content_features[i];
f.reset(); // Reset to defaults
}

// Set CONTENT_AIR
{
ContentFeatures f;
Expand Down Expand Up @@ -541,11 +541,11 @@ class CNodeDefManager: public IWritableNodeDefManager
bool new_style_water = g_settings->getBool("new_style_water");
bool new_style_leaves = g_settings->getBool("new_style_leaves");
bool opaque_water = g_settings->getBool("opaque_water");

for(u16 i=0; i<=MAX_CONTENT; i++)
{
ContentFeatures *f = &m_content_features[i];

// Figure out the actual tiles to use
TileDef tiledef[6];
for(u32 j=0; j<6; j++)
Expand Down
695 changes: 405 additions & 290 deletions src/noise.cpp

Large diffs are not rendered by default.

129 changes: 54 additions & 75 deletions src/noise.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define NOISE_HEADER

#include "debug.h"
#include "irr_v3d.h"

class PseudoRandom
{
Expand Down Expand Up @@ -59,91 +60,69 @@ class PseudoRandom
int m_next;
};

double easeCurve(double t);

// Return value: -1 ... 1
double noise2d(int x, int y, int seed);
double noise3d(int x, int y, int z, int seed);
struct NoiseParams {
float offset;
float scale;
v3f spread;
int seed;
int octaves;
float persist;
};

double noise2d_gradient(double x, double y, int seed);
double noise3d_gradient(double x, double y, double z, int seed);

double noise2d_perlin(double x, double y, int seed,
int octaves, double persistence);
class Noise {
public:
NoiseParams *np;
int seed;
int sx;
int sy;
int sz;
float *noisebuf;
float *buf;
float *result;

Noise(NoiseParams *np, int seed, int sx, int sy);
Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
~Noise();

void gradientMap2D(
float x, float y,
float step_x, float step_y,
int seed);
void gradientMap3D(
float x, float y, float z,
float step_x, float step_y, float step_z,
int seed);
float *perlinMap2D(float x, float y);
float *perlinMap3D(float x, float y, float z);
};

double noise2d_perlin_abs(double x, double y, int seed,
int octaves, double persistence);
// Return value: -1 ... 1
float noise2d(int x, int y, int seed);
float noise3d(int x, int y, int z, int seed);

double noise3d_perlin(double x, double y, double z, int seed,
int octaves, double persistence);
float noise2d_gradient(float x, float y, int seed);
float noise3d_gradient(float x, float y, float z, int seed);

double noise3d_perlin_abs(double x, double y, double z, int seed,
int octaves, double persistence);
float noise2d_perlin(float x, float y, int seed,
int octaves, float persistence);

enum NoiseType
{
NOISE_CONSTANT_ONE,
NOISE_PERLIN,
NOISE_PERLIN_ABS,
NOISE_PERLIN_CONTOUR,
NOISE_PERLIN_CONTOUR_FLIP_YZ,
};
float noise2d_perlin_abs(float x, float y, int seed,
int octaves, float persistence);

struct NoiseParams
{
NoiseType type;
int seed;
int octaves;
double persistence;
double pos_scale;
double noise_scale; // Useful for contour noises

NoiseParams(NoiseType type_=NOISE_PERLIN, int seed_=0,
int octaves_=3, double persistence_=0.5,
double pos_scale_=100.0, double noise_scale_=1.0):
type(type_),
seed(seed_),
octaves(octaves_),
persistence(persistence_),
pos_scale(pos_scale_),
noise_scale(noise_scale_)
{
}
};
float noise3d_perlin(float x, float y, float z, int seed,
int octaves, float persistence);

double noise3d_param(const NoiseParams &param, double x, double y, double z);
float noise3d_perlin_abs(float x, float y, float z, int seed,
int octaves, float persistence);

class NoiseBuffer
{
public:
NoiseBuffer();
~NoiseBuffer();

void clear();
void create(const NoiseParams &param,
double first_x, double first_y, double first_z,
double last_x, double last_y, double last_z,
double samplelength_x, double samplelength_y, double samplelength_z);
void multiply(const NoiseParams &param);
// Deprecated
void create(int seed, int octaves, double persistence,
bool abs,
double first_x, double first_y, double first_z,
double last_x, double last_y, double last_z,
double samplelength_x, double samplelength_y, double samplelength_z);

void intSet(int x, int y, int z, double d);
void intMultiply(int x, int y, int z, double d);
double intGet(int x, int y, int z);
double get(double x, double y, double z);
//bool contains(double x, double y, double z);
inline float easeCurve(float t) {
return t * t * t * (t * (6.f * t - 15.f) + 10.f);
}

private:
double *m_data;
double m_start_x, m_start_y, m_start_z;
double m_samplelength_x, m_samplelength_y, m_samplelength_z;
int m_size_x, m_size_y, m_size_z;
};
#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
noise2d_perlin((float)(x) * (np)->spread.X, (float)(y) * (np)->spread.Y, \
(s) + (np)->seed, (np)->octaves, (np)->persist))

#endif

16 changes: 8 additions & 8 deletions src/scriptapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3240,8 +3240,8 @@ class LuaPerlinNoise
private:
int seed;
int octaves;
double persistence;
double scale;
float persistence;
float scale;
static const char className[];
static const luaL_reg methods[];

Expand Down Expand Up @@ -3273,8 +3273,8 @@ class LuaPerlinNoise
}

public:
LuaPerlinNoise(int a_seed, int a_octaves, double a_persistence,
double a_scale):
LuaPerlinNoise(int a_seed, int a_octaves, float a_persistence,
float a_scale):
seed(a_seed),
octaves(a_octaves),
persistence(a_persistence),
Expand All @@ -3292,8 +3292,8 @@ class LuaPerlinNoise
{
int seed = luaL_checkint(L, 1);
int octaves = luaL_checkint(L, 2);
double persistence = luaL_checknumber(L, 3);
double scale = luaL_checknumber(L, 4);
float persistence = luaL_checknumber(L, 3);
float scale = luaL_checknumber(L, 4);
LuaPerlinNoise *o = new LuaPerlinNoise(seed, octaves, persistence, scale);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
Expand Down Expand Up @@ -3999,8 +3999,8 @@ class EnvRef

int seeddiff = luaL_checkint(L, 2);
int octaves = luaL_checkint(L, 3);
double persistence = luaL_checknumber(L, 4);
double scale = luaL_checknumber(L, 5);
float persistence = luaL_checknumber(L, 4);
float scale = luaL_checknumber(L, 5);

LuaPerlinNoise *n = new LuaPerlinNoise(seeddiff + int(env->getServerMap().getSeed()), octaves, persistence, scale);
*(void **)(lua_newuserdata(L, sizeof(void *))) = n;
Expand Down
419 changes: 217 additions & 202 deletions src/server.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ class Server : public con::PeerHandler, public MapEventReceiver,
bool m_rollback_sink_enabled;
bool m_enable_rollback_recording; // Updated once in a while

// Emerge manager
EmergeManager *m_emerge;

// Scripting
// Envlock and conlock should be locked when using Lua
lua_State *m_lua;
Expand Down
15 changes: 11 additions & 4 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,7 @@ class Settings
set(name, "false");
}

void setS32(std::string name, s32 value)
{
set(name, itos(value));
}


void setFloat(std::string name, float value)
{
Expand All @@ -598,6 +595,16 @@ class Settings
set(name, os.str());
}

void setS16(std::string name, s16 value)
{
set(name, itos(value));
}

void setS32(std::string name, s32 value)
{
set(name, itos(value));
}

void setU64(std::string name, u64 value)
{
std::ostringstream os;
Expand Down
1 change: 1 addition & 0 deletions src/util/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ inline s16 rangelim(s16 i, s16 max)
}

#define rangelim(d, min, max) ((d) < (min) ? (min) : ((d)>(max)?(max):(d)))
#define myfloor(x) ((x) > 0.0 ? (int)(x) : (int)(x) - 1)

inline v3s16 arealim(v3s16 p, s16 d)
{
Expand Down
34 changes: 17 additions & 17 deletions src/voxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class VoxelArea
MaxEdge(p)
{
}

/*
Modifying methods
*/
Expand Down Expand Up @@ -106,14 +106,14 @@ class VoxelArea
if(p.Y > MaxEdge.Y) MaxEdge.Y = p.Y;
if(p.Z > MaxEdge.Z) MaxEdge.Z = p.Z;
}

// Pad with d nodes
void pad(v3s16 d)
{
MinEdge -= d;
MaxEdge += d;
}

/*void operator+=(v3s16 off)
{
MinEdge += off;
Expand Down Expand Up @@ -202,7 +202,7 @@ class VoxelArea
}

assert(contains(a));

// Take back area, XY inclusive
{
v3s16 min(MinEdge.X, MinEdge.Y, a.MaxEdge.Z+1);
Expand Down Expand Up @@ -258,7 +258,7 @@ class VoxelArea
}

}

/*
Translates position from virtual coordinates to array index
*/
Expand All @@ -274,7 +274,7 @@ class VoxelArea
{
return index(p.X, p.Y, p.Z);
}

// Translate index in the X coordinate
void add_x(const v3s16 &extent, u32 &i, s16 a)
{
Expand Down Expand Up @@ -343,7 +343,7 @@ class VoxelManipulator /*: public NodeContainer*/
public:
VoxelManipulator();
virtual ~VoxelManipulator();

/*
Virtuals from NodeContainer
*/
Expand Down Expand Up @@ -430,7 +430,7 @@ class VoxelManipulator /*: public NodeContainer*/
void setNode(v3s16 p, const MapNode &n)
{
emerge(p);

m_data[m_area.index(p)] = n;
m_flags[m_area.index(p)] &= ~VOXELFLAG_INEXISTENT;
m_flags[m_area.index(p)] &= ~VOXELFLAG_NOT_LOADED;
Expand All @@ -457,10 +457,10 @@ class VoxelManipulator /*: public NodeContainer*/
//dstream<<"operator[] p=("<<p.X<<","<<p.Y<<","<<p.Z<<")"<<std::endl;
if(isValidPosition(p) == false)
emerge(VoxelArea(p));
return m_data[m_area.index(p)];
}*/

/*
Set stuff if available without an emerge.
Return false if failed.
Expand Down Expand Up @@ -496,7 +496,7 @@ class VoxelManipulator /*: public NodeContainer*/

void print(std::ostream &o, INodeDefManager *nodemgr,
VoxelPrintMode mode=VOXELPRINT_MATERIAL);

void addArea(VoxelArea area);

/*
Expand All @@ -505,7 +505,7 @@ class VoxelManipulator /*: public NodeContainer*/
*/
void copyFrom(MapNode *src, VoxelArea src_area,
v3s16 from_pos, v3s16 to_pos, v3s16 size);

// Copy data
void copyTo(MapNode *dst, VoxelArea dst_area,
v3s16 dst_pos, v3s16 from_pos, v3s16 size);
Expand All @@ -523,15 +523,15 @@ class VoxelManipulator /*: public NodeContainer*/
void unspreadLight(enum LightBank bank,
core::map<v3s16, u8> & from_nodes,
core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr);

void spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr);
void spreadLight(enum LightBank bank,
core::map<v3s16, bool> & from_nodes, INodeDefManager *nodemgr);

/*
Virtual functions
*/

/*
Get the contents of the requested area from somewhere.
Shall touch only nodes that have VOXELFLAG_NOT_LOADED
Expand Down Expand Up @@ -565,7 +565,7 @@ class VoxelManipulator /*: public NodeContainer*/
MaxEdge is 1 higher than maximum allowed position
*/
VoxelArea m_area;

/*
NULL if data size is 0 (extent (0,0,0))
Data is stored as [z*h*w + y*h + x]
Expand All @@ -576,7 +576,7 @@ class VoxelManipulator /*: public NodeContainer*/
Flags of all nodes
*/
u8 *m_flags;

//TODO: Use these or remove them
//TODO: Would these make any speed improvement?
//bool m_pressure_route_valid;
Expand Down
8 changes: 4 additions & 4 deletions src/voxelalgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
required_a.pad(v3s16(0,1,0));
// Make sure we have access to it
v.emerge(a);

s16 max_y = a.MaxEdge.Y;
s16 min_y = a.MinEdge.Y;

for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
{
Expand Down Expand Up @@ -125,11 +125,11 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,

if(incoming_light > old_light)
n.setLight(LIGHTBANK_DAY, incoming_light, ndef);

if(diminish_light(incoming_light) != 0)
light_sources.insert(p, true);
}

// Check validity of sunlight at top of block below if it
// hasn't already been proven invalid
if(bottom_sunlight_valid)
Expand Down