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
#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"

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_wptr 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.lock()->get<PhysicsComponent>()->setPosition(sunvector);
    PushConstants& constants = _currentSky.lock()->get<RenderingComponent>()->pushConstants();
    constants.set("enable_sun", PushConstantType::BOOL, true);
    constants.set("sun_vector", PushConstantType::VEC3, sunvector);
    constants.set("sun_colour", PushConstantType::VEC3, light.lock()->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 I32 btnStartXOffset = to_I32(windowCenterX - numColumns * 0.5f * btnWidth);
    const I32 btnStartYOffset = to_I32(windowCenterY - numRows * 0.5f * btnHeight);
    const I32 quitButtonWidth = 100;
    const I32 quitButtonHeight = 100;
    const I32 playerButtonHeight = 25;

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

        GUIButton* btn = _GUI->addButton(_ID_RT("StartScene" + scene), scene,
            vec2<I32>(btnStartXOffset + localOffsetX,
                btnStartYOffset + localOffsetY),
            vec2<U32>(btnWidth, btnHeight),
            DELEGATE_BIND(&DefaultScene::loadScene, this, std::placeholders::_1));

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

    _GUI->addButton(_ID_RT("Quit"), "Quit",
        vec2<I32>(resolution.width - quitButtonWidth * 1.5f, resolution.height - quitButtonHeight * 1.5f),
        vec2<U32>(quitButtonWidth, quitButtonHeight),
        [this](I64 btnGUID) { _context.app().RequestShutdown(); });

    _GUI->addButton(_ID_RT("AddPlayer"), "Add Player",
        vec2<I32>(0, resolution.height - playerButtonHeight * 1.5f),
        vec2<U32>(quitButtonWidth, playerButtonHeight),
        [this](I64 btnGUID) {
            addPlayerInternal(true);
        });

    _GUI->addButton(_ID_RT("RemovePlayer"), "Remove Player",
        vec2<I32>(0, resolution.height - playerButtonHeight * 1.5f - playerButtonHeight * 1.5f),
        vec2<U32>(quitButtonWidth, playerButtonHeight),
        [this](I64 btnGUID) {
            if (_scenePlayers.size() > 1) {
                removePlayerInternal(_scenePlayers.back()->index());
            }
    });

    _GUI->addText(_ID("globalMessage"),
        vec2<I32>(windowCenterX,
            windowCenterY + (numRows + 1)* btnHeight),
        Font::DIVIDE_DEFAULT,
        vec4<U8>(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("Loading ...");
    for (hashMapImpl<I64, stringImpl>::value_type it : _buttonToSceneMap) {
        GUIButton* btn = _GUI->getGUIElement<GUIButton>(it.first);
        if (btn->getGUID() != btnGUID) {
            btn->setActive(false);
            btn->setVisible(false);
        }
    }
}

void DefaultScene::onSetActive() {
    vectorImpl<stringImpl> scenes = _parent.sceneNameList();

    for (const stringImpl& scene : scenes) {
        GUIButton* btn = _GUI->getGUIElement<GUIButton>(_ID_RT("StartScene" + scene));
        
        btn->setText(scene);
        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
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 Diff Diff IonutCava picture IonutCava Tue 31 Oct, 2017 17:15:51 +0000

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

950 Diff Diff IonutCava picture IonutCava Sun 22 Oct, 2017 22:25:05 +0000

[Ionut]
- Revamp camera management
- More work on improving the command buffer system:
— Performance tweaks
— Validation
— Debug features
- Some code cleanup for Object3D stuff (preRender/onRender changes)

Still haven’t fixed random flashing issue

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

925 Diff Diff IonutCava picture IonutCava Fri 04 Aug, 2017 13:10:43 +0000

[Ionut]
- Cleanup commandIndex and commandOffset updates between GFXDevice and RenderingComponent
- Fix some shader code rot
- Fix a bug in ParticleEmitter creation
- Disable OIT passes for now (really buggy)

922 Diff Diff IonutCava picture IonutCava Mon 31 Jul, 2017 21:52:27 +0000

[Ionut]
- Rework time and metric conversion functions to be more type independent
— Add nano-second support
— Properly detect arithmetic operands' types and decide conversion based on rank for maximum precision
— Add unit tests for time conversion cases
- Auto-adapt number of gl queries for frame timing based on performance
- Modify fontstash and glfonststash to batch upload vert data and to use vertex attrib format and vb binding instead of attrib pointers
— Sacrifice some CPU performance by chaning the structure of arrays to an array of structures for vert data, but gain performance from fewer API calls to OpenGL for uploading text data

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

868 IonutCava picture IonutCava Sat 25 Feb, 2017 21:46:55 +0000

[IonutCava]
- Fix buggy SSE Quaternion math
- Fix some typos and naming issues