Compare commits

..

No commits in common. "59de57fe3adc00cfb98aca3326a67f9152b2da5b" and "3e3f322529f5c19888f9887ac46936b42fa1a8b6" have entirely different histories.

2 changed files with 15 additions and 14 deletions

View File

@ -26,7 +26,7 @@ object_t object_default();
void object_draw_sprite(object_t* object); void object_draw_sprite(object_t* object);
static inline static inline
int object_is_valid(object_t* object) { int object_is_valid(object_t* object) {
return object == NULL || object->active == 0; return object != NULL && object->active <= 0;
} }
#endif /* _object_h */ #endif /* _object_h */

View File

@ -1,6 +1,5 @@
#include "world.h" #include "world.h"
#include "memory.h" #include "memory.h"
#include "assert.h"
#include "math/vec.h" #include "math/vec.h"
#include "object.h" #include "object.h"
@ -19,19 +18,18 @@ int _expand_world() {
new_num = 16; new_num = 16;
} }
object_t** new_list = realloc(_world_objects.objects, new_num * sizeof(object_t*)); object_t** new_list = realloc(_world_objects.objects, new_num * sizeof(object_t*));
if(new_list == NULL) { if(new_list == NULL) {
assert(!"ERROR: Out of memory"); printf("ERROR: failed to expand world when requesting additional objects\n");
exit(-10); return 0;
} } else {
for(size_t i = _world_objects.num; i < new_num; ++i) {
new_list[i] = NULL;
}
for(size_t i = _world_objects.num; i < new_num; ++i) { _world_objects.objects = new_list;
new_list[i] = NULL; _world_objects.num = new_num;
return 1;
} }
_world_objects.objects = new_list;
_world_objects.num = new_num;
return 1;
} }
static inline static inline
@ -42,8 +40,11 @@ size_t _find_free_object() {
} }
} }
size_t num = _world_objects.num; size_t num = _world_objects.num;
_expand_world(); if(_expand_world()) {
return num; return num;
} else {
return NULL;
}
} }
void world_clear() { void world_clear() {