Merge branch 'master' of github.com:FacialTurd/PowderToypp

This commit is contained in:
Bryan Hoyle 2012-11-16 16:51:55 -05:00
commit 874cd40009
16 changed files with 126 additions and 32 deletions

View File

@ -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

View File

@ -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);

View File

@ -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");

View File

@ -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:

View File

@ -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);

View File

@ -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)

View File

@ -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)

View File

@ -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();

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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

View File

@ -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));
}
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -60,7 +60,7 @@ void TaskWindow::Exit()
if(ui::Engine::Ref().GetWindow()==this)
{
ui::Engine::Ref().CloseWindow();
delete this;
SelfDestruct();
}
}