ggez | Rust library to create a Good Game Easily | Game Engine library

 by   ggez Rust Version: 0.8.1 License: MIT

kandi X-RAY | ggez Summary

ggez is a Rust library typically used in Gaming, Game Engine applications. ggez has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc1. This is a RELEASE CANDIDATE version, which means that the API should be stable but there are still known bugs to address. See the release milestone on the issue tracker for details. More specifically, ggez is a lightweight cross-platform game framework for making 2D games with minimum friction. It aims to implement an API based on (a Rustified version of) the LÖVE game framework. This means it contains basic and portable 2D drawing, sound, resource loading and event handling, but finer details and performance characteristics may be different than LÖVE. ggez is not meant to be everything to everyone, but rather a good base upon which to build. Thus it takes a fairly batteries-included approach without needing a million additions and plugins for everything imaginable, but also does not dictate higher-level functionality such as physics engine or entity component system. Instead the goal is to allow you to use whichever libraries you want to provide these functions, or build your own libraries atop ggez.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        ggez has a medium active ecosystem.
                        summary
                        It has 3680 star(s) with 410 fork(s). There are 48 watchers for this library.
                        summary
                        There were 3 major release(s) in the last 6 months.
                        summary
                        There are 64 open issues and 647 have been closed. On average issues are closed in 185 days. There are 6 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of ggez is 0.8.1
                        ggez Support
                          Best in #Game Engine
                            Average in #Game Engine
                            ggez Support
                              Best in #Game Engine
                                Average in #Game Engine

                                  kandi-Quality Quality

                                    summary
                                    ggez has 0 bugs and 0 code smells.
                                    ggez Quality
                                      Best in #Game Engine
                                        Average in #Game Engine
                                        ggez Quality
                                          Best in #Game Engine
                                            Average in #Game Engine

                                              kandi-Security Security

                                                summary
                                                ggez has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                ggez code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                ggez Security
                                                  Best in #Game Engine
                                                    Average in #Game Engine
                                                    ggez Security
                                                      Best in #Game Engine
                                                        Average in #Game Engine

                                                          kandi-License License

                                                            summary
                                                            ggez is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            ggez License
                                                              Best in #Game Engine
                                                                Average in #Game Engine
                                                                ggez License
                                                                  Best in #Game Engine
                                                                    Average in #Game Engine

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        ggez releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions, examples and code snippets are available.
                                                                        ggez Reuse
                                                                          Best in #Game Engine
                                                                            Average in #Game Engine
                                                                            ggez Reuse
                                                                              Best in #Game Engine
                                                                                Average in #Game Engine
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  ggez Key Features

                                                                                  Filesystem abstraction that lets you load resources from folders or zip files
                                                                                  Hardware-accelerated 2D rendering built on the gfx-rs graphics engine
                                                                                  Loading and playing .ogg, .wav and .flac files via the rodio crate
                                                                                  TTF font rendering with rusttype and glyph_brush.
                                                                                  Interface for handling keyboard and mouse events easily through callbacks
                                                                                  Config file for defining engine and game settings
                                                                                  Easy timing and FPS measurement functions.
                                                                                  Math library integration with mint.
                                                                                  Some more advanced graphics options: shaders, sprite batches and render targets

                                                                                  ggez Examples and Code Snippets

                                                                                  No Code Snippets are available at this moment for ggez.
                                                                                  Community Discussions

                                                                                  Trending Discussions on ggez

                                                                                  Sending which enum variant to for a macro to construct
                                                                                  chevron right
                                                                                  Rust: Visibility of struct after refactoring now public; cannot add main to pub (in crate::main)
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  Sending which enum variant to for a macro to construct
                                                                                  Asked 2021-Feb-15 at 16:26

                                                                                  Currently, I'm working on a project where I use several crates that return different errors. I'm trying to not use unwrap on a result but instead passing the error upwards using the question mark syntax. To be able to do this I created my own error enum that has variants for the different types of errors from the different crates I'm using and then use map_err to map the errors to my error enum. I also decided that I should add the line and file where I remapped the error so I could see where I encountered the error.

                                                                                  My error enum
                                                                                  #[derive(Debug, Clone)]
                                                                                  pub enum Error {
                                                                                      GameError(ggez::GameError, String),
                                                                                      RonError(ron::error::Error, String),
                                                                                  }
                                                                                  
                                                                                  Example of mapping an error
                                                                                  let rdr = filesystem::open(ctx, gen_conf_path)
                                                                                      .map_err(|e| {
                                                                                      Error::GameError(e, format!("at line {} in {}", line!(), file!()))
                                                                                      })?;
                                                                                  

                                                                                  The problem with that is that the closure I need to send to map_err becomes quite long and is essentially the same every time except for the enum variant I'm mapping to. So I want to create a macro that generates the closure for the correct enum variant. So i could write something like the following.

                                                                                  let rdr = filesystem::open(ctx, gen_conf_path).map_err(map_to!(Error::GameError))?
                                                                                  

                                                                                  And the map_to! macro would generate the code i had before.
                                                                                  Is this possible? Can I send an enum variant to a macro and let it construct it or should I do this in a completely different way?

                                                                                  ANSWER

                                                                                  Answered 2021-Feb-15 at 09:56

                                                                                  An interesting implementation detail about enum variants, is that the initializers are actually functions.

                                                                                  We have another useful pattern that exploits an implementation detail of tuple structs and tuple-struct enum variants. These types use () as initializer syntax, which looks like a function call. The initializers are actually implemented as functions returning an instance that’s constructed from their arguments. We can use these initializer functions as function pointers that implement the closure traits, which means we can specify the initializer functions as arguments for methods that take closures

                                                                                  Advanced Functions and Closures - The Rust Programming Language

                                                                                  This means, that if you had an enum FooBar, which had a variant Foo(i32, i32), then you could use and pass FooBar::Foo as a Fn(i32, i32) -> FooBar.

                                                                                  enum FooBar {
                                                                                      Foo(i32, i32),
                                                                                      Bar(String),
                                                                                  }
                                                                                  
                                                                                  fn foo(f: fn(i32, i32) -> FooBar) -> FooBar {
                                                                                      f(1, 2)
                                                                                  }
                                                                                  
                                                                                  fn bar(f: F) -> FooBar
                                                                                  where
                                                                                      F: Fn(i32, i32) -> FooBar,
                                                                                  {
                                                                                      f(1, 2)
                                                                                  }
                                                                                  
                                                                                  fn main() {
                                                                                      foo(FooBar::Foo);
                                                                                      bar(FooBar::Foo);
                                                                                  }
                                                                                  

                                                                                  Thus if you think of your enum variant as function, then your macro becomes quite simple:

                                                                                  macro_rules! map_to {
                                                                                      ($f:expr) => {
                                                                                          |e| {
                                                                                              $f(e, format!("at line {} in {}", line!(), file!()))
                                                                                          }
                                                                                      };
                                                                                  }
                                                                                  

                                                                                  This is of course assuming that e is always the valid type, in relation to the enum variant used in relation to map_to.

                                                                                  Source https://stackoverflow.com/questions/66205516

                                                                                  QUESTION

                                                                                  Rust: Visibility of struct after refactoring now public; cannot add main to pub (in crate::main)
                                                                                  Asked 2020-Jun-27 at 10:55

                                                                                  I am rather new to rust, so the following might also be a misunderstanding of a concept: I took the ggez basic project template from the basic project template which looks like this:

                                                                                  use ggez::{graphics, Context, ContextBuilder, GameResult};
                                                                                  use ggez::event::{self, EventHandler};
                                                                                  
                                                                                  fn main() {
                                                                                      // Make a Context.
                                                                                      let (mut ctx, mut event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
                                                                                          .build()
                                                                                          .expect("aieee, could not create ggez context!");
                                                                                  
                                                                                      // Create an instance of your event handler.
                                                                                      // Usually, you should provide it with the Context object to
                                                                                      // use when setting your game up.
                                                                                      let mut my_game = MyGame::new(&mut ctx);
                                                                                  
                                                                                      // Run!
                                                                                      match event::run(&mut ctx, &mut event_loop, &mut my_game) {
                                                                                          Ok(_) => println!("Exited cleanly."),
                                                                                          Err(e) => println!("Error occured: {}", e)
                                                                                      }
                                                                                  }
                                                                                  
                                                                                  struct MyGame {
                                                                                      // Your state here...
                                                                                  }
                                                                                  
                                                                                  impl MyGame {
                                                                                      pub fn new(_ctx: &mut Context) -> MyGame {
                                                                                          // Load/create resources such as images here.
                                                                                          MyGame {
                                                                                              // ...
                                                                                          }
                                                                                      }
                                                                                  }
                                                                                  
                                                                                  impl EventHandler for MyGame {
                                                                                      fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
                                                                                          // Update code here...
                                                                                          Ok(())
                                                                                      }
                                                                                  
                                                                                      fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
                                                                                          graphics::clear(ctx, graphics::WHITE);
                                                                                          // Draw code here...
                                                                                          graphics::present(ctx)
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  And refactored it into two files main.rs and game.rs The first just contained the main() function, everything else goes into game.rs.

                                                                                  After changing the import in main.rs to

                                                                                  mod game;
                                                                                  
                                                                                  use game::MyGame;
                                                                                  use ggez::{graphics, Context, ContextBuilder, GameResult};
                                                                                  use ggez::event::{self, EventHandler};
                                                                                  

                                                                                  and adding this to game.rs

                                                                                  use ggez::event::EventHandler;
                                                                                  use ggez::{Context, GameResult, graphics};
                                                                                  

                                                                                  everything works provided I make MyGame public.

                                                                                  However, now the refactoring is making a huge change, as MyGame had been private before. I tried several approaches with pub (in infinite_runner::main) and similar, like crate::main but none was accepted with various error messages.

                                                                                  Now my question is, is there a way of exposing MyGame to main.rs without exposing it to anyone else? It seems like main is not a valid target.

                                                                                  ANSWER

                                                                                  Answered 2020-Jun-27 at 10:55

                                                                                  I managed to figure it out, by reiterating through the rust documentation. Although it feels a little fishy to answer my own question it might actually be helpful for others:

                                                                                  TLDR; We want the code inside the main function to have access to MyGame but any other module outside denied access.

                                                                                  Can it be done with factoring out the code to game.rs: No.

                                                                                  Can it be done at all: Yes.

                                                                                  Here is why and how:

                                                                                  From the rust documentation Visibility and Privacy:

                                                                                  With the notion of an item being either public or private, Rust allows item accesses in two cases:

                                                                                  1. If an item is public, then it can be accessed externally from some module m if you can access all the item's parent modules from m. You can also potentially be able to name the item through re-exports. See below.
                                                                                  2. If an item is private, it may be accessed by the current module and its descendants.

                                                                                  This means I cannot factor out horizontally and expect to limit horizontally at the same time. Since the main.rs is on the top level anything on the same level that is public is accessible to the whole crate as any other module since every module can access the parent of the top level. Therefore the answer for refactoring to the same level into a file (module) is: No.

                                                                                  On a side note, if I had factored out the code into a file called lib.rs then the only difference would have been the path, as lib.rs on the top level is implicitly just the crate path, while in a file called game.rs the path would be crate::game.

                                                                                  But the same behavior as the single file can be done by factoring out vertically. We create a directory called game and move game.rs inside this directory and add the pub keyword to MyGame: pub struct MyGame. Similar to the python __init__.py file rust needs a file mod.rs to make the directory a module. Inside the mod.rs you declare the files you have inside, mod game in our case. Now we could address MyGame by the path crate::game::game::MyGame, however since game.rs is declared private the access to MyGame is sealed, as all elements of the path have to be public. However, since MyGame is declared public, any module on the same level has access to it. We cannot move the main.rs into the game directory but we can factor the code inside it into another function. Let's call it init for lack of fantasy. We put the init function inside a file called init.rs inside the game directory and declare it public inside mod.rs like so: pub mod init. Now we can call game::init::init() because it is public, but not game::game::MyGame. Init however, has access to MyGame.

                                                                                  The final structure looks like this:

                                                                                  src
                                                                                  |---main.rs
                                                                                  |---game
                                                                                      |---mod.rs
                                                                                      |---game.rs
                                                                                      |---init.rs
                                                                                  

                                                                                  main.rs:

                                                                                  mod game;
                                                                                  use game::init;
                                                                                  
                                                                                  fn main() {
                                                                                      init::init();
                                                                                  }
                                                                                  

                                                                                  mod.rs:

                                                                                  pub mod init;
                                                                                  mod game;
                                                                                  

                                                                                  game.rs:

                                                                                  use ggez::event::EventHandler;
                                                                                  use ggez::{graphics, Context, GameResult};
                                                                                  
                                                                                  pub struct MyGame {
                                                                                      // Your state here...
                                                                                  }
                                                                                  
                                                                                  impl MyGame {
                                                                                      pub fn new(_ctx: &mut Context) -> MyGame {
                                                                                          // Load/create resources such as images here.
                                                                                          MyGame {
                                                                                              // ...
                                                                                          }
                                                                                      }
                                                                                  }
                                                                                  
                                                                                  impl EventHandler for MyGame {
                                                                                      fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
                                                                                          // Update code here...
                                                                                          Ok(())
                                                                                      }
                                                                                  
                                                                                      fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
                                                                                          graphics::clear(ctx, graphics::WHITE);
                                                                                          // Draw code here...
                                                                                          graphics::present(ctx)
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  init.rs:

                                                                                  use crate::game::game::MyGame;
                                                                                  use ggez::{ContextBuilder, event};
                                                                                  
                                                                                  pub fn init() {
                                                                                  // Make a Context.
                                                                                      let (mut ctx, mut event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
                                                                                          .build()
                                                                                          .expect("aieee, could not create ggez context!");
                                                                                  
                                                                                  // Create an instance of your event handler.
                                                                                  // Usually, you should provide it with the Context object to
                                                                                  // use when setting your game up.
                                                                                      let mut my_game = MyGame::new(&mut ctx);
                                                                                  
                                                                                  // Run!
                                                                                      match event::run(&mut ctx, &mut event_loop, &mut my_game) {
                                                                                          Ok(_) => println!("Exited cleanly."),
                                                                                          Err(e) => println!("Error occured: {}", e),
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/62603528

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install ggez

                                                                                  For a quick tutorial on ggez, see the Hello ggez guide in the docs/ directory.

                                                                                  Support

                                                                                  For details, see docs/BuildingForEveryPlatform.md.
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/ggez/ggez.git

                                                                                • CLI

                                                                                  gh repo clone ggez/ggez

                                                                                • sshUrl

                                                                                  git@github.com:ggez/ggez.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Reuse Pre-built Kits with ggez

                                                                                  Consider Popular Game Engine Libraries

                                                                                  godot

                                                                                  by godotengine

                                                                                  phaser

                                                                                  by photonstorm

                                                                                  libgdx

                                                                                  by libgdx

                                                                                  aseprite

                                                                                  by aseprite

                                                                                  Babylon.js

                                                                                  by BabylonJS

                                                                                  Try Top Libraries by ggez

                                                                                  good-web-game

                                                                                  by ggezRust

                                                                                  game-template

                                                                                  by ggezRust

                                                                                  ggez-goodies

                                                                                  by ggezRust

                                                                                  aseprite

                                                                                  by ggezRust

                                                                                  ggraphics

                                                                                  by ggezRust

                                                                                  Compare Game Engine Libraries with Highest Support

                                                                                  godot

                                                                                  by godotengine

                                                                                  Cataclysm-DDA

                                                                                  by CleverRaven

                                                                                  libgdx

                                                                                  by libgdx

                                                                                  phaser

                                                                                  by photonstorm

                                                                                  Mindustry

                                                                                  by Anuken

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit