/
con_busy.c
799 lines (667 loc) · 22.2 KB
/
con_busy.c
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/**\file con_busy.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2007-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2007-2011 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2007 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* Console Busy Mode
*
* Draws the screen while the main engine thread is working a long
* operation. The busy mode can be configured to be displaying a progress
* bar, the console output, or a more generic "please wait" message.
*/
// HEADER FILES ------------------------------------------------------------
#include <math.h>
#include "de_base.h"
#include "de_console.h"
#include "de_system.h"
#include "de_graphics.h"
#include "de_render.h"
#include "de_refresh.h"
#include "de_ui.h"
#include "de_misc.h"
#include "de_network.h"
#include "image.h"
#include "texturecontent.h"
// MACROS ------------------------------------------------------------------
#define SCREENSHOT_TEXTURE_SIZE 512
#define DOOMWIPESINE_NUMSAMPLES 320
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void Con_BusyLoop(void);
static void Con_BusyDrawer(void);
static void Con_BusyLoadTextures(void);
static void Con_BusyDeleteTextures(void);
static void seedDoomWipeSine(void);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
int rTransition = (int) TS_CROSSFADE;
int rTransitionTics = 28;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static boolean busyInited;
static int busyMode;
static char* busyTaskName;
static thread_t busyThread;
static timespan_t busyTime;
static volatile boolean busyDone;
static volatile boolean busyDoneCopy;
static volatile const char* busyError = NULL;
static fontnum_t busyFont = 0;
static int busyFontHgt; // Height of the font.
static mutex_t busy_Mutex; // To prevent Data races in the busy thread.
static DGLuint texLoading[2];
static DGLuint texScreenshot; // Captured screenshot of the latest frame.
static boolean transitionInProgress = false;
static transitionstyle_t transitionStyle = 0;
static uint transitionStartTime = 0;
static float transitionPosition;
static float doomWipeSine[DOOMWIPESINE_NUMSAMPLES];
// CODE --------------------------------------------------------------------
/**
* Busy mode.
*
* @param flags Busy mode flags (see BUSYF_PROGRESS_BAR and others).
* @param taskName Optional task name (drawn with the progress bar).
* @param worker Worker thread that does processing while in busy mode.
* @param workerData Data context for the worker thread.
*
* @return Return value of the worker.
*/
int Con_Busy(int flags, const char* taskName, busyworkerfunc_t worker,
void* workerData)
{
int result = 0;
if(!busyInited)
{
busy_Mutex = Sys_CreateMutex("BUSY_MUTEX");
}
if(busyInited)
{
Con_Error("Con_Busy: Already busy.\n");
}
busyMode = flags;
Sys_Lock(busy_Mutex);
busyDone = false;
if(taskName && taskName[0])
{ // Take a copy of the task name.
size_t len = strlen(taskName);
busyTaskName = M_Calloc(len + 1);
dd_snprintf(busyTaskName, len+1, "%s", taskName);
}
Sys_Unlock(busy_Mutex);
// Load any textures needed in this mode.
Con_BusyLoadTextures();
// Activate the UI binding context so that any and all accumulated input
// events are discarded when done.
DD_ClearKeyRepeaters();
B_ActivateContext(B_ContextByName(UI_BINDING_CONTEXT_NAME), true);
busyInited = true;
// Start the busy worker thread, which will proces things in the
// background while we keep the user occupied with nice animations.
busyThread = Sys_StartThread(worker, workerData);
// Are we doing a transition effect?
if(!isDedicated && !netGame && !(busyMode & BUSYF_STARTUP) &&
rTransitionTics > 0 && (busyMode & BUSYF_TRANSITION))
{
transitionStyle = rTransition;
if(transitionStyle == TS_DOOM || transitionStyle == TS_DOOMSMOOTH)
seedDoomWipeSine();
transitionInProgress = true;
}
// Wait for the busy thread to stop.
Con_BusyLoop();
if(!transitionInProgress)
{
// Clear any input events that might have accumulated whilst busy.
DD_ClearEvents();
B_ActivateContext(B_ContextByName(UI_BINDING_CONTEXT_NAME), false);
}
else
{
transitionStartTime = Sys_GetTime();
transitionPosition = 0;
}
// Free resources.
Con_BusyDeleteTextures();
if(busyTaskName)
M_Free(busyTaskName);
busyTaskName = NULL;
if(busyError)
{
Con_AbnormalShutdown((const char*) busyError);
}
// Make sure the worker finishes before we continue.
result = Sys_WaitThread(busyThread);
busyThread = NULL;
busyInited = false;
// Make sure that any remaining deferred content gets uploaded.
if(!(isDedicated || (busyMode & BUSYF_NO_UPLOADS)))
{
GL_ProcessDeferredTasks(0);
}
return result;
}
/**
* Called by the busy worker to shutdown the engine immediately.
*
* @param message Message, expected to exist until the engine closes.
*/
void Con_BusyWorkerError(const char* message)
{
busyError = message;
Con_BusyWorkerEnd();
}
/**
* Called by the busy worker thread when it has finished processing,
* to end busy mode.
*/
void Con_BusyWorkerEnd(void)
{
if(!busyInited)
return;
Sys_Lock(busy_Mutex);
busyDone = true;
Sys_Unlock(busy_Mutex);
}
boolean Con_IsBusy(void)
{
return busyInited;
}
static void Con_BusyLoadTextures(void)
{
image_t image;
if(isDedicated || novideo)
return;
if(!(busyMode & BUSYF_STARTUP))
{
// Not in startup, so take a copy of the current frame contents.
Con_AcquireScreenshotTexture();
}
// Need to load the progress indicator?
if(busyMode & (BUSYF_ACTIVITY | BUSYF_PROGRESS_BAR))
{
// These must be real files in the base dir because virtual files haven't
// been loaded yet when engine startup is done.
if(GL_LoadImage(&image, "}data/graphics/loading1.png"))
{
texLoading[0] = GL_NewTextureWithParams(DGL_RGBA, image.width, image.height,
image.pixels, TXCF_NEVER_DEFER);
GL_DestroyImagePixels(&image);
}
if(GL_LoadImage(&image, "}data/graphics/loading2.png"))
{
texLoading[1] = GL_NewTextureWithParams(DGL_RGBA, image.width, image.height,
image.pixels, TXCF_NEVER_DEFER);
GL_DestroyImagePixels(&image);
}
}
// Need to load any fonts for log messages etc?
if((busyMode & BUSYF_CONSOLE_OUTPUT) || busyTaskName)
{
// These must be real files in the base dir because virtual files haven't
// been loaded yet when the engine startup is done.
struct busyFont {
const char* name;
const char* path;
} static const fonts[] = {
{ FN_SYSTEM_NAME":normal12", "}data/fonts/normal12.dfn" },
{ FN_SYSTEM_NAME":normal18", "}data/fonts/normal18.dfn" }
};
int fontIdx = !(theWindow->width > 640)? 0 : 1;
font_t* font = Fonts_LoadExternal(fonts[fontIdx].name, fonts[fontIdx].path);
if(NULL != font)
{
busyFont = Fonts_ToIndex(font);
FR_SetFont(busyFont);
FR_LoadDefaultAttrib();
busyFontHgt = FR_SingleLineHeight("Busy");
}
}
}
static void Con_BusyDeleteTextures(void)
{
if(isDedicated)
return;
glDeleteTextures(2, (const GLuint*) texLoading);
texLoading[0] = texLoading[1] = 0;
// Don't release this yet if doing a transition.
if(!transitionInProgress)
Con_ReleaseScreenshotTexture();
busyFont = 0;
}
/**
* Take a screenshot and store it as a texture.
*/
void Con_AcquireScreenshotTexture(void)
{
int oldMaxTexSize = GL_state.maxTexSize;
uint8_t* frame;
#ifdef _DEBUG
timespan_t startTime;
#endif
if(texScreenshot)
{
Con_ReleaseScreenshotTexture();
}
#ifdef _DEBUG
startTime = Sys_GetRealSeconds();
#endif
frame = malloc(theWindow->width * theWindow->height * 3);
GL_Grab(0, 0, theWindow->width, theWindow->height, DGL_RGB, frame);
GL_state.maxTexSize = SCREENSHOT_TEXTURE_SIZE; // A bit of a hack, but don't use too large a texture.
texScreenshot = GL_UploadTextureWithParams(frame, theWindow->width, theWindow->height,
DGL_RGB, false, false, true, GL_LINEAR, GL_LINEAR, 0 /*no anisotropy*/,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, TXCF_NEVER_DEFER|TXCF_NO_COMPRESSION);
GL_state.maxTexSize = oldMaxTexSize;
free(frame);
#ifdef _DEBUG
printf("Con_AcquireScreenshotTexture: Took %.2f seconds.\n",
Sys_GetRealSeconds() - startTime);
#endif
}
void Con_ReleaseScreenshotTexture(void)
{
glDeleteTextures(1, (const GLuint*) &texScreenshot);
texScreenshot = 0;
}
/**
* The busy thread main function. Runs until busyDone set to true.
*/
static void Con_BusyLoop(void)
{
boolean canDraw = !(isDedicated || novideo);
boolean canUpload = (canDraw && !(busyMode & BUSYF_NO_UPLOADS));
timespan_t startTime = Sys_GetRealSeconds();
if(canDraw)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, theWindow->width, theWindow->height, 0, -1, 1);
}
Sys_Lock(busy_Mutex);
busyDoneCopy = busyDone;
Sys_Unlock(busy_Mutex);
while(!busyDoneCopy || (canUpload && GL_DeferredTaskCount() > 0))
{
Sys_Lock(busy_Mutex);
busyDoneCopy = busyDone;
Sys_Unlock(busy_Mutex);
Sys_Sleep(20);
if(canUpload)
{ // Make sure that any deferred content gets uploaded.
GL_ProcessDeferredTasks(15);
}
// Update the time.
busyTime = Sys_GetRealSeconds() - startTime;
// Time for an update?
if(canDraw)
Con_BusyDrawer();
}
if(verbose)
{
Con_Message("Con_Busy: Was busy for %.2lf seconds.\n", busyTime);
}
if(canDraw)
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
}
/**
* Draws the captured screenshot as a background, or just clears the screen if no
* screenshot is available.
*/
static void Con_DrawScreenshotBackground(float x, float y, float width, float height)
{
if(texScreenshot)
{
glBindTexture(GL_TEXTURE_2D, texScreenshot);
glEnable(GL_TEXTURE_2D);
glColor3ub(255, 255, 255);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(x, y);
glTexCoord2f(1, 1);
glVertex2f(x + width, y);
glTexCoord2f(1, 0);
glVertex2f(x + width, y + height);
glTexCoord2f(0, 0);
glVertex2f(x, y + height);
glEnd();
glDisable(GL_TEXTURE_2D);
}
else
{
glClear(GL_COLOR_BUFFER_BIT);
}
}
/**
* @param 0...1, to indicate how far things have progressed.
*/
static void Con_BusyDrawIndicator(float x, float y, float radius, float pos)
{
float col[4] = {1.f, 1.f, 1.f, .2f};
int i = 0;
int edgeCount = 0;
int backW, backH;
backW = backH = (radius * 2);
pos = MINMAX_OF(0, pos, 1);
edgeCount = MAX_OF(1, pos * 30);
// Draw a background.
glEnable(GL_BLEND);
GL_BlendMode(BM_NORMAL);
glBegin(GL_TRIANGLE_FAN);
glColor4ub(0, 0, 0, 140);
glVertex2f(x, y);
glColor4ub(0, 0, 0, 0);
glVertex2f(x, y - backH);
glVertex2f(x + backW*.8f, y - backH*.8f);
glVertex2f(x + backW, y);
glVertex2f(x + backW*.8f, y + backH*.8f);
glVertex2f(x, y + backH);
glVertex2f(x - backW*.8f, y + backH*.8f);
glVertex2f(x - backW, y);
glVertex2f(x - backW*.8f, y - backH*.8f);
glVertex2f(x, y - backH);
glEnd();
// Draw the frame.
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texLoading[0]);
glColor4fv(col);
GL_DrawRect(x - radius, y - radius, radius*2, radius*2);
// Rotate around center.
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(.5f, .5f, 0.f);
glRotatef(-busyTime * 20, 0.f, 0.f, 1.f);
glTranslatef(-.5f, -.5f, 0.f);
// Draw a fan.
glColor4f(col[0], col[1], col[2], .66f);
glBindTexture(GL_TEXTURE_2D, texLoading[1]);
glBegin(GL_TRIANGLE_FAN);
// Center.
glTexCoord2f(.5f, .5f);
glVertex2f(x, y);
// Vertices along the edge.
for(i = 0; i <= edgeCount; ++i)
{
float angle = 2 * PI * pos *
(i / (float)edgeCount) + PI/2;
glTexCoord2f(.5f + cos(angle)*.5f, .5f + sin(angle)*.5f);
glVertex2f(x + cos(angle)*radius*1.105f, y + sin(angle)*radius*1.105f);
}
glEnd();
glMatrixMode(GL_TEXTURE);
glPopMatrix();
// Draw the task name.
if(busyTaskName)
{
FR_SetFont(busyFont);
FR_LoadDefaultAttrib();
FR_SetColorAndAlpha(1.f, 1.f, 1.f, .66f);
FR_DrawText3(busyTaskName, x+radius, y, ALIGN_LEFT, DTF_ONLY_SHADOW);
}
glDisable(GL_TEXTURE_2D);
}
#define LINE_COUNT 4
/**
* @return Number of new lines since the old ones.
*/
static int GetBufLines(cbuffer_t* buffer, cbline_t const **oldLines)
{
cbline_t const* bufLines[LINE_COUNT + 1];
int count;
int newCount = 0;
int i, k;
count = Con_BufferGetLines2(buffer, LINE_COUNT, -LINE_COUNT, bufLines, BLF_OMIT_RULER|BLF_OMIT_EMPTYLINE);
for(i = 0; i < count; ++i)
{
for(k = 0; k < 2 * LINE_COUNT - newCount; ++k)
{
if(oldLines[k] == bufLines[i])
{
goto lineIsNotNew;
}
}
newCount++;
for(k = 0; k < (2 * LINE_COUNT - 1); ++k)
oldLines[k] = oldLines[k+1];
//memmove(oldLines, oldLines + 1, sizeof(cbline_t*) * (2 * LINE_COUNT - 1));
oldLines[2 * LINE_COUNT - 1] = bufLines[i];
lineIsNotNew:;
}
return newCount;
}
/**
* Draws a number of console output to the bottom of the screen.
* \fixme: Wow. I had some weird time hacking the smooth scrolling. Cleanup would be
* good some day. -jk
*/
void Con_BusyDrawConsoleOutput(void)
{
cbuffer_t* buffer;
static cbline_t const* visibleBusyLines[2 * LINE_COUNT];
static float scroll = 0;
static float scrollStartTime = 0;
static float scrollEndTime = 0;
static double lastNewTime = 0;
static double timeSinceLastNew = 0;
double nowTime = 0;
float y, topY;
uint i, newCount;
buffer = Con_HistoryBuffer();
newCount = GetBufLines(buffer, visibleBusyLines);
nowTime = Sys_GetRealSeconds();
if(newCount > 0)
{
timeSinceLastNew = nowTime - lastNewTime;
lastNewTime = nowTime;
if(nowTime < scrollEndTime)
{
// Abort last scroll.
scroll = 0;
scrollStartTime = nowTime;
scrollEndTime = nowTime;
}
else
{
double interval =
MIN_OF(timeSinceLastNew/2, 1.3);
// Begin new scroll.
scroll = newCount;
scrollStartTime = nowTime;
scrollEndTime = nowTime + interval;
}
}
glEnable(GL_BLEND);
GL_BlendMode(BM_NORMAL);
// Dark gradient as background.
glBegin(GL_QUADS);
glColor4ub(0, 0, 0, 0);
y = theWindow->height - (LINE_COUNT + 3) * busyFontHgt;
glVertex2f(0, y);
glVertex2f(theWindow->width, y);
glColor4ub(0, 0, 0, 128);
glVertex2f(theWindow->width, theWindow->height);
glVertex2f(0, theWindow->height);
glEnd();
glEnable(GL_TEXTURE_2D);
// The text lines.
topY = y = theWindow->height - busyFontHgt * (2 * LINE_COUNT + .5f);
if(newCount > 0 ||
(nowTime >= scrollStartTime && nowTime < scrollEndTime && scrollEndTime > scrollStartTime))
{
if(scrollEndTime - scrollStartTime > 0)
y += scroll * (scrollEndTime - nowTime) / (scrollEndTime - scrollStartTime) *
busyFontHgt;
}
FR_SetFont(busyFont);
FR_LoadDefaultAttrib();
FR_SetColor(1.f, 1.f, 1.f);
for(i = 0; i < 2 * LINE_COUNT; ++i, y += busyFontHgt)
{
const cbline_t* line = visibleBusyLines[i];
float alpha = 1;
if(!line)
continue;
alpha = ((y - topY) / busyFontHgt) - (LINE_COUNT - 1);
if(alpha < LINE_COUNT)
alpha = MINMAX_OF(0, alpha/2, 1);
else
alpha = 1 - (alpha - LINE_COUNT);
FR_SetAlpha(alpha);
FR_DrawText3(line->text, theWindow->width/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
}
glDisable(GL_TEXTURE_2D);
#undef LINE_COUNT
}
/**
* Busy drawer function. The entire frame is drawn here.
*/
static void Con_BusyDrawer(void)
{
float pos = 0;
Con_DrawScreenshotBackground(0, 0, theWindow->width, theWindow->height);
// Indefinite activity?
if((busyMode & BUSYF_ACTIVITY) || (busyMode & BUSYF_PROGRESS_BAR))
{
if(busyMode & BUSYF_ACTIVITY)
pos = 1;
else // The progress is animated elsewhere.
pos = Con_GetProgress();
Con_BusyDrawIndicator(theWindow->width/2, theWindow->height/2, theWindow->height/12, pos);
}
// Output from the console?
if(busyMode & BUSYF_CONSOLE_OUTPUT)
{
Con_BusyDrawConsoleOutput();
}
Sys_UpdateWindow(windowIDX);
}
boolean Con_TransitionInProgress(void)
{
return transitionInProgress;
}
void Con_TransitionTicker(timespan_t ticLength)
{
if(isDedicated)
return;
if(!Con_TransitionInProgress())
return;
transitionPosition = (float)(Sys_GetTime() - transitionStartTime) / rTransitionTics;
if(transitionPosition >= 1)
{
// Clear any input events that might have accumulated during the transition.
DD_ClearEvents();
B_ActivateContext(B_ContextByName(UI_BINDING_CONTEXT_NAME), false);
Con_ReleaseScreenshotTexture();
transitionInProgress = false;
}
}
static void seedDoomWipeSine(void)
{
int i;
doomWipeSine[0] = (128 - RNG_RandByte()) / 128.f;
for(i = 1; i < DOOMWIPESINE_NUMSAMPLES; ++i)
{
float r = (128 - RNG_RandByte()) / 512.f;
doomWipeSine[i] = MINMAX_OF(-1, doomWipeSine[i-1] + r, 1);
}
}
static float sampleDoomWipeSine(float point)
{
float sample = doomWipeSine[(uint)ROUND((DOOMWIPESINE_NUMSAMPLES-1) * MINMAX_OF(0, point, 1))];
float offset = SCREENHEIGHT * transitionPosition * transitionPosition;
return offset + (SCREENHEIGHT/2) * (transitionPosition + sample) * transitionPosition * transitionPosition;
}
void Con_DrawTransition(void)
{
if(isDedicated)
return;
if(!Con_TransitionInProgress())
return;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, SCREENWIDTH, SCREENHEIGHT, 0, -1, 1);
glBindTexture(GL_TEXTURE_2D, texScreenshot);
glEnable(GL_TEXTURE_2D);
switch(transitionStyle)
{
case TS_DOOMSMOOTH:
{
float colWidth = .5f / SCREENSHOT_TEXTURE_SIZE;
int i;
glColor3f(1, 1, 1);
glBegin(GL_QUAD_STRIP);
glTexCoord2f(0, 1); glVertex2f(0, MAX_OF(0, sampleDoomWipeSine(0)));
glTexCoord2f(0, 0); glVertex2f(0, MAX_OF(0, sampleDoomWipeSine(0))+SCREENHEIGHT);
for(i = 1; i <= SCREENWIDTH; ++i)
{
float s = (float) i / SCREENWIDTH - colWidth;
float x = i - .5f;
float y = MAX_OF(0, sampleDoomWipeSine((float) i / SCREENWIDTH));
glTexCoord2f(s, 1); glVertex2f(x, y);
glTexCoord2f(s, 0); glVertex2f(x, y+SCREENHEIGHT);
}
glTexCoord2f(1, 1); glVertex2f(SCREENWIDTH, MAX_OF(0, sampleDoomWipeSine(1)));
glTexCoord2f(1, 0); glVertex2f(SCREENWIDTH, MAX_OF(0, sampleDoomWipeSine(1))+SCREENHEIGHT);
glEnd();
break;
}
case TS_DOOM:
{ // As above but drawn with whole pixel columns.
float colWidth = 1.0f / SCREENSHOT_TEXTURE_SIZE;
int i;
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
for(i = 0; i <= SCREENWIDTH; ++i)
{
float s = (float) i / SCREENWIDTH;
float x = i;
float y = MAX_OF(0, sampleDoomWipeSine((float) i / SCREENWIDTH));
glTexCoord2f(s, 1); glVertex2f(x, y);
glTexCoord2f(s+colWidth, 1); glVertex2f(x+1, y);
glTexCoord2f(s+colWidth, 0); glVertex2f(x+1, y+SCREENHEIGHT);
glTexCoord2f(s, 0); glVertex2f(x, y+SCREENHEIGHT);
}
glEnd();
break;
}
case TS_CROSSFADE:
glColor4f(1, 1, 1, 1 - transitionPosition);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex2f(0, 0);
glTexCoord2f(0, 0); glVertex2f(0, SCREENHEIGHT);
glTexCoord2f(1, 0); glVertex2f(SCREENWIDTH, SCREENHEIGHT);
glTexCoord2f(1, 1); glVertex2f(SCREENWIDTH, 0);
glEnd();
break;
}
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}