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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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