Giter Club home page Giter Club logo

noclip's Introduction

noclip

Many computer games have a developer console or in-game console which provide a command-line interface for executing commands, changing game variables, or activating cheats. It's a very useful feature seen in many games like Quake (see screenshot below), Skyrim, Minecraft, and Counter-Strike.

noclip.h is a single-header library providing a very flexible and easy-to-use backend for building such consoles. By using lambdas and templates, the library elegantly implements a sophisticated backend in very few lines of code (~400 LOC). It also has a dead simple interface.

Quake Console Screenshot

Executing Commands

When you want to run a command (e.g. when the user presses enter), call console.execute(input, output). The input contains the command you want to execute. It can be a std::string or any istream such as std::cin.

Binding Commands

The purpose of console commands is to be able to execute compiled C++ functions from the console. To enable this, you bind C++ functions to the console during the runtime of your program/game.

void set_cheats(int mode) { ... }
...
console.bind_cmd("sv_cheats", set_cheats);
console.execute("sv_cheats 1", std::cout); // once executed, calls set_cheats with mode 1

Console Variables

You can expose variables of your program to the console by binding them. Once bound, you can set and get their values.

int hp = 100;
console.bind_cvar("health", &hp);
console.execute("set health 99", std::cout); // once executed, hp becomes 99

set <variable-name> <value> is a built-in command for mutating console variable values. Execute command help to see what other built-in commands there are.

Creating the Console

#include "noclip.h"
noclip::console c; // there is no custom constructor

More documentation is included directly in the header file.

noclip's People

Contributors

kevinmkchin avatar

Watchers

 avatar

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.