penguin-application

Crates.iopenguin-application
lib.rspenguin-application
version0.1.1
sourcesrc
created_at2021-12-22 17:34:01.493732
updated_at2021-12-23 01:22:44.427551
descriptionAppbuilder and abstraction layer for building applications using legion ECS.
homepage
repositoryhttps://github.com/Henrik-N/penguin-app
max_upload_size
id501818
size21,973
Henrik Nilsson (Henrik-N)

documentation

README

Penguin App

Penguin app is an appbuilder and abstraction layer for looping applications built on winit, legion ecs and fern logger. It also adds a bevy-like plugin implementation to legion.

The package also includes an optional feature adding a time resource plugin, enabling easy access to deltatime.

Dependencies

Cargo.toml

[dependencies]
penguin-application = { version = "0.1" }
penguin-config = { version = "0.1" }

Configuration

Create an app-config.json file like this and put in your project root directory. Available logger levels are ["error", "warning", "info", "debug", "trace"] in decending order of importance.

app-config.json

{
  "logger_config": {
    "output_path": "logs/output.log",
    "debug_message_severity": "debug"
  },
  "window_config": {
    "width": 640,
    "height": 400
  }
}

Usage

Log

Log messages are generated with the standard log function calls, such as log::error!("message").

App

use penguin_config::PenguinConfig;
use penguin_app::{App, config::AppConfig};

fn main() {
    App::builder(AppConfig::read_config())
        .add_plugin(penguin_app::time_plugin::TimePlugin)
        .run()
        .unwrap();
}

Plugin

use penguin_app::ecs::*;
use penguin_app::time_plugin::Time;


pub struct MeasureTimePlugin;

impl Plugin for MeasureTimePlugin {
    fn startup(&mut self, resources: &mut Resources) -> Vec<Step> {
        resources.insert(PassedTimeResource::default());
        vec![]
    }

    fn run() -> Vec<Step> {
        Schedule::builder()
            .add_system(measure_time_system())
            .build()
            .into_vec()
    }

    fn shutdown() -> Vec<Step> {
        vec![] 
    }
}


#[derive(Default)]
struct PassedTimeResource(f32);

#[system]
fn measure_time(#[resource] passed_time: &mut PassedTimeResource, #[resource] time: &Time) {
    passed_time.0 += time.delta();
    log::info!("Time passed: {}", passed_time.0);
}
Commit count: 14

cargo fmt