Skip to content

Commit

Permalink
tick should be u64
Browse files Browse the repository at this point in the history
because why not, it's not duplicated a lot tbh
  • Loading branch information
Uriopass committed Dec 8, 2023
1 parent ab399df commit c794e7a
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion engine_demo/src/terrain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::DemoElement;
use engine::terrain::TerrainRender as EngineTerrainRender;
use engine::{Context, FrameContext};
use geom::{vec2, Camera, InfiniteFrustrum, LinearColor};
use geom::{vec2, Camera, InfiniteFrustrum};

const CSIZE: usize = 256;
const CRESO: usize = 32;
Expand Down
4 changes: 2 additions & 2 deletions networking/src/catchup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CatchUp {

pub fn add_merged_inputs(&mut self, frame: Frame, inp: MergedInputs) {
for v in self.frame_history.values_mut() {
if frame.0 != v.from.0 + 1 + v.inputs.len() as u32 {
if frame.0 != v.from.0 + 1 + v.inputs.len() as u64 {
log::error!("wrong input for catch up !!!")
}
v.inputs.push(inp.clone())
Expand Down Expand Up @@ -65,7 +65,7 @@ impl CatchUp {
let inputs = Vec::from(&state.inputs[state.sent..]);
state.sent += inputs.len();

c.ack = state.from + Frame(state.sent as u32);
c.ack = state.from + Frame(state.sent as u64);

if diff <= 30 {
log::info!("{}: sending final catch up", c.name);
Expand Down
6 changes: 3 additions & 3 deletions networking/src/client/client_playout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ impl ClientPlayoutBuffer {
if frame <= self.consumed_frame {
return InsertResult::Ok; // already consumed, safely ignore
}
if frame.0 > self.consumed_frame.0 + self.future.len() {
if frame.0 > self.consumed_frame.0 + self.future.len() as u64 {
return InsertResult::TooFarAhead;
}
*self.future.get_mut(frame) = Some(input);
InsertResult::Ok
}

pub fn advance(&self) -> u32 {
pub fn advance(&self) -> u64 {
let mut advance = 0;
while self
.future
.get(Frame(self.consumed_frame.0 + 1 + advance))
.is_some()
&& advance < self.future.len()
&& advance < self.future.len() as u64
{
advance += 1;
}
Expand Down
6 changes: 3 additions & 3 deletions networking/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct Client<WORLD: DeserializeOwned, INPUT: Serialize + DeserializeOwned +
state: ClientState<WORLD, INPUT>,

pub step: Timestep,
lag_compensate: u32,
lag_compensate: u64,

_phantom: PhantomSendSync<(INPUT, WORLD)>,
}
Expand All @@ -78,7 +78,7 @@ pub struct ConnectConf {
pub name: String,
pub addr: IpAddr,
pub port: Option<u16>,
pub frame_buffer_advance: u32,
pub frame_buffer_advance: u64,
pub version: String,
}

Expand Down Expand Up @@ -323,7 +323,7 @@ impl<W: DeserializeOwned, I: Serialize + DeserializeOwned + Default> Client<W, I
{
assert_eq!(
final_consumed_frame,
Frame(consumed_frame.0 + final_inputs.len() as u32)
Frame(consumed_frame.0 + final_inputs.len() as u64)
);
self.state = ClientState::Playing {
id,
Expand Down
2 changes: 1 addition & 1 deletion networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) const DEFAULT_PORT: u16 = 23019;

#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Hash, Debug, Serialize, Deserialize)]
#[repr(transparent)]
pub struct Frame(pub u32);
pub struct Frame(pub u64);

#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Hash, Serialize, Deserialize)]
#[repr(transparent)]
Expand Down
4 changes: 2 additions & 2 deletions networking/src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl<T: Default> Ring<T> {
&mut self.ring[f.0 as usize % self.ring.len()]
}

pub fn len(&self) -> u32 {
self.ring.len() as u32
pub fn len(&self) -> usize {
self.ring.len()
}

#[allow(dead_code)]
Expand Down
6 changes: 3 additions & 3 deletions networking/src/server/server_playout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ServerPlayoutBuffer {
}

pub fn insert_input(&mut self, auth: AuthentID, frame: Frame, input: PlayerInput) {
if frame.0 + self.past.len() <= self.consumed_frame.0 {
if frame.0 + self.past.len() as u64 <= self.consumed_frame.0 {
log::info!("input was far too late");
return;
}
Expand All @@ -48,9 +48,9 @@ impl ServerPlayoutBuffer {
}
}

pub fn lag(&self, f: Frame) -> Option<u32> {
pub fn lag(&self, f: Frame) -> Option<u64> {
let lag = self.consumed_frame.0 - f.0;
if lag < self.past.len() - 1 {
if lag < self.past.len() as u64 - 1 {
Some(lag)
} else {
None
Expand Down
6 changes: 3 additions & 3 deletions simulation/src/economy/ecostats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::BTreeMap;
pub const HISTORY_SIZE: usize = 128;
/// Tick to wait before the new bin
/// Which can be recovred from FREQ * HISTORY_SIZZ / TICK_RATE
pub const LEVEL_FREQS: [u32; 4] = [250, 1500, 15000, 75000];
pub const LEVEL_FREQS: [u64; 4] = [250, 1500, 15000, 75000];
pub const LEVEL_NAMES: [&str; 4] = ["10m", "1h", "10h", "50h"];

/// One history of one item at one frequency level
Expand Down Expand Up @@ -86,7 +86,7 @@ impl ItemHistories {
}
}

pub fn advance(&mut self, tick: u32) {
pub fn advance(&mut self, tick: u64) {
for (c_i, (c, freq)) in self.cursors.iter_mut().zip(&LEVEL_FREQS).enumerate() {
if tick % *freq == 0 {
*c = (*c + 1) % HISTORY_SIZE;
Expand All @@ -108,7 +108,7 @@ impl EcoStats {
}
}

pub fn advance(&mut self, tick: u32, trades: &[Trade]) {
pub fn advance(&mut self, tick: u64, trades: &[Trade]) {
self.exports.advance(tick);
self.imports.advance(tick);
self.internal_trade.advance(tick);
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Simulation {
t.elapsed()
}

pub fn get_tick(&self) -> u32 {
pub fn get_tick(&self) -> u64 {
self.resources.read::<Tick>().0
}

Expand Down
4 changes: 2 additions & 2 deletions simulation/src/utils/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub const SECONDS_PER_REALTIME_SECOND: u32 = 15;
pub const SECONDS_PER_HOUR: i32 = 3600;
pub const HOURS_PER_DAY: i32 = 24;
pub const SECONDS_PER_DAY: i32 = SECONDS_PER_HOUR * HOURS_PER_DAY;
pub const TICKS_PER_SECOND: u32 = 50;
pub const TICKS_PER_SECOND: u64 = 50;

/// The amount of time the game was updated
/// Used as a resource
#[derive(Debug, Default, PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
pub struct Tick(pub u32);
pub struct Tick(pub u64);

/// An in-game instant used to measure time differences
#[derive(Inspect, PartialEq, PartialOrd, Debug, Copy, Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit c794e7a

Please sign in to comment.