restructure with windows
This commit is contained in:
parent
fe4543ae41
commit
64f4ea529a
7 changed files with 68 additions and 130 deletions
37
src/main.rs
37
src/main.rs
|
|
@ -1,14 +1,13 @@
|
|||
use crate::queue::PacketQueue;
|
||||
use game::Game;
|
||||
use servicepoint::{ClearCommand, UdpSocketExt, FRAME_PACING};
|
||||
use std::net::UdpSocket;
|
||||
use std::thread::sleep;
|
||||
use std::time::{Duration, Instant};
|
||||
use servicepoint::{BinaryOperation, BitVecCommand, Bitmap, CharGrid, CharGridCommand, ClearCommand, CompressionCode, UdpSocketExt, FRAME_PACING, TILE_HEIGHT, TILE_WIDTH};
|
||||
use std::{
|
||||
net::UdpSocket,
|
||||
thread::sleep,
|
||||
time::{Duration, Instant}
|
||||
};
|
||||
|
||||
mod bar;
|
||||
mod queue;
|
||||
mod game;
|
||||
mod label;
|
||||
|
||||
type Currency = f64;
|
||||
|
||||
|
|
@ -17,18 +16,17 @@ trait Progressable: Sized {
|
|||
fn progress(&self, delta: Duration) -> (Self, Currency);
|
||||
}
|
||||
|
||||
trait GenerateCommands {
|
||||
fn generate_commands(&self, queue: &mut impl PacketQueue);
|
||||
}
|
||||
|
||||
const DESTINATION: &str = "127.0.0.1:2342";
|
||||
//const DESTINATION: &str = "172.23.42.29:2342";
|
||||
|
||||
fn main() {
|
||||
let mut state = Game::new();
|
||||
let mut connection = UdpSocket::bind_connect(DESTINATION).unwrap();
|
||||
let connection = UdpSocket::bind_connect(DESTINATION).unwrap();
|
||||
connection.send_command(ClearCommand);
|
||||
|
||||
let mut chars = CharGrid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||
let mut pixels = Bitmap::max_sized();
|
||||
|
||||
let mut last_refresh = Instant::now();
|
||||
loop {
|
||||
let current_time = Instant::now();
|
||||
|
|
@ -37,7 +35,20 @@ fn main() {
|
|||
|
||||
(state, _) = state.progress(delta);
|
||||
|
||||
state.generate_commands(&mut connection);
|
||||
chars.fill(' ');
|
||||
pixels.fill(false);
|
||||
|
||||
let mut chars_view = chars.window_mut(0, 0, chars.width(), chars.height()).unwrap();
|
||||
let mut pixels_view = pixels.window_mut(0,0,pixels.width(), pixels.height()).unwrap();
|
||||
state.draw(&mut chars_view, &mut pixels_view);
|
||||
|
||||
connection.send_command(CharGridCommand::from(chars.clone())).unwrap();
|
||||
connection.send_command(BitVecCommand {
|
||||
bitvec: pixels.clone().into(),
|
||||
compression: CompressionCode::default(),
|
||||
operation: BinaryOperation::Or,
|
||||
offset: 0,
|
||||
}).unwrap();
|
||||
|
||||
sleep(FRAME_PACING);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue