feat: setup template
feat: implemented game of life feat: implemented automatic stepping fix: operator< Cell Cell now sorts by y first, then x fix: equalized scroll x/y fix: removed unused code path fix: marked simulation::living as static since it's no longer forward declared tweak: decreased number of cells on random initialization feat: defined Toggle element feat: added debug information toggle to UI feat: implemented simulation multithreading feat: improved simulation frame delta controls feat: inverted direction of panel colours fix: removed leftover die colors feat: reorganized and cleaned up style namespace chore: increased button border width feat: added SDL3 submodule feat: added SDL3_ttf submodule feat: moved clay to vendor (rather than include) feat: replaced premake5 with CMake to vendor SDL3 chore: translated more C stuff to C++ in main.cpp fix: stepping being inconsistent while running feat: fixed incorrect behaviour on simulation and added benchmarking code feat: minor adjustments to UI layout feat: increased thread count for pool feat: improved simulation benchmarking feat: simulation tasks can now be subdivided into separate workloads for separate threads feat: improved task counting thread safety chore: massively increased random field fix: target delta time is now enforced feat: added toggle for locked framerate fix: replaced manual .lock()/.unlock() calls with std::scoped_lock fix: benchmarking code was off by a magnitude of 1 feat: separated cell state checking into separate function in case another algo is faster than .contains chore: some comments on variables in simulation.cpp feat: set task split to hardware_concurrency() feat: added basic culling to cell renderer feat: implemented simulation threading toggle chore: lowered random button's field size chore: reduced padding on panel containers chore: minor formatting adjustment feat: added README.md fix: inverted x scroll feat: converted project to template feat: added .clangd
This commit is contained in:
commit
9b2ae482f1
27 changed files with 5622 additions and 0 deletions
144
src/main.cpp
Normal file
144
src/main.cpp
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
#define SDL_MAIN_HANDLED
|
||||
|
||||
#include "application.h"
|
||||
#include "input.h"
|
||||
#include "resources.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_error.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_hints.h>
|
||||
#include <SDL3/SDL_init.h>
|
||||
#include <SDL3/SDL_keycode.h>
|
||||
#include <SDL3/SDL_log.h>
|
||||
#include <SDL3/SDL_mouse.h>
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
#include <clay/clay.h>
|
||||
#include <renderer/clay_renderer_SDL3.h>
|
||||
#include <renderer/ui_data.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
constexpr SDL_InitFlags sdlInitFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||
|
||||
SDL_Window *window = nullptr;
|
||||
SDL_Renderer *renderer = nullptr;
|
||||
int screenWidth = 1920, screenHeight = 1080;
|
||||
bool running = true;
|
||||
uint64_t clayMemorySize = 0;
|
||||
|
||||
Clay_Arena clayPrimaryArena;
|
||||
|
||||
Clay_SDL3RendererData backendData = {
|
||||
nullptr, nullptr, nullptr
|
||||
};
|
||||
|
||||
static
|
||||
Clay_Dimensions MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
|
||||
TTF_Font **fonts = (TTF_Font**)userData;
|
||||
TTF_Font *font = fonts[config->fontId];
|
||||
int width, height;
|
||||
TTF_SetFontSize(font, config->fontSize);
|
||||
if (!TTF_GetStringSize(font, text.chars, text.length, &width, &height)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "MeasureText failed to measure text %s", SDL_GetError());
|
||||
}
|
||||
return (Clay_Dimensions) { (float)width, (float)height };
|
||||
}
|
||||
|
||||
static
|
||||
void HandleClayErrors(Clay_ErrorData data) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", data.errorText.chars);
|
||||
}
|
||||
|
||||
static inline
|
||||
void LogOutputResolution() {
|
||||
int w, h;
|
||||
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||
SDL_Log("output size: %i, %d", w, h);
|
||||
}
|
||||
|
||||
static inline
|
||||
void InitSDL() {
|
||||
SDL_SetHint(SDL_HINT_RENDER_LINE_METHOD, "3");
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_Init failed: %s", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
if ((window = SDL_CreateWindow("Window", screenWidth, screenHeight, sdlInitFlags)) == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateWindow failed: %s", SDL_GetError());
|
||||
exit(2);
|
||||
}
|
||||
if ((renderer = SDL_CreateRenderer(window, NULL)) == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateRenderer failed: %s", SDL_GetError());
|
||||
exit(3);
|
||||
}
|
||||
if (!TTF_Init()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_Init failed: %s", SDL_GetError());
|
||||
exit(4);
|
||||
}
|
||||
if ((resources::textEngine = TTF_CreateRendererTextEngine(renderer)) == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_CreateRendererTextEngine failed: %s", SDL_GetError());
|
||||
exit(5);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void InitClay() {
|
||||
clayMemorySize = Clay_MinMemorySize();
|
||||
clayPrimaryArena = Clay_CreateArenaWithCapacityAndMemory(clayMemorySize, SDL_malloc(clayMemorySize));
|
||||
Clay_Initialize(clayPrimaryArena, { (float)screenWidth, (float)screenHeight }, { HandleClayErrors });
|
||||
Clay_SetMeasureTextFunction(MeasureText, resources::fonts);
|
||||
Clay_SetLayoutDimensions({ (float)screenWidth, (float)screenHeight });
|
||||
float x{ 0 }, y{ 0 };
|
||||
SDL_GetMouseState(&x, &y);
|
||||
Clay_SetPointerState((Clay_Vector2) { x, y }, false);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
InitSDL();
|
||||
resources::LoadResources();
|
||||
LogOutputResolution();
|
||||
InitClay();
|
||||
backendData = { renderer, resources::textEngine, resources::fonts };
|
||||
SDL_Event event;
|
||||
uint64_t startFrameTime = SDL_GetTicksNS();
|
||||
double deltaTime = 0.0;
|
||||
while (running) {
|
||||
std::srand(SDL_GetTicksNS());
|
||||
deltaTime = SDL_GetTicksNS() - startFrameTime;
|
||||
startFrameTime = SDL_GetTicksNS();
|
||||
UiData_Clear();
|
||||
input::FrameStart();
|
||||
while (SDL_PollEvent(&event)) {
|
||||
application::HandleEvent(event);
|
||||
input::HandleEvent(event);
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
Clay_SetLayoutDimensions({
|
||||
(float)event.window.data1,
|
||||
(float)event.window.data2
|
||||
});
|
||||
LogOutputResolution();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
Clay_UpdateScrollContainers(true, input::scrollMotion, deltaTime);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
Clay_RenderCommandArray commands{ application::RenderApplication() };
|
||||
SDL_Clay_RenderClayCommands(&backendData, &commands);
|
||||
SDL_RenderPresent(renderer);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue