Port common.h and system.h. Add backends.h, defaults.h, port.h, xash3d_types.h from fork

This commit is contained in:
Alibek Omarov 2018-04-13 19:56:43 +03:00
parent a639b72e90
commit 25325e6150
7 changed files with 460 additions and 41 deletions

47
common/backends.h Normal file
View File

@ -0,0 +1,47 @@
/*
backends.h - backend macro definations
Copyright (C) 2016 Mittorn
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef BACKENDS_H
#define BACKENDS_H
// video backends (XASH_VIDEO)
#define VIDEO_NULL 0
#define VIDEO_SDL 1
#define VIDEO_ANDROID 2
// audio backends (XASH_SOUND)
#define SOUND_NULL 0
#define SOUND_SDL 1
#define SOUND_OPENSLES 2
// crash handler (XASH_CRASHHANDLER)
#define CRASHHANDLER_NULL 0
#define CRASHHANDLER_UCONTEXT 1
#define CRASHHANDLER_DBGHELP 2
#define CRASHHANDLER_WIN32 3
// input (XASH_INPUT)
#define INPUT_NULL 0
#define INPUT_SDL 1
#define INPUT_ANDROID 2
// timer (XASH_TIMER)
#define TIMER_NULL 0 // not used
#define TIMER_SDL 1
#define TIMER_LINUX 2
#define TIMER_WIN32 3
#endif /* BACKENDS_H */

View File

@ -732,14 +732,7 @@ typedef int string_t;
typedef unsigned char byte;
typedef unsigned short word;
#undef true
#undef false
#ifndef __cplusplus
typedef enum { false, true } qboolean;
#else
typedef int qboolean;
#endif
#include "xash3d_types.h"
typedef struct
{
@ -776,4 +769,4 @@ typedef struct
int hitgroup; // 0 == generic, non zero is specific body part
} trace_t;
#endif//CONST_H
#endif//CONST_H

159
common/defaults.h Normal file
View File

@ -0,0 +1,159 @@
/*
defaults.h - set up default configuration
Copyright (C) 2016 Mittorn
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef DEFAULTS_H
#define DEFAULTS_H
#include "backends.h"
/*
===================================================================
SETUP BACKENDS DEFINATIONS
===================================================================
*/
#ifndef XASH_DEDICATED
#ifdef XASH_SDL
// by default, use SDL subsystems
#ifndef XASH_VIDEO
#define XASH_VIDEO VIDEO_SDL
#endif // XASH_VIDEO
#ifndef XASH_TIMER
#define XASH_TIMER TIMER_SDL
#endif
#ifndef XASH_INPUT
#define XASH_INPUT INPUT_SDL
#endif
#ifndef XASH_SOUND
#define XASH_SOUND SOUND_SDL
#endif
#endif //XASH_SDL
#if defined __ANDROID__ && !defined XASH_SDL
#ifndef XASH_VIDEO
#define XASH_VIDEO VIDEO_ANDROID
#endif
#ifndef XASH_TIMER
#define XASH_TIMER TIMER_LINUX
#endif
#ifndef XASH_INPUT
#define XASH_INPUT INPUT_ANDROID
#endif
#ifndef XASH_SOUND
#define XASH_SOUND SOUND_OPENSLES
#endif
#endif // android case
#endif // XASH_DEDICATED
// select crashhandler based on defines
#ifndef XASH_CRASHHANDLER
#ifdef _WIN32
#ifdef DBGHELP
#define XASH_CRASHHANDLER CRASHHANDLER_DBGHELP
#endif
#elif defined CRASHHANDLER
#define XASH_CRASHHANDLER CRASHHANDLER_UCONTEXT
#else
#define XASH_CRASHHANDLER CRASHHANDLER_NULL
#endif
#endif
// no timer - no xash
#ifndef XASH_TIMER
#ifdef _WIN32
#define XASH_TIMER TIMER_WIN32
#else
#define XASH_TIMER TIMER_LINUX
#endif
#endif
//
// fallback to NULL
//
#ifndef XASH_VIDEO
#define XASH_VIDEO VIDEO_NULL
#endif
#ifndef XASH_SOUND
#define XASH_SOUND SOUND_NULL
#endif
#ifndef XASH_INPUT
#define XASH_INPUT INPUT_NULL
#endif
/*
=========================================================================
Default build-depended cvar and constant values
=========================================================================
*/
#if defined __ANDROID__ || TARGET_OS_IPHONE
#define DEFAULT_TOUCH_ENABLE "1"
#define DEFAULT_M_IGNORE "1"
#else
#define DEFAULT_TOUCH_ENABLE "0"
#define DEFAULT_M_IGNORE "0"
#endif
#if defined __ANDROID__ || TARGET_OS_IPHONE || defined __EMSCRIPTEN__
#define XASH_INTERNAL_GAMELIBS
// this means that libraries are provided with engine, but not in game data
// You need add library loading code to library.c when adding new platform
#endif
#if defined XASH_NANOGL || defined XASH_WES || defined XASH_REGAL
#define XASH_GL_STATIC
#endif
#define DEFAULT_SV_MASTER "ms.xash.su:27010"
// Set ForceSimulating to 1 by default for dedicated, because AMXModX timers require this
// TODO: enable simulating for any server?
#ifdef XASH_DEDICATED
#define DEFAULT_SV_FORCESIMULATING "1"
#else
#define DEFAULT_SV_FORCESIMULATING "0"
#endif
// allow override for developer/debug builds
#ifndef DEFAULT_DEV
#define DEFAULT_DEV 0
#endif
#ifndef DEFAULT_FULLSCREEN
#define DEFAULT_FULLSCREEN 1
#endif
#if TARGET_OS_IPHONE
#define DEFAULT_CON_MAXFRAC "0.5"
#else
#define DEFAULT_CON_MAXFRAC "1"
#endif
#endif // DEFAULTS_H

149
common/port.h Normal file
View File

@ -0,0 +1,149 @@
/*
port.h -- Portability Layer for Windows types
Copyright (C) 2015 Alibek Omarov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#pragma once
#ifndef PORT_H
#define PORT_H
#if defined(__LP64__) || defined(__LLP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define XASH_64BIT
#endif
#ifdef XASH_64BIT
#define ARCH_SUFFIX "64"
#else
#define ARCH_SUFFIX
#endif
#if defined(__ANDROID__) || TARGET_OS_IOS
#define XASH_MOBILE_PLATFORM
#endif
#if !defined(_WIN32)
#include <limits.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#if defined(__APPLE__)
#include <sys/syslimits.h>
#define OS_LIB_EXT "dylib"
#define OPEN_COMMAND "open"
#include "TargetConditionals.h"
#else
#define OS_LIB_EXT "so"
#define OPEN_COMMAND "xdg-open"
#endif
#if defined(__ANDROID__)
#if defined(LOAD_HARDFP)
#define POSTFIX "_hardfp"
#else
#define POSTFIX
#endif
// don't change these names
#define MENUDLL "libmenu" POSTFIX "." OS_LIB_EXT
#define CLIENTDLL "libclient" POSTFIX "." OS_LIB_EXT
#define SERVERDLL "libserver" POSTFIX "." OS_LIB_EXT
#define GAMEPATH "/sdcard/xash"
#else
#define MENUDLL "libxashmenu" ARCH_SUFFIX "." OS_LIB_EXT
#define CLIENTDLL "client" ARCH_SUFFIX "." OS_LIB_EXT
#endif
#define VGUI_SUPPORT_DLL "libvgui_support." OS_LIB_EXT
// Windows-specific
#define __cdecl
#define _inline static inline
#define O_BINARY 0 // O_BINARY is Windows extension
#define O_TEXT 0 // O_TEXT is Windows extension
// Windows functions to Linux equivalent
#define _mkdir( x ) mkdir( x, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH )
#define LoadLibrary( x ) dlopen( x, RTLD_NOW )
#define GetProcAddress( x, y ) dlsym( x, y )
#define SetCurrentDirectory( x ) (!chdir( x ))
#define FreeLibrary( x ) dlclose( x )
//#define MAKEWORD( a, b ) ((short int)(((unsigned char)(a))|(((short int)((unsigned char)(b)))<<8)))
#define max( a, b ) (((a) > (b)) ? (a) : (b))
#define min( a, b ) (((a) < (b)) ? (a) : (b))
#define tell( a ) lseek(a, 0, SEEK_CUR)
typedef unsigned char BYTE;
typedef short int WORD;
typedef unsigned int DWORD;
typedef int LONG;
typedef unsigned int ULONG;
typedef int WPARAM;
typedef unsigned int LPARAM;
typedef void* HANDLE;
typedef void* HMODULE;
typedef void* HINSTANCE;
typedef char* LPSTR;
typedef struct tagPOINT
{
int x, y;
} POINT;
#else // WIN32
#ifdef __MINGW32__
#define _inline static inline
#endif
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define open _open
#define read _read
// shut-up compiler warnings
#pragma warning(disable : 4244) // MIPS
#pragma warning(disable : 4018) // signed/unsigned mismatch
#pragma warning(disable : 4305) // truncation from const double to float
#pragma warning(disable : 4115) // named type definition in parentheses
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4057) // differs in indirection to slightly different base types
#pragma warning(disable : 4201) // nonstandard extension used
#pragma warning(disable : 4706) // assignment within conditional expression
#pragma warning(disable : 4054) // type cast' : from function pointer
#pragma warning(disable : 4310) // cast truncates constant value
#define HSPRITE WINAPI_HSPRITE
#include <windows.h>
#undef HSPRITE
#define OS_LIB_EXT "dll"
#define MENUDLL "menu"ARCH_SUFFIX"." OS_LIB_EXT
#define CLIENTDLL "client"ARCH_SUFFIX"." OS_LIB_EXT
#define VGUI_SUPPORT_DLL "../vgui_support." OS_LIB_EXT
#ifdef XASH_64BIT
// windows NameForFunction not implemented yet
#define XASH_ALLOW_SAVERESTORE_OFFSETS
#endif
#endif //WIN32
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef USHRT_MAX
#define USHRT_MAX 65535
#endif
#endif // PORT_H

33
common/xash3d_types.h Normal file
View File

@ -0,0 +1,33 @@
// basic typedefs
#ifndef XASH_TYPES_H
#define XASH_TYPES_H
typedef unsigned char byte;
typedef int sound_t;
typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef vec_t quat_t[4];
typedef byte rgba_t[4]; // unsigned byte colorpack
typedef byte rgb_t[3]; // unsigned byte colorpack
typedef vec_t matrix3x4[3][4];
typedef vec_t matrix4x4[4][4];
#undef true
#undef false
#ifndef __cplusplus
typedef enum { false, true } qboolean;
#else
typedef int qboolean;
#endif
#if _MSC_VER == 1200
typedef __int64 integer64; //msvc6
#elif defined (XASH_SDL)
typedef Uint64 integer64;
#else
typedef unsigned long long integer64;
#endif
typedef integer64 longtime_t;
#endif // XASH_TYPES_H

View File

@ -36,21 +36,53 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc
===================================================================================================================================
*/
// configuration
#define HACKS_RELATED_HLMODS // some HL-mods works differently under Xash and can't be fixed without some hacks at least at current time
#include "port.h"
// disable some warnings
#pragma warning(disable : 4244) // MIPS
#pragma warning(disable : 4018) // signed/unsigned mismatch
#pragma warning(disable : 4305) // truncation from const double to float
#pragma warning(disable : 4115) // named type definition in parentheses
#pragma warning(disable : 4100) // unreferenced formal parameter
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(disable : 4057) // differs in indirection to slightly different base types
#pragma warning(disable : 4201) // nonstandard extension used
#pragma warning(disable : 4706) // assignment within conditional expression
#pragma warning(disable : 4054) // type cast' : from function pointer
#pragma warning(disable : 4310) // cast truncates constant value
#include "backends.h"
#include "defaults.h"
#include <stdio.h>
#include <stdlib.h> // rand, adbs
#include <stdarg.h> // va
#ifndef _WIN32
#include <stddef.h> // size_t
#ifdef __i386__
#define EXPORT __attribute__ ((visibility ("default"),force_align_arg_pointer))
#else
#define EXPORT __attribute__ ((visibility ("default")))
#endif
#else
#include <sys/types.h> // off_t
#define EXPORT __declspec( dllexport )
#endif
// configuration
//
// check if selected backend not allowed
//
#if XASH_TIMER == TIMER_NULL
#error "Please select timer backend"
#endif
#ifndef XASH_DEDICATED
#if XASH_VIDEO == VIDEO_NULL
#error "Please select video backend"
#endif
#endif
#ifndef XASH_SDL
#if XASH_TIMER == TIMER_SDL || XASH_VIDEO == VIDEO_SDL || XASH_SOUND == SOUND_SDL || XASH_INPUT == INPUT_SDL
#error "SDL backends without XASH_SDL not allowed"
#endif
#endif
#define HACKS_RELATED_HLMODS // some HL-mods works differently under Xash and can't be fixed without some hacks at least at current time
#define MAX_STRING 256 // generic string
#define MAX_INFO_STRING 256 // infostrings are transmitted across network
@ -62,8 +94,7 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc
#define MAX_MODS 512 // environment games that engine can keep visible
#define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions
#define EXPORT __declspec( dllexport )
#define BIT( n ) (1<<( n ))
#define BIT( n ) ( 1 << ( n ))
#define GAMMA ( 2.2 ) // Valve Software gamma
#define INVGAMMA ( 1.0 / 2.2 ) // back to 1.0
#define TEXGAMMA ( 0.9 ) // compensate dim textures
@ -367,8 +398,6 @@ typedef struct
typedef struct host_parm_s
{
HINSTANCE hInst;
HANDLE hMutex;
LPTOP_LEVEL_EXCEPTION_FILTER oldFilter;
host_status_t status; // global host state
game_status_t game; // game manager
@ -397,7 +426,7 @@ typedef struct host_parm_s
vec3_t player_mins[MAX_MAP_HULLS]; // 4 hulls allowed
vec3_t player_maxs[MAX_MAP_HULLS]; // 4 hulls allowed
HWND hWnd; // main window
void* hWnd; // main window
qboolean allow_console; // allow console in dev-mode or multiplayer game
qboolean allow_console_init; // initial value to allow the console
qboolean key_overstrike; // key overstrike mode

View File

@ -20,24 +20,34 @@ GNU General Public License for more details.
extern "C" {
#endif
#include "port.h"
#include <setjmp.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#define MSGBOX( x ) MessageBox( NULL, x, "Xash Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP )
#ifdef XASH_SDL
#include <SDL_messagebox.h>
#define MSGBOX( x ) SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, "Xash Error", x, NULL )
#define MSGBOX2( x ) SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, "Host Error", x, host.hWnd )
#define MSGBOX3( x ) SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, "Host Recursive Error", x, host.hWnd )
#elif defined(__ANDROID__) && !defined(XASH_DEDICATED)
#define MSGBOX( x ) Android_MessageBox( "Xash Error", x )
#define MSGBOX2( x ) Android_MessageBox( "Host Error", x )
#define MSGBOX3( x ) Android_MessageBox( "Host Recursive Error", x )
#elif defined _WIN32
#define MSGBOX( x ) MessageBox( NULL, x, "Xash Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP )
#define MSGBOX2( x ) MessageBox( host.hWnd, x, "Host Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP )
#define MSGBOX3( x ) MessageBox( host.hWnd, x, "Host Recursive Error", MB_OK|MB_SETFOREGROUND|MB_ICONSTOP )
#else
#define BORDER1 "======================================\n"
#define MSGBOX( x ) fprintf( stderr, BORDER1 "Xash Error: %s\n" BORDER1, x )
#define MSGBOX2( x ) fprintf( stderr, BORDER1 "Host Error: %s\n" BORDER1, x )
#define MSGBOX3( x ) fprintf( stderr, BORDER1 "Host Recursive Error: %s\n" BORDER1, x )
#endif
// basic typedefs
typedef int sound_t;
typedef float vec_t;
typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4];
typedef byte rgba_t[4]; // unsigned byte colorpack
typedef vec_t matrix3x4[3][4];
typedef vec_t matrix4x4[4][4];
#include "xash3d_types.h"
#include "const.h"
@ -77,7 +87,6 @@ void* Sys_GetProcAddress( dll_info_t *dll, const char* name );
qboolean Sys_FreeLibrary( dll_info_t *dll );
void Sys_ParseCommandLine( LPSTR lpCmdLine, qboolean uncensored );
void Sys_MergeCommandLine( LPSTR lpCmdLine );
long _stdcall Sys_Crash( PEXCEPTION_POINTERS pInfo );
void Sys_SetClipboardData( const byte *buffer, size_t size );
#define Sys_GetParmFromCmdLine( parm, out ) _Sys_GetParmFromCmdLine( parm, out, sizeof( out ))
qboolean _Sys_GetParmFromCmdLine( char *parm, char *out, size_t size );
@ -109,4 +118,4 @@ void MsgDev( int level, const char *pMsg, ... );
#ifdef __cplusplus
}
#endif
#endif//SYSTEM_H
#endif//SYSTEM_H