Skip to content

Commit 8d1d73e

Browse files
committed
refactor: minor combo alias optimizations/cleanup
1 parent 6e0636d commit 8d1d73e

File tree

7 files changed

+91
-351
lines changed

7 files changed

+91
-351
lines changed

src/base/cpool.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,11 @@ int comboa_lmasktotal(byte layermask)
1515
++result;
1616
return result;
1717
}
18-
combo_alias::combo_alias()
19-
{
20-
memset(this, 0, sizeof(combo_alias));
21-
combos = new word[1];
22-
csets = new byte[1];
23-
combos[0] = 0;
24-
csets[0] = 0;
25-
}
2618
bool combo_alias::valid() const
2719
{
2820
if(combo)
2921
return combobuf[combo].tile;
30-
return width || height || (combos && combos[0]);
31-
}
32-
combo_alias& combo_alias::operator=(combo_alias const& other)
33-
{
34-
width = other.width;
35-
height = other.height;
36-
layermask = other.layermask;
37-
combo = other.combo;
38-
cset = other.cset;
39-
int count = (comboa_lmasktotal(layermask)+1)*(width+1)*(height+1);
40-
if(combos) delete[] combos;
41-
if(csets) delete[] csets;
42-
combos = new word[count];
43-
csets = new byte[count];
44-
memcpy(combos, other.combos, sizeof(word)*count);
45-
memcpy(csets, other.csets, sizeof(byte)*count);
46-
return *this;
22+
return width || height || (combos.size() && combos[0]);
4723
}
4824
void combo_alias::clear()
4925
{

src/base/cpool.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#ifndef _CPOOL_H_
22
#define _CPOOL_H_
33

4-
#include <vector>
4+
#include "base/headers.h"
5+
#include "base/containers.h"
56
#include "base/ints.h"
67
#include "base/general.h"
78

89
struct combo_alias
910
{
10-
combo_alias();
11+
combo_alias() = default;
1112

1213
byte width; // Max 15
1314
byte height; // Max 10
1415
byte layermask; // Specifies layers to be drawn
1516
word combo; // Optional thumbnail combo for the alias list
1617
word cset;
17-
word *combos; // Dynamic array. Will be stored in quest.
18-
byte *csets;
18+
bounded_vec<word,word> combos = {16*11*7, 0};
19+
bounded_vec<word,byte> csets = {16*11*7, 0};
1920

2021
bool valid() const;
2122
void clear();
22-
combo_alias& operator=(combo_alias const& other);
23+
combo_alias& operator=(combo_alias const& other) = default;
2324
};
2425

2526
struct cpool_entry

src/qst.cpp

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,6 @@ enum { ssiBOMB, ssiSWORD, ssiSHIELD, ssiCANDLE, ssiLETTER, ssiPOTION, ssiLETTERP
143143
static byte deprecated_rules[QUESTRULES_NEW_SIZE];
144144

145145

146-
void delete_combo_aliases()
147-
{
148-
for(int32_t j(0); j<256; j++)
149-
{
150-
if(combo_aliases[j].combos != NULL)
151-
{
152-
delete[] combo_aliases[j].combos;
153-
combo_aliases[j].combos=NULL;
154-
}
155-
156-
if(combo_aliases[j].csets != NULL)
157-
{
158-
delete[] combo_aliases[j].csets;
159-
combo_aliases[j].csets=NULL;
160-
}
161-
}
162-
163-
}
164-
165146
char *byte_conversion(int32_t number, int32_t format)
166147
{
167148
static char num_str[40];
@@ -17849,21 +17830,8 @@ int32_t readcombos_old(word section_version, PACKFILE *f, zquestheader *, word v
1784917830
combo_aliases[j].width = 0;
1785017831
combo_aliases[j].height = 0;
1785117832
combo_aliases[j].layermask = 0;
17852-
17853-
if(combo_aliases[j].combos != NULL)
17854-
{
17855-
delete[] combo_aliases[j].combos;
17856-
}
17857-
17858-
if(combo_aliases[j].csets != NULL)
17859-
{
17860-
delete[] combo_aliases[j].csets;
17861-
}
17862-
17863-
combo_aliases[j].combos = new word[1];
17864-
combo_aliases[j].csets = new byte[1];
17865-
combo_aliases[j].combos[0] = 0;
17866-
combo_aliases[j].csets[0] = 0;
17833+
combo_aliases[j].combos.clear();
17834+
combo_aliases[j].csets.clear();
1786717835
}
1786817836
}
1786917837

@@ -18288,21 +18256,11 @@ int32_t readcomboaliases(PACKFILE *f, zquestheader *Header, word version, word b
1828818256

1828918257
count=(width+1)*(height+1)*(comboa_lmasktotal(mask)+1);
1829018258

18291-
if(combo_aliases[j].combos != NULL)
18292-
{
18293-
delete[] combo_aliases[j].combos;
18294-
}
18295-
18296-
if(combo_aliases[j].csets != NULL)
18297-
{
18298-
delete[] combo_aliases[j].csets;
18299-
}
18300-
1830118259
combo_aliases[j].width = width;
1830218260
combo_aliases[j].height = height;
1830318261
combo_aliases[j].layermask = mask;
18304-
combo_aliases[j].combos = new word[count];
18305-
combo_aliases[j].csets = new byte[count];
18262+
combo_aliases[j].combos.clear();
18263+
combo_aliases[j].csets.clear();
1830618264

1830718265
for(int32_t k=0; k<count; k++)
1830818266
{

src/qst.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ void init_msgstr(MsgStr *str);
264264
int32_t get_version_and_build(PACKFILE *f, word *version, word *build);
265265
bool find_section(PACKFILE *f, int32_t section_id_requested);
266266

267-
extern void delete_combo_aliases();
268267
void reset_subscreen(subscreen_group *tempss);
269268
void reset_subscreens();
270269
int32_t setupsubscreens();

src/zc/zelda.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5629,7 +5629,6 @@ void remove_installed_timers()
56295629

56305630
void delete_everything_else() //blarg.
56315631
{
5632-
delete_combo_aliases();
56335632
refresh_subscr_buttonitems();
56345633
kill_subscr_items();
56355634
}

src/zq/zq_tiles.cpp

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19404,11 +19404,9 @@ int32_t readcomboaliasfile(PACKFILE *f)
1940419404
return 0;
1940519405
}
1940619406
//These values are flexible, and may differ in size, so we delete them
19407-
//and recreate them at the correct size on the pointer.
19408-
delete[] temp_alias.combos;
19409-
temp_alias.combos = new word[count2];
19410-
delete[] temp_alias.csets;
19411-
temp_alias.csets = new byte[count2];
19407+
//and recreate them at the correct size on the pointer.
19408+
temp_alias.combos.clear();
19409+
temp_alias.csets.clear();
1941219410
for(int32_t k=0; k<count2; k++)
1941319411
{
1941419412
if(!p_igetw(&tempword,f))
@@ -19486,7 +19484,6 @@ int32_t readcomboaliasfile_to_location(PACKFILE *f, int32_t start)
1948619484
al_trace("Cannot read .zalias packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
1948719485
return 0;
1948819486
}
19489-
1949019487
else if ( ( section_version > V_COMBOALIASES ) || ( section_version == V_COMBOALIASES && section_cversion > CV_COMBOALIASES ) )
1949119488
{
1949219489
al_trace("Cannot read .zalias packfile made using V_COMBOALIASES (%d) subversion (%d)\n", section_version, section_cversion);
@@ -19527,80 +19524,71 @@ int32_t readcomboaliasfile_to_location(PACKFILE *f, int32_t start)
1952719524
{
1952819525
memset(&temp_alias, 0, sizeof(temp_alias));
1952919526
if(!p_igetw(&temp_alias.combo,f))
19530-
{
19531-
return 0;
19532-
}
19527+
{
19528+
return 0;
19529+
}
1953319530

19534-
if(!p_getc(&temp_alias.cset,f))
19535-
{
19536-
return 0;
19537-
}
19531+
if(!p_getc(&temp_alias.cset,f))
19532+
{
19533+
return 0;
19534+
}
1953819535

19539-
int32_t count2 = 0;
19536+
int32_t count2 = 0;
1954019537

1954119538
if(!p_igetl(&count2,f))
19542-
{
19543-
return 0;
19544-
}
19539+
{
19540+
return 0;
19541+
}
1954519542

19546-
if(!p_getc(&temp_alias.width,f))
19543+
if(!p_getc(&temp_alias.width,f))
19544+
{
19545+
return 0;
19546+
}
19547+
19548+
if(!p_getc(&temp_alias.height,f))
19549+
{
19550+
return 0;
19551+
}
19552+
19553+
if(!p_getc(&temp_alias.layermask,f))
19554+
{
19555+
return 0;
19556+
}
19557+
//These values are flexible, and may differ in size, so we delete them
19558+
//and recreate them at the correct size on the pointer.
19559+
temp_alias.combos.clear();
19560+
temp_alias.csets.clear();
19561+
19562+
for(int32_t k=0; k<count2; k++)
19563+
{
19564+
if(!p_igetw(&tempword,f))
1954719565
{
1954819566
return 0;
1954919567
}
19550-
19551-
if(!p_getc(&temp_alias.height,f))
19568+
else
1955219569
{
19553-
return 0;
19570+
temp_alias.combos[k] = tempword;
1955419571
}
19572+
}
1955519573

19556-
if(!p_getc(&temp_alias.layermask,f))
19574+
for(int32_t k=0; k<count2; k++)
19575+
{
19576+
if(!p_getc(&tempcset,f))
1955719577
{
1955819578
return 0;
1955919579
}
19560-
//These values are flexible, and may differ in size, so we delete them
19561-
//and recreate them at the correct size on the pointer.
19562-
delete[] temp_alias.combos;
19563-
temp_alias.combos = new word[count2];
19564-
delete[] temp_alias.csets;
19565-
temp_alias.csets = new byte[count2];
19566-
19567-
for(int32_t k=0; k<count2; k++)
19580+
else
1956819581
{
19569-
if(!p_igetw(&tempword,f))
19570-
{
19571-
return 0;
19572-
}
19573-
else
19574-
{
19575-
temp_alias.combos[k] = tempword;
19576-
}
19582+
temp_alias.csets[k] = tempcset;
1957719583
}
19578-
19579-
for(int32_t k=0; k<count2; k++)
19580-
{
19581-
if(!p_getc(&tempcset,f))
19582-
{
19583-
return 0;
19584-
}
19585-
else
19586-
{
19587-
temp_alias.csets[k] = tempcset;
1958819584
}
19589-
}
19590-
1959119585

1959219586
if ( start+(tilect) < MAXCOMBOALIASES )
1959319587
{
1959419588
memcpy(&combo_aliases[start+(tilect)],&temp_alias,sizeof(temp_alias));
1959519589
}
1959619590
}
19597-
19598-
19599-
//::memcpy(&(newtilebuf[tile_index]),&temptile,sizeof(tiledata));
19600-
19601-
1960219591
return 1;
19603-
1960419592
}
1960519593
int32_t writecomboaliasfile(PACKFILE *f, int32_t index, int32_t count)
1960619594
{

0 commit comments

Comments
 (0)