mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-22 10:52:23 +00:00
Fix removing a tag unsetting the bit array even if more elements with that tag exist
This commit is contained in:
parent
ae663e7247
commit
e5a3e6a845
3 changed files with 25 additions and 6 deletions
|
@ -145,7 +145,7 @@ static int lib_numTaggroupElements(lua_State *L)
|
|||
else
|
||||
{
|
||||
const taggroup_t ** garray = lua_touserdata(L, up_garray);
|
||||
lua_pushnumber(L, garray[tag] ? garray[tag]->count : 0);
|
||||
lua_pushnumber(L, Taggroup_Count(garray[tag]));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -110,6 +110,12 @@ size_t Taggroup_Find (const taggroup_t *group, const size_t id)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/// group->count, but also checks for NULL
|
||||
size_t Taggroup_Count (const taggroup_t *group)
|
||||
{
|
||||
return group ? group->count : 0;
|
||||
}
|
||||
|
||||
/// Iterate thru elements in a global taggroup.
|
||||
INT32 Taggroup_Iterate
|
||||
( taggroup_t *garray[],
|
||||
|
@ -153,9 +159,10 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id)
|
|||
return;
|
||||
|
||||
if (! in_bit_array(tags_available, tag))
|
||||
{
|
||||
num_tags++;
|
||||
|
||||
set_bit_array(tags_available, tag);
|
||||
set_bit_array(tags_available, tag);
|
||||
}
|
||||
|
||||
// Create group if empty.
|
||||
if (!group)
|
||||
|
@ -182,6 +189,16 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id)
|
|||
group->elements[i] = id;
|
||||
}
|
||||
|
||||
static size_t total_elements_with_tag (const mtag_t tag)
|
||||
{
|
||||
return
|
||||
(
|
||||
Taggroup_Count(tags_sectors[tag]) +
|
||||
Taggroup_Count(tags_lines[tag]) +
|
||||
Taggroup_Count(tags_mapthings[tag])
|
||||
);
|
||||
}
|
||||
|
||||
/// Remove an element from a global taggroup.
|
||||
void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id)
|
||||
{
|
||||
|
@ -197,10 +214,11 @@ void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id)
|
|||
if ((rempos = Taggroup_Find(group, id)) == (size_t)-1)
|
||||
return;
|
||||
|
||||
if (in_bit_array(tags_available, tag))
|
||||
if (group->count == 1 && total_elements_with_tag(tag) == 1)
|
||||
{
|
||||
num_tags--;
|
||||
|
||||
unset_bit_array(tags_available, tag);
|
||||
unset_bit_array(tags_available, tag);
|
||||
}
|
||||
|
||||
// Strip away taggroup if no elements left.
|
||||
if (!(oldcount = group->count--))
|
||||
|
|
|
@ -54,6 +54,7 @@ extern taggroup_t* tags_mapthings[];
|
|||
void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id);
|
||||
void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id);
|
||||
size_t Taggroup_Find (const taggroup_t *group, const size_t id);
|
||||
size_t Taggroup_Count (const taggroup_t *group);
|
||||
|
||||
INT32 Taggroup_Iterate
|
||||
( taggroup_t *garray[],
|
||||
|
|
Loading…
Reference in a new issue