Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "stdafx.h"

#include "Headers/DefaultScene.h"

#include "GUI/Headers/GUIButton.h"

#include "Core/Headers/PlatformContext.h"
#include "Managers/Headers/SceneManager.h"
#include "Rendering/PostFX/Headers/PostFX.h"

#include "Dynamics/Entities/Units/Headers/Player.h"

#if !defined(CEGUI_STATIC)
#define CEGUI_STATIC
#endif
#include <CEGUI/CEGUI.h>

namespace Divide {
DefaultScene::DefaultScene(PlatformContext& context, ResourceCache& cache, SceneManager& parent, const stringImpl& name)
    : Scene(context, cache, parent, name)
{
}

bool DefaultScene::load(const stringImpl& name) {
    bool loadState = SCENE_LOAD(name, true, true);
    SceneGraphNode* light = addLight(LightType::DIRECTIONAL, _sceneGraph->getRoot());
    _currentSky = addSky();
    // Add a light
    vec2<F32> sunAngle(0.0f, Angle::to_RADIANS(45.0f));
    vec3<F32> sunvector(-cosf(sunAngle.x) * sinf(sunAngle.y),
                        -cosf(sunAngle.y),
                        -sinf(sunAngle.x) * sinf(sunAngle.y));
    
    light->get<TransformComponent>()->setPosition(sunvector);
    PushConstants& constants = _currentSky->get<RenderingComponent>()->pushConstants();
    constants.set("enable_sun", PushConstantType::BOOL, true);
    constants.set("sun_vector", PushConstantType::VEC3, sunvector);
    constants.set("sun_colour", PushConstantType::VEC3, light->getNode<Light>()->getDiffuseColour());

    state().saveLoadDisabled(true);

    return loadState;
}

void DefaultScene::processGUI(const U64 deltaTimeUS) {
    Scene::processGUI(deltaTimeUS);
}

bool DefaultScene::loadResources(bool continueOnErrors) {
    _taskTimers.push_back(0.0);

    return true;
}

void DefaultScene::postLoadMainThread() {
    // Replace buttons with nice, animated elements? images?
    const vectorImpl<stringImpl>& scenes = _parent.sceneNameList();

    const vec2<U16>& resolution = _context.gfx().renderingResolution();

    const I32 spacingX = 10;
    const I32 spacingY = 10;
    const I32 numColumns = 3;
    const I32 numRows = to_I32(std::ceil(to_F32(scenes.size()) / numColumns));
    const I32 btnWidth = 100;
    const I32 btnHeight = 100;
    const I32 windowCenterX = to_I32(resolution.width * 0.5f);
    const I32 windowCenterY = to_I32(resolution.height * 0.5f);
    const F32 btnStartXOffset = NORMALIZE(to_F32(windowCenterX) - numColumns * 0.5f * btnWidth, 0.0f, to_F32(resolution.width));
    const F32 btnStartYOffset = NORMALIZE(to_F32(windowCenterY) - numRows * 0.5f * btnHeight, 0.0f, to_F32(resolution.height));
    const I32 quitButtonWidth = 100;
    const I32 quitButtonHeight = 100;
    const I32 playerButtonHeight = 25;

    RelativePosition2D buttonPosition(RelativeValue(btnStartXOffset, 0.0f),
                                      RelativeValue(btnStartYOffset, 0.0f));
    // In pixels
    RelativeScale2D buttonSize(RelativeValue(0.0f, to_F32(btnWidth)),
                               RelativeValue(0.0f, to_F32(btnHeight)));

    size_t i = 0, j = 0;
    for (const stringImpl& scene : scenes) {
        if (scene != getName()) {
            size_t localOffsetX = btnWidth * (i % numColumns) + spacingX * (i % numColumns);
            size_t localOffsetY = btnHeight * (j % numRows) + spacingY * (j % numRows);

            buttonPosition.d_x.d_offset = to_F32(localOffsetX);
            buttonPosition.d_y.d_offset = to_F32(localOffsetY);
            GUIButton* btn = _GUI->addButton(_ID_RT("StartScene" + scene),
                                             scene,
                                             buttonPosition,
                                             buttonSize);

            btn->setEventCallback(GUIButton::Event::MouseClick,
                                  DELEGATE_BIND(&DefaultScene::loadScene, this, std::placeholders::_1));

            _buttonToSceneMap[btn->getGUID()] = scene;
            i++;
            if (i > 0 && i % numColumns == 0) {
                j++;
            }
        }
    }

    RelativePosition2D quitPosition(RelativeValue(0.0f, resolution.width - quitButtonWidth * 1.5f),
                                    RelativeValue(0.0f, resolution.height - quitButtonHeight * 1.5f));
    RelativeScale2D quitScale(RelativeValue(0.0f, to_F32(quitButtonWidth)),
                              RelativeValue(0.0f, to_F32(quitButtonHeight)));

    GUIButton* btn = _GUI->addButton(_ID_RT("Quit"),
                                     "Quit",
                                     quitPosition,
                                     quitScale);

    btn->setEventCallback(GUIButton::Event::MouseClick,
                          [this](I64 btnGUID) {
                              _context.app().RequestShutdown();
                          });

    RelativePosition2D playerChangePosition(RelativeValue(0.01f, 0.0f),
                                            RelativeValue(0.0f, resolution.height - playerButtonHeight * 1.5f));

    RelativeScale2D playerChangeScale = pixelScale(quitButtonWidth, playerButtonHeight);

    btn = _GUI->addButton(_ID_RT("AddPlayer"),
                    "Add Player",
                    playerChangePosition,
                    playerChangeScale);

    btn->setEventCallback(GUIButton::Event::MouseClick,
                          [this](I64 btnGUID) {
                              addPlayerInternal(true);
                          });

    playerChangePosition.d_y.d_offset -= playerButtonHeight * 1.5f;

    btn = _GUI->addButton(_ID_RT("RemovePlayer"),
                          "Remove Player",
                          playerChangePosition,
                          playerChangeScale);

    btn->setEventCallback(GUIButton::Event::MouseClick,
                          [this](I64 btnGUID) {
                              if (_scenePlayers.size() > 1) {
                                  removePlayerInternal(_scenePlayers.back()->index());
                              }
                          });

    RelativePosition2D textPosition = pixelPosition(windowCenterX - 100, windowCenterY - ((numRows / 2) + 1)* btnHeight);
    _GUI->addText("globalMessage",
                  textPosition,
                  Font::DIVIDE_DEFAULT,
                  UColour(128, 64, 64, 255),
                  "");
    
    Scene::postLoadMainThread();
}

void DefaultScene::processInput(PlayerIndex idx, const U64 deltaTimeUS) {
    if (!_sceneToLoad.empty()) {
        _GUI->modifyText(_ID("globalMessage"),
                         Util::StringFormat("Please wait while scene [ %s ] is loading", _sceneToLoad.c_str()));
        //_parent.switchScene(_sceneToLoad, false);
        _sceneToLoad.clear();
    }

    Angle::DEGREES<F32>& angle = _camAngle[getSceneIndexForPlayer(idx)];
    if (idx % 3 == 1) {
        getPlayerForIndex(idx)->getCamera().rotatePitch(angle);
    } else if (idx % 3 == 2) {
        getPlayerForIndex(idx)->getCamera().rotateRoll(angle);
    } else {
        getPlayerForIndex(idx)->getCamera().rotateYaw(angle);
    }
    angle = 0.0f;

    Scene::processInput(idx, deltaTimeUS);
}

void DefaultScene::processTasks(const U64 deltaTimeUS) {
    D64 SpinTimer = Time::Milliseconds(16.0);
    if (_taskTimers[0] >= SpinTimer) {
        for (hashMapImpl<U8, Angle::DEGREES<F32>>::value_type& it : _camAngle) {
            it.second = 0.25f * ((it.first * 2.0f) + 1.0f) * (it.first % 2 == 0 ? -1 : 1);
        }

        _taskTimers[0] = 0.0;
    }

    Scene::processTasks(deltaTimeUS);
}

void DefaultScene::loadScene(I64 btnGUID) {
    _sceneToLoad = _buttonToSceneMap[btnGUID];
    Console::d_printf("Loading scene [ %s ]", _sceneToLoad.c_str());

    GUIButton* selection = _GUI->getGUIElement<GUIButton>(btnGUID);
    selection->setText(_sceneToLoad + "\nLoading ...");
    for (hashMapImpl<I64, stringImpl>::value_type it : _buttonToSceneMap) {
        GUIButton* btn = _GUI->getGUIElement<GUIButton>(it.first);
        btn->setActive(false);
        if (it.first != btnGUID) {
            btn->setVisible(false);
        }
    }
}

void DefaultScene::onSetActive() {
    for (hashMapImpl<I64, stringImpl>::value_type it : _buttonToSceneMap) {
        GUIButton* btn = _GUI->getGUIElement<GUIButton>(it.first);
        
        btn->setText(it.second);
        btn->setActive(true);
        btn->setVisible(true);
    }

    Scene::onSetActive();
}

};

Commits for Divide-Framework/trunk/Source Code/Scenes/DefaultScene/DefaultScene.cpp

Diff revisions: vs.
Revision Author Commited Message
1004 Diff Diff IonutCava picture IonutCava Wed 20 Dec, 2017 17:16:32 +0000

[Ionut]
- More GUI cleanup (added multiple GUIButton events)
- Typedef vec4<U8> and vec4<F32> to UColour and FColour respectively for easier to read code.

1003 Diff Diff IonutCava picture IonutCava Tue 19 Dec, 2017 17:08:06 +0000

[Ionut]
- GUI cleanup

1002 Diff Diff IonutCava picture IonutCava Mon 18 Dec, 2017 17:31:54 +0000

[Ionut]
- Cleanup GUI a bit
- Disable some nVidia GL warnings

998 Diff Diff IonutCava picture IonutCava Wed 13 Dec, 2017 17:20:30 +0000

[Ionut]
- Fixed a scene change crash

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

992 Diff Diff IonutCava picture IonutCava Thu 07 Dec, 2017 18:01:51 +0000

[Ionut]
- Split PhysicsComponent into 2, ECS-based, components: TransformComponent and RigidBodyComponent
UNTESTED

979 Diff Diff IonutCava picture IonutCava Tue 21 Nov, 2017 23:24:57 +0000

[Ionut]
- W.I.P. Rework GUI element positioning and scaling
- Update ImGUI and IMGUI_ADDONS

978 Diff Diff IonutCava picture IonutCava Mon 20 Nov, 2017 23:42:23 +0000

[Ionut]
- More decoupling between window size and render resolution.
- Attempt to preserve render target aspect on window resize events

  • Resolution change is currently broken *
968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

957 IonutCava picture IonutCava Tue 31 Oct, 2017 17:15:51 +0000

[Ionut]
- Some SGN node search refactoring
- typedef PlayerIndex