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

35 lines
751 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;
static uint32_t world_size = 0;
2021-01-11 14:48:17 +00:00
static uint32_t world_width = 0;
2021-01-11 14:42:36 +00:00
int32_t world_gen(int32_t seed, uint8_t width, uint8_t height) {
2021-01-11 14:48:17 +00:00
if (world) {
world_destroy();
}
world_size = width*height;
world_width = width;
world = zpl_malloc(sizeof(uint8_t)*world_size);
if (!world) {
return WORLD_ERROR_OUTOFMEM;
}
2021-01-11 14:42:36 +00:00
return WORLD_ERROR_NONE;
}
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;
}