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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include "gameMainWindow.h"
#include "editNetwork.h"
#include "gameMainSelector.h"
#include "imgui_extras.h"
#include "manualCameraController.h"
#include "queryTool.h"
#include "svgIcon.h"
#include <SDL2/SDL.h>
#include <collection.h>
#include <game/environment.h>
#include <game/gamestate.h>
#include <game/network/rail.h>
#include <game/worldobject.h> // IWYU pragma: keep
#include <gfx/camera_controller.h>
#include <gfx/renderable.h>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <memory>
class GameMainToolbar : public UIComponent {
public:
static constexpr auto TOOLBAR_HEIGHT = 54.F;
template<typename T> static constexpr T TOOLBAR_ICON_SIZE {32, 32};
explicit GameMainToolbar(GameMainSelector * gms) : gms {gms} { }
void
render() override
{
if (IltGui::BeginToolbar("bottomBar", ImGuiDir_Down, TOOLBAR_HEIGHT)) {
if (ImGui::ImageButton("Build rails", *buildRailsIcon, TOOLBAR_ICON_SIZE<ImVec2>)) {
gms->target = std::make_unique<EditNetworkOf<RailLinks>>();
}
if (ImGui::ImageButton("Query", *queryToolIcon, TOOLBAR_ICON_SIZE<ImVec2>)) {
gms->target = std::make_unique<QueryTool>();
}
IltGui::EndToolbar();
}
}
bool
handleInput(const SDL_Event &) override
{
return false;
}
private:
SvgIcon buildRailsIcon {TOOLBAR_ICON_SIZE<ImageDimensions>, "ui/icon/rails.svg"};
SvgIcon queryToolIcon {TOOLBAR_ICON_SIZE<ImageDimensions>, "ui/icon/magnifier.svg"};
GameMainSelector * gms;
};
GameMainWindow::GameMainWindow(ScreenAbsCoord size) : SceneRenderer {size, 0}
{
uiComponents.create<ManualCameraController>(glm::vec2 {310'727'624, 494'018'810});
auto gms = uiComponents.create<GameMainSelector>(&camera);
uiComponents.create<GameMainToolbar>(gms);
}
void
GameMainWindow::tick(TickDuration)
{
uiComponents.apply<CameraController>(&CameraController::updateCamera, &camera);
}
bool
GameMainWindow::handleInput(const SDL_Event & event)
{
switch (event.type) {
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_RESIZED:
SceneRenderer::resize({event.window.data1, event.window.data2});
break;
default:
break;
}
default:
break;
}
return WindowContent::handleInput(event);
}
void
GameMainWindow::render()
{
SceneRenderer::render(*this);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
uiComponents.apply(&UIComponent::render);
}
void
GameMainWindow::content(const SceneShader & shader, const Frustum & frustum) const
{
for (const auto & [assetId, asset] : gameState->assets) {
if (const auto renderable = asset.getAs<const Renderable>()) {
renderable->render(shader, frustum);
}
}
gameState->world.apply<const Renderable>(&Renderable::render, shader, frustum);
uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader, frustum);
}
void
GameMainWindow::environment(const SceneShader &, const SceneRenderer & r) const
{
gameState->environment->render(r, *this);
}
void
GameMainWindow::lights(const SceneShader & shader) const
{
gameState->world.apply<const Renderable>(&Renderable::lights, shader);
}
void
GameMainWindow::shadows(const ShadowMapper & shadowMapper, const Frustum & frustum) const
{
for (const auto & [assetId, asset] : gameState->assets) {
if (const auto renderable = asset.getAs<const Renderable>()) {
renderable->shadows(shadowMapper, frustum);
}
}
gameState->world.apply<const Renderable>(&Renderable::shadows, shadowMapper, frustum);
}
|