gcc warning fixes (up to lua files)

This commit is contained in:
jacob1 2015-01-16 17:26:04 -05:00
parent 7676f739a0
commit 54d985f975
23 changed files with 293 additions and 272 deletions

View File

@ -66,7 +66,7 @@
return name; return name;
}*/ }*/
int update_start(char *data, int len) int update_start(char *data, unsigned int len)
{ {
char *self=exe_name(), *temp; char *self=exe_name(), *temp;
#ifdef WIN #ifdef WIN

View File

@ -2,7 +2,7 @@
#define UPDATE_H_ #define UPDATE_H_
//char *exe_name(void); //char *exe_name(void);
int update_start(char *data, int len); int update_start(char *data, unsigned int len);
int update_finish(void); int update_finish(void);
void update_cleanup(void); void update_cleanup(void);

View File

@ -345,7 +345,7 @@ bool Client::DoInstallation()
#include "icondoc.h" #include "icondoc.h"
std::string filename = exe_name(), pathname = filename.substr(0, filename.rfind('/')); std::string filename = exe_name(), pathname = filename.substr(0, filename.rfind('/'));
for (int i = 0; i < filename.size(); i++) for (size_t i = 0; i < filename.size(); i++)
{ {
if (filename[i] == '\'') if (filename[i] == '\'')
{ {
@ -489,7 +489,7 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str
#endif #endif
return std::vector<std::string>(); return std::vector<std::string>();
} }
while(directoryEntry = readdir(directoryHandle)) while ((directoryEntry = readdir(directoryHandle)))
{ {
std::string currentFileName = std::string(directoryEntry->d_name); std::string currentFileName = std::string(directoryEntry->d_name);
if(currentFileName.length()>4) if(currentFileName.length()>4)
@ -505,7 +505,7 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str
bool extensionMatch = !extensions.size(); bool extensionMatch = !extensions.size();
for(std::vector<std::string>::iterator extIter = extensions.begin(), extEnd = extensions.end(); extIter != extEnd; ++extIter) for(std::vector<std::string>::iterator extIter = extensions.begin(), extEnd = extensions.end(); extIter != extEnd; ++extIter)
{ {
int filenameLength = filename.length()-(*extIter).length(); size_t filenameLength = filename.length()-(*extIter).length();
if(filename.find(*extIter, filenameLength) == filenameLength) if(filename.find(*extIter, filenameLength) == filenameLength)
{ {
extensionMatch = true; extensionMatch = true;
@ -694,7 +694,7 @@ void Client::Tick()
//Notifications from server //Notifications from server
json::Array notificationsArray = objDocument["Notifications"]; json::Array notificationsArray = objDocument["Notifications"];
for(int j = 0; j < notificationsArray.Size(); j++) for(size_t j = 0; j < notificationsArray.Size(); j++)
{ {
json::String notificationLink = notificationsArray[j]["Link"]; json::String notificationLink = notificationsArray[j]["Link"];
json::String notificationText = notificationsArray[j]["Text"]; json::String notificationText = notificationsArray[j]["Text"];
@ -891,7 +891,7 @@ User Client::GetAuthUser()
RequestStatus Client::UploadSave(SaveInfo & save) RequestStatus Client::UploadSave(SaveInfo & save)
{ {
lastError = ""; lastError = "";
int gameDataLength; unsigned int gameDataLength;
char * gameData = NULL; char * gameData = NULL;
int dataStatus; int dataStatus;
char * data; char * data;
@ -926,7 +926,7 @@ RequestStatus Client::UploadSave(SaveInfo & save)
const char *const postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL }; const char *const postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL };
const char *const postDatas[] = { saveName, saveDescription, gameData, (char *)(save.GetPublished()?"Public":"Private") }; const char *const postDatas[] = { saveName, saveDescription, gameData, (char *)(save.GetPublished()?"Public":"Private") };
int postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, save.GetPublished()?6:7 }; size_t postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, (size_t)(save.GetPublished()?6:7) };
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl; //std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength); data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength);
@ -1049,7 +1049,7 @@ std::string Client::AddStamp(GameSave * saveData)
MakeDirectory(STAMPS_DIR); MakeDirectory(STAMPS_DIR);
int gameDataLength; unsigned int gameDataLength;
char * gameData = saveData->Serialise(gameDataLength); char * gameData = saveData->Serialise(gameDataLength);
std::ofstream stampStream; std::ofstream stampStream;
@ -1089,7 +1089,7 @@ void Client::RescanStamps()
if (directory != NULL) if (directory != NULL)
{ {
stampIDs.clear(); stampIDs.clear();
while (entry = readdir(directory)) while ((entry = readdir(directory)))
{ {
if(strncmp(entry->d_name, "..", 3) && strncmp(entry->d_name, ".", 2) && strstr(entry->d_name, ".stm") && strlen(entry->d_name) == 14) if(strncmp(entry->d_name, "..", 3) && strncmp(entry->d_name, ".", 2) && strstr(entry->d_name, ".stm") && strlen(entry->d_name) == 14)
{ {
@ -1110,15 +1110,18 @@ int Client::GetStampsCount()
std::vector<std::string> Client::GetStamps(int start, int count) std::vector<std::string> Client::GetStamps(int start, int count)
{ {
if(start+count > stampIDs.size()) { int size = (int)stampIDs.size();
if(start > stampIDs.size()) if (start+count > size)
{
if(start > size)
return std::vector<std::string>(); return std::vector<std::string>();
count = stampIDs.size()-start; count = size-start;
} }
std::vector<std::string> stampRange; std::vector<std::string> stampRange;
int index = 0; int index = 0;
for (std::list<std::string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator, ++index) { for (std::list<std::string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator, ++index)
{
if(index>=start && index < start+count) if(index>=start && index < start+count)
stampRange.push_back(*iterator); stampRange.push_back(*iterator);
} }
@ -1149,7 +1152,7 @@ RequestStatus Client::ExecVote(int saveID, int direction)
const char *const postNames[] = { "ID", "Action", NULL }; const char *const postNames[] = { "ID", "Action", NULL };
const char *const postDatas[] = { id, directionText }; const char *const postDatas[] = { id, directionText };
int postLengths[] = { saveIDText.length(), strlen(directionText) }; size_t postLengths[] = { saveIDText.length(), strlen(directionText) };
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl; //std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength); data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, userid, NULL, session, &dataStatus, &dataLength);
@ -1330,7 +1333,7 @@ LoginStatus Client::Login(std::string username, std::string password, User & use
int dataStatus, dataLength; int dataStatus, dataLength;
const char *const postNames[] = { "Username", "Hash", NULL }; const char *const postNames[] = { "Username", "Hash", NULL };
const char *const postDatas[] = { (char*)username.c_str(), totalHash }; const char *const postDatas[] = { (char*)username.c_str(), totalHash };
int postLengths[] = { username.length(), 32 }; size_t postLengths[] = { username.length(), 32 };
data = http_multipart_post("http://" SERVER "/Login.json", postNames, postDatas, postLengths, NULL, NULL, NULL, &dataStatus, &dataLength); data = http_multipart_post("http://" SERVER "/Login.json", postNames, postDatas, postLengths, NULL, NULL, NULL, &dataStatus, &dataLength);
if(dataStatus == 200 && data) if(dataStatus == 200 && data)
{ {
@ -1350,7 +1353,7 @@ LoginStatus Client::Login(std::string username, std::string password, User & use
json::String userElevationTemp = objDocument["Elevation"]; json::String userElevationTemp = objDocument["Elevation"];
json::Array notificationsArray = objDocument["Notifications"]; json::Array notificationsArray = objDocument["Notifications"];
for(int j = 0; j < notificationsArray.Size(); j++) for (size_t j = 0; j < notificationsArray.Size(); j++)
{ {
json::String notificationLink = notificationsArray[j]["Link"]; json::String notificationLink = notificationsArray[j]["Link"];
json::String notificationText = notificationsArray[j]["Text"]; json::String notificationText = notificationsArray[j]["Text"];
@ -1459,7 +1462,7 @@ RequestStatus Client::AddComment(int saveID, std::string comment)
const char *const postNames[] = { "Comment", NULL }; const char *const postNames[] = { "Comment", NULL };
const char *const postDatas[] = { (char*)(comment.c_str()) }; const char *const postDatas[] = { (char*)(comment.c_str()) };
int postLengths[] = { comment.length() }; size_t postLengths[] = { comment.length() };
data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
} }
else else
@ -1575,7 +1578,7 @@ RequestStatus Client::ReportSave(int saveID, std::string message)
const char *const postNames[] = { "Reason", NULL }; const char *const postNames[] = { "Reason", NULL };
const char *const postDatas[] = { (char*)(message.c_str()) }; const char *const postDatas[] = { (char*)(message.c_str()) };
int postLengths[] = { message.length() }; size_t postLengths[] = { message.length() };
data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
} }
else else
@ -1685,7 +1688,7 @@ RequestStatus Client::PublishSave(int saveID)
userIDStream << authUser.ID; userIDStream << authUser.ID;
const char *const postNames[] = { "ActionPublish", NULL }; const char *const postNames[] = { "ActionPublish", NULL };
const char *const postDatas[] = { "" }; const char *const postDatas[] = { "" };
int postLengths[] = { 1 }; size_t postLengths[] = { 1 };
char *data = http_multipart_post(urlStream.str().c_str(), postNames, postDatas, postLengths, userIDStream.str().c_str(), NULL, authUser.SessionID.c_str(), &dataStatus, NULL); char *data = http_multipart_post(urlStream.str().c_str(), postNames, postDatas, postLengths, userIDStream.str().c_str(), NULL, authUser.SessionID.c_str(), &dataStatus, NULL);
if (data) if (data)
free(data); free(data);
@ -1750,7 +1753,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
json::Array tagsArray = objDocument["Tags"]; json::Array tagsArray = objDocument["Tags"];
std::list<std::string> tempTags; std::list<std::string> tempTags;
for(int j = 0; j < tagsArray.Size(); j++) for (size_t j = 0; j < tagsArray.Size(); j++)
{ {
json::String tempTag = tagsArray[j]; json::String tempTag = tagsArray[j];
tempTags.push_back(tempTag.Value()); tempTags.push_back(tempTag.Value());
@ -1826,7 +1829,7 @@ RequestBroker::Request * Client::GetSaveAsync(int saveID, int saveDate)
json::Array tagsArray = objDocument["Tags"]; json::Array tagsArray = objDocument["Tags"];
std::list<std::string> tempTags; std::list<std::string> tempTags;
for(int j = 0; j < tagsArray.Size(); j++) for (size_t j = 0; j < tagsArray.Size(); j++)
{ {
json::String tempTag = tagsArray[j]; json::String tempTag = tagsArray[j];
tempTags.push_back(tempTag.Value()); tempTags.push_back(tempTag.Value());
@ -1919,7 +1922,7 @@ RequestBroker::Request * Client::GetCommentsAsync(int saveID, int start, int cou
json::Array commentsArray; json::Array commentsArray;
json::Reader::Read(commentsArray, dataStream); json::Reader::Read(commentsArray, dataStream);
for(int j = 0; j < commentsArray.Size(); j++) for (size_t j = 0; j < commentsArray.Size(); j++)
{ {
json::Number tempUserID = commentsArray[j]["UserID"]; json::Number tempUserID = commentsArray[j]["UserID"];
json::String tempUsername = commentsArray[j]["Username"]; json::String tempUsername = commentsArray[j]["Username"];
@ -1972,7 +1975,7 @@ std::vector<SaveComment*> * Client::GetComments(int saveID, int start, int count
json::Array commentsArray; json::Array commentsArray;
json::Reader::Read(commentsArray, dataStream); json::Reader::Read(commentsArray, dataStream);
for(int j = 0; j < commentsArray.Size(); j++) for (size_t j = 0; j < commentsArray.Size(); j++)
{ {
json::Number tempUserID = commentsArray[j]["UserID"]; json::Number tempUserID = commentsArray[j]["UserID"];
json::String tempUsername = commentsArray[j]["Username"]; json::String tempUsername = commentsArray[j]["Username"];
@ -2030,7 +2033,7 @@ std::vector<std::pair<std::string, int> > * Client::GetTags(int start, int count
json::Number tempCount = objDocument["TagTotal"]; json::Number tempCount = objDocument["TagTotal"];
resultCount = tempCount.Value(); resultCount = tempCount.Value();
json::Array tagsArray = objDocument["Tags"]; json::Array tagsArray = objDocument["Tags"];
for(int j = 0; j < tagsArray.Size(); j++) for (size_t j = 0; j < tagsArray.Size(); j++)
{ {
json::Number tagCount = tagsArray[j]["Count"]; json::Number tagCount = tagsArray[j]["Count"];
json::String tag = tagsArray[j]["Tag"]; json::String tag = tagsArray[j]["Tag"];
@ -2097,7 +2100,7 @@ std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, std::string q
json::Number tempCount = objDocument["Count"]; json::Number tempCount = objDocument["Count"];
resultCount = tempCount.Value(); resultCount = tempCount.Value();
json::Array savesArray = objDocument["Saves"]; json::Array savesArray = objDocument["Saves"];
for(int j = 0; j < savesArray.Size(); j++) for (size_t j = 0; j < savesArray.Size(); j++)
{ {
json::Number tempID = savesArray[j]["ID"]; json::Number tempID = savesArray[j]["ID"];
json::Number tempDate = savesArray[j]["Date"]; json::Number tempDate = savesArray[j]["Date"];
@ -2302,7 +2305,7 @@ std::list<std::string> * Client::RemoveTag(int saveID, std::string tag)
tags = new std::list<std::string>(); tags = new std::list<std::string>();
for(int j = 0; j < tagsArray.Size(); j++) for (size_t j = 0; j < tagsArray.Size(); j++)
{ {
json::String tempTag = tagsArray[j]; json::String tempTag = tagsArray[j];
tags->push_back(tempTag.Value()); tags->push_back(tempTag.Value());
@ -2363,7 +2366,7 @@ std::list<std::string> * Client::AddTag(int saveID, std::string tag)
tags = new std::list<std::string>(); tags = new std::list<std::string>();
for(int j = 0; j < tagsArray.Size(); j++) for (size_t j = 0; j < tagsArray.Size(); j++)
{ {
json::String tempTag = tagsArray[j]; json::String tempTag = tagsArray[j];
tags->push_back(tempTag.Value()); tags->push_back(tempTag.Value());

View File

@ -60,7 +60,7 @@ private:
std::string lastError; std::string lastError;
std::list<std::string> stampIDs; std::list<std::string> stampIDs;
int lastStampTime; unsigned lastStampTime;
int lastStampName; int lastStampName;
//Auth session //Auth session

View File

@ -18,16 +18,16 @@ GameSave::GameSave(GameSave & save) :
waterEEnabled(save.waterEEnabled), waterEEnabled(save.waterEEnabled),
legacyEnable(save.legacyEnable), legacyEnable(save.legacyEnable),
gravityEnable(save.gravityEnable), gravityEnable(save.gravityEnable),
aheatEnable(save.aheatEnable),
paused(save.paused), paused(save.paused),
gravityMode(save.gravityMode), gravityMode(save.gravityMode),
aheatEnable(save.aheatEnable),
airMode(save.airMode), airMode(save.airMode),
edgeMode(save.edgeMode), edgeMode(save.edgeMode),
signs(save.signs), signs(save.signs),
palette(save.palette),
expanded(save.expanded), expanded(save.expanded),
hasOriginalData(save.hasOriginalData), hasOriginalData(save.hasOriginalData),
originalData(save.originalData), originalData(save.originalData)
palette(save.palette)
{ {
blockMap = NULL; blockMap = NULL;
blockMapPtr = NULL; blockMapPtr = NULL;
@ -288,14 +288,14 @@ void GameSave::setSize(int newWidth, int newHeight)
std::vector<char> GameSave::Serialise() std::vector<char> GameSave::Serialise()
{ {
int dataSize; unsigned int dataSize;
char * data = Serialise(dataSize); char * data = Serialise(dataSize);
std::vector<char> dataVect(data, data+dataSize); std::vector<char> dataVect(data, data+dataSize);
delete[] data; delete[] data;
return dataVect; return dataVect;
} }
char * GameSave::Serialise(int & dataSize) char * GameSave::Serialise(unsigned int & dataSize)
{ {
return serialiseOPS(dataSize); return serialiseOPS(dataSize);
} }
@ -304,7 +304,7 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
{ {
if(Collapsed()) if(Collapsed())
Expand(); Expand();
int i, x, y, nx, ny, width = blockWidth*CELL, height = blockHeight*CELL, newWidth, newHeight, newBlockWidth, newBlockHeight; int x, y, nx, ny, width = blockWidth*CELL, height = blockHeight*CELL, newWidth, newHeight, newBlockWidth, newBlockHeight;
vector2d pos, tmp, ctl, cbr, vel; vector2d pos, tmp, ctl, cbr, vel;
vector2d cornerso[4]; vector2d cornerso[4];
// undo any translation caused by rotation // undo any translation caused by rotation
@ -312,7 +312,7 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
cornerso[1] = v2d_new(width-1,0); cornerso[1] = v2d_new(width-1,0);
cornerso[2] = v2d_new(0,height-1); cornerso[2] = v2d_new(0,height-1);
cornerso[3] = v2d_new(width-1,height-1); cornerso[3] = v2d_new(width-1,height-1);
for (i=0; i<4; i++) for (int i = 0; i < 4; i++)
{ {
tmp = m2d_multiply_v2d(transform,cornerso[i]); tmp = m2d_multiply_v2d(transform,cornerso[i]);
if (i==0) ctl = cbr = tmp; // top left, bottom right corner if (i==0) ctl = cbr = tmp; // top left, bottom right corner
@ -357,7 +357,7 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
fanVelYNew[y] = &fanVelYPtrNew[y*newBlockWidth]; fanVelYNew[y] = &fanVelYPtrNew[y*newBlockWidth];
// rotate and translate signs, parts, walls // rotate and translate signs, parts, walls
for (i=0; i < signs.size(); i++) for (size_t i = 0; i < signs.size(); i++)
{ {
pos = v2d_new(signs[i].x, signs[i].y); pos = v2d_new(signs[i].x, signs[i].y);
pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);
@ -371,7 +371,7 @@ void GameSave::Transform(matrix2d transform, vector2d translate)
signs[i].x = nx; signs[i].x = nx;
signs[i].y = ny; signs[i].y = ny;
} }
for (i=0; i<particlesCount; i++) for (int i = 0; i < particlesCount; i++)
{ {
if (!particles[i].type) continue; if (!particles[i].type) continue;
pos = v2d_new(particles[i].x, particles[i].y); pos = v2d_new(particles[i].x, particles[i].y);
@ -437,9 +437,8 @@ void GameSave::readOPS(char * data, int dataLength)
unsigned char * inputData = (unsigned char*)data, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL; unsigned char * inputData = (unsigned char*)data, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL;
unsigned int inputDataLen = dataLength, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, soapLinkDataLen; unsigned int inputDataLen = dataLength, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, soapLinkDataLen;
unsigned partsCount = 0, *partsSimIndex = NULL; unsigned partsCount = 0, *partsSimIndex = NULL;
int i, x, y, j;
int *freeIndices = NULL; int *freeIndices = NULL;
int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; unsigned int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH;
int savedVersion = inputData[4]; int savedVersion = inputData[4];
bson b; bson b;
bson_iterator iter; bson_iterator iter;
@ -717,15 +716,15 @@ void GameSave::readOPS(char * data, int dataLength)
//Read wall and fan data //Read wall and fan data
if(wallData) if(wallData)
{ {
j = 0; unsigned int j = 0;
if(blockW * blockH > wallDataLen) if (blockW * blockH > wallDataLen)
{ {
fprintf(stderr, "Not enough wall data\n"); fprintf(stderr, "Not enough wall data\n");
goto fail; goto fail;
} }
for(x = 0; x < blockW; x++) for (unsigned int x = 0; x < blockW; x++)
{ {
for(y = 0; y < blockH; y++) for (unsigned int y = 0; y < blockH; y++)
{ {
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];
@ -780,12 +779,11 @@ void GameSave::readOPS(char * data, int dataLength)
} }
//Read particle data //Read particle data
if(partsData && partsPosData) if (partsData && partsPosData)
{ {
int newIndex = 0, fieldDescriptor, tempTemp; int newIndex = 0, fieldDescriptor, tempTemp;
int posCount, posTotal, partsPosDataIndex = 0; int posCount, posTotal, partsPosDataIndex = 0;
int saved_x, saved_y; if (fullW * fullH * 3 > partsPosDataLen)
if(fullW * fullH * 3 > partsPosDataLen)
{ {
fprintf(stderr, "Not enough particle position data\n"); fprintf(stderr, "Not enough particle position data\n");
goto fail; goto fail;
@ -794,11 +792,12 @@ void GameSave::readOPS(char * data, int dataLength)
partsSimIndex = (unsigned int*)calloc(NPART, sizeof(unsigned)); partsSimIndex = (unsigned int*)calloc(NPART, sizeof(unsigned));
partsCount = 0; partsCount = 0;
i = 0; unsigned int i = 0;
unsigned int saved_x, saved_y, x, y;
newIndex = 0; newIndex = 0;
for (saved_y=0; saved_y<fullH; saved_y++) for (saved_y = 0; saved_y < fullH; saved_y++)
{ {
for (saved_x=0; saved_x<fullW; saved_x++) for (saved_x = 0; saved_x < fullW; saved_x++)
{ {
//Read total number of particles at this position //Read total number of particles at this position
posTotal = 0; posTotal = 0;
@ -806,10 +805,10 @@ void GameSave::readOPS(char * data, int dataLength)
posTotal |= partsPosData[partsPosDataIndex++]<<8; posTotal |= partsPosData[partsPosDataIndex++]<<8;
posTotal |= partsPosData[partsPosDataIndex++]; posTotal |= partsPosData[partsPosDataIndex++];
//Put the next posTotal particles at this position //Put the next posTotal particles at this position
for (posCount=0; posCount<posTotal; posCount++) for (posCount = 0; posCount < posTotal; posCount++)
{ {
particlesCount = newIndex+1; particlesCount = newIndex+1;
if(newIndex>=NPART) if (newIndex >= NPART)
{ {
goto fail; goto fail;
} }
@ -821,15 +820,15 @@ void GameSave::readOPS(char * data, int dataLength)
y = saved_y + fullY; y = saved_y + fullY;
fieldDescriptor = partsData[i+1]; fieldDescriptor = partsData[i+1];
fieldDescriptor |= partsData[i+2] << 8; fieldDescriptor |= partsData[i+2] << 8;
if(x >= fullW || x < 0 || y >= fullH || y < 0) if (x >= fullW || y >= fullH)
{ {
fprintf(stderr, "Out of range [%d]: %d %d, [%d, %d], [%d, %d]\n", i, x, y, (unsigned)partsData[i+1], (unsigned)partsData[i+2], (unsigned)partsData[i+3], (unsigned)partsData[i+4]); fprintf(stderr, "Out of range [%d]: %d %d, [%d, %d], [%d, %d]\n", i, x, y, (unsigned)partsData[i+1], (unsigned)partsData[i+2], (unsigned)partsData[i+3], (unsigned)partsData[i+4]);
goto fail; goto fail;
} }
if(partsData[i] >= PT_NUM) if (partsData[i] >= PT_NUM)
partsData[i] = PT_DMND; //Replace all invalid elements with diamond partsData[i] = PT_DMND; //Replace all invalid elements with diamond
if(newIndex < 0 || newIndex >= NPART) if (newIndex < 0 || newIndex >= NPART)
goto fail; goto fail;
//Store partsptr index+1 for this saved particle index (0 means not loaded) //Store partsptr index+1 for this saved particle index (0 means not loaded)
@ -1038,13 +1037,13 @@ void GameSave::readOPS(char * data, int dataLength)
} }
if (soapLinkData) if (soapLinkData)
{ {
int soapLinkDataPos = 0; unsigned int soapLinkDataPos = 0;
for (i=0; i<partsCount; i++) for (unsigned int i = 0; i < partsCount; i++)
{ {
if (partsSimIndex[i] && particles[partsSimIndex[i]-1].type == PT_SOAP) if (partsSimIndex[i] && particles[partsSimIndex[i]-1].type == PT_SOAP)
{ {
// Get the index of the particle forward linked from this one, if present in the save data // Get the index of the particle forward linked from this one, if present in the save data
int linkedIndex = 0; unsigned int linkedIndex = 0;
if (soapLinkDataPos+3 > soapLinkDataLen) break; if (soapLinkDataPos+3 > soapLinkDataLen) break;
linkedIndex |= soapLinkData[soapLinkDataPos++]<<16; linkedIndex |= soapLinkData[soapLinkDataPos++]<<16;
linkedIndex |= soapLinkData[soapLinkDataPos++]<<8; linkedIndex |= soapLinkData[soapLinkDataPos++]<<8;
@ -1067,7 +1066,7 @@ void GameSave::readOPS(char * data, int dataLength)
if(tempSigns.size()) if(tempSigns.size())
{ {
for (int i = 0; i < tempSigns.size(); i++) for (size_t i = 0; i < tempSigns.size(); i++)
{ {
if(signs.size() == MAXSIGNS) if(signs.size() == MAXSIGNS)
break; break;
@ -1189,7 +1188,7 @@ void GameSave::readPSv(char * data, int dataLength)
setSize(bw, bh); setSize(bw, bh);
int bzStatus = 0; int bzStatus = 0;
if (bzStatus = BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), dataLength-12, 0, 0)) if ((bzStatus = BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), dataLength-12, 0, 0)))
{ {
std::stringstream bzStatusStr; std::stringstream bzStatusStr;
bzStatusStr << bzStatus; bzStatusStr << bzStatus;
@ -1717,7 +1716,7 @@ void GameSave::readPSv(char * data, int dataLength)
p += x; p += x;
} }
for (i = 0; i < tempSigns.size(); i++) for (size_t i = 0; i < tempSigns.size(); i++)
{ {
if(signs.size() == MAXSIGNS) if(signs.size() == MAXSIGNS)
break; break;
@ -1763,7 +1762,7 @@ void GameSave::readPSv(char * data, int dataLength)
} }
} }
char * GameSave::serialiseOPS(int & dataLength) char * GameSave::serialiseOPS(unsigned int & dataLength)
{ {
//Particle *particles = sim->parts; //Particle *particles = sim->parts;
unsigned char *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *finalData = NULL, *outputData = NULL, *soapLinkData = NULL; unsigned char *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *finalData = NULL, *outputData = NULL, *soapLinkData = NULL;
@ -2131,17 +2130,17 @@ char * GameSave::serialiseOPS(int & dataLength)
bson_append_finish_array(&b); bson_append_finish_array(&b);
} }
signsCount = 0; signsCount = 0;
for(i = 0; i < signs.size(); i++) for (size_t i = 0; i < signs.size(); i++)
{ {
if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH) if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH)
{ {
signsCount++; signsCount++;
} }
} }
if(signsCount) if (signsCount)
{ {
bson_append_start_array(&b, "signs"); bson_append_start_array(&b, "signs");
for(i = 0; i < signs.size(); i++) for (size_t i = 0; i < signs.size(); i++)
{ {
if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH) if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH)
{ {

View File

@ -63,7 +63,7 @@ public:
GameSave(std::vector<unsigned char> data); GameSave(std::vector<unsigned char> data);
~GameSave(); ~GameSave();
void setSize(int width, int height); void setSize(int width, int height);
char * Serialise(int & dataSize); char * Serialise(unsigned int & dataSize);
std::vector<char> Serialise(); std::vector<char> Serialise();
void Transform(matrix2d transform, vector2d translate); void Transform(matrix2d transform, vector2d translate);
@ -100,7 +100,7 @@ private:
void read(char * data, int dataSize); void read(char * data, int dataSize);
void readOPS(char * data, int dataLength); void readOPS(char * data, int dataLength);
void readPSv(char * data, int dataLength); void readPSv(char * data, int dataLength);
char * serialiseOPS(int & dataSize); char * serialiseOPS(unsigned int & dataSize);
//serialisePSv(); //serialisePSv();
}; };

View File

@ -906,7 +906,7 @@ const char *http_ret_text(int ret)
return "Unknown Status Code"; return "Unknown Status Code";
} }
} }
char *http_multipart_post(const char *uri, const char *const *names, const char *const *parts, int *plens, const char *user, const char *pass, const char *session_id, int *ret, int *len) char *http_multipart_post(const char *uri, const char *const *names, const char *const *parts, size_t *plens, const char *user, const char *pass, const char *session_id, int *ret, int *len)
{ {
void *ctx; void *ctx;
char *data = NULL, *tmp; char *data = NULL, *tmp;
@ -925,7 +925,7 @@ char *http_multipart_post(const char *uri, const char *const *names, const char
{ {
own_plen = 1; own_plen = 1;
for (i=0; names[i]; i++) ; for (i=0; names[i]; i++) ;
plens = (int *)calloc(i, sizeof(int)); plens = (size_t *)calloc(i, sizeof(size_t));
for (i=0; names[i]; i++) for (i=0; names[i]; i++)
plens[i] = strlen(parts[i]); plens[i] = strlen(parts[i]);
} }
@ -936,7 +936,7 @@ retry:
memset(map, 0, 62*sizeof(int)); memset(map, 0, 62*sizeof(int));
for (i=0; names[i]; i++) for (i=0; names[i]; i++)
{ {
for (j=0; j<plens[i]-blen; j++) for (unsigned int j=0; j<plens[i]-blen; j++)
if (!blen || !memcmp(parts[i]+j, boundary, blen)) if (!blen || !memcmp(parts[i]+j, boundary, blen))
{ {
ch = parts[i][j+blen]; ch = parts[i][j+blen];

View File

@ -38,7 +38,7 @@ void http_async_get_length(void *ctx, int *total, int *done);
char *http_async_req_stop(void *ctx, int *ret, int *len); char *http_async_req_stop(void *ctx, int *ret, int *len);
void http_async_req_close(void *ctx); void http_async_req_close(void *ctx);
char *http_multipart_post(const char *uri, const char *const *names, const char *const *parts, int *plens, const char *user, const char *pass, const char * session_id, int *ret, int *len); char *http_multipart_post(const char *uri, const char *const *names, const char *const *parts, size_t *plens, const char *user, const char *pass, const char * session_id, int *ret, int *len);
void *http_multipart_post_async(const char *uri, const char *const *names, const char *const *parts, int *plens, const char *user, const char *pass, const char *session_id); void *http_multipart_post_async(const char *uri, const char *const *names, const char *const *parts, int *plens, const char *user, const char *pass, const char *session_id);
const char *http_ret_text(int ret); const char *http_ret_text(int ret);

View File

@ -109,7 +109,7 @@ void md5_final(unsigned char digest[16], struct md5_context *ctx)
putu32(ctx->buf[1], digest + 4); putu32(ctx->buf[1], digest + 4);
putu32(ctx->buf[2], digest + 8); putu32(ctx->buf[2], digest + 8);
putu32(ctx->buf[3], digest + 12); putu32(ctx->buf[3], digest + 12);
memset(ctx, 0, sizeof(ctx)); memset(&ctx, 0, sizeof(ctx));
} }
#define F1(x, y, z) (z ^ (x & (y ^ z))) #define F1(x, y, z) (z ^ (x & (y ^ z)))

View File

@ -4,8 +4,8 @@
#include "gui/search/Thumbnail.h" #include "gui/search/Thumbnail.h"
SaveFile::SaveFile(SaveFile & save): SaveFile::SaveFile(SaveFile & save):
gameSave(NULL),
thumbnail(NULL), thumbnail(NULL),
gameSave(NULL),
filename(save.filename), filename(save.filename),
displayName(save.displayName) displayName(save.displayName)
{ {
@ -26,10 +26,10 @@ void SaveFile::SetThumbnail(Thumbnail * thumb)
} }
SaveFile::SaveFile(std::string filename): SaveFile::SaveFile(std::string filename):
filename(filename), thumbnail(NULL),
displayName(filename),
gameSave(NULL), gameSave(NULL),
thumbnail(NULL) filename(filename),
displayName(filename)
{ {
} }

View File

@ -3,60 +3,64 @@
#include "Client.h" #include "Client.h"
SaveInfo::SaveInfo(SaveInfo & save): SaveInfo::SaveInfo(SaveInfo & save):
id(save.id),
date(save.date),
votesUp(save.votesUp),
votesDown(save.votesDown),
vote(save.vote),
Favourite(false),
Comments(save.Comments),
Views(save.Views),
Version(save.Version),
userName(save.userName), userName(save.userName),
name(save.name), name(save.name),
Description(save.Description), Description(save.Description),
date(save.date),
Published(save.Published), Published(save.Published),
id(save.id), gameSave(NULL)
votesUp(save.votesUp),
votesDown(save.votesDown),
gameSave(NULL),
vote(save.vote),
Comments(save.Comments),
Views(save.Views),
Version(save.Version)
{ {
std::list<std::string> tagsSorted = save.tags; std::list<std::string> tagsSorted = save.tags;
tagsSorted.sort(); tagsSorted.sort();
tags=tagsSorted; tags = tagsSorted;
if(save.gameSave) if (save.gameSave)
gameSave = new GameSave(*save.gameSave); gameSave = new GameSave(*save.gameSave);
} }
SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string _userName, std::string _name): SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string _userName, std::string _name):
id(_id), id(_id),
date(_date),
votesUp(_votesUp), votesUp(_votesUp),
votesDown(_votesDown), votesDown(_votesDown),
vote(0),
Favourite(false),
Comments(0),
Views(0),
Version(0),
userName(_userName), userName(_userName),
name(_name), name(_name),
Description(""), Description(""),
date(_date),
Published(false), Published(false),
gameSave(NULL),
vote(0),
tags(), tags(),
Comments(0), gameSave(NULL)
Views(0),
Version(0)
{ {
} }
SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags_): SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags_):
id(_id), id(_id),
date(date_),
votesUp(_votesUp), votesUp(_votesUp),
votesDown(_votesDown), votesDown(_votesDown),
vote(_vote),
Favourite(false),
Comments(0),
Views(0),
Version(0),
userName(_userName), userName(_userName),
name(_name), name(_name),
Description(description_), Description(description_),
date(date_),
Published(published_), Published(published_),
gameSave(NULL), tags(),
vote(_vote), gameSave(NULL)
Comments(0),
Views(0),
Version(0)
{ {
std::list<std::string> tagsSorted = tags_; std::list<std::string> tagsSorted = tags_;
tagsSorted.sort(); tagsSorted.sort();

View File

@ -16,11 +16,19 @@ public:
int id; int id;
int date; int date;
int votesUp, votesDown; int votesUp, votesDown;
int vote;
bool Favourite; bool Favourite;
int Comments; int Comments;
int Views; int Views;
int Version; int Version;
std::string userName;
std::string name;
std::string Description;
bool Published;
std::list<std::string> tags;
GameSave * gameSave; GameSave * gameSave;
SaveInfo(SaveInfo & save); SaveInfo(SaveInfo & save);
@ -31,17 +39,6 @@ public:
~SaveInfo(); ~SaveInfo();
std::string userName;
std::string name;
std::string Description;
std::list<std::string> tags;
int vote;
bool Published;
void SetName(std::string name); void SetName(std::string name);
std::string GetName(); std::string GetName();

View File

@ -35,6 +35,7 @@
#define PIXG(x) (((x)>>16)&0xFF) #define PIXG(x) (((x)>>16)&0xFF)
#define PIXB(x) (((x)>>24)&0xFF) #define PIXB(x) (((x)>>24)&0xFF)
#elif defined(PIX32OGL) #elif defined(PIX32OGL)
#undef PIXELCHANNELS
#define PIXELCHANNELS 4 #define PIXELCHANNELS 4
#define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) //32bit ARGB in 32bit int: AARRGGBB #define PIXPACK(x) (0xFF000000|((x)&0xFFFFFF)) //32bit ARGB in 32bit int: AARRGGBB
#define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b))) #define PIXRGB(r,g,b) (0xFF000000|((r)<<16)|((g)<<8)|((b)))

View File

@ -135,9 +135,8 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int
int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a) int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a)
{ {
int i, j, w, bn = 0, ba = 0;
unsigned char *rp = font_data + font_ptrs[c]; unsigned char *rp = font_data + font_ptrs[c];
w = *(rp++); int w = *(rp++);
VideoBuffer texture(w, 12); VideoBuffer texture(w, 12);
texture.SetCharacter(0, 0, c, r, g, b, a); texture.SetCharacter(0, 0, c, r, g, b, a);
@ -165,9 +164,8 @@ int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a
int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a) int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a)
{ {
int i, j, w, bn = 0, ba = 0;
unsigned char *rp = font_data + font_ptrs[c]; unsigned char *rp = font_data + font_ptrs[c];
w = *(rp++); int w = *(rp++);
VideoBuffer texture(w, 12); VideoBuffer texture(w, 12);
texture.AddCharacter(0, 0, c, r, g, b, a); texture.AddCharacter(0, 0, c, r, g, b, a);

View File

@ -912,7 +912,7 @@ void Renderer::DrawWalls()
void Renderer::DrawSigns() void Renderer::DrawSigns()
{ {
int i, j, x, y, w, h, dx, dy; int x, y, w, h;
std::vector<sign> signs = sim->signs; std::vector<sign> signs = sim->signs;
#ifdef OGLR #ifdef OGLR
GLint prevFbo; GLint prevFbo;
@ -920,7 +920,7 @@ void Renderer::DrawSigns()
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
glTranslated(0, MENUSIZE, 0); glTranslated(0, MENUSIZE, 0);
#endif #endif
for (i=0; i < signs.size(); i++) for (size_t i = 0; i < signs.size(); i++)
if (signs[i].text.length()) if (signs[i].text.length())
{ {
char type = 0; char type = 0;
@ -936,10 +936,10 @@ void Renderer::DrawSigns()
else else
drawtext(x+3, y+3, text, 0, 191, 255, 255); drawtext(x+3, y+3, text, 0, 191, 255, 255);
x = signs[i].x; int x = signs[i].x;
y = signs[i].y; int y = signs[i].y;
dx = 1 - signs[i].ju; int dx = 1 - signs[i].ju;
dy = (signs[i].y > 18) ? -1 : 1; int dy = (signs[i].y > 18) ? -1 : 1;
#ifdef OGLR #ifdef OGLR
glBegin(GL_LINES); glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
@ -947,11 +947,11 @@ void Renderer::DrawSigns()
glVertex2i(x+(dx*4), y+(dy*4)); glVertex2i(x+(dx*4), y+(dy*4));
glEnd(); glEnd();
#else #else
for (j=0; j<4; j++) for (int j = 0; j < 4; j++)
{ {
blendpixel(x, y, 192, 192, 192, 255); blendpixel(x, y, 192, 192, 192, 255);
x+=dx; x += dx;
y+=dy; y += dy;
} }
#endif #endif
} }
@ -2424,22 +2424,22 @@ pixel Renderer::GetPixel(int x, int y)
Renderer::Renderer(Graphics * g, Simulation * sim): Renderer::Renderer(Graphics * g, Simulation * sim):
sim(NULL), sim(NULL),
g(NULL), g(NULL),
render_mode(0),
colour_mode(0),
display_mode(0),
gravityZonesEnabled(false),
gravityFieldEnabled(false),
decorations_enable(1),
blackDecorations(false),
debugLines(false),
sampleColor(0xFFFFFFFF),
mousePos(0, 0),
zoomWindowPosition(0, 0), zoomWindowPosition(0, 0),
zoomScopePosition(0, 0), zoomScopePosition(0, 0),
zoomScopeSize(32), zoomScopeSize(32),
ZFACTOR(8),
zoomEnabled(false), zoomEnabled(false),
decorations_enable(1), ZFACTOR(8),
gravityFieldEnabled(false), gridSize(0)
gravityZonesEnabled(false),
mousePos(0, 0),
display_mode(0),
render_mode(0),
colour_mode(0),
gridSize(0),
blackDecorations(false),
debugLines(false),
sampleColor(0xFFFFFFFF)
{ {
this->g = g; this->g = g;
this->sim = sim; this->sim = sim;
@ -2688,7 +2688,7 @@ void Renderer::CompileRenderMode()
{ {
int old_render_mode = render_mode; int old_render_mode = render_mode;
render_mode = 0; render_mode = 0;
for(int i = 0; i < render_modes.size(); i++) for (size_t i = 0; i < render_modes.size(); i++)
render_mode |= render_modes[i]; render_mode |= render_modes[i];
//If firemode is removed, clear the fire display //If firemode is removed, clear the fire display
@ -2710,7 +2710,7 @@ void Renderer::ClearAccumulation()
void Renderer::AddRenderMode(unsigned int mode) void Renderer::AddRenderMode(unsigned int mode)
{ {
for(int i = 0; i < render_modes.size(); i++) for (size_t i = 0; i < render_modes.size(); i++)
{ {
if(render_modes[i] == mode) if(render_modes[i] == mode)
{ {
@ -2723,7 +2723,7 @@ void Renderer::AddRenderMode(unsigned int mode)
void Renderer::RemoveRenderMode(unsigned int mode) void Renderer::RemoveRenderMode(unsigned int mode)
{ {
for(int i = 0; i < render_modes.size(); i++) for (size_t i = 0; i < render_modes.size(); i++)
{ {
if(render_modes[i] == mode) if(render_modes[i] == mode)
{ {
@ -2749,9 +2749,9 @@ void Renderer::CompileDisplayMode()
{ {
int old_display_mode = display_mode; int old_display_mode = display_mode;
display_mode = 0; display_mode = 0;
for(int i = 0; i < display_modes.size(); i++) for (size_t i = 0; i < display_modes.size(); i++)
display_mode |= display_modes[i]; display_mode |= display_modes[i];
if(!(display_mode & DISPLAY_PERS) && (old_display_mode & DISPLAY_PERS)) if (!(display_mode & DISPLAY_PERS) && (old_display_mode & DISPLAY_PERS))
{ {
ClearAccumulation(); ClearAccumulation();
} }
@ -2759,13 +2759,13 @@ void Renderer::CompileDisplayMode()
void Renderer::AddDisplayMode(unsigned int mode) void Renderer::AddDisplayMode(unsigned int mode)
{ {
for(int i = 0; i < display_modes.size(); i++) for (size_t i = 0; i < display_modes.size(); i++)
{ {
if(display_modes[i] == mode) if (display_modes[i] == mode)
{ {
return; return;
} }
if(display_modes[i] & DISPLAY_AIR) if (display_modes[i] & DISPLAY_AIR)
{ {
display_modes.erase(display_modes.begin()+i); display_modes.erase(display_modes.begin()+i);
} }
@ -2776,9 +2776,9 @@ void Renderer::AddDisplayMode(unsigned int mode)
void Renderer::RemoveDisplayMode(unsigned int mode) void Renderer::RemoveDisplayMode(unsigned int mode)
{ {
for(int i = 0; i < display_modes.size(); i++) for (size_t i = 0; i < display_modes.size(); i++)
{ {
if(display_modes[i] == mode) if (display_modes[i] == mode)
{ {
display_modes.erase(display_modes.begin() + i); display_modes.erase(display_modes.begin() + i);
i = 0; i = 0;

View File

@ -41,6 +41,10 @@ typedef struct gcache_item gcache_item;
class Renderer class Renderer
{ {
public: public:
Simulation * sim;
Graphics * g;
gcache_item *graphicscache;
std::vector<unsigned int> render_modes; std::vector<unsigned int> render_modes;
unsigned int render_mode; unsigned int render_mode;
unsigned int colour_mode; unsigned int colour_mode;
@ -60,9 +64,6 @@ public:
int decorations_enable; int decorations_enable;
bool blackDecorations; bool blackDecorations;
bool debugLines; bool debugLines;
Simulation * sim;
Graphics * g;
gcache_item *graphicscache;
pixel sampleColor; pixel sampleColor;
//Mouse position for debug information //Mouse position for debug information

View File

@ -58,7 +58,7 @@ private:
notifyStatus("Unpacking update"); notifyStatus("Unpacking update");
notifyProgress(-1); notifyProgress(-1);
int uncompressedLength; unsigned int uncompressedLength;
if(dataLength<16) if(dataLength<16)
{ {

View File

@ -52,6 +52,8 @@ int luacon_partread(lua_State* l)
tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)); tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset));
lua_pushnumber(l, tempfloat); lua_pushnumber(l, tempfloat);
break; break;
default:
break;
} }
return 1; return 1;
} }
@ -78,6 +80,8 @@ int luacon_partwrite(lua_State* l)
break; break;
case CommandInterface::FormatElement: case CommandInterface::FormatElement:
luacon_sim->part_change_type(i, luacon_sim->parts[i].x, luacon_sim->parts[i].y, luaL_optinteger(l, 3, 0)); luacon_sim->part_change_type(i, luacon_sim->parts[i].x, luacon_sim->parts[i].y, luaL_optinteger(l, 3, 0));
default:
break;
} }
return 0; return 0;
} }
@ -403,9 +407,8 @@ int luacon_elementwrite(lua_State* l)
tempstring = mystrdup((char*)luaL_optstring(l, 3, "")); tempstring = mystrdup((char*)luaL_optstring(l, 3, ""));
if (!strcmp(key, "name")) if (!strcmp(key, "name"))
{ {
int j = 0;
//Convert to upper case //Convert to upper case
for(j = 0; j < strlen(tempstring); j++) for (size_t j = 0; j < strlen(tempstring); j++)
tempstring[j] = toupper(tempstring[j]); tempstring[j] = toupper(tempstring[j]);
if(luacon_ci->GetParticleType(tempstring) != -1) if(luacon_ci->GetParticleType(tempstring) != -1)
{ {
@ -1051,15 +1054,14 @@ int luatpt_reset_spark(lua_State* l)
int luatpt_set_property(lua_State* l) int luatpt_set_property(lua_State* l)
{ {
const char *prop, *name; const char *name;
int r, i, x, y, w, h, t, nx, ny, partsel = 0, acount; int r, i, x, y, w, h, t, nx, ny, partsel = 0;
float f; float f;
size_t offset; int acount = lua_gettop(l);
acount = lua_gettop(l); const char* prop = luaL_optstring(l, 1, "");
prop = luaL_optstring(l, 1, "");
CommandInterface::FormatType format; CommandInterface::FormatType format;
offset = luacon_ci->GetPropertyOffset(prop, format); int offset = luacon_ci->GetPropertyOffset(prop, format);
if (offset == -1) if (offset == -1)
return luaL_error(l, "Invalid property '%s'", prop); return luaL_error(l, "Invalid property '%s'", prop);
@ -1324,6 +1326,9 @@ int luatpt_get_property(lua_State* l)
case CommandInterface::FormatFloat: case CommandInterface::FormatFloat:
tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)); tempfloat = *((float*)(((unsigned char*)&luacon_sim->parts[i])+offset));
lua_pushnumber(l, tempfloat); lua_pushnumber(l, tempfloat);
break;
default:
break;
} }
return 1; return 1;
} }

View File

@ -88,8 +88,6 @@ int TptNewindexClosure(lua_State *l)
LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
CommandInterface(c, m), CommandInterface(c, m),
currentCommand(false),
legacy(new TPTScriptInterface(c, m)),
luacon_mousex(0), luacon_mousex(0),
luacon_mousey(0), luacon_mousey(0),
luacon_mousebutton(0), luacon_mousebutton(0),
@ -99,7 +97,9 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
luacon_selectedr(""), luacon_selectedr(""),
luacon_selectedalt(""), luacon_selectedalt(""),
luacon_selectedreplace(""), luacon_selectedreplace(""),
luacon_mousedown(false) luacon_mousedown(false),
currentCommand(false),
legacy(new TPTScriptInterface(c, m))
{ {
luacon_model = m; luacon_model = m;
luacon_controller = c; luacon_controller = c;
@ -137,7 +137,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
initFileSystemAPI(); initFileSystemAPI();
//Old TPT API //Old TPT API
int i = 0, j;
char tmpname[12]; char tmpname[12];
int currentElementMeta, currentElement; int currentElementMeta, currentElement;
const static struct luaL_Reg tptluaapi [] = { const static struct luaL_Reg tptluaapi [] = {
@ -281,9 +280,9 @@ tpt.partsdata = nil");
lua_newtable(l); lua_newtable(l);
tptElements = lua_gettop(l); tptElements = lua_gettop(l);
for(i = 1; i < PT_NUM; i++) for (int i = 1; i < PT_NUM; i++)
{ {
for(j = 0; j < strlen(luacon_sim->elements[i].Name); j++) for (size_t j = 0; j < strlen(luacon_sim->elements[i].Name); j++)
tmpname[j] = tolower(luacon_sim->elements[i].Name[j]); tmpname[j] = tolower(luacon_sim->elements[i].Name[j]);
tmpname[strlen(luacon_sim->elements[i].Name)] = 0; tmpname[strlen(luacon_sim->elements[i].Name)] = 0;
@ -306,9 +305,9 @@ tpt.partsdata = nil");
lua_newtable(l); lua_newtable(l);
tptElementTransitions = lua_gettop(l); tptElementTransitions = lua_gettop(l);
for(i = 1; i < PT_NUM; i++) for (int i = 1; i < PT_NUM; i++)
{ {
for(j = 0; j < strlen(luacon_sim->elements[i].Name); j++) for (size_t j = 0; j < strlen(luacon_sim->elements[i].Name); j++)
tmpname[j] = tolower(luacon_sim->elements[i].Name[j]); tmpname[j] = tolower(luacon_sim->elements[i].Name[j]);
tmpname[strlen(luacon_sim->elements[i].Name)] = 0; tmpname[strlen(luacon_sim->elements[i].Name)] = 0;
@ -331,7 +330,7 @@ tpt.partsdata = nil");
lua_el_func = (int*)calloc(PT_NUM, sizeof(int)); lua_el_func = (int*)calloc(PT_NUM, sizeof(int));
lua_el_mode = (int*)calloc(PT_NUM, sizeof(int)); lua_el_mode = (int*)calloc(PT_NUM, sizeof(int));
lua_gr_func = (int*)calloc(PT_NUM, sizeof(int)); lua_gr_func = (int*)calloc(PT_NUM, sizeof(int));
for(i = 0; i < PT_NUM; i++) for (int i = 0; i < PT_NUM; i++)
{ {
lua_el_mode[i] = 0; lua_el_mode[i] = 0;
lua_gr_func[i] = 0; lua_gr_func[i] = 0;
@ -470,21 +469,21 @@ int LuaScriptInterface::interface_addComponent(lua_State * l)
{ {
void * luaComponent = NULL; void * luaComponent = NULL;
ui::Component * component = NULL; ui::Component * component = NULL;
if(luaComponent = Luna<LuaButton>::tryGet(l, 1)) if ((luaComponent = Luna<LuaButton>::tryGet(l, 1)))
component = Luna<LuaButton>::get(luaComponent)->GetComponent(); component = Luna<LuaButton>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaLabel>::tryGet(l, 1)))
component = Luna<LuaLabel>::get(luaComponent)->GetComponent(); component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaTextbox>::tryGet(l, 1)))
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent(); component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)))
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent(); component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaSlider>::tryGet(l, 1)))
component = Luna<LuaSlider>::get(luaComponent)->GetComponent(); component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)))
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent(); component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
else else
luaL_typerror(l, 1, "Component"); luaL_typerror(l, 1, "Component");
if(luacon_ci->Window && component) if (luacon_ci->Window && component)
luacon_ci->Window->AddComponent(component); luacon_ci->Window->AddComponent(component);
return 0; return 0;
} }
@ -493,17 +492,17 @@ int LuaScriptInterface::interface_removeComponent(lua_State * l)
{ {
void * luaComponent = NULL; void * luaComponent = NULL;
ui::Component * component = NULL; ui::Component * component = NULL;
if(luaComponent = Luna<LuaButton>::tryGet(l, 1)) if ((luaComponent = Luna<LuaButton>::tryGet(l, 1)))
component = Luna<LuaButton>::get(luaComponent)->GetComponent(); component = Luna<LuaButton>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaLabel>::tryGet(l, 1)))
component = Luna<LuaLabel>::get(luaComponent)->GetComponent(); component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaTextbox>::tryGet(l, 1)))
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent(); component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)))
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent(); component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaSlider>::tryGet(l, 1)))
component = Luna<LuaSlider>::get(luaComponent)->GetComponent(); component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)))
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent(); component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
else else
luaL_typerror(l, 1, "Component"); luaL_typerror(l, 1, "Component");
@ -1097,7 +1096,7 @@ int LuaScriptInterface::simulation_createParts(lua_State * l)
int flags = luaL_optint(l,7,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,7,luacon_sim->replaceModeFlags);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
@ -1121,7 +1120,7 @@ int LuaScriptInterface::simulation_createLine(lua_State * l)
int flags = luaL_optint(l,9,luacon_sim->replaceModeFlags); int flags = luaL_optint(l,9,luacon_sim->replaceModeFlags);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
@ -1223,16 +1222,16 @@ int LuaScriptInterface::simulation_toolBrush(lua_State * l)
int tool = luaL_optint(l,5,0); int tool = luaL_optint(l,5,0);
int brush = luaL_optint(l,6,CIRCLE_BRUSH); int brush = luaL_optint(l,6,CIRCLE_BRUSH);
float strength = luaL_optnumber(l,7,1.0f); float strength = luaL_optnumber(l,7,1.0f);
if (tool == luacon_sim->tools.size()) if (tool == (int)luacon_sim->tools.size())
{ {
lua_pushinteger(l, 0); lua_pushinteger(l, 0);
return 1; return 1;
} }
else if (tool < 0 || tool >= luacon_sim->tools.size()) else if (tool < 0 || tool > (int)luacon_sim->tools.size())
return luaL_error(l, "Invalid tool id '%d'", tool); return luaL_error(l, "Invalid tool id '%d'", tool);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
@ -1254,16 +1253,16 @@ int LuaScriptInterface::simulation_toolLine(lua_State * l)
int tool = luaL_optint(l,7,0); int tool = luaL_optint(l,7,0);
int brush = luaL_optint(l,8,CIRCLE_BRUSH); int brush = luaL_optint(l,8,CIRCLE_BRUSH);
float strength = luaL_optnumber(l,9,1.0f); float strength = luaL_optnumber(l,9,1.0f);
if (tool < 0 || tool >= luacon_sim->tools.size()+1) if (tool < 0 || tool >= (int)luacon_sim->tools.size()+1)
return luaL_error(l, "Invalid tool id '%d'", tool); return luaL_error(l, "Invalid tool id '%d'", tool);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
if (tool == luacon_sim->tools.size()) if (tool == (int)luacon_sim->tools.size())
{ {
Tool *WindTool = luacon_model->GetToolFromIdentifier("DEFAULT_UI_WIND"); Tool *WindTool = luacon_model->GetToolFromIdentifier("DEFAULT_UI_WIND");
WindTool->DrawLine(luacon_sim, brushList[brush], ui::Point(x1, y1), ui::Point(x2, y2)); WindTool->DrawLine(luacon_sim, brushList[brush], ui::Point(x1, y1), ui::Point(x2, y2));
@ -1283,12 +1282,12 @@ int LuaScriptInterface::simulation_toolBox(lua_State * l)
int y2 = luaL_optint(l,4,-1); int y2 = luaL_optint(l,4,-1);
int tool = luaL_optint(l,5,0); int tool = luaL_optint(l,5,0);
float strength = luaL_optnumber(l,6,1.0f); float strength = luaL_optnumber(l,6,1.0f);
if (tool == luacon_sim->tools.size()) if (tool == (int)luacon_sim->tools.size())
{ {
lua_pushinteger(l, 0); lua_pushinteger(l, 0);
return 1; return 1;
} }
else if (tool < 0 || tool >= luacon_sim->tools.size()) else if (tool < 0 || tool >= (int)luacon_sim->tools.size())
return luaL_error(l, "Invalid tool id '%d'", tool); return luaL_error(l, "Invalid tool id '%d'", tool);
luacon_sim->ToolBox(x1, y1, x2, y2, tool, strength); luacon_sim->ToolBox(x1, y1, x2, y2, tool, strength);
@ -1309,7 +1308,7 @@ int LuaScriptInterface::simulation_decoBrush(lua_State * l)
int brush = luaL_optint(l,10,CIRCLE_BRUSH); int brush = luaL_optint(l,10,CIRCLE_BRUSH);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
@ -1335,7 +1334,7 @@ int LuaScriptInterface::simulation_decoLine(lua_State * l)
int brush = luaL_optint(l,12,CIRCLE_BRUSH); int brush = luaL_optint(l,12,CIRCLE_BRUSH);
vector<Brush*> brushList = luacon_model->GetBrushList(); vector<Brush*> brushList = luacon_model->GetBrushList();
if (brush < 0 || brush >= brushList.size()) if (brush < 0 || brush >= (int)brushList.size())
return luaL_error(l, "Invalid brush id '%d'", brush); return luaL_error(l, "Invalid brush id '%d'", brush);
ui::Point tempRadius = brushList[brush]->GetRadius(); ui::Point tempRadius = brushList[brush]->GetRadius();
brushList[brush]->SetRadius(ui::Point(rx, ry)); brushList[brush]->SetRadius(ui::Point(rx, ry));
@ -2071,11 +2070,11 @@ void LuaScriptInterface::initElementsAPI()
int LuaScriptInterface::elements_loadDefault(lua_State * l) int LuaScriptInterface::elements_loadDefault(lua_State * l)
{ {
int args = lua_gettop(l); int args = lua_gettop(l);
if(args) if (args)
{ {
luaL_checktype(l, 1, LUA_TNUMBER); luaL_checktype(l, 1, LUA_TNUMBER);
int id = lua_tointeger(l, 1); int id = lua_tointeger(l, 1);
if(id < 0 || id >= PT_NUM) if (id < 0 || id >= PT_NUM)
return luaL_error(l, "Invalid element"); return luaL_error(l, "Invalid element");
lua_getglobal(l, "elements"); lua_getglobal(l, "elements");
@ -2083,7 +2082,7 @@ int LuaScriptInterface::elements_loadDefault(lua_State * l)
lua_setfield(l, -2, luacon_sim->elements[id].Identifier); lua_setfield(l, -2, luacon_sim->elements[id].Identifier);
std::vector<Element> elementList = GetElements(); std::vector<Element> elementList = GetElements();
if(id < elementList.size()) if (id < (int)elementList.size())
luacon_sim->elements[id] = elementList[id]; luacon_sim->elements[id] = elementList[id];
else else
luacon_sim->elements[id] = Element(); luacon_sim->elements[id] = Element();
@ -2095,9 +2094,9 @@ int LuaScriptInterface::elements_loadDefault(lua_State * l)
else else
{ {
std::vector<Element> elementList = GetElements(); std::vector<Element> elementList = GetElements();
for(int i = 0; i < PT_NUM; i++) for (int i = 0; i < PT_NUM; i++)
{ {
if(i < elementList.size()) if (i < (int)elementList.size())
luacon_sim->elements[i] = elementList[i]; luacon_sim->elements[i] = elementList[i];
else else
luacon_sim->elements[i] = Element(); luacon_sim->elements[i] = Element();
@ -2746,7 +2745,7 @@ int LuaScriptInterface::fileSystem_list(lua_State * l)
directory = opendir(directoryName); directory = opendir(directoryName);
if (directory != NULL) if (directory != NULL)
{ {
while (entry = readdir(directory)) while ((entry = readdir(directory)))
{ {
if(strncmp(entry->d_name, "..", 3) && strncmp(entry->d_name, ".", 2)) if(strncmp(entry->d_name, "..", 3) && strncmp(entry->d_name, ".", 2))
{ {
@ -3024,7 +3023,7 @@ void LuaScriptInterface::OnTick()
int LuaScriptInterface::Command(std::string command) int LuaScriptInterface::Command(std::string command)
{ {
if(command[0] == '!') if (command[0] == '!')
{ {
lastError = ""; lastError = "";
int ret = legacy->Command(command.substr(1)); int ret = legacy->Command(command.substr(1));
@ -3037,21 +3036,22 @@ int LuaScriptInterface::Command(std::string command)
std::string text = ""; std::string text = "";
lastError = ""; lastError = "";
currentCommand = true; currentCommand = true;
if(lastCode.length()) if (lastCode.length())
lastCode += "\n"; lastCode += "\n";
lastCode += command; lastCode += command;
std::string tmp = "return " + lastCode; std::string tmp = "return " + lastCode;
ui::Engine::Ref().LastTick(gettime()); ui::Engine::Ref().LastTick(gettime());
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console"); luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
if(lua_type(l, -1) != LUA_TFUNCTION) if (lua_type(l, -1) != LUA_TFUNCTION)
{ {
lua_pop(l, 1); lua_pop(l, 1);
luaL_loadbuffer(l, lastCode.c_str(), lastCode.length(), "@console"); luaL_loadbuffer(l, lastCode.c_str(), lastCode.length(), "@console");
} }
if(lua_type(l, -1) != LUA_TFUNCTION) if (lua_type(l, -1) != LUA_TFUNCTION)
{ {
lastError = luacon_geterror(); lastError = luacon_geterror();
if(std::string(lastError).find("near '<eof>'")!=-1) //the idea stolen from lua-5.1.5/lua.c std::string err = lastError;
if (err.find("near '<eof>'") != err.npos) //the idea stolen from lua-5.1.5/lua.c
lastError = "..."; lastError = "...";
else else
lastCode = ""; lastCode = "";
@ -3060,24 +3060,26 @@ int LuaScriptInterface::Command(std::string command)
{ {
lastCode = ""; lastCode = "";
ret = lua_pcall(l, 0, LUA_MULTRET, 0); ret = lua_pcall(l, 0, LUA_MULTRET, 0);
if(ret) if (ret)
lastError = luacon_geterror(); lastError = luacon_geterror();
else else
{ {
for(level++;level<=lua_gettop(l);level++) for (level++;level<=lua_gettop(l);level++)
{ {
luaL_tostring(l, level); luaL_tostring(l, level);
if(text.length()) if (text.length())
text += ", " + std::string(luaL_optstring(l, -1, "")); text += ", " + std::string(luaL_optstring(l, -1, ""));
else else
text = std::string(luaL_optstring(l, -1, "")); text = std::string(luaL_optstring(l, -1, ""));
lua_pop(l, 1); lua_pop(l, 1);
} }
if(text.length()) if (text.length())
if(lastError.length()) {
if (lastError.length())
lastError += "; " + text; lastError += "; " + text;
else else
lastError = text; lastError = text;
}
} }
} }
@ -3112,7 +3114,7 @@ std::string highlight(std::string command)
int pos = 0; int pos = 0;
const char *raw = command.c_str(); const char *raw = command.c_str();
char c; char c;
while(c = raw[pos]) while ((c = raw[pos]))
{ {
if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
{ {
@ -3164,10 +3166,12 @@ std::string highlight(std::string command)
while((w = wstart[len]) && ((w >= '0' && w <= '9') || w == '.')) while((w = wstart[len]) && ((w >= '0' && w <= '9') || w == '.'))
{ {
if(w == '.') if(w == '.')
{
if(seendot) if(seendot)
break; break;
else else
seendot = true; seendot = true;
}
len++; len++;
} }
if(w == 'e') if(w == 'e')

View File

@ -109,17 +109,17 @@ int LuaWindow::addComponent(lua_State * l)
{ {
void * luaComponent = NULL; void * luaComponent = NULL;
ui::Component * component = NULL; ui::Component * component = NULL;
if(luaComponent = Luna<LuaButton>::tryGet(l, 1)) if ((luaComponent = Luna<LuaButton>::tryGet(l, 1)))
component = Luna<LuaButton>::get(luaComponent)->GetComponent(); component = Luna<LuaButton>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaLabel>::tryGet(l, 1)))
component = Luna<LuaLabel>::get(luaComponent)->GetComponent(); component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaTextbox>::tryGet(l, 1)))
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent(); component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)))
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent(); component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaSlider>::tryGet(l, 1)))
component = Luna<LuaSlider>::get(luaComponent)->GetComponent(); component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)))
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent(); component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
else else
luaL_typerror(l, 1, "Component"); luaL_typerror(l, 1, "Component");
@ -132,17 +132,17 @@ int LuaWindow::removeComponent(lua_State * l)
{ {
void * luaComponent = NULL; void * luaComponent = NULL;
ui::Component * component = NULL; ui::Component * component = NULL;
if(luaComponent = Luna<LuaButton>::tryGet(l, 1)) if ((luaComponent = Luna<LuaButton>::tryGet(l, 1)))
component = Luna<LuaButton>::get(luaComponent)->GetComponent(); component = Luna<LuaButton>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaLabel>::tryGet(l, 1)))
component = Luna<LuaLabel>::get(luaComponent)->GetComponent(); component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaTextbox>::tryGet(l, 1)))
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent(); component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaCheckbox>::tryGet(l, 1)))
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent(); component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaSlider>::tryGet(l, 1)))
component = Luna<LuaSlider>::get(luaComponent)->GetComponent(); component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)) else if ((luaComponent = Luna<LuaProgressBar>::tryGet(l, 1)))
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent(); component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
else else
luaL_typerror(l, 1, "Component"); luaL_typerror(l, 1, "Component");

View File

@ -61,27 +61,27 @@ int TPTScriptInterface::Command(std::string command)
ValueType TPTScriptInterface::testType(std::string word) ValueType TPTScriptInterface::testType(std::string word)
{ {
int i = 0; size_t i = 0;
char * rawWord = (char *)word.c_str(); char * rawWord = (char *)word.c_str();
//Function //Function
if(word == "set") if (word == "set")
return TypeFunction; return TypeFunction;
else if(word == "create") else if (word == "create")
return TypeFunction; return TypeFunction;
else if(word == "delete") else if (word == "delete")
return TypeFunction; return TypeFunction;
else if(word == "kill") else if (word == "kill")
return TypeFunction; return TypeFunction;
else if(word == "load") else if (word == "load")
return TypeFunction; return TypeFunction;
else if(word == "reset") else if (word == "reset")
return TypeFunction; return TypeFunction;
else if(word == "bubble") else if (word == "bubble")
return TypeFunction; return TypeFunction;
else if(word == "quit") else if (word == "quit")
return TypeFunction; return TypeFunction;
//Basic type //Basic type
for(i = 0; i < word.length(); i++) for (i = 0; i < word.length(); i++)
{ {
if (!(rawWord[i] >= '0' && rawWord[i] <= '9') && !(rawWord[i] == '-' && !i)) if (!(rawWord[i] >= '0' && rawWord[i] <= '9') && !(rawWord[i] == '-' && !i))
{ {
@ -101,21 +101,21 @@ ValueType TPTScriptInterface::testType(std::string word)
return TypeNumber; return TypeNumber;
parseFloat: parseFloat:
for (i++; i < word.length(); i++) for (i++; i < word.length(); i++)
if(!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F'))) if (!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
{ {
goto parseString; goto parseString;
} }
return TypeFloat; return TypeFloat;
parseNumberHex: parseNumberHex:
for (i++; i < word.length(); i++) for (i++; i < word.length(); i++)
if(!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F'))) if (!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
{ {
goto parseString; goto parseString;
} }
return TypeNumber; return TypeNumber;
parsePoint: parsePoint:
for (i++; i < word.length(); i++) for (i++; i < word.length(); i++)
if(!(rawWord[i] >= '0' && rawWord[i] <= '9')) if (!(rawWord[i] >= '0' && rawWord[i] <= '9'))
{ {
goto parseString; goto parseString;
} }
@ -141,14 +141,14 @@ float TPTScriptInterface::parseNumber(char * stringData)
} }
if (base == 16) if (base == 16)
{ {
while(cc = *(stringData++)) while ((cc = *(stringData++)))
{ {
currentNumber *= base; currentNumber *= base;
if(cc >= '0' && cc <= '9') if (cc >= '0' && cc <= '9')
currentNumber += cc - '0'; currentNumber += cc - '0';
else if(cc >= 'a' && cc <= 'f') else if (cc >= 'a' && cc <= 'f')
currentNumber += (cc - 'a') + 10; currentNumber += (cc - 'a') + 10;
else if(cc >= 'A' && cc <= 'F') else if (cc >= 'A' && cc <= 'F')
currentNumber += (cc - 'A') + 10; currentNumber += (cc - 'A') + 10;
else else
break; break;
@ -198,6 +198,8 @@ AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
} }
case TypeString: case TypeString:
return StringType(word); return StringType(word);
default:
break;
} }
return StringType(word); return StringType(word);
} }
@ -330,6 +332,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
case FormatElement: case FormatElement:
sim->part_change_type(partIndex, sim->parts[partIndex].x, sim->parts[partIndex].y, newValue); sim->part_change_type(partIndex, sim->parts[partIndex].x, sim->parts[partIndex].y, newValue);
break; break;
default:
break;
} }
returnValue = 1; returnValue = 1;
} }
@ -367,6 +371,8 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
} }
} }
break; break;
default:
break;
} }
} }
else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber) else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
@ -413,6 +419,9 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
sim->part_change_type(j, sim->parts[j].x, sim->parts[j].y, newValue); sim->part_change_type(j, sim->parts[j].x, sim->parts[j].y, newValue);
} }
} }
break;
default:
break;
} }
} }
else else

View File

@ -353,9 +353,9 @@ void Air::Invert()
} }
Air::Air(Simulation & simulation): Air::Air(Simulation & simulation):
sim(simulation),
airMode(0), airMode(0),
ambientAirTemp(295.15f), ambientAirTemp(295.15f)
sim(simulation)
{ {
//Simulation should do this. //Simulation should do this.
make_kernel(); make_kernel();