aboutsummaryrefslogtreecommitdiff
path: root/src/util
Commit message (Expand)AuthorAge
* Modernize include guards and add missing ones (#9898)Awkor2020-05-23
* Add MetricsBackend with prometheus counter supportLoic Blot2020-04-29
* Fix truncation warning for F1000_MIN, F1000_MAXsfan52020-04-27
* Add server side translations capability (#9733)EvidenceB Kidscode2020-04-25
* Android: fix handling non-latin characters on older Android devices (#9309)Maksim2020-04-17
* Formspecs: Add state-selection to style elements (#9378)Hugues Ross2020-04-11
* GUIHyperText: Fix bug with UTF8 chars in action name + simplify UTF8 stringw ...Jean-Patrick Guerrero2020-03-07
* EnrichedString: Fix substr segfault caused by non-formatted textSmallJoker2020-01-24
* EnrichedString: Fix uninitialized variable m_default_lengthSmallJoker2020-01-23
* StaticText/EnrichedString: Styling support (#9187)SmallJoker2020-01-22
* Android: fix cyrillic characters, update iconv lib (#9117)Maksim2020-01-13
* Formspec: add hypertext elementPierre-Yves Rollo2019-11-03
* Move Quicktune code to util/ (#8871)ANAND2019-09-29
* Fix AreaStore's IDs persistence (#8888)SmallJoker2019-09-21
* util/hex.h: Remove whitespace-only line (#8460)ANAND2019-04-08
* util/hex.h: Reserve result space in hex_encode()starling132019-04-07
* numeric: Fix clang, broken since d5456daSmallJoker2019-02-09
* Use true pitch/yaw/roll rotations without loss of precision by pgimeno (#8019)Paul Ouellette2019-02-07
* DragonFly BSD is somewhat identical to FreeBSD (#8159)Leonid Bobrov2019-02-03
* Drop libgmp on Android and use mini-gmp (#8047)Loïc Blot2019-01-04
* Proselytize the network. Use IEEE F32 (#8030)SmallJoker2019-01-03
* ieee_float: Silence compiler warningSmallJoker2018-12-18
* Network: Send IEEE floats (#7768)SmallJoker2018-12-13
* 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
* Raycast: export exact pointing location (#6304)Dániel Juhász2018-08-16
* Replace auth.txt with SQLite auth database (#7279)Ben Deutsch2018-08-05
* Smoothed yaw rotation for objects (#6825)SmallJoker2018-08-02
* Fix build on gcc 5.0 (#7586)zeuner2018-07-26
* Fix memory leak in guiConfirmRegistrationHybridDog2018-07-06
* Fix buffer overrun in SRP (#7484)red-0012018-06-26
* Fix MurmurHash implementation to really be unaligned (#7482)sfan52018-06-26
* Use server's zoom fov for distant world loading.Lars Hofhansl2018-05-15
* Formspecs: Allow setting alpha value for the box[] elementThomas--S2018-04-23
* Zoom adjustDist(): Improve variable name (#7208)Paramat2018-04-05
* Fix last performance-type-promotion-in-math-fn problemsLoic Blot2018-04-04
* Optimize a little bit isBlockInSight, adjustDist & collisions (#7193)Loïc Blot2018-04-04
* Fix last clang-tidy reported problems for performance-type-promotion-in-math-fnLoic Blot2018-04-03
* Fix various clang-tidy reported performance-type-promotion-in-math-fnLoïc Blot2018-04-03
* Revert "Add an active object step time budget #6721"Lars Hofhansl2018-01-12
* Fix Wstringop-overflow warning from util/srp.cpp (#6855)you2018-01-04
* Fix rounding error in g/set_node caused by truncation to floatrubenwardy2017-12-26
* directiontables: Fix MSVC compiler error (#6785)adrido2017-12-14
* 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
* directiontables.cpp: fix a warning reported by VS2017Loic Blot2017-10-17
* Real global textures (#6105)Vitaliy2017-10-15
* Use a Buffer instead of SharedBuffer in ConnectionCommandLoic Blot2017-09-05
* Remove DSTACK support (#6346)Loïc Blot2017-08-30
lass="hl opt">) local posr = advtrains.round_vector_floor_y(pos) local node_ok, conns, rhe = advtrains.get_rail_info_at(pos, train.drives_on) if not node_ok then return node_ok end local mconnid = advtrains.get_matching_conn(connid, #conns) train.index = rel_index train.path = { [0] = { x=posr.x, y=posr.y+rhe, z=posr.z } } train.path_cn = { [0] = connid } train.path_cp = { [0] = mconnid } train.path_dist = {} train.path_dir = { [0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c) } train.path_ext_f=0 train.path_ext_b=0 train.path_trk_f=0 train.path_trk_b=0 train.path_req_f=0 train.path_req_b=0 advtrains.occ.set_item(train.id, posr, 0) return true end -- Sets position and connid to properly restore after a crash, e.g. in order -- to save the train or to invalidate its path -- Assumes that the train is in clean state -- if invert ist true, setrestore will use the end index function advtrains.path_setrestore(train, invert) local idx = train.index if invert then idx = train.end_index end local pos, connid, frac = advtrains.path_getrestore(train, idx, invert, true) train.last_pos = pos train.last_connid = connid train.last_frac = frac end -- Get restore position, connid and frac (in this order) for a train that will originate at the passed index -- If invert is set, it will return path_cp and multiply frac by -1, in order to reverse the train there. function advtrains.path_getrestore(train, index, invert) local idx = index local cns = train.path_cn if invert then cns = train.path_cp end local fli = atfloor(index) advtrains.path_get(train, fli) if fli > train.path_trk_f then fli = train.path_trk_f end if fli < train.path_trk_b then fli = train.path_trk_b end return advtrains.path_get(train, fli), cns[fli], (idx - fli) * (invert and -1 or 1) end -- Invalidates a path -- this is supposed to clear stuff from the occupation tables -- This function throws a warning whenever any code calls it while the train steps are run, since that must not happen. -- The ignore_lock parameter can be used to ignore this, however, it should then be accompanied by a call to train_ensure_init -- before returning from the calling function. function advtrains.path_invalidate(train, ignore_lock) if advtrains.lock_path_inval and not ignore_lock then atwarn("Train ",train.train_id,": Illegal path invalidation has occured during train step:") atwarn(debug.traceback()) end if train.path then for i,p in pairs(train.path) do advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(p)) end end train.path = nil train.path_dist = nil train.path_cp = nil train.path_cn = nil train.path_dir = nil train.path_ext_f=0 train.path_ext_b=0 train.path_trk_f=0 train.path_trk_b=0 train.path_req_f=0 train.path_req_b=0 train.dirty = true end -- Prints a path using the passed print function -- This function should be 'atprint', 'atlog', 'atwarn' or 'atdebug', because it needs to use print_concat_table function advtrains.path_print(train, printf) printf("path_print: tid =",train.train_id," index =",train.index," end_index =",train.end_index," vel =",train.velocity) if not train.path then printf("path_print: Path is invalidated/inexistant.") return end printf("i: CP Position Dir CN ->Dist->") for i = train.path_ext_b, train.path_ext_f do if i==train.path_trk_b then printf("--Back on-track border here--") end printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ->",train.path_dist[i],"->") if i==train.path_trk_f then printf("--Front on-track border here--") end end end -- Function to get path entry at a position. This function will automatically calculate more of the path when required. -- returns: pos, on_track function advtrains.path_get(train, index) if not train.path then error("For train "..train.id..": path_get called but there's no path set yet!") end if index ~= atfloor(index) then error("For train "..train.id..": Called path_get() but index="..index.." is not a round number") end local pef = train.path_ext_f while index > pef do local pos = train.path[pef] local connid = train.path_cn[pef] local node_ok, this_conns, adj_pos, adj_connid, conn_idx, nextrail_y, next_conns if pef == train.path_trk_f then node_ok, this_conns = advtrains.get_rail_info_at(pos) if not node_ok then error("For train "..train.id..": Path item "..pef.." on-track but not a valid node!") end adj_pos, adj_connid, conn_idx, nextrail_y, next_conns = advtrains.get_adjacent_rail(pos, this_conns, connid, train.drives_on) end pef = pef + 1 if adj_pos then advtrains.occ.set_item(train.id, adj_pos, pef) adj_pos.y = adj_pos.y + nextrail_y train.path_cp[pef] = adj_connid local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns) train.path_cn[pef] = mconnid train.path_dir[pef] = advtrains.conn_angle_median(next_conns[adj_connid].c, next_conns[mconnid].c) train.path_trk_f = pef else -- off-track fallback behavior adj_pos = advtrains.pos_add_angle(pos, train.path_dir[pef-1]) --atdebug("Offtrack overgenerating(front) at",adj_pos,"index",peb,"trkf",train.path_trk_f) train.path_dir[pef] = train.path_dir[pef-1] end train.path[pef] = adj_pos train.path_dist[pef - 1] = vector.distance(pos, adj_pos) end train.path_ext_f = pef local peb = train.path_ext_b while index < peb do local pos = train.path[peb] local connid = train.path_cp[peb] local node_ok, this_conns, adj_pos, adj_connid, conn_idx, nextrail_y, next_conns if peb == train.path_trk_b then node_ok, this_conns = advtrains.get_rail_info_at(pos) if not node_ok then error("For train "..train.id..": Path item "..peb.." on-track but not a valid node!") end adj_pos, adj_connid, conn_idx, nextrail_y, next_conns = advtrains.get_adjacent_rail(pos, this_conns, connid, train.drives_on) end peb = peb - 1 if adj_pos then advtrains.occ.set_item(train.id, adj_pos, peb) adj_pos.y = adj_pos.y + nextrail_y train.path_cn[peb] = adj_connid local mconnid = advtrains.get_matching_conn(adj_connid, #next_conns) train.path_cp[peb] = mconnid train.path_dir[peb] = advtrains.conn_angle_median(next_conns[mconnid].c, next_conns[adj_connid].c) train.path_trk_b = peb else -- off-track fallback behavior adj_pos = advtrains.pos_add_angle(pos, train.path_dir[peb+1] + math.pi) --atdebug("Offtrack overgenerating(back) at",adj_pos,"index",peb,"trkb",train.path_trk_b) train.path_dir[peb] = train.path_dir[peb+1] end train.path[peb] = adj_pos train.path_dist[peb] = vector.distance(pos, adj_pos) end train.path_ext_b = peb if index < train.path_req_b then train.path_req_b = index end if index > train.path_req_f then train.path_req_f = index end return train.path[index], (index<=train.path_trk_f and index>=train.path_trk_b) end -- interpolated position to fractional index given, and angle based on path_dir -- returns: pos, angle(yaw), p_floor, p_ceil function advtrains.path_get_interpolated(train, index) local i_floor = atfloor(index) local i_ceil = i_floor + 1 local frac = index - i_floor local p_floor = advtrains.path_get(train, i_floor) local p_ceil = advtrains.path_get(train, i_ceil) -- Note: minimal code duplication to path_get_adjacent, for performance local a_floor = train.path_dir[i_floor] local a_ceil = train.path_dir[i_ceil] local ang = advtrains.minAngleDiffRad(a_floor, a_ceil) return vector.add(p_floor, vector.multiply(vector.subtract(p_ceil, p_floor), frac)), (a_floor + frac * ang)%(2*math.pi), p_floor, p_ceil end -- returns the 2 path positions directly adjacent to index and the fraction on how to interpolate between them -- returns: pos_floor, pos_ceil, fraction function advtrains.path_get_adjacent(train, index) local i_floor = atfloor(index) local i_ceil = i_floor + 1 local frac = index - i_floor local p_floor = advtrains.path_get(train, i_floor) local p_ceil = advtrains.path_get(train, i_ceil) return p_floor, p_ceil, frac end function advtrains.path_get_index_by_offset(train, index, offset) local off = offset local idx = atfloor(index) -- go down to floor. Calculate required path_dist advtrains.path_get_adjacent(train, idx) off = off + ((index-idx) * train.path_dist[idx]) --atdebug("pibo: 1 off=",off,"idx=",idx," index=",index) -- then walk the path back until we overshoot (off becomes >=0) while off<0 do idx = idx - 1 advtrains.path_get_adjacent(train, idx) off = off + train.path_dist[idx] end --atdebug("pibo: 2 off=",off,"idx=",idx) -- then walk the path forward until we would overshoot while off - train.path_dist[idx] >= 0 do idx = idx + 1 advtrains.path_get_adjacent(train, idx) if not train.path_dist[idx] then for i=-5,5 do atdebug(idx+i,train.path_dist[idx+i]) end end off = off - train.path_dist[idx] end --atdebug("pibo: 3 off=",off,"idx=",idx," returns:",idx + (off / train.path_dist[idx])) -- we should now be on the floor of the index we actually want. -- give them the rest! return idx + (off / train.path_dist[idx]) end local PATH_CLEAR_KEEP = 4 function advtrains.path_clear_unused(train) local i for i = train.path_ext_b, train.path_req_b - PATH_CLEAR_KEEP do advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i])) train.path[i] = nil train.path_dist[i-1] = nil train.path_cp[i] = nil train.path_cn[i] = nil train.path_dir[i] = nil train.path_ext_b = i + 1 end for i = train.path_ext_f,train.path_req_f + PATH_CLEAR_KEEP,-1 do advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i])) train.path[i] = nil train.path_dist[i] = nil train.path_cp[i] = nil train.path_cn[i] = nil train.path_dir[i+1] = nil train.path_ext_f = i - 1 end train.path_trk_b = math.max(train.path_trk_b, train.path_ext_b) train.path_trk_f = math.min(train.path_trk_f, train.path_ext_f) train.path_req_f = math.ceil(train.index) train.path_req_b = math.floor(train.end_index or train.index) end function advtrains.path_lookup(train, pos) local cp = advtrains.round_vector_floor_y(pos) for i = train.path_ext_b, train.path_ext_f do if vector.equals(advtrains.round_vector_floor_y(train.path[i]), cp) then return i end end return nil end