Compare commits

...

2 Commits

15 changed files with 45 additions and 26 deletions

6
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "intern/aliases"] [submodule "intern/wizapp"]
path = intern/aliases path = intern/wizapp
url = https://git.thewizardapprentice.com/abdelrahman/c-cpp-aliases.git url = https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib.git

18
compile
View File

@ -1,9 +1,21 @@
#!/bin/bash #!/bin/bash
CC=clang CC=clang
CFLAGS="-g -Wall -Iinclude -Iintern $(pkg-config --cflags sdl2)" CFLAGS="-g -Wall $(pkg-config --cflags sdl2)"
LIBS="$(pkg-config --libs sdl2) -lm" LIBS="$(pkg-config --libs sdl2) -lm"
SRC=src/*.c INCLUDE="\
-Iinclude \
-Iintern/wizapp/aliases \
-Iintern/wizapp/cpath/include \
-Iintern/wizapp/dstr/include \
$(find intern/wizapp/mem/include/ -type d | xargs -I{} printf "-I{} ") \
"
SRC="\
intern/wizapp/cpath/src/*.c \
intern/wizapp/dstr/src/*.c \
intern/wizapp/mem/src/*/*.c \
src/*.c \
"
OUT=main OUT=main
(set -x ; $CC $CFLAGS $LIBS $SRC -o $OUT) (set -x ; $CC $CFLAGS $INCLUDE $LIBS $SRC -o $OUT)

View File

@ -1,7 +1,7 @@
#ifndef COMPOSITOR_H #ifndef COMPOSITOR_H
#define COMPOSITOR_H #define COMPOSITOR_H
#include "aliases/aliases.h" #include "aliases.h"
i32 run_main_loop(void); i32 run_main_loop(void);

View File

@ -1,7 +1,7 @@
#ifndef MATH_UTILS_H #ifndef MATH_UTILS_H
#define MATH_UTILS_H #define MATH_UTILS_H
#include "aliases/aliases.h" #include "aliases.h"
#define square(x) (x * x) #define square(x) (x * x)
#define absolute(x) (x < 0.0 ? x * -1.0 : x) #define absolute(x) (x < 0.0 ? x * -1.0 : x)

View File

@ -1,7 +1,7 @@
#ifndef NODES_H #ifndef NODES_H
#define NODES_H #define NODES_H
#include "aliases/aliases.h" #include "aliases.h"
#include "ui.h" #include "ui.h"
#define MAX_NODES 1024 #define MAX_NODES 1024

View File

@ -1,7 +1,7 @@
#ifndef COMP_OPS_H #ifndef COMP_OPS_H
#define COMP_OPS_H #define COMP_OPS_H
#include "aliases/aliases.h" #include "aliases.h"
#include "nodes.h" #include "nodes.h"
enum comp_ops { enum comp_ops {
@ -18,7 +18,7 @@ i32 comp_sub(i32 a, i32 b);
i32 comp_mul(i32 a, i32 b); i32 comp_mul(i32 a, i32 b);
i32 comp_div(i32 a, i32 b); i32 comp_div(i32 a, i32 b);
INTERNAL node_func ops[COUNT_COMP_OPS] = { internal node_func ops[COUNT_COMP_OPS] = {
[COMP_OP_ADD] = comp_add, [COMP_OP_ADD] = comp_add,
[COMP_OP_SUB] = comp_sub, [COMP_OP_SUB] = comp_sub,
[COMP_OP_MUL] = comp_mul, [COMP_OP_MUL] = comp_mul,

View File

@ -2,7 +2,7 @@
#define UI_H #define UI_H
#include "SDL_events.h" #include "SDL_events.h"
#include "aliases/aliases.h" #include "aliases.h"
#include "window.h" #include "window.h"
#include <stdbool.h> #include <stdbool.h>

View File

@ -1,7 +1,7 @@
#ifndef WINDOW_H #ifndef WINDOW_H
#define WINDOW_H #define WINDOW_H
#include "aliases/aliases.h" #include "aliases.h"
#include <SDL2/SDL_pixels.h> #include <SDL2/SDL_pixels.h>
#include <SDL2/SDL_render.h> #include <SDL2/SDL_render.h>
#include <SDL2/SDL_video.h> #include <SDL2/SDL_video.h>

@ -1 +0,0 @@
Subproject commit f95f3aa499910286876c1f2cdceea8146ebcf7b1

1
intern/wizapp Submodule

@ -0,0 +1 @@
Subproject commit b8db582098a866aa56c62d0b2b6351ea08411f6b

View File

@ -1,4 +1,5 @@
#include "aliases/aliases.h" #include "aliases.h"
#include "mem_arena.h"
#include "nodes.h" #include "nodes.h"
#include "ops.h" #include "ops.h"
#include "ui.h" #include "ui.h"
@ -15,8 +16,11 @@
#define WINDOW_WIDTH 1280 #define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720 #define WINDOW_HEIGHT 720
#define ARENA_CAPACITY 1 * 1024 * 1024
typedef struct compositor compositor; typedef struct compositor compositor;
struct compositor { struct compositor {
Arena *arena;
window windows[MAX_WINDOWS]; window windows[MAX_WINDOWS];
u32 active_window; u32 active_window;
SDL_Event event; SDL_Event event;
@ -39,8 +43,9 @@ i32 run_main_loop(void) {
compositor comp = {0}; compositor comp = {0};
init_ui_ctx(&(comp.ctx)); init_ui_ctx(&(comp.ctx));
mem_arena_init(&comp.arena, ARENA_CAPACITY);
comp.nodes = (node *)malloc(sizeof(node) * MAX_NODES); comp.nodes = (node *)mem_arena_alloc(comp.arena, sizeof(node) * MAX_NODES);
window *main_window = &(comp.windows[0]); window *main_window = &(comp.windows[0]);
window *toolbox = &(comp.windows[1]); window *toolbox = &(comp.windows[1]);
@ -165,6 +170,8 @@ i32 run_main_loop(void) {
SDL_Quit(); SDL_Quit();
mem_arena_free(&comp.arena);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,4 +1,4 @@
#include "aliases/aliases.h" #include "aliases.h"
#include "compositor.h" #include "compositor.h"
i32 main(void) { return run_main_loop(); } i32 main(void) { return run_main_loop(); }

View File

@ -1,5 +1,5 @@
#include "ops.h" #include "ops.h"
#include "aliases/aliases.h" #include "aliases.h"
i32 comp_add(i32 a, i32 b) { return a + b; } i32 comp_add(i32 a, i32 b) { return a + b; }

View File

@ -1,6 +1,6 @@
#include "ui.h" #include "ui.h"
#include "SDL_events.h" #include "SDL_events.h"
#include "aliases/aliases.h" #include "aliases.h"
#include "math_utils.h" #include "math_utils.h"
#include "window.h" #include "window.h"
#include <math.h> #include <math.h>
@ -12,8 +12,8 @@
line ui_noodle(const window *wnd, ui_ctx *ctx, line ln, line ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
ui_elem_colours colours); ui_elem_colours colours);
INTERNAL bool aabb(rect rec, i32 x, i32 y); internal bool aabb(rect rec, i32 x, i32 y);
INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length); internal line line_from_origin(point origin, f64 angle, i32 line_length);
void init_ui_ctx(ui_ctx *ctx) { void init_ui_ctx(ui_ctx *ctx) {
*ctx = (ui_ctx){0}; *ctx = (ui_ctx){0};
@ -255,12 +255,12 @@ line ui_noodle(const window *wnd, ui_ctx *ctx, line ln,
return ln; return ln;
} }
INTERNAL bool aabb(rect rec, i32 x, i32 y) { internal bool aabb(rect rec, i32 x, i32 y) {
return x > rec.topleft.x && x <= rec.topleft.x + rec.w && y > rec.topleft.y && return x > rec.topleft.x && x <= rec.topleft.x + rec.w && y > rec.topleft.y &&
y <= rec.topleft.y + rec.h; y <= rec.topleft.y + rec.h;
} }
INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length) { internal line line_from_origin(point origin, f64 angle, i32 line_length) {
f64 rad = radians(angle); f64 rad = radians(angle);
f64 direction = angle / absolute(angle) * -1; f64 direction = angle / absolute(angle) * -1;

View File

@ -1,12 +1,12 @@
#include "window.h" #include "window.h"
#include "aliases/aliases.h" #include "aliases.h"
#include "math_utils.h" #include "math_utils.h"
#include <SDL2/SDL_rect.h> #include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h> #include <SDL2/SDL_render.h>
#include <SDL2/SDL_video.h> #include <SDL2/SDL_video.h>
#include <stdbool.h> #include <stdbool.h>
INTERNAL inline bool inside_triangle(triangle tri, point p); internal inline bool inside_triangle(triangle tri, point p);
bool init_window(window *wnd, const char *title, u32 width, u32 height, i32 x, bool init_window(window *wnd, const char *title, u32 width, u32 height, i32 x,
i32 y) { i32 y) {
@ -162,7 +162,7 @@ void fill_quad(const window *wnd, quad qd, colour colour) {
fill_triangle(wnd, t1, colour); fill_triangle(wnd, t1, colour);
} }
INTERNAL inline bool inside_triangle(triangle tri, point p) { internal inline bool inside_triangle(triangle tri, point p) {
// Based on the following video: // Based on the following video:
// https://www.youtube.com/watch?v=HYAgJN3x4GA // https://www.youtube.com/watch?v=HYAgJN3x4GA
f32 cy_min_ay = tri.p2.y - tri.p0.y; f32 cy_min_ay = tri.p2.y - tri.p0.y;