Compare commits
3 commits
cfa763ffc4
...
293ccf9370
Author | SHA1 | Date | |
---|---|---|---|
293ccf9370 | |||
cb64878186 | |||
3c0590b273 |
7 changed files with 14 additions and 13 deletions
|
@ -4,25 +4,25 @@ use bevy::prelude::*;
|
||||||
use super::state::AppState;
|
use super::state::AppState;
|
||||||
|
|
||||||
/// Basic implementation of a physics object
|
/// Basic implementation of a physics object
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Debug, Default)]
|
||||||
#[require(Collider, Mesh2d, MeshMaterial2d<ColorMaterial>, Restitution = Restitution::new(1.0), RigidBody, TransformInterpolation, Transform, StateScoped<AppState> = StateScoped(AppState::InGame))]
|
#[require(Collider, Mesh2d, MeshMaterial2d<ColorMaterial>, Restitution = Restitution::new(1.0), RigidBody, TransformInterpolation, Transform, StateScoped<AppState> = StateScoped(AppState::InGame))]
|
||||||
struct GameObject;
|
struct GameObject;
|
||||||
|
|
||||||
/// Radius of a ball
|
/// Radius of a ball
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Debug, Default)]
|
||||||
pub struct Radius(pub f32);
|
pub struct Radius(pub f32);
|
||||||
|
|
||||||
/// A basic ball with which to interact
|
/// A basic ball with which to interact
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Debug, Default)]
|
||||||
#[require(GameObject, RigidBody = RigidBody::Dynamic, Radius)]
|
#[require(GameObject, RigidBody = RigidBody::Dynamic, Radius)]
|
||||||
pub struct Ball;
|
pub struct Ball;
|
||||||
|
|
||||||
/// The controllable ball
|
/// The controllable ball
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Debug, Default)]
|
||||||
#[require(Ball)]
|
#[require(Ball)]
|
||||||
pub struct Player;
|
pub struct Player;
|
||||||
|
|
||||||
/// The static objects bounding the playable area
|
/// The static objects bounding the playable area
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Debug, Default)]
|
||||||
#[require(GameObject, RigidBody = RigidBody::Static)]
|
#[require(GameObject, RigidBody = RigidBody::Static)]
|
||||||
pub struct Wall;
|
pub struct Wall;
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub fn check_for_seed(seed: Option<Res<Seed>>, mut next_state: ResMut<NextState<
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The size of the playable area (x, y)
|
/// The size of the playable area (x, y)
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Debug)]
|
||||||
pub struct PlayableArea(f32, f32);
|
pub struct PlayableArea(f32, f32);
|
||||||
|
|
||||||
/// Initialize deterministic values
|
/// Initialize deterministic values
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod plugin;
|
mod plugin;
|
||||||
pub use plugin::NetIOPlugin;
|
pub use plugin::NetIOPlugin;
|
||||||
|
mod queues;
|
||||||
mod socket;
|
mod socket;
|
||||||
mod thread;
|
mod thread;
|
||||||
mod types;
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ use bevy::prelude::*;
|
||||||
use crate::game::prelude::Seed;
|
use crate::game::prelude::Seed;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
queues::{NetworkReceive, NetworkSend},
|
||||||
socket::bind_socket,
|
socket::bind_socket,
|
||||||
types::{NetworkReceive, NetworkSend},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn handle_network_io(
|
fn handle_network_io(
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub type NetworkMessage = (Vec<u8>, SocketAddr);
|
||||||
pub type SendQueue = Sender<NetworkMessage>;
|
pub type SendQueue = Sender<NetworkMessage>;
|
||||||
pub type ReceiveQueue = Receiver<NetworkMessage>;
|
pub type ReceiveQueue = Receiver<NetworkMessage>;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource, Debug)]
|
||||||
pub struct NetworkSend(SendQueue);
|
pub struct NetworkSend(SendQueue);
|
||||||
|
|
||||||
impl NetworkSend {
|
impl NetworkSend {
|
||||||
|
@ -25,7 +25,7 @@ impl NetworkSend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource, Clone, Debug)]
|
||||||
pub struct NetworkReceive(ReceiveQueue);
|
pub struct NetworkReceive(ReceiveQueue);
|
||||||
|
|
||||||
impl NetworkReceive {
|
impl NetworkReceive {
|
|
@ -1,18 +1,19 @@
|
||||||
use std::{
|
use std::{
|
||||||
io::Result,
|
io::Result,
|
||||||
net::{Ipv6Addr, UdpSocket},
|
net::{Ipv6Addr, UdpSocket},
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::unbounded;
|
use crossbeam_channel::unbounded;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
queues::{ReceiveQueue, SendQueue},
|
||||||
thread::{start_receive_thread, start_send_thread},
|
thread::{start_receive_thread, start_send_thread},
|
||||||
types::{ReceiveQueue, SendQueue},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn configure_socket(socket: &UdpSocket) -> Result<()> {
|
fn configure_socket(socket: &UdpSocket) -> Result<()> {
|
||||||
socket.set_read_timeout(None)?;
|
socket.set_read_timeout(None)?;
|
||||||
socket.set_write_timeout(None)?;
|
socket.set_write_timeout(Some(Duration::from_secs(1)))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use super::types::{ReceiveQueue, SendQueue};
|
use super::queues::{ReceiveQueue, SendQueue};
|
||||||
|
|
||||||
fn network_send_loop(messages: ReceiveQueue, socket: UdpSocket) -> Result {
|
fn network_send_loop(messages: ReceiveQueue, socket: UdpSocket) -> Result {
|
||||||
loop {
|
loop {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue