Giter VIP home page Giter VIP logo

cvars's Introduction

Evening ๐Ÿ‘‹

I like code that's correct, fast and readable. I'd say "in that order" but that would imply one can't have all three.

Games

As you might have noticed, I am a fan of Rust. I also write games in it:

  • RecWars is a free and open source clone of RecWar, a 2D multiplayer tank shooter - 3 vehicle types, 8 weapons, 3 game modes and lots of maps. Still very WIP, but playable. Has a browser version.

    RecWars originally started as a small project to evaluate Rust for gamedev before moving onto a 3D game. Well, turns out everything in Rust is still a bit immature so it's taking way longer than planned. Also kinda because I rewrote the whole thing several times as a "learning experience". But I am getting there, just one more redesign and maybe one more engine switch and everything's gonna be perfect.

  • RustCycles is a fast-paced first-person multiplayer shooter. Except you're not a boring old guy walking around, you're driving a motorbike, you can't stop and you can't go in circles because you're leaving a force-field wall behind yourself. So you better come up with a plan fast before you crash. And you better think clearly under fire because other people are gonna be shooting at you. Know Tron? That, with guns.

    Currently RustCycles is a very early proof of concept developed in parallel with RecWars - both games share a lot of the architecture even though they use different engines.

Cvars

If you also write games, consider my library, cvars. It's a Rust implementation of how games have been storing and managing configs since Quake 1 - tested and proven to work so well that it's still used in Half-Life: Alyx.

The secret? A proc macrto to generate a simple statically typed struct with string accessors. Includes in-game consoles for Macroquad and Fyrox.

Macroquad console

Fyrox console

cvars's People

Contributors

dependabot[bot] avatar martin-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cvars's Issues

Attribute for skipping a field?

I've got some structs with fields that must not be changed (would cause crashing and/or freezing), but would like to keep the remaining fields configurable...

Would it be possible to add something like a #[cvars(skip)] attribute, similar to #[serde(skip)]? Maybe check for the latter too?

Compile times

Switch to a hashmap or trie for storing the strings, the generated match is huge:

cargo llvm-lines:

  Lines          Copies       Function name
  -----          ------       -------------
  119771 (100%)  4182 (100%)  (TOTAL)
   30067 (25.1%)    1 (0.0%)  rec_wars::cvars::Cvars::set_str
    5892 (4.9%)     1 (0.0%)  rec_wars::cvars::Cvars::get_string
    3083 (2.6%)     1 (0.0%)  rec_wars::rendering::render_viewport

and render_viewport is a huge 700 line function.

Maybe llvm lines are not the best metric but it absolutely does add a lot to compile times (test with SetGetDummy)

Compare perf with alternatives

Compare normal access in gamecode and stringly-typed access when the user is accessing the config. Small and large amount of cvars.

Aliases

Aliases would allow users to save typing and one cvar could have multiple names for users coming from different engines used to different names.

Try it out link

When RecWars console works sanely or RustCycles supports WASM, add a heading "Try it out" right before usage that explains how to open the console and which cvars to try changing. Maybe reduce number of bots?

Integer ID's?

Would it be possible to have a pair of set_var and get_var-functions that use an integer-index (parallel to str), obtainable by some get_idx function? Maybe also have a macro that can resolve this at compile-time?

This could be implemented by wrapping the memory-offset (using https://crates.io/crates/memoffset ?) in a CvarHandle<T> {offset: u16} struct with an impl PartialEq, where T is the source-type... thus never exposing the actual offset to the library user.

Feature: Commands

  • Built-in - help, cvarlist, search/find/apropos, cmdlist ...
  • User-defined - just call a hook function and that returns true if handled? Would be nice to be a bit more declarative so they can be listed in help/cmdlist. Avoid making it overcomplicated - define_command function that takes the help message and the hook?

no_std compatibility

There are almost no allocations, might be worth seeing if it's possible to make it no_std compatible.

Would have to conditionally remove get_string since String allocates.

Add support for `pub(crate)`

Currently we hardcode pub in the generated code, which means making the Cvars struct pub(crate) gives an error about leaking a less visible type in a public interface.

CI

Check for:

  • dead links
  • FIXMEs
  • typos?

Feature: Nested structs

  • cvars_structs! {} to allow defining whole structs that contain each other
  • Useful for configuring multiple weapons/vehicles/items/etc that have the same fields - rec-wars does it manually atm.

Console features

  • Tab - autocompletion if unambiguous, print possibilities if ambiguous
  • Write text, up arrow -> search history only for items starting with the text
    • Pg up/down still walks history normally (like zsh)
  • cvarlist
  • find/search/apropos with multiple words - search for those words appearing in any order
  • If starting with space, don't save to history
  • History to file
  • CTRL+R - fuzzy search in history - possible to use fzf or alternative (atuin/skim)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.