166 changes: 146 additions & 20 deletions other/sdl/include/SDL_stdinc.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -83,16 +83,20 @@
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
# include <iconv.h>
#endif

/**
* The number of elements in an array.
*/
#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
#define SDL_TABLESIZE(table) SDL_arraysize(table)

/**
* Macro useful for building other macros with strings in them
*
* e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
*/
#define SDL_STRINGIFY_ARG(arg) #arg

/**
* \name Cast operators
*
Expand Down Expand Up @@ -165,6 +169,97 @@ typedef uint64_t Uint64;

/* @} *//* Basic data types */

/* Make sure we have macros for printing 64 bit values.
* <stdint.h> should define these but this is not true all platforms.
* (for example win32) */
#ifndef SDL_PRIs64
#ifdef PRIs64
#define SDL_PRIs64 PRIs64
#elif defined(__WIN32__)
#define SDL_PRIs64 "I64d"
#elif defined(__LINUX__) && defined(__LP64__)
#define SDL_PRIs64 "ld"
#else
#define SDL_PRIs64 "lld"
#endif
#endif
#ifndef SDL_PRIu64
#ifdef PRIu64
#define SDL_PRIu64 PRIu64
#elif defined(__WIN32__)
#define SDL_PRIu64 "I64u"
#elif defined(__LINUX__) && defined(__LP64__)
#define SDL_PRIu64 "lu"
#else
#define SDL_PRIu64 "llu"
#endif
#endif
#ifndef SDL_PRIx64
#ifdef PRIx64
#define SDL_PRIx64 PRIx64
#elif defined(__WIN32__)
#define SDL_PRIx64 "I64x"
#elif defined(__LINUX__) && defined(__LP64__)
#define SDL_PRIx64 "lx"
#else
#define SDL_PRIx64 "llx"
#endif
#endif
#ifndef SDL_PRIX64
#ifdef PRIX64
#define SDL_PRIX64 PRIX64
#elif defined(__WIN32__)
#define SDL_PRIX64 "I64X"
#elif defined(__LINUX__) && defined(__LP64__)
#define SDL_PRIX64 "lX"
#else
#define SDL_PRIX64 "llX"
#endif
#endif

/* Annotations to help code analysis tools */
#ifdef SDL_DISABLE_ANALYZE_MACROS
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#else
#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
#include <sal.h>

#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
#define SDL_OUT_CAP(x) _Out_cap_(x)
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)

#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
#else
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#endif
#if defined(__GNUC__)
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
#else
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#endif
#endif /* SDL_DISABLE_ANALYZE_MACROS */

#define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_dummy_ ## name[(x) * 2 - 1]
Expand Down Expand Up @@ -259,7 +354,7 @@ extern DECLSPEC int SDLCALL SDL_isspace(int x);
extern DECLSPEC int SDLCALL SDL_toupper(int x);
extern DECLSPEC int SDLCALL SDL_tolower(int x);

extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);

#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
Expand Down Expand Up @@ -294,24 +389,19 @@ SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
}


extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);

SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
{
return SDL_memcpy(dst, src, dwords * 4);
}
extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);

extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);

extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);

extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
Expand Down Expand Up @@ -340,10 +430,10 @@ extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);

extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);

#ifndef HAVE_M_PI
#ifndef M_PI
Expand All @@ -367,6 +457,9 @@ extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
extern DECLSPEC double SDLCALL SDL_sin(double x);
extern DECLSPEC float SDLCALL SDL_sinf(float x);
extern DECLSPEC double SDLCALL SDL_sqrt(double x);
extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
extern DECLSPEC double SDLCALL SDL_tan(double x);
extern DECLSPEC float SDLCALL SDL_tanf(float x);

/* The SDL implementation of iconv() returns these error codes */
#define SDL_ICONV_ERROR (size_t)-1
Expand Down Expand Up @@ -394,6 +487,39 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)

/* force builds using Clang's static analysis tools to use literal C runtime
here, since there are possibly tests that are ineffective otherwise. */
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
#define SDL_malloc malloc
#define SDL_calloc calloc
#define SDL_realloc realloc
#define SDL_free free
#define SDL_memset memset
#define SDL_memcpy memcpy
#define SDL_memmove memmove
#define SDL_memcmp memcmp
#define SDL_strlen strlen
#define SDL_strlcpy strlcpy
#define SDL_strlcat strlcat
#define SDL_strdup strdup
#define SDL_strchr strchr
#define SDL_strrchr strrchr
#define SDL_strstr strstr
#define SDL_strcmp strcmp
#define SDL_strncmp strncmp
#define SDL_strcasecmp strcasecmp
#define SDL_strncasecmp strncasecmp
#define SDL_sscanf sscanf
#define SDL_vsscanf vsscanf
#define SDL_snprintf snprintf
#define SDL_vsnprintf vsnprintf
#endif

SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
{
return SDL_memcpy(dst, src, dwords * 4);
}

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down
12 changes: 11 additions & 1 deletion other/sdl/include/SDL_surface.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -118,6 +118,8 @@ typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
(Uint32 flags, int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
(Uint32 flags, int width, int height, int depth, Uint32 format);
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
int width,
int height,
Expand All @@ -127,6 +129,8 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask);
extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
(void *pixels, int width, int height, int depth, int pitch, Uint32 format);
extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);

/**
Expand Down Expand Up @@ -184,6 +188,12 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
/**
* Save a surface to a seekable SDL data stream (memory or file).
*
* Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
* BMP directly. Other RGB formats with 8-bit or higher get converted to a
* 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
* surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
* not supported.
*
* If \c freedst is non-zero, the stream will be closed after being written.
*
* \return 0 if successful or -1 if there was an error.
Expand Down
55 changes: 40 additions & 15 deletions other/sdl/include/SDL_system.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -42,32 +42,47 @@ extern "C" {

/* Platform specific functions for Windows */
#ifdef __WIN32__

/**
\brief Set a function that is called for every windows message, before TranslateMessage()
*/
typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);

/**
\brief Returns the D3D9 adapter index that matches the specified display index.
/* Returns the D3D9 adapter index that matches the specified display index.
This adapter index can be passed to IDirect3D9::CreateDevice and controls
on which monitor a full screen application will appear.
*/
extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );

/* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
typedef struct IDirect3DDevice9 IDirect3DDevice9;
/**
\brief Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
Once you are done using the device, you should release it to avoid a resource leak.
*/
typedef struct IDirect3DDevice9 IDirect3DDevice9;
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);

/* Returns the DXGI Adapter and Output indices for the specified display index.
/**
\brief Returns the DXGI Adapter and Output indices for the specified display index.
These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
required to create a DX10 or DX11 device and swap chain.
*/
extern DECLSPEC void SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );

#endif /* __WIN32__ */


/* Platform specific functions for iOS */
#if defined(__IPHONEOS__) && __IPHONEOS__

#define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);

#define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);

#endif /* __IPHONEOS__ */
Expand All @@ -76,39 +91,50 @@ extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
/* Platform specific functions for Android */
#if defined(__ANDROID__) && __ANDROID__

/* Get the JNI environment for the current thread
/**
\brief Get the JNI environment for the current thread
This returns JNIEnv*, but the prototype is void* so we don't need jni.h
*/
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();

/* Get the SDL Activity object for the application
/**
\brief Get the SDL Activity object for the application
This returns jobject, but the prototype is void* so we don't need jni.h
The jobject returned by SDL_AndroidGetActivity is a local reference.
It is the caller's responsibility to properly release it
(using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
*/
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();

/* See the official Android developer guide for more information:
/**
See the official Android developer guide for more information:
http://developer.android.com/guide/topics/data/data-storage.html
*/
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02

/* Get the path used for internal storage for this application.
/**
\brief Get the path used for internal storage for this application.
This path is unique to your application and cannot be written to
by other applications.
*/
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();

/* Get the current state of external storage, a bitmask of these values:
/**
\brief Get the current state of external storage, a bitmask of these values:
SDL_ANDROID_EXTERNAL_STORAGE_READ
SDL_ANDROID_EXTERNAL_STORAGE_WRITE
If external storage is currently unavailable, this will return 0.
*/
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();

/* Get the path used for external storage for this application.
/**
\brief Get the path used for external storage for this application.
This path is unique to your application, but is public and can be
written to by other applications.
*/
Expand Down Expand Up @@ -151,7 +177,7 @@ typedef enum
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
*
* \param pathType The type of path to retrieve.
* \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL
* \return A UCS-2 string (16-bit, wide-char) containing the path, or NULL
* if the path is not available for any reason. Not all paths are
* available on all versions of Windows. This is especially true on
* Windows Phone. Check the documentation for the given
Expand All @@ -168,7 +194,7 @@ extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
*
* \param pathType The type of path to retrieve.
* \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
* \return A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
* if the path is not available for any reason. Not all paths are
* available on all versions of Windows. This is especially true on
* Windows Phone. Check the documentation for the given
Expand All @@ -179,7 +205,6 @@ extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathT

#endif /* __WINRT__ */


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down
65 changes: 57 additions & 8 deletions other/sdl/include/SDL_syswm.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -52,7 +52,9 @@ struct SDL_SysWMinfo;
#else

#if defined(SDL_VIDEO_DRIVER_WINDOWS)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#endif

Expand Down Expand Up @@ -83,7 +85,7 @@ struct SDL_SysWMinfo;

#if defined(SDL_VIDEO_DRIVER_COCOA)
#ifdef __OBJC__
#include <Cocoa/Cocoa.h>
@class NSWindow;
#else
typedef struct _NSWindow NSWindow;
#endif
Expand All @@ -96,12 +98,17 @@ typedef struct _NSWindow NSWindow;
typedef struct _UIWindow UIWindow;
typedef struct _UIViewController UIViewController;
#endif
typedef Uint32 GLuint;
#endif

#if defined(SDL_VIDEO_DRIVER_MIR)
#include <mir_toolkit/mir_client_library.h>
#if defined(SDL_VIDEO_DRIVER_ANDROID)
typedef struct ANativeWindow ANativeWindow;
typedef void *EGLSurface;
#endif

#if defined(SDL_VIDEO_DRIVER_VIVANTE)
#include "SDL_egl.h"
#endif

/**
* These are the various supported windowing subsystems
Expand All @@ -117,6 +124,8 @@ typedef enum
SDL_SYSWM_WAYLAND,
SDL_SYSWM_MIR,
SDL_SYSWM_WINRT,
SDL_SYSWM_ANDROID,
SDL_SYSWM_VIVANTE
} SDL_SYSWM_TYPE;

/**
Expand Down Expand Up @@ -149,14 +158,26 @@ struct SDL_SysWMmsg
#if defined(SDL_VIDEO_DRIVER_COCOA)
struct
{
/* Latest version of Xcode clang complains about empty structs in C v. C++:
error: empty struct has size 0 in C, size 1 in C++
*/
int dummy;
/* No Cocoa window events yet */
} cocoa;
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
struct
{
int dummy;
/* No UIKit window events yet */
} uikit;
#endif
#if defined(SDL_VIDEO_DRIVER_VIVANTE)
struct
{
int dummy;
/* No Vivante window events yet */
} vivante;
#endif
/* Can't have an empty union */
int dummy;
Expand All @@ -179,6 +200,7 @@ struct SDL_SysWMinfo
struct
{
HWND window; /**< The window handle */
HDC hdc; /**< The window device context */
} win;
#endif
#if defined(SDL_VIDEO_DRIVER_WINRT)
Expand All @@ -205,13 +227,24 @@ struct SDL_SysWMinfo
#if defined(SDL_VIDEO_DRIVER_COCOA)
struct
{
NSWindow *window; /* The Cocoa window */
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
NSWindow __unsafe_unretained *window; /* The Cocoa window */
#else
NSWindow *window; /* The Cocoa window */
#endif
} cocoa;
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
struct
{
UIWindow *window; /* The UIKit window */
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
UIWindow __unsafe_unretained *window; /* The UIKit window */
#else
UIWindow *window; /* The UIKit window */
#endif
GLuint framebuffer; /* The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
GLuint colorbuffer; /* The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
GLuint resolveFramebuffer; /* The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
} uikit;
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
Expand All @@ -225,11 +258,27 @@ struct SDL_SysWMinfo
#if defined(SDL_VIDEO_DRIVER_MIR)
struct
{
MirConnection *connection; /**< Mir display server connection */
MirSurface *surface; /**< Mir surface */
struct MirConnection *connection; /**< Mir display server connection */
struct MirSurface *surface; /**< Mir surface */
} mir;
#endif

#if defined(SDL_VIDEO_DRIVER_ANDROID)
struct
{
ANativeWindow *window;
EGLSurface surface;
} android;
#endif

#if defined(SDL_VIDEO_DRIVER_VIVANTE)
struct
{
EGLNativeDisplayType display;
EGLNativeWindowType window;
} vivante;
#endif

/* Can't have an empty union */
int dummy;
} info;
Expand Down
4 changes: 2 additions & 2 deletions other/sdl/include/SDL_test.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -52,7 +52,7 @@ extern "C" {
/* Global definitions */

/*
* Note: Maximum size of SDLTest log message is less than SDLs limit
* Note: Maximum size of SDLTest log message is less than SDL's limit
* to ensure we can fit additional information such as the timestamp.
*/
#define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584
Expand Down
10 changes: 5 additions & 5 deletions other/sdl/include/SDL_test_assert.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -58,7 +58,7 @@ extern "C" {
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);
void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);

/**
* \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
Expand All @@ -68,14 +68,14 @@ void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);
*
* \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
*/
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...);
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);

/**
* \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
* \brief Explicitly pass without checking an assertion condition. Updates assertion counter.
*
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_AssertPass(const char *assertDescription, ...);
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);

/**
* \brief Resets the assert summary counters to zero.
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_test_common.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
6 changes: 3 additions & 3 deletions other/sdl/include/SDL_test_compare.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -51,9 +51,9 @@ extern "C" {
*
* \param surface Surface used in comparison
* \param referenceSurface Test Surface used in comparison
* \param allowable_error Allowable difference (squared) in blending accuracy.
* \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy.
*
* \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
* \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
*/
int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);

Expand Down
26 changes: 13 additions & 13 deletions other/sdl/include/SDL_test_crc32.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -70,27 +70,27 @@ extern "C" {
/* ---------- Function Prototypes ------------- */

/**
* /brief Initialize the CRC context
* \brief Initialize the CRC context
*
* Note: The function initializes the crc table required for all crc calculations.
*
* /param crcContext pointer to context variable
* \param crcContext pointer to context variable
*
* /returns 0 for OK, -1 on error
* \returns 0 for OK, -1 on error
*
*/
int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);


/**
* /brief calculate a crc32 from a data block
* \brief calculate a crc32 from a data block
*
* /param crcContext pointer to context variable
* /param inBuf input buffer to checksum
* /param inLen length of input buffer
* /param crc32 pointer to Uint32 to store the final CRC into
* \param crcContext pointer to context variable
* \param inBuf input buffer to checksum
* \param inLen length of input buffer
* \param crc32 pointer to Uint32 to store the final CRC into
*
* /returns 0 for OK, -1 on error
* \returns 0 for OK, -1 on error
*
*/
int SDLTest_crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
Expand All @@ -102,11 +102,11 @@ int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf,


/**
* /brief clean up CRC context
* \brief clean up CRC context
*
* /param crcContext pointer to context variable
* \param crcContext pointer to context variable
*
* /returns 0 for OK, -1 on error
* \returns 0 for OK, -1 on error
*
*/

Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_test_font.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
6 changes: 3 additions & 3 deletions other/sdl/include/SDL_test_fuzzer.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -57,7 +57,7 @@ extern "C" {
/**
* Initializes the fuzzer for a test
*
* /param execKey Execution "Key" that initializes the random number generator uniquely for the test.
* \param execKey Execution "Key" that initializes the random number generator uniquely for the test.
*
*/
void SDLTest_FuzzerInit(Uint64 execKey);
Expand Down Expand Up @@ -318,7 +318,7 @@ Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL
/**
* Returns integer in range [min, max] (inclusive).
* Min and max values can be negative values.
* If Max in smaller tham min, then the values are swapped.
* If Max in smaller than min, then the values are swapped.
* Min and max are the same value, that value will be returned.
*
* \param min Minimum inclusive value of returned random number
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_test_harness.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_test_images.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
6 changes: 3 additions & 3 deletions other/sdl/include/SDL_test_log.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -47,14 +47,14 @@ extern "C" {
*
* \param fmt Message to be logged
*/
void SDLTest_Log(const char *fmt, ...);
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);

/**
* \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
*
* \param fmt Message to be logged
*/
void SDLTest_LogError(const char *fmt, ...);
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
20 changes: 10 additions & 10 deletions other/sdl/include/SDL_test_md5.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -78,9 +78,9 @@ extern "C" {
/* ---------- Function Prototypes ------------- */

/**
* /brief initialize the context
* \brief initialize the context
*
* /param mdContext pointer to context variable
* \param mdContext pointer to context variable
*
* Note: The function initializes the message-digest context
* mdContext. Call before each new use of the context -
Expand All @@ -90,11 +90,11 @@ extern "C" {


/**
* /brief update digest from variable length data
* \brief update digest from variable length data
*
* /param mdContext pointer to context variable
* /param inBuf pointer to data array/string
* /param inLen length of data array/string
* \param mdContext pointer to context variable
* \param inBuf pointer to data array/string
* \param inLen length of data array/string
*
* Note: The function updates the message-digest context to account
* for the presence of each of the characters inBuf[0..inLen-1]
Expand All @@ -105,10 +105,10 @@ extern "C" {
unsigned int inLen);


/*
* /brief complete digest computation
/**
* \brief complete digest computation
*
* /param mdContext pointer to context variable
* \param mdContext pointer to context variable
*
* Note: The function terminates the message-digest computation and
* ends with the desired message digest in mdContext.digest[0..15].
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_test_random.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
6 changes: 3 additions & 3 deletions other/sdl/include/SDL_thread.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -233,9 +233,9 @@ extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
* if (!thread_local_storage) {
* thread_local_storage = SDL_TLSCreate();
* }
* SDL_AtomicUnLock(&tls_lock);
* SDL_AtomicUnlock(&tls_lock);
* }
* SDL_TLSSet(thread_local_storage, value);
* SDL_TLSSet(thread_local_storage, value, 0);
* }
*
* void *GetMyThreadData(void)
Expand Down
4 changes: 2 additions & 2 deletions other/sdl/include/SDL_timer.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -88,7 +88,7 @@ typedef int SDL_TimerID;
/**
* \brief Add a new timer to the pool of timers already running.
*
* \return A timer ID, or NULL when an error occurs.
* \return A timer ID, or 0 when an error occurs.
*/
extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
SDL_TimerCallback callback,
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_touch.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/SDL_types.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
4 changes: 2 additions & 2 deletions other/sdl/include/SDL_version.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -59,7 +59,7 @@ typedef struct SDL_version
*/
#define SDL_MAJOR_VERSION 2
#define SDL_MINOR_VERSION 0
#define SDL_PATCHLEVEL 3
#define SDL_PATCHLEVEL 5

/**
* \brief Macro to determine SDL version program was compiled against.
Expand Down
299 changes: 269 additions & 30 deletions other/sdl/include/SDL_video.h

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions other/sdl/include/begin_code.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -41,6 +41,14 @@
# endif
#endif

#ifndef SDL_UNUSED
# ifdef __GNUC__
# define SDL_UNUSED __attribute__((unused))
# else
# define SDL_UNUSED
# endif
#endif

/* Some compilers use a special export keyword */
#ifndef DECLSPEC
# if defined(__WIN32__) || defined(__WINRT__)
Expand All @@ -56,8 +64,6 @@
# else
# if defined(__GNUC__) && __GNUC__ >= 4
# define DECLSPEC __attribute__ ((visibility("default")))
# elif defined(__GNUC__) && __GNUC__ >= 2
# define DECLSPEC __declspec(dllexport)
# else
# define DECLSPEC
# endif
Expand Down
2 changes: 1 addition & 1 deletion other/sdl/include/close_code.h
@@ -1,6 +1,6 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
Binary file modified other/sdl/lib32/SDL2.dll
Binary file not shown.
Binary file modified other/sdl/lib32/SDL2.lib
Binary file not shown.
Binary file modified other/sdl/lib32/SDL2main.lib
Binary file not shown.
Binary file modified other/sdl/lib32/SDL2test.lib
Binary file not shown.
Binary file modified other/sdl/lib64/SDL2.dll
Binary file not shown.
Binary file modified other/sdl/lib64/SDL2.lib
Binary file not shown.
Binary file modified other/sdl/lib64/SDL2main.lib
Binary file not shown.
Binary file modified other/sdl/lib64/SDL2test.lib
Binary file not shown.
4 changes: 1 addition & 3 deletions other/sdl/sdlnotes.txt
@@ -1,3 +1 @@
NOTE. This is a really stripped down version of SDL only used
to compile teeworlds for windows. For a complete release of
SDL, please visit their site at http://www.libsdl.org.
SDL 2.0.5
Binary file removed other/sdl/windows/lib32/SDL2.dll
Binary file not shown.
Binary file removed other/sdl/windows/lib32/SDL2.lib
Binary file not shown.
Binary file removed other/sdl/windows/lib32/SDL2main.lib
Binary file not shown.
Binary file removed other/sdl/windows/lib32/SDL2test.lib
Binary file not shown.
Binary file removed other/sdl/windows/lib64/SDL2.dll
Binary file not shown.
Binary file removed other/sdl/windows/lib64/SDL2.lib
Binary file not shown.
Binary file removed other/sdl/windows/lib64/SDL2main.lib
Binary file not shown.
Binary file removed other/sdl/windows/lib64/SDL2test.lib
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts/make_release.py
Expand Up @@ -93,6 +93,7 @@ def copydir(src, dst, excl=[]):
shutil.copy("config_store"+exe_ext, package_dir)
shutil.copy("config_retrieve"+exe_ext, package_dir)
shutil.copy("map_extract"+exe_ext, package_dir)
shutil.copy("map_diff"+exe_ext, package_dir)
#shutil.copy(name+"-Server_sql"+exe_ext, package_dir)

if include_src:
Expand All @@ -103,7 +104,7 @@ def copydir(src, dst, excl=[]):
shutil.copy("configure.lua", package_dir)

if use_bundle:
bins = [name, name+'-Server', 'dilate', 'config_store', 'config_retrieve', 'map_extract', 'serverlaunch']
bins = [name, name+'-Server', 'dilate', 'config_store', 'config_retrieve', 'map_extract', 'map_diff', 'serverlaunch']
platforms = ('x86', 'x86_64', 'ppc')
for bin in bins:
to_lipo = []
Expand All @@ -130,7 +131,6 @@ def copydir(src, dst, excl=[]):


shutil.copy("other/icons/DDNet.icns", clientbundle_resource_dir)
#shutil.copy("other/icons/Teeworlds.icns", clientbundle_resource_dir)
shutil.copy(name+exe_ext, clientbundle_bin_dir)
os.system("install_name_tool -change /opt/X11/lib/libfreetype.6.dylib @executable_path/../Frameworks/libfreetype.6.dylib " + binary_path)
os.system("install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 @executable_path/../Frameworks/SDL2.framework/SDL2 " + binary_path)
Expand Down
12 changes: 9 additions & 3 deletions src/base/system.c
Expand Up @@ -2241,12 +2241,18 @@ void str_timestamp(char *buffer, int buffer_size)

void str_escape(char **dst, const char *src, const char *end)
{
while(*src && *dst < end)
while(*src && *dst + 1 < end)
{
if(*src == '"' || *src == '\\') // escape \ and "
*(*dst)++ = '\\';
{
if(*dst + 2 < end)
*(*dst)++ = '\\';
else
break;
}
*(*dst)++ = *src++;
}
**dst = 0;
}

int mem_comp(const void *a, const void *b, int size)
Expand Down Expand Up @@ -2552,7 +2558,7 @@ void shell_execute(const char *file)
#endif
}

int os_compare_version(int major, int minor)
int os_compare_version(unsigned int major, unsigned int minor)
{
#if defined(CONF_FAMILY_WINDOWS)
OSVERSIONINFO ver;
Expand Down
5 changes: 3 additions & 2 deletions src/base/system.h
Expand Up @@ -1063,7 +1063,8 @@ void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *fo
Escapes \ and " characters in a string.
Parameters:
dst - Destination array pointer, gets increased
dst - Destination array pointer, gets increased, will point to
the terminating null.
src - Source array
end - End of destination array
*/
Expand Down Expand Up @@ -1424,7 +1425,7 @@ void shell_execute(const char *file);
0 - OS version same.
-1 - OS version lower.
*/
int os_compare_version(int major, int minor);
int os_compare_version(unsigned int major, unsigned int minor);

/*
Function: generate_password
Expand Down
1 change: 1 addition & 0 deletions src/base/tl/range.h
Expand Up @@ -185,6 +185,7 @@ class plain_range_sorted : public plain_range<T>
{}

plain_range_sorted(const plain_range_sorted &r)
: parent()
{
*this = r;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/client.h
Expand Up @@ -87,7 +87,7 @@ class IClient : public IInterface
inline float LocalTime() const { return m_LocalTime; }

// actions
virtual void Connect(const char *pAddress) = 0;
virtual void Connect(const char *pAddress, const char *pPassword = NULL) = 0;
virtual void Disconnect() = 0;

// dummy
Expand Down
32 changes: 24 additions & 8 deletions src/engine/client/backend_sdl.cpp
Expand Up @@ -594,16 +594,37 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
*pDesktopHeight = DisplayMode.h;

// use desktop resolution as default resolution
#ifndef __ANDROID__
#ifdef __ANDROID__
*pWidth = *pDesktopWidth;
*pHeight = *pDesktopHeight;
/*
#elif defined(CONF_FAMILY_WINDOWS)
if(*pWidth == 0 || *pHeight == 0)
#endif
{
*pWidth = *pDesktopWidth;
*pHeight = *pDesktopHeight;
}
else
{
float dpi = -1;
SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
if(dpi > 0)
{
*pWidth = *pWidth * 96 / dpi;
*pHeight = *pHeight * 96 / dpi;
}
}
*/
#else
if(*pWidth == 0 || *pHeight == 0)
{
*pWidth = *pDesktopWidth;
*pHeight = *pDesktopHeight;
}
#endif

// set flags
int SdlFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
int SdlFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI;
#if defined(SDL_VIDEO_DRIVER_X11)
if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE)
SdlFlags |= SDL_WINDOW_RESIZABLE;
Expand All @@ -621,11 +642,6 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
#endif
}

if(Flags&IGraphicsBackend::INITFLAG_HIGHDPI)
SdlFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
else
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");

// set gl attributes
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if(FsaaSamples)
Expand Down
50 changes: 33 additions & 17 deletions src/engine/client/client.cpp
Expand Up @@ -299,6 +299,7 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta)
m_RconAuthed[0] = 0;
m_RconAuthed[1] = 0;
m_RconPassword[0] = '\0';
m_Password[0] = '\0';

// version-checking
m_aVersionStr[0] = '0';
Expand All @@ -307,11 +308,8 @@ CClient::CClient() : m_DemoPlayer(&m_SnapshotDelta)
// pinging
m_PingStartTime = 0;

//
m_aCurrentMap[0] = 0;
m_CurrentMapCrc = 0;

//
m_aCmdConnect[0] = 0;

// map download
Expand Down Expand Up @@ -374,7 +372,9 @@ int CClient::SendMsgEx(CMsgPacker *pMsg, int Flags, bool System)

// HACK: modify the message id in the packet and store the system flag
if(*((unsigned char*)Packet.m_pData) == 1 && System && Packet.m_DataSize == 1)
{
dbg_break();
}

*((unsigned char*)Packet.m_pData) <<= 1;
if(System)
Expand Down Expand Up @@ -404,7 +404,7 @@ void CClient::SendInfo()
{
CMsgPacker Msg(NETMSG_INFO);
Msg.AddString(GameClient()->NetVersion(), 128);
Msg.AddString(g_Config.m_Password, 128);
Msg.AddString(m_Password, 128);
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH);
}

Expand Down Expand Up @@ -516,7 +516,11 @@ void CClient::SendInput()
m_CurrentInput[i] %= 200;

SendMsgExY(&Msg, MSGFLAG_FLUSH, true, i);
Force = true;
// ugly workaround for dummy. we need to send input with dummy to prevent
// prediction time resets. but if we do it too often, then it's
// impossible to use grenade with frozen dummy that gets hammered...
if(g_Config.m_ClDummyCopyMoves || m_CurrentInput[i] % 2)
Force = true;
}
}
}
Expand Down Expand Up @@ -665,7 +669,7 @@ void CClient::GenerateTimeoutCodes()
}
}

void CClient::Connect(const char *pAddress)
void CClient::Connect(const char *pAddress, const char *pPassword)
{
char aBuf[512];
int Port = 8303;
Expand All @@ -686,6 +690,11 @@ void CClient::Connect(const char *pAddress)
net_host_lookup("localhost", &m_ServerAddress, m_NetClient[0].NetType());
}

if(!pPassword)
m_Password[0] = 0;
else
str_copy(m_Password, pPassword, sizeof(m_Password));

m_RconAuthed[0] = 0;
if(m_ServerAddress.port == 0)
m_ServerAddress.port = Port;
Expand Down Expand Up @@ -808,7 +817,9 @@ int CClient::SendMsgExY(CMsgPacker *pMsg, int Flags, bool System, int NetClient)

// HACK: modify the message id in the packet and store the system flag
if(*((unsigned char*)Packet.m_pData) == 1 && System && Packet.m_DataSize == 1)
{
dbg_break();
}

*((unsigned char*)Packet.m_pData) <<= 1;
if(System)
Expand Down Expand Up @@ -1070,7 +1081,6 @@ const char *CClient::LoadMap(const char *pName, const char *pFilename, unsigned

str_copy(m_aCurrentMap, pName, sizeof(m_aCurrentMap));
str_copy(m_aCurrentMapPath, pFilename, sizeof(m_aCurrentMapPath));
m_CurrentMapCrc = m_pMap->Crc();

return 0x0;
}
Expand Down Expand Up @@ -1175,13 +1185,13 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_NEWS) + NEWS_SIZE) &&
mem_comp(pPacket->m_pData, VERSIONSRV_NEWS, sizeof(VERSIONSRV_NEWS)) == 0)
{
if (mem_comp(m_aNews, (char*)pPacket->m_pData + sizeof(VERSIONSRV_NEWS), NEWS_SIZE))
if(mem_comp(m_aNews, (char*)pPacket->m_pData + sizeof(VERSIONSRV_NEWS), NEWS_SIZE))
g_Config.m_UiPage = CMenus::PAGE_NEWS;

mem_copy(m_aNews, (char*)pPacket->m_pData + sizeof(VERSIONSRV_NEWS), NEWS_SIZE);

IOHANDLE NewsFile = m_pStorage->OpenFile("ddnet-news.txt", IOFLAG_WRITE, IStorage::TYPE_SAVE);
if (NewsFile)
if(NewsFile)
{
io_write(NewsFile, m_aNews, sizeof(m_aNews));
io_close(NewsFile);
Expand All @@ -1206,13 +1216,13 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
const char *pComp = (char*)pPacket->m_pData+sizeof(VERSIONSRV_DDNETLIST)+8;

// do decompression of serverlist
if (uncompress((Bytef*)aBuf, &DstLen, (Bytef*)pComp, CompLength) == Z_OK && (int)DstLen == PlainLength)
if(uncompress((Bytef*)aBuf, &DstLen, (Bytef*)pComp, CompLength) == Z_OK && (int)DstLen == PlainLength)
{
aBuf[DstLen] = '\0';
bool ListChanged = true;

IOHANDLE File = m_pStorage->OpenFile("ddnet-servers.json", IOFLAG_READ, IStorage::TYPE_SAVE);
if (File)
if(File)
{
char aBuf2[16384];
io_read(File, aBuf2, sizeof(aBuf2));
Expand All @@ -1222,10 +1232,10 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
}

// decompression successful, write plain file
if (ListChanged)
if(ListChanged)
{
IOHANDLE File = m_pStorage->OpenFile("ddnet-servers.json", IOFLAG_WRITE, IStorage::TYPE_SAVE);
if (File)
if(File)
{
io_write(File, aBuf, PlainLength);
io_close(File);
Expand Down Expand Up @@ -1649,7 +1659,10 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
if(Last)
{
if(m_MapdownloadFile)
{
io_close(m_MapdownloadFile);
m_MapdownloadFile = 0;
}
FinishMapDownload();
}
else
Expand Down Expand Up @@ -2218,7 +2231,10 @@ void CClient::FinishMapDownload()
else
{
if(m_MapdownloadFile)
{
io_close(m_MapdownloadFile);
m_MapdownloadFile = 0;
}
ResetMapDownload();
DisconnectWithReason(pError);
}
Expand Down Expand Up @@ -2785,7 +2801,7 @@ void CClient::Run()
// send client info
CMsgPacker MsgInfo(NETMSG_INFO);
MsgInfo.AddString(GameClient()->NetVersion(), 128);
MsgInfo.AddString(g_Config.m_Password, 128);
MsgInfo.AddString(m_Password, 128);
SendMsgExY(&MsgInfo, MSGFLAG_VITAL|MSGFLAG_FLUSH, true, 1);

// update netclient
Expand Down Expand Up @@ -3248,7 +3264,7 @@ void CClient::DemoRecorder_Start(const char *pFilename, bool WithTimestamp, int
}
else
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pFilename);
m_DemoRecorder[Recorder].Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client");
m_DemoRecorder[Recorder].Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_pMap->Crc(), "client", m_pMap->MapSize(), 0, m_pMap->File());
}
}

Expand Down Expand Up @@ -3642,7 +3658,7 @@ const char* CClient::GetCurrentMap()

int CClient::GetCurrentMapCrc()
{
return m_CurrentMapCrc;
return m_pMap->Crc();
}

const char* CClient::GetCurrentMapPath()
Expand All @@ -3658,7 +3674,7 @@ const char* CClient::RaceRecordStart(const char *pFilename)
if(State() != STATE_ONLINE)
dbg_msg("demorec/record", "client is not online");
else
m_DemoRecorder[RECORDER_RACE].Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client");
m_DemoRecorder[RECORDER_RACE].Start(Storage(), m_pConsole, aFilename, GameClient()->NetVersion(), m_aCurrentMap, m_pMap->Crc(), "client", m_pMap->MapSize(), 0, m_pMap->File());

return m_aCurrentMap;
}
Expand Down
5 changes: 2 additions & 3 deletions src/engine/client/client.h
Expand Up @@ -108,17 +108,16 @@ class CClient : public IClient, public CDemoPlayer::IListener
int m_RconAuthed[2];
char m_RconPassword[32];
int m_UseTempRconCommands;
char m_Password[32];

// version-checking
char m_aVersionStr[10];

// pinging
int64 m_PingStartTime;

//
char m_aCurrentMap[256];
char m_aCurrentMapPath[CEditor::MAX_PATH_LENGTH];
unsigned m_CurrentMapCrc;

char m_aTimeoutCodes[2][32];
bool m_aTimeoutCodeSent[2];
Expand Down Expand Up @@ -254,7 +253,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
void OnEnterGame();
virtual void EnterGame();

virtual void Connect(const char *pAddress);
virtual void Connect(const char *pAddress, const char *pPassword = NULL);
void DisconnectWithReason(const char *pReason);
virtual void Disconnect();

Expand Down
13 changes: 5 additions & 8 deletions src/engine/client/friends.cpp
Expand Up @@ -167,16 +167,13 @@ void CFriends::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
{
str_copy(aBuf, pSelf->m_Foes ? "add_foe " : "add_friend ", sizeof(aBuf));

char *pDst = aBuf+str_length(aBuf);
*pDst++ = '"';
str_append(aBuf, "\"", sizeof(aBuf));
char *pDst = aBuf + str_length(aBuf);
str_escape(&pDst, pSelf->m_aFriends[i].m_aName, pEnd);
*pDst++ = '"';
*pDst++ = ' ';

*pDst++ = '"';
str_append(aBuf, "\" \"", sizeof(aBuf));
pDst = aBuf + str_length(aBuf);
str_escape(&pDst, pSelf->m_aFriends[i].m_aClan, pEnd);
*pDst++ = '"';
*pDst++ = 0;
str_append(aBuf, "\"", sizeof(aBuf));

pConfig->WriteLine(aBuf);
}
Expand Down
1 change: 0 additions & 1 deletion src/engine/client/graphics_threaded.cpp
Expand Up @@ -789,7 +789,6 @@ int CGraphics_Threaded::IssueInit()
if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN;
if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC;
if(g_Config.m_GfxResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
if(g_Config.m_GfxHighdpi) Flags |= IGraphicsBackend::INITFLAG_HIGHDPI;

return m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight);
}
Expand Down
1 change: 0 additions & 1 deletion src/engine/client/graphics_threaded.h
Expand Up @@ -318,7 +318,6 @@ class IGraphicsBackend
INITFLAG_VSYNC = 2,
INITFLAG_RESIZABLE = 4,
INITFLAG_BORDERLESS = 8,
INITFLAG_HIGHDPI = 16,
};

virtual ~IGraphicsBackend() {}
Expand Down
32 changes: 18 additions & 14 deletions src/engine/client/input.cpp
Expand Up @@ -49,7 +49,7 @@ CInput::CInput()
m_VideoRestartNeeded = 0;
m_pClipboardText = NULL;

m_IsEditingText = false;
m_CountEditingText = 0;
}

void CInput::Init()
Expand Down Expand Up @@ -143,18 +143,25 @@ void CInput::NextFrame()

bool CInput::GetIMEState()
{
return m_IsEditingText;
return m_CountEditingText > 0;
}

void CInput::SetIMEState(bool activate)
void CInput::SetIMEState(bool Activate)
{
if (activate)
SDL_StartTextInput();
if(Activate)
{
if(m_CountEditingText == 0)
SDL_StartTextInput();
else
m_CountEditingText++;
}
else
{
// force stop editing
SDL_StopTextInput();
m_IsEditingText = false;
if(m_CountEditingText == 0)
return;
m_CountEditingText--;
if(m_CountEditingText == 0)
SDL_StopTextInput();
}
}

Expand Down Expand Up @@ -196,20 +203,17 @@ int CInput::Update()
int Key = -1;
int Scancode = 0;
int Action = IInput::FLAG_PRESS;
switch (Event.type)
switch(Event.type)
{
case SDL_TEXTEDITING:
{
if (str_length(Event.edit.text))
if(str_length(Event.edit.text))
{
str_format(m_pEditingText, sizeof(m_pEditingText), Event.edit.text);
m_EditingCursor = 0;
for (int i = 0; i < Event.edit.start; i++)
m_EditingCursor = str_utf8_forward(m_pEditingText, m_EditingCursor);
m_IsEditingText = true;
}
else
m_IsEditingText = false;
break;
}
case SDL_TEXTINPUT:
Expand Down Expand Up @@ -318,7 +322,7 @@ int CInput::Update()
return 1;
}

if(Key >= 0 && Key < g_MaxKeys && !IgnoreKeys && !m_IsEditingText)
if(Key >= 0 && Key < g_MaxKeys && !IgnoreKeys && m_CountEditingText == 0)
{
if(Action&IInput::FLAG_PRESS)
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/client/input.h
Expand Up @@ -26,7 +26,7 @@ class CInput : public IEngineInput
int m_InputCounter;

//ime support
bool m_IsEditingText;
int m_CountEditingText;
char m_pEditingText[32];
int m_EditingCursor;

Expand Down Expand Up @@ -55,7 +55,7 @@ class CInput : public IEngineInput
virtual int VideoRestartNeeded();

virtual bool GetIMEState();
virtual void SetIMEState(bool activate);
virtual void SetIMEState(bool Activate);
virtual const char* GetIMECandidate();
virtual int GetEditingCursor();
};
Expand Down
107 changes: 53 additions & 54 deletions src/engine/client/serverbrowser.cpp
Expand Up @@ -921,81 +921,80 @@ void CServerBrowser::LoadDDNet()
IStorage *pStorage = Kernel()->RequestInterface<IStorage>();
IOHANDLE File = pStorage->OpenFile("ddnet-servers.json", IOFLAG_READ, IStorage::TYPE_ALL);

if(File)
{
char aBuf[4096*4];
mem_zero(aBuf, sizeof(aBuf));
if(!File)
return;

io_read(File, aBuf, sizeof(aBuf));
io_close(File);
char aBuf[4096*4];
mem_zero(aBuf, sizeof(aBuf));

io_read(File, aBuf, sizeof(aBuf));
io_close(File);

// parse JSON
json_value *pCountries = json_parse(aBuf);
// parse JSON
json_value *pCountries = json_parse(aBuf);

if (pCountries && pCountries->type == json_array)
if (pCountries && pCountries->type == json_array)
{
for (int i = 0; i < json_array_length(pCountries) && m_NumDDNetCountries < MAX_DDNET_COUNTRIES; i++)
{
for (int i = 0; i < json_array_length(pCountries) && m_NumDDNetCountries < MAX_DDNET_COUNTRIES; i++)
// pSrv - { name, flagId, servers }
const json_value *pSrv = json_array_get(pCountries, i);
const json_value *pTypes = json_object_get(pSrv, "servers");
const json_value *pName = json_object_get(pSrv, "name");
const json_value *pFlagID = json_object_get(pSrv, "flagId");

if (pSrv->type != json_object || pTypes->type != json_object || pName->type != json_string || pFlagID->type != json_integer)
{
// pSrv - { name, flagId, servers }
const json_value *pSrv = json_array_get(pCountries, i);
const json_value *pTypes = json_object_get(pSrv, "servers");
const json_value *pName = json_object_get(pSrv, "name");
const json_value *pFlagID = json_object_get(pSrv, "flagId");
dbg_msg("client_srvbrowse", "invalid attributes");
continue;
}

if (pSrv->type != json_object || pTypes->type != json_object || pName->type != json_string || pFlagID->type != json_integer)
{
dbg_msg("client_srvbrowse", "invalid attributes");
continue;
}
// build structure
CDDNetCountry *pCntr = &m_aDDNetCountries[m_NumDDNetCountries];

// build structure
CDDNetCountry *pCntr = &m_aDDNetCountries[m_NumDDNetCountries];
pCntr->Reset();

pCntr->Reset();
str_copy(pCntr->m_aName, json_string_get(pName), sizeof(pCntr->m_aName));
pCntr->m_FlagID = json_int_get(pFlagID);

str_copy(pCntr->m_aName, json_string_get(pName), sizeof(pCntr->m_aName));
pCntr->m_FlagID = json_int_get(pFlagID);
// add country
for (unsigned int t = 0; t < pTypes->u.object.length; t++)
{
const char *pType = pTypes->u.object.values[t].name;
const json_value *pAddrs = pTypes->u.object.values[t].value;

// add country
for (unsigned int t = 0; t < pTypes->u.object.length; t++)
// add type
if(json_array_length(pAddrs) > 0 && m_NumDDNetTypes < MAX_DDNET_TYPES)
{
const char *pType = pTypes->u.object.values[t].name;
const json_value *pAddrs = pTypes->u.object.values[t].value;

// add type
if(json_array_length(pAddrs) > 0 && m_NumDDNetTypes < MAX_DDNET_TYPES)
int Pos;
for(Pos = 0; Pos < m_NumDDNetTypes; Pos++)
{
int Pos;
for(Pos = 0; Pos < m_NumDDNetTypes; Pos++)
{
if(!str_comp(m_aDDNetTypes[Pos], pType))
break;
}
if(Pos == m_NumDDNetTypes)
{
str_copy(m_aDDNetTypes[m_NumDDNetTypes], pType, sizeof(m_aDDNetTypes[m_NumDDNetTypes]));
m_NumDDNetTypes++;
}
if(!str_comp(m_aDDNetTypes[Pos], pType))
break;
}

// add addresses
for (int g = 0; g < json_array_length(pAddrs); g++, pCntr->m_NumServers++)
if(Pos == m_NumDDNetTypes)
{
const json_value *pAddr = json_array_get(pAddrs, g);
const char *pStr = json_string_get(pAddr);
net_addr_from_str(&pCntr->m_aServers[pCntr->m_NumServers], pStr);
str_copy(pCntr->m_aTypes[pCntr->m_NumServers], pType, sizeof(pCntr->m_aTypes[pCntr->m_NumServers]));
str_copy(m_aDDNetTypes[m_NumDDNetTypes], pType, sizeof(m_aDDNetTypes[m_NumDDNetTypes]));
m_NumDDNetTypes++;
}
}

m_NumDDNetCountries++;
// add addresses
for (int g = 0; g < json_array_length(pAddrs); g++, pCntr->m_NumServers++)
{
const json_value *pAddr = json_array_get(pAddrs, g);
const char *pStr = json_string_get(pAddr);
net_addr_from_str(&pCntr->m_aServers[pCntr->m_NumServers], pStr);
str_copy(pCntr->m_aTypes[pCntr->m_NumServers], pType, sizeof(pCntr->m_aTypes[pCntr->m_NumServers]));
}
}
}

if (pCountries)
json_value_free(pCountries);
m_NumDDNetCountries++;
}
}

if (pCountries)
json_value_free(pCountries);
}

bool CServerBrowser::IsRefreshing() const
Expand Down
20 changes: 7 additions & 13 deletions src/engine/client/sound.cpp
Expand Up @@ -216,7 +216,7 @@ static void Mix(short *pFinalOut, unsigned Frames)

{
Lvol *= FalloffX;
Rvol *= FalloffY;
Rvol *= FalloffX;
}
}
else
Expand Down Expand Up @@ -552,19 +552,16 @@ int CSound::LoadOpus(const char *pFilename)
}

int SampleID = AllocID();
if(SampleID < 0)
return -1;

// read the whole file into memory
int DataSize = io_length(ms_File);

if(DataSize <= 0)
if(SampleID < 0 || DataSize <= 0)
{
io_close(ms_File);
ms_File = NULL;
dbg_msg("sound/opus", "failed to open file. filename='%s'", pFilename);
return -1;
}

// read the whole file into memory
char *pData = new char[DataSize];
io_read(ms_File, pData, DataSize);

Expand Down Expand Up @@ -605,19 +602,16 @@ int CSound::LoadWV(const char *pFilename)
}

int SampleID = AllocID();
if(SampleID < 0)
return -1;

// read the whole file into memory
int DataSize = io_length(ms_File);

if(DataSize <= 0)
if(SampleID < 0 || DataSize <= 0)
{
io_close(ms_File);
ms_File = NULL;
dbg_msg("sound/wv", "failed to open file. filename='%s'", pFilename);
return -1;
}

// read the whole file into memory
char *pData = new char[DataSize];
io_read(ms_File, pData, DataSize);

Expand Down
58 changes: 29 additions & 29 deletions src/engine/client/updater.cpp
Expand Up @@ -26,7 +26,7 @@ void CUpdater::Init()
m_pStorage = Kernel()->RequestInterface<IStorage>();
m_pFetcher = Kernel()->RequestInterface<IFetcher>();
#if defined(CONF_FAMILY_WINDOWS)
m_IsWinXP = os_compare_version(5, 1) <= 0;
m_IsWinXP = os_compare_version(5U, 1U) <= 0;
#else
m_IsWinXP = false;
#endif
Expand Down Expand Up @@ -157,41 +157,41 @@ void CUpdater::ParseUpdate()
{
char aPath[512];
IOHANDLE File = m_pStorage->OpenFile(m_pStorage->GetBinaryPath("update/update.json", aPath, sizeof aPath), IOFLAG_READ, IStorage::TYPE_ALL);
if(File)
{
char aBuf[4096*4];
mem_zero(aBuf, sizeof (aBuf));
io_read(File, aBuf, sizeof(aBuf));
io_close(File);
if(!File)
return;

char aBuf[4096*4];
mem_zero(aBuf, sizeof (aBuf));
io_read(File, aBuf, sizeof(aBuf));
io_close(File);

json_value *pVersions = json_parse(aBuf);
json_value *pVersions = json_parse(aBuf);

if(pVersions && pVersions->type == json_array)
if(pVersions && pVersions->type == json_array)
{
for(int i = 0; i < json_array_length(pVersions); i++)
{
for(int i = 0; i < json_array_length(pVersions); i++)
const json_value *pTemp;
const json_value *pCurrent = json_array_get(pVersions, i);
if(str_comp(json_string_get(json_object_get(pCurrent, "version")), GAME_RELEASE_VERSION))
{
const json_value *pTemp;
const json_value *pCurrent = json_array_get(pVersions, i);
if(str_comp(json_string_get(json_object_get(pCurrent, "version")), GAME_RELEASE_VERSION))
if(json_boolean_get(json_object_get(pCurrent, "client")))
m_ClientUpdate = true;
if(json_boolean_get(json_object_get(pCurrent, "server")))
m_ServerUpdate = true;
if((pTemp = json_object_get(pCurrent, "download"))->type == json_array)
{
if(json_boolean_get(json_object_get(pCurrent, "client")))
m_ClientUpdate = true;
if(json_boolean_get(json_object_get(pCurrent, "server")))
m_ServerUpdate = true;
if((pTemp = json_object_get(pCurrent, "download"))->type == json_array)
{
for(int j = 0; j < json_array_length(pTemp); j++)
AddFileJob(json_string_get(json_array_get(pTemp, j)), true);
}
if((pTemp = json_object_get(pCurrent, "remove"))->type == json_array)
{
for(int j = 0; j < json_array_length(pTemp); j++)
AddFileJob(json_string_get(json_array_get(pTemp, j)), false);
}
for(int j = 0; j < json_array_length(pTemp); j++)
AddFileJob(json_string_get(json_array_get(pTemp, j)), true);
}
if((pTemp = json_object_get(pCurrent, "remove"))->type == json_array)
{
for(int j = 0; j < json_array_length(pTemp); j++)
AddFileJob(json_string_get(json_array_get(pTemp, j)), false);
}
else
break;
}
else
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/demo.h
Expand Up @@ -77,7 +77,7 @@ class IDemoRecorder : public IInterface
public:
~IDemoRecorder() {}
virtual bool IsRecording() const = 0;
virtual int Stop(bool Finalize = false) = 0;
virtual int Stop() = 0;
virtual int Length() const = 0;
};

Expand Down
8 changes: 4 additions & 4 deletions src/engine/fetcher.h
Expand Up @@ -40,10 +40,10 @@ class CFetchTask
STATE_ABORTED,
};

const double Current() const { return m_Current; };
const double Size() const { return m_Size; };
const int Progress() const { return m_Progress; };
const int State() const { return m_State; };
double Current() const { return m_Current; };
double Size() const { return m_Size; };
int Progress() const { return m_Progress; };
int State() const { return m_State; };
const char *Dest() const { return m_aDest; };

void Abort() { m_Abort = true; };
Expand Down
2 changes: 1 addition & 1 deletion src/engine/input.h
Expand Up @@ -69,7 +69,7 @@ class IInput : public IInterface
virtual void MouseRelative(float *x, float *y) = 0;

virtual bool GetIMEState() = 0;
virtual void SetIMEState(bool activate) = 0;
virtual void SetIMEState(bool Activate) = 0;
virtual const char* GetIMECandidate() = 0;
virtual int GetEditingCursor() = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions src/engine/map.h
Expand Up @@ -29,6 +29,8 @@ class IEngineMap : public IMap
virtual bool IsLoaded() = 0;
virtual void Unload() = 0;
virtual unsigned Crc() = 0;
virtual int MapSize() = 0;
virtual IOHANDLE File() = 0;
};

extern IEngineMap *CreateEngineMap();
Expand Down
72 changes: 37 additions & 35 deletions src/engine/server/server.cpp
Expand Up @@ -2258,7 +2258,7 @@ void CServer::DemoRecorder_HandleAutoStart()
char aDate[20];
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/%s_%s.demo", "auto/autorecord", aDate);
m_aDemoRecorder[MAX_CLIENTS].Start(Storage(), m_pConsole, aFilename, GameServer()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "server");
m_aDemoRecorder[MAX_CLIENTS].Start(Storage(), m_pConsole, aFilename, GameServer()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "server", m_CurrentMapSize, m_pCurrentMapData);
if(g_Config.m_SvAutoDemoMax)
{
// clean up auto recorded demos
Expand All @@ -2277,7 +2277,7 @@ void CServer::SaveDemo(int ClientID, float Time)
{
if(IsRecording(ClientID))
{
m_aDemoRecorder[ClientID].Stop(true);
m_aDemoRecorder[ClientID].Stop();

// rename the demo
char aOldFilename[256];
Expand All @@ -2294,7 +2294,7 @@ void CServer::StartRecord(int ClientID)
{
char aFilename[128];
str_format(aFilename, sizeof(aFilename), "demos/%s_%d_%d_tmp.demo", m_aCurrentMap, g_Config.m_SvPort, ClientID);
m_aDemoRecorder[ClientID].Start(Storage(), Console(), aFilename, GameServer()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "client", m_CurrentMapSize, m_pCurrentMapData);
m_aDemoRecorder[ClientID].Start(Storage(), Console(), aFilename, GameServer()->NetVersion(), m_aCurrentMap, m_CurrentMapCrc, "server", m_CurrentMapSize, m_pCurrentMapData);
}
}

Expand Down Expand Up @@ -2328,7 +2328,7 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser)
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/demo_%s.demo", aDate);
}
pServer->m_aDemoRecorder[MAX_CLIENTS].Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, pServer->m_CurrentMapCrc, "server");
pServer->m_aDemoRecorder[MAX_CLIENTS].Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, pServer->m_CurrentMapCrc, "server", pServer->m_CurrentMapSize, pServer->m_pCurrentMapData);
}

void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser)
Expand Down Expand Up @@ -2709,10 +2709,10 @@ int main(int argc, const char **argv) // ignore_convention
pServer->RegisterCommands();

// execute autoexec file
IOHANDLE file = pStorage->OpenFile(AUTOEXEC_SERVER_FILE, IOFLAG_READ, IStorage::TYPE_ALL);
if(file)
IOHANDLE File = pStorage->OpenFile(AUTOEXEC_SERVER_FILE, IOFLAG_READ, IStorage::TYPE_ALL);
if(File)
{
io_close(file);
io_close(File);
pConsole->ExecuteFile(AUTOEXEC_SERVER_FILE);
}
else // fallback
Expand Down Expand Up @@ -2758,37 +2758,39 @@ void CServer::GetClientAddr(int ClientID, NETADDR *pAddr)
const char *CServer::GetAnnouncementLine(char const *pFileName)
{
IOHANDLE File = m_pStorage->OpenFile(pFileName, IOFLAG_READ, IStorage::TYPE_ALL);
if(File)
if(!File)
return 0;

std::vector<char*> v;
char *pLine;
CLineReader *lr = new CLineReader();
lr->Init(File);
while((pLine = lr->Get()))
if(str_length(pLine))
if(pLine[0]!='#')
v.push_back(pLine);
if(v.size() == 1)
{
std::vector<char*> v;
char *pLine;
CLineReader *lr = new CLineReader();
lr->Init(File);
while((pLine = lr->Get()))
if(str_length(pLine))
if(pLine[0]!='#')
v.push_back(pLine);
if(v.size() == 1)
{
m_AnnouncementLastLine = 0;
}
else if(!g_Config.m_SvAnnouncementRandom)
{
if(m_AnnouncementLastLine >= v.size())
m_AnnouncementLastLine %= v.size();
}
else
{
unsigned Rand;
do
Rand = rand() % v.size();
while(Rand == m_AnnouncementLastLine);
m_AnnouncementLastLine = 0;
}
else if(!g_Config.m_SvAnnouncementRandom)
{
if(m_AnnouncementLastLine >= v.size())
m_AnnouncementLastLine %= v.size();
}
else
{
unsigned Rand;
do
Rand = rand() % v.size();
while(Rand == m_AnnouncementLastLine);

m_AnnouncementLastLine = Rand;
}
return v[m_AnnouncementLastLine];
m_AnnouncementLastLine = Rand;
}
return 0;

io_close(File);

return v[m_AnnouncementLastLine];
}

int* CServer::GetIdMap(int ClientID)
Expand Down
73 changes: 36 additions & 37 deletions src/engine/server/sql_server.cpp
Expand Up @@ -43,10 +43,23 @@ CSqlServer::~CSqlServer()
}
catch (sql::SQLException &e)
{
dbg_msg("sql", "ERROR: No SQL connection");
dbg_msg("sql", "ERROR: No SQL connection: %s", e.what());
}
catch (const std::exception& ex)
{
dbg_msg("sql", "ERROR: No SQL connection: %s", ex.what());
}
catch (const std::string& ex)
{
dbg_msg("sql", "ERROR: No SQL connection: %s", ex.c_str());
}
catch (...)
{
dbg_msg("sql", "Unknown Error cause by the MySQL/C++ Connector");
}
UnLock();
lock_destroy(m_SqlLock);
m_SqlLock = 0;
}

bool CSqlServer::Connect()
Expand All @@ -59,16 +72,28 @@ bool CSqlServer::Connect()
{
// Connect to specific database
m_pConnection->setSchema(m_aDatabase);
return true;
}
catch (sql::SQLException &e)
{
dbg_msg("sql", "MySQL Error: %s", e.what());

dbg_msg("sql", "ERROR: SQL connection failed");
UnLock();
return false;
}
return true;
catch (const std::exception& ex)
{
dbg_msg("sql", "MySQL Error: %s", ex.what());
}
catch (const std::string& ex)
{
dbg_msg("sql", "MySQL Error: %s", ex.c_str());
}
catch (...)
{
dbg_msg("sql", "Unknown Error cause by the MySQL/C++ Connector");
}

dbg_msg("sql", "ERROR: SQL connection failed");
UnLock();
return false;
}

try
Expand Down Expand Up @@ -110,47 +135,21 @@ bool CSqlServer::Connect()
catch (sql::SQLException &e)
{
dbg_msg("sql", "MySQL Error: %s", e.what());
dbg_msg("sql", "ERROR: sql connection failed");
UnLock();
return false;
}
catch (const std::exception& ex)
{
// ...
dbg_msg("sql", "1 %s",ex.what());

dbg_msg("sql", "MySQL Error: %s", ex.what());
}
catch (const std::string& ex)
{
// ...
dbg_msg("sql", "2 %s",ex.c_str());
}
catch( int )
{
dbg_msg("sql", "3 %s");
}
catch( float )
{
dbg_msg("sql", "4 %s");
}

catch( char[] )
{
dbg_msg("sql", "5 %s");
}

catch( char )
{
dbg_msg("sql", "6 %s");
dbg_msg("sql", "MySQL Error: %s", ex.c_str());
}
catch (...)
{
dbg_msg("sql", "Unknown Error cause by the MySQL/C++ Connector, my advice compile server_debug and use it");

dbg_msg("sql", "ERROR: sql connection failed");
UnLock();
return false;
dbg_msg("sql", "Unknown Error cause by the MySQL/C++ Connector");
}

dbg_msg("sql", "ERROR: sql connection failed");
UnLock();
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/engine/shared/config.cpp
Expand Up @@ -26,10 +26,9 @@ class CConfig : public IConfig
CCallback m_aCallbacks[MAX_CALLBACKS];
int m_NumCallbacks;

void EscapeParam(char *pDst, const char *pSrc, int size)
void EscapeParam(char *pDst, const char *pSrc, int Size)
{
str_escape(&pDst, pSrc, pDst + size);
*pDst = 0;
str_escape(&pDst, pSrc, pDst + Size);
}

public:
Expand Down
3 changes: 1 addition & 2 deletions src/engine/shared/config_variables.h
Expand Up @@ -131,7 +131,6 @@ MACRO_CONFIG_INT(GfxQuadAsTriangle, gfx_quad_as_triangle, 0, 0, 0, CFGFLAG_SAVE|
#else
MACRO_CONFIG_INT(GfxQuadAsTriangle, gfx_quad_as_triangle, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Render quads as triangles (fixes quad coloring on some GPUs)")
#endif
MACRO_CONFIG_INT(GfxHighdpi, gfx_highdpi, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Try to use high-dpi screen features")

MACRO_CONFIG_INT(InpMousesens, inp_mousesens, 100, 5, 100000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Mouse sensitivity")
MACRO_CONFIG_INT(InpMouseOld, inp_mouseold, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use old mouse mode (warp mouse instead of raw input)")
Expand Down Expand Up @@ -199,7 +198,7 @@ MACRO_CONFIG_INT(SvSaveWorseScores, sv_save_worse_scores, 1, 0, 1, CFGFLAG_SERVE
MACRO_CONFIG_INT(SvPauseable, sv_pauseable, 1, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Whether players can pause their char or not")
MACRO_CONFIG_INT(SvPauseMessages, sv_pause_messages, 0, 0, 1, CFGFLAG_SERVER, "Whether to show messages when a player pauses and resumes")
MACRO_CONFIG_INT(SvPauseTime, sv_pause_time, 0, 0, 1, CFGFLAG_SERVER, "Whether '/pause' and 'sv_max_dc_restore' pauses the time of player or not")
MACRO_CONFIG_INT(SvPauseFrequency, sv_pause_frequency, 1, 0, 9999, CFGFLAG_SERVER, "The minimum allowed delay between pauses")
MACRO_CONFIG_INT(SvSpecFrequency, sv_pause_frequency, 1, 0, 9999, CFGFLAG_SERVER, "The minimum allowed delay between /spec")
MACRO_CONFIG_INT(SvInvite, sv_invite, 1, 0, 1, CFGFLAG_SERVER, "Whether players can invite other players to teams")
MACRO_CONFIG_INT(SvInviteFrequency, sv_invite_frequency, 1, 0, 9999, CFGFLAG_SERVER, "The minimum allowed delay between invites")

Expand Down
7 changes: 2 additions & 5 deletions src/engine/shared/console.cpp
Expand Up @@ -738,13 +738,10 @@ void CConsole::ConToggle(IConsole::IResult *pResult, void *pUser)
{
CStrVariableData *pData = static_cast<CStrVariableData *>(pUserData);
const char *pStr = !str_comp(pData->m_pStr, pResult->GetString(1)) ? pResult->GetString(2) : pResult->GetString(1);
str_copy(aBuf, pResult->GetString(0), sizeof(aBuf));
str_format(aBuf, sizeof(aBuf), "%s \"", pResult->GetString(0));
char *pDst = aBuf + str_length(aBuf);
*pDst++ = ' ';
*pDst++ = '"';
str_escape(&pDst, pStr, aBuf + sizeof(aBuf));
*pDst++ = '"';
*pDst++ = 0;
str_append(aBuf, "\"", sizeof(aBuf));
pConsole->ExecuteLine(aBuf);
aBuf[0] = 0;
}
Expand Down
12 changes: 12 additions & 0 deletions src/engine/shared/datafile.cpp
Expand Up @@ -437,6 +437,18 @@ unsigned CDataFileReader::Crc()
return m_pDataFile->m_Crc;
}

int CDataFileReader::MapSize()
{
if(!m_pDataFile) return 0;
return m_pDataFile->m_Header.m_Size + 16;
}

IOHANDLE CDataFileReader::File()
{
if(!m_pDataFile) return 0;
return m_pDataFile->m_File;
}


CDataFileWriter::CDataFileWriter()
{
Expand Down
2 changes: 2 additions & 0 deletions src/engine/shared/datafile.h
Expand Up @@ -33,6 +33,8 @@ class CDataFileReader
void Unload();

unsigned Crc();
int MapSize();
IOHANDLE File();
};

// write access
Expand Down
51 changes: 25 additions & 26 deletions src/engine/shared/demo.cpp
Expand Up @@ -22,18 +22,18 @@ static const int gs_LengthOffset = 152;
static const int gs_NumMarkersOffset = 176;


CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool DelayedMapData)
CDemoRecorder::CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool NoMapData)
{
m_File = 0;
m_pfnFilter = 0;
m_pUser = 0;
m_LastTickMarker = -1;
m_pSnapshotDelta = pSnapshotDelta;
m_DelayedMapData = DelayedMapData;
m_NoMapData = NoMapData;
}

// Record
int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, unsigned Crc, const char *pType, unsigned int MapSize, unsigned char *pMapData, DEMOFUNC_FILTER pfnFilter, void *pUser)
int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetVersion, const char *pMap, unsigned Crc, const char *pType, unsigned int MapSize, unsigned char *pMapData, IOHANDLE MapFile, DEMOFUNC_FILTER pfnFilter, void *pUser)
{
m_pfnFilter = pfnFilter;
m_pUser = pUser;
Expand All @@ -52,14 +52,19 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con

CDemoHeader Header;
CTimelineMarkers TimelineMarkers;
if(m_File)
if(m_File) {
io_close(DemoFile);
return -1;
}

m_pConsole = pConsole;

IOHANDLE MapFile = NULL;
bool CloseMapFile = false;

if(MapFile)
io_seek(MapFile, 0, IOSEEK_START);

if(!m_DelayedMapData)
if(!pMapData && !MapFile)
{
// open mapfile
char aMapFilename[128];
Expand Down Expand Up @@ -87,6 +92,8 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf);
return -1;
}

CloseMapFile = true;
}

// write header
Expand All @@ -95,8 +102,6 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
Header.m_Version = gs_ActVersion;
str_copy(Header.m_aNetversion, pNetVersion, sizeof(Header.m_aNetversion));
str_copy(Header.m_aMapName, pMap, sizeof(Header.m_aMapName));
if(!m_DelayedMapData)
MapSize = io_length(MapFile);
Header.m_aMapSize[0] = (MapSize>>24)&0xff;
Header.m_aMapSize[1] = (MapSize>>16)&0xff;
Header.m_aMapSize[2] = (MapSize>>8)&0xff;
Expand All @@ -111,9 +116,12 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
io_write(DemoFile, &Header, sizeof(Header));
io_write(DemoFile, &TimelineMarkers, sizeof(TimelineMarkers)); // fill this on stop

if(m_DelayedMapData)
if(m_NoMapData)
{
}
else if(pMapData)
{
io_seek(DemoFile, MapSize, IOSEEK_CUR);
io_write(DemoFile, pMapData, MapSize);
}
else
{
Expand All @@ -126,7 +134,10 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
break;
io_write(DemoFile, &aChunk, Bytes);
}
io_close(MapFile);
if(CloseMapFile)
io_close(MapFile);
else
io_seek(MapFile, 0, IOSEEK_START);
}

m_LastKeyFrame = -1;
Expand Down Expand Up @@ -291,7 +302,7 @@ void CDemoRecorder::RecordMessage(const void *pData, int Size)
Write(CHUNKTYPE_MESSAGE, pData, Size);
}

int CDemoRecorder::Stop(bool Finalize)
int CDemoRecorder::Stop()
{
if(!m_File)
return -1;
Expand Down Expand Up @@ -325,12 +336,6 @@ int CDemoRecorder::Stop(bool Finalize)
io_write(m_File, aMarker, sizeof(aMarker));
}

if(Finalize && m_DelayedMapData)
{
io_seek(m_File, gs_NumMarkersOffset + sizeof(CTimelineMarkers), IOSEEK_START);
io_write(m_File, m_pMapData, m_MapSize);
}

io_close(m_File);
m_File = 0;
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Stopped recording");
Expand Down Expand Up @@ -916,14 +921,8 @@ bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, i
return false;

io_read(File, pDemoHeader, sizeof(CDemoHeader));
if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_OldVersion)
{
io_close(File);
return false;
}

io_close(File);
return true;
return !(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_OldVersion);
}

int CDemoPlayer::GetDemoType() const
Expand Down Expand Up @@ -959,7 +958,7 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
return;

const CDemoPlayer::CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo();
if (m_pDemoRecorder->Start(m_pStorage, m_pConsole, pDst, m_pNetVersion, pMapInfo->m_aName, pMapInfo->m_Crc, "client", 0, 0, pfnFilter, pUser) == -1)
if (m_pDemoRecorder->Start(m_pStorage, m_pConsole, pDst, m_pNetVersion, pMapInfo->m_aName, pMapInfo->m_Crc, "client", 0, 0, 0, pfnFilter, pUser) == -1)
return;


Expand Down
8 changes: 4 additions & 4 deletions src/engine/shared/demo.h
Expand Up @@ -19,7 +19,7 @@ class CDemoRecorder : public IDemoRecorder
class CSnapshotDelta *m_pSnapshotDelta;
int m_NumTimelineMarkers;
int m_aTimelineMarkers[MAX_TIMELINE_MARKERS];
bool m_DelayedMapData;
bool m_NoMapData;
unsigned int m_MapSize;
unsigned char *m_pMapData;

Expand All @@ -29,11 +29,11 @@ class CDemoRecorder : public IDemoRecorder
void WriteTickMarker(int Tick, int Keyframe);
void Write(int Type, const void *pData, int Size);
public:
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool DelayedMapData = false);
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta, bool NoMapData = false);
CDemoRecorder() {}

int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, unsigned MapCrc, const char *pType, unsigned int MapSize = 0, unsigned char *pMapData = 0, DEMOFUNC_FILTER pfnFilter = 0, void *pUser = 0);
int Stop(bool Finalize = false);
int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, unsigned MapCrc, const char *pType, unsigned int MapSize, unsigned char *pMapData, IOHANDLE MapFile = 0, DEMOFUNC_FILTER pfnFilter = 0, void *pUser = 0);
int Stop();
void AddDemoMarker();

void RecordSnapshot(int Tick, const void *pData, int Size);
Expand Down
10 changes: 10 additions & 0 deletions src/engine/shared/map.cpp
Expand Up @@ -43,6 +43,16 @@ class CMap : public IEngineMap
{
return m_DataFile.Crc();
}

virtual int MapSize()
{
return m_DataFile.MapSize();
}

virtual IOHANDLE File()
{
return m_DataFile.File();
}
};

extern IEngineMap *CreateEngineMap() { return new CMap; }
8 changes: 6 additions & 2 deletions src/engine/shared/storage.cpp
Expand Up @@ -280,7 +280,11 @@ class CStorage : public IStorage
BufferSize = sizeof(aBuffer);
}

if(pFilename[0] == '/' || pFilename[0] == '\\' || str_find(pFilename, "../") != NULL || str_find(pFilename, "..\\") != NULL
if(Type == TYPE_ABSOLUTE)
{
return io_open(pFilename, Flags);
}
else if (pFilename[0] == '/' || pFilename[0] == '\\' || str_find(pFilename, "../") != NULL || str_find(pFilename, "..\\") != NULL
#ifdef CONF_FAMILY_WINDOWS
|| (pFilename[0] && pFilename[1] == ':')
#endif
Expand All @@ -296,7 +300,7 @@ class CStorage : public IStorage
{
IOHANDLE Handle = 0;

if(Type == TYPE_ALL)
if(Type <= TYPE_ALL)
{
// check all available directories
for(int i = 0; i < m_NumPaths; ++i)
Expand Down
1 change: 1 addition & 0 deletions src/engine/storage.h
Expand Up @@ -13,6 +13,7 @@ class IStorage : public IInterface
{
TYPE_SAVE = 0,
TYPE_ALL = -1,
TYPE_ABSOLUTE = -2,

STORAGETYPE_BASIC = 0,
STORAGETYPE_SERVER,
Expand Down
8 changes: 3 additions & 5 deletions src/game/client/components/binds.cpp
Expand Up @@ -293,20 +293,18 @@ void CBinds::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
CBinds *pSelf = (CBinds *)pUserData;

char aBuffer[256];
char *pEnd = aBuffer+sizeof(aBuffer)-8;
char *pEnd = aBuffer+sizeof(aBuffer);
pConfig->WriteLine("unbindall");
for(int i = 0; i < KEY_LAST; i++)
{
if(!pSelf->m_apKeyBindings[i])
continue;
str_format(aBuffer, sizeof(aBuffer), "bind %s ", pSelf->Input()->KeyName(i));
str_format(aBuffer, sizeof(aBuffer), "bind %s \"", pSelf->Input()->KeyName(i));

// process the string. we need to escape some characters
char *pDst = aBuffer + str_length(aBuffer);
*pDst++ = '"';
str_escape(&pDst, pSelf->m_apKeyBindings[i], pEnd);
*pDst++ = '"';
*pDst++ = 0;
str_append(aBuffer, "\"", sizeof(aBuffer));

pConfig->WriteLine(aBuffer);
}
Expand Down
14 changes: 13 additions & 1 deletion src/game/client/components/controls.cpp
Expand Up @@ -217,7 +217,16 @@ int CControls::SnapInput(int *pData)
else if(m_pClient->m_pMenus->IsActive())
m_InputData[g_Config.m_ClDummy].m_PlayerFlags = PLAYERFLAG_IN_MENU;
else
{
if(m_InputData[g_Config.m_ClDummy].m_PlayerFlags == PLAYERFLAG_CHATTING)
{
CServerInfo Info;
GameClient()->Client()->GetServerInfo(&Info);
if(IsDDNet(&Info))
ResetInput(g_Config.m_ClDummy);
}
m_InputData[g_Config.m_ClDummy].m_PlayerFlags = PLAYERFLAG_PLAYING;
}

if(m_pClient->m_pScoreboard->Active())
m_InputData[g_Config.m_ClDummy].m_PlayerFlags |= PLAYERFLAG_SCOREBOARD;
Expand All @@ -236,7 +245,10 @@ int CControls::SnapInput(int *pData)
// we freeze the input if chat or menu is activated
if(!(m_InputData[g_Config.m_ClDummy].m_PlayerFlags&PLAYERFLAG_PLAYING))
{
ResetInput(g_Config.m_ClDummy);
CServerInfo Info;
GameClient()->Client()->GetServerInfo(&Info);
if(!IsDDNet(&Info))
ResetInput(g_Config.m_ClDummy);

mem_copy(pData, &m_InputData[g_Config.m_ClDummy], sizeof(m_InputData[0]));

Expand Down
5 changes: 3 additions & 2 deletions src/game/client/components/menus.cpp
Expand Up @@ -1277,7 +1277,7 @@ int CMenus::Render()
static int s_ButtonTryAgain = 0;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed)
{
Client()->Connect(g_Config.m_UiServerAddress);
Client()->Connect(g_Config.m_UiServerAddress, g_Config.m_Password);
}

Box.HSplitBottom(60.f, &Box, &Part);
Expand Down Expand Up @@ -1651,7 +1651,8 @@ int CMenus::Render()

void CMenus::SetActive(bool Active)
{
Input()->SetIMEState(Active);
if(Active != m_MenuActive)
Input()->SetIMEState(Active);
m_MenuActive = Active;
#if defined(__ANDROID__)
UI()->AndroidShowScreenKeys(!m_MenuActive && !m_pClient->m_pControls->m_UsingGamepad);
Expand Down
11 changes: 1 addition & 10 deletions src/game/client/components/menus_settings.cpp
Expand Up @@ -846,7 +846,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples;
static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality;
static int s_GfxTextureCompression = g_Config.m_GfxTextureCompression;
static int s_GfxHighdpi = g_Config.m_GfxHighdpi;

CUIRect ModeList;
MainView.VSplitLeft(300.0f, &MainView, &ModeList);
Expand Down Expand Up @@ -966,13 +965,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
if(DoButton_CheckBox(&g_Config.m_GfxHighDetail, Localize("High Detail"), g_Config.m_GfxHighDetail, &Button))
g_Config.m_GfxHighDetail ^= 1;

MainView.HSplitTop(20.0f, &Button, &MainView);
if(DoButton_CheckBox(&g_Config.m_GfxHighdpi, Localize("High-DPI screen support (experimental)"), g_Config.m_GfxHighdpi, &Button))
{
g_Config.m_GfxHighdpi ^= 1;
CheckSettings = true;
}

// check if the new settings require a restart
if(CheckSettings)
{
Expand All @@ -982,8 +974,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
s_GfxVsync == g_Config.m_GfxVsync &&
s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples &&
s_GfxTextureQuality == g_Config.m_GfxTextureQuality &&
s_GfxTextureCompression == g_Config.m_GfxTextureCompression &&
s_GfxHighdpi == g_Config.m_GfxHighdpi)
s_GfxTextureCompression == g_Config.m_GfxTextureCompression)
m_NeedRestartGraphics = false;
else
m_NeedRestartGraphics = true;
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/components/statboard.cpp
Expand Up @@ -434,7 +434,7 @@ void CStatboard::AutoStatCSV()
mem_free(buf);

Client()->AutoCSV_Start();
}
}
}

char* CStatboard::ReplaceCommata(char* pStr)
Expand Down
4 changes: 2 additions & 2 deletions src/game/editor/auto_map.h
Expand Up @@ -52,10 +52,10 @@ class CAutoMapper
void Load(const char* pTileName);
void Proceed(class CLayerTiles *pLayer, int ConfigID);

int ConfigNamesNum() { return m_lConfigs.size(); }
int ConfigNamesNum() const { return m_lConfigs.size(); }
const char* GetConfigName(int Index);

const bool IsLoaded() { return m_FileLoaded; }
bool IsLoaded() const { return m_FileLoaded; }
private:
array<CConfiguration> m_lConfigs;
class CEditor *m_pEditor;
Expand Down
9 changes: 7 additions & 2 deletions src/game/editor/editor.cpp
Expand Up @@ -973,6 +973,12 @@ void CEditor::DoToolbar(CUIRect ToolBar)
if(Input()->KeyPress(KEY_S) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL)) && (Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT)) && (Input()->KeyIsPressed(KEY_LALT) || Input()->KeyIsPressed(KEY_RALT)) && m_Dialog == DIALOG_NONE)
InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_MAP, "Save map", "Save", "maps", "", CallbackSaveCopyMap, this);

// ctrl+l to load
if(Input()->KeyPress(KEY_L) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL)) && m_Dialog == DIALOG_NONE)
{
InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_MAP, "Load map", "Load", "maps", "", CallbackOpenMap, this);
}

// detail button
TB_Top.VSplitLeft(40.0f, &Button, &TB_Top);
static int s_HqButton = 0;
Expand Down Expand Up @@ -3224,7 +3230,6 @@ void CEditor::ReplaceSound(const char *pFileName, int StorageType, void *pUser)
io_read(SoundFile, pData, (unsigned) DataSize);
io_close(SoundFile);

//
CEditorSound *pSound = pEditor->m_Map.m_lSounds[pEditor->m_SelectedSound];
int External = pSound->m_External;

Expand Down Expand Up @@ -5061,7 +5066,7 @@ void CEditor::RenderMenubar(CUIRect MenuBar)
time(&rawtime);
timeinfo = localtime(&rawtime);

str_format(aBuf, sizeof(aBuf), "Z: %i, A: %.1f, G: %i %02d:%02d", m_ZoomLevel, m_AnimateSpeed, m_GridFactor, timeinfo->tm_hour, timeinfo->tm_min);
str_format(aBuf, sizeof(aBuf), "X: %i, Y: %i, Z: %i, A: %.1f, G: %i %02d:%02d", (int)UI()->MouseWorldX()/32, (int)UI()->MouseWorldY()/32, m_ZoomLevel, m_AnimateSpeed, m_GridFactor, timeinfo->tm_hour, timeinfo->tm_min);
UI()->DoLabel(&Info, aBuf, 10.0f, 1, -1);

static int s_CloseButton = 0;
Expand Down
1 change: 1 addition & 0 deletions src/game/editor/io.cpp
Expand Up @@ -945,6 +945,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
TILE_SWITCHTIMEDOPEN,
TILE_SWITCHTIMEDCLOSE,
TILE_SWITCHOPEN,
TILE_SWITCHCLOSE,
TILE_FREEZE,
TILE_DFREEZE,
TILE_DUNFREEZE,
Expand Down
1 change: 1 addition & 0 deletions src/game/server/gamecontext.cpp
Expand Up @@ -2684,6 +2684,7 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
aLines.add(pCopy);
TotalLength += Length;
}
io_close(File);

char *pSettings = (char *)mem_alloc(TotalLength, 1);
int Offset = 0;
Expand Down
10 changes: 7 additions & 3 deletions src/game/server/player.cpp
Expand Up @@ -300,6 +300,9 @@ void CPlayer::Snap(int SnappingClient)
pPlayerInfo->m_Score = abs(m_Score) * -1;
pPlayerInfo->m_Team = (m_ClientVersion < VERSION_DDNET_OLD || m_Paused != PAUSE_PAUSED || m_ClientID != SnappingClient) && m_Paused < PAUSE_SPEC ? m_Team : TEAM_SPECTATORS;

if(m_ClientID == SnappingClient && m_Paused == PAUSE_PAUSED && m_ClientVersion < VERSION_DDNET_OLD)
pPlayerInfo->m_Team = TEAM_SPECTATORS;

if(m_ClientID == SnappingClient && (m_Paused != PAUSE_PAUSED || m_ClientVersion >= VERSION_DDNET_OLD))
pPlayerInfo->m_Local = 1;

Expand Down Expand Up @@ -677,18 +680,19 @@ int CPlayer::Pause(int State, bool Force)
case PAUSE_NONE:
if(m_pCharacter->IsPaused()) // First condition might be unnecessary
{
if(!Force && m_LastPause && m_LastPause + g_Config.m_SvPauseFrequency * Server()->TickSpeed() > Server()->Tick())
if(!Force && m_LastPause && m_LastPause + g_Config.m_SvSpecFrequency * Server()->TickSpeed() > Server()->Tick())
{
GameServer()->SendChatTarget(m_ClientID, "Can't pause that quickly.");
GameServer()->SendChatTarget(m_ClientID, "Can't /spec that quickly.");
return m_Paused; // Do not update state. Do not collect $200
}
m_pCharacter->Pause(false);
GameServer()->CreatePlayerSpawn(m_pCharacter->m_Pos, m_pCharacter->Teams()->TeamMask(m_pCharacter->Team(), -1, m_ClientID));
}
// fall-thru
case PAUSE_SPEC:
if(g_Config.m_SvPauseMessages)
{
str_format(aBuf, sizeof(aBuf), (m_Paused > PAUSE_NONE) ? "'%s' paused" : "'%s' resumed", Server()->ClientName(m_ClientID));
str_format(aBuf, sizeof(aBuf), (m_Paused > PAUSE_NONE) ? "'%s' speced" : "'%s' resumed", Server()->ClientName(m_ClientID));
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
break;
Expand Down
8 changes: 6 additions & 2 deletions src/game/server/score/sql_score.cpp
Expand Up @@ -97,8 +97,12 @@ void CSqlScore::ExecSqlFunc(void *pUser)
// try to connect to a working databaseserver
while (!Success && !connector.MaxTriesReached(pData->m_ReadOnly) && connector.ConnectSqlServer(pData->m_ReadOnly))
{
if (pData->m_pFuncPtr(connector.SqlServer(), pData->m_pSqlData, false))
Success = true;
try {
if (pData->m_pFuncPtr(connector.SqlServer(), pData->m_pSqlData, false))
Success = true;
} catch (...) {
dbg_msg("sql", "Unexpected exception caught");
}

// disconnect from databaseserver
connector.SqlServer()->Disconnect();
Expand Down
6 changes: 3 additions & 3 deletions src/game/version.h
Expand Up @@ -3,8 +3,8 @@
#ifndef GAME_VERSION_H
#define GAME_VERSION_H
#include "generated/nethash.cpp"
#define GAME_VERSION "0.6.3, 10.6.4"
#define GAME_VERSION "0.6.3, 10.6.5"
#define GAME_NETVERSION "0.6 626fce9a778df4d4"
static const char GAME_RELEASE_VERSION[8] = "10.6.4";
#define CLIENT_VERSIONNR 10064
static const char GAME_RELEASE_VERSION[8] = "10.6.5";
#define CLIENT_VERSIONNR 10065
#endif
4 changes: 2 additions & 2 deletions src/tools/config_retrieve.cpp
Expand Up @@ -6,7 +6,7 @@
void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
{
CDataFileReader Map;
if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ALL))
if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
{
dbg_msg("config_retrieve", "error opening map '%s'", pMapName);
return;
Expand All @@ -28,7 +28,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
break;

ConfigFound = true;
IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ALL);
IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ABSOLUTE);
if(!Config)
{
dbg_msg("config_retrieve", "error opening config for writing '%s'", pConfigName);
Expand Down
5 changes: 3 additions & 2 deletions src/tools/config_store.cpp
Expand Up @@ -7,7 +7,7 @@

void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
{
IOHANDLE File = pStorage->OpenFile(pConfigName, IOFLAG_READ, IStorage::TYPE_ALL);
IOHANDLE File = pStorage->OpenFile(pConfigName, IOFLAG_READ, IStorage::TYPE_ABSOLUTE);
array<char *> aLines;
char *pSettings = NULL;
if(!File)
Expand All @@ -29,6 +29,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
aLines.add(pCopy);
TotalLength += Length;
}
io_close(File);

pSettings = (char *)mem_alloc(TotalLength, 1);
int Offset = 0;
Expand All @@ -41,7 +42,7 @@ void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
}

CDataFileReader Reader;
Reader.Open(pStorage, pMapName, IStorage::TYPE_ALL);
Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE);

CDataFileWriter Writer;
Writer.Init();
Expand Down
116 changes: 116 additions & 0 deletions src/tools/map_diff.cpp
@@ -0,0 +1,116 @@
#include <game/mapitems.h>
#include <game/gamecore.h>
#include <base/system.h>
#include <engine/external/pnglite/pnglite.h>
#include <engine/shared/datafile.h>
#include <engine/storage.h>

bool Process(IStorage *pStorage, char **pMapNames)
{
CDataFileReader Maps[2];

for(int i = 0; i < 2; ++i)
{
if(!Maps[i].Open(pStorage, pMapNames[i], IStorage::TYPE_ABSOLUTE))
{
dbg_msg("map_compare", "error opening map '%s'", pMapNames[i]);
return false;
}

CDataFileReader *pMap = &Maps[i];
// check version
CMapItemVersion *pVersion = (CMapItemVersion *)pMap->FindItem(MAPITEMTYPE_VERSION, 0);
if(pVersion && pVersion->m_Version != 1)
return false;
}

int Start[2], Num[2];

Maps[0].GetType(MAPITEMTYPE_LAYER, &Start[0], &Num[0]);
Maps[1].GetType(MAPITEMTYPE_LAYER, &Start[1], &Num[1]);

// ensure basic layout
if(Num[0] != Num[1])
{
dbg_msg("map_compare", "different layer numbers:");
for(int i = 0; i < 2; ++i)
dbg_msg("map_compare", " \"%s\": %d layers", pMapNames[i], Num[i]);
return false;
}

// preload data
for(int j = 0; j < Num[0]; ++j)
{
CMapItemLayer *pItem[2];
CMapItemLayerTilemap *pTilemap[2];
for(int i = 0; i < 2; ++i)
{
pItem[i] = (CMapItemLayer *)Maps[i].GetItem(Start[i]+j, 0, 0);
pTilemap[i] = (CMapItemLayerTilemap *)pItem[i];
(CTile *)Maps[i].GetData(pTilemap[i]->m_Data);
}
}

// compare
for(int j = 0; j < Num[0]; ++j)
{
CMapItemLayer *pItem[2];
for(int i = 0; i < 2; ++i)
pItem[i] = (CMapItemLayer *)Maps[i].GetItem(Start[i]+j, 0, 0);

if(pItem[0]->m_Type != LAYERTYPE_TILES)
continue;

CMapItemLayerTilemap *pTilemap[2];
char aName[2][16];

for(int i = 0; i < 2; ++i)
{
pTilemap[i] = (CMapItemLayerTilemap *)pItem[i];
IntsToStr(pTilemap[i]->m_aName, sizeof(pTilemap[i]->m_aName)/sizeof(int), aName[i]);
}

if(str_comp_num(aName[0], aName[1], sizeof(aName[0])) != 0 || pTilemap[0]->m_Width != pTilemap[1]->m_Width || pTilemap[0]->m_Height != pTilemap[1]->m_Height)
{
dbg_msg("map_compare", "different tile layers:");
for(int i = 0; i < 2; ++i)
dbg_msg("map_compare", " \"%s\" (%dx%d)", aName[i], pTilemap[i]->m_Width, pTilemap[i]->m_Height);
return false;
}
CTile *pTile[2];
for(int i = 0; i < 2; ++i)
pTile[i] = (CTile *)Maps[i].GetData(pTilemap[i]->m_Data);

for(int y = 0; y < pTilemap[0]->m_Height; y++)
{
for(int x = 0; x < pTilemap[0]->m_Width; x++)
{
int pos = y * pTilemap[0]->m_Width + x;
if(pTile[0][pos].m_Index != pTile[1][pos].m_Index || pTile[0][pos].m_Flags != pTile[1][pos].m_Flags)
{
dbg_msg("map_compare", "[%d:%s] %dx%d: (index: %d, flags: %d) != (index: %d, flags: %d)", Num[0], aName[0], x, y, pTile[0][pos].m_Index, pTile[0][pos].m_Flags, pTile[1][pos].m_Index, pTile[0][pos].m_Flags);
}
}
}
}

return true;
}

int main(int argc, char* argv[])
{
dbg_logger_stdout();
dbg_logger_file("map_diff.txt");

IStorage *pStorage = CreateLocalStorage();

if(argc == 3)
{
return Process(pStorage, &argv[1]) ? 0 : 1;
}
else
{
dbg_msg("usage", "%s map1 map2", argv[0]);
return -1;
}
}
2 changes: 1 addition & 1 deletion src/tools/map_extract.cpp
Expand Up @@ -9,7 +9,7 @@ bool Process(IStorage *pStorage, const char *pMapName, const char *pPathSave)
{
CDataFileReader Map;

if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ALL))
if(!Map.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
{
dbg_msg("map_extract", "error opening map '%s'", pMapName);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/map_resave.cpp
Expand Up @@ -18,7 +18,7 @@ int main(int argc, const char **argv)

str_format(aFileName, sizeof(aFileName), "%s", argv[2]);

if(!DataFile.Open(pStorage, argv[1], IStorage::TYPE_ALL))
if(!DataFile.Open(pStorage, argv[1], IStorage::TYPE_ABSOLUTE))
return -1;
if(!df.Open(pStorage, aFileName))
return -1;
Expand Down