nyaa
This commit is contained in:
parent
44b0181dbb
commit
39ee7c8c8a
10 changed files with 174 additions and 70 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
*.frag
|
||||
*.vert
|
||||
*.spv
|
||||
nob
|
||||
build/*
|
||||
nob.old
|
||||
main
|
||||
|
|
173
nob.c
173
nob.c
|
@ -5,103 +5,166 @@
|
|||
|
||||
#define BUILD_FOLDER "build/"
|
||||
#define SRC_FOLDER "src/"
|
||||
#define RES_FOLDER "res/"
|
||||
|
||||
#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"};
|
||||
const char *blacklist[] = {"parser.c"};
|
||||
const char *comp = "cc";
|
||||
const char *scomp = "glslc";
|
||||
|
||||
bool discover_build() {
|
||||
Nob_File_Paths src_cpaths = {0};
|
||||
Procs procs = {0};
|
||||
Cmd cmd = {0};
|
||||
|
||||
bool process_res(char *res_base) {
|
||||
printf("reading %s\n", res_base);
|
||||
Nob_File_Paths res_paths = {0};
|
||||
if (!read_entire_dir(res_base, &res_paths)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < res_paths.count; i++) {
|
||||
if (*res_paths.items[i] == '.') {
|
||||
continue;
|
||||
}
|
||||
char *path = (char *)res_paths.items[i];
|
||||
switch (get_file_type(temp_sprintf("%s%s", res_base, path))) {
|
||||
case NOB_FILE_REGULAR:;
|
||||
bool blacklisted = false;
|
||||
for (int i = 0; i < len(blacklist); i++) {
|
||||
if (strcmp(path, blacklist[i]) == 0) {
|
||||
printf("skipping %s\n", path);
|
||||
blacklisted = true;
|
||||
}
|
||||
}
|
||||
if (!blacklisted) {
|
||||
char *tmp = path;
|
||||
while (*tmp != '.') {
|
||||
tmp++;
|
||||
}
|
||||
if (memcmp(tmp + 1, "vert", strlen("vert")) == 0 ||
|
||||
memcmp(tmp + 1, "frag", strlen("frag")) == 0) {
|
||||
*tmp = 0x0;
|
||||
// path now looks like meooow 0x0 glsl
|
||||
cmd_append(&cmd, scomp, "-c");
|
||||
cmd_append(&cmd, "-o", temp_sprintf("%s%s%s", res_base, path, ".spv"),
|
||||
temp_sprintf("%s%s.%s", res_base, path, tmp + 1));
|
||||
da_append(&procs, cmd_run_async_and_reset(&cmd));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case NOB_FILE_DIRECTORY:;
|
||||
char *folder_path = temp_sprintf("%s%s", res_base, res_paths.items[i]);
|
||||
if (!mkdir_if_not_exists(folder_path)) {
|
||||
return false;
|
||||
}
|
||||
if (!process_res(
|
||||
temp_sprintf("%s%s%c", res_base, res_paths.items[i], '/'))) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case NOB_FILE_SYMLINK:
|
||||
nob_log(ERROR, "symlink");
|
||||
return false;
|
||||
case NOB_FILE_OTHER:
|
||||
nob_log(ERROR, "other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// base is assumed to be .mew/meooow/nyaa/ or something, note the slashes
|
||||
bool discover_build(char *src_base, char *build_base) {
|
||||
Nob_File_Paths src_paths = {0};
|
||||
if (!read_entire_dir(SRC_FOLDER, &src_paths)) {
|
||||
exit(1);
|
||||
if (!read_entire_dir(src_base, &src_paths)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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:
|
||||
char *path = (char *)src_paths.items[i];
|
||||
switch (get_file_type(temp_sprintf("%s%s", src_base, path))) {
|
||||
case NOB_FILE_REGULAR:;
|
||||
bool blacklisted = false;
|
||||
for (int i = 0; i < len(blacklist); i++) {
|
||||
if (strcmp(path, blacklist[i]) == 0) {
|
||||
printf("skipping %s\n", path);
|
||||
blacklisted = true;
|
||||
}
|
||||
}
|
||||
if (!blacklisted) {
|
||||
char *tmp = path;
|
||||
while (*tmp != '.') {
|
||||
tmp++;
|
||||
}
|
||||
if (*(tmp + 1) == 'c') {
|
||||
*tmp = 0x0;
|
||||
// path now looks like meooow 0x0 c
|
||||
cmd_append(&cmd, comp, "-c");
|
||||
for (int j = 0; j < len(cflags); j++) {
|
||||
cmd_append(&cmd, cflags[j]);
|
||||
}
|
||||
cmd_append(&cmd, "-o", temp_sprintf("%s%s%s", build_base, path, ".o"),
|
||||
temp_sprintf("%s%s%s", src_base, path, ".c"));
|
||||
da_append(&procs, cmd_run_async_and_reset(&cmd));
|
||||
da_append(&src_cpaths,
|
||||
temp_sprintf("%s%s%s", build_base, path, ".o"));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case NOB_FILE_DIRECTORY:;
|
||||
if (!mkdir_if_not_exists(
|
||||
temp_sprintf("%s%s", BUILD_FOLDER, src_paths.items[i]))) {
|
||||
return 1;
|
||||
char *folder_path = temp_sprintf("%s%s", build_base, src_paths.items[i]);
|
||||
if (!mkdir_if_not_exists(folder_path)) {
|
||||
return false;
|
||||
}
|
||||
if (!discover_build(
|
||||
temp_sprintf("%s%s%c", src_base, src_paths.items[i], '/'),
|
||||
temp_sprintf("%s%s%c", build_base, src_paths.items[i], '/'))) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case NOB_FILE_SYMLINK:
|
||||
nob_log(ERROR, "symlink");
|
||||
exit(1);
|
||||
return false;
|
||||
case NOB_FILE_OTHER:
|
||||
nob_log(ERROR, "other");
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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/")) {
|
||||
if (!discover_build(SRC_FOLDER, BUILD_FOLDER)) {
|
||||
return 1;
|
||||
}
|
||||
if (!mkdir_if_not_exists(BUILD_FOLDER "Wayland/")) {
|
||||
if (!process_res(RES_FOLDER)) {
|
||||
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");
|
||||
cmd_append(&cmd, comp);
|
||||
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_append(&cmd, "-o", "main", "main.c");
|
||||
for (int i = 0; i < src_cpaths.count; i++) {
|
||||
cmd_append(&cmd, src_cpaths.items[i]);
|
||||
}
|
||||
cmd_run_sync_and_reset(&cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
11
res/shaders/frag.frag
Normal file
11
res/shaders/frag.frag
Normal file
|
@ -0,0 +1,11 @@
|
|||
#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);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
23
res/shaders/vert.vert
Normal file
23
res/shaders/vert.vert
Normal file
|
@ -0,0 +1,23 @@
|
|||
#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);
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
#include "paw_allocator.h"
|
||||
#include "paw_da.h"
|
||||
#include "vulkan.h"
|
||||
#include "vulkan_helpers.c"
|
||||
#include "vulkan_helpers.h"
|
||||
|
||||
struct Kitty *kitty_make(struct PawMem *mem) {
|
||||
struct Kitty *kitty;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "../allocator.h"
|
||||
#include "../io.h"
|
||||
#include "../log.h"
|
||||
#include "../paw_allocator.h"
|
||||
#include "../paw_log.h"
|
||||
#include "../string.h"
|
||||
#include "../util.h"
|
||||
#include "ast.h"
|
||||
|
@ -86,17 +86,17 @@ struct PawStackVal parse_stack_val(char *start, struct StringTable *vars,
|
|||
struct PawParseVal combine_val_ctrls(struct PawParseVal base,
|
||||
struct PawParseVal additions) {
|
||||
for (int i = 0; i < additions.pre.count; i++) {
|
||||
dyn_array_append(&base.pre, additions.pre.items[i]);
|
||||
paw_da_append(&base.pre, additions.pre.items[i]);
|
||||
}
|
||||
base.num_pops += additions.num_pops;
|
||||
return base;
|
||||
}
|
||||
|
||||
struct PawParseVal parse_val(int offset, struct StringTable *vars,
|
||||
struct Mem *tmp, struct Mem *pem, char *start,
|
||||
char *end) {
|
||||
struct PawMem *tmp, struct PawMem *pem,
|
||||
char *start, char *end) {
|
||||
struct PawParseVal val = {0};
|
||||
dyn_array_create_inplace_mem(&val.pre, tmp);
|
||||
paw_da_make_inplace_mem(&val.pre, tmp);
|
||||
|
||||
meow("parsing a val");
|
||||
start = trim_start(start);
|
||||
|
@ -174,7 +174,7 @@ struct PawParseVal parse_val(int offset, struct StringTable *vars,
|
|||
return val;
|
||||
}
|
||||
|
||||
enum PawCtrl *parse_block(struct Mem *tmp, struct Mem *pem, int offset,
|
||||
enum PawCtrl *parse_block(struct PawMem *tmp, struct PawMem *pem, int offset,
|
||||
struct StringTable *vars, char *start) {
|
||||
meow("parsing a block");
|
||||
enum PawCtrl *body = make_pawctrl_seq(pem);
|
||||
|
@ -346,8 +346,8 @@ struct PawAST *parse(char *path) {
|
|||
char *contents = read_text_file(path);
|
||||
struct PawAST *ast = ast_make();
|
||||
|
||||
struct Mem *tmp = make_mem(4096); // temporary memory
|
||||
struct Mem *pem =
|
||||
struct PawMem *tmp = paw_memmake(4096); // temporary memory
|
||||
struct PawMem *pem =
|
||||
ast->mem; // permanent memory, will be present once ast is evaled
|
||||
|
||||
struct StringTable *methods = st_make(tmp);
|
||||
|
@ -382,7 +382,7 @@ struct PawAST *parse(char *path) {
|
|||
tmp, pem, 0, st_make(tmp),
|
||||
skip_to_char(st_get(methods, st_get_nth_key(methods, i)), '{')));
|
||||
}
|
||||
uninit_mem(tmp);
|
||||
paw_memunmake(tmp);
|
||||
|
||||
return ast;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "vulkan_helpers.h"
|
||||
#include "paw_log.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
int get_size_of_format(enum VkFormat format) {
|
||||
switch (format) {
|
||||
case VK_FORMAT_R32_UINT:
|
||||
|
|
8
src/vulkan_helpers.h
Normal file
8
src/vulkan_helpers.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef INCLUDE_SRC_VULKAN_HELPERS_H_
|
||||
#define INCLUDE_SRC_VULKAN_HELPERS_H_
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
int get_size_of_format(enum VkFormat format);
|
||||
|
||||
#endif // INCLUDE_SRC_VULKAN_HELPERS_H_
|
Loading…
Add table
Add a link
Reference in a new issue