aboutsummaryrefslogtreecommitdiff
path: root/src/voxel.cpp
Commit message (Expand)AuthorAge
* Node definition manager refactor (#7016)Dániel Juhász2018-02-10
* Remove unused light updating codeDániel Juhász2018-02-04
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
* VoxelManip cleanups (const ref, const move) + function removal (#6169)Loïc Blot2017-07-26
* Cpp11 initializers: last src root changeset (#6022)Loïc Blot2017-06-21
* Time: Change old `u32` timestamps to 64-bit (#5818)SmallJoker2017-05-26
* Remove some old dead code. Fix some Clang warnings in SRP (ng->N... willLoic Blot2015-07-24
* Optimise MapBlockMesh related functionsgregorycu2015-02-23
* Create empty default constructor for MapNodeCraig Robbins2015-01-18
* Add VoxelArea::hasEmptyExtentunknown2015-01-13
* VoxelManipulator: Remove unnecessary deallocation stepskwolekr2014-12-27
* Large increase in performanceCraig Robbins2014-12-24
* Use std::string::empty() instead of size() where applicableAnton2014-12-12
* Optimise VoxelManipulator::copyFromCraig Robbins2014-12-04
* Optimise functions from CNodeDefManager and VoxelManipulatorCraig Robbins2014-11-21
* Remove emerge and speedup addArea by using memcopy instead of one by one assi...sapier2014-06-23
* Use memset for flag initialization (compiler optimization is way better)sapier2014-06-23
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Fix nearly all warningskwolekr2013-05-19
* Migrate to STL containers/algorithms.Ilya Zhuravlev2013-03-11
* Fix most walled-off caveskwolekr2013-02-25
* Update Copyright YearsSfan52013-02-24
* Change Minetest-c55 to MinetestPilzAdam2013-02-24
* Properly and efficiently use split utility headersPerttu Ahola2012-06-17
* Switch the license to be LGPLv2/later, with small parts still remaining as GP...Perttu Ahola2012-06-05
* Implement propagateSunlight for VoxelManipulatorPerttu Ahola2012-03-27
* Optimize lighting by a tiny bitPerttu Ahola2011-11-29
* GameDef compilesPerttu Ahola2011-11-29
* extended content-type rangePerttu Ahola2011-07-23
* Moved some mapnode content stuff from mapnode.{h,cpp} and digging property st...Perttu Ahola2011-06-17
* partly working chunk-based map generator (doesn't save properly, spawn is pre...Perttu Ahola2011-02-01
* map generation framework under development... not quite operational at this p...Perttu Ahola2011-01-30
* Reworked texture, material, mineral and whatever handlingPerttu Ahola2011-01-26
* removed alternative name "pressure" from param2Perttu Ahola2011-01-25
* Faster lighting at map generation timePerttu Ahola2011-01-24
* commented out old water stuffPerttu Ahola2011-01-24
* old water removed, some fixes here and therePerttu Ahola2011-01-17
* working goodPerttu Ahola2010-12-26
* some work-in-progressPerttu Ahola2010-12-22
* organizing stuff.Perttu Ahola2010-12-21
* framework for modifying texturesPerttu Ahola2010-12-20
* day/night working client sidePerttu Ahola2010-12-19
* before daynight mesh cachePerttu Ahola2010-12-18
* little fixesPerttu Ahola2010-12-14
* working nicelyPerttu Ahola2010-12-13
* starting to separate "material" to "content" and "tile"Perttu Ahola2010-12-12
* removed accidental double flowWaterPerttu Ahola2010-12-11
* commit before some radicallish changes to water behaviorPerttu Ahola2010-12-11
* some work-in-progress water stuffPerttu Ahola2010-12-01
* license stuffPerttu Ahola2010-11-29
hl kwd">mark_multiple_occurences (x) if no_identity [type(x)] then return end if seen_once [x] then seen_once [x], multiple [x] = nil, true elseif multiple [x] then -- pass else seen_once [x] = true end if type (x) == 'table' then nested [x] = true for k, v in pairs (x) do if nested[k] or nested[v] then mark_nest_point (x, k, v) else mark_multiple_occurences (k) mark_multiple_occurences (v) end end nested [x] = nil end end local dumped = { } -- multiply occuring values already dumped in localdefs local localdefs = { } -- already dumped local definitions as source code lines -- mutually recursive functions: local dump_val, dump_or_ref_val -------------------------------------------------------------------- -- if x occurs multiple times, dump the local var rather than the -- value. If it's the first time it's dumped, also dump the content -- in localdefs. -------------------------------------------------------------------- function dump_or_ref_val (x) if nested[x] then return 'false' end -- placeholder for recursive reference if not multiple[x] then return dump_val (x) end local var = dumped [x] if var then return "_[" .. var .. "]" end -- already referenced local val = dump_val(x) -- first occurence, create and register reference var = gensym() table.insert(localdefs, "_["..var.."]="..val) dumped [x] = var return "_[" .. var .. "]" end ----------------------------------------------------------------------------- -- Second pass, dump the object; subparts occuring multiple times are dumped -- in local variables which can be referenced multiple times; -- care is taken to dump locla vars in asensible order. ----------------------------------------------------------------------------- function dump_val(x) local t = type(x) if x==nil then return 'nil' elseif t=="number" then return tostring(x) elseif t=="string" then return string.format("%q", x) elseif t=="boolean" then return x and "true" or "false" elseif t=="table" then local acc = { } local idx_dumped = { } local np = nest_points [x] for i, v in ipairs(x) do if np and np[v] then table.insert (acc, 'false') -- placeholder else table.insert (acc, dump_or_ref_val(v)) end idx_dumped[i] = true end for k, v in pairs(x) do if np and (np[k] or np[v]) then --check_multiple(k); check_multiple(v) -- force dumps in localdefs elseif not idx_dumped[k] then table.insert (acc, "[" .. dump_or_ref_val(k) .. "] = " .. dump_or_ref_val(v)) end end return "{ "..table.concat(acc,", ").." }" else error ("Can't serialize data of type "..t) end end local function dump_nest_patches() for _, entry in ipairs(nest_patches) do local p, k, v = unpack (entry) assert (multiple[p]) local set = dump_or_ref_val (p) .. "[" .. dump_or_ref_val (k) .. "] = " .. dump_or_ref_val (v) .. " -- rec " table.insert (localdefs, set) end end mark_multiple_occurences (x) local toplevel = dump_or_ref_val (x) dump_nest_patches() if next (localdefs) then return "local _={ }\n" .. table.concat (localdefs, "\n") .. "\nreturn " .. toplevel else return "return " .. toplevel end end -- Deserialization. -- http://stackoverflow.com/questions/5958818/loading-serialized-data-into-a-table -- local function stringtotable(sdata) if sdata:byte(1) == 27 then return nil, "binary bytecode prohibited" end local f, message = assert(loadstring(sdata)) if not f then return nil, message end setfenv(f, table) return f() end function minetest.deserialize(sdata) local table = {} local okay,results = pcall(stringtotable, sdata) if okay then return results end print('error:'.. results) return nil end -- Run some unit tests local function unit_test() function unitTest(name, success) if not success then error(name .. ': failed') end end unittest_input = {cat={sound="nyan", speed=400}, dog={sound="woof"}} unittest_output = minetest.deserialize(minetest.serialize(unittest_input)) unitTest("test 1a", unittest_input.cat.sound == unittest_output.cat.sound) unitTest("test 1b", unittest_input.cat.speed == unittest_output.cat.speed) unitTest("test 1c", unittest_input.dog.sound == unittest_output.dog.sound) unittest_input = {escapechars="\n\r\t\v\\\"\'", noneuropean="θשׁ٩∂"} unittest_output = minetest.deserialize(minetest.serialize(unittest_input)) unitTest("test 3a", unittest_input.escapechars == unittest_output.escapechars) unitTest("test 3b", unittest_input.noneuropean == unittest_output.noneuropean) end unit_test() -- Run it unit_test = nil -- Hide it