rendered paste body? Makefile
? Makefile.in
? aclocal.m4
? autom4te.cache
? config.guess
? config.log
? config.status
? config.sub
? configure
? depcomp
? install-sh
? missing
? mkinstalldirs
? bin/Makefile
? bin/Makefile.in
? bin/xmoto.bin
? src/.deps
? src/Makefile
? src/Makefile.in
? src/xmoto
? src/xmoto-edit
Index: configure.in
===================================================================
RCS file: /cvsroot/xmoto/xmoto/configure.in,v
retrieving revision 1.31
diff -a -u -r1.31 configure.in
--- configure.in 29 Jul 2006 21:17:18 -0000 1.31
+++ configure.in 9 Aug 2006 06:26:11 -0000
@@ -6,14 +6,20 @@
AC_PROG_CC
AC_PROG_CXX
+AC_PROG_CPP
AC_PROG_INSTALL
+AC_C_BIGENDIAN(AC_DEFINE([XMOTO_BIG_ENDIAN]),
+ AC_DEFINE([XMOTO_LITTLE_ENDIAN]))
+
+dnl libz before png!
+AC_CHECK_LIB(z, uncompress, [], [AC_MSG_ERROR(zlib required)])
+
AC_CHECK_LIB(jpeg, jpeg_CreateCompress, [], [AC_MSG_ERROR(libjpeg required)])
AC_CHECK_LIB(png, png_read_image, [], [AC_MSG_ERROR(libpng required)])
-AC_CHECK_LIB(z, uncompress, [], [AC_MSG_ERROR(zlib required)])
AC_CHECK_LIB(bz2, BZ2_bzReadOpen, [], [AC_MSG_ERROR(libbz2 required)])
AM_PATH_SDL(1.0.0, [], [AC_MSG_ERROR(SDL required)])
-AC_CHECK_LIB(SDL_mixer, Mix_OpenAudio, [], [AC_MSG_ERROR(SDL_mixer required)])
+AC_SDL_CHECK_LIB(SDL_mixer, Mix_OpenAudio, [], [AC_MSG_ERROR(SDL_mixer required)])
AX_CHECK_GL()
AC_SEARCH_LIBS(lua_pushboolean,lua lua5.1 lua50, [], [AC_MSG_ERROR(liblua5.1, liblua50, or liblua required)])
@@ -42,8 +48,19 @@
AC_CHECK_HEADER(lualib.h,AC_DEFINE(HAVE_LUALIB_H),[])
dnl AC_SEARCH_LIBS(dJointAttach,ode ode0, [], [AC_MSG_ERROR(libode or libode0 required)])
+AC_LANG_PUSH([C++])
AC_SEARCH_LIBS(dJointAttach,ode ode0, [], [AC_MSG_ERROR(libode or libode0 required)], -lstdc++)
+AC_LANG_POP()
AC_CHECK_LIB(curl, curl_easy_init,[],[AC_MSG_WARN(online highscores disabled)])
+dnl Put GAMEDATADIR in makefiles
+AC_ARG_WITH([gamedatadir],
+ [AS_HELP_STRING([--with-gamedatadir=DIR],
+ [Override the default directory for game data])],
+ [GAMEDATADIR="$withval"],
+ [GAMEDATADIR="$datadir/$PACKAGE"]
+)
+AC_SUBST([GAMEDATADIR])
+
AC_OUTPUT(Makefile bin/Makefile src/Makefile)
Index: config/sdl.m4
===================================================================
RCS file: /cvsroot/xmoto/xmoto/config/sdl.m4,v
retrieving revision 1.1
diff -a -u -r1.1 sdl.m4
--- config/sdl.m4 1 Feb 2006 19:01:56 -0000 1.1
+++ config/sdl.m4 9 Aug 2006 06:26:12 -0000
@@ -18,6 +18,10 @@
sdl_exec_prefix="$withval", sdl_exec_prefix="")
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
, enable_sdltest=yes)
+AC_ARG_WITH([sdl-framework],
+ [AS_HELP_STRING([--with-sdl-framework],[use SDL.framework on Mac OS X])],
+ sdl_framework="$withval")
+
if test x$sdl_exec_prefix != x ; then
sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
@@ -33,23 +37,67 @@
fi
AC_REQUIRE([AC_CANONICAL_TARGET])
- PATH="$prefix/bin:$prefix/usr/bin:$PATH"
- AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
- min_sdl_version=ifelse([$1], ,0.11.0,$1)
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
+ min_sdl_version=ifelse([$1], ,0.11.0,$1)
no_sdl=""
- if test "$SDL_CONFIG" = "no" ; then
- no_sdl=yes
+
+ if test "x$sdl_framework" != x; then
+ AC_DEFINE([HAVE_SDL_FRAMEWORK], [1], [Use SDL.framework on Mac OS X])
+ if test "x$sdl_framework" = xyes; then
+dnl No arg, look for it in standard locations
+ sdl_framework=""
+ for dir in "$HOME/Library" /Library; do
+ framework="$dir/Frameworks/SDL.framework"
+ if test -d "$framework"; then
+ sdl_framework="$framework"
+ fi
+ done
+ else
+dnl Arg given
+ if test -d "$sdl_framework"; then
+ :
+ else
+ sdl_framework=""
+ fi
+ fi
+
+dnl Did we find something?
+ if test "x$sdl_framework" = x; then
+ AC_MSG_ERROR([No SDL.framework could be found!])
+ fi
+dnl Where to look for other frameworks
+ sdl_framework_dir=`dirname "$sdl_framework"`
+ SDL_CFLAGS="-I$sdl_framework/Headers"
+dnl Gotta make sure SDLmain is around!
+ SDL_LIBS="$sdl_framework/SDL -framework Cocoa -lSDLmain"
+
+dnl Set the version vars
+ AC_REQUIRE([AC_PROG_CPP])
+ sdl_major_version=`echo SDL_MAJOR_VERSION | \
+ $CPP - $CPPFLAGS $SDL_CFLAGS -P -imacros SDL.h`
+ sdl_minor_version=`echo SDL_MINOR_VERSION | \
+ $CPP - $CPPFLAGS $SDL_CFLAGS -P -imacros SDL.h`
+ sdl_micro_version=`echo SDL_PATCHLEVEL | \
+ $CPP - $CPPFLAGS $SDL_CFLAGS -P -imacros SDL.h`
else
- SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
- SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
-
- sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
- sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
- sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
- sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+dnl Not framework
+ PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
+ if test "$SDL_CONFIG" = "no" ; then
+ no_sdl=yes
+ else
+ SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
+ SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
+ sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+ sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+ sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+ fi
+ fi
+
+ if test "x$no_sdl" = x; then
if test "x$enable_sdltest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_CXXFLAGS="$CXXFLAGS"
@@ -178,3 +226,25 @@
AC_SUBST(SDL_LIBS)
rm -f conf.sdltest
])
+
+dnl Check if a SDL lib is available
+AC_DEFUN([AC_SDL_CHECK_LIB],[
+ if test "x$sdl_framework_dir" != x; then
+ CPPFLAGS="$CPPFLAGS -I$sdl_framework_dir/$1.framework/Headers"
+ LIBS="$LIBS $sdl_framework_dir/$1.framework/$1"
+
+ ac_save_CFLAGS="$CFLAGS"
+ ac_save_LIBS="$LIBS"
+ LIBS="$LIBS $SDL_LIBS"
+ CFLAGS="$CFLAGS $SDL_CFLAGS"
+
+ AC_MSG_CHECKING([for $1])
+ AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],[$3],[$4])
+ AC_MSG_RESULT([yes])
+
+ LIBS="$ac_save_LIBS"
+ CFLAGS="$ac_save_CFLAGS"
+ else
+ AC_CHECK_LIB($@)
+ fi
+])
Index: src/DBuffer.cpp
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/DBuffer.cpp,v
retrieving revision 1.4
diff -a -u -r1.4 DBuffer.cpp
--- src/DBuffer.cpp 30 Jul 2006 10:48:21 -0000 1.4
+++ src/DBuffer.cpp 9 Aug 2006 06:26:12 -0000
@@ -23,6 +23,8 @@
* Generic data buffer stuff.
*/
#include "DBuffer.h"
+#include "arch/SwapEndian.h"
+#include <algorithm>
namespace vapp {
@@ -53,7 +55,8 @@
m_bOwnData = false;
}
- void DBuffer::writeBuf(const char *pcBuf,int nBufSize) {
+ template <typename _ConstIter>
+ void DBuffer::writeBuf(_ConstIter pcBuf,int nBufSize) {
if(isOutput() && nBufSize > 0) {
/* Start writing into the part */
int nToWrite = nBufSize,i = 0;
@@ -73,13 +76,27 @@
int nWrite = nRem < nBufSize-i ? nRem : nBufSize-i;
/* Write it */
- memcpy(&m_Parts[m_nCurPart]->pcBuffer[m_Parts[m_nCurPart]->nPtr],&pcBuf[i],nWrite);
+ std::copy(pcBuf, pcBuf + nWrite,
+ &m_Parts[m_nCurPart]->pcBuffer[m_Parts[m_nCurPart]->nPtr]);
+ pcBuf += nWrite;
i += nWrite;
m_Parts[m_nCurPart]->nPtr += nWrite;
nToWrite -= nWrite;
}
}
}
+
+ // Instantiations
+ template void DBuffer::writeBuf(const char *, int);
+ template void DBuffer::writeBuf(char *, int);
+
+ void DBuffer::writeBuf_LE(const char *pcBuf,int nBufSize) {
+ if (SwapEndian::bigendien) {
+ writeBuf(std::reverse_iterator<const char *>(pcBuf + nBufSize), nBufSize);
+ } else {
+ writeBuf(pcBuf, nBufSize);
+ }
+ }
void DBuffer::_NewPart(void) {
DBufferPart *p = new DBufferPart;
@@ -89,21 +106,30 @@
m_Parts.push_back( p );
}
- void DBuffer::readBuf(char *pcBuf,int nBufSize) {
+ template <typename _Iter>
+ void DBuffer::readBuf(_Iter pcBuf,int nBufSize) {
if(isInput() && nBufSize > 0) {
/* Remaining in input buffer? */
if(m_nSize - m_nReadPtr < nBufSize) {
/* TODO: error */
- memset(pcBuf,0,nBufSize);
+ std::fill_n(pcBuf, nBufSize, 0);
}
else {
/* Read and advance ptr */
- memcpy(pcBuf,&m_pcData[m_nReadPtr],nBufSize);
+ std::copy(&m_pcData[m_nReadPtr], &m_pcData[m_nReadPtr] + nBufSize,
+ pcBuf);
m_nReadPtr += nBufSize;
}
}
}
+ // Instantiations
+ template void DBuffer::readBuf(char *, int);
+
+ void DBuffer::readBuf_LE(char *pcBuf,int nBufSize) {
+ readBuf(SwapEndian::LittleIter(pcBuf, nBufSize), nBufSize);
+ }
+
int DBuffer::numRemainingBytes(void) {
if(isInput()) {
return m_nSize - m_nReadPtr;
Index: src/DBuffer.h
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/DBuffer.h,v
retrieving revision 1.3
diff -a -u -r1.3 DBuffer.h
--- src/DBuffer.h 30 Jul 2006 10:48:21 -0000 1.3
+++ src/DBuffer.h 9 Aug 2006 06:26:12 -0000
@@ -49,18 +49,25 @@
/* Methods */
void initOutput(int nPartSize);
void initInput(char *pcInput,int nInputSize);
- void writeBuf(const char *pcBuf,int nBufSize);
- void readBuf(char *pcBuf,int nBufSize);
+
+ template<typename _ConstIter>
+ void writeBuf(_ConstIter pcBuf,int nBufSize);
+
+ template<typename _Iter>
+ void readBuf(_Iter pcBuf,int nBufSize);
+
+ void writeBuf_LE(const char *pcBuf,int nBufSize);
+ void readBuf_LE(char *pcBuf,int nBufSize);
int numRemainingBytes(void);
const char *convertOutputToInput(void);
/* Some I/O */
template<typename _T> void operator <<(_T n) {
- writeBuf(reinterpret_cast<const char *>(&n),sizeof(_T));
+ writeBuf_LE(reinterpret_cast<const char *>(&n),sizeof(_T));
}
template<typename _T> void operator >>(_T &n) {
- readBuf(reinterpret_cast<char *>(&n),sizeof(_T));
+ readBuf_LE(reinterpret_cast<char *>(&n),sizeof(_T));
}
/* Data interface */
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/Makefile.am,v
retrieving revision 1.9
diff -a -u -r1.9 Makefile.am
--- src/Makefile.am 30 Jul 2006 11:12:25 -0000 1.9
+++ src/Makefile.am 9 Aug 2006 06:26:12 -0000
@@ -2,9 +2,9 @@
WANTED_WARNNING= -pedantic -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wfloat-equal -Wformat -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimplicit -Wimport -Wuninitialized -Winline -Wlong-long -Wmissing-braces -Wmissing-format-attribute -Wmissing-noreturn -Wpacked -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wwrite-strings
# -Wunreachable-code
-AM_CXXFLAGS = -DNOMMGR $(WANTED_WARNNING) -DGAMEDATADIR=\"$(datadir)/@PACKAGE@\" $(GL_CFLAGS)
-AM_CFLAGS = -DNOMMGR $(WANTED_WARNNING) -DGAMEDATADIR=\"$(datadir)/@PACKAGE@\" $(GL_CFLAGS)
-AM_LDFLAGS = -s
+AM_CXXFLAGS = -DNOMMGR $(WANTED_WARNNING) -DGAMEDATADIR=\"$(GAMEDATADIR)\" $(GL_CFLAGS) $(SDL_CFLAGS)
+AM_CFLAGS = -DNOMMGR $(WANTED_WARNNING) -DGAMEDATADIR=\"$(GAMEDATADIR)\" $(GL_CFLAGS) $(SDL_CFLAGS)
+AM_LDFLAGS =
image_SOURCES = image/tim.cpp image/tim_io_stdio.cpp \
image/tim_jpeg.cpp image/tim_memory_crt.cpp \
@@ -43,7 +43,7 @@
WWW.h \
WWWAppInterface.h
-common_LDADD = $(GL_LIBS)
+common_LDADD = $(GL_LIBS) $(SDL_LIBS)
bin_PROGRAMS = xmoto xmoto-edit
Index: src/RendererFBO.cpp
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/RendererFBO.cpp,v
retrieving revision 1.4
diff -a -u -r1.4 RendererFBO.cpp
--- src/RendererFBO.cpp 30 Jul 2006 10:48:21 -0000 1.4
+++ src/RendererFBO.cpp 9 Aug 2006 06:26:12 -0000
@@ -75,16 +75,19 @@
m_pApp->glLinkProgramARB(m_ProgramID);
int nStatus = 0;
- m_pApp->glGetObjectParameterivARB(m_ProgramID,GL_OBJECT_LINK_STATUS_ARB,&nStatus);
+ m_pApp->glGetObjectParameterivARB(m_ProgramID,
+ GL_OBJECT_LINK_STATUS_ARB,(GLint*)&nStatus);
if(!nStatus) {
Log("-- Failed to link SFXOverlay shader program --");
/* Retrieve info-log */
int nInfoLogLen = 0;
- m_pApp->glGetObjectParameterivARB(m_ProgramID,GL_OBJECT_INFO_LOG_LENGTH_ARB,&nInfoLogLen);
+ m_pApp->glGetObjectParameterivARB(m_ProgramID,
+ GL_OBJECT_INFO_LOG_LENGTH_ARB,(GLint*)&nInfoLogLen);
char *pcInfoLog = new char[nInfoLogLen];
int nCharsWritten = 0;
- m_pApp->glGetInfoLogARB(m_ProgramID,nInfoLogLen,&nCharsWritten,pcInfoLog);
+ m_pApp->glGetInfoLogARB(m_ProgramID,nInfoLogLen,
+ (GLsizei*)&nCharsWritten,pcInfoLog);
LogRaw(pcInfoLog);
delete [] pcInfoLog;
@@ -175,17 +178,20 @@
/* Compile it! */
m_pApp->glCompileShaderARB(ShaderID);
int nStatus = 0;
- m_pApp->glGetObjectParameterivARB(ShaderID,GL_OBJECT_COMPILE_STATUS_ARB,&nStatus);
+ m_pApp->glGetObjectParameterivARB(ShaderID,
+ GL_OBJECT_COMPILE_STATUS_ARB,(GLint*)&nStatus);
if(!nStatus) {
_FreeShaderSource(ppc,nNumLines);
Log("-- Failed to compile shader: %s --",File.c_str());
/* Retrieve info-log */
int nInfoLogLen = 0;
- m_pApp->glGetObjectParameterivARB(ShaderID,GL_OBJECT_INFO_LOG_LENGTH_ARB,&nInfoLogLen);
+ m_pApp->glGetObjectParameterivARB(ShaderID,
+ GL_OBJECT_INFO_LOG_LENGTH_ARB,(GLint*)&nInfoLogLen);
char *pcInfoLog = new char[nInfoLogLen];
int nCharsWritten = 0;
- m_pApp->glGetInfoLogARB(ShaderID,nInfoLogLen,&nCharsWritten,pcInfoLog);
+ m_pApp->glGetInfoLogARB(ShaderID,nInfoLogLen,
+ (GLsizei*)&nCharsWritten,pcInfoLog);
LogRaw(pcInfoLog);
delete [] pcInfoLog;
Index: src/Replay.cpp
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/Replay.cpp,v
retrieving revision 1.33
diff -a -u -r1.33 Replay.cpp
--- src/Replay.cpp 30 Jul 2006 10:48:21 -0000 1.33
+++ src/Replay.cpp 9 Aug 2006 06:26:12 -0000
@@ -34,6 +34,8 @@
#include <iostream>
#include <locale>
+#include <arch/SwapEndian.h>
+
namespace vapp {
bool Replay::m_bEnableCompression = true;
@@ -203,7 +205,7 @@
}
else {
/* Little/big endian safety check */
- if(FS::readInt(pfh) != 0x12345678) {
+ if(FS::readInt_LE(pfh) != 0x12345678) {
FS::closeFile(pfh);
Log("** Warning ** : Sorry, the replay you're trying to open are not endian-compatible with your computer!");
return "";
@@ -216,26 +218,26 @@
Player = m_PlayerName = FS::readString(pfh);
/* Read replay frame rate */
- m_fFrameRate = FS::readFloat(pfh);
+ m_fFrameRate = FS::readFloat_LE(pfh);
if(pfFrameRate != NULL) *pfFrameRate = m_fFrameRate;
/* Read state size */
- m_nStateSize = FS::readInt(pfh);
+ m_nStateSize = FS::readInt_LE(pfh);
/* Read finish time if any */
m_bFinished = FS::readBool(pfh);
- m_fFinishTime = FS::readFloat(pfh);
+ m_fFinishTime = FS::readFloat_LE(pfh);
/* Version 1 includes event data */
if(nVersion == 1) {
/* Read uncompressed size */
- m_nInputEventsDataSize = FS::readInt(pfh);
+ m_nInputEventsDataSize = FS::readInt_LE(pfh);
m_pcInputEventsData = new char [m_nInputEventsDataSize];
/* Compressed? */
if(FS::readBool(pfh)) {
/* Compressed */
- int nCompressedEventsSize = FS::readInt(pfh);
+ int nCompressedEventsSize = FS::readInt_LE(pfh);
char *pcCompressedEvents = new char [nCompressedEventsSize];
FS::readBuf(pfh,pcCompressedEvents,nCompressedEventsSize);
@@ -266,16 +268,16 @@
}
/* Read chunks */
- int nNumChunks = FS::readInt(pfh);
+ int nNumChunks = FS::readInt_LE(pfh);
for(int i=0;i<nNumChunks;i++) {
ReplayStateChunk Chunk;
- Chunk.nNumStates = FS::readInt(pfh);
+ Chunk.nNumStates = FS::readInt_LE(pfh);
Chunk.pcChunkData = new char [Chunk.nNumStates * m_nStateSize];
/* Compressed or not compressed? */
if(FS::readBool(pfh)) {
/* Compressed! - read compressed size */
- int nCompressedSize = FS::readInt(pfh);
+ int nCompressedSize = FS::readInt_LE(pfh);
/* Read compressed data */
unsigned char *pcCompressed = new unsigned char [nCompressedSize];
@@ -414,6 +416,7 @@
memcpy(pcState,
&m_Chunks[m_nCurChunk].pcChunkData[((int)m_nCurState)*m_nStateSize],
m_nStateSize);
+ SwapEndian::LittleSerializedBikeState(*(SerializedBikeState*)pcState);
}
//std::vector<ReplayInfo *> Replay::createReplayList(const std::string &PlayerName,const std::string &LevelIDCheck) {
@@ -558,17 +561,17 @@
return NULL;
}
- if(FS::readInt(pfh) != 0x12345678) {
+ if(FS::readInt_LE(pfh) != 0x12345678) {
FS::closeFile(pfh);
return NULL;
}
std::string LevelID = FS::readString(pfh);
std::string Player = FS::readString(pfh);
- float fFrameRate = FS::readFloat(pfh);
- int nStateSize = FS::readInt(pfh);
+ float fFrameRate = FS::readFloat_LE(pfh);
+ int nStateSize = FS::readInt_LE(pfh);
bool bFinished = FS::readBool(pfh);
- float fFinishTime = FS::readFloat(pfh);
+ float fFinishTime = FS::readFloat_LE(pfh);
ReplayInfo *pRpl = new ReplayInfo;
int nTimeStamp = FS::getFileTimeStamp("Replays/" + p_ReplayName + ".rpl");
Index: src/VCommon.h
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/VCommon.h,v
retrieving revision 1.21
diff -a -u -r1.21 VCommon.h
--- src/VCommon.h 30 Jul 2006 10:16:08 -0000 1.21
+++ src/VCommon.h 9 Aug 2006 06:26:12 -0000
@@ -37,15 +37,23 @@
#include <stddef.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_mixer.h>
+#ifdef HAVE_SDL_FRAMEWORK
+ #include <SDL.h>
+ #include <SDL_mixer.h>
+#else
+ #include <SDL/SDL.h>
+ #include <SDL/SDL_mixer.h>
+#endif
+
+// Some places #define _T, which we want for a template parameter
+#undef _T
/* Pull in OpenGL headers */
//#define NO_SDL_GLEXT
//#include <SDL/SDL_opengl.h>
/* following scissored from SDL_opengl.h */
#define __glext_h_ /* Don't let gl.h include glext.h */
-#if defined(__MACOSX__)
+#ifdef HAVE_APPLE_OPENGL_FRAMEWORK
#include <OpenGL/gl.h> /* Header File For The OpenGL Library */
#include <OpenGL/glu.h> /* Header File For The GLU Library */
#elif defined(__MACOS__)
@@ -72,9 +80,9 @@
#include <endian.h>
#endif
-#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
+#if !defined(XMOTO_LITTLE_ENDIAN) && !defined(XMOTO_BIG_ENDIAN)
/* Assume little endian */
- #define LITTLE_ENDIAN
+ #define XMOTO_LITTLE_ENDIAN 1
#endif
extern "C" {
Index: src/VFileIO.cpp
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/VFileIO.cpp,v
retrieving revision 1.27
diff -a -u -r1.27 VFileIO.cpp
--- src/VFileIO.cpp 30 Jul 2006 10:48:22 -0000 1.27
+++ src/VFileIO.cpp 9 Aug 2006 06:26:12 -0000
@@ -636,17 +636,16 @@
std::string FS::readLongString(FileHandle *pfh) {
unsigned short v;
- v=readShort(pfh);
+ v=readShort_LE(pfh);
char cBuf[65536];
if(!readBuf(pfh,(char *)cBuf,v)) _ThrowFileError(pfh,"readLongString -> failed");
cBuf[v] = '\0';
return std::string(cBuf);
}
+ // We use one-byte bools
bool FS::readBool(FileHandle *pfh) {
- bool v;
- if(!readBuf(pfh,(char *)&v,sizeof(v))) _ThrowFileError(pfh,"readBool -> failed");
- return v;
+ return static_cast<bool>(readByte(pfh));
}
void FS::writeByte(FileHandle *pfh,unsigned char v) {
@@ -675,12 +674,12 @@
}
void FS::writeLongString(FileHandle *pfh,std::string v) {
- writeShort(pfh,v.length());
+ writeShort_LE(pfh,v.length());
if(!writeBuf(pfh,(char *)v.c_str(),v.length())) _ThrowFileError(pfh,"writeLongString -> failed");
}
void FS::writeBool(FileHandle *pfh,bool v) {
- if(!writeBuf(pfh,(char *)&v,sizeof(v))) _ThrowFileError(pfh,"writeBool -> failed");
+ writeByte(pfh,static_cast<unsigned char>(v));
}
void FS::writeLine(FileHandle *pfh,std::string Line) {
@@ -1172,13 +1171,8 @@
}
float FS::readFloat_LE(FileHandle *pfh) {
- float res;
-
- unsigned char *pc=(unsigned char *)&res;
- for(int i=0;i<4;i++)
- pc[i]=readByte(pfh);
-
- return res;
+ float f = readFloat(pfh);
+ return SwapEndian::LittleFloat(f);
}
bool FS::isInUserDir(std::string p_filepath) {
Index: src/arch/SwapEndian.cpp
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/arch/SwapEndian.cpp,v
retrieving revision 1.3
diff -a -u -r1.3 SwapEndian.cpp
--- src/arch/SwapEndian.cpp 17 Jul 2006 20:11:41 -0000 1.3
+++ src/arch/SwapEndian.cpp 9 Aug 2006 06:26:12 -0000
@@ -1,69 +1,84 @@
// source From Quake2
#include "SwapEndian.h"
#include <stdlib.h>
+#include <algorithm>
+using vapp::SerializedBikeState;
typedef unsigned char byte;
-short ShortSwap (short s);
-short ShortNoSwap (short s);
-int LongSwap (int l);
-int LongNoSwap (int l);
-float FloatSwap (float f);
-float FloatNoSwap (float f);
-double DoubleSwap (double d);
-double DoubleNoSwap(double d);
-
-short ShortSwap(short l) {
- byte b1,b2;
- b1 = l&255;
- b2 = (l>>8)&255;
- return (b1<<8) + b2;
+static short ShortSwap (short s);
+static short ShortNoSwap (short s);
+static int LongSwap (int l);
+static int LongNoSwap (int l);
+static float FloatSwap (float f);
+static float FloatNoSwap (float f);
+static double DoubleSwap (double d);
+static double DoubleNoSwap(double d);
+static void SerializedBikeStateSwap (SerializedBikeState& sbs);
+static void SerializedBikeStateNoSwap(SerializedBikeState& sbs);
+
+
+// Generic endian swapping
+template <typename _T>
+static void SwapInPlace(_T& n) {
+ std::reverse(reinterpret_cast<byte*>(&n),
+ reinterpret_cast<byte*>(&n) + sizeof(_T));
+}
+
+template <typename _T>
+static _T SwapCopy(_T n) {
+ SwapInPlace(n);
+ return n;
+}
+
+
+static short ShortSwap(short l) {
+ return SwapCopy(l);
}
-short ShortNoSwap(short l) {
+static short ShortNoSwap(short l) {
return l;
}
-int LongSwap(int l) {
- byte b1,b2,b3,b4;
- b1 = l&255;
- b2 = (l>>8)&255;
- b3 = (l>>16)&255;
- b4 = (l>>24)&255;
- return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
+static int LongSwap(int l) {
+ return SwapCopy(l);
}
-int LongNoSwap(int l) {
+static int LongNoSwap(int l) {
return l;
}
-float FloatSwap(float f) {
- union {
- float f;
- byte b[4];
- } dat1, dat2;
-
- dat1.f = f;
- dat2.b[0] = dat1.b[3];
- dat2.b[1] = dat1.b[2];
- dat2.b[2] = dat1.b[1];
- dat2.b[3] = dat1.b[0];
- return dat2.f;
+static float FloatSwap(float f) {
+ return SwapCopy(f);
}
-float FloatNoSwap(float f) {
+static float FloatNoSwap(float f) {
return f;
}
-double DoubleSwap(double d) {
- /* TODO !!! */
- return d;
+static double DoubleSwap(double d) {
+ return SwapCopy(d);
}
-double DoubleNoSwap(double d) {
+static double DoubleNoSwap(double d) {
return d;
}
+static void SerializedBikeStateSwap (SerializedBikeState& sbs) {
+ SwapInPlace(sbs.fGameTime);
+ SwapInPlace(sbs.fFrameX);
+ SwapInPlace(sbs.fFrameY);
+ SwapInPlace(sbs.fMaxXDiff);
+ SwapInPlace(sbs.fMaxYDiff);
+ SwapInPlace(sbs.nRearWheelRot);
+ SwapInPlace(sbs.nFrontWheelRot);
+ SwapInPlace(sbs.nFrameRot);
+}
+
+static void SerializedBikeStateNoSwap(SerializedBikeState& sbs) {
+ // noop
+}
+
/*
================
Swap_Init
@@ -79,6 +94,10 @@
float (*SwapEndian::_LittleFloat) (float f) = NULL;
double (*SwapEndian::_BigDouble) (double d) = NULL;
double (*SwapEndian::_LittleDouble)(double d) = NULL;
+void (*SwapEndian::_BigSerializedBikeState) (SerializedBikeState& sbs)
+ = NULL;
+void (*SwapEndian::_LittleSerializedBikeState)(SerializedBikeState& sbs)
+ = NULL;
void SwapEndian::Swap_Init() {
byte swaptest[2] = {1,0};
@@ -94,6 +113,8 @@
_LittleFloat = FloatNoSwap;
_BigDouble = DoubleSwap;
_LittleDouble = DoubleNoSwap;
+ _BigSerializedBikeState = SerializedBikeStateSwap;
+ _LittleSerializedBikeState = SerializedBikeStateNoSwap;
} else {
bigendien = true;
_BigShort = ShortNoSwap;
@@ -104,5 +125,7 @@
_LittleFloat = FloatSwap;
_BigDouble = DoubleNoSwap;
_LittleDouble = DoubleSwap;
+ _BigSerializedBikeState = SerializedBikeStateNoSwap;
+ _LittleSerializedBikeState = SerializedBikeStateSwap;
}
}
Index: src/arch/SwapEndian.h
===================================================================
RCS file: /cvsroot/xmoto/xmoto/src/arch/SwapEndian.h,v
retrieving revision 1.2
diff -a -u -r1.2 SwapEndian.h
--- src/arch/SwapEndian.h 11 Jul 2006 22:46:17 -0000 1.2
+++ src/arch/SwapEndian.h 9 Aug 2006 06:26:12 -0000
@@ -1,6 +1,10 @@
#ifndef __SWAPENDIAN_H__
#define __SWAPENDIAN_H__
+#include <iterator>
+#include "VCommon.h" // For XMOTO_LITTLE_ENDIAN
+#include "MotoGame.h" // For SerializedBikeState
+
class SwapEndian {
public:
static bool bigendien;
@@ -16,6 +20,20 @@
static double BigDouble (double d) {return _BigDouble(d); }
static double LittleDouble(double d) {return _LittleDouble(d);}
+ static void BigSerializedBikeState (vapp::SerializedBikeState& sbs)
+ { _BigSerializedBikeState (sbs); }
+ static void LittleSerializedBikeState(vapp::SerializedBikeState& sbs)
+ { _LittleSerializedBikeState(sbs); }
+
+#ifdef XMOTO_LITTLE_ENDIAN
+ template <typename _T> static _T LittleIter(_T p, int) { return p; }
+#else
+ template <typename _T>
+ static std::reverse_iterator<_T> LittleIter(_T p, int len) {
+ return std::reverse_iterator<_T>(p + len);
+ }
+#endif
+
private:
static short (*_BigShort) (short s);
static short (*_LittleShort) (short s);
@@ -25,6 +43,8 @@
static float (*_LittleFloat) (float f);
static double (*_BigDouble) (double d);
static double (*_LittleDouble)(double d);
+ static void (*_BigSerializedBikeState) (vapp::SerializedBikeState& sbs);
+ static void (*_LittleSerializedBikeState)(vapp::SerializedBikeState& sbs);
};
#endif /* __SWAPENDIAN_H__ */