mirror of
https://github.com/UberGames/rpgxEF.git
synced 2025-02-11 10:11:40 +00:00
See extended description
- modified G_RadiusListOfTypes - added list_init - modified list_remove - updated list documentation
This commit is contained in:
parent
aadb40d269
commit
d4c5758fd1
5 changed files with 158 additions and 17 deletions
|
@ -848,7 +848,21 @@ void G_AddEvent( gentity_t* ent, int event, int eventParm );
|
|||
void G_SetOrigin( gentity_t* ent, vec3_t origin );
|
||||
void G_SetAngles( gentity_t* ent, vec3_t anlges ); //RPG-X | GSIO01 | 24.08.2009
|
||||
int G_RadiusList ( vec3_t origin, float radius, gentity_t* ignore, qboolean takeDamage, gentity_t* ent_list[MAX_GENTITIES]);
|
||||
int G_RadiusListOfTypes(char* classname[], int count, vec3_t origin, float radius, gentity_t* ignore, list_p ent_list);
|
||||
|
||||
/**
|
||||
* Get a list of specified entity classes in a specified radius.
|
||||
*
|
||||
* \author Ubergames - GSIO01
|
||||
*
|
||||
* \param classname class names for searched entity classes
|
||||
* \param count cout of class names in classname
|
||||
* \param origin origin around which entities are searched
|
||||
* \param radius radius to search in
|
||||
* \param ignore entity to ignore
|
||||
* \param ent_list list to store the results
|
||||
* \return count of found entities
|
||||
*/
|
||||
int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p ignore, list_p ent_list);
|
||||
gentity_t* G_GetNearestEnt(char* classname, vec3_t origin, float radius, gentity_t* ignore, qboolean takeDamage);
|
||||
gentity_t* G_GetNearestPlayer(vec3_t origin, float radius, gentity_t* ignore );
|
||||
|
||||
|
|
|
@ -1083,20 +1083,28 @@ int G_RadiusList ( vec3_t origin, float radius, gentity_t *ignore, qboolean take
|
|||
return(ent_count);
|
||||
}
|
||||
|
||||
int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radius, gentity_t *ignore, list_p ent_list) {
|
||||
int G_RadiusListOfTypes(list_p classnames, vec3_t origin, float radius, list_p ignore, list_p ent_list) {
|
||||
float dist;
|
||||
gentity_t *ent;
|
||||
gentity_t *t;
|
||||
int entityList[MAX_GENTITIES];
|
||||
int numListedEntities;
|
||||
vec3_t mins, maxs;
|
||||
vec3_t v;
|
||||
int i, e;
|
||||
qboolean valid = qfalse;
|
||||
list_iter_p iter;
|
||||
container_p c;
|
||||
qboolean n = qfalse;
|
||||
|
||||
if(ent_list == NULL) {
|
||||
ent_list = create_list();
|
||||
}
|
||||
|
||||
if(classnames == NULL || classnames->length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( radius < 1 )
|
||||
{
|
||||
radius = 1;
|
||||
|
@ -1114,14 +1122,39 @@ int G_RadiusListOfTypes(char *classname[], int count, vec3_t origin, float radiu
|
|||
{
|
||||
ent = &g_entities[entityList[e]];
|
||||
|
||||
if ((ent == ignore) || !(ent->inuse))
|
||||
if(!(ent->inuse)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for(i = 0; i < count; i++) {
|
||||
if(!strcmp(ent->classname, classname[i])) {
|
||||
if(ignore != NULL) {
|
||||
iter = list_iterator(ignore, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
t = c->data;
|
||||
|
||||
if(t == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ent == t) {
|
||||
n = qtrue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
}
|
||||
|
||||
if(n == qtrue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
iter = list_iterator(classnames, LIST_FRONT);
|
||||
for(c = list_next(iter); c != NULL; c = list_next(iter)) {
|
||||
if(!strcmp(ent->classname, (char*)c->data)) {
|
||||
valid = qtrue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
destroy_iterator(iter);
|
||||
|
||||
if(!valid) {
|
||||
continue;
|
||||
|
|
|
@ -120,11 +120,17 @@ static void WP_FireHyperspanner(gentity_t *ent, qboolean alt_fire) {
|
|||
float nearestd = 65000;
|
||||
vec3_t dVec, end;
|
||||
vec3_t mins = { -40, -40, 0 }, maxs = { 40, 40, 0 };
|
||||
char* classnames[] = { "func_breakable", "misc_model_breakable" };
|
||||
struct list classnames;
|
||||
|
||||
/* prepare lists */
|
||||
list_init(&classnames, free);
|
||||
list_init(&validEnts, free);
|
||||
list_append(&classnames, "func_breakable", LT_STRING, strlen("func_breakable")+1);
|
||||
list_append(&classnames, "misc_model_breakable", LT_STRING, strlen("misc_model_breakable")+1);
|
||||
|
||||
/* find all vlaid entities in range */
|
||||
memset(&validEnts, 0, sizeof(struct list));
|
||||
count = G_RadiusListOfTypes(classnames, 2, ent->r.currentOrigin, 512, NULL, &validEnts);
|
||||
count = G_RadiusListOfTypes(&classnames, ent->r.currentOrigin, 512, NULL, &validEnts);
|
||||
list_clear(&classnames);
|
||||
//G_Printf("Found %d possible candidates\n", count);
|
||||
if(count) {
|
||||
trace_t tr;
|
||||
|
|
|
@ -282,7 +282,6 @@ container_p list_poll(list_p list){
|
|||
|
||||
void list_remove(list_p list, char end) {
|
||||
container_p cont;
|
||||
void (*destructor)(void*) = list->destructor;
|
||||
|
||||
if(end == LIST_FRONT) {
|
||||
cont = list_poll(list);
|
||||
|
@ -294,7 +293,7 @@ void list_remove(list_p list, char end) {
|
|||
|
||||
if(cont != NULL) {
|
||||
if(cont->pointer == 0 && cont->data != NULL) {
|
||||
destructor(cont->data);
|
||||
list->destructor(cont->data);
|
||||
}
|
||||
|
||||
free(cont);
|
||||
|
@ -333,3 +332,8 @@ void destroy_iterator(list_iter_p iter) {
|
|||
free(iter);
|
||||
}
|
||||
|
||||
void list_init(struct list * l, void (*destructor)(void*)) {
|
||||
memset(l, 0, sizeof(struct list));
|
||||
l->destructor = destructor;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,9 @@ typedef struct list_iter * list_iter_p;
|
|||
|
||||
/**
|
||||
* Create a linked_list object. This pointer is created on the heap and must be
|
||||
* cleared with a call to destroy_list to avoid memory leaks
|
||||
* cleared with a call to destroy_list to avoid memory leaks.
|
||||
*
|
||||
* \return A new list allocated on the heap.
|
||||
*/
|
||||
list_p create_list(void);
|
||||
|
||||
|
@ -120,30 +122,45 @@ list_p create_list(void);
|
|||
* Create a list_iter object for the linked_list list. The flag init can be
|
||||
* either LIST_FRONT or LIST_BACK and indicates whether to start the iterator from the first
|
||||
* or last item in the list
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param init indicator where to start from
|
||||
* \return A new list iterator.
|
||||
*
|
||||
*/
|
||||
list_iter_p list_iterator(list_p list, char init);
|
||||
|
||||
/**
|
||||
* Add a pointer to an item with the given value and type to the list.
|
||||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if succesfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of the data
|
||||
* \param end indicator where to insert
|
||||
* \return Count of elements in the list
|
||||
*/
|
||||
int list_add_ptr(list_p list, void* data, dataType_t type, char end);
|
||||
|
||||
/**
|
||||
* Add a pointer to an item with the given calue, type, and size to the end of the list.
|
||||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if successfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of data
|
||||
* \return Count of elements in list
|
||||
*/
|
||||
int list_append_ptr(list_p list, void* data, dataType_t type);
|
||||
|
||||
/**
|
||||
* Add a pointer to an item with the given calue, type, and size to the front of the list.
|
||||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if successfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of data
|
||||
* \return Count of elements in list
|
||||
*/
|
||||
int list_prepend_ptr(list_p list, void* data, dataType_t type);
|
||||
|
||||
|
@ -152,6 +169,13 @@ int list_prepend_ptr(list_p list, void* data, dataType_t type);
|
|||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if succesfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of data
|
||||
* \param size size of data
|
||||
* \param end indicator where to add the data
|
||||
* \return Count of elements in the list
|
||||
*/
|
||||
int list_add(list_p list, void* data, dataType_t type, size_t size, char end);
|
||||
|
||||
|
@ -160,6 +184,12 @@ int list_add(list_p list, void* data, dataType_t type, size_t size, char end);
|
|||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if successfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of data
|
||||
* \param size size of data
|
||||
* \return Count of elements in the list
|
||||
*/
|
||||
int list_append(list_p list, void* data, dataType_t type, size_t size);
|
||||
|
||||
|
@ -168,26 +198,44 @@ int list_append(list_p list, void* data, dataType_t type, size_t size);
|
|||
* The data is copied by value, so the original pointer must be freed if it
|
||||
* was allocated on the heap.
|
||||
* Returns the length of the list if successfull else returns 0.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param data pointer to data
|
||||
* \param type type of data
|
||||
* \param size size of data
|
||||
* \return Count of elements in the list
|
||||
*/
|
||||
int list_prepend(list_p list, void* data, dataType_t type, size_t size);
|
||||
|
||||
/**
|
||||
* Gets the data stored in the first item of the list or NULL if the list is empty
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \return container for the first element of the list
|
||||
*/
|
||||
container_p list_first(list_p list);
|
||||
/**
|
||||
* Gets the data stored in the last item of the list or NULL if the list is empty
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \return container for the last element of the list
|
||||
*/
|
||||
container_p list_last(list_p list);
|
||||
|
||||
/**
|
||||
* Removes the last item in the list (LIFO order) and returns the data stored
|
||||
* there. The data returned must be freed later in order to remain memory safe.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \return container for the last element of the list
|
||||
*/
|
||||
container_p list_pop(list_p list);
|
||||
/**
|
||||
* Removes the first item in the list (FIFO order) and returns the data stored
|
||||
* there. The data return must be freed later in order to remain memory safe.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \return container for the first element of the list
|
||||
*/
|
||||
container_p list_poll(list_p list);
|
||||
/**
|
||||
|
@ -195,49 +243,85 @@ container_p list_poll(list_p list);
|
|||
* flag is LIST_FRONT, an item will be polled from the front of the list and its data
|
||||
* freed. If the end flag is set to LIST_BACK, an item will be popped off the end of
|
||||
* the list and the data freed.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
* \param end indicator where to remove
|
||||
*/
|
||||
void list_remove(list_p list, char end);
|
||||
|
||||
/**
|
||||
* Completely free the data associated with the list.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
*/
|
||||
void destroy_list(list_p list);
|
||||
|
||||
/**
|
||||
* Destroy a list iterator if allocated.
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
*/
|
||||
void destroy_iterator(list_iter_p iter);
|
||||
|
||||
/**
|
||||
* Return the data held by the current item pointed to by the iterator
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
* \return container for the current element
|
||||
*/
|
||||
container_p list_current(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Advances the iterator to the next item in the list and returns the data
|
||||
* stored there.
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
* \return container of the next element
|
||||
*/
|
||||
container_p list_next(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Advances the iterator to the previous item in the list and returns the data
|
||||
* stored there.
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
* \return container of the previous element
|
||||
*/
|
||||
container_p list_prev(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Advances the iterator to the next item in the list and returns the data
|
||||
* stored there. If the end of the list is reached it continues with the first
|
||||
* element of the list.
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
* \return container of the next element
|
||||
*/
|
||||
container_p list_cycl_next(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Advances the iterator to the previous item in the list and returns the data
|
||||
* stored there. If the start of the list is reached it continues with the last
|
||||
* element of the list.
|
||||
*
|
||||
* \param list pointer to a iterator
|
||||
* \return container of the previous element
|
||||
*/
|
||||
container_p list_cycl_prev(list_iter_p list);
|
||||
|
||||
/**
|
||||
* Remove all elements.
|
||||
*
|
||||
* \param list pointer to a list
|
||||
*/
|
||||
void list_clear(list_p list);
|
||||
|
||||
/**
|
||||
* Initialize list. For use on lists that are NOT allocated on the heap.
|
||||
*
|
||||
* \param l a list
|
||||
* \param destructor pointer to destructor function
|
||||
*/
|
||||
void list_init(struct list * l, void (*destructor)(void*));
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue