saveload
in specs
" or "no saveload
in the root" for "use specs::saveload;". In Cargo.toml, i have 0.15.1 version. Thanks all.
specs
and maps. This stuff is all new for me and I don't really know if it is a good approach to use ECS for map rendering? For example right now I use a "map" as a component. This map contains lines, points and so on. For each map I then create entities which represents a "level". And one system which is responsible for handling the rendering in the end? Why I am asking? Because technically a map is not a entity. Right, or do I miss something?
builder.add_barrier()
and builder.add_thread_local()
add_thread_local
would probably just run the system on current thread
struct ContextWrapper{
pub ctx: *mut Context
}
impl ContextWrapper{
fn get(&self) -> &mut Context
{
unsafe{
&mut *self.ctx
}
}
}
unsafe impl Sync for ContextWrapper{}
unsafe impl Send for ContextWrapper{}
&mut World
instead of res
whatever it was at the date apparently
Hey, does anyone have experience using the saveload module with bincode? First issue: the Serializer struct that needs to be passed to the serialize function is private. I bypassed that by cloning the repository and making it public, but that's not really a nice solution.
Second issue, I get this error: Bincode can only encode sequences and maps that have a knowable size ahead of time
So bincode can't be used with saveload?
Hello there, I'm coming back to creating a text-based game using Specs and I can't figure out a good way to handle input. In my mind, a command (like attack) is composed of selectors (CreatureSelector and WeaponSelector in this case) that are responsible for associating a slice of input to something in the world. Those selectors must run in a given order defined by each command, and they all have very different needs in terms of storage reading. The most practical way I've found is to create custom system traits and my own dispatcher like so:
pub trait Command<'a> {
type Data: SystemData<'a>;
fn get_selectors(&self) -> &[Box<dyn ExecuteSelector>];
fn run(&self, args: Vec<Selectable>, game: &Game, data: Self::Data) -> CommandResult;
fn setup(&self, world: &mut World);
}
pub trait ExecuteCommand<'a> {
fn get_selectors(&self) -> &[Box<Selector>];
fn run(&self, args: Vec<Selectable>, game: &Game, world: &'a World) -> CommandResult;
fn setup(&self, world: &mut World);
}
impl<'a, T> ExecuteCommand<'a> for T
where T: Command<'a>
{ ... }
pub trait Selector<'a> {
type Data: SystemData<'a>;
fn parse(&self, input: &str, game: &Game, data: Self::Data) -> ParsingResult<(usize, Selectable)>;
fn setup(&self, res: &mut World);
}
pub trait ExecuteSelector<'a> { ... }
impl<'a, T> ExecuteSelector<'a> for T
where T: Selector<'a>
{ ... }
pub struct CommandDispatcher<'a> {
commands: Vec<Box<dyn ExecuteCommand<'a>>>
}
impl<'a> CommandDispatcher<'a> {
pub fn dispatch(&self, input: &str, game: &Game<'a>, world: &'a mut World) -> Result<(), DispatchingError> {
// Find which command to trigger based on the start of the input and strip the matching part.
// For each command's selector, run it and remove the matching part of the input. Add the results to a list of arguments.
// Run the command and pass it the list of arguments.
}
}
Of course this is a simplified version. But I think that this defeats the purpose of an ECS...
Does anyone have an idea on how to put it differently? Many thanks in advance!
Hey people, I'm following the specs book, and I'm finding plenty of problems. Even if I just copy and paste the examples to follow, not even the first ones compile. Most of them seem to be related to how the modules are imported, but there are plenty of things I don't get.
For instance, while doing this
use specs::{Component, ReadStorage, System, VecStorage, World, RunNow, WorldExt, Join};
// a bunch of code...
let entity = world
.create_entity()
.with(Position { x: 4.0, y: 7.0 }) // ERROR: no method named `with` found for type `specs::world::EntityBuilder<'_>`
.build();
I encounter that problem.
Which apparently gets fixed when "using" specs::world::* (not World)
I also needed to add WorldExt to the mix, because World::new() was not recognized. That is also not in the example of the book.
Also, even after fixing these 2 problems, I still cant compile:
let mut hello_world = HelloWorld;
hello_world.run_now(&world.res);
// ERROR: no field `res` on type `shred::world::World`
Here is the system pretty much the same as it is in the book:
struct HelloWorld;
impl<'a> System<'a> for HelloWorld {
type SystemData = ReadStorage<'a, Position>;
fn run(&mut self, position: Self::SystemData) {
for position in position.join() {
println!("Hello, {:?}", &position);
}
}
}
Not sure how I should make the "use" statements or what am I doing wrong. In any case, the book, while very easy to follow, it's examples straight up don't work, so that's something to keep in mind
are there any examples of using a generic resource in a system? for example:
trait IsALevelThing: Send + Sync {}
struct LevelThing;
struct Renderer<T> {
_a: PhantomData<T>,
}
impl<'a, T: 'a + IsALevelThing> System<'a> for Renderer<T> {
type SystemData = Read<'a, T, PanicHandler>;
fn run(&mut self, data: Self::SystemData) {
// TODO
}
}
seems like it should work but it gives the parameter type
Tmay not live long enough, consider adding an explicit lifetime bound T: 'static
. not sure why this is since from what i understand it just needs to live for 'a