From b4c46a29e260323701eb867971067d98719cdd9b Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 24 Jan 2018 19:09:22 +0300 Subject: [PATCH] no message --- src/main.c | 7 +++---- src/map.c | 26 +++++++++++++++----------- src/sfx.c | 34 ++++++++++++++++++---------------- src/studio.c | 42 ++++++++++++++++++++---------------------- src/studio.h | 4 +++- 5 files changed, 59 insertions(+), 54 deletions(-) diff --git a/src/main.c b/src/main.c index d557013..0335c88 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,6 @@ static struct } part; } gamepad; - bool quitFlag; bool missedFrame; } platform; @@ -592,7 +591,7 @@ static void pollEvent() // showSoftKeyboard(); // break; case SDL_QUIT: - platform.quitFlag = true; + platform.studio->quit = true; // exitStudio(); break; default: @@ -780,7 +779,7 @@ static void tick() // if(!platform.fs) return; -// if(platform.quitFlag) +// if(platform.quit) // { // #if defined __EMSCRIPTEN__ // platform.studio->tic->api.clear(platform.studio->tic, TIC_COLOR_BG); @@ -869,7 +868,7 @@ s32 main(s32 argc, char **argv) u64 nextTick = SDL_GetPerformanceCounter(); const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE; - while (!platform.quitFlag) + while (!platform.studio->quit) { platform.missedFrame = false; diff --git a/src/map.c b/src/map.c index de94596..0c8a0e7 100644 --- a/src/map.c +++ b/src/map.c @@ -864,7 +864,8 @@ static void drawMapOvr(Map* map) s32 scrollX = map->scroll.x % TIC_SPRITESIZE; s32 scrollY = map->scroll.y % TIC_SPRITESIZE; - map->tic->api.map(map->tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, + tic_mem* tic = map->tic; + tic->api.map(tic, map->src, getBankTiles(), map->scroll.x / TIC_SPRITESIZE, map->scroll.y / TIC_SPRITESIZE, TIC_MAP_SCREEN_WIDTH + 1, TIC_MAP_SCREEN_HEIGHT + 1, -scrollX, -scrollY, -1, 1); if(map->canvas.grid || map->scroll.active) @@ -874,13 +875,14 @@ static void drawMapOvr(Map* map) s32 screenScrollX = map->scroll.x % TIC80_WIDTH; s32 screenScrollY = map->scroll.y % TIC80_HEIGHT; - map->tic->api.line(map->tic, 0, TIC80_HEIGHT - screenScrollY, TIC80_WIDTH, TIC80_HEIGHT - screenScrollY, (tic_color_gray)); - map->tic->api.line(map->tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray)); + tic->api.line(tic, 0, TIC80_HEIGHT - screenScrollY, TIC80_WIDTH, TIC80_HEIGHT - screenScrollY, (tic_color_gray)); + tic->api.line(tic, TIC80_WIDTH - screenScrollX, 0, TIC80_WIDTH - screenScrollX, TIC80_HEIGHT, (tic_color_gray)); } if(!map->sheet.show && checkMousePos(&rect)) { - if(getKeyboard()[SDL_SCANCODE_SPACE]) + if(tic->api.key(tic, tic_key_space)) + // if(getKeyboard()[SDL_SCANCODE_SPACE]) { processScrolling(map, checkMouseDown(&rect, SDL_BUTTON_LEFT) || checkMouseDown(&rect, SDL_BUTTON_RIGHT)); } @@ -902,15 +904,17 @@ static void processKeyboard(Map* map) { enum{Step = 1}; - if(getKeyboard()[SDL_SCANCODE_UP]) map->scroll.y -= Step; - if(getKeyboard()[SDL_SCANCODE_DOWN]) map->scroll.y += Step; - if(getKeyboard()[SDL_SCANCODE_LEFT]) map->scroll.x -= Step; - if(getKeyboard()[SDL_SCANCODE_RIGHT]) map->scroll.x += Step; + tic_mem* tic = map->tic; - static const u8 Scancodes[] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT}; + if(tic->api.key(tic, tic_key_up)) map->scroll.y -= Step; + if(tic->api.key(tic, tic_key_down)) map->scroll.y += Step; + if(tic->api.key(tic, tic_key_left)) map->scroll.x -= Step; + if(tic->api.key(tic, tic_key_right)) map->scroll.x += Step; - for(s32 i = 0; i < COUNT_OF(Scancodes); i++) - if(getKeyboard()[Scancodes[i]]) + static const tic_key Keycodes[] = {tic_key_up, tic_key_down, tic_key_left, tic_key_right}; + + for(s32 i = 0; i < COUNT_OF(Keycodes); i++) + if(tic->api.key(tic, Keycodes[i])) { normalizeMap(&map->scroll.x, &map->scroll.y); break; diff --git a/src/sfx.c b/src/sfx.c index 665a76f..f0ec2a3 100644 --- a/src/sfx.c +++ b/src/sfx.c @@ -631,22 +631,24 @@ static void processKeyboard(Sfx* sfx) { s32 keyboardButton = -1; - static const s32 Scancodes[] = + static const s32 Keycodes[] = { - SDL_SCANCODE_Z, - SDL_SCANCODE_S, - SDL_SCANCODE_X, - SDL_SCANCODE_D, - SDL_SCANCODE_C, - SDL_SCANCODE_V, - SDL_SCANCODE_G, - SDL_SCANCODE_B, - SDL_SCANCODE_H, - SDL_SCANCODE_N, - SDL_SCANCODE_J, - SDL_SCANCODE_M, + tic_key_z, + tic_key_s, + tic_key_x, + tic_key_d, + tic_key_c, + tic_key_v, + tic_key_g, + tic_key_b, + tic_key_h, + tic_key_n, + tic_key_j, + tic_key_m, }; + tic_mem* tic = sfx->tic; + SDL_Keymod keymod = SDL_GetModState(); if(keymod & TIC_MOD_CTRL) @@ -655,8 +657,8 @@ static void processKeyboard(Sfx* sfx) } else { - for(int i = 0; i < COUNT_OF(Scancodes); i++) - if(getKeyboard()[Scancodes[i]]) + for(int i = 0; i < COUNT_OF(Keycodes); i++) + if(tic->api.key(tic, Keycodes[i])) keyboardButton = i; } @@ -668,7 +670,7 @@ static void processKeyboard(Sfx* sfx) sfx->play.active = true; } - if(getKeyboard()[SDL_SCANCODE_SPACE]) + if(tic->api.key(tic, tic_key_space)) sfx->play.active = true; } diff --git a/src/studio.c b/src/studio.c index a456439..f91ee17 100644 --- a/src/studio.c +++ b/src/studio.c @@ -96,9 +96,9 @@ static struct u64 mdate; }cart; - SDL_Window* window; - SDL_Renderer* renderer; - SDL_Texture* texture; + // SDL_Window* window; + // SDL_Renderer* renderer; + // SDL_Texture* texture; // struct // { @@ -131,7 +131,7 @@ static struct bool active; } gesture; - const u8* keyboard; + // const u8* keyboard; tic_key keycodes[KEYMAP_COUNT]; @@ -226,7 +226,6 @@ static struct FileSystem* fs; - bool quitFlag; bool missedFrame; s32 argc; @@ -238,9 +237,9 @@ static struct .tic80local = NULL, // .tic = NULL, - .window = NULL, - .renderer = NULL, - .texture = NULL, + // .window = NULL, + // .renderer = NULL, + // .texture = NULL, // .audio = // { // .device = 0, @@ -272,7 +271,7 @@ static struct .active = false, }, - .keyboard = NULL, + // .keyboard = NULL, .keycodes = { tic_key_up, @@ -316,7 +315,6 @@ static struct }, .fullscreen = false, - .quitFlag = false, .missedFrame = false, .argc = 0, .argv = NULL, @@ -920,10 +918,10 @@ ClipboardEvent getClipboardEvent(SDL_Keycode keycode) return TIC_CLIPBOARD_NONE; } -const u8* getKeyboard() -{ - return studioImpl.keyboard; -} +// const u8* getKeyboard() +// { +// return studioImpl.keyboard; +// } static void showPopupMessage(const char* text) { @@ -933,7 +931,7 @@ static void showPopupMessage(const char* text) static void exitConfirm(bool yes, void* data) { - studioImpl.quitFlag = yes; + studioImpl.studio.quit = yes; } void exitStudio() @@ -1213,12 +1211,12 @@ static void updateMDate() static void updateTitle() { - char name[FILENAME_MAX] = TIC_TITLE; + // char name[FILENAME_MAX] = TIC_TITLE; - if(strlen(studioImpl.console->romName)) - sprintf(name, "%s [%s]", TIC_TITLE, studioImpl.console->romName); + // if(strlen(studioImpl.console->romName)) + // sprintf(name, "%s [%s]", TIC_TITLE, studioImpl.console->romName); - SDL_SetWindowTitle(studioImpl.window, name); + // SDL_SetWindowTitle(studioImpl.window, name); } void studioRomSaved() @@ -1644,8 +1642,8 @@ static void processGesture() static void goFullscreen() { - studioImpl.fullscreen = !studioImpl.fullscreen; - SDL_SetWindowFullscreen(studioImpl.window, studioImpl.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + // studioImpl.fullscreen = !studioImpl.fullscreen; + // SDL_SetWindowFullscreen(studioImpl.window, studioImpl.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); } void runProject() @@ -2578,7 +2576,7 @@ static void renderStudio() // { // if(!studioImpl.fs) return; -// if(studioImpl.quitFlag) +// if(studioImpl.studio.quit) // { // #if defined __EMSCRIPTEN__ // studioImpl.studio.tic->api.clear(studioImpl.studio.tic, TIC_COLOR_BG); diff --git a/src/studio.h b/src/studio.h index 3e9abae..32fb0f7 100644 --- a/src/studio.h +++ b/src/studio.h @@ -133,7 +133,7 @@ bool checkMouseDown(const SDL_Rect* rect, s32 button); bool getGesturePos(SDL_Point* pos); -const u8* getKeyboard(); +// const u8* getKeyboard(); void drawToolbar(tic_mem* tic, u8 color, bool bg); void drawBitIcon(s32 x, s32 y, const u8* ptr, u8 color); @@ -202,6 +202,8 @@ tic_map* getBankMap(); typedef struct { tic_mem* tic; + bool quit; + } Studio; Studio* studioInit(s32 argc, char **argv, s32 samplerate);