#include "canvas.h" #include "simulation.h" #include #include #include int main() { Canvas canvas(800, 600); RingBuffer buffer(64); std::thread sim(simulation_thread, std::ref(buffer)); std::thread render(render_thread, std::ref(buffer), std::ref(canvas)); SDL_Init(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("Solar System", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, canvas.width, canvas.height, 0); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_STREAMING, canvas.width, canvas.height); while (running) { void *pixels; int pitch; SDL_LockTexture(texture, nullptr, &pixels, &pitch); memcpy(pixels, canvas.pixels.data(), canvas.pixels.size() * sizeof(Color)); SDL_UnlockTexture(texture); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, nullptr, nullptr); SDL_RenderPresent(renderer); SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) running = false; } std::this_thread::sleep_for(std::chrono::milliseconds(16)); // ~60fps } sim.join(); render.join(); }