diff options
| author | Bryan Hoyle <starfoxprime@gmail.com> | 2012-11-16 21:51:55 (GMT) |
|---|---|---|
| committer | Bryan Hoyle <starfoxprime@gmail.com> | 2012-11-16 21:51:55 (GMT) |
| commit | 874cd400093c38e67fde4a1861603bce83135539 (patch) | |
| tree | e9c8b31b7cc752133dd0e110c652ed9775e859d5 /src | |
| parent | e0aa92b017a8d5602ce8b43f6e240ab42a25fac4 (diff) | |
| parent | d8be547c734cfaa3d121412b11381b4787380762 (diff) | |
| download | powder-874cd400093c38e67fde4a1861603bce83135539.zip powder-874cd400093c38e67fde4a1861603bce83135539.tar.gz | |
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src')
| -rw-r--r-- | src/Config.h | 4 | ||||
| -rw-r--r-- | src/cat/LegacyLuaAPI.cpp | 2 | ||||
| -rw-r--r-- | src/cat/TPTScriptInterface.cpp | 2 | ||||
| -rw-r--r-- | src/client/GameSave.cpp | 36 | ||||
| -rw-r--r-- | src/client/GameSave.h | 4 | ||||
| -rw-r--r-- | src/game/Brush.cpp | 11 | ||||
| -rw-r--r-- | src/game/GameController.cpp | 8 | ||||
| -rw-r--r-- | src/game/GameModel.cpp | 6 | ||||
| -rw-r--r-- | src/interface/SaveButton.cpp | 26 | ||||
| -rw-r--r-- | src/save/ServerSaveActivity.cpp | 4 | ||||
| -rw-r--r-- | src/simulation/Element.h | 3 | ||||
| -rw-r--r-- | src/simulation/Simulation.cpp | 44 | ||||
| -rw-r--r-- | src/simulation/elements/FWRK.cpp | 2 | ||||
| -rw-r--r-- | src/simulation/elements/PLNT.cpp | 2 | ||||
| -rw-r--r-- | src/simulation/elements/WOOD.cpp | 2 | ||||
| -rw-r--r-- | src/tasks/TaskWindow.cpp | 2 |
16 files changed, 126 insertions, 32 deletions
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/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); 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<std::string> * 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/client/GameSave.cpp b/src/client/GameSave.cpp index 9072921..1751c54 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,24 @@ 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)); + } + } + } + } } //Read wall and fan data @@ -1622,7 +1641,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 +1958,15 @@ 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<PaletteItem>::iterator iter = palette.begin(), end = palette.end(); iter != end; ++iter) + { + bson_append_int(&b, (*iter).first.c_str(), (*iter).second); + } + bson_append_finish_array(&b); + } signsCount = 0; for(i = 0; i < signs.size(); i++) { @@ -1965,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); @@ -1994,7 +2024,9 @@ char * GameSave::serialiseOPS(int & dataLength) goto fin; } +#ifdef DEBUG printf("compressed data: %d\n", outputDataLen); +#endif dataLength = outputDataLen + 12; fin: 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<sign> signs; + + //Element palette + typedef std::pair<std::string, int> PaletteItem; + std::vector<PaletteItem> palette; GameSave(); GameSave(GameSave & save); diff --git a/src/game/Brush.cpp b/src/game/Brush.cpp index 5341f60..38dd809 100644 --- a/src/game/Brush.cpp +++ b/src/game/Brush.cpp @@ -18,9 +18,14 @@ 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); + if(width>0) + 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) 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..5c4ee97 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; @@ -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(); 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; } } } 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/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 <Windows.h> -#endif #define IPL -257.0f #define IPH 257.0f 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<GameSave::PaletteItem>::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)); + } } } 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); 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(); } } |
