-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef ZAKAROUF_Z_IMP__MAP2D_H | ||
#define ZAKAROUF_Z_IMP__MAP2D_H | ||
|
||
#include "std/primitives.h" | ||
#include "vector.h" | ||
|
||
#include "u8arr.h" | ||
|
||
/** | ||
* z__Map2D() | ||
* Tileset Oriented Map Type with layers or z-dimention. | ||
* size: Dimention of Map | ||
* layers: Total no. of z layers used | ||
* layers_capacity: Total no. of z layers allocated | ||
*/ | ||
#define z__Map2D(Name, T, ...) \ | ||
typedef struct Name Name; \ | ||
struct Name { \ | ||
z__u32Vec2 size; \ | ||
z__size plotsize; \ | ||
T *plots; \ | ||
__VA_ARGS__; \ | ||
} | ||
|
||
void z__Map2D_new__raw(void *_map, z__size plotsize, const z__u32 x, z__u32 const y); | ||
void z__Map2D_delete__raw(void *_map); | ||
|
||
#define z__Map2D_new(map, x, y) z__Map2D_new__raw(map, sizeof(*(map)->plots), x, y) | ||
#define z__Map2D_delete(map) { (void)(map)->plots; z__Map2D_delete__raw(map); } | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef ZAKAROUF_Z__MAP3D_H | ||
#define ZAKAROUF_Z__MAP3D_H | ||
|
||
#include "std/primitives.h" | ||
#include "vector.h" | ||
#include "utils.h" | ||
|
||
#include "u8arr.h" | ||
|
||
/** | ||
* z__Map3D() | ||
* Tileset Oriented Map Type with layers or z-dimention. | ||
* size: Dimention of Map | ||
* layers: Total no. of z layers used | ||
* layers_capacity: Total no. of z layers allocated | ||
*/ | ||
#define z__Map3D(Name, T, ...) \ | ||
typedef struct Name Name; \ | ||
struct Name { \ | ||
z__u32Vec3 size; \ | ||
z__u32 size_total; \ | ||
T *plots; \ | ||
__VA_ARGS__; \ | ||
} | ||
|
||
#define z__Map3D_get(map, x, y, z) (map).plots[z__xyz3Dto1D(x, y, z, (map).size.x, (map).size.y)] | ||
#define z__Map3D_set(map, x, y, z, value) { z__Map3D_get(map, x, y, z) = value; } | ||
|
||
#define z__Map3D_new(map, _x, _y, _z, ...)\ | ||
{ \ | ||
(map)->size = (z__u32Vec3) { .x = _x, .y = _y, .z = _z }; \ | ||
(map)->size_total = _x * _y * _z; \ | ||
(map)->plots = z__MALLOC( sizeof(*(map)->plots) * (map)->size_total );\ | ||
__VA_ARGS__;\ | ||
} | ||
|
||
#define z__Map3D_delete(map, ...)\ | ||
{ \ | ||
__VA_ARGS__; \ | ||
z__FREE((map)->plots); \ | ||
(map)-size = (z__u32Vec3){0}; \ | ||
(map)-size_total = 0; \ | ||
} \ | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdlib.h> | ||
#include <memory.h> | ||
#include <string.h> | ||
|
||
#include "std/mem.h" | ||
#include "utils.h" | ||
|
||
#include "u8arr.h" | ||
#include "map2d.h" | ||
#include "forrange.h" | ||
|
||
z__Map2D(VoidMap, void); | ||
#define self VoidMap *map = _map_; | ||
|
||
void z__Map2D_new__raw(void *_map_, z__size plotsize, z__u32 const x, z__u32 const y) | ||
{ | ||
self; | ||
map->plots = z__MALLOC(plotsize * x * y); | ||
map->plotsize = plotsize; | ||
map->size.x = x; | ||
map->size.y = y; | ||
} | ||
|
||
void z__Map2D_delete__raw(void *_map_) | ||
{ | ||
self; | ||
z__FREE(map->plots); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters