Skip to content

Commit

Permalink
more work on terminal resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jan 22, 2025
1 parent eebd81d commit 5be2ddd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 32 deletions.
Binary file modified data/sounds.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ int main(int argc, char *argv[])
ERR("Sound init");
}
sound_load(0.5, "data/sounds/interface/click2.wav", "click");
sound_load(0.5, "data/sounds/interface/error.wav", "error");
LOG("INI: Loaded");
flush_the_console();
}
Expand Down
10 changes: 5 additions & 5 deletions src/my_ascii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
#include "my_tile.hpp"
#include "my_ui.hpp"

#define TERM_WIDTH_DEF 144
#define TERM_HEIGHT_DEF 80
#define TERM_WIDTH_DEF 200
#define TERM_HEIGHT_DEF 100

#define TERM_WIDTH_MIN 100
#define TERM_HEIGHT_MIN 60
#define TERM_HEIGHT_MIN 50

#define TERM_WIDTH_MAX (TERM_WIDTH_DEF * 2)
#define TERM_HEIGHT_MAX (TERM_HEIGHT_DEF * 2)
#define TERM_WIDTH_MAX TERM_WIDTH_DEF
#define TERM_HEIGHT_MAX TERM_HEIGHT_DEF

class AsciiCell
{
Expand Down
8 changes: 6 additions & 2 deletions src/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ void config_game_gfx_update(void)
if (TERM_HEIGHT >= TERM_HEIGHT_MAX) {
LOG("SDL: Terminal (curr %ux%u min %ux%u max %ux%u font %ux%u) beyond max bounds", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
TERM_HEIGHT = TERM_WIDTH_MAX;
TERM_HEIGHT = TERM_HEIGHT_MAX;
continue;
}

Expand All @@ -805,7 +805,11 @@ void config_game_gfx_update(void)
}

if (tries < 0) {
LOG("SDL: Terminal (curr %ux%u min %ux%u max %ux%u font %ux%u) best effort", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH = TERM_WIDTH_MIN;
TERM_HEIGHT = TERM_HEIGHT_MIN;
font_width = game_window_pix_width_get(game) / TERM_WIDTH;
font_height = game_window_pix_height_get(game) / TERM_HEIGHT;
CON("SDL: Terminal (curr %ux%u min %ux%u max %ux%u font %ux%u) best effort", TERM_WIDTH, TERM_HEIGHT,
TERM_WIDTH_MIN, TERM_HEIGHT_MIN, TERM_WIDTH_MAX, TERM_HEIGHT_MAX, font_width, font_height);
}

Expand Down
42 changes: 23 additions & 19 deletions src/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
#include "my_game.hpp"
#include "my_string.hpp"

#include <errno.h>
#include <libproc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <unistd.h>

void callstack_dump(void)
{
Expand Down Expand Up @@ -46,8 +51,6 @@ std::string callstack_string(void)
return std::string(tmp);
}

#ifdef ENABLE_CRASH_HANDLER

#include <assert.h>
#ifndef _WIN32
#include <sys/wait.h>
Expand All @@ -58,29 +61,29 @@ std::string callstack_string(void)
#include <sys/prctl.h>
#endif

#ifdef __APPLE__
#endif

#ifndef PATH_MAX
#define PATH_MAX 512
#endif

#if defined __linux__
//
// Should work on linux only.
//
#ifndef __APPLE__
static void debug_crash_handler(int sig)
{
fprintf(stderr, "debug_crash_handler: Error: Signal %d:\n", sig);

std::string pid(std::to_string(getpid()));
std::string pid_str(std::to_string(getpid()));

const size_t max_path = PATH_MAX + 1;
char prog_name[ max_path ];

#if defined __APPLE__
uint32_t bufsize = max_path;
_NSGetExecutablePath(prog_name, &bufsize);
auto pid_num = getpid();
auto ret = proc_pidpath(pid_num, prog_name, sizeof(prog_name));
if (ret <= 0) {
fprintf(stderr, "PID %d: proc_pidpath ();\n", pid_num);
fprintf(stderr, " %s\n", strerror(errno));
} else {
printf("proc %d: %s\n", pid_num, prog_name);
}
#elif defined WIN32
HMODULE module = GetModuleHandleA(nullptr);
GetModuleFileNameA(module, prog_name, max_path);
Expand All @@ -95,8 +98,6 @@ static void debug_crash_handler(int sig)
ERR("debug_crash_handler: Symlink too long");
return;
}
#else
return;
#endif

#if defined __linux__
Expand All @@ -112,9 +113,9 @@ static void debug_crash_handler(int sig)
// Start GDB
//
#ifdef __APPLE__
execl("/usr/bin/lldb", "lldb", "-p", pid.c_str(), nullptr);
execl("/usr/bin/lldb", "lldb", "-p", pid_str.c_str(), nullptr);
#else
execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread apply all bt", prog_name, pid.c_str(), nullptr);
execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread apply all bt", prog_name, pid_str.c_str(), nullptr);
#endif
assert(false && "Debugger failed to exec");
} else {
Expand Down Expand Up @@ -155,12 +156,15 @@ void common_error_handler(std::string &tech_support)

void segv_handler(int sig)
{
TRACE_AND_INDENT();

std::string tech_support = "Sorry, a crash has occurred!";

#if defined __linux__
#ifdef __APPLE__
//
// Seems to cause hang issues on mac M1
// Can't get it to work.
//
#else
debug_crash_handler(sig);
#endif

Expand All @@ -179,8 +183,8 @@ void error_handler(const std::string &error_msg)
void ctrlc_handler(int sig)
{
TRACE_AND_INDENT();

fprintf(MY_STDERR, "Interrupted!!!");
backtrace_dump();
DIE_CLEAN("Interrupted");
}
#endif
4 changes: 0 additions & 4 deletions src/wid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "my_wid_tiles.hpp"
#include "my_wids.hpp"

#undef ENABLE_DEBUG_GFX_GL_BLEND
#undef ENABLE_DEBUG_UI
#undef ENABLE_DEBUG_UI2

typedef struct {
//
// Colors
Expand Down
11 changes: 9 additions & 2 deletions src/wid_cfg_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "my_main.hpp"
#include "my_sdl_event.hpp"
#include "my_sdl_proto.hpp"
#include "my_sound.hpp"
#include "my_wids.hpp"

static WidPopup *wid_cfg_gfx_window;
Expand Down Expand Up @@ -175,9 +176,12 @@ static bool wid_cfg_gfx_resolution_incr(Widp w, int x, int y, uint32_t button)
game_config_pix_height_set(game, mode.h);
SDL_SetWindowSize(sdl.window, mode.w, mode.h);
CON("INF: New resolution %s", chosen.c_str());
wid_cfg_gfx_save(nullptr, 0, 0, 0);
} else {
sound_play("error");
CON("INF: At maximum resolution (current %s)", res.c_str());
}

wid_cfg_gfx_save(nullptr, 0, 0, 0);
return true;
}

Expand Down Expand Up @@ -219,9 +223,12 @@ static bool wid_cfg_gfx_resolution_decr(Widp w, int x, int y, uint32_t button)
game_config_pix_height_set(game, mode.h);
SDL_SetWindowSize(sdl.window, mode.w, mode.h);
CON("INF: New resolution %s", chosen.c_str());
wid_cfg_gfx_save(nullptr, 0, 0, 0);
} else {
sound_play("error");
CON("INF: At minimm resolution (current %s)", res.c_str());
}

wid_cfg_gfx_save(nullptr, 0, 0, 0);
return true;
}

Expand Down

0 comments on commit 5be2ddd

Please sign in to comment.