]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/bsploader.cpp
Merge commit 'af4e2d29cfd3a54b44eb09e4289f3fa3f29412c9' into garux-merge
[xonotic/netradiant.git] / contrib / bobtoolz / bsploader.cpp
index aadd2b31f81e3ccd9478c9cc77a523fd1285ceb9..0c442e16ce0f2258abac3775b662a62e1c235027 100644 (file)
@@ -1,7 +1,7 @@
-#include "StdAfx.h"
-#include "./dialogs/dialogs-gtk.h"
+#include <globaldefs.h>
 #include "bsploader.h"
-#include "../../libs/cmdlib.h"
+#include "dialogs/dialogs-gtk.h"
+#include "cmdlib.h"
 
 int numnodes;
 int numplanes;
@@ -25,9 +25,9 @@ dbrush_t          *dbrushes =             NULL;
 dbrushside_t    *dbrushsides =      NULL;
 int                 *dleafbrushes =     NULL;
 
-#define BSP_IDENT   ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' )
-#define Q3_BSP_VERSION          46
-#define WOLF_BSP_VERSION            47
+const int BSP_IDENT = ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' );
+const int Q3_BSP_VERSION = 46;
+const int WOLF_BSP_VERSION = 47;
 
 /*
    ================
@@ -51,7 +51,7 @@ int FileLength( FILE *f ){
    LoadFile
    ==============
  */
-qboolean    LoadFile( const char *filename, byte **bufferptr ){
+bool    LoadFile( const char *filename, byte **bufferptr ){
        FILE    *f;
        int length;
        byte    *buffer;
@@ -71,15 +71,19 @@ qboolean    LoadFile( const char *filename, byte **bufferptr ){
        return true;
 }
 
-/*int    LittleLong (int l)
-   {
-    return l;
-   }
+int    LittleLong( int l ){
+       if (GDEF_ARCH_ENDIAN_BIG) {
+               std::reverse(reinterpret_cast<unsigned char *>( &l ), reinterpret_cast<unsigned char *>( &l ) + sizeof(int));
+       }
+       return l;
+}
 
-   float       LittleFloat (float l)
-   {
-    return l;
-   }*/
+float   LittleFloat( float l ){
+       if (GDEF_ARCH_ENDIAN_BIG) {
+               std::reverse( reinterpret_cast<unsigned char*>( &l ), reinterpret_cast<unsigned char*>( &l ) + sizeof( float ) );
+       }
+       return l;
+}
 
 /*
    =============
@@ -194,7 +198,7 @@ int CopyLump( dheader_t *header, int lump, void **dest, int size ) {
    LoadBSPFile
    =============
  */
-qboolean    LoadBSPFile( const char *filename ) {
+bool    LoadBSPFile( const char *filename ) {
        dheader_t   *header;
 
        // load the file header
@@ -206,12 +210,12 @@ qboolean    LoadBSPFile( const char *filename ) {
        SwapBlock( (int *)header, sizeof( *header ) );
 
        if ( header->ident != BSP_IDENT ) {
-               DoMessageBox( "Cant find a valid IBSP file", "Error", MB_OK );
+               DoMessageBox( "Cant find a valid IBSP file", "Error", eMB_OK );
                return false;
        }
        if ( ( header->version != Q3_BSP_VERSION ) &&
                 ( header->version != WOLF_BSP_VERSION ) ) {
-               DoMessageBox( "File is incorrect version", "Error", MB_OK );
+               DoMessageBox( "File is incorrect version", "Error", eMB_OK );
                return false;
        }