nob an a bunch of stuff

This commit is contained in:
qwertzuiopy 2025-04-07 23:24:42 +02:00
parent 6dcddb4da3
commit 44b0181dbb
19 changed files with 2357 additions and 78 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
*.frag
*.vert
nob
build/*
nob.old

View file

@ -1,11 +0,0 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragUV;
layout(location = 0) out vec4 outColor;
layout(binding = 2) uniform sampler2D texSampler;
void main() {
outColor = texture(texSampler, fragUV) * vec4(fragColor, 1.0);
}

View file

@ -1,23 +0,0 @@
#version 450
layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 2) in uint index;
layout(set = 0, binding = 0) uniform UBO {
mat3 view;
mat3 proj;
} ubo;
layout(set = 0, binding = 1) uniform UBO_INST {
mat3 model[1000];
} ubo_inst;
layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragUV;
void main() {
gl_Position = vec4(ubo.proj * ubo.view * ubo_inst.model[index] * vec3(inPosition, 1.0), 1.0);
fragColor = inColor;
fragUV = inPosition + vec2(0.5, 0.5);
}

BIN
image.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

6
main.c
View file

@ -3,9 +3,9 @@
#include "src/register.h" #include "src/register.h"
#include "trig.c" #include "trig.c"
#include "src/lang/ast.h" /* #include "src/lang/ast.h" */
#include "src/lang/ast_disc.h" /* #include "src/lang/ast_disc.h" */
#include "src/lang/parser.h" /* #include "src/lang/parser.h" */
#include <stdbool.h> #include <stdbool.h>

107
nob.c Normal file
View file

@ -0,0 +1,107 @@
#include <stdio.h>
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"
#define BUILD_FOLDER "build/"
#define SRC_FOLDER "src/"
#define len NOB_ARRAY_LEN
const char *sources[] = {
"comp", "wayland",
"glfw", "vulkan",
"kitty", "string",
"gpu_allocator", "hashmap",
"util", "io",
"matrix", "paw_da",
"image", "types",
"paw_allocator", "paw_log",
"paw_object", "register",
"lang/ast", "lang/vstack",
"lang/ast_disc", "lang/functable",
"lang/glue", "Wayland/xdg-shell-protocol",
};
const char *cflags[] = {"-g", "-rdynamic", "-lm", "-lwayland-client",
"-lxkbcommon", "-lvulkan", "-lglfw"};
bool discover_build() {
Nob_File_Paths src_paths = {0};
if (!read_entire_dir(SRC_FOLDER, &src_paths)) {
exit(1);
}
for (int i = 0; i < src_paths.count; i++) {
if (*src_paths.items[i] == '.') {
continue;
}
char *path = temp_sprintf("%s%s", SRC_FOLDER, src_paths.items[i]);
printf("%s\n", path);
switch (get_file_type(path)) {
case NOB_FILE_REGULAR:
break;
case NOB_FILE_DIRECTORY:;
if (!mkdir_if_not_exists(
temp_sprintf("%s%s", BUILD_FOLDER, src_paths.items[i]))) {
return 1;
}
break;
case NOB_FILE_SYMLINK:
nob_log(ERROR, "symlink");
exit(1);
case NOB_FILE_OTHER:
nob_log(ERROR, "other");
return 1;
}
}
}
int main(int argc, char **argv) {
NOB_GO_REBUILD_URSELF(argc, argv);
/* if (!discover_build()) { */
/* return 1; */
/* } */
/* return 0; */
if (!mkdir_if_not_exists(BUILD_FOLDER)) {
return 1;
}
if (!mkdir_if_not_exists(BUILD_FOLDER "lang/")) {
return 1;
}
if (!mkdir_if_not_exists(BUILD_FOLDER "Wayland/")) {
return 1;
}
Procs procs = {0};
Cmd cmd = {0};
for (int i = 0; i < len(sources); i++) {
cmd_append(&cmd, "cc", "-c");
for (int j = 0; j < len(cflags); j++) {
cmd_append(&cmd, cflags[j]);
}
cmd_append(&cmd, "-o",
temp_sprintf("%s%s%s", BUILD_FOLDER, sources[i], ".o"),
temp_sprintf("%s%s%s", SRC_FOLDER, sources[i], ".c"));
da_append(&procs, cmd_run_async_and_reset(&cmd));
}
if (!procs_wait_and_reset(&procs)) {
return 1;
}
cmd_append(&cmd, "cc");
for (int j = 0; j < len(cflags); j++) {
cmd_append(&cmd, cflags[j]);
}
cmd_append(&cmd, "-o", BUILD_FOLDER "main", "main.c");
for (int i = 0; i < len(sources); i++) {
cmd_append(&cmd, temp_sprintf("%s%s%s", BUILD_FOLDER, sources[i], ".o"));
}
cmd_run_sync_and_reset(&cmd);
return 0;
}

2143
nob.h Normal file

File diff suppressed because it is too large Load diff

View file

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Before After
Before After

BIN
res/shaders/frag.spv Normal file

Binary file not shown.

BIN
res/shaders/vert.spv Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
#define MAX_ALLOCS 1024 #define GPU_MAX_ALLOCS 1024
#define MAX_PAGES 10 #define MAX_PAGES 10
#define MIN_PAGE_SIZE 262144 #define MIN_PAGE_SIZE 262144
@ -21,7 +21,7 @@ struct GpuPage {
uint count; uint count;
uint32_t index; uint32_t index;
VkDeviceMemory memory; VkDeviceMemory memory;
struct GpuAlloc allocs[MAX_ALLOCS]; struct GpuAlloc allocs[GPU_MAX_ALLOCS];
struct GpuAlloc *alloc; struct GpuAlloc *alloc;
void *mapped; void *mapped;
}; };
@ -89,7 +89,7 @@ static struct GpuAlloc *get_next_gpu_alloc(struct GpuPage *page) {
while (page->allocs[page->count].start != 0 || while (page->allocs[page->count].start != 0 ||
page->allocs[page->count].next != NULL) { page->allocs[page->count].next != NULL) {
page->count++; page->count++;
if (page->count >= MAX_ALLOCS) { if (page->count >= GPU_MAX_ALLOCS) {
crash("out of allocs!"); crash("out of allocs!");
} }
} }

View file

@ -2,6 +2,7 @@
#define INCLUDE_WAYLANDCLIENT_DYNARRAY_H_ #define INCLUDE_WAYLANDCLIENT_DYNARRAY_H_
#include "paw_allocator.h" #include "paw_allocator.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>

52
src/paw_phys.c Normal file
View file

@ -0,0 +1,52 @@
#include "paw_phys.h"
#include "paw_da.h"
#include "paw_log.h"
struct PawPWorld2 *paw_world2_make() {
struct PawMem *mem = paw_memmake(2048);
struct PawPWorld2 *world = paw_memmalloc(mem, sizeof(struct PawPWorld2));
world->mem = mem;
paw_da_make_inplace_mem(&world->bodies, mem);
return world;
}
void paw_world2_unmake(struct PawPWorld2 *world) { paw_memunmake(world->mem); }
struct PawPBody2 *paw_pbody2_make(struct PawPWorld2 *world) {
struct PawPBody2 *body = paw_memmalloc(world->mem, sizeof(struct PawPBody2));
memset(body, 0, sizeof(struct PawPBody2));
paw_da_make_inplace_mem(&body->impulse_queue, world->mem);
return body;
}
void paw_pbody2_free(struct PawPBody2 *body) {
paw_memfree(body->impulse_queue.mem, body);
}
// first layer is 0 and so on, up to layer 32 (or 31 idk)
void paw_pbody2_set_layer(struct PawPBody2 *body, uint8_t layer, bool val) {
uint32_t mask = 0x1 << layer;
if (val) {
body->layers = body->layers | mask;
} else {
body->layers = body->layers & !mask;
}
}
void paw_pbody2_apply_impulse(struct PawPBody2 *body, struct Vec2 pos,
struct Vec2 force) {
paw_da_append(&body->impulse_queue,
((struct PawImpulse2){.pos = pos, .force = force}));
}
void paw_world2d_insert_body(struct PawPWorld2 *world, struct PawPBody2 *body) {
paw_da_append(&world->bodies, body);
}
void paw_world2d_remove_body(struct PawPWorld2 *world, struct PawPBody2 *body) {
for (int i = 0; i < world->bodies.count; i++) {
if (world->bodies.items[i] == body) {
paw_da_remove(&world->bodies, i);
return;
}
}
meow("body not found!");
}

39
src/paw_phys.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef INCLUDE_SRC_PHYSICS_H_
#define INCLUDE_SRC_PHYSICS_H_
#include "paw_allocator.h"
#include "paw_da.h"
#include "types.h"
#include <stdbool.h>
#include <stdint.h>
struct PawImpulse2 {
struct Vec2 pos;
struct Vec2 force;
};
paw_da_define(da_PawImpulse2, struct PawImpulse2);
enum PawPBodyType2 {
PAW_PBODY_RECT,
PAW_PBODY_CIRCLE,
};
struct PawPBody2 {
enum PawPBodyType2 type; // !! important !!
union {
struct Vec2 rect;
float cirle;
};
uint32_t layers; // use helper func
struct Vec2 pos; // should not be modified
float rot; // should not be modified
struct da_PawImpulse2 impulse_queue;
};
paw_da_define(da_PawPBody2, struct PawPBody2 *);
struct PawPWorld2 {
struct PawMem *mem;
struct da_PawPBody2 bodies;
};
#endif // INCLUDE_SRC_PHYSICS_H_

View file

@ -1 +0,0 @@
#include "physics.h"

View file

@ -1,25 +0,0 @@
#ifndef INCLUDE_SRC_PHYSICS_H_
#define INCLUDE_SRC_PHYSICS_H_
#include "allocator.h"
#include "types.h"
#include <stdint.h>
enum PawPBodyType {
PAW_PBODY_RECT,
PAW_PBODY_CIRCLE,
};
struct PawPBody {
enum PawPBodyType type;
uint32_t layers;
union {
struct Rect rect;
struct Circle cirle;
};
};
struct PawPServer {
struct Mem *mem;
};
#endif // INCLUDE_SRC_PHYSICS_H_

View file

@ -42,13 +42,4 @@ struct Vertex {
struct Vec3 col; struct Vec3 col;
}; };
struct Rect {
struct Vec2 pos;
struct Vec2 ext;
};
struct Circle {
struct Vec2 pos;
float r;
};
#endif // INCLUDE_WAYLANDCLIENT_TYPES_H_ #endif // INCLUDE_WAYLANDCLIENT_TYPES_H_

View file

@ -2,6 +2,7 @@
#define INCLUDE_ENGINE_UTIL_H_ #define INCLUDE_ENGINE_UTIL_H_
#define UINT32_NULL 42424242 #define UINT32_NULL 42424242
#define PAW_HOME "/home/michael/Projects/pawengine/src/"
#include "paw_allocator.h" #include "paw_allocator.h"

6
trig.c
View file

@ -38,8 +38,8 @@ struct Trig *trig_make_args(struct PawScene *scene) {
struct Trig *trig = paw_memmalloc(scene->mem, sizeof(struct Trig)); struct Trig *trig = paw_memmalloc(scene->mem, sizeof(struct Trig));
trig->kitty = kitty_make(scene->mem); trig->kitty = kitty_make(scene->mem);
kitty_set_vertex_shader(trig->kitty, "./Shaders/vert.spv"); kitty_set_vertex_shader(trig->kitty, "./res/shaders/vert.spv");
kitty_set_fragment_shader(trig->kitty, "./Shaders/frag.spv"); kitty_set_fragment_shader(trig->kitty, "./res/shaders/frag.spv");
kitty_set_vertex_buffer(trig->kitty, trig_vertices, TRIG_VERTEX_COUNT, kitty_set_vertex_buffer(trig->kitty, trig_vertices, TRIG_VERTEX_COUNT,
sizeof(struct Vertex)); sizeof(struct Vertex));
kitty_add_vertex_buffer_format(trig->kitty, VK_FORMAT_R32G32_SFLOAT); kitty_add_vertex_buffer_format(trig->kitty, VK_FORMAT_R32G32_SFLOAT);
@ -47,7 +47,7 @@ struct Trig *trig_make_args(struct PawScene *scene) {
kitty_attatch_ubo(trig->kitty, sizeof(struct TrigUBO)); kitty_attatch_ubo(trig->kitty, sizeof(struct TrigUBO));
kitty_attatch_ubo(trig->kitty, sizeof(struct mat3x3) * INSTANCE_COUNT); kitty_attatch_ubo(trig->kitty, sizeof(struct mat3x3) * INSTANCE_COUNT);
kitty_attatch_image(trig->kitty, "./neocat.png"); kitty_attatch_image(trig->kitty, "./res/neocat.png");
uint32_t instance_buffer[INSTANCE_COUNT] = {0}; uint32_t instance_buffer[INSTANCE_COUNT] = {0};
for (int i = 0; i < INSTANCE_COUNT; i++) { for (int i = 0; i < INSTANCE_COUNT; i++) {