aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
Commit message (Expand)AuthorAge
* Rework use_texture_alpha to provide three opaque/clip/blend modessfan52021-01-29
* Drop never documented 'alpha' property from nodedefsfan52021-01-29
* Removed some obsolete code (#10562)Zughy2021-01-21
* Fix ObjectRef errors due to lua_isnil() (#10564)Zughy2020-11-04
* Fix segfault in deprecation logging due to tail call, log by default (#10174)rubenwardy2020-10-31
* Decouple entity minimap markers from nametags replacing with show_on_minimap ...sfan52020-10-19
* Pass ContentFeatures as reference to read_content_features (#10464)JosiahWI2020-10-13
* Add a short_description to be used by mods (#8980)DS2020-10-09
* Remove unused functions reported by cppcheck (#10463)SmallJoker2020-10-05
* Fix precision not working in hud_change (#10186)Lars Müller2020-08-12
* Quick workaround for crashing destructor on Mingw32sfan52020-07-09
* Make shading of CAOs optional (#10033)Danila Shutov2020-06-16
* Lua API: Log incorrect parameter types as error (#9954)SmallJoker2020-06-01
* CSM: Fix crashing minetest.get_item_def()sfan52020-05-20
* Rework functionality of leveled nodes (#9852)Wuzzy2020-05-19
* Damage texture modifier (#9833)Lars Müller2020-05-11
* Add support for statbar “off state” icons (#9462)Wuzzy2020-05-11
* Expose collided objects in moveresultsfan52020-05-06
* Rename moveresult speed to velocitySmallJoker2020-05-05
* Expose collision information to LuaEntity on_stepsfan52020-04-27
* Script: Enforce type checks if not nil (#9748)SmallJoker2020-04-27
* Fix configuration caching in log_deprecated (#9697)HybridDog2020-04-22
* Fix parsing JSON with large integers (#9674)sfan52020-04-15
* scriptapi: Some small optimizations to value pushing (#9669)sfan52020-04-14
* Improve waypoints and add image variant (#9480)Lars Müller2020-04-11
* Fix broken config check in 659245asfan52020-04-11
* Move PlayerSAO to dedicated filesLoic Blot2020-04-11
* Move serveractiveobject & unitsaoLoic Blot2020-04-11
* Work around LuaJIT issues on aarch64 (#9614)sfan52020-04-08
* Fix 'the the' typos in comments (#9554)LNJ2020-04-04
* set_sky improvements, set_sun, set_moon and set_starsJordach2020-03-05
* Move core.get_connected_players() implementation to C++sfan52020-02-23
* Refactor Script API's log_deprecatedsfan52020-02-23
* Improve core.sound_play with ephemeral sounds and player exclusionsfan52020-02-01
* Remove unused weight property from objects (#9320)Wuzzy2020-01-22
* Add z-index management to HUDPierre-Yves Rollo2019-12-06
* Change some usages of "deprecated" to "obsolete" (#9062)random-geek2019-10-29
* Punchwear (improved) (#8959)sfan52019-09-22
* Do not add group values of zero to group lists. (#8751)Beha2019-08-07
* Move the clamping of hp/breath when their maximums change to read_object_prop...Beha2019-07-30
* HTTP API: Allow binary downloads and headers (#8573)SmallJoker2019-06-06
* Abort when trying to set a not registered node (#7011)HybridDog2019-03-07
* Consistent HP and damage types (#8167)SmallJoker2019-02-10
* Fix various bugs (Anticheat, Lua helpers) (#8013)SmallJoker2019-01-06
* Proselytize the network. Use IEEE F32 (#8030)SmallJoker2019-01-03
* Clean up stack after script_get_backtrace (#7854)Michael Muller2018-11-28
* Raycast: export exact pointing location (#6304)Dániel Juhász2018-08-16
* Add a MSVC / Windows compatible snprintf function (#7353)nOOb31672018-07-22
* Lua templating reading (part 4): s16, v2s16, v2f (#7512)Loïc Blot2018-07-08
* Modernize lua read (part 2 & 3): C++ templating assurance (#7410)Loïc Blot2018-06-30
=0 ? p : p-d+1) / d; } inline v2s16 getContainerPos(v2s16 p, s16 d) { return v2s16( getContainerPos(p.X, d), getContainerPos(p.Y, d) ); } inline v3s16 getContainerPos(v3s16 p, s16 d) { return v3s16( getContainerPos(p.X, d), getContainerPos(p.Y, d), getContainerPos(p.Z, d) ); } inline v2s16 getContainerPos(v2s16 p, v2s16 d) { return v2s16( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y) ); } inline v3s16 getContainerPos(v3s16 p, v3s16 d) { return v3s16( getContainerPos(p.X, d.X), getContainerPos(p.Y, d.Y), getContainerPos(p.Z, d.Z) ); } inline bool isInArea(v3s16 p, s16 d) { return ( p.X >= 0 && p.X < d && p.Y >= 0 && p.Y < d && p.Z >= 0 && p.Z < d ); } inline bool isInArea(v2s16 p, s16 d) { return ( p.X >= 0 && p.X < d && p.Y >= 0 && p.Y < d ); } inline bool isInArea(v3s16 p, v3s16 d) { return ( p.X >= 0 && p.X < d.X && p.Y >= 0 && p.Y < d.Y && p.Z >= 0 && p.Z < d.Z ); } inline s16 rangelim(s16 i, s16 max) { if(i < 0) return 0; if(i > max) return max; return i; } #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) { if(p.X < 0) p.X = 0; if(p.Y < 0) p.Y = 0; if(p.Z < 0) p.Z = 0; if(p.X > d-1) p.X = d-1; if(p.Y > d-1) p.Y = d-1; if(p.Z > d-1) p.Z = d-1; return p; } /* See test.cpp for example cases. wraps degrees to the range of -360...360 NOTE: Wrapping to 0...360 is not used because pitch needs negative values. */ inline float wrapDegrees(float f) { // Take examples of f=10, f=720.5, f=-0.5, f=-360.5 // This results in // 10, 720, -1, -361 int i = floor(f); // 0, 2, 0, -1 int l = i / 360; // NOTE: This would be used for wrapping to 0...360 // 0, 2, -1, -2 /*if(i < 0) l -= 1;*/ // 0, 720, 0, -360 int k = l * 360; // 10, 0.5, -0.5, -0.5 f -= float(k); return f; } /* Wrap to 0...360 */ inline float wrapDegrees_0_360(float f) { // Take examples of f=10, f=720.5, f=-0.5, f=-360.5 // This results in // 10, 720, -1, -361 int i = floor(f); // 0, 2, 0, -1 int l = i / 360; // Wrap to 0...360 // 0, 2, -1, -2 if(i < 0) l -= 1; // 0, 720, 0, -360 int k = l * 360; // 10, 0.5, -0.5, -0.5 f -= float(k); return f; } /* Wrap to -180...180 */ inline float wrapDegrees_180(float f) { f += 180; f = wrapDegrees_0_360(f); f -= 180; return f; } /* Pseudo-random (VC++ rand() sucks) */ int myrand(void); void mysrand(unsigned seed); #define MYRAND_MAX 32767 int myrand_range(int min, int max); /* Miscellaneous functions */ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); /* Some helper stuff */ #define MYMIN(a,b) ((a)<(b)?(a):(b)) #define MYMAX(a,b) ((a)>(b)?(a):(b)) /* Returns nearest 32-bit integer for given floating point number. <cmath> and <math.h> in VC++ don't provide round(). */ inline s32 myround(f32 f) { return floor(f + 0.5); } /* Returns integer position of node in given floating point position */ inline v3s16 floatToInt(v3f p, f32 d) { v3s16 p2( (p.X + (p.X>0 ? d/2 : -d/2))/d, (p.Y + (p.Y>0 ? d/2 : -d/2))/d, (p.Z + (p.Z>0 ? d/2 : -d/2))/d); return p2; } /* Returns floating point position of node in given integer position */ inline v3f intToFloat(v3s16 p, f32 d) { v3f p2( (f32)p.X * d, (f32)p.Y * d, (f32)p.Z * d ); return p2; } // Random helper. Usually d=BS inline core::aabbox3d<f32> getNodeBox(v3s16 p, float d) { return core::aabbox3d<f32>( (float)p.X * d - 0.5*d, (float)p.Y * d - 0.5*d, (float)p.Z * d - 0.5*d, (float)p.X * d + 0.5*d, (float)p.Y * d + 0.5*d, (float)p.Z * d + 0.5*d ); } class IntervalLimiter { public: IntervalLimiter(): m_accumulator(0) { } /* dtime: time from last call to this method wanted_interval: interval wanted return value: true: action should be skipped false: action should be done */ bool step(float dtime, float wanted_interval) { m_accumulator += dtime; if(m_accumulator < wanted_interval) return false; m_accumulator -= wanted_interval; return true; } protected: float m_accumulator; }; /* Splits a list into "pages". For example, the list [1,2,3,4,5] split into two pages would be [1,2,3],[4,5]. This function computes the minimum and maximum indices of a single page. length: Length of the list that should be split page: Page number, 1 <= page <= pagecount pagecount: The number of pages, >= 1 minindex: Receives the minimum index (inclusive). maxindex: Receives the maximum index (exclusive). Ensures 0 <= minindex <= maxindex <= length. */ inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxindex) { if(length < 1 || pagecount < 1 || page < 1 || page > pagecount) { // Special cases or invalid parameters minindex = maxindex = 0; } else if(pagecount <= length) { // Less pages than entries in the list: // Each page contains at least one entry minindex = (length * (page-1) + (pagecount-1)) / pagecount; maxindex = (length * page + (pagecount-1)) / pagecount; } else { // More pages than entries in the list: // Make sure the empty pages are at the end if(page < length) { minindex = page-1; maxindex = page; } else { minindex = 0; maxindex = 0; } } } #endif