/* * @brief Resets entity flags and other state which should only last one frame. */ static void Sv_ResetEntities(void) { uint32_t i; if (sv.state != SV_ACTIVE_GAME) return; for (i = 0; i < svs.game->num_edicts; i++) { g_edict_t *edict = EDICT_FOR_NUM(i); // events only last for a single message edict->s.event = 0; } }
/* * @brief Reloads svs.clients, svs.client_entities, the game programs, etc. Because * we must allocate clients and edicts based on sizes the game module requests, * we refresh the game module */ static void Sv_InitClients(void) { int32_t i; if (!svs.initialized || Cvar_PendingLatched()) { Sv_ShutdownGame(); Sv_ShutdownClients(); Sv_UpdateLatchedVars(); // initialize the clients array svs.clients = Z_TagMalloc(sizeof(sv_client_t) * sv_max_clients->integer, Z_TAG_SERVER); // and the entity states array svs.num_entity_states = sv_max_clients->integer * UPDATE_BACKUP * MAX_PACKET_ENTITIES; svs.entity_states = Z_TagMalloc(sizeof(entity_state_t) * svs.num_entity_states, Z_TAG_SERVER); svs.frame_rate = sv_hz->integer; svs.spawn_count = Random(); Sv_InitGame(); } else { svs.spawn_count++; } // align the game entities with the server's clients for (i = 0; i < sv_max_clients->integer; i++) { g_edict_t *edict = EDICT_FOR_NUM(i + 1); edict->s.number = i + 1; // assign their edict svs.clients[i].edict = edict; // reset state of spawned clients back to connected if (svs.clients[i].state > SV_CLIENT_CONNECTED) svs.clients[i].state = SV_CLIENT_CONNECTED; // invalidate last frame to force a baseline svs.clients[i].last_frame = -1; svs.clients[i].last_message = svs.real_time; } }
/* * @brief Entity baselines are used to compress the update messages * to the clients -- only the fields that differ from the * baseline will be transmitted */ static void Sv_CreateBaseline(void) { g_edict_t *ent; uint32_t i; for (i = 1; i < svs.game->num_edicts; i++) { ent = EDICT_FOR_NUM(i); if (!ent->in_use) continue; if (!ent->s.model1 && !ent->s.sound && !ent->s.effects) continue; ent->s.number = i; // take current state as baseline VectorCopy(ent->s.origin, ent->s.old_origin); sv.baselines[i] = ent->s; } }