summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorBryan Hoyle <starfoxprime@gmail.com>2012-11-16 21:51:55 (GMT)
committer Bryan Hoyle <starfoxprime@gmail.com>2012-11-16 21:51:55 (GMT)
commit874cd400093c38e67fde4a1861603bce83135539 (patch)
treee9c8b31b7cc752133dd0e110c652ed9775e859d5 /src/simulation
parente0aa92b017a8d5602ce8b43f6e240ab42a25fac4 (diff)
parentd8be547c734cfaa3d121412b11381b4787380762 (diff)
downloadpowder-874cd400093c38e67fde4a1861603bce83135539.zip
powder-874cd400093c38e67fde4a1861603bce83135539.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Element.h3
-rw-r--r--src/simulation/Simulation.cpp44
-rw-r--r--src/simulation/elements/FWRK.cpp2
-rw-r--r--src/simulation/elements/PLNT.cpp2
-rw-r--r--src/simulation/elements/WOOD.cpp2
5 files changed, 47 insertions, 6 deletions
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);