From 29189693b381ce7b31095fb2ae2ffb01bd8a221e Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 12 Nov 2012 10:22:16 +0000 Subject: Element palette for automatic element ID/mod mapping diff --git a/src/Config.h b/src/Config.h index e810221..5d2a1a5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -21,11 +21,11 @@ #endif #ifndef MINOR_VERSION -#define MINOR_VERSION 0 +#define MINOR_VERSION 2 #endif #ifndef BUILD_NUM -#define BUILD_NUM 246 +#define BUILD_NUM 248 #endif #ifndef SNAPSHOT_ID diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 9072921..0b94c1f 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -23,7 +23,8 @@ airMode(save.airMode), signs(save.signs), expanded(save.expanded), hasOriginalData(save.hasOriginalData), -originalData(save.originalData) +originalData(save.originalData), +palette(save.palette) { blockMap = NULL; blockMapPtr = NULL; @@ -659,6 +660,25 @@ void GameSave::readOPS(char * data, int dataLength) fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter)); } } + else if(strcmp(bson_iterator_key(&iter), "palette")==0) + { + palette.clear(); + if(bson_iterator_type(&iter)==BSON_ARRAY) + { + bson_iterator subiter; + bson_iterator_subiterator(&iter, &subiter); + while(bson_iterator_next(&subiter)) + { + if(bson_iterator_type(&subiter)==BSON_INT) + { + std::string id = std::string(bson_iterator_key(&subiter)); + int num = bson_iterator_int(&subiter); + palette.push_back(PaletteItem(id, num)); + printf("R P: %s %d\n", id.c_str(), num); + } + } + } + } } //Read wall and fan data @@ -1622,7 +1642,7 @@ char * GameSave::serialiseOPS(int & dataLength) int x, y, i, wallDataFound = 0; int posCount, signsCount; bson b; - + std::fill(elementCount, elementCount+PT_NUM, 0); //Get coords in blocks @@ -1939,6 +1959,16 @@ char * GameSave::serialiseOPS(int & dataLength) bson_append_binary(&b, "fanMap", BSON_BIN_USER, (const char *)fanData, fanDataLen); if(soapLinkData) bson_append_binary(&b, "soapLinks", BSON_BIN_USER, (const char *)soapLinkData, soapLinkDataLen); + if(partsData && palette.size()) + { + bson_append_start_array(&b, "palette"); + for(std::vector::iterator iter = palette.begin(), end = palette.end(); iter != end; ++iter) + { + bson_append_int(&b, (*iter).first.c_str(), (*iter).second); + printf("W P: %s %d\n", (*iter).first.c_str(), (*iter).second); + } + bson_append_finish_array(&b); + } signsCount = 0; for(i = 0; i < signs.size(); i++) { diff --git a/src/client/GameSave.h b/src/client/GameSave.h index 62adc17..8ac1fce 100644 --- a/src/client/GameSave.h +++ b/src/client/GameSave.h @@ -55,6 +55,10 @@ public: //Signs std::vector signs; + + //Element palette + typedef std::pair PaletteItem; + std::vector palette; GameSave(); GameSave(GameSave & save); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index ee4634c..a7f3750 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -45,6 +45,29 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) fullX = blockX*CELL; fullY = blockY*CELL; + int partMap[PT_NUM]; + for(int i = 0; i < PT_NUM; i++) + { + partMap[i] = i; + } + if(save->palette.size()) + { + for(std::vector::iterator iter = save->palette.begin(), end = save->palette.end(); iter != end; ++iter) + { + GameSave::PaletteItem pi = *iter; + if(pi.second >= 0 && pi.second < PT_NUM) + { + int myId = 0;//pi.second; + for(int i = 0; i < PT_NUM; i++) + { + if(elements[i].Enabled && elements[i].Identifier == pi.first) + myId = i; + } + partMap[pi.second] = myId; + } + } + } + int i; for(int n = 0; n < NPART && n < save->particlesCount; n++) { @@ -54,6 +77,9 @@ int Simulation::Load(int fullX, int fullY, GameSave * save) x = int(tempPart.x + 0.5f); y = int(tempPart.y + 0.5f); + if(tempPart.type >= 0 && tempPart.type < PT_NUM) + tempPart.type = partMap[tempPart.type]; + if ((player.spwn == 1 && tempPart.type==PT_STKM) || (player2.spwn == 1 && tempPart.type==PT_STKM2)) continue; if (!elements[tempPart.type].Enabled) @@ -182,6 +208,9 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) GameSave * newSave = new GameSave(blockW, blockH); + int storedParts = 0; + int elementCount[PT_NUM]; + std::fill(elementCount, elementCount+PT_NUM, 0); for(int i = 0; i < NPART; i++) { int x, y; @@ -193,7 +222,22 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) tempPart.x -= fullX; tempPart.y -= fullY; if(elements[tempPart.type].Enabled) + { *newSave << tempPart; + storedParts++; + elementCount[tempPart.type]++; + } + } + } + + if(storedParts) + { + for(int i = 0; i < PT_NUM; i++) + { + if(elements[i].Enabled && elementCount[i]) + { + newSave->palette.push_back(GameSave::PaletteItem(elements[i].Identifier, i)); + } } } -- cgit v0.9.2-21-gd62e From 947301c302ca84843300e08abf5ea920693d44dd Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 8 Nov 2012 14:28:47 +0400 Subject: Better rectangle tool render function, no crappy pixels in edge cases anymore diff --git a/src/game/Brush.cpp b/src/game/Brush.cpp index 5341f60..e57a771 100644 --- a/src/game/Brush.cpp +++ b/src/game/Brush.cpp @@ -18,9 +18,13 @@ void Brush::RenderRect(Renderer * ren, ui::Point position1, ui::Point position2) } ren->xor_line(position1.X, position1.Y, position1.X+width, position1.Y); - ren->xor_line(position1.X, position1.Y+height, position1.X+width, position1.Y+height); - ren->xor_line(position1.X+width, position1.Y+1, position1.X+width, position1.Y+height-1); - ren->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1); + if(height>0){ + ren->xor_line(position1.X, position1.Y+height, position1.X+width, position1.Y+height); + if(height>1){ + ren->xor_line(position1.X+width, position1.Y+1, position1.X+width, position1.Y+height-1); + ren->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1); + } + } } void Brush::RenderLine(Renderer * ren, ui::Point position1, ui::Point position2) -- cgit v0.9.2-21-gd62e From 3d635bc68f79e7e98e3e1db7924abd8f9f990e8c Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 8 Nov 2012 14:31:28 +0400 Subject: More edge cases diff --git a/src/game/Brush.cpp b/src/game/Brush.cpp index e57a771..38dd809 100644 --- a/src/game/Brush.cpp +++ b/src/game/Brush.cpp @@ -22,7 +22,8 @@ void Brush::RenderRect(Renderer * ren, ui::Point position1, ui::Point position2) ren->xor_line(position1.X, position1.Y+height, position1.X+width, position1.Y+height); if(height>1){ ren->xor_line(position1.X+width, position1.Y+1, position1.X+width, position1.Y+height-1); - ren->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1); + if(width>0) + ren->xor_line(position1.X, position1.Y+1, position1.X, position1.Y+height-1); } } } -- cgit v0.9.2-21-gd62e From 51a5af6d5d30c6d15877314d6973d841fad7bc74 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 12 Nov 2012 10:48:20 +0000 Subject: Remove some debug printing diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 0b94c1f..1751c54 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -674,7 +674,6 @@ void GameSave::readOPS(char * data, int dataLength) std::string id = std::string(bson_iterator_key(&subiter)); int num = bson_iterator_int(&subiter); palette.push_back(PaletteItem(id, num)); - printf("R P: %s %d\n", id.c_str(), num); } } } @@ -1965,7 +1964,6 @@ char * GameSave::serialiseOPS(int & dataLength) for(std::vector::iterator iter = palette.begin(), end = palette.end(); iter != end; ++iter) { bson_append_int(&b, (*iter).first.c_str(), (*iter).second); - printf("W P: %s %d\n", (*iter).first.c_str(), (*iter).second); } bson_append_finish_array(&b); } @@ -1995,7 +1993,9 @@ char * GameSave::serialiseOPS(int & dataLength) bson_append_finish_array(&b); } bson_finish(&b); +#ifdef DEBUG bson_print(&b); +#endif finalData = (unsigned char *)bson_data(&b); finalDataLen = bson_size(&b); @@ -2024,7 +2024,9 @@ char * GameSave::serialiseOPS(int & dataLength) goto fin; } +#ifdef DEBUG printf("compressed data: %d\n", outputDataLen); +#endif dataLength = outputDataLen + 12; fin: -- cgit v0.9.2-21-gd62e From 785fbcefdf8e2e71063f947abf307becc0bf8c26 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 15 Nov 2012 13:01:25 +0000 Subject: Fix divide-by-zero error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...  when displaying save buttons that have zero votes. diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp index 93a22f7..eb2640b 100644 --- a/src/interface/SaveButton.cpp +++ b/src/interface/SaveButton.cpp @@ -68,19 +68,27 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save): votesString = votes; int voteMax = std::max(save->GetVotesUp(),save->GetVotesDown()); - if (voteMax < 34) + if (voteMax) { - float ry = 33.0f/voteMax; - if (voteMax<8) - ry = ry/(8-voteMax); - voteBarHeightUp = (int)(save->GetVotesUp()*ry)-1; - voteBarHeightDown = (int)(save->GetVotesDown()*ry)-1; + if (voteMax < 34) + { + float ry = 33.0f/voteMax; + if (voteMax<8) + ry = ry/(8-voteMax); + voteBarHeightUp = (int)(save->GetVotesUp()*ry)-1; + voteBarHeightDown = (int)(save->GetVotesDown()*ry)-1; + } + else + { + float ry = voteMax/33.0f; + voteBarHeightUp = (int)(save->GetVotesUp()/ry)-1; + voteBarHeightDown = (int)(save->GetVotesDown()/ry)-1; + } } else { - float ry = voteMax/33.0f; - voteBarHeightUp = (int)(save->GetVotesUp()/ry)-1; - voteBarHeightDown = (int)(save->GetVotesDown()/ry)-1; + voteBarHeightUp = 0; + voteBarHeightDown = 0; } } } -- cgit v0.9.2-21-gd62e From 38a18af2c5557ee80392ac3f124fdfd531eaf45d Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 15 Nov 2012 20:00:55 -0500 Subject: fix crashes when deleting stamps or getting an error when saving diff --git a/src/save/ServerSaveActivity.cpp b/src/save/ServerSaveActivity.cpp index d336ea1..eda807b 100644 --- a/src/save/ServerSaveActivity.cpp +++ b/src/save/ServerSaveActivity.cpp @@ -174,8 +174,8 @@ void ServerSaveActivity::Save() virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) { if (result == ConfirmPrompt::ResultOkay) { - a->saveUpload(); a->Exit(); + a->saveUpload(); } } virtual ~PublishConfirmation() { } @@ -189,8 +189,8 @@ void ServerSaveActivity::Save() } else { - saveUpload(); Exit(); + saveUpload(); } } else diff --git a/src/tasks/TaskWindow.cpp b/src/tasks/TaskWindow.cpp index 7a1c544..b3055d1 100644 --- a/src/tasks/TaskWindow.cpp +++ b/src/tasks/TaskWindow.cpp @@ -60,7 +60,7 @@ void TaskWindow::Exit() if(ui::Engine::Ref().GetWindow()==this) { ui::Engine::Ref().CloseWindow(); - delete this; + SelfDestruct(); } } -- cgit v0.9.2-21-gd62e From bf3d7e9ad76a9c06c2f7f5771311dc8ea481dd96 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 15 Nov 2012 20:13:19 -0500 Subject: fix tpt.el.X.name commands diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index d6e6ce6..9a478e7 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -462,7 +462,7 @@ int luacon_elementwrite(lua_State* l){ free(key); return luaL_error(l, "Name too long"); } - if(luacon_ci->GetParticleType(tempstring) == -1) + if(luacon_ci->GetParticleType(tempstring) != -1) { free(tempstring); free(key); -- cgit v0.9.2-21-gd62e From 1e32c545d9ca7f960cdd6f77714c7b2761880478 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 15 Nov 2012 20:23:38 -0500 Subject: fix visual studio std::max problem diff --git a/src/simulation/Element.h b/src/simulation/Element.h index d9c7903..3c28e2f 100644 --- a/src/simulation/Element.h +++ b/src/simulation/Element.h @@ -8,9 +8,6 @@ #include "Gravity.h" #include "Misc.h" #include "ElementGraphics.h" -#ifdef _MSC_VER -#include -#endif #define IPL -257.0f #define IPH 257.0f diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index f9313fa..538bd05 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -96,6 +96,12 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) (rt!=PT_SPNG || parts[r>>8].life==0) && sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000)) { + int j = sim->create_part(-1, x-1+rand()%3, y-1+rand()%3, PT_SMKE); + if (j != -1) + { + parts[r>>8].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); + parts[j].life = rand()%80+480; + } sim->part_change_type(r>>8,x+rx,y+ry,PT_FIRE); parts[r>>8].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); parts[r>>8].life = rand()%80+180; diff --git a/src/simulation/elements/FWRK.cpp b/src/simulation/elements/FWRK.cpp index 6889f91..f05db69 100644 --- a/src/simulation/elements/FWRK.cpp +++ b/src/simulation/elements/FWRK.cpp @@ -61,7 +61,7 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS) gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f; } - gmax = fmaxf(fabsf(gx), fabsf(gy)); + gmax = std::max(fabsf(gx), fabsf(gy)); if (sim->eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL)) { multiplier = 15.0f/sqrtf(gx*gx+gy*gy); diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp index 84a83c2..e7439d1 100644 --- a/src/simulation/elements/PLNT.cpp +++ b/src/simulation/elements/PLNT.cpp @@ -107,7 +107,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_PLNT static int graphics(GRAPHICS_FUNC_ARGS) int Element_PLNT::graphics(GRAPHICS_FUNC_ARGS) { - float maxtemp = fmax(cpart->tmp2, cpart->temp); + float maxtemp = std::max((float)cpart->tmp2, cpart->temp); if (maxtemp > 300) { *colr += (int)restrict_flt((maxtemp-300)/5,0,58); diff --git a/src/simulation/elements/WOOD.cpp b/src/simulation/elements/WOOD.cpp index cbbab8f..134d827 100644 --- a/src/simulation/elements/WOOD.cpp +++ b/src/simulation/elements/WOOD.cpp @@ -49,7 +49,7 @@ Element_WOOD::Element_WOOD() //#TPT-Directive ElementHeader Element_WOOD static int graphics(GRAPHICS_FUNC_ARGS) int Element_WOOD::graphics(GRAPHICS_FUNC_ARGS) { - float maxtemp = fmax(cpart->tmp, cpart->temp); + float maxtemp = std::max((float)cpart->tmp, cpart->temp); if (maxtemp > 400) { *colr -= (int)restrict_flt((maxtemp-400)/3,0,172); -- cgit v0.9.2-21-gd62e From 16e4c5f7179db5beabe3065781adec7d27000cd9 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 15 Nov 2012 20:41:38 -0500 Subject: save pause state in stamps, load pause state from local saves and stamps correctly, remove accidental inclusion diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index 4782838..684467f 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -219,7 +219,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) newValue = GetParticleType(((StringType)value).Value()); if (newValue < 0 || newValue >= PT_NUM) { - if (((StringType)value).Value() == "GOLD") + if (((StringType)value).Value() == "GOLD" || ((StringType)value).Value() == "gold") throw GeneralException("No, GOLD will not be an element"); else throw GeneralException("Invalid element"); diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 0f3d92e..0cff7d2 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -240,7 +240,7 @@ void GameController::PlaceSave(ui::Point position) if(gameModel->GetPlaceSave()) { gameModel->GetSimulation()->Load(position.X, position.Y, gameModel->GetPlaceSave()); - gameModel->SetPaused(gameModel->GetPaused()); + gameModel->SetPaused(gameModel->GetPlaceSave()->paused | gameModel->GetPaused()); } } @@ -489,7 +489,10 @@ void GameController::StampRegion(ui::Point point1, ui::Point point2) GameSave * newSave; newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y); if(newSave) + { + newSave->paused = gameModel->GetPaused(); gameModel->AddStamp(newSave); + } else new ErrorMessage("Could not create stamp", "Error generating save file"); } @@ -499,7 +502,10 @@ void GameController::CopyRegion(ui::Point point1, ui::Point point2) GameSave * newSave; newSave = gameModel->GetSimulation()->Save(point1.X, point1.Y, point2.X, point2.Y); if(newSave) + { + newSave->paused = gameModel->GetPaused(); gameModel->SetClipboard(newSave); + } } void GameController::CutRegion(ui::Point point1, ui::Point point2) diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 4a11d55..774d636 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -587,7 +587,7 @@ void GameModel::SetSaveFile(SaveFile * newSave) if(newSave && newSave->GetGameSave()) { GameSave * saveData = newSave->GetGameSave(); - SetPaused(saveData->paused & GetPaused()); + SetPaused(saveData->paused | GetPaused()); sim->gravityMode = saveData->gravityMode; sim->air->airMode = saveData->airMode; sim->legacy_enable = saveData->legacyEnable; diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index 538bd05..f9313fa 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -96,12 +96,6 @@ int Element_FIRE::update(UPDATE_FUNC_ARGS) (rt!=PT_SPNG || parts[r>>8].life==0) && sim->elements[rt].Flammable && (sim->elements[rt].Flammable + (int)(sim->pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000)) { - int j = sim->create_part(-1, x-1+rand()%3, y-1+rand()%3, PT_SMKE); - if (j != -1) - { - parts[r>>8].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); - parts[j].life = rand()%80+480; - } sim->part_change_type(r>>8,x+rx,y+ry,PT_FIRE); parts[r>>8].temp = restrict_flt(sim->elements[PT_FIRE].Temperature + (sim->elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP); parts[r>>8].life = rand()%80+180; -- cgit v0.9.2-21-gd62e From d8be547c734cfaa3d121412b11381b4787380762 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 15 Nov 2012 20:50:19 -0500 Subject: fix pause state being reset every time you clear the sim diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 774d636..5c4ee97 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -823,17 +823,15 @@ void GameModel::FrameStep(int frames) void GameModel::ClearSimulation() { - sim->clear_sim(); - ren->ClearAccumulation(); //Load defaults - SetPaused(false); sim->gravityMode = 0; sim->air->airMode = 0; sim->legacy_enable = false; sim->water_equal_test = false; sim->grav->stop_grav_async(); sim->SetEdgeMode(edgeMode); + sim->clear_sim(); ren->ClearAccumulation(); -- cgit v0.9.2-21-gd62e