Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content pack system #7

Merged
merged 11 commits into from
Jan 19, 2025
Merged

Add content pack system #7

merged 11 commits into from
Jan 19, 2025

Conversation

lpenguin
Copy link
Contributor

@lpenguin lpenguin commented Jan 1, 2025

Notable changes:

  • Few commits to refactor core render and physics modules for content pack system
  • All code related to content packs system is placed under content_packs workspace member. This should probably be moved somewhere else and should replace bin/game in the future.
  • Currently event consuming is broken: frames are rendered every 16ms, but other input events are being ignored for some reason. The approach in bin/game/main.rs is not working also: frames are rendered without any pauses. Probably there should another timer system implemented, need input from @kvark.
  • I switched to the default gravity in physics.step (so I don't apply forces directly to each rigidbody), as I've seen no harm in doing that.

Key concepts of content pack system:

  • Entity - describe available game objects. Currently there's only one type of entity: Object (visual + physics + scripts). I plan to and Mechoses and Tabutasks.
  • Level - container for entities plus terrain
  • Content Pack: combines entities and levels. Currently there's only one root pack (under data/packs/root), but I plan to add a system to support additional packs that can override and extend root pack.
  • Some structs:
    • ObjectDesc - description of the object, read from RON file.
    • ObjectTemplate - preloaded object ready for instantiation in a level.
    • Object - object instance

@lpenguin lpenguin marked this pull request as draft January 2, 2025 07:37
@kvark
Copy link
Owner

kvark commented Jan 3, 2025

I switched to the default gravity in physics.step (so I don't apply forces directly to each rigidbody), as I've seen no harm in doing that.

We can't use the default gravity since our gravity direction is non-uniform: instead of always being down, it's directed towards the 0-Z axis.

Entity - describe available game objects. Currently there's only one type of entity: Object (visual + physics + scripts). I plan to and Mechoses and Tabutasks.

If there are different types, we might want to use an ECS in here, such as hecs.

@lpenguin
Copy link
Contributor Author

lpenguin commented Jan 3, 2025

We can't use the default gravity since our gravity direction is non-uniform: instead of always being down, it's directed towards the 0-Z axis.

Ah, right, good point

If there are different types, we might want to use an ECS in here, such as hecs.

That's a good suggestion, but currently it will be an overkill in my view. Let's think about it later with more entities added.

@lpenguin
Copy link
Contributor Author

lpenguin commented Jan 6, 2025

Currently event consuming is broken: frames are rendered every 16ms, but other input events are being ignored for some reason. The approach in bin/game/main.rs is not working also: frames are rendered without any pauses. Probably there should another timer system implemented, need input from @kvark.

Fixed in last commits

@@ -105,7 +100,7 @@ impl Physics {
terrain: &TerrainBody,
) {
//Note: real world power is -11, but our scales are different
const GRAVITY: f32 = 6.6743e-8;
const GRAVITY: f32 = 1e-3;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the working magic number is 1e-3, at least my demo cubes fall and collide more or less realistically

@lpenguin lpenguin marked this pull request as ready for review January 7, 2025 12:55
@lpenguin lpenguin changed the title WIP: Add content pack system Add content pack system Jan 7, 2025
Copy link
Owner

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very solid contribution, thank you!
Just a few questions to resolve before we land this

Cargo.toml Outdated
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["lib/ffi"]
members = ["lib/ffi", "lib/content_packs"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you consider dashes instead of underscores for file names?

}

impl CameraController {
pub fn new(camera: Camera) -> CameraController {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ->Self

}
}

pub fn camera(&self) -> &Camera {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be easier to just expose the camera field as pub?

let entry = entry.unwrap();
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "ron" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we assert if it's not "ron"? just ignoring it doesn't sound polite





Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a bunch of empty lines?

did you run cargo fmt on the project?

@@ -0,0 +1,230 @@
use std::collections::{HashMap, HashSet};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: I really like to have a single use statement per crate, e.g.

use std::{fs, time, {f32::consts::PI}, path::Path, sync::Arc};

Can we have that here please?

pub struct QuitEvent;

impl Game {
pub fn new(event_loop: &EventLoop<()>, mods_directory: &Path) -> Game {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: -> Self

@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
[dependencies]
vandals-and-heroes = { path = "../.." }
raw-window-handle = "0.6.2"
log = "0.4.22"
log = "0.4"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need the FFI? I was hoping you'd be comfortable with Rust modules by now

@kvark kvark merged commit d0a5c94 into kvark:main Jan 19, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants