Skip to content

Commit

Permalink
BAGEL: Remove some useless null check prior to delete, some renaming …
Browse files Browse the repository at this point in the history
…and cleanup
  • Loading branch information
Strangerke committed May 9, 2024
1 parent 62e0d10 commit aede2ba
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 51 deletions.
6 changes: 2 additions & 4 deletions engines/bagel/baglib/pan_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ CBagPanBitmap::CBagPanBitmap(const char *pszFileName, CBofPalette *pPalette, con
CBagPanBitmap::~CBagPanBitmap() {
assert(isValidObject(this));

if (_pCosineTable) {
delete[] _pCosineTable;
_pCosineTable = nullptr;
}
delete[] _pCosineTable;
_pCosineTable = nullptr;
}

// This must be updated whenever the size, view size, or correction width changes
Expand Down
9 changes: 4 additions & 5 deletions engines/bagel/baglib/text_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ CBagTextObject::CBagTextObject() : CBagObject() {
}

CBagTextObject::~CBagTextObject() {
if (_psInitInfo != nullptr) {
delete _psInitInfo;
_psInitInfo = nullptr;
}
delete _psInitInfo;
_psInitInfo = nullptr;

CBagTextObject::detach();
}

Expand Down Expand Up @@ -159,7 +158,7 @@ ErrorCode CBagTextObject::attach() {
}
}

bofFree(pTextBuff); // Changed from delete.
bofFree(pTextBuff);

} else {
reportError(ERR_MEMORY);
Expand Down
4 changes: 2 additions & 2 deletions engines/bagel/baglib/var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ CBagVarManager::~CBagVarManager() {
releaseVariables();
_xVarList.removeAll();

for (int i = 0; i < VAR_HTABLE_SIZE; i++) {
for (int i = 0; i < VAR_HASH_TABLE_SIZE; i++) {
_xVarHashList[i].removeAll();
}
}
Expand All @@ -214,7 +214,7 @@ static int HASHVAR(const char *p, int l) {
for (int j = 0; j < l; j++) {
h += p[j];
}
h %= VAR_HTABLE_SIZE;
h %= VAR_HASH_TABLE_SIZE;

return h;
}
Expand Down
6 changes: 3 additions & 3 deletions engines/bagel/baglib/var.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CBagVar : public CBagParseObject, public CBofObject {
CBagVar(const CBofString &sName, const CBofString &sValue, bool bAddToList);
virtual ~CBagVar();

ParseCodes setInfo(CBagIfstream &);
ParseCodes setInfo(CBagIfstream &) override;

const CBofString &getName() {
return _sVarName;
Expand Down Expand Up @@ -118,7 +118,7 @@ class CBagVar : public CBagParseObject, public CBofObject {
};

// This could be templated with the storage device manager
#define VAR_HTABLE_SIZE 131
#define VAR_HASH_TABLE_SIZE 131

class CBagVarManager : public CBagParseObject, public CBofObject {
private:
Expand All @@ -145,7 +145,7 @@ class CBagVarManager : public CBagParseObject, public CBofObject {
}

// Use a hash table to lookup variables.
CBofList<CBagVar *> _xVarHashList[VAR_HTABLE_SIZE];
CBofList<CBagVar *> _xVarHashList[VAR_HASH_TABLE_SIZE];
};

} // namespace Bagel
Expand Down
14 changes: 7 additions & 7 deletions engines/bagel/baglib/wield.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class CBagWield : public CBagStorageDevBmp {
_nWieldCursor = n;
}

virtual ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int nMaskColor = -1);
ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int nMaskColor = -1) override;

virtual ErrorCode loadFile(const CBofString &sFile);
virtual bool onObjInteraction(CBagObject *pObj, CBagStorageDev *pSDev);
ErrorCode loadFile(const CBofString &sFile) override;
bool onObjInteraction(CBagObject *pObj, CBagStorageDev *pSDev) override;

virtual ErrorCode attach();
virtual ErrorCode detach();
ErrorCode attach() override;
ErrorCode detach() override;

virtual ErrorCode activateLocalObject(CBagObject *pObj);
virtual ErrorCode deactivateLocalObject(CBagObject *pObj);
ErrorCode activateLocalObject(CBagObject *pObj) override;
ErrorCode deactivateLocalObject(CBagObject *pObj) override;
};

} // namespace Bagel
Expand Down
34 changes: 15 additions & 19 deletions engines/bagel/baglib/zoom_pda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
#include "bagel/baglib/rp_object.h"
#include "bagel/baglib/wield.h"
#include "bagel/baglib/zoom_pda.h"
#include "bagel/boflib/app.h"

namespace Bagel {

#define ZOOMMOOWLD "MOOZ_WLD"
#define ZOOMINVWLD "INVZ_WLD"
#define ZOOMMAPWLD "MAPZ_WLD"
#define ZOOMLOGWLD "LOGZ_WLD"
#define ZOOM_MOO_WLD "MOOZ_WLD"
#define ZOOM_INV_WLD "INVZ_WLD"
#define ZOOM_MAP_WLD "MAPZ_WLD"
#define ZOOM_LOG_WLD "LOGZ_WLD"

// Keep track of updates...
static uint32 g_lZoomPDALastUpdate;
Expand Down Expand Up @@ -76,24 +75,21 @@ ErrorCode SBZoomPda::onRender(CBofBitmap *pBmp, CBofRect *pRect) {
paintStorageDevice(nullptr, pBmp, pRect);

// Paint the inventory or Map to backdrop
if (bUpdate) {
if (_curDisplay != nullptr) {
_curDisplay->update(pBmp, _curDisplay->getPosition(), pRect);
}
}
if (bUpdate && (_curDisplay != nullptr))
_curDisplay->update(pBmp, _curDisplay->getPosition(), pRect);
}

return _errCode;
}

ErrorCode SBZoomPda::loadFile(const CBofString &sFile) {
ErrorCode error = CBagStorageDev::loadFile(sFile);
ErrorCode errorCode = CBagStorageDev::loadFile(sFile);
removeObject(_mooWnd);
removeObject(_invWnd);
removeObject(_mapWnd);
removeObject(_logWnd);

return error;
return errorCode;
}

ErrorCode SBZoomPda::detach() {
Expand Down Expand Up @@ -124,8 +120,8 @@ ErrorCode SBZoomPda::detach() {
// Since the regular PDA does not have a detach method (it doesn't get
// flushed out until you go to a flashback or quit the game), go through
// the entire list of RPO's (residue print objects) and restore the saved
// varible values. We do this so that any values that were changed in
// the zoomed version are propagated down to the unzoomed pda.
// variable values. We do this so that any values that were changed in
// the zoomed version are propagated down to the un-zoomed pda.

CBagRPObject::synchronizeResiduePrintedObjects(bLogZoomed);

Expand All @@ -142,7 +138,7 @@ ErrorCode SBZoomPda::attach() {
if (rc == ERR_NONE) {
CBagStorageDev *pSDev;
if (!_mooWnd) {
pSDev = g_SDevManager->getStorageDevice(ZOOMMOOWLD);
pSDev = g_SDevManager->getStorageDevice(ZOOM_MOO_WLD);

if (pSDev != nullptr) {
_mooWnd = (CBagStorageDevBmp *)pSDev;
Expand All @@ -157,7 +153,7 @@ ErrorCode SBZoomPda::attach() {
}

if (!_invWnd) {
pSDev = g_SDevManager->getStorageDevice(ZOOMINVWLD);
pSDev = g_SDevManager->getStorageDevice(ZOOM_INV_WLD);
if (pSDev != nullptr) {
_invWnd = (CBagStorageDevBmp *)pSDev;
_invWnd->setAssociateWnd(getAssociateWnd());
Expand All @@ -175,7 +171,7 @@ ErrorCode SBZoomPda::attach() {
}

if (!_mapWnd) {
pSDev = g_SDevManager->getStorageDevice(ZOOMMAPWLD);
pSDev = g_SDevManager->getStorageDevice(ZOOM_MAP_WLD);
if (pSDev != nullptr) {
_mapWnd = (CBagStorageDevBmp *)pSDev;
_mapWnd->setAssociateWnd(getAssociateWnd());
Expand All @@ -193,7 +189,7 @@ ErrorCode SBZoomPda::attach() {
}

if (!_logWnd) {
pSDev = g_SDevManager->getStorageDevice(ZOOMLOGWLD);
pSDev = g_SDevManager->getStorageDevice(ZOOM_LOG_WLD);
if (pSDev != nullptr) {
_logWnd = (CBagStorageDevBmp *)pSDev;
_logWnd->setAssociateWnd(getAssociateWnd());
Expand Down
22 changes: 11 additions & 11 deletions engines/bagel/baglib/zoom_pda.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ class SBZoomPda : public CBagStorageDevWnd, public SBBasePda {
/**
* Constructor
* @param pParent Pointer to the parent window
* @param xPoint Upper-left corner of PDA in parent window
* @param xRect Pda in parent window
* @param bActivated State of PDA whe constructed (optional)
*/
SBZoomPda(CBofWindow *pParent = nullptr, const CBofRect &xRect = CBofRect(), bool bActivated = true);
static void initialize();

virtual ErrorCode attach();
virtual ErrorCode detach();
ErrorCode attach() override;
ErrorCode detach() override;

virtual ErrorCode loadFile(const CBofString &sFile);
virtual void onMouseMove(uint32 nFlags, CBofPoint *, void * = nullptr);
ErrorCode loadFile(const CBofString &sFile) override;
void onMouseMove(uint32 nFlags, CBofPoint *, void * = nullptr) override;

/**
* Called to overload specific types of sprite objects
* @retrn Pointer to the new object
*/
CBagObject *onNewButtonObject(const CBofString &sInit);
CBagObject *onNewButtonObject(const CBofString &sInit) override;

virtual void onMainLoop();
void onMainLoop() override;

void onLButtonUp(uint32 nFlags, CBofPoint *xPoint, void * = nullptr);
virtual ErrorCode onRender(CBofBitmap *pBmp, CBofRect *pRect = nullptr);
void onLButtonUp(uint32 nFlags, CBofPoint *xPoint, void * = nullptr) override;
ErrorCode onRender(CBofBitmap *pBmp, CBofRect *pRect = nullptr) override;

virtual ErrorCode attachActiveObjects();
virtual ErrorCode detachActiveObjects();
ErrorCode attachActiveObjects() override;
ErrorCode detachActiveObjects() override;
};

} // namespace Bagel
Expand Down

0 comments on commit aede2ba

Please sign in to comment.