From 0c8c4de125880febb5388650a0a6437f007b80cc Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 29 Dec 2017 21:01:28 -0500 Subject: [PATCH] convert all of the rest of the things except GameSave.cpp and pipe/ray elements also add sim.PMAPBITS and sim.PMAPMASK constants --- src/debug/ParticleDebug.cpp | 2 +- src/graphics/Renderer.cpp | 8 ++++---- src/gui/game/GameModel.cpp | 2 +- src/gui/game/GameView.cpp | 4 ++-- src/gui/game/PropertyTool.cpp | 6 +++--- src/gui/game/SampleTool.cpp | 8 ++++---- src/gui/game/Tool.cpp | 6 +++--- src/lua/LegacyLuaAPI.cpp | 8 ++++---- src/lua/LuaScriptInterface.cpp | 31 +++++++++++++++++-------------- src/lua/TPTScriptInterface.cpp | 6 +++--- src/simulation/Sign.cpp | 2 +- src/simulation/simtools/Mix.cpp | 12 ++++++------ 12 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/debug/ParticleDebug.cpp b/src/debug/ParticleDebug.cpp index 7fb4e3b13..c838cc64d 100644 --- a/src/debug/ParticleDebug.cpp +++ b/src/debug/ParticleDebug.cpp @@ -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"; diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 5110804fa..03376221c 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -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 @@ -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+nyo0 && nx+nxopmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTI) + if (ny+nyo>0 && ny+nyo0 && nx+nxopmap[ny+nyo][nx+nxo]) != PT_PRTI) 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; nxo = (int)(ddist*cos(drad)); nyo = (int)(ddist*sin(drad)); - if (ny+nyo>0 && ny+nyo0 && nx+nxopmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTO) + if (ny+nyo>0 && ny+nyo0 && nx+nxopmap[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) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index d50b99a95..f81ecefc6 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -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); } diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 81f4d9952..73fb76b4a 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -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); @@ -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 diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index 2a71adce4..359f7f771 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -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; diff --git a/src/gui/game/SampleTool.cpp b/src/gui/game/SampleTool.cpp index b6e855dc9..3e38ea08f 100644 --- a/src/gui/game/SampleTool.cpp +++ b/src/gui/game/SampleTool.cpp @@ -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) diff --git a/src/gui/game/Tool.cpp b/src/gui/game/Tool.cpp index 2e79dab78..c2c48921c 100644 --- a/src/gui/game/Tool.cpp +++ b/src/gui/game/Tool.cpp @@ -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)); } diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index f557a0e5b..93ec42734 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -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); @@ -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); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 73d7db531..00b2a2a60 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -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 particlePropertiesV = Particle::GetProperties(); 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)) { 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++); } } @@ -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++); } } @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; diff --git a/src/lua/TPTScriptInterface.cpp b/src/lua/TPTScriptInterface.cpp index 6c786682f..8b66d46dc 100644 --- a/src/lua/TPTScriptInterface.cpp +++ b/src/lua/TPTScriptInterface.cpp @@ -457,10 +457,10 @@ AnyType TPTScriptInterface::tptS_create(std::deque * 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); diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index c9d734deb..c96ccfa8d 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -35,7 +35,7 @@ std::string sign::getText(Simulation *sim) else if (!strcmp(signText,"{t}")) { if (x>=0 && x=0 && ypmap[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 } diff --git a/src/simulation/simtools/Mix.cpp b/src/simulation/simtools/Mix.cpp index 185be9931..aec342acc 100755 --- a/src/simulation/simtools/Mix.cpp +++ b/src/simulation/simtools/Mix.cpp @@ -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); @@ -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; }