diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 12 | ||||
| -rw-r--r-- | src/gui/game/Tool.cpp | 8 | ||||
| -rw-r--r-- | src/gui/preview/PreviewModel.cpp | 18 | ||||
| -rw-r--r-- | src/simulation/Simulation.cpp | 59 | ||||
| -rw-r--r-- | 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 1653e28..2657456 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 bdc1801..97ab634 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 34d0c7f..88b281b 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<SaveComment*> * 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 f6f0110..53cd2e6 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<PT_NUM)?1:CELL; - int co = c; + int x1, x2; int coord_stack_limit = XRES*YRES; unsigned short (*coord_stack)[2]; int coord_stack_size = 0; @@ -522,7 +521,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) y = coord_stack[coord_stack_size][1]; x1 = x2 = x; // go left as far as possible - while (x1>=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<XRES-CELL) { - if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm) + if (bmap[y/CELL][(x2+1)/CELL]!=bm) { break; } @@ -1215,15 +1210,15 @@ int Simulation::FloodWalls(int x, int y, int wall, int cm, int bm, int flags) return 0; } // fill children - if (y>=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<YRES-CELL-dy) + if (y<YRES-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; return 1; } @@ -1425,11 +1420,10 @@ void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags) CreateParts(i, j, 0, 0, c, flags); } -int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) +int Simulation::FloodParts(int x, int y, int fullc, int cm, int flags) { int c = fullc&0xFF; int x1, x2, dy = (c<PT_NUM)?1:CELL; - int co = c; int coord_stack_limit = XRES*YRES; unsigned short (*coord_stack)[2]; int coord_stack_size = 0; @@ -1437,6 +1431,9 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) if (cm==-1) { + //if initial flood point is out of bounds, do nothing + if (c != 0 && (x < CELL || x >= 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<XRES-CELL) + while (c?x2<XRES-CELL-1:x2<XRES-1) { - if (!FloodFillPmapCheck(x2+1, y, cm) || bmap[y/CELL][(x2+1)/CELL]!=bm) + if (!FloodFillPmapCheck(x2+1, y, cm) || (c != 0 && IsWallBlocking(x2+1, y, c))) { break; } @@ -1492,9 +1487,9 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) created_something = 1; } - if (y>=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<YRES-CELL-dy) + if (c?y<YRES-CELL-dy:y<YRES-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; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 5369a5b..82adb6f 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -179,7 +179,7 @@ public: int CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBrush = NULL, int flags = -1); void CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, Brush * cBrush = NULL, int flags = -1); void CreateWallBox(int x1, int y1, int x2, int y2, int wall, int flags = -1); - int FloodWalls(int x, int y, int wall, int cm, int bm, int flags = -1); + int FloodWalls(int x, int y, int wall, int bm, int flags = -1); //Drawing Particles int CreateParts(int positionX, int positionY, int c, Brush * cBrush, int flags = -1); @@ -188,7 +188,7 @@ public: void CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush, int flags = -1); void CreateLine(int x1, int y1, int x2, int y2, int c); void CreateBox(int x1, int y1, int x2, int y2, int c, int flags = -1); - int FloodParts(int x, int y, int c, int cm, int bm, int flags = -1); + int FloodParts(int x, int y, int c, int cm, int flags = -1); void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY); |
