Skip to content

Commit

Permalink
HOPKINS: Refactoring in FontManager and LinesManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Dec 30, 2012
1 parent 17b5a57 commit f59f7da
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 366 deletions.
7 changes: 3 additions & 4 deletions engines/hopkins/dialogs.cpp
Expand Up @@ -376,11 +376,11 @@ void DialogsManager::showInventory() {
// Turn on drawing the inventory dialog in the event manager
_inventDisplayedFl = true;

int v8 = _vm->_eventsManager.getMouseX();
int v9 = _vm->_eventsManager.getMouseY();
int mousePosX = _vm->_eventsManager.getMouseX();
int mousePosY = _vm->_eventsManager.getMouseY();
int v12 = _vm->_eventsManager.getMouseButton();
int v10 = v13;
int v11 = _vm->_linesManager.ZONE_OBJET(v8, v9);
int v11 = _vm->_linesManager.ZONE_OBJET(mousePosX, mousePosY);
v13 = v11;
if (v11 != v10)
_vm->_objectsManager.initBorder(v11);
Expand All @@ -398,7 +398,6 @@ void DialogsManager::showInventory() {
if (v12 == 1) {
if (_vm->_eventsManager._mouseCursorId == 1 || _vm->_eventsManager._mouseCursorId == 16 || !_vm->_eventsManager._mouseCursorId || (uint16)(_vm->_eventsManager._mouseCursorId - 2) <= 1u)
break;
v9 = v13;
_vm->_objectsManager.VALID_OBJET(_vm->_globals._inventory[v13]);
if (_vm->_eventsManager._mouseCursorId == 8)
v20 = true;
Expand Down
8 changes: 3 additions & 5 deletions engines/hopkins/files.cpp
Expand Up @@ -69,17 +69,15 @@ int FileManager::readStream(Common::ReadStream &stream, void *buf, size_t nbytes
* Initialize censorship based on blood.dat file
*/
void FileManager::initCensorship() {
_vm->_globals.CENSURE = false;
_vm->_globals._censorshipFl = false;

// If file doesn't exist, fallback to uncensored
if (!fileExists(_vm->_globals.HOPSYSTEM, "BLOOD.DAT")) {
constructFilename(_vm->_globals.HOPSYSTEM, "BLOOD.DAT");
char *data = (char *)loadFile(_vm->_globals._curFilename);

if (*(data + 6) == 'u' && *(data + 7) == 'k')
_vm->_globals.CENSURE = true;
if (*(data + 6) == 'U' && *(data + 7) == 'K')
_vm->_globals.CENSURE = true;
if ((data[6] == 'u' && data[7] == 'k') || (data[6] == 'U' && data[7] == 'K'))
_vm->_globals._censorshipFl = true;

free(data);
}
Expand Down
21 changes: 8 additions & 13 deletions engines/hopkins/font.cpp
Expand Up @@ -110,7 +110,7 @@ void FontManager::setOptimalColor(int idx1, int idx2, int idx3, int idx4) {
/**
* Init text structure
*/
void FontManager::initTextBuffers(int idx, int messageId, const Common::String &filename, int xp, int yp, int a6, int a7, int textType, int a9, int color) {
void FontManager::initTextBuffers(int idx, int messageId, const Common::String &filename, int xp, int yp, int textType, int a9, int color) {
if ((idx - 5) > MAX_TEXT)
error("Attempted to display text > MAX_TEXT.");

Expand All @@ -120,8 +120,6 @@ void FontManager::initTextBuffers(int idx, int messageId, const Common::String &
txt._pos.x = xp;
txt._pos.y = yp;
txt._messageId = messageId;
txt._fieldE = a6; // Useless variable
txt._field10 = a7; // Useless variable
txt._textType = textType;
txt._field3FE = a9;
txt._color = color;
Expand Down Expand Up @@ -236,9 +234,9 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
if (v69) {
int v64 = 0;
for (;;) {
byte v14 = *(v60 + v64);
byte v14 = v60[v64];
if (v14 == '\r' || v14 == '\n') {
*(v60 + v64) = 0;
v60[v64] = 0;
if (!_text[idx]._field3FE)
break;
}
Expand All @@ -250,9 +248,9 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
_vm->_globals._boxWidth = 0;

for (int v15 = 0; v15 < v64 + 1; v15++) {
byte v16 = *(v60 + v15);
byte v16 = v60[v15];
if (v16 <= 31)
v16 = 32;
v16 = ' ';
_vm->_globals._boxWidth += _vm->_objectsManager.getWidth(_vm->_globals.police, v16 - 32);
}

Expand All @@ -272,15 +270,14 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
_vm->_globals._boxWidth = 240;
int v65 = 0;
byte *v61 = _tempText;
int v21;
int lineSize;
do {
int v19 = 0;
int ptrb = _vm->_globals._boxWidth - 4;
for (;;) {
lineSize = v19;
do
v11 = *(v61 + v65 + v19++);
v11 = v61[v65 + v19++];
while (v11 != ' ' && v11 != '%');
if (v19 >= ptrb / _vm->_globals.police_l)
break;
Expand All @@ -298,21 +295,19 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
lineSize = v19;
LABEL_57:
int v20 = lineCount;
v21 = v11;

// WORKAROUND: Perhaps due to the usage of ScummVM strings here, recalculate what the
// actual length of the line to be copied will be. Otherwise, you can see artifacts,
// such as a single character beyond the end of string NULL.
int actualSize = 0;
while (actualSize < lineSize && *(v61 + v65 + actualSize))
while (actualSize < lineSize && v61[v65 + actualSize])
++actualSize;

_text[idx]._lines[v20] = Common::String((const char *)v61 + v65, actualSize);
_textSortArray[lineCount++] = lineSize;

v65 += lineSize;
v11 = v21;
} while (v21 != '%');
} while (v11 != '%');

for (int i = 0; i <= 19; i++) {
if (_textSortArray[i] <= 0) {
Expand Down
4 changes: 1 addition & 3 deletions engines/hopkins/font.h
Expand Up @@ -39,8 +39,6 @@ struct TxtItem {
Common::String _filename;
Common::Point _pos;
int _messageId;
int _fieldE; // Useless variable
int _field10; // Useless variable
int _lineCount;
Common::String _lines[10];
int _textType;
Expand Down Expand Up @@ -79,7 +77,7 @@ class FontManager {
void hideText(int idx);
void setTextColor(int idx, byte colByte);
void setOptimalColor(int idx1, int idx2, int idx3, int idx4);
void initTextBuffers(int idx, int messageId, const Common::String &filename, int xp, int yp, int a6, int a7, int textType, int a9, int a10);
void initTextBuffers(int idx, int messageId, const Common::String &filename, int xp, int yp, int textType, int a9, int color);
void box(int idx, int messageId, const Common::String &filename, int xp, int yp);

void displayTextVesa(int xp, int yp, const Common::String &message, int col);
Expand Down
13 changes: 5 additions & 8 deletions engines/hopkins/globals.cpp
Expand Up @@ -217,7 +217,7 @@ Globals::Globals() {
OPTION_SPR = NULL;

// Reset flags
CENSURE = false;
_censorshipFl = false;
GESTE_FLAG = 0;
BPP_NOAFF = false;
_disableInventFl = false;
Expand Down Expand Up @@ -330,9 +330,6 @@ void Globals::setConfig() {
}

void Globals::clearAll() {
// TODO: The original allocated an explicit memory block for the null pointer
// to point to. For now, we're seeing if the NULL value will do as well

for (int idx = 0; idx < 6; ++idx)
CACHE_BANQUE[idx] = g_PTRNUL;

Expand Down Expand Up @@ -381,9 +378,9 @@ void Globals::clearAll() {
_vm->_linesManager.Ligne[idx].field8 = 0;
_vm->_linesManager.Ligne[idx].lineData = (int16 *)g_PTRNUL;

_vm->_linesManager.LigneZone[idx].count = 0;
_vm->_linesManager.LigneZone[idx].field2 = 0;
_vm->_linesManager.LigneZone[idx].zoneData = (int16 *)g_PTRNUL;
_vm->_linesManager._zoneLine[idx].count = 0;
_vm->_linesManager._zoneLine[idx].field2 = 0;
_vm->_linesManager._zoneLine[idx].zoneData = (int16 *)g_PTRNUL;
}

for (int idx = 0; idx < 100; ++idx) {
Expand Down Expand Up @@ -415,7 +412,7 @@ void Globals::clearAll() {
GESTE_FLAG = 0;
}

void Globals::HOPKINS_DATA() {
void Globals::loadCharacterData() {
assert(PERSO_TYPE >= 0 && PERSO_TYPE <= 2);

const int *srcList[] = { HOPKINS_PERSO_0, HOPKINS_PERSO_1, HOPKINS_PERSO_2 };
Expand Down
4 changes: 2 additions & 2 deletions engines/hopkins/globals.h
Expand Up @@ -354,7 +354,7 @@ class Globals {
int SOUNDVOL;
int MUSICVOL;
int VOICEVOL;
bool CENSURE;
bool _censorshipFl;
int g_old_anim;
int g_old_sens, g_old_sens2;
int _lastDirection;
Expand Down Expand Up @@ -473,7 +473,7 @@ class Globals {

void setConfig();
void clearAll();
void HOPKINS_DATA();
void loadCharacterData();
void INIT_ANIM();
void INIT_VBOB();
void CLEAR_VBOB();
Expand Down
10 changes: 5 additions & 5 deletions engines/hopkins/hopkins.cpp
Expand Up @@ -233,7 +233,7 @@ bool HopkinsEngine::runWin95Demo() {
_graphicsManager.clearScreen();
_graphicsManager.unlockScreen();
_graphicsManager.clearPalette();
if (!_globals.CENSURE)
if (!_globals._censorshipFl)
_animationManager.playAnim("BANQUE.ANM", 200, 28, 200);
else
_animationManager.playAnim("BANKUK.ANM", 200, 28, 200);
Expand Down Expand Up @@ -560,7 +560,7 @@ bool HopkinsEngine::runLinuxDemo() {
_graphicsManager.clearPalette();
_graphicsManager.FADE_LINUX = 2;

if (!_globals.CENSURE)
if (!_globals._censorshipFl)
_animationManager.playAnim("BANQUE.ANM", 200, 28, 200);
else
_animationManager.playAnim("BANKUK.ANM", 200, 28, 200);
Expand Down Expand Up @@ -2675,7 +2675,7 @@ bool HopkinsEngine::runWin95full() {
_graphicsManager.clearScreen();
_graphicsManager.unlockScreen();
_graphicsManager.clearPalette();
if (!_globals.CENSURE)
if (!_globals._censorshipFl)
_animationManager.playAnim("BANQUE.ANM", 200, 28, 200);
else
_animationManager.playAnim("BANKUK.ANM", 200, 28, 200);
Expand Down Expand Up @@ -3554,7 +3554,7 @@ bool HopkinsEngine::runLinuxFull() {
_graphicsManager.unlockScreen();
_graphicsManager.clearPalette();
_graphicsManager.FADE_LINUX = 2;
if (!_globals.CENSURE)
if (!_globals._censorshipFl)
_animationManager.playAnim("BANQUE.ANM", 200, 28, 200);
else
_animationManager.playAnim("BANKUK.ANM", 200, 28, 200);
Expand Down Expand Up @@ -4438,7 +4438,7 @@ void HopkinsEngine::initializeSystem() {
_eventsManager.setMouseOn();
_eventsManager._mouseFl = false;

_globals.HOPKINS_DATA();
_globals.loadCharacterData();

_eventsManager._mouseOffset.x = 0;
_eventsManager._mouseOffset.y = 0;
Expand Down

0 comments on commit f59f7da

Please sign in to comment.