Compare commits
No commits in common. "6538b038e7ff61e0ee8051a4a7dd11f3d4d408e4" and "3a38d8341b4aaba3c5a4107447ec56e6e414b754" have entirely different histories.
6538b038e7
...
3a38d8341b
|
@ -31,8 +31,7 @@ function build_dependencies {
|
|||
|
||||
cd .build/depends/libRR/Core/
|
||||
bash build.bash release
|
||||
cp .build/librr-core.a "$REPOSITORY_FOLDER/.build/"
|
||||
cp .build/librr-platform.a "$REPOSITORY_FOLDER/.build/"
|
||||
cp .build/libRR-Core.a "$REPOSITORY_FOLDER/.build/"
|
||||
|
||||
cd "$REPOSITORY_FOLDER"
|
||||
}
|
||||
|
@ -60,7 +59,7 @@ function compile_module_c_sources {
|
|||
echo $INCLUDE_STATEMENTS
|
||||
|
||||
MODULE_SOURCE_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/src-c/"
|
||||
MODULE_OBJECTS_FOLDER="$MAIN_OBJECTS_FOLDER/$MODULE_NAME/"
|
||||
MODULE_OBJECTS_FOLDER="$REPOSITORY_FOLDER/$MAIN_OBJECTS_FOLDER/$MODULE_NAME/"
|
||||
mkdir -p $MODULE_OBJECTS_FOLDER
|
||||
|
||||
# Loop through all files in the 'src-c'-folder and hand them over to GCC
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd $(dirname "$(pwd)/$0")
|
||||
REPOSITORY_FOLDER=$(pwd)
|
||||
|
||||
MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects/"
|
||||
DEFAULT_LINKAGE_PATHS="
|
||||
$REPOSITORY_FOLDER/.build/maintree-core.a
|
||||
$REPOSITORY_FOLDER/.build/librr-core.a
|
||||
$REPOSITORY_FOLDER/.build/librr-platform.a
|
||||
"
|
||||
|
||||
function get_include_path_configuration() {
|
||||
TEST_PATH=$1
|
||||
|
||||
INCLUDE_CONFIG_PATH="$TEST_PATH/include_paths.txt"
|
||||
INCLUDE_STATEMENTS="-I $TEST_PATH/inc-c/"
|
||||
if [[ ! -f $INCLUDE_CONFIG_PATH ]]
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
for LINE in $(cat $INCLUDE_CONFIG_PATH)
|
||||
do
|
||||
INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE"
|
||||
done
|
||||
}
|
||||
|
||||
function get_linkage_path_configuration() {
|
||||
TEST_PATH=$1
|
||||
|
||||
LINKAGE_PATHS=$DEFAULT_LINKAGE_PATHS
|
||||
if [[ -f "$TEST_PATH/linkage_paths.txt" ]]
|
||||
then
|
||||
for LINKAGE_ITEM in $(cat "$TEST_PATH/linkage_paths.txt")
|
||||
do
|
||||
LINKAGE_PATHS="$LINKAGE_PATHS $REPOSITORY_FOLDER/$LINKAGE_ITEM"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function compile_single_test() {
|
||||
TEST_PATH=$1
|
||||
TEST_NAME=$(basename $TEST_PATH)
|
||||
|
||||
echo "Compiling Test: $TEST_NAME"
|
||||
|
||||
# TODO: As a small improvement, the tests could be able to have multiple sub-folders for sources.
|
||||
|
||||
get_include_path_configuration $TEST_PATH
|
||||
get_linkage_path_configuration $TEST_PATH
|
||||
gcc -o $TEST_PATH/$TEST_NAME.elf $TEST_PATH/*.c $LINKAGE_PATHS $INCLUDE_STATEMENTS
|
||||
}
|
||||
|
||||
function compile_all_tests_of_module() {
|
||||
MODULE_NAME=$1
|
||||
|
||||
echo "================================================================"
|
||||
echo "COMPILING ALL TESTS OF MODULE: '$MODULE_NAME'."
|
||||
echo " "
|
||||
|
||||
TEST_PATH_LIST_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/build-config/tests.txt"
|
||||
if [[ ! -f $TEST_PATH_LIST_PATH ]]
|
||||
then
|
||||
echo "Couldn't find list of tests for module '$MODULE_NAME'. Skipping."
|
||||
return
|
||||
fi
|
||||
|
||||
for RELATIVE_TEST_PATH in $(cat $TEST_PATH_LIST_PATH)
|
||||
do
|
||||
TEST_PATH=$REPOSITORY_FOLDER/$MODULE_NAME/$RELATIVE_TEST_PATH
|
||||
compile_single_test $TEST_PATH
|
||||
done
|
||||
}
|
||||
|
||||
compile_all_tests_of_module core
|
|
@ -1,2 +1,3 @@
|
|||
core/exports/
|
||||
.build/depends/libRR/Core/core/exports/
|
||||
.build/depends/libRR/Core/platform/exports/
|
|
@ -43,7 +43,7 @@ void mt_add_create_effector(MtType type, char *effector_name, mt_entity_effector
|
|||
void mt_add_delete_effector(MtType type, char *effector_name, mt_entity_effector_fn function, void *userdata);
|
||||
void mt_add_entity_tick_effector(MtType type, char *effector_name, usz_t ticks_delta, mt_entity_effector_fn function, void *userdata);
|
||||
void mt_add_tick_effector(MtState state, char *effector_name, usz_t ticks_delta, mt_entity_effector_fn function, void *userdata);
|
||||
void mt_remove_effector(MtState state, const char *effector_name);
|
||||
void mt_task_remove_effector(MtState task, const char *effector_name);
|
||||
|
||||
/// @brief Adds a tick effector which only acts upon entitys with certain tags.
|
||||
/// @param type The type for which to add the tick effector.
|
||||
|
@ -61,15 +61,15 @@ void mt_tag_vec2(MtEntity entity, char *name, rr_vec2f_s vector);
|
|||
void mt_tag_vec3(MtEntity entity, char *name, rr_vec2f_s vector);
|
||||
void mt_tag_vec4(MtEntity entity, char *name, rr_vec4f_s vector);
|
||||
|
||||
void mt_untag(MtEntity entity, char *name);
|
||||
i64_t mt_untag_i64(MtEntity entity, char *name);
|
||||
f64_t mt_untag_f64(MtEntity entity, char *name);
|
||||
char * mt_untag_str(MtEntity entity, char *name);
|
||||
void * mt_untag_ptr(MtEntity entity, char *name);
|
||||
rr_vec2f_s mt_untag_vec2(MtEntity entity, char *name);
|
||||
rr_vec3f_s mt_untag_vec3(MtEntity entity, char *name);
|
||||
rr_vec4f_s mt_untag_vec4(MtEntity entity, char *name);
|
||||
|
||||
|
||||
i64_t mt_get_i64_tag(MtEntity entity, char *name);
|
||||
f64_t mt_get_f64_tag(MtEntity entity, char *name);
|
||||
char * mt_get_str_tag(MtEntity entity, char *name);
|
||||
void * mt_get_ptr_tag(MtEntity entity, char *name);
|
||||
rr_vec2f_s mt_get_vec2_tag(MtEntity entity, char *name);
|
||||
rr_vec3f_s mt_get_vec3_tag(MtEntity entity, char *name);
|
||||
rr_vec4f_s mt_get_vec4_tag(MtEntity entity, char *name);
|
||||
|
||||
MtTask mt_create_task(MtState state, MtTaskCreationInfo creation_info);
|
||||
void mt_delete_task(MtTask task);
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
|
||||
#ifndef MT_TAG_REGISTRY_H
|
||||
#define MT_TAG_REGISTRY_H
|
||||
|
||||
#include <librr/types.h>
|
||||
#include <librr/alloc/generic.h>
|
||||
|
||||
typedef struct MtTagRegistry MtTagRegistry;
|
||||
typedef struct MtTagEntry MtTagEntry;
|
||||
typedef struct MtTagCollection MtTagCollection;
|
||||
|
||||
/// @brief Contains an array of every tag's label/name with the identifier,
|
||||
/// meant for resolving one to another. This also is a the head structure
|
||||
/// of a label-to-identifier hash map for quickly inferring an identifier
|
||||
/// from the tag's name.
|
||||
struct MtTagRegistry
|
||||
{
|
||||
void *parent_state;
|
||||
|
||||
u32_t entries_capacity;
|
||||
u32_t num_entries;
|
||||
MtTagEntry *entries;
|
||||
|
||||
u32_t next_identifier;
|
||||
|
||||
u32_t num_collections;
|
||||
MtTagCollection *collections;
|
||||
};
|
||||
|
||||
struct MtTagEntry
|
||||
{
|
||||
u32_t identifier;
|
||||
char *label;
|
||||
};
|
||||
|
||||
struct MtTagCollection
|
||||
{
|
||||
u32_t capacity;
|
||||
u32_t num_tags;
|
||||
|
||||
/// @brief An array of pointers into the tag-registry's 'entries'-array.
|
||||
MtTagEntry **tags;
|
||||
};
|
||||
|
||||
MtTagRegistry mt_create_tag_registry(void *parent_state);
|
||||
void mt_delete_tag_registry(MtTagRegistry registry);
|
||||
|
||||
u32_t mt_get_tag_id(MtTagRegistry *registry, const char *tag_label);
|
||||
const char * mt_get_tag_label(MtTagRegistry *registry, u32_t tag_identifier);
|
||||
|
||||
#endif // MT_TAG_REGISTRY_H
|
|
@ -1,137 +0,0 @@
|
|||
#include <tag_registry.h>
|
||||
#include <librr/strutil.h>
|
||||
#include <librr/memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
MtTagRegistry mt_create_tag_registry(void *parent_state)
|
||||
{
|
||||
MtTagRegistry registry;
|
||||
registry.parent_state = parent_state;
|
||||
registry.num_collections = 256;
|
||||
registry.collections = calloc(sizeof(MtTagCollection), registry.num_collections);
|
||||
registry.next_identifier = 1;
|
||||
registry.entries_capacity = 512;
|
||||
registry.num_entries = 0;
|
||||
registry.entries = calloc(sizeof(MtTagEntry), registry.entries_capacity);
|
||||
return registry;
|
||||
}
|
||||
|
||||
void mt_delete_all_tag_registry_collections(MtTagRegistry registry)
|
||||
{
|
||||
usz_t index = 0;
|
||||
while(index < registry.num_collections)
|
||||
{
|
||||
MtTagCollection collection = registry.collections[index];
|
||||
if(collection.capacity == 0)
|
||||
return;
|
||||
|
||||
free(collection.tags);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
void mt_delete_all_tag_registry_entries(MtTagRegistry registry)
|
||||
{
|
||||
usz_t index = 0;
|
||||
while(index < registry.num_entries)
|
||||
{
|
||||
MtTagEntry entry = registry.entries[index];
|
||||
if(entry.label == NULL)
|
||||
return;
|
||||
free(entry.label);
|
||||
++index;
|
||||
}
|
||||
free(registry.entries);
|
||||
}
|
||||
|
||||
void mt_delete_tag_registry(MtTagRegistry registry)
|
||||
{
|
||||
mt_delete_all_tag_registry_collections(registry);
|
||||
mt_delete_all_tag_registry_entries(registry);
|
||||
}
|
||||
|
||||
|
||||
|
||||
u32_t mt_tag_label_to_hash(const char *tag_label, usz_t range)
|
||||
{
|
||||
usz_t len_tag_label = rr_measure_string(tag_label);
|
||||
if(len_tag_label <= 4)
|
||||
{
|
||||
const u32_t *tag_label_32 = (const void *) tag_label;
|
||||
return tag_label_32[0] % range;
|
||||
}
|
||||
if(len_tag_label <= 8)
|
||||
{
|
||||
u32_t hash = 0;
|
||||
hash |= tag_label[0] << 24;
|
||||
hash |= tag_label[1] << 16;
|
||||
hash |= tag_label[len_tag_label-2] << 8;
|
||||
hash |= tag_label[len_tag_label-1];
|
||||
return hash % range;
|
||||
}
|
||||
|
||||
u32_t hash = 0;
|
||||
usz_t char_index = 0;
|
||||
while(char_index < len_tag_label)
|
||||
{
|
||||
hash ^= tag_label[char_index] << (24 - ((char_index * 6) % 32));
|
||||
++char_index;
|
||||
}
|
||||
return hash % range;
|
||||
}
|
||||
|
||||
MtTagEntry * mt_create_tag_hash_entry(MtTagRegistry *registry, const char *tag_label)
|
||||
{
|
||||
u32_t collection_index = mt_tag_label_to_hash(tag_label, registry->num_collections);
|
||||
MtTagCollection *collection = ®istry->collections[collection_index];
|
||||
|
||||
if(collection->num_tags >= collection->capacity)
|
||||
{
|
||||
collection->capacity *= 2;
|
||||
collection->tags = realloc(collection->tags, sizeof(MtTagEntry *) * collection->capacity);
|
||||
}
|
||||
MtTagEntry *entry = collection->tags[collection->num_tags];
|
||||
++collection->num_tags;
|
||||
|
||||
usz_t len_tag_label = rr_measure_string(tag_label);
|
||||
|
||||
// TODO: There must be an arena allocator for this!
|
||||
entry->label = malloc(len_tag_label + 1);
|
||||
rr_memcopy(entry->label, tag_label, len_tag_label+1);
|
||||
|
||||
entry->identifier = registry->next_identifier;
|
||||
++registry->next_identifier;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
u32_t mt_get_tag_id(MtTagRegistry *registry, const char *tag_label)
|
||||
{
|
||||
u32_t collection_index = mt_tag_label_to_hash(tag_label, registry->num_collections);
|
||||
MtTagCollection collection = registry->collections[collection_index];
|
||||
usz_t entry_index = 0;
|
||||
while(entry_index < collection.num_tags)
|
||||
{
|
||||
MtTagEntry *entry = collection.tags[entry_index];
|
||||
if(rr_strings_equal(entry->label, tag_label))
|
||||
return entry->identifier;
|
||||
|
||||
++entry_index;
|
||||
}
|
||||
MtTagEntry *entry = mt_create_tag_hash_entry(registry, tag_label);
|
||||
return entry->identifier;
|
||||
}
|
||||
|
||||
const char * mt_get_tag_label(MtTagRegistry *registry, u32_t tag_identifier)
|
||||
{
|
||||
usz_t entry_index = 0;
|
||||
while(entry_index < registry->num_entries)
|
||||
{
|
||||
MtTagEntry *entry = ®istry->entries[entry_index];
|
||||
if(entry->identifier == tag_identifier)
|
||||
return entry->label;
|
||||
|
||||
++entry_index;
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
.build/depends/libRR/Core/core/exports/
|
||||
.build/depends/libRR/Core/platform/exports/
|
||||
core/inc-c/
|
|
@ -1,15 +0,0 @@
|
|||
#include <tag_registry.h>
|
||||
#include <librr/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MtTagRegistry tag_registry = mt_create_tag_registry(NULL);
|
||||
u32_t some_tag = mt_get_tag_id(&tag_registry, "some_tag");
|
||||
if(some_tag != mt_get_tag_id(&tag_registry, "some_tag"))
|
||||
{
|
||||
puts("Inconsistent returned tag identifiers.");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue