eco2d/code/apps/server/source/world.c

43 lines
909 B
C
Raw Normal View History

2021-01-11 13:47:14 +00:00
#include "world.h"
2021-01-11 14:42:36 +00:00
#include "zpl.h"
2021-01-11 13:47:14 +00:00
2021-01-11 14:42:36 +00:00
static uint8_t *world = NULL;
2021-01-11 17:30:47 +00:00
static uint32_t world_seed = 0;
2021-01-11 14:42:36 +00:00
static uint32_t world_size = 0;
2021-01-11 14:48:17 +00:00
static uint32_t world_width = 0;
2021-01-11 16:20:12 +00:00
static uint32_t world_height = 0;
2021-01-11 14:51:42 +00:00
2021-01-11 17:30:47 +00:00
int32_t world_gen();
2021-01-11 14:51:42 +00:00
int32_t world_init(int32_t seed, uint8_t width, uint8_t height) {
2021-01-11 14:48:17 +00:00
if (world) {
world_destroy();
}
2021-01-11 17:30:47 +00:00
world_seed = seed;
2021-01-11 14:48:17 +00:00
world_width = width;
2021-01-11 16:20:12 +00:00
world_height = height;
2021-01-11 17:30:47 +00:00
world_size = width*height;
2021-01-11 14:48:17 +00:00
world = zpl_malloc(sizeof(uint8_t)*world_size);
if (!world) {
return WORLD_ERROR_OUTOFMEM;
}
2021-01-11 17:30:47 +00:00
return world_gen();
2021-01-11 14:42:36 +00:00
}
int32_t world_destroy(void) {
2021-01-11 14:48:17 +00:00
zpl_mfree(world);
world = NULL;
2021-01-11 13:47:14 +00:00
return WORLD_ERROR_NONE;
}
2021-01-11 14:42:36 +00:00
2021-01-11 14:48:17 +00:00
uint32_t world_buf(uint8_t const **ptr, uint32_t *width) {
2021-01-11 14:42:36 +00:00
ZPL_ASSERT_NOT_NULL(world);
ZPL_ASSERT_NOT_NULL(ptr);
*ptr = world;
2021-01-11 14:48:17 +00:00
if (width) *width = world_width;
2021-01-11 14:42:36 +00:00
return world_size;
}
2021-01-11 16:49:00 +00:00
#include "world_gen.c"