Remote

Struct Remote 

Source
pub struct Remote<T: Model> { /* private fields */ }

Implementations§

Source§

impl<T: Model> Remote<T>

Source

pub fn update(&self) -> Vec<T::Event>

Examples found in repository?
examples/multiplayer.rs (line 105)
104    fn update(&mut self, delta_time: f64) {
105        self.model.update();
106        self.traffic_watcher.update(&self.model.traffic());
107        let delta_time = delta_time as f32;
108
109        self.current_time += delta_time;
110
111        const SPEED: f32 = 10.0;
112        if self.geng.window().is_key_pressed(geng::Key::ArrowLeft)
113            || self.geng.window().is_key_pressed(geng::Key::A)
114        {
115            self.player.position.x -= SPEED * delta_time;
116        }
117        if self.geng.window().is_key_pressed(geng::Key::ArrowRight)
118            || self.geng.window().is_key_pressed(geng::Key::D)
119        {
120            self.player.position.x += SPEED * delta_time;
121        }
122        if self.geng.window().is_key_pressed(geng::Key::ArrowUp)
123            || self.geng.window().is_key_pressed(geng::Key::W)
124        {
125            self.player.position.y += SPEED * delta_time;
126        }
127        if self.geng.window().is_key_pressed(geng::Key::ArrowDown)
128            || self.geng.window().is_key_pressed(geng::Key::S)
129        {
130            self.player.position.y -= SPEED * delta_time;
131        }
132
133        self.next_update -= delta_time;
134        if self.next_update < 0.0 {
135            while self.next_update < 0.0 {
136                self.next_update += 1.0 / <Model as simple_net::Model>::TICKS_PER_SECOND;
137            }
138            self.model
139                .send(Message::UpdatePosition(self.player.position));
140        }
141    }
Source

pub fn get(&self) -> Ref<'_, T>

Examples found in repository?
examples/multiplayer.rs (line 90)
89    fn new(geng: &Geng, player_id: PlayerId, model: simple_net::Remote<Model>) -> Self {
90        let current_time = model.get().current_time;
91        let player = model.get().players.get(&player_id).unwrap().clone();
92        Self {
93            geng: geng.clone(),
94            traffic_watcher: geng::net::TrafficWatcher::new(),
95            next_update: 0.0,
96            model,
97            player,
98            current_time,
99        }
100    }
101}
102
103impl geng::State for Game {
104    fn update(&mut self, delta_time: f64) {
105        self.model.update();
106        self.traffic_watcher.update(&self.model.traffic());
107        let delta_time = delta_time as f32;
108
109        self.current_time += delta_time;
110
111        const SPEED: f32 = 10.0;
112        if self.geng.window().is_key_pressed(geng::Key::ArrowLeft)
113            || self.geng.window().is_key_pressed(geng::Key::A)
114        {
115            self.player.position.x -= SPEED * delta_time;
116        }
117        if self.geng.window().is_key_pressed(geng::Key::ArrowRight)
118            || self.geng.window().is_key_pressed(geng::Key::D)
119        {
120            self.player.position.x += SPEED * delta_time;
121        }
122        if self.geng.window().is_key_pressed(geng::Key::ArrowUp)
123            || self.geng.window().is_key_pressed(geng::Key::W)
124        {
125            self.player.position.y += SPEED * delta_time;
126        }
127        if self.geng.window().is_key_pressed(geng::Key::ArrowDown)
128            || self.geng.window().is_key_pressed(geng::Key::S)
129        {
130            self.player.position.y -= SPEED * delta_time;
131        }
132
133        self.next_update -= delta_time;
134        if self.next_update < 0.0 {
135            while self.next_update < 0.0 {
136                self.next_update += 1.0 / <Model as simple_net::Model>::TICKS_PER_SECOND;
137            }
138            self.model
139                .send(Message::UpdatePosition(self.player.position));
140        }
141    }
142    fn draw(&mut self, framebuffer: &mut ugli::Framebuffer) {
143        ugli::clear(framebuffer, Some(Rgba::BLACK), None, None);
144        let camera = geng::Camera2d {
145            center: vec2(0.0, 0.0),
146            rotation: Angle::ZERO,
147            fov: 100.0,
148        };
149        let model = self.model.get();
150        for player in &model.players {
151            self.geng
152                .draw2d()
153                .circle(framebuffer, &camera, player.position, 1.0, Rgba::GRAY);
154        }
155        self.geng
156            .draw2d()
157            .circle(framebuffer, &camera, self.player.position, 1.0, Rgba::WHITE);
158        self.geng.default_font().draw(
159            framebuffer,
160            &geng::PixelPerfectCamera,
161            &format!("Server time: {:.1}", model.current_time),
162            vec2::splat(TextAlign::LEFT),
163            mat3::translate(vec2(0.0, 0.0)) * mat3::scale_uniform(32.0),
164            Rgba::WHITE,
165        );
166        self.geng.default_font().draw(
167            framebuffer,
168            &geng::PixelPerfectCamera,
169            &format!("Client time: {:.1}", self.current_time),
170            vec2::splat(TextAlign::LEFT),
171            mat3::translate(vec2(0.0, 32.0)) * mat3::scale_uniform(32.0),
172            Rgba::WHITE,
173        );
174        self.geng.default_font().draw(
175            framebuffer,
176            &geng::PixelPerfectCamera,
177            &format!("traffic: {}", self.traffic_watcher),
178            vec2::splat(TextAlign::LEFT),
179            mat3::translate(vec2(0.0, 32.0 * 2.0)) * mat3::scale_uniform(32.0),
180            Rgba::WHITE,
181        );
182    }
Source

pub fn send(&self, message: T::Message)

Examples found in repository?
examples/multiplayer.rs (line 139)
104    fn update(&mut self, delta_time: f64) {
105        self.model.update();
106        self.traffic_watcher.update(&self.model.traffic());
107        let delta_time = delta_time as f32;
108
109        self.current_time += delta_time;
110
111        const SPEED: f32 = 10.0;
112        if self.geng.window().is_key_pressed(geng::Key::ArrowLeft)
113            || self.geng.window().is_key_pressed(geng::Key::A)
114        {
115            self.player.position.x -= SPEED * delta_time;
116        }
117        if self.geng.window().is_key_pressed(geng::Key::ArrowRight)
118            || self.geng.window().is_key_pressed(geng::Key::D)
119        {
120            self.player.position.x += SPEED * delta_time;
121        }
122        if self.geng.window().is_key_pressed(geng::Key::ArrowUp)
123            || self.geng.window().is_key_pressed(geng::Key::W)
124        {
125            self.player.position.y += SPEED * delta_time;
126        }
127        if self.geng.window().is_key_pressed(geng::Key::ArrowDown)
128            || self.geng.window().is_key_pressed(geng::Key::S)
129        {
130            self.player.position.y -= SPEED * delta_time;
131        }
132
133        self.next_update -= delta_time;
134        if self.next_update < 0.0 {
135            while self.next_update < 0.0 {
136                self.next_update += 1.0 / <Model as simple_net::Model>::TICKS_PER_SECOND;
137            }
138            self.model
139                .send(Message::UpdatePosition(self.player.position));
140        }
141    }
Source

pub fn traffic(&self) -> Traffic

Examples found in repository?
examples/multiplayer.rs (line 106)
104    fn update(&mut self, delta_time: f64) {
105        self.model.update();
106        self.traffic_watcher.update(&self.model.traffic());
107        let delta_time = delta_time as f32;
108
109        self.current_time += delta_time;
110
111        const SPEED: f32 = 10.0;
112        if self.geng.window().is_key_pressed(geng::Key::ArrowLeft)
113            || self.geng.window().is_key_pressed(geng::Key::A)
114        {
115            self.player.position.x -= SPEED * delta_time;
116        }
117        if self.geng.window().is_key_pressed(geng::Key::ArrowRight)
118            || self.geng.window().is_key_pressed(geng::Key::D)
119        {
120            self.player.position.x += SPEED * delta_time;
121        }
122        if self.geng.window().is_key_pressed(geng::Key::ArrowUp)
123            || self.geng.window().is_key_pressed(geng::Key::W)
124        {
125            self.player.position.y += SPEED * delta_time;
126        }
127        if self.geng.window().is_key_pressed(geng::Key::ArrowDown)
128            || self.geng.window().is_key_pressed(geng::Key::S)
129        {
130            self.player.position.y -= SPEED * delta_time;
131        }
132
133        self.next_update -= delta_time;
134        if self.next_update < 0.0 {
135            while self.next_update < 0.0 {
136                self.next_update += 1.0 / <Model as simple_net::Model>::TICKS_PER_SECOND;
137            }
138            self.model
139                .send(Message::UpdatePosition(self.player.position));
140        }
141    }

Auto Trait Implementations§

§

impl<T> !Freeze for Remote<T>

§

impl<T> !RefUnwindSafe for Remote<T>

§

impl<T> Send for Remote<T>

§

impl<T> !Sync for Remote<T>

§

impl<T> Unpin for Remote<T>

§

impl<T> !UnwindSafe for Remote<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,