_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

util.h File Reference
#include <cstdlib>
#include <cstdint>
#include <string>
#include <cmath>
#include <string.h>

Go to the source code of this file.

util.h - General utilities.

#define _TRUNCATE   ((size_t)-1)
 
typedef int errno_t
 
unsigned SyncRandSeed
 
uint32_t FileChecksums
 Sync random seed value. More...
 
char * optarg
 
int optind
 
int opterr
 
int optopt
 
void InitSyncRand ()
 checksums of all loaded lua files More...
 
int SyncRand ()
 Initialize the syncron rand. More...
 
int SyncRand (int max)
 Syncron rand. More...
 
int MyRand ()
 Syncron rand. More...
 
long isqrt (long num)
 Compute a square root using ints. More...
 
int square (int v)
 
template<typename T >
void clamp (T *value, T minValue, T maxValue)
 
uint32_t fletcher32 (const std::string &content)
 
errno_t strcpy_s (char *dst, size_t dstsize, const char *src)
 
errno_t strncpy_s (char *dst, size_t dstsize, const char *src, size_t count)
 
errno_t strcat_s (char *dst, size_t dstsize, const char *src)
 
char * strcasestr (const char *str, const char *substr)
 case insensitive strstr More...
 
size_t strnlen (const char *str, size_t strsize)
 determine length of a fixed-length string More...
 
int getopt (int argc, char *const argv[], const char *optstring)
 
int GetClipboard (std::string &str)
 
void SetClipboard (std::string &str)
 
int UTF8GetNext (const std::string &text, int curpos)
 
int UTF8GetPrev (const std::string &text, int curpos)
 
bool supportsSSE2 ()
 
bool supportsAVX ()
 
voidaligned_malloc (size_t alignment, size_t size)
 
void aligned_free (void *block)
 

Macro Definition Documentation

◆ _TRUNCATE

#define _TRUNCATE   ((size_t)-1)

Typedef Documentation

◆ errno_t

typedef int errno_t

Function Documentation

◆ aligned_free()

void aligned_free ( void block)

◆ aligned_malloc()

void* aligned_malloc ( size_t  alignment,
size_t  size 
)

◆ clamp()

template<typename T >
void clamp ( T *  value,
minValue,
maxValue 
)

◆ fletcher32()

uint32_t fletcher32 ( const std::string &  content)

◆ GetClipboard()

int GetClipboard ( std::string &  str)

Paste text from the clipboard

◆ getopt()

int getopt ( int  argc,
char *const  argv[],
const char *  optstring 
)

◆ InitSyncRand()

void InitSyncRand ( )

checksums of all loaded lua files

Inititalize sync rand seed.

◆ isqrt()

long isqrt ( long  num)

Compute a square root using ints.

Compute a square root using ints

Uses John Halleck's method, see http://www.cc.utah.edu/~nahaj/factoring/isqrt.legalize.c.html

Parameters
numCalculate the square root of this number
Returns
The integer square root.

◆ MyRand()

int MyRand ( )

Syncron rand.

rand only used on this computer.

◆ SetClipboard()

void SetClipboard ( std::string &  str)

◆ square()

int square ( int  v)
inline

◆ strcasestr()

char* strcasestr ( const char *  a,
const char *  b 
)

case insensitive strstr

Case insensitive version of strstr

Parameters
aString to search in
bSubstring to search for
Returns
Pointer to first occurrence of b or NULL if not found.

◆ strcat_s()

errno_t strcat_s ( char *  dst,
size_t  dstsize,
const char *  src 
)

◆ strcpy_s()

errno_t strcpy_s ( char *  dst,
size_t  dstsize,
const char *  src 
)

◆ strncpy_s()

errno_t strncpy_s ( char *  dst,
size_t  dstsize,
const char *  src,
size_t  count 
)

◆ strnlen()

size_t strnlen ( const char *  str,
size_t  strsize 
)

determine length of a fixed-length string

◆ supportsAVX()

bool supportsAVX ( )

◆ supportsSSE2()

bool supportsSSE2 ( )

◆ SyncRand() [1/2]

int SyncRand ( )

Initialize the syncron rand.

Synchronized random number.

Note
This random value must be same on all machines in network game. Very simple random generations, enough for us.

◆ SyncRand() [2/2]

int SyncRand ( int  max)

Syncron rand.

Synchronized random number.

Parameters
maxMax value of random number to return

◆ UTF8GetNext()

int UTF8GetNext ( const std::string &  text,
int  curpos 
)

◆ UTF8GetPrev()

int UTF8GetPrev ( const std::string &  text,
int  curpos 
)

Variable Documentation

◆ FileChecksums

uint32_t FileChecksums

Sync random seed value.

Sync random seed value.

◆ optarg

char* optarg

◆ opterr

int opterr

◆ optind

int optind

◆ optopt

int optopt

◆ SyncRandSeed

unsigned SyncRandSeed
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.