RustyLee: Streamlines system lifecycle and organ commands
Removes several `LifeState` variants, focusing on a more essential set of states for the core system. Eliminates various `OrganCommand` protocols that are no longer needed, reducing the overall complexity of inter-organ communication. Adjusts the `Brain`'s main loop to actively process organ messages, simplifying its core operational logic.
This commit is contained in:
parent
6ea909347b
commit
a353c48d21
4 changed files with 31 additions and 34 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
use std::sync::mpsc::{Receiver, Sender};
|
use std::sync::mpsc::{Receiver, Sender};
|
||||||
use std::thread::JoinHandle;
|
|
||||||
use crate::lifecycle::{LifeState, LifecycleCommand, LifecycleCommandResponse, LifecycleReceipt};
|
use crate::lifecycle::{LifeState, LifecycleCommand, LifecycleCommandResponse, LifecycleReceipt};
|
||||||
use crate::lifecycle::LifeState::{Dying, Buried, Genisys, Dead};
|
use crate::lifecycle::LifeState::{Dying, Buried, Genisys, Dead};
|
||||||
use crate::organs::organ_factory::OrganFactory;
|
use crate::organs::organ_factory::OrganFactory;
|
||||||
|
|
@ -46,16 +45,15 @@ impl Brain {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.state == Dead {
|
|
||||||
self.rest();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.is_ready() {
|
if self.is_ready() {
|
||||||
self.request_heart_beat();
|
self.request_heart_beat();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.rest()
|
while let Ok(message) = self.organ_rx.try_recv() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
self.rest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +89,6 @@ impl Brain {
|
||||||
|
|
||||||
fn can_transition_lifecycle(&self, command: &LifecycleCommand) -> bool
|
fn can_transition_lifecycle(&self, command: &LifecycleCommand) -> bool
|
||||||
{
|
{
|
||||||
|
|
||||||
if command.required_state == Buried || command.required_state == Dying {
|
if command.required_state == Buried || command.required_state == Dying {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ use std::fmt;
|
||||||
pub enum LifeState {
|
pub enum LifeState {
|
||||||
Dead,
|
Dead,
|
||||||
Genisys,
|
Genisys,
|
||||||
Sleeping,
|
// Sleeping,
|
||||||
Wakening,
|
// Wakening,
|
||||||
Awake,
|
// Awake,
|
||||||
DeepThought,
|
// DeepThought,
|
||||||
ActionFocused,
|
// ActionFocused,
|
||||||
Flight,
|
// Flight,
|
||||||
Panic,
|
// Panic,
|
||||||
Dying,
|
Dying,
|
||||||
Buried,
|
Buried,
|
||||||
}
|
}
|
||||||
|
|
@ -21,13 +21,13 @@ impl fmt::Display for LifeState {
|
||||||
let state_str = match self {
|
let state_str = match self {
|
||||||
LifeState::Dead => "Dead",
|
LifeState::Dead => "Dead",
|
||||||
LifeState::Genisys => "In Genesis",
|
LifeState::Genisys => "In Genesis",
|
||||||
LifeState::Sleeping => "Sleeping",
|
// LifeState::Sleeping => "Sleeping",
|
||||||
LifeState::Wakening => "Wakening",
|
// LifeState::Wakening => "Wakening",
|
||||||
LifeState::Awake => "Fully Awake",
|
// LifeState::Awake => "Fully Awake",
|
||||||
LifeState::DeepThought => "In Deep Thought",
|
// LifeState::DeepThought => "In Deep Thought",
|
||||||
LifeState::ActionFocused => "Action Focused",
|
// LifeState::ActionFocused => "Action Focused",
|
||||||
LifeState::Flight => "In Flight",
|
// LifeState::Flight => "In Flight",
|
||||||
LifeState::Panic => "PANIC!",
|
// LifeState::Panic => "PANIC!",
|
||||||
LifeState::Dying => "Dying",
|
LifeState::Dying => "Dying",
|
||||||
LifeState::Buried => "Buried",
|
LifeState::Buried => "Buried",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl Heart {
|
||||||
|
|
||||||
match envelope.command {
|
match envelope.command {
|
||||||
OrganCommand::Beat(_) => {
|
OrganCommand::Beat(_) => {
|
||||||
if (self.ready_to_beat()) {
|
if self.ready_to_beat() {
|
||||||
self.beat();
|
self.beat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,18 @@ use crate::coordinates::Point3D;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OrganCommand {
|
pub enum OrganCommand {
|
||||||
Sleep,
|
// Sleep,
|
||||||
Waken,
|
// Waken,
|
||||||
Pause,
|
// Pause,
|
||||||
Resume,
|
// Resume,
|
||||||
Beat (u32),
|
Beat (u32),
|
||||||
ChangeSpeed (u32),
|
// ChangeSpeed (u32),
|
||||||
GoFaster(u32),
|
// GoFaster(u32),
|
||||||
GoSlower(u32),
|
// GoSlower(u32),
|
||||||
MoveTo {
|
// MoveTo {
|
||||||
relative_to_center: Point3D,
|
// relative_to_center: Point3D,
|
||||||
speed: u32
|
// speed: u32
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue