Compare commits
No commits in common. "1eb8ab2fd9973db749252780eb7e6969e87f0515" and "de7d14ae925ea4e1223ace1a747b0eabaf6f6e09" have entirely different histories.
1eb8ab2fd9
...
de7d14ae92
|
@ -31,6 +31,6 @@ add_executable(
|
||||||
${SOURCE_C}
|
${SOURCE_C}
|
||||||
${SOURCE_CPP})
|
${SOURCE_CPP})
|
||||||
|
|
||||||
target_link_libraries(${PROJECT} SDL2 SDL2_image SDL2_ttf m)
|
target_link_libraries(${PROJECT} SDL2 SDL2_image SDL2_ttf)
|
||||||
|
|
||||||
target_include_directories(${PROJECT} PRIVATE "${CMAKE_SOURCE_DIR}/include/" "${CMAKE_SOURCE_DIR}/src/corelib" "${CMAKE_SOURCE_DIR}/src/ui")
|
target_include_directories(${PROJECT} PRIVATE "${CMAKE_SOURCE_DIR}/include/" "${CMAKE_SOURCE_DIR}/src/corelib" "${CMAKE_SOURCE_DIR}/src/ui")
|
||||||
|
|
|
@ -1,46 +1,24 @@
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "memory.h"
|
|
||||||
#include "math/vec.h"
|
#include "math/vec.h"
|
||||||
|
|
||||||
struct {
|
object_t g_objects[WORLD_NUM_OBJECTS];
|
||||||
size_t num;
|
|
||||||
object_t** objects;
|
|
||||||
} _world_objects = {
|
|
||||||
.num = 0,
|
|
||||||
.objects = NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
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_objects.num; ++i) {
|
|
||||||
if(_world_objects.objects[i]->active == 0) {
|
|
||||||
return _world_objects.objects[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_expand_world();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void world_clear() {
|
void world_clear() {
|
||||||
for(int i = 0; i < _world_objects.num; ++i) {
|
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
||||||
_world_objects.objects[i]->active = 0;
|
g_objects[i].active = 0;
|
||||||
_world_objects.objects[i]->enabled = 0;
|
g_objects[i].enabled = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_t* _find_free_object() {
|
||||||
|
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
||||||
|
if(g_objects[i].active == 0) {
|
||||||
|
return g_objects + i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
object_t* make_object() {
|
object_t* make_object() {
|
||||||
object_t* o = _find_free_object();
|
object_t* o = _find_free_object();
|
||||||
*o = object_default();
|
*o = object_default();
|
||||||
|
|
|
@ -3,21 +3,18 @@
|
||||||
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
#define BASE_WORLD_SIZE 24
|
#define WORLD_NUM_OBJECTS 255
|
||||||
|
|
||||||
typedef struct object_t object_t;
|
typedef struct object_t object_t;
|
||||||
|
|
||||||
extern object_t* make_object();
|
extern object_t g_objects[WORLD_NUM_OBJECTS];
|
||||||
extern object_t* instantiate_object(const object_t* original);
|
|
||||||
|
|
||||||
extern void world_clear();
|
object_t* make_object();
|
||||||
|
object_t* instantiate_object(const object_t* original);
|
||||||
|
|
||||||
extern void world_update();
|
void world_clear();
|
||||||
extern void world_draw();
|
|
||||||
|
|
||||||
extern object_t* world_get_object(size_t at);
|
void world_update();
|
||||||
|
void world_draw();
|
||||||
extern size_t world_num_objects();
|
|
||||||
extern void world_reserve_objects(size_t min);
|
|
||||||
|
|
||||||
#endif /* _world_h */
|
#endif /* _world_h */
|
||||||
|
|
Loading…
Reference in New Issue