~starkingdoms/starkingdoms

ca4067406c39a4ee1a6063d793d37842196aadc9 — ghostly_zsh 8 months ago 76100ca
flip inputs
2 files changed, 64 insertions(+), 3 deletions(-)

M crates/client/src/networking/mod.rs
M crates/client/src/rendering/mod.rs
M crates/client/src/networking/mod.rs => crates/client/src/networking/mod.rs +0 -1
@@ 44,7 44,6 @@ pub fn process_packets(
                        LandingThrusterSuspension => "landingleg.svg",
                    }.to_string()
                }, ServerId(*id), Part));
                tracing::info!("here");
            }
            PartPositions { parts } => {
                for (id, part) in parts {

M crates/client/src/rendering/mod.rs => crates/client/src/rendering/mod.rs +64 -2
@@ 14,13 14,15 @@ use glutin::surface::{Surface, WindowSurface, GlSurface, SwapInterval};
use glutin::{config::{ConfigTemplateBuilder, GlConfig}, context::{ContextApi, ContextAttributesBuilder, PossiblyCurrentContext}, display::GetGlDisplay, prelude::{GlDisplay, NotCurrentGlContext}};
#[cfg(not(target_arch = "wasm32"))]
use glutin_winit::{DisplayBuilder, GlWindow};
use starkingdoms_common::packet::Packet;
use starkingdoms_common::PlanetType;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::{prelude::Closure, JsCast};
#[cfg(target_arch = "wasm32")]
use web_sys::{Event, HtmlCanvasElement};
use winit::event::MouseScrollDelta;
use winit::event::{ElementState, MouseScrollDelta};
use winit::event_loop::ControlFlow;
use winit::keyboard::{KeyCode, PhysicalKey};
#[cfg(target_arch = "wasm32")]
use winit::platform::web::{WindowAttributesExtWebSys, WindowExtWebSys};
use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, event_loop::ActiveEventLoop, raw_window_handle::HasWindowHandle, window::{Window, WindowAttributes}};


@@ 55,6 57,11 @@ pub struct App {
    send_packet_events: Events<SendPacket>,
    recv_packet_events: Events<RecvPacket>,
    planet_types: HashMap<PlanetType, (Entity, u32)>, // (world entity, server id)

    up: bool,
    down: bool,
    left: bool,
    right: bool,
}

const VERTICES: [f32; 16] = [


@@ 259,6 266,62 @@ impl ApplicationHandler for App {
                    camera.zoom *= delta;
                }
            }
            WindowEvent::KeyboardInput { ref event, .. } => {
                match event.physical_key {
                    PhysicalKey::Code(key) => {
                        let matched: bool;
                        match event.state {
                            ElementState::Pressed => match key {
                                KeyCode::KeyW => {
                                    self.up = true;
                                    matched = true;
                                }
                                KeyCode::KeyS => {
                                    self.down = true;
                                    matched = true;
                                }
                                KeyCode::KeyA => {
                                    self.left = true;
                                    matched = true;
                                }
                                KeyCode::KeyD => {
                                    self.right = true;
                                    matched = true;
                                }
                                _ => matched = false
                            }
                            ElementState::Released => match key {
                                KeyCode::KeyW => {
                                    self.up = false;
                                    matched = true;
                                }
                                KeyCode::KeyS => {
                                    self.down = false;
                                    matched = true;
                                }
                                KeyCode::KeyA => {
                                    self.left = false;
                                    matched = true;
                                }
                                KeyCode::KeyD => {
                                    self.right = false;
                                    matched = true;
                                }
                                _ => matched = false
                            }
                        }
                        if matched {
                            self.send_packet_events.send(SendPacket(Packet::PlayerInput {
                                up: self.down,
                                down: self.up,
                                left: self.right,
                                right: self.left,
                            }));
                        }
                    }
                    PhysicalKey::Unidentified(_) => {} // unsupported
                }
            }
            _ => {}
        }
        let event_response = self.egui_glow.as_mut().unwrap()


@@ 335,7 398,6 @@ impl ApplicationHandler for App {
                        glow::UNSIGNED_BYTE, PixelUnpackData::Slice(Some(&image.bytes)));
                    gl.generate_mipmap(glow::TEXTURE_2D);

                    tracing::info!("{}", texture.name);
                    self.textures.insert(texture.name.clone(), texture_object);
                }
                // now the texture must exist