25 for (
int it = 0; it < max; it++) {
34 memset(ulist->
list[it].
name, 0, 1024);
54 __n_assert(only_last_pos < 0 || only_last_pos > 1,
return FALSE);
66 n_log(
LOG_ERR,
"could not resize to only_last_pos VECTOR3D");
71 n_log(
LOG_ERR,
"could not resize to %d VECTOR3D", nb_rec_pos);
95 }
while (it < ulist->max && ulist->
list[it].
state != 0);
96 if (it < ulist->max) {
119 if (
id > ulist->
max) {
136 memset(ulist->
list[
id].
position, 0, 3 *
sizeof(
double));
138 memset(ulist->
list[
id].
name, 0, 1024);
169 for (
int it = 0; it <= ulist->
highter; it++) {
178 for (
int it = 0; it <= ulist->
highter; it++) {
239 for (
int it = 0; it < (*ulist)->max; it++) {
240 Free((*ulist)->list[it].last_positions);
243 Free((*ulist)->list);
244 unlock((*ulist)->user_rwbolt);
246 pthread_rwlock_destroy(&(*ulist)->user_rwbolt);
267 if (id <= ulist->highter) {
287 if (id <= ulist->highter) {
309 for (
int id = 0;
id <= ulist->
highter;
id++) {
#define init_lock(__rwlock_mutex)
Macro for initializing a rwlock.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define unlock(__rwlock_mutex)
Macro for releasing read/write lock a rwlock mutex.
#define write_lock(__rwlock_mutex)
Macro for acquiring a write lock on a rwlock mutex.
#define Realloc(__ptr, __struct, __size)
Realloc Handler to get errors.
#define Free(__ptr)
Free Handler to get errors.
#define read_lock(__rwlock_mutex)
Macro for acquiring a read lock on a rwlock mutex.
int list_empty(LIST *list)
Empty a LIST list of pointers.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
int list_destroy(LIST **list)
Empty and Free a list container.
#define MAX_LIST_ITEMS
flag to pass to new_generic_list for the maximum possible number of item in a list
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
A box including a string and his lenght.
char name[1024]
User Name.
VECTOR3D * last_positions
Last nb_rec_pos position messages, for a better dead reckoning / lag simulation.
int only_last_pos
1 => keep only_last_position in waitlist , 0 => send all the positions, default: 1
int max
Maximum of user inside the list.
LIST * netw_waitlist
N_STR *messages waiting to be sent.
pthread_rwlock_t user_rwbolt
Mutex for thread safe user management.
int state
State of the current user.
VECTOR3D position
actual position
NETWORK * netw
Associated NETWORK.
int highter
Position of the highter user inside the list.
int id
Unique world ident.
int nb_rec_pos
Number of saved positions , default: 10.
N_USER * list
Pointer to the allocated list of user.
int userlist_del_user(N_USERLIST *ulist, int id)
delete an user from the list
int userlist_add_msg_to(N_USERLIST *ulist, N_STR *msg, int id)
add a N_STR *message to user list (USERLIST_ONE)
int userlist_add_msg_to_ex(N_USERLIST *ulist, N_STR *msg, int mode, int id)
add a N_STR *message to user list
#define USERLIST_ONE
flag to target one user in the list
int userlist_user_send_waiting_msgs(N_USERLIST *ulist, int id)
send all waiting messages in user 'id' waiting list
#define USERLIST_ALL_EXCEPT
flag to target all users in the list except one
N_USERLIST * userlist_new(int max)
create a new N_USERLIST user list with 'max' users
#define USERLIST_ALL
flag to target all users in the list
int userlist_add_msg_to_all(N_USERLIST *ulist, N_STR *msg)
add a N_STR *message to user list (USERLIST_ALL)
int userlist_send_waiting_msgs(N_USERLIST *ulist)
send all waiting messages ofr each user of the lsit
int userlist_set_position_behavior(N_USERLIST *ulist, int id, int nb_rec_pos, int only_last_pos)
set the position parameters for trajectory processing for user 'id'
int userlist_add_user(N_USERLIST *ulist, NETWORK *netw)
add an user to the list
int userlist_add_msg_to_all_except(N_USERLIST *ulist, N_STR *msg, int id)
add a N_STR *message to user list except user 'id' (USERLIST_ALL_EXCEPT)
int userlist_destroy(N_USERLIST **ulist)
destroy and free a N_USERLIST *userlist
int userlist_user_add_waiting_msg(N_USERLIST *ulist, int id, N_STR *netmsg)
add a newtork message to specified user 'id'
int netw_add_msg(NETWORK *netw, N_STR *msg)
Add a message to send in aimed NETWORK.
double VECTOR3D[3]
struct of a point
USERS handling for tiny game apps.