diff --git a/project/jni/application/teeworlds-0.5.2/AndroidAppSettings.cfg b/project/jni/application/teeworlds-0.5.2/AndroidAppSettings.cfg deleted file mode 100644 index 21e6e5df3..000000000 --- a/project/jni/application/teeworlds-0.5.2/AndroidAppSettings.cfg +++ /dev/null @@ -1,47 +0,0 @@ -# The application settings for Android libSDL port -AppSettingVersion=17 -LibSdlVersion=1.2 -AppName="TeeWorlds" -AppFullName=com.teeworlds -ScreenOrientation=h -InhibitSuspend=n -AppDataDownloadUrl="Game data|teeworlds.zip" -VideoDepthBpp=16 -NeedDepthBuffer=n -NeedStencilBuffer=n -NeedGles2=n -SwVideoMode=n -SdlVideoResize=n -SdlVideoResizeKeepAspect=n -CompatibilityHacks=n -CompatibilityHacksStaticInit=n -CompatibilityHacksTextInputEmulatesHwKeyboard=n -AppUsesMouse=y -AppNeedsTwoButtonMouse=y -ShowMouseCursor=n -ForceRelativeMouseMode=y -AppNeedsArrowKeys=y -AppNeedsTextInput=y -AppUsesJoystick=y -AppHandlesJoystickSensitivity=n -AppUsesMultitouch=n -NonBlockingSwapBuffers=n -RedefinedKeys="SPACE RETURN LEFT RIGHT LSHIFT ESCAPE RSHIFT LSHIFT" -AppTouchscreenKeyboardKeysAmount=6 -AppTouchscreenKeyboardKeysAmountAutoFire=0 -RedefinedKeysScreenKb="SPACE RETURN LEFT RIGHT RSHIFT LSHIFT" -StartupMenuButtonTimeout=3000 -HiddenMenuOptions='OptionalDownloadConfig DisplaySizeConfig' -FirstStartMenuOptions='' -MultiABI=y -AppVersionCode=5207 -AppVersionName="0.5.2.07" -ResetSdlConfigForThisVersion=n -DeleteFilesOnUpgrade="%" -CompiledLibraries="sdl_image freetype" -CustomBuildScript=n -AppCflags='-O3' -AppLdflags='' -AppSubdirsBuild='' -AppCmdline='' -ReadmeText='^You may press "Home" now - the data will be downloaded in background' diff --git a/project/jni/application/teeworlds-0.5.2/AndroidData/teeworlds.zip b/project/jni/application/teeworlds-0.5.2/AndroidData/teeworlds.zip deleted file mode 100644 index e5480c23d..000000000 Binary files a/project/jni/application/teeworlds-0.5.2/AndroidData/teeworlds.zip and /dev/null differ diff --git a/project/jni/application/teeworlds-0.5.2/icon.png b/project/jni/application/teeworlds-0.5.2/icon.png deleted file mode 100644 index 78936fa81..000000000 Binary files a/project/jni/application/teeworlds-0.5.2/icon.png and /dev/null differ diff --git a/project/jni/application/teeworlds-0.5.2/license.txt b/project/jni/application/teeworlds-0.5.2/license.txt deleted file mode 100644 index e1d5c2cac..000000000 --- a/project/jni/application/teeworlds-0.5.2/license.txt +++ /dev/null @@ -1,28 +0,0 @@ -Copyright (C) 2007-2010 Magnus Auvinen - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. - ------------------------------------------------------------------------- - -IMPORTANT NOTE! The source under src/engine/external are stripped -libraries with their own licenses. Mostly BSD or zlib/libpng license but -check the individual libraries. - ------------------------------------------------------------------------- - -With that being said, contact us if there is anything you want to do -that the license does not premit. diff --git a/project/jni/application/teeworlds-0.5.2/readme.txt b/project/jni/application/teeworlds-0.5.2/readme.txt deleted file mode 100644 index a56a3981d..000000000 --- a/project/jni/application/teeworlds-0.5.2/readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -Copyright (c) 2010 Magnus Auvinen - - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - - -Please visit http://www.teeworlds.com for up-to-date information about -the game, including new versions, custom maps and much more. diff --git a/project/jni/application/teeworlds-0.5.2/src/base/detect.h b/project/jni/application/teeworlds-0.5.2/src/base/detect.h deleted file mode 100644 index 2369c8fe0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/base/detect.h +++ /dev/null @@ -1,134 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef BASELIB_FILE_CONFIG_H -#define BASELIB_FILE_CONFIG_H - -/* - this file detected the family, platform and architecture - to compile for. -*/ - -/* platforms */ - -/* windows Family */ -#if defined(WIN64) || defined(_WIN64) - /* Hmm, is this IA64 or x86-64? */ - #define CONF_FAMILY_WINDOWS 1 - #define CONF_FAMILY_STRING "windows" - #define CONF_PLATFORM_WIN64 1 - #define CONF_PLATFORM_STRING "win64" -#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__) - #define CONF_FAMILY_WINDOWS 1 - #define CONF_FAMILY_STRING "windows" - #define CONF_PLATFORM_WIN32 1 - #define CONF_PLATFORM_STRING "win32" -#endif - -/* unix family */ -#if defined(__FreeBSD__) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFORM_FREEBSD 1 - #define CONF_PLATFORM_STRING "freebsd" -#endif - -#if defined(__OpenBSD__) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFORM_OPENBSD 1 - #define CONF_PLATFORM_STRING "openbsd" -#endif - -#if defined(__LINUX__) || defined(__linux__) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFORM_LINUX 1 - #define CONF_PLATFORM_STRING "linux" -#endif - -#if defined(MACOSX) || defined(__APPLE__) || defined(__DARWIN__) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFORM_MACOSX 1 - #define CONF_PLATFORM_STRING "macosx" -#endif - -#if defined(__sun) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFROM_SOLARIS 1 - #define CONF_PLATFORM_STRING "solaris" -#endif - -/* beos family */ -#if defined(__BeOS) || defined(__BEOS__) - #define CONF_FAMILY_BEOS 1 - #define CONF_FAMILY_STRING "beos" - #define CONF_PLATFORM_BEOS 1 - #define CONF_PLATFORM_STRING "beos" -#endif - -#if defined(ANDROID) - #define CONF_FAMILY_UNIX 1 - #define CONF_FAMILY_STRING "unix" - #define CONF_PLATFORM_LINUX 1 - #define CONF_PLATFORM_STRING "android" -#endif - - -/* architectures */ -#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(CONF_PLATFORM_WIN32) - #define CONF_ARCH_IA32 1 - #define CONF_ARCH_STRING "ia32" - #define CONF_ARCH_ENDIAN_LITTLE 1 -#endif - -#if defined(__ia64__) - #define CONF_ARCH_IA64 1 - #define CONF_ARCH_STRING "ia64" - #define CONF_ARCH_ENDIAN_LITTLE 1 -#endif - -#if defined(__amd64__) || defined(__x86_64__) - #define CONF_ARCH_AMD64 1 - #define CONF_ARCH_STRING "amd64" - #define CONF_ARCH_ENDIAN_LITTLE 1 -#endif - -#if defined(__powerpc__) || defined(__ppc__) - #define CONF_ARCH_PPC 1 - #define CONF_ARCH_STRING "ppc" - #define CONF_ARCH_ENDIAN_BIG 1 -#endif - -#if defined(__sparc__) - #define CONF_ARCH_SPARC 1 - #define CONF_ARCH_STRING "sparc" - #define CONF_ARCH_ENDIAN_BIG 1 -#endif - -#if defined(__ARMEB__) - #define CONF_ARCH_ARM 1 - #define CONF_ARCH_STRING "arm" - #define CONF_ARCH_ENDIAN_BIG 1 -#endif - -#if defined(__ARMEL__) - #define CONF_ARCH_ARM 1 - #define CONF_ARCH_STRING "arm" - #define CONF_ARCH_ENDIAN_LITTLE 1 -#endif - - -#ifndef CONF_FAMILY_STRING -#define CONF_FAMILY_STRING "unknown" -#endif - -#ifndef CONF_PLATFORM_STRING -#define CONF_PLATFORM_STRING "unknown" -#endif - -#ifndef CONF_ARCH_STRING -#define CONF_ARCH_STRING "unknown" -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/base/math.hpp b/project/jni/application/teeworlds-0.5.2/src/base/math.hpp deleted file mode 100644 index 302935d76..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/base/math.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef BASE_MATH_H -#define BASE_MATH_H - -#include - -template -inline T clamp(T val, T min, T max) -{ - if(val < min) - return min; - if(val > max) - return max; - return val; -} - -inline float sign(float f) -{ - return f<0.0f?-1.0f:1.0f; -} - -inline int round(float f) -{ - if(f > 0) - return (int)(f+0.5f); - return (int)(f-0.5f); -} - -template -inline T mix(const T a, const T b, TB amount) -{ - return a + (b-a)*amount; -} - -inline float frandom() { return rand()/(float)(RAND_MAX); } - -// float to fixed -inline int f2fx(float v) { return (int)(v*(float)(1<<10)); } -inline float fx2f(int v) { return v*(1.0f/(1<<10)); } - -class fxp -{ - int value; -public: - void set(int v) { value = v; } - int get() const { return value; } - fxp &operator = (int v) { value = v<<10; return *this; } - fxp &operator = (float v) { value = (int)(v*(float)(1<<10)); return *this; } - operator float() const { return value/(float)(1<<10); } -}; - -class tune_param -{ - int value; -public: - void set(int v) { value = v; } - int get() const { return value; } - tune_param &operator = (int v) { value = (int)(v*100.0f); return *this; } - tune_param &operator = (float v) { value = (int)(v*100.0f); return *this; } - operator float() const { return value/100.0f; } -}; - -const float pi = 3.1415926535897932384626433f; - -template inline T min(T a, T b) { return a inline T max(T a, T b) { return a>b?a:b; } - -#endif // BASE_MATH_H diff --git a/project/jni/application/teeworlds-0.5.2/src/base/system.cpp b/project/jni/application/teeworlds-0.5.2/src/base/system.cpp deleted file mode 100644 index 1a20fedc7..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/base/system.cpp +++ /dev/null @@ -1,1200 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include -#include -#include - -/*#include "detect.h"*/ -#include "system.h" -/*#include "e_console.h"*/ - -#if defined(CONF_FAMILY_UNIX) - #include - #include - - /* unix net includes */ - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #include - - #if defined(CONF_PLATFORM_MACOSX) - #include - #endif -#ifdef ANDROID - #include -#endif - -#elif defined(CONF_FAMILY_WINDOWS) - #define WIN32_LEAN_AND_MEAN - #define _WIN32_WINNT 0x0501 /* required for mingw to get getaddrinfo to work */ - #include - #include - #include - #include - #include - #include - #include - - #define EWOULDBLOCK WSAEWOULDBLOCK -#else - #error NOT IMPLEMENTED -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -IOHANDLE io_stdin() { return (IOHANDLE)stdin; } -IOHANDLE io_stdout() { return (IOHANDLE)stdout; } -IOHANDLE io_stderr() { return (IOHANDLE)stderr; } - -static DBG_LOGGER loggers[16]; -static int num_loggers = 0; - -static NETSTATS network_stats = {0}; -static MEMSTATS memory_stats = {0}; - -void dbg_logger(DBG_LOGGER logger) -{ - loggers[num_loggers++] = logger; -} - -void dbg_assert_imp(const char *filename, int line, int test, const char *msg) -{ - if(!test) - { - dbg_msg("assert", "%s(%d): %s", filename, line, msg); - dbg_break(); - } -} - -void dbg_break() -{ - *((unsigned*)0) = 0x0; -} - -void dbg_msg(const char *sys, const char *fmt, ...) -{ - va_list args; - char str[1024*4]; - char *msg; - int i, len; - - str_format(str, sizeof(str), "[%08x][%s]: ", (int)time(0), sys); - len = strlen(str); - msg = (char *)str + len; - - va_start(args, fmt); -#if defined(CONF_FAMILY_WINDOWS) - _vsnprintf(msg, sizeof(str)-len, fmt, args); -#else - vsnprintf(msg, sizeof(str)-len, fmt, args); -#endif - va_end(args); - - for(i = 0; i < num_loggers; i++) - loggers[i](str); -} - -static void logger_stdout(const char *line) -{ - printf("%s\n", line); - fflush(stdout); -#ifdef ANDROID - __android_log_print(ANDROID_LOG_INFO, "Teeworlds", "%s", line); -#endif - -} - -static void logger_debugger(const char *line) -{ -#if defined(CONF_FAMILY_WINDOWS) - OutputDebugString(line); - OutputDebugString("\n"); -#endif -} - - -IOHANDLE logfile = 0; -static void logger_file(const char *line) -{ - io_write(logfile, line, strlen(line)); - io_write(logfile, "\n", 1); - io_flush(logfile); -} - -void dbg_logger_stdout() { dbg_logger(logger_stdout); } -void dbg_logger_debugger() { dbg_logger(logger_debugger); } -void dbg_logger_file(const char *filename) -{ - logfile = io_open(filename, IOFLAG_WRITE); - if(logfile) - dbg_logger(logger_file); - else - dbg_msg("dbg/logger", "failed to open '%s' for logging", filename); - -} - -/* */ - -int memory_alloced = 0; - -typedef struct MEMHEADER -{ - const char *filename; - int line; - int size; - struct MEMHEADER *prev; - struct MEMHEADER *next; -} MEMHEADER; - -typedef struct MEMTAIL -{ - int guard; -} MEMTAIL; - -static struct MEMHEADER *first = 0; -static const int MEM_GUARD_VAL = 0xbaadc0de; - -void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment) -{ - /* TODO: fix alignment */ - /* TODO: add debugging */ - MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); - MEMTAIL *tail = (struct MEMTAIL *)(((char*)(header+1))+size); - header->size = size; - header->filename = filename; - header->line = line; - - memory_stats.allocated += header->size; - memory_stats.total_allocations++; - memory_stats.active_allocations++; - - tail->guard = MEM_GUARD_VAL; - - header->prev = (MEMHEADER *)0; - header->next = first; - if(first) - first->prev = header; - first = header; - - /*dbg_msg("mem", "++ %p", header+1); */ - return header+1; -} - -void mem_free(void *p) -{ - if(p) - { - MEMHEADER *header = (MEMHEADER *)p - 1; - MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size); - - if(tail->guard != MEM_GUARD_VAL) - dbg_msg("mem", "!! %p", p); - /* dbg_msg("mem", "-- %p", p); */ - memory_stats.allocated -= header->size; - memory_stats.active_allocations--; - - if(header->prev) - header->prev->next = header->next; - else - first = header->next; - if(header->next) - header->next->prev = header->prev; - - free(header); - } -} - -void mem_debug_dump() -{ - char buf[1024]; - MEMHEADER *header = first; - IOHANDLE f = io_open("memory.txt", IOFLAG_WRITE); - - while(header) - { - str_format(buf, sizeof(buf), "%s(%d): %d\n", header->filename, header->line, header->size); - io_write(f, buf, strlen(buf)); - header = header->next; - } - - io_close(f); -} - - -void mem_copy(void *dest, const void *source, unsigned size) -{ - memcpy(dest, source, size); -} - -void mem_move(void *dest, const void *source, unsigned size) -{ - memmove(dest, source, size); -} - -void mem_zero(void *block,unsigned size) -{ - memset(block, 0, size); -} - -int mem_check_imp() -{ - MEMHEADER *header = first; - while(header) - { - MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size); - if(tail->guard != MEM_GUARD_VAL) - { - dbg_msg("mem", "Memory check failed at %s(%d): %d", header->filename, header->line, header->size); - return 0; - } - header = header->next; - } - - return 1; -} - -IOHANDLE io_open(const char *filename, int flags) -{ - if(flags == IOFLAG_READ) - return (IOHANDLE)fopen(filename, "rb"); - if(flags == IOFLAG_WRITE) - return (IOHANDLE)fopen(filename, "wb"); - return 0x0; -} - -unsigned io_read(IOHANDLE io, void *buffer, unsigned size) -{ - return fread(buffer, 1, size, (FILE*)io); -} - -unsigned io_skip(IOHANDLE io, unsigned size) -{ - fseek((FILE*)io, size, SEEK_CUR); - return size; -} - -int io_seek(IOHANDLE io, int offset, int origin) -{ - int real_origin; - - switch(origin) - { - case IOSEEK_START: - real_origin = SEEK_SET; - break; - case IOSEEK_CUR: - real_origin = SEEK_CUR; - break; - case IOSEEK_END: - real_origin = SEEK_END; - } - - return fseek((FILE*)io, offset, origin); -} - -long int io_tell(IOHANDLE io) -{ - return ftell((FILE*)io); -} - -long int io_length(IOHANDLE io) -{ - long int length; - io_seek(io, 0, IOSEEK_END); - length = io_tell(io); - io_seek(io, 0, IOSEEK_START); - return length; -} - -unsigned io_write(IOHANDLE io, const void *buffer, unsigned size) -{ - return fwrite(buffer, 1, size, (FILE*)io); -} - -int io_close(IOHANDLE io) -{ - fclose((FILE*)io); - return 1; -} - -int io_flush(IOHANDLE io) -{ - fflush((FILE*)io); - return 0; -} - -void *thread_create(void (*threadfunc)(void *), void *u) -{ -#if defined(CONF_FAMILY_UNIX) - pthread_t id; - pthread_create(&id, NULL, (void *(*)(void*))threadfunc, u); - return (void*)id; -#elif defined(CONF_FAMILY_WINDOWS) - return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc, u, 0, NULL); -#else - #error not implemented -#endif -} - -void thread_wait(void *thread) -{ -#if defined(CONF_FAMILY_UNIX) - pthread_join((pthread_t)thread, NULL); -#elif defined(CONF_FAMILY_WINDOWS) - WaitForSingleObject((HANDLE)thread, INFINITE); -#else - #error not implemented -#endif -} - -void thread_destroy(void *thread) -{ -#if defined(CONF_FAMILY_UNIX) - void *r = 0; - pthread_join((pthread_t)thread, &r); -#else - /*#error not implemented*/ -#endif -} - -void thread_yield() -{ -#if defined(CONF_FAMILY_UNIX) - sched_yield(); -#elif defined(CONF_FAMILY_WINDOWS) - Sleep(0); -#else - #error not implemented -#endif -} - -void thread_sleep(int milliseconds) -{ -#if defined(CONF_FAMILY_UNIX) - usleep(milliseconds*1000); -#elif defined(CONF_FAMILY_WINDOWS) - Sleep(milliseconds); -#else - #error not implemented -#endif -} - - - - -#if defined(CONF_FAMILY_UNIX) -typedef pthread_mutex_t LOCKINTERNAL; -#elif defined(CONF_FAMILY_WINDOWS) -typedef CRITICAL_SECTION LOCKINTERNAL; -#else - #error not implemented on this platform -#endif - -LOCK lock_create() -{ - LOCKINTERNAL *lock = (LOCKINTERNAL*)mem_alloc(sizeof(LOCKINTERNAL), 4); - -#if defined(CONF_FAMILY_UNIX) - pthread_mutex_init(lock, 0x0); -#elif defined(CONF_FAMILY_WINDOWS) - InitializeCriticalSection((LPCRITICAL_SECTION)lock); -#else - #error not implemented on this platform -#endif - return (LOCK)lock; -} - -void lock_destroy(LOCK lock) -{ -#if defined(CONF_FAMILY_UNIX) - pthread_mutex_destroy((LOCKINTERNAL *)lock); -#elif defined(CONF_FAMILY_WINDOWS) - DeleteCriticalSection((LPCRITICAL_SECTION)lock); -#else - #error not implemented on this platform -#endif - mem_free(lock); -} - -int lock_try(LOCK lock) -{ -#if defined(CONF_FAMILY_UNIX) - return pthread_mutex_trylock((LOCKINTERNAL *)lock); -#elif defined(CONF_FAMILY_WINDOWS) - return TryEnterCriticalSection((LPCRITICAL_SECTION)lock); -#else - #error not implemented on this platform -#endif -} - -void lock_wait(LOCK lock) -{ -#if defined(CONF_FAMILY_UNIX) - pthread_mutex_lock((LOCKINTERNAL *)lock); -#elif defined(CONF_FAMILY_WINDOWS) - EnterCriticalSection((LPCRITICAL_SECTION)lock); -#else - #error not implemented on this platform -#endif -} - -void lock_release(LOCK lock) -{ -#if defined(CONF_FAMILY_UNIX) - pthread_mutex_unlock((LOCKINTERNAL *)lock); -#elif defined(CONF_FAMILY_WINDOWS) - LeaveCriticalSection((LPCRITICAL_SECTION)lock); -#else - #error not implemented on this platform -#endif -} - -/* ----- time ----- */ -int64 time_get() -{ -#if defined(CONF_FAMILY_UNIX) - struct timeval val; - gettimeofday(&val, NULL); - return (int64)val.tv_sec*(int64)1000000+(int64)val.tv_usec; -#elif defined(CONF_FAMILY_WINDOWS) - static int64 last = 0; - int64 t; - QueryPerformanceCounter((PLARGE_INTEGER)&t); - if(tsin_family = AF_INET; - p->sin_port = htons(src->port); - p->sin_addr.s_addr = htonl(src->ip[0]<<24|src->ip[1]<<16|src->ip[2]<<8|src->ip[3]); -} - -static void sockaddr_to_netaddr(const struct sockaddr *src, NETADDR *dst) -{ - /* TODO: IPv6 support */ - unsigned int ip = htonl(((struct sockaddr_in*)src)->sin_addr.s_addr); - mem_zero(dst, sizeof(NETADDR)); - dst->type = NETTYPE_IPV4; - dst->port = htons(((struct sockaddr_in*)src)->sin_port); - dst->ip[0] = (unsigned char)((ip>>24)&0xFF); - dst->ip[1] = (unsigned char)((ip>>16)&0xFF); - dst->ip[2] = (unsigned char)((ip>>8)&0xFF); - dst->ip[3] = (unsigned char)(ip&0xFF); -} - -int net_addr_comp(const NETADDR *a, const NETADDR *b) -{ - return mem_comp(a, b, sizeof(NETADDR)); -} - -void net_addr_str(const NETADDR *addr, char *string, int max_length) -{ - if(addr->type == NETTYPE_IPV4) - str_format(string, max_length, "%d.%d.%d.%d:%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3], addr->port); - else if(addr->type == NETTYPE_IPV6) - { - str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d", - (addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7], - (addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15], - addr->port); - } - else - str_format(string, max_length, "unknown type %d", addr->type); -} - -int net_host_lookup(const char *hostname, NETADDR *addr, int types) -{ - /* TODO: IPv6 support */ - struct addrinfo hints; - struct addrinfo *result; - int e; - - mem_zero(&hints, sizeof(hints)); - hints.ai_family = AF_INET; - - e = getaddrinfo(hostname, NULL, &hints, &result); - if(e != 0 || !result) - return -1; - - sockaddr_to_netaddr(result->ai_addr, addr); - freeaddrinfo(result); - addr->port = 0; - return 0; -} - -static int parse_int(int *out, const char **str) -{ - int i = 0; - *out = 0; - if(**str < '0' || **str > '9') - return -1; - - i = **str - '0'; - (*str)++; - - while(1) - { - if(**str < '0' || **str > '9') - { - *out = i; - return 0; - } - - i = (i*10) + (**str - '0'); - (*str)++; - } - - return 0; -} - -static int parse_char(char c, const char **str) -{ - if(**str != c) return -1; - (*str)++; - return 0; -} - -static int parse_uint8(unsigned char *out, const char **str) -{ - int i; - if(parse_int(&i, str) != 0) return -1; - if(i < 0 || i > 0xff) return -1; - *out = i; - return 0; -} - -static int parse_uint16(unsigned short *out, const char **str) -{ - int i; - if(parse_int(&i, str) != 0) return -1; - if(i < 0 || i > 0xffff) return -1; - *out = i; - return 0; -} - -int net_addr_from_str(NETADDR *addr, const char *string) -{ - const char *str = string; - mem_zero(addr, sizeof(NETADDR)); - - if(str[0] == '[') - { - /* TODO: ipv6 */ - } - else - { - /* ipv4 */ - if(parse_uint8(&addr->ip[0], &str)) return -1; - if(parse_char('.', &str)) return -1; - if(parse_uint8(&addr->ip[1], &str)) return -1; - if(parse_char('.', &str)) return -1; - if(parse_uint8(&addr->ip[2], &str)) return -1; - if(parse_char('.', &str)) return -1; - if(parse_uint8(&addr->ip[3], &str)) return -1; - if(*str == ':') - { - str++; - if(parse_uint16(&addr->port, &str)) return -1; - } - - addr->type = NETTYPE_IPV4; - } - - return 0; -} - - -NETSOCKET net_udp_create(NETADDR bindaddr) -{ - /* TODO: IPv6 support */ - struct sockaddr addr; - unsigned int mode = 1; - int broadcast = 1; - - /* create socket */ - int sock = socket(AF_INET, SOCK_DGRAM, 0); - if(sock < 0) - return NETSOCKET_INVALID; - - /* bind, we should check for error */ - netaddr_to_sockaddr(&bindaddr, &addr); - if(bind(sock, &addr, sizeof(addr)) != 0) - { - net_udp_close(sock); - return NETSOCKET_INVALID; - } - - /* set non-blocking */ -#if defined(CONF_FAMILY_WINDOWS) - ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); -#else - ioctl(sock, FIONBIO, (unsigned long *)&mode); -#endif - - /* set boardcast */ - setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); - - /* return */ - return sock; -} - -int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size) -{ - struct sockaddr sa; - int d; - mem_zero(&sa, sizeof(sa)); - netaddr_to_sockaddr(addr, &sa); - d = sendto((int)sock, (const char*)data, size, 0, &sa, sizeof(sa)); - /*if(d < 0) - { - char addrstr[256]; - net_addr_str(addr, addrstr, sizeof(addrstr)); - - dbg_msg("net", "sendto error %d %x", d, d); - dbg_msg("net", "\tsock = %d %x", sock, sock); - dbg_msg("net", "\tsize = %d %x", size, size); - dbg_msg("net", "\taddr = %s", addrstr); - - }*/ - network_stats.sent_bytes += size; - network_stats.sent_packets++; - return d; -} - -int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize) -{ - struct sockaddr from; - int bytes; - socklen_t fromlen = sizeof(struct sockaddr); - bytes = recvfrom(sock, (char*)data, maxsize, 0, &from, &fromlen); - if(bytes > 0) - { - sockaddr_to_netaddr(&from, addr); - network_stats.recv_bytes += bytes; - network_stats.recv_packets++; - return bytes; - } - else if(bytes == 0) - return 0; - return -1; /* error */ -} - -int net_udp_close(NETSOCKET sock) -{ -#if defined(CONF_FAMILY_WINDOWS) - closesocket(sock); -#else - close((int)sock); -#endif - return 0; -} - -NETSOCKET net_tcp_create(const NETADDR *a) -{ - /* TODO: IPv6 support */ - struct sockaddr addr; - - /* create socket */ - int sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock < 0) - return NETSOCKET_INVALID; - - /* bind, we should check for error */ - netaddr_to_sockaddr(a, &addr); - bind(sock, &addr, sizeof(addr)); - - /* return */ - return sock; -} - -int net_tcp_set_non_blocking(NETSOCKET sock) -{ - unsigned int mode = 1; -#if defined(CONF_FAMILY_WINDOWS) - return ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); -#else - return ioctl(sock, FIONBIO, (unsigned long *)&mode); -#endif -} - -int net_tcp_set_blocking(NETSOCKET sock) -{ - unsigned int mode = 0; -#if defined(CONF_FAMILY_WINDOWS) - return ioctlsocket(sock, FIONBIO, (unsigned long *)&mode); -#else - return ioctl(sock, FIONBIO, (unsigned long *)&mode); -#endif -} - -int net_tcp_listen(NETSOCKET sock, int backlog) -{ - return listen(sock, backlog); -} - -int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *a) -{ - int s; - socklen_t sockaddr_len; - struct sockaddr addr; - - sockaddr_len = sizeof(addr); - - s = accept(sock, &addr, &sockaddr_len); - - if (s != -1) - { - sockaddr_to_netaddr(&addr, a); - *new_sock = s; - } - return s; -} - -int net_tcp_connect(NETSOCKET sock, const NETADDR *a) -{ - struct sockaddr addr; - - netaddr_to_sockaddr(a, &addr); - return connect(sock, &addr, sizeof(addr)); -} - -int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a) -{ - struct sockaddr addr; - int res; - - netaddr_to_sockaddr(a, &addr); - net_tcp_set_non_blocking(sock); - res = connect(sock, &addr, sizeof(addr)); - net_tcp_set_blocking(sock); - - return res; -} - -int net_tcp_send(NETSOCKET sock, const void *data, int size) -{ - int d; - d = send((int)sock, (const char*)data, size, 0); - return d; -} - -int net_tcp_recv(NETSOCKET sock, void *data, int maxsize) -{ - int bytes; - bytes = recv((int)sock, (char*)data, maxsize, 0); - return bytes; -} - -int net_tcp_close(NETSOCKET sock) -{ -#if defined(CONF_FAMILY_WINDOWS) - closesocket(sock); -#else - close((int)sock); -#endif - return 0; -} - -int net_errno() -{ - return errno; -} - -int net_would_block() -{ - return net_errno() == EWOULDBLOCK; -} - -int net_init() -{ -#if defined(CONF_FAMILY_WINDOWS) - WSADATA wsaData; - int err = WSAStartup(MAKEWORD(1, 1), &wsaData); - dbg_assert(err == 0, "network initialization failed."); - return err==0?0:1; -#endif - - return 0; -} - -int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, void *user) -{ -#if defined(CONF_FAMILY_WINDOWS) - WIN32_FIND_DATA finddata; - HANDLE handle; - char buffer[1024*2]; - str_format(buffer, sizeof(buffer), "%s/*", dir); - - handle = FindFirstFileA(buffer, &finddata); - - if (handle == INVALID_HANDLE_VALUE) - return 0; - - /* add all the entries */ - do - { - if(finddata.cFileName[0] != '.') - cb(finddata.cFileName, 0, user); - } while (FindNextFileA(handle, &finddata)); - - FindClose(handle); - return 0; -#else - struct dirent *entry; - DIR *d = opendir(dir); - - if(!d) - return 0; - - while((entry = readdir(d)) != NULL) - cb(entry->d_name, 0, user); - - /* close the directory and return */ - closedir(d); - return 0; -#endif -} - -int fs_storage_path(const char *appname, char *path, int max) -{ -#if defined(CONF_FAMILY_WINDOWS) - HRESULT r; - char *home = getenv("APPDATA"); - if(!home) - return -1; - _snprintf(path, max, "%s/%s", home, appname); - return 0; -#else - char *home = getenv("HOME"); -#if !defined(CONF_PLATFORM_MACOSX) - int i; -#endif - if(!home) - return -1; - -#if defined(CONF_PLATFORM_MACOSX) - snprintf(path, max, "%s/Library/Application Support/%s", home, appname); -#else - snprintf(path, max, "%s/.%s", home, appname); - for(i = strlen(home)+2; path[i]; i++) - path[i] = tolower(path[i]); -#endif - - return 0; -#endif -} - -int fs_makedir(const char *path) -{ -#if defined(CONF_FAMILY_WINDOWS) - if(_mkdir(path) == 0) - return 0; - if(errno == EEXIST) - return 0; - return -1; -#else - if(mkdir(path, 0755) == 0) - return 0; - if(errno == EEXIST) - return 0; - return -1; -#endif -} - -int fs_is_dir(const char *path) -{ -#if defined(CONF_FAMILY_WINDOWS) - /* TODO: do this smarter */ - WIN32_FIND_DATA finddata; - HANDLE handle; - char buffer[1024*2]; - str_format(buffer, sizeof(buffer), "%s/*", path); - - if ((handle = FindFirstFileA(buffer, &finddata)) == INVALID_HANDLE_VALUE) - return 0; - - FindClose(handle); - return 1; -#else - struct stat sb; - if (stat(path, &sb) == -1) - return 0; - - if (S_ISDIR(sb.st_mode)) - return 1; - else - return 0; -#endif -} - -int fs_chdir(const char *path) -{ - if (fs_is_dir(path)) - { - chdir(path); - return 0; - } - else - return 1; -} - -void swap_endian(void *data, unsigned elem_size, unsigned num) -{ - char *src = (char*) data; - char *dst = src + (elem_size - 1); - - while(num) - { - unsigned n = elem_size>>1; - char tmp; - while(n) - { - tmp = *src; - *src = *dst; - *dst = tmp; - - src++; - dst--; - n--; - } - - src = src + (elem_size>>1); - dst = src + (elem_size - 1); - num--; - } -} - -int net_socket_read_wait(NETSOCKET sock, int time) -{ - struct timeval tv; - fd_set readfds; - - tv.tv_sec = 0; - tv.tv_usec = 1000*time; - - FD_ZERO(&readfds); - FD_SET(sock, &readfds); - - /* don't care about writefds and exceptfds */ - select(sock+1, &readfds, NULL, NULL, &tv); - if(FD_ISSET(sock, &readfds)) - return 1; - return 0; -} - -unsigned time_timestamp() -{ - return time(0); -} - -void str_append(char *dst, const char *src, int dst_size) -{ - int s = strlen(dst); - int i = 0; - while(s < dst_size) - { - dst[s] = src[i]; - if(!src[i]) /* check for null termination */ - break; - s++; - i++; - } - - dst[dst_size-1] = 0; /* assure null termination */ -} - -void str_copy(char *dst, const char *src, int dst_size) -{ - strncpy(dst, src, dst_size); - dst[dst_size-1] = 0; /* assure null termination */ -} - -int str_length(const char *str) -{ - return (int)strlen(str); -} - -void str_format(char *buffer, int buffer_size, const char *format, ...) -{ -#if defined(CONF_FAMILY_WINDOWS) - va_list ap; - va_start(ap, format); - _vsnprintf(buffer, buffer_size, format, ap); - va_end(ap); -#else - va_list ap; - va_start(ap, format); - vsnprintf(buffer, buffer_size, format, ap); - va_end(ap); -#endif - - buffer[buffer_size-1] = 0; /* assure null termination */ -} - - - -/* makes sure that the string only contains the characters between 32 and 127 */ -void str_sanitize_strong(char *str_in) -{ - unsigned char *str = (unsigned char *)str_in; - while(*str) - { - *str &= 0x7f; - if(*str < 32) - *str = 32; - str++; - } -} - -/* makes sure that the string only contains the characters between 32 and 255 + \r\n\t */ -void str_sanitize(char *str_in) -{ - unsigned char *str = (unsigned char *)str_in; - while(*str) - { - if(*str < 32 && !(*str == '\r') && !(*str == '\n') && !(*str == '\t')) - *str = ' '; - str++; - } -} - -/* case */ -int str_comp_nocase(const char *a, const char *b) -{ -#if defined(CONF_FAMILY_WINDOWS) - return _stricmp(a,b); -#else - return strcasecmp(a,b); -#endif -} - -const char *str_find_nocase(const char *haystack, const char *needle) -{ - while(*haystack) /* native implementation */ - { - const char *a = haystack; - const char *b = needle; - while(*a && *b && tolower(*a) == tolower(*b)) - { - a++; - b++; - } - if(!(*b)) - return haystack; - haystack++; - } - - return 0; -} - -void str_hex(char *dst, int dst_size, const void *data, int data_size) -{ - static const char hex[] = "0123456789ABCDEF"; - int b; - - for(b = 0; b < data_size && b < dst_size/4-4; b++) - { - dst[b*3] = hex[((const unsigned char *)data)[b]>>4]; - dst[b*3+1] = hex[((const unsigned char *)data)[b]&0xf]; - dst[b*3+2] = ' '; - dst[b*3+3] = 0; - } -} - -int mem_comp(const void *a, const void *b, int size) -{ - return memcmp(a,b,size); -} - -const MEMSTATS *mem_stats() -{ - return &memory_stats; -} - -void net_stats(NETSTATS *stats_inout) -{ - *stats_inout = network_stats; -} - -void gui_messagebox(const char *title, const char *message) -{ -#if defined(CONF_PLATFORM_MACOSX) - DialogRef theItem; - DialogItemIndex itemIndex; - - /* FIXME: really needed? can we rely on glfw? */ - /* HACK - get events without a bundle */ - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - TransformProcessType(&psn,kProcessTransformToForegroundApplication); - SetFrontProcess(&psn); - /* END HACK */ - - CreateStandardAlert(kAlertStopAlert, - CFStringCreateWithCString(NULL, title, kCFStringEncodingASCII), - CFStringCreateWithCString(NULL, message, kCFStringEncodingASCII), - NULL, - &theItem); - - RunStandardAlert(theItem, NULL, &itemIndex); -#elif defined(CONF_FAMILY_UNIX) - static char cmd[1024]; - /* use xmessage which is available on nearly every X11 system */ - snprintf(cmd, sizeof(cmd), "xmessage -center -title '%s' '%s'", - title, - message); - - system(cmd); -#elif defined(CONF_FAMILY_WINDOWS) - MessageBox(NULL, - message, - title, - MB_ICONEXCLAMATION | MB_OK); -#else - /* this is not critical */ - #warning not implemented -#endif -} - -int str_isspace(char c) { return c == ' ' || c == '\n' || c == '\t'; } - - -#if defined(__cplusplus) -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/base/system.h b/project/jni/application/teeworlds-0.5.2/src/base/system.h deleted file mode 100644 index 3aa01cab6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/base/system.h +++ /dev/null @@ -1,954 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -/* - Title: OS Abstraction -*/ - -#ifndef BASE_SYSTEM_H -#define BASE_SYSTEM_H - -#include "detect.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Group: Debug */ -/* - Function: dbg_assert - Breaks into the debugger based on a test. - - Parameters: - test - Result of the test. - msg - Message that should be printed if the test fails. - - Remarks: - Does nothing in release version of the library. - - See Also: - -*/ -void dbg_assert(int test, const char *msg); -#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg) -void dbg_assert_imp(const char *filename, int line, int test, const char *msg); - -/* - Function: dbg_break - Breaks into the debugger. - - Remarks: - Does nothing in release version of the library. - - See Also: - -*/ -void dbg_break(); - -/* - Function: dbg_msg - - Prints a debug message. - - Parameters: - sys - A string that describes what system the message belongs to - fmt - A printf styled format string. - - Remarks: - Does nothing in relase version of the library. - - See Also: - -*/ -void dbg_msg(const char *sys, const char *fmt, ...); - -/* Group: Memory */ - -/* - Function: mem_alloc - Allocates memory. - - Parameters: - size - Size of the needed block. - alignment - Alignment for the block. - - Returns: - Returns a pointer to the newly allocated block. Returns a - null pointer if the memory couldn't be allocated. - - Remarks: - - Passing 0 to size will allocated the smallest amount possible - and return a unique pointer. - - See Also: - -*/ -void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment); -#define mem_alloc(s,a) mem_alloc_debug(__FILE__, __LINE__, (s), (a)) - -/* - Function: mem_free - Frees a block allocated through . - - Remarks: - - In the debug version of the library the function will assert if - a non-valid block is passed, like a null pointer or a block that - isn't allocated. - - See Also: - -*/ -void mem_free(void *block); - -/* - Function: mem_copy - Copies a a memory block. - - Parameters: - dest - Destination. - source - Source to copy. - size - Size of the block to copy. - - Remarks: - - This functions DOES NOT handles cases where source and - destination is overlapping. - - See Also: - -*/ -void mem_copy(void *dest, const void *source, unsigned size); - -/* - Function: mem_move - Copies a a memory block - - Parameters: - dest - Destination - source - Source to copy - size - Size of the block to copy - - Remarks: - - This functions handles cases where source and destination - is overlapping - - See Also: - -*/ -void mem_move(void *dest, const void *source, unsigned size); - -/* - Function: mem_zero - Sets a complete memory block to 0 - - Parameters: - block - Pointer to the block to zero out - size - Size of the block -*/ -void mem_zero(void *block, unsigned size); - -/* - Function: mem_comp - Compares two blocks of memory - - Parameters: - a - First block of data - b - Second block of data - size - Size of the data to compare - - Returns: - <0 - Block a is lesser then block b - 0 - Block a is equal to block b - >0 - Block a is greater then block b -*/ -int mem_comp(const void *a, const void *b, int size); - -/* - Function: mem_check - Validates the heap - Will trigger a assert if memory has failed. -*/ -int mem_check_imp(); -#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed") - -/* Group: File IO */ -enum { - IOFLAG_READ = 1, - IOFLAG_WRITE = 2, - IOFLAG_RANDOM = 4, - - IOSEEK_START = 0, - IOSEEK_CUR = 1, - IOSEEK_END = 2 -}; - -typedef struct IOINTERNAL *IOHANDLE; - -/* - Function: io_open - Opens a file. - - Parameters: - filename - File to open. - flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM. - - Returns: - Returns a handle to the file on success and 0 on failure. - -*/ -IOHANDLE io_open(const char *filename, int flags); - -/* - Function: io_read - Reads data into a buffer from a file. - - Parameters: - io - Handle to the file to read data from. - buffer - Pointer to the buffer that will recive the data. - size - Number of bytes to read from the file. - - Returns: - Number of bytes read. - -*/ -unsigned io_read(IOHANDLE io, void *buffer, unsigned size); - -/* - Function: io_skip - Skips data in a file. - - Parameters: - io - Handle to the file. - size - Number of bytes to skip. - - Returns: - Number of bytes skipped. -*/ -unsigned io_skip(IOHANDLE io, unsigned size); - -/* - Function: io_write - Writes data from a buffer to file. - - Parameters: - io - Handle to the file. - buffer - Pointer to the data that should be written. - size - Number of bytes to write. - - Returns: - Number of bytes written. -*/ -unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); - -/* - Function: io_seek - Seeks to a specified offset in the file. - - Parameters: - io - Handle to the file. - offset - Offset from pos to stop. - origin - Position to start searching from. - - Returns: - Returns 0 on success. -*/ -int io_seek(IOHANDLE io, int offset, int origin); - -/* - Function: io_tell - Gets the current position in the file. - - Parameters: - io - Handle to the file. - - Returns: - Returns the current position. -1L if an error occured. -*/ -long int io_tell(IOHANDLE io); - -/* - Function: io_length - Gets the total length of the file. Resetting cursor to the beginning - - Parameters: - io - Handle to the file. - - Returns: - Returns the total size. -1L if an error occured. -*/ -long int io_length(IOHANDLE io); - -/* - Function: io_close - Closes a file. - - Parameters: - io - Handle to the file. - - Returns: - Returns 0 on success. -*/ -int io_close(IOHANDLE io); - -/* - Function: io_flush - Empties all buffers and writes all pending data. - - Parameters: - io - Handle to the file. - - Returns: - Returns 0 on success. -*/ -int io_flush(IOHANDLE io); - - -/* - Function: io_stdin - Returns an to the standard input. -*/ -IOHANDLE io_stdin(); - -/* - Function: io_stdout - Returns an to the standard output. -*/ -IOHANDLE io_stdout(); - -/* - Function: io_stderr - Returns an to the standard error. -*/ -IOHANDLE io_stderr(); - - -/* Group: Threads */ - -/* - Function: thread_sleep - Suspends the current thread for a given period. - - Parameters: - milliseconds - Number of milliseconds to sleep. -*/ -void thread_sleep(int milliseconds); - -/* - Function: thread_create - Creates a new thread. - - Parameters: - threadfunc - Entry point for the new thread. - user - Pointer to pass to the thread. - -*/ -void *thread_create(void (*threadfunc)(void *), void *user); - -/* - Function: thread_wait - Waits for a thread to be done or destroyed. - - Parameters: - thread - Thread to wait for. -*/ -void thread_wait(void *thread); - -/* - Function: thread_destoy - Destroys a thread. - - Parameters: - thread - Thread to destroy. -*/ -void thread_destroy(void *thread); - -/* - Function: thread_yeild - Yeild the current threads execution slice. -*/ -void thread_yield(); - - -/* Group: Locks */ -typedef void* LOCK; - -LOCK lock_create(); -void lock_destroy(LOCK lock); - -int lock_try(LOCK lock); -void lock_wait(LOCK lock); -void lock_release(LOCK lock); - -/* Group: Timer */ -#ifdef __GNUC__ -/* if compiled with -pedantic-errors it will complain about long - not being a C90 thing. -*/ -__extension__ typedef long long int64; -#else -typedef long long int64; -#endif -/* - Function: time_get - Fetches a sample from a high resolution timer. - - Returns: - Current value of the timer. - - Remarks: - To know how fast the timer is ticking, see . -*/ -int64 time_get(); - -/* - Function: time_freq - Returns the frequency of the high resolution timer. - - Returns: - Returns the frequency of the high resolution timer. -*/ -int64 time_freq(); - -/* - Function: time_timestamp - Retrives the current time as a UNIX timestamp - - Returns: - The time as a UNIX timestamp -*/ -unsigned time_timestamp(); - -/* Group: Network General */ -typedef int NETSOCKET; -enum -{ - NETSOCKET_INVALID = -1, - - NETTYPE_INVALID = 0, - NETTYPE_IPV4 = 1, - NETTYPE_IPV6 = 2, - NETTYPE_ALL = ~0 -}; - -typedef struct -{ - unsigned int type; - unsigned char ip[16]; - unsigned short port; -} NETADDR; - -/* - Function: net_init - Initiates network functionallity. - - Returns: - Returns 0 on success, - - Remarks: - You must call this function before using any other network - functions. -*/ -int net_init(); - -/* - Function: net_host_lookup - Does a hostname lookup by name and fills out the passed - NETADDR struct with the recieved details. - - Returns: - 0 on success. -*/ -int net_host_lookup(const char *hostname, NETADDR *addr, int types); - -/* - Function: net_addr_comp - Compares two network addresses. - - Parameters: - a - Address to compare - b - Address to compare to. - - Returns: - <0 - Address a is lesser then address b - 0 - Address a is equal to address b - >0 - Address a is greater then address b -*/ -int net_addr_comp(const NETADDR *a, const NETADDR *b); - -/* - Function: net_addr_str - Turns a network address into a representive string. - - Parameters: - addr - Address to turn into a string. - string - Buffer to fill with the string. - max_length - Maximum size of the string. - - Remarks: - - The string will always be zero terminated - -*/ -void net_addr_str(const NETADDR *addr, char *string, int max_length); - -/* - Function: net_addr_from_str - Turns string into a network address. - - Returns: - 0 on success - - Parameters: - addr - Address to fill in. - string - String to parse. -*/ -int net_addr_from_str(NETADDR *addr, const char *string); - -/* Group: Network UDP */ - -/* - Function: net_udp_create - Creates a UDP socket and binds it to a port. - - Parameters: - bindaddr - Address to bind the socket to. - - Returns: - On success it returns an handle to the socket. On failure it - returns NETSOCKET_INVALID. -*/ -NETSOCKET net_udp_create(NETADDR bindaddr); - -/* - Function: net_udp_send - Sends a packet over an UDP socket. - - Parameters: - sock - Socket to use. - addr - Where to send the packet. - data - Pointer to the packet data to send. - size - Size of the packet. - - Returns: - On success it returns the number of bytes sent. Returns -1 - on error. -*/ -int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size); - -/* - Function: net_udp_recv - Recives a packet over an UDP socket. - - Parameters: - sock - Socket to use. - addr - Pointer to an NETADDR that will recive the address. - data - Pointer to a buffer that will recive the data. - maxsize - Maximum size to recive. - - Returns: - On success it returns the number of bytes recived. Returns -1 - on error. -*/ -int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize); - -/* - Function: net_udp_close - Closes an UDP socket. - - Parameters: - sock - Socket to close. - - Returns: - Returns 0 on success. -1 on error. -*/ -int net_udp_close(NETSOCKET sock); - - -/* Group: Network TCP */ - -/* - Function: net_tcp_create - Creates a TCP socket. - - Parameters: - bindaddr - Address to bind the socket to. - - Returns: - On success it returns an handle to the socket. On failure it returns NETSOCKET_INVALID. -*/ -NETSOCKET net_tcp_create(const NETADDR *a); - -/* - Function: net_tcp_listen - Makes the socket start listening for new connections. - - Parameters: - sock - Socket to start listen to. - backlog - Size of the queue of incomming connections to keep. - - Returns: - Returns 0 on success. -*/ -int net_tcp_listen(NETSOCKET sock, int backlog); - -/* - Function: net_tcp_accept - Polls a listning socket for a new connection. - - Parameters: - sock - Listning socket to poll. - new_sock - Pointer to a socket to fill in with the new socket. - addr - Pointer to an address that will be filled in the remote address (optional, can be NULL). - - Returns: - Returns a non-negative integer on success. Negative integer on failure. -*/ -int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr); - -/* - Function: net_tcp_connect - Connects one socket to another. - - Parameters: - sock - Socket to connect. - addr - Address to connect to. - - Returns: - Returns 0 on success. - -*/ -int net_tcp_connect(NETSOCKET sock, const NETADDR *addr); - -/* - Function: net_tcp_send - Sends data to a TCP stream. - - Parameters: - sock - Socket to send data to. - data - Pointer to the data to send. - size - Size of the data to send. - - Returns: - Number of bytes sent. Negative value on failure. -*/ -int net_tcp_send(NETSOCKET sock, const void *data, int size); - -/* - Function: net_tcp_recv - Recvives data from a TCP stream. - - Parameters: - sock - Socket to recvive data from. - data - Pointer to a buffer to write the data to - max_size - Maximum of data to write to the buffer. - - Returns: - Number of bytes recvived. Negative value on failure. When in - non-blocking mode, it returns 0 when there is no more data to - be fetched. -*/ -int net_tcp_recv(NETSOCKET sock, void *data, int maxsize); - -/* - Function: net_tcp_close - Closes a TCP socket. - - Parameters: - sock - Socket to close. - - Returns: - Returns 0 on success. Negative value on failure. -*/ -int net_tcp_close(NETSOCKET sock); - -/* Group: Strings */ - -/* - Function: str_append - Appends a string to another. - - Parameters: - dst - Pointer to a buffer that contains a string. - src - String to append. - dst_size - Size of the buffer of the dst string. - - Remarks: - - The strings are treated as zero-termineted strings. - - Garantees that dst string will contain zero-termination. -*/ -void str_append(char *dst, const char *src, int dst_size); - -/* - Function: str_copy - Copies a string to another. - - Parameters: - dst - Pointer to a buffer that shall recive the string. - src - String to be copied. - dst_size - Size of the buffer dst. - - Remarks: - - The strings are treated as zero-termineted strings. - - Garantees that dst string will contain zero-termination. -*/ -void str_copy(char *dst, const char *src, int dst_size); - -/* - Function: str_length - Returns the length of a zero terminated string. - - Parameters: - str - Pointer to the string. - - Returns: - Length of string in bytes excluding the zero termination. -*/ -int str_length(const char *str); - -/* - Function: str_format - Performs printf formating into a buffer. - - Parameters: - buffer - Pointer to the buffer to recive the formated string. - buffer_size - Size of the buffer. - format - printf formating string. - ... - Parameters for the formating. - - Remarks: - - See the C manual for syntax for the printf formating string. - - The strings are treated as zero-termineted strings. - - Garantees that dst string will contain zero-termination. -*/ -void str_format(char *buffer, int buffer_size, const char *format, ...); - -/* - Function: str_sanitize_strong - Replaces all characters below 32 and above 127 with whitespace. - - Parameters: - str - String to sanitize. - - Remarks: - - The strings are treated as zero-termineted strings. -*/ -void str_sanitize_strong(char *str); - -/* - Function: str_sanitize - Replaces all characters below 32 and above 127 with whitespace with - exception to \r, \n and \r. - - Parameters: - str - String to sanitize. - - Remarks: - - The strings are treated as zero-termineted strings. -*/ -void str_sanitize(char *str); - -/* - Function: str_comp_nocase - Compares to strings case insensitive. - - Parameters: - a - String to compare. - b - String to compare. - - Returns: - <0 - String a is lesser then string b - 0 - String a is equal to string b - >0 - String a is greater then string b - - Remarks: - - Only garanted to work with a-z/A-Z. - - The strings are treated as zero-termineted strings. -*/ -int str_comp_nocase(const char *a, const char *b); - -/* - Function: str_find_nocase - Finds a string inside another string case insensitive. - - Parameters: - haystack - String to search in - needle - String to search for - - Returns: - A pointer into haystack where the needle was found. - Returns NULL of needle could not be found. - - Remarks: - - Only garanted to work with a-z/A-Z. - - The strings are treated as zero-termineted strings. -*/ -const char *str_find_nocase(const char *haystack, const char *needle); - - -/* - Function: str_hex - Takes a datablock and generates a hexstring of it. - - Parameters: - dst - Buffer to fill with hex data - dst_size - size of the buffer - data - Data to turn into hex - data - Size of the data - - Remarks: - - The desination buffer will be zero-terminated -*/ -void str_hex(char *dst, int dst_size, const void *data, int data_size); - -/* Group: Filesystem */ - -/* - Function: fs_listdir - Lists the files in a directory - - Parameters: - dir - Directory to list - cb - Callback function to call for each entry - user - Pointer to give to the callback - - Returns: - Always returns 0. -*/ -typedef void (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, void *user); -int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, void *user); - -/* - Function: fs_makedir - Creates a directory - - Parameters: - path - Directory to create - - Returns: - Returns 0 on success. Negative value on failure. - - Remarks: - Does not create several directories if needed. "a/b/c" will result - in a failure if b or a does not exist. -*/ -int fs_makedir(const char *path); - -/* - Function: fs_storage_path - Fetches per user configuration directory. - - Returns: - Returns 0 on success. Negative value on failure. - - Remarks: - - Returns ~/.appname on UNIX based systems - - Returns ~/Library/Applications Support/appname on Mac OS X - - Returns %APPDATA%/Appname on Windows based systems -*/ -int fs_storage_path(const char *appname, char *path, int max); - -/* - Function: fs_is_dir - Checks if directory exists - - Returns: - Returns 1 on success, 0 on failure. -*/ -int fs_is_dir(const char *path); - -/* - Function: fs_chdir - Changes current working directory - - Returns: - Returns 0 on success, 1 on failure. -*/ -int fs_chdir(const char *path); - -/* - Group: Undocumented -*/ - - -/* - Function: net_tcp_connect_non_blocking - - DOCTODO: serp -*/ -int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a); - -/* - Function: net_tcp_set_non_blocking - - DOCTODO: serp -*/ -int net_tcp_set_non_blocking(NETSOCKET sock); - -/* - Function: net_tcp_set_non_blocking - - DOCTODO: serp -*/ -int net_tcp_set_blocking(NETSOCKET sock); - -/* - Function: net_errno - - DOCTODO: serp -*/ -int net_errno(); - -/* - Function: net_would_block - - DOCTODO: serp -*/ -int net_would_block(); - -int net_socket_read_wait(NETSOCKET sock, int time); - -void mem_debug_dump(); - -void swap_endian(void *data, unsigned elem_size, unsigned num); - -typedef void (*DBG_LOGGER)(const char *line); -void dbg_logger(DBG_LOGGER logger); -void dbg_logger_stdout(); -void dbg_logger_debugger(); -void dbg_logger_file(const char *filename); - -typedef struct -{ - int allocated; - int active_allocations; - int total_allocations; -} MEMSTATS; - -const MEMSTATS *mem_stats(); - -typedef struct -{ - int sent_packets; - int sent_bytes; - int recv_packets; - int recv_bytes; -} NETSTATS; - - -void net_stats(NETSTATS *stats); - -int str_isspace(char c); - - -/* - Function: gui_messagebox - Display plain OS-dependent message box - - Parameters: - title - title of the message box - message - text to display -*/ -void gui_messagebox(const char *title, const char *message); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/base/vmath.hpp b/project/jni/application/teeworlds-0.5.2/src/base/vmath.hpp deleted file mode 100644 index 49dd26d1d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/base/vmath.hpp +++ /dev/null @@ -1,196 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef BASE_VMATH_H -#define BASE_VMATH_H - -// ------------------------------------ - -template -class vector2_base -{ -public: - union { T x,u; }; - union { T y,v; }; - - vector2_base() {} - vector2_base(float nx, float ny) - { - x = nx; - y = ny; - } - - vector2_base operator -() const { return vector2_base(-x, -y); } - vector2_base operator -(const vector2_base &v) const { return vector2_base(x-v.x, y-v.y); } - vector2_base operator +(const vector2_base &v) const { return vector2_base(x+v.x, y+v.y); } - vector2_base operator *(const T v) const { return vector2_base(x*v, y*v); } - - const vector2_base &operator =(const vector2_base &v) { x = v.x; y = v.y; return *this; } - - const vector2_base &operator +=(const vector2_base &v) { x += v.x; y += v.y; return *this; } - const vector2_base &operator -=(const vector2_base &v) { x -= v.x; y -= v.y; return *this; } - const vector2_base &operator *=(const T v) { x *= v; y *= v; return *this; } - - bool operator ==(const vector2_base &v) const { return x == v.x && y == v.y; } //TODO: do this with an eps instead - - operator const T* () { return &x; } -}; - - -template -inline T length(const vector2_base &a) -{ - return sqrtf(a.x*a.x + a.y*a.y); -} - -template -inline T distance(const vector2_base a, const vector2_base &b) -{ - return length(a-b); -} - -template -inline T dot(const vector2_base a, const vector2_base &b) -{ - return a.x*b.x + a.y*b.y; -} - -template -inline vector2_base normalize(const vector2_base &v) -{ - T l = (T)(1.0f/sqrtf(v.x*v.x + v.y*v.y)); - return vector2_base(v.x*l, v.y*l); -} - -typedef vector2_base vec2; -typedef vector2_base bvec2; -typedef vector2_base ivec2; - -template -inline vector2_base closest_point_on_line(vector2_base line_point0, vector2_base line_point1, vector2_base target_point) -{ - vector2_base c = target_point - line_point0; - vector2_base v = (line_point1 - line_point0); - v = normalize(v); - T d = length(line_point0-line_point1); - T t = dot(v, c)/d; - return mix(line_point0, line_point1, clamp(t, (T)0, (T)1)); - /* - if (t < 0) t = 0; - if (t > 1.0f) return 1.0f; - return t;*/ -} - -// ------------------------------------ -template -class vector3_base -{ -public: - union { T x,r,h; }; - union { T y,g,s; }; - union { T z,b,v,l; }; - - vector3_base() {} - vector3_base(float nx, float ny, float nz) - { - x = nx; - y = ny; - z = nz; - } - - const vector3_base &operator =(const vector3_base &v) { x = v.x; y = v.y; z = v.z; return *this; } - - vector3_base operator -(const vector3_base &v) const { return vector3_base(x-v.x, y-v.y, z-v.z); } - vector3_base operator -() const { return vector3_base(-x, -y, -z); } - vector3_base operator +(const vector3_base &v) const { return vector3_base(x+v.x, y+v.y, z+v.z); } - vector3_base operator *(const T v) const { return vector3_base(x*v, y*v, z*v); } - vector3_base operator *(const vector3_base &v) const { return vector3_base(x*v.x, y*v.y, z*v.z); } - vector3_base operator /(const T v) const { return vector3_base(x/v, y/v, z/v); } - - const vector3_base &operator +=(const vector3_base &v) { x += v.x; y += v.y; z += v.z; return *this; } - const vector3_base &operator -=(const vector3_base &v) { x -= v.x; y -= v.y; z -= v.z; return *this; } - const vector3_base &operator *=(const T v) { x *= v; y *= v; z *= v; return *this; } - - bool operator ==(const vector3_base &v) const { return x == v.x && y == v.y && z == v.z; } //TODO: do this with an eps instead - - operator const T* () { return &x; } -}; - -template -inline T length(const vector3_base &a) -{ - return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z); -} - -template -inline T distance(const vector3_base &a, const vector3_base &b) -{ - return length(a-b); -} - -template -inline T dot(const vector3_base &a, const vector3_base &b) -{ - return a.x*b.x + a.y*b.y + a.z*b.z; -} - -template -inline vector3_base normalize(const vector3_base &v) -{ - T l = (T)(1.0f/sqrtf(v.x*v.x + v.y*v.y + v.z*v.z)); - return vector3_base(v.x*l, v.y*l, v.z*l); -} - -template -inline vector3_base cross(const vector3_base &a, const vector3_base &b) -{ - return vector3_base( - a.y*b.z - a.z*b.y, - a.z*b.x - a.x*b.z, - a.x*b.y - a.y*b.x); -} - -typedef vector3_base vec3; -typedef vector3_base bvec3; -typedef vector3_base ivec3; - -// ------------------------------------ - -template -class vector4_base -{ -public: - union { T x,r; }; - union { T y,g; }; - union { T z,b; }; - union { T w,a; }; - - vector4_base() {} - vector4_base(float nx, float ny, float nz, float nw) - { - x = nx; - y = ny; - z = nz; - w = nw; - } - - vector4_base operator +(const vector4_base &v) const { return vector4_base(x+v.x, y+v.y, z+v.z, w+v.w); } - vector4_base operator -(const vector4_base &v) const { return vector4_base(x-v.x, y-v.y, z-v.z, w-v.w); } - vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); } - vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); } - vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); } - - const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; } - - const vector4_base &operator +=(const vector4_base &v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } - const vector4_base &operator -=(const vector4_base &v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; } - const vector4_base &operator *=(const T v) { x *= v; y *= v; z *= v; w *= v; return *this; } - - bool operator ==(const vector4_base &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } //TODO: do this with an eps instead - - operator const T* () { return &x; } -}; - -typedef vector4_base vec4; -typedef vector4_base bvec4; -typedef vector4_base ivec4; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_client.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_client.cpp deleted file mode 100644 index 6dfb87c1f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_client.cpp +++ /dev/null @@ -1,2046 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include - -const int prediction_margin = 1000/50/2; /* magic network prediction value */ - -/* - Server Time - Client Mirror Time - Client Predicted Time - - Snapshot Latency - Downstream latency - - Prediction Latency - Upstream latency -*/ - -/* network client, must be accessible from other parts like the server browser */ -NETCLIENT *net; - -/* TODO: ugly, fix me */ -extern void client_serverbrowse_set(NETADDR *addr, int request, int token, SERVER_INFO *info); -extern void client_serverbrowse_save(); - -static unsigned snapshot_parts; -static int64 local_start_time; - -static int debug_font; -static float frametime = 0.0001f; -static float frametime_low = 1.0f; -static float frametime_high = 0.0f; -static int frames = 0; -static NETADDR server_address; -static int window_must_refocus = 0; -static int snapcrcerrors = 0; - -static int ack_game_tick = -1; -static int current_recv_tick = 0; -static int rcon_authed = 0; - -/* version-checking */ -static char versionstr[10] = "0"; - -/* pinging */ -static int64 ping_start_time = 0; - -/* */ -static char current_map[256] = {0}; -static int current_map_crc = 0; - -/* */ -static char cmd_connect[256] = {0}; - -/* map download */ -static char mapdownload_filename[256] = {0}; -static char mapdownload_name[256] = {0}; -static IOHANDLE mapdownload_file = 0; -static int mapdownload_chunk = 0; -static int mapdownload_crc = 0; -static int mapdownload_amount = -1; -static int mapdownload_totalsize = -1; - -/* */ -static SERVER_INFO current_server_info = {0}; -static int64 current_server_info_requesttime = -1; /* >= 0 should request, == -1 got info */ - -/* current time */ -static int current_tick = 0; -static float intratick = 0; -static float ticktime = 0; -static int prev_tick = 0; - -/* */ -/*static int predictiontime_pingspikecounter = 0; -static int gametime_pingspikecounter = 0;*/ - -/* predicted time */ -static int current_predtick = 0; -static float predintratick = 0; -static int last_input_timeleft = 0; - -static struct /* TODO: handle input better */ -{ - int data[MAX_INPUT_SIZE]; /* the input data */ - int tick; /* the tick that the input is for */ - int64 predicted_time; /* prediction latency when we sent this input */ - int64 time; -} inputs[200]; -static int current_input = 0; - -enum -{ - GRAPH_MAX=128 -}; - -typedef struct -{ - float min, max; - float values[GRAPH_MAX]; - float colors[GRAPH_MAX][3]; - int index; -} GRAPH; - -static void graph_init(GRAPH *g, float min, float max) -{ - g->min = min; - g->max = max; - g->index = 0; -} - -static void graph_scale_max(GRAPH *g) -{ - int i = 0; - g->max = 0; - for(i = 0; i < GRAPH_MAX; i++) - { - if(g->values[i] > g->max) - g->max = g->values[i]; - } -} - -static void graph_scale_min(GRAPH *g) -{ - int i = 0; - g->min = g->max; - for(i = 0; i < GRAPH_MAX; i++) - { - if(g->values[i] < g->min) - g->min = g->values[i]; - } -} - -static void graph_add(GRAPH *graph, float v, float r, float g, float b) -{ - graph->index = (graph->index+1)&(GRAPH_MAX-1); - graph->values[graph->index] = v; - graph->colors[graph->index][0] = r; - graph->colors[graph->index][1] = g; - graph->colors[graph->index][2] = b; -} - -static void graph_render(GRAPH *g, float x, float y, float w, float h, const char *description) -{ - char buf[32]; - int i; - - gfx_blend_normal(); - - - gfx_texture_set(-1); - - gfx_quads_begin(); - gfx_setcolor(0, 0, 0, 0.75f); - gfx_quads_drawTL(x, y, w, h); - gfx_quads_end(); - - gfx_lines_begin(); - gfx_setcolor(0.95f, 0.95f, 0.95f, 1.00f); - gfx_lines_draw(x, y+h/2, x+w, y+h/2); - gfx_setcolor(0.5f, 0.5f, 0.5f, 0.75f); - gfx_lines_draw(x, y+(h*3)/4, x+w, y+(h*3)/4); - gfx_lines_draw(x, y+h/4, x+w, y+h/4); - for(i = 1; i < GRAPH_MAX; i++) - { - float a0 = (i-1)/(float)GRAPH_MAX; - float a1 = i/(float)GRAPH_MAX; - int i0 = (g->index+i-1)&(GRAPH_MAX-1); - int i1 = (g->index+i)&(GRAPH_MAX-1); - - float v0 = (g->values[i0]-g->min) / (g->max-g->min); - float v1 = (g->values[i1]-g->min) / (g->max-g->min); - - gfx_setcolorvertex(0, g->colors[i0][0], g->colors[i0][1], g->colors[i0][2], 0.75f); - gfx_setcolorvertex(1, g->colors[i1][0], g->colors[i1][1], g->colors[i1][2], 0.75f); - gfx_lines_draw(x+a0*w, y+h-v0*h, x+a1*w, y+h-v1*h); - - } - gfx_lines_end(); - - - gfx_texture_set(debug_font); - gfx_quads_text(x+2, y+h-16, 16, 1,1,1,1, description); - - str_format(buf, sizeof(buf), "%.2f", g->max); - gfx_quads_text(x+w-8*strlen(buf)-8, y+2, 16, 1,1,1,1, buf); - - str_format(buf, sizeof(buf), "%.2f", g->min); - gfx_quads_text(x+w-8*strlen(buf)-8, y+h-16, 16, 1,1,1,1, buf); - -} - -typedef struct -{ - int64 snap; - int64 current; - int64 target; - - int64 rlast; - int64 tlast; - GRAPH graph; - - int spikecounter; - - float adjustspeed[2]; /* 0 = down, 1 = up */ -} SMOOTHTIME; - -static void st_init(SMOOTHTIME *st, int64 target) -{ - st->snap = time_get(); - st->current = target; - st->target = target; - st->adjustspeed[0] = 0.3f; - st->adjustspeed[1] = 0.3f; - graph_init(&st->graph, 0.0f, 0.5f); -} - -static int64 st_get(SMOOTHTIME *st, int64 now) -{ - float adjust_speed, a; - int64 c = st->current + (now - st->snap); - int64 t = st->target + (now - st->snap); - int64 r; - - /* it's faster to adjust upward instead of downward */ - /* we might need to adjust these abit */ - - adjust_speed = st->adjustspeed[0]; - if(t > c) - adjust_speed = st->adjustspeed[1]; - - a = ((now-st->snap)/(float)time_freq()) * adjust_speed; - if(a > 1.0f) - a = 1.0f; - - r = c + (int64)((t-c)*a); - - graph_add(&st->graph, a+0.5f,1,1,1); - - return r; -} - -static void st_update_int(SMOOTHTIME *st, int64 target) -{ - int64 now = time_get(); - st->current = st_get(st, now); - st->snap = now; - st->target = target; -} - -static void st_update(SMOOTHTIME *st, GRAPH *graph, int64 target, int time_left, int adjust_direction) -{ - int update_timer = 1; - - if(time_left < 0) - { - int is_spike = 0; - if(time_left < -50) - { - is_spike = 1; - - st->spikecounter += 5; - if(st->spikecounter > 50) - st->spikecounter = 50; - } - - if(is_spike && st->spikecounter < 15) - { - /* ignore this ping spike */ - update_timer = 0; - graph_add(graph, time_left, 1,1,0); - } - else - { - graph_add(graph, time_left, 1,0,0); - if(st->adjustspeed[adjust_direction] < 30.0f) - st->adjustspeed[adjust_direction] *= 2.0f; - } - } - else - { - if(st->spikecounter) - st->spikecounter--; - - graph_add(graph, time_left, 0,1,0); - - st->adjustspeed[adjust_direction] *= 0.95f; - if(st->adjustspeed[adjust_direction] < 2.0f) - st->adjustspeed[adjust_direction] = 2.0f; - } - - last_input_timeleft = time_left; - - if(update_timer) - st_update_int(st, target); -} - -static SMOOTHTIME game_time; -static SMOOTHTIME predicted_time; - -/* graphs */ -static GRAPH inputtime_margin_graph; -static GRAPH gametime_margin_graph; -static GRAPH fps_graph; - -/* -- snapshot handling --- */ -enum -{ - NUM_SNAPSHOT_TYPES=2 -}; - -/* the game snapshots are modifiable by the game */ -SNAPSTORAGE snapshot_storage; -static SNAPSTORAGE_HOLDER *snapshots[NUM_SNAPSHOT_TYPES]; - -static int recived_snapshots = 0; -static char snapshot_incomming_data[MAX_SNAPSHOT_SIZE]; - -static SNAPSTORAGE_HOLDER demorec_snapshotholders[NUM_SNAPSHOT_TYPES]; -static char *demorec_snapshotdata[NUM_SNAPSHOT_TYPES][2][MAX_SNAPSHOT_SIZE]; - -/* --- */ - -void *snap_get_item(int snapid, int index, SNAP_ITEM *item) -{ - SNAPSHOT_ITEM *i; - dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); - i = snapshot_get_item(snapshots[snapid]->alt_snap, index); - item->datasize = snapshot_get_item_datasize(snapshots[snapid]->alt_snap, index); - item->type = snapitem_type(i); - item->id = snapitem_id(i); - return (void *)snapitem_data(i); -} - -void snap_invalidate_item(int snapid, int index) -{ - SNAPSHOT_ITEM *i; - dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); - i = snapshot_get_item(snapshots[snapid]->alt_snap, index); - if(i) - { - if((char *)i < (char *)snapshots[snapid]->alt_snap || (char *)i > (char *)snapshots[snapid]->alt_snap + snapshots[snapid]->snap_size) - dbg_msg("ASDFASDFASdf", "ASDFASDFASDF"); - if((char *)i >= (char *)snapshots[snapid]->snap && (char *)i < (char *)snapshots[snapid]->snap + snapshots[snapid]->snap_size) - dbg_msg("ASDFASDFASdf", "ASDFASDFASDF"); - i->type_and_id = -1; - } -} - -void *snap_find_item(int snapid, int type, int id) -{ - /* TODO: linear search. should be fixed. */ - int i; - - if(!snapshots[snapid]) - return 0x0; - - for(i = 0; i < snapshots[snapid]->snap->num_items; i++) - { - SNAPSHOT_ITEM *itm = snapshot_get_item(snapshots[snapid]->alt_snap, i); - if(snapitem_type(itm) == type && snapitem_id(itm) == id) - return (void *)snapitem_data(itm); - } - return 0x0; -} - -int snap_num_items(int snapid) -{ - dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); - if(!snapshots[snapid]) - return 0; - return snapshots[snapid]->snap->num_items; -} - -/* ------ time functions ------ */ -float client_intratick() { return intratick; } -float client_predintratick() { return predintratick; } -float client_ticktime() { return ticktime; } -int client_tick() { return current_tick; } -int client_prevtick() { return prev_tick; } -int client_predtick() { return current_predtick; } -int client_tickspeed() { return SERVER_TICK_SPEED; } -float client_frametime() { return frametime; } -float client_localtime() { return (time_get()-local_start_time)/(float)(time_freq()); } - -/* ----- send functions ----- */ -int client_send_msg() -{ - const MSG_INFO *info = msg_get_info(); - NETCHUNK packet; - - if(!info) - return -1; - - mem_zero(&packet, sizeof(NETCHUNK)); - - packet.client_id = 0; - packet.data = info->data; - packet.data_size = info->size; - - if(info->flags&MSGFLAG_VITAL) - packet.flags |= NETSENDFLAG_VITAL; - if(info->flags&MSGFLAG_FLUSH) - packet.flags |= NETSENDFLAG_FLUSH; - - if(info->flags&MSGFLAG_RECORD) - { - if(demorec_isrecording()) - demorec_record_message(packet.data, packet.data_size); - } - - if(!(info->flags&MSGFLAG_NOSEND)) - netclient_send(net, &packet); - return 0; -} - -static void client_send_info() -{ - msg_pack_start_system(NETMSG_INFO, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_string(modc_net_version(), 128); - msg_pack_string(config.player_name, 128); - msg_pack_string(config.clan_name, 128); - msg_pack_string(config.password, 128); - msg_pack_end(); - client_send_msg(); -} - - -static void client_send_entergame() -{ - msg_pack_start_system(NETMSG_ENTERGAME, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_end(); - client_send_msg(); -} - -static void client_send_ready() -{ - msg_pack_start_system(NETMSG_READY, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_end(); - client_send_msg(); -} - -int client_rcon_authed() -{ - return rcon_authed; -} - -void client_rcon_auth(const char *name, const char *password) -{ - msg_pack_start_system(NETMSG_RCON_AUTH, MSGFLAG_VITAL); - msg_pack_string(name, 32); - msg_pack_string(password, 32); - msg_pack_end(); - client_send_msg(); -} - -void client_rcon(const char *cmd) -{ - msg_pack_start_system(NETMSG_RCON_CMD, MSGFLAG_VITAL); - msg_pack_string(cmd, 256); - msg_pack_end(); - client_send_msg(); -} - -int client_connection_problems() -{ - return netclient_gotproblems(net); -} - -void client_direct_input(int *input, int size) -{ - int i; - msg_pack_start_system(NETMSG_INPUT, 0); - msg_pack_int(ack_game_tick); - msg_pack_int(current_predtick); - msg_pack_int(size); - - for(i = 0; i < size/4; i++) - msg_pack_int(input[i]); - - msg_pack_end(); - client_send_msg(); -} - - -static void client_send_input() -{ - int64 now = time_get(); - int i, size; - - if(current_predtick <= 0) - return; - - /* fetch input */ - size = modc_snap_input(inputs[current_input].data); - - if(!size) - return; - - /* pack input */ - msg_pack_start_system(NETMSG_INPUT, MSGFLAG_FLUSH); - msg_pack_int(ack_game_tick); - msg_pack_int(current_predtick); - msg_pack_int(size); - - inputs[current_input].tick = current_predtick; - inputs[current_input].predicted_time = st_get(&predicted_time, now); - inputs[current_input].time = now; - - /* pack it */ - for(i = 0; i < size/4; i++) - msg_pack_int(inputs[current_input].data[i]); - - current_input++; - current_input%=200; - - msg_pack_end(); - client_send_msg(); -} - -const char *client_latestversion() -{ - return versionstr; -} - -/* TODO: OPT: do this alot smarter! */ -int *client_get_input(int tick) -{ - int i; - int best = -1; - for(i = 0; i < 200; i++) - { - if(inputs[i].tick <= tick && (best == -1 || inputs[best].tick < inputs[i].tick)) - best = i; - } - - if(best != -1) - return (int *)inputs[best].data; - return 0; -} - -/* ------ state handling ----- */ -static int state = CLIENTSTATE_OFFLINE; -int client_state() { return state; } -static void client_set_state(int s) -{ - int old = state; - if(config.debug) - dbg_msg("client", "state change. last=%d current=%d", state, s); - state = s; - if(old != s) - modc_statechange(state, old); -} - -/* called when the map is loaded and we should init for a new round */ -static void client_on_enter_game() -{ - /* reset input */ - int i; - for(i = 0; i < 200; i++) - inputs[i].tick = -1; - current_input = 0; - - /* reset snapshots */ - snapshots[SNAP_CURRENT] = 0; - snapshots[SNAP_PREV] = 0; - snapstorage_purge_all(&snapshot_storage); - recived_snapshots = 0; - snapshot_parts = 0; - current_predtick = 0; - current_recv_tick = 0; -} - -void client_entergame() -{ - /* now we will wait for two snapshots */ - /* to finish the connection */ - client_send_entergame(); - client_on_enter_game(); - /*netclient_flush(net);*/ -} - -void client_connect(const char *server_address_str) -{ - char buf[512]; - const char *port_str = 0; - int k; - int port = 8303; - - client_disconnect(); - - dbg_msg("client", "connecting to '%s'", server_address_str); - - //client_serverinfo_request(); - str_copy(buf, server_address_str, sizeof(buf)); - - for(k = 0; buf[k]; k++) - { - if(buf[k] == ':') - { - port_str = &(buf[k+1]); - buf[k] = 0; - break; - } - } - - if(port_str) - port = atoi(port_str); - - /* TODO: IPv6 support */ - if(net_host_lookup(buf, &server_address, NETTYPE_IPV4) != 0) - dbg_msg("client", "could not find the address of %s, connecting to localhost", buf); - - rcon_authed = 0; - server_address.port = port; - netclient_connect(net, &server_address); - client_set_state(CLIENTSTATE_CONNECTING); - - graph_init(&inputtime_margin_graph, -150.0f, 150.0f); - graph_init(&gametime_margin_graph, -150.0f, 150.0f); -} - -void client_disconnect_with_reason(const char *reason) -{ - /* stop demo playback */ - demorec_playback_stop(); - - /* */ - rcon_authed = 0; - netclient_disconnect(net, reason); - client_set_state(CLIENTSTATE_OFFLINE); - map_unload(); - - /* disable all downloads */ - mapdownload_chunk = 0; - if(mapdownload_file) - io_close(mapdownload_file); - mapdownload_file = 0; - mapdownload_crc = 0; - mapdownload_totalsize = -1; - mapdownload_amount = 0; - - /* clear the current server info */ - mem_zero(¤t_server_info, sizeof(current_server_info)); - mem_zero(&server_address, sizeof(server_address)); - - /* clear snapshots */ - snapshots[SNAP_CURRENT] = 0; - snapshots[SNAP_PREV] = 0; - recived_snapshots = 0; -} - -void client_disconnect() -{ - client_disconnect_with_reason(0); -} - - -void client_serverinfo(SERVER_INFO *serverinfo) -{ - mem_copy(serverinfo, ¤t_server_info, sizeof(current_server_info)); -} - -void client_serverinfo_request() -{ - mem_zero(¤t_server_info, sizeof(current_server_info)); - current_server_info_requesttime = 0; -} - -static int client_load_data() -{ - debug_font = gfx_load_texture("debug_font.png", IMG_AUTO, TEXLOAD_NORESAMPLE); - return 1; -} - -extern int snapshot_data_rate[0xffff]; -extern int snapshot_data_updates[0xffff]; - -extern "C" const char *modc_getitemname(int type); - -static void client_debug_render() -{ - static NETSTATS prev, current; - static int64 last_snap = 0; - static float frametime_avg = 0; - int64 now = time_get(); - char buffer[512]; - - if(!config.debug) - return; - - gfx_blend_normal(); - gfx_texture_set(debug_font); - gfx_mapscreen(0,0,gfx_screenwidth(),gfx_screenheight()); - - if(time_get()-last_snap > time_freq()) - { - last_snap = time_get(); - prev = current; - net_stats(¤t); - } - - /* - eth = 14 - ip = 20 - udp = 8 - total = 42 - */ - frametime_avg = frametime_avg*0.9f + frametime*0.1f; - str_format(buffer, sizeof(buffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d", - current_tick, current_predtick, - mem_stats()->allocated/1024, - mem_stats()->total_allocations, - gfx_memory_usage()/1024, - (int)(1.0f/frametime_avg)); - gfx_quads_text(2, 2, 16, 1,1,1,1, buffer); - - - { - int send_packets = (current.sent_packets-prev.sent_packets); - int send_bytes = (current.sent_bytes-prev.sent_bytes); - int send_total = send_bytes + send_packets*42; - int recv_packets = (current.recv_packets-prev.recv_packets); - int recv_bytes = (current.recv_bytes-prev.recv_bytes); - int recv_total = recv_bytes + recv_packets*42; - - if(!send_packets) send_packets++; - if(!recv_packets) recv_packets++; - str_format(buffer, sizeof(buffer), "send: %3d %5d+%4d=%5d (%3d kbps) avg: %5d\nrecv: %3d %5d+%4d=%5d (%3d kbps) avg: %5d", - send_packets, send_bytes, send_packets*42, send_total, (send_total*8)/1024, send_bytes/send_packets, - recv_packets, recv_bytes, recv_packets*42, recv_total, (recv_total*8)/1024, recv_bytes/recv_packets); - gfx_quads_text(2, 14, 16, 1,1,1,1, buffer); - } - - /* render rates */ - { - int y = 0; - int i; - for(i = 0; i < 256; i++) - { - if(snapshot_data_rate[i]) - { - str_format(buffer, sizeof(buffer), "%4d %20s: %8d %8d %8d", i, modc_getitemname(i), snapshot_data_rate[i]/8, snapshot_data_updates[i], - (snapshot_data_rate[i]/snapshot_data_updates[i])/8); - gfx_quads_text(2, 100+y*12, 16, 1,1,1,1, buffer); - y++; - } - } - } - - str_format(buffer, sizeof(buffer), "pred: %d ms %3.2f", - (int)((st_get(&predicted_time, now)-st_get(&game_time, now))*1000/(float)time_freq()), - predicted_time.adjustspeed[1]); - gfx_quads_text(2, 70, 16, 1,1,1,1, buffer); - - /* render graphs */ - if(config.dbg_graphs) - { - //gfx_mapscreen(0,0,400.0f,300.0f); - float w = gfx_screenwidth()/4.0f; - float h = gfx_screenheight()/6.0f; - float sp = gfx_screenwidth()/100.0f; - float x = gfx_screenwidth()-w-sp; - - graph_scale_max(&fps_graph); - graph_scale_min(&fps_graph); - graph_render(&fps_graph, x, sp*5, w, h, "FPS"); - graph_render(&inputtime_margin_graph, x, sp*5+h+sp, w, h, "Prediction Margin"); - graph_render(&gametime_margin_graph, x, sp*5+h+sp+h+sp, w, h, "Gametime Margin"); - } -} - -void client_quit() -{ - client_set_state(CLIENTSTATE_QUITING); -} - -const char *client_error_string() -{ - return netclient_error_string(net); -} - -static void client_render() -{ - if(config.gfx_clear) - gfx_clear(1,1,0); - - modc_render(); - client_debug_render(); -} - -static const char *client_load_map(const char *name, const char *filename, int wanted_crc) -{ - static char errormsg[128]; - DATAFILE *df; - int crc; - - client_set_state(CLIENTSTATE_LOADING); - - df = datafile_load(filename); - if(!df) - { - str_format(errormsg, sizeof(errormsg), "map '%s' not found", filename); - return errormsg; - } - - /* get the crc of the map */ - crc = datafile_crc(filename); - if(crc != wanted_crc) - { - datafile_unload(df); - str_format(errormsg, sizeof(errormsg), "map differs from the server. %08x != %08x", crc, wanted_crc); - return errormsg; - } - - // stop demo recording if we loaded a new map - demorec_record_stop(); - - dbg_msg("client", "loaded map '%s'", filename); - recived_snapshots = 0; - map_set(df); - - str_copy(current_map, name, sizeof(current_map)); - current_map_crc = crc; - - return NULL; -} - -static const char *client_load_map_search(const char *mapname, int wanted_crc) -{ - const char *error = 0; - char buf[512]; - dbg_msg("client", "loading map, map=%s wanted crc=%08x", mapname, wanted_crc); - client_set_state(CLIENTSTATE_LOADING); - - /* try the normal maps folder */ - str_format(buf, sizeof(buf), "maps/%s.map", mapname); - error = client_load_map(mapname, buf, wanted_crc); - if(!error) - return error; - - /* try the downloaded maps */ - str_format(buf, sizeof(buf), "downloadedmaps/%s_%08x.map", mapname, wanted_crc); - error = client_load_map(mapname, buf, wanted_crc); - return error; -} - -static int player_score_comp(const void *a, const void *b) -{ - SERVER_INFO_PLAYER *p0 = (SERVER_INFO_PLAYER *)a; - SERVER_INFO_PLAYER *p1 = (SERVER_INFO_PLAYER *)b; - if(p0->score == p1->score) - return 0; - if(p0->score < p1->score) - return 1; - return -1; -} - -static void client_process_packet(NETCHUNK *packet) -{ - if(packet->client_id == -1) - { - /* connectionlesss */ - if(packet->data_size == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)) && - memcmp(packet->data, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0) - { - unsigned char *versiondata = (unsigned char*) packet->data + sizeof(VERSIONSRV_VERSION); - int version_match = !memcmp(versiondata, VERSION_DATA, sizeof(VERSION_DATA)); - - dbg_msg("client/version", "version does %s (%d.%d.%d)", - version_match ? "match" : "NOT match", - versiondata[1], versiondata[2], versiondata[3]); - - /* assume version is out of date when version-data doesn't match */ - if (!version_match) - { - sprintf(versionstr, "%d.%d.%d", versiondata[1], versiondata[2], versiondata[3]); - } - } - - if(packet->data_size >= (int)sizeof(SERVERBROWSE_LIST) && - memcmp(packet->data, SERVERBROWSE_LIST, sizeof(SERVERBROWSE_LIST)) == 0) - { - int size = packet->data_size-sizeof(SERVERBROWSE_LIST); - int num = size/sizeof(MASTERSRV_ADDR); - MASTERSRV_ADDR *addrs = (MASTERSRV_ADDR *)((char*)packet->data+sizeof(SERVERBROWSE_LIST)); - int i; - - for(i = 0; i < num; i++) - { - NETADDR addr; - - /* convert address */ - mem_zero(&addr, sizeof(addr)); - addr.type = NETTYPE_IPV4; - addr.ip[0] = addrs[i].ip[0]; - addr.ip[1] = addrs[i].ip[1]; - addr.ip[2] = addrs[i].ip[2]; - addr.ip[3] = addrs[i].ip[3]; - addr.port = (addrs[i].port[1]<<8) | addrs[i].port[0]; - - client_serverbrowse_set(&addr, BROWSESET_MASTER_ADD, -1, NULL); - } - } - - { - int packet_type = 0; - if(packet->data_size >= (int)sizeof(SERVERBROWSE_INFO) && memcmp(packet->data, SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO)) == 0) - packet_type = 2; - - if(packet->data_size >= (int)sizeof(SERVERBROWSE_OLD_INFO) && memcmp(packet->data, SERVERBROWSE_OLD_INFO, sizeof(SERVERBROWSE_OLD_INFO)) == 0) - packet_type = 1; - - if(packet_type) - { - /* we got ze info */ - UNPACKER up; - SERVER_INFO info = {0}; - int i; - int token = -1; - - unpacker_reset(&up, (unsigned char*)packet->data+sizeof(SERVERBROWSE_INFO), packet->data_size-sizeof(SERVERBROWSE_INFO)); - if(packet_type >= 2) - token = atol(unpacker_get_string(&up)); - str_copy(info.version, unpacker_get_string(&up), sizeof(info.version)); - str_copy(info.name, unpacker_get_string(&up), sizeof(info.name)); - str_copy(info.map, unpacker_get_string(&up), sizeof(info.map)); - str_copy(info.gametype, unpacker_get_string(&up), sizeof(info.gametype)); - info.flags = atol(unpacker_get_string(&up)); - info.progression = atol(unpacker_get_string(&up)); - info.num_players = atol(unpacker_get_string(&up)); - info.max_players = atol(unpacker_get_string(&up)); - str_format(info.address, sizeof(info.address), "%d.%d.%d.%d:%d", - packet->address.ip[0], packet->address.ip[1], packet->address.ip[2], - packet->address.ip[3], packet->address.port); - - for(i = 0; i < info.num_players; i++) - { - str_copy(info.players[i].name, unpacker_get_string(&up), sizeof(info.players[i].name)); - info.players[i].score = atol(unpacker_get_string(&up)); - } - - if(!up.error) - { - /* sort players */ - qsort(info.players, info.num_players, sizeof(*info.players), player_score_comp); - - if(net_addr_comp(&server_address, &packet->address) == 0) - { - mem_copy(¤t_server_info, &info, sizeof(current_server_info)); - current_server_info.netaddr = server_address; - current_server_info_requesttime = -1; - } - else - { - if(packet_type == 2) - client_serverbrowse_set(&packet->address, BROWSESET_TOKEN, token, &info); - else - client_serverbrowse_set(&packet->address, BROWSESET_OLD_INTERNET, -1, &info); - } - } - } - } - } - else - { - int sys; - int msg = msg_unpack_start(packet->data, packet->data_size, &sys); - - if(sys) - { - /* system message */ - if(msg == NETMSG_MAP_CHANGE) - { - const char *map = msg_unpack_string(); - int map_crc = msg_unpack_int(); - const char *error = 0; - int i; - - if(msg_unpack_error()) - return; - - for(i = 0; map[i]; i++) /* protect the player from nasty map names */ - { - if(map[i] == '/' || map[i] == '\\') - error = "strange character in map name"; - } - - if(error) - client_disconnect_with_reason(error); - else - { - error = client_load_map_search(map, map_crc); - - if(!error) - { - dbg_msg("client/network", "loading done"); - client_send_ready(); - modc_connected(); - } - else - { - str_format(mapdownload_filename, sizeof(mapdownload_filename), "downloadedmaps/%s_%08x.map", map, map_crc); - - dbg_msg("client/network", "starting to download map to '%s'", mapdownload_filename); - - mapdownload_chunk = 0; - str_copy(mapdownload_name, map, sizeof(mapdownload_name)); - mapdownload_file = engine_openfile(mapdownload_filename, IOFLAG_WRITE); - mapdownload_crc = map_crc; - mapdownload_totalsize = -1; - mapdownload_amount = 0; - - msg_pack_start_system(NETMSG_REQUEST_MAP_DATA, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_int(mapdownload_chunk); - msg_pack_end(); - client_send_msg(); - - if(config.debug) - dbg_msg("client/network", "requested chunk %d", mapdownload_chunk); - } - } - } - else if(msg == NETMSG_MAP_DATA) - { - int last = msg_unpack_int(); - int total_size = msg_unpack_int(); - int size = msg_unpack_int(); - const unsigned char *data = msg_unpack_raw(size); - - /* check fior errors */ - if(msg_unpack_error() || size <= 0 || total_size <= 0 || !mapdownload_file) - return; - - io_write(mapdownload_file, data, size); - - mapdownload_totalsize = total_size; - mapdownload_amount += size; - - if(last) - { - const char *error; - dbg_msg("client/network", "download complete, loading map"); - - io_close(mapdownload_file); - mapdownload_file = 0; - mapdownload_amount = 0; - mapdownload_totalsize = -1; - - /* load map */ - error = client_load_map(mapdownload_name, mapdownload_filename, mapdownload_crc); - if(!error) - { - dbg_msg("client/network", "loading done"); - client_send_ready(); - modc_connected(); - } - else - client_disconnect_with_reason(error); - } - else - { - /* request new chunk */ - mapdownload_chunk++; - msg_pack_start_system(NETMSG_REQUEST_MAP_DATA, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_int(mapdownload_chunk); - msg_pack_end(); - client_send_msg(); - - if(config.debug) - dbg_msg("client/network", "requested chunk %d", mapdownload_chunk); - } - } - else if(msg == NETMSG_PING) - { - msg_pack_start_system(NETMSG_PING_REPLY, 0); - msg_pack_end(); - client_send_msg(); - } - else if(msg == NETMSG_RCON_AUTH_STATUS) - { - int result = msg_unpack_int(); - if(msg_unpack_error() == 0) - rcon_authed = result; - } - else if(msg == NETMSG_RCON_LINE) - { - const char *line = msg_unpack_string(); - if(msg_unpack_error() == 0) - { - /*dbg_msg("remote", "%s", line);*/ - modc_rcon_line(line); - } - } - else if(msg == NETMSG_PING_REPLY) - dbg_msg("client/network", "latency %.2f", (time_get() - ping_start_time)*1000 / (float)time_freq()); - else if(msg == NETMSG_INPUTTIMING) - { - int input_predtick = msg_unpack_int(); - int time_left = msg_unpack_int(); - - /* adjust our prediction time */ - int k; - int64 target = 0; - for(k = 0; k < 200; k++) - { - if(inputs[k].tick == input_predtick) - { - target = inputs[k].predicted_time + (time_get() - inputs[k].time); - target = target - (int64)(((time_left-prediction_margin)/1000.0f)*time_freq()); - //st_update(&predicted_time, ); - break; - } - } - - if(target) - st_update(&predicted_time, &inputtime_margin_graph, target, time_left, 1); - } - else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSINGLE || msg == NETMSG_SNAPEMPTY) - { - /*dbg_msg("client/network", "got snapshot"); */ - int num_parts = 1; - int part = 0; - int game_tick = msg_unpack_int(); - int delta_tick = game_tick-msg_unpack_int(); - int part_size = 0; - int crc = 0; - int complete_size = 0; - const char *data = 0; - - /* we are not allowed to process snapshot yet */ - if(client_state() < CLIENTSTATE_LOADING) - return; - - if(msg == NETMSG_SNAP) - { - num_parts = msg_unpack_int(); - part = msg_unpack_int(); - } - - if(msg != NETMSG_SNAPEMPTY) - { - crc = msg_unpack_int(); - part_size = msg_unpack_int(); - } - - data = (const char *)msg_unpack_raw(part_size); - - if(msg_unpack_error()) - return; - - if(game_tick >= current_recv_tick) - { - if(game_tick != current_recv_tick) - { - snapshot_parts = 0; - current_recv_tick = game_tick; - } - - /* TODO: clean this up abit */ - mem_copy((char*)snapshot_incomming_data + part*MAX_SNAPSHOT_PACKSIZE, data, part_size); - snapshot_parts |= 1<= 0) - { - int deltashot_size = snapstorage_get(&snapshot_storage, delta_tick, 0, &deltashot, 0); - - if(deltashot_size < 0) - { - /* couldn't find the delta snapshots that the server used */ - /* to compress this snapshot. force the server to resync */ - if(config.debug) - dbg_msg("client", "error, couldn't find the delta snapshot"); - - /* ack snapshot */ - /* TODO: combine this with the input message */ - ack_game_tick = -1; - return; - } - } - - /* decompress snapshot */ - deltadata = snapshot_empty_delta(); - deltasize = sizeof(int)*3; - - if(complete_size) - { - int intsize = intpack_decompress(snapshot_incomming_data, complete_size, tmpbuffer2); - - if(intsize < 0) /* failure during decompression, bail */ - return; - - deltadata = tmpbuffer2; - deltasize = intsize; - } - - /* unpack delta */ - purgetick = delta_tick; - snapsize = snapshot_unpack_delta(deltashot, (SNAPSHOT*)tmpbuffer3, deltadata, deltasize); - if(snapsize < 0) - { - dbg_msg("client", "delta unpack failed!"); - return; - } - - if(msg != NETMSG_SNAPEMPTY && snapshot_crc((SNAPSHOT*)tmpbuffer3) != crc) - { - if(config.debug) - { - dbg_msg("client", "snapshot crc error #%d - tick=%d wantedcrc=%d gotcrc=%d compressed_size=%d delta_tick=%d", - snapcrcerrors, game_tick, crc, snapshot_crc((SNAPSHOT*)tmpbuffer3), complete_size, delta_tick); - } - - snapcrcerrors++; - if(snapcrcerrors > 10) - { - /* to many errors, send reset */ - ack_game_tick = -1; - client_send_input(); - snapcrcerrors = 0; - } - return; - } - else - { - if(snapcrcerrors) - snapcrcerrors--; - } - - /* purge old snapshots */ - purgetick = delta_tick; - if(snapshots[SNAP_PREV] && snapshots[SNAP_PREV]->tick < purgetick) - purgetick = snapshots[SNAP_PREV]->tick; - if(snapshots[SNAP_CURRENT] && snapshots[SNAP_CURRENT]->tick < purgetick) - purgetick = snapshots[SNAP_PREV]->tick; - snapstorage_purge_until(&snapshot_storage, purgetick); - - /* add new */ - snapstorage_add(&snapshot_storage, game_tick, time_get(), snapsize, (SNAPSHOT*)tmpbuffer3, 1); - - /* add snapshot to demo */ - if(demorec_isrecording()) - { - - /* write tick marker */ - /* - DEMOREC_TICKMARKER marker; - marker.tick = game_tick; - swap_endian(&marker, sizeof(int), sizeof(marker)/sizeof(int)); - demorec_record_write("TICK", sizeof(marker), &marker); - demorec_record_write("SNAP", snapsize, tmpbuffer3); - */ - - /* write snapshot */ - demorec_record_snapshot(game_tick, tmpbuffer3, snapsize); - } - - /* apply snapshot, cycle pointers */ - recived_snapshots++; - - current_recv_tick = game_tick; - - /* we got two snapshots until we see us self as connected */ - if(recived_snapshots == 2) - { - /* start at 200ms and work from there */ - st_init(&predicted_time, game_tick*time_freq()/50); - predicted_time.adjustspeed[1] = 1000.0f; - st_init(&game_time, (game_tick-1)*time_freq()/50); - snapshots[SNAP_PREV] = snapshot_storage.first; - snapshots[SNAP_CURRENT] = snapshot_storage.last; - local_start_time = time_get(); - client_set_state(CLIENTSTATE_ONLINE); - } - - /* adjust game time */ - { - int64 now = st_get(&game_time, time_get()); - int64 tickstart = game_tick*time_freq()/50; - int64 time_left = (tickstart-now)*1000 / time_freq(); - /*st_update(&game_time, (game_tick-1)*time_freq()/50);*/ - st_update(&game_time, &gametime_margin_graph, (game_tick-1)*time_freq()/50, time_left, 0); - } - - /* ack snapshot */ - ack_game_tick = game_tick; - } - } - } - } - else - { - /* game message */ - if(demorec_isrecording()) - demorec_record_message(packet->data, packet->data_size); - /* demorec_record_write("MESG", packet->data_size, ); */ - - modc_message(msg); - } - } -} - -int client_mapdownload_amount() { return mapdownload_amount; } -int client_mapdownload_totalsize() { return mapdownload_totalsize; } - -static void client_pump_network() -{ - NETCHUNK packet; - - netclient_update(net); - - if(client_state() != CLIENTSTATE_DEMOPLAYBACK) - { - /* check for errors */ - if(client_state() != CLIENTSTATE_OFFLINE && netclient_state(net) == NETSTATE_OFFLINE) - { - client_set_state(CLIENTSTATE_OFFLINE); - client_disconnect(); - dbg_msg("client", "offline error='%s'", netclient_error_string(net)); - } - - /* */ - if(client_state() == CLIENTSTATE_CONNECTING && netclient_state(net) == NETSTATE_ONLINE) - { - /* we switched to online */ - dbg_msg("client", "connected, sending info"); - client_set_state(CLIENTSTATE_LOADING); - client_send_info(); - } - } - - /* process packets */ - while(netclient_recv(net, &packet)) - client_process_packet(&packet); -} - -static void client_democallback_snapshot(void *data, int size) -{ - /* update ticks, they could have changed */ - const DEMOREC_PLAYBACKINFO *info = demorec_playback_info(); - SNAPSTORAGE_HOLDER *temp; - current_tick = info->current_tick; - prev_tick = info->previous_tick; - - /* handle snapshots */ - temp = snapshots[SNAP_PREV]; - snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT]; - snapshots[SNAP_CURRENT] = temp; - - mem_copy(snapshots[SNAP_CURRENT]->snap, data, size); - mem_copy(snapshots[SNAP_CURRENT]->alt_snap, data, size); - - modc_newsnapshot(); - /*modc_predict();*/ -} - -static void client_democallback_message(void *data, int size) -{ - int sys = 0; - int msg = msg_unpack_start(data, size, &sys); - if(!sys) - modc_message(msg); -} - - -const DEMOPLAYBACK_INFO *client_demoplayer_getinfo() -{ - static DEMOPLAYBACK_INFO ret; - const DEMOREC_PLAYBACKINFO *info = demorec_playback_info(); - ret.first_tick = info->first_tick; - ret.last_tick = info->last_tick; - ret.current_tick = info->current_tick; - ret.paused = info->paused; - ret.speed = info->speed; - return &ret; -} - -void client_demoplayer_setpos(float percent) -{ - demorec_playback_set(percent); -} - -void client_demoplayer_setspeed(float speed) -{ - demorec_playback_setspeed(speed); -} - -void client_demoplayer_setpause(int paused) -{ - if(paused) - demorec_playback_pause(); - else - demorec_playback_unpause(); -} - -static void client_update() -{ - if(client_state() == CLIENTSTATE_DEMOPLAYBACK) - { - demorec_playback_update(); - if(demorec_isplaying()) - { - /* update timers */ - const DEMOREC_PLAYBACKINFO *info = demorec_playback_info(); - current_tick = info->current_tick; - prev_tick = info->previous_tick; - intratick = info->intratick; - ticktime = info->ticktime; - } - else - { - /* disconnect on error */ - client_disconnect(); - } - } - else if(client_state() != CLIENTSTATE_OFFLINE && recived_snapshots >= 3) - { - /* switch snapshot */ - int repredict = 0; - int64 freq = time_freq(); - int64 now = st_get(&game_time, time_get()); - int64 pred_now = st_get(&predicted_time, time_get()); - - while(1) - { - SNAPSTORAGE_HOLDER *cur = snapshots[SNAP_CURRENT]; - int64 tickstart = (cur->tick)*time_freq()/50; - - if(tickstart < now) - { - SNAPSTORAGE_HOLDER *next = snapshots[SNAP_CURRENT]->next; - if(next) - { - snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT]; - snapshots[SNAP_CURRENT] = next; - - /* set ticks */ - current_tick = snapshots[SNAP_CURRENT]->tick; - prev_tick = snapshots[SNAP_PREV]->tick; - - if(snapshots[SNAP_CURRENT] && snapshots[SNAP_PREV]) - { - modc_newsnapshot(); - repredict = 1; - } - } - else - break; - } - else - break; - } - - if(snapshots[SNAP_CURRENT] && snapshots[SNAP_PREV]) - { - int64 curtick_start = (snapshots[SNAP_CURRENT]->tick)*time_freq()/50; - int64 prevtick_start = (snapshots[SNAP_PREV]->tick)*time_freq()/50; - /*tg_add(&predicted_time_graph, pred_now, 0); */ - int prev_pred_tick = (int)(pred_now*50/time_freq()); - int new_pred_tick = prev_pred_tick+1; - static float last_predintra = 0; - - intratick = (now - prevtick_start) / (float)(curtick_start-prevtick_start); - ticktime = (now - prevtick_start) / (float)freq; /*(float)SERVER_TICK_SPEED);*/ - - curtick_start = new_pred_tick*time_freq()/50; - prevtick_start = prev_pred_tick*time_freq()/50; - predintratick = (pred_now - prevtick_start) / (float)(curtick_start-prevtick_start); - - if(new_pred_tick < snapshots[SNAP_PREV]->tick-SERVER_TICK_SPEED || new_pred_tick > snapshots[SNAP_PREV]->tick+SERVER_TICK_SPEED) - { - dbg_msg("client", "prediction time reset!"); - st_init(&predicted_time, snapshots[SNAP_CURRENT]->tick*time_freq()/50); - } - - if(new_pred_tick > current_predtick) - { - last_predintra = predintratick; - current_predtick = new_pred_tick; - repredict = 1; - - /* send input */ - client_send_input(); - } - - last_predintra = predintratick; - } - - /* only do sane predictions */ - if(repredict) - { - if(current_predtick > current_tick && current_predtick < current_tick+50) - modc_predict(); - } - - /* fetch server info if we don't have it */ - if(client_state() >= CLIENTSTATE_LOADING && - current_server_info_requesttime >= 0 && - time_get() > current_server_info_requesttime) - { - client_serverbrowse_request(&server_address); - current_server_info_requesttime = time_get()+time_freq()*2; - } - } - - /* STRESS TEST: join the server again */ - if(config.dbg_stress) - { - static int64 action_taken = 0; - int64 now = time_get(); - if(client_state() == CLIENTSTATE_OFFLINE) - { - if(now > action_taken+time_freq()*2) - { - dbg_msg("stress", "reconnecting!"); - client_connect(config.dbg_stress_server); - action_taken = now; - } - } - else - { - /*if(now > action_taken+time_freq()*(10+config.dbg_stress)) - { - dbg_msg("stress", "disconnecting!"); - client_disconnect(); - action_taken = now; - }*/ - } - } - - /* pump the network */ - client_pump_network(); - - /* update the maser server registry */ - mastersrv_update(); - - /* update the server browser */ - client_serverbrowse_update(); -} - - -static void client_versionupdate() -{ - static int state = 0; - static HOSTLOOKUP version_serveraddr; - - if(state == 0) - { - engine_hostlookup(&version_serveraddr, config.cl_version_server); - state++; - } - else if(state == 1) - { - if(jobs_status(&version_serveraddr.job) == JOBSTATUS_DONE) - { - NETCHUNK packet; - - mem_zero(&packet, sizeof(NETCHUNK)); - - version_serveraddr.addr.port = VERSIONSRV_PORT; - - packet.client_id = -1; - packet.address = version_serveraddr.addr; - packet.data = VERSIONSRV_GETVERSION; - packet.data_size = sizeof(VERSIONSRV_GETVERSION); - packet.flags = NETSENDFLAG_CONNLESS; - - netclient_send(net, &packet); - state++; - } - } -} - -extern "C" int editor_update_and_render(); -extern "C" void editor_init(); - -static void client_run() -{ - NETADDR bindaddr; - int64 reporttime = time_get(); - int64 reportinterval = time_freq()*1; - - static PERFORMACE_INFO rootscope = {"root", 0}; - perf_start(&rootscope); - - local_start_time = time_get(); - snapshot_parts = 0; - - /* init graphics and sound */ - if(gfx_init() != 0) - return; - - /* start refreshing addresses while we load */ - mastersrv_refresh_addresses(); - - /* init the editor */ - editor_init(); - - /* sound is allowed to fail */ - snd_init(); - - /* load data */ - if(!client_load_data()) - return; - - /* init the mod */ - modc_init(); - dbg_msg("client", "version %s", modc_net_version()); - - /* open socket */ - mem_zero(&bindaddr, sizeof(bindaddr)); - net = netclient_open(bindaddr, 0); - - /* connect to the server if wanted */ - /* - if(config.cl_connect[0] != 0) - client_connect(config.cl_connect); - config.cl_connect[0] = 0; - */ - - /* */ - graph_init(&fps_graph, 0.0f, 200.0f); - - /* never start with the editor */ - config.cl_editor = 0; - - inp_mouse_mode_relative(); - - while (1) - { - static PERFORMACE_INFO rootscope = {"root", 0}; - int64 frame_start_time = time_get(); - frames++; - - perf_start(&rootscope); - - /* */ - client_versionupdate(); - - /* handle pending connects */ - if(cmd_connect[0]) - { - client_connect(cmd_connect); - cmd_connect[0] = 0; - } - - /* update input */ - { - static PERFORMACE_INFO scope = {"inp_update", 0}; - perf_start(&scope); - inp_update(); - perf_end(); - } - - /* update sound */ - { - static PERFORMACE_INFO scope = {"snd_update", 0}; - perf_start(&scope); - snd_update(); - perf_end(); - } - - /* release focus */ - if(!gfx_window_active()) - { - if(window_must_refocus == 0) - inp_mouse_mode_absolute(); - window_must_refocus = 1; - } - else if (config.dbg_focus && inp_key_pressed(KEY_ESCAPE)) - { - inp_mouse_mode_absolute(); - window_must_refocus = 1; - } - - /* refocus */ - if(window_must_refocus && gfx_window_active()) - { - if(window_must_refocus < 3) - { - inp_mouse_mode_absolute(); - window_must_refocus++; - } - - if(inp_key_pressed(KEY_MOUSE_1)) - { - inp_mouse_mode_relative(); - window_must_refocus = 0; - } - } - - /* panic quit button */ - if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_pressed('q')) - break; - - if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_down('d')) - config.debug ^= 1; - - if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_down('g')) - config.dbg_graphs ^= 1; - - if(inp_key_pressed(KEY_LCTRL) && inp_key_pressed(KEY_LSHIFT) && inp_key_down('e')) - { - config.cl_editor = config.cl_editor^1; - inp_mouse_mode_relative(); - } - - /* - if(!gfx_window_open()) - break; - */ - - /* render */ - if(config.cl_editor) - { - client_update(); - editor_update_and_render(); - gfx_swap(); - } - else - { - { - static PERFORMACE_INFO scope = {"client_update", 0}; - perf_start(&scope); - client_update(); - perf_end(); - } - - if(config.dbg_stress) - { - if((frames%10) == 0) - { - client_render(); - gfx_swap(); - } - } - else - { - { - static PERFORMACE_INFO scope = {"client_render", 0}; - perf_start(&scope); - client_render(); - perf_end(); - } - - { - static PERFORMACE_INFO scope = {"gfx_swap", 0}; - perf_start(&scope); - gfx_swap(); - perf_end(); - } - } - } - - perf_end(); - - - /* check conditions */ - if(client_state() == CLIENTSTATE_QUITING) - break; - - /* be nice */ - if(config.dbg_stress) - thread_sleep(5); - else if(config.cl_cpu_throttle || !gfx_window_active()) - thread_sleep(1); - - if(config.dbg_hitch) - { - thread_sleep(config.dbg_hitch); - config.dbg_hitch = 0; - } - - if(reporttime < time_get()) - { - if(0 && config.debug) - { - dbg_msg("client/report", "fps=%.02f (%.02f %.02f) netstate=%d", - frames/(float)(reportinterval/time_freq()), - 1.0f/frametime_high, - 1.0f/frametime_low, - netclient_state(net)); - } - frametime_low = 1; - frametime_high = 0; - frames = 0; - reporttime += reportinterval; - perf_next(); - - if(config.dbg_pref) - perf_dump(&rootscope); - } - - /* update frametime */ - frametime = (time_get()-frame_start_time)/(float)time_freq(); - if(frametime < frametime_low) - frametime_low = frametime; - if(frametime > frametime_high) - frametime_high = frametime; - - graph_add(&fps_graph, 1.0f/frametime, 1,1,1); - } - - modc_shutdown(); - client_disconnect(); - - gfx_shutdown(); - snd_shutdown(); -} - -static void con_connect(void *result, void *user_data) -{ - str_copy(cmd_connect, console_arg_string(result, 0), sizeof(cmd_connect)); -} - -static void con_disconnect(void *result, void *user_data) -{ - client_disconnect(); -} - -static void con_quit(void *result, void *user_data) -{ - client_quit(); -} - -static void con_ping(void *result, void *user_data) -{ - msg_pack_start_system(NETMSG_PING, 0); - msg_pack_end(); - client_send_msg(); - ping_start_time = time_get(); -} - -static void con_screenshot(void *result, void *user_data) -{ - gfx_screenshot(); -} - -static void con_rcon(void *result, void *user_data) -{ - client_rcon(console_arg_string(result, 0)); -} - -static void con_rcon_auth(void *result, void *user_data) -{ - client_rcon_auth("", console_arg_string(result, 0)); -} - -static void con_addfavorite(void *result, void *user_data) -{ - NETADDR addr; - if(net_addr_from_str(&addr, console_arg_string(result, 0)) == 0) - client_serverbrowse_addfavorite(addr); -} - -void client_demoplayer_play(const char *filename) -{ - int crc; - client_disconnect(); - netclient_error_string_reset(net); - - /* try to start playback */ - demorec_playback_registercallbacks(client_democallback_snapshot, client_democallback_message); - - if(demorec_playback_load(filename)) - return; - - /* load map */ - crc = (demorec_playback_info()->header.crc[0]<<24)| - (demorec_playback_info()->header.crc[1]<<16)| - (demorec_playback_info()->header.crc[2]<<8)| - (demorec_playback_info()->header.crc[3]); - client_load_map_search(demorec_playback_info()->header.map, crc); - modc_connected(); - - /* setup buffers */ - mem_zero(demorec_snapshotdata, sizeof(demorec_snapshotdata)); - - snapshots[SNAP_CURRENT] = &demorec_snapshotholders[SNAP_CURRENT]; - snapshots[SNAP_PREV] = &demorec_snapshotholders[SNAP_PREV]; - - snapshots[SNAP_CURRENT]->snap = (SNAPSHOT *)demorec_snapshotdata[SNAP_CURRENT][0]; - snapshots[SNAP_CURRENT]->alt_snap = (SNAPSHOT *)demorec_snapshotdata[SNAP_CURRENT][1]; - snapshots[SNAP_CURRENT]->snap_size = 0; - snapshots[SNAP_CURRENT]->tick = -1; - - snapshots[SNAP_PREV]->snap = (SNAPSHOT *)demorec_snapshotdata[SNAP_PREV][0]; - snapshots[SNAP_PREV]->alt_snap = (SNAPSHOT *)demorec_snapshotdata[SNAP_PREV][1]; - snapshots[SNAP_PREV]->snap_size = 0; - snapshots[SNAP_PREV]->tick = -1; - - /* enter demo playback state */ - client_set_state(CLIENTSTATE_DEMOPLAYBACK); - - demorec_playback_play(); - modc_entergame(); -} - -static void con_play(void *result, void *user_data) -{ - client_demoplayer_play(console_arg_string(result, 0)); -} - -static void con_record(void *result, void *user_data) -{ - if(state != CLIENTSTATE_ONLINE) - dbg_msg("demorec/record", "client is not online"); - else - { - char filename[512]; - str_format(filename, sizeof(filename), "demos/%s.demo", console_arg_string(result, 0)); - demorec_record_start(filename, modc_net_version(), current_map, current_map_crc, "client"); - } -} - -static void con_stoprecord(void *result, void *user_data) -{ - demorec_record_stop(); -} - -static void con_serverdummy(void *result, void *user_data) -{ - dbg_msg("client", "this command is not available on the client"); -} - -static void client_register_commands() -{ - MACRO_REGISTER_COMMAND("quit", "", CFGFLAG_CLIENT, con_quit, 0x0, "Quit Teeworlds"); - MACRO_REGISTER_COMMAND("exit", "", CFGFLAG_CLIENT, con_quit, 0x0, "Quit Teeworlds"); - MACRO_REGISTER_COMMAND("connect", "s", CFGFLAG_CLIENT, con_connect, 0x0, "Connect to the specified host/ip"); - MACRO_REGISTER_COMMAND("disconnect", "", CFGFLAG_CLIENT, con_disconnect, 0x0, "Disconnect from the server"); - MACRO_REGISTER_COMMAND("ping", "", CFGFLAG_CLIENT, con_ping, 0x0, "Ping the current server"); - MACRO_REGISTER_COMMAND("screenshot", "", CFGFLAG_CLIENT, con_screenshot, 0x0, "Take a screenshot"); - MACRO_REGISTER_COMMAND("rcon", "r", CFGFLAG_CLIENT, con_rcon, 0x0, "Send specified command to rcon"); - MACRO_REGISTER_COMMAND("rcon_auth", "s", CFGFLAG_CLIENT, con_rcon_auth, 0x0, "Authenticate to rcon"); - - MACRO_REGISTER_COMMAND("play", "r", CFGFLAG_CLIENT, con_play, 0x0, "Play the file specified"); - MACRO_REGISTER_COMMAND("record", "s", CFGFLAG_CLIENT, con_record, 0, "Record to the file"); - MACRO_REGISTER_COMMAND("stoprecord", "", CFGFLAG_CLIENT, con_stoprecord, 0, "Stop recording"); - - MACRO_REGISTER_COMMAND("add_favorite", "s", CFGFLAG_CLIENT, con_addfavorite, 0x0, "Add a server as a favorite"); - - /* register server dummy commands for tab completion */ - MACRO_REGISTER_COMMAND("kick", "i", CFGFLAG_SERVER, con_serverdummy, 0, "Kick player with specified id"); - MACRO_REGISTER_COMMAND("ban", "s?i", CFGFLAG_SERVER, con_serverdummy, 0, "Ban player with ip/id for x minutes"); - MACRO_REGISTER_COMMAND("unban", "s", CFGFLAG_SERVER, con_serverdummy, 0, "Unban ip"); - MACRO_REGISTER_COMMAND("bans", "", CFGFLAG_SERVER, con_serverdummy, 0, "Show banlist"); - MACRO_REGISTER_COMMAND("status", "", CFGFLAG_SERVER, con_serverdummy, 0, "List players"); - MACRO_REGISTER_COMMAND("shutdown", "", CFGFLAG_SERVER, con_serverdummy, 0, "Shut down"); - /*MACRO_REGISTER_COMMAND("record", "", CFGFLAG_SERVER, con_serverdummy, 0); - MACRO_REGISTER_COMMAND("stoprecord", "", CFGFLAG_SERVER, con_serverdummy, 0);*/ -} - -void client_save_line(const char *line) -{ - engine_config_write_line(line); -} - -const char *client_user_directory() -{ - static char path[1024] = {0}; - fs_storage_path("Teeworlds", path, sizeof(path)); - return path; -} - -#if defined(CONF_PLATFORM_MACOSX) || defined(ANDROID) -extern "C" int SDL_main(int argc, char **argv) -#else -extern "C" int main(int argc, char **argv) -#endif -{ - /* init the engine */ - dbg_msg("client", "starting..."); - engine_init("Teeworlds"); - - /* register all console commands */ - client_register_commands(); - modc_console_init(); - - /* parse the command line arguments */ - engine_parse_arguments(argc, argv); - - /* execute config file */ - console_execute_file("settings.cfg"); - - /* run the client*/ - client_run(); - - /* write down the config and quit */ - if(engine_config_write_start() == 0) - { - config_save(); - client_serverbrowse_save(); - modc_save_config(); - engine_config_write_stop(); - } - - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.cpp deleted file mode 100644 index f8760d41c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include -#include -#include -#include "ec_font.h" - -typedef struct -{ - short x, y; - short width, height; - short x_offset, y_offset; - short x_advance; -} FONT_CHARACTER; - -typedef struct -{ - short size; - short width, height; - - short line_height; - short base; - - FONT_CHARACTER characters[256]; - - short kerning[256*256]; -} FONT_DATA; - -int font_load(FONT *font, const char *filename) -{ - FONT_DATA font_data; - IOHANDLE file; - - file = engine_openfile(filename, IOFLAG_READ); - - if(file) - { - int i; - - io_read(file, &font_data, sizeof(FONT_DATA)); - io_close(file); - -#if defined(CONF_ARCH_ENDIAN_BIG) - swap_endian(&font_data, 2, sizeof(FONT_DATA)/2); -#endif - - { - float scale_factor_x = 1.0f/font_data.size; - float scale_factor_y = 1.0f/font_data.size; - float scale_factor_tex_x = 1.0f/font_data.width; - float scale_factor_tex_y = 1.0f/font_data.height; - - for (i = 0; i < 256; i++) - { - float tex_x0 = font_data.characters[i].x*scale_factor_tex_x; - float tex_y0 = font_data.characters[i].y*scale_factor_tex_y; - float tex_x1 = (font_data.characters[i].x+font_data.characters[i].width)*scale_factor_tex_x; - float tex_y1 = (font_data.characters[i].y+font_data.characters[i].height)*scale_factor_tex_y; - - float width = font_data.characters[i].width*scale_factor_x; - float height = font_data.characters[i].height*scale_factor_y; - float x_offset = font_data.characters[i].x_offset*scale_factor_x; - float y_offset = font_data.characters[i].y_offset*scale_factor_y; - float x_advance = (font_data.characters[i].x_advance)*scale_factor_x; - - font->characters[i].tex_x0 = tex_x0; - font->characters[i].tex_y0 = tex_y0; - font->characters[i].tex_x1 = tex_x1; - font->characters[i].tex_y1 = tex_y1; - font->characters[i].width = width; - font->characters[i].height = height; - font->characters[i].x_offset = x_offset; - font->characters[i].y_offset = y_offset; - font->characters[i].x_advance = x_advance; - - } - - for (i = 0; i < 256*256; i++) - { - font->kerning[i] = (char)font_data.kerning[i]; - } - } - - return 0; - } - else - return -1; -} - -/*int gfx_load_texture(const char *filename, int store_format, int flags); -#define IMG_ALPHA 2*/ - -int font_set_load(FONT_SET *font_set, const char *font_filename, const char *text_texture_filename, const char *outline_texture_filename, int fonts, ...) -{ - int i; - va_list va; - - font_set->font_count = fonts; - - va_start(va, fonts); - for (i = 0; i < fonts; i++) - { - int size; - char composed_font_filename[256]; - char composed_text_texture_filename[256]; - char composed_outline_texture_filename[256]; - FONT *font = &font_set->fonts[i]; - - size = va_arg(va, int); - str_format(composed_font_filename, sizeof(composed_font_filename), font_filename, size); - str_format(composed_text_texture_filename, sizeof(composed_text_texture_filename), text_texture_filename, size); - str_format(composed_outline_texture_filename, sizeof(composed_outline_texture_filename), outline_texture_filename, size); - - if (font_load(font, composed_font_filename)) - { - dbg_msg("font/loading", "failed loading font %s.", composed_font_filename); - va_end(va); - return -1; - } - - font->size = size; - font->text_texture = gfx_load_texture(composed_text_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE); - font->outline_texture = gfx_load_texture(composed_outline_texture_filename, IMG_ALPHA, TEXLOAD_NORESAMPLE); - } - - va_end(va); - return 0; -} - -float font_text_width(FONT *font, const char *text, float size, int length) -{ - float width = 0.0f; - - const unsigned char *c = (unsigned char *)text; - int chars_left; - if (length == -1) - chars_left = strlen(text); - else - chars_left = length; - - while (chars_left--) - { - float tex_x0, tex_y0, tex_x1, tex_y1; - float char_width, char_height; - float x_offset, y_offset, x_advance; - float advance; - - font_character_info(font, *c, &tex_x0, &tex_y0, &tex_x1, &tex_y1, &char_width, &char_height, &x_offset, &y_offset, &x_advance); - - advance = x_advance + font_kerning(font, *c, *(c+1)); - - width += advance; - - c++; - } - - return width*size; -} - -void font_character_info(FONT *font, unsigned char c, float *tex_x0, float *tex_y0, float *tex_x1, float *tex_y1, float *width, float *height, float *x_offset, float *y_offset, float *x_advance) -{ - CHARACTER *character = &font->characters[c]; - - *tex_x0 = character->tex_x0; - *tex_y0 = character->tex_y0; - *tex_x1 = character->tex_x1; - *tex_y1 = character->tex_y1; - *width = character->width; - *height = character->height; - *x_offset = character->x_offset; - *y_offset = character->y_offset; - *x_advance = character->x_advance; -} - -float font_kerning(FONT *font, unsigned char c1, unsigned char c2) -{ - return font->kerning[c1 + c2*256] / (float)font->size; -} - -FONT *font_set_pick(FONT_SET *font_set, float size) -{ - int i; - FONT *picked_font = 0x0; - - for (i = font_set->font_count-1; i >= 0; i--) - { - FONT *font = &font_set->fonts[i]; - - if (font->size >= size) - picked_font = font; - } - - if (!picked_font) - picked_font = &font_set->fonts[font_set->font_count-1]; - - return picked_font; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.h b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.h deleted file mode 100644 index 8221a81a0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_font.h +++ /dev/null @@ -1,49 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef _FONT_H -#define _FONT_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - float tex_x0; - float tex_y0; - float tex_x1; - float tex_y1; - float width; - float height; - float x_offset; - float y_offset; - float x_advance; -} -CHARACTER; - -typedef struct -{ - int text_texture; - int outline_texture; - int size; - CHARACTER characters[256]; - char kerning[256*256]; -} FONT; - -typedef struct -{ - int font_count; - FONT fonts[14]; -} FONT_SET; - -int font_load(FONT *font, const char *filename); -int font_set_load(FONT_SET *font_set, const char *font_filename, const char *text_texture_filename, const char *outline_texture_filename, int fonts, ...); -float font_text_width(FONT *font, const char *text, float size, int width); -void font_character_info(FONT *font, unsigned char c, float *tex_x0, float *tex_y0, float *tex_x1, float *tex_y1, float *width, float *height, float *x_offset, float *y_offset, float *x_advance); -float font_kerning(FONT *font, unsigned char c1, unsigned char c2); -FONT *font_set_pick(FONT_SET *font_set, float size); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx.cpp deleted file mode 100644 index c3cdd1ab0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx.cpp +++ /dev/null @@ -1,1347 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include - -#include "SDL.h" - -#ifdef CONF_FAMILY_WINDOWS - #define WIN32_LEAN_AND_MEAN - #include -#endif - -#ifdef CONF_PLATFORM_MACOSX - #include - #include -#else -#ifdef ANDROID - #define GL_GLEXT_PROTOTYPES - #include - #include -#else - #include - #include -#endif -#endif - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#if defined(ANDROID) -#include -#endif - -#include "ec_font.h" - -/* compressed textures */ -#define GL_COMPRESSED_RGB_ARB 0x84ED -#define GL_COMPRESSED_RGBA_ARB 0x84EE -#define GL_COMPRESSED_ALPHA_ARB 0x84E9 - -#define TEXTURE_MAX_ANISOTROPY_EXT 0x84FE - -enum -{ - DRAWING_QUADS=1, - DRAWING_LINES=2 -}; - -/* */ -typedef struct { float x, y, z; } VEC3; -typedef struct { float u, v; } TEXCOORD; -typedef struct { float r, g, b, a; } COLOR; - -typedef struct -{ - VEC3 pos; - TEXCOORD tex; - COLOR color; -} VERTEX; - -const int vertex_buffer_size = 32*1024; -static VERTEX *vertices = 0; -static int num_vertices = 0; - -static int no_gfx = 0; - -static COLOR color[4]; -static TEXCOORD texture[4]; - -static int do_screenshot = 0; -static int render_enable = 1; - -static int screen_width = -1; -static int screen_height = -1; -static float rotation = 0; -static int drawing = 0; - -static float screen_x0 = 0; -static float screen_y0 = 0; -static float screen_x1 = 0; -static float screen_y1 = 0; - -static int invalid_texture = 0; - -typedef struct -{ - GLuint tex; - int memsize; - int flags; - int w, h; - int next; -} TEXTURE; - -enum -{ - MAX_TEXTURES = 1024*4 -}; - -static TEXTURE textures[MAX_TEXTURES]; -static int first_free_texture; -static int memory_usage = 0; -static int active_texture = -1; - -extern SDL_Surface *EC_screen_surface; -SDL_Surface *EC_screen_surface = NULL; - -static const unsigned char null_texture_data[] = { - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, -}; - -static void flush() -{ - if(num_vertices == 0) - return; - - if(no_gfx) - { - num_vertices = 0; - return; - } - - -#ifdef ANDROID - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glVertexPointer(3, GL_FLOAT, // Why do we need Z coord? Let it be just 2 coords - sizeof(VERTEX), - (char*)vertices); - glEnableClientState(GL_VERTEX_ARRAY); - - if(render_enable) - { - if(drawing == DRAWING_QUADS) - { - int i; - glTexCoordPointer(2, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices + sizeof(float)*3); - - glDisableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - for(i = 0; i < num_vertices / 4; i++) - { - -#define SINGLE_COLOR_PER_TEXTURE 1 -#define USE_GL_DRAW_TEX 1 -#define TEXTURE_OUT_OF_SCREEN_CHECK 1 // Some GLES renderers seems to not have this check - -#ifdef TEXTURE_OUT_OF_SCREEN_CHECK - if( - ( vertices[i * 4 + 0].pos.x < screen_x0 && - vertices[i * 4 + 1].pos.x < screen_x0 && - vertices[i * 4 + 2].pos.x < screen_x0 && - vertices[i * 4 + 3].pos.x < screen_x0 ) - || - ( vertices[i * 4 + 0].pos.x > screen_x1 && - vertices[i * 4 + 1].pos.x > screen_x1 && - vertices[i * 4 + 2].pos.x > screen_x1 && - vertices[i * 4 + 3].pos.x > screen_x1 ) - || - ( vertices[i * 4 + 0].pos.y < screen_y0 && - vertices[i * 4 + 1].pos.y < screen_y0 && - vertices[i * 4 + 2].pos.y < screen_y0 && - vertices[i * 4 + 3].pos.y < screen_y0 ) - || - ( vertices[i * 4 + 0].pos.y > screen_y1 && - vertices[i * 4 + 1].pos.y > screen_y1 && - vertices[i * 4 + 2].pos.y > screen_y1 && - vertices[i * 4 + 3].pos.y > screen_y1 ) - ) - continue; -#endif - -#ifndef SINGLE_COLOR_PER_TEXTURE - // GL_COLOR_ARRAY is too damn slow for textures, so we'll set per-texture color - glColorPointer(4, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices + sizeof(float)*5); - glEnableClientState(GL_COLOR_ARRAY); -#else - COLOR texcolor = { - ( vertices[i * 4 + 0].color.r + vertices[i * 4 + 1].color.r + - vertices[i * 4 + 2].color.r + vertices[i * 4 + 3].color.r ) / 4.0f, - ( vertices[i * 4 + 0].color.g + vertices[i * 4 + 1].color.g + - vertices[i * 4 + 2].color.g + vertices[i * 4 + 3].color.g ) / 4.0f, - ( vertices[i * 4 + 0].color.b + vertices[i * 4 + 1].color.b + - vertices[i * 4 + 2].color.b + vertices[i * 4 + 3].color.b ) / 4.0f, - ( vertices[i * 4 + 0].color.a + vertices[i * 4 + 1].color.a + - vertices[i * 4 + 2].color.a + vertices[i * 4 + 3].color.a ) / 4.0f, - }; - // R and B channels are swapped on Android - glColor4f(texcolor.b, texcolor.g, texcolor.r, texcolor.a); - -#endif -#ifdef USE_GL_DRAW_TEX - if( active_texture >= 0 && // Something fishy here eh, let's revert to generic code and hope OpenGL will handle that - (( fabsf(vertices[i * 4].pos.x - vertices[i * 4 + 1].pos.x) < 0.01f && - fabsf(vertices[i * 4].pos.y - vertices[i * 4 + 3].pos.y) < 0.01f ) || - ( fabsf(vertices[i * 4].pos.y - vertices[i * 4 + 1].pos.y) < 0.01f && - fabsf(vertices[i * 4].pos.x - vertices[i * 4 + 3].pos.x) < 0.01f )) ) - { - // No rotation - use faster glDrawTex() implementation - /* - GLint cropRect[4] = { - vertices[i * 4].tex.u, vertices[i * 4].tex.v, - vertices[i * 4 + 2].tex.u - vertices[i * 4].tex.u, - vertices[i * 4 + 2].tex.v - vertices[i * 4].tex.v - }; - glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); - */ - GLfloat cropRect[4] = { - vertices[i * 4].tex.u * textures[active_texture].w, - vertices[i * 4 + 2].tex.v * textures[active_texture].h, - (vertices[i * 4 + 2].tex.u - vertices[i * 4].tex.u) * textures[active_texture].w, - -(vertices[i * 4 + 2].tex.v - vertices[i * 4].tex.v) * textures[active_texture].h - }; - float aspectX = screen_width / (screen_x1 - screen_x0); - float aspectY = screen_height / (screen_y1 - screen_y0); - - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); - glDrawTexfOES( (vertices[i * 4].pos.x - screen_x0) * aspectX, - (screen_y1 - vertices[i * 4 + 2].pos.y) * aspectY, // Up and down are swapped for glDrawTex() - 0, - (vertices[i * 4 + 2].pos.x - vertices[i * 4].pos.x) * aspectX, - (vertices[i * 4 + 2].pos.y - vertices[i * 4].pos.y) * aspectY ); - } - else -#endif - { - //Rotation - we have to use generic implementation - glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); - } - } - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset to defaults - } - else if(drawing == DRAWING_LINES) - { - glColorPointer(4, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices + sizeof(float)*5); - glEnableClientState(GL_COLOR_ARRAY); - glDrawArrays(GL_LINES, 0, num_vertices); - } - } - -#else - // We're on acceptable hardware, not Android, just draw the texture without speed hacks - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glVertexPointer(3, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices); - glTexCoordPointer(2, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices + sizeof(float)*3); - glColorPointer(4, GL_FLOAT, - sizeof(VERTEX), - (char*)vertices + sizeof(float)*5); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - - if(render_enable) - { - if(drawing == DRAWING_QUADS) - glDrawArrays(GL_QUADS, 0, num_vertices); - else if(drawing == DRAWING_LINES) - glDrawArrays(GL_LINES, 0, num_vertices); - } -#endif - - /* Reset pointer */ - num_vertices = 0; -} - -static void add_vertices(int count) -{ - num_vertices += count; - if((num_vertices + count) >= vertex_buffer_size) - flush(); -} - -extern SDL_Joystick * EC_joystick; -SDL_Joystick * EC_joystick = NULL; - -static int try_init() -{ - const SDL_VideoInfo *info; - int flags = SDL_OPENGL; - -#ifdef ANDROID - config.gfx_screen_width = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN)[0]->w; - config.gfx_screen_height = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN)[0]->h; - - dbg_msg("gfx", "Physical display resolution is %dx%d", config.gfx_screen_width, config.gfx_screen_height); -#endif - - screen_width = config.gfx_screen_width; - screen_height = config.gfx_screen_height; - -#if defined(ANDROID) - // Redefine button layout - if( ! SDL_ANDROID_GetScreenKeyboardRedefinedByUser() ) - { - // Disable DPAD - SDL_Rect pos; - - pos.x = screen_width; - pos.y = screen_height; - pos.h = screen_height * 3 / 5; - pos.w = pos.h; - pos.x -= pos.w; - pos.y -= pos.h; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &pos); - - // Move buttons overlapped in lower-left - pos.x = 0; - pos.y = screen_height; - pos.h = screen_height / 2; - pos.w = pos.h / 2; - pos.y -= pos.h; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, &pos); - - pos.x += pos.w; - - // Jump button overlaps move buttons - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, &pos); - - pos.w *= 2; - pos.h = pos.w/2; - pos.x = 0; - pos.y -= pos.h/2; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, &pos); - - // Rope button below jump button - pos.y = 0; - pos.h = pos.h * 2 / 3; - pos.y = screen_height - pos.h; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &pos); - - // weapprev weapnext buttons - - pos.x = screen_width; - pos.y = 0; - pos.w = screen_width / 8; - pos.h = pos.w; - pos.x -= pos.w; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_5, &pos); - - pos.x -= pos.w; - - SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, &pos); - - } -#endif - - info = SDL_GetVideoInfo(); - - /* set flags */ - flags = SDL_OPENGL; - flags |= SDL_GL_DOUBLEBUFFER; - flags |= SDL_HWPALETTE; - if(config.dbg_resizable) - flags |= SDL_RESIZABLE; - - if(info->hw_available) - flags |= SDL_HWSURFACE; - else - flags |= SDL_SWSURFACE; - - if(info->blit_hw) - flags |= SDL_HWACCEL; - - if(config.gfx_fullscreen) - flags |= SDL_FULLSCREEN; - - /* set gl attributes */ - if(config.gfx_fsaa_samples) - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, config.gfx_fsaa_samples); - } - else - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); - } - - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, config.gfx_vsync); - - /* set caption */ - SDL_WM_SetCaption("Teeworlds", "Teeworlds"); - - /* create window */ - EC_screen_surface = SDL_SetVideoMode(screen_width, screen_height, 0, flags); - if(EC_screen_surface == NULL) - { - dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError()); - return -1; - } -#ifdef ANDROID - dbg_msg("gfx", "Number of joysticks: %d", SDL_NumJoysticks()); - if(SDL_NumJoysticks() > 0) - { - dbg_msg("gfx", "Joystick 0: %s", SDL_JoystickName(0)); - EC_joystick = SDL_JoystickOpen(0); - if( EC_joystick ) - dbg_msg("gfx", "Opened joystick 0, numaxes %d numbuttons %d", SDL_JoystickNumAxes(EC_joystick), SDL_JoystickNumButtons(EC_joystick)); - else - dbg_msg("gfx", "Error opening joystick 0"); - SDL_JoystickEventState(SDL_ENABLE); - } -#endif - - return 0; -} - -static int gfx_init_window() -{ - if(try_init() == 0) - return 0; - - /* try disabling fsaa */ - while(config.gfx_fsaa_samples) - { - config.gfx_fsaa_samples--; - - if(config.gfx_fsaa_samples) - dbg_msg("gfx", "lowering FSAA to %d and trying again", config.gfx_fsaa_samples); - else - dbg_msg("gfx", "disabling FSAA and trying again"); - - if(try_init() == 0) - return 0; - } - - /* try lowering the resolution */ - if(config.gfx_screen_width != 640 || config.gfx_screen_height != 480) - { - dbg_msg("gfx", "setting resolution to 640x480 and trying again"); - config.gfx_screen_width = 640; - config.gfx_screen_height = 480; - - if(try_init() == 0) - return 0; - } - - dbg_msg("gfx", "out of ideas. failed to init graphics"); - - return -1; -} - -int gfx_init() -{ - int i; - - if(config.dbg_stress) - no_gfx = 1; - - { - int systems = 0; - - if(!no_gfx) - systems |= SDL_INIT_VIDEO; - - if(config.snd_enable) - systems |= SDL_INIT_AUDIO; - - if(config.cl_eventthread) - systems |= SDL_INIT_EVENTTHREAD; - -#ifdef ANDROID - systems |= SDL_INIT_JOYSTICK; -#endif - - if(SDL_Init(systems) < 0) - { - dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError()); - return -1; - } - } - - atexit(SDL_Quit); - - if(!no_gfx) - { - #ifdef CONF_FAMILY_WINDOWS - if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) - putenv("SDL_VIDEO_WINDOW_POS=8,27"); - #endif - - if(gfx_init_window() != 0) - return -1; - } - - /* Init vertices */ - if (vertices) - mem_free(vertices); - vertices = (VERTEX*)mem_alloc(sizeof(VERTEX) * vertex_buffer_size, 1); - num_vertices = 0; - - - /* - dbg_msg("gfx", "OpenGL version %d.%d.%d", context.version_major(), - context.version_minor(), - context.version_rev());*/ - - - /* Set all z to -5.0f */ - for (i = 0; i < vertex_buffer_size; i++) - vertices[i].pos.z = -5.0f; - - /* init textures */ - first_free_texture = 0; - for(i = 0; i < MAX_TEXTURES; i++) - textures[i].next = i+1; - textures[MAX_TEXTURES-1].next = -1; - - if(!no_gfx) - { - SDL_ShowCursor(0); - gfx_mapscreen(0,0,config.gfx_screen_width, config.gfx_screen_height); - - /* set some default settings */ - glEnable(GL_BLEND); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glAlphaFunc(GL_GREATER, 0); - glEnable(GL_ALPHA_TEST); - glDepthMask(0); - -#ifdef ANDROID - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); -#else - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); -#endif - } - - /* init input */ - inp_init(); - - /* create null texture, will get id=0 */ - invalid_texture = gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data,IMG_RGBA,TEXLOAD_NORESAMPLE); - - /* perform some tests */ - /* pixeltest_dotesting(); */ - - /*if(config.dbg_stress) - gfx_minimize();*/ - - return 0; -} - -float gfx_screenaspect() -{ - return gfx_screenwidth()/(float)gfx_screenheight(); -} - -int gfx_window_active() -{ - return SDL_GetAppState()&SDL_APPINPUTFOCUS; -} - -int gfx_window_open() -{ - return SDL_GetAppState()&SDL_APPACTIVE; -} - -VIDEO_MODE fakemodes[] = { - {320,240,8,8,8}, {400,300,8,8,8}, {640,480,8,8,8}, - {720,400,8,8,8}, {768,576,8,8,8}, {800,600,8,8,8}, - {1024,600,8,8,8}, {1024,768,8,8,8}, {1152,864,8,8,8}, - {1280,768,8,8,8}, {1280,800,8,8,8}, {1280,960,8,8,8}, - {1280,1024,8,8,8}, {1368,768,8,8,8}, {1400,1050,8,8,8}, - {1440,900,8,8,8}, {1440,1050,8,8,8}, {1600,1000,8,8,8}, - {1600,1200,8,8,8}, {1680,1050,8,8,8}, {1792,1344,8,8,8}, - {1800,1440,8,8,8}, {1856,1392,8,8,8}, {1920,1080,8,8,8}, - {1920,1200,8,8,8}, {1920,1440,8,8,8}, {1920,2400,8,8,8}, - {2048,1536,8,8,8}, - - {320,240,5,6,5}, {400,300,5,6,5}, {640,480,5,6,5}, - {720,400,5,6,5}, {768,576,5,6,5}, {800,600,5,6,5}, - {1024,600,5,6,5}, {1024,768,5,6,5}, {1152,864,5,6,5}, - {1280,768,5,6,5}, {1280,800,5,6,5}, {1280,960,5,6,5}, - {1280,1024,5,6,5}, {1368,768,5,6,5}, {1400,1050,5,6,5}, - {1440,900,5,6,5}, {1440,1050,5,6,5}, {1600,1000,5,6,5}, - {1600,1200,5,6,5}, {1680,1050,5,6,5}, {1792,1344,5,6,5}, - {1800,1440,5,6,5}, {1856,1392,5,6,5}, {1920,1080,5,6,5}, - {1920,1200,5,6,5}, {1920,1440,5,6,5}, {1920,2400,5,6,5}, - {2048,1536,5,6,5} -}; - -int gfx_get_video_modes(VIDEO_MODE *list, int maxcount) -{ - int num_modes = sizeof(fakemodes)/sizeof(VIDEO_MODE); - SDL_Rect **modes; - - if(config.gfx_display_all_modes) - { - int count = sizeof(fakemodes)/sizeof(VIDEO_MODE); - mem_copy(list, fakemodes, sizeof(fakemodes)); - if(maxcount < count) - count = maxcount; - return count; - } - - /* TODO: fix this code on osx or windows */ - - modes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN); - if(modes == NULL) - { - /* no modes */ - num_modes = 0; - } - else if(modes == (SDL_Rect**)-1) - { - /* all modes */ - } - else - { - int i; - num_modes = 0; - for(i = 0; modes[i]; ++i) - { - if(num_modes == maxcount) - break; - list[num_modes].width = modes[i]->w; - list[num_modes].height = modes[i]->h; - list[num_modes].red = 8; - list[num_modes].green = 8; - list[num_modes].blue = 8; -#ifdef ANDROID - list[num_modes].red = 5; - list[num_modes].green = 6; - list[num_modes].blue = 5; -#endif - num_modes++; - } - } - - return num_modes; -} - -int gfx_unload_texture(int index) -{ - if(index == invalid_texture) - return 0; - - if(index < 0) - return 0; - - glDeleteTextures(1, &textures[index].tex); - textures[index].next = first_free_texture; - memory_usage -= textures[index].memsize; - first_free_texture = index; - return 0; -} - -void gfx_blend_none() -{ - if(no_gfx) return; - glDisable(GL_BLEND); -} - -void gfx_blend_normal() -{ - if(no_gfx) return; - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -} - -void gfx_blend_additive() -{ - if(no_gfx) return; - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); -} - -int gfx_memory_usage() { return memory_usage; } - -static unsigned char sample(int w, int h, const unsigned char *data, int u, int v, int offset) -{ - return (data[(v*w+u)*4+offset]+ - data[(v*w+u+1)*4+offset]+ - data[((v+1)*w+u)*4+offset]+ - data[((v+1)*w+u+1)*4+offset])/4; -} - -static int -power_of_2(int input) -{ - int value = 1; - - while (value < input) { - value <<= 1; - } - return value; -} - -int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format, int flags) -{ - int mipmap = 1; - unsigned char *texdata = (unsigned char *)data; - unsigned char *tmpdata = 0; - int oglformat = 0; - int store_oglformat = 0; - int tex = 0; - int glesType = 0; - - /* don't waste memory on texture if we are stress testing */ - if(config.dbg_stress || no_gfx) - return invalid_texture; - - /* grab texture */ - tex = first_free_texture; - first_free_texture = textures[tex].next; - textures[tex].next = -1; - - /* resample if needed */ - if(!(flags&TEXLOAD_NORESAMPLE) && config.gfx_texture_quality==0) - { - if(w > 16 && h > 16 && format == IMG_RGBA) - { - unsigned char *tmpdata; - int c = 0; - int x, y; - - tmpdata = (unsigned char *)mem_alloc(w*h*4, 1); - - w/=2; - h/=2; - - for(y = 0; y < h; y++) - for(x = 0; x < w; x++, c++) - { - tmpdata[c*4] = sample(w*2, h*2, texdata, x*2,y*2, 0); - tmpdata[c*4+1] = sample(w*2, h*2, texdata, x*2,y*2, 1); - tmpdata[c*4+2] = sample(w*2, h*2, texdata, x*2,y*2, 2); - tmpdata[c*4+3] = sample(w*2, h*2, texdata, x*2,y*2, 3); - } - texdata = tmpdata; - } - } - - oglformat = GL_RGBA; - glesType = GL_UNSIGNED_SHORT_5_5_5_1; - if(format == IMG_RGB) - { - oglformat = GL_RGB; - glesType = GL_UNSIGNED_SHORT_5_6_5; - } - else if(format == IMG_ALPHA) - { - oglformat = GL_ALPHA; -#ifdef ANDROID - oglformat = GL_RGBA; // No pure alpha textures on Android -#endif - glesType = GL_UNSIGNED_SHORT_4_4_4_4; - } - -#ifndef ANDROID - /* upload texture */ - if(config.gfx_texture_compression) - { - store_oglformat = GL_COMPRESSED_RGBA_ARB; - if(store_format == IMG_RGB) - store_oglformat = GL_COMPRESSED_RGB_ARB; - else if(store_format == IMG_ALPHA) - store_oglformat = GL_COMPRESSED_ALPHA_ARB; - } - else -#endif - { - store_oglformat = GL_RGBA; - if(store_format == IMG_RGB) - store_oglformat = GL_RGB; - else if(store_format == IMG_ALPHA) - store_oglformat = GL_ALPHA; - } - - glGenTextures(1, &textures[tex].tex); - glBindTexture(GL_TEXTURE_2D, textures[tex].tex); -#ifdef ANDROID - -/* -#define CONVERT_RGBA8888_RGBA4444( pixel ) \ - ( ( pixel >> 4 ) & 0xF ) | \ - ( ( pixel >> 8 ) & 0xF0 ) | \ - ( ( pixel >> 12 ) & 0xF00 ) | \ - ( ( pixel >> 16 ) & 0xF000 ) -*/ - -// R and B channels are swapped on Android - -#define SWAP_RB_8888( pixel ) \ - ((pixel & 0xFF) << 16 | \ - (pixel & 0xFF00) | \ - (pixel & 0xFF0000) >> 16 | \ - (pixel & 0xFF000000)) - -#define CONVERT_ARGB8888_RGBA4444( pixel ) \ - ( ( pixel >> 28 ) & 0xF ) | \ - ( ( pixel ) & 0xF0 ) | \ - ( ( pixel >> 4 ) & 0xF00 ) | \ - ( ( pixel >> 8 ) & 0xF000 ) - -#define CONVERT_ARGB8888_RGBA5551( pixel ) \ - ( ( pixel >> 31 ) & 0x1 ) | \ - ( ( pixel >> 2 ) & 0x3E ) | \ - ( ( pixel >> 5 ) & 0x7C0 ) | \ - ( ( pixel >> 8 ) & 0xF800 ) - - -#define CONVERT_RGB888_RGB565( pixel ) \ - ( ( pixel >> 3 ) & 0x1F ) | \ - ( ( pixel >> 5 ) & 0x7E0 ) | \ - ( ( pixel >> 8 ) & 0xF800 ) - - tmpdata = (unsigned char *)mem_alloc(w*h*2, 1); - { - Uint16 x, y; - if(format == IMG_RGB) - { - for(y = 0; y < h; y++) - for(x = 0; x < w; x++) - { - ((Uint16 *)tmpdata)[ y*(Uint32)w+x ] = CONVERT_RGB888_RGB565( SWAP_RB_8888(((* ((Uint32 *)(texdata+(y*w+x)*3))) & 0xFFFFFF) ) ); - } - } - else - if(format == IMG_RGBA) - { - for(y = 0; y < h; y++) - for(x = 0; x < w; x++) - { - ((Uint16 *)tmpdata)[ y*(Uint32)w+x ] = CONVERT_ARGB8888_RGBA5551( SWAP_RB_8888((((Uint32 *)texdata)[ y*w+x ]) ) ); - } - } - else - { - for(y = 0; y < h; y++) - for(x = 0; x < w; x++) - { - ((Uint16 *)tmpdata)[ y*(Uint32)w+x ] = CONVERT_ARGB8888_RGBA4444( SWAP_RB_8888((((Uint32 *)texdata)[ y*w+x ]) ) ); - } - } - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D( GL_TEXTURE_2D, 0, oglformat, power_of_2(w), power_of_2(h), 0, oglformat, glesType, NULL ); - glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, w, h, oglformat, glesType, tmpdata); -#else - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - gluBuild2DMipmaps(GL_TEXTURE_2D, store_oglformat, w, h, oglformat, GL_UNSIGNED_BYTE, texdata); -#endif - textures[tex].w = w; - textures[tex].h = h; - active_texture = tex; - - /* calculate memory usage */ - { - int pixel_size = 4; - if(store_format == IMG_RGB) - pixel_size = 3; - else if(store_format == IMG_ALPHA) - pixel_size = 1; - - textures[tex].memsize = w*h*pixel_size; - if(mipmap) - { - while(w > 2 && h > 2) - { - w>>=1; - h>>=1; - textures[tex].memsize += w*h*pixel_size; - } - } -#ifdef ANDROID - textures[tex].memsize = power_of_2(w)*power_of_2(h)*2; -#endif - } - - memory_usage += textures[tex].memsize; - mem_free(tmpdata); - return tex; -} - -/* simple uncompressed RGBA loaders */ -int gfx_load_texture(const char *filename, int store_format, int flags) -{ - int l = strlen(filename); - int id; - IMAGE_INFO img; - - if(l < 3) - return -1; - if(gfx_load_png(&img, filename)) - { - if (store_format == IMG_AUTO) - store_format = img.format; - - id = gfx_load_texture_raw(img.width, img.height, img.format, img.data, store_format, flags); - mem_free(img.data); - return id; - } - - return invalid_texture; -} - -int gfx_load_png(IMAGE_INFO *img, const char *filename) -{ - char completefilename[512]; - unsigned char *buffer; - png_t png; - - /* open file for reading */ - png_init(0,0); - - engine_getpath(completefilename, sizeof(completefilename), filename, IOFLAG_READ); - - if(png_open_file(&png, completefilename) != PNG_NO_ERROR) - { - dbg_msg("game/png", "failed to open file. filename='%s'", completefilename); - return 0; - } - - if(png.depth != 8 || (png.color_type != PNG_TRUECOLOR && png.color_type != PNG_TRUECOLOR_ALPHA)) - { - dbg_msg("game/png", "invalid format. filename='%s'", completefilename); - png_close_file(&png); - return 0; - } - - buffer = (unsigned char *)mem_alloc(png.width * png.height * png.bpp, 1); - png_get_data(&png, buffer); - png_close_file(&png); - - img->width = png.width; - img->height = png.height; - if(png.color_type == PNG_TRUECOLOR) - img->format = IMG_RGB; - else if(png.color_type == PNG_TRUECOLOR_ALPHA) - img->format = IMG_RGBA; - img->data = buffer; - return 1; -} - -void gfx_shutdown() -{ - if (vertices) - mem_free(vertices); - - /* TODO: SDL, is this correct? */ - SDL_Quit(); -} - -void gfx_screenshot() -{ - do_screenshot = 1; -} - -void gfx_swap() -{ - if(do_screenshot) - { - /* find filename */ - char filename[128]; - static int index = 1; - - for(; index < 1000; index++) - { - IOHANDLE io; - str_format(filename, sizeof(filename), "screenshots/screenshot%04d.png", index); - io = engine_openfile(filename, IOFLAG_READ); - if(io) - io_close(io); - else - break; - } - - gfx_screenshot_direct(filename); - - do_screenshot = 0; - } - - { - static PERFORMACE_INFO pscope = {"glfwSwapBuffers", 0}; - perf_start(&pscope); - SDL_GL_SwapBuffers(); - perf_end(); - } - - #ifndef ANDROID - if(render_enable && config.gfx_finish) - glFinish(); - #endif -} - -void gfx_screenshot_direct(const char *filename) -{ - /* fetch image data */ - int y; - int w = screen_width; - int h = screen_height; - unsigned char *pixel_data = (unsigned char *)mem_alloc(w*(h+1)*4, 1); - unsigned char *temp_row = pixel_data+w*h*4; - glReadPixels(0,0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_data); - - /* flip the pixel because opengl works from bottom left corner */ - for(y = 0; y < h/2; y++) - { - mem_copy(temp_row, pixel_data+y*w*4, w*4); - mem_copy(pixel_data+y*w*4, pixel_data+(h-y-1)*w*4, w*4); - mem_copy(pixel_data+(h-y-1)*w*4, temp_row,w*4); - } - - /* find filename */ - { - char wholepath[1024]; - png_t png; - - engine_savepath(filename, wholepath, sizeof(wholepath)); - - /* save png */ - dbg_msg("client", "saved screenshot to '%s'", wholepath); - png_open_file_write(&png, wholepath); - png_set_data(&png, w, h, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)pixel_data); - png_close_file(&png); - } - - /* clean up */ - mem_free(pixel_data); -} - -int gfx_screenwidth() -{ - return screen_width; -} - -int gfx_screenheight() -{ - return screen_height; -} - -void gfx_texture_set(int slot) -{ - dbg_assert(drawing == 0, "called gfx_texture_set within begin"); - if(no_gfx) return; - if(slot == -1) - { - glDisable(GL_TEXTURE_2D); - } - else - { - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, textures[slot].tex); - } - active_texture = slot; -} - -void gfx_clear(float r, float g, float b) -{ - if(no_gfx) return; - #ifndef ANDROID - glClearColor(r,g,b,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - #endif -} - -void gfx_mapscreen(float tl_x, float tl_y, float br_x, float br_y) -{ - screen_x0 = tl_x; - screen_y0 = tl_y; - screen_x1 = br_x; - screen_y1 = br_y; - if(no_gfx) return; - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); -#ifdef ANDROID -#define glOrtho glOrthof -#endif - glOrtho(tl_x, br_x, br_y, tl_y, 1.0f, 10.f); -} - -void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y) -{ - *tl_x = screen_x0; - *tl_y = screen_y0; - *br_x = screen_x1; - *br_y = screen_y1; -} - -void gfx_quads_begin() -{ - dbg_assert(drawing == 0, "called quads_begin twice"); - drawing = DRAWING_QUADS; - - gfx_quads_setsubset(0,0,1,1); - gfx_quads_setrotation(0); - gfx_setcolor(1,1,1,1); -} - -void gfx_quads_end() -{ - dbg_assert(drawing == DRAWING_QUADS, "called quads_end without begin"); - flush(); - drawing = 0; -} - - -void gfx_quads_setrotation(float angle) -{ - dbg_assert(drawing == DRAWING_QUADS, "called gfx_quads_setrotation without begin"); - rotation = angle; -} - -void gfx_setcolorvertex(int i, float r, float g, float b, float a) -{ - dbg_assert(drawing != 0, "called gfx_quads_setcolorvertex without begin"); - color[i].r = r; - color[i].g = g; - color[i].b = b; - color[i].a = a; -} - -void gfx_setcolor(float r, float g, float b, float a) -{ - dbg_assert(drawing != 0, "called gfx_quads_setcolor without begin"); - gfx_setcolorvertex(0, r, g, b, a); - gfx_setcolorvertex(1, r, g, b, a); - gfx_setcolorvertex(2, r, g, b, a); - gfx_setcolorvertex(3, r, g, b, a); -} - -void gfx_quads_setsubset(float tl_u, float tl_v, float br_u, float br_v) -{ - dbg_assert(drawing == DRAWING_QUADS, "called gfx_quads_setsubset without begin"); - - texture[0].u = tl_u; texture[1].u = br_u; - texture[0].v = tl_v; texture[1].v = tl_v; - - texture[3].u = tl_u; texture[2].u = br_u; - texture[3].v = br_v; texture[2].v = br_v; -} - -void gfx_quads_setsubset_free( - float x0, float y0, float x1, float y1, - float x2, float y2, float x3, float y3) -{ - texture[0].u = x0; texture[0].v = y0; - texture[1].u = x1; texture[1].v = y1; - texture[2].u = x2; texture[2].v = y2; - texture[3].u = x3; texture[3].v = y3; -} - - -static void rotate(VEC3 *center, VEC3 *point) -{ - float x = point->x - center->x; - float y = point->y - center->y; - point->x = x * cosf(rotation) - y * sinf(rotation) + center->x; - point->y = x * sinf(rotation) + y * cosf(rotation) + center->y; -} - -void gfx_quads_draw(float x, float y, float w, float h) -{ - gfx_quads_drawTL(x-w/2, y-h/2,w,h); -} - -void gfx_quads_drawTL(float x, float y, float width, float height) -{ - VEC3 center; - - dbg_assert(drawing == DRAWING_QUADS, "called quads_draw without begin"); - - center.x = x + width/2; - center.y = y + height/2; - center.z = 0; - - vertices[num_vertices].pos.x = x; - vertices[num_vertices].pos.y = y; - vertices[num_vertices].tex = texture[0]; - vertices[num_vertices].color = color[0]; - rotate(¢er, &vertices[num_vertices].pos); - - vertices[num_vertices + 1].pos.x = x+width; - vertices[num_vertices + 1].pos.y = y; - vertices[num_vertices + 1].tex = texture[1]; - vertices[num_vertices + 1].color = color[1]; - rotate(¢er, &vertices[num_vertices + 1].pos); - - vertices[num_vertices + 2].pos.x = x + width; - vertices[num_vertices + 2].pos.y = y+height; - vertices[num_vertices + 2].tex = texture[2]; - vertices[num_vertices + 2].color = color[2]; - rotate(¢er, &vertices[num_vertices + 2].pos); - - vertices[num_vertices + 3].pos.x = x; - vertices[num_vertices + 3].pos.y = y+height; - vertices[num_vertices + 3].tex = texture[3]; - vertices[num_vertices + 3].color = color[3]; - rotate(¢er, &vertices[num_vertices + 3].pos); - - add_vertices(4); -} - -void gfx_quads_draw_freeform( - float x0, float y0, float x1, float y1, - float x2, float y2, float x3, float y3) -{ - dbg_assert(drawing == DRAWING_QUADS, "called quads_draw_freeform without begin"); - - vertices[num_vertices].pos.x = x0; - vertices[num_vertices].pos.y = y0; - vertices[num_vertices].tex = texture[0]; - vertices[num_vertices].color = color[0]; - - vertices[num_vertices + 1].pos.x = x1; - vertices[num_vertices + 1].pos.y = y1; - vertices[num_vertices + 1].tex = texture[1]; - vertices[num_vertices + 1].color = color[1]; - - vertices[num_vertices + 2].pos.x = x3; - vertices[num_vertices + 2].pos.y = y3; - vertices[num_vertices + 2].tex = texture[3]; - vertices[num_vertices + 2].color = color[3]; - - vertices[num_vertices + 3].pos.x = x2; - vertices[num_vertices + 3].pos.y = y2; - vertices[num_vertices + 3].tex = texture[2]; - vertices[num_vertices + 3].color = color[2]; - - add_vertices(4); -} - -void gfx_quads_text(float x, float y, float size, float r, float g, float b, float a, const char *text) -{ - float startx = x; - - gfx_quads_begin(); - gfx_setcolor(r,g,b,a); - - while(*text) - { - char c = *text; - text++; - - if(c == '\n') - { - x = startx; - y += size; - } - else - { - gfx_quads_setsubset( - (c%16)/16.0f, - (c/16)/16.0f, - (c%16)/16.0f+1.0f/16.0f, - (c/16)/16.0f+1.0f/16.0f); - - gfx_quads_drawTL(x,y,size,size); - x += size/2; - } - } - - gfx_quads_end(); -} - -void gfx_lines_begin() -{ - dbg_assert(drawing == 0, "called begin twice"); - drawing = DRAWING_LINES; - gfx_setcolor(1,1,1,1); -} - -void gfx_lines_end() -{ - dbg_assert(drawing == DRAWING_LINES, "called end without begin"); - flush(); - drawing = 0; -} - -void gfx_lines_draw(float x0, float y0, float x1, float y1) -{ - dbg_assert(drawing == DRAWING_LINES, "called draw without begin"); - - vertices[num_vertices].pos.x = x0; - vertices[num_vertices].pos.y = y0; - vertices[num_vertices].tex = texture[0]; - vertices[num_vertices].color = color[0]; - - vertices[num_vertices + 1].pos.x = x1; - vertices[num_vertices + 1].pos.y = y1; - vertices[num_vertices + 1].tex = texture[1]; - vertices[num_vertices + 1].color = color[1]; - - add_vertices(2); -} - -void gfx_clip_enable(int x, int y, int w, int h) -{ - if(no_gfx) return; - glScissor(x, gfx_screenheight()-(y+h), w, h); - glEnable(GL_SCISSOR_TEST); -} - -void gfx_clip_disable() -{ - if(no_gfx) return; - glDisable(GL_SCISSOR_TEST); -} - -void gfx_minimize() -{ - SDL_WM_IconifyWindow(); -} - -void gfx_maximize() -{ - /* TODO: SDL */ -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx_text.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx_text.cpp deleted file mode 100644 index 5b55febdf..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_gfx_text.cpp +++ /dev/null @@ -1,239 +0,0 @@ -#include -#include -#include - -static int word_length(const char *text) -{ - int s = 1; - while(1) - { - if(*text == 0) - return s-1; - if(*text == '\n' || *text == '\t' || *text == ' ') - return s; - text++; - s++; - } -} - -static float text_r=1; -static float text_g=1; -static float text_b=1; -static float text_a=1; - -static FONT_SET *default_font_set = 0; -void gfx_text_set_default_font(void *font) -{ - default_font_set = (FONT_SET *)font; -} - - -void gfx_text_set_cursor(TEXT_CURSOR *cursor, float x, float y, float font_size, int flags) -{ - mem_zero(cursor, sizeof(*cursor)); - cursor->font_size = font_size; - cursor->start_x = x; - cursor->start_y = y; - cursor->x = x; - cursor->y = y; - cursor->line_count = 1; - cursor->line_width = -1; - cursor->flags = flags; - cursor->charcount = 0; -} - -void gfx_text_ex(TEXT_CURSOR *cursor, const char *text, int length) -{ - FONT_SET *font_set = (FONT_SET *)cursor->font_set; - float screen_x0, screen_y0, screen_x1, screen_y1; - float fake_to_screen_x, fake_to_screen_y; - int actual_x, actual_y; - - FONT *font; - int actual_size; - int i; - int got_new_line = 0; - float draw_x, draw_y; - float cursor_x, cursor_y; - const char *end; - - float size = cursor->font_size; - - /* to correct coords, convert to screen coords, round, and convert back */ - gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); - - fake_to_screen_x = (gfx_screenwidth()/(screen_x1-screen_x0)); - fake_to_screen_y = (gfx_screenheight()/(screen_y1-screen_y0)); - actual_x = cursor->x * fake_to_screen_x; - actual_y = cursor->y * fake_to_screen_y; - - cursor_x = actual_x / fake_to_screen_x; - cursor_y = actual_y / fake_to_screen_y; - - /* same with size */ - actual_size = size * fake_to_screen_y; - size = actual_size / fake_to_screen_y; - - if(!font_set) - font_set = default_font_set; - - font = font_set_pick(font_set, actual_size); - - if (length < 0) - length = strlen(text); - - end = text + length; - - /* if we don't want to render, we can just skip the first outline pass */ - i = 1; - if(cursor->flags&TEXTFLAG_RENDER) - i = 0; - - for(;i < 2; i++) - { - const unsigned char *current = (unsigned char *)text; - int to_render = length; - draw_x = cursor_x; - draw_y = cursor_y; - - if(cursor->flags&TEXTFLAG_RENDER) - { - if (i == 0) - gfx_texture_set(font->outline_texture); - else - gfx_texture_set(font->text_texture); - - gfx_quads_begin(); - if (i == 0) - gfx_setcolor(0.0f, 0.0f, 0.0f, 0.3f*text_a); - else - gfx_setcolor(text_r, text_g, text_b, text_a); - } - - while(to_render > 0) - { - int new_line = 0; - int this_batch = to_render; - if(cursor->line_width > 0 && !(cursor->flags&TEXTFLAG_STOP_AT_END)) - { - int wlen = word_length((char *)current); - TEXT_CURSOR compare = *cursor; - compare.x = draw_x; - compare.y = draw_y; - compare.flags &= ~TEXTFLAG_RENDER; - compare.line_width = -1; - gfx_text_ex(&compare, text, wlen); - - if(compare.x-draw_x > cursor->line_width) - { - /* word can't be fitted in one line, cut it */ - TEXT_CURSOR cutter = *cursor; - cutter.charcount = 0; - cutter.x = draw_x; - cutter.y = draw_y; - cutter.flags &= ~TEXTFLAG_RENDER; - cutter.flags |= TEXTFLAG_STOP_AT_END; - - gfx_text_ex(&cutter, (const char *)current, wlen); - wlen = cutter.charcount; - new_line = 1; - - if(wlen <= 3) /* if we can't place 3 chars of the word on this line, take the next */ - wlen = 0; - } - else if(compare.x-cursor->start_x > cursor->line_width) - { - new_line = 1; - wlen = 0; - } - - this_batch = wlen; - } - - if((const char *)current+this_batch > end) - this_batch = (const char *)end-(const char *)current; - - to_render -= this_batch; - - while(this_batch-- > 0) - { - float tex_x0, tex_y0, tex_x1, tex_y1; - float width, height; - float x_offset, y_offset, x_advance; - float advance; - - if(*current == '\n') - { - draw_x = cursor->start_x; - draw_y += size; - draw_x = (int)(draw_x * fake_to_screen_x) / fake_to_screen_x; /* realign */ - draw_y = (int)(draw_y * fake_to_screen_y) / fake_to_screen_y; - current++; - continue; - } - - font_character_info(font, *current, &tex_x0, &tex_y0, &tex_x1, &tex_y1, &width, &height, &x_offset, &y_offset, &x_advance); - - if(cursor->flags&TEXTFLAG_RENDER) - { - gfx_quads_setsubset(tex_x0, tex_y0, tex_x1, tex_y1); - gfx_quads_drawTL(draw_x+x_offset*size, draw_y+y_offset*size, width*size, height*size); - } - - advance = x_advance + font_kerning(font, *current, *(current+1)); - - if(cursor->flags&TEXTFLAG_STOP_AT_END && draw_x+advance*size-cursor->start_x > cursor->line_width) - { - /* we hit the end of the line, no more to render or count */ - to_render = 0; - break; - } - - draw_x += advance*size; - cursor->charcount++; - current++; - } - - if(new_line) - { - draw_x = cursor->start_x; - draw_y += size; - got_new_line = 1; - draw_x = (int)(draw_x * fake_to_screen_x) / fake_to_screen_x; /* realign */ - draw_y = (int)(draw_y * fake_to_screen_y) / fake_to_screen_y; - } - } - - if(cursor->flags&TEXTFLAG_RENDER) - gfx_quads_end(); - } - - cursor->x = draw_x; - - if(got_new_line) - cursor->y = draw_y; -} - -void gfx_text(void *font_set_v, float x, float y, float size, const char *text, int max_width) -{ - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, x, y, size, TEXTFLAG_RENDER); - cursor.line_width = max_width; - gfx_text_ex(&cursor, text, -1); -} - -float gfx_text_width(void *font_set_v, float size, const char *text, int length) -{ - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, 0, 0, size, 0); - gfx_text_ex(&cursor, text, length); - return cursor.x; -} - -void gfx_text_color(float r, float g, float b, float a) -{ - text_r = r; - text_g = g; - text_b = b; - text_a = a; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_inp.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_inp.cpp deleted file mode 100644 index b2f5644c0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_inp.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "SDL.h" - -#include -#include -#include - -#include - -static struct -{ - unsigned char presses; - unsigned char releases; -} input_count[2][1024] = {{{0}}, {{0}}}; - -static unsigned char input_state[2][1024] = {{0}, {0}}; - -static int input_current = 0; -static int input_grabbed = 0; - -static unsigned int last_release = 0; -static unsigned int release_delta = -1; - -extern SDL_Joystick * EC_joystick; -extern SDL_Surface *EC_screen_surface; - -static void add_event(char c, int key, int flags); - -void inp_mouse_relative(int *x, int *y) -{ - int nx = 0, ny = 0; - float sens = config.inp_mousesens/100.0f; - - if(config.inp_grab) - SDL_GetRelativeMouseState(&nx, &ny); - else - { - if(input_grabbed) - { - SDL_GetMouseState(&nx,&ny); - SDL_WarpMouse(gfx_screenwidth()/2,gfx_screenheight()/2); - nx -= gfx_screenwidth()/2; ny -= gfx_screenheight()/2; - } - } - - *x = nx*sens; - *y = ny*sens; -} - -void inp_mouse_absolute(int *x, int *y) -{ - SDL_GetMouseState(x, y); -} - -void inp_warp_mouse(int x, int y) -{ - SDL_WarpMouse(x,y); -} - -int inp_process_joystick() -{ - if( !EC_joystick || !EC_screen_surface ) - return 0; - int jx = SDL_JoystickGetAxis(EC_joystick, 0); - int jy = SDL_JoystickGetAxis(EC_joystick, 1); - if( abs(jx) > 10 && abs(jy) > 10 ) - { - jx = (jx + 32768) * EC_screen_surface->w / 65536; - jy = (jy + 32768) * EC_screen_surface->h / 65536; - SDL_WarpMouse(jx,jy); - SDL_PumpEvents(); - return 1; - } - return 0; -} - -enum -{ - INPUT_BUFFER_SIZE=32 -}; - -static INPUT_EVENT input_events[INPUT_BUFFER_SIZE]; -static int num_events = 0; - -static void add_event(char c, int key, int flags) -{ - if(num_events != INPUT_BUFFER_SIZE) - { - input_events[num_events].ch = c; - input_events[num_events].key = key; - input_events[num_events].flags = flags; - num_events++; - } -} - -int inp_num_events() -{ - return num_events; -} - -void inp_clear_events() -{ - num_events = 0; -} - -INPUT_EVENT inp_get_event(int index) -{ - if(index < 0 || index >= num_events) - { - INPUT_EVENT e = {0,0}; - return e; - } - - return input_events[index]; -} - -void inp_init() -{ - SDL_EnableUNICODE(1); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); -} - -void inp_mouse_mode_absolute() -{ - SDL_ShowCursor(1); - input_grabbed = 0; - if(config.inp_grab) - SDL_WM_GrabInput(SDL_GRAB_OFF); -} - -void inp_mouse_mode_relative() -{ - SDL_ShowCursor(0); - input_grabbed = 1; - if(config.inp_grab) - SDL_WM_GrabInput(SDL_GRAB_ON); -} - -int inp_mouse_doubleclick() -{ - return release_delta < (time_freq() >> 2); -} - -void inp_clear_key_states() -{ - mem_zero(input_state, sizeof(input_state)); - mem_zero(input_count, sizeof(input_count)); -} - -int inp_key_presses(int key) -{ - return input_count[input_current][key].presses; -} - -int inp_key_releases(int key) -{ - return input_count[input_current][key].releases; -} - -int inp_key_state(int key) -{ - return input_state[input_current][key]; -} - -int inp_key_pressed(int key) { return input_state[input_current][key]; } -int inp_key_was_pressed(int key) { return input_state[input_current^1][key]; } -int inp_key_down(int key) { return inp_key_pressed(key)&&!inp_key_was_pressed(key); } -int inp_button_pressed(int button) { return input_state[input_current][button]; } - -static int oldjoy = 0; - -void inp_update() -{ - int i; - - if(input_grabbed && !gfx_window_active()) - inp_mouse_mode_absolute(); - - /*if(!input_grabbed && gfx_window_active()) - inp_mouse_mode_relative();*/ - - /* clear and begin count on the other one */ - input_current^=1; - mem_zero(&input_count[input_current], sizeof(input_count[input_current])); - mem_zero(&input_state[input_current], sizeof(input_state[input_current])); - - { - Uint8 *state = SDL_GetKeyState(&i); - if(i >= KEY_LAST) - i = KEY_LAST-1; - mem_copy(input_state[input_current], state, i); - } - - /* these states must always be updated manually because they are not in the GetKeyState from SDL */ - i = SDL_GetMouseState(NULL, NULL); - int joy = inp_process_joystick(); - if(i&SDL_BUTTON(1)) input_state[input_current][KEY_MOUSE_1] = 1; /* 1 is left */ - if(i&SDL_BUTTON(3)) input_state[input_current][KEY_MOUSE_2] = 1; /* 3 is right */ - if(i&SDL_BUTTON(2)) input_state[input_current][KEY_MOUSE_3] = 1; /* 2 is middle */ - if(i&SDL_BUTTON(4)) input_state[input_current][KEY_MOUSE_4] = 1; - if(i&SDL_BUTTON(5)) input_state[input_current][KEY_MOUSE_5] = 1; - if(i&SDL_BUTTON(6)) input_state[input_current][KEY_MOUSE_6] = 1; - if(i&SDL_BUTTON(7)) input_state[input_current][KEY_MOUSE_7] = 1; - if(i&SDL_BUTTON(8)) input_state[input_current][KEY_MOUSE_8] = 1; - - { - SDL_Event event; - - while(SDL_PollEvent(&event)) - { - int key = -1; - int action = INPFLAG_PRESS; - switch (event.type) - { - /* handle keys */ - case SDL_KEYDOWN: - if(event.key.keysym.unicode < 255) - add_event(event.key.keysym.unicode, 0, 0); - key = event.key.keysym.sym; - break; - case SDL_KEYUP: - action = INPFLAG_RELEASE; - key = event.key.keysym.sym; - break; - - /* handle mouse buttons */ - case SDL_MOUSEBUTTONUP: - action = INPFLAG_RELEASE; - - if(event.button.button == 1) - { - release_delta = time_get() - last_release; - last_release = time_get(); - } - - /* fall through */ - case SDL_MOUSEBUTTONDOWN: - if(event.button.button == SDL_BUTTON_LEFT) key = KEY_MOUSE_1; - if(event.button.button == SDL_BUTTON_RIGHT) key = KEY_MOUSE_2; - if(event.button.button == SDL_BUTTON_MIDDLE) key = KEY_MOUSE_3; - if(event.button.button == SDL_BUTTON_WHEELUP) key = KEY_MOUSE_WHEEL_UP; - if(event.button.button == SDL_BUTTON_WHEELDOWN) key = KEY_MOUSE_WHEEL_DOWN; - if(event.button.button == 6) key = KEY_MOUSE_6; - if(event.button.button == 7) key = KEY_MOUSE_7; - if(event.button.button == 8) key = KEY_MOUSE_8; - break; - - /* other messages */ - case SDL_QUIT: -#ifdef ANDROID - case SDL_VIDEORESIZE: -#endif - /* TODO: cleaner exit */ - exit(0); - break; - } - - /* */ - if(key != -1) - { - input_count[input_current][key].presses++; - if(action == INPFLAG_PRESS) - input_state[input_current][key] = 1; - add_event(0, key, action); - } - - } - - if(joy && !input_state[input_current][KEY_MOUSE_1]) - { - input_count[input_current][KEY_MOUSE_1].presses++; - add_event(0, KEY_MOUSE_1, INPFLAG_PRESS); - } - if(!joy && oldjoy && !(i&SDL_BUTTON(1))) - { - input_count[input_current][KEY_MOUSE_1].presses++; - add_event(0, KEY_MOUSE_1, INPFLAG_RELEASE); - } - oldjoy = joy; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_snd.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_snd.cpp deleted file mode 100644 index 7b2546e3f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_snd.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include - -#include "SDL.h" - - -extern "C" { -#include -} - -#include -#include -#include -#ifdef ANDROID -#include -#include -#endif - -enum -{ - NUM_SAMPLES = 512, - NUM_VOICES = 64, - NUM_CHANNELS = 16, -}; - -typedef struct -{ - short *data; - int num_frames; - int rate; - int channels; - int loop_start; - int loop_end; -} SAMPLE; - -typedef struct -{ - int vol; - int pan; -} CHANNEL; - -typedef struct -{ - SAMPLE *snd; - CHANNEL *channel; - int tick; - int vol; /* 0 - 255 */ - int flags; - int x, y; -} VOICE; - -static SAMPLE samples[NUM_SAMPLES] = { {0} }; -static VOICE voices[NUM_VOICES] = { {0} }; -static CHANNEL channels[NUM_CHANNELS] = { {255, 0} }; - -static LOCK sound_lock = 0; -static int sound_enabled = 0; - -static int center_x = 0; -static int center_y = 0; - -static int mixing_rate = 48000; -static volatile int sound_volume = 100; - -static int next_voice = 0; -static int * mix_buffer = NULL; - -void snd_set_channel(int cid, float vol, float pan) -{ - channels[cid].vol = (int)(vol*255.0f); - channels[cid].pan = (int)(pan*255.0f); /* TODO: this is only on and off right now */ -} - -static int play(int cid, int sid, int flags, float x, float y) -{ - int vid = -1; - int i; - - lock_wait(sound_lock); - - /* search for voice */ - for(i = 0; i < NUM_VOICES; i++) - { - int id = (next_voice + i) % NUM_VOICES; - if(!voices[id].snd) - { - vid = id; - next_voice = id+1; - break; - } - } - - /* voice found, use it */ - if(vid != -1) - { - voices[vid].snd = &samples[sid]; - voices[vid].channel = &channels[cid]; - voices[vid].tick = 0; - voices[vid].vol = 255; - voices[vid].flags = flags; - voices[vid].x = (int)x; - voices[vid].y = (int)y; - } - - lock_release(sound_lock); - return vid; -} - -int snd_play_at(int cid, int sid, int flags, float x, float y) -{ - return play(cid, sid, flags|SNDFLAG_POS, x, y); -} - -int snd_play(int cid, int sid, int flags) -{ - return play(cid, sid, flags, 0, 0); -} - -void snd_stop(int vid) -{ - /* TODO: a nice fade out */ - lock_wait(sound_lock); - voices[vid].snd = 0; - lock_release(sound_lock); -} - -/* TODO: there should be a faster way todo this */ -static short int2short(int i) -{ - if(i > 0x7fff) - return 0x7fff; - else if(i < -0x7fff) - return -0x7fff; - return i; -} - -static int iabs(int i) -{ - if(i<0) - return -i; - return i; -} - -static void mix(short *final_out, unsigned frames) -{ - int i, s; - int master_vol; - - /* aquire lock while we are mixing */ - lock_wait(sound_lock); - -#ifdef ANDROID - bzero(mix_buffer, frames * 2 * sizeof(int)); -#else - memset(mix_buffer, 0, sizeof(mix_buffer)); -#endif - - master_vol = sound_volume; - - for(i = 0; i < NUM_VOICES; i++) - { - if(voices[i].snd) - { - /* mix voice */ - VOICE *v = &voices[i]; - int *out = mix_buffer; - - int step = v->snd->channels; /* setup input sources */ - short *in_l = &v->snd->data[v->tick*step]; - short *in_r = &v->snd->data[v->tick*step+1]; - - int end = v->snd->num_frames-v->tick; - - int rvol = v->channel->vol; - int lvol = v->channel->vol; - - /* make sure that we don't go outside the sound data */ - if(frames < end) - end = frames; - - /* check if we have a mono sound */ - if(v->snd->channels == 1) - in_r = in_l; - - /* volume calculation */ - if(v->flags&SNDFLAG_POS && v->channel->pan) - { - /* TODO: we should respect the channel panning value */ - const int range = 1500; /* magic value, remove */ - int dx = v->x - center_x; - int dy = v->y - center_y; - int dist = sqrt(dx*dx+dy*dy); /* double here. nasty */ - int p = iabs(dx); - if(dist < range) - { - /* panning */ - if(dx > 0) - lvol = ((range-p)*lvol)/range; - else - rvol = ((range-p)*rvol)/range; - - /* falloff */ - lvol = (lvol*(range-dist))/range; - rvol = (rvol*(range-dist))/range; - } - else - { - lvol = 0; - rvol = 0; - } - } - - /* process all frames */ - for(s = 0; s < end; s++) - { - *out++ += (*in_l)*lvol; - *out++ += (*in_r)*rvol; - in_l += step; - in_r += step; - v->tick++; - } - - /* free voice if not used any more */ - if(v->tick == v->snd->num_frames) - v->snd = 0; - - } - } - - - /* release the lock */ - lock_release(sound_lock); - - { - /* clamp accumulated values */ - /* TODO: this seams slow */ - for(i = 0; i < frames; i++) - { - int j = i<<1; - int vl = ((mix_buffer[j]*master_vol)/101)>>8; - int vr = ((mix_buffer[j+1]*master_vol)/101)>>8; - - final_out[j] = int2short(vl); - final_out[j+1] = int2short(vr); - } - } - -#if defined(CONF_ARCH_ENDIAN_BIG) - swap_endian(final_out, sizeof(short), frames * 2); -#endif -} - -static void sdlcallback(void *unused, Uint8 *stream, int len) -{ - mix((short *)stream, len/2/2); -} - -int snd_init() -{ - SDL_AudioSpec format, format2; - - sound_lock = lock_create(); - - if(!config.snd_enable) - return 0; - - mixing_rate = config.snd_rate; - - /* Set 16-bit stereo audio at 22Khz */ - format.freq = config.snd_rate; - format.format = AUDIO_S16; - format.channels = 2; - format.samples = config.snd_buffer_size; - format.callback = sdlcallback; - format.userdata = NULL; - - /* Open the audio device and start playing sound! */ - if(SDL_OpenAudio(&format, &format2) < 0) - { - dbg_msg("client/sound", "unable to open audio: %s", SDL_GetError()); - return -1; - } - else - dbg_msg("client/sound", "sound init successful"); - - mix_buffer = (int *)malloc(format2.samples * 2 * sizeof(int)); - - SDL_PauseAudio(0); - - sound_enabled = 1; - snd_update(); /* update the volume */ - return 0; -} - -int snd_update() -{ - /* update volume */ - int wanted_volume = config.snd_volume; - - if(!gfx_window_active() && config.snd_nonactive_mute) - wanted_volume = 0; - - if(wanted_volume != sound_volume) - { - lock_wait(sound_lock); - sound_volume = wanted_volume; - lock_release(sound_lock); - } - - return 0; -} - -int snd_shutdown() -{ - SDL_CloseAudio(); - lock_destroy(sound_lock); - if( mix_buffer ) - free(mix_buffer); - mix_buffer = NULL; - return 0; -} - -int snd_alloc_id() -{ - /* TODO: linear search, get rid of it */ - unsigned sid; - for(sid = 0; sid < NUM_SAMPLES; sid++) - { - if(samples[sid].data == 0x0) - return sid; - } - - return -1; -} - -static void rate_convert(int sid) -{ - SAMPLE *snd = &samples[sid]; - int num_frames = 0; - short *new_data = 0; - int i; - - /* make sure that we need to convert this sound */ - if(!snd->data || snd->rate == mixing_rate) - return; - - /* allocate new data */ - num_frames = (int)((snd->num_frames/(float)snd->rate)*mixing_rate); - new_data = (Sint16 *)mem_alloc(num_frames*snd->channels*sizeof(short), 1); - - for(i = 0; i < num_frames; i++) - { - /* resample TODO: this should be done better, like linear atleast */ - float a = i/(float)num_frames; - int f = (int)(a*snd->num_frames); - if(f >= snd->num_frames) - f = snd->num_frames-1; - - /* set new data */ - if(snd->channels == 1) - new_data[i] = snd->data[f]; - else if(snd->channels == 2) - { - new_data[i*2] = snd->data[f*2]; - new_data[i*2+1] = snd->data[f*2+1]; - } - } - - /* free old data and apply new */ - mem_free(snd->data); - snd->data = new_data; - snd->num_frames = num_frames; -} - - -static IOHANDLE file = NULL; - -static int read_data(void *buffer, int size) -{ - return io_read(file, buffer, size); -} - -int snd_load_wv(const char *filename) -{ - SAMPLE *snd; - int sid = -1; - char error[100]; - WavpackContext *context; - - /* don't waste memory on sound when we are stress testing */ - if(config.dbg_stress) - return -1; - - /* no need to load sound when we are running with no sound */ - if(!sound_enabled) - return 1; - - file = engine_openfile(filename, IOFLAG_READ); /* TODO: use system.h stuff for this */ - if(!file) - { - dbg_msg("sound/wv", "failed to open %s", filename); - return -1; - } - - sid = snd_alloc_id(); - if(sid < 0) - return -1; - snd = &samples[sid]; - - context = WavpackOpenFileInput(read_data, error); - if (context) - { - int samples = WavpackGetNumSamples(context); - int bitspersample = WavpackGetBitsPerSample(context); - unsigned int samplerate = WavpackGetSampleRate(context); - int channels = WavpackGetNumChannels(context); - int *data; - int *src; - short *dst; - int i; - - snd->channels = channels; - snd->rate = samplerate; - - if(snd->channels > 2) - { - dbg_msg("sound/wv", "file is not mono or stereo. filename='%s'", filename); - return -1; - } - - /* - if(snd->rate != 44100) - { - dbg_msg("sound/wv", "file is %d Hz, not 44100 Hz. filename='%s'", snd->rate, filename); - return -1; - }*/ - - if(bitspersample != 16) - { - dbg_msg("sound/wv", "bps is %d, not 16, filname='%s'", bitspersample, filename); - return -1; - } - - data = (int *)mem_alloc(4*samples*channels, 1); - WavpackUnpackSamples(context, data, samples); /* TODO: check return value */ - src = data; - - snd->data = (short *)mem_alloc(2*samples*channels, 1); - dst = snd->data; - - for (i = 0; i < samples*channels; i++) - *dst++ = (short)*src++; - - mem_free(data); - - snd->num_frames = samples; - snd->loop_start = -1; - snd->loop_end = -1; - } - else - { - dbg_msg("sound/wv", "failed to open %s: %s", filename, error); - } - - io_close(file); - file = NULL; - - if(config.debug) - dbg_msg("sound/wv", "loaded %s", filename); - - rate_convert(sid); - return sid; -} - -void snd_set_listener_pos(float x, float y) -{ - center_x = (int)x; - center_y = (int)y; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_srvbrowse.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_srvbrowse.cpp deleted file mode 100644 index 1744c0071..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/client/ec_srvbrowse.cpp +++ /dev/null @@ -1,737 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -extern NETCLIENT *net; - - -/* ------ server browse ---- */ -/* TODO: move all this to a separate file */ - -typedef struct SERVERENTRY_t SERVERENTRY; -struct SERVERENTRY_t -{ - NETADDR addr; - int64 request_time; - int got_info; - SERVER_INFO info; - - SERVERENTRY *next_ip; /* ip hashed list */ - - SERVERENTRY *prev_req; /* request list */ - SERVERENTRY *next_req; -}; - -static HEAP *serverlist_heap = 0; -static SERVERENTRY **serverlist = 0; -static int *sorted_serverlist = 0; - -enum -{ - MAX_FAVORITES=256 -}; - -static NETADDR favorite_servers[MAX_FAVORITES]; -static int num_favorite_servers = 0; - -static SERVERENTRY *serverlist_ip[256] = {0}; /* ip hash list */ - -static SERVERENTRY *first_req_server = 0; /* request list */ -static SERVERENTRY *last_req_server = 0; -static int num_requests = 0; - -static int need_refresh = 0; - -static int num_sorted_servers = 0; -static int num_sorted_servers_capacity = 0; -static int num_servers = 0; -static int num_server_capacity = 0; - -static int sorthash = 0; -static char filterstring[64] = {0}; -static char filtergametypestring[128] = {0}; - -/* the token is to keep server refresh separated from each other */ -static int current_token = 1; - -static int serverlist_type = 0; -static int64 broadcast_time = 0; - -int client_serverbrowse_lan() { return serverlist_type == BROWSETYPE_LAN; } -int client_serverbrowse_num() { return num_servers; } - -SERVER_INFO *client_serverbrowse_get(int index) -{ - if(index < 0 || index >= num_servers) - return 0; - return &serverlist[index]->info; -} - -int client_serverbrowse_sorted_num() { return num_sorted_servers; } - -SERVER_INFO *client_serverbrowse_sorted_get(int index) -{ - if(index < 0 || index >= num_sorted_servers) - return 0; - return &serverlist[sorted_serverlist[index]]->info; -} - - -int client_serverbrowse_num_requests() -{ - return num_requests; -} - -static int client_serverbrowse_sort_compare_name(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - return strcmp(a->info.name, b->info.name); -} - -static int client_serverbrowse_sort_compare_map(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - return strcmp(a->info.map, b->info.map); -} - -static int client_serverbrowse_sort_compare_ping(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - if(a->info.latency > b->info.latency) return 1; - if(a->info.latency < b->info.latency) return -1; - return 0; -} - -static int client_serverbrowse_sort_compare_gametype(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - return strcmp(a->info.gametype, b->info.gametype); -} - -static int client_serverbrowse_sort_compare_progression(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - if(a->info.progression > b->info.progression) return 1; - if(a->info.progression < b->info.progression) return -1; - return 0; -} - -static int client_serverbrowse_sort_compare_numplayers(const void *ai, const void *bi) -{ - SERVERENTRY *a = serverlist[*(const int*)ai]; - SERVERENTRY *b = serverlist[*(const int*)bi]; - if(a->info.num_players > b->info.num_players) return 1; - if(a->info.num_players < b->info.num_players) return -1; - return 0; -} - -static void client_serverbrowse_filter() -{ - int i = 0, p = 0; - num_sorted_servers = 0; - - /* allocate the sorted list */ - if(num_sorted_servers_capacity < num_servers) - { - if(sorted_serverlist) - mem_free(sorted_serverlist); - num_sorted_servers_capacity = num_servers; - sorted_serverlist = (int *)mem_alloc(num_sorted_servers_capacity*sizeof(int), 1); - } - - /* filter the servers */ - for(i = 0; i < num_servers; i++) - { - int filtered = 0; - - if(config.b_filter_empty && serverlist[i]->info.num_players == 0) - filtered = 1; - else if(config.b_filter_full && serverlist[i]->info.num_players == serverlist[i]->info.max_players) - filtered = 1; - else if(config.b_filter_pw && serverlist[i]->info.flags&SRVFLAG_PASSWORD) - filtered = 1; - else if(config.b_filter_pure && (strcmp(serverlist[i]->info.gametype, "DM") != 0 && strcmp(serverlist[i]->info.gametype, "TDM") != 0 && strcmp(serverlist[i]->info.gametype, "CTF") != 0)) - filtered = 1; - else if(config.b_filter_pure_map && - !(strcmp(serverlist[i]->info.map, "dm1") == 0 || - strcmp(serverlist[i]->info.map, "dm2") == 0 || - strcmp(serverlist[i]->info.map, "dm6") == 0 || - strcmp(serverlist[i]->info.map, "dm7") == 0 || - strcmp(serverlist[i]->info.map, "dm8") == 0 || - strcmp(serverlist[i]->info.map, "dm9") == 0 || - strcmp(serverlist[i]->info.map, "ctf1") == 0 || - strcmp(serverlist[i]->info.map, "ctf2") == 0 || - strcmp(serverlist[i]->info.map, "ctf3") == 0 || - strcmp(serverlist[i]->info.map, "ctf4") == 0 || - strcmp(serverlist[i]->info.map, "ctf5") == 0) - ) - { - filtered = 1; - } - else if(config.b_filter_ping < serverlist[i]->info.latency) - filtered = 1; - else if(config.b_filter_compatversion && strncmp(serverlist[i]->info.version, modc_net_version(), 3) != 0) - filtered = 1; - else - { - if(config.b_filter_string[0] != 0) - { - int matchfound = 0; - - serverlist[i]->info.quicksearch_hit = 0; - - /* match against server name */ - if(str_find_nocase(serverlist[i]->info.name, config.b_filter_string)) - { - matchfound = 1; - serverlist[i]->info.quicksearch_hit |= BROWSEQUICK_SERVERNAME; - } - - /* match against players */ - for(p = 0; p < serverlist[i]->info.num_players; p++) - { - if(str_find_nocase(serverlist[i]->info.players[p].name, config.b_filter_string)) - { - matchfound = 1; - serverlist[i]->info.quicksearch_hit |= BROWSEQUICK_PLAYERNAME; - break; - } - } - - /* match against map */ - if(str_find_nocase(serverlist[i]->info.map, config.b_filter_string)) - { - matchfound = 1; - serverlist[i]->info.quicksearch_hit |= BROWSEQUICK_MAPNAME; - } - - if(!matchfound) - filtered = 1; - } - - if(!filtered && config.b_filter_gametype[0] != 0) - { - /* match against game type */ - if(!str_find_nocase(serverlist[i]->info.gametype, config.b_filter_gametype)) - filtered = 1; - } - } - - if(filtered == 0) - sorted_serverlist[num_sorted_servers++] = i; - } -} - -static int client_serverbrowse_sorthash() -{ - int i = config.b_sort&0xf; - i |= config.b_filter_empty<<4; - i |= config.b_filter_full<<5; - i |= config.b_filter_pw<<6; - i |= config.b_sort_order<<7; - i |= config.b_filter_compatversion<<8; - i |= config.b_filter_pure<<9; - i |= config.b_filter_pure_map<<10; - i |= config.b_filter_ping<<16; - return i; -} - -static void client_serverbrowse_sort() -{ - int i; - - /* create filtered list */ - client_serverbrowse_filter(); - - /* sort */ - if(config.b_sort == BROWSESORT_NAME) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_name); - else if(config.b_sort == BROWSESORT_PING) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_ping); - else if(config.b_sort == BROWSESORT_MAP) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_map); - else if(config.b_sort == BROWSESORT_NUMPLAYERS) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_numplayers); - else if(config.b_sort == BROWSESORT_GAMETYPE) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_gametype); - else if(config.b_sort == BROWSESORT_PROGRESSION) - qsort(sorted_serverlist, num_sorted_servers, sizeof(int), client_serverbrowse_sort_compare_progression); - - /* invert the list if requested */ - if(config.b_sort_order) - { - for(i = 0; i < num_sorted_servers/2; i++) - { - int temp = sorted_serverlist[i]; - sorted_serverlist[i] = sorted_serverlist[num_sorted_servers-i-1]; - sorted_serverlist[num_sorted_servers-i-1] = temp; - } - } - - /* set indexes */ - for(i = 0; i < num_sorted_servers; i++) - serverlist[sorted_serverlist[i]]->info.sorted_index = i; - - str_copy(filtergametypestring, config.b_filter_gametype, sizeof(filtergametypestring)); - str_copy(filterstring, config.b_filter_string, sizeof(filterstring)); - sorthash = client_serverbrowse_sorthash(); -} - -static void client_serverbrowse_remove_request(SERVERENTRY *entry) -{ - if(entry->prev_req || entry->next_req || first_req_server == entry) - { - if(entry->prev_req) - entry->prev_req->next_req = entry->next_req; - else - first_req_server = entry->next_req; - - if(entry->next_req) - entry->next_req->prev_req = entry->prev_req; - else - last_req_server = entry->prev_req; - - entry->prev_req = 0; - entry->next_req = 0; - num_requests--; - } -} - -static SERVERENTRY *client_serverbrowse_find(NETADDR *addr) -{ - SERVERENTRY *entry = serverlist_ip[addr->ip[0]]; - - for(; entry; entry = entry->next_ip) - { - if(net_addr_comp(&entry->addr, addr) == 0) - return entry; - } - return (SERVERENTRY*)0; -} - -void client_serverbrowse_queuerequest(SERVERENTRY *entry) -{ - /* add it to the list of servers that we should request info from */ - entry->prev_req = last_req_server; - if(last_req_server) - last_req_server->next_req = entry; - else - first_req_server = entry; - last_req_server = entry; - - num_requests++; -} - -void client_serverbrowse_setinfo(SERVERENTRY *entry, SERVER_INFO *info) -{ - int fav = entry->info.favorite; - entry->info = *info; - entry->info.favorite = fav; - entry->info.netaddr = entry->addr; - - // all these are just for nice compability - if(entry->info.gametype[0] == '0' && entry->info.gametype[1] == 0) - str_copy(entry->info.gametype, "DM", sizeof(entry->info.gametype)); - else if(entry->info.gametype[0] == '1' && entry->info.gametype[1] == 0) - str_copy(entry->info.gametype, "TDM", sizeof(entry->info.gametype)); - else if(entry->info.gametype[0] == '2' && entry->info.gametype[1] == 0) - str_copy(entry->info.gametype, "CTF", sizeof(entry->info.gametype)); - - /*if(!request) - { - entry->info.latency = (time_get()-entry->request_time)*1000/time_freq(); - client_serverbrowse_remove_request(entry); - }*/ - - entry->got_info = 1; - client_serverbrowse_sort(); -} - -SERVERENTRY *client_serverbrowse_add(NETADDR *addr) -{ - int hash = addr->ip[0]; - SERVERENTRY *entry = 0; - int i; - - /* create new entry */ - entry = (SERVERENTRY *)memheap_allocate(serverlist_heap, sizeof(SERVERENTRY)); - mem_zero(entry, sizeof(SERVERENTRY)); - - /* set the info */ - entry->addr = *addr; - entry->info.netaddr = *addr; - - entry->info.latency = 999; - str_format(entry->info.address, sizeof(entry->info.address), "%d.%d.%d.%d:%d", - addr->ip[0], addr->ip[1], addr->ip[2], - addr->ip[3], addr->port); - str_format(entry->info.name, sizeof(entry->info.name), "\255%d.%d.%d.%d:%d", /* the \255 is to make sure that it's sorted last */ - addr->ip[0], addr->ip[1], addr->ip[2], - addr->ip[3], addr->port); - - /*if(serverlist_type == BROWSETYPE_LAN) - entry->info.latency = (time_get()-broadcast_time)*1000/time_freq();*/ - - /* check if it's a favorite */ - for(i = 0; i < num_favorite_servers; i++) - { - if(net_addr_comp(addr, &favorite_servers[i]) == 0) - entry->info.favorite = 1; - } - - /* add to the hash list */ - entry->next_ip = serverlist_ip[hash]; - serverlist_ip[hash] = entry; - - if(num_servers == num_server_capacity) - { - SERVERENTRY **newlist; - num_server_capacity += 100; - newlist = (SERVERENTRY**)mem_alloc(num_server_capacity*sizeof(SERVERENTRY*), 1); - mem_copy(newlist, serverlist, num_servers*sizeof(SERVERENTRY*)); - mem_free(serverlist); - serverlist = newlist; - } - - /* add to list */ - serverlist[num_servers] = entry; - entry->info.server_index = num_servers; - num_servers++; - - return entry; -} - -void client_serverbrowse_set(NETADDR *addr, int type, int token, SERVER_INFO *info) -{ - SERVERENTRY *entry = 0; - if(type == BROWSESET_MASTER_ADD) - { - if(serverlist_type != BROWSETYPE_INTERNET) - return; - - if(!client_serverbrowse_find(addr)) - { - entry = client_serverbrowse_add(addr); - client_serverbrowse_queuerequest(entry); - } - } - else if(type == BROWSESET_FAV_ADD) - { - if(serverlist_type != BROWSETYPE_FAVORITES) - return; - - if(!client_serverbrowse_find(addr)) - { - entry = client_serverbrowse_add(addr); - client_serverbrowse_queuerequest(entry); - } - } - else if(type == BROWSESET_TOKEN) - { - if(token != current_token) - return; - - entry = client_serverbrowse_find(addr); - if(!entry) - entry = client_serverbrowse_add(addr); - if(entry) - { - client_serverbrowse_setinfo(entry, info); - if(serverlist_type == BROWSETYPE_LAN) - entry->info.latency = (time_get()-broadcast_time)*1000/time_freq(); - else - entry->info.latency = (time_get()-entry->request_time)*1000/time_freq(); - client_serverbrowse_remove_request(entry); - } - } - else if(type == BROWSESET_OLD_INTERNET) - { - entry = client_serverbrowse_find(addr); - if(entry) - { - client_serverbrowse_setinfo(entry, info); - - if(serverlist_type == BROWSETYPE_LAN) - entry->info.latency = (time_get()-broadcast_time)*1000/time_freq(); - else - entry->info.latency = (time_get()-entry->request_time)*1000/time_freq(); - client_serverbrowse_remove_request(entry); - } - } - else if(type == BROWSESET_OLD_LAN) - { - entry = client_serverbrowse_find(addr); - if(entry) - if(!entry) - entry = client_serverbrowse_add(addr); - if(entry) - client_serverbrowse_setinfo(entry, info); - } - - client_serverbrowse_sort(); -} - -void client_serverbrowse_refresh(int type) -{ - /* clear out everything */ - if(serverlist_heap) - memheap_destroy(serverlist_heap); - serverlist_heap = memheap_create(); - num_servers = 0; - num_sorted_servers = 0; - mem_zero(serverlist_ip, sizeof(serverlist_ip)); - first_req_server = 0; - last_req_server = 0; - num_requests = 0; - - /* next token */ - current_token = (current_token+1)&0xff; - - /* */ - serverlist_type = type; - - if(type == BROWSETYPE_LAN) - { - unsigned char buffer[sizeof(SERVERBROWSE_GETINFO)+1]; - NETCHUNK packet; - int i; - - mem_copy(buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO)); - buffer[sizeof(SERVERBROWSE_GETINFO)] = current_token; - - packet.client_id = -1; - mem_zero(&packet, sizeof(packet)); - packet.address.ip[0] = 255; - packet.address.ip[1] = 255; - packet.address.ip[2] = 255; - packet.address.ip[3] = 255; - packet.flags = NETSENDFLAG_CONNLESS; - packet.data_size = sizeof(buffer); - packet.data = buffer; - broadcast_time = time_get(); - - for(i = 8303; i <= 8310; i++) - { - packet.address.port = i; - netclient_send(net, &packet); - } - - if(config.debug) - dbg_msg("client", "broadcasting for servers"); - } - else if(type == BROWSETYPE_INTERNET) - need_refresh = 1; - else if(type == BROWSETYPE_FAVORITES) - { - int i; - for(i = 0; i < num_favorite_servers; i++) - client_serverbrowse_set(&favorite_servers[i], BROWSESET_FAV_ADD, -1, 0); - } -} - -static void client_serverbrowse_request_impl(NETADDR *addr, SERVERENTRY *entry) -{ - /*unsigned char buffer[sizeof(SERVERBROWSE_GETINFO)+1];*/ - NETCHUNK p; - - if(config.debug) - { - dbg_msg("client", "requesting server info from %d.%d.%d.%d:%d", - addr->ip[0], addr->ip[1], addr->ip[2], - addr->ip[3], addr->port); - } - - /*mem_copy(buffer, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO)); - buffer[sizeof(SERVERBROWSE_GETINFO)] = current_token;*/ - - p.client_id = -1; - p.address = *addr; - p.flags = NETSENDFLAG_CONNLESS; - /*p.data_size = sizeof(buffer); - p.data = buffer; - netclient_send(net, &p);*/ - - /* send old requtest style aswell */ - p.data_size = sizeof(SERVERBROWSE_OLD_GETINFO); - p.data = SERVERBROWSE_OLD_GETINFO; - netclient_send(net, &p); - - if(entry) - entry->request_time = time_get(); -} - -void client_serverbrowse_request(NETADDR *addr) -{ - client_serverbrowse_request_impl(addr, 0); -} - - -void client_serverbrowse_update() -{ - int64 timeout = time_freq(); - int64 now = time_get(); - int count; - SERVERENTRY *entry, *next; - - /* do server list requests */ - if(need_refresh && !mastersrv_refreshing()) - { - NETADDR addr; - NETCHUNK p; - int i; - - need_refresh = 0; - - mem_zero(&p, sizeof(p)); - p.client_id = -1; - p.flags = NETSENDFLAG_CONNLESS; - p.data_size = sizeof(SERVERBROWSE_GETLIST); - p.data = SERVERBROWSE_GETLIST; - - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - addr = mastersrv_get(i); - if(!addr.ip[0] && !addr.ip[1] && !addr.ip[2] && !addr.ip[3]) - continue; - - p.address = addr; - netclient_send(net, &p); - } - - if(config.debug) - dbg_msg("client", "requesting server list"); - } - - /* do timeouts */ - entry = first_req_server; - while(1) - { - if(!entry) /* no more entries */ - break; - - next = entry->next_req; - - if(entry->request_time && entry->request_time+timeout < now) - { - /* timeout */ - client_serverbrowse_remove_request(entry); - num_requests--; - } - - entry = next; - } - - /* do timeouts */ - entry = first_req_server; - count = 0; - while(1) - { - if(!entry) /* no more entries */ - break; - - /* no more then 10 concurrent requests */ - if(count == config.b_max_requests) - break; - - if(entry->request_time == 0) - client_serverbrowse_request_impl(&entry->addr, entry); - - count++; - entry = entry->next_req; - } - - /* check if we need to resort */ - /* TODO: remove the strcmp */ - if(sorthash != client_serverbrowse_sorthash() || strcmp(filterstring, config.b_filter_string) != 0 || strcmp(filtergametypestring, config.b_filter_gametype) != 0) - client_serverbrowse_sort(); -} - - -int client_serverbrowse_isfavorite(NETADDR addr) -{ - /* search for the address */ - int i; - for(i = 0; i < num_favorite_servers; i++) - { - if(net_addr_comp(&addr, &favorite_servers[i]) == 0) - return 1; - } - return 0; -} - -void client_serverbrowse_addfavorite(NETADDR addr) -{ - int i; - SERVERENTRY *entry; - - if(num_favorite_servers == MAX_FAVORITES) - return; - - /* make sure that we don't already have the server in our list */ - for(i = 0; i < num_favorite_servers; i++) - { - if(net_addr_comp(&addr, &favorite_servers[i]) == 0) - return; - } - - /* add the server to the list */ - favorite_servers[num_favorite_servers++] = addr; - entry = client_serverbrowse_find(&addr); - if(entry) - entry->info.favorite = 1; - dbg_msg("", "added fav, %p", entry); -} - -void client_serverbrowse_removefavorite(NETADDR addr) -{ - int i; - SERVERENTRY *entry; - - for(i = 0; i < num_favorite_servers; i++) - { - if(net_addr_comp(&addr, &favorite_servers[i]) == 0) - { - mem_move(&favorite_servers[i], &favorite_servers[i+1], num_favorite_servers-(i+1)); - num_favorite_servers--; - - entry = client_serverbrowse_find(&addr); - if(entry) - entry->info.favorite = 0; - - return; - } - } -} - -void client_serverbrowse_save() -{ - int i; - char addrstr[128]; - char buffer[256]; - for(i = 0; i < num_favorite_servers; i++) - { - net_addr_str(&favorite_servers[i], addrstr, sizeof(addrstr)); - str_format(buffer, sizeof(buffer), "add_favorite %s", addrstr); - engine_config_write_line(buffer); - } -} - - -int client_serverbrowse_refreshingmasters() -{ - return mastersrv_refreshing(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/docs/client_time.txt b/project/jni/application/teeworlds-0.5.2/src/engine/docs/client_time.txt deleted file mode 100644 index bc76f91cd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/docs/client_time.txt +++ /dev/null @@ -1,11 +0,0 @@ -Title: Time on the client - -tick, intratick -predtick, predintratick - - prevtick tick predtick - 4 8 14 - |---------------------|---------------------| - 0 <- intratick -> 1 - 0 <- ticktime(in s)-> X - 0 <- predintratick?-> 1 diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/docs/prediction.txt b/project/jni/application/teeworlds-0.5.2/src/engine/docs/prediction.txt deleted file mode 100644 index d5771d1aa..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/docs/prediction.txt +++ /dev/null @@ -1,19 +0,0 @@ -Title: Prediction - -The engine calls when reprediction is required. This happens usally when new data has arrived from the server. should to prediction from the current snapshot and current snapshot tick ( + 1) upto and including the tick returned by . - -Predicted input sent to the server can be retrived by calling with the corresponding tick that you want the input for. Here is a simple example of how it might look. - -> void modc_predict() -> { -> int tick; -> prediction_reset(); -> -> for(tick = client_tick()+1; tick <= client_predtick(); tick++) -> { -> MY_INPUT *input = (MY_INPUT *)client_get_input(); -> if(input) -> prediction_apply_input(input); -> prediction_tick(); -> } -> } diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/docs/server_op.txt b/project/jni/application/teeworlds-0.5.2/src/engine/docs/server_op.txt deleted file mode 100644 index 59181e624..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/docs/server_op.txt +++ /dev/null @@ -1,39 +0,0 @@ -Title: Server Operation - -Section: Init - -Section: Running - -Here is an graph over how the server operates on each refresh. - -(start code) -load map -init mod - -while running - if map change then - load new map - shutdown mod - reset clients to init state - init mod - end if - - if new tick then - call - for each client do - create snapshot - send snapshot - end for - end - - process new network messages -end while - -unload map -(end) - - - -Section: Reinit - -Section: Shutdown diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/docs/snapshots.txt b/project/jni/application/teeworlds-0.5.2/src/engine/docs/snapshots.txt deleted file mode 100644 index 647b049ae..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/docs/snapshots.txt +++ /dev/null @@ -1,58 +0,0 @@ -Title: Snapshots - -Section: Overview - -Topic: Definitions - -- *Snapshot*. A is a serialized game state from which a client can render the game from. They are sent from the server at a regular interval and is created specificly for each client in order to reduce bandwidth. -- *Delta Snapshot*. A set of data that can be applied to a snapshot in order to create a new snapshot with the updated game state. - -Topic: Structure - -A snapshot contains a series of items. Each item have a type, id and data. - -- *Type*. Type of item. Could be projectile or character for example. -- *Id*. A unique id so the client can identify the item between two snapshots. -- *Data*. A series of 32-bit integers that contains the per item type specific data. - -Section: Server Side - -Topic: Creating - -Items can be added when is called using the function to insert an item to the snapshot. The server can not inspect the snapshot that is in progress of being created. - -Section: Client Side - -Topic: Inspection - is called when a new snapshot has arrived for processing. , and can be used to inspect the current and previous snapshot. This can be done anywhere while the client is running and not just in the function. The client can also call if an item contains improper information that could harm the operation of the client. This should however be done in to assure that no bad data propagates into the rest of the client. - -Topic: Rendering -DOCTODO - -Section: In depth - -Topic: Compression - -After a snapshot have been created, compression is applyed to reduce the bandwidth. There are several steps taken inorder to reduce the size of the size of the snapshot. - -- *Delta*. The server looks in a clients backlog of snapshots to find a previous acked snapshot. It then compares the two snapshots and creates a delta snapshot containing the changes from the previous acked snapshot to the new one. -- *Variable Integers*. The delta snapshot which is only consisting of 32-bit integers is then encoded into variable integers similar to UTF-8. Each byte has a bit that tells the decoder that it needs one more byte to decode the 32-bit integer. The first byte also contains a bit for telling the sign of the integer. - -> ESDDDDDD EDDDDDDD EDDDDDDD EDDDDDDD - -> E = extend -> S = sign -> D = data bit - -- *Huffman*. The last step is to compress the buffer with a huffman encoder. It uses a static tree that is weighted towards 0 because it's where most of the data will be because of the delta compression. - -Topic: Interval - -The interval for how often a client recives a snapshot changes during the course of the connection. There are three different snapshot rates. - -- *Init*. 5 snapshots per second. Used when a client is connecting and used until the client has acknowlaged a snapshot. This mechanism is used because the first snapshot because no delta compression can be done. - -- *Full*. Snapshot for every tick or every even tick depending on server configuration. This is used during normal gameplay and everything is running smooth. - -- *Recovery*. 1 snapshot each second. A client enters recovery rate when it havn't acknowlaged a snapshot over 1 second. This is to let the client to beable to recover if it has a slow connection. - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_client_interface.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_client_interface.h deleted file mode 100644 index 2cc9e5c79..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_client_interface.h +++ /dev/null @@ -1,25 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_CLIENT_INTERFACE_H -#define ENGINE_CLIENT_INTERFACE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "e_if_other.h" -#include "e_if_client.h" -#include "e_if_snd.h" -#include "e_if_gfx.h" -#include "e_if_inp.h" -#include "e_if_msg.h" -#include "e_if_modc.h" - -#include "e_console.h" -#include "e_config.h" -#include "client/ec_font.h" - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_common_interface.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_common_interface.h deleted file mode 100644 index 498bb6b48..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_common_interface.h +++ /dev/null @@ -1,16 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_COMMON_INTERFACE_H -#define ENGINE_COMMON_INTERFACE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "e_if_other.h" -#include "e_if_msg.h" - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.cpp deleted file mode 100644 index 0df91eb00..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_compression.h" - - -/* Format: ESDDDDDD EDDDDDDD EDD... Extended, Data, Sign */ -unsigned char *vint_pack(unsigned char *dst, int i) -{ - *dst = (i>>25)&0x40; /* set sign bit if i<0 */ - i = i^(i>>31); /* if(i<0) i = ~i */ - - *dst |= i&0x3F; /* pack 6bit into dst */ - i >>= 6; /* discard 6 bits */ - if(i) - { - *dst |= 0x80; /* set extend bit */ - while(1) - { - dst++; - *dst = i&(0x7F); /* pack 7bit */ - i >>= 7; /* discard 7 bits */ - *dst |= (i!=0)<<7; /* set extend bit (may branch) */ - if(!i) - break; - } - } - - dst++; - return dst; -} - -const unsigned char *vint_unpack(const unsigned char *src, int *i) -{ - int sign = (*src>>6)&1; - *i = *src&0x3F; - - do - { - if(!(*src&0x80)) break; - src++; - *i |= (*src&(0x7F))<<(6); - - if(!(*src&0x80)) break; - src++; - *i |= (*src&(0x7F))<<(6+7); - - if(!(*src&0x80)) break; - src++; - *i |= (*src&(0x7F))<<(6+7+7); - - if(!(*src&0x80)) break; - src++; - *i |= (*src&(0x7F))<<(6+7+7+7); - } while(0); - - src++; - *i ^= -sign; /* if(sign) *i = ~(*i) */ - return src; -} - - -long intpack_decompress(const void *src_, int size, void *dst_) -{ - const unsigned char *src = (unsigned char *)src_; - const unsigned char *end = src + size; - int *dst = (int *)dst_; - while(src < end) - { - src = vint_unpack(src, dst); - dst++; - } - return (long)((unsigned char *)dst-(unsigned char *)dst_); -} - -long intpack_compress(const void *src_, int size, void *dst_) -{ - int *src = (int *)src_; - unsigned char *dst = (unsigned char *)dst_; - size /= 4; - while(size) - { - dst = vint_pack(dst, *src); - size--; - src++; - } - return (long)(dst-(unsigned char *)dst_); -} - - -/* */ -long zerobit_compress(const void *src_, int size, void *dst_) -{ - unsigned char *src = (unsigned char *)src_; - unsigned char *dst = (unsigned char *)dst_; - - while(size) - { - unsigned char bit = 0x80; - unsigned char mask = 0; - int dst_move = 1; - int chunk = size < 8 ? size : 8; - int b; - size -= chunk; - - for(b = 0; b < chunk; b++, bit>>=1) - { - if(*src) - { - dst[dst_move] = *src; - mask |= bit; - dst_move++; - } - - src++; - } - - *dst = mask; - dst += dst_move; - } - - return (long)(dst-(unsigned char *)dst_); -} - -long zerobit_decompress(const void *src_, int size, void *dst_) -{ - unsigned char *src = (unsigned char *)src_; - unsigned char *dst = (unsigned char *)dst_; - unsigned char *end = src + size; - - while(src < end) - { - unsigned char bit = 0x80; - unsigned char mask = *src++; - int b; - - for(b = 0; b < 8; b++, bit>>=1) - { - if(mask&bit) - *dst++ = *src++; - else - *dst++ = 0; - } - - if(src > end) - return -1; - } - - return (long)(dst-(unsigned char *)dst_); -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.h deleted file mode 100644 index d5c212fbe..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_compression.h +++ /dev/null @@ -1,19 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* variable int packing */ -unsigned char *vint_pack(unsigned char *dst, int i); -const unsigned char *vint_unpack(const unsigned char *src, int *inout); -long intpack_compress(const void *src, int size, void *dst); -long intpack_decompress(const void *src, int size, void *dst); - -/* zerobit packing */ -long zerobit_compress(const void *src, int size, void *dst); -long zerobit_decompress(const void *src, int size, void *dst); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_config.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_config.cpp deleted file mode 100644 index 67a4c81a8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_config.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include -#include -#include - -#include -#include "e_if_other.h" -#include "e_config.h" -#include "e_linereader.h" -#include "e_engine.h" - -CONFIGURATION config; - -void config_reset() -{ - #define MACRO_CONFIG_INT(name,def,min,max,flags,desc) config.name = def; - #define MACRO_CONFIG_STR(name,len,def,flags,desc) str_copy(config.name, def, len); - - #include "e_config_variables.h" - - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_STR -} - -void config_save() -{ - char linebuf[1024*2]; - - #define MACRO_CONFIG_INT(name,def,min,max,flags,desc) if((flags)&CFGFLAG_SAVE){ str_format(linebuf, sizeof(linebuf), "%s %i", #name, config.name); engine_config_write_line(linebuf); } - #define MACRO_CONFIG_STR(name,len,def,flags,desc) if((flags)&CFGFLAG_SAVE){ str_format(linebuf, sizeof(linebuf), "%s %s", #name, config.name); engine_config_write_line(linebuf); } - - #include "e_config_variables.h" - - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_STR -} - -#define MACRO_CONFIG_INT(name,def,min,max,flags,desc) int config_get_ ## name (CONFIGURATION *c) { return c->name; } -#define MACRO_CONFIG_STR(name,len,def,flags,desc) const char *config_get_ ## name (CONFIGURATION *c) { return c->name; } -#include "e_config_variables.h" -#undef MACRO_CONFIG_INT -#undef MACRO_CONFIG_STR - -#define MACRO_CONFIG_INT(name,def,min,max,flags,desc) void config_set_ ## name (CONFIGURATION *c, int val) { if(min != max) { if (val < min) val = min; if (max != 0 && val > max) val = max; } c->name = val; } -#define MACRO_CONFIG_STR(name,len,def,flags,desc) void config_set_ ## name (CONFIGURATION *c, const char *str) { str_copy(c->name, str, len-1); c->name[sizeof(c->name)-1] = 0; } -#include "e_config_variables.h" -#undef MACRO_CONFIG_INT -#undef MACRO_CONFIG_STR diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_config.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_config.h deleted file mode 100644 index 965e08f05..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_config.h +++ /dev/null @@ -1,52 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef _CONFIG_H -#define _CONFIG_H - -#ifdef __cplusplus -extern "C"{ -#endif - -typedef struct -{ - #define MACRO_CONFIG_INT(name,def,min,max,save,desc) int name; - #define MACRO_CONFIG_STR(name,len,def,save,desc) char name[len]; /* Flawfinder: ignore */ - #include "e_config_variables.h" - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_STR -} CONFIGURATION; - -extern CONFIGURATION config; - -void config_init(); -void config_reset(); -void config_save(); - -enum -{ - CFGFLAG_SAVE=1, - CFGFLAG_CLIENT=2, - CFGFLAG_SERVER=4 -}; - -typedef int (*CONFIG_INT_GETTER)(CONFIGURATION *c); -typedef const char *(*CONFIG_STR_GETTER)(CONFIGURATION *c); -typedef void (*CONFIG_INT_SETTER)(CONFIGURATION *c, int val); -typedef void (*CONFIG_STR_SETTER)(CONFIGURATION *c, const char *str); - -#define MACRO_CONFIG_INT(name,def,min,max,flags,desc) int config_get_ ## name (CONFIGURATION *c); -#define MACRO_CONFIG_STR(name,len,def,flags,desc) const char *config_get_ ## name (CONFIGURATION *c); -#include "e_config_variables.h" -#undef MACRO_CONFIG_INT -#undef MACRO_CONFIG_STR - -#define MACRO_CONFIG_INT(name,def,min,max,flags,desc) void config_set_ ## name (CONFIGURATION *c, int val); -#define MACRO_CONFIG_STR(name,len,def,flags,desc) void config_set_ ## name (CONFIGURATION *c, const char *str); -#include "e_config_variables.h" -#undef MACRO_CONFIG_INT -#undef MACRO_CONFIG_STR - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_config_variables.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_config_variables.h deleted file mode 100644 index 21b71b2fc..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_config_variables.h +++ /dev/null @@ -1,87 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -/* TODO: remove this */ -#include "../game/variables.hpp" - - -MACRO_CONFIG_STR(player_name, 32, "nameless tee", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Name of the player") -MACRO_CONFIG_STR(clan_name, 32, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "(not used)") -MACRO_CONFIG_STR(password, 32, "", CFGFLAG_CLIENT, "Password to the server") -MACRO_CONFIG_STR(logfile, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filename to log all output to") - -MACRO_CONFIG_INT(cl_cpu_throttle, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(cl_editor, 0, 0, 1, CFGFLAG_CLIENT, "") - -MACRO_CONFIG_INT(cl_eventthread, 0, 0, 1, CFGFLAG_CLIENT, "Enables the usage of a thread to pump the events") - -MACRO_CONFIG_INT(inp_grab, 0, 0, 1, CFGFLAG_CLIENT, "Use forceful input grabbing method") - -MACRO_CONFIG_STR(b_filter_string, 64, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server browser filtering string") - -MACRO_CONFIG_INT(b_filter_full, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out full server in browser") -MACRO_CONFIG_INT(b_filter_empty, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out empty server in browser") -MACRO_CONFIG_INT(b_filter_pw, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out password protected servers in browser") -MACRO_CONFIG_INT(b_filter_ping, 999, 0, 999, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Ping to filter by in the server browser") -MACRO_CONFIG_STR(b_filter_gametype, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Game types to filter") -MACRO_CONFIG_INT(b_filter_pure, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard servers in browser") -MACRO_CONFIG_INT(b_filter_pure_map, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard maps in browser") -MACRO_CONFIG_INT(b_filter_compatversion, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser") - -MACRO_CONFIG_INT(b_sort, 1, 0, 256, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") // Sort by ping -MACRO_CONFIG_INT(b_sort_order, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(b_max_requests, 10, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Number of requests to use when refreshing server browser") - -MACRO_CONFIG_INT(snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size") -#ifdef ANDROID -MACRO_CONFIG_INT(snd_rate, 22050, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate") -#else -MACRO_CONFIG_INT(snd_rate, 48000, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate") -#endif -MACRO_CONFIG_INT(snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound enable") -MACRO_CONFIG_INT(snd_volume, 100, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound volume") -MACRO_CONFIG_INT(snd_device, -1, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "(deprecated) Sound device to use") - -MACRO_CONFIG_INT(snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") - -MACRO_CONFIG_INT(gfx_screen_width, 800, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width") -MACRO_CONFIG_INT(gfx_screen_height, 600, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height") -MACRO_CONFIG_INT(gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen") -MACRO_CONFIG_INT(gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)") -MACRO_CONFIG_INT(gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)") -MACRO_CONFIG_INT(gfx_clear, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Clear screen before rendering") -MACRO_CONFIG_INT(gfx_vsync, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Vertical sync") -MACRO_CONFIG_INT(gfx_display_all_modes, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(gfx_texture_compression, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use texture compression") -#ifdef ANDROID -MACRO_CONFIG_INT(gfx_high_detail, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "High detail") -MACRO_CONFIG_INT(gfx_texture_quality, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples") -#else -MACRO_CONFIG_INT(gfx_high_detail, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "High detail") -MACRO_CONFIG_INT(gfx_texture_quality, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples") -#endif -MACRO_CONFIG_INT(gfx_refresh_rate, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate") -MACRO_CONFIG_INT(gfx_finish, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") - -MACRO_CONFIG_INT(inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity") - -MACRO_CONFIG_STR(sv_name, 128, "unnamed server", CFGFLAG_SERVER, "Server name") -MACRO_CONFIG_STR(sv_bindaddr, 128, "", CFGFLAG_SERVER, "Address to bind the server to") -MACRO_CONFIG_INT(sv_port, 8303, 0, 0, CFGFLAG_SERVER, "Port to use for the server") -MACRO_CONFIG_INT(sv_external_port, 0, 0, 0, CFGFLAG_SERVER, "External port to report to the master servers") -MACRO_CONFIG_STR(sv_map, 128, "dm1", CFGFLAG_SERVER, "Map to use on the server") -MACRO_CONFIG_INT(sv_max_clients, 8, 1, MAX_CLIENTS, CFGFLAG_SERVER, "Maximum number of clients that are allowed on a server") -MACRO_CONFIG_INT(sv_high_bandwidth, 0, 0, 1, CFGFLAG_SERVER, "Use high bandwidth mode. Doubles the bandwidth required for the server. LAN use only") -MACRO_CONFIG_INT(sv_register, 1, 0, 1, CFGFLAG_SERVER, "Register server with master server for public listing") -MACRO_CONFIG_STR(sv_rcon_password, 32, "", CFGFLAG_SERVER, "Remote console password") -MACRO_CONFIG_INT(sv_map_reload, 0, 0, 1, CFGFLAG_SERVER, "Reload the current map") - -MACRO_CONFIG_INT(debug, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Debug mode") -MACRO_CONFIG_INT(dbg_stress, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress systems") -MACRO_CONFIG_INT(dbg_stress_network, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress network") -MACRO_CONFIG_INT(dbg_pref, 0, 0, 1, CFGFLAG_SERVER, "Performance outputs") -MACRO_CONFIG_INT(dbg_graphs, 0, 0, 1, CFGFLAG_CLIENT, "Performance graphs") -MACRO_CONFIG_INT(dbg_hitch, 0, 0, 0, CFGFLAG_SERVER, "Hitch warnings") -MACRO_CONFIG_STR(dbg_stress_server, 32, "localhost", CFGFLAG_CLIENT, "Server to stress") -MACRO_CONFIG_INT(dbg_resizable, 0, 0, 0, CFGFLAG_CLIENT, "Enables window resizing") diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_console.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_console.cpp deleted file mode 100644 index 700619a2f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_console.cpp +++ /dev/null @@ -1,443 +0,0 @@ -#include -#include "e_if_other.h" -#include "e_console.h" -#include "e_config.h" -#include "e_engine.h" -#include "e_linereader.h" -#include -#include -#include - - -#define CONSOLE_MAX_STR_LENGTH 1024 -/* the maximum number of tokens occurs in a string of length CONSOLE_MAX_STR_LENGTH with tokens size 1 separated by single spaces */ -#define MAX_PARTS (CONSOLE_MAX_STR_LENGTH+1)/2 - -typedef struct -{ - char string_storage[CONSOLE_MAX_STR_LENGTH+1]; - char *args_start; - - const char *command; - const char *args[MAX_PARTS]; - unsigned int num_args; -} PARSE_RESULT; - -static char *str_skipblanks(char *str) -{ - while(*str && (*str == ' ' || *str == '\t' || *str == '\n')) - str++; - return str; -} - -static char *str_skiptoblank(char *str) -{ - while(*str && (*str != ' ' && *str != '\t' && *str != '\n')) - str++; - return str; -} - -/* static int digit(char c) { return '0' <= c && c <= '9'; } */ - -static int console_parse_start(PARSE_RESULT *result, const char *string, int length) -{ - char *str; - int len = sizeof(result->string_storage); - if(length < len) - len = length; - - str_copy(result->string_storage, string, length); - str = result->string_storage; - - /* get command */ - str = str_skipblanks(str); - result->command = str; - str = str_skiptoblank(str); - - if(*str) - { - str[0] = 0; - str++; - } - - result->args_start = str; - result->num_args = 0; - return 0; -} - -static int console_parse_args(PARSE_RESULT *result, const char *format) -{ - char command; - char *str; - int optional = 0; - int error = 0; - - str = result->args_start; - - while(1) - { - /* fetch command */ - command = *format; - format++; - - if(!command) - break; - - if(command == '?') - optional = 1; - else - { - str = str_skipblanks(str); - - if(!(*str)) /* error, non optional command needs value */ - { - if(!optional) - error = 1; - break; - } - - /* add token */ - if(*str == '"') - { - char *dst; - str++; - result->args[result->num_args++] = str; - - dst = str; /* we might have to process escape data */ - while(1) - { - if(str[0] == '"') - break; - else if(str[0] == '\\') - { - if(str[1] == '\\') - str++; /* skip due to escape */ - else if(str[1] == '"') - str++; /* skip due to escape */ - } - else if(str[0] == 0) - return 1; /* return error */ - - *dst = *str; - dst++; - str++; - } - - /* write null termination */ - *dst = 0; - } - else - { - result->args[result->num_args++] = str; - - if(command == 'r') /* rest of the string */ - break; - else if(command == 'i') /* validate int */ - str = str_skiptoblank(str); - else if(command == 'f') /* validate float */ - str = str_skiptoblank(str); - else if(command == 's') /* validate string */ - str = str_skiptoblank(str); - - if(str[0] != 0) /* check for end of string */ - { - str[0] = 0; - str++; - } - } - } - } - - return error; -} - -const char *console_arg_string(void *res, int index) -{ - PARSE_RESULT *result = (PARSE_RESULT *)res; - if (index < 0 || index >= result->num_args) - return ""; - return result->args[index]; -} - -int console_arg_int(void *res, int index) -{ - PARSE_RESULT *result = (PARSE_RESULT *)res; - if (index < 0 || index >= result->num_args) - return 0; - return atoi(result->args[index]); -} - -float console_arg_float(void *res, int index) -{ - PARSE_RESULT *result = (PARSE_RESULT *)res; - if (index < 0 || index >= result->num_args) - return 0.0f; - return atof(result->args[index]); -} - -int console_arg_num(void *result) -{ - return ((PARSE_RESULT *)result)->num_args; -} - -static COMMAND *first_command = 0x0; - -COMMAND *console_find_command(const char *name) -{ - COMMAND *cmd; - for (cmd = first_command; cmd; cmd = cmd->next) - { - if (strcmp(cmd->name, name) == 0) - return cmd; - } - - return 0x0; -} - -void console_register(COMMAND *cmd) -{ - cmd->next = first_command; - first_command = cmd; -} - -static void (*print_callback)(const char *, void *) = 0x0; -static void *print_callback_userdata; - -void console_register_print_callback(void (*callback)(const char *, void *), void *user_data) -{ - print_callback = callback; - print_callback_userdata = user_data; -} - -void console_print(const char *str) -{ - if (print_callback) - print_callback(str, print_callback_userdata); -} - -void console_execute_line_stroked(int stroke, const char *str) -{ - PARSE_RESULT result; - COMMAND *command; - - char strokestr[2] = {'0', 0}; - if(stroke) - strokestr[0] = '1'; - - while(str) - { - const char *end = str; - const char *next_part = 0; - int in_string = 0; - - while(*end) - { - if(*end == '"') - in_string ^= 1; - else if(*end == '\\') /* escape sequences */ - { - if(end[1] == '"') - end++; - } - else if(!in_string) - { - if(*end == ';') /* command separator */ - { - next_part = end+1; - break; - } - else if(*end == '#') /* comment, no need to do anything more */ - break; - } - - end++; - } - - if(console_parse_start(&result, str, (end-str) + 1) != 0) - return; - - command = console_find_command(result.command); - - if(command) - { - int is_stroke_command = 0; - if(result.command[0] == '+') - { - /* insert the stroke direction token */ - result.args[result.num_args] = strokestr; - result.num_args++; - is_stroke_command = 1; - } - - if(stroke || is_stroke_command) - { - if(console_parse_args(&result, command->params)) - { - char buf[256]; - str_format(buf, sizeof(buf), "Invalid arguments... Usage: %s %s", command->name, command->params); - console_print(buf); - } - else - command->callback(&result, command->user_data); - } - } - else - { - char buf[256]; - str_format(buf, sizeof(buf), "No such command: %s.", result.command); - console_print(buf); - } - - str = next_part; - } -} - -void console_possible_commands(const char *str, int flagmask, void (*callback)(const char *cmd, void *user), void *user) -{ - COMMAND *cmd; - for (cmd = first_command; cmd; cmd = cmd->next) - { - if(cmd->flags&flagmask) - { - if(str_find_nocase(cmd->name, str)) - callback(cmd->name, user); - } - } -} - - -COMMAND *console_get_command(const char *str) -{ - COMMAND *cmd; - for (cmd = first_command; cmd; cmd = cmd->next) - { - if(str_comp_nocase(cmd->name, str) == 0) - return cmd; - } - - return 0x0; -} - -void console_execute_line(const char *str) -{ - console_execute_line_stroked(1, str); -} - -static void console_execute_file_real(const char *filename) -{ - IOHANDLE file; - file = engine_openfile(filename, IOFLAG_READ); - - if(file) - { - char *line; - LINEREADER lr; - - dbg_msg("console", "executing '%s'", filename); - linereader_init(&lr, file); - - while((line = linereader_get(&lr))) - console_execute_line(line); - - io_close(file); - } - else - dbg_msg("console", "failed to open '%s'", filename); -} - -struct EXECFILE -{ - const char *filename; - struct EXECFILE *next; -}; - -void console_execute_file(const char *filename) -{ - static struct EXECFILE *first = 0; - struct EXECFILE thisfile; - struct EXECFILE *cur; - struct EXECFILE *prev; - - /* make sure that this isn't being executed already */ - for(cur = first; cur; cur = cur->next) - if(strcmp(filename, cur->filename) == 0) - return; - - /* push this one to the stack */ - prev = first; - thisfile.filename = filename; - thisfile.next = first; - first = &thisfile; - - /* execute file */ - console_execute_file_real(filename); - - /* pop this one from the stack */ - first = prev; -} - -static void con_echo(void *result, void *user_data) -{ - console_print(console_arg_string(result, 0)); -} - -static void con_exec(void *result, void *user_data) -{ - console_execute_file(console_arg_string(result, 0)); - -} - - -typedef struct -{ - CONFIG_INT_GETTER getter; - CONFIG_INT_SETTER setter; -} INT_VARIABLE_DATA; - -typedef struct -{ - CONFIG_STR_GETTER getter; - CONFIG_STR_SETTER setter; -} STR_VARIABLE_DATA; - -static void int_variable_command(void *result, void *user_data) -{ - INT_VARIABLE_DATA *data = (INT_VARIABLE_DATA *)user_data; - - if(console_arg_num(result)) - data->setter(&config, console_arg_int(result, 0)); - else - { - char buf[1024]; - str_format(buf, sizeof(buf), "Value: %d", data->getter(&config)); - console_print(buf); - } -} - -static void str_variable_command(void *result, void *user_data) -{ - STR_VARIABLE_DATA *data = (STR_VARIABLE_DATA *)user_data; - - if(console_arg_num(result)) - data->setter(&config, console_arg_string(result, 0)); - else - { - char buf[1024]; - str_format(buf, sizeof(buf), "Value: %s", data->getter(&config)); - console_print(buf); - } -} - -void console_init() -{ - MACRO_REGISTER_COMMAND("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_echo, 0x0, "Echo the text"); - MACRO_REGISTER_COMMAND("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_exec, 0x0, "Execute the specified file"); - - #define MACRO_CONFIG_INT(name,def,min,max,flags,desc) { static INT_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?i", flags, int_variable_command, &data, desc) } - #define MACRO_CONFIG_STR(name,len,def,flags,desc) { static STR_VARIABLE_DATA data = { &config_get_ ## name, &config_set_ ## name }; MACRO_REGISTER_COMMAND(#name, "?r", flags, str_variable_command, &data, desc) } - - #include "e_config_variables.h" - - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_STR -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_console.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_console.h deleted file mode 100644 index c2393e399..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_console.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _CONSOLE_H -#define _CONSOLE_H - -#ifdef __cplusplus -extern "C"{ -#endif - -typedef void (*CONSOLE_CALLBACK)(void *result, void *user_data); - -typedef struct COMMAND_t -{ - const char *name; - const char *params; - int flags; - CONSOLE_CALLBACK callback; - void *user_data; - const char *help; - struct COMMAND_t *next; -} COMMAND; - -void console_init(); -void console_register(COMMAND *cmd); -void console_execute_line(const char *str); -void console_execute_line_stroked(int stroke, const char *str); -void console_execute_file(const char *filename); -void console_possible_commands(const char *str, int flagmask, void (*callback)(const char *cmd, void *user), void *user); -COMMAND *console_get_command(const char *cmd); -void console_print(const char *str); -void console_register_print_callback(void (*callback)(const char *, void *user_data), void *user_data); - -/*int console_result_string(void *result, int index, const char **str); -int console_result_int(void *result, int index, int *i); -int console_result_float(void *result, int index, float *f);*/ - -const char *console_arg_string(void *result, int index); -int console_arg_int(void *result, int index); -float console_arg_float(void *result, int index); -int console_arg_num(void *result); - -#define MACRO_REGISTER_COMMAND(name, params, flags, func, ptr, help) { static COMMAND cmd = { name, params, flags, func, ptr, help, 0x0}; console_register(&cmd); } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.cpp deleted file mode 100644 index 0317f9d00..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.cpp +++ /dev/null @@ -1,677 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_datafile.h" -#include "e_engine.h" -#include - -static const int DEBUG=0; - -typedef struct -{ - int type; - int start; - int num; -} DATAFILE_ITEM_TYPE; - -typedef struct -{ - int type_and_id; - int size; -} DATAFILE_ITEM; - -typedef struct -{ - char id[4]; - int version; - int size; - int swaplen; - int num_item_types; - int num_items; - int num_raw_data; - int item_size; - int data_size; -} DATAFILE_HEADER; - -typedef struct -{ - int num_item_types; - int num_items; - int num_raw_data; - int item_size; - int data_size; - char start[4]; -} DATAFILE_DATA; - -typedef struct -{ - DATAFILE_ITEM_TYPE *item_types; - int *item_offsets; - int *data_offsets; - int *data_sizes; - - char *item_start; - char *data_start; -} DATAFILE_INFO; - -struct DATAFILE_t -{ - IOHANDLE file; - DATAFILE_INFO info; - DATAFILE_HEADER header; - int data_start_offset; - char **data_ptrs; - char *data; -}; - -DATAFILE *datafile_load(const char *filename) -{ - DATAFILE *df; - IOHANDLE file; - DATAFILE_HEADER header; - unsigned readsize; - - unsigned *dst; - unsigned char *src; - unsigned j; - int size = 0; - int allocsize = 0; - - (void)dst; - (void)src; - (void)j; - - - dbg_msg("datafile", "datafile loading. filename='%s'", filename); - - file = engine_openfile(filename, IOFLAG_READ); - if(!file) - return 0; - - /* TODO: change this header */ - io_read(file, &header, sizeof(header)); - if(header.id[0] != 'A' || header.id[1] != 'T' || header.id[2] != 'A' || header.id[3] != 'D') - { - if(header.id[0] != 'D' || header.id[1] != 'A' || header.id[2] != 'T' || header.id[3] != 'A') - { - dbg_msg("datafile", "wrong signature. %x %x %x %x", header.id[0], header.id[1], header.id[2], header.id[3]); - return 0; - } - } - -#if defined(CONF_ARCH_ENDIAN_BIG) - swap_endian(&header, sizeof(int), sizeof(header)/sizeof(int)); -#endif - if(header.version != 3 && header.version != 4) - { - dbg_msg("datafile", "wrong version. version=%x", header.version); - return 0; - } - - /* read in the rest except the data */ - size = 0; - size += header.num_item_types*sizeof(DATAFILE_ITEM_TYPE); - size += (header.num_items+header.num_raw_data)*sizeof(int); - if(header.version == 4) - size += header.num_raw_data*sizeof(int); /* v4 has uncompressed data sizes aswell */ - size += header.item_size; - - allocsize = size; - allocsize += sizeof(DATAFILE); /* add space for info structure */ - allocsize += header.num_raw_data*sizeof(void*); /* add space for data pointers */ - - df = (DATAFILE*)mem_alloc(allocsize, 1); - df->header = header; - df->data_start_offset = sizeof(DATAFILE_HEADER) + size; - df->data_ptrs = (char**)(df+1); - df->data = (char *)(df+1)+header.num_raw_data*sizeof(char *); - df->file = file; - - /* clear the data pointers */ - mem_zero(df->data_ptrs, header.num_raw_data*sizeof(void*)); - - /* read types, offsets, sizes and item data */ - readsize = io_read(file, df->data, size); - if(readsize != size) - { - dbg_msg("datafile", "couldn't load the whole thing, wanted=%d got=%d", size, readsize); - return 0; - } - -#if defined(CONF_ARCH_ENDIAN_BIG) - swap_endian(df->data, sizeof(int), header.swaplen / sizeof(int)); -#endif - - if(DEBUG) - { - dbg_msg("datafile", "allocsize=%d", allocsize); - dbg_msg("datafile", "readsize=%d", readsize); - dbg_msg("datafile", "swaplen=%d", header.swaplen); - dbg_msg("datafile", "item_size=%d", df->header.item_size); - } - - df->info.item_types = (DATAFILE_ITEM_TYPE *)df->data; - df->info.item_offsets = (int *)&df->info.item_types[df->header.num_item_types]; - df->info.data_offsets = (int *)&df->info.item_offsets[df->header.num_items]; - df->info.data_sizes = (int *)&df->info.data_offsets[df->header.num_raw_data]; - - if(header.version == 4) - df->info.item_start = (char *)&df->info.data_sizes[df->header.num_raw_data]; - else - df->info.item_start = (char *)&df->info.data_offsets[df->header.num_raw_data]; - df->info.data_start = df->info.item_start + df->header.item_size; - - if(DEBUG) - dbg_msg("datafile", "datafile loading done. datafile='%s'", filename); - - if(DEBUG) - { - /* - for(int i = 0; i < df->data.num_raw_data; i++) - { - void *p = datafile_get_data(df, i); - dbg_msg("datafile", "%d %d", (int)((char*)p - (char*)(&df->data)), size); - } - - for(int i = 0; i < datafile_num_items(df); i++) - { - int type, id; - void *data = datafile_get_item(df, i, &type, &id); - dbg_msg("map", "\t%d: type=%x id=%x p=%p offset=%d", i, type, id, data, df->info.item_offsets[i]); - int *idata = (int*)data; - for(int k = 0; k < 3; k++) - dbg_msg("datafile", "\t\t%d=%d (%x)", k, idata[k], idata[k]); - } - - for(int i = 0; i < df->data.num_item_types; i++) - { - dbg_msg("map", "\t%d: type=%x start=%d num=%d", i, - df->info.item_types[i].type, - df->info.item_types[i].start, - df->info.item_types[i].num); - for(int k = 0; k < df->info.item_types[i].num; k++) - { - int type, id; - datafile_get_item(df, df->info.item_types[i].start+k, &type, &id); - if(type != df->info.item_types[i].type) - dbg_msg("map", "\tERROR"); - } - } - */ - } - - return df; -} - -int datafile_num_data(DATAFILE *df) -{ - return df->header.num_raw_data; -} - -/* always returns the size in the file */ -int datafile_get_datasize(DATAFILE *df, int index) -{ - if(index == df->header.num_raw_data-1) - return df->header.data_size-df->info.data_offsets[index]; - return df->info.data_offsets[index+1]-df->info.data_offsets[index]; -} - -static void *datafile_get_data_impl(DATAFILE *df, int index, int swap) -{ - /* load it if needed */ - if(!df->data_ptrs[index]) - { - /* fetch the data size */ - int datasize = datafile_get_datasize(df, index); - int swapsize = datasize; - - if(df->header.version == 4) - { - /* v4 has compressed data */ - void *temp = (char *)mem_alloc(datasize, 1); - unsigned long uncompressed_size = df->info.data_sizes[index]; - unsigned long s; - - dbg_msg("datafile", "loading data index=%d size=%d uncompressed=%d", index, datasize, uncompressed_size); - df->data_ptrs[index] = (char *)mem_alloc(uncompressed_size, 1); - - /* read the compressed data */ - io_seek(df->file, df->data_start_offset+df->info.data_offsets[index], IOSEEK_START); - io_read(df->file, temp, datasize); - - /* decompress the data, TODO: check for errors */ - s = uncompressed_size; - uncompress((Bytef*)df->data_ptrs[index], &s, (Bytef*)temp, datasize); - swapsize = s; - - /* clean up the temporary buffers */ - mem_free(temp); - } - else - { - /* load the data */ - dbg_msg("datafile", "loading data index=%d size=%d", index, datasize); - df->data_ptrs[index] = (char *)mem_alloc(datasize, 1); - io_seek(df->file, df->data_start_offset+df->info.data_offsets[index], IOSEEK_START); - io_read(df->file, df->data_ptrs[index], datasize); - } - -#if defined(CONF_ARCH_ENDIAN_BIG) - if(swap && swapsize) - swap_endian(df->data_ptrs[index], sizeof(int), swapsize/sizeof(int)); -#endif - } - - return df->data_ptrs[index]; -} - -void *datafile_get_data(DATAFILE *df, int index) -{ - return datafile_get_data_impl(df, index, 0); -} - -void *datafile_get_data_swapped(DATAFILE *df, int index) -{ - return datafile_get_data_impl(df, index, 1); -} - -void datafile_unload_data(DATAFILE *df, int index) -{ - if(index < 0) - return; - - /* */ - mem_free(df->data_ptrs[index]); - df->data_ptrs[index] = 0x0; -} - -int datafile_get_itemsize(DATAFILE *df, int index) -{ - if(index == df->header.num_items-1) - return df->header.item_size-df->info.item_offsets[index]; - return df->info.item_offsets[index+1]-df->info.item_offsets[index]; -} - -void *datafile_get_item(DATAFILE *df, int index, int *type, int *id) -{ - DATAFILE_ITEM *i = (DATAFILE_ITEM *)(df->info.item_start+df->info.item_offsets[index]); - if(type) - *type = (i->type_and_id>>16)&0xffff; /* remove sign extention */ - if(id) - *id = i->type_and_id&0xffff; - return (void *)(i+1); -} - -void datafile_get_type(DATAFILE *df, int type, int *start, int *num) -{ - int i; - for(i = 0; i < df->header.num_item_types; i++) - { - if(df->info.item_types[i].type == type) - { - *start = df->info.item_types[i].start; - *num = df->info.item_types[i].num; - return; - } - } - - *start = 0; - *num = 0; -} - -void *datafile_find_item(DATAFILE *df, int type, int id) -{ - int start, num,i ; - int item_id; - void *item; - - datafile_get_type(df, type, &start, &num); - for(i = 0; i < num; i++) - { - item = datafile_get_item(df, start+i,0, &item_id); - if(id == item_id) - return item; - } - return 0; -} - -int datafile_num_items(DATAFILE *df) -{ - return df->header.num_items; -} - -void datafile_unload(DATAFILE *df) -{ - if(df) - { - /* free the data that is loaded */ - int i; - for(i = 0; i < df->header.num_raw_data; i++) - mem_free(df->data_ptrs[i]); - - io_close(df->file); - mem_free(df); - } -} - -/* DATAFILE output */ -typedef struct -{ - int uncompressed_size; - int compressed_size; - void *compressed_data; -} DATA_INFO; - -typedef struct -{ - int type; - int id; - int size; - int next; - int prev; - void *data; -} ITEM_INFO; - -typedef struct -{ - int num; - int first; - int last; -} ITEMTYPE_INFO; - -/* */ -struct DATAFILE_OUT_t -{ - IOHANDLE file; - int num_items; - int num_datas; - int num_item_types; - ITEMTYPE_INFO item_types[0xffff]; - ITEM_INFO items[1024]; - DATA_INFO datas[1024]; -}; - -DATAFILE_OUT *datafile_create(const char *filename) -{ - int i; - DATAFILE_OUT *df = (DATAFILE_OUT*)mem_alloc(sizeof(DATAFILE_OUT), 1); - df->file = engine_openfile(filename, IOFLAG_WRITE); - if(!df->file) - { - mem_free(df); - return 0; - } - - df->num_items = 0; - df->num_datas = 0; - df->num_item_types = 0; - mem_zero(&df->item_types, sizeof(df->item_types)); - - for(i = 0; i < 0xffff; i++) - { - df->item_types[i].first = -1; - df->item_types[i].last = -1; - } - - return df; -} - -int datafile_add_item(DATAFILE_OUT *df, int type, int id, int size, void *data) -{ - df->items[df->num_items].type = type; - df->items[df->num_items].id = id; - df->items[df->num_items].size = size; - - /* - dbg_msg("datafile", "added item type=%d id=%d size=%d", type, id, size); - int i; - for(i = 0; i < size/4; i++) - dbg_msg("datafile", "\t%d: %08x %d", i, ((int*)data)[i], ((int*)data)[i]); - */ - - /* copy data */ - df->items[df->num_items].data = mem_alloc(size, 1); - mem_copy(df->items[df->num_items].data, data, size); - - if(!df->item_types[type].num) /* count item types */ - df->num_item_types++; - - /* link */ - df->items[df->num_items].prev = df->item_types[type].last; - df->items[df->num_items].next = -1; - - if(df->item_types[type].last != -1) - df->items[df->item_types[type].last].next = df->num_items; - df->item_types[type].last = df->num_items; - - if(df->item_types[type].first == -1) - df->item_types[type].first = df->num_items; - - df->item_types[type].num++; - - df->num_items++; - return df->num_items-1; -} - -int datafile_add_data(DATAFILE_OUT *df, int size, void *data) -{ - DATA_INFO *info = &df->datas[df->num_datas]; - unsigned long s = compressBound(size); - void *compdata = mem_alloc(s, 1); /* temporary buffer that we use duing compression */ - - int result = compress((Bytef*)compdata, &s, (Bytef*)data, size); - if(result != Z_OK) - { - dbg_msg("datafile", "compression error %d", result); - dbg_assert(0, "zlib error"); - } - - info->uncompressed_size = size; - info->compressed_size = (int)s; - info->compressed_data = mem_alloc(info->compressed_size, 1); - mem_copy(info->compressed_data, compdata, info->compressed_size); - mem_free(compdata); - - df->num_datas++; - return df->num_datas-1; -} - -int datafile_add_data_swapped(DATAFILE_OUT *df, int size, void *data) -{ -#if defined(CONF_ARCH_ENDIAN_BIG) - void *swapped = mem_alloc(size, 1); /* temporary buffer that we use duing compression */ - int index; - mem_copy(swapped, data, size); - swap_endian(&swapped, sizeof(int), size/sizeof(int)); - index = datafile_add_data(df, size, swapped); - mem_free(swapped); - return index; -#else - return datafile_add_data(df, size, data); -#endif -} - - -int datafile_finish(DATAFILE_OUT *df) -{ - int itemsize = 0; - int i, count, offset; - int typessize, headersize, offsetsize, filesize, swapsize; - int datasize = 0; - DATAFILE_ITEM_TYPE info; - DATAFILE_ITEM itm; - DATAFILE_HEADER header; - - /* we should now write this file! */ - if(DEBUG) - dbg_msg("datafile", "writing"); - - /* calculate sizes */ - for(i = 0; i < df->num_items; i++) - { - if(DEBUG) - dbg_msg("datafile", "item=%d size=%d (%d)", i, df->items[i].size, df->items[i].size+sizeof(DATAFILE_ITEM)); - itemsize += df->items[i].size + sizeof(DATAFILE_ITEM); - } - - - for(i = 0; i < df->num_datas; i++) - datasize += df->datas[i].compressed_size; - - /* calculate the complete size */ - typessize = df->num_item_types*sizeof(DATAFILE_ITEM_TYPE); - headersize = sizeof(DATAFILE_HEADER); - offsetsize = df->num_items*sizeof(int) + df->num_datas*sizeof(int); - filesize = headersize + typessize + offsetsize + itemsize + datasize; - swapsize = filesize - datasize; - - (void)swapsize; - - if(DEBUG) - dbg_msg("datafile", "num_item_types=%d typessize=%d itemsize=%d datasize=%d", df->num_item_types, typessize, itemsize, datasize); - - /* construct header */ - { - header.id[0] = 'D'; - header.id[1] = 'A'; - header.id[2] = 'T'; - header.id[3] = 'A'; - header.version = 4; - header.size = filesize - 16; - header.swaplen = swapsize - 16; - header.num_item_types = df->num_item_types; - header.num_items = df->num_items; - header.num_raw_data = df->num_datas; - header.item_size = itemsize; - header.data_size = datasize; - - /* TODO: apply swapping */ - /* write header */ - if(DEBUG) - dbg_msg("datafile", "headersize=%d", sizeof(header)); - io_write(df->file, &header, sizeof(header)); - } - - /* write types */ - for(i = 0, count = 0; i < 0xffff; i++) - { - if(df->item_types[i].num) - { - /* write info */ - info.type = i; - info.start = count; - info.num = df->item_types[i].num; - if(DEBUG) - dbg_msg("datafile", "writing type=%x start=%d num=%d", info.type, info.start, info.num); - io_write(df->file, &info, sizeof(info)); - count += df->item_types[i].num; - } - } - - /* write item offsets */ - for(i = 0, offset = 0; i < 0xffff; i++) - { - if(df->item_types[i].num) - { - /* write all items in of this type */ - int k = df->item_types[i].first; - while(k != -1) - { - if(DEBUG) - dbg_msg("datafile", "writing item offset num=%d offset=%d", k, offset); - io_write(df->file, &offset, sizeof(offset)); - offset += df->items[k].size + sizeof(DATAFILE_ITEM); - - /* next */ - k = df->items[k].next; - } - } - } - - /* write data offsets */ - for(i = 0, offset = 0; i < df->num_datas; i++) - { - if(DEBUG) - dbg_msg("datafile", "writing data offset num=%d offset=%d", i, offset); - io_write(df->file, &offset, sizeof(offset)); - offset += df->datas[i].compressed_size; - } - - /* write data uncompressed sizes */ - for(i = 0, offset = 0; i < df->num_datas; i++) - { - /* - if(DEBUG) - dbg_msg("datafile", "writing data offset num=%d offset=%d", i, offset); - */ - io_write(df->file, &df->datas[i].uncompressed_size, sizeof(int)); - } - - /* write items */ - for(i = 0; i < 0xffff; i++) - { - if(df->item_types[i].num) - { - /* write all items in of this type */ - int k = df->item_types[i].first; - while(k != -1) - { - itm.type_and_id = (i<<16)|df->items[k].id; - itm.size = df->items[k].size; - if(DEBUG) - dbg_msg("datafile", "writing item type=%x idx=%d id=%d size=%d", i, k, df->items[k].id, df->items[k].size); - - io_write(df->file, &itm, sizeof(itm)); - io_write(df->file, df->items[k].data, df->items[k].size); - - /* next */ - k = df->items[k].next; - } - } - } - - /* write data */ - for(i = 0; i < df->num_datas; i++) - { - if(DEBUG) - dbg_msg("datafile", "writing data id=%d size=%d", i, df->datas[i].compressed_size); - io_write(df->file, df->datas[i].compressed_data, df->datas[i].compressed_size); - } - - /* free data */ - for(i = 0; i < df->num_items; i++) - mem_free(df->items[i].data); - - - io_close(df->file); - mem_free(df); - - if(DEBUG) - dbg_msg("datafile", "done"); - return 0; -} - -#define BUFFER_SIZE 64*1024 - -int datafile_crc(const char *filename) -{ - unsigned char buffer[BUFFER_SIZE]; - IOHANDLE file; - int crc = 0; - unsigned bytes = 0; - - file = engine_openfile(filename, IOFLAG_READ); - if(!file) - return 0; - - while(1) - { - bytes = io_read(file, buffer, BUFFER_SIZE); - if(bytes <= 0) - break; - crc = crc32(crc, buffer, bytes); - } - - io_close(file); - - return crc; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.h deleted file mode 100644 index 4e56ff871..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_datafile.h +++ /dev/null @@ -1,43 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifndef __DATAFILE__H__ -#define __DATAFILE__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* raw datafile access */ -typedef struct DATAFILE_t DATAFILE; - -/* read access */ -DATAFILE *datafile_load(const char *filename); -DATAFILE *datafile_load_old(const char *filename); -void *datafile_get_data(DATAFILE *df, int index); -void *datafile_get_data_swapped(DATAFILE *df, int index); /* makes sure that the data is 32bit LE ints when saved */ -int datafile_get_datasize(DATAFILE *df, int index); -void datafile_unload_data(DATAFILE *df, int index); -void *datafile_get_item(DATAFILE *df, int index, int *type, int *id); -int datafile_get_itemsize(DATAFILE *df, int index); -void datafile_get_type(DATAFILE *df, int type, int *start, int *num); -void *datafile_find_item(DATAFILE *df, int type, int id); -int datafile_num_items(DATAFILE *df); -int datafile_num_data(DATAFILE *df); -void datafile_unload(DATAFILE *df); - -int datafile_crc(const char *filename); - -/* write access */ -typedef struct DATAFILE_OUT_t DATAFILE_OUT; -DATAFILE_OUT *datafile_create(const char *filename); -int datafile_add_data(DATAFILE_OUT *df, int size, void *data); -int datafile_add_data_swapped(DATAFILE_OUT *df, int size, void *data); -int datafile_add_item(DATAFILE_OUT *df, int type, int id, int size, void *data); -int datafile_finish(DATAFILE_OUT *df); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.cpp deleted file mode 100644 index 8bb586105..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.cpp +++ /dev/null @@ -1,640 +0,0 @@ - -#include -#include "e_demorec.h" -#include "e_memheap.h" -#include "e_snapshot.h" -#include "e_compression.h" -#include "e_network.h" -#include "e_engine.h" -#include "e_if_other.h" -#include "e_demorec.h" - -static IOHANDLE record_file = 0; -static const unsigned char header_marker[8] = {'T', 'W', 'D', 'E', 'M', 'O', 0, 1}; - -/* Record */ -static int record_lasttickmarker = -1; -static int record_lastkeyframe; -static unsigned char record_lastsnapshotdata[MAX_SNAPSHOT_SIZE]; - -int demorec_isrecording() { return record_file != 0; } - -int demorec_record_start(const char *filename, const char *netversion, const char *map, int crc, const char *type) -{ - DEMOREC_HEADER header; - if(record_file) - return -1; - - record_file = engine_openfile(filename, IOFLAG_WRITE); - - if(!record_file) - { - dbg_msg("demorec/record", "Unable to open '%s' for recording", filename); - return -1; - } - - /* write header */ - mem_zero(&header, sizeof(header)); - mem_copy(header.marker, header_marker, sizeof(header.marker)); - str_copy(header.netversion, netversion, sizeof(header.netversion)); - str_copy(header.map, map, sizeof(header.map)); - str_copy(header.type, type, sizeof(header.type)); - header.crc[0] = (crc>>24)&0xff; - header.crc[1] = (crc>>16)&0xff; - header.crc[2] = (crc>>8)&0xff; - header.crc[3] = (crc)&0xff; - io_write(record_file, &header, sizeof(header)); - - record_lastkeyframe = -1; - record_lasttickmarker = -1; - - dbg_msg("demorec/record", "Recording to '%s'", filename); - return 0; -} - -/* - Tickmarker - 7 = Always set - 6 = Keyframe flag - 0-5 = Delta tick - - Normal - 7 = Not set - 5-6 = Type - 0-4 = Size -*/ - -enum -{ - CHUNKTYPEFLAG_TICKMARKER = 0x80, - CHUNKTICKFLAG_KEYFRAME = 0x40, /* only when tickmarker is set*/ - - CHUNKMASK_TICK = 0x3f, - CHUNKMASK_TYPE = 0x60, - CHUNKMASK_SIZE = 0x1f, - - CHUNKTYPE_SNAPSHOT = 1, - CHUNKTYPE_MESSAGE = 2, - CHUNKTYPE_DELTA = 3, - - CHUNKFLAG_BIGSIZE = 0x10 -}; - -static void demorec_record_write_tickmarker(int tick, int keyframe) -{ - if(record_lasttickmarker == -1 || tick-record_lasttickmarker > 63 || keyframe) - { - unsigned char chunk[5]; - chunk[0] = CHUNKTYPEFLAG_TICKMARKER; - chunk[1] = (tick>>24)&0xff; - chunk[2] = (tick>>16)&0xff; - chunk[3] = (tick>>8)&0xff; - chunk[4] = (tick)&0xff; - - if(keyframe) - chunk[0] |= CHUNKTICKFLAG_KEYFRAME; - - io_write(record_file, chunk, sizeof(chunk)); - } - else - { - unsigned char chunk[1]; - chunk[0] = CHUNKTYPEFLAG_TICKMARKER | (tick-record_lasttickmarker); - io_write(record_file, chunk, sizeof(chunk)); - } - - record_lasttickmarker = tick; -} - -static void demorec_record_write(int type, const void *data, int size) -{ - char buffer[64*1024]; - char buffer2[64*1024]; - unsigned char chunk[3]; - - if(!record_file) - return; - - - /* pad the data with 0 so we get an alignment of 4, - else the compression won't work and miss some bytes */ - mem_copy(buffer2, data, size); - while(size&3) - buffer2[size++] = 0; - size = intpack_compress(buffer2, size, buffer); /* buffer2 -> buffer */ - size = netcommon_compress(buffer, size, buffer2, sizeof(buffer2)); /* buffer -> buffer2 */ - - - chunk[0] = ((type&0x3)<<5); - if(size < 30) - { - chunk[0] |= size; - io_write(record_file, chunk, 1); - } - else - { - if(size < 256) - { - chunk[0] |= 30; - chunk[1] = size&0xff; - io_write(record_file, chunk, 2); - } - else - { - chunk[0] |= 31; - chunk[1] = size&0xff; - chunk[2] = size>>8; - io_write(record_file, chunk, 3); - } - } - - io_write(record_file, buffer2, size); -} - -void demorec_record_snapshot(int tick, const void *data, int size) -{ - if(record_lastkeyframe == -1 || (tick-record_lastkeyframe) > SERVER_TICK_SPEED*5) - { - /* write full tickmarker */ - demorec_record_write_tickmarker(tick, 1); - - /* write snapshot */ - demorec_record_write(CHUNKTYPE_SNAPSHOT, data, size); - - record_lastkeyframe = tick; - mem_copy(record_lastsnapshotdata, data, size); - } - else - { - /* create delta, prepend tick */ - char delta_data[MAX_SNAPSHOT_SIZE+sizeof(int)]; - int delta_size; - - /* write tickmarker */ - demorec_record_write_tickmarker(tick, 0); - - delta_size = snapshot_create_delta((SNAPSHOT*)record_lastsnapshotdata, (SNAPSHOT*)data, &delta_data); - if(delta_size) - { - /* record delta */ - demorec_record_write(CHUNKTYPE_DELTA, delta_data, delta_size); - mem_copy(record_lastsnapshotdata, data, size); - } - } -} - -void demorec_record_message(const void *data, int size) -{ - demorec_record_write(CHUNKTYPE_MESSAGE, data, size); -} - -int demorec_record_stop() -{ - if(!record_file) - return -1; - - dbg_msg("demorec/record", "Stopped recording"); - io_close(record_file); - record_file = 0; - return 0; -} - -/* Playback */ -typedef struct KEYFRAME -{ - long filepos; - int tick; -} KEYFRAME; - -typedef struct KEYFRAME_SEARCH -{ - KEYFRAME frame; - struct KEYFRAME_SEARCH *next; -} KEYFRAME_SEARCH; - -static IOHANDLE play_file = 0; -static DEMOREC_PLAYCALLBACK play_callback_snapshot = 0; -static DEMOREC_PLAYCALLBACK play_callback_message = 0; -static KEYFRAME *keyframes = 0; - -static DEMOREC_PLAYBACKINFO playbackinfo; -static unsigned char playback_lastsnapshotdata[MAX_SNAPSHOT_SIZE]; -static int playback_lastsnapshotdata_size = -1; - - -const DEMOREC_PLAYBACKINFO *demorec_playback_info() { return &playbackinfo; } -int demorec_isplaying() { return play_file != 0; } - -int demorec_playback_registercallbacks(DEMOREC_PLAYCALLBACK snapshot_cb, DEMOREC_PLAYCALLBACK message_cb) -{ - play_callback_snapshot = snapshot_cb; - play_callback_message = message_cb; - return 0; -} - -static int read_chunk_header(int *type, int *size, int *tick) -{ - unsigned char chunk = 0; - - *size = 0; - *type = 0; - - if(io_read(play_file, &chunk, sizeof(chunk)) != sizeof(chunk)) - return -1; - - if(chunk&CHUNKTYPEFLAG_TICKMARKER) - { - /* decode tick marker */ - int tickdelta = chunk&(CHUNKMASK_TICK); - *type = chunk&(CHUNKTYPEFLAG_TICKMARKER|CHUNKTICKFLAG_KEYFRAME); - - if(tickdelta == 0) - { - unsigned char tickdata[4]; - if(io_read(play_file, tickdata, sizeof(tickdata)) != sizeof(tickdata)) - return -1; - *tick = (tickdata[0]<<24) | (tickdata[1]<<16) | (tickdata[2]<<8) | tickdata[3]; - } - else - { - *tick += tickdelta; - } - - } - else - { - /* decode normal chunk */ - *type = (chunk&CHUNKMASK_TYPE)>>5; - *size = chunk&CHUNKMASK_SIZE; - - if(*size == 30) - { - unsigned char sizedata[1]; - if(io_read(play_file, sizedata, sizeof(sizedata)) != sizeof(sizedata)) - return -1; - *size = sizedata[0]; - - } - else if(*size == 31) - { - unsigned char sizedata[2]; - if(io_read(play_file, sizedata, sizeof(sizedata)) != sizeof(sizedata)) - return -1; - *size = (sizedata[1]<<8) | sizedata[0]; - } - } - - return 0; -} - -static void scan_file() -{ - long start_pos; - HEAP *heap = 0; - KEYFRAME_SEARCH *first_key = 0; - KEYFRAME_SEARCH *current_key = 0; - /*DEMOREC_CHUNK chunk;*/ - int chunk_size, chunk_type, chunk_tick = 0; - int i; - - heap = memheap_create(); - - start_pos = io_tell(play_file); - playbackinfo.seekable_points = 0; - - while(1) - { - long current_pos = io_tell(play_file); - - if(read_chunk_header(&chunk_type, &chunk_size, &chunk_tick)) - break; - - /* read the chunk */ - if(chunk_type&CHUNKTYPEFLAG_TICKMARKER) - { - if(chunk_type&CHUNKTICKFLAG_KEYFRAME) - { - KEYFRAME_SEARCH *key; - - /* save the position */ - key = (KEYFRAME_SEARCH*)memheap_allocate(heap, sizeof(KEYFRAME_SEARCH)); - key->frame.filepos = current_pos; - key->frame.tick = chunk_tick; - key->next = 0; - if(current_key) - current_key->next = key; - if(!first_key) - first_key = key; - current_key = key; - playbackinfo.seekable_points++; - } - - if(playbackinfo.first_tick == -1) - playbackinfo.first_tick = chunk_tick; - playbackinfo.last_tick = chunk_tick; - } - else if(chunk_size) - io_skip(play_file, chunk_size); - - } - - /* copy all the frames to an array instead for fast access */ - keyframes = (KEYFRAME*)mem_alloc(playbackinfo.seekable_points*sizeof(KEYFRAME), 1); - for(current_key = first_key, i = 0; current_key; current_key = current_key->next, i++) - keyframes[i] = current_key->frame; - - /* destroy the temporary heap and seek back to the start */ - memheap_destroy(heap); - io_seek(play_file, start_pos, IOSEEK_START); -} - -static void do_tick() -{ - static char compresseddata[MAX_SNAPSHOT_SIZE]; - static char decompressed[MAX_SNAPSHOT_SIZE]; - static char data[MAX_SNAPSHOT_SIZE]; - int chunk_size, chunk_type, chunk_tick; - int data_size; - int got_snapshot = 0; - - /* update ticks */ - playbackinfo.previous_tick = playbackinfo.current_tick; - playbackinfo.current_tick = playbackinfo.next_tick; - chunk_tick = playbackinfo.current_tick; - - while(1) - { - if(read_chunk_header(&chunk_type, &chunk_size, &chunk_tick)) - { - /* stop on error or eof */ - dbg_msg("demorec", "end of file"); - demorec_playback_pause(); - break; - } - - /* read the chunk */ - if(chunk_size) - { - if(io_read(play_file, compresseddata, chunk_size) != chunk_size) - { - /* stop on error or eof */ - dbg_msg("demorec", "error reading chunk"); - demorec_playback_stop(); - break; - } - - data_size = netcommon_decompress(compresseddata, chunk_size, decompressed, sizeof(decompressed)); - if(data_size < 0) - { - /* stop on error or eof */ - dbg_msg("demorec", "error during network decompression"); - demorec_playback_stop(); - break; - } - - data_size = intpack_decompress(decompressed, data_size, data); - - if(data_size < 0) - { - dbg_msg("demorec", "error during intpack decompression"); - demorec_playback_stop(); - break; - } - } - - if(chunk_type == CHUNKTYPE_DELTA) - { - /* process delta snapshot */ - static char newsnap[MAX_SNAPSHOT_SIZE]; - - got_snapshot = 1; - - data_size = snapshot_unpack_delta((SNAPSHOT*)playback_lastsnapshotdata, (SNAPSHOT*)newsnap, data, data_size); - - if(data_size >= 0) - { - if(play_callback_snapshot) - play_callback_snapshot(newsnap, data_size); - - playback_lastsnapshotdata_size = data_size; - mem_copy(playback_lastsnapshotdata, newsnap, data_size); - } - else - dbg_msg("demorec", "error duing unpacking of delta, err=%d", data_size); - } - else if(chunk_type == CHUNKTYPE_SNAPSHOT) - { - /* process full snapshot */ - got_snapshot = 1; - - playback_lastsnapshotdata_size = data_size; - mem_copy(playback_lastsnapshotdata, data, data_size); - if(play_callback_snapshot) - play_callback_snapshot(data, data_size); - } - else - { - /* if there were no snapshots in this tick, replay the last one */ - if(!got_snapshot && play_callback_snapshot && playback_lastsnapshotdata_size != -1) - { - got_snapshot = 1; - play_callback_snapshot(playback_lastsnapshotdata, playback_lastsnapshotdata_size); - } - - /* check the remaining types */ - if(chunk_type&CHUNKTYPEFLAG_TICKMARKER) - { - playbackinfo.next_tick = chunk_tick; - break; - } - else if(chunk_type == CHUNKTYPE_MESSAGE) - { - if(play_callback_message) - play_callback_message(data, data_size); - } - } - } -} - -void demorec_playback_pause() -{ - playbackinfo.paused = 1; -} - -void demorec_playback_unpause() -{ - if(playbackinfo.paused) - { - /*playbackinfo.start_tick = playbackinfo.current_tick; - playbackinfo.start_time = time_get();*/ - playbackinfo.paused = 0; - } -} - -int demorec_playback_load(const char *filename) -{ - play_file = engine_openfile(filename, IOFLAG_READ); - if(!play_file) - { - dbg_msg("demorec/playback", "could not open '%s'", filename); - return -1; - } - - /* clear the playback info */ - mem_zero(&playbackinfo, sizeof(playbackinfo)); - playbackinfo.first_tick = -1; - playbackinfo.last_tick = -1; - /*playbackinfo.start_tick = -1;*/ - playbackinfo.next_tick = -1; - playbackinfo.current_tick = -1; - playbackinfo.previous_tick = -1; - playbackinfo.speed = 1; - - playback_lastsnapshotdata_size = -1; - - /* read the header */ - io_read(play_file, &playbackinfo.header, sizeof(playbackinfo.header)); - if(mem_comp(playbackinfo.header.marker, header_marker, sizeof(header_marker)) != 0) - { - dbg_msg("demorec/playback", "'%s' is not a demo file", filename); - io_close(play_file); - play_file = 0; - return -1; - } - - /* scan the file for interessting points */ - scan_file(); - - /* ready for playback */ - return 0; -} - -int demorec_playback_nextframe() -{ - do_tick(); - return demorec_isplaying(); -} - -int demorec_playback_play() -{ - /* fill in previous and next tick */ - while(playbackinfo.previous_tick == -1 && demorec_isplaying()) - do_tick(); - - /* set start info */ - /*playbackinfo.start_tick = playbackinfo.previous_tick; - playbackinfo.start_time = time_get();*/ - playbackinfo.current_time = playbackinfo.previous_tick*time_freq()/SERVER_TICK_SPEED; - playbackinfo.last_update = time_get(); - return 0; -} - -int demorec_playback_set(float percent) -{ - int keyframe; - int wanted_tick; - if(!play_file) - return -1; - - /* -5 because we have to have a current tick and previous tick when we do the playback */ - wanted_tick = playbackinfo.first_tick + (int)((playbackinfo.last_tick-playbackinfo.first_tick)*percent) - 5; - - keyframe = (int)(playbackinfo.seekable_points*percent); - - if(keyframe < 0 || keyframe >= playbackinfo.seekable_points) - return -1; - - /* get correct key frame */ - if(keyframes[keyframe].tick < wanted_tick) - while(keyframe < playbackinfo.seekable_points-1 && keyframes[keyframe].tick < wanted_tick) - keyframe++; - - while(keyframe && keyframes[keyframe].tick > wanted_tick) - keyframe--; - - /* seek to the correct keyframe */ - io_seek(play_file, keyframes[keyframe].filepos, IOSEEK_START); - - /*playbackinfo.start_tick = -1;*/ - playbackinfo.next_tick = -1; - playbackinfo.current_tick = -1; - playbackinfo.previous_tick = -1; - - /* playback everything until we hit our tick */ - while(playbackinfo.previous_tick < wanted_tick) - do_tick(); - - demorec_playback_play(); - - return 0; -} - -void demorec_playback_setspeed(float speed) -{ - playbackinfo.speed = speed; -} - -int demorec_playback_update() -{ - int64 now = time_get(); - int64 deltatime = now-playbackinfo.last_update; - playbackinfo.last_update = now; - - if(!demorec_isplaying()) - return 0; - - if(playbackinfo.paused) - { - - } - else - { - int64 freq = time_freq(); - playbackinfo.current_time += (int64)(deltatime*(double)playbackinfo.speed); - - while(1) - { - int64 curtick_start = (playbackinfo.current_tick)*freq/SERVER_TICK_SPEED; - - /* break if we are ready */ - if(curtick_start > playbackinfo.current_time) - break; - - /* do one more tick */ - do_tick(); - - if(playbackinfo.paused) - return 0; - } - - /* update intratick */ - { - int64 curtick_start = (playbackinfo.current_tick)*freq/SERVER_TICK_SPEED; - int64 prevtick_start = (playbackinfo.previous_tick)*freq/SERVER_TICK_SPEED; - playbackinfo.intratick = (playbackinfo.current_time - prevtick_start) / (float)(curtick_start-prevtick_start); - playbackinfo.ticktime = (playbackinfo.current_time - prevtick_start) / (float)freq; - } - - if(playbackinfo.current_tick == playbackinfo.previous_tick || - playbackinfo.current_tick == playbackinfo.next_tick) - { - dbg_msg("demorec/playback", "tick error prev=%d cur=%d next=%d", - playbackinfo.previous_tick, playbackinfo.current_tick, playbackinfo.next_tick); - } - } - - return 0; -} - -int demorec_playback_stop() -{ - if(!play_file) - return -1; - - dbg_msg("demorec/playback", "Stopped playback"); - io_close(play_file); - play_file = 0; - mem_free(keyframes); - keyframes = 0; - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.h deleted file mode 100644 index 482debb49..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_demorec.h +++ /dev/null @@ -1,77 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef _DEMOREC_H -#define _DEMOREC_H - -#ifdef __cplusplus -extern "C"{ -#endif - -typedef struct DEMOREC_HEADER -{ - char marker[8]; - char netversion[64]; - char map[64]; - unsigned char crc[4]; - char type[8]; -} DEMOREC_HEADER; - -typedef struct DEMOREC_CHUNK -{ - char type[2]; - unsigned short size; -} DEMOREC_CHUNK; - -typedef struct DEMOREC_TICKMARKER -{ - int tick; -} DEMOREC_TICKMARKER; - -typedef struct DEMOREC_PLAYBACKINFO -{ - DEMOREC_HEADER header; - - int paused; - float speed; - - int64 last_update; - int64 current_time; - - int first_tick; - int last_tick; - - int seekable_points; - - int next_tick; - int current_tick; - int previous_tick; - - float intratick; - float ticktime; -} DEMOREC_PLAYBACKINFO; - -int demorec_record_start(const char *filename, const char *netversion, const char *map, int map_crc, const char *type); -int demorec_isrecording(); -void demorec_record_snapshot(int tick, const void *data, int size); -void demorec_record_message(const void *data, int size); -int demorec_record_stop(); - -typedef void (*DEMOREC_PLAYCALLBACK)(void *data, int size); - -int demorec_playback_registercallbacks(DEMOREC_PLAYCALLBACK snapshot_cb, DEMOREC_PLAYCALLBACK message_cb); -int demorec_playback_load(const char *filename); -int demorec_playback_nextframe(); -int demorec_playback_play(); -void demorec_playback_pause(); -void demorec_playback_unpause(); -void demorec_playback_setspeed(float speed); -int demorec_playback_set(float precent); -int demorec_playback_update(); -const DEMOREC_PLAYBACKINFO *demorec_playback_info(); -int demorec_isplaying(); -int demorec_playback_stop(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.cpp deleted file mode 100644 index 06d152c45..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include "e_linereader.h" - -/* compiled-in data-dir path */ -#define DATA_DIR "data" - -static JOBPOOL hostlookuppool; -static int engine_find_datadir(char *argv0); - -static void con_dbg_dumpmem(void *result, void *user_data) -{ - mem_debug_dump(); -} - -static void con_dbg_lognetwork(void *result, void *user_data) -{ - netcommon_openlog("network_sent.dat", "network_recv.dat"); -} - - -static char application_save_path[512] = {0}; -static char datadir[512] = {0}; - -const char *engine_savepath(const char *filename, char *buffer, int max) -{ - str_format(buffer, max, "%s/%s", application_save_path, filename); - return buffer; -} - -void engine_init(const char *appname) -{ - dbg_logger_stdout(); - dbg_logger_debugger(); - - /* */ - dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING); -#ifdef CONF_ARCH_ENDIAN_LITTLE - dbg_msg("engine", "arch is little endian"); -#elif defined(CONF_ARCH_ENDIAN_BIG) - dbg_msg("engine", "arch is big endian"); -#else - dbg_msg("engine", "unknown endian"); -#endif - - /* init the network */ - net_init(); - netcommon_init(); - - /* create storage location */ - { - char path[1024] = {0}; - fs_storage_path(appname, application_save_path, sizeof(application_save_path)); - if(fs_makedir(application_save_path) == 0) - { - str_format(path, sizeof(path), "%s/screenshots", application_save_path); - fs_makedir(path); - - str_format(path, sizeof(path), "%s/maps", application_save_path); - fs_makedir(path); - - str_format(path, sizeof(path), "%s/downloadedmaps", application_save_path); - fs_makedir(path); - - str_format(path, sizeof(path), "%s/demos", application_save_path); - fs_makedir(path); - } - } - - /* init console and add the console logger */ - console_init(); - dbg_logger(console_print); - - jobs_initpool(&hostlookuppool, 1); - - MACRO_REGISTER_COMMAND("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_dumpmem, 0x0, "Dump the memory"); - MACRO_REGISTER_COMMAND("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, con_dbg_lognetwork, 0x0, "Log the network"); - - /* reset the config */ - config_reset(); -} - - -void engine_listdir(int types, const char *path, FS_LISTDIR_CALLBACK cb, void *user) -{ - char buffer[1024]; - - /* list current directory */ - if(types&LISTDIRTYPE_CURRENT) - { - fs_listdir(path, cb, user); - } - - /* list users directory */ - if(types&LISTDIRTYPE_SAVE) - { - engine_savepath(path, buffer, sizeof(buffer)); - fs_listdir(buffer, cb, user); - } - - /* list datadir directory */ - if(types&LISTDIRTYPE_DATA) - { - str_format(buffer, sizeof(buffer), "%s/%s", datadir, path); - fs_listdir(buffer, cb, user); - } -} - -void engine_getpath(char *buffer, int buffer_size, const char *filename, int flags) -{ - if(flags&IOFLAG_WRITE) - engine_savepath(filename, buffer, buffer_size); - else - { - IOHANDLE handle = 0; - - /* check current directory */ - handle = io_open(filename, flags); - if(handle) - { - str_copy(buffer, filename, buffer_size); - io_close(handle); - return; - } - - /* check user directory */ - engine_savepath(filename, buffer, buffer_size); - handle = io_open(buffer, flags); - if(handle) - { - io_close(handle); - return; - } - - /* check normal data directory */ - str_format(buffer, buffer_size, "%s/%s", datadir, filename); - handle = io_open(buffer, flags); - if(handle) - { - io_close(handle); - return; - } - } - - buffer[0] = 0; -} - -IOHANDLE engine_openfile(const char *filename, int flags) -{ - char buffer[1024]; - - if(flags&IOFLAG_WRITE) - { - engine_savepath(filename, buffer, sizeof(buffer)); - return io_open(buffer, flags); - } - else - { - IOHANDLE handle = 0; - - /* check current directory */ - handle = io_open(filename, flags); - if(handle) - return handle; - - /* check user directory */ - engine_savepath(filename, buffer, sizeof(buffer)); - handle = io_open(buffer, flags); - if(handle) - return handle; - - /* check normal data directory */ - str_format(buffer, sizeof(buffer), "%s/%s", datadir, filename); - handle = io_open(buffer, flags); - if(handle) - return handle; - } - return 0; -} - -void engine_parse_arguments(int argc, char **argv) -{ - /* load the configuration */ - int i; - - /* check for datadir override */ - for(i = 1; i < argc; i++) - { - if(argv[i][0] == '-' && argv[i][1] == 'd' && argv[i][2] == 0 && argc - i > 1) - { - str_copy(datadir, argv[i+1], sizeof(datadir)); - i++; - } - } - - /* search for data directory */ - engine_find_datadir(argv[0]); - - dbg_msg("engine/datadir", "paths used:"); - dbg_msg("engine/datadir", "\t."); - dbg_msg("engine/datadir", "\t%s", application_save_path); - dbg_msg("engine/datadir", "\t%s", datadir); - dbg_msg("engine/datadir", "saving files to: %s", application_save_path); - - - /* check for scripts to execute */ - for(i = 1; i < argc; i++) - { - if(argv[i][0] == '-' && argv[i][1] == 'f' && argv[i][2] == 0 && argc - i > 1) - { - console_execute_file(argv[i+1]); - i++; - } - } - - /* search arguments for overrides */ - { - int i; - for(i = 1; i < argc; i++) - console_execute_line(argv[i]); - } - - console_execute_file("autoexec.cfg"); - - /* open logfile if needed */ - if(config.logfile[0]) - dbg_logger_file(config.logfile); - - /* set default servers and load from disk*/ - mastersrv_default(); - mastersrv_load(); -} - - -static IOHANDLE config_file = 0; - -int engine_config_write_start() -{ - config_save(); - config_file = engine_openfile("settings.cfg", IOFLAG_WRITE); - if(config_file == 0) - return -1; - return 0; -} - -void engine_config_write_line(const char *line) -{ - if(config_file) - { -#if defined(CONF_FAMILY_WINDOWS) - static const char newline[] = "\r\n"; -#else - static const char newline[] = "\n"; -#endif - io_write(config_file, line, strlen(line)); - io_write(config_file, newline, sizeof(newline)-1); - } -} - -void engine_config_write_stop() -{ - io_close(config_file); - config_file = 0; -} -/* -void engine_writeconfig() -{ -}*/ - -static int perf_tick = 1; -static PERFORMACE_INFO *current = 0; - -void perf_init() -{ -} - -void perf_next() -{ - perf_tick++; - current = 0; -} - -void perf_start(PERFORMACE_INFO *info) -{ - if(info->tick != perf_tick) - { - info->parent = current; - info->first_child = 0; - info->next_child = 0; - - if(info->parent) - { - info->next_child = info->parent->first_child; - info->parent->first_child = info; - } - - info->tick = perf_tick; - info->biggest = 0; - info->total = 0; - } - - current = info; - current->start = time_get(); -} - -void perf_end() -{ - if(!current) - return; - - current->last_delta = time_get()-current->start; - current->total += current->last_delta; - - if(current->last_delta > current->biggest) - current->biggest = current->last_delta; - - current = current->parent; -} - -static void perf_dump_imp(PERFORMACE_INFO *info, int indent) -{ - char buf[512] = {0}; - int64 freq = time_freq(); - int i; - - for(i = 0; i < indent; i++) - buf[i] = ' '; - - str_format(&buf[indent], sizeof(buf)-indent, "%-20s %8.2f %8.2f", info->name, info->total*1000/(float)freq, info->biggest*1000/(float)freq); - dbg_msg("perf", "%s", buf); - - info = info->first_child; - while(info) - { - perf_dump_imp(info, indent+2); - info = info->next_child; - } -} - -void perf_dump(PERFORMACE_INFO *top) -{ - perf_dump_imp(top, 0); -} - -/* master server functions */ -typedef struct -{ - char hostname[128]; - NETADDR addr; - - HOSTLOOKUP lookup; -} MASTER_INFO; - -static MASTER_INFO master_servers[MAX_MASTERSERVERS] = {{{0}}}; -static int needs_update = -1; - -int mastersrv_refresh_addresses() -{ - int i; - - if(needs_update != -1) - return 0; - - dbg_msg("engine/mastersrv", "refreshing master server addresses"); - - /* add lookup jobs */ - for(i = 0; i < MAX_MASTERSERVERS; i++) - engine_hostlookup(&master_servers[i].lookup, master_servers[i].hostname); - - needs_update = 1; - return 0; -} - -void mastersrv_update() -{ - int i; - - /* check if we need to update */ - if(needs_update != 1) - return; - needs_update = 0; - - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - if(jobs_status(&master_servers[i].lookup.job) != JOBSTATUS_DONE) - needs_update = 1; - else - { - master_servers[i].addr = master_servers[i].lookup.addr; - master_servers[i].addr.port = 8300; - } - } - - if(!needs_update) - { - dbg_msg("engine/mastersrv", "saving addresses"); - mastersrv_save(); - } -} - -int mastersrv_refreshing() -{ - return needs_update; -} - -NETADDR mastersrv_get(int index) -{ - return master_servers[index].addr; -} - -const char *mastersrv_name(int index) -{ - return master_servers[index].hostname; -} - -void mastersrv_dump_servers() -{ - int i; - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - dbg_msg("mastersrv", "#%d = %d.%d.%d.%d", i, - master_servers[i].addr.ip[0], master_servers[i].addr.ip[1], - master_servers[i].addr.ip[2], master_servers[i].addr.ip[3]); - } -} - -void mastersrv_default() -{ - int i; - mem_zero(master_servers, sizeof(master_servers)); - for(i = 0; i < MAX_MASTERSERVERS; i++) - sprintf(master_servers[i].hostname, "master%d.teeworlds.com", i+1); -} - -int mastersrv_load() -{ - LINEREADER lr; - IOHANDLE file; - int count = 0; - - /* try to open file */ - file = engine_openfile("masters.cfg", IOFLAG_READ); - if(!file) - return -1; - - linereader_init(&lr, file); - while(1) - { - MASTER_INFO info = {{0}}; - int ip[4]; - const char *line = linereader_get(&lr); - if(!line) - break; - - /* parse line */ - if(sscanf(line, "%s %d.%d.%d.%d", info.hostname, &ip[0], &ip[1], &ip[2], &ip[3]) == 5) - { - info.addr.ip[0] = (unsigned char)ip[0]; - info.addr.ip[1] = (unsigned char)ip[1]; - info.addr.ip[2] = (unsigned char)ip[2]; - info.addr.ip[3] = (unsigned char)ip[3]; - info.addr.port = 8300; - if(count != MAX_MASTERSERVERS) - { - master_servers[count] = info; - count++; - } - else - dbg_msg("engine/mastersrv", "warning: skipped master server '%s' due to limit of %d", line, MAX_MASTERSERVERS); - } - else - dbg_msg("engine/mastersrv", "warning: couldn't parse master server '%s'", line); - } - - io_close(file); - return 0; -} - -int mastersrv_save() -{ - IOHANDLE file; - int i; - - /* try to open file */ - file = engine_openfile("masters.cfg", IOFLAG_WRITE); - if(!file) - return -1; - - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - char buf[1024]; - str_format(buf, sizeof(buf), "%s %d.%d.%d.%d\n", master_servers[i].hostname, - master_servers[i].addr.ip[0], master_servers[i].addr.ip[1], - master_servers[i].addr.ip[2], master_servers[i].addr.ip[3]); - - io_write(file, buf, strlen(buf)); - } - - io_close(file); - return 0; -} - - -int hostlookup_thread(void *user) -{ - HOSTLOOKUP *lookup = (HOSTLOOKUP *)user; - net_host_lookup(lookup->hostname, &lookup->addr, NETTYPE_IPV4); - return 0; -} - -void engine_hostlookup(HOSTLOOKUP *lookup, const char *hostname) -{ - str_copy(lookup->hostname, hostname, sizeof(lookup->hostname)); - jobs_add(&hostlookuppool, &lookup->job, hostlookup_thread, lookup); -} - -static int engine_find_datadir(char *argv0) -{ - /* 1) use provided data-dir override */ - if(datadir[0]) - { - if(fs_is_dir(datadir)) - return 0; - else - { - dbg_msg("engine/datadir", "specified data-dir '%s' does not exist", datadir); - return -1; - } - } - - /* 2) use data-dir in PWD if present */ - if(fs_is_dir("data")) - { - strcpy(datadir, "data"); - return 0; - } - - /* 3) use compiled-in data-dir if present */ - if (fs_is_dir(DATA_DIR)) - { - strcpy(datadir, DATA_DIR); - return 0; - } - - /* 4) check for usable path in argv[0] */ - { - unsigned int pos = strrchr(argv0, '/') - argv0; - - if (pos < sizeof(datadir)) - { - char basedir[sizeof(datadir)]; - strncpy(basedir, argv0, pos); - basedir[pos] = '\0'; - str_format(datadir, sizeof(datadir), "%s/data", basedir); - - if (fs_is_dir(datadir)) - return 0; - } - } - -#if defined(CONF_FAMILY_UNIX) - /* 5) check for all default locations */ - { - const char *sdirs[] = { - "/usr/share/teeworlds", - "/usr/local/share/teeworlds" - "/opt/teeworlds" - }; - const int sdirs_count = sizeof(sdirs) / sizeof(sdirs[0]); - - int i; - for (i = 0; i < sdirs_count; i++) - { - if (fs_is_dir(sdirs[i])) - { - strcpy(datadir, sdirs[i]); - return 0; - } - } - } -#endif - - /* no data-dir found */ - dbg_msg("engine/datadir", "warning no data directory found"); - return -1; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.h deleted file mode 100644 index 5091e2444..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_engine.h +++ /dev/null @@ -1,60 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include "e_jobs.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -const char *engine_savepath(const char *filename, char *buffer, int max); -void engine_init(const char *appname); -void engine_parse_arguments(int argc, char **argv); - -int engine_config_write_start(); -void engine_config_write_line(const char *line); -void engine_config_write_stop(); - - -enum -{ - LISTDIRTYPE_SAVE=1, - LISTDIRTYPE_CURRENT=2, - LISTDIRTYPE_DATA=4, - LISTDIRTYPE_ALL = ~0 -}; - -void engine_listdir(int types, const char *path, FS_LISTDIR_CALLBACK cb, void *user); -IOHANDLE engine_openfile(const char *filename, int flags); -void engine_getpath(char *buffer, int buffer_size, const char *filename, int flags); - -int engine_stress(float probability); - -typedef struct HOSTLOOKUP -{ - JOB job; - char hostname[128]; - NETADDR addr; -} HOSTLOOKUP; - -void engine_hostlookup(HOSTLOOKUP *lookup, const char *hostname); - -enum -{ - MAX_MASTERSERVERS=4 -}; - -void mastersrv_default(); -int mastersrv_load(); -int mastersrv_save(); - -int mastersrv_refresh_addresses(); -void mastersrv_update(); -int mastersrv_refreshing(); -void mastersrv_dump_servers(); -NETADDR mastersrv_get(int index); -const char *mastersrv_name(int index); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.cpp deleted file mode 100644 index 6a72a6c50..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.cpp +++ /dev/null @@ -1,277 +0,0 @@ -#include /* memset */ -#include /* memset */ -#include "e_huffman.h" - -typedef struct HUFFMAN_CONSTRUCT_NODE -{ - unsigned short node_id; - int frequency; -} HUFFMAN_CONSTRUCT_NODE; - -static void huffman_setbits_r(HUFFMAN_STATE *huff, HUFFMAN_NODE *node, int bits, int depth) -{ - if(node->leafs[1] != 0xffff) - huffman_setbits_r(huff, &huff->nodes[node->leafs[1]], bits|(1<leafs[0] != 0xffff) - huffman_setbits_r(huff, &huff->nodes[node->leafs[0]], bits, depth+1); - - if(node->num_bits) - { - node->bits = bits; - node->num_bits = depth; - } -} - -/* TODO: this should be something faster, but it's enough for now */ -void bubblesort(HUFFMAN_CONSTRUCT_NODE **list, int size) -{ - int i, changed = 1; - HUFFMAN_CONSTRUCT_NODE *temp; - - while(changed) - { - changed = 0; - for(i = 0; i < size-1; i++) - { - if(list[i]->frequency < list[i+1]->frequency) - { - temp = list[i]; - list[i] = list[i+1]; - list[i+1] = temp; - changed = 1; - } - } - } -} - -static void huffman_construct_tree(HUFFMAN_STATE *huff, const unsigned *frequencies) -{ - HUFFMAN_CONSTRUCT_NODE nodes_left_storage[HUFFMAN_MAX_SYMBOLS]; - HUFFMAN_CONSTRUCT_NODE *nodes_left[HUFFMAN_MAX_SYMBOLS]; - int num_nodes_left = HUFFMAN_MAX_SYMBOLS; - int i; - - /* add the symbols */ - for(i = 0; i < HUFFMAN_MAX_SYMBOLS; i++) - { - huff->nodes[i].num_bits = -1; - huff->nodes[i].symbol = i; - huff->nodes[i].leafs[0] = -1; - huff->nodes[i].leafs[1] = -1; - - if(i == HUFFMAN_EOF_SYMBOL) - nodes_left_storage[i].frequency = 1; - else - nodes_left_storage[i].frequency = frequencies[i]; - nodes_left_storage[i].node_id = i; - nodes_left[i] = &nodes_left_storage[i]; - - } - huff->num_nodes = HUFFMAN_MAX_SYMBOLS; - - /* construct the table */ - while(num_nodes_left > 1) - { - /* we can't rely on stdlib's qsort for this, it can generate different results on different implementations */ - bubblesort(nodes_left, num_nodes_left); - - huff->nodes[huff->num_nodes].num_bits = 0; - huff->nodes[huff->num_nodes].leafs[0] = nodes_left[num_nodes_left-1]->node_id; - huff->nodes[huff->num_nodes].leafs[1] = nodes_left[num_nodes_left-2]->node_id; - nodes_left[num_nodes_left-2]->node_id = huff->num_nodes; - nodes_left[num_nodes_left-2]->frequency = nodes_left[num_nodes_left-1]->frequency + nodes_left[num_nodes_left-2]->frequency; - - huff->num_nodes++; - num_nodes_left--; - } - - /* set start node */ - huff->start_node = &huff->nodes[huff->num_nodes-1]; - - /* build symbol bits */ - huffman_setbits_r(huff, huff->start_node, 0, 0); -} - -void huffman_init(HUFFMAN_STATE *huff, const unsigned *frequencies) -{ - int i; - - /* make sure to cleanout every thing */ - memset(huff, 0, sizeof(HUFFMAN_STATE)); - - /* construct the tree */ - huffman_construct_tree(huff, frequencies); - - /* build decode LUT */ - for(i = 0; i < HUFFMAN_LUTSIZE; i++) - { - unsigned bits = i; - int k; - HUFFMAN_NODE *node = huff->start_node; - for(k = 0; k < HUFFMAN_LUTBITS; k++) - { - node = &huff->nodes[node->leafs[bits&1]]; - bits >>= 1; - - if(!node) - break; - - if(node->num_bits) - { - huff->decode_lut[i] = node; - break; - } - } - - if(k == HUFFMAN_LUTBITS) - huff->decode_lut[i] = node; - } - -} - -/*****************************************************************/ -int huffman_compress(HUFFMAN_STATE *huff, const void *input, int input_size, void *output, int output_size) -{ - /* this macro loads a symbol for a byte into bits and bitcount */ -#define HUFFMAN_MACRO_LOADSYMBOL(sym) \ - bits |= huff->nodes[sym].bits << bitcount; \ - bitcount += huff->nodes[sym].num_bits; - - /* this macro writes the symbol stored in bits and bitcount to the dst pointer */ -#define HUFFMAN_MACRO_WRITE() \ - while(bitcount >= 8) \ - { \ - *dst++ = (unsigned char)(bits&0xff); \ - if(dst == dst_end) \ - return -1; \ - bits >>= 8; \ - bitcount -= 8; \ - } - - /* setup buffer pointers */ - const unsigned char *src = (const unsigned char *)input; - const unsigned char *src_end = src + input_size; - unsigned char *dst = (unsigned char *)output; - unsigned char *dst_end = dst + output_size; - - /* symbol variables */ - unsigned bits = 0; - unsigned bitcount = 0; - - /* make sure that we have data that we want to compress */ - if(input_size) - { - /* {A} load the first symbol */ - int symbol = *src++; - - while(src != src_end) - { - /* {B} load the symbol */ - HUFFMAN_MACRO_LOADSYMBOL(symbol) - - /* {C} fetch next symbol, this is done here because it will reduce dependency in the code */ - symbol = *src++; - - /* {B} write the symbol loaded at */ - HUFFMAN_MACRO_WRITE() - } - - /* write the last symbol loaded from {C} or {A} in the case of only 1 byte input buffer */ - HUFFMAN_MACRO_LOADSYMBOL(symbol) - HUFFMAN_MACRO_WRITE() - } - - /* write EOF symbol */ - HUFFMAN_MACRO_LOADSYMBOL(HUFFMAN_EOF_SYMBOL) - HUFFMAN_MACRO_WRITE() - - /* write out the last bits */ - *dst++ = bits; - - /* return the size of the output */ - return (int)(dst - (const unsigned char *)output); - - /* remove macros */ -#undef HUFFMAN_MACRO_LOADSYMBOL -#undef HUFFMAN_MACRO_WRITE -} - -/*****************************************************************/ -int huffman_decompress(HUFFMAN_STATE *huff, const void *input, int input_size, void *output, int output_size) -{ - /* setup buffer pointers */ - unsigned char *dst = (unsigned char *)output; - unsigned char *src = (unsigned char *)input; - unsigned char *dst_end = dst + output_size; - unsigned char *src_end = src + input_size; - - unsigned bits = 0; - unsigned bitcount = 0; - - HUFFMAN_NODE *eof = &huff->nodes[HUFFMAN_EOF_SYMBOL]; - HUFFMAN_NODE *node = 0; - - while(1) - { - /* {A} try to load a node now, this will reduce dependency at location {D} */ - node = 0; - if(bitcount >= HUFFMAN_LUTBITS) - node = huff->decode_lut[bits&HUFFMAN_LUTMASK]; - - /* {B} fill with new bits */ - while(bitcount < 24 && src != src_end) - { - bits |= (*src++) << bitcount; - bitcount += 8; - } - - /* {C} load symbol now if we didn't that earlier at location {A} */ - if(!node) - node = huff->decode_lut[bits&HUFFMAN_LUTMASK]; - - /* {D} check if we hit a symbol already */ - if(node->num_bits) - { - /* remove the bits for that symbol */ - bits >>= node->num_bits; - bitcount -= node->num_bits; - } - else - { - /* remove the bits that the lut checked up for us */ - bits >>= HUFFMAN_LUTBITS; - bitcount -= HUFFMAN_LUTBITS; - - /* walk the tree bit by bit */ - while(1) - { - /* traverse tree */ - node = &huff->nodes[node->leafs[bits&1]]; - - /* remove bit */ - bitcount--; - bits >>= 1; - - /* check if we hit a symbol */ - if(node->num_bits) - break; - - /* no more bits, decoding error */ - if(bitcount == 0) - return -1; - } - } - - /* check for eof */ - if(node == eof) - break; - - /* output character */ - if(dst == dst_end) - return -1; - *dst++ = node->symbol; - } - - /* return the size of the decompressed buffer */ - return (int)(dst - (const unsigned char *)output); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.h deleted file mode 100644 index c4e202234..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_huffman.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef __HUFFMAN_HEADER__ -#define __HUFFMAN_HEADER__ - -#ifdef __cplusplus -extern "C" { -#endif - -enum -{ - HUFFMAN_EOF_SYMBOL = 256, - - HUFFMAN_MAX_SYMBOLS=HUFFMAN_EOF_SYMBOL+1, - HUFFMAN_MAX_NODES=HUFFMAN_MAX_SYMBOLS*2-1, - - HUFFMAN_LUTBITS = 10, - HUFFMAN_LUTSIZE = (1< -*/ -float client_intratick(); - -/* - Function: client_predtick - Returns the current predicted tick. -*/ -int client_predtick(); - -/* - Function: client_predintratick - Returns the current preticted intra tick. - - Remarks: - This is the same as but for the current predicted tick and - previous predicted tick. - - See Also: - -*/ -float client_predintratick(); - -/* - Function: client_ticktime - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -float client_ticktime(); - -/* - Function: client_tickspeed - Returns how many ticks per second the client is doing. - - Remarks: - This will be the same as the server tick speed. -*/ -int client_tickspeed(); - -/* - Function: client_frametime - Returns how long time the last frame took to process. -*/ -float client_frametime(); - -/* - Function: client_localtime - Returns the clients local time. - - Remarks: - The local time is set to 0 when the client starts and when - it connects to a server. Can be used for client side effects. -*/ -float client_localtime(); - -/********************************************************************************** - Group: Server Browser -**********************************************************************************/ - -/* - Function: client_serverbrowse_refresh - Issues a refresh of the server browser. - - Arguments: - type - What type of servers to browse, internet, lan or favorites. - - Remarks: - This will cause a broadcast on the local network if the lan argument is set. - Otherwise it call ask all the master servers for their servers lists. -*/ -void client_serverbrowse_refresh(int type); - -/* - Function: client_serverbrowse_sorted_get - Returns server info from the sorted list. - - Arguments: - index - Zero based index into the sorted list. - - See Also: - -*/ -SERVER_INFO *client_serverbrowse_sorted_get(int index); - -/* - Function: client_serverbrowse_sorted_num - Returns how many servers there are in the sorted list. - - See Also: - -*/ -int client_serverbrowse_sorted_num(); - -/* - Function: client_serverbrowse_get - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -SERVER_INFO *client_serverbrowse_get(int index); - -/* - Function: client_serverbrowse_num - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_serverbrowse_num(); - -/* - Function: client_serverbrowse_num_requests - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_serverbrowse_num_requests(); - -/* - Function: client_serverbrowse_update - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void client_serverbrowse_update(); - -/* - Function: client_serverbrowse_lan - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_serverbrowse_lan(); - -/* - Function: client_serverbrowse_isfavorite - Asks the server browser is a netaddr is in the favorite list - - Arguments: - addr - Address of the server to ask about. - - Returns: - Returns zero if it's not in the list, non-zero if it is. -*/ -int client_serverbrowse_isfavorite(NETADDR addr); - -/* - Function: client_serverbrowse_addfavorite - Adds a server to the favorite list - - Arguments: - addr - Address of the favorite server. -*/ -void client_serverbrowse_addfavorite(NETADDR addr); - -/* - Function: client_serverbrowse_removefavorite - Removes a server to the favorite list - - Arguments: - addr - Address of the favorite server. -*/ -void client_serverbrowse_removefavorite(NETADDR addr); - -/********************************************************************************** - Group: Actions -**********************************************************************************/ - - -/* - Function: client_connect - Connects to a server at the specified address. - - Arguments: - address - Address of the server to connect to. - - See Also: - -*/ -void client_connect(const char *address); - -/* - Function: client_disconnect - Disconnects from the current server. - - Remarks: - Does nothing if not connected to a server. - - See Also: - -*/ -void client_disconnect(); - -/* - Function: client_quit - Tells to client to shutdown. - - See Also: - -*/ -void client_quit(); - -void client_entergame(); - -/* - Function: client_rcon - Sends a command to the server to execute on it's console. - - Arguments: - cmd - The command to send. - - Remarks: - The client must have the correct rcon password to connect. - - See Also: - -*/ -void client_rcon(const char *cmd); - -/* - Function: client_rcon_auth - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void client_rcon_auth(const char *name, const char *password); - -/* - Function: client_rcon_authed - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_rcon_authed(); - -/********************************************************************************** - Group: Other -**********************************************************************************/ -/* - Function: client_latestversion - Returns 0 if there's no version difference - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *client_latestversion(); - -/* - Function: client_get_input - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int *client_get_input(int tick); - -/* - Function: client_direct_input - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void client_direct_input(int *input, int size); - -/* - Function: client_error_string - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *client_error_string(); - -/* - Function: client_connection_problems - Returns 1 if the client is connection problems. - - Remarks: - Connections problems usually means that the client havn't recvived any data - from the server in a while. -*/ -int client_connection_problems(); - -/* - Function: client_state - Returns the state of the client. - - See Also: - -*/ -int client_state(); - -/* - Function: client_mapdownload_amount - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_mapdownload_amount(); - -/* - Function: client_mapdownload_totalsize - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_mapdownload_totalsize(); - -/* - Function: client_save_line - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void client_save_line(const char *line); - - - - - - -enum -{ - BROWSESET_MASTER_ADD=1, - BROWSESET_FAV_ADD, - BROWSESET_TOKEN, - BROWSESET_OLD_INTERNET, - BROWSESET_OLD_LAN -}; - -void client_serverbrowse_set(NETADDR *addr, int type, int token, SERVER_INFO *info); - -int client_serverbrowse_refreshingmasters(); - - -typedef struct DEMOPLAYBACK_INFO -{ - int first_tick; - int last_tick; - int current_tick; - int paused; - float speed; -} DEMOPLAYBACK_INFO; - -void client_demoplayer_play(const char *filename); -const DEMOPLAYBACK_INFO *client_demoplayer_getinfo(); -void client_demoplayer_setpos(float percent); -void client_demoplayer_setpause(int paused); -void client_demoplayer_setspeed(float speed); -const char *client_user_directory(); -void client_serverinfo(SERVER_INFO *serverinfo); -void client_serverinfo_request(); -void client_serverbrowse_request(NETADDR *addr); -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_gfx.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_gfx.h deleted file mode 100644 index 1b9f920c0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_gfx.h +++ /dev/null @@ -1,673 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_GFX_H -#define ENGINE_IF_GFX_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Title: Graphics -*/ - -/* - Section: Structures -*/ - -/* - Structure: IMAGE_INFO -*/ -typedef struct -{ - /* Variable: width - Contains the width of the image */ - int width; - - /* Variable: height - Contains the height of the image */ - int height; - - /* Variable: format - Contains the format of the image. See for more information. */ - int format; - - /* Variable: data - Pointer to the image data. */ - void *data; -} IMAGE_INFO; - -/* - Structure: VIDEO_MODE -*/ -typedef struct -{ - int width, height; - int red, green, blue; -} VIDEO_MODE; - -/* - Section: Functions -*/ - -/* - Group: Quads -*/ - -/* - Function: gfx_quads_begin - Begins a quad drawing session. - - Remarks: - This functions resets the rotation, color and subset. - End the session by using . - You can't change texture or blending mode during a session. - - See Also: - -*/ -void gfx_quads_begin(); - -/* - Function: gfx_quads_end - Ends a quad session. - - See Also: - -*/ -void gfx_quads_end(); - -/* - Function: gfx_quads_setrotation - Sets the rotation to use when drawing a quad. - - Arguments: - angle - Angle in radians. - - Remarks: - The angle is reset when is called. -*/ -void gfx_quads_setrotation(float angle); - -/* - Function: gfx_quads_setsubset - Sets the uv coordinates to use. - - Arguments: - tl_u - Top-left U value. - tl_v - Top-left V value. - br_u - Bottom-right U value. - br_v - Bottom-right V value. - - Remarks: - O,0 is top-left of the texture and 1,1 is bottom-right. - The color is reset when is called. -*/ -void gfx_quads_setsubset(float tl_u, float tl_v, float br_u, float br_v); - -/* - Function: gfx_quads_setsubset_free - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_quads_setsubset_free( - float x0, float y0, - float x1, float y1, - float x2, float y2, - float x3, float y3); - -/* - Function: gfx_quads_drawTL - Draws a quad by specifying the top-left point. - - Arguments: - x - X coordinate of the top-left corner. - y - Y coordinate of the top-left corner. - width - Width of the quad. - height - Height of the quad. - - Remarks: - Rotation still occurs from the center of the quad. - You must call before calling this function. - - See Also: - -*/ -void gfx_quads_drawTL(float x, float y, float width, float height); - -/* - Function: gfx_quads_draw - Draws a quad by specifying the center point. - - Arguments: - x - X coordinate of the center. - y - Y coordinate of the center. - width - Width of the quad. - height - Height of the quad. - - Remarks: - You must call before calling this function. - - See Also: - -*/ -void gfx_quads_draw(float x, float y, float w, float h); - -/* - Function: gfx_quads_draw_freeform - Draws a quad by specifying the corner points. - - Arguments: - x0, y0 - Coordinates of the upper left corner. - x1, y1 - Coordinates of the upper right corner. - x2, y2 - Coordinates of the lower left corner. // TODO: DOUBLE CHECK!!! - x3, y3 - Coordinates of the lower right corner. // TODO: DOUBLE CHECK!!! - - See Also: - -*/ -void gfx_quads_draw_freeform( - float x0, float y0, - float x1, float y1, - float x2, float y2, - float x3, float y3); - -/* - Function: gfx_quads_text - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_quads_text(float x, float y, float size, float r, float g, float b, float a, const char *text); - -/* - Group: Lines -*/ - -/* - Function: gfx_lines_begin - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_lines_begin(); - -/* - Function: gfx_lines_draw - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_lines_draw(float x0, float y0, float x1, float y1); - -/* - Function: gfx_minimize - Minimizes the window. - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_minimize(); - -/* - Function: gfx_minimize - Maximizes the window. - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_maximize(); - -/* - Function: gfx_lines_end - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_lines_end(); - -/* - Group: Text -*/ - - -/* - Function: gfx_text - TODO - - Arguments: - arg1 - desc - - Returns: - returns the number of lines written - See Also: - -*/ -void gfx_text(void *font, float x, float y, float size, const char *text, int max_width); - -/* - Function: gfx_text_width - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -float gfx_text_width(void *font, float size, const char *text, int length); - -/* - Function: gfx_text_color - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_text_color(float r, float g, float b, float a); - -/* - Function: gfx_text_set_default_font - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_text_set_default_font(void *font); - -/* - Group: Other -*/ - -/* - Function: gfx_get_video_modes - Fetches a list of all the available video modes. - - Arguments: - list - An array to recive the modes. Must be able to contain maxcount number of modes. - maxcount - The maximum number of modes to fetch. - - Returns: - The number of video modes that was fetched. -*/ -int gfx_get_video_modes(VIDEO_MODE *list, int maxcount); - -/* image loaders */ - -/* - Function: gfx_load_png - Loads a PNG image from disk. - - Arguments: - img - Pointer to an structure to be filled out with the image information. - filename - Filename of the image to load. - - Returns: - Returns non-zero on success and zero on error. - - Remarks: - The caller are responsible for cleaning up the allocated memory in the IMAGE_INFO structure. - - See Also: - -*/ -int gfx_load_png(IMAGE_INFO *img, const char *filename); - -/* textures */ -/* - Function: gfx_load_texture - Loads a texture from a file. TGA and PNG supported. - - Arguments: - filename - Null terminated string to the file to load. - store_format - What format to store on gfx card as. - flags - controls how the texture is uploaded - - Returns: - An ID to the texture. -1 on failure. - - See Also: - -*/ -int gfx_load_texture(const char *filename, int store_format, int flags); - -/* - Function: gfx_load_texture_raw - Loads a texture from memory. - - Arguments: - w - Width of the texture. - h - Height of the texture. - data - Pointer to the pixel data. - format - Format of the pixel data. - store_format - The format to store the texture on the graphics card. - flags - controls how the texture is uploaded - - Returns: - An ID to the texture. -1 on failure. - - Remarks: - The pixel data should be in RGBA format with 8 bit per component. - So the total size of the data should be w*h*4. - - See Also: - -*/ -int gfx_load_texture_raw(int w, int h, int format, const void *data, int store_format, int flags); - -/* - Function: gfx_texture_set - Sets the active texture. - - Arguments: - id - ID to the texture to set. -*/ -void gfx_texture_set(int id); - -/* - Function: gfx_unload_texture - Unloads a texture. - - Arguments: - id - ID to the texture to unload. - - See Also: - , - - Remarks: - NOT IMPLEMENTED -*/ -int gfx_unload_texture(int id); - -/* - Function: gfx_clear - Clears the screen with the specified color. - - Arguments: - r - Red component. - g - Green component. - b - Red component. - - Remarks: - The value of the components are given in 0.0 - 1.0 ranges. -*/ -void gfx_clear(float r, float g, float b); - -/* - Function: gfx_screenaspect - Returns the aspect ratio between width and height. - - See Also: - , -*/ -float gfx_screenaspect(); - -/* - Function: gfx_screenwidth - Returns the screen width. - - See Also: - -*/ -int gfx_screenwidth(); - -/* - Function: gfx_screenheight - Returns the screen height. - - See Also: - -*/ -int gfx_screenheight(); - -/* - Function: gfx_mapscreen - Specifies the coordinate system for the screen. - - Arguments: - tl_x - Top-left X - tl_y - Top-left Y - br_x - Bottom-right X - br_y - Bottom-right y -*/ -void gfx_mapscreen(float tl_x, float tl_y, float br_x, float br_y); - -/* - Function: gfx_blend_normal - Set the active blending mode to normal (src, 1-src). - - Remarks: - This must be used before calling . - This is equal to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). - - See Also: - -*/ -void gfx_blend_normal(); - -/* - Function: gfx_blend_additive - Set the active blending mode to additive (src, one). - - Remarks: - This must be used before calling . - This is equal to glBlendFunc(GL_SRC_ALPHA, GL_ONE). - - See Also: - -*/ -void gfx_blend_additive(); - -/* - Function: gfx_blend_none - Disables blending - - Remarks: - This must be used before calling . - - See Also: - -*/ -void gfx_blend_none(); - - -/* - Function: gfx_setcolorvertex - Sets the color of a vertex. - - Arguments: - i - Index to the vertex. - r - Red value. - g - Green value. - b - Blue value. - a - Alpha value. - - Remarks: - The color values are from 0.0 to 1.0. - The color is reset when is called. -*/ -void gfx_setcolorvertex(int i, float r, float g, float b, float a); - -/* - Function: gfx_setcolor - Sets the color of all the vertices. - - Arguments: - r - Red value. - g - Green value. - b - Blue value. - a - Alpha value. - - Remarks: - The color values are from 0.0 to 1.0. - The color is reset when is called. -*/ -void gfx_setcolor(float r, float g, float b, float a); - -/* - Function: gfx_getscreen - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y); - -/* - Function: gfx_memory_usage - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int gfx_memory_usage(); - -/* - Function: gfx_screenshot - TODO - - Arguments: - filename - desc - - Returns: - - See Also: - -*/ -void gfx_screenshot(); - -/* - Function: gfx_screenshot_direct - TODO - - Arguments: - filename - desc - - Returns: - - See Also: - -*/ -void gfx_screenshot_direct(const char *filename); - -/* - Function: gfx_clip_enable - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_clip_enable(int x, int y, int w, int h); - -/* - Function: gfx_clip_disable - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void gfx_clip_disable(); - - -enum -{ - TEXTFLAG_RENDER=1, - TEXTFLAG_ALLOW_NEWLINE=2, - TEXTFLAG_STOP_AT_END=4 -}; - -typedef struct -{ - int flags; - int line_count; - int charcount; - - float start_x; - float start_y; - float line_width; - float x, y; - void *font_set; - float font_size; -} TEXT_CURSOR; - -void gfx_text_set_cursor(TEXT_CURSOR *cursor, float x, float y, float font_size, int flags); -void gfx_text_ex(TEXT_CURSOR *cursor, const char *text, int length); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_inp.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_inp.h deleted file mode 100644 index 9277d8302..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_inp.h +++ /dev/null @@ -1,255 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_INP_H -#define ENGINE_IF_INP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Section: Input -*/ - - -/* - Structure: INPUT_EVENT -*/ -enum -{ - INPFLAG_PRESS=1, - INPFLAG_RELEASE=2, - INPFLAG_REPEAT=4 -}; - -typedef struct -{ - int flags; - unsigned char ch; - int key; -} INPUT_EVENT; - -/* - Function: inp_mouse_relative - Fetches the mouse movements. - - Arguments: - x - Pointer to the variable that should get the X movement. - y - Pointer to the variable that should get the Y movement. -*/ -void inp_mouse_relative(int *x, int *y); - -void inp_mouse_absolute(int *x, int *y); - -/* - Function: inp_mouse_scroll - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_mouse_scroll(); - -/* - Function: inp_key_pressed - Checks if a key is pressed. - - Arguments: - key - Index to the key to check - - Returns: - Returns 1 if the button is pressed, otherwise 0. - - Remarks: - Check keys.h for the keys. -*/ -int inp_key_pressed(int key); - - -/* input */ -/* - Function: inp_key_was_pressed - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_was_pressed(int key); - -/* - Function: inp_key_down - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_down(int key); - - -/* - Function: inp_num_events - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_num_events(); - -/* - Function: inp_get_event - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -INPUT_EVENT inp_get_event(int index); - -/* - Function: inp_clear_events - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void inp_clear_events(); - -/* - Function: inp_mouse_doubleclick - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_mouse_doubleclick(); - -/* - Function: inp_key_presses - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_presses(int key); - -/* - Function: inp_key_releases - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_releases(int key); - -/* - Function: inp_key_state - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_state(int key); - -/* - Function: inp_key_name - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *inp_key_name(int k); - -/* - Function: inp_key_code - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int inp_key_code(const char *key_name); - - - -/* - Function: inp_clear_key_states - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void inp_clear_key_states(); - -void inp_update(); -void inp_init(); -void inp_mouse_mode_absolute(); -void inp_mouse_mode_relative(); -void inp_warp_mouse(int x, int y); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_modc.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_modc.h deleted file mode 100644 index d09bebeb3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_modc.h +++ /dev/null @@ -1,153 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_MODC_H -#define ENGINE_IF_MODC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************************************************************************** - Section: Client Hooks -*********************************************************************************/ -/* - Function: modc_console_init - TODO -*/ -void modc_console_init(); - -/* - Function: modc_rcon_line - TODO -*/ -void modc_rcon_line(const char *line); - -/* - Function: modc_save_config - TODO -*/ -void modc_save_config(); - -/* - Function: modc_init - Called when the client starts. - - Remarks: - The game should load resources that are used during the entire - time of the game. No map is loaded. -*/ -void modc_init(); - -/* - Function: modc_newsnapshot - Called when the client progressed to a new snapshot. - - Remarks: - The client can check for items in the snapshot and perform one time - events like playing sounds, spawning client side effects etc. -*/ -void modc_newsnapshot(); - -/* - Function: modc_entergame - Called when the client has successfully connect to a server and - loaded a map. - - Remarks: - The client can check for items in the map and load them. -*/ -void modc_entergame(); - -/* - Function: modc_shutdown - Called when the client closes down. -*/ -void modc_shutdown(); - -/* - Function: modc_render - Called every frame to let the game render it self. -*/ -void modc_render(); - -/* - Function: modc_statechange - Called every time client changes state. -*/ -void modc_statechange(int new_state, int old_state); - -/* undocumented callbacks */ -/* - Function: modc_connected - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void modc_connected(); - -/* - Function: modc_message - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void modc_message(int msg); - -/* - Function: modc_predict - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void modc_predict(); - -/* - Function: modc_snap_input - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int modc_snap_input(int *data); - -/* - Function: modc_net_version - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *modc_net_version(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_mods.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_mods.h deleted file mode 100644 index f63c2a025..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_mods.h +++ /dev/null @@ -1,176 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_MOD_H -#define ENGINE_IF_MOD_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************************************************************************** - Section: Server Hooks -**********************************************************************************/ -/* - Function: mods_console_init - TODO -*/ -void mods_console_init(); - -/* - Function: mods_init - Called when the server is started. - - Remarks: - It's called after the map is loaded so all map items are available. -*/ -void mods_init(); - -/* - Function: mods_shutdown - Called when the server quits. - - Remarks: - Should be used to clean up all resources used. -*/ -void mods_shutdown(); - -/* - Function: mods_client_enter - Called when a client has joined the game. - - Arguments: - cid - Client ID. Is 0 - MAX_CLIENTS. - - Remarks: - It's called when the client is finished loading and should enter gameplay. -*/ -void mods_client_enter(int cid); - -/* - Function: mods_client_drop - Called when a client drops from the server. - - Arguments: - cid - Client ID. Is 0 - MAX_CLIENTS -*/ -void mods_client_drop(int cid); - -/* - Function: mods_client_direct_input - Called when the server recives new input from a client. - - Arguments: - cid - Client ID. Is 0 - MAX_CLIENTS. - input - Pointer to the input data. - size - Size of the data. (NOT IMPLEMENTED YET) -*/ -void mods_client_direct_input(int cid, void *input); - -/* - Function: mods_client_predicted_input - Called when the server applys the predicted input on the client. - - Arguments: - cid - Client ID. Is 0 - MAX_CLIENTS. - input - Pointer to the input data. - size - Size of the data. (NOT IMPLEMENTED YET) -*/ -void mods_client_predicted_input(int cid, void *input); - - -/* - Function: mods_tick - Called with a regular interval to progress the gameplay. - - Remarks: - The SERVER_TICK_SPEED tells the number of ticks per second. -*/ -void mods_tick(); - -/* - Function: mods_presnap - Called before the server starts to construct snapshots for the clients. -*/ -void mods_presnap(); - -/* - Function: mods_snap - Called to create the snapshot for a client. - - Arguments: - cid - Client ID. Is 0 - MAX_CLIENTS. - - Remarks: - The game should make a series of calls to to construct - the snapshot for the client. -*/ -void mods_snap(int cid); - -/* - Function: mods_postsnap - Called after the server is done sending the snapshots. -*/ -void mods_postsnap(); - - -/* - Function: mods_connected - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void mods_connected(int client_id); - - -/* - Function: mods_net_version - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *mods_net_version(); - -/* - Function: mods_version - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *mods_version(); - -/* - Function: mods_message - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void mods_message(int msg, int client_id); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_msg.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_msg.h deleted file mode 100644 index f83ec4219..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_msg.h +++ /dev/null @@ -1,158 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_MSG_H -#define ENGINE_IF_MSG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Section: Messaging -*/ - -void msg_pack_start_system(int msg, int flags); - -/* - Function: msg_pack_start - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void msg_pack_start(int msg, int flags); - -/* - Function: msg_pack_int - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void msg_pack_int(int i); - -/* - Function: msg_pack_string - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void msg_pack_string(const char *p, int limit); - -/* - Function: msg_pack_raw - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void msg_pack_raw(const void *data, int size); - -/* - Function: msg_pack_end - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void msg_pack_end(); - -typedef struct -{ - int msg; - int flags; - const unsigned char *data; - int size; -} MSG_INFO; - -const MSG_INFO *msg_get_info(); - -/* message unpacking */ -int msg_unpack_start(const void *data, int data_size, int *is_system); - -/* - Function: msg_unpack_int - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int msg_unpack_int(); - -/* - Function: msg_unpack_string - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *msg_unpack_string(); - -/* - Function: msg_unpack_raw - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const unsigned char *msg_unpack_raw(int size); - -/* - Function: msg_unpack_error - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int msg_unpack_error(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_other.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_other.h deleted file mode 100644 index 6d91ecc32..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_other.h +++ /dev/null @@ -1,392 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_OTHER_H -#define ENGINE_IF_OTHER_H - -/* - Title: Engine Interface -*/ - -#include -#include "e_keys.h" - -#ifdef __cplusplus -extern "C" { -#endif - -enum -{ - SERVER_TICK_SPEED=50, - MAX_CLIENTS=16, - - SNAP_CURRENT=0, - SNAP_PREV=1, - - MASK_NONE=0, - MASK_SET, - MASK_ZERO, - - SNDFLAG_LOOP=1, - SNDFLAG_POS=2, - SNDFLAG_ALL=3, - - MAX_NAME_LENGTH=32 -}; - -enum -{ - SRVFLAG_PASSWORD = 0x1, -}; - -/* - Structure: SNAP_ITEM -*/ -typedef struct -{ - int type; - int id; - int datasize; -} SNAP_ITEM; - -/* - Structure: CLIENT_INFO -*/ -typedef struct -{ - const char *name; - int latency; -} CLIENT_INFO; - -typedef struct PERFORMACE_INFO_t -{ - const char *name; - struct PERFORMACE_INFO_t *parent; - struct PERFORMACE_INFO_t *first_child; - struct PERFORMACE_INFO_t *next_child; - int tick; - int64 start; - int64 total; - int64 biggest; - int64 last_delta; -} PERFORMACE_INFO; - -void perf_init(); -void perf_next(); -void perf_start(PERFORMACE_INFO *info); -void perf_end(); -void perf_dump(PERFORMACE_INFO *top); - -int gfx_init(); -void gfx_shutdown(); -void gfx_swap(); -int gfx_window_active(); -int gfx_window_open(); - -void gfx_set_vsync(int val); - -int snd_init(); -int snd_shutdown(); -int snd_update(); - -int map_load(const char *mapname); -void map_unload(); - -void map_set(void *m); - -/* -#include "e_if_client.h" -#include "e_if_server.h" -#include "e_if_snd.h" -#include "e_if_gfx.h" -#include "e_if_inp.h" -#include "e_if_msg.h" -#include "e_if_mod.h"*/ - -/* - Section: Map -*/ - -/* - Function: map_is_loaded - Checks if a map is loaded. - - Returns: - Returns 1 if the button is pressed, otherwise 0. -*/ -int map_is_loaded(); - -/* - Function: map_num_items - Checks the number of items in the loaded map. - - Returns: - Returns the number of items. 0 if no map is loaded. -*/ -int map_num_items(); - -/* - Function: map_find_item - Searches the map for an item. - - Arguments: - type - Item type. - id - Item ID. - - Returns: - Returns a pointer to the item if it exists, otherwise it returns NULL. -*/ -void *map_find_item(int type, int id); - -/* - Function: map_get_item - Gets an item from the loaded map from index. - - Arguments: - index - Item index. - type - Pointer that recives the item type (can be NULL). - id - Pointer that recives the item id (can be NULL). - - Returns: - Returns a pointer to the item if it exists, otherwise it returns NULL. -*/ -void *map_get_item(int index, int *type, int *id); - -/* - Function: map_get_type - Gets the index range of an item type. - - Arguments: - type - Item type to search for. - start - Pointer that recives the starting index. - num - Pointer that recives the number of items. - - Returns: - If the item type is not in the map, start and num will be set to 0. -*/ -void map_get_type(int type, int *start, int *num); - -/* - Function: map_get_data - Fetches a pointer to a raw data chunk in the map. - - Arguments: - index - Index to the data to fetch. - - Returns: - A pointer to the raw data, otherwise 0. -*/ -void *map_get_data(int index); - -/* - Function: map_get_data_swapped - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void *map_get_data_swapped(int index); - -/* - Section: Network (Server) -*/ -/* - Function: snap_new_item - Creates a new item that should be sent. - - Arguments: - type - Type of the item. - id - ID of the item. - size - Size of the item. - - Returns: - A pointer to the item data, otherwise 0. - - Remarks: - The item data should only consist pf 4 byte integers as - they are subject to byte swapping. This means that the size - argument should be dividable by 4. -*/ -void *snap_new_item(int type, int id, int size); - -/* - Section:Section: Network (Client) -*/ -/* - Function: snap_num_items - Check the number of items in a snapshot. - - Arguments: - snapid - Snapshot ID to the data to fetch. - * SNAP_PREV for previous snapshot. - * SNAP_CUR for current snapshot. - - Returns: - The number of items in the snapshot. -*/ -int snap_num_items(int snapid); - -/* - Function: snap_get_item - Gets an item from a snapshot. - - Arguments: - snapid - Snapshot ID to the data to fetch. - * SNAP_PREV for previous snapshot. - * SNAP_CUR for current snapshot. - index - Index of the item. - item - Pointer that recives the item info. - - Returns: - Returns a pointer to the item if it exists, otherwise NULL. -*/ -void *snap_get_item(int snapid, int index, SNAP_ITEM *item); - -/* - Function: snap_find_item - Searches a snapshot for an item. - - Arguments: - snapid - Snapshot ID to the data to fetch. - * SNAP_PREV for previous snapshot. - * SNAP_CUR for current snapshot. - type - Type of the item. - id - ID of the item. - - Returns: - Returns a pointer to the item if it exists, otherwise NULL. -*/ -void *snap_find_item(int snapid, int type, int id); - -/* - Function: snap_invalidate_item - Marks an item as invalid byt setting type and id to 0xffffffff. - - Arguments: - snapid - Snapshot ID to the data to fetch. - * SNAP_PREV for previous snapshot. - * SNAP_CUR for current snapshot. - index - Index of the item. -*/ -void snap_invalidate_item(int snapid, int index); - -/* - Function: snap_input - Sets the input data to send to the server. - - Arguments: - data - Pointer to the data. - size - Size of the data. - - Remarks: - The data should only consist of 4 bytes integer as they are - subject to byte swapping. -*/ -void snap_input(void *data, int size); - -/* - Function: snap_set_staticsize - Tells the engine how big a specific item always will be. This - helps the engine to compress snapshots better. - - Arguments: - type - Item type - size - Size of the data. - - Remarks: - Size must be in a multiple of 4. -*/ -void snap_set_staticsize(int type, int size); - -/* message packing */ -enum -{ - MSGFLAG_VITAL=1, - MSGFLAG_FLUSH=2, - MSGFLAG_NORECORD=4, - MSGFLAG_RECORD=8, - MSGFLAG_NOSEND=16 -}; - -/* message sending */ -/* - Function: server_send_msg - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int server_send_msg(int client_id); /* client_id == -1 == broadcast */ - -/* - Function: client_send_msg - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int client_send_msg(); -/* undocumented graphics stuff */ - -/* server snap id */ -/* - Function: snap_new_id - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int snap_new_id(); - -/* - Function: snap_free_id - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void snap_free_id(int id); - -/* other */ -/* - Function: map_unload_data - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void map_unload_data(int index); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_server.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_server.h deleted file mode 100644 index 6940d4f37..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_server.h +++ /dev/null @@ -1,149 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_SERVER_H -#define ENGINE_IF_SERVER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Section: Server Interface -*/ - -/* server */ -/* - Function: server_getclientinfo - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int server_getclientinfo(int client_id, CLIENT_INFO *info); - -/* - Function: server_clientname - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -const char *server_clientname(int client_id); - -/* grabs the latest input for the client. not withholding anything */ - -/* - Function: server_latestinput - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int *server_latestinput(int client_id, int *size); - -/* - Function: server_setclientname - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void server_setclientname(int client_id, const char *name); - -/* - Function: server_setclientscore - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void server_setclientscore(int client_id, int score); - -/* - Function: server_setbrowseinfo - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void server_setbrowseinfo(const char *game_type, int progression); - -/* - Function: server_kick - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -void server_kick(int client_id, const char *reason); - -/* - Function: server_tick - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int server_tick(); - -/* - Function: server_tickspeed - TODO - - Arguments: - arg1 - desc - - Returns: - - See Also: - -*/ -int server_tickspeed(); - -int server_ban_add(NETADDR addr, int seconds); -int server_ban_remove(NETADDR addr); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_snd.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_if_snd.h deleted file mode 100644 index e21490500..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_if_snd.h +++ /dev/null @@ -1,99 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_IF_SND_H -#define ENGINE_IF_SND_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Section: Sound -*/ - -/* - Function: snd_set_channel - Sets the parameters for a sound channel. - - Arguments: - cid - Channel ID - vol - Volume for the channel. 0.0 to 1.0. - pan - Panning for the channel. -1.0 is all left. 0.0 is equal distribution. 1.0 is all right. -*/ -void snd_set_channel(int cid, float vol, float pan); - -/* - Function: snd_load_wv - Loads a wavpack compressed sound. - - Arguments: - filename - Filename of the file to load - - Returns: - The id of the loaded sound. -1 on failure. -*/ -int snd_load_wv(const char *filename); - -/* - Function: snd_play_at - Plays a sound at a specified postition. - - Arguments: - cid - Channel id of the channel to use. - sid - Sound id of the sound to play. - flags - TODO - x - TODO - y - TODO - - Returns: - An id to the voice. -1 on failure. - - See Also: - -*/ -int snd_play_at(int cid, int sid, int flags, float x, float y); - -/* - Function: snd_play - Plays a sound. - - Arguments: - Arguments: - cid - Channel id of the channel to use. - sid - Sound id of the sound to play. - flags - TODO - - Returns: - An id to the voice. -1 on failure. - - See Also: - -*/ -int snd_play(int cid, int sid, int flags); - -/* - Function: snd_stop - Stops a currenly playing sound. - - Arguments: - id - The ID of the voice to stop. - - See Also: - -*/ -void snd_stop(int id); - -/* - Function: snd_set_listener_pos - Sets the listener posititon. - - Arguments: - x - TODO - y - TODO -*/ -void snd_set_listener_pos(float x, float y); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.cpp deleted file mode 100644 index e87b395a0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_jobs.h" - -void worker_thread(void *user) -{ - JOBPOOL *pool = (JOBPOOL *)user; - - while(1) - { - JOB *job = 0; - - /* fetch job from queue */ - lock_wait(pool->lock); - if(pool->first_job) - { - job = pool->first_job; - pool->first_job = pool->first_job->next; - if(pool->first_job) - pool->first_job->prev = 0; - else - pool->last_job = 0; - } - lock_release(pool->lock); - - /* do the job if we have one */ - if(job) - { - job->status = JOBSTATUS_RUNNING; - job->result = job->func(job->func_data); - job->status = JOBSTATUS_DONE; - } - else - thread_sleep(10); - } - -} - -int jobs_initpool(JOBPOOL *pool, int num_threads) -{ - int i; - - /* empty the pool */ - mem_zero(pool, sizeof(JOBPOOL)); - pool->lock = lock_create(); - - /* start threads */ - for(i = 0; i < num_threads; i++) - thread_create(worker_thread, pool); - return 0; -} - -int jobs_add(JOBPOOL *pool, JOB *job, JOBFUNC func, void *data) -{ - mem_zero(job, sizeof(JOB)); - job->func = func; - job->func_data = data; - - lock_wait(pool->lock); - - /* add job to queue */ - job->prev = pool->last_job; - if(pool->last_job) - pool->last_job->next = job; - pool->last_job = job; - if(!pool->first_job) - pool->first_job = job; - - lock_release(pool->lock); - return 0; -} - -int jobs_status(JOB *job) -{ - return job->status; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.h deleted file mode 100644 index bcfe2685d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_jobs.h +++ /dev/null @@ -1,42 +0,0 @@ - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef int (*JOBFUNC)(void *data); - -typedef struct JOB -{ - struct JOBPOOL *pool; - struct JOB *prev; - struct JOB *next; - volatile int status; - volatile int result; - JOBFUNC func; - void *func_data; -} JOB; - -typedef struct JOBPOOL -{ - LOCK lock; - JOB *first_job; - JOB *last_job; -} JOBPOOL; - -enum -{ - JOBSTATUS_PENDING=0, - JOBSTATUS_RUNNING, - JOBSTATUS_DONE - /*JOBSTATUS_ABORTING,*/ - /*JOBSTATUS_ABORTED,*/ -}; - -int jobs_initpool(JOBPOOL *pool, int num_threads); -int jobs_add(JOBPOOL *pool, JOB *job, JOBFUNC func, void *data); -int jobs_status(JOB *job); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_keynames.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_keynames.cpp deleted file mode 100644 index fc91888c5..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_keynames.cpp +++ /dev/null @@ -1,525 +0,0 @@ -/* AUTO GENERATED! DO NOT EDIT MANUALLY! */ - -#include -#include "e_if_inp.h" - -static const char key_strings[512][16] = -{ - - "first", - "&1", - "&2", - "&3", - "&4", - "&5", - "&6", - "&7", - "backspace", - "tab", - "&10", - "&11", - "clear", - "return", - "&14", - "&15", - "&16", - "&17", - "&18", - "pause", - "&20", - "&21", - "&22", - "&23", - "&24", - "&25", - "&26", - "escape", - "&28", - "&29", - "&30", - "&31", - "space", - "exclaim", - "quotedbl", - "hash", - "dollar", - "&37", - "ampersand", - "quote", - "leftparen", - "rightparen", - "asterisk", - "plus", - "comma", - "minus", - "period", - "slash", - "0", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "colon", - "semicolon", - "less", - "equals", - "greater", - "question", - "at", - "&65", - "&66", - "&67", - "&68", - "&69", - "&70", - "&71", - "&72", - "&73", - "&74", - "&75", - "&76", - "&77", - "&78", - "&79", - "&80", - "&81", - "&82", - "&83", - "&84", - "&85", - "&86", - "&87", - "&88", - "&89", - "&90", - "leftbracket", - "backslash", - "rightbracket", - "caret", - "underscore", - "backquote", - "a", - "b", - "c", - "d", - "e", - "f", - "g", - "h", - "i", - "j", - "k", - "l", - "m", - "n", - "o", - "p", - "q", - "r", - "s", - "t", - "u", - "v", - "w", - "x", - "y", - "z", - "&123", - "&124", - "&125", - "&126", - "delete", - "&128", - "&129", - "&130", - "&131", - "&132", - "&133", - "&134", - "&135", - "&136", - "&137", - "&138", - "&139", - "&140", - "&141", - "&142", - "&143", - "&144", - "&145", - "&146", - "&147", - "&148", - "&149", - "&150", - "&151", - "&152", - "&153", - "&154", - "&155", - "&156", - "&157", - "&158", - "&159", - "world_0", - "world_1", - "world_2", - "world_3", - "world_4", - "world_5", - "world_6", - "world_7", - "world_8", - "world_9", - "world_10", - "world_11", - "world_12", - "world_13", - "world_14", - "world_15", - "world_16", - "world_17", - "world_18", - "world_19", - "world_20", - "world_21", - "world_22", - "world_23", - "world_24", - "world_25", - "world_26", - "world_27", - "world_28", - "world_29", - "world_30", - "world_31", - "world_32", - "world_33", - "world_34", - "world_35", - "world_36", - "world_37", - "world_38", - "world_39", - "world_40", - "world_41", - "world_42", - "world_43", - "world_44", - "world_45", - "world_46", - "world_47", - "world_48", - "world_49", - "world_50", - "world_51", - "world_52", - "world_53", - "world_54", - "world_55", - "world_56", - "world_57", - "world_58", - "world_59", - "world_60", - "world_61", - "world_62", - "world_63", - "world_64", - "world_65", - "world_66", - "world_67", - "world_68", - "world_69", - "world_70", - "world_71", - "world_72", - "world_73", - "world_74", - "world_75", - "world_76", - "world_77", - "world_78", - "world_79", - "world_80", - "world_81", - "world_82", - "world_83", - "world_84", - "world_85", - "world_86", - "world_87", - "world_88", - "world_89", - "world_90", - "world_91", - "world_92", - "world_93", - "world_94", - "world_95", - "kp0", - "kp1", - "kp2", - "kp3", - "kp4", - "kp5", - "kp6", - "kp7", - "kp8", - "kp9", - "kp_period", - "kp_divide", - "kp_multiply", - "kp_minus", - "kp_plus", - "kp_enter", - "kp_equals", - "up", - "down", - "right", - "left", - "insert", - "home", - "end", - "pageup", - "pagedown", - "f1", - "f2", - "f3", - "f4", - "f5", - "f6", - "f7", - "f8", - "f9", - "f10", - "f11", - "f12", - "f13", - "f14", - "f15", - "&297", - "&298", - "&299", - "numlock", - "capslock", - "scrollock", - "rshift", - "lshift", - "rctrl", - "lctrl", - "ralt", - "lalt", - "rmeta", - "lmeta", - "lsuper", - "rsuper", - "mode", - "compose", - "help", - "print", - "sysreq", - "break", - "menu", - "power", - "euro", - "undo", - "mouse1", - "mouse2", - "mouse3", - "mouse4", - "mouse5", - "mouse6", - "mouse7", - "mouse8", - "mousewheelup", - "mousewheeldown", - "&333", - "&334", - "&335", - "&336", - "&337", - "&338", - "&339", - "&340", - "&341", - "&342", - "&343", - "&344", - "&345", - "&346", - "&347", - "&348", - "&349", - "&350", - "&351", - "&352", - "&353", - "&354", - "&355", - "&356", - "&357", - "&358", - "&359", - "&360", - "&361", - "&362", - "&363", - "&364", - "&365", - "&366", - "&367", - "&368", - "&369", - "&370", - "&371", - "&372", - "&373", - "&374", - "&375", - "&376", - "&377", - "&378", - "&379", - "&380", - "&381", - "&382", - "&383", - "&384", - "&385", - "&386", - "&387", - "&388", - "&389", - "&390", - "&391", - "&392", - "&393", - "&394", - "&395", - "&396", - "&397", - "&398", - "&399", - "&400", - "&401", - "&402", - "&403", - "&404", - "&405", - "&406", - "&407", - "&408", - "&409", - "&410", - "&411", - "&412", - "&413", - "&414", - "&415", - "&416", - "&417", - "&418", - "&419", - "&420", - "&421", - "&422", - "&423", - "&424", - "&425", - "&426", - "&427", - "&428", - "&429", - "&430", - "&431", - "&432", - "&433", - "&434", - "&435", - "&436", - "&437", - "&438", - "&439", - "&440", - "&441", - "&442", - "&443", - "&444", - "&445", - "&446", - "&447", - "&448", - "&449", - "&450", - "&451", - "&452", - "&453", - "&454", - "&455", - "&456", - "&457", - "&458", - "&459", - "&460", - "&461", - "&462", - "&463", - "&464", - "&465", - "&466", - "&467", - "&468", - "&469", - "&470", - "&471", - "&472", - "&473", - "&474", - "&475", - "&476", - "&477", - "&478", - "&479", - "&480", - "&481", - "&482", - "&483", - "&484", - "&485", - "&486", - "&487", - "&488", - "&489", - "&490", - "&491", - "&492", - "&493", - "&494", - "&495", - "&496", - "&497", - "&498", - "&499", - "&500", - "&501", - "&502", - "&503", - "&504", - "&505", - "&506", - "&507", - "&508", - "&509", - "&510", - "&511", -}; - -const char *inp_key_name(int k) { if (k >= 0 && k < 512) return key_strings[k]; else return key_strings[0]; } -int inp_key_code(const char *key_name) { int i; if (!strcmp(key_name, "-?-")) return -1; else for (i = 0; i < 512; i++) if (!strcmp(key_strings[i], key_name)) return i; return -1; } - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_keys.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_keys.h deleted file mode 100644 index cb4ca3716..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_keys.h +++ /dev/null @@ -1,252 +0,0 @@ -#ifndef ENGINE_KEYS_H -#define ENGINE_KEYS_H -/* AUTO GENERATED! DO NOT EDIT MANUALLY! */ -enum -{ - KEY_UNKNOWN = 0, - KEY_FIRST = 0, - KEY_BACKSPACE = 8, - KEY_TAB = 9, - KEY_CLEAR = 12, - KEY_RETURN = 13, - KEY_PAUSE = 19, - KEY_ESCAPE = 27, - KEY_SPACE = 32, - KEY_EXCLAIM = 33, - KEY_QUOTEDBL = 34, - KEY_HASH = 35, - KEY_DOLLAR = 36, - KEY_AMPERSAND = 38, - KEY_QUOTE = 39, - KEY_LEFTPAREN = 40, - KEY_RIGHTPAREN = 41, - KEY_ASTERISK = 42, - KEY_PLUS = 43, - KEY_COMMA = 44, - KEY_MINUS = 45, - KEY_PERIOD = 46, - KEY_SLASH = 47, - KEY_0 = 48, - KEY_1 = 49, - KEY_2 = 50, - KEY_3 = 51, - KEY_4 = 52, - KEY_5 = 53, - KEY_6 = 54, - KEY_7 = 55, - KEY_8 = 56, - KEY_9 = 57, - KEY_COLON = 58, - KEY_SEMICOLON = 59, - KEY_LESS = 60, - KEY_EQUALS = 61, - KEY_GREATER = 62, - KEY_QUESTION = 63, - KEY_AT = 64, - KEY_LEFTBRACKET = 91, - KEY_BACKSLASH = 92, - KEY_RIGHTBRACKET = 93, - KEY_CARET = 94, - KEY_UNDERSCORE = 95, - KEY_BACKQUOTE = 96, - KEY_a = 97, - KEY_b = 98, - KEY_c = 99, - KEY_d = 100, - KEY_e = 101, - KEY_f = 102, - KEY_g = 103, - KEY_h = 104, - KEY_i = 105, - KEY_j = 106, - KEY_k = 107, - KEY_l = 108, - KEY_m = 109, - KEY_n = 110, - KEY_o = 111, - KEY_p = 112, - KEY_q = 113, - KEY_r = 114, - KEY_s = 115, - KEY_t = 116, - KEY_u = 117, - KEY_v = 118, - KEY_w = 119, - KEY_x = 120, - KEY_y = 121, - KEY_z = 122, - KEY_DELETE = 127, - KEY_WORLD_0 = 160, - KEY_WORLD_1 = 161, - KEY_WORLD_2 = 162, - KEY_WORLD_3 = 163, - KEY_WORLD_4 = 164, - KEY_WORLD_5 = 165, - KEY_WORLD_6 = 166, - KEY_WORLD_7 = 167, - KEY_WORLD_8 = 168, - KEY_WORLD_9 = 169, - KEY_WORLD_10 = 170, - KEY_WORLD_11 = 171, - KEY_WORLD_12 = 172, - KEY_WORLD_13 = 173, - KEY_WORLD_14 = 174, - KEY_WORLD_15 = 175, - KEY_WORLD_16 = 176, - KEY_WORLD_17 = 177, - KEY_WORLD_18 = 178, - KEY_WORLD_19 = 179, - KEY_WORLD_20 = 180, - KEY_WORLD_21 = 181, - KEY_WORLD_22 = 182, - KEY_WORLD_23 = 183, - KEY_WORLD_24 = 184, - KEY_WORLD_25 = 185, - KEY_WORLD_26 = 186, - KEY_WORLD_27 = 187, - KEY_WORLD_28 = 188, - KEY_WORLD_29 = 189, - KEY_WORLD_30 = 190, - KEY_WORLD_31 = 191, - KEY_WORLD_32 = 192, - KEY_WORLD_33 = 193, - KEY_WORLD_34 = 194, - KEY_WORLD_35 = 195, - KEY_WORLD_36 = 196, - KEY_WORLD_37 = 197, - KEY_WORLD_38 = 198, - KEY_WORLD_39 = 199, - KEY_WORLD_40 = 200, - KEY_WORLD_41 = 201, - KEY_WORLD_42 = 202, - KEY_WORLD_43 = 203, - KEY_WORLD_44 = 204, - KEY_WORLD_45 = 205, - KEY_WORLD_46 = 206, - KEY_WORLD_47 = 207, - KEY_WORLD_48 = 208, - KEY_WORLD_49 = 209, - KEY_WORLD_50 = 210, - KEY_WORLD_51 = 211, - KEY_WORLD_52 = 212, - KEY_WORLD_53 = 213, - KEY_WORLD_54 = 214, - KEY_WORLD_55 = 215, - KEY_WORLD_56 = 216, - KEY_WORLD_57 = 217, - KEY_WORLD_58 = 218, - KEY_WORLD_59 = 219, - KEY_WORLD_60 = 220, - KEY_WORLD_61 = 221, - KEY_WORLD_62 = 222, - KEY_WORLD_63 = 223, - KEY_WORLD_64 = 224, - KEY_WORLD_65 = 225, - KEY_WORLD_66 = 226, - KEY_WORLD_67 = 227, - KEY_WORLD_68 = 228, - KEY_WORLD_69 = 229, - KEY_WORLD_70 = 230, - KEY_WORLD_71 = 231, - KEY_WORLD_72 = 232, - KEY_WORLD_73 = 233, - KEY_WORLD_74 = 234, - KEY_WORLD_75 = 235, - KEY_WORLD_76 = 236, - KEY_WORLD_77 = 237, - KEY_WORLD_78 = 238, - KEY_WORLD_79 = 239, - KEY_WORLD_80 = 240, - KEY_WORLD_81 = 241, - KEY_WORLD_82 = 242, - KEY_WORLD_83 = 243, - KEY_WORLD_84 = 244, - KEY_WORLD_85 = 245, - KEY_WORLD_86 = 246, - KEY_WORLD_87 = 247, - KEY_WORLD_88 = 248, - KEY_WORLD_89 = 249, - KEY_WORLD_90 = 250, - KEY_WORLD_91 = 251, - KEY_WORLD_92 = 252, - KEY_WORLD_93 = 253, - KEY_WORLD_94 = 254, - KEY_WORLD_95 = 255, - KEY_KP0 = 256, - KEY_KP1 = 257, - KEY_KP2 = 258, - KEY_KP3 = 259, - KEY_KP4 = 260, - KEY_KP5 = 261, - KEY_KP6 = 262, - KEY_KP7 = 263, - KEY_KP8 = 264, - KEY_KP9 = 265, - KEY_KP_PERIOD = 266, - KEY_KP_DIVIDE = 267, - KEY_KP_MULTIPLY = 268, - KEY_KP_MINUS = 269, - KEY_KP_PLUS = 270, - KEY_KP_ENTER = 271, - KEY_KP_EQUALS = 272, - KEY_UP = 273, - KEY_DOWN = 274, - KEY_RIGHT = 275, - KEY_LEFT = 276, - KEY_INSERT = 277, - KEY_HOME = 278, - KEY_END = 279, - KEY_PAGEUP = 280, - KEY_PAGEDOWN = 281, - KEY_F1 = 282, - KEY_F2 = 283, - KEY_F3 = 284, - KEY_F4 = 285, - KEY_F5 = 286, - KEY_F6 = 287, - KEY_F7 = 288, - KEY_F8 = 289, - KEY_F9 = 290, - KEY_F10 = 291, - KEY_F11 = 292, - KEY_F12 = 293, - KEY_F13 = 294, - KEY_F14 = 295, - KEY_F15 = 296, - KEY_NUMLOCK = 300, - KEY_CAPSLOCK = 301, - KEY_SCROLLOCK = 302, - KEY_RSHIFT = 303, - KEY_LSHIFT = 304, - KEY_RCTRL = 305, - KEY_LCTRL = 306, - KEY_RALT = 307, - KEY_LALT = 308, - KEY_RMETA = 309, - KEY_LMETA = 310, - KEY_LSUPER = 311, - KEY_RSUPER = 312, - KEY_MODE = 313, - KEY_COMPOSE = 314, - KEY_HELP = 315, - KEY_PRINT = 316, - KEY_SYSREQ = 317, - KEY_BREAK = 318, - KEY_MENU = 319, - KEY_POWER = 320, - KEY_EURO = 321, - KEY_UNDO = 322, - KEY_MOUSE_1 = 323, - KEY_MOUSE_2 = 324, - KEY_MOUSE_3 = 325, - KEY_MOUSE_4 = 326, - KEY_MOUSE_5 = 327, - KEY_MOUSE_6 = 328, - KEY_MOUSE_7 = 329, - KEY_MOUSE_8 = 330, - KEY_MOUSE_WHEEL_UP = 331, - KEY_MOUSE_WHEEL_DOWN = 332, - KEY_LAST, -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.cpp deleted file mode 100644 index 57ba9a856..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "e_linereader.h" - -void linereader_init(LINEREADER *lr, IOHANDLE io) -{ - lr->buffer_max_size = 4*1024; - lr->buffer_size = 0; - lr->buffer_pos = 0; - lr->io = io; -} - -char *linereader_get(LINEREADER *lr) -{ - unsigned line_start = lr->buffer_pos; - - while(1) - { - if(lr->buffer_pos >= lr->buffer_size) - { - /* fetch more */ - - /* move the remaining part to the front */ - unsigned read; - unsigned left = lr->buffer_size - line_start; - - if(line_start > lr->buffer_size) - left = 0; - if(left) - mem_move(lr->buffer, &lr->buffer[line_start], left); - lr->buffer_pos = left; - - /* fill the buffer */ - read = io_read(lr->io, &lr->buffer[lr->buffer_pos], lr->buffer_max_size-lr->buffer_pos); - lr->buffer_size = left + read; - line_start = 0; - - if(!read) - { - if(left) - { - lr->buffer[left] = 0; /* return the last line */ - lr->buffer_pos = left; - lr->buffer_size = left; - return lr->buffer; - } - else - return 0x0; /* we are done! */ - } - } - else - { - if(lr->buffer[lr->buffer_pos] == '\n' || lr->buffer[lr->buffer_pos] == '\r') - { - /* line found */ - lr->buffer[lr->buffer_pos] = 0; - lr->buffer_pos++; - return &lr->buffer[line_start]; - } - else - lr->buffer_pos++; - } - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.h deleted file mode 100644 index 434a5f888..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_linereader.h +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* buffered stream for reading lines, should perhaps be something smaller */ -typedef struct -{ - char buffer[4*1024]; - unsigned buffer_pos; - unsigned buffer_size; - unsigned buffer_max_size; - IOHANDLE io; -} LINEREADER; - -void linereader_init(LINEREADER *lr, IOHANDLE io); -char *linereader_get(LINEREADER *lr); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_map.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_map.cpp deleted file mode 100644 index 445a95a37..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_map.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_datafile.h" -#include "e_if_other.h" - -static DATAFILE *map = 0; - -void *map_get_data(int index) -{ - return datafile_get_data(map, index); -} - -void *map_get_data_swapped(int index) -{ - return datafile_get_data_swapped(map, index); -} - -void map_unload_data(int index) -{ - datafile_unload_data(map, index); -} - -void *map_get_item(int index, int *type, int *id) -{ - return datafile_get_item(map, index, type, id); -} - -void map_get_type(int type, int *start, int *num) -{ - datafile_get_type(map, type, start, num); -} - -void *map_find_item(int type, int id) -{ - return datafile_find_item(map, type, id); -} - -int map_num_items() -{ - return datafile_num_items(map); -} - -void map_unload() -{ - datafile_unload(map); - map = 0x0; -} - -int map_is_loaded() -{ - return map != 0; -} - -int map_load(const char *mapname) -{ - char buf[512]; - str_format(buf, sizeof(buf), "maps/%s.map", mapname); - map = datafile_load(buf); - return map != 0; -} - -void map_set(void *m) -{ - if(map) - map_unload(); - map = (DATAFILE*)m; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.cpp deleted file mode 100644 index 652b9d7d5..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_memheap.h" - -typedef struct CHUNK_t -{ - char *memory; - char *current; - char *end; - struct CHUNK_t *next; -} CHUNK; - -typedef struct HEAP_t -{ - CHUNK *current; -} HEAP; - -/* how large each chunk should be */ -static const int chunksize = 1024*64; - -/* allocates a new chunk to be used */ -static CHUNK *memheap_newchunk() -{ - CHUNK *chunk; - char *mem; - - /* allocate memory */ - mem = (char*)mem_alloc(sizeof(CHUNK)+chunksize, 1); - if(!mem) - return 0x0; - - /* the chunk structure is located in the begining of the chunk */ - /* init it and return the chunk */ - chunk = (CHUNK*)mem; - chunk->memory = (char*)(chunk+1); - chunk->current = chunk->memory; - chunk->end = chunk->memory + chunksize; - chunk->next = (CHUNK *)0x0; - return chunk; -} - -/******************/ -static void *memheap_allocate_from_chunk(CHUNK *chunk, unsigned int size) -{ - char *mem; - - /* check if we need can fit the allocation */ - if(chunk->current + size > chunk->end) - return (void*)0x0; - - /* get memory and move the pointer forward */ - mem = chunk->current; - chunk->current += size; - return mem; -} - -/* creates a heap */ -HEAP *memheap_create() -{ - CHUNK *chunk; - HEAP *heap; - - /* allocate a chunk and allocate the heap structure on that chunk */ - chunk = memheap_newchunk(); - heap = (HEAP *)memheap_allocate_from_chunk(chunk, sizeof(HEAP)); - heap->current = chunk; - return heap; -} - -/* destroys the heap */ -void memheap_destroy(HEAP *heap) -{ - CHUNK *chunk = heap->current; - CHUNK *next; - - while(chunk) - { - next = chunk->next; - mem_free(chunk); - chunk = next; - } -} - -/* */ -void *memheap_allocate(HEAP *heap, unsigned int size) -{ - char *mem; - - /* try to allocate from current chunk */ - mem = (char *)memheap_allocate_from_chunk(heap->current, size); - if(!mem) - { - /* allocate new chunk and add it to the heap */ - CHUNK *chunk = memheap_newchunk(); - chunk->next = heap->current; - heap->current = chunk; - - /* try to allocate again */ - mem = (char *)memheap_allocate_from_chunk(heap->current, size); - } - - return mem; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.h deleted file mode 100644 index bba0c66e8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_memheap.h +++ /dev/null @@ -1,14 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct HEAP_t HEAP; -HEAP *memheap_create(); -void memheap_destroy(HEAP *heap); -void *memheap_allocate(HEAP *heap, unsigned int size); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_msg.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_msg.cpp deleted file mode 100644 index f9efc2bfe..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_msg.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include "e_common_interface.h" -#include "e_packer.h" - -/* message packing */ -static PACKER msg_packer; -static MSG_INFO pack_info; -static int packer_failed = 0; - -void msg_pack_int(int i) { packer_add_int(&msg_packer, i); } -void msg_pack_string(const char *p, int limit) { packer_add_string(&msg_packer, p, limit); } -void msg_pack_raw(const void *data, int size) { packer_add_raw(&msg_packer, (const unsigned char *)data, size); } - -void msg_pack_start_system(int msg, int flags) -{ - packer_reset(&msg_packer); - pack_info.msg = (msg<<1)|1; - pack_info.flags = flags; - packer_failed = 0; - - msg_pack_int(pack_info.msg); -} - -void msg_pack_start(int msg, int flags) -{ - packer_reset(&msg_packer); - pack_info.msg = msg<<1; - pack_info.flags = flags; - packer_failed = 0; - - msg_pack_int(pack_info.msg); -} - -void msg_pack_end() -{ - if(msg_packer.error) - { - packer_failed = 1; - pack_info.size = 0; - pack_info.data = (unsigned char *)""; - } - else - { - pack_info.size = packer_size(&msg_packer); - pack_info.data = packer_data(&msg_packer); - } -} - -const MSG_INFO *msg_get_info() -{ - if(packer_failed) - return 0; - return &pack_info; -} - -/* message unpacking */ -static UNPACKER msg_unpacker; -int msg_unpack_start(const void *data, int data_size, int *system) -{ - int msg; - unpacker_reset(&msg_unpacker, (const unsigned char *)data, data_size); - msg = msg_unpack_int(); - *system = msg&1; - return msg>>1; -} - -int msg_unpack_int() { return unpacker_get_int(&msg_unpacker); } -const char *msg_unpack_string() { return unpacker_get_string(&msg_unpacker); } -const unsigned char *msg_unpack_raw(int size) { return unpacker_get_raw(&msg_unpacker, size); } -int msg_unpack_error() { return msg_unpacker.error; } diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_network.cpp deleted file mode 100644 index c7aabc99a..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include - -#include /* strlen */ - -#include "e_config.h" -#include "e_engine.h" -#include "e_network.h" -#include "e_network_internal.h" -#include "e_huffman.h" - -void recvinfo_clear(NETRECVINFO *info) -{ - info->valid = 0; -} - -void recvinfo_start(NETRECVINFO *info, NETADDR *addr, NETCONNECTION *conn, int cid) -{ - info->addr = *addr; - info->conn = conn; - info->client_id = cid; - info->current_chunk = 0; - info->valid = 1; -} - - -int seq_in_backroom(int seq, int ack) -{ - int bottom = (ack-NET_MAX_SEQUENCE/2); - if(bottom < 0) - { - if(seq <= ack) - return 1; - if(seq >= (bottom + NET_MAX_SEQUENCE)) - return 1; - } - else - { - if(seq <= ack && seq >= bottom) - return 1; - } - - return 0; -} - -/* TODO: rename this function */ -int recvinfo_fetch_chunk(NETRECVINFO *info, NETCHUNK *chunk) -{ - NETCHUNKHEADER header; - unsigned char *end = info->data.chunk_data + info->data.data_size; - int i; - - while(1) - { - unsigned char *data = info->data.chunk_data; - - /* check for old data to unpack */ - if(!info->valid || info->current_chunk >= info->data.num_chunks) - { - recvinfo_clear(info); - return 0; - } - - /* TODO: add checking here so we don't read too far */ - for(i = 0; i < info->current_chunk; i++) - { - data = unpack_chunk_header(data, &header); - data += header.size; - } - - /* unpack the header */ - data = unpack_chunk_header(data, &header); - info->current_chunk++; - - if(data+header.size > end) - { - recvinfo_clear(info); - return 0; - } - - /* handle sequence stuff */ - if(info->conn && (header.flags&NET_CHUNKFLAG_VITAL)) - { - if(header.sequence == (info->conn->ack+1)%NET_MAX_SEQUENCE) - { - /* in sequence */ - info->conn->ack = (info->conn->ack+1)%NET_MAX_SEQUENCE; - } - else - { - /* old packet that we already got */ - if(seq_in_backroom(header.sequence, info->conn->ack)) - continue; - - /* out of sequence, request resend */ - if(config.debug) - dbg_msg("conn", "asking for resend %d %d", header.sequence, (info->conn->ack+1)%NET_MAX_SEQUENCE); - conn_want_resend(info->conn); - continue; /* take the next chunk in the packet */ - } - } - - /* fill in the info */ - chunk->client_id = info->client_id; - chunk->address = info->addr; - chunk->flags = 0; - chunk->data_size = header.size; - chunk->data = data; - return 1; - } -} - - -static IOHANDLE datalog_sent = 0; -static IOHANDLE datalog_recv = 0; -static HUFFMAN_STATE huffmanstate; - -#define COMPRESSION 1 - -/* packs the data tight and sends it */ -void send_packet_connless(NETSOCKET socket, NETADDR *addr, const void *data, int data_size) -{ - unsigned char buffer[NET_MAX_PACKETSIZE]; - buffer[0] = 0xff; - buffer[1] = 0xff; - buffer[2] = 0xff; - buffer[3] = 0xff; - buffer[4] = 0xff; - buffer[5] = 0xff; - mem_copy(&buffer[6], data, data_size); - net_udp_send(socket, addr, buffer, 6+data_size); -} - -int netcommon_compress(const void *data, int data_size, void *output, int output_size) -{ - return huffman_compress(&huffmanstate, data, data_size, output, output_size); -} - -int netcommon_decompress(const void *data, int data_size, void *output, int output_size) -{ - return huffman_decompress(&huffmanstate, data, data_size, output, output_size); -} - -void send_packet(NETSOCKET socket, NETADDR *addr, NETPACKETCONSTRUCT *packet) -{ - unsigned char buffer[NET_MAX_PACKETSIZE]; - int compressed_size = -1; - int final_size = -1; - - /* log the data */ - if(datalog_sent) - { - int type = 1; - io_write(datalog_sent, &type, sizeof(type)); - io_write(datalog_sent, &packet->data_size, sizeof(packet->data_size)); - io_write(datalog_sent, &packet->chunk_data, packet->data_size); - io_flush(datalog_sent); - } - - /* compress if its enabled */ - if(COMPRESSION) - compressed_size = huffman_compress(&huffmanstate, packet->chunk_data, packet->data_size, &buffer[3], NET_MAX_PACKETSIZE-4); - - /* check if the compression was enabled, successful and good enough */ - if(compressed_size > 0 && compressed_size < packet->data_size) - { - final_size = compressed_size; - packet->flags |= NET_PACKETFLAG_COMPRESSION; - } - else - { - /* use uncompressed data */ - final_size = packet->data_size; - mem_copy(&buffer[3], packet->chunk_data, packet->data_size); - packet->flags &= ~NET_PACKETFLAG_COMPRESSION; - } - - /* set header and send the packet if all things are good */ - if(final_size >= 0) - { - final_size += NET_PACKETHEADERSIZE; - buffer[0] = ((packet->flags<<4)&0xf0)|((packet->ack>>8)&0xf); - buffer[1] = packet->ack&0xff; - buffer[2] = packet->num_chunks; - net_udp_send(socket, addr, buffer, final_size); - - /* log raw socket data */ - if(datalog_sent) - { - int type = 0; - io_write(datalog_sent, &type, sizeof(type)); - io_write(datalog_sent, &final_size, sizeof(final_size)); - io_write(datalog_sent, buffer, final_size); - io_flush(datalog_sent); - } - } -} - -/* TODO: rename this function */ -int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *packet) -{ - /* check the size */ - if(size < NET_PACKETHEADERSIZE || size > NET_MAX_PACKETSIZE) - { - dbg_msg("", "packet too small, %d", size); - return -1; - } - - /* log the data */ - if(datalog_recv) - { - int type = 0; - io_write(datalog_recv, &type, sizeof(type)); - io_write(datalog_recv, &size, sizeof(size)); - io_write(datalog_recv, buffer, size); - io_flush(datalog_recv); - } - - /* read the packet */ - packet->flags = buffer[0]>>4; - packet->ack = ((buffer[0]&0xf)<<8) | buffer[1]; - packet->num_chunks = buffer[2]; - packet->data_size = size - NET_PACKETHEADERSIZE; - - if(packet->flags&NET_PACKETFLAG_CONNLESS) - { - packet->flags = NET_PACKETFLAG_CONNLESS; - packet->ack = 0; - packet->num_chunks = 0; - packet->data_size = size - 6; - mem_copy(packet->chunk_data, &buffer[6], packet->data_size); - } - else - { - if(packet->flags&NET_PACKETFLAG_COMPRESSION) - packet->data_size = huffman_decompress(&huffmanstate, &buffer[3], packet->data_size, packet->chunk_data, sizeof(packet->chunk_data)); - else - mem_copy(packet->chunk_data, &buffer[3], packet->data_size); - } - - /* check for errors */ - if(packet->data_size < 0) - { - if(config.debug) - dbg_msg("network", "error during packet decoding"); - return -1; - } - - /* log the data */ - if(datalog_recv) - { - int type = 1; - io_write(datalog_recv, &type, sizeof(type)); - io_write(datalog_recv, &packet->data_size, sizeof(packet->data_size)); - io_write(datalog_recv, packet->chunk_data, packet->data_size); - io_flush(datalog_recv); - } - - /* return success */ - return 0; -} - - -/* TODO: change the arguments of this function */ -unsigned char *pack_chunk_header(unsigned char *data, int flags, int size, int sequence) -{ - data[0] = ((flags&3)<<6)|((size>>4)&0x3f); - data[1] = (size&0xf); - if(flags&NET_CHUNKFLAG_VITAL) - { - data[1] |= (sequence>>2)&0xf0; - data[2] = sequence&0xff; - return data + 3; - } - return data + 2; -} - -unsigned char *unpack_chunk_header(unsigned char *data, NETCHUNKHEADER *header) -{ - header->flags = (data[0]>>6)&3; - header->size = ((data[0]&0x3f)<<4) | (data[1]&0xf); - header->sequence = -1; - if(header->flags&NET_CHUNKFLAG_VITAL) - { - header->sequence = ((data[1]&0xf0)<<2) | data[2]; - return data + 3; - } - return data + 2; -} - - -void send_controlmsg(NETSOCKET socket, NETADDR *addr, int ack, int controlmsg, const void *extra, int extra_size) -{ - NETPACKETCONSTRUCT construct; - construct.flags = NET_PACKETFLAG_CONTROL; - construct.ack = ack; - construct.num_chunks = 0; - construct.data_size = 1+extra_size; - construct.chunk_data[0] = controlmsg; - mem_copy(&construct.chunk_data[1], extra, extra_size); - - /* send the control message */ - send_packet(socket, addr, &construct); -} - -void netcommon_openlog(const char *sentlog, const char *recvlog) -{ - if(sentlog) - { - datalog_sent = engine_openfile(sentlog, IOFLAG_WRITE); - if(datalog_sent) - dbg_msg("network", "logging sent packages to '%s'", sentlog); - else - dbg_msg("network", "failed to open for logging '%s'", sentlog); - } - - if(recvlog) - { - datalog_recv = engine_openfile(recvlog, IOFLAG_WRITE); - if(recvlog) - dbg_msg("network", "logging recv packages to '%s'", recvlog); - else - dbg_msg("network", "failed to open for logging '%s'", recvlog); - } -} - -static const unsigned freq_table[256+1] = { - 1<<30,4545,2657,431,1950,919,444,482,2244,617,838,542,715,1814,304,240,754,212,647,186, - 283,131,146,166,543,164,167,136,179,859,363,113,157,154,204,108,137,180,202,176, - 872,404,168,134,151,111,113,109,120,126,129,100,41,20,16,22,18,18,17,19, - 16,37,13,21,362,166,99,78,95,88,81,70,83,284,91,187,77,68,52,68, - 59,66,61,638,71,157,50,46,69,43,11,24,13,19,10,12,12,20,14,9, - 20,20,10,10,15,15,12,12,7,19,15,14,13,18,35,19,17,14,8,5, - 15,17,9,15,14,18,8,10,2173,134,157,68,188,60,170,60,194,62,175,71, - 148,67,167,78,211,67,156,69,1674,90,174,53,147,89,181,51,174,63,163,80, - 167,94,128,122,223,153,218,77,200,110,190,73,174,69,145,66,277,143,141,60, - 136,53,180,57,142,57,158,61,166,112,152,92,26,22,21,28,20,26,30,21, - 32,27,20,17,23,21,30,22,22,21,27,25,17,27,23,18,39,26,15,21, - 12,18,18,27,20,18,15,19,11,17,33,12,18,15,19,18,16,26,17,18, - 9,10,25,22,22,17,20,16,6,16,15,20,14,18,24,335,1517}; - -void netcommon_init() -{ - huffman_init(&huffmanstate, freq_table); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_network.h deleted file mode 100644 index fa556749b..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef ENGINE_NETWORK_H -#define ENGINE_NETWORK_H -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef struct -{ - /* -1 means that it's a stateless packet */ - /* 0 on the client means the server */ - int client_id; - NETADDR address; /* only used when client_id == -1 */ - int flags; - int data_size; - const void *data; -} NETCHUNK; - - -typedef struct -{ - NETADDR addr; - int expires; -} NETBANINFO; - -/*typedef struct -{ - int send_bytes; - int recv_bytes; - int send_packets; - int recv_packets; - - int resend_packets; - int resend_bytes; -} NETSTATS;*/ - -typedef struct NETSERVER NETSERVER; -typedef struct NETCLIENT NETCLIENT; - -enum -{ - NETFLAG_ALLOWSTATELESS=1, - NETSENDFLAG_VITAL=1, - NETSENDFLAG_CONNLESS=2, - NETSENDFLAG_FLUSH=4, - - NETSTATE_OFFLINE=0, - NETSTATE_CONNECTING, - NETSTATE_ONLINE, - - NETBANTYPE_SOFT=1, - NETBANTYPE_DROP=2 -}; - -typedef int (*NETFUNC_DELCLIENT)(int cid, void *user); -typedef int (*NETFUNC_NEWCLIENT)(int cid, void *user); - -/* both */ -void netcommon_openlog(const char *sentlog, const char *recvlog); -void netcommon_init(); -int netcommon_compress(const void *data, int data_size, void *output, int output_size); -int netcommon_decompress(const void *data, int data_size, void *output, int output_size); - -/* server side */ -NETSERVER *netserver_open(NETADDR bindaddr, int max_clients, int flags); -int netserver_set_callbacks(NETSERVER *s, NETFUNC_NEWCLIENT new_client, NETFUNC_DELCLIENT del_client, void *user); -int netserver_recv(NETSERVER *s, NETCHUNK *chunk); -int netserver_send(NETSERVER *s, NETCHUNK *chunk); -int netserver_close(NETSERVER *s); -int netserver_update(NETSERVER *s); -NETSOCKET netserver_socket(NETSERVER *s); -int netserver_drop(NETSERVER *s, int client_id, const char *reason); -int netserver_client_addr(NETSERVER *s, int client_id, NETADDR *addr); -int netserver_max_clients(NETSERVER *s); - -int netserver_ban_add(NETSERVER *s, NETADDR addr, int seconds); -int netserver_ban_remove(NETSERVER *s, NETADDR addr); -int netserver_ban_num(NETSERVER *s); /* caution, slow */ -int netserver_ban_get(NETSERVER *s, int index, NETBANINFO *info); /* caution, slow */ - -/*void netserver_stats(NETSERVER *s, NETSTATS *stats);*/ - -/* client side */ -NETCLIENT *netclient_open(NETADDR bindaddr, int flags); -int netclient_disconnect(NETCLIENT *c, const char *reason); -int netclient_connect(NETCLIENT *c, NETADDR *addr); -int netclient_recv(NETCLIENT *c, NETCHUNK *chunk); -int netclient_send(NETCLIENT *c, NETCHUNK *chunk); -int netclient_close(NETCLIENT *c); -int netclient_update(NETCLIENT *c); -int netclient_state(NETCLIENT *c); -int netclient_flush(NETCLIENT *c); -int netclient_gotproblems(NETCLIENT *c); -/*void netclient_stats(NETCLIENT *c, NETSTATS *stats);*/ -int netclient_error_string_reset(NETCLIENT *c); -const char *netclient_error_string(NETCLIENT *c); - -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -class net_server -{ - NETSERVER *ptr; -public: - net_server() : ptr(0) {} - ~net_server() { close(); } - - int open(NETADDR bindaddr, int max, int flags) { ptr = netserver_open(bindaddr, max, flags); return ptr != 0; } - int close() { int r = netserver_close(ptr); ptr = 0; return r; } - - int set_callbacks(NETFUNC_NEWCLIENT new_client, NETFUNC_DELCLIENT del_client, void *user) - { return netserver_set_callbacks(ptr, new_client, del_client, user); } - - int recv(NETCHUNK *chunk) { return netserver_recv(ptr, chunk); } - int send(NETCHUNK *chunk) { return netserver_send(ptr, chunk); } - int update() { return netserver_update(ptr); } - - int drop(int client_id, const char *reason) { return netserver_drop(ptr, client_id, reason); } - - int max_clients() { return netserver_max_clients(ptr); } - /*void stats(NETSTATS *stats) { netserver_stats(ptr, stats); }*/ -}; - - -class net_client -{ - NETCLIENT *ptr; -public: - net_client() : ptr(0) {} - ~net_client() { close(); } - - int open(NETADDR bindaddr, int flags) { ptr = netclient_open(bindaddr, flags); return ptr != 0; } - int close() { int r = netclient_close(ptr); ptr = 0; return r; } - - int connect(NETADDR *addr) { return netclient_connect(ptr, addr); } - int disconnect(const char *reason) { return netclient_disconnect(ptr, reason); } - - int recv(NETCHUNK *chunk) { return netclient_recv(ptr, chunk); } - int send(NETCHUNK *chunk) { return netclient_send(ptr, chunk); } - int update() { return netclient_update(ptr); } - - const char *error_string() { return netclient_error_string(ptr); } - - int state() { return netclient_state(ptr); } - /*void stats(NETSTATS *stats) { netclient_stats(ptr, stats); }*/ -}; -#endif - - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_client.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_network_client.cpp deleted file mode 100644 index 75f7c5384..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_client.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include "e_network.h" -#include "e_network_internal.h" - -struct NETCLIENT -{ - NETADDR server_addr; - NETSOCKET socket; - - NETRECVINFO recv; - NETCONNECTION conn; -}; - -NETCLIENT *netclient_open(NETADDR bindaddr, int flags) -{ - NETCLIENT *client = (NETCLIENT *)mem_alloc(sizeof(NETCLIENT), 1); - mem_zero(client, sizeof(NETCLIENT)); - client->socket = net_udp_create(bindaddr); - conn_init(&client->conn, client->socket); - return client; -} - -int netclient_close(NETCLIENT *c) -{ - /* TODO: implement me */ - return 0; -} - - -int netclient_disconnect(NETCLIENT *c, const char *reason) -{ - dbg_msg("netclient", "disconnected. reason=\"%s\"", reason); - conn_disconnect(&c->conn, reason); - return 0; -} - -int netclient_update(NETCLIENT *c) -{ - conn_update(&c->conn); - if(c->conn.state == NET_CONNSTATE_ERROR) - netclient_disconnect(c, conn_error(&c->conn)); - return 0; -} - -int netclient_connect(NETCLIENT *c, NETADDR *addr) -{ - conn_connect(&c->conn, addr); - return 0; -} - -int netclient_error_string_reset(NETCLIENT *c) -{ - mem_zero(c->conn.error_string, sizeof(c->conn.error_string)); - return 0; -} - -int netclient_recv(NETCLIENT *c, NETCHUNK *chunk) -{ - while(1) - { - NETADDR addr; - int bytes; - - /* check for a chunk */ - if(recvinfo_fetch_chunk(&c->recv, chunk)) - return 1; - - /* TODO: empty the recvinfo */ - bytes = net_udp_recv(c->socket, &addr, c->recv.buffer, NET_MAX_PACKETSIZE); - - /* no more packets for now */ - if(bytes <= 0) - break; - - if(unpack_packet(c->recv.buffer, bytes, &c->recv.data) == 0) - { - if(c->recv.data.flags&NET_PACKETFLAG_CONNLESS) - { - chunk->flags = NETSENDFLAG_CONNLESS; - chunk->client_id = -1; - chunk->address = addr; - chunk->data_size = c->recv.data.data_size; - chunk->data = c->recv.data.chunk_data; - return 1; - } - else - { - if(conn_feed(&c->conn, &c->recv.data, &addr)) - recvinfo_start(&c->recv, &addr, &c->conn, 0); - } - } - } - return 0; -} - -int netclient_send(NETCLIENT *c, NETCHUNK *chunk) -{ - if(chunk->data_size >= NET_MAX_PAYLOAD) - { - dbg_msg("netclient", "chunk payload too big. %d. dropping chunk", chunk->data_size); - return -1; - } - - if(chunk->flags&NETSENDFLAG_CONNLESS) - { - /* send connectionless packet */ - send_packet_connless(c->socket, &chunk->address, chunk->data, chunk->data_size); - } - else - { - int f = 0; - dbg_assert(chunk->client_id == 0, "errornous client id"); - - if(chunk->flags&NETSENDFLAG_VITAL) - f = NET_CHUNKFLAG_VITAL; - - conn_queue_chunk(&c->conn, f, chunk->data_size, chunk->data); - - if(chunk->flags&NETSENDFLAG_FLUSH) - conn_flush(&c->conn); - } - return 0; -} - -int netclient_state(NETCLIENT *c) -{ - if(c->conn.state == NET_CONNSTATE_ONLINE) - return NETSTATE_ONLINE; - if(c->conn.state == NET_CONNSTATE_OFFLINE) - return NETSTATE_OFFLINE; - return NETSTATE_CONNECTING; -} - -int netclient_flush(NETCLIENT *c) -{ - return conn_flush(&c->conn); -} - -int netclient_gotproblems(NETCLIENT *c) -{ - if(time_get() - c->conn.last_recv_time > time_freq()) - return 1; - return 0; -} - -void netclient_stats(NETCLIENT *c, NETSTATS *stats) -{ - *stats = c->conn.stats; -} - -const char *netclient_error_string(NETCLIENT *c) -{ - return conn_error(&c->conn); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_conn.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_network_conn.cpp deleted file mode 100644 index ed68864f6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_conn.cpp +++ /dev/null @@ -1,369 +0,0 @@ -#include -#include -#include "e_config.h" -#include "e_network_internal.h" - -static void conn_reset_stats(NETCONNECTION *conn) -{ - mem_zero(&conn->stats, sizeof(conn->stats)); -} - -static void conn_reset(NETCONNECTION *conn) -{ - conn->seq = 0; - conn->ack = 0; - conn->remote_closed = 0; - - conn->state = NET_CONNSTATE_OFFLINE; - conn->last_send_time = 0; - conn->last_recv_time = 0; - conn->last_update_time = 0; - conn->token = -1; - mem_zero(&conn->peeraddr, sizeof(conn->peeraddr)); - - conn->buffer = ringbuf_init(conn->buffer_memory, sizeof(conn->buffer_memory), 0); - - mem_zero(&conn->construct, sizeof(conn->construct)); -} - - -const char *conn_error(NETCONNECTION *conn) -{ - return conn->error_string; -} - -static void conn_set_error(NETCONNECTION *conn, const char *str) -{ - str_copy(conn->error_string, str, sizeof(conn->error_string)); -} - -void conn_init(NETCONNECTION *conn, NETSOCKET socket) -{ - conn_reset(conn); - conn_reset_stats(conn); - conn->socket = socket; - mem_zero(conn->error_string, sizeof(conn->error_string)); -} - - -static void conn_ack(NETCONNECTION *conn, int ack) -{ - - while(1) - { - NETCHUNKDATA *resend = (NETCHUNKDATA *)ringbuf_first(conn->buffer); - if(!resend) - break; - - if(seq_in_backroom(resend->sequence, ack)) - ringbuf_popfirst(conn->buffer); - else - break; - } -} - -void conn_want_resend(NETCONNECTION *conn) -{ - conn->construct.flags |= NET_PACKETFLAG_RESEND; -} - -int conn_flush(NETCONNECTION *conn) -{ - int num_chunks = conn->construct.num_chunks; - if(!num_chunks && !conn->construct.flags) - return 0; - - /* send of the packets */ - conn->construct.ack = conn->ack; - send_packet(conn->socket, &conn->peeraddr, &conn->construct); - - /* update send times */ - conn->last_send_time = time_get(); - - /* clear construct so we can start building a new package */ - mem_zero(&conn->construct, sizeof(conn->construct)); - return num_chunks; -} - -static int conn_queue_chunk_ex(NETCONNECTION *conn, int flags, int data_size, const void *data, int sequence) -{ - unsigned char *chunk_data; - - /* check if we have space for it, if not, flush the connection */ - if(conn->construct.data_size + data_size + NET_MAX_CHUNKHEADERSIZE > sizeof(conn->construct.chunk_data)) - conn_flush(conn); - - /* pack all the data */ - chunk_data = &conn->construct.chunk_data[conn->construct.data_size]; - chunk_data = pack_chunk_header(chunk_data, flags, data_size, sequence); - mem_copy(chunk_data, data, data_size); - chunk_data += data_size; - - /* */ - conn->construct.num_chunks++; - conn->construct.data_size = (int)(chunk_data-conn->construct.chunk_data); - - /* set packet flags aswell */ - - if(flags&NET_CHUNKFLAG_VITAL && !(flags&NET_CHUNKFLAG_RESEND)) - { - /* save packet if we need to resend */ - NETCHUNKDATA *resend = (NETCHUNKDATA *)ringbuf_allocate(conn->buffer, sizeof(NETCHUNKDATA)+data_size); - if(resend) - { - resend->sequence = sequence; - resend->flags = flags; - resend->data_size = data_size; - resend->data = (unsigned char *)(resend+1); - resend->first_send_time = time_get(); - resend->last_send_time = resend->first_send_time; - mem_copy(resend->data, data, data_size); - } - else - { - /* out of buffer */ - conn_disconnect(conn, "too weak connection (out of buffer)"); - return -1; - } - } - - return 0; -} - -int conn_queue_chunk(NETCONNECTION *conn, int flags, int data_size, const void *data) -{ - if(flags&NET_CHUNKFLAG_VITAL) - conn->seq = (conn->seq+1)%NET_MAX_SEQUENCE; - return conn_queue_chunk_ex(conn, flags, data_size, data, conn->seq); -} - - -static void conn_send_control(NETCONNECTION *conn, int controlmsg, const void *extra, int extra_size) -{ - /* send the control message */ - conn->last_send_time = time_get(); - send_controlmsg(conn->socket, &conn->peeraddr, conn->ack, controlmsg, extra, extra_size); -} - -static void conn_resend_chunk(NETCONNECTION *conn, NETCHUNKDATA *resend) -{ - conn_queue_chunk_ex(conn, resend->flags|NET_CHUNKFLAG_RESEND, resend->data_size, resend->data, resend->sequence); - resend->last_send_time = time_get(); -} - -static void conn_resend(NETCONNECTION *conn) -{ - int resend_count = 0; - int first = 0, last = 0; - void *item = ringbuf_first(conn->buffer); - - while(item) - { - NETCHUNKDATA *resend = (NETCHUNKDATA *)item; - - if(resend_count == 0) - first = resend->sequence; - last = resend->sequence; - - conn_resend_chunk(conn, resend); - item = ringbuf_next(conn->buffer, item); - resend_count++; - } - - if(config.debug) - dbg_msg("conn", "resent %d packets (%d to %d)", resend_count, first, last); -} - -int conn_connect(NETCONNECTION *conn, NETADDR *addr) -{ - if(conn->state != NET_CONNSTATE_OFFLINE) - return -1; - - /* init connection */ - conn_reset(conn); - conn->peeraddr = *addr; - mem_zero(conn->error_string, sizeof(conn->error_string)); - conn->state = NET_CONNSTATE_CONNECT; - conn_send_control(conn, NET_CTRLMSG_CONNECT, 0, 0); - return 0; -} - -void conn_disconnect(NETCONNECTION *conn, const char *reason) -{ - if(conn->state == NET_CONNSTATE_OFFLINE) - return; - - if(conn->remote_closed == 0) - { - if(reason) - conn_send_control(conn, NET_CTRLMSG_CLOSE, reason, strlen(reason)+1); - else - conn_send_control(conn, NET_CTRLMSG_CLOSE, 0, 0); - - conn->error_string[0] = 0; - if(reason) - str_copy(conn->error_string, reason, sizeof(conn->error_string)); - } - - conn_reset(conn); -} - -int conn_feed(NETCONNECTION *conn, NETPACKETCONSTRUCT *packet, NETADDR *addr) -{ - int64 now = time_get(); - conn->last_recv_time = now; - - /* check if resend is requested */ - if(packet->flags&NET_PACKETFLAG_RESEND) - conn_resend(conn); - - /* */ - if(packet->flags&NET_PACKETFLAG_CONTROL) - { - int ctrlmsg = packet->chunk_data[0]; - - if(ctrlmsg == NET_CTRLMSG_CLOSE) - { - conn->state = NET_CONNSTATE_ERROR; - conn->remote_closed = 1; - - if(packet->data_size) - { - /* make sure to sanitize the error string form the other party*/ - char str[128]; - if(packet->data_size < 128) - str_copy(str, (char *)packet->chunk_data, packet->data_size); - else - str_copy(str, (char *)packet->chunk_data, 128); - str_sanitize_strong(str); - - /* set the error string */ - conn_set_error(conn, str); - } - else - conn_set_error(conn, "no reason given"); - - if(config.debug) - dbg_msg("conn", "closed reason='%s'", conn_error(conn)); - return 0; - } - else - { - if(conn->state == NET_CONNSTATE_OFFLINE) - { - if(ctrlmsg == NET_CTRLMSG_CONNECT) - { - /* send response and init connection */ - conn_reset(conn); - conn->state = NET_CONNSTATE_PENDING; - conn->peeraddr = *addr; - conn->last_send_time = now; - conn->last_recv_time = now; - conn->last_update_time = now; - conn_send_control(conn, NET_CTRLMSG_CONNECTACCEPT, 0, 0); - if(config.debug) - dbg_msg("connection", "got connection, sending connect+accept"); - } - } - else if(conn->state == NET_CONNSTATE_CONNECT) - { - /* connection made */ - if(ctrlmsg == NET_CTRLMSG_CONNECTACCEPT) - { - conn_send_control(conn, NET_CTRLMSG_ACCEPT, 0, 0); - conn->state = NET_CONNSTATE_ONLINE; - if(config.debug) - dbg_msg("connection", "got connect+accept, sending accept. connection online"); - } - } - else if(conn->state == NET_CONNSTATE_ONLINE) - { - /* connection made */ - /* - if(ctrlmsg == NET_CTRLMSG_CONNECTACCEPT) - { - - }*/ - } - } - } - else - { - if(conn->state == NET_CONNSTATE_PENDING) - { - conn->state = NET_CONNSTATE_ONLINE; - if(config.debug) - dbg_msg("connection", "connecting online"); - } - } - - if(conn->state == NET_CONNSTATE_ONLINE) - { - - conn_ack(conn, packet->ack); - } - - return 1; -} - -int conn_update(NETCONNECTION *conn) -{ - int64 now = time_get(); - - if(conn->state == NET_CONNSTATE_OFFLINE || conn->state == NET_CONNSTATE_ERROR) - return 0; - - /* check for timeout */ - if(conn->state != NET_CONNSTATE_OFFLINE && - conn->state != NET_CONNSTATE_CONNECT && - (now-conn->last_recv_time) > time_freq()*10) - { - conn->state = NET_CONNSTATE_ERROR; - conn_set_error(conn, "timeout"); - } - - /* fix resends */ - if(ringbuf_first(conn->buffer)) - { - NETCHUNKDATA *resend = (NETCHUNKDATA *)ringbuf_first(conn->buffer); - - /* check if we have some really old stuff laying around and abort if not acked */ - if(now-resend->first_send_time > time_freq()*10) - { - conn->state = NET_CONNSTATE_ERROR; - conn_set_error(conn, "too weak connection (not acked for 10 seconds)"); - } - else - { - /* resend packet if we havn't got it acked in 1 second */ - if(now-resend->last_send_time > time_freq()) - conn_resend_chunk(conn, resend); - } - } - - /* send keep alives if nothing has happend for 250ms */ - if(conn->state == NET_CONNSTATE_ONLINE) - { - if(time_get()-conn->last_send_time > time_freq()/2) /* flush connection after 500ms if needed */ - { - int num_flushed_chunks = conn_flush(conn); - if(num_flushed_chunks && config.debug) - dbg_msg("connection", "flushed connection due to timeout. %d chunks.", num_flushed_chunks); - } - - if(time_get()-conn->last_send_time > time_freq()) - conn_send_control(conn, NET_CTRLMSG_KEEPALIVE, 0, 0); - } - else if(conn->state == NET_CONNSTATE_CONNECT) - { - if(time_get()-conn->last_send_time > time_freq()/2) /* send a new connect every 500ms */ - conn_send_control(conn, NET_CTRLMSG_CONNECT, 0, 0); - } - else if(conn->state == NET_CONNSTATE_PENDING) - { - if(time_get()-conn->last_send_time > time_freq()/2) /* send a new connect/accept every 500ms */ - conn_send_control(conn, NET_CTRLMSG_CONNECTACCEPT, 0, 0); - } - - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_internal.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_network_internal.h deleted file mode 100644 index c7d4f016f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_internal.h +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include "e_network.h" -#include "e_ringbuffer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - -CURRENT: - packet header: 3 bytes - unsigned char flags_ack; // 4bit flags, 4bit ack - unsigned char ack; // 8 bit ack - unsigned char num_chunks; // 8 bit chunks - - (unsigned char padding[3]) // 24 bit extra incase it's a connection less packet - // this is to make sure that it's compatible with the - // old protocol - - chunk header: 2-3 bytes - unsigned char flags_size; // 2bit flags, 6 bit size - unsigned char size_seq; // 4bit size, 4bit seq - (unsigned char seq;) // 8bit seq, if vital flag is set - - -*/ - -enum -{ - NET_VERSION = 2, - - NET_MAX_CHUNKSIZE = 1024, - NET_MAX_PAYLOAD = NET_MAX_CHUNKSIZE+16, - NET_MAX_PACKETSIZE = NET_MAX_PAYLOAD+16, - NET_MAX_CHUNKHEADERSIZE = 5, - NET_PACKETHEADERSIZE = 3, - NET_MAX_CLIENTS = 16, - NET_MAX_SEQUENCE = 1<<10, - NET_SEQUENCE_MASK = NET_MAX_SEQUENCE-1, - - NET_CONNSTATE_OFFLINE=0, - NET_CONNSTATE_CONNECT=1, - NET_CONNSTATE_PENDING=2, - NET_CONNSTATE_ONLINE=3, - NET_CONNSTATE_ERROR=4, - - NET_PACKETFLAG_CONTROL=1, - NET_PACKETFLAG_CONNLESS=2, - NET_PACKETFLAG_RESEND=4, - NET_PACKETFLAG_COMPRESSION=8, - - NET_CHUNKFLAG_VITAL=1, - NET_CHUNKFLAG_RESEND=2, - - NET_CTRLMSG_KEEPALIVE=0, - NET_CTRLMSG_CONNECT=1, - NET_CTRLMSG_CONNECTACCEPT=2, - NET_CTRLMSG_ACCEPT=3, - NET_CTRLMSG_CLOSE=4, - - NET_SERVER_MAXBANS=1024, - - NET_CONN_BUFFERSIZE=1024*16, - - NET_ENUM_TERMINATOR -}; - - -typedef struct NETPACKETCONSTRUCT -{ - int flags; - int ack; - int num_chunks; - int data_size; - unsigned char chunk_data[NET_MAX_PAYLOAD]; -} NETPACKETCONSTRUCT; - -typedef struct NETCHUNKHEADER -{ - int flags; - int size; - int sequence; -} NETCHUNKHEADER; - -typedef struct -{ - int flags; - int data_size; - unsigned char *data; - - int sequence; - int64 last_send_time; - int64 first_send_time; -} NETCHUNKDATA; - -typedef struct -{ - unsigned short seq; - unsigned short ack; - unsigned state; - - int token; - int remote_closed; - - RINGBUFFER *buffer; - - int64 last_update_time; - int64 last_recv_time; - int64 last_send_time; - - char error_string[256]; - - NETPACKETCONSTRUCT construct; - - NETADDR peeraddr; - NETSOCKET socket; - NETSTATS stats; - - char buffer_memory[NET_CONN_BUFFERSIZE]; -} NETCONNECTION; - -typedef struct NETRECVINFO -{ - NETADDR addr; - NETCONNECTION *conn; - int current_chunk; - int client_id; - int valid; - NETPACKETCONSTRUCT data; - unsigned char buffer[NET_MAX_PACKETSIZE]; -} NETRECVINFO; - -/* */ - -/* connection functions */ -void conn_init(NETCONNECTION *conn, NETSOCKET socket); -int conn_connect(NETCONNECTION *conn, NETADDR *addr); -void conn_disconnect(NETCONNECTION *conn, const char *reason); -int conn_update(NETCONNECTION *conn); -int conn_feed(NETCONNECTION *conn, NETPACKETCONSTRUCT *packet, NETADDR *addr); -int conn_queue_chunk(NETCONNECTION *conn, int flags, int data_size, const void *data); -const char *conn_error(NETCONNECTION *conn); -void conn_want_resend(NETCONNECTION *conn); -int conn_flush(NETCONNECTION *conn); - -/* recvinfo functions */ -void recvinfo_clear(NETRECVINFO *info); -void recvinfo_start(NETRECVINFO *info, NETADDR *addr, NETCONNECTION *conn, int cid); -int recvinfo_fetch_chunk(NETRECVINFO *info, NETCHUNK *chunk); - -/* misc helper functions */ -/* The backroom is ack-NET_MAX_SEQUENCE/2. Used for knowing if we acked a packet or not */ -int seq_in_backroom(int seq, int ack); -void send_controlmsg(NETSOCKET socket, NETADDR *addr, int ack, int controlmsg, const void *extra, int extra_size); -void send_packet_connless(NETSOCKET socket, NETADDR *addr, const void *data, int data_size); -void send_packet(NETSOCKET socket, NETADDR *addr, NETPACKETCONSTRUCT *packet); -int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *packet); -unsigned char *pack_chunk_header(unsigned char *data, int flags, int size, int sequence); -unsigned char *unpack_chunk_header(unsigned char *data, NETCHUNKHEADER *header); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_server.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_network_server.cpp deleted file mode 100644 index 2131cb479..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_network_server.cpp +++ /dev/null @@ -1,491 +0,0 @@ -#include -#include -#include "e_network.h" -#include "e_network_internal.h" - -typedef struct -{ - NETCONNECTION conn; -} NETSLOT; - -typedef struct NETBAN -{ - NETBANINFO info; - - /* hash list */ - struct NETBAN *hashnext; - struct NETBAN *hashprev; - - /* used or free list */ - struct NETBAN *next; - struct NETBAN *prev; -} NETBAN; - -#define MACRO_LIST_LINK_FIRST(object, first, prev, next) \ - { if(first) first->prev = object; \ - object->prev = NULL; \ - object->next = first; \ - first = object; } - -#define MACRO_LIST_LINK_AFTER(object, after, prev, next) \ - { object->prev = after; \ - object->next = after->next; \ - after->next = object; \ - if(object->next) \ - object->next->prev = object; \ - } - -#define MACRO_LIST_UNLINK(object, first, prev, next) \ - { if(object->next) object->next->prev = object->prev; \ - if(object->prev) object->prev->next = object->next; \ - else first = object->next; \ - object->next = NULL; object->prev = NULL; } - -#define MACRO_LIST_FIND(start, next, expression) \ - { while(start && !(expression)) start = start->next; } - -struct NETSERVER -{ - NETSOCKET socket; - NETSLOT slots[NET_MAX_CLIENTS]; - int max_clients; - - NETBAN *bans[256]; - NETBAN banpool[NET_SERVER_MAXBANS]; - NETBAN *banpool_firstfree; - NETBAN *banpool_firstused; - - NETFUNC_NEWCLIENT new_client; - NETFUNC_NEWCLIENT del_client; - void *user_ptr; - - NETRECVINFO recv; -}; - -NETSERVER *netserver_open(NETADDR bindaddr, int max_clients, int flags) -{ - int i; - NETSERVER *server; - NETSOCKET socket = net_udp_create(bindaddr); - if(socket == NETSOCKET_INVALID) - return 0; - - server = (NETSERVER *)mem_alloc(sizeof(NETSERVER), 1); - mem_zero(server, sizeof(NETSERVER)); - server->socket = socket; - server->max_clients = max_clients; - if(server->max_clients > NET_MAX_CLIENTS) - server->max_clients = NET_MAX_CLIENTS; - if(server->max_clients < 1) - server->max_clients = 1; - - for(i = 0; i < NET_MAX_CLIENTS; i++) - conn_init(&server->slots[i].conn, server->socket); - - /* setup all pointers for bans */ - for(i = 1; i < NET_SERVER_MAXBANS-1; i++) - { - server->banpool[i].next = &server->banpool[i+1]; - server->banpool[i].prev = &server->banpool[i-1]; - } - - server->banpool[0].next = &server->banpool[1]; - server->banpool[NET_SERVER_MAXBANS-1].prev = &server->banpool[NET_SERVER_MAXBANS-2]; - server->banpool_firstfree = &server->banpool[0]; - - return server; -} - -int netserver_set_callbacks(NETSERVER *s, NETFUNC_NEWCLIENT new_client, NETFUNC_DELCLIENT del_client, void *user) -{ - s->new_client = new_client; - s->del_client = del_client; - s->user_ptr = user; - return 0; -} - -int netserver_max_clients(NETSERVER *s) -{ - return s->max_clients; -} - -int netserver_close(NETSERVER *s) -{ - /* TODO: implement me */ - return 0; -} - -int netserver_drop(NETSERVER *s, int client_id, const char *reason) -{ - /* TODO: insert lots of checks here */ - NETADDR addr; - netserver_client_addr(s, client_id, &addr); - - dbg_msg("net_server", "client dropped. cid=%d ip=%d.%d.%d.%d reason=\"%s\"", - client_id, - addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3], - reason - ); - conn_disconnect(&s->slots[client_id].conn, reason); - - if(s->del_client) - s->del_client(client_id, s->user_ptr); - - return 0; -} - -int netserver_ban_get(NETSERVER *s, int index, NETBANINFO *info) -{ - NETBAN *ban; - for(ban = s->banpool_firstused; ban && index; ban = ban->next, index--) - {} - - if(!ban) - return 0; - *info = ban->info; - return 1; -} - -int netserver_ban_num(NETSERVER *s) -{ - int count = 0; - NETBAN *ban; - for(ban = s->banpool_firstused; ban; ban = ban->next) - count++; - return count; -} - -static void netserver_ban_remove_by_object(NETSERVER *s, NETBAN *ban) -{ - int iphash = (ban->info.addr.ip[0]+ban->info.addr.ip[1]+ban->info.addr.ip[2]+ban->info.addr.ip[3])&0xff; - dbg_msg("netserver", "removing ban on %d.%d.%d.%d", - ban->info.addr.ip[0], ban->info.addr.ip[1], ban->info.addr.ip[2], ban->info.addr.ip[3]); - MACRO_LIST_UNLINK(ban, s->banpool_firstused, prev, next); - MACRO_LIST_UNLINK(ban, s->bans[iphash], hashprev, hashnext); - MACRO_LIST_LINK_FIRST(ban, s->banpool_firstfree, prev, next); -} - -int netserver_ban_remove(NETSERVER *s, NETADDR addr) -{ - int iphash = (addr.ip[0]+addr.ip[1]+addr.ip[2]+addr.ip[3])&0xff; - NETBAN *ban = s->bans[iphash]; - - MACRO_LIST_FIND(ban, hashnext, net_addr_comp(&ban->info.addr, &addr) == 0); - - if(ban) - { - netserver_ban_remove_by_object(s, ban); - return 0; - } - - return -1; -} - -int netserver_ban_add(NETSERVER *s, NETADDR addr, int seconds) -{ - int iphash = (addr.ip[0]+addr.ip[1]+addr.ip[2]+addr.ip[3])&0xff; - unsigned stamp = 0xffffffff; - NETBAN *ban; - - /* remove the port */ - addr.port = 0; - - if(seconds) - stamp = time_timestamp() + seconds; - - /* search to see if it already exists */ - ban = s->bans[iphash]; - MACRO_LIST_FIND(ban, hashnext, net_addr_comp(&ban->info.addr, &addr) == 0); - if(ban) - { - /* adjust the ban */ - ban->info.expires = stamp; - return 0; - } - - if(!s->banpool_firstfree) - return -1; - - /* fetch and clear the new ban */ - ban = s->banpool_firstfree; - MACRO_LIST_UNLINK(ban, s->banpool_firstfree, prev, next); - - /* setup the ban info */ - ban->info.expires = stamp; - ban->info.addr = addr; - - /* add it to the ban hash */ - MACRO_LIST_LINK_FIRST(ban, s->bans[iphash], hashprev, hashnext); - - /* insert it into the used list */ - { - if(s->banpool_firstused) - { - NETBAN *insert_after = s->banpool_firstused; - MACRO_LIST_FIND(insert_after, next, stamp < insert_after->info.expires); - - if(insert_after) - insert_after = insert_after->prev; - else - { - /* add to last */ - insert_after = s->banpool_firstused; - while(insert_after->next) - insert_after = insert_after->next; - } - - if(insert_after) - { - MACRO_LIST_LINK_AFTER(ban, insert_after, prev, next); - } - else - { - MACRO_LIST_LINK_FIRST(ban, s->banpool_firstused, prev, next); - } - } - else - { - MACRO_LIST_LINK_FIRST(ban, s->banpool_firstused, prev, next); - } - } - - /* drop banned clients */ - { - char buf[128]; - int i; - NETADDR banaddr; - - if(seconds) - str_format(buf, sizeof(buf), "you have been banned for %d minutes", seconds/60); - else - str_format(buf, sizeof(buf), "you have been banned for life"); - - for(i = 0; i < s->max_clients; i++) - { - banaddr = s->slots[i].conn.peeraddr; - banaddr.port = 0; - - if(net_addr_comp(&addr, &banaddr) == 0) - netserver_drop(s, i, buf); - } - } - return 0; -} - -int netserver_update(NETSERVER *s) -{ - unsigned now = time_timestamp(); - - int i; - for(i = 0; i < s->max_clients; i++) - { - conn_update(&s->slots[i].conn); - if(s->slots[i].conn.state == NET_CONNSTATE_ERROR) - netserver_drop(s, i, conn_error(&s->slots[i].conn)); - } - - /* remove expired bans */ - while(s->banpool_firstused && s->banpool_firstused->info.expires < now) - { - NETBAN *ban = s->banpool_firstused; - netserver_ban_remove_by_object(s, ban); - } - - (void)now; - - return 0; -} - -/* - TODO: chopp up this function into smaller working parts -*/ -int netserver_recv(NETSERVER *s, NETCHUNK *chunk) -{ - unsigned now = time_timestamp(); - - while(1) - { - NETADDR addr; - int i, bytes, found; - - /* check for a chunk */ - if(recvinfo_fetch_chunk(&s->recv, chunk)) - return 1; - - /* TODO: empty the recvinfo */ - bytes = net_udp_recv(s->socket, &addr, s->recv.buffer, NET_MAX_PACKETSIZE); - - /* no more packets for now */ - if(bytes <= 0) - break; - - if(unpack_packet(s->recv.buffer, bytes, &s->recv.data) == 0) - { - NETBAN *ban = 0; - NETADDR banaddr = addr; - int iphash = (addr.ip[0]+addr.ip[1]+addr.ip[2]+addr.ip[3])&0xff; - found = 0; - banaddr.port = 0; - - /* search a ban */ - for(ban = s->bans[iphash]; ban; ban = ban->hashnext) - { - if(net_addr_comp(&ban->info.addr, &banaddr) == 0) - break; - } - - /* check if we just should drop the packet */ - if(ban) - { - // banned, reply with a message - char banstr[128]; - if(ban->info.expires) - { - int mins = ((ban->info.expires - now)+59)/60; - if(mins == 1) - str_format(banstr, sizeof(banstr), "banned for %d minute", mins); - else - str_format(banstr, sizeof(banstr), "banned for %d minutes", mins); - } - else - str_format(banstr, sizeof(banstr), "banned for life"); - send_controlmsg(s->socket, &addr, 0, NET_CTRLMSG_CLOSE, banstr, str_length(banstr)+1); - continue; - } - - if(s->recv.data.flags&NET_PACKETFLAG_CONNLESS) - { - chunk->flags = NETSENDFLAG_CONNLESS; - chunk->client_id = -1; - chunk->address = addr; - chunk->data_size = s->recv.data.data_size; - chunk->data = s->recv.data.chunk_data; - return 1; - } - else - { - /* TODO: check size here */ - if(s->recv.data.flags&NET_PACKETFLAG_CONTROL && s->recv.data.chunk_data[0] == NET_CTRLMSG_CONNECT) - { - found = 0; - - /* check if we already got this client */ - for(i = 0; i < s->max_clients; i++) - { - if(s->slots[i].conn.state != NET_CONNSTATE_OFFLINE && - net_addr_comp(&s->slots[i].conn.peeraddr, &addr) == 0) - { - found = 1; /* silent ignore.. we got this client already */ - break; - } - } - - /* client that wants to connect */ - if(!found) - { - for(i = 0; i < s->max_clients; i++) - { - if(s->slots[i].conn.state == NET_CONNSTATE_OFFLINE) - { - found = 1; - conn_feed(&s->slots[i].conn, &s->recv.data, &addr); - if(s->new_client) - s->new_client(i, s->user_ptr); - break; - } - } - - if(!found) - { - const char fullmsg[] = "server is full"; - send_controlmsg(s->socket, &addr, 0, NET_CTRLMSG_CLOSE, fullmsg, sizeof(fullmsg)); - } - } - } - else - { - /* normal packet, find matching slot */ - for(i = 0; i < s->max_clients; i++) - { - if(net_addr_comp(&s->slots[i].conn.peeraddr, &addr) == 0) - { - if(conn_feed(&s->slots[i].conn, &s->recv.data, &addr)) - { - if(s->recv.data.data_size) - recvinfo_start(&s->recv, &addr, &s->slots[i].conn, i); - } - } - } - } - } - } - } - return 0; -} - -int netserver_send(NETSERVER *s, NETCHUNK *chunk) -{ - if(chunk->data_size >= NET_MAX_PAYLOAD) - { - dbg_msg("netserver", "packet payload too big. %d. dropping packet", chunk->data_size); - return -1; - } - - if(chunk->flags&NETSENDFLAG_CONNLESS) - { - /* send connectionless packet */ - send_packet_connless(s->socket, &chunk->address, chunk->data, chunk->data_size); - } - else - { - int f = 0; - dbg_assert(chunk->client_id >= 0, "errornous client id"); - dbg_assert(chunk->client_id < s->max_clients, "errornous client id"); - - if(chunk->flags&NETSENDFLAG_VITAL) - f = NET_CHUNKFLAG_VITAL; - - if(conn_queue_chunk(&s->slots[chunk->client_id].conn, f, chunk->data_size, chunk->data) == 0) - { - if(chunk->flags&NETSENDFLAG_FLUSH) - conn_flush(&s->slots[chunk->client_id].conn); - } - else - { - netserver_drop(s, chunk->client_id, "error sending data"); - } - - } - return 0; -} - -void netserver_stats(NETSERVER *s, NETSTATS *stats) -{ - int num_stats = sizeof(NETSTATS)/sizeof(int); - int *istats = (int *)stats; - int c, i; - - mem_zero(stats, sizeof(NETSTATS)); - - for(c = 0; c < s->max_clients; c++) - { - if(s->slots[c].conn.state != NET_CONNSTATE_OFFLINE) - { - int *sstats = (int *)(&(s->slots[c].conn.stats)); - for(i = 0; i < num_stats; i++) - istats[i] += sstats[i]; - } - } -} - -NETSOCKET netserver_socket(NETSERVER *s) -{ - return s->socket; -} - - -int netserver_client_addr(NETSERVER *s, int client_id, NETADDR *addr) -{ - *addr = s->slots[client_id].conn.peeraddr; - return 1; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.cpp deleted file mode 100644 index aee08aede..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include /* rand() */ -#include - -#include "e_packer.h" -#include "e_compression.h" -#include "e_engine.h" -#include "e_config.h" - -/* useful for debugging */ -#if 0 - #define packing_error(p) p->error = 1; dbg_break() -#else - #define packing_error(p) p->error = 1 -#endif - -static int stress_get_int() -{ - static const int nasty[] = {-1, 0, 1, 66000, -66000, (-1<<31), 0x7fffffff}; - if(rand()&1) - return rand(); - return nasty[rand()%6]; -} - -static const char *stress_get_string(int *size) -{ - static char noise[1024]; - int i; - int s; - s = (rand()%1024)-1; - for(i = 0; i < s; i++) - noise[i] = (rand()%254)+1; - noise[s] = 0; - if(size) - *size = s; - return noise; -} - - -static int stress_prob(float probability) -{ - if(!config.dbg_stress_network) - return 0; - if(rand()/(float)RAND_MAX < probability) - return 1; - return 0; -} - - -void packer_reset(PACKER *p) -{ - p->error = 0; - p->current = p->buffer; - p->end = p->current + PACKER_BUFFER_SIZE; -} - -void packer_add_int(PACKER *p, int i) -{ - if(p->error) - return; - - if(stress_prob(0.025f)) - i = stress_get_int(); - - /* make sure that we have space enough */ - if(p->end - p->current < 6) - { - dbg_break(); - p->error = 1; - } - else - p->current = vint_pack(p->current, i); -} - -void packer_add_string(PACKER *p, const char *str, int limit) -{ - if(p->error) - return; - - if(stress_prob(0.1f)) - { - str = stress_get_string(0); - limit = 0; - } - - /* */ - if(limit > 0) - { - while(*str && limit != 0) - { - *p->current++ = *str++; - limit--; - - if(p->current >= p->end) - { - packing_error(p); - break; - } - } - *p->current++ = 0; - } - else - { - while(*str) - { - *p->current++ = *str++; - - if(p->current >= p->end) - { - packing_error(p); - break; - } - } - *p->current++ = 0; - } -} - -void packer_add_raw(PACKER *p, const unsigned char *data, int size) -{ - if(p->error) - return; - - if(p->current+size >= p->end) - { - packing_error(p); - return; - } - - while(size) - { - *p->current++ = *data++; - size--; - } -} - -int packer_size(PACKER *p) -{ - return (const unsigned char *)p->current-(const unsigned char *)p->buffer; -} - -const unsigned char *packer_data(PACKER *p) -{ - return (const unsigned char *)p->buffer; -} - -void unpacker_reset(UNPACKER *p, const unsigned char *data, int size) -{ - p->error = 0; - p->start = data; - p->end = p->start + size; - p->current = p->start; -} - -int unpacker_get_int(UNPACKER *p) -{ - int i; - if(p->error) - return 0; - if(p->current >= p->end) - { - packing_error(p); - return 0; - } - - p->current = vint_unpack(p->current, &i); - if(p->current > p->end) - { - packing_error(p); - return 0; - } - return i; -} - -const char *unpacker_get_string(UNPACKER *p) -{ - char *ptr; - if(p->error || p->current >= p->end) - return ""; - - ptr = (char *)p->current; - while(*p->current) /* skip the string */ - { - p->current++; - if(p->current == p->end) - { - packing_error(p); - return ""; - } - } - p->current++; - - /* sanitize all strings */ - str_sanitize(ptr); - return ptr; -} - -const unsigned char *unpacker_get_raw(UNPACKER *p, int size) -{ - const unsigned char *ptr = p->current; - if(p->error) - return 0; - - /* check for nasty sizes */ - if(size < 0 || p->current+size > p->end) - { - packing_error(p); - return 0; - } - - /* "unpack" the data */ - p->current += size; - return ptr; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.h deleted file mode 100644 index c70207a78..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_packer.h +++ /dev/null @@ -1,43 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifdef __cplusplus -extern "C" { -#endif - -enum -{ - PACKER_BUFFER_SIZE=1024*2 -}; - -typedef struct -{ - - unsigned char buffer[PACKER_BUFFER_SIZE]; - unsigned char *current; - unsigned char *end; - int error; -} PACKER; - -typedef struct -{ - const unsigned char *current; - const unsigned char *start; - const unsigned char *end; - int error; -} UNPACKER; - -void packer_reset(PACKER *p); -void packer_add_int(PACKER *p, int i); -void packer_add_string(PACKER *p, const char *str, int limit); -void packer_add_raw(PACKER *p, const unsigned char *data, int size); -int packer_size(PACKER *p); -const unsigned char *packer_data(PACKER *p); - -void unpacker_reset(UNPACKER *p, const unsigned char *data, int size); -int unpacker_get_int(UNPACKER *p); -const char *unpacker_get_string(UNPACKER *p); -const unsigned char *unpacker_get_raw(UNPACKER *p, int size); - -#ifdef __cplusplus -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_protocol.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_protocol.h deleted file mode 100644 index a1feb4cce..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_protocol.h +++ /dev/null @@ -1,73 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include - -/* - Connection diagram - How the initilization works. - - Client -> INFO -> Server - Contains version info, name, and some other info. - - Client <- MAP <- Server - Contains current map. - - Client -> READY -> Server - The client has loaded the map and is ready to go, - but the mod needs to send it's information aswell. - modc_connected is called on the client and - mods_connected is called on the server. - The client should call client_entergame when the - mod has done it's initilization. - - Client -> ENTERGAME -> Server - Tells the server to start sending snapshots. - client_entergame and server_client_enter is called. -*/ - - -enum -{ - NETMSG_NULL=0, - - /* the first thing sent by the client - contains the version info for the client */ - NETMSG_INFO=1, - - /* sent by server */ - NETMSG_MAP_CHANGE, /* sent when client should switch map */ - NETMSG_MAP_DATA, /* map transfer, contains a chunk of the map file */ - NETMSG_SNAP, /* normal snapshot, multiple parts */ - NETMSG_SNAPEMPTY, /* empty snapshot */ - NETMSG_SNAPSINGLE, /* ? */ - NETMSG_SNAPSMALL, /* */ - NETMSG_INPUTTIMING, /* reports how off the input was */ - NETMSG_RCON_AUTH_STATUS,/* result of the authentication */ - NETMSG_RCON_LINE, /* line that should be printed to the remote console */ - - NETMSG_AUTH_CHALLANGE, /* */ - NETMSG_AUTH_RESULT, /* */ - - /* sent by client */ - NETMSG_READY, /* */ - NETMSG_ENTERGAME, - NETMSG_INPUT, /* contains the inputdata from the client */ - NETMSG_RCON_CMD, /* */ - NETMSG_RCON_AUTH, /* */ - NETMSG_REQUEST_MAP_DATA,/* */ - - NETMSG_AUTH_START, /* */ - NETMSG_AUTH_RESPONSE, /* */ - - /* sent by both */ - NETMSG_PING, - NETMSG_PING_REPLY, - NETMSG_ERROR -}; - - -/* this should be revised */ -enum -{ - MAX_CLANNAME_LENGTH=32, - MAX_INPUT_SIZE=128, - MAX_SNAPSHOT_PACKSIZE=900 -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.cpp deleted file mode 100644 index 39dfa3e9c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.cpp +++ /dev/null @@ -1,362 +0,0 @@ -#include - -#include "e_ringbuffer.h" - -typedef struct RBITEM -{ - struct RBITEM *prev; - struct RBITEM *next; - int free; - int size; -} RBITEM; - -/* - -*/ -struct RINGBUFFER -{ - RBITEM *produce; - RBITEM *consume; - - RBITEM *first; - RBITEM *last; - void *memory; - int size; - int flags; -}; - -RINGBUFFER *ringbuf_init(void *memory, int size, int flags) -{ - RINGBUFFER *rb = (RINGBUFFER *)memory; - mem_zero(memory, size); - - rb->memory = rb+1; - rb->size = (size-sizeof(RINGBUFFER))/sizeof(RBITEM)*sizeof(RBITEM); - rb->first = (RBITEM *)rb->memory; - rb->first->free = 1; - rb->first->size = rb->size; - rb->last = rb->first; - rb->produce = rb->first; - rb->consume = rb->first; - - rb->flags = flags; - - return rb; -} - -static RBITEM *ringbuf_nextblock(RINGBUFFER *rb, RBITEM *item) -{ - if(item->next) - return item->next; - return rb->first; -} - -static RBITEM *ringbuf_prevblock(RINGBUFFER *rb, RBITEM *item) -{ - if(item->prev) - return item->prev; - return rb->last; -} - -static RBITEM *ringbuf_mergeback(RINGBUFFER *rb, RBITEM *item) -{ - /* make sure that this block and previous block is free */ - if(!item->free || !item->prev || !item->prev->free) - return item; - - /* merge the blocks */ - item->prev->size += item->size; - item->prev->next = item->next; - - /* fixup pointers */ - if(item->next) - item->next->prev = item->prev; - else - rb->last = item->prev; - - if(item == rb->produce) - rb->produce = item->prev; - - if(item == rb->consume) - rb->consume = item->prev; - - /* return the current block */ - return item->prev; -} - -int ringbuf_popfirst(RINGBUFFER *rb) -{ - if(rb->consume->free) - return 0; - - /* set the free flag */ - rb->consume->free = 1; - - /* previous block is also free, merge them */ - rb->consume = ringbuf_mergeback(rb, rb->consume); - - /* advance the consume pointer */ - rb->consume = ringbuf_nextblock(rb, rb->consume); - while(rb->consume->free && rb->consume != rb->produce) - { - rb->consume = ringbuf_mergeback(rb, rb->consume); - rb->consume = ringbuf_nextblock(rb, rb->consume); - } - - /* in the case that we have catched up with the produce pointer */ - /* we might stand on a free block so merge em */ - ringbuf_mergeback(rb, rb->consume); - return 1; -} - -void *ringbuf_allocate(RINGBUFFER *rb, int size) -{ - int wanted_size = (size+sizeof(RBITEM)+sizeof(RBITEM)-1)/sizeof(RBITEM)*sizeof(RBITEM); - RBITEM *block = 0; - - /* check if we even can fit this block */ - if(wanted_size > rb->size) - return 0; - - while(1) - { - /* check for space */ - if(rb->produce->free) - { - if(rb->produce->size >= wanted_size) - block = rb->produce; - else - { - /* wrap around to try to find a block */ - if(rb->first->free && rb->first->size >= wanted_size) - block = rb->first; - } - } - - if(block) - break; - else - { - /* we have no block, check our policy and see what todo */ - if(rb->flags&RINGBUF_FLAG_RECYCLE) - { - if(!ringbuf_popfirst(rb)) - return 0; - } - else - return 0; - } - } - - /* okey, we have our block */ - - /* split the block if needed */ - if(block->size > wanted_size) - { - RBITEM *new_item = (RBITEM *)((char *)block + wanted_size); - new_item->prev = block; - new_item->next = block->next; - if(new_item->next) - new_item->next->prev = new_item; - block->next = new_item; - - new_item->free = 1; - new_item->size = block->size - wanted_size; - block->size = wanted_size; - - if(!new_item->next) - rb->last = new_item; - } - - - /* set next block */ - rb->produce = ringbuf_nextblock(rb, block); - - /* set as used and return the item pointer */ - block->free = 0; - return block+1; -} - -void *ringbuf_prev(RINGBUFFER *rb, void *current) -{ - RBITEM *item = ((RBITEM *)current) - 1; - - while(1) - { - item = ringbuf_prevblock(rb, item); - if(item == rb->produce) - return 0; - if(!item->free) - return item+1; - } -} - -void *ringbuf_next(RINGBUFFER *rb, void *current) -{ - RBITEM *item = ((RBITEM *)current) - 1; - - while(1) - { - item = ringbuf_nextblock(rb, item); - if(item == rb->produce) - return 0; - if(!item->free) - return item+1; - } -} - -void *ringbuf_first(RINGBUFFER *rb) -{ - if(rb->consume->free) - return 0; - return rb->consume+1; -} - -void *ringbuf_last(RINGBUFFER *rb) -{ - if(!rb->produce->free) - return rb->produce+1; - return ringbuf_prev(rb, rb->produce+1); -} - - -/* debugging and testing stuff */ - -static void ringbuf_debugdump(RINGBUFFER *rb, const char *msg) -{ - RBITEM *cur = rb->first; - - dbg_msg("ringbuf", "-- dumping --"); - - while(cur) - { - char flags[4] = " "; - if(cur->free) - flags[0] = 'F'; - if(cur == rb->consume) - flags[1] = '>'; - if(cur == rb->produce) - flags[2] = '<'; - dbg_msg("ringbuf", "%s %d", flags, cur->size); - cur = cur->next; - } - - dbg_msg("ringbuf", "-- --"); - - if(msg) - dbg_assert(0, msg); -} - - - -static void ringbuf_validate(RINGBUFFER *rb) -{ - RBITEM *prev = 0; - RBITEM *cur = rb->first; - int freechunks = 0; - int got_consume = 0; - int got_produce = 0; - - while(cur) - { - - if(cur->free) - freechunks++; - - if(freechunks > 2) ringbuf_debugdump(rb, "too many free chunks"); - if(prev && prev->free && cur->free) ringbuf_debugdump(rb, "two free chunks next to each other"); - if(cur == rb->consume) got_consume = 1; - if(cur == rb->produce) got_produce = 1; - - dbg_assert(cur->prev == prev, "prev pointers doesn't match"); - dbg_assert(!prev || prev->next == cur, "next pointers doesn't match"); - dbg_assert(cur->next || cur == rb->last, "last isn't last"); - - prev = cur; - cur = cur->next; - } - - if(!got_consume) ringbuf_debugdump(rb, "consume pointer isn't pointing at a valid block"); - if(!got_produce) ringbuf_debugdump(rb, "produce pointer isn't pointing at a valid block"); -} - -int ringbuf_test() -{ - char buffer[256]; - RINGBUFFER *rb; - int i, s, k, m; - int count; - int testcount = 0; - - void *item; - int before; - - - for(k = 100; k < sizeof(buffer); k++) - { - if((k%10) == 0) - dbg_msg("ringbuf", "testing at %d", k); - rb = ringbuf_init(buffer, k, 0); - count = 0; - - for(s = 1; s < sizeof(buffer); s++) - { - for(i = 0; i < k*8; i++, testcount++) - { - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - before = m; - - if(ringbuf_allocate(rb, s)) - { - count++; - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - if(before+1 != m) ringbuf_debugdump(rb, "alloc error"); - if(count != m) ringbuf_debugdump(rb, "count error"); - } - else - { - if(ringbuf_popfirst(rb)) - { - count--; - - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - if(before-1 != m) dbg_msg("", "popping error %d %d", before, m); - if(count != m) ringbuf_debugdump(rb, "count error"); - } - } - - /* remove an item every 10 */ - if((i%10) == 0) - { - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - before = m; - - if(ringbuf_popfirst(rb)) - { - count--; - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - if(before-1 != m) dbg_msg("", "popping error %d %d", before, m); - dbg_assert(count == m, "count error"); - } - } - - /* count items */ - for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); - if(m != count) ringbuf_debugdump(rb, "wrong number of items during forward count"); - - for(m = 0, item = ringbuf_last(rb); item; item = ringbuf_prev(rb, item), m++); - if(m != count) ringbuf_debugdump(rb, "wrong number of items during backward count"); - - ringbuf_validate(rb); - } - - /* empty the ring buffer */ - while(ringbuf_first(rb)) - ringbuf_popfirst(rb); - ringbuf_validate(rb); - count = 0; - } - } - - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.h deleted file mode 100644 index 523443dcf..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_ringbuffer.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _RINGBUFFER_H -#define _RINGBUFFER_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct RINGBUFFER RINGBUFFER; - -enum -{ - /* Will start to destroy items to try to fit the next one */ - RINGBUF_FLAG_RECYCLE=1 -}; - -RINGBUFFER *ringbuf_init(void *memory, int size, int flags); -void ringbuf_clear(RINGBUFFER *rb); -void *ringbuf_allocate(RINGBUFFER *rb, int size); - -void *ringbuf_prev(RINGBUFFER *rb, void *current); -void *ringbuf_next(RINGBUFFER *rb, void *current); -void *ringbuf_first(RINGBUFFER *rb); -void *ringbuf_last(RINGBUFFER *rb); - -int ringbuf_popfirst(RINGBUFFER *rb); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_server_interface.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_server_interface.h deleted file mode 100644 index 5b1e63275..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_server_interface.h +++ /dev/null @@ -1,20 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_SERVER_INTERFACE_H -#define ENGINE_SERVER_INTERFACE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "e_if_other.h" -#include "e_if_server.h" -#include "e_if_msg.h" -#include "e_if_mods.h" - -#include "e_console.h" /* TODO: clean this up*/ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.cpp deleted file mode 100644 index cce8a06e4..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.cpp +++ /dev/null @@ -1,604 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "e_snapshot.h" -#include "e_engine.h" -#include "e_compression.h" -#include "e_common_interface.h" - - -/* TODO: strange arbitrary number */ -static short item_sizes[64] = {0}; - -void snap_set_staticsize(int itemtype, int size) -{ - item_sizes[itemtype] = size; -} - -int *snapitem_data(SNAPSHOT_ITEM *item) { return (int *)(item+1); } -int snapitem_type(SNAPSHOT_ITEM *item) { return item->type_and_id>>16; } -int snapitem_id(SNAPSHOT_ITEM *item) { return item->type_and_id&0xffff; } -int snapitem_key(SNAPSHOT_ITEM *item) { return item->type_and_id; } - -int *snapshot_offsets(SNAPSHOT *snap) { return (int *)(snap+1); } -char *snapshot_datastart(SNAPSHOT *snap) { return (char*)(snapshot_offsets(snap)+snap->num_items); } - -SNAPSHOT_ITEM *snapshot_get_item(SNAPSHOT *snap, int index) -{ return (SNAPSHOT_ITEM *)(snapshot_datastart(snap) + snapshot_offsets(snap)[index]); } - -int snapshot_get_item_datasize(SNAPSHOT *snap, int index) -{ - if(index == snap->num_items-1) - return (snap->data_size - snapshot_offsets(snap)[index]) - sizeof(SNAPSHOT_ITEM); - return (snapshot_offsets(snap)[index+1] - snapshot_offsets(snap)[index]) - sizeof(SNAPSHOT_ITEM); -} - -int snapshot_get_item_index(SNAPSHOT *snap, int key) -{ - /* TODO: OPT: this should not be a linear search. very bad */ - int i; - for(i = 0; i < snap->num_items; i++) - { - if(snapitem_key(snapshot_get_item(snap, i)) == key) - return i; - } - return -1; -} -typedef struct -{ - int num; - int keys[64]; - int index[64]; -} ITEMLIST; -static ITEMLIST sorted[256]; - -static int snapshot_generate_hash(SNAPSHOT *snap) -{ - int i, key, hashid; - - for(i = 0; i < 256; i++) - sorted[i].num = 0; - - for(i = 0; i < snap->num_items; i++) - { - key = snapitem_key(snapshot_get_item(snap, i)); - hashid = ((key>>8)&0xf0) | (key&0xf); - if(sorted[hashid].num != 64) - { - sorted[hashid].index[sorted[hashid].num] = i; - sorted[hashid].keys[sorted[hashid].num] = key; - sorted[hashid].num++; - } - } - return 0; -} - -int snapshot_get_item_index_hashed(SNAPSHOT *snap, int key) -{ - int hashid = ((key>>8)&0xf0) | (key&0xf); - int i; - for(i = 0; i < sorted[hashid].num; i++) - { - if(sorted[hashid].keys[i] == key) - return sorted[hashid].index[i]; - } - - return -1; -} - -typedef struct -{ - int num_deleted_items; - int num_update_items; - int num_temp_items; /* needed? */ - int data[1]; - - /* - char *data_start() { return (char *)&offsets[num_deleted_items+num_update_items+num_temp_items]; } - - int deleted_item(int index) { return offsets[index]; } - item *update_item(int index) { return (item *)(data_start() + offsets[num_deleted_items+index]); } - item *temp_item(int index) { return (item *)(data_start() + offsets[num_deleted_items+num_update_items+index]); } - */ -} SNAPSHOT_DELTA; - - -static const int MAX_ITEMS = 512; -static SNAPSHOT_DELTA empty = {0,0,0,{0}}; - -void *snapshot_empty_delta() -{ - return ∅ -} - -int snapshot_crc(SNAPSHOT *snap) -{ - int crc = 0; - int i, b; - SNAPSHOT_ITEM *item; - int size; - - for(i = 0; i < snap->num_items; i++) - { - item = snapshot_get_item(snap, i); - size = snapshot_get_item_datasize(snap, i); - - for(b = 0; b < size/4; b++) - crc += snapitem_data(item)[b]; - } - return crc; -} - -void snapshot_debug_dump(SNAPSHOT *snap) -{ - int size, i, b; - SNAPSHOT_ITEM *item; - - dbg_msg("snapshot", "data_size=%d num_items=%d", snap->data_size, snap->num_items); - for(i = 0; i < snap->num_items; i++) - { - item = snapshot_get_item(snap, i); - size = snapshot_get_item_datasize(snap, i); - dbg_msg("snapshot", "\ttype=%d id=%d", snapitem_type(item), snapitem_id(item)); - for(b = 0; b < size/4; b++) - dbg_msg("snapshot", "\t\t%3d %12d\t%08x", b, snapitem_data(item)[b], snapitem_data(item)[b]); - } -} - -static int diff_item(int *past, int *current, int *out, int size) -{ - int needed = 0; - while(size) - { - *out = *current-*past; - needed |= *out; - out++; - past++; - current++; - size--; - } - - return needed; -} - -int snapshot_data_rate[0xffff] = {0}; -int snapshot_data_updates[0xffff] = {0}; -static int snapshot_current = 0; - -static void undiff_item(int *past, int *diff, int *out, int size) -{ - while(size) - { - *out = *past+*diff; - - if(*diff == 0) - snapshot_data_rate[snapshot_current] += 1; - else - { - unsigned char buf[16]; - unsigned char *end = vint_pack(buf, *diff); - snapshot_data_rate[snapshot_current] += (int)(end - (unsigned char*)buf) * 8; - } - - out++; - past++; - diff++; - size--; - } -} - - -/* TODO: OPT: this should be made much faster */ -int snapshot_create_delta(SNAPSHOT *from, SNAPSHOT *to, void *dstdata) -{ - static PERFORMACE_INFO hash_scope = {"hash", 0}; - SNAPSHOT_DELTA *delta = (SNAPSHOT_DELTA *)dstdata; - int *data = (int *)delta->data; - int i, itemsize, pastindex; - SNAPSHOT_ITEM *fromitem; - SNAPSHOT_ITEM *curitem; - SNAPSHOT_ITEM *pastitem; - int count = 0; - int size_count = 0; - - delta->num_deleted_items = 0; - delta->num_update_items = 0; - delta->num_temp_items = 0; - - perf_start(&hash_scope); - snapshot_generate_hash(to); - perf_end(); - - /* pack deleted stuff */ - { - static PERFORMACE_INFO scope = {"delete", 0}; - perf_start(&scope); - - for(i = 0; i < from->num_items; i++) - { - fromitem = snapshot_get_item(from, i); - if(snapshot_get_item_index_hashed(to, (snapitem_key(fromitem))) == -1) - { - /* deleted */ - delta->num_deleted_items++; - *data = snapitem_key(fromitem); - data++; - } - } - - perf_end(); - } - - perf_start(&hash_scope); - snapshot_generate_hash(from); - perf_end(); - - /* pack updated stuff */ - { - static PERFORMACE_INFO scope = {"update", 0}; - int pastindecies[1024]; - perf_start(&scope); - - /* fetch previous indices */ - /* we do this as a separate pass because it helps the cache */ - { - static PERFORMACE_INFO scope = {"find", 0}; - perf_start(&scope); - for(i = 0; i < to->num_items; i++) - { - curitem = snapshot_get_item(to, i); /* O(1) .. O(n) */ - pastindecies[i] = snapshot_get_item_index_hashed(from, snapitem_key(curitem)); /* O(n) .. O(n^n)*/ - } - perf_end(); - } - - for(i = 0; i < to->num_items; i++) - { - /* do delta */ - itemsize = snapshot_get_item_datasize(to, i); /* O(1) .. O(n) */ - curitem = snapshot_get_item(to, i); /* O(1) .. O(n) */ - pastindex = pastindecies[i]; - - if(pastindex != -1) - { - static PERFORMACE_INFO scope = {"diff", 0}; - int *item_data_dst = data+3; - perf_start(&scope); - - pastitem = snapshot_get_item(from, pastindex); - - if(item_sizes[snapitem_type(curitem)]) - item_data_dst = data+2; - - if(diff_item((int*)snapitem_data(pastitem), (int*)snapitem_data(curitem), item_data_dst, itemsize/4)) - { - - *data++ = snapitem_type(curitem); - *data++ = snapitem_id(curitem); - if(!item_sizes[snapitem_type(curitem)]) - *data++ = itemsize/4; - data += itemsize/4; - delta->num_update_items++; - } - perf_end(); - } - else - { - static PERFORMACE_INFO scope = {"copy", 0}; - perf_start(&scope); - - *data++ = snapitem_type(curitem); - *data++ = snapitem_id(curitem); - if(!item_sizes[snapitem_type(curitem)]) - *data++ = itemsize/4; - - mem_copy(data, snapitem_data(curitem), itemsize); - size_count += itemsize; - data += itemsize/4; - delta->num_update_items++; - count++; - - perf_end(); - } - } - - perf_end(); - } - - if(0) - { - dbg_msg("snapshot", "%d %d %d", - delta->num_deleted_items, - delta->num_update_items, - delta->num_temp_items); - } - - /* - // TODO: pack temp stuff - - // finish - //mem_copy(delta->offsets, deleted, delta->num_deleted_items*sizeof(int)); - //mem_copy(&(delta->offsets[delta->num_deleted_items]), update, delta->num_update_items*sizeof(int)); - //mem_copy(&(delta->offsets[delta->num_deleted_items+delta->num_update_items]), temp, delta->num_temp_items*sizeof(int)); - //mem_copy(delta->data_start(), data, data_size); - //delta->data_size = data_size; - * */ - - if(!delta->num_deleted_items && !delta->num_update_items && !delta->num_temp_items) - return 0; - - return (int)((char*)data-(char*)dstdata); -} - -static int range_check(void *end, void *ptr, int size) -{ - if((const char *)ptr + size > (const char *)end) - return -1; - return 0; -} - -int snapshot_unpack_delta(SNAPSHOT *from, SNAPSHOT *to, void *srcdata, int data_size) -{ - SNAPBUILD builder; - SNAPSHOT_DELTA *delta = (SNAPSHOT_DELTA *)srcdata; - int *data = (int *)delta->data; - int *end = (int *)(((char *)srcdata + data_size)); - - SNAPSHOT_ITEM *fromitem; - int i, d, keep, itemsize; - int *deleted; - int id, type, key; - int fromindex; - int *newdata; - - snapbuild_init(&builder); - - /* unpack deleted stuff */ - deleted = data; - data += delta->num_deleted_items; - if(data > end) - return -1; - - /* copy all non deleted stuff */ - for(i = 0; i < from->num_items; i++) - { - /* dbg_assert(0, "fail!"); */ - fromitem = snapshot_get_item(from, i); - itemsize = snapshot_get_item_datasize(from, i); - keep = 1; - for(d = 0; d < delta->num_deleted_items; d++) - { - if(deleted[d] == snapitem_key(fromitem)) - { - keep = 0; - break; - } - } - - if(keep) - { - /* keep it */ - mem_copy( - snapbuild_new_item(&builder, snapitem_type(fromitem), snapitem_id(fromitem), itemsize), - snapitem_data(fromitem), itemsize); - } - } - - /* unpack updated stuff */ - for(i = 0; i < delta->num_update_items; i++) - { - if(data+2 > end) - return -1; - - type = *data++; - id = *data++; - if(item_sizes[type]) - itemsize = item_sizes[type]; - else - { - if(data+1 > end) - return -2; - itemsize = (*data++) * 4; - } - snapshot_current = type; - - if(range_check(end, data, itemsize) || itemsize < 0) return -3; - - key = (type<<16)|id; - - /* create the item if needed */ - newdata = snapbuild_get_item_data(&builder, key); - if(!newdata) - newdata = (int *)snapbuild_new_item(&builder, key>>16, key&0xffff, itemsize); - - /*if(range_check(end, newdata, itemsize)) return -4;*/ - - fromindex = snapshot_get_item_index(from, key); - if(fromindex != -1) - { - /* we got an update so we need to apply the diff */ - undiff_item((int *)snapitem_data(snapshot_get_item(from, fromindex)), data, newdata, itemsize/4); - snapshot_data_updates[snapshot_current]++; - } - else /* no previous, just copy the data */ - { - mem_copy(newdata, data, itemsize); - snapshot_data_rate[snapshot_current] += itemsize*8; - snapshot_data_updates[snapshot_current]++; - } - - data += itemsize/4; - } - - /* finish up */ - return snapbuild_finish(&builder, to); -} - -/* SNAPSTORAGE */ - -void snapstorage_init(SNAPSTORAGE *ss) -{ - ss->first = 0; -} - -void snapstorage_purge_all(SNAPSTORAGE *ss) -{ - SNAPSTORAGE_HOLDER *h = ss->first; - SNAPSTORAGE_HOLDER *next; - - while(h) - { - next = h->next; - mem_free(h); - h = next; - } - - /* no more snapshots in storage */ - ss->first = 0; - ss->last = 0; -} - -void snapstorage_purge_until(SNAPSTORAGE *ss, int tick) -{ - SNAPSTORAGE_HOLDER *next; - SNAPSTORAGE_HOLDER *h = ss->first; - - while(h) - { - next = h->next; - if(h->tick >= tick) - return; /* no more to remove */ - mem_free(h); - - /* did we come to the end of the list? */ - if (!next) - break; - - ss->first = next; - next->prev = 0x0; - - h = next; - } - - /* no more snapshots in storage */ - ss->first = 0; - ss->last = 0; -} - -void snapstorage_add(SNAPSTORAGE *ss, int tick, int64 tagtime, int data_size, void *data, int create_alt) -{ - /* allocate memory for holder + snapshot_data */ - SNAPSTORAGE_HOLDER *h; - int total_size = sizeof(SNAPSTORAGE_HOLDER)+data_size; - - if(create_alt) - total_size += data_size; - - h = (SNAPSTORAGE_HOLDER *)mem_alloc(total_size, 1); - - /* set data */ - h->tick = tick; - h->tagtime = tagtime; - h->snap_size = data_size; - h->snap = (SNAPSHOT*)(h+1); - mem_copy(h->snap, data, data_size); - - if(create_alt) /* create alternative if wanted */ - { - h->alt_snap = (SNAPSHOT*)(((char *)h->snap) + data_size); - mem_copy(h->alt_snap, data, data_size); - } - else - h->alt_snap = 0; - - - /* link */ - h->next = 0; - h->prev = ss->last; - if(ss->last) - ss->last->next = h; - else - ss->first = h; - ss->last = h; -} - -int snapstorage_get(SNAPSTORAGE *ss, int tick, int64 *tagtime, SNAPSHOT **data, SNAPSHOT **alt_data) -{ - SNAPSTORAGE_HOLDER *h = ss->first; - - while(h) - { - if(h->tick == tick) - { - if(tagtime) - *tagtime = h->tagtime; - if(data) - *data = h->snap; - if(alt_data) - *alt_data = h->alt_snap; - return h->snap_size; - } - - h = h->next; - } - - return -1; -} - -/* SNAPBUILD */ - -void snapbuild_init(SNAPBUILD *sb) -{ - sb->data_size = 0; - sb->num_items = 0; -} - -SNAPSHOT_ITEM *snapbuild_get_item(SNAPBUILD *sb, int index) -{ - return (SNAPSHOT_ITEM *)&(sb->data[sb->offsets[index]]); -} - -int *snapbuild_get_item_data(SNAPBUILD *sb, int key) -{ - int i; - for(i = 0; i < sb->num_items; i++) - { - if(snapitem_key(snapbuild_get_item(sb, i)) == key) - return (int *)snapitem_data(snapbuild_get_item(sb, i)); - } - return 0; -} - -int snapbuild_finish(SNAPBUILD *sb, void *snapdata) -{ - /* flattern and make the snapshot */ - SNAPSHOT *snap = (SNAPSHOT *)snapdata; - int offset_size = sizeof(int)*sb->num_items; - snap->data_size = sb->data_size; - snap->num_items = sb->num_items; - mem_copy(snapshot_offsets(snap), sb->offsets, offset_size); - mem_copy(snapshot_datastart(snap), sb->data, sb->data_size); - return sizeof(SNAPSHOT) + offset_size + sb->data_size; -} - -void *snapbuild_new_item(SNAPBUILD *sb, int type, int id, int size) -{ - SNAPSHOT_ITEM *obj = (SNAPSHOT_ITEM *)(sb->data+sb->data_size); - - /*if(stress_prob(0.01f)) - { - size += ((rand()%5) - 2)*4; - if(size < 0) - size = 0; - }*/ - - mem_zero(obj, sizeof(SNAPSHOT_ITEM) + size); - obj->type_and_id = (type<<16)|id; - sb->offsets[sb->num_items] = sb->data_size; - sb->data_size += sizeof(SNAPSHOT_ITEM) + size; - sb->num_items++; - - dbg_assert(sb->data_size < MAX_SNAPSHOT_SIZE, "too much data"); - dbg_assert(sb->num_items < SNAPBUILD_MAX_ITEMS, "too many items"); - - return snapitem_data(obj); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.h b/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.h deleted file mode 100644 index 17ea0447d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/e_snapshot.h +++ /dev/null @@ -1,100 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef ENGINE_SNAPSHOT_H -#define ENGINE_SNAPSHOT_H - -#include - -/* SNAPSHOT */ - -#ifdef __cplusplus -extern "C" { -#endif - -enum -{ - MAX_SNAPSHOT_SIZE=64*1024 -}; - -typedef struct -{ - int type_and_id; -} SNAPSHOT_ITEM; - -typedef struct -{ - int data_size; - int num_items; -} SNAPSHOT; - -int *snapitem_data(SNAPSHOT_ITEM *item); -int snapitem_type(SNAPSHOT_ITEM *item); -int snapitem_id(SNAPSHOT_ITEM *item); -int snapitem_key(SNAPSHOT_ITEM *item); - -int *snapshot_offsets(SNAPSHOT *snap); -char *snapshot_datastart(SNAPSHOT *snap); - -SNAPSHOT_ITEM *snapshot_get_item(SNAPSHOT *snap, int index); -int snapshot_get_item_datasize(SNAPSHOT *snap, int index); -int snapshot_get_item_index(SNAPSHOT *snap, int key); - -void *snapshot_empty_delta(); -int snapshot_crc(SNAPSHOT *snap); -void snapshot_debug_dump(SNAPSHOT *snap); -int snapshot_create_delta(SNAPSHOT *from, SNAPSHOT *to, void *data); -int snapshot_unpack_delta(SNAPSHOT *from, SNAPSHOT *to, void *data, int data_size); - -/* SNAPSTORAGE */ - -typedef struct SNAPSTORAGE_HOLDER_t -{ - struct SNAPSTORAGE_HOLDER_t *prev; - struct SNAPSTORAGE_HOLDER_t *next; - - int64 tagtime; - int tick; - - int snap_size; - SNAPSHOT *snap; - SNAPSHOT *alt_snap; -} SNAPSTORAGE_HOLDER; - -typedef struct SNAPSTORAGE_t -{ - SNAPSTORAGE_HOLDER *first; - SNAPSTORAGE_HOLDER *last; -} SNAPSTORAGE; - -void snapstorage_init(SNAPSTORAGE *ss); -void snapstorage_purge_all(SNAPSTORAGE *ss); -void snapstorage_purge_until(SNAPSTORAGE *ss, int tick); -void snapstorage_add(SNAPSTORAGE *ss, int tick, int64 tagtime, int data_size, void *data, int create_alt); -int snapstorage_get(SNAPSTORAGE *ss, int tick, int64 *tagtime, SNAPSHOT **data, SNAPSHOT **alt_data); - -/* SNAPBUILD */ - -enum -{ - SNAPBUILD_MAX_ITEMS = 1024*2 -}; - -typedef struct SNAPBUILD -{ - char data[MAX_SNAPSHOT_SIZE]; - int data_size; - - int offsets[SNAPBUILD_MAX_ITEMS]; - int num_items; -} SNAPBUILD; - -void snapbuild_init(SNAPBUILD *sb); -SNAPSHOT_ITEM *snapbuild_get_item(SNAPBUILD *sb, int index); -int *snapbuild_get_item_data(SNAPBUILD *sb, int key); -int snapbuild_finish(SNAPBUILD *sb, void *snapdata); -void *snapbuild_new_item(SNAPBUILD *sb, int type, int id, int size); - -#ifdef __cplusplus -} -#endif - -#endif /* ENGINE_SNAPSHOT_H */ diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/important.txt b/project/jni/application/teeworlds-0.5.2/src/engine/external/important.txt deleted file mode 100644 index 305ccadcc..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/important.txt +++ /dev/null @@ -1,5 +0,0 @@ -The source code under this directory are external libraries -with their own licences. The source you find here is stripped -of unnessesary information. Please visit their websites for -more information and official releases. - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.c deleted file mode 100644 index b33f60ba0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.c +++ /dev/null @@ -1,877 +0,0 @@ -/* pnglite.c - pnglite library - For conditions of distribution and use, see copyright notice in pnglite.h -*/ -#define DO_CRC_CHECKS 1 -#define USE_ZLIB 1 - -#if USE_ZLIB -#include -#else -#include "zlite.h" -#endif - -#include -#include -#include -#include "pnglite.h" - - - -static png_alloc_t png_alloc; -static png_free_t png_free; - -static size_t file_read(png_t* png, void* out, size_t size, size_t numel) -{ - size_t result; - if(png->read_fun) - { - result = png->read_fun(out, size, numel, png->user_pointer); - } - else - { - if(!out) - { - result = fseek(png->user_pointer, (long)(size*numel), SEEK_CUR); - } - else - { - result = fread(out, size, numel, png->user_pointer); - } - } - - return result; -} - -static size_t file_write(png_t* png, void* p, size_t size, size_t numel) -{ - size_t result; - - if(png->write_fun) - { - result = png->write_fun(p, size, numel, png->user_pointer); - } - else - { - result = fwrite(p, size, numel, png->user_pointer); - } - - return result; -} - -static int file_read_ul(png_t* png, unsigned *out) -{ - unsigned char buf[4]; - - if(file_read(png, buf, 1, 4) != 4) - return PNG_FILE_ERROR; - - *out = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3]; - - return PNG_NO_ERROR; -} - -static int file_write_ul(png_t* png, unsigned in) -{ - unsigned char buf[4]; - - buf[0] = (in>>24) & 0xff; - buf[1] = (in>>16) & 0xff; - buf[2] = (in>>8) & 0xff; - buf[3] = (in) & 0xff; - - if(file_write(png, buf, 1, 4) != 4) - return PNG_FILE_ERROR; - - return PNG_NO_ERROR; -} - - -static unsigned get_ul(unsigned char* buf) -{ - unsigned result; - unsigned char foo[4]; - - memcpy(foo, buf, 4); - - result = (foo[0]<<24) | (foo[1]<<16) | (foo[2]<<8) | foo[3]; - - return result; -} - -static unsigned set_ul(unsigned char* buf, unsigned in) -{ - buf[0] = (in>>24) & 0xff; - buf[1] = (in>>16) & 0xff; - buf[2] = (in>>8) & 0xff; - buf[3] = (in) & 0xff; - - return PNG_NO_ERROR; -} - -int png_init(png_alloc_t pngalloc, png_free_t pngfree) -{ - if(pngalloc) - png_alloc = pngalloc; - else - png_alloc = &malloc; - - if(pngfree) - png_free = pngfree; - else - png_free = &free; - - return PNG_NO_ERROR; -} - -static int png_get_bpp(png_t* png) -{ - int bpp; - - switch(png->color_type) - { - case PNG_GREYSCALE: - bpp = 1; break; - case PNG_TRUECOLOR: - bpp = 3; break; - case PNG_INDEXED: - bpp = 1; break; - case PNG_GREYSCALE_ALPHA: - bpp = 2; break; - case PNG_TRUECOLOR_ALPHA: - bpp = 4; break; - default: - return PNG_FILE_ERROR; - } - - bpp *= png->depth/8; - - return bpp; -} - -static int png_read_ihdr(png_t* png) -{ - unsigned length; -#if DO_CRC_CHECKS - unsigned orig_crc; - unsigned calc_crc; -#endif - unsigned char ihdr[13+4]; /* length should be 13, make room for type (IHDR) */ - - file_read_ul(png, &length); - - if(length != 13) - { - printf("%d\n", length); - return PNG_CRC_ERROR; - } - - if(file_read(png, ihdr, 1, 13+4) != 13+4) - return PNG_EOF_ERROR; -#if DO_CRC_CHECKS - file_read_ul(png, &orig_crc); - - calc_crc = crc32(0L, 0, 0); - calc_crc = crc32(calc_crc, ihdr, 13+4); - - if(orig_crc != calc_crc) - return PNG_CRC_ERROR; -#else - file_read_ul(png); -#endif - - png->width = get_ul(ihdr+4); - png->height = get_ul(ihdr+8); - png->depth = ihdr[12]; - png->color_type = ihdr[13]; - png->compression_method = ihdr[14]; - png->filter_method = ihdr[15]; - png->interlace_method = ihdr[16]; - - if(png->color_type == PNG_INDEXED) - return PNG_NOT_SUPPORTED; - - if(png->depth != 8 && png->depth != 16) - return PNG_NOT_SUPPORTED; - - if(png->interlace_method) - return PNG_NOT_SUPPORTED; - - return PNG_NO_ERROR; -} - -static int png_write_ihdr(png_t* png) -{ - unsigned char ihdr[13+4]; - unsigned char *p = ihdr; - unsigned crc; - - file_write(png, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 1, 8); - - file_write_ul(png, 13); - - *p = 'I'; p++; - *p = 'H'; p++; - *p = 'D'; p++; - *p = 'R'; p++; - set_ul(p, png->width); p+=4; - set_ul(p, png->height); p+=4; - *p = png->depth; p++; - *p = png->color_type; p++; - *p = 0; p++; - *p = 0; p++; - *p = 0; p++; - - file_write(png, ihdr, 1, 13+4); - - crc = crc32(0L, 0, 0); - crc = crc32(crc, ihdr, 13+4); - - file_write_ul(png, crc); - - return PNG_NO_ERROR; -} - -void png_print_info(png_t* png) -{ - printf("PNG INFO:\n"); - printf("\twidth:\t\t%d\n", png->width); - printf("\theight:\t\t%d\n", png->height); - printf("\tdepth:\t\t%d\n", png->depth); - printf("\tcolor:\t\t"); - - switch(png->color_type) - { - case PNG_GREYSCALE: printf("greyscale\n"); break; - case PNG_TRUECOLOR: printf("truecolor\n"); break; - case PNG_INDEXED: printf("palette\n"); break; - case PNG_GREYSCALE_ALPHA: printf("greyscale with alpha\n"); break; - case PNG_TRUECOLOR_ALPHA: printf("truecolor with alpha\n"); break; - default: printf("unknown, this is not good\n"); break; - } - - printf("\tcompression:\t%s\n", png->compression_method?"unknown, this is not good":"inflate/deflate"); - printf("\tfilter:\t\t%s\n", png->filter_method?"unknown, this is not good":"adaptive"); - printf("\tinterlace:\t%s\n", png->interlace_method?"interlace":"no interlace"); -} - -int png_open_read(png_t* png, png_read_callback_t read_fun, void* user_pointer) -{ - char header[8]; - int result; - - png->read_fun = read_fun; - png->write_fun = 0; - png->user_pointer = user_pointer; - - if(!read_fun && !user_pointer) - return PNG_WRONG_ARGUMENTS; - - if(file_read(png, header, 1, 8) != 8) - return PNG_EOF_ERROR; - - if(memcmp(header, "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", 8) != 0) - return PNG_HEADER_ERROR; - - result = png_read_ihdr(png); - - png->bpp = (unsigned char)png_get_bpp(png); - - return result; -} - -int png_open_write(png_t* png, png_write_callback_t write_fun, void* user_pointer) -{ - png->write_fun = write_fun; - png->read_fun = 0; - png->user_pointer = user_pointer; - - if(!write_fun && !user_pointer) - return PNG_WRONG_ARGUMENTS; - - return PNG_NO_ERROR; -} - -int png_open(png_t* png, png_read_callback_t read_fun, void* user_pointer) -{ - return png_open_read(png, read_fun, user_pointer); -} - -int png_open_file_read(png_t *png, const char* filename) -{ - FILE* fp = fopen(filename, "rb"); - - if(!fp) - return PNG_FILE_ERROR; - - return png_open_read(png, 0, fp); -} - -int png_open_file_write(png_t *png, const char* filename) -{ - FILE* fp = fopen(filename, "wb"); - - if(!fp) - return PNG_FILE_ERROR; - - return png_open_write(png, 0, fp); -} - -int png_open_file(png_t *png, const char* filename) -{ - return png_open_file_read(png, filename); -} - -int png_close_file(png_t* png) -{ - fclose(png->user_pointer); - - return PNG_NO_ERROR; -} - -static int png_init_deflate(png_t* png, unsigned char* data, int datalen) -{ - z_stream *stream; - png->zs = png_alloc(sizeof(z_stream)); - - stream = png->zs; - - if(!stream) - return PNG_MEMORY_ERROR; - - memset(stream, 0, sizeof(z_stream)); - - if(deflateInit(stream, Z_DEFAULT_COMPRESSION) != Z_OK) - return PNG_ZLIB_ERROR; - - stream->next_in = data; - stream->avail_in = datalen; - - return PNG_NO_ERROR; -} - -static int png_init_inflate(png_t* png) -{ -#if USE_ZLIB - z_stream *stream; - png->zs = png_alloc(sizeof(z_stream)); -#else - zl_stream *stream; - png->zs = png_alloc(sizeof(zl_stream)); -#endif - - stream = png->zs; - - if(!stream) - return PNG_MEMORY_ERROR; - - - -#if USE_ZLIB - memset(stream, 0, sizeof(z_stream)); - if(inflateInit(stream) != Z_OK) - return PNG_ZLIB_ERROR; -#else - memset(stream, 0, sizeof(zl_stream)); - if(z_inflateInit(stream) != Z_OK) - return PNG_ZLIB_ERROR; -#endif - - stream->next_out = png->png_data; - stream->avail_out = png->png_datalen; - - return PNG_NO_ERROR; -} - -static int png_end_deflate(png_t* png) -{ - z_stream *stream = png->zs; - - if(!stream) - return PNG_MEMORY_ERROR; - - deflateEnd(stream); - - png_free(png->zs); - - return PNG_NO_ERROR; -} - -static int png_end_inflate(png_t* png) -{ -#if USE_ZLIB - z_stream *stream = png->zs; -#else - zl_stream *stream = png->zs; -#endif - - if(!stream) - return PNG_MEMORY_ERROR; - -#if USE_ZLIB - if(inflateEnd(stream) != Z_OK) -#else - if(z_inflateEnd(stream) != Z_OK) -#endif - { - printf("ZLIB says: %s\n", stream->msg); - return PNG_ZLIB_ERROR; - } - - png_free(png->zs); - - return PNG_NO_ERROR; -} - -static int png_inflate(png_t* png, char* data, int len) -{ - int result; -#if USE_ZLIB - z_stream *stream = png->zs; -#else - zl_stream *stream = png->zs; -#endif - - if(!stream) - return PNG_MEMORY_ERROR; - - stream->next_in = (unsigned char*)data; - stream->avail_in = len; - -#if USE_ZLIB - result = inflate(stream, Z_SYNC_FLUSH); -#else - result = z_inflate(stream); -#endif - - if(result != Z_STREAM_END && result != Z_OK) - { - printf("%s\n", stream->msg); - return PNG_ZLIB_ERROR; - } - - if(stream->avail_in != 0) - return PNG_ZLIB_ERROR; - - return PNG_NO_ERROR; -} - -static int png_deflate(png_t* png, char* outdata, int outlen, int *outwritten) -{ - int result; - - z_stream *stream = png->zs; - - - if(!stream) - return PNG_MEMORY_ERROR; - - stream->next_out = (unsigned char*)outdata; - stream->avail_out = outlen; - - result = deflate(stream, Z_SYNC_FLUSH); - - *outwritten = outlen - stream->avail_out; - - if(result != Z_STREAM_END && result != Z_OK) - { - printf("%s\n", stream->msg); - return PNG_ZLIB_ERROR; - } - - return result; -} - -static int png_write_idats(png_t* png, unsigned char* data) -{ - unsigned char *chunk; - unsigned long written; - unsigned long crc; - unsigned size = png->width * png->height * png->bpp + png->height; - - (void)png_init_deflate; - (void)png_end_deflate; - (void)png_deflate; - - chunk = png_alloc(size); - memcpy(chunk, "IDAT", 4); - - written = size; - compress(chunk+4, &written, data, size); - - crc = crc32(0L, Z_NULL, 0); - crc = crc32(crc, chunk, written+4); - set_ul(chunk+written+4, crc); - file_write_ul(png, written); - file_write(png, chunk, 1, written+8); - png_free(chunk); - - file_write_ul(png, 0); - file_write(png, "IEND", 1, 4); - crc = crc32(0L, (const unsigned char *)"IEND", 4); - file_write_ul(png, crc); - - return PNG_NO_ERROR; -} - -static int png_read_idat(png_t* png, unsigned firstlen) -{ - unsigned type = 0; - char *chunk; - int result; - unsigned length = firstlen; - unsigned old_len = length; - -#if DO_CRC_CHECKS - unsigned orig_crc; - unsigned calc_crc; -#endif - - chunk = png_alloc(firstlen); - - result = png_init_inflate(png); - - if(result != PNG_NO_ERROR) - { - png_end_inflate(png); - png_free(chunk); - return result; - } - - do - { - if(file_read(png, chunk, 1, length) != length) - { - png_end_inflate(png); - png_free(chunk); - return PNG_FILE_ERROR; - } - -#if DO_CRC_CHECKS - calc_crc = crc32(0L, Z_NULL, 0); - calc_crc = crc32(calc_crc, (unsigned char*)"IDAT", 4); - calc_crc = crc32(calc_crc, (unsigned char*)chunk, length); - - file_read_ul(png, &orig_crc); - - if(orig_crc != calc_crc) - { - result = PNG_CRC_ERROR; - break; - } -#else - file_read_ul(png); -#endif - - result = png_inflate(png, chunk, length); - - if(result != PNG_NO_ERROR) break; - - file_read_ul(png, &length); - - if(length > old_len) - { - png_free(chunk); - chunk = png_alloc(length); - old_len = length; - } - - if(file_read(png, &type, 1, 4) != 4) - { - result = PNG_FILE_ERROR; - break; - } - - }while(type == *(unsigned int*)"IDAT"); - - if(type == *(unsigned int*)"IEND") - result = PNG_DONE; - - png_free(chunk); - png_end_inflate(png); - - return result; -} - -static int png_process_chunk(png_t* png) -{ - int result = PNG_NO_ERROR; - unsigned type; - unsigned length; - - file_read_ul(png, &length); - - if(file_read(png, &type, 1, 4) != 4) - return PNG_FILE_ERROR; - - if(type == *(unsigned int*)"IDAT") /* if we found an idat, all other idats should be followed with no other chunks in between */ - { - png->png_datalen = png->width * png->height * png->bpp + png->height; - png->png_data = png_alloc(png->png_datalen); - - if(!png->png_data) - return PNG_MEMORY_ERROR; - - return png_read_idat(png, length); - } - else if(type == *(unsigned int*)"IEND") - { - return PNG_DONE; - } - else - { - file_read(png, 0, 1, length + 4); /* unknown chunk */ - } - - return result; -} - -static void png_filter_sub(int stride, unsigned char* in, unsigned char* out, int len) -{ - int i; - unsigned char a = 0; - - for(i = 0; i < len; i++) - { - if(i >= stride) - a = out[i - stride]; - - out[i] = in[i] + a; - } -} - -static void png_filter_up(int stride, unsigned char* in, unsigned char* out, unsigned char* prev_line, int len) -{ - int i; - - if(prev_line) - { - for(i = 0; i < len; i++) - out[i] = in[i] + prev_line[i]; - } - else - memcpy(out, in, len); -} - -static void png_filter_average(int stride, unsigned char* in, unsigned char* out, unsigned char* prev_line, int len) -{ - int i; - unsigned char a = 0; - unsigned char b = 0; - unsigned int sum = 0; - - for(i = 0; i < len; i++) - { - if(prev_line) - b = prev_line[i]; - - if(i >= stride) - a = out[i - stride]; - - sum = a; - sum += b; - - out[i] = (char)(in[i] + sum/2); - } -} - -static unsigned char png_paeth(unsigned char a, unsigned char b, unsigned char c) -{ - int p = (int)a + b - c; - int pa = abs(p - a); - int pb = abs(p - b); - int pc = abs(p - c); - - int pr; - - if(pa <= pb && pa <= pc) - pr = a; - else if(pb <= pc) - pr = b; - else - pr = c; - - return (char)pr; -} - -static void png_filter_paeth(int stride, unsigned char* in, unsigned char* out, unsigned char* prev_line, int len) -{ - int i; - unsigned char a; - unsigned char b; - unsigned char c; - - for(i = 0; i < len; i++) - { - if(prev_line && i >= stride) - { - a = out[i - stride]; - b = prev_line[i]; - c = prev_line[i - stride]; - } - else - { - if(prev_line) - b = prev_line[i]; - else - b = 0; - - if(i >= stride) - a = out[i - stride]; - else - a = 0; - - c = 0; - } - - out[i] = in[i] + png_paeth(a, b, c); - } -} - -static int png_filter(png_t* png, unsigned char* data) -{ - - - return PNG_NO_ERROR; -} - -static int png_unfilter(png_t* png, unsigned char* data) -{ - unsigned i; - unsigned pos = 0; - unsigned outpos = 0; - unsigned char *filtered = png->png_data; - - int stride = png->bpp; - - while(pos < png->png_datalen) - { - unsigned char filter = filtered[pos]; - - pos++; - - if(png->depth == 16) - { - for(i = 0; i < png->width * stride; i+=2) - { - *(short*)(filtered+pos+i) = (filtered[pos+i] << 8) | filtered[pos+i+1]; - } - } - - switch(filter) - { - case 0: /* none */ - memcpy(data+outpos, filtered+pos, png->width * stride); - break; - case 1: /* sub */ - png_filter_sub(stride, filtered+pos, data+outpos, png->width * stride); - break; - case 2: /* up */ - if(outpos) - png_filter_up(stride, filtered+pos, data+outpos, data + outpos - (png->width*stride), png->width*stride); - else - png_filter_up(stride, filtered+pos, data+outpos, 0, png->width*stride); - break; - case 3: /* average */ - if(outpos) - png_filter_average(stride, filtered+pos, data+outpos, data + outpos - (png->width*stride), png->width*stride); - else - png_filter_average(stride, filtered+pos, data+outpos, 0, png->width*stride); - break; - case 4: /* paeth */ - if(outpos) - png_filter_paeth(stride, filtered+pos, data+outpos, data + outpos - (png->width*stride), png->width*stride); - else - png_filter_paeth(stride, filtered+pos, data+outpos, 0, png->width*stride); - break; - default: - return PNG_UNKNOWN_FILTER; - } - - outpos += png->width * stride; - pos += png->width * stride; - } - - return PNG_NO_ERROR; -} - -int png_get_data(png_t* png, unsigned char* data) -{ - int result = PNG_NO_ERROR; - - while(result == PNG_NO_ERROR) - { - result = png_process_chunk(png); - } - - if(result != PNG_DONE) - { - png_free(png->png_data); - return result; - } - - result = png_unfilter(png, data); - - png_free(png->png_data); - - return result; -} - -int png_set_data(png_t* png, unsigned width, unsigned height, char depth, int color, unsigned char* data) -{ - int i; - unsigned char *filtered; - png->width = width; - png->height = height; - png->depth = depth; - png->color_type = color; - png->bpp = png_get_bpp(png); - - filtered = png_alloc(width * height * png->bpp + height); - - for(i = 0; i < png->height; i++) - { - filtered[i*png->width*png->bpp+i] = 0; - memcpy(&filtered[i*png->width*png->bpp+i+1], data + i * png->width*png->bpp, png->width*png->bpp); - } - - png_filter(png, filtered); - png_write_ihdr(png); - png_write_idats(png, filtered); - - png_free(filtered); - return PNG_NO_ERROR; -} - - -char* png_error_string(int error) -{ - switch(error) - { - case PNG_NO_ERROR: - return "No error"; - case PNG_FILE_ERROR: - return "Unknown file error."; - case PNG_HEADER_ERROR: - return "No PNG header found. Are you sure this is a PNG?"; - case PNG_IO_ERROR: - return "Failure while reading file."; - case PNG_EOF_ERROR: - return "Reached end of file."; - case PNG_CRC_ERROR: - return "CRC or chunk length error."; - case PNG_MEMORY_ERROR: - return "Could not allocate memory."; - case PNG_ZLIB_ERROR: - return "zlib reported an error."; - case PNG_UNKNOWN_FILTER: - return "Unknown filter method used in scanline."; - case PNG_DONE: - return "PNG done"; - case PNG_NOT_SUPPORTED: - return "The PNG is unsupported by pnglite, too bad for you!"; - case PNG_WRONG_ARGUMENTS: - return "Wrong combination of arguments passed to png_open. You must use either a read_function or supply a file pointer to use."; - default: - return "Unknown error."; - }; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.h b/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.h deleted file mode 100644 index 72ff1c52c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/pnglite/pnglite.h +++ /dev/null @@ -1,227 +0,0 @@ -/* pnglite.h - Interface for pnglite library - Copyright (c) 2007 Daniel Karling - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. - - Daniel Karling - daniel.karling@gmail.com - */ - - -#ifndef _PNGLITE_H_ -#define _PNGLITE_H_ - -#ifdef __cplusplus -extern "C"{ -#endif - -/* - Enumerations for pnglite. - Negative numbers are error codes and 0 and up are okay responses. -*/ - -enum -{ - PNG_DONE = 1, - PNG_NO_ERROR = 0, - PNG_FILE_ERROR = -1, - PNG_HEADER_ERROR = -2, - PNG_IO_ERROR = -3, - PNG_EOF_ERROR = -4, - PNG_CRC_ERROR = -5, - PNG_MEMORY_ERROR = -6, - PNG_ZLIB_ERROR = -7, - PNG_UNKNOWN_FILTER = -8, - PNG_NOT_SUPPORTED = -9, - PNG_WRONG_ARGUMENTS = -10 -}; - -/* - The five different kinds of color storage in PNG files. -*/ - -enum -{ - PNG_GREYSCALE = 0, - PNG_TRUECOLOR = 2, - PNG_INDEXED = 3, - PNG_GREYSCALE_ALPHA = 4, - PNG_TRUECOLOR_ALPHA = 6 -}; - -/* - Typedefs for callbacks. -*/ - -typedef unsigned (*png_write_callback_t)(void* input, unsigned long size, unsigned long numel, void* user_pointer); -typedef unsigned (*png_read_callback_t)(void* output, unsigned long size, unsigned long numel, void* user_pointer); -typedef void (*png_free_t)(void* p); -typedef void * (*png_alloc_t)(unsigned long s); - -typedef struct -{ - void* zs; /* pointer to z_stream */ - png_read_callback_t read_fun; - png_write_callback_t write_fun; - void* user_pointer; - - unsigned char* png_data; - unsigned png_datalen; - - unsigned width; - unsigned height; - unsigned char depth; - unsigned char color_type; - unsigned char compression_method; - unsigned char filter_method; - unsigned char interlace_method; - unsigned char bpp; -}png_t; - -/* - Function: png_init - - This function initializes pnglite. The parameters can be used to set your own memory allocation routines following these formats: - - > void* (*custom_alloc)(unsigned long s) - > void (*custom_free)(void* p) - Parameters: - pngalloc - Pointer to custom allocation routine. If 0 is passed, malloc from libc will be used. - pngfree - Pointer to custom free routine. If 0 is passed, free from libc will be used. - - Returns: - Always returns PNG_NO_ERROR. -*/ - -int png_init(png_alloc_t pngalloc, png_free_t pngfree); - -/* - Function: png_open_file - - This function is used to open a png file with the internal file IO system. This function should be used instead of - png_open if no custom read function is used. - - Parameters: - png - Empty png_t struct. - filename - Filename of the file to be opened. - - Returns: - PNG_NO_ERROR on success, otherwise an error code. -*/ - -int png_open_file(png_t *png, const char* filename); - -int png_open_file_read(png_t *png, const char* filename); -int png_open_file_write(png_t *png, const char* filename); - -/* - Function: png_open - - This function reads or writes a png from/to the specified callback. The callbacks should be of the format: - - > unsigned long (*png_write_callback_t)(void* input, unsigned long size, unsigned long numel, void* user_pointer); - > unsigned long (*png_read_callback_t)(void* output, unsigned long size, unsigned long numel, void* user_pointer). - - Only one callback has to be specified. The read callback in case of PNG reading, otherwise the write callback. - - Writing: - The callback will be called like fwrite. - - Reading: - The callback will be called each time pnglite needs more data. The callback should read as much data as requested, - or return 0. This should always be possible if the PNG is sane. If the output-buffer is a null-pointer the callback - should only skip ahead the specified number of elements. If the callback is a null-pointer the user_pointer will be - treated as a file pointer (use png_open_file instead). - - Parameters: - png - png_t struct - read_fun - Callback function for reading. - user_pointer - User pointer to be passed to read_fun. - - Returns: - PNG_NO_ERROR on success, otherwise an error code. -*/ - -int png_open(png_t* png, png_read_callback_t read_fun, void* user_pointer); - -int png_open_read(png_t* png, png_read_callback_t read_fun, void* user_pointer); -int png_open_write(png_t* png, png_write_callback_t write_fun, void* user_pointer); - -/* - Function: png_print_info - - This function prints some info about the opened png file to stdout. - - Parameters: - png - png struct to get info from. -*/ - -void png_print_info(png_t* png); - -/* - Function: png_error_string - - This function translates an error code to a human readable string. - - Parameters: - error - Error code. - - Returns: - Pointer to string. -*/ - -char* png_error_string(int error); - -/* - Function: png_get_data - - This function decodes the opened png file and stores the result in data. data should be big enough to hold the decoded png. Required size will be: - - > width*height*(bytes per pixel) - - Parameters: - data - Where to store result. - - Returns: - PNG_NO_ERROR on success, otherwise an error code. -*/ - -int png_get_data(png_t* png, unsigned char* data); - -int png_set_data(png_t* png, unsigned width, unsigned height, char depth, int color, unsigned char* data); - -/* - Function: png_close_file - - Closes an open png file pointer. Should only be used when the png has been opened with png_open_file. - - Parameters: - png - png to close. - - Returns: - PNG_NO_ERROR -*/ - -int png_close_file(png_t* png); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arm.S b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arm.S deleted file mode 100644 index 4f2998923..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arm.S +++ /dev/null @@ -1,461 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -/* This is an assembly optimized version of the following WavPack function: - * - * void decorr_stereo_pass_cont (struct decorr_pass *dpp, - * long *buffer, long sample_count); - * - * It performs a single pass of stereo decorrelation on the provided buffer. - * Note that this version of the function requires that the 8 previous stereo - * samples are visible and correct. In other words, it ignores the "samples_*" - * fields in the decorr_pass structure and gets the history data directly - * from the buffer. It does, however, return the appropriate history samples - * to the decorr_pass structure before returning. - * - * This is written to work on a ARM7TDMI processor. This version only uses the - * 32-bit multiply-accumulate instruction and so will overflow with 24-bit - * WavPack files. - */ - .text - .align - .global decorr_stereo_pass_cont_arm - -/* - * on entry: - * - * r0 = struct decorr_pass *dpp - * r1 = long *buffer - * r2 = long sample_count - */ - -decorr_stereo_pass_cont_arm: - - stmfd sp!, {r4 - r8, r10, r11, lr} - mov r5, r0 @ r5 = dpp - mov r11, #512 @ r11 = 512 for rounding - ldrsh r6, [r0, #2] @ r6 = dpp->delta - ldrsh r4, [r0, #4] @ r4 = dpp->weight_A - ldrsh r0, [r0, #6] @ r0 = dpp->weight_B - cmp r2, #0 @ exit if no samples to process - beq common_exit - - add r7, r1, r2, asl #3 @ r7 = buffer ending position - ldrsh r2, [r5, #0] @ r2 = dpp->term - cmp r2, #0 - bmi minus_term - - ldr lr, [r1, #-16] @ load 2 sample history from buffer - ldr r10, [r1, #-12] @ for terms 2, 17, and 18 - ldr r8, [r1, #-8] - ldr r3, [r1, #-4] - cmp r2, #17 - beq term_17_loop - cmp r2, #18 - beq term_18_loop - cmp r2, #2 - beq term_2_loop - b term_default_loop @ else handle default (1-8, except 2) - -minus_term: - mov r10, #1024 @ r10 = -1024 for weight clipping - rsb r10, r10, #0 @ (only used for negative terms) - cmn r2, #1 - beq term_minus_1 - cmn r2, #2 - beq term_minus_2 - cmn r2, #3 - beq term_minus_3 - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = 17 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample - * r3 = previous right sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = current decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_17_loop: - rsbs ip, lr, r8, asl #1 @ decorr value = (2 * prev) - 2nd prev - mov lr, r8 @ previous becomes 2nd previous - ldr r2, [r1], #4 @ get sample & update pointer - mla r8, ip, r4, r11 @ mult decorr value by weight, round, - add r8, r2, r8, asr #10 @ shift, and add to new sample - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L325 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L325: rsbs ip, r10, r3, asl #1 @ do same thing for right channel - mov r10, r3 - ldr r2, [r1], #4 - mla r3, ip, r0, r11 - add r3, r2, r3, asr #10 - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L329 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L329: cmp r7, r1 @ loop back if more samples to do - bhi term_17_loop - b store_1718 @ common exit for terms 17 & 18 - -/* - ****************************************************************************** - * Loop to handle term = 18 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample - * r3 = previous right sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_18_loop: - sub ip, r8, lr @ decorr value = - mov lr, r8 @ ((3 * prev) - 2nd prev) >> 1 - adds ip, r8, ip, asr #1 - ldr r2, [r1], #4 @ get sample & update pointer - mla r8, ip, r4, r11 @ mult decorr value by weight, round, - add r8, r2, r8, asr #10 @ shift, and add to new sample - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L337 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L337: sub ip, r3, r10 @ do same thing for right channel - mov r10, r3 - adds ip, r3, ip, asr #1 - ldr r2, [r1], #4 - mla r3, ip, r0, r11 - add r3, r2, r3, asr #10 - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L341 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L341: cmp r7, r1 @ loop back if more samples to do - bhi term_18_loop - -/* common exit for terms 17 & 18 */ - -store_1718: - str r3, [r5, #40] @ store sample history into struct - str r8, [r5, #8] - str r10, [r5, #44] - str lr, [r5, #12] - b common_exit @ and return - -/* - ****************************************************************************** - * Loop to handle term = 2 condition - * (note that this case can be handled by the default term handler (1-8), but - * this special case is faster because it doesn't have to read memory twice) - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample - * r3 = previous right sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_2_loop: - movs ip, lr @ get decorrelation value & test - mov lr, r8 @ previous becomes 2nd previous - ldr r2, [r1], #4 @ get sample & update pointer - mla r8, ip, r4, r11 @ mult decorr value by weight, round, - add r8, r2, r8, asr #10 @ shift, and add to new sample - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L225 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L225: movs ip, r10 @ do same thing for right channel - mov r10, r3 - ldr r2, [r1], #4 - mla r3, ip, r0, r11 - add r3, r2, r3, asr #10 - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L229 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L229: cmp r7, r1 @ loop back if more samples to do - bhi term_2_loop - b default_term_exit @ this exit updates all dpp->samples - -/* - ****************************************************************************** - * Loop to handle default term condition - * - * r0 = dpp->weight_B r8 = result accumulator - * r1 = bptr r9 = - * r2 = dpp->term r10 = - * r3 = decorrelation value r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = - * r7 = eptr pc = - ******************************************************************************* - */ - -term_default_loop: - ldr ip, [r1] @ get original sample - ldr r3, [r1, -r2, asl #3] @ get decorrelation value based on term - mla r8, r3, r4, r11 @ mult decorr value by weight, round, - add r8, ip, r8, asr #10 @ shift and add to new sample - str r8, [r1], #4 @ store update sample - cmp r3, #0 - cmpne ip, #0 - beq .L350 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L350: ldr ip, [r1] @ do the same thing for right channel - ldr r3, [r1, -r2, asl #3] - mla r8, r3, r0, r11 - add r8, ip, r8, asr #10 - str r8, [r1], #4 - cmp r3, #0 - cmpne ip, #0 - beq .L354 - teq ip, r3 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L354: cmp r7, r1 @ loop back if more samples to do - bhi term_default_loop - -/* - * This exit is used by terms 1-8 to store the previous 8 samples into the decorr - * structure (even if they are not all used for the given term) - */ - -default_term_exit: - ldrsh r3, [r5, #0] - sub ip, r3, #1 - mov lr, #7 - -.L358: and r3, ip, #7 - add r3, r5, r3, asl #2 - ldr r2, [r1, #-4] - str r2, [r3, #40] - ldr r2, [r1, #-8]! - str r2, [r3, #8] - sub ip, ip, #1 - sub lr, lr, #1 - cmn lr, #1 - bne .L358 - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -1 condition - * - * r0 = dpp->weight_B r8 = - * r1 = bptr r9 = - * r2 = intermediate result r10 = -1024 (for clipping) - * r3 = previous right sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = updated left sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_1: - ldr r3, [r1, #-4] - -term_minus_1_loop: - ldr ip, [r1] @ for left channel the decorrelation value - mla r2, r3, r4, r11 @ is the previous right sample (in r3) - add lr, ip, r2, asr #10 - str lr, [r1], #8 - cmp r3, #0 - cmpne ip, #0 - beq .L361 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #1024 - movgt r4, #1024 - cmp r4, r10 - movlt r4, r10 - -.L361: ldr r2, [r1, #-4] @ for right channel the decorrelation value - mla r3, lr, r0, r11 @ is the just updated right sample (in lr) - add r3, r2, r3, asr #10 - str r3, [r1, #-4] - cmp lr, #0 - cmpne r2, #0 - beq .L369 - teq r2, lr - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #1024 @ then clip weight to +/-1024 - movgt r0, #1024 - cmp r0, r10 - movlt r0, r10 - -.L369: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_1_loop - - str r3, [r5, #8] @ else store right sample and exit - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -2 condition - * (note that the channels are processed in the reverse order here) - * - * r0 = dpp->weight_B r8 = - * r1 = bptr r9 = - * r2 = intermediate result r10 = -1024 (for clipping) - * r3 = previous left sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = updated right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_2: - ldr r3, [r1, #-8] - -term_minus_2_loop: - ldr ip, [r1, #4] @ for right channel the decorrelation value - mla r2, r3, r0, r11 @ is the previous left sample (in r3) - add lr, ip, r2, asr #10 - str lr, [r1, #4] - cmp r3, #0 - cmpne ip, #0 - beq .L380 - teq ip, r3 @ update weight based on signs - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #1024 @ then clip weight to +/-1024 - movgt r0, #1024 - cmp r0, r10 - movlt r0, r10 - -.L380: ldr r2, [r1, #0] @ for left channel the decorrelation value - mla r3, lr, r4, r11 @ is the just updated left sample (in lr) - add r3, r2, r3, asr #10 - str r3, [r1], #8 - cmp lr, #0 - cmpne r2, #0 - beq .L388 - teq r2, lr - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #1024 - movgt r4, #1024 - cmp r4, r10 - movlt r4, r10 - -.L388: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_2_loop - - str r3, [r5, #40] @ else store left channel and exit - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -3 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current left sample r10 = -1024 (for clipping) - * r3 = previous right sample r11 = 512 (for rounding) - * r4 = dpp->weight_A ip = intermediate result - * r5 = dpp sp = - * r6 = dpp->delta lr = - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_3: - ldr r3, [r1, #-4] @ load previous samples - ldr r8, [r1, #-8] - -term_minus_3_loop: - ldr ip, [r1] - mla r2, r3, r4, r11 - add r2, ip, r2, asr #10 - str r2, [r1], #4 - cmp r3, #0 - cmpne ip, #0 - beq .L399 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #1024 @ then clip weight to +/-1024 - movgt r4, #1024 - cmp r4, r10 - movlt r4, r10 - -.L399: movs ip, r8 @ ip = previous left we use now - mov r8, r2 @ r8 = current left we use next time - ldr r2, [r1], #4 - mla r3, ip, r0, r11 - add r3, r2, r3, asr #10 - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L407 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #1024 - movgt r0, #1024 - cmp r0, r10 - movlt r0, r10 - -.L407: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_3_loop - - str r3, [r5, #8] @ else store previous samples & exit - str r8, [r5, #40] - -/* - * Before finally exiting we must store weights back for next time - */ - -common_exit: - strh r4, [r5, #4] - strh r0, [r5, #6] - ldmfd sp!, {r4 - r8, r10, r11, pc} - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arml.S b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arml.S deleted file mode 100644 index 7da005139..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/arml.S +++ /dev/null @@ -1,491 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -/* This is an assembly optimized version of the following WavPack function: - * - * void decorr_stereo_pass_cont (struct decorr_pass *dpp, - * long *buffer, long sample_count); - * - * It performs a single pass of stereo decorrelation on the provided buffer. - * Note that this version of the function requires that the 8 previous stereo - * samples are visible and correct. In other words, it ignores the "samples_*" - * fields in the decorr_pass structure and gets the history data directly - * from the buffer. It does, however, return the appropriate history samples - * to the decorr_pass structure before returning. - * - * This is written to work on a ARM7TDMI processor. This version uses the - * 64-bit multiply-accumulate instruction and so can be used with all - * WavPack files. However, for optimum performance with 16-bit WavPack - * files, there is a faster version that only uses the 32-bit MLA - * instruction. - */ - - .text - .align - .global decorr_stereo_pass_cont_arml - -/* - * on entry: - * - * r0 = struct decorr_pass *dpp - * r1 = long *buffer - * r2 = long sample_count - */ - -decorr_stereo_pass_cont_arml: - - stmfd sp!, {r4 - r8, r10, r11, lr} - mov r5, r0 @ r5 = dpp - mov r11, #512 @ r11 = 512 for rounding - ldrsh r6, [r0, #2] @ r6 = dpp->delta - ldrsh r4, [r0, #4] @ r4 = dpp->weight_A - ldrsh r0, [r0, #6] @ r0 = dpp->weight_B - cmp r2, #0 @ exit if no samples to process - beq common_exit - - mov r0, r0, asl #18 @ for 64-bit math we use weights << 18 - mov r4, r4, asl #18 - mov r6, r6, asl #18 - add r7, r1, r2, asl #3 @ r7 = buffer ending position - ldrsh r2, [r5, #0] @ r2 = dpp->term - cmp r2, #0 - blt minus_term - - ldr lr, [r1, #-16] @ load 2 sample history from buffer - ldr r10, [r1, #-12] @ for terms 2, 17, and 18 - ldr r8, [r1, #-8] - ldr r3, [r1, #-4] - - cmp r2, #18 - beq term_18_loop - mov lr, lr, asl #4 - mov r10, r10, asl #4 - cmp r2, #2 - beq term_2_loop - cmp r2, #17 - beq term_17_loop - b term_default_loop - -minus_term: - mov r10, #(1024 << 18) @ r10 = -1024 << 18 for weight clipping - rsb r10, r10, #0 @ (only used for negative terms) - cmn r2, #1 - beq term_minus_1 - cmn r2, #2 - beq term_minus_2 - cmn r2, #3 - beq term_minus_3 - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = 17 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample << 4 - * r3 = previous right sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = current decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample << 4 - * r7 = eptr pc = - ******************************************************************************* - */ - -term_17_loop: - rsbs ip, lr, r8, asl #5 @ decorr value = (2 * prev) - 2nd prev - mov lr, r8, asl #4 @ previous becomes 2nd previous - ldr r2, [r1], #4 @ get sample & update pointer - mov r11, #0x80000000 - mov r8, r2 - smlalne r11, r8, r4, ip - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L325 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L325: rsbs ip, r10, r3, asl #5 @ do same thing for right channel - mov r10, r3, asl #4 - ldr r2, [r1], #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r0, ip - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L329 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L329: cmp r7, r1 @ loop back if more samples to do - bhi term_17_loop - mov lr, lr, asr #4 - mov r10, r10, asr #4 - b store_1718 @ common exit for terms 17 & 18 - -/* - ****************************************************************************** - * Loop to handle term = 18 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample - * r3 = previous right sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_18_loop: - rsb ip, lr, r8 @ decorr value = - mov lr, r8 @ ((3 * prev) - 2nd prev) >> 1 - add ip, lr, ip, asr #1 - movs ip, ip, asl #4 - ldr r2, [r1], #4 @ get sample & update pointer - mov r11, #0x80000000 - mov r8, r2 - smlalne r11, r8, r4, ip - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L337 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L337: rsb ip, r10, r3 @ do same thing for right channel - mov r10, r3 - add ip, r10, ip, asr #1 - movs ip, ip, asl #4 - ldr r2, [r1], #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r0, ip - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L341 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L341: cmp r7, r1 @ loop back if more samples to do - bhi term_18_loop - -/* common exit for terms 17 & 18 */ - -store_1718: - str r3, [r5, #40] @ store sample history into struct - str r8, [r5, #8] - str r10, [r5, #44] - str lr, [r5, #12] - b common_exit @ and return - -/* - ****************************************************************************** - * Loop to handle term = 2 condition - * (note that this case can be handled by the default term handler (1-8), but - * this special case is faster because it doesn't have to read memory twice) - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current sample r10 = second previous left sample << 4 - * r3 = previous right sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = decorrelation value - * r5 = dpp sp = - * r6 = dpp->delta lr = second previous right sample << 4 - * r7 = eptr pc = - ******************************************************************************* - */ - -term_2_loop: - movs ip, lr @ get decorrelation value & test - ldr r2, [r1], #4 @ get sample & update pointer - mov lr, r8, asl #4 @ previous becomes 2nd previous - mov r11, #0x80000000 - mov r8, r2 - smlalne r11, r8, r4, ip - strne r8, [r1, #-4] @ if change possible, store sample back - cmpne r2, #0 - beq .L225 - teq ip, r2 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L225: movs ip, r10 @ do same thing for right channel - ldr r2, [r1], #4 - mov r10, r3, asl #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r0, ip - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L229 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L229: cmp r7, r1 @ loop back if more samples to do - bhi term_2_loop - - b default_term_exit @ this exit updates all dpp->samples - -/* - ****************************************************************************** - * Loop to handle default term condition - * - * r0 = dpp->weight_B r8 = result accumulator - * r1 = bptr r9 = - * r2 = dpp->term r10 = - * r3 = decorrelation value r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = - * r7 = eptr pc = - ******************************************************************************* - */ - -term_default_loop: - ldr r3, [r1, -r2, asl #3] @ get decorrelation value based on term - ldr ip, [r1], #4 @ get original sample and bump ptr - movs r3, r3, asl #4 - mov r11, #0x80000000 - mov r8, ip - smlalne r11, r8, r4, r3 - strne r8, [r1, #-4] @ if possibly changed, store updated sample - cmpne ip, #0 - beq .L350 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - -.L350: ldr r3, [r1, -r2, asl #3] @ do the same thing for right channel - ldr ip, [r1], #4 - movs r3, r3, asl #4 - mov r11, #0x80000000 - mov r8, ip - smlalne r11, r8, r0, r3 - strne r8, [r1, #-4] - cmpne ip, #0 - beq .L354 - teq ip, r3 - submi r0, r0, r6 - addpl r0, r0, r6 - -.L354: cmp r7, r1 @ loop back if more samples to do - bhi term_default_loop - -/* - * This exit is used by terms 1-8 to store the previous 8 samples into the decorr - * structure (even if they are not all used for the given term) - */ - -default_term_exit: - ldrsh r3, [r5, #0] - sub ip, r3, #1 - mov lr, #7 - -.L358: and r3, ip, #7 - add r3, r5, r3, asl #2 - ldr r2, [r1, #-4] - str r2, [r3, #40] - ldr r2, [r1, #-8]! - str r2, [r3, #8] - sub ip, ip, #1 - sub lr, lr, #1 - cmn lr, #1 - bne .L358 - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -1 condition - * - * r0 = dpp->weight_B r8 = - * r1 = bptr r9 = - * r2 = intermediate result r10 = -1024 (for clipping) - * r3 = previous right sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = updated left sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_1: - ldr r3, [r1, #-4] - -term_minus_1_loop: - ldr ip, [r1], #8 @ for left channel the decorrelation value - movs r3, r3, asl #4 @ is the previous right sample (in r3) - mov r11, #0x80000000 - mov lr, ip - smlalne r11, lr, r4, r3 - strne lr, [r1, #-8] - cmpne ip, #0 - beq .L361 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #(1024 << 18) - movgt r4, #(1024 << 18) - cmp r4, r10 - movlt r4, r10 - -.L361: ldr r2, [r1, #-4] @ for right channel the decorrelation value - movs lr, lr, asl #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r0, lr - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L369 - teq r2, lr - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #(1024 << 18) @ then clip weight to +/-1024 - movgt r0, #(1024 << 18) - cmp r0, r10 - movlt r0, r10 - -.L369: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_1_loop - - str r3, [r5, #8] @ else store right sample and exit - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -2 condition - * (note that the channels are processed in the reverse order here) - * - * r0 = dpp->weight_B r8 = - * r1 = bptr r9 = - * r2 = intermediate result r10 = -1024 (for clipping) - * r3 = previous left sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = current sample - * r5 = dpp sp = - * r6 = dpp->delta lr = updated right sample - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_2: - ldr r3, [r1, #-8] - -term_minus_2_loop: - ldr ip, [r1, #4] @ for right channel the decorrelation value - movs r3, r3, asl #4 @ is the previous left sample (in r3) - mov r11, #0x80000000 - mov lr, ip - smlalne r11, lr, r0, r3 - strne lr, [r1, #4] - cmpne ip, #0 - beq .L380 - teq ip, r3 @ update weight based on signs - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #(1024 << 18) @ then clip weight to +/-1024 - movgt r0, #(1024 << 18) - cmp r0, r10 - movlt r0, r10 - -.L380: ldr r2, [r1], #8 @ for left channel the decorrelation value - movs lr, lr, asl #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r4, lr - strne r3, [r1, #-8] - cmpne r2, #0 - beq .L388 - teq r2, lr - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #(1024 << 18) - movgt r4, #(1024 << 18) - cmp r4, r10 - movlt r4, r10 - -.L388: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_2_loop - - str r3, [r5, #40] @ else store left channel and exit - b common_exit - -/* - ****************************************************************************** - * Loop to handle term = -3 condition - * - * r0 = dpp->weight_B r8 = previous left sample - * r1 = bptr r9 = - * r2 = current left sample r10 = -1024 (for clipping) - * r3 = previous right sample r11 = lo accumulator (for rounding) - * r4 = dpp->weight_A ip = intermediate result - * r5 = dpp sp = - * r6 = dpp->delta lr = - * r7 = eptr pc = - ******************************************************************************* - */ - -term_minus_3: - ldr r3, [r1, #-4] @ load previous samples - ldr r8, [r1, #-8] - -term_minus_3_loop: - ldr ip, [r1], #4 - movs r3, r3, asl #4 - mov r11, #0x80000000 - mov r2, ip - smlalne r11, r2, r4, r3 - strne r2, [r1, #-4] - cmpne ip, #0 - beq .L399 - teq ip, r3 @ update weight based on signs - submi r4, r4, r6 - addpl r4, r4, r6 - cmp r4, #(1024 << 18) @ then clip weight to +/-1024 - movgt r4, #(1024 << 18) - cmp r4, r10 - movlt r4, r10 - -.L399: movs ip, r8, asl #4 @ ip = previous left we use now - mov r8, r2 @ r8 = current left we use next time - ldr r2, [r1], #4 - mov r11, #0x80000000 - mov r3, r2 - smlalne r11, r3, r0, ip - strne r3, [r1, #-4] - cmpne r2, #0 - beq .L407 - teq ip, r2 - submi r0, r0, r6 - addpl r0, r0, r6 - cmp r0, #(1024 << 18) - movgt r0, #(1024 << 18) - cmp r0, r10 - movlt r0, r10 - -.L407: cmp r7, r1 @ loop back if more samples to do - bhi term_minus_3_loop - - str r3, [r5, #8] @ else store previous samples & exit - str r8, [r5, #40] - -/* - * Before finally exiting we must store weights back for next time - */ - -common_exit: - mov r0, r0, asr #18 @ restore weights to real magnitude - mov r4, r4, asr #18 - strh r4, [r5, #4] - strh r0, [r5, #6] - ldmfd sp!, {r4 - r8, r10, r11, pc} - diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/bits.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/bits.c deleted file mode 100644 index b4f03385e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/bits.c +++ /dev/null @@ -1,140 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// bits.c - -// This module provides utilities to support the BitStream structure which is -// used to read and write all WavPack audio data streams. It also contains a -// wrapper for the stream I/O functions and a set of functions dealing with -// endian-ness, both for enhancing portability. Finally, a debug wrapper for -// the malloc() system is provided. - -#include "wavpack.h" - -#include -#include - -////////////////////////// Bitstream functions //////////////////////////////// - -// Open the specified BitStream and associate with the specified buffer. - -static void bs_read (Bitstream *bs); - -void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes) -{ - CLEAR (*bs); - bs->buf = buffer_start; - bs->end = buffer_end; - - if (file) { - bs->ptr = bs->end - 1; - bs->file_bytes = file_bytes; - bs->file = file; - } - else - bs->ptr = bs->buf - 1; - - bs->wrap = bs_read; -} - -// This function is only called from the getbit() and getbits() macros when -// the BitStream has been exhausted and more data is required. Sinve these -// bistreams no longer access files, this function simple sets an error and -// resets the buffer. - -static void bs_read (Bitstream *bs) -{ - if (bs->file && bs->file_bytes) { - uint32_t bytes_read, bytes_to_read = bs->end - bs->buf; - - if (bytes_to_read > bs->file_bytes) - bytes_to_read = bs->file_bytes; - - bytes_read = bs->file (bs->buf, bytes_to_read); - - if (bytes_read) { - bs->end = bs->buf + bytes_read; - bs->file_bytes -= bytes_read; - } - else { - memset (bs->buf, -1, bs->end - bs->buf); - bs->error = 1; - } - } - else - bs->error = 1; - - if (bs->error) - memset (bs->buf, -1, bs->end - bs->buf); - - bs->ptr = bs->buf; -} - -/////////////////////// Endian Correction Routines //////////////////////////// - -void little_endian_to_native (void *data, char *format) -{ - uchar *cp = (uchar *) data; - int32_t temp; - - while (*format) { - switch (*format) { - case 'L': - temp = cp [0] + ((int32_t) cp [1] << 8) + ((int32_t) cp [2] << 16) + ((int32_t) cp [3] << 24); - * (int32_t *) cp = temp; - cp += 4; - break; - - case 'S': - temp = cp [0] + (cp [1] << 8); - * (short *) cp = (short) temp; - cp += 2; - break; - - default: - if (isdigit (*format)) - cp += *format - '0'; - - break; - } - - format++; - } -} - -void native_to_little_endian (void *data, char *format) -{ - uchar *cp = (uchar *) data; - int32_t temp; - - while (*format) { - switch (*format) { - case 'L': - temp = * (int32_t *) cp; - *cp++ = (uchar) temp; - *cp++ = (uchar) (temp >> 8); - *cp++ = (uchar) (temp >> 16); - *cp++ = (uchar) (temp >> 24); - break; - - case 'S': - temp = * (short *) cp; - *cp++ = (uchar) temp; - *cp++ = (uchar) (temp >> 8); - break; - - default: - if (isdigit (*format)) - cp += *format - '0'; - - break; - } - - format++; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/coldfire.S b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/coldfire.S deleted file mode 100644 index 83530900c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/coldfire.S +++ /dev/null @@ -1,525 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -/* This is an assembly optimized version of the following WavPack function: - * - * void decorr_stereo_pass_cont (struct decorr_pass *dpp, - * long *buffer, long sample_count); - * - * It performs a single pass of stereo decorrelation on the provided buffer. - * Note that this version of the function requires that the 8 previous stereo - * samples are visible and correct. In other words, it ignores the "samples_*" - * fields in the decorr_pass structure and gets the history data directly - * from the buffer. It does, however, return the appropriate history samples - * to the decorr_pass structure before returning. - * - * This is written to work on a MCF5249 processor, or any processor based on - * the ColdFire V2 core with an EMAC unit. The EMAC is perfectly suited for - * the "apply_weight" function of WavPack decorrelation because it provides - * the requires 40-bit product. The fractional rounding mode of the EMAC is not - * configurable and uses "round to even" while WavPack uses "round to larger", - * so the rounding has to be done manually. - */ - - .text - .align 2 - .global decorr_stereo_pass_cont_mcf5249 - -decorr_stereo_pass_cont_mcf5249: - - lea (-44, %sp), %sp - movem.l %d2-%d7/%a2-%a6, (%sp) - move.l 44+4(%sp), %a2 | a2 = dpp-> - move.l 44+8(%sp), %a1 | a1 = bptr - move.w 2(%a2), %a3 | a3 = dpp->delta - move.w 4(%a2), %d3 | d3 = dpp->weight_A (sign extended) - ext.l %d3 - move.w 6(%a2), %d4 | d4 = dpp->weight_B (sign extended) - ext.l %d4 - move.l 44+12(%sp), %d0 | d0 = sample_count - jbeq return_only | if zero, nothing to do - - lsl.l #3, %d0 | d5 = bptr + (sample_count * 8) - move.l %d0, %d5 - add.l %a1, %d5 - - moveq.l #17, %d0 | left shift weights & delta 17 places - asl.l %d0, %d3 - asl.l %d0, %d4 - move.l %a3, %d1 - asl.l %d0, %d1 - move.l %d1, %a3 - - moveq.l #0x20, %d6 - move.l %d6, %macsr | set fractional mode for MAC - move.l #0, %acc1 | acc1 = 0x00 0000 80 (for rounding) - move.l #0x800000, %accext01 - - move.l #1024<<17, %d6 | d6 & d7 are weight clipping limits - move.l #-1024<<17, %d7 | (only used by negative terms) - - move.w (%a2), %d0 | d0 = term - ext.l %d0 - cmp.l #17, %d0 - jbeq term_17 | term = 17 - cmp.l #18, %d0 - jbeq term_18 | term = 18 - addq.l #1, %d0 - jbeq term_minus_1 | term = -1 - addq.l #1, %d0 - jbeq term_minus_2 | term = -2 - addq.l #1, %d0 - jbeq term_minus_3 | term = -3 - jbra term_default | default term = 1 - 8 - -|------------------------------------------------------------------------------ -| Loop to handle term = 17 condition -| -| a0 = d0 = (2 * bptr [-1]) - bptr [-2] -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_17: - move.l -8(%a1), %d0 | d0 = 2 * bptr [-1] - bptr [-2] - add.l %d0, %d0 - sub.l -16(%a1), %d0 - beq .L251 | if zero, skip calculation - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_A - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L255 - eor.l %d1, %d0 | else compare signs - bge .L256 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - sub.l %a3, %d3 | subtract again instead of branch -.L256: add.l %a3, %d3 | add delta to weight - -.L255: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | update bptr [0] and store - move.l %d2, (%a1)+ - -.L253: move.l -8(%a1), %d0 | d0 = 2 * bptr [-1] - bptr [-2] - add.l %d0, %d0 - sub.l -16(%a1), %d0 - beq .L257 | if zero, skip calculations - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_B - mac.l %d0, %d4, %acc0 - move.l (%a1), %d1 - beq .L254 - eor.l %d1, %d0 | else compare signs - bge .L259 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - sub.l %a3, %d4 | subtract again instead of branch -.L259: add.l %a3, %d4 | add delta to weight - -.L254: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | update bptr [0] and store - move.l %d2, (%a1)+ - -.L252: cmp.l %a1, %d5 | loop if bptr < eptr - jbhi term_17 - bra term_17_18_finish | exit through common path - -.L251: addq.l #4, %a1 | update point and jump back into loop - bra .L253 - -.L257: addq.l #4, %a1 | update point and jump back into loop - bra .L252 - -|------------------------------------------------------------------------------ -| Loop to handle term = 18 condition -| -| a0 = d0 = ((3 * bptr [-1]) - bptr [-2]) >> 1 -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_18: - move.l -8(%a1), %a0 | d0 = (3 * bptr [-1] - bptr [-2]) >> 1 - lea (%a0,%a0.l*2), %a0 - move.l %a0, %d0 - sub.l -16(%a1), %d0 - asr.l #1, %d0 - beq .L260 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_A - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L266 - eor.l %d1, %d0 | else compare signs - bge .L267 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - sub.l %a3, %d3 | subtract again instead of branch -.L267: add.l %a3, %d3 | add delta to weight - -.L266: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [0], store - move.l %d2, (%a1)+ - -.L268: move.l -8(%a1), %a0 | d0 = (3 * bptr [-1] - bptr [-2]) >> 1 - lea (%a0,%a0.l*2), %a0 - move.l %a0, %d0 - sub.l -16(%a1), %d0 - asr.l #1, %d0 - beq .L261 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_B - mac.l %d0, %d4, %acc0 - move.l (%a1), %d1 - beq .L265 - eor.l %d1, %d0 | else compare signs - bge .L270 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - sub.l %a3, %d4 | subtract again instead of branch -.L270: add.l %a3, %d4 | add delta to weight - -.L265: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [0], store - move.l %d2, (%a1)+ - -.L269: cmp.l %a1, %d5 | loop if bptr < eptr - jbhi term_18 - bra term_17_18_finish | exit through common path - -.L260: addq.l #4, %a1 | bump pointer and jump back into loop - bra .L268 - -.L261: addq.l #4, %a1 | bump pointer and jump back into loop - bra .L269 - -term_17_18_finish: - move.l -4(%a1), 40(%a2) | restore dpp->samples_A [0-1], B [0-1] - move.l -8(%a1), 8(%a2) - move.l -12(%a1), 44(%a2) - move.l -16(%a1), 12(%a2) - jbra finish_up - -|------------------------------------------------------------------------------ -| Loop to handle default terms (i.e. 1 - 8) -| -| a0 = tptr d0 = tptr [0] -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_default: - move.w (%a2), %d0 | a0 = a1 - (dpp->term * 8) - ext.l %d0 - lsl.l #3, %d0 - move.l %a1, %a0 - sub.l %d0, %a0 - -term_default_loop: - move.l (%a0)+, %d0 | d0 = tptr [0], skip ahead if zero - beq .L271 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_A - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L277 - eor.l %d1, %d0 | else compare signs - bge .L278 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - sub.l %a3, %d3 | subtract again instead of branch -.L278: add.l %a3, %d3 | add delta to weight - -.L277: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [0], store - move.l %d2, (%a1)+ - -.L275: move.l (%a0)+, %d0 | d0 = tptr [0], skip ahead if zero - beq .L272 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + (d0 << 4) * weight_B - mac.l %d0, %d4, %acc0 - move.l (%a1), %d1 - beq .L276 - eor.l %d1, %d0 | else compare signs - bge .L281 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - sub.l %a3, %d4 | subtract again instead of branch -.L281: add.l %a3, %d4 | add delta to weight - -.L276: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [0], store - move.l %d2, (%a1)+ - -.L274: cmp.l %a1, %d5 | loop back if bptr < eptr - jbhi term_default_loop - move.w (%a2), %d0 | d0 = term - 1 - moveq.l #8, %d1 | d1 = loop counter - -.L323: subq.l #1, %d0 | back up & mask index - and.l #7, %d0 - move.l -(%a1), 40(%a2,%d0.l*4) | store dpp->samples_B [d0] - move.l -(%a1), 8(%a2,%d0.l*4) | store dpp->samples_A [d0] - subq.l #1, %d1 | loop on count - jbne .L323 - jbra finish_up - -.L271: addq.l #4, %a1 | bump pointer and jump back into loop - bra .L275 - -.L272: addq.l #4, %a1 | bump pointer and jump back into loop - bra .L274 - - -|------------------------------------------------------------------------------ -| Loop to handle term = -1 condition -| -| a0 = d0 = decorrelation sample -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| a6 = d6 = 1024 << 17 -| a7 = d7 = -1024 << 17 -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_minus_1: - move.l -4(%a1), %d0 | d0 = bptr [-1] - beq .L402 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_A) - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L405 - eor.l %d1, %d0 | else compare signs - bge .L404 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - cmp.l %d7, %d3 | check for negative clip limit - bge .L405 - move.l %d7, %d3 - bra .L405 - -.L404: add.l %a3, %d3 | add delta to weight - cmp.l %d6, %d3 | check for positive clip limit - ble .L405 - move.l %d6, %d3 - -.L405: move.l %acc0, %d0 | d2 = rounded product - add.l %d1, %d0 | add applied weight to bptr [0], store - move.l %d0, (%a1)+ - beq .L401 - -.L410: move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_B) - mac.l %d0, %d4, %acc0 - move.l (%a1), %d1 - beq .L403 - eor.l %d1, %d0 | else compare signs - bge .L407 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - cmp.l %d7, %d4 | check for negative clip limit - bge .L403 - move.l %d7, %d4 - bra .L403 - -.L407: add.l %a3, %d4 | add delta to weight - cmp.l %d6, %d4 | check for positive clip limit - ble .L403 - move.l %d6, %d4 - -.L403: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [1], store - move.l %d2, (%a1)+ - -.L411: cmp.l %a1, %d5 | loop back if bptr < eptr - jbhi term_minus_1 - move.l -4(%a1), 8(%a2) | dpp->samples_A [0] = bptr [-1] - jbra finish_up - -.L402: move.l (%a1)+, %d0 - bne .L410 - -.L401: addq.l #4, %a1 - bra .L411 - - -|------------------------------------------------------------------------------ -| Loop to handle term = -2 condition -| -| a0 = d0 = decorrelation sample -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| a6 = d6 = 1024 << 17 -| a7 = d7 = -1024 << 17 -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_minus_2: - move.l -8(%a1), %d0 | d0 = bptr [-2] - beq .L511 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_B) - mac.l %d0, %d4, %acc0 - move.l 4(%a1), %d1 - beq .L505 - eor.l %d1, %d0 | else compare signs - bge .L504 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - cmp.l %d7, %d4 | ckeck for negative clip limit - bge .L505 - move.l %d7, %d4 - bra .L505 - -.L504: add.l %a3, %d4 | add delta to weight - cmp.l %d6, %d4 | check for positive clip limit - ble .L505 - move.l %d6, %d4 - -.L505: move.l %acc0, %d0 | d2 = rounded product - add.l %d1, %d0 | add applied weight to bptr [0], store - move.l %d0, 4(%a1) - beq .L512 - -.L510: move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_A) - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L503 - eor.l %d1, %d0 | else compare signs - bge .L507 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - cmp.l %d7, %d3 | check for negative clip limit - bge .L503 - move.l %d7, %d3 - bra .L503 - -.L507: add.l %a3, %d3 | add delta to weight - cmp.l %d6, %d3 | check for negative clip limit - ble .L503 - move.l %d6, %d3 - -.L503: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [1], store - move.l %d2, (%a1) - -.L512: addq.l #8, %a1 - cmp.l %a1, %d5 | loop if bptr < eptr - jbhi term_minus_2 - move.l -8(%a1), 40(%a2) | dpp->samples_B [0] = bptr [-4] - jbra finish_up - -.L511: move.l 4(%a1), %d0 - beq .L512 - bra .L510 - - -|------------------------------------------------------------------------------ -| Loop to handle term = -3 condition -| -| a0 = d0 = decorrelation sample -| a1 = bptr d1 = initial bptr [0] -| a2 = dpp-> d2 = updated bptr [0] -| a3 = dpp->delta << 17 d3 = dpp->weight_A << 17 -| a4 = d4 = dpp->weight_B << 17 -| a5 = d5 = eptr -| a6 = d6 = 1024 << 17 -| a7 = d7 = -1024 << 17 -| macsr = 0x20 acc1 = 0x00 0000 80 -|------------------------------------------------------------------------------ - -term_minus_3: - move.l -4(%a1), %d0 | d0 = bptr [-1] - beq .L301 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_A) - mac.l %d0, %d3, %acc0 - move.l (%a1), %d1 - beq .L320 - eor.l %d1, %d0 | else compare signs - bge .L319 | if same, add delta to weight - sub.l %a3, %d3 | else subtract delta from weight - cmp.l %d7, %d3 | check for negative clip limit - bge .L320 - move.l %d7, %d3 - bra .L320 - -.L319: add.l %a3, %d3 | add delta to weight - cmp.l %d6, %d3 | check for positive clip limit - ble .L320 - move.l %d6, %d3 - -.L320: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [0], store - move.l %d2, (%a1)+ - -.L330: move.l -12(%a1), %d0 | d0 = bptr [-2] - beq .L302 - move.l %acc1, %acc0 - asl.l #4, %d0 | acc0 = acc1 + ((d0 << 4) * weight_B) - mac.l %d0, %d4, %acc0 - move.l (%a1), %d1 - beq .L318 - eor.l %d1, %d0 | else compare signs - bge .L322 | if same, add delta to weight - sub.l %a3, %d4 | else subtract delta from weight - cmp.l %d7, %d4 | check for negative clip limit - bge .L318 - move.l %d7, %d4 - bra .L318 - -.L322: add.l %a3, %d4 | add delta to weight - cmp.l %d6, %d4 | check for positive clip limit - ble .L318 - move.l %d6, %d4 - -.L318: move.l %acc0, %d2 | d2 = rounded product - add.l %d1, %d2 | add applied weight to bptr [1], store - move.l %d2, (%a1)+ - -.L331: cmp.l %a1, %d5 | bptr, eptr - jbhi term_minus_3 - move.l -4(%a1), 8(%a2) | dpp->samples_A [0] = bptr [-1] - move.l -8(%a1), 40(%a2) | dpp->samples_B [0] = bptr [-2] - jbra finish_up - -.L301: addq.l #4, %a1 - bra .L330 - -.L302: addq.l #4, %a1 - bra .L331 - -| finish and return - -finish_up: - moveq.l #17, %d0 - asr.l %d0, %d3 - asr.l %d0, %d4 - move.w %d3, 4(%a2) | weight_A, dpp->weight_A - move.w %d4, 6(%a2) | weight_B, dpp->weight_B - - clr.l %d0 | clear up EMAC - move.l %d0, %acc0 - move.l %d0, %acc1 - -return_only: - movem.l (%sp), %d2-%d7/%a2-%a6 - lea (44,%sp), %sp - rts diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/float.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/float.c deleted file mode 100644 index 09f0e4c36..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/float.c +++ /dev/null @@ -1,50 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// float.c - -#include "wavpack.h" - -int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd) -{ - int bytecnt = wpmd->byte_length; - char *byteptr = wpmd->data; - - if (bytecnt != 4) - return FALSE; - - wps->float_flags = *byteptr++; - wps->float_shift = *byteptr++; - wps->float_max_exp = *byteptr++; - wps->float_norm_exp = *byteptr; - return TRUE; -} - -void float_values (WavpackStream *wps, int32_t *values, int32_t num_values) -{ - int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift; - - if (shift > 32) - shift = 32; - else if (shift < -32) - shift = -32; - - while (num_values--) { - if (shift > 0) - *values <<= shift; - else if (shift < 0) - *values >>= -shift; - - if (*values > 8388607L) - *values = 8388607L; - else if (*values < -8388608L) - *values = -8388608L; - - values++; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/license.txt b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/license.txt deleted file mode 100644 index d2ee90fc7..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/license.txt +++ /dev/null @@ -1,25 +0,0 @@ - Copyright (c) 1998 - 2006 Conifer Software - All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Conifer Software nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/metadata.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/metadata.c deleted file mode 100644 index 6a19ac9bb..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/metadata.c +++ /dev/null @@ -1,105 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// metadata.c - -// This module handles the metadata structure introduced in WavPack 4.0 - -#include "wavpack.h" - -int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) -{ - uchar tchar; - - if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1)) - return FALSE; - - wpmd->byte_length = tchar << 1; - - if (wpmd->id & ID_LARGE) { - wpmd->id &= ~ID_LARGE; - - if (!wpc->infile (&tchar, 1)) - return FALSE; - - wpmd->byte_length += (int32_t) tchar << 9; - - if (!wpc->infile (&tchar, 1)) - return FALSE; - - wpmd->byte_length += (int32_t) tchar << 17; - } - - if (wpmd->id & ID_ODD_SIZE) { - wpmd->id &= ~ID_ODD_SIZE; - wpmd->byte_length--; - } - - if (wpmd->byte_length && wpmd->byte_length <= sizeof (wpc->read_buffer)) { - uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); - - if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) { - wpmd->data = NULL; - return FALSE; - } - - wpmd->data = wpc->read_buffer; - } - else - wpmd->data = NULL; - - return TRUE; -} - -int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd) -{ - WavpackStream *wps = &wpc->stream; - - switch (wpmd->id) { - case ID_DUMMY: - return TRUE; - - case ID_DECORR_TERMS: - return read_decorr_terms (wps, wpmd); - - case ID_DECORR_WEIGHTS: - return read_decorr_weights (wps, wpmd); - - case ID_DECORR_SAMPLES: - return read_decorr_samples (wps, wpmd); - - case ID_ENTROPY_VARS: - return read_entropy_vars (wps, wpmd); - - case ID_HYBRID_PROFILE: - return read_hybrid_profile (wps, wpmd); - - case ID_FLOAT_INFO: - return read_float_info (wps, wpmd); - - case ID_INT32_INFO: - return read_int32_info (wps, wpmd); - - case ID_CHANNEL_INFO: - return read_channel_info (wpc, wpmd); - - case ID_CONFIG_BLOCK: - return read_config_info (wpc, wpmd); - - case ID_WV_BITSTREAM: - return init_wv_bitstream (wpc, wpmd); - - case ID_SHAPING_WEIGHTS: - case ID_WVC_BITSTREAM: - case ID_WVX_BITSTREAM: - return TRUE; - - default: - return (wpmd->id & ID_OPTIONAL_DATA) ? TRUE : FALSE; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/readme.txt b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/readme.txt deleted file mode 100644 index 07b7a261d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/readme.txt +++ /dev/null @@ -1,68 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -This package contains a tiny version of the WavPack 4.40 decoder that might -be used in a "resource limited" CPU environment or form the basis for a -hardware decoding implementation. It is packaged with a demo command-line -program that accepts a WavPack audio file on stdin and outputs a RIFF wav -file to stdout. The program is standard C, and a win32 executable is -included which was compiled under MS Visual C++ 6.0 using this command: - -cl /O1 /DWIN32 wvfilter.c wputils.c unpack.c float.c metadata.c words.c bits.c - -WavPack data is read with a stream reading callback. No direct seeking is -provided for, but it is possible to start decoding anywhere in a WavPack -stream. In this case, WavPack will be able to provide the sample-accurate -position when it synchs with the data and begins decoding. The WIN32 macro -is used for Windows to force the stdin and stdout streams to be binary mode. - -Compared to the previous version, this library has been optimized somewhat -for improved performance in exchange for slightly larger code size. The -library also now includes hand-optimized assembly language versions of the -decorrelation functions for both the ColdFire (w/EMAC) and ARM processors. - -For demonstration purposes this uses a single static copy of the -WavpackContext structure, so obviously it cannot be used for more than one -file at a time. Also, this decoder will not handle "correction" files, plays -only the first two channels of multi-channel files, and is limited in -resolution in some large integer or floating point files (but always -provides at least 24 bits of resolution). It also will not accept WavPack -files from before version 4.0. - -The previous version of this library would handle float files by returning -32-bit floating-point data (even though no floating point math was used). -Because this library would normally be used for simply playing WavPack -files where lossless performance (beyond 24-bits) is not relevant, I have -changed this behavior. Now, these files will generate clipped 24-bit data. -The MODE_FLOAT flag will still be returned by WavpackGetMode(), but the -BitsPerSample and BytesPerSample queries will be 24 and 3, respectfully. -What this means is that an application that can handle 24-bit data will -now be able to handle floating point data (assuming that the MODE_FLOAT -flag is ignored). - -To make this code viable on the greatest number of hardware platforms, the -following are true: - - speed is about 5x realtime on an AMD K6 300 MHz - ("high" mode 16/44 stereo; normal mode is about twice that fast) - - no floating-point math required; just 32b * 32b = 32b int multiply - - large data areas are static and less than 4K total - executable code and tables are less than 40K - no malloc / free usage - -To maintain compatibility on various platforms, the following conventions -are used: - - a "char" must be exactly 8-bits - a "short" must be exactly 16-bits - an "int" must be at least 16-bits, but may be larger - the "long" type is not used to avoid problems with 64-bit compilers - -Questions or comments should be directed to david@wavpack.com diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/unpack.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/unpack.c deleted file mode 100644 index 317fe2227..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/unpack.c +++ /dev/null @@ -1,785 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// unpack.c - -// This module actually handles the decompression of the audio data, except -// for the entropy decoding which is handled by the words.c module. For -// maximum efficiency, the conversion is isolated to tight loops that handle -// an entire buffer. - -#include "wavpack.h" - -#include -#include - -#define LOSSY_MUTE - -///////////////////////////// executable code //////////////////////////////// - -// This function initializes everything required to unpack a WavPack block -// and must be called before unpack_samples() is called to obtain audio data. -// It is assumed that the WavpackHeader has been read into the wps->wphdr -// (in the current WavpackStream). This is where all the metadata blocks are -// scanned up to the one containing the audio bitstream. - -int unpack_init (WavpackContext *wpc) -{ - WavpackStream *wps = &wpc->stream; - WavpackMetadata wpmd; - - if (wps->wphdr.block_samples && wps->wphdr.block_index != (uint32_t) -1) - wps->sample_index = wps->wphdr.block_index; - - wps->mute_error = FALSE; - wps->crc = 0xffffffff; - CLEAR (wps->wvbits); - CLEAR (wps->decorr_passes); - CLEAR (wps->w); - - while (read_metadata_buff (wpc, &wpmd)) { - if (!process_metadata (wpc, &wpmd)) { - strcpy (wpc->error_message, "invalid metadata!"); - return FALSE; - } - - if (wpmd.id == ID_WV_BITSTREAM) - break; - } - - if (wps->wphdr.block_samples && !bs_is_open (&wps->wvbits)) { - strcpy (wpc->error_message, "invalid WavPack file!"); - return FALSE; - } - - if (wps->wphdr.block_samples) { - if ((wps->wphdr.flags & INT32_DATA) && wps->int32_sent_bits) - wpc->lossy_blocks = TRUE; - - if ((wps->wphdr.flags & FLOAT_DATA) && - wps->float_flags & (FLOAT_EXCEPTIONS | FLOAT_ZEROS_SENT | FLOAT_SHIFT_SENT | FLOAT_SHIFT_SAME)) - wpc->lossy_blocks = TRUE; - } - - return TRUE; -} - -// This function initialzes the main bitstream for audio samples, which must -// be in the "wv" file. - -int init_wv_bitstream (WavpackContext *wpc, WavpackMetadata *wpmd) -{ - WavpackStream *wps = &wpc->stream; - - if (wpmd->data) - bs_open_read (&wps->wvbits, wpmd->data, (unsigned char *) wpmd->data + wpmd->byte_length, NULL, 0); - else if (wpmd->byte_length) - bs_open_read (&wps->wvbits, wpc->read_buffer, wpc->read_buffer + sizeof (wpc->read_buffer), - wpc->infile, wpmd->byte_length + (wpmd->byte_length & 1)); - - return TRUE; -} - -// Read decorrelation terms from specified metadata block into the -// decorr_passes array. The terms range from -3 to 8, plus 17 & 18; -// other values are reserved and generate errors for now. The delta -// ranges from 0 to 7 with all values valid. Note that the terms are -// stored in the opposite order in the decorr_passes array compared -// to packing. - -int read_decorr_terms (WavpackStream *wps, WavpackMetadata *wpmd) -{ - int termcnt = wpmd->byte_length; - uchar *byteptr = wpmd->data; - struct decorr_pass *dpp; - - if (termcnt > MAX_NTERMS) - return FALSE; - - wps->num_terms = termcnt; - - for (dpp = wps->decorr_passes + termcnt - 1; termcnt--; dpp--) { - dpp->term = (int)(*byteptr & 0x1f) - 5; - dpp->delta = (*byteptr++ >> 5) & 0x7; - - if (!dpp->term || dpp->term < -3 || (dpp->term > MAX_TERM && dpp->term < 17) || dpp->term > 18) - return FALSE; - } - - return TRUE; -} - -// Read decorrelation weights from specified metadata block into the -// decorr_passes array. The weights range +/-1024, but are rounded and -// truncated to fit in signed chars for metadata storage. Weights are -// separate for the two channels and are specified from the "last" term -// (first during encode). Unspecified weights are set to zero. - -int read_decorr_weights (WavpackStream *wps, WavpackMetadata *wpmd) -{ - int termcnt = wpmd->byte_length, tcount; - signed char *byteptr = wpmd->data; - struct decorr_pass *dpp; - - if (!(wps->wphdr.flags & MONO_DATA)) - termcnt /= 2; - - if (termcnt > wps->num_terms) - return FALSE; - - for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) - dpp->weight_A = dpp->weight_B = 0; - - while (--dpp >= wps->decorr_passes && termcnt--) { - dpp->weight_A = restore_weight (*byteptr++); - - if (!(wps->wphdr.flags & MONO_DATA)) - dpp->weight_B = restore_weight (*byteptr++); - } - - return TRUE; -} - -// Read decorrelation samples from specified metadata block into the -// decorr_passes array. The samples are signed 32-bit values, but are -// converted to signed log2 values for storage in metadata. Values are -// stored for both channels and are specified from the "last" term -// (first during encode) with unspecified samples set to zero. The -// number of samples stored varies with the actual term value, so -// those must obviously come first in the metadata. - -int read_decorr_samples (WavpackStream *wps, WavpackMetadata *wpmd) -{ - uchar *byteptr = wpmd->data; - uchar *endptr = byteptr + wpmd->byte_length; - struct decorr_pass *dpp; - int tcount; - - for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) { - CLEAR (dpp->samples_A); - CLEAR (dpp->samples_B); - } - - if (wps->wphdr.version == 0x402 && (wps->wphdr.flags & HYBRID_FLAG)) { - byteptr += 2; - - if (!(wps->wphdr.flags & MONO_DATA)) - byteptr += 2; - } - - while (dpp-- > wps->decorr_passes && byteptr < endptr) - if (dpp->term > MAX_TERM) { - dpp->samples_A [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - dpp->samples_A [1] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8))); - byteptr += 4; - - if (!(wps->wphdr.flags & MONO_DATA)) { - dpp->samples_B [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - dpp->samples_B [1] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8))); - byteptr += 4; - } - } - else if (dpp->term < 0) { - dpp->samples_A [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - dpp->samples_B [0] = exp2s ((short)(byteptr [2] + (byteptr [3] << 8))); - byteptr += 4; - } - else { - int m = 0, cnt = dpp->term; - - while (cnt--) { - dpp->samples_A [m] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - byteptr += 2; - - if (!(wps->wphdr.flags & MONO_DATA)) { - dpp->samples_B [m] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - byteptr += 2; - } - - m++; - } - } - - return byteptr == endptr; -} - -// Read the int32 data from the specified metadata into the specified stream. -// This data is used for integer data that has more than 24 bits of magnitude -// or, in some cases, used to eliminate redundant bits from any audio stream. - -int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd) -{ - int bytecnt = wpmd->byte_length; - char *byteptr = wpmd->data; - - if (bytecnt != 4) - return FALSE; - - wps->int32_sent_bits = *byteptr++; - wps->int32_zeros = *byteptr++; - wps->int32_ones = *byteptr++; - wps->int32_dups = *byteptr; - return TRUE; -} - -// Read multichannel information from metadata. The first byte is the total -// number of channels and the following bytes represent the channel_mask -// as described for Microsoft WAVEFORMATEX. - -int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd) -{ - int bytecnt = wpmd->byte_length, shift = 0; - char *byteptr = wpmd->data; - uint32_t mask = 0; - - if (!bytecnt || bytecnt > 5) - return FALSE; - - wpc->config.num_channels = *byteptr++; - - while (--bytecnt) { - mask |= (uint32_t) *byteptr++ << shift; - shift += 8; - } - - wpc->config.channel_mask = mask; - return TRUE; -} - -// Read configuration information from metadata. - -int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd) -{ - int bytecnt = wpmd->byte_length; - uchar *byteptr = wpmd->data; - - if (bytecnt >= 3) { - wpc->config.flags &= 0xff; - wpc->config.flags |= (int32_t) *byteptr++ << 8; - wpc->config.flags |= (int32_t) *byteptr++ << 16; - wpc->config.flags |= (int32_t) *byteptr << 24; - } - - return TRUE; -} - -// This monster actually unpacks the WavPack bitstream(s) into the specified -// buffer as 32-bit integers or floats (depending on orignal data). Lossy -// samples will be clipped to their original limits (i.e. 8-bit samples are -// clipped to -128/+127) but are still returned in int32_ts. It is up to the -// caller to potentially reformat this for the final output including any -// multichannel distribution, block alignment or endian compensation. The -// function unpack_init() must have been called and the entire WavPack block -// must still be visible (although wps->blockbuff will not be accessed again). -// For maximum clarity, the function is broken up into segments that handle -// various modes. This makes for a few extra infrequent flag checks, but -// makes the code easier to follow because the nesting does not become so -// deep. For maximum efficiency, the conversion is isolated to tight loops -// that handle an entire buffer. The function returns the total number of -// samples unpacked, which can be less than the number requested if an error -// occurs or the end of the block is reached. - -#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) -extern void decorr_stereo_pass_cont_mcf5249 (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -#elif defined(CPU_ARM) && !defined(SIMULATOR) -extern void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -extern void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -#else -static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -#endif - -static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count); -static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count); - -int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count) -{ - WavpackStream *wps = &wpc->stream; - uint32_t flags = wps->wphdr.flags, crc = wps->crc, i; - int32_t mute_limit = (1L << ((flags & MAG_MASK) >> MAG_LSB)) + 2; - struct decorr_pass *dpp; - int32_t *bptr, *eptr; - int tcount; - - if (wps->sample_index + sample_count > wps->wphdr.block_index + wps->wphdr.block_samples) - sample_count = wps->wphdr.block_index + wps->wphdr.block_samples - wps->sample_index; - - if (wps->mute_error) { - memset (buffer, 0, sample_count * (flags & MONO_FLAG ? 4 : 8)); - wps->sample_index += sample_count; - return sample_count; - } - - if (flags & HYBRID_FLAG) - mute_limit *= 2; - - ///////////////////// handle version 4 mono data ///////////////////////// - - if (flags & MONO_DATA) { - eptr = buffer + sample_count; - i = get_words (buffer, sample_count, flags, &wps->w, &wps->wvbits); - - for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) - decorr_mono_pass (dpp, buffer, sample_count); - - for (bptr = buffer; bptr < eptr; ++bptr) { - if (labs (bptr [0]) > mute_limit) { - i = bptr - buffer; - break; - } - - crc = crc * 3 + bptr [0]; - } - } - - //////////////////// handle version 4 stereo data //////////////////////// - - else { - eptr = buffer + (sample_count * 2); - i = get_words (buffer, sample_count, flags, &wps->w, &wps->wvbits); - - if (sample_count < 16) - for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) - decorr_stereo_pass (dpp, buffer, sample_count); - else - for (tcount = wps->num_terms, dpp = wps->decorr_passes; tcount--; dpp++) { - decorr_stereo_pass (dpp, buffer, 8); -#if defined(CPU_COLDFIRE) && !defined(SIMULATOR) - decorr_stereo_pass_cont_mcf5249 (dpp, buffer + 16, sample_count - 8); -#elif defined(CPU_ARM) && !defined(SIMULATOR) - if (((flags & MAG_MASK) >> MAG_LSB) > 15) - decorr_stereo_pass_cont_arml (dpp, buffer + 16, sample_count - 8); - else - decorr_stereo_pass_cont_arm (dpp, buffer + 16, sample_count - 8); -#else - decorr_stereo_pass_cont (dpp, buffer + 16, sample_count - 8); -#endif - } - - if (flags & JOINT_STEREO) - for (bptr = buffer; bptr < eptr; bptr += 2) { - bptr [0] += (bptr [1] -= (bptr [0] >> 1)); - - if (labs (bptr [0]) > mute_limit || labs (bptr [1]) > mute_limit) { - i = (bptr - buffer) / 2; - break; - } - - crc = (crc * 3 + bptr [0]) * 3 + bptr [1]; - } - else - for (bptr = buffer; bptr < eptr; bptr += 2) { - if (labs (bptr [0]) > mute_limit || labs (bptr [1]) > mute_limit) { - i = (bptr - buffer) / 2; - break; - } - - crc = (crc * 3 + bptr [0]) * 3 + bptr [1]; - } - } - - if (i != sample_count) { - memset (buffer, 0, sample_count * (flags & MONO_FLAG ? 4 : 8)); - wps->mute_error = TRUE; - i = sample_count; - } - - fixup_samples (wps, buffer, i); - - if (flags & FALSE_STEREO) { - int32_t *dptr = buffer + i * 2; - int32_t *sptr = buffer + i; - int32_t c = i; - - while (c--) { - *--dptr = *--sptr; - *--dptr = *sptr; - } - } - - wps->sample_index += i; - wps->crc = crc; - - return i; -} - -static void decorr_stereo_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count) -{ - int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; - int32_t *bptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; - int m, k; - - switch (dpp->term) { - - case 17: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = 2 * dpp->samples_A [0] - dpp->samples_A [1]; - dpp->samples_A [1] = dpp->samples_A [0]; - dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [0]; - - sam_A = 2 * dpp->samples_B [0] - dpp->samples_B [1]; - dpp->samples_B [1] = dpp->samples_B [0]; - dpp->samples_B [0] = apply_weight (weight_B, sam_A) + bptr [1]; - update_weight (weight_B, delta, sam_A, bptr [1]); - bptr [1] = dpp->samples_B [0]; - } - - break; - - case 18: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1; - dpp->samples_A [1] = dpp->samples_A [0]; - dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [0]; - - sam_A = (3 * dpp->samples_B [0] - dpp->samples_B [1]) >> 1; - dpp->samples_B [1] = dpp->samples_B [0]; - dpp->samples_B [0] = apply_weight (weight_B, sam_A) + bptr [1]; - update_weight (weight_B, delta, sam_A, bptr [1]); - bptr [1] = dpp->samples_B [0]; - } - - break; - - default: - for (m = 0, k = dpp->term & (MAX_TERM - 1), bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = dpp->samples_A [m]; - dpp->samples_A [k] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [k]; - - sam_A = dpp->samples_B [m]; - dpp->samples_B [k] = apply_weight (weight_B, sam_A) + bptr [1]; - update_weight (weight_B, delta, sam_A, bptr [1]); - bptr [1] = dpp->samples_B [k]; - - m = (m + 1) & (MAX_TERM - 1); - k = (k + 1) & (MAX_TERM - 1); - } - - if (m) { - int32_t temp_samples [MAX_TERM]; - - memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); - - for (k = 0; k < MAX_TERM; k++, m++) - dpp->samples_A [k] = temp_samples [m & (MAX_TERM - 1)]; - - memcpy (temp_samples, dpp->samples_B, sizeof (dpp->samples_B)); - - for (k = 0; k < MAX_TERM; k++, m++) - dpp->samples_B [k] = temp_samples [m & (MAX_TERM - 1)]; - } - - break; - - case -1: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = bptr [0] + apply_weight (weight_A, dpp->samples_A [0]); - update_weight_clip (weight_A, delta, dpp->samples_A [0], bptr [0]); - bptr [0] = sam_A; - dpp->samples_A [0] = bptr [1] + apply_weight (weight_B, sam_A); - update_weight_clip (weight_B, delta, sam_A, bptr [1]); - bptr [1] = dpp->samples_A [0]; - } - - break; - - case -2: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_B = bptr [1] + apply_weight (weight_B, dpp->samples_B [0]); - update_weight_clip (weight_B, delta, dpp->samples_B [0], bptr [1]); - bptr [1] = sam_B; - dpp->samples_B [0] = bptr [0] + apply_weight (weight_A, sam_B); - update_weight_clip (weight_A, delta, sam_B, bptr [0]); - bptr [0] = dpp->samples_B [0]; - } - - break; - - case -3: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = bptr [0] + apply_weight (weight_A, dpp->samples_A [0]); - update_weight_clip (weight_A, delta, dpp->samples_A [0], bptr [0]); - sam_B = bptr [1] + apply_weight (weight_B, dpp->samples_B [0]); - update_weight_clip (weight_B, delta, dpp->samples_B [0], bptr [1]); - bptr [0] = dpp->samples_B [0] = sam_A; - bptr [1] = dpp->samples_A [0] = sam_B; - } - - break; - } - - dpp->weight_A = weight_A; - dpp->weight_B = weight_B; -} - -#if (!defined(CPU_COLDFIRE) && !defined(CPU_ARM)) || defined(SIMULATOR) - -static void decorr_stereo_pass_cont (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count) -{ - int32_t delta = dpp->delta, weight_A = dpp->weight_A, weight_B = dpp->weight_B; - int32_t *bptr, *tptr, *eptr = buffer + (sample_count * 2), sam_A, sam_B; - int k, i; - - switch (dpp->term) { - - case 17: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = 2 * bptr [-2] - bptr [-4]; - bptr [0] = apply_weight (weight_A, sam_A) + (sam_B = bptr [0]); - update_weight (weight_A, delta, sam_A, sam_B); - - sam_A = 2 * bptr [-1] - bptr [-3]; - bptr [1] = apply_weight (weight_B, sam_A) + (sam_B = bptr [1]); - update_weight (weight_B, delta, sam_A, sam_B); - } - - dpp->samples_B [0] = bptr [-1]; - dpp->samples_A [0] = bptr [-2]; - dpp->samples_B [1] = bptr [-3]; - dpp->samples_A [1] = bptr [-4]; - break; - - case 18: - for (bptr = buffer; bptr < eptr; bptr += 2) { - sam_A = (3 * bptr [-2] - bptr [-4]) >> 1; - bptr [0] = apply_weight (weight_A, sam_A) + (sam_B = bptr [0]); - update_weight (weight_A, delta, sam_A, sam_B); - - sam_A = (3 * bptr [-1] - bptr [-3]) >> 1; - bptr [1] = apply_weight (weight_B, sam_A) + (sam_B = bptr [1]); - update_weight (weight_B, delta, sam_A, sam_B); - } - - dpp->samples_B [0] = bptr [-1]; - dpp->samples_A [0] = bptr [-2]; - dpp->samples_B [1] = bptr [-3]; - dpp->samples_A [1] = bptr [-4]; - break; - - default: - for (bptr = buffer, tptr = buffer - (dpp->term * 2); bptr < eptr; bptr += 2, tptr += 2) { - bptr [0] = apply_weight (weight_A, tptr [0]) + (sam_A = bptr [0]); - update_weight (weight_A, delta, tptr [0], sam_A); - - bptr [1] = apply_weight (weight_B, tptr [1]) + (sam_A = bptr [1]); - update_weight (weight_B, delta, tptr [1], sam_A); - } - - for (k = dpp->term - 1, i = 8; i--; k--) { - dpp->samples_B [k & (MAX_TERM - 1)] = *--bptr; - dpp->samples_A [k & (MAX_TERM - 1)] = *--bptr; - } - - break; - - case -1: - for (bptr = buffer; bptr < eptr; bptr += 2) { - bptr [0] = apply_weight (weight_A, bptr [-1]) + (sam_A = bptr [0]); - update_weight_clip (weight_A, delta, bptr [-1], sam_A); - bptr [1] = apply_weight (weight_B, bptr [0]) + (sam_A = bptr [1]); - update_weight_clip (weight_B, delta, bptr [0], sam_A); - } - - dpp->samples_A [0] = bptr [-1]; - break; - - case -2: - for (bptr = buffer; bptr < eptr; bptr += 2) { - bptr [1] = apply_weight (weight_B, bptr [-2]) + (sam_A = bptr [1]); - update_weight_clip (weight_B, delta, bptr [-2], sam_A); - bptr [0] = apply_weight (weight_A, bptr [1]) + (sam_A = bptr [0]); - update_weight_clip (weight_A, delta, bptr [1], sam_A); - } - - dpp->samples_B [0] = bptr [-2]; - break; - - case -3: - for (bptr = buffer; bptr < eptr; bptr += 2) { - bptr [0] = apply_weight (weight_A, bptr [-1]) + (sam_A = bptr [0]); - update_weight_clip (weight_A, delta, bptr [-1], sam_A); - bptr [1] = apply_weight (weight_B, bptr [-2]) + (sam_A = bptr [1]); - update_weight_clip (weight_B, delta, bptr [-2], sam_A); - } - - dpp->samples_A [0] = bptr [-1]; - dpp->samples_B [0] = bptr [-2]; - break; - } - - dpp->weight_A = weight_A; - dpp->weight_B = weight_B; -} - -#endif - -static void decorr_mono_pass (struct decorr_pass *dpp, int32_t *buffer, int32_t sample_count) -{ - int32_t delta = dpp->delta, weight_A = dpp->weight_A; - int32_t *bptr, *eptr = buffer + sample_count, sam_A; - int m, k; - - switch (dpp->term) { - - case 17: - for (bptr = buffer; bptr < eptr; bptr++) { - sam_A = 2 * dpp->samples_A [0] - dpp->samples_A [1]; - dpp->samples_A [1] = dpp->samples_A [0]; - dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [0]; - } - - break; - - case 18: - for (bptr = buffer; bptr < eptr; bptr++) { - sam_A = (3 * dpp->samples_A [0] - dpp->samples_A [1]) >> 1; - dpp->samples_A [1] = dpp->samples_A [0]; - dpp->samples_A [0] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [0]; - } - - break; - - default: - for (m = 0, k = dpp->term & (MAX_TERM - 1), bptr = buffer; bptr < eptr; bptr++) { - sam_A = dpp->samples_A [m]; - dpp->samples_A [k] = apply_weight (weight_A, sam_A) + bptr [0]; - update_weight (weight_A, delta, sam_A, bptr [0]); - bptr [0] = dpp->samples_A [k]; - m = (m + 1) & (MAX_TERM - 1); - k = (k + 1) & (MAX_TERM - 1); - } - - if (m) { - int32_t temp_samples [MAX_TERM]; - - memcpy (temp_samples, dpp->samples_A, sizeof (dpp->samples_A)); - - for (k = 0; k < MAX_TERM; k++, m++) - dpp->samples_A [k] = temp_samples [m & (MAX_TERM - 1)]; - } - - break; - } - - dpp->weight_A = weight_A; -} - - -// This is a helper function for unpack_samples() that applies several final -// operations. First, if the data is 32-bit float data, then that conversion -// is done in the float.c module (whether lossy or lossless) and we return. -// Otherwise, if the extended integer data applies, then that operation is -// executed first. If the unpacked data is lossy (and not corrected) then -// it is clipped and shifted in a single operation. Otherwise, if it's -// lossless then the last step is to apply the final shift (if any). - -static void fixup_samples (WavpackStream *wps, int32_t *buffer, uint32_t sample_count) -{ - uint32_t flags = wps->wphdr.flags; - int shift = (flags & SHIFT_MASK) >> SHIFT_LSB; - - if (flags & FLOAT_DATA) { - float_values (wps, buffer, (flags & MONO_FLAG) ? sample_count : sample_count * 2); - return; - } - - if (flags & INT32_DATA) { - uint32_t count = (flags & MONO_FLAG) ? sample_count : sample_count * 2; - int sent_bits = wps->int32_sent_bits, zeros = wps->int32_zeros; - int ones = wps->int32_ones, dups = wps->int32_dups; - int32_t *dptr = buffer; - - if (!(flags & HYBRID_FLAG) && !sent_bits && (zeros + ones + dups)) - while (count--) { - if (zeros) - *dptr <<= zeros; - else if (ones) - *dptr = ((*dptr + 1) << ones) - 1; - else if (dups) - *dptr = ((*dptr + (*dptr & 1)) << dups) - (*dptr & 1); - - dptr++; - } - else - shift += zeros + sent_bits + ones + dups; - } - - if (flags & HYBRID_FLAG) { - int32_t min_value, max_value, min_shifted, max_shifted; - - switch (flags & BYTES_STORED) { - case 0: - min_shifted = (min_value = -128 >> shift) << shift; - max_shifted = (max_value = 127 >> shift) << shift; - break; - - case 1: - min_shifted = (min_value = -32768 >> shift) << shift; - max_shifted = (max_value = 32767 >> shift) << shift; - break; - - case 2: - min_shifted = (min_value = -8388608 >> shift) << shift; - max_shifted = (max_value = 8388607 >> shift) << shift; - break; - - case 3: - default: - min_shifted = (min_value = (int32_t) 0x80000000 >> shift) << shift; - max_shifted = (max_value = (int32_t) 0x7FFFFFFF >> shift) << shift; - break; - } - - if (!(flags & MONO_FLAG)) - sample_count *= 2; - - while (sample_count--) { - if (*buffer < min_value) - *buffer++ = min_shifted; - else if (*buffer > max_value) - *buffer++ = max_shifted; - else - *buffer++ <<= shift; - } - } - else if (shift) { - if (!(flags & MONO_FLAG)) - sample_count *= 2; - - while (sample_count--) - *buffer++ <<= shift; - } -} - -// This function checks the crc value(s) for an unpacked block, returning the -// number of actual crc errors detected for the block. The block must be -// completely unpacked before this test is valid. For losslessly unpacked -// blocks of float or extended integer data the extended crc is also checked. -// Note that WavPack's crc is not a CCITT approved polynomial algorithm, but -// is a much simpler method that is virtually as robust for real world data. - -int check_crc_error (WavpackContext *wpc) -{ - WavpackStream *wps = &wpc->stream; - int result = 0; - - if (wps->crc != wps->wphdr.crc) - ++result; - - return result; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wavpack.h b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wavpack.h deleted file mode 100644 index 2e22fc51e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wavpack.h +++ /dev/null @@ -1,384 +0,0 @@ -/*////////////////////////////////////////////////////////////////////////// */ -/* **** WAVPACK **** // */ -/* Hybrid Lossless Wavefile Compressor // */ -/* Copyright (c) 1998 - 2004 Conifer Software. // */ -/* All Rights Reserved. // */ -/* Distributed under the BSD Software License (see license.txt) // */ -/*////////////////////////////////////////////////////////////////////////// */ - -/* wavpack.h */ - -#include - -/* This header file contains all the definitions required by WavPack. */ - -#ifdef __BORLANDC__ -typedef unsigned long uint32_t; -typedef long int32_t; -#elif defined(_WIN32) && !defined(__MINGW32__) -#include -typedef unsigned __int64 uint64_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef __int32 int32_t; -#else -#include -#endif - -typedef unsigned char uchar; - -#if !defined(__GNUC__) || defined(WIN32) -typedef unsigned short ushort; -typedef unsigned int uint; -#endif - -#include - -#define FALSE 0 -#define TRUE 1 - -/*//////////////////////////// WavPack Header ///////////////////////////////// */ - -/* Note that this is the ONLY structure that is written to (or read from) */ -/* WavPack 4.0 files, and is the preamble to every block in both the .wv */ -/* and .wvc files. */ - -typedef struct { - char ckID [4]; - uint32_t ckSize; - short version; - uchar track_no, index_no; - uint32_t total_samples, block_index, block_samples, flags, crc; -} WavpackHeader; - -#define WavpackHeaderFormat "4LS2LLLLL" - -/* or-values for "flags" */ - -#define BYTES_STORED 3 /* 1-4 bytes/sample */ -#define MONO_FLAG 4 /* not stereo */ -#define HYBRID_FLAG 8 /* hybrid mode */ -#define JOINT_STEREO 0x10 /* joint stereo */ -#define CROSS_DECORR 0x20 /* no-delay cross decorrelation */ -#define HYBRID_SHAPE 0x40 /* noise shape (hybrid mode only) */ -#define FLOAT_DATA 0x80 /* ieee 32-bit floating point data */ - -#define INT32_DATA 0x100 /* special extended int handling */ -#define HYBRID_BITRATE 0x200 /* bitrate noise (hybrid mode only) */ -#define HYBRID_BALANCE 0x400 /* balance noise (hybrid stereo mode only) */ - -#define INITIAL_BLOCK 0x800 /* initial block of multichannel segment */ -#define FINAL_BLOCK 0x1000 /* final block of multichannel segment */ - -#define SHIFT_LSB 13 -#define SHIFT_MASK (0x1fL << SHIFT_LSB) - -#define MAG_LSB 18 -#define MAG_MASK (0x1fL << MAG_LSB) - -#define SRATE_LSB 23 -#define SRATE_MASK (0xfL << SRATE_LSB) - -#define FALSE_STEREO 0x40000000 /* block is stereo, but data is mono */ - -#define IGNORED_FLAGS 0x18000000 /* reserved, but ignore if encountered */ -#define NEW_SHAPING 0x20000000 /* use IIR filter for negative shaping */ -#define UNKNOWN_FLAGS 0x80000000 /* also reserved, but refuse decode if */ - /* encountered */ - -#define MONO_DATA (MONO_FLAG | FALSE_STEREO) - -#define MIN_STREAM_VERS 0x402 /* lowest stream version we'll decode */ -#define MAX_STREAM_VERS 0x410 /* highest stream version we'll decode */ - -/*////////////////////////// WavPack Metadata ///////////////////////////////// */ - -/* This is an internal representation of metadata. */ - -typedef struct { - int32_t byte_length; - void *data; - uchar id; -} WavpackMetadata; - -#define ID_OPTIONAL_DATA 0x20 -#define ID_ODD_SIZE 0x40 -#define ID_LARGE 0x80 - -#define ID_DUMMY 0x0 -#define ID_ENCODER_INFO 0x1 -#define ID_DECORR_TERMS 0x2 -#define ID_DECORR_WEIGHTS 0x3 -#define ID_DECORR_SAMPLES 0x4 -#define ID_ENTROPY_VARS 0x5 -#define ID_HYBRID_PROFILE 0x6 -#define ID_SHAPING_WEIGHTS 0x7 -#define ID_FLOAT_INFO 0x8 -#define ID_INT32_INFO 0x9 -#define ID_WV_BITSTREAM 0xa -#define ID_WVC_BITSTREAM 0xb -#define ID_WVX_BITSTREAM 0xc -#define ID_CHANNEL_INFO 0xd - -#define ID_RIFF_HEADER (ID_OPTIONAL_DATA | 0x1) -#define ID_RIFF_TRAILER (ID_OPTIONAL_DATA | 0x2) -#define ID_REPLAY_GAIN (ID_OPTIONAL_DATA | 0x3) -#define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4) -#define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5) -#define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6) - -/*/////////////////////// WavPack Configuration /////////////////////////////// */ - -/* This internal structure is used during encode to provide configuration to */ -/* the encoding engine and during decoding to provide fle information back to */ -/* the higher level functions. Not all fields are used in both modes. */ - -typedef struct { - int bits_per_sample, bytes_per_sample; - int num_channels, float_norm_exp; - uint32_t flags, sample_rate, channel_mask; -} WavpackConfig; - -#define CONFIG_BYTES_STORED 3 /* 1-4 bytes/sample */ -#define CONFIG_MONO_FLAG 4 /* not stereo */ -#define CONFIG_HYBRID_FLAG 8 /* hybrid mode */ -#define CONFIG_JOINT_STEREO 0x10 /* joint stereo */ -#define CONFIG_CROSS_DECORR 0x20 /* no-delay cross decorrelation */ -#define CONFIG_HYBRID_SHAPE 0x40 /* noise shape (hybrid mode only) */ -#define CONFIG_FLOAT_DATA 0x80 /* ieee 32-bit floating point data */ - -#define CONFIG_FAST_FLAG 0x200 /* fast mode */ -#define CONFIG_HIGH_FLAG 0x800 /* high quality mode */ -#define CONFIG_VERY_HIGH_FLAG 0x1000 /* very high */ -#define CONFIG_BITRATE_KBPS 0x2000 /* bitrate is kbps, not bits / sample */ -#define CONFIG_AUTO_SHAPING 0x4000 /* automatic noise shaping */ -#define CONFIG_SHAPE_OVERRIDE 0x8000 /* shaping mode specified */ -#define CONFIG_JOINT_OVERRIDE 0x10000 /* joint-stereo mode specified */ -#define CONFIG_CREATE_EXE 0x40000 /* create executable */ -#define CONFIG_CREATE_WVC 0x80000 /* create correction file */ -#define CONFIG_OPTIMIZE_WVC 0x100000 /* maximize bybrid compression */ -#define CONFIG_CALC_NOISE 0x800000 /* calc noise in hybrid mode */ -#define CONFIG_LOSSY_MODE 0x1000000 /* obsolete (for information) */ -#define CONFIG_EXTRA_MODE 0x2000000 /* extra processing mode */ -#define CONFIG_SKIP_WVX 0x4000000 /* no wvx stream w/ floats & big ints */ -#define CONFIG_MD5_CHECKSUM 0x8000000 /* compute & store MD5 signature */ -#define CONFIG_OPTIMIZE_MONO 0x80000000 /* optimize for mono streams posing as stereo */ - -/*////////////////////////////// WavPack Stream /////////////////////////////// */ - -/* This internal structure contains everything required to handle a WavPack */ -/* "stream", which is defined as a stereo or mono stream of audio samples. For */ -/* multichannel audio several of these would be required. Each stream contains */ -/* pointers to hold a complete allocated block of WavPack data, although it's */ -/* possible to decode WavPack blocks without buffering an entire block. */ - -typedef int32_t (*read_stream)(void *, int32_t); - -typedef struct bs { - uchar *buf, *end, *ptr; - void (*wrap)(struct bs *bs); - uint32_t file_bytes, sr; - int error, bc; - read_stream file; -} Bitstream; - -#define MAX_NTERMS 16 -#define MAX_TERM 8 - -struct decorr_pass { - short term, delta, weight_A, weight_B; - int32_t samples_A [MAX_TERM], samples_B [MAX_TERM]; -}; - -struct entropy_data { - uint32_t median [3], slow_level, error_limit; -}; - -struct words_data { - uint32_t bitrate_delta [2], bitrate_acc [2]; - uint32_t pend_data, holding_one, zeros_acc; - int holding_zero, pend_count; - struct entropy_data c [2]; -}; - -typedef struct { - WavpackHeader wphdr; - Bitstream wvbits; - - struct words_data w; - - int num_terms, mute_error; - uint32_t sample_index, crc; - - uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups; - uchar float_flags, float_shift, float_max_exp, float_norm_exp; - - struct decorr_pass decorr_passes [MAX_NTERMS]; - -} WavpackStream; - -/* flags for float_flags: */ - -#define FLOAT_SHIFT_ONES 1 /* bits left-shifted into float = '1' */ -#define FLOAT_SHIFT_SAME 2 /* bits left-shifted into float are the same */ -#define FLOAT_SHIFT_SENT 4 /* bits shifted into float are sent literally */ -#define FLOAT_ZEROS_SENT 8 /* "zeros" are not all real zeros */ -#define FLOAT_NEG_ZEROS 0x10 /* contains negative zeros */ -#define FLOAT_EXCEPTIONS 0x20 /* contains exceptions (inf, nan, etc.) */ - -/*///////////////////////////// WavPack Context /////////////////////////////// */ - -/* This internal structure holds everything required to encode or decode WavPack */ -/* files. It is recommended that direct access to this structure be minimized */ -/* and the provided utilities used instead. */ - -typedef struct { - WavpackConfig config; - WavpackStream stream; - - uchar read_buffer [1024]; - char error_message [80]; - - read_stream infile; - uint32_t total_samples, crc_errors, first_flags; - int open_flags, norm_offset, reduced_channels, lossy_blocks; - -} WavpackContext; - -/*////////////////////// function prototypes and macros ////////////////////// */ - -#define CLEAR(destin) memset (&destin, 0, sizeof (destin)); - -/* bits.c */ - -void bs_open_read (Bitstream *bs, uchar *buffer_start, uchar *buffer_end, read_stream file, uint32_t file_bytes); - -#define bs_is_open(bs) ((bs)->ptr != NULL) - -#define getbit(bs) ( \ - (((bs)->bc) ? \ - ((bs)->bc--, (bs)->sr & 1) : \ - (((++((bs)->ptr) != (bs)->end) ? (void) 0 : (bs)->wrap (bs)), (bs)->bc = 7, ((bs)->sr = *((bs)->ptr)) & 1) \ - ) ? \ - ((bs)->sr >>= 1, 1) : \ - ((bs)->sr >>= 1, 0) \ -) - -#define getbits(value, nbits, bs) { \ - while ((nbits) > (bs)->bc) { \ - if (++((bs)->ptr) == (bs)->end) (bs)->wrap (bs); \ - (bs)->sr |= (int32_t)*((bs)->ptr) << (bs)->bc; \ - (bs)->bc += 8; \ - } \ - *(value) = (bs)->sr; \ - if ((bs)->bc > 32) { \ - (bs)->bc -= (nbits); \ - (bs)->sr = *((bs)->ptr) >> (8 - (bs)->bc); \ - } \ - else { \ - (bs)->bc -= (nbits); \ - (bs)->sr >>= (nbits); \ - } \ -} - -void little_endian_to_native (void *data, char *format); -void native_to_little_endian (void *data, char *format); - -/* These macros implement the weight application and update operations */ -/* that are at the heart of the decorrelation loops. Note that when there */ -/* are several alternative versions of the same macro (marked with PERFCOND) */ -/* then the versions are functionally equivalent with respect to WavPack */ -/* decoding and the user should choose the one that provides the best */ -/* performance. This may be easier to check when NOT using the assembly */ -/* language optimizations. */ - -#if 1 /* PERFCOND */ -#define apply_weight_i(weight, sample) ((weight * sample + 512) >> 10) -#else -#define apply_weight_i(weight, sample) ((((weight * sample) >> 8) + 2) >> 2) -#endif - -#define apply_weight_f(weight, sample) (((((sample & 0xffffL) * weight) >> 9) + \ - (((sample & ~0xffffL) >> 9) * weight) + 1) >> 1) - -#if 1 /* PERFCOND */ -#define apply_weight(weight, sample) (sample != (short) sample ? \ - apply_weight_f (weight, sample) : apply_weight_i (weight, sample)) -#else -#define apply_weight(weight, sample) ((int32_t)((weight * (int64_t) sample + 512) >> 10)) -#endif - -#if 0 /* PERFCOND */ -#define update_weight(weight, delta, source, result) \ - if (source && result) { int32_t s = (int32_t) (source ^ result) >> 31; weight = (delta ^ s) + (weight - s); } -#elif 1 -#define update_weight(weight, delta, source, result) \ - if (source && result) weight += (((source ^ result) >> 30) | 1) * delta -#else -#define update_weight(weight, delta, source, result) \ - if (source && result) (source ^ result) < 0 ? (weight -= delta) : (weight += delta) -#endif - -#define update_weight_clip(weight, delta, source, result) \ - if (source && result && ((source ^ result) < 0 ? (weight -= delta) < -1024 : (weight += delta) > 1024)) \ - weight = weight < 0 ? -1024 : 1024 - -/* unpack.c */ - -int unpack_init (WavpackContext *wpc); -int init_wv_bitstream (WavpackContext *wpc, WavpackMetadata *wpmd); -int read_decorr_terms (WavpackStream *wps, WavpackMetadata *wpmd); -int read_decorr_weights (WavpackStream *wps, WavpackMetadata *wpmd); -int read_decorr_samples (WavpackStream *wps, WavpackMetadata *wpmd); -int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd); -int read_int32_info (WavpackStream *wps, WavpackMetadata *wpmd); -int read_channel_info (WavpackContext *wpc, WavpackMetadata *wpmd); -int read_config_info (WavpackContext *wpc, WavpackMetadata *wpmd); -int32_t unpack_samples (WavpackContext *wpc, int32_t *buffer, uint32_t sample_count); -int check_crc_error (WavpackContext *wpc); - -/* metadata.c stuff */ - -int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd); -int process_metadata (WavpackContext *wpc, WavpackMetadata *wpmd); - -/* words.c stuff */ - -int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd); -int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd); -int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags, - struct words_data *w, Bitstream *bs); -int32_t exp2s (int log); -int restore_weight (signed char weight); - -#define WORD_EOF (1L << 31) - -/* float.c */ - -int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd); -void float_values (WavpackStream *wps, int32_t *values, int32_t num_values); - -/* wputils.c */ - -WavpackContext *WavpackOpenFileInput (read_stream infile, char *error); - -int WavpackGetMode (WavpackContext *wpc); - -#define MODE_WVC 0x1 -#define MODE_LOSSLESS 0x2 -#define MODE_HYBRID 0x4 -#define MODE_FLOAT 0x8 -#define MODE_VALID_TAG 0x10 -#define MODE_HIGH 0x20 -#define MODE_FAST 0x40 - -uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples); -uint32_t WavpackGetNumSamples (WavpackContext *wpc); -uint32_t WavpackGetSampleIndex (WavpackContext *wpc); -int WavpackGetNumErrors (WavpackContext *wpc); -int WavpackLossyBlocks (WavpackContext *wpc); -uint32_t WavpackGetSampleRate (WavpackContext *wpc); -int WavpackGetBitsPerSample (WavpackContext *wpc); -int WavpackGetBytesPerSample (WavpackContext *wpc); -int WavpackGetNumChannels (WavpackContext *wpc); -int WavpackGetReducedChannels (WavpackContext *wpc); diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/words.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/words.c deleted file mode 100644 index d39563b0c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/words.c +++ /dev/null @@ -1,560 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// words.c - -// This module provides entropy word encoding and decoding functions using -// a variation on the Rice method. This was introduced in version 3.93 -// because it allows splitting the data into a "lossy" stream and a -// "correction" stream in a very efficient manner and is therefore ideal -// for the "hybrid" mode. For 4.0, the efficiency of this method was -// significantly improved by moving away from the normal Rice restriction of -// using powers of two for the modulus divisions and now the method can be -// used for both hybrid and pure lossless encoding. - -// Samples are divided by median probabilities at 5/7 (71.43%), 10/49 (20.41%), -// and 20/343 (5.83%). Each zone has 3.5 times fewer samples than the -// previous. Using standard Rice coding on this data would result in 1.4 -// bits per sample average (not counting sign bit). However, there is a -// very simple encoding that is over 99% efficient with this data and -// results in about 1.22 bits per sample. - -#include "wavpack.h" - -#include - -//////////////////////////////// local macros ///////////////////////////////// - -#define LIMIT_ONES 16 // maximum consecutive 1s sent for "div" data - -// these control the time constant "slow_level" which is used for hybrid mode -// that controls bitrate as a function of residual level (HYBRID_BITRATE). -#define SLS 8 -#define SLO ((1 << (SLS - 1))) - -// these control the time constant of the 3 median level breakpoints -#define DIV0 128 // 5/7 of samples -#define DIV1 64 // 10/49 of samples -#define DIV2 32 // 20/343 of samples - -// this macro retrieves the specified median breakpoint (without frac; min = 1) -#define GET_MED(med) (((c->median [med]) >> 4) + 1) - -// These macros update the specified median breakpoints. Note that the median -// is incremented when the sample is higher than the median, else decremented. -// They are designed so that the median will never drop below 1 and the value -// is essentially stationary if there are 2 increments for every 5 decrements. - -#define INC_MED0() (c->median [0] += ((c->median [0] + DIV0) / DIV0) * 5) -#define DEC_MED0() (c->median [0] -= ((c->median [0] + (DIV0-2)) / DIV0) * 2) -#define INC_MED1() (c->median [1] += ((c->median [1] + DIV1) / DIV1) * 5) -#define DEC_MED1() (c->median [1] -= ((c->median [1] + (DIV1-2)) / DIV1) * 2) -#define INC_MED2() (c->median [2] += ((c->median [2] + DIV2) / DIV2) * 5) -#define DEC_MED2() (c->median [2] -= ((c->median [2] + (DIV2-2)) / DIV2) * 2) - -#define count_bits(av) ( \ - (av) < (1 << 8) ? nbits_table [av] : \ - ( \ - (av) < (1L << 16) ? nbits_table [(av) >> 8] + 8 : \ - ((av) < (1L << 24) ? nbits_table [(av) >> 16] + 16 : nbits_table [(av) >> 24] + 24) \ - ) \ -) - -///////////////////////////// local table storage //////////////////////////// - -const char nbits_table [] = { - 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, // 0 - 15 - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 16 - 31 - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 32 - 47 - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, // 48 - 63 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 64 - 79 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 80 - 95 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 96 - 111 - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 112 - 127 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 128 - 143 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 144 - 159 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 160 - 175 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 176 - 191 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 192 - 207 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 208 - 223 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 224 - 239 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 // 240 - 255 -}; - -static const uchar log2_table [] = { - 0x00, 0x01, 0x03, 0x04, 0x06, 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x10, 0x11, 0x12, 0x14, 0x15, - 0x16, 0x18, 0x19, 0x1a, 0x1c, 0x1d, 0x1e, 0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2a, - 0x2c, 0x2d, 0x2e, 0x2f, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37, 0x38, 0x39, 0x3b, 0x3c, 0x3d, 0x3e, - 0x3f, 0x41, 0x42, 0x43, 0x44, 0x45, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4d, 0x4e, 0x4f, 0x50, 0x51, - 0x52, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, - 0x64, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x74, 0x75, - 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, - 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, - 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, - 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb2, - 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc0, - 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcb, 0xcc, 0xcd, 0xce, - 0xcf, 0xd0, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd8, 0xd9, 0xda, 0xdb, - 0xdc, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe4, 0xe5, 0xe6, 0xe7, 0xe7, - 0xe8, 0xe9, 0xea, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xee, 0xef, 0xf0, 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, - 0xf4, 0xf5, 0xf6, 0xf7, 0xf7, 0xf8, 0xf9, 0xf9, 0xfa, 0xfb, 0xfc, 0xfc, 0xfd, 0xfe, 0xff, 0xff -}; - -static const uchar exp2_table [] = { - 0x00, 0x01, 0x01, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x08, 0x09, 0x0a, 0x0b, - 0x0b, 0x0c, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x13, 0x14, 0x15, 0x16, 0x16, - 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1d, 0x1e, 0x1f, 0x20, 0x20, 0x21, 0x22, 0x23, - 0x24, 0x24, 0x25, 0x26, 0x27, 0x28, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3a, 0x3b, 0x3c, 0x3d, - 0x3e, 0x3f, 0x40, 0x41, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b, - 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, - 0x5b, 0x5c, 0x5d, 0x5e, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, - 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, - 0x9c, 0x9d, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, - 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, - 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc8, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf, 0xd0, 0xd2, 0xd3, 0xd4, - 0xd6, 0xd7, 0xd8, 0xd9, 0xdb, 0xdc, 0xdd, 0xde, 0xe0, 0xe1, 0xe2, 0xe4, 0xe5, 0xe6, 0xe8, 0xe9, - 0xea, 0xec, 0xed, 0xee, 0xf0, 0xf1, 0xf2, 0xf4, 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff -}; - -static const char ones_count_table [] = { - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5, - 0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,8 -}; - -///////////////////////////// executable code //////////////////////////////// - -void init_words (WavpackStream *wps) -{ - CLEAR (wps->w); -} - -static int mylog2 (uint32_t avalue); - -// Read the median log2 values from the specifed metadata structure, convert -// them back to 32-bit unsigned values and store them. If length is not -// exactly correct then we flag and return an error. - -int read_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd) -{ - uchar *byteptr = wpmd->data; - - if (wpmd->byte_length != ((wps->wphdr.flags & MONO_DATA) ? 6 : 12)) - return FALSE; - - wps->w.c [0].median [0] = exp2s (byteptr [0] + (byteptr [1] << 8)); - wps->w.c [0].median [1] = exp2s (byteptr [2] + (byteptr [3] << 8)); - wps->w.c [0].median [2] = exp2s (byteptr [4] + (byteptr [5] << 8)); - - if (!(wps->wphdr.flags & MONO_DATA)) { - wps->w.c [1].median [0] = exp2s (byteptr [6] + (byteptr [7] << 8)); - wps->w.c [1].median [1] = exp2s (byteptr [8] + (byteptr [9] << 8)); - wps->w.c [1].median [2] = exp2s (byteptr [10] + (byteptr [11] << 8)); - } - - return TRUE; -} - -// Read the hybrid related values from the specifed metadata structure, convert -// them back to their internal formats and store them. The extended profile -// stuff is not implemented yet, so return an error if we get more data than -// we know what to do with. - -int read_hybrid_profile (WavpackStream *wps, WavpackMetadata *wpmd) -{ - uchar *byteptr = wpmd->data; - uchar *endptr = byteptr + wpmd->byte_length; - - if (wps->wphdr.flags & HYBRID_BITRATE) { - wps->w.c [0].slow_level = exp2s (byteptr [0] + (byteptr [1] << 8)); - byteptr += 2; - - if (!(wps->wphdr.flags & MONO_DATA)) { - wps->w.c [1].slow_level = exp2s (byteptr [0] + (byteptr [1] << 8)); - byteptr += 2; - } - } - - wps->w.bitrate_acc [0] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16; - byteptr += 2; - - if (!(wps->wphdr.flags & MONO_DATA)) { - wps->w.bitrate_acc [1] = (int32_t)(byteptr [0] + (byteptr [1] << 8)) << 16; - byteptr += 2; - } - - if (byteptr < endptr) { - wps->w.bitrate_delta [0] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - byteptr += 2; - - if (!(wps->wphdr.flags & MONO_DATA)) { - wps->w.bitrate_delta [1] = exp2s ((short)(byteptr [0] + (byteptr [1] << 8))); - byteptr += 2; - } - - if (byteptr < endptr) - return FALSE; - } - else - wps->w.bitrate_delta [0] = wps->w.bitrate_delta [1] = 0; - - return TRUE; -} - -// This function is called during both encoding and decoding of hybrid data to -// update the "error_limit" variable which determines the maximum sample error -// allowed in the main bitstream. In the HYBRID_BITRATE mode (which is the only -// currently implemented) this is calculated from the slow_level values and the -// bitrate accumulators. Note that the bitrate accumulators can be changing. - -void update_error_limit (struct words_data *w, uint32_t flags) -{ - int bitrate_0 = (w->bitrate_acc [0] += w->bitrate_delta [0]) >> 16; - - if (flags & MONO_DATA) { - if (flags & HYBRID_BITRATE) { - int slow_log_0 = (w->c [0].slow_level + SLO) >> SLS; - - if (slow_log_0 - bitrate_0 > -0x100) - w->c [0].error_limit = exp2s (slow_log_0 - bitrate_0 + 0x100); - else - w->c [0].error_limit = 0; - } - else - w->c [0].error_limit = exp2s (bitrate_0); - } - else { - int bitrate_1 = (w->bitrate_acc [1] += w->bitrate_delta [1]) >> 16; - - if (flags & HYBRID_BITRATE) { - int slow_log_0 = (w->c [0].slow_level + SLO) >> SLS; - int slow_log_1 = (w->c [1].slow_level + SLO) >> SLS; - - if (flags & HYBRID_BALANCE) { - int balance = (slow_log_1 - slow_log_0 + bitrate_1 + 1) >> 1; - - if (balance > bitrate_0) { - bitrate_1 = bitrate_0 * 2; - bitrate_0 = 0; - } - else if (-balance > bitrate_0) { - bitrate_0 = bitrate_0 * 2; - bitrate_1 = 0; - } - else { - bitrate_1 = bitrate_0 + balance; - bitrate_0 = bitrate_0 - balance; - } - } - - if (slow_log_0 - bitrate_0 > -0x100) - w->c [0].error_limit = exp2s (slow_log_0 - bitrate_0 + 0x100); - else - w->c [0].error_limit = 0; - - if (slow_log_1 - bitrate_1 > -0x100) - w->c [1].error_limit = exp2s (slow_log_1 - bitrate_1 + 0x100); - else - w->c [1].error_limit = 0; - } - else { - w->c [0].error_limit = exp2s (bitrate_0); - w->c [1].error_limit = exp2s (bitrate_1); - } - } -} - -static uint32_t read_code (Bitstream *bs, uint32_t maxcode); - -// Read the next word from the bitstream "wvbits" and return the value. This -// function can be used for hybrid or lossless streams, but since an -// optimized version is available for lossless this function would normally -// be used for hybrid only. If a hybrid lossless stream is being read then -// the "correction" offset is written at the specified pointer. A return value -// of WORD_EOF indicates that the end of the bitstream was reached (all 1s) or -// some other error occurred. - -int32_t get_words (int32_t *buffer, int nsamples, uint32_t flags, - struct words_data *w, Bitstream *bs) -{ - register struct entropy_data *c = w->c; - int csamples; - - if (!(flags & MONO_DATA)) - nsamples *= 2; - - for (csamples = 0; csamples < nsamples; ++csamples) { - uint32_t ones_count, low, mid, high; - - if (!(flags & MONO_DATA)) - c = w->c + (csamples & 1); - - if (!(w->c [0].median [0] & ~1) && !w->holding_zero && !w->holding_one && !(w->c [1].median [0] & ~1)) { - uint32_t mask; - int cbits; - - if (w->zeros_acc) { - if (--w->zeros_acc) { - c->slow_level -= (c->slow_level + SLO) >> SLS; - *buffer++ = 0; - continue; - } - } - else { - for (cbits = 0; cbits < 33 && getbit (bs); ++cbits); - - if (cbits == 33) - break; - - if (cbits < 2) - w->zeros_acc = cbits; - else { - for (mask = 1, w->zeros_acc = 0; --cbits; mask <<= 1) - if (getbit (bs)) - w->zeros_acc |= mask; - - w->zeros_acc |= mask; - } - - if (w->zeros_acc) { - c->slow_level -= (c->slow_level + SLO) >> SLS; - CLEAR (w->c [0].median); - CLEAR (w->c [1].median); - *buffer++ = 0; - continue; - } - } - } - - if (w->holding_zero) - ones_count = w->holding_zero = 0; - else { - int next8; - - if (bs->bc < 8) { - if (++(bs->ptr) == bs->end) - bs->wrap (bs); - - next8 = (bs->sr |= *(bs->ptr) << bs->bc) & 0xff; - bs->bc += 8; - } - else - next8 = bs->sr & 0xff; - - if (next8 == 0xff) { - bs->bc -= 8; - bs->sr >>= 8; - - for (ones_count = 8; ones_count < (LIMIT_ONES + 1) && getbit (bs); ++ones_count); - - if (ones_count == (LIMIT_ONES + 1)) - break; - - if (ones_count == LIMIT_ONES) { - uint32_t mask; - int cbits; - - for (cbits = 0; cbits < 33 && getbit (bs); ++cbits); - - if (cbits == 33) - break; - - if (cbits < 2) - ones_count = cbits; - else { - for (mask = 1, ones_count = 0; --cbits; mask <<= 1) - if (getbit (bs)) - ones_count |= mask; - - ones_count |= mask; - } - - ones_count += LIMIT_ONES; - } - } - else { - bs->bc -= (ones_count = ones_count_table [next8]) + 1; - bs->sr >>= ones_count + 1; - } - - if (w->holding_one) { - w->holding_one = ones_count & 1; - ones_count = (ones_count >> 1) + 1; - } - else { - w->holding_one = ones_count & 1; - ones_count >>= 1; - } - - w->holding_zero = ~w->holding_one & 1; - } - - if ((flags & HYBRID_FLAG) && ((flags & MONO_DATA) || !(csamples & 1))) - update_error_limit (w, flags); - - if (ones_count == 0) { - low = 0; - high = GET_MED (0) - 1; - DEC_MED0 (); - } - else { - low = GET_MED (0); - INC_MED0 (); - - if (ones_count == 1) { - high = low + GET_MED (1) - 1; - DEC_MED1 (); - } - else { - low += GET_MED (1); - INC_MED1 (); - - if (ones_count == 2) { - high = low + GET_MED (2) - 1; - DEC_MED2 (); - } - else { - low += (ones_count - 2) * GET_MED (2); - high = low + GET_MED (2) - 1; - INC_MED2 (); - } - } - } - - mid = (high + low + 1) >> 1; - - if (!c->error_limit) - mid = read_code (bs, high - low) + low; - else while (high - low > c->error_limit) { - if (getbit (bs)) - mid = (high + (low = mid) + 1) >> 1; - else - mid = ((high = mid - 1) + low + 1) >> 1; - } - - *buffer++ = getbit (bs) ? ~mid : mid; - - if (flags & HYBRID_BITRATE) - c->slow_level = c->slow_level - ((c->slow_level + SLO) >> SLS) + mylog2 (mid); - } - - return (flags & MONO_DATA) ? csamples : (csamples / 2); -} - -// Read a single unsigned value from the specified bitstream with a value -// from 0 to maxcode. If there are exactly a power of two number of possible -// codes then this will read a fixed number of bits; otherwise it reads the -// minimum number of bits and then determines whether another bit is needed -// to define the code. - -static uint32_t read_code (Bitstream *bs, uint32_t maxcode) -{ - int bitcount = count_bits (maxcode); - uint32_t extras = (1L << bitcount) - maxcode - 1, code; - - if (!bitcount) - return 0; - - getbits (&code, bitcount - 1, bs); - code &= (1L << (bitcount - 1)) - 1; - - if (code >= extras) { - code = (code << 1) - extras; - - if (getbit (bs)) - ++code; - } - - return code; -} - -// The concept of a base 2 logarithm is used in many parts of WavPack. It is -// a way of sufficiently accurately representing 32-bit signed and unsigned -// values storing only 16 bits (actually fewer). It is also used in the hybrid -// mode for quickly comparing the relative magnitude of large values (i.e. -// division) and providing smooth exponentials using only addition. - -// These are not strict logarithms in that they become linear around zero and -// can therefore represent both zero and negative values. They have 8 bits -// of precision and in "roundtrip" conversions the total error never exceeds 1 -// part in 225 except for the cases of +/-115 and +/-195 (which error by 1). - - -// This function returns the log2 for the specified 32-bit unsigned value. -// The maximum value allowed is about 0xff800000 and returns 8447. - -static int mylog2 (uint32_t avalue) -{ - int dbits; - - if ((avalue += avalue >> 9) < (1 << 8)) { - dbits = nbits_table [avalue]; - return (dbits << 8) + log2_table [(avalue << (9 - dbits)) & 0xff]; - } - else { - if (avalue < (1L << 16)) - dbits = nbits_table [avalue >> 8] + 8; - else if (avalue < (1L << 24)) - dbits = nbits_table [avalue >> 16] + 16; - else - dbits = nbits_table [avalue >> 24] + 24; - - return (dbits << 8) + log2_table [(avalue >> (dbits - 9)) & 0xff]; - } -} - -// This function returns the log2 for the specified 32-bit signed value. -// All input values are valid and the return values are in the range of -// +/- 8192. - -int log2s (int32_t value) -{ - return (value < 0) ? -mylog2 (-value) : mylog2 (value); -} - -// This function returns the original integer represented by the supplied -// logarithm (at least within the provided accuracy). The log is signed, -// but since a full 32-bit value is returned this can be used for unsigned -// conversions as well (i.e. the input range is -8192 to +8447). - -int32_t exp2s (int log) -{ - uint32_t value; - - if (log < 0) - return -exp2s (-log); - - value = exp2_table [log & 0xff] | 0x100; - - if ((log >>= 8) <= 9) - return value >> (9 - log); - else - return value << (log - 9); -} - -// These two functions convert internal weights (which are normally +/-1024) -// to and from an 8-bit signed character version for storage in metadata. The -// weights are clipped here in the case that they are outside that range. - -int restore_weight (signed char weight) -{ - int result; - - if ((result = (int) weight << 3) > 0) - result += (result + 64) >> 7; - - return result; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wputils.c b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wputils.c deleted file mode 100644 index 1bc656103..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wputils.c +++ /dev/null @@ -1,351 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// wputils.c - -// This module provides a high-level interface for decoding WavPack 4.0 audio -// streams and files. WavPack data is read with a stream reading callback. No -// direct seeking is provided for, but it is possible to start decoding -// anywhere in a WavPack stream. In this case, WavPack will be able to provide -// the sample-accurate position when it synchs with the data and begins -// decoding. - -#include "wavpack.h" - -#include - -///////////////////////////// local table storage //////////////////////////// - -const uint32_t sample_rates [] = { 6000, 8000, 9600, 11025, 12000, 16000, 22050, - 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000 }; - -///////////////////////////// executable code //////////////////////////////// - -static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr); - -// This function reads data from the specified stream in search of a valid -// WavPack 4.0 audio block. If this fails in 1 megabyte (or an invalid or -// unsupported WavPack block is encountered) then an appropriate message is -// copied to "error" and NULL is returned, otherwise a pointer to a -// WavpackContext structure is returned (which is used to call all other -// functions in this module). This can be initiated at the beginning of a -// WavPack file, or anywhere inside a WavPack file. To determine the exact -// position within the file use WavpackGetSampleIndex(). For demonstration -// purposes this uses a single static copy of the WavpackContext structure, -// so obviously it cannot be used for more than one file at a time. Also, -// this function will not handle "correction" files, plays only the first -// two channels of multi-channel files, and is limited in resolution in some -// large integer or floating point files (but always provides at least 24 bits -// of resolution). - -static WavpackContext wpc; - -WavpackContext *WavpackOpenFileInput (read_stream infile, char *error) -{ - WavpackStream *wps = &wpc.stream; - uint32_t bcount; - - CLEAR (wpc); - wpc.infile = infile; - wpc.total_samples = (uint32_t) -1; - wpc.norm_offset = 0; - wpc.open_flags = 0; - - // open the source file for reading and store the size - - while (!wps->wphdr.block_samples) { - - bcount = read_next_header (wpc.infile, &wps->wphdr); - - if (bcount == (uint32_t) -1) { - strcpy (error, "not compatible with this version of WavPack file!"); - return NULL; - } - - if (wps->wphdr.block_samples && wps->wphdr.total_samples != (uint32_t) -1) - wpc.total_samples = wps->wphdr.total_samples; - - if (!unpack_init (&wpc)) { - strcpy (error, wpc.error_message [0] ? wpc.error_message : - "not compatible with this version of WavPack file!"); - - return NULL; - } - } - - wpc.config.flags &= ~0xff; - wpc.config.flags |= wps->wphdr.flags & 0xff; - wpc.config.bytes_per_sample = (wps->wphdr.flags & BYTES_STORED) + 1; - wpc.config.float_norm_exp = wps->float_norm_exp; - - wpc.config.bits_per_sample = (wpc.config.bytes_per_sample * 8) - - ((wps->wphdr.flags & SHIFT_MASK) >> SHIFT_LSB); - - if (wpc.config.flags & FLOAT_DATA) { - wpc.config.bytes_per_sample = 3; - wpc.config.bits_per_sample = 24; - } - - if (!wpc.config.sample_rate) { - if (!wps || !wps->wphdr.block_samples || (wps->wphdr.flags & SRATE_MASK) == SRATE_MASK) - wpc.config.sample_rate = 44100; - else - wpc.config.sample_rate = sample_rates [(wps->wphdr.flags & SRATE_MASK) >> SRATE_LSB]; - } - - if (!wpc.config.num_channels) { - wpc.config.num_channels = (wps->wphdr.flags & MONO_FLAG) ? 1 : 2; - wpc.config.channel_mask = 0x5 - wpc.config.num_channels; - } - - if (!(wps->wphdr.flags & FINAL_BLOCK)) - wpc.reduced_channels = (wps->wphdr.flags & MONO_FLAG) ? 1 : 2; - - return &wpc; -} - -// This function obtains general information about an open file and returns -// a mask with the following bit values: - -// MODE_LOSSLESS: file is lossless (pure lossless only) -// MODE_HYBRID: file is hybrid mode (lossy part only) -// MODE_FLOAT: audio data is 32-bit ieee floating point (but will provided -// in 24-bit integers for convenience) -// MODE_HIGH: file was created in "high" mode (information only) -// MODE_FAST: file was created in "fast" mode (information only) - -int WavpackGetMode (WavpackContext *wpc) -{ - int mode = 0; - - if (wpc) { - if (wpc->config.flags & CONFIG_HYBRID_FLAG) - mode |= MODE_HYBRID; - else if (!(wpc->config.flags & CONFIG_LOSSY_MODE)) - mode |= MODE_LOSSLESS; - - if (wpc->lossy_blocks) - mode &= ~MODE_LOSSLESS; - - if (wpc->config.flags & CONFIG_FLOAT_DATA) - mode |= MODE_FLOAT; - - if (wpc->config.flags & CONFIG_HIGH_FLAG) - mode |= MODE_HIGH; - - if (wpc->config.flags & CONFIG_FAST_FLAG) - mode |= MODE_FAST; - } - - return mode; -} - -// Unpack the specified number of samples from the current file position. -// Note that "samples" here refers to "complete" samples, which would be -// 2 longs for stereo files. The audio data is returned right-justified in -// 32-bit longs in the endian mode native to the executing processor. So, -// if the original data was 16-bit, then the values returned would be -// +/-32k. Floating point data will be returned as 24-bit integers (and may -// also be clipped). The actual number of samples unpacked is returned, -// which should be equal to the number requested unless the end of fle is -// encountered or an error occurs. - -uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t samples) -{ - WavpackStream *wps = &wpc->stream; - uint32_t bcount, samples_unpacked = 0, samples_to_unpack; - int num_channels = wpc->config.num_channels; - - while (samples) { - if (!wps->wphdr.block_samples || !(wps->wphdr.flags & INITIAL_BLOCK) || - wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) { - bcount = read_next_header (wpc->infile, &wps->wphdr); - - if (bcount == (uint32_t) -1) - break; - - if (!wps->wphdr.block_samples || wps->sample_index == wps->wphdr.block_index) - if (!unpack_init (wpc)) - break; - } - - if (!wps->wphdr.block_samples || !(wps->wphdr.flags & INITIAL_BLOCK) || - wps->sample_index >= wps->wphdr.block_index + wps->wphdr.block_samples) - continue; - - if (wps->sample_index < wps->wphdr.block_index) { - samples_to_unpack = wps->wphdr.block_index - wps->sample_index; - - if (samples_to_unpack > samples) - samples_to_unpack = samples; - - wps->sample_index += samples_to_unpack; - samples_unpacked += samples_to_unpack; - samples -= samples_to_unpack; - - if (wpc->reduced_channels) - samples_to_unpack *= wpc->reduced_channels; - else - samples_to_unpack *= num_channels; - - while (samples_to_unpack--) - *buffer++ = 0; - - continue; - } - - samples_to_unpack = wps->wphdr.block_index + wps->wphdr.block_samples - wps->sample_index; - - if (samples_to_unpack > samples) - samples_to_unpack = samples; - - unpack_samples (wpc, buffer, samples_to_unpack); - - if (wpc->reduced_channels) - buffer += samples_to_unpack * wpc->reduced_channels; - else - buffer += samples_to_unpack * num_channels; - - samples_unpacked += samples_to_unpack; - samples -= samples_to_unpack; - - if (wps->sample_index == wps->wphdr.block_index + wps->wphdr.block_samples) { - if (check_crc_error (wpc)) - wpc->crc_errors++; - } - - if (wps->sample_index == wpc->total_samples) - break; - } - - return samples_unpacked; -} - -// Get total number of samples contained in the WavPack file, or -1 if unknown - -uint32_t WavpackGetNumSamples (WavpackContext *wpc) -{ - return wpc ? wpc->total_samples : (uint32_t) -1; -} - -// Get the current sample index position, or -1 if unknown - -uint32_t WavpackGetSampleIndex (WavpackContext *wpc) -{ - if (wpc) - return wpc->stream.sample_index; - - return (uint32_t) -1; -} - -// Get the number of errors encountered so far - -int WavpackGetNumErrors (WavpackContext *wpc) -{ - return wpc ? wpc->crc_errors : 0; -} - -// return TRUE if any uncorrected lossy blocks were actually written or read - -int WavpackLossyBlocks (WavpackContext *wpc) -{ - return wpc ? wpc->lossy_blocks : 0; -} - -// Returns the sample rate of the specified WavPack file - -uint32_t WavpackGetSampleRate (WavpackContext *wpc) -{ - return wpc ? wpc->config.sample_rate : 44100; -} - -// Returns the number of channels of the specified WavPack file. Note that -// this is the actual number of channels contained in the file, but this -// version can only decode the first two. - -int WavpackGetNumChannels (WavpackContext *wpc) -{ - return wpc ? wpc->config.num_channels : 2; -} - -// Returns the actual number of valid bits per sample contained in the -// original file, which may or may not be a multiple of 8. Floating data -// always has 32 bits, integers may be from 1 to 32 bits each. When this -// value is not a multiple of 8, then the "extra" bits are located in the -// LSBs of the results. That is, values are right justified when unpacked -// into longs, but are left justified in the number of bytes used by the -// original data. - -int WavpackGetBitsPerSample (WavpackContext *wpc) -{ - return wpc ? wpc->config.bits_per_sample : 16; -} - -// Returns the number of bytes used for each sample (1 to 4) in the original -// file. This is required information for the user of this module because the -// audio data is returned in the LOWER bytes of the long buffer and must be -// left-shifted 8, 16, or 24 bits if normalized longs are required. - -int WavpackGetBytesPerSample (WavpackContext *wpc) -{ - return wpc ? wpc->config.bytes_per_sample : 2; -} - -// This function will return the actual number of channels decoded from the -// file (which may or may not be less than the actual number of channels, but -// will always be 1 or 2). Normally, this will be the front left and right -// channels of a multi-channel file. - -int WavpackGetReducedChannels (WavpackContext *wpc) -{ - if (wpc) - return wpc->reduced_channels ? wpc->reduced_channels : wpc->config.num_channels; - else - return 2; -} - -// Read from current file position until a valid 32-byte WavPack 4.0 header is -// found and read into the specified pointer. The number of bytes skipped is -// returned. If no WavPack header is found within 1 meg, then a -1 is returned -// to indicate the error. No additional bytes are read past the header and it -// is returned in the processor's native endian mode. Seeking is not required. - -static uint32_t read_next_header (read_stream infile, WavpackHeader *wphdr) -{ - char buffer [sizeof (*wphdr)], *sp = buffer + sizeof (*wphdr), *ep = sp; - uint32_t bytes_skipped = 0; - int bleft; - - while (1) { - if (sp < ep) { - bleft = ep - sp; - memcpy (buffer, sp, bleft); - } - else - bleft = 0; - - if (infile (buffer + bleft, sizeof (*wphdr) - bleft) != (int32_t) sizeof (*wphdr) - bleft) - return -1; - - sp = buffer; - - if (*sp++ == 'w' && *sp == 'v' && *++sp == 'p' && *++sp == 'k' && - !(*++sp & 1) && sp [2] < 16 && !sp [3] && sp [5] == 4 && - sp [4] >= (MIN_STREAM_VERS & 0xff) && sp [4] <= (MAX_STREAM_VERS & 0xff)) { - memcpy (wphdr, buffer, sizeof (*wphdr)); - little_endian_to_native (wphdr, WavpackHeaderFormat); - return bytes_skipped; - } - - while (sp < ep && *sp != 'w') - sp++; - - if ((bytes_skipped += sp - buffer) > 1048576L) - return -1; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wvfilter.c.no_compile b/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wvfilter.c.no_compile deleted file mode 100644 index f80d73dd0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/external/wavpack/wvfilter.c.no_compile +++ /dev/null @@ -1,200 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// **** WAVPACK **** // -// Hybrid Lossless Wavefile Compressor // -// Copyright (c) 1998 - 2006 Conifer Software. // -// All Rights Reserved. // -// Distributed under the BSD Software License (see license.txt) // -//////////////////////////////////////////////////////////////////////////// - -// wv_filter.c - -// This is the main module for the demonstration WavPack command-line -// decoder filter. It uses the tiny "hardware" version of the decoder and -// accepts WavPack files on stdin and outputs a standard MS wav file to -// stdout. Note that this involves converting the data to little-endian -// (if the executing processor is not), possibly packing the data into -// fewer bytes per sample, and generating an appropriate riff wav header. -// Note that this is NOT the copy of the RIFF header that might be stored -// in the file, and any additional RIFF information and tags are lost. -// See wputils.c for further limitations. - -#include "wavpack.h" - -#if defined(WIN32) -#include -#include -#endif - -#include - -// These structures are used to place a wav riff header at the beginning of -// the output. - -typedef struct { - char ckID [4]; - uint32_t ckSize; - char formType [4]; -} RiffChunkHeader; - -typedef struct { - char ckID [4]; - uint32_t ckSize; -} ChunkHeader; - -#define ChunkHeaderFormat "4L" - -typedef struct { - ushort FormatTag, NumChannels; - uint32_t SampleRate, BytesPerSecond; - ushort BlockAlign, BitsPerSample; -} WaveHeader; - -#define WaveHeaderFormat "SSLLSS" - -static uchar *format_samples (int bps, uchar *dst, int32_t *src, uint32_t samcnt); -static int32_t read_bytes (void *buff, int32_t bcount); -static int32_t temp_buffer [256]; - -int main () -{ - ChunkHeader FormatChunkHeader, DataChunkHeader; - RiffChunkHeader RiffChunkHeader; - WaveHeader WaveHeader; - - uint32_t total_unpacked_samples = 0, total_samples; - int num_channels, bps; - WavpackContext *wpc; - char error [80]; - -#if defined(WIN32) - setmode (fileno (stdin), O_BINARY); - setmode (fileno (stdout), O_BINARY); -#endif - - wpc = WavpackOpenFileInput (read_bytes, error); - - if (!wpc) { - fputs (error, stderr); - fputs ("\n", stderr); - return 1; - } - - num_channels = WavpackGetReducedChannels (wpc); - total_samples = WavpackGetNumSamples (wpc); - bps = WavpackGetBytesPerSample (wpc); - - strncpy (RiffChunkHeader.ckID, "RIFF", sizeof (RiffChunkHeader.ckID)); - RiffChunkHeader.ckSize = total_samples * num_channels * bps + sizeof (ChunkHeader) * 2 + sizeof (WaveHeader) + 4; - strncpy (RiffChunkHeader.formType, "WAVE", sizeof (RiffChunkHeader.formType)); - - strncpy (FormatChunkHeader.ckID, "fmt ", sizeof (FormatChunkHeader.ckID)); - FormatChunkHeader.ckSize = sizeof (WaveHeader); - - WaveHeader.FormatTag = 1; - WaveHeader.NumChannels = num_channels; - WaveHeader.SampleRate = WavpackGetSampleRate (wpc); - WaveHeader.BlockAlign = num_channels * bps; - WaveHeader.BytesPerSecond = WaveHeader.SampleRate * WaveHeader.BlockAlign; - WaveHeader.BitsPerSample = WavpackGetBitsPerSample (wpc); - - strncpy (DataChunkHeader.ckID, "data", sizeof (DataChunkHeader.ckID)); - DataChunkHeader.ckSize = total_samples * num_channels * bps; - - native_to_little_endian (&RiffChunkHeader, ChunkHeaderFormat); - native_to_little_endian (&FormatChunkHeader, ChunkHeaderFormat); - native_to_little_endian (&WaveHeader, WaveHeaderFormat); - native_to_little_endian (&DataChunkHeader, ChunkHeaderFormat); - - if (!fwrite (&RiffChunkHeader, sizeof (RiffChunkHeader), 1, stdout) || - !fwrite (&FormatChunkHeader, sizeof (FormatChunkHeader), 1, stdout) || - !fwrite (&WaveHeader, sizeof (WaveHeader), 1, stdout) || - !fwrite (&DataChunkHeader, sizeof (DataChunkHeader), 1, stdout)) { - fputs ("can't write .WAV data, disk probably full!\n", stderr); - return 1; - } - - while (1) { - uint32_t samples_unpacked; - - samples_unpacked = WavpackUnpackSamples (wpc, temp_buffer, 256 / num_channels); - total_unpacked_samples += samples_unpacked; - - if (samples_unpacked) { - format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked *= num_channels); - - if (fwrite (temp_buffer, bps, samples_unpacked, stdout) != samples_unpacked) { - fputs ("can't write .WAV data, disk probably full!\n", stderr); - return 1; - } - } - - if (!samples_unpacked) - break; - } - - fflush (stdout); - - if (WavpackGetNumSamples (wpc) != (uint32_t) -1 && - total_unpacked_samples != WavpackGetNumSamples (wpc)) { - fputs ("incorrect number of samples!\n", stderr); - return 1; - } - - if (WavpackGetNumErrors (wpc)) { - fputs ("crc errors detected!\n", stderr); - return 1; - } - - return 0; -} - -static int32_t read_bytes (void *buff, int32_t bcount) -{ - return fread (buff, 1, bcount, stdin); -} - -// Reformat samples from longs in processor's native endian mode to -// little-endian data with (possibly) less than 4 bytes / sample. - -static uchar *format_samples (int bps, uchar *dst, int32_t *src, uint32_t samcnt) -{ - int32_t temp; - - switch (bps) { - - case 1: - while (samcnt--) - *dst++ = *src++ + 128; - - break; - - case 2: - while (samcnt--) { - *dst++ = (uchar)(temp = *src++); - *dst++ = (uchar)(temp >> 8); - } - - break; - - case 3: - while (samcnt--) { - *dst++ = (uchar)(temp = *src++); - *dst++ = (uchar)(temp >> 8); - *dst++ = (uchar)(temp >> 16); - } - - break; - - case 4: - while (samcnt--) { - *dst++ = (uchar)(temp = *src++); - *dst++ = (uchar)(temp >> 8); - *dst++ = (uchar)(temp >> 16); - *dst++ = (uchar)(temp >> 24); - } - - break; - } - - return dst; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/server/es_register.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/server/es_register.cpp deleted file mode 100644 index b3ac70a6e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/server/es_register.cpp +++ /dev/null @@ -1,272 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -extern NETSERVER *net; - -enum -{ - REGISTERSTATE_START=0, - REGISTERSTATE_UPDATE_ADDRS, - REGISTERSTATE_QUERY_COUNT, - REGISTERSTATE_HEARTBEAT, - REGISTERSTATE_REGISTERED, - REGISTERSTATE_ERROR -}; - -static int register_state = REGISTERSTATE_START; -static int64 register_state_start = 0; -static int register_first = 1; -static int register_count = 0; - -static void register_new_state(int state) -{ - register_state = state; - register_state_start = time_get(); -} - -static void register_send_fwcheckresponse(NETADDR *addr) -{ - NETCHUNK packet; - packet.client_id = -1; - packet.address = *addr; - packet.flags = NETSENDFLAG_CONNLESS; - packet.data_size = sizeof(SERVERBROWSE_FWRESPONSE); - packet.data = SERVERBROWSE_FWRESPONSE; - netserver_send(net, &packet); -} - -static void register_send_heartbeat(NETADDR addr) -{ - static unsigned char data[sizeof(SERVERBROWSE_HEARTBEAT) + 2]; - unsigned short port = config.sv_port; - NETCHUNK packet; - - mem_copy(data, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT)); - - packet.client_id = -1; - packet.address = addr; - packet.flags = NETSENDFLAG_CONNLESS; - packet.data_size = sizeof(SERVERBROWSE_HEARTBEAT) + 2; - packet.data = &data; - - /* supply the set port that the master can use if it has problems */ - if(config.sv_external_port) - port = config.sv_external_port; - data[sizeof(SERVERBROWSE_HEARTBEAT)] = port >> 8; - data[sizeof(SERVERBROWSE_HEARTBEAT)+1] = port&0xff; - netserver_send(net, &packet); -} - -static void register_send_count_request(NETADDR addr) -{ - NETCHUNK packet; - packet.client_id = -1; - packet.address = addr; - packet.flags = NETSENDFLAG_CONNLESS; - packet.data_size = sizeof(SERVERBROWSE_GETCOUNT); - packet.data = SERVERBROWSE_GETCOUNT; - netserver_send(net, &packet); -} - -typedef struct -{ - NETADDR addr; - int count; - int valid; - int64 last_send; -} MASTERSERVER_INFO; - -static MASTERSERVER_INFO masterserver_info[MAX_MASTERSERVERS] = {{{0}}}; -static int register_registered_server = -1; - -void register_update() -{ - int64 now = time_get(); - int64 freq = time_freq(); - - if(!config.sv_register) - return; - - mastersrv_update(); - - if(register_state == REGISTERSTATE_START) - { - register_count = 0; - register_first = 1; - register_new_state(REGISTERSTATE_UPDATE_ADDRS); - mastersrv_refresh_addresses(); - dbg_msg("register", "refreshing ip addresses"); - } - else if(register_state == REGISTERSTATE_UPDATE_ADDRS) - { - register_registered_server = -1; - - if(!mastersrv_refreshing()) - { - int i; - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - NETADDR addr = mastersrv_get(i); - masterserver_info[i].addr = addr; - masterserver_info[i].count = 0; - - if(!addr.ip[0] && !addr.ip[1] && !addr.ip[2] && !addr.ip[3]) - masterserver_info[i].valid = 0; - else - { - masterserver_info[i].valid = 1; - masterserver_info[i].count = -1; - masterserver_info[i].last_send = 0; - } - } - - dbg_msg("register", "fetching server counts"); - register_new_state(REGISTERSTATE_QUERY_COUNT); - } - } - else if(register_state == REGISTERSTATE_QUERY_COUNT) - { - int i; - int left = 0; - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - if(!masterserver_info[i].valid) - continue; - - if(masterserver_info[i].count == -1) - { - left++; - if(masterserver_info[i].last_send+freq < now) - { - masterserver_info[i].last_send = now; - register_send_count_request(masterserver_info[i].addr); - } - } - } - - /* check if we are done or timed out */ - if(left == 0 || now > register_state_start+freq*3) - { - /* choose server */ - int best = -1; - int i; - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - if(!masterserver_info[i].valid || masterserver_info[i].count == -1) - continue; - - if(best == -1 || masterserver_info[i].count < masterserver_info[best].count) - best = i; - } - - /* server chosen */ - register_registered_server = best; - if(register_registered_server == -1) - { - dbg_msg("register", "WARNING: No master servers. Retrying in 60 seconds"); - register_new_state(REGISTERSTATE_ERROR); - } - else - { - dbg_msg("register", "choosen '%s' as master, sending heartbeats", mastersrv_name(register_registered_server)); - masterserver_info[register_registered_server].last_send = 0; - register_new_state(REGISTERSTATE_HEARTBEAT); - } - } - } - else if(register_state == REGISTERSTATE_HEARTBEAT) - { - /* check if we should send heartbeat */ - if(now > masterserver_info[register_registered_server].last_send+freq*15) - { - masterserver_info[register_registered_server].last_send = now; - register_send_heartbeat(masterserver_info[register_registered_server].addr); - } - - if(now > register_state_start+freq*60) - { - dbg_msg("register", "WARNING: Master server is not responding, switching master"); - register_new_state(REGISTERSTATE_START); - } - } - else if(register_state == REGISTERSTATE_REGISTERED) - { - if(register_first) - dbg_msg("register", "server registered"); - - register_first = 0; - - /* check if we should send new heartbeat again */ - if(now > register_state_start+freq) - { - if(register_count == 120) /* redo the whole process after 60 minutes to balance out the master servers */ - register_new_state(REGISTERSTATE_START); - else - { - register_count++; - register_new_state(REGISTERSTATE_HEARTBEAT); - } - } - } - else if(register_state == REGISTERSTATE_ERROR) - { - /* check for restart */ - if(now > register_state_start+freq*60) - register_new_state(REGISTERSTATE_START); - } -} - -static void register_got_count(NETCHUNK *p) -{ - unsigned char *data = (unsigned char *)p->data; - int count = (data[sizeof(SERVERBROWSE_COUNT)]<<8) | data[sizeof(SERVERBROWSE_COUNT)+1]; - int i; - - for(i = 0; i < MAX_MASTERSERVERS; i++) - { - if(net_addr_comp(&masterserver_info[i].addr, &p->address) == 0) - { - masterserver_info[i].count = count; - break; - } - } -} - -int register_process_packet(NETCHUNK *packet) -{ - if(packet->data_size == sizeof(SERVERBROWSE_FWCHECK) && - memcmp(packet->data, SERVERBROWSE_FWCHECK, sizeof(SERVERBROWSE_FWCHECK)) == 0) - { - register_send_fwcheckresponse(&packet->address); - return 1; - } - else if(packet->data_size == sizeof(SERVERBROWSE_FWOK) && - memcmp(packet->data, SERVERBROWSE_FWOK, sizeof(SERVERBROWSE_FWOK)) == 0) - { - if(register_first) - dbg_msg("register", "no firewall/nat problems detected"); - register_new_state(REGISTERSTATE_REGISTERED); - return 1; - } - else if(packet->data_size == sizeof(SERVERBROWSE_FWERROR) && - memcmp(packet->data, SERVERBROWSE_FWERROR, sizeof(SERVERBROWSE_FWERROR)) == 0) - { - dbg_msg("register", "ERROR: the master server reports that clients can not connect to this server."); - dbg_msg("register", "ERROR: configure your firewall/nat to let through udp on port %d.", config.sv_port); - register_new_state(REGISTERSTATE_ERROR); - return 1; - } - else if(packet->data_size == sizeof(SERVERBROWSE_COUNT)+2 && - memcmp(packet->data, SERVERBROWSE_COUNT, sizeof(SERVERBROWSE_COUNT)) == 0) - { - register_got_count(packet); - return 1; - } - - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/engine/server/es_server.cpp b/project/jni/application/teeworlds-0.5.2/src/engine/server/es_server.cpp deleted file mode 100644 index 809e492f4..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/engine/server/es_server.cpp +++ /dev/null @@ -1,1379 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#if defined(CONF_FAMILY_WINDOWS) - #define _WIN32_WINNT 0x0500 - #include -#endif - -static SNAPBUILD builder; - -static int64 game_start_time; -static int current_tick = 0; -static int run_server = 1; - -static char browseinfo_gametype[16] = {0}; -static int browseinfo_progression = -1; - -static int64 lastheartbeat; -/*static NETADDR4 master_server;*/ - -static char current_map[64]; -static int current_map_crc; -static unsigned char *current_map_data = 0; -static int current_map_size = 0; - -void *snap_new_item(int type, int id, int size) -{ - dbg_assert(type >= 0 && type <=0xffff, "incorrect type"); - dbg_assert(id >= 0 && id <=0xffff, "incorrect id"); - return snapbuild_new_item(&builder, type, id, size); -} - -typedef struct -{ - short next; - short state; /* 0 = free, 1 = alloced, 2 = timed */ - int timeout; -} SNAP_ID; - -static const int MAX_IDS = 16*1024; /* should be lowered */ -static SNAP_ID snap_ids[16*1024]; -static int snap_first_free_id; -static int snap_first_timed_id; -static int snap_last_timed_id; -static int snap_id_usage; -static int snap_id_inusage; -static int snap_id_inited = 0; - -enum -{ - SRVCLIENT_STATE_EMPTY = 0, - SRVCLIENT_STATE_AUTH, - SRVCLIENT_STATE_CONNECTING, - SRVCLIENT_STATE_READY, - SRVCLIENT_STATE_INGAME, - - SRVCLIENT_SNAPRATE_INIT=0, - SRVCLIENT_SNAPRATE_FULL, - SRVCLIENT_SNAPRATE_RECOVER -}; - -typedef struct -{ - int data[MAX_INPUT_SIZE]; - int game_tick; /* the tick that was chosen for the input */ -} CLIENT_INPUT; - -/* */ -typedef struct -{ - /* connection state info */ - int state; - int latency; - int snap_rate; - - int last_acked_snapshot; - int last_input_tick; - SNAPSTORAGE snapshots; - - CLIENT_INPUT latestinput; - CLIENT_INPUT inputs[200]; /* TODO: handle input better */ - int current_input; - - char name[MAX_NAME_LENGTH]; - char clan[MAX_CLANNAME_LENGTH]; - int score; - int authed; -} CLIENT; - -static CLIENT clients[MAX_CLIENTS]; -static NETSERVER *net; - -static void snap_init_id() -{ - int i; - if(snap_id_inited) - return; - - for(i = 0; i < MAX_IDS; i++) - { - snap_ids[i].next = i+1; - snap_ids[i].state = 0; - } - - snap_ids[MAX_IDS-1].next = -1; - snap_first_free_id = 0; - snap_first_timed_id = -1; - snap_last_timed_id = -1; - snap_id_usage = 0; - snap_id_inusage = 0; - - snap_id_inited = 1; -} - -static void snap_remove_first_timeout() -{ - int next_timed = snap_ids[snap_first_timed_id].next; - - /* add it to the free list */ - snap_ids[snap_first_timed_id].next = snap_first_free_id; - snap_ids[snap_first_timed_id].state = 0; - snap_first_free_id = snap_first_timed_id; - - /* remove it from the timed list */ - snap_first_timed_id = next_timed; - if(snap_first_timed_id == -1) - snap_last_timed_id = -1; - - snap_id_usage--; -} - -int snap_new_id() -{ - int id; - int64 now = time_get(); - if(!snap_id_inited) - snap_init_id(); - - /* process timed ids */ - while(snap_first_timed_id != -1 && snap_ids[snap_first_timed_id].timeout < now) - snap_remove_first_timeout(); - - id = snap_first_free_id; - dbg_assert(id != -1, "id error"); - snap_first_free_id = snap_ids[snap_first_free_id].next; - snap_ids[id].state = 1; - snap_id_usage++; - snap_id_inusage++; - return id; -} - -void snap_timeout_ids() -{ - /* process timed ids */ - while(snap_first_timed_id != -1) - snap_remove_first_timeout(); -} - -void snap_free_id(int id) -{ - dbg_assert(snap_ids[id].state == 1, "id is not alloced"); - - snap_id_inusage--; - snap_ids[id].state = 2; - snap_ids[id].timeout = time_get()+time_freq()*5; - snap_ids[id].next = -1; - - if(snap_last_timed_id != -1) - { - snap_ids[snap_last_timed_id].next = id; - snap_last_timed_id = id; - } - else - { - snap_first_timed_id = id; - snap_last_timed_id = id; - } -} - -int *server_latestinput(int client_id, int *size) -{ - if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) - return 0; - return clients[client_id].latestinput.data; -} - -const char *server_clientname(int client_id) -{ - if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) - return "(invalid client)"; - return clients[client_id].name; -} - -static const char *str_ltrim(const char *str) -{ - while(*str && *str <= 32) - str++; - return str; -} - -static void str_rtrim(char *str) -{ - int i = str_length(str)-1; - while(i >= 0) - { - if(i > 23 || str[i] <= 32) - str[i] = 0; - else - break; - i--; - } -} - -static int server_try_setclientname(int client_id, const char *name) -{ - int i; - char trimmed_name[64]; - - /* trim the name */ - str_copy(trimmed_name, str_ltrim(name), sizeof(trimmed_name)); - str_rtrim(trimmed_name); - dbg_msg("", "'%s' -> '%s'", name, trimmed_name); - name = trimmed_name; - - - /* check for empty names */ - if(!name[0]) - return -1; - - /* make sure that two clients doesn't have the same name */ - for(i = 0; i < MAX_CLIENTS; i++) - if(i != client_id && clients[i].state >= SRVCLIENT_STATE_READY) - { - if(strcmp(name, clients[i].name) == 0) - return -1; - } - - /* set the client name */ - str_copy(clients[client_id].name, name, MAX_NAME_LENGTH); - return 0; -} - -void server_setclientname(int client_id, const char *name) -{ - char nametry[MAX_NAME_LENGTH]; - int i; - if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) - return; - - if(!name) - return; - - str_copy(nametry, name, MAX_NAME_LENGTH); - if(server_try_setclientname(client_id, nametry)) - { - /* auto rename */ - for(i = 1;; i++) - { - str_format(nametry, MAX_NAME_LENGTH, "(%d)%s", i, name); - if(server_try_setclientname(client_id, nametry) == 0) - break; - } - } -} - -void server_setclientscore(int client_id, int score) -{ - if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) - return; - clients[client_id].score = score; -} - -void server_setbrowseinfo(const char *game_type, int progression) -{ - str_copy(browseinfo_gametype, game_type, sizeof(browseinfo_gametype)); - browseinfo_progression = progression; - if(browseinfo_progression > 100) - browseinfo_progression = 100; - if(browseinfo_progression < -1) - browseinfo_progression = -1; -} - -void server_kick(int client_id, const char *reason) -{ - if(client_id < 0 || client_id > MAX_CLIENTS) - return; - - if(clients[client_id].state != SRVCLIENT_STATE_EMPTY) - netserver_drop(net, client_id, reason); -} - -int server_tick() -{ - return current_tick; -} - -int64 server_tick_start_time(int tick) -{ - return game_start_time + (time_freq()*tick)/SERVER_TICK_SPEED; -} - -int server_tickspeed() -{ - return SERVER_TICK_SPEED; -} - -int server_init() -{ - int i; - for(i = 0; i < MAX_CLIENTS; i++) - { - clients[i].state = SRVCLIENT_STATE_EMPTY; - clients[i].name[0] = 0; - clients[i].clan[0] = 0; - snapstorage_init(&clients[i].snapshots); - } - - current_tick = 0; - - return 0; -} - -int server_getclientinfo(int client_id, CLIENT_INFO *info) -{ - dbg_assert(client_id >= 0 && client_id < MAX_CLIENTS, "client_id is not valid"); - dbg_assert(info != 0, "info can not be null"); - - if(clients[client_id].state == SRVCLIENT_STATE_INGAME) - { - info->name = clients[client_id].name; - info->latency = clients[client_id].latency; - return 1; - } - return 0; -} - -int server_send_msg(int client_id) -{ - const MSG_INFO *info = msg_get_info(); - NETCHUNK packet; - if(!info) - return -1; - - mem_zero(&packet, sizeof(NETCHUNK)); - - packet.client_id = client_id; - packet.data = info->data; - packet.data_size = info->size; - - if(info->flags&MSGFLAG_VITAL) - packet.flags |= NETSENDFLAG_VITAL; - if(info->flags&MSGFLAG_FLUSH) - packet.flags |= NETSENDFLAG_FLUSH; - - /* write message to demo recorder */ - if(!(info->flags&MSGFLAG_NORECORD)) - demorec_record_message(info->data, info->size); - - if(!(info->flags&MSGFLAG_NOSEND)) - { - if(client_id == -1) - { - /* broadcast */ - int i; - for(i = 0; i < MAX_CLIENTS; i++) - if(clients[i].state == SRVCLIENT_STATE_INGAME) - { - packet.client_id = i; - netserver_send(net, &packet); - } - } - else - netserver_send(net, &packet); - } - return 0; -} - -static void server_do_snap() -{ - int i; - - { - static PERFORMACE_INFO scope = {"presnap", 0}; - perf_start(&scope); - mods_presnap(); - perf_end(); - } - - /* create snapshot for demo recording */ - if(demorec_isrecording()) - { - char data[MAX_SNAPSHOT_SIZE]; - int snapshot_size; - - /* build snap and possibly add some messages */ - snapbuild_init(&builder); - mods_snap(-1); - snapshot_size = snapbuild_finish(&builder, data); - - /* write snapshot */ - demorec_record_snapshot(server_tick(), data, snapshot_size); - } - - /* create snapshots for all clients */ - for(i = 0; i < MAX_CLIENTS; i++) - { - /* client must be ingame to recive snapshots */ - if(clients[i].state != SRVCLIENT_STATE_INGAME) - continue; - - /* this client is trying to recover, don't spam snapshots */ - if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_RECOVER && (server_tick()%50) != 0) - continue; - - /* this client is trying to recover, don't spam snapshots */ - if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_INIT && (server_tick()%10) != 0) - continue; - - { - char data[MAX_SNAPSHOT_SIZE]; - char deltadata[MAX_SNAPSHOT_SIZE]; - char compdata[MAX_SNAPSHOT_SIZE]; - int snapshot_size; - int crc; - static SNAPSHOT emptysnap; - SNAPSHOT *deltashot = &emptysnap; - int deltashot_size; - int delta_tick = -1; - int deltasize; - static PERFORMACE_INFO scope = {"build", 0}; - perf_start(&scope); - - snapbuild_init(&builder); - - { - static PERFORMACE_INFO scope = {"modsnap", 0}; - perf_start(&scope); - mods_snap(i); - perf_end(); - } - - /* finish snapshot */ - snapshot_size = snapbuild_finish(&builder, data); - crc = snapshot_crc((SNAPSHOT*)data); - - /* remove old snapshos */ - /* keep 3 seconds worth of snapshots */ - snapstorage_purge_until(&clients[i].snapshots, current_tick-SERVER_TICK_SPEED*3); - - /* save it the snapshot */ - snapstorage_add(&clients[i].snapshots, current_tick, time_get(), snapshot_size, data, 0); - - /* find snapshot that we can preform delta against */ - emptysnap.data_size = 0; - emptysnap.num_items = 0; - - { - deltashot_size = snapstorage_get(&clients[i].snapshots, clients[i].last_acked_snapshot, 0, &deltashot, 0); - if(deltashot_size >= 0) - delta_tick = clients[i].last_acked_snapshot; - else - { - /* no acked package found, force client to recover rate */ - if(clients[i].snap_rate == SRVCLIENT_SNAPRATE_FULL) - clients[i].snap_rate = SRVCLIENT_SNAPRATE_RECOVER; - } - } - - /* create delta */ - { - static PERFORMACE_INFO scope = {"delta", 0}; - perf_start(&scope); - deltasize = snapshot_create_delta(deltashot, (SNAPSHOT*)data, deltadata); - perf_end(); - } - - - if(deltasize) - { - /* compress it */ - int snapshot_size; - const int max_size = MAX_SNAPSHOT_PACKSIZE; - int numpackets; - int n, left; - - { - static PERFORMACE_INFO scope = {"compress", 0}; - /*char buffer[512];*/ - perf_start(&scope); - snapshot_size = intpack_compress(deltadata, deltasize, compdata); - - /*str_hex(buffer, sizeof(buffer), compdata, snapshot_size); - dbg_msg("", "deltasize=%d -> %d : %s", deltasize, snapshot_size, buffer);*/ - - perf_end(); - } - - numpackets = (snapshot_size+max_size-1)/max_size; - - for(n = 0, left = snapshot_size; left; n++) - { - int chunk = left < max_size ? left : max_size; - left -= chunk; - - if(numpackets == 1) - msg_pack_start_system(NETMSG_SNAPSINGLE, MSGFLAG_FLUSH); - else - msg_pack_start_system(NETMSG_SNAP, MSGFLAG_FLUSH); - - msg_pack_int(current_tick); - msg_pack_int(current_tick-delta_tick); /* compressed with */ - - if(numpackets != 1) - { - msg_pack_int(numpackets); - msg_pack_int(n); - } - - msg_pack_int(crc); - msg_pack_int(chunk); - msg_pack_raw(&compdata[n*max_size], chunk); - msg_pack_end(); - server_send_msg(i); - } - } - else - { - msg_pack_start_system(NETMSG_SNAPEMPTY, MSGFLAG_FLUSH); - msg_pack_int(current_tick); - msg_pack_int(current_tick-delta_tick); /* compressed with */ - msg_pack_end(); - server_send_msg(i); - } - - perf_end(); - } - } - - mods_postsnap(); -} - - -static void reset_client(int cid) -{ - /* reset input */ - int i; - for(i = 0; i < 200; i++) - clients[cid].inputs[i].game_tick = -1; - clients[cid].current_input = 0; - mem_zero(&clients[cid].latestinput, sizeof(clients[cid].latestinput)); - - snapstorage_purge_all(&clients[cid].snapshots); - clients[cid].last_acked_snapshot = -1; - clients[cid].last_input_tick = -1; - clients[cid].snap_rate = SRVCLIENT_SNAPRATE_INIT; - clients[cid].score = 0; - -} - -static int new_client_callback(int cid, void *user) -{ - clients[cid].state = SRVCLIENT_STATE_AUTH; - clients[cid].name[0] = 0; - clients[cid].clan[0] = 0; - clients[cid].authed = 0; - reset_client(cid); - return 0; -} - -static int del_client_callback(int cid, void *user) -{ - /* notify the mod about the drop */ - if(clients[cid].state >= SRVCLIENT_STATE_READY) - mods_client_drop(cid); - - clients[cid].state = SRVCLIENT_STATE_EMPTY; - clients[cid].name[0] = 0; - clients[cid].clan[0] = 0; - clients[cid].authed = 0; - snapstorage_purge_all(&clients[cid].snapshots); - return 0; -} - -static void server_send_map(int cid) -{ - msg_pack_start_system(NETMSG_MAP_CHANGE, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_string(config.sv_map, 0); - msg_pack_int(current_map_crc); - msg_pack_end(); - server_send_msg(cid); -} - -static void server_send_rcon_line(int cid, const char *line) -{ - msg_pack_start_system(NETMSG_RCON_LINE, MSGFLAG_VITAL); - msg_pack_string(line, 512); - msg_pack_end(); - server_send_msg(cid); -} - -static void server_send_rcon_line_authed(const char *line, void *user_data) -{ - static volatile int reentry_guard = 0; - int i; - - if(reentry_guard) return; - reentry_guard++; - - for(i = 0; i < MAX_CLIENTS; i++) - { - if(clients[i].state != SRVCLIENT_STATE_EMPTY && clients[i].authed) - server_send_rcon_line(i, line); - } - - reentry_guard--; -} - -static void server_process_client_packet(NETCHUNK *packet) -{ - int cid = packet->client_id; - NETADDR addr; - - int sys; - int msg = msg_unpack_start(packet->data, packet->data_size, &sys); - - if(clients[cid].state == SRVCLIENT_STATE_AUTH) - { - if(sys && msg == NETMSG_INFO) - { - char version[64]; - const char *password; - str_copy(version, msg_unpack_string(), 64); - if(strcmp(version, mods_net_version()) != 0) - { - /* OH FUCK! wrong version, drop him */ - char reason[256]; - str_format(reason, sizeof(reason), "wrong version. server is running '%s' and client '%s'.", mods_net_version(), version); - netserver_drop(net, cid, reason); - return; - } - - str_copy(clients[cid].name, msg_unpack_string(), MAX_NAME_LENGTH); - str_copy(clients[cid].clan, msg_unpack_string(), MAX_CLANNAME_LENGTH); - password = msg_unpack_string(); - - if(config.password[0] != 0 && strcmp(config.password, password) != 0) - { - /* wrong password */ - netserver_drop(net, cid, "wrong password"); - return; - } - - clients[cid].state = SRVCLIENT_STATE_CONNECTING; - server_send_map(cid); - } - } - else - { - if(sys) - { - /* system message */ - if(msg == NETMSG_REQUEST_MAP_DATA) - { - int chunk = msg_unpack_int(); - int chunk_size = 1024-128; - int offset = chunk * chunk_size; - int last = 0; - - /* drop faulty map data requests */ - if(chunk < 0 || offset > current_map_size) - return; - - if(offset+chunk_size >= current_map_size) - { - chunk_size = current_map_size-offset; - if(chunk_size < 0) - chunk_size = 0; - last = 1; - } - - msg_pack_start_system(NETMSG_MAP_DATA, MSGFLAG_VITAL|MSGFLAG_FLUSH); - msg_pack_int(last); - msg_pack_int(current_map_size); - msg_pack_int(chunk_size); - msg_pack_raw(¤t_map_data[offset], chunk_size); - msg_pack_end(); - server_send_msg(cid); - - if(config.debug) - dbg_msg("server", "sending chunk %d with size %d", chunk, chunk_size); - } - else if(msg == NETMSG_READY) - { - if(clients[cid].state == SRVCLIENT_STATE_CONNECTING) - { - netserver_client_addr(net, cid, &addr); - - dbg_msg("server", "player is ready. cid=%x ip=%d.%d.%d.%d", - cid, - addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3] - ); - clients[cid].state = SRVCLIENT_STATE_READY; - mods_connected(cid); - } - } - else if(msg == NETMSG_ENTERGAME) - { - if(clients[cid].state == SRVCLIENT_STATE_READY) - { - netserver_client_addr(net, cid, &addr); - - dbg_msg("server", "player has entered the game. cid=%x ip=%d.%d.%d.%d", - cid, - addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3] - ); - clients[cid].state = SRVCLIENT_STATE_INGAME; - mods_client_enter(cid); - } - } - else if(msg == NETMSG_INPUT) - { - int tick, size, i; - CLIENT_INPUT *input; - int64 tagtime; - - clients[cid].last_acked_snapshot = msg_unpack_int(); - tick = msg_unpack_int(); - size = msg_unpack_int(); - - /* check for errors */ - if(msg_unpack_error() || size/4 > MAX_INPUT_SIZE) - return; - - if(clients[cid].last_acked_snapshot > 0) - clients[cid].snap_rate = SRVCLIENT_SNAPRATE_FULL; - - if(snapstorage_get(&clients[cid].snapshots, clients[cid].last_acked_snapshot, &tagtime, 0, 0) >= 0) - clients[cid].latency = (int)(((time_get()-tagtime)*1000)/time_freq()); - - /* add message to report the input timing */ - /* skip packets that are old */ - if(tick > clients[cid].last_input_tick) - { - int time_left = ((server_tick_start_time(tick)-time_get())*1000) / time_freq(); - msg_pack_start_system(NETMSG_INPUTTIMING, 0); - msg_pack_int(tick); - msg_pack_int(time_left); - msg_pack_end(); - server_send_msg(cid); - } - - clients[cid].last_input_tick = tick; - - input = &clients[cid].inputs[clients[cid].current_input]; - - if(tick <= server_tick()) - tick = server_tick()+1; - - input->game_tick = tick; - - for(i = 0; i < size/4; i++) - input->data[i] = msg_unpack_int(); - - mem_copy(clients[cid].latestinput.data, input->data, MAX_INPUT_SIZE*sizeof(int)); - - clients[cid].current_input++; - clients[cid].current_input %= 200; - - /* call the mod with the fresh input data */ - if(clients[cid].state == SRVCLIENT_STATE_INGAME) - mods_client_direct_input(cid, clients[cid].latestinput.data); - } - else if(msg == NETMSG_RCON_CMD) - { - const char *cmd = msg_unpack_string(); - - if(msg_unpack_error() == 0 && clients[cid].authed) - { - dbg_msg("server", "cid=%d rcon='%s'", cid, cmd); - console_execute_line(cmd); - } - } - else if(msg == NETMSG_RCON_AUTH) - { - const char *pw; - msg_unpack_string(); /* login name, not used */ - pw = msg_unpack_string(); - - if(msg_unpack_error() == 0) - { - if(config.sv_rcon_password[0] == 0) - { - server_send_rcon_line(cid, "No rcon password set on server. Set sv_rcon_password to enable the remote console."); - } - else if(strcmp(pw, config.sv_rcon_password) == 0) - { - msg_pack_start_system(NETMSG_RCON_AUTH_STATUS, MSGFLAG_VITAL); - msg_pack_int(1); - msg_pack_end(); - server_send_msg(cid); - - clients[cid].authed = 1; - server_send_rcon_line(cid, "Authentication successful. Remote console access granted."); - dbg_msg("server", "cid=%d authed", cid); - } - else - { - server_send_rcon_line(cid, "Wrong password."); - } - } - } - else if(msg == NETMSG_PING) - { - msg_pack_start_system(NETMSG_PING_REPLY, 0); - msg_pack_end(); - server_send_msg(cid); - } - else - { - char hex[] = "0123456789ABCDEF"; - char buf[512]; - int b; - - for(b = 0; b < packet->data_size && b < 32; b++) - { - buf[b*3] = hex[((const unsigned char *)packet->data)[b]>>4]; - buf[b*3+1] = hex[((const unsigned char *)packet->data)[b]&0xf]; - buf[b*3+2] = ' '; - buf[b*3+3] = 0; - } - - dbg_msg("server", "strange message cid=%d msg=%d data_size=%d", cid, msg, packet->data_size); - dbg_msg("server", "%s", buf); - - } - } - else - { - /* game message */ - if(clients[cid].state >= SRVCLIENT_STATE_READY) - mods_message(msg, cid); - } - } -} - - -int server_ban_add(NETADDR addr, int seconds) -{ - return netserver_ban_add(net, addr, seconds); -} - -int server_ban_remove(NETADDR addr) -{ - return netserver_ban_remove(net, addr); -} - -static void server_send_serverinfo(NETADDR *addr, int token) -{ - NETCHUNK packet; - PACKER p; - char buf[128]; - - /* count the players */ - int player_count = 0; - int i; - for(i = 0; i < MAX_CLIENTS; i++) - { - if(clients[i].state != SRVCLIENT_STATE_EMPTY) - player_count++; - } - - packer_reset(&p); - - if(token >= 0) - { - /* new token based format */ - packer_add_raw(&p, SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO)); - str_format(buf, sizeof(buf), "%d", token); - packer_add_string(&p, buf, 6); - } - else - { - /* old format */ - packer_add_raw(&p, SERVERBROWSE_OLD_INFO, sizeof(SERVERBROWSE_OLD_INFO)); - } - - packer_add_string(&p, mods_version(), 32); - packer_add_string(&p, config.sv_name, 64); - packer_add_string(&p, config.sv_map, 32); - - /* gametype */ - packer_add_string(&p, browseinfo_gametype, 16); - - /* flags */ - i = 0; - if(config.password[0]) /* password set */ - i |= SRVFLAG_PASSWORD; - str_format(buf, sizeof(buf), "%d", i); - packer_add_string(&p, buf, 2); - - /* progression */ - str_format(buf, sizeof(buf), "%d", browseinfo_progression); - packer_add_string(&p, buf, 4); - - str_format(buf, sizeof(buf), "%d", player_count); packer_add_string(&p, buf, 3); /* num players */ - str_format(buf, sizeof(buf), "%d", netserver_max_clients(net)); packer_add_string(&p, buf, 3); /* max players */ - - for(i = 0; i < MAX_CLIENTS; i++) - { - if(clients[i].state != SRVCLIENT_STATE_EMPTY) - { - packer_add_string(&p, clients[i].name, 48); /* player name */ - str_format(buf, sizeof(buf), "%d", clients[i].score); packer_add_string(&p, buf, 6); /* player score */ - } - } - - - packet.client_id = -1; - packet.address = *addr; - packet.flags = NETSENDFLAG_CONNLESS; - packet.data_size = packer_size(&p); - packet.data = packer_data(&p); - netserver_send(net, &packet); -} - -extern int register_process_packet(NETCHUNK *packet); -extern int register_update(); - -static void server_pump_network() -{ - NETCHUNK packet; - - netserver_update(net); - - /* process packets */ - while(netserver_recv(net, &packet)) - { - if(packet.client_id == -1) - { - /* stateless */ - if(!register_process_packet(&packet)) - { - if(packet.data_size == sizeof(SERVERBROWSE_GETINFO)+1 && - memcmp(packet.data, SERVERBROWSE_GETINFO, sizeof(SERVERBROWSE_GETINFO)) == 0) - { - server_send_serverinfo(&packet.address, ((unsigned char *)packet.data)[sizeof(SERVERBROWSE_GETINFO)]); - } - - - if(packet.data_size == sizeof(SERVERBROWSE_OLD_GETINFO) && - memcmp(packet.data, SERVERBROWSE_OLD_GETINFO, sizeof(SERVERBROWSE_OLD_GETINFO)) == 0) - { - server_send_serverinfo(&packet.address, -1); - } - } - } - else - server_process_client_packet(&packet); - } -} - -static int server_load_map(const char *mapname) -{ - DATAFILE *df; - char buf[512]; - str_format(buf, sizeof(buf), "maps/%s.map", mapname); - df = datafile_load(buf); - if(!df) - return 0; - - /* reinit snapshot ids */ - snap_timeout_ids(); - - /* get the crc of the map */ - current_map_crc = datafile_crc(buf); - dbg_msg("server", "%s crc is %08x", buf, current_map_crc); - - str_copy(current_map, mapname, sizeof(current_map)); - map_set(df); - - /* load compelate map into memory for download */ - { - IOHANDLE file = engine_openfile(buf, IOFLAG_READ); - current_map_size = (int)io_length(file); - if(current_map_data) - mem_free(current_map_data); - current_map_data = (unsigned char *)mem_alloc(current_map_size, 1); - io_read(file, current_map_data, current_map_size); - io_close(file); - } - return 1; -} - -static int server_run() -{ - NETADDR bindaddr; - - snap_init_id(); - net_init(); - - /* */ - console_register_print_callback(server_send_rcon_line_authed, 0); - - /* load map */ - if(!server_load_map(config.sv_map)) - { - dbg_msg("server", "failed to load map. mapname='%s'", config.sv_map); - return -1; - } - - /* start server */ - /* TODO: IPv6 support */ - if(config.sv_bindaddr[0] && net_host_lookup(config.sv_bindaddr, &bindaddr, NETTYPE_IPV4) == 0) - { - /* sweet! */ - bindaddr.port = config.sv_port; - } - else - { - mem_zero(&bindaddr, sizeof(bindaddr)); - bindaddr.port = config.sv_port; - } - - net = netserver_open(bindaddr, config.sv_max_clients, 0); - if(!net) - { - dbg_msg("server", "couldn't open socket. port might already be in use"); - return -1; - } - - netserver_set_callbacks(net, new_client_callback, del_client_callback, 0); - - dbg_msg("server", "server name is '%s'", config.sv_name); - - mods_init(); - dbg_msg("server", "version %s", mods_net_version()); - - /* start game */ - { - int64 reporttime = time_get(); - int reportinterval = 3; - - lastheartbeat = 0; - game_start_time = time_get(); - - if(config.debug) - dbg_msg("server", "baseline memory usage %dk", mem_stats()->allocated/1024); - - while(run_server) - { - static PERFORMACE_INFO rootscope = {"root", 0}; - int64 t = time_get(); - int new_ticks = 0; - - perf_start(&rootscope); - - /* load new map TODO: don't poll this */ - if(strcmp(config.sv_map, current_map) != 0 || config.sv_map_reload) - { - config.sv_map_reload = 0; - - /* load map */ - if(server_load_map(config.sv_map)) - { - int c; - - /* new map loaded */ - mods_shutdown(); - - for(c = 0; c < MAX_CLIENTS; c++) - { - if(clients[c].state == SRVCLIENT_STATE_EMPTY) - continue; - - server_send_map(c); - reset_client(c); - clients[c].state = SRVCLIENT_STATE_CONNECTING; - } - - game_start_time = time_get(); - current_tick = 0; - mods_init(); - } - else - { - dbg_msg("server", "failed to load map. mapname='%s'", config.sv_map); - config_set_sv_map(&config, current_map); - } - } - - while(t > server_tick_start_time(current_tick+1)) - { - current_tick++; - new_ticks++; - - /* apply new input */ - { - static PERFORMACE_INFO scope = {"input", 0}; - int c, i; - - perf_start(&scope); - - for(c = 0; c < MAX_CLIENTS; c++) - { - if(clients[c].state == SRVCLIENT_STATE_EMPTY) - continue; - for(i = 0; i < 200; i++) - { - if(clients[c].inputs[i].game_tick == server_tick()) - { - if(clients[c].state == SRVCLIENT_STATE_INGAME) - mods_client_predicted_input(c, clients[c].inputs[i].data); - break; - } - } - } - - perf_end(); - } - - /* progress game */ - { - static PERFORMACE_INFO scope = {"tick", 0}; - perf_start(&scope); - mods_tick(); - perf_end(); - } - } - - /* snap game */ - if(new_ticks) - { - if(config.sv_high_bandwidth || (current_tick%2) == 0) - { - static PERFORMACE_INFO scope = {"snap", 0}; - perf_start(&scope); - server_do_snap(); - perf_end(); - } - } - - /* master server stuff */ - register_update(); - - - { - static PERFORMACE_INFO scope = {"net", 0}; - perf_start(&scope); - server_pump_network(); - perf_end(); - } - - perf_end(); - - if(reporttime < time_get()) - { - if(config.debug) - { - /* - static NETSTATS prev_stats; - NETSTATS stats; - netserver_stats(net, &stats); - - perf_next(); - - if(config.dbg_pref) - perf_dump(&rootscope); - - dbg_msg("server", "send=%8d recv=%8d", - (stats.send_bytes - prev_stats.send_bytes)/reportinterval, - (stats.recv_bytes - prev_stats.recv_bytes)/reportinterval); - - prev_stats = stats; - */ - } - - reporttime += time_freq()*reportinterval; - } - - /* wait for incomming data */ - net_socket_read_wait(netserver_socket(net), 5); - } - } - - mods_shutdown(); - map_unload(); - - if(current_map_data) - mem_free(current_map_data); - return 0; -} - -static void con_kick(void *result, void *user_data) -{ - server_kick(console_arg_int(result, 0), "kicked by console"); -} - -static int str_allnum(const char *str) -{ - while(*str) - { - if(!(*str >= '0' && *str <= '9')) - return 0; - str++; - } - return 1; -} - -static void con_ban(void *result, void *user_data) -{ - NETADDR addr; - char addrstr[128]; - const char *str = console_arg_string(result, 0); - int minutes = 30; - - if(console_arg_num(result) > 1) - minutes = console_arg_int(result, 1); - - if(net_addr_from_str(&addr, str) == 0) - server_ban_add(addr, minutes*60); - else if(str_allnum(str)) - { - NETADDR addr; - int cid = atoi(str); - - if(cid < 0 || cid > MAX_CLIENTS || clients[cid].state == SRVCLIENT_STATE_EMPTY) - { - dbg_msg("server", "invalid client id"); - return; - } - - netserver_client_addr(net, cid, &addr); - server_ban_add(addr, minutes*60); - } - - addr.port = 0; - net_addr_str(&addr, addrstr, sizeof(addrstr)); - - if(minutes) - dbg_msg("server", "banned %s for %d minutes", addrstr, minutes); - else - dbg_msg("server", "banned %s for life", addrstr); -} - -static void con_unban(void *result, void *user_data) -{ - NETADDR addr; - const char *str = console_arg_string(result, 0); - - if(net_addr_from_str(&addr, str) == 0) - server_ban_remove(addr); - else - dbg_msg("server", "invalid network address"); -} - -static void con_bans(void *result, void *user_data) -{ - int i; - unsigned now = time_timestamp(); - NETBANINFO info; - NETADDR addr; - int num = netserver_ban_num(net); - for(i = 0; i < num; i++) - { - unsigned t; - netserver_ban_get(net, i, &info); - addr = info.addr; - - if(info.expires == 0xffffffff) - { - dbg_msg("server", "#%d %d.%d.%d.%d for life", i, addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3]); - } - else - { - t = info.expires - now; - dbg_msg("server", "#%d %d.%d.%d.%d for %d minutes and %d seconds", i, addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3], t/60, t%60); - } - } - dbg_msg("server", "%d ban(s)", num); -} - -static void con_status(void *result, void *user_data) -{ - int i; - NETADDR addr; - for(i = 0; i < MAX_CLIENTS; i++) - { - if(clients[i].state == SRVCLIENT_STATE_INGAME) - { - netserver_client_addr(net, i, &addr); - dbg_msg("server", "id=%d addr=%d.%d.%d.%d:%d name='%s' score=%d", - i, addr.ip[0], addr.ip[1], addr.ip[2], addr.ip[3], addr.port, - clients[i].name, clients[i].score); - } - } -} - -static void con_shutdown(void *result, void *user_data) -{ - run_server = 0; -} - -static void con_record(void *result, void *user_data) -{ - char filename[512]; - str_format(filename, sizeof(filename), "demos/%s.demo", console_arg_string(result, 0)); - demorec_record_start(filename, mods_net_version(), current_map, current_map_crc, "server"); -} - -static void con_stoprecord(void *result, void *user_data) -{ - demorec_record_stop(); -} - -static void server_register_commands() -{ - MACRO_REGISTER_COMMAND("kick", "i", CFGFLAG_SERVER, con_kick, 0, ""); - MACRO_REGISTER_COMMAND("ban", "s?i", CFGFLAG_SERVER, con_ban, 0, ""); - MACRO_REGISTER_COMMAND("unban", "s", CFGFLAG_SERVER, con_unban, 0, ""); - MACRO_REGISTER_COMMAND("bans", "", CFGFLAG_SERVER, con_bans, 0, ""); - MACRO_REGISTER_COMMAND("status", "", CFGFLAG_SERVER, con_status, 0, ""); - MACRO_REGISTER_COMMAND("shutdown", "", CFGFLAG_SERVER, con_shutdown, 0, ""); - - MACRO_REGISTER_COMMAND("record", "s", CFGFLAG_SERVER, con_record, 0, ""); - MACRO_REGISTER_COMMAND("stoprecord", "", CFGFLAG_SERVER, con_stoprecord, 0, ""); -} - -#if 0 -int main(int argc, char **argv) -{ -#if defined(CONF_FAMILY_WINDOWS) - int i; - for(i = 1; i < argc; i++) - { - if(strcmp("-s", argv[i]) == 0 || strcmp("--silent", argv[i]) == 0) - { - ShowWindow(GetConsoleWindow(), SW_HIDE); - break; - } - } -#endif - - /* init the engine */ - dbg_msg("server", "starting..."); - engine_init("Teeworlds"); - - /* register all console commands */ - server_register_commands(); - mods_console_init(); - - /* parse the command line arguments */ - engine_parse_arguments(argc, argv); - - /* run the server */ - server_run(); - return 0; -} -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.cpp deleted file mode 100644 index d8c20decd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.cpp +++ /dev/null @@ -1,95 +0,0 @@ - -#include -#include -#include -#include - -#include "animstate.hpp" - -static void anim_seq_eval(ANIM_SEQUENCE *seq, float time, ANIM_KEYFRAME *frame) -{ - if(seq->num_frames == 0) - { - frame->time = 0; - frame->x = 0; - frame->y = 0; - frame->angle = 0; - } - else if(seq->num_frames == 1) - { - *frame = seq->frames[0]; - } - else - { - //time = max(0.0f, min(1.0f, time / duration)); // TODO: use clamp - ANIM_KEYFRAME *frame1 = 0; - ANIM_KEYFRAME *frame2 = 0; - float blend = 0.0f; - - // TODO: make this smarter.. binary search - for (int i = 1; i < seq->num_frames; i++) - { - if (seq->frames[i-1].time <= time && seq->frames[i].time >= time) - { - frame1 = &seq->frames[i-1]; - frame2 = &seq->frames[i]; - blend = (time - frame1->time) / (frame2->time - frame1->time); - break; - } - } - - if (frame1 && frame2) - { - frame->time = time; - frame->x = mix(frame1->x, frame2->x, blend); - frame->y = mix(frame1->y, frame2->y, blend); - frame->angle = mix(frame1->angle, frame2->angle, blend); - } - } -} - -static void anim_add_keyframe(ANIM_KEYFRAME *seq, ANIM_KEYFRAME *added, float amount) -{ - seq->x += added->x*amount; - seq->y += added->y*amount; - seq->angle += added->angle*amount; -} - -static void anim_add(ANIMSTATE *state, ANIMSTATE *added, float amount) -{ - anim_add_keyframe(&state->body, &added->body, amount); - anim_add_keyframe(&state->back_foot, &added->back_foot, amount); - anim_add_keyframe(&state->front_foot, &added->front_foot, amount); - anim_add_keyframe(&state->attach, &added->attach, amount); -} - - -void ANIMSTATE::set(ANIMATION *anim, float time) -{ - anim_seq_eval(&anim->body, time, &body); - anim_seq_eval(&anim->back_foot, time, &back_foot); - anim_seq_eval(&anim->front_foot, time, &front_foot); - anim_seq_eval(&anim->attach, time, &attach); -} - -void ANIMSTATE::add(ANIMATION *anim, float time, float amount) -{ - ANIMSTATE add; - add.set(anim, time); - anim_add(this, &add, amount); -} - -ANIMSTATE *ANIMSTATE::get_idle() -{ - static ANIMSTATE state; - static bool init = true; - - if(init) - { - state.set(&data->animations[ANIM_BASE], 0); - state.add(&data->animations[ANIM_IDLE], 0, 1.0f); - init = false; - } - - return &state; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.hpp deleted file mode 100644 index 4b84dd66c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/animstate.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef GAME_CLIENT_ANIMATION_H -#define GAME_CLIENT_ANIMATION_H - -class ANIMSTATE -{ -public: - ANIM_KEYFRAME body; - ANIM_KEYFRAME back_foot; - ANIM_KEYFRAME front_foot; - ANIM_KEYFRAME attach; - - void set(ANIMATION *anim, float time); - void add(ANIMATION *added, float time, float amount); - - static ANIMSTATE *get_idle(); -}; - -//void anim_seq_eval(ANIM_SEQUENCE *seq, float time, ANIM_KEYFRAME *frame); -//void anim_eval(ANIMATION *anim, float time, ANIM_STATE *state); -//void anim_add_keyframe(ANIM_KEYFRAME *seq, ANIM_KEYFRAME *added, float amount); -//void anim_add(ANIM_STATE *state, ANIM_STATE *added, float amount); -//void anim_eval_add(ANIM_STATE *state, ANIMATION *anim, float time, float amount); - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/clienthooks.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/clienthooks.cpp deleted file mode 100644 index 88a7722a6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/clienthooks.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -#include "gameclient.hpp" -#include "components/console.hpp" - - - - -// clean hooks -extern "C" void modc_entergame() {} -extern "C" void modc_shutdown() {} -extern "C" void modc_console_init() { gameclient.on_console_init(); } -extern "C" void modc_save_config() { gameclient.on_save(); } -extern "C" void modc_init() { gameclient.on_init(); } -extern "C" void modc_connected() { gameclient.on_connected(); } -extern "C" void modc_predict() { gameclient.on_predict(); } -extern "C" void modc_newsnapshot() { gameclient.on_snapshot(); } -extern "C" int modc_snap_input(int *data) { return gameclient.on_snapinput(data); } -extern "C" void modc_statechange(int state, int old) { gameclient.on_statechange(state, old); } -extern "C" void modc_render() { gameclient.on_render(); } -extern "C" void modc_message(int msgtype) { gameclient.on_message(msgtype); } -extern "C" void modc_rcon_line(const char *line) { gameclient.console->print_line(1, line); } - -extern "C" const char *modc_net_version() { return GAME_NETVERSION; } -extern "C" const char *modc_getitemname(int type) { return netobj_get_name(type); } - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/component.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/component.hpp deleted file mode 100644 index 3d5edb86d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/component.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GAME_CLIENT_GAMESYSTEM_H -#define GAME_CLIENT_GAMESYSTEM_H - -#include - -class GAMECLIENT; - -class COMPONENT -{ -protected: - GAMECLIENT *client; -public: - virtual ~COMPONENT() {} - - virtual void on_statechange(int new_state, int old_state) {}; - virtual void on_console_init() {}; - virtual void on_init() {}; - virtual void on_save() {}; - virtual void on_reset() {}; - virtual void on_render() {}; - virtual void on_mapload() {}; - virtual void on_message(int msg, void *rawmsg) {} - virtual bool on_mousemove(float x, float y) { return false; } - virtual bool on_input(INPUT_EVENT e) { return false; } -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.cpp deleted file mode 100644 index 7ab5ba407..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.cpp +++ /dev/null @@ -1,241 +0,0 @@ -#include // atoi -#include // strcmp -#include -#include "binds.hpp" - -bool BINDS::BINDS_SPECIAL::on_input(INPUT_EVENT e) -{ - // don't handle invalid events and keys that arn't set to anything - if(e.key >= KEY_F1 && e.key <= KEY_F15 && binds->keybindings[e.key][0] != 0) - { - int stroke = 0; - if(e.flags&INPFLAG_PRESS) - stroke = 1; - console_execute_line_stroked(stroke, binds->keybindings[e.key]); - return true; - } - - return false; -} - -BINDS::BINDS() -{ - mem_zero(keybindings, sizeof(keybindings)); - special_binds.binds = this; -} - -void BINDS::bind(int keyid, const char *str) -{ - if(keyid < 0 || keyid >= KEY_LAST) - return; - - str_copy(keybindings[keyid], str, sizeof(keybindings[keyid])); - if(!keybindings[keyid][0]) - dbg_msg("binds", "unbound %s (%d)", inp_key_name(keyid), keyid); - else - dbg_msg("binds", "bound %s (%d) = %s", inp_key_name(keyid), keyid, keybindings[keyid]); -} - - -bool BINDS::on_input(INPUT_EVENT e) -{ - // don't handle invalid events and keys that arn't set to anything - if(e.key <= 0 || e.key >= KEY_LAST || keybindings[e.key][0] == 0) - return false; - - int stroke = 0; - if(e.flags&INPFLAG_PRESS) - stroke = 1; - console_execute_line_stroked(stroke, keybindings[e.key]); - return true; -} - -void BINDS::unbindall() -{ - for(int i = 0; i < KEY_LAST; i++) - keybindings[i][0] = 0; -} - -const char *BINDS::get(int keyid) -{ - if(keyid > 0 && keyid < KEY_LAST) - return keybindings[keyid]; - return ""; -} - -const char *BINDS::get_key(const char *bindstr) -{ - for(int keyid = 0; keyid < KEY_LAST; keyid++) - { - const char *bind = get(keyid); - if(!bind[0]) - continue; - - if(strcmp(bind, bindstr) == 0) - return inp_key_name(keyid); - } - - return ""; -} - -void BINDS::set_defaults() -{ - // set default key bindings - unbindall(); - -#ifdef ANDROID - - bind(KEY_MOUSE_1, "+fire"); - bind(KEY_LEFT, "+left"); - bind(KEY_RIGHT, "+right"); - bind(KEY_UP, "+jump"); - bind(KEY_DOWN, "+hook"); - bind(KEY_RETURN, "+jump"); - bind(KEY_SPACE, "+hook"); - bind(KEY_MOUSE_2, "+hook"); - bind(KEY_LSHIFT, "+nextweapon"); - bind(KEY_RSHIFT, "+prevweapon"); - -#else - - bind(KEY_F1, "toggle_local_console"); - bind(KEY_F2, "toggle_remote_console"); - bind(KEY_TAB, "+scoreboard"); - bind(KEY_F10, "screenshot"); - - bind('a', "+left"); - bind('d', "+right"); - - bind(KEY_SPACE, "+jump"); - bind(KEY_MOUSE_1, "+fire"); - bind(KEY_MOUSE_2, "+hook"); - bind(KEY_LSHIFT, "+emote"); - - bind('1', "+weapon1"); - bind('2', "+weapon2"); - bind('3', "+weapon3"); - bind('4', "+weapon4"); - bind('5', "+weapon5"); - - bind(KEY_MOUSE_WHEEL_UP, "+prevweapon"); - bind(KEY_MOUSE_WHEEL_DOWN, "+nextweapon"); - - bind('t', "chat all"); - bind('y', "chat team"); - - bind(KEY_F3, "vote yes"); - bind(KEY_F4, "vote no"); - -#endif - -} - -void BINDS::on_console_init() -{ - // bindings - MACRO_REGISTER_COMMAND("bind", "sr", CFGFLAG_CLIENT, con_bind, this, "Bind key to execute the command"); - MACRO_REGISTER_COMMAND("unbind", "s", CFGFLAG_CLIENT, con_unbind, this, "Unbind key"); - MACRO_REGISTER_COMMAND("unbindall", "", CFGFLAG_CLIENT, con_unbindall, this, "Unbind all keys"); - MACRO_REGISTER_COMMAND("dump_binds", "", CFGFLAG_CLIENT, con_dump_binds, this, "Dump binds"); - - // default bindings - set_defaults(); -} - -void BINDS::con_bind(void *result, void *user_data) -{ - BINDS *binds = (BINDS *)user_data; - const char *key_name = console_arg_string(result, 0); - int id = binds->get_key_id(key_name); - - if(!id) - { - dbg_msg("binds", "key %s not found", key_name); - return; - } - - binds->bind(id, console_arg_string(result, 1)); -} - - -void BINDS::con_unbind(void *result, void *user_data) -{ - BINDS *binds = (BINDS *)user_data; - const char *key_name = console_arg_string(result, 0); - int id = binds->get_key_id(key_name); - - if(!id) - { - dbg_msg("binds", "key %s not found", key_name); - return; - } - - binds->bind(id, ""); -} - - -void BINDS::con_unbindall(void *result, void *user_data) -{ - BINDS *binds = (BINDS *)user_data; - binds->unbindall(); -} - - -void BINDS::con_dump_binds(void *result, void *user_data) -{ - BINDS *binds = (BINDS *)user_data; - for(int i = 0; i < KEY_LAST; i++) - { - if(binds->keybindings[i][0] == 0) - continue; - dbg_msg("binds", "%s (%d) = %s", inp_key_name(i), i, binds->keybindings[i]); - } -} - -int BINDS::get_key_id(const char *key_name) -{ - // check for numeric - if(key_name[0] == '&') - { - int i = atoi(key_name+1); - if(i > 0 && i < KEY_LAST) - return i; // numeric - } - - // search for key - for(int i = 0; i < KEY_LAST; i++) - { - if(strcmp(key_name, inp_key_name(i)) == 0) - return i; - } - - return 0; -} - -void BINDS::on_save() -{ - char buffer[256]; - char *end = buffer+sizeof(buffer)-8; - client_save_line("unbindall"); - for(int i = 0; i < KEY_LAST; i++) - { - if(keybindings[i][0] == 0) - continue; - str_format(buffer, sizeof(buffer), "bind %s ", inp_key_name(i)); - - // process the string. we need to escape some characters - const char *src = keybindings[i]; - char *dst = buffer + strlen(buffer); - *dst++ = '"'; - while(*src && dst < end) - { - if(*src == '"' || *src == '\\') // escape \ and " - *dst++ = '\\'; - *dst++ = *src++; - } - *dst++ = '"'; - *dst++ = 0; - - client_save_line(buffer); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.hpp deleted file mode 100644 index bdf242f91..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/binds.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -class BINDS : public COMPONENT -{ - char keybindings[KEY_LAST][128]; - - int get_key_id(const char *key_name); - - static void con_bind(void *result, void *user_data); - static void con_unbind(void *result, void *user_data); - static void con_unbindall(void *result, void *user_data); - static void con_dump_binds(void *result, void *user_data); - -public: - BINDS(); - - class BINDS_SPECIAL : public COMPONENT - { - public: - BINDS *binds; - virtual bool on_input(INPUT_EVENT e); - }; - - BINDS_SPECIAL special_binds; - - void bind(int keyid, const char *str); - void set_defaults(); - void unbindall(); - const char *get(int keyid); - const char *get_key(const char *bindstr); - - virtual void on_save(); - virtual void on_console_init(); - virtual bool on_input(INPUT_EVENT e); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.cpp deleted file mode 100644 index 960b004c6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "broadcast.hpp" - -void BROADCAST::on_reset() -{ - broadcast_time = 0; -} - -void BROADCAST::on_render() -{ - gfx_mapscreen(0, 0, 300*gfx_screenaspect(), 300); - - if(time_get() < broadcast_time) - { - float w = gfx_text_width(0, 14, broadcast_text, -1); - gfx_text(0, 150*gfx_screenaspect()-w/2, 35, 14, broadcast_text, -1); - } -} - -void BROADCAST::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_BROADCAST) - { - NETMSG_SV_BROADCAST *msg = (NETMSG_SV_BROADCAST *)rawmsg; - str_copy(broadcast_text, msg->message, sizeof(broadcast_text)); - broadcast_time = time_get()+time_freq()*10; - } -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.hpp deleted file mode 100644 index 102201ccd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/broadcast.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -class BROADCAST : public COMPONENT -{ -public: - // broadcasts - char broadcast_text[1024]; - int64 broadcast_time; - - virtual void on_reset(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.cpp deleted file mode 100644 index 7b188e006..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.cpp +++ /dev/null @@ -1,40 +0,0 @@ -extern "C" { - #include - #include -} - -#include -#include -#include -#include - -#include "camera.hpp" -#include "controls.hpp" - -CAMERA::CAMERA() -{ -} - -void CAMERA::on_render() -{ - //vec2 center; - zoom = 1.0f; - - // update camera center - if(gameclient.snap.spectate) - center = gameclient.controls->mouse_pos; - else - { - - float l = length(gameclient.controls->mouse_pos); - float deadzone = config.cl_mouse_deadzone; - float follow_factor = config.cl_mouse_followfactor/100.0f; - vec2 camera_offset(0, 0); - - float offset_amount = max(l-deadzone, 0.0f) * follow_factor; - if(l > 0.0001f) // make sure that this isn't 0 - camera_offset = normalize(gameclient.controls->mouse_pos)*offset_amount; - - center = gameclient.local_character_pos + camera_offset; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.hpp deleted file mode 100644 index 1cb05f5bf..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/camera.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -class CAMERA : public COMPONENT -{ -public: - vec2 center; - float zoom; - - CAMERA(); - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.cpp deleted file mode 100644 index 8ef4e17dd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include // strcmp - -#include -#include -#include - -#include - -#include - -#include "chat.hpp" - -void CHAT::on_statechange(int new_state, int old_state) -{ - if(old_state <= CLIENTSTATE_CONNECTING) - { - mode = MODE_NONE; - for(int i = 0; i < MAX_LINES; i++) - lines[i].time = 0; - current_line = 0; - } -} - -void CHAT::con_say(void *result, void *user_data) -{ - ((CHAT*)user_data)->say(0, console_arg_string(result, 0)); -} - -void CHAT::con_sayteam(void *result, void *user_data) -{ - ((CHAT*)user_data)->say(1, console_arg_string(result, 0)); -} - -void CHAT::con_chat(void *result, void *user_data) -{ - const char *mode = console_arg_string(result, 0); - if(strcmp(mode, "all") == 0) - ((CHAT*)user_data)->enable_mode(0); - else if(strcmp(mode, "team") == 0) - ((CHAT*)user_data)->enable_mode(1); - else - dbg_msg("console", "expected all or team as mode"); -} - -void CHAT::on_console_init() -{ - MACRO_REGISTER_COMMAND("say", "r", CFGFLAG_CLIENT, con_say, this, "Say in chat"); - MACRO_REGISTER_COMMAND("say_team", "r", CFGFLAG_CLIENT, con_sayteam, this, "Say in team chat"); - MACRO_REGISTER_COMMAND("chat", "s", CFGFLAG_CLIENT, con_chat, this, "Enable chat with all/team mode"); -} - -bool CHAT::on_input(INPUT_EVENT e) -{ - if(mode == MODE_NONE) - return false; - - if(e.flags&INPFLAG_PRESS && e.key == KEY_ESCAPE) - mode = MODE_NONE; - else if(e.flags&INPFLAG_PRESS && (e.key == KEY_RETURN || e.key == KEY_KP_ENTER)) - { - if(input.get_string()[0]) - gameclient.chat->say(mode == MODE_ALL ? 0 : 1, input.get_string()); - mode = MODE_NONE; - } - else - input.process_input(e); - - return true; -} - - -void CHAT::enable_mode(int team) -{ - if(mode == MODE_NONE) - { - if(team) - mode = MODE_TEAM; - else - mode = MODE_ALL; - - input.clear(); - inp_clear_events(); - } -} - -void CHAT::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_CHAT) - { - NETMSG_SV_CHAT *msg = (NETMSG_SV_CHAT *)rawmsg; - add_line(msg->cid, msg->team, msg->message); - - if(msg->cid >= 0) - gameclient.sounds->play(SOUNDS::CHN_GUI, SOUND_CHAT_CLIENT, 0, vec2(0,0)); - else - gameclient.sounds->play(SOUNDS::CHN_GUI, SOUND_CHAT_SERVER, 0, vec2(0,0)); - } -} - -void CHAT::add_line(int client_id, int team, const char *line) -{ - current_line = (current_line+1)%MAX_LINES; - lines[current_line].time = time_get(); - lines[current_line].client_id = client_id; - lines[current_line].team = team; - lines[current_line].name_color = -2; - - if(client_id == -1) // server message - { - str_copy(lines[current_line].name, "*** ", sizeof(lines[current_line].name)); - str_format(lines[current_line].text, sizeof(lines[current_line].text), "%s", line); - } - else - { - if(gameclient.clients[client_id].team == -1) - lines[current_line].name_color = -1; - - if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS) - { - if(gameclient.clients[client_id].team == 0) - lines[current_line].name_color = 0; - else if(gameclient.clients[client_id].team == 1) - lines[current_line].name_color = 1; - } - - str_copy(lines[current_line].name, gameclient.clients[client_id].name, sizeof(lines[current_line].name)); - str_format(lines[current_line].text, sizeof(lines[current_line].text), ": %s", line); - } - - dbg_msg("chat", "%s%s", lines[current_line].name, lines[current_line].text); -} - -void CHAT::on_render() -{ - gfx_mapscreen(0,0,300*gfx_screenaspect(),300); - float x = 10.0f; - float y = 300.0f-20.0f; - if(mode != MODE_NONE) - { - // render chat input - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, x, y, 8.0f, TEXTFLAG_RENDER); - cursor.line_width = 200.0f; - - if(mode == MODE_ALL) - gfx_text_ex(&cursor, "All: ", -1); - else if(mode == MODE_TEAM) - gfx_text_ex(&cursor, "Team: ", -1); - else - gfx_text_ex(&cursor, "Chat: ", -1); - - gfx_text_ex(&cursor, input.get_string(), input.cursor_offset()); - TEXT_CURSOR marker = cursor; - gfx_text_ex(&marker, "|", -1); - gfx_text_ex(&cursor, input.get_string()+input.cursor_offset(), -1); - } - - y -= 8; - - int i; - for(i = 0; i < MAX_LINES; i++) - { - int r = ((current_line-i)+MAX_LINES)%MAX_LINES; - if(time_get() > lines[r].time+15*time_freq()) - break; - - float begin = x; - float fontsize = 7.0f; - - // get the y offset - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, begin, 0, fontsize, 0); - cursor.line_width = 200.0f; - gfx_text_ex(&cursor, lines[r].name, -1); - gfx_text_ex(&cursor, lines[r].text, -1); - y -= cursor.y + cursor.font_size; - - // cut off if msgs waste too much space - if(y < 200.0f) - break; - - // reset the cursor - gfx_text_set_cursor(&cursor, begin, y, fontsize, TEXTFLAG_RENDER); - cursor.line_width = 200.0f; - - // render name - gfx_text_color(0.8f,0.8f,0.8f,1); - if(lines[r].client_id == -1) - gfx_text_color(1,1,0.5f,1); // system - else if(lines[r].team) - gfx_text_color(0.45f,0.9f,0.45f,1); // team message - else if(lines[r].name_color == 0) - gfx_text_color(1.0f,0.5f,0.5f,1); // red - else if(lines[r].name_color == 1) - gfx_text_color(0.7f,0.7f,1.0f,1); // blue - else if(lines[r].name_color == -1) - gfx_text_color(0.75f,0.5f,0.75f, 1); // spectator - - // render name - gfx_text_ex(&cursor, lines[r].name, -1); - - // render line - gfx_text_color(1,1,1,1); - if(lines[r].client_id == -1) - gfx_text_color(1,1,0.5f,1); // system - else if(lines[r].team) - gfx_text_color(0.65f,1,0.65f,1); // team message - - gfx_text_ex(&cursor, lines[r].text, -1); - } - - gfx_text_color(1,1,1,1); -} - -void CHAT::say(int team, const char *line) -{ - // send chat message - NETMSG_CL_SAY msg; - msg.team = team; - msg.message = line; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.hpp deleted file mode 100644 index ca34237d7..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/chat.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - -class CHAT : public COMPONENT -{ - LINEINPUT input; - - enum - { - MAX_LINES = 10, - }; - - struct LINE - { - int64 time; - int client_id; - int team; - int name_color; - char name[64]; - char text[512]; - }; - - LINE lines[MAX_LINES]; - int current_line; - - // chat - enum - { - MODE_NONE=0, - MODE_ALL, - MODE_TEAM, - }; - - int mode; - - static void con_say(void *result, void *user_data); - static void con_sayteam(void *result, void *user_data); - static void con_chat(void *result, void *user_data); - -public: - bool is_active() const { return mode != MODE_NONE; } - - void add_line(int client_id, int team, const char *line); - - void enable_mode(int team); - - void say(int team, const char *line); - - virtual void on_console_init(); - virtual void on_statechange(int new_state, int old_state); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); - virtual bool on_input(INPUT_EVENT e); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.cpp deleted file mode 100644 index 53d5637ed..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.cpp +++ /dev/null @@ -1,538 +0,0 @@ -//#include "gc_console.hpp" -#include - -#include - -#include - -#include - -extern "C" { - #include - #include -} - -#include -#include - -#include - -#include - -#include -#include - -#include "console.hpp" - -enum -{ - CONSOLE_CLOSED, - CONSOLE_OPENING, - CONSOLE_OPEN, - CONSOLE_CLOSING, -}; - -CONSOLE::INSTANCE::INSTANCE(int t) -{ - // init ringbuffers - history = ringbuf_init(history_data, sizeof(history_data), RINGBUF_FLAG_RECYCLE); - backlog = ringbuf_init(backlog_data, sizeof(backlog_data), RINGBUF_FLAG_RECYCLE); - - history_entry = 0x0; - - type = t; - - if(t == 0) - completion_flagmask = CFGFLAG_CLIENT; - else - completion_flagmask = CFGFLAG_SERVER; - - completion_buffer[0] = 0; - completion_chosen = -1; - - command = 0x0; -} - -void CONSOLE::INSTANCE::execute_line(const char *line) -{ - if(type == 0) - console_execute_line(line); - else - { - if(client_rcon_authed()) - client_rcon(line); - else - client_rcon_auth("", line); - } -} - -void CONSOLE::INSTANCE::possible_commands_complete_callback(const char *str, void *user) -{ - CONSOLE::INSTANCE *instance = (CONSOLE::INSTANCE *)user; - if(instance->completion_chosen == instance->completion_enumeration_count) - instance->input.set(str); - instance->completion_enumeration_count++; -} - -void CONSOLE::INSTANCE::on_input(INPUT_EVENT e) -{ - bool handled = false; - - if(e.flags&INPFLAG_PRESS) - { - if(e.key == KEY_RETURN || e.key == KEY_KP_ENTER) - { - if(input.get_string()[0]) - { - char *entry = (char *)ringbuf_allocate(history, input.get_length()+1); - mem_copy(entry, input.get_string(), input.get_length()+1); - - execute_line(input.get_string()); - input.clear(); - history_entry = 0x0; - } - - handled = true; - } - else if (e.key == KEY_UP) - { - if (history_entry) - { - char *test = (char *)ringbuf_prev(history, history_entry); - - if (test) - history_entry = test; - } - else - history_entry = (char *)ringbuf_last(history); - - if (history_entry) - { - unsigned int len = strlen(history_entry); - if (len < sizeof(input) - 1) - input.set(history_entry); - } - handled = true; - } - else if (e.key == KEY_DOWN) - { - if (history_entry) - history_entry = (char *)ringbuf_next(history, history_entry); - - if (history_entry) - { - unsigned int len = strlen(history_entry); - if (len < sizeof(input) - 1) - input.set(history_entry); - } - else - input.clear(); - handled = true; - } - else if(e.key == KEY_TAB) - { - completion_chosen++; - completion_enumeration_count = 0; - console_possible_commands(completion_buffer, completion_flagmask, possible_commands_complete_callback, this); - - // handle wrapping - if(completion_enumeration_count && completion_chosen >= completion_enumeration_count) - { - completion_chosen %= completion_enumeration_count; - completion_enumeration_count = 0; - console_possible_commands(completion_buffer, completion_flagmask, possible_commands_complete_callback, this); - } - } - - if(e.key != KEY_TAB) - { - completion_chosen = -1; - str_copy(completion_buffer, input.get_string(), sizeof(completion_buffer)); - } - - // find the current command - { - char buf[64] = {0}; - const char *src = get_string(); - int i = 0; - for(; i < (int)sizeof(buf) && *src && *src != ' ' && *src != ' '; i++, src++) - buf[i] = *src; - buf[i] = 0; - - command = console_get_command(buf); - } - } - - if(!handled) - input.process_input(e); -} - -void CONSOLE::INSTANCE::print_line(const char *line) -{ - int len = strlen(line); - - if (len > 255) - len = 255; - - char *entry = (char *)ringbuf_allocate(backlog, len+1); - mem_copy(entry, line, len+1); -} - -CONSOLE::CONSOLE() -: local_console(0), remote_console(1) -{ - console_type = 0; - console_state = CONSOLE_CLOSED; - state_change_end = 0.0f; - state_change_duration = 0.1f; -} - -float CONSOLE::time_now() -{ - static long long time_start = time_get(); - return float(time_get()-time_start)/float(time_freq()); -} - -CONSOLE::INSTANCE *CONSOLE::current_console() -{ - if(console_type != 0) - return &remote_console; - return &local_console; -} - -void CONSOLE::on_reset() -{ -} - -// only defined for 0<=t<=1 -static float console_scale_func(float t) -{ - //return t; - return sinf(acosf(1.0f-t)); -} - -struct RENDERINFO -{ - TEXT_CURSOR cursor; - const char *current_cmd; - int wanted_completion; - int enum_count; -}; - -void CONSOLE::possible_commands_render_callback(const char *str, void *user) -{ - RENDERINFO *info = (RENDERINFO *)user; - - if(info->enum_count == info->wanted_completion) - { - float tw = gfx_text_width(info->cursor.font_set, info->cursor.font_size, str, -1); - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,0.85f); - draw_round_rect(info->cursor.x-3, info->cursor.y, tw+5, info->cursor.font_size+4, info->cursor.font_size/3); - gfx_quads_end(); - - gfx_text_color(0.05f, 0.05f, 0.05f,1); - gfx_text_ex(&info->cursor, str, -1); - } - else - { - const char *match_start = str_find_nocase(str, info->current_cmd); - - if(match_start) - { - gfx_text_color(0.5f,0.5f,0.5f,1); - gfx_text_ex(&info->cursor, str, match_start-str); - gfx_text_color(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,1); - gfx_text_ex(&info->cursor, match_start, strlen(info->current_cmd)); - gfx_text_color(0.5f,0.5f,0.5f,1); - gfx_text_ex(&info->cursor, match_start+strlen(info->current_cmd), -1); - } - else - { - gfx_text_color(0.75f,0.75f,0.75f,1); - gfx_text_ex(&info->cursor, str, -1); - } - } - - info->enum_count++; - info->cursor.x += 7.0f; -} - -void CONSOLE::on_render() -{ - RECT screen = *ui_screen(); - float console_max_height = screen.h*3/5.0f; - float console_height; - - float progress = (time_now()-(state_change_end-state_change_duration))/float(state_change_duration); - - if (progress >= 1.0f) - { - if (console_state == CONSOLE_CLOSING) - console_state = CONSOLE_CLOSED; - else if (console_state == CONSOLE_OPENING) - console_state = CONSOLE_OPEN; - - progress = 1.0f; - } - - if (console_state == CONSOLE_OPEN && config.cl_editor) - toggle(0); - - if (console_state == CONSOLE_CLOSED) - return; - - if (console_state == CONSOLE_OPEN) - inp_mouse_mode_absolute(); - - float console_height_scale; - - if (console_state == CONSOLE_OPENING) - console_height_scale = console_scale_func(progress); - else if (console_state == CONSOLE_CLOSING) - console_height_scale = console_scale_func(1.0f-progress); - else //if (console_state == CONSOLE_OPEN) - console_height_scale = console_scale_func(1.0f); - - console_height = console_height_scale*console_max_height; - - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - - // do console shadow - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolorvertex(0, 0,0,0, 0.5f); - gfx_setcolorvertex(1, 0,0,0, 0.5f); - gfx_setcolorvertex(2, 0,0,0, 0.0f); - gfx_setcolorvertex(3, 0,0,0, 0.0f); - gfx_quads_drawTL(0,console_height,screen.w,10.0f); - gfx_quads_end(); - - // do background - gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id); - gfx_quads_begin(); - gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f); - if(console_type != 0) - gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f); - gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0); - gfx_quads_drawTL(0,0,screen.w,console_height); - gfx_quads_end(); - - // do small bar shadow - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolorvertex(0, 0,0,0, 0.0f); - gfx_setcolorvertex(1, 0,0,0, 0.0f); - gfx_setcolorvertex(2, 0,0,0, 0.25f); - gfx_setcolorvertex(3, 0,0,0, 0.25f); - gfx_quads_drawTL(0,console_height-20,screen.w,10); - gfx_quads_end(); - - // do the lower bar - gfx_texture_set(data->images[IMAGE_CONSOLE_BAR].id); - gfx_quads_begin(); - gfx_setcolor(1.0f, 1.0f, 1.0f, 0.9f); - gfx_quads_setsubset(0,0.1f,screen.w*0.015f,1-0.1f); - gfx_quads_drawTL(0,console_height-10.0f,screen.w,10.0f); - gfx_quads_end(); - - console_height -= 22.0f; - - INSTANCE *console = current_console(); - - { - float font_size = 10.0f; - float row_height = font_size*1.25f; - float x = 3; - float y = console_height - row_height - 2; - - // render prompt - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, x, y, font_size, TEXTFLAG_RENDER); - - RENDERINFO info; - info.wanted_completion = console->completion_chosen; - info.enum_count = 0; - info.current_cmd = console->completion_buffer; - gfx_text_set_cursor(&info.cursor, x, y+12.0f, font_size, TEXTFLAG_RENDER); - - const char *prompt = "> "; - if(console_type) - { - if(client_state() == CLIENTSTATE_ONLINE) - { - if(client_rcon_authed()) - prompt = "rcon> "; - else - prompt = "ENTER PASSWORD> "; - } - else - prompt = "NOT CONNECTED> "; - } - - gfx_text_ex(&cursor, prompt, -1); - - // render console input - gfx_text_ex(&cursor, console->input.get_string(), console->input.cursor_offset()); - TEXT_CURSOR marker = cursor; - gfx_text_ex(&marker, "|", -1); - gfx_text_ex(&cursor, console->input.get_string()+console->input.cursor_offset(), -1); - - // render version - char buf[128]; - str_format(buf, sizeof(buf), "v%s", GAME_VERSION); - float version_width = gfx_text_width(0, font_size, buf, -1); - gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1); - - // render possible commands - if(console->input.get_string()[0] != 0) - { - console_possible_commands(console->completion_buffer, console->completion_flagmask, possible_commands_render_callback, &info); - - if(info.enum_count <= 0) - { - if(console->command) - { - - char buf[512]; - str_format(buf, sizeof(buf), "Help: %s ", console->command->help); - gfx_text_ex(&info.cursor, buf, -1); - gfx_text_color(0.75f, 0.75f, 0.75f, 1); - str_format(buf, sizeof(buf), "Syntax: %s %s", console->command->name, console->command->params); - gfx_text_ex(&info.cursor, buf, -1); - } - } - } - gfx_text_color(1,1,1,1); - - // render log - y -= row_height; - char *entry = (char *)ringbuf_last(console->backlog); - while (y > 0.0f && entry) - { - gfx_text(0, x, y, font_size, entry, -1); - y -= row_height; - - entry = (char *)ringbuf_prev(console->backlog, entry); - } - } -} - -void CONSOLE::on_message(int msgtype, void *rawmsg) -{ -} - -bool CONSOLE::on_input(INPUT_EVENT e) -{ - if(console_state == CONSOLE_CLOSED) - return false; - if(e.key >= KEY_F1 && e.key <= KEY_F15) - return false; - - if(e.key == KEY_ESCAPE && (e.flags&INPFLAG_PRESS)) - toggle(console_type); - else - current_console()->on_input(e); - - return true; -} - -void CONSOLE::toggle(int type) -{ - if(console_type != type && (console_state == CONSOLE_OPEN || console_state == CONSOLE_OPENING)) - { - // don't toggle console, just switch what console to use - } - else - { - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_OPEN) - { - state_change_end = time_now()+state_change_duration; - } - else - { - float progress = state_change_end-time_now(); - float reversed_progress = state_change_duration-progress; - - state_change_end = time_now()+reversed_progress; - } - - if (console_state == CONSOLE_CLOSED || console_state == CONSOLE_CLOSING) - { - inp_mouse_mode_absolute(); - console_state = CONSOLE_OPENING; - } - else - { - inp_mouse_mode_relative(); - console_state = CONSOLE_CLOSING; - } - } - - console_type = type; -} - -void CONSOLE::con_toggle_local_console(void *result, void *user_data) -{ - ((CONSOLE *)user_data)->toggle(0); -} - -void CONSOLE::con_toggle_remote_console(void *result, void *user_data) -{ - ((CONSOLE *)user_data)->toggle(1); -} - -void CONSOLE::client_console_print_callback(const char *str, void *user_data) -{ - ((CONSOLE *)user_data)->local_console.print_line(str); -} - -void CONSOLE::print_line(int type, const char *line) -{ - if(type == 0) - local_console.print_line(line); - else if(type == 1) - remote_console.print_line(line); -} - -void CONSOLE::on_console_init() -{ - // - console_register_print_callback(client_console_print_callback, this); - - MACRO_REGISTER_COMMAND("toggle_local_console", "", CFGFLAG_CLIENT, con_toggle_local_console, this, "Toggle local console"); - MACRO_REGISTER_COMMAND("toggle_remote_console", "", CFGFLAG_CLIENT, con_toggle_remote_console, this, "Toggle remote console"); -} - -/* -static void con_team(void *result, void *user_data) -{ - send_switch_team(console_arg_int(result, 0)); -} - -static void con_kill(void *result, void *user_data) -{ - send_kill(-1); -} - -void send_kill(int client_id); - -static void con_emote(void *result, void *user_data) -{ - send_emoticon(console_arg_int(result, 0)); -} - -extern void con_chat(void *result, void *user_data); - -void client_console_init() -{ - // - MACRO_REGISTER_COMMAND("team", "i", con_team, 0x0); - MACRO_REGISTER_COMMAND("kill", "", con_kill, 0x0); - - // chatting - MACRO_REGISTER_COMMAND("emote", "i", con_emote, 0); - MACRO_REGISTER_COMMAND("+emote", "", con_key_input_state, &emoticon_selector_active); -} -*/ diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.hpp deleted file mode 100644 index 0a4adbda9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/console.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include - -class CONSOLE : public COMPONENT -{ - class INSTANCE - { - public: - char history_data[65536]; - struct RINGBUFFER *history; - char *history_entry; - - char backlog_data[65536]; - struct RINGBUFFER *backlog; - - LINEINPUT input; - - int type; - int completion_enumeration_count; - - public: - char completion_buffer[128]; - int completion_chosen; - int completion_flagmask; - - COMMAND *command; - - INSTANCE(int t); - - void execute_line(const char *line); - - void on_input(INPUT_EVENT e); - void print_line(const char *line); - - const char *get_string() const { return input.get_string(); } - - static void possible_commands_complete_callback(const char *str, void *user); - }; - - INSTANCE local_console; - INSTANCE remote_console; - - INSTANCE *current_console(); - float time_now(); - - int console_type; - int console_state; - float state_change_end; - float state_change_duration; - - - void toggle(int type); - - static void possible_commands_render_callback(const char *str, void *user); - static void client_console_print_callback(const char *str, void *user_data); - static void con_toggle_local_console(void *result, void *user_data); - static void con_toggle_remote_console(void *result, void *user_data); - -public: - CONSOLE(); - - void print_line(int type, const char *line); - - virtual void on_console_init(); - virtual void on_reset(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); - virtual bool on_input(INPUT_EVENT e); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.cpp deleted file mode 100644 index 964ef7670..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.cpp +++ /dev/null @@ -1,242 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "controls.hpp" - -CONTROLS::CONTROLS() -{ -} - -static void con_key_input_state(void *result, void *user_data) -{ - ((int *)user_data)[0] = console_arg_int(result, 0); -} - -#ifdef ANDROID -static bool con_key_fire_android_triggered = false; -#endif - -static void con_key_input_counter(void *result, void *user_data) -{ -#ifdef ANDROID - if(!con_key_fire_android_triggered) - return; -#endif - int *v = (int *)user_data; - if(((*v)&1) != console_arg_int(result, 0)) - (*v)++; - *v &= INPUT_STATE_MASK; -} - -struct INPUTSET -{ - CONTROLS *controls; - int *variable; - int value; -}; - -static void con_key_input_set(void *result, void *user_data) -{ - INPUTSET *set = (INPUTSET *)user_data; - *set->variable = console_arg_int(result, 0) ? *set->variable = set->value : 0; -} - -static void con_key_input_nextprev_weapon(void *result, void *user_data) -{ - INPUTSET *set = (INPUTSET *)user_data; - con_key_input_counter(result, set->variable); - set->controls->input_data.wanted_weapon = 0; -} - -void CONTROLS::on_console_init() -{ - // game commands - MACRO_REGISTER_COMMAND("+left", "", CFGFLAG_CLIENT, con_key_input_state, &input_direction_left, "Move left"); - MACRO_REGISTER_COMMAND("+right", "", CFGFLAG_CLIENT, con_key_input_state, &input_direction_right, "Move right"); - MACRO_REGISTER_COMMAND("+jump", "", CFGFLAG_CLIENT, con_key_input_state, &input_data.jump, "Jump"); - MACRO_REGISTER_COMMAND("+hook", "", CFGFLAG_CLIENT, con_key_input_state, &input_data.hook, "Hook"); - MACRO_REGISTER_COMMAND("+fire", "", CFGFLAG_CLIENT, con_key_input_counter, &input_data.fire, "Fire"); - - { static INPUTSET set = {this, &input_data.wanted_weapon, 1}; MACRO_REGISTER_COMMAND("+weapon1", "", CFGFLAG_CLIENT, con_key_input_set, (void *)&set, "Switch to hammer"); } - { static INPUTSET set = {this, &input_data.wanted_weapon, 2}; MACRO_REGISTER_COMMAND("+weapon2", "", CFGFLAG_CLIENT, con_key_input_set, (void *)&set, "Switch to gun"); } - { static INPUTSET set = {this, &input_data.wanted_weapon, 3}; MACRO_REGISTER_COMMAND("+weapon3", "", CFGFLAG_CLIENT, con_key_input_set, (void *)&set, "Switch to shotgun"); } - { static INPUTSET set = {this, &input_data.wanted_weapon, 4}; MACRO_REGISTER_COMMAND("+weapon4", "", CFGFLAG_CLIENT, con_key_input_set, (void *)&set, "Switch to grenade"); } - { static INPUTSET set = {this, &input_data.wanted_weapon, 5}; MACRO_REGISTER_COMMAND("+weapon5", "", CFGFLAG_CLIENT, con_key_input_set, (void *)&set, "Switch to rifle"); } - - { static INPUTSET set = {this, &input_data.next_weapon, 0}; MACRO_REGISTER_COMMAND("+nextweapon", "", CFGFLAG_CLIENT, con_key_input_nextprev_weapon, (void *)&set, "Switch to next weapon"); } - { static INPUTSET set = {this, &input_data.prev_weapon, 0}; MACRO_REGISTER_COMMAND("+prevweapon", "", CFGFLAG_CLIENT, con_key_input_nextprev_weapon, (void *)&set, "Switch to previous weapon"); } -} - -void CONTROLS::on_message(int msg, void *rawmsg) -{ - if(msg == NETMSGTYPE_SV_WEAPONPICKUP) - { - NETMSG_SV_WEAPONPICKUP *msg = (NETMSG_SV_WEAPONPICKUP *)rawmsg; - if(config.cl_autoswitch_weapons) - input_data.wanted_weapon = msg->weapon+1; - } -} - -int CONTROLS::snapinput(int *data) -{ - static NETOBJ_PLAYER_INPUT last_data = {0}; - static int64 last_send_time = 0; - bool send = false; - - // update player state - if(gameclient.chat->is_active()) - input_data.player_state = PLAYERSTATE_CHATTING; - else if(gameclient.menus->is_active()) - input_data.player_state = PLAYERSTATE_IN_MENU; - else - input_data.player_state = PLAYERSTATE_PLAYING; - - if(last_data.player_state != input_data.player_state) - send = true; - - last_data.player_state = input_data.player_state; - - // we freeze the input if chat or menu is activated - if(input_data.player_state != PLAYERSTATE_PLAYING) - { - last_data.direction = 0; - last_data.hook = 0; - last_data.jump = 0; - input_data = last_data; - - input_direction_left = 0; - input_direction_right = 0; - - mem_copy(data, &input_data, sizeof(input_data)); - - // send once a second just to be sure - if(time_get() > last_send_time + time_freq()) - send = true; - } - else - { - - input_data.target_x = (int)mouse_pos.x; - input_data.target_y = (int)mouse_pos.y; - if(!input_data.target_x && !input_data.target_y) - input_data.target_y = 1; - - // set direction - input_data.direction = 0; - if(input_direction_left && !input_direction_right) - input_data.direction = -1; - if(!input_direction_left && input_direction_right) - input_data.direction = 1; - - // stress testing - if(config.dbg_stress) - { - float t = client_localtime(); - mem_zero(&input_data, sizeof(input_data)); - - input_data.direction = ((int)t/2)&1; - input_data.jump = ((int)t); - input_data.fire = ((int)(t*10)); - input_data.hook = ((int)(t*2))&1; - input_data.wanted_weapon = ((int)t)%NUM_WEAPONS; - input_data.target_x = (int)(sinf(t*3)*100.0f); - input_data.target_y = (int)(cosf(t*3)*100.0f); - } - - // check if we need to send input - if(input_data.direction != last_data.direction) send = true; - else if(input_data.jump != last_data.jump) send = true; - else if(input_data.fire != last_data.fire) send = true; - else if(input_data.hook != last_data.hook) send = true; - else if(input_data.player_state != last_data.player_state) send = true; - else if(input_data.wanted_weapon != last_data.wanted_weapon) send = true; - else if(input_data.next_weapon != last_data.next_weapon) send = true; - else if(input_data.prev_weapon != last_data.prev_weapon) send = true; - - // send at at least 10hz - if(time_get() > last_send_time + time_freq()/25) - send = true; - } - - // copy and return size - last_data = input_data; - - if(!send) - return 0; - - last_send_time = time_get(); - mem_copy(data, &input_data, sizeof(input_data)); - return sizeof(input_data); -} - -void CONTROLS::on_render() -{ - // update target pos - if(!((gameclient.snap.gameobj && gameclient.snap.gameobj->paused) || gameclient.snap.spectate)) - target_pos = gameclient.local_character_pos + mouse_pos; -} - -bool CONTROLS::on_mousemove(float x, float y) -{ - if(gameclient.snap.gameobj && gameclient.snap.gameobj->paused) - return false; - mouse_pos += vec2(x, y); // TODO: ugly -#ifdef ANDROID - - if(gameclient.snap.spectate) - { - if( mouse_pos_old != vec2(x, y)) - { - mouse_pos_old = vec2(x, y); - mouse_pos += vec2((x - gfx_screenwidth()/2), (y - gfx_screenheight()/2)); - } - } - else - { - mouse_pos = vec2((x - gfx_screenwidth()/2) * 2, (y - gfx_screenheight()/2) * 2); - } -#endif - - // - float camera_max_distance = 200.0f; - float follow_factor = config.cl_mouse_followfactor/100.0f; - float deadzone = config.cl_mouse_deadzone; - float mouse_max = min(camera_max_distance/follow_factor + deadzone, (float)config.cl_mouse_max_distance); - - //vec2 camera_offset(0, 0); - - if(gameclient.snap.spectate) - { - if(mouse_pos.x < 200.0f) mouse_pos.x = 200.0f; - if(mouse_pos.y < 200.0f) mouse_pos.y = 200.0f; - if(mouse_pos.x > col_width()*32-200.0f) mouse_pos.x = col_width()*32-200.0f; - if(mouse_pos.y > col_height()*32-200.0f) mouse_pos.y = col_height()*32-200.0f; - - target_pos = mouse_pos; - } - else - { - float l = length(mouse_pos); - - if(l > mouse_max) - { - mouse_pos = normalize(mouse_pos)*mouse_max; - l = mouse_max; - } - -#ifdef ANDROID - con_key_fire_android_triggered = (l > mouse_max/4); -#endif - - //float offset_amount = max(l-deadzone, 0.0f) * follow_factor; - //if(l > 0.0001f) // make sure that this isn't 0 - //camera_offset = normalize(mouse_pos)*offset_amount; - } - - return true; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.hpp deleted file mode 100644 index 3aaef3f79..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/controls.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -class CONTROLS : public COMPONENT -{ -public: - vec2 mouse_pos; - vec2 target_pos; - vec2 mouse_pos_old; // for Android - - NETOBJ_PLAYER_INPUT input_data; - int input_direction_left; - int input_direction_right; - - CONTROLS(); - - virtual void on_render(); - virtual void on_message(int msg, void *rawmsg); - virtual bool on_mousemove(float x, float y); - virtual void on_console_init(); - - int snapinput(int *data); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.cpp deleted file mode 100644 index f585e4d30..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include - -#include // get_angle -#include -#include -#include "damageind.hpp" - -DAMAGEIND::DAMAGEIND() -{ - lastupdate = 0; - num_items = 0; -} - -DAMAGEIND::ITEM *DAMAGEIND::create_i() -{ - if (num_items < MAX_ITEMS) - { - ITEM *p = &items[num_items]; - num_items++; - return p; - } - return 0; -} - -void DAMAGEIND::destroy_i(DAMAGEIND::ITEM *i) -{ - num_items--; - *i = items[num_items]; -} - -void DAMAGEIND::create(vec2 pos, vec2 dir) -{ - ITEM *i = create_i(); - if (i) - { - i->pos = pos; - i->life = 0.75f; - i->dir = dir*-1; - i->startangle = (( (float)rand()/(float)RAND_MAX) - 1.0f) * 2.0f * pi; - } -} - -void DAMAGEIND::on_render() -{ - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - for(int i = 0; i < num_items;) - { - vec2 pos = mix(items[i].pos+items[i].dir*75.0f, items[i].pos, clamp((items[i].life-0.60f)/0.15f, 0.0f, 1.0f)); - - items[i].life -= client_frametime(); - if(items[i].life < 0.0f) - destroy_i(&items[i]); - else - { - gfx_setcolor(1.0f,1.0f,1.0f, items[i].life/0.1f); - gfx_quads_setrotation(items[i].startangle + items[i].life * 2.0f); - select_sprite(SPRITE_STAR1); - draw_sprite(pos.x, pos.y, 48.0f); - i++; - } - } - gfx_quads_end(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.hpp deleted file mode 100644 index c74af9ca8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/damageind.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -class DAMAGEIND : public COMPONENT -{ - int64 lastupdate; - struct ITEM - { - vec2 pos; - vec2 dir; - float life; - float startangle; - }; - - enum - { - MAX_ITEMS=64, - }; - - ITEM items[MAX_ITEMS]; - int num_items; - - ITEM *create_i(); - void destroy_i(ITEM *i); - -public: - DAMAGEIND(); - - void create(vec2 pos, vec2 dir); - virtual void on_render(); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.cpp deleted file mode 100644 index ada006eab..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include // memcmp - -extern "C" { - #include -} - -#include -#include -#include - -#include - -#include -#include -#include - -//#include "controls.hpp" -//#include "camera.hpp" -#include "debughud.hpp" - -void DEBUGHUD::render_netcorrections() -{ - if(!config.debug || !gameclient.snap.local_character || !gameclient.snap.local_prev_character) - return; - - gfx_mapscreen(0, 0, 300*gfx_screenaspect(), 300); - - /*float speed = distance(vec2(netobjects.local_prev_character->x, netobjects.local_prev_character->y), - vec2(netobjects.local_character->x, netobjects.local_character->y));*/ - - float velspeed = length(vec2(gameclient.snap.local_character->vx/256.0f, gameclient.snap.local_character->vy/256.0f))*50; - - float ramp = velocity_ramp(velspeed, gameclient.tuning.velramp_start, gameclient.tuning.velramp_range, gameclient.tuning.velramp_curvature); - - char buf[512]; - str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d %s\n%d %d", - velspeed, velspeed*ramp, ramp, - netobj_num_corrections(), netobj_corrected_on(), - gameclient.snap.local_character->x, - gameclient.snap.local_character->y - ); - gfx_text(0, 150, 50, 12, buf, -1); -} - -void DEBUGHUD::render_tuning() -{ - // render tuning debugging - if(!config.dbg_tuning) - return; - - TUNING_PARAMS standard_tuning; - - gfx_mapscreen(0, 0, 300*gfx_screenaspect(), 300); - - float y = 50.0f; - int count = 0; - for(int i = 0; i < gameclient.tuning.num(); i++) - { - char buf[128]; - float current, standard; - gameclient.tuning.get(i, ¤t); - standard_tuning.get(i, &standard); - - if(standard == current) - gfx_text_color(1,1,1,1.0f); - else - gfx_text_color(1,0.25f,0.25f,1.0f); - - float w; - float x = 5.0f; - - str_format(buf, sizeof(buf), "%.2f", standard); - x += 20.0f; - w = gfx_text_width(0, 5, buf, -1); - gfx_text(0x0, x-w, y+count*6, 5, buf, -1); - - str_format(buf, sizeof(buf), "%.2f", current); - x += 20.0f; - w = gfx_text_width(0, 5, buf, -1); - gfx_text(0x0, x-w, y+count*6, 5, buf, -1); - - x += 5.0f; - gfx_text(0x0, x, y+count*6, 5, gameclient.tuning.names[i], -1); - - count++; - } - - y = y+count*6; - - gfx_texture_set(-1); - gfx_blend_normal(); - gfx_lines_begin(); - float height = 50.0f; - float pv = 1; - for(int i = 0; i < 100; i++) - { - float speed = i/100.0f * 3000; - float ramp = velocity_ramp(speed, gameclient.tuning.velramp_start, gameclient.tuning.velramp_range, gameclient.tuning.velramp_curvature); - float rampedspeed = (speed * ramp)/1000.0f; - gfx_lines_draw((i-1)*2, y+height-pv*height, i*2, y+height-rampedspeed*height); - //gfx_lines_draw((i-1)*2, 200, i*2, 200); - pv = rampedspeed; - } - gfx_lines_end(); - gfx_text_color(1,1,1,1); -} - -void DEBUGHUD::on_render() -{ - render_tuning(); - render_netcorrections(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.hpp deleted file mode 100644 index 473b2ce22..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/debughud.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -class DEBUGHUD : public COMPONENT -{ - void render_netcorrections(); - void render_tuning(); -public: - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.cpp deleted file mode 100644 index c9c47a8d4..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.cpp +++ /dev/null @@ -1,261 +0,0 @@ -#include -//#include -#include - -#include -#include -#include -#include -#include -#include - -#include "effects.hpp" - -inline vec2 random_dir() { return normalize(vec2(frandom()-0.5f, frandom()-0.5f)); } - -EFFECTS::EFFECTS() -{ - add_50hz = false; - add_100hz = false; -} - -void EFFECTS::air_jump(vec2 pos) -{ - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_AIRJUMP; - p.pos = pos + vec2(-6.0f, 16.0f); - p.vel = vec2(0, -200); - p.life_span = 0.5f; - p.start_size = 48.0f; - p.end_size = 0; - p.rot = frandom()*pi*2; - p.rotspeed = pi*2; - p.gravity = 500; - p.friction = 0.7f; - p.flow_affected = 0.0f; - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); - - p.pos = pos + vec2(6.0f, 16.0f); - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); - - gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos); -} - -void EFFECTS::damage_indicator(vec2 pos, vec2 dir) -{ - gameclient.damageind->create(pos, dir); -} - -void EFFECTS::powerupshine(vec2 pos, vec2 size) -{ - if(!add_50hz) - return; - - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SLICE; - p.pos = pos + vec2((frandom()-0.5f)*size.x, (frandom()-0.5f)*size.y); - p.vel = vec2(0, 0); - p.life_span = 0.5f; - p.start_size = 16.0f; - p.end_size = 0; - p.rot = frandom()*pi*2; - p.rotspeed = pi*2; - p.gravity = 500; - p.friction = 0.9f; - p.flow_affected = 0.0f; - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); -} - -void EFFECTS::smoketrail(vec2 pos, vec2 vel) -{ - if(!add_50hz) - return; - - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SMOKE; - p.pos = pos; - p.vel = vel + random_dir()*50.0f; - p.life_span = 0.5f + frandom()*0.5f; - p.start_size = 12.0f + frandom()*8; - p.end_size = 0; - p.friction = 0.7; - p.gravity = frandom()*-500.0f; - gameclient.particles->add(PARTICLES::GROUP_PROJECTILE_TRAIL, &p); -} - - -void EFFECTS::skidtrail(vec2 pos, vec2 vel) -{ - if(!add_100hz) - return; - - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SMOKE; - p.pos = pos; - p.vel = vel + random_dir()*50.0f; - p.life_span = 0.5f + frandom()*0.5f; - p.start_size = 24.0f + frandom()*12; - p.end_size = 0; - p.friction = 0.7f; - p.gravity = frandom()*-500.0f; - p.color = vec4(0.75f,0.75f,0.75f,1.0f); - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); -} - -void EFFECTS::bullettrail(vec2 pos) -{ - if(!add_100hz) - return; - - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_BALL; - p.pos = pos; - p.life_span = 0.25f + frandom()*0.25f; - p.start_size = 8.0f; - p.end_size = 0; - p.friction = 0.7f; - gameclient.particles->add(PARTICLES::GROUP_PROJECTILE_TRAIL, &p); -} - -void EFFECTS::playerspawn(vec2 pos) -{ - for(int i = 0; i < 32; i++) - { - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SHELL; - p.pos = pos; - p.vel = random_dir() * (pow(frandom(), 3)*600.0f); - p.life_span = 0.3f + frandom()*0.3f; - p.start_size = 64.0f + frandom()*32; - p.end_size = 0; - p.rot = frandom()*pi*2; - p.rotspeed = frandom(); - p.gravity = frandom()*-400.0f; - p.friction = 0.7f; - p.color = vec4(0xb5/255.0f, 0x50/255.0f, 0xcb/255.0f, 1.0f); - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); - - } - gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, pos); -} - -void EFFECTS::playerdeath(vec2 pos, int cid) -{ - vec3 blood_color(1.0f,1.0f,1.0f); - - if(cid >= 0) - { - const SKINS::SKIN *s = gameclient.skins->get(gameclient.clients[cid].skin_id); - if(s) - blood_color = s->blood_color; - } - - for(int i = 0; i < 64; i++) - { - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SPLAT01 + (rand()%3); - p.pos = pos; - p.vel = random_dir() * ((frandom()+0.1f)*900.0f); - p.life_span = 0.3f + frandom()*0.3f; - p.start_size = 24.0f + frandom()*16; - p.end_size = 0; - p.rot = frandom()*pi*2; - p.rotspeed = (frandom()-0.5f) * pi; - p.gravity = 800.0f; - p.friction = 0.8f; - vec3 c = blood_color * (0.75f + frandom()*0.25f); - p.color = vec4(c.r, c.g, c.b, 0.75f); - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); - } -} - - -void EFFECTS::explosion(vec2 pos) -{ - // add to flow - for(int y = -8; y <= 8; y++) - for(int x = -8; x <= 8; x++) - { - if(x == 0 && y == 0) - continue; - - float a = 1 - (length(vec2(x,y)) / length(vec2(8,8))); - gameclient.flow->add(pos+vec2(x,y)*16, normalize(vec2(x,y))*5000.0f*a, 10.0f); - } - - // add the explosion - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_EXPL01; - p.pos = pos; - p.life_span = 0.4f; - p.start_size = 150.0f; - p.end_size = 0; - p.rot = frandom()*pi*2; - gameclient.particles->add(PARTICLES::GROUP_EXPLOSIONS, &p); - - // add the smoke - for(int i = 0; i < 24; i++) - { - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_SMOKE; - p.pos = pos; - p.vel = random_dir() * ((1.0f + frandom()*0.2f) * 1000.0f); - p.life_span = 0.5f + frandom()*0.4f; - p.start_size = 32.0f + frandom()*8; - p.end_size = 0; - p.gravity = frandom()*-800.0f; - p.friction = 0.4f; - p.color = mix(vec4(0.75f,0.75f,0.75f,1.0f), vec4(0.5f,0.5f,0.5f,1.0f), frandom()); - gameclient.particles->add(PARTICLES::GROUP_GENERAL, &p); - } -} - - -void EFFECTS::hammerhit(vec2 pos) -{ - // add the explosion - PARTICLE p; - p.set_default(); - p.spr = SPRITE_PART_EXPL01; - p.pos = pos; - p.life_span = 0.4f; - p.start_size = 150.0f; - p.end_size = 0; - p.rot = frandom()*pi*2; - gameclient.particles->add(PARTICLES::GROUP_EXPLOSIONS, &p); - gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HAMMER_HIT, 1.0f, pos); -} - -void EFFECTS::on_render() -{ - static int64 last_update_100hz = 0; - static int64 last_update_50hz = 0; - - if(time_get()-last_update_100hz > time_freq()/100) - { - add_100hz = true; - last_update_100hz = time_get(); - } - else - add_100hz = false; - - if(time_get()-last_update_50hz > time_freq()/100) - { - add_50hz = true; - last_update_50hz = time_get(); - } - else - add_50hz = false; - - if(add_50hz) - gameclient.flow->update(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.hpp deleted file mode 100644 index 8574bf601..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/effects.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -class EFFECTS : public COMPONENT -{ - bool add_50hz; - bool add_100hz; -public: - EFFECTS(); - - virtual void on_render(); - - void bullettrail(vec2 pos); - void smoketrail(vec2 pos, vec2 vel); - void skidtrail(vec2 pos, vec2 vel); - void explosion(vec2 pos); - void hammerhit(vec2 pos); - void air_jump(vec2 pos); - void damage_indicator(vec2 pos, vec2 dir); - void playerspawn(vec2 pos); - void playerdeath(vec2 pos, int cid); - void powerupshine(vec2 pos, vec2 size); - - void update(); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.cpp deleted file mode 100644 index 38325f0e5..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include -#include - -#include // get_angle -#include -#include -#include -#include "emoticon.hpp" - -EMOTICON::EMOTICON() -{ - on_reset(); -} - -void EMOTICON::con_key_emoticon(void *result, void *user_data) -{ - ((EMOTICON *)user_data)->active = console_arg_int(result, 0) != 0; -} - -void EMOTICON::con_emote(void *result, void *user_data) -{ - ((EMOTICON *)user_data)->emote(console_arg_int(result, 0)); -} - -void EMOTICON::on_console_init() -{ - MACRO_REGISTER_COMMAND("+emote", "", CFGFLAG_CLIENT, con_key_emoticon, this, "Open emote selector"); - MACRO_REGISTER_COMMAND("emote", "i", CFGFLAG_CLIENT, con_emote, this, "Use emote"); -} - -void EMOTICON::on_reset() -{ - was_active = false; - active = false; - selected_emote = -1; -} - -void EMOTICON::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_EMOTICON) - { - NETMSG_SV_EMOTICON *msg = (NETMSG_SV_EMOTICON *)rawmsg; - gameclient.clients[msg->cid].emoticon = msg->emoticon; - gameclient.clients[msg->cid].emoticon_start = client_tick(); - } -} - -bool EMOTICON::on_mousemove(float x, float y) -{ - if(!active) - return false; - - selector_mouse += vec2(x,y); -#ifdef ANDROID - selector_mouse = vec2(x,y); -#endif - return true; -} - -void EMOTICON::draw_circle(float x, float y, float r, int segments) -{ - float f_segments = (float)segments; - for(int i = 0; i < segments; i+=2) - { - float a1 = i/f_segments * 2*pi; - float a2 = (i+1)/f_segments * 2*pi; - float a3 = (i+2)/f_segments * 2*pi; - float ca1 = cosf(a1); - float ca2 = cosf(a2); - float ca3 = cosf(a3); - float sa1 = sinf(a1); - float sa2 = sinf(a2); - float sa3 = sinf(a3); - - gfx_quads_draw_freeform( - x, y, - x+ca1*r, y+sa1*r, - x+ca3*r, y+sa3*r, - x+ca2*r, y+sa2*r); - } -} - - -void EMOTICON::on_render() -{ - if(!active) - { - if(was_active && selected_emote != -1) - emote(selected_emote); - was_active = false; - return; - } - - was_active = true; - - int x, y; -#ifdef ANDROID - // No relative mouse here, we've got touchscreen - inp_mouse_absolute(&x, &y); - - selector_mouse.x = x; - selector_mouse.y = y; -#else - inp_mouse_relative(&x, &y); - - selector_mouse.x += x; - selector_mouse.y += y; -#endif - - if (length(selector_mouse) > 140) - selector_mouse = normalize(selector_mouse) * 140; - - float selected_angle = get_angle(selector_mouse) + 2*pi/24; - if (selected_angle < 0) - selected_angle += 2*pi; - - if (length(selector_mouse) > 100) - selected_emote = (int)(selected_angle / (2*pi) * 12.0f); - - RECT screen = *ui_screen(); - - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - - gfx_blend_normal(); - - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.3f); - draw_circle(screen.w/2, screen.h/2, 160, 64); - gfx_quads_end(); - - gfx_texture_set(data->images[IMAGE_EMOTICONS].id); - gfx_quads_begin(); - - for (int i = 0; i < 12; i++) - { - float angle = 2*pi*i/12.0; - if (angle > pi) - angle -= 2*pi; - - bool selected = selected_emote == i; - - float size = selected ? 96 : 64; - - float nudge_x = 120 * cos(angle); - float nudge_y = 120 * sin(angle); - select_sprite(SPRITE_OOP + i); - gfx_quads_draw(screen.w/2 + nudge_x, screen.h/2 + nudge_y, size, size); - } - - gfx_quads_end(); - - gfx_texture_set(data->images[IMAGE_CURSOR].id); - gfx_quads_begin(); - gfx_setcolor(1,1,1,1); - gfx_quads_drawTL(selector_mouse.x+screen.w/2,selector_mouse.y+screen.h/2,24,24); - gfx_quads_end(); -} - -void EMOTICON::emote(int emoticon) -{ - NETMSG_CL_EMOTICON msg; - msg.emoticon = emoticon; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.hpp deleted file mode 100644 index 446b4b00a..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/emoticon.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -class EMOTICON : public COMPONENT -{ - void draw_circle(float x, float y, float r, int segments); - - bool was_active; - bool active; - - vec2 selector_mouse; - int selected_emote; - - static void con_key_emoticon(void *result, void *user_data); - static void con_emote(void *result, void *user_data); - -public: - EMOTICON(); - - virtual void on_reset(); - virtual void on_console_init(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); - virtual bool on_mousemove(float x, float y); - - void emote(int emoticon); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.cpp deleted file mode 100644 index b2f983e64..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include "flow.hpp" - -FLOW::FLOW() -{ - cells = 0; - height = 0; - width = 0; - spacing = 16; -} - -void FLOW::dbg_render() -{ - if(!cells) - return; - - gfx_texture_set(-1); - gfx_lines_begin(); - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - { - vec2 pos(x*spacing, y*spacing); - vec2 vel = cells[y*width+x].vel * 0.01f; - gfx_lines_draw(pos.x, pos.y, pos.x+vel.x, pos.y+vel.y); - } - - gfx_lines_end(); -} - -void FLOW::init() -{ - if(cells) - { - mem_free(cells); - cells = 0; - } - - MAPITEM_LAYER_TILEMAP *tilemap = layers_game_layer(); - width = tilemap->width*32/spacing; - height = tilemap->height*32/spacing; - - // allocate and clear - cells = (CELL *)mem_alloc(sizeof(CELL)*width*height, 1); - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - cells[y*width+x].vel = vec2(0.0f, 0.0f); -} - -void FLOW::update() -{ - if(!cells) - return; - - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - cells[y*width+x].vel *= 0.85f; -} - -vec2 FLOW::get(vec2 pos) -{ - if(!cells) - return vec2(0,0); - - int x = (int)(pos.x / spacing); - int y = (int)(pos.y / spacing); - if(x < 0 || y < 0 || x >= width || y >= height) - return vec2(0,0); - - return cells[y*width+x].vel; -} - -void FLOW::add(vec2 pos, vec2 vel, float size) -{ - if(!cells) - return; - - int x = (int)(pos.x / spacing); - int y = (int)(pos.y / spacing); - if(x < 0 || y < 0 || x >= width || y >= height) - return; - - cells[y*width+x].vel += vel; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.hpp deleted file mode 100644 index 351b1f69e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/flow.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -class FLOW : public COMPONENT -{ - struct CELL - { - vec2 vel; - }; - - CELL *cells; - int height; - int width; - int spacing; - - void dbg_render(); - void init(); -public: - FLOW(); - - vec2 get(vec2 pos); - void add(vec2 pos, vec2 vel, float size); - void update(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.cpp deleted file mode 100644 index b1926ab48..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.cpp +++ /dev/null @@ -1,307 +0,0 @@ -#include // memcmp - -#include -#include -#include - -#include - -#include -#include -#include - -#include "controls.hpp" -#include "camera.hpp" -#include "hud.hpp" -#include "voting.hpp" -#include "binds.hpp" - -HUD::HUD() -{ - -} - -void HUD::on_reset() -{ -} - -void HUD::render_goals() -{ - // TODO: split this up into these: - // render_gametimer - // render_suddendeath - // render_scorehud - // render_warmuptimer - - int gameflags = gameclient.snap.gameobj->flags; - - float whole = 300*gfx_screenaspect(); - float half = whole/2.0f; - - - gfx_mapscreen(0,0,300*gfx_screenaspect(),300); - if(!gameclient.snap.gameobj->sudden_death) - { - char buf[32]; - int time = 0; - if(gameclient.snap.gameobj->time_limit) - { - time = gameclient.snap.gameobj->time_limit*60 - ((client_tick()-gameclient.snap.gameobj->round_start_tick)/client_tickspeed()); - - if(gameclient.snap.gameobj->game_over) - time = 0; - } - else - time = (client_tick()-gameclient.snap.gameobj->round_start_tick)/client_tickspeed(); - - str_format(buf, sizeof(buf), "%d:%02d", time /60, time %60); - float w = gfx_text_width(0, 16, buf, -1); - gfx_text(0, half-w/2, 2, 16, buf, -1); - } - - if(gameclient.snap.gameobj->sudden_death) - { - const char *text = "Sudden Death"; - float w = gfx_text_width(0, 16, text, -1); - gfx_text(0, half-w/2, 2, 16, text, -1); - } - - // render small score hud - if(!(gameclient.snap.gameobj && gameclient.snap.gameobj->game_over) && (gameflags&GAMEFLAG_TEAMS)) - { - for(int t = 0; t < 2; t++) - { - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - if(t == 0) - gfx_setcolor(1,0,0,0.25f); - else - gfx_setcolor(0,0,1,0.25f); - draw_round_rect(whole-40, 300-40-15+t*20, 50, 18, 5.0f); - gfx_quads_end(); - - char buf[32]; - str_format(buf, sizeof(buf), "%d", t?gameclient.snap.gameobj->teamscore_blue:gameclient.snap.gameobj->teamscore_red); - float w = gfx_text_width(0, 14, buf, -1); - - if(gameflags&GAMEFLAG_FLAGS) - { - gfx_text(0, whole-20-w/2+5, 300-40-15+t*20, 14, buf, -1); - if(gameclient.snap.flags[t]) - { - if(gameclient.snap.flags[t]->carried_by == -2 || (gameclient.snap.flags[t]->carried_by == -1 && ((client_tick()/10)&1))) - { - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - if(t == 0) select_sprite(SPRITE_FLAG_RED); - else select_sprite(SPRITE_FLAG_BLUE); - - float size = 16; - gfx_quads_drawTL(whole-40+5, 300-40-15+t*20+1, size/2, size); - gfx_quads_end(); - } - else if(gameclient.snap.flags[t]->carried_by >= 0) - { - int id = gameclient.snap.flags[t]->carried_by%MAX_CLIENTS; - const char *name = gameclient.clients[id].name; - float w = gfx_text_width(0, 10, name, -1); - gfx_text(0, whole-40-5-w, 300-40-15+t*20+2, 10, name, -1); - TEE_RENDER_INFO info = gameclient.clients[id].render_info; - info.size = 18.0f; - - render_tee(ANIMSTATE::get_idle(), &info, EMOTE_NORMAL, vec2(1,0), - vec2(whole-40+10, 300-40-15+9+t*20+1)); - } - } - } - else - gfx_text(0, whole-20-w/2, 300-40-15+t*20, 14, buf, -1); - } - } - - // render warmup timer - if(gameclient.snap.gameobj->warmup) - { - char buf[256]; - float w = gfx_text_width(0, 24, "Warmup", -1); - gfx_text(0, 150*gfx_screenaspect()+-w/2, 50, 24, "Warmup", -1); - - int seconds = gameclient.snap.gameobj->warmup/SERVER_TICK_SPEED; - if(seconds < 5) - str_format(buf, sizeof(buf), "%d.%d", seconds, (gameclient.snap.gameobj->warmup*10/SERVER_TICK_SPEED)%10); - else - str_format(buf, sizeof(buf), "%d", seconds); - w = gfx_text_width(0, 24, buf, -1); - gfx_text(0, 150*gfx_screenaspect()+-w/2, 75, 24, buf, -1); - } -} - -static void mapscreen_to_group(float center_x, float center_y, MAPITEM_GROUP *group) -{ - float points[4]; - mapscreen_to_world(center_x, center_y, group->parallax_x/100.0f, group->parallax_y/100.0f, - group->offset_x, group->offset_y, gfx_screenaspect(), 1.0f, points); - gfx_mapscreen(points[0], points[1], points[2], points[3]); -} - -void HUD::render_fps() -{ - if(config.cl_showfps) - { - char buf[512]; - str_format(buf, sizeof(buf), "%d", (int)(1.0f/client_frametime())); - gfx_text(0, width-10-gfx_text_width(0,12,buf,-1), 5, 12, buf, -1); - } -} - -void HUD::render_connectionwarning() -{ - if(client_connection_problems()) - { - const char *text = "Connection Problems..."; - float w = gfx_text_width(0, 24, text, -1); - gfx_text(0, 150*gfx_screenaspect()-w/2, 50, 24, text, -1); - } -} - -void HUD::render_teambalancewarning() -{ - // render prompt about team-balance - bool flash = time_get()/(time_freq()/2)%2 == 0; - if (gameclient.snap.gameobj && (gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS) != 0) - { - if (config.cl_warning_teambalance && abs(gameclient.snap.team_size[0]-gameclient.snap.team_size[1]) >= 2) - { - const char *text = "Please balance teams!"; - if(flash) - gfx_text_color(1,1,0.5f,1); - else - gfx_text_color(0.7f,0.7f,0.2f,1.0f); - gfx_text(0x0, 5, 50, 6, text, -1); - gfx_text_color(1,1,1,1); - } - } -} - - -void HUD::render_voting() -{ - if(!gameclient.voting->is_voting()) - return; - - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.40f); - draw_round_rect(-10, 60-2, 100+10+4+5, 28, 5.0f); - gfx_quads_end(); - - gfx_text_color(1,1,1,1); - - char buf[512]; - gfx_text(0x0, 5, 60, 6, gameclient.voting->vote_description(), -1); - - str_format(buf, sizeof(buf), "%ds left", gameclient.voting->seconds_left()); - float tw = gfx_text_width(0x0, 6, buf, -1); - gfx_text(0x0, 5+100-tw, 60, 6, buf, -1); - - - RECT base = {5, 70, 100, 4}; - gameclient.voting->render_bars(base, false); - - const char *yes_key = gameclient.binds->get_key("vote yes"); - const char *no_key = gameclient.binds->get_key("vote no"); - str_format(buf, sizeof(buf), "%s - Vote Yes", yes_key); - base.y += base.h+1; - ui_do_label(&base, buf, 6.0f, -1); - - str_format(buf, sizeof(buf), "Vote No - %s", no_key); - ui_do_label(&base, buf, 6.0f, 1); -} - -void HUD::render_cursor() -{ - if(!gameclient.snap.local_character) - return; - - mapscreen_to_group(gameclient.camera->center.x, gameclient.camera->center.y, layers_game_group()); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - // render cursor - select_sprite(data->weapons.id[gameclient.snap.local_character->weapon%NUM_WEAPONS].sprite_cursor); - float cursorsize = 64; - draw_sprite(gameclient.controls->target_pos.x, gameclient.controls->target_pos.y, cursorsize); - gfx_quads_end(); -} - -void HUD::render_healthandammo() -{ - //mapscreen_to_group(gacenter_x, center_y, layers_game_group()); - - float x = 5; - float y = 5; - - // render ammo count - // render gui stuff - - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_mapscreen(0,0,width,300); - - gfx_quads_begin(); - - // if weaponstage is active, put a "glow" around the stage ammo - select_sprite(data->weapons.id[gameclient.snap.local_character->weapon%NUM_WEAPONS].sprite_proj); - for (int i = 0; i < min(gameclient.snap.local_character->ammocount, 10); i++) - gfx_quads_drawTL(x+i*12,y+24,10,10); - - gfx_quads_end(); - - gfx_quads_begin(); - int h = 0; - - // render health - select_sprite(SPRITE_HEALTH_FULL); - for(; h < gameclient.snap.local_character->health; h++) - gfx_quads_drawTL(x+h*12,y,10,10); - - select_sprite(SPRITE_HEALTH_EMPTY); - for(; h < 10; h++) - gfx_quads_drawTL(x+h*12,y,10,10); - - // render armor meter - h = 0; - select_sprite(SPRITE_ARMOR_FULL); - for(; h < gameclient.snap.local_character->armor; h++) - gfx_quads_drawTL(x+h*12,y+12,10,10); - - select_sprite(SPRITE_ARMOR_EMPTY); - for(; h < 10; h++) - gfx_quads_drawTL(x+h*12,y+12,10,10); - gfx_quads_end(); -} - -void HUD::on_render() -{ - if(!gameclient.snap.gameobj) - return; - - width = 300*gfx_screenaspect(); - - bool spectate = false; - if(gameclient.snap.local_info && gameclient.snap.local_info->team == -1) - spectate = true; - - if(gameclient.snap.local_character && !spectate && !(gameclient.snap.gameobj && gameclient.snap.gameobj->game_over)) - render_healthandammo(); - - render_goals(); - render_fps(); - if(client_state() != CLIENTSTATE_DEMOPLAYBACK) - render_connectionwarning(); - render_teambalancewarning(); - render_voting(); - render_cursor(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.hpp deleted file mode 100644 index 41fa0ff29..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/hud.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -class HUD : public COMPONENT -{ - float width; - - void render_cursor(); - - void render_fps(); - void render_connectionwarning(); - void render_teambalancewarning(); - void render_voting(); - void render_healthandammo(); - void render_goals(); - -public: - HUD(); - - virtual void on_reset(); - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.cpp deleted file mode 100644 index 1d579619d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include -#include -#include - -#include // get_angle -#include -#include -#include - -#include -#include - -#include "items.hpp" - -void ITEMS::render_projectile(const NETOBJ_PROJECTILE *current, int itemid) -{ - - // get positions - float curvature = 0; - float speed = 0; - if(current->type == WEAPON_GRENADE) - { - curvature = gameclient.tuning.grenade_curvature; - speed = gameclient.tuning.grenade_speed; - } - else if(current->type == WEAPON_SHOTGUN) - { - curvature = gameclient.tuning.shotgun_curvature; - speed = gameclient.tuning.shotgun_speed; - } - else if(current->type == WEAPON_GUN) - { - curvature = gameclient.tuning.gun_curvature; - speed = gameclient.tuning.gun_speed; - } - - float ct = (client_prevtick()-current->start_tick)/(float)SERVER_TICK_SPEED + client_ticktime(); - if(ct < 0) - return; // projectile havn't been shot yet - - vec2 startpos(current->x, current->y); - vec2 startvel(current->vx/100.0f, current->vy/100.0f); - vec2 pos = calc_pos(startpos, startvel, curvature, speed, ct); - vec2 prevpos = calc_pos(startpos, startvel, curvature, speed, ct-0.001f); - - - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - select_sprite(data->weapons.id[clamp(current->type, 0, NUM_WEAPONS-1)].sprite_proj); - vec2 vel = pos-prevpos; - //vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); - - - // add particle for this projectile - if(current->type == WEAPON_GRENADE) - { - gameclient.effects->smoketrail(pos, vel*-1); - gameclient.flow->add(pos, vel*1000*client_frametime(), 10.0f); - gfx_quads_setrotation(client_localtime()*pi*2*2 + itemid); - } - else - { - gameclient.effects->bullettrail(pos); - gameclient.flow->add(pos, vel*1000*client_frametime(), 10.0f); - - if(length(vel) > 0.00001f) - gfx_quads_setrotation(get_angle(vel)); - else - gfx_quads_setrotation(0); - - } - - gfx_quads_draw(pos.x, pos.y, 32, 32); - gfx_quads_setrotation(0); - gfx_quads_end(); -} - -void ITEMS::render_pickup(const NETOBJ_PICKUP *prev, const NETOBJ_PICKUP *current) -{ - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); - float angle = 0.0f; - float size = 64.0f; - if (current->type == POWERUP_WEAPON) - { - angle = 0; //-pi/6;//-0.25f * pi * 2.0f; - select_sprite(data->weapons.id[clamp(current->subtype, 0, NUM_WEAPONS-1)].sprite_body); - size = data->weapons.id[clamp(current->subtype, 0, NUM_WEAPONS-1)].visual_size; - } - else - { - const int c[] = { - SPRITE_PICKUP_HEALTH, - SPRITE_PICKUP_ARMOR, - SPRITE_PICKUP_WEAPON, - SPRITE_PICKUP_NINJA - }; - select_sprite(c[current->type]); - - if(c[current->type] == SPRITE_PICKUP_NINJA) - { - gameclient.effects->powerupshine(pos, vec2(96,18)); - size *= 2.0f; - pos.x += 10.0f; - } - } - - gfx_quads_setrotation(angle); - - float offset = pos.y/32.0f + pos.x/32.0f; - pos.x += cosf(client_localtime()*2.0f+offset)*2.5f; - pos.y += sinf(client_localtime()*2.0f+offset)*2.5f; - draw_sprite(pos.x, pos.y, size); - gfx_quads_end(); -} - -void ITEMS::render_flag(const NETOBJ_FLAG *prev, const NETOBJ_FLAG *current) -{ - float angle = 0.0f; - float size = 42.0f; - - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - if(current->team == 0) // red team - select_sprite(SPRITE_FLAG_RED); - else - select_sprite(SPRITE_FLAG_BLUE); - - gfx_quads_setrotation(angle); - - vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); - - // make sure that the flag isn't interpolated between capture and return - if(prev->carried_by != current->carried_by) - pos = vec2(current->x, current->y); - - // make sure to use predicted position if we are the carrier - if(gameclient.snap.local_info && current->carried_by == gameclient.snap.local_info->cid) - pos = gameclient.local_character_pos; - - gfx_quads_draw(pos.x, pos.y-size*0.75f, size, size*2); - gfx_quads_end(); -} - - -void ITEMS::render_laser(const struct NETOBJ_LASER *current) -{ - vec2 pos = vec2(current->x, current->y); - vec2 from = vec2(current->from_x, current->from_y); - vec2 dir = normalize(pos-from); - - float ticks = client_tick() + client_intratick() - current->start_tick; - float ms = (ticks/50.0f) * 1000.0f; - float a = ms / gameclient.tuning.laser_bounce_delay; - a = clamp(a, 0.0f, 1.0f); - float ia = 1-a; - - vec2 out, border; - - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - - //vec4 inner_color(0.15f,0.35f,0.75f,1.0f); - //vec4 outer_color(0.65f,0.85f,1.0f,1.0f); - - // do outline - vec4 outer_color(0.075f,0.075f,0.25f,1.0f); - gfx_setcolor(outer_color.r,outer_color.g,outer_color.b,1.0f); - out = vec2(dir.y, -dir.x) * (7.0f*ia); - - gfx_quads_draw_freeform( - from.x-out.x, from.y-out.y, - from.x+out.x, from.y+out.y, - pos.x-out.x, pos.y-out.y, - pos.x+out.x, pos.y+out.y - ); - - // do inner - vec4 inner_color(0.5f,0.5f,1.0f,1.0f); - out = vec2(dir.y, -dir.x) * (5.0f*ia); - gfx_setcolor(inner_color.r, inner_color.g, inner_color.b, 1.0f); // center - - gfx_quads_draw_freeform( - from.x-out.x, from.y-out.y, - from.x+out.x, from.y+out.y, - pos.x-out.x, pos.y-out.y, - pos.x+out.x, pos.y+out.y - ); - - gfx_quads_end(); - - // render head - { - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_PARTICLES].id); - gfx_quads_begin(); - - int sprites[] = {SPRITE_PART_SPLAT01, SPRITE_PART_SPLAT02, SPRITE_PART_SPLAT03}; - select_sprite(sprites[client_tick()%3]); - gfx_quads_setrotation(client_tick()); - gfx_setcolor(outer_color.r,outer_color.g,outer_color.b,1.0f); - gfx_quads_draw(pos.x, pos.y, 24,24); - gfx_setcolor(inner_color.r, inner_color.g, inner_color.b, 1.0f); - gfx_quads_draw(pos.x, pos.y, 20,20); - gfx_quads_end(); - } - - gfx_blend_normal(); -} - -void ITEMS::on_render() -{ - int num = snap_num_items(SNAP_CURRENT); - for(int i = 0; i < num; i++) - { - SNAP_ITEM item; - const void *data = snap_get_item(SNAP_CURRENT, i, &item); - - if(item.type == NETOBJTYPE_PROJECTILE) - { - render_projectile((const NETOBJ_PROJECTILE *)data, item.id); - } - else if(item.type == NETOBJTYPE_PICKUP) - { - const void *prev = snap_find_item(SNAP_PREV, item.type, item.id); - if(prev) - render_pickup((const NETOBJ_PICKUP *)prev, (const NETOBJ_PICKUP *)data); - } - else if(item.type == NETOBJTYPE_LASER) - { - render_laser((const NETOBJ_LASER *)data); - } - else if(item.type == NETOBJTYPE_FLAG) - { - const void *prev = snap_find_item(SNAP_PREV, item.type, item.id); - if (prev) - render_flag((const NETOBJ_FLAG *)prev, (const NETOBJ_FLAG *)data); - } - } - - // render extra projectiles - /* - for(int i = 0; i < extraproj_num; i++) - { - if(extraproj_projectiles[i].start_tick < client_tick()) - { - extraproj_projectiles[i] = extraproj_projectiles[extraproj_num-1]; - extraproj_num--; - } - else - render_projectile(&extraproj_projectiles[i], 0); - }*/ -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.hpp deleted file mode 100644 index 2f33c8c4b..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/items.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -class ITEMS : public COMPONENT -{ - void render_projectile(const NETOBJ_PROJECTILE *current, int itemid); - void render_pickup(const NETOBJ_PICKUP *prev, const NETOBJ_PICKUP *current); - void render_flag(const NETOBJ_FLAG *prev, const NETOBJ_FLAG *current); - void render_laser(const struct NETOBJ_LASER *current); - -public: - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.cpp deleted file mode 100644 index 410f2c3d4..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include - -#include -#include -#include "killmessages.hpp" - -void KILLMESSAGES::on_reset() -{ - killmsg_current = 0; - for(int i = 0; i < killmsg_max; i++) - killmsgs[i].tick = -100000; -} - -void KILLMESSAGES::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_KILLMSG) - { - NETMSG_SV_KILLMSG *msg = (NETMSG_SV_KILLMSG *)rawmsg; - - // unpack messages - KILLMSG kill; - kill.killer = msg->killer; - kill.victim = msg->victim; - kill.weapon = msg->weapon; - kill.mode_special = msg->mode_special; - kill.tick = client_tick(); - - // add the message - killmsg_current = (killmsg_current+1)%killmsg_max; - killmsgs[killmsg_current] = kill; - } -} - -void KILLMESSAGES::on_render() -{ - float width = 400*3.0f*gfx_screenaspect(); - float height = 400*3.0f; - - gfx_mapscreen(0, 0, width*1.5f, height*1.5f); - float startx = width*1.5f-10.0f; - float y = 20.0f; - - for(int i = 0; i < killmsg_max; i++) - { - - int r = (killmsg_current+i+1)%killmsg_max; - if(client_tick() > killmsgs[r].tick+50*10) - continue; - - float font_size = 36.0f; - float killername_w = gfx_text_width(0, font_size, gameclient.clients[killmsgs[r].killer].name, -1); - float victimname_w = gfx_text_width(0, font_size, gameclient.clients[killmsgs[r].victim].name, -1); - - float x = startx; - - // render victim name - x -= victimname_w; - gfx_text(0, x, y, font_size, gameclient.clients[killmsgs[r].victim].name, -1); - - // render victim tee - x -= 24.0f; - - if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_FLAGS) - { - if(killmsgs[r].mode_special&1) - { - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - if(gameclient.clients[killmsgs[r].victim].team == 0) select_sprite(SPRITE_FLAG_BLUE); - else select_sprite(SPRITE_FLAG_RED); - - float size = 56.0f; - gfx_quads_drawTL(x, y-16, size/2, size); - gfx_quads_end(); - } - } - - render_tee(ANIMSTATE::get_idle(), &gameclient.clients[killmsgs[r].victim].render_info, EMOTE_PAIN, vec2(-1,0), vec2(x, y+28)); - x -= 32.0f; - - // render weapon - x -= 44.0f; - if (killmsgs[r].weapon >= 0) - { - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - select_sprite(data->weapons.id[killmsgs[r].weapon].sprite_body); - draw_sprite(x, y+28, 96); - gfx_quads_end(); - } - x -= 52.0f; - - if(killmsgs[r].victim != killmsgs[r].killer) - { - if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_FLAGS) - { - if(killmsgs[r].mode_special&2) - { - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - if(gameclient.clients[killmsgs[r].killer].team == 0) select_sprite(SPRITE_FLAG_BLUE, SPRITE_FLAG_FLIP_X); - else select_sprite(SPRITE_FLAG_RED, SPRITE_FLAG_FLIP_X); - - float size = 56.0f; - gfx_quads_drawTL(x-56, y-16, size/2, size); - gfx_quads_end(); - } - } - - // render killer tee - x -= 24.0f; - render_tee(ANIMSTATE::get_idle(), &gameclient.clients[killmsgs[r].killer].render_info, EMOTE_ANGRY, vec2(1,0), vec2(x, y+28)); - x -= 32.0f; - - // render killer name - x -= killername_w; - gfx_text(0, x, y, font_size, gameclient.clients[killmsgs[r].killer].name, -1); - } - - y += 44; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.hpp deleted file mode 100644 index f29e0bdf9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/killmessages.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -class KILLMESSAGES : public COMPONENT -{ -public: - // kill messages - struct KILLMSG - { - int weapon; - int victim; - int killer; - int mode_special; // for CTF, if the guy is carrying a flag for example - int tick; - }; - - static const int killmsg_max = 5; - KILLMSG killmsgs[killmsg_max]; - int killmsg_current; - - virtual void on_reset(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.cpp deleted file mode 100644 index 7f839da05..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -#include "mapimages.hpp" - -MAPIMAGES::MAPIMAGES() -{ - count = 0; -} - -void MAPIMAGES::on_mapload() -{ - // unload all textures - for(int i = 0; i < count; i++) - { - gfx_unload_texture(textures[i]); - textures[i] = -1; - } - count = 0; - - int start; - map_get_type(MAPITEMTYPE_IMAGE, &start, &count); - - // load new textures - for(int i = 0; i < count; i++) - { - textures[i] = 0; - - MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0); - if(img->external) - { - char buf[256]; - char *name = (char *)map_get_data(img->image_name); - str_format(buf, sizeof(buf), "mapres/%s.png", name); - textures[i] = gfx_load_texture(buf, IMG_AUTO, 0); - } - else - { - void *data = map_get_data(img->image_data); - textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0); - map_unload_data(img->image_data); - } - } -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.hpp deleted file mode 100644 index cba460332..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/mapimages.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -class MAPIMAGES : public COMPONENT -{ - int textures[64]; - int count; -public: - MAPIMAGES(); - - int get(int index) const { return textures[index]; } - int num() const { return count; } - - virtual void on_mapload(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.cpp deleted file mode 100644 index 847350e62..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -#include "maplayers.hpp" - -MAPLAYERS::MAPLAYERS(int t) -{ - type = t; -} - - -static void mapscreen_to_group(float center_x, float center_y, MAPITEM_GROUP *group) -{ - float points[4]; - mapscreen_to_world(center_x, center_y, group->parallax_x/100.0f, group->parallax_y/100.0f, - group->offset_x, group->offset_y, gfx_screenaspect(), 1.0f, points); - gfx_mapscreen(points[0], points[1], points[2], points[3]); -} - -static void envelope_eval(float time_offset, int env, float *channels) -{ - channels[0] = 0; - channels[1] = 0; - channels[2] = 0; - channels[3] = 0; - - ENVPOINT *points; - - { - int start, num; - map_get_type(MAPITEMTYPE_ENVPOINTS, &start, &num); - if(num) - points = (ENVPOINT *)map_get_item(start, 0, 0); - } - - int start, num; - map_get_type(MAPITEMTYPE_ENVELOPE, &start, &num); - - if(env >= num) - return; - - MAPITEM_ENVELOPE *item = (MAPITEM_ENVELOPE *)map_get_item(start+env, 0, 0); - render_eval_envelope(points+item->start_point, item->num_points, 4, client_localtime()+time_offset, channels); -} - -void MAPLAYERS::on_render() -{ - if(client_state() != CLIENTSTATE_ONLINE && client_state() != CLIENTSTATE_DEMOPLAYBACK) - return; - - RECT screen; - gfx_getscreen(&screen.x, &screen.y, &screen.w, &screen.h); - - vec2 center = gameclient.camera->center; - //float center_x = gameclient.camera->center.x; - //float center_y = gameclient.camera->center.y; - - bool passed_gamelayer = false; - - for(int g = 0; g < layers_num_groups(); g++) - { - MAPITEM_GROUP *group = layers_get_group(g); - - if(!config.gfx_noclip && group->version >= 2 && group->use_clipping) - { - // set clipping - float points[4]; - mapscreen_to_group(center.x, center.y, layers_game_group()); - gfx_getscreen(&points[0], &points[1], &points[2], &points[3]); - float x0 = (group->clip_x - points[0]) / (points[2]-points[0]); - float y0 = (group->clip_y - points[1]) / (points[3]-points[1]); - float x1 = ((group->clip_x+group->clip_w) - points[0]) / (points[2]-points[0]); - float y1 = ((group->clip_y+group->clip_h) - points[1]) / (points[3]-points[1]); - - gfx_clip_enable((int)(x0*gfx_screenwidth()), (int)(y0*gfx_screenheight()), - (int)((x1-x0)*gfx_screenwidth()), (int)((y1-y0)*gfx_screenheight())); - } - - mapscreen_to_group(center.x, center.y, group); - - for(int l = 0; l < group->num_layers; l++) - { - MAPITEM_LAYER *layer = layers_get_layer(group->start_layer+l); - bool render = false; - bool is_game_layer = false; - - if(layer == (MAPITEM_LAYER*)layers_game_layer()) - { - is_game_layer = true; - passed_gamelayer = 1; - } - - // skip rendering if detail layers if not wanted - if(layer->flags&LAYERFLAG_DETAIL && !config.gfx_high_detail && !is_game_layer) - continue; - - if(type == -1) - render = true; - else if(type == 0) - { - if(passed_gamelayer) - return; - render = true; - } - else - { - if(passed_gamelayer && !is_game_layer) - render = true; - } - - if(render && !is_game_layer) - { - //layershot_begin(); - - if(layer->type == LAYERTYPE_TILES) - { - MAPITEM_LAYER_TILEMAP *tmap = (MAPITEM_LAYER_TILEMAP *)layer; - if(tmap->image == -1) - gfx_texture_set(-1); - else - gfx_texture_set(gameclient.mapimages->get(tmap->image)); - - TILE *tiles = (TILE *)map_get_data(tmap->data); - gfx_blend_none(); - render_tilemap(tiles, tmap->width, tmap->height, 32.0f, vec4(1,1,1,1), TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE); - gfx_blend_normal(); - render_tilemap(tiles, tmap->width, tmap->height, 32.0f, vec4(1,1,1,1), TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); - } - else if(layer->type == LAYERTYPE_QUADS) - { - MAPITEM_LAYER_QUADS *qlayer = (MAPITEM_LAYER_QUADS *)layer; - if(qlayer->image == -1) - gfx_texture_set(-1); - else - gfx_texture_set(gameclient.mapimages->get(qlayer->image)); - - QUAD *quads = (QUAD *)map_get_data_swapped(qlayer->data); - - gfx_blend_none(); - render_quads(quads, qlayer->num_quads, envelope_eval, LAYERRENDERFLAG_OPAQUE); - gfx_blend_normal(); - render_quads(quads, qlayer->num_quads, envelope_eval, LAYERRENDERFLAG_TRANSPARENT); - } - - //layershot_end(); - } - } - if(!config.gfx_noclip) - gfx_clip_disable(); - } - - if(!config.gfx_noclip) - gfx_clip_disable(); - - // reset the screen like it was before - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.hpp deleted file mode 100644 index c2919f082..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/maplayers.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -class MAPLAYERS : public COMPONENT -{ - int type; -public: - enum - { - TYPE_BACKGROUND=0, - TYPE_FOREGROUND, - }; - - MAPLAYERS(int type); - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.cpp deleted file mode 100644 index 7d9e3b4cd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.cpp +++ /dev/null @@ -1,1145 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include - -#include -#include -#include - -#include "menus.hpp" -#include "skins.hpp" - -#include - -extern "C" { - #include -} - -#include -#include - -#include -#include -#include - -vec4 MENUS::gui_color; -vec4 MENUS::color_tabbar_inactive_outgame; -vec4 MENUS::color_tabbar_active_outgame; -vec4 MENUS::color_tabbar_inactive; -vec4 MENUS::color_tabbar_active; -vec4 MENUS::color_tabbar_inactive_ingame; -vec4 MENUS::color_tabbar_active_ingame; - - -float MENUS::button_height = 25.0f; -float MENUS::listheader_height = 17.0f; -float MENUS::fontmod_height = 0.8f; - -INPUT_EVENT MENUS::inputevents[MAX_INPUTEVENTS]; -int MENUS::num_inputevents; - -inline float hue_to_rgb(float v1, float v2, float h) -{ - if(h < 0) h += 1; - if(h > 1) h -= 1; - if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; - if((2 * h) < 1) return v2; - if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; - return v1; -} - -inline vec3 hsl_to_rgb(vec3 in) -{ - float v1, v2; - vec3 out; - - if(in.s == 0) - { - out.r = in.l; - out.g = in.l; - out.b = in.l; - } - else - { - if(in.l < 0.5f) - v2 = in.l * (1 + in.s); - else - v2 = (in.l+in.s) - (in.s*in.l); - - v1 = 2 * in.l - v2; - - out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f)); - out.g = hue_to_rgb(v1, v2, in.h); - out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f)); - } - - return out; -} - - -MENUS::MENUS() -{ - popup = POPUP_NONE; - active_page = PAGE_INTERNET; - game_page = PAGE_GAME; - - need_restart = false; - need_sendinfo = false; - menu_active = true; - - escape_pressed = false; - enter_pressed = false; - num_inputevents = 0; - - demos = 0; - num_demos = 0; - - last_input = time_get(); -} - -vec4 MENUS::button_color_mul(const void *id) -{ - if(ui_active_item() == id) - return vec4(1,1,1,0.5f); - else if(ui_hot_item() == id) - return vec4(1,1,1,1.5f); - return vec4(1,1,1,1); -} - -void MENUS::ui_draw_browse_icon(int what, const RECT *r) -{ - gfx_texture_set(data->images[IMAGE_BROWSEICONS].id); - gfx_quads_begin(); - select_sprite(what); - gfx_quads_drawTL(r->x,r->y,r->w,r->h); - gfx_quads_end(); -} - - -void MENUS::ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); - ui_do_label(r, text, r->h*fontmod_height, 0); -} - -void MENUS::ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - ui_draw_rect(r, vec4(1,1,1,0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); - ui_do_label(r, text, r->h*fontmod_height, 0); -} - -void MENUS::ui_draw_menu_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - int corners = CORNER_T; - vec4 colormod(1,1,1,1); - if(extra) - corners = *(int *)extra; - - if(checked) - ui_draw_rect(r, color_tabbar_active, corners, 10.0f); - else - ui_draw_rect(r, color_tabbar_inactive, corners, 10.0f); - ui_do_label(r, text, r->h*fontmod_height, 0); -} - - -void MENUS::ui_draw_settings_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(checked) - ui_draw_rect(r, color_tabbar_active, CORNER_R, 10.0f); - else - ui_draw_rect(r, color_tabbar_inactive, CORNER_R, 10.0f); - ui_do_label(r, text, r->h*fontmod_height, 0); -} - -void MENUS::ui_draw_grid_header(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(checked) - ui_draw_rect(r, vec4(1,1,1,0.5f), CORNER_T, 5.0f); - RECT t; - ui_vsplit_l(r, 5.0f, 0, &t); - ui_do_label(&t, text, r->h*fontmod_height, -1); -} - -void MENUS::ui_draw_list_row(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(checked) - { - RECT sr = *r; - ui_margin(&sr, 1.5f, &sr); - ui_draw_rect(&sr, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f); - } - ui_do_label(r, text, r->h*fontmod_height, -1); -} - -void MENUS::ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const RECT *r) -{ - RECT c = *r; - RECT t = *r; - c.w = c.h; - t.x += c.w; - t.w -= c.w; - ui_vsplit_l(&t, 5.0f, 0, &t); - - ui_margin(&c, 2.0f, &c); - ui_draw_rect(&c, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 3.0f); - c.y += 2; - ui_do_label(&c, boxtext, r->h*fontmod_height*0.75f, 0); - ui_do_label(&t, text, r->h*fontmod_height*0.8f, -1); -} - -void MENUS::ui_draw_checkbox(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - ui_draw_checkbox_common(id, text, checked?"X":"", r); -} - - -void MENUS::ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - char buf[16]; - str_format(buf, sizeof(buf), "%d", checked); - ui_draw_checkbox_common(id, text, buf, r); -} - -int MENUS::ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden) -{ - int inside = ui_mouse_inside(rect); - int r = 0; - static int at_index = 0; - - if(ui_last_active_item() == id) - { - int len = strlen(str); - - if (inside && ui_mouse_button(0)) - { - int mx_rel = (int)(ui_mouse_x() - rect->x); - - for (int i = 1; i <= len; i++) - { - if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel) - { - at_index = i - 1; - break; - } - - if (i == len) - at_index = len; - } - } - - for(int i = 0; i < num_inputevents; i++) - { - len = strlen(str); - INPUT_EVENT e = inputevents[i]; - char c = e.ch; - int k = e.key; - - if (at_index > len) - at_index = len; - - if (!(c >= 0 && c < 32) && c != 127) - { - if (len < str_size - 1 && at_index < str_size - 1) - { - memmove(str + at_index + 1, str + at_index, len - at_index + 1); - str[at_index] = c; - at_index++; - r = 1; - } - } - - if(e.flags&INPFLAG_PRESS) - { - if (k == KEY_BACKSPACE && at_index > 0) - { - memmove(str + at_index - 1, str + at_index, len - at_index + 1); - at_index--; - r = 1; - } - else if (k == KEY_DELETE && at_index < len) - { - memmove(str + at_index, str + at_index + 1, len - at_index); - r = 1; - } - else if (k == KEY_RETURN) - ui_clear_last_active_item(); - else if (k == KEY_LEFT && at_index > 0) - at_index--; - else if (k == KEY_RIGHT && at_index < len) - at_index++; - else if (k == KEY_HOME) - at_index = 0; - else if (k == KEY_END) - at_index = len; - } - } - } - - bool just_got_active = false; - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - if (ui_last_active_item() != id) - just_got_active = true; - ui_set_active_item(id); - } - } - - if(inside) - ui_set_hot_item(id); - - RECT textbox = *rect; - ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); - ui_vmargin(&textbox, 5.0f, &textbox); - - const char *display_str = str; - char stars[128]; - - if(hidden) - { - unsigned s = strlen(str); - if(s >= sizeof(stars)) - s = sizeof(stars)-1; - memset(stars, '*', s); - stars[s] = 0; - display_str = stars; - } - - ui_do_label(&textbox, display_str, font_size, -1); - - if (ui_last_active_item() == id && !just_got_active) - { - float w = gfx_text_width(0, font_size, display_str, at_index); - textbox.x += w*ui_scale(); - ui_do_label(&textbox, "_", font_size, -1); - } - - return r; -} - -float MENUS::ui_do_scrollbar_v(const void *id, const RECT *rect, float current) -{ - RECT handle; - static float offset_y; - ui_hsplit_t(rect, 33, &handle, 0); - - handle.y += (rect->h-handle.h)*current; - - /* logic */ - float ret = current; - int inside = ui_mouse_inside(&handle); - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - - float min = rect->y; - float max = rect->h-handle.h; - float cur = ui_mouse_y()-offset_y; - ret = (cur-min)/max; - if(ret < 0.0f) ret = 0.0f; - if(ret > 1.0f) ret = 1.0f; - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - ui_set_active_item(id); - offset_y = ui_mouse_y()-handle.y; - } - } - - if(inside) - ui_set_hot_item(id); - - // render - RECT rail; - ui_vmargin(rect, 5.0f, &rail); - ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f); - - RECT slider = handle; - slider.w = rail.x-slider.x; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_L, 2.5f); - slider.x = rail.x+rail.w; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_R, 2.5f); - - slider = handle; - ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); - - return ret; -} - - - -float MENUS::ui_do_scrollbar_h(const void *id, const RECT *rect, float current) -{ - RECT handle; - static float offset_x; - ui_vsplit_l(rect, 33, &handle, 0); - - handle.x += (rect->w-handle.w)*current; - - /* logic */ - float ret = current; - int inside = ui_mouse_inside(&handle); - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - - float min = rect->x; - float max = rect->w-handle.w; - float cur = ui_mouse_x()-offset_x; - ret = (cur-min)/max; - if(ret < 0.0f) ret = 0.0f; - if(ret > 1.0f) ret = 1.0f; - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - ui_set_active_item(id); - offset_x = ui_mouse_x()-handle.x; - } - } - - if(inside) - ui_set_hot_item(id); - - // render - RECT rail; - ui_hmargin(rect, 5.0f, &rail); - ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f); - - RECT slider = handle; - slider.h = rail.y-slider.y; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_T, 2.5f); - slider.y = rail.y+rail.h; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_B, 2.5f); - - slider = handle; - ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); - - return ret; -} - -int MENUS::ui_do_key_reader(void *id, const RECT *rect, int key) -{ - // process - static void *grabbed_id = 0; - static bool mouse_released = true; - int inside = ui_mouse_inside(rect); - int new_key = key; - - if(!ui_mouse_button(0) && grabbed_id == id) - mouse_released = true; - - if(ui_active_item() == id) - { - if(binder.got_key) - { - new_key = binder.key.key; - binder.got_key = false; - ui_set_active_item(0); - mouse_released = false; - grabbed_id = id; - } - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0) && mouse_released) - { - binder.take_key = true; - binder.got_key = false; - ui_set_active_item(id); - } - } - - if(inside) - ui_set_hot_item(id); - - // draw - if (ui_active_item() == id) - ui_draw_keyselect_button(id, "???", 0, rect, 0); - else - { - if(key == 0) - ui_draw_keyselect_button(id, "", 0, rect, 0); - else - ui_draw_keyselect_button(id, inp_key_name(key), 0, rect, 0); - } - return new_key; -} - - -int MENUS::render_menubar(RECT r) -{ - RECT box = r; - RECT button; - - int active_page = config.ui_page; - int new_page = -1; - - if(client_state() != CLIENTSTATE_OFFLINE) - active_page = game_page; - - if(client_state() == CLIENTSTATE_OFFLINE) - { - /* offline menus */ - if(0) // this is not done yet - { - ui_vsplit_l(&box, 90.0f, &button, &box); - static int news_button=0; - if (ui_do_button(&news_button, "News", active_page==PAGE_NEWS, &button, ui_draw_menu_tab_button, 0)) - new_page = PAGE_NEWS; - ui_vsplit_l(&box, 30.0f, 0, &box); - } - - ui_vsplit_l(&box, 100.0f, &button, &box); - static int internet_button=0; - int corners = CORNER_TL; - if (ui_do_button(&internet_button, "Internet", active_page==PAGE_INTERNET, &button, ui_draw_menu_tab_button, &corners)) - { - client_serverbrowse_refresh(BROWSETYPE_INTERNET); - new_page = PAGE_INTERNET; - } - - //ui_vsplit_l(&box, 4.0f, 0, &box); - ui_vsplit_l(&box, 80.0f, &button, &box); - static int lan_button=0; - corners = 0; - if (ui_do_button(&lan_button, "LAN", active_page==PAGE_LAN, &button, ui_draw_menu_tab_button, &corners)) - { - client_serverbrowse_refresh(BROWSETYPE_LAN); - new_page = PAGE_LAN; - } - - //ui_vsplit_l(&box, 4.0f, 0, &box); - ui_vsplit_l(&box, 110.0f, &button, &box); - static int favorites_button=0; - corners = CORNER_TR; - if (ui_do_button(&favorites_button, "Favorites", active_page==PAGE_FAVORITES, &button, ui_draw_menu_tab_button, &corners)) - { - client_serverbrowse_refresh(BROWSETYPE_FAVORITES); - new_page = PAGE_FAVORITES; - } - - ui_vsplit_l(&box, 4.0f*5, 0, &box); - ui_vsplit_l(&box, 100.0f, &button, &box); - static int demos_button=0; - if (ui_do_button(&demos_button, "Demos", active_page==PAGE_DEMOS, &button, ui_draw_menu_tab_button, 0)) - { - demolist_populate(); - new_page = PAGE_DEMOS; - } - } - else - { - /* online menus */ - ui_vsplit_l(&box, 90.0f, &button, &box); - static int game_button=0; - if (ui_do_button(&game_button, "Game", active_page==PAGE_GAME, &button, ui_draw_menu_tab_button, 0)) - new_page = PAGE_GAME; - - ui_vsplit_l(&box, 4.0f, 0, &box); - ui_vsplit_l(&box, 140.0f, &button, &box); - static int server_info_button=0; - if (ui_do_button(&server_info_button, "Server Info", active_page==PAGE_SERVER_INFO, &button, ui_draw_menu_tab_button, 0)) - new_page = PAGE_SERVER_INFO; - - ui_vsplit_l(&box, 4.0f, 0, &box); - ui_vsplit_l(&box, 140.0f, &button, &box); - static int callvote_button=0; - if (ui_do_button(&callvote_button, "Call Vote", active_page==PAGE_CALLVOTE, &button, ui_draw_menu_tab_button, 0)) - new_page = PAGE_CALLVOTE; - - ui_vsplit_l(&box, 30.0f, 0, &box); - } - - /* - ui_vsplit_r(&box, 110.0f, &box, &button); - static int system_button=0; - if (ui_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui_draw_menu_tab_button, 0)) - config.ui_page = PAGE_SYSTEM; - - ui_vsplit_r(&box, 30.0f, &box, 0); - */ - - ui_vsplit_r(&box, 90.0f, &box, &button); - static int quit_button=0; - if (ui_do_button(&quit_button, "Quit", 0, &button, ui_draw_menu_tab_button, 0)) - popup = POPUP_QUIT; - - ui_vsplit_r(&box, 10.0f, &box, &button); - ui_vsplit_r(&box, 120.0f, &box, &button); - static int settings_button=0; - if (ui_do_button(&settings_button, "Settings", active_page==PAGE_SETTINGS, &button, ui_draw_menu_tab_button, 0)) - new_page = PAGE_SETTINGS; - - if(new_page != -1) - { - if(client_state() == CLIENTSTATE_OFFLINE) - config.ui_page = new_page; - else - game_page = new_page; - } - - return 0; -} - -void MENUS::render_loading(float percent) -{ - // need up date this here to get correct - vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f)); - gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f); - - RECT screen = *ui_screen(); - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - - render_background(); - - float tw; - - float w = 700; - float h = 200; - float x = screen.w/2-w/2; - float y = screen.h/2-h/2; - - gfx_blend_normal(); - - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.50f); - draw_round_rect(x, y, w, h, 40.0f); - gfx_quads_end(); - - - const char *caption = "Loading"; - - tw = gfx_text_width(0, 48.0f, caption, -1); - RECT r; - r.x = x; - r.y = y+20; - r.w = w; - r.h = h; - ui_do_label(&r, caption, 48.0f, 0, -1); - - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(1,1,1,0.75f); - draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f); - gfx_quads_end(); - - gfx_swap(); -} - -void MENUS::render_news(RECT main_view) -{ - ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f); -} - -void MENUS::init() -{ - if(config.cl_show_welcome) - popup = POPUP_FIRST_LAUNCH; - config.cl_show_welcome = 0; -} - -int MENUS::render() -{ - RECT screen = *ui_screen(); - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - - static bool first = true; - if(first) - { - if(config.ui_page == PAGE_INTERNET) - client_serverbrowse_refresh(0); - else if(config.ui_page == PAGE_LAN) - client_serverbrowse_refresh(1); - first = false; - } - - if(client_state() == CLIENTSTATE_ONLINE) - { - color_tabbar_inactive = color_tabbar_inactive_ingame; - color_tabbar_active = color_tabbar_active_ingame; - } - else - { - render_background(); - color_tabbar_inactive = color_tabbar_inactive_outgame; - color_tabbar_active = color_tabbar_active_outgame; - } - - RECT tab_bar; - RECT main_view; - - // some margin around the screen - ui_margin(&screen, 10.0f, &screen); - - if(popup == POPUP_NONE) - { - // do tab bar - ui_hsplit_t(&screen, 24.0f, &tab_bar, &main_view); - ui_vmargin(&tab_bar, 20.0f, &tab_bar); - render_menubar(tab_bar); - - // news is not implemented yet - if(config.ui_page <= PAGE_NEWS || config.ui_page > PAGE_SETTINGS || (client_state() == CLIENTSTATE_OFFLINE && config.ui_page >= PAGE_GAME && config.ui_page <= PAGE_CALLVOTE)) - { - client_serverbrowse_refresh(BROWSETYPE_INTERNET); - config.ui_page = PAGE_INTERNET; - } - - // render current page - if(client_state() != CLIENTSTATE_OFFLINE) - { - if(game_page == PAGE_GAME) - render_game(main_view); - else if(game_page == PAGE_SERVER_INFO) - render_serverinfo(main_view); - else if(game_page == PAGE_CALLVOTE) - render_servercontrol(main_view); - else if(game_page == PAGE_SETTINGS) - render_settings(main_view); - } - else if(config.ui_page == PAGE_NEWS) - render_news(main_view); - else if(config.ui_page == PAGE_INTERNET) - render_serverbrowser(main_view); - else if(config.ui_page == PAGE_LAN) - render_serverbrowser(main_view); - else if(config.ui_page == PAGE_DEMOS) - render_demolist(main_view); - else if(config.ui_page == PAGE_FAVORITES) - render_serverbrowser(main_view); - else if(config.ui_page == PAGE_SETTINGS) - render_settings(main_view); - } - else - { - // make sure that other windows doesn't do anything funnay! - //ui_set_hot_item(0); - //ui_set_active_item(0); - char buf[128]; - const char *title = ""; - const char *extra_text = ""; - const char *button_text = ""; - int extra_align = 0; - - if(popup == POPUP_CONNECTING) - { - title = "Connecting to"; - extra_text = config.ui_server_address; // TODO: query the client about the address - button_text = "Abort"; - if(client_mapdownload_totalsize() > 0) - { - title = "Downloading map"; - str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024); - extra_text = buf; - } - } - else if(popup == POPUP_DISCONNECTED) - { - title = "Disconnected"; - extra_text = client_error_string(); - button_text = "Ok"; - extra_align = -1; - } - else if(popup == POPUP_PURE) - { - title = "Disconnected"; - extra_text = "The server is running a non-standard tuning on a pure game mode."; - button_text = "Ok"; - extra_align = -1; - } - else if(popup == POPUP_PASSWORD) - { - title = "Password Error"; - extra_text = client_error_string(); - button_text = "Try Again"; - } - else if(popup == POPUP_QUIT) - { - title = "Quit"; - extra_text = "Are you sure that you want to quit?"; - } - else if(popup == POPUP_FIRST_LAUNCH) - { - title = "Welcome to Teeworlds"; - extra_text = - "As this is the first time you launch the game, please enter your nick name below. " - "It's recommended that you check the settings to adjust them to your liking " - "before joining a server."; - button_text = "Ok"; - extra_align = -1; - } - - RECT box, part; - box = screen; - ui_vmargin(&box, 150.0f, &box); - ui_hmargin(&box, 150.0f, &box); - - // render the box - ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f); - - ui_hsplit_t(&box, 20.f, &part, &box); - ui_hsplit_t(&box, 24.f, &part, &box); - ui_do_label(&part, title, 24.f, 0); - ui_hsplit_t(&box, 20.f, &part, &box); - ui_hsplit_t(&box, 24.f, &part, &box); - ui_vmargin(&part, 20.f, &part); - - if(extra_align == -1) - ui_do_label(&part, extra_text, 20.f, -1, (int)part.w); - else - ui_do_label(&part, extra_text, 20.f, 0, -1); - - if(popup == POPUP_QUIT) - { - RECT yes, no; - ui_hsplit_b(&box, 20.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - ui_vmargin(&part, 80.0f, &part); - - ui_vsplit_mid(&part, &no, &yes); - - ui_vmargin(&yes, 20.0f, &yes); - ui_vmargin(&no, 20.0f, &no); - - static int button_abort = 0; - if(ui_do_button(&button_abort, "No", 0, &no, ui_draw_menu_button, 0) || escape_pressed) - popup = POPUP_NONE; - - static int button_tryagain = 0; - if(ui_do_button(&button_tryagain, "Yes", 0, &yes, ui_draw_menu_button, 0) || enter_pressed) - client_quit(); - } - else if(popup == POPUP_PASSWORD) - { - RECT label, textbox, tryagain, abort; - - ui_hsplit_b(&box, 20.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - ui_vmargin(&part, 80.0f, &part); - - ui_vsplit_mid(&part, &abort, &tryagain); - - ui_vmargin(&tryagain, 20.0f, &tryagain); - ui_vmargin(&abort, 20.0f, &abort); - - static int button_abort = 0; - if(ui_do_button(&button_abort, "Abort", 0, &abort, ui_draw_menu_button, 0) || escape_pressed) - popup = POPUP_NONE; - - static int button_tryagain = 0; - if(ui_do_button(&button_tryagain, "Try again", 0, &tryagain, ui_draw_menu_button, 0) || enter_pressed) - { - client_connect(config.ui_server_address); - } - - ui_hsplit_b(&box, 60.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - - ui_vsplit_l(&part, 60.0f, 0, &label); - ui_vsplit_l(&label, 100.0f, 0, &textbox); - ui_vsplit_l(&textbox, 20.0f, 0, &textbox); - ui_vsplit_r(&textbox, 60.0f, &textbox, 0); - ui_do_label(&label, "Password:", 20, -1); - ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), 14.0f, true); - } - else if(popup == POPUP_FIRST_LAUNCH) - { - RECT label, textbox; - - ui_hsplit_b(&box, 20.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - ui_vmargin(&part, 80.0f, &part); - - static int enter_button = 0; - if(ui_do_button(&enter_button, "Enter", 0, &part, ui_draw_menu_button, 0) || enter_pressed) - popup = POPUP_NONE; - - ui_hsplit_b(&box, 40.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - - ui_vsplit_l(&part, 60.0f, 0, &label); - ui_vsplit_l(&label, 100.0f, 0, &textbox); - ui_vsplit_l(&textbox, 20.0f, 0, &textbox); - ui_vsplit_r(&textbox, 60.0f, &textbox, 0); - ui_do_label(&label, "Nickname:", 20, -1); - ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f); - } - else - { - ui_hsplit_b(&box, 20.f, &box, &part); - ui_hsplit_b(&box, 24.f, &box, &part); - ui_vmargin(&part, 120.0f, &part); - - static int button = 0; - if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || escape_pressed || enter_pressed) - { - if(popup == POPUP_CONNECTING) - client_disconnect(); - popup = POPUP_NONE; - } - } - } - - return 0; -} - - -void MENUS::set_active(bool active) -{ - menu_active = active; - if(!menu_active && need_sendinfo) - { - gameclient.send_info(false); - need_sendinfo = false; - } -} - -void MENUS::on_reset() -{ -} - -bool MENUS::on_mousemove(float x, float y) -{ - last_input = time_get(); - - if(!menu_active) - return false; - - mouse_pos.x += x; - mouse_pos.y += y; - -#ifdef ANDROID - mouse_pos.x = x; - mouse_pos.y = y; -#endif - - if(mouse_pos.x < 0) mouse_pos.x = 0; - if(mouse_pos.y < 0) mouse_pos.y = 0; - if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth(); - if(mouse_pos.y > gfx_screenheight()) mouse_pos.y = gfx_screenheight(); - - return true; -} - -bool MENUS::on_input(INPUT_EVENT e) -{ - last_input = time_get(); - - // special handle esc and enter for popup purposes - if(e.flags&INPFLAG_PRESS) - { - if(e.key == KEY_ESCAPE) - { - escape_pressed = true; - set_active(!is_active()); - return true; - } - } - - if(is_active()) - { - // special for popups - if(e.flags&INPFLAG_PRESS && e.key == KEY_RETURN) - enter_pressed = true; - - if(num_inputevents < MAX_INPUTEVENTS) - inputevents[num_inputevents++] = e; - return true; - } - return false; -} - -void MENUS::on_statechange(int new_state, int old_state) -{ - if(new_state == CLIENTSTATE_OFFLINE) - { - popup = POPUP_NONE; - if(client_error_string() && client_error_string()[0] != 0) - { - if(strstr(client_error_string(), "password")) - { - popup = POPUP_PASSWORD; - ui_set_hot_item(&config.password); - ui_set_active_item(&config.password); - } - else - popup = POPUP_DISCONNECTED; - } } - else if(new_state == CLIENTSTATE_LOADING) - { - popup = POPUP_CONNECTING; - client_serverinfo_request(); - } - else if(new_state == CLIENTSTATE_CONNECTING) - popup = POPUP_CONNECTING; - else if (new_state == CLIENTSTATE_ONLINE || new_state == CLIENTSTATE_DEMOPLAYBACK) - { - popup = POPUP_NONE; - set_active(false); - } -} - -void MENUS::on_render() -{ - if(client_state() != CLIENTSTATE_ONLINE && client_state() != CLIENTSTATE_DEMOPLAYBACK) - set_active(true); - - if(client_state() == CLIENTSTATE_DEMOPLAYBACK) - { - RECT screen = *ui_screen(); - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - render_demoplayer(screen); - } - - if(client_state() == CLIENTSTATE_ONLINE && gameclient.servermode == gameclient.SERVERMODE_PUREMOD) - { - client_disconnect(); - set_active(true); - popup = POPUP_PURE; - } - - if(!is_active()) - { - escape_pressed = false; - enter_pressed = false; - num_inputevents = 0; - return; - } - - // update colors - vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f)); - gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f); - - color_tabbar_inactive_outgame = vec4(0,0,0,0.25f); - color_tabbar_active_outgame = vec4(0,0,0,0.5f); - - float color_ingame_scale_i = 0.5f; - float color_ingame_scale_a = 0.2f; - color_tabbar_inactive_ingame = vec4( - gui_color.r*color_ingame_scale_i, - gui_color.g*color_ingame_scale_i, - gui_color.b*color_ingame_scale_i, - gui_color.a*0.8f); - - color_tabbar_active_ingame = vec4( - gui_color.r*color_ingame_scale_a, - gui_color.g*color_ingame_scale_a, - gui_color.b*color_ingame_scale_a, - gui_color.a); - - // update the ui - RECT *screen = ui_screen(); - float mx = (mouse_pos.x/(float)gfx_screenwidth())*screen->w; - float my = (mouse_pos.y/(float)gfx_screenheight())*screen->h; - - int buttons = 0; - if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1; - if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2; - if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4; - - ui_update(mx,my,mx*3.0f,my*3.0f,buttons); - - // render - if(client_state() != CLIENTSTATE_DEMOPLAYBACK) - render(); - - // render cursor - gfx_texture_set(data->images[IMAGE_CURSOR].id); - gfx_quads_begin(); - gfx_setcolor(1,1,1,1); - gfx_quads_drawTL(mx,my,24,24); - gfx_quads_end(); - - // render debug information - if(config.debug) - { - RECT screen = *ui_screen(); - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); - - char buf[512]; - str_format(buf, sizeof(buf), "%p %p %p", ui_hot_item(), ui_active_item(), ui_last_active_item()); - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, 10, 10, 10, TEXTFLAG_RENDER); - gfx_text_ex(&cursor, buf, -1); - } - - escape_pressed = false; - enter_pressed = false; - num_inputevents = 0; -} - -static int texture_blob = -1; - -void MENUS::render_background() -{ - //gfx_clear(1,1,1); - //render_sunrays(0,0); - if(texture_blob == -1) - texture_blob = gfx_load_texture("blob.png", IMG_AUTO, 0); - - - float sw = 300*gfx_screenaspect(); - float sh = 300; - gfx_mapscreen(0, 0, sw, sh); - - RECT s = *ui_screen(); - - // render background color - gfx_texture_set(-1); - gfx_quads_begin(); - //vec4 bottom(gui_color.r*0.3f, gui_color.g*0.3f, gui_color.b*0.3f, 1.0f); - //vec4 bottom(0, 0, 0, 1.0f); - vec4 bottom(gui_color.r, gui_color.g, gui_color.b, 1.0f); - vec4 top(gui_color.r, gui_color.g, gui_color.b, 1.0f); - gfx_setcolorvertex(0, top.r, top.g, top.b, top.a); - gfx_setcolorvertex(1, top.r, top.g, top.b, top.a); - gfx_setcolorvertex(2, bottom.r, bottom.g, bottom.b, bottom.a); - gfx_setcolorvertex(3, bottom.r, bottom.g, bottom.b, bottom.a); - gfx_quads_drawTL(0, 0, sw, sh); - gfx_quads_end(); - - // render the tiles - gfx_texture_set(-1); - gfx_quads_begin(); - float size = 15.0f; - float offset_time = fmod(client_localtime()*0.15f, 2.0f); - for(int y = -2; y < (int)(sw/size); y++) - for(int x = -2; x < (int)(sh/size); x++) - { - gfx_setcolor(0,0,0,0.045f); - gfx_quads_drawTL((x-offset_time)*size*2+(y&1)*size, (y+offset_time)*size, size, size); - } - gfx_quads_end(); - - // render border fade - gfx_texture_set(texture_blob); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.5f); - gfx_quads_drawTL(-100, -100, sw+200, sh+200); - gfx_quads_end(); - - // restore screen - {RECT screen = *ui_screen(); - gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);} -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.hpp deleted file mode 100644 index 8a50c1227..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus.hpp +++ /dev/null @@ -1,183 +0,0 @@ -#include - -#include -#include - - -// compnent to fetch keypresses, override all other input -class MENUS_KEYBINDER : public COMPONENT -{ -public: - bool take_key; - bool got_key; - INPUT_EVENT key; - MENUS_KEYBINDER(); - virtual bool on_input(INPUT_EVENT e); -}; - -class MENUS : public COMPONENT -{ - static vec4 gui_color; - static vec4 color_tabbar_inactive_outgame; - static vec4 color_tabbar_active_outgame; - static vec4 color_tabbar_inactive_ingame; - static vec4 color_tabbar_active_ingame; - static vec4 color_tabbar_inactive; - static vec4 color_tabbar_active; - - static vec4 button_color_mul(const void *id); - - - static void ui_draw_demoplayer_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); - - static void ui_draw_browse_icon(int what, const RECT *r); - static void ui_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_menu_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_settings_tab_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_grid_header(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_list_row(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const RECT *r); - static void ui_draw_checkbox(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra); - static int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden=false); - - static float ui_do_scrollbar_v(const void *id, const RECT *rect, float current); - static float ui_do_scrollbar_h(const void *id, const RECT *rect, float current); - - static int ui_do_key_reader(void *id, const RECT *rect, int key); - static void ui_do_getbuttons(int start, int stop, RECT view); - - struct LISTBOXITEM - { - int visible; - int selected; - RECT rect; - }; - - static void ui_do_listbox_start(void *id, const RECT *rect, float row_height, const char *title, int num_items, int selected_index); - static LISTBOXITEM ui_do_listbox_nextitem(void *id); - static int ui_do_listbox_end(); - - //static void demolist_listdir_callback(const char *name, int is_dir, void *user); - //static void demolist_list_callback(const RECT *rect, int index, void *user); - - enum - { - POPUP_NONE=0, - POPUP_FIRST_LAUNCH, - POPUP_CONNECTING, - POPUP_DISCONNECTED, - POPUP_PURE, - POPUP_PASSWORD, - POPUP_QUIT, - }; - - enum - { - PAGE_NEWS=1, - PAGE_GAME, - PAGE_SERVER_INFO, - PAGE_CALLVOTE, - PAGE_INTERNET, - PAGE_LAN, - PAGE_FAVORITES, - PAGE_DEMOS, - PAGE_SETTINGS, - PAGE_SYSTEM, - }; - - int game_page; - int popup; - int active_page; - bool menu_active; - vec2 mouse_pos; - - int64 last_input; - - // TODO: this is a bit ugly but.. well.. yeah - enum { MAX_INPUTEVENTS = 32 }; - static INPUT_EVENT inputevents[MAX_INPUTEVENTS]; - static int num_inputevents; - - // some settings - static float button_height; - static float listheader_height; - static float fontmod_height; - - // for graphic settings - bool need_restart; - bool need_sendinfo; - - // - bool escape_pressed; - bool enter_pressed; - - // for call vote - int callvote_selectedoption; - int callvote_selectedplayer; - - // demo - struct DEMOITEM - { - char filename[512]; - char name[256]; - }; - - DEMOITEM *demos; - int num_demos; - - void demolist_populate(); - static void demolist_count_callback(const char *name, int is_dir, void *user); - static void demolist_fetch_callback(const char *name, int is_dir, void *user); - - // found in menus.cpp - int render(); - void render_background(); - //void render_loading(float percent); - int render_menubar(RECT r); - void render_news(RECT main_view); - - // found in menus_demo.cpp - void render_demoplayer(RECT main_view); - void render_demolist(RECT main_view); - - // found in menus_ingame.cpp - void render_game(RECT main_view); - void render_serverinfo(RECT main_view); - void render_servercontrol(RECT main_view); - void render_servercontrol_kick(RECT main_view); - void render_servercontrol_server(RECT main_view); - - // found in menus_browser.cpp - int selected_index; - void render_serverbrowser_serverlist(RECT view); - void render_serverbrowser_serverdetail(RECT view); - void render_serverbrowser_filters(RECT view); - void render_serverbrowser(RECT main_view); - - // found in menus_settings.cpp - void render_settings_player(RECT main_view); - void render_settings_controls(RECT main_view); - void render_settings_graphics(RECT main_view); - void render_settings_sound(RECT main_view); - void render_settings(RECT main_view); - - void set_active(bool active); -public: - static MENUS_KEYBINDER binder; - - MENUS(); - - void render_loading(float percent); - - bool is_active() const { return menu_active; } - - void init(); - - virtual void on_statechange(int new_state, int old_state); - virtual void on_reset(); - virtual void on_render(); - virtual bool on_input(INPUT_EVENT e); - virtual bool on_mousemove(float x, float y); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_browser.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_browser.cpp deleted file mode 100644 index 1c1837e4b..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_browser.cpp +++ /dev/null @@ -1,669 +0,0 @@ - -#include // strcmp, strlen, strncpy -#include // atoi - -#include - -extern "C" { - #include -} - -#include -#include - -#include -#include -#include "menus.hpp" -#include - -void MENUS::render_serverbrowser_serverlist(RECT view) -{ - RECT headers; - RECT status; - - ui_hsplit_t(&view, listheader_height, &headers, &view); - ui_hsplit_b(&view, 28.0f, &view, &status); - - // split of the scrollbar - ui_draw_rect(&headers, vec4(1,1,1,0.25f), CORNER_T, 5.0f); - ui_vsplit_r(&headers, 20.0f, &headers, 0); - - struct column - { - int id; - int sort; - const char *caption; - int direction; - float width; - int flags; - RECT rect; - RECT spacer; - }; - - enum - { - FIXED=1, - SPACER=2, - - COL_FLAG_LOCK=0, - COL_FLAG_PURE, - COL_FLAG_FAV, - COL_NAME, - COL_GAMETYPE, - COL_MAP, - COL_PLAYERS, - COL_PING, - COL_PROGRESS, - COL_VERSION, - }; - - static column cols[] = { - {-1, -1, " ", -1, 2.0f, 0, {0}, {0}}, - {COL_FLAG_LOCK, -1, " ", -1, 14.0f, 0, {0}, {0}}, - {COL_FLAG_PURE, -1, " ", -1, 14.0f, 0, {0}, {0}}, - {COL_FLAG_FAV, -1, " ", -1, 14.0f, 0, {0}, {0}}, - {COL_NAME, BROWSESORT_NAME, "Name", 0, 300.0f, 0, {0}, {0}}, - {COL_GAMETYPE, BROWSESORT_GAMETYPE, "Type", 1, 50.0f, 0, {0}, {0}}, - {COL_MAP, BROWSESORT_MAP, "Map", 1, 100.0f, 0, {0}, {0}}, - {COL_PLAYERS, BROWSESORT_NUMPLAYERS, "Players", 1, 60.0f, 0, {0}, {0}}, - {-1, -1, " ", 1, 10.0f, 0, {0}, {0}}, - {COL_PING, BROWSESORT_PING, "Ping", 1, 40.0f, FIXED, {0}, {0}}, - }; - - int num_cols = sizeof(cols)/sizeof(column); - - // do layout - for(int i = 0; i < num_cols; i++) - { - if(cols[i].direction == -1) - { - ui_vsplit_l(&headers, cols[i].width, &cols[i].rect, &headers); - - if(i+1 < num_cols) - { - //cols[i].flags |= SPACER; - ui_vsplit_l(&headers, 2, &cols[i].spacer, &headers); - } - } - } - - for(int i = num_cols-1; i >= 0; i--) - { - if(cols[i].direction == 1) - { - ui_vsplit_r(&headers, cols[i].width, &headers, &cols[i].rect); - ui_vsplit_r(&headers, 2, &headers, &cols[i].spacer); - } - } - - for(int i = 0; i < num_cols; i++) - { - if(cols[i].direction == 0) - cols[i].rect = headers; - } - - // do headers - for(int i = 0; i < num_cols; i++) - { - if(ui_do_button(cols[i].caption, cols[i].caption, config.b_sort == cols[i].sort, &cols[i].rect, ui_draw_grid_header, 0)) - { - if(cols[i].sort != -1) - { - if(config.b_sort == cols[i].sort) - config.b_sort_order ^= 1; - else - config.b_sort_order = 0; - config.b_sort = cols[i].sort; - } - } - } - - ui_draw_rect(&view, vec4(0,0,0,0.15f), 0, 0); - - RECT scroll; - ui_vsplit_r(&view, 15, &view, &scroll); - - int num_servers = client_serverbrowse_sorted_num(); - - // display important messages in the middle of the screen so no - // users misses it - { - RECT msgbox = view; - msgbox.y += view.h/3; - - if(active_page == PAGE_INTERNET && client_serverbrowse_refreshingmasters()) - ui_do_label(&msgbox, "Refreshing master servers", 16.0f, 0); - else if(!client_serverbrowse_num()) - ui_do_label(&msgbox, "No servers found", 16.0f, 0); - else if(client_serverbrowse_num() && !num_servers) - ui_do_label(&msgbox, "No servers match your filter criteria", 16.0f, 0); - } - - int num = (int)(view.h/cols[0].rect.h); - static int scrollbar = 0; - static float scrollvalue = 0; - //static int selected_index = -1; - ui_hmargin(&scroll, 5.0f, &scroll); - scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue); - - int scrollnum = num_servers-num+10; - if(scrollnum > 0) - { - if(inp_key_presses(KEY_MOUSE_WHEEL_UP)) - scrollvalue -= 1.0f/scrollnum; - if(inp_key_presses(KEY_MOUSE_WHEEL_DOWN)) - scrollvalue += 1.0f/scrollnum; - - if(scrollvalue < 0) scrollvalue = 0; - if(scrollvalue > 1) scrollvalue = 1; - } - else - scrollnum = 0; - - // set clipping - ui_clip_enable(&view); - - int start = (int)(scrollnum*scrollvalue); - if(start < 0) - start = 0; - - RECT original_view = view; - view.y -= scrollvalue*scrollnum*cols[0].rect.h; - - int new_selected = -1; - int num_players = 0; - - selected_index = -1; - - for (int i = 0; i < num_servers; i++) - { - SERVER_INFO *item = client_serverbrowse_sorted_get(i); - num_players += item->num_players; - } - - for (int i = 0; i < num_servers; i++) - { - int item_index = i; - SERVER_INFO *item = client_serverbrowse_sorted_get(item_index); - RECT row; - RECT select_hit_box; - - int selected = strcmp(item->address, config.ui_server_address) == 0; //selected_index==item_index; - - ui_hsplit_t(&view, 17.0f, &row, &view); - select_hit_box = row; - - if(selected) - { - selected_index = i; - RECT r = row; - ui_margin(&r, 1.5f, &r); - ui_draw_rect(&r, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f); - } - - - // make sure that only those in view can be selected - if(row.y+row.h > original_view.y) - { - if(select_hit_box.y < original_view.y) // clip the selection - { - select_hit_box.h -= original_view.y-select_hit_box.y; - select_hit_box.y = original_view.y; - } - - if(ui_do_button(item, "", selected, &select_hit_box, 0, 0)) - { - new_selected = item_index; - } - } - - // check if we need to do more - if(row.y > original_view.y+original_view.h && !ui_active_item()) - break; - - for(int c = 0; c < num_cols; c++) - { - RECT button; - char temp[64]; - button.x = cols[c].rect.x; - button.y = row.y; - button.h = row.h; - button.w = cols[c].rect.w; - - //int s = 0; - int id = cols[c].id; - - //s = ui_do_button(item, "L", l, &button, ui_draw_browse_icon, 0); - - if(id == COL_FLAG_LOCK) - { - if(item->flags & SRVFLAG_PASSWORD) - ui_draw_browse_icon(SPRITE_BROWSE_LOCK, &button); - } - else if(id == COL_FLAG_PURE) - { - if(strcmp(item->gametype, "DM") == 0 || strcmp(item->gametype, "TDM") == 0 || strcmp(item->gametype, "CTF") == 0) - { - // pure server - } - else - { - // unpure - ui_draw_browse_icon(SPRITE_BROWSE_UNPURE, &button); - } - } - else if(id == COL_FLAG_FAV) - { - if(item->favorite) - ui_draw_browse_icon(SPRITE_BROWSE_HEART, &button); - } - else if(id == COL_NAME) - { - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, button.x, button.y, 12.0f*ui_scale(), TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); - cursor.line_width = button.w; - - if(config.b_filter_string[0] && (item->quicksearch_hit&BROWSEQUICK_SERVERNAME)) - { - // highlight the parts that matches - const char *s = str_find_nocase(item->name, config.b_filter_string); - if(s) - { - gfx_text_ex(&cursor, item->name, (int)(s-item->name)); - gfx_text_color(0.4f,0.4f,1.0f,1); - gfx_text_ex(&cursor, s, strlen(config.b_filter_string)); - gfx_text_color(1,1,1,1); - gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1); - } - else - gfx_text_ex(&cursor, item->name, -1); - } - else - gfx_text_ex(&cursor, item->name, -1); - } - else if(id == COL_MAP) - ui_do_label(&button, item->map, 12.0f, -1); - else if(id == COL_PLAYERS) - { - str_format(temp, sizeof(temp), "%i/%i", item->num_players, item->max_players); - if(config.b_filter_string[0] && (item->quicksearch_hit&BROWSEQUICK_PLAYERNAME)) - gfx_text_color(0.4f,0.4f,1.0f,1); - ui_do_label(&button, temp, 12.0f, 1); - gfx_text_color(1,1,1,1); - } - else if(id == COL_PING) - { - str_format(temp, sizeof(temp), "%i", item->latency); - ui_do_label(&button, temp, 12.0f, 1); - } - else if(id == COL_PROGRESS) - { - if(item->progression > 100) - item->progression = 100; - ui_draw_browse_icon(item->progression, &button); - } - else if(id == COL_VERSION) - { - const char *version = item->version; - if(strcmp(version, "0.3 e2d7973c6647a13c") == 0) // TODO: remove me later on - version = "0.3.0"; - ui_do_label(&button, version, 12.0f, 1); - } - else if(id == COL_GAMETYPE) - { - ui_do_label(&button, item->gametype, 12.0f, 0); - } - - } - } - - ui_clip_disable(); - - if(new_selected != -1) - { - // select the new server - SERVER_INFO *item = client_serverbrowse_sorted_get(new_selected); - strncpy(config.ui_server_address, item->address, sizeof(config.ui_server_address)); - if(inp_mouse_doubleclick()) - client_connect(config.ui_server_address); - } - - ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f); - ui_margin(&status, 5.0f, &status); - - // render quick search - RECT quicksearch, button; - ui_vsplit_l(&status, 250.0f, &quicksearch, &status); - ui_do_label(&quicksearch, "Quick search: ", 14.0f, -1); - ui_vsplit_l(&quicksearch, gfx_text_width(0, 14.0f, "Quick search: ", -1), 0, &quicksearch); - ui_do_edit_box(&config.b_filter_string, &quicksearch, config.b_filter_string, sizeof(config.b_filter_string), 14.0f); - ui_vsplit_l(&quicksearch, 135.0f, &quicksearch, &button); - ui_vmargin(&button, 0.0f, &button); - static int clear_button = 0; - if(ui_do_button(&clear_button, "x", 0, &button, ui_draw_menu_button, 0)) - config.b_filter_string[0] = 0; - - // render status - char buf[128]; - str_format(buf, sizeof(buf), "%d of %d servers, %d players", client_serverbrowse_sorted_num(), client_serverbrowse_num(), num_players); - ui_vsplit_r(&status, gfx_text_width(0, 14.0f, buf, -1), 0, &status); - ui_do_label(&status, buf, 14.0f, -1); -} - -void MENUS::render_serverbrowser_filters(RECT view) -{ - // filters - RECT button; - - ui_hsplit_t(&view, 5.0f, 0, &view); - ui_vsplit_l(&view, 5.0f, 0, &view); - ui_vsplit_r(&view, 5.0f, &view, 0); - ui_hsplit_b(&view, 5.0f, &view, 0); - - // render filters - ui_hsplit_t(&view, 20.0f, &button, &view); - if (ui_do_button(&config.b_filter_empty, "Has people playing", config.b_filter_empty, &button, ui_draw_checkbox, 0)) - config.b_filter_empty ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - if (ui_do_button(&config.b_filter_full, "Server not full", config.b_filter_full, &button, ui_draw_checkbox, 0)) - config.b_filter_full ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - if (ui_do_button(&config.b_filter_pw, "No password", config.b_filter_pw, &button, ui_draw_checkbox, 0)) - config.b_filter_pw ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - if (ui_do_button((char *)&config.b_filter_compatversion, "Compatible Version", config.b_filter_compatversion, &button, ui_draw_checkbox, 0)) - config.b_filter_compatversion ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - if (ui_do_button((char *)&config.b_filter_pure, "Standard gametype", config.b_filter_pure, &button, ui_draw_checkbox, 0)) - config.b_filter_pure ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - /*ui_vsplit_l(&button, 20.0f, 0, &button);*/ - if (ui_do_button((char *)&config.b_filter_pure_map, "Standard map", config.b_filter_pure_map, &button, ui_draw_checkbox, 0)) - config.b_filter_pure_map ^= 1; - - ui_hsplit_t(&view, 20.0f, &button, &view); - ui_do_label(&button, "Game types: ", 14.0f, -1); - ui_vsplit_l(&button, 95.0f, 0, &button); - ui_margin(&button, 1.0f, &button); - ui_do_edit_box(&config.b_filter_gametype, &button, config.b_filter_gametype, sizeof(config.b_filter_gametype), 14.0f); - - { - ui_hsplit_t(&view, 20.0f, &button, &view); - RECT editbox; - ui_vsplit_l(&button, 40.0f, &editbox, &button); - ui_vsplit_l(&button, 5.0f, &button, &button); - - char buf[8]; - str_format(buf, sizeof(buf), "%d", config.b_filter_ping); - ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f); - config.b_filter_ping = atoi(buf); - - ui_do_label(&button, "Maximum ping", 14.0f, -1); - } - - ui_hsplit_b(&view, button_height, &view, &button); - static int clear_button = 0; - if(ui_do_button(&clear_button, "Reset Filter", 0, &button, ui_draw_menu_button, 0)) - { - config.b_filter_full = 0; - config.b_filter_empty = 0; - config.b_filter_pw = 0; - config.b_filter_ping = 999; - config.b_filter_gametype[0] = 0; - config.b_filter_compatversion = 1; - config.b_filter_string[0] = 0; - config.b_filter_pure = 1; - } -} - -void MENUS::render_serverbrowser_serverdetail(RECT view) -{ - RECT server_details = view; - RECT server_scoreboard, server_header; - - SERVER_INFO *selected_server = client_serverbrowse_sorted_get(selected_index); - - //ui_vsplit_l(&server_details, 10.0f, 0x0, &server_details); - - // split off a piece to use for scoreboard - ui_hsplit_t(&server_details, 140.0f, &server_details, &server_scoreboard); - ui_hsplit_b(&server_details, 10.0f, &server_details, 0x0); - - // server details - const float font_size = 12.0f; - ui_hsplit_t(&server_details, 20.0f, &server_header, &server_details); - ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f); - ui_draw_rect(&server_details, vec4(0,0,0,0.15f), CORNER_B, 4.0f); - ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header); - ui_do_label(&server_header, "Server Details: ", font_size+2.0f, -1); - - ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details); - - ui_margin(&server_details, 3.0f, &server_details); - - if (selected_server) - { - RECT row; - static const char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" }; - - RECT left_column; - RECT right_column; - - // - { - RECT button; - ui_hsplit_b(&server_details, 20.0f, &server_details, &button); - static int add_fav_button = 0; - if (ui_do_button(&add_fav_button, "Favorite", selected_server->favorite, &button, ui_draw_checkbox, 0)) - { - if(selected_server->favorite) - client_serverbrowse_removefavorite(selected_server->netaddr); - else - client_serverbrowse_addfavorite(selected_server->netaddr); - } - } - //ui_do_label(&row, temp, font_size, -1); - - ui_vsplit_l(&server_details, 5.0f, 0x0, &server_details); - ui_vsplit_l(&server_details, 80.0f, &left_column, &right_column); - - for (unsigned int i = 0; i < sizeof(labels) / sizeof(labels[0]); i++) - { - ui_hsplit_t(&left_column, 15.0f, &row, &left_column); - ui_do_label(&row, labels[i], font_size, -1); - } - - ui_hsplit_t(&right_column, 15.0f, &row, &right_column); - ui_do_label(&row, selected_server->version, font_size, -1); - - ui_hsplit_t(&right_column, 15.0f, &row, &right_column); - ui_do_label(&row, selected_server->gametype, font_size, -1); - - char temp[16]; - - if(selected_server->progression < 0) - str_format(temp, sizeof(temp), "N/A"); - else - str_format(temp, sizeof(temp), "%d%%", selected_server->progression); - ui_hsplit_t(&right_column, 15.0f, &row, &right_column); - ui_do_label(&row, temp, font_size, -1); - - str_format(temp, sizeof(temp), "%d", selected_server->latency); - ui_hsplit_t(&right_column, 15.0f, &row, &right_column); - ui_do_label(&row, temp, font_size, -1); - - } - - // server scoreboard - - ui_hsplit_b(&server_scoreboard, 10.0f, &server_scoreboard, 0x0); - ui_hsplit_t(&server_scoreboard, 20.0f, &server_header, &server_scoreboard); - ui_draw_rect(&server_header, vec4(1,1,1,0.25f), CORNER_T, 4.0f); - ui_draw_rect(&server_scoreboard, vec4(0,0,0,0.15f), CORNER_B, 4.0f); - ui_vsplit_l(&server_header, 8.0f, 0x0, &server_header); - ui_do_label(&server_header, "Scoreboard: ", font_size+2.0f, -1); - - ui_vsplit_l(&server_scoreboard, 5.0f, 0x0, &server_scoreboard); - - ui_margin(&server_scoreboard, 3.0f, &server_scoreboard); - - if (selected_server) - { - for (int i = 0; i < selected_server->num_players; i++) - { - RECT row; - char temp[16]; - ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard); - - str_format(temp, sizeof(temp), "%d", selected_server->players[i].score); - ui_do_label(&row, temp, font_size, -1); - - ui_vsplit_l(&row, 25.0f, 0x0, &row); - - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, row.x, row.y, 12.0f, TEXTFLAG_RENDER); - - const char *name = selected_server->players[i].name; - if(config.b_filter_string[0]) - { - // highlight the parts that matches - const char *s = str_find_nocase(name, config.b_filter_string); - if(s) - { - gfx_text_ex(&cursor, name, (int)(s-name)); - gfx_text_color(0.4f,0.4f,1,1); - gfx_text_ex(&cursor, s, strlen(config.b_filter_string)); - gfx_text_color(1,1,1,1); - gfx_text_ex(&cursor, s+strlen(config.b_filter_string), -1); - } - else - gfx_text_ex(&cursor, name, -1); - } - else - gfx_text_ex(&cursor, name, -1); - - } - } -} - -void MENUS::render_serverbrowser(RECT main_view) -{ - ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f); - - RECT view; - ui_margin(&main_view, 10.0f, &view); - - /* - +-----------------+ +------+ - | | | | - | | | tool | - | | | box | - | | | | - | | +------+ - +-----------------+ button - status toolbar box - */ - - - //RECT filters; - RECT status_toolbar; - RECT toolbox; - RECT button_box; - - // split off a piece for filters, details and scoreboard - ui_vsplit_r(&view, 200.0f, &view, &toolbox); - ui_hsplit_b(&toolbox, 80.0f, &toolbox, &button_box); - ui_hsplit_b(&view, button_height+5.0f, &view, &status_toolbar); - - render_serverbrowser_serverlist(view); - - int toolbox_page = config.ui_toolbox_page; - - ui_vsplit_l(&toolbox, 5.0f, 0, &toolbox); - - // do tabbar - { - RECT tab_bar; - RECT tabbutton0, tabbutton1; - ui_hsplit_t(&toolbox, 22.0f, &tab_bar, &toolbox); - - ui_vsplit_mid(&tab_bar, &tabbutton0, &tabbutton1); - ui_vsplit_r(&tabbutton0, 5.0f, &tabbutton0, 0); - ui_vsplit_l(&tabbutton1, 5.0f, 0, &tabbutton1); - - static int filters_tab = 0; - if (ui_do_button(&filters_tab, "Filter", toolbox_page==0, &tabbutton0, ui_draw_menu_tab_button, 0)) - toolbox_page = 0; - - static int info_tab = 0; - if (ui_do_button(&info_tab, "Info", toolbox_page==1, &tabbutton1, ui_draw_menu_tab_button, 0)) - toolbox_page = 1; - } - - config.ui_toolbox_page = toolbox_page; - - ui_draw_rect(&toolbox, vec4(0,0,0,0.15f), 0, 0); - - ui_hsplit_t(&toolbox, 5.0f, 0, &toolbox); - - if(toolbox_page == 0) - render_serverbrowser_filters(toolbox); - else if(toolbox_page == 1) - render_serverbrowser_serverdetail(toolbox); - - { - ui_hsplit_t(&status_toolbar, 5.0f, 0, &status_toolbar); - - RECT button; - //ui_vsplit_r(&buttons, 20.0f, &buttons, &button); - ui_vsplit_r(&status_toolbar, 100.0f, &status_toolbar, &button); - ui_vmargin(&button, 2.0f, &button); - static int refresh_button = 0; - if(ui_do_button(&refresh_button, "Refresh", 0, &button, ui_draw_menu_button, 0)) - { - if(config.ui_page == PAGE_INTERNET) - client_serverbrowse_refresh(BROWSETYPE_INTERNET); - else if(config.ui_page == PAGE_LAN) - client_serverbrowse_refresh(BROWSETYPE_LAN); - else if(config.ui_page == PAGE_FAVORITES) - client_serverbrowse_refresh(BROWSETYPE_FAVORITES); - } - - char buf[512]; - if(strcmp(client_latestversion(), "0") != 0) - str_format(buf, sizeof(buf), "Teeworlds %s is out! Download it at www.teeworlds.com!\nCurrent version: %s", client_latestversion(), GAME_VERSION); - else - str_format(buf, sizeof(buf), "Current version: %s", GAME_VERSION); - ui_do_label(&status_toolbar, buf, 14.0f, -1); - } - - // do the button box - { - - ui_vsplit_l(&button_box, 5.0f, 0, &button_box); - ui_vsplit_r(&button_box, 5.0f, &button_box, 0); - - RECT button; - ui_hsplit_b(&button_box, button_height, &button_box, &button); - ui_vsplit_r(&button, 120.0f, 0, &button); - ui_vmargin(&button, 2.0f, &button); - //ui_vmargin(&button, 2.0f, &button); - static int join_button = 0; - if(ui_do_button(&join_button, "Connect", 0, &button, ui_draw_menu_button, 0) || enter_pressed) - { - client_connect(config.ui_server_address); - enter_pressed = false; - } - - ui_hsplit_b(&button_box, 5.0f, &button_box, &button); - ui_hsplit_b(&button_box, 20.0f, &button_box, &button); - ui_do_edit_box(&config.ui_server_address, &button, config.ui_server_address, sizeof(config.ui_server_address), 14.0f); - ui_hsplit_b(&button_box, 20.0f, &button_box, &button); - ui_do_label(&button, "Host address:", 14.0f, -1); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_demo.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_demo.cpp deleted file mode 100644 index 2966160f8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_demo.cpp +++ /dev/null @@ -1,408 +0,0 @@ - -#include - -//#include // strcmp, strlen, strncpy -//#include // atoi - -#include -#include -#include - -//#include -//#include - -#include -//#include -//#include - -#include "menus.hpp" - -void MENUS::ui_draw_demoplayer_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - ui_draw_rect(r, vec4(1,1,1, checked ? 0.10f : 0.5f)*button_color_mul(id), CORNER_ALL, 5.0f); - ui_do_label(r, text, 14.0f, 0); -} - -void MENUS::render_demoplayer(RECT main_view) -{ - const DEMOPLAYBACK_INFO *info = client_demoplayer_getinfo(); - - const float seekbar_height = 15.0f; - const float buttonbar_height = 20.0f; - const float margins = 5.0f; - float total_height; - - if(menu_active) - total_height = seekbar_height+buttonbar_height+margins*3; - else - total_height = seekbar_height+margins*2; - - ui_hsplit_b(&main_view, total_height, 0, &main_view); - ui_vsplit_l(&main_view, 250.0f, 0, &main_view); - ui_vsplit_r(&main_view, 250.0f, &main_view, 0); - - ui_draw_rect(&main_view, color_tabbar_active, CORNER_T, 10.0f); - - ui_margin(&main_view, 5.0f, &main_view); - - RECT seekbar, buttonbar; - - if(menu_active) - { - ui_hsplit_t(&main_view, seekbar_height, &seekbar, &buttonbar); - ui_hsplit_t(&buttonbar, margins, 0, &buttonbar); - } - else - seekbar = main_view; - - // do seekbar - { - static int seekbar_id = 0; - void *id = &seekbar_id; - char buffer[128]; - - ui_draw_rect(&seekbar, vec4(0,0,0,0.5f), CORNER_ALL, 5.0f); - - int current_tick = info->current_tick - info->first_tick; - int total_ticks = info->last_tick - info->first_tick; - - float amount = current_tick/(float)total_ticks; - - RECT filledbar = seekbar; - filledbar.w = 10.0f + (filledbar.w-10.0f)*amount; - - ui_draw_rect(&filledbar, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); - - str_format(buffer, sizeof(buffer), "%d:%02d / %d:%02d", - current_tick/SERVER_TICK_SPEED/60, (current_tick/SERVER_TICK_SPEED)%60, - total_ticks/SERVER_TICK_SPEED/60, (total_ticks/SERVER_TICK_SPEED)%60); - ui_do_label(&seekbar, buffer, seekbar.h*0.70f, 0); - - // do the logic - int inside = ui_mouse_inside(&seekbar); - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - else - { - float amount = (ui_mouse_x()-seekbar.x)/(float)seekbar.w; - if(amount > 0 && amount < 1.0f) - { - gameclient.on_reset(); - gameclient.suppress_events = true; - client_demoplayer_setpos(amount); - gameclient.suppress_events = false; - } - } - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - ui_set_active_item(id); - } - - if(inside) - ui_set_hot_item(id); - } - - - if(menu_active) - { - // do buttons - RECT button; - - // pause button - ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar); - static int pause_button = 0; - if(ui_do_button(&pause_button, "| |", info->paused, &button, ui_draw_demoplayer_button, 0)) - client_demoplayer_setpause(!info->paused); - - // play button - ui_vsplit_l(&buttonbar, margins, 0, &buttonbar); - ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar); - static int play_button = 0; - if(ui_do_button(&play_button, ">", !info->paused, &button, ui_draw_demoplayer_button, 0)) - { - client_demoplayer_setpause(0); - client_demoplayer_setspeed(1.0f); - } - - // slowdown - ui_vsplit_l(&buttonbar, margins, 0, &buttonbar); - ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar); - static int slowdown_button = 0; - if(ui_do_button(&slowdown_button, "<<", 0, &button, ui_draw_demoplayer_button, 0)) - { - if(info->speed > 4.0f) client_demoplayer_setspeed(4.0f); - else if(info->speed > 2.0f) client_demoplayer_setspeed(2.0f); - else if(info->speed > 1.0f) client_demoplayer_setspeed(1.0f); - else if(info->speed > 0.5f) client_demoplayer_setspeed(0.5f); - else client_demoplayer_setspeed(0.05f); - } - - // fastforward - ui_vsplit_l(&buttonbar, margins, 0, &buttonbar); - ui_vsplit_l(&buttonbar, buttonbar_height, &button, &buttonbar); - static int fastforward_button = 0; - if(ui_do_button(&fastforward_button, ">>", 0, &button, ui_draw_demoplayer_button, 0)) - { - if(info->speed < 0.5f) client_demoplayer_setspeed(0.5f); - else if(info->speed < 1.0f) client_demoplayer_setspeed(1.0f); - else if(info->speed < 2.0f) client_demoplayer_setspeed(2.0f); - else if(info->speed < 4.0f) client_demoplayer_setspeed(4.0f); - else client_demoplayer_setspeed(8.0f); - } - - // speed meter - ui_vsplit_l(&buttonbar, margins*3, 0, &buttonbar); - char buffer[64]; - if(info->speed >= 1.0f) - str_format(buffer, sizeof(buffer), "x%.0f", info->speed); - else - str_format(buffer, sizeof(buffer), "x%.1f", info->speed); - ui_do_label(&buttonbar, buffer, button.h*0.7f, -1); - - // exit button - ui_vsplit_r(&buttonbar, buttonbar_height*3, &buttonbar, &button); - static int exit_button = 0; - if(ui_do_button(&exit_button, "Exit", 0, &button, ui_draw_demoplayer_button, 0)) - client_disconnect(); - } -} - -static RECT listbox_originalview; -static RECT listbox_view; -static float listbox_rowheight; -static int listbox_itemindex; -static int listbox_selected_index; -static int listbox_new_selected; - -void MENUS::ui_do_listbox_start(void *id, const RECT *rect, float row_height, const char *title, int num_items, int selected_index) -{ - RECT scroll, row; - RECT view = *rect; - RECT header, footer; - - // draw header - ui_hsplit_t(&view, listheader_height, &header, &view); - ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); - ui_do_label(&header, title, header.h*fontmod_height, 0); - - // draw footers - ui_hsplit_b(&view, listheader_height, &view, &footer); - ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); - ui_vsplit_l(&footer, 10.0f, 0, &footer); - - // background - ui_draw_rect(&view, vec4(0,0,0,0.15f), 0, 0); - - // prepare the scroll - ui_vsplit_r(&view, 15, &view, &scroll); - - // setup the variables - listbox_originalview = view; - listbox_selected_index = selected_index; - listbox_new_selected = selected_index; - listbox_itemindex = 0; - listbox_rowheight = row_height; - //int num_servers = client_serverbrowse_sorted_num(); - - - // do the scrollbar - ui_hsplit_t(&view, listbox_rowheight, &row, 0); - - int num = (int)(listbox_originalview.h/row.h); - static float scrollvalue = 0; - ui_hmargin(&scroll, 5.0f, &scroll); - scrollvalue = ui_do_scrollbar_v(id, &scroll, scrollvalue); - - int start = (int)(num*scrollvalue); - if(start < 0) - start = 0; - - // the list - listbox_view = listbox_originalview; - ui_vmargin(&listbox_view, 5.0f, &listbox_view); - ui_clip_enable(&listbox_view); - listbox_view.y -= scrollvalue*num*row.h; -} - -MENUS::LISTBOXITEM MENUS::ui_do_listbox_nextitem(void *id) -{ - RECT row; - LISTBOXITEM item = {0}; - ui_hsplit_t(&listbox_view, listbox_rowheight-2.0f, &row, &listbox_view); - ui_hsplit_t(&listbox_view, 2.0f, 0, &listbox_view); - - RECT select_hit_box = row; - - item.visible = 1; - if(listbox_selected_index == listbox_itemindex) - item.selected = 1; - - // make sure that only those in view can be selected - if(row.y+row.h > listbox_originalview.y) - { - - if(select_hit_box.y < listbox_originalview.y) // clip the selection - { - select_hit_box.h -= listbox_originalview.y-select_hit_box.y; - select_hit_box.y = listbox_originalview.y; - } - - if(ui_do_button(id, "", listbox_selected_index==listbox_itemindex, &select_hit_box, 0, 0)) - listbox_new_selected = listbox_itemindex; - } - else - item.visible = 0; - - item.rect = row; - - // check if we need to do more - if(row.y > listbox_originalview.y+listbox_originalview.h) - item.visible = 0; - - if(listbox_selected_index==listbox_itemindex) - { - //selected_index = i; - RECT r = row; - ui_margin(&r, 1.5f, &r); - ui_draw_rect(&r, vec4(1,1,1,0.5f), CORNER_ALL, 4.0f); - } - - listbox_itemindex++; - - ui_vmargin(&item.rect, 5.0f, &item.rect); - - return item; -} - -int MENUS::ui_do_listbox_end() -{ - ui_clip_disable(); - return listbox_new_selected; -} - -/* -void MENUS::demolist_listdir_callback(const char *name, int is_dir, void *user) -{ - - (*count)++; - LISTBOXITEM item = ui_do_listbox_nextitem((void*)(10+*count)); - if(item.visible) - ui_do_label(&item.rect, name, item.rect.h*fontmod_height, -1); -} - - - DEMOITEM *demos; - int num_demos; - */ - -void MENUS::demolist_count_callback(const char *name, int is_dir, void *user) -{ - if(is_dir || name[0] == '.') - return; - (*(int *)user)++; -} - -struct FETCH_CALLBACKINFO -{ - MENUS *self; - const char *prefix; - int count; -}; - -void MENUS::demolist_fetch_callback(const char *name, int is_dir, void *user) -{ - if(is_dir || name[0] == '.') - return; - - FETCH_CALLBACKINFO *info = (FETCH_CALLBACKINFO *)user; - - if(info->count == info->self->num_demos) - return; - - str_format(info->self->demos[info->count].filename, sizeof(info->self->demos[info->count].filename), "%s/%s", info->prefix, name); - str_copy(info->self->demos[info->count].name, name, sizeof(info->self->demos[info->count].name)); - info->count++; -} - - -void MENUS::demolist_populate() -{ - if(demos) - mem_free(demos); - demos = 0; - num_demos = 0; - - char buf[512]; - str_format(buf, sizeof(buf), "%s/demos", client_user_directory()); - fs_listdir(buf, demolist_count_callback, &num_demos); - fs_listdir("demos", demolist_count_callback, &num_demos); - - demos = (DEMOITEM *)mem_alloc(sizeof(DEMOITEM)*num_demos, 1); - mem_zero(demos, sizeof(DEMOITEM)*num_demos); - - FETCH_CALLBACKINFO info = {this, buf, 0}; - fs_listdir(buf, demolist_fetch_callback, &info); - info.prefix = "demos"; - fs_listdir("demos", demolist_fetch_callback, &info); -} - - -void MENUS::render_demolist(RECT main_view) -{ - static int inited = 0; - if(!inited) - demolist_populate(); - inited = 1; - - // render background - ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f); - ui_margin(&main_view, 10.0f, &main_view); - - RECT buttonbar; - ui_hsplit_b(&main_view, button_height+5.0f, &main_view, &buttonbar); - ui_hsplit_t(&buttonbar, 5.0f, 0, &buttonbar); - - static int selected_item = -1; - static int num_items = 0; - static int demolist_id = 0; - - ui_do_listbox_start(&demolist_id, &main_view, 17.0f, "Demos", num_items, selected_item); - for(int i = 0; i < num_demos; i++) - { - LISTBOXITEM item = ui_do_listbox_nextitem((void*)(10+i)); - if(item.visible) - ui_do_label(&item.rect, demos[i].name, item.rect.h*fontmod_height, -1); - } - selected_item = ui_do_listbox_end(); - - if(selected_item >= 0 && selected_item < num_demos && inp_mouse_doubleclick()) - { - ui_set_active_item(0); - client_demoplayer_play(demos[selected_item].filename); - } - - RECT refresh_rect, play_rect; - ui_vsplit_r(&buttonbar, 250.0f, &buttonbar, &refresh_rect); - ui_vsplit_r(&refresh_rect, 130.0f, &refresh_rect, &play_rect); - ui_vsplit_r(&play_rect, 120.0f, 0x0, &play_rect); - - static int refresh_button = 0; - if(ui_do_button(&refresh_button, "Refresh", 0, &refresh_rect, ui_draw_menu_button, 0)) - { - demolist_populate(); - } - - static int play_button = 0; - if(ui_do_button(&play_button, "Play", 0, &play_rect, ui_draw_menu_button, 0)) - { - if(selected_item >= 0 && selected_item < num_demos) - client_demoplayer_play(demos[selected_item].filename); - } - -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_ingame.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_ingame.cpp deleted file mode 100644 index 1623075d9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_ingame.cpp +++ /dev/null @@ -1,398 +0,0 @@ - -#include - -#include // strcmp, strlen, strncpy -#include // atoi - -#include - -#include -#include - -#include -#include -#include - -#include "menus.hpp" -#include "motd.hpp" -#include "voting.hpp" - -void MENUS::render_game(RECT main_view) -{ - RECT button; - //RECT votearea; - ui_hsplit_t(&main_view, 45.0f, &main_view, 0); - ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f); - - ui_hsplit_t(&main_view, 10.0f, 0, &main_view); - ui_hsplit_t(&main_view, 25.0f, &main_view, 0); - ui_vmargin(&main_view, 10.0f, &main_view); - - ui_vsplit_r(&main_view, 120.0f, &main_view, &button); - static int disconnect_button = 0; - if(ui_do_button(&disconnect_button, "Disconnect", 0, &button, ui_draw_menu_button, 0)) - client_disconnect(); - - if(gameclient.snap.local_info && gameclient.snap.gameobj) - { - if(gameclient.snap.local_info->team != -1) - { - ui_vsplit_l(&main_view, 10.0f, &button, &main_view); - ui_vsplit_l(&main_view, 120.0f, &button, &main_view); - static int spectate_button = 0; - if(ui_do_button(&spectate_button, "Spectate", 0, &button, ui_draw_menu_button, 0)) - { - gameclient.send_switch_team(-1); - set_active(false); - } - } - - if(gameclient.snap.gameobj->flags & GAMEFLAG_TEAMS) - { - if(gameclient.snap.local_info->team != 0) - { - ui_vsplit_l(&main_view, 10.0f, &button, &main_view); - ui_vsplit_l(&main_view, 120.0f, &button, &main_view); - static int spectate_button = 0; - if(ui_do_button(&spectate_button, "Join Red", 0, &button, ui_draw_menu_button, 0)) - { - gameclient.send_switch_team(0); - set_active(false); - } - } - - if(gameclient.snap.local_info->team != 1) - { - ui_vsplit_l(&main_view, 10.0f, &button, &main_view); - ui_vsplit_l(&main_view, 120.0f, &button, &main_view); - static int spectate_button = 0; - if(ui_do_button(&spectate_button, "Join Blue", 0, &button, ui_draw_menu_button, 0)) - { - gameclient.send_switch_team(1); - set_active(false); - } - } - } - else - { - if(gameclient.snap.local_info->team != 0) - { - ui_vsplit_l(&main_view, 10.0f, &button, &main_view); - ui_vsplit_l(&main_view, 120.0f, &button, &main_view); - static int spectate_button = 0; - if(ui_do_button(&spectate_button, "Join Game", 0, &button, ui_draw_menu_button, 0)) - { - gameclient.send_switch_team(0); - set_active(false); - } - } - } - } - - /* - RECT bars; - ui_hsplit_t(&votearea, 10.0f, 0, &votearea); - ui_hsplit_t(&votearea, 25.0f + 10.0f*3 + 25.0f, &votearea, &bars); - - ui_draw_rect(&votearea, color_tabbar_active, CORNER_ALL, 10.0f); - - ui_vmargin(&votearea, 20.0f, &votearea); - ui_hmargin(&votearea, 10.0f, &votearea); - - ui_hsplit_b(&votearea, 35.0f, &votearea, &bars); - - if(gameclient.voting->is_voting()) - { - // do yes button - ui_vsplit_l(&votearea, 50.0f, &button, &votearea); - static int yes_button = 0; - if(ui_do_button(&yes_button, "Yes", 0, &button, ui_draw_menu_button, 0)) - gameclient.voting->vote(1); - - // do no button - ui_vsplit_l(&votearea, 5.0f, 0, &votearea); - ui_vsplit_l(&votearea, 50.0f, &button, &votearea); - static int no_button = 0; - if(ui_do_button(&no_button, "No", 0, &button, ui_draw_menu_button, 0)) - gameclient.voting->vote(-1); - - // do time left - ui_vsplit_r(&votearea, 50.0f, &votearea, &button); - char buf[256]; - str_format(buf, sizeof(buf), "%d", gameclient.voting->seconds_left()); - ui_do_label(&button, buf, 24.0f, 0); - - // do description and command - ui_vsplit_l(&votearea, 5.0f, 0, &votearea); - ui_do_label(&votearea, gameclient.voting->vote_description(), 14.0f, -1); - ui_hsplit_t(&votearea, 16.0f, 0, &votearea); - ui_do_label(&votearea, gameclient.voting->vote_command(), 10.0f, -1); - - // do bars - ui_hsplit_t(&bars, 10.0f, 0, &bars); - ui_hmargin(&bars, 5.0f, &bars); - - gameclient.voting->render_bars(bars, true); - - } - else - { - ui_do_label(&votearea, "No vote in progress", 18.0f, -1); - }*/ -} - -void MENUS::render_serverinfo(RECT main_view) -{ - // fetch server info - SERVER_INFO current_server_info; - client_serverinfo(¤t_server_info); - - if(!gameclient.snap.local_info) - return; - - // count players for server info-box - int num_players = 0; - for(int i = 0; i < snap_num_items(SNAP_CURRENT); i++) - { - SNAP_ITEM item; - snap_get_item(SNAP_CURRENT, i, &item); - - if(item.type == NETOBJTYPE_PLAYER_INFO) - { - num_players++; - } - } - - // render background - ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f); - - RECT view, serverinfo, gameinfo, motd; - - float x = 0.0f; - float y = 0.0f; - - char buf[1024]; - - // set view to use for all sub-modules - ui_margin(&main_view, 10.0f, &view); - - /* serverinfo */ - ui_hsplit_t(&view, view.h/2-5.0f, &serverinfo, &motd); - ui_vsplit_l(&serverinfo, view.w/2-5.0f, &serverinfo, &gameinfo); - ui_draw_rect(&serverinfo, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - - ui_margin(&serverinfo, 5.0f, &serverinfo); - - x = 5.0f; - y = 0.0f; - - gfx_text(0, serverinfo.x+x, serverinfo.y+y, 32, "Server info", 250); - y += 32.0f+5.0f; - - mem_zero(buf, sizeof(buf)); - str_format( - buf, - sizeof(buf), - "%s\n\n" - "Address: %s\n" - "Ping: %d\n" - "Version: %s\n" - "Password: %s\n", - current_server_info.name, - config.ui_server_address, - gameclient.snap.local_info->latency, - current_server_info.version, - current_server_info.flags&1 ? "Yes" : "No" - ); - - gfx_text(0, serverinfo.x+x, serverinfo.y+y, 20, buf, 250); - - { - RECT button; - int is_favorite = client_serverbrowse_isfavorite(current_server_info.netaddr); - ui_hsplit_b(&serverinfo, 20.0f, &serverinfo, &button); - static int add_fav_button = 0; - if (ui_do_button(&add_fav_button, "Favorite", is_favorite, &button, ui_draw_checkbox, 0)) - { - if(is_favorite) - client_serverbrowse_removefavorite(current_server_info.netaddr); - else - client_serverbrowse_addfavorite(current_server_info.netaddr); - } - } - - /* gameinfo */ - ui_vsplit_l(&gameinfo, 10.0f, 0x0, &gameinfo); - ui_draw_rect(&gameinfo, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - - ui_margin(&gameinfo, 5.0f, &gameinfo); - - x = 5.0f; - y = 0.0f; - - gfx_text(0, gameinfo.x+x, gameinfo.y+y, 32, "Game info", 250); - y += 32.0f+5.0f; - - mem_zero(buf, sizeof(buf)); - str_format( - buf, - sizeof(buf), - "\n\n" - "Gametype: %s\n" - "Map: %s\n" - "Score limit: %d\n" - "Time limit: %d\n" - "\n" - "Players: %d/%d\n", - current_server_info.gametype, - current_server_info.map, - gameclient.snap.gameobj->score_limit, - gameclient.snap.gameobj->time_limit, - gameclient.snap.num_players, - current_server_info.max_players - ); - gfx_text(0, gameinfo.x+x, gameinfo.y+y, 20, buf, 250); - - /* motd */ - ui_hsplit_t(&motd, 10.0f, 0, &motd); - ui_draw_rect(&motd, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&motd, 5.0f, &motd); - y = 0.0f; - x = 5.0f; - gfx_text(0, motd.x+x, motd.y+y, 32, "MOTD", -1); - y += 32.0f+5.0f; - gfx_text(0, motd.x+x, motd.y+y, 16, gameclient.motd->server_motd, (int)motd.w); -} - -static const char *format_command(const char *cmd) -{ - return cmd; -} - -void MENUS::render_servercontrol_server(RECT main_view) -{ - int num_options = 0; - for(VOTING::VOTEOPTION *option = gameclient.voting->first; option; option = option->next) - num_options++; - - static int votelist = 0; - RECT list = main_view; - ui_do_listbox_start(&votelist, &list, 24.0f, "Options", num_options, callvote_selectedoption); - - for(VOTING::VOTEOPTION *option = gameclient.voting->first; option; option = option->next) - { - LISTBOXITEM item = ui_do_listbox_nextitem(option); - - if(item.visible) - ui_do_label(&item.rect, format_command(option->command), 16.0f, -1); - } - - callvote_selectedoption = ui_do_listbox_end(); -} - -void MENUS::render_servercontrol_kick(RECT main_view) -{ - // draw header - RECT header, footer; - ui_hsplit_t(&main_view, 20, &header, &main_view); - ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); - ui_do_label(&header, "Players", 18.0f, 0); - - // draw footers - ui_hsplit_b(&main_view, 20, &main_view, &footer); - ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); - ui_vsplit_l(&footer, 10.0f, 0, &footer); - - // players - ui_draw_rect(&main_view, vec4(0,0,0,0.15f), 0, 0); - RECT list = main_view; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(!gameclient.snap.player_infos[i]) - continue; - - RECT button; - ui_hsplit_t(&list, button_height, &button, &list); - - if(ui_do_button((char *)&gameclient.snap+i, "", callvote_selectedplayer == i, &button, ui_draw_list_row, 0)) - callvote_selectedplayer = i; - - TEE_RENDER_INFO info = gameclient.clients[i].render_info; - info.size = button.h; - render_tee(ANIMSTATE::get_idle(), &info, EMOTE_NORMAL, vec2(1,0), vec2(button.x+button.h/2, button.y+button.h/2)); - - button.x += button.h; - ui_do_label(&button, gameclient.clients[i].name, 18.0f, -1); - } -} - -void MENUS::render_servercontrol(RECT main_view) -{ - static int control_page = 0; - - // render background - RECT temp, tabbar; - ui_vsplit_r(&main_view, 120.0f, &main_view, &tabbar); - ui_draw_rect(&main_view, color_tabbar_active, CORNER_B|CORNER_TL, 10.0f); - ui_hsplit_t(&tabbar, 50.0f, &temp, &tabbar); - ui_draw_rect(&temp, color_tabbar_active, CORNER_R, 10.0f); - - ui_hsplit_t(&main_view, 10.0f, 0, &main_view); - - RECT button; - - const char *tabs[] = {"Options", "Kick"}; - int num_tabs = (int)(sizeof(tabs)/sizeof(*tabs)); - - for(int i = 0; i < num_tabs; i++) - { - ui_hsplit_t(&tabbar, 10, &button, &tabbar); - ui_hsplit_t(&tabbar, 26, &button, &tabbar); - if(ui_do_button(tabs[i], tabs[i], control_page == i, &button, ui_draw_settings_tab_button, 0)) - { - control_page = i; - callvote_selectedplayer = -1; - callvote_selectedoption = -1; - } - } - - ui_margin(&main_view, 10.0f, &main_view); - RECT bottom; - ui_hsplit_b(&main_view, button_height + 5*2, &main_view, &bottom); - ui_hmargin(&bottom, 5.0f, &bottom); - - // render page - if(control_page == 0) - render_servercontrol_server(main_view); - else if(control_page == 1) - render_servercontrol_kick(main_view); - - - { - RECT button; - ui_vsplit_r(&bottom, 120.0f, &bottom, &button); - - static int callvote_button = 0; - if(ui_do_button(&callvote_button, "Call vote", 0, &button, ui_draw_menu_button, 0)) - { - if(control_page == 0) - { - // - gameclient.voting->callvote_option(callvote_selectedoption); - /* - if(callvote_selectedmap >= 0 && callvote_selectedmap < gameclient.maplist->num()) - gameclient.voting->callvote_map(gameclient.maplist->name(callvote_selectedmap));*/ - } - else if(control_page == 1) - { - if(callvote_selectedplayer >= 0 && callvote_selectedplayer < MAX_CLIENTS && - gameclient.snap.player_infos[callvote_selectedplayer]) - { - gameclient.voting->callvote_kick(callvote_selectedplayer); - set_active(false); - } - } - } - } -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_settings.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_settings.cpp deleted file mode 100644 index b240c6078..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/menus_settings.cpp +++ /dev/null @@ -1,667 +0,0 @@ - -#include - -#include // strcmp, strlen, strncpy -#include // atoi - -#include - -#include -#include - -#include -#include -#include -#include - -#include "binds.hpp" -#include "menus.hpp" -#include "skins.hpp" - -MENUS_KEYBINDER MENUS::binder; - -MENUS_KEYBINDER::MENUS_KEYBINDER() -{ - take_key = false; - got_key = false; -} - -bool MENUS_KEYBINDER::on_input(INPUT_EVENT e) -{ - if(take_key) - { - if(e.flags&INPFLAG_PRESS && e.key != KEY_ESCAPE) - { - key = e; - got_key = true; - take_key = false; - } - return true; - } - - return false; -} - -void MENUS::render_settings_player(RECT main_view) -{ - RECT button; - RECT skinselection; - ui_vsplit_l(&main_view, 300.0f, &main_view, &skinselection); - - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - - // render settings - { - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - ui_do_label(&button, "Name:", 14.0, -1); - ui_vsplit_l(&button, 80.0f, 0, &button); - ui_vsplit_l(&button, 180.0f, &button, 0); - if(ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f)) - need_sendinfo = true; - - static int dynamic_camera_button = 0; - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if(ui_do_button(&dynamic_camera_button, "Dynamic Camera", config.cl_mouse_deadzone != 0, &button, ui_draw_checkbox, 0)) - { - - if(config.cl_mouse_deadzone) - { - config.cl_mouse_followfactor = 0; - config.cl_mouse_max_distance = 400; - config.cl_mouse_deadzone = 0; - } - else - { - config.cl_mouse_followfactor = 60; - config.cl_mouse_max_distance = 1000; - config.cl_mouse_deadzone = 300; - } - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.cl_autoswitch_weapons, "Switch weapon on pickup", config.cl_autoswitch_weapons, &button, ui_draw_checkbox, 0)) - config.cl_autoswitch_weapons ^= 1; - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.cl_nameplates, "Show name plates", config.cl_nameplates, &button, ui_draw_checkbox, 0)) - config.cl_nameplates ^= 1; - - //if(config.cl_nameplates) - { - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - ui_vsplit_l(&button, 15.0f, 0, &button); - if (ui_do_button(&config.cl_nameplates_always, "Always show name plates", config.cl_nameplates_always, &button, ui_draw_checkbox, 0)) - config.cl_nameplates_always ^= 1; - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.player_color_body, "Custom colors", config.player_use_custom_color, &button, ui_draw_checkbox, 0)) - { - config.player_use_custom_color = config.player_use_custom_color?0:1; - need_sendinfo = true; - } - - if(config.player_use_custom_color) - { - int *colors[2]; - colors[0] = &config.player_color_body; - colors[1] = &config.player_color_feet; - - const char *parts[] = {"Body", "Feet"}; - const char *labels[] = {"Hue", "Sat.", "Lht."}; - static int color_slider[2][3] = {{0}}; - //static float v[2][3] = {{0, 0.5f, 0.25f}, {0, 0.5f, 0.25f}}; - - for(int i = 0; i < 2; i++) - { - RECT text; - ui_hsplit_t(&main_view, 20.0f, &text, &main_view); - ui_vsplit_l(&text, 15.0f, 0, &text); - ui_do_label(&text, parts[i], 14.0f, -1); - - int prevcolor = *colors[i]; - int color = 0; - for(int s = 0; s < 3; s++) - { - RECT text; - ui_hsplit_t(&main_view, 19.0f, &button, &main_view); - ui_vsplit_l(&button, 30.0f, 0, &button); - ui_vsplit_l(&button, 30.0f, &text, &button); - ui_vsplit_r(&button, 5.0f, &button, 0); - ui_hsplit_t(&button, 4.0f, 0, &button); - - float k = ((prevcolor>>((2-s)*8))&0xff) / 255.0f; - k = ui_do_scrollbar_h(&color_slider[i][s], &button, k); - color <<= 8; - color += clamp((int)(k*255), 0, 255); - ui_do_label(&text, labels[s], 15.0f, -1); - - } - - if(*colors[i] != color) - need_sendinfo = true; - - *colors[i] = color; - ui_hsplit_t(&main_view, 5.0f, 0, &main_view); - } - } - } - - // draw header - RECT header, footer; - ui_hsplit_t(&skinselection, 20, &header, &skinselection); - ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); - ui_do_label(&header, "Skins", 18.0f, 0); - - // draw footers - ui_hsplit_b(&skinselection, 20, &skinselection, &footer); - ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); - ui_vsplit_l(&footer, 10.0f, 0, &footer); - - // modes - ui_draw_rect(&skinselection, vec4(0,0,0,0.15f), 0, 0); - - RECT scroll; - ui_vsplit_r(&skinselection, 15, &skinselection, &scroll); - - RECT list = skinselection; - ui_hsplit_t(&list, 50, &button, &list); - - int num = (int)(skinselection.h/button.h); - static float scrollvalue = 0; - static int scrollbar = 0; - ui_hmargin(&scroll, 5.0f, &scroll); - scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue); - - int start = (int)((gameclient.skins->num()-num)*scrollvalue); - if(start < 0) - start = 0; - - for(int i = start; i < start+num && i < gameclient.skins->num(); i++) - { - const SKINS::SKIN *s = gameclient.skins->get(i); - - // no special skins - if(s->name[0] == 'x' && s->name[1] == '_') - { - num++; - continue; - } - - char buf[128]; - str_format(buf, sizeof(buf), "%s", s->name); - int selected = 0; - if(strcmp(s->name, config.player_skin) == 0) - selected = 1; - - TEE_RENDER_INFO info; - info.texture = s->org_texture; - info.color_body = vec4(1,1,1,1); - info.color_feet = vec4(1,1,1,1); - if(config.player_use_custom_color) - { - info.color_body = gameclient.skins->get_color(config.player_color_body); - info.color_feet = gameclient.skins->get_color(config.player_color_feet); - info.texture = s->color_texture; - } - - info.size = ui_scale()*50.0f; - - RECT icon; - RECT text; - ui_vsplit_l(&button, 50.0f, &icon, &text); - - if(ui_do_button(s, "", selected, &button, ui_draw_list_row, 0)) - { - config_set_player_skin(&config, s->name); - need_sendinfo = true; - } - - ui_hsplit_t(&text, 12.0f, 0, &text); // some margin from the top - ui_do_label(&text, buf, 18.0f, 0); - - ui_hsplit_t(&icon, 5.0f, 0, &icon); // some margin from the top - render_tee(ANIMSTATE::get_idle(), &info, 0, vec2(1, 0), vec2(icon.x+icon.w/2, icon.y+icon.h/2)); - - if(config.debug) - { - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(s->blood_color.r, s->blood_color.g, s->blood_color.b, 1.0f); - gfx_quads_drawTL(icon.x, icon.y, 12, 12); - gfx_quads_end(); - } - - ui_hsplit_t(&list, 50, &button, &list); - } -} - -typedef void (*assign_func_callback)(CONFIGURATION *config, int value); - -typedef struct -{ - const char *name; - const char *command; - int keyid; -} KEYINFO; - -KEYINFO keys[] = -{ - { "Move Left:", "+left", 0}, - { "Move Right:", "+right", 0 }, - { "Jump:", "+jump", 0 }, - { "Fire:", "+fire", 0 }, - { "Hook:", "+hook", 0 }, - { "Hammer:", "+weapon1", 0 }, - { "Pistol:", "+weapon2", 0 }, - { "Shotgun:", "+weapon3", 0 }, - { "Grenade:", "+weapon4", 0 }, - { "Rifle:", "+weapon5", 0 }, - { "Next Weapon:", "+nextweapon", 0 }, - { "Prev. Weapon:", "+prevweapon", 0 }, - { "Vote Yes:", "vote yes", 0 }, - { "Vote No:", "vote no", 0 }, - { "Chat:", "chat all", 0 }, - { "Team Chat:", "chat team", 0 }, - { "Emoticon:", "+emote", 0 }, - { "Console:", "toggle_local_console", 0 }, - { "Remote Console:", "toggle_remote_console", 0 }, - { "Screenshot:", "screenshot", 0 }, - { "Scoreboard:", "+scoreboard", 0 }, -}; - -const int key_count = sizeof(keys) / sizeof(KEYINFO); - -void MENUS::ui_do_getbuttons(int start, int stop, RECT view) -{ - for (int i = start; i < stop; i++) - { - KEYINFO key = keys[i]; - RECT button, label; - ui_hsplit_t(&view, 20.0f, &button, &view); - ui_vsplit_l(&button, 130.0f, &label, &button); - - ui_do_label(&label, key.name, 14.0f, -1); - int oldid = key.keyid; - int newid = ui_do_key_reader((void *)keys[i].name, &button, oldid); - if(newid != oldid) - { - gameclient.binds->bind(oldid, ""); - gameclient.binds->bind(newid, keys[i].command); - } - ui_hsplit_t(&view, 5.0f, 0, &view); - } -} - -void MENUS::render_settings_controls(RECT main_view) -{ - // this is kinda slow, but whatever - for(int i = 0; i < key_count; i++) - keys[i].keyid = 0; - - for(int keyid = 0; keyid < KEY_LAST; keyid++) - { - const char *bind = gameclient.binds->get(keyid); - if(!bind[0]) - continue; - - for(int i = 0; i < key_count; i++) - if(strcmp(bind, keys[i].command) == 0) - { - keys[i].keyid = keyid; - break; - } - } - - RECT movement_settings, weapon_settings, voting_settings, chat_settings, misc_settings, reset_button; - ui_vsplit_l(&main_view, main_view.w/2-5.0f, &movement_settings, &voting_settings); - - /* movement settings */ - { - ui_hsplit_t(&movement_settings, main_view.h/2-5.0f, &movement_settings, &weapon_settings); - ui_draw_rect(&movement_settings, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&movement_settings, 10.0f, &movement_settings); - - gfx_text(0, movement_settings.x, movement_settings.y, 14, "Movement", -1); - - ui_hsplit_t(&movement_settings, 14.0f+5.0f+10.0f, 0, &movement_settings); - - { - RECT button, label; - ui_hsplit_t(&movement_settings, 20.0f, &button, &movement_settings); - ui_vsplit_l(&button, 130.0f, &label, &button); - ui_do_label(&label, "Mouse sens.", 14.0f, -1); - ui_hmargin(&button, 2.0f, &button); - config.inp_mousesens = (int)(ui_do_scrollbar_h(&config.inp_mousesens, &button, (config.inp_mousesens-5)/500.0f)*500.0f)+5; - //*key.key = ui_do_key_reader(key.key, &button, *key.key); - ui_hsplit_t(&movement_settings, 20.0f, 0, &movement_settings); - } - - ui_do_getbuttons(0, 5, movement_settings); - - } - - /* weapon settings */ - { - ui_hsplit_t(&weapon_settings, 10.0f, 0, &weapon_settings); - ui_draw_rect(&weapon_settings, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&weapon_settings, 10.0f, &weapon_settings); - - gfx_text(0, weapon_settings.x, weapon_settings.y, 14, "Weapon", -1); - - ui_hsplit_t(&weapon_settings, 14.0f+5.0f+10.0f, 0, &weapon_settings); - ui_do_getbuttons(5, 12, weapon_settings); - } - - /* voting settings */ - { - ui_vsplit_l(&voting_settings, 10.0f, 0, &voting_settings); - ui_hsplit_t(&voting_settings, main_view.h/4-5.0f, &voting_settings, &chat_settings); - ui_draw_rect(&voting_settings, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&voting_settings, 10.0f, &voting_settings); - - gfx_text(0, voting_settings.x, voting_settings.y, 14, "Voting", -1); - - ui_hsplit_t(&voting_settings, 14.0f+5.0f+10.0f, 0, &voting_settings); - ui_do_getbuttons(12, 14, voting_settings); - } - - /* chat settings */ - { - ui_hsplit_t(&chat_settings, 10.0f, 0, &chat_settings); - ui_hsplit_t(&chat_settings, main_view.h/4-10.0f, &chat_settings, &misc_settings); - ui_draw_rect(&chat_settings, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&chat_settings, 10.0f, &chat_settings); - - gfx_text(0, chat_settings.x, chat_settings.y, 14, "Chat", -1); - - ui_hsplit_t(&chat_settings, 14.0f+5.0f+10.0f, 0, &chat_settings); - ui_do_getbuttons(14, 16, chat_settings); - } - - /* misc settings */ - { - ui_hsplit_t(&misc_settings, 10.0f, 0, &misc_settings); - ui_hsplit_t(&misc_settings, main_view.h/2-5.0f-45.0f, &misc_settings, &reset_button); - ui_draw_rect(&misc_settings, vec4(1,1,1,0.25f), CORNER_ALL, 10.0f); - ui_margin(&misc_settings, 10.0f, &misc_settings); - - gfx_text(0, misc_settings.x, misc_settings.y, 14, "Miscellaneous", -1); - - ui_hsplit_t(&misc_settings, 14.0f+5.0f+10.0f, 0, &misc_settings); - ui_do_getbuttons(16, 21, misc_settings); - } - - // defaults - ui_hsplit_t(&reset_button, 10.0f, 0, &reset_button); - static int default_button = 0; - if (ui_do_button((void*)&default_button, "Reset to defaults", 0, &reset_button, ui_draw_menu_button, 0)) - gameclient.binds->set_defaults(); -} - -void MENUS::render_settings_graphics(RECT main_view) -{ - RECT button; - char buf[128]; - - static const int MAX_RESOLUTIONS = 256; - static VIDEO_MODE modes[MAX_RESOLUTIONS]; - static int num_modes = -1; - - if(num_modes == -1) - num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS); - - RECT modelist; - ui_vsplit_l(&main_view, 300.0f, &main_view, &modelist); - - // draw allmodes switch - RECT header, footer; - ui_hsplit_t(&modelist, 20, &button, &modelist); - if (ui_do_button(&config.gfx_display_all_modes, "Show only supported", config.gfx_display_all_modes^1, &button, ui_draw_checkbox, 0)) - { - config.gfx_display_all_modes ^= 1; - num_modes = gfx_get_video_modes(modes, MAX_RESOLUTIONS); - } - - // draw header - ui_hsplit_t(&modelist, 20, &header, &modelist); - ui_draw_rect(&header, vec4(1,1,1,0.25f), CORNER_T, 5.0f); - ui_do_label(&header, "Display Modes", 14.0f, 0); - - // draw footers - ui_hsplit_b(&modelist, 20, &modelist, &footer); - str_format(buf, sizeof(buf), "Current: %dx%d %d bit", config.gfx_screen_width, config.gfx_screen_height, config.gfx_color_depth); - ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f); - ui_vsplit_l(&footer, 10.0f, 0, &footer); - ui_do_label(&footer, buf, 14.0f, -1); - - // modes - ui_draw_rect(&modelist, vec4(0,0,0,0.15f), 0, 0); - - RECT scroll; - ui_vsplit_r(&modelist, 15, &modelist, &scroll); - - RECT list = modelist; - ui_hsplit_t(&list, 20, &button, &list); - - int num = (int)(modelist.h/button.h); - static float scrollvalue = 0; - static int scrollbar = 0; - ui_hmargin(&scroll, 5.0f, &scroll); - scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue); - - int start = (int)((num_modes-num)*scrollvalue); - if(start < 0) - start = 0; - - for(int i = start; i < start+num && i < num_modes; i++) - { - int depth = modes[i].red+modes[i].green+modes[i].blue; - if(depth < 16) - depth = 16; - else if(depth > 16) - depth = 24; - - int selected = 0; - if(config.gfx_color_depth == depth && - config.gfx_screen_width == modes[i].width && - config.gfx_screen_height == modes[i].height) - { - selected = 1; - } - - str_format(buf, sizeof(buf), " %dx%d %d bit", modes[i].width, modes[i].height, depth); - if(ui_do_button(&modes[i], buf, selected, &button, ui_draw_list_row, 0)) - { - config.gfx_color_depth = depth; - config.gfx_screen_width = modes[i].width; - config.gfx_screen_height = modes[i].height; - if(!selected) - need_restart = true; - } - - ui_hsplit_t(&list, 20, &button, &list); - } - - - // switches - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_fullscreen, "Fullscreen", config.gfx_fullscreen, &button, ui_draw_checkbox, 0)) - { - config.gfx_fullscreen ^= 1; - need_restart = true; - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_vsync, "V-Sync", config.gfx_vsync, &button, ui_draw_checkbox, 0)) - { - config.gfx_vsync ^= 1; - need_restart = true; - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_fsaa_samples, "FSAA samples", config.gfx_fsaa_samples, &button, ui_draw_checkbox_number, 0)) - { - config.gfx_fsaa_samples = (config.gfx_fsaa_samples+1)%17; - need_restart = true; - } - - ui_hsplit_t(&main_view, 40.0f, &button, &main_view); - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_texture_quality, "Quality Textures", config.gfx_texture_quality, &button, ui_draw_checkbox, 0)) - { - config.gfx_texture_quality ^= 1; - need_restart = true; - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_texture_compression, "Texture Compression", config.gfx_texture_compression, &button, ui_draw_checkbox, 0)) - { - config.gfx_texture_compression ^= 1; - need_restart = true; - } - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.gfx_high_detail, "High Detail", config.gfx_high_detail, &button, ui_draw_checkbox, 0)) - config.gfx_high_detail ^= 1; - - // - - RECT text; - ui_hsplit_t(&main_view, 20.0f, 0, &main_view); - ui_hsplit_t(&main_view, 20.0f, &text, &main_view); - //ui_vsplit_l(&text, 15.0f, 0, &text); - ui_do_label(&text, "UI Color", 14.0f, -1); - - const char *labels[] = {"Hue", "Sat.", "Lht.", "Alpha"}; - int *color_slider[4] = {&config.ui_color_hue, &config.ui_color_sat, &config.ui_color_lht, &config.ui_color_alpha}; - for(int s = 0; s < 4; s++) - { - RECT text; - ui_hsplit_t(&main_view, 19.0f, &button, &main_view); - ui_vmargin(&button, 15.0f, &button); - ui_vsplit_l(&button, 50.0f, &text, &button); - ui_vsplit_r(&button, 5.0f, &button, 0); - ui_hsplit_t(&button, 4.0f, 0, &button); - - float k = (*color_slider[s]) / 255.0f; - k = ui_do_scrollbar_h(color_slider[s], &button, k); - *color_slider[s] = (int)(k*255.0f); - ui_do_label(&text, labels[s], 15.0f, -1); - } -} - -void MENUS::render_settings_sound(RECT main_view) -{ - RECT button; - ui_vsplit_l(&main_view, 300.0f, &main_view, 0); - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.snd_enable, "Use Sounds", config.snd_enable, &button, ui_draw_checkbox, 0)) - { - config.snd_enable ^= 1; - need_restart = true; - } - - if(!config.snd_enable) - return; - - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - if (ui_do_button(&config.snd_nonactive_mute, "Mute when not active", config.snd_nonactive_mute, &button, ui_draw_checkbox, 0)) - config.snd_nonactive_mute ^= 1; - - // sample rate box - { - char buf[64]; - str_format(buf, sizeof(buf), "%d", config.snd_rate); - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - ui_do_label(&button, "Sample Rate", 14.0f, -1); - ui_vsplit_l(&button, 110.0f, 0, &button); - ui_vsplit_l(&button, 180.0f, &button, 0); - ui_do_edit_box(&config.snd_rate, &button, buf, sizeof(buf), 14.0f); - int before = config.snd_rate; - config.snd_rate = atoi(buf); - - if(config.snd_rate != before) - need_restart = true; - - if(config.snd_rate < 1) - config.snd_rate = 1; - } - - // volume slider - { - RECT button, label; - ui_hsplit_t(&main_view, 5.0f, &button, &main_view); - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - ui_vsplit_l(&button, 110.0f, &label, &button); - ui_hmargin(&button, 2.0f, &button); - ui_do_label(&label, "Sound Volume", 14.0f, -1); - config.snd_volume = (int)(ui_do_scrollbar_h(&config.snd_volume, &button, config.snd_volume/100.0f)*100.0f); - ui_hsplit_t(&main_view, 20.0f, 0, &main_view); - } -} - - - /* -static void menu2_render_settings_network(RECT main_view) -{ - RECT button; - ui_vsplit_l(&main_view, 300.0f, &main_view, 0); - - { - ui_hsplit_t(&main_view, 20.0f, &button, &main_view); - ui_do_label(&button, "Rcon Password", 14.0, -1); - ui_vsplit_l(&button, 110.0f, 0, &button); - ui_vsplit_l(&button, 180.0f, &button, 0); - ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true); - } -}*/ - -void MENUS::render_settings(RECT main_view) -{ - static int settings_page = 0; - - // render background - RECT temp, tabbar; - ui_vsplit_r(&main_view, 120.0f, &main_view, &tabbar); - ui_draw_rect(&main_view, color_tabbar_active, CORNER_B|CORNER_TL, 10.0f); - ui_hsplit_t(&tabbar, 50.0f, &temp, &tabbar); - ui_draw_rect(&temp, color_tabbar_active, CORNER_R, 10.0f); - - ui_hsplit_t(&main_view, 10.0f, 0, &main_view); - - RECT button; - - const char *tabs[] = {"Player", "Controls", "Graphics", "Sound"}; - int num_tabs = (int)(sizeof(tabs)/sizeof(*tabs)); - - for(int i = 0; i < num_tabs; i++) - { - ui_hsplit_t(&tabbar, 10, &button, &tabbar); - ui_hsplit_t(&tabbar, 26, &button, &tabbar); - if(ui_do_button(tabs[i], tabs[i], settings_page == i, &button, ui_draw_settings_tab_button, 0)) - settings_page = i; - } - - ui_margin(&main_view, 10.0f, &main_view); - - if(settings_page == 0) - render_settings_player(main_view); - else if(settings_page == 1) - render_settings_controls(main_view); - else if(settings_page == 2) - render_settings_graphics(main_view); - else if(settings_page == 3) - render_settings_sound(main_view); - - if(need_restart) - { - RECT restart_warning; - ui_hsplit_b(&main_view, 40, &main_view, &restart_warning); - ui_do_label(&restart_warning, "You must restart the game for all settings to take effect.", 15.0f, -1, 220); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.cpp deleted file mode 100644 index 3b8f2243b..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include - -#include - -#include "motd.hpp" - -void MOTD::on_reset() -{ - clear(); -} - -void MOTD::clear() -{ - server_motd_time = 0; -} - -bool MOTD::is_active() -{ - return time_get() < server_motd_time; -} - -void MOTD::on_render() -{ - if(!is_active()) - return; - - float width = 400*3.0f*gfx_screenaspect(); - float height = 400*3.0f; - - gfx_mapscreen(0, 0, width, height); - - float h = 800.0f; - float w = 650.0f; - float x = width/2 - w/2; - float y = 150.0f; - - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.5f); - draw_round_rect(x, y, w, h, 40.0f); - gfx_quads_end(); - - gfx_text(0, x+40.0f, y+40.0f, 32.0f, server_motd, (int)(w-80.0f)); -} - -void MOTD::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_MOTD) - { - NETMSG_SV_MOTD *msg = (NETMSG_SV_MOTD *)rawmsg; - - // process escaping - str_copy(server_motd, msg->message, sizeof(server_motd)); - for(int i = 0; server_motd[i]; i++) - { - if(server_motd[i] == '\\') - { - if(server_motd[i+1] == 'n') - { - server_motd[i] = ' '; - server_motd[i+1] = '\n'; - i++; - } - } - } - - if(server_motd[0] && config.cl_motd_time) - server_motd_time = time_get()+time_freq()*config.cl_motd_time; - else - server_motd_time = 0; - } -} - -bool MOTD::on_input(INPUT_EVENT e) -{ - if(is_active() && e.flags&INPFLAG_PRESS && e.key == KEY_ESCAPE) - { - clear(); - return true; - } - return false; -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.hpp deleted file mode 100644 index 5ee16086e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/motd.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -class MOTD : public COMPONENT -{ - // motd - int64 server_motd_time; -public: - char server_motd[900]; - - void clear(); - bool is_active(); - - virtual void on_reset(); - virtual void on_render(); - virtual void on_message(int msgtype, void *rawmsg); - virtual bool on_input(INPUT_EVENT e); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.cpp deleted file mode 100644 index 4a47ea376..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include - -#include -#include -#include "nameplates.hpp" -#include "controls.hpp" - -void NAMEPLATES::render_nameplate( - const NETOBJ_CHARACTER *prev_char, - const NETOBJ_CHARACTER *player_char, - const NETOBJ_PLAYER_INFO *player_info - ) -{ - float intratick = client_intratick(); - - vec2 position = mix(vec2(prev_char->x, prev_char->y), vec2(player_char->x, player_char->y), intratick); - - // render name plate - if(!player_info->local) - { - //gfx_text_color - float a = 1; - if(config.cl_nameplates_always == 0) - a = clamp(1-powf(distance(gameclient.controls->target_pos, position)/200.0f,16.0f), 0.0f, 1.0f); - - const char *name = gameclient.clients[player_info->cid].name; - float tw = gfx_text_width(0, 28.0f, name, -1); - gfx_text_color(1,1,1,a); - gfx_text(0, position.x-tw/2.0f, position.y-60, 28.0f, name, -1); - - if(config.debug) // render client id when in debug aswell - { - char buf[128]; - str_format(buf, sizeof(buf),"%d", player_info->cid); - gfx_text(0, position.x, position.y-90, 28.0f, buf, -1); - } - - gfx_text_color(1,1,1,1); - } -} - -void NAMEPLATES::on_render() -{ - if (!config.cl_nameplates) - return; - - for(int i = 0; i < MAX_CLIENTS; i++) - { - // only render active characters - if(!gameclient.snap.characters[i].active) - continue; - - const void *info = snap_find_item(SNAP_CURRENT, NETOBJTYPE_PLAYER_INFO, i); - - if(info) - { - render_nameplate( - &gameclient.snap.characters[i].prev, - &gameclient.snap.characters[i].cur, - (const NETOBJ_PLAYER_INFO *)info); - } - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.hpp deleted file mode 100644 index 2695f5ac0..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/nameplates.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#include - -class NAMEPLATES : public COMPONENT -{ - void render_nameplate( - const class NETOBJ_CHARACTER *prev_char, - const class NETOBJ_CHARACTER *player_char, - const class NETOBJ_PLAYER_INFO *player_info - ); - -public: - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.cpp deleted file mode 100644 index ef6dbbe90..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include -#include -#include "particles.hpp" - -PARTICLES::PARTICLES() -{ - on_reset(); - render_trail.parts = this; - render_explosions.parts = this; - render_general.parts = this; -} - - -void PARTICLES::on_reset() -{ - // reset particles - for(int i = 0; i < MAX_PARTICLES; i++) - { - particles[i].prev_part = i-1; - particles[i].next_part = i+1; - } - - particles[0].prev_part = 0; - particles[MAX_PARTICLES-1].next_part = -1; - first_free = 0; - - for(int i = 0; i < NUM_GROUPS; i++) - first_part[i] = -1; -} - -void PARTICLES::add(int group, PARTICLE *part) -{ - if (first_free == -1) - return; - - // remove from the free list - int id = first_free; - first_free = particles[id].next_part; - particles[first_free].prev_part = -1; - - // copy data - particles[id] = *part; - - // insert to the group list - particles[id].prev_part = -1; - particles[id].next_part = first_part[group]; - if(first_part[group] != -1) - particles[first_part[group]].prev_part = id; - first_part[group] = id; - - // set some parameters - particles[id].life = 0; -} - -void PARTICLES::update(float time_passed) -{ - static float friction_fraction = 0; - friction_fraction += time_passed; - - if(friction_fraction > 2.0f) // safty messure - friction_fraction = 0; - - int friction_count = 0; - while(friction_fraction > 0.05f) - { - friction_count++; - friction_fraction -= 0.05f; - } - - for(int g = 0; g < NUM_GROUPS; g++) - { - int i = first_part[g]; - while(i != -1) - { - int next = particles[i].next_part; - //particles[i].vel += flow_get(particles[i].pos)*time_passed * particles[i].flow_affected; - particles[i].vel.y += particles[i].gravity*time_passed; - - for(int f = 0; f < friction_count; f++) // apply friction - particles[i].vel *= particles[i].friction; - - // move the point - vec2 vel = particles[i].vel*time_passed; - move_point(&particles[i].pos, &vel, 0.1f+0.9f*frandom(), NULL); - particles[i].vel = vel* (1.0f/time_passed); - - particles[i].life += time_passed; - particles[i].rot += time_passed * particles[i].rotspeed; - - // check particle death - if(particles[i].life > particles[i].life_span) - { - // remove it from the group list - if(particles[i].prev_part != -1) - particles[particles[i].prev_part].next_part = particles[i].next_part; - else - first_part[g] = particles[i].next_part; - - if(particles[i].next_part != -1) - particles[particles[i].next_part].prev_part = particles[i].prev_part; - - // insert to the free list - if(first_free != -1) - particles[first_free].prev_part = i; - particles[i].prev_part = -1; - particles[i].next_part = first_free; - first_free = i; - } - - i = next; - } - } -} - -void PARTICLES::on_render() -{ - static int64 lasttime = 0; - int64 t = time_get(); - update((float)((t-lasttime)/(double)time_freq())); - lasttime = t; -} - -void PARTICLES::render_group(int group) -{ - gfx_blend_normal(); - //gfx_blend_additive(); - gfx_texture_set(data->images[IMAGE_PARTICLES].id); - gfx_quads_begin(); - - int i = first_part[group]; - while(i != -1) - { - select_sprite(particles[i].spr); - float a = particles[i].life / particles[i].life_span; - vec2 p = particles[i].pos; - float size = mix(particles[i].start_size, particles[i].end_size, a); - - gfx_quads_setrotation(particles[i].rot); - - gfx_setcolor( - particles[i].color.r, - particles[i].color.g, - particles[i].color.b, - particles[i].color.a); // pow(a, 0.75f) * - - gfx_quads_draw(p.x, p.y, size, size); - - i = particles[i].next_part; - } - gfx_quads_end(); - gfx_blend_normal(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.hpp deleted file mode 100644 index 6c466d941..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/particles.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include - -// particles -struct PARTICLE -{ - void set_default() - { - vel = vec2(0,0); - life_span = 0; - start_size = 32; - end_size = 32; - rot = 0; - rotspeed = 0; - gravity = 0; - friction = 0; - flow_affected = 1.0f; - color = vec4(1,1,1,1); - } - - vec2 pos; - vec2 vel; - - int spr; - - float flow_affected; - - float life_span; - - float start_size; - float end_size; - - float rot; - float rotspeed; - - float gravity; - float friction; - - vec4 color; - - // set by the particle system - float life; - int prev_part; - int next_part; -}; - -class PARTICLES : public COMPONENT -{ - friend class GAMECLIENT; -public: - enum - { - GROUP_PROJECTILE_TRAIL=0, - GROUP_EXPLOSIONS, - GROUP_GENERAL, - NUM_GROUPS - }; - - PARTICLES(); - - void add(int group, PARTICLE *part); - - virtual void on_reset(); - virtual void on_render(); - -private: - - enum - { - MAX_PARTICLES=1024*8, - }; - - PARTICLE particles[MAX_PARTICLES]; - int first_free; - int first_part[NUM_GROUPS]; - - void render_group(int group); - void update(float time_passed); - - template - class RENDER_GROUP : public COMPONENT - { - public: - PARTICLES *parts; - virtual void on_render() { parts->render_group(TGROUP); } - }; - - RENDER_GROUP render_trail; - RENDER_GROUP render_explosions; - RENDER_GROUP render_general; -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.cpp deleted file mode 100644 index af1700de6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.cpp +++ /dev/null @@ -1,494 +0,0 @@ -#include -#include -#include - -#include // get_angle -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "players.hpp" - -void PLAYERS::render_hand(TEE_RENDER_INFO *info, vec2 center_pos, vec2 dir, float angle_offset, vec2 post_rot_offset) -{ - // for drawing hand - //const skin *s = skin_get(skin_id); - - float basesize = 10.0f; - //dir = normalize(hook_pos-pos); - - vec2 hand_pos = center_pos + dir; - float angle = get_angle(dir); - if (dir.x < 0) - angle -= angle_offset; - else - angle += angle_offset; - - vec2 dirx = dir; - vec2 diry(-dir.y,dir.x); - - if (dir.x < 0) - diry = -diry; - - hand_pos += dirx * post_rot_offset.x; - hand_pos += diry * post_rot_offset.y; - - //gfx_texture_set(data->images[IMAGE_CHAR_DEFAULT].id); - gfx_texture_set(info->texture); - gfx_quads_begin(); - gfx_setcolor(info->color_body.r, info->color_body.g, info->color_body.b, info->color_body.a); - - // two passes - for (int i = 0; i < 2; i++) - { - bool outline = i == 0; - - select_sprite(outline?SPRITE_TEE_HAND_OUTLINE:SPRITE_TEE_HAND, 0, 0, 0); - gfx_quads_setrotation(angle); - gfx_quads_draw(hand_pos.x, hand_pos.y, 2*basesize, 2*basesize); - } - - gfx_quads_setrotation(0); - gfx_quads_end(); -} - -inline float normalize_angular(float f) -{ - return fmod(f+pi*2, pi*2); -} - -inline float angular_mix_direction(float src, float dst) { return sinf(dst-src) >0?1:-1; } -inline float angular_distance(float src, float dst) { return asinf(sinf(dst-src)); } - -inline float angular_approach(float src, float dst, float amount) -{ - float d = angular_mix_direction(src, dst); - float n = src + amount*d; - if(angular_mix_direction(n, dst) != d) - return dst; - return n; -} - -void PLAYERS::render_player( - const NETOBJ_CHARACTER *prev_char, - const NETOBJ_CHARACTER *player_char, - const NETOBJ_PLAYER_INFO *prev_info, - const NETOBJ_PLAYER_INFO *player_info - ) -{ - NETOBJ_CHARACTER prev; - NETOBJ_CHARACTER player; - prev = *prev_char; - player = *player_char; - - NETOBJ_PLAYER_INFO info = *player_info; - TEE_RENDER_INFO render_info = gameclient.clients[info.cid].render_info; - - // check for teamplay modes - bool is_teamplay = false; - bool new_tick = gameclient.new_tick; - if(gameclient.snap.gameobj) - is_teamplay = (gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS) != 0; - - // check for ninja - if (player.weapon == WEAPON_NINJA) - { - // change the skin for the player to the ninja - int skin = gameclient.skins->find("x_ninja"); - if(skin != -1) - { - if(is_teamplay) - render_info.texture = gameclient.skins->get(skin)->color_texture; - else - { - render_info.texture = gameclient.skins->get(skin)->org_texture; - render_info.color_body = vec4(1,1,1,1); - render_info.color_feet = vec4(1,1,1,1); - } - } - } - - // set size - render_info.size = 64.0f; - - float intratick = client_intratick(); - - if(player.health < 0) // dont render dead players - return; - - float angle = mix((float)prev.angle, (float)player.angle, intratick)/256.0f; - - //float angle = 0; - - if(info.local && client_state() != CLIENTSTATE_DEMOPLAYBACK) - { - // just use the direct input if it's local player we are rendering - angle = get_angle(gameclient.controls->mouse_pos); - } - else - { - /* - float mixspeed = client_frametime()*2.5f; - if(player.attacktick != prev.attacktick) // shooting boosts the mixing speed - mixspeed *= 15.0f; - - // move the delta on a constant speed on a x^2 curve - float current = gameclient.clients[info.cid].angle; - float target = player.angle/256.0f; - float delta = angular_distance(current, target); - float sign = delta < 0 ? -1 : 1; - float new_delta = delta - 2*mixspeed*sqrt(delta*sign)*sign + mixspeed*mixspeed; - - // make sure that it doesn't vibrate when it's still - if(fabs(delta) < 2/256.0f) - angle = target; - else - angle = angular_approach(current, target, fabs(delta-new_delta)); - - gameclient.clients[info.cid].angle = angle;*/ - } - - // use preditect players if needed - if(info.local && config.cl_predict && client_state() != CLIENTSTATE_DEMOPLAYBACK) - { - if(!gameclient.snap.local_character || (gameclient.snap.local_character->health < 0) || (gameclient.snap.gameobj && gameclient.snap.gameobj->game_over)) - { - } - else - { - // apply predicted results - gameclient.predicted_char.write(&player); - gameclient.predicted_prev_char.write(&prev); - intratick = client_predintratick(); - new_tick = gameclient.new_predicted_tick; - } - } - - vec2 direction = get_direction((int)(angle*256.0f)); - vec2 position = mix(vec2(prev.x, prev.y), vec2(player.x, player.y), intratick); - vec2 vel = mix(vec2(prev.vx/256.0f, prev.vy/256.0f), vec2(player.vx/256.0f, player.vy/256.0f), intratick); - - gameclient.flow->add(position, vel*100.0f, 10.0f); - - render_info.got_airjump = player.jumped&2?0:1; - - - // detect events - if(new_tick) - { - // detect air jump - if(!render_info.got_airjump && !(prev.jumped&2)) - gameclient.effects->air_jump(position); - } - - if(prev.health < 0) // Don't flicker from previous position - position = vec2(player.x, player.y); - - bool stationary = player.vx <= 1 && player.vx >= -1; - bool inair = col_check_point(player.x, player.y+16) == 0; - bool want_other_dir = (player.direction == -1 && vel.x > 0) || (player.direction == 1 && vel.x < 0); - - // evaluate animation - float walk_time = fmod(position.x, 100.0f)/100.0f; - ANIMSTATE state; - state.set(&data->animations[ANIM_BASE], 0); - - if(inair) - state.add(&data->animations[ANIM_INAIR], 0, 1.0f); // TODO: some sort of time here - else if(stationary) - state.add(&data->animations[ANIM_IDLE], 0, 1.0f); // TODO: some sort of time here - else if(!want_other_dir) - state.add(&data->animations[ANIM_WALK], walk_time, 1.0f); - - if (player.weapon == WEAPON_HAMMER) - { - float ct = (client_prevtick()-player.attacktick)/(float)SERVER_TICK_SPEED + client_ticktime(); - state.add(&data->animations[ANIM_HAMMER_SWING], clamp(ct*5.0f,0.0f,1.0f), 1.0f); - } - if (player.weapon == WEAPON_NINJA) - { - float ct = (client_prevtick()-player.attacktick)/(float)SERVER_TICK_SPEED + client_ticktime(); - state.add(&data->animations[ANIM_NINJA_SWING], clamp(ct*2.0f,0.0f,1.0f), 1.0f); - } - - // do skidding - if(!inair && want_other_dir && length(vel*50) > 500.0f) - { - static int64 skid_sound_time = 0; - if(time_get()-skid_sound_time > time_freq()/10) - { - gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_PLAYER_SKID, 0.25f, position); - skid_sound_time = time_get(); - } - - gameclient.effects->skidtrail( - position+vec2(-player.direction*6,12), - vec2(-player.direction*100*length(vel),-50) - ); - } - - // draw hook - if (prev.hook_state>0 && player.hook_state>0) - { - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - //gfx_quads_begin(); - - vec2 pos = position; - vec2 hook_pos; - - if(player_char->hooked_player != -1) - { - if(gameclient.snap.local_info && player_char->hooked_player == gameclient.snap.local_info->cid) - { - hook_pos = mix(vec2(gameclient.predicted_prev_char.pos.x, gameclient.predicted_prev_char.pos.y), - vec2(gameclient.predicted_char.pos.x, gameclient.predicted_char.pos.y), client_predintratick()); - } - else - hook_pos = mix(vec2(prev_char->hook_x, prev_char->hook_y), vec2(player_char->hook_x, player_char->hook_y), client_intratick()); - } - else - hook_pos = mix(vec2(prev.hook_x, prev.hook_y), vec2(player.hook_x, player.hook_y), intratick); - - float d = distance(pos, hook_pos); - vec2 dir = normalize(pos-hook_pos); - - gfx_quads_setrotation(get_angle(dir)+pi); - - // render head - select_sprite(SPRITE_HOOK_HEAD); - gfx_quads_draw(hook_pos.x, hook_pos.y, 24,16); - - // render chain - select_sprite(SPRITE_HOOK_CHAIN); - int i = 0; - for(float f = 24; f < d && i < 1024; f += 24, i++) - { - vec2 p = hook_pos + dir*f; - gfx_quads_draw(p.x, p.y,24,16); - } - - gfx_quads_setrotation(0); - gfx_quads_end(); - - render_hand(&render_info, position, normalize(hook_pos-pos), -pi/2, vec2(20, 0)); - } - - // draw gun - { - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - gfx_quads_setrotation(state.attach.angle*pi*2+angle); - - // normal weapons - int iw = clamp(player.weapon, 0, NUM_WEAPONS-1); - select_sprite(data->weapons.id[iw].sprite_body, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); - - vec2 dir = direction; - float recoil = 0.0f; - vec2 p; - if (player.weapon == WEAPON_HAMMER) - { - // Static position for hammer - p = position + vec2(state.attach.x, state.attach.y); - p.y += data->weapons.id[iw].offsety; - // if attack is under way, bash stuffs - if(direction.x < 0) - { - gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2); - p.x -= data->weapons.id[iw].offsetx; - } - else - { - gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2); - } - draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); - } - else if (player.weapon == WEAPON_NINJA) - { - p = position; - p.y += data->weapons.id[iw].offsety; - - if(direction.x < 0) - { - gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2); - p.x -= data->weapons.id[iw].offsetx; - gameclient.effects->powerupshine(p+vec2(32,0), vec2(32,12)); - } - else - { - gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2); - gameclient.effects->powerupshine(p-vec2(32,0), vec2(32,12)); - } - draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); - - // HADOKEN - if ((client_tick()-player.attacktick) <= (SERVER_TICK_SPEED / 6) && data->weapons.id[iw].num_sprite_muzzles) - { - int itex = rand() % data->weapons.id[iw].num_sprite_muzzles; - float alpha = 1.0f; - if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex]) - { - vec2 dir = vec2(player_char->x,player_char->y) - vec2(prev_char->x, prev_char->y); - dir = normalize(dir); - float hadokenangle = get_angle(dir); - gfx_quads_setrotation(hadokenangle); - //float offsety = -data->weapons[iw].muzzleoffsety; - select_sprite(data->weapons.id[iw].sprite_muzzles[itex], 0); - vec2 diry(-dir.y,dir.x); - p = position; - float offsetx = data->weapons.id[iw].muzzleoffsetx; - p -= dir * offsetx; - draw_sprite(p.x, p.y, 160.0f); - } - } - } - else - { - // TODO: should be an animation - recoil = 0; - float a = (client_tick()-player.attacktick+intratick)/5.0f; - if(a < 1) - recoil = sinf(a*pi); - p = position + dir * data->weapons.id[iw].offsetx - dir*recoil*10.0f; - p.y += data->weapons.id[iw].offsety; - draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); - } - - if (player.weapon == WEAPON_GUN || player.weapon == WEAPON_SHOTGUN) - { - // check if we're firing stuff - if(data->weapons.id[iw].num_sprite_muzzles)//prev.attackticks) - { - float alpha = 0.0f; - int phase1tick = (client_tick() - player.attacktick); - if (phase1tick < (data->weapons.id[iw].muzzleduration + 3)) - { - float t = ((((float)phase1tick) + intratick)/(float)data->weapons.id[iw].muzzleduration); - alpha = LERP(2.0, 0.0f, min(1.0f,max(0.0f,t))); - } - - int itex = rand() % data->weapons.id[iw].num_sprite_muzzles; - if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex]) - { - float offsety = -data->weapons.id[iw].muzzleoffsety; - select_sprite(data->weapons.id[iw].sprite_muzzles[itex], direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); - if(direction.x < 0) - offsety = -offsety; - - vec2 diry(-dir.y,dir.x); - vec2 muzzlepos = p + dir * data->weapons.id[iw].muzzleoffsetx + diry * offsety; - - draw_sprite(muzzlepos.x, muzzlepos.y, data->weapons.id[iw].visual_size); - } - } - } - gfx_quads_end(); - - switch (player.weapon) - { - case WEAPON_GUN: render_hand(&render_info, p, direction, -3*pi/4, vec2(-15, 4)); break; - case WEAPON_SHOTGUN: render_hand(&render_info, p, direction, -pi/2, vec2(-5, 4)); break; - case WEAPON_GRENADE: render_hand(&render_info, p, direction, -pi/2, vec2(-4, 7)); break; - } - - } - - // render the "shadow" tee - if(info.local && config.debug) - { - vec2 ghost_position = mix(vec2(prev_char->x, prev_char->y), vec2(player_char->x, player_char->y), client_intratick()); - TEE_RENDER_INFO ghost = render_info; - ghost.color_body.a = 0.5f; - ghost.color_feet.a = 0.5f; - render_tee(&state, &ghost, player.emote, direction, ghost_position); // render ghost - } - - render_info.size = 64.0f; // force some settings - render_info.color_body.a = 1.0f; - render_info.color_feet.a = 1.0f; - render_tee(&state, &render_info, player.emote, direction, position); - - if(player.player_state == PLAYERSTATE_CHATTING) - { - gfx_texture_set(data->images[IMAGE_EMOTICONS].id); - gfx_quads_begin(); - select_sprite(SPRITE_DOTDOT); - gfx_quads_draw(position.x + 24, position.y - 40, 64,64); - gfx_quads_end(); - } - - if (gameclient.clients[info.cid].emoticon_start != -1 && gameclient.clients[info.cid].emoticon_start + 2 * client_tickspeed() > client_tick()) - { - gfx_texture_set(data->images[IMAGE_EMOTICONS].id); - gfx_quads_begin(); - - int since_start = client_tick() - gameclient.clients[info.cid].emoticon_start; - int from_end = gameclient.clients[info.cid].emoticon_start + 2 * client_tickspeed() - client_tick(); - - float a = 1; - - if (from_end < client_tickspeed() / 5) - a = from_end / (client_tickspeed() / 5.0); - - float h = 1; - if (since_start < client_tickspeed() / 10) - h = since_start / (client_tickspeed() / 10.0); - - float wiggle = 0; - if (since_start < client_tickspeed() / 5) - wiggle = since_start / (client_tickspeed() / 5.0); - - float wiggle_angle = sin(5*wiggle); - - gfx_quads_setrotation(pi/6*wiggle_angle); - - gfx_setcolor(1.0f,1.0f,1.0f,a); - // client_datas::emoticon is an offset from the first emoticon - select_sprite(SPRITE_OOP + gameclient.clients[info.cid].emoticon); - gfx_quads_draw(position.x, position.y - 23 - 32*h, 64, 64*h); - gfx_quads_end(); - } -} - -void PLAYERS::on_render() -{ - // render other players in two passes, first pass we render the other, second pass we render our self - for(int p = 0; p < 2; p++) - { - for(int i = 0; i < MAX_CLIENTS; i++) - { - // only render active characters - if(!gameclient.snap.characters[i].active) - continue; - - const void *prev_info = snap_find_item(SNAP_PREV, NETOBJTYPE_PLAYER_INFO, i); - const void *info = snap_find_item(SNAP_CURRENT, NETOBJTYPE_PLAYER_INFO, i); - - if(prev_info && info) - { - // - bool local = ((const NETOBJ_PLAYER_INFO *)info)->local !=0; - if(p == 0 && local) continue; - if(p == 1 && !local) continue; - - NETOBJ_CHARACTER prev_char = gameclient.snap.characters[i].prev; - NETOBJ_CHARACTER cur_char = gameclient.snap.characters[i].cur; - - render_player( - &prev_char, - &cur_char, - (const NETOBJ_PLAYER_INFO *)prev_info, - (const NETOBJ_PLAYER_INFO *)info - ); - } - } - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.hpp deleted file mode 100644 index bdce91de3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/players.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -class PLAYERS : public COMPONENT -{ - void render_hand(class TEE_RENDER_INFO *info, vec2 center_pos, vec2 dir, float angle_offset, vec2 post_rot_offset); - void render_player( - const class NETOBJ_CHARACTER *prev_char, - const class NETOBJ_CHARACTER *player_char, - const class NETOBJ_PLAYER_INFO *prev_info, - const class NETOBJ_PLAYER_INFO *player_info - ); - -public: - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.cpp deleted file mode 100644 index dc1c42837..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "scoreboard.hpp" - - -SCOREBOARD::SCOREBOARD() -{ - on_reset(); -} - -void SCOREBOARD::con_key_scoreboard(void *result, void *user_data) -{ - ((SCOREBOARD *)user_data)->active = console_arg_int(result, 0) != 0; -} - -void SCOREBOARD::on_reset() -{ - active = false; -} - -void SCOREBOARD::on_console_init() -{ - MACRO_REGISTER_COMMAND("+scoreboard", "", CFGFLAG_CLIENT, con_key_scoreboard, this, "Show scoreboard"); -} - -void SCOREBOARD::render_goals(float x, float y, float w) -{ - float h = 50.0f; - - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.5f); - draw_round_rect(x-10.f, y-10.f, w, h, 10.0f); - gfx_quads_end(); - - // render goals - //y = ystart+h-54; - float tw = 0.0f; - if(gameclient.snap.gameobj && gameclient.snap.gameobj->score_limit) - { - char buf[64]; - str_format(buf, sizeof(buf), "Score Limit: %d", gameclient.snap.gameobj->score_limit); - gfx_text(0, x+20.0f, y, 22.0f, buf, -1); - tw += gfx_text_width(0, 22.0f, buf, -1); - } - if(gameclient.snap.gameobj && gameclient.snap.gameobj->time_limit) - { - char buf[64]; - str_format(buf, sizeof(buf), "Time Limit: %d min", gameclient.snap.gameobj->time_limit); - gfx_text(0, x+220.0f, y, 22.0f, buf, -1); - tw += gfx_text_width(0, 22.0f, buf, -1); - } - if(gameclient.snap.gameobj && gameclient.snap.gameobj->round_num && gameclient.snap.gameobj->round_current) - { - char buf[64]; - str_format(buf, sizeof(buf), "Round %d/%d", gameclient.snap.gameobj->round_current, gameclient.snap.gameobj->round_num); - gfx_text(0, x+450.0f, y, 22.0f, buf, -1); - - /*[48c3fd4c][game/scoreboard]: timelimit x:219.428558 - [48c3fd4c][game/scoreboard]: round x:453.142822*/ - } -} - -void SCOREBOARD::render_spectators(float x, float y, float w) -{ - char buffer[1024*4]; - int count = 0; - float h = 120.0f; - - str_copy(buffer, "Spectators: ", sizeof(buffer)); - - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.5f); - draw_round_rect(x-10.f, y-10.f, w, h, 10.0f); - gfx_quads_end(); - - for(int i = 0; i < snap_num_items(SNAP_CURRENT); i++) - { - SNAP_ITEM item; - const void *data = snap_get_item(SNAP_CURRENT, i, &item); - - if(item.type == NETOBJTYPE_PLAYER_INFO) - { - const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data; - if(info->team == -1) - { - if(count) - strcat(buffer, ", "); - strcat(buffer, gameclient.clients[info->cid].name); - count++; - } - } - } - - gfx_text(0, x+10, y, 32, buffer, (int)w-20); -} - -void SCOREBOARD::render_scoreboard(float x, float y, float w, int team, const char *title) -{ - //float ystart = y; - float h = 750.0f; - - gfx_blend_normal(); - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(0,0,0,0.5f); - draw_round_rect(x-10.f, y-10.f, w, h, 17.0f); - gfx_quads_end(); - - // render title - if(!title) - { - if(gameclient.snap.gameobj->game_over) - title = "Game Over"; - else - title = "Score Board"; - } - - float tw = gfx_text_width(0, 48, title, -1); - - if(team == -1) - { - gfx_text(0, x+w/2-tw/2, y, 48, title, -1); - } - else - { - gfx_text(0, x+10, y, 48, title, -1); - - if(gameclient.snap.gameobj) - { - char buf[128]; - int score = team ? gameclient.snap.gameobj->teamscore_blue : gameclient.snap.gameobj->teamscore_red; - str_format(buf, sizeof(buf), "%d", score); - tw = gfx_text_width(0, 48, buf, -1); - gfx_text(0, x+w-tw-30, y, 48, buf, -1); - } - } - - y += 54.0f; - - // find players - const NETOBJ_PLAYER_INFO *players[MAX_CLIENTS] = {0}; - int num_players = 0; - for(int i = 0; i < snap_num_items(SNAP_CURRENT); i++) - { - SNAP_ITEM item; - const void *data = snap_get_item(SNAP_CURRENT, i, &item); - - if(item.type == NETOBJTYPE_PLAYER_INFO) - { - const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data; - if(info->team == team) - { - players[num_players] = info; - num_players++; - } - } - } - - // sort players - for(int k = 0; k < num_players; k++) // ffs, bubblesort - { - for(int i = 0; i < num_players-k-1; i++) - { - if(players[i]->score < players[i+1]->score) - { - const NETOBJ_PLAYER_INFO *tmp = players[i]; - players[i] = players[i+1]; - players[i+1] = tmp; - } - } - } - - // render headlines - gfx_text(0, x+10, y, 24.0f, "Score", -1); - gfx_text(0, x+125, y, 24.0f, "Name", -1); - gfx_text(0, x+w-70, y, 24.0f, "Ping", -1); - y += 29.0f; - - float font_size = 35.0f; - float line_height = 50.0f; - float tee_sizemod = 1.0f; - float tee_offset = 0.0f; - - if(num_players > 13) - { - font_size = 30.0f; - line_height = 40.0f; - tee_sizemod = 0.8f; - tee_offset = -5.0f; - } - - // render player scores - for(int i = 0; i < num_players; i++) - { - const NETOBJ_PLAYER_INFO *info = players[i]; - - // make sure that we render the correct team - - char buf[128]; - if(info->local) - { - // background so it's easy to find the local player - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(1,1,1,0.25f); - draw_round_rect(x, y, w-20, line_height*0.95f, 17.0f); - gfx_quads_end(); - } - - str_format(buf, sizeof(buf), "%4d", info->score); - gfx_text(0, x+60-gfx_text_width(0, font_size,buf,-1), y, font_size, buf, -1); - - gfx_text(0, x+128, y, font_size, gameclient.clients[info->cid].name, -1); - - str_format(buf, sizeof(buf), "%4d", info->latency); - float tw = gfx_text_width(0, font_size, buf, -1); - gfx_text(0, x+w-tw-35, y, font_size, buf, -1); - - // render avatar - if((gameclient.snap.flags[0] && gameclient.snap.flags[0]->carried_by == info->cid) || - (gameclient.snap.flags[1] && gameclient.snap.flags[1]->carried_by == info->cid)) - { - gfx_blend_normal(); - gfx_texture_set(data->images[IMAGE_GAME].id); - gfx_quads_begin(); - - if(info->team == 0) select_sprite(SPRITE_FLAG_BLUE, SPRITE_FLAG_FLIP_X); - else select_sprite(SPRITE_FLAG_RED, SPRITE_FLAG_FLIP_X); - - float size = 64.0f; - gfx_quads_drawTL(x+55, y-15, size/2, size); - gfx_quads_end(); - } - - TEE_RENDER_INFO teeinfo = gameclient.clients[info->cid].render_info; - teeinfo.size *= tee_sizemod; - render_tee(ANIMSTATE::get_idle(), &teeinfo, EMOTE_NORMAL, vec2(1,0), vec2(x+90, y+28+tee_offset)); - - - y += line_height; - } -} - -void SCOREBOARD::on_render() -{ - bool do_scoreboard = false; - - // if we activly wanna look on the scoreboard - if(active) - do_scoreboard = true; - - if(gameclient.snap.local_info && gameclient.snap.local_info->team != -1) - { - // we are not a spectator, check if we are ead - if(!gameclient.snap.local_character || gameclient.snap.local_character->health < 0) - do_scoreboard = true; - } - - // if we the game is over - if(gameclient.snap.gameobj && gameclient.snap.gameobj->game_over) - do_scoreboard = true; - - if(!do_scoreboard) - return; - - // if the score board is active, then we should clear the motd message aswell - if(active) - gameclient.motd->clear(); - - - float width = 400*3.0f*gfx_screenaspect(); - float height = 400*3.0f; - - gfx_mapscreen(0, 0, width, height); - - float w = 650.0f; - - if(gameclient.snap.gameobj && !(gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS)) - { - render_scoreboard(width/2-w/2, 150.0f, w, 0, 0); - //render_scoreboard(gameobj, 0, 0, -1, 0); - } - else - { - - if(gameclient.snap.gameobj && gameclient.snap.gameobj->game_over) - { - const char *text = "DRAW!"; - if(gameclient.snap.gameobj->teamscore_red > gameclient.snap.gameobj->teamscore_blue) - text = "Red Team Wins!"; - else if(gameclient.snap.gameobj->teamscore_blue > gameclient.snap.gameobj->teamscore_red) - text = "Blue Team Wins!"; - - float w = gfx_text_width(0, 92.0f, text, -1); - gfx_text(0, width/2-w/2, 45, 92.0f, text, -1); - } - - render_scoreboard(width/2-w-20, 150.0f, w, 0, "Red Team"); - render_scoreboard(width/2 + 20, 150.0f, w, 1, "Blue Team"); - } - - render_goals(width/2-w/2, 150+750+25, w); - render_spectators(width/2-w/2, 150+750+25+50+25, w); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.hpp deleted file mode 100644 index 222dab9da..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/scoreboard.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -class SCOREBOARD : public COMPONENT -{ - void render_goals(float x, float y, float w); - void render_spectators(float x, float y, float w); - void render_scoreboard(float x, float y, float w, int team, const char *title); - - static void con_key_scoreboard(void *result, void *user_data); - - bool active; - -public: - SCOREBOARD(); - virtual void on_reset(); - virtual void on_console_init(); - virtual void on_render(); -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.cpp deleted file mode 100644 index 451a77f33..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include -#include - -#include - -extern "C" -{ - #include -} - -#include "skins.hpp" - -SKINS::SKINS() -{ - num_skins = 0; -} - -void SKINS::skinscan(const char *name, int is_dir, void *user) -{ - SKINS *self = (SKINS *)user; - int l = strlen(name); - if(l < 4 || is_dir || self->num_skins == MAX_SKINS) - return; - if(strcmp(name+l-4, ".png") != 0) - return; - - char buf[512]; - str_format(buf, sizeof(buf), "skins/%s", name); - IMAGE_INFO info; - if(!gfx_load_png(&info, buf)) - { - dbg_msg("game", "failed to load skin from %s", name); - return; - } - - self->skins[self->num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format, 0); - - int body_size = 96; // body size - unsigned char *d = (unsigned char *)info.data; - int pitch = info.width*4; - - // dig out blood color - { - int colors[3] = {0}; - for(int y = 0; y < body_size; y++) - for(int x = 0; x < body_size; x++) - { - if(d[y*pitch+x*4+3] > 128) - { - colors[0] += d[y*pitch+x*4+0]; - colors[1] += d[y*pitch+x*4+1]; - colors[2] += d[y*pitch+x*4+2]; - } - } - - self->skins[self->num_skins].blood_color = normalize(vec3(colors[0], colors[1], colors[2])); - } - - // create colorless version - int step = info.format == IMG_RGBA ? 4 : 3; - - // make the texture gray scale - for(int i = 0; i < info.width*info.height; i++) - { - int v = (d[i*step]+d[i*step+1]+d[i*step+2])/3; - d[i*step] = v; - d[i*step+1] = v; - d[i*step+2] = v; - } - - - if(1) - { - int freq[256] = {0}; - int org_weight = 0; - int new_weight = 192; - - // find most common frequence - for(int y = 0; y < body_size; y++) - for(int x = 0; x < body_size; x++) - { - if(d[y*pitch+x*4+3] > 128) - freq[d[y*pitch+x*4]]++; - } - - for(int i = 1; i < 256; i++) - { - if(freq[org_weight] < freq[i]) - org_weight = i; - } - - // reorder - int inv_org_weight = 255-org_weight; - int inv_new_weight = 255-new_weight; - for(int y = 0; y < body_size; y++) - for(int x = 0; x < body_size; x++) - { - int v = d[y*pitch+x*4]; - if(v <= org_weight) - v = (int)(((v/(float)org_weight) * new_weight)); - else - v = (int)(((v-org_weight)/(float)inv_org_weight)*inv_new_weight + new_weight); - d[y*pitch+x*4] = v; - d[y*pitch+x*4+1] = v; - d[y*pitch+x*4+2] = v; - } - } - - self->skins[self->num_skins].color_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data, info.format, 0); - mem_free(info.data); - - // set skin data - strncpy(self->skins[self->num_skins].name, name, min((int)sizeof(self->skins[self->num_skins].name),l-4)); - dbg_msg("game", "load skin %s", self->skins[self->num_skins].name); - self->num_skins++; -} - - -void SKINS::init() -{ - // load skins - num_skins = 0; - engine_listdir(LISTDIRTYPE_ALL, "skins", skinscan, this); -} - -int SKINS::num() -{ - return num_skins; -} - -const SKINS::SKIN *SKINS::get(int index) -{ - return &skins[index%num_skins]; -} - -int SKINS::find(const char *name) -{ - for(int i = 0; i < num_skins; i++) - { - if(strcmp(skins[i].name, name) == 0) - return i; - } - return -1; -} - -// these converter functions were nicked from some random internet pages -static float hue_to_rgb(float v1, float v2, float h) -{ - if(h < 0) h += 1; - if(h > 1) h -= 1; - if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; - if((2 * h) < 1) return v2; - if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; - return v1; -} - -static vec3 hsl_to_rgb(vec3 in) -{ - float v1, v2; - vec3 out; - - if(in.s == 0) - { - out.r = in.l; - out.g = in.l; - out.b = in.l; - } - else - { - if(in.l < 0.5f) - v2 = in.l * (1 + in.s); - else - v2 = (in.l+in.s) - (in.s*in.l); - - v1 = 2 * in.l - v2; - - out.r = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f)); - out.g = hue_to_rgb(v1, v2, in.h); - out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f)); - } - - return out; -} - -vec4 SKINS::get_color(int v) -{ - vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); - return vec4(r.r, r.g, r.b, 1.0f); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.hpp deleted file mode 100644 index 078fd71d9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/skins.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -class SKINS : public COMPONENT -{ -public: - // do this better and nicer - typedef struct - { - int org_texture; - int color_texture; - char name[31]; - char term[1]; - vec3 blood_color; - } SKIN; - - SKINS(); - - void init(); - - vec4 get_color(int v); - int num(); - const SKIN *get(int index); - int find(const char *name); - -private: - enum - { - MAX_SKINS=256, - }; - - SKIN skins[MAX_SKINS]; - int num_skins; - - static void skinscan(const char *name, int is_dir, void *user); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.cpp deleted file mode 100644 index dfa7e31b9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -#include "sounds.hpp" - -void SOUNDS::on_init() -{ - // setup sound channels - snd_set_channel(SOUNDS::CHN_GUI, 1.0f, 0.0f); - snd_set_channel(SOUNDS::CHN_MUSIC, 1.0f, 0.0f); - snd_set_channel(SOUNDS::CHN_WORLD, 0.9f, 1.0f); - snd_set_channel(SOUNDS::CHN_GLOBAL, 1.0f, 0.0f); - - snd_set_listener_pos(0.0f, 0.0f); -} - -void SOUNDS::on_render() -{ - // set listner pos - snd_set_listener_pos(gameclient.camera->center.x, gameclient.camera->center.y); -} - -void SOUNDS::play_and_record(int chn, int setid, float vol, vec2 pos) -{ - NETMSG_SV_SOUNDGLOBAL msg; - msg.soundid = setid; - msg.pack(MSGFLAG_NOSEND|MSGFLAG_RECORD); - client_send_msg(); - - play(chn, setid, vol, pos); -} - -void SOUNDS::play(int chn, int setid, float vol, vec2 pos) -{ - SOUNDSET *set = &data->sounds[setid]; - - if(!set->num_sounds) - return; - - if(set->num_sounds == 1) - { - snd_play_at(chn, set->sounds[0].id, 0, pos.x, pos.y); - return; - } - - // play a random one - int id; - do { - id = rand() % set->num_sounds; - } while(id == set->last); - snd_play_at(chn, set->sounds[id].id, 0, pos.x, pos.y); - set->last = id; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.hpp deleted file mode 100644 index 95ddb1ecc..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/sounds.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -class SOUNDS : public COMPONENT -{ -public: - // sound channels - enum - { - CHN_GUI=0, - CHN_MUSIC, - CHN_WORLD, - CHN_GLOBAL, - }; - - virtual void on_init(); - virtual void on_render(); - - void play(int chn, int setid, float vol, vec2 pos); - void play_and_record(int chn, int setid, float vol, vec2 pos); -}; - - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.cpp deleted file mode 100644 index 190ba2246..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include -//#include -#include "voting.hpp" - -void VOTING::con_callvote(void *result, void *user_data) -{ - VOTING *self = (VOTING*)user_data; - self->callvote(console_arg_string(result, 0), console_arg_string(result, 1)); -} - -void VOTING::con_vote(void *result, void *user_data) -{ - VOTING *self = (VOTING *)user_data; - if(str_comp_nocase(console_arg_string(result, 0), "yes") == 0) - self->vote(1); - else if(str_comp_nocase(console_arg_string(result, 0), "no") == 0) - self->vote(-1); -} - -void VOTING::callvote(const char *type, const char *value) -{ - NETMSG_CL_CALLVOTE msg = {0}; - msg.type = type; - msg.value = value; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} - -void VOTING::callvote_kick(int client_id) -{ - char buf[32]; - str_format(buf, sizeof(buf), "%d", client_id); - callvote("kick", buf); -} - -void VOTING::callvote_option(int option_id) -{ - VOTEOPTION *option = this->first; - while(option && option_id >= 0) - { - if(option_id == 0) - { - callvote("option", option->command); - break; - } - - option_id--; - option = option->next; - } -} - -void VOTING::vote(int v) -{ - NETMSG_CL_VOTE msg = {v}; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} - -VOTING::VOTING() -{ - heap = 0; - clearoptions(); - on_reset(); -} - - -void VOTING::clearoptions() -{ - if(heap) - memheap_destroy(heap); - heap = memheap_create(); - - first = 0; - last = 0; -} - -void VOTING::on_reset() -{ - closetime = 0; - description[0] = 0; - command[0] = 0; - yes = no = pass = total = 0; - voted = 0; -} - -void VOTING::on_console_init() -{ - MACRO_REGISTER_COMMAND("callvote", "sr", CFGFLAG_CLIENT, con_callvote, this, "Call vote"); - MACRO_REGISTER_COMMAND("vote", "r", CFGFLAG_CLIENT, con_vote, this, "Vote yes/no"); -} - -void VOTING::on_message(int msgtype, void *rawmsg) -{ - if(msgtype == NETMSGTYPE_SV_VOTE_SET) - { - NETMSG_SV_VOTE_SET *msg = (NETMSG_SV_VOTE_SET *)rawmsg; - if(msg->timeout) - { - on_reset(); - str_copy(description, msg->description, sizeof(description)); - str_copy(command, msg->command, sizeof(description)); - closetime = time_get() + time_freq() * msg->timeout; - } - else - on_reset(); - } - else if(msgtype == NETMSGTYPE_SV_VOTE_STATUS) - { - NETMSG_SV_VOTE_STATUS *msg = (NETMSG_SV_VOTE_STATUS *)rawmsg; - yes = msg->yes; - no = msg->no; - pass = msg->pass; - total = msg->total; - } - else if(msgtype == NETMSGTYPE_SV_VOTE_CLEAROPTIONS) - { - clearoptions(); - } - else if(msgtype == NETMSGTYPE_SV_VOTE_OPTION) - { - NETMSG_SV_VOTE_OPTION *msg = (NETMSG_SV_VOTE_OPTION *)rawmsg; - int len = str_length(msg->command); - - VOTEOPTION *option = (VOTEOPTION *)memheap_allocate(heap, sizeof(VOTEOPTION) + len); - option->next = 0; - option->prev = last; - if(option->prev) - option->prev->next = option; - last = option; - if(!first) - first = option; - - mem_copy(option->command, msg->command, len+1); - - } -} - -void VOTING::on_render() -{ -} - - -void VOTING::render_bars(RECT bars, bool text) -{ - ui_draw_rect(&bars, vec4(0.8f,0.8f,0.8f,0.5f), CORNER_ALL, bars.h/3); - - RECT splitter = bars; - splitter.x = splitter.x+splitter.w/2; - splitter.w = splitter.h/2.0f; - splitter.x -= splitter.w/2; - ui_draw_rect(&splitter, vec4(0.4f,0.4f,0.4f,0.5f), CORNER_ALL, splitter.h/4); - - if(total) - { - RECT pass_area = bars; - if(yes) - { - RECT yes_area = bars; - yes_area.w *= yes/(float)total; - ui_draw_rect(&yes_area, vec4(0.2f,0.9f,0.2f,0.85f), CORNER_ALL, bars.h/3); - - if(text) - { - char buf[256]; - str_format(buf, sizeof(buf), "%d", yes); - ui_do_label(&yes_area, buf, bars.h*0.75f, 0); - } - - pass_area.x += yes_area.w; - pass_area.w -= yes_area.w; - } - - if(no) - { - RECT no_area = bars; - no_area.w *= no/(float)total; - no_area.x = (bars.x + bars.w)-no_area.w; - ui_draw_rect(&no_area, vec4(0.9f,0.2f,0.2f,0.85f), CORNER_ALL, bars.h/3); - - if(text) - { - char buf[256]; - str_format(buf, sizeof(buf), "%d", no); - ui_do_label(&no_area, buf, bars.h*0.75f, 0); - } - - pass_area.w -= no_area.w; - } - - if(text && pass) - { - char buf[256]; - str_format(buf, sizeof(buf), "%d", pass); - ui_do_label(&pass_area, buf, bars.h*0.75f, 0); - } - } -} - - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.hpp deleted file mode 100644 index 3341edea2..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/components/voting.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -extern "C" -{ - #include -} - -class VOTING : public COMPONENT -{ - HEAP *heap; - - static void con_callvote(void *result, void *user_data); - static void con_vote(void *result, void *user_data); - - int64 closetime; - char description[512]; - char command[512]; - int voted; - - void clearoptions(); - void callvote(const char *type, const char *value); - -public: - - struct VOTEOPTION - { - VOTEOPTION *next; - VOTEOPTION *prev; - char command[1]; - }; - VOTEOPTION *first; - VOTEOPTION *last; - - VOTING(); - virtual void on_reset(); - virtual void on_console_init(); - virtual void on_message(int msgtype, void *rawmsg); - virtual void on_render(); - - void render_bars(RECT bars, bool text); - - void callvote_kick(int client_id); - void callvote_option(int option); - - void vote(int v); // -1 = no, 1 = yes - - int seconds_left() { return (closetime - time_get())/time_freq(); } - bool is_voting() { return closetime != 0; } - int taken_choice() const { return voted; } - const char *vote_description() const { return description; } - const char *vote_command() const { return command; } - - int yes, no, pass, total; -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.cpp deleted file mode 100644 index a8a62ddfe..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.cpp +++ /dev/null @@ -1,890 +0,0 @@ -#include -#include -#include - -#include -#include - -#include -#include "render.hpp" - -#include "gameclient.hpp" - -#include "components/binds.hpp" -#include "components/broadcast.hpp" -#include "components/camera.hpp" -#include "components/chat.hpp" -#include "components/console.hpp" -#include "components/controls.hpp" -#include "components/damageind.hpp" -#include "components/debughud.hpp" -#include "components/effects.hpp" -#include "components/emoticon.hpp" -#include "components/flow.hpp" -#include "components/hud.hpp" -#include "components/items.hpp" -#include "components/killmessages.hpp" -#include "components/mapimages.hpp" -#include "components/maplayers.hpp" -#include "components/menus.hpp" -#include "components/motd.hpp" -#include "components/particles.hpp" -#include "components/players.hpp" -#include "components/nameplates.hpp" -#include "components/scoreboard.hpp" -#include "components/skins.hpp" -#include "components/sounds.hpp" -#include "components/voting.hpp" - -GAMECLIENT gameclient; - -// instanciate all systems -static KILLMESSAGES killmessages; -static CAMERA camera; -static CHAT chat; -static MOTD motd; -static BROADCAST broadcast; -static CONSOLE console; -static BINDS binds; -static PARTICLES particles; -static MENUS menus; -static SKINS skins; -static FLOW flow; -static HUD hud; -static DEBUGHUD debughud; -static CONTROLS controls; -static EFFECTS effects; -static SCOREBOARD scoreboard; -static SOUNDS sounds; -static EMOTICON emoticon; -static DAMAGEIND damageind; -static VOTING voting; - -static PLAYERS players; -static NAMEPLATES nameplates; -static ITEMS items; -static MAPIMAGES mapimages; - -static MAPLAYERS maplayers_background(MAPLAYERS::TYPE_BACKGROUND); -static MAPLAYERS maplayers_foreground(MAPLAYERS::TYPE_FOREGROUND); - -GAMECLIENT::STACK::STACK() { num = 0; } -void GAMECLIENT::STACK::add(class COMPONENT *component) { components[num++] = component; } - -static int load_current; -static int load_total; - -static void load_sounds_thread(void *do_render) -{ - // load sounds - for(int s = 0; s < data->num_sounds; s++) - { - if(do_render) - gameclient.menus->render_loading(load_current/(float)load_total); - for(int i = 0; i < data->sounds[s].num_sounds; i++) - { - int id = snd_load_wv(data->sounds[s].sounds[i].filename); - data->sounds[s].sounds[i].id = id; - } - - if(do_render) - load_current++; - } -} - -static void con_serverdummy(void *result, void *user_data) -{ - dbg_msg("client", "this command is not available on the client"); -} - -void GAMECLIENT::on_console_init() -{ - // setup pointers - binds = &::binds; - console = &::console; - particles = &::particles; - menus = &::menus; - skins = &::skins; - chat = &::chat; - flow = &::flow; - camera = &::camera; - controls = &::controls; - effects = &::effects; - sounds = &::sounds; - motd = &::motd; - damageind = &::damageind; - mapimages = &::mapimages; - voting = &::voting; - - // make a list of all the systems, make sure to add them in the corrent render order - all.add(skins); - all.add(mapimages); - all.add(effects); // doesn't render anything, just updates effects - all.add(particles); - all.add(binds); - all.add(controls); - all.add(camera); - all.add(sounds); - all.add(voting); - all.add(particles); // doesn't render anything, just updates all the particles - - all.add(&maplayers_background); // first to render - all.add(&particles->render_trail); - all.add(&particles->render_explosions); - all.add(&items); - all.add(&players); - all.add(&maplayers_foreground); - all.add(&nameplates); - all.add(&particles->render_general); - all.add(damageind); - all.add(&hud); - all.add(&emoticon); - all.add(&killmessages); - all.add(chat); - all.add(&broadcast); - all.add(&debughud); - all.add(&scoreboard); - all.add(motd); - all.add(menus); - all.add(console); - - // build the input stack - input.add(&menus->binder); // this will take over all input when we want to bind a key - input.add(&binds->special_binds); - input.add(console); - input.add(chat); // chat has higher prio due to tha you can quit it by pressing esc - input.add(motd); // for pressing esc to remove it - input.add(menus); - input.add(&emoticon); - input.add(controls); - input.add(binds); - - // add the some console commands - MACRO_REGISTER_COMMAND("team", "i", CFGFLAG_CLIENT, con_team, this, "Switch team"); - MACRO_REGISTER_COMMAND("kill", "", CFGFLAG_CLIENT, con_kill, this, "Kill yourself"); - - // register server dummy commands for tab completion - MACRO_REGISTER_COMMAND("tune", "si", CFGFLAG_SERVER, con_serverdummy, 0, "Tune variable to value"); - MACRO_REGISTER_COMMAND("tune_reset", "", CFGFLAG_SERVER, con_serverdummy, 0, "Reset tuning"); - MACRO_REGISTER_COMMAND("tune_dump", "", CFGFLAG_SERVER, con_serverdummy, 0, "Dump tuning"); - MACRO_REGISTER_COMMAND("change_map", "r", CFGFLAG_SERVER, con_serverdummy, 0, "Change map"); - MACRO_REGISTER_COMMAND("restart", "?i", CFGFLAG_SERVER, con_serverdummy, 0, "Restart in x seconds"); - MACRO_REGISTER_COMMAND("broadcast", "r", CFGFLAG_SERVER, con_serverdummy, 0, "Broadcast message"); - /*MACRO_REGISTER_COMMAND("say", "r", CFGFLAG_SERVER, con_serverdummy, 0);*/ - MACRO_REGISTER_COMMAND("set_team", "ii", CFGFLAG_SERVER, con_serverdummy, 0, "Set team of player to team"); - MACRO_REGISTER_COMMAND("addvote", "r", CFGFLAG_SERVER, con_serverdummy, 0, "Add a voting option"); - /*MACRO_REGISTER_COMMAND("vote", "", CFGFLAG_SERVER, con_serverdummy, 0);*/ - - // let all the other components register their console commands - for(int i = 0; i < all.num; i++) - all.components[i]->on_console_init(); - - // - suppress_events = false; -} - -void GAMECLIENT::on_init() -{ - // init all components - for(int i = 0; i < all.num; i++) - all.components[i]->on_init(); - - // setup item sizes - for(int i = 0; i < NUM_NETOBJTYPES; i++) - snap_set_staticsize(i, netobj_get_size(i)); - - // load default font - static FONT_SET default_font; - int64 start = time_get(); - - int before = gfx_memory_usage(); - font_set_load(&default_font, "fonts/default_font%d.tfnt", "fonts/default_font%d.png", "fonts/default_font%d_b.png", 14, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 36); - dbg_msg("font", "gfx memory used for font textures: %d", gfx_memory_usage()-before); - - gfx_text_set_default_font(&default_font); - - config.cl_threadsoundloading = 0; - - // setup load amount - load_total = data->num_images; - load_current = 0; - if(!config.cl_threadsoundloading) - load_total += data->num_sounds; - - // load textures - for(int i = 0; i < data->num_images; i++) - { - gameclient.menus->render_loading(load_current/load_total); - data->images[i].id = gfx_load_texture(data->images[i].filename, IMG_AUTO, 0); - load_current++; - } - - ::skins.init(); - - if(config.cl_threadsoundloading) - thread_create(load_sounds_thread, 0); - else - load_sounds_thread((void*)1); - - for(int i = 0; i < all.num; i++) - all.components[i]->on_reset(); - - int64 end = time_get(); - dbg_msg("", "%f.2ms", ((end-start)*1000)/(float)time_freq()); - - servermode = SERVERMODE_PURE; -} - -void GAMECLIENT::on_save() -{ - for(int i = 0; i < all.num; i++) - all.components[i]->on_save(); -} - -void GAMECLIENT::dispatch_input() -{ - // handle mouse movement - int x=0, y=0; -#ifdef ANDROID - // No relative mouse here, we've got touchscreen - inp_mouse_absolute(&x, &y); -#else - inp_mouse_relative(&x, &y); - if(x || y) -#endif - { - for(int h = 0; h < input.num; h++) - { - if(input.components[h]->on_mousemove(x, y)) - break; - } - } - - // handle key presses - for(int i = 0; i < inp_num_events(); i++) - { - INPUT_EVENT e = inp_get_event(i); - - for(int h = 0; h < input.num; h++) - { - if(input.components[h]->on_input(e)) - { - //dbg_msg("", "%d char=%d key=%d flags=%d", h, e.ch, e.key, e.flags); - break; - } - } - } - - // clear all events for this frame - inp_clear_events(); -} - - -int GAMECLIENT::on_snapinput(int *data) -{ - return controls->snapinput(data); -} - -void GAMECLIENT::on_connected() -{ - layers_init(); - col_init(); - render_tilemap_generate_skip(); - - for(int i = 0; i < all.num; i++) - { - all.components[i]->on_mapload(); - all.components[i]->on_reset(); - } - - SERVER_INFO current_server_info; - client_serverinfo(¤t_server_info); - - servermode = SERVERMODE_PURE; - - // send the inital info - send_info(true); -} - -void GAMECLIENT::on_reset() -{ - // clear out the invalid pointers - last_new_predicted_tick = -1; - mem_zero(&gameclient.snap, sizeof(gameclient.snap)); - - for(int i = 0; i < MAX_CLIENTS; i++) - { - clients[i].name[0] = 0; - clients[i].skin_id = 0; - clients[i].team = 0; - clients[i].angle = 0; - clients[i].emoticon = 0; - clients[i].emoticon_start = -1; - clients[i].skin_info.texture = gameclient.skins->get(0)->color_texture; - clients[i].skin_info.color_body = vec4(1,1,1,1); - clients[i].skin_info.color_feet = vec4(1,1,1,1); - clients[i].update_render_info(); - } - - for(int i = 0; i < all.num; i++) - all.components[i]->on_reset(); -} - - -void GAMECLIENT::update_local_character_pos() -{ - if(config.cl_predict && client_state() != CLIENTSTATE_DEMOPLAYBACK) - { - if(!snap.local_character || (snap.local_character->health < 0) || (snap.gameobj && snap.gameobj->game_over)) - { - // don't use predicted - } - else - local_character_pos = mix(predicted_prev_char.pos, predicted_char.pos, client_predintratick()); - } - else if(snap.local_character && snap.local_prev_character) - { - local_character_pos = mix( - vec2(snap.local_prev_character->x, snap.local_prev_character->y), - vec2(snap.local_character->x, snap.local_character->y), client_intratick()); - } -} - - -static void evolve(NETOBJ_CHARACTER *character, int tick) -{ - WORLD_CORE tempworld; - CHARACTER_CORE tempcore; - mem_zero(&tempcore, sizeof(tempcore)); - tempcore.world = &tempworld; - tempcore.read(character); - - while(character->tick < tick) - { - character->tick++; - tempcore.tick(false); - tempcore.move(); - tempcore.quantize(); - } - - tempcore.write(character); -} - - -void GAMECLIENT::on_render() -{ - // update the local character position - update_local_character_pos(); - - // dispatch all input to systems - dispatch_input(); - - // render all systems - for(int i = 0; i < all.num; i++) - all.components[i]->on_render(); - - // clear new tick flags - new_tick = false; - new_predicted_tick = false; -} - -void GAMECLIENT::on_message(int msgtype) -{ - - // special messages - if(msgtype == NETMSGTYPE_SV_EXTRAPROJECTILE) - { - /* - int num = msg_unpack_int(); - - for(int k = 0; k < num; k++) - { - NETOBJ_PROJECTILE proj; - for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) - ((int *)&proj)[i] = msg_unpack_int(); - - if(msg_unpack_error()) - return; - - if(extraproj_num != MAX_EXTRA_PROJECTILES) - { - extraproj_projectiles[extraproj_num] = proj; - extraproj_num++; - } - } - - return;*/ - } - else if(msgtype == NETMSGTYPE_SV_TUNEPARAMS) - { - // unpack the new tuning - TUNING_PARAMS new_tuning; - int *params = (int *)&new_tuning; - for(unsigned i = 0; i < sizeof(TUNING_PARAMS)/sizeof(int); i++) - params[i] = msg_unpack_int(); - - // check for unpacking errors - if(msg_unpack_error()) - return; - - servermode = SERVERMODE_PURE; - - // apply new tuning - tuning = new_tuning; - return; - } - - void *rawmsg = netmsg_secure_unpack(msgtype); - if(!rawmsg) - { - dbg_msg("client", "dropped weird message '%s' (%d), failed on '%s'", netmsg_get_name(msgtype), msgtype, netmsg_failed_on()); - return; - } - - // TODO: this should be done smarter - for(int i = 0; i < all.num; i++) - all.components[i]->on_message(msgtype, rawmsg); - - if(msgtype == NETMSGTYPE_SV_READYTOENTER) - { - client_entergame(); - } - else if (msgtype == NETMSGTYPE_SV_EMOTICON) - { - NETMSG_SV_EMOTICON *msg = (NETMSG_SV_EMOTICON *)rawmsg; - - // apply - clients[msg->cid].emoticon = msg->emoticon; - clients[msg->cid].emoticon_start = client_tick(); - } - else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL) - { - if(suppress_events) - return; - - NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg; - gameclient.sounds->play(SOUNDS::CHN_GLOBAL, msg->soundid, 1.0f, vec2(0,0)); - } -} - -void GAMECLIENT::on_statechange(int new_state, int old_state) -{ - if(demorec_isrecording()) - demorec_record_stop(); - - // reset everything - on_reset(); - - // then change the state - for(int i = 0; i < all.num; i++) - all.components[i]->on_statechange(new_state, old_state); -} - - - -void GAMECLIENT::process_events() -{ - if(suppress_events) - return; - - int snaptype = SNAP_CURRENT; - int num = snap_num_items(snaptype); - for(int index = 0; index < num; index++) - { - SNAP_ITEM item; - const void *data = snap_get_item(snaptype, index, &item); - - if(item.type == NETEVENTTYPE_DAMAGEIND) - { - NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)data; - gameclient.effects->damage_indicator(vec2(ev->x, ev->y), get_direction(ev->angle)); - } - else if(item.type == NETEVENTTYPE_EXPLOSION) - { - NETEVENT_EXPLOSION *ev = (NETEVENT_EXPLOSION *)data; - gameclient.effects->explosion(vec2(ev->x, ev->y)); - } - else if(item.type == NETEVENTTYPE_HAMMERHIT) - { - NETEVENT_HAMMERHIT *ev = (NETEVENT_HAMMERHIT *)data; - gameclient.effects->hammerhit(vec2(ev->x, ev->y)); - } - else if(item.type == NETEVENTTYPE_SPAWN) - { - NETEVENT_SPAWN *ev = (NETEVENT_SPAWN *)data; - gameclient.effects->playerspawn(vec2(ev->x, ev->y)); - } - else if(item.type == NETEVENTTYPE_DEATH) - { - NETEVENT_DEATH *ev = (NETEVENT_DEATH *)data; - gameclient.effects->playerdeath(vec2(ev->x, ev->y), ev->cid); - } - else if(item.type == NETEVENTTYPE_SOUNDWORLD) - { - NETEVENT_SOUNDWORLD *ev = (NETEVENT_SOUNDWORLD *)data; - gameclient.sounds->play(SOUNDS::CHN_WORLD, ev->soundid, 1.0f, vec2(ev->x, ev->y)); - } - } -} - -void GAMECLIENT::on_snapshot() -{ - new_tick = true; - - // clear out the invalid pointers - mem_zero(&gameclient.snap, sizeof(gameclient.snap)); - snap.local_cid = -1; - - // secure snapshot - { - int num = snap_num_items(SNAP_CURRENT); - for(int index = 0; index < num; index++) - { - SNAP_ITEM item; - void *data = snap_get_item(SNAP_CURRENT, index, &item); - if(netobj_validate(item.type, data, item.datasize) != 0) - { - if(config.debug) - dbg_msg("game", "invalidated index=%d type=%d (%s) size=%d id=%d", index, item.type, netobj_get_name(item.type), item.datasize, item.id); - snap_invalidate_item(SNAP_CURRENT, index); - } - } - } - - process_events(); - - if(config.dbg_stress) - { - if((client_tick()%100) == 0) - { - char message[64]; - int msglen = rand()%(sizeof(message)-1); - for(int i = 0; i < msglen; i++) - message[i] = 'a'+(rand()%('z'-'a')); - message[msglen] = 0; - - NETMSG_CL_SAY msg; - msg.team = rand()&1; - msg.message = message; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); - } - } - - // go trough all the items in the snapshot and gather the info we want - { - snap.team_size[0] = snap.team_size[1] = 0; - - int num = snap_num_items(SNAP_CURRENT); - for(int i = 0; i < num; i++) - { - SNAP_ITEM item; - const void *data = snap_get_item(SNAP_CURRENT, i, &item); - - if(item.type == NETOBJTYPE_CLIENT_INFO) - { - const NETOBJ_CLIENT_INFO *info = (const NETOBJ_CLIENT_INFO *)data; - int cid = item.id; - ints_to_str(&info->name0, 6, clients[cid].name); - ints_to_str(&info->skin0, 6, clients[cid].skin_name); - - clients[cid].use_custom_color = info->use_custom_color; - clients[cid].color_body = info->color_body; - clients[cid].color_feet = info->color_feet; - - // prepare the info - if(clients[cid].skin_name[0] == 'x' || clients[cid].skin_name[1] == '_') - str_copy(clients[cid].skin_name, "default", 64); - - clients[cid].skin_info.color_body = skins->get_color(clients[cid].color_body); - clients[cid].skin_info.color_feet = skins->get_color(clients[cid].color_feet); - clients[cid].skin_info.size = 64; - - // find new skin - clients[cid].skin_id = gameclient.skins->find(clients[cid].skin_name); - if(clients[cid].skin_id < 0) - { - clients[cid].skin_id = gameclient.skins->find("default"); - if(clients[cid].skin_id < 0) - clients[cid].skin_id = 0; - } - - if(clients[cid].use_custom_color) - clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->color_texture; - else - { - clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->org_texture; - clients[cid].skin_info.color_body = vec4(1,1,1,1); - clients[cid].skin_info.color_feet = vec4(1,1,1,1); - } - - clients[cid].update_render_info(); - gameclient.snap.num_players++; - - } - else if(item.type == NETOBJTYPE_PLAYER_INFO) - { - const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data; - - clients[info->cid].team = info->team; - snap.player_infos[info->cid] = info; - - if(info->local) - { - snap.local_cid = item.id; - snap.local_info = info; - - if (info->team == -1) - snap.spectate = true; - } - - // calculate team-balance - if(info->team != -1) - snap.team_size[info->team]++; - - } - else if(item.type == NETOBJTYPE_CHARACTER) - { - const void *old = snap_find_item(SNAP_PREV, NETOBJTYPE_CHARACTER, item.id); - if(old) - { - snap.characters[item.id].active = true; - snap.characters[item.id].prev = *((const NETOBJ_CHARACTER *)old); - snap.characters[item.id].cur = *((const NETOBJ_CHARACTER *)data); - - if(snap.characters[item.id].prev.tick) - evolve(&snap.characters[item.id].prev, client_prevtick()); - if(snap.characters[item.id].cur.tick) - evolve(&snap.characters[item.id].cur, client_tick()); - } - } - else if(item.type == NETOBJTYPE_GAME) - snap.gameobj = (NETOBJ_GAME *)data; - else if(item.type == NETOBJTYPE_FLAG) - snap.flags[item.id%2] = (const NETOBJ_FLAG *)data; - } - } - - // setup local pointers - if(snap.local_cid >= 0) - { - SNAPSTATE::CHARACTERINFO *c = &snap.characters[snap.local_cid]; - if(c->active) - { - snap.local_character = &c->cur; - snap.local_prev_character = &c->prev; - local_character_pos = vec2(snap.local_character->x, snap.local_character->y); - } - } - else - snap.spectate = true; - - TUNING_PARAMS standard_tuning; - SERVER_INFO current_server_info; - client_serverinfo(¤t_server_info); - if(current_server_info.gametype[0] != '0') - { - if(strcmp(current_server_info.gametype, "DM") != 0 && strcmp(current_server_info.gametype, "TDM") != 0 && strcmp(current_server_info.gametype, "CTF") != 0) - servermode = SERVERMODE_MOD; - else if(memcmp(&standard_tuning, &tuning, sizeof(TUNING_PARAMS)) == 0) - servermode = SERVERMODE_PURE; - else - servermode = SERVERMODE_PUREMOD; - } - - - // update render info - for(int i = 0; i < MAX_CLIENTS; i++) - clients[i].update_render_info(); -} - -void GAMECLIENT::on_predict() -{ - // store the previous values so we can detect prediction errors - CHARACTER_CORE before_prev_char = predicted_prev_char; - CHARACTER_CORE before_char = predicted_char; - - // we can't predict without our own id or own character - if(snap.local_cid == -1 || !snap.characters[snap.local_cid].active) - return; - - // don't predict anything if we are paused - if(snap.gameobj && snap.gameobj->paused) - { - if(snap.local_character) - predicted_char.read(snap.local_character); - if(snap.local_prev_character) - predicted_prev_char.read(snap.local_prev_character); - return; - } - - // repredict character - WORLD_CORE world; - world.tuning = tuning; - - // search for players - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(!snap.characters[i].active) - continue; - - gameclient.clients[i].predicted.world = &world; - world.characters[i] = &gameclient.clients[i].predicted; - gameclient.clients[i].predicted.read(&snap.characters[i].cur); - } - - // predict - for(int tick = client_tick()+1; tick <= client_predtick(); tick++) - { - // fetch the local - if(tick == client_predtick() && world.characters[snap.local_cid]) - predicted_prev_char = *world.characters[snap.local_cid]; - - // first calculate where everyone should move - for(int c = 0; c < MAX_CLIENTS; c++) - { - if(!world.characters[c]) - continue; - - mem_zero(&world.characters[c]->input, sizeof(world.characters[c]->input)); - if(snap.local_cid == c) - { - // apply player input - int *input = client_get_input(tick); - if(input) - world.characters[c]->input = *((NETOBJ_PLAYER_INPUT*)input); - world.characters[c]->tick(true); - } - else - world.characters[c]->tick(false); - - } - - // move all players and quantize their data - for(int c = 0; c < MAX_CLIENTS; c++) - { - if(!world.characters[c]) - continue; - - world.characters[c]->move(); - world.characters[c]->quantize(); - } - - // check if we want to trigger effects - if(tick > last_new_predicted_tick) - { - last_new_predicted_tick = tick; - new_predicted_tick = true; - - if(snap.local_cid != -1 && world.characters[snap.local_cid]) - { - vec2 pos = world.characters[snap.local_cid]->pos; - int events = world.characters[snap.local_cid]->triggered_events; - if(events&COREEVENT_GROUND_JUMP) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); - - /*if(events&COREEVENT_AIR_JUMP) - { - gameclient.effects->air_jump(pos); - gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos); - }*/ - - //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); - //if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos); - if(events&COREEVENT_HOOK_ATTACH_GROUND) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); - if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, pos); - //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); - } - } - - if(tick == client_predtick() && world.characters[snap.local_cid]) - predicted_char = *world.characters[snap.local_cid]; - } - - if(config.debug && config.cl_predict && predicted_tick == client_predtick()) - { - NETOBJ_CHARACTER_CORE before = {0}, now = {0}, before_prev = {0}, now_prev = {0}; - before_char.write(&before); - before_prev_char.write(&before_prev); - predicted_char.write(&now); - predicted_prev_char.write(&now_prev); - - if(mem_comp(&before, &now, sizeof(NETOBJ_CHARACTER_CORE)) != 0) - { - dbg_msg("client", "prediction error"); - for(unsigned i = 0; i < sizeof(NETOBJ_CHARACTER_CORE)/sizeof(int); i++) - if(((int *)&before)[i] != ((int *)&now)[i]) - { - dbg_msg("", "\t%d %d %d (%d %d)", i, ((int *)&before)[i], ((int *)&now)[i], ((int *)&before_prev)[i], ((int *)&now_prev)[i]); - } - } - } - - predicted_tick = client_predtick(); -} - -void GAMECLIENT::CLIENT_DATA::update_render_info() -{ - render_info = skin_info; - - // force team colors - if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_TEAMS) - { - const int team_colors[2] = {65387, 10223467}; - if(team >= 0 || team <= 1) - { - render_info.texture = gameclient.skins->get(skin_id)->color_texture; - render_info.color_body = gameclient.skins->get_color(team_colors[team]); - render_info.color_feet = gameclient.skins->get_color(team_colors[team]); - } - } -} - -void GAMECLIENT::send_switch_team(int team) -{ - NETMSG_CL_SETTEAM msg; - msg.team = team; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} - -void GAMECLIENT::send_info(bool start) -{ - if(start) - { - NETMSG_CL_STARTINFO msg; - msg.name = config.player_name; - msg.skin = config.player_skin; - msg.use_custom_color = config.player_use_custom_color; - msg.color_body = config.player_color_body; - msg.color_feet = config.player_color_feet; - msg.pack(MSGFLAG_VITAL); - } - else - { - NETMSG_CL_CHANGEINFO msg; - msg.name = config.player_name; - msg.skin = config.player_skin; - msg.use_custom_color = config.player_use_custom_color; - msg.color_body = config.player_color_body; - msg.color_feet = config.player_color_feet; - msg.pack(MSGFLAG_VITAL); - } - client_send_msg(); -} - -void GAMECLIENT::send_kill(int client_id) -{ - NETMSG_CL_KILL msg; - msg.pack(MSGFLAG_VITAL); - client_send_msg(); -} - -void GAMECLIENT::con_team(void *result, void *user_data) -{ - ((GAMECLIENT*)user_data)->send_switch_team(console_arg_int(result, 0)); -} - -void GAMECLIENT::con_kill(void *result, void *user_data) -{ - ((GAMECLIENT*)user_data)->send_kill(-1); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.hpp deleted file mode 100644 index 041df10d3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/gameclient.hpp +++ /dev/null @@ -1,159 +0,0 @@ - -#include -#include -#include "render.hpp" - -class GAMECLIENT -{ - class STACK - { - public: - enum - { - MAX_COMPONENTS = 64, - }; - - STACK(); - void add(class COMPONENT *component); - - class COMPONENT *components[MAX_COMPONENTS]; - int num; - }; - - STACK all; - STACK input; - - - void dispatch_input(); - void process_events(); - void update_local_character_pos(); - - int predicted_tick; - int last_new_predicted_tick; - - static void con_team(void *result, void *user_data); - static void con_kill(void *result, void *user_data); - -public: - bool suppress_events; - bool new_tick; - bool new_predicted_tick; - - // TODO: move this - TUNING_PARAMS tuning; - - enum - { - SERVERMODE_PURE=0, - SERVERMODE_MOD, - SERVERMODE_PUREMOD, - }; - int servermode; - - vec2 local_character_pos; - - // predicted players - CHARACTER_CORE predicted_prev_char; - CHARACTER_CORE predicted_char; - - // snap pointers - struct SNAPSTATE - { - const NETOBJ_CHARACTER *local_character; - const NETOBJ_CHARACTER *local_prev_character; - const NETOBJ_PLAYER_INFO *local_info; - const NETOBJ_FLAG *flags[2]; - const NETOBJ_GAME *gameobj; - - const NETOBJ_PLAYER_INFO *player_infos[MAX_CLIENTS]; - const NETOBJ_PLAYER_INFO *info_by_score[MAX_CLIENTS]; - - int local_cid; - int num_players; - int team_size[2]; - bool spectate; - - // - struct CHARACTERINFO - { - bool active; - - // snapshots - NETOBJ_CHARACTER prev; - NETOBJ_CHARACTER cur; - - // interpolated position - vec2 position; - }; - - CHARACTERINFO characters[MAX_CLIENTS]; - }; - - SNAPSTATE snap; - - // client data - struct CLIENT_DATA - { - int use_custom_color; - int color_body; - int color_feet; - - char name[64]; - char skin_name[64]; - int skin_id; - int skin_color; - int team; - int emoticon; - int emoticon_start; - CHARACTER_CORE predicted; - - TEE_RENDER_INFO skin_info; // this is what the server reports - TEE_RENDER_INFO render_info; // this is what we use - - float angle; - - void update_render_info(); - }; - - CLIENT_DATA clients[MAX_CLIENTS]; - - void on_reset(); - - // hooks - void on_connected(); - void on_render(); - void on_init(); - void on_save(); - void on_console_init(); - void on_statechange(int new_state, int old_state); - void on_message(int msgtype); - void on_snapshot(); - void on_predict(); - int on_snapinput(int *data); - - // actions - // TODO: move these - void send_switch_team(int team); - void send_info(bool start); - void send_kill(int client_id); - - // pointers to all systems - class CONSOLE *console; - class BINDS *binds; - class PARTICLES *particles; - class MENUS *menus; - class SKINS *skins; - class FLOW *flow; - class CHAT *chat; - class DAMAGEIND *damageind; - class CAMERA *camera; - class CONTROLS *controls; - class EFFECTS *effects; - class SOUNDS *sounds; - class MOTD *motd; - class MAPIMAGES *mapimages; - class VOTING *voting; -}; - -extern GAMECLIENT gameclient; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.cpp deleted file mode 100644 index 40c47d411..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include // strlen -#include "lineinput.hpp" - -LINEINPUT::LINEINPUT() -{ - clear(); -} - -void LINEINPUT::clear() -{ - mem_zero(str, sizeof(str)); - len = 0; - cursor_pos = 0; -} - -void LINEINPUT::set(const char *string) -{ - str_copy(str, string, sizeof(str)); - len = strlen(str); - cursor_pos = len; -} - -void LINEINPUT::process_input(INPUT_EVENT e) -{ - if(cursor_pos > len) - cursor_pos = len; - - char c = e.ch; - int k = e.key; - - // 127 is produced on Mac OS X and corresponds to the delete key - if (!(c >= 0 && c < 32) && c != 127) - { - if (len < sizeof(str) - 1 && cursor_pos < sizeof(str) - 1) - { - memmove(str + cursor_pos + 1, str + cursor_pos, len - cursor_pos + 1); - str[cursor_pos] = c; - cursor_pos++; - len++; - } - } - - if(e.flags&INPFLAG_PRESS) - { - if (k == KEY_BACKSPACE && cursor_pos > 0) - { - memmove(str + cursor_pos - 1, str + cursor_pos, len - cursor_pos + 1); - cursor_pos--; - len--; - } - else if (k == KEY_DELETE && cursor_pos < len) - { - memmove(str + cursor_pos, str + cursor_pos + 1, len - cursor_pos); - len--; - } - else if (k == KEY_LEFT && cursor_pos > 0) - cursor_pos--; - else if (k == KEY_RIGHT && cursor_pos < len) - cursor_pos++; - else if (k == KEY_HOME) - cursor_pos = 0; - else if (k == KEY_END) - cursor_pos = len; - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.hpp deleted file mode 100644 index 80ef3c521..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/lineinput.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GAME_CLIENT_LINEINPUT_H -#define GAME_CLIENT_LINEINPUT_H - -// line input helter -class LINEINPUT -{ - char str[256]; - unsigned len; - unsigned cursor_pos; -public: - class CALLBACK - { - public: - virtual ~CALLBACK() {} - virtual bool event(INPUT_EVENT e) = 0; - }; - - LINEINPUT(); - void clear(); - void process_input(INPUT_EVENT e); - void set(const char *string); - const char *get_string() const { return str; } - int get_length() const { return len; } - unsigned cursor_offset() const { return cursor_pos; } -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/render.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/render.cpp deleted file mode 100644 index f63e86922..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/render.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include - -#include - -#include -#include -#include -#include -#include -#include "animstate.hpp" -#include "render.hpp" - -static float sprite_w_scale; -static float sprite_h_scale; -/* -static void layershot_begin() -{ - if(!config.cl_layershot) - return; - - gfx_clear(0,0,0); -} - -static void layershot_end() -{ - if(!config.cl_layershot) - return; - - char buf[256]; - str_format(buf, sizeof(buf), "screenshots/layers_%04d.png", config.cl_layershot); - gfx_screenshot_direct(buf); - config.cl_layershot++; -}*/ - -void select_sprite(SPRITE *spr, int flags, int sx, int sy) -{ - int x = spr->x+sx; - int y = spr->y+sy; - int w = spr->w; - int h = spr->h; - int cx = spr->set->gridx; - int cy = spr->set->gridy; - - float f = sqrtf(h*h + w*w); - sprite_w_scale = w/f; - sprite_h_scale = h/f; - - float x1 = x/(float)cx; - float x2 = (x+w)/(float)cx; - float y1 = y/(float)cy; - float y2 = (y+h)/(float)cy; - float temp = 0; - - if(flags&SPRITE_FLAG_FLIP_Y) - { - temp = y1; - y1 = y2; - y2 = temp; - } - - if(flags&SPRITE_FLAG_FLIP_X) - { - temp = x1; - x1 = x2; - x2 = temp; - } - - gfx_quads_setsubset(x1, y1, x2, y2); -} - -void select_sprite(int id, int flags, int sx, int sy) -{ - if(id < 0 || id > data->num_sprites) - return; - select_sprite(&data->sprites[id], flags, sx, sy); -} - -void draw_sprite(float x, float y, float size) -{ - gfx_quads_draw(x, y, size*sprite_w_scale, size*sprite_h_scale); -} - -void draw_round_rect_ext(float x, float y, float w, float h, float r, int corners) -{ - int num = 8; - for(int i = 0; i < num; i+=2) - { - float a1 = i/(float)num * pi/2; - float a2 = (i+1)/(float)num * pi/2; - float a3 = (i+2)/(float)num * pi/2; - float ca1 = cosf(a1); - float ca2 = cosf(a2); - float ca3 = cosf(a3); - float sa1 = sinf(a1); - float sa2 = sinf(a2); - float sa3 = sinf(a3); - - if(corners&1) // TL - gfx_quads_draw_freeform( - x+r, y+r, - x+(1-ca1)*r, y+(1-sa1)*r, - x+(1-ca3)*r, y+(1-sa3)*r, - x+(1-ca2)*r, y+(1-sa2)*r); - - if(corners&2) // TR - gfx_quads_draw_freeform( - x+w-r, y+r, - x+w-r+ca1*r, y+(1-sa1)*r, - x+w-r+ca3*r, y+(1-sa3)*r, - x+w-r+ca2*r, y+(1-sa2)*r); - - if(corners&4) // BL - gfx_quads_draw_freeform( - x+r, y+h-r, - x+(1-ca1)*r, y+h-r+sa1*r, - x+(1-ca3)*r, y+h-r+sa3*r, - x+(1-ca2)*r, y+h-r+sa2*r); - - if(corners&8) // BR - gfx_quads_draw_freeform( - x+w-r, y+h-r, - x+w-r+ca1*r, y+h-r+sa1*r, - x+w-r+ca3*r, y+h-r+sa3*r, - x+w-r+ca2*r, y+h-r+sa2*r); - } - - gfx_quads_drawTL(x+r, y+r, w-r*2, h-r*2); // center - gfx_quads_drawTL(x+r, y, w-r*2, r); // top - gfx_quads_drawTL(x+r, y+h-r, w-r*2, r); // bottom - gfx_quads_drawTL(x, y+r, r, h-r*2); // left - gfx_quads_drawTL(x+w-r, y+r, r, h-r*2); // right - - if(!(corners&1)) gfx_quads_drawTL(x, y, r, r); // TL - if(!(corners&2)) gfx_quads_drawTL(x+w, y, -r, r); // TR - if(!(corners&4)) gfx_quads_drawTL(x, y+h, r, -r); // BL - if(!(corners&8)) gfx_quads_drawTL(x+w, y+h, -r, -r); // BR -} - -void draw_round_rect(float x, float y, float w, float h, float r) -{ - draw_round_rect_ext(x,y,w,h,r,0xf); -} - -void ui_draw_rect(const RECT *r, vec4 color, int corners, float rounding) -{ - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(color.r, color.g, color.b, color.a); - draw_round_rect_ext(r->x,r->y,r->w,r->h,rounding*ui_scale(), corners); - gfx_quads_end(); -} - -void render_tee(ANIMSTATE *anim, TEE_RENDER_INFO *info, int emote, vec2 dir, vec2 pos) -{ - vec2 direction = dir; - vec2 position = pos; - - //gfx_texture_set(data->images[IMAGE_CHAR_DEFAULT].id); - gfx_texture_set(info->texture); - gfx_quads_begin(); - //gfx_quads_draw(pos.x, pos.y-128, 128, 128); - - // first pass we draw the outline - // second pass we draw the filling - for(int p = 0; p < 2; p++) - { - int outline = p==0 ? 1 : 0; - - for(int f = 0; f < 2; f++) - { - float animscale = info->size * 1.0f/64.0f; - float basesize = info->size; - if(f == 1) - { - gfx_quads_setrotation(anim->body.angle*pi*2); - - // draw body - gfx_setcolor(info->color_body.r, info->color_body.g, info->color_body.b, 1.0f); - vec2 body_pos = position + vec2(anim->body.x, anim->body.y)*animscale; - select_sprite(outline?SPRITE_TEE_BODY_OUTLINE:SPRITE_TEE_BODY, 0, 0, 0); - gfx_quads_draw(body_pos.x, body_pos.y, basesize, basesize); - - // draw eyes - if(p == 1) - { - switch (emote) - { - case EMOTE_PAIN: - select_sprite(SPRITE_TEE_EYE_PAIN, 0, 0, 0); - break; - case EMOTE_HAPPY: - select_sprite(SPRITE_TEE_EYE_HAPPY, 0, 0, 0); - break; - case EMOTE_SURPRISE: - select_sprite(SPRITE_TEE_EYE_SURPRISE, 0, 0, 0); - break; - case EMOTE_ANGRY: - select_sprite(SPRITE_TEE_EYE_ANGRY, 0, 0, 0); - break; - default: - select_sprite(SPRITE_TEE_EYE_NORMAL, 0, 0, 0); - break; - } - - float eyescale = basesize*0.40f; - float h = emote == EMOTE_BLINK ? basesize*0.15f : eyescale; - float eyeseparation = (0.075f - 0.010f*fabs(direction.x))*basesize; - vec2 offset = vec2(direction.x*0.125f, -0.05f+direction.y*0.10f)*basesize; - gfx_quads_draw(body_pos.x-eyeseparation+offset.x, body_pos.y+offset.y, eyescale, h); - gfx_quads_draw(body_pos.x+eyeseparation+offset.x, body_pos.y+offset.y, -eyescale, h); - } - } - - // draw feet - ANIM_KEYFRAME *foot = f ? &anim->front_foot : &anim->back_foot; - - float w = basesize; - float h = basesize/2; - - gfx_quads_setrotation(foot->angle*pi*2); - - bool indicate = !info->got_airjump && config.cl_airjumpindicator; - float cs = 1.0f; // color scale - - if(outline) - select_sprite(SPRITE_TEE_FOOT_OUTLINE, 0, 0, 0); - else - { - select_sprite(SPRITE_TEE_FOOT, 0, 0, 0); - if(indicate) - cs = 0.5f; - } - - gfx_setcolor(info->color_feet.r*cs, info->color_feet.g*cs, info->color_feet.b*cs, 1.0f); - gfx_quads_draw(position.x+foot->x*animscale, position.y+foot->y*animscale, w, h); - } - } - - gfx_quads_end(); - - -} - -static void calc_screen_params(float amount, float wmax, float hmax, float aspect, float *w, float *h) -{ - float f = sqrt(amount) / sqrt(aspect); - *w = f*aspect; - *h = f; - - // limit the view - if(*w > wmax) - { - *w = wmax; - *h = *w/aspect; - } - - if(*h > hmax) - { - *h = hmax; - *w = *h*aspect; - } -} - -void mapscreen_to_world(float center_x, float center_y, float parallax_x, float parallax_y, - float offset_x, float offset_y, float aspect, float zoom, float *points) -{ - float width, height; - calc_screen_params(1150*1000, 1500, 1050, aspect, &width, &height); - center_x *= parallax_x; - center_y *= parallax_y; - width *= zoom; - height *= zoom; - points[0] = offset_x+center_x-width/2; - points[1] = offset_y+center_y-height/2; - points[2] = offset_x+center_x+width/2; - points[3] = offset_y+center_y+height/2; -} - -void render_tilemap_generate_skip() -{ - for(int g = 0; g < layers_num_groups(); g++) - { - MAPITEM_GROUP *group = layers_get_group(g); - - for(int l = 0; l < group->num_layers; l++) - { - MAPITEM_LAYER *layer = layers_get_layer(group->start_layer+l); - - if(layer->type == LAYERTYPE_TILES) - { - MAPITEM_LAYER_TILEMAP *tmap = (MAPITEM_LAYER_TILEMAP *)layer; - TILE *tiles = (TILE *)map_get_data(tmap->data); - for(int y = 0; y < tmap->height; y++) - { - for(int x = 1; x < tmap->width; x++) - { - int sx; - for(sx = 1; x+sx < tmap->width && sx < 255; sx++) - { - if(tiles[y*tmap->width+x+sx].index) - break; - } - - tiles[y*tmap->width+x].skip = sx-1; - } - } - } - } - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/render.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/render.hpp deleted file mode 100644 index edbe9cb08..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/render.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef GAME_CLIENT_RENDER_H -#define GAME_CLIENT_RENDER_H - -#include - -#include "../mapitems.hpp" -#include "ui.hpp" - -struct TEE_RENDER_INFO -{ - TEE_RENDER_INFO() - { - texture = -1; - color_body = vec4(1,1,1,1); - color_feet = vec4(1,1,1,1); - size = 1.0f; - got_airjump = 1; - }; - - int texture; - vec4 color_body; - vec4 color_feet; - float size; - int got_airjump; -}; - -// sprite renderings -enum -{ - SPRITE_FLAG_FLIP_Y=1, - SPRITE_FLAG_FLIP_X=2, - - LAYERRENDERFLAG_OPAQUE=1, - LAYERRENDERFLAG_TRANSPARENT=2, - - TILERENDERFLAG_EXTEND=4, -}; - -struct SPRITE; - -void select_sprite(SPRITE *spr, int flags=0, int sx=0, int sy=0); -void select_sprite(int id, int flags=0, int sx=0, int sy=0); - -void draw_sprite(float x, float y, float size); - -// rects -void draw_round_rect(float x, float y, float w, float h, float r); -void draw_round_rect_ext(float x, float y, float w, float h, float r, int corners); -void ui_draw_rect(const RECT *r, vec4 color, int corners, float rounding); - -// larger rendering methods -void render_tilemap_generate_skip(); - -// object render methods (gc_render_obj.cpp) -void render_tee(class ANIMSTATE *anim, TEE_RENDER_INFO *info, int emote, vec2 dir, vec2 pos); - -// map render methods (gc_render_map.cpp) -void render_eval_envelope(ENVPOINT *points, int num_points, int channels, float time, float *result); -void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels), int flags); -void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int flags); - -// helpers -void mapscreen_to_world(float center_x, float center_y, float parallax_x, float parallax_y, - float offset_x, float offset_y, float aspect, float zoom, float *points); - - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/render_map.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/render_map.cpp deleted file mode 100644 index 118a4d736..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/render_map.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include "render.hpp" - -void render_eval_envelope(ENVPOINT *points, int num_points, int channels, float time, float *result) -{ - if(num_points == 0) - { - result[0] = 0; - result[1] = 0; - result[2] = 0; - result[3] = 0; - return; - } - - if(num_points == 1) - { - result[0] = fx2f(points[0].values[0]); - result[1] = fx2f(points[0].values[1]); - result[2] = fx2f(points[0].values[2]); - result[3] = fx2f(points[0].values[3]); - return; - } - - time = fmod(time, points[num_points-1].time/1000.0f)*1000.0f; - for(int i = 0; i < num_points-1; i++) - { - if(time >= points[i].time && time <= points[i+1].time) - { - float delta = points[i+1].time-points[i].time; - float a = (time-points[i].time)/delta; - - - if(points[i].curvetype == CURVETYPE_SMOOTH) - a = -2*a*a*a + 3*a*a; // second hermite basis - else if(points[i].curvetype == CURVETYPE_SLOW) - a = a*a*a; - else if(points[i].curvetype == CURVETYPE_FAST) - { - a = 1-a; - a = 1-a*a*a; - } - else if (points[i].curvetype == CURVETYPE_STEP) - a = 0; - else - { - // linear - } - - for(int c = 0; c < channels; c++) - { - float v0 = fx2f(points[i].values[c]); - float v1 = fx2f(points[i+1].values[c]); - result[c] = v0 + (v1-v0) * a; - } - - return; - } - } - - result[0] = fx2f(points[num_points-1].values[0]); - result[1] = fx2f(points[num_points-1].values[1]); - result[2] = fx2f(points[num_points-1].values[2]); - result[3] = fx2f(points[num_points-1].values[3]); - return; -} - - -static void rotate(POINT *center, POINT *point, float rotation) -{ - int x = point->x - center->x; - int y = point->y - center->y; - point->x = (int)(x * cosf(rotation) - y * sinf(rotation) + center->x); - point->y = (int)(x * sinf(rotation) + y * cosf(rotation) + center->y); -} - -void render_quads(QUAD *quads, int num_quads, void (*eval)(float time_offset, int env, float *channels), int renderflags) -{ - gfx_quads_begin(); - float conv = 1/255.0f; - for(int i = 0; i < num_quads; i++) - { - QUAD *q = &quads[i]; - - float r=1, g=1, b=1, a=1; - - if(q->color_env >= 0) - { - float channels[4]; - eval(q->color_env_offset/1000.0f, q->color_env, channels); - r = channels[0]; - g = channels[1]; - b = channels[2]; - a = channels[3]; - } - - bool opaque = false; - if(a < 0.01f || (q->colors[0].a < 0.01f && q->colors[1].a < 0.01f && q->colors[2].a < 0.01f && q->colors[3].a < 0.01f)) - opaque = true; - - if(opaque && !(renderflags&LAYERRENDERFLAG_OPAQUE)) - continue; - if(!opaque && !(renderflags&LAYERRENDERFLAG_TRANSPARENT)) - continue; - - gfx_quads_setsubset_free( - fx2f(q->texcoords[0].x), fx2f(q->texcoords[0].y), - fx2f(q->texcoords[1].x), fx2f(q->texcoords[1].y), - fx2f(q->texcoords[2].x), fx2f(q->texcoords[2].y), - fx2f(q->texcoords[3].x), fx2f(q->texcoords[3].y) - ); - - float offset_x = 0; - float offset_y = 0; - float rot = 0; - - // TODO: fix this - if(q->pos_env >= 0) - { - float channels[4]; - eval(q->pos_env_offset/1000.0f, q->pos_env, channels); - offset_x = channels[0]; - offset_y = channels[1]; - rot = channels[2]/360.0f*pi*2; - } - - - gfx_setcolorvertex(0, q->colors[0].r*conv*r, q->colors[0].g*conv*g, q->colors[0].b*conv*b, q->colors[0].a*conv*a); - gfx_setcolorvertex(1, q->colors[1].r*conv*r, q->colors[1].g*conv*g, q->colors[1].b*conv*b, q->colors[1].a*conv*a); - gfx_setcolorvertex(2, q->colors[2].r*conv*r, q->colors[2].g*conv*g, q->colors[2].b*conv*b, q->colors[2].a*conv*a); - gfx_setcolorvertex(3, q->colors[3].r*conv*r, q->colors[3].g*conv*g, q->colors[3].b*conv*b, q->colors[3].a*conv*a); - - POINT *points = q->points; - - if(rot != 0) - { - static POINT rotated[4]; - rotated[0] = q->points[0]; - rotated[1] = q->points[1]; - rotated[2] = q->points[2]; - rotated[3] = q->points[3]; - points = rotated; - - rotate(&q->points[4], &rotated[0], rot); - rotate(&q->points[4], &rotated[1], rot); - rotate(&q->points[4], &rotated[2], rot); - rotate(&q->points[4], &rotated[3], rot); - } - - gfx_quads_draw_freeform( - fx2f(points[0].x)+offset_x, fx2f(points[0].y)+offset_y, - fx2f(points[1].x)+offset_x, fx2f(points[1].y)+offset_y, - fx2f(points[2].x)+offset_x, fx2f(points[2].y)+offset_y, - fx2f(points[3].x)+offset_x, fx2f(points[3].y)+offset_y - ); - } - gfx_quads_end(); -} - -void render_tilemap(TILE *tiles, int w, int h, float scale, vec4 color, int renderflags) -{ - //gfx_texture_set(img_get(tmap->image)); - float screen_x0, screen_y0, screen_x1, screen_y1; - gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); - //gfx_mapscreen(screen_x0-50, screen_y0-50, screen_x1+50, screen_y1+50); - - // calculate the final pixelsize for the tiles - float tile_pixelsize = 1024/32.0f; - float final_tilesize = scale/(screen_x1-screen_x0) * gfx_screenwidth(); - float final_tilesize_scale = final_tilesize/tile_pixelsize; - - gfx_quads_begin(); - gfx_setcolor(color.r, color.g, color.b, color.a); - - int starty = (int)(screen_y0/scale)-1; - int startx = (int)(screen_x0/scale)-1; - int endy = (int)(screen_y1/scale)+1; - int endx = (int)(screen_x1/scale)+1; - - // adjust the texture shift according to mipmap level - float texsize = 1024.0f; - float frac = (1.25f/texsize) * (1/final_tilesize_scale); - float nudge = (0.5f/texsize) * (1/final_tilesize_scale); - - for(int y = starty; y < endy; y++) - for(int x = startx; x < endx; x++) - { - int mx = x; - int my = y; - - if(renderflags&TILERENDERFLAG_EXTEND) - { - if(mx<0) - mx = 0; - if(mx>=w) - mx = w-1; - if(my<0) - my = 0; - if(my>=h) - my = h-1; - } - else - { - if(mx<0) - continue; // mx = 0; - if(mx>=w) - continue; // mx = w-1; - if(my<0) - continue; // my = 0; - if(my>=h) - continue; // my = h-1; - } - - int c = mx + my*w; - - unsigned char index = tiles[c].index; - if(index) - { - unsigned char flags = tiles[c].flags; - - bool render = false; - if(flags&TILEFLAG_OPAQUE) - { - if(renderflags&LAYERRENDERFLAG_OPAQUE) - render = true; - } - else - { - if(renderflags&LAYERRENDERFLAG_TRANSPARENT) - render = true; - } - - if(render) - { - - int tx = index%16; - int ty = index/16; - int px0 = tx*(1024/16); - int py0 = ty*(1024/16); - int px1 = (tx+1)*(1024/16)-1; - int py1 = (ty+1)*(1024/16)-1; - - float u0 = nudge + px0/texsize+frac; - float v0 = nudge + py0/texsize+frac; - float u1 = nudge + px1/texsize-frac; - float v1 = nudge + py1/texsize-frac; - - if(flags&TILEFLAG_VFLIP) - { - float tmp = u0; - u0 = u1; - u1 = tmp; - } - - if(flags&TILEFLAG_HFLIP) - { - float tmp = v0; - v0 = v1; - v1 = tmp; - } - - gfx_quads_setsubset(u0,v0,u1,v1); - gfx_quads_drawTL(x*scale, y*scale, scale, scale); - } - } - x += tiles[c].skip; - } - - gfx_quads_end(); - gfx_mapscreen(screen_x0, screen_y0, screen_x1, screen_y1); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/ui.cpp b/project/jni/application/teeworlds-0.5.2/src/game/client/ui.cpp deleted file mode 100644 index 1361b85c3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/ui.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include - -#include -#include -#include "ui.hpp" - -/******************************************************** - UI -*********************************************************/ -static const void *hot_item = 0; -static const void *active_item = 0; -static const void *last_active_item = 0; -static const void *becomming_hot_item = 0; -static float mouse_x, mouse_y; /* in gui space */ -static float mouse_wx, mouse_wy; /* in world space */ -static unsigned mouse_buttons = 0; -static unsigned last_mouse_buttons = 0; - -float ui_mouse_x() { return mouse_x; } -float ui_mouse_y() { return mouse_y; } -float ui_mouse_world_x() { return mouse_wx; } -float ui_mouse_world_y() { return mouse_wy; } -int ui_mouse_button(int index) { return (mouse_buttons>>index)&1; } -int ui_mouse_button_clicked(int index) { return ui_mouse_button(index) && !((last_mouse_buttons>>index)&1) ; } - -void ui_set_hot_item(const void *id) { becomming_hot_item = id; } -void ui_set_active_item(const void *id) { active_item = id; if (id) last_active_item = id; } -void ui_clear_last_active_item() { last_active_item = 0; } -const void *ui_hot_item() { return hot_item; } -const void *ui_next_hot_item() { return becomming_hot_item; } -const void *ui_active_item() { return active_item; } -const void *ui_last_active_item() { return last_active_item; } - -int ui_update(float mx, float my, float mwx, float mwy, int buttons) -{ - mouse_x = mx; - mouse_y = my; - mouse_wx = mwx; - mouse_wy = mwy; - last_mouse_buttons = mouse_buttons; - mouse_buttons = buttons; - hot_item = becomming_hot_item; - if(active_item) - hot_item = active_item; - becomming_hot_item = 0; - return 0; -} -/* -bool ui_ -*/ -int ui_mouse_inside(const RECT *r) -{ - if(mouse_x >= r->x && mouse_x <= r->x+r->w && mouse_y >= r->y && mouse_y <= r->y+r->h) - return 1; - return 0; -} - -static RECT screen = { 0.0f, 0.0f, 848.0f, 480.0f }; - -RECT *ui_screen() -{ - float aspect = gfx_screenaspect(); - float w, h; - - h = 600; - w = aspect*h; - - screen.w = w; - screen.h = h; - - return &screen; -} - -void ui_set_scale(float s) -{ - config.ui_scale = (int)(s*100.0f); -} - -float ui_scale() -{ - return config.ui_scale/100.0f; -} - -void ui_clip_enable(const RECT *r) -{ - float xscale = gfx_screenwidth()/ui_screen()->w; - float yscale = gfx_screenheight()/ui_screen()->h; - gfx_clip_enable((int)(r->x*xscale), (int)(r->y*yscale), (int)(r->w*xscale), (int)(r->h*yscale)); -} - -void ui_clip_disable() -{ - gfx_clip_disable(); -} - -void ui_hsplit_t(const RECT *original, float cut, RECT *top, RECT *bottom) -{ - RECT r = *original; - cut *= ui_scale(); - - if (top) - { - top->x = r.x; - top->y = r.y; - top->w = r.w; - top->h = cut; - } - - if (bottom) - { - bottom->x = r.x; - bottom->y = r.y + cut; - bottom->w = r.w; - bottom->h = r.h - cut; - } -} - -void ui_hsplit_b(const RECT *original, float cut, RECT *top, RECT *bottom) -{ - RECT r = *original; - cut *= ui_scale(); - - if (top) - { - top->x = r.x; - top->y = r.y; - top->w = r.w; - top->h = r.h - cut; - } - - if (bottom) - { - bottom->x = r.x; - bottom->y = r.y + r.h - cut; - bottom->w = r.w; - bottom->h = cut; - } -} - - -void ui_vsplit_mid(const RECT *original, RECT *left, RECT *right) -{ - RECT r = *original; - float cut = r.w/2; - - if (left) - { - left->x = r.x; - left->y = r.y; - left->w = cut; - left->h = r.h; - } - - if (right) - { - right->x = r.x + cut; - right->y = r.y; - right->w = r.w - cut; - right->h = r.h; - } -} - -void ui_vsplit_l(const RECT *original, float cut, RECT *left, RECT *right) -{ - RECT r = *original; - cut *= ui_scale(); - - if (left) - { - left->x = r.x; - left->y = r.y; - left->w = cut; - left->h = r.h; - } - - if (right) - { - right->x = r.x + cut; - right->y = r.y; - right->w = r.w - cut; - right->h = r.h; - } -} - -void ui_vsplit_r(const RECT *original, float cut, RECT *left, RECT *right) -{ - RECT r = *original; - cut *= ui_scale(); - - if (left) - { - left->x = r.x; - left->y = r.y; - left->w = r.w - cut; - left->h = r.h; - } - - if (right) - { - right->x = r.x + r.w - cut; - right->y = r.y; - right->w = cut; - right->h = r.h; - } -} - -void ui_margin(const RECT *original, float cut, RECT *other_rect) -{ - RECT r = *original; - cut *= ui_scale(); - - other_rect->x = r.x + cut; - other_rect->y = r.y + cut; - other_rect->w = r.w - 2*cut; - other_rect->h = r.h - 2*cut; -} - -void ui_vmargin(const RECT *original, float cut, RECT *other_rect) -{ - RECT r = *original; - cut *= ui_scale(); - - other_rect->x = r.x + cut; - other_rect->y = r.y; - other_rect->w = r.w - 2*cut; - other_rect->h = r.h; -} - -void ui_hmargin(const RECT *original, float cut, RECT *other_rect) -{ - RECT r = *original; - cut *= ui_scale(); - - other_rect->x = r.x; - other_rect->y = r.y + cut; - other_rect->w = r.w; - other_rect->h = r.h - 2*cut; -} - - -int ui_do_button(const void *id, const char *text, int checked, const RECT *r, ui_draw_button_func draw_func, const void *extra) -{ - /* logic */ - int ret = 0; - int inside = ui_mouse_inside(r); - static int button_used = 0; - - if(ui_active_item() == id) - { - if(!ui_mouse_button(button_used)) - { - if(inside && checked >= 0) - ret = 1+button_used; - ui_set_active_item(0); - } - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - ui_set_active_item(id); - button_used = 0; - } - - if(ui_mouse_button(1)) - { - ui_set_active_item(id); - button_used = 1; - } - } - - if(inside) - ui_set_hot_item(id); - - if(draw_func) - draw_func(id, text, checked, r, extra); - return ret; -} - -void ui_do_label(const RECT *r, const char *text, float size, int align, int max_width) -{ - gfx_blend_normal(); - size *= ui_scale(); - if(align == 0) - { - float tw = gfx_text_width(0, size, text, max_width); - gfx_text(0, r->x + r->w/2-tw/2, r->y, size, text, max_width); - } - else if(align < 0) - gfx_text(0, r->x, r->y, size, text, max_width); - else if(align > 0) - { - float tw = gfx_text_width(0, size, text, max_width); - gfx_text(0, r->x + r->w-tw, r->y, size, text, max_width); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/client/ui.hpp b/project/jni/application/teeworlds-0.5.2/src/game/client/ui.hpp deleted file mode 100644 index 7a6cb5ded..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/client/ui.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef FILE_GAME_CLIENT_UI_H -#define FILE_GAME_CLIENT_UI_H - -typedef struct -{ - float x, y, w, h; -} RECT; - -enum -{ - CORNER_TL=1, - CORNER_TR=2, - CORNER_BL=4, - CORNER_BR=8, - - CORNER_T=CORNER_TL|CORNER_TR, - CORNER_B=CORNER_BL|CORNER_BR, - CORNER_R=CORNER_TR|CORNER_BR, - CORNER_L=CORNER_TL|CORNER_BL, - - CORNER_ALL=CORNER_T|CORNER_B -}; - -int ui_update(float mx, float my, float mwx, float mwy, int buttons); - -float ui_mouse_x(); -float ui_mouse_y(); -float ui_mouse_world_x(); -float ui_mouse_world_y(); -int ui_mouse_button(int index); -int ui_mouse_button_clicked(int index); - -void ui_set_hot_item(const void *id); -void ui_set_active_item(const void *id); -void ui_clear_last_active_item(); -const void *ui_hot_item(); -const void *ui_next_hot_item(); -const void *ui_active_item(); -const void *ui_last_active_item(); - -int ui_mouse_inside(const RECT *r); - -RECT *ui_screen(); -void ui_set_scale(float s); -float ui_scale(); -void ui_clip_enable(const RECT *r); -void ui_clip_disable(); - -void ui_hsplit_t(const RECT *original, float cut, RECT *top, RECT *bottom); -void ui_hsplit_b(const RECT *original, float cut, RECT *top, RECT *bottom); -void ui_vsplit_mid(const RECT *original, RECT *left, RECT *right); -void ui_vsplit_l(const RECT *original, float cut, RECT *left, RECT *right); -void ui_vsplit_r(const RECT *original, float cut, RECT *left, RECT *right); - -void ui_margin(const RECT *original, float cut, RECT *other_rect); -void ui_vmargin(const RECT *original, float cut, RECT *other_rect); -void ui_hmargin(const RECT *original, float cut, RECT *other_rect); - -typedef void (*ui_draw_button_func)(const void *id, const char *text, int checked, const RECT *r, const void *extra); -int ui_do_button(const void *id, const char *text, int checked, const RECT *r, ui_draw_button_func draw_func, const void *extra); -void ui_do_label(const RECT *r, const char *text, float size, int align, int max_width = -1); - - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/collision.cpp b/project/jni/application/teeworlds-0.5.2/src/game/collision.cpp deleted file mode 100644 index 73f4a9c5d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/collision.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include -#include -#include -#include -#include - -static TILE *tiles; -static int width = 0; -static int height = 0; - -int col_width() { return width; } -int col_height() { return height; } - -int col_init() -{ - width = layers_game_layer()->width; - height = layers_game_layer()->height; - tiles = (TILE *)map_get_data(layers_game_layer()->data); - - for(int i = 0; i < width*height; i++) - { - int index = tiles[i].index; - - if(index > 128) - continue; - - if(index == TILE_DEATH) - tiles[i].index = COLFLAG_DEATH; - else if(index == TILE_SOLID) - tiles[i].index = COLFLAG_SOLID; - else if(index == TILE_NOHOOK) - tiles[i].index = COLFLAG_SOLID|COLFLAG_NOHOOK; - else - tiles[i].index = 0; - } - - return 1; -} - - -int col_get(int x, int y) -{ - int nx = clamp(x/32, 0, width-1); - int ny = clamp(y/32, 0, height-1); - - if(tiles[ny*width+nx].index > 128) - return 0; - return tiles[ny*width+nx].index; -} - -int col_is_solid(int x, int y) -{ - return col_get(x,y)&COLFLAG_SOLID; -} - - -// TODO: rewrite this smarter! -int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out_collision, vec2 *out_before_collision) -{ - float d = distance(pos0, pos1); - vec2 last = pos0; - - for(float f = 0; f < d; f++) - { - float a = f/d; - vec2 pos = mix(pos0, pos1, a); - if(col_is_solid(round(pos.x), round(pos.y))) - { - if(out_collision) - *out_collision = pos; - if(out_before_collision) - *out_before_collision = last; - return col_get(round(pos.x), round(pos.y)); - } - last = pos; - } - if(out_collision) - *out_collision = pos1; - if(out_before_collision) - *out_before_collision = pos1; - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/collision.hpp b/project/jni/application/teeworlds-0.5.2/src/game/collision.hpp deleted file mode 100644 index 0f072daa7..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/collision.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef GAME_MAPRES_COL_H -#define GAME_MAPRES_COL_H - -#include - -enum -{ - COLFLAG_SOLID=1, - COLFLAG_DEATH=2, - COLFLAG_NOHOOK=4, -}; - -int col_init(); -int col_is_solid(int x, int y); -int col_get(int x, int y); -int col_width(); -int col_height(); -int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out_collision, vec2 *out_before_collision); - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/array.hpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/array.hpp deleted file mode 100755 index fe9f2739a..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/array.hpp +++ /dev/null @@ -1,238 +0,0 @@ - -template -class array -{ - // - // - void init() - { - list = 0; - clear(); - } - -public: - array() - { - init(); - } - - // - array(const array &other) - { - init(); - setsize(other.len()); - for(int i = 0; i < len(); i++) - (*this)[i] = other[i]; - } - - - // - // - virtual ~array() - { - delete [] list; - list = 0; - } - - // - // - void deleteall() - { - for(int i = 0; i < len(); i++) - delete list[i]; - - clear(); - } - - - // - // - void clear() - { - delete [] list; - - list_size = 1; - list = new T[1]; - num_elements = 0; - } - - int find(T val) - { - for(int i = 0; i < len(); i++) - if((*this)[i] == val) - return i; - return -1; - } - - bool exist(T val) - { - return find(val) != -1; - } - - // - // returns the number of elements in the list - // - int len() const - { - return num_elements; - } - - // - // This doesn't conserve the order in the list. Be careful - // - void removebyindexfast(int index) - { - //ASSUME(_Pos >= 0 && _Pos < num_elements); - list[index] = list[num_elements-1]; - setsize(len()-1); - } - - void removefast(const T& _Elem) - { - for(int i = 0; i < len(); i++) - if(list[i] == _Elem) - { - removebyindexfast(i); - return; - } - } - - // - // - void removebyindex(int index) - { - //ASSUME(_Pos >= 0 && _Pos < num_elements); - - for(int i = index+1; i < num_elements; i++) - list[i-1] = list[i]; - - setsize(len()-1); - } - - void insert(int index, const T& element) - { - int some_len = len(); - if (index < some_len) - setsize(some_len+1); - else - setsize(index + 1); - - for(int i = num_elements-2; i >= index; i--) - list[i+1] = list[i]; - - list[index] = element; - } - - bool remove(const T& element) - { - for(int i = 0; i < len(); i++) - if(list[i] == element) - { - removebyindex(i); - return true; - } - return false; - } - - // - // - int add(const T& element) - { - //if(num_elements == list_size) - setsize(len()+1); - list[num_elements-1] = element; - return num_elements-1; - } - - // - // - int add(const T& elem, int index) - { - setsize(len()+1); - - for(int i = num_elements-1; i > index; i--) - list[i] = list[i-1]; - - list[index] = elem; - - //num_elements++; - return num_elements-1; - } - - // - // - T& operator[] (int index) - { - return list[index]; - } - - const T& operator[] (int index) const - { - return list[index]; - } - - // - // - T *getptr() - { - return list; - } - - const T *getptr() const - { - return list; - } - - // - // - // - void setsize(int new_len) - { - if (list_size < new_len) - allocsize(new_len); - num_elements = new_len; - } - - // removes unnessasary data, returns how many bytes was earned - int optimize() - { - int Before = memoryusage(); - setsize(num_elements); - return Before - memoryusage(); - } - - // returns how much memory this dynamic array is using - int memoryusage() - { - return sizeof(array) + sizeof(T)*list_size; - } - - // - array &operator = (const array &other) - { - setsize(other.len()); - for(int i = 0; i < len(); i++) - (*this)[i] = other[i]; - return *this; - } -private: - void allocsize(int new_len) - { - list_size = new_len; - T *new_list = new T[list_size]; - - long end = num_elements < list_size ? num_elements : list_size; - for(int i = 0; i < end; i++) - new_list[i] = list[i]; - - delete [] list; - list = 0; - num_elements = num_elements < list_size ? num_elements : list_size; - list = new_list; - } - - T *list; - long list_size; - long num_elements; -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.cpp deleted file mode 100644 index 07f105118..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.cpp +++ /dev/null @@ -1,2781 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "ed_editor.hpp" - -static int checker_texture = 0; -static int background_texture = 0; -static int cursor_texture = 0; -static int entities_texture = 0; - - -static const void *ui_got_context = 0; - -EDITOR editor; - -LAYERGROUP::LAYERGROUP() -{ - name = ""; - visible = true; - game_group = false; - offset_x = 0; - offset_y = 0; - parallax_x = 100; - parallax_y = 100; - - use_clipping = 0; - clip_x = 0; - clip_y = 0; - clip_w = 0; - clip_h = 0; -} - -LAYERGROUP::~LAYERGROUP() -{ - clear(); -} - -void LAYERGROUP::convert(RECT *rect) -{ - rect->x += offset_x; - rect->y += offset_y; -} - -void LAYERGROUP::mapping(float *points) -{ - mapscreen_to_world( - editor.world_offset_x, editor.world_offset_y, - parallax_x/100.0f, parallax_y/100.0f, - offset_x, offset_y, - gfx_screenaspect(), editor.world_zoom, points); - - points[0] += editor.editor_offset_x; - points[1] += editor.editor_offset_y; - points[2] += editor.editor_offset_x; - points[3] += editor.editor_offset_y; -} - -void LAYERGROUP::mapscreen() -{ - float points[4]; - mapping(points); - gfx_mapscreen(points[0], points[1], points[2], points[3]); -} - -void LAYERGROUP::render() -{ - mapscreen(); - - if(use_clipping) - { - float points[4]; - editor.map.game_group->mapping(points); - float x0 = (clip_x - points[0]) / (points[2]-points[0]); - float y0 = (clip_y - points[1]) / (points[3]-points[1]); - float x1 = ((clip_x+clip_w) - points[0]) / (points[2]-points[0]); - float y1 = ((clip_y+clip_h) - points[1]) / (points[3]-points[1]); - - gfx_clip_enable((int)(x0*gfx_screenwidth()), (int)(y0*gfx_screenheight()), - (int)((x1-x0)*gfx_screenwidth()), (int)((y1-y0)*gfx_screenheight())); - } - - for(int i = 0; i < layers.len(); i++) - { - if(layers[i]->visible && layers[i] != editor.map.game_layer) - { - if(editor.show_detail || !(layers[i]->flags&LAYERFLAG_DETAIL)) - layers[i]->render(); - } - } - - gfx_clip_disable(); -} - -bool LAYERGROUP::is_empty() const { return layers.len() == 0; } -void LAYERGROUP::clear() { layers.deleteall(); } -void LAYERGROUP::add_layer(LAYER *l) { layers.add(l); } - -void LAYERGROUP::delete_layer(int index) -{ - if(index < 0 || index >= layers.len()) return; - delete layers[index]; - layers.removebyindex(index); -} - -void LAYERGROUP::get_size(float *w, float *h) -{ - *w = 0; *h = 0; - for(int i = 0; i < layers.len(); i++) - { - float lw, lh; - layers[i]->get_size(&lw, &lh); - *w = max(*w, lw); - *h = max(*h, lh); - } -} - - -int LAYERGROUP::swap_layers(int index0, int index1) -{ - if(index0 < 0 || index0 >= layers.len()) return index0; - if(index1 < 0 || index1 >= layers.len()) return index0; - if(index0 == index1) return index0; - swap(layers[index0], layers[index1]); - return index1; -} - -void EDITOR_IMAGE::analyse_tileflags() -{ - mem_zero(tileflags, sizeof(tileflags)); - - int tw = width/16; // tilesizes - int th = height/16; - if ( tw == th ) { - unsigned char *pixeldata = (unsigned char *)data; - - int tile_id = 0; - for(int ty = 0; ty < 16; ty++) - for(int tx = 0; tx < 16; tx++, tile_id++) - { - bool opaque = true; - for(int x = 0; x < tw; x++) - for(int y = 0; y < th; y++) - { - int p = (ty*tw+y)*width + tx*tw+x; - if(pixeldata[p*4+3] < 250) - { - opaque = false; - break; - } - } - - if(opaque) - tileflags[tile_id] |= TILEFLAG_OPAQUE; - } - } - -} - -/******************************************************** - OTHER -*********************************************************/ - -// copied from gc_menu.cpp, should be more generalized -//extern int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden=false); - -int ui_do_edit_box(void *id, const RECT *rect, char *str, int str_size, float font_size, bool hidden=false) -{ - int inside = ui_mouse_inside(rect); - int r = 0; - static int at_index = 0; - - if(ui_last_active_item() == id) - { - int len = strlen(str); - - if (inside && ui_mouse_button(0)) - { - int mx_rel = (int)(ui_mouse_x() - rect->x); - - for (int i = 1; i <= len; i++) - { - if (gfx_text_width(0, font_size, str, i) + 10 > mx_rel) - { - at_index = i - 1; - break; - } - - if (i == len) - at_index = len; - } - } - - for(int i = 0; i < inp_num_events(); i++) - { - len = strlen(str); - - INPUT_EVENT e = inp_get_event(i); - char c = e.ch; - int k = e.key; - - if (at_index > len) - at_index = len; - - if (!(c >= 0 && c < 32) && c != 127) - { - if (len < str_size - 1 && at_index < str_size - 1) - { - memmove(str + at_index + 1, str + at_index, len - at_index + 1); - str[at_index] = c; - at_index++; - } - } - - if(e.flags&INPFLAG_PRESS) - { - if (k == KEY_BACKSPACE && at_index > 0) - { - memmove(str + at_index - 1, str + at_index, len - at_index + 1); - at_index--; - } - else if (k == KEY_DELETE && at_index < len) - memmove(str + at_index, str + at_index + 1, len - at_index); - else if (k == KEY_RETURN) - ui_clear_last_active_item(); - else if (k == KEY_LEFT && at_index > 0) - at_index--; - else if (k == KEY_RIGHT && at_index < len) - at_index++; - else if (k == KEY_HOME) - at_index = 0; - else if (k == KEY_END) - at_index = len; - } - } - - r = 1; - } - - bool just_got_active = false; - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - if (ui_last_active_item() != id) - just_got_active = true; - ui_set_active_item(id); - } - } - - if(inside) - ui_set_hot_item(id); - - RECT textbox = *rect; - ui_draw_rect(&textbox, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f); - ui_vmargin(&textbox, 5.0f, &textbox); - - const char *display_str = str; - char stars[128]; - - if(hidden) - { - unsigned s = strlen(str); - if(s >= sizeof(stars)) - s = sizeof(stars)-1; - memset(stars, '*', s); - stars[s] = 0; - display_str = stars; - } - - ui_do_label(&textbox, display_str, font_size, -1); - - if (ui_last_active_item() == id && !just_got_active) - { - float w = gfx_text_width(0, font_size, display_str, at_index); - textbox.x += w*ui_scale(); - ui_do_label(&textbox, "_", font_size, -1); - } - - return r; -} - -vec4 button_color_mul(const void *id) -{ - if(ui_active_item() == id) - return vec4(1,1,1,0.5f); - else if(ui_hot_item() == id) - return vec4(1,1,1,1.5f); - return vec4(1,1,1,1); -} - -float ui_do_scrollbar_v(const void *id, const RECT *rect, float current) -{ - RECT handle; - static float offset_y; - ui_hsplit_t(rect, 33, &handle, 0); - - handle.y += (rect->h-handle.h)*current; - - /* logic */ - float ret = current; - int inside = ui_mouse_inside(&handle); - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - ui_set_active_item(0); - - float min = rect->y; - float max = rect->h-handle.h; - float cur = ui_mouse_y()-offset_y; - ret = (cur-min)/max; - if(ret < 0.0f) ret = 0.0f; - if(ret > 1.0f) ret = 1.0f; - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - ui_set_active_item(id); - offset_y = ui_mouse_y()-handle.y; - } - } - - if(inside) - ui_set_hot_item(id); - - // render - RECT rail; - ui_vmargin(rect, 5.0f, &rail); - ui_draw_rect(&rail, vec4(1,1,1,0.25f), 0, 0.0f); - - RECT slider = handle; - slider.w = rail.x-slider.x; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_L, 2.5f); - slider.x = rail.x+rail.w; - ui_draw_rect(&slider, vec4(1,1,1,0.25f), CORNER_R, 2.5f); - - slider = handle; - ui_margin(&slider, 5.0f, &slider); - ui_draw_rect(&slider, vec4(1,1,1,0.25f)*button_color_mul(id), CORNER_ALL, 2.5f); - - return ret; -} - -static vec4 get_button_color(const void *id, int checked) -{ - if(checked < 0) - return vec4(0,0,0,0.5f); - - if(checked > 0) - { - if(ui_hot_item() == id) - return vec4(1,0,0,0.75f); - return vec4(1,0,0,0.5f); - } - - if(ui_hot_item() == id) - return vec4(1,1,1,0.75f); - return vec4(1,1,1,0.5f); -} - -void draw_editor_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), CORNER_ALL, 3.0f); - ui_do_label(r, text, 10, 0, -1); -} - -static void draw_editor_button_file(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - if(ui_hot_item() == id) - ui_draw_rect(r, get_button_color(id, checked), CORNER_ALL, 3.0f); - - RECT t = *r; - ui_vmargin(&t, 5.0f, &t); - ui_do_label(&t, text, 10, -1, -1); -} - -static void draw_editor_button_menu(const void *id, const char *text, int checked, const RECT *rect, const void *extra) -{ - /* - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - if(ui_hot_item() == id) - ui_draw_rect(r, get_button_color(id, checked), CORNER_ALL, 3.0f); - */ - - RECT r = *rect; - /* - if(ui_popups[id == id) - { - ui_draw_rect(&r, vec4(0.5f,0.5f,0.5f,0.75f), CORNER_T, 3.0f); - ui_margin(&r, 1.0f, &r); - ui_draw_rect(&r, vec4(0,0,0,0.75f), CORNER_T, 3.0f); - } - else*/ - ui_draw_rect(&r, vec4(0.5f,0.5f,0.5f, 1.0f), CORNER_T, 3.0f); - - - r = *rect; - ui_vmargin(&r, 5.0f, &r); - ui_do_label(&r, text, 10, -1, -1); - - //RECT t = *r; -} - -void draw_editor_button_menuitem(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - if(ui_hot_item() == id || checked) - ui_draw_rect(r, get_button_color(id, checked), CORNER_ALL, 3.0f); - - RECT t = *r; - ui_vmargin(&t, 5.0f, &t); - ui_do_label(&t, text, 10, -1, -1); -} - -static void draw_editor_button_l(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), CORNER_L, 3.0f); - ui_do_label(r, text, 10, 0, -1); -} - -static void draw_editor_button_m(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), 0, 3.0f); - ui_do_label(r, text, 10, 0, -1); -} - -static void draw_editor_button_r(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item() == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), CORNER_R, 3.0f); - ui_do_label(r, text, 10, 0, -1); -} - -static void draw_inc_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), CORNER_R, 3.0f); - ui_do_label(r, text?text:">", 10, 0, -1); -} - -static void draw_dec_button(const void *id, const char *text, int checked, const RECT *r, const void *extra) -{ - if(ui_hot_item == id) if(extra) editor.tooltip = (const char *)extra; - ui_draw_rect(r, get_button_color(id, checked), CORNER_L, 3.0f); - ui_do_label(r, text?text:"<", 10, 0, -1); -} - -enum -{ - BUTTON_CONTEXT=1, -}; - -int do_editor_button(const void *id, const char *text, int checked, const RECT *r, ui_draw_button_func draw_func, int flags, const char *tooltip) -{ - if(ui_mouse_inside(r)) - { - if(flags&BUTTON_CONTEXT) - ui_got_context = id; - if(tooltip) - editor.tooltip = tooltip; - } - - return ui_do_button(id, text, checked, r, draw_func, 0); -} - - -static void render_background(RECT view, int texture, float size, float brightness) -{ - gfx_texture_set(texture); - gfx_blend_normal(); - gfx_quads_begin(); - gfx_setcolor(brightness,brightness,brightness,1.0f); - gfx_quads_setsubset(0,0, view.w/size, view.h/size); - gfx_quads_drawTL(view.x, view.y, view.w, view.h); - gfx_quads_end(); -} - -static LAYERGROUP brush; -static LAYER_TILES tileset_picker(16, 16); - -static int ui_do_value_selector(void *id, RECT *r, const char *label, int current, int min, int max, float scale) -{ - /* logic */ - static float value; - int ret = 0; - int inside = ui_mouse_inside(r); - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - { - if(inside) - ret = 1; - editor.lock_mouse = false; - ui_set_active_item(0); - } - else - { - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - value += editor.mouse_delta_x*0.05f; - else - value += editor.mouse_delta_x; - - if(fabs(value) > scale) - { - int count = (int)(value/scale); - value = fmod(value, scale); - current += count; - if(current < min) - current = min; - if(current > max) - current = max; - } - } - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - editor.lock_mouse = true; - value = 0; - ui_set_active_item(id); - } - } - - if(inside) - ui_set_hot_item(id); - - // render - char buf[128]; - sprintf(buf, "%s %d", label, current); - ui_draw_rect(r, get_button_color(id, 0), CORNER_ALL, 5.0f); - ui_do_label(r, buf, 10, 0, -1); - return current; -} - -LAYERGROUP *EDITOR::get_selected_group() -{ - if(selected_group >= 0 && selected_group < editor.map.groups.len()) - return editor.map.groups[selected_group]; - return 0x0; -} - -LAYER *EDITOR::get_selected_layer(int index) -{ - LAYERGROUP *group = get_selected_group(); - if(!group) - return 0x0; - - if(selected_layer >= 0 && selected_layer < editor.map.groups[selected_group]->layers.len()) - return group->layers[selected_layer]; - return 0x0; -} - -LAYER *EDITOR::get_selected_layer_type(int index, int type) -{ - LAYER *p = get_selected_layer(index); - if(p && p->type == type) - return p; - return 0x0; -} - -QUAD *EDITOR::get_selected_quad() -{ - LAYER_QUADS *ql = (LAYER_QUADS *)get_selected_layer_type(0, LAYERTYPE_QUADS); - if(!ql) - return 0; - if(selected_quad >= 0 && selected_quad < ql->quads.len()) - return &ql->quads[selected_quad]; - return 0; -} - -static void callback_open_map(const char *filename) { editor.load(filename); } -static void callback_append_map(const char *filename) { editor.append(filename); } -static void callback_save_map(const char *filename) { editor.save(filename); } - -static void do_toolbar(RECT toolbar) -{ - RECT button; - - // ctrl+o to open - if(inp_key_down('o') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL))) - editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Open Map", "Open", "maps/", "", callback_open_map); - - // ctrl+s to save - if(inp_key_down('s') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL))) - editor.invoke_file_dialog(LISTDIRTYPE_SAVE, "Save Map", "Save", "maps/", "", callback_save_map); - - // detail button - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int hq_button = 0; - if(do_editor_button(&hq_button, "Detail", editor.show_detail, &button, draw_editor_button, 0, "[ctrl+h] Toggle High Detail") || - (inp_key_down('h') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL)))) - { - editor.show_detail = !editor.show_detail; - } - - ui_vsplit_l(&toolbar, 5.0f, 0, &toolbar); - - // animation button - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int animate_button = 0; - if(do_editor_button(&animate_button, "Anim", editor.animate, &button, draw_editor_button, 0, "[ctrl+m] Toggle animation") || - (inp_key_down('m') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL)))) - { - editor.animate_start = time_get(); - editor.animate = !editor.animate; - } - - ui_vsplit_l(&toolbar, 5.0f, 0, &toolbar); - - // proof button - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int proof_button = 0; - if(do_editor_button(&proof_button, "Proof", editor.proof_borders, &button, draw_editor_button, 0, "[ctrl-p] Toggles proof borders. These borders represent what a player maximum can see.") || - (inp_key_down('p') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL)))) - { - editor.proof_borders = !editor.proof_borders; - } - - ui_vsplit_l(&toolbar, 15.0f, 0, &toolbar); - - // zoom group - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int zoom_out_button = 0; - if(do_editor_button(&zoom_out_button, "ZO", 0, &button, draw_editor_button_l, 0, "[NumPad-] Zoom out") || inp_key_down(KEY_KP_MINUS)) - editor.zoom_level += 50; - - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int zoom_normal_button = 0; - if(do_editor_button(&zoom_normal_button, "1:1", 0, &button, draw_editor_button_m, 0, "[NumPad*] Zoom to normal and remove editor offset") || inp_key_down(KEY_KP_MULTIPLY)) - { - editor.editor_offset_x = 0; - editor.editor_offset_y = 0; - editor.zoom_level = 100; - } - - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int zoom_in_button = 0; - if(do_editor_button(&zoom_in_button, "ZI", 0, &button, draw_editor_button_r, 0, "[NumPad+] Zoom in") || inp_key_down(KEY_KP_PLUS)) - editor.zoom_level -= 50; - - ui_vsplit_l(&toolbar, 15.0f, 0, &toolbar); - - // animation speed - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int anim_faster_button = 0; - if(do_editor_button(&anim_faster_button, "A+", 0, &button, draw_editor_button_l, 0, "Increase animation speed")) - editor.animate_speed += 0.5f; - - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int anim_normal_button = 0; - if(do_editor_button(&anim_normal_button, "1", 0, &button, draw_editor_button_m, 0, "Normal animation speed")) - editor.animate_speed = 1.0f; - - ui_vsplit_l(&toolbar, 16.0f, &button, &toolbar); - static int anim_slower_button = 0; - if(do_editor_button(&anim_slower_button, "A-", 0, &button, draw_editor_button_r, 0, "Decrease animation speed")) - { - if(editor.animate_speed > 0.5f) - editor.animate_speed -= 0.5f; - } - - if(inp_key_presses(KEY_MOUSE_WHEEL_UP) && editor.dialog == DIALOG_NONE) - editor.zoom_level -= 20; - - if(inp_key_presses(KEY_MOUSE_WHEEL_DOWN) && editor.dialog == DIALOG_NONE) - editor.zoom_level += 20; - - if(editor.zoom_level < 50) - editor.zoom_level = 50; - editor.world_zoom = editor.zoom_level/100.0f; - - ui_vsplit_l(&toolbar, 10.0f, &button, &toolbar); - - - // brush manipulation - { - int enabled = brush.is_empty()?-1:0; - - // flip buttons - ui_vsplit_l(&toolbar, 20.0f, &button, &toolbar); - static int flipx_button = 0; - if(do_editor_button(&flipx_button, "^X", enabled, &button, draw_editor_button_l, 0, "[N] Flip brush horizontal") || inp_key_down('n')) - { - for(int i = 0; i < brush.layers.len(); i++) - brush.layers[i]->brush_flip_x(); - } - - ui_vsplit_l(&toolbar, 20.0f, &button, &toolbar); - static int flipy_button = 0; - if(do_editor_button(&flipy_button, "^Y", enabled, &button, draw_editor_button_r, 0, "[M] Flip brush vertical") || inp_key_down('m')) - { - for(int i = 0; i < brush.layers.len(); i++) - brush.layers[i]->brush_flip_y(); - } - - // rotate buttons - ui_vsplit_l(&toolbar, 20.0f, &button, &toolbar); - - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int rotation_amount = 90; - rotation_amount = ui_do_value_selector(&rotation_amount, &button, "", rotation_amount, 1, 360, 2.0f); - - ui_vsplit_l(&toolbar, 5.0f, &button, &toolbar); - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int ccw_button = 0; - if(do_editor_button(&ccw_button, "CCW", enabled, &button, draw_editor_button_l, 0, "[R] Rotates the brush counter clockwise") || inp_key_down('r')) - { - for(int i = 0; i < brush.layers.len(); i++) - brush.layers[i]->brush_rotate(-rotation_amount/360.0f*pi*2); - } - - ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); - static int cw_button = 0; - if(do_editor_button(&cw_button, "CW", enabled, &button, draw_editor_button_r, 0, "[T] Rotates the brush clockwise") || inp_key_down('t')) - { - for(int i = 0; i < brush.layers.len(); i++) - brush.layers[i]->brush_rotate(rotation_amount/360.0f*pi*2); - } - } - - // quad manipulation - { - // do add button - ui_vsplit_l(&toolbar, 10.0f, &button, &toolbar); - ui_vsplit_l(&toolbar, 60.0f, &button, &toolbar); - static int new_button = 0; - - LAYER_QUADS *qlayer = (LAYER_QUADS *)editor.get_selected_layer_type(0, LAYERTYPE_QUADS); - //LAYER_TILES *tlayer = (LAYER_TILES *)editor.get_selected_layer_type(0, LAYERTYPE_TILES); - if(do_editor_button(&new_button, "Add Quad", qlayer?0:-1, &button, draw_editor_button, 0, "Adds a new quad")) - { - if(qlayer) - { - float mapping[4]; - LAYERGROUP *g = editor.get_selected_group(); - g->mapping(mapping); - int add_x = f2fx(mapping[0] + (mapping[2]-mapping[0])/2); - int add_y = f2fx(mapping[1] + (mapping[3]-mapping[1])/2); - - QUAD *q = qlayer->new_quad(); - for(int i = 0; i < 5; i++) - { - q->points[i].x += add_x; - q->points[i].y += add_y; - } - } - } - } -} - -static void rotate(POINT *center, POINT *point, float rotation) -{ - int x = point->x - center->x; - int y = point->y - center->y; - point->x = (int)(x * cosf(rotation) - y * sinf(rotation) + center->x); - point->y = (int)(x * sinf(rotation) + y * cosf(rotation) + center->y); -} - -static void do_quad(QUAD *q, int index) -{ - enum - { - OP_NONE=0, - OP_MOVE_ALL, - OP_MOVE_PIVOT, - OP_ROTATE, - OP_CONTEXT_MENU, - }; - - // some basic values - void *id = &q->points[4]; // use pivot addr as id - static POINT rotate_points[4]; - static float last_wx; - static float last_wy; - static int operation = OP_NONE; - static float rotate_angle = 0; - float wx = ui_mouse_world_x(); - float wy = ui_mouse_world_y(); - - // get pivot - float center_x = fx2f(q->points[4].x); - float center_y = fx2f(q->points[4].y); - - float dx = (center_x - wx); - float dy = (center_y - wy); - if(dx*dx+dy*dy < 10*10) - ui_set_hot_item(id); - - // draw selection background - if(editor.selected_quad == index) - { - gfx_setcolor(0,0,0,1); - gfx_quads_draw(center_x, center_y, 7.0f, 7.0f); - } - - if(ui_active_item() == id) - { - // check if we only should move pivot - if(operation == OP_MOVE_PIVOT) - { - q->points[4].x += f2fx(wx-last_wx); - q->points[4].y += f2fx(wy-last_wy); - } - else if(operation == OP_MOVE_ALL) - { - // move all points including pivot - for(int v = 0; v < 5; v++) - { - q->points[v].x += f2fx(wx-last_wx); - q->points[v].y += f2fx(wy-last_wy); - } - } - else if(operation == OP_ROTATE) - { - for(int v = 0; v < 4; v++) - { - q->points[v] = rotate_points[v]; - rotate(&q->points[4], &q->points[v], rotate_angle); - } - } - - rotate_angle += (editor.mouse_delta_x) * 0.002f; - last_wx = wx; - last_wy = wy; - - if(operation == OP_CONTEXT_MENU) - { - if(!ui_mouse_button(1)) - { - static int quad_popup_id = 0; - ui_invoke_popup_menu(&quad_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 150, popup_quad); - editor.lock_mouse = false; - operation = OP_NONE; - ui_set_active_item(0); - } - } - else - { - if(!ui_mouse_button(0)) - { - editor.lock_mouse = false; - operation = OP_NONE; - ui_set_active_item(0); - } - } - - gfx_setcolor(1,1,1,1); - } - else if(ui_hot_item() == id) - { - ui_got_context = id; - - gfx_setcolor(1,1,1,1); - editor.tooltip = "Left mouse button to move. Hold shift to move pivot. Hold ctrl to rotate"; - - if(ui_mouse_button(0)) - { - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - operation = OP_MOVE_PIVOT; - else if(inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL)) - { - editor.lock_mouse = true; - operation = OP_ROTATE; - rotate_angle = 0; - rotate_points[0] = q->points[0]; - rotate_points[1] = q->points[1]; - rotate_points[2] = q->points[2]; - rotate_points[3] = q->points[3]; - } - else - operation = OP_MOVE_ALL; - - ui_set_active_item(id); - editor.selected_quad = index; - last_wx = wx; - last_wy = wy; - } - - if(ui_mouse_button(1)) - { - editor.selected_quad = index; - operation = OP_CONTEXT_MENU; - ui_set_active_item(id); - } - } - else - gfx_setcolor(0,1,0,1); - - gfx_quads_draw(center_x, center_y, 5.0f, 5.0f); -} - -static void do_quad_point(QUAD *q, int quad_index, int v) -{ - void *id = &q->points[v]; - - float wx = ui_mouse_world_x(); - float wy = ui_mouse_world_y(); - - float px = fx2f(q->points[v].x); - float py = fx2f(q->points[v].y); - - float dx = (px - wx); - float dy = (py - wy); - if(dx*dx+dy*dy < 10*10) - ui_set_hot_item(id); - - // draw selection background - if(editor.selected_quad == quad_index && editor.selected_points&(1< 0.5f) - moved = true; - } - - if(moved) - { - if(operation == OP_MOVEPOINT) - { - for(int m = 0; m < 4; m++) - if(editor.selected_points&(1<points[m].x += f2fx(dx); - q->points[m].y += f2fx(dy); - } - } - else if(operation == OP_MOVEUV) - { - for(int m = 0; m < 4; m++) - if(editor.selected_points&(1<texcoords[m].x += f2fx(dx*0.001f); - q->texcoords[m].y += f2fx(dy*0.001f); - } - } - } - - if(operation == OP_CONTEXT_MENU) - { - if(!ui_mouse_button(1)) - { - static int point_popup_id = 0; - ui_invoke_popup_menu(&point_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 150, popup_point); - ui_set_active_item(0); - } - } - else - { - if(!ui_mouse_button(0)) - { - if(!moved) - { - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - editor.selected_points ^= 1<visible) - editor.map.groups[g]->render(); - //ui_clip_enable(&view); - } - - // render the game above everything else - if(editor.map.game_group->visible && editor.map.game_layer->visible) - { - editor.map.game_group->mapscreen(); - editor.map.game_layer->render(); - } - } - - static void *editor_id = (void *)&editor_id; - int inside = ui_mouse_inside(&view); - - // fetch mouse position - float wx = ui_mouse_world_x(); - float wy = ui_mouse_world_y(); - float mx = ui_mouse_x(); - float my = ui_mouse_y(); - - static float start_wx = 0; - static float start_wy = 0; - static float start_mx = 0; - static float start_my = 0; - - enum - { - OP_NONE=0, - OP_BRUSH_GRAB, - OP_BRUSH_DRAW, - OP_PAN_WORLD, - OP_PAN_EDITOR, - }; - - // remap the screen so it can display the whole tileset - if(show_picker) - { - RECT screen = *ui_screen(); - float size = 32.0*16.0f; - float w = size*(screen.w/view.w); - float h = size*(screen.h/view.h); - float x = -(view.x/screen.w)*w; - float y = -(view.y/screen.h)*h; - wx = x+w*mx/screen.w; - wy = y+h*my/screen.h; - gfx_mapscreen(x, y, x+w, y+h); - LAYER_TILES *t = (LAYER_TILES *)editor.get_selected_layer_type(0, LAYERTYPE_TILES); - if(t) - { - tileset_picker.image = t->image; - tileset_picker.tex_id = t->tex_id; - tileset_picker.render(); - } - } - - static int operation = OP_NONE; - - // draw layer borders - LAYER *edit_layers[16]; - int num_edit_layers = 0; - num_edit_layers = 0; - - if(show_picker) - { - edit_layers[0] = &tileset_picker; - num_edit_layers++; - } - else - { - edit_layers[0] = editor.get_selected_layer(0); - if(edit_layers[0]) - num_edit_layers++; - - LAYERGROUP *g = editor.get_selected_group(); - if(g) - { - g->mapscreen(); - - for(int i = 0; i < num_edit_layers; i++) - { - if(edit_layers[i]->type != LAYERTYPE_TILES) - continue; - - float w, h; - edit_layers[i]->get_size(&w, &h); - - gfx_texture_set(-1); - gfx_lines_begin(); - gfx_lines_draw(0,0, w,0); - gfx_lines_draw(w,0, w,h); - gfx_lines_draw(w,h, 0,h); - gfx_lines_draw(0,h, 0,0); - gfx_lines_end(); - } - } - } - - if(inside) - { - ui_set_hot_item(editor_id); - - // do global operations like pan and zoom - if(ui_active_item() == 0 && (ui_mouse_button(0) || ui_mouse_button(2))) - { - start_wx = wx; - start_wy = wy; - start_mx = mx; - start_my = my; - - if(inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL) || ui_mouse_button(2)) - { - if(inp_key_pressed(KEY_LSHIFT)) - operation = OP_PAN_EDITOR; - else - operation = OP_PAN_WORLD; - ui_set_active_item(editor_id); - } - } - - // brush editing - if(ui_hot_item() == editor_id) - { - if(brush.is_empty()) - editor.tooltip = "Use left mouse button to drag and create a brush."; - else - editor.tooltip = "Use left mouse button to paint with the brush. Right button clears the brush."; - - if(ui_active_item() == editor_id) - { - RECT r; - r.x = start_wx; - r.y = start_wy; - r.w = wx-start_wx; - r.h = wy-start_wy; - if(r.w < 0) - { - r.x += r.w; - r.w = -r.w; - } - - if(r.h < 0) - { - r.y += r.h; - r.h = -r.h; - } - - if(operation == OP_BRUSH_DRAW) - { - if(!brush.is_empty()) - { - // draw with brush - for(int k = 0; k < num_edit_layers; k++) - { - if(edit_layers[k]->type == brush.layers[0]->type) - edit_layers[k]->brush_draw(brush.layers[0], wx, wy); - } - } - } - else if(operation == OP_BRUSH_GRAB) - { - if(!ui_mouse_button(0)) - { - // grab brush - dbg_msg("editor", "grabbing %f %f %f %f", r.x, r.y, r.w, r.h); - - // TODO: do all layers - int grabs = 0; - for(int k = 0; k < num_edit_layers; k++) - grabs += edit_layers[k]->brush_grab(&brush, r); - if(grabs == 0) - brush.clear(); - } - else - { - //editor.map.groups[selected_group]->mapscreen(); - for(int k = 0; k < num_edit_layers; k++) - edit_layers[k]->brush_selecting(r); - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - } - } - } - else - { - if(ui_mouse_button(1)) - brush.clear(); - - if(ui_mouse_button(0) && operation == OP_NONE) - { - ui_set_active_item(editor_id); - - if(brush.is_empty()) - operation = OP_BRUSH_GRAB; - else - { - operation = OP_BRUSH_DRAW; - for(int k = 0; k < num_edit_layers; k++) - { - if(edit_layers[k]->type == brush.layers[0]->type) - edit_layers[k]->brush_place(brush.layers[0], wx, wy); - } - - } - } - - if(!brush.is_empty()) - { - brush.offset_x = -(int)wx; - brush.offset_y = -(int)wy; - for(int i = 0; i < brush.layers.len(); i++) - { - if(brush.layers[i]->type == LAYERTYPE_TILES) - { - brush.offset_x = -(int)(wx/32.0f)*32; - brush.offset_y = -(int)(wy/32.0f)*32; - break; - } - } - - LAYERGROUP *g = editor.get_selected_group(); - brush.offset_x += g->offset_x; - brush.offset_y += g->offset_y; - brush.parallax_x = g->parallax_x; - brush.parallax_y = g->parallax_y; - brush.render(); - float w, h; - brush.get_size(&w, &h); - - gfx_texture_set(-1); - gfx_lines_begin(); - gfx_lines_draw(0,0, w,0); - gfx_lines_draw(w,0, w,h); - gfx_lines_draw(w,h, 0,h); - gfx_lines_draw(0,h, 0,0); - gfx_lines_end(); - - } - } - } - - // quad editing - { - if(!show_picker && brush.is_empty()) - { - // fetch layers - LAYERGROUP *g = editor.get_selected_group(); - if(g) - g->mapscreen(); - - for(int k = 0; k < num_edit_layers; k++) - { - if(edit_layers[k]->type == LAYERTYPE_QUADS) - { - LAYER_QUADS *layer = (LAYER_QUADS *)edit_layers[k]; - - gfx_texture_set(-1); - gfx_quads_begin(); - for(int i = 0; i < layer->quads.len(); i++) - { - for(int v = 0; v < 4; v++) - do_quad_point(&layer->quads[i], i, v); - - do_quad(&layer->quads[i], i); - } - gfx_quads_end(); - } - } - - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - } - - // do panning - if(ui_active_item() == editor_id) - { - if(operation == OP_PAN_WORLD) - { - editor.world_offset_x -= editor.mouse_delta_x*editor.world_zoom; - editor.world_offset_y -= editor.mouse_delta_y*editor.world_zoom; - } - else if(operation == OP_PAN_EDITOR) - { - editor.editor_offset_x -= editor.mouse_delta_x*editor.world_zoom; - editor.editor_offset_y -= editor.mouse_delta_y*editor.world_zoom; - } - - // release mouse - if(!ui_mouse_button(0)) - { - operation = OP_NONE; - ui_set_active_item(0); - } - } - } - } - - if(editor.get_selected_group() && editor.get_selected_group()->use_clipping) - { - LAYERGROUP *g = editor.map.game_group; - g->mapscreen(); - - gfx_texture_set(-1); - gfx_lines_begin(); - - RECT r; - r.x = editor.get_selected_group()->clip_x; - r.y = editor.get_selected_group()->clip_y; - r.w = editor.get_selected_group()->clip_w; - r.h = editor.get_selected_group()->clip_h; - - gfx_setcolor(1,0,0,1); - gfx_lines_draw(r.x, r.y, r.x+r.w, r.y); - gfx_lines_draw(r.x+r.w, r.y, r.x+r.w, r.y+r.h); - gfx_lines_draw(r.x+r.w, r.y+r.h, r.x, r.y+r.h); - gfx_lines_draw(r.x, r.y+r.h, r.x, r.y); - - gfx_lines_end(); - } - - // render screen sizes - if(editor.proof_borders) - { - LAYERGROUP *g = editor.map.game_group; - g->mapscreen(); - - gfx_texture_set(-1); - gfx_lines_begin(); - - float last_points[4]; - float start = 1.0f; //9.0f/16.0f; - float end = 16.0f/9.0f; - const int num_steps = 20; - for(int i = 0; i <= num_steps; i++) - { - float points[4]; - float aspect = start + (end-start)*(i/(float)num_steps); - - mapscreen_to_world( - editor.world_offset_x, editor.world_offset_y, - 1.0f, 1.0f, 0.0f, 0.0f, aspect, 1.0f, points); - - if(i == 0) - { - gfx_lines_draw(points[0], points[1], points[2], points[1]); - gfx_lines_draw(points[0], points[3], points[2], points[3]); - } - - if(i != 0) - { - gfx_lines_draw(points[0], points[1], last_points[0], last_points[1]); - gfx_lines_draw(points[2], points[1], last_points[2], last_points[1]); - gfx_lines_draw(points[0], points[3], last_points[0], last_points[3]); - gfx_lines_draw(points[2], points[3], last_points[2], last_points[3]); - } - - if(i == num_steps) - { - gfx_lines_draw(points[0], points[1], points[0], points[3]); - gfx_lines_draw(points[2], points[1], points[2], points[3]); - } - - mem_copy(last_points, points, sizeof(points)); - } - - if(1) - { - gfx_setcolor(1,0,0,1); - for(int i = 0; i < 2; i++) - { - float points[4]; - float aspects[] = {4.0f/3.0f, 16.0f/10.0f, 5.0f/4.0f, 16.0f/9.0f}; - float aspect = aspects[i]; - - mapscreen_to_world( - editor.world_offset_x, editor.world_offset_y, - 1.0f, 1.0f, 0.0f, 0.0f, aspect, 1.0f, points); - - RECT r; - r.x = points[0]; - r.y = points[1]; - r.w = points[2]-points[0]; - r.h = points[3]-points[1]; - - gfx_lines_draw(r.x, r.y, r.x+r.w, r.y); - gfx_lines_draw(r.x+r.w, r.y, r.x+r.w, r.y+r.h); - gfx_lines_draw(r.x+r.w, r.y+r.h, r.x, r.y+r.h); - gfx_lines_draw(r.x, r.y+r.h, r.x, r.y); - gfx_setcolor(0,1,0,1); - } - } - - gfx_lines_end(); - } - - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - //ui_clip_disable(); -} - - -int EDITOR::do_properties(RECT *toolbox, PROPERTY *props, int *ids, int *new_val) -{ - int change = -1; - - for(int i = 0; props[i].name; i++) - { - RECT slot; - ui_hsplit_t(toolbox, 13.0f, &slot, toolbox); - RECT label, shifter; - ui_vsplit_mid(&slot, &label, &shifter); - ui_hmargin(&shifter, 1.0f, &shifter); - ui_do_label(&label, props[i].name, 10.0f, -1, -1); - - if(props[i].type == PROPTYPE_INT_STEP) - { - RECT inc, dec; - char buf[64]; - - ui_vsplit_r(&shifter, 10.0f, &shifter, &inc); - ui_vsplit_l(&shifter, 10.0f, &dec, &shifter); - sprintf(buf, "%d", props[i].value); - ui_draw_rect(&shifter, vec4(1,1,1,0.5f), 0, 0.0f); - ui_do_label(&shifter, buf, 10.0f, 0, -1); - - if(do_editor_button(&ids[i], 0, 0, &dec, draw_dec_button, 0, "Decrease")) - { - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - *new_val = props[i].value-5; - else - *new_val = props[i].value-1; - change = i; - } - if(do_editor_button(((char *)&ids[i])+1, 0, 0, &inc, draw_inc_button, 0, "Increase")) - { - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - *new_val = props[i].value+5; - else - *new_val = props[i].value+1; - change = i; - } - } - else if(props[i].type == PROPTYPE_BOOL) - { - RECT no, yes; - ui_vsplit_mid(&shifter, &no, &yes); - if(do_editor_button(&ids[i], "No", !props[i].value, &no, draw_dec_button, 0, "")) - { - *new_val = 0; - change = i; - } - if(do_editor_button(((char *)&ids[i])+1, "Yes", props[i].value, &yes, draw_inc_button, 0, "")) - { - *new_val = 1; - change = i; - } - } - else if(props[i].type == PROPTYPE_INT_SCROLL) - { - int new_value = ui_do_value_selector(&ids[i], &shifter, "", props[i].value, props[i].min, props[i].max, 1.0f); - if(new_value != props[i].value) - { - *new_val = new_value; - change = i; - } - } - else if(props[i].type == PROPTYPE_COLOR) - { - static const char *texts[4] = {"R", "G", "B", "A"}; - static int shift[] = {24, 16, 8, 0}; - int new_color = 0; - - for(int c = 0; c < 4; c++) - { - int v = (props[i].value >> shift[c])&0xff; - new_color |= ui_do_value_selector(((char *)&ids[i])+c, &shifter, texts[c], v, 0, 255, 1.0f)<name); - - if(do_editor_button(&ids[i], buf, 0, &shifter, draw_editor_button, 0, 0)) - popup_select_image_invoke(props[i].value, ui_mouse_x(), ui_mouse_y()); - - int r = popup_select_image_result(); - if(r >= -1) - { - *new_val = r; - change = i; - } - } - } - - return change; -} - -static void render_layers(RECT toolbox, RECT toolbar, RECT view) -{ - RECT layersbox = toolbox; - - if(!editor.gui_active) - return; - - RECT slot, button; - char buf[64]; - - int valid_group = 0; - int valid_layer = 0; - if(editor.selected_group >= 0 && editor.selected_group < editor.map.groups.len()) - valid_group = 1; - - if(valid_group && editor.selected_layer >= 0 && editor.selected_layer < editor.map.groups[editor.selected_group]->layers.len()) - valid_layer = 1; - - // render layers - { - for(int g = 0; g < editor.map.groups.len(); g++) - { - RECT visible_toggle; - ui_hsplit_t(&layersbox, 12.0f, &slot, &layersbox); - ui_vsplit_l(&slot, 12, &visible_toggle, &slot); - if(do_editor_button(&editor.map.groups[g]->visible, editor.map.groups[g]->visible?"V":"H", 0, &visible_toggle, draw_editor_button_l, 0, "Toggle group visibility")) - editor.map.groups[g]->visible = !editor.map.groups[g]->visible; - - sprintf(buf, "#%d %s", g, editor.map.groups[g]->name); - if(int result = do_editor_button(&editor.map.groups[g], buf, g==editor.selected_group, &slot, draw_editor_button_r, - BUTTON_CONTEXT, "Select group. Right click for properties.")) - { - editor.selected_group = g; - editor.selected_layer = 0; - - static int group_popup_id = 0; - if(result == 2) - ui_invoke_popup_menu(&group_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 200, popup_group); - } - - - ui_hsplit_t(&layersbox, 2.0f, &slot, &layersbox); - - for(int i = 0; i < editor.map.groups[g]->layers.len(); i++) - { - //visible - ui_hsplit_t(&layersbox, 12.0f, &slot, &layersbox); - ui_vsplit_l(&slot, 12.0f, 0, &button); - ui_vsplit_l(&button, 15, &visible_toggle, &button); - - if(do_editor_button(&editor.map.groups[g]->layers[i]->visible, editor.map.groups[g]->layers[i]->visible?"V":"H", 0, &visible_toggle, draw_editor_button_l, 0, "Toggle layer visibility")) - editor.map.groups[g]->layers[i]->visible = !editor.map.groups[g]->layers[i]->visible; - - sprintf(buf, "#%d %s ", i, editor.map.groups[g]->layers[i]->type_name); - if(int result = do_editor_button(editor.map.groups[g]->layers[i], buf, g==editor.selected_group&&i==editor.selected_layer, &button, draw_editor_button_r, - BUTTON_CONTEXT, "Select layer. Right click for properties.")) - { - editor.selected_layer = i; - editor.selected_group = g; - static int layer_popup_id = 0; - if(result == 2) - ui_invoke_popup_menu(&layer_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 150, popup_layer); - } - - - ui_hsplit_t(&layersbox, 2.0f, &slot, &layersbox); - } - ui_hsplit_t(&layersbox, 5.0f, &slot, &layersbox); - } - } - - - { - ui_hsplit_t(&layersbox, 12.0f, &slot, &layersbox); - - static int new_group_button = 0; - if(do_editor_button(&new_group_button, "Add Group", 0, &slot, draw_editor_button, 0, "Adds a new group")) - { - editor.map.new_group(); - editor.selected_group = editor.map.groups.len()-1; - } - } - - ui_hsplit_t(&layersbox, 5.0f, &slot, &layersbox); - -} - -static void extract_name(const char *filename, char *name) -{ - int len = strlen(filename); - int start = len; - int end = len; - - while(start > 0) - { - start--; - if(filename[start] == '/' || filename[start] == '\\') - { - start++; - break; - } - } - - end = start; - for(int i = start; i < len; i++) - { - if(filename[i] == '.') - end = i; - } - - if(end == start) - end = len; - - int final_len = end-start; - mem_copy(name, &filename[start], final_len); - name[final_len] = 0; - dbg_msg("", "%s %s %d %d", filename, name, start, end); -} - -static void replace_image(const char *filename) -{ - EDITOR_IMAGE imginfo; - if(!gfx_load_png(&imginfo, filename)) - return; - - EDITOR_IMAGE *img = editor.map.images[editor.selected_image]; - gfx_unload_texture(img->tex_id); - *img = imginfo; - extract_name(filename, img->name); - img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0); -} - -static void add_image(const char *filename) -{ - EDITOR_IMAGE imginfo; - if(!gfx_load_png(&imginfo, filename)) - return; - - EDITOR_IMAGE *img = new EDITOR_IMAGE; - *img = imginfo; - img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0); - img->external = 1; // external by default - extract_name(filename, img->name); - editor.map.images.add(img); -} - - -static int modify_index_deleted_index; -static void modify_index_deleted(int *index) -{ - if(*index == modify_index_deleted_index) - *index = -1; - else if(*index > modify_index_deleted_index) - *index = *index - 1; -} - -static int popup_image(RECT view) -{ - static int replace_button = 0; - static int remove_button = 0; - - RECT slot; - ui_hsplit_t(&view, 2.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - EDITOR_IMAGE *img = editor.map.images[editor.selected_image]; - - static int external_button = 0; - if(img->external) - { - if(do_editor_button(&external_button, "Embedd", 0, &slot, draw_editor_button_menuitem, 0, "Embedds the image into the map file.")) - { - img->external = 0; - return 1; - } - } - else - { - if(do_editor_button(&external_button, "Make external", 0, &slot, draw_editor_button_menuitem, 0, "Removes the image from the map file.")) - { - img->external = 1; - return 1; - } - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&replace_button, "Replace", 0, &slot, draw_editor_button_menuitem, 0, "Replaces the image with a new one")) - { - editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Replace Image", "Replace", "mapres/", "", replace_image); - return 1; - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&remove_button, "Remove", 0, &slot, draw_editor_button_menuitem, 0, "Removes the image from the map")) - { - delete img; - editor.map.images.removebyindex(editor.selected_image); - modify_index_deleted_index = editor.selected_image; - editor.map.modify_image_index(modify_index_deleted); - return 1; - } - - return 0; -} - - -static void render_images(RECT toolbox, RECT toolbar, RECT view) -{ - for(int e = 0; e < 2; e++) // two passes, first embedded, then external - { - RECT slot; - ui_hsplit_t(&toolbox, 15.0f, &slot, &toolbox); - if(e == 0) - ui_do_label(&slot, "Embedded", 12.0f, 0); - else - ui_do_label(&slot, "External", 12.0f, 0); - - for(int i = 0; i < editor.map.images.len(); i++) - { - if((e && !editor.map.images[i]->external) || - (!e && editor.map.images[i]->external)) - { - continue; - } - - char buf[128]; - sprintf(buf, "%s", editor.map.images[i]->name); - ui_hsplit_t(&toolbox, 12.0f, &slot, &toolbox); - - if(int result = do_editor_button(&editor.map.images[i], buf, editor.selected_image == i, &slot, draw_editor_button, - BUTTON_CONTEXT, "Select image")) - { - editor.selected_image = i; - - static int popup_image_id = 0; - if(result == 2) - ui_invoke_popup_menu(&popup_image_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 80, popup_image); - } - - ui_hsplit_t(&toolbox, 2.0f, 0, &toolbox); - - // render image - if(editor.selected_image == i) - { - RECT r; - ui_margin(&view, 10.0f, &r); - if(r.h < r.w) - r.w = r.h; - else - r.h = r.w; - gfx_texture_set(editor.map.images[i]->tex_id); - gfx_blend_normal(); - gfx_quads_begin(); - gfx_quads_drawTL(r.x, r.y, r.w, r.h); - gfx_quads_end(); - - } - } - } - - RECT slot; - ui_hsplit_t(&toolbox, 5.0f, &slot, &toolbox); - - // new image - static int new_image_button = 0; - ui_hsplit_t(&toolbox, 10.0f, &slot, &toolbox); - ui_hsplit_t(&toolbox, 12.0f, &slot, &toolbox); - if(do_editor_button(&new_image_button, "Add", 0, &slot, draw_editor_button, 0, "Load a new image to use in the map")) - editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Add Image", "Add", "mapres/", "", add_image); -} - - -static int file_dialog_dirtypes = 0; -static const char *file_dialog_title = 0; -static const char *file_dialog_button_text = 0; -static void (*file_dialog_func)(const char *filename); -static char file_dialog_filename[512] = {0}; -static char file_dialog_path[512] = {0}; -static char file_dialog_complete_filename[512] = {0}; -static int files_num = 0; -int files_startat = 0; -int files_cur = 0; -int files_stopat = 999; - -static void editor_listdir_callback(const char *name, int is_dir, void *user) -{ - if(name[0] == '.' || is_dir) // skip this shit! - return; - - if(files_cur > files_num) - files_num = files_cur; - - files_cur++; - if(files_cur-1 < files_startat || files_cur > files_stopat) - return; - - RECT *view = (RECT *)user; - RECT button; - ui_hsplit_t(view, 15.0f, &button, view); - ui_hsplit_t(view, 2.0f, 0, view); - //char buf[512]; - - if(do_editor_button((void*)(10+(int)button.y), name, 0, &button, draw_editor_button_file, 0, 0)) - { - strncpy(file_dialog_filename, name, sizeof(file_dialog_filename)); - - file_dialog_complete_filename[0] = 0; - strcat(file_dialog_complete_filename, file_dialog_path); - strcat(file_dialog_complete_filename, file_dialog_filename); - - if(inp_mouse_doubleclick()) - { - if(file_dialog_func) - file_dialog_func(file_dialog_complete_filename); - editor.dialog = DIALOG_NONE; - } - } -} - -static void render_file_dialog() -{ - // GUI coordsys - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - - RECT view = *ui_screen(); - ui_draw_rect(&view, vec4(0,0,0,0.25f), 0, 0); - ui_vmargin(&view, 150.0f, &view); - ui_hmargin(&view, 50.0f, &view); - ui_draw_rect(&view, vec4(0,0,0,0.75f), CORNER_ALL, 5.0f); - ui_margin(&view, 10.0f, &view); - - RECT title, filebox, filebox_label, buttonbar, scroll; - ui_hsplit_t(&view, 18.0f, &title, &view); - ui_hsplit_t(&view, 5.0f, 0, &view); // some spacing - ui_hsplit_b(&view, 14.0f, &view, &buttonbar); - ui_hsplit_b(&view, 10.0f, &view, 0); // some spacing - ui_hsplit_b(&view, 14.0f, &view, &filebox); - ui_vsplit_l(&filebox, 50.0f, &filebox_label, &filebox); - ui_vsplit_r(&view, 15.0f, &view, &scroll); - - // title - ui_draw_rect(&title, vec4(1,1,1,0.25f), CORNER_ALL, 5.0f); - ui_vmargin(&title, 10.0f, &title); - ui_do_label(&title, file_dialog_title, 14.0f, -1, -1); - - // filebox - ui_do_label(&filebox_label, "Filename:", 10.0f, -1, -1); - - static int filebox_id = 0; - ui_do_edit_box(&filebox_id, &filebox, file_dialog_filename, sizeof(file_dialog_filename), 10.0f); - - file_dialog_complete_filename[0] = 0; - strcat(file_dialog_complete_filename, file_dialog_path); - strcat(file_dialog_complete_filename, file_dialog_filename); - - int num = (int)(view.h/17.0); - static float scrollvalue = 0; - static int scrollbar = 0; - ui_hmargin(&scroll, 5.0f, &scroll); - scrollvalue = ui_do_scrollbar_v(&scrollbar, &scroll, scrollvalue); - - int scrollnum = files_num-num+10; - if(scrollnum > 0) - { - if(inp_key_presses(KEY_MOUSE_WHEEL_UP)) - scrollvalue -= 3.0f/scrollnum; - if(inp_key_presses(KEY_MOUSE_WHEEL_DOWN)) - scrollvalue += 3.0f/scrollnum; - - if(scrollvalue < 0) scrollvalue = 0; - if(scrollvalue > 1) scrollvalue = 1; - } - else - scrollnum = 0; - - files_startat = (int)(scrollnum*scrollvalue); - if(files_startat < 0) - files_startat = 0; - - files_stopat = files_startat+num; - - files_cur = 0; - - // set clipping - ui_clip_enable(&view); - - // the list - engine_listdir(file_dialog_dirtypes, file_dialog_path, editor_listdir_callback, &view); - - // disable clipping again - ui_clip_disable(); - - // the buttons - static int ok_button = 0; - static int cancel_button = 0; - - RECT button; - ui_vsplit_r(&buttonbar, 50.0f, &buttonbar, &button); - if(do_editor_button(&ok_button, file_dialog_button_text, 0, &button, draw_editor_button, 0, 0) || inp_key_pressed(KEY_RETURN)) - { - if(file_dialog_func) - file_dialog_func(file_dialog_complete_filename); - editor.dialog = DIALOG_NONE; - } - - ui_vsplit_r(&buttonbar, 40.0f, &buttonbar, &button); - ui_vsplit_r(&buttonbar, 50.0f, &buttonbar, &button); - if(do_editor_button(&cancel_button, "Cancel", 0, &button, draw_editor_button, 0, 0) || inp_key_pressed(KEY_ESCAPE)) - editor.dialog = DIALOG_NONE; -} - -void EDITOR::invoke_file_dialog(int listdirtypes, const char *title, const char *button_text, - const char *basepath, const char *default_name, - void (*func)(const char *filename)) -{ - file_dialog_dirtypes = listdirtypes; - file_dialog_title = title; - file_dialog_button_text = button_text; - file_dialog_func = func; - file_dialog_filename[0] = 0; - file_dialog_path[0] = 0; - - if(default_name) - strncpy(file_dialog_filename, default_name, sizeof(file_dialog_filename)); - if(basepath) - strncpy(file_dialog_path, basepath, sizeof(file_dialog_path)); - - editor.dialog = DIALOG_FILE; -} - - - -static void render_modebar(RECT view) -{ - RECT button; - - // mode buttons - { - ui_vsplit_l(&view, 40.0f, &button, &view); - static int tile_button = 0; - if(do_editor_button(&tile_button, "Layers", editor.mode == MODE_LAYERS, &button, draw_editor_button_m, 0, "Switch to edit layers.")) - editor.mode = MODE_LAYERS; - - ui_vsplit_l(&view, 40.0f, &button, &view); - static int img_button = 0; - if(do_editor_button(&img_button, "Images", editor.mode == MODE_IMAGES, &button, draw_editor_button_r, 0, "Switch to manage images.")) - editor.mode = MODE_IMAGES; - } - - ui_vsplit_l(&view, 5.0f, 0, &view); - - // spacing - //ui_vsplit_l(&view, 10.0f, 0, &view); -} - -static void render_statusbar(RECT view) -{ - RECT button; - ui_vsplit_r(&view, 60.0f, &view, &button); - static int envelope_button = 0; - if(do_editor_button(&envelope_button, "Envelopes", editor.show_envelope_editor, &button, draw_editor_button, 0, "Toggles the envelope editor.")) - editor.show_envelope_editor = (editor.show_envelope_editor+1)%4; - - if(editor.tooltip) - { - if(ui_got_context && ui_got_context == ui_hot_item()) - { - char buf[512]; - sprintf(buf, "%s Right click for context menu.", editor.tooltip); - ui_do_label(&view, buf, 10.0f, -1, -1); - } - else - ui_do_label(&view, editor.tooltip, 10.0f, -1, -1); - } -} - -static void render_envelopeeditor(RECT view) -{ - if(editor.selected_envelope < 0) editor.selected_envelope = 0; - if(editor.selected_envelope >= editor.map.envelopes.len()) editor.selected_envelope--; - - ENVELOPE *envelope = 0; - if(editor.selected_envelope >= 0 && editor.selected_envelope < editor.map.envelopes.len()) - envelope = editor.map.envelopes[editor.selected_envelope]; - - bool show_colorbar = false; - if(envelope && envelope->channels == 4) - show_colorbar = true; - - RECT toolbar, curvebar, colorbar; - ui_hsplit_t(&view, 15.0f, &toolbar, &view); - ui_hsplit_t(&view, 15.0f, &curvebar, &view); - ui_margin(&toolbar, 2.0f, &toolbar); - ui_margin(&curvebar, 2.0f, &curvebar); - - if(show_colorbar) - { - ui_hsplit_t(&view, 20.0f, &colorbar, &view); - ui_margin(&colorbar, 2.0f, &colorbar); - render_background(colorbar, checker_texture, 16.0f, 1.0f); - } - - render_background(view, checker_texture, 32.0f, 0.1f); - - // do the toolbar - { - RECT button; - ENVELOPE *new_env = 0; - - ui_vsplit_r(&toolbar, 50.0f, &toolbar, &button); - static int new_4d_button = 0; - if(do_editor_button(&new_4d_button, "Color+", 0, &button, draw_editor_button, 0, "Creates a new color envelope")) - new_env = editor.map.new_envelope(4); - - ui_vsplit_r(&toolbar, 5.0f, &toolbar, &button); - ui_vsplit_r(&toolbar, 50.0f, &toolbar, &button); - static int new_2d_button = 0; - if(do_editor_button(&new_2d_button, "Pos.+", 0, &button, draw_editor_button, 0, "Creates a new pos envelope")) - new_env = editor.map.new_envelope(3); - - if(new_env) // add the default points - { - if(new_env->channels == 4) - { - new_env->add_point(0, 1,1,1,1); - new_env->add_point(1000, 1,1,1,1); - } - else - { - new_env->add_point(0, 0); - new_env->add_point(1000, 0); - } - } - - RECT shifter, inc, dec; - ui_vsplit_l(&toolbar, 60.0f, &shifter, &toolbar); - ui_vsplit_r(&shifter, 15.0f, &shifter, &inc); - ui_vsplit_l(&shifter, 15.0f, &dec, &shifter); - char buf[512]; - sprintf(buf, "%d/%d", editor.selected_envelope+1, editor.map.envelopes.len()); - ui_draw_rect(&shifter, vec4(1,1,1,0.5f), 0, 0.0f); - ui_do_label(&shifter, buf, 10.0f, 0, -1); - - static int prev_button = 0; - if(do_editor_button(&prev_button, 0, 0, &dec, draw_dec_button, 0, "Previous Envelope")) - editor.selected_envelope--; - - static int next_button = 0; - if(do_editor_button(&next_button, 0, 0, &inc, draw_inc_button, 0, "Next Envelope")) - editor.selected_envelope++; - - if(envelope) - { - ui_vsplit_l(&toolbar, 15.0f, &button, &toolbar); - ui_vsplit_l(&toolbar, 35.0f, &button, &toolbar); - ui_do_label(&button, "Name:", 10.0f, -1, -1); - - ui_vsplit_l(&toolbar, 80.0f, &button, &toolbar); - - static int name_box = 0; - ui_do_edit_box(&name_box, &button, envelope->name, sizeof(envelope->name), 10.0f); - } - } - - if(envelope) - { - static array selection; - static int envelope_editor_id = 0; - static int active_channels = 0xf; - - if(envelope) - { - RECT button; - - ui_vsplit_l(&toolbar, 15.0f, &button, &toolbar); - - static const char *names[4][4] = { - {"X", "", "", ""}, - {"X", "Y", "", ""}, - {"X", "Y", "R", ""}, - {"R", "G", "B", "A"}, - }; - - static int channel_buttons[4] = {0}; - int bit = 1; - ui_draw_button_func draw_func; - - for(int i = 0; i < envelope->channels; i++, bit<<=1) - { - ui_vsplit_l(&toolbar, 15.0f, &button, &toolbar); - - if(i == 0) draw_func = draw_editor_button_l; - else if(i == envelope->channels-1) draw_func = draw_editor_button_r; - else draw_func = draw_editor_button_m; - - if(do_editor_button(&channel_buttons[i], names[envelope->channels-1][i], active_channels&bit, &button, draw_func, 0, 0)) - active_channels ^= bit; - } - } - - float end_time = envelope->end_time(); - if(end_time < 1) - end_time = 1; - - envelope->find_top_bottom(active_channels); - float top = envelope->top; - float bottom = envelope->bottom; - - if(top < 1) - top = 1; - if(bottom >= 0) - bottom = 0; - - float timescale = end_time/view.w; - float valuescale = (top-bottom)/view.h; - - if(ui_mouse_inside(&view)) - ui_set_hot_item(&envelope_editor_id); - - if(ui_hot_item() == &envelope_editor_id) - { - // do stuff - if(envelope) - { - if(ui_mouse_button_clicked(1)) - { - // add point - int time = (int)(((ui_mouse_x()-view.x)*timescale)*1000.0f); - //float env_y = (ui_mouse_y()-view.y)/timescale; - float channels[4]; - envelope->eval(time, channels); - envelope->add_point(time, - f2fx(channels[0]), f2fx(channels[1]), - f2fx(channels[2]), f2fx(channels[3])); - } - - editor.tooltip = "Press right mouse button to create a new point"; - } - } - - vec3 colors[] = {vec3(1,0.2f,0.2f), vec3(0.2f,1,0.2f), vec3(0.2f,0.2f,1), vec3(1,1,0.2f)}; - - // render lines - { - ui_clip_enable(&view); - gfx_texture_set(-1); - gfx_lines_begin(); - for(int c = 0; c < envelope->channels; c++) - { - if(active_channels&(1<eval(0.000001f, results); - float prev_value = results[c]; - - int steps = (int)((view.w/ui_screen()->w) * gfx_screenwidth()); - for(int i = 1; i <= steps; i++) - { - float a = i/(float)steps; - envelope->eval(a*end_time, results); - float v = results[c]; - v = (v-bottom)/(top-bottom); - - gfx_lines_draw(view.x + prev_x*view.w, view.y+view.h - prev_value*view.h, view.x + a*view.w, view.y+view.h - v*view.h); - prev_x = a; - prev_value = v; - } - } - gfx_lines_end(); - ui_clip_disable(); - } - - // render curve options - { - for(int i = 0; i < envelope->points.len()-1; i++) - { - float t0 = envelope->points[i].time/1000.0f/end_time; - float t1 = envelope->points[i+1].time/1000.0f/end_time; - - //dbg_msg("", "%f", end_time); - - RECT v; - v.x = curvebar.x + (t0+(t1-t0)*0.5f) * curvebar.w; - v.y = curvebar.y; - v.h = curvebar.h; - v.w = curvebar.h; - v.x -= v.w/2; - void *id = &envelope->points[i].curvetype; - const char *type_name[] = { - "N", "L", "S", "F", "M" - }; - - if(do_editor_button(id, type_name[envelope->points[i].curvetype], 0, &v, draw_editor_button, 0, "Switch curve type")) - envelope->points[i].curvetype = (envelope->points[i].curvetype+1)%NUM_CURVETYPES; - } - } - - // render colorbar - if(show_colorbar) - { - gfx_texture_set(-1); - gfx_quads_begin(); - for(int i = 0; i < envelope->points.len()-1; i++) - { - float r0 = fx2f(envelope->points[i].values[0]); - float g0 = fx2f(envelope->points[i].values[1]); - float b0 = fx2f(envelope->points[i].values[2]); - float a0 = fx2f(envelope->points[i].values[3]); - float r1 = fx2f(envelope->points[i+1].values[0]); - float g1 = fx2f(envelope->points[i+1].values[1]); - float b1 = fx2f(envelope->points[i+1].values[2]); - float a1 = fx2f(envelope->points[i+1].values[3]); - - gfx_setcolorvertex(0, r0, g0, b0, a0); - gfx_setcolorvertex(1, r1, g1, b1, a1); - gfx_setcolorvertex(2, r1, g1, b1, a1); - gfx_setcolorvertex(3, r0, g0, b0, a0); - - float x0 = envelope->points[i].time/1000.0f/end_time; -// float y0 = (fx2f(envelope->points[i].values[c])-bottom)/(top-bottom); - float x1 = envelope->points[i+1].time/1000.0f/end_time; - //float y1 = (fx2f(envelope->points[i+1].values[c])-bottom)/(top-bottom); - RECT v; - v.x = colorbar.x + x0*colorbar.w; - v.y = colorbar.y; - v.w = (x1-x0)*colorbar.w; - v.h = colorbar.h; - - gfx_quads_drawTL(v.x, v.y, v.w, v.h); - } - gfx_quads_end(); - } - - // render handles - { - static bool move = false; - - int current_value = 0, current_time = 0; - - gfx_texture_set(-1); - gfx_quads_begin(); - for(int c = 0; c < envelope->channels; c++) - { - if(!(active_channels&(1<points.len(); i++) - { - float x0 = envelope->points[i].time/1000.0f/end_time; - float y0 = (fx2f(envelope->points[i].values[c])-bottom)/(top-bottom); - RECT final; - final.x = view.x + x0*view.w; - final.y = view.y+view.h - y0*view.h; - final.x -= 2.0f; - final.y -= 2.0f; - final.w = 4.0f; - final.h = 4.0f; - - void *id = &envelope->points[i].values[c]; - - if(ui_mouse_inside(&final)) - ui_set_hot_item(id); - - float colormod = 1.0f; - - if(ui_active_item() == id) - { - if(!ui_mouse_button(0)) - { - ui_set_active_item(0); - move = false; - } - else - { - envelope->points[i].values[c] -= f2fx(editor.mouse_delta_y*valuescale); - if(inp_key_pressed(KEY_LSHIFT) || inp_key_pressed(KEY_RSHIFT)) - { - if(i != 0) - { - envelope->points[i].time += (int)((editor.mouse_delta_x*timescale)*1000.0f); - if(envelope->points[i].time < envelope->points[i-1].time) - envelope->points[i].time = envelope->points[i-1].time + 1; - if(i+1 != envelope->points.len() && envelope->points[i].time > envelope->points[i+1].time) - envelope->points[i].time = envelope->points[i+1].time - 1; - } - } - } - - colormod = 100.0f; - gfx_setcolor(1,1,1,1); - } - else if(ui_hot_item() == id) - { - if(ui_mouse_button(0)) - { - selection.clear(); - selection.add(i); - ui_set_active_item(id); - } - - // remove point - if(ui_mouse_button_clicked(1)) - envelope->points.removebyindex(i); - - colormod = 100.0f; - gfx_setcolor(1,0.75f,0.75f,1); - editor.tooltip = "Left mouse to drag. Hold shift to alter time point aswell. Right click to delete."; - } - - if(ui_active_item() == id || ui_hot_item() == id) - { - current_time = envelope->points[i].time; - current_value = envelope->points[i].values[c]; - } - - gfx_setcolor(colors[c].r*colormod, colors[c].g*colormod, colors[c].b*colormod, 1.0f); - gfx_quads_drawTL(final.x, final.y, final.w, final.h); - } - } - gfx_quads_end(); - - char buf[512]; - sprintf(buf, "%.3f %.3f", current_time/1000.0f, fx2f(current_value)); - ui_do_label(&toolbar, buf, 10.0f, 0, -1); - } - } -} - -static int popup_menu_file(RECT view) -{ - static int new_map_button = 0; - static int save_button = 0; - static int save_as_button = 0; - static int open_button = 0; - static int append_button = 0; - static int exit_button = 0; - - RECT slot; - ui_hsplit_t(&view, 2.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&new_map_button, "New", 0, &slot, draw_editor_button_menuitem, 0, "Creates a new map")) - { - editor.reset(); - return 1; - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&open_button, "Open", 0, &slot, draw_editor_button_menuitem, 0, "Opens a map for editing")) - { - editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Open Map", "Open", "maps/", "", callback_open_map); - return 1; - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&append_button, "Append", 0, &slot, draw_editor_button_menuitem, 0, "Opens a map and adds everything from that map to the current one")) - { - editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Append Map", "Append", "maps/", "", callback_append_map); - return 1; - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&save_button, "Save (NOT IMPL)", 0, &slot, draw_editor_button_menuitem, 0, "Saves the current map")) - { - return 1; - } - - ui_hsplit_t(&view, 2.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&save_as_button, "Save As", 0, &slot, draw_editor_button_menuitem, 0, "Saves the current map under a new name")) - { - editor.invoke_file_dialog(LISTDIRTYPE_SAVE, "Save Map", "Save", "maps/", "", callback_save_map); - return 1; - } - - ui_hsplit_t(&view, 10.0f, &slot, &view); - ui_hsplit_t(&view, 12.0f, &slot, &view); - if(do_editor_button(&exit_button, "Exit", 0, &slot, draw_editor_button_menuitem, 0, "Exits from the editor")) - { - config.cl_editor = 0; - return 1; - } - - return 0; -} - -static void render_menubar(RECT menubar) -{ - static RECT file /*, view, help*/; - - ui_vsplit_l(&menubar, 60.0f, &file, &menubar); - if(do_editor_button(&file, "File", 0, &file, draw_editor_button_menu, 0, 0)) - ui_invoke_popup_menu(&file, 1, file.x, file.y+file.h-1.0f, 120, 150, popup_menu_file); - - /* - ui_vsplit_l(&menubar, 5.0f, 0, &menubar); - ui_vsplit_l(&menubar, 60.0f, &view, &menubar); - if(do_editor_button(&view, "View", 0, &view, draw_editor_button_menu, 0, 0)) - (void)0; - - ui_vsplit_l(&menubar, 5.0f, 0, &menubar); - ui_vsplit_l(&menubar, 60.0f, &help, &menubar); - if(do_editor_button(&help, "Help", 0, &help, draw_editor_button_menu, 0, 0)) - (void)0; - */ -} - -void EDITOR::render() -{ - // basic start - gfx_clear(1.0f,0.0f,1.0f); - RECT view = *ui_screen(); - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - - // reset tip - editor.tooltip = 0; - - // render checker - render_background(view, checker_texture, 32.0f, 1.0f); - - RECT menubar, modebar, toolbar, statusbar, envelope_editor, toolbox; - - if(editor.gui_active) - { - - ui_hsplit_t(&view, 16.0f, &menubar, &view); - ui_vsplit_l(&view, 80.0f, &toolbox, &view); - ui_hsplit_t(&view, 16.0f, &toolbar, &view); - ui_hsplit_b(&view, 16.0f, &view, &statusbar); - - if(editor.show_envelope_editor) - { - float size = 125.0f; - if(editor.show_envelope_editor == 2) - size *= 2.0f; - else if(editor.show_envelope_editor == 3) - size *= 3.0f; - ui_hsplit_b(&view, size, &view, &envelope_editor); - } - } - - // a little hack for now - if(editor.mode == MODE_LAYERS) - do_map_editor(view, toolbar); - - if(editor.gui_active) - { - float brightness = 0.25f; - render_background(menubar, background_texture, 128.0f, brightness*0); - ui_margin(&menubar, 2.0f, &menubar); - - render_background(toolbox, background_texture, 128.0f, brightness); - ui_margin(&toolbox, 2.0f, &toolbox); - - render_background(toolbar, background_texture, 128.0f, brightness); - ui_margin(&toolbar, 2.0f, &toolbar); - ui_vsplit_l(&toolbar, 150.0f, &modebar, &toolbar); - - render_background(statusbar, background_texture, 128.0f, brightness); - ui_margin(&statusbar, 2.0f, &statusbar); - - // do the toolbar - if(editor.mode == MODE_LAYERS) - do_toolbar(toolbar); - - if(editor.show_envelope_editor) - { - render_background(envelope_editor, background_texture, 128.0f, brightness); - ui_margin(&envelope_editor, 2.0f, &envelope_editor); - } - } - - - if(editor.mode == MODE_LAYERS) - render_layers(toolbox, toolbar, view); - else if(editor.mode == MODE_IMAGES) - render_images(toolbox, toolbar, view); - - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - - if(editor.gui_active) - { - render_menubar(menubar); - - render_modebar(modebar); - if(editor.show_envelope_editor) - render_envelopeeditor(envelope_editor); - } - - if(editor.dialog == DIALOG_FILE) - { - static int null_ui_target = 0; - ui_set_hot_item(&null_ui_target); - render_file_dialog(); - } - - - ui_do_popup_menu(); - - if(editor.gui_active) - render_statusbar(statusbar); - - // - if(config.ed_showkeys) - { - gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h); - TEXT_CURSOR cursor; - gfx_text_set_cursor(&cursor, view.x+10, view.y+view.h-24-10, 24.0f, TEXTFLAG_RENDER); - - int nkeys = 0; - for(int i = 0; i < KEY_LAST; i++) - { - if(inp_key_pressed(i)) - { - if(nkeys) - gfx_text_ex(&cursor, " + ", -1); - gfx_text_ex(&cursor, inp_key_name(i), -1); - nkeys++; - } - } - } - - if (editor.show_mouse_pointer) - { - // render butt ugly mouse cursor - float mx = ui_mouse_x(); - float my = ui_mouse_y(); - gfx_texture_set(cursor_texture); - gfx_quads_begin(); - if(ui_got_context == ui_hot_item()) - gfx_setcolor(1,0,0,1); - gfx_quads_drawTL(mx,my, 16.0f, 16.0f); - gfx_quads_end(); - } - -} - -void EDITOR::reset(bool create_default) -{ - editor.map.clean(); - - // create default layers - if(create_default) - editor.map.create_default(entities_texture); - - /* - { - }*/ - - selected_layer = 0; - selected_group = 0; - selected_quad = -1; - selected_points = 0; - selected_envelope = 0; - selected_image = 0; -} - -void MAP::make_game_layer(LAYER *layer) -{ - game_layer = (LAYER_GAME *)layer; - game_layer->tex_id = entities_texture; -} - -void MAP::make_game_group(LAYERGROUP *group) -{ - game_group = group; - game_group->game_group = true; - game_group->name = "Game"; -} - - - -void MAP::clean() -{ - groups.deleteall(); - envelopes.deleteall(); - images.deleteall(); - - game_layer = 0x0; - game_group = 0x0; -} - -void MAP::create_default(int entities_texture) -{ - make_game_group(new_group()); - make_game_layer(new LAYER_GAME(50, 50)); - game_group->add_layer(game_layer); -} - -extern "C" void editor_init() -{ - checker_texture = gfx_load_texture("editor/checker.png", IMG_AUTO, 0); - background_texture = gfx_load_texture("editor/background.png", IMG_AUTO, 0); - cursor_texture = gfx_load_texture("editor/cursor.png", IMG_AUTO, 0); - entities_texture = gfx_load_texture("editor/entities.png", IMG_AUTO, 0); - - tileset_picker.make_palette(); - tileset_picker.readonly = true; - - editor.reset(); -} - -extern "C" void editor_update_and_render() -{ - static int mouse_x = 0; - static int mouse_y = 0; - - if(editor.animate) - editor.animate_time = (time_get()-editor.animate_start)/(float)time_freq(); - else - editor.animate_time = 0; - ui_got_context = 0; - - // handle mouse movement - float mx, my, mwx, mwy; - int rx, ry; - { -#ifdef ANDROID - // No relative mouse here, we've got touchscreen - inp_mouse_absolute(&rx, &ry); - editor.mouse_delta_x = rx - mouse_x; - editor.mouse_delta_y = ry - mouse_y; - mouse_x = rx; - mouse_y = ry; -#else - inp_mouse_relative(&rx, &ry); - editor.mouse_delta_x = rx; - editor.mouse_delta_y = ry; - - if(!editor.lock_mouse) - { - mouse_x += rx; - mouse_y += ry; - } -#endif - - if(mouse_x < 0) mouse_x = 0; - if(mouse_y < 0) mouse_y = 0; - if(mouse_x > ui_screen()->w) mouse_x = (int)ui_screen()->w; - if(mouse_y > ui_screen()->h) mouse_y = (int)ui_screen()->h; - - // update the ui - mx = mouse_x; - my = mouse_y; - mwx = 0; - mwy = 0; - - // fix correct world x and y - LAYERGROUP *g = editor.get_selected_group(); - if(g) - { - float points[4]; - g->mapping(points); - - float world_width = points[2]-points[0]; - float world_height = points[3]-points[1]; - - mwx = points[0] + world_width * (mouse_x/ui_screen()->w); - mwy = points[1] + world_height * (mouse_y/ui_screen()->h); - editor.mouse_delta_wx = editor.mouse_delta_x*(world_width / ui_screen()->w); - editor.mouse_delta_wy = editor.mouse_delta_y*(world_height / ui_screen()->h); - } - - int buttons = 0; - if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1; - if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2; - if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4; - - ui_update(mx,my,mwx,mwy,buttons); - } - - // toggle gui - if(inp_key_down(KEY_TAB)) - editor.gui_active = !editor.gui_active; - - if(inp_key_down(KEY_F5)) - editor.save("maps/debug_test2.map"); - - if(inp_key_down(KEY_F6)) - editor.load("maps/debug_test2.map"); - - if(inp_key_down(KEY_F8)) - editor.load("maps/debug_test.map"); - - if(inp_key_down(KEY_F10)) - editor.show_mouse_pointer = false; - - editor.render(); - - if(inp_key_down(KEY_F10)) - { - gfx_screenshot(); - editor.show_mouse_pointer = true; - } - - inp_clear_events(); -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.hpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.hpp deleted file mode 100644 index 313a381ff..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_editor.hpp +++ /dev/null @@ -1,522 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include -#include - -#include -#include -#include "array.hpp" -#include "../mapitems.hpp" -#include "../client/render.hpp" - -extern "C" { - #include - #include - #include -} - -#include - -typedef void (*INDEX_MODIFY_FUNC)(int *index); - -// EDITOR SPECIFIC -template -void swap(T &a, T &b) -{ - T tmp = a; - a = b; - b = tmp; -} - -enum -{ - MODE_LAYERS=0, - MODE_IMAGES, - - DIALOG_NONE=0, - DIALOG_FILE, -}; - -typedef struct -{ - POINT position; - int type; -} ENTITY; - -class ENVELOPE -{ -public: - int channels; - array points; - char name[32]; - float bottom, top; - - ENVELOPE(int chan) - { - channels = chan; - name[0] = 0; - bottom = 0; - top = 0; - } - - static int sort_comp(const void *v0, const void *v1) - { - const ENVPOINT *p0 = (const ENVPOINT *)v0; - const ENVPOINT *p1 = (const ENVPOINT *)v1; - if(p0->time < p1->time) - return -1; - if(p0->time > p1->time) - return 1; - return 0; - } - - void resort() - { - qsort(points.getptr(), points.len(), sizeof(ENVPOINT), sort_comp); - find_top_bottom(0xf); - } - - void find_top_bottom(int channelmask) - { - top = -1000000000.0f; - bottom = 1000000000.0f; - for(int i = 0; i < points.len(); i++) - { - for(int c = 0; c < channels; c++) - { - if(channelmask&(1< top) top = v; - if(v < bottom) bottom = v; - } - } - } - } - - int eval(float time, float *result) - { - render_eval_envelope(points.getptr(), points.len(), channels, time, result); - return channels; - } - - void add_point(int time, int v0, int v1=0, int v2=0, int v3=0) - { - ENVPOINT p; - p.time = time; - p.values[0] = v0; - p.values[1] = v1; - p.values[2] = v2; - p.values[3] = v3; - p.curvetype = CURVETYPE_LINEAR; - points.add(p); - resort(); - } - - float end_time() - { - if(points.len()) - return points[points.len()-1].time*(1.0f/1000.0f); - return 0; - } -}; - - -class LAYER; -class LAYERGROUP; -class MAP; - -class LAYER -{ -public: - LAYER() - { - type = LAYERTYPE_INVALID; - type_name = "(invalid)"; - visible = true; - readonly = false; - flags = 0; - } - - virtual ~LAYER() - { - } - - - virtual void brush_selecting(RECT rect) {} - virtual int brush_grab(LAYERGROUP *brush, RECT rect) { return 0; } - virtual void brush_draw(LAYER *brush, float x, float y) {} - virtual void brush_place(LAYER *brush, float x, float y) {} - virtual void brush_flip_x() {} - virtual void brush_flip_y() {} - virtual void brush_rotate(float amount) {} - - virtual void render() {} - virtual int render_properties(RECT *toolbox) { return 0; } - - virtual void modify_image_index(INDEX_MODIFY_FUNC func) {} - virtual void modify_envelope_index(INDEX_MODIFY_FUNC func) {} - - virtual void get_size(float *w, float *h) { *w = 0; *h = 0;} - - const char *type_name; - int type; - int flags; - - bool readonly; - bool visible; -}; - -class LAYERGROUP -{ -public: - array layers; - - int offset_x; - int offset_y; - - int parallax_x; - int parallax_y; - - int use_clipping; - int clip_x; - int clip_y; - int clip_w; - int clip_h; - - const char *name; - bool game_group; - bool visible; - - LAYERGROUP(); - ~LAYERGROUP(); - - void convert(RECT *rect); - void render(); - void mapscreen(); - void mapping(float *points); - - bool is_empty() const; - void clear(); - void add_layer(LAYER *l); - - void get_size(float *w, float *h); - - void delete_layer(int index); - int swap_layers(int index0, int index1); - - void modify_image_index(INDEX_MODIFY_FUNC func) - { - for(int i = 0; i < layers.len(); i++) - layers[i]->modify_image_index(func); - } - - void modify_envelope_index(INDEX_MODIFY_FUNC func) - { - for(int i = 0; i < layers.len(); i++) - layers[i]->modify_envelope_index(func); - } -}; - -class EDITOR_IMAGE : public IMAGE_INFO -{ -public: - EDITOR_IMAGE() - { - tex_id = -1; - name[0] = 0; - external = 0; - width = 0; - height = 0; - data = 0; - format = 0; - } - - ~EDITOR_IMAGE() - { - gfx_unload_texture(tex_id); - } - - void analyse_tileflags(); - - int tex_id; - int external; - char name[128]; - unsigned char tileflags[256]; -}; - -class MAP -{ - void make_game_group(LAYERGROUP *group); - void make_game_layer(LAYER *layer); -public: - MAP() - { - clean(); - } - - array groups; - array images; - array envelopes; - - class LAYER_GAME *game_layer; - LAYERGROUP *game_group; - - ENVELOPE *new_envelope(int channels) - { - ENVELOPE *e = new ENVELOPE(channels); - envelopes.add(e); - return e; - } - - LAYERGROUP *new_group() - { - LAYERGROUP *g = new LAYERGROUP; - groups.add(g); - return g; - } - - int swap_groups(int index0, int index1) - { - if(index0 < 0 || index0 >= groups.len()) return index0; - if(index1 < 0 || index1 >= groups.len()) return index0; - if(index0 == index1) return index0; - swap(groups[index0], groups[index1]); - return index1; - } - - void delete_group(int index) - { - if(index < 0 || index >= groups.len()) return; - delete groups[index]; - groups.removebyindex(index); - } - - void modify_image_index(INDEX_MODIFY_FUNC func) - { - for(int i = 0; i < groups.len(); i++) - groups[i]->modify_image_index(func); - } - - void modify_envelope_index(INDEX_MODIFY_FUNC func) - { - for(int i = 0; i < groups.len(); i++) - groups[i]->modify_envelope_index(func); - } - - void clean(); - void create_default(int entities_texture); - - // io - int save(const char *filename); - int load(const char *filename); -}; - - -struct PROPERTY -{ - const char *name; - int value; - int type; - int min; - int max; -}; - -enum -{ - PROPTYPE_NULL=0, - PROPTYPE_BOOL, - PROPTYPE_INT_STEP, - PROPTYPE_INT_SCROLL, - PROPTYPE_COLOR, - PROPTYPE_IMAGE, - PROPTYPE_ENVELOPE, -}; - -class EDITOR -{ -public: - EDITOR() - { - mode = MODE_LAYERS; - dialog = 0; - tooltip = 0; - - world_offset_x = 0; - world_offset_y = 0; - editor_offset_x = 0.0f; - editor_offset_y = 0.0f; - - world_zoom = 1.0f; - zoom_level = 100; - lock_mouse = false; - show_mouse_pointer = true; - mouse_delta_x = 0; - mouse_delta_y = 0; - mouse_delta_wx = 0; - mouse_delta_wy = 0; - - gui_active = true; - proof_borders = false; - - show_detail = true; - animate = false; - animate_start = 0; - animate_time = 0; - animate_speed = 1; - - show_envelope_editor = 0; - } - - void invoke_file_dialog(int listdir_type, const char *title, const char *button_text, - const char *basepath, const char *default_name, - void (*func)(const char *filename)); - - void reset(bool create_default=true); - int save(const char *filename); - int load(const char *filename); - int append(const char *filename); - void render(); - - QUAD *get_selected_quad(); - LAYER *get_selected_layer_type(int index, int type); - LAYER *get_selected_layer(int index); - LAYERGROUP *get_selected_group(); - - int do_properties(RECT *toolbox, PROPERTY *props, int *ids, int *new_val); - - int mode; - int dialog; - const char *tooltip; - - float world_offset_x; - float world_offset_y; - float editor_offset_x; - float editor_offset_y; - float world_zoom; - int zoom_level; - bool lock_mouse; - bool show_mouse_pointer; - bool gui_active; - bool proof_borders; - float mouse_delta_x; - float mouse_delta_y; - float mouse_delta_wx; - float mouse_delta_wy; - - bool show_detail; - bool animate; - int64 animate_start; - float animate_time; - float animate_speed; - - int show_envelope_editor; - - int selected_layer; - int selected_group; - int selected_quad; - int selected_points; - int selected_envelope; - int selected_image; - - MAP map; -}; - -extern EDITOR editor; - -typedef struct -{ - int x, y; - int w, h; -} RECTi; - -class LAYER_TILES : public LAYER -{ -public: - LAYER_TILES(int w, int h); - ~LAYER_TILES(); - - void resize(int new_w, int new_h); - - void make_palette(); - virtual void render(); - - int convert_x(float x) const; - int convert_y(float y) const; - void convert(RECT rect, RECTi *out); - void snap(RECT *rect); - void clamp(RECTi *rect); - - virtual void brush_selecting(RECT rect); - virtual int brush_grab(LAYERGROUP *brush, RECT rect); - virtual void brush_draw(LAYER *brush, float wx, float wy); - virtual void brush_flip_x(); - virtual void brush_flip_y(); - - virtual int render_properties(RECT *toolbox); - - virtual void modify_image_index(INDEX_MODIFY_FUNC func); - virtual void modify_envelope_index(INDEX_MODIFY_FUNC func); - - void prepare_for_save(); - - void get_size(float *w, float *h) { *w = width*32.0f; *h = height*32.0f; } - - int tex_id; - int game; - int image; - int width; - int height; - TILE *tiles; -}; - -class LAYER_QUADS : public LAYER -{ -public: - LAYER_QUADS(); - ~LAYER_QUADS(); - - virtual void render(); - QUAD *new_quad(); - - virtual void brush_selecting(RECT rect); - virtual int brush_grab(LAYERGROUP *brush, RECT rect); - virtual void brush_place(LAYER *brush, float wx, float wy); - virtual void brush_flip_x(); - virtual void brush_flip_y(); - virtual void brush_rotate(float amount); - - virtual int render_properties(RECT *toolbox); - - virtual void modify_image_index(INDEX_MODIFY_FUNC func); - virtual void modify_envelope_index(INDEX_MODIFY_FUNC func); - - void get_size(float *w, float *h); - - int image; - array quads; -}; - -class LAYER_GAME : public LAYER_TILES -{ -public: - LAYER_GAME(int w, int h); - ~LAYER_GAME(); - - virtual int render_properties(RECT *toolbox); -}; - -int do_editor_button(const void *id, const char *text, int checked, const RECT *r, ui_draw_button_func draw_func, int flags, const char *tooltip); -void draw_editor_button(const void *id, const char *text, int checked, const RECT *r, const void *extra); -void draw_editor_button_menuitem(const void *id, const char *text, int checked, const RECT *r, const void *extra); - -void ui_invoke_popup_menu(void *id, int flags, float x, float y, float w, float h, int (*func)(RECT rect), void *extra=0); -void ui_do_popup_menu(); - -int popup_group(RECT view); -int popup_layer(RECT view); -int popup_quad(RECT view); -int popup_point(RECT view); - -void popup_select_image_invoke(int current, float x, float y); -int popup_select_image_result(); diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_io.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_io.cpp deleted file mode 100644 index dfaa0e2c3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_io.cpp +++ /dev/null @@ -1,602 +0,0 @@ -#include -#include -#include "ed_editor.hpp" - -template -static int make_version(int i, const T &v) -{ return (i<<16)+sizeof(T); } - -// backwards compatiblity -void editor_load_old(DATAFILE *df, MAP *map) -{ - class mapres_image - { - public: - int width; - int height; - int image_data; - }; - - struct mapres_tilemap - { - int image; - int width; - int height; - int x, y; - int scale; - int data; - int main; - }; - - struct mapres_entity - { - int x, y; - int data[1]; - }; - - struct mapres_spawnpoint - { - int x, y; - }; - - struct mapres_item - { - int x, y; - int type; - }; - - struct mapres_flagstand - { - int x, y; - }; - - enum - { - MAPRES_ENTS_START=1, - MAPRES_SPAWNPOINT=1, - MAPRES_ITEM=2, - MAPRES_SPAWNPOINT_RED=3, - MAPRES_SPAWNPOINT_BLUE=4, - MAPRES_FLAGSTAND_RED=5, - MAPRES_FLAGSTAND_BLUE=6, - MAPRES_ENTS_END, - - ITEM_NULL=0, - ITEM_WEAPON_GUN=0x00010001, - ITEM_WEAPON_SHOTGUN=0x00010002, - ITEM_WEAPON_ROCKET=0x00010003, - ITEM_WEAPON_SNIPER=0x00010004, - ITEM_WEAPON_HAMMER=0x00010005, - ITEM_HEALTH =0x00020001, - ITEM_ARMOR=0x00030001, - ITEM_NINJA=0x00040001, - }; - - enum - { - MAPRES_REGISTERED=0x8000, - MAPRES_IMAGE=0x8001, - MAPRES_TILEMAP=0x8002, - MAPRES_COLLISIONMAP=0x8003, - MAPRES_TEMP_THEME=0x8fff, - }; - - // load tilemaps - int game_width = 0; - int game_height = 0; - { - int start, num; - datafile_get_type(df, MAPRES_TILEMAP, &start, &num); - for(int t = 0; t < num; t++) - { - mapres_tilemap *tmap = (mapres_tilemap *)datafile_get_item(df, start+t,0,0); - - LAYER_TILES *l = new LAYER_TILES(tmap->width, tmap->height); - - if(tmap->main) - { - // move game layer to correct position - for(int i = 0; i < map->groups[0]->layers.len()-1; i++) - { - if(map->groups[0]->layers[i] == editor.map.game_layer) - map->groups[0]->swap_layers(i, i+1); - } - - game_width = tmap->width; - game_height = tmap->height; - } - - // add new layer - map->groups[0]->add_layer(l); - - // process the data - unsigned char *src_data = (unsigned char *)datafile_get_data(df, tmap->data); - TILE *dst_data = l->tiles; - - for(int y = 0; y < tmap->height; y++) - for(int x = 0; x < tmap->width; x++, dst_data++, src_data+=2) - { - dst_data->index = src_data[0]; - dst_data->flags = src_data[1]; - } - - l->image = tmap->image; - } - } - - // load images - { - int start, count; - datafile_get_type(df, MAPRES_IMAGE, &start, &count); - for(int i = 0; i < count; i++) - { - mapres_image *imgres = (mapres_image *)datafile_get_item(df, start+i, 0, 0); - void *data = datafile_get_data(df, imgres->image_data); - - EDITOR_IMAGE *img = new EDITOR_IMAGE; - img->width = imgres->width; - img->height = imgres->height; - img->format = IMG_RGBA; - - // copy image data - img->data = mem_alloc(img->width*img->height*4, 1); - mem_copy(img->data, data, img->width*img->height*4); - img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO, 0); - map->images.add(img); - - // unload image - datafile_unload_data(df, imgres->image_data); - } - } - - // load entities - { - LAYER_GAME *g = map->game_layer; - g->resize(game_width, game_height); - for(int t = MAPRES_ENTS_START; t < MAPRES_ENTS_END; t++) - { - // fetch entities of this class - int start, num; - datafile_get_type(df, t, &start, &num); - - - for(int i = 0; i < num; i++) - { - mapres_entity *e = (mapres_entity *)datafile_get_item(df, start+i,0,0); - int x = e->x/32; - int y = e->y/32; - int id = -1; - - if(t == MAPRES_SPAWNPOINT) id = ENTITY_SPAWN; - else if(t == MAPRES_SPAWNPOINT_RED) id = ENTITY_SPAWN_RED; - else if(t == MAPRES_SPAWNPOINT_BLUE) id = ENTITY_SPAWN_BLUE; - else if(t == MAPRES_FLAGSTAND_RED) id = ENTITY_FLAGSTAND_RED; - else if(t == MAPRES_FLAGSTAND_BLUE) id = ENTITY_FLAGSTAND_BLUE; - else if(t == MAPRES_ITEM) - { - if(e->data[0] == ITEM_WEAPON_SHOTGUN) id = ENTITY_WEAPON_SHOTGUN; - else if(e->data[0] == ITEM_WEAPON_ROCKET) id = ENTITY_WEAPON_GRENADE; - else if(e->data[0] == ITEM_NINJA) id = ENTITY_POWERUP_NINJA; - else if(e->data[0] == ITEM_ARMOR) id = ENTITY_ARMOR_1; - else if(e->data[0] == ITEM_HEALTH) id = ENTITY_HEALTH_1; - } - - if(id > 0 && x >= 0 && x < g->width && y >= 0 && y < g->height) - g->tiles[y*g->width+x].index = id+ENTITY_OFFSET; - } - } - } -} - -int EDITOR::save(const char *filename) -{ - return map.save(filename); -} - -int MAP::save(const char *filename) -{ - dbg_msg("editor", "saving to '%s'...", filename); - DATAFILE_OUT *df = datafile_create(filename); - if(!df) - { - dbg_msg("editor", "failed to open file '%s'...", filename); - return 0; - } - - // save version - { - MAPITEM_VERSION item; - item.version = 1; - datafile_add_item(df, MAPITEMTYPE_VERSION, 0, sizeof(item), &item); - } - - // save images - for(int i = 0; i < images.len(); i++) - { - EDITOR_IMAGE *img = images[i]; - - // analyse the image for when saving (should be done when we load the image) - // TODO! - img->analyse_tileflags(); - - MAPITEM_IMAGE item; - item.version = 1; - - item.width = img->width; - item.height = img->height; - item.external = img->external; - item.image_name = datafile_add_data(df, strlen(img->name)+1, img->name); - if(img->external) - item.image_data = -1; - else - item.image_data = datafile_add_data(df, item.width*item.height*4, img->data); - datafile_add_item(df, MAPITEMTYPE_IMAGE, i, sizeof(item), &item); - } - - // save layers - int layer_count = 0; - for(int g = 0; g < groups.len(); g++) - { - LAYERGROUP *group = groups[g]; - MAPITEM_GROUP gitem; - gitem.version = MAPITEM_GROUP::CURRENT_VERSION; - - gitem.parallax_x = group->parallax_x; - gitem.parallax_y = group->parallax_y; - gitem.offset_x = group->offset_x; - gitem.offset_y = group->offset_y; - gitem.use_clipping = group->use_clipping; - gitem.clip_x = group->clip_x; - gitem.clip_y = group->clip_y; - gitem.clip_w = group->clip_w; - gitem.clip_h = group->clip_h; - gitem.start_layer = layer_count; - gitem.num_layers = 0; - - for(int l = 0; l < group->layers.len(); l++) - { - if(group->layers[l]->type == LAYERTYPE_TILES) - { - dbg_msg("editor", "saving tiles layer"); - LAYER_TILES *layer = (LAYER_TILES *)group->layers[l]; - layer->prepare_for_save(); - - MAPITEM_LAYER_TILEMAP item; - item.version = 2; - - item.layer.flags = layer->flags; - item.layer.type = layer->type; - - item.color.r = 255; // not in use right now - item.color.g = 255; - item.color.b = 255; - item.color.a = 255; - item.color_env = -1; - item.color_env_offset = 0; - - item.width = layer->width; - item.height = layer->height; - item.flags = layer->game; - item.image = layer->image; - item.data = datafile_add_data(df, layer->width*layer->height*sizeof(TILE), layer->tiles); - datafile_add_item(df, MAPITEMTYPE_LAYER, layer_count, sizeof(item), &item); - - gitem.num_layers++; - layer_count++; - } - else if(group->layers[l]->type == LAYERTYPE_QUADS) - { - dbg_msg("editor", "saving quads layer"); - LAYER_QUADS *layer = (LAYER_QUADS *)group->layers[l]; - if(layer->quads.len()) - { - MAPITEM_LAYER_QUADS item; - item.version = 1; - item.layer.flags = layer->flags; - item.layer.type = layer->type; - item.image = layer->image; - - // add the data - item.num_quads = layer->quads.len(); - item.data = datafile_add_data_swapped(df, layer->quads.len()*sizeof(QUAD), layer->quads.getptr()); - datafile_add_item(df, MAPITEMTYPE_LAYER, layer_count, sizeof(item), &item); - - // clean up - //mem_free(quads); - - gitem.num_layers++; - layer_count++; - } - } - } - - datafile_add_item(df, MAPITEMTYPE_GROUP, g, sizeof(gitem), &gitem); - } - - // save envelopes - int point_count = 0; - for(int e = 0; e < envelopes.len(); e++) - { - MAPITEM_ENVELOPE item; - item.version = 1; - item.channels = envelopes[e]->channels; - item.start_point = point_count; - item.num_points = envelopes[e]->points.len(); - item.name = -1; - - datafile_add_item(df, MAPITEMTYPE_ENVELOPE, e, sizeof(item), &item); - point_count += item.num_points; - } - - // save points - int totalsize = sizeof(ENVPOINT) * point_count; - ENVPOINT *points = (ENVPOINT *)mem_alloc(totalsize, 1); - point_count = 0; - - for(int e = 0; e < envelopes.len(); e++) - { - int count = envelopes[e]->points.len(); - mem_copy(&points[point_count], envelopes[e]->points.getptr(), sizeof(ENVPOINT)*count); - point_count += count; - } - - datafile_add_item(df, MAPITEMTYPE_ENVPOINTS, 0, totalsize, points); - - // finish the data file - datafile_finish(df); - dbg_msg("editor", "done"); - - // send rcon.. if we can - if(client_rcon_authed()) - { - client_rcon("sv_map_reload 1"); - } - - return 1; -} - -int EDITOR::load(const char *filename) -{ - reset(); - return map.load(filename); -} - -int MAP::load(const char *filename) -{ - DATAFILE *df = datafile_load(filename); - if(!df) - return 0; - - clean(); - - // check version - MAPITEM_VERSION *item = (MAPITEM_VERSION *)datafile_find_item(df, MAPITEMTYPE_VERSION, 0); - if(!item) - { - // import old map - MAP old_mapstuff; - editor.reset(); - editor_load_old(df, this); - } - else if(item->version == 1) - { - //editor.reset(false); - - // load images - { - int start, num; - datafile_get_type(df, MAPITEMTYPE_IMAGE, &start, &num); - for(int i = 0; i < num; i++) - { - MAPITEM_IMAGE *item = (MAPITEM_IMAGE *)datafile_get_item(df, start+i, 0, 0); - char *name = (char *)datafile_get_data(df, item->image_name); - - // copy base info - EDITOR_IMAGE *img = new EDITOR_IMAGE; - img->external = item->external; - - if(item->external) - { - char buf[256]; - sprintf(buf, "mapres/%s.png", name); - - // load external - EDITOR_IMAGE imginfo; - if(gfx_load_png(&imginfo, buf)) - { - *img = imginfo; - img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0); - img->external = 1; - } - } - else - { - img->width = item->width; - img->height = item->height; - img->format = IMG_RGBA; - - // copy image data - void *data = datafile_get_data(df, item->image_data); - img->data = mem_alloc(img->width*img->height*4, 1); - mem_copy(img->data, data, img->width*img->height*4); - img->tex_id = gfx_load_texture_raw(img->width, img->height, img->format, img->data, IMG_AUTO, 0); - } - - // copy image name - if(name) - strncpy(img->name, name, 128); - - images.add(img); - - // unload image - datafile_unload_data(df, item->image_data); - datafile_unload_data(df, item->image_name); - } - } - - // load groups - { - int layers_start, layers_num; - datafile_get_type(df, MAPITEMTYPE_LAYER, &layers_start, &layers_num); - - int start, num; - datafile_get_type(df, MAPITEMTYPE_GROUP, &start, &num); - for(int g = 0; g < num; g++) - { - MAPITEM_GROUP *gitem = (MAPITEM_GROUP *)datafile_get_item(df, start+g, 0, 0); - - if(gitem->version < 1 || gitem->version > MAPITEM_GROUP::CURRENT_VERSION) - continue; - - LAYERGROUP *group = new_group(); - group->parallax_x = gitem->parallax_x; - group->parallax_y = gitem->parallax_y; - group->offset_x = gitem->offset_x; - group->offset_y = gitem->offset_y; - - if(gitem->version >= 2) - { - group->use_clipping = gitem->use_clipping; - group->clip_x = gitem->clip_x; - group->clip_y = gitem->clip_y; - group->clip_w = gitem->clip_w; - group->clip_h = gitem->clip_h; - } - - for(int l = 0; l < gitem->num_layers; l++) - { - LAYER *layer = 0; - MAPITEM_LAYER *layer_item = (MAPITEM_LAYER *)datafile_get_item(df, layers_start+gitem->start_layer+l, 0, 0); - if(!layer_item) - continue; - - if(layer_item->type == LAYERTYPE_TILES) - { - MAPITEM_LAYER_TILEMAP *tilemap_item = (MAPITEM_LAYER_TILEMAP *)layer_item; - LAYER_TILES *tiles = 0; - - if(tilemap_item->flags&1) - { - tiles = new LAYER_GAME(tilemap_item->width, tilemap_item->height); - make_game_layer(tiles); - make_game_group(group); - } - else - tiles = new LAYER_TILES(tilemap_item->width, tilemap_item->height); - - layer = tiles; - - group->add_layer(tiles); - void *data = datafile_get_data(df, tilemap_item->data); - tiles->image = tilemap_item->image; - tiles->game = tilemap_item->flags&1; - - mem_copy(tiles->tiles, data, tiles->width*tiles->height*sizeof(TILE)); - - if(tiles->game && tilemap_item->version == make_version(1, *tilemap_item)) - { - for(int i = 0; i < tiles->width*tiles->height; i++) - { - if(tiles->tiles[i].index) - tiles->tiles[i].index += ENTITY_OFFSET; - } - } - - datafile_unload_data(df, tilemap_item->data); - } - else if(layer_item->type == LAYERTYPE_QUADS) - { - MAPITEM_LAYER_QUADS *quads_item = (MAPITEM_LAYER_QUADS *)layer_item; - LAYER_QUADS *quads = new LAYER_QUADS; - layer = quads; - quads->image = quads_item->image; - if(quads->image < -1 || quads->image >= images.len()) - quads->image = -1; - void *data = datafile_get_data_swapped(df, quads_item->data); - group->add_layer(quads); - quads->quads.setsize(quads_item->num_quads); - mem_copy(quads->quads.getptr(), data, sizeof(QUAD)*quads_item->num_quads); - datafile_unload_data(df, quads_item->data); - } - - if(layer) - layer->flags = layer_item->flags; - } - } - } - - // load envelopes - { - ENVPOINT *points = 0; - - { - int start, num; - datafile_get_type(df, MAPITEMTYPE_ENVPOINTS, &start, &num); - if(num) - points = (ENVPOINT *)datafile_get_item(df, start, 0, 0); - } - - int start, num; - datafile_get_type(df, MAPITEMTYPE_ENVELOPE, &start, &num); - for(int e = 0; e < num; e++) - { - MAPITEM_ENVELOPE *item = (MAPITEM_ENVELOPE *)datafile_get_item(df, start+e, 0, 0); - ENVELOPE *env = new ENVELOPE(item->channels); - env->points.setsize(item->num_points); - mem_copy(env->points.getptr(), &points[item->start_point], sizeof(ENVPOINT)*item->num_points); - envelopes.add(env); - } - } - } - - datafile_unload(df); - - return 0; -} - -static int modify_add_amount = 0; -static void modify_add(int *index) -{ - if(*index >= 0) - *index += modify_add_amount; -} - -int EDITOR::append(const char *filename) -{ - MAP new_map; - int err; - err = new_map.load(filename); - if(err) - return err; - - // modify indecies - modify_add_amount = map.images.len(); - new_map.modify_image_index(modify_add); - - modify_add_amount = map.envelopes.len(); - new_map.modify_envelope_index(modify_add); - - // transfer images - for(int i = 0; i < new_map.images.len(); i++) - map.images.add(new_map.images[i]); - new_map.images.clear(); - - // transfer envelopes - for(int i = 0; i < new_map.envelopes.len(); i++) - map.envelopes.add(new_map.envelopes[i]); - new_map.envelopes.clear(); - - // transfer groups - - for(int i = 0; i < new_map.groups.len(); i++) - { - if(new_map.groups[i] == new_map.game_group) - delete new_map.groups[i]; - else - map.groups.add(new_map.groups[i]); - } - new_map.groups.clear(); - - // all done \o/ - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_game.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_game.cpp deleted file mode 100644 index 60825ec3e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_game.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "ed_editor.hpp" - - -LAYER_GAME::LAYER_GAME(int w, int h) -: LAYER_TILES(w, h) -{ - type_name = "Game"; - game = 1; -} - -LAYER_GAME::~LAYER_GAME() -{ -} - -int LAYER_GAME::render_properties(RECT *toolbox) -{ - int r = LAYER_TILES::render_properties(toolbox); - image = -1; - return r; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_quads.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_quads.cpp deleted file mode 100644 index bbe5fb6dc..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_quads.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include - -#include "ed_editor.hpp" -#include -#include - -LAYER_QUADS::LAYER_QUADS() -{ - type = LAYERTYPE_QUADS; - type_name = "Quads"; - image = -1; -} - -LAYER_QUADS::~LAYER_QUADS() -{ -} - -static void envelope_eval(float time_offset, int env, float *channels) -{ - if(env < 0 || env > editor.map.envelopes.len()) - { - channels[0] = 0; - channels[1] = 0; - channels[2] = 0; - channels[3] = 0; - return; - } - - ENVELOPE *e = editor.map.envelopes[env]; - float t = editor.animate_time+time_offset; - t *= editor.animate_speed; - e->eval(t, channels); -} - -void LAYER_QUADS::render() -{ - gfx_texture_set(-1); - if(image >= 0 && image < editor.map.images.len()) - gfx_texture_set(editor.map.images[image]->tex_id); - - render_quads(quads.getptr(), quads.len(), envelope_eval, LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT); -} - -QUAD *LAYER_QUADS::new_quad() -{ - QUAD *q = &quads[quads.add(QUAD())]; - - q->pos_env = -1; - q->color_env = -1; - q->pos_env_offset = 0; - q->color_env_offset = 0; - int x = 0, y = 0; - q->points[0].x = x; - q->points[0].y = y; - q->points[1].x = x+64; - q->points[1].y = y; - q->points[2].x = x; - q->points[2].y = y+64; - q->points[3].x = x+64; - q->points[3].y = y+64; - - q->points[4].x = x+32; // pivot - q->points[4].y = y+32; - - for(int i = 0; i < 5; i++) - { - q->points[i].x <<= 10; - q->points[i].y <<= 10; - } - - - q->texcoords[0].x = 0; - q->texcoords[0].y = 0; - - q->texcoords[1].x = 1<<10; - q->texcoords[1].y = 0; - - q->texcoords[2].x = 0; - q->texcoords[2].y = 1<<10; - - q->texcoords[3].x = 1<<10; - q->texcoords[3].y = 1<<10; - - q->colors[0].r = 255; q->colors[0].g = 255; q->colors[0].b = 255; q->colors[0].a = 255; - q->colors[1].r = 255; q->colors[1].g = 255; q->colors[1].b = 255; q->colors[1].a = 255; - q->colors[2].r = 255; q->colors[2].g = 255; q->colors[2].b = 255; q->colors[2].a = 255; - q->colors[3].r = 255; q->colors[3].g = 255; q->colors[3].b = 255; q->colors[3].a = 255; - - return q; -} - -void LAYER_QUADS::brush_selecting(RECT rect) -{ - // draw selection rectangle - gfx_texture_set(-1); - gfx_lines_begin(); - gfx_lines_draw(rect.x, rect.y, rect.x+rect.w, rect.y); - gfx_lines_draw(rect.x+rect.w, rect.y, rect.x+rect.w, rect.y+rect.h); - gfx_lines_draw(rect.x+rect.w, rect.y+rect.h, rect.x, rect.y+rect.h); - gfx_lines_draw(rect.x, rect.y+rect.h, rect.x, rect.y); - gfx_lines_end(); -} - -int LAYER_QUADS::brush_grab(LAYERGROUP *brush, RECT rect) -{ - // create new layers - LAYER_QUADS *grabbed = new LAYER_QUADS(); - grabbed->image = image; - brush->add_layer(grabbed); - - //dbg_msg("", "%f %f %f %f", rect.x, rect.y, rect.w, rect.h); - for(int i = 0; i < quads.len(); i++) - { - QUAD *q = &quads[i]; - float px = fx2f(q->points[4].x); - float py = fx2f(q->points[4].y); - - if(px > rect.x && px < rect.x+rect.w && py > rect.y && py < rect.y+rect.h) - { - dbg_msg("", "grabbed one"); - QUAD n; - n = *q; - - for(int p = 0; p < 5; p++) - { - n.points[p].x -= f2fx(rect.x); - n.points[p].y -= f2fx(rect.y); - } - - grabbed->quads.add(n); - } - } - - return grabbed->quads.len()?1:0; -} - -void LAYER_QUADS::brush_place(LAYER *brush, float wx, float wy) -{ - LAYER_QUADS *l = (LAYER_QUADS *)brush; - for(int i = 0; i < l->quads.len(); i++) - { - QUAD n = l->quads[i]; - - for(int p = 0; p < 5; p++) - { - n.points[p].x += f2fx(wx); - n.points[p].y += f2fx(wy); - } - - quads.add(n); - } -} - -void LAYER_QUADS::brush_flip_x() -{ -} - -void LAYER_QUADS::brush_flip_y() -{ -} - -void rotate(vec2 *center, vec2 *point, float rotation) -{ - float x = point->x - center->x; - float y = point->y - center->y; - point->x = x * cosf(rotation) - y * sinf(rotation) + center->x; - point->y = x * sinf(rotation) + y * cosf(rotation) + center->y; -} - -void LAYER_QUADS::brush_rotate(float amount) -{ - vec2 center; - get_size(¢er.x, ¢er.y); - center.x /= 2; - center.y /= 2; - - for(int i = 0; i < quads.len(); i++) - { - QUAD *q = &quads[i]; - - for(int p = 0; p < 5; p++) - { - vec2 pos(fx2f(q->points[p].x), fx2f(q->points[p].y)); - rotate(¢er, &pos, amount); - q->points[p].x = f2fx(pos.x); - q->points[p].y = f2fx(pos.y); - } - } -} - -void LAYER_QUADS::get_size(float *w, float *h) -{ - *w = 0; *h = 0; - - for(int i = 0; i < quads.len(); i++) - { - for(int p = 0; p < 5; p++) - { - *w = max(*w, fx2f(quads[i].points[p].x)); - *h = max(*h, fx2f(quads[i].points[p].y)); - } - } -} - -extern int selected_points; - -int LAYER_QUADS::render_properties(RECT *toolbox) -{ - // layer props - enum - { - PROP_IMAGE=0, - NUM_PROPS, - }; - - PROPERTY props[] = { - {"Image", image, PROPTYPE_IMAGE, -1, 0}, - {0}, - }; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - int prop = editor.do_properties(toolbox, props, ids, &new_val); - - if(prop == PROP_IMAGE) - { - if(new_val >= 0) - image = new_val%editor.map.images.len(); - else - image = -1; - } - - return 0; -} - - -void LAYER_QUADS::modify_image_index(INDEX_MODIFY_FUNC func) -{ - func(&image); -} - -void LAYER_QUADS::modify_envelope_index(INDEX_MODIFY_FUNC func) -{ - for(int i = 0; i < quads.len(); i++) - { - func(&quads[i].pos_env); - func(&quads[i].color_env); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_tiles.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_tiles.cpp deleted file mode 100644 index 80ccaa3ad..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_layer_tiles.cpp +++ /dev/null @@ -1,296 +0,0 @@ -#include - -#include -#include -#include "ed_editor.hpp" - -LAYER_TILES::LAYER_TILES(int w, int h) -{ - type = LAYERTYPE_TILES; - type_name = "Tiles"; - width = w; - height = h; - image = -1; - tex_id = -1; - game = 0; - - tiles = new TILE[width*height]; - mem_zero(tiles, width*height*sizeof(TILE)); -} - -LAYER_TILES::~LAYER_TILES() -{ - delete [] tiles; -} - -void LAYER_TILES::prepare_for_save() -{ - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - tiles[y*width+x].flags &= TILEFLAG_VFLIP|TILEFLAG_HFLIP; - - if(image != -1) - { - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - tiles[y*width+x].flags |= editor.map.images[image]->tileflags[tiles[y*width+x].index]; - } -} - -void LAYER_TILES::make_palette() -{ - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - tiles[y*width+x].index = y*16+x; -} - -void LAYER_TILES::render() -{ - if(image >= 0 && image < editor.map.images.len()) - tex_id = editor.map.images[image]->tex_id; - gfx_texture_set(tex_id); - render_tilemap(tiles, width, height, 32.0f, vec4(1,1,1,1), LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT); -} - -int LAYER_TILES::convert_x(float x) const { return (int)(x/32.0f); } -int LAYER_TILES::convert_y(float y) const { return (int)(y/32.0f); } - -void LAYER_TILES::convert(RECT rect, RECTi *out) -{ - out->x = convert_x(rect.x); - out->y = convert_y(rect.y); - out->w = convert_x(rect.x+rect.w+31) - out->x; - out->h = convert_y(rect.y+rect.h+31) - out->y; -} - -void LAYER_TILES::snap(RECT *rect) -{ - RECTi out; - convert(*rect, &out); - rect->x = out.x*32.0f; - rect->y = out.y*32.0f; - rect->w = out.w*32.0f; - rect->h = out.h*32.0f; -} - -void LAYER_TILES::clamp(RECTi *rect) -{ - if(rect->x < 0) - { - rect->w += rect->x; - rect->x = 0; - } - - if(rect->y < 0) - { - rect->h += rect->y; - rect->y = 0; - } - - if(rect->x+rect->w > width) - rect->w = width-rect->x; - - if(rect->y+rect->h > height) - rect->h = height-rect->y; - - if(rect->h < 0) - rect->h = 0; - if(rect->w < 0) - rect->w = 0; -} - -void LAYER_TILES::brush_selecting(RECT rect) -{ - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_setcolor(1,1,1,0.4f); - snap(&rect); - gfx_quads_drawTL(rect.x, rect.y, rect.w, rect.h); - gfx_quads_end(); - char buf[16]; - str_format(buf, sizeof(buf), "%d,%d", convert_x(rect.w), convert_y(rect.h)); - gfx_text(0, rect.x+3.0f, rect.y+3.0f, 15.0f*editor.world_zoom, buf, -1); -} - -int LAYER_TILES::brush_grab(LAYERGROUP *brush, RECT rect) -{ - RECTi r; - convert(rect, &r); - clamp(&r); - - if(!r.w || !r.h) - return 0; - - // create new layers - LAYER_TILES *grabbed = new LAYER_TILES(r.w, r.h); - grabbed->tex_id = tex_id; - grabbed->image = image; - brush->add_layer(grabbed); - - // copy the tiles - for(int y = 0; y < r.h; y++) - for(int x = 0; x < r.w; x++) - grabbed->tiles[y*grabbed->width+x] = tiles[(r.y+y)*width+(r.x+x)]; - - return 1; -} - -void LAYER_TILES::brush_draw(LAYER *brush, float wx, float wy) -{ - if(readonly) - return; - - // - LAYER_TILES *l = (LAYER_TILES *)brush; - int sx = convert_x(wx); - int sy = convert_y(wy); - - for(int y = 0; y < l->height; y++) - for(int x = 0; x < l->width; x++) - { - int fx = x+sx; - int fy = y+sy; - if(fx<0 || fx >= width || fy < 0 || fy >= height) - continue; - - tiles[fy*width+fx] = l->tiles[y*l->width+x]; - } -} - -void LAYER_TILES::brush_flip_x() -{ - for(int y = 0; y < height; y++) - for(int x = 0; x < width/2; x++) - { - TILE tmp = tiles[y*width+x]; - tiles[y*width+x] = tiles[y*width+width-1-x]; - tiles[y*width+width-1-x] = tmp; - } - - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - tiles[y*width+x].flags ^= TILEFLAG_VFLIP; -} - -void LAYER_TILES::brush_flip_y() -{ - for(int y = 0; y < height/2; y++) - for(int x = 0; x < width; x++) - { - TILE tmp = tiles[y*width+x]; - tiles[y*width+x] = tiles[(height-1-y)*width+x]; - tiles[(height-1-y)*width+x] = tmp; - } - - for(int y = 0; y < height; y++) - for(int x = 0; x < width; x++) - tiles[y*width+x].flags ^= TILEFLAG_HFLIP; -} - -void LAYER_TILES::resize(int new_w, int new_h) -{ - TILE *new_data = new TILE[new_w*new_h]; - mem_zero(new_data, new_w*new_h*sizeof(TILE)); - - // copy old data - for(int y = 0; y < min(new_h, height); y++) - mem_copy(&new_data[y*new_w], &tiles[y*width], min(width, new_w)*sizeof(TILE)); - - // replace old - delete [] tiles; - tiles = new_data; - width = new_w; - height = new_h; -} - - -int LAYER_TILES::render_properties(RECT *toolbox) -{ - RECT button; - ui_hsplit_b(toolbox, 12.0f, toolbox, &button); - bool in_gamegroup = editor.map.game_group->layers.find(this) != -1; - if(editor.map.game_layer == this) - in_gamegroup = false; - static int colcl_button = 0; - if(do_editor_button(&colcl_button, "Clear Collision", in_gamegroup?0:-1, &button, draw_editor_button, 0, "Removes collision from this layer")) - { - LAYER_TILES *gl = editor.map.game_layer; - int w = min(gl->width, width); - int h = min(gl->height, height); - for(int y = 0; y < h; y++) - for(int x = 0; x < w; x++) - { - if(gl->tiles[y*gl->width+x].index <= TILE_SOLID) - if(tiles[y*width+x].index) - gl->tiles[y*gl->width+x].index = TILE_AIR; - } - - return 1; - } - static int col_button = 0; - ui_hsplit_b(toolbox, 5.0f, toolbox, &button); - ui_hsplit_b(toolbox, 12.0f, toolbox, &button); - if(do_editor_button(&col_button, "Make Collision", in_gamegroup?0:-1, &button, draw_editor_button, 0, "Constructs collision from this layer")) - { - LAYER_TILES *gl = editor.map.game_layer; - int w = min(gl->width, width); - int h = min(gl->height, height); - for(int y = 0; y < h; y++) - for(int x = 0; x < w; x++) - { - if(gl->tiles[y*gl->width+x].index <= TILE_SOLID) - gl->tiles[y*gl->width+x].index = tiles[y*width+x].index?TILE_SOLID:TILE_AIR; - } - - return 1; - } - - enum - { - PROP_WIDTH=0, - PROP_HEIGHT, - PROP_IMAGE, - NUM_PROPS, - }; - - PROPERTY props[] = { - {"Width", width, PROPTYPE_INT_STEP, 1, 1000000000}, - {"Height", height, PROPTYPE_INT_STEP, 1, 1000000000}, - {"Image", image, PROPTYPE_IMAGE, 0, 0}, - {0}, - }; - - if(editor.map.game_layer == this) // remove the image from the selection if this is the game layer - props[2].name = 0; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - int prop = editor.do_properties(toolbox, props, ids, &new_val); - - if(prop == PROP_WIDTH && new_val > 1) - resize(new_val, height); - else if(prop == PROP_HEIGHT && new_val > 1) - resize(width, new_val); - else if(prop == PROP_IMAGE) - { - if (new_val == -1) - { - tex_id = -1; - image = -1; - } - else - image = new_val%editor.map.images.len(); - } - - return 0; -} - - -void LAYER_TILES::modify_image_index(INDEX_MODIFY_FUNC func) -{ - func(&image); -} - -void LAYER_TILES::modify_envelope_index(INDEX_MODIFY_FUNC func) -{ -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_popups.cpp b/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_popups.cpp deleted file mode 100644 index 13bfe243e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/editor/ed_popups.cpp +++ /dev/null @@ -1,424 +0,0 @@ -#include -#include "ed_editor.hpp" - - -// popup menu handling -static struct -{ - RECT rect; - void *id; - int (*func)(RECT rect); - int is_menu; - void *extra; -} ui_popups[8]; - -static int ui_num_popups = 0; - -void ui_invoke_popup_menu(void *id, int flags, float x, float y, float w, float h, int (*func)(RECT rect), void *extra) -{ - dbg_msg("", "invoked"); - ui_popups[ui_num_popups].id = id; - ui_popups[ui_num_popups].is_menu = flags; - ui_popups[ui_num_popups].rect.x = x; - ui_popups[ui_num_popups].rect.y = y; - ui_popups[ui_num_popups].rect.w = w; - ui_popups[ui_num_popups].rect.h = h; - ui_popups[ui_num_popups].func = func; - ui_popups[ui_num_popups].extra = extra; - ui_num_popups++; -} - -void ui_do_popup_menu() -{ - for(int i = 0; i < ui_num_popups; i++) - { - bool inside = ui_mouse_inside(&ui_popups[i].rect); - ui_set_hot_item(&ui_popups[i].id); - - if(ui_active_item() == &ui_popups[i].id) - { - if(!ui_mouse_button(0)) - { - if(!inside) - ui_num_popups--; - ui_set_active_item(0); - } - } - else if(ui_hot_item() == &ui_popups[i].id) - { - if(ui_mouse_button(0)) - ui_set_active_item(&ui_popups[i].id); - } - - int corners = CORNER_ALL; - if(ui_popups[i].is_menu) - corners = CORNER_R|CORNER_B; - - RECT r = ui_popups[i].rect; - ui_draw_rect(&r, vec4(0.5f,0.5f,0.5f,0.75f), corners, 3.0f); - ui_margin(&r, 1.0f, &r); - ui_draw_rect(&r, vec4(0,0,0,0.75f), corners, 3.0f); - ui_margin(&r, 4.0f, &r); - - if(ui_popups[i].func(r)) - ui_num_popups--; - - if(inp_key_down(KEY_ESCAPE)) - ui_num_popups--; - } -} - - -int popup_group(RECT view) -{ - // remove group button - RECT button; - ui_hsplit_b(&view, 12.0f, &view, &button); - static int delete_button = 0; - - // don't allow deletion of game group - if(editor.map.game_group != editor.get_selected_group() && - do_editor_button(&delete_button, "Delete Group", 0, &button, draw_editor_button, 0, "Delete group")) - { - editor.map.delete_group(editor.selected_group); - return 1; - } - - // new tile layer - ui_hsplit_b(&view, 10.0f, &view, &button); - ui_hsplit_b(&view, 12.0f, &view, &button); - static int new_quad_layer_button = 0; - if(do_editor_button(&new_quad_layer_button, "Add Quads Layer", 0, &button, draw_editor_button, 0, "Creates a new quad layer")) - { - LAYER *l = new LAYER_QUADS; - editor.map.groups[editor.selected_group]->add_layer(l); - editor.selected_layer = editor.map.groups[editor.selected_group]->layers.len()-1; - return 1; - } - - // new quad layer - ui_hsplit_b(&view, 5.0f, &view, &button); - ui_hsplit_b(&view, 12.0f, &view, &button); - static int new_tile_layer_button = 0; - if(do_editor_button(&new_tile_layer_button, "Add Tile Layer", 0, &button, draw_editor_button, 0, "Creates a new tile layer")) - { - LAYER *l = new LAYER_TILES(50, 50); - editor.map.groups[editor.selected_group]->add_layer(l); - editor.selected_layer = editor.map.groups[editor.selected_group]->layers.len()-1; - return 1; - } - - enum - { - PROP_ORDER=0, - PROP_POS_X, - PROP_POS_Y, - PROP_PARA_X, - PROP_PARA_Y, - PROP_USE_CLIPPING, - PROP_CLIP_X, - PROP_CLIP_Y, - PROP_CLIP_W, - PROP_CLIP_H, - NUM_PROPS, - }; - - PROPERTY props[] = { - {"Order", editor.selected_group, PROPTYPE_INT_STEP, 0, editor.map.groups.len()-1}, - {"Pos X", -editor.map.groups[editor.selected_group]->offset_x, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Pos Y", -editor.map.groups[editor.selected_group]->offset_y, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Para X", editor.map.groups[editor.selected_group]->parallax_x, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Para Y", editor.map.groups[editor.selected_group]->parallax_y, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - - {"Use Clipping", editor.map.groups[editor.selected_group]->use_clipping, PROPTYPE_BOOL, 0, 1}, - {"Clip X", editor.map.groups[editor.selected_group]->clip_x, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip Y", editor.map.groups[editor.selected_group]->clip_y, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip W", editor.map.groups[editor.selected_group]->clip_w, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Clip H", editor.map.groups[editor.selected_group]->clip_h, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {0}, - }; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - - // cut the properties that isn't needed - if(editor.get_selected_group()->game_group) - props[PROP_POS_X].name = 0; - - int prop = editor.do_properties(&view, props, ids, &new_val); - if(prop == PROP_ORDER) - editor.selected_group = editor.map.swap_groups(editor.selected_group, new_val); - - // these can not be changed on the game group - if(!editor.get_selected_group()->game_group) - { - if(prop == PROP_PARA_X) editor.map.groups[editor.selected_group]->parallax_x = new_val; - else if(prop == PROP_PARA_Y) editor.map.groups[editor.selected_group]->parallax_y = new_val; - else if(prop == PROP_POS_X) editor.map.groups[editor.selected_group]->offset_x = -new_val; - else if(prop == PROP_POS_Y) editor.map.groups[editor.selected_group]->offset_y = -new_val; - else if(prop == PROP_USE_CLIPPING) editor.map.groups[editor.selected_group]->use_clipping = new_val; - else if(prop == PROP_CLIP_X) editor.map.groups[editor.selected_group]->clip_x = new_val; - else if(prop == PROP_CLIP_Y) editor.map.groups[editor.selected_group]->clip_y = new_val; - else if(prop == PROP_CLIP_W) editor.map.groups[editor.selected_group]->clip_w = new_val; - else if(prop == PROP_CLIP_H) editor.map.groups[editor.selected_group]->clip_h = new_val; - } - - return 0; -} - -int popup_layer(RECT view) -{ - // remove layer button - RECT button; - ui_hsplit_b(&view, 12.0f, &view, &button); - static int delete_button = 0; - - // don't allow deletion of game layer - if(editor.map.game_layer != editor.get_selected_layer(0) && - do_editor_button(&delete_button, "Delete Layer", 0, &button, draw_editor_button, 0, "Deletes the layer")) - { - editor.map.groups[editor.selected_group]->delete_layer(editor.selected_layer); - return 1; - } - - ui_hsplit_b(&view, 10.0f, &view, 0); - - LAYERGROUP *current_group = editor.map.groups[editor.selected_group]; - LAYER *current_layer = editor.get_selected_layer(0); - - enum - { - PROP_GROUP=0, - PROP_ORDER, - PROP_HQ, - NUM_PROPS, - }; - - PROPERTY props[] = { - {"Group", editor.selected_group, PROPTYPE_INT_STEP, 0, editor.map.groups.len()-1}, - {"Order", editor.selected_layer, PROPTYPE_INT_STEP, 0, current_group->layers.len()}, - {"Detail", current_layer->flags&LAYERFLAG_DETAIL, PROPTYPE_BOOL, 0, 1}, - {0}, - }; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - int prop = editor.do_properties(&view, props, ids, &new_val); - - if(prop == PROP_ORDER) - editor.selected_layer = current_group->swap_layers(editor.selected_layer, new_val); - else if(prop == PROP_GROUP && current_layer->type != LAYERTYPE_GAME) - { - if(new_val >= 0 && new_val < editor.map.groups.len()) - { - current_group->layers.remove(current_layer); - editor.map.groups[new_val]->layers.add(current_layer); - editor.selected_group = new_val; - editor.selected_layer = editor.map.groups[new_val]->layers.len()-1; - } - } - else if(prop == PROP_HQ) - { - current_layer->flags &= ~LAYERFLAG_DETAIL; - if(new_val) - current_layer->flags |= LAYERFLAG_DETAIL; - } - - return current_layer->render_properties(&view); -} - -int popup_quad(RECT view) -{ - QUAD *quad = editor.get_selected_quad(); - - RECT button; - - // delete button - ui_hsplit_b(&view, 12.0f, &view, &button); - static int delete_button = 0; - if(do_editor_button(&delete_button, "Delete", 0, &button, draw_editor_button, 0, "Deletes the current quad")) - { - LAYER_QUADS *layer = (LAYER_QUADS *)editor.get_selected_layer_type(0, LAYERTYPE_QUADS); - if(layer) - { - layer->quads.removebyindex(editor.selected_quad); - editor.selected_quad--; - } - return 1; - } - - // square button - ui_hsplit_b(&view, 10.0f, &view, &button); - ui_hsplit_b(&view, 12.0f, &view, &button); - static int sq_button = 0; - if(do_editor_button(&sq_button, "Square", 0, &button, draw_editor_button, 0, "Squares the current quad")) - { - int top = quad->points[0].y; - int left = quad->points[0].x; - int bottom = quad->points[0].y; - int right = quad->points[0].x; - - for(int k = 1; k < 4; k++) - { - if(quad->points[k].y < top) top = quad->points[k].y; - if(quad->points[k].x < left) left = quad->points[k].x; - if(quad->points[k].y > bottom) bottom = quad->points[k].y; - if(quad->points[k].x > right) right = quad->points[k].x; - } - - quad->points[0].x = left; quad->points[0].y = top; - quad->points[1].x = right; quad->points[1].y = top; - quad->points[2].x = left; quad->points[2].y = bottom; - quad->points[3].x = right; quad->points[3].y = bottom; - return 1; - } - - - enum - { - PROP_POS_ENV=0, - PROP_POS_ENV_OFFSET, - PROP_COLOR_ENV, - PROP_COLOR_ENV_OFFSET, - NUM_PROPS, - }; - - PROPERTY props[] = { - {"Pos. Env", quad->pos_env, PROPTYPE_INT_STEP, -1, editor.map.envelopes.len()}, - {"Pos. TO", quad->pos_env_offset, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - {"Color Env", quad->color_env, PROPTYPE_INT_STEP, -1, editor.map.envelopes.len()}, - {"Color TO", quad->color_env_offset, PROPTYPE_INT_SCROLL, -1000000, 1000000}, - - {0}, - }; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - int prop = editor.do_properties(&view, props, ids, &new_val); - - if(prop == PROP_POS_ENV) quad->pos_env = clamp(new_val, -1, editor.map.envelopes.len()-1); - if(prop == PROP_POS_ENV_OFFSET) quad->pos_env_offset = new_val; - if(prop == PROP_COLOR_ENV) quad->color_env = clamp(new_val, -1, editor.map.envelopes.len()-1); - if(prop == PROP_COLOR_ENV_OFFSET) quad->color_env_offset = new_val; - - return 0; -} - -int popup_point(RECT view) -{ - QUAD *quad = editor.get_selected_quad(); - - enum - { - PROP_COLOR=0, - NUM_PROPS, - }; - - int color = 0; - - for(int v = 0; v < 4; v++) - { - if(editor.selected_points&(1<colors[v].r<<24; - color |= quad->colors[v].g<<16; - color |= quad->colors[v].b<<8; - color |= quad->colors[v].a; - } - } - - - PROPERTY props[] = { - {"Color", color, PROPTYPE_COLOR, -1, editor.map.envelopes.len()}, - {0}, - }; - - static int ids[NUM_PROPS] = {0}; - int new_val = 0; - int prop = editor.do_properties(&view, props, ids, &new_val); - if(prop == PROP_COLOR) - { - for(int v = 0; v < 4; v++) - { - if(editor.selected_points&(1<colors[v].r = (new_val>>24)&0xff; - quad->colors[v].g = (new_val>>16)&0xff; - quad->colors[v].b = (new_val>>8)&0xff; - quad->colors[v].a = new_val&0xff; - } - } - } - - return 0; -} - - - -static int select_image_selected = -100; -static int select_image_current = -100; - -int popup_select_image(RECT view) -{ - RECT buttonbar, imageview; - ui_vsplit_l(&view, 80.0f, &buttonbar, &view); - ui_margin(&view, 10.0f, &imageview); - - int show_image = select_image_current; - - for(int i = -1; i < editor.map.images.len(); i++) - { - RECT button; - ui_hsplit_t(&buttonbar, 12.0f, &button, &buttonbar); - ui_hsplit_t(&buttonbar, 2.0f, 0, &buttonbar); - - if(ui_mouse_inside(&button)) - show_image = i; - - if(i == -1) - { - if(do_editor_button(&editor.map.images[i], "None", i==select_image_current, &button, draw_editor_button_menuitem, 0, 0)) - select_image_selected = -1; - } - else - { - if(do_editor_button(&editor.map.images[i], editor.map.images[i]->name, i==select_image_current, &button, draw_editor_button_menuitem, 0, 0)) - select_image_selected = i; - } - } - - if(show_image >= 0 && show_image < editor.map.images.len()) - gfx_texture_set(editor.map.images[show_image]->tex_id); - else - gfx_texture_set(-1); - gfx_quads_begin(); - gfx_quads_drawTL(imageview.x, imageview.y, imageview.w, imageview.h); - gfx_quads_end(); - - return 0; -} - -void popup_select_image_invoke(int current, float x, float y) -{ - static int select_image_popup_id = 0; - select_image_selected = -100; - select_image_current = current; - ui_invoke_popup_menu(&select_image_popup_id, 0, x, y, 400, 300, popup_select_image); -} - -int popup_select_image_result() -{ - if(select_image_selected == -100) - return -100; - - select_image_current = select_image_selected; - select_image_selected = -100; - return select_image_current; -} - - - - - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/gamecore.cpp b/project/jni/application/teeworlds-0.5.2/src/game/gamecore.cpp deleted file mode 100644 index ceb63be3a..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/gamecore.cpp +++ /dev/null @@ -1,514 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "gamecore.hpp" - -const char *TUNING_PARAMS::names[] = -{ - #define MACRO_TUNING_PARAM(name,value) #name, - #include "tuning.hpp" - #undef MACRO_TUNING_PARAM -}; - - -bool TUNING_PARAMS::set(int index, float value) -{ - if(index < 0 || index >= num()) - return false; - ((tune_param *)this)[index] = value; - return true; -} - -bool TUNING_PARAMS::get(int index, float *value) -{ - if(index < 0 || index >= num()) - return false; - *value = (float)((tune_param *)this)[index]; - return true; -} - -bool TUNING_PARAMS::set(const char *name, float value) -{ - for(int i = 0; i < num(); i++) - if(strcmp(name, names[i]) == 0) - return set(i, value); - return false; -} - -bool TUNING_PARAMS::get(const char *name, float *value) -{ - for(int i = 0; i < num(); i++) - if(strcmp(name, names[i]) == 0) - return get(i, value); - - return false; -} - -// TODO: OPT: rewrite this smarter! -void move_point(vec2 *inout_pos, vec2 *inout_vel, float elasticity, int *bounces) -{ - if(bounces) - *bounces = 0; - - vec2 pos = *inout_pos; - vec2 vel = *inout_vel; - if(col_check_point(pos + vel)) - { - int affected = 0; - if(col_check_point(pos.x + vel.x, pos.y)) - { - inout_vel->x *= -elasticity; - if(bounces) - (*bounces)++; - affected++; - } - - if(col_check_point(pos.x, pos.y + vel.y)) - { - inout_vel->y *= -elasticity; - if(bounces) - (*bounces)++; - affected++; - } - - if(affected == 0) - { - inout_vel->x *= -elasticity; - inout_vel->y *= -elasticity; - } - } - else - { - *inout_pos = pos + vel; - } -} - -bool test_box(vec2 pos, vec2 size) -{ - size *= 0.5f; - if(col_check_point(pos.x-size.x, pos.y-size.y)) - return true; - if(col_check_point(pos.x+size.x, pos.y-size.y)) - return true; - if(col_check_point(pos.x-size.x, pos.y+size.y)) - return true; - if(col_check_point(pos.x+size.x, pos.y+size.y)) - return true; - return false; -} - -void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity) -{ - // do the move - vec2 pos = *inout_pos; - vec2 vel = *inout_vel; - - float distance = length(vel); - int max = (int)distance; - - if(distance > 0.00001f) - { - //vec2 old_pos = pos; - float fraction = 1.0f/(float)(max+1); - for(int i = 0; i <= max; i++) - { - //float amount = i/(float)max; - //if(max == 0) - //amount = 0; - - vec2 new_pos = pos + vel*fraction; // TODO: this row is not nice - - if(test_box(vec2(new_pos.x, new_pos.y), size)) - { - int hits = 0; - - if(test_box(vec2(pos.x, new_pos.y), size)) - { - new_pos.y = pos.y; - vel.y *= -elasticity; - hits++; - } - - if(test_box(vec2(new_pos.x, pos.y), size)) - { - new_pos.x = pos.x; - vel.x *= -elasticity; - hits++; - } - - // neither of the tests got a collision. - // this is a real _corner case_! - if(hits == 0) - { - new_pos.y = pos.y; - vel.y *= -elasticity; - new_pos.x = pos.x; - vel.x *= -elasticity; - } - } - - pos = new_pos; - } - } - - *inout_pos = pos; - *inout_vel = vel; -} - -float hermite_basis1(float v) -{ - return 2*v*v*v - 3*v*v+1; -} - -float velocity_ramp(float value, float start, float range, float curvature) -{ - if(value < start) - return 1.0f; - return 1.0f/pow(curvature, (value-start)/range); -} - -void CHARACTER_CORE::reset() -{ - pos = vec2(0,0); - vel = vec2(0,0); - hook_pos = vec2(0,0); - hook_dir = vec2(0,0); - hook_tick = 0; - hook_state = HOOK_IDLE; - hooked_player = -1; - jumped = 0; - triggered_events = 0; -} - -void CHARACTER_CORE::tick(bool use_input) -{ - float phys_size = 28.0f; - triggered_events = 0; - - // get ground state - bool grounded = false; - if(col_check_point(pos.x+phys_size/2, pos.y+phys_size/2+5)) - grounded = true; - if(col_check_point(pos.x-phys_size/2, pos.y+phys_size/2+5)) - grounded = true; - - vec2 target_direction = normalize(vec2(input.target_x, input.target_y)); - - vel.y += world->tuning.gravity; - - float max_speed = grounded ? world->tuning.ground_control_speed : world->tuning.air_control_speed; - float accel = grounded ? world->tuning.ground_control_accel : world->tuning.air_control_accel; - float friction = grounded ? world->tuning.ground_friction : world->tuning.air_friction; - - // handle input - if(use_input) - { - direction = input.direction; - - // setup angle - float a = 0; - if(input.target_x == 0) - a = atan((float)input.target_y); - else - a = atan((float)input.target_y/(float)input.target_x); - - if(input.target_x < 0) - a = a+pi; - - angle = (int)(a*256.0f); - - // handle jump - if(input.jump) - { - if(!(jumped&1)) - { - if(grounded) - { - triggered_events |= COREEVENT_GROUND_JUMP; - vel.y = -world->tuning.ground_jump_impulse; - jumped |= 1; - } - else if(!(jumped&2)) - { - triggered_events |= COREEVENT_AIR_JUMP; - vel.y = -world->tuning.air_jump_impulse; - jumped |= 3; - } - } - } - else - jumped &= ~1; - - // handle hook - if(input.hook) - { - if(hook_state == HOOK_IDLE) - { - hook_state = HOOK_FLYING; - hook_pos = pos+target_direction*phys_size*1.5f; - hook_dir = target_direction; - hooked_player = -1; - hook_tick = 0; - triggered_events |= COREEVENT_HOOK_LAUNCH; - } - } - else - { - hooked_player = -1; - hook_state = HOOK_IDLE; - hook_pos = pos; - } - } - - // add the speed modification according to players wanted direction - if(direction < 0) - vel.x = saturated_add(-max_speed, max_speed, vel.x, -accel); - if(direction > 0) - vel.x = saturated_add(-max_speed, max_speed, vel.x, accel); - if(direction == 0) - vel.x *= friction; - - // handle jumping - // 1 bit = to keep track if a jump has been made on this input - // 2 bit = to keep track if a air-jump has been made - if(grounded) - jumped &= ~2; - - // do hook - if(hook_state == HOOK_IDLE) - { - hooked_player = -1; - hook_state = HOOK_IDLE; - hook_pos = pos; - } - else if(hook_state >= HOOK_RETRACT_START && hook_state < HOOK_RETRACT_END) - { - hook_state++; - } - else if(hook_state == HOOK_RETRACT_END) - { - hook_state = HOOK_RETRACTED; - triggered_events |= COREEVENT_HOOK_RETRACT; - hook_state = HOOK_RETRACTED; - } - else if(hook_state == HOOK_FLYING) - { - vec2 new_pos = hook_pos+hook_dir*world->tuning.hook_fire_speed; - if(distance(pos, new_pos) > world->tuning.hook_length) - { - hook_state = HOOK_RETRACT_START; - new_pos = pos + normalize(new_pos-pos) * world->tuning.hook_length; - } - - // make sure that the hook doesn't go though the ground - bool going_to_hit_ground = false; - bool going_to_retract = false; - int hit = col_intersect_line(hook_pos, new_pos, &new_pos, 0); - if(hit) - { - if(hit&COLFLAG_NOHOOK) - going_to_retract = true; - else - going_to_hit_ground = true; - } - - // Check against other players first - if(world && world->tuning.player_hooking) - { - float dist = 0.0f; - for(int i = 0; i < MAX_CLIENTS; i++) - { - CHARACTER_CORE *p = world->characters[i]; - if(!p || p == this) - continue; - - vec2 closest_point = closest_point_on_line(hook_pos, new_pos, p->pos); - if(distance(p->pos, closest_point) < phys_size+2.0f) - { - if (hooked_player == -1 || distance (hook_pos, p->pos) < dist) - { - triggered_events |= COREEVENT_HOOK_ATTACH_PLAYER; - hook_state = HOOK_GRABBED; - hooked_player = i; - dist = distance (hook_pos, p->pos); - } - } - } - } - - if(hook_state == HOOK_FLYING) - { - // check against ground - if(going_to_hit_ground) - { - triggered_events |= COREEVENT_HOOK_ATTACH_GROUND; - hook_state = HOOK_GRABBED; - } - else if(going_to_retract) - { - triggered_events |= COREEVENT_HOOK_HIT_NOHOOK; - hook_state = HOOK_RETRACT_START; - } - - hook_pos = new_pos; - } - } - - if(hook_state == HOOK_GRABBED) - { - if(hooked_player != -1) - { - CHARACTER_CORE *p = world->characters[hooked_player]; - if(p) - hook_pos = p->pos; - else - { - // release hook - hooked_player = -1; - hook_state = HOOK_RETRACTED; - hook_pos = pos; - } - - // keep players hooked for a max of 1.5sec - //if(server_tick() > hook_tick+(server_tickspeed()*3)/2) - //release_hooked(); - } - - // don't do this hook rutine when we are hook to a player - if(hooked_player == -1 && distance(hook_pos, pos) > 46.0f) - { - vec2 hookvel = normalize(hook_pos-pos)*world->tuning.hook_drag_accel; - // the hook as more power to drag you up then down. - // this makes it easier to get on top of an platform - if(hookvel.y > 0) - hookvel.y *= 0.3f; - - // the hook will boost it's power if the player wants to move - // in that direction. otherwise it will dampen everything abit - if((hookvel.x < 0 && direction < 0) || (hookvel.x > 0 && direction > 0)) - hookvel.x *= 0.95f; - else - hookvel.x *= 0.75f; - - vec2 new_vel = vel+hookvel; - - // check if we are under the legal limit for the hook - if(length(new_vel) < world->tuning.hook_drag_speed || length(new_vel) < length(vel)) - vel = new_vel; // no problem. apply - - } - - // release hook (max hook time is 1.25 - hook_tick++; - if(hooked_player != -1 && (hook_tick > SERVER_TICK_SPEED+SERVER_TICK_SPEED/5 || !world->characters[hooked_player])) - { - hooked_player = -1; - hook_state = HOOK_RETRACTED; - hook_pos = pos; - } - } - - if(world && world->tuning.player_collision) - { - for(int i = 0; i < MAX_CLIENTS; i++) - { - CHARACTER_CORE *p = world->characters[i]; - if(!p) - continue; - - //player *p = (player*)ent; - if(p == this) // || !(p->flags&FLAG_ALIVE) - continue; // make sure that we don't nudge our self - - // handle player <-> player collision - float d = distance(pos, p->pos); - vec2 dir = normalize(pos - p->pos); - if(d < phys_size*1.25f && d > 1.0f) - { - float a = (phys_size*1.45f - d); - - // make sure that we don't add excess force by checking the - // direction against the current velocity - vec2 veldir = normalize(vel); - float v = 1-(dot(veldir, dir)+1)/2; - vel = vel + dir*a*(v*0.75f); - vel = vel * 0.85f; - } - - // handle hook influence - if(hooked_player == i) - { - if(d > phys_size*1.50f) // TODO: fix tweakable variable - { - float accel = world->tuning.hook_drag_accel * (d/world->tuning.hook_length); - float drag_speed = world->tuning.hook_drag_speed; - - // add force to the hooked player - p->vel.x = saturated_add(-drag_speed, drag_speed, p->vel.x, accel*dir.x*1.5f); - p->vel.y = saturated_add(-drag_speed, drag_speed, p->vel.y, accel*dir.y*1.5f); - - // add a little bit force to the guy who has the grip - vel.x = saturated_add(-drag_speed, drag_speed, vel.x, -accel*dir.x*0.25f); - vel.y = saturated_add(-drag_speed, drag_speed, vel.y, -accel*dir.y*0.25f); - } - } - } - } - - // clamp the velocity to something sane - if(length(vel) > 6000) - vel = normalize(vel) * 6000; -} - -void CHARACTER_CORE::move() -{ - float rampvalue = velocity_ramp(length(vel)*50, world->tuning.velramp_start, world->tuning.velramp_range, world->tuning.velramp_curvature); - - vel.x = vel.x*rampvalue; - move_box(&pos, &vel, vec2(28.0f, 28.0f), 0); - vel.x = vel.x*(1.0f/rampvalue); -} - -void CHARACTER_CORE::write(NETOBJ_CHARACTER_CORE *obj_core) -{ - obj_core->x = round(pos.x); - obj_core->y = round(pos.y); - - obj_core->vx = round(vel.x*256.0f); - obj_core->vy = round(vel.y*256.0f); - obj_core->hook_state = hook_state; - obj_core->hook_tick = hook_tick; - obj_core->hook_x = round(hook_pos.x); - obj_core->hook_y = round(hook_pos.y); - obj_core->hook_dx = round(hook_dir.x*256.0f); - obj_core->hook_dy = round(hook_dir.y*256.0f); - obj_core->hooked_player = hooked_player; - obj_core->jumped = jumped; - obj_core->direction = direction; - obj_core->angle = angle; -} - -void CHARACTER_CORE::read(const NETOBJ_CHARACTER_CORE *obj_core) -{ - pos.x = obj_core->x; - pos.y = obj_core->y; - vel.x = obj_core->vx/256.0f; - vel.y = obj_core->vy/256.0f; - hook_state = obj_core->hook_state; - hook_tick = obj_core->hook_tick; - hook_pos.x = obj_core->hook_x; - hook_pos.y = obj_core->hook_y; - hook_dir.x = obj_core->hook_dx/256.0f; - hook_dir.y = obj_core->hook_dy/256.0f; - hooked_player = obj_core->hooked_player; - jumped = obj_core->jumped; - direction = obj_core->direction; - angle = obj_core->angle; -} - -void CHARACTER_CORE::quantize() -{ - NETOBJ_CHARACTER_CORE c; - write(&c); - read(&c); -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/gamecore.hpp b/project/jni/application/teeworlds-0.5.2/src/game/gamecore.hpp deleted file mode 100644 index 2734820c8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/gamecore.hpp +++ /dev/null @@ -1,200 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef GAME_GAME_H -#define GAME_GAME_H - -#include -#include - -#include -#include -#include "collision.hpp" -#include - -struct TUNING_PARAMS -{ - TUNING_PARAMS() - { - const float ticks_per_second = 50.0f; - #define MACRO_TUNING_PARAM(name,value) name.set((int)(value*100.0f)); - #include "tuning.hpp" - #undef MACRO_TUNING_PARAM - } - - static const char *names[]; - - #define MACRO_TUNING_PARAM(name,value) tune_param name; - #include "tuning.hpp" - #undef MACRO_TUNING_PARAM - - static int num() { return sizeof(TUNING_PARAMS)/sizeof(int); } - bool set(int index, float value); - bool set(const char *name, float value); - bool get(int index, float *value); - bool get(const char *name, float *value); -}; - - -inline vec2 get_direction(int angle) -{ - float a = angle/256.0f; - return vec2(cosf(a), sinf(a)); -} - -inline vec2 get_dir(float a) -{ - return vec2(cosf(a), sinf(a)); -} - -inline float get_angle(vec2 dir) -{ - float a = atan(dir.y/dir.x); - if(dir.x < 0) - a = a+pi; - return a; -} - -inline void str_to_ints(int *ints, int num, const char *str) -{ - int index = 0; - while(num) - { - char buf[4] = {0,0,0,0}; - for(int c = 0; c < 4 && str[index]; c++, index++) - buf[c] = str[index]; - *ints = ((buf[0]+128)<<24)|((buf[1]+128)<<16)|((buf[2]+128)<<8)|(buf[3]+128); - ints++; - num--; - } - - // null terminate - ints[-1] &= 0xffffff00; -} - -inline void ints_to_str(const int *ints, int num, char *str) -{ - while(num) - { - str[0] = (((*ints)>>24)&0xff)-128; - str[1] = (((*ints)>>16)&0xff)-128; - str[2] = (((*ints)>>8)&0xff)-128; - str[3] = ((*ints)&0xff)-128; - str += 4; - ints++; - num--; - } - - // null terminate - str[-1] = 0; -} - - - -inline vec2 calc_pos(vec2 p, vec2 v, float curvature, float speed, float t) -{ - vec2 n; - t *= speed; - n.x = p.x + v.x*t; - n.y = p.y + v.y*t + curvature/10000*(t*t); - return n; -} - - -template -inline T saturated_add(T min, T max, T current, T modifier) -{ - if(modifier < 0) - { - if(current < min) - return current; - current += modifier; - if(current < min) - current = min; - return current; - } - else - { - if(current > max) - return current; - current += modifier; - if(current > max) - current = max; - return current; - } -} - -void move_point(vec2 *inout_pos, vec2 *inout_vel, float elasticity, int *bounces); -void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity); -bool test_box(vec2 pos, vec2 size); -float velocity_ramp(float value, float start, float range, float curvature); - -// hooking stuff -enum -{ - HOOK_RETRACTED=-1, - HOOK_IDLE=0, - HOOK_RETRACT_START=1, - HOOK_RETRACT_END=3, - HOOK_FLYING, - HOOK_GRABBED, - - COREEVENT_GROUND_JUMP=0x01, - COREEVENT_AIR_JUMP=0x02, - COREEVENT_HOOK_LAUNCH=0x04, - COREEVENT_HOOK_ATTACH_PLAYER=0x08, - COREEVENT_HOOK_ATTACH_GROUND=0x10, - COREEVENT_HOOK_HIT_NOHOOK=0x20, - COREEVENT_HOOK_RETRACT=0x40, -}; - -class WORLD_CORE -{ -public: - WORLD_CORE() - { - mem_zero(characters, sizeof(characters)); - } - - TUNING_PARAMS tuning; - class CHARACTER_CORE *characters[MAX_CLIENTS]; -}; - -class CHARACTER_CORE -{ -public: - WORLD_CORE *world; - - vec2 pos; - vec2 vel; - - vec2 hook_pos; - vec2 hook_dir; - int hook_tick; - int hook_state; - int hooked_player; - - int jumped; - - int direction; - int angle; - NETOBJ_PLAYER_INPUT input; - - int triggered_events; - - void reset(); - void tick(bool use_input); - void move(); - - void read(const NETOBJ_CHARACTER_CORE *obj_core); - void write(NETOBJ_CHARACTER_CORE *obj_core); - void quantize(); -}; - - -#define LERP(a,b,t) (a + (b-a) * t) -#define min(a, b) ( a > b ? b : a) -#define max(a, b) ( a > b ? a : b) - -inline bool col_check_point(float x, float y) { return col_is_solid(round(x), round(y)) != 0; } -inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); } - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/createdir.txt b/project/jni/application/teeworlds-0.5.2/src/game/generated/createdir.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.cpp b/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.cpp deleted file mode 100644 index 75348b7cd..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.cpp +++ /dev/null @@ -1,528 +0,0 @@ -#include -#include "g_protocol.hpp" -const char *msg_failed_on = ""; -const char *obj_corrected_on = ""; -static int num_corrections = 0; -int netobj_num_corrections() { return num_corrections; } -const char *netobj_corrected_on() { return obj_corrected_on; } -const char *netmsg_failed_on() { return msg_failed_on; } -const int max_int = 0x7fffffff; -static int netobj_clamp_int(const char *error_msg, int v, int min, int max) -{ - if(vmax) { obj_corrected_on = error_msg; num_corrections++; return max; } - return v; -} -static const char *netobj_names[] = { - "invalid", - "player_input", - "projectile", - "laser", - "pickup", - "flag", - "game", - "character_core", - "character", - "player_info", - "client_info", - "common", - "explosion", - "spawn", - "hammerhit", - "death", - "soundglobal", - "soundworld", - "damageind", - "" -}; - -static int netobj_sizes[] = { - 0, - sizeof(NETOBJ_PLAYER_INPUT), - sizeof(NETOBJ_PROJECTILE), - sizeof(NETOBJ_LASER), - sizeof(NETOBJ_PICKUP), - sizeof(NETOBJ_FLAG), - sizeof(NETOBJ_GAME), - sizeof(NETOBJ_CHARACTER_CORE), - sizeof(NETOBJ_CHARACTER), - sizeof(NETOBJ_PLAYER_INFO), - sizeof(NETOBJ_CLIENT_INFO), - sizeof(NETEVENT_COMMON), - sizeof(NETEVENT_EXPLOSION), - sizeof(NETEVENT_SPAWN), - sizeof(NETEVENT_HAMMERHIT), - sizeof(NETEVENT_DEATH), - sizeof(NETEVENT_SOUNDGLOBAL), - sizeof(NETEVENT_SOUNDWORLD), - sizeof(NETEVENT_DAMAGEIND), - 0 -}; - -static int validate_player_input(void *data, int size) -{ - NETOBJ_PLAYER_INPUT *obj = (NETOBJ_PLAYER_INPUT *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("player_state", obj->player_state, 0, 4); - return 0; -} - -static int validate_projectile(void *data, int size) -{ - NETOBJ_PROJECTILE *obj = (NETOBJ_PROJECTILE *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("type", obj->type, 0, NUM_WEAPONS-1); - netobj_clamp_int("start_tick", obj->start_tick, 0, max_int); - return 0; -} - -static int validate_laser(void *data, int size) -{ - NETOBJ_LASER *obj = (NETOBJ_LASER *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("start_tick", obj->start_tick, 0, max_int); - return 0; -} - -static int validate_pickup(void *data, int size) -{ - NETOBJ_PICKUP *obj = (NETOBJ_PICKUP *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("type", obj->type, 0, max_int); - netobj_clamp_int("subtype", obj->subtype, 0, max_int); - return 0; -} - -static int validate_flag(void *data, int size) -{ - NETOBJ_FLAG *obj = (NETOBJ_FLAG *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("team", obj->team, 0, 1); - netobj_clamp_int("carried_by", obj->carried_by, -2, MAX_CLIENTS-1); - return 0; -} - -static int validate_game(void *data, int size) -{ - NETOBJ_GAME *obj = (NETOBJ_GAME *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("flags", obj->flags, 0, 256); - netobj_clamp_int("round_start_tick", obj->round_start_tick, 0, max_int); - netobj_clamp_int("game_over", obj->game_over, 0, 1); - netobj_clamp_int("sudden_death", obj->sudden_death, 0, 1); - netobj_clamp_int("paused", obj->paused, 0, 1); - netobj_clamp_int("score_limit", obj->score_limit, 0, max_int); - netobj_clamp_int("time_limit", obj->time_limit, 0, max_int); - netobj_clamp_int("warmup", obj->warmup, 0, max_int); - netobj_clamp_int("round_num", obj->round_num, 0, max_int); - netobj_clamp_int("round_current", obj->round_current, 0, max_int); - return 0; -} - -static int validate_character_core(void *data, int size) -{ - NETOBJ_CHARACTER_CORE *obj = (NETOBJ_CHARACTER_CORE *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("direction", obj->direction, -1, 1); - netobj_clamp_int("jumped", obj->jumped, 0, 3); - netobj_clamp_int("hooked_player", obj->hooked_player, 0, MAX_CLIENTS-1); - netobj_clamp_int("hook_state", obj->hook_state, -1, 5); - netobj_clamp_int("hook_tick", obj->hook_tick, 0, max_int); - return 0; -} - -static int validate_character(void *data, int size) -{ - NETOBJ_CHARACTER *obj = (NETOBJ_CHARACTER *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("player_state", obj->player_state, 0, NUM_PLAYERSTATES-1); - netobj_clamp_int("health", obj->health, 0, 10); - netobj_clamp_int("armor", obj->armor, 0, 10); - netobj_clamp_int("ammocount", obj->ammocount, 0, 10); - netobj_clamp_int("weapon", obj->weapon, 0, NUM_WEAPONS-1); - netobj_clamp_int("emote", obj->emote, 0, 6); - netobj_clamp_int("attacktick", obj->attacktick, 0, max_int); - return 0; -} - -static int validate_player_info(void *data, int size) -{ - NETOBJ_PLAYER_INFO *obj = (NETOBJ_PLAYER_INFO *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("local", obj->local, 0, 1); - netobj_clamp_int("cid", obj->cid, 0, MAX_CLIENTS-1); - netobj_clamp_int("team", obj->team, -1, 1); - return 0; -} - -static int validate_client_info(void *data, int size) -{ - NETOBJ_CLIENT_INFO *obj = (NETOBJ_CLIENT_INFO *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("use_custom_color", obj->use_custom_color, 0, 1); - return 0; -} - -static int validate_common(void *data, int size) -{ - NETEVENT_COMMON *obj = (NETEVENT_COMMON *)data; - if(sizeof(*obj) != size) return -1; - return 0; -} - -static int validate_explosion(void *data, int size) -{ - NETEVENT_EXPLOSION *obj = (NETEVENT_EXPLOSION *)data; - if(sizeof(*obj) != size) return -1; - return 0; -} - -static int validate_spawn(void *data, int size) -{ - NETEVENT_SPAWN *obj = (NETEVENT_SPAWN *)data; - if(sizeof(*obj) != size) return -1; - return 0; -} - -static int validate_hammerhit(void *data, int size) -{ - NETEVENT_HAMMERHIT *obj = (NETEVENT_HAMMERHIT *)data; - if(sizeof(*obj) != size) return -1; - return 0; -} - -static int validate_death(void *data, int size) -{ - NETEVENT_DEATH *obj = (NETEVENT_DEATH *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("cid", obj->cid, 0, MAX_CLIENTS-1); - return 0; -} - -static int validate_soundglobal(void *data, int size) -{ - NETEVENT_SOUNDGLOBAL *obj = (NETEVENT_SOUNDGLOBAL *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("soundid", obj->soundid, 0, NUM_SOUNDS-1); - return 0; -} - -static int validate_soundworld(void *data, int size) -{ - NETEVENT_SOUNDWORLD *obj = (NETEVENT_SOUNDWORLD *)data; - if(sizeof(*obj) != size) return -1; - netobj_clamp_int("soundid", obj->soundid, 0, NUM_SOUNDS-1); - return 0; -} - -static int validate_damageind(void *data, int size) -{ - NETEVENT_DAMAGEIND *obj = (NETEVENT_DAMAGEIND *)data; - if(sizeof(*obj) != size) return -1; - return 0; -} - -static void *secure_unpack_sv_motd() -{ - static NETMSG_SV_MOTD msg; - msg.message = msg_unpack_string(); - return &msg; -} - -static void *secure_unpack_sv_broadcast() -{ - static NETMSG_SV_BROADCAST msg; - msg.message = msg_unpack_string(); - return &msg; -} - -static void *secure_unpack_sv_chat() -{ - static NETMSG_SV_CHAT msg; - msg.team = msg_unpack_int(); - msg.cid = msg_unpack_int(); - msg.message = msg_unpack_string(); - if(msg.team < -1 || msg.team > 1) { msg_failed_on = "team"; return 0; } - if(msg.cid < -1 || msg.cid > MAX_CLIENTS-1) { msg_failed_on = "cid"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_killmsg() -{ - static NETMSG_SV_KILLMSG msg; - msg.killer = msg_unpack_int(); - msg.victim = msg_unpack_int(); - msg.weapon = msg_unpack_int(); - msg.mode_special = msg_unpack_int(); - if(msg.killer < 0 || msg.killer > MAX_CLIENTS-1) { msg_failed_on = "killer"; return 0; } - if(msg.victim < 0 || msg.victim > MAX_CLIENTS-1) { msg_failed_on = "victim"; return 0; } - if(msg.weapon < -3 || msg.weapon > NUM_WEAPONS-1) { msg_failed_on = "weapon"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_soundglobal() -{ - static NETMSG_SV_SOUNDGLOBAL msg; - msg.soundid = msg_unpack_int(); - if(msg.soundid < 0 || msg.soundid > NUM_SOUNDS-1) { msg_failed_on = "soundid"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_tuneparams() -{ - static NETMSG_SV_TUNEPARAMS msg; - return &msg; -} - -static void *secure_unpack_sv_extraprojectile() -{ - static NETMSG_SV_EXTRAPROJECTILE msg; - return &msg; -} - -static void *secure_unpack_sv_readytoenter() -{ - static NETMSG_SV_READYTOENTER msg; - return &msg; -} - -static void *secure_unpack_sv_weaponpickup() -{ - static NETMSG_SV_WEAPONPICKUP msg; - msg.weapon = msg_unpack_int(); - if(msg.weapon < 0 || msg.weapon > NUM_WEAPONS-1) { msg_failed_on = "weapon"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_emoticon() -{ - static NETMSG_SV_EMOTICON msg; - msg.cid = msg_unpack_int(); - msg.emoticon = msg_unpack_int(); - if(msg.cid < 0 || msg.cid > MAX_CLIENTS-1) { msg_failed_on = "cid"; return 0; } - if(msg.emoticon < 0 || msg.emoticon > NUM_EMOTICONS-1) { msg_failed_on = "emoticon"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_vote_clearoptions() -{ - static NETMSG_SV_VOTE_CLEAROPTIONS msg; - return &msg; -} - -static void *secure_unpack_sv_vote_option() -{ - static NETMSG_SV_VOTE_OPTION msg; - msg.command = msg_unpack_string(); - return &msg; -} - -static void *secure_unpack_sv_vote_set() -{ - static NETMSG_SV_VOTE_SET msg; - msg.timeout = msg_unpack_int(); - msg.description = msg_unpack_string(); - msg.command = msg_unpack_string(); - if(msg.timeout < 0 || msg.timeout > 60) { msg_failed_on = "timeout"; return 0; } - return &msg; -} - -static void *secure_unpack_sv_vote_status() -{ - static NETMSG_SV_VOTE_STATUS msg; - msg.yes = msg_unpack_int(); - msg.no = msg_unpack_int(); - msg.pass = msg_unpack_int(); - msg.total = msg_unpack_int(); - if(msg.yes < 0 || msg.yes > MAX_CLIENTS) { msg_failed_on = "yes"; return 0; } - if(msg.no < 0 || msg.no > MAX_CLIENTS) { msg_failed_on = "no"; return 0; } - if(msg.pass < 0 || msg.pass > MAX_CLIENTS) { msg_failed_on = "pass"; return 0; } - if(msg.total < 0 || msg.total > MAX_CLIENTS) { msg_failed_on = "total"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_say() -{ - static NETMSG_CL_SAY msg; - msg.team = msg_unpack_int(); - msg.message = msg_unpack_string(); - if(msg.team < 0 || msg.team > 1) { msg_failed_on = "team"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_setteam() -{ - static NETMSG_CL_SETTEAM msg; - msg.team = msg_unpack_int(); - if(msg.team < -1 || msg.team > 1) { msg_failed_on = "team"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_startinfo() -{ - static NETMSG_CL_STARTINFO msg; - msg.name = msg_unpack_string(); - msg.skin = msg_unpack_string(); - msg.use_custom_color = msg_unpack_int(); - msg.color_body = msg_unpack_int(); - msg.color_feet = msg_unpack_int(); - if(msg.use_custom_color < 0 || msg.use_custom_color > 1) { msg_failed_on = "use_custom_color"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_changeinfo() -{ - static NETMSG_CL_CHANGEINFO msg; - msg.name = msg_unpack_string(); - msg.skin = msg_unpack_string(); - msg.use_custom_color = msg_unpack_int(); - msg.color_body = msg_unpack_int(); - msg.color_feet = msg_unpack_int(); - if(msg.use_custom_color < 0 || msg.use_custom_color > 1) { msg_failed_on = "use_custom_color"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_kill() -{ - static NETMSG_CL_KILL msg; - return &msg; -} - -static void *secure_unpack_cl_emoticon() -{ - static NETMSG_CL_EMOTICON msg; - msg.emoticon = msg_unpack_int(); - if(msg.emoticon < 0 || msg.emoticon > NUM_EMOTICONS-1) { msg_failed_on = "emoticon"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_vote() -{ - static NETMSG_CL_VOTE msg; - msg.vote = msg_unpack_int(); - if(msg.vote < -1 || msg.vote > 1) { msg_failed_on = "vote"; return 0; } - return &msg; -} - -static void *secure_unpack_cl_callvote() -{ - static NETMSG_CL_CALLVOTE msg; - msg.type = msg_unpack_string(); - msg.value = msg_unpack_string(); - return &msg; -} - -static int validate_invalid(void *data, int size) { return -1; } -typedef int(*VALIDATEFUNC)(void *data, int size); -static VALIDATEFUNC validate_funcs[] = { - validate_invalid, - validate_player_input, - validate_projectile, - validate_laser, - validate_pickup, - validate_flag, - validate_game, - validate_character_core, - validate_character, - validate_player_info, - validate_client_info, - validate_common, - validate_explosion, - validate_spawn, - validate_hammerhit, - validate_death, - validate_soundglobal, - validate_soundworld, - validate_damageind, - 0x0 -}; - -int netobj_validate(int type, void *data, int size) -{ - if(type < 0 || type >= NUM_NETOBJTYPES) return -1; - return validate_funcs[type](data, size); -}; - -const char *netobj_get_name(int type) -{ - if(type < 0 || type >= NUM_NETOBJTYPES) return "(out of range)"; - return netobj_names[type]; -}; - -int netobj_get_size(int type) -{ - if(type < 0 || type >= NUM_NETOBJTYPES) return 0; - return netobj_sizes[type]; -}; - -static void *secure_unpack_invalid() { return 0; } -typedef void *(*SECUREUNPACKFUNC)(); -static SECUREUNPACKFUNC secure_unpack_funcs[] = { - secure_unpack_invalid, - secure_unpack_sv_motd, - secure_unpack_sv_broadcast, - secure_unpack_sv_chat, - secure_unpack_sv_killmsg, - secure_unpack_sv_soundglobal, - secure_unpack_sv_tuneparams, - secure_unpack_sv_extraprojectile, - secure_unpack_sv_readytoenter, - secure_unpack_sv_weaponpickup, - secure_unpack_sv_emoticon, - secure_unpack_sv_vote_clearoptions, - secure_unpack_sv_vote_option, - secure_unpack_sv_vote_set, - secure_unpack_sv_vote_status, - secure_unpack_cl_say, - secure_unpack_cl_setteam, - secure_unpack_cl_startinfo, - secure_unpack_cl_changeinfo, - secure_unpack_cl_kill, - secure_unpack_cl_emoticon, - secure_unpack_cl_vote, - secure_unpack_cl_callvote, - 0x0 -}; -void *netmsg_secure_unpack(int type) -{ - void *msg; - msg_failed_on = ""; - if(type < 0 || type >= NUM_NETMSGTYPES) { msg_failed_on = "(type out of range)"; return 0; } - msg = secure_unpack_funcs[type](); - if(msg_unpack_error()) { msg_failed_on = "(unpack error)"; return 0; } - return msg; -}; - -static const char *message_names[] = { - "invalid", - "sv_motd", - "sv_broadcast", - "sv_chat", - "sv_killmsg", - "sv_soundglobal", - "sv_tuneparams", - "sv_extraprojectile", - "sv_readytoenter", - "sv_weaponpickup", - "sv_emoticon", - "sv_vote_clearoptions", - "sv_vote_option", - "sv_vote_set", - "sv_vote_status", - "cl_say", - "cl_setteam", - "cl_startinfo", - "cl_changeinfo", - "cl_kill", - "cl_emoticon", - "cl_vote", - "cl_callvote", - "" -}; - -const char *netmsg_get_name(int type) -{ - if(type < 0 || type >= NUM_NETMSGTYPES) return "(out of range)"; - return message_names[type]; -}; - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.hpp b/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.hpp deleted file mode 100644 index 55769a947..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/g_protocol.hpp +++ /dev/null @@ -1,613 +0,0 @@ -#ifndef FILE_G_PROTOCOL_H -#define FILE_G_PROTOCOL_H - -enum -{ - INPUT_STATE_MASK=0x3f, -}; - -enum -{ - PLAYERSTATE_UNKNOWN=0, - PLAYERSTATE_PLAYING, - PLAYERSTATE_IN_MENU, - PLAYERSTATE_CHATTING, - NUM_PLAYERSTATES -}; - -enum -{ - EMOTE_NORMAL=0, - EMOTE_PAIN, - EMOTE_HAPPY, - EMOTE_SURPRISE, - EMOTE_ANGRY, - EMOTE_BLINK, - NUM_EMOTES -}; - -enum -{ - POWERUP_HEALTH=0, - POWERUP_ARMOR, - POWERUP_WEAPON, - POWERUP_NINJA, - NUM_POWERUPS -}; - -enum -{ - EMOTICON_1=0, - EMOTICON_2, - EMOTICON_3, - EMOTICON_4, - EMOTICON_5, - EMOTICON_6, - EMOTICON_7, - EMOTICON_8, - EMOTICON_9, - EMOTICON_10, - EMOTICON_11, - EMOTICON_12, - EMOTICON_13, - EMOTICON_14, - EMOTICON_15, - NUM_EMOTICONS -}; - -enum -{ - GAMEFLAG_TEAMS = 1<<0, - GAMEFLAG_FLAGS = 1<<1, -}; - -enum -{ - NETOBJ_INVALID=0, - NETOBJTYPE_PLAYER_INPUT, - NETOBJTYPE_PROJECTILE, - NETOBJTYPE_LASER, - NETOBJTYPE_PICKUP, - NETOBJTYPE_FLAG, - NETOBJTYPE_GAME, - NETOBJTYPE_CHARACTER_CORE, - NETOBJTYPE_CHARACTER, - NETOBJTYPE_PLAYER_INFO, - NETOBJTYPE_CLIENT_INFO, - NETEVENTTYPE_COMMON, - NETEVENTTYPE_EXPLOSION, - NETEVENTTYPE_SPAWN, - NETEVENTTYPE_HAMMERHIT, - NETEVENTTYPE_DEATH, - NETEVENTTYPE_SOUNDGLOBAL, - NETEVENTTYPE_SOUNDWORLD, - NETEVENTTYPE_DAMAGEIND, - NUM_NETOBJTYPES -}; - -enum -{ - NETMSG_INVALID=0, - NETMSGTYPE_SV_MOTD, - NETMSGTYPE_SV_BROADCAST, - NETMSGTYPE_SV_CHAT, - NETMSGTYPE_SV_KILLMSG, - NETMSGTYPE_SV_SOUNDGLOBAL, - NETMSGTYPE_SV_TUNEPARAMS, - NETMSGTYPE_SV_EXTRAPROJECTILE, - NETMSGTYPE_SV_READYTOENTER, - NETMSGTYPE_SV_WEAPONPICKUP, - NETMSGTYPE_SV_EMOTICON, - NETMSGTYPE_SV_VOTE_CLEAROPTIONS, - NETMSGTYPE_SV_VOTE_OPTION, - NETMSGTYPE_SV_VOTE_SET, - NETMSGTYPE_SV_VOTE_STATUS, - NETMSGTYPE_CL_SAY, - NETMSGTYPE_CL_SETTEAM, - NETMSGTYPE_CL_STARTINFO, - NETMSGTYPE_CL_CHANGEINFO, - NETMSGTYPE_CL_KILL, - NETMSGTYPE_CL_EMOTICON, - NETMSGTYPE_CL_VOTE, - NETMSGTYPE_CL_CALLVOTE, - NUM_NETMSGTYPES -}; - -struct NETOBJ_PLAYER_INPUT -{ - int direction; - int target_x; - int target_y; - int jump; - int fire; - int hook; - int player_state; - int wanted_weapon; - int next_weapon; - int prev_weapon; -}; - -struct NETOBJ_PROJECTILE -{ - int x; - int y; - int vx; - int vy; - int type; - int start_tick; -}; - -struct NETOBJ_LASER -{ - int x; - int y; - int from_x; - int from_y; - int start_tick; -}; - -struct NETOBJ_PICKUP -{ - int x; - int y; - int type; - int subtype; -}; - -struct NETOBJ_FLAG -{ - int x; - int y; - int team; - int carried_by; -}; - -struct NETOBJ_GAME -{ - int flags; - int round_start_tick; - int game_over; - int sudden_death; - int paused; - int score_limit; - int time_limit; - int warmup; - int round_num; - int round_current; - int teamscore_red; - int teamscore_blue; -}; - -struct NETOBJ_CHARACTER_CORE -{ - int tick; - int x; - int y; - int vx; - int vy; - int angle; - int direction; - int jumped; - int hooked_player; - int hook_state; - int hook_tick; - int hook_x; - int hook_y; - int hook_dx; - int hook_dy; -}; - -struct NETOBJ_CHARACTER : public NETOBJ_CHARACTER_CORE -{ - int player_state; - int health; - int armor; - int ammocount; - int weapon; - int emote; - int attacktick; -}; - -struct NETOBJ_PLAYER_INFO -{ - int local; - int cid; - int team; - int score; - int latency; - int latency_flux; -}; - -struct NETOBJ_CLIENT_INFO -{ - int name0; - int name1; - int name2; - int name3; - int name4; - int name5; - int skin0; - int skin1; - int skin2; - int skin3; - int skin4; - int skin5; - int use_custom_color; - int color_body; - int color_feet; -}; - -struct NETEVENT_COMMON -{ - int x; - int y; -}; - -struct NETEVENT_EXPLOSION : public NETEVENT_COMMON -{ -}; - -struct NETEVENT_SPAWN : public NETEVENT_COMMON -{ -}; - -struct NETEVENT_HAMMERHIT : public NETEVENT_COMMON -{ -}; - -struct NETEVENT_DEATH : public NETEVENT_COMMON -{ - int cid; -}; - -struct NETEVENT_SOUNDGLOBAL : public NETEVENT_COMMON -{ - int soundid; -}; - -struct NETEVENT_SOUNDWORLD : public NETEVENT_COMMON -{ - int soundid; -}; - -struct NETEVENT_DAMAGEIND : public NETEVENT_COMMON -{ - int angle; -}; - -struct NETMSG_SV_MOTD -{ - const char *message; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_MOTD, flags); - msg_pack_string(message, -1); - msg_pack_end(); - } -}; - -struct NETMSG_SV_BROADCAST -{ - const char *message; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_BROADCAST, flags); - msg_pack_string(message, -1); - msg_pack_end(); - } -}; - -struct NETMSG_SV_CHAT -{ - int team; - int cid; - const char *message; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_CHAT, flags); - msg_pack_int(team); - msg_pack_int(cid); - msg_pack_string(message, -1); - msg_pack_end(); - } -}; - -struct NETMSG_SV_KILLMSG -{ - int killer; - int victim; - int weapon; - int mode_special; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_KILLMSG, flags); - msg_pack_int(killer); - msg_pack_int(victim); - msg_pack_int(weapon); - msg_pack_int(mode_special); - msg_pack_end(); - } -}; - -struct NETMSG_SV_SOUNDGLOBAL -{ - int soundid; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_SOUNDGLOBAL, flags); - msg_pack_int(soundid); - msg_pack_end(); - } -}; - -struct NETMSG_SV_TUNEPARAMS -{ - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_TUNEPARAMS, flags); - msg_pack_end(); - } -}; - -struct NETMSG_SV_EXTRAPROJECTILE -{ - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, flags); - msg_pack_end(); - } -}; - -struct NETMSG_SV_READYTOENTER -{ - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_READYTOENTER, flags); - msg_pack_end(); - } -}; - -struct NETMSG_SV_WEAPONPICKUP -{ - int weapon; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_WEAPONPICKUP, flags); - msg_pack_int(weapon); - msg_pack_end(); - } -}; - -struct NETMSG_SV_EMOTICON -{ - int cid; - int emoticon; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_EMOTICON, flags); - msg_pack_int(cid); - msg_pack_int(emoticon); - msg_pack_end(); - } -}; - -struct NETMSG_SV_VOTE_CLEAROPTIONS -{ - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_VOTE_CLEAROPTIONS, flags); - msg_pack_end(); - } -}; - -struct NETMSG_SV_VOTE_OPTION -{ - const char *command; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_VOTE_OPTION, flags); - msg_pack_string(command, -1); - msg_pack_end(); - } -}; - -struct NETMSG_SV_VOTE_SET -{ - int timeout; - const char *description; - const char *command; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_VOTE_SET, flags); - msg_pack_int(timeout); - msg_pack_string(description, -1); - msg_pack_string(command, -1); - msg_pack_end(); - } -}; - -struct NETMSG_SV_VOTE_STATUS -{ - int yes; - int no; - int pass; - int total; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_SV_VOTE_STATUS, flags); - msg_pack_int(yes); - msg_pack_int(no); - msg_pack_int(pass); - msg_pack_int(total); - msg_pack_end(); - } -}; - -struct NETMSG_CL_SAY -{ - int team; - const char *message; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_SAY, flags); - msg_pack_int(team); - msg_pack_string(message, -1); - msg_pack_end(); - } -}; - -struct NETMSG_CL_SETTEAM -{ - int team; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_SETTEAM, flags); - msg_pack_int(team); - msg_pack_end(); - } -}; - -struct NETMSG_CL_STARTINFO -{ - const char *name; - const char *skin; - int use_custom_color; - int color_body; - int color_feet; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_STARTINFO, flags); - msg_pack_string(name, -1); - msg_pack_string(skin, -1); - msg_pack_int(use_custom_color); - msg_pack_int(color_body); - msg_pack_int(color_feet); - msg_pack_end(); - } -}; - -struct NETMSG_CL_CHANGEINFO -{ - const char *name; - const char *skin; - int use_custom_color; - int color_body; - int color_feet; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_CHANGEINFO, flags); - msg_pack_string(name, -1); - msg_pack_string(skin, -1); - msg_pack_int(use_custom_color); - msg_pack_int(color_body); - msg_pack_int(color_feet); - msg_pack_end(); - } -}; - -struct NETMSG_CL_KILL -{ - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_KILL, flags); - msg_pack_end(); - } -}; - -struct NETMSG_CL_EMOTICON -{ - int emoticon; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_EMOTICON, flags); - msg_pack_int(emoticon); - msg_pack_end(); - } -}; - -struct NETMSG_CL_VOTE -{ - int vote; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_VOTE, flags); - msg_pack_int(vote); - msg_pack_end(); - } -}; - -struct NETMSG_CL_CALLVOTE -{ - const char *type; - const char *value; - void pack(int flags) - { - msg_pack_start(NETMSGTYPE_CL_CALLVOTE, flags); - msg_pack_string(type, -1); - msg_pack_string(value, -1); - msg_pack_end(); - } -}; - -enum -{ - SOUND_GUN_FIRE=0, - SOUND_SHOTGUN_FIRE, - SOUND_GRENADE_FIRE, - SOUND_HAMMER_FIRE, - SOUND_HAMMER_HIT, - SOUND_NINJA_FIRE, - SOUND_GRENADE_EXPLODE, - SOUND_NINJA_HIT, - SOUND_RIFLE_FIRE, - SOUND_RIFLE_BOUNCE, - SOUND_WEAPON_SWITCH, - SOUND_PLAYER_PAIN_SHORT, - SOUND_PLAYER_PAIN_LONG, - SOUND_BODY_LAND, - SOUND_PLAYER_AIRJUMP, - SOUND_PLAYER_JUMP, - SOUND_PLAYER_DIE, - SOUND_PLAYER_SPAWN, - SOUND_PLAYER_SKID, - SOUND_TEE_CRY, - SOUND_HOOK_LOOP, - SOUND_HOOK_ATTACH_GROUND, - SOUND_HOOK_ATTACH_PLAYER, - SOUND_HOOK_NOATTACH, - SOUND_PICKUP_HEALTH, - SOUND_PICKUP_ARMOR, - SOUND_PICKUP_GRENADE, - SOUND_PICKUP_SHOTGUN, - SOUND_PICKUP_NINJA, - SOUND_WEAPON_SPAWN, - SOUND_WEAPON_NOAMMO, - SOUND_HIT, - SOUND_CHAT_SERVER, - SOUND_CHAT_CLIENT, - SOUND_CTF_DROP, - SOUND_CTF_RETURN, - SOUND_CTF_GRAB_PL, - SOUND_CTF_GRAB_EN, - SOUND_CTF_CAPTURE, - NUM_SOUNDS -}; -enum -{ - WEAPON_HAMMER=0, - WEAPON_GUN, - WEAPON_SHOTGUN, - WEAPON_GRENADE, - WEAPON_RIFLE, - WEAPON_NINJA, - NUM_WEAPONS -}; -int netobj_validate(int type, void *data, int size); -const char *netobj_get_name(int type); -int netobj_get_size(int type); -void *netmsg_secure_unpack(int type); -const char *netmsg_get_name(int type); -const char *netmsg_failed_on(); -int netobj_num_corrections(); -const char *netobj_corrected_on(); -#endif // FILE_G_PROTOCOL_H diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.cpp b/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.cpp deleted file mode 100644 index 9399feb50..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.cpp +++ /dev/null @@ -1,469 +0,0 @@ -#include "gc_data.hpp" -static SOUND x1890[] = { - /* x1890[0] */ { 0, "audio/wp_gun_fire-01.wv", }, - /* x1890[1] */ { 0, "audio/wp_gun_fire-02.wv", }, - /* x1890[2] */ { 0, "audio/wp_gun_fire-03.wv", }, -}; -static SOUND x1906[] = { - /* x1906[0] */ { 0, "audio/wp_shotty_fire-01.wv", }, - /* x1906[1] */ { 0, "audio/wp_shotty_fire-02.wv", }, - /* x1906[2] */ { 0, "audio/wp_shotty_fire-03.wv", }, -}; -static SOUND x1922[] = { - /* x1922[0] */ { 0, "audio/wp_flump_launch-01.wv", }, - /* x1922[1] */ { 0, "audio/wp_flump_launch-02.wv", }, - /* x1922[2] */ { 0, "audio/wp_flump_launch-03.wv", }, -}; -static SOUND x1938[] = { - /* x1938[0] */ { 0, "audio/wp_hammer_swing-01.wv", }, - /* x1938[1] */ { 0, "audio/wp_hammer_swing-02.wv", }, - /* x1938[2] */ { 0, "audio/wp_hammer_swing-03.wv", }, -}; -static SOUND x1954[] = { - /* x1954[0] */ { 0, "audio/wp_hammer_hit-01.wv", }, - /* x1954[1] */ { 0, "audio/wp_hammer_hit-02.wv", }, - /* x1954[2] */ { 0, "audio/wp_hammer_hit-03.wv", }, -}; -static SOUND x1970[] = { - /* x1970[0] */ { 0, "audio/wp_ninja_attack-01.wv", }, - /* x1970[1] */ { 0, "audio/wp_ninja_attack-02.wv", }, - /* x1970[2] */ { 0, "audio/wp_ninja_attack-03.wv", }, -}; -static SOUND x1986[] = { - /* x1986[0] */ { 0, "audio/wp_flump_explo-01.wv", }, - /* x1986[1] */ { 0, "audio/wp_flump_explo-02.wv", }, - /* x1986[2] */ { 0, "audio/wp_flump_explo-03.wv", }, -}; -static SOUND x2002[] = { - /* x2002[0] */ { 0, "audio/wp_ninja_hit-01.wv", }, - /* x2002[1] */ { 0, "audio/wp_ninja_hit-02.wv", }, - /* x2002[2] */ { 0, "audio/wp_ninja_hit-03.wv", }, -}; -static SOUND x2018[] = { - /* x2018[0] */ { 0, "audio/wp_rifle_fire-01.wv", }, - /* x2018[1] */ { 0, "audio/wp_rifle_fire-02.wv", }, - /* x2018[2] */ { 0, "audio/wp_rifle_fire-03.wv", }, -}; -static SOUND x2034[] = { - /* x2034[0] */ { 0, "audio/wp_rifle_bnce-01.wv", }, - /* x2034[1] */ { 0, "audio/wp_rifle_bnce-02.wv", }, - /* x2034[2] */ { 0, "audio/wp_rifle_bnce-03.wv", }, -}; -static SOUND x2050[] = { - /* x2050[0] */ { 0, "audio/wp_switch-01.wv", }, - /* x2050[1] */ { 0, "audio/wp_switch-02.wv", }, - /* x2050[2] */ { 0, "audio/wp_switch-03.wv", }, -}; -static SOUND x2066[] = { - /* x2066[0] */ { 0, "audio/vo_teefault_pain_short-01.wv", }, - /* x2066[1] */ { 0, "audio/vo_teefault_pain_short-02.wv", }, - /* x2066[2] */ { 0, "audio/vo_teefault_pain_short-03.wv", }, - /* x2066[3] */ { 0, "audio/vo_teefault_pain_short-04.wv", }, - /* x2066[4] */ { 0, "audio/vo_teefault_pain_short-05.wv", }, - /* x2066[5] */ { 0, "audio/vo_teefault_pain_short-06.wv", }, - /* x2066[6] */ { 0, "audio/vo_teefault_pain_short-07.wv", }, - /* x2066[7] */ { 0, "audio/vo_teefault_pain_short-08.wv", }, - /* x2066[8] */ { 0, "audio/vo_teefault_pain_short-09.wv", }, - /* x2066[9] */ { 0, "audio/vo_teefault_pain_short-10.wv", }, - /* x2066[10] */ { 0, "audio/vo_teefault_pain_short-11.wv", }, - /* x2066[11] */ { 0, "audio/vo_teefault_pain_short-12.wv", }, -}; -static SOUND x2109[] = { - /* x2109[0] */ { 0, "audio/vo_teefault_pain_long-01.wv", }, - /* x2109[1] */ { 0, "audio/vo_teefault_pain_long-02.wv", }, -}; -static SOUND x2122[] = { - /* x2122[0] */ { 0, "audio/foley_land-01.wv", }, - /* x2122[1] */ { 0, "audio/foley_land-02.wv", }, - /* x2122[2] */ { 0, "audio/foley_land-03.wv", }, - /* x2122[3] */ { 0, "audio/foley_land-04.wv", }, -}; -static SOUND x2141[] = { - /* x2141[0] */ { 0, "audio/foley_dbljump-01.wv", }, - /* x2141[1] */ { 0, "audio/foley_dbljump-02.wv", }, - /* x2141[2] */ { 0, "audio/foley_dbljump-03.wv", }, -}; -static SOUND x2157[] = { - /* x2157[0] */ { 0, "audio/foley_foot_left-01.wv", }, - /* x2157[1] */ { 0, "audio/foley_foot_left-02.wv", }, - /* x2157[2] */ { 0, "audio/foley_foot_left-03.wv", }, - /* x2157[3] */ { 0, "audio/foley_foot_left-04.wv", }, - /* x2157[4] */ { 0, "audio/foley_foot_right-01.wv", }, - /* x2157[5] */ { 0, "audio/foley_foot_right-02.wv", }, - /* x2157[6] */ { 0, "audio/foley_foot_right-03.wv", }, - /* x2157[7] */ { 0, "audio/foley_foot_right-04.wv", }, -}; -static SOUND x2188[] = { - /* x2188[0] */ { 0, "audio/foley_body_splat-01.wv", }, - /* x2188[1] */ { 0, "audio/foley_body_splat-02.wv", }, - /* x2188[2] */ { 0, "audio/foley_body_splat-03.wv", }, -}; -static SOUND x2204[] = { - /* x2204[0] */ { 0, "audio/vo_teefault_spawn-01.wv", }, - /* x2204[1] */ { 0, "audio/vo_teefault_spawn-02.wv", }, - /* x2204[2] */ { 0, "audio/vo_teefault_spawn-03.wv", }, - /* x2204[3] */ { 0, "audio/vo_teefault_spawn-04.wv", }, - /* x2204[4] */ { 0, "audio/vo_teefault_spawn-05.wv", }, - /* x2204[5] */ { 0, "audio/vo_teefault_spawn-06.wv", }, - /* x2204[6] */ { 0, "audio/vo_teefault_spawn-07.wv", }, -}; -static SOUND x2232[] = { - /* x2232[0] */ { 0, "audio/sfx_skid-01.wv", }, - /* x2232[1] */ { 0, "audio/sfx_skid-02.wv", }, - /* x2232[2] */ { 0, "audio/sfx_skid-03.wv", }, - /* x2232[3] */ { 0, "audio/sfx_skid-04.wv", }, -}; -static SOUND x2251[] = { - /* x2251[0] */ { 0, "audio/vo_teefault_cry-01.wv", }, - /* x2251[1] */ { 0, "audio/vo_teefault_cry-02.wv", }, -}; -static SOUND x2264[] = { - /* x2264[0] */ { 0, "audio/hook_loop-01.wv", }, - /* x2264[1] */ { 0, "audio/hook_loop-02.wv", }, -}; -static SOUND x2277[] = { - /* x2277[0] */ { 0, "audio/hook_attach-01.wv", }, - /* x2277[1] */ { 0, "audio/hook_attach-02.wv", }, - /* x2277[2] */ { 0, "audio/hook_attach-03.wv", }, -}; -static SOUND x2293[] = { - /* x2293[0] */ { 0, "audio/foley_body_impact-01.wv", }, - /* x2293[1] */ { 0, "audio/foley_body_impact-02.wv", }, - /* x2293[2] */ { 0, "audio/foley_body_impact-03.wv", }, -}; -static SOUND x2309[] = { - /* x2309[0] */ { 0, "audio/hook_noattach-01.wv", }, - /* x2309[1] */ { 0, "audio/hook_noattach-02.wv", }, -}; -static SOUND x2322[] = { - /* x2322[0] */ { 0, "audio/sfx_pickup_hrt-01.wv", }, - /* x2322[1] */ { 0, "audio/sfx_pickup_hrt-02.wv", }, -}; -static SOUND x2335[] = { - /* x2335[0] */ { 0, "audio/sfx_pickup_arm-01.wv", }, - /* x2335[1] */ { 0, "audio/sfx_pickup_arm-02.wv", }, - /* x2335[2] */ { 0, "audio/sfx_pickup_arm-03.wv", }, - /* x2335[3] */ { 0, "audio/sfx_pickup_arm-04.wv", }, -}; -static SOUND x2354[] = { - /* x2354[0] */ { 0, "audio/sfx_pickup_launcher.wv", }, -}; -static SOUND x2364[] = { - /* x2364[0] */ { 0, "audio/sfx_pickup_sg.wv", }, -}; -static SOUND x2374[] = { - /* x2374[0] */ { 0, "audio/sfx_pickup_ninja.wv", }, -}; -static SOUND x2384[] = { - /* x2384[0] */ { 0, "audio/sfx_spawn_wpn-01.wv", }, - /* x2384[1] */ { 0, "audio/sfx_spawn_wpn-02.wv", }, - /* x2384[2] */ { 0, "audio/sfx_spawn_wpn-03.wv", }, -}; -static SOUND x2400[] = { - /* x2400[0] */ { 0, "audio/wp_noammo-01.wv", }, - /* x2400[1] */ { 0, "audio/wp_noammo-02.wv", }, - /* x2400[2] */ { 0, "audio/wp_noammo-03.wv", }, - /* x2400[3] */ { 0, "audio/wp_noammo-04.wv", }, - /* x2400[4] */ { 0, "audio/wp_noammo-05.wv", }, -}; -static SOUND x2422[] = { - /* x2422[0] */ { 0, "audio/sfx_hit_weak-01.wv", }, - /* x2422[1] */ { 0, "audio/sfx_hit_weak-02.wv", }, -}; -static SOUND x2435[] = { - /* x2435[0] */ { 0, "audio/sfx_msg-server.wv", }, -}; -static SOUND x2445[] = { - /* x2445[0] */ { 0, "audio/sfx_msg-client.wv", }, -}; -static SOUND x2455[] = { - /* x2455[0] */ { 0, "audio/sfx_ctf_drop.wv", }, -}; -static SOUND x2465[] = { - /* x2465[0] */ { 0, "audio/sfx_ctf_rtn.wv", }, -}; -static SOUND x2475[] = { - /* x2475[0] */ { 0, "audio/sfx_ctf_grab_pl.wv", }, -}; -static SOUND x2485[] = { - /* x2485[0] */ { 0, "audio/sfx_ctf_grab_en.wv", }, -}; -static SOUND x2495[] = { - /* x2495[0] */ { 0, "audio/sfx_ctf_cap_pl.wv", }, -}; -static SOUNDSET x9[] = { - /* x9[0] */ { "gun_fire", 3,x1890, -1, }, - /* x9[1] */ { "shotgun_fire", 3,x1906, -1, }, - /* x9[2] */ { "grenade_fire", 3,x1922, -1, }, - /* x9[3] */ { "hammer_fire", 3,x1938, -1, }, - /* x9[4] */ { "hammer_hit", 3,x1954, -1, }, - /* x9[5] */ { "ninja_fire", 3,x1970, -1, }, - /* x9[6] */ { "grenade_explode", 3,x1986, -1, }, - /* x9[7] */ { "ninja_hit", 3,x2002, -1, }, - /* x9[8] */ { "rifle_fire", 3,x2018, -1, }, - /* x9[9] */ { "rifle_bounce", 3,x2034, -1, }, - /* x9[10] */ { "weapon_switch", 3,x2050, -1, }, - /* x9[11] */ { "player_pain_short", 12,x2066, -1, }, - /* x9[12] */ { "player_pain_long", 2,x2109, -1, }, - /* x9[13] */ { "body_land", 4,x2122, -1, }, - /* x9[14] */ { "player_airjump", 3,x2141, -1, }, - /* x9[15] */ { "player_jump", 8,x2157, -1, }, - /* x9[16] */ { "player_die", 3,x2188, -1, }, - /* x9[17] */ { "player_spawn", 7,x2204, -1, }, - /* x9[18] */ { "player_skid", 4,x2232, -1, }, - /* x9[19] */ { "tee_cry", 2,x2251, -1, }, - /* x9[20] */ { "hook_loop", 2,x2264, -1, }, - /* x9[21] */ { "hook_attach_ground", 3,x2277, -1, }, - /* x9[22] */ { "hook_attach_player", 3,x2293, -1, }, - /* x9[23] */ { "hook_noattach", 2,x2309, -1, }, - /* x9[24] */ { "pickup_health", 2,x2322, -1, }, - /* x9[25] */ { "pickup_armor", 4,x2335, -1, }, - /* x9[26] */ { "pickup_grenade", 1,x2354, -1, }, - /* x9[27] */ { "pickup_shotgun", 1,x2364, -1, }, - /* x9[28] */ { "pickup_ninja", 1,x2374, -1, }, - /* x9[29] */ { "weapon_spawn", 3,x2384, -1, }, - /* x9[30] */ { "weapon_noammo", 5,x2400, -1, }, - /* x9[31] */ { "hit", 2,x2422, -1, }, - /* x9[32] */ { "chat_server", 1,x2435, -1, }, - /* x9[33] */ { "chat_client", 1,x2445, -1, }, - /* x9[34] */ { "ctf_drop", 1,x2455, -1, }, - /* x9[35] */ { "ctf_return", 1,x2465, -1, }, - /* x9[36] */ { "ctf_grab_pl", 1,x2475, -1, }, - /* x9[37] */ { "ctf_grab_en", 1,x2485, -1, }, - /* x9[38] */ { "ctf_capture", 1,x2495, -1, }, -}; -static IMAGE x14[] = { - /* x14[0] */ { "null", "", -1, }, - /* x14[1] */ { "game", "game.png", -1, }, - /* x14[2] */ { "particles", "particles.png", -1, }, - /* x14[3] */ { "cursor", "gui_cursor.png", -1, }, - /* x14[4] */ { "banner", "gui_logo.png", -1, }, - /* x14[5] */ { "emoticons", "emoticons.png", -1, }, - /* x14[6] */ { "browseicons", "browse_icons.png", -1, }, - /* x14[7] */ { "console_bg", "console.png", -1, }, - /* x14[8] */ { "console_bar", "console_bar.png", -1, }, -}; -static PICKUPSPEC x19[] = { - /* x19[0] */ { "health", 15, 0, }, - /* x19[1] */ { "armor", 15, 0, }, - /* x19[2] */ { "weapon", 15, 0, }, - /* x19[3] */ { "ninja", 90, 90, }, -}; -static SPRITESET x28[] = { - /* x28[0] */ { &x14[2], 8, 8, }, - /* x28[1] */ { &x14[1], 32, 16, }, - /* x28[2] */ { &x14[0], 8, 4, }, - /* x28[3] */ { &x14[6], 4, 1, }, - /* x28[4] */ { &x14[5], 4, 4, }, -}; -static SPRITE x44[] = { - /* x44[0] */ { "part_slice", &x28[0], 0, 0, 1, 1, }, - /* x44[1] */ { "part_ball", &x28[0], 1, 0, 1, 1, }, - /* x44[2] */ { "part_splat01", &x28[0], 2, 0, 1, 1, }, - /* x44[3] */ { "part_splat02", &x28[0], 3, 0, 1, 1, }, - /* x44[4] */ { "part_splat03", &x28[0], 4, 0, 1, 1, }, - /* x44[5] */ { "part_smoke", &x28[0], 0, 1, 1, 1, }, - /* x44[6] */ { "part_shell", &x28[0], 0, 2, 2, 2, }, - /* x44[7] */ { "part_expl01", &x28[0], 0, 4, 4, 4, }, - /* x44[8] */ { "part_airjump", &x28[0], 2, 2, 2, 2, }, - /* x44[9] */ { "health_full", &x28[1], 21, 0, 2, 2, }, - /* x44[10] */ { "health_empty", &x28[1], 23, 0, 2, 2, }, - /* x44[11] */ { "armor_full", &x28[1], 21, 2, 2, 2, }, - /* x44[12] */ { "armor_empty", &x28[1], 23, 2, 2, 2, }, - /* x44[13] */ { "star1", &x28[1], 15, 0, 2, 2, }, - /* x44[14] */ { "star2", &x28[1], 17, 0, 2, 2, }, - /* x44[15] */ { "star3", &x28[1], 19, 0, 2, 2, }, - /* x44[16] */ { "part1", &x28[1], 6, 0, 1, 1, }, - /* x44[17] */ { "part2", &x28[1], 6, 1, 1, 1, }, - /* x44[18] */ { "part3", &x28[1], 7, 0, 1, 1, }, - /* x44[19] */ { "part4", &x28[1], 7, 1, 1, 1, }, - /* x44[20] */ { "part5", &x28[1], 8, 0, 1, 1, }, - /* x44[21] */ { "part6", &x28[1], 8, 1, 1, 1, }, - /* x44[22] */ { "part7", &x28[1], 9, 0, 2, 2, }, - /* x44[23] */ { "part8", &x28[1], 11, 0, 2, 2, }, - /* x44[24] */ { "part9", &x28[1], 13, 0, 2, 2, }, - /* x44[25] */ { "weapon_gun_body", &x28[1], 2, 4, 4, 2, }, - /* x44[26] */ { "weapon_gun_cursor", &x28[1], 0, 4, 2, 2, }, - /* x44[27] */ { "weapon_gun_proj", &x28[1], 6, 4, 2, 2, }, - /* x44[28] */ { "weapon_gun_muzzle1", &x28[1], 8, 4, 3, 2, }, - /* x44[29] */ { "weapon_gun_muzzle2", &x28[1], 12, 4, 3, 2, }, - /* x44[30] */ { "weapon_gun_muzzle3", &x28[1], 16, 4, 3, 2, }, - /* x44[31] */ { "weapon_shotgun_body", &x28[1], 2, 6, 8, 2, }, - /* x44[32] */ { "weapon_shotgun_cursor", &x28[1], 0, 6, 2, 2, }, - /* x44[33] */ { "weapon_shotgun_proj", &x28[1], 10, 6, 2, 2, }, - /* x44[34] */ { "weapon_shotgun_muzzle1", &x28[1], 12, 6, 3, 2, }, - /* x44[35] */ { "weapon_shotgun_muzzle2", &x28[1], 16, 6, 3, 2, }, - /* x44[36] */ { "weapon_shotgun_muzzle3", &x28[1], 20, 6, 3, 2, }, - /* x44[37] */ { "weapon_grenade_body", &x28[1], 2, 8, 7, 2, }, - /* x44[38] */ { "weapon_grenade_cursor", &x28[1], 0, 8, 2, 2, }, - /* x44[39] */ { "weapon_grenade_proj", &x28[1], 10, 8, 2, 2, }, - /* x44[40] */ { "weapon_hammer_body", &x28[1], 2, 1, 4, 3, }, - /* x44[41] */ { "weapon_hammer_cursor", &x28[1], 0, 0, 2, 2, }, - /* x44[42] */ { "weapon_hammer_proj", &x28[1], 0, 0, 0, 0, }, - /* x44[43] */ { "weapon_ninja_body", &x28[1], 2, 10, 7, 2, }, - /* x44[44] */ { "weapon_ninja_cursor", &x28[1], 0, 10, 2, 2, }, - /* x44[45] */ { "weapon_ninja_proj", &x28[1], 0, 0, 0, 0, }, - /* x44[46] */ { "weapon_rifle_body", &x28[1], 2, 12, 7, 3, }, - /* x44[47] */ { "weapon_rifle_cursor", &x28[1], 0, 12, 2, 2, }, - /* x44[48] */ { "weapon_rifle_proj", &x28[1], 10, 12, 2, 2, }, - /* x44[49] */ { "hook_chain", &x28[1], 2, 0, 1, 1, }, - /* x44[50] */ { "hook_head", &x28[1], 3, 0, 2, 1, }, - /* x44[51] */ { "weapon_ninja_muzzle1", &x28[1], 25, 0, 7, 4, }, - /* x44[52] */ { "weapon_ninja_muzzle2", &x28[1], 25, 4, 7, 4, }, - /* x44[53] */ { "weapon_ninja_muzzle3", &x28[1], 25, 8, 7, 4, }, - /* x44[54] */ { "pickup_health", &x28[1], 10, 2, 2, 2, }, - /* x44[55] */ { "pickup_armor", &x28[1], 12, 2, 2, 2, }, - /* x44[56] */ { "pickup_weapon", &x28[1], 3, 0, 6, 2, }, - /* x44[57] */ { "pickup_ninja", &x28[1], 3, 10, 7, 2, }, - /* x44[58] */ { "flag_blue", &x28[1], 12, 8, 4, 8, }, - /* x44[59] */ { "flag_red", &x28[1], 16, 8, 4, 8, }, - /* x44[60] */ { "tee_body", &x28[2], 0, 0, 3, 3, }, - /* x44[61] */ { "tee_body_outline", &x28[2], 3, 0, 3, 3, }, - /* x44[62] */ { "tee_foot", &x28[2], 6, 1, 2, 1, }, - /* x44[63] */ { "tee_foot_outline", &x28[2], 6, 2, 2, 1, }, - /* x44[64] */ { "tee_hand", &x28[2], 6, 0, 1, 1, }, - /* x44[65] */ { "tee_hand_outline", &x28[2], 7, 0, 1, 1, }, - /* x44[66] */ { "tee_eye_normal", &x28[2], 2, 3, 1, 1, }, - /* x44[67] */ { "tee_eye_angry", &x28[2], 3, 3, 1, 1, }, - /* x44[68] */ { "tee_eye_pain", &x28[2], 4, 3, 1, 1, }, - /* x44[69] */ { "tee_eye_happy", &x28[2], 5, 3, 1, 1, }, - /* x44[70] */ { "tee_eye_dead", &x28[2], 6, 3, 1, 1, }, - /* x44[71] */ { "tee_eye_surprise", &x28[2], 7, 3, 1, 1, }, - /* x44[72] */ { "oop", &x28[4], 0, 0, 1, 1, }, - /* x44[73] */ { "exclamation", &x28[4], 1, 0, 1, 1, }, - /* x44[74] */ { "hearts", &x28[4], 2, 0, 1, 1, }, - /* x44[75] */ { "drop", &x28[4], 3, 0, 1, 1, }, - /* x44[76] */ { "dotdot", &x28[4], 0, 1, 1, 1, }, - /* x44[77] */ { "music1", &x28[4], 1, 1, 1, 1, }, - /* x44[78] */ { "music2", &x28[4], 2, 1, 1, 1, }, - /* x44[79] */ { "ghost", &x28[4], 3, 1, 1, 1, }, - /* x44[80] */ { "sushi", &x28[4], 0, 2, 1, 1, }, - /* x44[81] */ { "splattee", &x28[4], 1, 2, 1, 1, }, - /* x44[82] */ { "deviltee", &x28[4], 2, 2, 1, 1, }, - /* x44[83] */ { "zomg", &x28[4], 3, 2, 1, 1, }, - /* x44[84] */ { "zzz", &x28[4], 0, 3, 1, 1, }, - /* x44[85] */ { "blank1", &x28[4], 1, 3, 1, 1, }, - /* x44[86] */ { "deadtee", &x28[4], 2, 3, 1, 1, }, - /* x44[87] */ { "blank2", &x28[4], 3, 3, 1, 1, }, - /* x44[88] */ { "browse_lock", &x28[3], 0, 0, 1, 1, }, - /* x44[89] */ { "browse_heart", &x28[3], 1, 0, 1, 1, }, - /* x44[90] */ { "browse_unpure", &x28[3], 3, 0, 1, 1, }, -}; -static ANIM_KEYFRAME x3965[] = { - /* x3965[0] */ { 0.000000, 0.000000, -4.000000, 0.000000, }, -}; -static ANIM_KEYFRAME x3972[] = { - /* x3972[0] */ { 0.000000, 0.000000, 10.000000, 0.000000, }, -}; -static ANIM_KEYFRAME x3979[] = { - /* x3979[0] */ { 0.000000, 0.000000, 10.000000, 0.000000, }, -}; -static ANIM_KEYFRAME *x3986 = 0; -static ANIM_KEYFRAME *x4010 = 0; -static ANIM_KEYFRAME x4017[] = { - /* x4017[0] */ { 0.000000, -7.000000, 0.000000, 0.000000, }, -}; -static ANIM_KEYFRAME x4024[] = { - /* x4024[0] */ { 0.000000, 7.000000, 0.000000, 0.000000, }, -}; -static ANIM_KEYFRAME *x4031 = 0; -static ANIM_KEYFRAME *x4050 = 0; -static ANIM_KEYFRAME x4057[] = { - /* x4057[0] */ { 0.000000, -3.000000, 0.000000, -0.100000, }, -}; -static ANIM_KEYFRAME x4064[] = { - /* x4064[0] */ { 0.000000, 3.000000, 0.000000, -0.100000, }, -}; -static ANIM_KEYFRAME *x4071 = 0; -static ANIM_KEYFRAME x4090[] = { - /* x4090[0] */ { 0.000000, 0.000000, 0.000000, 0.000000, }, - /* x4090[1] */ { 0.200000, 0.000000, -1.000000, 0.000000, }, - /* x4090[2] */ { 0.400000, 0.000000, 0.000000, 0.000000, }, - /* x4090[3] */ { 0.600000, 0.000000, 0.000000, 0.000000, }, - /* x4090[4] */ { 0.800000, 0.000000, -1.000000, 0.000000, }, - /* x4090[5] */ { 1.000000, 0.000000, 0.000000, 0.000000, }, -}; -static ANIM_KEYFRAME x4097[] = { - /* x4097[0] */ { 0.000000, 8.000000, 0.000000, 0.000000, }, - /* x4097[1] */ { 0.200000, -8.000000, 0.000000, 0.000000, }, - /* x4097[2] */ { 0.400000, -10.000000, -4.000000, 0.200000, }, - /* x4097[3] */ { 0.600000, -8.000000, -8.000000, 0.300000, }, - /* x4097[4] */ { 0.800000, 4.000000, -4.000000, -0.200000, }, - /* x4097[5] */ { 1.000000, 8.000000, 0.000000, 0.000000, }, -}; -static ANIM_KEYFRAME x4104[] = { - /* x4104[0] */ { 0.000000, -10.000000, -4.000000, 0.200000, }, - /* x4104[1] */ { 0.200000, -8.000000, -8.000000, 0.300000, }, - /* x4104[2] */ { 0.400000, 4.000000, -4.000000, -0.200000, }, - /* x4104[3] */ { 0.600000, 8.000000, 0.000000, 0.000000, }, - /* x4104[4] */ { 0.800000, 8.000000, 0.000000, 0.000000, }, - /* x4104[5] */ { 1.000000, -10.000000, -4.000000, 0.200000, }, -}; -static ANIM_KEYFRAME *x4111 = 0; -static ANIM_KEYFRAME *x4210 = 0; -static ANIM_KEYFRAME *x4217 = 0; -static ANIM_KEYFRAME *x4224 = 0; -static ANIM_KEYFRAME x4231[] = { - /* x4231[0] */ { 0.000000, 0.000000, 0.000000, -0.100000, }, - /* x4231[1] */ { 0.300000, 0.000000, 0.000000, 0.250000, }, - /* x4231[2] */ { 0.400000, 0.000000, 0.000000, 0.300000, }, - /* x4231[3] */ { 0.500000, 0.000000, 0.000000, 0.250000, }, - /* x4231[4] */ { 1.000000, 0.000000, 0.000000, -0.100000, }, -}; -static ANIM_KEYFRAME *x4265 = 0; -static ANIM_KEYFRAME *x4272 = 0; -static ANIM_KEYFRAME *x4279 = 0; -static ANIM_KEYFRAME x4286[] = { - /* x4286[0] */ { 0.000000, 0.000000, 0.000000, -0.250000, }, - /* x4286[1] */ { 0.100000, 0.000000, 0.000000, -0.050000, }, - /* x4286[2] */ { 0.150000, 0.000000, 0.000000, 0.350000, }, - /* x4286[3] */ { 0.420000, 0.000000, 0.000000, 0.400000, }, - /* x4286[4] */ { 0.500000, 0.000000, 0.000000, 0.350000, }, - /* x4286[5] */ { 1.000000, 0.000000, 0.000000, -0.250000, }, -}; -static ANIMATION x75[] = { - /* x75[0] */ { "base", /* x75[0].body */ { 1,x3965, }, /* x75[0].back_foot */ { 1,x3972, }, /* x75[0].front_foot */ { 1,x3979, }, /* x75[0].attach */ { 0,x3986, }, }, - /* x75[1] */ { "idle", /* x75[1].body */ { 0,x4010, }, /* x75[1].back_foot */ { 1,x4017, }, /* x75[1].front_foot */ { 1,x4024, }, /* x75[1].attach */ { 0,x4031, }, }, - /* x75[2] */ { "inair", /* x75[2].body */ { 0,x4050, }, /* x75[2].back_foot */ { 1,x4057, }, /* x75[2].front_foot */ { 1,x4064, }, /* x75[2].attach */ { 0,x4071, }, }, - /* x75[3] */ { "walk", /* x75[3].body */ { 6,x4090, }, /* x75[3].back_foot */ { 6,x4097, }, /* x75[3].front_foot */ { 6,x4104, }, /* x75[3].attach */ { 0,x4111, }, }, - /* x75[4] */ { "hammer_swing", /* x75[4].body */ { 0,x4210, }, /* x75[4].back_foot */ { 0,x4217, }, /* x75[4].front_foot */ { 0,x4224, }, /* x75[4].attach */ { 5,x4231, }, }, - /* x75[5] */ { "ninja_swing", /* x75[5].body */ { 0,x4265, }, /* x75[5].back_foot */ { 0,x4272, }, /* x75[5].front_foot */ { 0,x4279, }, /* x75[5].attach */ { 6,x4286, }, }, -}; -static SPRITE* *x4443 = 0; -static SPRITE* x4580[] = { - &x44[28], - &x44[29], - &x44[30], -}; -static SPRITE* x4765[] = { - &x44[34], - &x44[35], - &x44[36], -}; -static SPRITE* *x4950 = 0; -static SPRITE* *x5087 = 0; -static SPRITE* x5224[] = { - &x44[51], - &x44[52], - &x44[53], -}; -static WEAPONSPEC x1884[] = { - /* x1884[0] */ { "hammer", &x44[40], &x44[41], &x44[42], 0,x4443, 96, 125, 10, 0, 3, 4.000000, -20.000000, 0.000000, 0.000000, 5.000000, }, - /* x1884[1] */ { "gun", &x44[25], &x44[26], &x44[27], 3,x4580, 64, 125, 10, 500, 1, 32.000000, -4.000000, 50.000000, 6.000000, 5.000000, }, - /* x1884[2] */ { "shotgun", &x44[31], &x44[32], &x44[33], 3,x4765, 96, 500, 10, 0, 1, 24.000000, -2.000000, 70.000000, 6.000000, 5.000000, }, - /* x1884[3] */ { "grenade", &x44[37], &x44[38], &x44[39], 0,x4950, 96, 500, 10, 0, 1, 24.000000, -2.000000, 0.000000, 0.000000, 5.000000, }, - /* x1884[4] */ { "rifle", &x44[46], &x44[47], &x44[48], 0,x5087, 92, 800, 10, 0, 5, 24.000000, -2.000000, 0.000000, 0.000000, 5.000000, }, - /* x1884[5] */ { "ninja", &x44[43], &x44[44], &x44[45], 3,x5224, 96, 800, 10, 0, 9, 0.000000, 0.000000, 40.000000, -4.000000, 5.000000, }, -}; -DATACONTAINER datacontainer = -/* datacontainer */ { - 39,x9, - 9,x14, - 4,x19, - 5,x28, - 91,x44, - 6,x75, - /* datacontainer.weapons */ { /* datacontainer.weapons.hammer */ { &x1884[0], }, /* datacontainer.weapons.gun */ { &x1884[1], }, /* datacontainer.weapons.shotgun */ { &x1884[2], 1.250000, 2200.000000, 0.800000, 0.250000, }, /* datacontainer.weapons.grenade */ { &x1884[3], 7.000000, 1000.000000, 2.000000, }, /* datacontainer.weapons.rifle */ { &x1884[4], 800.000000, 150, 1, 0.000000, }, /* datacontainer.weapons.ninja */ { &x1884[5], 15000, 200, 50, }, 6,x1884, }, -} -; -DATACONTAINER *data = &datacontainer; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.hpp b/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.hpp deleted file mode 100644 index 3faf49852..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/gc_data.hpp +++ /dev/null @@ -1,268 +0,0 @@ -#ifndef CLIENT_CONTENT_HEADER -#define CLIENT_CONTENT_HEADER -struct SOUND -{ - int id; - const char* filename; -}; -struct SOUNDSET -{ - const char* name; - int num_sounds; - SOUND *sounds; - int last; -}; -struct IMAGE -{ - const char* name; - const char* filename; - int id; -}; -struct SPRITESET -{ - IMAGE* image; - int gridx; - int gridy; -}; -struct SPRITE -{ - const char* name; - SPRITESET* set; - int x; - int y; - int w; - int h; -}; -struct PICKUPSPEC -{ - const char* name; - int respawntime; - int spawndelay; -}; -struct ANIM_KEYFRAME -{ - float time; - float x; - float y; - float angle; -}; -struct ANIM_SEQUENCE -{ - int num_frames; - ANIM_KEYFRAME *frames; -}; -struct ANIMATION -{ - const char* name; - ANIM_SEQUENCE body; - ANIM_SEQUENCE back_foot; - ANIM_SEQUENCE front_foot; - ANIM_SEQUENCE attach; -}; -struct WEAPONSPEC -{ - const char* name; - SPRITE* sprite_body; - SPRITE* sprite_cursor; - SPRITE* sprite_proj; - int num_sprite_muzzles; - SPRITE* *sprite_muzzles; - int visual_size; - int firedelay; - int maxammo; - int ammoregentime; - int damage; - float offsetx; - float offsety; - float muzzleoffsetx; - float muzzleoffsety; - float muzzleduration; -}; -struct WEAPONSPEC_HAMMER -{ - WEAPONSPEC* base; -}; -struct WEAPONSPEC_GUN -{ - WEAPONSPEC* base; - float curvature; - float speed; - float lifetime; -}; -struct WEAPONSPEC_SHOTGUN -{ - WEAPONSPEC* base; - float curvature; - float speed; - float speeddiff; - float lifetime; -}; -struct WEAPONSPEC_GRENADE -{ - WEAPONSPEC* base; - float curvature; - float speed; - float lifetime; -}; -struct WEAPONSPEC_RIFLE -{ - WEAPONSPEC* base; - float reach; - int bounce_delay; - int bounce_num; - float bounce_cost; -}; -struct WEAPONSPEC_NINJA -{ - WEAPONSPEC* base; - int duration; - int movetime; - int velocity; -}; -struct WEAPONSPECS -{ - WEAPONSPEC_HAMMER hammer; - WEAPONSPEC_HAMMER gun; - WEAPONSPEC_SHOTGUN shotgun; - WEAPONSPEC_GRENADE grenade; - WEAPONSPEC_RIFLE rifle; - WEAPONSPEC_NINJA ninja; - int num_id; - WEAPONSPEC *id; -}; -struct DATACONTAINER -{ - int num_sounds; - SOUNDSET *sounds; - int num_images; - IMAGE *images; - int num_pickups; - PICKUPSPEC *pickups; - int num_spritesets; - SPRITESET *spritesets; - int num_sprites; - SPRITE *sprites; - int num_animations; - ANIMATION *animations; - WEAPONSPECS weapons; -}; -extern DATACONTAINER *data; -enum -{ - IMAGE_NULL=0, - IMAGE_GAME, - IMAGE_PARTICLES, - IMAGE_CURSOR, - IMAGE_BANNER, - IMAGE_EMOTICONS, - IMAGE_BROWSEICONS, - IMAGE_CONSOLE_BG, - IMAGE_CONSOLE_BAR, - NUM_IMAGES -}; -enum -{ - ANIM_BASE=0, - ANIM_IDLE, - ANIM_INAIR, - ANIM_WALK, - ANIM_HAMMER_SWING, - ANIM_NINJA_SWING, - NUM_ANIMS -}; -enum -{ - SPRITE_PART_SLICE=0, - SPRITE_PART_BALL, - SPRITE_PART_SPLAT01, - SPRITE_PART_SPLAT02, - SPRITE_PART_SPLAT03, - SPRITE_PART_SMOKE, - SPRITE_PART_SHELL, - SPRITE_PART_EXPL01, - SPRITE_PART_AIRJUMP, - SPRITE_HEALTH_FULL, - SPRITE_HEALTH_EMPTY, - SPRITE_ARMOR_FULL, - SPRITE_ARMOR_EMPTY, - SPRITE_STAR1, - SPRITE_STAR2, - SPRITE_STAR3, - SPRITE_PART1, - SPRITE_PART2, - SPRITE_PART3, - SPRITE_PART4, - SPRITE_PART5, - SPRITE_PART6, - SPRITE_PART7, - SPRITE_PART8, - SPRITE_PART9, - SPRITE_WEAPON_GUN_BODY, - SPRITE_WEAPON_GUN_CURSOR, - SPRITE_WEAPON_GUN_PROJ, - SPRITE_WEAPON_GUN_MUZZLE1, - SPRITE_WEAPON_GUN_MUZZLE2, - SPRITE_WEAPON_GUN_MUZZLE3, - SPRITE_WEAPON_SHOTGUN_BODY, - SPRITE_WEAPON_SHOTGUN_CURSOR, - SPRITE_WEAPON_SHOTGUN_PROJ, - SPRITE_WEAPON_SHOTGUN_MUZZLE1, - SPRITE_WEAPON_SHOTGUN_MUZZLE2, - SPRITE_WEAPON_SHOTGUN_MUZZLE3, - SPRITE_WEAPON_GRENADE_BODY, - SPRITE_WEAPON_GRENADE_CURSOR, - SPRITE_WEAPON_GRENADE_PROJ, - SPRITE_WEAPON_HAMMER_BODY, - SPRITE_WEAPON_HAMMER_CURSOR, - SPRITE_WEAPON_HAMMER_PROJ, - SPRITE_WEAPON_NINJA_BODY, - SPRITE_WEAPON_NINJA_CURSOR, - SPRITE_WEAPON_NINJA_PROJ, - SPRITE_WEAPON_RIFLE_BODY, - SPRITE_WEAPON_RIFLE_CURSOR, - SPRITE_WEAPON_RIFLE_PROJ, - SPRITE_HOOK_CHAIN, - SPRITE_HOOK_HEAD, - SPRITE_WEAPON_NINJA_MUZZLE1, - SPRITE_WEAPON_NINJA_MUZZLE2, - SPRITE_WEAPON_NINJA_MUZZLE3, - SPRITE_PICKUP_HEALTH, - SPRITE_PICKUP_ARMOR, - SPRITE_PICKUP_WEAPON, - SPRITE_PICKUP_NINJA, - SPRITE_FLAG_BLUE, - SPRITE_FLAG_RED, - SPRITE_TEE_BODY, - SPRITE_TEE_BODY_OUTLINE, - SPRITE_TEE_FOOT, - SPRITE_TEE_FOOT_OUTLINE, - SPRITE_TEE_HAND, - SPRITE_TEE_HAND_OUTLINE, - SPRITE_TEE_EYE_NORMAL, - SPRITE_TEE_EYE_ANGRY, - SPRITE_TEE_EYE_PAIN, - SPRITE_TEE_EYE_HAPPY, - SPRITE_TEE_EYE_DEAD, - SPRITE_TEE_EYE_SURPRISE, - SPRITE_OOP, - SPRITE_EXCLAMATION, - SPRITE_HEARTS, - SPRITE_DROP, - SPRITE_DOTDOT, - SPRITE_MUSIC1, - SPRITE_MUSIC2, - SPRITE_GHOST, - SPRITE_SUSHI, - SPRITE_SPLATTEE, - SPRITE_DEVILTEE, - SPRITE_ZOMG, - SPRITE_ZZZ, - SPRITE_BLANK1, - SPRITE_DEADTEE, - SPRITE_BLANK2, - SPRITE_BROWSE_LOCK, - SPRITE_BROWSE_HEART, - SPRITE_BROWSE_UNPURE, - NUM_SPRITES -}; -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/gs_data.hpp b/project/jni/application/teeworlds-0.5.2/src/game/generated/gs_data.hpp deleted file mode 100644 index ecc150450..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/gs_data.hpp +++ /dev/null @@ -1,268 +0,0 @@ -#ifndef SERVER_CONTENT_HEADER -#define SERVER_CONTENT_HEADER -struct SOUND -{ - int id; - const char* filename; -}; -struct SOUNDSET -{ - const char* name; - int num_sounds; - SOUND *sounds; - int last; -}; -struct IMAGE -{ - const char* name; - const char* filename; - int id; -}; -struct SPRITESET -{ - IMAGE* image; - int gridx; - int gridy; -}; -struct SPRITE -{ - const char* name; - SPRITESET* set; - int x; - int y; - int w; - int h; -}; -struct PICKUPSPEC -{ - const char* name; - int respawntime; - int spawndelay; -}; -struct ANIM_KEYFRAME -{ - float time; - float x; - float y; - float angle; -}; -struct ANIM_SEQUENCE -{ - int num_frames; - ANIM_KEYFRAME *frames; -}; -struct ANIMATION -{ - const char* name; - ANIM_SEQUENCE body; - ANIM_SEQUENCE back_foot; - ANIM_SEQUENCE front_foot; - ANIM_SEQUENCE attach; -}; -struct WEAPONSPEC -{ - const char* name; - SPRITE* sprite_body; - SPRITE* sprite_cursor; - SPRITE* sprite_proj; - int num_sprite_muzzles; - SPRITE* *sprite_muzzles; - int visual_size; - int firedelay; - int maxammo; - int ammoregentime; - int damage; - float offsetx; - float offsety; - float muzzleoffsetx; - float muzzleoffsety; - float muzzleduration; -}; -struct WEAPONSPEC_HAMMER -{ - WEAPONSPEC* base; -}; -struct WEAPONSPEC_GUN -{ - WEAPONSPEC* base; - float curvature; - float speed; - float lifetime; -}; -struct WEAPONSPEC_SHOTGUN -{ - WEAPONSPEC* base; - float curvature; - float speed; - float speeddiff; - float lifetime; -}; -struct WEAPONSPEC_GRENADE -{ - WEAPONSPEC* base; - float curvature; - float speed; - float lifetime; -}; -struct WEAPONSPEC_RIFLE -{ - WEAPONSPEC* base; - float reach; - int bounce_delay; - int bounce_num; - float bounce_cost; -}; -struct WEAPONSPEC_NINJA -{ - WEAPONSPEC* base; - int duration; - int movetime; - int velocity; -}; -struct WEAPONSPECS -{ - WEAPONSPEC_HAMMER hammer; - WEAPONSPEC_HAMMER gun; - WEAPONSPEC_SHOTGUN shotgun; - WEAPONSPEC_GRENADE grenade; - WEAPONSPEC_RIFLE rifle; - WEAPONSPEC_NINJA ninja; - int num_id; - WEAPONSPEC *id; -}; -struct DATACONTAINER -{ - int num_sounds; - SOUNDSET *sounds; - int num_images; - IMAGE *images; - int num_pickups; - PICKUPSPEC *pickups; - int num_spritesets; - SPRITESET *spritesets; - int num_sprites; - SPRITE *sprites; - int num_animations; - ANIMATION *animations; - WEAPONSPECS weapons; -}; -extern DATACONTAINER *data; -enum -{ - IMAGE_NULL=0, - IMAGE_GAME, - IMAGE_PARTICLES, - IMAGE_CURSOR, - IMAGE_BANNER, - IMAGE_EMOTICONS, - IMAGE_BROWSEICONS, - IMAGE_CONSOLE_BG, - IMAGE_CONSOLE_BAR, - NUM_IMAGES -}; -enum -{ - ANIM_BASE=0, - ANIM_IDLE, - ANIM_INAIR, - ANIM_WALK, - ANIM_HAMMER_SWING, - ANIM_NINJA_SWING, - NUM_ANIMS -}; -enum -{ - SPRITE_PART_SLICE=0, - SPRITE_PART_BALL, - SPRITE_PART_SPLAT01, - SPRITE_PART_SPLAT02, - SPRITE_PART_SPLAT03, - SPRITE_PART_SMOKE, - SPRITE_PART_SHELL, - SPRITE_PART_EXPL01, - SPRITE_PART_AIRJUMP, - SPRITE_HEALTH_FULL, - SPRITE_HEALTH_EMPTY, - SPRITE_ARMOR_FULL, - SPRITE_ARMOR_EMPTY, - SPRITE_STAR1, - SPRITE_STAR2, - SPRITE_STAR3, - SPRITE_PART1, - SPRITE_PART2, - SPRITE_PART3, - SPRITE_PART4, - SPRITE_PART5, - SPRITE_PART6, - SPRITE_PART7, - SPRITE_PART8, - SPRITE_PART9, - SPRITE_WEAPON_GUN_BODY, - SPRITE_WEAPON_GUN_CURSOR, - SPRITE_WEAPON_GUN_PROJ, - SPRITE_WEAPON_GUN_MUZZLE1, - SPRITE_WEAPON_GUN_MUZZLE2, - SPRITE_WEAPON_GUN_MUZZLE3, - SPRITE_WEAPON_SHOTGUN_BODY, - SPRITE_WEAPON_SHOTGUN_CURSOR, - SPRITE_WEAPON_SHOTGUN_PROJ, - SPRITE_WEAPON_SHOTGUN_MUZZLE1, - SPRITE_WEAPON_SHOTGUN_MUZZLE2, - SPRITE_WEAPON_SHOTGUN_MUZZLE3, - SPRITE_WEAPON_GRENADE_BODY, - SPRITE_WEAPON_GRENADE_CURSOR, - SPRITE_WEAPON_GRENADE_PROJ, - SPRITE_WEAPON_HAMMER_BODY, - SPRITE_WEAPON_HAMMER_CURSOR, - SPRITE_WEAPON_HAMMER_PROJ, - SPRITE_WEAPON_NINJA_BODY, - SPRITE_WEAPON_NINJA_CURSOR, - SPRITE_WEAPON_NINJA_PROJ, - SPRITE_WEAPON_RIFLE_BODY, - SPRITE_WEAPON_RIFLE_CURSOR, - SPRITE_WEAPON_RIFLE_PROJ, - SPRITE_HOOK_CHAIN, - SPRITE_HOOK_HEAD, - SPRITE_WEAPON_NINJA_MUZZLE1, - SPRITE_WEAPON_NINJA_MUZZLE2, - SPRITE_WEAPON_NINJA_MUZZLE3, - SPRITE_PICKUP_HEALTH, - SPRITE_PICKUP_ARMOR, - SPRITE_PICKUP_WEAPON, - SPRITE_PICKUP_NINJA, - SPRITE_FLAG_BLUE, - SPRITE_FLAG_RED, - SPRITE_TEE_BODY, - SPRITE_TEE_BODY_OUTLINE, - SPRITE_TEE_FOOT, - SPRITE_TEE_FOOT_OUTLINE, - SPRITE_TEE_HAND, - SPRITE_TEE_HAND_OUTLINE, - SPRITE_TEE_EYE_NORMAL, - SPRITE_TEE_EYE_ANGRY, - SPRITE_TEE_EYE_PAIN, - SPRITE_TEE_EYE_HAPPY, - SPRITE_TEE_EYE_DEAD, - SPRITE_TEE_EYE_SURPRISE, - SPRITE_OOP, - SPRITE_EXCLAMATION, - SPRITE_HEARTS, - SPRITE_DROP, - SPRITE_DOTDOT, - SPRITE_MUSIC1, - SPRITE_MUSIC2, - SPRITE_GHOST, - SPRITE_SUSHI, - SPRITE_SPLATTEE, - SPRITE_DEVILTEE, - SPRITE_ZOMG, - SPRITE_ZZZ, - SPRITE_BLANK1, - SPRITE_DEADTEE, - SPRITE_BLANK2, - SPRITE_BROWSE_LOCK, - SPRITE_BROWSE_HEART, - SPRITE_BROWSE_UNPURE, - NUM_SPRITES -}; -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/generated/nethash.c b/project/jni/application/teeworlds-0.5.2/src/game/generated/nethash.c deleted file mode 100644 index e1e0a9beb..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/generated/nethash.c +++ /dev/null @@ -1 +0,0 @@ -#define GAME_NETVERSION_HASH "b67d1f1a1eea234e" diff --git a/project/jni/application/teeworlds-0.5.2/src/game/layers.cpp b/project/jni/application/teeworlds-0.5.2/src/game/layers.cpp deleted file mode 100644 index 832dc766d..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/layers.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include "layers.hpp" - -static MAPITEM_LAYER_TILEMAP *game_layer = 0; -static MAPITEM_GROUP *game_group = 0; - -static int groups_start = 0; -static int groups_num = 0; -static int layers_start = 0; -static int layers_num = 0; - -void layers_init() -{ - map_get_type(MAPITEMTYPE_GROUP, &groups_start, &groups_num); - map_get_type(MAPITEMTYPE_LAYER, &layers_start, &layers_num); - - for(int g = 0; g < layers_num_groups(); g++) - { - MAPITEM_GROUP *group = layers_get_group(g); - for(int l = 0; l < group->num_layers; l++) - { - MAPITEM_LAYER *layer = layers_get_layer(group->start_layer+l); - - if(layer->type == LAYERTYPE_TILES) - { - MAPITEM_LAYER_TILEMAP *tilemap = (MAPITEM_LAYER_TILEMAP *)layer; - if(tilemap->flags&1) - { - game_layer = tilemap; - game_group = group; - } - } - } - } -} - -int layers_num_groups() { return groups_num; } -MAPITEM_GROUP *layers_get_group(int index) -{ - return (MAPITEM_GROUP *)map_get_item(groups_start+index, 0, 0); -} - -MAPITEM_LAYER *layers_get_layer(int index) -{ - return (MAPITEM_LAYER *)map_get_item(layers_start+index, 0, 0); -} - -MAPITEM_LAYER_TILEMAP *layers_game_layer() -{ - return game_layer; -} - -MAPITEM_GROUP *layers_game_group() -{ - return game_group; -} - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/layers.hpp b/project/jni/application/teeworlds-0.5.2/src/game/layers.hpp deleted file mode 100644 index cb18419be..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/layers.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mapitems.hpp" - -void layers_init(); - -MAPITEM_LAYER_TILEMAP *layers_game_layer(); -MAPITEM_GROUP *layers_game_group(); - -int layers_num_groups(); -MAPITEM_GROUP *layers_get_group(int index); -MAPITEM_LAYER *layers_get_layer(int index); - - diff --git a/project/jni/application/teeworlds-0.5.2/src/game/mapitems.hpp b/project/jni/application/teeworlds-0.5.2/src/game/mapitems.hpp deleted file mode 100644 index 9c9936d27..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/mapitems.hpp +++ /dev/null @@ -1,178 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef GAME_MAPITEMS_H -#define GAME_MAPITEMS_H - -// layer types -enum -{ - LAYERTYPE_INVALID=0, - LAYERTYPE_GAME, // not used - LAYERTYPE_TILES, - LAYERTYPE_QUADS, - - MAPITEMTYPE_VERSION=0, - MAPITEMTYPE_INFO, - MAPITEMTYPE_IMAGE, - MAPITEMTYPE_ENVELOPE, - MAPITEMTYPE_GROUP, - MAPITEMTYPE_LAYER, - MAPITEMTYPE_ENVPOINTS, - - - CURVETYPE_STEP=0, - CURVETYPE_LINEAR, - CURVETYPE_SLOW, - CURVETYPE_FAST, - CURVETYPE_SMOOTH, - NUM_CURVETYPES, - - // game layer tiles - ENTITY_NULL=0, - ENTITY_SPAWN, - ENTITY_SPAWN_RED, - ENTITY_SPAWN_BLUE, - ENTITY_FLAGSTAND_RED, - ENTITY_FLAGSTAND_BLUE, - ENTITY_ARMOR_1, - ENTITY_HEALTH_1, - ENTITY_WEAPON_SHOTGUN, - ENTITY_WEAPON_GRENADE, - ENTITY_POWERUP_NINJA, - ENTITY_WEAPON_RIFLE, - NUM_ENTITIES, - - TILE_AIR=0, - TILE_SOLID, - TILE_DEATH, - TILE_NOHOOK, - - TILEFLAG_VFLIP=1, - TILEFLAG_HFLIP=2, - TILEFLAG_OPAQUE=4, - - LAYERFLAG_DETAIL=1, - - ENTITY_OFFSET=255-16*4, -}; - -typedef struct -{ - int x, y; // 22.10 fixed point -} POINT; - -typedef struct -{ - int r, g, b, a; -} COLOR; - -typedef struct -{ - POINT points[5]; - COLOR colors[4]; - POINT texcoords[4]; - - int pos_env; - int pos_env_offset; - - int color_env; - int color_env_offset; -} QUAD; - -typedef struct -{ - unsigned char index; - unsigned char flags; - unsigned char skip; - unsigned char reserved; -} TILE; - -typedef struct -{ - int version; - int width; - int height; - int external; - int image_name; - int image_data; -} MAPITEM_IMAGE; - -struct MAPITEM_GROUP_v1 -{ - int version; - int offset_x; - int offset_y; - int parallax_x; - int parallax_y; - - int start_layer; - int num_layers; -} ; - - -struct MAPITEM_GROUP : public MAPITEM_GROUP_v1 -{ - enum { CURRENT_VERSION=2 }; - - int use_clipping; - int clip_x; - int clip_y; - int clip_w; - int clip_h; -} ; - -typedef struct -{ - int version; - int type; - int flags; -} MAPITEM_LAYER; - -typedef struct -{ - MAPITEM_LAYER layer; - int version; - - int width; - int height; - int flags; - - COLOR color; - int color_env; - int color_env_offset; - - int image; - int data; -} MAPITEM_LAYER_TILEMAP; - -typedef struct -{ - MAPITEM_LAYER layer; - int version; - - int num_quads; - int data; - int image; -} MAPITEM_LAYER_QUADS; - -typedef struct -{ - int version; -} MAPITEM_VERSION; - -typedef struct -{ - int time; // in ms - int curvetype; - int values[4]; // 1-4 depending on envelope (22.10 fixed point) -} ENVPOINT; - -typedef struct -{ - int version; - int channels; - int start_point; - int num_points; - int name; -} MAPITEM_ENVELOPE; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.cpp deleted file mode 100644 index 3bbe86709..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.cpp +++ /dev/null @@ -1,838 +0,0 @@ -#include -#include -#include -#include -#include - -#include "character.hpp" -#include "laser.hpp" -#include "projectile.hpp" - -struct INPUT_COUNT -{ - int presses; - int releases; -}; - -static INPUT_COUNT count_input(int prev, int cur) -{ - INPUT_COUNT c = {0,0}; - prev &= INPUT_STATE_MASK; - cur &= INPUT_STATE_MASK; - int i = prev; - while(i != cur) - { - i = (i+1)&INPUT_STATE_MASK; - if(i&1) - c.presses++; - else - c.releases++; - } - - return c; -} - - -MACRO_ALLOC_POOL_ID_IMPL(CHARACTER, MAX_CLIENTS) - -// player -CHARACTER::CHARACTER() -: ENTITY(NETOBJTYPE_CHARACTER) -{ - proximity_radius = phys_size; -} - -void CHARACTER::reset() -{ - destroy(); -} - -bool CHARACTER::spawn(PLAYER *player, vec2 pos, int team) -{ - player_state = PLAYERSTATE_UNKNOWN; - emote_stop = -1; - last_action = -1; - active_weapon = WEAPON_GUN; - last_weapon = WEAPON_HAMMER; - queued_weapon = -1; - - //clear(); - this->player = player; - this->pos = pos; - this->team = team; - - core.reset(); - core.world = &game.world.core; - core.pos = pos; - game.world.core.characters[player->client_id] = &core; - - reckoning_tick = 0; - mem_zero(&sendcore, sizeof(sendcore)); - mem_zero(&reckoningcore, sizeof(reckoningcore)); - - game.world.insert_entity(this); - alive = true; - player->force_balanced = false; - - game.controller->on_character_spawn(this); - - return true; -} - -void CHARACTER::destroy() -{ - game.world.core.characters[player->client_id] = 0; - alive = false; -} - -void CHARACTER::set_weapon(int w) -{ - if(w == active_weapon) - return; - - last_weapon = active_weapon; - queued_weapon = -1; - active_weapon = w; - if(active_weapon < 0 || active_weapon >= NUM_WEAPONS) - active_weapon = 0; - - game.create_sound(pos, SOUND_WEAPON_SWITCH); -} - -bool CHARACTER::is_grounded() -{ - if(col_check_point((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2+5))) - return true; - if(col_check_point((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2+5))) - return true; - return false; -} - - -int CHARACTER::handle_ninja() -{ - if(active_weapon != WEAPON_NINJA) - return 0; - - vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); - - if ((server_tick() - ninja.activationtick) > (data->weapons.ninja.duration * server_tickspeed() / 1000)) - { - // time's up, return - weapons[WEAPON_NINJA].got = false; - active_weapon = last_weapon; - if(active_weapon == WEAPON_NINJA) - active_weapon = WEAPON_GUN; - set_weapon(active_weapon); - return 0; - } - - // force ninja weapon - set_weapon(WEAPON_NINJA); - - ninja.currentmovetime--; - - if (ninja.currentmovetime == 0) - { - // reset player velocity - core.vel *= 0.2f; - //return MODIFIER_RETURNFLAGS_OVERRIDEWEAPON; - } - - if (ninja.currentmovetime > 0) - { - // Set player velocity - core.vel = ninja.activationdir * data->weapons.ninja.velocity; - vec2 oldpos = pos; - move_box(&core.pos, &core.vel, vec2(phys_size, phys_size), 0.0f); - // reset velocity so the client doesn't predict stuff - core.vel = vec2(0.0f,0.0f); - if ((ninja.currentmovetime % 2) == 0) - { - //create_smoke(pos); - } - - // check if we hit anything along the way - { - CHARACTER *ents[64]; - vec2 dir = pos - oldpos; - float radius = phys_size * 2.0f; //length(dir * 0.5f); - vec2 center = oldpos + dir * 0.5f; - int num = game.world.find_entities(center, radius, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER); - - for (int i = 0; i < num; i++) - { - // Check if entity is a player - if (ents[i] == this) - continue; - // make sure we haven't hit this object before - bool balreadyhit = false; - for (int j = 0; j < numobjectshit; j++) - { - if (hitobjects[j] == ents[i]) - balreadyhit = true; - } - if (balreadyhit) - continue; - - // check so we are sufficiently close - if (distance(ents[i]->pos, pos) > (phys_size * 2.0f)) - continue; - - // hit a player, give him damage and stuffs... - game.create_sound(ents[i]->pos, SOUND_NINJA_HIT); - // set his velocity to fast upward (for now) - if(numobjectshit < 10) - hitobjects[numobjectshit++] = ents[i]; - - ents[i]->take_damage(vec2(0,10.0f), data->weapons.ninja.base->damage, player->client_id,WEAPON_NINJA); - } - } - return 0; - } - - return 0; -} - - -void CHARACTER::do_weaponswitch() -{ - if(reload_timer != 0) // make sure we have reloaded - return; - - if(queued_weapon == -1) // check for a queued weapon - return; - - if(weapons[WEAPON_NINJA].got) // if we have ninja, no weapon selection is possible - return; - - // switch weapon - set_weapon(queued_weapon); -} - -void CHARACTER::handle_weaponswitch() -{ - int wanted_weapon = active_weapon; - if(queued_weapon != -1) - wanted_weapon = queued_weapon; - - // select weapon - int next = count_input(latest_previnput.next_weapon, latest_input.next_weapon).presses; - int prev = count_input(latest_previnput.prev_weapon, latest_input.prev_weapon).presses; - - if(next < 128) // make sure we only try sane stuff - { - while(next) // next weapon selection - { - wanted_weapon = (wanted_weapon+1)%NUM_WEAPONS; - if(weapons[wanted_weapon].got) - next--; - } - } - - if(prev < 128) // make sure we only try sane stuff - { - while(prev) // prev weapon selection - { - wanted_weapon = (wanted_weapon-1)<0?NUM_WEAPONS-1:wanted_weapon-1; - if(weapons[wanted_weapon].got) - prev--; - } - } - - // direct weapon selection - if(latest_input.wanted_weapon) - wanted_weapon = input.wanted_weapon-1; - - // check for insane values - if(wanted_weapon >= 0 && wanted_weapon < NUM_WEAPONS && wanted_weapon != active_weapon && weapons[wanted_weapon].got) - queued_weapon = wanted_weapon; - - do_weaponswitch(); -} - -void CHARACTER::fire_weapon() -{ - if(reload_timer != 0) - return; - - do_weaponswitch(); - - vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); - - bool fullauto = false; - if(active_weapon == WEAPON_GRENADE || active_weapon == WEAPON_SHOTGUN || active_weapon == WEAPON_RIFLE) - fullauto = true; - - - // check if we gonna fire - bool will_fire = false; - if(count_input(latest_previnput.fire, latest_input.fire).presses) will_fire = true; - if(fullauto && (latest_input.fire&1) && weapons[active_weapon].ammo) will_fire = true; - if(!will_fire) - return; - - // check for ammo - if(!weapons[active_weapon].ammo) - { - // 125ms is a magical limit of how fast a human can click - reload_timer = 125 * server_tickspeed() / 1000;; - game.create_sound(pos, SOUND_WEAPON_NOAMMO); - return; - } - - vec2 projectile_startpos = pos+direction*phys_size*0.75f; - - switch(active_weapon) - { - case WEAPON_HAMMER: - { - // reset objects hit - numobjectshit = 0; - game.create_sound(pos, SOUND_HAMMER_FIRE); - - CHARACTER *ents[64]; - int hits = 0; - int num = game.world.find_entities(pos+direction*phys_size*0.75f, phys_size*0.5f, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER); - - for (int i = 0; i < num; i++) - { - CHARACTER *target = ents[i]; - if (target == this) - continue; - - // hit a player, give him damage and stuffs... - vec2 fdir = normalize(ents[i]->pos - pos); - - // set his velocity to fast upward (for now) - game.create_hammerhit(pos); - ents[i]->take_damage(vec2(0,-1.0f), data->weapons.hammer.base->damage, player->client_id, active_weapon); - vec2 dir; - if (length(target->pos - pos) > 0.0f) - dir = normalize(target->pos - pos); - else - dir = vec2(0,-1); - - target->core.vel += normalize(dir + vec2(0,-1.1f)) * 10.0f; - hits++; - } - - // if we hit anything, we have to wait for the reload - if(hits) - reload_timer = server_tickspeed()/3; - - } break; - - case WEAPON_GUN: - { - PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, - player->client_id, - projectile_startpos, - direction, - (int)(server_tickspeed()*tuning.gun_lifetime), - 1, 0, 0, -1, WEAPON_GUN); - - // pack the projectile and send it to the client directly - NETOBJ_PROJECTILE p; - proj->fill_info(&p); - - msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); - msg_pack_int(1); - for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) - msg_pack_int(((int *)&p)[i]); - msg_pack_end(); - server_send_msg(player->client_id); - - game.create_sound(pos, SOUND_GUN_FIRE); - } break; - - case WEAPON_SHOTGUN: - { - int shotspread = 2; - - msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); - msg_pack_int(shotspread*2+1); - - for(int i = -shotspread; i <= shotspread; i++) - { - float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; - float a = get_angle(direction); - a += spreading[i+2]; - float v = 1-(abs(i)/(float)shotspread); - float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v); - PROJECTILE *proj = new PROJECTILE(WEAPON_SHOTGUN, - player->client_id, - projectile_startpos, - vec2(cosf(a), sinf(a))*speed, - (int)(server_tickspeed()*tuning.shotgun_lifetime), - 1, 0, 0, -1, WEAPON_SHOTGUN); - - // pack the projectile and send it to the client directly - NETOBJ_PROJECTILE p; - proj->fill_info(&p); - - for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) - msg_pack_int(((int *)&p)[i]); - } - - msg_pack_end(); - server_send_msg(player->client_id); - - game.create_sound(pos, SOUND_SHOTGUN_FIRE); - } break; - - case WEAPON_GRENADE: - { - PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, - player->client_id, - projectile_startpos, - direction, - (int)(server_tickspeed()*tuning.grenade_lifetime), - 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); - - // pack the projectile and send it to the client directly - NETOBJ_PROJECTILE p; - proj->fill_info(&p); - - msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); - msg_pack_int(1); - for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) - msg_pack_int(((int *)&p)[i]); - msg_pack_end(); - server_send_msg(player->client_id); - - game.create_sound(pos, SOUND_GRENADE_FIRE); - } break; - - case WEAPON_RIFLE: - { - new LASER(pos, direction, tuning.laser_reach, player->client_id); - game.create_sound(pos, SOUND_RIFLE_FIRE); - } break; - - case WEAPON_NINJA: - { - attack_tick = server_tick(); - ninja.activationdir = direction; - ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 1000; - - //reload_timer = data->weapons.ninja.base->firedelay * server_tickspeed() / 1000 + server_tick(); - - // reset hit objects - numobjectshit = 0; - - game.create_sound(pos, SOUND_NINJA_FIRE); - - } break; - - } - - if(weapons[active_weapon].ammo > 0) // -1 == unlimited - weapons[active_weapon].ammo--; - attack_tick = server_tick(); - if(!reload_timer) - reload_timer = data->weapons.id[active_weapon].firedelay * server_tickspeed() / 1000; -} - -int CHARACTER::handle_weapons() -{ - vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); - - /* - if(config.dbg_stress) - { - for(int i = 0; i < NUM_WEAPONS; i++) - { - weapons[i].got = true; - weapons[i].ammo = 10; - } - - if(reload_timer) // twice as fast reload - reload_timer--; - } */ - - //if(active_weapon == WEAPON_NINJA) - handle_ninja(); - - - // check reload timer - if(reload_timer) - { - reload_timer--; - return 0; - } - - /* - if (active_weapon == WEAPON_NINJA) - { - // don't update other weapons while ninja is active - return handle_ninja(); - }*/ - - // fire weapon, if wanted - fire_weapon(); - - // ammo regen - int ammoregentime = data->weapons.id[active_weapon].ammoregentime; - if(ammoregentime) - { - // If equipped and not active, regen ammo? - if (reload_timer <= 0) - { - if (weapons[active_weapon].ammoregenstart < 0) - weapons[active_weapon].ammoregenstart = server_tick(); - - if ((server_tick() - weapons[active_weapon].ammoregenstart) >= ammoregentime * server_tickspeed() / 1000) - { - // Add some ammo - weapons[active_weapon].ammo = min(weapons[active_weapon].ammo + 1, 10); - weapons[active_weapon].ammoregenstart = -1; - } - } - else - { - weapons[active_weapon].ammoregenstart = -1; - } - } - - return 0; -} - -void CHARACTER::on_predicted_input(NETOBJ_PLAYER_INPUT *new_input) -{ - // check for changes - if(mem_comp(&input, new_input, sizeof(NETOBJ_PLAYER_INPUT)) != 0) - last_action = server_tick(); - - // copy new input - mem_copy(&input, new_input, sizeof(input)); - num_inputs++; - - // or are not allowed to aim in the center - if(input.target_x == 0 && input.target_y == 0) - input.target_y = -1; -} - -void CHARACTER::on_direct_input(NETOBJ_PLAYER_INPUT *new_input) -{ - mem_copy(&latest_previnput, &latest_input, sizeof(latest_input)); - mem_copy(&latest_input, new_input, sizeof(latest_input)); - - if(num_inputs > 2 && team != -1) - { - handle_weaponswitch(); - fire_weapon(); - } - - mem_copy(&latest_previnput, &latest_input, sizeof(latest_input)); -} - -void CHARACTER::tick() -{ - if(player->force_balanced) - { - char buf[128]; - str_format(buf, sizeof(buf), "You were moved to %s due to team balancing", game.controller->get_team_name(team)); - game.send_broadcast(buf, player->client_id); - - player->force_balanced = false; - } - - //player_core core; - //core.pos = pos; - //core.jumped = jumped; - core.input = input; - core.tick(true); - - float phys_size = 28.0f; - // handle death-tiles - if(col_get((int)(pos.x+phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH || - col_get((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH || - col_get((int)(pos.x-phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH || - col_get((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH) - { - die(player->client_id, WEAPON_WORLD); - } - - // handle weapons - handle_weapons(); - - player_state = input.player_state; - - // Previnput - previnput = input; - return; -} - -void CHARACTER::tick_defered() -{ - // advance the dummy - { - WORLD_CORE tempworld; - reckoningcore.world = &tempworld; - reckoningcore.tick(false); - reckoningcore.move(); - reckoningcore.quantize(); - } - - //lastsentcore; - /*if(!dead) - {*/ - vec2 start_pos = core.pos; - vec2 start_vel = core.vel; - bool stuck_before = test_box(core.pos, vec2(28.0f, 28.0f)); - - core.move(); - bool stuck_after_move = test_box(core.pos, vec2(28.0f, 28.0f)); - core.quantize(); - bool stuck_after_quant = test_box(core.pos, vec2(28.0f, 28.0f)); - pos = core.pos; - - if(!stuck_before && (stuck_after_move || stuck_after_quant)) - { - dbg_msg("player", "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", - stuck_before, - stuck_after_move, - stuck_after_quant, - start_pos.x, start_pos.y, - start_vel.x, start_vel.y, - *((unsigned *)&start_pos.x), *((unsigned *)&start_pos.y), - *((unsigned *)&start_vel.x), *((unsigned *)&start_vel.y)); - } - - int events = core.triggered_events; - int mask = cmask_all_except_one(player->client_id); - - if(events&COREEVENT_GROUND_JUMP) game.create_sound(pos, SOUND_PLAYER_JUMP, mask); - - //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); - if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all()); - if(events&COREEVENT_HOOK_ATTACH_GROUND) game.create_sound(pos, SOUND_HOOK_ATTACH_GROUND, mask); - if(events&COREEVENT_HOOK_HIT_NOHOOK) game.create_sound(pos, SOUND_HOOK_NOATTACH, mask); - //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); - //} - - if(team == -1) - { - pos.x = input.target_x; - pos.y = input.target_y; - } - - // update the sendcore if needed - { - NETOBJ_CHARACTER predicted; - NETOBJ_CHARACTER current; - mem_zero(&predicted, sizeof(predicted)); - mem_zero(¤t, sizeof(current)); - reckoningcore.write(&predicted); - core.write(¤t); - - // only allow dead reackoning for a top of 3 seconds - if(reckoning_tick+server_tickspeed()*3 < server_tick() || mem_comp(&predicted, ¤t, sizeof(NETOBJ_CHARACTER)) != 0) - { - reckoning_tick = server_tick(); - sendcore = core; - reckoningcore = core; - } - } -} - -bool CHARACTER::increase_health(int amount) -{ - if(health >= 10) - return false; - health = clamp(health+amount, 0, 10); - return true; -} - -bool CHARACTER::increase_armor(int amount) -{ - if(armor >= 10) - return false; - armor = clamp(armor+amount, 0, 10); - return true; -} - -void CHARACTER::die(int killer, int weapon) -{ - /*if (dead || team == -1) - return;*/ - int mode_special = game.controller->on_character_death(this, game.players[killer], weapon); - - dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", - killer, server_clientname(killer), - player->client_id, server_clientname(player->client_id), weapon, mode_special); - - // send the kill message - NETMSG_SV_KILLMSG msg; - msg.killer = killer; - msg.victim = player->client_id; - msg.weapon = weapon; - msg.mode_special = mode_special; - msg.pack(MSGFLAG_VITAL); - server_send_msg(-1); - - // a nice sound - game.create_sound(pos, SOUND_PLAYER_DIE); - - // set dead state - // TODO: do stuff here - /* - die_pos = pos; - dead = true; - */ - - // this is for auto respawn after 3 secs - player->die_tick = server_tick(); - - alive = false; - game.world.remove_entity(this); - game.world.core.characters[player->client_id] = 0; - game.create_death(pos, player->client_id); - - // we got to wait 0.5 secs before respawning - player->respawn_tick = server_tick()+server_tickspeed()/2; -} - -bool CHARACTER::take_damage(vec2 force, int dmg, int from, int weapon) -{ - core.vel += force; - - if(game.controller->is_friendly_fire(player->client_id, from) && !config.sv_teamdamage) - return false; - - // player only inflicts half damage on self - if(from == player->client_id) - dmg = max(1, dmg/2); - - damage_taken++; - - // create healthmod indicator - if(server_tick() < damage_taken_tick+25) - { - // make sure that the damage indicators doesn't group together - game.create_damageind(pos, damage_taken*0.25f, dmg); - } - else - { - damage_taken = 0; - game.create_damageind(pos, 0, dmg); - } - - if(dmg) - { - if(armor) - { - if(dmg > 1) - { - health--; - dmg--; - } - - if(dmg > armor) - { - dmg -= armor; - armor = 0; - } - else - { - armor -= dmg; - dmg = 0; - } - } - - health -= dmg; - } - - damage_taken_tick = server_tick(); - - // do damage hit sound - if(from >= 0 && from != player->client_id && game.players[from]) - game.create_sound(game.players[from]->view_pos, SOUND_HIT, cmask_one(from)); - - // check for death - if(health <= 0) - { - die(from, weapon); - - // set attacker's face to happy (taunt!) - if (from >= 0 && from != player->client_id && game.players[from]) - { - CHARACTER *chr = game.players[from]->get_character(); - if (chr) - { - chr->emote_type = EMOTE_HAPPY; - chr->emote_stop = server_tick() + server_tickspeed(); - } - } - - return false; - } - - if (dmg > 2) - game.create_sound(pos, SOUND_PLAYER_PAIN_LONG); - else - game.create_sound(pos, SOUND_PLAYER_PAIN_SHORT); - - emote_type = EMOTE_PAIN; - emote_stop = server_tick() + 500 * server_tickspeed() / 1000; - - // spawn blood? - return true; -} - -void CHARACTER::snap(int snapping_client) -{ - if(networkclipped(snapping_client)) - return; - - NETOBJ_CHARACTER *character = (NETOBJ_CHARACTER *)snap_new_item(NETOBJTYPE_CHARACTER, player->client_id, sizeof(NETOBJ_CHARACTER)); - - // write down the core - if(game.world.paused) - { - // no dead reckoning when paused because the client doesn't know - // how far to perform the reckoning - character->tick = 0; - core.write(character); - } - else - { - character->tick = reckoning_tick; - sendcore.write(character); - } - - // set emote - if (emote_stop < server_tick()) - { - emote_type = EMOTE_NORMAL; - emote_stop = -1; - } - - character->emote = emote_type; - - character->ammocount = 0; - character->health = 0; - character->armor = 0; - - character->weapon = active_weapon; - character->attacktick = attack_tick; - - character->direction = input.direction; - - if(player->client_id == snapping_client) - { - character->health = health; - character->armor = armor; - if(weapons[active_weapon].ammo > 0) - character->ammocount = weapons[active_weapon].ammo; - } - - if (character->emote == EMOTE_NORMAL) - { - if(250 - ((server_tick() - last_action)%(250)) < 5) - character->emote = EMOTE_BLINK; - } - - character->player_state = player_state; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.hpp deleted file mode 100644 index bd2f7afe8..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/character.hpp +++ /dev/null @@ -1,134 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifndef GAME_SERVER_ENTITY_CHARACTER_H -#define GAME_SERVER_ENTITY_CHARACTER_H - -#include -#include -#include - -#include - -enum -{ - WEAPON_GAME = -3, // team switching etc - WEAPON_SELF = -2, // console kill command - WEAPON_WORLD = -1, // death tiles etc -}; - -class CHARACTER : public ENTITY -{ - MACRO_ALLOC_POOL_ID() -public: - // player controlling this character - class PLAYER *player; - - bool alive; - - // weapon info - ENTITY *hitobjects[10]; - int numobjectshit; - struct WEAPONSTAT - { - int ammoregenstart; - int ammo; - int ammocost; - bool got; - } weapons[NUM_WEAPONS]; - - int active_weapon; - int last_weapon; - int queued_weapon; - - int reload_timer; - int attack_tick; - - int damage_taken; - - int emote_type; - int emote_stop; - - // TODO: clean this up - char skin_name[64]; - int use_custom_color; - int color_body; - int color_feet; - - int last_action; // last tick that the player took any action ie some input - - // these are non-heldback inputs - NETOBJ_PLAYER_INPUT latest_previnput; - NETOBJ_PLAYER_INPUT latest_input; - - // input - NETOBJ_PLAYER_INPUT previnput; - NETOBJ_PLAYER_INPUT input; - int num_inputs; - int jumped; - - int damage_taken_tick; - - int health; - int armor; - - // ninja - struct - { - vec2 activationdir; - int activationtick; - int currentmovetime; - } ninja; - - // - //int score; - int team; - int player_state; // if the client is chatting, accessing a menu or so - - // the player core for the physics - CHARACTER_CORE core; - - // info for dead reckoning - int reckoning_tick; // tick that we are performing dead reckoning from - CHARACTER_CORE sendcore; // core that we should send - CHARACTER_CORE reckoningcore; // the dead reckoning core - - // - CHARACTER(); - - virtual void reset(); - virtual void destroy(); - - bool is_grounded(); - - void set_weapon(int w); - - void handle_weaponswitch(); - void do_weaponswitch(); - - int handle_weapons(); - int handle_ninja(); - - void on_predicted_input(NETOBJ_PLAYER_INPUT *new_input); - void on_direct_input(NETOBJ_PLAYER_INPUT *new_input); - void fire_weapon(); - - void die(int killer, int weapon); - - bool take_damage(vec2 force, int dmg, int from, int weapon); - - - bool spawn(PLAYER *player, vec2 pos, int team); - //bool init_tryspawn(int team); - bool remove(); - - static const int phys_size = 28; - - virtual void tick(); - virtual void tick_defered(); - virtual void snap(int snapping_client); - - bool increase_health(int amount); - bool increase_armor(int amount); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.cpp deleted file mode 100644 index 2c6fa0ff7..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include "laser.hpp" - -////////////////////////////////////////////////// -// laser -////////////////////////////////////////////////// -LASER::LASER(vec2 pos, vec2 direction, float start_energy, int owner) -: ENTITY(NETOBJTYPE_LASER) -{ - this->pos = pos; - this->owner = owner; - energy = start_energy; - dir = direction; - bounces = 0; - do_bounce(); - - game.world.insert_entity(this); -} - - -bool LASER::hit_character(vec2 from, vec2 to) -{ - vec2 at; - CHARACTER *owner_char = game.get_player_char(owner); - CHARACTER *hit = game.world.intersect_character(pos, to, 0.0f, at, owner_char); - if(!hit) - return false; - - this->from = from; - pos = at; - energy = -1; - hit->take_damage(vec2(0,0), tuning.laser_damage, owner, WEAPON_RIFLE); - return true; -} - -void LASER::do_bounce() -{ - eval_tick = server_tick(); - - if(energy < 0) - { - //dbg_msg("laser", "%d removed", server_tick()); - game.world.destroy_entity(this); - return; - } - - vec2 to = pos + dir*energy; - vec2 org_to = to; - - if(col_intersect_line(pos, to, 0x0, &to)) - { - if(!hit_character(pos, to)) - { - // intersected - from = pos; - pos = to; - - vec2 temp_pos = pos; - vec2 temp_dir = dir*4.0f; - - move_point(&temp_pos, &temp_dir, 1.0f, 0); - pos = temp_pos; - dir = normalize(temp_dir); - - energy -= distance(from, pos) + tuning.laser_bounce_cost; - bounces++; - - if(bounces > tuning.laser_bounce_num) - energy = -1; - - game.create_sound(pos, SOUND_RIFLE_BOUNCE); - } - } - else - { - if(!hit_character(pos, to)) - { - from = pos; - pos = to; - energy = -1; - } - } - - //dbg_msg("laser", "%d done %f %f %f %f", server_tick(), from.x, from.y, pos.x, pos.y); -} - -void LASER::reset() -{ - game.world.destroy_entity(this); -} - -void LASER::tick() -{ - if(server_tick() > eval_tick+(server_tickspeed()*tuning.laser_bounce_delay)/1000.0f) - { - do_bounce(); - } - -} - -void LASER::snap(int snapping_client) -{ - if(networkclipped(snapping_client)) - return; - - NETOBJ_LASER *obj = (NETOBJ_LASER *)snap_new_item(NETOBJTYPE_LASER, id, sizeof(NETOBJ_LASER)); - obj->x = (int)pos.x; - obj->y = (int)pos.y; - obj->from_x = (int)from.x; - obj->from_y = (int)from.y; - obj->start_tick = eval_tick; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.hpp deleted file mode 100644 index aa4c22843..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/laser.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifndef GAME_SERVER_ENTITY_LASER_H -#define GAME_SERVER_ENTITY_LASER_H - -#include - -class CHARACTER; - -class LASER : public ENTITY -{ - vec2 from; - vec2 dir; - float energy; - int bounces; - int eval_tick; - int owner; - - bool hit_character(vec2 from, vec2 to); - void do_bounce(); - -public: - - LASER(vec2 pos, vec2 direction, float start_energy, int owner); - - virtual void reset(); - virtual void tick(); - virtual void snap(int snapping_client); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.cpp deleted file mode 100644 index 92d5c3e75..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -#include -#include "pickup.hpp" - -////////////////////////////////////////////////// -// pickup -////////////////////////////////////////////////// -PICKUP::PICKUP(int _type, int _subtype) -: ENTITY(NETOBJTYPE_PICKUP) -{ - type = _type; - subtype = _subtype; - proximity_radius = phys_size; - - reset(); - - // TODO: should this be done here? - game.world.insert_entity(this); -} - -void PICKUP::reset() -{ - if (data->pickups[type].spawndelay > 0) - spawntick = server_tick() + server_tickspeed() * data->pickups[type].spawndelay; - else - spawntick = -1; -} - -void PICKUP::tick() -{ - // wait for respawn - if(spawntick > 0) - { - if(server_tick() > spawntick) - { - // respawn - spawntick = -1; - - if(type == POWERUP_WEAPON) - game.create_sound(pos, SOUND_WEAPON_SPAWN); - } - else - return; - } - - // Check if a player intersected us - CHARACTER *chr = game.world.closest_character(pos, 20.0f, 0); - if(chr && chr->alive) - { - // player picked us up, is someone was hooking us, let them go - int respawntime = -1; - switch (type) - { - case POWERUP_HEALTH: - if(chr->increase_health(1)) - { - game.create_sound(pos, SOUND_PICKUP_HEALTH); - respawntime = data->pickups[type].respawntime; - } - break; - case POWERUP_ARMOR: - if(chr->increase_armor(1)) - { - game.create_sound(pos, SOUND_PICKUP_ARMOR); - respawntime = data->pickups[type].respawntime; - } - break; - - case POWERUP_WEAPON: - if(subtype >= 0 && subtype < NUM_WEAPONS) - { - if(chr->weapons[subtype].ammo < data->weapons.id[subtype].maxammo || !chr->weapons[subtype].got) - { - chr->weapons[subtype].got = true; - chr->weapons[subtype].ammo = min(data->weapons.id[subtype].maxammo, chr->weapons[subtype].ammo + 10); - respawntime = data->pickups[type].respawntime; - - // TODO: data compiler should take care of stuff like this - if(subtype == WEAPON_GRENADE) - game.create_sound(pos, SOUND_PICKUP_GRENADE); - else if(subtype == WEAPON_SHOTGUN) - game.create_sound(pos, SOUND_PICKUP_SHOTGUN); - else if(subtype == WEAPON_RIFLE) - game.create_sound(pos, SOUND_PICKUP_SHOTGUN); - - if(chr->player) - game.send_weapon_pickup(chr->player->client_id, subtype); - } - } - break; - case POWERUP_NINJA: - { - // activate ninja on target player - chr->ninja.activationtick = server_tick(); - chr->weapons[WEAPON_NINJA].got = true; - chr->weapons[WEAPON_NINJA].ammo = -1; - chr->last_weapon = chr->active_weapon; - chr->active_weapon = WEAPON_NINJA; - respawntime = data->pickups[type].respawntime; - game.create_sound(pos, SOUND_PICKUP_NINJA); - - // loop through all players, setting their emotes - ENTITY *ents[64]; - int num = game.world.find_entities(vec2(0, 0), 1000000, ents, 64, NETOBJTYPE_CHARACTER); - for (int i = 0; i < num; i++) - { - CHARACTER *c = (CHARACTER *)ents[i]; - if (c != chr) - { - c->emote_type = EMOTE_SURPRISE; - c->emote_stop = server_tick() + server_tickspeed(); - } - } - - chr->emote_type = EMOTE_ANGRY; - chr->emote_stop = server_tick() + 1200 * server_tickspeed() / 1000; - - break; - } - default: - break; - }; - - if(respawntime >= 0) - { - dbg_msg("game", "pickup player='%d:%s' item=%d/%d", - chr->player->client_id, server_clientname(chr->player->client_id), type, subtype); - spawntick = server_tick() + server_tickspeed() * respawntime; - } - } -} - -void PICKUP::snap(int snapping_client) -{ - if(spawntick != -1) - return; - - NETOBJ_PICKUP *up = (NETOBJ_PICKUP *)snap_new_item(NETOBJTYPE_PICKUP, id, sizeof(NETOBJ_PICKUP)); - up->x = (int)pos.x; - up->y = (int)pos.y; - up->type = type; // TODO: two diffrent types? what gives? - up->subtype = subtype; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.hpp deleted file mode 100644 index cd480d92a..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/pickup.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifndef GAME_SERVER_ENTITY_PICKUP_H -#define GAME_SERVER_ENTITY_PICKUP_H - -#include - -// TODO: move to seperate file -class PICKUP : public ENTITY -{ -public: - static const int phys_size = 14; - - int type; - int subtype; // weapon type for instance? - int spawntick; - PICKUP(int _type, int _subtype = 0); - - virtual void reset(); - virtual void tick(); - virtual void snap(int snapping_client); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.cpp deleted file mode 100644 index 2a8de766b..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include -#include -#include "projectile.hpp" - - -////////////////////////////////////////////////// -// projectile -////////////////////////////////////////////////// -PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, - int damage, int flags, float force, int sound_impact, int weapon) -: ENTITY(NETOBJTYPE_PROJECTILE) -{ - this->type = type; - this->pos = pos; - this->direction = dir; - this->lifespan = span; - this->owner = owner; - this->flags = flags; - this->force = force; - this->damage = damage; - this->sound_impact = sound_impact; - this->weapon = weapon; - this->bounce = 0; - this->start_tick = server_tick(); - game.world.insert_entity(this); -} - -void PROJECTILE::reset() -{ - game.world.destroy_entity(this); -} - -vec2 PROJECTILE::get_pos(float time) -{ - float curvature = 0; - float speed = 0; - if(type == WEAPON_GRENADE) - { - curvature = tuning.grenade_curvature; - speed = tuning.grenade_speed; - } - else if(type == WEAPON_SHOTGUN) - { - curvature = tuning.shotgun_curvature; - speed = tuning.shotgun_speed; - } - else if(type == WEAPON_GUN) - { - curvature = tuning.gun_curvature; - speed = tuning.gun_speed; - } - - return calc_pos(pos, direction, curvature, speed, time); -} - - -void PROJECTILE::tick() -{ - - float pt = (server_tick()-start_tick-1)/(float)server_tickspeed(); - float ct = (server_tick()-start_tick)/(float)server_tickspeed(); - vec2 prevpos = get_pos(pt); - vec2 curpos = get_pos(ct); - - lifespan--; - - int collide = col_intersect_line(prevpos, curpos, &curpos, 0); - //int collide = col_check_point((int)curpos.x, (int)curpos.y); - CHARACTER *ownerchar = game.get_player_char(owner); - CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, ownerchar); - if(targetchr || collide || lifespan < 0) - { - if(lifespan >= 0 || weapon == WEAPON_GRENADE) - game.create_sound(curpos, sound_impact); - - if(flags & PROJECTILE_FLAGS_EXPLODE) - game.create_explosion(curpos, owner, weapon, false); - else if(targetchr) - targetchr->take_damage(direction * max(0.001f, force), damage, owner, weapon); - - game.world.destroy_entity(this); - } -} - -void PROJECTILE::fill_info(NETOBJ_PROJECTILE *proj) -{ - proj->x = (int)pos.x; - proj->y = (int)pos.y; - proj->vx = (int)(direction.x*100.0f); - proj->vy = (int)(direction.y*100.0f); - proj->start_tick = start_tick; - proj->type = type; -} - -void PROJECTILE::snap(int snapping_client) -{ - float ct = (server_tick()-start_tick)/(float)server_tickspeed(); - - if(networkclipped(snapping_client, get_pos(ct))) - return; - - NETOBJ_PROJECTILE *proj = (NETOBJ_PROJECTILE *)snap_new_item(NETOBJTYPE_PROJECTILE, id, sizeof(NETOBJ_PROJECTILE)); - fill_info(proj); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.hpp deleted file mode 100644 index a5c3b88f6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entities/projectile.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#ifndef GAME_SERVER_ENTITY_PROJECTILE_H -#define GAME_SERVER_ENTITY_PROJECTILE_H - -class PROJECTILE : public ENTITY -{ -public: - enum - { - PROJECTILE_FLAGS_EXPLODE = 1 << 0, - }; - - vec2 direction; - int lifespan; - int owner; - int type; - int flags; - int damage; - int sound_impact; - int weapon; - int bounce; - float force; - int start_tick; - - PROJECTILE(int type, int owner, vec2 pos, vec2 vel, int span, - int damage, int flags, float force, int sound_impact, int weapon); - - vec2 get_pos(float time); - void fill_info(NETOBJ_PROJECTILE *proj); - - virtual void reset(); - virtual void tick(); - virtual void snap(int snapping_client); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entity.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entity.cpp deleted file mode 100644 index 8e3345ab3..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entity.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -#include -#include "entity.hpp" -#include "gamecontext.hpp" - -////////////////////////////////////////////////// -// Entity -////////////////////////////////////////////////// -ENTITY::ENTITY(int objtype) -{ - this->objtype = objtype; - pos = vec2(0,0); - proximity_radius = 0; - - marked_for_destroy = false; - id = snap_new_id(); - - next_entity = 0; - prev_entity = 0; - prev_type_entity = 0; - next_type_entity = 0; -} - -ENTITY::~ENTITY() -{ - game.world.remove_entity(this); - snap_free_id(id); -} - -int ENTITY::networkclipped(int snapping_client) -{ - return networkclipped(snapping_client, pos); -} - -int ENTITY::networkclipped(int snapping_client, vec2 check_pos) -{ - if(snapping_client == -1) - return 0; - - float dx = game.players[snapping_client]->view_pos.x-check_pos.x; - float dy = game.players[snapping_client]->view_pos.y-check_pos.y; - - if(fabs(dx) > 1000.0f || fabs(dy) > 800.0f) - return 1; - - if(distance(game.players[snapping_client]->view_pos, check_pos) > 1100.0f) - return 1; - return 0; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/entity.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/entity.hpp deleted file mode 100644 index 6bdb25dee..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/entity.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef GAME_SERVER_ENTITY_H -#define GAME_SERVER_ENTITY_H - -#include -#include -#include - -#define MACRO_ALLOC_HEAP() \ - public: \ - void *operator new(size_t size) \ - { \ - void *p = mem_alloc(size, 1); \ - /*dbg_msg("", "++ %p %d", p, size);*/ \ - mem_zero(p, size); \ - return p; \ - } \ - void operator delete(void *p) \ - { \ - /*dbg_msg("", "-- %p", p);*/ \ - mem_free(p); \ - } \ - private: - -#define MACRO_ALLOC_POOL_ID() \ - public: \ - void *operator new(size_t size, int id); \ - void operator delete(void *p); \ - private: - -#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, poolsize) \ - static char pool_data_##POOLTYPE[poolsize][sizeof(POOLTYPE)] = {{0}}; \ - static int pool_used_##POOLTYPE[poolsize] = {0}; \ - void *POOLTYPE::operator new(size_t size, int id) \ - { \ - dbg_assert(sizeof(POOLTYPE) == size, "size error"); \ - dbg_assert(!pool_used_##POOLTYPE[id], "already used"); \ - /*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \ - pool_used_##POOLTYPE[id] = 1; \ - mem_zero(pool_data_##POOLTYPE[id], size); \ - return pool_data_##POOLTYPE[id]; \ - } \ - void POOLTYPE::operator delete(void *p) \ - { \ - int id = (POOLTYPE*)p - (POOLTYPE*)pool_data_##POOLTYPE; \ - dbg_assert(pool_used_##POOLTYPE[id], "not used"); \ - /*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \ - pool_used_##POOLTYPE[id] = 0; \ - mem_zero(pool_data_##POOLTYPE[id], sizeof(POOLTYPE)); \ - } - -/* - Class: Entity - Basic entity class. -*/ -class ENTITY -{ - MACRO_ALLOC_HEAP() -private: - friend class GAMEWORLD; // thy these? - ENTITY *prev_entity; - ENTITY *next_entity; - - ENTITY *prev_type_entity; - ENTITY *next_type_entity; -protected: - bool marked_for_destroy; - int id; - int objtype; -public: - ENTITY(int objtype); - virtual ~ENTITY(); - - ENTITY *typenext() { return next_type_entity; } - ENTITY *typeprev() { return prev_type_entity; } - - /* - Function: destroy - Destorys the entity. - */ - virtual void destroy() { delete this; } - - /* - Function: reset - Called when the game resets the map. Puts the entity - back to it's starting state or perhaps destroys it. - */ - virtual void reset() {} - - /* - Function: tick - Called progress the entity to the next tick. Updates - and moves the entity to it's new state and position. - */ - virtual void tick() {} - - /* - Function: tick_defered - Called after all entities tick() function has been called. - */ - virtual void tick_defered() {} - - /* - Function: snap - Called when a new snapshot is being generated for a specific - client. - - Arguments: - snapping_client - ID of the client which snapshot is - being generated. Could be -1 to create a complete - snapshot of everything in the game for demo - recording. - */ - virtual void snap(int snapping_client) {} - - /* - Function: networkclipped(int snapping_client) - Performs a series of test to see if a client can see the - entity. - - Arguments: - snapping_client - ID of the client which snapshot is - being generated. Could be -1 to create a complete - snapshot of everything in the game for demo - recording. - - Returns: - Non-zero if the entity doesn't have to be in the snapshot. - */ - int networkclipped(int snapping_client); - int networkclipped(int snapping_client, vec2 check_pos); - - - /* - Variable: proximity_radius - Contains the physical size of the entity. - */ - float proximity_radius; - - /* - Variable: pos - Contains the current posititon of the entity. - */ - vec2 pos; -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.cpp deleted file mode 100644 index 761eaf2c6..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "eventhandler.hpp" -#include "gamecontext.hpp" - -////////////////////////////////////////////////// -// Event handler -////////////////////////////////////////////////// -EVENTHANDLER::EVENTHANDLER() -{ - clear(); -} - -void *EVENTHANDLER::create(int type, int size, int mask) -{ - if(num_events == MAX_EVENTS) - return 0; - if(current_offset+size >= MAX_DATASIZE) - return 0; - - void *p = &data[current_offset]; - offsets[num_events] = current_offset; - types[num_events] = type; - sizes[num_events] = size; - client_masks[num_events] = mask; - current_offset += size; - num_events++; - return p; -} - -void EVENTHANDLER::clear() -{ - num_events = 0; - current_offset = 0; -} - -void EVENTHANDLER::snap(int snapping_client) -{ - for(int i = 0; i < num_events; i++) - { - if(snapping_client == -1 || cmask_is_set(client_masks[i], snapping_client)) - { - NETEVENT_COMMON *ev = (NETEVENT_COMMON *)&data[offsets[i]]; - if(snapping_client == -1 || distance(game.players[snapping_client]->view_pos, vec2(ev->x, ev->y)) < 1500.0f) - { - void *d = snap_new_item(types[i], i, sizes[i]); - mem_copy(d, &data[offsets[i]], sizes[i]); - } - } - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.hpp deleted file mode 100644 index 4d5131545..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/eventhandler.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef GAME_SERVER_EVENTHANDLER_H -#define GAME_SERVER_EVENTHANDLER_H - -// -class EVENTHANDLER -{ - static const int MAX_EVENTS = 128; - static const int MAX_DATASIZE = 128*64; - - int types[MAX_EVENTS]; // TODO: remove some of these arrays - int offsets[MAX_EVENTS]; - int sizes[MAX_EVENTS]; - int client_masks[MAX_EVENTS]; - char data[MAX_DATASIZE]; - - int current_offset; - int num_events; -public: - EVENTHANDLER(); - void *create(int type, int size, int mask = -1); - void clear(); - void snap(int snapping_client); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.cpp deleted file mode 100644 index 9e53d6ffb..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include -#include -#include -#include "gamecontext.hpp" - -GAMECONTEXT game; - -GAMECONTEXT::GAMECONTEXT() -{ - for(int i = 0; i < MAX_CLIENTS; i++) - players[i] = 0; - - controller = 0; - vote_closetime = 0; -} - -GAMECONTEXT::~GAMECONTEXT() -{ - for(int i = 0; i < MAX_CLIENTS; i++) - delete players[i]; -} - -void GAMECONTEXT::clear() -{ - this->~GAMECONTEXT(); - mem_zero(this, sizeof(*this)); - new (this) GAMECONTEXT(); -} - - -class CHARACTER *GAMECONTEXT::get_player_char(int client_id) -{ - if(client_id < 0 || client_id >= MAX_CLIENTS || !players[client_id]) - return 0; - return players[client_id]->get_character(); -} - -void GAMECONTEXT::create_damageind(vec2 p, float angle, int amount) -{ - float a = 3 * 3.14159f / 2 + angle; - //float a = get_angle(dir); - float s = a-pi/3; - float e = a+pi/3; - for(int i = 0; i < amount; i++) - { - float f = mix(s, e, float(i+1)/float(amount+2)); - NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)events.create(NETEVENTTYPE_DAMAGEIND, sizeof(NETEVENT_DAMAGEIND)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - ev->angle = (int)(f*256.0f); - } - } -} - -void GAMECONTEXT::create_hammerhit(vec2 p) -{ - // create the event - NETEVENT_HAMMERHIT *ev = (NETEVENT_HAMMERHIT *)events.create(NETEVENTTYPE_HAMMERHIT, sizeof(NETEVENT_HAMMERHIT)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - } -} - - -void GAMECONTEXT::create_explosion(vec2 p, int owner, int weapon, bool bnodamage) -{ - // create the event - NETEVENT_EXPLOSION *ev = (NETEVENT_EXPLOSION *)events.create(NETEVENTTYPE_EXPLOSION, sizeof(NETEVENT_EXPLOSION)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - } - - if (!bnodamage) - { - // deal damage - CHARACTER *ents[64]; - float radius = 135.0f; - float innerradius = 48.0f; - int num = game.world.find_entities(p, radius, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER); - for(int i = 0; i < num; i++) - { - vec2 diff = ents[i]->pos - p; - vec2 forcedir(0,1); - float l = length(diff); - if(l) - forcedir = normalize(diff); - l = 1-clamp((l-innerradius)/(radius-innerradius), 0.0f, 1.0f); - float dmg = 6 * l; - if((int)dmg) - ents[i]->take_damage(forcedir*dmg*2, (int)dmg, owner, weapon); - } - } -} - -/* -void create_smoke(vec2 p) -{ - // create the event - EV_EXPLOSION *ev = (EV_EXPLOSION *)events.create(EVENT_SMOKE, sizeof(EV_EXPLOSION)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - } -}*/ - -void GAMECONTEXT::create_playerspawn(vec2 p) -{ - // create the event - NETEVENT_SPAWN *ev = (NETEVENT_SPAWN *)events.create(NETEVENTTYPE_SPAWN, sizeof(NETEVENT_SPAWN)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - } -} - -void GAMECONTEXT::create_death(vec2 p, int cid) -{ - // create the event - NETEVENT_DEATH *ev = (NETEVENT_DEATH *)events.create(NETEVENTTYPE_DEATH, sizeof(NETEVENT_DEATH)); - if(ev) - { - ev->x = (int)p.x; - ev->y = (int)p.y; - ev->cid = cid; - } -} - -void GAMECONTEXT::create_sound(vec2 pos, int sound, int mask) -{ - if (sound < 0) - return; - - // create a sound - NETEVENT_SOUNDWORLD *ev = (NETEVENT_SOUNDWORLD *)events.create(NETEVENTTYPE_SOUNDWORLD, sizeof(NETEVENT_SOUNDWORLD), mask); - if(ev) - { - ev->x = (int)pos.x; - ev->y = (int)pos.y; - ev->soundid = sound; - } -} - -void GAMECONTEXT::create_sound_global(int sound, int target) -{ - if (sound < 0) - return; - - NETMSG_SV_SOUNDGLOBAL msg; - msg.soundid = sound; - msg.pack(MSGFLAG_VITAL); - server_send_msg(target); -} - - -void GAMECONTEXT::send_chat_target(int to, const char *text) -{ - NETMSG_SV_CHAT msg; - msg.team = 0; - msg.cid = -1; - msg.message = text; - msg.pack(MSGFLAG_VITAL); - server_send_msg(to); -} - - -void GAMECONTEXT::send_chat(int chatter_cid, int team, const char *text) -{ - if(chatter_cid >= 0 && chatter_cid < MAX_CLIENTS) - dbg_msg("chat", "%d:%d:%s: %s", chatter_cid, team, server_clientname(chatter_cid), text); - else - dbg_msg("chat", "*** %s", text); - - if(team == CHAT_ALL) - { - NETMSG_SV_CHAT msg; - msg.team = 0; - msg.cid = chatter_cid; - msg.message = text; - msg.pack(MSGFLAG_VITAL); - server_send_msg(-1); - } - else - { - NETMSG_SV_CHAT msg; - msg.team = 1; - msg.cid = chatter_cid; - msg.message = text; - msg.pack(MSGFLAG_VITAL); - - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i] && game.players[i]->team == team) - server_send_msg(i); - } - } -} - -void GAMECONTEXT::send_emoticon(int cid, int emoticon) -{ - NETMSG_SV_EMOTICON msg; - msg.cid = cid; - msg.emoticon = emoticon; - msg.pack(MSGFLAG_VITAL); - server_send_msg(-1); -} - -void GAMECONTEXT::send_weapon_pickup(int cid, int weapon) -{ - NETMSG_SV_WEAPONPICKUP msg; - msg.weapon = weapon; - msg.pack(MSGFLAG_VITAL); - server_send_msg(cid); -} - - -void GAMECONTEXT::send_broadcast(const char *text, int cid) -{ - NETMSG_SV_BROADCAST msg; - msg.message = text; - msg.pack(MSGFLAG_VITAL); - server_send_msg(cid); -} - -// -void GAMECONTEXT::start_vote(const char *desc, const char *command) -{ - // check if a vote is already running - if(vote_closetime) - return; - - // reset votes - vote_enforce = VOTE_ENFORCE_UNKNOWN; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(players[i]) - players[i]->vote = 0; - } - - // start vote - vote_closetime = time_get() + time_freq()*25; - str_copy(vote_description, desc, sizeof(vote_description)); - str_copy(vote_command, command, sizeof(vote_description)); - send_vote_set(-1); - send_vote_status(-1); -} - - -void GAMECONTEXT::end_vote() -{ - vote_closetime = 0; - send_vote_set(-1); -} - -void GAMECONTEXT::send_vote_set(int cid) -{ - NETMSG_SV_VOTE_SET msg; - if(vote_closetime) - { - msg.timeout = (vote_closetime-time_get())/time_freq(); - msg.description = vote_description; - msg.command = vote_command; - } - else - { - msg.timeout = 0; - msg.description = ""; - msg.command = ""; - } - msg.pack(MSGFLAG_VITAL); - server_send_msg(cid); -} - -void GAMECONTEXT::send_vote_status(int cid) -{ - NETMSG_SV_VOTE_STATUS msg = {0}; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(players[i]) - { - msg.total++; - if(players[i]->vote > 0) - msg.yes++; - else if(players[i]->vote < 0) - msg.no++; - else - msg.pass++; - } - } - - msg.pack(MSGFLAG_VITAL); - server_send_msg(cid); - -} - -void GAMECONTEXT::abort_vote_kick_on_disconnect(int client_id) -{ - if(vote_closetime && !strncmp(vote_command, "kick ", 5) && atoi(&vote_command[5]) == client_id) - vote_closetime = -1; -} - -void GAMECONTEXT::tick() -{ - world.core.tuning = tuning; - world.tick(); - - //if(world.paused) // make sure that the game object always updates - controller->tick(); - - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(players[i]) - players[i]->tick(); - } - - // update voting - if(vote_closetime) - { - // abort the kick-vote on player-leave - if(vote_closetime == -1) - { - send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote aborted"); - end_vote(); - } - else - { - // count votes - int total = 0, yes = 0, no = 0; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(players[i]) - { - total++; - if(players[i]->vote > 0) - yes++; - else if(players[i]->vote < 0) - no++; - } - } - - if(vote_enforce == VOTE_ENFORCE_YES || yes >= total/2+1) - { - console_execute_line(vote_command); - end_vote(); - send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote passed"); - - if(players[vote_creator]) - players[vote_creator]->last_votecall = 0; - } - else if(vote_enforce == VOTE_ENFORCE_NO || time_get() > vote_closetime || no >= total/2+1 || yes+no == total) - { - end_vote(); - send_chat(-1, GAMECONTEXT::CHAT_ALL, "Vote failed"); - } - } - } -} - -void GAMECONTEXT::snap(int client_id) -{ - world.snap(client_id); - controller->snap(client_id); - events.snap(client_id); - - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(players[i]) - players[i]->snap(client_id); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.hpp deleted file mode 100644 index bea087cb9..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontext.hpp +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef GAME_SERVER_GAMECONTEXT_H -#define GAME_SERVER_GAMECONTEXT_H - -#include "eventhandler.hpp" -#include "gamecontroller.hpp" -#include "gameworld.hpp" -#include "player.hpp" - -/* - Tick - Game Context (GAMECONTEXT::tick) - Game World (GAMEWORLD::tick) - Reset world if requested (GAMEWORLD::reset) - All entities in the world (ENTITY::tick) - All entities in the world (ENTITY::tick_defered) - Remove entities marked for deletion (GAMEWORLD::remove_entities) - Game Controller (GAMECONTROLLER::tick) - All players (PLAYER::tick) - - - Snap - Game Context (GAMECONTEXT::snap) - Game World (GAMEWORLD::snap) - All entities in the world (ENTITY::snap) - Game Controller (GAMECONTROLLER::snap) - Events handler (EVENT_HANDLER::snap) - All players (PLAYER::snap) - -*/ -class GAMECONTEXT -{ -public: - GAMECONTEXT(); - ~GAMECONTEXT(); - - void clear(); - - EVENTHANDLER events; - PLAYER *players[MAX_CLIENTS]; - - GAMECONTROLLER *controller; - GAMEWORLD world; - - void tick(); - void snap(int client_id); - - // helper functions - class CHARACTER *get_player_char(int client_id); - - // voting - void start_vote(const char *desc, const char *command); - void end_vote(); - void send_vote_set(int cid); - void send_vote_status(int cid); - void abort_vote_kick_on_disconnect(int client_id); - int vote_creator; - int64 vote_closetime; - char vote_description[512]; - char vote_command[512]; - int vote_enforce; - enum - { - VOTE_ENFORCE_UNKNOWN=0, - VOTE_ENFORCE_NO, - VOTE_ENFORCE_YES, - }; - - // helper functions - void create_damageind(vec2 p, float angle_mod, int amount); - void create_explosion(vec2 p, int owner, int weapon, bool bnodamage); - void create_smoke(vec2 p); - void create_hammerhit(vec2 p); - void create_playerspawn(vec2 p); - void create_death(vec2 p, int who); - void create_sound(vec2 pos, int sound, int mask=-1); - void create_sound_global(int sound, int target=-1); - - - enum - { - CHAT_ALL=-2, - CHAT_SPEC=-1, - CHAT_RED=0, - CHAT_BLUE=1 - }; - - // network - void send_chat_target(int to, const char *text); - void send_chat(int cid, int team, const char *text); - void send_emoticon(int cid, int emoticon); - void send_weapon_pickup(int cid, int weapon); - void send_broadcast(const char *text, int cid); - -}; - -extern GAMECONTEXT game; - -// MISC stuff, move to a better place later on - -extern TUNING_PARAMS tuning; -inline int cmask_all() { return -1; } -inline int cmask_one(int cid) { return 1< -#include -#include -#include - -#include - -#include "entities/pickup.hpp" -#include "gamecontroller.hpp" -#include "gamecontext.hpp" - - - -GAMECONTROLLER::GAMECONTROLLER() -{ - gametype = "unknown"; - - // - do_warmup(config.sv_warmup); - game_over_tick = -1; - sudden_death = 0; - round_start_tick = server_tick(); - round_count = 0; - game_flags = 0; - teamscore[0] = 0; - teamscore[1] = 0; - map_wish[0] = 0; - - unbalanced_tick = -1; - force_balanced = false; - - num_spawn_points[0] = 0; - num_spawn_points[1] = 0; - num_spawn_points[2] = 0; -} - -GAMECONTROLLER::~GAMECONTROLLER() -{ -} - -float GAMECONTROLLER::evaluate_spawn_pos(SPAWNEVAL *eval, vec2 pos) -{ - float score = 0.0f; - CHARACTER *c = (CHARACTER *)game.world.find_first(NETOBJTYPE_CHARACTER); - for(; c; c = (CHARACTER *)c->typenext()) - { - // team mates are not as dangerous as enemies - float scoremod = 1.0f; - if(eval->friendly_team != -1 && c->team == eval->friendly_team) - scoremod = 0.5f; - - float d = distance(pos, c->pos); - if(d == 0) - score += 1000000000.0f; - else - score += 1.0f/d; - } - - return score; -} - -void GAMECONTROLLER::evaluate_spawn_type(SPAWNEVAL *eval, int t) -{ - // get spawn point - for(int i = 0; i < num_spawn_points[t]; i++) - { - vec2 p = spawn_points[t][i]; - float s = evaluate_spawn_pos(eval, p); - if(!eval->got || eval->score > s) - { - eval->got = true; - eval->score = s; - eval->pos = p; - } - } -} - -bool GAMECONTROLLER::can_spawn(PLAYER *player, vec2 *out_pos) -{ - SPAWNEVAL eval; - - // spectators can't spawn - if(player->team == -1) - return false; - - if(is_teamplay()) - { - eval.friendly_team = player->team; - - // try first try own team spawn, then normal spawn and then enemy - evaluate_spawn_type(&eval, 1+(player->team&1)); - if(!eval.got) - { - evaluate_spawn_type(&eval, 0); - if(!eval.got) - evaluate_spawn_type(&eval, 1+((player->team+1)&1)); - } - } - else - { - evaluate_spawn_type(&eval, 0); - evaluate_spawn_type(&eval, 1); - evaluate_spawn_type(&eval, 2); - } - - *out_pos = eval.pos; - return eval.got; -} - - -bool GAMECONTROLLER::on_entity(int index, vec2 pos) -{ - int type = -1; - int subtype = 0; - - if(index == ENTITY_SPAWN) - spawn_points[0][num_spawn_points[0]++] = pos; - else if(index == ENTITY_SPAWN_RED) - spawn_points[1][num_spawn_points[1]++] = pos; - else if(index == ENTITY_SPAWN_BLUE) - spawn_points[2][num_spawn_points[2]++] = pos; - else if(index == ENTITY_ARMOR_1) - type = POWERUP_ARMOR; - else if(index == ENTITY_HEALTH_1) - type = POWERUP_HEALTH; - else if(index == ENTITY_WEAPON_SHOTGUN) - { - type = POWERUP_WEAPON; - subtype = WEAPON_SHOTGUN; - } - else if(index == ENTITY_WEAPON_GRENADE) - { - type = POWERUP_WEAPON; - subtype = WEAPON_GRENADE; - } - else if(index == ENTITY_WEAPON_RIFLE) - { - type = POWERUP_WEAPON; - subtype = WEAPON_RIFLE; - } - else if(index == ENTITY_POWERUP_NINJA && config.sv_powerups) - { - type = POWERUP_NINJA; - subtype = WEAPON_NINJA; - } - - if(type != -1) - { - PICKUP *pickup = new PICKUP(type, subtype); - pickup->pos = pos; - return true; - } - - return false; -} - -void GAMECONTROLLER::endround() -{ - if(warmup) // game can't end when we are running warmup - return; - - game.world.paused = true; - game_over_tick = server_tick(); - sudden_death = 0; -} - -void GAMECONTROLLER::resetgame() -{ - game.world.reset_requested = true; -} - -const char *GAMECONTROLLER::get_team_name(int team) -{ - if(is_teamplay()) - { - if(team == 0) - return "red team"; - else if(team == 1) - return "blue team"; - } - else - { - if(team == 0) - return "game"; - } - - return "spectators"; -} - -static bool is_separator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; } - -void GAMECONTROLLER::startround() -{ - resetgame(); - - round_start_tick = server_tick(); - sudden_death = 0; - game_over_tick = -1; - game.world.paused = false; - teamscore[0] = 0; - teamscore[1] = 0; - unbalanced_tick = -1; - force_balanced = false; - dbg_msg("game","start round type='%s' teamplay='%d'", gametype, game_flags&GAMEFLAG_TEAMS); -} - -void GAMECONTROLLER::change_map(const char *to_map) -{ - str_copy(map_wish, to_map, sizeof(map_wish)); - endround(); -} - -void GAMECONTROLLER::cyclemap() -{ - if(map_wish[0] != 0) - { - dbg_msg("game", "rotating map to %s", map_wish); - str_copy(config.sv_map, map_wish, sizeof(config.sv_map)); - map_wish[0] = 0; - round_count = 0; - return; - } - if(!strlen(config.sv_maprotation)) - return; - - if(round_count < config.sv_rounds_per_map-1) - return; - - // handle maprotation - const char *map_rotation = config.sv_maprotation; - const char *current_map = config.sv_map; - - int current_map_len = strlen(current_map); - const char *next_map = map_rotation; - while(*next_map) - { - int wordlen = 0; - while(next_map[wordlen] && !is_separator(next_map[wordlen])) - wordlen++; - - if(wordlen == current_map_len && strncmp(next_map, current_map, current_map_len) == 0) - { - // map found - next_map += current_map_len; - while(*next_map && is_separator(*next_map)) - next_map++; - - break; - } - - next_map++; - } - - // restart rotation - if(next_map[0] == 0) - next_map = map_rotation; - - // cut out the next map - char buf[512]; - for(int i = 0; i < 512; i++) - { - buf[i] = next_map[i]; - if(is_separator(next_map[i]) || next_map[i] == 0) - { - buf[i] = 0; - break; - } - } - - // skip spaces - int i = 0; - while(is_separator(buf[i])) - i++; - - round_count = 0; - - dbg_msg("game", "rotating map to %s", &buf[i]); - str_copy(config.sv_map, &buf[i], sizeof(config.sv_map)); -} - -void GAMECONTROLLER::post_reset() -{ - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - { - game.players[i]->respawn(); - game.players[i]->score = 0; - } - } -} - -void GAMECONTROLLER::on_player_info_change(class PLAYER *p) -{ - const int team_colors[2] = {65387, 10223467}; - if(is_teamplay()) - { - if(p->team >= 0 || p->team <= 1) - { - p->use_custom_color = 1; - p->color_body = team_colors[p->team]; - p->color_feet = team_colors[p->team]; - } - } -} - - -int GAMECONTROLLER::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon) -{ - // do scoreing - if(!killer) - return 0; - if(killer == victim->player) - victim->player->score--; // suicide - else - { - if(is_teamplay() && victim->team == killer->team) - killer->score--; // teamkill - else - killer->score++; // normal kill - } - return 0; -} - -void GAMECONTROLLER::on_character_spawn(class CHARACTER *chr) -{ - // default health - chr->health = 10; - - // give default weapons - chr->weapons[WEAPON_HAMMER].got = 1; - chr->weapons[WEAPON_HAMMER].ammo = -1; - chr->weapons[WEAPON_GUN].got = 1; - chr->weapons[WEAPON_GUN].ammo = 10; -} - -void GAMECONTROLLER::do_warmup(int seconds) -{ - warmup = seconds*server_tickspeed(); -} - -bool GAMECONTROLLER::is_friendly_fire(int cid1, int cid2) -{ - if(cid1 == cid2) - return false; - - if(is_teamplay()) - { - if(!game.players[cid1] || !game.players[cid2]) - return false; - - if(game.players[cid1]->team == game.players[cid2]->team) - return true; - } - - return false; -} - -bool GAMECONTROLLER::is_force_balanced() -{ - if(force_balanced) - { - force_balanced = false; - return true; - } - else - return false; -} - -void GAMECONTROLLER::tick() -{ - // do warmup - if(warmup) - { - warmup--; - if(!warmup) - startround(); - } - - if(game_over_tick != -1) - { - // game over.. wait for restart - if(server_tick() > game_over_tick+server_tickspeed()*10) - { - cyclemap(); - startround(); - round_count++; - } - } - - // do team-balancing - if (is_teamplay() && unbalanced_tick != -1 && server_tick() > unbalanced_tick+config.sv_teambalance_time*server_tickspeed()*60) - { - dbg_msg("game", "Balancing teams"); - - int t[2] = {0,0}; - int tscore[2] = {0,0}; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i] && game.players[i]->team != -1) - { - t[game.players[i]->team]++; - tscore[game.players[i]->team]+=game.players[i]->score; - } - } - - // are teams unbalanced? - if(abs(t[0]-t[1]) >= 2) - { - int m = (t[0] > t[1]) ? 0 : 1; - int num_balance = abs(t[0]-t[1]) / 2; - - do - { - PLAYER *p = 0; - int pd = tscore[m]; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(!game.players[i]) - continue; - - // remember the player who would cause lowest score-difference - if(game.players[i]->team == m && (!p || abs((tscore[m^1]+game.players[i]->score) - (tscore[m]-game.players[i]->score)) < pd)) - { - p = game.players[i]; - pd = abs((tscore[m^1]+p->score) - (tscore[m]-p->score)); - } - } - - // move the player to other team without losing his score - // TODO: change in player::set_team needed: player won't lose score on team-change - int score_before = p->score; - p->set_team(m^1); - p->score = score_before; - - p->respawn(); - p->force_balanced = true; - } while (--num_balance); - - force_balanced = true; - } - unbalanced_tick = -1; - } - - // update browse info - int prog = -1; - if(config.sv_timelimit > 0) - prog = max(prog, (server_tick()-round_start_tick) * 100 / (config.sv_timelimit*server_tickspeed()*60)); - - if(config.sv_scorelimit) - { - if(is_teamplay()) - { - prog = max(prog, (teamscore[0]*100)/config.sv_scorelimit); - prog = max(prog, (teamscore[1]*100)/config.sv_scorelimit); - } - else - { - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - prog = max(prog, (game.players[i]->score*100)/config.sv_scorelimit); - } - } - } - - if(warmup) - prog = -1; - - server_setbrowseinfo(gametype, prog); -} - - -bool GAMECONTROLLER::is_teamplay() const -{ - return game_flags&GAMEFLAG_TEAMS; -} - -void GAMECONTROLLER::snap(int snapping_client) -{ - NETOBJ_GAME *gameobj = (NETOBJ_GAME *)snap_new_item(NETOBJTYPE_GAME, 0, sizeof(NETOBJ_GAME)); - gameobj->paused = game.world.paused; - gameobj->game_over = game_over_tick==-1?0:1; - gameobj->sudden_death = sudden_death; - - gameobj->score_limit = config.sv_scorelimit; - gameobj->time_limit = config.sv_timelimit; - gameobj->round_start_tick = round_start_tick; - gameobj->flags = game_flags; - - gameobj->warmup = warmup; - - gameobj->round_num = (strlen(config.sv_maprotation) && config.sv_rounds_per_map) ? config.sv_rounds_per_map : 0; - gameobj->round_current = round_count+1; - - - if(snapping_client == -1) - { - // we are recording a demo, just set the scores - gameobj->teamscore_red = teamscore[0]; - gameobj->teamscore_blue = teamscore[1]; - } - else - { - // TODO: this little hack should be removed - gameobj->teamscore_red = is_teamplay() ? teamscore[0] : game.players[snapping_client]->score; - gameobj->teamscore_blue = teamscore[1]; - } -} - -int GAMECONTROLLER::get_auto_team(int notthisid) -{ - // this will force the auto balancer to work overtime aswell - if(config.dbg_stress) - return 0; - - int numplayers[2] = {0,0}; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i] && i != notthisid) - { - if(game.players[i]->team == 0 || game.players[i]->team == 1) - numplayers[game.players[i]->team]++; - } - } - - int team = 0; - if(is_teamplay()) - team = numplayers[0] > numplayers[1] ? 1 : 0; - - if(can_join_team(team, notthisid)) - return team; - return -1; -} - -bool GAMECONTROLLER::can_join_team(int team, int notthisid) -{ - (void)team; - int numplayers[2] = {0,0}; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i] && i != notthisid) - { - if(game.players[i]->team >= 0 || game.players[i]->team == 1) - numplayers[game.players[i]->team]++; - } - } - - return (numplayers[0] + numplayers[1]) < config.sv_max_clients-config.sv_spectator_slots; -} - -bool GAMECONTROLLER::check_team_balance() -{ - if(!is_teamplay() || !config.sv_teambalance_time) - return true; - - int t[2] = {0, 0}; - for(int i = 0; i < MAX_CLIENTS; i++) - { - PLAYER *p = game.players[i]; - if(p && p->team != -1) - t[p->team]++; - } - - if(abs(t[0]-t[1]) >= 2) - { - dbg_msg("game", "Team is NOT balanced (red=%d blue=%d)", t[0], t[1]); - if (game.controller->unbalanced_tick == -1) - game.controller->unbalanced_tick = server_tick(); - return false; - } - else - { - dbg_msg("game", "Team is balanced (red=%d blue=%d)", t[0], t[1]); - game.controller->unbalanced_tick = -1; - return true; - } -} - -bool GAMECONTROLLER::can_change_team(PLAYER *pplayer, int jointeam) -{ - int t[2] = {0, 0}; - - if (!is_teamplay() || jointeam == -1 || !config.sv_teambalance_time) - return true; - - for(int i = 0; i < MAX_CLIENTS; i++) - { - PLAYER *p = game.players[i]; - if(p && p->team != -1) - t[p->team]++; - } - - // simulate what would happen if changed team - t[jointeam]++; - if (pplayer->team != -1) - t[jointeam^1]--; - - // there is a player-difference of at least 2 - if(abs(t[0]-t[1]) >= 2) - { - // player wants to join team with less players - if ((t[0] < t[1] && jointeam == 0) || (t[0] > t[1] && jointeam == 1)) - return true; - else - return false; - } - else - return true; -} - -void GAMECONTROLLER::do_player_score_wincheck() -{ - if(game_over_tick == -1 && !warmup) - { - // gather some stats - int topscore = 0; - int topscore_count = 0; - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - { - if(game.players[i]->score > topscore) - { - topscore = game.players[i]->score; - topscore_count = 1; - } - else if(game.players[i]->score == topscore) - topscore_count++; - } - } - - // check score win condition - if((config.sv_scorelimit > 0 && topscore >= config.sv_scorelimit) || - (config.sv_timelimit > 0 && (server_tick()-round_start_tick) >= config.sv_timelimit*server_tickspeed()*60)) - { - if(topscore_count == 1) - endround(); - else - sudden_death = 1; - } - } -} - -void GAMECONTROLLER::do_team_score_wincheck() -{ - if(game_over_tick == -1 && !warmup) - { - // check score win condition - if((config.sv_scorelimit > 0 && (teamscore[0] >= config.sv_scorelimit || teamscore[1] >= config.sv_scorelimit)) || - (config.sv_timelimit > 0 && (server_tick()-round_start_tick) >= config.sv_timelimit*server_tickspeed()*60)) - { - if(teamscore[0] != teamscore[1]) - endround(); - else - sudden_death = 1; - } - } -} - -int GAMECONTROLLER::clampteam(int team) -{ - if(team < 0) // spectator - return -1; - if(is_teamplay()) - return team&1; - return 0; -} - -GAMECONTROLLER *gamecontroller = 0; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontroller.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontroller.hpp deleted file mode 100644 index 26b8a81f5..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamecontroller.hpp +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef GAME_SERVER_GAMECONTROLLER_H -#define GAME_SERVER_GAMECONTROLLER_H - -#include - -/* - Class: Game Controller - Controls the main game logic. Keeping track of team and player score, - winning conditions and specific game logic. -*/ -class GAMECONTROLLER -{ - vec2 spawn_points[3][64]; - int num_spawn_points[3]; -protected: - struct SPAWNEVAL - { - SPAWNEVAL() - { - got = false; - friendly_team = -1; - pos = vec2(100,100); - } - - vec2 pos; - bool got; - int friendly_team; - float score; - }; - - float evaluate_spawn_pos(SPAWNEVAL *eval, vec2 pos); - void evaluate_spawn_type(SPAWNEVAL *eval, int type); - bool evaluate_spawn(class PLAYER *p, vec2 *pos); - - void cyclemap(); - void resetgame(); - - char map_wish[128]; - - - int round_start_tick; - int game_over_tick; - int sudden_death; - - int teamscore[2]; - - int warmup; - int round_count; - - int game_flags; - int unbalanced_tick; - bool force_balanced; - -public: - const char *gametype; - - bool is_teamplay() const; - - GAMECONTROLLER(); - virtual ~GAMECONTROLLER(); - - void do_team_score_wincheck(); - void do_player_score_wincheck(); - - void do_warmup(int seconds); - - void startround(); - void endround(); - void change_map(const char *to_map); - - bool is_friendly_fire(int cid1, int cid2); - - bool is_force_balanced(); - - /* - - */ - virtual void tick(); - - virtual void snap(int snapping_client); - - /* - Function: on_entity - Called when the map is loaded to process an entity - in the map. - - Arguments: - index - Entity index. - pos - Where the entity is located in the world. - - Returns: - bool? - */ - virtual bool on_entity(int index, vec2 pos); - - /* - Function: on_character_spawn - Called when a character spawns into the game world. - - Arguments: - chr - The character that was spawned. - */ - virtual void on_character_spawn(class CHARACTER *chr); - - /* - Function: on_character_death - Called when a character in the world dies. - - Arguments: - victim - The character that died. - killer - The player that killed it. - weapon - What weapon that killed it. Can be -1 for undefined - weapon when switching team or player suicides. - */ - virtual int on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon); - - - virtual void on_player_info_change(class PLAYER *p); - - // - virtual bool can_spawn(class PLAYER *p, vec2 *pos); - - /* - - */ - virtual const char *get_team_name(int team); - virtual int get_auto_team(int notthisid); - virtual bool can_join_team(int team, int notthisid); - bool check_team_balance(); - bool can_change_team(PLAYER *pplayer, int jointeam); - int clampteam(int team); - - virtual void post_reset(); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.cpp deleted file mode 100644 index b2146b511..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include -#include -#include "ctf.hpp" - -GAMECONTROLLER_CTF::GAMECONTROLLER_CTF() -{ - flags[0] = 0; - flags[1] = 0; - gametype = "CTF"; - game_flags = GAMEFLAG_TEAMS|GAMEFLAG_FLAGS; -} - -bool GAMECONTROLLER_CTF::on_entity(int index, vec2 pos) -{ - if(GAMECONTROLLER::on_entity(index, pos)) - return true; - - int team = -1; - if(index == ENTITY_FLAGSTAND_RED) team = 0; - if(index == ENTITY_FLAGSTAND_BLUE) team = 1; - if(team == -1) - return false; - - FLAG *f = new FLAG(team); - f->stand_pos = pos; - f->pos = pos; - flags[team] = f; - return true; -} - -int GAMECONTROLLER_CTF::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weaponid) -{ - GAMECONTROLLER::on_character_death(victim, killer, weaponid); - int had_flag = 0; - - // drop flags - for(int fi = 0; fi < 2; fi++) - { - FLAG *f = flags[fi]; - if(f && killer && f->carrying_character == killer->get_character()) - had_flag |= 2; - if(f && f->carrying_character == victim) - { - game.create_sound_global(SOUND_CTF_DROP); - f->drop_tick = server_tick(); - f->carrying_character = 0; - f->vel = vec2(0,0); - - if(killer && killer->team != victim->team) - killer->score++; - - had_flag |= 1; - } - } - - return had_flag; -} - -void GAMECONTROLLER_CTF::tick() -{ - GAMECONTROLLER::tick(); - - do_team_score_wincheck(); - - for(int fi = 0; fi < 2; fi++) - { - FLAG *f = flags[fi]; - - if(!f) - continue; - - // flag hits death-tile, reset it - if(col_get((int)f->pos.x, (int)f->pos.y)&COLFLAG_DEATH) - { - game.create_sound_global(SOUND_CTF_RETURN); - f->reset(); - continue; - } - - // - if(f->carrying_character) - { - // update flag position - f->pos = f->carrying_character->pos; - - if(flags[fi^1] && flags[fi^1]->at_stand) - { - if(distance(f->pos, flags[fi^1]->pos) < 32) - { - // CAPTURE! \o/ - teamscore[fi^1] += 100; - f->carrying_character->player->score += 5; - - dbg_msg("game", "flag_capture player='%d:%s'", - f->carrying_character->player->client_id, - server_clientname(f->carrying_character->player->client_id)); - - char buf[512]; - float capture_time = (server_tick() - f->grab_tick)/(float)server_tickspeed(); - if(capture_time <= 60) - { - str_format(buf, sizeof(buf), "the %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id), (int)capture_time%60, ((int)(capture_time*100)%100)<10?"0":"", (int)(capture_time*100)%100); - } - else - { - str_format(buf, sizeof(buf), "the %s flag was captured by %s", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id)); - } - game.send_chat(-1, -2, buf); - for(int i = 0; i < 2; i++) - flags[i]->reset(); - - game.create_sound_global(SOUND_CTF_CAPTURE); - } - } - } - else - { - CHARACTER *close_characters[MAX_CLIENTS]; - int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER); - for(int i = 0; i < num; i++) - { - if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL, NULL)) - continue; - - if(close_characters[i]->team == f->team) - { - // return the flag - if(!f->at_stand) - { - CHARACTER *chr = close_characters[i]; - chr->player->score += 1; - - dbg_msg("game", "flag_return player='%d:%s'", - chr->player->client_id, - server_clientname(chr->player->client_id)); - - game.create_sound_global(SOUND_CTF_RETURN); - f->reset(); - } - } - else - { - // take the flag - if(f->at_stand) - { - teamscore[fi^1]++; - f->grab_tick = server_tick(); - } - f->at_stand = 0; - f->carrying_character = close_characters[i]; - f->carrying_character->player->score += 1; - - dbg_msg("game", "flag_grab player='%d:%s'", - f->carrying_character->player->client_id, - server_clientname(f->carrying_character->player->client_id)); - - for(int c = 0; c < MAX_CLIENTS; c++) - { - if(!game.players[c]) - continue; - - if(game.players[c]->team == fi) - game.create_sound_global(SOUND_CTF_GRAB_EN, game.players[c]->client_id); - else - game.create_sound_global(SOUND_CTF_GRAB_PL, game.players[c]->client_id); - } - break; - } - } - - if(!f->carrying_character && !f->at_stand) - { - if(server_tick() > f->drop_tick + server_tickspeed()*30) - { - game.create_sound_global(SOUND_CTF_RETURN); - f->reset(); - } - else - { - f->vel.y += game.world.core.tuning.gravity; - move_box(&f->pos, &f->vel, vec2(f->phys_size, f->phys_size), 0.5f); - } - } - } - } -} - -// Flag -FLAG::FLAG(int _team) -: ENTITY(NETOBJTYPE_FLAG) -{ - team = _team; - proximity_radius = phys_size; - carrying_character = 0x0; - grab_tick = 0; - - reset(); - - // TODO: should this be done here? - game.world.insert_entity(this); -} - -void FLAG::reset() -{ - carrying_character = 0x0; - at_stand = 1; - pos = stand_pos; - vel = vec2(0,0); - grab_tick = 0; -} - -void FLAG::snap(int snapping_client) -{ - NETOBJ_FLAG *flag = (NETOBJ_FLAG *)snap_new_item(NETOBJTYPE_FLAG, team, sizeof(NETOBJ_FLAG)); - flag->x = (int)pos.x; - flag->y = (int)pos.y; - flag->team = team; - flag->carried_by = -1; - - if(at_stand) - flag->carried_by = -2; - else if(carrying_character && carrying_character->player) - flag->carried_by = carrying_character->player->client_id; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.hpp deleted file mode 100644 index 67a098a48..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/ctf.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include -#include - -class GAMECONTROLLER_CTF : public GAMECONTROLLER -{ -public: - class FLAG *flags[2]; - - GAMECONTROLLER_CTF(); - virtual void tick(); - - virtual bool on_entity(int index, vec2 pos); - virtual int on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon); -}; - -// TODO: move to seperate file -class FLAG : public ENTITY -{ -public: - static const int phys_size = 14; - CHARACTER *carrying_character; - vec2 vel; - vec2 stand_pos; - - int team; - int at_stand; - int drop_tick; - int grab_tick; - - FLAG(int _team); - - virtual void reset(); - virtual void snap(int snapping_client); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.cpp deleted file mode 100644 index 15c0b987c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include "dm.hpp" - - -GAMECONTROLLER_DM::GAMECONTROLLER_DM() -{ - gametype = "DM"; -} - -void GAMECONTROLLER_DM::tick() -{ - do_player_score_wincheck(); - GAMECONTROLLER::tick(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.hpp deleted file mode 100644 index 6fb25f61f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/dm.hpp +++ /dev/null @@ -1,10 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include - -class GAMECONTROLLER_DM : public GAMECONTROLLER -{ -public: - GAMECONTROLLER_DM(); - virtual void tick(); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.cpp deleted file mode 100644 index 87b37411c..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include "mod.hpp" - -GAMECONTROLLER_MOD::GAMECONTROLLER_MOD() -{ - // Exchange this to a string that identifies your game mode. - // DM, TDM and CTF are reserved for teeworlds original modes. - gametype = "MOD"; - - //game_flags = GAMEFLAG_TEAMS; // GAMEFLAG_TEAMS makes it a two-team gamemode -} - -void GAMECONTROLLER_MOD::tick() -{ - // this is the main part of the gamemode, this function is run every tick - do_player_score_wincheck(); // checks for winners, no teams version - //do_team_score_wincheck(); // checks for winners, two teams version - - GAMECONTROLLER::tick(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.hpp deleted file mode 100644 index 9915a615f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/mod.hpp +++ /dev/null @@ -1,13 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include - -// you can subclass GAMECONTROLLER_CTF, GAMECONTROLLER_TDM etc if you want -// todo a modification with their base as well. -class GAMECONTROLLER_MOD : public GAMECONTROLLER -{ -public: - GAMECONTROLLER_MOD(); - virtual void tick(); - // add more virtual functions here if you wish -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.cpp deleted file mode 100644 index 72605000e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include -#include "tdm.hpp" - -GAMECONTROLLER_TDM::GAMECONTROLLER_TDM() -{ - gametype = "TDM"; - game_flags = GAMEFLAG_TEAMS; -} - -int GAMECONTROLLER_TDM::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon) -{ - GAMECONTROLLER::on_character_death(victim, killer, weapon); - - - if(weapon != WEAPON_GAME) - { - // do team scoring - if(killer == victim->player || killer->team == victim->player->team) - teamscore[killer->team&1]--; // klant arschel - else - teamscore[killer->team&1]++; // good shit - } - - return 0; -} - -void GAMECONTROLLER_TDM::tick() -{ - do_team_score_wincheck(); - GAMECONTROLLER::tick(); -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.hpp deleted file mode 100644 index 51c47ca5e..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gamemodes/tdm.hpp +++ /dev/null @@ -1,12 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -#include - -class GAMECONTROLLER_TDM : public GAMECONTROLLER -{ -public: - GAMECONTROLLER_TDM(); - - int on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon); - virtual void tick(); -}; diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.cpp deleted file mode 100644 index 9e76f14ba..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.cpp +++ /dev/null @@ -1,217 +0,0 @@ - -#include "gameworld.hpp" -#include "entity.hpp" -#include "gamecontext.hpp" - -////////////////////////////////////////////////// -// game world -////////////////////////////////////////////////// -GAMEWORLD::GAMEWORLD() -{ - paused = false; - reset_requested = false; - first_entity = 0x0; - for(int i = 0; i < NUM_ENT_TYPES; i++) - first_entity_types[i] = 0; -} - -GAMEWORLD::~GAMEWORLD() -{ - // delete all entities - while(first_entity) - delete first_entity; -} - -ENTITY *GAMEWORLD::find_first(int type) -{ - return first_entity_types[type]; -} - - -int GAMEWORLD::find_entities(vec2 pos, float radius, ENTITY **ents, int max, int type) -{ - int num = 0; - for(ENTITY *ent = (type<0) ? first_entity : first_entity_types[type]; - ent; ent = (type<0) ? ent->next_entity : ent->next_type_entity) - { - if(distance(ent->pos, pos) < radius+ent->proximity_radius) - { - ents[num] = ent; - num++; - if(num == max) - break; - } - } - - return num; -} - -void GAMEWORLD::insert_entity(ENTITY *ent) -{ - ENTITY *cur = first_entity; - while(cur) - { - dbg_assert(cur != ent, "err"); - cur = cur->next_entity; - } - - // insert it - if(first_entity) - first_entity->prev_entity = ent; - ent->next_entity = first_entity; - ent->prev_entity = 0x0; - first_entity = ent; - - // into typelist aswell - if(first_entity_types[ent->objtype]) - first_entity_types[ent->objtype]->prev_type_entity = ent; - ent->next_type_entity = first_entity_types[ent->objtype]; - ent->prev_type_entity = 0x0; - first_entity_types[ent->objtype] = ent; -} - -void GAMEWORLD::destroy_entity(ENTITY *ent) -{ - ent->marked_for_destroy = true; -} - -void GAMEWORLD::remove_entity(ENTITY *ent) -{ - // not in the list - if(!ent->next_entity && !ent->prev_entity && first_entity != ent) - return; - - // remove - if(ent->prev_entity) - ent->prev_entity->next_entity = ent->next_entity; - else - first_entity = ent->next_entity; - if(ent->next_entity) - ent->next_entity->prev_entity = ent->prev_entity; - - if(ent->prev_type_entity) - ent->prev_type_entity->next_type_entity = ent->next_type_entity; - else - first_entity_types[ent->objtype] = ent->next_type_entity; - if(ent->next_type_entity) - ent->next_type_entity->prev_type_entity = ent->prev_type_entity; - - ent->next_entity = 0; - ent->prev_entity = 0; - ent->next_type_entity = 0; - ent->prev_type_entity = 0; -} - -// -void GAMEWORLD::snap(int snapping_client) -{ - for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) - ent->snap(snapping_client); -} - -void GAMEWORLD::reset() -{ - // reset all entities - for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) - ent->reset(); - remove_entities(); - - game.controller->post_reset(); - remove_entities(); - - reset_requested = false; -} - -void GAMEWORLD::remove_entities() -{ - // destroy objects marked for destruction - ENTITY *ent = first_entity; - while(ent) - { - ENTITY *next = ent->next_entity; - if(ent->marked_for_destroy) - { - remove_entity(ent); - ent->destroy(); - } - ent = next; - } -} - -void GAMEWORLD::tick() -{ - if(reset_requested) - reset(); - - if(!paused) - { - if(game.controller->is_force_balanced()) - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, "Teams have been balanced"); - // update all objects - for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) - ent->tick(); - - for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) - ent->tick_defered(); - } - - remove_entities(); -} - - -// TODO: should be more general -CHARACTER *GAMEWORLD::intersect_character(vec2 pos0, vec2 pos1, float radius, vec2& new_pos, ENTITY *notthis) -{ - // Find other players - float closest_len = distance(pos0, pos1) * 100.0f; - vec2 line_dir = normalize(pos1-pos0); - CHARACTER *closest = 0; - - CHARACTER *p = (CHARACTER *)game.world.find_first(NETOBJTYPE_CHARACTER); - for(; p; p = (CHARACTER *)p->typenext()) - { - if(p == notthis) - continue; - - vec2 intersect_pos = closest_point_on_line(pos0, pos1, p->pos); - float len = distance(p->pos, intersect_pos); - if(len < CHARACTER::phys_size+radius) - { - if(len < closest_len) - { - new_pos = intersect_pos; - closest_len = len; - closest = p; - } - } - } - - return closest; -} - - -CHARACTER *GAMEWORLD::closest_character(vec2 pos, float radius, ENTITY *notthis) -{ - // Find other players - float closest_range = radius*2; - CHARACTER *closest = 0; - - CHARACTER *p = (CHARACTER *)game.world.find_first(NETOBJTYPE_CHARACTER); - for(; p; p = (CHARACTER *)p->typenext()) - { - if(p == notthis) - continue; - - float len = distance(pos, p->pos); - if(len < CHARACTER::phys_size+radius) - { - if(len < closest_range) - { - closest_range = len; - closest = p; - } - } - } - - return closest; -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.hpp deleted file mode 100644 index 4757ad679..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/gameworld.hpp +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef GAME_SERVER_GAMEWORLD_H -#define GAME_SERVER_GAMEWORLD_H - -#include - -class ENTITY; -class CHARACTER; - -/* - Class: Game World - Tracks all entities in the game. Propagates tick and - snap calls to all entities. -*/ -class GAMEWORLD -{ - void reset(); - void remove_entities(); - - enum - { - NUM_ENT_TYPES=10, // TODO: are more exact value perhaps? :) - }; - - // TODO: two lists seams kinda not good, shouldn't be needed - ENTITY *first_entity; - ENTITY *first_entity_types[NUM_ENT_TYPES]; - -public: - bool reset_requested; - bool paused; - WORLD_CORE core; - - GAMEWORLD(); - ~GAMEWORLD(); - - ENTITY *find_first() { return first_entity; } - ENTITY *find_first(int type); - - /* - Function: find_entities - Finds entities close to a position and returns them in a list. - - Arguments: - pos - Position. - radius - How close the entities have to be. - ents - Pointer to a list that should be filled with the pointers - to the entities. - max - Number of entities that fits into the ents array. - type - Type of the entities to find. -1 for all types. - - Returns: - Number of entities found and added to the ents array. - */ - int find_entities(vec2 pos, float radius, ENTITY **ents, int max, int type = -1); - - /* - Function: interserct_character - Finds the closest character that intersects the line. - - Arguments: - pos0 - Start position - pos2 - End position - radius - How for from the line the character is allowed to be. - new_pos - Intersection position - notthis - Entity to ignore intersecting with - - Returns: - Returns a pointer to the closest hit or NULL of there is no intersection. - */ - class CHARACTER *intersect_character(vec2 pos0, vec2 pos1, float radius, vec2 &new_pos, class ENTITY *notthis = 0); - - /* - Function: closest_character - Finds the closest character to a specific point. - - Arguments: - pos - The center position. - radius - How far off the character is allowed to be - notthis - Entity to ignore - - Returns: - Returns a pointer to the closest character or NULL if no character is close enough. - */ - class CHARACTER *closest_character(vec2 pos, float radius, ENTITY *notthis); - - /* - Function: insert_entity - Adds an entity to the world. - - Arguments: - entity - Entity to add - */ - void insert_entity(ENTITY *entity); - - /* - Function: remove_entity - Removes an entity from the world. - - Arguments: - entity - Entity to remove - */ - void remove_entity(ENTITY *entity); - - /* - Function: destroy_entity - Destroys an entity in the world. - - Arguments: - entity - Entity to destroy - */ - void destroy_entity(ENTITY *entity); - - /* - Function: snap - Calls snap on all the entities in the world to create - the snapshot. - - Arguments: - snapping_client - ID of the client which snapshot - is being created. - */ - void snap(int snapping_client); - - /* - Function: tick - Calls tick on all the entities in the world to progress - the world to the next tick. - - */ - void tick(); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/hooks.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/hooks.cpp deleted file mode 100644 index 73c03fd62..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/hooks.cpp +++ /dev/null @@ -1,601 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include -#include - -#include - -#include -#include -extern "C" -{ - #include -} -#include -#include -#include - -#include - -#include "gamecontext.hpp" -#include "gamemodes/dm.hpp" -#include "gamemodes/tdm.hpp" -#include "gamemodes/ctf.hpp" -#include "gamemodes/mod.hpp" - -TUNING_PARAMS tuning; - -static void check_pure_tuning() -{ - // might not be created yet during start up - if(!game.controller) - return; - - if( strcmp(game.controller->gametype, "DM")==0 || - strcmp(game.controller->gametype, "TDM")==0 || - strcmp(game.controller->gametype, "CTF")==0) - { - TUNING_PARAMS p; - if(memcmp(&p, &tuning, sizeof(TUNING_PARAMS)) != 0) - { - dbg_msg("server", "resetting tuning due to pure server"); - tuning = p; - } - } -} - -struct VOTEOPTION -{ - VOTEOPTION *next; - VOTEOPTION *prev; - char command[1]; -}; - -static HEAP *voteoption_heap = 0; -static VOTEOPTION *voteoption_first = 0; -static VOTEOPTION *voteoption_last = 0; - -void send_tuning_params(int cid) -{ - check_pure_tuning(); - - msg_pack_start(NETMSGTYPE_SV_TUNEPARAMS, MSGFLAG_VITAL); - int *params = (int *)&tuning; - for(unsigned i = 0; i < sizeof(tuning)/sizeof(int); i++) - msg_pack_int(params[i]); - msg_pack_end(); - server_send_msg(cid); -} - -// Server hooks -void mods_client_direct_input(int client_id, void *input) -{ - if(!game.world.paused) - game.players[client_id]->on_direct_input((NETOBJ_PLAYER_INPUT *)input); -} - -void mods_client_predicted_input(int client_id, void *input) -{ - if(!game.world.paused) - game.players[client_id]->on_predicted_input((NETOBJ_PLAYER_INPUT *)input); -} - -// Server hooks -void mods_tick() -{ - check_pure_tuning(); - - game.tick(); - -#ifdef CONF_DEBUG - if(config.dbg_dummies) - { - for(int i = 0; i < config.dbg_dummies ; i++) - { - NETOBJ_PLAYER_INPUT input = {0}; - input.direction = (i&1)?-1:1; - game.players[MAX_CLIENTS-i-1]->on_predicted_input(&input); - } - } -#endif -} - -void mods_snap(int client_id) -{ - game.snap(client_id); -} - -void mods_client_enter(int client_id) -{ - //game.world.insert_entity(&game.players[client_id]); - game.players[client_id]->respawn(); - dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id)); - - - char buf[512]; - str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), game.controller->get_team_name(game.players[client_id]->team)); - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); - - dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), game.players[client_id]->team); -} - -void mods_connected(int client_id) -{ - game.players[client_id] = new(client_id) PLAYER(client_id); - //game.players[client_id].init(client_id); - //game.players[client_id].client_id = client_id; - - // Check which team the player should be on - if(config.sv_tournament_mode) - game.players[client_id]->team = -1; - else - game.players[client_id]->team = game.controller->get_auto_team(client_id); - - (void) game.controller->check_team_balance(); - - // send motd - NETMSG_SV_MOTD msg; - msg.message = config.sv_motd; - msg.pack(MSGFLAG_VITAL); - server_send_msg(client_id); -} - -void mods_client_drop(int client_id) -{ - game.abort_vote_kick_on_disconnect(client_id); - game.players[client_id]->on_disconnect(); - delete game.players[client_id]; - game.players[client_id] = 0; - - (void) game.controller->check_team_balance(); -} - -/*static bool is_separator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; } - -static const char *liststr_find(const char *str, const char *needle) -{ - int needle_len = strlen(needle); - while(*str) - { - int wordlen = 0; - while(str[wordlen] && !is_separator(str[wordlen])) - wordlen++; - - if(wordlen == needle_len && strncmp(str, needle, needle_len) == 0) - return str; - - str += wordlen+1; - } - - return 0; -}*/ - -void mods_message(int msgtype, int client_id) -{ - void *rawmsg = netmsg_secure_unpack(msgtype); - PLAYER *p = game.players[client_id]; - - if(!rawmsg) - { - dbg_msg("server", "dropped weird message '%s' (%d), failed on '%s'", netmsg_get_name(msgtype), msgtype, netmsg_failed_on()); - return; - } - - if(msgtype == NETMSGTYPE_CL_SAY) - { - NETMSG_CL_SAY *msg = (NETMSG_CL_SAY *)rawmsg; - int team = msg->team; - if(team) - team = p->team; - else - team = GAMECONTEXT::CHAT_ALL; - - if(config.sv_spamprotection && p->last_chat+time_freq() > time_get()) - return; - - p->last_chat = time_get(); - - game.send_chat(client_id, team, msg->message); - } - else if(msgtype == NETMSGTYPE_CL_CALLVOTE) - { - int64 now = time_get(); - if(game.vote_closetime) - { - game.send_chat_target(client_id, "Wait for current vote to end before calling a new one."); - return; - } - - int64 timeleft = p->last_votecall + time_freq()*60 - now; - if(timeleft > 0) - { - char chatmsg[512] = {0}; - str_format(chatmsg, sizeof(chatmsg), "You must wait %d seconds before making another vote", (timeleft/time_freq())+1); - game.send_chat_target(client_id, chatmsg); - return; - } - - char chatmsg[512] = {0}; - char desc[512] = {0}; - char cmd[512] = {0}; - NETMSG_CL_CALLVOTE *msg = (NETMSG_CL_CALLVOTE *)rawmsg; - if(str_comp_nocase(msg->type, "option") == 0) - { - VOTEOPTION *option = voteoption_first; - while(option) - { - if(str_comp_nocase(msg->value, option->command) == 0) - { - str_format(chatmsg, sizeof(chatmsg), "%s called vote to change server option '%s'", server_clientname(client_id), option->command); - str_format(desc, sizeof(desc), "%s", option->command); - str_format(cmd, sizeof(cmd), "%s", option->command); - break; - } - - option = option->next; - } - - if(!option) - { - str_format(chatmsg, sizeof(chatmsg), "'%s' isn't an option on this server", msg->value); - game.send_chat_target(client_id, chatmsg); - return; - } - } - else if(str_comp_nocase(msg->type, "kick") == 0) - { - if(!config.sv_vote_kick) - { - game.send_chat_target(client_id, "Server does not allow voting to kick players"); - return; - } - - int kick_id = atoi(msg->value); - if(kick_id < 0 || kick_id >= MAX_CLIENTS || !game.players[kick_id]) - { - game.send_chat_target(client_id, "Invalid client id to kick"); - return; - } - - str_format(chatmsg, sizeof(chatmsg), "Vote called to kick '%s'", server_clientname(kick_id)); - str_format(desc, sizeof(desc), "Kick '%s'", server_clientname(kick_id)); - str_format(cmd, sizeof(cmd), "kick %d", kick_id); - if (!config.sv_vote_kick_bantime) - str_format(cmd, sizeof(cmd), "kick %d", kick_id); - else - str_format(cmd, sizeof(cmd), "ban %d %d", kick_id, config.sv_vote_kick_bantime); - } - - if(cmd[0]) - { - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chatmsg); - game.start_vote(desc, cmd); - p->vote = 1; - game.vote_creator = client_id; - p->last_votecall = now; - game.send_vote_status(-1); - } - } - else if(msgtype == NETMSGTYPE_CL_VOTE) - { - if(!game.vote_closetime) - return; - - if(p->vote == 0) - { - NETMSG_CL_VOTE *msg = (NETMSG_CL_VOTE *)rawmsg; - p->vote = msg->vote; - game.send_vote_status(-1); - } - } - else if (msgtype == NETMSGTYPE_CL_SETTEAM && !game.world.paused) - { - NETMSG_CL_SETTEAM *msg = (NETMSG_CL_SETTEAM *)rawmsg; - - if(p->team == msg->team || (config.sv_spamprotection && p->last_setteam+time_freq()*3 > time_get())) - return; - - // Switch team on given client and kill/respawn him - if(game.controller->can_join_team(msg->team, client_id)) - { - if(game.controller->can_change_team(p, msg->team)) - { - p->last_setteam = time_get(); - p->set_team(msg->team); - (void) game.controller->check_team_balance(); - } - else - game.send_broadcast("Teams must be balanced, please join other team", client_id); - } - else - { - char buf[128]; - str_format(buf, sizeof(buf), "Only %d active players are allowed", config.sv_max_clients-config.sv_spectator_slots); - game.send_broadcast(buf, client_id); - } - } - else if (msgtype == NETMSGTYPE_CL_CHANGEINFO || msgtype == NETMSGTYPE_CL_STARTINFO) - { - NETMSG_CL_CHANGEINFO *msg = (NETMSG_CL_CHANGEINFO *)rawmsg; - - if(config.sv_spamprotection && p->last_changeinfo+time_freq()*5 > time_get()) - return; - - p->last_changeinfo = time_get(); - - p->use_custom_color = msg->use_custom_color; - p->color_body = msg->color_body; - p->color_feet = msg->color_feet; - - // check for invalid chars - unsigned char *name = (unsigned char *)msg->name; - while (*name) - { - if(*name < 32) - *name = ' '; - name++; - } - - // copy old name - char oldname[MAX_NAME_LENGTH]; - str_copy(oldname, server_clientname(client_id), MAX_NAME_LENGTH); - - server_setclientname(client_id, msg->name); - if(msgtype == NETMSGTYPE_CL_CHANGEINFO && strcmp(oldname, server_clientname(client_id)) != 0) - { - char chattext[256]; - str_format(chattext, sizeof(chattext), "%s changed name to %s", oldname, server_clientname(client_id)); - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, chattext); - } - - // set skin - str_copy(p->skin_name, msg->skin, sizeof(p->skin_name)); - - game.controller->on_player_info_change(p); - - if(msgtype == NETMSGTYPE_CL_STARTINFO) - { - // send vote options - NETMSG_SV_VOTE_CLEAROPTIONS clearmsg; - clearmsg.pack(MSGFLAG_VITAL); - server_send_msg(client_id); - VOTEOPTION *current = voteoption_first; - while(current) - { - NETMSG_SV_VOTE_OPTION optionmsg; - optionmsg.command = current->command; - optionmsg.pack(MSGFLAG_VITAL); - server_send_msg(client_id); - current = current->next; - } - - // send tuning parameters to client - send_tuning_params(client_id); - - // - NETMSG_SV_READYTOENTER m; - m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH); - server_send_msg(client_id); - } - } - else if (msgtype == NETMSGTYPE_CL_EMOTICON && !game.world.paused) - { - NETMSG_CL_EMOTICON *msg = (NETMSG_CL_EMOTICON *)rawmsg; - - if(config.sv_spamprotection && p->last_emote+time_freq()*3 > time_get()) - return; - - p->last_emote = time_get(); - - game.send_emoticon(client_id, msg->emoticon); - } - else if (msgtype == NETMSGTYPE_CL_KILL && !game.world.paused) - { - if(p->last_kill+time_freq()*3 > time_get()) - return; - - p->last_kill = time_get(); - p->kill_character(WEAPON_SELF); - p->respawn_tick = server_tick()+server_tickspeed()*3; - } -} - -static void con_tune_param(void *result, void *user_data) -{ - const char *param_name = console_arg_string(result, 0); - float new_value = console_arg_float(result, 1); - - if(tuning.set(param_name, new_value)) - { - dbg_msg("tuning", "%s changed to %.2f", param_name, new_value); - send_tuning_params(-1); - } - else - console_print("No such tuning parameter"); -} - -static void con_tune_reset(void *result, void *user_data) -{ - TUNING_PARAMS p; - tuning = p; - send_tuning_params(-1); - console_print("tuning reset"); -} - -static void con_tune_dump(void *result, void *user_data) -{ - for(int i = 0; i < tuning.num(); i++) - { - float v; - tuning.get(i, &v); - dbg_msg("tuning", "%s %.2f", tuning.names[i], v); - } -} - - -static void con_change_map(void *result, void *user_data) -{ - game.controller->change_map(console_arg_string(result, 0)); -} - -static void con_restart(void *result, void *user_data) -{ - if(console_arg_num(result)) - game.controller->do_warmup(console_arg_int(result, 0)); - else - game.controller->startround(); -} - -static void con_broadcast(void *result, void *user_data) -{ - game.send_broadcast(console_arg_string(result, 0), -1); -} - -static void con_say(void *result, void *user_data) -{ - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, console_arg_string(result, 0)); -} - -static void con_set_team(void *result, void *user_data) -{ - int client_id = clamp(console_arg_int(result, 0), 0, (int)MAX_CLIENTS - 1); - int team = clamp(console_arg_int(result, 1), -1, 1); - - dbg_msg("", "%d %d", client_id, team); - - if(!game.players[client_id]) - return; - - game.players[client_id]->set_team(team); - (void) game.controller->check_team_balance(); -} - -static void con_addvote(void *result, void *user_data) -{ - int len = strlen(console_arg_string(result, 0)); - - if(!voteoption_heap) - voteoption_heap = memheap_create(); - - VOTEOPTION *option = (VOTEOPTION *)memheap_allocate(voteoption_heap, sizeof(VOTEOPTION) + len); - option->next = 0; - option->prev = voteoption_last; - if(option->prev) - option->prev->next = option; - voteoption_last = option; - if(!voteoption_first) - voteoption_first = option; - - mem_copy(option->command, console_arg_string(result, 0), len+1); - dbg_msg("server", "added option '%s'", option->command); -} - -static void con_vote(void *result, void *user_data) -{ - if(str_comp_nocase(console_arg_string(result, 0), "yes") == 0) - game.vote_enforce = GAMECONTEXT::VOTE_ENFORCE_YES; - else if(str_comp_nocase(console_arg_string(result, 0), "no") == 0) - game.vote_enforce = GAMECONTEXT::VOTE_ENFORCE_NO; - dbg_msg("server", "forcing vote %s", console_arg_string(result, 0)); -} - -void mods_console_init() -{ - MACRO_REGISTER_COMMAND("tune", "si", CFGFLAG_SERVER, con_tune_param, 0, ""); - MACRO_REGISTER_COMMAND("tune_reset", "", CFGFLAG_SERVER, con_tune_reset, 0, ""); - MACRO_REGISTER_COMMAND("tune_dump", "", CFGFLAG_SERVER, con_tune_dump, 0, ""); - - MACRO_REGISTER_COMMAND("change_map", "r", CFGFLAG_SERVER, con_change_map, 0, ""); - MACRO_REGISTER_COMMAND("restart", "?i", CFGFLAG_SERVER, con_restart, 0, ""); - MACRO_REGISTER_COMMAND("broadcast", "r", CFGFLAG_SERVER, con_broadcast, 0, ""); - MACRO_REGISTER_COMMAND("say", "r", CFGFLAG_SERVER, con_say, 0, ""); - MACRO_REGISTER_COMMAND("set_team", "ii", CFGFLAG_SERVER, con_set_team, 0, ""); - - MACRO_REGISTER_COMMAND("addvote", "r", CFGFLAG_SERVER, con_addvote, 0, ""); - MACRO_REGISTER_COMMAND("vote", "r", CFGFLAG_SERVER, con_vote, 0, ""); -} - -void mods_init() -{ - //if(!data) /* only load once */ - //data = load_data_from_memory(internal_data); - - for(int i = 0; i < NUM_NETOBJTYPES; i++) - snap_set_staticsize(i, netobj_get_size(i)); - - layers_init(); - col_init(); - - // reset everything here - //world = new GAMEWORLD; - //players = new PLAYER[MAX_CLIENTS]; - - // select gametype - if(strcmp(config.sv_gametype, "mod") == 0) - game.controller = new GAMECONTROLLER_MOD; - else if(strcmp(config.sv_gametype, "ctf") == 0) - game.controller = new GAMECONTROLLER_CTF; - else if(strcmp(config.sv_gametype, "tdm") == 0) - game.controller = new GAMECONTROLLER_TDM; - else - game.controller = new GAMECONTROLLER_DM; - - // setup core world - //for(int i = 0; i < MAX_CLIENTS; i++) - // game.players[i].core.world = &game.world.core; - - // create all entities from the game layer - MAPITEM_LAYER_TILEMAP *tmap = layers_game_layer(); - TILE *tiles = (TILE *)map_get_data(tmap->data); - - /* - num_spawn_points[0] = 0; - num_spawn_points[1] = 0; - num_spawn_points[2] = 0; - */ - - for(int y = 0; y < tmap->height; y++) - { - for(int x = 0; x < tmap->width; x++) - { - int index = tiles[y*tmap->width+x].index; - - if(index >= ENTITY_OFFSET) - { - vec2 pos(x*32.0f+16.0f, y*32.0f+16.0f); - game.controller->on_entity(index-ENTITY_OFFSET, pos); - } - } - } - - //game.world.insert_entity(game.controller); - -#ifdef CONF_DEBUG - if(config.dbg_dummies) - { - for(int i = 0; i < config.dbg_dummies ; i++) - { - mods_connected(MAX_CLIENTS-i-1); - mods_client_enter(MAX_CLIENTS-i-1); - if(game.controller->is_teamplay()) - game.players[MAX_CLIENTS-i-1]->team = i&1; - } - } -#endif -} - -void mods_shutdown() -{ - delete game.controller; - game.controller = 0; - game.clear(); -} - -void mods_presnap() {} -void mods_postsnap() -{ - game.events.clear(); -} - -extern "C" const char *mods_net_version() { return GAME_NETVERSION; } -extern "C" const char *mods_version() { return GAME_VERSION; } diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/player.cpp b/project/jni/application/teeworlds-0.5.2/src/game/server/player.cpp deleted file mode 100644 index a0a2b051f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/player.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include - -#include - -#include "player.hpp" -#include "gamecontext.hpp" - -MACRO_ALLOC_POOL_ID_IMPL(PLAYER, MAX_CLIENTS) - -PLAYER::PLAYER(int client_id) -{ - respawn_tick = server_tick(); - character = 0; - this->client_id = client_id; -} - -PLAYER::~PLAYER() -{ - delete character; - character = 0; -} - -void PLAYER::tick() -{ - server_setclientscore(client_id, score); - - // do latency stuff - { - CLIENT_INFO info; - if(server_getclientinfo(client_id, &info)) - { - latency.accum += info.latency; - latency.accum_max = max(latency.accum_max, info.latency); - latency.accum_min = min(latency.accum_min, info.latency); - } - - if(server_tick()%server_tickspeed() == 0) - { - latency.avg = latency.accum/server_tickspeed(); - latency.max = latency.accum_max; - latency.min = latency.accum_min; - latency.accum = 0; - latency.accum_min = 1000; - latency.accum_max = 0; - } - } - - if(!character && die_tick+server_tickspeed()*3 <= server_tick()) - spawning = true; - - if(character) - { - if(character->alive) - { - view_pos = character->pos; - } - else - { - delete character; - character = 0; - } - } - else if(spawning && respawn_tick <= server_tick()) - try_respawn(); -} - -void PLAYER::snap(int snapping_client) -{ - NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO)); - str_to_ints(&client_info->name0, 6, server_clientname(client_id)); - str_to_ints(&client_info->skin0, 6, skin_name); - client_info->use_custom_color = use_custom_color; - client_info->color_body = color_body; - client_info->color_feet = color_feet; - - NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO)); - - info->latency = latency.min; - info->latency_flux = latency.max-latency.min; - info->local = 0; - info->cid = client_id; - info->score = score; - info->team = team; - - if(client_id == snapping_client) - info->local = 1; -} - -void PLAYER::on_disconnect() -{ - kill_character(WEAPON_GAME); - - //game.controller->on_player_death(&game.players[client_id], 0, -1); - - char buf[512]; - str_format(buf, sizeof(buf), "%s has left the game", server_clientname(client_id)); - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); - - dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id)); -} - -void PLAYER::on_predicted_input(NETOBJ_PLAYER_INPUT *new_input) -{ - CHARACTER *chr = get_character(); - if(chr) - chr->on_predicted_input(new_input); -} - -void PLAYER::on_direct_input(NETOBJ_PLAYER_INPUT *new_input) -{ - CHARACTER *chr = get_character(); - if(chr) - chr->on_direct_input(new_input); - - if(!chr && team >= 0 && (new_input->fire&1)) - spawning = true; - - if(!chr && team == -1) - view_pos = vec2(new_input->target_x, new_input->target_y); -} - -CHARACTER *PLAYER::get_character() -{ - if(character && character->alive) - return character; - return 0; -} - -void PLAYER::kill_character(int weapon) -{ - //CHARACTER *chr = get_character(); - if(character) - { - character->die(client_id, weapon); - delete character; - character = 0; - } -} - -void PLAYER::respawn() -{ - if(team > -1) - spawning = true; -} - -void PLAYER::set_team(int new_team) -{ - // clamp the team - new_team = game.controller->clampteam(new_team); - if(team == new_team) - return; - - char buf[512]; - str_format(buf, sizeof(buf), "%s joined the %s", server_clientname(client_id), game.controller->get_team_name(new_team)); - game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); - - kill_character(WEAPON_GAME); - team = new_team; - score = 0; - dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team); - - game.controller->on_player_info_change(game.players[client_id]); -} - -void PLAYER::try_respawn() -{ - vec2 spawnpos = vec2(100.0f, -60.0f); - - if(!game.controller->can_spawn(this, &spawnpos)) - return; - - // check if the position is occupado - ENTITY *ents[2] = {0}; - int num_ents = game.world.find_entities(spawnpos, 64, ents, 2, NETOBJTYPE_CHARACTER); - - if(num_ents == 0) - { - spawning = false; - character = new(client_id) CHARACTER(); - character->spawn(this, spawnpos, team); - game.create_playerspawn(spawnpos); - } -} diff --git a/project/jni/application/teeworlds-0.5.2/src/game/server/player.hpp b/project/jni/application/teeworlds-0.5.2/src/game/server/player.hpp deleted file mode 100644 index e93aee01f..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/server/player.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef GAME_SERVER_PLAYER_H -#define GAME_SERVER_PLAYER_H - -// this include should perhaps be removed -#include "entities/character.hpp" - -// player object -class PLAYER -{ - MACRO_ALLOC_POOL_ID() -private: - CHARACTER *character; -public: - PLAYER(int client_id); - ~PLAYER(); - - // TODO: clean this up - char skin_name[64]; - int use_custom_color; - int color_body; - int color_feet; - - int respawn_tick; - int die_tick; - // - bool spawning; - int client_id; - int team; - int score; - bool force_balanced; - - // - int vote; - int64 last_votecall; - - // - int64 last_chat; - int64 last_setteam; - int64 last_changeinfo; - int64 last_emote; - int64 last_kill; - - // network latency calculations - struct - { - int accum; - int accum_min; - int accum_max; - int avg; - int min; - int max; - } latency; - - // this is used for snapping so we know how we can clip the view for the player - vec2 view_pos; - - void init(int client_id); - - CHARACTER *get_character(); - - void kill_character(int weapon); - - void try_respawn(); - void respawn(); - void set_team(int team); - - void tick(); - void snap(int snapping_client); - - void on_direct_input(NETOBJ_PLAYER_INPUT *new_input); - void on_predicted_input(NETOBJ_PLAYER_INPUT *new_input); - void on_disconnect(); -}; - -#endif diff --git a/project/jni/application/teeworlds-0.5.2/src/game/tuning.hpp b/project/jni/application/teeworlds-0.5.2/src/game/tuning.hpp deleted file mode 100644 index 4554a8eb5..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/tuning.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* physics tuning */ -MACRO_TUNING_PARAM(ground_control_speed, 10.0f) -MACRO_TUNING_PARAM(ground_control_accel, 100.0f / ticks_per_second) -MACRO_TUNING_PARAM(ground_friction, 0.5f) -MACRO_TUNING_PARAM(ground_jump_impulse, 13.2f) -MACRO_TUNING_PARAM(air_jump_impulse, 12.0f) -MACRO_TUNING_PARAM(air_control_speed, 250.0f / ticks_per_second) -MACRO_TUNING_PARAM(air_control_accel, 1.5f) -MACRO_TUNING_PARAM(air_friction, 0.95f) -MACRO_TUNING_PARAM(hook_length, 380.0f) -MACRO_TUNING_PARAM(hook_fire_speed, 80.0f) -MACRO_TUNING_PARAM(hook_drag_accel, 3.0f) -MACRO_TUNING_PARAM(hook_drag_speed, 15.0f) -MACRO_TUNING_PARAM(gravity, 0.5f) - -MACRO_TUNING_PARAM(velramp_start, 550) -MACRO_TUNING_PARAM(velramp_range, 2000) -MACRO_TUNING_PARAM(velramp_curvature, 1.4f) - -/* weapon tuning */ -MACRO_TUNING_PARAM(gun_curvature, 1.25f) -MACRO_TUNING_PARAM(gun_speed, 2200.0f) -MACRO_TUNING_PARAM(gun_lifetime, 2.0f) - -MACRO_TUNING_PARAM(shotgun_curvature, 1.25f) -MACRO_TUNING_PARAM(shotgun_speed, 2750.0f) -MACRO_TUNING_PARAM(shotgun_speeddiff, 0.8f) -MACRO_TUNING_PARAM(shotgun_lifetime, 0.20f) - -MACRO_TUNING_PARAM(grenade_curvature, 7.0f) -MACRO_TUNING_PARAM(grenade_speed, 1000.0f) -MACRO_TUNING_PARAM(grenade_lifetime, 2.0f) - -MACRO_TUNING_PARAM(laser_reach, 800.0f) -MACRO_TUNING_PARAM(laser_bounce_delay, 150) -MACRO_TUNING_PARAM(laser_bounce_num, 1) -MACRO_TUNING_PARAM(laser_bounce_cost, 0) -MACRO_TUNING_PARAM(laser_damage, 5) - -MACRO_TUNING_PARAM(player_collision, 1) -MACRO_TUNING_PARAM(player_hooking, 1) diff --git a/project/jni/application/teeworlds-0.5.2/src/game/variables.hpp b/project/jni/application/teeworlds-0.5.2/src/game/variables.hpp deleted file mode 100644 index f78b168d4..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/variables.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - - -/* client */ -MACRO_CONFIG_INT(cl_predict, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict client movements") -MACRO_CONFIG_INT(cl_nameplates, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show nameplates") -MACRO_CONFIG_INT(cl_nameplates_always, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Always show nameplats disregarding of distance") -MACRO_CONFIG_INT(cl_autoswitch_weapons, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon on pickup") - -MACRO_CONFIG_INT(cl_showfps, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame FPS counter") - -MACRO_CONFIG_INT(cl_airjumpindicator, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") -MACRO_CONFIG_INT(cl_threadsoundloading, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") - -MACRO_CONFIG_INT(cl_warning_teambalance, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Warn about team balance") - -MACRO_CONFIG_INT(cl_mouse_deadzone, 300, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") -MACRO_CONFIG_INT(cl_mouse_followfactor, 60, 0, 200, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") -MACRO_CONFIG_INT(cl_mouse_max_distance, 800, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") - -MACRO_CONFIG_INT(ed_showkeys, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") - -MACRO_CONFIG_INT(cl_flow, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") - -MACRO_CONFIG_INT(cl_show_welcome, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "") -MACRO_CONFIG_INT(cl_motd_time, 10, 0, 100, CFGFLAG_CLIENT|CFGFLAG_SAVE, "How long to show the server message of the day") - -MACRO_CONFIG_STR(cl_version_server, 100, "version.teeworlds.com", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Server to use to check for new versions") - -MACRO_CONFIG_INT(player_use_custom_color, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toggles usage of custom colors") -MACRO_CONFIG_INT(player_color_body, 65408, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player body color") -MACRO_CONFIG_INT(player_color_feet, 65408, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player feet color") -MACRO_CONFIG_STR(player_skin, 64, "default", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player skin") - -MACRO_CONFIG_INT(ui_page, 5, 0, 9, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface page") -MACRO_CONFIG_INT(ui_toolbox_page, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toolbox page") -MACRO_CONFIG_STR(ui_server_address, 128, "localhost:8303", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface server address") -MACRO_CONFIG_INT(ui_scale, 100, 1, 100000, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface scale") - -MACRO_CONFIG_INT(ui_color_hue, 160, 0, 255, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface color hue") -MACRO_CONFIG_INT(ui_color_sat, 70, 0, 255, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface color saturation") -MACRO_CONFIG_INT(ui_color_lht, 175, 0, 255, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface color lightness") -MACRO_CONFIG_INT(ui_color_alpha, 228, 0, 255, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Interface alpha") - -MACRO_CONFIG_INT(gfx_noclip, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Disable clipping") - -/* server */ -MACRO_CONFIG_INT(sv_warmup, 0, 0, 0, CFGFLAG_SERVER, "Number of seconds to do warpup before round starts") -MACRO_CONFIG_STR(sv_motd, 900, "", CFGFLAG_SERVER, "Message of the day to display for the clients") -MACRO_CONFIG_INT(sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage") -MACRO_CONFIG_STR(sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between") -MACRO_CONFIG_INT(sv_rounds_per_map, 1, 1, 100, CFGFLAG_SERVER, "Number of rounds on each map before rotating") -MACRO_CONFIG_INT(sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja") -MACRO_CONFIG_INT(sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)") -MACRO_CONFIG_INT(sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)") -MACRO_CONFIG_STR(sv_gametype, 32, "dm", CFGFLAG_SERVER, "Game type (dm, tdm, ctf)") -MACRO_CONFIG_INT(sv_tournament_mode, 0, 0, 1, CFGFLAG_SERVER, "Tournament mode. When enabled, players joins the server as spectator") -MACRO_CONFIG_INT(sv_spamprotection, 1, 0, 1, CFGFLAG_SERVER, "Spam protection") - -MACRO_CONFIG_INT(sv_spectator_slots, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Number of slots to reserve for spectators") -MACRO_CONFIG_INT(sv_teambalance_time, 1, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before autobalancing teams") - -MACRO_CONFIG_INT(sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players") -MACRO_CONFIG_INT(sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick") -MACRO_CONFIG_INT(sv_vote_scorelimit, 0, 0, 1, CFGFLAG_SERVER, "Allow voting to change score limit") -MACRO_CONFIG_INT(sv_vote_timelimit, 0, 0, 1, CFGFLAG_SERVER, "Allow voting to change time limit") - -/* debug */ -#ifdef CONF_DEBUG /* this one can crash the server if not used correctly */ - MACRO_CONFIG_INT(dbg_dummies, 0, 0, 15, CFGFLAG_SERVER, "") -#endif - -MACRO_CONFIG_INT(dbg_focus, 0, 0, 1, CFGFLAG_CLIENT, "") -MACRO_CONFIG_INT(dbg_tuning, 0, 0, 1, CFGFLAG_CLIENT, "") diff --git a/project/jni/application/teeworlds-0.5.2/src/game/version.hpp b/project/jni/application/teeworlds-0.5.2/src/game/version.hpp deleted file mode 100644 index 99628b856..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/game/version.hpp +++ /dev/null @@ -1,4 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include "generated/nethash.c" -#define GAME_VERSION "0.5.2" -#define GAME_NETVERSION "0.5 " GAME_NETVERSION_HASH diff --git a/project/jni/application/teeworlds-0.5.2/src/mastersrv/mastersrv.h b/project/jni/application/teeworlds-0.5.2/src/mastersrv/mastersrv.h deleted file mode 100644 index cfac2e715..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/mastersrv/mastersrv.h +++ /dev/null @@ -1,27 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -static const int MASTERSERVER_PORT = 8300; - -typedef struct MASTERSRV_ADDR -{ - unsigned char ip[4]; - unsigned char port[2]; -} MASTERSRV_ADDR; - -static const unsigned char SERVERBROWSE_HEARTBEAT[] = {255, 255, 255, 255, 'b', 'e', 'a', 't'}; - -static const unsigned char SERVERBROWSE_GETLIST[] = {255, 255, 255, 255, 'r', 'e', 'q', 't'}; -static const unsigned char SERVERBROWSE_LIST[] = {255, 255, 255, 255, 'l', 'i', 's', 't'}; - -static const unsigned char SERVERBROWSE_GETCOUNT[] = {255, 255, 255, 255, 'c', 'o', 'u', 'n'}; -static const unsigned char SERVERBROWSE_COUNT[] = {255, 255, 255, 255, 's', 'i', 'z', 'e'}; - -static const unsigned char SERVERBROWSE_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', '2'}; -static const unsigned char SERVERBROWSE_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', '2'}; - -static const unsigned char SERVERBROWSE_OLD_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', 'f'}; -static const unsigned char SERVERBROWSE_OLD_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', 'o'}; - -static const unsigned char SERVERBROWSE_FWCHECK[] = {255, 255, 255, 255, 'f', 'w', '?', '?'}; -static const unsigned char SERVERBROWSE_FWRESPONSE[] = {255, 255, 255, 255, 'f', 'w', '!', '!'}; -static const unsigned char SERVERBROWSE_FWOK[] = {255, 255, 255, 255, 'f', 'w', 'o', 'k'}; -static const unsigned char SERVERBROWSE_FWERROR[] = {255, 255, 255, 255, 'f', 'w', 'e', 'r'}; diff --git a/project/jni/application/teeworlds-0.5.2/src/versionsrv/versionsrv.h b/project/jni/application/teeworlds-0.5.2/src/versionsrv/versionsrv.h deleted file mode 100644 index 298f6c275..000000000 --- a/project/jni/application/teeworlds-0.5.2/src/versionsrv/versionsrv.h +++ /dev/null @@ -1,7 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -static const int VERSIONSRV_PORT = 8302; - -static const unsigned char VERSION_DATA[] = {0x00, 0, 5, 1}; - -static const unsigned char VERSIONSRV_GETVERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 'g'}; -static const unsigned char VERSIONSRV_VERSION[] = {255, 255, 255, 255, 'v', 'e', 'r', 's'}; diff --git a/project/jni/application/teeworlds/AndroidAppSettings.cfg b/project/jni/application/teeworlds/AndroidAppSettings.cfg index 0ea1fb69d..d240dcc18 100644 --- a/project/jni/application/teeworlds/AndroidAppSettings.cfg +++ b/project/jni/application/teeworlds/AndroidAppSettings.cfg @@ -159,10 +159,10 @@ MultiABI=y AppMinimumRAM=0 # Application version code (integer) -AppVersionCode=06208 +AppVersionCode=06209 # Application user-visible version name (string) -AppVersionName="0.6.2.08" +AppVersionName="0.6.2.09" # Reset SDL config when updating application to the new version (y) / (n) ResetSdlConfigForThisVersion=y diff --git a/project/jni/application/teeworlds/src b/project/jni/application/teeworlds/src index 6b42c4d0c..829dce89a 160000 --- a/project/jni/application/teeworlds/src +++ b/project/jni/application/teeworlds/src @@ -1 +1 @@ -Subproject commit 6b42c4d0cdcdf19552e3d7ab5bd58d46bdfc834a +Subproject commit 829dce89a2ad994d476e5a009ee7265e96832200