From: Perttu Ahola Date: Wed, 28 Mar 2012 17:46:05 +0000 (+0300) Subject: Add blockseed to on_generated X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=9a1df7bf3879bc77025779f11f4a99943572931f;p=zefram%2Fminetest%2Fminetest_engine.git Add blockseed to on_generated --- diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 49da0089..ae6771be 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -444,7 +444,7 @@ minetest.register_globalstep(func(dtime)) minetest.register_on_placenode(func(pos, newnode, placer)) minetest.register_on_dignode(func(pos, oldnode, digger)) minetest.register_on_punchnode(func(pos, node, puncher)) -minetest.register_on_generated(func(minp, maxp)) +minetest.register_on_generated(func(minp, maxp, blockseed)) minetest.register_on_newplayer(func(ObjectRef)) minetest.register_on_dieplayer(func(ObjectRef)) minetest.register_on_respawnplayer(func(ObjectRef)) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 46304cdf..61718d91 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -193,6 +193,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, } } +#if 0 static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { @@ -280,7 +281,7 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, } } -void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, +static void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { MapNode papyrusnode(ndef->getId("mapgen_papyrus")); @@ -295,7 +296,7 @@ void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, } } -void make_cactus(VoxelManipulator &vmanip, v3s16 p0, +static void make_cactus(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef) { MapNode cactusnode(ndef->getId("mapgen_cactus")); @@ -309,7 +310,9 @@ void make_cactus(VoxelManipulator &vmanip, v3s16 p0, p1.Y++; } } +#endif +#if 0 /* Dungeon making routines */ @@ -861,7 +864,9 @@ static void make_dungeon1(VoxelManipulator &vmanip, PseudoRandom &random, } } +#endif +#if 0 static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random, INodeDefManager *ndef) { @@ -896,6 +901,7 @@ static void make_nc(VoxelManipulator &vmanip, PseudoRandom &random, vmanip.m_data[vmanip.m_area.index(p)] = MapNode(ndef->getId("mapgen_nyancat_rainbow")); } } +#endif /* Noise functions. Make sure seed is mangled differently in each one. @@ -1272,6 +1278,12 @@ bool get_have_sand(u64 seed, v2s16 p2d) return (sandnoise > -0.15); } +u32 get_blockseed(u64 seed, v3s16 p) +{ + s32 x=p.X, y=p.Y, z=p.Z; + return (u32)(seed%0x100000000ULL) + z*38134234 + y*42123 + x*23; +} + #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 void make_block(BlockMakeData *data) diff --git a/src/mapgen.h b/src/mapgen.h index 24a853bd..3374c678 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -36,6 +36,9 @@ namespace mapgen // Find out if block is completely underground bool block_is_underground(u64 seed, v3s16 blockpos); + // Get a pseudorandom seed for a position on the map + u32 get_blockseed(u64 seed, v3s16 p); + // Main map generation routine void make_block(BlockMakeData *data); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index d2ded57c..944b81a5 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -4403,7 +4403,8 @@ void scriptapi_environment_step(lua_State *L, float dtime) } } -void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp) +void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp, + u32 blockseed) { realitycheck(L); assert(lua_checkstack(L, 20)); @@ -4423,7 +4424,8 @@ void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp) // Call function push_v3s16(L, minp); push_v3s16(L, maxp); - if(lua_pcall(L, 2, 0, 0)) + lua_pushnumber(L, blockseed); + if(lua_pcall(L, 3, 0, 0)) script_error(L, "error: %s", lua_tostring(L, -1)); // value removed, keep key for next iteration } diff --git a/src/scriptapi.h b/src/scriptapi.h index f63cab36..37326288 100644 --- a/src/scriptapi.h +++ b/src/scriptapi.h @@ -51,7 +51,8 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name, // On environment step void scriptapi_environment_step(lua_State *L, float dtime); // After generating a piece of map -void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp); +void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp, + u32 blockseed); /* misc */ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player); diff --git a/src/server.cpp b/src/server.cpp index 6756e4a0..d3c1218e 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -283,7 +283,7 @@ void * EmergeThread::Thread() v3s16 minp = block->getPos()*MAP_BLOCKSIZE; v3s16 maxp = minp + v3s16(1,1,1)*(MAP_BLOCKSIZE-1); scriptapi_environment_on_generated(m_server->m_lua, - minp, maxp); + minp, maxp, mapgen::get_blockseed(data.seed, minp)); if(enable_mapgen_debug_info) infostream<<"EmergeThread: ended up with: "