- more updates to support big endian
This commit is contained in:
parent
37b09daa77
commit
3bba236d02
|
@ -3074,7 +3074,7 @@ int glestMain(int argc, char** argv) {
|
|||
if( haveSpecialOutputCommandLineOption == false ||
|
||||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true) {
|
||||
printf("%s %s",extractFileFromDirectoryPath(argv[0]).c_str(),getNetworkPlatformFreeVersionString().c_str());
|
||||
printf("\nCompiled using: %s on: %s platform: %s",getCompilerNameString().c_str(),getCompileDateTime().c_str(),getPlatformNameString().c_str());
|
||||
printf("\nCompiled using: %s on: %s platform: %s endianness: %s",getCompilerNameString().c_str(),getCompileDateTime().c_str(),getPlatformNameString().c_str(),(Shared::PlatformByteOrder::isBigEndian() == true ? "big" : "little"));
|
||||
printf("\nSVN: [%s]",getSVNRevisionString().c_str());
|
||||
#ifdef USE_STREFLOP
|
||||
//# define STREFLOP_NO_DENORMALS
|
||||
|
|
|
@ -91,6 +91,9 @@ struct MapFileHeader {
|
|||
};
|
||||
};
|
||||
|
||||
void toEndianMapFileHeader(MapFileHeader &header);
|
||||
void fromEndianMapFileHeader(MapFileHeader &header);
|
||||
|
||||
class MapInfo {
|
||||
public:
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <iterator>
|
||||
#include "platform_util.h"
|
||||
#include "conversion.h"
|
||||
#include "byte_order.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <errno.h>
|
||||
|
@ -747,6 +748,35 @@ void MapPreview::switchSurfaces(MapSurfaceType surf1, MapSurfaceType surf2) {
|
|||
}
|
||||
}
|
||||
|
||||
void toEndianMapFileHeader(MapFileHeader &header) {
|
||||
header.version = Shared::PlatformByteOrder::toCommonEndian(header.version);
|
||||
header.maxFactions = Shared::PlatformByteOrder::toCommonEndian(header.maxFactions);
|
||||
header.width = Shared::PlatformByteOrder::toCommonEndian(header.width);
|
||||
header.height = Shared::PlatformByteOrder::toCommonEndian(header.height);
|
||||
header.heightFactor = Shared::PlatformByteOrder::toCommonEndian(header.heightFactor);
|
||||
header.waterLevel = Shared::PlatformByteOrder::toCommonEndian(header.waterLevel);
|
||||
for(unsigned int i =0; i < MAX_TITLE_LENGTH; ++i) {
|
||||
header.title[i] = Shared::PlatformByteOrder::toCommonEndian(header.title[i]);
|
||||
}
|
||||
for(unsigned int i =0; i < MAX_DESCRIPTION_LENGTH; ++i) {
|
||||
header.description[i] = Shared::PlatformByteOrder::toCommonEndian(header.description[i]);
|
||||
}
|
||||
}
|
||||
void fromEndianMapFileHeader(MapFileHeader &header) {
|
||||
header.version = Shared::PlatformByteOrder::fromCommonEndian(header.version);
|
||||
header.maxFactions = Shared::PlatformByteOrder::fromCommonEndian(header.maxFactions);
|
||||
header.width = Shared::PlatformByteOrder::fromCommonEndian(header.width);
|
||||
header.height = Shared::PlatformByteOrder::fromCommonEndian(header.height);
|
||||
header.heightFactor = Shared::PlatformByteOrder::fromCommonEndian(header.heightFactor);
|
||||
header.waterLevel = Shared::PlatformByteOrder::fromCommonEndian(header.waterLevel);
|
||||
for(unsigned int i =0; i < MAX_TITLE_LENGTH; ++i) {
|
||||
header.title[i] = Shared::PlatformByteOrder::fromCommonEndian(header.title[i]);
|
||||
}
|
||||
for(unsigned int i =0; i < MAX_DESCRIPTION_LENGTH; ++i) {
|
||||
header.description[i] = Shared::PlatformByteOrder::fromCommonEndian(header.description[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void MapPreview::loadFromFile(const string &path) {
|
||||
|
||||
// "Could not open file, result: 3 - 2 No such file or directory [C:\Documents and Settings\人間五\Application Data\megaglest\maps\clearings_in_the_woods.gbm]
|
||||
|
@ -768,16 +798,17 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
fromEndianMapFileHeader(header);
|
||||
|
||||
heightFactor = header.heightFactor;
|
||||
waterLevel = header.waterLevel;
|
||||
title = header.title;
|
||||
author = header.author;
|
||||
cliffLevel = 0;
|
||||
if(header.version==1){
|
||||
if(header.version == 1) {
|
||||
desc = header.description;
|
||||
}
|
||||
else if(header.version==2){
|
||||
else if(header.version == 2) {
|
||||
desc = header.version2.short_desc;
|
||||
cliffLevel=header.version2.cliffLevel;
|
||||
cameraHeight=header.version2.cameraHeight;
|
||||
|
@ -792,6 +823,7 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
startLocations[i].x = Shared::PlatformByteOrder::toCommonEndian(startLocations[i].x);
|
||||
|
||||
bytes = fread(&startLocations[i].y, sizeof(int32), 1, f1);
|
||||
if(bytes != 1) {
|
||||
|
@ -799,7 +831,7 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
|
||||
startLocations[i].y = Shared::PlatformByteOrder::toCommonEndian(startLocations[i].y);
|
||||
}
|
||||
|
||||
//read Heights
|
||||
|
@ -812,6 +844,7 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
cells[i][j].height = Shared::PlatformByteOrder::toCommonEndian(cells[i][j].height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -824,6 +857,7 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
cells[i][j].surface = Shared::PlatformByteOrder::toCommonEndian(cells[i][j].surface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,6 +871,7 @@ void MapPreview::loadFromFile(const string &path) {
|
|||
snprintf(szBuf,8096,"fread returned wrong size = %zu on line: %d.",bytes,__LINE__);
|
||||
throw megaglest_runtime_error(szBuf);
|
||||
}
|
||||
obj = Shared::PlatformByteOrder::toCommonEndian(obj);
|
||||
|
||||
if (obj <= 10) {
|
||||
cells[i][j].object = obj;
|
||||
|
@ -1028,6 +1063,8 @@ bool MapPreview::loadMapInfo(string file, MapInfo *mapInfo, string i18nMaxMapPla
|
|||
}
|
||||
}
|
||||
else {
|
||||
fromEndianMapFileHeader(header);
|
||||
|
||||
if(header.version < mapver_1 || header.version >= mapver_MAX) {
|
||||
validMap = false;
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include <algorithm>
|
||||
#include "platform_util.h"
|
||||
#include "utf8.h"
|
||||
#include "byte_order.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -654,6 +655,9 @@ pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, uint32 &value) {
|
|||
}
|
||||
|
||||
int readbytes = fscanf(fp,"%20ld,%20u,%20ld",&refreshDate,&crcValue,&lastUpdateDate);
|
||||
refreshDate = Shared::PlatformByteOrder::fromCommonEndian(refreshDate);
|
||||
crcValue = Shared::PlatformByteOrder::fromCommonEndian(crcValue);
|
||||
lastUpdateDate = Shared::PlatformByteOrder::fromCommonEndian(lastUpdateDate);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d for Cache file [%s] readbytes = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),readbytes);
|
||||
|
@ -746,7 +750,7 @@ void writeCachedFileCRCValue(string crcCacheFile, uint32 &crcValue) {
|
|||
char szBuf1[100]="";
|
||||
strftime(szBuf1,100,"%Y-%m-%d %H:%M:%S",loctime);
|
||||
|
||||
fprintf(fp,"%ld,%u,%ld",refreshDate,crcValue,now);
|
||||
fprintf(fp,"%ld,%u,%ld",Shared::PlatformByteOrder::toCommonEndian(refreshDate),Shared::PlatformByteOrder::toCommonEndian(crcValue),Shared::PlatformByteOrder::toCommonEndian(now));
|
||||
fclose(fp);
|
||||
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"========== Writing CRC Cache offset [%d] refreshDate = %ld [%s], crcValue = %u, file [%s]\n",offset,refreshDate,szBuf1,crcValue,crcCacheFile.c_str());
|
||||
|
|
Loading…
Reference in New Issue
Block a user