187 Commits

Author SHA1 Message Date
FcAYH
b0ed8b7a3c
fixed a typo (countour -> contour) (#617) 2023-03-25 13:22:02 -04:00
Graham Pentheny
405cc095ab Add missing null check in rcFreePolyMeshDetail 2023-01-02 17:20:10 -05:00
Graham Pentheny
a4be369ac3 Removed rcPolyMeshDetail destructor to maintain backwards-compatibility
https://github.com/recastnavigation/recastnavigation/pull/598#discussion_r1059522812
2023-01-02 14:05:02 -05:00
Graham Pentheny
b43c82c808
Removed _USE_MATH_DEFINES directive (#596)
Since none of the `M_` prefixed constants are used anywhere in the code, this is unnecessary.  It's also Windows-specific, so these non-standard defines shouldn't be used anyway.

Ref: https://learn.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=msvc-170
2022-12-29 15:09:01 -05:00
Graham Pentheny
7501007439
More Recast code cleanup (#598)
* Code formatting, dosctring consolidation, spelling fixes
* Fixed rule-of-three for rcCompactHeightfield, rcHeightfieldLayerSet, rcContourSet, rcPolyMesh
* Better names for variables and parameters mostly in Recast.cpp
* Added constructor and destructor to rcPolyMeshDetail
* Remove redundant default-value specifiers in constructor initialization lists.
2022-12-29 14:57:46 -05:00
Graham Pentheny
b51925bb87
Cleanup Rasterization Code (#592)
Mostly just improving variable names for clarity.

Removed a redundant base-case check in AddSpan that resulted in a small but measurable perf improvement due to removing a branch. Also tightened up the bounding box overlap check so it early-outs faster, which also has a small perf improvement to rasterization times.

Updated docstrings for user-facing functions.

* Moved docstring comments to the header with the rest of the docstring
* Removed unused function
* Make a cpp-only function static
* Added docstring for rasterizeTri
* Use spaces to indent function parameter lists so they look good regardless of the editor's tab width
* Better parameter names for rcClamp
* Cleanup code formatting, a couple variable names, and some comments in rasterizeTri
* Clean up dividePoly, added rcAxis enum
* Cleanup rasterizeTri docstring
* Faster overlapBounds check in rasterization
* Renamed some vars in rasterizeTri
* cleanup addSpan and remove redundant branch
* addSpan docstring
* Cleanup the implementations of rcRasterizeTriangle and rcRasterizeTriangles overloads
* Added docstrings and renamed vars in rcAllocSpan and rcFreeSpan
* Clean up rcRasterizeTriangle and rcRasterizeTriangles in the header.  Removed redundant const qualifiers on value parameters
* Better parameter names for rasterizeTri, updated docstring, fixed some incorrect comments
* Improved parameter names of rcRasterizeTriangle, rcRasterizeTriangles, and rcAddSpan
* Fixed some old variable names referenced in the docstring for rcAddSpan
2022-12-22 12:16:04 -05:00
Piotr Piastucki
3901c5854c
Fix incorrect rasterization at tile borders (#476)
* Fix incorrect rasterization at tile borders

Clip the polygon at the tile border and disregard coordinates outside of
the tile before clamping.

* Added unit test with minimal repro case for the rasterization issue fixed in PR #476

Co-authored-by: Graham Pentheny <graham.pentheny@gmail.com>
2022-11-23 02:42:03 -05:00
Graham Pentheny
5111139558
Fixes for many low-severity compiler warnings (#576)
* Fixes for many low-severity compiler warnings

Mostly a lot of pedantic things like end-of-file newlines and commas on the last enum value.  However some fixes like the weak v-tables warnings fixes might help with code gen.  It's unclear if the linker is able to elide multiple copies of the same type's v-table in different translation units, (sometimes it can) but these fixes ensure we don't have to rely on it.
2022-11-11 21:03:03 -05:00
Brian Swenson
c02d6fa81e -Wunused-but-set-variable flagged variables removed 2022-06-03 02:24:29 -04:00
Gleb Mazovetskiy
e75adf86f9
Avoid reallocs of temp vectors (#467)
* Use clear() instead of resize(0) for temp vectors

Nicer style

* rcVectorBase::resize: Avoid realloc on grow

When capacity is sufficient, do not realloc the whole buffer

* rcVector: Grow exponentially on resize
2021-02-15 12:27:21 +01:00
Icecream95 (gitlab.com/icecream95)
57610fa6ef Explicitly define winding as being signed 2019-10-21 14:44:25 +02:00
Jakob Botsch Nielsen
33a9eb1cce Document detail triangle edge flags 2019-03-16 16:18:23 +01:00
MoYummy
13dc549bbe Improve triangulateHull to start from an ear with shortest perimeter 2018-08-25 12:18:27 +02:00
Maciej Babinski
ba12abead9 Add more constructors. 2018-05-22 13:09:26 +02:00
mbabinski-at-google
9235b4a0c4 Add rcNew/rcDelete, template functions that allocate/deallocate objects using rcAlloc/rcFree. (#324)
Add rcNew/rcDelete, template functions that allocate/deallocate objects using rcAlloc/rcNew.
The intention is to use these to move construction logic out of rcAllocateFooObject/rcFreeFooObject and into constructors/destructors, giving users flexbility in how objects are allocated. In particular, this allows stack allocation.
2018-05-18 15:40:37 +02:00
mbabinski-at-google
1284a2b191 Remove placement-new in RecastRegion.cpp in favor of rcTempVector. (#326) 2018-05-18 13:50:42 +02:00
mbabinski-at-google
3ddb9ba074 Convert lvlStacks to be vectors of structs instead of a bag of ints. (#323) 2018-05-17 17:35:05 +02:00
Maciej Babinski
bec073c947 Switch expandRegions to using a rcTempVector of structs rather than a blob of ints.
Also updates rcVector::clear() to not require the contained type to be default-constructible.
2018-05-15 16:43:11 +02:00
mbabinski-at-google
fa7debb0c3 Add homebrewed rcVector class and tests, and use it to implement rcIntArray. (#318)
This implements most of the std::vector interface, with some minor elisions of
infrequently used methods such as "insert", and some STL bookkeeping.
Performance is favorable compared to std::vector, and, in some cases, somewhat
better than naive code to manually manage a malloc'd dynamic array.

BM_FlatArray_Push:                     100 iterations in   72889721 nanos:  728897.21 nanos/it
BM_FlatArray_Fill:                     100 iterations in    2700746 nanos:   27007.46 nanos/it
BM_FlatArray_Memset:                   100 iterations in    2687810 nanos:   26878.10 nanos/it
BM_rcVector_Push:                      100 iterations in   51114316 nanos:  511143.16 nanos/it
BM_rcVector_PushPreallocated:          100 iterations in    9532106 nanos:   95321.06 nanos/it
BM_rcVector_Assign:                    100 iterations in    2371534 nanos:   23715.34 nanos/it
BM_rcVector_AssignIndices:             100 iterations in    2573052 nanos:   25730.52 nanos/it
BM_rcVector_Resize:                    100 iterations in    2455761 nanos:   24557.61 nanos/it
BM_stdvector_Push:                     100 iterations in   71739167 nanos:  717391.67 nanos/it
BM_stdvector_PushPreallocated:         100 iterations in   15723737 nanos:  157237.37 nanos/it
BM_stdvector_Assign:                   100 iterations in    2564985 nanos:   25649.85 nanos/it
BM_stdvector_AssignIndices:            100 iterations in    5174923 nanos:   51749.23 nanos/it
BM_stdvector_Resize:                   100 iterations in    2520054 nanos:   25200.54 nanos/it
2018-05-13 16:22:56 +02:00
mbabinski-at-google
18562383f4 Remove redundant copying in rcBuildRegions. (#314)
Remove dstReg and dstDist from rcBuildRegions entirely -- just use temporary scratch space in expandRegions.
This saves a considerable amount of time when the number of spans is large. A sample map tried has 16M spans, and only writes at most 4000 of them.
2018-04-27 22:08:52 +02:00
elsid
367065415c Unconditionally initialize rcCompactHeightfield borderSize
To avoid uninitialized value when borderSize <= 0.
2018-03-20 00:01:57 +01:00
Domenico Albani
dfd40071c5 Assertion failure custom function (#250)
Implement custom functions to be called when an assertion fails.
2017-01-23 23:02:46 +01:00
Ben Hymers
d11c1bdbac Fix multiline comment warning 2017-01-12 11:31:29 +00:00
Acai
787ce2c18d Fix log errors in rcBuildLayerRegions. (#242) 2016-11-27 12:12:54 +01:00
Jakob Botsch Nielsen
7a88c13946 Add an assertion for alloc in rcIntArray::doResize (#219)
Fix #170
2016-07-13 11:30:13 +02:00
Jakob Botsch Nielsen
9763478a9a Detect all overflows in rcBuildHeightfieldLayers (#214)
The function now fails if it fails to insert all layers because the
array overflowed. Previously this would silently corrupt the heap.
2016-07-08 01:51:23 +03:00
grahamboree
c9bacf3c9c Unit tests for a good number of Recast functions.
These are by no means complete coverage of the functions they test, but are at least a start.  For consistency, all floating point comparisons use Approx(), regardless of whether they need to or not.

Removed unnecessary C++11 unique_ptr stuff, now that rcHeightfield has a constructor and destructor.
2016-03-29 01:04:51 -04:00
grahamboree
61dbce80e9 Added Constructor and Destructor to rcHeightfield. 2016-03-20 18:42:14 -04:00
Ben Hymers
d9c6fc58ce Remove redundant double assignment 2016-03-15 08:02:28 +00:00
Ben Hymers
e344fe8295 Remove dead code in rcBuildRegions
The code is checking for an invalid region ID, after setting it to a valid value
2016-03-15 07:56:57 +00:00
Ben Hymers
c208fd332c Minor typo and style changes 2016-03-14 09:03:40 +00:00
Graham Pentheny
6ee79b25a8 Merge pull request #169 from wbierman/master
Detect, log and fail in the event of an overflow of region ids in watershed partitioning
2016-01-21 13:21:03 -05:00
Bill Bierman
e49017ac63 Detect, log and fail in the event of an overflow of region ids in watershed partitioning 2016-01-21 07:07:40 -10:00
Graham Pentheny
b7a83e0afb Fixed rule of 3 violations in many places.
* Added virtual qualifier to a few destructors in subclasses.
* Removed a few empty destructors that didn't need to be explicitly defined.
* Fixed a few typos
* Removed unnecessary empty virtual destructors in some classes with parent's who derrived from a class with a virtual destructor
2016-01-20 11:57:32 -05:00
Bill Bierman
92bc6ce5bd Change if to else-if to avoid unnecessary comparison 2016-01-19 11:34:04 -10:00
Ben Hymers
551d1b250e Use size_t for rcAlloc and dtAlloc
This was already partly done by @cexikitin in #65, I'm just finishing it
off in their absence!

Closes #65
2016-01-15 00:36:18 +00:00
Jakob Botsch Nielsen
0143337a64 Merge pull request #154 from Janiels/fix-detail-unsampled-heights
Increase recover radius for unsampled heights
2016-01-14 22:18:43 +01:00
Jakob Botsch Nielsen
b99d62047b Increase recover radius for unsampled heights
When the detail mesh sampling sees an unset height it previously tried
to recover by looking for heights of neighbors. When the heightfield was
not eroded this recovery would fail since the contour simplification
could mean that the nearest valid cell was further away than a neighbor.
We now walk adjacent cells in a spiral to find a height and do this
depending on the max simplification error.

Fix #153
2016-01-14 19:20:43 +01:00
Jakob Botsch Nielsen
f002387afc Merge pull request #151 from Janiels/fix-detail-sampling
Use flood fill for potentially overlapping polys
2016-01-14 16:48:13 +01:00
Jakob Botsch Nielsen
5fce286267 Use flood fill for potentially overlapping polys
This changes the detail sampling to find height data by using the flood
fill method for polygons that were merged because of a border vertex
removal. This could potentially cause overlapping polygons to receive
the same region IDs which would later make the fast-path sampling in
getHeightData sample the wrong heights.

Also includes optimizations for this path and getHeightData itself.
Previously the seeding was responsible for 25% of the total time spent
in getHeightData in these cases. We now use the direction and prefer
moving directly towards the center of the polygon. This makes the
overhead of seedArrayWithPolyCenter virtually nonexistent (~2%
according to profiling).

Fix #146
2016-01-14 11:25:48 +01:00
Jakob Botsch Nielsen
c1f9fd8406 Fix heap corruption when collecting region layers
The collecting could overflow the neighbours array due to a missing boundary
check.

Fix #30
2016-01-02 13:33:27 +01:00
Rafael Stahl
15025e8519 handle the case when allocSpan fails to allocate memory. adds bool return types to rcAddSpan, rcRasterizeTriangle and rcRasterizeTriangles 2015-12-18 16:41:02 +01:00
Rafael Stahl
6d3c9b38ba add rcScopedTimer to fix timers not being stopped on all paths and to prevent it in the future. 2015-12-18 14:48:31 +01:00
jackpoz
18b537c23f Fix 2 "unused parameter" build warnings 2015-06-28 21:32:16 +02:00
CharlesJClark
6730d4ddda Update RecastMesh.cpp
Fixed validation checks of allocations.
2015-06-19 09:33:27 -07:00
Kromster80
3ca4db4864 Fixed loop overrun 2015-02-19 14:03:59 +03:00
Kromster80
ce304d195f Removed superflous memset
We have already filled whole set of layers with zeroes at line 477. It looks like we don't need to fill the layers once again. Right?
2014-12-23 11:10:05 +03:00
Mikko Mononen
ff7549bb57 Merge pull request #51 from Kromster80/HULL-UNDEF
Renamed enums to avoid name collisions with "hull" variables
2014-12-13 13:55:33 +02:00
Mikko Mononen
b869953fd2 Merge pull request #54 from Kromster80/var
Removed unnecessary variable assignment
2014-12-13 13:44:45 +02:00
Mikko Mononen
ace7f1f19a Merge pull request #52 from Kromster80/typo-fixes
Typo fixes
2014-12-13 13:35:40 +02:00