51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
#include "blocks.h"
|
|
#include "state.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
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;
|
|
}
|
|
|