mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 05:13:59 +02:00
- code cleanup from cppcheck
- added more checks when loading models, maps and textures
This commit is contained in:
@@ -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++)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -125,7 +125,7 @@ bool Window::handleEvent() {
|
||||
SDL_Event event;
|
||||
SDL_GetMouseState(&oldX,&oldY);
|
||||
|
||||
codeLocation = "b";
|
||||
//codeLocation = "b";
|
||||
|
||||
while(SDL_PollEvent(&event)) {
|
||||
try {
|
||||
|
@@ -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();
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user