From 7ec1fd31544aeffc72287be880c577250162013e Mon Sep 17 00:00:00 2001 From: Neon_Knight Date: Sun, 9 Jun 2019 11:56:45 -0300 Subject: [PATCH] Refactoring to match the current yq2 projects. --- CMakeLists.txt | 46 +++++++-------- Makefile | 91 +++++++++++++++++++---------- src/{ => bot}/bot.c | 6 +- src/{bot_fire.c => bot/fire.c} | 6 +- src/{bot_func.c => bot/func.c} | 4 +- src/{bot_za.c => bot/za.c} | 6 +- src/g_chase.c | 2 +- src/g_cmds.c | 6 +- src/g_combat.c | 4 +- src/g_ctf.c | 4 +- src/g_func.c | 4 +- src/g_items.c | 6 +- src/g_main.c | 4 +- src/g_misc.c | 4 +- src/g_monster.c | 4 +- src/g_phys.c | 2 +- src/g_save.c | 4 +- src/g_spawn.c | 4 +- src/g_svcmds.c | 4 +- src/g_target.c | 2 +- src/g_trigger.c | 2 +- src/g_utils.c | 2 +- src/g_weapon.c | 4 +- src/{ => header}/bot.h | 2 +- src/{ => header}/botstr.h | 0 src/{g_ctf.h => header/ctf.h} | 0 src/{ => header}/game.h | 0 src/{g_local.h => header/local.h} | 6 +- src/{p_menu.h => header/menu.h} | 0 src/{m_player.h => header/player.h} | 0 src/{q_shared.h => header/shared.h} | 0 src/{m_move.c => monster/move.c} | 2 +- src/{p_client.c => player/client.c} | 6 +- src/{p_hud.c => player/hud.c} | 4 +- src/{p_menu.c => player/menu.c} | 2 +- src/{p_trail.c => player/trail.c} | 2 +- src/{p_view.c => player/view.c} | 6 +- src/{p_weapon.c => player/weapon.c} | 6 +- src/{q_shared.c => shared/shared.c} | 2 +- 39 files changed, 143 insertions(+), 116 deletions(-) rename src/{ => bot}/bot.c (98%) rename src/{bot_fire.c => bot/fire.c} (99%) rename src/{bot_func.c => bot/func.c} (99%) rename src/{bot_za.c => bot/za.c} (99%) rename src/{ => header}/bot.h (99%) rename src/{ => header}/botstr.h (100%) rename src/{g_ctf.h => header/ctf.h} (100%) rename src/{ => header}/game.h (100%) rename src/{g_local.h => header/local.h} (99%) rename src/{p_menu.h => header/menu.h} (100%) rename src/{m_player.h => header/player.h} (100%) rename src/{q_shared.h => header/shared.h} (100%) rename src/{m_move.c => monster/move.c} (98%) rename src/{p_client.c => player/client.c} (99%) rename src/{p_hud.c => player/hud.c} (99%) rename src/{p_menu.c => player/menu.c} (99%) rename src/{p_trail.c => player/trail.c} (98%) rename src/{p_view.c => player/view.c} (99%) rename src/{p_weapon.c => player/weapon.c} (99%) rename src/{q_shared.c => shared/shared.c} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f36cd68..4fe5165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,9 +22,9 @@ string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") 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}) +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 @@ -35,10 +35,10 @@ else() endif() set(3zb2-Source - src/bot_fire.c - src/bot_func.c - src/bot_za.c - src/bot.c + src/bot/fire.c + src/bot/func.c + src/bot/za.c + src/bot/bot.c src/g_chase.c src/g_cmds.c src/g_combat.c @@ -57,25 +57,25 @@ set(3zb2-Source src/g_turret.c src/g_utils.c src/g_weapon.c - src/m_move.c - src/p_client.c - src/p_hud.c - src/p_menu.c - src/p_trail.c - src/p_view.c - src/p_weapon.c - src/q_shared.c + src/monster/move.c + src/player/client.c + src/player/hud.c + src/player/menu.c + src/player/trail.c + src/player/view.c + src/player/weapon.c + src/shared/shared.c ) set(3zb2-Header - src/bot.h - src/botstr.h - src/g_ctf.h - src/g_local.h - src/game.h - src/m_player.h - src/p_menu.h - src/q_shared.h + src/header/bot.h + src/header/botstr.h + src/header/ctf.h + src/header/game.h + src/header/local.h + src/header/menu.h + src/header/player.h + src/header/shared.h ) # Build the 3zb2 dynamic library diff --git a/Makefile b/Makefile index b9d45b2..a75c7c7 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ # ----------------------------------------------------- # -# Makefile for the 3zb2game module for Quake II # +# Makefile for the 3zb2 game module for Quake II # # # # Just type "make" to compile the # -# - The Reckoning Game (game.so / game.dll) # +# - 3rd. Zigock Bot Game (game.so) # # # # Dependencies: # # - None, but you need a Quake II to play. # -# While in theorie every one should work # +# While in theorie every client should work # # Yamagi Quake II ist recommended. # # # # Platforms: # @@ -23,12 +23,12 @@ OSTYPE := Windows else OSTYPE := $(shell uname -s) endif - + # Special case for MinGW ifneq (,$(findstring MINGW,$(OSTYPE))) OSTYPE := Windows endif - + # Detect the architecture ifeq ($(OSTYPE), Windows) ifdef PROCESSOR_ARCHITEW6432 @@ -43,12 +43,23 @@ else ARCH := $(shell uname -m | sed -e 's/i.86/i386/' -e 's/amd64/x86_64/' -e 's/^arm.*/arm/') endif +# Detect the compiler +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) +COMPILER := clang +COMPILERVER := $(shell $(CC) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/') +else ifeq ($(shell $(CC) -v 2>&1 | grep -c -E "(gcc version|gcc-Version)"), 1) +COMPILER := gcc +COMPILERVER := $(shell $(CC) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/') +else +COMPILER := unknown +endif + # ---------- -# Base CFLAGS. +# Base CFLAGS. # # -O2 are enough optimizations. -# +# # -fno-strict-aliasing since the source doesn't comply # with strict aliasing rules and it's next to impossible # to get it there... @@ -73,6 +84,22 @@ endif # ---------- +# Switch of some annoying warnings. +ifeq ($(COMPILER), clang) + # -Wno-missing-braces because otherwise clang complains + # about totally valid 'vec3_t bla = {0}' constructs. + CFLAGS += -Wno-missing-braces +else ifeq ($(COMPILER), gcc) + # GCC 8.0 or higher. + ifeq ($(shell test $(COMPILERVER) -ge 80000; echo $$?),0) + # -Wno-format-truncation and -Wno-format-overflow + # because GCC spams about 50 false positives. + CFLAGS += -Wno-format-truncation -Wno-format-overflow + endif +endif + +# ---------- + # Defines the operating system and architecture CFLAGS += -DOSTYPE=\"$(OSTYPE)\" -DARCH=\"$(ARCH)\" @@ -80,11 +107,11 @@ CFLAGS += -DOSTYPE=\"$(OSTYPE)\" -DARCH=\"$(ARCH)\" # Base LDFLAGS. ifeq ($(OSTYPE), Darwin) -LDFLAGS := -shared -arch i386 -arch x86_64 +LDFLAGS := -shared -arch i386 -arch x86_64 else ifeq ($(OSTYPE), Windows) LDFLAGS := -shared -static-libgcc else -LDFLAGS := -shared +LDFLAGS := -shared -lm endif # ---------- @@ -104,12 +131,12 @@ Q := @ endif # ---------- - + # Phony targets .PHONY : all clean 3zb2 # ---------- - + # Cleanup clean: @echo "===> CLEAN" @@ -122,33 +149,33 @@ ifeq ($(OSTYPE), Windows) 3zb2: @echo "===> Building game.dll" ${Q}mkdir -p release - ${MAKE} release/game.dll - -build/%.o: %.c - @echo "===> CC $<" - ${Q}mkdir -p $(@D) - ${Q}$(CC) -c $(CFLAGS) -o $@ $< + $(MAKE) release/game.dll +else ifeq ($(OSTYPE), Darwin) +3zb2: + @echo "===> Building game.dylib" + ${Q}mkdir -p release + $(MAKE) release/game.dylib else 3zb2: @echo "===> Building game.so" ${Q}mkdir -p release $(MAKE) release/game.so +release/game.so : CFLAGS += -fPIC +endif + build/%.o: %.c @echo "===> CC $<" ${Q}mkdir -p $(@D) ${Q}$(CC) -c $(CFLAGS) -o $@ $< -release/game.so : CFLAGS += -fPIC -endif - # ---------- 3ZB2_OBJS_ = \ - src/bot.o \ - src/bot_fire.o \ - src/bot_func.o \ - src/bot_za.o \ + src/bot/bot.o \ + src/bot/fire.o \ + src/bot/func.o \ + src/bot/za.o \ src/g_chase.o \ src/g_cmds.o \ src/g_combat.o \ @@ -166,14 +193,14 @@ endif src/g_trigger.o \ src/g_utils.o \ src/g_weapon.o \ - src/m_move.o \ - src/p_client.o \ - src/p_hud.o \ - src/p_menu.o \ - src/p_trail.o \ - src/p_view.o \ - src/p_weapon.o \ - src/q_shared.o + src/monster/move.o \ + src/player/client.o \ + src/player/hud.o \ + src/player/menu.o \ + src/player/trail.o \ + src/player/view.o \ + src/player/weapon.o \ + src/shared/shared.o # ---------- diff --git a/src/bot.c b/src/bot/bot.c similarity index 98% rename from src/bot.c rename to src/bot/bot.c index 6c523c3..1001fb8 100644 --- a/src/bot.c +++ b/src/bot/bot.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "m_player.h" -#include "bot.h" +#include "../header/local.h" +#include "../header/player.h" +#include "../header/bot.h" void droptofloor (edict_t *ent); diff --git a/src/bot_fire.c b/src/bot/fire.c similarity index 99% rename from src/bot_fire.c rename to src/bot/fire.c index 4f9079c..aa4d71c 100644 --- a/src/bot_fire.c +++ b/src/bot/fire.c @@ -1,6 +1,6 @@ -#include "bot.h" -#include "q_shared.h" -#include "m_player.h" +#include "../header/bot.h" +#include "../header/shared.h" +#include "../header/player.h" //====================================================================== //aim決定 diff --git a/src/bot_func.c b/src/bot/func.c similarity index 99% rename from src/bot_func.c rename to src/bot/func.c index 7161786..3551a21 100644 --- a/src/bot_func.c +++ b/src/bot/func.c @@ -1,5 +1,5 @@ -#include "bot.h" -#include "m_player.h" +#include "../header/bot.h" +#include "../header/player.h" qboolean Get_YenPos(char *Buff,int *curr) diff --git a/src/bot_za.c b/src/bot/za.c similarity index 99% rename from src/bot_za.c rename to src/bot/za.c index 5429749..2dfa973 100644 --- a/src/bot_za.c +++ b/src/bot/za.c @@ -1,6 +1,6 @@ -#include "bot.h" -#include "q_shared.h" -#include "m_player.h" +#include "../header/bot.h" +#include "../header/shared.h" +#include "../header/player.h" qboolean pickup_pri; diff --git a/src/g_chase.c b/src/g_chase.c index b5d4d8a..5e7e9fa 100644 --- a/src/g_chase.c +++ b/src/g_chase.c @@ -1,4 +1,4 @@ -#include "g_local.h" +#include "header/local.h" void UpdateChaseCam(edict_t *ent) { diff --git a/src/g_cmds.c b/src/g_cmds.c index 2146d60..c492d6f 100644 --- a/src/g_cmds.c +++ b/src/g_cmds.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "m_player.h" -#include "bot.h" +#include "header/local.h" +#include "header/player.h" +#include "header/bot.h" char *ClientTeam (edict_t *ent) { diff --git a/src/g_combat.c b/src/g_combat.c index 0932b1c..8281f41 100644 --- a/src/g_combat.c +++ b/src/g_combat.c @@ -1,7 +1,7 @@ // g_combat.c -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" /* ============ CanDamage diff --git a/src/g_ctf.c b/src/g_ctf.c index 19428b3..aa958eb 100644 --- a/src/g_ctf.c +++ b/src/g_ctf.c @@ -1,5 +1,5 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" typedef struct ctfgame_s { diff --git a/src/g_func.c b/src/g_func.c index 5bca914..7cb6ee8 100644 --- a/src/g_func.c +++ b/src/g_func.c @@ -1,5 +1,5 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" void SpawnItem3 (edict_t *ent, gitem_t *item); /* diff --git a/src/g_items.c b/src/g_items.c index 839a1ed..9dda6eb 100644 --- a/src/g_items.c +++ b/src/g_items.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "bot.h" -#include "g_ctf.h" +#include "header/local.h" +#include "header/bot.h" +#include "header/ctf.h" qboolean Pickup_Weapon (edict_t *ent, edict_t *other); void Use_Weapon (edict_t *ent, gitem_t *inv); diff --git a/src/g_main.c b/src/g_main.c index 2d75367..f660f81 100644 --- a/src/g_main.c +++ b/src/g_main.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" game_locals_t game; level_locals_t level; diff --git a/src/g_misc.c b/src/g_misc.c index 258527e..e00ab07 100644 --- a/src/g_misc.c +++ b/src/g_misc.c @@ -1,7 +1,7 @@ // g_misc.c -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" /*QUAKED func_group (0 0 0) ? Used to group brushes together just for editor convenience. diff --git a/src/g_monster.c b/src/g_monster.c index 71cb6f9..0ba1cda 100644 --- a/src/g_monster.c +++ b/src/g_monster.c @@ -1,5 +1,5 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" // // monster weapons diff --git a/src/g_phys.c b/src/g_phys.c index 9f0850f..d0bb83e 100644 --- a/src/g_phys.c +++ b/src/g_phys.c @@ -1,6 +1,6 @@ // g_phys.c -#include "g_local.h" +#include "header/local.h" /* diff --git a/src/g_save.c b/src/g_save.c index b81fc72..9530ccd 100644 --- a/src/g_save.c +++ b/src/g_save.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" field_t fields[] = { {"classname", FOFS(classname), F_LSTRING}, diff --git a/src/g_spawn.c b/src/g_spawn.c index 3950113..89b56d0 100644 --- a/src/g_spawn.c +++ b/src/g_spawn.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" typedef struct { char *name; diff --git a/src/g_svcmds.c b/src/g_svcmds.c index d7d5901..339abf0 100644 --- a/src/g_svcmds.c +++ b/src/g_svcmds.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" diff --git a/src/g_target.c b/src/g_target.c index 29f5a8c..8fd8f74 100644 --- a/src/g_target.c +++ b/src/g_target.c @@ -1,4 +1,4 @@ -#include "g_local.h" +#include "header/local.h" /*QUAKED target_temp_entity (1 0 0) (-8 -8 -8) (8 8 8) Fire an origin based temp entity event to the clients. diff --git a/src/g_trigger.c b/src/g_trigger.c index dd10968..b6344e8 100644 --- a/src/g_trigger.c +++ b/src/g_trigger.c @@ -1,4 +1,4 @@ -#include "g_local.h" +#include "header/local.h" void InitTrigger (edict_t *self) diff --git a/src/g_utils.c b/src/g_utils.c index 23aa4bd..2983a7e 100644 --- a/src/g_utils.c +++ b/src/g_utils.c @@ -1,6 +1,6 @@ // g_utils.c -- misc utility functions for game module -#include "g_local.h" +#include "header/local.h" void G_ProjectSource (vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result) diff --git a/src/g_weapon.c b/src/g_weapon.c index 6893a2f..b6601f8 100644 --- a/src/g_weapon.c +++ b/src/g_weapon.c @@ -1,5 +1,5 @@ -#include "g_local.h" -#include "bot.h" +#include "header/local.h" +#include "header/bot.h" /* diff --git a/src/bot.h b/src/header/bot.h similarity index 99% rename from src/bot.h rename to src/header/bot.h index 9e90e26..1750fab 100644 --- a/src/bot.h +++ b/src/header/bot.h @@ -1,6 +1,6 @@ #ifndef BOTHEAD #define BOTHEAD -#include "g_local.h" +#include "../header/local.h" //general func void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point); diff --git a/src/botstr.h b/src/header/botstr.h similarity index 100% rename from src/botstr.h rename to src/header/botstr.h diff --git a/src/g_ctf.h b/src/header/ctf.h similarity index 100% rename from src/g_ctf.h rename to src/header/ctf.h diff --git a/src/game.h b/src/header/game.h similarity index 100% rename from src/game.h rename to src/header/game.h diff --git a/src/g_local.h b/src/header/local.h similarity index 99% rename from src/g_local.h rename to src/header/local.h index a4a189e..9aff669 100644 --- a/src/g_local.h +++ b/src/header/local.h @@ -1,6 +1,6 @@ // g_local.h -- local definitions for game module -#include "q_shared.h" +#include "shared.h" #ifndef G_LOCAL #define G_LOCAL @@ -12,7 +12,7 @@ #include "game.h" //ZOID -#include "p_menu.h" +#include "menu.h" //ZOID // the "gameversion" client command will print this plus compile date @@ -1252,6 +1252,6 @@ struct edict_s }; //ZOID -#include "g_ctf.h" +#include "ctf.h" //ZOID #endif \ No newline at end of file diff --git a/src/p_menu.h b/src/header/menu.h similarity index 100% rename from src/p_menu.h rename to src/header/menu.h diff --git a/src/m_player.h b/src/header/player.h similarity index 100% rename from src/m_player.h rename to src/header/player.h diff --git a/src/q_shared.h b/src/header/shared.h similarity index 100% rename from src/q_shared.h rename to src/header/shared.h diff --git a/src/m_move.c b/src/monster/move.c similarity index 98% rename from src/m_move.c rename to src/monster/move.c index 9c825b1..e0fc23f 100644 --- a/src/m_move.c +++ b/src/monster/move.c @@ -1,6 +1,6 @@ // m_move.c -- monster movement -#include "g_local.h" +#include "../header/local.h" #define STEPSIZE 18 diff --git a/src/p_client.c b/src/player/client.c similarity index 99% rename from src/p_client.c rename to src/player/client.c index aeb82b9..208e86d 100644 --- a/src/p_client.c +++ b/src/player/client.c @@ -1,6 +1,6 @@ -#include "g_local.h" -#include "m_player.h" -#include "bot.h" +#include "../header/local.h" +#include "../header/player.h" +#include "../header/bot.h" int cumsindex; diff --git a/src/p_hud.c b/src/player/hud.c similarity index 99% rename from src/p_hud.c rename to src/player/hud.c index 8f2ae7f..a5449b2 100644 --- a/src/p_hud.c +++ b/src/player/hud.c @@ -1,5 +1,5 @@ -#include "g_local.h" -#include "bot.h" +#include "../header/local.h" +#include "../header/bot.h" /* ====================================================================== diff --git a/src/p_menu.c b/src/player/menu.c similarity index 99% rename from src/p_menu.c rename to src/player/menu.c index ba0bc89..b5adf68 100644 --- a/src/p_menu.c +++ b/src/player/menu.c @@ -1,4 +1,4 @@ -#include "g_local.h" +#include "../header/local.h" void PMenu_Open(edict_t *ent, pmenu_t *entries, int cur, int num) { diff --git a/src/p_trail.c b/src/player/trail.c similarity index 98% rename from src/p_trail.c rename to src/player/trail.c index b8f72ba..60fe9e2 100644 --- a/src/p_trail.c +++ b/src/player/trail.c @@ -1,4 +1,4 @@ -#include "g_local.h" +#include "../header/local.h" /* diff --git a/src/p_view.c b/src/player/view.c similarity index 99% rename from src/p_view.c rename to src/player/view.c index 60dfe5c..386b020 100644 --- a/src/p_view.c +++ b/src/player/view.c @@ -1,7 +1,7 @@ -#include "g_local.h" -#include "m_player.h" -#include "bot.h" +#include "../header/local.h" +#include "../header/player.h" +#include "../header/bot.h" static edict_t *current_player; diff --git a/src/p_weapon.c b/src/player/weapon.c similarity index 99% rename from src/p_weapon.c rename to src/player/weapon.c index 2362173..d430584 100644 --- a/src/p_weapon.c +++ b/src/player/weapon.c @@ -1,8 +1,8 @@ // g_weapon.c -#include "g_local.h" -#include "m_player.h" -#include "bot.h" +#include "../header/local.h" +#include "../header/player.h" +#include "../header/bot.h" qboolean is_quad; // RAFAEL diff --git a/src/q_shared.c b/src/shared/shared.c similarity index 99% rename from src/q_shared.c rename to src/shared/shared.c index e1a5124..8faf20a 100644 --- a/src/q_shared.c +++ b/src/shared/shared.c @@ -1,4 +1,4 @@ -#include "q_shared.h" +#include "../header/shared.h" #define DEG2RAD( a ) ( a * M_PI ) / 180.0F