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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "Headers/DisplayWindow.h"
#include "Core/Headers/Application.h"

#include "Core/Headers/ParamHandler.h"

#define HAVE_M_PI
#include <SDL.h>

namespace Divide {
DisplayWindow::DisplayWindow(WindowManager& context)
 : GUIDWrapper(),
   _context(context),
   _hasFocus(true),
   _minimized(false),
   _hidden(true),
   _type(WindowType::COUNT),
   _previousType(WindowType::COUNT),
   _queuedType(WindowType::COUNT),
   _mainWindow(nullptr),
   _internalMoveEvent(false),
   _externalResizeEvent(false)
{
    _windowPosition.fill(vec2<I32>(0));
    _prevDimensions.fill(vec2<U16>(1));
    _windowDimensions.fill(vec2<U16>(1));
}

DisplayWindow::~DisplayWindow() 
{
}

ErrorCode DisplayWindow::destroyWindow() {
    if (_type != WindowType::COUNT) {
        DIVIDE_ASSERT(_mainWindow != nullptr,
            "DisplayWindow::destroyWindow error: Tried to double-delete the same window!");

        SDL_DestroyWindow(_mainWindow);
        _mainWindow = nullptr;
    }

    return ErrorCode::NO_ERR;
}

ErrorCode DisplayWindow::init(U32 windowFlags, WindowType initialType, const ResolutionByType& initialResolutions) {
    ParamHandler& par = ParamHandler::instance();

    _type = initialType;

    _windowDimensions = initialResolutions;

    _mainWindow = SDL_CreateWindow(par.getParam<stringImpl>(_ID("appTitle"), "Divide").c_str(),
                                   SDL_WINDOWPOS_CENTERED_DISPLAY(_context.targetDisplay()),
                                   SDL_WINDOWPOS_CENTERED_DISPLAY(_context.targetDisplay()),
                                   1,
                                   1,
                                   windowFlags);

    I32 positionX, positionY;
    SDL_GetWindowPosition(_mainWindow, &positionX, &positionY);
    setPosition(type(), positionX, positionY);

    // Check if we have a valid window
    if (!_mainWindow) {
        SDL_Quit();
        Console::errorfn(Locale::get(_ID("ERROR_GFX_DEVICE")),
                         Locale::get(_ID("ERROR_SDL_WINDOW")));
        Console::printfn(Locale::get(_ID("WARN_APPLICATION_CLOSE")));
        return ErrorCode::SDL_WINDOW_INIT_ERROR;
    }

    return ErrorCode::NO_ERR;
}

void DisplayWindow::update() {
    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
        case SDL_QUIT: {
            SDL_HideWindow(_mainWindow);
            Application::instance().RequestShutdown();
        } break;
        case SDL_WINDOWEVENT: {
            switch (event.window.event) {
            case SDL_WINDOWEVENT_ENTER:
            case SDL_WINDOWEVENT_FOCUS_GAINED: {
                _context.handleWindowEvent(WindowEvent::GAINED_FOCUS,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_LEAVE:
            case SDL_WINDOWEVENT_FOCUS_LOST: {
                _context.handleWindowEvent(WindowEvent::LOST_FOCUS,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_RESIZED: {
                _externalResizeEvent = true;
                setDimensions(type(),
                              to_ushort(event.window.data1),
                              to_ushort(event.window.data2));
                _externalResizeEvent = false;
            }break;
            case SDL_WINDOWEVENT_SIZE_CHANGED: {
                _context.handleWindowEvent(WindowEvent::RESIZED_INTERNAL,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_MOVED: {
                _context.handleWindowEvent(WindowEvent::MOVED,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);

                if (!_internalMoveEvent) {
                    setPosition(type(),
                                event.window.data1,
                                event.window.data2);
                    _internalMoveEvent = false;
                }
            } break;
            case SDL_WINDOWEVENT_SHOWN: {
                _context.handleWindowEvent(WindowEvent::SHOWN,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_HIDDEN: {
                _context.handleWindowEvent(WindowEvent::HIDDEN,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_MINIMIZED: {
                _context.handleWindowEvent(WindowEvent::MAXIMIZED,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_MAXIMIZED: {
                _context.handleWindowEvent(WindowEvent::MAXIMIZED,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            case SDL_WINDOWEVENT_RESTORED: {
                _context.handleWindowEvent(WindowEvent::RESTORED,
                    getGUID(),
                    event.window.data1,
                    event.window.data2);
            } break;
            };
        } break;
        }
    }

    if (_queuedType != WindowType::COUNT) {
        //handleChangeWindowType(_queuedType);
        _queuedType = WindowType::COUNT;
    }
}

void DisplayWindow::setDimensionsInternal(U16 w, U16 h) {
    if (_externalResizeEvent && 
        (_type != WindowType::WINDOW &&
         _type != WindowType::SPLASH))
    {
        return;
    }

    if (_type == WindowType::FULLSCREEN) {
        // Should never be true, but need to be sure
        SDL_DisplayMode mode, closestMode;
        SDL_GetCurrentDisplayMode(_context.targetDisplay(), &mode);
        mode.w = w;
        mode.h = h;
        SDL_GetClosestDisplayMode(_context.targetDisplay(), &mode, &closestMode);
        SDL_SetWindowDisplayMode(_mainWindow, &closestMode);
    } else {
        if (_externalResizeEvent) {
            // Find a decent resolution close to our dragged dimensions
            SDL_DisplayMode mode, closestMode;
            SDL_GetCurrentDisplayMode(_context.targetDisplay(), &mode);
            mode.w = w;
            mode.h = h;
            SDL_GetClosestDisplayMode(_context.targetDisplay(), &mode, &closestMode);
            w = to_ushort(closestMode.w);
            h = to_ushort(closestMode.h);
        }

        SDL_SetWindowSize(_mainWindow, w, h);
    }
}

/// Window positioning is handled by SDL
void DisplayWindow::setPositionInternal(I32 w, I32 h) {
    _internalMoveEvent = true;
    SDL_SetWindowPosition(_mainWindow, w, h);
}

/// Centering is also easier via SDL
void DisplayWindow::centerWindowPosition() {
    _internalMoveEvent = true;

    setPosition(type(),
                SDL_WINDOWPOS_CENTERED_DISPLAY(_context.targetDisplay()),
                SDL_WINDOWPOS_CENTERED_DISPLAY(_context.targetDisplay()));
}

/// Mouse positioning is handled by SDL
void DisplayWindow::setCursorPosition(I32 x, I32 y) const {
    SDL_WarpMouseInWindow(_mainWindow, x, y);
}

void DisplayWindow::handleChangeWindowType(WindowType newWindowType) {
    _previousType = _type;
    _type = newWindowType;
    I32 switchState = 0;
    switch (newWindowType) {
        case WindowType::SPLASH: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, 0);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::WINDOW: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, 0);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_TRUE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::FULLSCREEN_WINDOWED: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_FALSE);
        } break;
        case WindowType::FULLSCREEN: {
            switchState = SDL_SetWindowFullscreen(_mainWindow, SDL_WINDOW_FULLSCREEN);
            assert(switchState >= 0);

            SDL_SetWindowBordered(_mainWindow, SDL_FALSE);
            SDL_SetWindowGrab(_mainWindow, SDL_TRUE);
        } break;
    };

    const vec2<U16>& dimensions = getDimensions(newWindowType);
    setDimensionsInternal(dimensions.width, dimensions.height);

    centerWindowPosition();

    if (hidden()) {
        SDL_ShowWindow(_mainWindow);
        hidden(false);
    }
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/DisplayWindow.cpp

Diff revisions: vs.
Revision Author Commited Message
827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

818 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

720 Diff Diff IonutCava picture IonutCava Mon 06 Jun, 2016 15:51:06 +0000

[IonutCava]
- PVS-Studio guided static analysis fixes and optimizations
- Added a flag to SceneState to bypass the Save/Load system not needed for certain types of scenes (menus, cinematics, etc)

684 Diff Diff IonutCava picture IonutCava Wed 20 Apr, 2016 16:27:05 +0000

[IonutCava]
- More math template code cleanup

670 Diff Diff IonutCava picture IonutCava Wed 06 Apr, 2016 16:21:35 +0000

[IonutCava]
- getInstance() renamed to instance() for simplicity (should really go away altogether, but that’s a different issue)
- some particle emitter threading updates

669 Diff Diff IonutCava picture IonutCava Mon 04 Apr, 2016 16:15:35 +0000

[IonutCava]
- Move Task creation calls to TaskPool.h
- Allow tasks to use any pool, but default behaviour is to use the Kernel’s main task pool
- Change image transparency check to use the task pool instead of OpenMP
— Perfect place for future parallel_for implementation
- Warning fixes
- Some method renaming for improved readability

667 Diff Diff IonutCava picture IonutCava Fri 01 Apr, 2016 16:12:16 +0000

[IonutCava]
- replaced more strings with _ID equivalent
- streamlined shader include preprocessing
- improved intersection test performance for the Octree system at the cost of some memory

656 Diff Diff IonutCava picture IonutCava Fri 04 Mar, 2016 17:23:26 +0000

[Ionut]
- Separate resolution from window size
— Still buggy

655 IonutCava picture IonutCava Wed 02 Mar, 2016 17:22:28 +0000

[IonutCava]
- Rebalance responsibilities between Kernel and Application
— Application handles the main loop and calls the appropriate kernel methods