123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "client/input/Controller.h"
- #include "client/rendering/Engine.h"
- #include "client/rendering/Framebuffers.h"
- #include "client/rendering/RenderSettings.h"
- #include "client/rendering/Shaders.h"
- #include "gaming-core/network/Client.h"
- #include "gaming-core/network/ENet.h"
- #include "gaming-core/rendering/Window.h"
- #include "gaming-core/rendering/WindowOptions.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"
- void updateSize(const Window& window, Size& size, Framebuffers& framebuffers) {
- Size newSize = window.getSize();
- if(newSize.width != size.width || newSize.height != size.height) {
- size = newSize;
- GL::setViewport(size.width, size.height);
- framebuffers.resize(size);
- }
- }
- int main() {
- ENet enet;
- if(enet.init()) {
- std::cout << "cannot initialize enet\n";
- return 0;
- }
- Client client;
- if(client.hasError()) {
- std::cout << client.getError() << '\n';
- return 0;
- }
- if(GLFW::init()) {
- return 0;
- }
- Size size(1024, 620);
- WindowOptions options(4, 0, size, false, "test");
- TextInput textInput;
- Window window(textInput, options);
- if(window.hasError() || GLEW::init()) {
- return 0;
- }
- Shaders shaders;
- if(shaders.hasError()) {
- return 0;
- }
- Framebuffers framebuffers;
- if(framebuffers.init(size)) {
- return 0;
- }
- RenderSettings renderSettings;
- Engine engine(shaders, framebuffers, size, renderSettings);
- Buttons buttons(window);
- Controller controller(buttons);
- Clock fps;
- Clock tps;
- Game game(textInput, controller, fps, tps, renderSettings, size, client);
- window.show();
- GL::printError("setup error");
- const Clock::Nanos nanosPerTick = 50000000;
- Clock::Nanos lag = 0;
- while(!window.shouldClose() && game.isRunning()) {
- GL::printError("loop error");
- updateSize(window, size, framebuffers);
- engine.renderTick(static_cast<float>(lag) / nanosPerTick, game);
- window.swapBuffers();
- lag += fps.update();
- while(lag >= nanosPerTick) {
- lag -= nanosPerTick;
- tps.update();
- buttons.tick();
- game.tick();
- }
- glfwPollEvents();
- }
- return 0;
- }
|