Moved old TeeWorlds to different folder
This commit is contained in:
134
project/jni/application/teeworlds-0.5.2/src/base/detect.h
Normal file
134
project/jni/application/teeworlds-0.5.2/src/base/detect.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
||||
#ifndef BASELIB_FILE_CONFIG_H
|
||||
#define BASELIB_FILE_CONFIG_H
|
||||
|
||||
/*
|
||||
this file detected the family, platform and architecture
|
||||
to compile for.
|
||||
*/
|
||||
|
||||
/* platforms */
|
||||
|
||||
/* windows Family */
|
||||
#if defined(WIN64) || defined(_WIN64)
|
||||
/* Hmm, is this IA64 or x86-64? */
|
||||
#define CONF_FAMILY_WINDOWS 1
|
||||
#define CONF_FAMILY_STRING "windows"
|
||||
#define CONF_PLATFORM_WIN64 1
|
||||
#define CONF_PLATFORM_STRING "win64"
|
||||
#elif defined(WIN32) || defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
|
||||
#define CONF_FAMILY_WINDOWS 1
|
||||
#define CONF_FAMILY_STRING "windows"
|
||||
#define CONF_PLATFORM_WIN32 1
|
||||
#define CONF_PLATFORM_STRING "win32"
|
||||
#endif
|
||||
|
||||
/* unix family */
|
||||
#if defined(__FreeBSD__)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFORM_FREEBSD 1
|
||||
#define CONF_PLATFORM_STRING "freebsd"
|
||||
#endif
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFORM_OPENBSD 1
|
||||
#define CONF_PLATFORM_STRING "openbsd"
|
||||
#endif
|
||||
|
||||
#if defined(__LINUX__) || defined(__linux__)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFORM_LINUX 1
|
||||
#define CONF_PLATFORM_STRING "linux"
|
||||
#endif
|
||||
|
||||
#if defined(MACOSX) || defined(__APPLE__) || defined(__DARWIN__)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFORM_MACOSX 1
|
||||
#define CONF_PLATFORM_STRING "macosx"
|
||||
#endif
|
||||
|
||||
#if defined(__sun)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFROM_SOLARIS 1
|
||||
#define CONF_PLATFORM_STRING "solaris"
|
||||
#endif
|
||||
|
||||
/* beos family */
|
||||
#if defined(__BeOS) || defined(__BEOS__)
|
||||
#define CONF_FAMILY_BEOS 1
|
||||
#define CONF_FAMILY_STRING "beos"
|
||||
#define CONF_PLATFORM_BEOS 1
|
||||
#define CONF_PLATFORM_STRING "beos"
|
||||
#endif
|
||||
|
||||
#if defined(ANDROID)
|
||||
#define CONF_FAMILY_UNIX 1
|
||||
#define CONF_FAMILY_STRING "unix"
|
||||
#define CONF_PLATFORM_LINUX 1
|
||||
#define CONF_PLATFORM_STRING "android"
|
||||
#endif
|
||||
|
||||
|
||||
/* architectures */
|
||||
#if defined(i386) || defined(__i386__) || defined(__x86__) || defined(CONF_PLATFORM_WIN32)
|
||||
#define CONF_ARCH_IA32 1
|
||||
#define CONF_ARCH_STRING "ia32"
|
||||
#define CONF_ARCH_ENDIAN_LITTLE 1
|
||||
#endif
|
||||
|
||||
#if defined(__ia64__)
|
||||
#define CONF_ARCH_IA64 1
|
||||
#define CONF_ARCH_STRING "ia64"
|
||||
#define CONF_ARCH_ENDIAN_LITTLE 1
|
||||
#endif
|
||||
|
||||
#if defined(__amd64__) || defined(__x86_64__)
|
||||
#define CONF_ARCH_AMD64 1
|
||||
#define CONF_ARCH_STRING "amd64"
|
||||
#define CONF_ARCH_ENDIAN_LITTLE 1
|
||||
#endif
|
||||
|
||||
#if defined(__powerpc__) || defined(__ppc__)
|
||||
#define CONF_ARCH_PPC 1
|
||||
#define CONF_ARCH_STRING "ppc"
|
||||
#define CONF_ARCH_ENDIAN_BIG 1
|
||||
#endif
|
||||
|
||||
#if defined(__sparc__)
|
||||
#define CONF_ARCH_SPARC 1
|
||||
#define CONF_ARCH_STRING "sparc"
|
||||
#define CONF_ARCH_ENDIAN_BIG 1
|
||||
#endif
|
||||
|
||||
#if defined(__ARMEB__)
|
||||
#define CONF_ARCH_ARM 1
|
||||
#define CONF_ARCH_STRING "arm"
|
||||
#define CONF_ARCH_ENDIAN_BIG 1
|
||||
#endif
|
||||
|
||||
#if defined(__ARMEL__)
|
||||
#define CONF_ARCH_ARM 1
|
||||
#define CONF_ARCH_STRING "arm"
|
||||
#define CONF_ARCH_ENDIAN_LITTLE 1
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef CONF_FAMILY_STRING
|
||||
#define CONF_FAMILY_STRING "unknown"
|
||||
#endif
|
||||
|
||||
#ifndef CONF_PLATFORM_STRING
|
||||
#define CONF_PLATFORM_STRING "unknown"
|
||||
#endif
|
||||
|
||||
#ifndef CONF_ARCH_STRING
|
||||
#define CONF_ARCH_STRING "unknown"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
68
project/jni/application/teeworlds-0.5.2/src/base/math.hpp
Normal file
68
project/jni/application/teeworlds-0.5.2/src/base/math.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
||||
#ifndef BASE_MATH_H
|
||||
#define BASE_MATH_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
template <typename T>
|
||||
inline T clamp(T val, T min, T max)
|
||||
{
|
||||
if(val < min)
|
||||
return min;
|
||||
if(val > max)
|
||||
return max;
|
||||
return val;
|
||||
}
|
||||
|
||||
inline float sign(float f)
|
||||
{
|
||||
return f<0.0f?-1.0f:1.0f;
|
||||
}
|
||||
|
||||
inline int round(float f)
|
||||
{
|
||||
if(f > 0)
|
||||
return (int)(f+0.5f);
|
||||
return (int)(f-0.5f);
|
||||
}
|
||||
|
||||
template<typename T, typename TB>
|
||||
inline T mix(const T a, const T b, TB amount)
|
||||
{
|
||||
return a + (b-a)*amount;
|
||||
}
|
||||
|
||||
inline float frandom() { return rand()/(float)(RAND_MAX); }
|
||||
|
||||
// float to fixed
|
||||
inline int f2fx(float v) { return (int)(v*(float)(1<<10)); }
|
||||
inline float fx2f(int v) { return v*(1.0f/(1<<10)); }
|
||||
|
||||
class fxp
|
||||
{
|
||||
int value;
|
||||
public:
|
||||
void set(int v) { value = v; }
|
||||
int get() const { return value; }
|
||||
fxp &operator = (int v) { value = v<<10; return *this; }
|
||||
fxp &operator = (float v) { value = (int)(v*(float)(1<<10)); return *this; }
|
||||
operator float() const { return value/(float)(1<<10); }
|
||||
};
|
||||
|
||||
class tune_param
|
||||
{
|
||||
int value;
|
||||
public:
|
||||
void set(int v) { value = v; }
|
||||
int get() const { return value; }
|
||||
tune_param &operator = (int v) { value = (int)(v*100.0f); return *this; }
|
||||
tune_param &operator = (float v) { value = (int)(v*100.0f); return *this; }
|
||||
operator float() const { return value/100.0f; }
|
||||
};
|
||||
|
||||
const float pi = 3.1415926535897932384626433f;
|
||||
|
||||
template <typename T> inline T min(T a, T b) { return a<b?a:b; }
|
||||
template <typename T> inline T max(T a, T b) { return a>b?a:b; }
|
||||
|
||||
#endif // BASE_MATH_H
|
||||
1200
project/jni/application/teeworlds-0.5.2/src/base/system.cpp
Normal file
1200
project/jni/application/teeworlds-0.5.2/src/base/system.cpp
Normal file
File diff suppressed because it is too large
Load Diff
954
project/jni/application/teeworlds-0.5.2/src/base/system.h
Normal file
954
project/jni/application/teeworlds-0.5.2/src/base/system.h
Normal file
@@ -0,0 +1,954 @@
|
||||
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
||||
|
||||
/*
|
||||
Title: OS Abstraction
|
||||
*/
|
||||
|
||||
#ifndef BASE_SYSTEM_H
|
||||
#define BASE_SYSTEM_H
|
||||
|
||||
#include "detect.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Group: Debug */
|
||||
/*
|
||||
Function: dbg_assert
|
||||
Breaks into the debugger based on a test.
|
||||
|
||||
Parameters:
|
||||
test - Result of the test.
|
||||
msg - Message that should be printed if the test fails.
|
||||
|
||||
Remarks:
|
||||
Does nothing in release version of the library.
|
||||
|
||||
See Also:
|
||||
<dbg_break>
|
||||
*/
|
||||
void dbg_assert(int test, const char *msg);
|
||||
#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
|
||||
void dbg_assert_imp(const char *filename, int line, int test, const char *msg);
|
||||
|
||||
/*
|
||||
Function: dbg_break
|
||||
Breaks into the debugger.
|
||||
|
||||
Remarks:
|
||||
Does nothing in release version of the library.
|
||||
|
||||
See Also:
|
||||
<dbg_assert>
|
||||
*/
|
||||
void dbg_break();
|
||||
|
||||
/*
|
||||
Function: dbg_msg
|
||||
|
||||
Prints a debug message.
|
||||
|
||||
Parameters:
|
||||
sys - A string that describes what system the message belongs to
|
||||
fmt - A printf styled format string.
|
||||
|
||||
Remarks:
|
||||
Does nothing in relase version of the library.
|
||||
|
||||
See Also:
|
||||
<dbg_assert>
|
||||
*/
|
||||
void dbg_msg(const char *sys, const char *fmt, ...);
|
||||
|
||||
/* Group: Memory */
|
||||
|
||||
/*
|
||||
Function: mem_alloc
|
||||
Allocates memory.
|
||||
|
||||
Parameters:
|
||||
size - Size of the needed block.
|
||||
alignment - Alignment for the block.
|
||||
|
||||
Returns:
|
||||
Returns a pointer to the newly allocated block. Returns a
|
||||
null pointer if the memory couldn't be allocated.
|
||||
|
||||
Remarks:
|
||||
- Passing 0 to size will allocated the smallest amount possible
|
||||
and return a unique pointer.
|
||||
|
||||
See Also:
|
||||
<mem_free>
|
||||
*/
|
||||
void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment);
|
||||
#define mem_alloc(s,a) mem_alloc_debug(__FILE__, __LINE__, (s), (a))
|
||||
|
||||
/*
|
||||
Function: mem_free
|
||||
Frees a block allocated through <mem_alloc>.
|
||||
|
||||
Remarks:
|
||||
- In the debug version of the library the function will assert if
|
||||
a non-valid block is passed, like a null pointer or a block that
|
||||
isn't allocated.
|
||||
|
||||
See Also:
|
||||
<mem_alloc>
|
||||
*/
|
||||
void mem_free(void *block);
|
||||
|
||||
/*
|
||||
Function: mem_copy
|
||||
Copies a a memory block.
|
||||
|
||||
Parameters:
|
||||
dest - Destination.
|
||||
source - Source to copy.
|
||||
size - Size of the block to copy.
|
||||
|
||||
Remarks:
|
||||
- This functions DOES NOT handles cases where source and
|
||||
destination is overlapping.
|
||||
|
||||
See Also:
|
||||
<mem_move>
|
||||
*/
|
||||
void mem_copy(void *dest, const void *source, unsigned size);
|
||||
|
||||
/*
|
||||
Function: mem_move
|
||||
Copies a a memory block
|
||||
|
||||
Parameters:
|
||||
dest - Destination
|
||||
source - Source to copy
|
||||
size - Size of the block to copy
|
||||
|
||||
Remarks:
|
||||
- This functions handles cases where source and destination
|
||||
is overlapping
|
||||
|
||||
See Also:
|
||||
<mem_copy>
|
||||
*/
|
||||
void mem_move(void *dest, const void *source, unsigned size);
|
||||
|
||||
/*
|
||||
Function: mem_zero
|
||||
Sets a complete memory block to 0
|
||||
|
||||
Parameters:
|
||||
block - Pointer to the block to zero out
|
||||
size - Size of the block
|
||||
*/
|
||||
void mem_zero(void *block, unsigned size);
|
||||
|
||||
/*
|
||||
Function: mem_comp
|
||||
Compares two blocks of memory
|
||||
|
||||
Parameters:
|
||||
a - First block of data
|
||||
b - Second block of data
|
||||
size - Size of the data to compare
|
||||
|
||||
Returns:
|
||||
<0 - Block a is lesser then block b
|
||||
0 - Block a is equal to block b
|
||||
>0 - Block a is greater then block b
|
||||
*/
|
||||
int mem_comp(const void *a, const void *b, int size);
|
||||
|
||||
/*
|
||||
Function: mem_check
|
||||
Validates the heap
|
||||
Will trigger a assert if memory has failed.
|
||||
*/
|
||||
int mem_check_imp();
|
||||
#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed")
|
||||
|
||||
/* Group: File IO */
|
||||
enum {
|
||||
IOFLAG_READ = 1,
|
||||
IOFLAG_WRITE = 2,
|
||||
IOFLAG_RANDOM = 4,
|
||||
|
||||
IOSEEK_START = 0,
|
||||
IOSEEK_CUR = 1,
|
||||
IOSEEK_END = 2
|
||||
};
|
||||
|
||||
typedef struct IOINTERNAL *IOHANDLE;
|
||||
|
||||
/*
|
||||
Function: io_open
|
||||
Opens a file.
|
||||
|
||||
Parameters:
|
||||
filename - File to open.
|
||||
flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM.
|
||||
|
||||
Returns:
|
||||
Returns a handle to the file on success and 0 on failure.
|
||||
|
||||
*/
|
||||
IOHANDLE io_open(const char *filename, int flags);
|
||||
|
||||
/*
|
||||
Function: io_read
|
||||
Reads data into a buffer from a file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file to read data from.
|
||||
buffer - Pointer to the buffer that will recive the data.
|
||||
size - Number of bytes to read from the file.
|
||||
|
||||
Returns:
|
||||
Number of bytes read.
|
||||
|
||||
*/
|
||||
unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
|
||||
|
||||
/*
|
||||
Function: io_skip
|
||||
Skips data in a file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
size - Number of bytes to skip.
|
||||
|
||||
Returns:
|
||||
Number of bytes skipped.
|
||||
*/
|
||||
unsigned io_skip(IOHANDLE io, unsigned size);
|
||||
|
||||
/*
|
||||
Function: io_write
|
||||
Writes data from a buffer to file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
buffer - Pointer to the data that should be written.
|
||||
size - Number of bytes to write.
|
||||
|
||||
Returns:
|
||||
Number of bytes written.
|
||||
*/
|
||||
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
|
||||
|
||||
/*
|
||||
Function: io_seek
|
||||
Seeks to a specified offset in the file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
offset - Offset from pos to stop.
|
||||
origin - Position to start searching from.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
int io_seek(IOHANDLE io, int offset, int origin);
|
||||
|
||||
/*
|
||||
Function: io_tell
|
||||
Gets the current position in the file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
Returns:
|
||||
Returns the current position. -1L if an error occured.
|
||||
*/
|
||||
long int io_tell(IOHANDLE io);
|
||||
|
||||
/*
|
||||
Function: io_length
|
||||
Gets the total length of the file. Resetting cursor to the beginning
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
Returns:
|
||||
Returns the total size. -1L if an error occured.
|
||||
*/
|
||||
long int io_length(IOHANDLE io);
|
||||
|
||||
/*
|
||||
Function: io_close
|
||||
Closes a file.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
int io_close(IOHANDLE io);
|
||||
|
||||
/*
|
||||
Function: io_flush
|
||||
Empties all buffers and writes all pending data.
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
int io_flush(IOHANDLE io);
|
||||
|
||||
|
||||
/*
|
||||
Function: io_stdin
|
||||
Returns an <IOHANDLE> to the standard input.
|
||||
*/
|
||||
IOHANDLE io_stdin();
|
||||
|
||||
/*
|
||||
Function: io_stdout
|
||||
Returns an <IOHANDLE> to the standard output.
|
||||
*/
|
||||
IOHANDLE io_stdout();
|
||||
|
||||
/*
|
||||
Function: io_stderr
|
||||
Returns an <IOHANDLE> to the standard error.
|
||||
*/
|
||||
IOHANDLE io_stderr();
|
||||
|
||||
|
||||
/* Group: Threads */
|
||||
|
||||
/*
|
||||
Function: thread_sleep
|
||||
Suspends the current thread for a given period.
|
||||
|
||||
Parameters:
|
||||
milliseconds - Number of milliseconds to sleep.
|
||||
*/
|
||||
void thread_sleep(int milliseconds);
|
||||
|
||||
/*
|
||||
Function: thread_create
|
||||
Creates a new thread.
|
||||
|
||||
Parameters:
|
||||
threadfunc - Entry point for the new thread.
|
||||
user - Pointer to pass to the thread.
|
||||
|
||||
*/
|
||||
void *thread_create(void (*threadfunc)(void *), void *user);
|
||||
|
||||
/*
|
||||
Function: thread_wait
|
||||
Waits for a thread to be done or destroyed.
|
||||
|
||||
Parameters:
|
||||
thread - Thread to wait for.
|
||||
*/
|
||||
void thread_wait(void *thread);
|
||||
|
||||
/*
|
||||
Function: thread_destoy
|
||||
Destroys a thread.
|
||||
|
||||
Parameters:
|
||||
thread - Thread to destroy.
|
||||
*/
|
||||
void thread_destroy(void *thread);
|
||||
|
||||
/*
|
||||
Function: thread_yeild
|
||||
Yeild the current threads execution slice.
|
||||
*/
|
||||
void thread_yield();
|
||||
|
||||
|
||||
/* Group: Locks */
|
||||
typedef void* LOCK;
|
||||
|
||||
LOCK lock_create();
|
||||
void lock_destroy(LOCK lock);
|
||||
|
||||
int lock_try(LOCK lock);
|
||||
void lock_wait(LOCK lock);
|
||||
void lock_release(LOCK lock);
|
||||
|
||||
/* Group: Timer */
|
||||
#ifdef __GNUC__
|
||||
/* if compiled with -pedantic-errors it will complain about long
|
||||
not being a C90 thing.
|
||||
*/
|
||||
__extension__ typedef long long int64;
|
||||
#else
|
||||
typedef long long int64;
|
||||
#endif
|
||||
/*
|
||||
Function: time_get
|
||||
Fetches a sample from a high resolution timer.
|
||||
|
||||
Returns:
|
||||
Current value of the timer.
|
||||
|
||||
Remarks:
|
||||
To know how fast the timer is ticking, see <time_freq>.
|
||||
*/
|
||||
int64 time_get();
|
||||
|
||||
/*
|
||||
Function: time_freq
|
||||
Returns the frequency of the high resolution timer.
|
||||
|
||||
Returns:
|
||||
Returns the frequency of the high resolution timer.
|
||||
*/
|
||||
int64 time_freq();
|
||||
|
||||
/*
|
||||
Function: time_timestamp
|
||||
Retrives the current time as a UNIX timestamp
|
||||
|
||||
Returns:
|
||||
The time as a UNIX timestamp
|
||||
*/
|
||||
unsigned time_timestamp();
|
||||
|
||||
/* Group: Network General */
|
||||
typedef int NETSOCKET;
|
||||
enum
|
||||
{
|
||||
NETSOCKET_INVALID = -1,
|
||||
|
||||
NETTYPE_INVALID = 0,
|
||||
NETTYPE_IPV4 = 1,
|
||||
NETTYPE_IPV6 = 2,
|
||||
NETTYPE_ALL = ~0
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned char ip[16];
|
||||
unsigned short port;
|
||||
} NETADDR;
|
||||
|
||||
/*
|
||||
Function: net_init
|
||||
Initiates network functionallity.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success,
|
||||
|
||||
Remarks:
|
||||
You must call this function before using any other network
|
||||
functions.
|
||||
*/
|
||||
int net_init();
|
||||
|
||||
/*
|
||||
Function: net_host_lookup
|
||||
Does a hostname lookup by name and fills out the passed
|
||||
NETADDR struct with the recieved details.
|
||||
|
||||
Returns:
|
||||
0 on success.
|
||||
*/
|
||||
int net_host_lookup(const char *hostname, NETADDR *addr, int types);
|
||||
|
||||
/*
|
||||
Function: net_addr_comp
|
||||
Compares two network addresses.
|
||||
|
||||
Parameters:
|
||||
a - Address to compare
|
||||
b - Address to compare to.
|
||||
|
||||
Returns:
|
||||
<0 - Address a is lesser then address b
|
||||
0 - Address a is equal to address b
|
||||
>0 - Address a is greater then address b
|
||||
*/
|
||||
int net_addr_comp(const NETADDR *a, const NETADDR *b);
|
||||
|
||||
/*
|
||||
Function: net_addr_str
|
||||
Turns a network address into a representive string.
|
||||
|
||||
Parameters:
|
||||
addr - Address to turn into a string.
|
||||
string - Buffer to fill with the string.
|
||||
max_length - Maximum size of the string.
|
||||
|
||||
Remarks:
|
||||
- The string will always be zero terminated
|
||||
|
||||
*/
|
||||
void net_addr_str(const NETADDR *addr, char *string, int max_length);
|
||||
|
||||
/*
|
||||
Function: net_addr_from_str
|
||||
Turns string into a network address.
|
||||
|
||||
Returns:
|
||||
0 on success
|
||||
|
||||
Parameters:
|
||||
addr - Address to fill in.
|
||||
string - String to parse.
|
||||
*/
|
||||
int net_addr_from_str(NETADDR *addr, const char *string);
|
||||
|
||||
/* Group: Network UDP */
|
||||
|
||||
/*
|
||||
Function: net_udp_create
|
||||
Creates a UDP socket and binds it to a port.
|
||||
|
||||
Parameters:
|
||||
bindaddr - Address to bind the socket to.
|
||||
|
||||
Returns:
|
||||
On success it returns an handle to the socket. On failure it
|
||||
returns NETSOCKET_INVALID.
|
||||
*/
|
||||
NETSOCKET net_udp_create(NETADDR bindaddr);
|
||||
|
||||
/*
|
||||
Function: net_udp_send
|
||||
Sends a packet over an UDP socket.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to use.
|
||||
addr - Where to send the packet.
|
||||
data - Pointer to the packet data to send.
|
||||
size - Size of the packet.
|
||||
|
||||
Returns:
|
||||
On success it returns the number of bytes sent. Returns -1
|
||||
on error.
|
||||
*/
|
||||
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
|
||||
|
||||
/*
|
||||
Function: net_udp_recv
|
||||
Recives a packet over an UDP socket.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to use.
|
||||
addr - Pointer to an NETADDR that will recive the address.
|
||||
data - Pointer to a buffer that will recive the data.
|
||||
maxsize - Maximum size to recive.
|
||||
|
||||
Returns:
|
||||
On success it returns the number of bytes recived. Returns -1
|
||||
on error.
|
||||
*/
|
||||
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize);
|
||||
|
||||
/*
|
||||
Function: net_udp_close
|
||||
Closes an UDP socket.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to close.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. -1 on error.
|
||||
*/
|
||||
int net_udp_close(NETSOCKET sock);
|
||||
|
||||
|
||||
/* Group: Network TCP */
|
||||
|
||||
/*
|
||||
Function: net_tcp_create
|
||||
Creates a TCP socket.
|
||||
|
||||
Parameters:
|
||||
bindaddr - Address to bind the socket to.
|
||||
|
||||
Returns:
|
||||
On success it returns an handle to the socket. On failure it returns NETSOCKET_INVALID.
|
||||
*/
|
||||
NETSOCKET net_tcp_create(const NETADDR *a);
|
||||
|
||||
/*
|
||||
Function: net_tcp_listen
|
||||
Makes the socket start listening for new connections.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to start listen to.
|
||||
backlog - Size of the queue of incomming connections to keep.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
int net_tcp_listen(NETSOCKET sock, int backlog);
|
||||
|
||||
/*
|
||||
Function: net_tcp_accept
|
||||
Polls a listning socket for a new connection.
|
||||
|
||||
Parameters:
|
||||
sock - Listning socket to poll.
|
||||
new_sock - Pointer to a socket to fill in with the new socket.
|
||||
addr - Pointer to an address that will be filled in the remote address (optional, can be NULL).
|
||||
|
||||
Returns:
|
||||
Returns a non-negative integer on success. Negative integer on failure.
|
||||
*/
|
||||
int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
|
||||
|
||||
/*
|
||||
Function: net_tcp_connect
|
||||
Connects one socket to another.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to connect.
|
||||
addr - Address to connect to.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
|
||||
*/
|
||||
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
|
||||
|
||||
/*
|
||||
Function: net_tcp_send
|
||||
Sends data to a TCP stream.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to send data to.
|
||||
data - Pointer to the data to send.
|
||||
size - Size of the data to send.
|
||||
|
||||
Returns:
|
||||
Number of bytes sent. Negative value on failure.
|
||||
*/
|
||||
int net_tcp_send(NETSOCKET sock, const void *data, int size);
|
||||
|
||||
/*
|
||||
Function: net_tcp_recv
|
||||
Recvives data from a TCP stream.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to recvive data from.
|
||||
data - Pointer to a buffer to write the data to
|
||||
max_size - Maximum of data to write to the buffer.
|
||||
|
||||
Returns:
|
||||
Number of bytes recvived. Negative value on failure. When in
|
||||
non-blocking mode, it returns 0 when there is no more data to
|
||||
be fetched.
|
||||
*/
|
||||
int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
|
||||
|
||||
/*
|
||||
Function: net_tcp_close
|
||||
Closes a TCP socket.
|
||||
|
||||
Parameters:
|
||||
sock - Socket to close.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
*/
|
||||
int net_tcp_close(NETSOCKET sock);
|
||||
|
||||
/* Group: Strings */
|
||||
|
||||
/*
|
||||
Function: str_append
|
||||
Appends a string to another.
|
||||
|
||||
Parameters:
|
||||
dst - Pointer to a buffer that contains a string.
|
||||
src - String to append.
|
||||
dst_size - Size of the buffer of the dst string.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-termineted strings.
|
||||
- Garantees that dst string will contain zero-termination.
|
||||
*/
|
||||
void str_append(char *dst, const char *src, int dst_size);
|
||||
|
||||
/*
|
||||
Function: str_copy
|
||||
Copies a string to another.
|
||||
|
||||
Parameters:
|
||||
dst - Pointer to a buffer that shall recive the string.
|
||||
src - String to be copied.
|
||||
dst_size - Size of the buffer dst.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-termineted strings.
|
||||
- Garantees that dst string will contain zero-termination.
|
||||
*/
|
||||
void str_copy(char *dst, const char *src, int dst_size);
|
||||
|
||||
/*
|
||||
Function: str_length
|
||||
Returns the length of a zero terminated string.
|
||||
|
||||
Parameters:
|
||||
str - Pointer to the string.
|
||||
|
||||
Returns:
|
||||
Length of string in bytes excluding the zero termination.
|
||||
*/
|
||||
int str_length(const char *str);
|
||||
|
||||
/*
|
||||
Function: str_format
|
||||
Performs printf formating into a buffer.
|
||||
|
||||
Parameters:
|
||||
buffer - Pointer to the buffer to recive the formated string.
|
||||
buffer_size - Size of the buffer.
|
||||
format - printf formating string.
|
||||
... - Parameters for the formating.
|
||||
|
||||
Remarks:
|
||||
- See the C manual for syntax for the printf formating string.
|
||||
- The strings are treated as zero-termineted strings.
|
||||
- Garantees that dst string will contain zero-termination.
|
||||
*/
|
||||
void str_format(char *buffer, int buffer_size, const char *format, ...);
|
||||
|
||||
/*
|
||||
Function: str_sanitize_strong
|
||||
Replaces all characters below 32 and above 127 with whitespace.
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-termineted strings.
|
||||
*/
|
||||
void str_sanitize_strong(char *str);
|
||||
|
||||
/*
|
||||
Function: str_sanitize
|
||||
Replaces all characters below 32 and above 127 with whitespace with
|
||||
exception to \r, \n and \r.
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-termineted strings.
|
||||
*/
|
||||
void str_sanitize(char *str);
|
||||
|
||||
/*
|
||||
Function: str_comp_nocase
|
||||
Compares to strings case insensitive.
|
||||
|
||||
Parameters:
|
||||
a - String to compare.
|
||||
b - String to compare.
|
||||
|
||||
Returns:
|
||||
<0 - String a is lesser then string b
|
||||
0 - String a is equal to string b
|
||||
>0 - String a is greater then string b
|
||||
|
||||
Remarks:
|
||||
- Only garanted to work with a-z/A-Z.
|
||||
- The strings are treated as zero-termineted strings.
|
||||
*/
|
||||
int str_comp_nocase(const char *a, const char *b);
|
||||
|
||||
/*
|
||||
Function: str_find_nocase
|
||||
Finds a string inside another string case insensitive.
|
||||
|
||||
Parameters:
|
||||
haystack - String to search in
|
||||
needle - String to search for
|
||||
|
||||
Returns:
|
||||
A pointer into haystack where the needle was found.
|
||||
Returns NULL of needle could not be found.
|
||||
|
||||
Remarks:
|
||||
- Only garanted to work with a-z/A-Z.
|
||||
- The strings are treated as zero-termineted strings.
|
||||
*/
|
||||
const char *str_find_nocase(const char *haystack, const char *needle);
|
||||
|
||||
|
||||
/*
|
||||
Function: str_hex
|
||||
Takes a datablock and generates a hexstring of it.
|
||||
|
||||
Parameters:
|
||||
dst - Buffer to fill with hex data
|
||||
dst_size - size of the buffer
|
||||
data - Data to turn into hex
|
||||
data - Size of the data
|
||||
|
||||
Remarks:
|
||||
- The desination buffer will be zero-terminated
|
||||
*/
|
||||
void str_hex(char *dst, int dst_size, const void *data, int data_size);
|
||||
|
||||
/* Group: Filesystem */
|
||||
|
||||
/*
|
||||
Function: fs_listdir
|
||||
Lists the files in a directory
|
||||
|
||||
Parameters:
|
||||
dir - Directory to list
|
||||
cb - Callback function to call for each entry
|
||||
user - Pointer to give to the callback
|
||||
|
||||
Returns:
|
||||
Always returns 0.
|
||||
*/
|
||||
typedef void (*FS_LISTDIR_CALLBACK)(const char *name, int is_dir, void *user);
|
||||
int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, void *user);
|
||||
|
||||
/*
|
||||
Function: fs_makedir
|
||||
Creates a directory
|
||||
|
||||
Parameters:
|
||||
path - Directory to create
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
|
||||
Remarks:
|
||||
Does not create several directories if needed. "a/b/c" will result
|
||||
in a failure if b or a does not exist.
|
||||
*/
|
||||
int fs_makedir(const char *path);
|
||||
|
||||
/*
|
||||
Function: fs_storage_path
|
||||
Fetches per user configuration directory.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
|
||||
Remarks:
|
||||
- Returns ~/.appname on UNIX based systems
|
||||
- Returns ~/Library/Applications Support/appname on Mac OS X
|
||||
- Returns %APPDATA%/Appname on Windows based systems
|
||||
*/
|
||||
int fs_storage_path(const char *appname, char *path, int max);
|
||||
|
||||
/*
|
||||
Function: fs_is_dir
|
||||
Checks if directory exists
|
||||
|
||||
Returns:
|
||||
Returns 1 on success, 0 on failure.
|
||||
*/
|
||||
int fs_is_dir(const char *path);
|
||||
|
||||
/*
|
||||
Function: fs_chdir
|
||||
Changes current working directory
|
||||
|
||||
Returns:
|
||||
Returns 0 on success, 1 on failure.
|
||||
*/
|
||||
int fs_chdir(const char *path);
|
||||
|
||||
/*
|
||||
Group: Undocumented
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Function: net_tcp_connect_non_blocking
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a);
|
||||
|
||||
/*
|
||||
Function: net_tcp_set_non_blocking
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_tcp_set_non_blocking(NETSOCKET sock);
|
||||
|
||||
/*
|
||||
Function: net_tcp_set_non_blocking
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_tcp_set_blocking(NETSOCKET sock);
|
||||
|
||||
/*
|
||||
Function: net_errno
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_errno();
|
||||
|
||||
/*
|
||||
Function: net_would_block
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_would_block();
|
||||
|
||||
int net_socket_read_wait(NETSOCKET sock, int time);
|
||||
|
||||
void mem_debug_dump();
|
||||
|
||||
void swap_endian(void *data, unsigned elem_size, unsigned num);
|
||||
|
||||
typedef void (*DBG_LOGGER)(const char *line);
|
||||
void dbg_logger(DBG_LOGGER logger);
|
||||
void dbg_logger_stdout();
|
||||
void dbg_logger_debugger();
|
||||
void dbg_logger_file(const char *filename);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int allocated;
|
||||
int active_allocations;
|
||||
int total_allocations;
|
||||
} MEMSTATS;
|
||||
|
||||
const MEMSTATS *mem_stats();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sent_packets;
|
||||
int sent_bytes;
|
||||
int recv_packets;
|
||||
int recv_bytes;
|
||||
} NETSTATS;
|
||||
|
||||
|
||||
void net_stats(NETSTATS *stats);
|
||||
|
||||
int str_isspace(char c);
|
||||
|
||||
|
||||
/*
|
||||
Function: gui_messagebox
|
||||
Display plain OS-dependent message box
|
||||
|
||||
Parameters:
|
||||
title - title of the message box
|
||||
message - text to display
|
||||
*/
|
||||
void gui_messagebox(const char *title, const char *message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
196
project/jni/application/teeworlds-0.5.2/src/base/vmath.hpp
Normal file
196
project/jni/application/teeworlds-0.5.2/src/base/vmath.hpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
||||
#ifndef BASE_VMATH_H
|
||||
#define BASE_VMATH_H
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
template<typename T>
|
||||
class vector2_base
|
||||
{
|
||||
public:
|
||||
union { T x,u; };
|
||||
union { T y,v; };
|
||||
|
||||
vector2_base() {}
|
||||
vector2_base(float nx, float ny)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
}
|
||||
|
||||
vector2_base operator -() const { return vector2_base(-x, -y); }
|
||||
vector2_base operator -(const vector2_base &v) const { return vector2_base(x-v.x, y-v.y); }
|
||||
vector2_base operator +(const vector2_base &v) const { return vector2_base(x+v.x, y+v.y); }
|
||||
vector2_base operator *(const T v) const { return vector2_base(x*v, y*v); }
|
||||
|
||||
const vector2_base &operator =(const vector2_base &v) { x = v.x; y = v.y; return *this; }
|
||||
|
||||
const vector2_base &operator +=(const vector2_base &v) { x += v.x; y += v.y; return *this; }
|
||||
const vector2_base &operator -=(const vector2_base &v) { x -= v.x; y -= v.y; return *this; }
|
||||
const vector2_base &operator *=(const T v) { x *= v; y *= v; return *this; }
|
||||
|
||||
bool operator ==(const vector2_base &v) const { return x == v.x && y == v.y; } //TODO: do this with an eps instead
|
||||
|
||||
operator const T* () { return &x; }
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline T length(const vector2_base<T> &a)
|
||||
{
|
||||
return sqrtf(a.x*a.x + a.y*a.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T distance(const vector2_base<T> a, const vector2_base<T> &b)
|
||||
{
|
||||
return length(a-b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T dot(const vector2_base<T> a, const vector2_base<T> &b)
|
||||
{
|
||||
return a.x*b.x + a.y*b.y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline vector2_base<T> normalize(const vector2_base<T> &v)
|
||||
{
|
||||
T l = (T)(1.0f/sqrtf(v.x*v.x + v.y*v.y));
|
||||
return vector2_base<T>(v.x*l, v.y*l);
|
||||
}
|
||||
|
||||
typedef vector2_base<float> vec2;
|
||||
typedef vector2_base<bool> bvec2;
|
||||
typedef vector2_base<int> ivec2;
|
||||
|
||||
template<typename T>
|
||||
inline vector2_base<T> closest_point_on_line(vector2_base<T> line_point0, vector2_base<T> line_point1, vector2_base<T> target_point)
|
||||
{
|
||||
vector2_base<T> c = target_point - line_point0;
|
||||
vector2_base<T> v = (line_point1 - line_point0);
|
||||
v = normalize(v);
|
||||
T d = length(line_point0-line_point1);
|
||||
T t = dot(v, c)/d;
|
||||
return mix(line_point0, line_point1, clamp(t, (T)0, (T)1));
|
||||
/*
|
||||
if (t < 0) t = 0;
|
||||
if (t > 1.0f) return 1.0f;
|
||||
return t;*/
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
template<typename T>
|
||||
class vector3_base
|
||||
{
|
||||
public:
|
||||
union { T x,r,h; };
|
||||
union { T y,g,s; };
|
||||
union { T z,b,v,l; };
|
||||
|
||||
vector3_base() {}
|
||||
vector3_base(float nx, float ny, float nz)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
const vector3_base &operator =(const vector3_base &v) { x = v.x; y = v.y; z = v.z; return *this; }
|
||||
|
||||
vector3_base operator -(const vector3_base &v) const { return vector3_base(x-v.x, y-v.y, z-v.z); }
|
||||
vector3_base operator -() const { return vector3_base(-x, -y, -z); }
|
||||
vector3_base operator +(const vector3_base &v) const { return vector3_base(x+v.x, y+v.y, z+v.z); }
|
||||
vector3_base operator *(const T v) const { return vector3_base(x*v, y*v, z*v); }
|
||||
vector3_base operator *(const vector3_base &v) const { return vector3_base(x*v.x, y*v.y, z*v.z); }
|
||||
vector3_base operator /(const T v) const { return vector3_base(x/v, y/v, z/v); }
|
||||
|
||||
const vector3_base &operator +=(const vector3_base &v) { x += v.x; y += v.y; z += v.z; return *this; }
|
||||
const vector3_base &operator -=(const vector3_base &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
|
||||
const vector3_base &operator *=(const T v) { x *= v; y *= v; z *= v; return *this; }
|
||||
|
||||
bool operator ==(const vector3_base &v) const { return x == v.x && y == v.y && z == v.z; } //TODO: do this with an eps instead
|
||||
|
||||
operator const T* () { return &x; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline T length(const vector3_base<T> &a)
|
||||
{
|
||||
return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T distance(const vector3_base<T> &a, const vector3_base<T> &b)
|
||||
{
|
||||
return length(a-b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T dot(const vector3_base<T> &a, const vector3_base<T> &b)
|
||||
{
|
||||
return a.x*b.x + a.y*b.y + a.z*b.z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline vector3_base<T> normalize(const vector3_base<T> &v)
|
||||
{
|
||||
T l = (T)(1.0f/sqrtf(v.x*v.x + v.y*v.y + v.z*v.z));
|
||||
return vector3_base<T>(v.x*l, v.y*l, v.z*l);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline vector3_base<T> cross(const vector3_base<T> &a, const vector3_base<T> &b)
|
||||
{
|
||||
return vector3_base<T>(
|
||||
a.y*b.z - a.z*b.y,
|
||||
a.z*b.x - a.x*b.z,
|
||||
a.x*b.y - a.y*b.x);
|
||||
}
|
||||
|
||||
typedef vector3_base<float> vec3;
|
||||
typedef vector3_base<bool> bvec3;
|
||||
typedef vector3_base<int> ivec3;
|
||||
|
||||
// ------------------------------------
|
||||
|
||||
template<typename T>
|
||||
class vector4_base
|
||||
{
|
||||
public:
|
||||
union { T x,r; };
|
||||
union { T y,g; };
|
||||
union { T z,b; };
|
||||
union { T w,a; };
|
||||
|
||||
vector4_base() {}
|
||||
vector4_base(float nx, float ny, float nz, float nw)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
w = nw;
|
||||
}
|
||||
|
||||
vector4_base operator +(const vector4_base &v) const { return vector4_base(x+v.x, y+v.y, z+v.z, w+v.w); }
|
||||
vector4_base operator -(const vector4_base &v) const { return vector4_base(x-v.x, y-v.y, z-v.z, w-v.w); }
|
||||
vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); }
|
||||
vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); }
|
||||
vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); }
|
||||
|
||||
const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; }
|
||||
|
||||
const vector4_base &operator +=(const vector4_base &v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; }
|
||||
const vector4_base &operator -=(const vector4_base &v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; }
|
||||
const vector4_base &operator *=(const T v) { x *= v; y *= v; z *= v; w *= v; return *this; }
|
||||
|
||||
bool operator ==(const vector4_base &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } //TODO: do this with an eps instead
|
||||
|
||||
operator const T* () { return &x; }
|
||||
};
|
||||
|
||||
typedef vector4_base<float> vec4;
|
||||
typedef vector4_base<bool> bvec4;
|
||||
typedef vector4_base<int> ivec4;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user