From 7297ebcaf635b2e41d163d630b32c90df4798e0a Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Thu, 14 Jan 2021 12:25:22 +0100 Subject: [PATCH] Fix fonts on Big Endian systems, fixes #148 The code used #ifdef __ppc__, probably a leftover from old Mac support, which apparently doesn't work on all PPC systems (maybe not 64bit PPC). Now using the LittleFloat() function instead which exists for exactly this purpose and already handles endianess properly. --- neo/renderer/tr_font.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/neo/renderer/tr_font.cpp b/neo/renderer/tr_font.cpp index f841b5b9..7a5f08be 100644 --- a/neo/renderer/tr_font.cpp +++ b/neo/renderer/tr_font.cpp @@ -246,31 +246,16 @@ int readInt( void ) { return i; } -typedef union { - byte fred[4]; - float ffred; -} poor; - /* ============ readFloat ============ */ float readFloat( void ) { - poor me; -#ifdef __ppc__ - me.fred[0] = fdFile[fdOffset+3]; - me.fred[1] = fdFile[fdOffset+2]; - me.fred[2] = fdFile[fdOffset+1]; - me.fred[3] = fdFile[fdOffset+0]; -#else - me.fred[0] = fdFile[fdOffset+0]; - me.fred[1] = fdFile[fdOffset+1]; - me.fred[2] = fdFile[fdOffset+2]; - me.fred[3] = fdFile[fdOffset+3]; -#endif - fdOffset += 4; - return me.ffred; + float f; + memcpy(&f, &fdFile[fdOffset], sizeof(float)); + fdOffset += sizeof(float); + return LittleFloat(f); } /* @@ -312,6 +297,7 @@ bool idRenderSystemLocal::RegisterFont( const char *fontName, fontInfoEx_t &font } } */ + assert(sizeof(float) == 4 && "if this is false, readFloat() won't work"); memset( &font, 0, sizeof( font ) );