Advertisement
Kitomas

globals.cpp as of 2024-03-29

Mar 29th, 2024
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <globals.hpp>
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace kit;
  7.  
  8.  
  9.  
  10.  
  11.  
  12. TimerSimple* gl_frameTimer = nullptr;
  13. SoundEngine* gl_snd        = nullptr;
  14. Window*      gl_win        = nullptr;
  15. BitmapFont*  gl_text       = nullptr;
  16. FStr*       _gl_text_fstr  = nullptr;
  17.  
  18.  
  19.  
  20. Bitmap* gl_spritesheetPlayer = nullptr;
  21.  
  22.  
  23.  
  24.  
  25.  
  26. void handleInit(){
  27.   gl_frameTimer = new TimerSimple;
  28.   gl_frameTimer->setTimer(0.101);
  29.  
  30.  
  31.   srand((u32)time::getTicks());
  32.  
  33.  
  34.   gl_snd = new SoundEngine(96);
  35.   gl_snd->streamStart();
  36.  
  37.  
  38.  
  39.   gl_win = new Window(WINDOW_TITLE, 1280, 720,
  40.                       WINFLAG_RESIZABLE | WINFLAG_HIDDEN,
  41.                       WINPOS_CENTERED, WINPOS_CENTERED,
  42.                       CANVSIZ_X, CANVSIZ_Y, false);
  43.  
  44.  
  45.  
  46.   gl_text = new BitmapFont("dat/img/_font8x8.qoi", gl_win);
  47.  
  48.   _gl_text_fstr = new FStr(4096);
  49.  
  50.  
  51.  
  52.   gl_spritesheetPlayer = new Bitmap("dat/img/spritesheet_player.qoi", gl_win);
  53.  
  54.  
  55.  
  56.   gl_frameTimer->wait(2000);
  57.  
  58.   gl_win->setVisibility(true);
  59.   gl_win->setFocus(true);
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. void handleQuit(){
  67.   if(gl_frameTimer) gl_frameTimer->setTimer(0.015);
  68.  
  69.   if(gl_snd){
  70.     gl_snd->musicStop();
  71.     gl_snd->sfxStopAll();
  72.   }
  73.  
  74.   delete _gl_text_fstr;
  75.   delete gl_text;
  76.   delete gl_win;
  77.  
  78.  
  79.   delete gl_spritesheetPlayer;
  80.  
  81.  
  82.   if(gl_frameTimer) gl_frameTimer->wait(2000);
  83.  
  84.   delete gl_frameTimer;
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. extern int gameMain(int argc, char** argv);
  92.  
  93.  
  94.  
  95. int main(int argc, char** argv){ try {
  96.   handleInit();
  97.  
  98.   int result = gameMain(argc, argv);
  99.  
  100.   handleQuit();
  101.  
  102.   return result;
  103.  
  104.  
  105. } catch(const char* errorText){
  106. #ifdef _DEBUG
  107.   printf("FATAL EXCEPTION OCCURRED!: \"%s\"\n", errorText);
  108. #else
  109.   showMessageBox(errorText, "FATAL EXCEPTION OCCURRED! COMPLAIN TO THE DEV! (lol)", MSGBOX_ICN_ERROR);
  110. #endif /* _DEBUG */
  111.  
  112.   return -1;
  113.  
  114.  
  115. }}
  116.  
  117.  
  118.  
  119.  
  120.  
  121. f64 frand(){
  122.   u32 value = (rand()<<15) | rand();
  123.   return (f64)value/(KIT_U32_MAX>>2);
  124. }
  125.  
  126.  
  127.  
  128. f32 frandf(){
  129.   u32 value = (rand()<<15) | rand();
  130.   return (f32)value/(KIT_U32_MAX>>2);
  131. }
  132.  
  133.  
  134.  
  135.  
  136. f64 frandRange(f64 start, f64 maxDeviation){
  137.   return start + (frand()*2.0-1.0)*maxDeviation;
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement