From a6bfc6011e155de266137f8448ac156eb1546aa7 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Wed, 14 Feb 2018 14:52:10 +0300 Subject: [PATCH] no message --- src/code.c | 6 +-- src/console.c | 4 +- src/fs.c | 14 +++--- src/main.h | 28 +++++++++++- src/map.c | 4 +- src/music.c | 4 +- src/run.c | 4 +- src/studio.c | 116 +++----------------------------------------------- src/studio.h | 58 ++++--------------------- src/surf.c | 4 +- 10 files changed, 61 insertions(+), 181 deletions(-) diff --git a/src/code.c b/src/code.c index 30cbeec..fc8d08f 100644 --- a/src/code.c +++ b/src/code.c @@ -540,7 +540,7 @@ static void copyToClipboard(Code* code) { memcpy(clipboard, start, size); clipboard[size] = '\0'; - setClipboardText(clipboard); + getSystem()->setClipboardText(clipboard); free(clipboard); } } @@ -554,9 +554,9 @@ static void cutToClipboard(Code* code) static void copyFromClipboard(Code* code) { - if(hasClipboardText()) + if(getSystem()->hasClipboardText()) { - char* clipboard = getClipboardText(); + char* clipboard = getSystem()->getClipboardText(); if(clipboard) { diff --git a/src/console.c b/src/console.c index 34fcc56..5d20cc1 100644 --- a/src/console.c +++ b/src/console.c @@ -2573,7 +2573,7 @@ static NetVersion netVersionRequest() }; s32 size = 0; - void* buffer = getUrlRequest("/api?fn=version", &size); + void* buffer = getSystem()->getUrlRequest("/api?fn=version", &size); if(buffer && size) { @@ -3055,7 +3055,7 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config, { char buf[256]; sprintf(buf, "parameter or file not processed: %s\n", argv[i]); - showMessageBox("Warning", buf); + getSystem()->showMessageBox("Warning", buf); } } } diff --git a/src/fs.c b/src/fs.c index 9a98fe3..ee15324 100644 --- a/src/fs.c +++ b/src/fs.c @@ -280,7 +280,7 @@ static void netDirRequest(const char* path, ListCallback callback, void* data) sprintf(request, "/api?fn=dir&path=%s", path); s32 size = 0; - void* buffer = getUrlRequest(request, &size); + void* buffer = getSystem()->getUrlRequest(request, &size); NetDirData netDirData = {callback, data}; onDirResponse(buffer, size, &netDirData); @@ -420,7 +420,7 @@ void fsAddFile(FileSystem* fs, AddCallback callback, void* data) *addFileData = (AddFileData) { fs, callback, data }; - _file_dialog_load(&onAddFile, addFileData); + getSystem()->file_dialog_load(&onAddFile, addFileData); } typedef struct @@ -552,7 +552,7 @@ void fsGetFileData(GetCallback callback, const char* name, void* buffer, size_t GetFileData* command = (GetFileData*)malloc(sizeof(GetFileData)); *command = (GetFileData) {callback, data, buffer}; - _file_dialog_save(onGetFile, name, buffer, size, command, mode); + getSystem()->file_dialog_save(onGetFile, name, buffer, size, command, mode); } typedef struct @@ -576,7 +576,7 @@ void fsOpenFileData(OpenCallback callback, void* data) *command = (OpenFileData){callback, data}; - _file_dialog_load(onOpenFileData, command); + getSystem()->file_dialog_load(onOpenFileData, command); } void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* data) @@ -590,7 +590,7 @@ void fsGetFile(FileSystem* fs, GetCallback callback, const char* name, void* dat *command = (GetFileData) {callback, data, buffer}; s32 mode = fsGetMode(fs, name); - _file_dialog_save(onGetFile, name, buffer, size, command, mode); + getSystem()->file_dialog_save(onGetFile, name, buffer, size, command, mode); } else callback(FS_FILE_NOT_DOWNLOADED, data); } @@ -843,7 +843,7 @@ void* fsLoadFile(FileSystem* fs, const char* name, s32* size) char path[FILENAME_MAX] = {0}; sprintf(path, "/cart/%s/cart.tic", loadPublicCartData.hash); - void* data = getUrlRequest(path, size); + void* data = getSystem()->getUrlRequest(path, size); if(data) fsSaveRootFile(fs, cachePath, data, *size, false); @@ -900,7 +900,7 @@ void fsOpenWorkingFolder(FileSystem* fs) if(isPublic(fs)) path = fs->dir; - openSystemPath(path); + getSystem()->openSystemPath(path); } FileSystem* createFileSystem(const char* path) diff --git a/src/main.h b/src/main.h index 7b9637e..90a9280 100644 --- a/src/main.h +++ b/src/main.h @@ -1 +1,27 @@ -#pragma once \ No newline at end of file +#pragma once + +#include "tic.h" +#include "ext/file_dialog.h" + +typedef struct +{ + void (*setClipboardText)(const char* text); + bool (*hasClipboardText)(); + char* (*getClipboardText)(); + u64 (*getPerformanceCounter)(); + u64 (*getPerformanceFrequency)(); + + void* (*getUrlRequest)(const char* url, s32* size); + + void (*file_dialog_load)(file_dialog_load_callback callback, void* data); + void (*file_dialog_save)(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode); + + void (*goFullscreen)(); + void (*showMessageBox)(const char* title, const char* message); + void (*setWindowTitle)(const char* title); + + void (*openSystemPath)(const char* path); + +} System; + +System* getSystem(); diff --git a/src/map.c b/src/map.c index 9044482..9cdad0c 100644 --- a/src/map.c +++ b/src/map.c @@ -976,9 +976,9 @@ static void cutToClipboard(Map* map) static void copyFromClipboard(Map* map) { - if(hasClipboardText()) + if(getSystem()->hasClipboardText()) { - char* clipboard = getClipboardText(); + char* clipboard = getSystem()->getClipboardText(); if(clipboard) { diff --git a/src/music.c b/src/music.c index 9b6c1c2..ade0a38 100644 --- a/src/music.c +++ b/src/music.c @@ -619,9 +619,9 @@ static void copyFromClipboard(Music* music) { tic_track_pattern* pattern = getChannelPattern(music); - if(pattern && hasClipboardText()) + if(pattern && getSystem()->hasClipboardText()) { - char* clipboard = getClipboardText(); + char* clipboard = getSystem()->getClipboardText(); if(clipboard) { diff --git a/src/run.c b/src/run.c index ccfe66b..85a8e02 100644 --- a/src/run.c +++ b/src/run.c @@ -183,8 +183,8 @@ void initRun(Run* run, Console* console, tic_mem* tic) { .error = onError, .trace = onTrace, - .counter = getPerformanceCounter, - .freq = getPerformanceFrequency, + .counter = getSystem()->getPerformanceCounter, + .freq = getSystem()->getPerformanceFrequency, .start = 0, .data = run, .exit = onExit, diff --git a/src/studio.c b/src/studio.c index 91ebbea..2006204 100644 --- a/src/studio.c +++ b/src/studio.c @@ -49,12 +49,7 @@ #include #include - -// #define TEXTURE_SIZE (TIC80_FULLWIDTH) -// #define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888 #define FRAME_SIZE (TIC80_FULLWIDTH * TIC80_FULLHEIGHT * sizeof(u32)) -// #define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2) -// #define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2) #define POPUP_DUR (TIC_FRAMERATE*2) #define KEYBOARD_HOLD 20 @@ -372,7 +367,7 @@ void toClipboard(const void* data, s32 size, bool flip) } } - setClipboardText(clipboard); + getSystem()->setClipboardText(clipboard); free(clipboard); } } @@ -416,9 +411,9 @@ bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces) { if(data) { - if(hasClipboardText()) + if(getSystem()->hasClipboardText()) { - char* clipboard = getClipboardText(); + char* clipboard = getSystem()->getClipboardText(); if(clipboard) { @@ -1649,8 +1644,6 @@ static void renderStudio() if(studioImpl.mode != TIC_RUN_MODE) useSystemPalette(); - - // renderCursor(); } static void updateSystemFont() @@ -1716,60 +1709,6 @@ static void initKeymap() } } -// #if defined(__EMSCRIPTEN__) - -// #define DEFAULT_CART "cart.tic" - -// static void onEmscriptenWget(const char* file) -// { -// studioImpl.argv[1] = DEFAULT_CART; -// createFileSystem(NULL, onFSInitialized); -// } - -// static void onEmscriptenWgetError(const char* error) {} - -// static void emstick() -// { -// static double nextTick = -1.0; - -// studioImpl.missedFrame = false; - -// if(nextTick < 0.0) -// nextTick = emscripten_get_now(); - -// nextTick += 1000.0/TIC_FRAMERATE; -// tick(); -// double delay = nextTick - emscripten_get_now(); - -// if(delay < 0.0) -// { -// nextTick -= delay; -// studioImpl.missedFrame = true; -// } -// else -// emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, delay); -// } - -// #endif - -// #if defined(__EMSCRIPTEN__) - -// if(studioImpl.argc == 2) -// { -// emscripten_async_wget(studioImpl.argv[1], DEFAULT_CART, onEmscriptenWget, onEmscriptenWgetError); -// } -// else createFileSystem(NULL, onFSInitialized); - -// // emscripten_set_main_loop(emstick, TIC_FRAMERATE, 1); - -// #else - -// FileSystem* fs = createFileSystem(argc > 1 && fsExists(argv[1]) ? fsBasename(argv[1]) : folder); -// onFSInitialized(fs); - -// #endif - - Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* folder, System* system) { setbuf(stdout, NULL); @@ -1935,52 +1874,7 @@ void studioClose() tic80_delete((tic80*)studioImpl.tic80local); } -void setClipboardText(const char* text) +System* getSystem() { - studioImpl.system->setClipboardText(text); + return studioImpl.system; } - -bool hasClipboardText() -{ - return studioImpl.system->hasClipboardText(); -} - -char* getClipboardText() -{ - return studioImpl.system->getClipboardText(); -} - -u64 getPerformanceCounter() -{ - return studioImpl.system->getPerformanceCounter(); -} - -u64 getPerformanceFrequency() -{ - return studioImpl.system->getPerformanceFrequency(); -} - -void _file_dialog_load(file_dialog_load_callback callback, void* data) -{ - studioImpl.system->file_dialog_load(callback, data); -} - -void _file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode) -{ - studioImpl.system->file_dialog_save(callback, name, buffer, size, data, mode); -} - -void showMessageBox(const char* title, const char* message) -{ - studioImpl.system->showMessageBox(title, message); -} - -void openSystemPath(const char* path) -{ - studioImpl.system->openSystemPath(path); -} - -void* getUrlRequest(const char* url, s32* size) -{ - return studioImpl.system->getUrlRequest(url, size); -} \ No newline at end of file diff --git a/src/studio.h b/src/studio.h index 5451f63..a1e44db 100644 --- a/src/studio.h +++ b/src/studio.h @@ -27,8 +27,6 @@ #include #include -// #include - #if defined(__EMSCRIPTEN__) #include #endif @@ -38,12 +36,11 @@ #include "defines.h" #include "tools.h" #include "ext/file_dialog.h" +#include "main.h" #define TIC_LOCAL ".local/" #define TIC_CACHE TIC_LOCAL "cache/" -// #define TIC_MOD_CTRL (KMOD_GUI|KMOD_CTRL) - #define TOOLBAR_SIZE 7 #define STUDIO_TEXT_WIDTH (TIC_FONT_WIDTH) #define STUDIO_TEXT_HEIGHT (TIC_FONT_HEIGHT+1) @@ -211,54 +208,17 @@ void runProject(); tic_tiles* getBankTiles(); tic_map* getBankMap(); -typedef struct -{ - tic_mem* tic; - bool quit; - -} Studio; - -typedef struct -{ - void (*setClipboardText)(const char* text); - bool (*hasClipboardText)(); - char* (*getClipboardText)(); - u64 (*getPerformanceCounter)(); - u64 (*getPerformanceFrequency)(); - - void* (*getUrlRequest)(const char* url, s32* size); - - void (*file_dialog_load)(file_dialog_load_callback callback, void* data); - void (*file_dialog_save)(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode); - - void (*goFullscreen)(); - void (*showMessageBox)(const char* title, const char* message); - void (*setWindowTitle)(const char* title); - - void (*openSystemPath)(const char* path); - -} System; - -TIC80_API Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder, System* system); -TIC80_API void studioTick(void* pixels); -TIC80_API void studioClose(); - char getKeyboardText(); bool keyWasPressed(tic_key key); bool anyKeyWasPressed(); -void setClipboardText(const char* text); -bool hasClipboardText(); -char* getClipboardText(); +typedef struct +{ + tic_mem* tic; + bool quit; +} Studio; -u64 getPerformanceCounter(); -u64 getPerformanceFrequency(); - -void _file_dialog_load(file_dialog_load_callback callback, void* data); -void _file_dialog_save(file_dialog_save_callback callback, const char* name, const u8* buffer, size_t size, void* data, u32 mode); - -void showMessageBox(const char* title, const char* message); +TIC80_API Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder, System* system); +TIC80_API void studioTick(void* pixels); +TIC80_API void studioClose(); TIC80_API void updateStudioProject(); - -void openSystemPath(const char* path); -void* getUrlRequest(const char* url, s32* size); diff --git a/src/surf.c b/src/surf.c index 20f5110..dd91146 100644 --- a/src/surf.c +++ b/src/surf.c @@ -477,7 +477,7 @@ static void* requestCover(Surf* surf, const char* hash, s32* size) char path[FILENAME_MAX] = {0}; sprintf(path, "/cart/%s/cover.gif", hash); - void* data = getUrlRequest(path, size); + void* data = getSystem()->getUrlRequest(path, size); if(data) { @@ -780,7 +780,7 @@ static void processGamepad(Surf* surf) { char url[FILENAME_MAX]; sprintf(url, "https://" TIC_HOST "/play?cart=%i", item->id); - openSystemPath(url); + getSystem()->openSystemPath(url); } } #endif