Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Yusuf Bera Ertan
@yusdacra_gitlab

Hello, i have a question about joining. How can i join a storage with an entity? Like this

(&mut world.write_storage::<Enemy>(), &enemy_entity).join()

enemy_entity is an specs::Entity. When i do that, compiler gives a trait bound error.

Or is there another way to get components of an entity if you know the entity already?
Yusuf Bera Ertan
@yusdacra_gitlab

Nvm, i just found it. The thing i was looking for was

world.write_storage::<Enemy>().entry(enemy_entity)

Sorry for not reading the docs.

Aaron DeVore
@adevore
Hey, I'm maintainer of the Rudy crate. At this point, I'm not really putting any development time into Rudy, so I don't think it will ever be faster than the built-in data structures. I was wonder about whether specs should remove its support.
For that matter, it's unclear as to whether Judy arrays (the data structure that Rudy aims to implement) are even any faster. They were designed a while ago, so modern CPU's might have different performance bottlenecks.
Aleksi Juvani
@aleksijuvani
is there any reason for insert in World to require Resources to have a 'static lifetime? it seems to me like this should be the lifetime of the World instead
Aleksi Juvani
@aleksijuvani
this is what i end up doing right now which is kinda gross
world.insert(unsafe { transmute::<&'_ DebugOverlay, &'static DebugOverlay>(surface.debug_overlay()) });
Matthew Hoffman
@mhoff12358
I'm profiling my code and seeing that DispatcherBuilder::add eventually starts to take a long time (~400ms). A RawVec realloc is what's taking up the whole time. The only thing I can think of is that there's some global state associated with each System that keeps getting added to when I make a new Dispatcher each frame. I wanted to try making the Dispatcher once, but I can't figure out how to have one as a member variable on my struct because I don't know what lifetimes to template it with.
Matthew Hoffman
@mhoff12358
I managed to figure it out. The 'a and 'b lifetime templates for Dispatcher ensure any System passed in through .with or .with_thread_local live at least as long as 'a and 'b. But since none of my Systems have any references it is okay to just have 'a and 'b be 'static.
Alex Davidson Bryan
@alxdb

hey, can someone tell me if a VecStorage will ever shrink in size?

Looking at the VecStorage implementation of UnsafeStorage it seems that when entities as entities are added the vec grows, but the only way it can shrink is when it is cleaned, where all entities are removed. Is my thinking correct?

WaDelma
@WaDelma
Yes it only shrinks when it's cleared. The size of VecStorage is always larger than the largest id of an entity.
Roman Holovin
@roman-holovin
Hi, is there is a way to get immutable borrow of the world from within system run function? I know about LazyUpdate``exec function, but given closure to it will be executing at the end of a frame and I'm not sure if it is suits me.
WaDelma
@WaDelma
What do you want to do with it?
Roman Holovin
@roman-holovin
Basically, spare some typing, pathfinding need half of the world to be able to route entities that move, so I would like to just pass immutable reference to world, so pathfinding logic would query whatever it needs
Ian Sly
@uzkbwza
so I saw this article, using specs, about events being used in the form of functions. I'm writing my code pretty faithful to the way it is done in the specs documentation (main loop doesn't do much more than dispatch and check if the game is ended). I'm wondering how one would accomplish this inside the systems themselves, or if it is something I should avoid doing in the first place, and just stick to using components for events
Daniel Salvadori
@danaugrs
@uzkbwza I'm working on a game engine using specs and I'm using shrev for events. Each event/event type (usually an enum type) has an associated global EventChannel resource which can be read and written to by systems. This allows specs/shred to optimize which systems can be executed in parallel automatically, like it's done for component reads/writes. It's working pretty nicely for me so far. Also, this is how specs does events internally for its FlaggedStorage, which allows you to check if/which components have been modified.
Ian Sly
@uzkbwza
If you don't mind, could you post an example of how you're using shrev with specs?
Oh, funny. it even mentions shrev in the specs book. https://slide-rs.github.io/specs/07_setup.html
This is exactly what i needed! lol.
Daniel Salvadori
@danaugrs
@uzkbwza wow yep that explains it pretty well :D
Thomas Schaller
@torkleyy
@WaDelma Dispatcher isn't Send because it can contain thread-local systems.
Roman Holovin
@roman-holovin

I have a problem with pathfinding. I wrote a function to calculate paths. It needs bunch of storages, read-only. Unfortunately, one system that interacts with pathfinding requires one of this storages for mutable access. I had to specify WriteStorage for pathfinding arguments just because one of system needs it this way. Documentation specifies that it is forbidden to require both ReadStorage and WriteStorage simultaneously, so I cannot do that. At this point it doesn't really bother me that much, but I suspect I will have problem with FlaggedStorage in future.

Is there way to specify argument type for function so it would accept both ReadStorage and WriteStorage whichever is available for me in the system, so I can pass it to pathfinding?

Daniel Salvadori
@danaugrs
@roman-holovin Could try one of the storage traits
WaDelma
@WaDelma
@torkleyy Makes sense
So that probably could be added to the documentation, because it confused me quite bit
Ian Sly
@uzkbwza

i'm having trouble using the .join() method outside of the System trait implementation block. anyone know how i should fix it?

pardon the ugly code, but here is something that I'm having issues with.
https://pastebin.com/wzURVPS5

the method at line 121 does not work when used in a method for the Ai struct, but it does inside the system's .run() function at line 156. what am i doing wrong? perhaps am I just structuring my code wrong in the first place? should I be approaching this sort of thing in a different way?

Aleksi Juvani
@aleksijuvani
i think you're just missing borrows there
try for (player_entity, target_pos, player) in (&data.entities, &data.positions, &data.players).join()
Ian Sly
@uzkbwza
ahh, thanks. dumb mistake on my part
Aleksi Juvani
@aleksijuvani
oof the saveload api seems like a whole ordeal
i was expecting just to be able to call serialize on the world and be done with it
but this seems to expect that i want to use markers and do some kind of error handling stuff in a trait when i don't care about any of that
Vladimir Zaytsev
@vladimir.zaytsev_gitlab

Hi,

I'm new to rust and specs. I writing a system that needs to access a data that is not owned by specs::World and cannot be copied into world as a resource. What is a good way to pass a data's reference into system's run method? I also cannot store a reference to the data inside of system type because it's lifetime much shorter than the system.

Vladimir Zaytsev
@vladimir.zaytsev_gitlab
nvm, a found similar use-case in examples/cluster_bomb.rs. I think reading world's entities from storage and processing them outside of specs is what I actually should do.
Roman Holovin
@roman-holovin
Hi, is there a reason why GenericReadStorage does not implement Join trait? I'm trying to implement a function that will accept both ReadStorage and WriteStorage, but it seems I cannot join it.
Ian Sly
@uzkbwza
How are you guys handling entity templates? i don't want to be using hard-coded functions for entity generation after a certain point. something like Dwarf Fortress's raw files come to mind, or Caves of Qud saving entity "types" in xml files. Just wondering what your processes are.
Andrew
@robo-corg
@uzkbwza I use serde to deserialize json into an intermediary blueprint format. Then I use serde again to instantiate an entity from that intermediate format. I might rewrite it some since its a bit clunky and probably slow.
Ian Sly
@uzkbwza
Cool, I'd like to see how you've implemented it, if you don't mind. I've gone through a couple different implementations but I'm not happy with anything I've written so far.
FlorentKl
@FlorentKl
Hi. Maybe i am an idiot, but i'm pretty new to Rust, and can't figure out how to import the saveload module. I use "use specs::saveload::{SimpleMarker, SimpleMarkerAllocator};", but keep getting an error : "could not find saveload in specs" or "no saveload in the root" for "use specs::saveload;". In Cargo.toml, i have 0.15.1 version. Thanks all.
WaDelma
@WaDelma
You need to enable serde feature in your Cargo.toml. Here is the documentation on how to do it.
FlorentKl
@FlorentKl
Thanks, it work now.
Bastczuak
@Bastczuak
Hello guys, I am new here and I have a general questions regarding 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?
Troels Jessen
@Sheepyhead
Hey friends, this is somewhat of a long shot, but I'm at my wit's end with specs. How do you folks manage to draw anything inside a system? I stumbled upon the ability to define thread local systems, but the system isn't the problem, the problem is the resource. To draw something generally you need a graphics context, and generally that context absolutely cannot be shared between threads, and I cannot seem to find a way to add a resource like that. All I want is to use a Draw system to render my entities based on their Position and Sprite components, but at this point I have no idea how to do this. Right now I'm using ggez as my game engine, but I had the same problem when I was using Piston.
I'm currently looking through the docs for Amethyst, since none of the specs examples seem to have any actual rendering happening, but I figured it wouldn't hurt to ask here.
What I was expecting to work was to insert the resource using world.insert or a variant that works with thread local systems, but I can't seem to find anything in the docs that appear to be what I need to pass a graphics context into a rendering system. Is it simply that I shouldn't be using systems to render things?
Troels Jessen
@Sheepyhead
No that can't be it, the chapter on rendering explicitly has a system named RenderSys, which sounds like it should be a rendering system. Unfortunately it neglects to display how such a system would actually do any rendering https://specs.amethyst.rs/docs/tutorials/10_rendering.html
Seems the only mention of this RenderSys in the repo is that one markdown file. I might be missing something obvious, but this seems like a major oversight to me. In any case I would really love some help with this, as it's currently blocking my entire game project from proceeding :(
Dmitriy
@dpogretskiy
RenderSys is a part of rendering bundle, you should probably dig the sources a bit to understand what's up with it, cause the one is used in amethyst tutorials is aready built in.
https://docs.rs/crate/amethyst_rendy/0.3.0/source/src/bundle.rs
2 interesting bits here are builder.add_barrier() and builder.add_thread_local()