mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
a slight oopsie on the location of WriteFloat and friends :P plus nq is now
endian/size clean.
This commit is contained in:
parent
39872aad5b
commit
c350bb2b1b
4 changed files with 106 additions and 102 deletions
|
@ -66,6 +66,18 @@ int LongNoSwap (int l);
|
|||
float FloatSwap (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
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/qtypes.h"
|
||||
#include "QF/vfile.h"
|
||||
|
||||
/*
|
||||
BYTE ORDER FUNCTIONS
|
||||
|
@ -117,3 +118,86 @@ FloatNoSwap (float 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];
|
||||
}
|
||||
|
|
|
@ -39,15 +39,16 @@
|
|||
|
||||
#include "QF/qendian.h"
|
||||
#include "QF/va.h"
|
||||
#include "host.h"
|
||||
#include "QF/msg.h"
|
||||
#include "client.h"
|
||||
#include "compat.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/console.h"
|
||||
#include "QF/cmd.h"
|
||||
#include "QF/keys.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "compat.h"
|
||||
#include "host.h"
|
||||
|
||||
void CL_FinishTimeDemo (void);
|
||||
|
||||
/*
|
||||
|
@ -90,16 +91,11 @@ CL_StopPlayback (void)
|
|||
void
|
||||
CL_WriteDemoMessage (void)
|
||||
{
|
||||
int len;
|
||||
int i;
|
||||
float f;
|
||||
|
||||
len = LittleLong (net_message->message->cursize);
|
||||
Qwrite (cls.demofile, &len, 4);
|
||||
for (i = 0; i < 3; i++) {
|
||||
f = LittleFloat (cl.viewangles[i]);
|
||||
Qwrite (cls.demofile, &f, 4);
|
||||
}
|
||||
WriteLong (cls.demofile, net_message->message->cursize);
|
||||
for (i = 0; i < 3; i++)
|
||||
WriteFloat (cls.demofile, cl.viewangles[i]);
|
||||
Qwrite (cls.demofile, net_message->message->data,
|
||||
net_message->message->cursize);
|
||||
Qflush (cls.demofile);
|
||||
|
@ -115,7 +111,6 @@ int
|
|||
CL_GetMessage (void)
|
||||
{
|
||||
int r, i;
|
||||
float f;
|
||||
|
||||
if (cls.demoplayback) {
|
||||
// decide if it is time to grab the next message
|
||||
|
@ -134,15 +129,11 @@ CL_GetMessage (void)
|
|||
}
|
||||
}
|
||||
// get the next message
|
||||
Qread (cls.demofile, &net_message->message->cursize, 4);
|
||||
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
|
||||
for (i = 0; i < 3; i++) {
|
||||
r = Qread (cls.demofile, &f, 4);
|
||||
cl.mviewangles[0][i] = LittleFloat (f);
|
||||
}
|
||||
net_message->message->cursize = ReadLong (cls.demofile);
|
||||
for (i = 0; i < 3; i++)
|
||||
cl.mviewangles[0][i] = ReadFloat (cls.demofile);
|
||||
|
||||
net_message->message->cursize =
|
||||
LittleLong (net_message->message->cursize);
|
||||
if (net_message->message->cursize > MAX_MSGLEN)
|
||||
Sys_Error ("Demo message > MAX_MSGLEN");
|
||||
r =
|
||||
|
|
|
@ -52,89 +52,6 @@
|
|||
void CL_FinishTimeDemo (void);
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue