|
1 #ifndef IPC_MAPCONN_H_ |
|
2 #define IPC_MAPCONN_H_ |
|
3 |
|
4 #include "../model/map.h" |
|
5 #include <stdint.h> |
|
6 |
|
7 #define MAPIMAGE_WIDTH 256 |
|
8 #define MAPIMAGE_HEIGHT 128 |
|
9 #define MAPIMAGE_BYTES (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT) |
|
10 |
|
11 struct _flib_mapconn; |
|
12 typedef struct _flib_mapconn flib_mapconn; |
|
13 |
|
14 /** |
|
15 * Start a new map rendering connection (mapconn). This means a listening socket |
|
16 * will be started on a random unused port, waiting for a connection from the |
|
17 * engine process. Once this connection is established, the required information |
|
18 * will be sent to the engine, and the reply is read. |
|
19 * |
|
20 * No NULL parameters allowed, returns NULL on failure. |
|
21 * Use flib_mapconn_destroy to free the returned object. |
|
22 */ |
|
23 flib_mapconn *flib_mapconn_create(char *seed, flib_map *mapdesc); |
|
24 |
|
25 /** |
|
26 * Destroy the mapconn object. Passing NULL is allowed and does nothing. |
|
27 * flib_mapconn_destroy may be called from inside a callback function. |
|
28 */ |
|
29 void flib_mapconn_destroy(flib_mapconn *conn); |
|
30 |
|
31 /** |
|
32 * Returns the port on which the mapconn is listening. Only fails if you |
|
33 * pass NULL (not allowed), in that case 0 is returned. |
|
34 */ |
|
35 int flib_mapconn_getport(flib_mapconn *conn); |
|
36 |
|
37 /** |
|
38 * Set a callback which will receive the rendered map if the rendering succeeds. |
|
39 * You can pass callback=NULL to unset a callback. |
|
40 * |
|
41 * Expected callback signature: |
|
42 * void handleSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) |
|
43 * |
|
44 * The context passed to the callback is the same pointer you provided when |
|
45 * registering the callback. bitmap is a pointer to a buffer of size MAPIMAGE_BYTES |
|
46 * containing a bit-packed image of size MAPIMAGE_WIDTH * MAPIMAGE_HEIGHT. |
|
47 * numHedgehogs is the number of hogs that fit on this map. |
|
48 * |
|
49 * The bitmap pointer passed to the callback belongs to the caller, |
|
50 * so it should not be stored elsewhere. Note that it remains valid |
|
51 * inside the callback method even if flib_mapconn_destroy is called. |
|
52 */ |
|
53 void flib_mapconn_onSuccess(flib_mapconn *conn, void (*callback)(void* context, const uint8_t *bitmap, int numHedgehogs), void *context); |
|
54 |
|
55 /** |
|
56 * Set a callback which will receive an error message if rendering fails. |
|
57 * You can pass callback=NULL to unset a callback. |
|
58 * |
|
59 * Expected callback signature: |
|
60 * void handleFailure(void *context, const char *errormessage) |
|
61 * |
|
62 * The context passed to the callback is the same pointer you provided when |
|
63 * registering the callback. |
|
64 * |
|
65 * The error message passed to the callback belongs to the caller, |
|
66 * so it should not be stored elsewhere. Note that it remains valid |
|
67 * inside the callback method even if flib_mapconn_destroy is called. |
|
68 */ |
|
69 void flib_mapconn_onFailure(flib_mapconn *conn, void (*callback)(void* context, const char *errormessage), void *context); |
|
70 |
|
71 /** |
|
72 * Perform I/O operations and call callbacks if something interesting happens. |
|
73 * Should be called regularly. |
|
74 */ |
|
75 void flib_mapconn_tick(flib_mapconn *conn); |
|
76 |
|
77 #endif |