44 for (
int it = 0; it < max; it++) {
53 memset(ulist->
list[it].
name, 0, 1024);
73 if (nb_rec_pos < 1)
return FALSE;
75 if (only_last_pos < 0 || only_last_pos > 1)
return FALSE;
78 if (id < 0 || id >= ulist->
max) {
94 n_log(
LOG_ERR,
"could not resize to only_last_pos VECTOR3D");
100 n_log(
LOG_ERR,
"could not resize to %d VECTOR3D", nb_rec_pos);
125 }
while (it < ulist->max && ulist->
list[it].
state != 0);
126 if (it < ulist->max) {
149 if (
id >= ulist->
max) {
165 memset(ulist->
list[
id].
position, 0, 3 *
sizeof(
double));
167 memset(ulist->
list[
id].
name, 0, 1024);
178 if (it < 0) ulist->
highter = -1;
199 for (
int it = 0; it <= ulist->
highter; it++) {
208 for (
int it = 0; it <= ulist->
highter; it++) {
269 for (
int it = 0; it < (*ulist)->max; it++) {
270 Free((*ulist)->list[it].last_positions);
273 Free((*ulist)->list);
274 unlock((*ulist)->user_rwbolt);
276 pthread_rwlock_destroy(&(*ulist)->user_rwbolt);
297 if (id <= ulist->highter) {
317 if (id <= ulist->highter) {
339 for (
int id = 0;
id <= ulist->
highter;
id++) {
NETWORK * netw
Network for server mode, accepting incomming.
#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, safe for node removal during iteration.
int list_destroy(LIST **list)
Empty and Free a list container.
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
#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 for each user of the list
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 network 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.