Skip to content

Commit 232ef5b

Browse files
committed
Accounted for scene wrapping, updated changelog, minor cleanup
1 parent 0dc365a commit 232ef5b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
126126

127127
- Exposed `FrameMan` properties `ScreenCount` and `ResolutionMultiplier` to Lua (R).
128128

129+
- New `SceneMan` Lua functions:
130+
`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+
134+
129135
</details>
130136

131137
<details><summary><b>Changed</b></summary>
@@ -168,6 +174,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
168174

169175
- The `SceneObject` property `IsBuyable` has been renamed to `Buyable`.
170176

177+
- `SceneMan` Lua function `DislodgePixel()` now optionally accepts a third boolean argument to delete the found pixel immediately. Format is `DislodgePixel(int posX, int posY, bool deletePixel)`. `DislodgePixel()` now also automatically accounts for scene wrapping.
178+
171179
</details>
172180

173181
<details><summary><b>Fixed</b></summary>

Source/Managers/SceneMan.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ bool SceneMan::TryPenetrate(int posX,
893893
}
894894

895895
MovableObject* SceneMan::DislodgePixel(int posX, int posY) {
896+
WrapPosition(posX, posY);
896897
int materialID = getpixel(m_pCurrentScene->GetTerrain()->GetMaterialBitmap(), posX, posY);
897898
if (materialID <= MaterialColorKeys::g_MaterialAir) {
898899
return nullptr;
@@ -925,19 +926,20 @@ MovableObject* SceneMan::DislodgePixel(int posX, int posY) {
925926
// Bool variant to avoid changing the original
926927
MovableObject* SceneMan::DislodgePixelBool(int posX, int posY, bool deletePixel) {
927928
MovableObject* pixelMO = DislodgePixel(posX, posY);
928-
pixelMO->SetToDelete(deletePixel);
929+
if (pixelMO) {
930+
pixelMO->SetToDelete(deletePixel);
931+
}
929932
return pixelMO;
930933
}
931934

932935
std::vector<MovableObject*>* SceneMan::DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels) {
933936
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
934-
for (float x = 0; x <= radius * 2; x++) {
935-
for (float y = 0; y <= radius * 2; y++) {
936-
Vector checkPos = Vector(x - radius, y - radius) + centre;
937+
for (int x = 0; x <= static_cast<int>(radius) * 2; x++) {
938+
for (int y = 0; y <= static_cast<int>(radius) * 2; y++) {
939+
Vector checkPos = Vector(static_cast<float>(x) - radius, static_cast<float>(y) - radius) + centre;
937940
if (!ShortestDistance(centre, checkPos, true).MagnitudeIsGreaterThan(radius)) {
938-
MovableObject* px = DislodgePixel(checkPos.m_X, checkPos.m_Y);
941+
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
939942
if (px) {
940-
px->SetToDelete(deletePixels);
941943
pixelList->push_back(px);
942944
}
943945
}
@@ -960,12 +962,11 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelBox(const Vector& upperLeftC
960962

961963
float width = end.m_X - start.m_X;
962964
float height = end.m_Y - start.m_Y;
963-
for (float x = 0; x <= width * 2; x++) {
964-
for (float y = 0; y <= height * 2; y++) {
965-
Vector checkPos = start + Vector(x, y);
966-
MovableObject* px = DislodgePixel(checkPos.m_X, checkPos.m_Y);
965+
for (int x = 0; x <= static_cast<int>(width) * 2; x++) {
966+
for (int y = 0; y <= static_cast<int>(height) * 2; y++) {
967+
Vector checkPos = start + Vector(static_cast<float>(x), static_cast<float>(y));
968+
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
967969
if (px) {
968-
px->SetToDelete(deletePixels);
969970
pixelList->push_back(px);
970971
}
971972
}
@@ -1034,9 +1035,8 @@ std::vector<MovableObject*>* SceneMan::DislodgePixelLine(const Vector& start, co
10341035
// Scene wrapping
10351036
g_SceneMan.WrapPosition(intPos[X], intPos[Y]);
10361037

1037-
MovableObject* px = DislodgePixel(intPos[X], intPos[Y]);
1038+
MovableObject* px = DislodgePixelBool(intPos[X], intPos[Y], deletePixels);
10381039
if (px) {
1039-
px->SetToDelete(deletePixels);
10401040
pixelList->push_back(px);
10411041
}
10421042

0 commit comments

Comments
 (0)