Skip to content

Commit

Permalink
opengl: Make rest of the game use the new renderer (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
katajakasa committed Sep 29, 2024
1 parent 9f6f248 commit 2000aab
Show file tree
Hide file tree
Showing 69 changed files with 777 additions and 851 deletions.
24 changes: 4 additions & 20 deletions src/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ void console_output_render(void) {
int x = 0;
int y = 0;
unsigned int lines = 0;
const color textcolor = color_create(121, 121, 121, 255);
for(unsigned int i = con->output_pos; i != con->output_tail && lines < 15; i = BUFFER_INC(i)) {

char c = con->output[i];
Expand All @@ -193,7 +192,7 @@ void console_output_render(void) {
lines++;
} else {
// TODO add word wrapping?
font_render_char(&font_small, c, x, y + con->ypos - 100, textcolor);
font_render_char(&font_small, c, x, y + con->ypos - 100, TEXT_MEDIUM_GREEN);
x += font_small.w;
}
}
Expand All @@ -206,8 +205,6 @@ int console_init(void) {
con->isopen = 0;
con->ownsinput = 0;
con->ypos = 0;
con->ticks = 0;
con->dir = 0;
con->input[0] = '\0';
con->output[0] = '\0';
con->output_head = 0;
Expand Down Expand Up @@ -313,13 +310,11 @@ void console_render(void) {
con->input[0] = '\0';
con->histpos_changed = 0;
}
video_render_sprite(&con->background, -1, con->ypos - 101, BLEND_ALPHA, 0);
int t = con->ticks / 2;
video_draw(&con->background, -1, con->ypos - 101);
// input line
font_render(&font_small, con->input, 0, con->ypos - 7, color_create(121, 121, 121, 255));
font_render(&font_small, con->input, 0, con->ypos - 7, TEXT_MEDIUM_GREEN);
// cursor
font_render(&font_small, CURSOR_STR, strlen(con->input) * font_small.w, con->ypos - 7,
color_create(121 - t, 121 - t, 121 - t, 255));
font_render(&font_small, CURSOR_STR, strlen(con->input) * font_small.w, con->ypos - 7, TEXT_BLINKY_GREEN);
console_output_render();
}
}
Expand All @@ -336,17 +331,6 @@ void console_tick(void) {
con->ypos = 0;
}
}
if(!con->dir) {
con->ticks++;
} else {
con->ticks--;
}
if(con->ticks > 120) {
con->dir = 1;
}
if(con->ticks == 0) {
con->dir = 0;
}
}

void console_add_cmd(const char *name, command_func func, const char *doc) {
Expand Down
2 changes: 0 additions & 2 deletions src/console/console_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ typedef struct {
int isopen;
int ownsinput;
int ypos;
unsigned int ticks;
unsigned int dir;
hashmap cmds; // string -> command
} console;

Expand Down
15 changes: 6 additions & 9 deletions src/formats/fonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int sd_font_save(const sd_font *font, const char *file) {
return SD_SUCCESS;
}

int sd_font_decode(const sd_font *font, sd_rgba_image *o, uint8_t ch, uint8_t r, uint8_t g, uint8_t b) {
int sd_font_decode(const sd_font *font, sd_vga_image *o, uint8_t ch, uint8_t color) {
if(font == NULL || o == NULL || ch >= 224) {
return SD_INVALID_INPUT;
}
Expand All @@ -66,16 +66,13 @@ int sd_font_decode(const sd_font *font, sd_rgba_image *o, uint8_t ch, uint8_t r,
for(int i = 0; i < font->h; i++) {
for(int k = font->h - 1; k >= 0; k--) {
if(font->chars[ch].data[i] & (1 << k)) {
o->data[t++] = r;
o->data[t++] = g;
o->data[t++] = b;
o->data[t++] = (uint8_t)255;
o->data[t] = color;
o->stencil[t] = 1;
} else {
o->data[t++] = 0;
o->data[t++] = 0;
o->data[t++] = 0;
o->data[t++] = 0;
o->data[t] = 0;
o->stencil[t] = 0;
}
t++;
}
}
return SD_SUCCESS;
Expand Down
9 changes: 4 additions & 5 deletions src/formats/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define SD_FONTS_H

#include "formats/rgba_image.h"
#include "vga_image.h"
#include <stdint.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -92,13 +93,11 @@ int sd_font_save(const sd_font *font, const char *filename);
* \retval SD_SUCCESS Success.
*
* \param font Font struct pointer.
* \param surface Image surface to save to. Must be preallocated!
* \param surface Image surface to save to. Must be pre-allocated!
* \param ch Character to load. Must be 0 <= ch <= 224.
* \param r Red color index (0 - 0xFF)
* \param g Green color index (0 - 0xFF)
* \param b Blue color index (0 - 0xFF)
* \param color Color palette index (0 - 0xFF)
*/
int sd_font_decode(const sd_font *font, sd_rgba_image *surface, uint8_t ch, uint8_t r, uint8_t g, uint8_t b);
int sd_font_decode(const sd_font *font, sd_vga_image *surface, uint8_t ch, uint8_t color);

#ifdef __cplusplus
}
Expand Down
65 changes: 39 additions & 26 deletions src/formats/palette.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
#include "formats/altpal.h"
#include "formats/error.h"
#include "utils/allocator.h"
#include "video/color.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define COLOR_6TO8(color) ((color * 255.0) / 63.0)
#define COLOR_8TO6(color) ((color * 63.0) / 255.0)

// Inserted to range 250 - 255.
static const int menu_colors[6][3] = {
{0, 0, 42}, // 0, 0, 170
{0, 0, 60}, // 0, 0, 242
{0, 0, 22}, // 0, 0, 89
{0, 63, 0 }, // 0, 255, 0
{0, 30, 0 }, // 0, 121, 0
{20, 63, 20}, // 80, 255, 80
};

int palette_create(palette *pal) {
if(pal == NULL) {
return SD_INVALID_INPUT;
Expand All @@ -30,13 +41,6 @@ unsigned char palette_resolve_color(uint8_t r, uint8_t g, uint8_t b, const palet
return 0;
}

color palette_lookup_color(uint8_t i, const palette *pal) {
uint8_t red = pal->data[i][0] & 0xff;
uint8_t green = pal->data[i][1] & 0xff;
uint8_t blue = pal->data[i][2] & 0xff;
return color_create(red, green, blue, 255);
}

int palette_to_gimp_palette(const palette *pal, const char *filename) {
sd_writer *w;
const unsigned char *d;
Expand Down Expand Up @@ -110,13 +114,22 @@ int palette_from_gimp_palette(palette *pal, const char *filename) {
return SD_SUCCESS;
}

void palette_set_menu_colors(palette *pal) {
// Set the default menu colors. These are always set for the default (0) palette.
for(int i = 0; i < 6; i++) {
pal->data[250 + i][0] = COLOR_6TO8(menu_colors[i][0]);
pal->data[250 + i][1] = COLOR_6TO8(menu_colors[i][1]);
pal->data[250 + i][2] = COLOR_6TO8(menu_colors[i][2]);
}
}

int palette_load_range(sd_reader *reader, palette *pal, int index_start, int index_count) {
char d[3];
for(int i = index_start; i < index_start + index_count; i++) {
sd_read_buf(reader, d, 3);
pal->data[i][0] = ((d[0] << 2) | ((d[0] & 0x30) >> 4));
pal->data[i][1] = ((d[1] << 2) | ((d[1] & 0x30) >> 4));
pal->data[i][2] = ((d[2] << 2) | ((d[2] & 0x30) >> 4));
pal->data[i][0] = COLOR_6TO8(d[0]);
pal->data[i][1] = COLOR_6TO8(d[1]);
pal->data[i][2] = COLOR_6TO8(d[2]);
}
return SD_SUCCESS;
}
Expand All @@ -125,9 +138,9 @@ int palette_mload_range(memreader *reader, palette *pal, int index_start, int in
char d[3];
for(int i = index_start; i < index_start + index_count; i++) {
memread_buf(reader, d, 3);
pal->data[i][0] = ((d[0] << 2) | ((d[0] & 0x30) >> 4));
pal->data[i][1] = ((d[1] << 2) | ((d[1] & 0x30) >> 4));
pal->data[i][2] = ((d[2] << 2) | ((d[2] & 0x30) >> 4));
pal->data[i][0] = COLOR_6TO8(d[0]);
pal->data[i][1] = COLOR_6TO8(d[1]);
pal->data[i][2] = COLOR_6TO8(d[2]);
}
return SD_SUCCESS;
}
Expand All @@ -143,9 +156,9 @@ void palette_save_range(sd_writer *writer, const palette *pal, int index_start,
for(int i = index_start; i < index_start + index_count; i++) {
d = pal->data[i];
// for some reason, we need to mask off the high bits or the bitshift doesn't work
sd_write_ubyte(writer, (d[0] & 0xff) >> 2);
sd_write_ubyte(writer, (d[1] & 0xff) >> 2);
sd_write_ubyte(writer, (d[2] & 0xff) >> 2);
sd_write_ubyte(writer, COLOR_8TO6(d[0]));
sd_write_ubyte(writer, COLOR_8TO6(d[1]));
sd_write_ubyte(writer, COLOR_8TO6(d[2]));
}
}

Expand All @@ -154,9 +167,9 @@ void palette_msave_range(memwriter *writer, const palette *pal, int index_start,
for(int i = index_start; i < index_start + index_count; i++) {
d = pal->data[i];
// for some reason, we need to mask off the high bits or the bitshift doesn't work
memwrite_ubyte(writer, (d[0] & 0xff) >> 2);
memwrite_ubyte(writer, (d[1] & 0xff) >> 2);
memwrite_ubyte(writer, (d[2] & 0xff) >> 2);
memwrite_ubyte(writer, COLOR_8TO6(d[0]));
memwrite_ubyte(writer, COLOR_8TO6(d[1]));
memwrite_ubyte(writer, COLOR_8TO6(d[2]));
}
}

Expand All @@ -168,8 +181,8 @@ void palette_save(sd_writer *writer, const palette *pal) {
void palette_load_player_colors(palette *dst, palette *src, int player) {
// only load 47 palette colors, skipping the first one
// because that seems to be ignored by the original
int dstoff = (player * 48) + 1;
memcpy(dst->data + dstoff, src->data + 1, 47 * 3);
int dst_offset = (player * 48) + 1;
memcpy(dst->data + dst_offset, src->data + 1, 47 * 3);
}

void palette_load_player_cutscene_colors(palette *dst, palette *src) {
Expand All @@ -180,9 +193,9 @@ void palette_load_player_cutscene_colors(palette *dst, palette *src) {
}
}

void palette_set_player_color(palette *pal, int player, int srccolor, int dstcolor) {
int dst = dstcolor * 16 + player * 48;
int src = srccolor * 16;
void palette_set_player_color(palette *pal, int player, int src_color, int dst_color) {
int dst = dst_color * 16 + player * 48;
int src = src_color * 16;
char iz[3];
memcpy(iz, pal->data, 3);
if(altpals) {
Expand Down
5 changes: 2 additions & 3 deletions src/formats/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ void palette_free(palette *pal);
*/
unsigned char palette_resolve_color(uint8_t r, uint8_t g, uint8_t b, const palette *pal);

color palette_lookup_color(uint8_t i, const palette *pal);

/*! \brief Exports palette to GIMP palette file.
*
* Exports a palette to GIMP palette format (GPL). Palette remappings are NOT
Expand Down Expand Up @@ -96,6 +94,7 @@ int palette_to_gimp_palette(const palette *pal, const char *filename);
*/
int palette_from_gimp_palette(palette *pal, const char *filename);

void palette_set_menu_colors(palette *pal);
int palette_mload_range(memreader *reader, palette *pal, int index_start, int index_count);
int palette_load_range(sd_reader *reader, palette *pal, int index_start, int index_count);
int palette_load(sd_reader *reader, palette *pal);
Expand All @@ -104,7 +103,7 @@ void palette_save_range(sd_writer *writer, const palette *pal, int index_start,
void palette_save(sd_writer *writer, const palette *pal);
void palette_load_player_colors(palette *dst, palette *src, int player);
void palette_load_player_cutscene_colors(palette *dst, palette *src);
void palette_set_player_color(palette *pal, int player, int sourcecolor, int destcolor);
void palette_set_player_color(palette *pal, int player, int src_color, int dst_color);
void palette_copy(palette *dst, const palette *src, int index_start, int inde_count);

#ifdef __cplusplus
Expand Down
14 changes: 7 additions & 7 deletions src/game/gui/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ void dialog_create(dialog *dlg, dialog_style style, const char *text, int x, int
text_settings tconf;
text_defaults(&tconf);
tconf.font = FONT_BIG;
tconf.cforeground = COLOR_DARK_GREEN;
tconf.cforeground = TEXT_MEDIUM_GREEN;

text_settings tconf_desc;
text_defaults(&tconf_desc);
tconf_desc.font = FONT_SMALL;
tconf_desc.cforeground = COLOR_DARK_GREEN;
tconf_desc.cforeground = TEXT_MEDIUM_GREEN;

dlg->x = x;
dlg->y = y;
Expand All @@ -36,15 +36,15 @@ void dialog_create(dialog *dlg, dialog_style style, const char *text, int x, int
if(style == DIALOG_STYLE_YES_NO) {
dlg->yes = textbutton_create(&tconf, "YES", NULL, COM_ENABLED, NULL, NULL);
dlg->no = textbutton_create(&tconf, "NO", NULL, COM_ENABLED, NULL, NULL);
textbutton_set_border(dlg->yes, COLOR_BLUE);
textbutton_set_border(dlg->no, COLOR_BLUE);
textbutton_set_border(dlg->yes, TEXT_MEDIUM_GREEN);
textbutton_set_border(dlg->no, TEXT_MEDIUM_GREEN);
component_layout(dlg->yes, x + 54, x + h + 6, 8, 8);
component_layout(dlg->no, x + 114, x + h + 6, 8, 8);
component_select(dlg->yes, 1);
dlg->result = DIALOG_RESULT_YES_OK;
} else if(style == DIALOG_STYLE_OK) {
dlg->ok = textbutton_create(&tconf, "OK", NULL, COM_ENABLED, NULL, NULL);
textbutton_set_border(dlg->ok, COLOR_BLUE);
textbutton_set_border(dlg->ok, TEXT_MEDIUM_GREEN);
component_layout(dlg->ok, x + 84, x + h + 6, 8, 8);
component_select(dlg->ok, 1);
dlg->result = DIALOG_RESULT_YES_OK;
Expand Down Expand Up @@ -76,7 +76,7 @@ void dialog_render(dialog *dlg) {
if(!dlg->visible) {
return;
}
video_render_sprite(&dlg->background, dlg->x, dlg->y, BLEND_ALPHA, 0);
video_draw(&dlg->background, dlg->x, dlg->y);
if(dlg->yes) {
component_render(dlg->yes);
}
Expand All @@ -86,7 +86,7 @@ void dialog_render(dialog *dlg) {
if(dlg->ok) {
component_render(dlg->ok);
}
font_render_wrapped_shadowed(&font_small, dlg->text, dlg->x + 15, dlg->y + 3, MAX_WIDTH, COLOR_GREEN,
font_render_wrapped_shadowed(&font_small, dlg->text, dlg->x + 15, dlg->y + 3, MAX_WIDTH, TEXT_MEDIUM_GREEN,
TEXT_SHADOW_RIGHT | TEXT_SHADOW_BOTTOM);
}

Expand Down
Loading

0 comments on commit 2000aab

Please sign in to comment.