mirror of
https://github.com/UberGames/rpgxEF.git
synced 2024-11-10 07:11:34 +00:00
Added addtional functions ...
- added list_append - added list_prepend
This commit is contained in:
parent
afe3614b2a
commit
b58d94864d
4 changed files with 41 additions and 6 deletions
|
@ -7463,7 +7463,7 @@ void addShaderToList(list_p list, char *shader) {
|
|||
}
|
||||
}
|
||||
|
||||
list_add(list, s, LT_DATA, sizeof(rShader_s));
|
||||
list_append(list, s, LT_DATA, sizeof(rShader_s));
|
||||
}
|
||||
|
||||
extern target_alert_Shaders_s alertShaders;
|
||||
|
|
|
@ -968,7 +968,7 @@ static void G_LoadTimedMessages(void) {
|
|||
}
|
||||
|
||||
msg->message = strdup(token);
|
||||
list_add(level.timedMessages, msg, LT_DATA, sizeof(timedMessage_s));
|
||||
list_append(level.timedMessages, msg, LT_DATA, sizeof(timedMessage_s));
|
||||
} else {
|
||||
if(token[0] == '}') {
|
||||
break;
|
||||
|
|
|
@ -58,13 +58,14 @@ list_iter_p list_iterator(list_p list, char init) {
|
|||
return iter;
|
||||
}
|
||||
|
||||
int list_add(list_p list, void* data, dataType_t type, int size) {
|
||||
int list_add(list_p list, void* data, dataType_t type, size_t size, char end) {
|
||||
lnode_p node = (lnode_p)malloc(sizeof(struct linked_node));
|
||||
|
||||
node->cont = (container_p)(sizeof(container));
|
||||
if(node->cont == NULL) {
|
||||
return 0;
|
||||
}
|
||||
node->cont->type = type;
|
||||
|
||||
node->cont->data = malloc(size);
|
||||
if(node->cont->data == NULL) {
|
||||
|
@ -77,7 +78,17 @@ int list_add(list_p list, void* data, dataType_t type, int size) {
|
|||
node->next = NULL;
|
||||
list->first = node;
|
||||
list->last = node;
|
||||
} else {
|
||||
} else if(end == LIST_BACK) {
|
||||
list->last->next = node;
|
||||
node->prev = list->last;
|
||||
node->next = NULL;
|
||||
list->last = node;
|
||||
} else if(end == LIST_FRONT) {
|
||||
list->first->prev = node;
|
||||
node->next = list->first;
|
||||
node->prev = NULL;
|
||||
list->first = node;
|
||||
} else { // assume back
|
||||
list->last->next = node;
|
||||
node->prev = list->last;
|
||||
node->next = NULL;
|
||||
|
@ -88,6 +99,14 @@ int list_add(list_p list, void* data, dataType_t type, int size) {
|
|||
return list->length;
|
||||
}
|
||||
|
||||
int list_append(list_p list, void* data, dataType_t type, size_t size) {
|
||||
return list_add(list, data, type, size, LIST_BACK);
|
||||
}
|
||||
|
||||
int list_prepend(list_p list, void* data, dataType_t type, size_t size) {
|
||||
return list_add(list, data, type, size, LIST_FRONT);
|
||||
}
|
||||
|
||||
container_p list_current(list_iter_p iter){
|
||||
if(iter->started && iter->current != NULL) {
|
||||
return iter->current->cont;
|
||||
|
|
|
@ -93,12 +93,28 @@ list_p create_list(void);
|
|||
list_iter_p list_iterator(list_p list, char init);
|
||||
|
||||
/**
|
||||
* Add an item with the given value, type, and size to the back of the list.
|
||||
* Add an item with the given value, type, and size 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 succesfull else returns 0.
|
||||
*/
|
||||
int list_add(list_p list, void* data, dataType_t type, int size);
|
||||
int list_add(list_p list, void* data, dataType_t type, size_t size, char end);
|
||||
|
||||
/**
|
||||
* Add 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.
|
||||
*/
|
||||
int list_append(list_p list, void* data, dataType_t type, size_t size);
|
||||
|
||||
/**
|
||||
* Add 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.
|
||||
*/
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue