LAB: Fix a regression related to random number generation, some renaming

This commit is contained in:
Strangerke 2015-12-14 12:40:19 +01:00 committed by Willem Jan Palenstijn
parent cbf4c876e5
commit 21e6f40301
7 changed files with 75 additions and 69 deletions

View file

@ -48,7 +48,7 @@ DisplayMan::DisplayMan(LabEngine *vm) : _vm(vm) {
_doNotDrawMessage = false;
_screenBytesPerPage = 65536;
_curapen = 0;
_curPen = 0;
_curBitmap = nullptr;
_displayBuffer = nullptr;
_currentDisplayBuffer = nullptr;
@ -179,7 +179,7 @@ void DisplayMan::getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer
* each line less than 255 characters.
*/
uint32 DisplayMan::flowText(
void *font, // the TextAttr pointer
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@ -200,7 +200,7 @@ uint32 DisplayMan::flowText(
setAPen(pencolor);
TextFont *msgFont = (TextFont *)font;
TextFont *msgFont = font;
uint16 fontheight = textHeight(msgFont) + spacing;
uint16 numlines = (y2 - y1 + 1) / fontheight;
uint16 width = x2 - x1 + 1;
@ -242,7 +242,7 @@ uint32 DisplayMan::flowText(
}
uint32 DisplayMan::flowTextScaled(
void *font, // the TextAttr pointer
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte penColor, // pen number to use for text
byte backPen, // the background color
@ -262,7 +262,7 @@ uint32 DisplayMan::flowTextScaled(
* Calls flowText, but flows it to memory. Same restrictions as flowText.
*/
uint32 DisplayMan::flowTextToMem(Image *destIm,
void *font, // the TextAttr pointer
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@ -470,8 +470,8 @@ void DisplayMan::setUpScreens() {
/**
* Sets the pen number to use on all the drawing operations.
*/
void DisplayMan::setAPen(byte pennum) {
_curapen = pennum;
void DisplayMan::setAPen(byte penNum) {
_curPen = penNum;
}
/**
@ -495,7 +495,7 @@ void DisplayMan::rectFill(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int ww = w;
while (ww-- > 0) {
*dd++ = _curapen;
*dd++ = _curPen;
}
d += _screenWidth;
@ -567,7 +567,7 @@ void DisplayMan::setAmigaPal(uint16 *pal, uint16 numColors) {
/**
* Writes any number of the 256 color registers.
* first: the number of the first color register to write.
* numreg: the number of registers to write
* numReg: the number of registers to write
* buf: a char pointer which contains the selected color registers.
* Each value representing a color register occupies 3 bytes in
* the array. The order is red, green then blue. The first byte
@ -575,21 +575,19 @@ void DisplayMan::setAmigaPal(uint16 *pal, uint16 numColors) {
* The length of the buffer is 3 times the number of registers
* selected.
*/
void DisplayMan::writeColorRegs(byte *buf, uint16 first, uint16 numreg) {
void DisplayMan::writeColorRegs(byte *buf, uint16 first, uint16 numReg) {
byte tmp[256 * 3];
for (int i = 0; i < 256 * 3; i++) {
for (int i = 0; i < 256 * 3; i++)
tmp[i] = buf[i] * 4;
}
g_system->getPaletteManager()->setPalette(tmp, first, numreg);
memcpy(&(_curvgapal[first * 3]), buf, numreg * 3);
g_system->getPaletteManager()->setPalette(tmp, first, numReg);
memcpy(&(_curvgapal[first * 3]), buf, numReg * 3);
}
void DisplayMan::setPalette(void *cmap, uint16 numcolors) {
if (memcmp(cmap, _curvgapal, numcolors * 3) != 0)
writeColorRegs((byte *)cmap, 0, numcolors);
void DisplayMan::setPalette(void *cmap, uint16 numColors) {
if (memcmp(cmap, _curvgapal, numColors * 3) != 0)
writeColorRegs((byte *)cmap, 0, numColors);
}
/**
@ -605,7 +603,7 @@ byte *DisplayMan::getCurrentDrawingBuffer() {
/**
* Overlays a region on the screen using the desired pen color.
*/
void DisplayMan::overlayRect(uint16 pencolor, uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
void DisplayMan::overlayRect(uint16 penColor, uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int w = x2 - x1 + 1;
int h = y2 - y1 + 1;
@ -628,7 +626,7 @@ void DisplayMan::overlayRect(uint16 pencolor, uint16 x1, uint16 y1, uint16 x2, u
}
while (ww > 0) {
*dd = pencolor;
*dd = penColor;
dd += 2;
ww -= 2;
}
@ -642,24 +640,24 @@ void DisplayMan::overlayRect(uint16 pencolor, uint16 x1, uint16 y1, uint16 x2, u
/**
* Closes a font and frees all memory associated with it.
*/
void DisplayMan::closeFont(TextFont *tf) {
if (tf) {
if (tf->_data && tf->_dataLength)
delete[] tf->_data;
void DisplayMan::closeFont(TextFont *font) {
if (font) {
if (font->_data && font->_dataLength)
delete[] font->_data;
delete tf;
delete font;
}
}
/**
* Returns the length of a text in the specified font.
*/
uint16 DisplayMan::textLength(TextFont *tf, const char *text, uint16 numchars) {
uint16 DisplayMan::textLength(TextFont *font, const char *text, uint16 numChars) {
uint16 length = 0;
if (tf) {
for (uint16 i = 0; i < numchars; i++) {
length += tf->_widths[(uint)*text];
if (font) {
for (uint16 i = 0; i < numChars; i++) {
length += font->_widths[(uint)*text];
text++;
}
}

View file

@ -64,7 +64,7 @@ private:
uint16 fadeNumOut(uint16 num, uint16 res, uint16 counter);
void getWord(char *wordBuffer, const char *mainBuffer, uint16 *wordWidth);
byte _curapen;
byte _curPen;
byte *_curBitmap;
byte _curvgapal[256 * 3];
@ -94,7 +94,7 @@ public:
void rectFill(uint16 x1, uint16 y1, uint16 x2, uint16 y2);
void rectFillScaled(uint16 x1, uint16 y1, uint16 x2, uint16 y2);
// Window text stuff
uint32 flowText(void *font, // the TextAttr pointer
uint32 flowText(TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@ -107,7 +107,7 @@ public:
const char *text); // The text itself
uint32 flowTextScaled(
void *font, // the TextAttr pointer
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@ -120,7 +120,7 @@ public:
const char *text); // The text itself
uint32 flowTextToMem(Image *destIm,
void *font, // the TextAttr pointer
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@ -135,17 +135,17 @@ public:
void drawHLine(uint16 x, uint16 y1, uint16 y2);
void drawVLine(uint16 x1, uint16 y, uint16 x2);
void screenUpdate();
void createScreen(bool HiRes);
void createScreen(bool hiRes);
void setAmigaPal(uint16 *pal, uint16 numColors);
void writeColorRegs(byte *buf, uint16 first, uint16 numreg);
void setPalette(void *cmap, uint16 numcolors);
void overlayRect(uint16 pencolor, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
void writeColorRegs(byte *buf, uint16 first, uint16 numReg);
void setPalette(void *cmap, uint16 numColors);
void overlayRect(uint16 penColor, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
byte *getCurrentDrawingBuffer();
void scrollDisplayX(int16 dx, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer);
void scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer);
void fade(bool fadein, uint16 res);
void closeFont(TextFont *tf);
uint16 textLength(TextFont *tf, const char *text, uint16 numchars);
void closeFont(TextFont *font);
uint16 textLength(TextFont *font, const char *text, uint16 numChars);
uint16 textHeight(TextFont *tf);
void text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars);
void getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth);

View file

@ -48,7 +48,7 @@
namespace Lab {
LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
: Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0), _rnd("lab") {
: Engine(syst), _gameDescription(gameDesc), _extraGameFeatures(0) {
_lastWaitTOFTicks = 0;
_isHiRes = false;

View file

@ -136,7 +136,6 @@ private:
Image *_journalBackImage;
Image *_screenImage;
TextFont *_journalFont;
Common::RandomSource _rnd;
public:
bool _alternate;

View file

@ -359,7 +359,7 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) {
case SHOWMESSAGES: {
char **str = (char **)actionList->_data;
_graphics->_doNotDrawMessage = false;
_graphics->drawMessage(str[_rnd.getRandomNumber(actionList->_param1)]);
_graphics->drawMessage(str[_utils->getRandom(actionList->_param1)]);
_graphics->_doNotDrawMessage = true;
}
break;

View file

@ -34,7 +34,7 @@
#include "lab/utils.h"
namespace Lab {
Utils::Utils(LabEngine *vm) : _vm(vm) {
Utils::Utils(LabEngine *vm) : _vm(vm), _rnd("lab") {
_dataBytesPerRow = 0;
}
@ -427,4 +427,10 @@ void Utils::setBytesPerRow(int num) {
_dataBytesPerRow = num;
}
uint16 Utils::getRandom(uint16 max) {
if (max > 1)
return _rnd.getRandomNumber(max - 1);
else
return 0;
}
} // End of namespace Lab

View file

@ -40,13 +40,15 @@ private:
void unDiffByteByte(byte *dest, byte *diff);
void unDiffByteWord(uint16 *dest, uint16 *diff);
void VUnDiffByteByte(byte *Dest, byte *diff, uint16 bytesperrow);
void VUnDiffByteWord(uint16 *Dest, uint16 *diff, uint16 bytesperrow);
void VUnDiffByteLong(uint32 *Dest, uint32 *diff, uint16 bytesperrow);
void VUnDiffByteByte(byte *dest, byte *diff, uint16 bytesPerRow);
void VUnDiffByteWord(uint16 *dest, uint16 *diff, uint16 bytesPerRow);
void VUnDiffByteLong(uint32 *dest, uint32 *diff, uint16 bytesPerRow);
public:
Utils(LabEngine *vm);
Common::RandomSource _rnd;
uint16 scaleX(uint16 x);
uint16 scaleY(uint16 y);
int16 vgaScaleX(int16 x);
@ -55,10 +57,11 @@ public:
uint16 mapScaleX(uint16 x);
uint16 mapScaleY(uint16 y);
Common::Point vgaUnscale(Common::Point pos);
void unDiff(byte *newBuf, byte *oldBuf, byte *diffData, uint16 bytesperrow, bool isV);
void unDiff(byte *newBuf, byte *oldBuf, byte *diffData, uint16 bytesPerRow, bool isV);
void runLengthDecode(byte *dest, byte *source);
void VRunLengthDecode(byte *dest, byte *source, uint16 bytesPerRow);
void setBytesPerRow(int num);
uint16 getRandom(uint16 max);
};