- code cleanup from cppcheck

- added more checks when loading models, maps and textures
This commit is contained in:
Mark Vejvoda 2012-10-20 07:15:13 +00:00
parent 9356034920
commit 64058b17e7
13 changed files with 285 additions and 117 deletions

View File

@ -44,9 +44,7 @@ public:
}
};
ScriptManagerMessage::ScriptManagerMessage() {
this->text= "";
this->header= "";
ScriptManagerMessage::ScriptManagerMessage() : text(""), header("") {
this->factionIndex=-1;
this->teamIndex=-1;
}

View File

@ -802,43 +802,6 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
}
MapInfo MenuStateMods::loadMapInfo(string file) {
/*
Lang &lang= Lang::getInstance();
MapInfo mapInfo;
//memset(&mapInfo,0,sizeof(mapInfo));
try{
#ifdef WIN32
FILE *f= _wfopen(utf8_decode(file).c_str(), L"rb");
#else
FILE *f= fopen(file.c_str(), "rb");
#endif
if(f != NULL) {
MapFileHeader header;
size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f);
mapInfo.size.x= header.width;
mapInfo.size.y= header.height;
mapInfo.players= header.maxFactions;
mapInfo.desc= lang.get("MaxPlayers")+": "+intToStr(mapInfo.players)+"\n";
mapInfo.desc+=lang.get("Size")+": "+intToStr(mapInfo.size.x) + " x " + intToStr(mapInfo.size.y);
fclose(f);
}
}
catch(exception &e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what(),file.c_str());
throw megaglest_runtime_error("Error loading map file: [" + file + "] msg: " + e.what());
}
return mapInfo;
*/
//memset(&mapInfo,0,sizeof(mapInfo));
try{
Lang &lang= Lang::getInstance();
// Not painting properly so this is on hold

View File

@ -247,9 +247,7 @@ void GameNetworkInterface::requestCommand(const NetworkCommand *networkCommand,
const int32 SEND_FILE = 0x20;
const int32 ACK = 0x47;
FileTransferSocketThread::FileTransferSocketThread(FileTransferInfo fileInfo)
{
this->info = fileInfo;
FileTransferSocketThread::FileTransferSocketThread(FileTransferInfo fileInfo) : info(fileInfo) {
this->info.serverPort += 100;
}

View File

@ -26,22 +26,20 @@ namespace Glest{ namespace Game{
// =====================================================
// class Command
// =====================================================
Command::Command() {
Command::Command() : unitRef() {
this->commandType= NULL;
this->unitRef= NULL;
unitType= NULL;
stateType = cst_None;
stateValue = -1;
unitCommandGroupId = -1;
}
Command::Command(const CommandType *ct, const Vec2i &pos){
Command::Command(const CommandType *ct, const Vec2i &pos) :unitRef() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct);
this->commandType= ct;
this->pos= pos;
this->originalPos = this->pos;
this->unitRef= NULL;
unitType= NULL;
stateType = cst_None;
stateValue = -1;
@ -63,11 +61,10 @@ Command::Command(const CommandType *ct, Unit* unit) {
unitCommandGroupId = -1;
}
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) {
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing) : unitRef() {
this->commandType= ct;
this->pos= pos;
this->originalPos = this->pos;
this->unitRef= NULL;
this->unitType= unitType;
this->facing = facing;
stateType = cst_None;

View File

@ -403,7 +403,19 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
for(int i=0; i < maxPlayers; ++i) {
int x=0, y=0;
readBytes = fread(&x, sizeof(int32), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&y, sizeof(int32), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
startLocations[i]= Vec2i(x, y)*cellScale;
}
@ -416,6 +428,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
for(int i = 0; i < surfaceW; ++i) {
float32 alt=0;
readBytes = fread(&alt, sizeof(float32), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
SurfaceCell *sc= getSurfaceCell(i, j);
sc->setVertex(Vec3f(i*mapScale, alt / heightFactor, j*mapScale));
}
@ -426,6 +444,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
for(int i = 0; i < surfaceW; ++i) {
int8 surf=0;
readBytes = fread(&surf, sizeof(int8), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
getSurfaceCell(i, j)->setSurfaceType(surf-1);
}
}
@ -436,6 +460,12 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
int8 objNumber=0;
readBytes = fread(&objNumber, sizeof(int8), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
SurfaceCell *sc= getSurfaceCell(toSurfCoords(Vec2i(i, j)));
if(objNumber == 0) {
sc->setObject(NULL);

View File

@ -147,11 +147,11 @@ int ftpExecute(void)
int socksRdy=0;
ftpSession_S *pSession=NULL;
int sessionId=0;
int activeJobs=0;
//int activeJobs=0;
int len;
int bufLen;
activeJobs = ftpGetActiveTransCnt(); // are there any active transmitions?
int activeJobs = ftpGetActiveTransCnt(); // are there any active transmitions?
//for(n = 0; (activeJobs > 0) && (n < MAX_CONNECTIONS); n++)
for(n = 0; n < MAX_CONNECTIONS; n++)
{

View File

@ -251,6 +251,11 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
//read header
MeshHeaderV2 meshHeader;
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV2), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
@ -324,14 +329,48 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
//read data
readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(textures[mtDiffuse]!=NULL){
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(textures[mtDiffuse] != NULL) {
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
if(readBytes != 1 && vertexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
readBytes = fread(&diffuseColor, sizeof(Vec3f), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&opacity, sizeof(float32), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
if(readBytes != 1 && indexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,indexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
@ -343,6 +382,11 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
//read header
MeshHeaderV3 meshHeader;
size_t readBytes = fread(&meshHeader, sizeof(MeshHeaderV3), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
@ -413,16 +457,50 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
//read data
readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(textures[mtDiffuse]!=NULL){
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(textures[mtDiffuse] != NULL) {
for(unsigned int i=0; i<meshHeader.texCoordFrameCount; ++i){
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
if(readBytes != 1 && vertexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
}
readBytes = fread(&diffuseColor, sizeof(Vec3f), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&opacity, sizeof(float32), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
fseek(f, sizeof(Vec4f)*(meshHeader.colorFrameCount-1), SEEK_CUR);
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
if(readBytes != 1 && indexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,indexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex,
@ -485,6 +563,11 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
//read header
MeshHeader meshHeader;
size_t readBytes = fread(&meshHeader, sizeof(MeshHeader), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
name = reinterpret_cast<char*>(meshHeader.name);
@ -518,6 +601,12 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
if((meshHeader.textures & flag) && textureManager != NULL) {
uint8 cMapPath[mapPathSize];
readBytes = fread(cMapPath, mapPathSize, 1, f);
if(readBytes != 1 && mapPathSize != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,mapPathSize,__LINE__);
throw megaglest_runtime_error(szBuf);
}
string mapPath= toLower(reinterpret_cast<char*>(cMapPath));
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("mapPath [%s] meshHeader.textures = %d flag = %d (meshHeader.textures & flag) = %d meshIndex = %d i = %d\n",mapPath.c_str(),meshHeader.textures,flag,(meshHeader.textures & flag),meshIndex,i);
@ -537,11 +626,35 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
//read data
readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(readBytes != 1 && (frameCount * vertexCount) != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(meshHeader.textures!=0){
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
if(readBytes != 1 && vertexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u][%u] on line: %d.",readBytes,frameCount,vertexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
if(readBytes != 1 && indexCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,indexCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
//tangents
if(textures[mtNormal]!=NULL){
@ -878,6 +991,13 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
//file header
FileHeader fileHeader;
size_t readBytes = fread(&fileHeader, sizeof(FileHeader), 1, f);
if(readBytes != 1) {
fclose(f);
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(strncmp(reinterpret_cast<char*>(fileHeader.id), "G3D", 3) != 0) {
fclose(f);
f = NULL;
@ -893,6 +1013,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
//model header
ModelHeader modelHeader;
readBytes = fread(&modelHeader, sizeof(ModelHeader), 1, f);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
meshCount= modelHeader.meshCount;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);
@ -920,6 +1046,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
//version 3
else if(fileHeader.version == 3) {
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
if(readBytes != 1 && meshCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,meshCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);
@ -941,6 +1073,12 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
//version 2
else if(fileHeader.version == 2) {
readBytes = fread(&meshCount, sizeof(meshCount), 1, f);
if(readBytes != 1 && meshCount != 0) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu [%u] on line: %d.",readBytes,meshCount,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("meshCount = %d\n",meshCount);

View File

@ -1482,14 +1482,14 @@ void ProjectileParticleSystem::update(){
//printf("Update particle targetVector [%s][%f] currentVector [%s][%f] relative = %f\n",targetVector.getString().c_str(),targetVector.length(),currentVector.getString().c_str(),currentVector.length(),relative);
#ifdef USE_STREFLOP
float absolute= clamp(streflop::fabs(static_cast<streflop::Simple>(currentVector.length())), 0.0f, 1.0f);
#else
float absolute= clamp(fabs(currentVector.length()), 0.0f, 1.0f);
#endif
//#ifdef USE_STREFLOP
// float absolute= clamp(streflop::fabs(static_cast<streflop::Simple>(currentVector.length())), 0.0f, 1.0f);
//#else
// float absolute= clamp(fabs(currentVector.length()), 0.0f, 1.0f);
//#endif
//printf("#a currentVector.length() = %f, targetVector.length() = %f, relative = %f, absolute = %f, trajectorySpeed = %f\n",currentVector.length(),targetVector.length(),relative,absolute,trajectorySpeed);
absolute = relative;
float absolute = relative;
setTween(relative,absolute);

View File

@ -120,6 +120,11 @@ void PixmapIoTga::openRead(const string &path) {
//read header
TargaFileHeader fileHeader;
size_t readBytes = fread(&fileHeader, sizeof(TargaFileHeader), 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
//check that we can load this tga file
if(fileHeader.idLength != 0) {
@ -150,6 +155,12 @@ void PixmapIoTga::read(uint8 *pixels, int components) {
if(this->components == 1) {
size_t readBytes = fread(&l, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
r= l;
g= l;
b= l;
@ -157,10 +168,34 @@ void PixmapIoTga::read(uint8 *pixels, int components) {
}
else {
size_t readBytes = fread(&b, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&g, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&r, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(this->components == 4) {
readBytes = fread(&a, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
else {
a= 255;
@ -256,6 +291,12 @@ void PixmapIoBmp::openRead(const string &path){
//read file header
BitmapFileHeader fileHeader;
size_t readBytes = fread(&fileHeader, sizeof(BitmapFileHeader), 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
throw megaglest_runtime_error(path +" is not a bitmap");
}
@ -263,6 +304,12 @@ void PixmapIoBmp::openRead(const string &path){
//read info header
BitmapInfoHeader infoHeader;
readBytes = fread(&infoHeader, sizeof(BitmapInfoHeader), 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if(infoHeader.bitCount!=24){
throw megaglest_runtime_error(path+" is not a 24 bit bitmap");
}
@ -280,8 +327,26 @@ void PixmapIoBmp::read(uint8 *pixels, int components) {
for(int i=0; i<h*w*components; i+=components) {
uint8 r, g, b;
size_t readBytes = fread(&b, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&g, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
readBytes = fread(&r, 1, 1, file);
if(readBytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",readBytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
switch(components){
case 1:
@ -365,69 +430,16 @@ PixmapIoPng::~PixmapIoPng() {
}
void PixmapIoPng::openRead(const string &path) {
throw megaglest_runtime_error("PixmapIoPng::openRead not implemented!");
/*
file= fopen(path.c_str(),"rb");
if (file==NULL){
throw megaglest_runtime_error("Can't open BMP file: "+ path);
}
//read file header
BitmapFileHeader fileHeader;
size_t readBytes = fread(&fileHeader, sizeof(BitmapFileHeader), 1, file);
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
throw megaglest_runtime_error(path +" is not a bitmap");
}
//read info header
BitmapInfoHeader infoHeader;
readBytes = fread(&infoHeader, sizeof(BitmapInfoHeader), 1, file);
if(infoHeader.bitCount!=24){
throw megaglest_runtime_error(path+" is not a 24 bit bitmap");
}
h= infoHeader.height;
w= infoHeader.width;
components= 3;
*/
}
void PixmapIoPng::read(uint8 *pixels) {
throw megaglest_runtime_error("PixmapIoPng::read not implemented!");
//read(pixels, 3);
}
void PixmapIoPng::read(uint8 *pixels, int components) {
throw megaglest_runtime_error("PixmapIoPng::read #2 not implemented!");
/*
for(int i=0; i<h*w*components; i+=components) {
uint8 r, g, b;
size_t readBytes = fread(&b, 1, 1, file);
readBytes = fread(&g, 1, 1, file);
readBytes = fread(&r, 1, 1, file);
switch(components){
case 1:
pixels[i]= (r+g+b)/3;
break;
case 3:
pixels[i]= r;
pixels[i+1]= g;
pixels[i+2]= b;
break;
case 4:
pixels[i]= r;
pixels[i+1]= g;
pixels[i+2]= b;
pixels[i+3]= 255;
break;
}
}
*/
}
void PixmapIoPng::openWrite(const string &path, int w, int h, int components) {

View File

@ -763,6 +763,11 @@ void MapPreview::loadFromFile(const string &path) {
//read header
MapFileHeader header;
size_t bytes = fread(&header, sizeof(MapFileHeader), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
heightFactor = header.heightFactor;
waterLevel = header.waterLevel;
@ -782,7 +787,19 @@ void MapPreview::loadFromFile(const string &path) {
resetFactions(header.maxFactions);
for (int i = 0; i < maxFactions; ++i) {
bytes = fread(&startLocations[i].x, sizeof(int32), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
bytes = fread(&startLocations[i].y, sizeof(int32), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
//read Heights
@ -790,6 +807,11 @@ void MapPreview::loadFromFile(const string &path) {
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
bytes = fread(&cells[i][j].height, sizeof(float), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
}
@ -797,6 +819,11 @@ void MapPreview::loadFromFile(const string &path) {
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
bytes = fread(&cells[i][j].surface, sizeof(int8), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
}
}
@ -805,6 +832,12 @@ void MapPreview::loadFromFile(const string &path) {
for (int i = 0; i < w; ++i) {
int8 obj;
bytes = fread(&obj, sizeof(int8), 1, f1);
if(bytes != 1) {
char szBuf[8096]="";
snprintf(szBuf,8096,"fread returned wrong size = %lu on line: %d.",bytes,__LINE__);
throw megaglest_runtime_error(szBuf);
}
if (obj <= 10) {
cells[i][j].object = obj;
}

View File

@ -841,7 +841,7 @@ Socket::Socket() {
socklen_t optlen = sizeof(bufsize);
int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&bufsize, &optlen);
printf("Original setsockopt(SO_SNDBUF) = [%d] new will be [%d]\n",bufsize,Socket::DEFAULT_SOCKET_SENDBUF_SIZE);
printf("Original setsockopt(SO_SNDBUF) = [%d] new will be [%d] ret = %d\n",bufsize,Socket::DEFAULT_SOCKET_SENDBUF_SIZE,ret);
ret = setsockopt( sock, SOL_SOCKET, SO_SNDBUF, (char *) &Socket::DEFAULT_SOCKET_SENDBUF_SIZE, sizeof( int ) );
if (ret == -1) {
@ -854,7 +854,7 @@ Socket::Socket() {
socklen_t optlen = sizeof(bufsize);
int ret = getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&bufsize, &optlen);
printf("Original setsockopt(SO_RCVBUF) = [%d] new will be [%d]\n",bufsize,Socket::DEFAULT_SOCKET_RECVBUF_SIZE);
printf("Original setsockopt(SO_RCVBUF) = [%d] new will be [%d] ret = %d\n",bufsize,Socket::DEFAULT_SOCKET_RECVBUF_SIZE,ret);
ret = setsockopt( sock, SOL_SOCKET, SO_RCVBUF, (char *) &Socket::DEFAULT_SOCKET_RECVBUF_SIZE, sizeof( int ) );
if (ret == -1) {

View File

@ -125,7 +125,7 @@ bool Window::handleEvent() {
SDL_Event event;
SDL_GetMouseState(&oldX,&oldY);
codeLocation = "b";
//codeLocation = "b";
while(SDL_PollEvent(&event)) {
try {

View File

@ -108,8 +108,7 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
dwErrorGL = GetLastError();
assertGl();
BOOL err= 0;
err= wglUseFontBitmaps(dc, 0, charCount, base);
BOOL err= wglUseFontBitmaps(dc, 0, charCount, base);
dwErrorGL = GetLastError();
/*