#Some architectural reference.

9 messages · Page 1 of 1 (latest)

twilit ocean
#

Hi. I'm looking for an engine for myself. Bevy mostly fits into my criteria but I'm a c++ user and i did try using bevy but i tried to write code like I'm using c++(like inheritance etc. which i could not get it working). I could not find a good reference to how people write code in rust+bevy. Could you list some repos or some sort of tutorials pls?

granite dagger
#

If you want to try something like ecs but in c++, you can look into flecs.

Most of the tutorials for Bevy assume some familiarity with rust, probably mostly out of necessity since Bevy changes quickly. So you'll probably want to practice rust by itself a bit first. The official rust "book" does a pretty decent job: https://doc.rust-lang.org/book/

Rust polymorphism is very different from c++ to start, using traits (closer to interfaces, but not exactly) instead of class inheritance.

Once you have an idea of rust basics, you can generally get the most up to date information from the bevyengine/bevy repo in the examples folder.

cosmic quail
#

ECS components are very different from using inheritance - specifically they're a rather pure form of composition. each component has some purpose, and you define systems which run when a entity has more than that component to achieve behaviour when theres multiple components.

lets look at a example inheritance structure:

  • GameEntity (base class of all things in the game)
    • TransformEntity (adds tranlation/rotation/scale)
      • PhysicsEntity (adds mass, velocity and acceleration)

here, you inherit from PhysicsEntity for your player where you need to implement physics_collision and for things like jumping behaviour. if you want a static platform you only need to inherit from TransformEntity where you only need to implement render.

its just a example which i hope makes sense.

Now, the ECS way of doing this:

all behaviour is caused by database (ecs world) queries. Entity is just the integer primary key.

your game could look like this:

Entity0v1 -> (PlayerMarker, Transform, Sprite, Mass, Velocity, Acceleration)
Entity0v2 -> (PlatformMarker, Transform, Sprite)

Then you (or in bevys case the engine) can implement rendering like this

query = Query<(Entity, Transform, Sprite)>
for (entity, transform, sprite) in query {
render_sprite(transform.pos, sprite)
print("rendered" + entity)
}
-> query all entities which have a sprite for which we can now the position (has a transform).

Query<(Transform, Acceleration), With<Player AND HasGroundContact>>
-> query the players position and acceleration if it has ground contact, allowing you to add jumping velocity

#

i've used pseudocode here, to focus on the concept instead of the syntax

twilit ocean
#

I wasnt using inheritence instead of ecs(edit: well.. yeah i was). I have fairly good knowledge about ecs infact i made simple game engine-ish using using entt(ecs library). But in that engine i have Scene class wich can be inherited and added extra stuff. And there is singleton SceneManager which holds unordered map of scenes and IDs and u can switch scenes using function that takes int

#

I was trying to do something like that but it seams u gotta do that as entity too

cosmic quail
#

most things should be entities, except singletons, those are resources

twilit ocean
#

kk thx