mirror of
https://github.com/yquake2/rogue.git
synced 2024-11-10 06:42:21 +00:00
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:
parent
7e7ed6bf94
commit
6467137619
3 changed files with 105 additions and 55 deletions
|
@ -18,6 +18,15 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-strict-aliasing -fwrapv")
|
|||
# Use -O2 as maximum optimization level. -O3 has it's problems with yquake2.
|
||||
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
||||
|
||||
# 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}")
|
||||
|
||||
# Linker Flags
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
list(APPEND RogueLinkerFlags "-lm")
|
||||
|
|
24
Makefile
24
Makefile
|
@ -31,19 +31,16 @@ endif
|
|||
|
||||
# Detect the architecture
|
||||
ifeq ($(OSTYPE), Windows)
|
||||
# At this time only i386 is supported on Windows
|
||||
ARCH := i386
|
||||
# seems like mingw doesn't set CC by default
|
||||
CC := gcc
|
||||
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
|
||||
|
||||
# ----------
|
||||
|
@ -76,6 +73,11 @@ endif
|
|||
|
||||
# ----------
|
||||
|
||||
# Defines the operating system and architecture
|
||||
CFLAGS += -DOSTYPE=\"$(OSTYPE)\" -DARCH=\"$(ARCH)\"
|
||||
|
||||
# ----------
|
||||
|
||||
# Base LDFLAGS.
|
||||
ifeq ($(OSTYPE), Darwin)
|
||||
LDFLAGS := -shared -arch i386 -arch x86_64
|
||||
|
|
|
@ -47,47 +47,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-2"
|
||||
#define SAVEGAMEVER "YQ2-3"
|
||||
|
||||
/*
|
||||
* This macros are used to
|
||||
* prohibit loading of savegames
|
||||
* created on other systems or
|
||||
* architectures. This will
|
||||
* crash q2 in spectecular
|
||||
* ways
|
||||
* This macros are used to prohibit loading of savegames
|
||||
* created on other systems or architectures. This will
|
||||
* crash q2 in spectacular ways
|
||||
*/
|
||||
#if defined(__FreeBSD__)
|
||||
#define OS "FreeBSD"
|
||||
#elif defined(__APPLE__)
|
||||
#define OS "MacOS X"
|
||||
#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-2.
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
#define OSTYPE_1 "MacOS X"
|
||||
#elif defined(__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
|
||||
|
||||
/*
|
||||
|
@ -770,7 +776,7 @@ WriteGame(const char *filename, qboolean autosave)
|
|||
|
||||
strncpy(str_ver, SAVEGAMEVER, sizeof(str_ver));
|
||||
strncpy(str_game, GAMEVERSION, sizeof(str_game));
|
||||
strncpy(str_os, OS, sizeof(str_os));
|
||||
strncpy(str_os, OSTYPE, sizeof(str_os));
|
||||
strncpy(str_arch, ARCH, sizeof(str_arch));
|
||||
|
||||
fwrite(str_ver, sizeof(str_ver), 1, f);
|
||||
|
@ -820,27 +826,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-2"))
|
||||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue