DynamicTileCheckpoint.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
  3. DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. using System.Collections.Generic;
  19. using DotRecast.Recast;
  20. namespace DotRecast.Detour.Dynamic
  21. {
  22. public class DynamicTileCheckpoint
  23. {
  24. public readonly RcHeightfield heightfield;
  25. public readonly ISet<long> colliders;
  26. public DynamicTileCheckpoint(RcHeightfield heightfield, ISet<long> colliders)
  27. {
  28. this.colliders = colliders;
  29. this.heightfield = Clone(heightfield);
  30. }
  31. private RcHeightfield Clone(RcHeightfield source)
  32. {
  33. RcHeightfield clone = new RcHeightfield(source.width, source.height, source.bmin, source.bmax, source.cs, source.ch, source.borderSize);
  34. for (int z = 0, pz = 0; z < source.height; z++, pz += source.width)
  35. {
  36. for (int x = 0; x < source.width; x++)
  37. {
  38. RcSpan span = source.spans[pz + x];
  39. RcSpan prevCopy = null;
  40. while (span != null)
  41. {
  42. RcSpan copy = new RcSpan();
  43. copy.smin = span.smin;
  44. copy.smax = span.smax;
  45. copy.area = span.area;
  46. if (prevCopy == null)
  47. {
  48. clone.spans[pz + x] = copy;
  49. }
  50. else
  51. {
  52. prevCopy.next = copy;
  53. }
  54. prevCopy = copy;
  55. span = span.next;
  56. }
  57. }
  58. }
  59. return clone;
  60. }
  61. }
  62. }