convert all of the rest of the things except GameSave.cpp and pipe/ray elements

also add sim.PMAPBITS and sim.PMAPMASK constants
This commit is contained in:
jacob1 2017-12-29 21:01:28 -05:00
parent 20e1abd840
commit 0c8c4de125
12 changed files with 49 additions and 46 deletions

View File

@ -32,7 +32,7 @@ void ParticleDebug::Debug(int mode, int x, int y)
} }
else if (mode == 1) else if (mode == 1)
{ {
if (x < 0 || x >= XRES || y < 0 || y >= YRES || !sim->pmap[y][x] || (i = (sim->pmap[y][x]>>8)) < debug_currentParticle) if (x < 0 || x >= XRES || y < 0 || y >= YRES || !sim->pmap[y][x] || (i = ID(sim->pmap[y][x])) < debug_currentParticle)
{ {
i = NPART; i = NPART;
logmessage << "Updated particles from #" << debug_currentParticle << " to end, updated sim"; logmessage << "Updated particles from #" << debug_currentParticle << " to end, updated sim";

View File

@ -1245,7 +1245,7 @@ void Renderer::render_parts()
if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0) if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0)
continue; continue;
if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) if(TYP(sim->photons[ny][nx]) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH)
continue; continue;
//Defaults //Defaults
@ -1994,7 +1994,7 @@ void Renderer::render_parts()
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(drad)); nxo = (int)(ddist*cos(drad));
nyo = (int)(ddist*sin(drad)); nyo = (int)(ddist*sin(drad));
if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (sim->pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTI) if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && TYP(sim->pmap[ny+nyo][nx+nxo]) != PT_PRTI)
addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]);
} }
} }
@ -2011,14 +2011,14 @@ void Renderer::render_parts()
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(drad)); nxo = (int)(ddist*cos(drad));
nyo = (int)(ddist*sin(drad)); nyo = (int)(ddist*sin(drad));
if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (sim->pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTO) if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && TYP(sim->pmap[ny+nyo][nx+nxo]) != PT_PRTO)
addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]);
} }
} }
if (pixel_mode & EFFECT_DBGLINES && !(display_mode&DISPLAY_PERS)) if (pixel_mode & EFFECT_DBGLINES && !(display_mode&DISPLAY_PERS))
{ {
// draw lines connecting wifi/portal channels // draw lines connecting wifi/portal channels
if (mousePos.X == nx && mousePos.Y == ny && (i == sim->pmap[ny][nx]>>8) && debugLines) if (mousePos.X == nx && mousePos.Y == ny && i == ID(sim->pmap[ny][nx]) && debugLines)
{ {
int type = parts[i].type, tmp = (int)((parts[i].temp-73.15f)/100+1), othertmp; int type = parts[i].type, tmp = (int)((parts[i].temp-73.15f)/100+1), othertmp;
if (type == PT_PRTI) if (type == PT_PRTI)

View File

@ -305,7 +305,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types //Build menu for GOL types
for(int i = 0; i < NGOL; i++) for(int i = 0; i < NGOL; i++)
{ {
Tool * tempTool = new ElementTool(PT_LIFE|(i<<8), sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+std::string(sim->gmenu[i].name)); Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+std::string(sim->gmenu[i].name));
menuList[SC_LIFE]->AddTool(tempTool); menuList[SC_LIFE]->AddTool(tempTool);
} }

View File

@ -2293,7 +2293,7 @@ void GameView::OnDraw()
{ {
int ctype = sample.particle.ctype; int ctype = sample.particle.ctype;
if (type == PT_PIPE || type == PT_PPIP) if (type == PT_PIPE || type == PT_PPIP)
ctype = sample.particle.tmp&0xFF; ctype = TYP(sample.particle.tmp);
if (type == PT_PHOT || type == PT_BIZR || type == PT_BIZRG || type == PT_BIZRS || type == PT_FILT || type == PT_BRAY || type == PT_C5) if (type == PT_PHOT || type == PT_BIZR || type == PT_BIZRG || type == PT_BIZRS || type == PT_FILT || type == PT_BRAY || type == PT_C5)
wavelengthGfx = (ctype&0x3FFFFFFF); wavelengthGfx = (ctype&0x3FFFFFFF);
@ -2322,7 +2322,7 @@ void GameView::OnDraw()
sampleInfo << " (" << ctype << ")"; sampleInfo << " (" << ctype << ")";
// Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2 // Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2
else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV) else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV)
sampleInfo << " (" << c->ElementResolve(ctype&0xFF, ctype>>8) << ")"; sampleInfo << " (" << c->ElementResolve(TYP(type), ID(ctype)) << ")";
else if (c->IsValidElement(ctype)) else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")"; sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")";
else else

View File

@ -255,14 +255,14 @@ void PropertyTool::SetProperty(Simulation *sim, ui::Point position)
switch (propType) switch (propType)
{ {
case StructProperty::Float: case StructProperty::Float:
*((float*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.Float; *((float*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.Float;
break; break;
case StructProperty::ParticleType: case StructProperty::ParticleType:
case StructProperty::Integer: case StructProperty::Integer:
*((int*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.Integer; *((int*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.Integer;
break; break;
case StructProperty::UInteger: case StructProperty::UInteger:
*((unsigned int*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.UInteger; *((unsigned int*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.UInteger;
break; break;
default: default:
break; break;

View File

@ -35,13 +35,13 @@ void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
int particleCtype = 0; int particleCtype = 0;
if (sim->photons[position.Y][position.X]) if (sim->photons[position.Y][position.X])
{ {
particleType = sim->parts[sim->photons[position.Y][position.X]>>8].type; particleType = sim->parts[ID(sim->photons[position.Y][position.X])].type;
particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype; particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
} }
else if (sim->pmap[position.Y][position.X]) else if (sim->pmap[position.Y][position.X])
{ {
particleType = sim->parts[sim->pmap[position.Y][position.X]>>8].type; particleType = sim->parts[ID(sim->pmap[position.Y][position.X])].type;
particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype; particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
} }
if(particleType) if(particleType)

View File

@ -153,15 +153,15 @@ void Element_LIGH_Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point posi
void Element_TESC_Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { 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; int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | (radiusInfo << 8)); sim->CreateBox(position1.X, position1.Y, position2.X, position2.Y, toolID | PMAPID(radiusInfo));
} }
void Element_TESC_Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { void Element_TESC_Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7; int radiusInfo = brush->GetRadius().X*4+brush->GetRadius().Y*4+7;
sim->FloodParts(position.X, position.Y, toolID | (radiusInfo << 8), -1); sim->FloodParts(position.X, position.Y, toolID | PMAPID(radiusInfo), -1);
} }
void PlopTool::Click(Simulation * sim, Brush * brush, ui::Point position) void PlopTool::Click(Simulation * sim, Brush * brush, ui::Point position)
{ {
sim->create_part(-2, position.X, position.Y, toolID&0xFF, toolID>>8); sim->create_part(-2, position.X, position.Y, TYP(toolID), ID(toolID));
} }

View File

@ -1146,11 +1146,11 @@ int luatpt_set_property(lua_State* l)
if (i>=XRES || y>=YRES) if (i>=XRES || y>=YRES)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y); return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
r = luacon_sim->pmap[y][i]; r = luacon_sim->pmap[y][i];
if (!r || (partsel && partsel != (r&0xFF))) if (!r || (partsel && partsel != TYP(r)))
r = luacon_sim->photons[y][i]; r = luacon_sim->photons[y][i];
if (!r || (partsel && partsel != (r&0xFF))) if (!r || (partsel && partsel != TYP(r)))
return 0; return 0;
i = r>>8; i = ID(r);
} }
if (i < 0 || i >= NPART) if (i < 0 || i >= NPART)
return luaL_error(l, "Invalid particle ID '%d'", i); return luaL_error(l, "Invalid particle ID '%d'", i);
@ -1295,7 +1295,7 @@ int luatpt_get_property(lua_State* l)
return luaL_error(l, "Particle does not exist"); return luaL_error(l, "Particle does not exist");
} }
} }
i = r>>8; i = ID(r);
} }
else if (y != -1) else if (y != -1)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y); return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);

View File

@ -800,6 +800,9 @@ void LuaScriptInterface::initSimulationAPI()
SETCONST(l, DECO_DIVIDE); SETCONST(l, DECO_DIVIDE);
SETCONST(l, DECO_SMUDGE); SETCONST(l, DECO_SMUDGE);
SETCONST(l, PMAPBITS);
SETCONST(l, PMAPMASK);
//Declare FIELD_BLAH constants //Declare FIELD_BLAH constants
std::vector<StructProperty> particlePropertiesV = Particle::GetProperties(); std::vector<StructProperty> particlePropertiesV = Particle::GetProperties();
particlePropertiesCount = 0; particlePropertiesCount = 0;
@ -876,11 +879,11 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry)) if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
{ {
n = luacon_sim->pmap[y+ry][x+rx]; n = luacon_sim->pmap[y+ry][x+rx];
if (!n || (n&0xFF) != t) if (!n || TYP(n) != t)
n = luacon_sim->photons[y+ry][x+rx]; n = luacon_sim->photons[y+ry][x+rx];
if (n && (n&0xFF) == t) if (n && TYP(n) == t)
{ {
lua_pushinteger(l, n>>8); lua_pushinteger(l, ID(n));
lua_rawseti(l, -2, id++); lua_rawseti(l, -2, id++);
} }
} }
@ -897,7 +900,7 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
n = luacon_sim->photons[y+ry][x+rx]; n = luacon_sim->photons[y+ry][x+rx];
if (n) if (n)
{ {
lua_pushinteger(l, n>>8); lua_pushinteger(l, ID(n));
lua_rawseti(l, -2, id++); lua_rawseti(l, -2, id++);
} }
} }
@ -929,10 +932,10 @@ int LuaScriptInterface::simulation_partCreate(lua_State * l)
} }
int type = lua_tointeger(l, 4); int type = lua_tointeger(l, 4);
int v = -1; int v = -1;
if (type>>8) if (ID(type))
{ {
v = type>>8; v = ID(type);
type = type&0xFF; type = TYP(type);
} }
lua_pushinteger(l, luacon_sim->create_part(newID, lua_tointeger(l, 2), lua_tointeger(l, 3), type, v)); lua_pushinteger(l, luacon_sim->create_part(newID, lua_tointeger(l, 2), lua_tointeger(l, 3), type, v));
return 1; return 1;
@ -955,7 +958,7 @@ int LuaScriptInterface::simulation_partID(lua_State * l)
if (!amalgam) if (!amalgam)
lua_pushnil(l); lua_pushnil(l);
else else
lua_pushinteger(l, amalgam >> 8); lua_pushinteger(l, ID(amalgam));
return 1; return 1;
} }
@ -2045,9 +2048,9 @@ int LuaScriptInterface::simulation_pmap(lua_State * l)
if (x < 0 || x >= XRES || y < 0 || y >= YRES) if (x < 0 || x >= XRES || y < 0 || y >= YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y); return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
int r = luacon_sim->pmap[y][x]; int r = luacon_sim->pmap[y][x];
if (!(r&0xFF)) if (!TYP(r))
return 0; return 0;
lua_pushnumber(l, r>>8); lua_pushnumber(l, ID(r));
return 1; return 1;
} }
@ -2058,9 +2061,9 @@ int LuaScriptInterface::simulation_photons(lua_State * l)
if (x < 0 || x >= XRES || y < 0 || y >= YRES) if (x < 0 || x >= XRES || y < 0 || y >= YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y); return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
int r = luacon_sim->photons[y][x]; int r = luacon_sim->photons[y][x];
if (!(r&0xFF)) if (!TYP(r))
return 0; return 0;
lua_pushnumber(l, r>>8); lua_pushnumber(l, ID(r));
return 1; return 1;
} }
@ -2090,12 +2093,12 @@ int NeighboursClosure(lua_State * l)
i=luacon_sim->pmap[y+sy][x+sx]; i=luacon_sim->pmap[y+sy][x+sx];
if(!i) if(!i)
i=luacon_sim->photons[y+sy][x+sx]; i=luacon_sim->photons[y+sy][x+sx];
} while(!(i&0xFF)); } while(!TYP(i));
lua_pushnumber(l, x); lua_pushnumber(l, x);
lua_replace(l, lua_upvalueindex(5)); lua_replace(l, lua_upvalueindex(5));
lua_pushnumber(l, y); lua_pushnumber(l, y);
lua_replace(l, lua_upvalueindex(6)); lua_replace(l, lua_upvalueindex(6));
lua_pushnumber(l, i>>8); lua_pushnumber(l, ID(i));
lua_pushnumber(l, x+sx); lua_pushnumber(l, x+sx);
lua_pushnumber(l, y+sy); lua_pushnumber(l, y+sy);
return 3; return 3;

View File

@ -457,10 +457,10 @@ AnyType TPTScriptInterface::tptS_create(std::deque<std::string> * words)
throw GeneralException("Invalid position"); throw GeneralException("Invalid position");
int v = -1; int v = -1;
if (type>>8) if (ID(type))
{ {
v = type>>8; v = ID(type);
type = type&0xFF; type = TYP(type);
} }
int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type, v); int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type, v);

View File

@ -35,7 +35,7 @@ std::string sign::getText(Simulation *sim)
else if (!strcmp(signText,"{t}")) else if (!strcmp(signText,"{t}"))
{ {
if (x>=0 && x<XRES && y>=0 && y<YRES && sim->pmap[y][x]) if (x>=0 && x<XRES && y>=0 && y<YRES && sim->pmap[y][x])
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[y][x]>>8].temp-273.15); //...temperature sprintf(buff, "Temp: %4.2f", sim->parts[ID(sim->pmap[y][x])].temp-273.15); //...temperature
else else
sprintf(buff, "Temp: 0.00"); //...temperature sprintf(buff, "Temp: 0.00"); //...temperature
} }

View File

@ -19,7 +19,7 @@ int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, float st
int distance = (int)(std::pow(strength, .5f) * 10); int distance = (int)(std::pow(strength, .5f) * 10);
if(!(sim->elements[thisPart&0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS))) if(!(sim->elements[TYP(thisPart)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS)))
return 0; return 0;
int newX = x + (rand() % distance) - (distance/2); int newX = x + (rand() % distance) - (distance/2);
@ -32,16 +32,16 @@ int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, float st
if(!thatPart) if(!thatPart)
return 0; return 0;
if ((sim->elements[thisPart&0xFF].Properties&STATE_FLAGS) != (sim->elements[thatPart&0xFF].Properties&STATE_FLAGS)) if ((sim->elements[TYP(thisPart)].Properties&STATE_FLAGS) != (sim->elements[TYP(thatPart)].Properties&STATE_FLAGS))
return 0; return 0;
sim->pmap[y][x] = thatPart; sim->pmap[y][x] = thatPart;
sim->parts[thatPart>>8].x = x; sim->parts[ID(thatPart)].x = x;
sim->parts[thatPart>>8].y = y; sim->parts[ID(thatPart)].y = y;
sim->pmap[newY][newX] = thisPart; sim->pmap[newY][newX] = thisPart;
sim->parts[thisPart>>8].x = newX; sim->parts[ID(thisPart)].x = newX;
sim->parts[thisPart>>8].y = newY; sim->parts[ID(thisPart)].y = newY;
return 1; return 1;
} }