Compare commits
4 Commits
de7d14ae92
...
1eb8ab2fd9
Author | SHA1 | Date |
---|---|---|
|
1eb8ab2fd9 | |
|
a18d5599b4 | |
|
ca3b2af703 | |
|
ac722f6e5f |
|
@ -31,6 +31,6 @@ add_executable(
|
|||
${SOURCE_C}
|
||||
${SOURCE_CPP})
|
||||
|
||||
target_link_libraries(${PROJECT} SDL2 SDL2_image SDL2_ttf)
|
||||
target_link_libraries(${PROJECT} SDL2 SDL2_image SDL2_ttf m)
|
||||
|
||||
target_include_directories(${PROJECT} PRIVATE "${CMAKE_SOURCE_DIR}/include/" "${CMAKE_SOURCE_DIR}/src/corelib" "${CMAKE_SOURCE_DIR}/src/ui")
|
||||
|
|
|
@ -1,24 +1,46 @@
|
|||
#include "world.h"
|
||||
#include "memory.h"
|
||||
#include "math/vec.h"
|
||||
|
||||
object_t g_objects[WORLD_NUM_OBJECTS];
|
||||
struct {
|
||||
size_t num;
|
||||
object_t** objects;
|
||||
} _world_objects = {
|
||||
.num = 0,
|
||||
.objects = NULL
|
||||
};
|
||||
|
||||
void world_clear() {
|
||||
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
||||
g_objects[i].active = 0;
|
||||
g_objects[i].enabled = 0;
|
||||
static inline
|
||||
int _expand_world() {
|
||||
size_t new_num = _world_objects.num * 2;
|
||||
object_t** new_list = realloc(_world_objects.objects, new_num * sizeof(object_t*));
|
||||
if(new_list == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
_world_objects.objects = new_list;
|
||||
_world_objects.num = new_num;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static inline
|
||||
object_t* _find_free_object() {
|
||||
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
||||
if(g_objects[i].active == 0) {
|
||||
return g_objects + i;
|
||||
for(int i = 0; i < _world_objects.num; ++i) {
|
||||
if(_world_objects.objects[i]->active == 0) {
|
||||
return _world_objects.objects[i];
|
||||
}
|
||||
}
|
||||
_expand_world();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void world_clear() {
|
||||
for(int i = 0; i < _world_objects.num; ++i) {
|
||||
_world_objects.objects[i]->active = 0;
|
||||
_world_objects.objects[i]->enabled = 0;
|
||||
}
|
||||
}
|
||||
|
||||
object_t* make_object() {
|
||||
object_t* o = _find_free_object();
|
||||
*o = object_default();
|
||||
|
|
|
@ -3,18 +3,21 @@
|
|||
|
||||
#include "object.h"
|
||||
|
||||
#define WORLD_NUM_OBJECTS 255
|
||||
#define BASE_WORLD_SIZE 24
|
||||
|
||||
typedef struct object_t object_t;
|
||||
|
||||
extern object_t g_objects[WORLD_NUM_OBJECTS];
|
||||
extern object_t* make_object();
|
||||
extern object_t* instantiate_object(const object_t* original);
|
||||
|
||||
object_t* make_object();
|
||||
object_t* instantiate_object(const object_t* original);
|
||||
extern void world_clear();
|
||||
|
||||
void world_clear();
|
||||
extern void world_update();
|
||||
extern void world_draw();
|
||||
|
||||
void world_update();
|
||||
void world_draw();
|
||||
extern object_t* world_get_object(size_t at);
|
||||
|
||||
extern size_t world_num_objects();
|
||||
extern void world_reserve_objects(size_t min);
|
||||
|
||||
#endif /* _world_h */
|
||||
|
|
Loading…
Reference in New Issue