Replaced some bg_list usages by std::vector

This commit is contained in:
Walter Julius Hennecke 2018-06-30 18:31:35 +02:00
parent 2711c300dd
commit 0a8684db2d
6 changed files with 2274 additions and 2304 deletions

View file

@ -6625,10 +6625,6 @@ Cmd_getEntByTarget_f
*/
static void Cmd_getEntByTarget_f(gentity_t* ent) {
char arg[MAX_STRING_TOKENS];
struct list entities;
list_iter_p iter;
container_p c;
gentity_t* t = NULL;
G_Assert(ent, (void)0);
@ -6646,13 +6642,10 @@ static void Cmd_getEntByTarget_f(gentity_t* ent) {
trap_Argv(1, arg, sizeof(arg));
list_init(&entities, free);
G_GetEntityByTarget(arg, &entities);
iter = entities.iterator(&entities, LIST_FRONT);
for (c = entities.next(iter); c != NULL; c = entities.next(iter)) {
t = (gentity_t*)c->data;
auto entities = G_GetEntityByTarget(arg);
for(auto t : entities)
{
if (t == NULL) {
continue;
}
@ -6663,8 +6656,6 @@ static void Cmd_getEntByTarget_f(gentity_t* ent) {
G_PrintfClient(ent, "ENT %i: %s\n\"", t->s.number, t->classname);
}
destroy_iterator(iter);
entities.clear(&entities);
}
/*
@ -7727,11 +7718,6 @@ static void Cmd_findEntitiesInRadius(gentity_t* ent) {
qboolean all = qfalse;
qboolean takeDamage = qfalse;
int32_t radius = 0;
struct list entities;
struct list ignore;
list_iter_p iter;
container_p c;
gentity_t* t = NULL;
G_Assert(ent, (void)0);
@ -7768,31 +7754,27 @@ static void Cmd_findEntitiesInRadius(gentity_t* ent) {
trap_Argv(3, arg, sizeof(arg));
takeDamage = (qboolean)atoi(arg);
list_init(&entities, free);
list_init(&ignore, free);
ignore.append_ptr(&ignore, ent, LT_DATA);
G_RadiusList(ent->r.currentOrigin, radius, &ignore, takeDamage, &entities);
ignore.clear(&ignore);
iter = entities.iterator(&entities, LIST_FRONT);
for (c = entities.next(iter); c != NULL; c = entities.next(iter)) {
t = (gentity_t*)c->data;
auto entities = G_RadiusList(ent->r.currentOrigin, radius, {ent}, takeDamage);
for(auto t : entities)
{
if(t == nullptr)
{
continue;
}
if (t == NULL) {
continue;
}
if (all) {
G_PrintfClient(ent, "Entity: %i, Classname: %s", t - g_entities, t->classname);
}
else {
if (Q_stricmpn(t->classname, classname, strlen(classname)) == 0) {
G_PrintfClient(ent, "Entity: %i Classname: %s", t - g_entities, classname);
}
}
}
destroy_iterator(iter);
entities.clear(&entities);
if(all)
{
G_PrintfClient(ent, "Entity: %i, Classname: %s", t - g_entities, t->classname);
}
else
{
if(Q_stricmpn(t->classname, classname, strlen(classname)) == 0)
{
G_PrintfClient(ent, "Entity: %i Classname: %s", t - g_entities, classname);
}
}
}
}
// CCAM
@ -7851,54 +7833,28 @@ void Cmd_ScriptCall_f(gentity_t* ent) {
}
}
void addShaderToList(list_p list, char* shader) {
char* s = NULL;
char* t = NULL;
container_p c;
list_iter_p i;
if (shader[0] == 0) {
void addShaderToList(std::vector<std::string>& list, char* shader) {
if (shader[0] == 0) {
return;
}
if (list == NULL) {
return;
}
s = strdup(shader);
if (s == NULL) {
return;
}
i = list->iterator(list, LIST_FRONT);
if (i == NULL) {
free(s);
return;
}
for (c = list->next(i); c != NULL; c = list->next(i)) {
t = (char*)c->data;
if (!strcmp(shader, t)) {
free(s);
for(auto t : list)
{
if (!strcmp(shader, t.data())) {
return;
}
}
destroy_iterator(i);
}
list->append(list, s, LT_STRING, strlen(s) + 1);
list.push_back(shader);
}
extern target_alert_Shaders_s alertShaders;
void Cmd_GeneratePrecacheFile(gentity_t* ent) {
char info[MAX_INFO_STRING];
char file[MAX_QPATH];
char* s = NULL;
int32_t i = 0;
list_p shaders;
list_iter_p iter;
qboolean first = qtrue;
fileHandle_t f;
container_p c;
G_Assert(ent, (void)0);
@ -7910,12 +7866,7 @@ void Cmd_GeneratePrecacheFile(gentity_t* ent) {
return;
}
shaders = create_list();
if (shaders == NULL) {
G_Printf(S_COLOR_RED "[Error] - Could not create shader list.\n");
trap_FS_FCloseFile(f);
return;
}
std::vector<std::string> shaders;
G_Printf("Generating precache file '%s' ...\n", file);
@ -7944,36 +7895,25 @@ void Cmd_GeneratePrecacheFile(gentity_t* ent) {
}
}
iter = shaders->iterator(shaders, LIST_FRONT);
if (iter == NULL) {
trap_FS_FCloseFile(f);
destroy_list(shaders);
return;
}
for (c = shaders->next(iter); c != NULL; c = shaders->next(iter)) {
s = (char*)c->data;
G_Printf("\t%s\n", s);
for(auto s : shaders)
{
G_Printf("\t%s\n", s.data());
if (first) {
trap_FS_Write("\"", 1, f);
trap_FS_Write(s, strlen(s), f);
trap_FS_Write(s.data(), s.length(), f);
trap_FS_Write("\"", 1, f);
first = qfalse;
}
else {
trap_FS_Write("\n\"", 2, f);
trap_FS_Write(s, strlen(s), f);
trap_FS_Write(s.data(), s.length(), f);
trap_FS_Write("\"", 1, f);
}
}
trap_FS_Write("\n\"END\"", 6, f);
destroy_iterator(iter);
G_Printf("Done.\n");
if (shaders != NULL) {
destroy_list(shaders);
}
trap_FS_FCloseFile(f);
}

View file

@ -10,7 +10,6 @@
#include "../base_game/q_shared.h"
#include "../base_game/bg_public.h"
#include "g_public.h"
#include "../base_game/bg_list.h"
//==================================================================
@ -703,39 +702,6 @@ struct gclient_s {
#define MAX_SPAWN_VARS 64
#define MAX_SPAWN_VARS_CHARS 2048
/** \typedef levelLocation
* Type for level location.
* @see levelLocation_s
*
* \author Ubergames - GSIO01
*/
typedef struct levelLocation_s levelLocation;
/** \typedef levelLocation´_p
* Pointer to a level location.
* @see levelLocation
* @see levelLocation_s
*
* \author Ubergames - GSIO01
*/
typedef levelLocation levelLocation_p;
/** \struct levelLocation_s
* Describes a level location.
*
* Contains a list of origin and angles where the first is the primary location origin and angles.
* A name which identifies the location like the targetname for entities.
* The actual description displayed.
*
* \author Ubergames - GSIO01
*/
struct levelLocation_s {
list_p origins;
list_p angles;
char* name;
char* description;
};
/** \typedef srvChangeData_t
* Type for \link srvChangeData_s \endlink
*
@ -833,9 +799,6 @@ typedef struct {
int numBrushEnts; /*!< number of entities in the level that use brushmodels */
/*@shared@*/ /*@null@*/ list_p safezones; /*!< self destruct safezones list */
/*@shared@*/ /*@null@*/ list_p locations; /*!< level locations list */
size_t timedMessageIndex = 0;
std::vector<std::string> timedMessages;
@ -1137,10 +1100,9 @@ void G_SetAngles( gentity_t* ent, vec3_t anlges ); //RPG-X | GSIO01 | 24.08.2009
* \param radius Radius to serach in.
* \param ignore List of entities to ignore.
* \param takeDamage Only return entities matching this value for takeDamage.
* \param ent_list List to store found entities in.
* \return Count of entities found.
* \return List of entities.
*/
int32_t G_RadiusList ( vec3_t origin, double radius, list_p ignore, qboolean takeDamage, list_p ent_list);
std::vector<gentity_t*> G_RadiusList(vec3_t origin, double radius, const std::vector<gentity_t*>& ignore, qboolean takeDamage);
/**
* Get a list of specified entity classes in a specified radius.
@ -1155,7 +1117,7 @@ int32_t G_RadiusList ( vec3_t origin, double radius, list_p ignore, qboolean tak
* \param ent_list list to store the results
* \return count of found entities
*/
int32_t G_RadiusListOfTypes(list_p classnames, vec3_t origin, double radius, list_p ignore, list_p ent_list);
std::vector<gentity_t*> G_RadiusListOfTypes(const std::vector<std::string>& classnames, vec3_t origin, double radius, const std::vector<gentity_t*>& ignore);
/**
* Get the neares entity to an origin.
@ -1167,7 +1129,7 @@ int32_t G_RadiusListOfTypes(list_p classnames, vec3_t origin, double radius, lis
* \param takeDamage Only return entities that match this value for takeDamage.
* \return Nearest entity found.
*/
/*@shared@*/ /*@null@*/ gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, double radius, list_p ignore, qboolean takeDamage);
/*@shared@*/ /*@null@*/ gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, double radius, std::vector<gentity_t*>& ignore, qboolean takeDamage);
/**
* Get the nearest player orund an origin.
@ -1177,7 +1139,7 @@ int32_t G_RadiusListOfTypes(list_p classnames, vec3_t origin, double radius, lis
* \param ignore List of entities to ignore.
* \return Nearest player.
*/
/*@shared@*/ /*@null@*/ gentity_t* G_GetNearestPlayer(vec3_t origin, double radius, list_p ignore );
/*@shared@*/ /*@null@*/ gentity_t* G_GetNearestPlayer(vec3_t origin, double radius, const std::vector<gentity_t*>& ignore);
/**
* \author Ubergames - GSIO01
@ -1190,7 +1152,7 @@ int32_t G_RadiusListOfTypes(list_p classnames, vec3_t origin, double radius, lis
*
* \return number of entities found
*/
int G_GetEntityByTargetname(const char* targetname, list_p entities);
int G_GetEntityByTargetname(const char* targetname, std::vector<gentity_t*>& entities);
/**
* \author Ubergames - GSIO01
@ -1203,7 +1165,7 @@ int G_GetEntityByTargetname(const char* targetname, list_p entities);
*
* \return number of matches found
*/
int G_GetEntityByTarget(const char* target, list_p entities);
std::vector<gentity_t*> G_GetEntityByTarget(const char* target);
/**
* \author Ubergames - GSIO01
@ -1217,7 +1179,7 @@ int G_GetEntityByTarget(const char* target, list_p entities);
*
* \return number of matches found
*/
int G_GetEntityByBmodel(char* bmodel,list_p entities);
int G_GetEntityByBmodel(char* bmodel, std::vector<gentity_t*>& entities);
/**
* \brief Add a new shader remap.

View file

@ -1,7 +1,6 @@
// Copyright (C) 1999-2000 Id Software, Inc.
//
#include "g_local.h"
#include "../base_game/bg_list.h"
#include "../base_game/bg_misc.h"
#include "g_spawn.h"
#include "g_client.h"

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1255,13 +1255,7 @@ HYPERSPANNER
*/
static void WP_FireHyperspanner(gentity_t* ent, qboolean alt_fire) {
double modifier = 0.0;
struct list validEnts;
struct list classnames;
list_iter_p iter = NULL;
container_p cont = NULL;
gentity_t* e = NULL;
gentity_t* nearest = NULL;
int32_t count = 0;
double nearestd = 65000.0;
vec3_t dVec = { 0, 0, 0 };
vec3_t end = { 0, 0, 0 };
@ -1273,24 +1267,18 @@ static void WP_FireHyperspanner(gentity_t* ent, qboolean alt_fire) {
G_Assert(ent, (void)0);
/* prepare lists */
list_init(&classnames, free);
list_init(&validEnts, free);
classnames.append(&classnames, "func_breakable", LT_STRING, strlen("func_breakable") + 1);
classnames.append(&classnames, "misc_model_breakable", LT_STRING, strlen("misc_model_breakable") + 1);
std::vector<std::string> classnames = {"func_breakable", "misc_model_breakable"};
/* find all vlaid entities in range */
count = G_RadiusListOfTypes(&classnames, ent->r.currentOrigin, 512, NULL, &validEnts);
classnames.clear(&classnames);
auto validEnts = G_RadiusListOfTypes(classnames, ent->r.currentOrigin, 512, {});
if (count > 0) {
if (!validEnts.empty()) {
trace_t tr;
memset(&tr, 0, sizeof(trace_t));
iter = validEnts.iterator(&validEnts, LIST_FRONT);
for (cont = validEnts.next(iter); cont != NULL; cont = validEnts.next(iter)) {
e = (gentity_t*)cont->data;
for(auto e : validEnts)
{
// TODO: fix problems with small distance
if ((e->spawnflags & 512) != 0) {
VectorSubtract(ent->r.currentOrigin, e->s.angles2, dVec);
@ -1323,7 +1311,6 @@ static void WP_FireHyperspanner(gentity_t* ent, qboolean alt_fire) {
}
if (nearest == NULL || nearest->inuse == qfalse) {
validEnts.clear(&validEnts);
G_LogFuncEnd();
return;
}
@ -1342,8 +1329,6 @@ static void WP_FireHyperspanner(gentity_t* ent, qboolean alt_fire) {
G_Combat_Repair(ent, nearest, weaponConfig.hyperspanner.primary.rate * modifier);
}
validEnts.clear(&validEnts);
G_LogFuncEnd();
}