https://github.com/justinmeiners/c-game-debug-console
Quake style debug console for games. Written in ANSI C.
https://github.com/justinmeiners/c-game-debug-console
c game
Last synced: over 1 year ago
JSON representation
Quake style debug console for games. Written in ANSI C.
- Host: GitHub
- URL: https://github.com/justinmeiners/c-game-debug-console
- Owner: justinmeiners
- Created: 2013-06-20T21:45:31.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-07-09T04:07:12.000Z (almost 13 years ago)
- Last Synced: 2023-04-05T16:26:26.151Z (about 3 years ago)
- Topics: c, game
- Language: C
- Homepage:
- Size: 160 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
C Game Debug Console
====================
A Quake style debug console for games.
* **Portable** - ANSI C + Standard Library
* **Easy Integration** - A single header and source file for the console, and one for the default library.
* **Clean** - Well designed interface with opaque data structures.
* **Simple** - Simple design and featureset. Easily add new commands and variables. If more complexity is needed (arrays, returns, complex expressions etc.) a complete scripting language may be more appropriate. Check out [lua](http://lua.org) instead.
* **Persitent** - Save and load and console states.
### Integration: ###
```C
#include "Console.h"
#include "ConsoleStdLib.h"
/* create console with output file */
ConsoleRef console = Console_Create(stdout);
/* register standard library (optional) */
ConsoleStdLib_Register(console);
/* execute functions */
Console_Execute(...)
Console_Execute(...)
....
/* shutdown */
Console_Destroy(console);
```
### Usage: ###
Commands take the simple form of:
```
command_name arg1 arg2 argN...
Example:
set my_var 40
or
set my_var other_var
```
Standard Library:
* **TRUE** - bool 1
* **FALSE** - bool 0
* **echo** - prints the value of a variable
* **inspect** - prints the type of a variable
* **set** - assigns the value of the second argument to the first
### Custom Variables: ###
```C
/* registration */
ConsoleVarRef myVar = Console_RegisterVar(console,
"my_var", /* variable name */
kConsoleVarTypeInt, /* int type */
0); /* flags - readonly, etc (none used) */
...
...
...
/* access outside of console in C code */
/* find handle or use cached */
ConsoleVarRef myVar = Console_FindVar("my_var");
/* get value */
int val = ConsoleVar_IntValue(myVar);
/* assignment */
ConsoleVar_SetIntValue(myVar, 100);
```
### Custom Commands: ###
```C
/* sample command function */
int calculateAverage(ConsoleRef console, ConsoleArgRef args)
{
ConsoleArgRef arg = args;
double total = 0.0;
int count = 0;
/* args is linked list */
while (arg)
{
total += ConsoleVar_DoubleValue(arg->var);
count++;
arg = arg->next;
}
fprintf(Console_Log(console), "%lf\n", total / (double)count);
/* return success */
return 1;
}
/* registration */
Console_RegisterCommand(console,
"avg", /* command name */
calculateAverage, /* function pointer */
-1); /* how many arguments (-1 indicates a variable number) ? */
```