Skip to content

Commit

Permalink
new function sim.clearRect, plus fix rounding errors breaking ctrl+x
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Mar 12, 2015
1 parent 1eb8940 commit fc5f367
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/lua/LuaScriptInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ void LuaScriptInterface::initSimulationAPI()
{"decoColor", simulation_decoColor},
{"decoColour", simulation_decoColor},
{"clearSim", simulation_clearSim},
{"clearRect", simulation_clearRect},
{"resetTemp", simulation_resetTemp},
{"resetPressure", simulation_resetPressure},
{"saveStamp", simulation_saveStamp},
Expand Down Expand Up @@ -1398,6 +1399,16 @@ int LuaScriptInterface::simulation_clearSim(lua_State * l)
return 0;
}

int LuaScriptInterface::simulation_clearRect(lua_State * l)
{
int x = luaL_checkint(l,1);
int y = luaL_checkint(l,2);
int w = luaL_checkint(l,3)-1;
int h = luaL_checkint(l,4)-1;
luacon_sim->clear_area(x, y, w, h);
return 0;
}

int LuaScriptInterface::simulation_resetTemp(lua_State * l)
{
bool onlyConductors = luaL_optint(l, 1, 0);
Expand Down
1 change: 1 addition & 0 deletions src/lua/LuaScriptInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LuaScriptInterface: public CommandInterface
static int simulation_decoBox(lua_State * l);
static int simulation_decoColor(lua_State * l);
static int simulation_clearSim(lua_State * l);
static int simulation_clearRect(lua_State * l);
static int simulation_resetTemp(lua_State * l);
static int simulation_resetPressure(lua_State * l);
static int simulation_saveStamp(lua_State * l);
Expand Down
24 changes: 12 additions & 12 deletions src/simulation/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,27 +356,27 @@ void Simulation::Restore(const Snapshot & snap)

void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
{
int i = 0;
for (i = 0; i <= parts_lastActiveIndex; i++) {
float fx = area_x-.5f, fy = area_y-.5f;
for (int i = 0; i <= parts_lastActiveIndex; i++)
{
if (parts[i].type)
if (parts[i].x >= area_x && parts[i].x <= area_x + area_w && parts[i].y >= area_y && parts[i].y <= area_y + area_h)
if (parts[i].x >= fx && parts[i].x <= fx+area_w+1 && parts[i].y >= fy && parts[i].y <= fy+area_h+1)
kill_part(i);
}
int cx = 0;
int cy = 0;
for (cy=0; cy<=area_h; cy++)
int cx1 = area_x/CELL, cy1 = area_y/CELL, cx2 = (area_x+area_w)/CELL, cy2 = (area_y+area_h)/CELL;
for (int y = cy1; y <= cy2; y++)
{
for (cx=0; cx<=area_w; cx++)
for (int x = cx1; x <= cx2; x++)
{
if(bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] == WL_GRAV)
if (bmap[y][x] == WL_GRAV)
gravWallChanged = true;
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
emap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
bmap[y][x] = 0;
emap[y][x] = 0;
}
}
for(int i = signs.size()-1; i >= 0; i--)
for( int i = signs.size()-1; i >= 0; i--)
{
if(signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h)
if (signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h)
{
signs.erase(signs.begin()+i);
}
Expand Down

0 comments on commit fc5f367

Please sign in to comment.