this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

#1247: Added headless mode to run console commands (use `--cli` argument), also fixed batch commands processing

Nesbox 29aa5fda 92884fe3

+99 -71
+21 -14
src/studio/screens/console.c
··· 2012 2012 if(params.id >= 0 && params.id < SFX_COUNT) 2013 2013 error = studioExportSfx(params.id, filename) == NULL; 2014 2014 2015 - onFileExported(console, filename, error); 2015 + onFileExported(console, filename, !error); 2016 2016 } 2017 2017 2018 2018 static void onExport_music(Console* console, const char* type, const char* name, ExportParams params) ··· 2023 2023 if(params.id >= 0 && params.id < MUSIC_TRACKS) 2024 2024 error = studioExportMusic(params.id, filename) == NULL; 2025 2025 2026 - onFileExported(console, filename, error); 2026 + onFileExported(console, filename, !error); 2027 2027 } 2028 2028 2029 2029 static void onExport_screen(Console* console, const char* param, const char* name, ExportParams params) ··· 2941 2941 2942 2942 static void printTable(Console* console, const char* text) 2943 2943 { 2944 + #ifndef BAREMETALPI 2944 2945 printf("%s", text); 2946 + #endif 2945 2947 2946 2948 for(const char* textPointer = text, *endText = textPointer + strlen(text); textPointer != endText;) 2947 2949 { ··· 3087 3089 { 3088 3090 const char* command = console->desc->command; 3089 3091 3090 - printf("%s", console->desc->command); 3091 - 3092 3092 FOR(const Command*, cmd, Commands) 3093 3093 if(casecmp(console->desc->command, cmd->name) == 0 || 3094 3094 (cmd->alt && casecmp(console->desc->command, cmd->alt) == 0)) ··· 3111 3111 3112 3112 static void processCommands(Console* console) 3113 3113 { 3114 - char* command = strdup(console->args.cmd); 3114 + char* command = console->args.cmd; 3115 3115 static const char Sep[] = " & "; 3116 3116 char* next = strstr(command, Sep); 3117 3117 ··· 3125 3125 3126 3126 printFront(console, command); 3127 3127 processCommand(console, command); 3128 - 3129 - free(command); 3130 3128 } 3131 3129 3132 3130 static void fillHistory(Console* console) ··· 3182 3180 3183 3181 if(commandSize) 3184 3182 { 3183 + printf(console->input.text); 3185 3184 appendHistory(console, console->input.text); 3186 3185 processCommand(console, console->input.text); 3187 3186 } ··· 3520 3519 { 3521 3520 loadDemo(console, 0); 3522 3521 3523 - printBack(console, "\n hello! type "); 3524 - printFront(console, "help"); 3525 - printBack(console, " for help\n"); 3522 + if(!console->args.skip) 3523 + { 3524 + printBack(console, "\n hello! type "); 3525 + printFront(console, "help"); 3526 + printBack(console, " for help\n"); 3526 3527 3527 - if(getConfig()->checkNewVersion) 3528 - tic_net_get(console->net, "/api?fn=version", onHttpVesrsionGet, console); 3528 + if(getConfig()->checkNewVersion) 3529 + tic_net_get(console->net, "/api?fn=version", onHttpVesrsionGet, console); 3530 + } 3529 3531 3530 3532 commandDone(console); 3531 3533 } ··· 3567 3569 3568 3570 drawCursor(console); 3569 3571 3570 - if(console->active && console->args.cmd) 3571 - processCommands(console); 3572 + if(console->active) 3573 + { 3574 + if(console->args.cmd) 3575 + processCommands(console); 3576 + else if(getConfig()->cli) 3577 + exitStudio(); 3578 + } 3572 3579 } 3573 3580 3574 3581 console->tickCounter++;
+5
src/studio/studio.c
··· 2060 2060 OPT_HELP(), 2061 2061 OPT_BOOLEAN('\0', "skip", &args.skip, "skip startup animation"), 2062 2062 OPT_BOOLEAN('\0', "nosound", &args.nosound, "disable sound output"), 2063 + OPT_BOOLEAN('\0', "cli", &args.cli, "console only output"), 2063 2064 OPT_BOOLEAN('\0', "fullscreen", &args.fullscreen, "enable fullscreen mode"), 2064 2065 OPT_STRING('\0', "fs", &args.fs, "path to the file system folder"), 2065 2066 OPT_INTEGER('\0', "scale", &args.scale, "main window scale"), ··· 2145 2146 2146 2147 impl.config->data.goFullscreen = args.fullscreen; 2147 2148 impl.config->data.noSound = args.nosound; 2149 + impl.config->data.cli = args.cli; 2148 2150 2149 2151 impl.studio.tick = studioTick; 2150 2152 impl.studio.close = studioClose; 2151 2153 impl.studio.updateProject = updateStudioProject; 2152 2154 impl.studio.exit = exitStudio; 2153 2155 impl.studio.config = getConfig; 2156 + 2157 + if(args.cli) 2158 + args.skip = true; 2154 2159 2155 2160 if(args.skip) 2156 2161 setStudioMode(TIC_CONSOLE_MODE);
+1
src/studio/studio.h
··· 75 75 { 76 76 bool skip; 77 77 bool nosound; 78 + bool cli; 78 79 bool fullscreen; 79 80 s32 scale; 80 81 char *fs;
+1
src/studio/system.h
··· 114 114 115 115 bool checkNewVersion; 116 116 bool noSound; 117 + bool cli; 117 118 118 119 #if defined(CRT_SHADER_SUPPORT) 119 120 bool crtMonitor;
+58 -52
src/system/sdl/main.c
··· 1575 1575 1576 1576 static s32 start(s32 argc, char **argv, const char* folder) 1577 1577 { 1578 - SDL_SetHint(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, "1"); 1579 - SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); 1580 - 1581 - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); 1582 - 1583 - initSound(); 1578 + DEFER(platform.studio = studioInit(argc, argv, TIC80_SAMPLERATE, folder), platform.studio->close()) 1579 + { 1580 + if (platform.studio->config()->cli) 1581 + { 1582 + while (!platform.studio->quit) 1583 + platform.studio->tick(); 1584 + } 1585 + else 1586 + { 1587 + SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); 1588 + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); 1584 1589 1585 - platform.studio = studioInit(argc, argv, platform.audio.spec.freq, folder); 1590 + initSound(); 1586 1591 1587 - { 1588 - const s32 Width = TIC80_FULLWIDTH * platform.studio->config()->uiScale; 1589 - const s32 Height = TIC80_FULLHEIGHT * platform.studio->config()->uiScale; 1592 + { 1593 + const s32 Width = TIC80_FULLWIDTH * platform.studio->config()->uiScale; 1594 + const s32 Height = TIC80_FULLHEIGHT * platform.studio->config()->uiScale; 1590 1595 1591 - platform.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1592 - Width, Height, SDL_WINDOW_SHOWN 1593 - | SDL_WINDOW_RESIZABLE 1596 + platform.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1597 + Width, Height, SDL_WINDOW_SHOWN 1598 + | SDL_WINDOW_RESIZABLE 1594 1599 #if defined(CRT_SHADER_SUPPORT) 1595 - | SDL_WINDOW_OPENGL 1600 + | SDL_WINDOW_OPENGL 1596 1601 #endif 1597 1602 #if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__) 1598 - | SDL_WINDOW_ALLOW_HIGHDPI 1603 + | SDL_WINDOW_ALLOW_HIGHDPI 1599 1604 #endif 1600 - ); 1605 + ); 1601 1606 1602 - setWindowIcon(); 1603 - createMouseCursors(); 1607 + setWindowIcon(); 1608 + createMouseCursors(); 1604 1609 1605 - initGPU(); 1610 + initGPU(); 1606 1611 1607 - if(platform.studio->config()->goFullscreen) 1608 - tic_sys_fullscreen(); 1609 - } 1612 + if(platform.studio->config()->goFullscreen) 1613 + tic_sys_fullscreen(); 1614 + } 1610 1615 1611 - SDL_PauseAudioDevice(platform.audio.device, 0); 1616 + SDL_PauseAudioDevice(platform.audio.device, 0); 1612 1617 1613 1618 #if defined(__EMSCRIPTEN__) 1614 - emscripten_set_main_loop(emsGpuTick, 0, 1); 1619 + emscripten_set_main_loop(emsGpuTick, 0, 1); 1615 1620 #else 1616 - { 1617 - u64 nextTick = SDL_GetPerformanceCounter(); 1618 - const u64 Delta = SDL_GetPerformanceFrequency() / TIC80_FRAMERATE; 1621 + { 1622 + u64 nextTick = SDL_GetPerformanceCounter(); 1623 + const u64 Delta = SDL_GetPerformanceFrequency() / TIC80_FRAMERATE; 1619 1624 1620 - while (!platform.studio->quit) 1621 - { 1622 - nextTick += Delta; 1623 - 1624 - gpuTick(); 1625 + while (!platform.studio->quit) 1626 + { 1627 + nextTick += Delta; 1628 + 1629 + gpuTick(); 1625 1630 1626 - { 1627 - s64 delay = nextTick - SDL_GetPerformanceCounter(); 1631 + { 1632 + s64 delay = nextTick - SDL_GetPerformanceCounter(); 1628 1633 1629 - if(delay < 0) 1630 - nextTick -= delay; 1631 - else 1632 - SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency())); 1634 + if(delay < 0) 1635 + nextTick -= delay; 1636 + else 1637 + SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency())); 1638 + } 1639 + } 1633 1640 } 1634 - } 1635 - } 1636 1641 1637 1642 #endif 1638 1643 1639 1644 #if defined(TOUCH_INPUT_SUPPORT) 1640 - if(SDL_IsTextInputActive()) 1641 - SDL_StopTextInput(); 1645 + if(SDL_IsTextInputActive()) 1646 + SDL_StopTextInput(); 1642 1647 #endif 1643 1648 1644 - platform.studio->close(); 1645 - 1646 - { 1647 - destroyGPU(); 1649 + { 1650 + destroyGPU(); 1648 1651 1649 1652 #if defined(TOUCH_INPUT_SUPPORT) 1650 - if(platform.gamepad.touch.pixels) 1651 - SDL_free(platform.gamepad.touch.pixels); 1653 + if(platform.gamepad.touch.pixels) 1654 + SDL_free(platform.gamepad.touch.pixels); 1652 1655 #endif 1653 1656 1654 - SDL_DestroyWindow(platform.window); 1655 - SDL_CloseAudioDevice(platform.audio.device); 1657 + SDL_DestroyWindow(platform.window); 1658 + SDL_CloseAudioDevice(platform.audio.device); 1659 + 1660 + for(s32 i = 0; i < COUNT_OF(platform.mouse.cursors); i++) 1661 + SDL_FreeCursor(platform.mouse.cursors[i]); 1662 + } 1656 1663 1657 - for(s32 i = 0; i < COUNT_OF(platform.mouse.cursors); i++) 1658 - SDL_FreeCursor(platform.mouse.cursors[i]); 1664 + } 1659 1665 } 1660 1666 1661 1667 return 0;
+13 -5
src/system/sokol/sokol.c
··· 170 170 sokol_gfx_draw(platform.studio->tic->screen); 171 171 172 172 s32 count = tic->samples.size / sizeof tic->samples.buffer[0]; 173 - for(s32 i = 0; i < count; i++) 174 - platform.audio.samples[i] = (float)tic->samples.buffer[i] / SHRT_MAX; 173 + for(s32 i = 0; i < count; i++) 174 + platform.audio.samples[i] = (float)tic->samples.buffer[i] / SHRT_MAX; 175 175 176 - saudio_push(platform.audio.samples, count / 2); 177 - 176 + saudio_push(platform.audio.samples, count / 2); 177 + 178 178 input->mouse.scrollx = input->mouse.scrolly = 0; 179 179 platform.keyboard.text = '\0'; 180 180 } ··· 404 404 platform.audio.desc.num_channels = TIC_STEREO_CHANNELS; 405 405 saudio_setup(&platform.audio.desc); 406 406 407 - platform.studio = studioInit(argc, (const char**)argv, saudio_sample_rate(), "./"); 407 + platform.studio = studioInit(argc, argv, saudio_sample_rate(), "./"); 408 + 409 + if(platform.studio->config()->cli) 410 + { 411 + while (!platform.studio->quit) 412 + platform.studio->tick(); 413 + 414 + exit(0); 415 + } 408 416 409 417 const s32 Width = TIC80_FULLWIDTH * platform.studio->config()->uiScale; 410 418 const s32 Height = TIC80_FULLHEIGHT * platform.studio->config()->uiScale;