Atlas - common.c

Home / ext / SDL2 / Xcode-iOS / Demos / src Lines: 2 | Size: 1042 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 * common.c 3 * written by Holmes Futrell 4 * use however you want 5 */ 6 7#include "common.h" 8#include "SDL.h" 9#include <stdlib.h> 10 11/* 12 Produces a random int x, min <= x <= max 13 following a uniform distribution 14*/ 15int 16randomInt(int min, int max) 17{ 18 return min + rand() % (max - min + 1); 19} 20 21/* 22 Produces a random float x, min <= x <= max 23 following a uniform distribution 24 */ 25float 26randomFloat(float min, float max) 27{ 28 return rand() / (float) RAND_MAX *(max - min) + min; 29} 30 31void 32fatalError(const char *string) 33{ 34 printf("%s: %s\n", string, SDL_GetError()); 35 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, string, SDL_GetError(), NULL); 36 exit(1); 37} 38 39static Uint64 prevTime = 0; 40 41double 42updateDeltaTime(void) 43{ 44 Uint64 curTime; 45 double deltaTime; 46 47 if (prevTime == 0) { 48 prevTime = SDL_GetPerformanceCounter(); 49 } 50 51 curTime = SDL_GetPerformanceCounter(); 52 deltaTime = (double) (curTime - prevTime) / (double) SDL_GetPerformanceFrequency(); 53 prevTime = curTime; 54 55 return deltaTime; 56} 57
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.