summaryrefslogtreecommitdiffstats
path: root/src/core/Core.hpp
blob: fdbb377298aa880a11709aefe7d175cf5c940904 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once

#include <iomanip>
#include <tuple>

#include <easylogging++.h>
#include <SFML/Window.hpp>
#include <GL/glew.h>
#include <glm/gtc/type_ptr.hpp>

#include <world/GameState.hpp>
#include <core/AssetManager.hpp>
#include <graphics/Shader.hpp>
#include <graphics/Gui.hpp>
#include <graphics/RenderSection.hpp>
#include <network/NetworkClient.hpp>

struct MyMutex {
    std::mutex mtx;
    std::string str;
    MyMutex(std::string name);
    void lock();
    void unlock();
};

class Core {
	GameState *gameState;
	NetworkClient *client;
	sf::Window *window;
	AssetManager *assetManager;
	bool isMouseCaptured = false;
	bool isRunning = true;
	enum {
		MainMenu,
		Loading,
		Playing,
		PauseMenu,
	} currentState = Playing;
	float mouseXDelta, mouseYDelta;
	float deltaTime;
	float absTime;

	void RenderWorld();

	void HandleMouseCapture();

	void HandleEvents();

	void InitSfml(unsigned int WinWidth, unsigned int WinHeight, std::string WinTitle);

	void InitGlew();

	void SetMouseCapture(bool IsCaptured);

	void PrepareToRendering();

	void RenderFrame();

	unsigned int width();

	unsigned int height();

	void UpdateChunksToRender();

	void UpdateGameState();

	void UpdateSections();

	std::thread gameStateLoopThread;
	std::thread sectionUpdateLoopThread;

	Shader *shader;
	//Cube verticies, Cube VAO, Cube UVs, TextureIndexes UboTextureIndexes, TextureData UboTextureIndexes, TextureData2 UboTextureIndexes, Blocks VBO, Models VBO, Line VAO, Lines VBO
	bool isRendersShouldBeCreated=false;
	std::condition_variable waitRendersCreated;
	std::vector<Vector> renders;
	std::mutex toRenderMutex;
	std::vector<Vector> toRender;
	std::map<Vector, RenderSection> availableChunks;
	std::mutex availableChunksMutex;

	int ChunkDistance = 3;

	RenderState renderState;

	double tickRate = 0;
    double sectionRate = 0;

public:
	Core();

	~Core();

	void Exec();
};