Skip to content

Commit

Permalink
Move Point struct into common module
Browse files Browse the repository at this point in the history
  • Loading branch information
davidffa committed Mar 18, 2024
1 parent df2a06a commit 5f8f02f
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client/src/game.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::{HashMap, VecDeque};

use crate::util::Point;
use common::util::Point;

#[derive(PartialEq)]
pub enum State {
Expand Down
5 changes: 2 additions & 3 deletions client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod game;
mod renderer;
mod util;

use std::{
collections::VecDeque,
Expand All @@ -9,12 +8,12 @@ use std::{
net::TcpStream,
};

use common::packet::{PacketBuilder, PacketType, ReadablePacket};
use common::{packet::{PacketBuilder, PacketType, ReadablePacket}, util::Point};
use game::{Direction, GameContext, Snake};
use renderer::{Renderer, WINDOW_HEIGHT, WINDOW_WIDTH};
use sdl2::{event::Event, keyboard::Keycode};

use crate::{game::State, util::Point};
use crate::game::State;

const ADDR: &str = "127.0.0.1:14300";

Expand Down
3 changes: 2 additions & 1 deletion client/src/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use common::util::Point;
use sdl2::{pixels::Color, rect::Rect, render::WindowCanvas, video::Window};

use crate::{game::GameContext, util::Point};
use crate::game::GameContext;

const BG_COLOR: Color = Color::RGB(24, 24, 24);
const FOOD_COLOR: Color = Color::RED;
Expand Down
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod packet;
pub mod util;

1 change: 1 addition & 0 deletions client/src/util.rs → common/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::Add;


#[derive(Clone, Copy, PartialEq)]
pub struct Point(pub i32, pub i32);

Expand Down
3 changes: 1 addition & 2 deletions server/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};

use common::util::Point;
use rand::{rngs::StdRng, Rng, SeedableRng};

use crate::util::Point;

const WIDTH: i32 = 80;
const HEIGHT: i32 = 60;

Expand Down
4 changes: 1 addition & 3 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod game;
mod util;

use std::{
collections::HashMap,
Expand All @@ -10,13 +9,12 @@ use std::{
time::Duration,
};

use common::packet::{PacketBuilder, PacketType, ReadablePacket};
use common::{packet::{PacketBuilder, PacketType, ReadablePacket}, util::Point};
use game::Snake;
use mio::{
net::{TcpListener, TcpStream},
Events, Interest, Poll, Token,
};
use util::Point;

use crate::game::{Direction, GameContext};

Expand Down
12 changes: 0 additions & 12 deletions server/src/util.rs

This file was deleted.

0 comments on commit 5f8f02f

Please sign in to comment.