From 7f00e9354d4e40e30e3e25ff0eb656a6422951c6 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Fri, 18 Jun 2021 09:26:24 +0200 Subject: [PATCH] Add shared/platform.h which will send hints as to what target platform we're dealing with (pc, touch, web, console etc.) --- src/gs-entbase/shared/baseentity.qc | 19 +++++----- src/menu-fn/includes.src | 1 + src/menu-fn/m_customgame.qc | 2 +- src/shared/defs.h | 3 +- src/shared/platform.h | 59 +++++++++++++++++++++++++++++ src/shared/player.qc | 8 ++-- 6 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 src/shared/platform.h diff --git a/src/gs-entbase/shared/baseentity.qc b/src/gs-entbase/shared/baseentity.qc index ab1b227c..243a5448 100644 --- a/src/gs-entbase/shared/baseentity.qc +++ b/src/gs-entbase/shared/baseentity.qc @@ -272,9 +272,9 @@ CBaseEntity::ReceiveEntity(float flChanged) origin[2] = readcoord(); } if (flChanged & BASEFL_CHANGED_ANGLES) { - angles[0] = readshort() / (65535/360); - angles[1] = readshort() / (65535/360); - angles[2] = readshort() / (65535/360); + angles[0] = readshort() / (32767 / 360); + angles[1] = readshort() / (32767 / 360); + angles[2] = readshort() / (32767 / 360); } if (flChanged & BASEFL_CHANGED_MODELINDEX) { setmodelindex(this, readshort()); @@ -473,12 +473,9 @@ CBaseEntity::SendEntity(entity ePEnt, float fChanged) WriteCoord(MSG_ENTITY, origin[2]); } if (fChanged & BASEFL_CHANGED_ANGLES) { - angles[0] = Math_FixDelta(angles[0]); - angles[1] = Math_FixDelta(angles[1]); - angles[2] = Math_FixDelta(angles[2]); - WriteShort(MSG_ENTITY, angles[0] * (65535/360)); - WriteShort(MSG_ENTITY, angles[1] * (65535/360)); - WriteShort(MSG_ENTITY, angles[2] * (65535/360)); + WriteShort(MSG_ENTITY, angles[0] * 32767 / 360); + WriteShort(MSG_ENTITY, angles[1] * 32767 / 360); + WriteShort(MSG_ENTITY, angles[2] * 32767 / 360); } if (fChanged & BASEFL_CHANGED_MODELINDEX) { WriteShort(MSG_ENTITY, modelindex); @@ -566,6 +563,10 @@ CBaseEntity::ParentUpdate(void) SendFlags |= BASEFL_CHANGED_ORIGIN; } if (net_angles != angles) { + angles[0] = Math_FixDelta(angles[0]); + angles[1] = Math_FixDelta(angles[1]); + angles[2] = Math_FixDelta(angles[2]); + net_angles = angles; SendFlags |= BASEFL_CHANGED_ANGLES; } diff --git a/src/menu-fn/includes.src b/src/menu-fn/includes.src index dec88db2..c285e346 100644 --- a/src/menu-fn/includes.src +++ b/src/menu-fn/includes.src @@ -2,6 +2,7 @@ ../shared/fteextensions.qc ../shared/math.h ../shared/math.qc +../shared/platform.h defs.h bitmaps.h strings.h diff --git a/src/menu-fn/m_customgame.qc b/src/menu-fn/m_customgame.qc index 70b5a484..73f70ee1 100644 --- a/src/menu-fn/m_customgame.qc +++ b/src/menu-fn/m_customgame.qc @@ -250,8 +250,8 @@ filestream games_find_in_gamedir(string filename, string gamedirname) { searchhandle sh; - filestream fh; searchhandle psh; + filestream fh; /* first let's see if we've got a liblist.gam just floating inside the gamedir */ sh = search_begin(filename, SB_FULLPACKAGEPATH | SB_FORCESEARCH, FALSE, gamedirname); diff --git a/src/shared/defs.h b/src/shared/defs.h index 4255c824..88daf660 100644 --- a/src/shared/defs.h +++ b/src/shared/defs.h @@ -27,6 +27,7 @@ #include "pmove.h" #include "memory.h" #include "spectator.h" +#include "platform.h" #define BSPVER_PREREL 28 #define BSPVER_Q1 29 @@ -39,7 +40,7 @@ #define CLASSEXPORT(classname,classa) void classname(void) { spawnfunc_##classa(); } -#define printf(a) print(sprintf(a)) +#define printf(x, ...) print(sprintf(x, ...)) const vector VEC_HULL_MIN = [-16,-16,-36]; const vector VEC_HULL_MAX = [16,16,36]; diff --git a/src/shared/platform.h b/src/shared/platform.h new file mode 100644 index 00000000..3bd32baf --- /dev/null +++ b/src/shared/platform.h @@ -0,0 +1,59 @@ + +typedef enum +{ + PLATFORM_UNINITIALIZED = -1, + PLATFORM_UNKNOWN = 0, + PLATFORM_PC, + PLATFORM_CONSOLE, + PLATFORM_TOUCH, + PLATFORM_WEB +} platform; + +var platform g_platform = PLATFORM_UNINITIALIZED; + +/* fast way to query which system we're on */ +platform +Platform_GetPlatform(void) +{ + if (g_platform == PLATFORM_UNINITIALIZED) { + string osname = cvar_string("sys_platform"); + g_platform = PLATFORM_UNKNOWN; + + switch (osname) { + case "Web": + g_platform = PLATFORM_WEB; + break; + case "WinCE": + case "Xbox": + g_platform = PLATFORM_CONSOLE; + break; + case "WinRT": + case "iOSSim": + case "iOS": + case "Android": + g_platform = PLATFORM_TOUCH; + break; + case "Unknown": + case "Nacl": + case "Win": + case "Win16": + case "Cygwin": + case "Linux": + case "Mac": + case "Apple": + case "FreeBSD": + case "OpenBSD": + case "NetBSD": + case "BSD": + case "MorphOS": + case "AmigaOS": + case "MacOS X": + case "Dos": + default: + g_platform = PLATFORM_PC; + break; + } + } + + return g_platform; +} diff --git a/src/shared/player.qc b/src/shared/player.qc index 61a6ef0f..b55d72a3 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -49,9 +49,9 @@ base_player::ReceiveEntity(float new, float fl) if (fl & PLAYER_ORIGIN_Z) origin[2] = readcoord(); if (fl & PLAYER_ANGLES_X) - pitch = readshort() / (65535/360); + pitch = readshort() / (32767 / 360); if (fl & PLAYER_ANGLES_Y) - angles[1] = readshort() / (65535/360); + angles[1] = readshort() / (32767 / 360); if (fl & PLAYER_COLORMAP) colormap = readfloat(); @@ -288,9 +288,9 @@ base_player::SendEntity(entity ePEnt, float fChanged) WriteCoord(MSG_ENTITY, origin[2]); if (fChanged & PLAYER_ANGLES_X) - WriteShort(MSG_ENTITY, v_angle[0] * (65535/360)); + WriteShort(MSG_ENTITY, v_angle[0] * 32767 / 360); if (fChanged & PLAYER_ANGLES_Y) - WriteShort(MSG_ENTITY, angles[1] * (65535/360)); + WriteShort(MSG_ENTITY, angles[1] * 32767 / 360); if (fChanged & PLAYER_COLORMAP) WriteFloat(MSG_ENTITY, colormap);