[RELEASE] u22-v04

This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
2020-10-09 00:00:00 +00:00
parent 84c3a02b9a
commit 80b3b82332
277 changed files with 12154 additions and 13836 deletions

View File

@@ -0,0 +1,19 @@
add_library(loparticle
aura.c
base.c
misc.c
pool.c
)
target_crial_sources(loparticle
aura.crial
base.crial
)
target_link_libraries(loparticle
msgpackc
mpkutil
locommon
loentity
loshader
)

66
core/loparticle/aura.c Normal file
View File

@@ -0,0 +1,66 @@
#include "./aura.h"
#include <assert.h>
#include <stdbool.h>
#include <msgpack.h>
#include "util/mpkutil/get.h"
#include "util/mpkutil/pack.h"
#include "core/locommon/msgpack.h"
#include "core/loentity/entity.h"
#include "./base.h"
/* generated serializer */
#include "core/loparticle/crial/aura.h"
_Static_assert(
sizeof(loparticle_aura_param_t) <= LOPARTICLE_BASE_DATA_MAX_SIZE,
"data size overflow");
bool loparticle_aura_param_valid(const loparticle_aura_param_t* param) {
return param != NULL;
}
void loparticle_aura_param_pack(
const loparticle_aura_param_t* param, msgpack_packer* packer) {
assert(param != NULL);
assert(packer != NULL);
msgpack_pack_map(packer, CRIAL_PROPERTY_COUNT_);
CRIAL_SERIALIZER_;
}
bool loparticle_aura_param_unpack(
loparticle_aura_param_t* param, const msgpack_object* obj) {
assert(param != NULL);
const msgpack_object_map* root = mpkutil_get_map(obj);
if (root == NULL) return false;
CRIAL_DESERIALIZER_;
return loparticle_aura_param_valid(param);
}
void loparticle_aura_build(
loparticle_base_t* base,
loparticle_type_t type,
const loparticle_aura_param_t* param) {
assert(base != NULL);
assert(param != NULL);
base->type = type;
*((loparticle_aura_param_t*) base->data) = *param;
}
bool loparticle_aura_guard_update(loparticle_base_t* base) {
assert(base != NULL);
/* TODO(catfoot): */
return true;
}

View File

@@ -0,0 +1,13 @@
/* CRIAL
SERIALIZER_BEGIN
mpkutil_pack_str(packer, "$name");
LOCOMMON_MSGPACK_PACK_ANY(packer, &param->$code);
END
DESERIALIZER_BEGIN
if (!LOCOMMON_MSGPACK_UNPACK_ANY(
mpkutil_get_map_item_by_str(root, "$name"), &param->$code)) {
return false;
}
END
PROPERTY target
*/

51
core/loparticle/aura.h Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include <stdbool.h>
#include <msgpack.h>
#include "core/loentity/entity.h"
#include "./base.h"
typedef struct {
loentity_id_t target;
} loparticle_aura_param_t;
bool
loparticle_aura_valid(
const loparticle_aura_param_t* param
);
void
loparticle_aura_param_pack(
const loparticle_aura_param_t* param,
msgpack_packer* packer
);
bool
loparticle_aura_param_unpack(
loparticle_aura_param_t* param,
const msgpack_object* obj
);
void
loparticle_aura_build(
loparticle_base_t* base,
loparticle_type_t type,
const loparticle_aura_param_t* param
);
bool
loparticle_aura_guard_update(
loparticle_base_t* base
);
#define loparticle_aura_guard_build(base, param) \
loparticle_aura_build(base, LOPARTICLE_TYPE_AURA_GUARD, param)
#define loparticle_aura_guard_tear_down(base)
#define loparticle_aura_guard_pack_data(base, packer) \
loparticle_aura_param_pack( \
(const loparticle_aura_param_t*) base->data, packer)
#define loparticle_aura_guard_unpack_data(base, obj) \
loparticle_aura_param_unpack( \
(loparticle_aura_param_t*) base->data, obj)

165
core/loparticle/base.c Normal file
View File

@@ -0,0 +1,165 @@
#include "./base.h"
#include <assert.h>
#include <stdbool.h>
#include <msgpack.h>
#include "util/mpkutil/get.h"
#include "util/mpkutil/pack.h"
#include "core/locommon/msgpack.h"
#include "core/locommon/ticker.h"
#include "core/loentity/entity.h"
#include "core/loentity/store.h"
#include "core/loshader/particle.h"
#include "./aura.h"
#include "./misc.h"
/* generated serializer */
#include "core/loparticle/crial/base.h"
static void loparticle_base_delete_(loentity_t* entity) {
assert(entity != NULL);
loparticle_base_t* base = (typeof(base)) entity;
if (!base->used) return;
base->used = false;
# define each_(NAME, name) do { \
if (base->type == LOPARTICLE_TYPE_##NAME) { \
loparticle_##name##_tear_down(base); \
return; \
} \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
assert(false);
# undef each_
}
static void loparticle_base_die_(loentity_t* entity) {
assert(entity != NULL);
}
static bool loparticle_base_update_(loentity_t* entity) {
assert(entity != NULL);
loparticle_base_t* base = (typeof(base)) entity;
base->cache = (typeof(base->cache)) {0};
# define each_(NAME, name) do { \
if (base->type == LOPARTICLE_TYPE_##NAME) { \
return loparticle_##name##_update(base); \
} \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
return false;
# undef each_
}
static void loparticle_base_draw_(
loentity_t* entity, const locommon_position_t* basepos) {
assert(entity != NULL);
assert(basepos != NULL);
loparticle_base_t* base = (typeof(base)) entity;
vec2_t p;
locommon_position_sub(&p, &base->super.pos, basepos);
vec2_addeq(&base->cache.instance.pos, &p);
loshader_particle_drawer_add_instance(base->drawer, &base->cache.instance);
}
static void loparticle_base_pack_(
const loentity_t* entity, msgpack_packer* packer) {
assert(entity != NULL);
assert(packer != NULL);
const loparticle_base_t* base = (typeof(base)) entity;
msgpack_pack_map(packer, CRIAL_PROPERTY_COUNT_+1);
CRIAL_SERIALIZER_;
mpkutil_pack_str(packer, "data");
# define each_(NAME, name) do { \
if (base->type == LOPARTICLE_TYPE_##NAME) { \
loparticle_##name##_pack_data(base, packer); \
return; \
} \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
assert(false);
# undef each_
}
void loparticle_base_initialize(
loparticle_base_t* base,
loshader_particle_drawer_t* drawer,
const locommon_ticker_t* ticker,
loentity_store_t* entities) {
assert(base != NULL);
assert(drawer != NULL);
assert(ticker != NULL);
assert(entities != NULL);
*base = (typeof(*base)) {
.super = {
.vtable = {
.delete = loparticle_base_delete_,
.die = loparticle_base_die_,
.update = loparticle_base_update_,
.draw = loparticle_base_draw_,
.pack = loparticle_base_pack_,
},
.subclass = LOENTITY_SUBCLASS_PARTICLE,
},
.drawer = drawer,
.ticker = ticker,
.entities = entities,
};
}
void loparticle_base_reinitialize(loparticle_base_t* base, loentity_id_t id) {
assert(base != NULL);
base->super.id = id;
}
void loparticle_base_deinitialize(loparticle_base_t* base) {
assert(base != NULL);
loparticle_base_delete_(&base->super);
}
bool loparticle_base_unpack(
loparticle_base_t* base, const msgpack_object* obj) {
assert(base != NULL);
loparticle_base_reinitialize(base, 0);
const msgpack_object_map* root = mpkutil_get_map(obj);
CRIAL_DESERIALIZER_;
const msgpack_object* data = mpkutil_get_map_item_by_str(root, "data");
# define each_(NAME, name) do { \
if (base->type == LOPARTICLE_TYPE_##NAME) { \
if (!loparticle_##name##_unpack_data(base, data)) return false; \
} \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
return true;
# undef each_
}

View File

@@ -0,0 +1,31 @@
/* CRIAL
SERIALIZER_BEGIN
mpkutil_pack_str(packer, "$name");
mpkutil_pack_str(packer, $code);
END
DESERIALIZER_BEGIN
const char* v;
size_t vlen;
if (!mpkutil_get_str(
mpkutil_get_map_item_by_str(root, "$name"), &v, &vlen) ||
strncmp(v, $code, vlen) != 0 || $code[vlen] != 0) {
return false;
}
END
PROPERTY subclass = "particle"
SERIALIZER_BEGIN
mpkutil_pack_str(packer, "$name");
LOCOMMON_MSGPACK_PACK_ANY(packer, &base->$code);
END
DESERIALIZER_BEGIN
if (!LOCOMMON_MSGPACK_UNPACK_ANY(
mpkutil_get_map_item_by_str(root, "$name"), &base->$code)) {
return false;
}
END
PROPERTY type
PROPERTY id = super.id
# data property is serialized manually (plz see pack/unpack function)
*/

59
core/loparticle/base.h Normal file
View File

@@ -0,0 +1,59 @@
#pragma once
#include <stdbool.h>
#include <msgpack.h>
#include "core/locommon/ticker.h"
#include "core/loentity/entity.h"
#include "core/loentity/store.h"
#include "core/loshader/particle.h"
#include "./misc.h"
typedef struct {
loentity_t super;
bool used;
/* injected deps */
loshader_particle_drawer_t* drawer;
const locommon_ticker_t* ticker;
loentity_store_t* entities;
/* params not to be packed */
struct {
loshader_particle_drawer_instance_t instance;
} cache;
/* params to be packed */
loparticle_type_t type;
# define LOPARTICLE_BASE_DATA_MAX_SIZE 256
uint8_t data[LOPARTICLE_BASE_DATA_MAX_SIZE];
/* pack function for the type is used */
} loparticle_base_t;
void
loparticle_base_initialize(
loparticle_base_t* base,
loshader_particle_drawer_t* drawer,
const locommon_ticker_t* ticker,
loentity_store_t* entities
);
void
loparticle_base_reinitialize(
loparticle_base_t* base,
loentity_id_t id
);
void
loparticle_base_deinitialize(
loparticle_base_t* base
);
bool
loparticle_base_unpack(
loparticle_base_t* base,
const msgpack_object* obj
);

37
core/loparticle/misc.c Normal file
View File

@@ -0,0 +1,37 @@
#include "./misc.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
const char* loparticle_type_stringify(loparticle_type_t type) {
# define each_(NAME, name) do { \
if (type == LOPARTICLE_TYPE_##NAME) return #name; \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
# undef each_
assert(false);
return NULL;
}
bool loparticle_type_unstringify(
loparticle_type_t* type, const char* v, size_t len) {
assert(type != NULL);
assert(v != NULL || len == 0);
# define each_(NAME, name) do { \
if (strncmp(v, #name, len) == 0 && #name[len] == 0) { \
*type = LOPARTICLE_TYPE_##NAME; \
return true; \
} \
} while (0)
LOPARTICLE_TYPE_EACH_(each_);
return false;
# undef each_
}

25
core/loparticle/misc.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
/* don't forget to update EACH macro */
typedef enum {
LOPARTICLE_TYPE_AURA_GUARD,
} loparticle_type_t;
#define LOPARTICLE_TYPE_EACH_(PROC) do { \
PROC(AURA_GUARD, aura_guard); \
} while (0)
const char*
loparticle_type_stringify(
loparticle_type_t type
);
bool
loparticle_type_unstringify(
loparticle_type_t* type,
const char* v,
size_t len
);

45
core/loparticle/pool.c Normal file
View File

@@ -0,0 +1,45 @@
#include "./pool.h"
#include <stddef.h>
#include <msgpack.h>
#include "util/memory/memory.h"
#include "core/locommon/counter.h"
#include "core/locommon/ticker.h"
#include "core/loentity/pool.h"
#include "core/loentity/store.h"
#include "core/loshader/particle.h"
#include "./base.h"
LOENTITY_POOL_SOURCE_TEMPLATE(loparticle)
loparticle_pool_t* loparticle_pool_new(
loshader_particle_drawer_t* drawer,
locommon_counter_t* idgen,
const locommon_ticker_t* ticker,
loentity_store_t* entities,
size_t length) {
assert(drawer != NULL);
assert(idgen != NULL);
assert(ticker != NULL);
assert(entities != NULL);
assert(length > 0);
loparticle_pool_t* pool =
memory_new(sizeof(*pool) + (length-1)*sizeof(pool->items[0]));
*pool = (typeof(*pool)) {
.idgen = idgen,
.length = length,
};
for (size_t i = 0; i < pool->length; ++i) {
loparticle_base_initialize(
&pool->items[i],
drawer,
ticker,
entities);
}
return pool;
}

40
core/loparticle/pool.h Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#include <stddef.h>
#include <msgpack.h>
#include "core/locommon/counter.h"
#include "core/locommon/ticker.h"
#include "core/loentity/store.h"
#include "core/loshader/particle.h"
#include "./base.h"
struct loparticle_pool_t;
typedef struct loparticle_pool_t loparticle_pool_t;
loparticle_pool_t* /* OWNERSHIP */
loparticle_pool_new(
loshader_particle_drawer_t* drawer,
locommon_counter_t* idgen,
const locommon_ticker_t* ticker,
loentity_store_t* entities,
size_t length
);
void
loparticle_pool_delete(
loparticle_pool_t* pool /* OWNERSHIP */
);
loparticle_base_t*
loparticle_pool_create(
loparticle_pool_t* pool
);
loparticle_base_t*
loparticle_pool_unpack_item(
loparticle_pool_t* pool,
const msgpack_object* obj
);