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

This commit is contained in:
build.powdertoy.co.uk
2012-07-20 20:10:56 +01:00
7 changed files with 170 additions and 67 deletions

View File

@@ -112,7 +112,7 @@ if(GetOption('lin32') or GetOption('lin64')):
if(GetOption('release')): if(GetOption('release')):
ev.Append(CCFLAGS='-O3') env.Append(CCFLAGS='-O3')
if(GetOption('opengl')): if(GetOption('opengl')):
env.Append(CPPDEFINES=["OGLI", "PIX32OGL"]) env.Append(CPPDEFINES=["OGLI", "PIX32OGL"])

View File

@@ -22,7 +22,13 @@ gravityMode(save.gravityMode),
airMode(save.airMode), airMode(save.airMode),
signs(save.signs) signs(save.signs)
{ {
blockMap, blockMapPtr, fanVelX, fanVelXPtr, fanVelY, fanVelYPtr, particles = NULL; blockMap = NULL;
blockMapPtr = NULL;
fanVelX = NULL;
fanVelXPtr = NULL;
fanVelY = NULL;
fanVelYPtr = NULL;
particles = NULL;
setSize(save.blockWidth, save.blockHeight); setSize(save.blockWidth, save.blockHeight);
@@ -35,14 +41,30 @@ signs(save.signs)
GameSave::GameSave(int width, int height) GameSave::GameSave(int width, int height)
{ {
blockMap, blockMapPtr, fanVelX, fanVelXPtr, fanVelY, fanVelYPtr, particles = NULL; blockMap = NULL;
blockMapPtr = NULL;
fanVelX = NULL;
fanVelXPtr = NULL;
fanVelY = NULL;
fanVelYPtr = NULL;
particles = NULL;
setSize(width, height); setSize(width, height);
} }
GameSave::GameSave(char * data, int dataSize) GameSave::GameSave(char * data, int dataSize)
{ {
blockWidth, blockHeight = 0; blockWidth = 0;
blockMap, blockMapPtr, fanVelX, fanVelXPtr, fanVelY, fanVelYPtr, particles = NULL; blockHeight = 0;
blockMap = NULL;
blockMapPtr = NULL;
fanVelX = NULL;
fanVelXPtr = NULL;
fanVelY = NULL;
fanVelYPtr = NULL;
particles = NULL;
try { try {
if(dataSize > 0) if(dataSize > 0)
{ {
@@ -65,6 +87,7 @@ GameSave::GameSave(char * data, int dataSize)
throw ParseException(ParseException::Corrupt, "No data"); throw ParseException(ParseException::Corrupt, "No data");
} }
} catch (ParseException& e) { } catch (ParseException& e) {
std::cout << e.what() << std::endl;
this->~GameSave(); //Free any allocated memory this->~GameSave(); //Free any allocated memory
throw; throw;
} }
@@ -487,7 +510,41 @@ void GameSave::readOPS(char * data, int dataLength)
{ {
if (wallData[y*blockW+x]) if (wallData[y*blockW+x])
blockMap[blockY+y][blockX+x] = wallData[y*blockW+x]; blockMap[blockY+y][blockX+x] = wallData[y*blockW+x];
if (wallData[y*blockW+x] == WL_FAN && fanData)
if (blockMap[y][x]==O_WL_WALLELEC)
blockMap[y][x]=WL_WALLELEC;
if (blockMap[y][x]==O_WL_EWALL)
blockMap[y][x]=WL_EWALL;
if (blockMap[y][x]==O_WL_DETECT)
blockMap[y][x]=WL_DETECT;
if (blockMap[y][x]==O_WL_STREAM)
blockMap[y][x]=WL_STREAM;
if (blockMap[y][x]==O_WL_FAN||blockMap[y][x]==O_WL_FANHELPER)
blockMap[y][x]=WL_FAN;
if (blockMap[y][x]==O_WL_ALLOWLIQUID)
blockMap[y][x]=WL_ALLOWLIQUID;
if (blockMap[y][x]==O_WL_DESTROYALL)
blockMap[y][x]=WL_DESTROYALL;
if (blockMap[y][x]==O_WL_ERASE)
blockMap[y][x]=WL_ERASE;
if (blockMap[y][x]==O_WL_WALL)
blockMap[y][x]=WL_WALL;
if (blockMap[y][x]==O_WL_ALLOWAIR)
blockMap[y][x]=WL_ALLOWAIR;
if (blockMap[y][x]==O_WL_ALLOWSOLID)
blockMap[y][x]=WL_ALLOWSOLID;
if (blockMap[y][x]==O_WL_ALLOWALLELEC)
blockMap[y][x]=WL_ALLOWALLELEC;
if (blockMap[y][x]==O_WL_EHOLE)
blockMap[y][x]=WL_EHOLE;
if (blockMap[y][x]==O_WL_ALLOWGAS)
blockMap[y][x]=WL_ALLOWGAS;
if (blockMap[y][x]==O_WL_GRAV)
blockMap[y][x]=WL_GRAV;
if (blockMap[y][x]==O_WL_ALLOWENERGY)
blockMap[y][x]=WL_ALLOWENERGY;
if (blockMap[y][x] == WL_FAN && fanData)
{ {
if(j+1 >= fanDataLen) if(j+1 >= fanDataLen)
{ {
@@ -737,6 +794,9 @@ void GameSave::readPSv(char * data, int dataLength)
vector<Element> elements = GetElements(); vector<Element> elements = GetElements();
try
{
//New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures //New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures
//This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error
@@ -803,6 +863,8 @@ void GameSave::readPSv(char * data, int dataLength)
throw ParseException(ParseException::Corrupt, "Cannot decompress"); throw ParseException(ParseException::Corrupt, "Cannot decompress");
dataLength = i; dataLength = i;
std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl;
if (dataLength < bw*bh) if (dataLength < bw*bh)
throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)"); throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)");
@@ -897,18 +959,18 @@ void GameSave::readPSv(char * data, int dataLength)
} }
for (y=by0; y<by0+bh; y++) for (y=by0; y<by0+bh; y++)
for (x=bx0; x<bx0+bw; x++) for (x=bx0; x<bx0+bw; x++)
if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==WL_FAN) if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==O_WL_FAN)
{ {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
fanVelX[y][x] = (d[p++]-127.0f)/64.0f; fanVelX[y][x] = (d[p++]-127.0f)/64.0f;
} }
for (y=by0; y<by0+bh; y++) for (y=by0; y<by0+bh; y++)
for (x=bx0; x<bx0+bw; x++) for (x=bx0; x<bx0+bw; x++)
if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==WL_FAN) if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==O_WL_FAN)
{ {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
fanVelY[y][x] = (d[p++]-127.0f)/64.0f; fanVelY[y][x] = (d[p++]-127.0f)/64.0f;
} }
@@ -920,11 +982,11 @@ void GameSave::readPSv(char * data, int dataLength)
for (x=x0; x<x0+w; x++) for (x=x0; x<x0+w; x++)
{ {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
j=d[p++]; j=d[p++];
if (j >= PT_NUM) { if (j >= PT_NUM) {
//TODO: Possibly some server side translation //TODO: Possibly some server side translation
j = PT_DUST;//goto corrupt; j = PT_DUST;//throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (j) if (j)
{ {
@@ -955,7 +1017,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
i--; i--;
if (p+1 >= dataLength) if (p+1 >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
if (i < NPART) if (i < NPART)
{ {
particles[i].vx = (d[p++]-127.0f)/16.0f; particles[i].vx = (d[p++]-127.0f)/16.0f;
@@ -972,7 +1034,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (ver>=44) { if (ver>=44) {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
ttv = (d[p++])<<8; ttv = (d[p++])<<8;
@@ -983,7 +1045,7 @@ void GameSave::readPSv(char * data, int dataLength)
} }
} else { } else {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
if (i <= NPART) if (i <= NPART)
particles[i-1].life = d[p++]*4; particles[i-1].life = d[p++]*4;
else else
@@ -998,7 +1060,7 @@ void GameSave::readPSv(char * data, int dataLength)
if (i) if (i)
{ {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
ttv = (d[p++])<<8; ttv = (d[p++])<<8;
@@ -1028,7 +1090,7 @@ void GameSave::readPSv(char * data, int dataLength)
if (i && (ty==PT_PBCN || (ty==PT_TRON && ver>=77))) if (i && (ty==PT_PBCN || (ty==PT_TRON && ver>=77)))
{ {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
if (i <= NPART) if (i <= NPART)
particles[i-1].tmp2 = d[p++]; particles[i-1].tmp2 = d[p++];
else else
@@ -1044,7 +1106,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (ver>=49) { if (ver>=49) {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
particles[i-1].dcolour = d[p++]<<24; particles[i-1].dcolour = d[p++]<<24;
@@ -1062,7 +1124,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (ver>=49) { if (ver>=49) {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
particles[i-1].dcolour |= d[p++]<<16; particles[i-1].dcolour |= d[p++]<<16;
@@ -1080,7 +1142,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (ver>=49) { if (ver>=49) {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
particles[i-1].dcolour |= d[p++]<<8; particles[i-1].dcolour |= d[p++]<<8;
@@ -1098,7 +1160,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (ver>=49) { if (ver>=49) {
if (p >= dataLength) { if (p >= dataLength) {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) { if (i <= NPART) {
particles[i-1].dcolour |= d[p++]; particles[i-1].dcolour |= d[p++];
@@ -1118,7 +1180,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
if (p >= dataLength) if (p >= dataLength)
{ {
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (i <= NPART) if (i <= NPART)
{ {
@@ -1160,7 +1222,7 @@ void GameSave::readPSv(char * data, int dataLength)
if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43) || (ty==PT_LIFE && ver>=51) || (ty==PT_PBCN && ver>=52) || (ty==PT_WIRE && ver>=55) || (ty==PT_STOR && ver>=59) || (ty==PT_CONV && ver>=60))) if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43) || (ty==PT_LIFE && ver>=51) || (ty==PT_PBCN && ver>=52) || (ty==PT_WIRE && ver>=55) || (ty==PT_STOR && ver>=59) || (ty==PT_CONV && ver>=60)))
{ {
if (p >= dataLength) if (p >= dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
if (i <= NPART) if (i <= NPART)
particles[i-1].ctype = d[p++]; particles[i-1].ctype = d[p++];
else else
@@ -1238,7 +1300,7 @@ void GameSave::readPSv(char * data, int dataLength)
for (i=0; i<j; i++) for (i=0; i<j; i++)
{ {
if (p+6 > dataLength) if (p+6 > dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
x = d[p++]; x = d[p++];
x |= ((unsigned)d[p++])<<8; x |= ((unsigned)d[p++])<<8;
tempSign.x = x+x0; tempSign.x = x+x0;
@@ -1249,7 +1311,7 @@ void GameSave::readPSv(char * data, int dataLength)
tempSign.ju = (sign::Justification)x; tempSign.ju = (sign::Justification)x;
x = d[p++]; x = d[p++];
if (p+x > dataLength) if (p+x > dataLength)
goto corrupt; throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
if(x>254) if(x>254)
x = 254; x = 254;
memcpy(tempSignText, d+p, x); memcpy(tempSignText, d+p, x);
@@ -1266,19 +1328,43 @@ void GameSave::readPSv(char * data, int dataLength)
signs.push_back(tempSigns[i]); signs.push_back(tempSigns[i]);
} }
version1: }
if (m) free(m); catch(ParseException & e)
if (d) free(d); {
if (fp) free(fp); if (m)
{
free(m);
m = 0;
}
if (d)
{
free(d);
d = 0;
}
if (fp)
{
free(fp);
fp = 0;
}
throw;
}
return; version1:
if (m)
corrupt: {
if (m) free(m); free(m);
if (d) free(d); m = 0;
if (fp) free(fp); }
if (d)
throw ParseException(ParseException::Corrupt, "Save data corrupt"); {
free(d);
d = 0;
}
if (fp)
{
free(fp);
fp = 0;
}
} }
char * GameSave::serialiseOPS(int & dataLength) char * GameSave::serialiseOPS(int & dataLength)

View File

@@ -850,6 +850,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case '`': case '`':
c->ShowConsole(); c->ShowConsole();
break; break;
case 'e':
c->OpenElementSearch();
break;
case 'f': case 'f':
c->FrameStep(); c->FrameStep();
break; break;

View File

@@ -38,7 +38,7 @@ void ToolButton::OnMouseUp(int x, int y, unsigned int button)
void ToolButton::Draw(const ui::Point& screenPos) void ToolButton::Draw(const ui::Point& screenPos)
{ {
Graphics * g = ui::Engine::Ref().g; Graphics * g = ui::Engine::Ref().g;
int totalColour = Appearance.BackgroundInactive.Red + (3*Appearance.BackgroundInactive.Green) + (2*Appearance.BackgroundInactive.Blue); int totalColour = Appearance.BackgroundInactive.Blue + (3*Appearance.BackgroundInactive.Green) + (2*Appearance.BackgroundInactive.Red);
g->fillrect(screenPos.X+2, screenPos.Y+2, Size.X-4, Size.Y-4, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, Appearance.BackgroundInactive.Alpha); g->fillrect(screenPos.X+2, screenPos.Y+2, Size.X-4, Size.Y-4, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, Appearance.BackgroundInactive.Alpha);

View File

@@ -48,11 +48,13 @@ void Label::SetText(std::string text)
void Label::updateMultiline() void Label::updateMultiline()
{ {
int lines = 1;
if(text.length()>0)
{
char * rawText = new char[text.length()+1]; char * rawText = new char[text.length()+1];
std::copy(text.begin(), text.end(), rawText); std::copy(text.begin(), text.end(), rawText);
rawText[text.length()] = 0; rawText[text.length()] = 0;
int lines = 1;
int currentWidth = 0; int currentWidth = 0;
char * lastSpace = NULL; char * lastSpace = NULL;
char * currentWord = rawText; char * currentWord = rawText;
@@ -73,7 +75,7 @@ void Label::updateMultiline()
currentWidth += width; currentWidth += width;
if(nextSpace) if(nextSpace)
nextSpace[0] = ' '; nextSpace[0] = ' ';
if(!(currentWord = strchr(currentWord+1, ' '))) if(!currentWord[0] || !currentWord[1] || !(currentWord = strchr(currentWord+1, ' ')))
break; break;
} }
if(autoHeight) if(autoHeight)
@@ -82,6 +84,15 @@ void Label::updateMultiline()
} }
textLines = std::string(rawText); textLines = std::string(rawText);
delete[] rawText; delete[] rawText;
}
else
{
if(autoHeight)
{
Size.Y = 12;
}
textLines = std::string("");
}
} }
std::string Label::GetText() std::string Label::GetText()

View File

@@ -244,6 +244,8 @@ void Textbox::Draw(const Point& screenPos)
} }
if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255);
} }
if(Appearance.icon)
g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon);
} }
/* /*

View File

@@ -216,7 +216,7 @@ void PreviewView::OnDraw()
g->draw_image(savePreview->Data, (Position.X+1)+(((XRES/2)-savePreview->Size.X)/2), (Position.Y+1)+(((YRES/2)-savePreview->Size.Y)/2), savePreview->Size.X, savePreview->Size.Y, 255); g->draw_image(savePreview->Data, (Position.X+1)+(((XRES/2)-savePreview->Size.X)/2), (Position.Y+1)+(((YRES/2)-savePreview->Size.Y)/2), savePreview->Size.X, savePreview->Size.Y, 255);
} }
g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100); g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100);
g->draw_line(Position.X+1+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255); g->draw_line(Position.X+1+XRES/2, Position.Y+1, Position.X+1+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255);
g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255); g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255);
@@ -509,6 +509,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
maxY += 16; maxY += 16;
tempComment = new ui::Label(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment); tempComment = new ui::Label(ui::Point(0, 0), ui::Point(Size.X-((XRES/2) + 10), -1), comments[i].comment);
tempComment->SetMultiline(true);
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
tempComment->SetTextColour(ui::Colour(180, 180, 180)); tempComment->SetTextColour(ui::Colour(180, 180, 180));