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

util.cpp File Reference
#include <random>
#include "stratagus.h"
#include "util.h"
#include "SDL.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <malloc.h>
#include <windows.h>
#include <intrin.h>
#include "st_backtrace.h"
#include <string.h>

util.cpp - General utilites.

unsigned SyncRandSeed
 
uint32_t FileChecksums = 0
 sync random seed value. More...
 
static std::random_device dev
 
int opterr = 1
 
int optind = 1
 
int optopt
 
char * optarg
 
void InitSyncRand ()
 checksums of all loaded lua files More...
 
int SyncRand ()
 Initialize the syncron rand. More...
 
int SyncRand (int max)
 Syncron rand. More...
 
static std::mt19937 rng_engine (dev())
 
static std::uniform_int_distribution< std::mt19937::result_type > rng_dist (0, RAND_MAX)
 
int MyRand ()
 Syncron rand. More...
 
long isqrt (long num)
 Compute a square root using ints. More...
 
uint32_t fletcher32 (const std::string &content)
 
errno_t strcpy_s (char *dst, size_t dstsize, const char *src)
 
size_t strnlen (const char *str, size_t strsize)
 determine length of a fixed-length string More...
 
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 *a, const char *b)
 case insensitive strstr More...
 
static void getopt_err (const char *argv0, const char *str, char opt)
 
int getopt (int argc, char *const *argv, const char *opts)
 
int GetClipboard (std::string &str)
 
void SetClipboard (std::string &str)
 
int UTF8GetPrev (const std::string &text, int curpos)
 
int UTF8GetNext (const std::string &text, int curpos)
 
void PrintLocation (const char *file, int line, const char *funcName)
 
void AbortAt (const char *file, int line, const char *funcName, const char *conditionStr)
 
void PrintOnStdOut (const char *format,...)
 
bool supportsSSE2 ()
 
bool supportsAVX ()
 
voidaligned_malloc (size_t alignment, size_t size)
 
void aligned_free (void *block)
 

Function Documentation

◆ AbortAt()

void AbortAt ( const char *  file,
int  line,
const char *  funcName,
const char *  conditionStr 
)

◆ aligned_free()

void aligned_free ( void block)

◆ aligned_malloc()

void* aligned_malloc ( size_t  alignment,
size_t  size 
)

◆ 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 *  opts 
)

◆ getopt_err()

static void getopt_err ( const char *  argv0,
const char *  str,
char  opt 
)
static

◆ 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.

◆ PrintLocation()

void PrintLocation ( const char *  file,
int  line,
const char *  funcName 
)

◆ PrintOnStdOut()

void PrintOnStdOut ( const char *  format,
  ... 
)

◆ rng_dist()

static std::uniform_int_distribution<std::mt19937::result_type> rng_dist ( ,
RAND_MAX   
)
static

◆ rng_engine()

static std::mt19937 rng_engine ( dev()  )
static

◆ SetClipboard()

void SetClipboard ( std::string &  str)

◆ 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

◆ dev

std::random_device dev
static

◆ FileChecksums

uint32_t FileChecksums = 0

sync random seed value.

Sync random seed value.

◆ optarg

char* optarg

◆ opterr

int opterr = 1

Standard implementation of getopt(3).

One extension: If the first character of the optionsstring is a ':' the error return for 'argument required' is a ':' not a '?'. This makes it easier to differentiate between an 'illegal option' and an 'argument required' error.

◆ optind

int optind = 1

◆ 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.