Files
ReSkate/Engine/Game/Multiplayer/session_physics.h
T
AyeZeeBB 3fddd1433a Trainer: quiet by default, host's setup for guests; drop the out-of-view cut
Follow-ups to the trainer (PR 37), and one multiplayer change.

Off until asked for (Extension/Trainer)
- The jump read-out and the LB+RB controller shortcuts start off. Jumps
  are logged only while the read-out or telemetry recording is on, and
  trick launches only when the trainer scaled them. A saved trainer.json
  keeps what the player chose.

Memory search on demand (trainer.cpp, trainer_classes.cpp)
- The search for the game's tuning classes reads all writable memory.
  It ran for every player after a level loaded, and up to seven times
  when it found nothing. It now runs only when a class value or the flip
  speed is not the game's own (the player's, or a host's they skate
  with) or the EVERYTHING list is open, and at most three times a level.
- For those players it runs again on each level, which brings fresh
  copies; a search from an earlier level used to count as done.

Guests under enforced physics
- A guest is locked by the session's enforce setting, from the moment
  of joining (Engine/Game/Multiplayer/session_physics.h), not by whether
  the enforcement status text was set yet.
- A guest's class values no longer come back after a map change.

The host's whole setup reaches its guests (protocol 39)
- Only Gameplay/SkatePhysicsTuning travelled, so a host could push,
  sprint or jump further than the guests it held to the game's own.
- New packet physics_extras (30): the host's class values, trick
  multipliers and auto push (trainer_session.h), sent when they change
  and to players who join later, taken from the host only. A dedicated
  server's are the game's own and it ignores the packet.
- Under enforcement a guest's own trick multipliers stand down for the
  host's, whatever the boosts switch says. With enforcement off nothing
  changes.
- A guest refuses bytes that are not an encoding, holds values to the
  trainer's own ranges, and leaves out class values written for another
  game build's table.
- protocol_version 38 -> 39: released versions disconnect from a peer
  that sends a packet they cannot decode.

Out-of-view players are posed every frame again (Session/session.cpp)
- Players outside the camera's view and past 8 m were sampled at 20 Hz
  (b763631). The game's replays record each skater as it stood every
  frame and their camera looks anywhere, so those players moved at
  20 Hz in replays. Removed; the distance rule (20 Hz past 200 m, 10 Hz
  past 350 m) stays. This gives back the client-tick time it saved on
  busy servers.
2026-10-04 14:19:30 -05:00

72 lines
3.2 KiB
C++

#pragma once
// What a session does to the local player's physics, between the session (which knows the
// host and its rules) and the code that changes physics (the trainer). The tuning asset itself
// goes through Extension/Skater/physics_tuning.h; this is the rest.
#include <algorithm>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <span>
#include <vector>
namespace dingosdk {
// Physics a player changes outside Gameplay/SkatePhysicsTuning: the trainer's tuning-class
// values and trick multipliers (Extension/Trainer/trainer_session.h reads and writes the
// bytes; they are opaque here and on the wire). Empty: everything the game's own.
inline constexpr std::size_t max_physics_extras = 4096;
namespace session_physics_detail {
inline std::atomic<bool> enforced{};
struct Box {
std::mutex mutex;
std::vector<std::uint8_t> bytes;
std::uint64_t revision = 1; // moves whenever `bytes` does; nobody's `seen` starts at it
};
inline Box &local_box() { static Box value; return value; }
inline Box &host_box() { static Box value; return value; }
inline void put(Box &box, std::span<const std::uint8_t> bytes) {
std::lock_guard lock(box.mutex);
if (std::ranges::equal(box.bytes, bytes)) return;
box.bytes.assign(bytes.begin(), bytes.end());
++box.revision;
}
inline bool take(Box &box, std::uint64_t &seen, std::vector<std::uint8_t> &bytes) {
std::lock_guard lock(box.mutex);
if (seen == box.revision) return false;
seen = box.revision;
bytes = box.bytes;
return true;
}
} // namespace session_physics_detail
// The local player is a guest of a session whose host (or dedicated server) sets everyone's
// physics (the roster's enforce_tuning): their own physics edits stand down, and what the host
// shares is theirs. False outside a session and for a host. Set by the session every tick.
inline bool session_tuning_enforced() noexcept {
return session_physics_detail::enforced.load(std::memory_order_acquire);
}
inline void set_session_tuning_enforced(bool enforced) noexcept {
session_physics_detail::enforced.store(enforced, std::memory_order_release);
}
// The local player's own extras, published by whoever edits them; a host's session sends them
// to its guests. The readers copy `bytes` out only when they are not the ones `seen` names
// (start `seen` at 0), and say whether they did.
inline void set_local_physics_extras(std::span<const std::uint8_t> bytes) {
session_physics_detail::put(session_physics_detail::local_box(), bytes);
}
inline bool local_physics_extras(std::uint64_t &seen, std::vector<std::uint8_t> &bytes) {
return session_physics_detail::take(session_physics_detail::local_box(), seen, bytes);
}
// A guest's host's extras, set by the session: empty until the host sends some, and always for
// a dedicated server, whose physics are the game's own. Only meaningful while
// session_tuning_enforced().
inline void set_host_physics_extras(std::span<const std::uint8_t> bytes) {
session_physics_detail::put(session_physics_detail::host_box(), bytes);
}
inline bool host_physics_extras(std::uint64_t &seen, std::vector<std::uint8_t> &bytes) {
return session_physics_detail::take(session_physics_detail::host_box(), seen, bytes);
}
} // namespace dingosdk