Skip to content

Commit

Permalink
HOPKINS: Remove g_PTRNUL
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke committed Apr 5, 2013
1 parent f9247f0 commit e79a51c
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 177 deletions.
6 changes: 3 additions & 3 deletions engines/hopkins/anim.cpp
Expand Up @@ -531,7 +531,7 @@ void AnimationManager::searchAnim(const byte *data, int animIndex, int bufSize)
innerLoopCond = true;
if (bufSize < curBufferPos) {
_animBqe[animIndex]._enabledFl = false;
_animBqe[animIndex]._data = g_PTRNUL;
_animBqe[animIndex]._data = NULL;
return;
}
++curBufferPos;
Expand Down Expand Up @@ -817,12 +817,12 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u

void AnimationManager::initAnimBqe() {
for (int idx = 0; idx < 35; ++idx) {
_animBqe[idx]._data = g_PTRNUL;
_animBqe[idx]._data = NULL;
_animBqe[idx]._enabledFl = false;
}

for (int idx = 0; idx < 8; ++idx) {
Bank[idx]._data = g_PTRNUL;
Bank[idx]._data = NULL;
Bank[idx]._loadedFl = false;
Bank[idx]._filename = "";
Bank[idx]._fileHeader = 0;
Expand Down
8 changes: 4 additions & 4 deletions engines/hopkins/computer.cpp
Expand Up @@ -44,9 +44,9 @@ ComputerManager::ComputerManager(HopkinsEngine *vm) {
memset(_menuText[i]._line, 0, 90);
}
Common::fill(&_inputBuf[0], &_inputBuf[200], '\0');
_breakoutSpr = g_PTRNUL;
_breakoutSpr = NULL;
_textColor = 0;
_breakoutLevel = (int16 *)g_PTRNUL;
_breakoutLevel = (int16 *)NULL;
_breakoutBrickNbr = 0;
_breakoutScore = 0;
_breakoutLives = 0;
Expand Down Expand Up @@ -536,9 +536,9 @@ void ComputerManager::displayGamesSubMenu() {

_vm->_globals->_speed = 1;
_vm->_eventsManager->changeMouseCursor(0);
_breakoutSpr = g_PTRNUL;
_breakoutSpr = NULL;
_vm->_eventsManager->_breakoutFl = true;
_breakoutLevel = (int16 *)g_PTRNUL;
_breakoutLevel = (int16 *)NULL;
_breakoutBrickNbr = 0;
_breakoutScore = 0;
_breakoutLives = 5;
Expand Down
12 changes: 6 additions & 6 deletions engines/hopkins/dialogs.cpp
Expand Up @@ -44,9 +44,9 @@ DialogsManager::DialogsManager(HopkinsEngine *vm) {
_removeInventFl = false;
_inventX = _inventY = 0;
_inventWidth = _inventHeight = 0;
_inventWin1 = g_PTRNUL;
_inventBuf2 = g_PTRNUL;
_inventoryIcons = g_PTRNUL;
_inventWin1 = NULL;
_inventBuf2 = NULL;
_inventoryIcons = NULL;
}

DialogsManager::~DialogsManager() {
Expand All @@ -56,8 +56,8 @@ DialogsManager::~DialogsManager() {
}

void DialogsManager::clearAll() {
_inventWin1 = g_PTRNUL;
_inventBuf2 = g_PTRNUL;
_inventWin1 = NULL;
_inventBuf2 = NULL;
}

void DialogsManager::loadIcons() {
Expand Down Expand Up @@ -341,7 +341,7 @@ void DialogsManager::showInventory() {
_vm->_eventsManager->getMouseY();
_vm->_eventsManager->refreshScreenAndEvents();
}
_inventWin1 = g_PTRNUL;
_inventWin1 = NULL;

bool loopFl;
do {
Expand Down
4 changes: 2 additions & 2 deletions engines/hopkins/events.cpp
Expand Up @@ -44,14 +44,14 @@ EventsManager::EventsManager(HopkinsEngine *vm) {
_mouseSpriteId = 0;
_curMouseButton = 0;
_mouseButton = 0;
_mouseCursor = g_PTRNUL;
_mouseCursor = NULL;
_gameCounter = 0;
_rateCounter = 0;
_escKeyFl = false;
_gameKey = KEY_NONE;
_mouseCursorId = 0;
_oldIconId = 0;
_objectBuf = g_PTRNUL;
_objectBuf = NULL;

Common::fill(&_keyState[0], &_keyState[256], false);
_priorCounterTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion engines/hopkins/files.cpp
Expand Up @@ -239,7 +239,7 @@ byte *FileManager::searchCat(const Common::String &file, CatMode mode, bool &fil
f.seek(_catalogPos);

byte *catData = _vm->_globals->allocMemory(_catalogSize);
if (catData == g_PTRNUL)
if (catData == NULL)
error("CHARGE_FICHIER");

readStream(f, catData, _catalogSize);
Expand Down
12 changes: 6 additions & 6 deletions engines/hopkins/font.cpp
Expand Up @@ -59,7 +59,7 @@ void FontManager::loadZoneText() {
}

void FontManager::clearAll() {
_font = g_PTRNUL;
_font = NULL;
_fontFixedHeight = 0;
_fontFixedWidth = 0;

Expand All @@ -82,8 +82,8 @@ void FontManager::clearAll() {
for (int idx = 0; idx < 4048; idx++)
_index[idx] = 0;

_tempText = g_PTRNUL;
_zoneText = g_PTRNUL;
_tempText = NULL;
_zoneText = NULL;

_boxWidth = 240;
}
Expand Down Expand Up @@ -214,7 +214,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
f.seek(_index[messageId]);

_tempText = _vm->_globals->allocMemory(2058);
if (_tempText == g_PTRNUL)
if (_tempText == NULL)
error("Error allocating text");

Common::fill(&_tempText[0], &_tempText[2058], 0);
Expand Down Expand Up @@ -358,7 +358,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
if (textType == 1 || textType == 3 || textType == 5 || textType == 6) {
int size = saveHeight * saveWidth;
byte *ptrd = _vm->_globals->allocMemory(size);
if (ptrd == g_PTRNUL)
if (ptrd == NULL)
error("Cutting a block for text box (%d)", size);

_vm->_graphicsManager->copySurfaceRect(_vm->_graphicsManager->_frontBuffer, ptrd, posX, posY, saveWidth, saveHeight);
Expand Down Expand Up @@ -389,7 +389,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in
_text[idx]._textBlock = _vm->_globals->freeMemory(_text[idx]._textBlock);
int blockSize = blockHeight * blockWidth;
byte *ptre = _vm->_globals->allocMemory(blockSize + 20);
if (ptre == g_PTRNUL)
if (ptre == NULL)
error("Cutting a block for text box (%d)", blockSize);

_text[idx]._textBlock = ptre;
Expand Down
32 changes: 12 additions & 20 deletions engines/hopkins/globals.cpp
Expand Up @@ -32,10 +32,6 @@

namespace Hopkins {

// Global null pointer. This is needed by the engine to recognise NULL pointers, since
// there are places that differentiate between it and a 0 'error' value
byte *g_PTRNUL;

// Default data for the Hopkins array

const int HOPKINS_PERSO_0[] = {
Expand Down Expand Up @@ -65,10 +61,6 @@ const int HOPKINS_PERSO_2[] = {
Globals::Globals(HopkinsEngine *vm) {
_vm = vm;

// Set up the special g_PTRNUL variable
g_PTRNUL = (byte *)malloc(16);
strcpy((char *)g_PTRNUL, "POINTERNULL");

// Initialize array properties
for (int i = 0; i < 500; ++i)
_spriteSize[i] = 0;
Expand Down Expand Up @@ -113,11 +105,11 @@ Globals::Globals(HopkinsEngine *vm) {
_oceanDirection = DIR_NONE;

// Initialize pointers
_levelSpriteBuf = g_PTRNUL;
_saveData = (Savegame *)g_PTRNUL;
_answerBuffer = g_PTRNUL;
_characterSpriteBuf = g_PTRNUL;
_optionDialogSpr = g_PTRNUL;
_levelSpriteBuf = NULL;
_saveData = (Savegame *)NULL;
_answerBuffer = NULL;
_characterSpriteBuf = NULL;
_optionDialogSpr = NULL;

// Reset flags
_censorshipFl = false;
Expand All @@ -136,7 +128,7 @@ Globals::~Globals() {
freeMemory((byte *)_saveData);
freeMemory(_answerBuffer);
freeMemory(_characterSpriteBuf);
free(g_PTRNUL);
free(NULL);
}

void Globals::setConfig() {
Expand Down Expand Up @@ -178,9 +170,9 @@ void Globals::setConfig() {
void Globals::clearAll() {
_vm->_fontManager->clearAll();
_vm->_dialogsManager->clearAll();
_answerBuffer = g_PTRNUL;
_levelSpriteBuf = g_PTRNUL;
_saveData = (Savegame *)g_PTRNUL;
_answerBuffer = NULL;
_levelSpriteBuf = NULL;
_saveData = (Savegame *)NULL;
_vm->_objectsManager->_curObjectIndex = 0;

_vm->_linesManager->clearAll();
Expand Down Expand Up @@ -210,14 +202,14 @@ void Globals::loadCharacterData() {
byte *Globals::allocMemory(int count) {
byte *result = (byte *)malloc(count);
if (!result)
result = g_PTRNUL;
result = NULL;
return result;
}

byte *Globals::freeMemory(byte *p) {
if (p != g_PTRNUL)
if (p != NULL)
free(p);
return g_PTRNUL;
return NULL;
}

} // End of namespace Hopkins
3 changes: 0 additions & 3 deletions engines/hopkins/globals.h
Expand Up @@ -220,9 +220,6 @@ class Globals {
int _curRoomNum;
};

// Global null pointer
extern byte *g_PTRNUL;

} // End of namespace Hopkins

#endif /* HOPKINS_GLOBALS_H */
16 changes: 8 additions & 8 deletions engines/hopkins/graphics.cpp
Expand Up @@ -42,17 +42,17 @@ GraphicsManager::GraphicsManager(HopkinsEngine *vm) {
_initGraphicsFl = false;
_screenWidth = _screenHeight = 0;
_screenLineSize = 0;
PAL_PIXELS = g_PTRNUL;
PAL_PIXELS = NULL;
_lineNbr = 0;
_videoPtr = NULL;
_scrollOffset = 0;
_scrollPosX = 0;
_largeScreenFl = false;
_oldScrollPosX = 0;
_backBuffer = g_PTRNUL;
_frontBuffer = g_PTRNUL;
_screenBuffer = g_PTRNUL;
_backupScreen = g_PTRNUL;
_backBuffer = NULL;
_frontBuffer = NULL;
_screenBuffer = NULL;
_backupScreen = NULL;
_showDirtyRects = false;

_lineNbr2 = 0;
Expand Down Expand Up @@ -1840,7 +1840,7 @@ void GraphicsManager::drawVerticalLine(byte *surface, int xp, int yp, int height
*/
void GraphicsManager::backupScreen() {
// Allocate a new data block for the screen, if necessary
if (_vm->_graphicsManager->_backupScreen == g_PTRNUL)
if (_vm->_graphicsManager->_backupScreen == NULL)
_vm->_graphicsManager->_backupScreen = _vm->_globals->allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT);

// Backup the screen
Expand All @@ -1852,13 +1852,13 @@ void GraphicsManager::backupScreen() {
* Restore a previously backed up screen
*/
void GraphicsManager::restoreScreen() {
assert(_vm->_graphicsManager->_backupScreen != g_PTRNUL);
assert(_vm->_graphicsManager->_backupScreen != NULL);

// Restore the screen and free the buffer
Common::copy(_vm->_graphicsManager->_backupScreen, _vm->_graphicsManager->_backupScreen +
SCREEN_WIDTH * 2 * SCREEN_HEIGHT, _vm->_graphicsManager->_backBuffer);
_vm->_globals->freeMemory(_vm->_graphicsManager->_backupScreen);
_backupScreen = g_PTRNUL;
_backupScreen = NULL;
}

} // End of namespace Hopkins
6 changes: 3 additions & 3 deletions engines/hopkins/hopkins.cpp
Expand Up @@ -1193,7 +1193,7 @@ bool HopkinsEngine::runFull() {
_objectsManager->_forestFl = true;
Common::String im = Common::String::format("IM%d", _globals->_exitId);
_soundManager->playSound(13);
if (_objectsManager->_forestSprite == g_PTRNUL) {
if (_objectsManager->_forestSprite == NULL) {
_objectsManager->_forestSprite = _objectsManager->loadSprite("HOPDEG.SPR");
_soundManager->loadSample(1, "SOUND41.WAV");
}
Expand Down Expand Up @@ -2097,7 +2097,7 @@ void HopkinsEngine::playEnding() {
_globals->_cityMapEnabledFl = false;
_globals->_eventMode = EVENTMODE_IGNORE;
_soundManager->playSound(26);
_linesManager->_route = (RouteItem *)g_PTRNUL;
_linesManager->_route = (RouteItem *)NULL;
_globals->_freezeCharacterFl = true;
_globals->_exitId = 0;
_soundManager->loadSample(1, "SOUND90.WAV");
Expand Down Expand Up @@ -2830,7 +2830,7 @@ void HopkinsEngine::handleOceanMaze(int16 curExitId, Common::String backgroundFi
_graphicsManager->SETCOLOR3(251, 100, 100, 100);
_graphicsManager->SETCOLOR3(254, 0, 0, 0);
_objectsManager->animateSprite(0);
_linesManager->_route = (RouteItem *)g_PTRNUL;
_linesManager->_route = (RouteItem *)NULL;
_eventsManager->mouseOn();
_eventsManager->changeMouseCursor(4);

Expand Down

0 comments on commit e79a51c

Please sign in to comment.