aboutsummaryrefslogtreecommitdiff
path: root/src/util/numeric.h
Commit message (Expand)AuthorAge
* Formspecs: Add state-selection to style elements (#9378)Hugues Ross2020-04-11
* Use true pitch/yaw/roll rotations without loss of precision by pgimeno (#8019)Paul Ouellette2019-02-07
* Add Lua methods 'set_rotation()' and 'get_rotation()' (#7395)CoderForTheBetter2018-11-28
* Light curve: Simplify and improve code, fix darkened daytime sky (#7693)Vitaliy2018-09-16
* Smoothed yaw rotation for objects (#6825)SmallJoker2018-08-02
* Revert "Add an active object step time budget #6721"Lars Hofhansl2018-01-12
* Fix rounding error in g/set_node caused by truncation to floatrubenwardy2017-12-26
* Add an active object step time budget #6721Lars Hofhansl2017-12-06
* Allow zoom to actually show more data.Lars Hofhansl2017-11-15
* Move files to subdirectories (#6599)Vitaliy2017-11-08
* Change BS constant from implicit double to float (#6286)Jens Rottmann2017-08-20
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
* C++11 cleanup on constructors (#6000)Vincent Glize2017-06-19
* Use C++11 mutexes only (remove compat code) (#5922)Loïc Blot2017-06-06
* Fix myfloor(0.0)ShadowNinja2017-05-06
* Clean up numeric.h and split FacePositionCache from itShadowNinja2017-05-06
* Minimap: Optimisenumber Zero2017-03-11
* use unordered containers where possible (patch 4 on X)Loic Blot2016-10-06
* v2d & aabbox3d<f32> & sky cleanupsnerzhul2016-02-11
* Rename and move basicmacros.h to util/basic_macros.hest312015-11-02
* Move basic, non-numeric macros from util/numeric.h to basicmacros.hkwolekr2015-10-27
* Clean up threadingShadowNinja2015-08-23
* src/util/numeric.{cpp,h}: Fix FacePositionCache data raceBřetislav Štec2015-08-02
* Fix several MSVC issues numeric.hSmallJoker2015-05-01
* Clean scaling pre-filter for formspec/HUD.Aaron Suen2015-04-01
* Fix set_bitskwolekr2015-03-31
* GenElementManager: Pass opaque handles to Lua and rename to ObjDefManagerkwolekr2015-03-31
* Add support for the PCG32 PRNG algo (and associated script APIs)kwolekr2015-03-22
* Fix wrapDegrees family of functionsCraig Robbins2015-02-23
* Performance Improvement: Use a cache which caches result for getFacePositions.Loic Blot2015-02-16
* Water fixesgregorycu2015-01-18
* Remove unused rangelim function (the macro still exists)Kahrl2014-11-19
* Implement WieldMeshSceneNode which improves wield mesh renderingKahrl2014-11-08
* Refactor decoration-related codekwolekr2014-10-29
* Accept hexadecimal and string values for seedskwolekr2013-11-04
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Weather supportproller2013-07-27
* Decoration: Add Schematic decoration typekwolekr2013-06-22
* Migrate to STL containers/algorithms.Ilya Zhuravlev2013-03-11
* Update Copyright YearsSfan52013-02-24
* Change Minetest-c55 to MinetestPilzAdam2013-02-24
* The new mapgen, noise functions, et al.kwolekr2013-01-21
* Optimize headersPerttu Ahola2012-06-17
* Initially split utility.h to multiple files in util/Perttu Ahola2012-06-17
/span>single_conn[((conns.conn2+4*i)%16)]={name=nodename, param2=i} end tp.tracks[nnprefix].modify[nodename]=true end function tp.add_worked(nnprefix, suffix, rotation, cycle_follows) tp.tracks[nnprefix].twcycle[suffix]=cycle_follows if not tp.tracks[nnprefix].twrotate[suffix] then tp.tracks[nnprefix].twrotate[suffix]={} end table.insert(tp.tracks[nnprefix].twrotate[suffix], rotation) end function tp.find_adjacent_tracks(pos)--TODO vertical calculations(check node below) local conn1=0 while conn1<16 and not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, conn1)).name, advtrains.all_tracktypes) do conn1=conn1+1 end if conn1>=16 then return nil, nil end local conn2=0 while conn2<16 and not advtrains.is_track_and_drives_on(minetest.get_node(advtrains.dirCoordSet(pos, conn2)).name, advtrains.all_tracktypes) or conn2==conn1 do conn2=conn2+1 end if conn2>=16 then return conn1, nil end return conn1, conn2 end function tp.find_already_connected(pos)--TODO vertical calculations(check node below) local function istrackandbc(pos, conn) local cnode=minetest.get_node(advtrains.dirCoordSet(pos, conn)) local bconn=(conn+8)%16 if advtrains.is_track_and_drives_on(cnode.name, advtrains.all_tracktypes) then local cconn1, cconn2=advtrains.get_track_connections(cnode.name, cnode.param2) return cconn1==bconn or cconn2==bconn end return false end local conn1=0 while conn1<16 and not istrackandbc(pos, conn1) do conn1=conn1+1 end if conn1>=16 then return nil, nil end local conn2=0 while conn2<16 and not istrackandbc(pos, conn2) or conn2==conn1 do conn2=conn2+1 end if conn2>=16 then return conn1, nil end return conn1, conn2 end function tp.placetrack(pos, nnpref) local conn1, conn2=tp.find_adjacent_tracks(pos) local tr=tp.tracks[nnpref] if not conn1 and not conn2 then minetest.set_node(pos, {name=nnpref.."_"..tr.default}) elseif conn1 and not conn2 then if tr.single_conn[conn1] then tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16) minetest.set_node(pos, tr.single_conn[conn1]) else minetest.set_node(pos, {name=nnpref.."_"..tr.default}) end elseif conn1 and conn2 then if tr.double_conn[conn1.."_"..conn2] then tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16) tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn2), (conn1+8)%16) minetest.set_node(pos, tr.double_conn[conn1.."_"..conn2]) elseif tr.single_conn[conn1] then --try at least one side tp.try_adjust_rail(tr, advtrains.dirCoordSet(pos, conn1), (conn1+8)%16) minetest.set_node(pos, tr.single_conn[conn1]) else minetest.set_node(pos, {name=nnpref.."_"..tr.default}) end end end function tp.try_adjust_rail(tr, pos, newdir) --is rail already connected? local node=minetest.get_node(pos) local conn1, conn2=advtrains.get_track_connections(node.name, node.param2) if newdir==conn1 or newdir==conn2 then return end --rail at other end? local adj1, adj2=tp.find_already_connected(pos) if adj1 and adj2 then return false--dont destroy existing track elseif adj1 and not adj2 then if tr.double_conn[adj1.."_"..newdir] then minetest.set_node(pos, tr.double_conn[adj1.."_"..newdir]) return true--if exists, connect new rail and old end end return false else if tr.single_conn[newdir] then--just rotate old rail to right orientation minetest.set_node(pos, tr.single_conn[newdir]) return true end return false end end function tp.register_track_placer(nnprefix, imgprefix, dispname) minetest.register_craftitem(nnprefix.."_placer",{ description = dispname, inventory_image = imgprefix.."_placer.png", wield_image = imgprefix.."_placer.png", groups={}, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type=="node" then local pos=pointed_thing.above if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to then tp.placetrack(pos, nnprefix) if not minetest.setting_getbool("creative_mode") then itemstack:take_item() end end end return itemstack end, }) end minetest.register_craftitem("advtrains:trackworker",{ description = "Track Worker Tool\n\nLeft-click: change rail type (straight/curve/switch)\nRight-click: rotate rail", groups = {cracky=1}, -- key=name, value=rating; rating=1..3. inventory_image = "advtrains_trackworker.png", wield_image = "advtrains_trackworker.png", stack_max = 1, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type=="node" then local pos=pointed_thing.under local node=minetest.get_node(pos) if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end if advtrains.is_train_at_pos(pos) then return end local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation) if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then print("[advtrains]railtype not workable by trackworker") return end local modext=tp.tracks[nnprefix].twrotate[suffix] if rotation==modext[#modext] then --increase param2 minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[1], param2=(node.param2+1)%4}) return else local modpos for k,v in pairs(modext) do if v==rotation then modpos=k end end if not modpos then print("[advtrains]rail not workable by trackworker") return end minetest.set_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) end advtrains.invalidate_all_paths() end end, on_use=function(itemstack, user, pointed_thing) if pointed_thing.type=="node" then local pos=pointed_thing.under local node=minetest.get_node(pos) if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end if advtrains.is_train_at_pos(pos) then return end local nnprefix, suffix, rotation=string.match(node.name, "^([^_]+)_([^_]+)(_?.*)$") if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then print("[advtrains]railtype not workable by trackworker") return end local nextsuffix=tp.tracks[nnprefix].twcycle[suffix] minetest.set_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2}) --invalidate trains advtrains.invalidate_all_paths() end end, }) --putting into right place advtrains.trackplacer=tp