]>
git.bts.cx Git - benzene.git/blob - src/bz/gfx/drawing.c
1 #include <bz/gfx/drawing.h>
3 #include <bz/math/math.h>
4 #include <bz/gfx/gfx.h>
5 #include <bz/gfx/tilemap.h>
8 #define DRAW_DATA(name, members, ...) \
9 struct data##name { members; }; typedef struct data##name data##name; \
10 static void dispatch##name(void *userParam) { data##name *data = (data##name *)userParam; name(__VA_ARGS__); } \
12 #define DRAW_DATA_DISPATCH(drawQueue, name, ...) \
13 if (drawQueue != NULL) { \
14 data##name *data = (data##name *)bzGfxDrawQueueEnqueue(drawQueue, sortIdx, dispatch##name, sizeof(data##name)); \
15 *data = (data##name){ __VA_ARGS__ }; \
20 DRAW_DATA(bzPSet
, float x
; float y
; int c
, data
->x
, data
->y
, data
->c
)
21 DRAW_DATA(bzCls
, uint8_t c
, data
->c
)
22 DRAW_DATA(bzCamera
, float x
; float y
, data
->x
, data
->y
)
23 DRAW_DATA(bzCirc
, int x
; int y
; int r
; int c
, data
->x
, data
->y
, data
->r
, data
->c
)
24 DRAW_DATA(bzCircFill
, int x
; int y
; int r
; int c
, data
->x
, data
->y
, data
->r
, data
->c
)
25 DRAW_DATA(bzLine
, int x0
; int y0
; int x1
; int y1
; int c
, data
->x0
, data
->y0
, data
->x1
, data
->y1
, data
->c
)
26 DRAW_DATA(bzRect
, int x0
; int y0
; int x1
; int y1
; int c
, data
->x0
, data
->y0
, data
->x1
, data
->y1
, data
->c
)
27 DRAW_DATA(bzRectFill
, int x0
; int y0
; int x1
; int y1
; int c
, data
->x0
, data
->y0
, data
->x1
, data
->y1
, data
->c
)
28 DRAW_DATA(bzTriangle
, int x0
; int y0
; int x1
; int y1
; int x2
; int y2
; int c
, data
->x0
, data
->y0
, data
->x1
, data
->y1
, data
->x2
, data
->y2
, data
->c
)
29 DRAW_DATA(bzSpr
, int n
; int x
; int y
, data
->n
, data
->x
, data
->y
)
30 DRAW_DATA(bzSprExt
, int n
; int x
; int y
; int w
; int h
; bool flipX
; bool flipY
, data
->n
, data
->x
, data
->y
, data
->w
, data
->h
, data
->flipX
, data
->flipY
)
31 DRAW_DATA(bzSSpr
, int sx
; int sy
; int sw
; int sh
; int dx
; int dy
, data
->sx
, data
->sy
, data
->sw
, data
->sh
, data
->dx
, data
->dy
)
32 DRAW_DATA(bzSSprExt
, int sx
; int sy
; int sw
; int sh
; int dx
; int dy
; int dw
; int dh
; bool flipX
; bool flipY
, data
->sx
, data
->sy
, data
->sw
, data
->sh
, data
->dx
, data
->dy
, data
->dw
, data
->dh
, data
->flipX
, data
->flipY
)
33 DRAW_DATA(bzPrint
, int x
; int y
; int c
; char string
[], data
->x
, data
->y
, data
->c
, data
->string
)
34 DRAW_DATA(bzFillP
, uint16_t p
, data
->p
)
35 DRAW_DATA(bzSetPaletteColor
, int palette
; int colorIdx
; int color
, data
->palette
, data
->colorIdx
, data
->color
)
36 DRAW_DATA(bzSetOutputBuffer
, int idx
, data
->idx
)
37 DRAW_DATA(bzGfxMap
, BZTilemapID tilemap
; int tx
; int ty
; int x
; int y
; int mw
; int mh
; BZIdentifierHash tag
, data
->tilemap
, data
->tx
, data
->ty
, data
->x
, data
->y
, data
->mw
, data
->mh
, data
->tag
)
39 void bzDrawPSet(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, float x
, float y
, int c
) {
40 BZVector pos
= bzVectorMake(x
, y
);
41 bzMatrixTransformVector(&pos
, &pos
, mtx
);
42 DRAW_DATA_DISPATCH(drawQueue
, bzPSet
, pos
.x
, pos
.y
, c
)
45 void bzDrawCls(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, uint8_t c
) {
46 DRAW_DATA_DISPATCH(drawQueue
, bzCls
, c
)
49 void bzDrawCamera(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, float x
, float y
) {
50 DRAW_DATA_DISPATCH(drawQueue
, bzCamera
, x
, y
)
53 void bzDrawCirc(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x
, int y
, int r
, int c
) {
54 BZVector pos
= bzVectorMake(x
, y
);
55 BZVector radius
= bzVectorMake(r
, 0);
56 bzMatrixTransformVector(&pos
, &pos
, mtx
);
57 bzMatrixScaleRotateVector(&radius
, &radius
, mtx
);
58 DRAW_DATA_DISPATCH(drawQueue
, bzCirc
, pos
.x
, pos
.y
, bzVectorMagnitude(&radius
), c
) // FIXME, RADIUS
61 void bzDrawCircFill(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x
, int y
, int r
, int c
) {
62 BZVector pos
= bzVectorMake(x
, y
);
63 BZVector radius
= bzVectorMake(r
, 0);
64 bzMatrixTransformVector(&pos
, &pos
, mtx
);
65 bzMatrixScaleRotateVector(&radius
, &radius
, mtx
);
66 DRAW_DATA_DISPATCH(drawQueue
, bzCircFill
, pos
.x
, pos
.y
, bzVectorMagnitude(&radius
), c
) // FIXME, RADIUS
69 void bzDrawLine(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x0
, int y0
, int x1
, int y1
, int c
) {
70 BZVector pos0
= bzVectorMake(x0
, y0
);
71 BZVector pos1
= bzVectorMake(x1
, y1
);
72 bzMatrixTransformVector(&pos0
, &pos0
, mtx
);
73 bzMatrixTransformVector(&pos1
, &pos1
, mtx
);
74 DRAW_DATA_DISPATCH(drawQueue
, bzLine
, pos0
.x
, pos0
.y
, pos1
.x
, pos1
.y
, c
)
77 void bzDrawRect(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x0
, int y0
, int x1
, int y1
, int c
) {
78 BZVector pos0
= bzVectorMake(x0
, y0
);
79 BZVector pos1
= bzVectorMake(x1
, y1
);
80 bzMatrixTransformVector(&pos0
, &pos0
, mtx
);
81 bzMatrixTransformVector(&pos1
, &pos1
, mtx
);
82 DRAW_DATA_DISPATCH(drawQueue
, bzRect
, pos0
.x
, pos0
.y
, pos1
.x
, pos1
.y
, c
) // FIXME, rotation??
85 void bzDrawRectFill(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x0
, int y0
, int x1
, int y1
, int c
) {
86 BZVector pos0
= bzVectorMake(x0
, y0
);
87 BZVector pos1
= bzVectorMake(x1
, y1
);
88 bzMatrixTransformVector(&pos0
, &pos0
, mtx
);
89 bzMatrixTransformVector(&pos1
, &pos1
, mtx
);
90 DRAW_DATA_DISPATCH(drawQueue
, bzRectFill
, pos0
.x
, pos0
.y
, pos1
.x
, pos1
.y
, c
) // FIXME, rotation??
93 void bzDrawTriangle(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x0
, int y0
, int x1
, int y1
, int x2
, int y2
, int c
) {
94 BZVector pos0
= bzVectorMake(x0
, y0
);
95 BZVector pos1
= bzVectorMake(x1
, y1
);
96 BZVector pos2
= bzVectorMake(x2
, y2
);
97 bzMatrixTransformVector(&pos0
, &pos0
, mtx
);
98 bzMatrixTransformVector(&pos1
, &pos1
, mtx
);
99 bzMatrixTransformVector(&pos2
, &pos2
, mtx
);
100 DRAW_DATA_DISPATCH(drawQueue
, bzTriangle
, pos0
.x
, pos0
.y
, pos1
.x
, pos1
.y
, pos2
.x
, pos2
.y
, c
)
103 void bzDrawSpr(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int n
, int x
, int y
) {
104 DRAW_DATA_DISPATCH(drawQueue
, bzSpr
, n
, x
, y
)
107 void bzDrawSprExt(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int n
, int x
, int y
, int w
, int h
, bool flipX
, bool flipY
) {
108 DRAW_DATA_DISPATCH(drawQueue
, bzSprExt
, n
, x
, y
, w
, h
, flipX
, flipY
)
111 void bzDrawSSpr(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int sx
, int sy
, int sw
, int sh
, int dx
, int dy
) {
112 DRAW_DATA_DISPATCH(drawQueue
, bzSSpr
, sx
, sy
, sw
, sh
, dx
, dy
)
115 void bzDrawSSprExt(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int sx
, int sy
, int sw
, int sh
, int dx
, int dy
, int dw
, int dh
, bool flipX
, bool flipY
) {
116 DRAW_DATA_DISPATCH(drawQueue
, bzSSprExt
, sx
, sy
, sw
, sh
, dx
, dy
, dw
, dh
, flipX
, flipY
)
119 void bzDrawPrint(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int x
, int y
, int color
, const char *text
) {
120 BZVector pos
= bzVectorMake(x
, y
);
121 bzMatrixTransformVector(&pos
, &pos
, mtx
);
122 if (drawQueue
!= NULL
) {
123 size_t dataSize
= sizeof(databzPrint
) + strlen(text
);
124 databzPrint
*data
= (databzPrint
*)bzGfxDrawQueueEnqueue(drawQueue
, sortIdx
, dispatchbzPrint
, dataSize
);
128 strcpy(data
->string
, text
);
130 bzPrint(pos
.x
, pos
.y
, color
, text
);
134 void bzDrawFillP(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, uint16_t p
) {
135 DRAW_DATA_DISPATCH(drawQueue
, bzFillP
, p
)
138 void bzDrawSetPaletteColor(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int palette
, int colorIdx
, int color
) {
139 DRAW_DATA_DISPATCH(drawQueue
, bzSetPaletteColor
, palette
, colorIdx
, color
)
142 void bzDrawSetOutputBuffer(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, int idx
) {
143 DRAW_DATA_DISPATCH(drawQueue
, bzSetOutputBuffer
, idx
)
146 void bzDrawMap(BZDrawQueueID drawQueue
, uint8_t sortIdx
, const BZMatrix
*mtx
, BZTilemapID tilemap
, int tx
, int ty
, int x
, int y
, int mw
, int mh
, BZIdentifierHash tag
) {
147 DRAW_DATA_DISPATCH(drawQueue
, bzGfxMap
, tilemap
, tx
, ty
, x
, y
, mw
, mh
, tag
)