Add back replace mode and specific delete *

* only usable by Lua
This commit is contained in:
jacob1 2013-06-22 22:48:51 -04:00
parent 625766028d
commit 43540eb7e4
9 changed files with 436 additions and 460 deletions

View File

@ -1571,7 +1571,7 @@ int luatpt_delete(lua_State* l)
}
arg2 = abs(arg2);
if(arg2 < YRES && arg1 < XRES){
luacon_sim->delete_part(arg1, arg2, 0);
luacon_sim->delete_part(arg1, arg2);
return 0;
}
return luaL_error(l,"Invalid coordinates or particle ID");

View File

@ -782,7 +782,7 @@ int LuaScriptInterface::simulation_partProperty(lua_State * l)
int LuaScriptInterface::simulation_partKill(lua_State * l)
{
if(lua_gettop(l)==2)
luacon_sim->delete_part(lua_tointeger(l, 1), lua_tointeger(l, 2), 0);
luacon_sim->delete_part(lua_tointeger(l, 1), lua_tointeger(l, 2));
else
luacon_sim->kill_part(lua_tointeger(l, 1));
return 0;
@ -977,7 +977,7 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
int ry = luaL_optint(l,4,5);
int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID());
int brush = luaL_optint(l,6,CIRCLE_BRUSH);
int flags = luaL_optint(l,7,0);
int flags = luaL_optint(l,7,luacon_sim->replaceModeFlags);
vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size())
@ -985,7 +985,7 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry));
int ret = luacon_sim->CreateParts(x, y, c, brushList[brush]);
int ret = luacon_sim->CreateParts(x, y, c, brushList[brush], flags);
brushList[brush]->SetRadius(tempRadius);
lua_pushinteger(l, ret);
return 1;
@ -1001,7 +1001,7 @@ int LuaScriptInterface::simulation_createLine(lua_State * l)
int ry = luaL_optint(l,6,5);
int c = luaL_optint(l,7,luacon_model->GetActiveTool(0)->GetToolID());
int brush = luaL_optint(l,8,CIRCLE_BRUSH);
int flags = luaL_optint(l,9,0);
int flags = luaL_optint(l,9,luacon_sim->replaceModeFlags);
vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size())
@ -1009,7 +1009,7 @@ int LuaScriptInterface::simulation_createLine(lua_State * l)
ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry));
luacon_sim->CreateLine(x1, y1, x2, y2, c, brushList[brush]);
luacon_sim->CreateLine(x1, y1, x2, y2, c, brushList[brush], flags);
brushList[brush]->SetRadius(tempRadius);
return 0;
}
@ -1021,7 +1021,7 @@ int LuaScriptInterface::simulation_createBox(lua_State * l)
int x2 = luaL_optint(l,3,-1);
int y2 = luaL_optint(l,4,-1);
int c = luaL_optint(l,5,luacon_model->GetActiveTool(0)->GetToolID());
int flags = luaL_optint(l,6,0);
int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags);
luacon_sim->CreateBox(x1, y1, x2, y2, c, flags);
return 0;
@ -1034,7 +1034,7 @@ int LuaScriptInterface::simulation_floodParts(lua_State * l)
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,0);
int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags);
int ret = luacon_sim->FloodParts(x, y, c, cm, bm, flags);
lua_pushinteger(l, ret);
return 1;
@ -1047,11 +1047,11 @@ int LuaScriptInterface::simulation_createWalls(lua_State * l)
int rx = luaL_optint(l,3,0);
int ry = luaL_optint(l,4,0);
int c = luaL_optint(l,5,8);
int flags = luaL_optint(l,6,0);
int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags);
if (c < 0 || c >= UI_WALLCOUNT)
return luaL_error(l, "Unrecognised wall id '%d'", c);
int ret = luacon_sim->CreateWalls(x, y, rx, ry, c, flags);
int ret = luacon_sim->CreateWalls(x, y, rx, ry, c, NULL, flags);
lua_pushinteger(l, ret);
return 1;
}
@ -1065,11 +1065,11 @@ int LuaScriptInterface::simulation_createWallLine(lua_State * l)
int rx = luaL_optint(l,5,0);
int ry = luaL_optint(l,6,0);
int c = luaL_optint(l,7,8);
int flags = luaL_optint(l,8,0);
int flags = luaL_optint(l,8,luacon_sim->replaceModeFlags);
if (c < 0 || c >= UI_WALLCOUNT)
return luaL_error(l, "Unrecognised wall id '%d'", c);
luacon_sim->CreateWallLine(x1, y1, x2, y2, rx, ry, c, flags);
luacon_sim->CreateWallLine(x1, y1, x2, y2, rx, ry, c, NULL, flags);
return 0;
}
@ -1080,7 +1080,7 @@ int LuaScriptInterface::simulation_createWallBox(lua_State * l)
int x2 = luaL_optint(l,3,-1);
int y2 = luaL_optint(l,4,-1);
int c = luaL_optint(l,5,8);
int flags = luaL_optint(l,6,0);
int flags = luaL_optint(l,6,luacon_sim->replaceModeFlags);
if (c < 0 || c >= UI_WALLCOUNT)
return luaL_error(l, "Unrecognised wall id '%d'", c);
@ -1095,7 +1095,7 @@ int LuaScriptInterface::simulation_floodWalls(lua_State * l)
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,0);
int flags = luaL_optint(l,6,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);

View File

@ -406,7 +406,7 @@ AnyType TPTScriptInterface::tptS_delete(std::deque<std::string> * words)
ui::Point deletePoint = ((PointType)partRef).Value();
if(deletePoint.X<0 || deletePoint.Y<0 || deletePoint.Y >= YRES || deletePoint.X >= XRES)
throw GeneralException("Invalid position");
sim->delete_part(deletePoint.X, deletePoint.Y, 0);
sim->delete_part(deletePoint.X, deletePoint.Y);
}
else if(partRef.GetType() == TypeNumber)
{

View File

@ -62,10 +62,10 @@ void ElementTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1,
sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush);
}
void ElementTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
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, 0);
sim->FloodParts(position.X, position.Y, toolID, -1, -1);
}
@ -75,8 +75,8 @@ Tool(id, name, description, r, g, b, identifier, textureGen)
resolution = CELL;
}
WallTool::~WallTool() {}
void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){
sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush);
void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position) {
sim->CreateWalls(position.X, position.Y, 1, 1, toolID, brush);
}
void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) {
int wallX = position1.X/CELL;
@ -99,15 +99,15 @@ void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui
}
else
{
sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush);
sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, brush);
}
}
void WallTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID, 0);
sim->CreateWallBox(position1.X, position1.Y, position2.X, position2.Y, toolID);
}
void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
if (toolID != WL_STREAM)
sim->FloodWalls(position.X, position.Y, toolID, -1, -1, 0);
sim->FloodWalls(position.X, position.Y, toolID, -1, -1);
}
WindTool::WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
@ -181,11 +181,11 @@ void Element_TESC_Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point posi
}
void Element_TESC_Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {
int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | (radiusInfo << 8), 0);
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | (radiusInfo << 8));
}
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, 0);
sim->FloodParts(position.X, position.Y, toolID | (radiusInfo << 8), -1, -1);
}

View File

@ -360,7 +360,7 @@ void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
gravWallChanged = true;
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
emap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
delete_part(cx+area_x, cy+area_y, 0);
delete_part(cx+area_x, cy+area_y);
}
}
for(int i = 0; i < MAXSIGNS && i < signs.size(); i++)
@ -372,46 +372,6 @@ void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
}
}
void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateParts(i, j, 0, 0, c, flags);
}
void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int c, int flags)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateWalls(i, j, 0, 0, c, flags);
}
int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype, int parttype, char * bitmap)
{
int x1, x2, i, dy = 1;
@ -669,165 +629,6 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm)
return created_something;
}
int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, 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;
int created_something = 0;
if (cm==-1)
{
if (c==0)
{
cm = pmap[y][x]&0xFF;
if (!cm)
return 0;
}
else
cm = 0;
}
if (bm==-1)
{
bm = bmap[y/CELL][x/CELL];
}
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm ))
return 1;
coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit);
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y;
coord_stack_size++;
do
{
coord_stack_size--;
x = coord_stack[coord_stack_size][0];
y = coord_stack[coord_stack_size][1];
x1 = x2 = x;
// go left as far as possible
while (x1>=CELL)
{
if ((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm)
{
break;
}
x1--;
}
// go right as far as possible
while (x2<XRES-CELL)
{
if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (CreateParts(x, y, 0, 0, fullc, flags))
created_something = 1;
}
if (y>=CELL+dy)
for (x=x1; x<=x2; x++)
if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm)
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y-dy;
coord_stack_size++;
if (coord_stack_size>=coord_stack_limit)
{
free(coord_stack);
return -1;
}
}
if (y<YRES-CELL-dy)
for (x=x1; x<=x2; x++)
if ((pmap[y+dy][x]&0xFF)==cm && bmap[(y+dy)/CELL][x/CELL]==bm)
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y+dy;
coord_stack_size++;
if (coord_stack_size>=coord_stack_limit)
{
free(coord_stack);
return -1;
}
}
} while (coord_stack_size>0);
free(coord_stack);
return created_something;
}
int Simulation::FloodWalls(int x, int y, int c, int cm, int bm, int flags)
{
int x1, x2, dy = CELL;
int co = c;
if (cm==-1)
{
cm = pmap[y][x]&0xFF;
}
if (bm==-1)
{
if (c==WL_ERASE)
{
bm = bmap[y/CELL][x/CELL];
if (!bm)
return 0;
}
else
bm = 0;
}
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )/*||( (flags&BRUSH_SPECIFIC_DELETE) && cm!=SLALT)*/)
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)
{
break;
}
x1--;
}
while (x2<XRES-CELL)
{
if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (!CreateWalls(x, y, 0, 0, c, flags))
return 0;
}
// fill children
if (y>=CELL+dy)
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, c, cm, bm, flags))
return 0;
if (y<YRES-CELL-dy)
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, c, cm, bm, flags))
return 0;
return 1;
}
int Simulation::flood_water(int x, int y, int i, int originaly, int check)
{
int x1 = 0,x2 = 0;
@ -1036,8 +837,6 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_,
void Simulation::ApplyDecorationPoint(int positionX, int positionY, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
{
int i, j;
if(cBrush)
{
int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y;
@ -1056,32 +855,11 @@ void Simulation::ApplyDecorationPoint(int positionX, int positionY, int colR, in
}
}
void Simulation::ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
ApplyDecoration(i, j, colR, colG, colB, colA, mode);
}
void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush)
{
bool reverseXY = abs(y2-y1) > abs(x2-x1);
int x, y, dx, dy, sy, rx, ry;
float e, de;
float e = 0.0f, de;
if(cBrush)
{
@ -1109,7 +887,6 @@ void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, i
}
dx = x2 - x1;
dy = abs(y2 - y1);
e = 0.0f;
if (dx)
de = dy/(float)dx;
else
@ -1138,6 +915,27 @@ void Simulation::ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, i
}
}
void Simulation::ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
ApplyDecoration(i, j, colR, colG, colB, colA, mode);
}
int Simulation::Tool(int x, int y, int tool, float strength)
{
if(tools[tool])
@ -1171,7 +969,7 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru
{
bool reverseXY = abs(y2-y1) > abs(x2-x1);
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
float e, de;
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
@ -1192,7 +990,6 @@ void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBru
}
dx = x2 - x1;
dy = abs(y2 - y1);
e = 0.0f;
if (dx)
de = dy/(float)dx;
else
@ -1240,146 +1037,64 @@ void Simulation::ToolBox(int x1, int y1, int x2, int y2, int tool, float strengt
Tool(i, j, tool, strength);
}
int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush)
int Simulation::CreateWalls(int x, int y, int rx, int ry, int wall, Brush * cBrush, int flags)
{
if(cBrush)
{
int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y, fn;
unsigned char *bitmap = cBrush->GetBitmap();
if (c == 0)// && !(flags&BRUSH_REPLACEMODE)) // delete
fn = 0;
//else if ((flags&BRUSH_SPECIFIC_DELETE) && !(flags&BRUSH_REPLACEMODE)) // specific delete
// fn = 1;
//else if (flags&BRUSH_REPLACEMODE) // replace
// fn = 2;
else // normal draw
fn = 3;
for(int y = 0; y < sizeY; y++)
{
for(int x = 0; x < sizeX; x++)
{
if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
{
CreatePartFlags(positionX+(x-radiusX), positionY+(y-radiusY), c, fn, 0);
}
}
}
}
return 0;
}
int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags)
{
int i, j, f = 0, fn;
if (c == 0)// && !(flags&BRUSH_REPLACEMODE)) // delete
fn = 0;
//else if ((flags&BRUSH_SPECIFIC_DELETE) && !(flags&BRUSH_REPLACEMODE)) // specific delete
// fn = 1;
//else if (flags&BRUSH_REPLACEMODE) // replace
// fn = 2;
else // normal draw
fn = 3;
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
if (CreatePartFlags(x+i, y+j, c, fn, flags))
f = 1;
return !f;
}
int Simulation::CreatePartFlags(int x, int y, int c, int fn, int flags)
{
if (fn == 0) //delete
delete_part(x, y, 0);
else if (fn == 1) //specific delete
delete_part(x, y, flags);
else if (fn == 2) //replace mode
{
if (x<0 || y<0 || x>=XRES || y>=YRES)
return 0;
//if ((pmap[y][x]&0xFF)!=SLALT&&SLALT!=0)
// return 0;
if ((pmap[y][x]))
{
delete_part(x, y, 0);
if (c!=0)
create_part(-2, x, y, c);
}
}
else if (fn == 3) //normal draw
if (create_part(-2, x, y, c) == -1)
return 1;
return 0;
}
int Simulation::CreateWalls(int x, int y, int rx, int ry, int c, int flags, Brush * cBrush)
{
int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n;
if(cBrush)
{
rx = cBrush->GetRadius().X;
ry = cBrush->GetRadius().Y;
}
int wall = c;
if (wall == WL_ERASE)
b = 0;
else
b = wall;
wall = 0;
if (flags == -1)
flags = replaceModeFlags;
ry = ry/CELL;
rx = rx/CELL;
x = x/CELL;
y = y/CELL;
x -= rx;///2;
y -= ry;///2;
for (ox=x; ox<=x+rx+rx; ox++)
x -= rx;
y -= ry;
for (int wallX = x; wallX <= x+rx+rx; wallX++)
{
for (oy=y; oy<=y+ry+ry; oy++)
for (int wallY = y; wallY <= y+ry+ry; wallY++)
{
if (ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
if (wallX >= 0 && wallX < XRES/CELL && wallY >= 0 && wallY < YRES/CELL)
{
i = ox;
j = oy;
if (b==WL_FAN)
if ((flags&SPECIFIC_DELETE) && wall != WL_FLOODHELPER && wall == replaceModeSelected)
wall = 0;
if (wall == WL_FAN)
{
fvx[j][i] = 0.0f;
fvy[j][i] = 0.0f;
fvx[wallY][wallX] = 0.0f;
fvy[wallY][wallX] = 0.0f;
}
if (b==WL_GRAV || bmap[j][i]==WL_GRAV)
else if (wall == WL_STREAM)
{
gravWallChanged = true;
}
if (b==WL_STREAM)
{
i = x + rx;///2;
j = y + ry;///2;
for (v=-1; v<2; v++)
for (u=-1; u<2; u++)
if (i+u>=0 && i+u<XRES/CELL &&
j+v>=0 && j+v<YRES/CELL &&
bmap[j+v][i+u] == WL_STREAM)
wallX = x + rx;
wallY = y + ry;
//streamlines can't be drawn next to each other
for (int tempY = wallY-1; tempY < wallY+2; tempY++)
for (int tempX = wallX-1; tempX < wallX+2; tempX++)
{
if (tempX >= 0 && tempX < XRES/CELL && tempY >= 0 && tempY < YRES/CELL && bmap[tempY][tempX] == WL_STREAM)
return 1;
bmap[j][i] = WL_STREAM;
continue;
}
}
bmap[j][i] = b;
if (wall == WL_GRAV || bmap[wallY][wallX] == WL_GRAV)
gravWallChanged = true;
bmap[wallY][wallX] = wall;
}
}
}
return 1;
}
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush)
void Simulation::CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, Brush * cBrush, int flags)
{
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
int x, y, dx, dy, sy;
bool reverseXY = abs(y2-y1) > abs(x2-x1);
float e, de;
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
@ -1400,7 +1115,6 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrus
}
dx = x2 - x1;
dy = abs(y2 - y1);
e = 0.0f;
if (dx)
de = dy/(float)dx;
else
@ -1410,9 +1124,9 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrus
for (x=x1; x<=x2; x++)
{
if (reverseXY)
CreateParts(y, x, c, cBrush);
CreateWalls(y, x, rx, ry, wall, cBrush, flags);
else
CreateParts(x, y, c, cBrush);
CreateWalls(x, y, rx, ry, wall, cBrush, flags);
e += de;
if (e >= 0.5f)
{
@ -1420,9 +1134,214 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrus
if (!(rx+ry) && ((y1<y2) ? (y<=y2) : (y>=y2)))
{
if (reverseXY)
CreateParts(y, x, c, cBrush);
CreateWalls(y, x, rx, ry, wall, cBrush, flags);
else
CreateParts(x, y, c, cBrush);
CreateWalls(x, y, rx, ry, wall, cBrush, flags);
}
e -= 1.0f;
}
}
}
void Simulation::CreateWallBox(int x1, int y1, int x2, int y2, int wall, int flags)
{
int i, j;
if (x1>x2)
{
i = x2;
x2 = x1;
x1 = i;
}
if (y1>y2)
{
j = y2;
y2 = y1;
y1 = j;
}
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateWalls(i, j, 0, 0, wall, NULL, flags);
}
int Simulation::FloodWalls(int x, int y, int wall, int cm, int bm, int flags)
{
int x1, x2, dy = CELL;
if (cm==-1)
{
cm = pmap[y][x]&0xFF;
}
if (bm==-1)
{
if (wall==WL_ERASE)
{
bm = bmap[y/CELL][x/CELL];
if (!bm)
return 0;
}
else
bm = 0;
if (flags == -1)
flags = replaceModeFlags;
}
if ((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm || ((flags&SPECIFIC_DELETE) && cm != replaceModeSelected))
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)
{
break;
}
x1--;
}
while (x2<XRES-CELL)
{
if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (!CreateWalls(x, y, 0, 0, wall, NULL, flags))
return 0;
}
// fill children
if (y>=CELL+dy)
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))
return 0;
if (y<YRES-CELL-dy)
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))
return 0;
return 1;
}
int Simulation::CreateParts(int positionX, int positionY, int c, Brush * cBrush, int flags)
{
if (flags == -1)
flags = replaceModeFlags;
if(cBrush)
{
int radiusX = cBrush->GetRadius().X, radiusY = cBrush->GetRadius().Y, sizeX = cBrush->GetSize().X, sizeY = cBrush->GetSize().Y;
unsigned char *bitmap = cBrush->GetBitmap();
for(int y = 0; y < sizeY; y++)
{
for(int x = 0; x < sizeX; x++)
{
if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
{
CreatePartFlags(positionX+(x-radiusX), positionY+(y-radiusY), c, flags);
}
}
}
}
return 0;
}
int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags)
{
int i, j, f = 0;
if (flags == -1)
flags = replaceModeFlags;
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++)
if (CreatePartFlags(x+i, y+j, c, flags))
f = 1;
return !f;
}
int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
//delete
if (c == 0 && !(flags&REPLACE_MODE))
delete_part(x, y);
//specific delete
else if ((flags&SPECIFIC_DELETE) && !(flags&REPLACE_MODE))
{
if (!replaceModeSelected || (pmap[y][x]&0xFF) == replaceModeSelected || (photons[y][x]&0xFF) == replaceModeSelected)
delete_part(x, y);
}
//replace mode
else if (flags&REPLACE_MODE)
{
if (x<0 || y<0 || x>=XRES || y>=YRES)
return 0;
if (replaceModeSelected && (pmap[y][x]&0xFF) != replaceModeSelected && (photons[y][x]&0xFF) != replaceModeSelected)
return 0;
if ((pmap[y][x]))
{
delete_part(x, y);
if (c!=0)
create_part(-2, x, y, c);
}
}
//normal draw
else
if (create_part(-2, x, y, c) == -1)
return 1;
return 0;
}
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush, int flags)
{
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
bool reverseXY = abs(y2-y1) > abs(x2-x1);
float e = 0.0f, de;
if (reverseXY)
{
y = x1;
x1 = y1;
y1 = y;
y = x2;
x2 = y2;
y2 = y;
}
if (x1 > x2)
{
y = x1;
x1 = x2;
x2 = y;
y = y1;
y1 = y2;
y2 = y;
}
dx = x2 - x1;
dy = abs(y2 - y1);
if (dx)
de = dy/(float)dx;
else
de = 0.0f;
y = y1;
sy = (y1<y2) ? 1 : -1;
for (x=x1; x<=x2; x++)
{
if (reverseXY)
CreateParts(y, x, c, cBrush, flags);
else
CreateParts(x, y, c, cBrush, flags);
e += de;
if (e >= 0.5f)
{
y += sy;
if (!(rx+ry) && ((y1<y2) ? (y<=y2) : (y>=y2)))
{
if (reverseXY)
CreateParts(y, x, c, cBrush, flags);
else
CreateParts(x, y, c, cBrush, flags);
}
e -= 1.0f;
}
@ -1484,57 +1403,121 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c)
}
}
void Simulation::CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush)
void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags)
{
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de;
if (cp)
int i, j;
if (x1>x2)
{
y = x1;
x1 = y1;
y1 = y;
y = x2;
x2 = y2;
y2 = y;
i = x2;
x2 = x1;
x1 = i;
}
if (x1 > x2)
if (y1>y2)
{
y = x1;
x1 = x2;
x2 = y;
y = y1;
y1 = y2;
y2 = y;
j = y2;
y2 = y1;
y1 = j;
}
dx = x2 - x1;
dy = abs(y2 - y1);
e = 0.0f;
if (dx)
de = dy/(float)dx;
else
de = 0.0f;
y = y1;
sy = (y1<y2) ? 1 : -1;
for (x=x1; x<=x2; x++)
for (j=y1; j<=y2; j++)
for (i=x1; i<=x2; i++)
CreateParts(i, j, 0, 0, c, flags);
}
int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, 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;
int created_something = 0;
if (cm==-1)
{
if (cp)
CreateWalls(y, x, rx, ry, c, flags, cBrush);
else
CreateWalls(x, y, rx, ry, c, flags, cBrush);
e += de;
if (e >= 0.5f)
if (c==0)
{
y += sy;
if (!(rx+ry) && ((y1<y2) ? (y<=y2) : (y>=y2)))
{
if (cp)
CreateWalls(y, x, rx, ry, c, flags, cBrush);
else
CreateWalls(x, y, rx, ry, c, flags, cBrush);
}
e -= 1.0f;
cm = pmap[y][x]&0xFF;
if (!cm)
return 0;
}
else
cm = 0;
}
if (bm==-1)
{
bm = bmap[y/CELL][x/CELL];
}
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm ))
return 1;
coord_stack = (short unsigned int (*)[2])malloc(sizeof(unsigned short)*2*coord_stack_limit);
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y;
coord_stack_size++;
do
{
coord_stack_size--;
x = coord_stack[coord_stack_size][0];
y = coord_stack[coord_stack_size][1];
x1 = x2 = x;
// go left as far as possible
while (x1>=CELL)
{
if ((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm)
{
break;
}
x1--;
}
// go right as far as possible
while (x2<XRES-CELL)
{
if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
{
break;
}
x2++;
}
// fill span
for (x=x1; x<=x2; x++)
{
if (CreateParts(x, y, 0, 0, fullc, flags))
created_something = 1;
}
if (y>=CELL+dy)
for (x=x1; x<=x2; x++)
if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm)
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y-dy;
coord_stack_size++;
if (coord_stack_size>=coord_stack_limit)
{
free(coord_stack);
return -1;
}
}
if (y<YRES-CELL-dy)
for (x=x1; x<=x2; x++)
if ((pmap[y+dy][x]&0xFF)==cm && bmap[(y+dy)/CELL][x/CELL]==bm)
{
coord_stack[coord_stack_size][0] = x;
coord_stack[coord_stack_size][1] = y+dy;
coord_stack_size++;
if (coord_stack_size>=coord_stack_limit)
{
free(coord_stack);
return -1;
}
}
} while (coord_stack_size>0);
free(coord_stack);
return created_something;
}
void *Simulation::transform_save(void *odata, int *size, matrix2d transform, vector2d translate)
@ -3171,7 +3154,7 @@ void Simulation::create_cherenkov_photon(int pp)//photons from NEUT going throug
parts[i].vy *= r;
}
void Simulation::delete_part(int x, int y, int flags)//calls kill_part with the particle located at x,y
void Simulation::delete_part(int x, int y)//calls kill_part with the particle located at x,y
{
unsigned i;
@ -4776,7 +4759,9 @@ Simulation::Simulation():
force_stacking_check(0),
ISWIRE(0),
VINE_MODE(0),
gravWallChanged(false)
gravWallChanged(false),
replaceModeSelected(0),
replaceModeFlags(0)
{
int tportal_rx[] = {-1, 0, 1, 1, 1, 0,-1,-1};
int tportal_ry[] = {-1,-1,-1, 0, 1, 1, 1, 0};

View File

@ -1,5 +1,5 @@
#ifndef SIMULATION_H_
#define SIMULATION_H_
#ifndef SIMULATION_H
#define SIMULATION_H
#include <cstring>
#include <cstddef>
#include <vector>
@ -30,10 +30,8 @@ class Gravity;
class Air;
class GameSave;
//#ifdef _cplusplus
class Simulation
{
private:
public:
Gravity * grav;
@ -51,9 +49,11 @@ public:
menu_section msections[SC_TOTAL];
int currentTick;
int replaceModeSelected;
int replaceModeFlags;
char can_move[PT_NUM][PT_NUM];
int parts_lastActiveIndex;// = NPART-1;
int parts_lastActiveIndex;
int pfree;
int NUM_PARTS;
bool elementRecount;
@ -142,12 +142,13 @@ public:
int flood_prop(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype);
int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype, int parttype, char * bitmap);
int flood_water(int x, int y, int i, int originaly, int check);
int FloodINST(int x, int y, int fullc, int cm);
TPT_NO_INLINE void detach(int i);
TPT_NO_INLINE void part_change_type(int i, int x, int y, int t);
//int InCurrentBrush(int i, int j, int rx, int ry);
//int get_brush_flags();
TPT_NO_INLINE int create_part(int p, int x, int y, int t);
TPT_NO_INLINE void delete_part(int x, int y, int flags);
TPT_NO_INLINE void delete_part(int x, int y);
void get_sign_pos(int i, int *x0, int *y0, int *w, int *h);
TPT_NO_INLINE int is_wire(int x, int y);
TPT_NO_INLINE int is_wire_off(int x, int y);
@ -162,31 +163,33 @@ public:
void SetEdgeMode(int newEdgeMode);
//Drawing Deco
void ApplyDecoration(int x, int y, int colR, int colG, int colB, int colA, int mode);
void ApplyDecorationPoint(int x, int y, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
void ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
void ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode);
//Drawing Tools like HEAT, AIR, and GRAV
int Tool(int x, int y, int tool, float strength = 1.0f);
int ToolBrush(int x, int y, int tool, Brush * cBrush, float strength = 1.0f);
void ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength = 1.0f);
void ToolBox(int x1, int y1, int x2, int y2, int tool, float strength = 1.0f);
void CreateBox(int x1, int y1, int x2, int y2, int c, int flags);
int FloodINST(int x, int y, int fullc, int cm);
int FloodParts(int x, int y, int c, int cm, int bm, int flags);
//Create particles from brush/mask
int CreateParts(int positionX, int positionY, int c, Brush * cBrush);
//Old particle creation, will create a crappy square, do not use
int CreateParts(int x, int y, int rx, int ry, int c, int flags);
int CreatePartFlags(int x, int y, int c, int fn, int flags);
void CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush);
//Drawing Walls
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);
//Drawing Particles
int CreateParts(int positionX, int positionY, int c, Brush * cBrush, int flags = -1);
int CreateParts(int x, int y, int rx, int ry, int c, int flags = -1);
int CreatePartFlags(int x, int y, int c, int flags);
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 CreateWallBox(int x1, int y1, int x2, int y2, int c, int flags);
int FloodWalls(int x, int y, int c, int cm, int bm, int flags);
int CreateWalls(int x, int y, int rx, int ry, int c, int flags, Brush * cBrush = NULL);
void CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags, Brush * cBrush = NULL);
void ApplyDecoration(int x, int y, int colR, int colG, int colB, int colA, int mode);
void ApplyDecorationPoint(int x, int y, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
void ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
void ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode);
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);
void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY);
@ -204,6 +207,4 @@ public:
~Simulation();
};
//#endif
#endif /* SIMULATION_H_ */
#endif /* SIMULATION_H */

View File

@ -19,8 +19,6 @@
#define SC_CRACKER2 16
#define SC_TOTAL 15
#define UI_WALLCOUNT 16
#define O_WL_WALLELEC 122
#define O_WL_EWALL 123
#define O_WL_DETECT 124
@ -40,7 +38,6 @@
#define O_WL_GRAV 142
#define O_WL_ALLOWENERGY 145
#define WL_ERASE 0
#define WL_WALLELEC 1
#define WL_EWALL 2
@ -59,6 +56,8 @@
#define WL_ALLOWENERGY 15
#define WL_FLOODHELPER 255
#define UI_WALLCOUNT 16
#define OLD_SPC_AIR 236
#define SPC_AIR 256
@ -122,30 +121,21 @@
#define NGT_FROG 22
#define NGT_BRAN 23
#ifndef SIMULATIONDATA_H_
#define SIMULATIONDATA_H_
//replace mode / specific delete flags
#define REPLACE_MODE 0x1
#define SPECIFIC_DELETE 0x2
//#include "elements/NULLElement.h"
//#include "Simulation.h"
/*class Simulation;
class Renderer;
struct Particle;*/
#ifndef SIMULATIONDATA_H
#define SIMULATIONDATA_H
struct part_type;
struct part_transition;
struct wall_type;
struct gol_menu;
struct menu_section;
struct wall_type;
class SimTool;
class Element;
gol_menu * LoadGOLMenu(int & golMenuCount);
@ -160,4 +150,4 @@ menu_section * LoadMenus(int & menuCount);
unsigned int * LoadLatent(int & elementCount);
#endif /* SIMULATIONDATA_H_ */
#endif /* SIMULATIONDATA_H */

View File

@ -69,7 +69,7 @@ int Element_BOMB::update(UPDATE_FUNC_ARGS)
if ((pow((float)nxi,2))/(pow((float)rad,2))+(pow((float)nxj,2))/(pow((float)rad,2))<=1)
if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_VIBR)
{
sim->delete_part(x+nxi, y+nxj, 0);
sim->delete_part(x+nxi, y+nxj);
sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
nb = sim->create_part(-3, x+nxi, y+nxj, PT_EMBR);
if (nb!=-1)

View File

@ -87,7 +87,7 @@ namespace vm
TRAPDEF(deletePart)
{
sim->delete_part(ARG(0).int4, ARG(1).int4, ARG(2).int4);
sim->delete_part(ARG(0).int4, ARG(1).int4);
return 0;
}