a slight oopsie on the location of WriteFloat and friends :P plus nq is now

endian/size clean.
This commit is contained in:
Bill Currie 2001-06-29 06:50:29 +00:00
parent 39872aad5b
commit c350bb2b1b
4 changed files with 106 additions and 102 deletions

View file

@ -66,6 +66,18 @@ int LongNoSwap (int l);
float FloatSwap (float f); float FloatSwap (float f);
float FloatNoSwap (float f); float FloatNoSwap (float f);
//NOTE: thes /always/ read and write /little/ endian entities.
struct VFile_s;
void WriteFloat (struct VFile_s *file, float f);
void WriteByte (struct VFile_s *file, int b);
void WriteShort (struct VFile_s *file, unsigned int s);
void WriteLong (struct VFile_s *file, unsigned int l);
float ReadFloat (struct VFile_s *file);
byte ReadByte (struct VFile_s *file);
unsigned short ReadShort (struct VFile_s *file);
unsigned long ReadLong (struct VFile_s *file);
//============================================================================ //============================================================================
#endif // __qendian_h #endif // __qendian_h

View file

@ -36,6 +36,7 @@
#include "QF/qendian.h" #include "QF/qendian.h"
#include "QF/qtypes.h" #include "QF/qtypes.h"
#include "QF/vfile.h"
/* /*
BYTE ORDER FUNCTIONS BYTE ORDER FUNCTIONS
@ -117,3 +118,86 @@ FloatNoSwap (float f)
{ {
return f; return f;
} }
void
WriteFloat (VFile *file, float f)
{
// a float in C is /defined/ to be 32 bits. byte order, can, of course
// still make a mess.
union {
float f;
byte b[4];
} dat;
dat.f = LittleFloat (f);
Qwrite (file, dat.b, sizeof (dat.b));
}
void
WriteByte (VFile *file, int b)
{
byte dat = b & 0xff;
Qwrite (file, &dat, 1);
}
void
WriteShort (VFile *file, unsigned int s)
{
byte dat[2];
dat[0] = s & 0xff;
dat[1] = (s >> 8) & 0xff;
Qwrite (file, dat, sizeof (dat));
}
void
WriteLong (VFile *file, unsigned int l)
{
byte dat[4];
dat[0] = l & 0xff;
dat[1] = (l >> 8) & 0xff;
dat[2] = (l >> 16) & 0xff;
dat[3] = (l >> 24) & 0xff;
Qwrite (file, dat, sizeof (dat));
}
float
ReadFloat (VFile *file)
{
// a float in C is /defined/ to be 32 bits. byte order, can, of course
// still make a mess.
union {
float f;
byte b[4];
} dat;
Qread (file, dat.b, sizeof (dat.b));
return LittleFloat (dat.f);
}
byte
ReadByte (VFile *file)
{
byte dat;
Qread (file, &dat, 1);
return dat;
}
unsigned short
ReadShort (VFile *file)
{
byte dat[2];
Qread (file, dat, sizeof (dat));
return (dat[1] << 8) | dat[0];
}
unsigned long
ReadLong (VFile *file)
{
byte dat[4];
Qread (file, dat, sizeof (dat));
return (dat[3] << 24) | (dat[2] << 16) | (dat[1] << 8) | dat[0];
}

View file

@ -39,15 +39,16 @@
#include "QF/qendian.h" #include "QF/qendian.h"
#include "QF/va.h" #include "QF/va.h"
#include "host.h"
#include "QF/msg.h" #include "QF/msg.h"
#include "client.h"
#include "compat.h"
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/console.h" #include "QF/console.h"
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/keys.h" #include "QF/keys.h"
#include "client.h"
#include "compat.h"
#include "host.h"
void CL_FinishTimeDemo (void); void CL_FinishTimeDemo (void);
/* /*
@ -90,16 +91,11 @@ CL_StopPlayback (void)
void void
CL_WriteDemoMessage (void) CL_WriteDemoMessage (void)
{ {
int len;
int i; int i;
float f;
len = LittleLong (net_message->message->cursize); WriteLong (cls.demofile, net_message->message->cursize);
Qwrite (cls.demofile, &len, 4); for (i = 0; i < 3; i++)
for (i = 0; i < 3; i++) { WriteFloat (cls.demofile, cl.viewangles[i]);
f = LittleFloat (cl.viewangles[i]);
Qwrite (cls.demofile, &f, 4);
}
Qwrite (cls.demofile, net_message->message->data, Qwrite (cls.demofile, net_message->message->data,
net_message->message->cursize); net_message->message->cursize);
Qflush (cls.demofile); Qflush (cls.demofile);
@ -115,7 +111,6 @@ int
CL_GetMessage (void) CL_GetMessage (void)
{ {
int r, i; int r, i;
float f;
if (cls.demoplayback) { if (cls.demoplayback) {
// decide if it is time to grab the next message // decide if it is time to grab the next message
@ -134,15 +129,11 @@ CL_GetMessage (void)
} }
} }
// get the next message // get the next message
Qread (cls.demofile, &net_message->message->cursize, 4);
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]); VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
for (i = 0; i < 3; i++) { net_message->message->cursize = ReadLong (cls.demofile);
r = Qread (cls.demofile, &f, 4); for (i = 0; i < 3; i++)
cl.mviewangles[0][i] = LittleFloat (f); cl.mviewangles[0][i] = ReadFloat (cls.demofile);
}
net_message->message->cursize =
LittleLong (net_message->message->cursize);
if (net_message->message->cursize > MAX_MSGLEN) if (net_message->message->cursize > MAX_MSGLEN)
Sys_Error ("Demo message > MAX_MSGLEN"); Sys_Error ("Demo message > MAX_MSGLEN");
r = r =

View file

@ -52,89 +52,6 @@
void CL_FinishTimeDemo (void); void CL_FinishTimeDemo (void);
int demotime_cached; int demotime_cached;
static void
WriteFloat (VFile *file, float f)
{
// a float in C is /defined/ to be 32 bits. byte order, can, of course
// still make a mess.
union {
float f;
byte b[4];
} dat;
dat.f = LittleFloat (f);
Qwrite (file, dat.b, sizeof (dat.b));
}
static void
WriteByte (VFile *file, int b)
{
byte dat = b & 0xff;
Qwrite (file, &dat, 1);
}
static void
WriteShort (VFile *file, unsigned int s)
{
byte dat[2];
dat[0] = s & 0xff;
dat[1] = (s >> 8) & 0xff;
Qwrite (file, dat, sizeof (dat));
}
static void
WriteLong (VFile *file, unsigned int l)
{
byte dat[4];
dat[0] = l & 0xff;
dat[1] = (l >> 8) & 0xff;
dat[2] = (l >> 16) & 0xff;
dat[3] = (l >> 24) & 0xff;
Qwrite (file, dat, sizeof (dat));
}
static float
ReadFloat (VFile *file)
{
// a float in C is /defined/ to be 32 bits. byte order, can, of course
// still make a mess.
union {
float f;
byte b[4];
} dat;
Qread (file, dat.b, sizeof (dat.b));
return LittleFloat (dat.f);
}
static byte
ReadByte (VFile *file)
{
byte dat;
Qread (file, &dat, 1);
return dat;
}
static unsigned short
ReadShort (VFile *file)
{
byte dat[2];
Qread (file, dat, sizeof (dat));
return (dat[1] << 8) | dat[0];
}
static unsigned long
ReadLong (VFile *file)
{
byte dat[4];
Qread (file, dat, sizeof (dat));
return (dat[3] << 24) | (dat[2] << 16) | (dat[1] << 8) | dat[0];
}
/* /*
DEMO CODE DEMO CODE