From 8b4f0249e7f324cfa5d4f3a21df8efb4c3850ef9 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sat, 24 Dec 2016 15:46:13 +0100 Subject: Improve entity discarding. Instead of discarding all team_* and info_* entities from all maps but the iirst one, discard all entities with the "mapcat_discard" key. --- src/common.h | 4 +++- src/main.c | 3 +-- src/mapcat.c | 38 +++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/common.h b/src/common.h index 0413001..dd892ff 100644 --- a/src/common.h +++ b/src/common.h @@ -112,6 +112,8 @@ typedef struct { typedef struct { char *classname; + bool discard; + brush_t *brushes; entity_key_t *keys; @@ -132,6 +134,6 @@ void map_init(map_t *map); void map_free(map_t *map); int map_read(map_t *map, const char *path); int map_write(const map_t *map, const char *path); -int map_postprocess(map_t *map, bool filter_team_ents); +int map_postprocess(map_t *map); int map_merge(map_t *master, map_t *slave); void map_print_stats(const char *path, const map_t *map); diff --git a/src/main.c b/src/main.c index 4778b51..30c5d15 100644 --- a/src/main.c +++ b/src/main.c @@ -118,8 +118,7 @@ int main(int argc, char **argv) goto out; } - // team_* and info_* ents are kept only in the first part - if (map_postprocess(&part, (input != inputs))) { + if (map_postprocess(&part)) { map_free(&map); map_free(&part); goto out; diff --git a/src/mapcat.c b/src/mapcat.c index 54bed98..8a19c77 100644 --- a/src/mapcat.c +++ b/src/mapcat.c @@ -102,6 +102,16 @@ static int read_entity_key(lexer_state_t *ls, entity_t *entity) return 0; } + if (!vstr_cmp(ls->token, "mapcat_discard")) { + entity->discard = true; + + // make sure to read (and forget) the value + if (lexer_get_token(ls)) + goto expected_key_value; + + return 0; + } + key = malloc(sizeof(entity_key_t)); if (!key) goto error_oom; @@ -114,6 +124,7 @@ static int read_entity_key(lexer_state_t *ls, entity_t *entity) goto error_oom; if (lexer_get_token(ls)) { + expected_key_value: lexer_perror_eg(ls, "the key value"); return 1; } @@ -281,7 +292,7 @@ static int read_brush_faces(lexer_state_t *ls, brush_t *brush) while (1) { if (lexer_get_token(ls)) { bad_token: - lexer_perror_eg(ls, "the beginning of a brush face, " + lexer_perror_eg(ls, "the beginning of a brush face" " \"(\", the end of this brush" " \"}\" or the beginning of a" " patch \"patchDef2\""); @@ -400,6 +411,12 @@ static int read_entity(lexer_state_t *ls, map_t *map) } no_brushes: + if (entity->discard) { + map->num_discarded_entities++; + free_entity(entity); + return 0; + } + if (!strcmp(entity->classname, "worldspawn")) { if (map->worldspawn) { lexer_perror(ls, "this entity is a worldspawn, but a " @@ -619,29 +636,12 @@ out: return rv; } -int map_postprocess(map_t *map, bool filter_team_ents) +int map_postprocess(map_t *map) { entity_t *entity; entity_key_t *key; char *prefix = NULL; - if (filter_team_ents) { - entity_t *next; - - for (entity = map->entities; entity; entity = next) { - next = elist_next(entity, list); - - if (strncmp(entity->classname, "team_", 5) && - strncmp(entity->classname, "info_", 5)) - continue; - - map->num_entities--; - map->num_discarded_entities++; - elist_unlink(&map->entities, entity, list); - free_entity(entity); - } - } - if (map->worldspawn) { entity_key_t *next; -- cgit