[RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
@@ -13,4 +13,5 @@ target_link_libraries(loentity
|
||||
memory
|
||||
|
||||
locommon
|
||||
loeffect
|
||||
)
|
||||
|
@@ -25,6 +25,8 @@ struct loentity_character_t {
|
||||
loentity_t super;
|
||||
|
||||
loentity_character_vtable_t vtable;
|
||||
|
||||
vec2_t velocity;
|
||||
};
|
||||
|
||||
void
|
||||
|
@@ -43,6 +43,7 @@ typedef struct {
|
||||
typedef enum {
|
||||
LOENTITY_SUBCLASS_NONE,
|
||||
LOENTITY_SUBCLASS_GROUND,
|
||||
LOENTITY_SUBCLASS_PARTICLE,
|
||||
LOENTITY_SUBCLASS_BULLET,
|
||||
LOENTITY_SUBCLASS_CHARACTER,
|
||||
} loentity_subclass_t;
|
||||
|
64
core/loentity/pool.h
Normal file
64
core/loentity/pool.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <msgpack.h>
|
||||
|
||||
#include "util/memory/memory.h"
|
||||
|
||||
/* You must define prefix##_pool_new function yourself. */
|
||||
|
||||
#define LOENTITY_POOL_SOURCE_TEMPLATE(prefix) \
|
||||
struct prefix##_pool_t { \
|
||||
locommon_counter_t* idgen; \
|
||||
size_t length; \
|
||||
prefix##_base_t items[1]; \
|
||||
}; \
|
||||
\
|
||||
static size_t prefix##_pool_find_unused_item_index_( \
|
||||
const prefix##_pool_t* pool) { \
|
||||
assert(pool != NULL); \
|
||||
\
|
||||
for (size_t i = 0; i < pool->length; ++i) { \
|
||||
if (!pool->items[i].used) return i; \
|
||||
} \
|
||||
fprintf(stderr, #prefix " pool overflow\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
\
|
||||
void prefix##_pool_delete(prefix##_pool_t* pool) { \
|
||||
assert(pool != NULL); \
|
||||
\
|
||||
for (size_t i = 0; i < pool->length; ++i) { \
|
||||
prefix##_base_deinitialize(&pool->items[i]); \
|
||||
} \
|
||||
memory_delete(pool); \
|
||||
} \
|
||||
\
|
||||
prefix##_base_t* prefix##_pool_create(prefix##_pool_t* pool) { \
|
||||
assert(pool != NULL); \
|
||||
\
|
||||
const size_t i = prefix##_pool_find_unused_item_index_(pool); \
|
||||
\
|
||||
prefix##_base_reinitialize( \
|
||||
&pool->items[i], locommon_counter_count(pool->idgen)); \
|
||||
\
|
||||
pool->items[i].used = true; \
|
||||
return &pool->items[i]; \
|
||||
} \
|
||||
\
|
||||
prefix##_base_t* prefix##_pool_unpack_item( \
|
||||
prefix##_pool_t* pool, const msgpack_object* obj) { \
|
||||
assert(pool != NULL); \
|
||||
\
|
||||
const size_t i = prefix##_pool_find_unused_item_index_(pool); \
|
||||
\
|
||||
if (!prefix##_base_unpack(&pool->items[i], obj)) return NULL; \
|
||||
\
|
||||
pool->items[i].used = true; \
|
||||
return &pool->items[i]; \
|
||||
}
|
@@ -37,6 +37,8 @@ static void loentity_store_iterator_assign_by_index_(
|
||||
case LOENTITY_SUBCLASS_GROUND:
|
||||
itr->ground = (loentity_ground_t*) itr->entity;
|
||||
break;
|
||||
case LOENTITY_SUBCLASS_PARTICLE:
|
||||
break;
|
||||
case LOENTITY_SUBCLASS_BULLET:
|
||||
itr->bullet = (loentity_bullet_t*) itr->entity;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user