Kohi Game Engine
kvar.h File Reference

A file that contains the KVar system. KVars are global variables that are dynamically created and set/used within the engine and/or application, and are accessible from anywhere. More...

#include "defines.h"

Go to the source code of this file.

Data Structures

union  kvar_value
 
struct  kvar_change
 

Typedefs

typedef enum kvar_types kvar_types
 
typedef union kvar_value kvar_value
 
typedef struct kvar_change kvar_change
 

Enumerations

enum  kvar_types { KVAR_TYPE_INT , KVAR_TYPE_FLOAT , KVAR_TYPE_STRING }
 

Functions

b8 kvar_system_initialize (u64 *memory_requirement, struct kvar_state *memory, void *config)
 Initializes the KVar system. KVars are global variables that are dynamically created and set/used within the engine and/or application, and are accessible from anywhere. Like any other system, this should be called twice, once to obtain the memory requirement (where memory = 0), and a second time with an allocated block of memory. More...
 
void kvar_system_shutdown (struct kvar_state *state)
 Shuts down the KVar system. More...
 
KAPI b8 kvar_i32_get (const char *name, i32 *out_value)
 Attempts to obtain a variable value with the given name and return its value as an integer. Also attempts conversion if the variable is a type other than int, but this conversion can fail. More...
 
KAPI b8 kvar_i32_set (const char *name, const char *desc, i32 value)
 Attempts to set the value as an integer of an existing variable with the given name. Creates if the variable does not yet exist. More...
 
KAPI b8 kvar_f32_get (const char *name, f32 *out_value)
 Attempts to obtain a variable value with the given name and return its value as a float. Also attempts conversion if the variable is a type other than float, but this conversion can fail. More...
 
KAPI b8 kvar_f32_set (const char *name, const char *desc, f32 value)
 Attempts to set the value as a float of an existing variable with the given name. Creates if the variable does not yet exist. More...
 
KAPI const char * kvar_string_get (const char *name)
 Attempts to obtain a variable value with the given name and return its value as a string. Also attempts conversion if the variable is a type other than string, but this conversion can fail. Return value is dynamically allocated and must be freed by the caller. More...
 
KAPI b8 kvar_string_set (const char *name, const char *desc, const char *value)
 Attempts to set the value as a string of an existing variable with the given name. Creates if the variable does not yet exist. More...
 

Detailed Description

A file that contains the KVar system. KVars are global variables that are dynamically created and set/used within the engine and/or application, and are accessible from anywhere.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
2.0
Date
2024-04-2

Typedef Documentation

◆ kvar_change

typedef struct kvar_change kvar_change

◆ kvar_types

typedef enum kvar_types kvar_types

◆ kvar_value

typedef union kvar_value kvar_value

Enumeration Type Documentation

◆ kvar_types

enum kvar_types
Enumerator
KVAR_TYPE_INT 
KVAR_TYPE_FLOAT 
KVAR_TYPE_STRING 

Function Documentation

◆ kvar_f32_get()

KAPI b8 kvar_f32_get ( const char *  name,
f32 out_value 
)

Attempts to obtain a variable value with the given name and return its value as a float. Also attempts conversion if the variable is a type other than float, but this conversion can fail.

Parameters
nameThe name of the variable.
out_valueA pointer to hold the variable.
Returns
True if the variable was found and the value was successfully converted/returned; otherwise false.

◆ kvar_f32_set()

KAPI b8 kvar_f32_set ( const char *  name,
const char *  desc,
f32  value 
)

Attempts to set the value as a float of an existing variable with the given name. Creates if the variable does not yet exist.

Parameters
nameThe name of the variable.
descriptionDescription of the variable. Optional. If updating existing, description will be overwritten unless 0 is passed.
valueThe value to be set.
Returns
True if found and set, otherwise false.

◆ kvar_i32_get()

KAPI b8 kvar_i32_get ( const char *  name,
i32 out_value 
)

Attempts to obtain a variable value with the given name and return its value as an integer. Also attempts conversion if the variable is a type other than int, but this conversion can fail.

Parameters
nameThe name of the variable.
out_valueA pointer to hold the variable.
Returns
True if the variable was found and the value was successfully converted/returned; otherwise false.

◆ kvar_i32_set()

KAPI b8 kvar_i32_set ( const char *  name,
const char *  desc,
i32  value 
)

Attempts to set the value as an integer of an existing variable with the given name. Creates if the variable does not yet exist.

Parameters
nameThe name of the variable.
descriptionDescription of the variable. Optional. If updating existing, description will be overwritten unless 0 is passed.
valueThe value to be set.
Returns
True if found and set, otherwise false.

◆ kvar_string_get()

KAPI const char* kvar_string_get ( const char *  name)

Attempts to obtain a variable value with the given name and return its value as a string. Also attempts conversion if the variable is a type other than string, but this conversion can fail. Return value is dynamically allocated and must be freed by the caller.

Parameters
nameThe name of the variable.
Returns
A copy of the value as a string, or 0 if the operation fails. Must be freed by the caller.

◆ kvar_string_set()

KAPI b8 kvar_string_set ( const char *  name,
const char *  desc,
const char *  value 
)

Attempts to set the value as a string of an existing variable with the given name. Creates if the variable does not yet exist.

Parameters
nameThe name of the variable.
descriptionDescription of the variable. Optional. If updating existing, description will be overwritten unless 0 is passed.
valueThe value to be set.
Returns
True if found and set, otherwise false.

◆ kvar_system_initialize()

b8 kvar_system_initialize ( u64 memory_requirement,
struct kvar_state *  memory,
void *  config 
)

Initializes the KVar system. KVars are global variables that are dynamically created and set/used within the engine and/or application, and are accessible from anywhere. Like any other system, this should be called twice, once to obtain the memory requirement (where memory = 0), and a second time with an allocated block of memory.

Parameters
memory_requirementA pointer to hold the memory requirement for this system.
memoryAn allocated block of memory the size of memory_requirement.
configA pointer to config, if required.
Returns
b8 True on success; otherwise false.

◆ kvar_system_shutdown()

void kvar_system_shutdown ( struct kvar_state *  state)

Shuts down the KVar system.

Parameters
stateThe system state.