Skip to content

Commit

Permalink
convert all of the rest of the things except GameSave.cpp and pipe/ra…
Browse files Browse the repository at this point in the history
…y elements

also add sim.PMAPBITS and sim.PMAPMASK constants
  • Loading branch information
jacob1 committed Dec 30, 2017
1 parent 20e1abd commit 0c8c4de
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/debug/ParticleDebug.cpp
Expand Up @@ -32,7 +32,7 @@ void ParticleDebug::Debug(int mode, int x, int y)
}
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;
logmessage << "Updated particles from #" << debug_currentParticle << " to end, updated sim";
Expand Down
8 changes: 4 additions & 4 deletions src/graphics/Renderer.cpp
Expand Up @@ -1245,7 +1245,7 @@ void Renderer::render_parts()

if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0)
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;

//Defaults
Expand Down Expand Up @@ -1994,7 +1994,7 @@ void Renderer::render_parts()
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(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]);
}
}
Expand All @@ -2011,14 +2011,14 @@ void Renderer::render_parts()
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(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]);
}
}
if (pixel_mode & EFFECT_DBGLINES && !(display_mode&DISPLAY_PERS))
{
// 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;
if (type == PT_PRTI)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameModel.cpp
Expand Up @@ -305,7 +305,7 @@ void GameModel::BuildMenus()
//Build menu for GOL types
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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/game/GameView.cpp
Expand Up @@ -2293,7 +2293,7 @@ void GameView::OnDraw()
{
int ctype = sample.particle.ctype;
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)
wavelengthGfx = (ctype&0x3FFFFFFF);
Expand Down Expand Up @@ -2322,7 +2322,7 @@ void GameView::OnDraw()
sampleInfo << " (" << ctype << ")";
// 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)
sampleInfo << " (" << c->ElementResolve(ctype&0xFF, ctype>>8) << ")";
sampleInfo << " (" << c->ElementResolve(TYP(type), ID(ctype)) << ")";
else if (c->IsValidElement(ctype))
sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")";
else
Expand Down
6 changes: 3 additions & 3 deletions src/gui/game/PropertyTool.cpp
Expand Up @@ -255,14 +255,14 @@ void PropertyTool::SetProperty(Simulation *sim, ui::Point position)
switch (propType)
{
case StructProperty::Float:
*((float*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.Float;
*((float*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.Float;
break;
case StructProperty::ParticleType:
case StructProperty::Integer:
*((int*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.Integer;
*((int*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.Integer;
break;
case StructProperty::UInteger:
*((unsigned int*)(((char*)&sim->parts[i>>8])+propOffset)) = propValue.UInteger;
*((unsigned int*)(((char*)&sim->parts[ID(i)])+propOffset)) = propValue.UInteger;
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/game/SampleTool.cpp
Expand Up @@ -35,13 +35,13 @@ void SampleTool::Draw(Simulation * sim, Brush * brush, ui::Point position)
int particleCtype = 0;
if (sim->photons[position.Y][position.X])
{
particleType = sim->parts[sim->photons[position.Y][position.X]>>8].type;
particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype;
particleType = sim->parts[ID(sim->photons[position.Y][position.X])].type;
particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
}
else if (sim->pmap[position.Y][position.X])
{
particleType = sim->parts[sim->pmap[position.Y][position.X]>>8].type;
particleCtype = sim->parts[sim->pmap[position.Y][position.X]>>8].ctype;
particleType = sim->parts[ID(sim->pmap[position.Y][position.X])].type;
particleCtype = sim->parts[ID(sim->pmap[position.Y][position.X])].ctype;
}

if(particleType)
Expand Down
6 changes: 3 additions & 3 deletions src/gui/game/Tool.cpp
Expand Up @@ -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) {
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) {
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)
{
sim->create_part(-2, position.X, position.Y, toolID&0xFF, toolID>>8);
sim->create_part(-2, position.X, position.Y, TYP(toolID), ID(toolID));
}
8 changes: 4 additions & 4 deletions src/lua/LegacyLuaAPI.cpp
Expand Up @@ -1146,11 +1146,11 @@ int luatpt_set_property(lua_State* l)
if (i>=XRES || y>=YRES)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
r = luacon_sim->pmap[y][i];
if (!r || (partsel && partsel != (r&0xFF)))
if (!r || (partsel && partsel != TYP(r)))
r = luacon_sim->photons[y][i];
if (!r || (partsel && partsel != (r&0xFF)))
if (!r || (partsel && partsel != TYP(r)))
return 0;
i = r>>8;
i = ID(r);
}
if (i < 0 || i >= NPART)
return luaL_error(l, "Invalid particle ID '%d'", i);
Expand Down Expand Up @@ -1295,7 +1295,7 @@ int luatpt_get_property(lua_State* l)
return luaL_error(l, "Particle does not exist");
}
}
i = r>>8;
i = ID(r);
}
else if (y != -1)
return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
Expand Down
31 changes: 17 additions & 14 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -800,6 +800,9 @@ void LuaScriptInterface::initSimulationAPI()
SETCONST(l, DECO_DIVIDE);
SETCONST(l, DECO_SMUDGE);

SETCONST(l, PMAPBITS);
SETCONST(l, PMAPMASK);

//Declare FIELD_BLAH constants
std::vector<StructProperty> particlePropertiesV = Particle::GetProperties();
particlePropertiesCount = 0;
Expand Down Expand Up @@ -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))
{
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];
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++);
}
}
Expand All @@ -897,7 +900,7 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
n = luacon_sim->photons[y+ry][x+rx];
if (n)
{
lua_pushinteger(l, n>>8);
lua_pushinteger(l, ID(n));
lua_rawseti(l, -2, id++);
}
}
Expand Down Expand Up @@ -929,10 +932,10 @@ int LuaScriptInterface::simulation_partCreate(lua_State * l)
}
int type = lua_tointeger(l, 4);
int v = -1;
if (type>>8)
if (ID(type))
{
v = type>>8;
type = type&0xFF;
v = ID(type);
type = TYP(type);
}
lua_pushinteger(l, luacon_sim->create_part(newID, lua_tointeger(l, 2), lua_tointeger(l, 3), type, v));
return 1;
Expand All @@ -955,7 +958,7 @@ int LuaScriptInterface::simulation_partID(lua_State * l)
if (!amalgam)
lua_pushnil(l);
else
lua_pushinteger(l, amalgam >> 8);
lua_pushinteger(l, ID(amalgam));
return 1;
}

Expand Down Expand Up @@ -2045,9 +2048,9 @@ int LuaScriptInterface::simulation_pmap(lua_State * l)
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
int r = luacon_sim->pmap[y][x];
if (!(r&0xFF))
if (!TYP(r))
return 0;
lua_pushnumber(l, r>>8);
lua_pushnumber(l, ID(r));
return 1;
}

Expand All @@ -2058,9 +2061,9 @@ int LuaScriptInterface::simulation_photons(lua_State * l)
if (x < 0 || x >= XRES || y < 0 || y >= YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
int r = luacon_sim->photons[y][x];
if (!(r&0xFF))
if (!TYP(r))
return 0;
lua_pushnumber(l, r>>8);
lua_pushnumber(l, ID(r));
return 1;
}

Expand Down Expand Up @@ -2090,12 +2093,12 @@ int NeighboursClosure(lua_State * l)
i=luacon_sim->pmap[y+sy][x+sx];
if(!i)
i=luacon_sim->photons[y+sy][x+sx];
} while(!(i&0xFF));
} while(!TYP(i));
lua_pushnumber(l, x);
lua_replace(l, lua_upvalueindex(5));
lua_pushnumber(l, y);
lua_replace(l, lua_upvalueindex(6));
lua_pushnumber(l, i>>8);
lua_pushnumber(l, ID(i));
lua_pushnumber(l, x+sx);
lua_pushnumber(l, y+sy);
return 3;
Expand Down
6 changes: 3 additions & 3 deletions src/lua/TPTScriptInterface.cpp
Expand Up @@ -457,10 +457,10 @@ AnyType TPTScriptInterface::tptS_create(std::deque<std::string> * words)
throw GeneralException("Invalid position");

int v = -1;
if (type>>8)
if (ID(type))
{
v = type>>8;
type = type&0xFF;
v = ID(type);
type = TYP(type);
}
int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type, v);

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/Sign.cpp
Expand Up @@ -35,7 +35,7 @@ std::string sign::getText(Simulation *sim)
else if (!strcmp(signText,"{t}"))
{
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
sprintf(buff, "Temp: 0.00"); //...temperature
}
Expand Down
12 changes: 6 additions & 6 deletions src/simulation/simtools/Mix.cpp
Expand Up @@ -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);

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;

int newX = x + (rand() % distance) - (distance/2);
Expand All @@ -32,16 +32,16 @@ int Tool_Mix::Perform(Simulation * sim, Particle * cpart, int x, int y, float st
if(!thatPart)
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;

sim->pmap[y][x] = thatPart;
sim->parts[thatPart>>8].x = x;
sim->parts[thatPart>>8].y = y;
sim->parts[ID(thatPart)].x = x;
sim->parts[ID(thatPart)].y = y;

sim->pmap[newY][newX] = thisPart;
sim->parts[thisPart>>8].x = newX;
sim->parts[thisPart>>8].y = newY;
sim->parts[ID(thisPart)].x = newX;
sim->parts[ID(thisPart)].y = newY;

return 1;
}
Expand Down

0 comments on commit 0c8c4de

Please sign in to comment.