Skip to content

Commit f35bccc

Browse files
committedJul 20, 2011
For commit ebc8976
the wrong stash was used. Reapplying missing part of patch. closes ticket:2824 Revert "Speed up text rendering for console messages by rendering to pixmaps instead of re-rendering the strings themselves for every display frame." This reverts commit aaedaab.
1 parent 2808328 commit f35bccc

File tree

6 files changed

+117
-59
lines changed

6 files changed

+117
-59
lines changed
 

‎lib/framework/wzapp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ void WzMainWindow::initializeGL()
220220
QtGameWidget::initializeGL();
221221
}
222222

223+
#if 0
224+
// Re-enable when Qt's font rendering is improved.
223225
void WzMainWindow::drawPixmap(int XPos, int YPos, QPixmap *pix)
224226
{
225227
QPainter painter(context()->device());
@@ -229,6 +231,7 @@ void WzMainWindow::drawPixmap(int XPos, int YPos, QPixmap *pix)
229231
rendStatesRendModeHack(); // rendStates.rendMode = REND_ALPHA;
230232
pie_SetRendMode(REND_OPAQUE); // beat state machinery into submission
231233
}
234+
#endif
232235

233236
void WzMainWindow::resizeGL(int width, int height)
234237
{

‎lib/framework/wzapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class WzMainWindow : public QtGameWidget
9090
void setFontSize(float size);
9191
int ticks() { return tickCount.elapsed(); }
9292
void setReadyToPaint() { notReadyToPaint = false; }
93+
#if 0
94+
// Re-enable when Qt's font rendering is improved.
9395
void drawPixmap(int XPos, int YPos, QPixmap *pix);
96+
#endif
9497

9598
public slots:
9699
void tick();

‎src/console.cpp

Lines changed: 109 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
Functions for the in-game console.
2323
*/
2424

25-
#include <QtCore/QString>
26-
#include <QtGui/QPixmap>
27-
#include <QtGui/QPainter>
28-
#include "lib/framework/wzapp.h"
29-
// **NOTE: Qt headers must be before platform specific headers!
30-
3125
#include "lib/framework/frame.h"
3226
#include "lib/framework/input.h"
3327
#include "lib/gamelib/gtime.h"
@@ -61,11 +55,11 @@ struct CONSOLE
6155
/* Definition of a message */
6256
struct CONSOLE_MESSAGE
6357
{
64-
QPixmap *cache; // Text of the message
65-
QString text; // Text of the message
58+
char text[MAX_CONSOLE_STRING_LENGTH]; // Text of the message
6659
UDWORD timeAdded; // When was it added to our list?
67-
int id;
68-
int player; // Player who sent this message or SYSTEM_MESSAGE
60+
UDWORD JustifyType;
61+
UDWORD id;
62+
SDWORD player; // Player who sent this message or SYSTEM_MESSAGE
6963
CONSOLE_MESSAGE * psNext;
7064
};
7165

@@ -122,12 +116,14 @@ static UDWORD consoleVisibleLines;
122116
/** Whether new messages are allowed to be added */
123117
static int allowNewMessages;
124118

119+
/** What's the default justification? */
120+
static CONSOLE_TEXT_JUSTIFICATION defJustification;
121+
125122
static UDWORD messageId; // unique ID
126123

127124
/// Global string for new console messages.
128125
char ConsoleString[MAX_CONSOLE_TMP_STRING_LENGTH];
129126

130-
static PIELIGHT getConsoleTextColor(SDWORD player);
131127

132128
/**
133129
Specify how long messages will stay on screen.
@@ -137,28 +133,12 @@ static void setConsoleMessageDuration(UDWORD time)
137133
messageDuration = time;
138134
}
139135

140-
void consoleInit()
141-
{
142-
int i;
143-
144-
for (i = 0; i < MAX_CONSOLE_MESSAGES; i++)
145-
{
146-
consoleStorage[i].cache = NULL;
147-
}
148-
}
149-
150136
/** Sets the system up */
151137
void initConsoleMessages( void )
152138
{
153-
int i, TextLineSize = iV_GetTextLineSize();
139+
int TextLineSize = iV_GetTextLineSize();
154140
messageIndex = 0;
155141

156-
for (i = 0; i < MAX_CONSOLE_MESSAGES; i++)
157-
{
158-
delete consoleStorage[i].cache;
159-
consoleStorage[i].cache = NULL;
160-
}
161-
162142
/* Console can extend to half screen height */
163143
if (TextLineSize)
164144
{
@@ -195,6 +175,9 @@ void initConsoleMessages( void )
195175
/* Turn on the console display */
196176
enableConsoleDisplay(true);
197177

178+
/* Set left justification as default */
179+
setDefaultConsoleJust(LEFT_JUSTIFY);
180+
198181
/* Set up the console size and postion
199182
x,y,width */
200183
setConsoleSizePos(16, 16, pie_GetVideoBufferWidth()-32);
@@ -232,6 +215,7 @@ void toggleConsoleDrop( void )
232215
bool addConsoleMessage(const char *messageText, CONSOLE_TEXT_JUSTIFICATION jusType,
233216
SDWORD player)
234217
{
218+
int textLength;
235219
CONSOLE_MESSAGE *psMessage;
236220

237221
/* Just don't add it if there's too many already */
@@ -246,34 +230,49 @@ bool addConsoleMessage(const char *messageText, CONSOLE_TEXT_JUSTIFICATION jusTy
246230
return false ;
247231
}
248232

233+
/* Is the string too long? */
234+
textLength = strlen(messageText);
235+
236+
ASSERT( textLength<MAX_CONSOLE_STRING_LENGTH,
237+
"Attempt to add a message to the console that exceeds MAX_CONSOLE_STRING_LENGTH" );
238+
239+
/* Are we using a defualt justification? */
240+
if(jusType == DEFAULT_JUSTIFY)
241+
{
242+
/* Then set it */
243+
jusType = defJustification;
244+
}
245+
249246
debug(LOG_CONSOLE, "(to player %d): %s", (int)player, messageText);
250247

251248
consoleStorage[messageIndex].player = player;
252249

253-
/* Draw the text of the message */
254-
PIELIGHT color(getConsoleTextColor(player));
255-
delete consoleStorage[messageIndex].cache;
256-
consoleStorage[messageIndex].cache = new QPixmap(mainConsole.width, iV_GetTextLineSize());
257-
consoleStorage[messageIndex].cache->fill(QColor(16, 16, 128, 128)); // FIXME, and fix pie_TransBoxFill, to not use hardcoded numbers
258-
consoleStorage[messageIndex].text = QString::fromUtf8(messageText);
259-
QPainter painter(consoleStorage[messageIndex].cache);
260-
painter.setPen(QColor(color.byte.r, color.byte.g, color.byte.b, color.byte.a));
261250
/* Precalculate and store (quicker!) the indent for justified text */
262-
QTextOption opts;
263251
switch(jusType)
264252
{
265-
case DEFAULT_JUSTIFY:
253+
/* Allign to left edge of screen */
266254
case LEFT_JUSTIFY:
267-
opts.setAlignment(Qt::AlignLeft);
255+
consoleStorage[messageIndex].JustifyType = FTEXT_LEFTJUSTIFY;
268256
break;
257+
258+
/* Allign to right edge of screen */
269259
case RIGHT_JUSTIFY:
270-
opts.setAlignment(Qt::AlignRight);
260+
consoleStorage[messageIndex].JustifyType = FTEXT_RIGHTJUSTIFY;
271261
break;
262+
263+
/* Allign to centre of the screen,NOT TO CENTRE OF CONSOLE!!!!!! */
272264
case CENTRE_JUSTIFY:
273-
opts.setAlignment(Qt::AlignHCenter);
265+
consoleStorage[messageIndex].JustifyType = FTEXT_CENTRE;
266+
break;
267+
/* Gone tits up by the looks of it */
268+
default:
269+
debug( LOG_FATAL, "Weirdy type of text justification for console print" );
270+
abort();
274271
break;
275272
}
276-
painter.drawText(QRect(0, 0, mainConsole.width, iV_GetTextLineSize()), consoleStorage[messageIndex].text, opts);
273+
274+
/* Copy over the text of the message */
275+
sstrcpy(consoleStorage[messageIndex].text, messageText);
277276

278277
/* Set the time when it was added - this might not be needed */
279278
consoleStorage[messageIndex].timeAdded = gameTime2;
@@ -417,35 +416,35 @@ void flushConsoleMessages( void )
417416
}
418417

419418
/** Sets console text color depending on message type */
420-
static PIELIGHT getConsoleTextColor(SDWORD player)
419+
static void setConsoleTextColor(SDWORD player)
421420
{
422421
// System messages
423-
if (player == SYSTEM_MESSAGE)
422+
if(player == SYSTEM_MESSAGE)
424423
{
425-
return WZCOL_CONS_TEXT_SYSTEM;
424+
iV_SetTextColour(WZCOL_CONS_TEXT_SYSTEM);
426425
}
427426
else if (player == NOTIFY_MESSAGE)
428427
{
429-
return WZCOL_YELLOW;
428+
iV_SetTextColour(WZCOL_YELLOW);
430429
}
431430
else
432431
{
433432
// Don't use friend-foe colors in the lobby
434-
if (bEnemyAllyRadarColor && (GetGameMode() == GS_NORMAL))
433+
if(bEnemyAllyRadarColor && (GetGameMode() == GS_NORMAL))
435434
{
436-
if (aiCheckAlliances(player,selectedPlayer))
435+
if(aiCheckAlliances(player,selectedPlayer))
437436
{
438-
return WZCOL_CONS_TEXT_USER_ALLY;
437+
iV_SetTextColour(WZCOL_CONS_TEXT_USER_ALLY);
439438
}
440439
else
441440
{
442-
return WZCOL_CONS_TEXT_USER_ENEMY;
441+
iV_SetTextColour(WZCOL_CONS_TEXT_USER_ENEMY);
443442
}
444443
}
445444
else
446445
{
447446
// Friend-foe is off
448-
return WZCOL_CONS_TEXT_USER;
447+
iV_SetTextColour(WZCOL_CONS_TEXT_USER);
449448
}
450449
}
451450
}
@@ -515,18 +514,47 @@ static int displayOldMessages(void)
515514
{
516515
/* Get the line pitch */
517516
linePitch = iV_GetTextLineSize();
517+
518+
/* How big a box is necessary? */
519+
/* GET RID OF THE MAGIC NUMBERS BELOW */
520+
iV_TransBoxFill(mainConsole.topX - CON_BORDER_WIDTH,mainConsole.topY-mainConsole.textDepth-CON_BORDER_HEIGHT,
521+
mainConsole.topX+mainConsole.width ,mainConsole.topY+((count)*linePitch)+CON_BORDER_HEIGHT-linePitch);
522+
}
523+
/*
524+
if(count)
525+
{
526+
sprintf(buildData,"%s,%s",__TIME__,__DATE__);
527+
528+
buildWidth = iV_GetTextWidth(buildData);
529+
530+
iV_DrawText(buildData,((mainConsole.topX+mainConsole.width) - buildWidth - 16),
531+
mainConsole.topY);
518532
}
533+
*/
519534
MesY = mainConsole.topY;
520535
/* Render what we found */
521536
for(i=count-1; i>0; i--)
522537
{
538+
/* Set text color depending on message type */
539+
setConsoleTextColor(consoleStorage[history[i]].player);
540+
523541
/* Draw the text string */
524-
WzMainWindow::instance()->drawPixmap(mainConsole.topX, MesY, consoleStorage[history[i]].cache);
525-
MesY += iV_GetTextLineSize();
542+
MesY = iV_DrawFormattedText(consoleStorage[history[i]].text,
543+
mainConsole.topX,
544+
MesY,
545+
mainConsole.width,
546+
consoleStorage[history[i]].JustifyType);
526547
}
527548

549+
/* Set text color depending on message type */
550+
setConsoleTextColor(consoleStorage[history[0]].player);
551+
528552
/* Draw the top one */
529-
WzMainWindow::instance()->drawPixmap(mainConsole.topX, MesY, consoleStorage[history[0]].cache);
553+
iV_DrawFormattedText(consoleStorage[history[0]].text,
554+
mainConsole.topX,
555+
MesY,
556+
mainConsole.width,
557+
consoleStorage[history[0]].JustifyType);
530558

531559
/* Return how much to drop the existing console by... Fix this for lines>screenWIDTH */
532560
if(count)
@@ -587,7 +615,7 @@ void displayConsoleMessages( void )
587615
psMessage && consoleVisibleLines > 0 && exceed < 4; // ho ho ho!!!
588616
psMessage = psMessage->psNext)
589617
{
590-
if (iV_GetTextWidth(psMessage->text.toAscii().constData()) > mainConsole.width)
618+
if (iV_GetTextWidth(psMessage->text) > mainConsole.width)
591619
{
592620
++exceed;
593621
}
@@ -605,6 +633,9 @@ void displayConsoleMessages( void )
605633
{
606634
clipDepth = (pie_GetVideoBufferHeight() - linePitch);
607635
}
636+
637+
iV_TransBoxFill(mainConsole.topX - CON_BORDER_WIDTH,mainConsole.topY-mainConsole.textDepth-CON_BORDER_HEIGHT+drop+1,
638+
mainConsole.topX+mainConsole.width ,clipDepth);
608639
}
609640

610641
/* Stop when we've drawn enough or we're at the end */
@@ -614,9 +645,13 @@ void displayConsoleMessages( void )
614645
psMessage && numProcessed < consoleVisibleLines && MesY < pie_GetVideoBufferHeight() - linePitch;
615646
psMessage = psMessage->psNext)
616647
{
648+
649+
/* Set text color depending on message type */
650+
setConsoleTextColor(psMessage->player);
651+
617652
/* Draw the text string */
618-
WzMainWindow::instance()->drawPixmap(mainConsole.topX, MesY, psMessage->cache);
619-
MesY += iV_GetTextLineSize();
653+
MesY = iV_DrawFormattedText(psMessage->text, mainConsole.topX, MesY,
654+
mainConsole.width, psMessage->JustifyType);
620655

621656
/* Move on */
622657
++numProcessed;
@@ -640,6 +675,23 @@ void enableConsoleDisplay(bool state)
640675
bConsoleDisplayEnabled = state;
641676
}
642677

678+
/** Sets the default justification for text */
679+
void setDefaultConsoleJust(CONSOLE_TEXT_JUSTIFICATION defJ)
680+
{
681+
switch(defJ)
682+
{
683+
case LEFT_JUSTIFY:
684+
case RIGHT_JUSTIFY:
685+
case CENTRE_JUSTIFY:
686+
defJustification = defJ;
687+
break;
688+
default:
689+
debug( LOG_FATAL, "Weird default text justification for console" );
690+
abort();
691+
break;
692+
}
693+
}
694+
643695
/** Allows positioning of the console on screen */
644696
void setConsoleSizePos(UDWORD x, UDWORD y, UDWORD width)
645697
{

‎src/console.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ enum CONSOLE_TEXT_JUSTIFICATION
3939

4040
extern char ConsoleString[MAX_CONSOLE_TMP_STRING_LENGTH];
4141

42-
void consoleInit(void);
4342
bool addConsoleMessage(const char *messageText, CONSOLE_TEXT_JUSTIFICATION jusType, SDWORD player);
4443
void updateConsoleMessages(void);
4544
void initConsoleMessages(void);
@@ -49,6 +48,7 @@ void flushConsoleMessages(void);
4948
void setConsoleBackdropStatus(bool state);
5049
void enableConsoleDisplay(bool state);
5150
bool getConsoleDisplayStatus(void);
51+
void setDefaultConsoleJust(CONSOLE_TEXT_JUSTIFICATION defJ);
5252
void setConsoleSizePos(UDWORD x, UDWORD y, UDWORD width);
5353
void setConsolePermanence(bool state, bool bClearOld);
5454
bool mouseOverConsoleBox(void);

‎src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ bool systemInitialise(void)
466466
{
467467
return false;
468468
}
469-
consoleInit();
470469

471470
buildMapList();
472471

‎src/multiint.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,7 @@ static void addChatBox(void)
25892589
initConsoleMessages();
25902590
enableConsoleDisplay(true);
25912591
setConsoleBackdropStatus(false);
2592+
setDefaultConsoleJust(LEFT_JUSTIFY);
25922593
setConsoleSizePos(MULTIOP_CHATBOXX+4+D_W, MULTIOP_CHATBOXY+14+D_H, MULTIOP_CHATBOXW-4);
25932594
setConsolePermanence(true,true);
25942595
setConsoleLineInfo(5); // use x lines on chat window

0 commit comments

Comments
 (0)