]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Move types to dragontype submodule
authorElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Aug 2021 14:23:15 +0000 (16:23 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 24 Aug 2021 14:23:15 +0000 (16:23 +0200)
32 files changed:
.gitmodules
deps/dragontype [new submodule]
src/CMakeLists.txt
src/array.c [deleted file]
src/array.h [deleted file]
src/bintree.c [deleted file]
src/bintree.h [deleted file]
src/client/camera.h
src/client/client.h
src/client/client_commands.c
src/client/client_map.h
src/client/client_player.h
src/client/facecache.c
src/client/facecache.h
src/client/hud.h
src/client/object.h
src/client/scene.c
src/client/texture.c
src/environment.h
src/list.c [deleted file]
src/list.h [deleted file]
src/map.h
src/node.h
src/perlin.c
src/perlin.h
src/queue.c [deleted file]
src/queue.h [deleted file]
src/server/biomes.h
src/server/server.h
src/types.c [deleted file]
src/types.h [deleted file]
src/util.h

index 6c23b94f7261fd3c697456f859eba60cca9a347d..f1266074eb6c11acb356fa086f6f08fb8e00f9f0 100644 (file)
@@ -7,3 +7,6 @@
 [submodule "deps/stb"]
        path = deps/stb
        url = https://github.com/nothings/stb
+[submodule "deps/dragontype"]
+       path = deps/dragontype
+       url = https://github.com/dragonblocks/dragontype
diff --git a/deps/dragontype b/deps/dragontype
new file mode 160000 (submodule)
index 0000000..df31600
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit df31600e08952b5911e0669da98491593997c623
index f04e38f64784619b421862a2768060dd8f671fa6..b8e67f88cd42f2505c5a882c6cc227d40f443dc1 100644 (file)
@@ -17,8 +17,10 @@ link_libraries(
        z
 )
 
+set(DEPS_DIR "${CMAKE_SOURCE_DIR}/../deps/")
+
 include_directories(SYSTEM
-       "${CMAKE_SOURCE_DIR}/../deps/"
+       ${DEPS_DIR}
 )
 
 include_directories(BEFORE
@@ -28,17 +30,14 @@ include_directories(BEFORE
 add_compile_options(-Wall -Wextra -Wpedantic -Werror)
 
 set(SOURCES_COMMON
-       array.c
-       bintree.c
        environment.c
-       list.c
        map.c
-       signal_handlers.c
-       util.c
-       types.c
        node.c
        perlin.c
-       queue.c
+       signal_handlers.c
+       util.c
+       "${DEPS_DIR}/dragontype/implementation.c"
+       "${DEPS_DIR}/perlin/perlin.c"
 )
 
 add_executable(Dragonblocks
diff --git a/src/array.c b/src/array.c
deleted file mode 100644 (file)
index d5de936..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#include <assert.h>
-#include <string.h>
-#include <stdlib.h>
-#include "array.h"
-
-Array array_create(size_t membsiz)
-{
-       return (Array) {
-               .membsiz = membsiz,
-               .siz = 0,
-               .cap = 0,
-               .ptr = NULL,
-       };
-}
-
-
-static void array_realloc(Array *array)
-{
-       if (array->siz > array->cap) {
-               array->cap = array->siz + ARRAY_REALLOC_EXTRA;
-               array->ptr = realloc(array->ptr, array->cap * array->membsiz);
-       }
-}
-
-static void array_alloc(Array *array, size_t siz)
-{
-       array->siz += siz;
-       array_realloc(array);
-}
-
-void array_insert(Array *array, void *elem, size_t idx)
-{
-       size_t oldsiz = array->siz;
-       array_alloc(array, 1);
-
-       char *iptr = (char *) array->ptr + idx * array->membsiz;
-       memmove(iptr + array->membsiz, iptr, (oldsiz - idx) * array->membsiz);
-       memcpy(iptr, elem, array->membsiz);
-}
-
-void array_append(Array *array, void *elem)
-{
-       size_t oldsiz = array->siz;
-       array_alloc(array, 1);
-
-       memcpy((char *) array->ptr + oldsiz * array->membsiz, elem, array->membsiz);
-}
-
-void array_copy(Array *array, void **ptr, size_t *count)
-{
-       *count = array->siz;
-       size_t size = array->siz * array->membsiz;
-       *ptr = malloc(size);
-       memcpy(*ptr, array->ptr, size);
-}
diff --git a/src/array.h b/src/array.h
deleted file mode 100644 (file)
index a887ad5..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _ARRAY_H_
-#define _ARRAY_H_
-
-#define ARRAY_REALLOC_EXTRA 25
-
-#include <stddef.h>
-#include <stdbool.h>
-#include "types.h"
-
-typedef struct
-{
-       size_t membsiz;
-       size_t siz, cap;
-       void *ptr;
-} Array;
-
-Array array_create(size_t membsiz);
-void array_insert(Array *array, void *elem, size_t idx);
-void array_append(Array *array, void *elem);
-void array_copy(Array *array, void **ptr, size_t *count);
-
-#endif
diff --git a/src/bintree.c b/src/bintree.c
deleted file mode 100644 (file)
index f68fa1e..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include "bintree.h"
-
-Bintree bintree_create(size_t key_size)
-{
-       return (Bintree) {
-               .root = NULL,
-               .key_size = key_size,
-       };
-}
-
-static BintreeNode **search_recursive(Bintree *tree, BintreeNode **nodeptr, void *key)
-{
-       if (*nodeptr) {
-               int cond;
-
-               if ((cond = memcmp((*nodeptr)->key, key, tree->key_size)) == 0)
-                       return nodeptr;
-               else if (cond > 0)
-                       return search_recursive(tree, &(*nodeptr)->left, key);
-               else
-                       return search_recursive(tree, &(*nodeptr)->right, key);
-       } else {
-               return nodeptr;
-       }
-}
-
-BintreeNode **bintree_search(Bintree *tree, void *key)
-{
-       return search_recursive(tree, &tree->root, key);
-}
-
-void bintree_add_node(Bintree *tree, BintreeNode **nodeptr, void *key, void *value)
-{
-       *nodeptr = malloc(sizeof(BintreeNode));
-       (*nodeptr)->key = malloc(tree->key_size);
-       memcpy((*nodeptr)->key, key, tree->key_size);
-       (*nodeptr)->value = value;
-       (*nodeptr)->left = (*nodeptr)->right = NULL;
-}
-
-static void free_recursive(BintreeNode *node, BintreeFreeFunction func, void *arg)
-{
-       if (node) {
-               free_recursive(node->left, func, arg);
-               free_recursive(node->right, func, arg);
-               free(node->key);
-               if (func)
-                       func(node->value, arg);
-               free(node);
-       }
-}
-
-void bintree_clear(Bintree *tree, BintreeFreeFunction func, void *arg)
-{
-       if (tree) {
-               free_recursive(tree->root, func, arg);
-               tree->root = NULL;
-       }
-}
diff --git a/src/bintree.h b/src/bintree.h
deleted file mode 100644 (file)
index 49efe15..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _BINTREE_H_
-#define _BINTREE_H_
-
-#include <stddef.h>
-
-typedef struct BintreeNode
-{
-       void *key;
-       void *value;
-       struct BintreeNode *left;
-       struct BintreeNode *right;
-} BintreeNode;
-
-typedef struct
-{
-       BintreeNode *root;
-       size_t key_size;
-} Bintree;
-
-typedef void (*BintreeFreeFunction)(void *value, void *arg);
-
-Bintree bintree_create(size_t key_size);
-BintreeNode **bintree_search(Bintree *tree, void *key);
-void bintree_add_node(Bintree *tree, BintreeNode **nodeptr, void *key, void *value);
-void bintree_clear(Bintree *tree, BintreeFreeFunction func, void *arg);
-
-#endif
index bc7d57c826b58246b18ba36ec54fcef46ba920ad..e5f7f456bf4a53c563f6933bfab6ebfcfde23512 100644 (file)
@@ -4,7 +4,7 @@
 #include <GL/glew.h>
 #include <GLFW/glfw3.h>
 #include <linmath.h/linmath.h>
-#include "types.h"
+#include <dragontype/number.h>
 
 extern struct Camera
 {
index d5ac964be8bde8d9f656759d9465a2ee14451e7b..bca96f807286a39a481452ca29c5b749a29e8950 100644 (file)
@@ -3,11 +3,11 @@
 
 #include <stdbool.h>
 #include <pthread.h>
+#include <dragontype/number.h>
 #include "client/client_commands.h"
 #include "client/scene.h"
 #include "server/server_commands.h"
 #include "network.h"
-#include "types.h"
 
 #ifdef RELEASE
        #define RESSOURCEPATH ""
index cf3cf5439e59abbeedabaec98da9c40eeff8cc27..c2cdc60657d8876cfabfed17da68340ebd07fab3 100644 (file)
@@ -1,8 +1,8 @@
 #include <stdio.h>
 #include <unistd.h>
+#include <dragontype/number.h>
 #include "client/client.h"
 #include "client/client_map.h"
-#include "types.h"
 #include "util.h"
 
 static bool disconnect_handler(unused Client *client, bool good)
index 657dcb1dd4e15b9cdb49ee292215e1bc2d68b0bc..ce4056b9cdb280850ea5533b6e5a279d78522964 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <stdbool.h>
 #include <pthread.h>
+#include <dragontype/queue.h>
 #include "map.h"
-#include "queue.h"
 #include "client/object.h"
 
 typedef enum
index 1621aa46008647010f42f2391cb0ece92cd4cde1..2bd163a7b9bb714982738841191a23a55b3f8832 100644 (file)
@@ -2,10 +2,10 @@
 #define _CLIENT_PLAYER_H_
 
 #include <pthread.h>
+#include <dragontype/number.h>
 #include "client/client.h"
 #include "client/hud.h"
 #include "client/object.h"
-#include "types.h"
 
 extern struct ClientPlayer
 {
index b902c90f0d40740e301fdf284a44f2e7bc3eed03..09ea7d69cc62110b33773d64bea086dac7c092af 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdlib.h>
+#include <dragontype/array.h>
 #include "client/facecache.h"
-#include "array.h"
 
 static struct
 {
index 847b739603f3d8d70edc21886b472e9f2a01c1c9..2900cd53f84132b82c93a1720afc29322bc24e1e 100644 (file)
@@ -2,7 +2,7 @@
 #define _FACECACHE_H_
 
 #include <pthread.h>
-#include "types.h"
+#include <dragontype/number.h>
 
 v3s32 facecache_face(size_t i, v3s32 *base);
 size_t facecache_count(u32 size);
index 8f81eb93b05453bbb373e96df344c300e6a774af..d58af37c5aba13cb1e6c019d559c266ae9db8dde 100644 (file)
@@ -3,10 +3,10 @@
 
 #include <stdbool.h>
 #include <linmath.h/linmath.h>
+#include <dragontype/number.h>
+#include <dragontype/list.h>
 #include "client/font.h"
 #include "client/texture.h"
-#include "list.h"
-#include "types.h"
 
 typedef enum
 {
index 7b9dab89a706e92a85239d9a545fceb510b15f47..3e06b3d2bc56ee582f11435ff9410cc2c045f0fc 100644 (file)
@@ -6,11 +6,11 @@
 #include <GL/glew.h>
 #include <GL/gl.h>
 #include <linmath.h/linmath.h>
+#include <dragontype/array.h>
+#include <dragontype/number.h>
 #include "client/mesh.h"
 #include "client/texture.h"
 #include "client/vertex.h"
-#include "array.h"
-#include "types.h"
 
 typedef struct {
        GLfloat x, y, z;
index d4708519b229bdd91a00a9c940f97809cd4a9a9d..99935f2e2d382862cbbd8e07d4a187402b414fad 100644 (file)
@@ -2,11 +2,11 @@
 #include <stdio.h>
 #include <pthread.h>
 #include <linmath.h/linmath.h>
+#include <dragontype/list.h>
 #include "client/camera.h"
 #include "client/client.h"
 #include "client/scene.h"
 #include "client/shader.h"
-#include "list.h"
 #include "util.h"
 
 static struct
index 994f027a1d9f70de3835dc1883da964484ec3f4b..6393bb3c9ab71c7c9485e2a209873d3cfe303503 100644 (file)
@@ -1,8 +1,8 @@
 #define STB_IMAGE_IMPLEMENTATION
 #include <stb/stb_image.h>
 #include <stdbool.h>
+#include <dragontype/list.h>
 #include "client/texture.h"
-#include "list.h"
 #include "util.h"
 
 static List textures;
index 1de120c775092f5d3dfeac38a119ca0ea06eea3b..bacda150956806961274adde2b91775f19d07ff1 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _ENVIRONMENT_H_
 #define _ENVIRONMENT_H_
 
-#include "types.h"
+#include <dragontype/number.h>
 
 f64 get_humidity(v3s32 pos);
 f64 get_temperature(v3s32 pos);
diff --git a/src/list.c b/src/list.c
deleted file mode 100644 (file)
index 7388eaf..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "list.h"
-
-bool list_compare_default(void *v1, void *v2)
-{
-       return v1 == v2;
-}
-
-bool list_compare_string(void *v1, void *v2)
-{
-       return strcmp(v1, v2) == 0;
-}
-
-List list_create(ListComparator cmp)
-{
-       return (List) {
-               .cmp = cmp ? cmp : list_compare_default,
-               .first = NULL,
-       };
-}
-
-void list_clear(List *list)
-{
-       list_clear_func(list, NULL, NULL);
-}
-
-void list_clear_func(List *list, void (*func)(void *key, void *value, void *arg), void *arg)
-{
-       for (ListPair *pair = list->first; pair != NULL;) {
-               ListPair *next = pair->next;
-               if (func)
-                       func(pair->key, pair->value, arg);
-               free(pair);
-               pair = next;
-       }
-       list->first = NULL;
-}
-
-static ListPair *make_pair(void *key, void *value)
-{
-       ListPair *pair = malloc(sizeof(ListPair));
-       pair->key = key;
-       pair->value = value;
-       pair->next = NULL;
-       return pair;
-}
-
-bool list_put(List *list, void *key, void *value)
-{
-       ListPair **pairptr;
-       for (pairptr = &list->first; *pairptr != NULL; pairptr = &(*pairptr)->next) {
-               if (list->cmp((*pairptr)->key, key))
-                       return false;
-       }
-       *pairptr = make_pair(key, value);
-       return true;
-}
-
-void *list_get_cached(List *list, void *key, void *(*provider)(void *key))
-{
-       ListPair **pairptr;
-       for (pairptr = &list->first; *pairptr != NULL; pairptr = &(*pairptr)->next) {
-               if (list->cmp((*pairptr)->key, key))
-                       return (*pairptr)->value;
-       }
-       return (*pairptr = make_pair(key, provider(key)))->value;
-}
-
-void list_set(List *list, void *key, void *value)
-{
-       ListPair **pairptr;
-       for (pairptr = &list->first; *pairptr != NULL; pairptr = &(*pairptr)->next) {
-               if (list->cmp((*pairptr)->key, key))
-                       break;
-       }
-       *pairptr = make_pair(key, value);
-}
-
-void *list_delete(List *list, void *key)
-{
-       for (ListPair **pairptr = &list->first; *pairptr != NULL; pairptr = &(*pairptr)->next) {
-               if (list->cmp((*pairptr)->key, key)) {
-                       ListPair *pair = *pairptr;
-                       void *value = (*pairptr)->value;
-                       *pairptr = pair->next;
-                       free(pair);
-                       return value;
-               }
-       }
-       return NULL;
-}
-
-void *list_get(List *list, void *key)
-{
-       for (ListPair *pair = list->first; pair != NULL; pair = pair->next)
-               if (list->cmp(pair->key, key))
-                       return pair->value;
-       return NULL;
-}
diff --git a/src/list.h b/src/list.h
deleted file mode 100644 (file)
index 065100b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef _List_H_
-#define _List_H_
-
-#include <stdbool.h>
-
-#define ITERATE_LIST(list, pair) for (ListPair *pair = (list)->first; pair != NULL; pair = pair->next)
-
-typedef struct ListPair
-{
-       struct ListPair *next;
-       void *key;
-       void *value;
-} ListPair;
-
-typedef bool (*ListComparator)(void *v1, void *v2);
-
-typedef struct
-{
-       ListComparator cmp;
-       ListPair *first;
-} List;
-
-bool list_compare_default(void *v1, void *v2);
-bool list_compare_string(void *v1, void *v2);
-
-List list_create(ListComparator cmp);
-void list_clear(List *list);
-void list_clear_func(List *list, void (*func)(void *key, void *value, void *arg), void *arg);
-
-bool list_put(List *list, void *key, void *value);
-void *list_get_cached(List *list, void *key, void *(*provider)(void *key));
-void list_set(List *list, void *key, void *value);
-void *list_get(List *list, void *key);
-void *list_delete(List *list, void *key);
-
-bool list_serialize(int fd, List *list); // ToDo
-bool list_deserialize(int fd, List *list); // ToDo
-
-#endif
index c60293fd1a78320323ba42f00836966d9723218e..25827f07702a751e9bafccdf885658db129ee20d 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -3,10 +3,10 @@
 
 #include <stdbool.h>
 #include <pthread.h>
-#include "bintree.h"
-#include "list.h"
+#include <dragontype/bintree.h>
+#include <dragontype/number.h>
+#include <dragontype/list.h>
 #include "node.h"
-#include "types.h"
 
 #define MAPBLOCK_SIZE 16
 #define ITERATE_MAPBLOCK for (u8 x = 0; x < MAPBLOCK_SIZE; x++) for (u8 y = 0; y < MAPBLOCK_SIZE; y++) for (u8 z = 0; z < MAPBLOCK_SIZE; z++)
index 626b5d79403bfea216c614496c0f3dbf12f3e7de..45e5231604b902e52b54200fd67b744d0972785a 100644 (file)
@@ -2,7 +2,7 @@
 #define _NODE_H_
 
 #include <stdbool.h>
-#include "types.h"
+#include <dragontype/number.h>
 
 typedef enum
 {
index 82bff9560470d58fce4afedf3d50e0ff665795b0..d5bd44622a8feea3f41e2f6be9364b6f3fedef0d 100644 (file)
@@ -1,6 +1,3 @@
 #include "perlin.h"
 
-// include perlin submodule implementation
-#include <perlin/perlin.c>
-
 int seed = 0;
index c1af34be0b39bf4726b63dddd6da5b7ed763cc38..e90b388d00d0ec8a6ae0e3b7e5e108e6043cd8b2 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _PERLIN_H_
 #define _PERLIN_H_
 
-#include <perlin/perlin.h> // include perlin submodule header file
+#include <perlin/perlin.h>
 
 typedef enum
 {
diff --git a/src/queue.c b/src/queue.c
deleted file mode 100644 (file)
index 04aaccd..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <stdlib.h>
-#include "queue.h"
-
-Queue *queue_create()
-{
-       Queue *queue = malloc(sizeof(Queue));
-       queue->list = list_create(NULL);
-       pthread_mutex_init(&queue->mtx, NULL);
-       return queue;
-}
-
-void queue_delete(Queue *queue)
-{
-       pthread_mutex_destroy(&queue->mtx);
-       list_clear(&queue->list);
-       free(queue);
-}
-
-void queue_enqueue(Queue *queue, void *elem)
-{
-       pthread_mutex_lock(&queue->mtx);
-       list_put(&queue->list, elem, NULL);
-       pthread_mutex_unlock(&queue->mtx);
-}
-
-void *dequeue(Queue *queue)
-{
-       return queue_dequeue_callback(queue, NULL);
-}
-
-void *queue_dequeue_callback(Queue *queue, void (*callback)(void *elem))
-{
-       pthread_mutex_lock(&queue->mtx);
-       void *elem = NULL;
-       ListPair **lptr = &queue->list.first;
-       if (*lptr) {
-               elem = (*lptr)->key;
-               ListPair *next = (*lptr)->next;
-               free(*lptr);
-               *lptr = next;
-
-               if (callback)
-                       callback(elem);
-       }
-       pthread_mutex_unlock(&queue->mtx);
-       return elem;
-}
diff --git a/src/queue.h b/src/queue.h
deleted file mode 100644 (file)
index d669026..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _QUEUE_H_
-#define _QUEUE_H_
-
-#include <pthread.h>
-#include "list.h"
-
-typedef struct
-{
-       List list;
-       pthread_mutex_t mtx;
-} Queue;
-
-Queue *queue_create();
-void queue_delete(Queue *queue);
-void queue_enqueue(Queue *queue, void *elem);
-void *queue_dequeue(Queue *queue);
-void *queue_dequeue_callback(Queue *queue, void (*callback)(void *elem));
-
-#endif
index 1481e3fed3ccbccbb693bf1a5568a9ddeac19f7e..0cf488105648575de4ff7f3aa1d820bbc4c0517a 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _BIOMES_H_
 #define _BIOMES_H_
 
-#include "types.h"
+#include <dragontype/number.h>
 #include "map.h"
 #include "perlin.h"
 
index f9a54c5c7acefd500140ec78232e29b899ef7e6c..f53289221a8b6bf6145d343a3205a5c9800cbb81 100644 (file)
@@ -3,12 +3,12 @@
 
 #include <pthread.h>
 #include <netinet/in.h>
+#include <dragontype/number.h>
+#include <dragontype/list.h>
 #include "client/client_commands.h"
 #include "server/database.h"
 #include "server/server_commands.h"
-#include "list.h"
 #include "network.h"
-#include "types.h"
 
 typedef struct
 {
diff --git a/src/types.c b/src/types.c
deleted file mode 100644 (file)
index 4a79da4..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <endian.h>
-#include <poll.h>
-#include "types.h"
-
-bool read_full(int fd, char *buffer, size_t size)
-{
-       size_t n_read_total = 0;
-       int n_read;
-       while (n_read_total < size) {
-               if ((n_read = read(fd, buffer + n_read_total, size - n_read_total)) == -1) {
-                       perror("read");
-                       return false;
-               }
-               n_read_total += n_read;
-       }
-       return true;
-}
-
-#define htobe8(x) x
-#define be8toh(x) x
-
-#define READVEC(type, n) \
-       type buf[n]; \
-       for (int i = 0; i < n; i++) { \
-               if (! read_ ## type(fd, &buf[i])) \
-                       return false; \
-       }
-
-#define WRITEVEC(type, n) \
-       for (int i = 0; i < n; i++) { \
-               if (! write_ ## type(fd, vec[i])) \
-                       return false; \
-       } \
-       return true;
-
-#define DEFVEC(type) \
-       bool read_v2 ## type(int fd, v2 ## type *ptr) \
-       { \
-               READVEC(type, 2) \
-               ptr->x = buf[0]; \
-               ptr->y = buf[1]; \
-               return true; \
-       } \
-       bool write_v2 ## type(int fd, v2 ## type val) \
-       { \
-               type vec[2] = {val.x, val.y}; \
-               WRITEVEC(type, 2) \
-       } \
-       bool v2 ## type ## _equals(v2 ## type a, v2 ## type b) \
-       { \
-               return a.x == b.x && a.y == b.y; \
-       } \
-       v2 ## type v2 ## type ## _add(v2 ## type a, v2 ## type b) \
-       { \
-               return (v2 ## type) {a.x + b.x, a.y + b.y}; \
-       } \
-       bool read_v3 ## type(int fd, v3 ## type *ptr) \
-       { \
-               READVEC(type, 3) \
-               ptr->x = buf[0]; \
-               ptr->y = buf[1]; \
-               ptr->z = buf[2]; \
-               return true; \
-       } \
-       bool write_v3 ## type(int fd, v3 ## type val) \
-       { \
-               type vec[3] = {val.x, val.y, val.z}; \
-               WRITEVEC(type, 3) \
-       } \
-       bool v3 ## type ## _equals(v3 ## type a, v3 ## type b) \
-       { \
-               return a.x == b.x && a.y == b.y && a.z == b.z; \
-       } \
-       v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b) \
-       { \
-               return (v3 ## type) {a.x + b.x, a.y + b.y, a.z + b.z}; \
-       }
-
-#define DEFTYP(type, bits) \
-       bool read_ ## type(int fd, type *buf) \
-       { \
-               u ## bits encoded; \
-               if (! read_full(fd, (char *) &encoded, sizeof(type))) \
-                       return false; \
-               *buf = be ## bits ## toh(encoded); \
-               return true; \
-       } \
-       bool write_ ## type(int fd, type val) \
-       { \
-               u ## bits encoded = htobe ## bits(val); \
-               if (write(fd, &encoded, sizeof(encoded)) == -1) { \
-                       perror("write"); \
-                       return false; \
-               } \
-               return true; \
-       } \
-       DEFVEC(type)
-
-#define DEFTYPES(bits) \
-       DEFTYP(s ## bits, bits) \
-       DEFTYP(u ## bits, bits)
-
-DEFTYPES(8)
-DEFTYPES(16)
-DEFTYPES(32)
-DEFTYPES(64)
-
-#define DEFFLOAT(type) \
-       bool read_ ## type(int fd, type *buf) \
-       { \
-               if (! read_full(fd, (char *) buf, sizeof(type))) \
-                       return false; \
-               return true; \
-       } \
-       bool write_ ## type(int fd, type val) \
-       { \
-               if (write(fd, &val, sizeof(val)) == -1) { \
-                       perror("write"); \
-                       return false; \
-               } \
-               return true; \
-       } \
-       DEFVEC(type)
-
-DEFFLOAT(f32)
-DEFFLOAT(f64)
diff --git a/src/types.h b/src/types.h
deleted file mode 100644 (file)
index 025e661..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef _TYPES_H_
-#define _TYPES_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <stddef.h>
-
-bool read_full(int fd, char *buffer, size_t size);
-
-#define DEFRW(type) \
-       bool read_ ## type(int fd, type *ptr); \
-       bool write_ ## type(int fd, type val);
-
-#define DEFBOX(type) \
-       typedef struct {v ## type min; v ## type max;} aabb ## type;
-
-#define DEFVEC(type) \
-       typedef struct {type x, y;} v2 ## type; \
-       DEFRW(v2 ## type) \
-       DEFBOX(2 ## type) \
-       bool v2 ## type ## _equals(v2 ## type a, v2 ## type b); \
-       v2 ## type v2 ## type ## _add(v2 ## type a, v2 ## type b); \
-       typedef struct {type x, y, z;} v3 ## type; \
-       DEFRW(v3 ## type) \
-       DEFBOX(3 ## type) \
-       bool v3 ## type ## _equals(v3 ## type a, v3 ## type b); \
-       v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b);
-
-#define DEFTYP(from, to) \
-       typedef from to; \
-       DEFRW(to) \
-       DEFVEC(to)
-
-#define DEFTYPES(bits) \
-       DEFTYP(int ## bits ## _t, s ## bits) \
-       DEFTYP(uint ## bits ## _t, u ## bits)
-
-DEFTYPES(8)
-DEFTYPES(16)
-DEFTYPES(32)
-DEFTYPES(64)
-
-typedef float f32;
-typedef double f64;
-
-DEFTYP(float, f32)
-DEFTYP(double, f64)
-
-#undef DEFRW
-#undef DEFBOX
-#undef DEFVEC
-#undef DEFTYP
-#undef DEFTYPES
-
-#endif
index c2761f60d3872f7c29837ce6bdca60162f33c677..ec63c1c356c0d035c9a9750b977302b4537a2c5e 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <stdbool.h>
 #include <arpa/inet.h>
-#include "types.h"
+#include <dragontype/number.h>
 
 #define ever (;;)                                                                                                              // infinite for loop with style
 #define INBRACES(str) str ? "(" : "", str ? str : "", str ? ")" : ""   // wrapper for printf to optionally add a message in braces if message is not NULL