diff --git a/code/source-c/blocks.c b/code/source-c/blocks.c new file mode 100644 index 0000000..1a6442c --- /dev/null +++ b/code/source-c/blocks.c @@ -0,0 +1,50 @@ +#include "blocks.h" +#include "state.h" + +#include + +tc_block_entry_s tc_new_block_entry(char *name) +{ + tc_block_entry_s entry; + entry.name = name; + entry.attributes_capacity = 16; + entry.num_attributes = 0; + entry.attributes = calloc(sizeof(tc_block_attribute_s), entry.attributes_capacity); + + return entry; +} + +void tc_add_attribute_to_block(tc_block_entry_s *entry, tc_block_attribute_s attribute) +{ + if(entry->num_attributes >= entry->attributes_capacity) + { + entry->attributes_capacity *= 2; + entry->attributes = + realloc(entry->attributes, sizeof(tc_block_attribute_s) * entry->attributes_capacity); + } + + entry->attributes[entry->num_attributes] = attribute; +} + +tc_block_entry_s * tc_get_block(char *name) +{ + uint32_t index = 0; + while(index < tc_game_state_g.block_registry.num_blocks) + { + if(!strcmp(tc_game_state_g.block_registry.blocks[index].name, name)) + return &tc_game_state_g.block_registry.blocks[index]; + + ++index; + } + return NULL; +} + +tc_block_registry_s tc_init_blocks() +{ + tc_block_registry_s registry; + registry.blocks_capacity = 256; + registry.blocks = calloc(sizeof(tc_block_entry_s), registry.blocks_capacity); + + return registry; +} + diff --git a/code/source-c/blocks.h b/code/source-c/blocks.h new file mode 100644 index 0000000..4b1e309 --- /dev/null +++ b/code/source-c/blocks.h @@ -0,0 +1,46 @@ + +#ifndef TC_BLOCK_H +#define TC_BLOCK_H + +#include +#include + +#include + +typedef struct tc_block_attribute +{ + uint32_t len_name; + uint32_t len_content; + + char *name; + void *content; + +} tc_block_attribute_s; + +typedef struct tc_block_entry +{ + char *name; + + uint32_t attributes_capacity; + uint32_t num_attributes; + tc_block_attribute_s *attributes; + +} tc_block_entry_s; + +typedef struct tc_block_registry +{ + uint32_t blocks_capacity; + uint32_t num_blocks; + tc_block_entry_s *blocks; + +} tc_block_registry_s; + +tc_block_entry_s tc_new_block_entry (char *name); +void tc_add_attribute_to_block + (tc_block_entry_s *entry, tc_block_attribute_s attribute); +tc_block_entry_s * tc_get_block (char *name); + +tc_block_registry_s tc_init_blocks (); + +#endif + diff --git a/code/source-c/main.c b/code/source-c/main.c index 855f92b..954b2ea 100644 --- a/code/source-c/main.c +++ b/code/source-c/main.c @@ -258,15 +258,10 @@ bool update() return true; } -void flushput(const char *message) -{ - puts(message); - fflush(stdout); -} - int main(int argc, char **argv) { - tc_game_state_g = tc_init(); + tc_game_state_g = tc_init(); + tc_game_state_g.block_registry = tc_init_blocks(); block = tc_new_block_at_3f(0.0, 0.0, 0.0); diff --git a/code/source-c/state.h b/code/source-c/state.h index 5f0e61f..a58f801 100644 --- a/code/source-c/state.h +++ b/code/source-c/state.h @@ -7,6 +7,7 @@ #include #include "shaders.h" +#include "blocks.h" typedef struct tc_vec3 { @@ -53,6 +54,7 @@ typedef struct tc_renderer typedef struct { tc_renderer_s renderer; + tc_block_registry_s block_registry; } techneck_s;