Switch from an arch whitelist to an "all archs are supported" approach.

The old whitelist was a leftover from the early days of YQ2. It should
run on most / all architectures, as long SDL supports them. As suggested
by smcv in issue #138 generate the OSTYPE and ARCH defines by the build
system instead of hardcoding it.

Savegame compatibility is provided by bumping the savegame version. Old
savegames are compared against the old OSTYPE and ARCH defined, new ones
against the new defines. This compatibility code should be removed
somewhere in the distant future.
This commit is contained in:
Yamagi Burmeister 2016-06-08 19:10:43 +02:00
parent da6ad6953d
commit 5a384c79b1
8 changed files with 117 additions and 89 deletions

View file

@ -55,6 +55,15 @@ set(GAME_SRC_DIR ${SOURCE_DIR}/game)
set(SERVER_SRC_DIR ${SOURCE_DIR}/server)
set(CLIENT_SRC_DIR ${SOURCE_DIR}/client)
# Operating system
add_definitions(-DOSTYPE="${CMAKE_SYSTEM_NAME}")
# Architecture string
string(REGEX REPLACE "amd64" "x86_64" ARCH ${CMAKE_SYSTEM_PROCESSOR})
string(REGEX REPLACE "i.86" "i386" ARCH ${ARCH})
string(REGEX REPLACE "^arm.*" "arm" ARCH ${ARCH})
add_definitions(-DARCH="${ARCH}")
# Systemwide installation of game assets
if(${SYSTEMWIDE_SUPPORT})
add_definitions(-DSYSTEMWIDE)

View file

@ -106,20 +106,16 @@ endif
# Detect the architecture
ifeq ($(OSTYPE), Windows)
# At this time only i386 is supported on Windows
# (amd64 works, but building an 64 bit executable
# is not that easy. Especially SDL and OpenAL are
# somewhat problematic)
ARCH ?= i386
ifdef PROCESSOR_ARCHITEW6432
# 64 bit Windows
ARCH := $(PROCESSOR_ARCHITEW6432)
else
# Some platforms call it "amd64" and some "x86_64"
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/amd64/x86_64/)
# 32 bit Windows
ARCH := $(PROCESSOR_ARCHITECTURE)
endif
# Refuse all other platforms as a firewall against PEBKAC
# (You'll need some #ifdef for your unsupported plattform!)
ifeq ($(findstring $(ARCH), i386 x86_64 sparc64 ia64),)
$(error arch $(ARCH) is currently not supported)
else
# Normalize some abiguous ARCH strings
ARCH := $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/')
endif
# Disable CDA for SDL2
@ -156,7 +152,6 @@ endif
ifeq ($(OSTYPE), Darwin)
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -fwrapv
#-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.5.sdk
CFLAGS += $(OSX_ARCH)
else
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
@ -165,6 +160,11 @@ endif
# ----------
# Defines the operating system and architecture
CFLAGS += -DOSTYPE=\"$(OSTYPE)\" -DARCH=\"$(ARCH)\"
# ----------
# Systemwide installation
ifeq ($(WITH_SYSTEMWIDE),yes)
CFLAGS += -DSYSTEMWIDE

View file

@ -110,8 +110,8 @@ main(int argc, char **argv)
#endif
#endif
printf("Platform: %s\n", BUILDSTRING);
printf("Architecture: %s\n", CPUSTRING);
printf("Platform: %s\n", OSTYPE);
printf("Architecture: %s\n", ARCH);
/* Seed PRNG */
randk_seed();

View file

@ -49,8 +49,8 @@ printBacktrace(int sig)
printf("Product: Yamagi Quake II\n");
printf("Version: %s\n", YQ2VERSION);
printf("Plattform: %s\n", BUILDSTRING);
printf("Architecture: %s\n", CPUSTRING);
printf("Plattform: %s\n", OSTYPE);
printf("Architecture: %s\n", ARCH);
printf("Compiler: %s\n", __VERSION__);
printf("Signal: %i\n", sig);
printf("\nBacktrace:\n");
@ -70,8 +70,8 @@ printBacktrace(int sig)
{
printf("Product: Yamagi Quake II\n");
printf("Version: %s\n", YQ2VERSION);
printf("Plattform: %s\n", BUILDSTRING);
printf("Architecture: %s\n", CPUSTRING);
printf("Plattform: %s\n", OSTYPE);
printf("Architecture: %s\n", ARCH);
printf("Compiler: %s\n", __VERSION__);
printf("Signal: %i\n", sig);
printf("\nBacktrace:\n");

View file

@ -739,8 +739,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
#endif
#endif
printf("Platform: %s\n", BUILDSTRING);
printf("Architecture: %s\n", CPUSTRING);
printf("Platform: %s\n", OSTYPE);
printf("Architecture: %s\n", ARCH);
/* Seed PRNG */
randk_seed();

View file

@ -34,33 +34,14 @@
/* Should have 4 characters. */
#define YQ2VERSION "5.34pre"
#define BASEDIRNAME "baseq2"
#if defined __linux__
#define BUILDSTRING "Linux"
#elif defined __FreeBSD__
#define BUILDSTRING "FreeBSD"
#elif defined __OpenBSD__
#define BUILDSTRING "OpenBSD"
#elif defined _WIN32
#define BUILDSTRING "Windows"
#elif defined __APPLE__
#define BUILDSTRING "MacOS X"
#else
#define BUILDSTRING "Unknown"
#ifndef OSTYPE
#error OSTYPE should be defined by the build system
#endif
#ifdef __i386__
#define CPUSTRING "i386"
#elif defined __x86_64__
#define CPUSTRING "amd64"
#elif defined __sparc__
#define CPUSTRING "sparc64"
#elif defined __ia64__
#define CPUSTRING "ia64"
#else
#define CPUSTRING "Unknown"
#ifndef ARCH
#error ARCH should be defined by the build system
#endif
#ifdef _WIN32
@ -79,7 +60,6 @@
#define LIBGL "libGL.so.1"
#endif
/* ================================================================== */
typedef struct sizebuf_s
@ -767,7 +747,7 @@ extern vec3_t bytedirs[NUMVERTEXNORMALS];
/* this is in the client code, but can be used for debugging from server */
void SCR_DebugGraph(float value, int color);
/* NON-PORTABLE SYSTEM SERVICES */
/* NON-PORTABLE OSTYPE SERVICES */
void Sys_Init(void);
void Sys_UnloadGame(void);

View file

@ -241,7 +241,7 @@ Qcommon_Init(int argc, char **argv)
dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET);
#endif
s = va("%s %s %s %s", YQ2VERSION, CPUSTRING, __DATE__, BUILDSTRING);
s = va("%s %s %s %s", YQ2VERSION, ARCH, __DATE__, OSTYPE);
Cvar_Get("version", s, CVAR_SERVERINFO | CVAR_NOSET);
if (dedicated->value)

View file

@ -67,47 +67,53 @@
#include "../header/local.h"
/*
* When ever the savegame version
* is changed, q2 will refuse to
* load older savegames. This
* should be bumped if the files
* in tables/ are changed, otherwise
* strange things may happen.
* When ever the savegame version is changed, q2 will refuse to
* load older savegames. This should be bumped if the files
* in tables/ are changed, otherwise strange things may happen.
*/
#define SAVEGAMEVER "YQ2-1"
#define SAVEGAMEVER "YQ2-2"
/*
* This macros are used to
* prohibit loading of savegames
* created on other systems or
* architectures. This will
* crash q2 in spectacular
* ways
* This macros are used to prohibit loading of savegames
* created on other systems or architectures. This will
* crash q2 in spectacular ways
*/
#ifndef OSTYPE
#error OSTYPE should be defined by the build system
#endif
#ifndef ARCH
#error ARCH should be defined by the build system
#endif
/*
* Older operating systen and architecture detection
* macros, implemented by savegame version YQ2-1.
*/
#if defined(__APPLE__)
#define OS "MacOS X"
#define OSTYPE_1 "MacOS X"
#elif defined(__FreeBSD__)
#define OS "FreeBSD"
#define OSTYPE_1 "FreeBSD"
#elif defined(__OpenBSD__)
#define OS "OpenBSD"
#define OSTYPE_1 "OpenBSD"
#elif defined(__linux__)
#define OS "Linux"
#define OSTYPE_1 "Linux"
#elif defined(_WIN32)
#define OS "Windows"
#define OSTYPE_1 "Windows"
#else
#define OS "Unknown"
#define OSTYPE_1 "Unknown"
#endif
#if defined(__i386__)
#define ARCH "i386"
#define ARCH_1 "i386"
#elif defined(__x86_64__)
#define ARCH "amd64"
#define ARCH_1 "amd64"
#elif defined(__sparc__)
#define ARCH "sparc64"
#define ARCH_1 "sparc64"
#elif defined(__ia64__)
#define ARCH "ia64"
#define ARCH_1 "ia64"
#else
#define ARCH "unknown"
#define ARCH_1 "unknown"
#endif
/*
@ -777,7 +783,7 @@ WriteGame(const char *filename, qboolean autosave)
Q_strlcpy(str_ver, SAVEGAMEVER, sizeof(str_ver));
Q_strlcpy(str_game, GAMEVERSION, sizeof(str_game));
Q_strlcpy(str_os, OS, sizeof(str_os));
Q_strlcpy(str_os, OSTYPE, sizeof(str_os));
Q_strlcpy(str_arch, ARCH, sizeof(str_arch));
fwrite(str_ver, sizeof(str_ver), 1, f);
@ -827,27 +833,60 @@ ReadGame(const char *filename)
fread(str_os, sizeof(str_os), 1, f);
fread(str_arch, sizeof(str_arch), 1, f);
if (strcmp(str_ver, SAVEGAMEVER))
if (!strcmp(str_ver, SAVEGAMEVER))
{
if (strcmp(str_game, GAMEVERSION))
{
fclose(f);
gi.error("Savegame from an other game.so.\n");
}
else if (strcmp(str_os, OSTYPE))
{
fclose(f);
gi.error("Savegame from an other os.\n");
}
else if (strcmp(str_arch, ARCH))
{
fclose(f);
gi.error("Savegame from an other architecure.\n");
}
}
else if (!strcmp(str_ver, "YQ2-1"))
{
if (strcmp(str_game, GAMEVERSION))
{
fclose(f);
gi.error("Savegame from an other game.so.\n");
}
else if (strcmp(str_os, OSTYPE_1))
{
fclose(f);
gi.error("Savegame from an other os.\n");
}
if (!strcmp(str_os, "Windows"))
{
/* Windows was forced to i386 */
if (strcmp(str_arch, "i386"))
{
fclose(f);
gi.error("Savegame from an other architecure.\n");
}
}
else
{
if (strcmp(str_arch, ARCH_1))
{
fclose(f);
gi.error("Savegame from an other architecure.\n");
}
}
}
else
{
fclose(f);
gi.error("Savegame from an incompatible version.\n");
}
else if (strcmp(str_game, GAMEVERSION))
{
fclose(f);
gi.error("Savegame from an other game.so.\n");
}
else if (strcmp(str_os, OS))
{
fclose(f);
gi.error("Savegame from an other os.\n");
}
else if (strcmp(str_arch, ARCH))
{
fclose(f);
gi.error("Savegame from an other architecure.\n");
}
g_edicts = gi.TagMalloc(game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
globals.edicts = g_edicts;