Skip to content

Commit 1f110bc

Browse files
committed
Added DislodgePixelRing to SceneMan
1 parent 232ef5b commit 1f110bc

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
128128

129129
- New `SceneMan` Lua functions:
130130
`DislodgePixelCircle(Vector centre, float radius, bool deletePixels)`, which calls `DislodgePixel()` on all pixels in a given circle, returns them as an iterable list. The bool is an optional argument to delete all found pixels immediately; defaults to `false`.
131-
`DislodgePixelBox(Vector upperLeftCorner, Vector lowerRightCorner, bool deletePixels)`, similar to above but in a rectangular area.
132-
`DislodgePixelLine(Vector startPos, Vector ray, int skip, bool deletePixels)`, calls `DislodgePixel()` on all pixels in a line, like above, but similar in function to a ray cast.
133-
131+
`DislodgePixelRing(Vector centre, float innerRadius, float outerRadius, bool deletePixels)`, same as above but additionally ignores pixels within the inner radius.
132+
`DislodgePixelBox(Vector upperLeftCorner, Vector lowerRightCorner, bool deletePixels)`, similar to above, but in a rectangular area defined by upper left- and lower right corners.
133+
`DislodgePixelLine(Vector startPos, Vector ray, int skip, bool deletePixels)`, calls `DislodgePixel()` on all pixels in a line, like above. Similar in function to a ray cast, so pixels can be skipped.
134134

135135
</details>
136136

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, SceneMan) {
338338
.def("DislodgePixelCircle", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float radius, bool deletePixels) const) & SceneMan::DislodgePixelCircle, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
339339
.def("DislodgePixelCircle", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float radius) const) & SceneMan::DislodgePixelCircleNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
340340
.def("DislodgePixelBox", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) const) & SceneMan::DislodgePixelBox, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
341-
.def("DislodgePixelBox", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner) const) & SceneMan::DislodgePixelBoxNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator);
341+
.def("DislodgePixelBox", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& upperLeftCorner, const Vector& lowerRightCorner) const) & SceneMan::DislodgePixelBoxNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
342+
.def("DislodgePixelRing", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) const) & SceneMan::DislodgePixelRing, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator)
343+
.def("DislodgePixelRing", (const std::vector<MovableObject*>* (SceneMan::*)(const Vector& centre, float innerRadius, float outerRadius) const) & SceneMan::DislodgePixelRingNoBool, luabind::adopt(luabind::return_value) + luabind::return_stl_iterator);
342344
}
343345

344346
LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, CameraMan) {

Source/Managers/SceneMan.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,33 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelCircleNoBool(const Vector& c
953953
return DislodgePixelCircle(centre, radius, false);
954954
}
955955

956+
std::vector<MovableObject*>* SceneMan::DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels) {
957+
// Account for users inputting radii in the wrong order
958+
if (outerRadius < innerRadius) {
959+
std::swap(outerRadius, innerRadius);
960+
}
961+
962+
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
963+
for (int x = 0; x <= static_cast<int>(outerRadius) * 2; x++) {
964+
for (int y = 0; y <= static_cast<int>(outerRadius) * 2; y++) {
965+
Vector checkPos = Vector(static_cast<float>(x) - outerRadius, static_cast<float>(y) - outerRadius) + centre;
966+
Vector distance = ShortestDistance(centre, checkPos, true);
967+
if (!distance.MagnitudeIsGreaterThan(outerRadius) && !distance.MagnitudeIsLessThan(innerRadius)) {
968+
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
969+
if (px) {
970+
pixelList->push_back(px);
971+
}
972+
}
973+
}
974+
}
975+
976+
return pixelList;
977+
}
978+
979+
std::vector<MovableObject*>* SceneMan::DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius) {
980+
return DislodgePixelRing(centre, innerRadius, outerRadius, false);
981+
}
982+
956983
std::vector<MovableObject*>* SceneMan::DislodgePixelBox(const Vector& upperLeftCorner, const Vector& lowerRightCorner, bool deletePixels) {
957984
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
958985

Source/Managers/SceneMan.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ namespace RTE {
423423
/// @return A list of the removed pixels, if any.
424424
std::vector<MovableObject*>* DislodgePixelCircleNoBool(const Vector& centre, float radius);
425425

426+
/// Removes a ring of pixels from the terrain and adds them to MovableMan.
427+
/// @param centre The vector position of the centre of the ring.
428+
/// @param innerRadius The inner radius of the ring of pixels to remove.
429+
/// @param outerRadius The outer radius of the ring of pixels to remove.
430+
/// @param deletePixels Whether or not to immediately mark all found pixels for deletion.
431+
/// @return A list of the removed pixels, if any.
432+
std::vector<MovableObject*>* DislodgePixelRing(const Vector& centre, float innerRadius, float outerRadius, bool deletePixels);
433+
434+
/// Removes a ring of pixels from the terrain and adds them to MovableMan.
435+
/// @param centre The vector position of the centre of the ring.
436+
/// @param innerRadius The inner radius of the ring of pixels to remove.
437+
/// @param outerRadius The outer radius of the ring of pixels to remove.
438+
/// @return A list of the removed pixels, if any.
439+
std::vector<MovableObject*>* DislodgePixelRingNoBool(const Vector& centre, float innerRadius, float outerRadius);
440+
426441
/// Removes a box of pixels from the terrain and adds them to MovableMan.
427442
/// @param upperLeftCorner The vector position of the upper left corner of the box.
428443
/// @param lowerRightCorner The vector position of the lower right corner of the box.

0 commit comments

Comments
 (0)