code cleanup

This commit is contained in:
GaryOderNichts 2021-02-01 18:50:17 +01:00
parent e2f665b9c0
commit 57eaa999ec
16 changed files with 57 additions and 203 deletions

View File

@ -810,17 +810,11 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
float *fbuf = (float*)buf; float *fbuf = (float*)buf;
CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&anpk.size);
anpk.size = BSWAP32(anpk.size);
#endif
if(!CGeneral::faststrncmp(anpk.ident, "ANLF", 4)) { if(!CGeneral::faststrncmp(anpk.ident, "ANLF", 4)) {
ROUNDSIZE(anpk.size); ROUNDSIZE(anpk.size);
CFileMgr::Read(fd, buf, anpk.size); CFileMgr::Read(fd, buf, anpk.size);
#ifndef BIGENDIAN
numANPK = *(int*)buf;
#else
numANPK = BSWAP32(*(int*)buf); numANPK = BSWAP32(*(int*)buf);
#endif
} else if(!CGeneral::faststrncmp(anpk.ident, "ANPK", 4)) { } else if(!CGeneral::faststrncmp(anpk.ident, "ANPK", 4)) {
CFileMgr::Seek(fd, -8, 1); CFileMgr::Seek(fd, -8, 1);
numANPK = 1; numANPK = 1;
@ -829,23 +823,15 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
for(i = 0; i < numANPK; i++){ for(i = 0; i < numANPK; i++){
// block name // block name
CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&anpk, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&anpk.size);
anpk.size = BSWAP32(anpk.size);
#endif
ROUNDSIZE(anpk.size); ROUNDSIZE(anpk.size);
CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&info.size);
info.size = BSWAP32(info.size);
#endif
ROUNDSIZE(info.size); ROUNDSIZE(info.size);
CFileMgr::Read(fd, buf, info.size); CFileMgr::Read(fd, buf, info.size);
CAnimBlock *animBlock = &ms_aAnimBlocks[ms_numAnimBlocks++]; CAnimBlock *animBlock = &ms_aAnimBlocks[ms_numAnimBlocks++];
strncpy(animBlock->name, buf+4, 24); strncpy(animBlock->name, buf+4, 24);
#ifndef BIGENDIAN
animBlock->numAnims = *(int*)buf;
#else
animBlock->numAnims = BSWAP32(*(int*)buf); animBlock->numAnims = BSWAP32(*(int*)buf);
#endif
animBlock->firstIndex = ms_numAnimations; animBlock->firstIndex = ms_numAnimations;
@ -854,59 +840,37 @@ CAnimManager::LoadAnimFile(int fd, bool compress)
// animation name // animation name
CFileMgr::Read(fd, (char*)&name, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&name, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&name.size);
name.size = BSWAP32(name.size);
#endif
ROUNDSIZE(name.size); ROUNDSIZE(name.size);
CFileMgr::Read(fd, buf, name.size); CFileMgr::Read(fd, buf, name.size);
hier->SetName(buf); hier->SetName(buf);
// DG info has number of nodes/sequences // DG info has number of nodes/sequences
CFileMgr::Read(fd, (char*)&dgan, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&dgan, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&dgan.size);
dgan.size = BSWAP32(dgan.size);
#endif
ROUNDSIZE(dgan.size); ROUNDSIZE(dgan.size);
CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&info, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&info.size);
info.size = BSWAP32(info.size);
#endif
ROUNDSIZE(info.size); ROUNDSIZE(info.size);
CFileMgr::Read(fd, buf, info.size); CFileMgr::Read(fd, buf, info.size);
#ifndef BIGENDIAN
hier->numSequences = *(int*)buf;
#else
hier->numSequences = BSWAP32(*(int*)buf); hier->numSequences = BSWAP32(*(int*)buf);
#endif
hier->sequences = new CAnimBlendSequence[hier->numSequences]; hier->sequences = new CAnimBlendSequence[hier->numSequences];
CAnimBlendSequence *seq = hier->sequences; CAnimBlendSequence *seq = hier->sequences;
for(k = 0; k < hier->numSequences; k++, seq++){ for(k = 0; k < hier->numSequences; k++, seq++){
// Each node has a name and key frames // Each node has a name and key frames
CFileMgr::Read(fd, (char*)&cpan, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&cpan, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&cpan.size);
cpan.size = BSWAP32(cpan.size);
#endif
ROUNDSIZE(dgan.size); ROUNDSIZE(dgan.size);
CFileMgr::Read(fd, (char*)&anim, sizeof(IfpHeader)); CFileMgr::Read(fd, (char*)&anim, sizeof(IfpHeader));
#ifdef BIGENDIAN memLittle32(&anim.size);
anim.size = BSWAP32(anim.size);
#endif
ROUNDSIZE(anim.size); ROUNDSIZE(anim.size);
CFileMgr::Read(fd, buf, anim.size); CFileMgr::Read(fd, buf, anim.size);
#ifndef BIGENDIAN
int numFrames = *(int*)(buf+28);
#else
int numFrames = BSWAP32(*(int*)(buf+28)); int numFrames = BSWAP32(*(int*)(buf+28));
#endif
seq->SetName(buf); seq->SetName(buf);
#ifdef PED_SKIN #ifdef PED_SKIN
if(anim.size == 44) if(anim.size == 44)
#ifndef BIGENDIAN
seq->SetBoneTag(*(int*)(buf+40));
#else
seq->SetBoneTag(BSWAP32(*(int*)(buf+40))); seq->SetBoneTag(BSWAP32(*(int*)(buf+40)));
#endif
#endif #endif
if(numFrames == 0) if(numFrames == 0)
continue; continue;

View File

@ -53,7 +53,6 @@ using namespace re3_openal;
void EFXInit() void EFXInit()
{ {
/* Define a macro to help load the function pointers. */ /* Define a macro to help load the function pointers. */
/* Prefix all the function pointers with re* to avoid linking issue with the library functions */
#define LOAD_PROC(T, x) ((x) = (T)alGetProcAddress(#x)) #define LOAD_PROC(T, x) ((x) = (T)alGetProcAddress(#x))
LOAD_PROC(LPALGENEFFECTS, alGenEffects); LOAD_PROC(LPALGENEFFECTS, alGenEffects);
LOAD_PROC(LPALDELETEEFFECTS, alDeleteEffects); LOAD_PROC(LPALDELETEEFFECTS, alDeleteEffects);

View File

@ -46,16 +46,7 @@
//TODO: max channels //TODO: max channels
//TODO: loop count //TODO: loop count
#ifdef _WIN32 #ifdef __WIIU__
#pragma comment( lib, "OpenAL32.lib" )
#endif
// for user MP3s
#ifdef _WIN32
#include <direct.h>
#include <shobjidl.h>
#include <shlguid.h>
#elif defined __WIIU__
extern "C" char *_getcwd (char *__buf, size_t __size); extern "C" char *_getcwd (char *__buf, size_t __size);
#else #else
#define _getcwd getcwd #define _getcwd getcwd
@ -267,7 +258,6 @@ release_existing()
alcSuspendContext(ALContext); alcSuspendContext(ALContext);
alcDestroyContext(ALContext); alcDestroyContext(ALContext);
} }
if ( ALDevice ) if ( ALDevice )
alcCloseDevice(ALDevice); alcCloseDevice(ALDevice);
@ -2021,11 +2011,11 @@ cSampleManager::InitialiseSampleBanks(void)
// fix endianess // fix endianess
for (int i = 0; i < TOTAL_AUDIO_SAMPLES; i++) for (int i = 0; i < TOTAL_AUDIO_SAMPLES; i++)
{ {
m_aSamples[i].nOffset = BSWAP32(m_aSamples[i].nOffset); memLittle32(&m_aSamples[i].nOffset);
m_aSamples[i].nSize = BSWAP32(m_aSamples[i].nSize); memLittle32(&m_aSamples[i].nSize);
m_aSamples[i].nFrequency = BSWAP32(m_aSamples[i].nFrequency); memLittle32(&m_aSamples[i].nFrequency);
m_aSamples[i].nLoopStart = BSWAP32(m_aSamples[i].nLoopStart); memLittle32(&m_aSamples[i].nLoopStart);
m_aSamples[i].nLoopEnd = BSWAP32(m_aSamples[i].nLoopEnd); memLittle32(&m_aSamples[i].nLoopEnd);
} }
#endif #endif
#ifdef OPUS_SFX #ifdef OPUS_SFX

View File

@ -107,11 +107,7 @@ void COnscreenTimerEntry::Process() {
} }
int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset); int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
#ifndef BIGENDIAN
int32 oldTime = *timerPtr;
#else
int32 oldTime = BSWAP32(*timerPtr); int32 oldTime = BSWAP32(*timerPtr);
#endif
int32 newTime = oldTime - int32(CTimer::GetTimeStepInSeconds() * 1000); int32 newTime = oldTime - int32(CTimer::GetTimeStepInSeconds() * 1000);
if(newTime < 0) { if(newTime < 0) {
*timerPtr = 0; *timerPtr = 0;
@ -119,11 +115,7 @@ void COnscreenTimerEntry::Process() {
m_nTimerOffset = 0; m_nTimerOffset = 0;
m_aTimerText[0] = 0; m_aTimerText[0] = 0;
} else { } else {
#ifndef BIGENDIAN
*timerPtr = newTime;
#else
*timerPtr = BSWAP32(newTime); *timerPtr = BSWAP32(newTime);
#endif
int32 oldTimeSeconds = oldTime / 1000; int32 oldTimeSeconds = oldTime / 1000;
if(oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds) { if(oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds) {
DMAudio.PlayFrontEndSound(SOUND_CLOCK_TICK, newTime / 1000); DMAudio.PlayFrontEndSound(SOUND_CLOCK_TICK, newTime / 1000);
@ -152,20 +144,12 @@ bool COnscreenTimerEntry::ProcessForDisplay() {
} }
void COnscreenTimerEntry::ProcessForDisplayClock() { void COnscreenTimerEntry::ProcessForDisplayClock() {
#ifndef BIGENDIAN
uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
#else
uint32 time = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nTimerOffset)); uint32 time = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nTimerOffset));
#endif
sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60, sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60,
time / 1000 % 60); time / 1000 % 60);
} }
void COnscreenTimerEntry::ProcessForDisplayCounter() { void COnscreenTimerEntry::ProcessForDisplayCounter() {
#ifndef BIGENDIAN
uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset);
#else
uint32 counter = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nCounterOffset)); uint32 counter = BSWAP32(*CTheScripts::GetPointerToScriptVariable(m_nCounterOffset));
#endif
sprintf(m_bCounterBuffer, "%d", counter); sprintf(m_bCounterBuffer, "%d", counter);
} }

View File

@ -67,12 +67,6 @@ void CRecordDataForGame::SaveOrRetrieveDataForThisFrame(void)
uint8* pEndPtr = pController2; uint8* pEndPtr = pController2;
if ((pDataBufferForFrame.m_nSizeOfPads[0] + pDataBufferForFrame.m_nSizeOfPads[1]) & 1) if ((pDataBufferForFrame.m_nSizeOfPads[0] + pDataBufferForFrame.m_nSizeOfPads[1]) & 1)
pEndPtr += 2; pEndPtr += 2;
#ifdef BIGENDIAN
// save as LE
pDataBufferForFrame.m_fTimeStep = FLOATSWAP32(pDataBufferForFrame.m_fTimeStep);
pDataBufferForFrame.m_nTimeInMilliseconds = BSWAP32(pDataBufferForFrame.m_nTimeInMilliseconds);
pDataBufferForFrame.m_nChecksum = BSWAP32(pDataBufferForFrame.m_nChecksum);
#endif
CFileMgr::Write(FId, (char*)&pDataBufferForFrame, pEndPtr - (uint8*)&pDataBufferForFrame); CFileMgr::Write(FId, (char*)&pDataBufferForFrame, pEndPtr - (uint8*)&pDataBufferForFrame);
break; break;
} }
@ -81,11 +75,6 @@ void CRecordDataForGame::SaveOrRetrieveDataForThisFrame(void)
CPad::GetPad(0)->NewState.Clear(); CPad::GetPad(0)->NewState.Clear();
else { else {
tGameBuffer* pData = (tGameBuffer*)pDataBufferPointer; tGameBuffer* pData = (tGameBuffer*)pDataBufferPointer;
#ifdef BIGENDIAN
pData->m_fTimeStep = FLOATSWAP32(pData->m_fTimeStep);
pData->m_nTimeInMilliseconds = BSWAP32(pData->m_nTimeInMilliseconds);
pData->m_nChecksum = BSWAP32(pData->m_nChecksum);
#endif
CTimer::SetTimeInMilliseconds(pData->m_nTimeInMilliseconds); CTimer::SetTimeInMilliseconds(pData->m_nTimeInMilliseconds);
CTimer::SetTimeStep(pData->m_fTimeStep); CTimer::SetTimeStep(pData->m_fTimeStep);
uint8 size1 = pData->m_nSizeOfPads[0]; uint8 size1 = pData->m_nSizeOfPads[0];

View File

@ -1602,11 +1602,7 @@ void CRunningScript::CollectParameters(uint32* pIp, int16 total)
case ARGUMENT_GLOBALVAR: case ARGUMENT_GLOBALVAR:
varIndex = CTheScripts::Read2BytesFromScript(pIp); varIndex = CTheScripts::Read2BytesFromScript(pIp);
script_assert(varIndex >= 8 && varIndex < CTheScripts::GetSizeOfVariableSpace()); script_assert(varIndex >= 8 && varIndex < CTheScripts::GetSizeOfVariableSpace());
#ifndef BIGENDIAN
ScriptParams[i] = *((int32*)&CTheScripts::ScriptSpace[varIndex]);
#else
ScriptParams[i] = BSWAP32(*((int32*)&CTheScripts::ScriptSpace[varIndex])); ScriptParams[i] = BSWAP32(*((int32*)&CTheScripts::ScriptSpace[varIndex]));
#endif
break; break;
case ARGUMENT_LOCALVAR: case ARGUMENT_LOCALVAR:
varIndex = CTheScripts::Read2BytesFromScript(pIp); varIndex = CTheScripts::Read2BytesFromScript(pIp);
@ -1647,11 +1643,7 @@ int CRunningScript::CollectParameterForDebug(char* buf, bool& var)
var = true; var = true;
sprintf(tmpstr, " $%d", varIndex / 4); sprintf(tmpstr, " $%d", varIndex / 4);
strcat(buf, tmpstr); strcat(buf, tmpstr);
#ifndef BIGENDIAN
return *((int32*)&CTheScripts::ScriptSpace[varIndex]);
#else
return BSWAP32(*((int32*)&CTheScripts::ScriptSpace[varIndex])); return BSWAP32(*((int32*)&CTheScripts::ScriptSpace[varIndex]));
#endif
case ARGUMENT_LOCALVAR: case ARGUMENT_LOCALVAR:
varIndex = CTheScripts::Read2BytesFromScript(&m_nIp); varIndex = CTheScripts::Read2BytesFromScript(&m_nIp);
script_assert(varIndex >= 0 && varIndex < ARRAY_SIZE(m_anLocalVariables)); script_assert(varIndex >= 0 && varIndex < ARRAY_SIZE(m_anLocalVariables));
@ -1705,11 +1697,7 @@ int32 CRunningScript::CollectNextParameterWithoutIncreasingPC(uint32 ip)
case ARGUMENT_INT32: case ARGUMENT_INT32:
return CTheScripts::Read4BytesFromScript(pIp); return CTheScripts::Read4BytesFromScript(pIp);
case ARGUMENT_GLOBALVAR: case ARGUMENT_GLOBALVAR:
#ifndef BIGENDIAN
return *((int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)]);
#else
return BSWAP32(*((int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)])); return BSWAP32(*((int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)]));
#endif
case ARGUMENT_LOCALVAR: case ARGUMENT_LOCALVAR:
return m_anLocalVariables[CTheScripts::Read2BytesFromScript(pIp)]; return m_anLocalVariables[CTheScripts::Read2BytesFromScript(pIp)];
case ARGUMENT_INT8: case ARGUMENT_INT8:
@ -1730,12 +1718,7 @@ void CRunningScript::StoreParameters(uint32* pIp, int16 number)
for (int16 i = 0; i < number; i++){ for (int16 i = 0; i < number; i++){
switch (CTheScripts::Read1ByteFromScript(pIp)) { switch (CTheScripts::Read1ByteFromScript(pIp)) {
case ARGUMENT_GLOBALVAR: case ARGUMENT_GLOBALVAR:
#ifndef BIGENDIAN
*(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)] = ScriptParams[i];
#else
// store as LE
*(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)] = BSWAP32(ScriptParams[i]); *(int32*)&CTheScripts::ScriptSpace[(uint16)CTheScripts::Read2BytesFromScript(pIp)] = BSWAP32(ScriptParams[i]);
#endif
break; break;
case ARGUMENT_LOCALVAR: case ARGUMENT_LOCALVAR:
m_anLocalVariables[CTheScripts::Read2BytesFromScript(pIp)] = ScriptParams[i]; m_anLocalVariables[CTheScripts::Read2BytesFromScript(pIp)] = ScriptParams[i];
@ -2034,11 +2017,7 @@ CRunningScript* CTheScripts::StartTestScript()
bool CTheScripts::IsPlayerOnAMission() bool CTheScripts::IsPlayerOnAMission()
{ {
#ifndef BIGENDIAN
return OnAMissionFlag && *(int32*)&ScriptSpace[OnAMissionFlag] == 1;
#else
return OnAMissionFlag && BSWAP32(*(int32*)&ScriptSpace[OnAMissionFlag]) == 1; return OnAMissionFlag && BSWAP32(*(int32*)&ScriptSpace[OnAMissionFlag]) == 1;
#endif
} }
void CRunningScript::Process() void CRunningScript::Process()

View File

@ -164,6 +164,7 @@ CdStreamInitThread(void)
ASSERT(gChannelRequestQ.items != nil ); ASSERT(gChannelRequestQ.items != nil );
gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 0); gCdStreamSema = sem_open("/semaphore_cd_stream", O_CREAT, 0644, 0);
if (gCdStreamSema == SEM_FAILED) { if (gCdStreamSema == SEM_FAILED) {
CDTRACE("failed to create stream semaphore"); CDTRACE("failed to create stream semaphore");
ASSERT(0); ASSERT(0);

View File

@ -24,10 +24,8 @@ CDirectory::ReadDirFile(const char *filename)
fd = CFileMgr::OpenFile(filename, "rb"); fd = CFileMgr::OpenFile(filename, "rb");
while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo))) while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo)))
{ {
#ifdef BIGENDIAN memLittle32(&dirinfo.offset);
dirinfo.offset = BSWAP32(dirinfo.offset); memLittle32(&dirinfo.size);
dirinfo.size = BSWAP32(dirinfo.size);
#endif
AddItem(dirinfo); AddItem(dirinfo);
} }
CFileMgr::CloseFile(fd); CFileMgr::CloseFile(fd);

View File

@ -218,9 +218,7 @@ CFileLoader::LoadCollisionFile(const char *filename)
#else #else
assert(header.ident == 'LLOC'); assert(header.ident == 'LLOC');
#endif #endif
#ifdef BIGENDIAN memLittle32(&header.size);
header.size = BSWAP32(header.size);
#endif
CFileMgr::Read(fd, (char*)work_buff, header.size); CFileMgr::Read(fd, (char*)work_buff, header.size);
memcpy(modelname, work_buff, 24); memcpy(modelname, work_buff, 24);
@ -248,19 +246,6 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
{ {
int i; int i;
#ifndef BIGENDIAN
model.boundingSphere.radius = *(float*)(buf);
model.boundingSphere.center.x = *(float*)(buf+4);
model.boundingSphere.center.y = *(float*)(buf+8);
model.boundingSphere.center.z = *(float*)(buf+12);
model.boundingBox.min.x = *(float*)(buf+16);
model.boundingBox.min.y = *(float*)(buf+20);
model.boundingBox.min.z = *(float*)(buf+24);
model.boundingBox.max.x = *(float*)(buf+28);
model.boundingBox.max.y = *(float*)(buf+32);
model.boundingBox.max.z = *(float*)(buf+36);
model.numSpheres = *(int16*)(buf+40);
#else
model.boundingSphere.radius = FLOATSWAP32(*(float*)(buf)); model.boundingSphere.radius = FLOATSWAP32(*(float*)(buf));
model.boundingSphere.center.x = FLOATSWAP32(*(float*)(buf+4)); model.boundingSphere.center.x = FLOATSWAP32(*(float*)(buf+4));
model.boundingSphere.center.y = FLOATSWAP32(*(float*)(buf+8)); model.boundingSphere.center.y = FLOATSWAP32(*(float*)(buf+8));
@ -272,7 +257,6 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.boundingBox.max.y = FLOATSWAP32(*(float*)(buf+32)); model.boundingBox.max.y = FLOATSWAP32(*(float*)(buf+32));
model.boundingBox.max.z = FLOATSWAP32(*(float*)(buf+36)); model.boundingBox.max.z = FLOATSWAP32(*(float*)(buf+36));
model.numSpheres = (int16) BSWAP16(*(uint16*)(buf+40)); model.numSpheres = (int16) BSWAP16(*(uint16*)(buf+40));
#endif
buf += 44; buf += 44;
if(model.numSpheres > 0){ if(model.numSpheres > 0){
@ -294,11 +278,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
}else }else
model.spheres = nil; model.spheres = nil;
#ifndef BIGENDIAN
model.numLines = *(int16*)buf;
#else
model.numLines = (int16) BSWAP16(*(uint16*)buf); model.numLines = (int16) BSWAP16(*(uint16*)buf);
#endif
buf += 4; buf += 4;
if(model.numLines > 0){ if(model.numLines > 0){
model.lines = (CColLine*)RwMalloc(model.numLines*sizeof(CColLine)); model.lines = (CColLine*)RwMalloc(model.numLines*sizeof(CColLine));
@ -322,11 +302,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
}else }else
model.lines = nil; model.lines = nil;
#ifndef BIGENDIAN
model.numBoxes = *(int16*)buf;
#else
model.numBoxes = (int16) BSWAP16(*(uint16*)buf); model.numBoxes = (int16) BSWAP16(*(uint16*)buf);
#endif
buf += 4; buf += 4;
if(model.numBoxes > 0){ if(model.numBoxes > 0){
model.boxes = (CColBox*)RwMalloc(model.numBoxes*sizeof(CColBox)); model.boxes = (CColBox*)RwMalloc(model.numBoxes*sizeof(CColBox));
@ -350,11 +326,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
}else }else
model.boxes = nil; model.boxes = nil;
#ifndef BIGENDIAN
int32 numVertices = *(int16*)buf;
#else
int32 numVertices = (int16) BSWAP16(*(uint16*)buf); int32 numVertices = (int16) BSWAP16(*(uint16*)buf);
#endif
buf += 4; buf += 4;
if(numVertices > 0){ if(numVertices > 0){
model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector)); model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector));
@ -381,11 +353,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
}else }else
model.vertices = nil; model.vertices = nil;
#ifndef BIGENDIAN
model.numTriangles = *(int16*)buf;
#else
model.numTriangles = (int16) BSWAP16(*(uint16*)buf); model.numTriangles = (int16) BSWAP16(*(uint16*)buf);
#endif
buf += 4; buf += 4;
if(model.numTriangles > 0){ if(model.numTriangles > 0){
model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle)); model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle));

View File

@ -527,7 +527,7 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp()
} }
} }
#elif __WIIU__ #elif __WIIU__
// TODO: WIIU // no mouse on the Wii U
#else #else
// It seems there is no way to get number of buttons on mouse, so assign all buttons if we have mouse. // It seems there is no way to get number of buttons on mouse, so assign all buttons if we have mouse.
double xpos = 1.0f, ypos; double xpos = 1.0f, ypos;
@ -588,7 +588,7 @@ void CPad::UpdateMouse()
} }
} }
#elif __WIIU__ #elif __WIIU__
// TODO: wiiu // no mouse on the Wii U
#else #else
if ( IsForegroundApp() && PSGLOBAL(cursorIsInWindow) ) if ( IsForegroundApp() && PSGLOBAL(cursorIsInWindow) )
{ {

View File

@ -420,10 +420,8 @@ CStreaming::LoadCdDirectory(const char *dirname, int n)
imgSelector = n<<24; imgSelector = n<<24;
assert(sizeof(direntry) == 32); assert(sizeof(direntry) == 32);
while(CFileMgr::Read(fd, (char*)&direntry, sizeof(direntry))){ while(CFileMgr::Read(fd, (char*)&direntry, sizeof(direntry))){
#ifdef BIGENDIAN memLittle32(&direntry.offset);
direntry.offset = BSWAP32(direntry.offset); memLittle32(&direntry.size);
direntry.size = BSWAP32(direntry.size);
#endif
dot = strchr(direntry.name, '.'); dot = strchr(direntry.name, '.');
assert(dot); assert(dot);
if(dot) *dot = '\0'; if(dot) *dot = '\0';

View File

@ -107,36 +107,33 @@ typedef uint16 bool16;
typedef uint32 bool32; typedef uint32 bool32;
#ifdef BIGENDIAN #ifdef BIGENDIAN
inline float _floatswap32(float f)
{
uint32_t _swapval = __builtin_bswap32(*(uint32_t*)&f);
return *(float*)&_swapval;
}
#define BSWAP32(x) __builtin_bswap32(x) #define BSWAP32(x) __builtin_bswap32(x)
#define BSWAP16(x) __builtin_bswap16(x) #define BSWAP16(x) __builtin_bswap16(x)
inline float _floatswap32(float f)
{
uint32 _swapval = BSWAP32(*(uint32*)&f);
return *(float*)&_swapval;
}
#define FLOATSWAP32(x) _floatswap32(x) #define FLOATSWAP32(x) _floatswap32(x)
#define BSWAP_VECTOR(v) \
do { \ inline void _memLittle32(void* val)
v.x = FLOATSWAP32(v.x); \ {
v.y = FLOATSWAP32(v.y); \ *(uint32*)val = BSWAP32(*(uint32*)val);
v.z = FLOATSWAP32(v.z); \ }
} while(0) #define memLittle32(val) _memLittle32(val)
#define BSWAP_MTX(m) \
do { \ inline void _memLittle16(void* val)
BSWAP_VECTOR(m.right); \ {
BSWAP_VECTOR(m.up); \ *(uint16*)val = BSWAP16(*(uint16*)val);
BSWAP_VECTOR(m.at); \ }
BSWAP_VECTOR(m.pos); \ #define memLittle16(val) _memLittle16(val)
BSWAP32(m.flags); \
BSWAP32(m.pad1); \
BSWAP32(m.pad2); \
BSWAP32(m.pad3); \
} while(0)
#else #else
#define BSWAP32(x) (x) #define BSWAP32(x) (x)
#define BSWAP16(x) (x) #define BSWAP16(x) (x)
#define FLOATSWAP32(x) (x) #define FLOATSWAP32(x) (x)
#define memLittle32(val)
#define memLittle16(val)
#endif #endif
#if defined(_MSC_VER) || defined (__MWERKS__) #if defined(_MSC_VER) || defined (__MWERKS__)

View File

@ -32,10 +32,8 @@ FindPlayerDff(uint32 &offset, uint32 &size)
do { do {
if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo))) if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo)))
return; return;
#ifdef BIGENDIAN memLittle32(&info.offset);
info.offset = BSWAP32(info.offset); memLittle32(&info.size);
info.size = BSWAP32(info.size);
#endif
} while (strcasecmp("player.dff", info.name) != 0); } while (strcasecmp("player.dff", info.name) != 0);
offset = info.offset; offset = info.offset;

View File

@ -35,9 +35,7 @@ GeometryListStreamRead1(RwStream *stream, rpGeometryList *geomlist)
if(RwStreamRead(stream, &numGeoms, 4) != 4) if(RwStreamRead(stream, &numGeoms, 4) != 4)
return nil; return nil;
#ifdef BIGENDIAN memLittle32(&numGeoms);
numGeoms = BSWAP32(numGeoms);
#endif
numberGeometrys = numGeoms/2; numberGeometrys = numGeoms/2;
geomlist->numGeoms = numGeoms; geomlist->numGeoms = numGeoms;
@ -106,12 +104,10 @@ ClumpAtomicStreamRead(RwStream *stream, rwFrameList *frmList, rpGeometryList *ge
if(RwStreamRead(stream, &a, size) != size) if(RwStreamRead(stream, &a, size) != size)
return nil; return nil;
#ifdef BIGENDIAN memLittle32(&a.frameIndex);
a.frameIndex = BSWAP32(a.frameIndex); memLittle32(&a.geomIndex);
a.geomIndex = BSWAP32(a.geomIndex); memLittle32(&a.flags);
a.flags = BSWAP32(a.flags); memLittle32(&a.unused);
a.unused = BSWAP32(a.unused);
#endif
atomic = RpAtomicCreate(); atomic = RpAtomicCreate();
if(atomic == nil) if(atomic == nil)
@ -162,11 +158,9 @@ RpClumpGtaStreamRead1(RwStream *stream)
return false; return false;
} }
#ifdef BIGENDIAN memLittle32(&gClumpInfo.numAtomics);
gClumpInfo.numAtomics = BSWAP32(gClumpInfo.numAtomics); memLittle32(&gClumpInfo.numCameras);
gClumpInfo.numCameras = BSWAP32(gClumpInfo.numCameras); memLittle32(&gClumpInfo.numLights);
gClumpInfo.numLights = BSWAP32(gClumpInfo.numLights);
#endif
if(!RwStreamFindChunk(stream, rwID_FRAMELIST, nil, &version)) if(!RwStreamFindChunk(stream, rwID_FRAMELIST, nil, &version))
return false; return false;

View File

@ -81,9 +81,7 @@ RwTexDictionaryGtaStreamRead(RwStream *stream)
if(RwStreamRead(stream, &numTextures, size) != size) if(RwStreamRead(stream, &numTextures, size) != size)
return nil; return nil;
#ifdef BIGENDIAN memLittle32(&numTextures);
numTextures = BSWAP32(numTextures);
#endif
texDict = RwTexDictionaryCreate(); texDict = RwTexDictionaryCreate();
if(texDict == nil) if(texDict == nil)
@ -120,9 +118,7 @@ RwTexDictionaryGtaStreamRead1(RwStream *stream)
if(RwStreamRead(stream, &numTextures, size) != size) if(RwStreamRead(stream, &numTextures, size) != size)
return nil; return nil;
#ifdef BIGENDIAN memLittle32(&numTextures);
numTextures = BSWAP32(numTextures);
#endif
texDict = RwTexDictionaryCreate(); texDict = RwTexDictionaryCreate();
if(texDict == nil) if(texDict == nil)

View File

@ -70,7 +70,6 @@ CText::Load(void)
type[3] = filedata[offset++]; type[3] = filedata[offset++];
sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 | sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 |
(int)filedata[offset+1]<<8 | (int)filedata[offset+0]; (int)filedata[offset+1]<<8 | (int)filedata[offset+0];
offset += 4; offset += 4;
if(sectlen != 0){ if(sectlen != 0){
if(strncmp(type, "TKEY", 4) == 0) if(strncmp(type, "TKEY", 4) == 0)
@ -192,7 +191,7 @@ CKeyArray::Load(size_t length, uint8 *data, ssize_t *offset)
#ifdef BIGENDIAN #ifdef BIGENDIAN
for (i = 0; i < numEntries; i++) for (i = 0; i < numEntries; i++)
entries[i].valueOffset = BSWAP32(entries[i].valueOffset); memLittle32(&entries[i].valueOffset);
#endif #endif
} }
@ -277,7 +276,7 @@ CData::Load(size_t length, uint8 *data, ssize_t *offset)
#ifdef BIGENDIAN #ifdef BIGENDIAN
for (i = 0; i < numChars; i++) for (i = 0; i < numChars; i++)
chars[i] = BSWAP16(chars[i]); memLittle16(&chars[i]);
#endif #endif
} }