Skip to content

Commit

Permalink
build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed May 8, 2022
1 parent bcbe8ee commit 4823bae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 113 deletions.
Binary file modified data/levels/dm6.rgs
Binary file not shown.
5 changes: 1 addition & 4 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use fyrox::{
transform::TransformBuilder,
Scene,
},
utils::{
log::{Log, MessageKind},
navmesh::Navmesh,
},
utils::log::{Log, MessageKind},
};
use std::{
ops::{Deref, DerefMut},
Expand Down
66 changes: 8 additions & 58 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use fyrox::{
};
use std::{path::Path, sync::mpsc::Sender};

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Visit)]
pub enum ItemKind {
Medkit,

Expand All @@ -29,35 +29,7 @@ pub enum ItemKind {
RocketLauncher,
}

impl ItemKind {
fn from_id(id: u32) -> Result<ItemKind, String> {
match id {
0 => Ok(ItemKind::Medkit),
1 => Ok(ItemKind::Plasma),
2 => Ok(ItemKind::Ak47Ammo),
3 => Ok(ItemKind::M4Ammo),
4 => Ok(ItemKind::PlasmaGun),
5 => Ok(ItemKind::Ak47),
6 => Ok(ItemKind::M4),
7 => Ok(ItemKind::RocketLauncher),
_ => Err(format!("Unknown item kind {}", id)),
}
}

fn id(self) -> u32 {
match self {
ItemKind::Medkit => 0,
ItemKind::Plasma => 1,
ItemKind::Ak47Ammo => 2,
ItemKind::M4Ammo => 3,
ItemKind::PlasmaGun => 4,
ItemKind::Ak47 => 5,
ItemKind::M4 => 6,
ItemKind::RocketLauncher => 7,
}
}
}

#[derive(Visit)]
pub struct Item {
kind: ItemKind,
pivot: Handle<Node>,
Expand All @@ -67,7 +39,7 @@ pub struct Item {
offset_factor: f32,
reactivation_timer: f32,
active: bool,
definition: &'static ItemDefinition,
#[visit(skip)]
pub sender: Option<Sender<Message>>,
lifetime: Option<f32>,
}
Expand All @@ -83,7 +55,6 @@ impl Default for Item {
offset_factor: 0.0,
reactivation_timer: 0.0,
active: true,
definition: Self::get_definition(ItemKind::Medkit),
sender: None,
lifetime: None,
}
Expand Down Expand Up @@ -249,8 +220,12 @@ impl Item {
self.kind
}

pub fn definition(&self) -> &'static ItemDefinition {
Self::get_definition(self.kind)
}

pub fn pick_up(&mut self) {
self.reactivation_timer = self.definition.reactivation_interval;
self.reactivation_timer = self.definition().reactivation_interval;
self.active = false;
}

Expand All @@ -274,31 +249,6 @@ impl Item {
}
}

impl Visit for Item {
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
visitor.enter_region(name)?;

let mut kind = self.kind.id();
kind.visit("Kind", visitor)?;
if visitor.is_reading() {
self.kind = ItemKind::from_id(kind)?;
}

self.definition = Self::get_definition(self.kind);
self.model.visit("Model", visitor)?;
self.pivot.visit("Pivot", visitor)?;
self.offset.visit("Offset", visitor)?;
self.offset_factor.visit("OffsetFactor", visitor)?;
self.dest_offset.visit("DestOffset", visitor)?;
self.reactivation_timer
.visit("ReactivationTimer", visitor)?;
self.active.visit("Active", visitor)?;
self.lifetime.visit("Lifetime", visitor)?;

visitor.leave_region()
}
}

#[derive(Visit)]
pub struct ItemContainer {
pool: Pool<Item>,
Expand Down
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ impl Level {
let scene = &mut engine.scenes[self.scene];
let weapon = &mut self.weapons[weapon_handle];
if weapon.try_shoot(scene, time) {
let kind = weapon.definition.projectile;
let kind = weapon.definition().projectile;
let position = weapon.get_shot_position(&scene.graph);
let direction = direction
.unwrap_or_else(|| weapon.get_shot_direction(&scene.graph))
Expand Down
60 changes: 10 additions & 50 deletions src/weapon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,15 @@ use std::{
sync::mpsc::Sender,
};

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Visit)]
pub enum WeaponKind {
M4,
Ak47,
PlasmaRifle,
RocketLauncher,
}

impl WeaponKind {
pub fn id(self) -> u32 {
match self {
WeaponKind::M4 => 0,
WeaponKind::Ak47 => 1,
WeaponKind::PlasmaRifle => 2,
WeaponKind::RocketLauncher => 3,
}
}

pub fn new(id: u32) -> Result<Self, String> {
match id {
0 => Ok(WeaponKind::M4),
1 => Ok(WeaponKind::Ak47),
2 => Ok(WeaponKind::PlasmaRifle),
3 => Ok(WeaponKind::RocketLauncher),
_ => Err(format!("unknown weapon kind {}", id)),
}
}
}

#[derive(Visit)]
pub struct Weapon {
kind: WeaponKind,
model: Handle<Node>,
Expand All @@ -66,7 +46,7 @@ pub struct Weapon {
shot_position: Vector3<f32>,
owner: Handle<Actor>,
ammo: u32,
pub definition: &'static WeaponDefinition,
#[visit(skip)]
pub sender: Option<Sender<Message>>,
}

Expand All @@ -91,35 +71,11 @@ impl Default for Weapon {
shot_position: Vector3::default(),
owner: Handle::NONE,
ammo: 250,
definition: Self::get_definition(WeaponKind::M4),
sender: None,
}
}
}

impl Visit for Weapon {
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
visitor.enter_region(name)?;

let mut kind_id = self.kind.id();
kind_id.visit("KindId", visitor)?;
if visitor.is_reading() {
self.kind = WeaponKind::new(kind_id)?
}

self.definition = Self::get_definition(self.kind);
self.model.visit("Model", visitor)?;
self.laser_dot.visit("LaserDot", visitor)?;
self.offset.visit("Offset", visitor)?;
self.dest_offset.visit("DestOffset", visitor)?;
self.last_shot_time.visit("LastShotTime", visitor)?;
self.owner.visit("Owner", visitor)?;
self.ammo.visit("Ammo", visitor)?;

visitor.leave_region()
}
}

impl Weapon {
pub fn get_definition(kind: WeaponKind) -> &'static WeaponDefinition {
match kind {
Expand Down Expand Up @@ -200,7 +156,6 @@ impl Weapon {
laser_dot,
model,
shot_point,
definition,
ammo: definition.ammo,
sender: Some(sender),
..Default::default()
Expand Down Expand Up @@ -302,8 +257,13 @@ impl Weapon {
self.owner = owner;
}

pub fn definition(&self) -> &'static WeaponDefinition {
Self::get_definition(self.kind)
}

pub fn try_shoot(&mut self, scene: &mut Scene, time: GameTime) -> bool {
if self.ammo != 0 && time.elapsed - self.last_shot_time >= self.definition.shoot_interval {
if self.ammo != 0 && time.elapsed - self.last_shot_time >= self.definition().shoot_interval
{
self.ammo -= 1;

self.offset = Vector3::new(0.0, 0.0, -0.05);
Expand All @@ -314,7 +274,7 @@ impl Weapon {
if let Some(sender) = self.sender.as_ref() {
sender
.send(Message::PlaySound {
path: PathBuf::from(self.definition.shot_sound),
path: PathBuf::from(self.definition().shot_sound),
position,
gain: 1.0,
rolloff_factor: 5.0,
Expand Down

0 comments on commit 4823bae

Please sign in to comment.