no message

This commit is contained in:
BADIM-PC\Vadim 2018-01-24 12:20:05 +03:00
parent 6cc4560cdc
commit ee5830b613
18 changed files with 1365 additions and 833 deletions

View File

@ -241,6 +241,9 @@ bin/menu.o: src/menu.c $(TIC80_H) $(TIC_H)
bin/surf.o: src/surf.c $(TIC80_H) $(TIC_H) bin/surf.o: src/surf.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@ $(CC) $< $(OPT) $(INCLUDES) -c -o $@
bin/main.o: src/main.c src/keycodes.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
TIC_O=\ TIC_O=\
bin/studio.o \ bin/studio.o \
bin/console.o \ bin/console.o \
@ -265,7 +268,8 @@ TIC_O=\
bin/net.o \ bin/net.o \
bin/dialog.o \ bin/dialog.o \
bin/menu.o \ bin/menu.o \
bin/surf.o bin/surf.o \
bin/main.o
bin/tic80.o: src/tic80.c $(TIC80_H) bin/tic80.o: src/tic80.c $(TIC80_H)
$(CC) $< $(OPT) $(INCLUDES) -DTIC80_SHARED -c -o $@ $(CC) $< $(OPT) $(INCLUDES) -DTIC80_SHARED -c -o $@

File diff suppressed because one or more lines are too long

View File

@ -1052,40 +1052,40 @@ static void processMouse(Code* code)
static void textEditTick(Code* code) static void textEditTick(Code* code)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_MOUSEWHEEL: // case SDL_MOUSEWHEEL:
{ // {
enum{Scroll = 3}; // enum{Scroll = 3};
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; // s32 delta = event->wheel.y > 0 ? -Scroll : Scroll;
code->scroll.y += delta; // code->scroll.y += delta;
normalizeScroll(code); // normalizeScroll(code);
} // }
break; // break;
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(code, event->key.keysym.sym); // processKeydown(code, event->key.keysym.sym);
break; // break;
case SDL_TEXTINPUT: // case SDL_TEXTINPUT:
#if defined(__LINUX__) // #if defined(__LINUX__)
if(!(SDL_GetModState() & KMOD_LALT)) // if(!(SDL_GetModState() & KMOD_LALT))
#endif // #endif
if(strlen(event->text.text) == 1) // if(strlen(event->text.text) == 1)
{ // {
inputSymbol(code, *event->text.text); // inputSymbol(code, *event->text.text);
updateEditor(code); // updateEditor(code);
} // }
break; // break;
} // }
} // }
processGestures(code); processGestures(code);
processMouse(code); processMouse(code);
@ -1146,54 +1146,54 @@ static char* downStrStr(const char* start, const char* from, const char* substr)
static void textFindTick(Code* code) static void textFindTick(Code* code)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
switch(event->key.keysym.sym) // switch(event->key.keysym.sym)
{ // {
case SDLK_RETURN: // case SDLK_RETURN:
setCodeMode(code, TEXT_EDIT_MODE); // setCodeMode(code, TEXT_EDIT_MODE);
break; // break;
case SDLK_UP: // case SDLK_UP:
case SDLK_LEFT: // case SDLK_LEFT:
case SDLK_DOWN: // case SDLK_DOWN:
case SDLK_RIGHT: // case SDLK_RIGHT:
if(*code->popup.text) // if(*code->popup.text)
{ // {
SDL_Keycode keycode = event->key.keysym.sym; // SDL_Keycode keycode = event->key.keysym.sym;
bool reverse = keycode == SDLK_UP || keycode == SDLK_LEFT; // bool reverse = keycode == SDLK_UP || keycode == SDLK_LEFT;
char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr; // char* (*func)(const char*, const char*, const char*) = reverse ? upStrStr : downStrStr;
char* from = reverse ? SDL_min(code->cursor.position, code->cursor.selection) : SDL_max(code->cursor.position, code->cursor.selection); // char* from = reverse ? SDL_min(code->cursor.position, code->cursor.selection) : SDL_max(code->cursor.position, code->cursor.selection);
char* pos = func(code->src, from, code->popup.text); // char* pos = func(code->src, from, code->popup.text);
updateFindCode(code, pos); // updateFindCode(code, pos);
} // }
break; // break;
case SDLK_BACKSPACE: // case SDLK_BACKSPACE:
if(*code->popup.text) // if(*code->popup.text)
{ // {
code->popup.text[strlen(code->popup.text)-1] = '\0'; // code->popup.text[strlen(code->popup.text)-1] = '\0';
updateFindCode(code, strstr(code->src, code->popup.text)); // updateFindCode(code, strstr(code->src, code->popup.text));
} // }
break; // break;
default: break; // default: break;
} // }
break; // break;
case SDL_TEXTINPUT: // case SDL_TEXTINPUT:
if(strlen(event->text.text) == 1) // if(strlen(event->text.text) == 1)
{ // {
if(strlen(code->popup.text) + 1 < sizeof code->popup.text) // if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
{ // {
strcat(code->popup.text, event->text.text); // strcat(code->popup.text, event->text.text);
updateFindCode(code, strstr(code->src, code->popup.text)); // updateFindCode(code, strstr(code->src, code->popup.text));
} // }
} // }
break; // break;
default: break; // default: break;
} // }
} // }
code->tic->api.clear(code->tic, getConfig()->theme.code.bg); code->tic->api.clear(code->tic, getConfig()->theme.code.bg);
@ -1223,45 +1223,45 @@ static void updateGotoCode(Code* code)
static void textGoToTick(Code* code) static void textGoToTick(Code* code)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
switch(event->key.keysym.sym) // switch(event->key.keysym.sym)
{ // {
case SDLK_RETURN: // case SDLK_RETURN:
if(*code->popup.text) // if(*code->popup.text)
updateGotoCode(code); // updateGotoCode(code);
setCodeMode(code, TEXT_EDIT_MODE); // setCodeMode(code, TEXT_EDIT_MODE);
break; // break;
case SDLK_BACKSPACE: // case SDLK_BACKSPACE:
if(*code->popup.text) // if(*code->popup.text)
{ // {
code->popup.text[strlen(code->popup.text)-1] = '\0'; // code->popup.text[strlen(code->popup.text)-1] = '\0';
updateGotoCode(code); // updateGotoCode(code);
} // }
break; // break;
default: break; // default: break;
} // }
break; // break;
case SDL_TEXTINPUT: // case SDL_TEXTINPUT:
if(strlen(event->text.text) == 1) // if(strlen(event->text.text) == 1)
{ // {
char sym = *event->text.text; // char sym = *event->text.text;
if(strlen(code->popup.text)+1 < sizeof code->popup.text && sym >= '0' && sym <= '9') // if(strlen(code->popup.text)+1 < sizeof code->popup.text && sym >= '0' && sym <= '9')
{ // {
strcat(code->popup.text, event->text.text); // strcat(code->popup.text, event->text.text);
updateGotoCode(code); // updateGotoCode(code);
} // }
} // }
break; // break;
default: break; // default: break;
} // }
} // }
code->tic->api.clear(code->tic, getConfig()->theme.code.bg); code->tic->api.clear(code->tic, getConfig()->theme.code.bg);
@ -1321,55 +1321,55 @@ static void drawOutlineBar(Code* code, s32 x, s32 y)
static void textOutlineTick(Code* code) static void textOutlineTick(Code* code)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
switch(event->key.keysym.sym) // switch(event->key.keysym.sym)
{ // {
case SDLK_UP: // case SDLK_UP:
if(code->outline.index > 0) // if(code->outline.index > 0)
{ // {
code->outline.index--; // code->outline.index--;
updateOutlineCode(code); // updateOutlineCode(code);
} // }
break; // break;
case SDLK_DOWN: // case SDLK_DOWN:
if(code->outline.index < OUTLINE_SIZE - 1 && code->outline.items[code->outline.index + 1].pos) // if(code->outline.index < OUTLINE_SIZE - 1 && code->outline.items[code->outline.index + 1].pos)
{ // {
code->outline.index++; // code->outline.index++;
updateOutlineCode(code); // updateOutlineCode(code);
} // }
break; // break;
case SDLK_RETURN: // case SDLK_RETURN:
updateOutlineCode(code); // updateOutlineCode(code);
setCodeMode(code, TEXT_EDIT_MODE); // setCodeMode(code, TEXT_EDIT_MODE);
break; // break;
case SDLK_BACKSPACE: // case SDLK_BACKSPACE:
if(*code->popup.text) // if(*code->popup.text)
{ // {
code->popup.text[strlen(code->popup.text)-1] = '\0'; // code->popup.text[strlen(code->popup.text)-1] = '\0';
setOutlineMode(code); // setOutlineMode(code);
} // }
break; // break;
default: break; // default: break;
} // }
break; // break;
case SDL_TEXTINPUT: // case SDL_TEXTINPUT:
if(strlen(event->text.text) == 1) // if(strlen(event->text.text) == 1)
{ // {
if(strlen(code->popup.text) + 1 < sizeof code->popup.text) // if(strlen(code->popup.text) + 1 < sizeof code->popup.text)
{ // {
strcat(code->popup.text, event->text.text); // strcat(code->popup.text, event->text.text);
setOutlineMode(code); // setOutlineMode(code);
} // }
} // }
break; // break;
default: break; // default: break;
} // }
} // }
code->tic->api.clear(code->tic, getConfig()->theme.code.bg); code->tic->api.clear(code->tic, getConfig()->theme.code.bg);

View File

@ -2537,81 +2537,81 @@ static void checkNewVersion(Console* console)
static void tick(Console* console) static void tick(Console* console)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_MOUSEWHEEL: // case SDL_MOUSEWHEEL:
{ // {
enum{Scroll = 3}; // enum{Scroll = 3};
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; // s32 delta = event->wheel.y > 0 ? -Scroll : Scroll;
setScroll(console, console->scroll.pos + delta); // setScroll(console, console->scroll.pos + delta);
} // }
break; // break;
case SDL_KEYDOWN: // case SDL_KEYDOWN:
{ // {
switch(event->key.keysym.sym) // switch(event->key.keysym.sym)
{ // {
case SDLK_UP: // case SDLK_UP:
onHistoryUp(console); // onHistoryUp(console);
break; // break;
case SDLK_DOWN: // case SDLK_DOWN:
onHistoryDown(console); // onHistoryDown(console);
break; // break;
case SDLK_RIGHT: // case SDLK_RIGHT:
{ // {
console->inputPosition++; // console->inputPosition++;
size_t len = strlen(console->inputBuffer); // size_t len = strlen(console->inputBuffer);
if(console->inputPosition > len) // if(console->inputPosition > len)
console->inputPosition = len; // console->inputPosition = len;
} // }
break; // break;
case SDLK_LEFT: // case SDLK_LEFT:
{ // {
if(console->inputPosition > 0) // if(console->inputPosition > 0)
console->inputPosition--; // console->inputPosition--;
} // }
break; // break;
case SDLK_RETURN: processConsoleCommand(console); break; // case SDLK_RETURN: processConsoleCommand(console); break;
case SDLK_BACKSPACE: processConsoleBackspace(console); break; // case SDLK_BACKSPACE: processConsoleBackspace(console); break;
case SDLK_DELETE: processConsoleDel(console); break; // case SDLK_DELETE: processConsoleDel(console); break;
case SDLK_HOME: processConsoleHome(console); break; // case SDLK_HOME: processConsoleHome(console); break;
case SDLK_END: processConsoleEnd(console); break; // case SDLK_END: processConsoleEnd(console); break;
case SDLK_TAB: processConsoleTab(console); break; // case SDLK_TAB: processConsoleTab(console); break;
default: break; // default: break;
} // }
scrollConsole(console); // scrollConsole(console);
console->cursor.delay = CONSOLE_CURSOR_DELAY; // console->cursor.delay = CONSOLE_CURSOR_DELAY;
} // }
break; // break;
case SDL_TEXTINPUT: // case SDL_TEXTINPUT:
{ // {
const char* symbol = event->text.text; // const char* symbol = event->text.text;
if(strlen(symbol) == 1) // if(strlen(symbol) == 1)
{ // {
char sym = *symbol; // char sym = *symbol;
size_t size = strlen(console->inputBuffer); // size_t size = strlen(console->inputBuffer);
if(size < sizeof(console->inputBuffer)) // if(size < sizeof(console->inputBuffer))
{ // {
char* pos = console->inputBuffer + console->inputPosition; // char* pos = console->inputBuffer + console->inputPosition;
memmove(pos + 1, pos, strlen(pos)); // memmove(pos + 1, pos, strlen(pos));
*(console->inputBuffer + console->inputPosition) = sym; // *(console->inputBuffer + console->inputPosition) = sym;
console->inputPosition++; // console->inputPosition++;
} // }
} // }
console->cursor.delay = CONSOLE_CURSOR_DELAY; // console->cursor.delay = CONSOLE_CURSOR_DELAY;
} // }
break; // break;
} // }
} // }
processGesture(console); processGesture(console);

View File

@ -191,16 +191,16 @@ static void drawDialog(Dialog* dlg)
static void tick(Dialog* dlg) static void tick(Dialog* dlg)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(dlg, &event->key.keysym); // processKeydown(dlg, &event->key.keysym);
break; // break;
} // }
} // }
if(!dlg->init) if(!dlg->init)
{ {

521
src/main.c Normal file
View File

@ -0,0 +1,521 @@
#include "main.h"
#include "studio.h"
#define STUDIO_UI_SCALE 3
#define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
#define TEXTURE_SIZE (TIC80_FULLWIDTH)
#define OFFSET_LEFT ((TIC80_FULLWIDTH-TIC80_WIDTH)/2)
#define OFFSET_TOP ((TIC80_FULLHEIGHT-TIC80_HEIGHT)/2)
static struct
{
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Texture* texture;
struct
{
SDL_AudioSpec spec;
SDL_AudioDeviceID device;
SDL_AudioCVT cvt;
} audio;
bool quitFlag;
bool missedFrame;
} platform;
static void initSound()
{
SDL_AudioSpec want =
{
.freq = 44100,
.format = AUDIO_S16,
.channels = 1,
.userdata = NULL,
};
platform.audio.device = SDL_OpenAudioDevice(NULL, 0, &want, &platform.audio.spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDL_BuildAudioCVT(&platform.audio.cvt, want.format, want.channels, platform.audio.spec.freq, platform.audio.spec.format, platform.audio.spec.channels, platform.audio.spec.freq);
if(platform.audio.cvt.needed)
{
platform.audio.cvt.len = platform.audio.spec.freq * sizeof(s16) / TIC_FRAMERATE;
platform.audio.cvt.buf = SDL_malloc(platform.audio.cvt.len * platform.audio.cvt.len_mult);
}
}
static void setWindowIcon()
{
// enum{ Size = 64, TileSize = 16, ColorKey = 14, Cols = TileSize / TIC_SPRITESIZE, Scale = Size/TileSize};
// studio.tic->api.clear(studio.tic, 0);
// u32* pixels = SDL_malloc(Size * Size * sizeof(u32));
// const u32* pal = tic_palette_blit(&studio.tic->config.palette);
// for(s32 j = 0, index = 0; j < Size; j++)
// for(s32 i = 0; i < Size; i++, index++)
// {
// u8 color = getSpritePixel(studio.tic->config.bank0.tiles.data, i/Scale, j/Scale);
// pixels[index] = color == ColorKey ? 0 : pal[color];
// }
// SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(pixels, Size, Size,
// sizeof(s32) * BITS_IN_BYTE, Size * sizeof(s32),
// 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
// SDL_SetWindowIcon(platform.window, surface);
// SDL_FreeSurface(surface);
// SDL_free(pixels);
}
static void updateGamepadParts()
{
// s32 tileSize = TIC_SPRITESIZE;
// s32 offset = 0;
// SDL_Rect rect;
// const s32 JoySize = 3;
// SDL_GetWindowSize(platform.window, &rect.w, &rect.h);
// if(rect.w < rect.h)
// {
// tileSize = rect.w / 2 / JoySize;
// offset = (rect.h * 2 - JoySize * tileSize) / 3;
// }
// else
// {
// tileSize = rect.w / 5 / JoySize;
// offset = (rect.h - JoySize * tileSize) / 2;
// }
// studio.gamepad.part.size = tileSize;
// studio.gamepad.part.axis = (SDL_Point){0, offset};
// studio.gamepad.part.a = (SDL_Point){rect.w - 2*tileSize, 2*tileSize + offset};
// studio.gamepad.part.b = (SDL_Point){rect.w - 1*tileSize, 1*tileSize + offset};
// studio.gamepad.part.x = (SDL_Point){rect.w - 3*tileSize, 1*tileSize + offset};
// studio.gamepad.part.y = (SDL_Point){rect.w - 2*tileSize, 0*tileSize + offset};
}
static void transparentBlit(u32* out, s32 pitch)
{
// const u8* in = studio.tic->ram.vram.screen.data;
// const u8* end = in + sizeof(studio.tic->ram.vram.screen);
// const u32* pal = tic_palette_blit(&studio.tic->config.palette);
// const u32 Delta = (pitch/sizeof *out - TIC80_WIDTH);
// s32 col = 0;
// while(in != end)
// {
// u8 low = *in & 0x0f;
// u8 hi = (*in & 0xf0) >> TIC_PALETTE_BPP;
// *out++ = low ? (*(pal + low) | 0xff000000) : 0;
// *out++ = hi ? (*(pal + hi) | 0xff000000) : 0;
// in++;
// col += BITS_IN_BYTE / TIC_PALETTE_BPP;
// if (col == TIC80_WIDTH)
// {
// col = 0;
// out += Delta;
// }
// }
}
static void initTouchGamepad()
{
// if (!platform.renderer)
// return;
// studio.tic->api.map(studio.tic, &studio.tic->config.bank0.map, &studio.tic->config.bank0.tiles, 0, 0, TIC_MAP_SCREEN_WIDTH, TIC_MAP_SCREEN_HEIGHT, 0, 0, -1, 1);
// if(!studio.gamepad.texture)
// {
// studio.gamepad.texture = SDL_CreateTexture(platform.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE);
// SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND);
// }
// {
// void* pixels = NULL;
// s32 pitch = 0;
// SDL_LockTexture(studio.gamepad.texture, NULL, &pixels, &pitch);
// transparentBlit(pixels, pitch);
// SDL_UnlockTexture(studio.gamepad.texture);
// }
// updateGamepadParts();
}
static SDL_Event* pollEvent()
{
static SDL_Event event;
if(SDL_PollEvent(&event))
{
switch(event.type)
{
// case SDL_KEYDOWN:
// if(processShortcuts(&event.key)) return NULL;
// break;
// case SDL_JOYDEVICEADDED:
// {
// s32 id = event.jdevice.which;
// if (id < TIC_GAMEPADS)
// {
// if(studio.joysticks[id])
// SDL_JoystickClose(studio.joysticks[id]);
// studio.joysticks[id] = SDL_JoystickOpen(id);
// }
// }
// break;
// case SDL_JOYDEVICEREMOVED:
// {
// s32 id = event.jdevice.which;
// if (id < TIC_GAMEPADS && studio.joysticks[id])
// {
// SDL_JoystickClose(studio.joysticks[id]);
// studio.joysticks[id] = NULL;
// }
// }
// break;
// case SDL_WINDOWEVENT:
// switch(event.window.event)
// {
// case SDL_WINDOWEVENT_RESIZED: updateGamepadParts(); break;
// case SDL_WINDOWEVENT_FOCUS_GAINED:
// #if defined(TIC80_PRO)
// if(studio.mode != TIC_START_MODE)
// {
// Console* console = studio.console;
// u64 mdate = fsMDate(console->fs, console->romName);
// if(studio.cart.mdate && mdate > studio.cart.mdate)
// {
// if(studioCartChanged())
// {
// static const char* Rows[] =
// {
// "",
// "CART HAS CHANGED!",
// "",
// "DO YOU WANT",
// "TO RELOAD IT?"
// };
// showDialog(Rows, COUNT_OF(Rows), reloadConfirm, NULL);
// }
// else console->updateProject(console);
// }
// }
// #endif
// {
// Code* code = studio.editor[studio.bank.index.code].code;
// studio.console->codeLiveReload.reload(studio.console, code->src);
// if(studio.console->codeLiveReload.active && code->update)
// code->update(code);
// }
// break;
// }
// break;
// case SDL_FINGERUP:
// showSoftKeyboard();
// break;
case SDL_QUIT:
platform.quitFlag = true;
// exitStudio();
break;
default:
break;
}
return &event;
}
// if(studio.mode != TIC_RUN_MODE)
// processGesture();
// if(!studio.gesture.active)
// processMouse();
// if(studio.mode == TIC_RUN_MODE)
// {
// if(studio.tic->input.gamepad) processGamepadInput();
// if(studio.tic->input.mouse) processMouseInput();
// if(studio.tic->input.keyboard) processKeyboardInput();
// }
// else
// {
// processGamepadInput();
// }
return NULL;
}
static void calcTextureRect(SDL_Rect* rect)
{
SDL_GetWindowSize(platform.window, &rect->w, &rect->h);
if (rect->w * TIC80_HEIGHT < rect->h * TIC80_WIDTH)
{
s32 discreteWidth = rect->w - rect->w % TIC80_WIDTH;
s32 discreteHeight = TIC80_HEIGHT * discreteWidth / TIC80_WIDTH;
rect->x = (rect->w - discreteWidth) / 2;
rect->y = rect->w > rect->h
? (rect->h - discreteHeight) / 2
: OFFSET_LEFT*discreteWidth/TIC80_WIDTH;
rect->w = discreteWidth;
rect->h = discreteHeight;
}
else
{
s32 discreteHeight = rect->h - rect->h % TIC80_HEIGHT;
s32 discreteWidth = TIC80_WIDTH * discreteHeight / TIC80_HEIGHT;
rect->x = (rect->w - discreteWidth) / 2;
rect->y = (rect->h - discreteHeight) / 2;
rect->w = discreteWidth;
rect->h = discreteHeight;
}
}
static void blitTexture()
{
// tic_mem* tic = studio.tic;
SDL_Rect rect = {0, 0, 0, 0};
calcTextureRect(&rect);
void* pixels = NULL;
s32 pitch = 0;
SDL_LockTexture(platform.texture, NULL, &pixels, &pitch);
studioTick(pixels);
// tic_scanline scanline = NULL;
// tic_overlap overlap = NULL;
// void* data = NULL;
// switch(studio.mode)
// {
// case TIC_RUN_MODE:
// scanline = tic->api.scanline;
// overlap = tic->api.overlap;
// break;
// case TIC_SPRITE_MODE:
// {
// Sprite* sprite = studio.editor[studio.bank.index.sprites].sprite;
// overlap = sprite->overlap;
// data = sprite;
// }
// break;
// case TIC_MAP_MODE:
// {
// Map* map = studio.editor[studio.bank.index.map].map;
// overlap = map->overlap;
// data = map;
// }
// break;
// default:
// break;
// }
// tic->api.blit(tic, scanline, overlap, data);
// SDL_memcpy(pixels, tic->screen, sizeof tic->screen);
// recordFrame(pixels);
// drawDesyncLabel(pixels);
SDL_UnlockTexture(platform.texture);
{
enum {Header = OFFSET_TOP};
SDL_Rect srcRect = {0, 0, TIC80_FULLWIDTH, Header};
SDL_Rect dstRect = {0};
SDL_GetWindowSize(platform.window, &dstRect.w, &dstRect.h);
dstRect.h = rect.y;
SDL_RenderCopy(platform.renderer, platform.texture, &srcRect, &dstRect);
}
{
enum {Header = OFFSET_TOP};
SDL_Rect srcRect = {0, TIC80_FULLHEIGHT - Header, TIC80_FULLWIDTH, Header};
SDL_Rect dstRect = {0};
SDL_GetWindowSize(platform.window, &dstRect.w, &dstRect.h);
dstRect.y = rect.y + rect.h;
dstRect.h = rect.y;
SDL_RenderCopy(platform.renderer, platform.texture, &srcRect, &dstRect);
}
{
enum {Header = OFFSET_TOP};
enum {Left = OFFSET_LEFT};
SDL_Rect srcRect = {0, Header, Left, TIC80_HEIGHT};
SDL_Rect dstRect = {0};
SDL_GetWindowSize(platform.window, &dstRect.w, &dstRect.h);
dstRect.y = rect.y;
dstRect.h = rect.h;
SDL_RenderCopy(platform.renderer, platform.texture, &srcRect, &dstRect);
}
{
enum {Top = OFFSET_TOP};
enum {Left = OFFSET_LEFT};
SDL_Rect srcRect = {Left, Top, TIC80_WIDTH, TIC80_HEIGHT};
SDL_RenderCopy(platform.renderer, platform.texture, &srcRect, &rect);
}
}
static void tick()
{
pollEvent();
// if(!studio.fs) return;
// if(studio.quitFlag)
// {
// #if defined __EMSCRIPTEN__
// studio.tic->api.clear(studio.tic, TIC_COLOR_BG);
// blitTexture();
// emscripten_cancel_main_loop();
// #endif
// return;
// }
// SDL_SystemCursor cursor = studio.mouse.system;
// studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
SDL_RenderClear(platform.renderer);
// if(studio.mode == TIC_RUN_MODE && studio.tic->input.gamepad)
// renderGamepad();
// if(studio.mode == TIC_MENU_MODE || studio.mode == TIC_SURF_MODE)
// renderGamepad();
// if(studio.mouse.system != cursor)
// SDL_SetCursor(SDL_CreateSystemCursor(studio.mouse.system));
blitTexture();
SDL_RenderPresent(platform.renderer);
// blitSound();
}
s32 main(s32 argc, char **argv)
{
SDL_SetHint(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, "1");
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
initSound();
platform.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
(TIC80_FULLWIDTH) * STUDIO_UI_SCALE,
(TIC80_FULLHEIGHT) * STUDIO_UI_SCALE,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
#if defined(__CHIP__)
| SDL_WINDOW_FULLSCREEN_DESKTOP
#endif
);
// set the window icon before renderer is created (issues on Linux)
setWindowIcon();
platform.renderer = SDL_CreateRenderer(platform.window, -1,
#if defined(__CHIP__)
SDL_RENDERER_SOFTWARE
#elif defined(__EMSCRIPTEN__)
SDL_RENDERER_ACCELERATED
#else
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC//(getConfig()->useVsync ? SDL_RENDERER_PRESENTVSYNC : 0)
#endif
);
platform.texture = SDL_CreateTexture(platform.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING, TEXTURE_SIZE, TEXTURE_SIZE);
initTouchGamepad();
studioInit(argc, argv);
#if defined(__EMSCRIPTEN__)
emscripten_set_main_loop(emstick, TIC_FRAMERATE, 1);
#else
{
bool useDelay = false;
{
SDL_RendererInfo info;
SDL_DisplayMode mode;
SDL_GetRendererInfo(platform.renderer, &info);
SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(platform.window), &mode);
useDelay = !(info.flags & SDL_RENDERER_PRESENTVSYNC) || mode.refresh_rate > TIC_FRAMERATE;
}
u64 nextTick = SDL_GetPerformanceCounter();
const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE;
while (!platform.quitFlag)
{
platform.missedFrame = false;
nextTick += Delta;
tick();
{
s64 delay = nextTick - SDL_GetPerformanceCounter();
if(delay < 0)
{
nextTick -= delay;
platform.missedFrame = true;
}
else
{
if(useDelay || SDL_GetWindowFlags(platform.window) & SDL_WINDOW_MINIMIZED)
{
u32 time = (u32)(delay * 1000 / SDL_GetPerformanceFrequency());
if(time >= 10)
SDL_Delay(time);
}
}
}
}
}
#endif
studioClose();
SDL_DestroyTexture(platform.texture);
SDL_DestroyRenderer(platform.renderer);
SDL_DestroyWindow(platform.window);
SDL_CloseAudioDevice(platform.audio.device);
return 0;
}

1
src/main.h Normal file
View File

@ -0,0 +1 @@
#pragma once

View File

@ -1100,19 +1100,19 @@ static void tick(Map* map)
{ {
map->tickCounter++; map->tickCounter++;
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(map, event->key.keysym.sym); // processKeydown(map, event->key.keysym.sym);
break; // break;
case SDL_KEYUP: // case SDL_KEYUP:
processKeyup(map, event->key.keysym.sym); // processKeyup(map, event->key.keysym.sym);
break; // break;
} // }
} // }
processKeyboard(map); processKeyboard(map);
processGesture(map); processGesture(map);

View File

@ -458,16 +458,16 @@ static void tick(Menu* menu)
{ {
menu->ticks++; menu->ticks++;
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYUP: // case SDL_KEYUP:
processKeydown(menu, &event->key.keysym); // processKeydown(menu, &event->key.keysym);
break; // break;
} // }
} // }
if(getStudioMode() != TIC_MENU_MODE) if(getStudioMode() != TIC_MENU_MODE)
return; return;

View File

@ -1529,8 +1529,8 @@ static void drawMusicToolbar(Music* music)
static void drawPianoLayout(Music* music) static void drawPianoLayout(Music* music)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())){} // while ((event = pollEvent())){}
music->tic->api.clear(music->tic, (tic_color_gray)); music->tic->api.clear(music->tic, (tic_color_gray));
@ -1571,34 +1571,34 @@ static void scrollNotes(Music* music, s32 delta)
static void drawTrackerLayout(Music* music) static void drawTrackerLayout(Music* music)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch (event->type) // switch (event->type)
{ // {
case SDL_MOUSEWHEEL: // case SDL_MOUSEWHEEL:
if(SDL_GetModState() & TIC_MOD_CTRL) // if(SDL_GetModState() & TIC_MOD_CTRL)
{ // {
scrollNotes(music, event->wheel.y > 0 ? 1 : -1); // scrollNotes(music, event->wheel.y > 0 ? 1 : -1);
} // }
else // else
{ // {
enum{Scroll = NOTES_PER_BEET}; // enum{Scroll = NOTES_PER_BEET};
s32 delta = event->wheel.y > 0 ? -Scroll : Scroll; // s32 delta = event->wheel.y > 0 ? -Scroll : Scroll;
music->tracker.scroll += delta; // music->tracker.scroll += delta;
updateScroll(music); // updateScroll(music);
} // }
break; // break;
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(music, &event->key.keysym); // processKeydown(music, &event->key.keysym);
break; // break;
case SDL_KEYUP: // case SDL_KEYUP:
processKeyup(music, &event->key.keysym); // processKeyup(music, &event->key.keysym);
break; // break;
} // }
} // }
if(music->tracker.follow) if(music->tracker.follow)
{ {

View File

@ -86,7 +86,7 @@ static void initPMemName(Run* run)
static void tick(Run* run) static void tick(Run* run)
{ {
while(pollEvent()); // while(pollEvent());
if (getStudioMode() != TIC_RUN_MODE) if (getStudioMode() != TIC_RUN_MODE)
return; return;
@ -169,7 +169,7 @@ static void preseed()
static bool forceExit(void* data) static bool forceExit(void* data)
{ {
while(pollEvent()); // while(pollEvent());
return getStudioMode() != TIC_RUN_MODE; return getStudioMode() != TIC_RUN_MODE;
} }

View File

@ -823,16 +823,16 @@ static void drawSfxToolbar(Sfx* sfx)
static void envelopesTick(Sfx* sfx) static void envelopesTick(Sfx* sfx)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(sfx, event->key.keysym.sym); // processKeydown(sfx, event->key.keysym.sym);
break; // break;
} // }
} // }
processKeyboard(sfx); processKeyboard(sfx);
@ -954,16 +954,16 @@ static void drawWaveformCanvas(Sfx* sfx, s32 x, s32 y)
static void waveformTick(Sfx* sfx) static void waveformTick(Sfx* sfx)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processWaveformKeydown(sfx, event->key.keysym.sym); // processWaveformKeydown(sfx, event->key.keysym.sym);
break; // break;
} // }
} // }
processKeyboard(sfx); processKeyboard(sfx);

View File

@ -1589,30 +1589,30 @@ static void drawSpriteToolbar(Sprite* sprite)
static void tick(Sprite* sprite) static void tick(Sprite* sprite)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(sprite, event->key.keysym.sym); // processKeydown(sprite, event->key.keysym.sym);
break; // break;
case SDL_MOUSEWHEEL: // case SDL_MOUSEWHEEL:
{ // {
s32 size = sprite->size; // s32 size = sprite->size;
s32 delta = event->wheel.y; // s32 delta = event->wheel.y;
if(delta > 0) // if(delta > 0)
{ // {
if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1; // if(size < (TIC_SPRITESIZE * TIC_SPRITESIZE)) size <<= 1;
} // }
else if(size > TIC_SPRITESIZE) size >>= 1; // else if(size > TIC_SPRITESIZE) size >>= 1;
updateSpriteSize(sprite, size); // updateSpriteSize(sprite, size);
} // }
break; // break;
} // }
} // }
sprite->tic->api.clear(sprite->tic, (tic_color_gray)); sprite->tic->api.clear(sprite->tic, (tic_color_gray));

View File

@ -78,7 +78,7 @@ static void tick(Start* start)
start->initialized = true; start->initialized = true;
} }
while (pollEvent()); // while (pollEvent());
start->tic->api.clear(start->tic, TIC_COLOR_BG); start->tic->api.clear(start->tic, TIC_COLOR_BG);

File diff suppressed because it is too large Load Diff

View File

@ -122,7 +122,7 @@ typedef enum
TIC_SURF_MODE, TIC_SURF_MODE,
} EditorMode; } EditorMode;
SDL_Event* pollEvent(); // SDL_Event* pollEvent();
void setCursor(SDL_SystemCursor id); void setCursor(SDL_SystemCursor id);
s32 getMouseX(); s32 getMouseX();
@ -198,3 +198,8 @@ void runProject();
tic_tiles* getBankTiles(); tic_tiles* getBankTiles();
tic_map* getBankMap(); tic_map* getBankMap();
s32 studioInit(s32 argc, char **argv);
void studioTick(void* pixels);
void studioClose();

View File

@ -803,7 +803,7 @@ static void tick(Surf* surf)
surf->ticks++; surf->ticks++;
while (pollEvent()); // while (pollEvent());
tic_mem* tic = surf->tic; tic_mem* tic = surf->tic;

View File

@ -71,16 +71,16 @@ static void processKeydown(World* world, SDL_Keycode keycode)
static void tick(World* world) static void tick(World* world)
{ {
SDL_Event* event = NULL; // SDL_Event* event = NULL;
while ((event = pollEvent())) // while ((event = pollEvent()))
{ // {
switch(event->type) // switch(event->type)
{ // {
case SDL_KEYDOWN: // case SDL_KEYDOWN:
processKeydown(world, event->key.keysym.sym); // processKeydown(world, event->key.keysym.sym);
break; // break;
} // }
} // }
SDL_memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE); SDL_memcpy(&world->tic->ram.vram, world->preview, PREVIEW_SIZE);