world api
parent
a6761bf271
commit
0712851e3e
|
@ -6,9 +6,13 @@
|
||||||
#define BLOCKS_ERROR_NOTFOUND -0x0002
|
#define BLOCKS_ERROR_NOTFOUND -0x0002
|
||||||
#define BLOCKS_ERROR_INVALID -0x0003
|
#define BLOCKS_ERROR_INVALID -0x0003
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BLOCK_FLAG_COLLISION = (1 << 0)
|
||||||
|
} block_flags;
|
||||||
|
|
||||||
int32_t blocks_init(void);
|
int32_t blocks_init(void);
|
||||||
int32_t blocks_destroy(void);
|
int32_t blocks_destroy(void);
|
||||||
|
|
||||||
// persisting buffer
|
// persisting buffer
|
||||||
char *blocks_get_name(uint32_t id);
|
char *blocks_get_name(uint8_t id);
|
||||||
uint32_t blocks_get_flags(uint32_t id);
|
uint32_t blocks_get_flags(uint8_t id);
|
||||||
|
|
|
@ -7,4 +7,7 @@
|
||||||
#define WORLD_ERROR_INVALID_DIMENSIONS -0x0003
|
#define WORLD_ERROR_INVALID_DIMENSIONS -0x0003
|
||||||
#define WORLD_ERROR_INVALID_BUFFER -0x0004
|
#define WORLD_ERROR_INVALID_BUFFER -0x0004
|
||||||
|
|
||||||
int32_t world_gen(int32_t seed, uint8_t width, uint8_t height, uint8_t *buffer, uint32_t size);
|
int32_t world_gen(int32_t seed, uint8_t width, uint8_t height);
|
||||||
|
int32_t world_destroy(void);
|
||||||
|
|
||||||
|
uint32_t world_buf(uint8_t const **ptr);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#define BLOCK_NAMELEN 80
|
#define BLOCK_NAMELEN 80
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t id;
|
uint8_t id;
|
||||||
char name[BLOCK_NAMELEN];
|
char name[BLOCK_NAMELEN];
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
} block;
|
} block;
|
||||||
|
@ -16,11 +16,11 @@ static uint32_t blocks_count = 0;
|
||||||
|
|
||||||
int blocks_comparer(void const *a, void const *b) {
|
int blocks_comparer(void const *a, void const *b) {
|
||||||
block *ba = (block*)a;
|
block *ba = (block*)a;
|
||||||
uint32_t bb = *(uint32_t*)b;
|
uint8_t bb = *(uint8_t*)b;
|
||||||
return ba->id < bb ? -1 : ba->id > bb;
|
return ba->id < bb ? -1 : ba->id > bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static block *blocks_find(uint32_t id) {
|
static block *blocks_find(uint8_t id) {
|
||||||
ZPL_ASSERT_NOT_NULL(blocks);
|
ZPL_ASSERT_NOT_NULL(blocks);
|
||||||
int32_t index = zpl_binary_search((void*)blocks, blocks_count, sizeof(block), (void*)&id, blocks_comparer);
|
int32_t index = zpl_binary_search((void*)blocks, blocks_count, sizeof(block), (void*)&id, blocks_comparer);
|
||||||
ZPL_ASSERT_MSG(index != -1, "block could not be found");
|
ZPL_ASSERT_MSG(index != -1, "block could not be found");
|
||||||
|
@ -39,12 +39,12 @@ int32_t blocks_destroy(void) {
|
||||||
return BLOCKS_ERROR_NONE;
|
return BLOCKS_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *blocks_get_name(uint32_t id) {
|
char *blocks_get_name(uint8_t id) {
|
||||||
ZPL_ASSERT_NOT_NULL(blocks);
|
ZPL_ASSERT_NOT_NULL(blocks);
|
||||||
return blocks_find(id)->name;
|
return blocks_find(id)->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t blocks_get_flags(uint32_t id) {
|
uint32_t blocks_get_flags(uint8_t id) {
|
||||||
ZPL_ASSERT_NOT_NULL(blocks);
|
ZPL_ASSERT_NOT_NULL(blocks);
|
||||||
return blocks_find(id)->flags;
|
return blocks_find(id)->flags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
#include "zpl.h"
|
||||||
|
|
||||||
int32_t world_gen(int32_t seed, uint8_t width, uint8_t height, uint8_t *buffer, uint32_t size) {
|
static uint8_t *world = NULL;
|
||||||
|
static uint32_t world_size = 0;
|
||||||
|
|
||||||
|
int32_t world_gen(int32_t seed, uint8_t width, uint8_t height) {
|
||||||
return WORLD_ERROR_NONE;
|
return WORLD_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t world_destroy(void) {
|
||||||
|
return WORLD_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t world_buf(uint8_t const **ptr) {
|
||||||
|
ZPL_ASSERT_NOT_NULL(world);
|
||||||
|
ZPL_ASSERT_NOT_NULL(ptr);
|
||||||
|
*ptr = world;
|
||||||
|
return world_size;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue