attempt to set optional tilesize arguments for load_texture()

develop
Taxi Service 2023-06-01 20:16:31 +02:00 committed by Myk Taylor
parent a51032b8ee
commit 3e2940ef8f
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 23 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

@ -46,6 +46,11 @@ DFHACK_EXPORT long getIconsTexposStart();
*/
DFHACK_EXPORT long getOnOffTexposStart();
/**
* Get the first texpos for the pathable 32x32 sprites. It's a 2x1 grid.
*/
DFHACK_EXPORT long getPathableTexposStart();
/**
* Get the first texpos for the control panel icons. 10x2 grid.
*/

@ -25,6 +25,7 @@ static long g_green_pin_texpos_start = -1;
static long g_red_pin_texpos_start = -1;
static long g_icons_texpos_start = -1;
static long g_on_off_texpos_start = -1;
static long g_pathable_texpos_start = -1;
static long g_control_panel_texpos_start = -1;
static long g_thin_borders_texpos_start = -1;
static long g_medium_borders_texpos_start = -1;
@ -74,7 +75,9 @@ const uint32_t TILE_WIDTH_PX = 8;
const uint32_t TILE_HEIGHT_PX = 12;
static size_t load_textures(color_ostream & out, const char * fname,
long *texpos_start) {
long *texpos_start,
int tile_w = TILE_WIDTH_PX,
int tile_h = TILE_HEIGHT_PX) {
SDL_Surface *s = DFIMG_Load(fname);
if (!s) {
out.printerr("unable to load textures from '%s'\n", fname);
@ -82,20 +85,20 @@ static size_t load_textures(color_ostream & out, const char * fname,
}
s = canonicalize_format(s);
int dimx = s->w / TILE_WIDTH_PX;
int dimy = s->h / TILE_HEIGHT_PX;
int dimx = s->w / tile_w;
int dimy = s->h / tile_h;
long count = 0;
for (int y = 0; y < dimy; y++) {
for (int x = 0; x < dimx; x++) {
SDL_Surface *tile = DFSDL_CreateRGBSurface(0, // SDL_SWSURFACE
TILE_WIDTH_PX, TILE_HEIGHT_PX, 32,
tile_w, tile_h, 32,
s->format->Rmask, s->format->Gmask, s->format->Bmask,
s->format->Amask);
SDL_Rect vp;
vp.x = TILE_WIDTH_PX * x;
vp.y = TILE_HEIGHT_PX * y;
vp.w = TILE_WIDTH_PX;
vp.h = TILE_HEIGHT_PX;
vp.x = tile_w * x;
vp.y = tile_h * y;
vp.w = tile_w;
vp.h = tile_h;
DFSDL_UpperBlit(s, &vp, tile, NULL);
if (!count++)
*texpos_start = enabler->textures.raws.size();
@ -137,6 +140,8 @@ void Textures::init(color_ostream &out) {
&g_icons_texpos_start);
g_num_dfhack_textures += load_textures(out, "hack/data/art/on-off.png",
&g_on_off_texpos_start);
g_num_dfhack_textures += load_textures(out, "hack/data/art/pathable.png",
&g_pathable_texpos_start, 32, 32);
g_num_dfhack_textures += load_textures(out, "hack/data/art/control-panel.png",
&g_control_panel_texpos_start);
g_num_dfhack_textures += load_textures(out, "hack/data/art/border-thin.png",
@ -201,6 +206,10 @@ long Textures::getOnOffTexposStart() {
return g_on_off_texpos_start;
}
long Textures::getPathableTexposStart() {
return g_pathable_texpos_start;
}
long Textures::getControlPanelTexposStart() {
return g_control_panel_texpos_start;
}

@ -41,7 +41,7 @@ static void paintScreen(df::coord target, bool skip_unrevealed = false) {
long pathable_tile_texpos = df::global::init->load_bar_texpos[1];
long unpathable_tile_texpos = df::global::init->load_bar_texpos[4];
long on_off_texpos = Textures::getOnOffTexposStart();
long on_off_texpos = Textures::getPathableTexposStart();
if (on_off_texpos > 0) {
pathable_tile_texpos = on_off_texpos + 0;
unpathable_tile_texpos = on_off_texpos + 1;