diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d03705 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/build/ +/wschod +/perf.data* +/massif.out* \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..04b285a --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +# To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront + +SRC := $(shell find src -name '*.c') +OBJ := $(patsubst src/%.c, build/%.o, $(SRC)) +DEP := $(OBJ:.o=.d) + +CC := gcc +LD := gcc +STD := gnu23 +RM := rm -f + +DEBUG ?= 1 + +CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP `pkg-config --cflags sdl3 sdl3-image glib-2.0` +LDFLAGS := -std=$(STD) -lm `pkg-config --libs sdl3 sdl3-image glib-2.0` + +TARGET := librefront + +ifeq ($(DEBUG),1) + CFLAGS += -g -DDEBUG + LDFLAGS += -g +else + CFLAGS += -O2 -DNDEBUG +endif + +.PHONY: all clean + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(LD) $^ -o $@ $(LDFLAGS) + +build/%.o: src/%.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ $(CFLAGS) + +clean: + $(RM) -r build/ $(TARGET) $(OBJ) $(DEP) perf.data* massif.out* + +-include $(DEP) diff --git a/README.md b/README.md index 2b6ae0a..4c45445 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Fast, multithreaded, multicore, GPU, CUDA, raytracing, NVIDIA game # TODOs -- [ ] Basic SDL window open +- [X] Basic SDL window open - [ ] Map structure programmed - [ ] Loading a map from a file - [ ] Displaying a map on the screen diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d0eb7cb --- /dev/null +++ b/shell.nix @@ -0,0 +1,19 @@ +let + nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-25.05"; + pkgs = import nixpkgs { config = {}; overlays = []; }; +in +pkgs.mkShellNoCC { + packages = with pkgs; [ + sdl3 + sdl3-image + glib + + gcc + pkg-config + cloc + valgrind + gdb + cpulimit + linuxKernel.packages.linux_6_12.perf + ]; +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..b6016fa --- /dev/null +++ b/src/main.c @@ -0,0 +1,80 @@ +#define SDL_MAIN_USE_CALLBACKS 1 +#include +#include +#include +#include + +#include "util.h" + +SDL_Window *sdl_window; +SDL_Renderer *sdl_renderer; + +SDL_AppResult +SDL_AppInit (void **appstate, int argc, char **argv) +{ + UNUSED (appstate, argc, argv); + + setenv ("GIO_USE_VFS", "local", 1); + setenv ("GSETTINGS_BACKEND", "memory", 1); + +#ifdef DEBUG + setenv ("G_MESSAGES_DEBUG", "all", 1); +#endif + + SDL_SetAppMetadata ("LibreFront", "0.1", + "https://git.cfpi-fpsi.eu:8443/chopin-interactive/librefront"); + + if (!SDL_Init (SDL_INIT_VIDEO)) + { + g_error ("Couldn't initialize SDL: %s", SDL_GetError ()); + } + + sdl_window = SDL_CreateWindow ("LibreFront", 800, 600, SDL_WINDOW_RESIZABLE); + + if (!sdl_window) + { + g_error ("Couldn't create window: %s", SDL_GetError ()); + } + + sdl_renderer = SDL_CreateRenderer (sdl_window, NULL); + + if (!sdl_renderer) + { + g_error ("Couldn't create renderer: %s", SDL_GetError ()); + } + + return SDL_APP_CONTINUE; +} + +SDL_AppResult +SDL_AppEvent (void *appstate, SDL_Event *event) +{ + UNUSED (appstate); + + if (event->type == SDL_EVENT_QUIT) + { + return SDL_APP_SUCCESS; + } + + return SDL_APP_CONTINUE; +} + +SDL_AppResult +SDL_AppIterate (void *appstate) +{ + UNUSED (appstate); + + SDL_RenderClear (sdl_renderer); + SDL_RenderPresent (sdl_renderer); + + return SDL_APP_CONTINUE; +} + +void +SDL_AppQuit (void *appstate, SDL_AppResult result) +{ + UNUSED (appstate, result); + + SDL_DestroyRenderer (sdl_renderer); + SDL_DestroyWindow (sdl_window); +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..a3dd55c --- /dev/null +++ b/src/util.h @@ -0,0 +1,19 @@ +#pragma once + +#define UNUSED(...) (UNUSED_1 (__VA_ARGS__, 0)) +#define UNUSED_1(arg, ...) (void) arg, UNUSED_2 (__VA_ARGS__, 0) +#define UNUSED_2(arg, ...) (void) arg, UNUSED_3 (__VA_ARGS__, 0) +#define UNUSED_3(arg, ...) (void) arg + +/* + + GLib log levels: + + g_debug + g_info + g_message + g_warning + g_critical + g_error + + */