/
legacywidget.cpp
210 lines (175 loc) · 5.47 KB
/
legacywidget.cpp
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
/** @file legacywidget.cpp
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#include "de_platform.h"
#include "ui/widgets/legacywidget.h"
#include "ui/dd_input.h"
#include "ui/ui_main.h"
#include "ui/ui2_main.h"
#include "ui/sys_input.h"
#include "ui/busyvisual.h"
#include "ui/windowsystem.h"
#include "dd_def.h"
#include "dd_main.h"
#include "dd_loop.h"
#include "sys_system.h"
#include "map/gamemap.h"
#include "network/net_main.h"
#include "render/r_main.h"
#include "render/rend_list.h"
#include "render/rend_console.h"
#include "audio/s_main.h"
#include "gl/gl_main.h"
#include "gl/sys_opengl.h"
#include "gl/gl_defer.h"
/**
* Maximum number of milliseconds spent uploading textures at the beginning
* of a frame. Note that non-uploaded textures will appear as pure white
* until their content gets uploaded (you should precache them).
*/
#define FRAME_DEFERRED_UPLOAD_TIMEOUT 20
boolean drawGame = true; // If false the game viewport won't be rendered
using namespace de;
DENG2_PIMPL(LegacyWidget)
{
Instance(Public *i) : Base(i)
{}
};
LegacyWidget::LegacyWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{}
void LegacyWidget::viewResized()
{
if(BusyMode_Active() || isDisabled() || Sys_IsShuttingDown()) return;
LOG_AS("LegacyWidget");
LOG_TRACE("View resized to ") << root().viewSize().asText();
// Update viewports.
R_SetViewGrid(0, 0);
if(/*BusyMode_Active() ||*/ UI_IsActive() || !App_GameLoaded())
{
// Update for busy mode.
R_UseViewPort(0);
}
R_LoadSystemFonts();
if(UI_IsActive())
{
UI_UpdatePageLayout();
}
}
void LegacyWidget::update()
{
if(isDisabled()) return;
//LOG_DEBUG("Legacy update");
DENG2_ASSERT(!BusyMode_Active());
// We may be performing GL operations.
ClientWindow::main().glActivate();
// Run at least one (fractional) tic.
Loop_RunTics();
// We may have received a Quit message from the windowing system
// during events/tics processing.
if(Sys_IsShuttingDown())
return;
GL_ProcessDeferredTasks(FRAME_DEFERRED_UPLOAD_TIMEOUT);
// Request update of window contents.
root().window().draw();
// After the first frame, start timedemo.
//DD_CheckTimeDemo();
}
void LegacyWidget::draw()
{
bool cannotDraw = (isDisabled() || !GL_IsFullyInited());
if(renderWireframe || cannotDraw)
{
// When rendering is wireframe mode, we must clear the screen
// before rendering a frame.
glClear(GL_COLOR_BUFFER_BIT);
}
if(cannotDraw) return;
if(drawGame)
{
if(App_GameLoaded())
{
// Interpolate the world ready for drawing view(s) of it.
if(theMap)
{
R_BeginWorldFrame();
}
R_RenderViewPorts();
}
else if(titleFinale == 0)
{
// Title finale is not playing. Lets do it manually.
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);
R_RenderBlankView();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
if(!(UI_IsActive() && UI_Alpha() >= 1.0))
{
UI2_Drawer();
// Draw any full window game graphics.
if(App_GameLoaded() && gx.DrawWindow)
{
Size2Raw dimensions(DENG_WINDOW->width(), DENG_WINDOW->height());
gx.DrawWindow(&dimensions);
}
}
}
if(Con_TransitionInProgress())
Con_DrawTransition();
if(drawGame)
{
// Debug information.
Net_Drawer();
S_Drawer();
// Finish up any tasks that must be completed after view(s) have been drawn.
R_EndWorldFrame();
}
if(UI_IsActive())
{
// Draw user interface.
UI_Drawer();
}
// Draw console.
Rend_Console();
// End any open DGL sequence.
DGL_End();
}
bool LegacyWidget::handleEvent(Event const &event)
{
/**
* @todo Event processing should occur here, not during Loop_RunTics().
* However, care must be taken to reproduce the vanilla behavior of
* controls with regard to response times.
*
* @todo Input drivers need to support Unicode text; for now we have to
* submit as Latin1.
*/
// Note: repeat events are ignored here as the legacy input system does
// its own.
if(event.type() == Event::KeyPress ||
event.type() == Event::KeyRelease)
{
KeyEvent const &ev = event.as<KeyEvent>();
Keyboard_Submit(ev.state() == KeyEvent::Pressed? IKE_DOWN : IKE_UP,
ev.ddKey(), ev.nativeCode(), ev.text().toLatin1());
}
return false;
}