Initial commit.
This commit is contained in:
14
.clang-format
Normal file
14
.clang-format
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: true
|
||||||
|
AcrossComments: true
|
||||||
|
IndentCaseLabels: true
|
||||||
|
AllowShortBlocksOnASingleLine: Always
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
IndentWidth: 4
|
||||||
|
PointerAlignment: Left
|
||||||
|
AlignAfterOpenBracket: BlockIndent
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
*.o
|
||||||
|
*.so
|
||||||
|
tags
|
||||||
|
data
|
||||||
|
*.out
|
||||||
|
.cache
|
||||||
|
build/*
|
||||||
|
vgcore.*
|
||||||
|
compile_commands.json
|
||||||
33
Makefile
Normal file
33
Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
include config.mk
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
release: clean
|
||||||
|
release: CFLAGS = -Wall -O2
|
||||||
|
release: $(TARGET)
|
||||||
|
|
||||||
|
# Run the target.
|
||||||
|
run: $(TARGET)
|
||||||
|
./$(TARGET)
|
||||||
|
|
||||||
|
# Compile project source objects.
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC_DIR)/%.h
|
||||||
|
@ mkdir -p $(OBJ_DIR)
|
||||||
|
@ $(PRINT) "$(WHITE_BOLD)Compiling source object $(WHITE)$@$(WHITE_BOLD)... $(RESETCOLOR)"
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
# Link to final binary.
|
||||||
|
$(TARGET): $(OBJ_FILES)
|
||||||
|
@ $(PRINT) "$(WHITE_BOLD)Linking $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)"
|
||||||
|
$(LINK) -o $(TARGET) $(OBJ_FILES) $(LDFLAGS)
|
||||||
|
|
||||||
|
# Clean out objects, binaries, and built artifacts.
|
||||||
|
clean:
|
||||||
|
@ $(PRINT) "$(WHITE_BOLD)Cleaning up...$(RESETCOLOR)"
|
||||||
|
rm -rf $(OBJ_DIR)/*.o $(TARGET)
|
||||||
|
|
||||||
|
# Get LOC.
|
||||||
|
lines:
|
||||||
|
@ wc -l $(SRC_FILES) $(INC_FILES) $(GRAM_SRC)
|
||||||
|
|
||||||
|
.PHONY: all clean test nocolor release run lines
|
||||||
24
config.mk
Normal file
24
config.mk
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
NAME = terrin
|
||||||
|
|
||||||
|
TARGET = $(NAME).out
|
||||||
|
|
||||||
|
SRC_DIR = src
|
||||||
|
INC_DIR = $(SRC_DIR)/include
|
||||||
|
BUILD_DIR = build
|
||||||
|
OBJ_DIR = $(BUILD_DIR)/obj
|
||||||
|
|
||||||
|
CC = clang -std=c23
|
||||||
|
LINK = clang
|
||||||
|
CFLAGS = -Wall -DDBG -ggdb -fsanitize=leak
|
||||||
|
LDFLAGS = -lGL -lX11 -lXi -lXcursor -ldl -lpthread -lm
|
||||||
|
PRINT = echo -e
|
||||||
|
|
||||||
|
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
|
||||||
|
INC_FILES = $(wildcard $(INC_DIR)/*.h)
|
||||||
|
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
|
||||||
|
OBJ_FILES_NOMAIN = $(filter-out $(OBJ_DIR)/main.o, $(OBJ_FILES)) # Object files without main.c.
|
||||||
|
|
||||||
|
RESETCOLOR = \033[0m
|
||||||
|
WHITE = $(RESETCOLOR)\033[0m
|
||||||
|
WHITE_BOLD = $(RESETCOLOR)\033[0;1m
|
||||||
|
RED_BOLD = $(RESETCOLOR)\033[31;1m
|
||||||
22
src/gen.c
Normal file
22
src/gen.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "include/gen.h"
|
||||||
|
#include "include/col.h"
|
||||||
|
#include "include/vol.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
void gen(void) {
|
||||||
|
srand((unsigned int)time(NULL));
|
||||||
|
|
||||||
|
for (int x = 0; x < VOL_WIDTH; x++) {
|
||||||
|
for (int y = 0; y < VOL_HEIGHT; y++) {
|
||||||
|
for (int z = 0; z < VOL_DEPTH; z++) {
|
||||||
|
if (rand() % 2 == 0) vol_set_vox(x, y, z, COL_WHT);
|
||||||
|
else vol_set_vox(x, y, z, COL_BLK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Volume initialized.\n");
|
||||||
|
}
|
||||||
18
src/include/col.h
Normal file
18
src/include/col.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef COL_H
|
||||||
|
#define COL_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// An RGB color.
|
||||||
|
typedef struct {
|
||||||
|
uint8_t r, g, b;
|
||||||
|
} Col;
|
||||||
|
|
||||||
|
#define COL_WHT (Col) {255, 255, 255}
|
||||||
|
#define COL_GRY (Col) {127, 127, 127}
|
||||||
|
#define COL_BLK (Col) {0, 0, 0}
|
||||||
|
#define COL_RED (Col) {255, 0, 0}
|
||||||
|
#define COL_GRN (Col) {0, 255, 0}
|
||||||
|
#define COL_BLU (Col) {0, 0, 255}
|
||||||
|
|
||||||
|
#endif
|
||||||
6
src/include/gen.h
Normal file
6
src/include/gen.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef GEN_H
|
||||||
|
#define GEN_H
|
||||||
|
|
||||||
|
void gen(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
0
src/include/main.h
Normal file
0
src/include/main.h
Normal file
16
src/include/vol.h
Normal file
16
src/include/vol.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef VOL_H
|
||||||
|
#define VOL_H
|
||||||
|
|
||||||
|
#include "vox.h"
|
||||||
|
#include "col.h"
|
||||||
|
|
||||||
|
#define VOL_WIDTH 128
|
||||||
|
#define VOL_HEIGHT 128
|
||||||
|
#define VOL_DEPTH 128
|
||||||
|
|
||||||
|
// The volume in which our voxels may be found.
|
||||||
|
extern Vox volume[VOL_WIDTH][VOL_HEIGHT][VOL_DEPTH];
|
||||||
|
|
||||||
|
void vol_set_vox(int x, int y, int z, Col col);
|
||||||
|
|
||||||
|
#endif
|
||||||
13
src/include/vox.h
Normal file
13
src/include/vox.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef VOX_H
|
||||||
|
#define VOX_H
|
||||||
|
|
||||||
|
#include "col.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// A voxel.
|
||||||
|
typedef struct {
|
||||||
|
Col col;
|
||||||
|
} Vox;
|
||||||
|
|
||||||
|
#endif
|
||||||
21
src/main.c
Normal file
21
src/main.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "include/main.h"
|
||||||
|
|
||||||
|
#include "include/gen.h"
|
||||||
|
#include "include/vol.h"
|
||||||
|
#include "include/vox.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
printf("Hello, world.\n");
|
||||||
|
|
||||||
|
gen();
|
||||||
|
|
||||||
|
Vox testvox = volume[10][5][20];
|
||||||
|
printf(
|
||||||
|
"Test voxel is (%d, %d, %d)\n", testvox.col.r, testvox.col.g,
|
||||||
|
testvox.col.b
|
||||||
|
);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
12
src/vol.c
Normal file
12
src/vol.c
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "include/vol.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
Vox volume[VOL_WIDTH][VOL_HEIGHT][VOL_DEPTH];
|
||||||
|
|
||||||
|
void vol_set_vox(int x, int y, int z, Col col) {
|
||||||
|
if (x >= 0 && x < VOL_WIDTH && y >= 0 && y < VOL_HEIGHT && z >= 0 &&
|
||||||
|
z < VOL_DEPTH)
|
||||||
|
volume[x][y][z].col = col;
|
||||||
|
else exit(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user