]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
Fixed some of the mess. Might work now...
[xonotic/darkplaces.git] / common.c
index ed4e4a7212b34d46827ec90d8c94d395504f8b6e..e31b48d7605b8d089bd2c87dc3d472e9806ce31f 100644 (file)
--- a/common.c
+++ b/common.c
@@ -585,12 +585,21 @@ void MSG_WriteString (sizebuf_t *sb, char *s)
 
 void MSG_WriteCoord (sizebuf_t *sb, float f)
 {
-       MSG_WriteShort (sb, (int)(f*8));
+       if (dpprotocol)
+               MSG_WriteFloat(sb, f);
+       else
+               MSG_WriteShort (sb, (int)(f*8.0f + 0.5f));
+}
+
+void MSG_WritePreciseAngle (sizebuf_t *sb, float f)
+{
+       MSG_WriteShort (sb, (int)(f*(65536.0f/360.0f) + 0.5f) & 65535);
 }
 
+// LordHavoc: round to nearest value, rather than rounding down, fixes crosshair problem
 void MSG_WriteAngle (sizebuf_t *sb, float f)
 {
-       MSG_WriteByte (sb, ((int)f*256/360) & 255);
+       MSG_WriteByte (sb, (int)(f*(256.0f/360.0f) + 0.5f) & 255);
 }
 
 //
@@ -722,6 +731,14 @@ char *MSG_ReadString (void)
        return string;
 }
 
+float MSG_ReadCoord (void)
+{
+       if (dpprotocol)
+               return MSG_ReadFloat();
+       else
+               return MSG_ReadShort() * (1.0f/8.0f);
+}
+
 /*
 float MSG_ReadCoord (void)
 {
@@ -732,8 +749,12 @@ float MSG_ReadAngle (void)
 {
        return MSG_ReadChar() * (360.0f/256.0f);
 }
-*/
 
+float MSG_ReadPreciseAngle (void)
+{
+       return MSG_ReadShort() * (360.0f/65536);
+}
+*/
 
 
 //===========================================================================
@@ -1262,7 +1283,7 @@ typedef struct
        int             dirlen;
 } dpackheader_t;
 
-// LordHavoc: was 2048
+// LordHavoc: was 2048, increased to 16384 and changed info[MAX_PACK_FILES] to a temporary malloc to avoid stack overflows
 #define MAX_FILES_IN_PACK       16384
 
 char    com_cachedir[MAX_OSPATH];
@@ -1661,7 +1682,8 @@ pack_t *COM_LoadPackFile (char *packfile)
        int                             numpackfiles;
        pack_t                  *pack;
        int                             packhandle;
-       dpackfile_t             info[MAX_FILES_IN_PACK];
+       // LordHavoc: changed from stack array to temporary malloc, allowing huge pack directories
+       dpackfile_t             *info;
        unsigned short          crc;
 
        if (Sys_FileOpenRead (packfile, &packhandle) == -1)
@@ -1686,6 +1708,7 @@ pack_t *COM_LoadPackFile (char *packfile)
 
        newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile");
 
+       info = malloc(sizeof(*info)*MAX_FILES_IN_PACK);
        Sys_FileSeek (packhandle, header.dirofs);
        Sys_FileRead (packhandle, (void *)info, header.dirlen);
 
@@ -1705,6 +1728,7 @@ pack_t *COM_LoadPackFile (char *packfile)
                newfiles[i].filepos = LittleLong(info[i].filepos);
                newfiles[i].filelen = LittleLong(info[i].filelen);
        }
+       free(info);
 
        pack = Hunk_Alloc (sizeof (pack_t));
        strcpy (pack->filename, packfile);