add flatbuffers support and initial rewrite

Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
folling 2024-05-12 14:15:42 +02:00 committed by Folling
parent 5f7a62ecb7
commit 4d7bf09c4e
Signed by: folling
SSH key fingerprint: SHA256:S9qEx5WCFFLK49tE/LKnKuJYM5sw+++Dn6qJbbyxnCY
72 changed files with 3929 additions and 1403 deletions

View file

@ -20,7 +20,6 @@ struct IkarusNumberProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -36,31 +35,6 @@ IKA_API IkarusNumberProperty * ikarus_number_property_create(
IkarusErrorData * error_out
);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusNumberValue *
ikarus_number_property_get_default_value(struct IkarusNumberProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a number property.
/// \param property The number property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_number_property_set_default_value(
struct IkarusNumberProperty * property,
struct IkarusNumberValue * new_default_value,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}

View file

@ -4,10 +4,10 @@
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/id.h>
#include <ikarus/macros.h>
#include <ikarus/objects/properties/property_type.h>
#include <ikarus/stdtypes.h>
#include <ikarus/values/value_cardinality.h>
#include <ikarus/values/value_type.h>
/// \defgroup properties Properties
/// \brief Properties define the structure and types of data.
@ -15,9 +15,10 @@
IKARUS_BEGIN_HEADER
/// \brief Properties are the placeholders of values for entities.
/// \details Each entity can have any number of properties.
/// \brief Properties define the structure of blueprints.
/// \details Each blueprint can have any number of properties.
/// Every property has a type that identifies the kind of data that can be put in.
/// This is the "base class" of properties. See the derived types (e.g. IkarusToggleProperty) for more information.
///
/// The following types currently exist:
/// - Toggle: A true/false boolean-like value
@ -29,32 +30,10 @@ IKARUS_BEGIN_HEADER
/// - Age (Number)
/// - ISBN (Text)
///
/// Every property has settings which can be used to customise the property further.
/// Two settings that are shared among all properties are the following:
/// - List
/// - May be undefined
///
/// Additionally, each property has a default value. If no default value is provided, a sensible default is chosen.
/// Setting a default value that isn't valid for the property is an error. Changing settings so that the current default
/// value becomes invalid is valid but unsets the custom default value.
///
/// The former transforms a property into a list. Instead of one number, you could then specify a series of numbers.
/// The latter allows you to specify an "unknown" value for a property.
/// It might not be known if a character is dead or not for example.
///
/// Each entity associated with the property has a value for it.
///
/// Properties can also be added to blueprints in which case they are available for all entities associated with the
/// blueprint.
///
/// We call properties within entities "Entity Properties" and properties within blueprints "Blueprint Properties".
///
///
/// \remark Properties are scoped to the blueprint or entity they are associated with.
/// \remark Values for properties are lazily created as space saving measure.
/// \remark Values for properties are lazily created to save space.
/// Fetching the value for some property of some entity will return the property's default value if none is specified.
/// This default value is specified when the property is created and can be updated later.
/// \remark Properties' tree structures are scoped to the entity or blueprint they are associated with.
struct IkarusProperty;
/// \brief Deletes a property.
@ -71,7 +50,7 @@ IKA_API void ikarus_property_delete(IkarusProperty * property, IkarusErrorData *
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The ID of the property or 0 if an error occurs.
IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
IKA_API int64_t ikarus_property_get_id(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the project of a property.
/// \param property The property to get the project of.
@ -81,31 +60,66 @@ IKA_API IkarusId ikarus_property_get_id(IkarusProperty const * property, IkarusE
/// \return The project of the property or null if an error occurs.
IKA_API struct IkarusProject * ikarus_property_get_project(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the name of an property.
/// \param entity The property to get the name of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The name of the property or null if an error occurs.
IKA_API char const * ikarus_property_get_name(IkarusProperty const * entity, IkarusErrorData * error_out);
/// \brief Sets the name of an property.
/// \param entity The property to set the name of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param name The new name of the property.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
IKA_API void ikarus_property_set_name(IkarusProperty * entity, char const * name, IkarusErrorData * error_out);
/// \brief Gets the type info of a property.
/// \param property The property to get the type info of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The type info of the property or null if an error occurs.
IKA_API IkarusPropertyType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
/// \remark Changing the type of a property is not supported. This is because the property would need to change
IKA_API IkarusValueType ikarus_property_get_type(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the source of a property.
// there is no `set_type` as we encode type information in the underlying datatype
/// \briefs Gets a property's cardinality.
/// \param property The property to get the cardinality of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The cardinality of the property or false if an error occurs.
IKA_API IkarusValueCardinality ikarus_property_get_cardinality(IkarusProperty const * property, IkarusErrorData * error_out);
/// \briefs Sets a property's default value.
/// \param property The property to set the cardinality of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \\param cardinality The new cardinality of the property.
/// \param error_out \see errors.h
IKA_API void
ikarus_property_set_cardinality(IkarusProperty * property, IkarusValueCardinality cardinality, IkarusErrorData * error_out);
/// \briefs Gets a property's default value.
/// \param property The property to get the default value of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value of the property or null if an error occurs.
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the source blueprint of a property.
/// \param property The property to get the source of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The source of the property or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope const * ikarus_property_get_scope(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Gets the default value of a property.
/// \param property The property to get the type info of.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value of the property or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusValue * ikarus_property_get_default_value(IkarusProperty const * property, IkarusErrorData * error_out);
IKA_API struct IkarusBlueprint * ikarus_property_get_blueprint(IkarusProperty const * property, IkarusErrorData * error_out);
/// \brief Visits a property. Calling the appropriate function for the property's type.
/// \param property The property to visit.
@ -125,28 +139,6 @@ IKA_API void ikarus_property_visit(
IkarusErrorData * error_out
);
/// \see ikarus_property_visit
IKA_API void ikarus_property_visit_const(
IkarusProperty const * property,
void (*toggle_property_visitor)(struct IkarusToggleProperty const *, void *),
void (*number_property_visitor)(struct IkarusNumberProperty const *, void *),
void (*text_property_visitor)(struct IkarusTextProperty const *, void *),
void * data,
IkarusErrorData * error_out
);
/// \brief Casts a property to an object.
/// \param property The property to cast.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The property represented as an object or null if an error occurs.
/// \remark This operation is guaranteed to be very fast and is intended to be used frequently.
IKA_API struct IkarusObject * ikarus_property_to_object(IkarusProperty * property, IkarusErrorData * error_out);
/// \see ikarus_property_to_object
IKA_API struct IkarusObject const * ikarus_property_to_object_const(IkarusProperty const * property, IkarusErrorData * error_out);
IKARUS_END_HEADER
// @}

View file

@ -1,62 +0,0 @@
#pragma once
/// \file property_source.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/errors.h>
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// @{
IKARUS_BEGIN_HEADER
struct IkarusPropertyScope;
/// \brief Creates an blueprint property source.
/// \param blueprint The blueprint to create the property source for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The created property source or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope *
ikarus_property_source_create_blueprint(struct IkarusBlueprint * blueprint, IkarusErrorData * error_out);
/// \brief Creates an entity property source.
/// \param entity The entity to create the property source for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The created property source or null if an error occurs.
/// \remark Must be freed using #ikarus_free.
IKA_API struct IkarusPropertyScope * ikarus_property_source_create_entity(struct IkarusEntity * entity, IkarusErrorData * error_out);
/// \brief Visits a property source, calling the appropriate callback.
/// \param property_source The property source to visit.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param blueprint_visitor The callback to call if the source is a blueprint, skipped if null.
/// \param entity_visitor The callback to call if the source is an entity, skipped if null.
/// \param user_data User data to pass to the callbacks.
/// \param error_out \see errors.h
IKA_API void ikarus_property_source_visit(
struct IkarusPropertyScope * property_source,
void (*blueprint_visitor)(struct IkarusBlueprint *, void *),
void (*entity_visitor)(struct IkarusEntity *, void *),
void * user_data,
IkarusErrorData * error_out
);
/// \see ikarus_property_source_visit
IKA_API void ikarus_property_source_visit_const(
struct IkarusPropertyScope const * property_source,
void (*blueprint_visitor)(struct IkarusBlueprint const *, void *),
void (*entity_visitor)(struct IkarusEntity const *, void *),
void * user_data,
IkarusErrorData * error_out
);
IKARUS_END_HEADER
/// @}

View file

@ -1,27 +0,0 @@
#pragma once
/// \file property_type.h
/// \author Folling <folling@ikarus.world>
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// @{
IKARUS_BEGIN_HEADER
/// \brief The type of a property.
/// \details Designates the type of data stored by the property as well as which settings are
/// available.
enum IkarusPropertyType {
/// \brief A true/false boolean-esque value.
IkarusPropertyType_Toggle = 0x10000000,
/// \brief A numeric value, limited to IEEE 80 bit floating point numbers.
IkarusPropertyType_Number = 0x20000000,
/// \brief An arbitrary UTF-8 textual value.
IkarusPropertyType_Text = 0x30000000,
};
IKARUS_END_HEADER
/// @}

View file

@ -20,7 +20,6 @@ struct IkarusTextProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
@ -32,31 +31,7 @@ IKA_API IkarusTextProperty * ikarus_text_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusTextValue* default_value,
IkarusErrorData * error_out
);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusTextValue * ikarus_text_property_get_default_value(struct IkarusTextProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a text property.
/// \param property The text property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_text_property_set_default_value(
struct IkarusTextProperty * property,
struct IkarusTextValue * new_default_value,
struct IkarusTextValue * default_value,
IkarusErrorData * error_out
);

View file

@ -7,11 +7,11 @@
#include <ikarus/macros.h>
/// \addtogroup properties Properties
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
/// @{
IKARUS_BEGIN_HEADER
/// \brief Toggle properties store a value that can be either true or false. (e.g. "Is the character dead?")
struct IkarusToggleProperty;
/// \brief Creates a toggle property.
@ -20,44 +20,15 @@ struct IkarusToggleProperty;
/// \pre \li Must exist.
/// \param name The name of the property.
/// \pre \li Must not be null.
/// \pre \li Must not be empty.
/// \param property_source The property source to create the property for.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param default_value The default value for the property.
/// \pre \li Must not be null.
/// \param error_out \see errors.h
/// \return The created property or null if an error occurs.
IKA_API IkarusToggleProperty * ikarus_toggle_property_create(
struct IkarusProject * project,
char const * name,
struct IkarusPropertySource * property_source,
struct IkarusToggleValue * default_value,
IkarusErrorData * error_out
);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param error_out \see errors.h
/// \return The default value or null if an error occurs.
IKA_API struct IkarusToggleValue *
ikarus_toggle_property_get_default_value(struct IkarusToggleProperty * property, IkarusErrorData * error_out);
/// \brief Sets the default value for a toggle property.
/// \param property The toggle property.
/// \pre \li Must not be null.
/// \pre \li Must exist.
/// \param new_default_value The default value.
/// \pre \li Must not be null.
/// \pre \li Must be a valid value for the property.
/// \param error_out \see errors.h
/// \remark Please see \ref property.h "the property documentation" for more information on the interplay between
/// default values and other settings.
IKA_API void ikarus_toggle_property_set_default_value(
struct IkarusToggleProperty * property,
struct IkarusToggleValue * new_default_value,
IkarusErrorData * error_out
);