Skip to content

Commit b6e949e

Browse files
committed
swars: Functions for converting between texture index and UV coords
1 parent 6d4169d commit b6e949e

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/enginsngtxtr.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ ushort next_floor_texture = 1;
3030

3131
ushort next_local_mat = 1;
3232

33+
/******************************************************************************/
34+
35+
/** Convert given texture index into page+U+V coordinates in texture atlas.
36+
*/
37+
void texture_index_to_page_u_v(ubyte *p_page, ubyte *p_tmap_u, ubyte *p_tmap_v, int index)
38+
{
39+
*p_page = index / (8 * 8);
40+
*p_tmap_u = (index % 8) * 32;
41+
*p_tmap_v = ((index / 8) % 8) * 32;
42+
}
43+
44+
/** Convert page+U+V coordinates from texture atlas into single texture index.
45+
*/
46+
int texture_page_u_v_to_index(ubyte page, ubyte tmap_u, ubyte tmap_v)
47+
{
48+
int index;
49+
50+
index = page * (8 * 8);
51+
index += (tmap_v / 32) * 8;
52+
index += (tmap_u / 32);
53+
return index;
54+
}
55+
3356
/** Checks whether texture with specified index is the only in use within given SingleFloorTexture.
3457
*/
3558
TbBool floor_texture_is_only_using_index(struct SingleFloorTexture *p_fltextr, int index)

src/lvfiles.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,13 +1420,15 @@ void load_map_bnb(int a1)
14201420
asm volatile ("call ASM_load_map_bnb\n"
14211421
: : "a" (a1));
14221422
#endif
1423-
char locstr[52];
1423+
char locstr[DISKPATH_SIZE];
1424+
PathInfo *pinfo;
14241425
TbFileHandle fh;
14251426
ubyte Amin, Amax;
14261427
ubyte Bmin, Bmax;
14271428

1428-
sprintf(locstr, "%s/map%03d.b&b", "maps", a1);
1429-
fh = LbFileOpen(locstr, 2u);
1429+
pinfo = &game_dirs[DirPlace_Maps];
1430+
snprintf(locstr, DISKPATH_SIZE-1, "%s/map%03d.b&b", pinfo->directory, a1);
1431+
fh = LbFileOpen(locstr, Lb_FILE_MODE_READ_ONLY);
14301432
if (fh == INVALID_FILE)
14311433
{
14321434
map_bnb.field_0 = 0;

0 commit comments

Comments
 (0)