diff --git a/.gitignore b/.gitignore index 41099b16..0344d749 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,10 @@ *.mak *.mak.vpc_crc *.vpc_crc -*.a *.project -lib/ *obj_* build/ .waf* .lock-waf* __pycache__ +*.pyc diff --git a/README.md b/README.md index 2b857614..580310e7 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,19 @@ The main purpose of this repository is to port the engine for other platforms. * replace current buildsystem with waf * rewrite achivement system( to work without steam ) # How to Build? -On Linux: 1. Clone repo ( ```git clone https://github.com/nillerusr/source-engine```) 2. Run ```git submodule init && git submodule update``` -3. Build + +On Linux: ``` ./waf configure -T debug ./waf build ``` +On Linux for Android(**Note: only Android NDK r10e is supported**): +``` +export ANDROID_NDK=/path/to/ndk +./waf configure -T debug --android=armeabi-v7a,4.9,21 +./waf build +``` +On Windows: +**TODO(WAF is not configured for Windows. Use VPC as temporary solution)** diff --git a/appframework/sdlmgr.cpp b/appframework/sdlmgr.cpp index 7234f4d1..7d6f4229 100644 --- a/appframework/sdlmgr.cpp +++ b/appframework/sdlmgr.cpp @@ -56,6 +56,11 @@ COpenGLEntryPoints *gGL = NULL; const int kBogusSwapInterval = INT_MAX; +#ifdef ANDROID +static void *gl4es = NULL; +void *(*_glGetProcAddress)( const char * ); +#endif + /* From Ryan Gordon: @@ -174,7 +179,19 @@ void *VoidFnPtrLookup_GlMgr(const char *fn, bool &okay, const bool bRequired, vo return NULL; // The SDL path would work on all these platforms, if we were using SDL there, too... -#if defined( USE_SDL ) + + +#ifdef ANDROID + // SDL does the right thing, so we never need to use tier0 in this case. + if( _glGetProcAddress ) + retval = _glGetProcAddress(fn); + //printf("CDynamicFunctionOpenGL: SDL_GL_GetProcAddress(\"%s\") returned %p\n", fn, retval); + if ((retval == NULL) && (fallback != NULL)) + { + //printf("CDynamicFunctionOpenGL: Using fallback %p for \"%s\"\n", fallback, fn); + retval = fallback; + } +#elif defined( USE_SDL ) // SDL does the right thing, so we never need to use tier0 in this case. retval = SDL_GL_GetProcAddress(fn); //printf("CDynamicFunctionOpenGL: SDL_GL_GetProcAddress(\"%s\") returned %p\n", fn, retval); @@ -196,7 +213,7 @@ void *VoidFnPtrLookup_GlMgr(const char *fn, bool &okay, const bool bRequired, vo // We can't continue execution, because one or more GL function pointers will be NULL. Error( "Could not find required OpenGL entry point '%s'! Either your video card is unsupported, or your OpenGL driver needs to be updated.\n", fn); } - + return retval; } @@ -742,6 +759,18 @@ bool CSDLMgr::CreateHiddenGameWindow( const char *pTitle, int width, int height SDL_GL_MakeCurrent(m_Window, m_GLContext); +#ifdef ANDROID + gl4es = dlopen("libgl4es.so", RTLD_LAZY); + + if( gl4es ) + { + _glGetProcAddress = dlsym(gl4es, "gl4es_GetProcAddress" ); + void (*initialize_gl4es)( ); + initialize_gl4es = dlsym(gl4es, "initialize_gl4es" ); + initialize_gl4es(); + } +#endif + // !!! FIXME: note for later...we never delete this context anywhere, I think. // !!! FIXME: when we do get around to that, don't forget to delete/NULL gGL! @@ -762,7 +791,7 @@ bool CSDLMgr::CreateHiddenGameWindow( const char *pTitle, int width, int height #endif // DBGFLAG_ASSERT gGL = GetOpenGLEntryPoints(VoidFnPtrLookup_GlMgr); - + // It is now safe to call any base GL entry point that's supplied by gGL. // You still need to explicitly test for extension entry points, though! diff --git a/common/freetype/config/ftconfig.h b/common/freetype/config/ftconfig.h index 8d4a074b..5e19c414 100644 --- a/common/freetype/config/ftconfig.h +++ b/common/freetype/config/ftconfig.h @@ -1,7 +1,11 @@ #ifndef __FTCONFIG_H__MULTILIB #define __FTCONFIG_H__MULTILIB +#ifdef ANDROID +#include +#else #include +#endif #if __WORDSIZE == 32 # include "ftconfig-32.h" diff --git a/datacache/wscript b/datacache/wscript index 81bd128f..3cb9a277 100755 --- a/datacache/wscript +++ b/datacache/wscript @@ -35,6 +35,9 @@ def build(bld): libs = ['tier0','tier1','tier2','tier3'] + if bld.env.DEST_OS == 'android': + libs += ['ANDROID_SUPPORT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/datamodel/dmattribute.cpp b/datamodel/dmattribute.cpp index ba295924..3569b4dc 100644 --- a/datamodel/dmattribute.cpp +++ b/datamodel/dmattribute.cpp @@ -2898,7 +2898,7 @@ void CDmaDecorator::Init( CDmElement *pOwner, const char *pAttributeName, i { Assert( pOwner ); this->m_pAttribute = pOwner->AddExternalAttribute( pAttributeName, CDmAttributeInfo >::AttributeType(), &Value() ); - Assert( m_pAttribute ); + Assert( this->m_pAttribute ); if ( nFlags ) { this->m_pAttribute->AddFlag( nFlags ); diff --git a/engine/wscript b/engine/wscript index 0e48ae14..29a03ad8 100755 --- a/engine/wscript +++ b/engine/wscript @@ -323,12 +323,15 @@ def build(bld): '../common', 'audio', 'audio/public', - 'audio/private' + 'audio/private', ] defines = [] - libs = ['tier0','vgui_controls','dmxloader','tier1','tier2','tier3','bitmap','vstdlib','appframework','datamodel','vtf','mathlib','steam_api','matsys_controls','BZ2','SDL2','JPEG','ZLIB','OPENAL','CURL'] + libs = ['tier0','vgui_controls','dmxloader','tier1','tier2','tier3','bitmap','vstdlib','appframework','datamodel','vtf','mathlib','steam_api','matsys_controls','BZ2','SDL2','JPEG','ZLIB','OPENAL','CURL' ] + + if bld.env.DEST_OS == 'android': + libs += ['SSL', 'CRYPTO'] # android curl was built with openssl install_path = bld.env.LIBDIR diff --git a/filesystem/basefilesystem.cpp b/filesystem/basefilesystem.cpp index 4423cb4c..c33b9582 100644 --- a/filesystem/basefilesystem.cpp +++ b/filesystem/basefilesystem.cpp @@ -3770,8 +3770,10 @@ bool CBaseFileSystem::IsFileWritable( char const *pFileName, char const *pPathID { #ifdef WIN32 if( buf.st_mode & _S_IWRITE ) -#elif LINUX +#elif defined (LINUX) && !defined (ANDROID) if( buf.st_mode & S_IWRITE ) +#elif ANDROID + if( buf.st_mode & S_IWUSR ) #else if( buf.st_mode & S_IWRITE ) #endif @@ -3792,8 +3794,10 @@ bool CBaseFileSystem::IsFileWritable( char const *pFileName, char const *pPathID { #ifdef WIN32 if ( buf.st_mode & _S_IWRITE ) -#elif LINUX +#elif defined (LINUX) && !defined (ANDROID) if ( buf.st_mode & S_IWRITE ) +#elif ANDROID + if ( buf.st_mode & S_IWUSR ) #else if ( buf.st_mode & S_IWRITE ) #endif @@ -3812,6 +3816,8 @@ bool CBaseFileSystem::SetFileWritable( char const *pFileName, bool writable, con #ifdef _WIN32 int pmode = writable ? ( _S_IWRITE | _S_IREAD ) : ( _S_IREAD ); +#elif ANDROID + int pmode = writable ? ( S_IWUSR | S_IRUSR ) : ( S_IRUSR ); #else int pmode = writable ? ( S_IWRITE | S_IREAD ) : ( S_IREAD ); #endif @@ -5062,13 +5068,15 @@ CSysModule *CBaseFileSystem::LoadModule( const char *pFileName, const char *pPat #ifdef POSIX - Q_snprintf( tempPathID, sizeof(tempPathID), "lib%s", pFileName ); - pModule = Sys_LoadModule( tempPathID ); if( !pModule ) -#endif { - pModule = Sys_LoadModule( pFileName ); + Q_snprintf( tempPathID, sizeof(tempPathID), "lib%s", pFileName ); + pModule = Sys_LoadModule( tempPathID ); } +#endif + + if( !pModule ) + pModule = Sys_LoadModule( pFileName ); return pModule; } diff --git a/filesystem/filesystem_stdio.cpp b/filesystem/filesystem_stdio.cpp index 43916fe3..3bb7c5b5 100644 --- a/filesystem/filesystem_stdio.cpp +++ b/filesystem/filesystem_stdio.cpp @@ -972,7 +972,11 @@ void CStdioFile::FS_fclose() AUTO_LOCK( m_MutexLockedFD ); struct _stat buf; +#ifdef ANDROID + int fd = fileno( m_pFile ); // need to test this +#else int fd = fileno_unlocked( m_pFile ); +#endif fstat( fd, &buf ); fflush( m_pFile ); diff --git a/filesystem/packfile.cpp b/filesystem/packfile.cpp index 5190959a..f18fa0e7 100644 --- a/filesystem/packfile.cpp +++ b/filesystem/packfile.cpp @@ -879,10 +879,10 @@ int64 CZipPackFileHandle::AbsoluteBaseOffset() return m_pOwner->GetPackFileBaseOffset() + m_nBase; } -#if defined( _DEBUG ) && !defined( OSX ) +#if defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) #include static std::atomic sLZMAPackFileHandles( 0 ); -#endif // defined( _DEBUG ) && !defined( OSX ) +#endif // defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) CLZMAZipPackFileHandle::CLZMAZipPackFileHandle( CZipPackFile* pOwner, int64 nBase, unsigned int nOriginalSize, unsigned int nCompressedSize, unsigned int nIndex, unsigned int nFilePointer ) @@ -892,7 +892,7 @@ CLZMAZipPackFileHandle::CLZMAZipPackFileHandle( CZipPackFile* pOwner, int64 nBas m_pLZMAStream( NULL ), m_nSeekPosition( 0 ), m_nOriginalSize( nOriginalSize ) { Reset(); -#if defined( _DEBUG ) && !defined( OSX ) +#if defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) if ( ++sLZMAPackFileHandles == PACKFILE_COMPRESSED_FILE_HANDLES_WARNING ) { // By my count a live filehandle is currently around 270k, mostly due to the LZMA dictionary (256k) with the @@ -901,17 +901,17 @@ CLZMAZipPackFileHandle::CLZMAZipPackFileHandle( CZipPackFile* pOwner, int64 nBas "These carry large buffers around, and can cause high memory usage\n", PACKFILE_COMPRESSED_FILE_HANDLES_WARNING ); } -#endif // defined( _DEBUG ) && !defined( OSX ) +#endif // defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) } CLZMAZipPackFileHandle::~CLZMAZipPackFileHandle() { delete m_pLZMAStream; m_pLZMAStream = NULL; -#if defined( _DEBUG ) && !defined( OSX ) +#if defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) sLZMAPackFileHandles--; Assert( sLZMAPackFileHandles >= 0 ); -#endif // defined( _DEBUG ) && !defined( OSX ) +#endif // defined( _DEBUG ) && !defined( OSX ) && !defined( ANDROID ) } int CLZMAZipPackFileHandle::Read( void* pBuffer, int nDestSize, int nBytes ) diff --git a/game/client/mumble.cpp b/game/client/mumble.cpp index 8e58bc22..73c03647 100644 --- a/game/client/mumble.cpp +++ b/game/client/mumble.cpp @@ -98,6 +98,8 @@ void CMumbleSystem::LevelInitPostEntity() g_hMapObject = NULL; return; } +#elif defined( ANDROID ) + return; // TODO(JusicP): implement #elif defined( POSIX ) char memname[256]; V_sprintf_safe( memname, "/MumbleLink.%d", getuid() ); diff --git a/game/client/wscript b/game/client/wscript index b4f81d2f..db939982 100755 --- a/game/client/wscript +++ b/game/client/wscript @@ -559,7 +559,9 @@ def build(bld): 'RT' ] - install_path = bld.env.PREFIX+'/hl2/bin' + install_path = bld.env.PREFIX + if bld.env.DEST_OS != 'android': + install_path += '/hl2/bin' bld.shlib( source = source, diff --git a/game/server/wscript b/game/server/wscript index f22a0a42..ff4e2b09 100755 --- a/game/server/wscript +++ b/game/server/wscript @@ -602,7 +602,9 @@ def build(bld): libs = ['tier0','particles','dmxloader','tier1','tier2','tier3','mathlib','vstdlib','choreoobjects','steam_api'] - install_path = bld.env.PREFIX+'/hl2/bin' + install_path = bld.env.PREFIX + if bld.env.DEST_OS != 'android': + install_path += '/hl2/bin' bld.shlib( source = source, diff --git a/gameui/wscript b/gameui/wscript index d508bbd9..76473ce2 100755 --- a/gameui/wscript +++ b/gameui/wscript @@ -107,7 +107,7 @@ def build(bld): defines = [] - libs = ['tier0','vgui_controls','tier1','tier2','tier3','vstdlib','vtf','bitmap','mathlib','SDL2','steam_api','matsys_controls','JPEG','PNG'] + libs = ['tier0','vgui_controls','tier1','tier2','tier3','vstdlib','vtf','bitmap','mathlib','SDL2','steam_api','matsys_controls','JPEG','PNG','ZLIB'] install_path = bld.env.LIBDIR diff --git a/launcher/android.cpp b/launcher/android.cpp new file mode 100644 index 00000000..a9b38527 --- /dev/null +++ b/launcher/android.cpp @@ -0,0 +1,145 @@ +#ifdef ANDROID + +#include +#include +#include +#include +#include +#include +#include + + +#include "tier0/threadtools.h" + +char *LauncherArgv[512]; +char java_args[4096]; +int iLastArgs = 0; + +#define TAG "SRCENG" +#define PRIO ANDROID_LOG_DEBUG +#define LogPrintf(...) do { __android_log_print(PRIO, TAG, __VA_ARGS__); printf( __VA_ARGS__); } while( 0 ); +#define DLLEXPORT extern "C" __attribute__((visibility("default"))) + +DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setDataDirectoryPath(JNIEnv *env, jclass *clazz, jstring path) +{ + setenv( "APP_DATA_PATH", env->GetStringUTFChars(path, NULL), 1); + LogPrintf( "Java_com_valvesoftware_ValveActivity2_setDataDirectoryPath: %s", getenv("APP_DATA_PATH") ); +} + +DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setGameDirectoryPath(JNIEnv *env, jclass *clazz, jstring path) +{ + LogPrintf( "Java_com_valvesoftware_ValveActivity2_setGameDirectoryPath" ); + setenv( "VALVE_GAME_PATH", env->GetStringUTFChars(path, NULL), 1 ); +} + +DLLEXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over) +{ + LogPrintf( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) ); + return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over ); +} + +DLLEXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult() +{ + LogPrintf( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" ); +} + +void parseArgs( char *args ) +{ + char *pch; + pch = strtok (args," "); + while (pch != NULL) + { + LauncherArgv[iLastArgs++] = pch; + pch = strtok (NULL, " "); + } +} + +DLLEXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str) +{ + strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args ); +} + +DLLEXPORT int LauncherMain( int argc, char **argv ); + +#define A(a,b) LauncherArgv[iLastArgs++] = (char*)a; \ + LauncherArgv[iLastArgs++] = (char*)b + +#define D(a) LauncherArgv[iLastArgs++] = (char*)a + +void SetLauncherArgs() +{ + static char binPath[2048]; + snprintf(binPath, sizeof binPath, "%s/hl2_linux", getenv("APP_DATA_PATH") ); + LogPrintf(binPath); + D(binPath); + + parseArgs(java_args); + + A("-game", "hl2"); + D("-window"); + D("-nosteam"); + D("-insecure"); +} + +static void *lgles; + +typedef void (*t_set_getprocaddress)(void *(*new_proc_address)(const char *)); +t_set_getprocaddress gl4es_set_getprocaddress; + +typedef void *(*t_eglGetProcAddress)( const char * ); +t_eglGetProcAddress eglGetProcAddress; + +void *GetProcAddress( const char *procname ) +{ + void *result = dlsym(lgles, procname); + if(result) + return result; + else + return eglGetProcAddress(procname); +} + +DLLEXPORT int LauncherMainAndroid( int argc, char **argv ) +{ + + SetLauncherArgs(); + + void *lgl4es = dlopen("libgl4es.so", 0); + if( !lgl4es ) + { + LogPrintf("Failed to dlopen library libgl4es.so: %s\n", dlerror()); + return 1; + } + + void *lEGL = dlopen("libEGL.so", 0); + if( !lEGL ) + { + LogPrintf("Failed to dlopen library libEGL.so: %s\n", dlerror()); + return 1; + } + + lgles = dlopen("libGLESv2.so", 0); + if( !lgles ) + { + LogPrintf("Failed to dlopen library libGLESv2.so: %s\n", dlerror()); + return 1; + } + + gl4es_set_getprocaddress = (t_set_getprocaddress)dlsym(lgl4es, "set_getprocaddress"); + eglGetProcAddress = (t_eglGetProcAddress)dlsym(lEGL, "eglGetProcAddress"); + + if( gl4es_set_getprocaddress && eglGetProcAddress ) + { + gl4es_set_getprocaddress( &GetProcAddress ); + } + else + { + LogPrintf("Failed to call set_getprocaddress\n"); + return 1; + } + + DeclareCurrentThreadIsMainThread(); // Init thread propertly on Android + + return LauncherMain(iLastArgs, LauncherArgv); +} + +#endif diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index d34ae113..5ba0ab18 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -82,6 +82,11 @@ int MessageBox( HWND hWnd, const char *message, const char *header, unsigned uTy #define RELAUNCH_FILE "/tmp/hl2_relaunch" #endif +#if defined ( ANDROID ) +#include +#include "jni.h" +#endif + // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -248,7 +253,11 @@ bool GetExecutableName( char *out, int outSize ) //----------------------------------------------------------------------------- char *GetBaseDirectory( void ) { +#ifdef ANDROID + return getenv("VALVE_GAME_PATH"); +#else return g_szBasedir; +#endif } //----------------------------------------------------------------------------- @@ -680,8 +689,7 @@ bool CSourceAppSystemGroup::Create() if ( !AddSystems( appSystems ) ) return false; - - + // This will be NULL for games that don't support VR. That's ok. Just don't load the DLL AppModule_t sourceVRModule = LoadModule( "sourcevr" DLL_EXT_STRING ); if( sourceVRModule != APP_MODULE_INVALID ) @@ -934,7 +942,9 @@ bool GrabSourceMutex() CRC32_ProcessBuffer( &gameCRC, (void *)pchGameParam, Q_strlen( pchGameParam ) ); CRC32_Final( &gameCRC ); -#ifdef LINUX +#ifdef ANDROID + return true; +#elif defined (LINUX) /* * Linux */ @@ -1175,7 +1185,7 @@ static const char *BuildCommand() // Output : int APIENTRY //----------------------------------------------------------------------------- #ifdef WIN32 -extern "C" __declspec(dllexport) int LauncherMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +extern "C" __declspec(DLL_EXPORT) int LauncherMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) #else DLL_EXPORT int LauncherMain( int argc, char **argv ) #endif @@ -1229,7 +1239,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv ) { return -1; } - + const char *filename; #ifdef WIN32 CommandLine()->CreateCmdLine( IsPC() ? VCRHook_GetCommandLine() : lpCmdLine ); @@ -1448,6 +1458,7 @@ DLL_EXPORT int LauncherMain( int argc, char **argv ) // Figure out the directory the executable is running from // and make that be the current working directory + _chdir( GetBaseDirectory() ); g_LeakDump.m_bCheckLeaks = CommandLine()->CheckParm( "-leakcheck" ) ? true : false; diff --git a/launcher/wscript b/launcher/wscript index 7af6dd6b..5beb4f91 100755 --- a/launcher/wscript +++ b/launcher/wscript @@ -19,6 +19,7 @@ def build(bld): '../public/filesystem_init.cpp', 'launcher.cpp', 'reslistgenerator.cpp', + 'android.cpp' ] includes = [ diff --git a/launcher_main/main.cpp b/launcher_main/main.cpp index 1fca6b10..90aafcc3 100644 --- a/launcher_main/main.cpp +++ b/launcher_main/main.cpp @@ -146,6 +146,7 @@ int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL #if defined( LINUX ) #include +#include static bool IsDebuggerPresent( int time ) { diff --git a/launcher_main/wscript b/launcher_main/wscript index 622952bc..11f105b0 100755 --- a/launcher_main/wscript +++ b/launcher_main/wscript @@ -15,6 +15,8 @@ def configure(conf): return def build(bld): + if bld.env.DEST_OS == 'android': + return source = ['main.cpp'] includes = ['../public'] @@ -22,7 +24,7 @@ def build(bld): libs = [] if bld.env.DEST_OS != 'win32': - libs += [ 'DL' ] + libs += [ 'DL', 'LOG' ] else: libs += ['USER32', 'SHELL32'] source += ['launcher_main.rc'] diff --git a/lib/android/armeabi-v7a/libSDL2.so b/lib/android/armeabi-v7a/libSDL2.so new file mode 100755 index 00000000..fccfb169 Binary files /dev/null and b/lib/android/armeabi-v7a/libSDL2.so differ diff --git a/lib/android/armeabi-v7a/libandroid_support.a b/lib/android/armeabi-v7a/libandroid_support.a new file mode 100644 index 00000000..30a81d72 Binary files /dev/null and b/lib/android/armeabi-v7a/libandroid_support.a differ diff --git a/lib/android/armeabi-v7a/libbz2.a b/lib/android/armeabi-v7a/libbz2.a new file mode 100755 index 00000000..effd9de5 Binary files /dev/null and b/lib/android/armeabi-v7a/libbz2.a differ diff --git a/lib/android/armeabi-v7a/libcrypto.a b/lib/android/armeabi-v7a/libcrypto.a new file mode 100755 index 00000000..ccd1a094 Binary files /dev/null and b/lib/android/armeabi-v7a/libcrypto.a differ diff --git a/lib/android/armeabi-v7a/libcurl.a b/lib/android/armeabi-v7a/libcurl.a new file mode 100755 index 00000000..7ac63950 Binary files /dev/null and b/lib/android/armeabi-v7a/libcurl.a differ diff --git a/lib/android/armeabi-v7a/libexpat.a b/lib/android/armeabi-v7a/libexpat.a new file mode 100755 index 00000000..f2a28a73 Binary files /dev/null and b/lib/android/armeabi-v7a/libexpat.a differ diff --git a/lib/android/armeabi-v7a/libfreetype2.a b/lib/android/armeabi-v7a/libfreetype2.a new file mode 100755 index 00000000..e27727e8 Binary files /dev/null and b/lib/android/armeabi-v7a/libfreetype2.a differ diff --git a/lib/android/armeabi-v7a/libjpeg.a b/lib/android/armeabi-v7a/libjpeg.a new file mode 100755 index 00000000..95f1be07 Binary files /dev/null and b/lib/android/armeabi-v7a/libjpeg.a differ diff --git a/lib/android/armeabi-v7a/libopenal.a b/lib/android/armeabi-v7a/libopenal.a new file mode 100755 index 00000000..7ab7cd9f Binary files /dev/null and b/lib/android/armeabi-v7a/libopenal.a differ diff --git a/lib/android/armeabi-v7a/libpng.a b/lib/android/armeabi-v7a/libpng.a new file mode 100755 index 00000000..f2f75054 Binary files /dev/null and b/lib/android/armeabi-v7a/libpng.a differ diff --git a/lib/android/armeabi-v7a/libssl.a b/lib/android/armeabi-v7a/libssl.a new file mode 100755 index 00000000..47f090bb Binary files /dev/null and b/lib/android/armeabi-v7a/libssl.a differ diff --git a/lib/android/x86/libandroid_support.a b/lib/android/x86/libandroid_support.a new file mode 100644 index 00000000..5d405f85 Binary files /dev/null and b/lib/android/x86/libandroid_support.a differ diff --git a/materialsystem/shaderapidx9/wscript b/materialsystem/shaderapidx9/wscript index 168d8539..d1126bb9 100755 --- a/materialsystem/shaderapidx9/wscript +++ b/materialsystem/shaderapidx9/wscript @@ -15,7 +15,7 @@ def configure(conf): conf.env.append_unique('DEFINES',[ 'SHADERAPIDX9', 'SHADER_DLL_EXPORT', - 'PROTECTED_THINGS_ENABLE', + #'PROTECTED_THINGS_ENABLE', # conflicts with stlport 'strncpy=use_Q_strncpy_instead', '_snprintf=use_Q_snprintf_instead', 'GL_GLEXT_PROTOTYPES', @@ -58,6 +58,9 @@ def build(bld): libs = ['tier0','tier1','tier2','vstdlib','togl','bitmap','mathlib'] + if bld.env.DEST_OS == 'android': + libs += ['ANDROID_SUPPORT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/materialsystem/stdshaders/wscript b/materialsystem/stdshaders/wscript index c4a82640..66ec1c06 100644 --- a/materialsystem/stdshaders/wscript +++ b/materialsystem/stdshaders/wscript @@ -150,6 +150,9 @@ def build(bld): libs = ['tier0','shaderlib','tier1','mathlib'] + if bld.env.DEST_OS == 'android': + libs += ['ANDROID_SUPPORT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/materialsystem/wscript b/materialsystem/wscript index 4bb7d2f8..a99fb804 100755 --- a/materialsystem/wscript +++ b/materialsystem/wscript @@ -15,7 +15,7 @@ def configure(conf): conf.env.append_unique('DEFINES',[ 'DEFINE_MATERIALSYSTEM_INTERFACE', 'MATERIALSYSTEM_EXPORTS', - 'PROTECTED_THINGS_ENABLE', + #'PROTECTED_THINGS_ENABLE', # conflicts with stlport 'strncpy=use_Q_strncpy_instead', '_snprintf=use_Q_snprintf_instead' ]) diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index d6126578..2b2c2ee6 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -341,29 +341,40 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) Q_FixSlashes( exedir ); +#ifdef ANDROID + const char* libDir = "lib"; +#else + const char* libDir = "bin"; +#endif + // Return the bin directory as the executable dir if it's not in there // because that's really where we're running from... char ext[MAX_PATH]; Q_StrRight( exedir, 4, ext, sizeof( ext ) ); - if ( ext[0] != CORRECT_PATH_SEPARATOR || Q_stricmp( ext+1, "bin" ) != 0 ) + if ( ext[0] != CORRECT_PATH_SEPARATOR || Q_stricmp( ext+1, libDir ) != 0 ) { Q_strncat( exedir, CORRECT_PATH_SEPARATOR_S, exeDirLen, COPY_ALL_CHARACTERS ); - Q_strncat( exedir, "bin", exeDirLen, COPY_ALL_CHARACTERS ); + Q_strncat( exedir, libDir, exeDirLen, COPY_ALL_CHARACTERS ); Q_FixSlashes( exedir ); } - + return true; } static bool FileSystem_GetBaseDir( char *baseDir, int baseDirLen ) { +#ifdef ANDROID + strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); + return true; +#else if ( FileSystem_GetExecutableDir( baseDir, baseDirLen ) ) { Q_StripFilename( baseDir ); return true; } - + return false; +#endif } void LaunchVConfig() @@ -543,6 +554,8 @@ FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo ) if ( !FileSystem_GetBaseDir( baseDir, sizeof( baseDir ) ) ) return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); + Msg("filesystem BaseDir: %s\n", baseDir); + // The MOD directory is always the one that contains gameinfo.txt Q_strncpy( initInfo.m_ModPath, initInfo.m_pDirectoryName, sizeof( initInfo.m_ModPath ) ); diff --git a/public/tier0/memdbgon.h b/public/tier0/memdbgon.h index 9f022a09..3998b223 100644 --- a/public/tier0/memdbgon.h +++ b/public/tier0/memdbgon.h @@ -39,7 +39,9 @@ #define _NORMAL_BLOCK 1 #include + #ifndef ANDROID #include + #endif #include #include #if !defined( DID_THE_OPERATOR_NEW ) diff --git a/public/tier0/memoverride.cpp b/public/tier0/memoverride.cpp index 925f9d2a..57d3f4cb 100644 --- a/public/tier0/memoverride.cpp +++ b/public/tier0/memoverride.cpp @@ -390,7 +390,7 @@ extern "C" // ensures they are here even when linking against debug or release static libs //----------------------------------------------------------------------------- #ifndef NO_MEMOVERRIDE_NEW_DELETE -#ifdef OSX +#if defined (OSX) || defined (ANDROID) void *__cdecl operator new( size_t nSize ) throw (std::bad_alloc) #else void *__cdecl operator new( size_t nSize ) @@ -404,7 +404,7 @@ void *__cdecl operator new( size_t nSize, int nBlockUse, const char *pFileName, return g_pMemAlloc->Alloc(nSize, pFileName, nLine); } -#ifdef OSX +#if defined (OSX) || defined (ANDROID) void __cdecl operator delete( void *pMem ) throw() #else void __cdecl operator delete( void *pMem ) @@ -412,8 +412,7 @@ void __cdecl operator delete( void *pMem ) { g_pMemAlloc->Free( pMem ); } - -#ifdef OSX +#if defined (OSX) || defined (ANDROID) void operator delete(void*pMem, std::size_t) #else void operator delete(void*pMem, std::size_t) throw() @@ -422,7 +421,7 @@ void operator delete(void*pMem, std::size_t) throw() g_pMemAlloc->Free( pMem ); } -#ifdef OSX +#if defined (OSX) || defined (ANDROID) void *__cdecl operator new[]( size_t nSize ) throw (std::bad_alloc) #else void *__cdecl operator new[]( size_t nSize ) @@ -436,7 +435,7 @@ void *__cdecl operator new[] ( size_t nSize, int nBlockUse, const char *pFileNam return g_pMemAlloc->Alloc(nSize, pFileName, nLine); } -#ifdef OSX +#if defined (OSX) || defined (ANDROID) void __cdecl operator delete[]( void *pMem ) throw() #else void __cdecl operator delete[]( void *pMem ) diff --git a/public/tier1/utlvector.h b/public/tier1/utlvector.h index 6fffc6a2..7fa9687e 100644 --- a/public/tier1/utlvector.h +++ b/public/tier1/utlvector.h @@ -182,6 +182,7 @@ public: // Purges the list and calls delete on each element in it. void PurgeAndDeleteElements(); + void PurgeAndDeleteElementsArray(); // Compacts the vector to the number of elements actually in use void Compact(); @@ -475,6 +476,18 @@ public: } } + void PurgeAndDeleteElementsArray() + { + if ( m_pData != StaticData() ) + { + for( int i=0; i < m_pData->m_Size; i++ ) + { + delete[] Element(i); + } + RemoveAll(); + } + } + void FastRemove( int elem ) { Assert( IsValidIndex(elem) ); @@ -1413,6 +1426,17 @@ inline void CUtlVector::PurgeAndDeleteElements() Purge(); } +template< typename T, class A > +inline void CUtlVector::PurgeAndDeleteElementsArray() +{ + for( int i=0; i < m_Size; i++ ) + { + delete[] Element(i); + } + RemoveAll(); +} + + template< typename T, class A > inline void CUtlVector::Compact() { @@ -1441,23 +1465,16 @@ void CUtlVector::Validate( CValidator &validator, char *pchName ) } #endif // DBGFLAG_VALIDATE -// A vector class for storing pointers, so that the elements pointed to by the pointers are deleted -// on exit. -template class CUtlVectorAutoPurge : public CUtlVector< T, CUtlMemory< T, int> > -{ -public: - ~CUtlVectorAutoPurge( void ) - { - this->PurgeAndDeleteElements(); - } - -}; - // easy string list class with dynamically allocated strings. For use with V_SplitString, etc. // Frees the dynamic strings in destructor. -class CUtlStringList : public CUtlVectorAutoPurge< char *> +class CUtlStringList : public CUtlVector< char*, CUtlMemory< char*, int > > { public: + ~CUtlStringList( void ) + { + PurgeAndDeleteElementsArray(); + } + void CopyAndAddToTail( char const *pString ) // clone the string and add to the end { char *pNewStr = new char[1 + strlen( pString )]; diff --git a/scenefilecache/wscript b/scenefilecache/wscript index a63db9a9..828c06d9 100755 --- a/scenefilecache/wscript +++ b/scenefilecache/wscript @@ -13,7 +13,7 @@ def options(opt): def configure(conf): conf.define('_WINDOWS',1) # WTF? this defined in original vpc file - conf.define('PROTECTED_THINGS_ENABLE',1) + #conf.define('PROTECTED_THINGS_ENABLE',1) # conflicts with stlport def build(bld): source = [ @@ -32,6 +32,9 @@ def build(bld): libs = ['tier0','tier1'] + if bld.env.DEST_OS == 'android': + libs += ['ANDROID_SUPPORT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/scripts/waifulib/xcompile.py b/scripts/waifulib/xcompile.py index a7818911..fc5ab628 100644 --- a/scripts/waifulib/xcompile.py +++ b/scripts/waifulib/xcompile.py @@ -213,7 +213,11 @@ class Android: def system_stl(self): # TODO: proper STL support - return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')) + return [ + #os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')), + os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'stlport', 'stlport')), + os.path.abspath(os.path.join(self.ndk_home, 'sources', 'android', 'support', 'include')) + ] def libsysroot(self): arch = self.arch @@ -243,7 +247,7 @@ class Android: '-isystem', '%s/usr/include/' % (self.sysroot()) ] - cflags += ['-I%s' % (self.system_stl()), '-DANDROID', '-D__ANDROID__'] + cflags += ['-I%s'%i for i in self.system_stl()]+['-DANDROID', '-D__ANDROID__'] if cxx and not self.is_clang() and self.toolchain not in ['4.8','4.9']: cflags += ['-fno-sized-deallocation'] @@ -335,13 +339,15 @@ def configure(conf): conf.env.CXXFLAGS += android.cflags(True) conf.env.LINKFLAGS += android.linkflags() conf.env.LDFLAGS += android.ldflags() + conf.env.STLIBPATH += [os.path.abspath(os.path.join(android.ndk_home, 'sources','cxx-stl','stlport','libs',values[0]))] + conf.env.LDFLAGS += ['-lstlport_static'] conf.env.HAVE_M = True if android.is_hardfp(): conf.env.LIB_M = ['m_hard'] else: conf.env.LIB_M = ['m'] - conf.env.PREFIX = '/lib/%s' % android.apk_arch() + conf.env.PREFIX += '/lib/%s' % android.apk_arch() conf.msg('Selected Android NDK', '%s, version: %d' % (android.ndk_home, android.ndk_rev)) # no need to print C/C++ compiler, as it would be printed by compiler_c/cxx diff --git a/soundemittersystem/wscript b/soundemittersystem/wscript index 36e1e413..3da4b83a 100755 --- a/soundemittersystem/wscript +++ b/soundemittersystem/wscript @@ -14,7 +14,7 @@ def options(opt): def configure(conf): conf.define('SOUNDEMITTERSYSTEM_EXPORTS',1) conf.define('_WINDOWS',1) - conf.define('PROTECTED_THINGS_ENABLE',1) + #conf.define('PROTECTED_THINGS_ENABLE',1) # conflicts with stlport #conf.define('fopen','dont_use_fopen') # WINDOWS def build(bld): diff --git a/studiorender/wscript b/studiorender/wscript index 9d55719e..2e6d7b5c 100755 --- a/studiorender/wscript +++ b/studiorender/wscript @@ -14,7 +14,7 @@ def options(opt): def configure(conf): conf.env.append_unique('DEFINES',[ 'STUDIORENDER_EXPORTS', - 'PROTECTED_THINGS_ENABLE' + #'PROTECTED_THINGS_ENABLE' # conflicts with stlport ]) def build(bld): diff --git a/thirdparty b/thirdparty index ecce0cec..c397ca05 160000 --- a/thirdparty +++ b/thirdparty @@ -1 +1 @@ -Subproject commit ecce0cecc39b32bdf704542e3cb870ba4e2e8e42 +Subproject commit c397ca0520de10f8bf9c85fadc9fcc3055c60b0f diff --git a/tier0/dbg.cpp b/tier0/dbg.cpp index ce01801f..931ea21f 100644 --- a/tier0/dbg.cpp +++ b/tier0/dbg.cpp @@ -31,6 +31,10 @@ #include "xbox/xbox_console.h" #endif +#ifdef ANDROID +#include +#endif + #include "tier0/etwprof.h" #ifndef STEAM @@ -309,6 +313,10 @@ static SpewRetval_t _SpewMessage( SpewType_t spewType, const char *pGroupName, i nLevel }; +#ifdef ANDROID + __android_log_print( ANDROID_LOG_INFO, "SRCENG", "%s", pTempBuffer ); +#endif + g_pSpewInfo = &spewInfo; ret = s_SpewOutputFunc( spewType, pTempBuffer ); g_pSpewInfo = (int)NULL; diff --git a/tier0/platform_posix.cpp b/tier0/platform_posix.cpp index ba2783a5..9a12bc3b 100644 --- a/tier0/platform_posix.cpp +++ b/tier0/platform_posix.cpp @@ -28,6 +28,9 @@ #include #include #endif +#ifdef ANDROID +#include +#endif #include "tier0/memdbgon.h" // Benchmark mode uses this heavy-handed method diff --git a/tier0/threadtools.cpp b/tier0/threadtools.cpp index caafef6c..99da9d66 100644 --- a/tier0/threadtools.cpp +++ b/tier0/threadtools.cpp @@ -23,8 +23,13 @@ #elif defined(POSIX) #if !defined(OSX) +#if defined(ANDROID) + #include + #include +#else #include #include +#endif #define sem_unlink( arg ) #define OS_TO_PTHREAD(x) (x) #else diff --git a/tier0/wscript b/tier0/wscript index 9f6e39bb..0e9faed4 100755 --- a/tier0/wscript +++ b/tier0/wscript @@ -54,7 +54,7 @@ def build(bld): 'vcrmode_posix.cpp', #[$POSIX] 'vprof.cpp', # 'win32consoleio.cpp', [$WINDOWS] - '../tier1/pathmatch.cpp' # [$LINUXALL] + #'../tier1/pathmatch.cpp' # [$LINUXALL] ] includes = [ @@ -65,7 +65,7 @@ def build(bld): defines = [] - libs = ['DL'] + libs = ['DL', 'M', 'LOG'] install_path = bld.env.LIBDIR diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 3c91cc30..96dd90c9 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -247,8 +247,10 @@ HMODULE Sys_LoadLibrary( const char *pLibraryName, Sys_Flags flags ) #elif POSIX int dlopen_mode = RTLD_NOW; +#ifndef ANDROID if ( flags & SYS_NOLOAD ) dlopen_mode |= RTLD_NOLOAD; +#endif HMODULE ret = ( HMODULE )dlopen( str, dlopen_mode ); if ( !ret && !( flags & SYS_NOLOAD ) ) @@ -301,20 +303,34 @@ CSysModule *Sys_LoadModule( const char *pModuleName, Sys_Flags flags /* = SYS_NO size_t cCwd = strlen( szCwd ); bool bUseLibPrefix = false; - + +#ifdef ANDROID + struct stat statBuf; + char *dataPath = getenv("APP_DATA_PATH"); + + + Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/lib/lib%s", dataPath ,pModuleName); + if( stat(szAbsoluteModuleName, &statBuf) != 0 ) + Q_snprintf(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/lib/%s", dataPath ,pModuleName); +#else + #ifdef POSIX struct stat statBuf; Q_snprintf(szModuleName, sizeof(szModuleName), "bin/lib%s", pModuleName); bUseLibPrefix |= stat(szModuleName, &statBuf) == 0; #endif - if( bUseLibPrefix ) Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/lib%s", szCwd, pModuleName ); else Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/%s", szCwd, pModuleName ); +#endif // ANDROID + Msg("LoadLibrary: pModule: %s, path: %s\n", pModuleName, szAbsoluteModuleName); hDLL = Sys_LoadLibrary( szAbsoluteModuleName, flags ); } + else + Msg("LoadLibrary: path: %s\n", pModuleName); + if ( !hDLL ) { diff --git a/tier1/pathmatch.cpp b/tier1/pathmatch.cpp index bd8d3cbd..8e439dfe 100644 --- a/tier1/pathmatch.cpp +++ b/tier1/pathmatch.cpp @@ -750,7 +750,7 @@ extern "C" { return CALL(freopen)( mpath, mode, stream ); } - +#ifndef ANDROID WRAP(fopen, FILE *, const char *path, const char *mode) { // if mode does not have w, a, or +, it's open for read. @@ -788,7 +788,7 @@ extern "C" { { return __wrap_open( pathname, O_CREAT|O_WRONLY|O_TRUNC, mode ); } - +#endif int __wrap_access(const char *pathname, int mode) { return __real_access( CWrap( pathname, false ), mode ); @@ -815,6 +815,7 @@ extern "C" { { return CALL(opendir)( CWrap( name, false ) ); } +#ifndef ANDROID WRAP(__xstat, int, int __ver, __const char *__filename, struct stat *__stat_buf) { @@ -835,7 +836,7 @@ extern "C" { { return CALL(__lxstat64)( __ver, CWrap( __filename, false), __stat_buf ); } - +#endif WRAP(chmod, int, const char *path, mode_t mode) { return CALL(chmod)( CWrap( path, false), mode ); diff --git a/tier1/wscript b/tier1/wscript index c8a8673e..80a32f69 100755 --- a/tier1/wscript +++ b/tier1/wscript @@ -40,7 +40,7 @@ def build(bld): 'memstack.cpp', 'NetAdr.cpp', 'newbitbuf.cpp', - 'pathmatch.cpp', # [$LINUXALL] +# 'pathmatch.cpp', # [$LINUXALL] # 'processor_detect.cpp', # [$WINDOWS||$X360] 'processor_detect_linux.cpp', # [$POSIX] 'qsort_s.cpp', # [$LINUXALL||$PS3] diff --git a/togl/linuxwin/glentrypoints.cpp b/togl/linuxwin/glentrypoints.cpp index 25e49ab3..ef1f01ff 100644 --- a/togl/linuxwin/glentrypoints.cpp +++ b/togl/linuxwin/glentrypoints.cpp @@ -43,7 +43,7 @@ #include "tier1.h" #include "tier2/tier2.h" -#ifdef _LINUX +#if defined(_LINUX) && !defined(__ANDROID__) #include #endif @@ -296,7 +296,7 @@ static bool CheckOpenGLExtension_internal(const char *ext, const int coremajor, return false; } } -#elif !defined ( OSX ) +#elif !defined ( OSX ) && !defined( __ANDROID__ ) if (!ptr) { static CDynamicFunctionOpenGL< true, Display *( APIENTRY *)( ), Display* > glXGetCurrentDisplay("glXGetCurrentDisplay"); @@ -377,10 +377,12 @@ COpenGLEntryPoints::COpenGLEntryPoints() // !!! FIXME: hint Apple's drivers and not because we rely on the // !!! FIXME: functionality. If so, just remove this check (and the // !!! FIXME: GL_NV_fence code entirely). +#ifndef ANDROID // HACK if ((m_bHave_OpenGL) && ((!m_bHave_GL_NV_fence) && (!m_bHave_GL_ARB_sync) && (!m_bHave_GL_APPLE_fence))) { Error( "Required OpenGL extension \"GL_NV_fence\", \"GL_ARB_sync\", or \"GL_APPLE_fence\" is not supported. Please upgrade your OpenGL driver." ); } +#endif // same extension, different name. if (m_bHave_GL_EXT_vertex_array_bgra || m_bHave_GL_ARB_vertex_array_bgra) diff --git a/togl/wscript b/togl/wscript index bdce47f3..ab31edfe 100755 --- a/togl/wscript +++ b/togl/wscript @@ -13,7 +13,6 @@ def options(opt): def configure(conf): conf.define('TOGL_DLL_EXPORT',1) - conf.define('PROTECTED_THINGS_ENABLE',1) conf.env.append_unique('DEFINES',['strncpy=use_Q_strncpy_instead', '_snprintf=use_Q_snprintf_instead']) diff --git a/vgui2/vgui_surfacelib/linuxfont.cpp b/vgui2/vgui_surfacelib/linuxfont.cpp index b80d908c..f94d7a40 100644 --- a/vgui2/vgui_surfacelib/linuxfont.cpp +++ b/vgui2/vgui_surfacelib/linuxfont.cpp @@ -92,7 +92,8 @@ void CLinuxFont::CreateFontList() if ( m_FriendlyNameCache.Count() > 0 ) return; - if(!FcInit()) +#ifndef ANDROID + if(!FcInit()) return; FcConfig *config; FcPattern *pat; @@ -160,8 +161,11 @@ void CLinuxFont::CreateFontList() FcFontSetDestroy(fontset); FcObjectSetDestroy(os); FcPatternDestroy(pat); + +#endif } +#ifndef ANDROID static FcPattern* FontMatch(const char* type, FcType vtype, const void* value, ...) { @@ -204,6 +208,7 @@ static FcPattern* FontMatch(const char* type, FcType vtype, const void* value, return match; } +#endif bool CLinuxFont::CreateFromMemory(const char *windowsFontName, void *data, int datasize, int tall, int weight, int blur, int scanlines, int flags) { @@ -400,6 +405,52 @@ bool CLinuxFont::CreateFromMemory(const char *windowsFontName, void *data, int d return true; } +#ifdef ANDROID +char *FindFontAndroid(bool bBold, int italic) +{ + const char *fontFileName, *fontFileNamePost = NULL; + + fontFileName = "Roboto"; + + if( bBold ) + { + if( italic ) + fontFileNamePost = "BoldItalic"; + else + fontFileNamePost = "Bold"; + } + else if( italic ) + fontFileNamePost = "Italic"; + else + fontFileName = "Regular"; + + char dataFile[MAX_PATH]; + + if( fontFileNamePost ) + snprintf( dataFile, sizeof dataFile, "/system/fonts/%s-%s.ttf", fontFileName, fontFileNamePost ); + else + snprintf( dataFile, sizeof dataFile, "/system/fonts/%s.ttf", fontFileName ); + + if( access( dataFile, R_OK ) != 0 ) + { + fontFileNamePost = NULL; + fontFileName = "DroidSans"; + if( bBold > 500 ) + fontFileNamePost = "Bold"; + + if( fontFileNamePost ) + snprintf( dataFile, sizeof dataFile, "/system/fonts/%s-%s.ttf", fontFileName, fontFileNamePost ); + else + snprintf( dataFile, sizeof dataFile, "/system/fonts/%s.ttf", fontFileName ); + + if( access( dataFile, R_OK ) != 0 ) + return NULL; + } + + return dataFile; +} +#endif + //----------------------------------------------------------------------------- // Purpose: Given a font name from windows, match it to the filename and return that. //----------------------------------------------------------------------------- @@ -413,18 +464,24 @@ char *CLinuxFont::GetFontFileName( const char *windowsFontName, int flags ) else if ( !Q_stricmp( pchFontName, "Arial Black" ) || Q_stristr( pchFontName, "bold" ) ) bBold = true; - const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; - const int nFcWeight = bBold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL; + const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; - FcPattern *match = FontMatch( FC_FAMILY, FcTypeString, pchFontName, +#ifdef ANDROID + char *filename = FindFontAndroid( bBold, italic ); + Msg("Android font: %s", filename); + if( !filename ) return NULL; + return strdup( filename ); +#else + const int nFcWeight = bBold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL; + FcPattern *match = FontMatch( FC_FAMILY, FcTypeString, pchFontName, FC_WEIGHT, FcTypeInteger, nFcWeight, FC_SLANT, FcTypeInteger, italic, NULL); if ( !match ) - { + { AssertMsg1( false, "Unable to find font named %s\n", windowsFontName ); - return NULL; - } + return NULL; + } else { char *filenameret = NULL; @@ -440,8 +497,11 @@ char *CLinuxFont::GetFontFileName( const char *windowsFontName, int flags ) } FcPatternDestroy( match ); + Msg("Android font fc: %s", filenameret); + return filenameret; } +#endif } //----------------------------------------------------------------------------- @@ -502,7 +562,7 @@ void CLinuxFont::GetCharRGBA( wchar_t ch, int rgbaWide, int rgbaTall, unsigned c if( error == 0 ) { uint32 alpha_scale = 1; - int Width = min( rgbaWide, bitmap.width ); + int Width = MIN( rgbaWide, bitmap.width ); unsigned char *rgba = prgba + ( nSkipRows * rgbaWide * 4 ); switch( m_face->glyph->bitmap.pixel_mode ) diff --git a/vgui2/vgui_surfacelib/wscript b/vgui2/vgui_surfacelib/wscript index 44dc4e78..0de65a46 100644 --- a/vgui2/vgui_surfacelib/wscript +++ b/vgui2/vgui_surfacelib/wscript @@ -31,7 +31,7 @@ def build(bld): '../../public', '../../public/tier0', '../../public/tier1', - '../../common' + '../../common', ] + bld.env.INCLUDES_FT2 defines = [] diff --git a/vguimatsurface/wscript b/vguimatsurface/wscript index 90ebb812..7359a3ab 100644 --- a/vguimatsurface/wscript +++ b/vguimatsurface/wscript @@ -15,7 +15,7 @@ def configure(conf): conf.define('VGUIMATSURFACE_DLL_EXPORT',1) conf.define('GAMEUI_EXPORTS',1) conf.define('DONT_PROTECT_FILEIO_FUNCTIONS',1) - conf.define('PROTECTED_THINGS_ENABLE',1) + #conf.define('PROTECTED_THINGS_ENABLE',1) # conflicts with stlport def build(bld): @@ -38,13 +38,16 @@ def build(bld): '../public', '../public/tier0', '../public/tier1', - '../common' - ] + bld.env.INCLUDES_SDL2 + bld.env.INCLUDES_FREETYPE + '../common', + ] defines = [] libs = ['bitmap','mathlib','tier0','vgui_controls','tier1','vstdlib','tier2','tier3','vgui_surfacelib','FT2','FC','SDL2'] + if bld.env.DEST_OS == 'android': + libs += ['EXPAT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/vstdlib/wscript b/vstdlib/wscript index 730ab25c..3e2547af 100755 --- a/vstdlib/wscript +++ b/vstdlib/wscript @@ -40,6 +40,9 @@ def build(bld): libs = ['tier0','tier1'] + if bld.env.DEST_OS == 'android': + libs += ['ANDROID_SUPPORT'] + install_path = bld.env.LIBDIR bld.shlib( diff --git a/wscript b/wscript index ab1bcf05..0367b858 100644 --- a/wscript +++ b/wscript @@ -1,6 +1,6 @@ #! /usr/bin/env python # encoding: utf-8 -# a1batross, mittorn, nillerusr +# nillerusr from __future__ import print_function from waflib import Logs, Context, Configure @@ -86,7 +86,7 @@ projects={ 'dedicated_main', 'dmxloader', 'engine', -# 'game/server', + 'game/server', 'ivp/havana', 'ivp/havana/havok/hk_base', 'ivp/havana/havok/hk_math', @@ -154,15 +154,12 @@ def define_platform(conf): if conf.options.SDL: conf.define('USE_SDL', 1) - print(conf.env.DEST_OS) - if conf.env.DEST_OS == 'linux': conf.define('_GLIBCXX_USE_CXX11_ABI',0) conf.env.append_unique('DEFINES', [ 'LINUX=1', '_LINUX=1', 'POSIX=1', '_POSIX=1', 'GNUC', - 'NDEBUG', 'NO_HOOK_MALLOC', '_DLL_EXT=.so' ]) @@ -173,11 +170,19 @@ def define_platform(conf): 'LINUX=1', '_LINUX=1', 'POSIX=1', '_POSIX=1', 'GNUC', - 'NDEBUG', 'NO_HOOK_MALLOC', '_DLL_EXT=.so' ]) + if conf.options.DEBUG_ENGINE: + conf.env.append_unique('DEFINES', [ + 'DEBUG', '_DEBUG' + ]) + else: + conf.env.append_unique('DEFINES', [ + 'NDEBUG' + ]) + def options(opt): grp = opt.add_option_group('Common options') @@ -187,12 +192,18 @@ def options(opt): grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False, help = 'build dedicated server [default: %default]') + grp.add_option('-D', '--debug-engine', action = 'store_true', dest = 'DEBUG_ENGINE', default = False, + help = 'build with -DDEBUG [default: %default]') + grp.add_option('--use-sdl', action = 'store', dest = 'SDL', type = 'int', default = True, help = 'build engine with SDL [default: %default]') grp.add_option('--use-togl', action = 'store', dest = 'GL', type = 'int', default = True, help = 'build engine with ToGL [default: %default]') + grp.add_option('--use-ccache', action = 'store_true', dest = 'CCACHE', default = False, + help = 'build using ccache [default: %default]') + opt.load('compiler_optimizations subproject') # opt.add_subproject(projects['game']) @@ -226,20 +237,6 @@ def configure(conf): conf.load('force_32bit') - if conf.options.SDL: - conf.check_cfg(package='sdl2', uselib_store='SDL2', args=['--cflags', '--libs']) - if conf.options.DEDICATED: - conf.check_cfg(package='libedit', uselib_store='EDIT', args=['--cflags', '--libs']) - else: - conf.check_pkg('freetype2', 'FT2', FT2_CHECK) - conf.check_pkg('fontconfig', 'FC', FC_CHECK) - conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) - conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs']) - conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs']) - conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs']) - - conf.check_cfg(package='zlib', uselib_store='ZLIB', args=['--cflags', '--libs']) - compiler_optional_flags = [ '-Wall', '-fdiagnostics-color=always', @@ -258,6 +255,17 @@ def configure(conf): flags = ['-fPIC'] + if conf.env.DEST_OS == 'android': + flags += [ + '-L'+os.path.abspath('.')+'/lib/android/armeabi-v7a/', + '-I'+os.path.abspath('.')+'/thirdparty/curl/include', + '-I'+os.path.abspath('.')+'/thirdparty/SDL', + '-I'+os.path.abspath('.')+'/thirdparty/openal-soft/include/', + '-I'+os.path.abspath('.')+'/thirdparty/fontconfig', + '-I'+os.path.abspath('.')+'/thirdparty/freetype/include', + '-llog' + ] + if conf.env.DEST_CPU == 'arm': flags += ['-mfpu=neon', '-fsigned-char'] else: @@ -270,15 +278,17 @@ def configure(conf): cxxflags = list(cflags) + ['-std=c++11','-fpermissive'] if conf.env.COMPILER_CC == 'gcc': - wrapfunctions = ['freopen','fopen','open','creat','access','__xstat','stat','lstat','fopen64','open64', - 'opendir','__lxstat','chmod','chown','lchown','symlink','link','__lxstat64','mknod', - 'utimes','unlink','rename','utime','__xstat64','mount','mkfifo','mkdir','rmdir','scandir','realpath'] +# wrapfunctions = ['freopen','creat','access','__xstat','stat','lstat','fopen64','open64', +# 'opendir','__lxstat','chmod','chown','lchown','symlink','link','__lxstat64','mknod', +# 'utimes','unlink','rename','utime','__xstat64','mount','mkdir','rmdir','scandir','realpath','mkfifo'] + +# for func in wrapfunctions: +# linkflags += ['-Wl,--wrap='+func] - for func in wrapfunctions: - linkflags += ['-Wl,--wrap='+func] conf.define('COMPILER_GCC', 1) + if conf.env.COMPILER_CC != 'msvc': conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags') conf.check_cxx(cxxflags=cxxflags, linkflags=linkflags, msg='Checking for required C++ flags') @@ -296,6 +306,32 @@ def configure(conf): conf.env.append_unique('LINKFLAGS', linkflags) conf.env.append_unique('INCLUDES', [os.path.abspath('common/')]) + if conf.env.DEST_OS != 'android': + if conf.options.SDL: + conf.check_cfg(package='sdl2', uselib_store='SDL2', args=['--cflags', '--libs']) + if conf.options.DEDICATED: + conf.check_cfg(package='libedit', uselib_store='EDIT', args=['--cflags', '--libs']) + else: + conf.check_pkg('freetype2', 'FT2', FT2_CHECK) + conf.check_pkg('fontconfig', 'FC', FC_CHECK) + conf.check_cfg(package='openal', uselib_store='OPENAL', args=['--cflags', '--libs']) + conf.check_cfg(package='libjpeg', uselib_store='JPEG', args=['--cflags', '--libs']) + conf.check_cfg(package='libpng', uselib_store='PNG', args=['--cflags', '--libs']) + conf.check_cfg(package='libcurl', uselib_store='CURL', args=['--cflags', '--libs']) + conf.check_cfg(package='zlib', uselib_store='ZLIB', args=['--cflags', '--libs']) + else: + conf.check(lib='SDL2', uselib_store='SDL2') + conf.check(lib='freetype2', uselib_store='FT2') + conf.check(lib='openal', uselib_store='OPENAL') + conf.check(lib='jpeg', uselib_store='JPEG') + conf.check(lib='png', uselib_store='PNG') + conf.check(lib='curl', uselib_store='CURL') + conf.check(lib='z', uselib_store='ZLIB') + conf.check(lib='crypto', uselib_store='CRYPTO') + conf.check(lib='ssl', uselib_store='SSL') + conf.check(lib='expat', uselib_store='EXPAT') + conf.check(lib='android_support', uselib_store='ANDROID_SUPPORT') + if conf.env.DEST_OS != 'win32': conf.check_cc(lib='dl', mandatory=False) conf.check_cc(lib='bz2', mandatory=False) @@ -336,12 +372,19 @@ def configure(conf): else: conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX + if conf.options.CCACHE: + conf.env.CC.insert(0, 'ccache') + conf.env.CXX.insert(0, 'ccache') + print( conf.env ) + if conf.options.DEDICATED: conf.add_subproject(projects['dedicated']) else: conf.add_subproject(projects['game']) def build(bld): + os.environ["CCACHE_DIR"] = os.path.abspath('.ccache/'+bld.env.COMPILER_CC+'/'+bld.env.DEST_OS+'/'+bld.env.DEST_CPU) + if bld.env.DEDICATED: bld.add_subproject(projects['dedicated']) else: