Apparently *self referencial structs* are a big no no in Rust, bummer
This commit is contained in:
77
src/main.rs
77
src/main.rs
@@ -10,87 +10,38 @@ mod timer;
|
||||
mod player;
|
||||
mod input;
|
||||
mod util;
|
||||
mod loader;
|
||||
mod entstate;
|
||||
mod resources;
|
||||
mod collision;
|
||||
|
||||
use crate::player::Player;
|
||||
use crate::timer::Timer;
|
||||
use crate::input::Input;
|
||||
use crate::loader::Loader;
|
||||
use crate::entstate::EntState;
|
||||
use crate::resources::Resources;
|
||||
use crate::collision::Collision;
|
||||
|
||||
extern crate nalgebra as na;
|
||||
extern crate ncollide2d;
|
||||
|
||||
use sfml::graphics::{
|
||||
Color, RenderTarget, RenderWindow,
|
||||
Sprite, Transformable
|
||||
};
|
||||
use sfml::window::{ Event, Key, Style};
|
||||
use sfml::system::Vector2 as sfVec2;
|
||||
use ncollide2d::bounding_volume::{AABB, BoundingVolumeInterferencesCollector};
|
||||
use ncollide2d::partitioning::BVT;
|
||||
use sfml::graphics::RectangleShape;
|
||||
use std::{thread, time};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use ncollide2d::bounding_volume;
|
||||
|
||||
|
||||
pub struct EntState<'a> {
|
||||
dynamic_bvh : Option<BVT<&'a Sprite<'a>, AABB<f64>>>,
|
||||
dynamic_entities: Vec<RefCell< Sprite<'a> >>,
|
||||
|
||||
static_bvh : Option<BVT<&'a Sprite<'a>, AABB<f64>>>,
|
||||
static_entities : Vec<RefCell< Sprite<'a> >>,
|
||||
player : Player<'a>,
|
||||
}
|
||||
|
||||
impl<'a> EntState<'a> {
|
||||
|
||||
pub fn gen_bvt(&'a mut self) {
|
||||
|
||||
let mut dynamic_sprites: Vec<(&'a Sprite, AABB<f64>)> = Vec::new();
|
||||
{
|
||||
for i in self.dynamic_entities {
|
||||
let bounds = i.borrow().global_bounds();
|
||||
let pos = i.borrow().position();
|
||||
let volume = bounding_volume::AABB::new(na::Point2::new(pos.x as f64, pos.y as f64),
|
||||
na::Point2::new((pos.x + bounds.width) as f64, (pos.y + bounds.width) as f64));
|
||||
|
||||
dynamic_sprites.push((&i.borrow(), volume));
|
||||
}
|
||||
}
|
||||
self.dynamic_bvh = Some(BVT::new_balanced(dynamic_sprites));
|
||||
|
||||
// let mut static_sprites: Vec<(&Sprite, AABB<f64>)> = Vec::new();
|
||||
// {
|
||||
// for i in self.static_entities {
|
||||
// let bounds = i.local_bounds();
|
||||
// let pos = i.position();
|
||||
// let volume = bounding_volume::AABB::new(na::Point2::new(pos.x as f64, pos.y as f64),
|
||||
// na::Point2::new((pos.x + bounds.width) as f64, (pos.y + bounds.width) as f64));
|
||||
//
|
||||
// static_sprites.push((i, volume));
|
||||
// }
|
||||
// }
|
||||
// self.static_bvh = Some(BVT::new_balanced(static_sprites));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let loader = Loader::new();
|
||||
let mut state = EntState {
|
||||
dynamic_bvh: Option::None,
|
||||
dynamic_entities: Vec::new(),
|
||||
static_bvh: Option::None,
|
||||
static_entities: Vec::new(),
|
||||
player: Player::new(),
|
||||
};
|
||||
|
||||
loader.read_static_entities(String::from("static_entities.txt"), &mut state);
|
||||
loader.read_dynamic_entities(String::from("dynamic_entities.txt"), &mut state);
|
||||
let mut resources = Resources::new();
|
||||
let mut collision = Collision::new();
|
||||
let mut state = EntState::new();
|
||||
|
||||
state.gen_bvt();
|
||||
state.read_static_entities(String::from("static_entities.txt"), &resources);
|
||||
//state.read_static_entities(String::from("static_entities.txt"), &resources);
|
||||
//state.read_dynamic_entities(String::from("dynamic_entities.txt"));
|
||||
|
||||
//state.gen_bvt();
|
||||
|
||||
|
||||
let mut window = RenderWindow::new(
|
||||
|
||||
Reference in New Issue
Block a user