From 12205696b64f11b7b51d330573fbe0ad19a9bed8 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Sat, 17 May 2025 09:58:44 +0200 Subject: [PATCH] init --- .gitignore | 1 + Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/const.h | 11 +++++++++++ src/func.cpp | 10 ++++++++++ src/func.h | 1 + src/main.cpp | 35 +++++++++++++++++++++++++++++++++++ src/types.h | 5 +++++ 7 files changed, 111 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/const.h create mode 100644 src/func.cpp create mode 100644 src/func.h create mode 100644 src/main.cpp create mode 100644 src/types.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8af22e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# Compiler and flags +CPPC = g++ +CPPC_FLAGS = -std=c++23 -s -O3 -lSDL3 -Wall -Wextra -Wno-write-strings +DEBUG_FLAGS = -ggdb -std=c++23 -lSDL3 -Wall -Wextra -Wno-write-strings +DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lSDL3 -Wall -Wextra -Wno-write-strings + + +SRC_PATH := src +OBJ_PATH := build/obj +BIN_PATH := build/bin + +BIN_NAME = pupes-screensaver + + +SRC_FILES := $(shell find $(SRC_PATH) -name '*.cpp') +OBJ_FILES := $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(SRC_FILES)) + + +all: make-build-dir $(BIN_PATH)/$(BIN_NAME) + + +debug: CPPC_FLAGS = $(DEBUG_FLAGS) +debug: make-build-dir $(BIN_PATH)/$(BIN_NAME) + +asan: CPPC_FLAGS = $(DEBUG_ASANITIZE) +asan: make-build-dir $(BIN_PATH)/$(BIN_NAME) + + +make-build-dir: + mkdir -p $(OBJ_PATH) + mkdir -p $(BIN_PATH) + + +$(BIN_PATH)/$(BIN_NAME): $(OBJ_FILES) + $(CPPC) $(CPPC_FLAGS) $^ -o $@ + + +$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cpp + $(CPPC) $(CPPC_FLAGS) -c $< -o $@ + + +install: + @install -vpm 755 -o root -g root $(BIN_PATH)/$(BIN_NAME) /usr/bin/ + +clean: + rm -fr build + +.PHONY: all clean install debug asan diff --git a/src/const.h b/src/const.h new file mode 100644 index 0000000..28b1352 --- /dev/null +++ b/src/const.h @@ -0,0 +1,11 @@ +#include + +#ifndef CONST_NS +#define CONST_NS + +constexpr int SCREEN_WIDTH = 1920; +constexpr int SCREEN_HEIGHT = 1080; +constexpr int TARGET_FPS = 60; +constexpr Uint64 TARGET_FRAME_TIME_NS = 1'000'000'000 / TARGET_FPS; + +#endif diff --git a/src/func.cpp b/src/func.cpp new file mode 100644 index 0000000..0a1cb74 --- /dev/null +++ b/src/func.cpp @@ -0,0 +1,10 @@ +#include + +int get_random_num(int min, int max) { + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution dist( + min, max); // set range + + return dist(rng); +} diff --git a/src/func.h b/src/func.h new file mode 100644 index 0000000..8cc002b --- /dev/null +++ b/src/func.h @@ -0,0 +1 @@ +int get_random_num(int min, int max); diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b8e1208 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,35 @@ +#include +#include "types.h" +#include "const.h" +#include +#include +#include +#include "func.h" +#include +#include + + + + +int main() { + SDL_Init(SDL_INIT_VIDEO); + sdl_session main_sdl_session; + + main_sdl_session.window = SDL_CreateWindow("pupes screensave", SCREEN_WIDTH, SCREEN_HEIGHT, 0); + SDL_Renderer *renderer = SDL_CreateRenderer(main_sdl_session.window, "gpu,vulcan"); + + signal(SIGTERM, exit); + SDL_FPoint last_pos = {static_cast(get_random_num(0,1920)),static_cast(get_random_num(0,1080))}; + SDL_FPoint new_pos; + while (true) { + + SDL_SetRenderDrawColor(renderer, get_random_num(0,255), get_random_num(0,255),get_random_num(0,255), SDL_ALPHA_OPAQUE); + new_pos = {static_cast(get_random_num(0,1920)),static_cast(get_random_num(0,1080))}; + SDL_RenderLine(renderer, last_pos.x ,last_pos.y, new_pos.x,new_pos.y); + last_pos = new_pos; + SDL_RenderPresent(renderer); + usleep(500000); + } + + std::cin.get(); +} diff --git a/src/types.h b/src/types.h new file mode 100644 index 0000000..fd619a8 --- /dev/null +++ b/src/types.h @@ -0,0 +1,5 @@ +#include +struct sdl_session { + SDL_Window *window; + SDL_Renderer *renderer; +};