no message

This commit is contained in:
BADIM-PC\Vadim 2018-02-14 15:14:05 +03:00
parent a6bfc6011e
commit 7b9551f2a0
5 changed files with 158 additions and 201 deletions

View File

@ -420,7 +420,7 @@ void fsAddFile(FileSystem* fs, AddCallback callback, void* data)
*addFileData = (AddFileData) { fs, callback, data };
getSystem()->file_dialog_load(&onAddFile, addFileData);
getSystem()->fileDialogLoad(&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};
getSystem()->file_dialog_save(onGetFile, name, buffer, size, command, mode);
getSystem()->fileDialogSave(onGetFile, name, buffer, size, command, mode);
}
typedef struct
@ -576,7 +576,7 @@ void fsOpenFileData(OpenCallback callback, void* data)
*command = (OpenFileData){callback, data};
getSystem()->file_dialog_load(onOpenFileData, command);
getSystem()->fileDialogLoad(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);
getSystem()->file_dialog_save(onGetFile, name, buffer, size, command, mode);
getSystem()->fileDialogSave(onGetFile, name, buffer, size, command, mode);
}
else callback(FS_FILE_NOT_DOWNLOADED, data);
}

View File

@ -580,7 +580,7 @@ static void pollEvent()
switch(event.window.event)
{
case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break;
case SDL_WINDOWEVENT_FOCUS_GAINED: updateStudioProject(); break;
case SDL_WINDOWEVENT_FOCUS_GAINED: platform.studio->updateProject(); break;
}
break;
case SDL_QUIT:
@ -610,7 +610,7 @@ static void blitTexture()
s32 pitch = 0;
SDL_LockTexture(platform.texture, NULL, &pixels, &pitch);
studioTick(pixels);
platform.studio->tick(pixels);
SDL_UnlockTexture(platform.texture);
@ -882,50 +882,50 @@ static const char* getAppFolder()
return appFolder;
}
static void _setClipboardText(const char* text)
static void setClipboardText(const char* text)
{
SDL_SetClipboardText(text);
}
static bool _hasClipboardText()
static bool hasClipboardText()
{
return SDL_HasClipboardText();
}
static char* _getClipboardText()
static char* getClipboardText()
{
return SDL_GetClipboardText();
}
static u64 _getPerformanceCounter()
static u64 getPerformanceCounter()
{
return SDL_GetPerformanceCounter();
}
static u64 _getPerformanceFrequency()
static u64 getPerformanceFrequency()
{
return SDL_GetPerformanceFrequency();
}
static void _goFullscreen()
static void goFullscreen()
{
platform.fullscreen = !platform.fullscreen;
SDL_SetWindowFullscreen(platform.window, platform.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
}
static void _showMessageBox(const char* title, const char* message)
static void showMessageBox(const char* title, const char* message)
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, message, NULL);
}
static void _setWindowTitle(const char* title)
static void setWindowTitle(const char* title)
{
SDL_SetWindowTitle(platform.window, title);
}
#if defined(__WINDOWS__) || defined(__LINUX__) || defined(__MACOSX__)
static void _openSystemPath(const char* path)
static void openSystemPath(const char* path)
{
char command[FILENAME_MAX];
@ -955,33 +955,33 @@ static void _openSystemPath(const char* path)
#else
void _openSystemPath(const char* path) {}
static void openSystemPath(const char* path) {}
#endif
static void* _getUrlRequest(const char* url, s32* size)
static void* getUrlRequest(const char* url, s32* size)
{
return netGetRequest(platform.net, url, size);
}
static System sysHandlers =
static System systemInterface =
{
.setClipboardText = _setClipboardText,
.hasClipboardText = _hasClipboardText,
.getClipboardText = _getClipboardText,
.getPerformanceCounter = _getPerformanceCounter,
.getPerformanceFrequency = _getPerformanceFrequency,
.setClipboardText = setClipboardText,
.hasClipboardText = hasClipboardText,
.getClipboardText = getClipboardText,
.getPerformanceCounter = getPerformanceCounter,
.getPerformanceFrequency = getPerformanceFrequency,
.getUrlRequest = _getUrlRequest,
.getUrlRequest = getUrlRequest,
.file_dialog_load = file_dialog_load,
.file_dialog_save = file_dialog_save,
.fileDialogLoad = file_dialog_load,
.fileDialogSave = file_dialog_save,
.goFullscreen = _goFullscreen,
.showMessageBox = _showMessageBox,
.setWindowTitle = _setWindowTitle,
.goFullscreen = goFullscreen,
.showMessageBox = showMessageBox,
.setWindowTitle = setWindowTitle,
.openSystemPath = _openSystemPath,
.openSystemPath = openSystemPath,
};
#if defined(__EMSCRIPTEN__)
@ -1010,55 +1010,6 @@ static void emstick()
#endif
// else
// {
// #if defined(__EMSCRIPTEN__)
// strcpy(fs->dir, "/" TIC_PACKAGE "/" TIC_NAME "/");
// #elif defined(__ANDROID__)
// strcpy(fs->dir, SDL_AndroidGetExternalStoragePath());
// const char AppFolder[] = "/" TIC_NAME "/";
// strcat(fs->dir, AppFolder);
// mkdir(fs->dir, 0700);
// #else
// char* path = SDL_GetPrefPath(TIC_PACKAGE, TIC_NAME);
// strcpy(fs->dir, path);
// free(path);
// #endif
// #if defined(__EMSCRIPTEN__)
// EM_ASM_
// (
// {
// var dir = "";
// Module.Pointer_stringify($0).split("/").forEach(function(val)
// {
// if(val.length)
// {
// dir += "/" + val;
// FS.mkdir(dir);
// }
// });
// FS.mount(IDBFS, {}, dir);
// FS.syncfs(true, function(error)
// {
// if(error) console.log(error);
// else Runtime.dynCall('vi', $1, [$2]);
// });
// }, fs->dir, callback, fs
// );
// #else
// callback(fs);
// #endif
// }
static s32 start(s32 argc, char **argv, const char* folder)
{
SDL_SetHint(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, "1");
@ -1079,7 +1030,7 @@ static s32 start(s32 argc, char **argv, const char* folder)
#endif
);
platform.studio = studioInit(argc, argv, platform.audio.spec.freq, folder, &sysHandlers);
platform.studio = studioInit(argc, argv, platform.audio.spec.freq, folder, &systemInterface);
// set the window icon before renderer is created (issues on Linux)
setWindowIcon();
@ -1128,7 +1079,7 @@ static s32 start(s32 argc, char **argv, const char* folder)
#endif
studioClose();
platform.studio->close();
closeNet(platform.net);

View File

@ -1,6 +1,6 @@
#pragma once
#include "tic.h"
#include "ticapi.h"
#include "ext/file_dialog.h"
typedef struct
@ -13,8 +13,8 @@ typedef struct
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 (*fileDialogLoad)(file_dialog_load_callback callback, void* data);
void (*fileDialogSave)(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);
@ -24,4 +24,15 @@ typedef struct
} System;
System* getSystem();
typedef struct
{
tic_mem* tic;
bool quit;
void (*tick)(void* pixels);
void (*close)();
void (*updateProject)();
} Studio;
TIC80_API Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* appFolder, System* system);

View File

@ -1418,7 +1418,7 @@ static void reloadConfirm(bool yes, void* data)
#endif
void updateStudioProject()
static void updateStudioProject()
{
#if defined(TIC80_PRO)
@ -1709,6 +1709,111 @@ static void initKeymap()
}
}
static void processMouseStates()
{
for(int i = 0; i < COUNT_OF(studioImpl.mouse.state); i++)
studioImpl.mouse.state[i].click = false;
tic_mem* tic = studioImpl.studio.tic;
tic->ram.vram.vars.cursor.sprite = tic_cursor_arrow;
tic->ram.vram.vars.cursor.system = true;
for(int i = 0; i < COUNT_OF(studioImpl.mouse.state); i++)
{
MouseState* state = &studioImpl.mouse.state[i];
if(!state->down && (tic->ram.input.mouse.btns & (1 << i)))
{
state->down = true;
state->start.x = tic->ram.input.mouse.x;
state->start.y = tic->ram.input.mouse.y;
}
else if(state->down && !(tic->ram.input.mouse.btns & (1 << i)))
{
state->end.x = tic->ram.input.mouse.x;
state->end.y = tic->ram.input.mouse.y;
state->click = true;
state->down = false;
}
}
}
static void studioTick(void* pixels)
{
processShortcuts();
processMouseStates();
processGamepadMapping();
renderStudio();
tic_mem* tic = studioImpl.studio.tic;
{
tic_scanline scanline = NULL;
tic_overlap overlap = NULL;
void* data = NULL;
switch(studioImpl.mode)
{
case TIC_RUN_MODE:
scanline = tic->api.scanline;
overlap = tic->api.overlap;
break;
case TIC_SPRITE_MODE:
{
Sprite* sprite = studioImpl.editor[studioImpl.bank.index.sprites].sprite;
overlap = sprite->overlap;
data = sprite;
}
break;
case TIC_MAP_MODE:
{
Map* map = studioImpl.editor[studioImpl.bank.index.map].map;
overlap = map->overlap;
data = map;
}
break;
default:
break;
}
tic->api.blit(tic, scanline, overlap, data);
memcpy(pixels, tic->screen, sizeof tic->screen);
recordFrame(pixels);
drawDesyncLabel(pixels);
}
}
static void studioClose()
{
{
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
free(studioImpl.editor[i].code);
free(studioImpl.editor[i].sprite);
free(studioImpl.editor[i].map);
free(studioImpl.editor[i].sfx);
free(studioImpl.editor[i].music);
}
free(studioImpl.start);
free(studioImpl.console);
free(studioImpl.run);
free(studioImpl.world);
free(studioImpl.config);
free(studioImpl.dialog);
free(studioImpl.menu);
free(studioImpl.surf);
}
if(studioImpl.tic80local)
tic80_delete((tic80*)studioImpl.tic80local);
}
Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* folder, System* system)
{
setbuf(stdout, NULL);
@ -1766,114 +1871,13 @@ Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* folder, Sy
goFullscreen();
}
studioImpl.studio.tick = studioTick;
studioImpl.studio.close = studioClose;
studioImpl.studio.updateProject = updateStudioProject;
return &studioImpl.studio;
}
static void processMouseStates()
{
for(int i = 0; i < COUNT_OF(studioImpl.mouse.state); i++)
studioImpl.mouse.state[i].click = false;
tic_mem* tic = studioImpl.studio.tic;
tic->ram.vram.vars.cursor.sprite = tic_cursor_arrow;
tic->ram.vram.vars.cursor.system = true;
for(int i = 0; i < COUNT_OF(studioImpl.mouse.state); i++)
{
MouseState* state = &studioImpl.mouse.state[i];
if(!state->down && (tic->ram.input.mouse.btns & (1 << i)))
{
state->down = true;
state->start.x = tic->ram.input.mouse.x;
state->start.y = tic->ram.input.mouse.y;
}
else if(state->down && !(tic->ram.input.mouse.btns & (1 << i)))
{
state->end.x = tic->ram.input.mouse.x;
state->end.y = tic->ram.input.mouse.y;
state->click = true;
state->down = false;
}
}
}
void studioTick(void* pixels)
{
processShortcuts();
processMouseStates();
processGamepadMapping();
renderStudio();
tic_mem* tic = studioImpl.studio.tic;
{
tic_scanline scanline = NULL;
tic_overlap overlap = NULL;
void* data = NULL;
switch(studioImpl.mode)
{
case TIC_RUN_MODE:
scanline = tic->api.scanline;
overlap = tic->api.overlap;
break;
case TIC_SPRITE_MODE:
{
Sprite* sprite = studioImpl.editor[studioImpl.bank.index.sprites].sprite;
overlap = sprite->overlap;
data = sprite;
}
break;
case TIC_MAP_MODE:
{
Map* map = studioImpl.editor[studioImpl.bank.index.map].map;
overlap = map->overlap;
data = map;
}
break;
default:
break;
}
tic->api.blit(tic, scanline, overlap, data);
memcpy(pixels, tic->screen, sizeof tic->screen);
recordFrame(pixels);
drawDesyncLabel(pixels);
}
}
void studioClose()
{
{
for(s32 i = 0; i < TIC_EDITOR_BANKS; i++)
{
free(studioImpl.editor[i].code);
free(studioImpl.editor[i].sprite);
free(studioImpl.editor[i].map);
free(studioImpl.editor[i].sfx);
free(studioImpl.editor[i].music);
}
free(studioImpl.start);
free(studioImpl.console);
free(studioImpl.run);
free(studioImpl.world);
free(studioImpl.config);
free(studioImpl.dialog);
free(studioImpl.menu);
free(studioImpl.surf);
}
if(studioImpl.tic80local)
tic80_delete((tic80*)studioImpl.tic80local);
}
System* getSystem()
{
return studioImpl.system;

View File

@ -212,13 +212,4 @@ char getKeyboardText();
bool keyWasPressed(tic_key key);
bool anyKeyWasPressed();
typedef struct
{
tic_mem* tic;
bool quit;
} Studio;
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();
System* getSystem();