From a06202c78f392db833733d621974af1edcdb1cec Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 11 Jul 2013 22:43:36 -0400 Subject: [PATCH] fixes to wall and particle floodfill. Wall fill ignores particles and always goes to the edges, while particle fill will only ignore walls it can't exist in, and flood particle erase won't check for walls / edges at all --- src/cat/LuaScriptInterface.cpp | 12 +++---- src/gui/game/Tool.cpp | 8 ++--- src/gui/preview/PreviewModel.cpp | 18 ++++++---- src/simulation/Simulation.cpp | 59 +++++++++++++++----------------- src/simulation/Simulation.h | 4 +-- 5 files changed, 49 insertions(+), 52 deletions(-) diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 1653e2861..265745677 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -1033,9 +1033,8 @@ int LuaScriptInterface::simulation_floodParts(lua_State * l) int y = luaL_optint(l,2,-1); int c = luaL_optint(l,3,luacon_model->GetActiveTool(0)->GetToolID()); int cm = luaL_optint(l,4,-1); - int bm = luaL_optint(l,5,-1); - int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags); - int ret = luacon_sim->FloodParts(x, y, c, cm, bm, flags); + int flags = luaL_optint(l,5,luacon_sim->replaceModeFlags); + int ret = luacon_sim->FloodParts(x, y, c, cm, flags); lua_pushinteger(l, ret); return 1; } @@ -1093,12 +1092,11 @@ int LuaScriptInterface::simulation_floodWalls(lua_State * l) int x = luaL_optint(l,1,-1); int y = luaL_optint(l,2,-1); int c = luaL_optint(l,3,8); - int cm = luaL_optint(l,4,-1); - int bm = luaL_optint(l,5,-1); - int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags); + int bm = luaL_optint(l,4,-1); + int flags = luaL_optint(l,5,luacon_sim->replaceModeFlags); if (c < 0 || c >= UI_WALLCOUNT) return luaL_error(l, "Unrecognised wall id '%d'", c); - int ret = luacon_sim->FloodWalls(x, y, c, cm, bm, flags); + int ret = luacon_sim->FloodWalls(x, y, c, bm, flags); lua_pushinteger(l, ret); return 1; } diff --git a/src/gui/game/Tool.cpp b/src/gui/game/Tool.cpp index bdc1801d7..97ab6346d 100644 --- a/src/gui/game/Tool.cpp +++ b/src/gui/game/Tool.cpp @@ -65,7 +65,7 @@ void ElementTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID); } void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { - sim->FloodParts(position.X, position.Y, toolID, -1, -1); + sim->FloodParts(position.X, position.Y, toolID, -1); } @@ -87,7 +87,7 @@ void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui newFanVelX *= strength; float newFanVelY = (position2.Y-position1.Y)*0.005f; newFanVelY *= strength; - sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, -1, WL_FAN, 0); + sim->FloodWalls(position1.X, position1.Y, WL_FLOODHELPER, WL_FAN, 0); for (int j = 0; j < YRES/CELL; j++) for (int i = 0; i < XRES/CELL; i++) if (sim->bmap[j][i] == WL_FLOODHELPER) @@ -107,7 +107,7 @@ void WallTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui } void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { if (toolID != WL_STREAM) - sim->FloodWalls(position.X, position.Y, toolID, -1, -1); + sim->FloodWalls(position.X, position.Y, toolID, -1); } WindTool::WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)): @@ -185,7 +185,7 @@ void Element_TESC_Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point posi } void Element_TESC_Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7; - sim->FloodParts(position.X, position.Y, toolID | (radiusInfo << 8), -1, -1); + sim->FloodParts(position.X, position.Y, toolID | (radiusInfo << 8), -1); } diff --git a/src/gui/preview/PreviewModel.cpp b/src/gui/preview/PreviewModel.cpp index 34d0c7f18..88b281b7b 100644 --- a/src/gui/preview/PreviewModel.cpp +++ b/src/gui/preview/PreviewModel.cpp @@ -23,9 +23,10 @@ void * PreviewModel::updateSaveInfoT(void * obj) { SaveInfo * tempSave = Client::Ref().GetSave(((threadInfo*)obj)->saveID, ((threadInfo*)obj)->saveDate); ((threadInfo*)obj)->threadFinished = true; - if (((threadInfo*)obj)->previewExited && tempSave) + if (((threadInfo*)obj)->previewExited) { - delete tempSave; + if (tempSave) + delete tempSave; delete obj; } return tempSave; @@ -52,12 +53,15 @@ void * PreviewModel::updateSaveCommentsT(void * obj) { std::vector * tempComments = Client::Ref().GetComments(((threadInfo*)obj)->saveID, (((threadInfo*)obj)->saveDate-1)*20, 20); //saveDate is used as commentsPageNumber ((threadInfo*)obj)->threadFinished = true; - if (((threadInfo*)obj)->previewExited && tempComments) + if (((threadInfo*)obj)->previewExited) { - for(int i = 0; i < tempComments->size(); i++) - delete tempComments->at(i); - tempComments->clear(); - delete tempComments; + if (tempComments) + { + for(int i = 0; i < tempComments->size(); i++) + delete tempComments->at(i); + tempComments->clear(); + delete tempComments; + } delete obj; } return tempComments; diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index f6f0110e5..53cd2e663 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -485,8 +485,7 @@ SimulationSample Simulation::GetSample(int x, int y) int Simulation::FloodINST(int x, int y, int fullc, int cm) { int c = fullc&0xFF; - int x1, x2, dy = (c=CELL) + while (x1>=0) { if ((pmap[y][x1-1]&0xFF)!=cm || parts[pmap[y][x1-1]>>8].life!=0) { @@ -1165,13 +1164,9 @@ void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int wall, int fla CreateWalls(i, j, 0, 0, wall, NULL, flags); } -int Simulation::FloodWalls(int x, int y, int wall, int cm, int bm, int flags) +int Simulation::FloodWalls(int x, int y, int wall, int bm, int flags) { int x1, x2, dy = CELL; - if (cm==-1) - { - cm = pmap[y][x]&0xFF; - } if (bm==-1) { if (wall==WL_ERASE) @@ -1186,14 +1181,14 @@ int Simulation::FloodWalls(int x, int y, int wall, int cm, int bm, int flags) flags = replaceModeFlags; } - if ((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm || ((flags&SPECIFIC_DELETE) && cm != replaceModeSelected)) + if (bmap[y/CELL][x/CELL]!=bm) return 1; // go left as far as possible x1 = x2 = x; while (x1>=CELL) { - if ((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm) + if (bmap[y/CELL][(x1-1)/CELL]!=bm) { break; } @@ -1201,7 +1196,7 @@ int Simulation::FloodWalls(int x, int y, int wall, int cm, int bm, int flags) } while (x2=CELL+dy) + if (y>=CELL) for (x=x1; x<=x2; x++) - if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) - if (!FloodWalls(x, y-dy, wall, cm, bm, flags)) + if (bmap[(y-dy)/CELL][x/CELL]==bm) + if (!FloodWalls(x, y-dy, wall, bm, flags)) return 0; - if (y= XRES-CELL || y < CELL || y >= YRES-CELL)) + return 1; if (c==0) { cm = pmap[y][x]&0xFF; @@ -1448,12 +1445,10 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) else cm = 0; } - if (bm==-1) - { - bm = bmap[y/CELL][x/CELL]; - } + if (IsWallBlocking(x, y, c)) + return 1; - if (!FloodFillPmapCheck(x, y, cm) || bmap[y/CELL][x/CELL] != bm ) + if (!FloodFillPmapCheck(x, y, cm)) return 1; coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit); @@ -1468,18 +1463,18 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) y = coord_stack[coord_stack_size][1]; x1 = x2 = x; // go left as far as possible - while (x1>=CELL) + while (c?x1>CELL:x1>0) { - if (!FloodFillPmapCheck(x1-1, y, cm) || bmap[y/CELL][(x1-1)/CELL]!=bm) + if (!FloodFillPmapCheck(x1-1, y, cm) || (c != 0 && IsWallBlocking(x1-1, y, c))) { break; } x1--; } // go right as far as possible - while (x2=CELL+dy) + if (c?y>=CELL+dy:y>=dy) for (x=x1; x<=x2; x++) - if (FloodFillPmapCheck(x, y-dy, cm) && bmap[(y-dy)/CELL][x/CELL]==bm) + if (FloodFillPmapCheck(x, y-dy, cm) && (c == 0 || !IsWallBlocking(x, y-dy, c))) { coord_stack[coord_stack_size][0] = x; coord_stack[coord_stack_size][1] = y-dy; @@ -1506,9 +1501,9 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) } } - if (y