]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
broke rtlights, oops (shadowtest was reversed)
[xonotic/darkplaces.git] / common.c
index 45e9f814050eac6b858266d88eedeb680bc426b2..e167f66d1add361649079204c19c608aa4f2b223 100644 (file)
--- a/common.c
+++ b/common.c
@@ -41,9 +41,10 @@ const char **com_argv;
 char com_cmdline[CMDLINE_LENGTH];
 
 int gamemode;
-char *gamename;
-char *gamedirname;
-char com_modname[MAX_OSPATH];
+const char *gamename;
+const char *gamedirname;
+const char *gamescreenshotname;
+char com_modname[MAX_OSPATH] = "";
 
 
 /*
@@ -54,15 +55,6 @@ char com_modname[MAX_OSPATH];
 ============================================================================
 */
 
-#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
-short   (*BigShort) (short l);
-short   (*LittleShort) (short l);
-int     (*BigLong) (int l);
-int     (*LittleLong) (int l);
-float   (*BigFloat) (float l);
-float   (*LittleFloat) (float l);
-#endif
-
 short   ShortSwap (short l)
 {
        qbyte    b1,b2;
@@ -73,13 +65,6 @@ short   ShortSwap (short l)
        return (b1<<8) + b2;
 }
 
-#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
-short   ShortNoSwap (short l)
-{
-       return l;
-}
-#endif
-
 int    LongSwap (int l)
 {
        qbyte    b1,b2,b3,b4;
@@ -92,13 +77,6 @@ int    LongSwap (int l)
        return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
 }
 
-#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
-int     LongNoSwap (int l)
-{
-       return l;
-}
-#endif
-
 float FloatSwap (float f)
 {
        union
@@ -116,13 +94,6 @@ float FloatSwap (float f)
        return dat2.f;
 }
 
-#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
-float FloatNoSwap (float f)
-{
-       return f;
-}
-#endif
-
 
 // Extract integers from buffers
 
@@ -353,16 +324,10 @@ int MSG_ReadBytes (int numbytes, unsigned char *out)
        return l;
 }
 
-// used by server (always latest PROTOCOL_DARKPLACES)
-float MSG_ReadDPCoord (void)
-{
-       return (signed short) MSG_ReadLittleShort();
-}
-
 // used by client
 float MSG_ReadCoord (void)
 {
-       if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
+       if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
                return (signed short) MSG_ReadLittleShort();
        else if (cl.protocol == PROTOCOL_DARKPLACES1)
                return MSG_ReadLittleFloat();
@@ -410,7 +375,7 @@ void *SZ_GetSpace (sizebuf_t *buf, int length)
                        Host_Error ("SZ_GetSpace: %i is > full buffer size\n", length);
 
                buf->overflowed = true;
-               Con_Print("SZ_GetSpace: overflow\n");
+               Con_Print("SZ_GetSpace: overflow\n");
                SZ_Clear (buf);
        }
 
@@ -444,39 +409,47 @@ void Com_HexDumpToConsole(const qbyte *data, int size)
                if (n > size - i)
                        n = size - i;
                d = data + i;
+               // print offset
                *cur++ = hexchar[(i >> 12) & 15];
                *cur++ = hexchar[(i >>  8) & 15];
                *cur++ = hexchar[(i >>  4) & 15];
                *cur++ = hexchar[(i >>  0) & 15];
                *cur++ = ':';
-               for (j = 0;j < n;j++)
+               // print hex
+               for (j = 0;j < 16;j++)
                {
-                       if (j & 1)
+                       if (j < n)
                        {
-                               *cur++ = hexchar[(d[j] >> 4) & 15] | 0x80;
-                               *cur++ = hexchar[(d[j] >> 0) & 15] | 0x80;
+                               *cur++ = hexchar[(d[j] >> 4) & 15];
+                               *cur++ = hexchar[(d[j] >> 0) & 15];
                        }
                        else
                        {
-                               *cur++ = hexchar[(d[j] >> 4) & 15];
-                               *cur++ = hexchar[(d[j] >> 0) & 15];
+                               *cur++ = ' ';
+                               *cur++ = ' ';
                        }
+                       if ((j & 3) == 0)
+                               *cur++ = ' ';
                }
-               for (;j < 16;j++)
+               // print text
+               for (j = 0;j < 16;j++)
                {
-                       *cur++ = ' ';
-                       *cur++ = ' ';
+                       if (j < n)
+                       {
+                               if (d[j] >= ' ' && d[j] <= 127)
+                                       *cur++ = d[j];
+                               else
+                                       *cur++ = '.';
+                       }
+                       else
+                               *cur++ = ' ';
                }
-               for (j = 0;j < n;j++)
-                       *cur++ = (d[j] >= ' ' && d[j] <= 0x7E) ? d[j] : '.';
-               for (;j < 16;j++)
-                       *cur++ = ' ';
                *cur++ = '\n';
                i += n;
                if (cur >= flushpointer || i >= size)
                {
                        *cur++ = 0;
-                       Con_Printf("%s", text);
+                       Con_Print(text);
                        cur = text;
                }
        }
@@ -701,14 +674,14 @@ void COM_CheckRegistered (void)
        if (!FS_FileExists("gfx/pop.lmp"))
        {
                if (fs_modified)
-                       Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
+                       Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
                else
-                       Con_Print("Playing shareware version.\n");
+                       Con_Print("Playing shareware version.\n");
                return;
        }
 
        Cvar_Set ("registered", "1");
-       Con_Print("Playing registered version.\n");
+       Con_Print("Playing registered version.\n");
 }
 
 
@@ -735,124 +708,86 @@ void COM_InitArgv (void)
        com_cmdline[n] = 0;
 }
 
+
+//===========================================================================
+
+// Game mods
+
+typedef struct
+{
+       const char* prog_name;
+       const char* cmdline;
+       const char* gamename;
+       const char* gamedirname;
+       const char* gamescreenshotname;
+} gamemode_info_t;
+
+static const gamemode_info_t gamemode_info [] =
+{// prog_name          cmdline                 gamename                                gamedirname     gamescreenshotname
+
+// GAME_NORMAL
+{ "",                          "-quake",               "DarkPlaces-Quake",             "",                     "dp" },
+// GAME_HIPNOTIC
+{ "hipnotic",          "-hipnotic",    "Darkplaces-Hipnotic",  "hipnotic",     "dp" },
+// GAME_ROGUE
+{ "rogue",                     "-rogue",               "Darkplaces-Rogue",             "rogue",        "dp" },
+// GAME_NEHAHRA
+{ "nehahra",           "-nehahra",             "DarkPlaces-Nehahra",   "nehahra",      "dp" },
+// GAME_NEXUIZ
+{ "nexuiz",                    "-nexuiz",              "Nexuiz",                               "data",         "nexuiz" },
+// GAME_TRANSFUSION
+{ "transfusion",       "-transfusion", "Transfusion",                  "basetf",       "transfusion" },
+// GAME_GOODVSBAD2
+{ "gvb2",                      "-goodvsbad2",  "GoodVs.Bad2",                  "rts",          "gvb2" },
+// GAME_TEU
+{ "teu",                       "-teu",                 "TheEvilUnleashed",             "baseteu",      "teu" },
+// GAME_BATTLEMECH
+{ "battlemech",                "-battlemech",  "Battlemech",                   "base",         "battlemech" },
+// GAME_ZYMOTIC
+{ "zymotic",           "-zymotic",             "Zymotic",                              "data",         "zymotic" },
+// GAME_FNIGGIUM
+{ "fniggium",          "-fniggium",    "Fniggium",                             "data",         "fniggium" },
+// GAME_SETHERAL
+{ "setheral",          "-setheral",    "Setheral",                             "data",         "setheral" },
+// GAME_SOM
+{ "som",                       "-som",                 "Son of Man",                   "sonofman",     "som" },
+// GAME_TENEBRAE
+{ "tenebrae",          "-tenebrae",    "DarkPlaces-Tenebrae",  "tenebrae",     "dp" },
+// GAME_NEOTERIC
+{ "neoteric",          "-neoteric",    "Neoteric",                             "neobase",      "neo" },
+// GAME_OPENQUARTZ
+{ "openquartz",                "-openquartz",  "OpenQuartz",                   "id1",          "openquartz"},
+
+};
+
 void COM_InitGameType (void)
 {
-       char name[MAX_OSPATH];
+       char name [MAX_OSPATH];
+       unsigned int i;
+
        FS_StripExtension (com_argv[0], name, sizeof (name));
        COM_ToLowerString (name, name, sizeof (name));
 
-       if (strstr(name, "transfusion"))
-               gamemode = GAME_TRANSFUSION;
-       else if (strstr(name, "nexuiz"))
-               gamemode = GAME_NEXUIZ;
-       else if (strstr(name, "nehahra"))
-               gamemode = GAME_NEHAHRA;
-       else if (strstr(name, "hipnotic"))
-               gamemode = GAME_HIPNOTIC;
-       else if (strstr(name, "rogue"))
-               gamemode = GAME_ROGUE;
-       else if (strstr(name, "gvb2"))
-               gamemode = GAME_GOODVSBAD2;
-       else if (strstr(name, "teu"))
-               gamemode = GAME_TEU;
-       else if (strstr(name, "battlemech"))
-               gamemode = GAME_BATTLEMECH;
-       else if (strstr(name, "zymotic"))
-               gamemode = GAME_ZYMOTIC;
-       else if (strstr(name, "fniggium"))
-               gamemode = GAME_FNIGGIUM;
-       else if (strstr(name, "setheral"))
-               gamemode = GAME_SETHERAL;
-       else if (strstr(name, "som"))
-               gamemode = GAME_SOM;
-       else
-               gamemode = GAME_NORMAL;
-
-       if (COM_CheckParm ("-transfusion"))
-               gamemode = GAME_TRANSFUSION;
-       else if (COM_CheckParm ("-nexuiz"))
-               gamemode = GAME_NEXUIZ;
-       else if (COM_CheckParm ("-nehahra"))
-               gamemode = GAME_NEHAHRA;
-       else if (COM_CheckParm ("-hipnotic"))
-               gamemode = GAME_HIPNOTIC;
-       else if (COM_CheckParm ("-rogue"))
-               gamemode = GAME_ROGUE;
-       else if (COM_CheckParm ("-quake"))
-               gamemode = GAME_NORMAL;
-       else if (COM_CheckParm ("-goodvsbad2"))
-               gamemode = GAME_GOODVSBAD2;
-       else if (COM_CheckParm ("-teu"))
-               gamemode = GAME_TEU;
-       else if (COM_CheckParm ("-battlemech"))
-               gamemode = GAME_BATTLEMECH;
-       else if (COM_CheckParm ("-zymotic"))
-               gamemode = GAME_ZYMOTIC;
-       else if (COM_CheckParm ("-fniggium"))
-               gamemode = GAME_FNIGGIUM;
-       else if (COM_CheckParm ("-setheral"))
-               gamemode = GAME_SETHERAL;
-       else if (COM_CheckParm ("-som"))
-               gamemode = GAME_SOM;
-
-       switch(gamemode)
-       {
-       case GAME_NORMAL:
-               gamename = "DarkPlaces-Quake";
-               gamedirname = "";
-               break;
-       case GAME_HIPNOTIC:
-               gamename = "Darkplaces-Hipnotic";
-               gamedirname = "hipnotic";
-               break;
-       case GAME_ROGUE:
-               gamename = "Darkplaces-Rogue";
-               gamedirname = "rogue";
-               break;
-       case GAME_NEHAHRA:
-               gamename = "DarkPlaces-Nehahra";
-               gamedirname = "nehahra";
-               break;
-       case GAME_NEXUIZ:
-               gamename = "Nexuiz";
-               gamedirname = "data";
-               break;
-       case GAME_TRANSFUSION:
-               gamename = "Transfusion";
-               gamedirname = "basetf";
-               break;
-       case GAME_GOODVSBAD2:
-               gamename = "GoodVs.Bad2";
-               gamedirname = "rts";
-               break;
-       case GAME_TEU:
-               gamename = "TheEvilUnleashed";
-               gamedirname = "baseteu";
-               break;
-       case GAME_BATTLEMECH:
-               gamename = "Battlemech";
-               gamedirname = "base";
-               break;
-       case GAME_ZYMOTIC:
-               gamename = "Zymotic";
-               gamedirname = "data";
-               break;
-       case GAME_FNIGGIUM:
-               gamename = "Fniggium";
-               gamedirname = "data";
-               break;
-       case GAME_SETHERAL:
-               gamename = "Setheral";
-               gamedirname = "data";
-               break;
-       case GAME_SOM:
-               gamename = "Son of Man";
-               gamedirname = "data";
-               break;
-       default:
-               Sys_Error("COM_InitGameType: unknown gamemode %i\n", gamemode);
-               break;
-       }
+       // Check the binary name; default to GAME_NORMAL (0)
+       gamemode = GAME_NORMAL;
+       for (i = 1; i < sizeof (gamemode_info) / sizeof (gamemode_info[0]); i++)
+               if (strstr (name, gamemode_info[i].prog_name))
+               {
+                       gamemode = i;
+                       break;
+               }
+
+       // Look for a command-line option
+       for (i = 0; i < sizeof (gamemode_info) / sizeof (gamemode_info[0]); i++)
+               if (COM_CheckParm (gamemode_info[i].cmdline))
+               {
+                       gamemode = i;
+                       break;
+               }
+
+       gamename = gamemode_info[gamemode].gamename;
+       gamedirname = gamemode_info[gamemode].gamedirname;
+       gamescreenshotname = gamemode_info[gamemode].gamescreenshotname;
 }
 
 
@@ -866,40 +801,14 @@ COM_Init
 */
 void COM_Init (void)
 {
-#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
-       qbyte swaptest[2] = {1,0};
-
-// set the byte swapping variables in a portable manner
-       if ( *(short *)swaptest == 1)
-       {
-               BigShort = ShortSwap;
-               LittleShort = ShortNoSwap;
-               BigLong = LongSwap;
-               LittleLong = LongNoSwap;
-               BigFloat = FloatSwap;
-               LittleFloat = FloatNoSwap;
-       }
-       else
-       {
-               BigShort = ShortNoSwap;
-               LittleShort = ShortSwap;
-               BigLong = LongNoSwap;
-               LittleLong = LongSwap;
-               BigFloat = FloatNoSwap;
-               LittleFloat = FloatSwap;
-       }
-#endif
-
        Cvar_RegisterVariable (&registered);
        Cvar_RegisterVariable (&cmdline);
 
        Mathlib_Init();
 
        FS_Init ();
-       Con_InitLogging();
+       Log_Init ();
        COM_CheckRegistered ();
-
-       COM_InitGameType();
 }
 
 
@@ -1115,9 +1024,7 @@ char *SearchInfostring(const char *infostring, const char *key)
 /*     $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $     */
 
 
-// Most (all?) BSDs already have them
-#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !(defined(__APPLE__) && defined(__MACH__))
-
+#ifndef HAVE_STRLCAT
 size_t
 strlcat(char *dst, const char *src, size_t siz)
 {
@@ -1145,7 +1052,10 @@ strlcat(char *dst, const char *src, size_t siz)
 
        return(dlen + (s - src));       /* count does not include NUL */
 }
+#endif  // #ifndef HAVE_STRLCAT
+
 
+#ifndef HAVE_STRLCPY
 size_t
 strlcpy(char *dst, const char *src, size_t siz)
 {
@@ -1172,4 +1082,4 @@ strlcpy(char *dst, const char *src, size_t siz)
        return(s - src - 1);    /* count does not include NUL */
 }
 
-#endif  // #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
+#endif  // #ifndef HAVE_STRLCPY