Kohi Game Engine
console.h File Reference

Contains the console system, which disperses all logging to registered consumers as well as handles registered command inputs. More...

#include "defines.h"
#include "logger.h"

Go to the source code of this file.

Data Structures

struct  console_command_argument
 Represents a single console command argument's value. Always represented as a string, it is up to the console command function to interpret and convert it to the required type during processing. More...
 
struct  console_command_context
 Context to be passed along with an executing console command (i.e. arguments to the command). More...
 

Typedefs

typedef b8(* PFN_console_consumer_write) (void *inst, log_level level, const char *message)
 Typedef for a console consumer write function, which is invoked every time a logging event occurs. Consumers must implement this and handle the input thusly. More...
 
typedef struct console_command_argument console_command_argument
 Represents a single console command argument's value. Always represented as a string, it is up to the console command function to interpret and convert it to the required type during processing. More...
 
typedef struct console_command_context console_command_context
 Context to be passed along with an executing console command (i.e. arguments to the command). More...
 
typedef void(* PFN_console_command) (console_command_context context)
 A typedef for a function pointer which represents a registered console command, and is called when triggered by some means of console input (typically a debug console). More...
 

Functions

b8 console_initialize (u64 *memory_requirement, void *memory, void *config)
 Initializes the console system. As with other systems, must be called twice; once to get the memory requirement (where memory = 0), and a second time passing allocated memory. More...
 
void console_shutdown (void *state)
 Shuts down the console system. More...
 
KAPI void console_consumer_register (void *inst, PFN_console_consumer_write callback, u8 *out_consumer_id)
 Registers a console consumer with the console system. More...
 
KAPI void console_consumer_update (u8 consumer_id, void *inst, PFN_console_consumer_write callback)
 Updates the instance and callback for the consumer with the given identifier. More...
 
void console_write_line (log_level level, const char *message)
 Called internally by the logging system to write a new line to the console. More...
 
KAPI b8 console_command_register (const char *command, u8 arg_count, PFN_console_command func)
 Registers a console command with the console system. More...
 
KAPI b8 console_command_unregister (const char *command)
 Unregisters the given command. More...
 
KAPI b8 console_command_execute (const char *command)
 Executes a console command. More...
 

Detailed Description

Contains the console system, which disperses all logging to registered consumers as well as handles registered command inputs.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2023-01-18

Typedef Documentation

◆ console_command_argument

Represents a single console command argument's value. Always represented as a string, it is up to the console command function to interpret and convert it to the required type during processing.

◆ console_command_context

Context to be passed along with an executing console command (i.e. arguments to the command).

◆ PFN_console_command

typedef void(* PFN_console_command) (console_command_context context)

A typedef for a function pointer which represents a registered console command, and is called when triggered by some means of console input (typically a debug console).

◆ PFN_console_consumer_write

typedef b8(* PFN_console_consumer_write) (void *inst, log_level level, const char *message)

Typedef for a console consumer write function, which is invoked every time a logging event occurs. Consumers must implement this and handle the input thusly.

Function Documentation

◆ console_command_execute()

KAPI b8 console_command_execute ( const char *  command)

Executes a console command.

Parameters
commandThe command, including arguments separated by spaces. ex: "kvar_int_set test_var 4"
Returns
True on success; otherwise false.

◆ console_command_register()

KAPI b8 console_command_register ( const char *  command,
u8  arg_count,
PFN_console_command  func 
)

Registers a console command with the console system.

Parameters
commandThe name of the command.
arg_countThe number of required arguments.
funcThe function pointer to be invoked.
Returns
True on success; otherwise false.

◆ console_command_unregister()

KAPI b8 console_command_unregister ( const char *  command)

Unregisters the given command.

Parameters
commandThe name of the command to be unregistered.
Returns
True on success; otherwise false.

◆ console_consumer_register()

KAPI void console_consumer_register ( void *  inst,
PFN_console_consumer_write  callback,
u8 out_consumer_id 
)

Registers a console consumer with the console system.

Parameters
instInstance information to pass along with the consumer.
callbackThe callback to be made on console write.

◆ console_consumer_update()

KAPI void console_consumer_update ( u8  consumer_id,
void *  inst,
PFN_console_consumer_write  callback 
)

Updates the instance and callback for the consumer with the given identifier.

Parameters
consumer_idThe identifier of the consumer to update.
instThe consumer instance.
callbackThe new callback function.

◆ console_initialize()

b8 console_initialize ( u64 memory_requirement,
void *  memory,
void *  config 
)

Initializes the console system. As with other systems, must be called twice; once to get the memory requirement (where memory = 0), and a second time passing allocated memory.

Parameters
memory_requirementA pointer to hold the memory requirement.
memoryThe allocated memory for this system's state.
configIgnored.
Returns
True on success; otherwise false.

◆ console_shutdown()

void console_shutdown ( void *  state)

Shuts down the console system.

Parameters
stateA pointer to the console system state.

◆ console_write_line()

void console_write_line ( log_level  level,
const char *  message 
)

Called internally by the logging system to write a new line to the console.

Parameters
levelThe logging level.
messageThe message to be written.