Skip to content

Commit

Permalink
TONY: Moved remaining globals to Globals class
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 13, 2012
1 parent b01482b commit 94f5a98
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 361 deletions.
41 changes: 41 additions & 0 deletions engines/tony/globals.cpp
Expand Up @@ -20,6 +20,7 @@
*
*/

#include "common/algorithm.h"
#include "tony/globals.h"

namespace Tony {
Expand All @@ -31,6 +32,8 @@ Globals::Globals() {
curChannel = 0;
flipflop = 0;
curBackText = NULL;
bTonyIsSpeaking = false;
curChangedHotspot = 0;
Tony = NULL;
Pointer = NULL;
Boxes = NULL;
Expand Down Expand Up @@ -89,6 +92,44 @@ Globals::Globals() {
Common::fill(&tappeti[0], &tappeti[200], 0);
SFM_nLoc = 0;
vdb = NULL;

// MPAL global variables
mpalError = 0;
lpiifCustom = NULL;
lplpFunctions = NULL;
lplpFunctionStrings = NULL;
nObjs = 0;
nVars = 0;
hVars = NULL;
lpmvVars = NULL;
nMsgs = 0;
hMsgs = NULL;
lpmmMsgs = NULL;
nDialogs = 0;
hDialogs = NULL;
lpmdDialogs = NULL;
nItems = 0;
hItems = NULL;
lpmiItems = NULL;
nLocations = 0;
hLocations = NULL;
lpmlLocations = NULL;
nScripts = 0;
hScripts = NULL;
lpmsScripts = NULL;
nResources = 0;
lpResources = NULL;
bExecutingAction = false;
bExecutingDialog = false;
Common::fill(&nPollingLocations[0], &nPollingLocations[MAXPOLLINGLOCATIONS], 0);
Common::fill(&hEndPollingLocations[0], &hEndPollingLocations[MAXPOLLINGLOCATIONS], 0);
Common::fill(&PollingThreads[0], &PollingThreads[MAXPOLLINGLOCATIONS], 0);
hAskChoice = 0;
hDoneChoice = 0;
nExecutingAction = 0;
nExecutingDialog = 0;
nExecutingChoice = 0;
nSelectedChoice = 0;
}

} // End of namespace Tony
66 changes: 66 additions & 0 deletions engines/tony/globals.h
Expand Up @@ -29,6 +29,8 @@
#include "tony/inventory.h"
#include "tony/loc.h"
#include "tony/tonychar.h"
#include "tony/mpal/mpal.h"
#include "tony/mpal/mpaldll.h"

namespace Tony {

Expand Down Expand Up @@ -140,6 +142,28 @@ struct ChangedHotspotStruct {
}
};

/****************************************************************************\
* typedef CFCALL
* --------------
* Description: Descrizione di una chiamata a una custom function
\****************************************************************************/

typedef struct {
int nCf;

int arg1, arg2, arg3, arg4;
} CFCALL;
typedef CFCALL* LPCFCALL;
typedef LPCFCALL* LPLPCFCALL;


/****************************************************************************\
* Global variables
\****************************************************************************/

/**
* Globals class
*/
class Globals {
public:
Globals();
Expand Down Expand Up @@ -225,6 +249,48 @@ class Globals {
int tappeti[200];
RMPoint SFM_pt;
int SFM_nLoc;

/**
* @defgroup MPAL variables
*
*/
uint32 mpalError;
LPITEMIRQFUNCTION lpiifCustom;
LPLPCUSTOMFUNCTION lplpFunctions;
Common::String * lplpFunctionStrings;
uint16 nObjs;
uint16 nVars;
HGLOBAL hVars;
LPMPALVAR lpmvVars;
uint16 nMsgs;
HGLOBAL hMsgs;
LPMPALMSG lpmmMsgs;
uint16 nDialogs;
HGLOBAL hDialogs;
LPMPALDIALOG lpmdDialogs;
uint16 nItems;
HGLOBAL hItems;
LPMPALITEM lpmiItems;
uint16 nLocations;
HGLOBAL hLocations;
LPMPALLOCATION lpmlLocations;
uint16 nScripts;
HGLOBAL hScripts;
LPMPALSCRIPT lpmsScripts;
Common::File hMpr;
uint16 nResources;
uint32 * lpResources;
bool bExecutingAction;
bool bExecutingDialog;
uint32 nPollingLocations[MAXPOLLINGLOCATIONS];
uint32 hEndPollingLocations[MAXPOLLINGLOCATIONS];
uint32 PollingThreads[MAXPOLLINGLOCATIONS];
uint32 hAskChoice;
uint32 hDoneChoice;
uint32 nExecutingAction;
uint32 nExecutingDialog;
uint32 nExecutingChoice;
uint32 nSelectedChoice;
};

} // End of namespace Tony
Expand Down
2 changes: 1 addition & 1 deletion engines/tony/mpal/expr.cpp
Expand Up @@ -209,7 +209,7 @@ static int Compute(int a, int b, byte symbol) {
case OP_OR:
return a||b;
default:
mpalError=1;
GLOBALS.mpalError = 1;
break;
}

Expand Down
124 changes: 62 additions & 62 deletions engines/tony/mpal/loadmpc.cpp
Expand Up @@ -517,58 +517,58 @@ bool ParseMpc(const byte *lpBuf) {
return false;

lpBuf += 4;
nVars = READ_LE_UINT16(lpBuf);
GLOBALS.nVars = READ_LE_UINT16(lpBuf);
lpBuf += 2;

hVars = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)nVars);
if (hVars == NULL)
GLOBALS.hVars = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars);
if (GLOBALS.hVars == NULL)
return false;

lpmvVars = (LPMPALVAR)GlobalLock(hVars);
GLOBALS.lpmvVars = (LPMPALVAR)GlobalLock(GLOBALS.hVars);

for (i = 0; i < nVars; i++) {
for (i = 0; i < GLOBALS.nVars; i++) {
wLen = *(const byte *)lpBuf;
lpBuf++;
CopyMemory(lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32));
CopyMemory(GLOBALS.lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32));
lpBuf += wLen;
lpmvVars->dwVal = READ_LE_UINT32(lpBuf);
GLOBALS.lpmvVars->dwVal = READ_LE_UINT32(lpBuf);
lpBuf += 4;

lpBuf++; // Salta 'ext'
lpmvVars++;
GLOBALS.lpmvVars++;
}

GlobalUnlock(hVars);
GlobalUnlock(GLOBALS.hVars);

/* 2. Messaggi */
if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S')
return false;

lpBuf += 4;
nMsgs = READ_LE_UINT16(lpBuf);
GLOBALS.nMsgs = READ_LE_UINT16(lpBuf);
lpBuf += 2;

#ifdef NEED_LOCK_MSGS
hMsgs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)nMsgs);
if (hMsgs == NULL)
GLOBALS.hMsgs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs);
if (GLOBALS.hMsgs == NULL)
return false;

lpmmMsgs = (LPMPALMSG)GlobalLock(hMsgs);
GLOBALS.lpmmMsgs = (LPMPALMSG)GlobalLock(GLOBALS.hMsgs);
#else
lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)nMsgs);
if (lpmmMsgs==NULL)
GLOBALS.lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)GLOBALS.nMsgs);
if (GLOBALS.lpmmMsgs==NULL)
return false;
#endif

for (i = 0; i < nMsgs; i++) {
lpmmMsgs->wNum = READ_LE_UINT16(lpBuf);
for (i = 0; i < GLOBALS.nMsgs; i++) {
GLOBALS.lpmmMsgs->wNum = READ_LE_UINT16(lpBuf);
lpBuf += 2;

for (j = 0; lpBuf[j] != 0;)
j += lpBuf[j] + 1;

lpmmMsgs->hText = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1);
lpTemp2 = lpTemp = (byte *)GlobalLock(lpmmMsgs->hText);
GLOBALS.lpmmMsgs->hText = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1);
lpTemp2 = lpTemp = (byte *)GlobalLock(GLOBALS.lpmmMsgs->hText);

for (j = 0; lpBuf[j] != 0;) {
CopyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]);
Expand All @@ -580,109 +580,109 @@ bool ParseMpc(const byte *lpBuf) {
lpBuf += j + 1;
*lpTemp = '\0';

GlobalUnlock(lpmmMsgs->hText);
lpmmMsgs++;
GlobalUnlock(GLOBALS.lpmmMsgs->hText);
GLOBALS.lpmmMsgs++;
}

#ifdef NEED_LOCK_MSGS
GlobalUnlock(hMsgs);
GlobalUnlock(GLOBALS.hMsgs);
#endif

/* 3. Oggetti */
if (lpBuf[0] != 'O' || lpBuf[1] != 'B' || lpBuf[2] != 'J' || lpBuf[3] != 'S')
return false;

lpBuf += 4;
nObjs = READ_LE_UINT16(lpBuf);
GLOBALS.nObjs = READ_LE_UINT16(lpBuf);
lpBuf += 2;

// Controlla i dialoghi
nDialogs = 0;
hDialogs = lpmdDialogs = NULL;
GLOBALS.nDialogs = 0;
GLOBALS.hDialogs = GLOBALS.lpmdDialogs = NULL;
if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) {
nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2;
GLOBALS.nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2;

hDialogs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)nDialogs * sizeof(MPALDIALOG));
if (hDialogs == NULL)
GLOBALS.hDialogs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG));
if (GLOBALS.hDialogs == NULL)
return false;

lpmdDialogs = (LPMPALDIALOG)GlobalLock(hDialogs);
GLOBALS.lpmdDialogs = (LPMPALDIALOG)GlobalLock(GLOBALS.hDialogs);

for (i = 0;i < nDialogs; i++)
if ((lpBuf = ParseDialog(lpBuf + 7, &lpmdDialogs[i])) == NULL)
for (i = 0;i < GLOBALS.nDialogs; i++)
if ((lpBuf = ParseDialog(lpBuf + 7, &GLOBALS.lpmdDialogs[i])) == NULL)
return false;

GlobalUnlock(hDialogs);
GlobalUnlock(GLOBALS.hDialogs);
}

// Controlla gli item
nItems = 0;
hItems = lpmiItems = NULL;
GLOBALS.nItems = 0;
GLOBALS.hItems = GLOBALS.lpmiItems = NULL;
if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4)==0) {
nItems = READ_LE_UINT16(lpBuf); lpBuf += 2;
GLOBALS.nItems = READ_LE_UINT16(lpBuf); lpBuf += 2;

// Alloca la memoria e li legge
hItems=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)nItems * sizeof(MPALITEM));
if (hItems == NULL)
GLOBALS.hItems = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM));
if (GLOBALS.hItems == NULL)
return false;

lpmiItems=(LPMPALITEM)GlobalLock(hItems);
GLOBALS.lpmiItems=(LPMPALITEM)GlobalLock(GLOBALS.hItems);

for (i = 0; i < nItems; i++)
if ((lpBuf = ParseItem(lpBuf + 5, &lpmiItems[i])) == NULL)
for (i = 0; i < GLOBALS.nItems; i++)
if ((lpBuf = ParseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL)
return false;

GlobalUnlock(hItems);
GlobalUnlock(GLOBALS.hItems);
}

// Controlla le locazioni
nLocations = 0;
hLocations = lpmlLocations = NULL;
GLOBALS.nLocations = 0;
GLOBALS.hLocations = GLOBALS.lpmlLocations = NULL;
if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8)==0) {
nLocations = READ_LE_UINT16(lpBuf); lpBuf += 2;
GLOBALS.nLocations = READ_LE_UINT16(lpBuf); lpBuf += 2;

// Alloca la memoria e li legge
hLocations=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)nLocations*sizeof(MPALLOCATION));
if (hLocations == NULL)
GLOBALS.hLocations=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION));
if (GLOBALS.hLocations == NULL)
return false;

lpmlLocations = (LPMPALLOCATION)GlobalLock(hLocations);
GLOBALS.lpmlLocations = (LPMPALLOCATION)GlobalLock(GLOBALS.hLocations);

for (i = 0; i < nLocations; i++)
if ((lpBuf = ParseLocation(lpBuf + 9, &lpmlLocations[i])) == NULL)
for (i = 0; i < GLOBALS.nLocations; i++)
if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS.lpmlLocations[i])) == NULL)
return false;

GlobalUnlock(hLocations);
GlobalUnlock(GLOBALS.hLocations);
}

// Controlla gli script
nScripts = 0;
hScripts = lpmsScripts = NULL;
GLOBALS.nScripts = 0;
GLOBALS.hScripts = GLOBALS.lpmsScripts = NULL;
if (*(lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Script", 6) == 0) {
nScripts = READ_LE_UINT16(lpBuf); lpBuf += 2;
GLOBALS.nScripts = READ_LE_UINT16(lpBuf); lpBuf += 2;

// Alloca la memoria
hScripts = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)nScripts * sizeof(MPALSCRIPT));
if (hScripts == NULL)
GLOBALS.hScripts = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT));
if (GLOBALS.hScripts == NULL)
return false;

lpmsScripts = (LPMPALSCRIPT)GlobalLock(hScripts);
GLOBALS.lpmsScripts = (LPMPALSCRIPT)GlobalLock(GLOBALS.hScripts);

for (i = 0; i < nScripts; i++) {
if ((lpBuf = ParseScript(lpBuf + 7, &lpmsScripts[i])) == NULL)
for (i = 0; i < GLOBALS.nScripts; i++) {
if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS.lpmsScripts[i])) == NULL)
return false;

// Ordina i vari moments dello script
//qsort(
//lpmsScripts[i].Moment,
//lpmsScripts[i].nMoments,
//sizeof(lpmsScripts[i].Moment[0]),
//GLOBALS.lpmsScripts[i].Moment,
//GLOBALS.lpmsScripts[i].nMoments,
//sizeof(GLOBALS.lpmsScripts[i].Moment[0]),
//(int (*)(const void *, const void *))CompareMoments
//);

}

GlobalUnlock(hScripts);
GlobalUnlock(GLOBALS.hScripts);
}

if (lpBuf[0] != 'E' || lpBuf[1] != 'N' || lpBuf[2] != 'D' || lpBuf[3] != '0')
Expand Down

0 comments on commit 94f5a98

Please sign in to comment.