123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include <iostream>
- #include <getopt.h>
- #include "Game.h"
- #include "gaming-core/utils/Clock.h"
- #include "gaming-core/wrapper/GL.h"
- #include "gaming-core/wrapper/GLEW.h"
- #include "gaming-core/wrapper/GLFW.h"
- #include "gaming-core/wrapper/Shader.h"
- #include "gaming-core/wrapper/Window.h"
- #include "gaming-core/wrapper/WindowOptions.h"
- #include "rendering/Renderer.h"
- bool parseArgs(int argAmount, char* const* args, WindowOptions& options) {
- while(true) {
- switch(getopt(argAmount, args, "fv")) {
- case '?': return true;
- case 'f': options.fullscreen = true; break;
- case 'v': options.vsync = true; break;
- case -1: return false;
- }
- }
- }
- int main(int argAmount, char* const* args) {
- WindowOptions options(3, 0, Size(800, 480), true, "Pigine");
- if(parseArgs(argAmount, args, options) || GLFW::init()) {
- return 0;
- }
- Window window(options);
- if(window.hasError() || GLEW::init()) {
- return 0;
- }
- Shader shader("resources/shader/vertex.vs", "resources/shader/fragment.fs");
- if(shader.hasError()) {
- return 0;
- }
- Renderer renderer(shader);
- Clock fps;
- Clock tps;
- Buttons buttons(window);
- Controller controller(buttons);
- static Game game(controller, fps, tps);
- window.show();
- const Clock::Nanos nanosPerTick = 10'000'000;
- Clock::Nanos lag = 0;
- while(!window.shouldClose() && game.isRunning()) {
- GL::checkAndPrintError("GL-Error");
- lag += fps.update();
- while(lag >= nanosPerTick) {
- lag -= nanosPerTick;
- tps.update();
- buttons.tick();
- game.tick();
- }
- Size size = window.getSize();
- GL::setViewport(size.width, size.height);
- Matrix view;
- view.scale(Vector3(2.0f / size.width, -2.0f / size.height, 1.0f));
- view.translate(Vector3(-1.0f, 1.0f, 0.0f));
- shader.setMatrix("view", view.getValues());
- game.render(static_cast<float>(lag) / nanosPerTick, renderer);
- window.swapBuffers();
- GL::clearFramebuffer();
- glfwPollEvents();
- }
- return 0;
- }
|