mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-10 18:12:40 +00:00
Added update rates for objects based on distance
This commit is contained in:
parent
3d055255bc
commit
de9eab364f
1 changed files with 14 additions and 4 deletions
|
|
@ -30,6 +30,7 @@ void network_send_object(struct SyncObject* so) {
|
||||||
packet_write(&p, &o->oMoveAngleYaw, 4);
|
packet_write(&p, &o->oMoveAngleYaw, 4);
|
||||||
|
|
||||||
if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { so->syncDeactive++; }
|
if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { so->syncDeactive++; }
|
||||||
|
so->ticksSinceUpdate = 0;
|
||||||
network_send(&p);
|
network_send(&p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,14 +84,23 @@ void forget_sync_object(struct SyncObject* so) {
|
||||||
|
|
||||||
void network_update_objects(void) {
|
void network_update_objects(void) {
|
||||||
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
|
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
|
||||||
if (syncObjects[i].o == NULL) { continue; }
|
struct SyncObject* so = &syncObjects[i];
|
||||||
|
if (so->o == NULL) { continue; }
|
||||||
|
|
||||||
if (syncObjects[i].o->oSyncID != i || syncObjects[i].syncDeactive > 10) {
|
// check for stale sync object
|
||||||
forget_sync_object(&syncObjects[i]);
|
if (so->o->oSyncID != i || so->syncDeactive > 10) {
|
||||||
|
forget_sync_object(so);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
so->ticksSinceUpdate++;
|
||||||
|
|
||||||
if (!should_own_object(&syncObjects[i])) { continue; }
|
// check if we should be the one syncing this object
|
||||||
|
if (!should_own_object(so)) { continue; }
|
||||||
|
|
||||||
|
// check update rate
|
||||||
|
int updateRate = player_distance(&gMarioStates[0], so->o) / 50;
|
||||||
|
if (gMarioStates[0].heldObj == so->o) { updateRate = 0; }
|
||||||
|
if (so->ticksSinceUpdate < updateRate) { continue; }
|
||||||
|
|
||||||
network_send_object(&syncObjects[i]);
|
network_send_object(&syncObjects[i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue