diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 22:59:27 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-05-25 22:59:27 -0300 |
| commit | c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76 (patch) | |
| tree | 289089acc4aa6e6228bf8bf207db50ddaf481d90 /src/common.hh | |
| parent | ad8213f35523cbb07f418ae275af448a47cc0288 (diff) | |
| download | game-c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76.tar.gz game-c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76.zip | |
impl a couple more `util.cc` functions
Diffstat (limited to 'src/common.hh')
| -rw-r--r-- | src/common.hh | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common.hh b/src/common.hh index e113e41..58a28c3 100644 --- a/src/common.hh +++ b/src/common.hh @@ -134,6 +134,8 @@ void SetErrorFunction(TErrorFunction *Function); void SetPrintFunction(TPrintFunction *Function); void error(const char *Text, ...) ATTR_PRINTF(1, 2); void print(int Level, const char *Text, ...) ATTR_PRINTF(2, 3); +int random(int Min, int Max); +bool FileExists(const char *FileName); bool isSpace(int c); bool isAlpha(int c); @@ -147,6 +149,22 @@ int stricmp(const char *s1, const char *s2, int Max = INT_MAX); char *findFirst(char *s, char c); char *findLast(char *s, char c); +template<typename T> +void RandomShuffle(T *Buffer, int Size){ + if(Buffer == NULL){ + error("RandomShuffle: Buffer ist NULL.\n"); + return; + } + + int Max = Size - 1; + for(int Min = 0; Min < Max; Min += 1){ + int Swap = random(Min, Max); + if(Swap != Min){ + std::swap(Buffer[Min], Buffer[Swap]); + } + } +} + struct TReadStream { // VIRTUAL FUNCTIONS // ========================================================================= |
