Skip to content

Commit

Permalink
improve remote
Browse files Browse the repository at this point in the history
  • Loading branch information
flmichel committed Jun 2, 2023
1 parent c7384fb commit e98795e
Show file tree
Hide file tree
Showing 17,119 changed files with 4,259 additions and 1,930,629 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3,547 changes: 3,547 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"./server",
"./game",
]
2 changes: 0 additions & 2 deletions game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ edition = "2021"

[dependencies]
qrcode = { version = "0.12" }
specs = "0.18"
specs-derive = "0.4"
anyhow = "1.0"
tokio = { version = "1", features = ["full"] }
webrtc = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion game/src/controllers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn start_peer_connection(offer: String, sender: Sender<String>) {
sender.send(answer).await.expect("failed to send answer");
}

pub fn listen(peer_connection: RTCPeerConnection, sender: Sender<String>) {
pub fn listen(peer_connection: RTCPeerConnection) {
peer_connection.on_peer_connection_state_change(Box::new(move |s: RTCPeerConnectionState| {
println!("Peer Connection State has changed: {s}");

Expand Down
11 changes: 3 additions & 8 deletions game/src/game.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use serde::Deserialize;

use crate::remotes::RemoteInput;

#[derive(Deserialize)]
#[serde(untagged)]
pub enum MessageToGame {
Input(Input),
RemoteInput(RemoteInput),
RoomId(String),
PlayerDirection(f64),
}

#[derive(Deserialize)]
pub enum Input {
A,
B,
}
8 changes: 8 additions & 0 deletions game/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod controllers;
pub mod game;
pub mod players_connector;
pub mod remote_communicator;
pub mod remotes;
pub mod room_code;
pub mod server_communicator;
pub mod signal;
34 changes: 13 additions & 21 deletions game/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
mod controllers;
mod game;
mod players_connector;
mod remote_communicator;
mod room_code;
mod server_communicator;
mod signal;

use futures_channel::mpsc::unbounded;
use game::{Input, MessageToGame};
use game::game::MessageToGame;
use game::remotes::{GameInput, RemoteInput};
use game::{players_connector, room_code, server_communicator};
use players_connector::PlayersConnector;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
Expand All @@ -19,7 +13,7 @@ use anyhow::Result;
use image::LoadTexture;
use room_code::RoomCode;
use sdl2::image::{self, InitFlag};
use server_communicator::{MessageToServer, SdpMessage, ServerCommunicator};
use server_communicator::ServerCommunicator;
use std::time::Duration;
use tokio::spawn;

Expand Down Expand Up @@ -49,7 +43,9 @@ fn render(
let squares = room_code.get_qr_code_squares(10);
squares.iter().for_each(|(square, color)| {
canvas.set_draw_color(*color);
canvas.fill_rect(*square).unwrap();
let mut square = square.clone();
square.offset(10, 10);
canvas.fill_rect(square).unwrap();
});

let (width, height) = canvas.output_size()?;
Expand Down Expand Up @@ -94,17 +90,10 @@ async fn main() -> Result<(), String> {
let server_communicator = ServerCommunicator::new(
sender_to_game,
sender_to_player_connector,
//receiver_server,
"ws://localhost:5000",
);
spawn(async move { server_communicator.start(receiver_server).await });

let answer = MessageToServer::SdpAnswer(SdpMessage {
data: "hello".to_owned(),
id: 23,
});
//sender_to_server.unbounded_send(answer).unwrap();

let sdl_context = sdl2::init().expect("failed to create context");
let video_subsystem = sdl_context.video()?;
// Leading "_" tells Rust that this is an unused variable that we don't care about. It has to
Expand Down Expand Up @@ -158,14 +147,17 @@ async fn main() -> Result<(), String> {
MessageToGame::RoomId(id) => {
println!("creating qrcode with room_id {}", id);
room_code = RoomCode::new(
format!("http://192.168.0.103:8080/?room-id={}", id).to_owned(),
format!("http://192.168.0.107:8080/?room-id={}", id).to_owned(),
);
}
MessageToGame::Input(_) => {}
MessageToGame::PlayerDirection(direction) => {
MessageToGame::RemoteInput(RemoteInput::GameInput(GameInput::Move(direction))) => {
player.speed = PLAYER_MOVEMENT_SPEED;
player.direction = Direction(direction);
}
MessageToGame::RemoteInput(RemoteInput::GameInput(GameInput::Stop)) => {
player.speed = 0.0;
}
MessageToGame::RemoteInput(_) => {}
}
}

Expand Down
9 changes: 1 addition & 8 deletions game/src/players_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl PlayersConnector {
receiver: UnboundedReceiver<SdpMessage>,
) -> Self {
let mut m = MediaEngine::default();
let mut fastest_codec = RTCRtpCodecParameters {
let fastest_codec = RTCRtpCodecParameters {
capability: RTCRtpCodecCapability {
mime_type: MIME_TYPE_OPUS.to_owned(),
clock_rate: 48000,
Expand Down Expand Up @@ -181,13 +181,6 @@ impl PlayersConnector {
Ok(()) => println!("The message was successfully sent"),
Err(err) => println!("failed to send message {}", err.to_string()),
}

let sender_to_game = self.sender_to_game.clone();
/*spawn(async move {
let mut remote_communicator =
RemoteCommunicator::new(peer_connection, sender_to_game);
remote_communicator.start().await
});*/
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions game/src/remote_communicator.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use anyhow::Result;
use std::{time::Duration, sync::Arc};

use futures_channel::mpsc::UnboundedSender;
use webrtc::{peer_connection::{RTCPeerConnection, peer_connection_state::RTCPeerConnectionState}, data_channel::{data_channel_message::DataChannelMessage, RTCDataChannel}};

use crate::game::MessageToGame;

pub struct RemoteCommunicator {
peer_connection: RTCPeerConnection,
sender_to_game: UnboundedSender<MessageToGame>,
}

impl RemoteCommunicator {
pub fn new(peer_connection: RTCPeerConnection, sender_to_game: UnboundedSender<MessageToGame>) -> Self {
pub fn new(peer_connection: RTCPeerConnection) -> Self {
print!("new player could connect");
Self {
peer_connection,
sender_to_game,
}
}

Expand Down
20 changes: 20 additions & 0 deletions game/src/remotes/messages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::Deserialize;

#[derive(Deserialize)]
#[serde(untagged)]

pub enum RemoteInput {
GameInput(GameInput),
ReadyToPlay,
SetUsername(String),
}

#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum GameInput {
Aim(f64),
Shoot(f64),
Bomb,
Stop,
Move(f64),
}
3 changes: 3 additions & 0 deletions game/src/remotes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod messages;

pub use messages::*;
13 changes: 3 additions & 10 deletions game/src/signal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use base64::{engine::general_purpose, Engine};

/// must_read_stdin blocks until input is received from stdin
pub fn must_read_stdin() -> Result<String> {
Expand All @@ -17,21 +18,13 @@ pub fn must_read_stdin() -> Result<String> {
/// encode encodes the input in base64
/// It can optionally zip the input before encoding
pub fn encode(b: &str) -> String {
//if COMPRESS {
// b = zip(b)
//}

base64::encode(b)
general_purpose::STANDARD.encode(b.as_bytes())
}

/// decode decodes the input from base64
/// It can optionally unzip the input after decoding
pub fn decode(s: &str) -> Result<String> {
let b = base64::decode(s)?;

//if COMPRESS {
// b = unzip(b)
//}
let b = general_purpose::STANDARD.decode(s)?;

let s = String::from_utf8(b)?;
Ok(s)
Expand Down
1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/acorn

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/ansi-html

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/browserslist

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/conc

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/concurrently

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/envinfo

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/import-local-fixture

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/is-docker

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/mime

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/multicast-dns

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/node-which

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/resolve

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/rimraf

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/semver

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/terser

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/tree-kill

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/tsc

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/tsserver

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/update-browserslist-db

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/uuid

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/webpack

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/webpack-cli

This file was deleted.

1 change: 0 additions & 1 deletion lit-remote/node_modules/.bin/webpack-dev-server

This file was deleted.

Loading

0 comments on commit e98795e

Please sign in to comment.