Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <globals.hpp>
- #include <tile.hpp>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace kit;
- TimerSimple* gl_frameTimer = nullptr;
- SoundEngine* gl_snd = nullptr;
- MutexSimple* gl_snd_lock = nullptr;
- Window* gl_win = nullptr;
- BitmapFont* gl_text = nullptr;
- FStr* gl_fstr = nullptr;
- Bitmap* gl_spritesheetPlayer = nullptr;
- u16 gl_sceneCurrent = 0;
- Scene gl_scenes[gl_scenes_len];
- Bitmap* gl_tilesets[gl_tilesets_len];
- Bitmap* gl_tileset_missing = nullptr;
- void handleInit(){
- gl_frameTimer = new TimerSimple;
- gl_frameTimer->setTimer(0.101);
- srand((u32)time::getTicks());
- gl_snd = new SoundEngine(128);
- gl_snd->streamStart();
- gl_snd_lock = new MutexSimple;
- gl_win = new Window(WINDOW_TITLE, CANVSIZ_X*2, CANVSIZ_Y*2,
- WINFLAG_RESIZABLE | WINFLAG_HIDDEN,
- WINPOS_CENTERED, WINPOS_CENTERED,
- CANVSIZ_X, CANVSIZ_Y, false);
- gl_text = new BitmapFont("dat/img/_font8x8.qoi", gl_win);
- gl_fstr = new FStr(4096);
- //gl_textf(0, 0, "loading");
- //gl_win->present();
- //gl_win->setVisibility(true);
- gl_spritesheetPlayer = new Bitmap("dat/img/spritesheet_player.qoi", gl_win);
- //memset just in case, though i'm pretty sure this redundant
- memset0(gl_tilesets);
- char* fstr_ptr = gl_fstr->ptr();
- for(u32 i=0; i<gl_tilesets_len; ++i){
- gl_fstr->fmt("dat/tilesets/tileset_%u.qoi", i);
- if(!fileio::fileExists(fstr_ptr))
- throw (const char*)gl_fstr->fmt("\"dat/tilesets/tileset_%u.qoi\" doesn't exist",i);
- gl_tilesets[i] = new Bitmap(fstr_ptr, gl_win);
- }
- gl_tileset_missing = new Bitmap("dat/tilesets/tileset_missing.qoi", gl_win);
- gl_frameTimer->wait(2000);
- gl_win->setVisibility(true);
- gl_win->setFocus(true);
- }
- void handleQuit(){
- if(gl_frameTimer) gl_frameTimer->setTimer(0.05);
- if(gl_snd){
- gl_snd->musicStop();
- gl_snd->sfxStopAll();
- }
- delete gl_snd_lock;
- delete gl_fstr;
- delete gl_text;
- delete gl_win;
- delete gl_spritesheetPlayer;
- for(u32 i=0; i<gl_tilesets_len; ++i) delete gl_tilesets[i];
- delete gl_tileset_missing;
- if(gl_frameTimer) gl_frameTimer->wait(2000);
- delete gl_frameTimer;
- }
- extern int gameMain(int argc, char** argv);
- int main(int argc, char** argv){ try {
- handleInit();
- int result = gameMain(argc, argv);
- handleQuit();
- printf("# OF CONTROLLED ALLOCATIONS = %llu\n",memory::getNumAllocations()-6);
- return result;
- } catch(const char* errorText){
- #ifdef _DEBUG
- printf("FATAL EXCEPTION OCCURRED!: \"%s\"\n", errorText);
- #else
- showMessageBox(errorText, "FATAL EXCEPTION OCCURRED! COMPLAIN TO THE DEV! (lol)", MSGBOX_ICN_ERROR);
- #endif /* _DEBUG */
- return -1;
- }}
- f64 frand(){
- u32 value = (rand()<<15) | rand();
- return (f64)value/(KIT_U32_MAX>>2);
- }
- f32 frandf(){
- u32 value = (rand()<<15) | rand();
- return (f32)value/(KIT_U32_MAX>>2);
- }
- f64 frandRange(f64 start, f64 maxDeviation){
- return start + (frand()*2.0-1.0)*maxDeviation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement