Skip to content

Commit

Permalink
wip on fixing ascii fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jan 10, 2025
1 parent 2d3f98e commit 17a0e69
Show file tree
Hide file tree
Showing 21 changed files with 31 additions and 107 deletions.
Binary file added data/fonts/PressStart.tga
Binary file not shown.
Binary file added data/fonts/PressStart.xcf
Binary file not shown.
Binary file removed data/fonts/font-alternative.xcf
Binary file not shown.
Binary file removed data/fonts/font.tga
Binary file not shown.
Binary file removed data/fonts/font.xcf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ascii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ void ascii_display(void)
{
mouse_found = false;

gl_enter_2d_mode(game_ui_pix_width_get(game), game_ui_pix_height_get(game));
gl_enter_2d_mode(game_window_pix_width_get(game), game_window_pix_height_get(game));
blit_init();
ascii_blit();
blit_flush();
Expand Down
13 changes: 0 additions & 13 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ using Config = class Config_
int map_pix_height = {};
int map_pix_width = {};
//
// The user interface that can be higher res than the game
//
int ui_pix_height = {};
int ui_pix_width = {};
//
// The actual display res
//
int window_pix_height = {};
Expand Down Expand Up @@ -257,8 +252,6 @@ void Config::reset(void)
mouse_wheel_ud_negated = false;
ui_gfx_term_height = {TERM_GFX_HEIGHT_DEF};
ui_gfx_term_width = {TERM_GFX_WIDTH_DEF};
ui_pix_height = {};
ui_pix_width = {};
version = "" MYVER "";
aspect_ratio = {};
window_pix_height = {};
Expand Down Expand Up @@ -606,12 +599,6 @@ void game_map_pix_height_set(class Game *g, int val) { g->config.map_pix_height
int game_map_pix_width_get(class Game *g) { return g->config.map_pix_width; }
void game_map_pix_width_set(class Game *g, int val) { g->config.map_pix_width = val; }

int game_ui_pix_height_get(class Game *g) { return g->config.ui_pix_height; }
void game_ui_pix_height_set(class Game *g, int val) { g->config.ui_pix_height = val; }

int game_ui_pix_width_get(class Game *g) { return g->config.ui_pix_width; }
void game_ui_pix_width_set(class Game *g, int val) { g->config.ui_pix_width = val; }

int game_window_pix_height_get(class Game *g) { return g->config.window_pix_height; }
void game_window_pix_height_set(class Game *g, int val) { g->config.window_pix_height = val; }

Expand Down
12 changes: 0 additions & 12 deletions src/game_load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ std::istream &operator>>(std::istream &in, Bits< Config & > my)
in >> bits(my.t.tiles_visible_down);
in >> bits(my.t.ui_gfx_term_height);
in >> bits(my.t.ui_gfx_term_width);
in >> bits(my.t.ui_pix_height);
in >> bits(my.t.ui_pix_width);
in >> bits(my.t.window_pix_height);
in >> bits(my.t.window_pix_width);

Expand All @@ -119,8 +117,6 @@ std::istream &operator>>(std::istream &in, Bits< Config & > my)
LOG("Read config: sound_volume = %d", my.t.sound_volume);
LOG("Read config: tiles_visible_across = %d", my.t.tiles_visible_across);
LOG("Read config: tiles_visible_down = %d", my.t.tiles_visible_down);
LOG("Read config: ui_pix_height = %d", my.t.ui_pix_height);
LOG("Read config: ui_pix_width = %d", my.t.ui_pix_width);
LOG("Read config: window_pix_height = %d", my.t.window_pix_height);
LOG("Read config: window_pix_width = %d", my.t.window_pix_width);
// seed name handled below
Expand Down Expand Up @@ -184,14 +180,6 @@ std::istream &operator>>(std::istream &in, Bits< Config & > my)
game_load_error += "map_pix_width is invalid";
return in;
}
if (my.t.ui_pix_height < 0) {
game_load_error += "ui_pix_height is invalid";
return in;
}
if (my.t.ui_pix_width < 0) {
game_load_error += "ui_pix_width is invalid";
return in;
}
if (my.t.aspect_ratio < 0) {
game_load_error += "aspect_ratio is invalid";
return in;
Expand Down
2 changes: 0 additions & 2 deletions src/game_save.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ std::ostream &operator<<(std::ostream &out, Bits< const Config & > const my)
out << bits(my.t.tiles_visible_down);
out << bits(my.t.ui_gfx_term_height);
out << bits(my.t.ui_gfx_term_width);
out << bits(my.t.ui_pix_height);
out << bits(my.t.ui_pix_width);
out << bits(my.t.window_pix_height);
out << bits(my.t.window_pix_width);

Expand Down
2 changes: 1 addition & 1 deletion src/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void gfx_init_font_ui(void)
"nothing",
};

tile_load_arr("data/fonts/font.tga", "font_ui", UI_FONT_WIDTH, UI_FONT_HEIGHT, ARRAY_SIZE(tiles), tiles);
tile_load_arr("data/fonts/PressStart.tga", "font_ui", UI_FONT_WIDTH, UI_FONT_HEIGHT, ARRAY_SIZE(tiles), tiles);
}

static void gfx_ui_init_0(void)
Expand Down
11 changes: 2 additions & 9 deletions src/gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ void fbo_get_size(int fbo, int &w, int &h)
h = game_map_pix_height_get(game);
break;
case FBO_WID :
w = game_ui_pix_width_get(game);
h = game_ui_pix_height_get(game);
w = game_window_pix_width_get(game);
h = game_window_pix_height_get(game);
break;
case FBO_FINAL :
w = game_window_pix_width_get(game);
Expand All @@ -469,13 +469,6 @@ void blit_fbo(int fbo)
blit_flush();
}

void blit_fbo_ui_pix(int fbo)
{
blit_init();
blit(g_fbo_tex_id[ fbo ], 0.0, 1.0, 1.0, 0.0, 0, 0, game_ui_pix_width_get(game), game_ui_pix_height_get(game));
blit_flush();
}

void blit_fbo_window_pix(int fbo)
{
blit_init();
Expand Down
2 changes: 1 addition & 1 deletion src/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ void topcon_(const char *fmt, va_list args)

buf[ 0 ] = '\0';
get_timestamp(ts, MAXLONGSTR);
snprintf(buf, sizeof(buf) - 1, "%s", ts);
snprintf(buf, SIZEOF(buf) - 1, "%s", ts);
len = (int) strlen(buf);
vsnprintf(buf + len, MAXLONGSTR - len, fmt, args);

Expand Down
2 changes: 1 addition & 1 deletion src/my_ascii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "my_ui.hpp"

#define TERM_GFX_WIDTH_DEF 132
#define TERM_GFX_HEIGHT_DEF 46
#define TERM_GFX_HEIGHT_DEF 60

#define TERM_WIDTH_MAX TERM_GFX_WIDTH_DEF
#define TERM_HEIGHT_MAX TERM_GFX_HEIGHT_DEF
Expand Down
6 changes: 0 additions & 6 deletions src/my_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ void game_map_pix_height_set(class Game *, int);
int game_map_pix_width_get(class Game *);
void game_map_pix_width_set(class Game *, int);

int game_ui_pix_height_get(class Game *);
void game_ui_pix_height_set(class Game *, int);

int game_ui_pix_width_get(class Game *);
void game_ui_pix_width_set(class Game *, int);

int game_window_pix_height_get(class Game *);
void game_window_pix_height_set(class Game *, int);

Expand Down
1 change: 0 additions & 1 deletion src/my_gl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ void blit_fbo_push(int fbo);
void blit_fbo_pop(void);
void blit_fbo_bind(int fbo);
void blit_fbo_bind_locked(int fbo);
void blit_fbo_ui_pix(int fbo);
void blit_fbo_window_pix(int fbo);
void blit_fbo_unbind(void);
void blit_fbo_unbind_locked(void);
Expand Down
9 changes: 4 additions & 5 deletions src/my_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
#define UI_CONSOLE_WIDTH (TERM_WIDTH - 3)
#define UI_CURSOR_COLOR GRAY
#define UI_CURSOR_OTHER_COLOR WHITE
#define UI_FONT_HEIGHT 232
#define UI_FONT_WIDTH 128
#define UI_HEALTH_BAR_STEPS 18 // How many graduations on health bar
#define UI_LEFTBAR_WIDTH UI_HEALTH_BAR_STEPS
#define UI_FONT_HEIGHT 8
#define UI_FONT_WIDTH 8
#define UI_LEFTBAR_WIDTH 20 // In characters
#define UI_RIGHTBAR_WIDTH 20 // In characters
#define UI_LOGGING_EMPTY_LINE "`" // Complete hack, char I use to force space
#define UI_MOUSE_DOUBLE_CLICK 500 // Double click time
#define UI_MOUSE_WHEEL_SCALE 2.0 // How much the wheel mouse moves.
#define UI_MOUSE_WHEEL_SCALE_MAX 10
#define UI_POPUP_TEXT_COLOR UI_TEXT_COLOR
#define UI_RIGHTBAR_WIDTH 18
#define UI_SCROLL_JOY_SCALE 1.0
#define UI_SCROLL_JOY_SCALE_MAX 1.5
#define UI_TEXT_COLOR GRAY // Default text color
Expand Down
2 changes: 1 addition & 1 deletion src/my_wid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void wid_destroy_in(Widp w, uint32_t ms);
void wid_destroy_nodelay(Widp *);
void wid_destroy_ptr_in(Widp *w, uint32_t ms);
void wid_destroy(Widp *);
void wid_display_all(bool ok_to_handle_requests = true);
void wid_display_all(void);
void wid_dump(Widp w, int depth);
void wid_fake_joy_button(class Game *, int x, int y);
void wid_find_first_focus(void);
Expand Down
29 changes: 6 additions & 23 deletions src/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,6 @@ int sdl_get_mouse(void)
return button;
}

x *= game_window_pix_width_get(game) / game_ui_pix_width_get(game);
y *= game_window_pix_height_get(game) / game_ui_pix_height_get(game);

sdl.mouse_x = x;
sdl.mouse_y = y;

Expand Down Expand Up @@ -672,7 +669,7 @@ void sdl_flush_display(class Game *g, bool force)

glEnable(GL_TEXTURE_2D);
gl_enter_2d_mode();
wid_display_all(false);
wid_display_all();
gl_leave_2d_mode();
gl_enter_2d_mode(game_window_pix_width_get(game), game_window_pix_height_get(game));

Expand All @@ -689,13 +686,6 @@ void config_game_gfx_update(void)
//
game_aspect_ratio_set(game, (double) game_window_pix_width_get(game) / (double) game_window_pix_height_get(game));

//
// Use the same resolution as the game for large smooth fonts.
// This is the max size we can have. The real size will be trimmed based on how many characters we can fit.
//
game_ui_pix_height_set(game, game_window_pix_height_get(game));
game_ui_pix_width_set(game, game_window_pix_width_get(game));

TERM_WIDTH = game_ui_gfx_term_width_get(game);
TERM_HEIGHT = game_ui_gfx_term_height_get(game);

Expand All @@ -718,27 +708,24 @@ void config_game_gfx_update(void)
TERM_HEIGHT = TERM_HEIGHT_MAX;
}

//
// Account for rounding errors, so the tiles look smoother.
//
float font_width = game_window_pix_width_get(game) / TERM_WIDTH;
float font_height = font_width * ((float) UI_FONT_HEIGHT / (float) UI_FONT_WIDTH);
float font_height = game_window_pix_height_get(game) / TERM_HEIGHT;

game_ascii_gl_width_set(game, font_width);
game_ascii_gl_height_set(game, font_height);

//
// If we overflow the screen, try to cut a few rows and columns off
//
while (game_ascii_gl_width_get(game) * TERM_WIDTH > game_ui_pix_width_get(game)) {
while (game_ascii_gl_width_get(game) * TERM_WIDTH > game_window_pix_width_get(game)) {
TERM_WIDTH--;
LOG("SDL: - font width %u exceeded terminal pixel width %u, try term width: %d", game_ascii_gl_width_get(game),
game_ui_pix_width_get(game), TERM_WIDTH);
game_window_pix_width_get(game), TERM_WIDTH);
}
while (game_ascii_gl_height_get(game) * TERM_HEIGHT > game_ui_pix_height_get(game)) {
while (game_ascii_gl_height_get(game) * TERM_HEIGHT > game_window_pix_height_get(game)) {
TERM_HEIGHT--;
LOG("SDL: - font height %u exceeded terminal pixel height %u, try term height: %d",
game_ascii_gl_height_get(game), game_ui_pix_height_get(game), TERM_HEIGHT);
game_ascii_gl_height_get(game), game_window_pix_height_get(game), TERM_HEIGHT);
}

//
Expand Down Expand Up @@ -799,12 +786,8 @@ void config_game_gfx_update(void)
game_tiles_visible_across_set(game, tiles_across);
game_tiles_visible_down_set(game, tiles_down);

game_ui_pix_width_set(game, TERM_WIDTH * game_ascii_gl_width_get(game));
game_ui_pix_height_set(game, TERM_HEIGHT * game_ascii_gl_height_get(game));

LOG("SDL: Window:");
LOG("SDL: - window pixel size : %dx%d", game_window_pix_width_get(game), game_window_pix_height_get(game));
LOG("SDL: - UI pixel size : %dx%d", game_ui_pix_width_get(game), game_ui_pix_height_get(game));
LOG("SDL: - game map pixel size : %dx%d", game_pix_width_get(game), game_pix_height_get(game));
LOG("SDL: - visible map pixel size : %dx%d", game_map_pix_width_get(game), game_map_pix_height_get(game));
LOG("SDL: Terminal");
Expand Down
27 changes: 2 additions & 25 deletions src/wid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5202,21 +5202,6 @@ static void wid_tick_all(void)
}
}

//
// Do stuff for all widgets.
//
static void wid_handle_requests(void)
{
TRACE_AND_INDENT();

//
// If the console is visible, don't create any new windows
//
if (wid_console_window && wid_console_window->visible) {
return;
}
}

static void wid_tick_all_post_display(void)
{
TRACE_AND_INDENT();
Expand Down Expand Up @@ -5245,22 +5230,14 @@ static void wid_tick_all_post_display(void)
//
// Display all widgets
//
void wid_display_all(bool ok_to_handle_requests)
void wid_display_all(void)
{
TRACE_AND_INDENT();

ascii_clear_display();

//
// A bit faster to avoid this when flushing the display
//
if (ok_to_handle_requests) {

wid_handle_requests();
}

gl_leave_2d_mode();
gl_enter_2d_mode(game_ui_pix_width_get(game), game_ui_pix_height_get(game));
gl_enter_2d_mode(game_window_pix_width_get(game), game_window_pix_height_get(game));
blit_fbo_bind_locked(FBO_WID);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClear(GL_COLOR_BUFFER_BIT);
Expand Down
3 changes: 2 additions & 1 deletion src/wid_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ static void wid_keyboard_bg_tick(Widp w)

std::string t = "grid";
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand Down
15 changes: 10 additions & 5 deletions src/wid_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ static void game_display_title_bg(void)

std::string t = "title_bg";
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand All @@ -150,7 +151,8 @@ static void game_display_title_fg1(void)

std::string t = "title_fg1_1";
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand Down Expand Up @@ -181,7 +183,8 @@ static void game_display_title_fg2(void)

std::string t = "title_fg2_1";
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand Down Expand Up @@ -260,7 +263,8 @@ static void game_display_title_fg3(void)

std::string t = "title_fg3_1";
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand All @@ -284,7 +288,8 @@ static void game_display_title_fg4(void)

std::string t = "title_fg4_" + std::to_string(frame);
blit_init();
tile_blit(tile_find_mand(t.c_str()), point(0, 0), point(game_ui_pix_width_get(game), game_ui_pix_height_get(game)));
tile_blit(tile_find_mand(t.c_str()), point(0, 0),
point(game_window_pix_width_get(game), game_window_pix_height_get(game)));
blit_flush();
}

Expand Down

0 comments on commit 17a0e69

Please sign in to comment.