Skip to content

Commit ea93429

Browse files
authored
Allow more textures (#2679)
Adds a tmapbXXX.dat file to allow custom textures Also implement campaign specific texture files Resolves #2519
1 parent 3d32dab commit ea93429

14 files changed

+91
-73
lines changed

config/fxdata/textureanim.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# and for determining the floor texture in columns in columns.cfg and the .clm files bundled with maps
44
# the frames reference static textures 0-543 for textures in tmapaXXX.dat
55
# the animated numbers start at 544 and end at 999
6+
# numbers starting at 1000 are in tmapbXXX.dat
67

78
[texture544]
89
name = "dirt_near_water"

src/config_slabsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ TbBool load_columns_config_file(const char *textname, const char *fname, unsigne
219219
cols[col_no].use = value_int32(value_dict_get(section, "Utilized"));
220220
cols[col_no].bitfields = bitfields;
221221
cols[col_no].solidmask = value_int32(value_dict_get(section, "SolidMask"));
222-
cols[col_no].baseblock = value_int32(value_dict_get(section, "FloorTexture"));
222+
cols[col_no].floor_texture = value_int32(value_dict_get(section, "FloorTexture"));
223223
cols[col_no].orient = value_int32(value_dict_get(section, "Orientation"));
224224

225225
VALUE *Cubes_arr = value_dict_get(section, "Cubes");

src/config_textures.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,10 @@ TbBool load_textureanim_config_file(const char *textname, const char *fname, uns
4848
{
4949

5050
{
51-
sprintf(key, "texture%d", tex_no + TEXTURE_BLOCKS_STAT_COUNT);
51+
sprintf(key, "texture%d", tex_no + TEXTURE_BLOCKS_STAT_COUNT_A);
5252
section = value_dict_get(&file_root, key);
5353
}
54-
if (value_type(section) != VALUE_DICT)
55-
{
56-
if ((flags & CnfLd_IgnoreErrors) == 0)
57-
{
58-
WARNMSG("Invalid texture section %d", tex_no + TEXTURE_BLOCKS_STAT_COUNT);
59-
}
60-
}
61-
else
54+
if (value_type(section) == VALUE_DICT)
6255
{
6356
VALUE *frames_arr = value_dict_get(section, "frames");
6457
if(value_array_size(frames_arr) != TEXTURE_BLOCKS_ANIM_FRAMES)

src/engine_arrays.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ extern "C" {
3636
/******************************************************************************/
3737
short td_iso[TD_ISO_POINTS];
3838
short iso_td[TD_ISO_POINTS];
39-
unsigned short floor_to_ceiling_map[FLOOR_TO_CEILING_MAP_LEN];
39+
unsigned short floor_to_ceiling_map[TEXTURE_BLOCKS_COUNT];
4040
struct WibbleTable blank_wibble_table[128];
4141

4242
long randomisors[512];
4343
struct WibbleTable wibble_table[128];
44-
unsigned short floor_to_ceiling_map[592];
4544
long floor_height_table[256];
4645
long lintel_top_height[256];
4746
long lintel_bottom_height[256];

src/engine_arrays.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
// All anims below this have two different sprites in 3d and map view
2828
#define TD_ISO_POINTS 982
29-
#define FLOOR_TO_CEILING_MAP_LEN 592
3029
#define RANDOMISORS_LEN 512
3130
#define RANDOMISORS_MASK 0x1ff
3231
#define RANDOMISORS_RANGE 63
@@ -50,7 +49,6 @@ struct WibbleTable {
5049
/******************************************************************************/
5150
extern long randomisors[512];
5251
extern struct WibbleTable wibble_table[128];
53-
extern unsigned short floor_to_ceiling_map[592];
5452
extern long floor_height_table[256];
5553
extern long lintel_top_height[256];
5654
extern long lintel_bottom_height[256];
@@ -60,7 +58,7 @@ extern long lintel_bottom_height[256];
6058
extern short iso_td_add[KEEPERSPRITE_ADD_NUM];
6159
extern short td_iso_add[KEEPERSPRITE_ADD_NUM];
6260
/******************************************************************************/
63-
extern unsigned short floor_to_ceiling_map[FLOOR_TO_CEILING_MAP_LEN];
61+
extern unsigned short floor_to_ceiling_map[TEXTURE_BLOCKS_COUNT];
6462
extern struct WibbleTable blank_wibble_table[128];
6563
/******************************************************************************/
6664
short convert_td_iso(short n);

src/engine_render.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,7 @@ static void do_a_plane_of_engine_columns_perspective(long stl_x, long stl_y, lon
42534253
} else
42544254
{
42554255
ecpos = 0;
4256-
textr_idx = engine_remap_texture_blocks(stl_num_decode_x(center_block_idx), stl_num_decode_y(center_block_idx), colmn->baseblock);
4256+
textr_idx = engine_remap_texture_blocks(stl_num_decode_x(center_block_idx), stl_num_decode_y(center_block_idx), colmn->floor_texture);
42574257
do_a_trig_gourad_tr(&bec[0].cors[ecpos], &bec[1].cors[ecpos], &fec[1].cors[ecpos], textr_idx, -1);
42584258
do_a_trig_gourad_bl(&fec[1].cors[ecpos], &fec[0].cors[ecpos], &bec[0].cors[ecpos], textr_idx, -1);
42594259
}
@@ -4275,7 +4275,7 @@ static void do_a_plane_of_engine_columns_perspective(long stl_x, long stl_y, lon
42754275
// Draw the universal ceiling on top of the columns
42764276
ecpos = 8;
42774277
{
4278-
textr_idx = engine_remap_texture_blocks(stl_num_decode_x(center_block_idx), stl_num_decode_y(center_block_idx), floor_to_ceiling_map[colmn->baseblock]);
4278+
textr_idx = engine_remap_texture_blocks(stl_num_decode_x(center_block_idx), stl_num_decode_y(center_block_idx), floor_to_ceiling_map[colmn->floor_texture]);
42794279
do_a_trig_gourad_tr(&fec[0].cors[ecpos], &fec[1].cors[ecpos], &bec[1].cors[ecpos], textr_idx, -1);
42804280
do_a_trig_gourad_bl(&bec[1].cors[ecpos], &bec[0].cors[ecpos], &fec[0].cors[ecpos], textr_idx, -1);
42814281
}
@@ -4690,7 +4690,7 @@ static void do_a_plane_of_engine_columns_cluedo(long stl_x, long stl_y, long pla
46904690
{
46914691
if ((cur_mapblk->flags & SlbAtFlg_Unexplored) == 0)
46924692
{
4693-
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cur_colmn->baseblock);
4693+
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cur_colmn->floor_texture);
46944694
do_a_gpoly_gourad_tr(&bec[0].cors[0], &bec[1].cors[0], &fec[1].cors[0], textr_id, -1);
46954695
do_a_gpoly_gourad_bl(&fec[1].cors[0], &fec[0].cors[0], &bec[0].cors[0], textr_id, -1);
46964696
} else
@@ -4860,7 +4860,7 @@ static void do_a_plane_of_engine_columns_isometric(long stl_x, long stl_y, long
48604860
else if ((cur_mapblk->flags & (SlbAtFlg_TaggedValuable|SlbAtFlg_Unexplored)) == 0)
48614861
{
48624862
struct CubeConfigStats * cubed;
4863-
cubed = get_cube_model_stats(*(short *)((char *)&cur_colmn->baseblock + 2 * ncor + 1));
4863+
cubed = get_cube_model_stats(*(short *)((char *)&cur_colmn->floor_texture + 2 * ncor + 1));
48644864
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cubed->texture_id[4]);
48654865
// Top surface on full iso mode
48664866
do_a_gpoly_gourad_tr(&bec[0].cors[ncor], &bec[1].cors[ncor], &fec[1].cors[ncor], textr_id, -1);
@@ -4876,7 +4876,7 @@ static void do_a_plane_of_engine_columns_isometric(long stl_x, long stl_y, long
48764876
{
48774877
if ((cur_mapblk->flags & SlbAtFlg_Unexplored) == 0)
48784878
{
4879-
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cur_colmn->baseblock);
4879+
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cur_colmn->floor_texture);
48804880
do_a_gpoly_gourad_tr(&bec[0].cors[0], &bec[1].cors[0], &fec[1].cors[0], textr_id, -1);
48814881
do_a_gpoly_gourad_bl(&fec[1].cors[0], &fec[0].cors[0], &bec[0].cors[0], textr_id, -1);
48824882
} else
@@ -4890,7 +4890,7 @@ static void do_a_plane_of_engine_columns_isometric(long stl_x, long stl_y, long
48904890
if (ncor > 0)
48914891
{
48924892
struct CubeConfigStats * cubed;
4893-
cubed = get_cube_model_stats(*(short *)((char *)&cur_colmn->baseblock + 2 * ncor + 1));
4893+
cubed = get_cube_model_stats(*(short *)((char *)&cur_colmn->floor_texture + 2 * ncor + 1));
48944894
unsigned short textr_id = engine_remap_texture_blocks(stl_x + xaval + xidx, stl_y, cubed->texture_id[4]);
48954895
do_a_gpoly_gourad_tr(&bec[0].cors[ncor], &bec[1].cors[ncor], &fec[1].cors[ncor], textr_id, -1);
48964896
do_a_gpoly_gourad_bl(&fec[1].cors[ncor], &fec[0].cors[ncor], &bec[0].cors[ncor], textr_id, -1);
@@ -7439,10 +7439,10 @@ static void draw_element(struct Map *map, long lightness, long stl_x, long stl_y
74397439

74407440
if (*ymax > pos_y)
74417441
{
7442-
if ((col->baseblock != 0) && (col->cubes[0] == 0))
7442+
if ((col->floor_texture != 0) && (col->cubes[0] == 0))
74437443
{
74447444
*ymax = pos_y;
7445-
textr_idx = engine_remap_texture_blocks(stl_x, stl_y, col->baseblock);
7445+
textr_idx = engine_remap_texture_blocks(stl_x, stl_y, col->floor_texture);
74467446
if ((mapblk->flags & SlbAtFlg_Unexplored) != 0)
74477447
{
74487448
add_textruredquad_to_polypool(pos_x, pos_y, textr_idx, a7, 0,

src/engine_textures.c

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
extern "C" {
3535
#endif
3636
/******************************************************************************/
37-
/******************************************************************************/
38-
unsigned char block_mem[TEXTURE_FILES_COUNT * TEXTURE_BLOCKS_STAT_COUNT * 32 * 32];
39-
unsigned char *block_ptrs[TEXTURE_FILES_COUNT * TEXTURE_BLOCKS_COUNT];
37+
unsigned char block_mem[TEXTURE_VARIATIONS_COUNT * TEXTURE_BLOCKS_STAT_COUNT * 32 * 32];
38+
unsigned char *block_ptrs[TEXTURE_VARIATIONS_COUNT * TEXTURE_BLOCKS_COUNT];
4039

4140
long block_dimension = 32;
4241
long block_count_per_row = 8;
@@ -51,13 +50,13 @@ void setup_texture_block_mem(void)
5150
{
5251
unsigned char** dst = block_ptrs;
5352
unsigned char* src = block_mem;
54-
for (int i = 0; i < (TEXTURE_FILES_COUNT * TEXTURE_BLOCKS_COUNT); i++)
53+
for (int i = 0; i < (TEXTURE_VARIATIONS_COUNT * TEXTURE_BLOCKS_COUNT); i++)
5554
{
5655
block_ptrs[i] = block_mem + block_dimension;
5756
}
58-
for (int f = 0; f < TEXTURE_FILES_COUNT; f++)
57+
for (int f = 0; f < TEXTURE_VARIATIONS_COUNT; f++)
5958
{
60-
for (int i = 0; i < TEXTURE_BLOCKS_STAT_COUNT / block_count_per_row; i++)
59+
for (int i = 0; i < TEXTURE_BLOCKS_STAT_COUNT_A / block_count_per_row; i++)
6160
{
6261
for (unsigned long k = 0; k < block_count_per_row; k++)
6362
{
@@ -68,6 +67,18 @@ void setup_texture_block_mem(void)
6867
src += (block_dimension-1)*block_dimension*block_count_per_row;
6968
}
7069
dst += TEXTURE_BLOCKS_ANIM_COUNT;
70+
71+
for (int i = 0; i < TEXTURE_BLOCKS_STAT_COUNT_B / block_count_per_row; i++)
72+
{
73+
for (unsigned long k = 0; k < block_count_per_row; k++)
74+
{
75+
*dst = src;
76+
src += block_dimension;
77+
dst++;
78+
}
79+
src += (block_dimension-1)*block_dimension*block_count_per_row;
80+
}
81+
7182
}
7283
}
7384

@@ -85,14 +96,15 @@ short update_animating_texture_maps(void)
8596
short result=true;
8697

8798
anim_counter = (anim_counter+1) % TEXTURE_BLOCKS_ANIM_FRAMES;
88-
for (int f = 0; f < TEXTURE_FILES_COUNT; f++)
99+
for (int f = 0; f < TEXTURE_VARIATIONS_COUNT; f++)
89100
{
90101
for (int i = 0; i < TEXTURE_BLOCKS_ANIM_COUNT; i++)
91102
{
92103
short j = game.texture_animation[TEXTURE_BLOCKS_ANIM_FRAMES*i+anim_counter];
93-
if ((j>=0) && (j<TEXTURE_BLOCKS_STAT_COUNT))
104+
if (((j>=0) && (j<TEXTURE_BLOCKS_STAT_COUNT_A)) ||
105+
((j>=TEX_B_START_POINT) && (j<(TEX_B_START_POINT + TEXTURE_BLOCKS_STAT_COUNT_B))))
94106
{
95-
dst[TEXTURE_BLOCKS_STAT_COUNT + i] = dst[j];
107+
dst[TEXTURE_BLOCKS_STAT_COUNT_A + i] = dst[j];
96108
}
97109
else
98110
{
@@ -104,14 +116,16 @@ short update_animating_texture_maps(void)
104116
return result;
105117
}
106118

107-
static TbBool load_one_file(unsigned long tmapidx, void *dst)
119+
static TbBool load_one_file(unsigned long tmapidx,char letter, void *dst)
108120
{
109121
SYNCDBG(9,"Starting");
110-
#ifdef SPRITE_FORMAT_V2
111-
fname = prepare_file_fmtpath(FGrp_StdData,"tmapa%03d-%d.dat",tmapidx,32);
112-
#else
113-
char* fname = prepare_file_fmtpath(FGrp_StdData, "tmapa%03d.dat", tmapidx);
114-
#endif
122+
123+
char* fname = prepare_file_fmtpath(FGrp_CmpgConfig, "tmap%c%03d.dat",letter, tmapidx);
124+
if (!LbFileExists(fname))
125+
{
126+
fname = prepare_file_fmtpath(FGrp_StdData, "tmap%c%03d.dat",letter, tmapidx);
127+
}
128+
115129
if (!wait_for_cd_to_be_available())
116130
return false;
117131
if (!LbFileExists(fname))
@@ -127,21 +141,28 @@ static TbBool load_one_file(unsigned long tmapidx, void *dst)
127141
}
128142
return true;
129143
}
130-
TbBool load_texture_map_file(unsigned long tmapidx, unsigned char n)
144+
145+
TbBool load_texture_map_file(unsigned long tmapidx)
131146
{
132147
SYNCDBG(7,"Starting");
133148
memset(block_mem, 130, sizeof(block_mem));
134-
if (!load_one_file(tmapidx, block_mem))
149+
if (!load_one_file(tmapidx,'a', block_mem))
135150
{
136151
return false;
137152
}
138-
unsigned char *dst = block_mem + (TEXTURE_BLOCKS_STAT_COUNT * 32 * 32);
139-
for (int i = 0; i < TEXTURE_FILES_COUNT-1; i++, dst += (TEXTURE_BLOCKS_STAT_COUNT * 32 * 32))
153+
unsigned char *dst = block_mem + (TEXTURE_BLOCKS_STAT_COUNT_A * 32 * 32);
154+
load_one_file(tmapidx,'b', dst);
155+
dst += (TEXTURE_BLOCKS_STAT_COUNT_B * 32 * 32);
156+
157+
for (int i = 0; i < TEXTURE_VARIATIONS_COUNT-1; i++)
158+
140159
{
141-
if (!load_one_file(i, dst))
142-
{
143-
continue;
144-
}
160+
load_one_file(i,'a', dst);
161+
162+
dst += (TEXTURE_BLOCKS_STAT_COUNT_A * 32 * 32);
163+
load_one_file(i,'b', dst);
164+
dst += (TEXTURE_BLOCKS_STAT_COUNT_B * 32 * 32);
165+
145166
}
146167
return true;
147168
}

src/engine_textures.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,39 @@
2222

2323
#include "bflib_basics.h"
2424
#include "globals.h"
25-
#include "game_legacy.h"
2625

2726
#ifdef __cplusplus
2827
extern "C" {
2928
#endif
3029
/******************************************************************************/
3130
// Num of known texture files
32-
#define TEXTURE_FILES_COUNT 16
31+
#define TEXTURE_VARIATIONS_COUNT 16
32+
33+
// Static textures in tmapa
34+
#define TEXTURE_BLOCKS_STAT_COUNT_A 544
35+
// Static textures in tmapb
36+
#define TEXTURE_BLOCKS_STAT_COUNT_B 544
37+
#define TEX_B_START_POINT 1000
38+
39+
#define TEXTURE_BLOCKS_STAT_COUNT (TEXTURE_BLOCKS_STAT_COUNT_A + TEXTURE_BLOCKS_STAT_COUNT_B)
40+
// Animated texture frames count
41+
#define TEXTURE_BLOCKS_ANIM_FRAMES 8
42+
// Animated textures amount
43+
#define TEXTURE_BLOCKS_ANIM_COUNT TEX_B_START_POINT - TEXTURE_BLOCKS_STAT_COUNT_A
44+
#define TEXTURE_BLOCKS_COUNT (TEXTURE_BLOCKS_STAT_COUNT + TEXTURE_BLOCKS_ANIM_COUNT)
3345

3446
#define TEXTURE_LAND_MARKED_LAND 578
3547
#define TEXTURE_LAND_MARKED_GOLD 579
3648
/******************************************************************************/
3749

38-
extern unsigned char block_mem[TEXTURE_FILES_COUNT * TEXTURE_BLOCKS_STAT_COUNT * 32 * 32];
39-
extern unsigned char *block_ptrs[TEXTURE_FILES_COUNT * TEXTURE_BLOCKS_COUNT];
50+
extern unsigned char block_mem[TEXTURE_VARIATIONS_COUNT * TEXTURE_BLOCKS_STAT_COUNT * 32 * 32];
51+
extern unsigned char *block_ptrs[TEXTURE_VARIATIONS_COUNT * TEXTURE_BLOCKS_COUNT];
4052
extern long block_dimension;
4153
/******************************************************************************/
4254
void setup_texture_block_mem(void);
4355
short init_animating_texture_maps(void);
4456
short update_animating_texture_maps(void);
45-
TbBool load_texture_map_file(unsigned long tmapidx, unsigned char n);
57+
TbBool load_texture_map_file(unsigned long tmapidx);
4658

4759
/******************************************************************************/
4860
#ifdef __cplusplus

src/game_legacy.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,9 @@
5454
#include "sounds.h"
5555
#include "game_lghtshdw.h"
5656
#include "game_merge.h"
57+
#include "engine_textures.h"
5758

5859
#define BOOKMARKS_COUNT 5
59-
// Static textures
60-
#define TEXTURE_BLOCKS_STAT_COUNT 544
61-
// Animated texture frames count
62-
#define TEXTURE_BLOCKS_ANIM_FRAMES 8
63-
// Animated textures amount
64-
#define TEXTURE_BLOCKS_ANIM_COUNT 48
65-
#define TEXTURE_BLOCKS_COUNT (TEXTURE_BLOCKS_STAT_COUNT+TEXTURE_BLOCKS_ANIM_COUNT)
6660

6761
#ifdef __cplusplus
6862
extern "C" {
@@ -195,7 +189,7 @@ unsigned int packet_file_pos;
195189
int something_light_x;
196190
int something_light_y;
197191
unsigned long time_delta;
198-
short top_cube[592];
192+
short top_cube[TEXTURE_BLOCKS_COUNT];// if you ask for top cube on a column without cubes, it'll return the first cube it finds with said texture at the top
199193
unsigned char small_map_state;
200194
struct Coord3d mouse_light_pos;
201195
struct Packet packets[PACKETS_COUNT];

src/lvl_filesdk1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ TbBool columns_add_static_entries(void)
985985
for (long i=0; i < 3; i++)
986986
{
987987
LbMemorySet(&lcolmn, 0, sizeof(struct Column));
988-
lcolmn.baseblock = c[i];
988+
lcolmn.floor_texture = c[i];
989989
for (long k = 0; k < 6; k++)
990990
{
991991
lcolmn.cubes[0] = player_cubes[k];
@@ -1015,7 +1015,7 @@ TbBool update_slabset_column_indices(struct Column *cols, long ccount)
10151015
long ncol;
10161016
if (n >= 0)
10171017
{
1018-
lcolmn.baseblock = n;
1018+
lcolmn.floor_texture = n;
10191019
ncol = find_column(&lcolmn);
10201020
if (ncol == 0)
10211021
{
@@ -1405,7 +1405,7 @@ static TbBool load_level_file(LevelNumber lvnum)
14051405
result = false;
14061406
load_map_wibble_file(lvnum);
14071407
load_and_setup_map_info(lvnum);
1408-
load_texture_map_file(game.texture_id, 2);
1408+
load_texture_map_file(game.texture_id);
14091409
if (new_format)
14101410
{
14111411
load_aptfx_file(lvnum);
@@ -1437,7 +1437,7 @@ static TbBool load_level_file(LevelNumber lvnum)
14371437
load_slab_file();
14381438
init_columns();
14391439
game.texture_id = 0;
1440-
load_texture_map_file(game.texture_id, 2);
1440+
load_texture_map_file(game.texture_id);
14411441
init_top_texture_to_cube_table();
14421442
result = false;
14431443
}

0 commit comments

Comments
 (0)