diff options
author | 2025-05-19 16:19:10 +0200 | |
---|---|---|
committer | 2025-05-19 16:19:10 +0200 | |
commit | d658971135bc1016325b223a3b21007be5fcc6e8 (patch) | |
tree | 66b4a9221cd4a47df1ed5dd2f8c083cd9f145ce4 | |
parent | 45579c2a734ea8f679655d0a59f5535078ecb568 (diff) | |
download | tris-d658971135bc1016325b223a3b21007be5fcc6e8.tar.gz tris-d658971135bc1016325b223a3b21007be5fcc6e8.zip |
Add the Circle type
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/main/engine/engine.c | 23 | ||||
-rw-r--r-- | src/main/engine/types.h | 31 |
3 files changed, 56 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 31d9982..119a240 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(tris src/main/game/game.c src/main/util/list.h src/main/util/list.c - src/main/engine/ui/types.h) + src/main/engine/ui/types.h + src/main/engine/types.h) target_link_libraries(tris PRIVATE X11 GL GLX) diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index bea9554..92222bb 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -25,6 +25,7 @@ #include "../util.h" #include "ui/ui.h" #include "../util/list.h" +#include "types.h" #ifdef X11 #include <X11/Xlib.h> @@ -45,6 +46,7 @@ typedef struct Line { typedef struct Engine { UI *ui; + list_t *circles; void (*draw_frame)(); } Engine; @@ -66,6 +68,7 @@ engine_init(int w, int h) log_error("Error allocating memory for engine"); exit(EXIT_FAILURE); } + engine->circles = list_create(); width = w; height = h; @@ -77,6 +80,26 @@ engine_init(int w, int h) lines = list_create(); } +static Circle * +engine_new_circle(float cx, float cy, float r, int num_segments, int outline) +{ + Circle *circle = malloc(sizeof(Circle)); + circle->cx = cx; + circle->cy = cy; + circle->r = r; + circle->num_segments = num_segments; + circle->outline = outline; + + return circle; +} + +void +engine_draw_circle(float cx, float cy, float r, int num_segments, int outline) +{ + if (engine == NULL || engine->circles == NULL) return; + list_add(engine->circles, engine_new_circle(cx, cy, r, num_segments, outline)); +} + static Line * engine_new_line(int x1, int y1, int x2, int y2) { diff --git a/src/main/engine/types.h b/src/main/engine/types.h new file mode 100644 index 0000000..a87f087 --- /dev/null +++ b/src/main/engine/types.h @@ -0,0 +1,31 @@ +/*- +* Copyright (C) 2025 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of Tris Game. + * + * Tris Game is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tris Game is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tris Game. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __ENGINE_TYPES_H__ +#define __ENGINE_TYPES_H__ + +typedef struct Circle { + int outline; + float cx; + float cy; + float r; + int num_segments; +} Circle; + +#endif /* __ENGINE_TYPES_H__ */ |