Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override some scale settings; finer-grained SDL init #2007

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2367,7 +2367,7 @@ bool studio_alive(Studio* studio)
return studio->alive;
}

Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder)
Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* folder, s32 maxscale)
{
setbuf(stdout, NULL);

Expand Down Expand Up @@ -2483,6 +2483,13 @@ Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_f
tic_fs_makedir(studio->fs, TIC_LOCAL_VERSION);

initConfig(studio->config, studio, studio->fs);

if (studio->config->data.uiScale > maxscale)
{
printf("Overriding specified uiScale of %i; the maximum your screen will accommodate is %i", studio->config->data.uiScale, maxscale);
studio->config->data.uiScale = maxscale;
}

initStart(studio->start, studio, args.cart);
initRunMode(studio);

Expand Down
2 changes: 1 addition & 1 deletion src/studio/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void studio_exit(Studio* studio);
void studio_delete(Studio* studio);
const StudioConfig* studio_config(Studio* studio);

Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder);
Studio* studio_create(s32 argc, char **argv, s32 samplerate, tic80_pixel_color_format format, const char* appFolder, s32 maxscale);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions src/system/baremetalpi/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ TShutdownMode Run(void)
char* argv[] = { &arg0[0], NULL };
int argc = 1;
malloc(88);
platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80");
platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX);
malloc(99);

}
Expand All @@ -394,7 +394,7 @@ TShutdownMode Run(void)
char* argv[] = { &arg0[0], &arg1[0], NULL };
int argc = 2;
dbg("Without keyboard\n");
platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80");
platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX);
}
dbg("studio_create OK\n");

Expand Down
2 changes: 1 addition & 1 deletion src/system/n3ds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ int main(int argc, char **argv) {
n3ds_draw_init();
n3ds_keyboard_init(&platform.keyboard);

platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./");
platform.studio = studio_create(argc_used, argv_used, AUDIO_FREQ, TIC80_PIXEL_COLOR_ABGR8888, "./", INT32_MAX);

n3ds_sound_init(AUDIO_FREQ);

Expand Down
56 changes: 54 additions & 2 deletions src/system/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,10 +1662,62 @@ static void emsGpuTick()

#endif

s32 determineMaximumScale()
{
SDL_DisplayMode current;
int result = SDL_GetCurrentDisplayMode(0, &current);
s32 maxScale;

if (result != 0)
{
SDL_Log("Unable to SDL_GetCurrentDisplayMode: %s", SDL_GetError());
return INT32_MAX;
}

int maxScaleByW = current.w / TIC80_WIDTH;
int maxScaleByH = current.h / TIC80_HEIGHT;

if (maxScaleByW < maxScaleByW)
{
maxScale = maxScaleByW;
}
else
{
maxScale = maxScaleByH;
}

if (maxScale <= 1)
{
return 1;
}
else
{
return maxScale;
}
}

static s32 start(s32 argc, char **argv, const char* folder)
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder);
int result = SDL_Init(SDL_INIT_VIDEO);
if (result != 0)
{
SDL_Log("Unable to initialize SDL Video: %i, %s\n", result, SDL_GetError());
return result;
}

result = SDL_Init(SDL_INIT_AUDIO);
if (result != 0)
{
SDL_Log("Unable to initialize SDL Audio: %i, %s\n", result, SDL_GetError());
}

result = SDL_Init(SDL_INIT_JOYSTICK);
if (result != 0)
{
SDL_Log("Unable to initialize SDL Joystick: %i, %s\n", result, SDL_GetError());
}

platform.studio = studio_create(argc, argv, TIC80_SAMPLERATE, SCREEN_FORMAT, folder, determineMaximumScale());

SCOPE(studio_delete(platform.studio))
{
Expand Down
2 changes: 1 addition & 1 deletion src/system/sokol/sokol.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ sapp_desc sokol_main(s32 argc, char* argv[])
platform.audio.desc.num_channels = TIC80_SAMPLE_CHANNELS;
saudio_setup(&platform.audio.desc);

platform.studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./");
platform.studio = studio_create(argc, argv, saudio_sample_rate(), TIC80_PIXEL_COLOR_RGBA8888, "./", INT32_MAX);

if(studio_config(platform.studio)->cli)
{
Expand Down