Compare commits
No commits in common. "84cdb87a199f18a3ead6acceb41adc7268603f8f" and "10ba3d642da3b35a84ee1f7d7934d9d656a03290" have entirely different histories.
84cdb87a19
...
10ba3d642d
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,3 +1,3 @@
|
|||||||
[submodule "intern/wizapp"]
|
[submodule "intern/aliases"]
|
||||||
path = intern/wizapp
|
path = intern/aliases
|
||||||
url = https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib.git
|
url = https://git.thewizardapprentice.com/abdelrahman/c-cpp-aliases.git
|
||||||
|
18
compile
18
compile
@ -1,21 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CC=clang
|
CC=clang
|
||||||
CFLAGS="-g -Wall $(pkg-config --cflags sdl2)"
|
CFLAGS="-g -Wall -Iinclude -Iintern $(pkg-config --cflags sdl2)"
|
||||||
LIBS="$(pkg-config --libs sdl2) -lm"
|
LIBS="$(pkg-config --libs sdl2) -lm"
|
||||||
INCLUDE="\
|
SRC=src/*.c
|
||||||
-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 $INCLUDE $LIBS $SRC -o $OUT)
|
(set -x ; $CC $CFLAGS $LIBS $SRC -o $OUT)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef COMPOSITOR_H
|
#ifndef COMPOSITOR_H
|
||||||
#define COMPOSITOR_H
|
#define COMPOSITOR_H
|
||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
|
|
||||||
i32 run_main_loop(void);
|
i32 run_main_loop(void);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef MATH_UTILS_H
|
#ifndef MATH_UTILS_H
|
||||||
#define MATH_UTILS_H
|
#define MATH_UTILS_H
|
||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases/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)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef NODES_H
|
#ifndef NODES_H
|
||||||
#define NODES_H
|
#define NODES_H
|
||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
#define MAX_NODES 1024
|
#define MAX_NODES 1024
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef COMP_OPS_H
|
#ifndef COMP_OPS_H
|
||||||
#define COMP_OPS_H
|
#define COMP_OPS_H
|
||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases/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,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define UI_H
|
#define UI_H
|
||||||
|
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef WINDOW_H
|
#ifndef WINDOW_H
|
||||||
#define WINDOW_H
|
#define WINDOW_H
|
||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases/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
intern/aliases
Submodule
1
intern/aliases
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f95f3aa499910286876c1f2cdceea8146ebcf7b1
|
@ -1 +0,0 @@
|
|||||||
Subproject commit b8db582098a866aa56c62d0b2b6351ea08411f6b
|
|
@ -1,5 +1,4 @@
|
|||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
#include "mem_arena.h"
|
|
||||||
#include "nodes.h"
|
#include "nodes.h"
|
||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
@ -16,11 +15,8 @@
|
|||||||
#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;
|
||||||
@ -43,9 +39,8 @@ 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 *)mem_arena_alloc(comp.arena, sizeof(node) * MAX_NODES);
|
comp.nodes = (node *)malloc(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]);
|
||||||
@ -170,8 +165,6 @@ i32 run_main_loop(void) {
|
|||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
mem_arena_free(&comp.arena);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
#include "compositor.h"
|
#include "compositor.h"
|
||||||
|
|
||||||
i32 main(void) { return run_main_loop(); }
|
i32 main(void) { return run_main_loop(); }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "ops.h"
|
#include "ops.h"
|
||||||
#include "aliases.h"
|
#include "aliases/aliases.h"
|
||||||
|
|
||||||
i32 comp_add(i32 a, i32 b) { return a + b; }
|
i32 comp_add(i32 a, i32 b) { return a + b; }
|
||||||
|
|
||||||
|
10
src/ui.c
10
src/ui.c
@ -1,6 +1,6 @@
|
|||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "aliases.h"
|
#include "aliases/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;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "aliases.h"
|
#include "aliases/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;
|
||||||
|
Loading…
Reference in New Issue
Block a user