From 637be83cf5b129b7e55de97c5988f4dfa3c397bf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 26 Apr 2012 09:43:55 +1000 Subject: TONY: Start of work converting over MPAL sub-system --- engines/tony/mpal/expr.cpp | 471 +++++++ engines/tony/mpal/expr.h | 116 ++ engines/tony/mpal/loadmpc.cpp | 720 ++++++++++ engines/tony/mpal/loadmpc.h | 83 ++ engines/tony/mpal/lzo1x.h | 188 +++ engines/tony/mpal/mpal.cpp | 3071 +++++++++++++++++++++++++++++++++++++++++ engines/tony/mpal/mpal.h | 769 +++++++++++ engines/tony/mpal/mpaldll.h | 418 ++++++ engines/tony/mpal/stubs.cpp | 140 ++ engines/tony/mpal/stubs.h | 121 ++ 10 files changed, 6097 insertions(+) create mode 100644 engines/tony/mpal/expr.cpp create mode 100644 engines/tony/mpal/expr.h create mode 100644 engines/tony/mpal/loadmpc.cpp create mode 100644 engines/tony/mpal/loadmpc.h create mode 100644 engines/tony/mpal/lzo1x.h create mode 100644 engines/tony/mpal/mpal.cpp create mode 100644 engines/tony/mpal/mpal.h create mode 100644 engines/tony/mpal/mpaldll.h create mode 100644 engines/tony/mpal/stubs.cpp create mode 100644 engines/tony/mpal/stubs.h (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp new file mode 100644 index 0000000000..0faf91744c --- /dev/null +++ b/engines/tony/mpal/expr.cpp @@ -0,0 +1,471 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/************************************************************************** + * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * ... Spyral Software snc * + * . x#""*$Nu -= We create much MORE than ALL =- * + * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * .F ^$k $ "$b * + * ." $b u "$ #$L * + * P $c :*$L"$L '$k Project: MPAL................... * + * d @$N. $. d ^$b^$k $c * + * F 4 "$c '$ $ #$u#$u '$ Module: Expression gestor...... * + * 4 4k *N #b .> '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Gestisce le espressioni * + * 4> ^R$oue# d matematiche............ * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +#include "mpal.h" +#include "mpaldll.h" +#include "stubs.h" + +/* +#include "lzo1x.h" +*/ + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* Operazioni matematiche gestite +\****************************************************************************/ + +#define OP_MUL ((1<<4)|0) +#define OP_DIV ((1<<4)|1) +#define OP_MODULE ((1<<4)|2) +#define OP_ADD ((2<<4)|0) +#define OP_SUB ((2<<4)|1) +#define OP_SHL ((3<<4)|0) +#define OP_SHR ((3<<4)|1) +#define OP_MINOR ((4<<4)|0) +#define OP_MAJOR ((4<<4)|1) +#define OP_MINEQ ((4<<4)|2) +#define OP_MAJEQ ((4<<4)|3) +#define OP_EQUAL ((5<<4)|0) +#define OP_NOEQUAL ((5<<4)|1) +#define OP_BITAND ((6<<4)|0) +#define OP_BITXOR ((7<<4)|0) +#define OP_BITOR ((8<<4)|0) +#define OP_AND ((9<<4)|0) +#define OP_OR ((10<<4)|0) + + +/****************************************************************************\ +* enum ExprListTypes +* ------------------ +* Description: Tipi di oggetto che possono essere contenuti in una struttura +* EXPRESSION. +\****************************************************************************/ + +enum ExprListTypes +{ + ELT_NUMBER=1, + ELT_VAR=2, + ELT_PARENTH=3, + ELT_PARENTH2=4 +}; + + +/****************************************************************************\ +* Structures +\****************************************************************************/ + +/****************************************************************************\ +* typedef EXPRESSION +* ------------------ +* Description: Struttura per gestire le operazioni matematiche +\****************************************************************************/ + +typedef struct { + byte type; // Tipo di oggetto (vedi enum ExprListTypes) + byte unary; // Unary operatore (NON SUPPORTATO) + + union { + int num; // Numero (se type==ELT_NUMBER) + char *name; // Nome variabile (se type==ELT_VAR) + HGLOBAL son; // Handle a espressione (type==ELT_PARENTH) + byte *pson; // Handle lockato (type==ELT_PARENTH2) + } val; + + byte symbol; // Simbolo matematico (vedi #define OP_*) + +} EXPRESSION; +typedef EXPRESSION* LPEXPRESSION; + + +/****************************************************************************\ +* +* Function: LPEXPRESSION DuplicateExpression(HGLOBAL h); +* +* Description: Duplica un'espressione matematica. L'espressione duplicata +* sara' formata da memoria non swappabile. +* +* Input: HGLOBAL h Handle dell'espressione originale +* +* Return: Pointer all'espressione clone della prima +* +\****************************************************************************/ + +static byte *DuplicateExpression(HGLOBAL h) { + int i, num; + byte *orig, *clone; + LPEXPRESSION one, two; + + orig=(byte *)GlobalLock(h); + + num=*(byte *)orig; + one=(LPEXPRESSION)(orig+1); + + clone=GlobalAlloc(GMEM_FIXED,sizeof(EXPRESSION)*num+1); + two=(LPEXPRESSION)(clone+1); + + CopyMemory(clone,orig,sizeof(EXPRESSION)*num+1); + + for (i=0;itype==ELT_PARENTH) { + two->type=ELT_PARENTH2; + two->val.pson=DuplicateExpression(two->val.son); + } + + one++; + two++; + } + + GlobalUnlock(h); + return clone; +} + +static int Compute(int a, int b, byte symbol) { + switch (symbol) { + case OP_MUL: + return a*b; + case OP_DIV: + return a/b; + case OP_MODULE: + return a%b; + case OP_ADD: + return a+b; + case OP_SUB: + return a-b; + case OP_SHL: + return a<>b; + case OP_MINOR: + return ab; + case OP_MINEQ: + return a<=b; + case OP_MAJEQ: + return a>=b; + case OP_EQUAL: + return a==b; + case OP_NOEQUAL: + return a!=b; + case OP_BITAND: + return a&b; + case OP_BITXOR: + return a^b; + case OP_BITOR: + return a|b; + case OP_AND: + return a&&b; + case OP_OR: + return a||b; + default: + mpalError=1; + break; + } + + return 0; +} + +static void Solve(LPEXPRESSION one, int num) { + LPEXPRESSION two, three; + int j; + + while (num>1) { + two=one+1; + if ((two->symbol==0) || (one->symbol&0xF0) <= (two->symbol&0xF0)) { + two->val.num=Compute(one->val.num,two->val.num,one->symbol); + CopyMemory(one,two,(num-1)*sizeof(EXPRESSION)); + num--; + } else { + j=1; + three=two+1; + while ((three->symbol!=0) && (two->symbol&0xF0)>(three->symbol&0xF0)) { + two++; + three++; + j++; + } + + three->val.num=Compute(two->val.num,three->val.num,two->symbol); + CopyMemory(two,three,(num-j-1)*sizeof(EXPRESSION)); + num--; + } + } +} + + +/****************************************************************************\ +* +* Function: int EvaluateAndFreeExpression(byte *expr); +* +* Description: Calcola il risultato di una espressione matematica, sosti- +* tuendo ad eventuali variabili il valore corrente. +* +* Input: byte *expr Pointer all'espressione duplicata +* tramite DuplicateExpression +* +* Return: Valore dell'espressione +* +\****************************************************************************/ + +static int EvaluateAndFreeExpression(byte *expr) { + int i,num,val; + LPEXPRESSION one,cur; + + num=*expr; + one=(LPEXPRESSION)(expr+1); + + // 1) Sostituzioni delle variabili + for (i=0,cur=one;itype==ELT_VAR) { + cur->type=ELT_NUMBER; + cur->val.num=varGetValue(cur->val.name); + } + } + + // 2) Sostituzioni delle parentesi (tramite ricorsione) + for (i=0,cur=one;itype==ELT_PARENTH2) { + cur->type=ELT_NUMBER; + cur->val.num=EvaluateAndFreeExpression(cur->val.pson); + } + } + + // 3) Risoluzione algebrica + Solve(one,num); + val=one->val.num; + GlobalFree(expr); + + return val; +} + +/****************************************************************************\ +* +* Function: byte *ParseExpression(byte *buf, HGLOBAL *h); +* +* Description: Esegue il parsing da file .MPC di un'espressione matematica. +* +* Input: byte *buf Buffer contenente l'espressione +* compilata. +* HGLOBAL *h Pointer a un handle che, alla fine +* dell'esecuzione, puntera' alla +* zona di memoria contenete l'espres- +* sione parsata +* +* Return: Puntatore al buffer subito dopo l'espressione, o NULL in caso +* di errore. +* +\****************************************************************************/ + +byte *ParseExpression(byte *lpBuf, HGLOBAL *h) { + LPEXPRESSION cur; + byte *start; + uint32 num, i; + + num=*lpBuf; + lpBuf++; + + if (num==0) + return NULL; + + *h=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,num*sizeof(EXPRESSION)+1); + if (*h==NULL) + return NULL; + + start=(byte *)GlobalLock(*h); + *start=(byte)num; + + cur=(LPEXPRESSION)(start+1); + + for (i=0;itype=*(lpBuf); + cur->unary=*(lpBuf+1); + lpBuf+=2; + switch (cur->type) { + case ELT_NUMBER: + cur->val.num=*(int *)lpBuf; + lpBuf+=4; + break; + + case ELT_VAR: + cur->val.name=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,(*lpBuf)+1); + if (cur->val.name==NULL) + return NULL; + CopyMemory(cur->val.name,lpBuf+1,*lpBuf); + lpBuf+=*lpBuf+1; + break; + + case ELT_PARENTH: + lpBuf=ParseExpression(lpBuf,&cur->val.son); + if (lpBuf==NULL) + return NULL; + break; + + default: + return NULL; + } + + cur->symbol=*lpBuf; + lpBuf++; + + cur++; + } + + if (*lpBuf!=0) + return NULL; + + lpBuf++; + + return lpBuf; +} + + +/****************************************************************************\ +* +* Function: int EvaluateExpression(HGLOBAL h); +* +* Description: Calcola il valore di un'espressione matematica +* +* Input: HGLOBAL h Handle all'espressione +* +* Return: Valore numerico +* +\****************************************************************************/ + +int EvaluateExpression(HGLOBAL h) { + int ret; + + LockVar(); + ret=EvaluateAndFreeExpression(DuplicateExpression(h)); + UnlockVar(); + + return ret; +} + + +/****************************************************************************\ +* +* Function: bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); +* +* Description: Confronta due espressioni matematiche tra loro +* +* Input: HGLOBAL h1,h2 Espressioni da confrontare +* +* Return: true se sono uguali, false se sono diverse +* +\****************************************************************************/ + +bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { + int i,num1,num2; + byte *e1, *e2; + LPEXPRESSION one, two; + + e1=(byte *)GlobalLock(h1); + e2=(byte *)GlobalLock(h2); + + num1=*(byte *)e1; + num2=*(byte *)e2; + + if (num1 != num2) { + GlobalUnlock(h1); + GlobalUnlock(h2); + return false; + } + + one=(LPEXPRESSION)(e1+1); + two=(LPEXPRESSION)(e2+1); + + for (i=0;itype!=two->type || (i!=num1-1 && one->symbol!=two->symbol)) { + GlobalUnlock(h1); + GlobalUnlock(h2); + return false; + } + + switch (one->type) { + case ELT_NUMBER: + if (one->val.num != two->val.num) { + GlobalUnlock(h1); + GlobalUnlock(h2); + return false; + } + break; + + case ELT_VAR: + if (strcmp(one->val.name, two->val.name)!=0) { + GlobalUnlock(h1); + GlobalUnlock(h2); + return false; + } + break; + + case ELT_PARENTH: + if (!CompareExpressions(one->val.son,two->val.son)) { + GlobalUnlock(h1); + GlobalUnlock(h2); + return false; + } + break; + } + + one++; + two++; + } + + GlobalUnlock(h1); + GlobalUnlock(h2); + + return true; +} + + +} // end of namespace MPAL + +} // end of namespace Tony diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h new file mode 100644 index 0000000000..d54f17b088 --- /dev/null +++ b/engines/tony/mpal/expr.h @@ -0,0 +1,116 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/************************************************************************** + * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * ... Spyral Software snc * + * . x#""*$Nu -= We create much MORE than ALL =- * + * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * .F ^$k $ "$b * + * ." $b u "$ #$L * + * P $c :*$L"$L '$k Project: MPAL................... * + * d @$N. $. d ^$b^$k $c * + * F 4 "$c '$ $ #$u#$u '$ Module: Expression gestor heade * + * 4 4k *N #b .> '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Gestisce le espressioni * + * 4> ^R$oue# d matematiche............ * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +#ifndef MPAL_EXPR_H +#define MPAL_EXPR_H + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* Prototipi di funzione +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: byte *ParseExpression(byte *buf, HGLOBAL *h); +* +* Description: Esegue il parsing da file .MPC di un'espressione matematica. +* +* Input: byte *buf Buffer contenente l'espressione +* compilata. +* HGLOBAL *h Pointer a un handle che, alla fine +* dell'esecuzione, puntera' alla +* zona di memoria contenete l'espres- +* sione parsata +* +* Return: Puntatore al buffer subito dopo l'espressione, o NULL in caso +* di errore. +* +\****************************************************************************/ + +byte *ParseExpression(byte *lpBuf, HGLOBAL *h); + + +/****************************************************************************\ +* +* Function: int EvaluateExpression(HGLOBAL h); +* +* Description: Calcola il valore di un'espressione matematica +* +* Input: HGLOBAL h Handle all'espressione +* +* Return: Valore numerico +* +\****************************************************************************/ + +int EvaluateExpression(HGLOBAL h); + + +/****************************************************************************\ +* +* Function: bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); +* +* Description: Confronta due espressioni matematiche tra loro +* +* Input: HGLOBAL h1,h2 Espressioni da confrontare +* +* Return: TRUE se sono uguali, FALSE se sono diverse +* +\****************************************************************************/ + +bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); + + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp new file mode 100644 index 0000000000..f9426c8d58 --- /dev/null +++ b/engines/tony/mpal/loadmpc.cpp @@ -0,0 +1,720 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/************************************************************************** + * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * ... Spyral Software snc * + * . x#""*$Nu -= We create much MORE than ALL =- * + * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * .F ^$k $ "$b * + * ." $b u "$ #$L * + * P $c :*$L"$L '$k Project: MPAL................... * + * d @$N. $. d ^$b^$k $c * + * F 4 "$c '$ $ #$u#$u '$ Module: MPC Loader............. * + * 4 4k *N #b .> '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Legge un file compilato * + * 4> ^R$oue# d di MPAL................ * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +/* +#include "lzo1x.h" +*/ +#include "mpal.h" +#include "mpaldll.h" + +namespace Tony { + +namespace MPAL { + + +/****************************************************************************\ +* Funzioni statiche +\****************************************************************************/ + +static bool CompareCommands(struct command *cmd1, struct command *cmd2) { + if (cmd1->type == 2 && cmd2->type == 2) { + if (strcmp(cmd1->lpszVarName,cmd2->lpszVarName)==0 && + CompareExpressions(cmd1->expr,cmd2->expr)) + return true; + else + return false; + } else + return (memcmp(cmd1,cmd2,sizeof(struct command))==0); +} + + +/****************************************************************************\ +* +* Function: LPBTYE ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript); +* +* Description: Esegue il parsing da file .MPC di uno script e inserisce il +* tutto dentro una struttura +* +* Input: byte *lpBuf Buffer contenente lo script compilato +* LPMPALSCRIPT lpmsScript Puntatore a una struttura che verra' +* riempita con i dati dello script +* lato +* +* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore +* +\****************************************************************************/ + +static byte *ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript) { + int curCmd,j,len; + uint i; + + lpmsScript->nObj=*(int *)lpBuf; + lpBuf+=4; + + lpmsScript->nMoments=*(uint16 *)lpBuf; + lpBuf+=2; + + curCmd=0; + + for (i=0;inMoments;i++) { + lpmsScript->Moment[i].dwTime=*(int *)lpBuf; lpBuf+=4; + lpmsScript->Moment[i].nCmds=*lpBuf; lpBuf++; + + for (j=0;jMoment[i].nCmds;j++) { + lpmsScript->Command[curCmd].type=*lpBuf; lpBuf++; + switch (lpmsScript->Command[curCmd].type) { + case 1: + lpmsScript->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; + lpmsScript->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; + lpmsScript->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; + lpmsScript->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; + lpmsScript->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + break; + + case 2: // Variable assign + len=*lpBuf; lpBuf++; + lpmsScript->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); + if (lpmsScript->Command[curCmd].lpszVarName==NULL) + return NULL; + CopyMemory(lpmsScript->Command[curCmd].lpszVarName, lpBuf, len); + lpBuf+=len; + + lpBuf=ParseExpression(lpBuf,&lpmsScript->Command[curCmd].expr); + if (lpBuf==NULL) + return NULL; + break; + + default: + return NULL; + } + + lpmsScript->Moment[i].CmdNum[j]=curCmd; + curCmd++; + } + } + + return lpBuf; +} + + +/****************************************************************************\ +* +* Function: byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog); +* +* Description: Esegue il parsing da file .MPC di un dialog, e inserisce il +* tutto dentro una struttura +* +* Input: byte *lpBuf Buffer contenente il dialogo compi- +* lato +* LPMPALDIALOG lpmdDialog Puntatore a una struttura che verra' +* riempita con i dati del dialogo +* compilato +* +* Return: Puntatore al buffer dopo il dialogo, o NULL in caso di errore +* +\****************************************************************************/ + +static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { + uint32 i,j,z,kk; + uint32 num,num2,num3; + byte *lpLock; + uint32 curCmd; + uint32 len; + + lpmdDialog->nObj=*(int *)lpBuf; + lpBuf+=4; + + /* Periodi */ + num=*(uint16 *)lpBuf; lpBuf+=2; + + if (num >= MAX_PERIODS_PER_DIALOG-1) { + Common::String msg = Common::String::format("Too much periods in dialog #%d",lpmdDialog->nObj); + MessageBox(msg); + } + + for (i=0;iPeriodNums[i]=*(uint16 *)lpBuf; lpBuf+=2; + lpmdDialog->Periods[i]=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,*lpBuf+1); + lpLock = (byte *)GlobalLock(lpmdDialog->Periods[i]); + CopyMemory(lpLock,lpBuf+1,*lpBuf); + GlobalUnlock(lpmdDialog->Periods[i]); + lpBuf+=(*lpBuf)+1; + } + + lpmdDialog->PeriodNums[i]=0; + lpmdDialog->Periods[i]=NULL; + + /* Gruppi */ + num=*(uint16 *)lpBuf; lpBuf+=2; + curCmd=0; + + if (num >= MAX_GROUPS_PER_DIALOG) { + Common::String msg = Common::String::format("Too much groups in dialog #%d",lpmdDialog->nObj); + MessageBox(msg); + } + + for (i=0;iGroup[i].num=*(uint16 *)lpBuf; lpBuf+=2; + lpmdDialog->Group[i].nCmds=*lpBuf; lpBuf++; + + if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) { + Common::String msg = Common::String::format("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); + MessageBox(msg); + } + + for (j=0;jGroup[i].nCmds;j++) { + lpmdDialog->Command[curCmd].type=*lpBuf; + lpBuf++; + + switch (lpmdDialog->Command[curCmd].type) { + // Call custom function + case 1: + lpmdDialog->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; + lpmdDialog->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; + lpmdDialog->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; + lpmdDialog->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; + lpmdDialog->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + break; + + // Variable assign + case 2: + len=*lpBuf; + lpBuf++; + lpmdDialog->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); + if (lpmdDialog->Command[curCmd].lpszVarName==NULL) + return NULL; + CopyMemory(lpmdDialog->Command[curCmd].lpszVarName,lpBuf,len); + lpBuf+=len; + + lpBuf=ParseExpression(lpBuf,&lpmdDialog->Command[curCmd].expr); + if (lpBuf==NULL) + return NULL; + break; + + // Do Choice + case 3: + lpmdDialog->Command[curCmd].nChoice=*(uint16 *)lpBuf; lpBuf+=2; + break; + + default: + return NULL; + } + + for (kk=0;kkCommand[kk],&lpmdDialog->Command[curCmd])) { + lpmdDialog->Group[i].CmdNum[j]=kk; + break; + } + } + + if (kk==curCmd) { + lpmdDialog->Group[i].CmdNum[j]=curCmd; + curCmd++; + } + } + } + + if (curCmd >= MAX_COMMANDS_PER_DIALOG) { + Common::String msg = Common::String::format("Too much commands in dialog #%d",lpmdDialog->nObj); + MessageBox(msg); + } + + /* Choices */ + num=*(uint16 *)lpBuf; lpBuf+=2; + + if (num >= MAX_CHOICES_PER_DIALOG) { + Common::String msg = Common::String::format("Too much choices in dialog #%d",lpmdDialog->nObj); + MessageBox(msg); + } + + for (i=0;iChoice[i].nChoice=*(uint16 *)lpBuf; lpBuf+=2; + + num2=*lpBuf++; + + if (num2 >= MAX_SELECTS_PER_CHOICE) { + Common::String msg = Common::String::format("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); + MessageBox(msg); + } + + for (j=0;jChoice[i].Select[j].when=NULL; + break; + + case 1: + lpBuf=ParseExpression(lpBuf,&lpmdDialog->Choice[i].Select[j].when); + if (lpBuf==NULL) + return NULL; + break; + + case 2: + return NULL; + } + + // Attrib + lpmdDialog->Choice[i].Select[j].attr=*lpBuf++; + + // Data + lpmdDialog->Choice[i].Select[j].dwData=*(uint32 *)lpBuf; lpBuf+=4; + + // PlayGroup + num3=*lpBuf; *lpBuf++; + + if (num3 >= MAX_PLAYGROUPS_PER_SELECT) { + Common::String msg = Common::String::format("Too much playgroups in select #%d in choice #%d in dialog #%d",j,lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); + MessageBox(msg); + } + + for (z=0;zChoice[i].Select[j].wPlayGroup[z]=*(uint16 *)lpBuf; lpBuf+=2; + } + + lpmdDialog->Choice[i].Select[j].wPlayGroup[num3]=0; + } + + // Segna l'ultimo select + lpmdDialog->Choice[i].Select[num2].dwData=0; + } + + lpmdDialog->Choice[num].nChoice=0; + + return lpBuf; +} + +/****************************************************************************\ +* +* Function: byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem); +* +* Description: Esegue il parsing da file .MPC di un item, e inserisce il +* tutto dentro una struttura +* +* Input: byte *lpBuf Buffer contenete l'item compilato +* LPMPALITEM lpmiItem Puntatore a una struttura che verra' +* riempita con i dati dell'item +* compilato +* +* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore +* +* Note: E' necessario che la struttura passata come parametro sia +* stata completamente inizializzata a 0 (con una ZeroMemory, +* ad esempio). +* +\****************************************************************************/ + +static byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem) { + byte len; + uint32 i,j,kk; + uint32 curCmd; + + lpmiItem->nObj=*(int *)lpBuf; + lpBuf+=4; + + len=*lpBuf; + lpBuf++; + CopyMemory(lpmiItem->lpszDescribe,lpBuf, MIN((byte)127, len)); + lpBuf+=len; + + if (len >= MAX_DESCRIBE_SIZE) { + Common::String msg = Common::String::format("Describe too long in item #%d",lpmiItem->nObj); + MessageBox(msg); + } + + lpmiItem->nActions=*lpBuf; + lpBuf++; + + /* Alloca le azioni */ + if (lpmiItem->nActions>0) + lpmiItem->Action = (ItemAction *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(struct ItemAction)*(int)lpmiItem->nActions); + + curCmd=0; + + for (i=0;inActions;i++) { + lpmiItem->Action[i].num=*lpBuf; + lpBuf++; + + lpmiItem->Action[i].wParm=*(uint16 *)lpBuf; + lpBuf+=2; + + if (lpmiItem->Action[i].num==0xFF) { + lpmiItem->Action[i].wTime=*(uint16 *)lpBuf; + lpBuf+=2; + + lpmiItem->Action[i].perc=*lpBuf; + lpBuf++; + } + + + if (*lpBuf==0) { + lpBuf++; + lpmiItem->Action[i].when=NULL; + } else { + lpBuf++; + lpBuf=ParseExpression(lpBuf,&lpmiItem->Action[i].when); + if (lpBuf==NULL) + return NULL; + } + + lpmiItem->Action[i].nCmds=*lpBuf; + lpBuf++; + + if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) { + Common::String msg = Common::String::format("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); + MessageBox(msg); + } + + for (j=0;jAction[i].nCmds;j++) { + lpmiItem->Command[curCmd].type=*lpBuf; + lpBuf++; + switch (lpmiItem->Command[curCmd].type) { + case 1: // Call custom function + lpmiItem->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; + lpmiItem->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; + lpmiItem->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; + lpmiItem->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; + lpmiItem->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + break; + + case 2: // Variable assign + len=*lpBuf; + lpBuf++; + lpmiItem->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); + if (lpmiItem->Command[curCmd].lpszVarName==NULL) + return NULL; + CopyMemory(lpmiItem->Command[curCmd].lpszVarName,lpBuf,len); + lpBuf+=len; + + lpBuf=ParseExpression(lpBuf,&lpmiItem->Command[curCmd].expr); + if (lpBuf==NULL) + return NULL; + break; + + default: + return NULL; + } + + for (kk=0;kkCommand[kk],&lpmiItem->Command[curCmd])) { + lpmiItem->Action[i].CmdNum[j]=kk; + break; + } + } + + if (kk==curCmd) { + lpmiItem->Action[i].CmdNum[j]=curCmd; + curCmd++; + + if (curCmd >= MAX_COMMANDS_PER_ITEM) { + Common::String msg = Common::String::format("Too much commands in item #%d",lpmiItem->nObj); + MessageBox(msg); + curCmd=0; + } + } + } + } + + lpmiItem->dwRes=*(uint32 *)lpBuf; lpBuf+=4; + + return lpBuf; +} + + +/****************************************************************************\ +* +* Function: byte *ParseLocation(byte *buf, LPMPALLOCATIONN lpmlLocation) +* +* Description: Esegue il parsing da file .MPC di una locazione, riempendo +* una struttura +* +* Input: byte *buf Buffer contenente la locazione +* compilata +* LPMPALLOCATION +* lpmlLocation Pointer alla struttura che verra' +* riempita con i dati sulla locazione +* +* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore +* +\****************************************************************************/ + +static byte *ParseLocation(byte *lpBuf, LPMPALLOCATION lpmlLocation) { + lpmlLocation->nObj=*(int *)lpBuf; + lpBuf+=4; + lpmlLocation->dwXlen=*(uint16 *)lpBuf; + lpBuf+=2; + lpmlLocation->dwYlen=*(uint16 *)lpBuf; + lpBuf+=2; + lpmlLocation->dwPicRes=*(uint32 *)lpBuf; + lpBuf+=4; + + return lpBuf; +} + +/*static int CompareMoments(int * a, int * b) { + if (*a<*b) + return -1; + else if (*a>*b) + return 1; + else + return 0; +}*/ + +/****************************************************************************\ +* Funzioni globali +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: bool ParseMpc(byte *lpBuf); +* +* Description: Legge e interpreta un file MPC, e crea le strutture per le +* varie direttive nelle variabili globali +* +* Input: byte *lpBuf Immagine in memoria del file MPC, +* escluso l'header +* +* Return: true se tutto OK, false in caso di errore. +* +\****************************************************************************/ + +bool ParseMpc(byte *lpBuf) { + uint16 i,j; + uint16 wLen; + byte *lpTemp, *lpTemp2; + + // Oggetti dummy. Definiti static per evitare stack overflow + static MPALITEM dummyitem; + static MPALLOCATION dummylocation; + static MPALSCRIPT dummyscript; + static MPALDIALOG dummydialog; + + /* 1. Variabili */ + if (lpBuf[0]!='V' || lpBuf[1]!='A' || lpBuf[2]!='R' || lpBuf[3]!='S') + return false; + + lpBuf+=4; + nVars=*(uint16 *)lpBuf; + lpBuf+=2; + + hVars=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(MPALVAR)*(uint32)nVars); + if (hVars==NULL) + return false; + + lpmvVars=(LPMPALVAR)GlobalLock(hVars); + + for (i=0;ilpszVarName,lpBuf,MIN(wLen, (uint16)32)); + lpBuf+=wLen; + lpmvVars->dwVal=*(int *)lpBuf; + lpBuf+=4; + + lpBuf++; // Salta 'ext' + lpmvVars++; + } + + GlobalUnlock(hVars); + + /* 2. Messaggi */ + if (lpBuf[0]!='M' || lpBuf[1]!='S' || lpBuf[2]!='G' || lpBuf[3]!='S') + return false; + + lpBuf+=4; + nMsgs=*(uint16 *)lpBuf; + lpBuf+=2; + +#ifdef NEED_LOCK_MSGS + hMsgs=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)nMsgs); + if (hMsgs==NULL) + return false; + + lpmmMsgs=(LPMPALMSG)GlobalLock(hMsgs); +#else + lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)nMsgs); + if (lpmmMsgs==NULL) + return false; +#endif + + for (i=0;iwNum=*(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); + + for (j=0;lpBuf[j]!=0;) { + CopyMemory(lpTemp,&lpBuf[j+1],lpBuf[j]); + lpTemp+=lpBuf[j]; + *lpTemp++='\0'; + j+=lpBuf[j]+1; + } + + lpBuf+=j+1; + *lpTemp='\0'; + + GlobalUnlock(lpmmMsgs->hText); + lpmmMsgs++; + } + +#ifdef NEED_LOCK_MSGS + GlobalUnlock(hMsgs); +#endif + + /* 3. Oggetti */ + if (lpBuf[0]!='O' || lpBuf[1]!='B' || lpBuf[2]!='J' || lpBuf[3]!='S') + return false; + + lpBuf+=4; + nObjs=*(uint16 *)lpBuf; + lpBuf+=2; + + // Controlla i dialoghi + nDialogs=0; + hDialogs=lpmdDialogs=NULL; + if (*((const char *)lpBuf+2)==6 && strncmp((const char *)lpBuf+3,"Dialog",6)==0) { + nDialogs=*(uint16 *)lpBuf; lpBuf+=2; + + hDialogs=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,(uint32)nDialogs*sizeof(MPALDIALOG)); + if (hDialogs==NULL) + return false; + + lpmdDialogs=(LPMPALDIALOG)GlobalLock(hDialogs); + + for (i=0;i '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Legge un file compilato * + * 4> ^R$oue# d MPC.................... * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +#ifndef __LOADMPC_H +#define __LOADMPC_H + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* Prototipi di funzione +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: BOOL ParseMpc(LPBYTE lpBuf); +* +* Description: Legge e interpreta un file MPC, e crea le strutture per le +* varie direttive nelle variabili globali +* +* Input: LPBYTE lpBuf Immagine in memoria del file MPC, +* escluso l'header +* +* Return: TRUE se tutto OK, FALSE in caso di errore. +* +\****************************************************************************/ + +bool ParseMpc(const byte *lpBuf); + + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif + diff --git a/engines/tony/mpal/lzo1x.h b/engines/tony/mpal/lzo1x.h new file mode 100644 index 0000000000..83b547428c --- /dev/null +++ b/engines/tony/mpal/lzo1x.h @@ -0,0 +1,188 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/* lzo1x.h -- public interface of the LZO1X compression algorithm + + This file is part of the LZO real-time data compression library. + + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + + The LZO library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + The LZO library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Markus F.X.J. Oberhumer + + http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html + */ + + +#ifndef __LZO1X_H +#define __LZO1X_H + +#ifndef __LZOCONF_H +#include "lzoconf.h" +#endif + +namespace Tony { + +namespace MPAL { + +/*********************************************************************** +// +************************************************************************/ + +/* Memory required for the wrkmem parameter. + * When the required size is 0, you can also pass a NULL pointer. + */ + +#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS +#define LZO1X_MEM_DECOMPRESS (0) +#define LZO1X_MEM_OPTIMIZE (0) + + +/* decompression */ +LZO_EXTERN(int) +lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + +/* safe decompression with overrun testing */ +LZO_EXTERN(int) +lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + + +/*********************************************************************** +// +************************************************************************/ + +#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) + +LZO_EXTERN(int) +lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem ); + + +/*********************************************************************** +// special compressor versions +************************************************************************/ + +/* this version needs only 8 kB work memory */ +#define LZO1X_1_11_MEM_COMPRESS ((lzo_uint32) (2048L * lzo_sizeof_dict_t)) + +LZO_EXTERN(int) +lzo1x_1_11_compress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem ); + + +/* this version needs 16 kB work memory */ +#define LZO1X_1_12_MEM_COMPRESS ((lzo_uint32) (4096L * lzo_sizeof_dict_t)) + +LZO_EXTERN(int) +lzo1x_1_12_compress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem ); + + +/* use this version if you need a little more compression speed */ +#define LZO1X_1_15_MEM_COMPRESS ((lzo_uint32) (32768L * lzo_sizeof_dict_t)) + +LZO_EXTERN(int) +lzo1x_1_15_compress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem ); + + +/*********************************************************************** +// better compression ratio at the cost of more memory and time +************************************************************************/ + +#define LZO1X_999_MEM_COMPRESS ((lzo_uint32) (14 * 16384L * sizeof(short))) + +#if !defined(LZO_999_UNSUPPORTED) +LZO_EXTERN(int) +lzo1x_999_compress ( const lzo_byte *src, lzo_uint src_len, + lzo_byte *dst, lzo_uint *dst_len, + lzo_voidp wrkmem ); +#endif + + +/*********************************************************************** +// +************************************************************************/ + +#if !defined(LZO_999_UNSUPPORTED) +LZO_EXTERN(int) +lzo1x_999_compress_dict ( const lzo_byte *in , lzo_uint in_len, + lzo_byte *out, lzo_uint *out_len, + lzo_voidp wrkmem, + const lzo_byte *dict, lzo_uint dict_len ); + +LZO_EXTERN(int) +lzo1x_999_compress_level ( const lzo_byte *in , lzo_uint in_len, + lzo_byte *out, lzo_uint *out_len, + lzo_voidp wrkmem, + const lzo_byte *dict, lzo_uint dict_len, + lzo_progress_callback_t cb, + int compression_level ); +#endif + +LZO_EXTERN(int) +lzo1x_decompress_dict_safe ( const lzo_byte *in, lzo_uint in_len, + lzo_byte *out, lzo_uint *out_len, + lzo_voidp wrkmem /* NOT USED */, + const lzo_byte *dict, lzo_uint dict_len ); + + +/*********************************************************************** +// optimize a compressed data block +************************************************************************/ + +LZO_EXTERN(int) +lzo1x_optimize ( lzo_byte *in , lzo_uint in_len, + lzo_byte *out, lzo_uint *out_len, + lzo_voidp wrkmem ); + + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif /* already included */ diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp new file mode 100644 index 0000000000..2fd9f3b9c3 --- /dev/null +++ b/engines/tony/mpal/mpal.cpp @@ -0,0 +1,3071 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/************************************************************************** + * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * ... Spyral Software snc * + * . x#""*$Nu -= We create much MORE than ALL =- * + * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * .F ^$k $ "$b * + * ." $b u "$ #$L * + * P $c :*$L"$L '$k Project: MPAL................... * + * d @$N. $. d ^$b^$k $c * + * F 4 "$c '$ $ #$u#$u '$ Module: Mpal Query Library..... * + * 4 4k *N #b .> '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Libreria principale di * + * 4> ^R$oue# d MPAL, contenente il * + * '$ "" @ codice per le query.... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +#include "common/scummsys.h" +#include "common/file.h" +#include "common/savefile.h" +#include "common/system.h" +#include "mpal.h" +#include "mpaldll.h" +#include "stubs.h" +#include "tony/tony.h" +#include "tony/lzo/lzo1x.h" + +namespace Tony { + +namespace MPAL { + +using namespace Tony::LZO; + +/****************************************************************************\ +* Copyright +\****************************************************************************/ + +const char *mpalCopyright = + "\n\nMPAL - MultiPurpose Adventure Language for Windows 95\n" + "Copyright 1997-98 Giovanni Bajo and Luca Giusti\n" + "ALL RIGHTS RESERVED\n" + "\n" + "\n"; + +/****************************************************************************\ +* Structures +\****************************************************************************/ + +/****************************************************************************\ +* 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 +\****************************************************************************/ + +uint32 mpalError; + +static bool bInit=false; +static byte * lpMpcImage; + +LPITEMIRQFUNCTION lpiifCustom=NULL; + +LPLPCUSTOMFUNCTION lplpFunctions=NULL; +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]; +HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS]; +HANDLE PollingThreads[MAXPOLLINGLOCATIONS]; + +HANDLE hAskChoice; +HANDLE hDoneChoice; + +uint32 nExecutingAction; + +uint32 nExecutingDialog; +uint32 nExecutingChoice; +uint32 nSelectedChoice; + + +/****************************************************************************\ +* Static functions +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: void LockVar(void); +* +* Description: Locka le variabili per accederci +* +\****************************************************************************/ + +void LockVar(void) { + lpmvVars=(LPMPALVAR)GlobalLock(hVars); +} + +/****************************************************************************\ +* +* Function: void UnlockVar(void); +* +* Description: Unlocka le variabili dopo l'uso +* +\****************************************************************************/ + +void UnlockVar(void) { + GlobalUnlock(hVars); +} + + +/****************************************************************************\ +* +* Function: void LockMsg(void); +* +* Description: Locka i messaggi per accederci +* +\****************************************************************************/ + +static void LockMsg(void) { +#ifdef NEED_LOCK_MSGS + lpmmMsgs=(LPMPALMSG)GlobalLock(hMsgs); +#endif +} + + +/****************************************************************************\ +* +* Function: void UnlockMsg(void); +* +* Description: Unlocka i messaggi dopo l'uso +* +\****************************************************************************/ + +static void UnlockMsg(void) { +#ifdef NEED_LOCK_MSGS + GlobalUnlock(hMsgs); +#endif +} + + +/****************************************************************************\ +* +* Function: void LockDialogs(void); +* +* Description: Locka i dialoghi per accederci +* +\****************************************************************************/ + +static void LockDialogs(void) { + lpmdDialogs=(LPMPALDIALOG)GlobalLock(hDialogs); +} + + +/****************************************************************************\ +* +* Function: void UnlockDialogs(void); +* +* Description: Unlocka i dialoghi dopo l'uso +* +\****************************************************************************/ + +static void UnlockDialogs(void) { + GlobalUnlock(hDialogs); +} + + +/****************************************************************************\ +* +* Function: void LockLocations(void); +* +* Description: Locka le strutture di dati sulle locazioni +* +\****************************************************************************/ + +static void LockLocations(void) { + lpmlLocations=(LPMPALLOCATION)GlobalLock(hLocations); +} + + +/****************************************************************************\ +* +* Function: void UnlockLocations(void); +* +* Description: Unlocka le strutture di dati sulle locazioni +* +\****************************************************************************/ + +static void UnlockLocations(void) { + GlobalUnlock(hLocations); +} + + +/****************************************************************************\ +* +* Function: void LockItems(void); +* +* Description: Locka le strutture di dati sugli item +* +\****************************************************************************/ + +static void LockItems(void) { + lpmiItems=(LPMPALITEM)GlobalLock(hItems); +} + + +/****************************************************************************\ +* +* Function: void UnlockItems(void); +* +* Description: Unlocka le strutture di dati sugli item +* +\****************************************************************************/ + +static void UnlockItems(void) { + GlobalUnlock(hItems); +} + +/****************************************************************************\ +* +* Function: void LockScripts(void); +* +* Description: Locka le strutture di dati sugli script +* +\****************************************************************************/ + +static void LockScripts(void) { + lpmsScripts=(LPMPALSCRIPT)GlobalLock(hScripts); +} + + +/****************************************************************************\ +* +* Function: void UnlockScripts(void); +* +* Description: Unlocka le strutture di dati sugli script +* +\****************************************************************************/ + +static void UnlockScripts(void) { + GlobalUnlock(hScripts); +} + + + + + +/****************************************************************************\ +* +* Function: int varGetValue(char * lpszVarName); +* +* Description: Restituisce il valore corrente di una variabile globale +* +* Input: char * lpszVarName Nome della variabile +* +* Return: Valore corrente +* +* Note: Prima di questa funzione, bisogna richiamare LockVar() che +* locka le variabili globali per l'utilizzo. Dopo inoltre bi- +* sogna ricordarsi di chiamare UnlockVar() +* +\****************************************************************************/ + +int32 varGetValue(const char *lpszVarName) { + int i; + LPMPALVAR v=lpmvVars; + + for (i=0;ilpszVarName)==0) + return v->dwVal; + + mpalError=1; + return 0; +} + + +/****************************************************************************\ +* +* Function: void varSetValue(char * lpszVarName, int val); +* +* Description: Setta un nuovo valore per una variabile globale di MPAL +* +* Input: char * lpszVarName Nome della variabile +* int val Valore da settare +* +\****************************************************************************/ + +void varSetValue(const char *lpszVarName, int32 val) { + int i; + LPMPALVAR v=lpmvVars; + + for (i=0;ilpszVarName)==0) { + v->dwVal=val; + if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Pattern.",8)==0) { + i=0; + sscanf(v->lpszVarName,"Pattern.%u",&i); + lpiifCustom(i,val,-1); + } else if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Status.",7)==0) { + i=0; + sscanf(v->lpszVarName,"Status.%u",&i); + lpiifCustom(i,-1,val); + } + return; + } + + mpalError=1; + return; +} + + +/****************************************************************************\ +* +* Function: int locGetOrderFromNum(uint32 nLoc); +* +* Description: Trova l'indice della locazione #nLoc all'interno dell'array +* delle strutture delle locazioni +* +* Input: uint32 nLoc Numero della locazione da cercare +* +* Return: Indice, o -1 se la locazione non e' presente +* +* Note: Per funzionare, la funzione necessita che le locazioni siano +* state lockate con LockLoc() +* +\****************************************************************************/ + +static int locGetOrderFromNum(uint32 nLoc) { + int i; + LPMPALLOCATION loc=lpmlLocations; + + for (i=0;inObj==nLoc) + return i; + + return -1; +} + +/****************************************************************************\ +* +* Function: int msgGetOrderFromNum(uint32 nMsg); +* +* Description: Trova l'indice del messaggio #nMsg all'interno dell'array +* delle strutture dei messaggi +* +* Input: uint32 nMsg Numero del messaggio da cercare +* +* Return: Indice, o -1 se il messaggio non e' presente +* +* Note: Per funzionare, la funzione necessita che i messaggi siano +* stati lockati con LockMsg() +* +\****************************************************************************/ + +static int msgGetOrderFromNum(uint32 nMsg) { + int i; + LPMPALMSG msg=lpmmMsgs; + + for (i=0;iwNum==nMsg) + return i; + + return -1; +} + + +/****************************************************************************\ +* +* Function: int itemGetOrderFromNum(uint32 nItem); +* +* Description: Trova l'indice dell'item #nItem all'interno dell'array delle +* strutture degli item +* +* Input: uint32 nItem Numero dell'item da cercare +* +* Return: Indice, o -1 se l'item non e' presente +* +* Note: Per funzionare, questa funzione necessita che gli item siano +* stati lockati tramite LockItem() +* +\****************************************************************************/ + +static int itemGetOrderFromNum(uint32 nItem) { + int i; + LPMPALITEM item=lpmiItems; + + for (i=0;inObj==nItem) + return i; + + return -1; +} + + +/****************************************************************************\ +* +* Function: int scriptGetOrderFromNum(uint32 nScript); +* +* Description: Trova l'indice dello script #nScript all'interno dell'array +* delle strutture degli script +* +* Input: uint32 nScript Numero dello script da cercare +* +* Return: Indice, o -1 se lo script non e' presente +* +* Note: Per funzionare, questa funzione necessita che gli script siano +* stati lockati tramite LockScript() +* +\****************************************************************************/ + +static int scriptGetOrderFromNum(uint32 nScript) { + int i; + LPMPALSCRIPT script=lpmsScripts; + + for (i=0;inObj==nScript) + return i; + + return -1; +} + + +/****************************************************************************\ +* +* Function: int dialogGetOrderFromNum(uint32 nDialog); +* +* Description: Trova l'indice del dialog #nDialog all'interno dell'array +* delle strutture dei dialog +* +* Input: uint32 nDialog Numero del dialog da cercare +* +* Return: Indice, o -1 se il dialog non e' presente +* +* Note: Per funzionare, questa funzione necessita che i dialog siano +* stati lockati tramite LockDialogs() +* +\****************************************************************************/ + +static int dialogGetOrderFromNum(uint32 nDialog) { + int i; + LPMPALDIALOG dialog=lpmdDialogs; + + for (i=0;inObj==nDialog) + return i; + + return -1; +} + + + +/****************************************************************************\ +* +* Function: char * DuplicateMessage(uint32 nMsgOrd); +* +* Description: Duplica un messaggio +* +* Input: uint32 nMsgOrd Indice del messaggio dentro l'array +* di strutture dei messaggi +* +* Return: Pointer al messaggio duplicato (che puo' essere liberato +* con GlobalFree()). +* +\****************************************************************************/ + +static char *DuplicateMessage(uint32 nMsgOrd) { + const char *origmsg; + char *clonemsg; + int j; + + if (nMsgOrd == (uint32)-1) + return NULL; + + origmsg = (const char *)GlobalLock(lpmmMsgs[nMsgOrd].hText); + + j=0; + while (origmsg[j]!='\0' || origmsg[j+1]!='\0') + j++; + j+=2; + + clonemsg=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,j); + if (clonemsg==NULL) + return NULL; + + CopyMemory(clonemsg, origmsg, j); + GlobalUnlock(lpmmMsgs[nMsgOrd].hText); + + return clonemsg; +} + + +/****************************************************************************\ +* +* Function: char * DuplicateDialogPeriod(uint32 nDlgOrd, uint32 nPeriod); +* +* Description: Duplica una frase di un dialog +* +* Input: uint32 nDlgOrd Indice del dialogo dentro l'array di +* strutture dei dialoghi +* +* uint32 nPeriod Numero della frase da duplicare +* +* Return: Pointer alla frase duplicata (che puo' essere liberata con +* GlobalFree()). +* +\****************************************************************************/ + +static char *DuplicateDialogPeriod(uint32 nPeriod) { + const char *origmsg; + char *clonemsg; + LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; + int i,j; + + for (j=0;dialog->Periods[j]!=NULL;j++) + if (dialog->PeriodNums[j]==nPeriod) { + /* Trovata la frase, va duplicata */ + origmsg = (const char *)GlobalLock(dialog->Periods[j]); + + /* Calcola la lunghezza e alloca la memoria */ + i=0; + while (origmsg[i]!='\0') i++; + + clonemsg = (char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,i+1); + if (clonemsg==NULL) + return NULL; + + CopyMemory(clonemsg, origmsg, i); + + GlobalUnlock(dialog->Periods[j]); + + return clonemsg; + } + + return NULL; +} + + + +/****************************************************************************\ +* +* Function: HGLOBAL resLoad(uint32 dwId); +* +* Description: Carica una risorsa dal file MPR +* +* Input: uint32 dwId ID della risorsa da caricare +* +* Return: Handle alla memoria in cui si trova la risorsa +* +\****************************************************************************/ + +HGLOBAL resLoad(uint32 dwId) { + int i; + HGLOBAL h; + char head[4]; + uint32 nBytesRead; + uint32 nSizeComp, nSizeDecomp; + byte *temp, *buf; + + for (i=0;iChoice[i].Select[j].dwData!=0;j++) + if (dialog->Choice[i].Select[j].curActive) + num++; + + /* Se sono 0, e' un errore */ + if (num==0) + return NULL; + + sl= (uint32 *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(uint32)*(num+1)); + if (sl==NULL) + return NULL; + + /* Copia il dato di ogni select attivo dentro la lista */ + k=0; + for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) + if (dialog->Choice[i].Select[j].curActive) + sl[k++]=dialog->Choice[i].Select[j].dwData; + + sl[k] = (uint32)NULL; + return sl; +} + +static uint32 *GetItemList(uint32 nLoc) { + uint32 *il; + uint32 num,i,j; + LPMPALVAR v=lpmvVars; + + num=0; + for (i=0;ilpszVarName,"Location",8)==0 && v->dwVal==nLoc) + num++; + } + + il=(uint32 *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(uint32)*(num+1)); + if (il==NULL) + return NULL; + + v=lpmvVars; + j=0; + for (i=0;ilpszVarName,"Location",8)==0 && v->dwVal==nLoc) { + sscanf(v->lpszVarName,"Location.%u",&il[j]); + j++; + } + } + + il[j] = (uint32)NULL; + return il; +} + +static LPITEM GetItemData(uint32 nOrdItem) { + LPMPALITEM curitem=lpmiItems+nOrdItem; + LPITEM ret; + HGLOBAL hDat; + char *dat; + int i,j; + char *patlength; + uint32 dim; + + // Lo zeroinit e' obbligatorio!!!! + ret = (LPITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(ITEM)); + if (ret==NULL) + return NULL; + ret->speed=150; + + hDat = resLoad(curitem->dwRes); + dat = (char *)GlobalLock(hDat); + + if (dat[0]=='D' && dat[1]=='A' && dat[2]=='T') { + i=dat[3]; // Versione!! Per ora 1.0 + dat+=4; + + if (i>=0x10) { // Dalla 1.0 c'e' il punto di destinazione per ogni oggetto + ret->destX=*(uint16 *)dat; + ret->destY=*(uint16 *)(dat+2); + dat+=4; + } + + if (i>=0x11) {// Dalla 1.1 c'e' la velocita' di animazione + ret->speed=*(uint16 *)dat; + dat+=2; + } else + ret->speed=150; + } + + ret->numframe=*dat++; + ret->numpattern=*dat++; + ret->Zvalue=*dat++; + + // Carica le coordinate left&top di ogni frame + for (i=0;inumframe;i++) { + ret->frameslocations[i].left=*(short*)(dat); + ret->frameslocations[i].top=*(short*)(dat+2); + dat+=4; + } + + // Carica le dimensioni di ogni frame e calcola right&bottom + for (i=0;inumframe;i++) { + ret->frameslocations[i].right=*(uint16 *)(dat)+ret->frameslocations[i].left; + ret->frameslocations[i].bottom=*(uint16 *)(dat+2)+ret->frameslocations[i].top; + dat+=4; + } + + // Carica i bounding box di ogni frame + for (i=0;inumframe;i++) { + ret->bbox[i].left=*(uint16 *)(dat); + ret->bbox[i].top=*(uint16 *)(dat+2); + ret->bbox[i].right=*(uint16 *)(dat+4); + ret->bbox[i].bottom=*(uint16 *)(dat+6); + dat+=8; + } + + // Carica i pattern di animazione + patlength = dat; + dat+=ret->numpattern; + + for (i=1;inumpattern;i++) { + for (j=0;jpattern[i][j]=dat[j]; + ret->pattern[i][patlength[i]]=255; // Termina i pattern + dat+=patlength[i]; + } + + // Carica i singoli frame di animazione + for (i=1;inumframe;i++) { + dim=(uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left)* + (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); + ret->frames[i]=(char *)GlobalAlloc(GMEM_FIXED,dim); + + if (ret->frames[i]==NULL) + return NULL; + CopyMemory(ret->frames[i], dat, dim); + dat+=dim; + } + + // Controlla se siamo arrivati fino alla fine del file + i=*(uint16 *)dat; + if (i!=0xABCD) + return NULL; + + GlobalUnlock(hDat); + GlobalFree(hDat); + + return ret; +} + + +/****************************************************************************\ +* +* Function: void PASCAL CustomThread(LPCFCALL p); +* +* Description: Thread che richiama una funzione custom. Viene usato negli +* script, in modo che ciascuna funzione venga eseguita senza +* ritardare le altre +* +* Input: LPCFCALL p Struttura che definisce la chiamata +* +* Note: La struttura passata come parametro viene freeata con +* GlobalFree() alla fine dell'esecuzione. +* +\****************************************************************************/ + +void PASCAL CustomThread(LPCFCALL p) { + lplpFunctions[p->nCf](p->arg1,p->arg2,p->arg3,p->arg4); + GlobalFree(p); + ExitThread(1); +// _endthread(); +} + + +/****************************************************************************\ +* +* Function: void PASCAL ScriptThread(LPMPALSCRIPT s); +* +* Description: Esegue uno script. Questa funzione e' pensata come starting +* point per un thread +* +* Input: LPMPALSCRIPT s Script da eseguire +* +* Note: Lo script passato come parametro viene, alla fine dell'ese- +* cuzione, freeato con una GlobalFree() +* +\****************************************************************************/ + +void PASCAL ScriptThread(LPMPALSCRIPT s) { + uint i,j,k; + uint32 dwStartTime = timeGetTime(); + uint32 dwCurTime; + uint32 dwId; + static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT]; + int numHandles; + LPCFCALL p; + +// warning("PlayScript(): Moments: %u\n",s->nMoments); + for (i=0;inMoments;i++) { + // Dorme il tempo necessario per arrivare al momento successivo + if (s->Moment[i].dwTime==-1) { + WaitForMultipleObjects(numHandles,cfHandles,true,INFINITE); + dwStartTime=timeGetTime(); + } else { + dwCurTime=timeGetTime(); + if (dwCurTime < dwStartTime+(s->Moment[i].dwTime*100)) { + // warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); + Sleep(dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); + } + } + + numHandles=0; + for (j=0;jMoment[i].nCmds;j++) { + k=s->Moment[i].CmdNum[j]; + + switch (s->Command[k].type) { + case 1: + p=(LPCFCALL)GlobalAlloc(GMEM_FIXED,sizeof(CFCALL)); + if (p==NULL) { + mpalError=1; + ExitThread(0); +// _endthread(); + } + + p->nCf=s->Command[k].nCf; + p->arg1=s->Command[k].arg1; + p->arg2=s->Command[k].arg2; + p->arg3=s->Command[k].arg3; + p->arg4=s->Command[k].arg4; + + // !!! Nuova gestione dei thread + if ((cfHandles[numHandles++]=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)CustomThread,(void *)p,0,&dwId))==NULL) { + //if ((cfHandles[numHandles++]=(void*)_beginthread(CustomThread, 10240, (void *)p))==(void*)-1) + mpalError=1; + ExitThread(0); +// _endthread(); + } + break; + + case 2: + LockVar(); + varSetValue( + s->Command[k].lpszVarName, + EvaluateExpression(s->Command[k].expr) + ); + UnlockVar(); + break; + + default: + mpalError=1; + GlobalFree(s); + ExitThread(0); +// _endthread(); + } + } + } + + GlobalFree(s); + ExitThread(1); + //_endthread(); +} + + +/****************************************************************************\ +* +* Function: void PASCAL ActionThread(LPMPALITEM item); +* +* Description: Thread che esegue una azione su un item. Il thread +* esegue sempre l'azione 0, per cui e' necessario creare +* un item nuovo in cui l'azione 0 sia quella richiesta. +* Inoltre non viene controllata l'espressione when, ma viene +* sempre eseguita l'azione. +* +* Input: LPMPALITEM item Item che contiene l'azione +* +\****************************************************************************/ + +void PASCAL ActionThread(LPMPALITEM item) { + int j,k; + + for (j=0;jAction[item->dwRes].nCmds;j++) { + k=item->Action[item->dwRes].CmdNum[j]; + + switch (item->Command[k].type) { + case 1: + // Funzione custom + lplpFunctions[item->Command[k].nCf]( + item->Command[k].arg1, + item->Command[k].arg2, + item->Command[k].arg3, + item->Command[k].arg4 + ); + break; + + case 2: + // Variable assign + LockVar(); + varSetValue(item->Command[k].lpszVarName,EvaluateExpression(item->Command[k].expr)); + UnlockVar(); + break; + + default: + mpalError=1; + ExitThread(0); +// _endthread(); + } + } + + GlobalFree(item); + //bExecutingAction=false; + + ExitThread(1); +// _endthread(); +} + +void PASCAL ShutUpActionThread(HANDLE hThread) { + WaitForSingleObject(hThread,INFINITE); + bExecutingAction=false; + + ExitThread(1); +// _endthread(); +} + +/****************************************************************************\ +* +* Function: void PASCAL LocationPollThread(uint32 id); +* +* Description: Esegue il polling di una locazione (starting point di un +* thread). +* +* Input: uint32 id Indice per gli array relativi ai +* polling degli item delle locazioni +* +\****************************************************************************/ + +void PASCAL LocationPollThread(uint32 id) { + uint32 *il; + int i,j,k; + int numitems; + int nRealItems; + LPMPALITEM curItem,newItem; + int nIdleActions; + uint32 curTime; + uint32 dwSleepTime; + uint32 dwId; + + typedef struct { + uint32 nItem, nAction; + + uint16 wTime; + byte perc; + HGLOBAL when; + byte nCmds; + uint16 CmdNum[MAX_COMMANDS_PER_ACTION]; + + uint32 dwLastTime; + } MYACTION; + + typedef struct { + uint32 nItem; + HANDLE hThread; + } MYTHREAD; + + MYACTION *MyActions; + MYTHREAD *MyThreads; + + /* Tanto per cominciare, e' necessario richiedere la lista degli item + presenti nella locazione. */ + il = mpalQueryItemList(nPollingLocations[id]); + + /* Contiamo gli items */ + for (numitems=0;il[numitems]!=0;numitems++) + ; + + /* Cerchiamo gli items della locazione senza idle actions e li eliminiamo + dalla lista */ + LockItems(); + nIdleActions=0; + nRealItems=0; + for (i=0;inActions;j++) + if (curItem->Action[j].num==0xFF) + k++; + + nIdleActions+=k; + + if (k==0) + /* Possiamo eliminare questo item dalla lista */ + il[i] = (uint32)NULL; + else + nRealItems++; + } + UnlockItems(); + + /* Se non e' rimasto nessuno possiamo uscire */ + if (nRealItems==0) { + GlobalFree(il); + ExitThread(0); +// _endthread(); + } + + MyThreads=(MYTHREAD*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,nRealItems*sizeof(MYTHREAD)); + if (MyThreads==NULL) { + GlobalFree(il); + ExitThread(0); +// _endthread(); + } + + /* Inizializziamo le routine random */ + //curTime=timeGetTime(); + //srand(curTime); + + + /* Abbiamo appurato che esiste almeno un item che contiene idle actions. + Ora creaiamo le copie speculari delle idle actions */ + MyActions=(MYACTION*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,nIdleActions*sizeof(MYACTION)); + if (MyActions==NULL) { + GlobalFree(MyThreads); + GlobalFree(il); + ExitThread(0); +// _endthread(); + } + + LockItems(); + k=0; + + for (i=0;inActions;j++) + if (curItem->Action[j].num==0xFF) { + MyActions[k].nItem=il[i]; + MyActions[k].nAction=j; + + MyActions[k].wTime=curItem->Action[j].wTime; + MyActions[k].perc=curItem->Action[j].perc; + MyActions[k].when=curItem->Action[j].when; + MyActions[k].nCmds=curItem->Action[j].nCmds; + CopyMemory(MyActions[k].CmdNum, curItem->Action[j].CmdNum, + MAX_COMMANDS_PER_ACTION*sizeof(uint16)); + + MyActions[k].dwLastTime=timeGetTime(); + k++; + } + } + + UnlockItems(); + + /* La item list non ci serve piu' */ + GlobalFree(il); + + + /* Eccoci al ciclo principale. */ + while (1) { + /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per + l'esecuzione */ + curTime=timeGetTime(); + dwSleepTime=(uint32)-1L; + + for (k=0;k=MyActions[k].dwLastTime+MyActions[k].wTime) { + dwSleepTime=0; + break; + } else + dwSleepTime=MIN(dwSleepTime,MyActions[k].dwLastTime+MyActions[k].wTime-curTime); + + /* Ci addormentiamo, ma controllando sempre l'evento che viene settato + quando viene richiesta la nostra chiusura */ + k=WaitForSingleObject(hEndPollingLocations[id],dwSleepTime); + if (k==WAIT_OBJECT_0) + break; + + for (i=0;i=MyActions[k].dwLastTime+MyActions[k].wTime) { + MyActions[k].dwLastTime+=MyActions[k].wTime; + + /* E' il momento di tirare il nostro dado virtuale, e controllare + se la sorte e' dalla parte della idle action */ + byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); + if (randomVal < MyActions[k].perc) { + /* Controlliamo se c'e' una action in esecuzione sull'item */ + if ((bExecutingAction) && (nExecutingAction==MyActions[k].nItem)) + continue; + + /* Controlliamo se c'e' gia' un'altra idle function in esecuzione + sullo stesso item */ + for (i=0;iAction[j].when!=NULL) + if (!EvaluateExpression(curItem->Action[j].when)) { + UnlockItems(); + continue; + } + + /* Ok, possiamo eseguire la azione. Per comodita' lo facciamo in + un nuovo thread */ + newItem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALITEM)); + if (newItem==false) { + GlobalFree(MyThreads); + GlobalFree(MyActions); + ExitThread(0); +// _endthread(); + } + + CopyMemory(newItem,curItem,sizeof(MPALITEM)); + UnlockItems(); + + /* Copiamo l'azione nella #0 */ +// newItem->Action[0].nCmds=curItem->Action[j].nCmds; +// CopyMemory(newItem->Action[0].CmdNum,curItem->Action[j].CmdNum,newItem->Action[0].nCmds*sizeof(newItem->Action[0].CmdNum[0])); + newItem->dwRes=j; + + /* Creaiamo l'action thread. Provvedera' lui a liberare la memoria + allocata per il nuovo item */ + for (i=0;iGroup[i].num!=0;i++) + if (dialog->Group[i].num==nGroup) { + /* Cicla eseguendo i comandi del gruppo */ + for (j=0;jGroup[i].nCmds;j++) { + k=dialog->Group[i].CmdNum[j]; + + switch (dialog->Command[k].type) { + /* Funzione custom: la richiama */ + case 1: + lplpFunctions[dialog->Command[k].nCf]( + dialog->Command[k].arg1, + dialog->Command[k].arg2, + dialog->Command[k].arg3, + dialog->Command[k].arg4 + ); + break; + + /* Variabile: la setta */ + case 2: + LockVar(); + varSetValue(dialog->Command[k].lpszVarName,EvaluateExpression(dialog->Command[k].expr)); + UnlockVar(); + break; + + /* DoChoice: richiama la funzione di scelta */ + case 3: + DoChoice((uint32)dialog->Command[k].nChoice); + break; + + default: + mpalError=1; + UnlockDialogs(); + ExitThread(0); +// _endthread(); + } + } + + /* Abbiamo eseguito il gruppo. Possiamo uscire alla funzione chiamante. + Se il gruppo era il primo chiamato, allora automaticamente il + thread viene chiuso, altrimenti si ritorno al gruppo chiamante. */ + UnlockDialogs(); + return; + } + + /* Se siamo qui, vuol dire che non abbiamo trovato il gruppo richiesto */ + mpalError=1; + UnlockDialogs(); + ExitThread(0); +// _endthread(); +} + + +/****************************************************************************\ +* +* Function: void DoChoice(uint32 nChoice); +* +* Description: Esegue una scelta nel dialogo corrente +* +* Input: uint32 nChoice Numero della scelta da eseguire +* +\****************************************************************************/ + +void DoChoice(uint32 nChoice) { + LPMPALDIALOG dialog; + int i,j,k; + + /* Locka i dialoghi */ + LockDialogs(); + + /* Trova il puntatore al dialogo corrente */ + dialog=lpmdDialogs+nExecutingDialog; + + /* Cerca la scelta richiesta tra quelle nel dialogo */ + for (i=0;dialog->Choice[i].nChoice!=0;i++) + if (dialog->Choice[i].nChoice==nChoice) + break; + + /* Se non l'ha trovata, esce con errore */ + if (dialog->Choice[i].nChoice==0) { + /* Se siamo qui, non abbiamo trovato la choice richiesta */ + mpalError=1; + UnlockDialogs(); + ExitThread(0); +// _endthread(); + } + + /* Abbiamo trova la choice richiesta. Ricordiamoci qual e' nella + variabile globale */ + nExecutingChoice=i; + + while (1) { + nExecutingChoice=i; + + k=0; + /* Calcoliamo le when expression di ciascun select, per vedere se sono + attivi o disattivi */ + for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) + if (dialog->Choice[i].Select[j].when==NULL) { + dialog->Choice[i].Select[j].curActive=1; + k++; + } else if (EvaluateExpression(dialog->Choice[i].Select[j].when)) { + dialog->Choice[i].Select[j].curActive=1; + k++; + } else + dialog->Choice[i].Select[j].curActive=0; + + /* Se non ci sono scelte attivate, la scelta e' finita */ + if (k==0) { + UnlockDialogs(); + break; + } + + /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, + e restiamo in attesa della risposta */ + ResetEvent(hDoneChoice); + SetEvent(hAskChoice); + WaitForSingleObject(hDoneChoice,INFINITE); + + /* Ora che la scelta e' stata effettuata, possiamo eseguire i gruppi + associati con la scelta */ + j=nSelectedChoice; + for (k=0;dialog->Choice[i].Select[j].wPlayGroup[k]!=0;k++) + GroupThread(dialog->Choice[i].Select[j].wPlayGroup[k]); + + /* Controllo sugli attributi */ + if (dialog->Choice[i].Select[j].attr&(1<<0)) { + /* Bit 0 settato: fine della scelta */ + UnlockDialogs(); + break; + } + + if (dialog->Choice[i].Select[j].attr&(1<<1)) { + /* Bit 1 settato: fine del dialogo */ + UnlockDialogs(); + ExitThread(1); +// _endthread(); + } + + /* Fine della scelta senza attributi: bisogna rifarla */ + } + + /* Se siamo qui, abbiamo trovato un end choice. Ritorna al gruppo chiamante */ + return; +} + + + +/****************************************************************************\ +* +* Function: HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam); +* +* Description: Esegue una azione su un certo item +* +* Input: uint32 nAction Numero dell'azione +* uint32 ordItem Indice dell'item nelle strutture +* degli item +* uint32 dwParam Eventuale parametro per l'azione +* +* Return: Handle del thread che sta eseguendo l'azione, oppure +* INVALID_HANDLE_VALUE se l'azione non e' definita, o l'item +* e' disattivato. +* +* Note: Si puo' ottenere l'indice dell'item a partire dal suo numero +* tramite la funzione itemGetOrderFromNum(). +* Gli item devono essere lockati, perche' questa funzione +* funzioni, tramite LockItem(); +* +\****************************************************************************/ + +static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { + LPMPALITEM item=lpmiItems; + int i; + LPMPALITEM newitem; + uint32 dwId; + HANDLE h; + + item+=ordItem; + Common::String buf = Common::String::format("Status.%u", item->nObj); + if (varGetValue(buf.c_str())<=0) + return INVALID_HANDLE_VALUE; + + for (i=0;inActions;i++) { + if (item->Action[i].num!=nAction) + continue; + + if (item->Action[i].wParm!=dwParam) + continue; + + if (item->Action[i].when!=NULL) { + if (!EvaluateExpression(item->Action[i].when)) + continue; + } + + // Ora abbiamo trova l'azione giusta che deve essere eseguita. + // Duplichiamo l'item corrente e copiamo la azione #i nella #0 + newitem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALITEM)); + if (newitem==NULL) + return INVALID_HANDLE_VALUE; + + // Nella nuova versione scriviamo il numero dell'azione in dwRes + CopyMemory(newitem,item,sizeof(MPALITEM)); +/* newitem->Action[0].nCmds=item->Action[i].nCmds; + CopyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); +*/ + newitem->dwRes=i; + + // E finalmente possiamo richiamare il thread, che eseguira' l'azione + // 0 dell'item, e poi liberera' la memoria con la GlobalFree() + +/* !!! Nuova gestione dei thread +*/ + if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ActionThread,(void *)newitem,0,&dwId))==NULL) + return INVALID_HANDLE_VALUE; + + if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ShutUpActionThread,(void *)h,0,&dwId))==NULL) + return INVALID_HANDLE_VALUE; + +/* + if ((h=(void*)_beginthread(ActionThread,10240,(void *)newitem))==(void*)-1) + return INVALID_HANDLE_VALUE; + + if ((h=(void*)_beginthread(ShutUpActionThread,10240,(void *)h))==(void*)-1) + return INVALID_HANDLE_VALUE; + +*/ + nExecutingAction=item->nObj; + bExecutingAction=true; + + return h; + } + + return INVALID_HANDLE_VALUE; +} + + +/****************************************************************************\ +* +* Function: HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup); +* +* Description: Esegue un dialogo in un thread +* +* Input: uint32 nDlgOrd Indice del dialogo da eseguire +* all'interno dell'array di strutture +* dei dialoghi +* uint32 nGroup Numero del gruppo da eseguire +* +* Return: Handle del thread che sta eseguendo il dialogo, o +* INVALID_HANDLE_VALUE in caso di errore +* +* Note: Il dialogo viene eseguito in un thread creato apposta, che +* deve informa tramite un evento quando e' necessario far +* fare una scelta all'utente. I dati sulle scelte possono +* essere richiesti tramite le varie query. +* +\****************************************************************************/ + +static HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup) { +// LPMPALDIALOG dialog=lpmdDialogs+nDlgOrd; + uint32 dwId; + HANDLE h; + + /* Si ricorda nella variabile globale qual e' il dialogo in esecuzione */ + nExecutingDialog=nDlgOrd; + + /* Attiva la flag per indicare che c'e' un dialogo in esecuzione */ + bExecutingDialog=true; + + ResetEvent(hAskChoice); + ResetEvent(hDoneChoice); + + /* Crea un thread in cui esegue un gruppo del dialogo */ + + // !!! Nuova gestione dei thread + if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)GroupThread,(void *)nGroup,0,&dwId))==NULL) + // if ((h=(void*)_beginthread(GroupThread,10240,(void *)nGroup))==(void*)-1) + return INVALID_HANDLE_VALUE; + + /* Crea un thread che attende la fine del dialogo e rimette a posto le + variabili globali */ + // !!! Nuova gestione dei thread + if (CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ShutUpDialogThread,(void *)h,0,&dwId)==NULL) { + //if ((h=(void*)_beginthread(ShutUpDialogThread,10240,(void *)h))==(void*)-1) + TerminateThread(h,0); + CloseHandle(h); + return INVALID_HANDLE_VALUE; + } + + return h; +} + + +/****************************************************************************\ +* +* Function: bool DoSelection(uint32 nChoice, uint32 dwData); +* +* Description: Prende nota del select scelto dall'utente, e avverte il +* thread che stava eseguendo il dialogo che puo' continuare. +* +* Input: uint32 nChoice Numero della scelta che era in corso +* uint32 dwData Dato abbinato al select selezionato +* +* Return: true se tutto OK, false in caso di errore +* +\****************************************************************************/ + +bool DoSelection(uint32 i, uint32 dwData) { + LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; + int j; + + for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) + if (dialog->Choice[i].Select[j].dwData==dwData && dialog->Choice[i].Select[j].curActive!=0) + break; + + if (dialog->Choice[i].Select[j].dwData==0) + return false; + + nSelectedChoice=j; + SetEvent(hDoneChoice); + return true; +} + + + +/****************************************************************************\ +* Exported functions +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, +* LPLPCUSTOMFUNCTION lplpcfArray); +* +* Description: Inizializza la libreria MPAL, e apre un file .MPC, che +* verra' utilizzato per tutte le query +* +* Input: char * lpszMpcFileName Nome del file .MPC, comprensivo di +* estensione +* char * lpszMprFileName Nome del file .MPR, comprensivo di +* estensione +* LPLPCUSTOMFUNCTION +* lplpcfArray Array di pointer a funzioni custom +* +* Return: true se tutto OK, false in caso di errore +* +\****************************************************************************/ + +bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { + Common::File hMpc; + byte buf[5]; + uint32 nBytesRead; + bool bCompress; + uint32 dwSizeDecomp, dwSizeComp; + byte *cmpbuf; + + //printf("Item: %lu\n",sizeof(MPALITEM)); + //printf("Script: %lu\n",sizeof(MPALSCRIPT)); + //printf("Dialog: %lu\n",sizeof(MPALDIALOG)); + + /* Si salva l'array delle funzioni custom */ + lplpFunctions=lplpcfArray; + + /* Apre il file MPC in lettura */ + if (!hMpc.open(lpszMpcFileName)) + return false; + + /* Legge e controlla l'header */ + nBytesRead = hMpc.read(buf, 5); + if (nBytesRead !=5) + return false; + + if (buf[0]!='M' || buf[1]!='P' || buf[2]!='C' || buf[3]!=0x20) + return false; + + bCompress=buf[4]; + + /* Legge la dimensione del file decompresso, e alloca la memoria */ + dwSizeDecomp = hMpc.readUint32LE(); + if (hMpc.err()) + return false; + + lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeDecomp+16); + if (lpMpcImage==NULL) + return false; + + if (bCompress) { + /* Se il file e' compresso, guarda quanto e' grande e alloca la + memoria temporanea per la decompressione */ + dwSizeComp = hMpc.readUint32LE(); + if (nBytesRead != 4) + return false; + + cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeComp); + if (cmpbuf==NULL) + return false; + + nBytesRead = hMpc.read(cmpbuf, dwSizeComp); + if (nBytesRead != dwSizeComp) + return false; + + /* Decomprime l'immagine */ + lzo1x_decompress(cmpbuf,dwSizeComp,lpMpcImage,(lzo_uint*)&nBytesRead,NULL); + if (nBytesRead != dwSizeDecomp) + return false; + + GlobalFree(cmpbuf); + } else { + /* Se il file non e' compresso, lo legge all'interno della memoria gia' + allocata */ + nBytesRead = hMpc.read(lpMpcImage, dwSizeDecomp); + if (nBytesRead != dwSizeDecomp) + return false; + } + + /* Chiude il file */ + hMpc.close(); + + /* Parsa l'immagine */ + if (ParseMpc(lpMpcImage)==false) + return false; + + GlobalFree(lpMpcImage); + + /* Calcola utilizzo di memoria */ + /* + { + char errbuf[256]; + wsprintf(errbuf,"Utilizzo in RAM: VAR %lu, MSG %lu, DLG %lu, ITM %lu, LOC %lu, SCR %lu", + nVars*sizeof(MPALVAR), + nMsgs*sizeof(MPALMSG), + nDialogs*sizeof(MPALDIALOG), + nItems*sizeof(MPALITEM), + nLocations*sizeof(MPALLOCATION), + nScripts*sizeof(MPALSCRIPT)); + MessageBox(NULL,errbuf,"Dump",MB_OK); + } +*/ + + /* Apre il file MPR in lettura */ + if (!hMpr.open(lpszMprFileName)) + return false; + + /* Si posiziona a 8 byte dalla fine del file */ + hMpr.seek(-12, SEEK_END); + + dwSizeComp = hMpr.readUint32LE(); + if (hMpr.err()) + return false; + + nResources = hMpr.readUint32LE(); + if (hMpr.err()) + return false; + + nBytesRead = hMpr.read(buf, 4); + if (hMpr.err()) + return false; + + if (buf[0] !='E' || buf[1] != 'N' || buf[2] != 'D' || buf[3] != '0') + return false; + + /* Si posiziona all'inizio dell'header delle risorse */ + hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); + + lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nResources * 8); + if (lpResources==NULL) + return false; + + cmpbuf = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); + if (cmpbuf==NULL) + return false; + + nBytesRead = hMpr.read(cmpbuf, dwSizeComp); + if (nBytesRead != dwSizeComp) + return false; + + lzo1x_decompress((byte *)cmpbuf,dwSizeComp,(byte *)lpResources, (uint32 *)&nBytesRead, NULL); + if (nBytesRead != (uint32)nResources*8) + return false; + + GlobalFree(cmpbuf); + + /* Si riposiziona all'inizio lasciando il file di risorse aperto */ + hMpr.seek(0, SEEK_SET); + + /* Non c'e' nessuna azione ne' dialogo in esecuzione */ + bExecutingAction = false; + bExecutingDialog = false; + + /* Non c'e' nessuna locazione in polling */ + Common::fill(nPollingLocations, nPollingLocations + MAXPOLLINGLOCATIONS, 0); + + /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' + da effettuare una scelta */ + hAskChoice=CreateEvent(NULL, true, false, NULL); + hDoneChoice=CreateEvent(NULL, true, false, NULL); + + return true; +} + +/****************************************************************************\ +* +* Function: uint32 mpalQuery(uint16 wQueryType, ...); +* +* Description: Questa e' la funzione generale per comunicare con la libreria, +* per richiedere informazioni riguardo a quanto si trova nel +* file .MPC +* +* Input: uint16 wQueryType Tipo di query. La lista e' in +* enum QueryTypes +* +* Return: 4 bytes che dipendono dal tipo di query +* +* Note: E' _FORTEMENTE_ consigliato utilizzare le macro +* definite sopra per utilizzare le query, dato che +* permettono di evitare spiacevoli bug dovuti a dimenticanze +* di parametri. +* +\****************************************************************************/ + +#define GETARG(type) va_arg(v,type) + +uint32 mpalQuery(uint16 wQueryType, ...) { + uint32 dwRet; int x,y,z; char * n; + va_list v; + Common::String buf; + + mpalError=OK; + va_start(v,wQueryType); + + switch (wQueryType) { + /* + * uint32 mpalQuery(MPQ_VERSION); + */ + case MPQ_VERSION: + dwRet = HEX_VERSION; + break; + + /* + * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); + */ + case MPQ_GLOBAL_VAR: + LockVar(); + dwRet=(uint32)varGetValue(GETARG(char *)); + UnlockVar(); + break; + + /* + * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg); + */ + case MPQ_MESSAGE: + LockMsg(); + dwRet=(uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); + UnlockMsg(); + break; + + /* + * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); + */ + case MPQ_ITEM_PATTERN: + LockVar(); + buf = Common::String::format("Pattern.%u", GETARG(uint32)); + dwRet = (uint32)varGetValue(buf.c_str()); + UnlockVar(); + break; + + /* + * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); + */ + case MPQ_LOCATION_SIZE: + LockLocations(); + x=locGetOrderFromNum(GETARG(uint32)); + y=GETARG(uint32); + if (x!=-1) { + if (y==MPQ_X) + dwRet=lpmlLocations[x].dwXlen; + else if (y==MPQ_Y) + dwRet=lpmlLocations[x].dwYlen; + else + mpalError=1; + } else + mpalError=1; + UnlockLocations(); + break; + + /* + * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); + */ + case MPQ_LOCATION_IMAGE: + LockLocations(); + x=locGetOrderFromNum(GETARG(uint32)); + dwRet=(uint32)resLoad(lpmlLocations[x].dwPicRes); + UnlockLocations(); + break; + + /* + * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); + */ + case MPQ_RESOURCE: + dwRet=(uint32)resLoad(GETARG(uint32)); + break; + + /* + * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); + */ + case MPQ_ITEM_LIST: + LockVar(); + dwRet=(uint32)GetItemList(GETARG(uint32)); + LockVar(); + break; + + /* + * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); + */ + case MPQ_ITEM_DATA: + LockItems(); + dwRet=(uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); + UnlockItems(); + break; + + /* + * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); + */ + case MPQ_ITEM_IS_ACTIVE: + LockVar(); + x=GETARG(uint32); + buf = Common::String::format("Status.%u", x); + if (varGetValue(buf.c_str()) <= 0) + dwRet = (uint32)false; + else + dwRet = (uint32)true; + UnlockVar(); + break; + + + /* + * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); + */ + case MPQ_ITEM_NAME: + LockVar(); + x=GETARG(uint32); + n=GETARG(char *); + buf = Common::String::format("Status.%u", x); + if (varGetValue(buf.c_str()) <= 0) + n[0]='\0'; + else { + LockItems(); + y=itemGetOrderFromNum(x); + CopyMemory(n, (char *)(lpmiItems+y)->lpszDescribe, MAX_DESCRIBE_SIZE); + UnlockItems(); + } + + UnlockVar(); + break; + + + /* + * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); + */ + case MPQ_DIALOG_PERIOD: + LockDialogs(); + y=GETARG(uint32); + dwRet=(uint32)DuplicateDialogPeriod(y); + UnlockDialogs(); + break; + + + /* + * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); + */ + case MPQ_DIALOG_WAITFORCHOICE: + WaitForSingleObject(hAskChoice,INFINITE); + ResetEvent(hAskChoice); + + if (bExecutingDialog) + dwRet=(uint32)nExecutingChoice; + else + dwRet=(uint32)((int)-1); + break; + + + /* + * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); + */ + case MPQ_DIALOG_SELECTLIST: + LockDialogs(); + dwRet=(uint32)GetSelectList(GETARG(uint32)); + UnlockDialogs(); + break; + + /* + * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); + */ + case MPQ_DIALOG_SELECTION: + LockDialogs(); + x=GETARG(uint32); + y=GETARG(uint32); + dwRet=(uint32)DoSelection(x,y); + UnlockDialogs(); + break; + + + /* + * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam); + */ + case MPQ_DO_ACTION: + /* + if (bExecutingAction) + { + dwRet=(uint32)INVALID_HANDLE_VALUE; + break; + } + */ + + LockItems(); + LockVar(); + x=GETARG(uint32); + z=GETARG(uint32); + y=itemGetOrderFromNum(z); + if (y!=-1) { + dwRet=(uint32)DoAction(x,y,GETARG(uint32)); + } else { + dwRet=(uint32)INVALID_HANDLE_VALUE; + mpalError=1; + } + UnlockVar(); + UnlockItems(); + break; + + /* + * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); + */ + case MPQ_DO_DIALOG: + if (bExecutingDialog) + break; + + LockDialogs(); + + x=dialogGetOrderFromNum(GETARG(uint32)); + y=GETARG(uint32); + dwRet=(uint32)DoDialog(x,y); + UnlockDialogs(); + break; + + /* + * DEFAULT -> ERROR + */ + default: + mpalError=1; + break; + } + + va_end(v); + + return dwRet; +} + + +/****************************************************************************\ +* +* Function: uint32 mpalGetError(void); +* +* Description: Ritorna il codice di errore corrente di MPAL +* +* Return: Codice di errore +* +\****************************************************************************/ + +uint32 mpalGetError(void) { + return mpalError; +} + + +/****************************************************************************\ +* +* Function: void mpalExecuteScript(int nScript); +* +* Description: Esegue uno script. Lo script viene eseguito in multitasking +* tramite un thread. +* +* Input: int nScript Numero dello script da eseguire +* +* Return: true se lo script e' stato avviato, false in caso di errore +* +\****************************************************************************/ + +bool EXPORT mpalExecuteScript(int nScript) { + int n; + LPMPALSCRIPT s; + uint32 dwId; + + LockScripts(); + n=scriptGetOrderFromNum(nScript); + s=(LPMPALSCRIPT)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALSCRIPT)); + if (s==NULL) + return false; + + CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT)); + UnlockScripts(); + +// !!! Nuova gestione dei thread + if (CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s,0,&dwId)==NULL) + //if ((void*)_beginthread(ScriptThread,10240,(void *)s)==(void*)-1) + return false; + + return true; +} + + +/****************************************************************************\ +* +* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); +* +* Description: Install a custom routine that will be called by MPAL every +* time the pattern of an item has been changed. +* +* Input: LPITEMIRQFUNCTION lpiifCustom Custom function to install +* +\****************************************************************************/ + +void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { + lpiifCustom=lpiifCus; +} + + +/****************************************************************************\ +* +* Function: bool mpalStartIdlePoll(int nLoc); +* +* Description: Process the idle actions of the items on one location. +* +* Input: int nLoc Number of the location whose items +* must be processed for idle actions. +* +* Return: true se tutto OK, false se si e' superato il limite massimo. +* +* Note: Il numero massimo delle locazione che e' possibile pollare +* contemporaneamente e' contenuto nel define MAXPOLLINGFUNCIONS +* +\****************************************************************************/ + +bool EXPORT mpalStartIdlePoll(int nLoc) { + uint32 i; + uint32 dwId; + + for (i=0;iwriteString("\n

\n

\n"); + + if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { + f->writeString(Common::String::format("%s\n", MsgComments[i].pComment)); + f->writeString("

\n

\n\n"); + } else + bDontOutput=true; + return; + } +} + +void OutputEndMsgComment(uint16 wNum, Common::OutSaveFile *f) { + int i; + + for (i=0;MsgComments[i].wEnd!=0;i++) + if (MsgComments[i].wEnd == wNum) { +warning("End: %d\n", wNum); + + if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { + f->writeString("
\n

\n"); + } else + bDontOutput=false; + + f->writeString("

\n

\n\n"); + return; + } +} + + +int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { + int i; + + for (i=0;MsgComments[i].wStart!=0;i++) + if (MsgComments[i].wStart <= wNum && MsgComments[i].wEnd >= wNum) { + if (strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { + if (MsgComments[i].wStart == wNum) { + f->writeString(Common::String::format("%s\n", MsgComments[i].pComment+4)); + f->writeString("

\n

\n

\n"); + } + + return 1; + } + } + + return 0; +} + + +void OutputEndOther(uint16 wNum, Common::OutSaveFile *f) { + int i; + + for (i=0;MsgComments[i].wStart!=0;i++) + if (MsgComments[i].wEnd == wNum && strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { + f->writeString("
\n

\n"); + break; + } +} + + +void mpalDumpMessages(void) { + int i,j; + char *lpMessage; + char *p; + char *lpPeriods[30]; + char fname[64]; + char frase[2048]; + int nPeriods; + Common::OutSaveFile *f, *v1; + + v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); + + LockMsg(); + + bDontOutput=false; + + warning("Dumping MESSAGES.HTM...\n"); + + f = g_system->getSavefileManager()->openForSaving("Messages.htm"); + f->writeString("\n\n\n"); + + for (i=0;iwriteString(Common::String::format("%s\n", fname)); + f->writeString("\t\n"); + f->writeString(Common::String::format("\t\t\n", fname)); + f->writeString(Common::String::format("\t\t\n", frase)); + f->writeString("\t\n"); + } + } + + OutputEndMsgComment(lpmmMsgs[i].wNum, f); + + GlobalUnlock(lpmmMsgs[i].hText); + } + } + + f->writeString("
%s %s
\n\n\n"); + + f->finalize(); + v1->finalize(); + delete f; + delete v1; + + UnlockMsg(); +} + + + +void mpalDumpOthers(void) { + int i,j; + char *lpMessage; + char *p; + char *lpPeriods[30]; + char fname[64]; + char frase[2048]; + int nPeriods; + + Common::OutSaveFile *f, *v1; + + v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); + f = g_system->getSavefileManager()->openForSaving("Others.htm"); + LockMsg(); + + bDontOutput=false; + + warning("Dumping OTHERS.HTM...\n"); + + f->writeString("\n\n"); + + for (i=0;iwriteString(Common::String::format("%s\n", fname)); + f->writeString("\t\n"); + f->writeString(Common::String::format("\t\t %s \n", fname)); + f->writeString(Common::String::format("\t\t %s \n", frase)); + f->writeString("\t\n"); + } + } + } + + OutputEndOther(lpmmMsgs[i].wNum, f); + + GlobalUnlock(lpmmMsgs[i].hText); + } + } + + f->writeString("\n\n"); + + f->finalize(); + v1->finalize(); + + delete f; + delete v1; + UnlockMsg(); +} + + +#if 0 // English names +char *DLG10[] = { "Tony", NULL }; +char *DLG51[] = { "Tony", "Butch", "Dudley" }; +char *DLG52[] = { "Tony", NULL }; +char *DLG61[] = { "Tony", "Old lady 1", NULL }; +char *DLG71[] = { "Tony", "Timothy", "Convict", NULL, NULL, "Jack (with microphone)", "Old lady 1", NULL }; +char *DLG90[] = { "Tony", "Bearded lady", NULL }; +char *DLG110[] = { "Tony", "Lorenz", NULL }; +char *DLG111[] = { "Tony", "Lorenz", NULL }; +char *DLG130[] = { "Tony", "Piranha", NULL }; +char *DLG150[] = { "Tony", "Rufus", "Snowman", NULL }; +char *DLG151[] = { "Tony", "Rufus", "Snowman", NULL }; +char *DLG152[] = { "Tony", "Rufus", "Snowman", NULL }; +char *DLG153[] = { "Tony", "Rufus", "Snowman", NULL }; +char *DLG154[] = { "Tony", "Rufus", "Snowman", NULL }; +char *DLG160[] = { "Tony", "Shmiley", NULL }; +char *DLG161[] = { "Tony", "Shmiley", NULL }; +char *DLG162[] = { "Tony", "Shmiley", NULL }; +char *DLG163[] = { "Tony", "Shmiley", NULL }; +char *DLG180[] = { "Tony", "Beast", NULL }; +char *DLG190[] = { "Tony", "Beast", NULL }; +char *DLG191[] = { "Tony", "Beast", NULL }; +char *DLG201[] = { "Tony", NULL }; +char *DLG210[] = { "Tony", "Mortimer", NULL }; +char *DLG211[] = { "Tony", "Mortimer", NULL }; +char *DLG212[] = { "Tony", "Mortimer", NULL }; +char *DLG240[] = { "Tony", "Isabella", NULL }; +char *DLG250[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; +char *DLG251[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; +char *DLG260[] = { "Tony", "Captain", "Captain (tale)", NULL }; +char *DLG270[] = { "Tony", "Egghead", NULL }; +char *DLG271[] = { "Tony", "Egghead", NULL }; +char *DLG272[] = { "Tony", "Egghead", NULL }; +char *DLG290[] = { "Tony", "Old lady 2", NULL }; +char *DLG310[] = { "Tony", "Wally", NULL }; +char *DLG330[] = { "Tony", "Polly", "Captain (off scene)", NULL }; +char *DLG340[] = { "Tony", "Randall", NULL }; +char *DLG360[] = { "Tony", NULL }; +char *DLG361[] = { "Tony", NULL }; +char *DLG370[] = { "Tony", "Gatekeeper", NULL }; +char *DLG371[] = { "Tony", "Gatekeeper", NULL }; +char *DLG372[] = { "Tony", "Gatekeeper", NULL }; +char *DLG373[] = { "Tony", "Gatekeeper", NULL }; +char *DLG380[] = { "Tony", NULL }; +char *DLG410[] = { "Tony", "Gwendel", NULL }; +char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +char *DLG460[] = { "Tony", NULL }; +char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG480[] = { "Tony", "Pin-up", NULL }; +char *DLG490[] = { "Tony", "Gwendel", NULL }; +char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +char *DLG550[] = { "Tony", "Mr. Wishing Well", "Tony (from the top of the well)", NULL }; +char *DLG560[] = { "Tony", "Superintendent", NULL }; +char *DLG590[] = { "Tony", "Pantagruel", NULL }; +char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Storyteller", "Mr. Wishing Well", NULL }; +#endif + +#if 0 // Polish names +char *DLG10[] = { "Tony", NULL }; +char *DLG51[] = { "Tony", "Butch", "Dudley" }; +char *DLG52[] = { "Tony", NULL }; +char *DLG61[] = { "Tony", "Staruszka 1", NULL }; +char *DLG71[] = { "Tony", "Timothy", "Skazaniec", NULL, NULL, "£ebster (przez mikrofon)", "Staruszka 1", NULL }; +char *DLG90[] = { "Tony", "Kobieta z Brod¹", NULL }; +char *DLG110[] = { "Tony", "Lorenz", NULL }; +char *DLG111[] = { "Tony", "Lorenz", NULL }; +char *DLG130[] = { "Tony", "Pirania", NULL }; +char *DLG150[] = { "Tony", "Rufus", "Ba³wan", NULL }; +char *DLG151[] = { "Tony", "Rufus", "Ba³wan", NULL }; +char *DLG152[] = { "Tony", "Rufus", "Ba³wan", NULL }; +char *DLG153[] = { "Tony", "Rufus", "Ba³wan", NULL }; +char *DLG154[] = { "Tony", "Rufus", "Ba³wan", NULL }; +char *DLG160[] = { "Tony", "Œmiechozol", NULL }; +char *DLG161[] = { "Tony", "Œmiechozol", NULL }; +char *DLG162[] = { "Tony", "Œmiechozol", NULL }; +char *DLG163[] = { "Tony", "Œmiechozol", NULL }; +char *DLG180[] = { "Tony", "Wycz", NULL }; +char *DLG190[] = { "Tony", "Wycz", NULL }; +char *DLG191[] = { "Tony", "Wycz", NULL }; +char *DLG201[] = { "Tony", NULL }; +char *DLG210[] = { "Tony", "Mortimer (Okropny)", NULL }; +char *DLG211[] = { "Tony", "Mortimer (Okropny)", NULL }; +char *DLG212[] = { "Tony", "Mortimer (Okropny)", NULL }; +char *DLG240[] = { "Tony", "Isabella", NULL }; +char *DLG250[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; +char *DLG251[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; +char *DLG260[] = { "Tony", "Kapitan", "Captain (opowieœæ)", NULL }; +char *DLG270[] = { "Tony", "Jajog³owy", NULL }; +char *DLG271[] = { "Tony", "Jajog³owy", NULL }; +char *DLG272[] = { "Tony", "Jajog³owy", NULL }; +char *DLG290[] = { "Tony", "Staruszka 2", NULL }; +char *DLG310[] = { "Tony", "Wally", NULL }; +char *DLG330[] = { "Tony", "Polly", "Kapitan (zza sceny)", NULL }; +char *DLG340[] = { "Tony", "Randall", NULL }; +char *DLG360[] = { "Tony", NULL }; +char *DLG361[] = { "Tony", NULL }; +char *DLG370[] = { "Tony", "Stra¿nik", NULL }; +char *DLG371[] = { "Tony", "Stra¿nik", NULL }; +char *DLG372[] = { "Tony", "Stra¿nik", NULL }; +char *DLG373[] = { "Tony", "Stra¿nik", NULL }; +char *DLG380[] = { "Tony", NULL }; +char *DLG410[] = { "Tony", "Gwendel", NULL }; +char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Gospodyni (zza sceny)", NULL }; +char *DLG460[] = { "Tony", NULL }; +char *DLG470[] = { "Tony", "Gospodyni", "Mirror", NULL }; +char *DLG471[] = { "Tony", "Gospodyni", "Mirror", NULL }; +char *DLG472[] = { "Tony", "Gospodyni", "Mirror", NULL }; +char *DLG473[] = { "Tony", "Gospodyni", "Mirror", NULL }; +char *DLG474[] = { "Tony", "Gospodyni", "Mirror", NULL }; +char *DLG480[] = { "Tony", "Pin-up", NULL }; +char *DLG490[] = { "Tony", "Gwendel", NULL }; +char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +char *DLG550[] = { "Tony", "Pan Studnia ¯yczeñ", "Tony (nad studni¹)", NULL }; +char *DLG560[] = { "Tony", "Inspektor", NULL }; +char *DLG590[] = { "Tony", "Pantaloniarz", NULL }; +char *DLG600[] = { "Tony", "£ebster", "£ebster", NULL, "£ebster", NULL, NULL, NULL, "Narrator", "Pan Studnia ¯yczeñ", NULL }; +#endif // Polish + + +#if 0 // Russian +char *DLG10[] = { "Òîíè", NULL }; +char *DLG51[] = { "Òîíè", "Áó÷", "Äàäëè" }; +char *DLG52[] = { "Òîíè", NULL }; +char *DLG61[] = { "Òîíè", "Ñòàðóøêà 1", NULL }; +char *DLG71[] = { "Òîíè", "Òèìîòè", "Îñóæäåííûé", NULL, NULL, "Äæåê (ñ ìèêðîôîíîì)", "Ñòàðóøêà 1", NULL }; +char *DLG90[] = { "Òîíè", "Áîðîäàòàÿ æåíùèíà", NULL }; +char *DLG110[] = { "Òîíè", "Ëîðåíö", NULL }; +char *DLG111[] = { "Òîíè", "Ëîðåíö", NULL }; +char *DLG130[] = { "Òîíè", "Ïèðàíüÿ", NULL }; +char *DLG150[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +char *DLG151[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +char *DLG152[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +char *DLG153[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +char *DLG154[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +char *DLG160[] = { "Òîíè", "Øìàéëè", NULL }; +char *DLG161[] = { "Òîíè", "Øìàéëè", NULL }; +char *DLG162[] = { "Òîíè", "Øìàéëè", NULL }; +char *DLG163[] = { "Òîíè", "Øìàéëè", NULL }; +char *DLG180[] = { "Òîíè", "×óäîâèùå", NULL }; +char *DLG190[] = { "Òîíè", "×óäîâèùå", NULL }; +char *DLG191[] = { "Òîíè", "×óäîâèùå", NULL }; +char *DLG201[] = { "Òîíè", NULL }; +char *DLG210[] = { "Òîíè", "Ìîðòèìåð", NULL }; +char *DLG211[] = { "Òîíè", "Ìîðòèìåð", NULL }; +char *DLG212[] = { "Òîíè", "Ìîðòèìåð", NULL }; +char *DLG240[] = { "Òîíè", "Èçàáåëëà", NULL }; +char *DLG250[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; +char *DLG251[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; +char *DLG260[] = { "Òîíè", "Êàïèòàí", "Êàïèòàí (ðàññêàç)", NULL }; +char *DLG270[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +char *DLG271[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +char *DLG272[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +char *DLG290[] = { "Òîíè", "Ñòàðóøêà 2", NULL }; +char *DLG310[] = { "Òîíè", "Óîëëè", NULL }; +char *DLG330[] = { "Òîíè", "Ïîëëè", "Êàïèòàí (çà ñöåíîé)", NULL }; +char *DLG340[] = { "Òîíè", "Ðýíäàë", NULL }; +char *DLG360[] = { "Òîíè", NULL }; +char *DLG361[] = { "Òîíè", NULL }; +char *DLG370[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +char *DLG371[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +char *DLG372[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +char *DLG373[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +char *DLG380[] = { "Òîíè", NULL }; +char *DLG410[] = { "Òîíè", "Ãâåíäåëü", NULL }; +char *DLG430[] = { "Òîíè", "Ãàðîëüä", "×àê", "Pigeons", "Housekeeper (off scene)", NULL }; +char *DLG460[] = { "Òîíè", NULL }; +char *DLG470[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +char *DLG471[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +char *DLG472[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +char *DLG473[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +char *DLG474[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +char *DLG480[] = { "Òîíè", "Pin-up", NULL }; +char *DLG490[] = { "Òîíè", "Ãâåíäåëü", NULL }; +char *DLG530[] = { "Òîíè", "Ãàðîëüä", "×àê", NULL }; +char *DLG550[] = { "Òîíè", "Ãîñïîäèí Êîëîäåö æåëàíèé", "Òîíè (ñ âåðøèíû êîëîäöà)", NULL }; +char *DLG560[] = { "Òîíè", "Íà÷àëüíèê îõðàíû", NULL }; +char *DLG590[] = { "Òîíè", "Ïàíòàãðþýëü", NULL }; +char *DLG600[] = { "Òîíè", "Äæåê", "Äæåê", NULL, "Äæåê", NULL, NULL, NULL, "Ðàññêàç÷èê", "Ãîñïîäèí Êîëîäåö æåëàíèé", NULL }; +#endif // Russian + + +#if 0 // Czech names +char *DLG10[] = { "Tony", NULL }; +char *DLG51[] = { "Tony", "Butch", "Dudley" }; +char *DLG52[] = { "Tony", NULL }; +char *DLG61[] = { "Tony", "Stará paní 1", NULL }; +char *DLG71[] = { "Tony", "Timothy", "Trestanec", NULL, NULL, "Jack (s mikrofonem)", "Stará paní 1", NULL }; +char *DLG90[] = { "Tony", "Vousatá žena", NULL }; +char *DLG110[] = { "Tony", "Lorenz", NULL }; +char *DLG111[] = { "Tony", "Lorenz", NULL }; +char *DLG130[] = { "Tony", "Piraòa", NULL }; +char *DLG150[] = { "Tony", "Rufus", "Snìhulák", NULL }; +char *DLG151[] = { "Tony", "Rufus", "Snìhulák", NULL }; +char *DLG152[] = { "Tony", "Rufus", "Snìhulák", NULL }; +char *DLG153[] = { "Tony", "Rufus", "Snìhulák", NULL }; +char *DLG154[] = { "Tony", "Rufus", "Snìhulák", NULL }; +char *DLG160[] = { "Tony", "Shmiley", NULL }; +char *DLG161[] = { "Tony", "Shmiley", NULL }; +char *DLG162[] = { "Tony", "Shmiley", NULL }; +char *DLG163[] = { "Tony", "Shmiley", NULL }; +char *DLG180[] = { "Tony", "Zvíøe", NULL }; +char *DLG190[] = { "Tony", "Zvíøe", NULL }; +char *DLG191[] = { "Tony", "Zvíøe", NULL }; +char *DLG201[] = { "Tony", NULL }; +char *DLG210[] = { "Tony", "Mortimer", NULL }; +char *DLG211[] = { "Tony", "Mortimer", NULL }; +char *DLG212[] = { "Tony", "Mortimer", NULL }; +char *DLG240[] = { "Tony", "Isabella", NULL }; +char *DLG250[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; +char *DLG251[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; +char *DLG260[] = { "Tony", "Kapitán", "Kapitán (pøíbìh)", NULL }; +char *DLG270[] = { "Tony", "Intelektuál", NULL }; +char *DLG271[] = { "Tony", "Intelektuál", NULL }; +char *DLG272[] = { "Tony", "Intelektuál", NULL }; +char *DLG290[] = { "Tony", "Stará paní 2", NULL }; +char *DLG310[] = { "Tony", "Wally", NULL }; +char *DLG330[] = { "Tony", "Lóra", "Kapitán (mimo scénu)", NULL }; +char *DLG340[] = { "Tony", "Randall", NULL }; +char *DLG360[] = { "Tony", NULL }; +char *DLG361[] = { "Tony", NULL }; +char *DLG370[] = { "Tony", "Strážný", NULL }; +char *DLG371[] = { "Tony", "Strážný", NULL }; +char *DLG372[] = { "Tony", "Strážný", NULL }; +char *DLG373[] = { "Tony", "Strážný", NULL }; +char *DLG380[] = { "Tony", NULL }; +char *DLG410[] = { "Tony", "Gwendel", NULL }; +char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +char *DLG460[] = { "Tony", NULL }; +char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG480[] = { "Tony", "Pin-up", NULL }; +char *DLG490[] = { "Tony", "Gwendel", NULL }; +char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +char *DLG550[] = { "Tony", "Pan Studna pøání", "Tony (z vrcholu studny)", NULL }; +char *DLG560[] = { "Tony", "Správce", NULL }; +char *DLG590[] = { "Tony", "Pantagruel", NULL }; +char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Vypravìè", "Pan Studna pøání", NULL }; +#endif // Czech names + +#if 1 // Deutsch names +char *DLG10[] = { "Tony", NULL }; +char *DLG51[] = { "Tony", "Butch", "Dudley" }; +char *DLG52[] = { "Tony", NULL }; +char *DLG61[] = { "Tony", "Alte Dame 1", NULL }; +char *DLG71[] = { "Tony", "Timothy", "Sträfling", NULL, NULL, "Jack (mit Mikrofon)", "Alte Dame 1", NULL }; +char *DLG90[] = { "Tony", "Bärtige Dame", NULL }; +char *DLG110[] = { "Tony", "Lorenz", NULL }; +char *DLG111[] = { "Tony", "Lorenz", NULL }; +char *DLG130[] = { "Tony", "Piranha", NULL }; +char *DLG150[] = { "Tony", "Rufus", "Schneemann", NULL }; +char *DLG151[] = { "Tony", "Rufus", "Schneemann", NULL }; +char *DLG152[] = { "Tony", "Rufus", "Schneemann", NULL }; +char *DLG153[] = { "Tony", "Rufus", "Schneemann", NULL }; +char *DLG154[] = { "Tony", "Rufus", "Schneemann", NULL }; +char *DLG160[] = { "Tony", "Shmiley", NULL }; +char *DLG161[] = { "Tony", "Shmiley", NULL }; +char *DLG162[] = { "Tony", "Shmiley", NULL }; +char *DLG163[] = { "Tony", "Shmiley", NULL }; +char *DLG180[] = { "Tony", "Biest", NULL }; +char *DLG190[] = { "Tony", "Biest", NULL }; +char *DLG191[] = { "Tony", "Biest", NULL }; +char *DLG201[] = { "Tony", NULL }; +char *DLG210[] = { "Tony", "Mortimer", NULL }; +char *DLG211[] = { "Tony", "Mortimer", NULL }; +char *DLG212[] = { "Tony", "Mortimer", NULL }; +char *DLG240[] = { "Tony", "Isabella", NULL }; +char *DLG250[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; +char *DLG251[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; +char *DLG260[] = { "Tony", "Kapitän", "Kapitän (Erzählung)", NULL }; +char *DLG270[] = { "Tony", "Eierkopf", NULL }; +char *DLG271[] = { "Tony", "Eierkopf", NULL }; +char *DLG272[] = { "Tony", "Eierkopf", NULL }; +char *DLG290[] = { "Tony", "Alte Dame 2", NULL }; +char *DLG310[] = { "Tony", "Wally", NULL }; +char *DLG330[] = { "Tony", "Polly", "Kapitän (im Off)", NULL }; +char *DLG340[] = { "Tony", "Randall", NULL }; +char *DLG360[] = { "Tony", NULL }; +char *DLG361[] = { "Tony", NULL }; +char *DLG370[] = { "Tony", "Pförtner", NULL }; +char *DLG371[] = { "Tony", "Pförtner", NULL }; +char *DLG372[] = { "Tony", "Pförtner", NULL }; +char *DLG373[] = { "Tony", "Pförtner", NULL }; +char *DLG380[] = { "Tony", NULL }; +char *DLG410[] = { "Tony", "Gwendel", NULL }; +char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +char *DLG460[] = { "Tony", NULL }; +char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +char *DLG480[] = { "Tony", "Pin-up", NULL }; +char *DLG490[] = { "Tony", "Gwendel", NULL }; +char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +char *DLG550[] = { "Tony", "Herr Wunschbrunnen", "Tony (über dem Brunnen)", NULL }; +char *DLG560[] = { "Tony", "Verwalter", NULL }; +char *DLG590[] = { "Tony", "Pantagruel", NULL }; +char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Erzähler", "Herr Wunschbrunnen", NULL }; +#endif + + +#define HANDLE_DIALOG(num) \ +case num: \ + if (nPers >= sizeof(DLG##num) / sizeof(char*) || DLG##num[nPers]==NULL) \ + { \ + warning("ERROR: Il personaggio #%d non esiste nel dialogo %d!\n", nPers, nDlg); \ + return "ERROR"; \ + } \ + else \ + return DLG##num[nPers]; + + +char *GetPersonName(uint16 nDlg, int nPers) +{ + switch (nDlg) + { + HANDLE_DIALOG(10); + HANDLE_DIALOG(51); + HANDLE_DIALOG(52); + HANDLE_DIALOG(61); + HANDLE_DIALOG(71); + HANDLE_DIALOG(90); + HANDLE_DIALOG(110); + HANDLE_DIALOG(111); + HANDLE_DIALOG(130); + HANDLE_DIALOG(150); + HANDLE_DIALOG(151); + HANDLE_DIALOG(152); + HANDLE_DIALOG(153); + HANDLE_DIALOG(154); + HANDLE_DIALOG(160); + HANDLE_DIALOG(161); + HANDLE_DIALOG(162); + HANDLE_DIALOG(163); + HANDLE_DIALOG(180); + HANDLE_DIALOG(190); + HANDLE_DIALOG(191); + HANDLE_DIALOG(201); + HANDLE_DIALOG(210); + HANDLE_DIALOG(211); + HANDLE_DIALOG(212); + HANDLE_DIALOG(240); + HANDLE_DIALOG(250); + HANDLE_DIALOG(251); + HANDLE_DIALOG(260); + HANDLE_DIALOG(270); + HANDLE_DIALOG(271); + HANDLE_DIALOG(272); + HANDLE_DIALOG(290); + HANDLE_DIALOG(310); + HANDLE_DIALOG(330); + HANDLE_DIALOG(340); + HANDLE_DIALOG(360); + HANDLE_DIALOG(361); + HANDLE_DIALOG(370); + HANDLE_DIALOG(371); + HANDLE_DIALOG(372); + HANDLE_DIALOG(373); + HANDLE_DIALOG(380); + HANDLE_DIALOG(410); + HANDLE_DIALOG(430); + HANDLE_DIALOG(460); + HANDLE_DIALOG(470); + HANDLE_DIALOG(471); + HANDLE_DIALOG(472); + HANDLE_DIALOG(473); + HANDLE_DIALOG(474); + HANDLE_DIALOG(480); + HANDLE_DIALOG(490); + HANDLE_DIALOG(530); + HANDLE_DIALOG(550); + HANDLE_DIALOG(560); + HANDLE_DIALOG(590); + HANDLE_DIALOG(600); + + default: + warning("ERROR: Il dialogo %d non esiste!\n", nDlg); + return "ERROR"; + } +} + +void mpalDumpDialog(LPMPALDIALOG dlg) { + char dfn[64]; + char fname[64]; + int g,c,j; + struct command* curCmd; + char *frase; char *p; + char copia[2048]; + bool bAtLeastOne; + Common::OutSaveFile *f, *v1; + + v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); + + sprintf(dfn,"DIALOG%03d.HTM",dlg->nObj); + warning("Dumping %s...\n", dfn); + + f = g_system->getSavefileManager()->openForSaving(dfn); + + f->writeString("\n\n"); + + for (g=0;dlg->Group[g].num != 0; g++) { + bAtLeastOne = false; + + for (c=0;cGroup[g].nCmds; c++) { + curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; + if (curCmd->type == 1 && curCmd->nCf == 71) { + bAtLeastOne=true; + break; + } + } + + if (!bAtLeastOne) + continue; + + f->writeString(Common::String::format("

\n

Group %d

\n

\n", g)); + f->writeString("\n"); + + for (c=0;cGroup[g].nCmds; c++) { + curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; + + // Se è una funzione custom, e richiama la SendDialogMessage(nPers, nMsg) + if (curCmd->type == 1 && curCmd->nCf == 71) { + sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->arg2); + + for (j=0;dlg->Periods[j]!=NULL;j++) + if (dlg->PeriodNums[j] == curCmd->arg2) + break; + + if (dlg->Periods[j]==NULL) + warning("ERROR: Dialogo %d, Periodo %d non trovato!\n", (int)dlg->nObj, (int)curCmd->arg2); + else { + frase = (char *)GlobalLock(dlg->Periods[j]); + strcpy(copia, frase); + GlobalUnlock(dlg->Periods[j]); + + while ((p=strchr(copia,'^')) != NULL) + *p = '\"'; + + p = frase; + while (*p == ' ') p++; + if (*p == '\0') + continue; + + v1->writeString(Common::String::format("%s\n", fname)); + f->writeString("\t\n"); + f->writeString(Common::String::format("\t\t\n", fname)); + f->writeString(Common::String::format("\t\t\n", + GetPersonName(dlg->nObj, curCmd->arg1))); + f->writeString(Common::String::format("\t\t\n",copia)); + f->writeString("\t\n"); + //fprintf(f, "(%s) <%s> %s\n", fname, GetPersonName(dlg->nObj, curCmd->arg1), copia); + } + } + } + + f->writeString("
%s %s %s

\n"); + //fprintf(f,"\n\n\n\n"); + } + + f->finalize(); + v1->finalize(); + delete f; + delete v1; +} + +void mpalDumpDialogs(void) { + int i; + + LockDialogs(); + + for (i=0;i '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Main Include file for * + * 4> ^R$oue# d using MPAL.DLL......... * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + + +/****************************************************************************\ +* Copyright Notice +\****************************************************************************/ + +/* + * A Spyral Software Production: + * + * MPAL - MultiPurpose Adventure Language + * (C) 1997 Giovanni Bajo and Luca Giusti + * ALL RIGHTS RESERVED + * + * + */ + + +/****************************************************************************\ +* General Introduction +\****************************************************************************/ + +/* + * MPAL (MultiPurpose Adventure Language) is a high level language + * for the definition of adventure. Through the use of MPAL you can describe + * storyboard the adventure, and then use it with any user interface. + * In fact, unlike many other similar products, MPAL is not programmed through + * the whole adventure, but are defined only the locations, objects, as they may + * interact with each other, etc.. thus making MPAL useful for any type of adventure. + */ + +/****************************************************************************\ +* Structure +\****************************************************************************/ + +/* + * MPAL consists of two main files: MPAL.DLL and MPAL.H + * The first is the DLL that contains the code to interface with MPAL + * adventures, the second is the header that defines the prototypes + * functions. MPAL is compiled for Win32, and it can therefore be used with + * any compiler that supports Win32 DLL (Watcom C++, Visual C++, + * Delphi, etc.), and therefore compatible with both Windows 95 and Windows NT. + * + * To use the DLL, and 'obviously need to create a library for symbols to export. + * + */ + + +/****************************************************************************\ +* Custom Functions +\****************************************************************************/ + +/* + * A custom function and a function specified by the program that uses the + * library, to perform the particular code. The custom functions are + * retrieved from the library as specified in the source MPAL, and in particular + * in defining the behavior of an item with some action. + * + * To use the custom functions, you need to prepare an array of + * pointers to functions (such as using the type casting LPCUSTOMFUNCTION, + * (defined below), and pass it as second parameter to mpalInit (). Note you + * must specify the size of the array, as elements of pointers and which do not + * contain the same: the library will call it only those functions specified in + * the source MPAL. It can be useful, for debugging reasons, do not bet + * the shares of arrays used to debugging function, to avoid unpleasant crash, + * if it has been made an error in source and / or some oversight in the code. + * + */ + +#ifndef __MPAL_H +#define __MPAL_H + +#include "common/scummsys.h" +#include "common/rect.h" + +/****************************************************************************\ +* Macro definitions and structures +\****************************************************************************/ + +/* OK value for the error codes */ +#define OK 0 + +#define MAXFRAMES 400 // frame animation of an object +#define MAXPATTERN 40 // pattern of animation of an object + +#define MAXPOLLINGLOCATIONS 64 + +#define EXPORT +#define LPSTR char * + +/****************************************************************************\ +* enum QueryCoordinates +* --------------------- +* Description: Macro for use with queries that may refer to X and Y co-ordinates +\****************************************************************************/ + +enum QueryCoordinates { + MPQ_X, + MPQ_Y +}; + + +/****************************************************************************\ +* enum QueryTypes +* --------------- +* Description: Query can be used with mpalQuery (). In practice corresponds +* all claims that can do at the library +\****************************************************************************/ + +enum QueryTypes { + /* General Query */ + MPQ_VERSION=10, + + MPQ_GLOBAL_VAR=50, + MPQ_RESOURCE, + MPQ_MESSAGE, + + /* Query on leases */ + MPQ_LOCATION_IMAGE=100, + MPQ_LOCATION_SIZE, + + /* Queries about items */ + MPQ_ITEM_LIST=200, + MPQ_ITEM_DATA, + MPQ_ITEM_PATTERN, + MPQ_ITEM_NAME, + MPQ_ITEM_IS_ACTIVE, + + /* Query dialog */ + MPQ_DIALOG_PERIOD=300, + MPQ_DIALOG_WAITFORCHOICE, + MPQ_DIALOG_SELECTLIST, + MPQ_DIALOG_SELECTION, + + /* Query execution */ + MPQ_DO_ACTION=400, + MPQ_DO_DIALOG +}; + + +/****************************************************************************\ +* typedef ITEM +* ------------ +* Description: Framework to manage the animation of an item +\****************************************************************************/ + +typedef struct { + char *frames[MAXFRAMES]; + Common::Rect frameslocations[MAXFRAMES]; + Common::Rect bbox[MAXFRAMES]; + short pattern[MAXPATTERN][MAXFRAMES]; + short speed; + char numframe; + char numpattern; + char curframe; + char curpattern; + short destX, destY; + signed char Zvalue; + short objectID; + char TAG; +} ITEM; +typedef ITEM *LPITEM; + + +/****************************************************************************\ +* typedef LPCUSTOMFUNCTION +* ------------------------ +* Description: Define a custom function, to use the language MPAL +* to perform various controls as a result of an action +\****************************************************************************/ + +typedef void (*LPCUSTOMFUNCTION)(uint32, uint32, uint32, uint32); +typedef LPCUSTOMFUNCTION *LPLPCUSTOMFUNCTION; + + +/****************************************************************************\ +* typedef LPITEMIRQFUNCTION +* ------------------------- +* Description: Define an IRQ of an item that is called when the +* pattern changes or the status of an item +\****************************************************************************/ + +typedef void (*LPITEMIRQFUNCTION)(uint32, int, int); +typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; + + +/****************************************************************************\ +* Macrofunctions query +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: uint32 mpalQueryVersion(void); +* +* Description: Gets the current version of MPAL +* +* Return: Version number (0x1232 = 1.2.3b) +* +\****************************************************************************/ + +#define mpalQueryVersion() \ + (uint16)mpalQuery(MPQ_VERSION) + + + +/****************************************************************************\ +* +* Function: uint32 mpalQueryGlobalVar(LPSTR lpszVarName); +* +* Description: Gets the numerical value of a global variable +* +* Input: LPSTR lpszVarName Nome della variabile (ASCIIZ) +* +* Return: Valore della variabile +* +* Note: This query was implemented for debugging. The program, +* if well designed, should not need to access variables from +* within the library. +* +\****************************************************************************/ + +#define mpalQueryGlobalVar(lpszVarName) \ + (uint32)mpalQuery(MPQ_GLOBAL_VAR,(LPSTR)(lpszVarName)) + + + +/****************************************************************************\ +* +* Function: HGLOBAL mpalQueryResource(uint32 dwResId); +* +* Description: Provides access to a resource inside the .MPC file +* +* Input: uint32 dwResId ID della risorsa +* +* Return: Handle to a memory area containing the resource, +* ready for use. +* +\****************************************************************************/ + +#define mpalQueryResource(dwResId) \ + (HGLOBAL)mpalQuery(MPQ_RESOURCE,(uint32)(dwResId)) + + + +/****************************************************************************\ +* +* Function: LPSTR mpalQueryMessage(uint32 nMsg); +* +* Description: Returns a message. +* +* Input: uint32 nMsg Message number +* +* Return: ASCIIZ message +* +* Note: The returned pointer must be freed with GlobalFree() +* after use. The message will be in ASCIIZ format. +* +\****************************************************************************/ + +#define mpalQueryMessage(nMsg) \ + (LPSTR)mpalQuery(MPQ_MESSAGE,(uint32)(nMsg)) + + + +/****************************************************************************\ +* +* Function: HGLOBAL mpalQueryLocationImage(uint32 nLoc); +* +* Description: Provides a image image +* +* Input: uint32 nLoc Locazion number +* +* Return: Returns a picture handle +* +\****************************************************************************/ + +#define mpalQueryLocationImage(nLoc) \ + (HGLOBAL)mpalQuery(MPQ_LOCATION_IMAGE,(uint32)(nLoc)) + + + +/****************************************************************************\ +* +* Function: uint32 mpalQueryLocationSize(uint32 nLoc, uint32 dwCoord); +* +* Description: Request the x or y size of a location in pixels +* +* Input: uint32 nLoc Location number +* uint32 dwCoord MPQ_Xr o MPQ_Y +* +* Return: Size +* +\****************************************************************************/ + +#define mpalQueryLocationSize(nLoc,dwCoord) \ + (uint32)mpalQuery(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord)) + + + +/****************************************************************************\ +* +* Function: uint32 * mpalQueryItemList(uint32 nLoc); +* +* Description: Provides the list of objects in the lease. +* +* Input: uint32 nLoc Location number +* +* Return: List of objects (accessible by Item [0], Item [1], etc.) +* +\****************************************************************************/ + +#define mpalQueryItemList(nLoc) \ + (uint32 *)mpalQuery(MPQ_ITEM_LIST,(uint32)(nLoc)) + + + +/****************************************************************************\ +* +* Function: LPBKGANIM mpalQueryItemData(uint32 nItem); +* +* Description: Provides information on an item +*e +* Input: uint32 nItem Item number +* +* Return: structure filled with requested information +* +\****************************************************************************/ + +#define mpalQueryItemData(nItem) \ + (LPITEM)mpalQuery(MPQ_ITEM_DATA,(uint32)(nItem)) + + + +/****************************************************************************\ +* +* Function: uint32 mpalQueryItemPattern(uint32 nItem); +* +* Description: Provides the current pattern of an item +* +* Input: uint32 nItem Item number +* +* Return: Number of animation patterns to be executed. +* +* Note: By default, the pattern of 0 indicates that we should +* do nothing. +* +\****************************************************************************/ + +#define mpalQueryItemPattern(nItem) \ + (uint32)mpalQuery(MPQ_ITEM_PATTERN,(uint32)(nItem)) + + + +/****************************************************************************\ +* +* Function: bool mpalQueryItemIsActive(uint32 nItem); +* +* Description: Returns true if an item is active +* +* Input: uint32 nItem Item number +* +* Return: TRUE if the item is active, FALSE otherwise +* +\****************************************************************************/ + +#define mpalQueryItemIsActive(nItem) \ + (bool)mpalQuery(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem)) + + +/****************************************************************************\ +* +* Function: void mpalQueryItemName(uint32 nItem, LPSTR lpszName); +* +* Description: Returns the name of an item +* +* Input: uint32 nItem Item number +* LPSTR lpszName Pointer to a buffer of at least 33 bytes +* that will be filled with the name +* +* Note: If the item is not active (ie. if its status or number +* is less than or equal to 0), the string will be empty. +* +\****************************************************************************/ + +#define mpalQueryItemName(nItem,lpszName) \ + (uint32)mpalQuery(MPQ_ITEM_NAME,(uint32)(nItem),(LPSTR)(lpszName)) + + + +/****************************************************************************\ +* +* Function: LPSTR mpalQueryDialogPeriod(uint32 nDialog, uint32 nPeriod); +* +* Description: Returns a sentence of dialog. +* +* Input: uint32 nDialog Dialog number +* uint32 nPeriod Number of words +* +* Return: A pointer to the string of words, or NULL on failure. +* +* Note: The string must be freed after use by GlobalFree (). +* +* Unlike normal messages, the sentences of dialogue +* are formed by a single string terminated with 0. +* +\****************************************************************************/ + +#define mpalQueryDialogPeriod(nPeriod) \ + (LPSTR)mpalQuery(MPQ_DIALOG_PERIOD,(uint32)(nPeriod)) + + + +/****************************************************************************\ +* +* Function: int mpalQueryDialogWaitForChoice(void); +* +* Description: Wait until the moment in which the need is signaled +* to make a choice by the user. +* +* Return: Number of choice to be made, or -1 if the dialogue is finished. +* +\****************************************************************************/ + +#define mpalQueryDialogWaitForChoice() \ + (int)mpalQuery(MPQ_DIALOG_WAITFORCHOICE) + + + +/****************************************************************************\ +* +* Function: uint32 * mpalQueryDialogSelectList(uint32 nChoice); +* +* Description: Requires a list of various options for some choice within +* the current dialog. + +* Input: uint32 nChoice Choice number +* +* Return: A pointer to an array containing the data matched to each option. +* +* Note: The figure 'a uint32 specified in the source to which MPAL +* You can 'assign meaning that the more' suits. +* +* The pointer msut be freed after use by GlobalFree(). +* +\****************************************************************************/ + +#define mpalQueryDialogSelectList(nChoice) \ + (uint32 *)mpalQuery(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice)) + + + +/****************************************************************************\ +* +* Function: bool mpalQueryDialogSelection(uint32 nChoice, uint32 dwData); +* +* Description: Warns the library that the user has selected, in a certain +* choice of the current dialog, corresponding option +* at a certain given. +* +* Input: uint32 nChoice Choice number of the choice that +* was in progress +* uint32 dwData Option that was selected by the user. +* +* Return: TRUE if all OK, FALSE on failure. +* +* Note: After execution of this query, MPAL continue +* Groups according to the execution of the dialogue. And necessary so the game +* remains on hold again for another Chosen by mpalQueryDialogWaitForChoice (). +* +\****************************************************************************/ + +#define mpalQueryDialogSelection(nChoice,dwData) \ + (bool)mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) + + + +/****************************************************************************\ +* +* Function: HANDLE mpalQueryDoAction(uint32 nAction, uint32 nItem, +* uint32 dwParam); +* +* Description: Warns the library an action was performed on a Object. +* The library will call 'custom functions, if necessary. +* +* Input: uint32 nAction Action number +* uint32 nItem Item number +* uint32 dwParam Action parameter +* +* Return: Handle to the thread that is performing the action, or +* INVALID_HANDLE_VALUE if the action is not 'defined for +* the item, or the item and 'off. +* +* Note: The parameter is used primarily to implement actions +* as "U.S." involving two objects together. The action will be executed only +* if the item is active, ie if its status is a positive number greater than 0. +* +\****************************************************************************/ + +#define mpalQueryDoAction(nAction,nItem,dwParam) \ + (HANDLE)mpalQuery(MPQ_DO_ACTION,(uint32)(nAction),(uint32)(nItem),(uint32)(dwParam)) + + + +/****************************************************************************\ +* +* Function: HANDLE mpalQueryDoDialog(uint32 nDialog, uint32 nGroup); +* +* Description: Warns the library a dialogue was required. +* +* Input: uint32 nDialog Dialog number +* uint32 nGroup Group number to use +* +* Return: Handle to the thread that is running the box, or +* INVALID_HANDLE_VALUE if the dialogue does not exist. +* +\****************************************************************************/ + +#define mpalQueryDoDialog(nDialog,nGroup) \ + (HANDLE)mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup)) + + + +/****************************************************************************\ +* Functions exported DLL +\****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************\ +* +* Function: bool mpalInit(LPSTR lpszMpcFileName, LPSTR lpszMprFileName, +* LPLPCUSTOMFUNCTION lplpcfArray); +* +* Description: Initializes the MPAL library, and opens an .MPC file, which +* will be 'used for all queries +* +* Input: LPSTR lpszMpcFileName Name of the .MPC file, including extension +* LPSTR lpszMprFileName Name of the .MPR file, including extension +* LPLPCUSTOMFUNCTION Array of pointers to custom functions +* +* Return: TRUE if all OK, FALSE on failure +* +\****************************************************************************/ + +bool EXPORT mpalInit(LPSTR lpszFileName, LPSTR lpszMprFileName, + LPLPCUSTOMFUNCTION lplpcfArray); + + + +/****************************************************************************\ +* +* Function: uint32 mpalQuery(uint16 wQueryType, ...); +* +* Description: This is the general function to communicate with the library, +* To request information about what is in the .MPC file +* +* Input: uint16 wQueryType Type of query. The list is in +* the QueryTypes enum. +* +* Return: 4 bytes depending on the type of query +* +* Note: I _strongly_ recommended to use macros defined above to use +* the query, since it helps avoid any unpleasant bugs due to +* forgeting parameters. +* +\****************************************************************************/ + +uint32 EXPORT mpalQuery(uint16 wQueryType, ...); + + + +/****************************************************************************\ +* +* Function: bool mpalExecuteScript(int nScript); +* +* Description: Execute a script. The script runs on multitasking by a thread. +* +* Input: int nScript Script number to run +* +* Return: TRUE if the script 'was launched, FALSE on failure +* +\****************************************************************************/ + +bool EXPORT mpalExecuteScript(int nScript); + + + +/****************************************************************************\ +* +* Function: uint32 mpalGetError(void); +* +* Description: Returns the current MPAL error code +* +* Return: Error code +* +\****************************************************************************/ + +uint32 EXPORT mpalGetError(void); + + + +/****************************************************************************\ +* +* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); +* +* Description: Install a custom routine That will be called by MPAL +* every time the pattern of an item has-been changed. +* +* Input: LPITEMIRQFUNCTION lpiifCustom Custom function to install +* +\****************************************************************************/ + +void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); + + +/****************************************************************************\ +* +* Function: bool mpalStartIdlePoll(int nLoc); +* +* Description: Process the idle actions of the items on one location. +* +* Input: int nLoc Number of the location whose items +* must be processed for idle actions. +* +* Return: TRUE if all OK, and FALSE if it exceeded the maximum limit. +* +* Note: The maximum number of locations that can be polled +* simultaneously is defined defined by MAXPOLLINGFUNCIONS +* +\****************************************************************************/ + +bool EXPORT mpalStartIdlePoll(int nLoc); + + +/****************************************************************************\ +* +* Function: bool mpalEndIdlePoll(int nLoc); +* +* Description: Stop processing the idle actions of the items on one location. +* +* Input: int nLoc Number of the location +* +* Return: TRUE if all OK, FALSE if the specified location was not +* in the process of polling +* +\****************************************************************************/ + +bool EXPORT mpalEndIdlePoll(int nLoc); + + + +/****************************************************************************\ +* +* Function: int mpalLoadState(LPBYTE buf); +* +* Description: Load a save state from a buffer. +* +* Input: LPBYTE buf Buffer where to store the state +* +* Return: Length of the state in bytes +* +\****************************************************************************/ + +int EXPORT mpalLoadState(byte *buf); + + + +/****************************************************************************\ +* +* Function: void mpalSaveState(LPBYTE buf); +* +* Description: Store the save state into a buffer. The buffer must be +* length at least the size specified with mpalGetSaveStateSize +* +* Input: LPBYTE buf Buffer where to store the state +* +\****************************************************************************/ + +void EXPORT mpalSaveState(byte *buf); + + + +/****************************************************************************\ +* +* Function: int mpalGetSaveStateSize(void); +* +* Description: Acquire the length of a save state +* +* Return: Length in bytes +* +\****************************************************************************/ + +int EXPORT mpalGetSaveStateSize(void); + +#ifdef __cplusplus +} +#endif + +/****************************************************************************\ +* +* Function: void LockVar(void); +* +* Description: Locka le variabili per accederci +* +\****************************************************************************/ + +extern void LockVar(void); + +/****************************************************************************\ +* +* Function: void UnlockVar(void); +* +* Description: Unlocka le variabili dopo l'uso +* +\****************************************************************************/ + +extern void UnlockVar(void); + +#endif + diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h new file mode 100644 index 0000000000..8a52f1ed90 --- /dev/null +++ b/engines/tony/mpal/mpaldll.h @@ -0,0 +1,418 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/************************************************************************** + * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * ... Spyral Software snc * + * . x#""*$Nu -= We create much MORE than ALL =- * + * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * .F ^$k $ "$b * + * ." $b u "$ #$L * + * P $c :*$L"$L '$k Project: MPAL................... * + * d @$N. $. d ^$b^$k $c * + * F 4 "$c '$ $ #$u#$u '$ Module: MPAL DLL Header........ * + * 4 4k *N #b .> '$N'*$u * * + * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * + * M '$u "$u :" *$. "#*#" * + * M '$N. " F ^$k Desc: Header per i moduli per * + * 4> ^R$oue# d la DLL di query di MPAL * + * '$ "" @ ....................... * + * #b u# * + * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * + * #$u .d" * + * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * "*$$beooee$*" @"M This source code is * + * """ '$.? Copyright (C) Spyral Software * + * '$d> ALL RIGHTS RESERVED * + * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * + * * + **************************************************************************/ + +#ifndef __MPALDLL_H +#define __MPALDLL_H + +#include "common/file.h" +#include "stubs.h" + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* Defines +\****************************************************************************/ + +#define HEX_VERSION 0x0170 + +/* + SICURA + +#define MAX_ACTIONS_PER_ITEM 40 +#define MAX_COMMANDS_PER_ITEM 256 +#define MAX_COMMANDS_PER_ACTION 64 +#define MAX_DESCRIBE_SIZE 128 +*/ + +#define MAX_ACTIONS_PER_ITEM 40 +#define MAX_COMMANDS_PER_ITEM 128 +#define MAX_COMMANDS_PER_ACTION 128 +#define MAX_DESCRIBE_SIZE 64 + + + +#define MAX_MOMENTS_PER_SCRIPT 256 +#define MAX_COMMANDS_PER_SCRIPT 256 +#define MAX_COMMANDS_PER_MOMENT 32 + + + + + +/* + Versione sicura! + +#define MAX_GROUPS_PER_DIALOG 128 +#define MAX_COMMANDS_PER_DIALOG 640 +#define MAX_COMMANDS_PER_GROUP 64 +#define MAX_CHOICES_PER_DIALOG 64 +#define MAX_SELECTS_PER_CHOICE 33 +#define MAX_PLAYGROUPS_PER_SELECT 9 +#define MAX_PERIODS_PER_DIALOG 640 + +*/ + +#define MAX_GROUPS_PER_DIALOG 128 +#define MAX_COMMANDS_PER_DIALOG 480 +#define MAX_COMMANDS_PER_GROUP 64 +#define MAX_CHOICES_PER_DIALOG 64 +#define MAX_SELECTS_PER_CHOICE 64 +#define MAX_PLAYGROUPS_PER_SELECT 9 +#define MAX_PERIODS_PER_DIALOG 400 + +/* + Prima di Rufus: + +#define MAX_GROUPS_PER_DIALOG 128 +#define MAX_COMMANDS_PER_DIALOG 512 +#define MAX_COMMANDS_PER_GROUP 32 +#define MAX_CHOICES_PER_DIALOG 64 +#define MAX_SELECTS_PER_CHOICE 32 +#define MAX_PLAYGROUPS_PER_SELECT 4 +#define MAX_PERIODS_PER_DIALOG 512 +*/ + +#define NEED_LOCK_MSGS + + +/****************************************************************************\ +* Strutture +\****************************************************************************/ + +#include "common/pack-start.h" + +/****************************************************************************\ +* typedef MPALVAR +* --------------- +* Description: Variabile globale di MPAL +\****************************************************************************/ + +struct MPALVAR { + uint32 dwVal; // Valore della variabile + char lpszVarName[33]; // Nome della variabile +} PACKED_STRUCT; +typedef MPALVAR* LPMPALVAR; +typedef LPMPALVAR* LPLPMPALVAR; + + +/****************************************************************************\ +* typedef MPALMSG +* --------------- +* Description: Messaggio di MPAL +\****************************************************************************/ + +struct MPALMSG { + HGLOBAL hText; // Handle al testo del messaggio + uint16 wNum; // Numero del messaggio +} PACKED_STRUCT; +typedef MPALMSG* LPMPALMSG; +typedef LPMPALMSG* LPLPMPALMSG; + + +/****************************************************************************\ +* typedef MPALLOCATION +* -------------------- +* Description: Locazione di MPAL +\****************************************************************************/ + +struct MPALLOCATION { + uint32 nObj; // Numero della locazione + uint32 dwXlen, dwYlen; // Dimensione + uint32 dwPicRes; // Risorsa che contiene l'immagine +} PACKED_STRUCT; +typedef MPALLOCATION* LPMPALLOCATION; +typedef LPMPALLOCATION* LPLPMPALLOCATION; + + +/****************************************************************************\ +* struct command +* -------------- +* Description: Gestisce un comando, cioe' le tag utilizzate dalle OnAction +* negli item, dalle Time negli script e dai Group nei Dialog +\****************************************************************************/ + +struct command { + /* + * Tipi di comandi riconosciuti: + * + * #1 -> Chiamata a funzione custom (ITEM, SCRIPT, DIALOG) + * #2 -> Assegnazione di variabile (ITEM, SCRIPT, DIALOG) + * #3 -> Esecuzione di una scelta (DIALOG) + * + */ + byte type; // Tipo di comando + + union { + int32 nCf; // Numero funzione custom [#1] + char *lpszVarName; // Nome variabile [#2] + int32 nChoice; // Numero di scelta da fare [#3] + }; + + union { + int32 arg1; // Argomento 1 funzione custom [#1] + HGLOBAL expr; // Espressione da assegnare alla + // variabile [#2] + }; + + int32 arg2,arg3,arg4; // Argomenti per funzione custom [#1] +} PACKED_STRUCT; + +/****************************************************************************\ +* typedef MPALDIALOG +* ------------------ +* Description: Dialog di MPAL +\****************************************************************************/ + +struct MPALDIALOG { + uint32 nObj; // Numero dialog + + struct command Command[MAX_COMMANDS_PER_DIALOG]; + + struct { + uint16 num; + + byte nCmds; + uint16 CmdNum[MAX_COMMANDS_PER_GROUP]; + + } Group[MAX_GROUPS_PER_DIALOG]; + + struct { + // L'ultima choice ha nChoice==0 + uint16 nChoice; + + // Non c'e' il numero di Select (siamo abbastanza avari di RAM). L'ultimo + // select ha dwData==0 + struct { + HGLOBAL when; + uint32 dwData; + uint16 wPlayGroup[MAX_PLAYGROUPS_PER_SELECT]; + + // Bit 0=endchoice Bit 1=enddialog + byte attr; + + // Modificata a run-time: 0 se il select e' correntemente disabilitato, + // 1 se e' correntemente attivato + byte curActive; + } Select[MAX_SELECTS_PER_CHOICE]; + + } Choice[MAX_CHOICES_PER_DIALOG]; + + uint16 PeriodNums[MAX_PERIODS_PER_DIALOG]; + HGLOBAL Periods[MAX_PERIODS_PER_DIALOG]; + +} PACKED_STRUCT; +typedef MPALDIALOG* LPMPALDIALOG; +typedef LPMPALDIALOG* LPLPMPALDIALOG; + +/****************************************************************************\ +* typedef MPALITEM +* ---------------- +* Description: Item di MPAL +\****************************************************************************/ + +struct ItemAction { + byte num; // Numero dell'azione + uint16 wTime; // In caso di idle, il tempo che deve passare + byte perc; // Percentuale di eseguire l'idle + HGLOBAL when; // Espressione da calcolare: se !=0, allora + // l'azione puo' essere eseguita + uint16 wParm; // Parametro per l'azione + + byte nCmds; // Numero comandi da eseguire + uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Comando da eseguire +} PACKED_STRUCT; + +struct MPALITEM { + uint32 nObj; // Numero item + + byte lpszDescribe[MAX_DESCRIBE_SIZE]; // Nome + byte nActions; // Numero delle azioni gestite + uint32 dwRes; // Risorsa che contiene frame e pattern + + struct command Command[MAX_COMMANDS_PER_ITEM]; + + // Array di strutture contenenti le varie azioni gestite. In pratica, di + // ogni azione sappiamo quali comandi eseguire, tra quelli definiti nella + // struttura qui sopra +/* + struct + { + byte num; // Numero dell'azione + uint16 wTime; // In caso di idle, il tempo che deve passare + byte perc; // Percentuale di eseguire l'idle + HGLOBAL when; // Espressione da calcolare: se !=0, allora + // l'azione puo' essere eseguita + uint16 wParm; // Parametro per l'azione + + byte nCmds; // Numero comandi da eseguire + uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Comando da eseguire + + } Action[MAX_ACTIONS_PER_ITEM]; + */ + struct ItemAction *Action; + +} PACKED_STRUCT; +typedef MPALITEM* LPMPALITEM; +typedef LPMPALITEM* LPLPMPALITEM; + + +/****************************************************************************\ +* typedef MPALSCRIPT +* ------------------ +* Description: Script di MPAL +\****************************************************************************/ + +struct MPALSCRIPT { + uint32 nObj; + + uint32 nMoments; + + struct command Command[MAX_COMMANDS_PER_SCRIPT]; + + struct { + int32 dwTime; + + byte nCmds; + uint32 CmdNum[MAX_COMMANDS_PER_MOMENT]; + + } Moment[MAX_MOMENTS_PER_SCRIPT]; + +} PACKED_STRUCT; +typedef MPALSCRIPT* LPMPALSCRIPT; +typedef LPMPALSCRIPT* LPLPMPALSCRIPT; + +#include "common/pack-end.h" + +/****************************************************************************\ +* Variabili globali +\****************************************************************************/ + +extern uint32 mpalError; +extern LPLPCUSTOMFUNCTION lplpFunctions; +extern uint16 nObjs; + +extern uint16 nVars; +extern HGLOBAL hVars; +extern LPMPALVAR lpmvVars; + +extern uint16 nMsgs; +extern HGLOBAL hMsgs; +extern LPMPALMSG lpmmMsgs; + +extern uint16 nDialogs; +extern HGLOBAL hDialogs; +extern LPMPALDIALOG lpmdDialogs; + +extern uint16 nItems; +extern HGLOBAL hItems; +extern LPMPALITEM lpmiItems; + +extern uint16 nLocations; +extern HGLOBAL hLocations; +extern LPMPALLOCATION lpmlLocations; + +extern uint16 nScripts; +extern HGLOBAL hScripts; +extern LPMPALSCRIPT lpmsScripts; + +extern Common::File hMpr; +extern uint16 nResources; +extern uint32 * lpResources; + +/****************************************************************************\ +* Prototipi di funzione +\****************************************************************************/ + +/****************************************************************************\ +* +* Function: int32 varGetValue(const char *lpszVarName); +* +* Description: Restituisce il valore corrente di una variabile globale +* +* Input: const char *lpszVarName Nome della variabile +* +* Return: Valore corrente +* +* Note: Prima di questa funzione, bisogna richiamare LockVar() che +* locka le variabili globali per l'utilizzo. Dopo inoltre bi- +* sogna ricordarsi di chiamare UnlockVar() +* +\****************************************************************************/ + +int32 varGetValue(const char *lpszVarName); + + +/****************************************************************************\ +* +* Function: void varSetValue(const char *lpszVarName, int32 val); +* +* Description: Setta un nuovo valore per una variabile globale di MPAL +* +* Input: const char *lpszVarName Nome della variabile +* int32 val Valore da settare +* +\****************************************************************************/ + +void varSetValue(const char *lpszVarName, int32 val); + +/****************************************************************************\ +* Includes the various modules +\****************************************************************************/ + +} // end of namespace MPAL + +} // end of namespace Tony + +#include "loadmpc.h" +#include "expr.h" + +#endif + diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp new file mode 100644 index 0000000000..342678b856 --- /dev/null +++ b/engines/tony/mpal/stubs.cpp @@ -0,0 +1,140 @@ +e/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +#ifndef TONY_MPAL_STUBS +#define TONY_MPAL_STUBS + +/****************************************************************************\ +* This file contains stubs and mappings for things used by the MPAL +* library that are handled differently under ScummVM +\****************************************************************************/ + +#include "common/algorithm.h" +#include "common/system.h" +#include "engines/engine.h" +#include "tony/tony.h" +#include "stubs.h" + +namespace Tony { + +namespace MPAL { + +/** + * Allocates a memory block + */ +byte *GlobalAlloc(uint16 flags, int size) { + byte *result = (byte *)malloc(size); + + if (flags & GMEM_ZEROINIT) + Common::fill(result, result + size, 0); + + return result; +} + +/** + * Lock a global handle + * @param h Global handle + * @remarks Since HGLOBALs are directly representing the pointers anyway, + * simply return it + */ +void *GlobalLock(HGLOBAL h) { + return h; +} + +/** + * Unlock a global handle + * @param h Global handle + * @remarks Since HGLOBALs are directly representing the pointers anyway, + * the unlock method doesn't need to do anything + */ +void GlobalUnlock(HGLOBAL h) { +} + +/** + * Free a globally allocated memory block + * @param h Global handle + */ +void GlobalFree(HGLOBAL h) { + free(h); +} + +/** + * Display a message + * @param msg Message to display + */ +void MessageBox(const Common::String &msg) { + + _vm->GUIError(msg); +} + +/** + * Gets the current time in milliseconds + */ +uint32 timeGetTime() { + return g_system->getMillis(); +} + +HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, + LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, + uint32 dwCreationFlags, uint32 *lpThreadId) { + *lpThreadId = 0; + return 0; +} + +void ExitThread(HANDLE ThreadId) { +} + +void TerminateThread(HANDLE ThreadId, uint32 dwExitCode) { + +} + +void CloseHandle(HANDLE ThreadId) { + +} + +void Sleep(uint32 time) { +} + +int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime) { + return 0; +} + +uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds) { + return 0; +} + +HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName) { + return 0; +} + +void SetEvent(HANDLE hEvent) { +} + +void ResetEvent(HANDLE hEvent) { +} + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h new file mode 100644 index 0000000000..d66e12d00d --- /dev/null +++ b/engines/tony/mpal/stubs.h @@ -0,0 +1,121 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +/****************************************************************************\ +* This file contains stubs and mappings for things used by the MPAL +* library that are handled differently under ScummVM +\****************************************************************************/ + +#ifndef MPAL_STUBS +#define MPAL_STUBS + +#include "common/scummsys.h" +#include "common/algorithm.h" + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* Types +\****************************************************************************/ + +typedef void *HGLOBAL; +typedef void *HANDLE; + +typedef uint32 (__stdcall *LPTHREAD_START_ROUTINE)(void *lpThreadParameter); + +/****************************************************************************\ +* Defines +\****************************************************************************/ + +#define GMEM_FIXED 1 +#define GMEM_MOVEABLE 2 +#define GMEM_ZEROINIT 4 + +#define MB_OK 1 + +#define PASCAL + +/****************************************************************************\ +* Templates +\****************************************************************************/ + +/** + * Copies data from the range [first, last) to [dst, dst + (last - first)). + * It requires the range [dst, dst + (last - first)) to be valid. + * It also requires dst not to be in the range [first, last). + */ +template +Out CopyMemory(Out dst, In first, int size) { + return Common::copy(first, first + size, dst); +} + +/****************************************************************************\ +* Methods +\****************************************************************************/ + +extern byte *GlobalAlloc(uint16 flags, int size); + +extern void *GlobalLock(HGLOBAL h); + +extern void GlobalUnlock(HGLOBAL h); + +extern void GlobalFree(HGLOBAL h); + +extern void MessageBox(const Common::String &msg); + +extern uint32 timeGetTime(); + +#define INFINITE 0xffffffff +#define WAIT_OBJECT_0 -2 +// Horrendously bad cast +#define INVALID_HANDLE_VALUE (void *)-3 + +extern HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, + LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, + uint32 dwCreationFlags, uint32 *lpThreadId); + +extern void ExitThread(int ThreadId); + +extern void TerminateThread(HANDLE ThreadId, uint32 dwExitCode); + +extern void CloseHandle(HANDLE ThreadId); + +extern void Sleep(uint32 time); + +extern int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime); + +extern uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds); + +extern HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName); + +extern void SetEvent(HANDLE hEvent); + +extern void ResetEvent(HANDLE hEvent); + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif -- cgit v1.2.3 From f955745ebf9aba0525de8196dc90de99fce6eab3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 27 Apr 2012 01:32:46 +1000 Subject: TONY: Extra compilation changes and stubs so core MPAL code compiles --- engines/tony/mpal/loadmpc.h | 2 +- engines/tony/mpal/mpal.cpp | 2 +- engines/tony/mpal/mpal.h | 12 ++++++++++-- engines/tony/mpal/stubs.cpp | 9 ++------- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index 8763fbf95b..fc03e43b40 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -72,7 +72,7 @@ namespace MPAL { * \****************************************************************************/ -bool ParseMpc(const byte *lpBuf); +bool ParseMpc(byte *lpBuf); } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 2fd9f3b9c3..f068f0fabf 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -153,7 +153,7 @@ uint32 nSelectedChoice; /****************************************************************************\ -* Static functions +* Internal functions \****************************************************************************/ /****************************************************************************\ diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 73e2dec50f..70b49a1fd9 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -114,12 +114,16 @@ * */ -#ifndef __MPAL_H -#define __MPAL_H +#ifndef TONY_MPAL_H +#define TONY_MPAL_H #include "common/scummsys.h" #include "common/rect.h" +namespace Tony { + +namespace MPAL { + /****************************************************************************\ * Macro definitions and structures \****************************************************************************/ @@ -765,5 +769,9 @@ extern void LockVar(void); extern void UnlockVar(void); +} // end of namespace MPAL + +} // end of namespace Tony + #endif diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 342678b856..c25dd2ab43 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -1,4 +1,4 @@ -e/* ScummVM - Graphic Adventure Engine +/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT @@ -21,9 +21,6 @@ e/* ScummVM - Graphic Adventure Engine * */ -#ifndef TONY_MPAL_STUBS -#define TONY_MPAL_STUBS - /****************************************************************************\ * This file contains stubs and mappings for things used by the MPAL * library that are handled differently under ScummVM @@ -101,7 +98,7 @@ HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, return 0; } -void ExitThread(HANDLE ThreadId) { +void ExitThread(int ThreadId) { } void TerminateThread(HANDLE ThreadId, uint32 dwExitCode) { @@ -136,5 +133,3 @@ void ResetEvent(HANDLE hEvent) { } // end of namespace MPAL } // end of namespace Tony - -#endif -- cgit v1.2.3 From ff71cda42448efaa50f7e98473087fec9c8ddb8d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 29 Apr 2012 09:14:45 +1000 Subject: TONY: Further work on LZO integration --- engines/tony/mpal/lzo.cpp | 509 +++++++++++++++++++++++++++++++++++++++++++++ engines/tony/mpal/lzo.h | 100 +++++++++ engines/tony/mpal/lzo1x.h | 188 ----------------- engines/tony/mpal/mpal.cpp | 14 +- 4 files changed, 615 insertions(+), 196 deletions(-) create mode 100644 engines/tony/mpal/lzo.cpp create mode 100644 engines/tony/mpal/lzo.h delete mode 100644 engines/tony/mpal/lzo1x.h (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/lzo.cpp b/engines/tony/mpal/lzo.cpp new file mode 100644 index 0000000000..5f4b2d40f1 --- /dev/null +++ b/engines/tony/mpal/lzo.cpp @@ -0,0 +1,509 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/* minilzo.c -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + The LZO library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +#include "lzo.h" + +namespace Tony { + +namespace MPAL { + +#define pd(a,b) ((uint32) ((a)-(b))) + +#define TEST_IP (ip < ip_end) +#define TEST_OP 1 +#define NEED_IP(x) ((void) 0) +#define NEED_OP(x) ((void) 0) +#define TEST_LB(m_pos) ((void) 0) + +#define M2_MAX_OFFSET 0x0800 + +/** + * Decompresses an LZO compressed resource + */ +int lzo1x_decompress(const byte *in , uint32 in_len, byte *out, uint32 *out_len) { + register byte *op; + register const byte *ip; + register uint32 t = 0; +#if defined(COPY_DICT) + uint32 m_off; + const byte *dict_end; +#else + register const byte *m_pos; +#endif + + const byte * const ip_end = in + in_len; +#if defined(HAVE_ANY_OP) + byte * const op_end = out + *out_len; +#endif +#if defined(LZO1Z) + uint32 last_m_off = 0; +#endif + +#if defined(COPY_DICT) + if (dict) + { + if (dict_len > M4_MAX_OFFSET) + { + dict += dict_len - M4_MAX_OFFSET; + dict_len = M4_MAX_OFFSET; + } + dict_end = dict + dict_len; + } + else + { + dict_len = 0; + dict_end = NULL; + } +#endif + + *out_len = 0; + + op = out; + ip = in; + + if (*ip > 17) + { + t = *ip++ - 17; + if (t < 4) + goto match_next; + assert(t > 0); NEED_OP(t); NEED_IP(t+1); + do *op++ = *ip++; while (--t > 0); + goto first_literal_run; + } + + while (TEST_IP && TEST_OP) + { + t = *ip++; + if (t >= 16) + goto match; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 15 + *ip++; + } + assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + t += 3; + if (t >= 8) do + { + UA_COPY64(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } + if (t > 0) + { + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } + } +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (PTR_ALIGNED2_4(op,ip)) + { +#endif + UA_COPY32(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) + { + do { + UA_COPY32(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); + } + else + do *op++ = *ip++; while (--t > 0); + } +#if !defined(LZO_UNALIGNED_OK_4) + } + else +#endif +#endif +#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) + { + *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; + do *op++ = *ip++; while (--t > 0); + } +#endif + +first_literal_run: + + t = *ip++; + if (t >= 16) + goto match; +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(3); + t = 3; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - (1 + M2_MAX_OFFSET); + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(3); + *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + + do { +match: + if (t >= 64) + { +#if defined(COPY_DICT) +#if defined(LZO1X) + m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); + t = (t >> 4) - 3; +#elif defined(LZO1Z) + m_off = t & 0x1f; + if (m_off >= 0x1c) + m_off = last_m_off; + else + { + m_off = 1 + (m_off << 6) + (*ip++ >> 2); + last_m_off = m_off; + } + t = (t >> 5) - 1; +#endif +#else +#if defined(LZO1X) + m_pos = op - 1; + m_pos -= (t >> 2) & 7; + m_pos -= *ip++ << 3; + t = (t >> 5) - 1; +#elif defined(LZO1Y) + m_pos = op - 1; + m_pos -= (t >> 2) & 3; + m_pos -= *ip++ << 2; + t = (t >> 4) - 3; +#elif defined(LZO1Z) + { + uint32 off = t & 0x1f; + m_pos = op; + if (off >= 0x1c) + { + assert(last_m_off > 0); + m_pos -= last_m_off; + } + else + { + off = 1 + (off << 6) + (*ip++ >> 2); + m_pos -= off; + last_m_off = off; + } + } + t = (t >> 5) - 1; +#endif + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); + goto copy_match; +#endif + } + else if (t >= 32) + { + t &= 31; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 31 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); + last_m_off = m_off; +#else + m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); +#endif +#else +#if defined(LZO1Z) + { + uint32 off = 1 + (ip[0] << 6) + (ip[1] >> 2); + m_pos = op - off; + last_m_off = off; + } +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos = op - 1; + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos = op - 1; + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif +#endif + ip += 2; + } + else if (t >= 16) + { +#if defined(COPY_DICT) + m_off = (t & 8) << 11; +#else + m_pos = op; + m_pos -= (t & 8) << 11; +#endif + t &= 7; + if (t == 0) + { + NEED_IP(1); + while (*ip == 0) + { + t += 255; + ip++; + NEED_IP(1); + } + t += 7 + *ip++; + } +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off += (ip[0] << 6) + (ip[1] >> 2); +#else + m_off += (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_off == 0) + goto eof_found; + m_off += 0x4000; +#if defined(LZO1Z) + last_m_off = m_off; +#endif +#else +#if defined(LZO1Z) + m_pos -= (ip[0] << 6) + (ip[1] >> 2); +#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET16(ip) >> 2; +#else + m_pos -= (ip[0] >> 2) + (ip[1] << 6); +#endif + ip += 2; + if (m_pos == op) + goto eof_found; + m_pos -= 0x4000; +#if defined(LZO1Z) + last_m_off = pd((const byte *)op, m_pos); +#endif +#endif + } + else + { +#if defined(COPY_DICT) +#if defined(LZO1Z) + m_off = 1 + (t << 6) + (*ip++ >> 2); + last_m_off = m_off; +#else + m_off = 1 + (t >> 2) + (*ip++ << 2); +#endif + NEED_OP(2); + t = 2; COPY_DICT(t,m_off) +#else +#if defined(LZO1Z) + t = 1 + (t << 6) + (*ip++ >> 2); + m_pos = op - t; + last_m_off = t; +#else + m_pos = op - 1; + m_pos -= t >> 2; + m_pos -= *ip++ << 2; +#endif + TEST_LB(m_pos); NEED_OP(2); + *op++ = *m_pos++; *op++ = *m_pos; +#endif + goto match_done; + } + +#if defined(COPY_DICT) + + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) + +#else + + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + if (op - m_pos >= 8) + { + t += (3 - 1); + if (t >= 8) do + { + UA_COPY64(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); + if (t >= 4) + { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } + if (t > 0) + { + *op++ = m_pos[0]; + if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } + } + } + else +#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) +#if !defined(LZO_UNALIGNED_OK_4) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + { + assert((op - m_pos) >= 4); +#else + if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) + { +#endif + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4 - (3 - 1); + do { + UA_COPY32(op,m_pos); + op += 4; m_pos += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } + else +#endif + { +copy_match: + *op++ = *m_pos++; *op++ = *m_pos++; + do *op++ = *m_pos++; while (--t > 0); + } + +#endif + +match_done: +#if defined(LZO1Z) + t = ip[-1] & 3; +#else + t = ip[-2] & 3; +#endif + if (t == 0) + break; + +match_next: + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); +#if 0 + do *op++ = *ip++; while (--t > 0); +#else + *op++ = *ip++; + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } +#endif + t = *ip++; + } while (TEST_IP && TEST_OP); + } + +#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) + *out_len = pd(op, out); + return LZO_E_EOF_NOT_FOUND; +#endif + +eof_found: + assert(t == 1); + *out_len = pd(op, out); + return (ip == ip_end ? LZO_E_OK : + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + +#if defined(HAVE_NEED_IP) +input_overrun: + *out_len = pd(op, out); + return LZO_E_INPUT_OVERRUN; +#endif + +#if defined(HAVE_NEED_OP) +output_overrun: + *out_len = pd(op, out); + return LZO_E_OUTPUT_OVERRUN; +#endif + +#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) +lookbehind_overrun: + *out_len = pd(op, out); + return LZO_E_LOOKBEHIND_OVERRUN; +#endif +} + +} // end of namespace MPAL + +} // end of namespace Tony diff --git a/engines/tony/mpal/lzo.h b/engines/tony/mpal/lzo.h new file mode 100644 index 0000000000..1d20c8e96e --- /dev/null +++ b/engines/tony/mpal/lzo.h @@ -0,0 +1,100 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ +/* minilzo.c -- mini subset of the LZO real-time data compression library + + This file is part of the LZO real-time data compression library. + + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + All Rights Reserved. + + The LZO library is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + The LZO library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the LZO library; see the file COPYING. + If not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Markus F.X.J. Oberhumer + + http://www.oberhumer.com/opensource/lzo/ + */ + +#ifndef TONY_MPAL_LZO_H +#define TONY_MPAL_LZO_H + +#include "common/scummsys.h" + +namespace Tony { + +namespace MPAL { + +/* Error codes for the compression/decompression functions. Negative + * values are errors, positive values will be used for special but + * normal events. + */ +#define LZO_E_OK 0 +#define LZO_E_ERROR (-1) +#define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */ +#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */ +#define LZO_E_INPUT_OVERRUN (-4) +#define LZO_E_OUTPUT_OVERRUN (-5) +#define LZO_E_LOOKBEHIND_OVERRUN (-6) +#define LZO_E_EOF_NOT_FOUND (-7) +#define LZO_E_INPUT_NOT_CONSUMED (-8) +#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ +#define LZO_E_INVALID_ARGUMENT (-10) + + +/** + * Decompresses an LZO compressed resource + */ +int lzo1x_decompress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len); + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif /* already included */ diff --git a/engines/tony/mpal/lzo1x.h b/engines/tony/mpal/lzo1x.h deleted file mode 100644 index 83b547428c..0000000000 --- a/engines/tony/mpal/lzo1x.h +++ /dev/null @@ -1,188 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * - */ -/* lzo1x.h -- public interface of the LZO1X compression algorithm - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer - - The LZO library is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. - - The LZO library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with the LZO library; see the file COPYING. - If not, write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Markus F.X.J. Oberhumer - - http://wildsau.idv.uni-linz.ac.at/mfx/lzo.html - */ - - -#ifndef __LZO1X_H -#define __LZO1X_H - -#ifndef __LZOCONF_H -#include "lzoconf.h" -#endif - -namespace Tony { - -namespace MPAL { - -/*********************************************************************** -// -************************************************************************/ - -/* Memory required for the wrkmem parameter. - * When the required size is 0, you can also pass a NULL pointer. - */ - -#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS -#define LZO1X_MEM_DECOMPRESS (0) -#define LZO1X_MEM_OPTIMIZE (0) - - -/* decompression */ -LZO_EXTERN(int) -lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem /* NOT USED */ ); - -/* safe decompression with overrun testing */ -LZO_EXTERN(int) -lzo1x_decompress_safe ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem /* NOT USED */ ); - - -/*********************************************************************** -// -************************************************************************/ - -#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) - -LZO_EXTERN(int) -lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem ); - - -/*********************************************************************** -// special compressor versions -************************************************************************/ - -/* this version needs only 8 kB work memory */ -#define LZO1X_1_11_MEM_COMPRESS ((lzo_uint32) (2048L * lzo_sizeof_dict_t)) - -LZO_EXTERN(int) -lzo1x_1_11_compress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem ); - - -/* this version needs 16 kB work memory */ -#define LZO1X_1_12_MEM_COMPRESS ((lzo_uint32) (4096L * lzo_sizeof_dict_t)) - -LZO_EXTERN(int) -lzo1x_1_12_compress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem ); - - -/* use this version if you need a little more compression speed */ -#define LZO1X_1_15_MEM_COMPRESS ((lzo_uint32) (32768L * lzo_sizeof_dict_t)) - -LZO_EXTERN(int) -lzo1x_1_15_compress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem ); - - -/*********************************************************************** -// better compression ratio at the cost of more memory and time -************************************************************************/ - -#define LZO1X_999_MEM_COMPRESS ((lzo_uint32) (14 * 16384L * sizeof(short))) - -#if !defined(LZO_999_UNSUPPORTED) -LZO_EXTERN(int) -lzo1x_999_compress ( const lzo_byte *src, lzo_uint src_len, - lzo_byte *dst, lzo_uint *dst_len, - lzo_voidp wrkmem ); -#endif - - -/*********************************************************************** -// -************************************************************************/ - -#if !defined(LZO_999_UNSUPPORTED) -LZO_EXTERN(int) -lzo1x_999_compress_dict ( const lzo_byte *in , lzo_uint in_len, - lzo_byte *out, lzo_uint *out_len, - lzo_voidp wrkmem, - const lzo_byte *dict, lzo_uint dict_len ); - -LZO_EXTERN(int) -lzo1x_999_compress_level ( const lzo_byte *in , lzo_uint in_len, - lzo_byte *out, lzo_uint *out_len, - lzo_voidp wrkmem, - const lzo_byte *dict, lzo_uint dict_len, - lzo_progress_callback_t cb, - int compression_level ); -#endif - -LZO_EXTERN(int) -lzo1x_decompress_dict_safe ( const lzo_byte *in, lzo_uint in_len, - lzo_byte *out, lzo_uint *out_len, - lzo_voidp wrkmem /* NOT USED */, - const lzo_byte *dict, lzo_uint dict_len ); - - -/*********************************************************************** -// optimize a compressed data block -************************************************************************/ - -LZO_EXTERN(int) -lzo1x_optimize ( lzo_byte *in , lzo_uint in_len, - lzo_byte *out, lzo_uint *out_len, - lzo_voidp wrkmem ); - - -} // end of namespace MPAL - -} // end of namespace Tony - -#endif /* already included */ diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index f068f0fabf..e07669849e 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -51,18 +51,16 @@ #include "common/file.h" #include "common/savefile.h" #include "common/system.h" +#include "tony/tony.h" +#include "lzo.h" #include "mpal.h" #include "mpaldll.h" #include "stubs.h" -#include "tony/tony.h" -#include "tony/lzo/lzo1x.h" namespace Tony { namespace MPAL { -using namespace Tony::LZO; - /****************************************************************************\ * Copyright \****************************************************************************/ @@ -653,7 +651,7 @@ HGLOBAL resLoad(uint32 dwId) { if (nBytesRead != nSizeComp) return NULL; - lzo1x_decompress(temp, nSizeComp, buf, (lzo_uint*)&nBytesRead, NULL); + lzo1x_decompress(temp, nSizeComp, buf, &nBytesRead); if (nBytesRead != nSizeDecomp) return NULL; @@ -1709,7 +1707,7 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION /* Se il file e' compresso, guarda quanto e' grande e alloca la memoria temporanea per la decompressione */ dwSizeComp = hMpc.readUint32LE(); - if (nBytesRead != 4) + if (hMpc.err()) return false; cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeComp); @@ -1721,7 +1719,7 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION return false; /* Decomprime l'immagine */ - lzo1x_decompress(cmpbuf,dwSizeComp,lpMpcImage,(lzo_uint*)&nBytesRead,NULL); + lzo1x_decompress(cmpbuf, dwSizeComp, lpMpcImage, &nBytesRead); if (nBytesRead != dwSizeDecomp) return false; @@ -1795,7 +1793,7 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION if (nBytesRead != dwSizeComp) return false; - lzo1x_decompress((byte *)cmpbuf,dwSizeComp,(byte *)lpResources, (uint32 *)&nBytesRead, NULL); + lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)lpResources, (uint32 *)&nBytesRead); if (nBytesRead != (uint32)nResources*8) return false; -- cgit v1.2.3 From a2c4b4ca68aa15a763281ce7092178d78603d161 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 29 Apr 2012 10:16:56 +1000 Subject: TONY: LZO decompression now working correctly --- engines/tony/mpal/lzo.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/lzo.cpp b/engines/tony/mpal/lzo.cpp index 5f4b2d40f1..6cd755fc93 100644 --- a/engines/tony/mpal/lzo.cpp +++ b/engines/tony/mpal/lzo.cpp @@ -77,6 +77,7 @@ namespace MPAL { #define TEST_LB(m_pos) ((void) 0) #define M2_MAX_OFFSET 0x0800 +#define LZO1X /** * Decompresses an LZO compressed resource -- cgit v1.2.3 From 4784367debbaeae656f3bdec5a146b821150a2d0 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 29 Apr 2012 08:44:15 +0200 Subject: TONY: Remove __stdcall to make it build on Linux --- engines/tony/mpal/stubs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index d66e12d00d..f41d222b8a 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -43,7 +43,7 @@ namespace MPAL { typedef void *HGLOBAL; typedef void *HANDLE; -typedef uint32 (__stdcall *LPTHREAD_START_ROUTINE)(void *lpThreadParameter); +typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter); /****************************************************************************\ * Defines -- cgit v1.2.3 From 118f5ca0102144b5c282f012def6c96c69052bc1 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 29 Apr 2012 23:19:30 +1000 Subject: TONY: Implemented RMGameBoxes class and all dependent classes --- engines/tony/mpal/expr.cpp | 4 +- engines/tony/mpal/loadmpc.cpp | 2 + engines/tony/mpal/memory.cpp | 145 ++++++++++++++++++++++++++++++++++++++++ engines/tony/mpal/memory.h | 82 +++++++++++++++++++++++ engines/tony/mpal/mpal.cpp | 12 ++-- engines/tony/mpal/mpaldll.h | 1 + engines/tony/mpal/mpalutils.cpp | 106 +++++++++++++++++++++++++++++ engines/tony/mpal/mpalutils.h | 69 +++++++++++++++++++ engines/tony/mpal/stubs.cpp | 39 ----------- engines/tony/mpal/stubs.h | 12 +--- 10 files changed, 416 insertions(+), 56 deletions(-) create mode 100644 engines/tony/mpal/memory.cpp create mode 100644 engines/tony/mpal/memory.h create mode 100644 engines/tony/mpal/mpalutils.cpp create mode 100644 engines/tony/mpal/mpalutils.h (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 0faf91744c..2f0e890af9 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -48,8 +48,10 @@ **************************************************************************/ #include "mpal.h" +#include "memory.h" #include "mpaldll.h" #include "stubs.h" +#include "tony/tony.h" /* #include "lzo1x.h" @@ -149,7 +151,7 @@ static byte *DuplicateExpression(HGLOBAL h) { num=*(byte *)orig; one=(LPEXPRESSION)(orig+1); - clone=GlobalAlloc(GMEM_FIXED,sizeof(EXPRESSION)*num+1); + clone = (byte *)GlobalAlloc(GMEM_FIXED, sizeof(EXPRESSION)*num+1); two=(LPEXPRESSION)(clone+1); CopyMemory(clone,orig,sizeof(EXPRESSION)*num+1); diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index f9426c8d58..ff94dbae8d 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -52,6 +52,8 @@ */ #include "mpal.h" #include "mpaldll.h" +#include "memory.h" +#include "tony/tony.h" namespace Tony { diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp new file mode 100644 index 0000000000..604e61ed24 --- /dev/null +++ b/engines/tony/mpal/memory.cpp @@ -0,0 +1,145 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +#include "common/textconsole.h" +#include "tony/mpal/memory.h" + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* MemoryItem methods +\****************************************************************************/ + +/** + * Constructor + * @param Data sizee + */ +MemoryItem::MemoryItem(uint32 size) { + _size = size; + _buffer = (size == 0) ? NULL : new byte[size]; +} + +/** + * Destructor + */ +MemoryItem::~MemoryItem() { + delete[] _buffer; +} + +/** + * Returns a pointer to the resource + */ +MemoryItem::operator void *() { + return DataPointer(); +} + +/****************************************************************************\ +* MemoryManager methods +\****************************************************************************/ + +MemoryManager::MemoryManager() { +} + +/** + * Destructor + */ +MemoryManager::~MemoryManager() { + Common::List::iterator i; + for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) { + MemoryItem *item = *i; + delete item; + } +} + +/** + * Allocates a new memory block + * @returns Returns a MemoryItem instance for the new block + */ +MemoryItem &MemoryManager::allocate(uint32 size) { + MemoryItem *newItem = new MemoryItem(size); + _memoryBlocks.push_back(newItem); + + return *newItem; +} + +/** + * Allocates a new memory block and returns it's data pointer + * @returns Data pointer to allocated block + */ +HGLOBAL MemoryManager::alloc(uint32 size) { + MemoryItem &newItem = allocate(size); + return (HGLOBAL)newItem.DataPointer(); +} + +/** + * Returns a reference to the MemoryItem for a gien byte pointer + * @param block Byte pointer + */ +MemoryItem &MemoryManager::getItem(HGLOBAL handle) { + Common::List::iterator i; + for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) { + MemoryItem *item = *i; + if (item->DataPointer() == handle) + return *item; + } + + error("Could not locate a memory block"); +} + +/** + * Square bracketes operator + * @param block Byte pointer + */ +MemoryItem &MemoryManager::operator[](HGLOBAL handle) { + return getItem(handle); +} + +/** + * Returns a size of a memory block given it's pointer + */ +uint32 MemoryManager::getSize(HGLOBAL handle) { + MemoryItem &item = getItem(handle); + return item.Size(); +} + +/** + * Erases a given item + */ +void MemoryManager::erase(MemoryItem &item) { + delete item; + _memoryBlocks.remove(&item); +} + +/** + * Erases a given item + */ +void MemoryManager::erase(HGLOBAL handle) { + MemoryItem &item = getItem(handle); + erase(item); +} + +} // end of namespace MPAL + +} // end of namespace Tony diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h new file mode 100644 index 0000000000..dde2e8908c --- /dev/null +++ b/engines/tony/mpal/memory.h @@ -0,0 +1,82 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +#ifndef TONY_MPAL_MEMORY +#define TONY_MPAL_MEMORY + +#include "common/scummsys.h" +#include "common/list.h" + +namespace Tony { + +namespace MPAL { + +typedef void *HANDLE; +typedef HANDLE HGLOBAL; + +class MemoryItem { +protected: + void *_buffer; + uint32 _size; +public: + MemoryItem(uint32 size); + virtual ~MemoryItem(); + + uint32 Size() { return _size; } + void *DataPointer() { return _buffer; } + bool IsValid() { return _buffer != NULL; } + + // Casting for access to data + operator void *(); +}; + +class MemoryManager { +private: + Common::List _memoryBlocks; +public: + MemoryManager(); + virtual ~MemoryManager(); + + MemoryItem &allocate(uint32 size); + HGLOBAL alloc(uint32 size); + MemoryItem &getItem(HGLOBAL handle); + MemoryItem &operator[](HGLOBAL handle); + void erase(MemoryItem &item); + void erase(HGLOBAL handle); + + uint32 getSize(HANDLE handle); +}; + +// defines +#define GlobalAlloc(flags, size) _vm->_memoryManager.alloc(size) +#define GlobalAllocate(size) _vm->_memoryManager.allocate(size) +#define GlobalFree(handle) _vm->_memoryManager.erase(handle) +#define GlobalLock(handle) (_vm->_memoryManager.getItem(handle).DataPointer()) +#define GlobalUnlock(handle) {} +#define GlobalSize(handle) (_vm->_memoryManager.getItem(handle).Size()) + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index e07669849e..b4b37e7723 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -860,7 +860,7 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { uint32 dwCurTime; uint32 dwId; static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT]; - int numHandles; + int numHandles = 0; LPCFCALL p; // warning("PlayScript(): Moments: %u\n",s->nMoments); @@ -1785,7 +1785,7 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION if (lpResources==NULL) return false; - cmpbuf = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); + cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); if (cmpbuf==NULL) return false; @@ -1840,12 +1840,14 @@ bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION #define GETARG(type) va_arg(v,type) uint32 mpalQuery(uint16 wQueryType, ...) { - uint32 dwRet; int x,y,z; char * n; + uint32 dwRet = 0; + int x,y,z; + char *n; va_list v; Common::String buf; - mpalError=OK; - va_start(v,wQueryType); + mpalError = OK; + va_start(v, wQueryType); switch (wQueryType) { /* diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 8a52f1ed90..ee3820531a 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -51,6 +51,7 @@ #define __MPALDLL_H #include "common/file.h" +#include "memory.h" #include "stubs.h" namespace Tony { diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp new file mode 100644 index 0000000000..2e3bd07383 --- /dev/null +++ b/engines/tony/mpal/mpalutils.cpp @@ -0,0 +1,106 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +#include "tony/mpal/mpalutils.h" +#include "tony/tony.h" + +namespace Tony { + +namespace MPAL { + +/****************************************************************************\ +* RMRes methods +\****************************************************************************/ + +/** + * Constructor + * @param resId MPAL resource to open + */ +RMRes::RMRes(uint32 resID) { + m_h = _vm->_resUpdate.QueryResource(resID); + if (m_h == NULL) + m_h = mpalQueryResource(resID); + if (m_h != NULL) + m_buf = (byte *)GlobalLock(m_h); +} + +/** + * Destructor + */ +RMRes::~RMRes() { + if (m_h != NULL) { + GlobalUnlock(m_h); + GlobalFree(m_h); + } +} + +/** + * Returns a pointer to the resource + */ +const byte *RMRes::DataPointer() { + return m_buf; +} + +/** + * Returns a pointer to the resource + */ +RMRes::operator const byte *() { + return DataPointer(); +} + +/** + * Returns the size of the resource + */ +unsigned int RMRes::Size() { + return GlobalSize(m_h); +} + +/****************************************************************************\ +* RMResRaw methods +\****************************************************************************/ + +RMResRaw::RMResRaw(uint32 resID) : RMRes(resID) { +} + +RMResRaw::~RMResRaw() { +} + +const byte *RMResRaw::DataPointer() { + return m_buf + 8; +} + +RMResRaw::operator const byte *() { + return DataPointer(); +} + +int RMResRaw::Width() { + return READ_LE_UINT16(m_buf + 4); +} + +int RMResRaw::Height() { + return READ_LE_UINT16(m_buf + 6); +} + +} // end of namespace MPAL + +} // end of namespace Tony diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h new file mode 100644 index 0000000000..cb8d4ec97d --- /dev/null +++ b/engines/tony/mpal/mpalutils.h @@ -0,0 +1,69 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * + */ + +#ifndef TONY_MPAL_MPALUTILS +#define TONY_MPAL_MPALUTILS + +#include "common/scummsys.h" +#include "memory.h" +#include "stubs.h" + +namespace Tony { + +namespace MPAL { + +class RMRes { +protected: + HGLOBAL m_h; + byte *m_buf; + +public: + RMRes(uint32 resID); + virtual ~RMRes(); + + // Attributes + unsigned int Size(); + const byte *DataPointer(); + bool IsValid() { return m_h != NULL; } + + // Casting for access to data + operator const byte*(); +}; + +class RMResRaw : public RMRes { +public: + RMResRaw(uint32 resID); + virtual ~RMResRaw(); + + const byte *DataPointer(); + operator const byte*(); + + int Width(); + int Height(); +}; + +} // end of namespace MPAL + +} // end of namespace Tony + +#endif diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index c25dd2ab43..054ed55c68 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -36,45 +36,6 @@ namespace Tony { namespace MPAL { -/** - * Allocates a memory block - */ -byte *GlobalAlloc(uint16 flags, int size) { - byte *result = (byte *)malloc(size); - - if (flags & GMEM_ZEROINIT) - Common::fill(result, result + size, 0); - - return result; -} - -/** - * Lock a global handle - * @param h Global handle - * @remarks Since HGLOBALs are directly representing the pointers anyway, - * simply return it - */ -void *GlobalLock(HGLOBAL h) { - return h; -} - -/** - * Unlock a global handle - * @param h Global handle - * @remarks Since HGLOBALs are directly representing the pointers anyway, - * the unlock method doesn't need to do anything - */ -void GlobalUnlock(HGLOBAL h) { -} - -/** - * Free a globally allocated memory block - * @param h Global handle - */ -void GlobalFree(HGLOBAL h) { - free(h); -} - /** * Display a message * @param msg Message to display diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index f41d222b8a..be856790bc 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -31,6 +31,7 @@ #include "common/scummsys.h" #include "common/algorithm.h" +#include "tony/mpal/memory.h" namespace Tony { @@ -40,9 +41,6 @@ namespace MPAL { * Types \****************************************************************************/ -typedef void *HGLOBAL; -typedef void *HANDLE; - typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter); /****************************************************************************\ @@ -75,14 +73,6 @@ Out CopyMemory(Out dst, In first, int size) { * Methods \****************************************************************************/ -extern byte *GlobalAlloc(uint16 flags, int size); - -extern void *GlobalLock(HGLOBAL h); - -extern void GlobalUnlock(HGLOBAL h); - -extern void GlobalFree(HGLOBAL h); - extern void MessageBox(const Common::String &msg); extern uint32 timeGetTime(); -- cgit v1.2.3 From b0eef829728183b7ea170b30a33eca091bcc4574 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 30 Apr 2012 09:27:12 +1000 Subject: TONY: Added include files for graphics engine and all dependent classes --- engines/tony/mpal/memory.h | 4 ++++ engines/tony/mpal/stubs.h | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index dde2e8908c..fde0d33b3e 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -75,6 +75,10 @@ public: #define GlobalUnlock(handle) {} #define GlobalSize(handle) (_vm->_memoryManager.getItem(handle).Size()) +#define GMEM_FIXED 1 +#define GMEM_MOVEABLE 2 +#define GMEM_ZEROINIT 4 + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index be856790bc..a8d3253ddb 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -47,10 +47,6 @@ typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter); * Defines \****************************************************************************/ -#define GMEM_FIXED 1 -#define GMEM_MOVEABLE 2 -#define GMEM_ZEROINIT 4 - #define MB_OK 1 #define PASCAL -- cgit v1.2.3 From 68bcaa61b9eb1108028b3db072ade95431b9f14f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 30 Apr 2012 23:16:19 +1000 Subject: TONY: More header files and functionality added --- engines/tony/mpal/lzo.cpp | 14 ++++++++++++++ engines/tony/mpal/lzo.h | 11 +++++++++++ engines/tony/mpal/stubs.cpp | 10 ++++++++++ engines/tony/mpal/stubs.h | 8 ++++++++ 4 files changed, 43 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/lzo.cpp b/engines/tony/mpal/lzo.cpp index 6cd755fc93..17b059455c 100644 --- a/engines/tony/mpal/lzo.cpp +++ b/engines/tony/mpal/lzo.cpp @@ -63,6 +63,7 @@ */ #include "lzo.h" +#include "common/textconsole.h" namespace Tony { @@ -505,6 +506,19 @@ lookbehind_overrun: #endif } +int lzo1x_1_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem) { + warning("TODO: lzo1x_1_compress"); + return 0; +} + +/** + * better compression ratio at the cost of more memory and time + */ +int lzo1x_999_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem) { + warning("TODO: lzo1x_999_compress"); + return 0; +} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/lzo.h b/engines/tony/mpal/lzo.h index 1d20c8e96e..ebb1c4b516 100644 --- a/engines/tony/mpal/lzo.h +++ b/engines/tony/mpal/lzo.h @@ -87,12 +87,23 @@ namespace MPAL { #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ #define LZO_E_INVALID_ARGUMENT (-10) +#define LZO1X_999_MEM_COMPRESS ((uint32) (14 * 16384L * sizeof(uint16))) /** * Decompresses an LZO compressed resource */ int lzo1x_decompress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len); +/** + * Comrpess a data block into an LZO stream + */ +int lzo1x_1_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem); + +/** + * better compression ratio at the cost of more memory and time + */ +int lzo1x_999_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem); + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 054ed55c68..ea93265ec9 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -59,9 +59,15 @@ HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, return 0; } +void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter) { +} + void ExitThread(int ThreadId) { } +void _endthread() { +} + void TerminateThread(HANDLE ThreadId, uint32 dwExitCode) { } @@ -91,6 +97,10 @@ void SetEvent(HANDLE hEvent) { void ResetEvent(HANDLE hEvent) { } +uint16 GetAsyncKeyState(Common::KeyCode kc) { + return 0; +} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index a8d3253ddb..9a22b65b7a 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -31,6 +31,7 @@ #include "common/scummsys.h" #include "common/algorithm.h" +#include "common/keyboard.h" #include "tony/mpal/memory.h" namespace Tony { @@ -42,6 +43,7 @@ namespace MPAL { \****************************************************************************/ typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter); +typedef void (*LPTHREAD_ROUTINE)(void *lpThreadParameter); /****************************************************************************\ * Defines @@ -82,8 +84,12 @@ extern HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, uint32 dwCreationFlags, uint32 *lpThreadId); +extern void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter); + extern void ExitThread(int ThreadId); +extern void _endthread(); + extern void TerminateThread(HANDLE ThreadId, uint32 dwExitCode); extern void CloseHandle(HANDLE ThreadId); @@ -100,6 +106,8 @@ extern void SetEvent(HANDLE hEvent); extern void ResetEvent(HANDLE hEvent); +extern uint16 GetAsyncKeyState(Common::KeyCode kc); + } // end of namespace MPAL } // end of namespace Tony -- cgit v1.2.3 From 4300db9ee4798d43eb2214db87b575ed12640458 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 2 May 2012 23:35:32 +1000 Subject: TONY: Implemented font.cpp methods --- engines/tony/mpal/stubs.cpp | 3 +++ engines/tony/mpal/stubs.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index ea93265ec9..9d4a87d61c 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -97,6 +97,9 @@ void SetEvent(HANDLE hEvent) { void ResetEvent(HANDLE hEvent) { } +void PulseEvent(HANDLE hEvent) { +} + uint16 GetAsyncKeyState(Common::KeyCode kc) { return 0; } diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index 9a22b65b7a..5c50b76db1 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -106,6 +106,8 @@ extern void SetEvent(HANDLE hEvent); extern void ResetEvent(HANDLE hEvent); +extern void PulseEvent(HANDLE hEvent); + extern uint16 GetAsyncKeyState(Common::KeyCode kc); } // end of namespace MPAL -- cgit v1.2.3 From 6d0f1fca46c8bd9b5b4e7ccaf6631850c29d1447 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 3 May 2012 23:08:19 +1000 Subject: TONY: Formatting fixes --- engines/tony/mpal/mpal.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index b4b37e7723..74dbedd90f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -2902,10 +2902,8 @@ case num: \ return DLG##num[nPers]; -char *GetPersonName(uint16 nDlg, int nPers) -{ - switch (nDlg) - { +char *GetPersonName(uint16 nDlg, int nPers) { + switch (nDlg) { HANDLE_DIALOG(10); HANDLE_DIALOG(51); HANDLE_DIALOG(52); -- cgit v1.2.3 From 5b2c69b1f291b1ee3d7f3be4ffd40e427b437ac6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 00:11:38 +1000 Subject: TONY: Implemented some missing and incorrect init code --- engines/tony/mpal/mpal.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 74dbedd90f..610dd59984 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -626,13 +626,13 @@ HGLOBAL resLoad(uint32 dwId) { uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; - for (i=0;iMoment[i].dwTime==-1) { WaitForMultipleObjects(numHandles,cfHandles,true,INFINITE); - dwStartTime=timeGetTime(); + dwStartTime = timeGetTime(); } else { - dwCurTime=timeGetTime(); + dwCurTime = timeGetTime(); if (dwCurTime < dwStartTime+(s->Moment[i].dwTime*100)) { // warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); Sleep(dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); @@ -1043,23 +1043,23 @@ void PASCAL LocationPollThread(uint32 id) { /* Cerchiamo gli items della locazione senza idle actions e li eliminiamo dalla lista */ LockItems(); - nIdleActions=0; - nRealItems=0; - for (i=0;inActions;j++) - if (curItem->Action[j].num==0xFF) + for (j = 0; j < curItem->nActions; j++) + if (curItem->Action[j].num == 0xFF) k++; - nIdleActions+=k; + nIdleActions += k; - if (k==0) + if (k == 0) /* Possiamo eliminare questo item dalla lista */ il[i] = (uint32)NULL; else @@ -1068,28 +1068,28 @@ void PASCAL LocationPollThread(uint32 id) { UnlockItems(); /* Se non e' rimasto nessuno possiamo uscire */ - if (nRealItems==0) { + if (nRealItems == 0) { GlobalFree(il); ExitThread(0); // _endthread(); } - MyThreads=(MYTHREAD*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,nRealItems*sizeof(MYTHREAD)); - if (MyThreads==NULL) { + MyThreads=(MYTHREAD *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nRealItems * sizeof(MYTHREAD)); + if (MyThreads == NULL) { GlobalFree(il); ExitThread(0); // _endthread(); } /* Inizializziamo le routine random */ - //curTime=timeGetTime(); + //curTime = timeGetTime(); //srand(curTime); /* Abbiamo appurato che esiste almeno un item che contiene idle actions. Ora creaiamo le copie speculari delle idle actions */ - MyActions=(MYACTION*)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,nIdleActions*sizeof(MYACTION)); - if (MyActions==NULL) { + MyActions = (MYACTION *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nIdleActions * sizeof(MYACTION)); + if (MyActions == NULL) { GlobalFree(MyThreads); GlobalFree(il); ExitThread(0); @@ -1097,27 +1097,27 @@ void PASCAL LocationPollThread(uint32 id) { } LockItems(); - k=0; + k = 0; - for (i=0;inActions;j++) - if (curItem->Action[j].num==0xFF) { - MyActions[k].nItem=il[i]; - MyActions[k].nAction=j; + for (j = 0; j < curItem->nActions; j++) + if (curItem->Action[j].num == 0xFF) { + MyActions[k].nItem = il[i]; + MyActions[k].nAction = j; - MyActions[k].wTime=curItem->Action[j].wTime; - MyActions[k].perc=curItem->Action[j].perc; - MyActions[k].when=curItem->Action[j].when; - MyActions[k].nCmds=curItem->Action[j].nCmds; + MyActions[k].wTime = curItem->Action[j].wTime; + MyActions[k].perc = curItem->Action[j].perc; + MyActions[k].when = curItem->Action[j].when; + MyActions[k].nCmds = curItem->Action[j].nCmds; CopyMemory(MyActions[k].CmdNum, curItem->Action[j].CmdNum, - MAX_COMMANDS_PER_ACTION*sizeof(uint16)); + MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - MyActions[k].dwLastTime=timeGetTime(); + MyActions[k].dwLastTime = timeGetTime(); k++; } } @@ -1132,7 +1132,7 @@ void PASCAL LocationPollThread(uint32 id) { while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ - curTime=timeGetTime(); + curTime = timeGetTime(); dwSleepTime=(uint32)-1L; for (k=0;kAction[0].nCmds=curItem->Action[j].nCmds; +// newItem->Action[0].nCmds = curItem->Action[j].nCmds; // CopyMemory(newItem->Action[0].CmdNum,curItem->Action[j].CmdNum,newItem->Action[0].nCmds*sizeof(newItem->Action[0].CmdNum[0])); newItem->dwRes=j; diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 70b49a1fd9..26c4283018 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -271,7 +271,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryGlobalVar(lpszVarName) \ - (uint32)mpalQuery(MPQ_GLOBAL_VAR,(LPSTR)(lpszVarName)) + (uint32)mpalQuery(MPQ_GLOBAL_VAR,(const char *)(lpszVarName)) -- cgit v1.2.3 From 23cd3b7730c292539649578d1aea373812e6b4ce Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 22:28:51 +1000 Subject: TONY: Fixed many warnings identified by gcc --- engines/tony/mpal/loadmpc.cpp | 8 +- engines/tony/mpal/mpal.cpp | 609 +++++++++++++++++++++--------------------- engines/tony/mpal/mpal.h | 2 +- 3 files changed, 307 insertions(+), 312 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index ff94dbae8d..484f1ad2a0 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -527,16 +527,10 @@ static byte *ParseLocation(byte *lpBuf, LPMPALLOCATION lpmlLocation) { \****************************************************************************/ bool ParseMpc(byte *lpBuf) { - uint16 i,j; + uint16 i, j; uint16 wLen; byte *lpTemp, *lpTemp2; - // Oggetti dummy. Definiti static per evitare stack overflow - static MPALITEM dummyitem; - static MPALLOCATION dummylocation; - static MPALSCRIPT dummyscript; - static MPALDIALOG dummydialog; - /* 1. Variabili */ if (lpBuf[0]!='V' || lpBuf[1]!='A' || lpBuf[2]!='R' || lpBuf[3]!='S') return false; diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 6ec08f9d26..d767dbe381 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -356,20 +356,20 @@ int32 varGetValue(const char *lpszVarName) { \****************************************************************************/ void varSetValue(const char *lpszVarName, int32 val) { - int i; + uint i; LPMPALVAR v=lpmvVars; for (i=0;ilpszVarName)==0) { v->dwVal=val; - if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Pattern.",8)==0) { - i=0; - sscanf(v->lpszVarName,"Pattern.%u",&i); + if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Pattern.",8) == 0) { + i = 0; + sscanf(v->lpszVarName, "Pattern.%u", &i); lpiifCustom(i,val,-1); - } else if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Status.",7)==0) { - i=0; - sscanf(v->lpszVarName,"Status.%u",&i); - lpiifCustom(i,-1,val); + } else if (lpiifCustom!=NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { + i = 0; + sscanf(v->lpszVarName,"Status.%u", &i); + lpiifCustom(i, -1, val); } return; } @@ -1648,7 +1648,7 @@ bool DoSelection(uint32 i, uint32 dwData) { /****************************************************************************\ * -* Function: bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, +* Function: bool mpalInit(LPSTR lpszMpcFileName, LPSTR lpszMprFileName, * LPLPCUSTOMFUNCTION lplpcfArray); * * Description: Inizializza la libreria MPAL, e apre un file .MPC, che @@ -1665,7 +1665,7 @@ bool DoSelection(uint32 i, uint32 dwData) { * \****************************************************************************/ -bool mpalInit(char * lpszMpcFileName, char * lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { +bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { Common::File hMpc; byte buf[5]; uint32 nBytesRead; @@ -2281,11 +2281,12 @@ int mpalLoadState(byte *buf) { bool bDontOutput; -struct { +struct MsgCommentsStruct { uint16 wStart; uint16 wEnd; char *pComment; -} MsgComments[] = { +}; +MsgCommentsStruct MsgComments[] = { { 10, 16, "###" }, { 560, 563, "@@@ BUTCH & DUDLEY:" }, { 551, 553, "@@@ JACK'S LETTER (JACK'S VOICE):" }, @@ -2584,310 +2585,310 @@ void mpalDumpOthers(void) { #if 0 // English names -char *DLG10[] = { "Tony", NULL }; -char *DLG51[] = { "Tony", "Butch", "Dudley" }; -char *DLG52[] = { "Tony", NULL }; -char *DLG61[] = { "Tony", "Old lady 1", NULL }; -char *DLG71[] = { "Tony", "Timothy", "Convict", NULL, NULL, "Jack (with microphone)", "Old lady 1", NULL }; -char *DLG90[] = { "Tony", "Bearded lady", NULL }; -char *DLG110[] = { "Tony", "Lorenz", NULL }; -char *DLG111[] = { "Tony", "Lorenz", NULL }; -char *DLG130[] = { "Tony", "Piranha", NULL }; -char *DLG150[] = { "Tony", "Rufus", "Snowman", NULL }; -char *DLG151[] = { "Tony", "Rufus", "Snowman", NULL }; -char *DLG152[] = { "Tony", "Rufus", "Snowman", NULL }; -char *DLG153[] = { "Tony", "Rufus", "Snowman", NULL }; -char *DLG154[] = { "Tony", "Rufus", "Snowman", NULL }; -char *DLG160[] = { "Tony", "Shmiley", NULL }; -char *DLG161[] = { "Tony", "Shmiley", NULL }; -char *DLG162[] = { "Tony", "Shmiley", NULL }; -char *DLG163[] = { "Tony", "Shmiley", NULL }; -char *DLG180[] = { "Tony", "Beast", NULL }; -char *DLG190[] = { "Tony", "Beast", NULL }; -char *DLG191[] = { "Tony", "Beast", NULL }; -char *DLG201[] = { "Tony", NULL }; -char *DLG210[] = { "Tony", "Mortimer", NULL }; -char *DLG211[] = { "Tony", "Mortimer", NULL }; -char *DLG212[] = { "Tony", "Mortimer", NULL }; -char *DLG240[] = { "Tony", "Isabella", NULL }; -char *DLG250[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; -char *DLG251[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; -char *DLG260[] = { "Tony", "Captain", "Captain (tale)", NULL }; -char *DLG270[] = { "Tony", "Egghead", NULL }; -char *DLG271[] = { "Tony", "Egghead", NULL }; -char *DLG272[] = { "Tony", "Egghead", NULL }; -char *DLG290[] = { "Tony", "Old lady 2", NULL }; -char *DLG310[] = { "Tony", "Wally", NULL }; -char *DLG330[] = { "Tony", "Polly", "Captain (off scene)", NULL }; -char *DLG340[] = { "Tony", "Randall", NULL }; -char *DLG360[] = { "Tony", NULL }; -char *DLG361[] = { "Tony", NULL }; -char *DLG370[] = { "Tony", "Gatekeeper", NULL }; -char *DLG371[] = { "Tony", "Gatekeeper", NULL }; -char *DLG372[] = { "Tony", "Gatekeeper", NULL }; -char *DLG373[] = { "Tony", "Gatekeeper", NULL }; -char *DLG380[] = { "Tony", NULL }; -char *DLG410[] = { "Tony", "Gwendel", NULL }; -char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -char *DLG460[] = { "Tony", NULL }; -char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG480[] = { "Tony", "Pin-up", NULL }; -char *DLG490[] = { "Tony", "Gwendel", NULL }; -char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -char *DLG550[] = { "Tony", "Mr. Wishing Well", "Tony (from the top of the well)", NULL }; -char *DLG560[] = { "Tony", "Superintendent", NULL }; -char *DLG590[] = { "Tony", "Pantagruel", NULL }; -char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Storyteller", "Mr. Wishing Well", NULL }; +const char *DLG10[] = { "Tony", NULL }; +const char *DLG51[] = { "Tony", "Butch", "Dudley" }; +const char *DLG52[] = { "Tony", NULL }; +const char *DLG61[] = { "Tony", "Old lady 1", NULL }; +const char *DLG71[] = { "Tony", "Timothy", "Convict", NULL, NULL, "Jack (with microphone)", "Old lady 1", NULL }; +const char *DLG90[] = { "Tony", "Bearded lady", NULL }; +const char *DLG110[] = { "Tony", "Lorenz", NULL }; +const char *DLG111[] = { "Tony", "Lorenz", NULL }; +const char *DLG130[] = { "Tony", "Piranha", NULL }; +const char *DLG150[] = { "Tony", "Rufus", "Snowman", NULL }; +const char *DLG151[] = { "Tony", "Rufus", "Snowman", NULL }; +const char *DLG152[] = { "Tony", "Rufus", "Snowman", NULL }; +const char *DLG153[] = { "Tony", "Rufus", "Snowman", NULL }; +const char *DLG154[] = { "Tony", "Rufus", "Snowman", NULL }; +const char *DLG160[] = { "Tony", "Shmiley", NULL }; +const char *DLG161[] = { "Tony", "Shmiley", NULL }; +const char *DLG162[] = { "Tony", "Shmiley", NULL }; +const char *DLG163[] = { "Tony", "Shmiley", NULL }; +const char *DLG180[] = { "Tony", "Beast", NULL }; +const char *DLG190[] = { "Tony", "Beast", NULL }; +const char *DLG191[] = { "Tony", "Beast", NULL }; +const char *DLG201[] = { "Tony", NULL }; +const char *DLG210[] = { "Tony", "Mortimer", NULL }; +const char *DLG211[] = { "Tony", "Mortimer", NULL }; +const char *DLG212[] = { "Tony", "Mortimer", NULL }; +const char *DLG240[] = { "Tony", "Isabella", NULL }; +const char *DLG250[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; +const char *DLG251[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; +const char *DLG260[] = { "Tony", "Captain", "Captain (tale)", NULL }; +const char *DLG270[] = { "Tony", "Egghead", NULL }; +const char *DLG271[] = { "Tony", "Egghead", NULL }; +const char *DLG272[] = { "Tony", "Egghead", NULL }; +const char *DLG290[] = { "Tony", "Old lady 2", NULL }; +const char *DLG310[] = { "Tony", "Wally", NULL }; +const char *DLG330[] = { "Tony", "Polly", "Captain (off scene)", NULL }; +const char *DLG340[] = { "Tony", "Randall", NULL }; +const char *DLG360[] = { "Tony", NULL }; +const char *DLG361[] = { "Tony", NULL }; +const char *DLG370[] = { "Tony", "Gatekeeper", NULL }; +const char *DLG371[] = { "Tony", "Gatekeeper", NULL }; +const char *DLG372[] = { "Tony", "Gatekeeper", NULL }; +const char *DLG373[] = { "Tony", "Gatekeeper", NULL }; +const char *DLG380[] = { "Tony", NULL }; +const char *DLG410[] = { "Tony", "Gwendel", NULL }; +const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +const char *DLG460[] = { "Tony", NULL }; +const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG480[] = { "Tony", "Pin-up", NULL }; +const char *DLG490[] = { "Tony", "Gwendel", NULL }; +const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +const char *DLG550[] = { "Tony", "Mr. Wishing Well", "Tony (from the top of the well)", NULL }; +const char *DLG560[] = { "Tony", "Superintendent", NULL }; +const char *DLG590[] = { "Tony", "Pantagruel", NULL }; +const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Storyteller", "Mr. Wishing Well", NULL }; #endif #if 0 // Polish names -char *DLG10[] = { "Tony", NULL }; -char *DLG51[] = { "Tony", "Butch", "Dudley" }; -char *DLG52[] = { "Tony", NULL }; -char *DLG61[] = { "Tony", "Staruszka 1", NULL }; -char *DLG71[] = { "Tony", "Timothy", "Skazaniec", NULL, NULL, "£ebster (przez mikrofon)", "Staruszka 1", NULL }; -char *DLG90[] = { "Tony", "Kobieta z Brod¹", NULL }; -char *DLG110[] = { "Tony", "Lorenz", NULL }; -char *DLG111[] = { "Tony", "Lorenz", NULL }; -char *DLG130[] = { "Tony", "Pirania", NULL }; -char *DLG150[] = { "Tony", "Rufus", "Ba³wan", NULL }; -char *DLG151[] = { "Tony", "Rufus", "Ba³wan", NULL }; -char *DLG152[] = { "Tony", "Rufus", "Ba³wan", NULL }; -char *DLG153[] = { "Tony", "Rufus", "Ba³wan", NULL }; -char *DLG154[] = { "Tony", "Rufus", "Ba³wan", NULL }; -char *DLG160[] = { "Tony", "Œmiechozol", NULL }; -char *DLG161[] = { "Tony", "Œmiechozol", NULL }; -char *DLG162[] = { "Tony", "Œmiechozol", NULL }; -char *DLG163[] = { "Tony", "Œmiechozol", NULL }; -char *DLG180[] = { "Tony", "Wycz", NULL }; -char *DLG190[] = { "Tony", "Wycz", NULL }; -char *DLG191[] = { "Tony", "Wycz", NULL }; -char *DLG201[] = { "Tony", NULL }; -char *DLG210[] = { "Tony", "Mortimer (Okropny)", NULL }; -char *DLG211[] = { "Tony", "Mortimer (Okropny)", NULL }; -char *DLG212[] = { "Tony", "Mortimer (Okropny)", NULL }; -char *DLG240[] = { "Tony", "Isabella", NULL }; -char *DLG250[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; -char *DLG251[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; -char *DLG260[] = { "Tony", "Kapitan", "Captain (opowieœæ)", NULL }; -char *DLG270[] = { "Tony", "Jajog³owy", NULL }; -char *DLG271[] = { "Tony", "Jajog³owy", NULL }; -char *DLG272[] = { "Tony", "Jajog³owy", NULL }; -char *DLG290[] = { "Tony", "Staruszka 2", NULL }; -char *DLG310[] = { "Tony", "Wally", NULL }; -char *DLG330[] = { "Tony", "Polly", "Kapitan (zza sceny)", NULL }; -char *DLG340[] = { "Tony", "Randall", NULL }; -char *DLG360[] = { "Tony", NULL }; -char *DLG361[] = { "Tony", NULL }; -char *DLG370[] = { "Tony", "Stra¿nik", NULL }; -char *DLG371[] = { "Tony", "Stra¿nik", NULL }; -char *DLG372[] = { "Tony", "Stra¿nik", NULL }; -char *DLG373[] = { "Tony", "Stra¿nik", NULL }; -char *DLG380[] = { "Tony", NULL }; -char *DLG410[] = { "Tony", "Gwendel", NULL }; -char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Gospodyni (zza sceny)", NULL }; -char *DLG460[] = { "Tony", NULL }; -char *DLG470[] = { "Tony", "Gospodyni", "Mirror", NULL }; -char *DLG471[] = { "Tony", "Gospodyni", "Mirror", NULL }; -char *DLG472[] = { "Tony", "Gospodyni", "Mirror", NULL }; -char *DLG473[] = { "Tony", "Gospodyni", "Mirror", NULL }; -char *DLG474[] = { "Tony", "Gospodyni", "Mirror", NULL }; -char *DLG480[] = { "Tony", "Pin-up", NULL }; -char *DLG490[] = { "Tony", "Gwendel", NULL }; -char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -char *DLG550[] = { "Tony", "Pan Studnia ¯yczeñ", "Tony (nad studni¹)", NULL }; -char *DLG560[] = { "Tony", "Inspektor", NULL }; -char *DLG590[] = { "Tony", "Pantaloniarz", NULL }; -char *DLG600[] = { "Tony", "£ebster", "£ebster", NULL, "£ebster", NULL, NULL, NULL, "Narrator", "Pan Studnia ¯yczeñ", NULL }; +const char *DLG10[] = { "Tony", NULL }; +const char *DLG51[] = { "Tony", "Butch", "Dudley" }; +const char *DLG52[] = { "Tony", NULL }; +const char *DLG61[] = { "Tony", "Staruszka 1", NULL }; +const char *DLG71[] = { "Tony", "Timothy", "Skazaniec", NULL, NULL, "£ebster (przez mikrofon)", "Staruszka 1", NULL }; +const char *DLG90[] = { "Tony", "Kobieta z Brod¹", NULL }; +const char *DLG110[] = { "Tony", "Lorenz", NULL }; +const char *DLG111[] = { "Tony", "Lorenz", NULL }; +const char *DLG130[] = { "Tony", "Pirania", NULL }; +const char *DLG150[] = { "Tony", "Rufus", "Ba³wan", NULL }; +const char *DLG151[] = { "Tony", "Rufus", "Ba³wan", NULL }; +const char *DLG152[] = { "Tony", "Rufus", "Ba³wan", NULL }; +const char *DLG153[] = { "Tony", "Rufus", "Ba³wan", NULL }; +const char *DLG154[] = { "Tony", "Rufus", "Ba³wan", NULL }; +const char *DLG160[] = { "Tony", "Œmiechozol", NULL }; +const char *DLG161[] = { "Tony", "Œmiechozol", NULL }; +const char *DLG162[] = { "Tony", "Œmiechozol", NULL }; +const char *DLG163[] = { "Tony", "Œmiechozol", NULL }; +const char *DLG180[] = { "Tony", "Wycz", NULL }; +const char *DLG190[] = { "Tony", "Wycz", NULL }; +const char *DLG191[] = { "Tony", "Wycz", NULL }; +const char *DLG201[] = { "Tony", NULL }; +const char *DLG210[] = { "Tony", "Mortimer (Okropny)", NULL }; +const char *DLG211[] = { "Tony", "Mortimer (Okropny)", NULL }; +const char *DLG212[] = { "Tony", "Mortimer (Okropny)", NULL }; +const char *DLG240[] = { "Tony", "Isabella", NULL }; +const char *DLG250[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; +const char *DLG251[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; +const char *DLG260[] = { "Tony", "Kapitan", "Captain (opowieœæ)", NULL }; +const char *DLG270[] = { "Tony", "Jajog³owy", NULL }; +const char *DLG271[] = { "Tony", "Jajog³owy", NULL }; +const char *DLG272[] = { "Tony", "Jajog³owy", NULL }; +const char *DLG290[] = { "Tony", "Staruszka 2", NULL }; +const char *DLG310[] = { "Tony", "Wally", NULL }; +const char *DLG330[] = { "Tony", "Polly", "Kapitan (zza sceny)", NULL }; +const char *DLG340[] = { "Tony", "Randall", NULL }; +const char *DLG360[] = { "Tony", NULL }; +const char *DLG361[] = { "Tony", NULL }; +const char *DLG370[] = { "Tony", "Stra¿nik", NULL }; +const char *DLG371[] = { "Tony", "Stra¿nik", NULL }; +const char *DLG372[] = { "Tony", "Stra¿nik", NULL }; +const char *DLG373[] = { "Tony", "Stra¿nik", NULL }; +const char *DLG380[] = { "Tony", NULL }; +const char *DLG410[] = { "Tony", "Gwendel", NULL }; +const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Gospodyni (zza sceny)", NULL }; +const char *DLG460[] = { "Tony", NULL }; +const char *DLG470[] = { "Tony", "Gospodyni", "Mirror", NULL }; +const char *DLG471[] = { "Tony", "Gospodyni", "Mirror", NULL }; +const char *DLG472[] = { "Tony", "Gospodyni", "Mirror", NULL }; +const char *DLG473[] = { "Tony", "Gospodyni", "Mirror", NULL }; +const char *DLG474[] = { "Tony", "Gospodyni", "Mirror", NULL }; +const char *DLG480[] = { "Tony", "Pin-up", NULL }; +const char *DLG490[] = { "Tony", "Gwendel", NULL }; +const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +const char *DLG550[] = { "Tony", "Pan Studnia ¯yczeñ", "Tony (nad studni¹)", NULL }; +const char *DLG560[] = { "Tony", "Inspektor", NULL }; +const char *DLG590[] = { "Tony", "Pantaloniarz", NULL }; +const char *DLG600[] = { "Tony", "£ebster", "£ebster", NULL, "£ebster", NULL, NULL, NULL, "Narrator", "Pan Studnia ¯yczeñ", NULL }; #endif // Polish #if 0 // Russian -char *DLG10[] = { "Òîíè", NULL }; -char *DLG51[] = { "Òîíè", "Áó÷", "Äàäëè" }; -char *DLG52[] = { "Òîíè", NULL }; -char *DLG61[] = { "Òîíè", "Ñòàðóøêà 1", NULL }; -char *DLG71[] = { "Òîíè", "Òèìîòè", "Îñóæäåííûé", NULL, NULL, "Äæåê (ñ ìèêðîôîíîì)", "Ñòàðóøêà 1", NULL }; -char *DLG90[] = { "Òîíè", "Áîðîäàòàÿ æåíùèíà", NULL }; -char *DLG110[] = { "Òîíè", "Ëîðåíö", NULL }; -char *DLG111[] = { "Òîíè", "Ëîðåíö", NULL }; -char *DLG130[] = { "Òîíè", "Ïèðàíüÿ", NULL }; -char *DLG150[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -char *DLG151[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -char *DLG152[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -char *DLG153[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -char *DLG154[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -char *DLG160[] = { "Òîíè", "Øìàéëè", NULL }; -char *DLG161[] = { "Òîíè", "Øìàéëè", NULL }; -char *DLG162[] = { "Òîíè", "Øìàéëè", NULL }; -char *DLG163[] = { "Òîíè", "Øìàéëè", NULL }; -char *DLG180[] = { "Òîíè", "×óäîâèùå", NULL }; -char *DLG190[] = { "Òîíè", "×óäîâèùå", NULL }; -char *DLG191[] = { "Òîíè", "×óäîâèùå", NULL }; -char *DLG201[] = { "Òîíè", NULL }; -char *DLG210[] = { "Òîíè", "Ìîðòèìåð", NULL }; -char *DLG211[] = { "Òîíè", "Ìîðòèìåð", NULL }; -char *DLG212[] = { "Òîíè", "Ìîðòèìåð", NULL }; -char *DLG240[] = { "Òîíè", "Èçàáåëëà", NULL }; -char *DLG250[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; -char *DLG251[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; -char *DLG260[] = { "Òîíè", "Êàïèòàí", "Êàïèòàí (ðàññêàç)", NULL }; -char *DLG270[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -char *DLG271[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -char *DLG272[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -char *DLG290[] = { "Òîíè", "Ñòàðóøêà 2", NULL }; -char *DLG310[] = { "Òîíè", "Óîëëè", NULL }; -char *DLG330[] = { "Òîíè", "Ïîëëè", "Êàïèòàí (çà ñöåíîé)", NULL }; -char *DLG340[] = { "Òîíè", "Ðýíäàë", NULL }; -char *DLG360[] = { "Òîíè", NULL }; -char *DLG361[] = { "Òîíè", NULL }; -char *DLG370[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -char *DLG371[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -char *DLG372[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -char *DLG373[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -char *DLG380[] = { "Òîíè", NULL }; -char *DLG410[] = { "Òîíè", "Ãâåíäåëü", NULL }; -char *DLG430[] = { "Òîíè", "Ãàðîëüä", "×àê", "Pigeons", "Housekeeper (off scene)", NULL }; -char *DLG460[] = { "Òîíè", NULL }; -char *DLG470[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -char *DLG471[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -char *DLG472[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -char *DLG473[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -char *DLG474[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -char *DLG480[] = { "Òîíè", "Pin-up", NULL }; -char *DLG490[] = { "Òîíè", "Ãâåíäåëü", NULL }; -char *DLG530[] = { "Òîíè", "Ãàðîëüä", "×àê", NULL }; -char *DLG550[] = { "Òîíè", "Ãîñïîäèí Êîëîäåö æåëàíèé", "Òîíè (ñ âåðøèíû êîëîäöà)", NULL }; -char *DLG560[] = { "Òîíè", "Íà÷àëüíèê îõðàíû", NULL }; -char *DLG590[] = { "Òîíè", "Ïàíòàãðþýëü", NULL }; -char *DLG600[] = { "Òîíè", "Äæåê", "Äæåê", NULL, "Äæåê", NULL, NULL, NULL, "Ðàññêàç÷èê", "Ãîñïîäèí Êîëîäåö æåëàíèé", NULL }; +const char *DLG10[] = { "Òîíè", NULL }; +const char *DLG51[] = { "Òîíè", "Áó÷", "Äàäëè" }; +const char *DLG52[] = { "Òîíè", NULL }; +const char *DLG61[] = { "Òîíè", "Ñòàðóøêà 1", NULL }; +const char *DLG71[] = { "Òîíè", "Òèìîòè", "Îñóæäåííûé", NULL, NULL, "Äæåê (ñ ìèêðîôîíîì)", "Ñòàðóøêà 1", NULL }; +const char *DLG90[] = { "Òîíè", "Áîðîäàòàÿ æåíùèíà", NULL }; +const char *DLG110[] = { "Òîíè", "Ëîðåíö", NULL }; +const char *DLG111[] = { "Òîíè", "Ëîðåíö", NULL }; +const char *DLG130[] = { "Òîíè", "Ïèðàíüÿ", NULL }; +const char *DLG150[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +const char *DLG151[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +const char *DLG152[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +const char *DLG153[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +const char *DLG154[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; +const char *DLG160[] = { "Òîíè", "Øìàéëè", NULL }; +const char *DLG161[] = { "Òîíè", "Øìàéëè", NULL }; +const char *DLG162[] = { "Òîíè", "Øìàéëè", NULL }; +const char *DLG163[] = { "Òîíè", "Øìàéëè", NULL }; +const char *DLG180[] = { "Òîíè", "×óäîâèùå", NULL }; +const char *DLG190[] = { "Òîíè", "×óäîâèùå", NULL }; +const char *DLG191[] = { "Òîíè", "×óäîâèùå", NULL }; +const char *DLG201[] = { "Òîíè", NULL }; +const char *DLG210[] = { "Òîíè", "Ìîðòèìåð", NULL }; +const char *DLG211[] = { "Òîíè", "Ìîðòèìåð", NULL }; +const char *DLG212[] = { "Òîíè", "Ìîðòèìåð", NULL }; +const char *DLG240[] = { "Òîíè", "Èçàáåëëà", NULL }; +const char *DLG250[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; +const char *DLG251[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; +const char *DLG260[] = { "Òîíè", "Êàïèòàí", "Êàïèòàí (ðàññêàç)", NULL }; +const char *DLG270[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +const char *DLG271[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +const char *DLG272[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; +const char *DLG290[] = { "Òîíè", "Ñòàðóøêà 2", NULL }; +const char *DLG310[] = { "Òîíè", "Óîëëè", NULL }; +const char *DLG330[] = { "Òîíè", "Ïîëëè", "Êàïèòàí (çà ñöåíîé)", NULL }; +const char *DLG340[] = { "Òîíè", "Ðýíäàë", NULL }; +const char *DLG360[] = { "Òîíè", NULL }; +const char *DLG361[] = { "Òîíè", NULL }; +const char *DLG370[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +const char *DLG371[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +const char *DLG372[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +const char *DLG373[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; +const char *DLG380[] = { "Òîíè", NULL }; +const char *DLG410[] = { "Òîíè", "Ãâåíäåëü", NULL }; +const char *DLG430[] = { "Òîíè", "Ãàðîëüä", "×àê", "Pigeons", "Housekeeper (off scene)", NULL }; +const char *DLG460[] = { "Òîíè", NULL }; +const char *DLG470[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +const char *DLG471[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +const char *DLG472[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +const char *DLG473[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +const char *DLG474[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; +const char *DLG480[] = { "Òîíè", "Pin-up", NULL }; +const char *DLG490[] = { "Òîíè", "Ãâåíäåëü", NULL }; +const char *DLG530[] = { "Òîíè", "Ãàðîëüä", "×àê", NULL }; +const char *DLG550[] = { "Òîíè", "Ãîñïîäèí Êîëîäåö æåëàíèé", "Òîíè (ñ âåðøèíû êîëîäöà)", NULL }; +const char *DLG560[] = { "Òîíè", "Íà÷àëüíèê îõðàíû", NULL }; +const char *DLG590[] = { "Òîíè", "Ïàíòàãðþýëü", NULL }; +const char *DLG600[] = { "Òîíè", "Äæåê", "Äæåê", NULL, "Äæåê", NULL, NULL, NULL, "Ðàññêàç÷èê", "Ãîñïîäèí Êîëîäåö æåëàíèé", NULL }; #endif // Russian #if 0 // Czech names -char *DLG10[] = { "Tony", NULL }; -char *DLG51[] = { "Tony", "Butch", "Dudley" }; -char *DLG52[] = { "Tony", NULL }; -char *DLG61[] = { "Tony", "Stará paní 1", NULL }; -char *DLG71[] = { "Tony", "Timothy", "Trestanec", NULL, NULL, "Jack (s mikrofonem)", "Stará paní 1", NULL }; -char *DLG90[] = { "Tony", "Vousatá žena", NULL }; -char *DLG110[] = { "Tony", "Lorenz", NULL }; -char *DLG111[] = { "Tony", "Lorenz", NULL }; -char *DLG130[] = { "Tony", "Piraòa", NULL }; -char *DLG150[] = { "Tony", "Rufus", "Snìhulák", NULL }; -char *DLG151[] = { "Tony", "Rufus", "Snìhulák", NULL }; -char *DLG152[] = { "Tony", "Rufus", "Snìhulák", NULL }; -char *DLG153[] = { "Tony", "Rufus", "Snìhulák", NULL }; -char *DLG154[] = { "Tony", "Rufus", "Snìhulák", NULL }; -char *DLG160[] = { "Tony", "Shmiley", NULL }; -char *DLG161[] = { "Tony", "Shmiley", NULL }; -char *DLG162[] = { "Tony", "Shmiley", NULL }; -char *DLG163[] = { "Tony", "Shmiley", NULL }; -char *DLG180[] = { "Tony", "Zvíøe", NULL }; -char *DLG190[] = { "Tony", "Zvíøe", NULL }; -char *DLG191[] = { "Tony", "Zvíøe", NULL }; -char *DLG201[] = { "Tony", NULL }; -char *DLG210[] = { "Tony", "Mortimer", NULL }; -char *DLG211[] = { "Tony", "Mortimer", NULL }; -char *DLG212[] = { "Tony", "Mortimer", NULL }; -char *DLG240[] = { "Tony", "Isabella", NULL }; -char *DLG250[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; -char *DLG251[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; -char *DLG260[] = { "Tony", "Kapitán", "Kapitán (pøíbìh)", NULL }; -char *DLG270[] = { "Tony", "Intelektuál", NULL }; -char *DLG271[] = { "Tony", "Intelektuál", NULL }; -char *DLG272[] = { "Tony", "Intelektuál", NULL }; -char *DLG290[] = { "Tony", "Stará paní 2", NULL }; -char *DLG310[] = { "Tony", "Wally", NULL }; -char *DLG330[] = { "Tony", "Lóra", "Kapitán (mimo scénu)", NULL }; -char *DLG340[] = { "Tony", "Randall", NULL }; -char *DLG360[] = { "Tony", NULL }; -char *DLG361[] = { "Tony", NULL }; -char *DLG370[] = { "Tony", "Strážný", NULL }; -char *DLG371[] = { "Tony", "Strážný", NULL }; -char *DLG372[] = { "Tony", "Strážný", NULL }; -char *DLG373[] = { "Tony", "Strážný", NULL }; -char *DLG380[] = { "Tony", NULL }; -char *DLG410[] = { "Tony", "Gwendel", NULL }; -char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -char *DLG460[] = { "Tony", NULL }; -char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG480[] = { "Tony", "Pin-up", NULL }; -char *DLG490[] = { "Tony", "Gwendel", NULL }; -char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -char *DLG550[] = { "Tony", "Pan Studna pøání", "Tony (z vrcholu studny)", NULL }; -char *DLG560[] = { "Tony", "Správce", NULL }; -char *DLG590[] = { "Tony", "Pantagruel", NULL }; -char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Vypravìè", "Pan Studna pøání", NULL }; +const char *DLG10[] = { "Tony", NULL }; +const char *DLG51[] = { "Tony", "Butch", "Dudley" }; +const char *DLG52[] = { "Tony", NULL }; +const char *DLG61[] = { "Tony", "Stará paní 1", NULL }; +const char *DLG71[] = { "Tony", "Timothy", "Trestanec", NULL, NULL, "Jack (s mikrofonem)", "Stará paní 1", NULL }; +const char *DLG90[] = { "Tony", "Vousatá žena", NULL }; +const char *DLG110[] = { "Tony", "Lorenz", NULL }; +const char *DLG111[] = { "Tony", "Lorenz", NULL }; +const char *DLG130[] = { "Tony", "Piraòa", NULL }; +const char *DLG150[] = { "Tony", "Rufus", "Snìhulák", NULL }; +const char *DLG151[] = { "Tony", "Rufus", "Snìhulák", NULL }; +const char *DLG152[] = { "Tony", "Rufus", "Snìhulák", NULL }; +const char *DLG153[] = { "Tony", "Rufus", "Snìhulák", NULL }; +const char *DLG154[] = { "Tony", "Rufus", "Snìhulák", NULL }; +const char *DLG160[] = { "Tony", "Shmiley", NULL }; +const char *DLG161[] = { "Tony", "Shmiley", NULL }; +const char *DLG162[] = { "Tony", "Shmiley", NULL }; +const char *DLG163[] = { "Tony", "Shmiley", NULL }; +const char *DLG180[] = { "Tony", "Zvíøe", NULL }; +const char *DLG190[] = { "Tony", "Zvíøe", NULL }; +const char *DLG191[] = { "Tony", "Zvíøe", NULL }; +const char *DLG201[] = { "Tony", NULL }; +const char *DLG210[] = { "Tony", "Mortimer", NULL }; +const char *DLG211[] = { "Tony", "Mortimer", NULL }; +const char *DLG212[] = { "Tony", "Mortimer", NULL }; +const char *DLG240[] = { "Tony", "Isabella", NULL }; +const char *DLG250[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; +const char *DLG251[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; +const char *DLG260[] = { "Tony", "Kapitán", "Kapitán (pøíbìh)", NULL }; +const char *DLG270[] = { "Tony", "Intelektuál", NULL }; +const char *DLG271[] = { "Tony", "Intelektuál", NULL }; +const char *DLG272[] = { "Tony", "Intelektuál", NULL }; +const char *DLG290[] = { "Tony", "Stará paní 2", NULL }; +const char *DLG310[] = { "Tony", "Wally", NULL }; +const char *DLG330[] = { "Tony", "Lóra", "Kapitán (mimo scénu)", NULL }; +const char *DLG340[] = { "Tony", "Randall", NULL }; +const char *DLG360[] = { "Tony", NULL }; +const char *DLG361[] = { "Tony", NULL }; +const char *DLG370[] = { "Tony", "Strážný", NULL }; +const char *DLG371[] = { "Tony", "Strážný", NULL }; +const char *DLG372[] = { "Tony", "Strážný", NULL }; +const char *DLG373[] = { "Tony", "Strážný", NULL }; +const char *DLG380[] = { "Tony", NULL }; +const char *DLG410[] = { "Tony", "Gwendel", NULL }; +const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +const char *DLG460[] = { "Tony", NULL }; +const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG480[] = { "Tony", "Pin-up", NULL }; +const char *DLG490[] = { "Tony", "Gwendel", NULL }; +const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +const char *DLG550[] = { "Tony", "Pan Studna pøání", "Tony (z vrcholu studny)", NULL }; +const char *DLG560[] = { "Tony", "Správce", NULL }; +const char *DLG590[] = { "Tony", "Pantagruel", NULL }; +const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Vypravìè", "Pan Studna pøání", NULL }; #endif // Czech names #if 1 // Deutsch names -char *DLG10[] = { "Tony", NULL }; -char *DLG51[] = { "Tony", "Butch", "Dudley" }; -char *DLG52[] = { "Tony", NULL }; -char *DLG61[] = { "Tony", "Alte Dame 1", NULL }; -char *DLG71[] = { "Tony", "Timothy", "Sträfling", NULL, NULL, "Jack (mit Mikrofon)", "Alte Dame 1", NULL }; -char *DLG90[] = { "Tony", "Bärtige Dame", NULL }; -char *DLG110[] = { "Tony", "Lorenz", NULL }; -char *DLG111[] = { "Tony", "Lorenz", NULL }; -char *DLG130[] = { "Tony", "Piranha", NULL }; -char *DLG150[] = { "Tony", "Rufus", "Schneemann", NULL }; -char *DLG151[] = { "Tony", "Rufus", "Schneemann", NULL }; -char *DLG152[] = { "Tony", "Rufus", "Schneemann", NULL }; -char *DLG153[] = { "Tony", "Rufus", "Schneemann", NULL }; -char *DLG154[] = { "Tony", "Rufus", "Schneemann", NULL }; -char *DLG160[] = { "Tony", "Shmiley", NULL }; -char *DLG161[] = { "Tony", "Shmiley", NULL }; -char *DLG162[] = { "Tony", "Shmiley", NULL }; -char *DLG163[] = { "Tony", "Shmiley", NULL }; -char *DLG180[] = { "Tony", "Biest", NULL }; -char *DLG190[] = { "Tony", "Biest", NULL }; -char *DLG191[] = { "Tony", "Biest", NULL }; -char *DLG201[] = { "Tony", NULL }; -char *DLG210[] = { "Tony", "Mortimer", NULL }; -char *DLG211[] = { "Tony", "Mortimer", NULL }; -char *DLG212[] = { "Tony", "Mortimer", NULL }; -char *DLG240[] = { "Tony", "Isabella", NULL }; -char *DLG250[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; -char *DLG251[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; -char *DLG260[] = { "Tony", "Kapitän", "Kapitän (Erzählung)", NULL }; -char *DLG270[] = { "Tony", "Eierkopf", NULL }; -char *DLG271[] = { "Tony", "Eierkopf", NULL }; -char *DLG272[] = { "Tony", "Eierkopf", NULL }; -char *DLG290[] = { "Tony", "Alte Dame 2", NULL }; -char *DLG310[] = { "Tony", "Wally", NULL }; -char *DLG330[] = { "Tony", "Polly", "Kapitän (im Off)", NULL }; -char *DLG340[] = { "Tony", "Randall", NULL }; -char *DLG360[] = { "Tony", NULL }; -char *DLG361[] = { "Tony", NULL }; -char *DLG370[] = { "Tony", "Pförtner", NULL }; -char *DLG371[] = { "Tony", "Pförtner", NULL }; -char *DLG372[] = { "Tony", "Pförtner", NULL }; -char *DLG373[] = { "Tony", "Pförtner", NULL }; -char *DLG380[] = { "Tony", NULL }; -char *DLG410[] = { "Tony", "Gwendel", NULL }; -char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -char *DLG460[] = { "Tony", NULL }; -char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -char *DLG480[] = { "Tony", "Pin-up", NULL }; -char *DLG490[] = { "Tony", "Gwendel", NULL }; -char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -char *DLG550[] = { "Tony", "Herr Wunschbrunnen", "Tony (über dem Brunnen)", NULL }; -char *DLG560[] = { "Tony", "Verwalter", NULL }; -char *DLG590[] = { "Tony", "Pantagruel", NULL }; -char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Erzähler", "Herr Wunschbrunnen", NULL }; +const char *DLG10[] = { "Tony", NULL }; +const char *DLG51[] = { "Tony", "Butch", "Dudley" }; +const char *DLG52[] = { "Tony", NULL }; +const char *DLG61[] = { "Tony", "Alte Dame 1", NULL }; +const char *DLG71[] = { "Tony", "Timothy", "Sträfling", NULL, NULL, "Jack (mit Mikrofon)", "Alte Dame 1", NULL }; +const char *DLG90[] = { "Tony", "Bärtige Dame", NULL }; +const char *DLG110[] = { "Tony", "Lorenz", NULL }; +const char *DLG111[] = { "Tony", "Lorenz", NULL }; +const char *DLG130[] = { "Tony", "Piranha", NULL }; +const char *DLG150[] = { "Tony", "Rufus", "Schneemann", NULL }; +const char *DLG151[] = { "Tony", "Rufus", "Schneemann", NULL }; +const char *DLG152[] = { "Tony", "Rufus", "Schneemann", NULL }; +const char *DLG153[] = { "Tony", "Rufus", "Schneemann", NULL }; +const char *DLG154[] = { "Tony", "Rufus", "Schneemann", NULL }; +const char *DLG160[] = { "Tony", "Shmiley", NULL }; +const char *DLG161[] = { "Tony", "Shmiley", NULL }; +const char *DLG162[] = { "Tony", "Shmiley", NULL }; +const char *DLG163[] = { "Tony", "Shmiley", NULL }; +const char *DLG180[] = { "Tony", "Biest", NULL }; +const char *DLG190[] = { "Tony", "Biest", NULL }; +const char *DLG191[] = { "Tony", "Biest", NULL }; +const char *DLG201[] = { "Tony", NULL }; +const char *DLG210[] = { "Tony", "Mortimer", NULL }; +const char *DLG211[] = { "Tony", "Mortimer", NULL }; +const char *DLG212[] = { "Tony", "Mortimer", NULL }; +const char *DLG240[] = { "Tony", "Isabella", NULL }; +const char *DLG250[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; +const char *DLG251[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; +const char *DLG260[] = { "Tony", "Kapitän", "Kapitän (Erzählung)", NULL }; +const char *DLG270[] = { "Tony", "Eierkopf", NULL }; +const char *DLG271[] = { "Tony", "Eierkopf", NULL }; +const char *DLG272[] = { "Tony", "Eierkopf", NULL }; +const char *DLG290[] = { "Tony", "Alte Dame 2", NULL }; +const char *DLG310[] = { "Tony", "Wally", NULL }; +const char *DLG330[] = { "Tony", "Polly", "Kapitän (im Off)", NULL }; +const char *DLG340[] = { "Tony", "Randall", NULL }; +const char *DLG360[] = { "Tony", NULL }; +const char *DLG361[] = { "Tony", NULL }; +const char *DLG370[] = { "Tony", "Pförtner", NULL }; +const char *DLG371[] = { "Tony", "Pförtner", NULL }; +const char *DLG372[] = { "Tony", "Pförtner", NULL }; +const char *DLG373[] = { "Tony", "Pförtner", NULL }; +const char *DLG380[] = { "Tony", NULL }; +const char *DLG410[] = { "Tony", "Gwendel", NULL }; +const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; +const char *DLG460[] = { "Tony", NULL }; +const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; +const char *DLG480[] = { "Tony", "Pin-up", NULL }; +const char *DLG490[] = { "Tony", "Gwendel", NULL }; +const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; +const char *DLG550[] = { "Tony", "Herr Wunschbrunnen", "Tony (über dem Brunnen)", NULL }; +const char *DLG560[] = { "Tony", "Verwalter", NULL }; +const char *DLG590[] = { "Tony", "Pantagruel", NULL }; +const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Erzähler", "Herr Wunschbrunnen", NULL }; #endif @@ -2902,7 +2903,7 @@ case num: \ return DLG##num[nPers]; -char *GetPersonName(uint16 nDlg, int nPers) { +const char *GetPersonName(uint16 nDlg, int nPers) { switch (nDlg) { HANDLE_DIALOG(10); HANDLE_DIALOG(51); @@ -2964,7 +2965,7 @@ char *GetPersonName(uint16 nDlg, int nPers) { HANDLE_DIALOG(600); default: - warning("ERROR: Il dialogo %d non esiste!\n", nDlg); + warning("ERROR: Il dialogo %d non esiste!\n", (int)nDlg); return "ERROR"; } } diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 26c4283018..d800be60b8 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -595,7 +595,7 @@ extern "C" { * \****************************************************************************/ -bool EXPORT mpalInit(LPSTR lpszFileName, LPSTR lpszMprFileName, +bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray); -- cgit v1.2.3 From 9c2ccc4f9c0f4e27209ac876bf2112fd2a6e2987 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 22:39:30 +1000 Subject: TONY: Further bugfixes for gcc warnings --- engines/tony/mpal/mpal.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index d767dbe381..55d70b2e18 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -97,7 +97,6 @@ typedef LPCFCALL* LPLPCFCALL; uint32 mpalError; -static bool bInit=false; static byte * lpMpcImage; LPITEMIRQFUNCTION lpiifCustom=NULL; @@ -786,11 +785,11 @@ static LPITEM GetItemData(uint32 nOrdItem) { patlength = dat; dat+=ret->numpattern; - for (i=1;inumpattern;i++) { - for (j=0;jpattern[i][j]=dat[j]; - ret->pattern[i][patlength[i]]=255; // Termina i pattern - dat+=patlength[i]; + for (i = 1; i < ret->numpattern; i++) { + for (j = 0; j < patlength[i]; j++) + ret->pattern[i][j] = dat[j]; + ret->pattern[i][(int)patlength[i]] = 255; // Termina i pattern + dat += patlength[i]; } // Carica i singoli frame di animazione @@ -2284,9 +2283,9 @@ bool bDontOutput; struct MsgCommentsStruct { uint16 wStart; uint16 wEnd; - char *pComment; + const char *pComment; }; -MsgCommentsStruct MsgComments[] = { +const MsgCommentsStruct MsgComments[] = { { 10, 16, "###" }, { 560, 563, "@@@ BUTCH & DUDLEY:" }, { 551, 553, "@@@ JACK'S LETTER (JACK'S VOICE):" }, @@ -2894,7 +2893,7 @@ const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, #define HANDLE_DIALOG(num) \ case num: \ - if (nPers >= sizeof(DLG##num) / sizeof(char*) || DLG##num[nPers]==NULL) \ + if (nPers >= (int)(sizeof(DLG##num) / sizeof(const char *)) || DLG##num[nPers] == NULL) \ { \ warning("ERROR: Il personaggio #%d non esiste nel dialogo %d!\n", nPers, nDlg); \ return "ERROR"; \ -- cgit v1.2.3 From 3184a5a874f3cfaa75424e7efb21f1cca3702988 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 22:58:42 +1000 Subject: TONY: Fix warnings about return values not being used --- engines/tony/mpal/mpal.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index d800be60b8..e66f1fdb7e 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -523,7 +523,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDialogSelection(nChoice,dwData) \ (bool)mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) - +#define mpalQueryDialogSelectionU32(nChoice, dwData) \ + mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) /****************************************************************************\ * @@ -547,9 +548,11 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * \****************************************************************************/ -#define mpalQueryDoAction(nAction,nItem,dwParam) \ - (HANDLE)mpalQuery(MPQ_DO_ACTION,(uint32)(nAction),(uint32)(nItem),(uint32)(dwParam)) +#define mpalQueryDoAction(nAction, nItem, dwParam) \ + (HANDLE)mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) +#define mpalQueryDoActionU32(nAction, nItem, dwParam) \ + mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) /****************************************************************************\ @@ -569,6 +572,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDoDialog(nDialog,nGroup) \ (HANDLE)mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup)) +#define mpalQueryDoDialogU32(nDialog, nGroup) \ + mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup)) /****************************************************************************\ -- cgit v1.2.3 From e628da0cccbba04c9d19b28b46e97107ab66beb7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 23:20:01 +1000 Subject: TONY: Fix some inconsistent allocation/deallocations --- engines/tony/mpal/memory.cpp | 6 +++--- engines/tony/mpal/memory.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 604e61ed24..de6e918a38 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -127,9 +127,9 @@ uint32 MemoryManager::getSize(HGLOBAL handle) { /** * Erases a given item */ -void MemoryManager::erase(MemoryItem &item) { +void MemoryManager::erase(MemoryItem *item) { delete item; - _memoryBlocks.remove(&item); + _memoryBlocks.remove(item); } /** @@ -137,7 +137,7 @@ void MemoryManager::erase(MemoryItem &item) { */ void MemoryManager::erase(HGLOBAL handle) { MemoryItem &item = getItem(handle); - erase(item); + erase(&item); } } // end of namespace MPAL diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index fde0d33b3e..ebf42b6207 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -36,14 +36,14 @@ typedef HANDLE HGLOBAL; class MemoryItem { protected: - void *_buffer; + byte *_buffer; uint32 _size; public: MemoryItem(uint32 size); virtual ~MemoryItem(); uint32 Size() { return _size; } - void *DataPointer() { return _buffer; } + void *DataPointer() { return (void *)_buffer; } bool IsValid() { return _buffer != NULL; } // Casting for access to data @@ -61,7 +61,7 @@ public: HGLOBAL alloc(uint32 size); MemoryItem &getItem(HGLOBAL handle); MemoryItem &operator[](HGLOBAL handle); - void erase(MemoryItem &item); + void erase(MemoryItem *item); void erase(HGLOBAL handle); uint32 getSize(HANDLE handle); -- cgit v1.2.3 From 5ab27cdacd0b93e4c1de613833edf1894820d2b4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 May 2012 23:38:34 +1000 Subject: TONY: Fix Valgrind identified leaks in memory allocator and dialog parsing --- engines/tony/mpal/loadmpc.cpp | 115 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 56 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 484f1ad2a0..c88f485b95 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -66,7 +66,7 @@ namespace MPAL { static bool CompareCommands(struct command *cmd1, struct command *cmd2) { if (cmd1->type == 2 && cmd2->type == 2) { - if (strcmp(cmd1->lpszVarName,cmd2->lpszVarName)==0 && + if (strcmp(cmd1->lpszVarName, cmd2->lpszVarName) == 0 && CompareExpressions(cmd1->expr,cmd2->expr)) return true; else @@ -169,94 +169,97 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 curCmd; uint32 len; - lpmdDialog->nObj=*(int *)lpBuf; - lpBuf+=4; + lpmdDialog->nObj = READ_LE_UINT32(lpBuf); + lpBuf += 4; /* Periodi */ - num=*(uint16 *)lpBuf; lpBuf+=2; + num = READ_LE_UINT16(lpBuf); lpBuf += 2; - if (num >= MAX_PERIODS_PER_DIALOG-1) { - Common::String msg = Common::String::format("Too much periods in dialog #%d",lpmdDialog->nObj); + if (num >= MAX_PERIODS_PER_DIALOG - 1) { + Common::String msg = Common::String::format("Too much periods in dialog #%d", lpmdDialog->nObj); MessageBox(msg); } - for (i=0;iPeriodNums[i]=*(uint16 *)lpBuf; lpBuf+=2; - lpmdDialog->Periods[i]=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,*lpBuf+1); + for (i = 0; i < num; i++) { + lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Periods[i] = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); lpLock = (byte *)GlobalLock(lpmdDialog->Periods[i]); - CopyMemory(lpLock,lpBuf+1,*lpBuf); + Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock); + lpLock[*lpBuf] = '\0'; GlobalUnlock(lpmdDialog->Periods[i]); - lpBuf+=(*lpBuf)+1; + lpBuf += (*lpBuf) + 1; } - lpmdDialog->PeriodNums[i]=0; - lpmdDialog->Periods[i]=NULL; + lpmdDialog->PeriodNums[i] = 0; + lpmdDialog->Periods[i] = NULL; /* Gruppi */ - num=*(uint16 *)lpBuf; lpBuf+=2; - curCmd=0; + num = READ_LE_UINT16(lpBuf); lpBuf += 2; + curCmd = 0; if (num >= MAX_GROUPS_PER_DIALOG) { - Common::String msg = Common::String::format("Too much groups in dialog #%d",lpmdDialog->nObj); + Common::String msg = Common::String::format("Too much groups in dialog #%d", lpmdDialog->nObj); MessageBox(msg); } - for (i=0;iGroup[i].num=*(uint16 *)lpBuf; lpBuf+=2; - lpmdDialog->Group[i].nCmds=*lpBuf; lpBuf++; + for (i = 0; i < num; i++) { + lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++; if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) { Common::String msg = Common::String::format("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); MessageBox(msg); } - for (j=0;jGroup[i].nCmds;j++) { - lpmdDialog->Command[curCmd].type=*lpBuf; + for (j = 0; j < lpmdDialog->Group[i].nCmds; j++) { + lpmdDialog->Command[curCmd].type = *lpBuf; lpBuf++; switch (lpmdDialog->Command[curCmd].type) { // Call custom function case 1: - lpmdDialog->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; - lpmdDialog->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; - lpmdDialog->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; - lpmdDialog->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; - lpmdDialog->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + lpmdDialog->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Command[curCmd].arg1 = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->Command[curCmd].arg2 = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->Command[curCmd].arg3 = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->Command[curCmd].arg4 = READ_LE_UINT32(lpBuf); lpBuf += 4; break; // Variable assign case 2: - len=*lpBuf; + len = *lpBuf; lpBuf++; - lpmdDialog->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); - if (lpmdDialog->Command[curCmd].lpszVarName==NULL) + lpmdDialog->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmdDialog->Command[curCmd].lpszVarName == NULL) return NULL; - CopyMemory(lpmdDialog->Command[curCmd].lpszVarName,lpBuf,len); - lpBuf+=len; - lpBuf=ParseExpression(lpBuf,&lpmdDialog->Command[curCmd].expr); - if (lpBuf==NULL) + Common::copy(lpBuf, lpBuf + len, lpmdDialog->Command[curCmd].lpszVarName); + lpmdDialog->Command[curCmd].lpszVarName[len] = '\0'; + lpBuf += len; + + lpBuf=ParseExpression(lpBuf, &lpmdDialog->Command[curCmd].expr); + if (lpBuf == NULL) return NULL; break; // Do Choice case 3: - lpmdDialog->Command[curCmd].nChoice=*(uint16 *)lpBuf; lpBuf+=2; + lpmdDialog->Command[curCmd].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; break; default: return NULL; } - for (kk=0;kkCommand[kk],&lpmdDialog->Command[curCmd])) { - lpmdDialog->Group[i].CmdNum[j]=kk; + for (kk = 0;kk < curCmd; kk++) { + if (CompareCommands(&lpmdDialog->Command[kk], &lpmdDialog->Command[curCmd])) { + lpmdDialog->Group[i].CmdNum[j] = kk; break; } } - if (kk==curCmd) { - lpmdDialog->Group[i].CmdNum[j]=curCmd; + if (kk == curCmd) { + lpmdDialog->Group[i].CmdNum[j] = curCmd; curCmd++; } } @@ -268,33 +271,33 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { } /* Choices */ - num=*(uint16 *)lpBuf; lpBuf+=2; + num=*(uint16 *)lpBuf; lpBuf += 2; if (num >= MAX_CHOICES_PER_DIALOG) { Common::String msg = Common::String::format("Too much choices in dialog #%d",lpmdDialog->nObj); MessageBox(msg); } - for (i=0;iChoice[i].nChoice=*(uint16 *)lpBuf; lpBuf+=2; + for (i = 0; i < num; i++) { + lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; - num2=*lpBuf++; + num2 = *lpBuf++; if (num2 >= MAX_SELECTS_PER_CHOICE) { Common::String msg = Common::String::format("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); MessageBox(msg); } - for (j=0;jChoice[i].Select[j].when=NULL; + lpmdDialog->Choice[i].Select[j].when = NULL; break; case 1: - lpBuf=ParseExpression(lpBuf,&lpmdDialog->Choice[i].Select[j].when); - if (lpBuf==NULL) + lpBuf = ParseExpression(lpBuf,&lpmdDialog->Choice[i].Select[j].when); + if (lpBuf == NULL) return NULL; break; @@ -303,31 +306,31 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { } // Attrib - lpmdDialog->Choice[i].Select[j].attr=*lpBuf++; + lpmdDialog->Choice[i].Select[j].attr = *lpBuf++; // Data - lpmdDialog->Choice[i].Select[j].dwData=*(uint32 *)lpBuf; lpBuf+=4; + lpmdDialog->Choice[i].Select[j].dwData = READ_LE_UINT32(lpBuf); lpBuf += 4; // PlayGroup - num3=*lpBuf; *lpBuf++; + num3 = *lpBuf; *lpBuf++; if (num3 >= MAX_PLAYGROUPS_PER_SELECT) { - Common::String msg = Common::String::format("Too much playgroups in select #%d in choice #%d in dialog #%d",j,lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); + Common::String msg = Common::String::format("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); MessageBox(msg); } - for (z=0;zChoice[i].Select[j].wPlayGroup[z]=*(uint16 *)lpBuf; lpBuf+=2; + for (z = 0; z < num3; z++) { + lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; } - lpmdDialog->Choice[i].Select[j].wPlayGroup[num3]=0; + lpmdDialog->Choice[i].Select[j].wPlayGroup[num3] = 0; } // Segna l'ultimo select - lpmdDialog->Choice[i].Select[num2].dwData=0; + lpmdDialog->Choice[i].Select[num2].dwData = 0; } - lpmdDialog->Choice[num].nChoice=0; + lpmdDialog->Choice[num].nChoice = 0; return lpBuf; } -- cgit v1.2.3 From a511b828e416c657e01a86e931016d4a4b7d49b9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 May 2012 00:29:44 +1000 Subject: TONY: Initial fixes for some of the Valgrind reported errors --- engines/tony/mpal/expr.cpp | 10 +-- engines/tony/mpal/expr.h | 2 +- engines/tony/mpal/loadmpc.cpp | 173 ++++++++++++++++++++---------------------- engines/tony/mpal/loadmpc.h | 2 +- engines/tony/mpal/memory.cpp | 12 ++- engines/tony/mpal/memory.h | 8 +- engines/tony/mpal/mpal.cpp | 2 +- 7 files changed, 105 insertions(+), 104 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 2f0e890af9..0ca02d2931 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -306,18 +306,18 @@ static int EvaluateAndFreeExpression(byte *expr) { * \****************************************************************************/ -byte *ParseExpression(byte *lpBuf, HGLOBAL *h) { +const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { LPEXPRESSION cur; byte *start; uint32 num, i; - num=*lpBuf; + num = *lpBuf; lpBuf++; - if (num==0) + if (num == 0) return NULL; - *h=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,num*sizeof(EXPRESSION)+1); + *h = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); if (*h==NULL) return NULL; @@ -441,7 +441,7 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { break; case ELT_VAR: - if (strcmp(one->val.name, two->val.name)!=0) { + if (strcmp(one->val.name, two->val.name) != 0) { GlobalUnlock(h1); GlobalUnlock(h2); return false; diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index d54f17b088..582f6d381d 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -76,7 +76,7 @@ namespace MPAL { * \****************************************************************************/ -byte *ParseExpression(byte *lpBuf, HGLOBAL *h); +const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); /****************************************************************************\ diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index c88f485b95..b08a5f2b3d 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -67,12 +67,12 @@ namespace MPAL { static bool CompareCommands(struct command *cmd1, struct command *cmd2) { if (cmd1->type == 2 && cmd2->type == 2) { if (strcmp(cmd1->lpszVarName, cmd2->lpszVarName) == 0 && - CompareExpressions(cmd1->expr,cmd2->expr)) + CompareExpressions(cmd1->expr, cmd2->expr)) return true; else return false; } else - return (memcmp(cmd1,cmd2,sizeof(struct command))==0); + return (memcmp(cmd1, cmd2, sizeof(struct command)) == 0); } @@ -92,7 +92,7 @@ static bool CompareCommands(struct command *cmd1, struct command *cmd2) { * \****************************************************************************/ -static byte *ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript) { +static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { int curCmd,j,len; uint i; @@ -127,7 +127,7 @@ static byte *ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript) { CopyMemory(lpmsScript->Command[curCmd].lpszVarName, lpBuf, len); lpBuf+=len; - lpBuf=ParseExpression(lpBuf,&lpmsScript->Command[curCmd].expr); + lpBuf = ParseExpression(lpBuf, &lpmsScript->Command[curCmd].expr); if (lpBuf==NULL) return NULL; break; @@ -162,16 +162,13 @@ static byte *ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript) { * \****************************************************************************/ -static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { +static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 i,j,z,kk; uint32 num,num2,num3; byte *lpLock; uint32 curCmd; uint32 len; - lpmdDialog->nObj = READ_LE_UINT32(lpBuf); - lpBuf += 4; - /* Periodi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -185,7 +182,6 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->Periods[i] = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); lpLock = (byte *)GlobalLock(lpmdDialog->Periods[i]); Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock); - lpLock[*lpBuf] = '\0'; GlobalUnlock(lpmdDialog->Periods[i]); lpBuf += (*lpBuf) + 1; } @@ -234,10 +230,9 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { return NULL; Common::copy(lpBuf, lpBuf + len, lpmdDialog->Command[curCmd].lpszVarName); - lpmdDialog->Command[curCmd].lpszVarName[len] = '\0'; lpBuf += len; - lpBuf=ParseExpression(lpBuf, &lpmdDialog->Command[curCmd].expr); + lpBuf = ParseExpression(lpBuf, &lpmdDialog->Command[curCmd].expr); if (lpBuf == NULL) return NULL; break; @@ -355,7 +350,7 @@ static byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog) { * \****************************************************************************/ -static byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem) { +static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { byte len; uint32 i,j,kk; uint32 curCmd; @@ -403,8 +398,8 @@ static byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->Action[i].when=NULL; } else { lpBuf++; - lpBuf=ParseExpression(lpBuf,&lpmiItem->Action[i].when); - if (lpBuf==NULL) + lpBuf = ParseExpression(lpBuf,&lpmiItem->Action[i].when); + if (lpBuf == NULL) return NULL; } @@ -489,7 +484,7 @@ static byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem) { * \****************************************************************************/ -static byte *ParseLocation(byte *lpBuf, LPMPALLOCATION lpmlLocation) { +static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) { lpmlLocation->nObj=*(int *)lpBuf; lpBuf+=4; lpmlLocation->dwXlen=*(uint16 *)lpBuf; @@ -529,32 +524,32 @@ static byte *ParseLocation(byte *lpBuf, LPMPALLOCATION lpmlLocation) { * \****************************************************************************/ -bool ParseMpc(byte *lpBuf) { +bool ParseMpc(const byte *lpBuf) { uint16 i, j; uint16 wLen; byte *lpTemp, *lpTemp2; /* 1. Variabili */ - if (lpBuf[0]!='V' || lpBuf[1]!='A' || lpBuf[2]!='R' || lpBuf[3]!='S') + if (lpBuf[0] != 'V' || lpBuf[1] != 'A' || lpBuf[2] != 'R' || lpBuf[3] != 'S') return false; - lpBuf+=4; - nVars=*(uint16 *)lpBuf; - lpBuf+=2; + lpBuf += 4; + nVars = READ_LE_UINT16(lpBuf); + lpBuf += 2; - hVars=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(MPALVAR)*(uint32)nVars); - if (hVars==NULL) + hVars = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)nVars); + if (hVars == NULL) return false; - lpmvVars=(LPMPALVAR)GlobalLock(hVars); + lpmvVars = (LPMPALVAR)GlobalLock(hVars); - for (i=0;ilpszVarName,lpBuf,MIN(wLen, (uint16)32)); - lpBuf+=wLen; - lpmvVars->dwVal=*(int *)lpBuf; - lpBuf+=4; + CopyMemory(lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); + lpBuf += wLen; + lpmvVars->dwVal = READ_LE_UINT32(lpBuf); + lpBuf += 4; lpBuf++; // Salta 'ext' lpmvVars++; @@ -563,44 +558,44 @@ bool ParseMpc(byte *lpBuf) { GlobalUnlock(hVars); /* 2. Messaggi */ - if (lpBuf[0]!='M' || lpBuf[1]!='S' || lpBuf[2]!='G' || lpBuf[3]!='S') + if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S') return false; - lpBuf+=4; - nMsgs=*(uint16 *)lpBuf; - lpBuf+=2; + lpBuf += 4; + nMsgs = READ_LE_UINT16(lpBuf); + lpBuf += 2; #ifdef NEED_LOCK_MSGS - hMsgs=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)nMsgs); - if (hMsgs==NULL) + hMsgs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)nMsgs); + if (hMsgs == NULL) return false; - lpmmMsgs=(LPMPALMSG)GlobalLock(hMsgs); + lpmmMsgs = (LPMPALMSG)GlobalLock(hMsgs); #else lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)nMsgs); if (lpmmMsgs==NULL) return false; #endif - for (i=0;iwNum=*(uint16 *)lpBuf; - lpBuf+=2; + for (i = 0; i < nMsgs; i++) { + lpmmMsgs->wNum = READ_LE_UINT16(lpBuf); + lpBuf += 2; - for (j=0;lpBuf[j]!=0;) - j+=lpBuf[j]+1; + 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); + lpmmMsgs->hText = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); + lpTemp2 = lpTemp = (byte *)GlobalLock(lpmmMsgs->hText); - for (j=0;lpBuf[j]!=0;) { - CopyMemory(lpTemp,&lpBuf[j+1],lpBuf[j]); - lpTemp+=lpBuf[j]; - *lpTemp++='\0'; - j+=lpBuf[j]+1; + for (j = 0; lpBuf[j] != 0;) { + CopyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]); + lpTemp += lpBuf[j]; + *lpTemp ++= '\0'; + j += lpBuf[j] + 1; } - lpBuf+=j+1; - *lpTemp='\0'; + lpBuf += j + 1; + *lpTemp = '\0'; GlobalUnlock(lpmmMsgs->hText); lpmmMsgs++; @@ -611,87 +606,87 @@ bool ParseMpc(byte *lpBuf) { #endif /* 3. Oggetti */ - if (lpBuf[0]!='O' || lpBuf[1]!='B' || lpBuf[2]!='J' || lpBuf[3]!='S') + if (lpBuf[0] != 'O' || lpBuf[1] != 'B' || lpBuf[2] != 'J' || lpBuf[3] != 'S') return false; - lpBuf+=4; - nObjs=*(uint16 *)lpBuf; - lpBuf+=2; + lpBuf += 4; + nObjs = READ_LE_UINT16(lpBuf); + lpBuf += 2; // Controlla i dialoghi - nDialogs=0; - hDialogs=lpmdDialogs=NULL; - if (*((const char *)lpBuf+2)==6 && strncmp((const char *)lpBuf+3,"Dialog",6)==0) { - nDialogs=*(uint16 *)lpBuf; lpBuf+=2; + nDialogs = 0; + hDialogs = lpmdDialogs = NULL; + if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) { + nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2; - hDialogs=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,(uint32)nDialogs*sizeof(MPALDIALOG)); - if (hDialogs==NULL) + hDialogs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)nDialogs * sizeof(MPALDIALOG)); + if (hDialogs == NULL) return false; - lpmdDialogs=(LPMPALDIALOG)GlobalLock(hDialogs); + lpmdDialogs = (LPMPALDIALOG)GlobalLock(hDialogs); - for (i=0;iDataPointer(); + Common::fill(dataP, dataP + size, 0); + } + _memoryBlocks.push_back(newItem); return *newItem; @@ -88,8 +94,8 @@ MemoryItem &MemoryManager::allocate(uint32 size) { * Allocates a new memory block and returns it's data pointer * @returns Data pointer to allocated block */ -HGLOBAL MemoryManager::alloc(uint32 size) { - MemoryItem &newItem = allocate(size); +HGLOBAL MemoryManager::alloc(uint32 size, uint flags) { + MemoryItem &newItem = allocate(size, flags); return (HGLOBAL)newItem.DataPointer(); } diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index ebf42b6207..6fd55e7ce5 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -57,8 +57,8 @@ public: MemoryManager(); virtual ~MemoryManager(); - MemoryItem &allocate(uint32 size); - HGLOBAL alloc(uint32 size); + MemoryItem &allocate(uint32 size, uint flags); + HGLOBAL alloc(uint32 size, uint flags); MemoryItem &getItem(HGLOBAL handle); MemoryItem &operator[](HGLOBAL handle); void erase(MemoryItem *item); @@ -68,8 +68,8 @@ public: }; // defines -#define GlobalAlloc(flags, size) _vm->_memoryManager.alloc(size) -#define GlobalAllocate(size) _vm->_memoryManager.allocate(size) +#define GlobalAlloc(flags, size) _vm->_memoryManager.alloc(size, flags) +#define GlobalAllocate(size) _vm->_memoryManager.allocate(size, 0) #define GlobalFree(handle) _vm->_memoryManager.erase(handle) #define GlobalLock(handle) (_vm->_memoryManager.getItem(handle).DataPointer()) #define GlobalUnlock(handle) {} diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 55d70b2e18..ec38083a76 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1735,7 +1735,7 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU hMpc.close(); /* Parsa l'immagine */ - if (ParseMpc(lpMpcImage)==false) + if (ParseMpc(lpMpcImage) == false) return false; GlobalFree(lpMpcImage); -- cgit v1.2.3 From fe0fa0f86b44d6f6766386fa070c84c6f358ccb9 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 May 2012 00:35:16 +1000 Subject: TONY: Added accidentally cut line --- engines/tony/mpal/loadmpc.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index b08a5f2b3d..cdcf91abc4 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -169,6 +169,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 curCmd; uint32 len; + lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; + /* Periodi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; -- cgit v1.2.3 From 3454a0a9c3738b09ac8de417297cb1f8adb0d2da Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 May 2012 00:40:23 +1000 Subject: TONY: A few more compiler warning fixes --- engines/tony/mpal/loadmpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index cdcf91abc4..27ef3f99c5 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -546,7 +546,7 @@ bool ParseMpc(const byte *lpBuf) { lpmvVars = (LPMPALVAR)GlobalLock(hVars); for (i = 0; i < nVars; i++) { - wLen=*(byte *)lpBuf; + wLen = *(const byte *)lpBuf; lpBuf++; CopyMemory(lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; -- cgit v1.2.3 From 91328fce56144caf15abc8995b68a5a5a0562f0a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 May 2012 09:56:06 +1000 Subject: TONY: Fixed some more Valgrid identified errors --- engines/tony/mpal/mpal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index ec38083a76..5f88eef268 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1518,7 +1518,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { return INVALID_HANDLE_VALUE; // Nella nuova versione scriviamo il numero dell'azione in dwRes - CopyMemory(newitem,item,sizeof(MPALITEM)); + Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); /* newitem->Action[0].nCmds=item->Action[i].nCmds; CopyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); */ -- cgit v1.2.3 From 607855cfbc892d4ecfa34f2c469a10e310e51124 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 5 May 2012 23:51:04 +1000 Subject: TONY: Formatting and endian fixes --- engines/tony/mpal/mpal.cpp | 629 ++++++++++++++++++++++----------------------- 1 file changed, 313 insertions(+), 316 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 5f88eef268..b977feb03b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -311,9 +311,6 @@ static void UnlockScripts(void) { } - - - /****************************************************************************\ * * Function: int varGetValue(char * lpszVarName); @@ -334,11 +331,11 @@ int32 varGetValue(const char *lpszVarName) { int i; LPMPALVAR v=lpmvVars; - for (i=0;ilpszVarName)==0) + for (i = 0; i < nVars; v++, i++) + if (strcmp(lpszVarName, v->lpszVarName) == 0) return v->dwVal; - mpalError=1; + mpalError = 1; return 0; } @@ -356,16 +353,16 @@ int32 varGetValue(const char *lpszVarName) { void varSetValue(const char *lpszVarName, int32 val) { uint i; - LPMPALVAR v=lpmvVars; + LPMPALVAR v = lpmvVars; - for (i=0;ilpszVarName)==0) { - v->dwVal=val; - if (lpiifCustom!=NULL && strncmp(v->lpszVarName,"Pattern.",8) == 0) { + for (i = 0; i < nVars; v++, i++) + if (strcmp(lpszVarName, v->lpszVarName) == 0) { + v->dwVal = val; + if (lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { i = 0; sscanf(v->lpszVarName, "Pattern.%u", &i); - lpiifCustom(i,val,-1); - } else if (lpiifCustom!=NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { + lpiifCustom(i, val, -1); + } else if (lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { i = 0; sscanf(v->lpszVarName,"Status.%u", &i); lpiifCustom(i, -1, val); @@ -373,7 +370,7 @@ void varSetValue(const char *lpszVarName, int32 val) { return; } - mpalError=1; + mpalError = 1; return; } @@ -396,10 +393,10 @@ void varSetValue(const char *lpszVarName, int32 val) { static int locGetOrderFromNum(uint32 nLoc) { int i; - LPMPALLOCATION loc=lpmlLocations; + LPMPALLOCATION loc = lpmlLocations; - for (i=0;inObj==nLoc) + for (i = 0; i < nLocations; i++,loc++) + if (loc->nObj == nLoc) return i; return -1; @@ -425,8 +422,8 @@ static int msgGetOrderFromNum(uint32 nMsg) { int i; LPMPALMSG msg=lpmmMsgs; - for (i=0;iwNum==nMsg) + for (i = 0; i < nMsgs; i++, msg++) + if (msg->wNum == nMsg) return i; return -1; @@ -453,8 +450,8 @@ static int itemGetOrderFromNum(uint32 nItem) { int i; LPMPALITEM item=lpmiItems; - for (i=0;inObj==nItem) + for (i = 0; i < nItems; i++, item++) + if (item->nObj == nItem) return i; return -1; @@ -479,10 +476,10 @@ static int itemGetOrderFromNum(uint32 nItem) { static int scriptGetOrderFromNum(uint32 nScript) { int i; - LPMPALSCRIPT script=lpmsScripts; + LPMPALSCRIPT script = lpmsScripts; - for (i=0;inObj==nScript) + for (i = 0; i < nScripts; i++,script++) + if (script->nObj == nScript) return i; return -1; @@ -509,8 +506,8 @@ static int dialogGetOrderFromNum(uint32 nDialog) { int i; LPMPALDIALOG dialog=lpmdDialogs; - for (i=0;inObj==nDialog) + for (i = 0; i < nDialogs; i++, dialog++) + if (dialog->nObj == nDialog) return i; return -1; @@ -542,13 +539,13 @@ static char *DuplicateMessage(uint32 nMsgOrd) { origmsg = (const char *)GlobalLock(lpmmMsgs[nMsgOrd].hText); - j=0; - while (origmsg[j]!='\0' || origmsg[j+1]!='\0') + j = 0; + while (origmsg[j] != '\0' || origmsg[j+1] != '\0') j++; - j+=2; + j += 2; - clonemsg=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,j); - if (clonemsg==NULL) + clonemsg=(char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, j); + if (clonemsg == NULL) return NULL; CopyMemory(clonemsg, origmsg, j); @@ -580,17 +577,17 @@ static char *DuplicateDialogPeriod(uint32 nPeriod) { LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; int i,j; - for (j=0;dialog->Periods[j]!=NULL;j++) - if (dialog->PeriodNums[j]==nPeriod) { + for (j = 0; dialog->Periods[j] != NULL; j++) + if (dialog->PeriodNums[j] == nPeriod) { /* Trovata la frase, va duplicata */ origmsg = (const char *)GlobalLock(dialog->Periods[j]); /* Calcola la lunghezza e alloca la memoria */ - i=0; - while (origmsg[i]!='\0') i++; + i = 0; + while (origmsg[i] != '\0') i++; - clonemsg = (char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,i+1); - if (clonemsg==NULL) + clonemsg = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, i + 1); + if (clonemsg == NULL) return NULL; CopyMemory(clonemsg, origmsg, i); @@ -644,7 +641,7 @@ HGLOBAL resLoad(uint32 dwId) { h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); buf = (byte *)GlobalLock(h); - temp = (byte *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,nSizeComp); + temp = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); nBytesRead = hMpr.read(temp, nSizeComp); if (nBytesRead != nSizeComp) @@ -668,24 +665,24 @@ static uint32 *GetSelectList(uint32 i) { LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; /* Conta quanti select attivi ci sono */ - num=0; - for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) + num = 0; + for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) if (dialog->Choice[i].Select[j].curActive) num++; /* Se sono 0, e' un errore */ - if (num==0) + if (num == 0) return NULL; - sl= (uint32 *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(uint32)*(num+1)); - if (sl==NULL) + sl= (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + if (sl == NULL) return NULL; /* Copia il dato di ogni select attivo dentro la lista */ - k=0; - for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) + k = 0; + for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) if (dialog->Choice[i].Select[j].curActive) - sl[k++]=dialog->Choice[i].Select[j].dwData; + sl[k++] = dialog->Choice[i].Select[j].dwData; sl[k] = (uint32)NULL; return sl; @@ -694,23 +691,23 @@ static uint32 *GetSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; uint32 num,i,j; - LPMPALVAR v=lpmvVars; + LPMPALVAR v = lpmvVars; - num=0; - for (i=0;ilpszVarName,"Location",8)==0 && v->dwVal==nLoc) + num = 0; + for (i = 0; i < nVars; i++,v++) { + if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } - il=(uint32 *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(uint32)*(num+1)); - if (il==NULL) + il=(uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + if (il == NULL) return NULL; - v=lpmvVars; - j=0; - for (i=0;ilpszVarName,"Location",8)==0 && v->dwVal==nLoc) { - sscanf(v->lpszVarName,"Location.%u",&il[j]); + v = lpmvVars; + j = 0; + for (i = 0; i < nVars; i++,v++) { + if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) { + sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; } } @@ -720,38 +717,38 @@ static uint32 *GetItemList(uint32 nLoc) { } static LPITEM GetItemData(uint32 nOrdItem) { - LPMPALITEM curitem=lpmiItems+nOrdItem; + LPMPALITEM curitem = lpmiItems+nOrdItem; LPITEM ret; HGLOBAL hDat; char *dat; - int i,j; + int i, j; char *patlength; uint32 dim; // Lo zeroinit e' obbligatorio!!!! - ret = (LPITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(ITEM)); - if (ret==NULL) + ret = (LPITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); + if (ret == NULL) return NULL; - ret->speed=150; + ret->speed = 150; hDat = resLoad(curitem->dwRes); dat = (char *)GlobalLock(hDat); - if (dat[0]=='D' && dat[1]=='A' && dat[2]=='T') { - i=dat[3]; // Versione!! Per ora 1.0 - dat+=4; + if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { + i = dat[3]; // Versione!! Per ora 1.0 + dat += 4; - if (i>=0x10) { // Dalla 1.0 c'e' il punto di destinazione per ogni oggetto - ret->destX=*(uint16 *)dat; - ret->destY=*(uint16 *)(dat+2); + if (i >= 0x10) { // Dalla 1.0 c'e' il punto di destinazione per ogni oggetto + ret->destX = (int16)READ_LE_UINT16(dat); + ret->destY = (int16)READ_LE_UINT16(dat + 2); dat+=4; } - if (i>=0x11) {// Dalla 1.1 c'e' la velocita' di animazione - ret->speed=*(uint16 *)dat; - dat+=2; + if (i >= 0x11) {// Dalla 1.1 c'e' la velocita' di animazione + ret->speed = READ_LE_UINT16(dat); + dat += 2; } else - ret->speed=150; + ret->speed = 150; } ret->numframe=*dat++; @@ -759,25 +756,25 @@ static LPITEM GetItemData(uint32 nOrdItem) { ret->Zvalue=*dat++; // Carica le coordinate left&top di ogni frame - for (i=0;inumframe;i++) { - ret->frameslocations[i].left=*(short*)(dat); - ret->frameslocations[i].top=*(short*)(dat+2); - dat+=4; + for (i = 0; i < ret->numframe; i++) { + ret->frameslocations[i].left = (int16)READ_LE_UINT16(dat); + ret->frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); + dat += 4; } // Carica le dimensioni di ogni frame e calcola right&bottom - for (i=0;inumframe;i++) { - ret->frameslocations[i].right=*(uint16 *)(dat)+ret->frameslocations[i].left; - ret->frameslocations[i].bottom=*(uint16 *)(dat+2)+ret->frameslocations[i].top; + for (i = 0; i < ret->numframe; i++) { + ret->frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->frameslocations[i].left; + ret->frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->frameslocations[i].top; dat+=4; } // Carica i bounding box di ogni frame - for (i=0;inumframe;i++) { - ret->bbox[i].left=*(uint16 *)(dat); - ret->bbox[i].top=*(uint16 *)(dat+2); - ret->bbox[i].right=*(uint16 *)(dat+4); - ret->bbox[i].bottom=*(uint16 *)(dat+6); + for (i = 0; i < ret->numframe; i++) { + ret->bbox[i].left = (int16)READ_LE_UINT16(dat); + ret->bbox[i].top = (int16)READ_LE_UINT16(dat + 2); + ret->bbox[i].right = (int16)READ_LE_UINT16(dat + 4); + ret->bbox[i].bottom = (int16)READ_LE_UINT16(dat + 6); dat+=8; } @@ -793,20 +790,20 @@ static LPITEM GetItemData(uint32 nOrdItem) { } // Carica i singoli frame di animazione - for (i=1;inumframe;i++) { - dim=(uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left)* + for (i = 1; i < ret->numframe; i++) { + dim=(uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); ret->frames[i]=(char *)GlobalAlloc(GMEM_FIXED,dim); - if (ret->frames[i]==NULL) + if (ret->frames[i] == NULL) return NULL; CopyMemory(ret->frames[i], dat, dim); - dat+=dim; + dat += dim; } // Controlla se siamo arrivati fino alla fine del file - i=*(uint16 *)dat; - if (i!=0xABCD) + i = READ_LE_UINT16(dat); + if (i != 0xABCD) return NULL; GlobalUnlock(hDat); @@ -832,7 +829,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { \****************************************************************************/ void PASCAL CustomThread(LPCFCALL p) { - lplpFunctions[p->nCf](p->arg1,p->arg2,p->arg3,p->arg4); + lplpFunctions[p->nCf](p->arg1, p->arg2, p->arg3, p->arg4); GlobalFree(p); ExitThread(1); // _endthread(); @@ -863,28 +860,28 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { LPCFCALL p; // warning("PlayScript(): Moments: %u\n",s->nMoments); - for (i=0;inMoments;i++) { + for (i = 0; i < s->nMoments; i++) { // Dorme il tempo necessario per arrivare al momento successivo - if (s->Moment[i].dwTime==-1) { - WaitForMultipleObjects(numHandles,cfHandles,true,INFINITE); + if (s->Moment[i].dwTime == -1) { + WaitForMultipleObjects(numHandles, cfHandles, true, INFINITE); dwStartTime = timeGetTime(); } else { dwCurTime = timeGetTime(); - if (dwCurTime < dwStartTime+(s->Moment[i].dwTime*100)) { + if (dwCurTime < dwStartTime + (s->Moment[i].dwTime * 100)) { // warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); - Sleep(dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); + Sleep(dwStartTime+(s->Moment[i].dwTime * 100) - dwCurTime); } } - numHandles=0; - for (j=0;jMoment[i].nCmds;j++) { + numHandles = 0; + for (j = 0;jMoment[i].nCmds; j++) { k=s->Moment[i].CmdNum[j]; switch (s->Command[k].type) { case 1: - p=(LPCFCALL)GlobalAlloc(GMEM_FIXED,sizeof(CFCALL)); - if (p==NULL) { - mpalError=1; + p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); + if (p == NULL) { + mpalError = 1; ExitThread(0); // _endthread(); } @@ -896,9 +893,9 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { p->arg4=s->Command[k].arg4; // !!! Nuova gestione dei thread - if ((cfHandles[numHandles++]=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)CustomThread,(void *)p,0,&dwId))==NULL) { + if ((cfHandles[numHandles++] = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)CustomThread,(void *)p, 0, &dwId)) == NULL) { //if ((cfHandles[numHandles++]=(void*)_beginthread(CustomThread, 10240, (void *)p))==(void*)-1) - mpalError=1; + mpalError = 1; ExitThread(0); // _endthread(); } @@ -914,7 +911,7 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { break; default: - mpalError=1; + mpalError = 1; GlobalFree(s); ExitThread(0); // _endthread(); @@ -943,9 +940,9 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { \****************************************************************************/ void PASCAL ActionThread(LPMPALITEM item) { - int j,k; + int j, k; - for (j=0;jAction[item->dwRes].nCmds;j++) { + for (j = 0;jAction[item->dwRes].nCmds; j++) { k=item->Action[item->dwRes].CmdNum[j]; switch (item->Command[k].type) { @@ -962,27 +959,27 @@ void PASCAL ActionThread(LPMPALITEM item) { case 2: // Variable assign LockVar(); - varSetValue(item->Command[k].lpszVarName,EvaluateExpression(item->Command[k].expr)); + varSetValue(item->Command[k].lpszVarName, EvaluateExpression(item->Command[k].expr)); UnlockVar(); break; default: - mpalError=1; + mpalError = 1; ExitThread(0); // _endthread(); } } GlobalFree(item); - //bExecutingAction=false; + //bExecutingAction = false; ExitThread(1); // _endthread(); } void PASCAL ShutUpActionThread(HANDLE hThread) { - WaitForSingleObject(hThread,INFINITE); - bExecutingAction=false; + WaitForSingleObject(hThread, INFINITE); + bExecutingAction = false; ExitThread(1); // _endthread(); @@ -1036,7 +1033,7 @@ void PASCAL LocationPollThread(uint32 id) { il = mpalQueryItemList(nPollingLocations[id]); /* Contiamo gli items */ - for (numitems=0;il[numitems]!=0;numitems++) + for (numitems = 0; il[numitems] != 0; numitems++) ; /* Cerchiamo gli items della locazione senza idle actions e li eliminiamo @@ -1051,7 +1048,7 @@ void PASCAL LocationPollThread(uint32 id) { curItem = lpmiItems + ord; - k=0; + k = 0; for (j = 0; j < curItem->nActions; j++) if (curItem->Action[j].num == 0xFF) k++; @@ -1132,49 +1129,49 @@ void PASCAL LocationPollThread(uint32 id) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ curTime = timeGetTime(); - dwSleepTime=(uint32)-1L; + dwSleepTime=(uint32) - 1L; - for (k=0;k=MyActions[k].dwLastTime+MyActions[k].wTime) { - dwSleepTime=0; + for (k = 0;k= MyActions[k].dwLastTime + MyActions[k].wTime) { + dwSleepTime = 0; break; } else - dwSleepTime=MIN(dwSleepTime,MyActions[k].dwLastTime+MyActions[k].wTime-curTime); + dwSleepTime = MIN(dwSleepTime,MyActions[k].dwLastTime+MyActions[k].wTime-curTime); /* Ci addormentiamo, ma controllando sempre l'evento che viene settato quando viene richiesta la nostra chiusura */ - k=WaitForSingleObject(hEndPollingLocations[id],dwSleepTime); - if (k==WAIT_OBJECT_0) + k = WaitForSingleObject(hEndPollingLocations[id], dwSleepTime); + if (k == WAIT_OBJECT_0) break; - for (i=0;i=MyActions[k].dwLastTime+MyActions[k].wTime) { - MyActions[k].dwLastTime+=MyActions[k].wTime; + for (k = 0; k < nIdleActions; k++) + if (curTime >= MyActions[k].dwLastTime + MyActions[k].wTime) { + MyActions[k].dwLastTime += MyActions[k].wTime; /* E' il momento di tirare il nostro dado virtuale, e controllare se la sorte e' dalla parte della idle action */ byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); if (randomVal < MyActions[k].perc) { /* Controlliamo se c'e' una action in esecuzione sull'item */ - if ((bExecutingAction) && (nExecutingAction==MyActions[k].nItem)) + if ((bExecutingAction) && (nExecutingAction == MyActions[k].nItem)) continue; /* Controlliamo se c'e' gia' un'altra idle function in esecuzione sullo stesso item */ - for (i=0;iAction[j].when!=NULL) + if (curItem->Action[j].when != NULL) if (!EvaluateExpression(curItem->Action[j].when)) { UnlockItems(); continue; @@ -1191,15 +1188,15 @@ void PASCAL LocationPollThread(uint32 id) { /* Ok, possiamo eseguire la azione. Per comodita' lo facciamo in un nuovo thread */ - newItem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALITEM)); - if (newItem==false) { + newItem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + if (newItem == false) { GlobalFree(MyThreads); GlobalFree(MyActions); ExitThread(0); // _endthread(); } - CopyMemory(newItem,curItem,sizeof(MPALITEM)); + CopyMemory(newItem,curItem, sizeof(MPALITEM)); UnlockItems(); /* Copiamo l'azione nella #0 */ @@ -1209,15 +1206,15 @@ void PASCAL LocationPollThread(uint32 id) { /* Creaiamo l'action thread. Provvedera' lui a liberare la memoria allocata per il nuovo item */ - for (i=0;iGroup[i].num!=0;i++) + for (i = 0; dialog->Group[i].num != 0; i++) if (dialog->Group[i].num==nGroup) { /* Cicla eseguendo i comandi del gruppo */ - for (j=0;jGroup[i].nCmds;j++) { + for (j = 0; j < dialog->Group[i].nCmds; j++) { k=dialog->Group[i].CmdNum[j]; switch (dialog->Command[k].type) { @@ -1348,7 +1345,7 @@ void PASCAL GroupThread(uint32 nGroup) { break; default: - mpalError=1; + mpalError = 1; UnlockDialogs(); ExitThread(0); // _endthread(); @@ -1363,7 +1360,7 @@ void PASCAL GroupThread(uint32 nGroup) { } /* Se siamo qui, vuol dire che non abbiamo trovato il gruppo richiesto */ - mpalError=1; + mpalError = 1; UnlockDialogs(); ExitThread(0); // _endthread(); @@ -1391,14 +1388,14 @@ void DoChoice(uint32 nChoice) { dialog=lpmdDialogs+nExecutingDialog; /* Cerca la scelta richiesta tra quelle nel dialogo */ - for (i=0;dialog->Choice[i].nChoice!=0;i++) - if (dialog->Choice[i].nChoice==nChoice) + for (i = 0; dialog->Choice[i].nChoice != 0; i++) + if (dialog->Choice[i].nChoice == nChoice) break; /* Se non l'ha trovata, esce con errore */ - if (dialog->Choice[i].nChoice==0) { + if (dialog->Choice[i].nChoice == 0) { /* Se siamo qui, non abbiamo trovato la choice richiesta */ - mpalError=1; + mpalError = 1; UnlockDialogs(); ExitThread(0); // _endthread(); @@ -1406,26 +1403,26 @@ void DoChoice(uint32 nChoice) { /* Abbiamo trova la choice richiesta. Ricordiamoci qual e' nella variabile globale */ - nExecutingChoice=i; + nExecutingChoice = i; while (1) { - nExecutingChoice=i; + nExecutingChoice = i; - k=0; + k = 0; /* Calcoliamo le when expression di ciascun select, per vedere se sono attivi o disattivi */ - for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) - if (dialog->Choice[i].Select[j].when==NULL) { - dialog->Choice[i].Select[j].curActive=1; + for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) + if (dialog->Choice[i].Select[j].when == NULL) { + dialog->Choice[i].Select[j].curActive = 1; k++; } else if (EvaluateExpression(dialog->Choice[i].Select[j].when)) { - dialog->Choice[i].Select[j].curActive=1; + dialog->Choice[i].Select[j].curActive = 1; k++; } else - dialog->Choice[i].Select[j].curActive=0; + dialog->Choice[i].Select[j].curActive = 0; /* Se non ci sono scelte attivate, la scelta e' finita */ - if (k==0) { + if (k == 0) { UnlockDialogs(); break; } @@ -1434,22 +1431,22 @@ void DoChoice(uint32 nChoice) { e restiamo in attesa della risposta */ ResetEvent(hDoneChoice); SetEvent(hAskChoice); - WaitForSingleObject(hDoneChoice,INFINITE); + WaitForSingleObject(hDoneChoice, INFINITE); /* Ora che la scelta e' stata effettuata, possiamo eseguire i gruppi associati con la scelta */ j=nSelectedChoice; - for (k=0;dialog->Choice[i].Select[j].wPlayGroup[k]!=0;k++) + for (k = 0; dialog->Choice[i].Select[j].wPlayGroup[k] != 0; k++) GroupThread(dialog->Choice[i].Select[j].wPlayGroup[k]); /* Controllo sugli attributi */ - if (dialog->Choice[i].Select[j].attr&(1<<0)) { + if (dialog->Choice[i].Select[j].attr & (1 << 0)) { /* Bit 0 settato: fine della scelta */ UnlockDialogs(); break; } - if (dialog->Choice[i].Select[j].attr&(1<<1)) { + if (dialog->Choice[i].Select[j].attr & (1 << 1)) { /* Bit 1 settato: fine del dialogo */ UnlockDialogs(); ExitThread(1); @@ -1488,7 +1485,7 @@ void DoChoice(uint32 nChoice) { \****************************************************************************/ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { - LPMPALITEM item=lpmiItems; + LPMPALITEM item = lpmiItems; int i; LPMPALITEM newitem; uint32 dwId; @@ -1496,25 +1493,25 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); - if (varGetValue(buf.c_str())<=0) + if (varGetValue(buf.c_str()) <= 0) return INVALID_HANDLE_VALUE; - for (i=0;inActions;i++) { - if (item->Action[i].num!=nAction) + for (i = 0; i < item->nActions; i++) { + if (item->Action[i].num != nAction) continue; - if (item->Action[i].wParm!=dwParam) + if (item->Action[i].wParm != dwParam) continue; - if (item->Action[i].when!=NULL) { + if (item->Action[i].when != NULL) { if (!EvaluateExpression(item->Action[i].when)) continue; } // Ora abbiamo trova l'azione giusta che deve essere eseguita. // Duplichiamo l'item corrente e copiamo la azione #i nella #0 - newitem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALITEM)); - if (newitem==NULL) + newitem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + if (newitem == NULL) return INVALID_HANDLE_VALUE; // Nella nuova versione scriviamo il numero dell'azione in dwRes @@ -1522,29 +1519,29 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { /* newitem->Action[0].nCmds=item->Action[i].nCmds; CopyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); */ - newitem->dwRes=i; + newitem->dwRes = i; // E finalmente possiamo richiamare il thread, che eseguira' l'azione // 0 dell'item, e poi liberera' la memoria con la GlobalFree() /* !!! Nuova gestione dei thread */ - if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ActionThread,(void *)newitem,0,&dwId))==NULL) + if ((h = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)ActionThread, (void *)newitem, 0, &dwId)) == NULL) return INVALID_HANDLE_VALUE; - if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ShutUpActionThread,(void *)h,0,&dwId))==NULL) + if ((h = CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ShutUpActionThread, (void *)h, 0, &dwId)) == NULL) return INVALID_HANDLE_VALUE; /* - if ((h=(void*)_beginthread(ActionThread,10240,(void *)newitem))==(void*)-1) + if ((h=(void*)_beginthread(ActionThread, 10240,(void *)newitem))==(void*)-1) return INVALID_HANDLE_VALUE; - if ((h=(void*)_beginthread(ShutUpActionThread,10240,(void *)h))==(void*)-1) + if ((h=(void*)_beginthread(ShutUpActionThread, 10240,(void *)h))==(void*)-1) return INVALID_HANDLE_VALUE; */ - nExecutingAction=item->nObj; - bExecutingAction=true; + nExecutingAction = item->nObj; + bExecutingAction = true; return h; } @@ -1580,10 +1577,10 @@ static HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup) { HANDLE h; /* Si ricorda nella variabile globale qual e' il dialogo in esecuzione */ - nExecutingDialog=nDlgOrd; + nExecutingDialog = nDlgOrd; /* Attiva la flag per indicare che c'e' un dialogo in esecuzione */ - bExecutingDialog=true; + bExecutingDialog = true; ResetEvent(hAskChoice); ResetEvent(hDoneChoice); @@ -1591,16 +1588,16 @@ static HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup) { /* Crea un thread in cui esegue un gruppo del dialogo */ // !!! Nuova gestione dei thread - if ((h=CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)GroupThread,(void *)nGroup,0,&dwId))==NULL) - // if ((h=(void*)_beginthread(GroupThread,10240,(void *)nGroup))==(void*)-1) + if ((h = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)GroupThread, (void *)nGroup, 0, &dwId)) == NULL) + // if ((h=(void*)_beginthread(GroupThread, 10240,(void *)nGroup))==(void*)-1) return INVALID_HANDLE_VALUE; /* Crea un thread che attende la fine del dialogo e rimette a posto le variabili globali */ // !!! Nuova gestione dei thread - if (CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ShutUpDialogThread,(void *)h,0,&dwId)==NULL) { - //if ((h=(void*)_beginthread(ShutUpDialogThread,10240,(void *)h))==(void*)-1) - TerminateThread(h,0); + if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ShutUpDialogThread,(void *)h, 0, &dwId) == NULL) { + //if ((h=(void*)_beginthread(ShutUpDialogThread, 10240,(void *)h))==(void*)-1) + TerminateThread(h, 0); CloseHandle(h); return INVALID_HANDLE_VALUE; } @@ -1627,14 +1624,14 @@ bool DoSelection(uint32 i, uint32 dwData) { LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; int j; - for (j=0;dialog->Choice[i].Select[j].dwData!=0;j++) - if (dialog->Choice[i].Select[j].dwData==dwData && dialog->Choice[i].Select[j].curActive!=0) + for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) + if (dialog->Choice[i].Select[j].dwData == dwData && dialog->Choice[i].Select[j].curActive != 0) break; - if (dialog->Choice[i].Select[j].dwData==0) + if (dialog->Choice[i].Select[j].dwData == 0) return false; - nSelectedChoice=j; + nSelectedChoice = j; SetEvent(hDoneChoice); return true; } @@ -1664,7 +1661,7 @@ bool DoSelection(uint32 i, uint32 dwData) { * \****************************************************************************/ -bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { +bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { Common::File hMpc; byte buf[5]; uint32 nBytesRead; @@ -1672,9 +1669,9 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU uint32 dwSizeDecomp, dwSizeComp; byte *cmpbuf; - //printf("Item: %lu\n",sizeof(MPALITEM)); - //printf("Script: %lu\n",sizeof(MPALSCRIPT)); - //printf("Dialog: %lu\n",sizeof(MPALDIALOG)); + //printf("Item: %lu\n", sizeof(MPALITEM)); + //printf("Script: %lu\n", sizeof(MPALSCRIPT)); + //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); /* Si salva l'array delle funzioni custom */ lplpFunctions=lplpcfArray; @@ -1685,13 +1682,13 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU /* Legge e controlla l'header */ nBytesRead = hMpc.read(buf, 5); - if (nBytesRead !=5) + if (nBytesRead != 5) return false; - if (buf[0]!='M' || buf[1]!='P' || buf[2]!='C' || buf[3]!=0x20) + if (buf[0] != 'M' || buf[1] != 'P' || buf[2] != 'C' || buf[3] != 0x20) return false; - bCompress=buf[4]; + bCompress = buf[4]; /* Legge la dimensione del file decompresso, e alloca la memoria */ dwSizeDecomp = hMpc.readUint32LE(); @@ -1699,7 +1696,7 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU return false; lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeDecomp+16); - if (lpMpcImage==NULL) + if (lpMpcImage == NULL) return false; if (bCompress) { @@ -1710,7 +1707,7 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU return false; cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeComp); - if (cmpbuf==NULL) + if (cmpbuf == NULL) return false; nBytesRead = hMpc.read(cmpbuf, dwSizeComp); @@ -1781,11 +1778,11 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nResources * 8); - if (lpResources==NULL) + if (lpResources == NULL) return false; cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); - if (cmpbuf==NULL) + if (cmpbuf == NULL) return false; nBytesRead = hMpr.read(cmpbuf, dwSizeComp); @@ -1810,8 +1807,8 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' da effettuare una scelta */ - hAskChoice=CreateEvent(NULL, true, false, NULL); - hDoneChoice=CreateEvent(NULL, true, false, NULL); + hAskChoice = CreateEvent(NULL, true, false, NULL); + hDoneChoice = CreateEvent(NULL, true, false, NULL); return true; } @@ -1840,7 +1837,7 @@ bool mpalInit(const char * lpszMpcFileName, const char * lpszMprFileName, LPLPCU uint32 mpalQuery(uint16 wQueryType, ...) { uint32 dwRet = 0; - int x,y,z; + int x, y, z; char *n; va_list v; Common::String buf; @@ -1861,7 +1858,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_GLOBAL_VAR: LockVar(); - dwRet=(uint32)varGetValue(GETARG(char *)); + dwRet = (uint32)varGetValue(GETARG(char *)); UnlockVar(); break; @@ -1870,7 +1867,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_MESSAGE: LockMsg(); - dwRet=(uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); + dwRet = (uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); UnlockMsg(); break; @@ -1889,17 +1886,17 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_LOCATION_SIZE: LockLocations(); - x=locGetOrderFromNum(GETARG(uint32)); - y=GETARG(uint32); - if (x!=-1) { - if (y==MPQ_X) - dwRet=lpmlLocations[x].dwXlen; - else if (y==MPQ_Y) - dwRet=lpmlLocations[x].dwYlen; + x = locGetOrderFromNum(GETARG(uint32)); + y = GETARG(uint32); + if (x != -1) { + if (y == MPQ_X) + dwRet = lpmlLocations[x].dwXlen; + else if (y == MPQ_Y) + dwRet = lpmlLocations[x].dwYlen; else - mpalError=1; + mpalError = 1; } else - mpalError=1; + mpalError = 1; UnlockLocations(); break; @@ -1908,8 +1905,8 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_LOCATION_IMAGE: LockLocations(); - x=locGetOrderFromNum(GETARG(uint32)); - dwRet=(uint32)resLoad(lpmlLocations[x].dwPicRes); + x = locGetOrderFromNum(GETARG(uint32)); + dwRet = (uint32)resLoad(lpmlLocations[x].dwPicRes); UnlockLocations(); break; @@ -1917,7 +1914,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); */ case MPQ_RESOURCE: - dwRet=(uint32)resLoad(GETARG(uint32)); + dwRet = (uint32)resLoad(GETARG(uint32)); break; /* @@ -1925,7 +1922,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_ITEM_LIST: LockVar(); - dwRet=(uint32)GetItemList(GETARG(uint32)); + dwRet = (uint32)GetItemList(GETARG(uint32)); LockVar(); break; @@ -1934,7 +1931,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_ITEM_DATA: LockItems(); - dwRet=(uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); + dwRet = (uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); UnlockItems(); break; @@ -1943,7 +1940,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_ITEM_IS_ACTIVE: LockVar(); - x=GETARG(uint32); + x = GETARG(uint32); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) dwRet = (uint32)false; @@ -1958,14 +1955,14 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_ITEM_NAME: LockVar(); - x=GETARG(uint32); + x = GETARG(uint32); n=GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0]='\0'; else { LockItems(); - y=itemGetOrderFromNum(x); + y = itemGetOrderFromNum(x); CopyMemory(n, (char *)(lpmiItems+y)->lpszDescribe, MAX_DESCRIBE_SIZE); UnlockItems(); } @@ -1979,8 +1976,8 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_DIALOG_PERIOD: LockDialogs(); - y=GETARG(uint32); - dwRet=(uint32)DuplicateDialogPeriod(y); + y = GETARG(uint32); + dwRet = (uint32)DuplicateDialogPeriod(y); UnlockDialogs(); break; @@ -1989,13 +1986,13 @@ uint32 mpalQuery(uint16 wQueryType, ...) { * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ case MPQ_DIALOG_WAITFORCHOICE: - WaitForSingleObject(hAskChoice,INFINITE); + WaitForSingleObject(hAskChoice, INFINITE); ResetEvent(hAskChoice); if (bExecutingDialog) - dwRet=(uint32)nExecutingChoice; + dwRet = (uint32)nExecutingChoice; else - dwRet=(uint32)((int)-1); + dwRet = (uint32)((int)-1); break; @@ -2004,7 +2001,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_DIALOG_SELECTLIST: LockDialogs(); - dwRet=(uint32)GetSelectList(GETARG(uint32)); + dwRet = (uint32)GetSelectList(GETARG(uint32)); UnlockDialogs(); break; @@ -2013,9 +2010,9 @@ uint32 mpalQuery(uint16 wQueryType, ...) { */ case MPQ_DIALOG_SELECTION: LockDialogs(); - x=GETARG(uint32); - y=GETARG(uint32); - dwRet=(uint32)DoSelection(x,y); + x = GETARG(uint32); + y = GETARG(uint32); + dwRet = (uint32)DoSelection(x,y); UnlockDialogs(); break; @@ -2027,21 +2024,21 @@ uint32 mpalQuery(uint16 wQueryType, ...) { /* if (bExecutingAction) { - dwRet=(uint32)INVALID_HANDLE_VALUE; + dwRet = (uint32)INVALID_HANDLE_VALUE; break; } */ LockItems(); LockVar(); - x=GETARG(uint32); - z=GETARG(uint32); - y=itemGetOrderFromNum(z); + x = GETARG(uint32); + z = GETARG(uint32); + y = itemGetOrderFromNum(z); if (y!=-1) { - dwRet=(uint32)DoAction(x,y,GETARG(uint32)); + dwRet = (uint32)DoAction(x, y, GETARG(uint32)); } else { - dwRet=(uint32)INVALID_HANDLE_VALUE; - mpalError=1; + dwRet = (uint32)INVALID_HANDLE_VALUE; + mpalError = 1; } UnlockVar(); UnlockItems(); @@ -2056,9 +2053,9 @@ uint32 mpalQuery(uint16 wQueryType, ...) { LockDialogs(); - x=dialogGetOrderFromNum(GETARG(uint32)); - y=GETARG(uint32); - dwRet=(uint32)DoDialog(x,y); + x = dialogGetOrderFromNum(GETARG(uint32)); + y = GETARG(uint32); + dwRet = (uint32)DoDialog(x, y); UnlockDialogs(); break; @@ -2066,7 +2063,7 @@ uint32 mpalQuery(uint16 wQueryType, ...) { * DEFAULT -> ERROR */ default: - mpalError=1; + mpalError = 1; break; } @@ -2110,17 +2107,17 @@ bool EXPORT mpalExecuteScript(int nScript) { uint32 dwId; LockScripts(); - n=scriptGetOrderFromNum(nScript); - s=(LPMPALSCRIPT)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALSCRIPT)); - if (s==NULL) + n = scriptGetOrderFromNum(nScript); + s = (LPMPALSCRIPT)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); + if (s == NULL) return false; CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT)); UnlockScripts(); // !!! Nuova gestione dei thread - if (CreateThread(NULL,10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s,0,&dwId)==NULL) - //if ((void*)_beginthread(ScriptThread,10240,(void *)s)==(void*)-1) + if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s, 0, &dwId) == NULL) + //if ((void*)_beginthread(ScriptThread, 10240,(void *)s)==(void*)-1) return false; return true; @@ -2139,7 +2136,7 @@ bool EXPORT mpalExecuteScript(int nScript) { \****************************************************************************/ void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { - lpiifCustom=lpiifCus; + lpiifCustom = lpiifCus; } @@ -2163,18 +2160,18 @@ bool EXPORT mpalStartIdlePoll(int nLoc) { uint32 i; uint32 dwId; - for (i=0;iwriteString("\n

\n

\n"); if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { f->writeString(Common::String::format("%s\n", MsgComments[i].pComment)); - f->writeString("

\n

\n\n"); + f->writeString("

\n

\n

\n"); } else - bDontOutput=true; + bDontOutput = true; return; } } @@ -2360,16 +2357,16 @@ warning("Start: %d\n", wNum); void OutputEndMsgComment(uint16 wNum, Common::OutSaveFile *f) { int i; - for (i=0;MsgComments[i].wEnd!=0;i++) + for (i = 0; MsgComments[i].wEnd != 0; i++) if (MsgComments[i].wEnd == wNum) { warning("End: %d\n", wNum); if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { f->writeString("
\n

\n"); } else - bDontOutput=false; + bDontOutput = false; - f->writeString("

\n

\n\n"); + f->writeString("

\n

\n

\n"); return; } } @@ -2378,12 +2375,12 @@ warning("End: %d\n", wNum); int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { int i; - for (i=0;MsgComments[i].wStart!=0;i++) + for (i = 0; MsgComments[i].wStart != 0; i++) if (MsgComments[i].wStart <= wNum && MsgComments[i].wEnd >= wNum) { if (strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { if (MsgComments[i].wStart == wNum) { - f->writeString(Common::String::format("%s\n", MsgComments[i].pComment+4)); - f->writeString("

\n

\n

\n"); + f->writeString(Common::String::format("%s\n", MsgComments[i].pComment + 4)); + f->writeString("

\n

\n

\n"); } return 1; @@ -2397,7 +2394,7 @@ int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { void OutputEndOther(uint16 wNum, Common::OutSaveFile *f) { int i; - for (i=0;MsgComments[i].wStart!=0;i++) + for (i = 0; MsgComments[i].wStart != 0; i++) if (MsgComments[i].wEnd == wNum && strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { f->writeString("
\n

\n"); break; @@ -2406,7 +2403,7 @@ void OutputEndOther(uint16 wNum, Common::OutSaveFile *f) { void mpalDumpMessages(void) { - int i,j; + int i, j; char *lpMessage; char *p; char *lpPeriods[30]; @@ -2419,50 +2416,50 @@ void mpalDumpMessages(void) { LockMsg(); - bDontOutput=false; + bDontOutput = false; warning("Dumping MESSAGES.HTM...\n"); f = g_system->getSavefileManager()->openForSaving("Messages.htm"); - f->writeString("\n\n\n"); + f->writeString("\n\n
\n"); - for (i=0;igetSavefileManager()->openForSaving("Others.htm"); LockMsg(); - bDontOutput=false; + bDontOutput = false; warning("Dumping OTHERS.HTM...\n"); f->writeString("\n\n"); - for (i=0;igetSavefileManager()->openForSaving("voicelist.txt"); - sprintf(dfn,"DIALOG%03d.HTM",dlg->nObj); + sprintf(dfn,"DIALOG%03d.HTM", dlg->nObj); warning("Dumping %s...\n", dfn); f = g_system->getSavefileManager()->openForSaving(dfn); f->writeString("\n\n"); - for (g=0;dlg->Group[g].num != 0; g++) { + for (g = 0;dlg->Group[g].num != 0; g++) { bAtLeastOne = false; - for (c=0;cGroup[g].nCmds; c++) { + for (c = 0; cGroup[g].nCmds; c++) { curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; if (curCmd->type == 1 && curCmd->nCf == 71) { - bAtLeastOne=true; + bAtLeastOne = true; break; } } @@ -3003,27 +3000,27 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { continue; f->writeString(Common::String::format("

\n

Group %d

\n

\n", g)); - f->writeString("

\n"); + f->writeString("
\n"); - for (c=0;cGroup[g].nCmds; c++) { + for (c = 0;cGroup[g].nCmds; c++) { curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; // Se è una funzione custom, e richiama la SendDialogMessage(nPers, nMsg) if (curCmd->type == 1 && curCmd->nCf == 71) { sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->arg2); - for (j=0;dlg->Periods[j]!=NULL;j++) + for (j = 0; dlg->Periods[j] != NULL; j++) if (dlg->PeriodNums[j] == curCmd->arg2) break; - if (dlg->Periods[j]==NULL) + if (dlg->Periods[j] == NULL) warning("ERROR: Dialogo %d, Periodo %d non trovato!\n", (int)dlg->nObj, (int)curCmd->arg2); else { frase = (char *)GlobalLock(dlg->Periods[j]); strcpy(copia, frase); GlobalUnlock(dlg->Periods[j]); - while ((p=strchr(copia,'^')) != NULL) + while ((p = strchr(copia,'^')) != NULL) *p = '\"'; p = frase; @@ -3034,7 +3031,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { v1->writeString(Common::String::format("%s\n", fname)); f->writeString("\t\n"); f->writeString(Common::String::format("\t\t\n", fname)); - f->writeString(Common::String::format("\t\t\n", + f->writeString(Common::String::format("\t\t\n", GetPersonName(dlg->nObj, curCmd->arg1))); f->writeString(Common::String::format("\t\t\n",copia)); f->writeString("\t\n"); @@ -3058,7 +3055,7 @@ void mpalDumpDialogs(void) { LockDialogs(); - for (i=0;inCf](p->arg1, p->arg2, p->arg3, p->arg4); + // FIXME: Convert to proper corotuine call + warning("FIXME: CustomThread call"); + + lplpFunctions[p->nCf](nullContext, p->arg1, p->arg2, p->arg3, p->arg4); GlobalFree(p); ExitThread(1); // _endthread(); @@ -939,50 +943,69 @@ void PASCAL ScriptThread(LPMPALSCRIPT s) { * \****************************************************************************/ -void PASCAL ActionThread(LPMPALITEM item) { - int j, k; +void ActionThread(CORO_PARAM, const void *param) { + // COROUTINE + CORO_BEGIN_CONTEXT; + int j, k; + CORO_END_CONTEXT(_ctx); - for (j = 0;jAction[item->dwRes].nCmds; j++) { - k=item->Action[item->dwRes].CmdNum[j]; + const LPMPALITEM item = *(const LPMPALITEM *)param; - switch (item->Command[k].type) { - case 1: - // Funzione custom - lplpFunctions[item->Command[k].nCf]( - item->Command[k].arg1, - item->Command[k].arg2, - item->Command[k].arg3, - item->Command[k].arg4 - ); - break; + CORO_BEGIN_CODE(_ctx); + + mpalError = 0; + for (_ctx->j = 0; _ctx->j < item->Action[item->dwRes].nCmds; _ctx->j++) { + _ctx->k = item->Action[item->dwRes].CmdNum[_ctx->j]; + + if (item->Command[_ctx->k].type == 1) { + // Custom function + CORO_INVOKE_4(lplpFunctions[item->Command[_ctx->k].nCf], + item->Command[_ctx->k].arg1, + item->Command[_ctx->k].arg2, + item->Command[_ctx->k].arg3, + item->Command[_ctx->k].arg4 - case 2: + ); + } else if (item->Command[_ctx->k].type == 2) { // Variable assign LockVar(); - varSetValue(item->Command[k].lpszVarName, EvaluateExpression(item->Command[k].expr)); + varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); UnlockVar(); break; - default: + } else { mpalError = 1; - ExitThread(0); -// _endthread(); + break; } } GlobalFree(item); - //bExecutingAction = false; + + CORO_KILL_SELF(); - ExitThread(1); -// _endthread(); + CORO_END_CODE; } -void PASCAL ShutUpActionThread(HANDLE hThread) { +/** + * This thread monitors a created action to detect when it ends. + * @remarks Since actions can spawn sub-actions, this needs to be a + * separate thread to determine when the outer action is done + */ +void ShutUpActionThread(CORO_PARAM, const void *param) { + // COROUTINE + CORO_BEGIN_CONTEXT; + CORO_END_CONTEXT(_ctx); + + HANDLE hThread = *(const HANDLE *)param; + + CORO_BEGIN_CODE(_ctx); + WaitForSingleObject(hThread, INFINITE); bExecutingAction = false; - ExitThread(1); -// _endthread(); + CORO_KILL_SELF(); + + CORO_END_CODE; } /****************************************************************************\ @@ -1241,7 +1264,8 @@ void PASCAL LocationPollThread(uint32 id) { */ // Set idle skip on - lplpFunctions[200](0, 0, 0, 0); + // FIXME: Convert to co-routine + lplpFunctions[200](nullContext, 0, 0, 0, 0); for (i = 0; i < nRealItems; i++) if (MyThreads[i].nItem != 0) { @@ -1252,7 +1276,8 @@ void PASCAL LocationPollThread(uint32 id) { } // Set idle skip off - lplpFunctions[201](0, 0, 0, 0); + // FIXME: Convert to co-routine + lplpFunctions[201](nullContext, 0, 0, 0, 0); /* Abbiamo finito */ GlobalFree(MyThreads); @@ -1324,7 +1349,9 @@ void PASCAL GroupThread(uint32 nGroup) { switch (dialog->Command[k].type) { /* Funzione custom: la richiama */ case 1: + // FIXME: Convert to co-routine lplpFunctions[dialog->Command[k].nCf]( + nullContext, dialog->Command[k].arg1, dialog->Command[k].arg2, dialog->Command[k].arg3, @@ -1488,8 +1515,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = lpmiItems; int i; LPMPALITEM newitem; - uint32 dwId; - HANDLE h; + PROCESS *h; item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); @@ -1510,7 +1536,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // Ora abbiamo trova l'azione giusta che deve essere eseguita. // Duplichiamo l'item corrente e copiamo la azione #i nella #0 - newitem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (newitem == NULL) return INVALID_HANDLE_VALUE; @@ -1524,12 +1550,11 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // E finalmente possiamo richiamare il thread, che eseguira' l'azione // 0 dell'item, e poi liberera' la memoria con la GlobalFree() -/* !!! Nuova gestione dei thread -*/ - if ((h = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)ActionThread, (void *)newitem, 0, &dwId)) == NULL) + // !!! New thread management + if ((h = g_scheduler->createProcess(ActionThread, newitem)) == NULL) return INVALID_HANDLE_VALUE; - if ((h = CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ShutUpActionThread, (void *)h, 0, &dwId)) == NULL) + if ((h = g_scheduler->createProcess(0, ShutUpActionThread, &h, sizeof(PROCESS *))) == NULL) return INVALID_HANDLE_VALUE; /* @@ -1543,7 +1568,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { nExecutingAction = item->nObj; bExecutingAction = true; - return h; + return (HANDLE)h; } return INVALID_HANDLE_VALUE; @@ -1674,7 +1699,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUST //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); /* Si salva l'array delle funzioni custom */ - lplpFunctions=lplpcfArray; + lplpFunctions = lplpcfArray; /* Apre il file MPC in lettura */ if (!hMpc.open(lpszMpcFileName)) diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index e66f1fdb7e..3c2e62d992 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -119,6 +119,7 @@ #include "common/scummsys.h" #include "common/rect.h" +#include "tony/coroutine.h" namespace Tony { @@ -220,7 +221,7 @@ typedef ITEM *LPITEM; * to perform various controls as a result of an action \****************************************************************************/ -typedef void (*LPCUSTOMFUNCTION)(uint32, uint32, uint32, uint32); +typedef void (*LPCUSTOMFUNCTION)(CORO_PARAM, uint32, uint32, uint32, uint32); typedef LPCUSTOMFUNCTION *LPLPCUSTOMFUNCTION; -- cgit v1.2.3 From 4c8ce3bec99db9d0b63dd65f1c7a89cbe41a679b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 May 2012 12:54:57 +1000 Subject: TONY: Implemented Scheduler::waitForSingleObject method This will be the coroutine version of the threading method. With this, the main menu of the demo is now shown. --- engines/tony/mpal/mpal.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 3757cdddcf..78111753ce 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -996,11 +996,12 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; CORO_END_CONTEXT(_ctx); - HANDLE hThread = *(const HANDLE *)param; + int pid = *(const int *)param; CORO_BEGIN_CODE(_ctx); - WaitForSingleObject(hThread, INFINITE); + CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, pid, INFINITE); + bExecutingAction = false; CORO_KILL_SELF(); @@ -1554,7 +1555,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { if ((h = g_scheduler->createProcess(ActionThread, newitem)) == NULL) return INVALID_HANDLE_VALUE; - if ((h = g_scheduler->createProcess(0, ShutUpActionThread, &h, sizeof(PROCESS *))) == NULL) + if ((h = g_scheduler->createProcess(ShutUpActionThread, &h->pid, sizeof(int))) == NULL) return INVALID_HANDLE_VALUE; /* -- cgit v1.2.3 From 770e55d06578f7f51959ea331da7baaaaa0e360d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 May 2012 15:18:03 +1000 Subject: TONY: Further conversion of initially launched threads to processes. This includes all the dependent routines that they call. --- engines/tony/mpal/mpal.cpp | 310 ++++++++++++++++++++++++--------------------- engines/tony/mpal/mpal.h | 3 +- 2 files changed, 170 insertions(+), 143 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 78111753ce..851de7cb0c 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -138,7 +138,7 @@ bool bExecutingDialog; uint32 nPollingLocations[MAXPOLLINGLOCATIONS]; HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS]; -HANDLE PollingThreads[MAXPOLLINGLOCATIONS]; +uint32 PollingThreads[MAXPOLLINGLOCATIONS]; HANDLE hAskChoice; HANDLE hDoneChoice; @@ -996,7 +996,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; CORO_END_CONTEXT(_ctx); - int pid = *(const int *)param; + uint32 pid = *(const uint32 *)param; CORO_BEGIN_CODE(_ctx); @@ -1021,17 +1021,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { * \****************************************************************************/ -void PASCAL LocationPollThread(uint32 id) { - uint32 *il; - int i,j,k; - int numitems; - int nRealItems; - LPMPALITEM curItem,newItem; - int nIdleActions; - uint32 curTime; - uint32 dwSleepTime; - uint32 dwId; - +void LocationPollThread(CORO_PARAM, const void *param) { typedef struct { uint32 nItem, nAction; @@ -1046,59 +1036,77 @@ void PASCAL LocationPollThread(uint32 id) { typedef struct { uint32 nItem; - HANDLE hThread; + uint32 hThread; } MYTHREAD; - MYACTION *MyActions; - MYTHREAD *MyThreads; + CORO_BEGIN_CONTEXT; + uint32 *il; + int i, j, k; + int numitems; + int nRealItems; + LPMPALITEM curItem,newItem; + int nIdleActions; + uint32 curTime; + uint32 dwSleepTime; + uint32 dwId; + int ord; + bool delayExpired; + + MYACTION *MyActions; + MYTHREAD *MyThreads; + CORO_END_CONTEXT(_ctx); + + uint32 id = *((const uint32 *)param); + + CORO_BEGIN_CODE(_ctx); /* Tanto per cominciare, e' necessario richiedere la lista degli item presenti nella locazione. */ - il = mpalQueryItemList(nPollingLocations[id]); + _ctx->il = mpalQueryItemList(nPollingLocations[id]); /* Contiamo gli items */ - for (numitems = 0; il[numitems] != 0; numitems++) + for (_ctx->numitems = 0; _ctx->il[_ctx->numitems] != 0; _ctx->numitems++) ; /* Cerchiamo gli items della locazione senza idle actions e li eliminiamo dalla lista */ LockItems(); - nIdleActions = 0; - nRealItems = 0; - for (i = 0; i < numitems; i++) { - int ord = itemGetOrderFromNum(il[i]); + _ctx->nIdleActions = 0; + _ctx->nRealItems = 0; + for (_ctx->i = 0; _ctx->i < _ctx->numitems; _ctx->i++) { + _ctx->ord = itemGetOrderFromNum(_ctx->il[_ctx->i]); - if (ord == -1) continue; + if (_ctx->ord == -1) continue; - curItem = lpmiItems + ord; + _ctx->curItem = lpmiItems + _ctx->ord; - k = 0; - for (j = 0; j < curItem->nActions; j++) - if (curItem->Action[j].num == 0xFF) - k++; + _ctx->k = 0; + for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) + if (_ctx->curItem->Action[_ctx->j].num == 0xFF) + _ctx->k++; - nIdleActions += k; + _ctx->nIdleActions += _ctx->k; - if (k == 0) + if (_ctx->k == 0) /* Possiamo eliminare questo item dalla lista */ - il[i] = (uint32)NULL; + _ctx->il[_ctx->i] = (uint32)NULL; else - nRealItems++; + _ctx->nRealItems++; } UnlockItems(); /* Se non e' rimasto nessuno possiamo uscire */ - if (nRealItems == 0) { - GlobalFree(il); - ExitThread(0); -// _endthread(); + if (_ctx->nRealItems == 0) { + GlobalFree(_ctx->il); + CORO_KILL_SELF(); + return; } - MyThreads=(MYTHREAD *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nRealItems * sizeof(MYTHREAD)); - if (MyThreads == NULL) { - GlobalFree(il); - ExitThread(0); -// _endthread(); + _ctx->MyThreads = (MYTHREAD *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); + if (_ctx->MyThreads == NULL) { + GlobalFree(_ctx->il); + CORO_KILL_SELF(); + return; } /* Inizializziamo le routine random */ @@ -1108,142 +1116,147 @@ void PASCAL LocationPollThread(uint32 id) { /* Abbiamo appurato che esiste almeno un item che contiene idle actions. Ora creaiamo le copie speculari delle idle actions */ - MyActions = (MYACTION *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nIdleActions * sizeof(MYACTION)); - if (MyActions == NULL) { - GlobalFree(MyThreads); - GlobalFree(il); - ExitThread(0); -// _endthread(); + _ctx->MyActions = (MYACTION *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); + if (_ctx->MyActions == NULL) { + GlobalFree(_ctx->MyThreads); + GlobalFree(_ctx->il); + CORO_KILL_SELF(); + return; } LockItems(); - k = 0; + _ctx->k = 0; - for (i = 0; i < numitems; i++) { - if (il[i] == 0) + for (_ctx->i = 0; _ctx->i < _ctx->numitems; _ctx->i++) { + if (_ctx->il[_ctx->i] == 0) continue; - curItem = lpmiItems + itemGetOrderFromNum(il[i]); + _ctx->curItem = lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); - for (j = 0; j < curItem->nActions; j++) - if (curItem->Action[j].num == 0xFF) { - MyActions[k].nItem = il[i]; - MyActions[k].nAction = j; + for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) + if (_ctx->curItem->Action[_ctx->j].num == 0xFF) { + _ctx->MyActions[_ctx->k].nItem = _ctx->il[_ctx->i]; + _ctx->MyActions[_ctx->k].nAction = _ctx->j; - MyActions[k].wTime = curItem->Action[j].wTime; - MyActions[k].perc = curItem->Action[j].perc; - MyActions[k].when = curItem->Action[j].when; - MyActions[k].nCmds = curItem->Action[j].nCmds; - CopyMemory(MyActions[k].CmdNum, curItem->Action[j].CmdNum, + _ctx->MyActions[_ctx->k].wTime = _ctx->curItem->Action[_ctx->j].wTime; + _ctx->MyActions[_ctx->k].perc = _ctx->curItem->Action[_ctx->j].perc; + _ctx->MyActions[_ctx->k].when = _ctx->curItem->Action[_ctx->j].when; + _ctx->MyActions[_ctx->k].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; + CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - MyActions[k].dwLastTime = timeGetTime(); - k++; + _ctx->MyActions[_ctx->k].dwLastTime = timeGetTime(); + _ctx->k++; } } UnlockItems(); /* La item list non ci serve piu' */ - GlobalFree(il); + GlobalFree(_ctx->il); /* Eccoci al ciclo principale. */ while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ - curTime = timeGetTime(); - dwSleepTime=(uint32) - 1L; + _ctx->curTime = timeGetTime(); + _ctx->dwSleepTime = (uint32)-1L; - for (k = 0;k= MyActions[k].dwLastTime + MyActions[k].wTime) { - dwSleepTime = 0; + for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) + if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { + _ctx->dwSleepTime = 0; break; } else - dwSleepTime = MIN(dwSleepTime,MyActions[k].dwLastTime+MyActions[k].wTime-curTime); + _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); /* Ci addormentiamo, ma controllando sempre l'evento che viene settato quando viene richiesta la nostra chiusura */ - k = WaitForSingleObject(hEndPollingLocations[id], dwSleepTime); - if (k == WAIT_OBJECT_0) + _ctx->k = WaitForSingleObject(hEndPollingLocations[id], _ctx->dwSleepTime); + if (_ctx->k == WAIT_OBJECT_0) break; - for (i = 0; i < nRealItems; i++) - if (MyThreads[i].nItem != 0) { - if (WaitForSingleObject(MyThreads[i].hThread, 0) == WAIT_OBJECT_0) - MyThreads[i].nItem = 0; + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + if (_ctx->MyThreads[_ctx->i].nItem != 0) { + CORO_INVOKE_3(_vm->_scheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); + + // if result ) == WAIT_OBJECT_0) + if (!_ctx->delayExpired) + _ctx->MyThreads[_ctx->i].nItem = 0; } - curTime = timeGetTime(); + _ctx->curTime = timeGetTime(); /* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */ - for (k = 0; k < nIdleActions; k++) - if (curTime >= MyActions[k].dwLastTime + MyActions[k].wTime) { - MyActions[k].dwLastTime += MyActions[k].wTime; + for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) + if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { + _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; - /* E' il momento di tirare il nostro dado virtuale, e controllare + /* E' _ctx->il momento di tirare _ctx->il nostro dado virtuale, e controllare se la sorte e' dalla parte della idle action */ byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); - if (randomVal < MyActions[k].perc) { + if (randomVal < _ctx->MyActions[_ctx->k].perc) { /* Controlliamo se c'e' una action in esecuzione sull'item */ - if ((bExecutingAction) && (nExecutingAction == MyActions[k].nItem)) + if ((bExecutingAction) && (nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) continue; /* Controlliamo se c'e' gia' un'altra idle function in esecuzione sullo stesso item */ - for (i = 0; i < nRealItems; i++) - if (MyThreads[i].nItem == MyActions[k].nItem) + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + if (_ctx->MyThreads[_ctx->i].nItem == _ctx->MyActions[_ctx->k].nItem) break; - if (i < nRealItems) + if (_ctx->i < _ctx->nRealItems) continue; /* Ok, siamo gli unici :) */ LockItems(); - curItem=lpmiItems+itemGetOrderFromNum(MyActions[k].nItem); + _ctx->curItem=lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); /* Controlliamo se c'e' un esperessione WhenExecute */ - j=MyActions[k].nAction; - if (curItem->Action[j].when != NULL) - if (!EvaluateExpression(curItem->Action[j].when)) { + _ctx->j=_ctx->MyActions[_ctx->k].nAction; + if (_ctx->curItem->Action[_ctx->j].when != NULL) + if (!EvaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { UnlockItems(); continue; } /* Ok, possiamo eseguire la azione. Per comodita' lo facciamo in un nuovo thread */ - newItem=(LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); - if (newItem == false) { - GlobalFree(MyThreads); - GlobalFree(MyActions); - ExitThread(0); -// _endthread(); + _ctx->newItem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + if (_ctx->newItem == false) { + GlobalFree(_ctx->MyThreads); + GlobalFree(_ctx->MyActions); + + CORO_KILL_SELF(); + return; } - CopyMemory(newItem,curItem, sizeof(MPALITEM)); + CopyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); UnlockItems(); /* Copiamo l'azione nella #0 */ -// newItem->Action[0].nCmds = curItem->Action[j].nCmds; -// CopyMemory(newItem->Action[0].CmdNum,curItem->Action[j].CmdNum,newItem->Action[0].nCmds*sizeof(newItem->Action[0].CmdNum[0])); - newItem->dwRes=j; +// _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; +// CopyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); + _ctx->newItem->dwRes=_ctx->j; /* Creaiamo l'action thread. Provvedera' lui a liberare la memoria - allocata per il nuovo item */ - for (i = 0; i < nRealItems; i++) - if (MyThreads[i].nItem == 0) + allocata per _ctx->il nuovo item */ + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + if (_ctx->MyThreads[_ctx->i].nItem == 0) break; - MyThreads[i].nItem=MyActions[k].nItem; + _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; // !!! Nuova gestione dei thread - if ((MyThreads[i].hThread = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)ActionThread,(void *)newItem, 0, &dwId)) == NULL) { - //if ((MyThreads[i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)newItem))==(void*)-1) - GlobalFree(newItem); - GlobalFree(MyThreads); - GlobalFree(MyActions); - ExitThread(0); -// _endthread(); + if ((_ctx->MyThreads[_ctx->i].hThread = _vm->_scheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { + //if ((_ctx->MyThreads[_ctx->i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))==(void*)-1) + GlobalFree(_ctx->newItem); + GlobalFree(_ctx->MyThreads); + GlobalFree(_ctx->MyActions); + + CORO_KILL_SELF(); + return; } /* Skippa tutte le idle action dello stesso item */ @@ -1251,16 +1264,16 @@ void PASCAL LocationPollThread(uint32 id) { } } - /* Chiude tutti i thread interni */ + /* Chiude tutti _ctx->i thread interni */ /* CODICE OBSOLETO: ANDIAMO DI SKIP CHE RULLA - for (i = 0; i < nRealItems; i++) - if (MyThreads[i].nItem != 0) { - TerminateThread(MyThreads[i].hThread, 0); - CloseHandle(MyThreads[i].hThread); + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + if (_ctx->MyThreads[_ctx->i].nItem != 0) { + TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); + CloseHandle(_ctx->MyThreads[_ctx->i].hThread); } */ @@ -1268,23 +1281,28 @@ void PASCAL LocationPollThread(uint32 id) { // FIXME: Convert to co-routine lplpFunctions[200](nullContext, 0, 0, 0, 0); - for (i = 0; i < nRealItems; i++) - if (MyThreads[i].nItem != 0) { - if (WaitForSingleObject(MyThreads[i].hThread,5000) != WAIT_OBJECT_0) - TerminateThread(MyThreads[i].hThread, 0); + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + if (_ctx->MyThreads[_ctx->i].nItem != 0) { + CORO_INVOKE_3(_vm->_scheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); - CloseHandle(MyThreads[i].hThread); +/* + //if (result != WAIT_OBJECT_0) + if (_ctx->delayExpired) + TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); +*/ + _vm->_scheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); } // Set idle skip off - // FIXME: Convert to co-routine - lplpFunctions[201](nullContext, 0, 0, 0, 0); + CORO_INVOKE_4(lplpFunctions[201], 0, 0, 0, 0); /* Abbiamo finito */ - GlobalFree(MyThreads); - GlobalFree(MyActions); - ExitThread(1); -//endthread(); + GlobalFree(_ctx->MyThreads); + GlobalFree(_ctx->MyActions); + + CORO_KILL_SELF(); + + CORO_END_CODE; } @@ -1516,7 +1534,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = lpmiItems; int i; LPMPALITEM newitem; - PROCESS *h; + uint32 h; item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); @@ -1552,10 +1570,10 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // 0 dell'item, e poi liberera' la memoria con la GlobalFree() // !!! New thread management - if ((h = g_scheduler->createProcess(ActionThread, newitem)) == NULL) + if ((h = g_scheduler->createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL) return INVALID_HANDLE_VALUE; - if ((h = g_scheduler->createProcess(ShutUpActionThread, &h->pid, sizeof(int))) == NULL) + if ((h = g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32))) == NULL) return INVALID_HANDLE_VALUE; /* @@ -2182,7 +2200,7 @@ void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { * \****************************************************************************/ -bool EXPORT mpalStartIdlePoll(int nLoc) { +bool mpalStartIdlePoll(int nLoc) { uint32 i; uint32 dwId; @@ -2196,7 +2214,7 @@ bool EXPORT mpalStartIdlePoll(int nLoc) { hEndPollingLocations[i] = CreateEvent(NULL, true, false, NULL); // !!! Nuova gestione dei thread - if ((PollingThreads[i] = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)LocationPollThread,(void *)i, 0, &dwId)) == NULL) + if ((PollingThreads[i] = _vm->_scheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) // if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) return false; @@ -2222,22 +2240,32 @@ bool EXPORT mpalStartIdlePoll(int nLoc) { * \****************************************************************************/ -bool EXPORT mpalEndIdlePoll(int nLoc) { - uint32 i; +void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { + CORO_BEGIN_CONTEXT; + int i; + CORO_END_CONTEXT(_ctx); - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) - if (nPollingLocations[i] == (uint32)nLoc) { - SetEvent(hEndPollingLocations[i]); + CORO_BEGIN_CODE(_ctx); + + for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { + if (nPollingLocations[_ctx->i] == (uint32)nLoc) { + SetEvent(hEndPollingLocations[_ctx->i]); - WaitForSingleObject(PollingThreads[i], INFINITE); + CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, PollingThreads[_ctx->i], INFINITE); - CloseHandle(hEndPollingLocations[i]); - nPollingLocations[i] = 0; + CloseHandle(hEndPollingLocations[_ctx->i]); + nPollingLocations[_ctx->i] = 0; - return true; + if (result) + *result = true; + return; + } } - return false; + if (result) + *result = false; + + CORO_END_CODE; } diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 3c2e62d992..9da963d39e 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -704,8 +704,7 @@ bool EXPORT mpalStartIdlePoll(int nLoc); * \****************************************************************************/ -bool EXPORT mpalEndIdlePoll(int nLoc); - +void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result); /****************************************************************************\ -- cgit v1.2.3 From 8bfc60f5c9bdba4b1f37fcf42df4b0aa360c325f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 May 2012 16:39:42 +1000 Subject: TONY: Refactored RMInput class to use ScummVM event loop --- engines/tony/mpal/mpal.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 851de7cb0c..9000693292 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -2202,7 +2202,6 @@ void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { bool mpalStartIdlePoll(int nLoc) { uint32 i; - uint32 dwId; for (i = 0; i < MAXPOLLINGLOCATIONS; i++) if (nPollingLocations[i] == (uint32)nLoc) -- cgit v1.2.3 From 156d8cdb733fe03688da9e2e9844b722681bed7f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 May 2012 21:24:55 +1000 Subject: TONY: Bugfix for waitForSingleObject, and added action process debug information --- engines/tony/mpal/mpal.cpp | 18 ++++++++++++++++-- engines/tony/mpal/mpal.h | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 9000693292..26cbf3652d 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -102,7 +102,8 @@ static byte * lpMpcImage; LPITEMIRQFUNCTION lpiifCustom=NULL; -LPLPCUSTOMFUNCTION lplpFunctions=NULL; +LPLPCUSTOMFUNCTION lplpFunctions = NULL; +Common::String * lplpFunctionStrings = NULL; uint16 nObjs; uint16 nVars; @@ -959,6 +960,12 @@ void ActionThread(CORO_PARAM, const void *param) { if (item->Command[_ctx->k].type == 1) { // Custom function + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", + _vm->_scheduler.getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), + item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, + item->Command[_ctx->k].arg3, item->Command[_ctx->k].arg4 + ); + CORO_INVOKE_4(lplpFunctions[item->Command[_ctx->k].nCf], item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, @@ -968,6 +975,9 @@ void ActionThread(CORO_PARAM, const void *param) { ); } else if (item->Command[_ctx->k].type == 2) { // Variable assign + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", + _vm->_scheduler.getCurrentPID(), item->Command[_ctx->k].lpszVarName); + LockVar(); varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); UnlockVar(); @@ -981,6 +991,8 @@ void ActionThread(CORO_PARAM, const void *param) { GlobalFree(item); + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", _vm->_scheduler.getCurrentPID()); + CORO_KILL_SELF(); CORO_END_CODE; @@ -1705,7 +1717,8 @@ bool DoSelection(uint32 i, uint32 dwData) { * \****************************************************************************/ -bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray) { +bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, + LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings) { Common::File hMpc; byte buf[5]; uint32 nBytesRead; @@ -1719,6 +1732,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUST /* Si salva l'array delle funzioni custom */ lplpFunctions = lplpcfArray; + lplpFunctionStrings = lpcfStrings; /* Apre il file MPC in lettura */ if (!hMpc.open(lpszMpcFileName)) diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 9da963d39e..c9f8625744 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -119,6 +119,7 @@ #include "common/scummsys.h" #include "common/rect.h" +#include "common/str.h" #include "tony/coroutine.h" namespace Tony { @@ -602,7 +603,7 @@ extern "C" { \****************************************************************************/ bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName, - LPLPCUSTOMFUNCTION lplpcfArray); + LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings); -- cgit v1.2.3 From 0b8974ec4ab37ef056ac50c098d3fe8045ec172b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 6 May 2012 23:51:11 +1000 Subject: TONY: Beginnings of converting dialog processes to coroutines --- engines/tony/mpal/mpal.cpp | 585 ++++++++++++++++++++++---------------------- engines/tony/mpal/mpal.h | 8 +- engines/tony/mpal/stubs.cpp | 2 + 3 files changed, 292 insertions(+), 303 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 26cbf3652d..592c4788df 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1335,93 +1335,101 @@ void LocationPollThread(CORO_PARAM, const void *param) { * \****************************************************************************/ -void PASCAL ShutUpDialogThread(HANDLE hThread) { - WaitForSingleObject(hThread, INFINITE); +void ShutUpDialogThread(CORO_PARAM, const void *param) { + CORO_BEGIN_CONTEXT; + CORO_END_CONTEXT(_ctx); + + uint32 pid = *(const uint32 *)param; + + CORO_BEGIN_CODE(_ctx); + + CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, pid, INFINITE); bExecutingDialog = false; nExecutingDialog = 0; nExecutingChoice = 0; SetEvent(hAskChoice); - ExitThread(1); -// _endthread(); + + CORO_KILL_SELF(); + + CORO_END_CODE; } +void DoChoice(CORO_PARAM, uint32 nChoice); -/****************************************************************************\ -* -* Function: void GroupThread(uint32 nGroup); -* -* Description: Esegue un gruppo del dialogo corrente. Puo' essere lo -* starting point di un thread. -* -* Input: uint32 nGroup Numero del gruppo da eseguire -* -\****************************************************************************/ -void DoChoice(uint32 nChoice); +/** + * Executes a group of the current dialog. Can 'be the Starting point of a process. + * @parm nGroup Number of the group to perform + */ +void GroupThread(CORO_PARAM, const void *param) { + CORO_BEGIN_CONTEXT; + LPMPALDIALOG dialog; + int i, j, k; + int type; + CORO_END_CONTEXT(_ctx); -void PASCAL GroupThread(uint32 nGroup) { - LPMPALDIALOG dialog; - int i, j, k; + uint32 nGroup = *(const uint32 *)param; + + CORO_BEGIN_CODE(_ctx); - /* Locka i dialoghi */ + // Lock the _ctx->dialog LockDialogs(); - /* Trova il puntatore al dialogo corrente */ - dialog = lpmdDialogs+nExecutingDialog; - - /* Cerca il gruppo richiesto all'interno del dialogo */ - for (i = 0; dialog->Group[i].num != 0; i++) - if (dialog->Group[i].num==nGroup) { - /* Cicla eseguendo i comandi del gruppo */ - for (j = 0; j < dialog->Group[i].nCmds; j++) { - k=dialog->Group[i].CmdNum[j]; - - switch (dialog->Command[k].type) { - /* Funzione custom: la richiama */ - case 1: - // FIXME: Convert to co-routine - lplpFunctions[dialog->Command[k].nCf]( - nullContext, - dialog->Command[k].arg1, - dialog->Command[k].arg2, - dialog->Command[k].arg3, - dialog->Command[k].arg4 + // Find the pointer to the current _ctx->dialog + _ctx->dialog = lpmdDialogs + nExecutingDialog; + + // Search inside the group requesting the _ctx->dialog + for (_ctx->i = 0; _ctx->dialog->Group[_ctx->i].num != 0; _ctx->i++) { + if (_ctx->dialog->Group[_ctx->i].num == nGroup) { + // Cycle through executing the commands of the group + for (_ctx->j = 0; _ctx->j < _ctx->dialog->Group[_ctx->i].nCmds; _ctx->j++) { + _ctx->k = _ctx->dialog->Group[_ctx->i].CmdNum[_ctx->j]; + + _ctx->type = _ctx->dialog->Command[_ctx->k].type; + if (_ctx->type == 1) { + // Call custom function + CORO_INVOKE_4(lplpFunctions[_ctx->dialog->Command[_ctx->k].nCf], + _ctx->dialog->Command[_ctx->k].arg1, + _ctx->dialog->Command[_ctx->k].arg2, + _ctx->dialog->Command[_ctx->k].arg3, + _ctx->dialog->Command[_ctx->k].arg4 ); - break; - /* Variabile: la setta */ - case 2: + } else if (_ctx->type == 2) { + // Set a variable LockVar(); - varSetValue(dialog->Command[k].lpszVarName,EvaluateExpression(dialog->Command[k].expr)); + varSetValue(_ctx->dialog->Command[_ctx->k].lpszVarName, EvaluateExpression(_ctx->dialog->Command[_ctx->k].expr)); UnlockVar(); - break; - - /* DoChoice: richiama la funzione di scelta */ - case 3: - DoChoice((uint32)dialog->Command[k].nChoice); - break; - - default: + + } else if (_ctx->type == 3) { + // DoChoice: call the chosen function + CORO_INVOKE_1(DoChoice, (uint32)_ctx->dialog->Command[_ctx->k].nChoice); + + } else { mpalError = 1; UnlockDialogs(); - ExitThread(0); -// _endthread(); + + CORO_KILL_SELF(); + return; + } } - } - /* Abbiamo eseguito il gruppo. Possiamo uscire alla funzione chiamante. - Se il gruppo era il primo chiamato, allora automaticamente il - thread viene chiuso, altrimenti si ritorno al gruppo chiamante. */ - UnlockDialogs(); - return; + /* The gruop is finished, so we can return to the calling function. + * If the group was the first called, then the process will automatically + * end. Otherwise it returns to the caller method + */ + return; + } } /* Se siamo qui, vuol dire che non abbiamo trovato il gruppo richiesto */ mpalError = 1; UnlockDialogs(); - ExitThread(0); -// _endthread(); + + CORO_KILL_SELF(); + + CORO_END_CODE; } @@ -1435,52 +1443,58 @@ void PASCAL GroupThread(uint32 nGroup) { * \****************************************************************************/ -void DoChoice(uint32 nChoice) { - LPMPALDIALOG dialog; - int i,j,k; +void DoChoice(CORO_PARAM, uint32 nChoice) { + CORO_BEGIN_CONTEXT; + LPMPALDIALOG dialog; + int i, j, k; + uint32 nGroup; + CORO_END_CONTEXT(_ctx); + + CORO_BEGIN_CODE(_ctx); - /* Locka i dialoghi */ + /* Locka _ctx->i dialoghi */ LockDialogs(); /* Trova il puntatore al dialogo corrente */ - dialog=lpmdDialogs+nExecutingDialog; + _ctx->dialog=lpmdDialogs+nExecutingDialog; /* Cerca la scelta richiesta tra quelle nel dialogo */ - for (i = 0; dialog->Choice[i].nChoice != 0; i++) - if (dialog->Choice[i].nChoice == nChoice) + for (_ctx->i = 0; _ctx->dialog->Choice[_ctx->i].nChoice != 0; _ctx->i++) + if (_ctx->dialog->Choice[_ctx->i].nChoice == nChoice) break; /* Se non l'ha trovata, esce con errore */ - if (dialog->Choice[i].nChoice == 0) { + if (_ctx->dialog->Choice[_ctx->i].nChoice == 0) { /* Se siamo qui, non abbiamo trovato la choice richiesta */ mpalError = 1; UnlockDialogs(); - ExitThread(0); -// _endthread(); + + CORO_KILL_SELF(); + return; } /* Abbiamo trova la choice richiesta. Ricordiamoci qual e' nella variabile globale */ - nExecutingChoice = i; + nExecutingChoice = _ctx->i; while (1) { - nExecutingChoice = i; + nExecutingChoice = _ctx->i; - k = 0; + _ctx->k = 0; /* Calcoliamo le when expression di ciascun select, per vedere se sono attivi o disattivi */ - for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) - if (dialog->Choice[i].Select[j].when == NULL) { - dialog->Choice[i].Select[j].curActive = 1; - k++; - } else if (EvaluateExpression(dialog->Choice[i].Select[j].when)) { - dialog->Choice[i].Select[j].curActive = 1; - k++; + for (_ctx->j = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].dwData != 0; _ctx->j++) + if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].when == NULL) { + _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 1; + _ctx->k++; + } else if (EvaluateExpression(_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].when)) { + _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 1; + _ctx->k++; } else - dialog->Choice[i].Select[j].curActive = 0; + _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 0; /* Se non ci sono scelte attivate, la scelta e' finita */ - if (k == 0) { + if (_ctx->k == 0) { UnlockDialogs(); break; } @@ -1491,31 +1505,36 @@ void DoChoice(uint32 nChoice) { SetEvent(hAskChoice); WaitForSingleObject(hDoneChoice, INFINITE); - /* Ora che la scelta e' stata effettuata, possiamo eseguire i gruppi + /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi associati con la scelta */ - j=nSelectedChoice; - for (k = 0; dialog->Choice[i].Select[j].wPlayGroup[k] != 0; k++) - GroupThread(dialog->Choice[i].Select[j].wPlayGroup[k]); + _ctx->j = nSelectedChoice; + for (_ctx->k = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { + _ctx->nGroup = _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k]; + CORO_INVOKE_1(GroupThread, &_ctx->nGroup); + } /* Controllo sugli attributi */ - if (dialog->Choice[i].Select[j].attr & (1 << 0)) { + if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 0)) { /* Bit 0 settato: fine della scelta */ UnlockDialogs(); break; } - if (dialog->Choice[i].Select[j].attr & (1 << 1)) { + if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 1)) { /* Bit 1 settato: fine del dialogo */ UnlockDialogs(); - ExitThread(1); -// _endthread(); + + CORO_KILL_SELF(); + return; } /* Fine della scelta senza attributi: bisogna rifarla */ } - /* Se siamo qui, abbiamo trovato un end choice. Ritorna al gruppo chiamante */ + // If we're here, we found an end choice. Return to the caller group return; + + CORO_END_CODE; } @@ -1605,57 +1624,40 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { return INVALID_HANDLE_VALUE; } +/** + * Shows a dialog in a separate process. + * + * @param nDlgOrd The index of the dialog in the dialog list + * @param nGroup Number of the group to perform + * @returns The process Id of the process running the dialog + * or INVALID_HANDLE_VALUE on error + * @remarks The dialogue runs in a thread created on purpose, + * so that must inform through an event and when 'necessary to you make a choice. + * The data on the choices may be obtained through various queries. + */ +static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { + uint32 h; -/****************************************************************************\ -* -* Function: HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup); -* -* Description: Esegue un dialogo in un thread -* -* Input: uint32 nDlgOrd Indice del dialogo da eseguire -* all'interno dell'array di strutture -* dei dialoghi -* uint32 nGroup Numero del gruppo da eseguire -* -* Return: Handle del thread che sta eseguendo il dialogo, o -* INVALID_HANDLE_VALUE in caso di errore -* -* Note: Il dialogo viene eseguito in un thread creato apposta, che -* deve informa tramite un evento quando e' necessario far -* fare una scelta all'utente. I dati sulle scelte possono -* essere richiesti tramite le varie query. -* -\****************************************************************************/ - -static HANDLE DoDialog(uint32 nDlgOrd, uint32 nGroup) { -// LPMPALDIALOG dialog=lpmdDialogs+nDlgOrd; - uint32 dwId; - HANDLE h; - - /* Si ricorda nella variabile globale qual e' il dialogo in esecuzione */ + // Store the running dialog in a global variable nExecutingDialog = nDlgOrd; - /* Attiva la flag per indicare che c'e' un dialogo in esecuzione */ + // Enables the flag to indicate that there is' a running dialogue bExecutingDialog = true; ResetEvent(hAskChoice); ResetEvent(hDoneChoice); - /* Crea un thread in cui esegue un gruppo del dialogo */ + // Create a thread that performs the dialogue group - // !!! Nuova gestione dei thread - if ((h = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)GroupThread, (void *)nGroup, 0, &dwId)) == NULL) - // if ((h=(void*)_beginthread(GroupThread, 10240,(void *)nGroup))==(void*)-1) - return INVALID_HANDLE_VALUE; + // Create the process + if ((h = _vm->_scheduler.createProcess(GroupThread, &nGroup, sizeof(uint32))) == 0) + return 0; - /* Crea un thread che attende la fine del dialogo e rimette a posto le - variabili globali */ - // !!! Nuova gestione dei thread - if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ShutUpDialogThread,(void *)h, 0, &dwId) == NULL) { - //if ((h=(void*)_beginthread(ShutUpDialogThread, 10240,(void *)h))==(void*)-1) - TerminateThread(h, 0); - CloseHandle(h); - return INVALID_HANDLE_VALUE; + // Create a thread that waits until the end of the dialog process, and will restore the global variables + if (_vm->_scheduler.createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == 0) { + // Something went wrong, so kill the previously started dialog process + _vm->_scheduler.killMatchingProcess(h); + return 0; } return h; @@ -1893,243 +1895,230 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, #define GETARG(type) va_arg(v,type) -uint32 mpalQuery(uint16 wQueryType, ...) { - uint32 dwRet = 0; - int x, y, z; - char *n; - va_list v; - Common::String buf; +void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { + CORO_BEGIN_CONTEXT; + int x, y, z; + char *n; + Common::String buf; + CORO_END_CONTEXT(_ctx); + + CORO_BEGIN_CODE(_ctx); mpalError = OK; - va_start(v, wQueryType); - switch (wQueryType) { - /* - * uint32 mpalQuery(MPQ_VERSION); - */ - case MPQ_VERSION: - dwRet = HEX_VERSION; - break; + if (wQueryType == MPQ_VERSION) { + /* + * uint32 mpalQuery(MPQ_VERSION); + */ + *dwRet = HEX_VERSION; - /* - * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); - */ - case MPQ_GLOBAL_VAR: + } else if (wQueryType == MPQ_GLOBAL_VAR) { + /* + * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); + */ LockVar(); - dwRet = (uint32)varGetValue(GETARG(char *)); + *dwRet = (uint32)varGetValue(GETARG(char *)); UnlockVar(); - break; - /* - * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg); - */ - case MPQ_MESSAGE: + } else if (wQueryType == MPQ_MESSAGE) { + /* + * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg); + */ LockMsg(); - dwRet = (uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); + *dwRet = (uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); UnlockMsg(); - break; - - /* - * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); - */ - case MPQ_ITEM_PATTERN: + + } else if (wQueryType == MPQ_ITEM_PATTERN) { + /* + * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); + */ LockVar(); - buf = Common::String::format("Pattern.%u", GETARG(uint32)); - dwRet = (uint32)varGetValue(buf.c_str()); + _ctx->buf = Common::String::format("Pattern.%u", GETARG(uint32)); + *dwRet = (uint32)varGetValue(_ctx->buf.c_str()); UnlockVar(); - break; - - /* - * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); - */ - case MPQ_LOCATION_SIZE: + + } else if (wQueryType == MPQ_LOCATION_SIZE) { + /* + * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); + */ LockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); - if (x != -1) { - if (y == MPQ_X) - dwRet = lpmlLocations[x].dwXlen; - else if (y == MPQ_Y) - dwRet = lpmlLocations[x].dwYlen; + _ctx->x = locGetOrderFromNum(GETARG(uint32)); + _ctx->y = GETARG(uint32); + if (_ctx->x != -1) { + if (_ctx->y == MPQ_X) + *dwRet = lpmlLocations[_ctx->x].dwXlen; + else if (_ctx->y == MPQ_Y) + *dwRet = lpmlLocations[_ctx->x].dwYlen; else mpalError = 1; } else mpalError = 1; UnlockLocations(); - break; - - /* - * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); - */ - case MPQ_LOCATION_IMAGE: + + } else if (wQueryType == MPQ_LOCATION_IMAGE) { + /* + * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); + */ LockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); - dwRet = (uint32)resLoad(lpmlLocations[x].dwPicRes); + _ctx->x = locGetOrderFromNum(GETARG(uint32)); + *dwRet = (uint32)resLoad(lpmlLocations[_ctx->x].dwPicRes); UnlockLocations(); - break; - /* - * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); - */ - case MPQ_RESOURCE: - dwRet = (uint32)resLoad(GETARG(uint32)); - break; + } else if (wQueryType == MPQ_RESOURCE) { + /* + * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); + */ + *dwRet = (uint32)resLoad(GETARG(uint32)); - /* - * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); - */ - case MPQ_ITEM_LIST: + } else if (wQueryType == MPQ_ITEM_LIST) { + /* + * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); + */ LockVar(); - dwRet = (uint32)GetItemList(GETARG(uint32)); + *dwRet = (uint32)GetItemList(GETARG(uint32)); LockVar(); - break; - /* - * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); - */ - case MPQ_ITEM_DATA: + } else if (wQueryType == MPQ_ITEM_DATA) { + /* + * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); + */ LockItems(); - dwRet = (uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); + *dwRet = (uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); UnlockItems(); - break; - /* - * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); - */ - case MPQ_ITEM_IS_ACTIVE: + } else if (wQueryType == MPQ_ITEM_IS_ACTIVE) { + /* + * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); + */ LockVar(); - x = GETARG(uint32); - buf = Common::String::format("Status.%u", x); - if (varGetValue(buf.c_str()) <= 0) - dwRet = (uint32)false; + _ctx->x = GETARG(uint32); + _ctx->buf = Common::String::format("Status.%u", _ctx->x); + if (varGetValue(_ctx->buf.c_str()) <= 0) + *dwRet = (uint32)false; else - dwRet = (uint32)true; + *dwRet = (uint32)true; UnlockVar(); - break; - - /* - * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); - */ - case MPQ_ITEM_NAME: + } else if (wQueryType == MPQ_ITEM_NAME) { + /* + * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); + */ LockVar(); - x = GETARG(uint32); - n=GETARG(char *); - buf = Common::String::format("Status.%u", x); - if (varGetValue(buf.c_str()) <= 0) - n[0]='\0'; + _ctx->x = GETARG(uint32); + _ctx->n = GETARG(char *); + _ctx->buf = Common::String::format("Status.%u", _ctx->x); + if (varGetValue(_ctx->buf.c_str()) <= 0) + _ctx->n[0]='\0'; else { LockItems(); - y = itemGetOrderFromNum(x); - CopyMemory(n, (char *)(lpmiItems+y)->lpszDescribe, MAX_DESCRIBE_SIZE); + _ctx->y = itemGetOrderFromNum(_ctx->x); + CopyMemory(_ctx->n, (char *)(lpmiItems+_ctx->y)->lpszDescribe, MAX_DESCRIBE_SIZE); UnlockItems(); } UnlockVar(); - break; - - /* - * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); - */ - case MPQ_DIALOG_PERIOD: + } else if (wQueryType == MPQ_DIALOG_PERIOD) { + /* + * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); + */ LockDialogs(); - y = GETARG(uint32); - dwRet = (uint32)DuplicateDialogPeriod(y); + _ctx->y = GETARG(uint32); + *dwRet = (uint32)DuplicateDialogPeriod(_ctx->y); UnlockDialogs(); - break; - - /* - * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); - */ - case MPQ_DIALOG_WAITFORCHOICE: + } else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) { + /* + * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); + */ WaitForSingleObject(hAskChoice, INFINITE); ResetEvent(hAskChoice); if (bExecutingDialog) - dwRet = (uint32)nExecutingChoice; + *dwRet = (uint32)nExecutingChoice; else - dwRet = (uint32)((int)-1); - break; - + *dwRet = (uint32)((int)-1); - /* - * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); - */ - case MPQ_DIALOG_SELECTLIST: + } else if (wQueryType == MPQ_DIALOG_SELECTLIST) { + /* + * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); + */ LockDialogs(); - dwRet = (uint32)GetSelectList(GETARG(uint32)); + *dwRet = (uint32)GetSelectList(GETARG(uint32)); UnlockDialogs(); break; - /* - * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); - */ - case MPQ_DIALOG_SELECTION: + } else if (wQueryType == MPQ_DIALOG_SELECTION) { + /* + * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); + */ LockDialogs(); - x = GETARG(uint32); - y = GETARG(uint32); - dwRet = (uint32)DoSelection(x,y); + _ctx->x = GETARG(uint32); + _ctx->y = GETARG(uint32); + *dwRet = (uint32)DoSelection(_ctx->x,_ctx->y); UnlockDialogs(); - break; - - - /* - * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam); - */ - case MPQ_DO_ACTION: - /* - if (bExecutingAction) - { - dwRet = (uint32)INVALID_HANDLE_VALUE; - break; - } - */ + } else if (wQueryType == MPQ_DO_ACTION) { + /* + * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam); + */ LockItems(); LockVar(); - x = GETARG(uint32); - z = GETARG(uint32); - y = itemGetOrderFromNum(z); - if (y!=-1) { - dwRet = (uint32)DoAction(x, y, GETARG(uint32)); + _ctx->x = GETARG(uint32); + _ctx->z = GETARG(uint32); + _ctx->y = itemGetOrderFromNum(_ctx->z); + if (_ctx->y!=-1) { + *dwRet = (uint32)DoAction(_ctx->x, _ctx->y, GETARG(uint32)); } else { - dwRet = (uint32)INVALID_HANDLE_VALUE; + *dwRet = (uint32)INVALID_HANDLE_VALUE; mpalError = 1; } UnlockVar(); UnlockItems(); - break; - /* - * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); - */ - case MPQ_DO_DIALOG: - if (bExecutingDialog) - break; + } else if (wQueryType == MPQ_DO_DIALOG) { + /* + * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); + */ + if (!bExecutingDialog) { + LockDialogs(); - LockDialogs(); - - x = dialogGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); - dwRet = (uint32)DoDialog(x, y); - UnlockDialogs(); - break; - - /* - * DEFAULT -> ERROR - */ - default: + _ctx->x = dialogGetOrderFromNum(GETARG(uint32)); + _ctx->y = GETARG(uint32); + *dwRet = DoDialog(_ctx->x, _ctx->y); + UnlockDialogs(); + } + } else { + /* + * DEFAULT -> ERROR + */ mpalError = 1; - break; } + CORO_END_CODE; +} + +uint32 mpalQuery(uint16 wQueryType, ...) { + uint32 dwRet; + va_list v; + va_start(v, wQueryType); + + mpalQueryInner(nullContext, wQueryType, &dwRet, v); + va_end(v); return dwRet; } +void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...) { + va_list v; + va_start(v, wQueryType); + + mpalQueryInner(coroParam, wQueryType, dwRet, v); + + va_end(v); +} + /****************************************************************************\ * diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index c9f8625744..5517a6518c 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -474,10 +474,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * \****************************************************************************/ -#define mpalQueryDialogWaitForChoice() \ - (int)mpalQuery(MPQ_DIALOG_WAITFORCHOICE) - - +#define mpalQueryDialogWaitForChoice(dwRet) \ + CORO_INVOKE_2(mpalQueryCoro, dwRet, MPQ_DIALOG_WAITFORCHOICE) /****************************************************************************\ * @@ -627,7 +625,7 @@ bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName, uint32 EXPORT mpalQuery(uint16 wQueryType, ...); - +void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...); /****************************************************************************\ * diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 9d4a87d61c..0fc01d4d07 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -80,10 +80,12 @@ void Sleep(uint32 time) { } int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime) { + warning("TODO: Old style WaitForSingleObject"); return 0; } uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds) { + warning("TODO: Old style WaitForMultipleObjects"); return 0; } -- cgit v1.2.3 From 8527302057052e784c3ea32ca8eebb0220bf15e6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 8 May 2012 08:25:33 +1000 Subject: TONY: Added support for threading events to scheduler, converted more procs to coroutines --- engines/tony/mpal/mpal.cpp | 27 ++++++++++++++------------- engines/tony/mpal/stubs.cpp | 4 ++++ 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 592c4788df..c5ded67c81 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -141,8 +141,8 @@ uint32 nPollingLocations[MAXPOLLINGLOCATIONS]; HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS]; uint32 PollingThreads[MAXPOLLINGLOCATIONS]; -HANDLE hAskChoice; -HANDLE hDoneChoice; +uint32 hAskChoice; +uint32 hDoneChoice; uint32 nExecutingAction; @@ -1349,7 +1349,7 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { nExecutingDialog = 0; nExecutingChoice = 0; - SetEvent(hAskChoice); + _vm->_scheduler.setEvent(hAskChoice); CORO_KILL_SELF(); @@ -1501,9 +1501,9 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, e restiamo in attesa della risposta */ - ResetEvent(hDoneChoice); - SetEvent(hAskChoice); - WaitForSingleObject(hDoneChoice, INFINITE); + _vm->_scheduler.resetEvent(hDoneChoice); + _vm->_scheduler.setEvent(hAskChoice); + CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, hDoneChoice, INFINITE); /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi associati con la scelta */ @@ -1644,8 +1644,8 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { // Enables the flag to indicate that there is' a running dialogue bExecutingDialog = true; - ResetEvent(hAskChoice); - ResetEvent(hDoneChoice); + _vm->_scheduler.resetEvent(hAskChoice); + _vm->_scheduler.resetEvent(hDoneChoice); // Create a thread that performs the dialogue group @@ -1690,7 +1690,7 @@ bool DoSelection(uint32 i, uint32 dwData) { return false; nSelectedChoice = j; - SetEvent(hDoneChoice); + _vm->_scheduler.setEvent(hDoneChoice); return true; } @@ -1867,8 +1867,8 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' da effettuare una scelta */ - hAskChoice = CreateEvent(NULL, true, false, NULL); - hDoneChoice = CreateEvent(NULL, true, false, NULL); + hAskChoice = _vm->_scheduler.createEvent(true, false); + hDoneChoice = _vm->_scheduler.createEvent(true, false); return true; } @@ -2031,8 +2031,9 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - WaitForSingleObject(hAskChoice, INFINITE); - ResetEvent(hAskChoice); + CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, hAskChoice, INFINITE); + + _vm->_scheduler.resetEvent(hAskChoice); if (bExecutingDialog) *dwRet = (uint32)nExecutingChoice; diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 0fc01d4d07..58ecc6d6d9 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -90,16 +90,20 @@ uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWait } HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName) { + warning("TODO: Refactor call to old style CreateEvent method"); return 0; } void SetEvent(HANDLE hEvent) { + warning("TODO: Refactor call to old style SetEvent method"); } void ResetEvent(HANDLE hEvent) { + warning("TODO: Refactor call to old style ResetEvent method"); } void PulseEvent(HANDLE hEvent) { + warning("TODO: Refactor call to old style PulseEvent method"); } uint16 GetAsyncKeyState(Common::KeyCode kc) { -- cgit v1.2.3 From a254f100253bda1b23f280226b7b4d909206d49c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 8 May 2012 09:32:21 +1000 Subject: TONY: Added support for Windows-style threading events to scheduler --- engines/tony/mpal/mpal.cpp | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index c5ded67c81..0cea50a3d3 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -961,7 +961,7 @@ void ActionThread(CORO_PARAM, const void *param) { if (item->Command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - _vm->_scheduler.getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), + g_scheduler->getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, item->Command[_ctx->k].arg3, item->Command[_ctx->k].arg4 ); @@ -976,7 +976,7 @@ void ActionThread(CORO_PARAM, const void *param) { } else if (item->Command[_ctx->k].type == 2) { // Variable assign debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", - _vm->_scheduler.getCurrentPID(), item->Command[_ctx->k].lpszVarName); + g_scheduler->getCurrentPID(), item->Command[_ctx->k].lpszVarName); LockVar(); varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); @@ -991,7 +991,7 @@ void ActionThread(CORO_PARAM, const void *param) { GlobalFree(item); - debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", _vm->_scheduler.getCurrentPID()); + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", g_scheduler->getCurrentPID()); CORO_KILL_SELF(); @@ -1012,7 +1012,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, pid, INFINITE); + CORO_INVOKE_2(g_scheduler->waitForSingleObject, pid, INFINITE); bExecutingAction = false; @@ -1190,7 +1190,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(_vm->_scheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); + CORO_INVOKE_3(g_scheduler->waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); // if result ) == WAIT_OBJECT_0) if (!_ctx->delayExpired) @@ -1261,7 +1261,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; // !!! Nuova gestione dei thread - if ((_ctx->MyThreads[_ctx->i].hThread = _vm->_scheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { + if ((_ctx->MyThreads[_ctx->i].hThread = g_scheduler->createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { //if ((_ctx->MyThreads[_ctx->i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))==(void*)-1) GlobalFree(_ctx->newItem); GlobalFree(_ctx->MyThreads); @@ -1295,14 +1295,14 @@ void LocationPollThread(CORO_PARAM, const void *param) { for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(_vm->_scheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); + CORO_INVOKE_3(g_scheduler->waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); /* //if (result != WAIT_OBJECT_0) if (_ctx->delayExpired) TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); */ - _vm->_scheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); + g_scheduler->killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); } // Set idle skip off @@ -1343,13 +1343,13 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, pid, INFINITE); + CORO_INVOKE_2(g_scheduler->waitForSingleObject, pid, INFINITE); bExecutingDialog = false; nExecutingDialog = 0; nExecutingChoice = 0; - _vm->_scheduler.setEvent(hAskChoice); + g_scheduler->setEvent(hAskChoice); CORO_KILL_SELF(); @@ -1501,9 +1501,9 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, e restiamo in attesa della risposta */ - _vm->_scheduler.resetEvent(hDoneChoice); - _vm->_scheduler.setEvent(hAskChoice); - CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, hDoneChoice, INFINITE); + g_scheduler->resetEvent(hDoneChoice); + g_scheduler->setEvent(hAskChoice); + CORO_INVOKE_2(g_scheduler->waitForSingleObject, hDoneChoice, INFINITE); /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi associati con la scelta */ @@ -1644,19 +1644,19 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { // Enables the flag to indicate that there is' a running dialogue bExecutingDialog = true; - _vm->_scheduler.resetEvent(hAskChoice); - _vm->_scheduler.resetEvent(hDoneChoice); + g_scheduler->resetEvent(hAskChoice); + g_scheduler->resetEvent(hDoneChoice); // Create a thread that performs the dialogue group // Create the process - if ((h = _vm->_scheduler.createProcess(GroupThread, &nGroup, sizeof(uint32))) == 0) + if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == 0) return 0; // Create a thread that waits until the end of the dialog process, and will restore the global variables - if (_vm->_scheduler.createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == 0) { + if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == 0) { // Something went wrong, so kill the previously started dialog process - _vm->_scheduler.killMatchingProcess(h); + g_scheduler->killMatchingProcess(h); return 0; } @@ -1690,7 +1690,7 @@ bool DoSelection(uint32 i, uint32 dwData) { return false; nSelectedChoice = j; - _vm->_scheduler.setEvent(hDoneChoice); + g_scheduler->setEvent(hDoneChoice); return true; } @@ -1867,8 +1867,8 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' da effettuare una scelta */ - hAskChoice = _vm->_scheduler.createEvent(true, false); - hDoneChoice = _vm->_scheduler.createEvent(true, false); + hAskChoice = g_scheduler->createEvent(true, false); + hDoneChoice = g_scheduler->createEvent(true, false); return true; } @@ -2031,9 +2031,9 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, hAskChoice, INFINITE); + CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE); - _vm->_scheduler.resetEvent(hAskChoice); + g_scheduler->resetEvent(hAskChoice); if (bExecutingDialog) *dwRet = (uint32)nExecutingChoice; @@ -2217,7 +2217,7 @@ bool mpalStartIdlePoll(int nLoc) { hEndPollingLocations[i] = CreateEvent(NULL, true, false, NULL); // !!! Nuova gestione dei thread - if ((PollingThreads[i] = _vm->_scheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) + if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) // if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) return false; @@ -2254,7 +2254,7 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { if (nPollingLocations[_ctx->i] == (uint32)nLoc) { SetEvent(hEndPollingLocations[_ctx->i]); - CORO_INVOKE_2(_vm->_scheduler.waitForSingleObject, PollingThreads[_ctx->i], INFINITE); + CORO_INVOKE_2(g_scheduler->waitForSingleObject, PollingThreads[_ctx->i], INFINITE); CloseHandle(hEndPollingLocations[_ctx->i]); nPollingLocations[_ctx->i] = 0; -- cgit v1.2.3 From 26898dd7ad399a641f63eabf04aa2d839f8508fc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 9 May 2012 00:42:27 +1000 Subject: TONY: Completed bulk of initial coro refactoring --- engines/tony/mpal/loadmpc.cpp | 59 ++++++---------- engines/tony/mpal/mpal.cpp | 156 +++++++++++++++++++++++------------------- engines/tony/mpal/stubs.cpp | 70 ------------------- engines/tony/mpal/stubs.h | 36 +--------- 4 files changed, 108 insertions(+), 213 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 27ef3f99c5..9d6ef19e55 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -174,10 +174,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { /* Periodi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; - if (num >= MAX_PERIODS_PER_DIALOG - 1) { - Common::String msg = Common::String::format("Too much periods in dialog #%d", lpmdDialog->nObj); - MessageBox(msg); - } + if (num >= MAX_PERIODS_PER_DIALOG - 1) + error("Too much periods in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -195,19 +193,15 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { num = READ_LE_UINT16(lpBuf); lpBuf += 2; curCmd = 0; - if (num >= MAX_GROUPS_PER_DIALOG) { - Common::String msg = Common::String::format("Too much groups in dialog #%d", lpmdDialog->nObj); - MessageBox(msg); - } + if (num >= MAX_GROUPS_PER_DIALOG) + error("Too much groups in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2; lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++; - if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) { - Common::String msg = Common::String::format("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); - MessageBox(msg); - } + if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) + error("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); for (j = 0; j < lpmdDialog->Group[i].nCmds; j++) { lpmdDialog->Command[curCmd].type = *lpBuf; @@ -262,28 +256,22 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { } } - if (curCmd >= MAX_COMMANDS_PER_DIALOG) { - Common::String msg = Common::String::format("Too much commands in dialog #%d",lpmdDialog->nObj); - MessageBox(msg); - } + if (curCmd >= MAX_COMMANDS_PER_DIALOG) + error("Too much commands in dialog #%d",lpmdDialog->nObj); /* Choices */ num=*(uint16 *)lpBuf; lpBuf += 2; - if (num >= MAX_CHOICES_PER_DIALOG) { - Common::String msg = Common::String::format("Too much choices in dialog #%d",lpmdDialog->nObj); - MessageBox(msg); - } + if (num >= MAX_CHOICES_PER_DIALOG) + error("Too much choices in dialog #%d",lpmdDialog->nObj); for (i = 0; i < num; i++) { lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; num2 = *lpBuf++; - if (num2 >= MAX_SELECTS_PER_CHOICE) { - Common::String msg = Common::String::format("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); - MessageBox(msg); - } + if (num2 >= MAX_SELECTS_PER_CHOICE) + error("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); for (j = 0; j < num2; j++) { // When @@ -311,10 +299,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { // PlayGroup num3 = *lpBuf; *lpBuf++; - if (num3 >= MAX_PLAYGROUPS_PER_SELECT) { - Common::String msg = Common::String::format("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); - MessageBox(msg); - } + if (num3 >= MAX_PLAYGROUPS_PER_SELECT) + error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); for (z = 0; z < num3; z++) { lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -365,10 +351,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { CopyMemory(lpmiItem->lpszDescribe,lpBuf, MIN((byte)127, len)); lpBuf+=len; - if (len >= MAX_DESCRIBE_SIZE) { - Common::String msg = Common::String::format("Describe too long in item #%d",lpmiItem->nObj); - MessageBox(msg); - } + if (len >= MAX_DESCRIBE_SIZE) + error("Describe too long in item #%d",lpmiItem->nObj); lpmiItem->nActions=*lpBuf; lpBuf++; @@ -408,10 +392,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->Action[i].nCmds=*lpBuf; lpBuf++; - if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) { - Common::String msg = Common::String::format("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); - MessageBox(msg); - } + if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) + error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); for (j=0;jAction[i].nCmds;j++) { lpmiItem->Command[curCmd].type=*lpBuf; @@ -455,9 +437,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { curCmd++; if (curCmd >= MAX_COMMANDS_PER_ITEM) { - Common::String msg = Common::String::format("Too much commands in item #%d",lpmiItem->nObj); - MessageBox(msg); - curCmd=0; + error("Too much commands in item #%d",lpmiItem->nObj); + //curCmd=0; } } } diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 0cea50a3d3..d6230d7768 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -137,9 +137,9 @@ uint32 * lpResources; bool bExecutingAction; bool bExecutingDialog; -uint32 nPollingLocations[MAXPOLLINGLOCATIONS]; -HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS]; -uint32 PollingThreads[MAXPOLLINGLOCATIONS]; +uint32 nPollingLocations[MAXPOLLINGLOCATIONS]; +uint32 hEndPollingLocations[MAXPOLLINGLOCATIONS]; +uint32 PollingThreads[MAXPOLLINGLOCATIONS]; uint32 hAskChoice; uint32 hDoneChoice; @@ -830,14 +830,20 @@ static LPITEM GetItemData(uint32 nOrdItem) { * \****************************************************************************/ -void PASCAL CustomThread(LPCFCALL p) { - // FIXME: Convert to proper corotuine call - warning("FIXME: CustomThread call"); +void CustomThread(CORO_PARAM, const void *param) { + CORO_BEGIN_CONTEXT; + LPCFCALL p; + CORO_END_CONTEXT(_ctx); + + CORO_BEGIN_CODE(_ctx); + + _ctx->p = *(LPCFCALL *)param; - lplpFunctions[p->nCf](nullContext, p->arg1, p->arg2, p->arg3, p->arg4); - GlobalFree(p); - ExitThread(1); -// _endthread(); + CORO_INVOKE_4(lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4); + + GlobalFree(_ctx->p); + + CORO_END_CODE; } @@ -855,78 +861,87 @@ void PASCAL CustomThread(LPCFCALL p) { * \****************************************************************************/ -void PASCAL ScriptThread(LPMPALSCRIPT s) { - uint i,j,k; - uint32 dwStartTime = timeGetTime(); - uint32 dwCurTime; - uint32 dwId; - static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT]; - int numHandles = 0; - LPCFCALL p; +void ScriptThread(CORO_PARAM, const void *param) { + CORO_BEGIN_CONTEXT; + uint i, j, k; + uint32 dwStartTime; + uint32 dwCurTime; + uint32 dwId; + int numHandles; + LPCFCALL p; + CORO_END_CONTEXT(_ctx); + + static uint32 cfHandles[MAX_COMMANDS_PER_MOMENT]; + LPMPALSCRIPT s = *(const LPMPALSCRIPT *)param; + + CORO_BEGIN_CODE(_ctx); + + _ctx->dwStartTime = _vm->GetTime(); + _ctx->numHandles = 0; // warning("PlayScript(): Moments: %u\n",s->nMoments); - for (i = 0; i < s->nMoments; i++) { + for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) { // Dorme il tempo necessario per arrivare al momento successivo - if (s->Moment[i].dwTime == -1) { - WaitForMultipleObjects(numHandles, cfHandles, true, INFINITE); - dwStartTime = timeGetTime(); + if (s->Moment[_ctx->i].dwTime == -1) { + CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, _ctx->numHandles, cfHandles, true, INFINITE); + _ctx->dwStartTime = _vm->GetTime(); } else { - dwCurTime = timeGetTime(); - if (dwCurTime < dwStartTime + (s->Moment[i].dwTime * 100)) { - // warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); - Sleep(dwStartTime+(s->Moment[i].dwTime * 100) - dwCurTime); + _ctx->dwCurTime = _vm->GetTime(); + if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { + // warning("PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); + CORO_INVOKE_1(g_scheduler->sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); } } - numHandles = 0; - for (j = 0;jMoment[i].nCmds; j++) { - k=s->Moment[i].CmdNum[j]; + _ctx->numHandles = 0; + for (_ctx->j = 0; _ctx->jMoment[_ctx->i].nCmds; _ctx->j++) { + _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j]; - switch (s->Command[k].type) { - case 1: - p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); - if (p == NULL) { + if (s->Command[_ctx->k].type == 1) { + _ctx->p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); + if (_ctx->p == NULL) { mpalError = 1; - ExitThread(0); -// _endthread(); + + CORO_KILL_SELF(); + return; } - p->nCf=s->Command[k].nCf; - p->arg1=s->Command[k].arg1; - p->arg2=s->Command[k].arg2; - p->arg3=s->Command[k].arg3; - p->arg4=s->Command[k].arg4; + _ctx->p->nCf=s->Command[_ctx->k].nCf; + _ctx->p->arg1=s->Command[_ctx->k].arg1; + _ctx->p->arg2=s->Command[_ctx->k].arg2; + _ctx->p->arg3=s->Command[_ctx->k].arg3; + _ctx->p->arg4=s->Command[_ctx->k].arg4; // !!! Nuova gestione dei thread - if ((cfHandles[numHandles++] = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)CustomThread,(void *)p, 0, &dwId)) == NULL) { - //if ((cfHandles[numHandles++]=(void*)_beginthread(CustomThread, 10240, (void *)p))==(void*)-1) + if ((cfHandles[_ctx->numHandles++] = g_scheduler->createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { mpalError = 1; - ExitThread(0); -// _endthread(); - } - break; - case 2: + CORO_KILL_SELF(); + return; + } + } else if (s->Command[_ctx->k].type == 2) { LockVar(); varSetValue( - s->Command[k].lpszVarName, - EvaluateExpression(s->Command[k].expr) + s->Command[_ctx->k].lpszVarName, + EvaluateExpression(s->Command[_ctx->k].expr) ); UnlockVar(); - break; - default: + } else { mpalError = 1; GlobalFree(s); - ExitThread(0); -// _endthread(); + + CORO_KILL_SELF(); + return; } } } GlobalFree(s); - ExitThread(1); - //_endthread(); + + CORO_KILL_SELF(); + + CORO_END_CODE; } @@ -1063,6 +1078,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { uint32 dwId; int ord; bool delayExpired; + bool expired; MYACTION *MyActions; MYTHREAD *MyThreads; @@ -1122,7 +1138,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } /* Inizializziamo le routine random */ - //curTime = timeGetTime(); + //curTime = _vm->GetTime(); //srand(curTime); @@ -1157,7 +1173,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - _ctx->MyActions[_ctx->k].dwLastTime = timeGetTime(); + _ctx->MyActions[_ctx->k].dwLastTime = _vm->GetTime(); _ctx->k++; } } @@ -1172,7 +1188,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ - _ctx->curTime = timeGetTime(); + _ctx->curTime = _vm->GetTime(); _ctx->dwSleepTime = (uint32)-1L; for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) @@ -1184,8 +1200,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ci addormentiamo, ma controllando sempre l'evento che viene settato quando viene richiesta la nostra chiusura */ - _ctx->k = WaitForSingleObject(hEndPollingLocations[id], _ctx->dwSleepTime); - if (_ctx->k == WAIT_OBJECT_0) + + CORO_INVOKE_3(g_scheduler->waitForSingleObject, hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); + + //if (_ctx->k == WAIT_OBJECT_0) + if (!_ctx->expired) break; for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) @@ -1197,7 +1216,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads[_ctx->i].nItem = 0; } - _ctx->curTime = timeGetTime(); + _ctx->curTime = _vm->GetTime(); /* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */ for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) @@ -2163,10 +2182,9 @@ bool EXPORT mpalExecuteScript(int nScript) { CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT)); UnlockScripts(); -// !!! Nuova gestione dei thread - if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s, 0, &dwId) == NULL) - //if ((void*)_beginthread(ScriptThread, 10240,(void *)s)==(void*)-1) - return false; + // !!! Nuova gestione dei thread + if (g_scheduler->createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == INVALID_PID_VALUE) + return false; return true; } @@ -2213,9 +2231,9 @@ bool mpalStartIdlePoll(int nLoc) { for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (nPollingLocations[i] == 0) { - nPollingLocations[i]=nLoc; + nPollingLocations[i] = nLoc; - hEndPollingLocations[i] = CreateEvent(NULL, true, false, NULL); + hEndPollingLocations[i] = g_scheduler->createEvent(true, false); // !!! Nuova gestione dei thread if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) // if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) @@ -2252,11 +2270,11 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { if (nPollingLocations[_ctx->i] == (uint32)nLoc) { - SetEvent(hEndPollingLocations[_ctx->i]); + g_scheduler->setEvent(hEndPollingLocations[_ctx->i]); CORO_INVOKE_2(g_scheduler->waitForSingleObject, PollingThreads[_ctx->i], INFINITE); - CloseHandle(hEndPollingLocations[_ctx->i]); + g_scheduler->closeEvent(hEndPollingLocations[_ctx->i]); nPollingLocations[_ctx->i] = 0; if (result) diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 58ecc6d6d9..23bc18b0ea 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -36,76 +36,6 @@ namespace Tony { namespace MPAL { -/** - * Display a message - * @param msg Message to display - */ -void MessageBox(const Common::String &msg) { - - _vm->GUIError(msg); -} - -/** - * Gets the current time in milliseconds - */ -uint32 timeGetTime() { - return g_system->getMillis(); -} - -HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, - LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, - uint32 dwCreationFlags, uint32 *lpThreadId) { - *lpThreadId = 0; - return 0; -} - -void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter) { -} - -void ExitThread(int ThreadId) { -} - -void _endthread() { -} - -void TerminateThread(HANDLE ThreadId, uint32 dwExitCode) { - -} - -void CloseHandle(HANDLE ThreadId) { - -} - -void Sleep(uint32 time) { -} - -int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime) { - warning("TODO: Old style WaitForSingleObject"); - return 0; -} - -uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds) { - warning("TODO: Old style WaitForMultipleObjects"); - return 0; -} - -HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName) { - warning("TODO: Refactor call to old style CreateEvent method"); - return 0; -} - -void SetEvent(HANDLE hEvent) { - warning("TODO: Refactor call to old style SetEvent method"); -} - -void ResetEvent(HANDLE hEvent) { - warning("TODO: Refactor call to old style ResetEvent method"); -} - -void PulseEvent(HANDLE hEvent) { - warning("TODO: Refactor call to old style PulseEvent method"); -} - uint16 GetAsyncKeyState(Common::KeyCode kc) { return 0; } diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index 5c50b76db1..082974898c 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -71,42 +71,8 @@ Out CopyMemory(Out dst, In first, int size) { * Methods \****************************************************************************/ -extern void MessageBox(const Common::String &msg); - -extern uint32 timeGetTime(); - -#define INFINITE 0xffffffff -#define WAIT_OBJECT_0 -2 // Horrendously bad cast -#define INVALID_HANDLE_VALUE (void *)-3 - -extern HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize, - LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter, - uint32 dwCreationFlags, uint32 *lpThreadId); - -extern void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter); - -extern void ExitThread(int ThreadId); - -extern void _endthread(); - -extern void TerminateThread(HANDLE ThreadId, uint32 dwExitCode); - -extern void CloseHandle(HANDLE ThreadId); - -extern void Sleep(uint32 time); - -extern int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime); - -extern uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds); - -extern HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName); - -extern void SetEvent(HANDLE hEvent); - -extern void ResetEvent(HANDLE hEvent); - -extern void PulseEvent(HANDLE hEvent); +#define INVALID_HANDLE_VALUE (void *)-1 extern uint16 GetAsyncKeyState(Common::KeyCode kc); -- cgit v1.2.3 From 5a069cdc861538fe763de48de8628d7d754f7959 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 9 May 2012 23:15:41 +1000 Subject: TONY: Refactored out usage of nullContext in favour of proper coroutines --- engines/tony/mpal/mpal.cpp | 368 ++++++++++++++++++++++++++++++++------------- engines/tony/mpal/mpal.h | 59 ++++---- engines/tony/mpal/stubs.h | 3 - 3 files changed, 290 insertions(+), 140 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index d6230d7768..c21d84cd9b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1570,7 +1570,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { * uint32 dwParam Eventuale parametro per l'azione * * Return: Handle del thread che sta eseguendo l'azione, oppure -* INVALID_HANDLE_VALUE se l'azione non e' definita, o l'item +* INVALID_PID_VALUE se l'azione non e' definita, o l'item * e' disattivato. * * Note: Si puo' ottenere l'indice dell'item a partire dal suo numero @@ -1580,7 +1580,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { * \****************************************************************************/ -static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { +static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = lpmiItems; int i; LPMPALITEM newitem; @@ -1589,7 +1589,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); if (varGetValue(buf.c_str()) <= 0) - return INVALID_HANDLE_VALUE; + return INVALID_PID_VALUE; for (i = 0; i < item->nActions; i++) { if (item->Action[i].num != nAction) @@ -1607,7 +1607,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // Duplichiamo l'item corrente e copiamo la azione #i nella #0 newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (newitem == NULL) - return INVALID_HANDLE_VALUE; + return INVALID_PID_VALUE; // Nella nuova versione scriviamo il numero dell'azione in dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); @@ -1621,26 +1621,18 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // !!! New thread management if ((h = g_scheduler->createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL) - return INVALID_HANDLE_VALUE; + return INVALID_PID_VALUE; - if ((h = g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32))) == NULL) - return INVALID_HANDLE_VALUE; + if (g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32)) == NULL) + return INVALID_PID_VALUE; -/* - if ((h=(void*)_beginthread(ActionThread, 10240,(void *)newitem))==(void*)-1) - return INVALID_HANDLE_VALUE; - - if ((h=(void*)_beginthread(ShutUpActionThread, 10240,(void *)h))==(void*)-1) - return INVALID_HANDLE_VALUE; - -*/ nExecutingAction = item->nObj; bExecutingAction = true; - return (HANDLE)h; + return h; } - return INVALID_HANDLE_VALUE; + return INVALID_PID_VALUE; } /** @@ -1649,7 +1641,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * @param nDlgOrd The index of the dialog in the dialog list * @param nGroup Number of the group to perform * @returns The process Id of the process running the dialog - * or INVALID_HANDLE_VALUE on error + * or INVALID_PID_VALUE on error * @remarks The dialogue runs in a thread created on purpose, * so that must inform through an event and when 'necessary to you make a choice. * The data on the choices may be obtained through various queries. @@ -1669,14 +1661,14 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { // Create a thread that performs the dialogue group // Create the process - if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == 0) - return 0; + if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == INVALID_PID_VALUE) + return INVALID_PID_VALUE; // Create a thread that waits until the end of the dialog process, and will restore the global variables - if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == 0) { + if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == INVALID_PID_VALUE) { // Something went wrong, so kill the previously started dialog process g_scheduler->killMatchingProcess(h); - return 0; + return INVALID_PID_VALUE; } return h; @@ -1912,16 +1904,23 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, * \****************************************************************************/ -#define GETARG(type) va_arg(v,type) +#define GETARG(type) va_arg(v, type) -void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { - CORO_BEGIN_CONTEXT; - int x, y, z; - char *n; - Common::String buf; - CORO_END_CONTEXT(_ctx); +/** + * MPAL Query variation #1 - dword return + * This variation handles mpal query types that need to return a dword result. + * + * @param wQueryType Query type + * @param v Variable length argument list + */ +uint32 mpalQueryDWORD(uint16 wQueryType, ...) { + int x, y, z; + Common::String buf; + uint32 dwRet = 0; + char *n; - CORO_BEGIN_CODE(_ctx); + va_list v; + va_start(v, wQueryType); mpalError = OK; @@ -1929,31 +1928,30 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { /* * uint32 mpalQuery(MPQ_VERSION); */ - *dwRet = HEX_VERSION; + dwRet = HEX_VERSION; } else if (wQueryType == MPQ_GLOBAL_VAR) { /* * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); */ LockVar(); - *dwRet = (uint32)varGetValue(GETARG(char *)); + dwRet = (uint32)varGetValue(GETARG(char *)); UnlockVar(); } else if (wQueryType == MPQ_MESSAGE) { /* * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg); */ - LockMsg(); - *dwRet = (uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); - UnlockMsg(); + error("mpalQuery(MPQ_MESSAGE, uint32 nMsg) used incorrect method variant"); + } else if (wQueryType == MPQ_ITEM_PATTERN) { /* * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); */ LockVar(); - _ctx->buf = Common::String::format("Pattern.%u", GETARG(uint32)); - *dwRet = (uint32)varGetValue(_ctx->buf.c_str()); + buf = Common::String::format("Pattern.%u", GETARG(uint32)); + dwRet = (uint32)varGetValue(buf.c_str()); UnlockVar(); } else if (wQueryType == MPQ_LOCATION_SIZE) { @@ -1961,61 +1959,56 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); */ LockLocations(); - _ctx->x = locGetOrderFromNum(GETARG(uint32)); - _ctx->y = GETARG(uint32); - if (_ctx->x != -1) { - if (_ctx->y == MPQ_X) - *dwRet = lpmlLocations[_ctx->x].dwXlen; - else if (_ctx->y == MPQ_Y) - *dwRet = lpmlLocations[_ctx->x].dwYlen; + x = locGetOrderFromNum(GETARG(uint32)); + y = GETARG(uint32); + if (x != -1) { + if (y == MPQ_X) + dwRet = lpmlLocations[x].dwXlen; + else if (y == MPQ_Y) + dwRet = lpmlLocations[x].dwYlen; else mpalError = 1; } else mpalError = 1; + UnlockLocations(); } else if (wQueryType == MPQ_LOCATION_IMAGE) { /* * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); */ - LockLocations(); - _ctx->x = locGetOrderFromNum(GETARG(uint32)); - *dwRet = (uint32)resLoad(lpmlLocations[_ctx->x].dwPicRes); - UnlockLocations(); + error("mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc) used incorrect variant"); } else if (wQueryType == MPQ_RESOURCE) { /* * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); */ - *dwRet = (uint32)resLoad(GETARG(uint32)); + error("mpalQuery(MPQ_RESOURCE, uint32 dwRes) used incorrect variant"); } else if (wQueryType == MPQ_ITEM_LIST) { /* * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); */ - LockVar(); - *dwRet = (uint32)GetItemList(GETARG(uint32)); - LockVar(); + error("mpalQuery(MPQ_ITEM_LIST, uint32 nLoc) used incorrect variant"); } else if (wQueryType == MPQ_ITEM_DATA) { /* * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); */ - LockItems(); - *dwRet = (uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32))); - UnlockItems(); + error("mpalQuery(MPQ_ITEM_DATA, uint32 nItem) used incorrect variant"); } else if (wQueryType == MPQ_ITEM_IS_ACTIVE) { /* * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); */ LockVar(); - _ctx->x = GETARG(uint32); - _ctx->buf = Common::String::format("Status.%u", _ctx->x); - if (varGetValue(_ctx->buf.c_str()) <= 0) - *dwRet = (uint32)false; + x = GETARG(uint32); + buf = Common::String::format("Status.%u", x); + if (varGetValue(buf.c_str()) <= 0) + dwRet = (uint32)false; else - *dwRet = (uint32)true; + dwRet = (uint32)true; + UnlockVar(); } else if (wQueryType == MPQ_ITEM_NAME) { @@ -2023,15 +2016,15 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); */ LockVar(); - _ctx->x = GETARG(uint32); - _ctx->n = GETARG(char *); - _ctx->buf = Common::String::format("Status.%u", _ctx->x); - if (varGetValue(_ctx->buf.c_str()) <= 0) - _ctx->n[0]='\0'; + x = GETARG(uint32); + n = GETARG(char *); + buf = Common::String::format("Status.%u", x); + if (varGetValue(buf.c_str()) <= 0) + n[0]='\0'; else { LockItems(); - _ctx->y = itemGetOrderFromNum(_ctx->x); - CopyMemory(_ctx->n, (char *)(lpmiItems+_ctx->y)->lpszDescribe, MAX_DESCRIBE_SIZE); + y = itemGetOrderFromNum(x); + CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); UnlockItems(); } @@ -2039,43 +2032,31 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { } else if (wQueryType == MPQ_DIALOG_PERIOD) { /* - * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); + * char *mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); */ - LockDialogs(); - _ctx->y = GETARG(uint32); - *dwRet = (uint32)DuplicateDialogPeriod(_ctx->y); - UnlockDialogs(); + error("mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod) used incorrect variant"); } else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE); - - g_scheduler->resetEvent(hAskChoice); - - if (bExecutingDialog) - *dwRet = (uint32)nExecutingChoice; - else - *dwRet = (uint32)((int)-1); + error("mpalQuery(MPQ_DIALOG_WAITFORCHOICE) used incorrect variant"); } else if (wQueryType == MPQ_DIALOG_SELECTLIST) { /* * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); */ - LockDialogs(); - *dwRet = (uint32)GetSelectList(GETARG(uint32)); - UnlockDialogs(); - break; + error("mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice) used incorrect variant"); } else if (wQueryType == MPQ_DIALOG_SELECTION) { /* * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); */ LockDialogs(); - _ctx->x = GETARG(uint32); - _ctx->y = GETARG(uint32); - *dwRet = (uint32)DoSelection(_ctx->x,_ctx->y); + x = GETARG(uint32); + y = GETARG(uint32); + dwRet = (uint32)DoSelection(x, y); + UnlockDialogs(); } else if (wQueryType == MPQ_DO_ACTION) { @@ -2084,15 +2065,16 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { */ LockItems(); LockVar(); - _ctx->x = GETARG(uint32); - _ctx->z = GETARG(uint32); - _ctx->y = itemGetOrderFromNum(_ctx->z); - if (_ctx->y!=-1) { - *dwRet = (uint32)DoAction(_ctx->x, _ctx->y, GETARG(uint32)); + x = GETARG(uint32); + z = GETARG(uint32); + y = itemGetOrderFromNum(z); + if (y != -1) { + dwRet = DoAction(x, y, GETARG(uint32)); } else { - *dwRet = (uint32)INVALID_HANDLE_VALUE; + dwRet = INVALID_PID_VALUE; mpalError = 1; } + UnlockVar(); UnlockItems(); @@ -2103,9 +2085,9 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { if (!bExecutingDialog) { LockDialogs(); - _ctx->x = dialogGetOrderFromNum(GETARG(uint32)); - _ctx->y = GETARG(uint32); - *dwRet = DoDialog(_ctx->x, _ctx->y); + x = dialogGetOrderFromNum(GETARG(uint32)); + y = GETARG(uint32); + dwRet = DoDialog(x, y); UnlockDialogs(); } } else { @@ -2115,26 +2097,201 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) { mpalError = 1; } - CORO_END_CODE; + va_end(v); + return dwRet; } -uint32 mpalQuery(uint16 wQueryType, ...) { - uint32 dwRet; +/** + * MPAL Query variation #1 - dword return + * This variation handles mpal query types that need to return a pointer/handle result + * + * @param wQueryType Query type + * @param v Variable length argument list + */ +HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { + int x, y; + char *n; + Common::String buf; va_list v; va_start(v, wQueryType); + void *hRet = NULL; + + mpalError = OK; - mpalQueryInner(nullContext, wQueryType, &dwRet, v); + if (wQueryType == MPQ_VERSION) { + /* + * uint32 mpalQuery(MPQ_VERSION); + */ + error("mpalQuery(MPQ_VERSION) used incorrect variant"); - va_end(v); + } else if (wQueryType == MPQ_GLOBAL_VAR) { + /* + * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); + */ + error("mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName) used incorrect variant"); - return dwRet; + } else if (wQueryType == MPQ_MESSAGE) { + /* + * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg); + */ + LockMsg(); + hRet = DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); + UnlockMsg(); + + } else if (wQueryType == MPQ_ITEM_PATTERN) { + /* + * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); + */ + error("mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem) used incorrect variant"); + + } else if (wQueryType == MPQ_LOCATION_SIZE) { + /* + * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); + */ + error("mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord) used incorrect variant"); + + } else if (wQueryType == MPQ_LOCATION_IMAGE) { + /* + * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); + */ + LockLocations(); + x = locGetOrderFromNum(GETARG(uint32)); + hRet = resLoad(lpmlLocations[x].dwPicRes); + UnlockLocations(); + + } else if (wQueryType == MPQ_RESOURCE) { + /* + * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes); + */ + hRet = resLoad(GETARG(uint32)); + + } else if (wQueryType == MPQ_ITEM_LIST) { + /* + * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); + */ + LockVar(); + hRet = GetItemList(GETARG(uint32)); + LockVar(); + + } else if (wQueryType == MPQ_ITEM_DATA) { + /* + * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); + */ + LockItems(); + hRet = GetItemData(itemGetOrderFromNum(GETARG(uint32))); + UnlockItems(); + + } else if (wQueryType == MPQ_ITEM_IS_ACTIVE) { + /* + * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); + */ + error("mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem) used incorrect variant"); + + } else if (wQueryType == MPQ_ITEM_NAME) { + /* + * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char *lpszName); + */ + LockVar(); + x = GETARG(uint32); + n = GETARG(char *); + buf = Common::String::format("Status.%u", x); + if (varGetValue(buf.c_str()) <= 0) + n[0]='\0'; + else { + LockItems(); + y = itemGetOrderFromNum(x); + CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + UnlockItems(); + } + + UnlockVar(); + + } else if (wQueryType == MPQ_DIALOG_PERIOD) { + /* + * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); + */ + LockDialogs(); + y = GETARG(uint32); + hRet = DuplicateDialogPeriod(y); + UnlockDialogs(); + + } else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) { + /* + * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); + */ + error("mpalQuery(MPQ_DIALOG_WAITFORCHOICE) used incorrect variant"); + + } else if (wQueryType == MPQ_DIALOG_SELECTLIST) { + /* + * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); + */ + LockDialogs(); + hRet = GetSelectList(GETARG(uint32)); + UnlockDialogs(); + + } else if (wQueryType == MPQ_DIALOG_SELECTION) { + /* + * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); + */ + error("mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData) used incorrect variant"); + + } else if (wQueryType == MPQ_DO_ACTION) { + /* + * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam); + */ + error("mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam) used incorrect variant"); + + } else if (wQueryType == MPQ_DO_DIALOG) { + /* + * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); + */ + error("mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup) used incorrect variant"); + } else { + /* + * DEFAULT -> ERROR + */ + mpalError = 1; + } + + va_end(v); + return hRet; } -void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...) { +/** + * MPAL Query variation #1 - dword return + * This variation handles mpal query types that need to return a pointer/handle result + * + * @param wQueryType Query type + * @param dwRet DWORD return value (when coroutine method completes) + * @param v Variable length argument list + */ +void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { + CORO_BEGIN_CONTEXT; + uint32 dwRet; + CORO_END_CONTEXT(_ctx); + va_list v; - va_start(v, wQueryType); + va_start(v, dwRet); + + CORO_BEGIN_CODE(_ctx); + + if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) { + /* + * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); + */ + CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE); + + g_scheduler->resetEvent(hAskChoice); - mpalQueryInner(coroParam, wQueryType, dwRet, v); + if (bExecutingDialog) + *dwRet = (uint32)nExecutingChoice; + else + *dwRet = (uint32)((int)-1); + } else { + error("mpalQueryCORO called with unsupported query type"); + } + + CORO_END_CODE; va_end(v); } @@ -2171,7 +2328,6 @@ uint32 mpalGetError(void) { bool EXPORT mpalExecuteScript(int nScript) { int n; LPMPALSCRIPT s; - uint32 dwId; LockScripts(); n = scriptGetOrderFromNum(nScript); diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 5517a6518c..9a85f2df17 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -156,7 +156,7 @@ enum QueryCoordinates { /****************************************************************************\ * enum QueryTypes * --------------- -* Description: Query can be used with mpalQuery (). In practice corresponds +* Description: Query can be used with mpalQuery methods. In practice corresponds * all claims that can do at the library \****************************************************************************/ @@ -252,7 +252,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryVersion() \ - (uint16)mpalQuery(MPQ_VERSION) + (uint16)mpalQueryDWORD(MPQ_VERSION) @@ -273,7 +273,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryGlobalVar(lpszVarName) \ - (uint32)mpalQuery(MPQ_GLOBAL_VAR,(const char *)(lpszVarName)) + mpalQueryDWORD(MPQ_GLOBAL_VAR, (const char *)(lpszVarName)) @@ -291,7 +291,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryResource(dwResId) \ - (HGLOBAL)mpalQuery(MPQ_RESOURCE,(uint32)(dwResId)) + mpalQueryHANDLE(MPQ_RESOURCE, (uint32)(dwResId)) @@ -311,7 +311,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryMessage(nMsg) \ - (LPSTR)mpalQuery(MPQ_MESSAGE,(uint32)(nMsg)) + (LPSTR)mpalQueryHANDLE(MPQ_MESSAGE, (uint32)(nMsg)) @@ -328,7 +328,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryLocationImage(nLoc) \ - (HGLOBAL)mpalQuery(MPQ_LOCATION_IMAGE,(uint32)(nLoc)) + mpalQueryHANDLE(MPQ_LOCATION_IMAGE, (uint32)(nLoc)) @@ -346,7 +346,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryLocationSize(nLoc,dwCoord) \ - (uint32)mpalQuery(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord)) + mpalQueryDWORD(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord)) @@ -361,9 +361,9 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * Return: List of objects (accessible by Item [0], Item [1], etc.) * \****************************************************************************/ - +// TODO: Check if the results of this are endian safe #define mpalQueryItemList(nLoc) \ - (uint32 *)mpalQuery(MPQ_ITEM_LIST,(uint32)(nLoc)) + (uint32 *)mpalQueryHANDLE(MPQ_ITEM_LIST,(uint32)(nLoc)) @@ -380,7 +380,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryItemData(nItem) \ - (LPITEM)mpalQuery(MPQ_ITEM_DATA,(uint32)(nItem)) + (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA,(uint32)(nItem)) @@ -400,7 +400,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryItemPattern(nItem) \ - (uint32)mpalQuery(MPQ_ITEM_PATTERN,(uint32)(nItem)) + mpalQueryDWORD(MPQ_ITEM_PATTERN,(uint32)(nItem)) @@ -417,7 +417,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryItemIsActive(nItem) \ - (bool)mpalQuery(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem)) + (bool)mpalQueryDWORD(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem)) /****************************************************************************\ @@ -435,8 +435,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * \****************************************************************************/ -#define mpalQueryItemName(nItem,lpszName) \ - (uint32)mpalQuery(MPQ_ITEM_NAME,(uint32)(nItem),(LPSTR)(lpszName)) +#define mpalQueryItemName(nItem, lpszName) \ + mpalQueryHANDLE(MPQ_ITEM_NAME,(uint32)(nItem), (LPSTR)(lpszName)) @@ -459,7 +459,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDialogPeriod(nPeriod) \ - (LPSTR)mpalQuery(MPQ_DIALOG_PERIOD,(uint32)(nPeriod)) + (LPSTR)mpalQueryHANDLE(MPQ_DIALOG_PERIOD, (uint32)(nPeriod)) @@ -475,7 +475,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDialogWaitForChoice(dwRet) \ - CORO_INVOKE_2(mpalQueryCoro, dwRet, MPQ_DIALOG_WAITFORCHOICE) + CORO_INVOKE_2(mpalQueryCORO, MPQ_DIALOG_WAITFORCHOICE, dwRet) /****************************************************************************\ * @@ -496,7 +496,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDialogSelectList(nChoice) \ - (uint32 *)mpalQuery(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice)) + (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice)) @@ -521,10 +521,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDialogSelection(nChoice,dwData) \ - (bool)mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) + (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) -#define mpalQueryDialogSelectionU32(nChoice, dwData) \ - mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) /****************************************************************************\ * @@ -539,7 +537,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * uint32 dwParam Action parameter * * Return: Handle to the thread that is performing the action, or -* INVALID_HANDLE_VALUE if the action is not 'defined for +* INVALID_PID_VALUE if the action is not 'defined for * the item, or the item and 'off. * * Note: The parameter is used primarily to implement actions @@ -549,10 +547,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDoAction(nAction, nItem, dwParam) \ - (HANDLE)mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) + mpalQueryDWORD(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) -#define mpalQueryDoActionU32(nAction, nItem, dwParam) \ - mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) /****************************************************************************\ @@ -565,15 +561,12 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * uint32 nGroup Group number to use * * Return: Handle to the thread that is running the box, or -* INVALID_HANDLE_VALUE if the dialogue does not exist. +* INVALID_PID_VALUE if the dialogue does not exist. * \****************************************************************************/ #define mpalQueryDoDialog(nDialog,nGroup) \ - (HANDLE)mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup)) - -#define mpalQueryDoDialogU32(nDialog, nGroup) \ - mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup)) + mpalQueryHANDLE(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) /****************************************************************************\ @@ -623,9 +616,13 @@ bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName, * \****************************************************************************/ -uint32 EXPORT mpalQuery(uint16 wQueryType, ...); +typedef void *HANDLE; + +uint32 mpalQueryDWORD(uint16 wQueryType, ...); + +HANDLE mpalQueryHANDLE(uint16 wQueryType, ...); -void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...); +void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...); /****************************************************************************\ * diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index 082974898c..ae25f7127e 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -71,9 +71,6 @@ Out CopyMemory(Out dst, In first, int size) { * Methods \****************************************************************************/ -// Horrendously bad cast -#define INVALID_HANDLE_VALUE (void *)-1 - extern uint16 GetAsyncKeyState(Common::KeyCode kc); } // end of namespace MPAL -- cgit v1.2.3 From 9a7393e0c397c2f5e3a6a9be06197d847ab0d28b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 10 May 2012 22:18:33 +1000 Subject: TONY: Fix operation of MPAL ActionThread method --- engines/tony/mpal/mpal.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index c21d84cd9b..da736a138f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -996,7 +996,6 @@ void ActionThread(CORO_PARAM, const void *param) { LockVar(); varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); UnlockVar(); - break; } else { mpalError = 1; -- cgit v1.2.3 From 724deb6b84b8a5f5a3aa96adc2a512c962f7081a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 11 May 2012 08:44:50 +1000 Subject: TONY: Bugfixes for showing the credits screen. --- engines/tony/mpal/mpal.cpp | 4 ++-- engines/tony/mpal/mpal.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index da736a138f..e82df11328 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -422,7 +422,7 @@ static int locGetOrderFromNum(uint32 nLoc) { static int msgGetOrderFromNum(uint32 nMsg) { int i; - LPMPALMSG msg=lpmmMsgs; + LPMPALMSG msg = lpmmMsgs; for (i = 0; i < nMsgs; i++, msg++) if (msg->wNum == nMsg) @@ -542,7 +542,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { origmsg = (const char *)GlobalLock(lpmmMsgs[nMsgOrd].hText); j = 0; - while (origmsg[j] != '\0' || origmsg[j+1] != '\0') + while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') j++; j += 2; diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 9a85f2df17..cd46219b57 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -566,7 +566,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; \****************************************************************************/ #define mpalQueryDoDialog(nDialog,nGroup) \ - mpalQueryHANDLE(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) + mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) /****************************************************************************\ -- cgit v1.2.3 From 68c1b0b0e46b0575a4670d1ffda2fa3c8ae94ed8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 11 May 2012 23:15:59 +1000 Subject: TONY: Refactored Tony to use the Common coroutine scheduler --- engines/tony/mpal/mpal.cpp | 92 +++++++++++++++++++++++----------------------- engines/tony/mpal/mpal.h | 6 +-- 2 files changed, 49 insertions(+), 49 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index e82df11328..42c790a1c7 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -883,13 +883,13 @@ void ScriptThread(CORO_PARAM, const void *param) { for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) { // Dorme il tempo necessario per arrivare al momento successivo if (s->Moment[_ctx->i].dwTime == -1) { - CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, _ctx->numHandles, cfHandles, true, INFINITE); + CORO_INVOKE_4(CoroScheduler.waitForMultipleObjects, _ctx->numHandles, cfHandles, true, CORO_INFINITE); _ctx->dwStartTime = _vm->GetTime(); } else { _ctx->dwCurTime = _vm->GetTime(); if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { // warning("PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); - CORO_INVOKE_1(g_scheduler->sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); + CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); } } @@ -913,7 +913,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->p->arg4=s->Command[_ctx->k].arg4; // !!! Nuova gestione dei thread - if ((cfHandles[_ctx->numHandles++] = g_scheduler->createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { + if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { mpalError = 1; CORO_KILL_SELF(); @@ -976,7 +976,7 @@ void ActionThread(CORO_PARAM, const void *param) { if (item->Command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - g_scheduler->getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), + CoroScheduler.getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, item->Command[_ctx->k].arg3, item->Command[_ctx->k].arg4 ); @@ -991,7 +991,7 @@ void ActionThread(CORO_PARAM, const void *param) { } else if (item->Command[_ctx->k].type == 2) { // Variable assign debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", - g_scheduler->getCurrentPID(), item->Command[_ctx->k].lpszVarName); + CoroScheduler.getCurrentPID(), item->Command[_ctx->k].lpszVarName); LockVar(); varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); @@ -1005,7 +1005,7 @@ void ActionThread(CORO_PARAM, const void *param) { GlobalFree(item); - debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", g_scheduler->getCurrentPID()); + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); CORO_KILL_SELF(); @@ -1026,7 +1026,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - CORO_INVOKE_2(g_scheduler->waitForSingleObject, pid, INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); bExecutingAction = false; @@ -1200,7 +1200,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ci addormentiamo, ma controllando sempre l'evento che viene settato quando viene richiesta la nostra chiusura */ - CORO_INVOKE_3(g_scheduler->waitForSingleObject, hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); //if (_ctx->k == WAIT_OBJECT_0) if (!_ctx->expired) @@ -1208,7 +1208,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(g_scheduler->waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); // if result ) == WAIT_OBJECT_0) if (!_ctx->delayExpired) @@ -1279,7 +1279,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; // !!! Nuova gestione dei thread - if ((_ctx->MyThreads[_ctx->i].hThread = g_scheduler->createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { + if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { //if ((_ctx->MyThreads[_ctx->i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))==(void*)-1) GlobalFree(_ctx->newItem); GlobalFree(_ctx->MyThreads); @@ -1309,18 +1309,18 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Set idle skip on // FIXME: Convert to co-routine - lplpFunctions[200](nullContext, 0, 0, 0, 0); + CORO_INVOKE_4(lplpFunctions[200], 0, 0, 0, 0); for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(g_scheduler->waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); /* //if (result != WAIT_OBJECT_0) if (_ctx->delayExpired) TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); */ - g_scheduler->killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); + CoroScheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); } // Set idle skip off @@ -1361,13 +1361,13 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - CORO_INVOKE_2(g_scheduler->waitForSingleObject, pid, INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); bExecutingDialog = false; nExecutingDialog = 0; nExecutingChoice = 0; - g_scheduler->setEvent(hAskChoice); + CoroScheduler.setEvent(hAskChoice); CORO_KILL_SELF(); @@ -1519,9 +1519,9 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, e restiamo in attesa della risposta */ - g_scheduler->resetEvent(hDoneChoice); - g_scheduler->setEvent(hAskChoice); - CORO_INVOKE_2(g_scheduler->waitForSingleObject, hDoneChoice, INFINITE); + CoroScheduler.resetEvent(hDoneChoice); + CoroScheduler.setEvent(hAskChoice); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, hDoneChoice, CORO_INFINITE); /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi associati con la scelta */ @@ -1569,7 +1569,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { * uint32 dwParam Eventuale parametro per l'azione * * Return: Handle del thread che sta eseguendo l'azione, oppure -* INVALID_PID_VALUE se l'azione non e' definita, o l'item +* CORO_INVALID_PID_VALUE se l'azione non e' definita, o l'item * e' disattivato. * * Note: Si puo' ottenere l'indice dell'item a partire dal suo numero @@ -1588,7 +1588,7 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); if (varGetValue(buf.c_str()) <= 0) - return INVALID_PID_VALUE; + return CORO_INVALID_PID_VALUE; for (i = 0; i < item->nActions; i++) { if (item->Action[i].num != nAction) @@ -1606,7 +1606,7 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // Duplichiamo l'item corrente e copiamo la azione #i nella #0 newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (newitem == NULL) - return INVALID_PID_VALUE; + return CORO_INVALID_PID_VALUE; // Nella nuova versione scriviamo il numero dell'azione in dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); @@ -1619,11 +1619,11 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // 0 dell'item, e poi liberera' la memoria con la GlobalFree() // !!! New thread management - if ((h = g_scheduler->createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL) - return INVALID_PID_VALUE; + if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL) + return CORO_INVALID_PID_VALUE; - if (g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32)) == NULL) - return INVALID_PID_VALUE; + if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == NULL) + return CORO_INVALID_PID_VALUE; nExecutingAction = item->nObj; bExecutingAction = true; @@ -1631,7 +1631,7 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { return h; } - return INVALID_PID_VALUE; + return CORO_INVALID_PID_VALUE; } /** @@ -1640,7 +1640,7 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * @param nDlgOrd The index of the dialog in the dialog list * @param nGroup Number of the group to perform * @returns The process Id of the process running the dialog - * or INVALID_PID_VALUE on error + * or CORO_INVALID_PID_VALUE on error * @remarks The dialogue runs in a thread created on purpose, * so that must inform through an event and when 'necessary to you make a choice. * The data on the choices may be obtained through various queries. @@ -1654,20 +1654,20 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { // Enables the flag to indicate that there is' a running dialogue bExecutingDialog = true; - g_scheduler->resetEvent(hAskChoice); - g_scheduler->resetEvent(hDoneChoice); + CoroScheduler.resetEvent(hAskChoice); + CoroScheduler.resetEvent(hDoneChoice); // Create a thread that performs the dialogue group // Create the process - if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == INVALID_PID_VALUE) - return INVALID_PID_VALUE; + if ((h = CoroScheduler.createProcess(GroupThread, &nGroup, sizeof(uint32))) == CORO_INVALID_PID_VALUE) + return CORO_INVALID_PID_VALUE; // Create a thread that waits until the end of the dialog process, and will restore the global variables - if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == INVALID_PID_VALUE) { + if (CoroScheduler.createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == CORO_INVALID_PID_VALUE) { // Something went wrong, so kill the previously started dialog process - g_scheduler->killMatchingProcess(h); - return INVALID_PID_VALUE; + CoroScheduler.killMatchingProcess(h); + return CORO_INVALID_PID_VALUE; } return h; @@ -1700,7 +1700,7 @@ bool DoSelection(uint32 i, uint32 dwData) { return false; nSelectedChoice = j; - g_scheduler->setEvent(hDoneChoice); + CoroScheduler.setEvent(hDoneChoice); return true; } @@ -1877,8 +1877,8 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' da effettuare una scelta */ - hAskChoice = g_scheduler->createEvent(true, false); - hDoneChoice = g_scheduler->createEvent(true, false); + hAskChoice = CoroScheduler.createEvent(true, false); + hDoneChoice = CoroScheduler.createEvent(true, false); return true; } @@ -2070,7 +2070,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { if (y != -1) { dwRet = DoAction(x, y, GETARG(uint32)); } else { - dwRet = INVALID_PID_VALUE; + dwRet = CORO_INVALID_PID_VALUE; mpalError = 1; } @@ -2278,9 +2278,9 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, hAskChoice, CORO_INFINITE); - g_scheduler->resetEvent(hAskChoice); + CoroScheduler.resetEvent(hAskChoice); if (bExecutingDialog) *dwRet = (uint32)nExecutingChoice; @@ -2338,7 +2338,7 @@ bool EXPORT mpalExecuteScript(int nScript) { UnlockScripts(); // !!! Nuova gestione dei thread - if (g_scheduler->createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == INVALID_PID_VALUE) + if (CoroScheduler.createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == CORO_INVALID_PID_VALUE) return false; return true; @@ -2388,9 +2388,9 @@ bool mpalStartIdlePoll(int nLoc) { if (nPollingLocations[i] == 0) { nPollingLocations[i] = nLoc; - hEndPollingLocations[i] = g_scheduler->createEvent(true, false); + hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); // !!! Nuova gestione dei thread - if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) + if ((PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) // if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) return false; @@ -2425,11 +2425,11 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { if (nPollingLocations[_ctx->i] == (uint32)nLoc) { - g_scheduler->setEvent(hEndPollingLocations[_ctx->i]); + CoroScheduler.setEvent(hEndPollingLocations[_ctx->i]); - CORO_INVOKE_2(g_scheduler->waitForSingleObject, PollingThreads[_ctx->i], INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, PollingThreads[_ctx->i], CORO_INFINITE); - g_scheduler->closeEvent(hEndPollingLocations[_ctx->i]); + CoroScheduler.closeEvent(hEndPollingLocations[_ctx->i]); nPollingLocations[_ctx->i] = 0; if (result) diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index cd46219b57..49601bc1e9 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -118,9 +118,9 @@ #define TONY_MPAL_H #include "common/scummsys.h" +#include "common/coroutines.h" #include "common/rect.h" #include "common/str.h" -#include "tony/coroutine.h" namespace Tony { @@ -537,7 +537,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * uint32 dwParam Action parameter * * Return: Handle to the thread that is performing the action, or -* INVALID_PID_VALUE if the action is not 'defined for +* CORO_INVALID_PID_VALUE if the action is not 'defined for * the item, or the item and 'off. * * Note: The parameter is used primarily to implement actions @@ -561,7 +561,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * uint32 nGroup Group number to use * * Return: Handle to the thread that is running the box, or -* INVALID_PID_VALUE if the dialogue does not exist. +* CORO_INVALID_PID_VALUE if the dialogue does not exist. * \****************************************************************************/ -- cgit v1.2.3 From beef5fdb264850079208b5513cf72626ff7edd86 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 11 May 2012 23:23:05 +1000 Subject: TONY: Removal of now redundant includes, and deprecated scheduler/coroutine files --- engines/tony/mpal/mpal.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 42c790a1c7..a665fbacc5 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -51,7 +51,6 @@ #include "common/file.h" #include "common/savefile.h" #include "common/system.h" -#include "tony/sched.h" #include "tony/tony.h" #include "tony/mpal/lzo.h" #include "tony/mpal/mpal.h" -- cgit v1.2.3 From 435971f256f33f9944bc37f7c23c90eb70c77948 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 12 May 2012 10:55:18 +1000 Subject: TONY: Fixed the CopyMemory stub to copy the correct number of bytes. Tony can now leave his office without the game crashing. --- engines/tony/mpal/stubs.cpp | 4 ++++ engines/tony/mpal/stubs.h | 16 ++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp index 23bc18b0ea..89740fdd52 100644 --- a/engines/tony/mpal/stubs.cpp +++ b/engines/tony/mpal/stubs.cpp @@ -40,6 +40,10 @@ uint16 GetAsyncKeyState(Common::KeyCode kc) { return 0; } +void CopyMemory(void *dst, const void *first, int size) { + Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst); +} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index ae25f7127e..ea88c1c76c 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -53,24 +53,12 @@ typedef void (*LPTHREAD_ROUTINE)(void *lpThreadParameter); #define PASCAL -/****************************************************************************\ -* Templates -\****************************************************************************/ - -/** - * Copies data from the range [first, last) to [dst, dst + (last - first)). - * It requires the range [dst, dst + (last - first)) to be valid. - * It also requires dst not to be in the range [first, last). - */ -template -Out CopyMemory(Out dst, In first, int size) { - return Common::copy(first, first + size, dst); -} - /****************************************************************************\ * Methods \****************************************************************************/ +extern void CopyMemory(void *dst, const void *first, int size); + extern uint16 GetAsyncKeyState(Common::KeyCode kc); } // end of namespace MPAL -- cgit v1.2.3 From 65ec900cebbfdbf453cdcdb8ec24f86bd797fdcd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 12 May 2012 11:01:20 +1000 Subject: TONY: Removed old extern, PASCAL, and EXPORT function modifiers --- engines/tony/mpal/mpal.cpp | 12 ++++++------ engines/tony/mpal/mpal.h | 25 +++++++++---------------- engines/tony/mpal/stubs.h | 2 -- 3 files changed, 15 insertions(+), 24 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index a665fbacc5..d28fd8e8e2 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -816,7 +816,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { /****************************************************************************\ * -* Function: void PASCAL CustomThread(LPCFCALL p); +* Function: void CustomThread(LPCFCALL p); * * Description: Thread che richiama una funzione custom. Viene usato negli * script, in modo che ciascuna funzione venga eseguita senza @@ -848,7 +848,7 @@ void CustomThread(CORO_PARAM, const void *param) { /****************************************************************************\ * -* Function: void PASCAL ScriptThread(LPMPALSCRIPT s); +* Function: void ScriptThread(LPMPALSCRIPT s); * * Description: Esegue uno script. Questa funzione e' pensata come starting * point per un thread @@ -946,7 +946,7 @@ void ScriptThread(CORO_PARAM, const void *param) { /****************************************************************************\ * -* Function: void PASCAL ActionThread(LPMPALITEM item); +* Function: void ActionThread(LPMPALITEM item); * * Description: Thread che esegue una azione su un item. Il thread * esegue sempre l'azione 0, per cui e' necessario creare @@ -1036,7 +1036,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { /****************************************************************************\ * -* Function: void PASCAL LocationPollThread(uint32 id); +* Function: void LocationPollThread(uint32 id); * * Description: Esegue il polling di una locazione (starting point di un * thread). @@ -2323,7 +2323,7 @@ uint32 mpalGetError(void) { * \****************************************************************************/ -bool EXPORT mpalExecuteScript(int nScript) { +bool mpalExecuteScript(int nScript) { int n; LPMPALSCRIPT s; @@ -2355,7 +2355,7 @@ bool EXPORT mpalExecuteScript(int nScript) { * \****************************************************************************/ -void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { +void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { lpiifCustom = lpiifCus; } diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 49601bc1e9..1d298b4f26 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -138,7 +138,6 @@ namespace MPAL { #define MAXPOLLINGLOCATIONS 64 -#define EXPORT #define LPSTR char * /****************************************************************************\ @@ -570,12 +569,9 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; /****************************************************************************\ -* Functions exported DLL +* Functions exported to the main game \****************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif /****************************************************************************\ * @@ -593,7 +589,7 @@ extern "C" { * \****************************************************************************/ -bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName, +bool mpalInit(const char *lpszFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings); @@ -636,7 +632,7 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...); * \****************************************************************************/ -bool EXPORT mpalExecuteScript(int nScript); +bool mpalExecuteScript(int nScript); @@ -650,7 +646,7 @@ bool EXPORT mpalExecuteScript(int nScript); * \****************************************************************************/ -uint32 EXPORT mpalGetError(void); +uint32 mpalGetError(void); @@ -665,7 +661,7 @@ uint32 EXPORT mpalGetError(void); * \****************************************************************************/ -void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); +void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); /****************************************************************************\ @@ -684,7 +680,7 @@ void EXPORT mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); * \****************************************************************************/ -bool EXPORT mpalStartIdlePoll(int nLoc); +bool mpalStartIdlePoll(int nLoc); /****************************************************************************\ @@ -715,7 +711,7 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result); * \****************************************************************************/ -int EXPORT mpalLoadState(byte *buf); +int mpalLoadState(byte *buf); @@ -730,7 +726,7 @@ int EXPORT mpalLoadState(byte *buf); * \****************************************************************************/ -void EXPORT mpalSaveState(byte *buf); +void mpalSaveState(byte *buf); @@ -744,11 +740,8 @@ void EXPORT mpalSaveState(byte *buf); * \****************************************************************************/ -int EXPORT mpalGetSaveStateSize(void); +int mpalGetSaveStateSize(void); -#ifdef __cplusplus -} -#endif /****************************************************************************\ * diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h index ea88c1c76c..66f83997ae 100644 --- a/engines/tony/mpal/stubs.h +++ b/engines/tony/mpal/stubs.h @@ -51,8 +51,6 @@ typedef void (*LPTHREAD_ROUTINE)(void *lpThreadParameter); #define MB_OK 1 -#define PASCAL - /****************************************************************************\ * Methods \****************************************************************************/ -- cgit v1.2.3 From 63e3b47857fe5a507858b4256b1f3f4d7fe50c22 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 13 May 2012 00:53:09 +1000 Subject: TONY: Fix compiler warnings --- engines/tony/mpal/mpal.cpp | 4 ++-- engines/tony/mpal/mpal.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index d28fd8e8e2..bfde7fe2a6 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1618,10 +1618,10 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // 0 dell'item, e poi liberera' la memoria con la GlobalFree() // !!! New thread management - if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL) + if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; - if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == NULL) + if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; nExecutingAction = item->nObj; diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 1d298b4f26..319f71c6a8 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -522,6 +522,9 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDialogSelection(nChoice,dwData) \ (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) +#define mpalQueryDialogSelectionDWORD(nChoice,dwData) \ + mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) + /****************************************************************************\ * -- cgit v1.2.3 From 94f5a989873151d435f144de59bf06146a48a4b6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 13 May 2012 23:44:08 +1000 Subject: TONY: Moved remaining globals to Globals class --- engines/tony/mpal/expr.cpp | 2 +- engines/tony/mpal/loadmpc.cpp | 124 ++++++------ engines/tony/mpal/mpal.cpp | 438 +++++++++++++++++------------------------- engines/tony/mpal/mpaldll.h | 44 +---- 4 files changed, 247 insertions(+), 361 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 0ca02d2931..19170ce60c 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -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; } diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 9d6ef19e55..937374517f 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -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]); @@ -580,12 +580,12 @@ 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 */ @@ -593,96 +593,96 @@ bool ParseMpc(const byte *lpBuf) { 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') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index bfde7fe2a6..66d467f301 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -72,84 +72,6 @@ const char *mpalCopyright = "\n" "\n"; -/****************************************************************************\ -* Structures -\****************************************************************************/ - -/****************************************************************************\ -* 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 -\****************************************************************************/ - -uint32 mpalError; - -static byte * lpMpcImage; - -LPITEMIRQFUNCTION lpiifCustom=NULL; - -LPLPCUSTOMFUNCTION lplpFunctions = NULL; -Common::String * lplpFunctionStrings = NULL; -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; - - /****************************************************************************\ * Internal functions \****************************************************************************/ @@ -163,7 +85,7 @@ uint32 nSelectedChoice; \****************************************************************************/ void LockVar(void) { - lpmvVars=(LPMPALVAR)GlobalLock(hVars); + GLOBALS.lpmvVars = (LPMPALVAR)GlobalLock(GLOBALS.hVars); } /****************************************************************************\ @@ -175,7 +97,7 @@ void LockVar(void) { \****************************************************************************/ void UnlockVar(void) { - GlobalUnlock(hVars); + GlobalUnlock(GLOBALS.hVars); } @@ -189,7 +111,7 @@ void UnlockVar(void) { static void LockMsg(void) { #ifdef NEED_LOCK_MSGS - lpmmMsgs=(LPMPALMSG)GlobalLock(hMsgs); + GLOBALS.lpmmMsgs = (LPMPALMSG)GlobalLock(GLOBALS.hMsgs); #endif } @@ -204,7 +126,7 @@ static void LockMsg(void) { static void UnlockMsg(void) { #ifdef NEED_LOCK_MSGS - GlobalUnlock(hMsgs); + GlobalUnlock(GLOBALS.hMsgs); #endif } @@ -218,7 +140,7 @@ static void UnlockMsg(void) { \****************************************************************************/ static void LockDialogs(void) { - lpmdDialogs=(LPMPALDIALOG)GlobalLock(hDialogs); + GLOBALS.lpmdDialogs = (LPMPALDIALOG)GlobalLock(GLOBALS.hDialogs); } @@ -231,7 +153,7 @@ static void LockDialogs(void) { \****************************************************************************/ static void UnlockDialogs(void) { - GlobalUnlock(hDialogs); + GlobalUnlock(GLOBALS.hDialogs); } @@ -244,7 +166,7 @@ static void UnlockDialogs(void) { \****************************************************************************/ static void LockLocations(void) { - lpmlLocations=(LPMPALLOCATION)GlobalLock(hLocations); + GLOBALS.lpmlLocations = (LPMPALLOCATION)GlobalLock(GLOBALS.hLocations); } @@ -257,7 +179,7 @@ static void LockLocations(void) { \****************************************************************************/ static void UnlockLocations(void) { - GlobalUnlock(hLocations); + GlobalUnlock(GLOBALS.hLocations); } @@ -270,7 +192,7 @@ static void UnlockLocations(void) { \****************************************************************************/ static void LockItems(void) { - lpmiItems=(LPMPALITEM)GlobalLock(hItems); + GLOBALS.lpmiItems = (LPMPALITEM)GlobalLock(GLOBALS.hItems); } @@ -283,7 +205,7 @@ static void LockItems(void) { \****************************************************************************/ static void UnlockItems(void) { - GlobalUnlock(hItems); + GlobalUnlock(GLOBALS.hItems); } /****************************************************************************\ @@ -295,7 +217,7 @@ static void UnlockItems(void) { \****************************************************************************/ static void LockScripts(void) { - lpmsScripts=(LPMPALSCRIPT)GlobalLock(hScripts); + GLOBALS.lpmsScripts = (LPMPALSCRIPT)GlobalLock(GLOBALS.hScripts); } @@ -308,7 +230,7 @@ static void LockScripts(void) { \****************************************************************************/ static void UnlockScripts(void) { - GlobalUnlock(hScripts); + GlobalUnlock(GLOBALS.hScripts); } @@ -330,13 +252,13 @@ static void UnlockScripts(void) { int32 varGetValue(const char *lpszVarName) { int i; - LPMPALVAR v=lpmvVars; + LPMPALVAR v=GLOBALS.lpmvVars; - for (i = 0; i < nVars; v++, i++) + for (i = 0; i < GLOBALS.nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) return v->dwVal; - mpalError = 1; + GLOBALS.mpalError = 1; return 0; } @@ -354,24 +276,24 @@ int32 varGetValue(const char *lpszVarName) { void varSetValue(const char *lpszVarName, int32 val) { uint i; - LPMPALVAR v = lpmvVars; + LPMPALVAR v = GLOBALS.lpmvVars; - for (i = 0; i < nVars; v++, i++) + for (i = 0; i < GLOBALS.nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) { v->dwVal = val; - if (lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { + if (GLOBALS.lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { i = 0; sscanf(v->lpszVarName, "Pattern.%u", &i); - lpiifCustom(i, val, -1); - } else if (lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { + GLOBALS.lpiifCustom(i, val, -1); + } else if (GLOBALS.lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { i = 0; sscanf(v->lpszVarName,"Status.%u", &i); - lpiifCustom(i, -1, val); + GLOBALS.lpiifCustom(i, -1, val); } return; } - mpalError = 1; + GLOBALS.mpalError = 1; return; } @@ -394,9 +316,9 @@ void varSetValue(const char *lpszVarName, int32 val) { static int locGetOrderFromNum(uint32 nLoc) { int i; - LPMPALLOCATION loc = lpmlLocations; + LPMPALLOCATION loc = GLOBALS.lpmlLocations; - for (i = 0; i < nLocations; i++,loc++) + for (i = 0; i < GLOBALS.nLocations; i++, loc++) if (loc->nObj == nLoc) return i; @@ -421,9 +343,9 @@ static int locGetOrderFromNum(uint32 nLoc) { static int msgGetOrderFromNum(uint32 nMsg) { int i; - LPMPALMSG msg = lpmmMsgs; + LPMPALMSG msg = GLOBALS.lpmmMsgs; - for (i = 0; i < nMsgs; i++, msg++) + for (i = 0; i < GLOBALS.nMsgs; i++, msg++) if (msg->wNum == nMsg) return i; @@ -449,9 +371,9 @@ static int msgGetOrderFromNum(uint32 nMsg) { static int itemGetOrderFromNum(uint32 nItem) { int i; - LPMPALITEM item=lpmiItems; + LPMPALITEM item = GLOBALS.lpmiItems; - for (i = 0; i < nItems; i++, item++) + for (i = 0; i < GLOBALS.nItems; i++, item++) if (item->nObj == nItem) return i; @@ -477,9 +399,9 @@ static int itemGetOrderFromNum(uint32 nItem) { static int scriptGetOrderFromNum(uint32 nScript) { int i; - LPMPALSCRIPT script = lpmsScripts; + LPMPALSCRIPT script = GLOBALS.lpmsScripts; - for (i = 0; i < nScripts; i++,script++) + for (i = 0; i < GLOBALS.nScripts; i++, script++) if (script->nObj == nScript) return i; @@ -505,9 +427,9 @@ static int scriptGetOrderFromNum(uint32 nScript) { static int dialogGetOrderFromNum(uint32 nDialog) { int i; - LPMPALDIALOG dialog=lpmdDialogs; + LPMPALDIALOG dialog = GLOBALS.lpmdDialogs; - for (i = 0; i < nDialogs; i++, dialog++) + for (i = 0; i < GLOBALS.nDialogs; i++, dialog++) if (dialog->nObj == nDialog) return i; @@ -538,7 +460,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { if (nMsgOrd == (uint32)-1) return NULL; - origmsg = (const char *)GlobalLock(lpmmMsgs[nMsgOrd].hText); + origmsg = (const char *)GlobalLock(GLOBALS.lpmmMsgs[nMsgOrd].hText); j = 0; while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') @@ -550,7 +472,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { return NULL; CopyMemory(clonemsg, origmsg, j); - GlobalUnlock(lpmmMsgs[nMsgOrd].hText); + GlobalUnlock(GLOBALS.lpmmMsgs[nMsgOrd].hText); return clonemsg; } @@ -575,7 +497,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { static char *DuplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; - LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; + LPMPALDIALOG dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; int i,j; for (j = 0; dialog->Periods[j] != NULL; j++) @@ -623,28 +545,28 @@ HGLOBAL resLoad(uint32 dwId) { uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; - for (i = 0; i < nResources; i++) - if (lpResources[i * 2] == dwId) { - hMpr.seek(lpResources[i * 2 + 1]); - nBytesRead = hMpr.read(head, 4); + for (i = 0; i < GLOBALS.nResources; i++) + if (GLOBALS.lpResources[i * 2] == dwId) { + GLOBALS.hMpr.seek(GLOBALS.lpResources[i * 2 + 1]); + nBytesRead = GLOBALS.hMpr.read(head, 4); if (nBytesRead != 4) return NULL; if (head[0] != 'R' || head[1] != 'E' || head[2] != 'S' || head[3] != 'D') return NULL; - nSizeDecomp = hMpr.readUint32LE(); - if (hMpr.err()) + nSizeDecomp = GLOBALS.hMpr.readUint32LE(); + if (GLOBALS.hMpr.err()) return NULL; - nSizeComp = hMpr.readUint32LE(); - if (hMpr.err()) + nSizeComp = GLOBALS.hMpr.readUint32LE(); + if (GLOBALS.hMpr.err()) return NULL; h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); buf = (byte *)GlobalLock(h); temp = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); - nBytesRead = hMpr.read(temp, nSizeComp); + nBytesRead = GLOBALS.hMpr.read(temp, nSizeComp); if (nBytesRead != nSizeComp) return NULL; @@ -663,7 +585,7 @@ HGLOBAL resLoad(uint32 dwId) { static uint32 *GetSelectList(uint32 i) { uint32 *sl; int j,k,num; - LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; + LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; /* Conta quanti select attivi ci sono */ num = 0; @@ -692,10 +614,10 @@ static uint32 *GetSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; uint32 num,i,j; - LPMPALVAR v = lpmvVars; + LPMPALVAR v = GLOBALS.lpmvVars; num = 0; - for (i = 0; i < nVars; i++,v++) { + for (i = 0; i < GLOBALS.nVars; i++,v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } @@ -704,9 +626,9 @@ static uint32 *GetItemList(uint32 nLoc) { if (il == NULL) return NULL; - v = lpmvVars; + v = GLOBALS.lpmvVars; j = 0; - for (i = 0; i < nVars; i++,v++) { + for (i = 0; i < GLOBALS.nVars; i++,v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) { sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; @@ -718,7 +640,7 @@ static uint32 *GetItemList(uint32 nLoc) { } static LPITEM GetItemData(uint32 nOrdItem) { - LPMPALITEM curitem = lpmiItems+nOrdItem; + LPMPALITEM curitem = GLOBALS.lpmiItems+nOrdItem; LPITEM ret; HGLOBAL hDat; char *dat; @@ -838,7 +760,7 @@ void CustomThread(CORO_PARAM, const void *param) { _ctx->p = *(LPCFCALL *)param; - CORO_INVOKE_4(lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4); + CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4); GlobalFree(_ctx->p); @@ -899,7 +821,7 @@ void ScriptThread(CORO_PARAM, const void *param) { if (s->Command[_ctx->k].type == 1) { _ctx->p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) { - mpalError = 1; + GLOBALS.mpalError = 1; CORO_KILL_SELF(); return; @@ -913,7 +835,7 @@ void ScriptThread(CORO_PARAM, const void *param) { // !!! Nuova gestione dei thread if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { - mpalError = 1; + GLOBALS.mpalError = 1; CORO_KILL_SELF(); return; @@ -927,7 +849,7 @@ void ScriptThread(CORO_PARAM, const void *param) { UnlockVar(); } else { - mpalError = 1; + GLOBALS.mpalError = 1; GlobalFree(s); CORO_KILL_SELF(); @@ -968,19 +890,19 @@ void ActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - mpalError = 0; + GLOBALS.mpalError = 0; for (_ctx->j = 0; _ctx->j < item->Action[item->dwRes].nCmds; _ctx->j++) { _ctx->k = item->Action[item->dwRes].CmdNum[_ctx->j]; if (item->Command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - CoroScheduler.getCurrentPID(), lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), + CoroScheduler.getCurrentPID(), GLOBALS.lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, item->Command[_ctx->k].arg3, item->Command[_ctx->k].arg4 ); - CORO_INVOKE_4(lplpFunctions[item->Command[_ctx->k].nCf], + CORO_INVOKE_4(GLOBALS.lplpFunctions[item->Command[_ctx->k].nCf], item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, item->Command[_ctx->k].arg3, @@ -997,7 +919,7 @@ void ActionThread(CORO_PARAM, const void *param) { UnlockVar(); } else { - mpalError = 1; + GLOBALS.mpalError = 1; break; } } @@ -1027,7 +949,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); - bExecutingAction = false; + GLOBALS.bExecutingAction = false; CORO_KILL_SELF(); @@ -1088,7 +1010,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Tanto per cominciare, e' necessario richiedere la lista degli item presenti nella locazione. */ - _ctx->il = mpalQueryItemList(nPollingLocations[id]); + _ctx->il = mpalQueryItemList(GLOBALS.nPollingLocations[id]); /* Contiamo gli items */ for (_ctx->numitems = 0; _ctx->il[_ctx->numitems] != 0; _ctx->numitems++) @@ -1104,7 +1026,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->ord == -1) continue; - _ctx->curItem = lpmiItems + _ctx->ord; + _ctx->curItem = GLOBALS.lpmiItems + _ctx->ord; _ctx->k = 0; for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) @@ -1157,7 +1079,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->il[_ctx->i] == 0) continue; - _ctx->curItem = lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); + _ctx->curItem = GLOBALS.lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) if (_ctx->curItem->Action[_ctx->j].num == 0xFF) { @@ -1199,7 +1121,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ci addormentiamo, ma controllando sempre l'evento che viene settato quando viene richiesta la nostra chiusura */ - CORO_INVOKE_3(CoroScheduler.waitForSingleObject, hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS.hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); //if (_ctx->k == WAIT_OBJECT_0) if (!_ctx->expired) @@ -1226,7 +1148,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); if (randomVal < _ctx->MyActions[_ctx->k].perc) { /* Controlliamo se c'e' una action in esecuzione sull'item */ - if ((bExecutingAction) && (nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) + if ((GLOBALS.bExecutingAction) && (GLOBALS.nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) continue; /* Controlliamo se c'e' gia' un'altra idle function in esecuzione @@ -1240,7 +1162,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ok, siamo gli unici :) */ LockItems(); - _ctx->curItem=lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); + _ctx->curItem=GLOBALS.lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); /* Controlliamo se c'e' un esperessione WhenExecute */ _ctx->j=_ctx->MyActions[_ctx->k].nAction; @@ -1308,7 +1230,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Set idle skip on // FIXME: Convert to co-routine - CORO_INVOKE_4(lplpFunctions[200], 0, 0, 0, 0); + CORO_INVOKE_4(GLOBALS.lplpFunctions[200], 0, 0, 0, 0); for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { @@ -1323,7 +1245,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } // Set idle skip off - CORO_INVOKE_4(lplpFunctions[201], 0, 0, 0, 0); + CORO_INVOKE_4(GLOBALS.lplpFunctions[201], 0, 0, 0, 0); /* Abbiamo finito */ GlobalFree(_ctx->MyThreads); @@ -1362,11 +1284,11 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); - bExecutingDialog = false; - nExecutingDialog = 0; - nExecutingChoice = 0; + GLOBALS.bExecutingDialog = false; + GLOBALS.nExecutingDialog = 0; + GLOBALS.nExecutingChoice = 0; - CoroScheduler.setEvent(hAskChoice); + CoroScheduler.setEvent(GLOBALS.hAskChoice); CORO_KILL_SELF(); @@ -1394,7 +1316,7 @@ void GroupThread(CORO_PARAM, const void *param) { LockDialogs(); // Find the pointer to the current _ctx->dialog - _ctx->dialog = lpmdDialogs + nExecutingDialog; + _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; // Search inside the group requesting the _ctx->dialog for (_ctx->i = 0; _ctx->dialog->Group[_ctx->i].num != 0; _ctx->i++) { @@ -1406,7 +1328,7 @@ void GroupThread(CORO_PARAM, const void *param) { _ctx->type = _ctx->dialog->Command[_ctx->k].type; if (_ctx->type == 1) { // Call custom function - CORO_INVOKE_4(lplpFunctions[_ctx->dialog->Command[_ctx->k].nCf], + CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->dialog->Command[_ctx->k].nCf], _ctx->dialog->Command[_ctx->k].arg1, _ctx->dialog->Command[_ctx->k].arg2, _ctx->dialog->Command[_ctx->k].arg3, @@ -1424,7 +1346,7 @@ void GroupThread(CORO_PARAM, const void *param) { CORO_INVOKE_1(DoChoice, (uint32)_ctx->dialog->Command[_ctx->k].nChoice); } else { - mpalError = 1; + GLOBALS.mpalError = 1; UnlockDialogs(); CORO_KILL_SELF(); @@ -1441,7 +1363,7 @@ void GroupThread(CORO_PARAM, const void *param) { } /* Se siamo qui, vuol dire che non abbiamo trovato il gruppo richiesto */ - mpalError = 1; + GLOBALS.mpalError = 1; UnlockDialogs(); CORO_KILL_SELF(); @@ -1473,7 +1395,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { LockDialogs(); /* Trova il puntatore al dialogo corrente */ - _ctx->dialog=lpmdDialogs+nExecutingDialog; + _ctx->dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; /* Cerca la scelta richiesta tra quelle nel dialogo */ for (_ctx->i = 0; _ctx->dialog->Choice[_ctx->i].nChoice != 0; _ctx->i++) @@ -1483,7 +1405,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Se non l'ha trovata, esce con errore */ if (_ctx->dialog->Choice[_ctx->i].nChoice == 0) { /* Se siamo qui, non abbiamo trovato la choice richiesta */ - mpalError = 1; + GLOBALS.mpalError = 1; UnlockDialogs(); CORO_KILL_SELF(); @@ -1492,10 +1414,10 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Abbiamo trova la choice richiesta. Ricordiamoci qual e' nella variabile globale */ - nExecutingChoice = _ctx->i; + GLOBALS.nExecutingChoice = _ctx->i; while (1) { - nExecutingChoice = _ctx->i; + GLOBALS.nExecutingChoice = _ctx->i; _ctx->k = 0; /* Calcoliamo le when expression di ciascun select, per vedere se sono @@ -1518,13 +1440,13 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, e restiamo in attesa della risposta */ - CoroScheduler.resetEvent(hDoneChoice); - CoroScheduler.setEvent(hAskChoice); - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, hDoneChoice, CORO_INFINITE); + CoroScheduler.resetEvent(GLOBALS.hDoneChoice); + CoroScheduler.setEvent(GLOBALS.hAskChoice); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.hDoneChoice, CORO_INFINITE); /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi associati con la scelta */ - _ctx->j = nSelectedChoice; + _ctx->j = GLOBALS.nSelectedChoice; for (_ctx->k = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { _ctx->nGroup = _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); @@ -1579,7 +1501,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { \****************************************************************************/ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { - LPMPALITEM item = lpmiItems; + LPMPALITEM item = GLOBALS.lpmiItems; int i; LPMPALITEM newitem; uint32 h; @@ -1624,8 +1546,8 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; - nExecutingAction = item->nObj; - bExecutingAction = true; + GLOBALS.nExecutingAction = item->nObj; + GLOBALS.bExecutingAction = true; return h; } @@ -1648,13 +1570,13 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { uint32 h; // Store the running dialog in a global variable - nExecutingDialog = nDlgOrd; + GLOBALS.nExecutingDialog = nDlgOrd; // Enables the flag to indicate that there is' a running dialogue - bExecutingDialog = true; + GLOBALS.bExecutingDialog = true; - CoroScheduler.resetEvent(hAskChoice); - CoroScheduler.resetEvent(hDoneChoice); + CoroScheduler.resetEvent(GLOBALS.hAskChoice); + CoroScheduler.resetEvent(GLOBALS.hDoneChoice); // Create a thread that performs the dialogue group @@ -1688,7 +1610,7 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { \****************************************************************************/ bool DoSelection(uint32 i, uint32 dwData) { - LPMPALDIALOG dialog=lpmdDialogs+nExecutingDialog; + LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; int j; for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) @@ -1698,8 +1620,8 @@ bool DoSelection(uint32 i, uint32 dwData) { if (dialog->Choice[i].Select[j].dwData == 0) return false; - nSelectedChoice = j; - CoroScheduler.setEvent(hDoneChoice); + GLOBALS.nSelectedChoice = j; + CoroScheduler.setEvent(GLOBALS.hDoneChoice); return true; } @@ -1742,8 +1664,8 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); /* Si salva l'array delle funzioni custom */ - lplpFunctions = lplpcfArray; - lplpFunctionStrings = lpcfStrings; + GLOBALS.lplpFunctions = lplpcfArray; + GLOBALS.lplpFunctionStrings = lpcfStrings; /* Apre il file MPC in lettura */ if (!hMpc.open(lpszMpcFileName)) @@ -1764,7 +1686,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (hMpc.err()) return false; - lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeDecomp+16); + byte *lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeDecomp+16); if (lpMpcImage == NULL) return false; @@ -1811,73 +1733,73 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, { char errbuf[256]; wsprintf(errbuf,"Utilizzo in RAM: VAR %lu, MSG %lu, DLG %lu, ITM %lu, LOC %lu, SCR %lu", - nVars*sizeof(MPALVAR), - nMsgs*sizeof(MPALMSG), - nDialogs*sizeof(MPALDIALOG), - nItems*sizeof(MPALITEM), - nLocations*sizeof(MPALLOCATION), - nScripts*sizeof(MPALSCRIPT)); + GLOBALS.nVars*sizeof(MPALVAR), + GLOBALS.nMsgs*sizeof(MPALMSG), + GLOBALS.nDialogs*sizeof(MPALDIALOG), + GLOBALS.nItems*sizeof(MPALITEM), + GLOBALS.nLocations*sizeof(MPALLOCATION), + GLOBALS.nScripts*sizeof(MPALSCRIPT)); MessageBox(NULL,errbuf,"Dump",MB_OK); } */ /* Apre il file MPR in lettura */ - if (!hMpr.open(lpszMprFileName)) + if (!GLOBALS.hMpr.open(lpszMprFileName)) return false; /* Si posiziona a 8 byte dalla fine del file */ - hMpr.seek(-12, SEEK_END); + GLOBALS.hMpr.seek(-12, SEEK_END); - dwSizeComp = hMpr.readUint32LE(); - if (hMpr.err()) + dwSizeComp = GLOBALS.hMpr.readUint32LE(); + if (GLOBALS.hMpr.err()) return false; - nResources = hMpr.readUint32LE(); - if (hMpr.err()) + GLOBALS.nResources = GLOBALS.hMpr.readUint32LE(); + if (GLOBALS.hMpr.err()) return false; - nBytesRead = hMpr.read(buf, 4); - if (hMpr.err()) + nBytesRead = GLOBALS.hMpr.read(buf, 4); + if (GLOBALS.hMpr.err()) return false; if (buf[0] !='E' || buf[1] != 'N' || buf[2] != 'D' || buf[3] != '0') return false; /* Si posiziona all'inizio dell'header delle risorse */ - hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); + GLOBALS.hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); - lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nResources * 8); - if (lpResources == NULL) + GLOBALS.lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS.nResources * 8); + if (GLOBALS.lpResources == NULL) return false; cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); if (cmpbuf == NULL) return false; - nBytesRead = hMpr.read(cmpbuf, dwSizeComp); + nBytesRead = GLOBALS.hMpr.read(cmpbuf, dwSizeComp); if (nBytesRead != dwSizeComp) return false; - lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)lpResources, (uint32 *)&nBytesRead); - if (nBytesRead != (uint32)nResources*8) + lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)GLOBALS.lpResources, (uint32 *)&nBytesRead); + if (nBytesRead != (uint32)GLOBALS.nResources*8) return false; GlobalFree(cmpbuf); /* Si riposiziona all'inizio lasciando il file di risorse aperto */ - hMpr.seek(0, SEEK_SET); + GLOBALS.hMpr.seek(0, SEEK_SET); /* Non c'e' nessuna azione ne' dialogo in esecuzione */ - bExecutingAction = false; - bExecutingDialog = false; + GLOBALS.bExecutingAction = false; + GLOBALS.bExecutingDialog = false; /* Non c'e' nessuna locazione in polling */ - Common::fill(nPollingLocations, nPollingLocations + MAXPOLLINGLOCATIONS, 0); + Common::fill(GLOBALS.nPollingLocations, GLOBALS.nPollingLocations + MAXPOLLINGLOCATIONS, 0); /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' da effettuare una scelta */ - hAskChoice = CoroScheduler.createEvent(true, false); - hDoneChoice = CoroScheduler.createEvent(true, false); + GLOBALS.hAskChoice = CoroScheduler.createEvent(true, false); + GLOBALS.hDoneChoice = CoroScheduler.createEvent(true, false); return true; } @@ -1920,7 +1842,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { va_list v; va_start(v, wQueryType); - mpalError = OK; + GLOBALS.mpalError = OK; if (wQueryType == MPQ_VERSION) { /* @@ -1961,13 +1883,13 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { y = GETARG(uint32); if (x != -1) { if (y == MPQ_X) - dwRet = lpmlLocations[x].dwXlen; + dwRet = GLOBALS.lpmlLocations[x].dwXlen; else if (y == MPQ_Y) - dwRet = lpmlLocations[x].dwYlen; + dwRet = GLOBALS.lpmlLocations[x].dwYlen; else - mpalError = 1; + GLOBALS.mpalError = 1; } else - mpalError = 1; + GLOBALS.mpalError = 1; UnlockLocations(); @@ -2022,7 +1944,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { else { LockItems(); y = itemGetOrderFromNum(x); - CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + CopyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); UnlockItems(); } @@ -2070,7 +1992,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { dwRet = DoAction(x, y, GETARG(uint32)); } else { dwRet = CORO_INVALID_PID_VALUE; - mpalError = 1; + GLOBALS.mpalError = 1; } UnlockVar(); @@ -2080,7 +2002,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); */ - if (!bExecutingDialog) { + if (!GLOBALS.bExecutingDialog) { LockDialogs(); x = dialogGetOrderFromNum(GETARG(uint32)); @@ -2092,7 +2014,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * DEFAULT -> ERROR */ - mpalError = 1; + GLOBALS.mpalError = 1; } va_end(v); @@ -2114,7 +2036,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { va_start(v, wQueryType); void *hRet = NULL; - mpalError = OK; + GLOBALS.mpalError = OK; if (wQueryType == MPQ_VERSION) { /* @@ -2154,7 +2076,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { */ LockLocations(); x = locGetOrderFromNum(GETARG(uint32)); - hRet = resLoad(lpmlLocations[x].dwPicRes); + hRet = resLoad(GLOBALS.lpmlLocations[x].dwPicRes); UnlockLocations(); } else if (wQueryType == MPQ_RESOURCE) { @@ -2198,7 +2120,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { else { LockItems(); y = itemGetOrderFromNum(x); - CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + CopyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); UnlockItems(); } @@ -2248,7 +2170,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * DEFAULT -> ERROR */ - mpalError = 1; + GLOBALS.mpalError = 1; } va_end(v); @@ -2277,12 +2199,12 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, hAskChoice, CORO_INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.hAskChoice, CORO_INFINITE); - CoroScheduler.resetEvent(hAskChoice); + CoroScheduler.resetEvent(GLOBALS.hAskChoice); - if (bExecutingDialog) - *dwRet = (uint32)nExecutingChoice; + if (GLOBALS.bExecutingDialog) + *dwRet = (uint32)GLOBALS.nExecutingChoice; else *dwRet = (uint32)((int)-1); } else { @@ -2306,7 +2228,7 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { \****************************************************************************/ uint32 mpalGetError(void) { - return mpalError; + return GLOBALS.mpalError; } @@ -2333,7 +2255,7 @@ bool mpalExecuteScript(int nScript) { if (s == NULL) return false; - CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT)); + CopyMemory(s, GLOBALS.lpmsScripts + n, sizeof(MPALSCRIPT)); UnlockScripts(); // !!! Nuova gestione dei thread @@ -2346,17 +2268,17 @@ bool mpalExecuteScript(int nScript) { /****************************************************************************\ * -* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); +* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION GLOBALS.lpiifCustom); * * Description: Install a custom routine that will be called by MPAL every * time the pattern of an item has been changed. * -* Input: LPITEMIRQFUNCTION lpiifCustom Custom function to install +* Input: LPITEMIRQFUNCTION GLOBALS.lpiifCustom Custom function to install * \****************************************************************************/ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { - lpiifCustom = lpiifCus; + GLOBALS.lpiifCustom = lpiifCus; } @@ -2380,17 +2302,17 @@ bool mpalStartIdlePoll(int nLoc) { uint32 i; for (i = 0; i < MAXPOLLINGLOCATIONS; i++) - if (nPollingLocations[i] == (uint32)nLoc) + if (GLOBALS.nPollingLocations[i] == (uint32)nLoc) return false; for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { - if (nPollingLocations[i] == 0) { - nPollingLocations[i] = nLoc; + if (GLOBALS.nPollingLocations[i] == 0) { + GLOBALS.nPollingLocations[i] = nLoc; - hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); + GLOBALS.hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); // !!! Nuova gestione dei thread - if ((PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) -// if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) + if ((GLOBALS.PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) +// if ((GLOBALS.hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) return false; return true; @@ -2423,13 +2345,13 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { CORO_BEGIN_CODE(_ctx); for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { - if (nPollingLocations[_ctx->i] == (uint32)nLoc) { - CoroScheduler.setEvent(hEndPollingLocations[_ctx->i]); + if (GLOBALS.nPollingLocations[_ctx->i] == (uint32)nLoc) { + CoroScheduler.setEvent(GLOBALS.hEndPollingLocations[_ctx->i]); - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, PollingThreads[_ctx->i], CORO_INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.PollingThreads[_ctx->i], CORO_INFINITE); - CoroScheduler.closeEvent(hEndPollingLocations[_ctx->i]); - nPollingLocations[_ctx->i] = 0; + CoroScheduler.closeEvent(GLOBALS.hEndPollingLocations[_ctx->i]); + GLOBALS.nPollingLocations[_ctx->i] = 0; if (result) *result = true; @@ -2456,7 +2378,7 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { \****************************************************************************/ int mpalGetSaveStateSize(void) { - return nVars * sizeof(MPALVAR) + 4; + return GLOBALS.nVars * sizeof(MPALVAR) + 4; } @@ -2473,8 +2395,8 @@ int mpalGetSaveStateSize(void) { void mpalSaveState(byte *buf) { LockVar(); - WRITE_LE_UINT32(buf, nVars); - CopyMemory(buf + 4, (byte *)lpmvVars, nVars * sizeof(MPALVAR)); + WRITE_LE_UINT32(buf, GLOBALS.nVars); + CopyMemory(buf + 4, (byte *)GLOBALS.lpmvVars, GLOBALS.nVars * sizeof(MPALVAR)); UnlockVar(); } @@ -2492,16 +2414,16 @@ void mpalSaveState(byte *buf) { int mpalLoadState(byte *buf) { // Dobbiamo distruggere tutte le variabili e ricrearle - GlobalFree(hVars); + GlobalFree(GLOBALS.hVars); - nVars = READ_LE_UINT32(buf); + GLOBALS.nVars = READ_LE_UINT32(buf); - hVars = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, nVars * sizeof(MPALVAR)); + GLOBALS.hVars = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); LockVar(); - CopyMemory((byte *)lpmvVars, buf + 4, nVars * sizeof(MPALVAR)); + CopyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); UnlockVar(); - return nVars*sizeof(MPALVAR)+4; + return GLOBALS.nVars*sizeof(MPALVAR)+4; } bool bDontOutput; @@ -2652,18 +2574,18 @@ void mpalDumpMessages(void) { f = g_system->getSavefileManager()->openForSaving("Messages.htm"); f->writeString("\n\n
%s %s %s %s
\n"); - for (i = 0; i < nMsgs; i++) { - lpMessage = (char*)GlobalLock(lpmmMsgs[i].hText); + for (i = 0; i < GLOBALS.nMsgs; i++) { + lpMessage = (char*)GlobalLock(GLOBALS.lpmmMsgs[i].hText); if (*lpMessage != '\0') { // bernie: debug - /*if (lpmmMsgs[i].wNum == 1950) { + /*if (GLOBALS.lpmmMsgs[i].wNum == 1950) { int a = 1; }*/ nPeriods = 1; p=lpPeriods[0] = lpMessage; - OutputStartMsgComment(lpmmMsgs[i].wNum, f); + OutputStartMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); while (1) { // Trova la fine del periodo corrente @@ -2682,9 +2604,9 @@ void mpalDumpMessages(void) { // Ora fa un ciclo su tutti i periodi for (j = 0;jwriteString("\n\n"); - for (i = 0; i < nMsgs; i++) { - lpMessage = (char*)GlobalLock(lpmmMsgs[i].hText); + for (i = 0; i < GLOBALS.nMsgs; i++) { + lpMessage = (char*)GlobalLock(GLOBALS.lpmmMsgs[i].hText); if (*lpMessage != '\0') { nPeriods = 1; p=lpPeriods[0] = lpMessage; - if (OutputStartOther(lpmmMsgs[i].wNum, f)) { + if (OutputStartOther(GLOBALS.lpmmMsgs[i].wNum, f)) { while (1) { // Trova la fine del periodo corrente while (*p!='\0') @@ -2768,9 +2690,9 @@ void mpalDumpOthers(void) { // Ora fa un ciclo su tutti i periodi for (j = 0; j < nPeriods; j++) { if (nPeriods == 1) - sprintf(fname, "000-%05d.WAV", lpmmMsgs[i].wNum); + sprintf(fname, "000-%05d.WAV", GLOBALS.lpmmMsgs[i].wNum); else - sprintf(fname, "000-%05d-%02d.WAV", lpmmMsgs[i].wNum,j); + sprintf(fname, "000-%05d-%02d.WAV", GLOBALS.lpmmMsgs[i].wNum,j); strcpy(frase,lpPeriods[j]); @@ -2792,9 +2714,9 @@ void mpalDumpOthers(void) { } } - OutputEndOther(lpmmMsgs[i].wNum, f); + OutputEndOther(GLOBALS.lpmmMsgs[i].wNum, f); - GlobalUnlock(lpmmMsgs[i].hText); + GlobalUnlock(GLOBALS.lpmmMsgs[i].hText); } } @@ -3284,8 +3206,8 @@ void mpalDumpDialogs(void) { LockDialogs(); - for (i = 0; i < nDialogs; i++) - mpalDumpDialog(&lpmdDialogs[i]); + for (i = 0; i < GLOBALS.nDialogs; i++) + mpalDumpDialog(&GLOBALS.lpmdDialogs[i]); UnlockDialogs(); } diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index ee3820531a..a7b6dfc5aa 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -51,8 +51,10 @@ #define __MPALDLL_H #include "common/file.h" -#include "memory.h" -#include "stubs.h" +#include "tony/mpal/memory.h" +#include "tony/mpal/stubs.h" +#include "tony/mpal/loadmpc.h" +#include "tony/mpal/expr.h" namespace Tony { @@ -332,41 +334,6 @@ typedef LPMPALSCRIPT* LPLPMPALSCRIPT; #include "common/pack-end.h" -/****************************************************************************\ -* Variabili globali -\****************************************************************************/ - -extern uint32 mpalError; -extern LPLPCUSTOMFUNCTION lplpFunctions; -extern uint16 nObjs; - -extern uint16 nVars; -extern HGLOBAL hVars; -extern LPMPALVAR lpmvVars; - -extern uint16 nMsgs; -extern HGLOBAL hMsgs; -extern LPMPALMSG lpmmMsgs; - -extern uint16 nDialogs; -extern HGLOBAL hDialogs; -extern LPMPALDIALOG lpmdDialogs; - -extern uint16 nItems; -extern HGLOBAL hItems; -extern LPMPALITEM lpmiItems; - -extern uint16 nLocations; -extern HGLOBAL hLocations; -extern LPMPALLOCATION lpmlLocations; - -extern uint16 nScripts; -extern HGLOBAL hScripts; -extern LPMPALSCRIPT lpmsScripts; - -extern Common::File hMpr; -extern uint16 nResources; -extern uint32 * lpResources; /****************************************************************************\ * Prototipi di funzione @@ -412,8 +379,5 @@ void varSetValue(const char *lpszVarName, int32 val); } // end of namespace Tony -#include "loadmpc.h" -#include "expr.h" - #endif -- cgit v1.2.3 From cf3d2cd3562a6d30690f6e8acb8fb4f17739fa35 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 14 May 2012 08:53:09 +1000 Subject: TONY: Removed some no longer needed FIXME's --- engines/tony/mpal/mpal.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 66d467f301..f049ecf3ea 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1229,7 +1229,6 @@ void LocationPollThread(CORO_PARAM, const void *param) { */ // Set idle skip on - // FIXME: Convert to co-routine CORO_INVOKE_4(GLOBALS.lplpFunctions[200], 0, 0, 0, 0); for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) -- cgit v1.2.3 From 9eb66a2324120a6c4e22a980a9114bce437fcd8b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 14 May 2012 20:21:54 +1000 Subject: TONY: Added endian fixes for reading data --- engines/tony/mpal/loadmpc.cpp | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 937374517f..6430325503 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -96,27 +96,27 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { int curCmd,j,len; uint i; - lpmsScript->nObj=*(int *)lpBuf; - lpBuf+=4; + lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; - lpmsScript->nMoments=*(uint16 *)lpBuf; - lpBuf+=2; + lpmsScript->nMoments = READ_LE_UINT16(lpBuf); + lpBuf += 2; curCmd=0; for (i=0;inMoments;i++) { - lpmsScript->Moment[i].dwTime=*(int *)lpBuf; lpBuf+=4; + lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; lpmsScript->Moment[i].nCmds=*lpBuf; lpBuf++; for (j=0;jMoment[i].nCmds;j++) { lpmsScript->Command[curCmd].type=*lpBuf; lpBuf++; switch (lpmsScript->Command[curCmd].type) { case 1: - lpmsScript->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; - lpmsScript->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; - lpmsScript->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; - lpmsScript->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; - lpmsScript->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + lpmsScript->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmsScript->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmsScript->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmsScript->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmsScript->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; case 2: // Variable assign @@ -260,7 +260,7 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { error("Too much commands in dialog #%d",lpmdDialog->nObj); /* Choices */ - num=*(uint16 *)lpBuf; lpBuf += 2; + num = READ_LE_UINT16(lpBuf); lpBuf += 2; if (num >= MAX_CHOICES_PER_DIALOG) error("Too much choices in dialog #%d",lpmdDialog->nObj); @@ -343,8 +343,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { uint32 i,j,kk; uint32 curCmd; - lpmiItem->nObj=*(int *)lpBuf; - lpBuf+=4; + lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; len=*lpBuf; lpBuf++; @@ -367,12 +367,12 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->Action[i].num=*lpBuf; lpBuf++; - lpmiItem->Action[i].wParm=*(uint16 *)lpBuf; - lpBuf+=2; + lpmiItem->Action[i].wParm = READ_LE_UINT16(lpBuf); + lpBuf += 2; if (lpmiItem->Action[i].num==0xFF) { - lpmiItem->Action[i].wTime=*(uint16 *)lpBuf; - lpBuf+=2; + lpmiItem->Action[i].wTime = READ_LE_UINT16(lpBuf); + lpBuf += 2; lpmiItem->Action[i].perc=*lpBuf; lpBuf++; @@ -400,11 +400,11 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpBuf++; switch (lpmiItem->Command[curCmd].type) { case 1: // Call custom function - lpmiItem->Command[curCmd].nCf =*(uint16 *)(lpBuf); lpBuf+=2; - lpmiItem->Command[curCmd].arg1=*(int *)(lpBuf); lpBuf+=4; - lpmiItem->Command[curCmd].arg2=*(int *)(lpBuf); lpBuf+=4; - lpmiItem->Command[curCmd].arg3=*(int *)(lpBuf); lpBuf+=4; - lpmiItem->Command[curCmd].arg4=*(int *)(lpBuf); lpBuf+=4; + lpmiItem->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmiItem->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmiItem->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmiItem->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmiItem->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; case 2: // Variable assign @@ -444,7 +444,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } } - lpmiItem->dwRes=*(uint32 *)lpBuf; lpBuf+=4; + lpmiItem->dwRes = READ_LE_UINT32(lpBuf); lpBuf += 4; return lpBuf; } @@ -468,14 +468,14 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { \****************************************************************************/ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) { - lpmlLocation->nObj=*(int *)lpBuf; - lpBuf+=4; - lpmlLocation->dwXlen=*(uint16 *)lpBuf; - lpBuf+=2; - lpmlLocation->dwYlen=*(uint16 *)lpBuf; - lpBuf+=2; - lpmlLocation->dwPicRes=*(uint32 *)lpBuf; - lpBuf+=4; + lpmlLocation->nObj = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmlLocation->dwXlen = READ_LE_UINT16(lpBuf); + lpBuf += 2; + lpmlLocation->dwYlen = READ_LE_UINT16(lpBuf); + lpBuf += 2; + lpmlLocation->dwPicRes = READ_LE_UINT32(lpBuf); + lpBuf += 4; return lpBuf; } -- cgit v1.2.3 From d67a5162addcc143c870ed35000212bdd7d7ab2c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 May 2012 21:48:03 +1000 Subject: TONY: Converting method comments to DOXYGEN format --- engines/tony/mpal/mpal.cpp | 770 +++++++++++++++------------------------------ engines/tony/mpal/mpal.h | 705 +++++++++++++++-------------------------- 2 files changed, 503 insertions(+), 972 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index f049ecf3ea..a173b707f2 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -61,6 +61,8 @@ namespace Tony { namespace MPAL { +#define GETARG(type) va_arg(v, type) + /****************************************************************************\ * Copyright \****************************************************************************/ @@ -76,39 +78,25 @@ const char *mpalCopyright = * Internal functions \****************************************************************************/ -/****************************************************************************\ -* -* Function: void LockVar(void); -* -* Description: Locka le variabili per accederci -* -\****************************************************************************/ - +/** + * Locks the variables for access + */ void LockVar(void) { GLOBALS.lpmvVars = (LPMPALVAR)GlobalLock(GLOBALS.hVars); } -/****************************************************************************\ -* -* Function: void UnlockVar(void); -* -* Description: Unlocka le variabili dopo l'uso -* -\****************************************************************************/ +/** + * Unlocks variables after use + */ void UnlockVar(void) { GlobalUnlock(GLOBALS.hVars); } -/****************************************************************************\ -* -* Function: void LockMsg(void); -* -* Description: Locka i messaggi per accederci -* -\****************************************************************************/ - +/** + * Locks the messages for access + */ static void LockMsg(void) { #ifdef NEED_LOCK_MSGS GLOBALS.lpmmMsgs = (LPMPALMSG)GlobalLock(GLOBALS.hMsgs); @@ -116,14 +104,9 @@ static void LockMsg(void) { } -/****************************************************************************\ -* -* Function: void UnlockMsg(void); -* -* Description: Unlocka i messaggi dopo l'uso -* -\****************************************************************************/ - +/** + * Unlocks the messages after use + */ static void UnlockMsg(void) { #ifdef NEED_LOCK_MSGS GlobalUnlock(GLOBALS.hMsgs); @@ -131,125 +114,79 @@ static void UnlockMsg(void) { } -/****************************************************************************\ -* -* Function: void LockDialogs(void); -* -* Description: Locka i dialoghi per accederci -* -\****************************************************************************/ - +/** + * Locks the dialogs for access + */ static void LockDialogs(void) { GLOBALS.lpmdDialogs = (LPMPALDIALOG)GlobalLock(GLOBALS.hDialogs); } -/****************************************************************************\ -* -* Function: void UnlockDialogs(void); -* -* Description: Unlocka i dialoghi dopo l'uso -* -\****************************************************************************/ - +/** + * Unlocks the dialogs after use + */ static void UnlockDialogs(void) { GlobalUnlock(GLOBALS.hDialogs); } -/****************************************************************************\ -* -* Function: void LockLocations(void); -* -* Description: Locka le strutture di dati sulle locazioni -* -\****************************************************************************/ - +/** + * Locks the location data structures for access + */ static void LockLocations(void) { GLOBALS.lpmlLocations = (LPMPALLOCATION)GlobalLock(GLOBALS.hLocations); } -/****************************************************************************\ -* -* Function: void UnlockLocations(void); -* -* Description: Unlocka le strutture di dati sulle locazioni -* -\****************************************************************************/ - +/** + * Unlocks the location structures after use + */ static void UnlockLocations(void) { GlobalUnlock(GLOBALS.hLocations); } -/****************************************************************************\ -* -* Function: void LockItems(void); -* -* Description: Locka le strutture di dati sugli item -* -\****************************************************************************/ - +/** + * Locks the items structures for use + */ static void LockItems(void) { GLOBALS.lpmiItems = (LPMPALITEM)GlobalLock(GLOBALS.hItems); } -/****************************************************************************\ -* -* Function: void UnlockItems(void); -* -* Description: Unlocka le strutture di dati sugli item -* -\****************************************************************************/ - +/** + * Unlocks the items structures after use + */ static void UnlockItems(void) { GlobalUnlock(GLOBALS.hItems); } -/****************************************************************************\ -* -* Function: void LockScripts(void); -* -* Description: Locka le strutture di dati sugli script -* -\****************************************************************************/ +/** + * Locks the script data structures for use + */ static void LockScripts(void) { GLOBALS.lpmsScripts = (LPMPALSCRIPT)GlobalLock(GLOBALS.hScripts); } -/****************************************************************************\ -* -* Function: void UnlockScripts(void); -* -* Description: Unlocka le strutture di dati sugli script -* -\****************************************************************************/ - +/** + * Unlocks the script data structures after use + */ static void UnlockScripts(void) { GlobalUnlock(GLOBALS.hScripts); } -/****************************************************************************\ -* -* Function: int varGetValue(char * lpszVarName); -* -* Description: Restituisce il valore corrente di una variabile globale -* -* Input: char * lpszVarName Nome della variabile -* -* Return: Valore corrente -* -* Note: Prima di questa funzione, bisogna richiamare LockVar() che -* locka le variabili globali per l'utilizzo. Dopo inoltre bi- -* sogna ricordarsi di chiamare UnlockVar() -* -\****************************************************************************/ - +/** + * Returns the current value of a global variable + * + * @param lpszVarName Name of the variable + * @returns Current value + * @remarks Before using this method, you must call LockVar() to + * lock the global variablves for use. Then afterwards, you will + * need to remember to call UnlockVar() + */ int32 varGetValue(const char *lpszVarName) { int i; LPMPALVAR v=GLOBALS.lpmvVars; @@ -263,17 +200,11 @@ int32 varGetValue(const char *lpszVarName) { } -/****************************************************************************\ -* -* Function: void varSetValue(char * lpszVarName, int val); -* -* Description: Setta un nuovo valore per una variabile globale di MPAL -* -* Input: char * lpszVarName Nome della variabile -* int val Valore da settare -* -\****************************************************************************/ - +/** + * Sets the value of a MPAL global variable + * @param lpszVarName Name of the variable + * @param val Value to set + */ void varSetValue(const char *lpszVarName, int32 val) { uint i; LPMPALVAR v = GLOBALS.lpmvVars; @@ -298,22 +229,14 @@ void varSetValue(const char *lpszVarName, int32 val) { } -/****************************************************************************\ -* -* Function: int locGetOrderFromNum(uint32 nLoc); -* -* Description: Trova l'indice della locazione #nLoc all'interno dell'array -* delle strutture delle locazioni -* -* Input: uint32 nLoc Numero della locazione da cercare -* -* Return: Indice, o -1 se la locazione non e' presente -* -* Note: Per funzionare, la funzione necessita che le locazioni siano -* state lockate con LockLoc() -* -\****************************************************************************/ - +/** + * Find the index of a location within the location array. Remember to call LockLoc() beforehand. + * + * @param nLoc Location number to search for + * @returns Index, or -1 if the location is not present + * @remarks This function requires the location list to have + * first been locked with a call to LockLoc(). + */ static int locGetOrderFromNum(uint32 nLoc) { int i; LPMPALLOCATION loc = GLOBALS.lpmlLocations; @@ -325,22 +248,14 @@ static int locGetOrderFromNum(uint32 nLoc) { return -1; } -/****************************************************************************\ -* -* Function: int msgGetOrderFromNum(uint32 nMsg); -* -* Description: Trova l'indice del messaggio #nMsg all'interno dell'array -* delle strutture dei messaggi -* -* Input: uint32 nMsg Numero del messaggio da cercare -* -* Return: Indice, o -1 se il messaggio non e' presente -* -* Note: Per funzionare, la funzione necessita che i messaggi siano -* stati lockati con LockMsg() -* -\****************************************************************************/ +/** + * Find the index of a message within the messages array + * @param nMsg Message number to search for + * @returns Index, or -1 if the message is not present + * @remarks This function requires the message list to have + * first been locked with a call to LockMsg() + */ static int msgGetOrderFromNum(uint32 nMsg) { int i; LPMPALMSG msg = GLOBALS.lpmmMsgs; @@ -352,23 +267,13 @@ static int msgGetOrderFromNum(uint32 nMsg) { return -1; } - -/****************************************************************************\ -* -* Function: int itemGetOrderFromNum(uint32 nItem); -* -* Description: Trova l'indice dell'item #nItem all'interno dell'array delle -* strutture degli item -* -* Input: uint32 nItem Numero dell'item da cercare -* -* Return: Indice, o -1 se l'item non e' presente -* -* Note: Per funzionare, questa funzione necessita che gli item siano -* stati lockati tramite LockItem() -* -\****************************************************************************/ - +/** + * Find the index of an item within the items array + * @param nItem Item number to search for + * @returns Index, or -1 if the item is not present + * @remarks This function requires the item list to have + * first been locked with a call to LockItems() + */ static int itemGetOrderFromNum(uint32 nItem) { int i; LPMPALITEM item = GLOBALS.lpmiItems; @@ -381,22 +286,13 @@ static int itemGetOrderFromNum(uint32 nItem) { } -/****************************************************************************\ -* -* Function: int scriptGetOrderFromNum(uint32 nScript); -* -* Description: Trova l'indice dello script #nScript all'interno dell'array -* delle strutture degli script -* -* Input: uint32 nScript Numero dello script da cercare -* -* Return: Indice, o -1 se lo script non e' presente -* -* Note: Per funzionare, questa funzione necessita che gli script siano -* stati lockati tramite LockScript() -* -\****************************************************************************/ - +/** + * Find the index of a script within the scripts array + * @param nScript Script number to search for + * @returns Index, or -1 if the script is not present + * @remarks This function requires the script list to have + * first been locked with a call to LockScripts() + */ static int scriptGetOrderFromNum(uint32 nScript) { int i; LPMPALSCRIPT script = GLOBALS.lpmsScripts; @@ -409,22 +305,13 @@ static int scriptGetOrderFromNum(uint32 nScript) { } -/****************************************************************************\ -* -* Function: int dialogGetOrderFromNum(uint32 nDialog); -* -* Description: Trova l'indice del dialog #nDialog all'interno dell'array -* delle strutture dei dialog -* -* Input: uint32 nDialog Numero del dialog da cercare -* -* Return: Indice, o -1 se il dialog non e' presente -* -* Note: Per funzionare, questa funzione necessita che i dialog siano -* stati lockati tramite LockDialogs() -* -\****************************************************************************/ - +/** + * Find the index of a dialog within the dialogs array + * @param nDialog Dialog number to search for + * @returns Index, or -1 if the dialog is not present + * @remarks This function requires the dialog list to have + * first been locked with a call to LockDialogs() + */ static int dialogGetOrderFromNum(uint32 nDialog) { int i; LPMPALDIALOG dialog = GLOBALS.lpmdDialogs; @@ -437,21 +324,12 @@ static int dialogGetOrderFromNum(uint32 nDialog) { } - -/****************************************************************************\ -* -* Function: char * DuplicateMessage(uint32 nMsgOrd); -* -* Description: Duplica un messaggio -* -* Input: uint32 nMsgOrd Indice del messaggio dentro l'array -* di strutture dei messaggi -* -* Return: Pointer al messaggio duplicato (che puo' essere liberato -* con GlobalFree()). -* -\****************************************************************************/ - +/** + * Duplicates a message + * @param nMsgOrd Index of the message inside the messages array + * @returns Pointer to the duplicated message. + * @remarks Remember to free the duplicated message when done with it. + */ static char *DuplicateMessage(uint32 nMsgOrd) { const char *origmsg; char *clonemsg; @@ -478,22 +356,13 @@ static char *DuplicateMessage(uint32 nMsgOrd) { } -/****************************************************************************\ -* -* Function: char * DuplicateDialogPeriod(uint32 nDlgOrd, uint32 nPeriod); -* -* Description: Duplica una frase di un dialog -* -* Input: uint32 nDlgOrd Indice del dialogo dentro l'array di -* strutture dei dialoghi -* -* uint32 nPeriod Numero della frase da duplicare -* -* Return: Pointer alla frase duplicata (che puo' essere liberata con -* GlobalFree()). -* -\****************************************************************************/ - +/** + * Duplicate a sentence of a dialog + * @param nDlgOrd Index of the dialog in the dialogs array + * @param nPeriod Sentence number to be duplicated. + * @returns Pointer to the duplicated phrase. Remember to free it + * when done with it. + */ static char *DuplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; @@ -524,19 +393,12 @@ static char *DuplicateDialogPeriod(uint32 nPeriod) { } - -/****************************************************************************\ -* -* Function: HGLOBAL resLoad(uint32 dwId); -* -* Description: Carica una risorsa dal file MPR -* -* Input: uint32 dwId ID della risorsa da caricare -* -* Return: Handle alla memoria in cui si trova la risorsa -* -\****************************************************************************/ - +/** + * Load a resource from the MPR file + * + * @param dwId ID of the resource to load + * @returns Handle to the loaded resource + */ HGLOBAL resLoad(uint32 dwId) { int i; HGLOBAL h; @@ -736,21 +598,13 @@ static LPITEM GetItemData(uint32 nOrdItem) { } -/****************************************************************************\ -* -* Function: void CustomThread(LPCFCALL p); -* -* Description: Thread che richiama una funzione custom. Viene usato negli -* script, in modo che ciascuna funzione venga eseguita senza -* ritardare le altre -* -* Input: LPCFCALL p Struttura che definisce la chiamata -* -* Note: La struttura passata come parametro viene freeata con -* GlobalFree() alla fine dell'esecuzione. -* -\****************************************************************************/ - +/** + * Thread that calls a custom function. It is used in scripts, so that each script + * function is executed without delaying the others. + * + * @param param pointer to a pointer to the structure that defines the call. + * @remarks The passed structure is freed when the process finishes. + */ void CustomThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; LPCFCALL p; @@ -768,20 +622,12 @@ void CustomThread(CORO_PARAM, const void *param) { } -/****************************************************************************\ -* -* Function: void ScriptThread(LPMPALSCRIPT s); -* -* Description: Esegue uno script. Questa funzione e' pensata come starting -* point per un thread -* -* Input: LPMPALSCRIPT s Script da eseguire -* -* Note: Lo script passato come parametro viene, alla fine dell'ese- -* cuzione, freeato con una GlobalFree() -* -\****************************************************************************/ - +/** + * Main process for running a script. + * + * @param param Pointer to a pointer to a structure containing the script data. + * @remarks The passed structure is freed when the process finishes. + */ void ScriptThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; uint i, j, k; @@ -866,20 +712,13 @@ void ScriptThread(CORO_PARAM, const void *param) { } -/****************************************************************************\ -* -* Function: void ActionThread(LPMPALITEM item); -* -* Description: Thread che esegue una azione su un item. Il thread -* esegue sempre l'azione 0, per cui e' necessario creare -* un item nuovo in cui l'azione 0 sia quella richiesta. -* Inoltre non viene controllata l'espressione when, ma viene -* sempre eseguita l'azione. -* -* Input: LPMPALITEM item Item che contiene l'azione -* -\****************************************************************************/ - +/** + * Thread that performs an action on an item. the thread always executes the action, + * so it should create a new item in which the action is the one required. + * Furthermore, the expression is not checked, but it is always performed the action. + * + * @param param Pointer to a pointer to a structure containing the action. + */ void ActionThread(CORO_PARAM, const void *param) { // COROUTINE CORO_BEGIN_CONTEXT; @@ -935,8 +774,8 @@ void ActionThread(CORO_PARAM, const void *param) { /** * This thread monitors a created action to detect when it ends. - * @remarks Since actions can spawn sub-actions, this needs to be a - * separate thread to determine when the outer action is done + * @remarks Since actions can spawn sub-actions, this needs to be a + * separate thread to determine when the outer action is done */ void ShutUpActionThread(CORO_PARAM, const void *param) { // COROUTINE @@ -956,18 +795,12 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_END_CODE; } -/****************************************************************************\ -* -* Function: void LocationPollThread(uint32 id); -* -* Description: Esegue il polling di una locazione (starting point di un -* thread). -* -* Input: uint32 id Indice per gli array relativi ai -* polling degli item delle locazioni -* -\****************************************************************************/ +/** + * Polls one location (starting point of a process) + * + * @param param Pointer to an index in the array of polling locations. + */ void LocationPollThread(CORO_PARAM, const void *param) { typedef struct { uint32 nItem, nAction; @@ -1257,22 +1090,17 @@ void LocationPollThread(CORO_PARAM, const void *param) { -/****************************************************************************\ -* -* Function: void ShutUpDialogThread(HANDLE hThread); -* -* Description: Aspetta la fine dell'esecuzione del dialog thread e ripri- -* stina le variabili globali indicando che il dialogo e' finito. -* -* Input: HANDLE hThread Handle del dialog thread -* -* Note: Si ricorre a questo thread aggiuntivo, al posto di azzerare -* le variabili all'interno del dialog thread stesso, poiche', -* a causa della natura ricorsiva di un dialogo, non e' sempre -* possibile sapere quando esattamente finisce un dialogo. -* -\****************************************************************************/ + +/** + * Wait for the end of the dialog execution thread, and then restore global + * variables indicating that the dialogue has finished. + * + * @param param Pointer to a handle to the dialog + * @remarks This additional process is used, instead of clearing variables + * within the same dialog thread, because due to the recursive nature of a dialog, + * it would be difficult to know within it when the dialog is actually ending. + */ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; CORO_END_CONTEXT(_ctx); @@ -1296,9 +1124,10 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { void DoChoice(CORO_PARAM, uint32 nChoice); + /** * Executes a group of the current dialog. Can 'be the Starting point of a process. - * @parm nGroup Number of the group to perform + * @parm nGroup Number of the group to perform */ void GroupThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; @@ -1371,16 +1200,11 @@ void GroupThread(CORO_PARAM, const void *param) { } -/****************************************************************************\ -* -* Function: void DoChoice(uint32 nChoice); -* -* Description: Esegue una scelta nel dialogo corrente -* -* Input: uint32 nChoice Numero della scelta da eseguire -* -\****************************************************************************/ - +/** + * Make a choice in the current dialog. + * + * @param nChoice Number of choice to perform + */ void DoChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CONTEXT; LPMPALDIALOG dialog; @@ -1476,29 +1300,18 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { } - -/****************************************************************************\ -* -* Function: HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam); -* -* Description: Esegue una azione su un certo item -* -* Input: uint32 nAction Numero dell'azione -* uint32 ordItem Indice dell'item nelle strutture -* degli item -* uint32 dwParam Eventuale parametro per l'azione -* -* Return: Handle del thread che sta eseguendo l'azione, oppure -* CORO_INVALID_PID_VALUE se l'azione non e' definita, o l'item -* e' disattivato. -* -* Note: Si puo' ottenere l'indice dell'item a partire dal suo numero -* tramite la funzione itemGetOrderFromNum(). -* Gli item devono essere lockati, perche' questa funzione -* funzioni, tramite LockItem(); -* -\****************************************************************************/ - +/** + * Perform an action on a certain item. + * + * @param nAction Action number + * @param ordItem Index of the item in the items list + * @param dwParam Any parameter for the action. + * @returns Id of the process that was launched to perform the action, or + * CORO_INVALID_PID_VALUE if the action was not defined, or the item was inactive. + * @remarks You can get the index of an item from it's number by using + * the itemGetOrderFromNum() function. The items list must first be locked + * by calling LockItem(). + */ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = GLOBALS.lpmiItems; int i; @@ -1594,20 +1407,14 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { } -/****************************************************************************\ -* -* Function: bool DoSelection(uint32 nChoice, uint32 dwData); -* -* Description: Prende nota del select scelto dall'utente, e avverte il -* thread che stava eseguendo il dialogo che puo' continuare. -* -* Input: uint32 nChoice Numero della scelta che era in corso -* uint32 dwData Dato abbinato al select selezionato -* -* Return: true se tutto OK, false in caso di errore -* -\****************************************************************************/ - +/** + * Takes note of the selection chosen by the user, and warns the process that was running + * the box that it can continue. + * + * @param nChoice Number of choice that was in progress + * @param dwData Since combined with select selection + * @returns True if everything is OK, false on failure + */ bool DoSelection(uint32 i, uint32 dwData) { LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; int j; @@ -1625,30 +1432,18 @@ bool DoSelection(uint32 i, uint32 dwData) { } +/** + * @defgroup Exported functions + */ -/****************************************************************************\ -* Exported functions -\****************************************************************************/ - -/****************************************************************************\ -* -* Function: bool mpalInit(LPSTR lpszMpcFileName, LPSTR lpszMprFileName, -* LPLPCUSTOMFUNCTION lplpcfArray); -* -* Description: Inizializza la libreria MPAL, e apre un file .MPC, che -* verra' utilizzato per tutte le query -* -* Input: char * lpszMpcFileName Nome del file .MPC, comprensivo di -* estensione -* char * lpszMprFileName Nome del file .MPR, comprensivo di -* estensione -* LPLPCUSTOMFUNCTION -* lplpcfArray Array di pointer a funzioni custom -* -* Return: true se tutto OK, false in caso di errore -* -\****************************************************************************/ - +/** + * Initialises the MPAL library and opens the .MPC file, which will be used for all queries. + * + * @param lpszMpcFileName Name of the MPC file + * @param lpszMprFileName Name of the MPR file + * @param lplpcfArray Array of pointers to custom functions. + * @returns True if everything is OK, false on failure + */ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings) { Common::File hMpc; @@ -1803,34 +1598,15 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, return true; } -/****************************************************************************\ -* -* Function: uint32 mpalQuery(uint16 wQueryType, ...); -* -* Description: Questa e' la funzione generale per comunicare con la libreria, -* per richiedere informazioni riguardo a quanto si trova nel -* file .MPC -* -* Input: uint16 wQueryType Tipo di query. La lista e' in -* enum QueryTypes -* -* Return: 4 bytes che dipendono dal tipo di query -* -* Note: E' _FORTEMENTE_ consigliato utilizzare le macro -* definite sopra per utilizzare le query, dato che -* permettono di evitare spiacevoli bug dovuti a dimenticanze -* di parametri. -* -\****************************************************************************/ - -#define GETARG(type) va_arg(v, type) /** - * MPAL Query variation #1 - dword return - * This variation handles mpal query types that need to return a dword result. + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file * - * @param wQueryType Query type - * @param v Variable length argument list + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that returns numeric results. */ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { int x, y, z; @@ -1844,6 +1620,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { GLOBALS.mpalError = OK; if (wQueryType == MPQ_VERSION) { + /* * uint32 mpalQuery(MPQ_VERSION); */ @@ -2021,11 +1798,13 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { } /** - * MPAL Query variation #1 - dword return - * This variation handles mpal query types that need to return a pointer/handle result + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file * - * @param wQueryType Query type - * @param v Variable length argument list + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that returns a pointer or handle. */ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { int x, y; @@ -2176,13 +1955,15 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { return hRet; } + /** - * MPAL Query variation #1 - dword return - * This variation handles mpal query types that need to return a pointer/handle result + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file * - * @param wQueryType Query type - * @param dwRet DWORD return value (when coroutine method completes) - * @param v Variable length argument list + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that needs to run within a co-routine context. */ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { CORO_BEGIN_CONTEXT; @@ -2216,34 +1997,22 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { } -/****************************************************************************\ -* -* Function: uint32 mpalGetError(void); -* -* Description: Ritorna il codice di errore corrente di MPAL -* -* Return: Codice di errore -* -\****************************************************************************/ - +/** + * Returns the current MPAL error code + * + * @returns Error code + */ uint32 mpalGetError(void) { return GLOBALS.mpalError; } -/****************************************************************************\ -* -* Function: void mpalExecuteScript(int nScript); -* -* Description: Esegue uno script. Lo script viene eseguito in multitasking -* tramite un thread. -* -* Input: int nScript Numero dello script da eseguire -* -* Return: true se lo script e' stato avviato, false in caso di errore -* -\****************************************************************************/ - +/** + * Execute a script. The script runs on multitasking by a thread. + * + * @param nScript Script number to run + * @returns TRUE if the script 'was launched, FALSE on failure + */ bool mpalExecuteScript(int nScript) { int n; LPMPALSCRIPT s; @@ -2265,38 +2034,26 @@ bool mpalExecuteScript(int nScript) { } -/****************************************************************************\ -* -* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION GLOBALS.lpiifCustom); -* -* Description: Install a custom routine that will be called by MPAL every -* time the pattern of an item has been changed. -* -* Input: LPITEMIRQFUNCTION GLOBALS.lpiifCustom Custom function to install -* -\****************************************************************************/ - +/** + * Install a custom routine That will be called by MPAL every time the pattern + * of an item has been changed. + * + * @param lpiifCustom Custom function to install + */ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { GLOBALS.lpiifCustom = lpiifCus; } -/****************************************************************************\ -* -* Function: bool mpalStartIdlePoll(int nLoc); -* -* Description: Process the idle actions of the items on one location. -* -* Input: int nLoc Number of the location whose items -* must be processed for idle actions. -* -* Return: true se tutto OK, false se si e' superato il limite massimo. -* -* Note: Il numero massimo delle locazione che e' possibile pollare -* contemporaneamente e' contenuto nel define MAXPOLLINGFUNCIONS -* -\****************************************************************************/ - +/** + * Process the idle actions of the items on one location. + * + * @param nLoc Number of the location whose items must be processed + * for idle actions. + * @returns TRUE if all OK, and FALSE if it exceeded the maximum limit. + * @remarks The maximum number of locations that can be polled + * simultaneously is defined defined by MAXPOLLINGFUNCIONS + */ bool mpalStartIdlePoll(int nLoc) { uint32 i; @@ -2322,20 +2079,13 @@ bool mpalStartIdlePoll(int nLoc) { } - -/****************************************************************************\ -* -* Function: bool mpalEndIdlePoll(int nLoc); -* -* Description: Stop processing the idle actions of the items on one location. -* -* Input: int nLoc Number of the location -* -* Return: true se tutto OK, false se la locazione specificata non era -* in fase di polling -* -\****************************************************************************/ - +/** + * Stop processing the idle actions of the items on one location. + * + * @param nLo Number of the location + * @returns TRUE if all OK, FALSE if the specified location was not + * in the process of polling + */ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { CORO_BEGIN_CONTEXT; int i; @@ -2365,33 +2115,22 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { } - -/****************************************************************************\ -* -* Function: int mpalGetSaveStateSize(void); -* -* Description: Acquire the length of a save state -* -* Return: Length in bytes -* -\****************************************************************************/ - +/** + * Retrieve the length of a save state + * + * @returns Length in bytes + */ int mpalGetSaveStateSize(void) { return GLOBALS.nVars * sizeof(MPALVAR) + 4; } -/****************************************************************************\ -* -* Function: void mpalSaveState(byte *buf); -* -* Description: Store the save state into a buffer. The buffer must be -* length at least the size specified with mpalGetSaveStateSize -* -* Input: byte *buf Buffer where to store the state -* -\****************************************************************************/ - +/** + * Store the save state into a buffer. The buffer must be + * length at least the size specified with mpalGetSaveStateSize + * + * @param buf Buffer where to store the state + */ void mpalSaveState(byte *buf) { LockVar(); WRITE_LE_UINT32(buf, GLOBALS.nVars); @@ -2399,18 +2138,13 @@ void mpalSaveState(byte *buf) { UnlockVar(); } -/****************************************************************************\ -* -* Function: int mpalLoadState(byte *buf); -* -* Description: Load a save state from a buffer. -* -* Input: byte *buf Buffer where to store the state -* -* Return: Length of the state in bytes -* -\****************************************************************************/ +/** + * Load a save state from a buffer. + * + * @param buf Buffer where to store the state + * @returns Length of the state buffer in bytes + */ int mpalLoadState(byte *buf) { // Dobbiamo distruggere tutte le variabili e ricrearle GlobalFree(GLOBALS.hVars); diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 319f71c6a8..a14bfd1895 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -126,6 +126,12 @@ namespace Tony { namespace MPAL { +/****************************************************************************\ +* Type definitions +\****************************************************************************/ + +typedef void *HANDLE; + /****************************************************************************\ * Macro definitions and structures \****************************************************************************/ @@ -140,25 +146,19 @@ namespace MPAL { #define LPSTR char * -/****************************************************************************\ -* enum QueryCoordinates -* --------------------- -* Description: Macro for use with queries that may refer to X and Y co-ordinates -\****************************************************************************/ - +/** + * Macro for use with queries that may refer to X and Y co-ordinates + */ enum QueryCoordinates { MPQ_X, MPQ_Y }; -/****************************************************************************\ -* enum QueryTypes -* --------------- -* Description: Query can be used with mpalQuery methods. In practice corresponds -* all claims that can do at the library -\****************************************************************************/ - +/** + * Query can be used with mpalQuery methods. In practice corresponds all claims + * that can do at the library + */ enum QueryTypes { /* General Query */ MPQ_VERSION=10, @@ -189,13 +189,9 @@ enum QueryTypes { MPQ_DO_DIALOG }; - -/****************************************************************************\ -* typedef ITEM -* ------------ -* Description: Framework to manage the animation of an item -\****************************************************************************/ - +/** + * Framework to manage the animation of an item + */ typedef struct { char *frames[MAXFRAMES]; Common::Rect frameslocations[MAXFRAMES]; @@ -214,311 +210,188 @@ typedef struct { typedef ITEM *LPITEM; -/****************************************************************************\ -* typedef LPCUSTOMFUNCTION -* ------------------------ -* Description: Define a custom function, to use the language MPAL -* to perform various controls as a result of an action -\****************************************************************************/ - +/** + * Define a custom function, to use the language MPAL to perform various controls as a result of an action + */ typedef void (*LPCUSTOMFUNCTION)(CORO_PARAM, uint32, uint32, uint32, uint32); typedef LPCUSTOMFUNCTION *LPLPCUSTOMFUNCTION; - -/****************************************************************************\ -* typedef LPITEMIRQFUNCTION -* ------------------------- -* Description: Define an IRQ of an item that is called when the -* pattern changes or the status of an item -\****************************************************************************/ - +/** + * + * Define an IRQ of an item that is called when the pattern changes or the status of an item + */ typedef void (*LPITEMIRQFUNCTION)(uint32, int, int); typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; +/** + * @defgroup Macrofunctions query + * + * The following are defines used for simplifying calling the mpalQuery variants + */ -/****************************************************************************\ -* Macrofunctions query -\****************************************************************************/ - -/****************************************************************************\ -* -* Function: uint32 mpalQueryVersion(void); -* -* Description: Gets the current version of MPAL -* -* Return: Version number (0x1232 = 1.2.3b) -* -\****************************************************************************/ - +/** + * Gets the current version of MPAL + * + * @returns Version number (0x1232 = 1.2.3b) + */ #define mpalQueryVersion() \ (uint16)mpalQueryDWORD(MPQ_VERSION) - - -/****************************************************************************\ -* -* Function: uint32 mpalQueryGlobalVar(LPSTR lpszVarName); -* -* Description: Gets the numerical value of a global variable -* -* Input: LPSTR lpszVarName Nome della variabile (ASCIIZ) -* -* Return: Valore della variabile -* -* Note: This query was implemented for debugging. The program, -* if well designed, should not need to access variables from -* within the library. -* -\****************************************************************************/ - +/** + * Gets the numerical value of a global variable + * + * @param lpszVarName Nome della variabile (ASCIIZ) + * @returns Global variable value + * @remarks This query was implemented for debugging. The program, + * if well designed, should not need to access variables from + * within the library. + */ #define mpalQueryGlobalVar(lpszVarName) \ mpalQueryDWORD(MPQ_GLOBAL_VAR, (const char *)(lpszVarName)) - -/****************************************************************************\ -* -* Function: HGLOBAL mpalQueryResource(uint32 dwResId); -* -* Description: Provides access to a resource inside the .MPC file -* -* Input: uint32 dwResId ID della risorsa -* -* Return: Handle to a memory area containing the resource, -* ready for use. -* -\****************************************************************************/ - +/** + * Provides access to a resource inside the .MPC file + * + * @param dwResId Resource Id + * @returns Handle to a memory area containing the resource, ready for use. + */ #define mpalQueryResource(dwResId) \ mpalQueryHANDLE(MPQ_RESOURCE, (uint32)(dwResId)) - -/****************************************************************************\ -* -* Function: LPSTR mpalQueryMessage(uint32 nMsg); -* -* Description: Returns a message. -* -* Input: uint32 nMsg Message number -* -* Return: ASCIIZ message -* -* Note: The returned pointer must be freed with GlobalFree() +/** + * Returns a message. + * + * @param nMsg Message number + * @returns ASCIIZ message + * @remarks The returned pointer must be freed via the memory manager * after use. The message will be in ASCIIZ format. -* -\****************************************************************************/ - +*/ #define mpalQueryMessage(nMsg) \ (LPSTR)mpalQueryHANDLE(MPQ_MESSAGE, (uint32)(nMsg)) - -/****************************************************************************\ -* -* Function: HGLOBAL mpalQueryLocationImage(uint32 nLoc); -* -* Description: Provides a image image -* -* Input: uint32 nLoc Locazion number -* -* Return: Returns a picture handle -* -\****************************************************************************/ - +/** + * Provides a location image + * @return Returns a picture handle + */ #define mpalQueryLocationImage(nLoc) \ mpalQueryHANDLE(MPQ_LOCATION_IMAGE, (uint32)(nLoc)) - -/****************************************************************************\ -* -* Function: uint32 mpalQueryLocationSize(uint32 nLoc, uint32 dwCoord); -* -* Description: Request the x or y size of a location in pixels -* -* Input: uint32 nLoc Location number -* uint32 dwCoord MPQ_Xr o MPQ_Y -* -* Return: Size -* -\****************************************************************************/ - +/** + * Request the x or y size of a location in pixels + * + * @param nLoc Location number + * @param dwCoord MPQ_X or MPQ_Y coordinate to retrieve + * @returns Size + */ #define mpalQueryLocationSize(nLoc,dwCoord) \ mpalQueryDWORD(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord)) - -/****************************************************************************\ -* -* Function: uint32 * mpalQueryItemList(uint32 nLoc); -* -* Description: Provides the list of objects in the lease. -* -* Input: uint32 nLoc Location number -* -* Return: List of objects (accessible by Item [0], Item [1], etc.) -* -\****************************************************************************/ -// TODO: Check if the results of this are endian safe +/** + * Provides the list of objects in a location. + * + * @param nLoc Location number + * @returns List of objects (accessible by Item [0], Item [1], etc.) + */ +// TODO: Determine if this is endian safe #define mpalQueryItemList(nLoc) \ (uint32 *)mpalQueryHANDLE(MPQ_ITEM_LIST,(uint32)(nLoc)) - -/****************************************************************************\ -* -* Function: LPBKGANIM mpalQueryItemData(uint32 nItem); -* -* Description: Provides information on an item -*e -* Input: uint32 nItem Item number -* -* Return: structure filled with requested information -* -\****************************************************************************/ - +/** + * Provides information on an item + * + * @param nItem Item number + * @returns Structure filled with requested information + */ #define mpalQueryItemData(nItem) \ (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA,(uint32)(nItem)) - -/****************************************************************************\ -* -* Function: uint32 mpalQueryItemPattern(uint32 nItem); -* -* Description: Provides the current pattern of an item -* -* Input: uint32 nItem Item number -* -* Return: Number of animation patterns to be executed. -* -* Note: By default, the pattern of 0 indicates that we should -* do nothing. -* -\****************************************************************************/ - +/** + * Provides the current pattern of an item + * + * @param nItem Item number + * @returns Number of animation patterns to be executed. + * @remarks By default, the pattern of 0 indicates that we should do nothing. + */ #define mpalQueryItemPattern(nItem) \ mpalQueryDWORD(MPQ_ITEM_PATTERN,(uint32)(nItem)) - -/****************************************************************************\ -* -* Function: bool mpalQueryItemIsActive(uint32 nItem); -* -* Description: Returns true if an item is active -* -* Input: uint32 nItem Item number -* -* Return: TRUE if the item is active, FALSE otherwise -* -\****************************************************************************/ - +/** + * Returns true if an item is active + * + * @param nItem Item number + * @returns TRUE if the item is active, FALSE otherwise + */ #define mpalQueryItemIsActive(nItem) \ (bool)mpalQueryDWORD(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem)) -/****************************************************************************\ -* -* Function: void mpalQueryItemName(uint32 nItem, LPSTR lpszName); -* -* Description: Returns the name of an item -* -* Input: uint32 nItem Item number -* LPSTR lpszName Pointer to a buffer of at least 33 bytes -* that will be filled with the name -* -* Note: If the item is not active (ie. if its status or number -* is less than or equal to 0), the string will be empty. -* -\****************************************************************************/ - +/** + * Returns the name of an item + * + * @param nItem Item number + * @param lpszName Pointer to a buffer of at least 33 bytes + * that will be filled with the name + * @remarks If the item is not active (ie. if its status or number + * is less than or equal to 0), the string will be empty. + */ #define mpalQueryItemName(nItem, lpszName) \ mpalQueryHANDLE(MPQ_ITEM_NAME,(uint32)(nItem), (LPSTR)(lpszName)) - -/****************************************************************************\ -* -* Function: LPSTR mpalQueryDialogPeriod(uint32 nDialog, uint32 nPeriod); -* -* Description: Returns a sentence of dialog. -* -* Input: uint32 nDialog Dialog number -* uint32 nPeriod Number of words -* -* Return: A pointer to the string of words, or NULL on failure. -* -* Note: The string must be freed after use by GlobalFree (). -* -* Unlike normal messages, the sentences of dialogue -* are formed by a single string terminated with 0. -* -\****************************************************************************/ - +/** + * Returns a sentence of dialog. + * + * @param nDialog Dialog number + * @param nPeriod Number of words + * @returns A pointer to the string of words, or NULL on failure. + * @remarks The string must be freed after use using the memory manager. + * Unlike normal messages, the sentences of dialogue are formed by a single + * string terminated with 0. + */ #define mpalQueryDialogPeriod(nPeriod) \ (LPSTR)mpalQueryHANDLE(MPQ_DIALOG_PERIOD, (uint32)(nPeriod)) - -/****************************************************************************\ -* -* Function: int mpalQueryDialogWaitForChoice(void); -* -* Description: Wait until the moment in which the need is signaled -* to make a choice by the user. -* -* Return: Number of choice to be made, or -1 if the dialogue is finished. -* -\****************************************************************************/ - +/** + * Wait until the moment in which the need is signaled to make a choice by the user. + * @returns Number of choice to be made, or -1 if the dialogue is finished. + */ #define mpalQueryDialogWaitForChoice(dwRet) \ CORO_INVOKE_2(mpalQueryCORO, MPQ_DIALOG_WAITFORCHOICE, dwRet) -/****************************************************************************\ -* -* Function: uint32 * mpalQueryDialogSelectList(uint32 nChoice); -* -* Description: Requires a list of various options for some choice within -* the current dialog. - -* Input: uint32 nChoice Choice number -* -* Return: A pointer to an array containing the data matched to each option. -* -* Note: The figure 'a uint32 specified in the source to which MPAL -* You can 'assign meaning that the more' suits. -* -* The pointer msut be freed after use by GlobalFree(). -* -\****************************************************************************/ +/** + * Requires a list of various options for some choice within the current dialog. + * + * @param nChoice Choice number + * @returns A pointer to an array containing the data matched to each option. + * @remarks The figure 'a uint32 specified in the source to which MPAL + * You can assign meaning that the more' suits. + * The pointer msut be freed after use using the memory memory. + */ #define mpalQueryDialogSelectList(nChoice) \ (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice)) - -/****************************************************************************\ -* -* Function: bool mpalQueryDialogSelection(uint32 nChoice, uint32 dwData); -* -* Description: Warns the library that the user has selected, in a certain -* choice of the current dialog, corresponding option -* at a certain given. -* -* Input: uint32 nChoice Choice number of the choice that -* was in progress -* uint32 dwData Option that was selected by the user. -* -* Return: TRUE if all OK, FALSE on failure. -* -* Note: After execution of this query, MPAL continue -* Groups according to the execution of the dialogue. And necessary so the game -* remains on hold again for another Chosen by mpalQueryDialogWaitForChoice (). -* -\****************************************************************************/ - +/** + * Warns the library that the user has selected, in a certain choice of the current dialog, + * corresponding option at a certain given. + * + * @param nChoice Choice number of the choice that was in progress + * @param dwData Option that was selected by the user. + * @returns TRUE if all OK, FALSE on failure. + * @remarks After execution of this query, MPAL continue + * Groups according to the execution of the dialogue. And necessary so the game + * remains on hold again for another chosen by mpalQueryDialogWaitForChoice (). + */ #define mpalQueryDialogSelection(nChoice,dwData) \ (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) @@ -526,245 +399,169 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) -/****************************************************************************\ -* -* Function: HANDLE mpalQueryDoAction(uint32 nAction, uint32 nItem, -* uint32 dwParam); -* -* Description: Warns the library an action was performed on a Object. -* The library will call 'custom functions, if necessary. -* -* Input: uint32 nAction Action number -* uint32 nItem Item number -* uint32 dwParam Action parameter -* -* Return: Handle to the thread that is performing the action, or -* CORO_INVALID_PID_VALUE if the action is not 'defined for -* the item, or the item and 'off. -* -* Note: The parameter is used primarily to implement actions -* as "U.S." involving two objects together. The action will be executed only -* if the item is active, ie if its status is a positive number greater than 0. -* -\****************************************************************************/ - +/** + * Warns the library an action was performed on a Object. + * The library will call custom functions, if necessary. + * + * @param nAction Action number + * @param nItem Item number + * @param dwParam Action parameter + * @returns Handle to the thread that is performing the action, or CORO_INVALID_PID_VALUE + * if the action is not defined for the item, or the item is inactive. + * @remarks The parameter is used primarily to implement actions + * as "U.S." involving two objects together. The action will be executed only + * if the item is active, ie if its status is a positive number greater than 0. + */ #define mpalQueryDoAction(nAction, nItem, dwParam) \ mpalQueryDWORD(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) - -/****************************************************************************\ -* -* Function: HANDLE mpalQueryDoDialog(uint32 nDialog, uint32 nGroup); -* -* Description: Warns the library a dialogue was required. -* -* Input: uint32 nDialog Dialog number -* uint32 nGroup Group number to use -* -* Return: Handle to the thread that is running the box, or -* CORO_INVALID_PID_VALUE if the dialogue does not exist. -* -\****************************************************************************/ - +/** + * Warns the library a dialogue was required. + * + * @param nDialog Dialog number + * @param nGroup Group number to use + * @returns Handle to the thread that is running the box, or + * CORO_INVALID_PID_VALUE if the dialogue does not exist. + */ #define mpalQueryDoDialog(nDialog,nGroup) \ mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) -/****************************************************************************\ -* Functions exported to the main game -\****************************************************************************/ - +/** + * @defgroup Functions exported to the main game + */ -/****************************************************************************\ -* -* Function: bool mpalInit(LPSTR lpszMpcFileName, LPSTR lpszMprFileName, -* LPLPCUSTOMFUNCTION lplpcfArray); -* -* Description: Initializes the MPAL library, and opens an .MPC file, which -* will be 'used for all queries -* -* Input: LPSTR lpszMpcFileName Name of the .MPC file, including extension -* LPSTR lpszMprFileName Name of the .MPR file, including extension -* LPLPCUSTOMFUNCTION Array of pointers to custom functions -* -* Return: TRUE if all OK, FALSE on failure -* -\****************************************************************************/ +/** + * Initializes the MPAL library, and opens an .MPC file, which will be 'used for all queries + * @param lpszMpcFileName Name of the .MPC file, including extension + * @param lpszMprFileName Name of the .MPR file, including extension + * @param lplpcfArray Array of pointers to custom functions + * @returns TRUE if all OK, FALSE on failure + */ bool mpalInit(const char *lpszFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings); - -/****************************************************************************\ -* -* Function: uint32 mpalQuery(uint16 wQueryType, ...); -* -* Description: This is the general function to communicate with the library, -* To request information about what is in the .MPC file -* -* Input: uint16 wQueryType Type of query. The list is in -* the QueryTypes enum. -* -* Return: 4 bytes depending on the type of query -* -* Note: I _strongly_ recommended to use macros defined above to use -* the query, since it helps avoid any unpleasant bugs due to -* forgeting parameters. -* -\****************************************************************************/ - -typedef void *HANDLE; - +/** + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file + * + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that returns numeric results. + */ uint32 mpalQueryDWORD(uint16 wQueryType, ...); +/** + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file + * + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that returns a pointer or handle. + */ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...); +/** + * This is a general function to communicate with the library, to request information + * about what is in the .MPC file + * + * @param wQueryType Type of query. The list is in the QueryTypes enum. + * @returns 4 bytes depending on the type of query + * @remarks This is the specialised version of the original single mpalQuery + * method that needs to run within a co-routine context. + */ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...); -/****************************************************************************\ -* -* Function: bool mpalExecuteScript(int nScript); -* -* Description: Execute a script. The script runs on multitasking by a thread. -* -* Input: int nScript Script number to run -* -* Return: TRUE if the script 'was launched, FALSE on failure -* -\****************************************************************************/ +/** + * Execute a script. The script runs on multitasking by a thread. + * + * @param nScript Script number to run + * @returns TRUE if the script 'was launched, FALSE on failure + */ bool mpalExecuteScript(int nScript); - -/****************************************************************************\ -* -* Function: uint32 mpalGetError(void); -* -* Description: Returns the current MPAL error code -* -* Return: Error code -* -\****************************************************************************/ - +/** + * Returns the current MPAL error code + * + * @returns Error code + */ uint32 mpalGetError(void); - -/****************************************************************************\ -* -* Function: void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); -* -* Description: Install a custom routine That will be called by MPAL -* every time the pattern of an item has-been changed. -* -* Input: LPITEMIRQFUNCTION lpiifCustom Custom function to install -* -\****************************************************************************/ - +/** + * Install a custom routine That will be called by MPAL every time the pattern + * of an item has been changed. + * + * @param lpiifCustom Custom function to install + */ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); -/****************************************************************************\ -* -* Function: bool mpalStartIdlePoll(int nLoc); -* -* Description: Process the idle actions of the items on one location. -* -* Input: int nLoc Number of the location whose items -* must be processed for idle actions. -* -* Return: TRUE if all OK, and FALSE if it exceeded the maximum limit. -* -* Note: The maximum number of locations that can be polled -* simultaneously is defined defined by MAXPOLLINGFUNCIONS -* -\****************************************************************************/ - +/** + * Process the idle actions of the items on one location. + * + * @param nLoc Number of the location whose items must be processed + * for idle actions. + * @returns TRUE if all OK, and FALSE if it exceeded the maximum limit. + * @remarks The maximum number of locations that can be polled + * simultaneously is defined defined by MAXPOLLINGFUNCIONS + */ bool mpalStartIdlePoll(int nLoc); -/****************************************************************************\ -* -* Function: bool mpalEndIdlePoll(int nLoc); -* -* Description: Stop processing the idle actions of the items on one location. -* -* Input: int nLoc Number of the location -* -* Return: TRUE if all OK, FALSE if the specified location was not -* in the process of polling -* -\****************************************************************************/ - +/** + * Stop processing the idle actions of the items on one location. + * + * @param nLo Number of the location + * @returns TRUE if all OK, FALSE if the specified location was not + * in the process of polling + */ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result); -/****************************************************************************\ -* -* Function: int mpalLoadState(LPBYTE buf); -* -* Description: Load a save state from a buffer. -* -* Input: LPBYTE buf Buffer where to store the state -* -* Return: Length of the state in bytes -* -\****************************************************************************/ - +/** + * Load a save state from a buffer. + * + * @param buf Buffer where to store the state + * @returns Length of the state buffer in bytes + */ int mpalLoadState(byte *buf); - -/****************************************************************************\ -* -* Function: void mpalSaveState(LPBYTE buf); -* -* Description: Store the save state into a buffer. The buffer must be -* length at least the size specified with mpalGetSaveStateSize -* -* Input: LPBYTE buf Buffer where to store the state -* -\****************************************************************************/ - +/** + * Store the save state into a buffer. The buffer must be + * length at least the size specified with mpalGetSaveStateSize + * + * @param buf Buffer where to store the state + */ void mpalSaveState(byte *buf); - -/****************************************************************************\ -* -* Function: int mpalGetSaveStateSize(void); -* -* Description: Acquire the length of a save state -* -* Return: Length in bytes -* -\****************************************************************************/ - +/** + * Retrieve the length of a save state + * + * @returns Length in bytes + */ int mpalGetSaveStateSize(void); -/****************************************************************************\ -* -* Function: void LockVar(void); -* -* Description: Locka le variabili per accederci -* -\****************************************************************************/ - -extern void LockVar(void); +/** + * Locks the variables for access + */ +void LockVar(void); -/****************************************************************************\ -* -* Function: void UnlockVar(void); -* -* Description: Unlocka le variabili dopo l'uso -* -\****************************************************************************/ -extern void UnlockVar(void); +/** + * Unlocks variables after use + */ +void UnlockVar(void); } // end of namespace MPAL -- cgit v1.2.3 From bcaeacf1246b652f1564fc7696719ca9429b5acf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 18 May 2012 22:57:25 +1000 Subject: TONY: Implemented support for loading savegames directly from the launcher. It's not perfect.. the startup screen briefly flashes, and Tony briefly disappears when you do a first action afterwards. --- engines/tony/mpal/mpal.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index a173b707f2..854372cdda 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -767,8 +767,6 @@ void ActionThread(CORO_PARAM, const void *param) { debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); - CORO_KILL_SELF(); - CORO_END_CODE; } @@ -780,6 +778,7 @@ void ActionThread(CORO_PARAM, const void *param) { void ShutUpActionThread(CORO_PARAM, const void *param) { // COROUTINE CORO_BEGIN_CONTEXT; + int slotNumber; CORO_END_CONTEXT(_ctx); uint32 pid = *(const uint32 *)param; @@ -790,7 +789,13 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { GLOBALS.bExecutingAction = false; - CORO_KILL_SELF(); + if (_vm->_initialLoadSlotNumber != -1) { + _ctx->slotNumber = _vm->_initialLoadSlotNumber; + _vm->_initialLoadSlotNumber = -1; + + CORO_INVOKE_1(_vm->LoadState, _ctx->slotNumber); + } + CORO_END_CODE; } -- cgit v1.2.3 From 5d18a71045bd933fc2efc7ed6e60ef7763745cb7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 12:33:14 +1000 Subject: TONY: Converting comments to English and formatting --- engines/tony/mpal/expr.cpp | 293 ++++++++++++++++++------------------------ engines/tony/mpal/expr.h | 65 +++------- engines/tony/mpal/loadmpc.cpp | 235 ++++++++++++++------------------- engines/tony/mpal/loadmpc.h | 21 +-- 4 files changed, 247 insertions(+), 367 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 19170ce60c..5e09e5dec6 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -61,9 +61,9 @@ namespace Tony { namespace MPAL { -/****************************************************************************\ -* Operazioni matematiche gestite -\****************************************************************************/ +/** + * @defgroup Mathamatical operations + */ #define OP_MUL ((1<<4)|0) #define OP_DIV ((1<<4)|1) @@ -85,32 +85,24 @@ namespace MPAL { #define OP_OR ((10<<4)|0) -/****************************************************************************\ -* enum ExprListTypes -* ------------------ -* Description: Tipi di oggetto che possono essere contenuti in una struttura -* EXPRESSION. -\****************************************************************************/ - -enum ExprListTypes -{ - ELT_NUMBER=1, - ELT_VAR=2, - ELT_PARENTH=3, - ELT_PARENTH2=4 +/** + * Object types that can be contained in an EXPRESSION structure + */ +enum ExprListTypes { + ELT_NUMBER = 1, + ELT_VAR = 2, + ELT_PARENTH = 3, + ELT_PARENTH2 = 4 }; -/****************************************************************************\ -* Structures -\****************************************************************************/ - -/****************************************************************************\ -* typedef EXPRESSION -* ------------------ -* Description: Struttura per gestire le operazioni matematiche -\****************************************************************************/ +/** + * @defgroup Structures + */ +/** + * Mathamatical framework to manage operations + */ typedef struct { byte type; // Tipo di oggetto (vedi enum ExprListTypes) byte unary; // Unary operatore (NON SUPPORTATO) @@ -128,38 +120,31 @@ typedef struct { typedef EXPRESSION* LPEXPRESSION; -/****************************************************************************\ -* -* Function: LPEXPRESSION DuplicateExpression(HGLOBAL h); -* -* Description: Duplica un'espressione matematica. L'espressione duplicata -* sara' formata da memoria non swappabile. -* -* Input: HGLOBAL h Handle dell'espressione originale -* -* Return: Pointer all'espressione clone della prima -* -\****************************************************************************/ - +/** + * Duplicate a mathematical expression. + * + * @param h Handle to the original expression + * @retruns Pointer to the cloned expression + */ static byte *DuplicateExpression(HGLOBAL h) { int i, num; byte *orig, *clone; LPEXPRESSION one, two; - orig=(byte *)GlobalLock(h); + orig = (byte *)GlobalLock(h); - num=*(byte *)orig; - one=(LPEXPRESSION)(orig+1); + num = *(byte *)orig; + one = (LPEXPRESSION)(orig+1); - clone = (byte *)GlobalAlloc(GMEM_FIXED, sizeof(EXPRESSION)*num+1); - two=(LPEXPRESSION)(clone+1); + clone = (byte *)GlobalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); + two = (LPEXPRESSION)(clone + 1); - CopyMemory(clone,orig,sizeof(EXPRESSION)*num+1); + CopyMemory(clone, orig, sizeof(EXPRESSION) * num + 1); - for (i=0;itype==ELT_PARENTH) { - two->type=ELT_PARENTH2; - two->val.pson=DuplicateExpression(two->val.son); + for (i = 0; i < num; i++) { + if (one->type == ELT_PARENTH) { + two->type = ELT_PARENTH2; + two->val.pson = DuplicateExpression(two->val.son); } one++; @@ -173,41 +158,41 @@ static byte *DuplicateExpression(HGLOBAL h) { static int Compute(int a, int b, byte symbol) { switch (symbol) { case OP_MUL: - return a*b; + return a * b; case OP_DIV: - return a/b; + return a / b; case OP_MODULE: - return a%b; + return a % b; case OP_ADD: - return a+b; + return a + b; case OP_SUB: - return a-b; + return a - b; case OP_SHL: - return a<>b; + return a >> b; case OP_MINOR: - return ab; + return a > b; case OP_MINEQ: - return a<=b; + return a <= b; case OP_MAJEQ: - return a>=b; + return a >= b; case OP_EQUAL: - return a==b; + return a == b; case OP_NOEQUAL: - return a!=b; + return a != b; case OP_BITAND: - return a&b; + return a & b; case OP_BITXOR: - return a^b; + return a ^ b; case OP_BITOR: - return a|b; + return a | b; case OP_AND: - return a&&b; + return a && b; case OP_OR: - return a||b; + return a || b; default: GLOBALS.mpalError = 1; break; @@ -220,52 +205,45 @@ static void Solve(LPEXPRESSION one, int num) { LPEXPRESSION two, three; int j; - while (num>1) { - two=one+1; - if ((two->symbol==0) || (one->symbol&0xF0) <= (two->symbol&0xF0)) { - two->val.num=Compute(one->val.num,two->val.num,one->symbol); - CopyMemory(one,two,(num-1)*sizeof(EXPRESSION)); + while (num > 1) { + two=one + 1; + if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { + two->val.num=Compute(one->val.num, two->val.num,one->symbol); + CopyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); num--; } else { - j=1; - three=two+1; - while ((three->symbol!=0) && (two->symbol&0xF0)>(three->symbol&0xF0)) { + j = 1; + three = two + 1; + while ((three->symbol != 0) && (two->symbol & 0xF0)>(three->symbol & 0xF0)) { two++; three++; j++; } - three->val.num=Compute(two->val.num,three->val.num,two->symbol); - CopyMemory(two,three,(num-j-1)*sizeof(EXPRESSION)); + three->val.num = Compute(two->val.num, three->val.num, two->symbol); + CopyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION)); num--; } } } -/****************************************************************************\ -* -* Function: int EvaluateAndFreeExpression(byte *expr); -* -* Description: Calcola il risultato di una espressione matematica, sosti- -* tuendo ad eventuali variabili il valore corrente. -* -* Input: byte *expr Pointer all'espressione duplicata -* tramite DuplicateExpression -* -* Return: Valore dell'espressione -* -\****************************************************************************/ - +/** + * Calculates the result of a mathematical expression, replacing the current + * value of any variable. + * + * @param expr Pointer to an expression duplicated by DuplicateExpression + * @returns Value + */ static int EvaluateAndFreeExpression(byte *expr) { int i,num,val; LPEXPRESSION one,cur; - num=*expr; - one=(LPEXPRESSION)(expr+1); + num = *expr; + one = (LPEXPRESSION)(expr + 1); // 1) Sostituzioni delle variabili - for (i=0,cur=one;itype==ELT_VAR) { cur->type=ELT_NUMBER; cur->val.num=varGetValue(cur->val.name); @@ -273,39 +251,30 @@ static int EvaluateAndFreeExpression(byte *expr) { } // 2) Sostituzioni delle parentesi (tramite ricorsione) - for (i=0,cur=one;itype==ELT_PARENTH2) { - cur->type=ELT_NUMBER; - cur->val.num=EvaluateAndFreeExpression(cur->val.pson); + for (i = 0, cur = one; i < num; i++, cur++) { + if (cur->type == ELT_PARENTH2) { + cur->type = ELT_NUMBER; + cur->val.num = EvaluateAndFreeExpression(cur->val.pson); } } // 3) Risoluzione algebrica - Solve(one,num); - val=one->val.num; + Solve(one, num); + val = one->val.num; GlobalFree(expr); return val; } -/****************************************************************************\ -* -* Function: byte *ParseExpression(byte *buf, HGLOBAL *h); -* -* Description: Esegue il parsing da file .MPC di un'espressione matematica. -* -* Input: byte *buf Buffer contenente l'espressione -* compilata. -* HGLOBAL *h Pointer a un handle che, alla fine -* dell'esecuzione, puntera' alla -* zona di memoria contenete l'espres- -* sione parsata -* -* Return: Puntatore al buffer subito dopo l'espressione, o NULL in caso -* di errore. -* -\****************************************************************************/ +/** + * Parses a mathematical expression from the MPC file + * + * @param buf Buffer containing the expression to evaluate + * @param h Pointer to a handle that, at the end of execution, + * will point to the area of memory containing the parsed expression + * @returns Pointer to the buffer immediately after the expression, or NULL if error. + */ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { LPEXPRESSION cur; byte *start; @@ -317,36 +286,36 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { if (num == 0) return NULL; - *h = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); + *h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); if (*h==NULL) return NULL; - start=(byte *)GlobalLock(*h); - *start=(byte)num; + start = (byte *)GlobalLock(*h); + *start = (byte)num; - cur=(LPEXPRESSION)(start+1); + cur = (LPEXPRESSION)(start + 1); - for (i=0;itype=*(lpBuf); - cur->unary=*(lpBuf+1); - lpBuf+=2; + for (i = 0;i < num; i++) { + cur->type = *(lpBuf); + cur->unary = *(lpBuf + 1); + lpBuf += 2; switch (cur->type) { case ELT_NUMBER: - cur->val.num=*(int *)lpBuf; - lpBuf+=4; + cur->val.num = *(int *)lpBuf; + lpBuf += 4; break; case ELT_VAR: - cur->val.name=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,(*lpBuf)+1); - if (cur->val.name==NULL) + cur->val.name = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); + if (cur->val.name == NULL) return NULL; - CopyMemory(cur->val.name,lpBuf+1,*lpBuf); - lpBuf+=*lpBuf+1; + CopyMemory(cur->val.name, lpBuf + 1, *lpBuf); + lpBuf += *lpBuf + 1; break; case ELT_PARENTH: - lpBuf=ParseExpression(lpBuf,&cur->val.son); - if (lpBuf==NULL) + lpBuf=ParseExpression(lpBuf, &cur->val.son); + if (lpBuf == NULL) return NULL; break; @@ -354,13 +323,13 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { return NULL; } - cur->symbol=*lpBuf; + cur->symbol = *lpBuf; lpBuf++; cur++; } - if (*lpBuf!=0) + if (*lpBuf != 0) return NULL; lpBuf++; @@ -369,18 +338,12 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { } -/****************************************************************************\ -* -* Function: int EvaluateExpression(HGLOBAL h); -* -* Description: Calcola il valore di un'espressione matematica -* -* Input: HGLOBAL h Handle all'espressione -* -* Return: Valore numerico -* -\****************************************************************************/ - +/** + * Calculate the value of a mathamatical expression + * + * @param h Handle to the expression + * @returns Numeric value + */ int EvaluateExpression(HGLOBAL h) { int ret; @@ -392,28 +355,22 @@ int EvaluateExpression(HGLOBAL h) { } -/****************************************************************************\ -* -* Function: bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); -* -* Description: Confronta due espressioni matematiche tra loro -* -* Input: HGLOBAL h1,h2 Espressioni da confrontare -* -* Return: true se sono uguali, false se sono diverse -* -\****************************************************************************/ - +/** + * Compare two mathematical expressions together + * + * @param h1 Expression to be compared + * @param h2 Expression to be compared + */ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { - int i,num1,num2; + int i, num1, num2; byte *e1, *e2; LPEXPRESSION one, two; - e1=(byte *)GlobalLock(h1); - e2=(byte *)GlobalLock(h2); + e1 = (byte *)GlobalLock(h1); + e2 = (byte *)GlobalLock(h2); - num1=*(byte *)e1; - num2=*(byte *)e2; + num1 = *(byte *)e1; + num2 = *(byte *)e2; if (num1 != num2) { GlobalUnlock(h1); @@ -421,11 +378,11 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { return false; } - one=(LPEXPRESSION)(e1+1); - two=(LPEXPRESSION)(e2+1); + one = (LPEXPRESSION)(e1+1); + two = (LPEXPRESSION)(e2+1); - for (i=0;itype!=two->type || (i!=num1-1 && one->symbol!=two->symbol)) { + for (i = 0; i < num1; i++) { + if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { GlobalUnlock(h1); GlobalUnlock(h2); return false; @@ -449,7 +406,7 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { break; case ELT_PARENTH: - if (!CompareExpressions(one->val.son,two->val.son)) { + if (!CompareExpressions(one->val.son, two->val.son)) { GlobalUnlock(h1); GlobalUnlock(h2); return false; diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 582f6d381d..3a9f0f3208 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -55,60 +55,37 @@ namespace Tony { namespace MPAL { /****************************************************************************\ -* Prototipi di funzione -\****************************************************************************/ - -/****************************************************************************\ -* -* Function: byte *ParseExpression(byte *buf, HGLOBAL *h); -* -* Description: Esegue il parsing da file .MPC di un'espressione matematica. -* -* Input: byte *buf Buffer contenente l'espressione -* compilata. -* HGLOBAL *h Pointer a un handle che, alla fine -* dell'esecuzione, puntera' alla -* zona di memoria contenete l'espres- -* sione parsata -* -* Return: Puntatore al buffer subito dopo l'espressione, o NULL in caso -* di errore. -* +* Function Prototypes \****************************************************************************/ +/** + * Parses a mathematical expression from the MPC file + * + * @param buf Buffer containing the expression to evaluate + * @param h Pointer to a handle that, at the end of execution, + * will point to the area of memory containing the parsed expression + * @returns Pointer to the buffer immediately after the expression, or NULL if error. + */ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); -/****************************************************************************\ -* -* Function: int EvaluateExpression(HGLOBAL h); -* -* Description: Calcola il valore di un'espressione matematica -* -* Input: HGLOBAL h Handle all'espressione -* -* Return: Valore numerico -* -\****************************************************************************/ - +/** + * Calculate the value of a mathamatical expression + * + * @param h Handle to the expression + * @returns Numeric value + */ int EvaluateExpression(HGLOBAL h); -/****************************************************************************\ -* -* Function: bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); -* -* Description: Confronta due espressioni matematiche tra loro -* -* Input: HGLOBAL h1,h2 Espressioni da confrontare -* -* Return: TRUE se sono uguali, FALSE se sono diverse -* -\****************************************************************************/ - +/** + * Compare two mathematical expressions together + * + * @param h1 Expression to be compared + * @param h2 Expression to be compared + */ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); - } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 6430325503..6a1213bc19 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -76,22 +76,14 @@ static bool CompareCommands(struct command *cmd1, struct command *cmd2) { } -/****************************************************************************\ -* -* Function: LPBTYE ParseScript(byte *lpBuf, LPMPALSCRIPT lpmsScript); -* -* Description: Esegue il parsing da file .MPC di uno script e inserisce il -* tutto dentro una struttura -* -* Input: byte *lpBuf Buffer contenente lo script compilato -* LPMPALSCRIPT lpmsScript Puntatore a una struttura che verra' -* riempita con i dati dello script -* lato -* -* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore -* -\****************************************************************************/ - +/** + * Parses a script from the MPC file, and inserts it's data into a structure + * + * @param lpBuf Buffer containing the compiled script. + * @param lpmsScript Pointer to a structure that will be filled with the + * data of the script. + * @returns Pointer to the buffer after the item, or NULL on failure. + */ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { int curCmd,j,len; uint i; @@ -102,14 +94,14 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpmsScript->nMoments = READ_LE_UINT16(lpBuf); lpBuf += 2; - curCmd=0; + curCmd = 0; - for (i=0;inMoments;i++) { + for (i = 0; i < lpmsScript->nMoments; i++) { lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Moment[i].nCmds=*lpBuf; lpBuf++; + lpmsScript->Moment[i].nCmds = *lpBuf; lpBuf++; - for (j=0;jMoment[i].nCmds;j++) { - lpmsScript->Command[curCmd].type=*lpBuf; lpBuf++; + for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) { + lpmsScript->Command[curCmd].type = *lpBuf; lpBuf++; switch (lpmsScript->Command[curCmd].type) { case 1: lpmsScript->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -121,14 +113,14 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { case 2: // Variable assign len=*lpBuf; lpBuf++; - lpmsScript->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); - if (lpmsScript->Command[curCmd].lpszVarName==NULL) + lpmsScript->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); + if (lpmsScript->Command[curCmd].lpszVarName == NULL) return NULL; CopyMemory(lpmsScript->Command[curCmd].lpszVarName, lpBuf, len); lpBuf+=len; lpBuf = ParseExpression(lpBuf, &lpmsScript->Command[curCmd].expr); - if (lpBuf==NULL) + if (lpBuf == NULL) return NULL; break; @@ -136,7 +128,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { return NULL; } - lpmsScript->Moment[i].CmdNum[j]=curCmd; + lpmsScript->Moment[i].CmdNum[j] = curCmd; curCmd++; } } @@ -145,26 +137,17 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { } -/****************************************************************************\ -* -* Function: byte *ParseDialog(byte *lpBuf, LPMPALDIALOG lpmdDialog); -* -* Description: Esegue il parsing da file .MPC di un dialog, e inserisce il -* tutto dentro una struttura -* -* Input: byte *lpBuf Buffer contenente il dialogo compi- -* lato -* LPMPALDIALOG lpmdDialog Puntatore a una struttura che verra' -* riempita con i dati del dialogo -* compilato -* -* Return: Puntatore al buffer dopo il dialogo, o NULL in caso di errore -* -\****************************************************************************/ - +/** + * Parses a dialog from the MPC file, and inserts it's data into a structure + * + * @param lpBuf Buffer containing the compiled dialog. + * @param lpmdDialog Pointer to a structure that will be filled with the + * data of the dialog. + * @returns Pointer to the buffer after the item, or NULL on failure. + */ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { - uint32 i,j,z,kk; - uint32 num,num2,num3; + uint32 i, j, z, kk; + uint32 num, num2, num3; byte *lpLock; uint32 curCmd; uint32 len; @@ -309,7 +292,7 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->Choice[i].Select[j].wPlayGroup[num3] = 0; } - // Segna l'ultimo select + // Mark the last selection lpmdDialog->Choice[i].Select[num2].dwData = 0; } @@ -318,70 +301,61 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { return lpBuf; } -/****************************************************************************\ -* -* Function: byte *ParseItem(byte *lpBuf, LPMPALITEM lpmiItem); -* -* Description: Esegue il parsing da file .MPC di un item, e inserisce il -* tutto dentro una struttura -* -* Input: byte *lpBuf Buffer contenete l'item compilato -* LPMPALITEM lpmiItem Puntatore a una struttura che verra' -* riempita con i dati dell'item -* compilato -* -* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore -* -* Note: E' necessario che la struttura passata come parametro sia -* stata completamente inizializzata a 0 (con una ZeroMemory, -* ad esempio). -* -\****************************************************************************/ +/** + * Parses an item from the MPC file, and inserts it's data into a structure + * + * @param lpBuf Buffer containing the compiled dialog. + * @param lpmiItem Pointer to a structure that will be filled with the + * data of the item. + * @returns Pointer to the buffer after the item, or NULL on failure. + * @remarks It's necessary that the structure that is passed has been + * completely initialised to 0 beforehand. + */ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { byte len; - uint32 i,j,kk; + uint32 i, j, kk; uint32 curCmd; lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - len=*lpBuf; + len = *lpBuf; lpBuf++; - CopyMemory(lpmiItem->lpszDescribe,lpBuf, MIN((byte)127, len)); - lpBuf+=len; + CopyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); + lpBuf += len; if (len >= MAX_DESCRIBE_SIZE) - error("Describe too long in item #%d",lpmiItem->nObj); + error("Describe too long in item #%d", lpmiItem->nObj); lpmiItem->nActions=*lpBuf; lpBuf++; /* Alloca le azioni */ - if (lpmiItem->nActions>0) - lpmiItem->Action = (ItemAction *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(struct ItemAction)*(int)lpmiItem->nActions); + if (lpmiItem->nActions > 0) + lpmiItem->Action = (ItemAction *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); - curCmd=0; + curCmd = 0; - for (i=0;inActions;i++) { - lpmiItem->Action[i].num=*lpBuf; + for (i = 0; i < lpmiItem->nActions; i++) { + lpmiItem->Action[i].num = *lpBuf; lpBuf++; lpmiItem->Action[i].wParm = READ_LE_UINT16(lpBuf); lpBuf += 2; - if (lpmiItem->Action[i].num==0xFF) { + if (lpmiItem->Action[i].num == 0xFF) { lpmiItem->Action[i].wTime = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmiItem->Action[i].perc=*lpBuf; + lpmiItem->Action[i].perc = *lpBuf; lpBuf++; } - if (*lpBuf==0) { + if (*lpBuf == 0) { lpBuf++; - lpmiItem->Action[i].when=NULL; + lpmiItem->Action[i].when = NULL; } else { lpBuf++; lpBuf = ParseExpression(lpBuf,&lpmiItem->Action[i].when); @@ -395,8 +369,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); - for (j=0;jAction[i].nCmds;j++) { - lpmiItem->Command[curCmd].type=*lpBuf; + for (j = 0; j < lpmiItem->Action[i].nCmds; j++) { + lpmiItem->Command[curCmd].type = *lpBuf; lpBuf++; switch (lpmiItem->Command[curCmd].type) { case 1: // Call custom function @@ -408,16 +382,16 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { break; case 2: // Variable assign - len=*lpBuf; + len = *lpBuf; lpBuf++; - lpmiItem->Command[curCmd].lpszVarName=(char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); - if (lpmiItem->Command[curCmd].lpszVarName==NULL) + lpmiItem->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmiItem->Command[curCmd].lpszVarName == NULL) return NULL; - CopyMemory(lpmiItem->Command[curCmd].lpszVarName,lpBuf,len); - lpBuf+=len; + CopyMemory(lpmiItem->Command[curCmd].lpszVarName, lpBuf, len); + lpBuf += len; - lpBuf=ParseExpression(lpBuf,&lpmiItem->Command[curCmd].expr); - if (lpBuf==NULL) + lpBuf=ParseExpression(lpBuf, &lpmiItem->Command[curCmd].expr); + if (lpBuf == NULL) return NULL; break; @@ -425,15 +399,15 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { return NULL; } - for (kk=0;kkCommand[kk],&lpmiItem->Command[curCmd])) { - lpmiItem->Action[i].CmdNum[j]=kk; + lpmiItem->Action[i].CmdNum[j] = kk; break; } } if (kk==curCmd) { - lpmiItem->Action[i].CmdNum[j]=curCmd; + lpmiItem->Action[i].CmdNum[j] = curCmd; curCmd++; if (curCmd >= MAX_COMMANDS_PER_ITEM) { @@ -450,23 +424,14 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } -/****************************************************************************\ -* -* Function: byte *ParseLocation(byte *buf, LPMPALLOCATIONN lpmlLocation) -* -* Description: Esegue il parsing da file .MPC di una locazione, riempendo -* una struttura -* -* Input: byte *buf Buffer contenente la locazione -* compilata -* LPMPALLOCATION -* lpmlLocation Pointer alla struttura che verra' -* riempita con i dati sulla locazione -* -* Return: Puntatore al buffer dopo l'item, o NULL in caso di errore -* -\****************************************************************************/ - +/** + * Parses a location from the MPC file, and inserts it's data into a structure + * + * @param lpBuf Buffer containing the compiled location. + * @param lpmiLocation Pointer to a structure that will be filled with the + * data of the location. + * @returns Pointer to the buffer after the location, or NULL on failure. + */ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) { lpmlLocation->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; @@ -480,39 +445,27 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) return lpBuf; } -/*static int CompareMoments(int * a, int * b) { - if (*a<*b) - return -1; - else if (*a>*b) - return 1; - else - return 0; -}*/ - -/****************************************************************************\ -* Funzioni globali -\****************************************************************************/ /****************************************************************************\ -* -* Function: bool ParseMpc(byte *lpBuf); -* -* Description: Legge e interpreta un file MPC, e crea le strutture per le -* varie direttive nelle variabili globali -* -* Input: byte *lpBuf Immagine in memoria del file MPC, -* escluso l'header -* -* Return: true se tutto OK, false in caso di errore. -* +* Exported functions \****************************************************************************/ +/** + * @defgroup Exported functions + */ +/** + * Reads and interprets the MPC file, and create structures for various directives + * in the global variables + * + * @param lpBuf Buffer containing the MPC file data, excluding the header. + * @returns True if succeeded OK, false if failure. + */ bool ParseMpc(const byte *lpBuf) { uint16 i, j; uint16 wLen; byte *lpTemp, *lpTemp2; - /* 1. Variabili */ + /* 1. Variables */ if (lpBuf[0] != 'V' || lpBuf[1] != 'A' || lpBuf[2] != 'R' || lpBuf[3] != 'S') return false; @@ -540,7 +493,7 @@ bool ParseMpc(const byte *lpBuf) { GlobalUnlock(GLOBALS.hVars); - /* 2. Messaggi */ + /* 2. Messages */ if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S') return false; @@ -588,7 +541,7 @@ bool ParseMpc(const byte *lpBuf) { GlobalUnlock(GLOBALS.hMsgs); #endif - /* 3. Oggetti */ + /* 3. Objects */ if (lpBuf[0] != 'O' || lpBuf[1] != 'B' || lpBuf[2] != 'J' || lpBuf[3] != 'S') return false; @@ -596,7 +549,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.nObjs = READ_LE_UINT16(lpBuf); lpBuf += 2; - // Controlla i dialoghi + // Check out the dialogs GLOBALS.nDialogs = 0; GLOBALS.hDialogs = GLOBALS.lpmdDialogs = NULL; if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) { @@ -615,13 +568,13 @@ bool ParseMpc(const byte *lpBuf) { GlobalUnlock(GLOBALS.hDialogs); } - // Controlla gli item + // Check the items GLOBALS.nItems = 0; GLOBALS.hItems = GLOBALS.lpmiItems = NULL; if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4)==0) { GLOBALS.nItems = READ_LE_UINT16(lpBuf); lpBuf += 2; - // Alloca la memoria e li legge + // Allocate memory and read them in GLOBALS.hItems = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); if (GLOBALS.hItems == NULL) return false; @@ -635,13 +588,13 @@ bool ParseMpc(const byte *lpBuf) { GlobalUnlock(GLOBALS.hItems); } - // Controlla le locazioni + // Check the locations GLOBALS.nLocations = 0; GLOBALS.hLocations = GLOBALS.lpmlLocations = NULL; if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8)==0) { GLOBALS.nLocations = READ_LE_UINT16(lpBuf); lpBuf += 2; - // Alloca la memoria e li legge + // Allocate memory and read them in GLOBALS.hLocations=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); if (GLOBALS.hLocations == NULL) return false; @@ -655,13 +608,13 @@ bool ParseMpc(const byte *lpBuf) { GlobalUnlock(GLOBALS.hLocations); } - // Controlla gli script + // Check the scripts GLOBALS.nScripts = 0; GLOBALS.hScripts = GLOBALS.lpmsScripts = NULL; if (*(lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Script", 6) == 0) { GLOBALS.nScripts = READ_LE_UINT16(lpBuf); lpBuf += 2; - // Alloca la memoria + // Allocate memory GLOBALS.hScripts = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); if (GLOBALS.hScripts == NULL) return false; @@ -672,7 +625,7 @@ bool ParseMpc(const byte *lpBuf) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS.lpmsScripts[i])) == NULL) return false; - // Ordina i vari moments dello script + // Sort the various moments of the script //qsort( //GLOBALS.lpmsScripts[i].Moment, //GLOBALS.lpmsScripts[i].nMoments, diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index 8763fbf95b..6aea3de16b 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -58,20 +58,13 @@ namespace MPAL { * Prototipi di funzione \****************************************************************************/ -/****************************************************************************\ -* -* Function: BOOL ParseMpc(LPBYTE lpBuf); -* -* Description: Legge e interpreta un file MPC, e crea le strutture per le -* varie direttive nelle variabili globali -* -* Input: LPBYTE lpBuf Immagine in memoria del file MPC, -* escluso l'header -* -* Return: TRUE se tutto OK, FALSE in caso di errore. -* -\****************************************************************************/ - +/** + * Reads and interprets the MPC file, and create structures for various directives + * in the global variables + * + * @param lpBuf Buffer containing the MPC file data, excluding the header. + * @returns True if succeeded OK, false if failure. + */ bool ParseMpc(const byte *lpBuf); -- cgit v1.2.3 From bd064fe044beb4c38b48a1c111d922fdfcf73516 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 13:18:47 +1000 Subject: TONY: Endian fix in expression parser --- engines/tony/mpal/expr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 5e09e5dec6..7643c8bde3 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -301,7 +301,7 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { lpBuf += 2; switch (cur->type) { case ELT_NUMBER: - cur->val.num = *(int *)lpBuf; + cur->val.num = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; -- cgit v1.2.3 From 8457c1c7682e3c0d0c382c01b042158ec506e300 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 16:57:17 +1000 Subject: TONY: Removed deprecated MPAL stubs file --- engines/tony/mpal/expr.cpp | 7 ++--- engines/tony/mpal/memory.cpp | 9 ++++++ engines/tony/mpal/memory.h | 3 ++ engines/tony/mpal/mpal.cpp | 1 - engines/tony/mpal/mpaldll.h | 1 - engines/tony/mpal/mpalutils.h | 3 +- engines/tony/mpal/stubs.cpp | 49 -------------------------------- engines/tony/mpal/stubs.h | 66 ------------------------------------------- 8 files changed, 16 insertions(+), 123 deletions(-) delete mode 100644 engines/tony/mpal/stubs.cpp delete mode 100644 engines/tony/mpal/stubs.h (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 7643c8bde3..cf688341be 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -47,10 +47,9 @@ * * **************************************************************************/ -#include "mpal.h" -#include "memory.h" -#include "mpaldll.h" -#include "stubs.h" +#include "tony/mpal/mpal.h" +#include "tony/mpal/memory.h" +#include "tony/mpal/mpaldll.h" #include "tony/tony.h" /* diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 166e3598f8..4410e8016c 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -146,6 +146,15 @@ void MemoryManager::erase(HGLOBAL handle) { erase(&item); } +/****************************************************************************\ +* Stand-alone methods +\****************************************************************************/ + +void CopyMemory(void *dst, const void *first, int size) { + Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst); +} + + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index 6fd55e7ce5..8d8411c6a1 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -79,6 +79,9 @@ public: #define GMEM_MOVEABLE 2 #define GMEM_ZEROINIT 4 +// Stand-alone methods +extern void CopyMemory(void *dst, const void *first, int size); + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 854372cdda..6ec92e74c1 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -55,7 +55,6 @@ #include "tony/mpal/lzo.h" #include "tony/mpal/mpal.h" #include "tony/mpal/mpaldll.h" -#include "tony/mpal/stubs.h" namespace Tony { diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index a7b6dfc5aa..69e58720a4 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -52,7 +52,6 @@ #include "common/file.h" #include "tony/mpal/memory.h" -#include "tony/mpal/stubs.h" #include "tony/mpal/loadmpc.h" #include "tony/mpal/expr.h" diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index cb8d4ec97d..a9f8403fcd 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -25,8 +25,7 @@ #define TONY_MPAL_MPALUTILS #include "common/scummsys.h" -#include "memory.h" -#include "stubs.h" +#include "tony/mpal/memory.h" namespace Tony { diff --git a/engines/tony/mpal/stubs.cpp b/engines/tony/mpal/stubs.cpp deleted file mode 100644 index 89740fdd52..0000000000 --- a/engines/tony/mpal/stubs.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * - */ - -/****************************************************************************\ -* This file contains stubs and mappings for things used by the MPAL -* library that are handled differently under ScummVM -\****************************************************************************/ - -#include "common/algorithm.h" -#include "common/system.h" -#include "engines/engine.h" -#include "tony/tony.h" -#include "stubs.h" - -namespace Tony { - -namespace MPAL { - -uint16 GetAsyncKeyState(Common::KeyCode kc) { - return 0; -} - -void CopyMemory(void *dst, const void *first, int size) { - Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst); -} - -} // end of namespace MPAL - -} // end of namespace Tony diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h deleted file mode 100644 index 66f83997ae..0000000000 --- a/engines/tony/mpal/stubs.h +++ /dev/null @@ -1,66 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * - */ - -/****************************************************************************\ -* This file contains stubs and mappings for things used by the MPAL -* library that are handled differently under ScummVM -\****************************************************************************/ - -#ifndef MPAL_STUBS -#define MPAL_STUBS - -#include "common/scummsys.h" -#include "common/algorithm.h" -#include "common/keyboard.h" -#include "tony/mpal/memory.h" - -namespace Tony { - -namespace MPAL { - -/****************************************************************************\ -* Types -\****************************************************************************/ - -typedef uint32 (*LPTHREAD_START_ROUTINE)(void *lpThreadParameter); -typedef void (*LPTHREAD_ROUTINE)(void *lpThreadParameter); - -/****************************************************************************\ -* Defines -\****************************************************************************/ - -#define MB_OK 1 - -/****************************************************************************\ -* Methods -\****************************************************************************/ - -extern void CopyMemory(void *dst, const void *first, int size); - -extern uint16 GetAsyncKeyState(Common::KeyCode kc); - -} // end of namespace MPAL - -} // end of namespace Tony - -#endif -- cgit v1.2.3 From 827454a87ee73b079a96fbd4bd0df3b43224eb06 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 19 May 2012 11:05:57 +0200 Subject: TONY: Change "it's" to "its" in comments where appropriate. (I think.) --- engines/tony/mpal/loadmpc.cpp | 8 ++++---- engines/tony/mpal/memory.cpp | 4 ++-- engines/tony/mpal/mpal.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 6a1213bc19..6329a2090a 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -77,7 +77,7 @@ static bool CompareCommands(struct command *cmd1, struct command *cmd2) { /** - * Parses a script from the MPC file, and inserts it's data into a structure + * Parses a script from the MPC file, and inserts its data into a structure * * @param lpBuf Buffer containing the compiled script. * @param lpmsScript Pointer to a structure that will be filled with the @@ -138,7 +138,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { /** - * Parses a dialog from the MPC file, and inserts it's data into a structure + * Parses a dialog from the MPC file, and inserts its data into a structure * * @param lpBuf Buffer containing the compiled dialog. * @param lpmdDialog Pointer to a structure that will be filled with the @@ -303,7 +303,7 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { /** - * Parses an item from the MPC file, and inserts it's data into a structure + * Parses an item from the MPC file, and inserts its data into a structure * * @param lpBuf Buffer containing the compiled dialog. * @param lpmiItem Pointer to a structure that will be filled with the @@ -425,7 +425,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { /** - * Parses a location from the MPC file, and inserts it's data into a structure + * Parses a location from the MPC file, and inserts its data into a structure * * @param lpBuf Buffer containing the compiled location. * @param lpmiLocation Pointer to a structure that will be filled with the diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 4410e8016c..04cb906431 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -91,7 +91,7 @@ MemoryItem &MemoryManager::allocate(uint32 size, uint flags) { } /** - * Allocates a new memory block and returns it's data pointer + * Allocates a new memory block and returns its data pointer * @returns Data pointer to allocated block */ HGLOBAL MemoryManager::alloc(uint32 size, uint flags) { @@ -123,7 +123,7 @@ MemoryItem &MemoryManager::operator[](HGLOBAL handle) { } /** - * Returns a size of a memory block given it's pointer + * Returns a size of a memory block given its pointer */ uint32 MemoryManager::getSize(HGLOBAL handle) { MemoryItem &item = getItem(handle); diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 6ec92e74c1..aea441138b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1312,7 +1312,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { * @param dwParam Any parameter for the action. * @returns Id of the process that was launched to perform the action, or * CORO_INVALID_PID_VALUE if the action was not defined, or the item was inactive. - * @remarks You can get the index of an item from it's number by using + * @remarks You can get the index of an item from its number by using * the itemGetOrderFromNum() function. The items list must first be locked * by calling LockItem(). */ -- cgit v1.2.3 From a4a02e15b594e768b73a781823c38234f9f9cf7d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 19:43:30 +1000 Subject: TONY: Converting Italian comments to English --- engines/tony/mpal/mpal.cpp | 212 +++++++++++++++++----------------------- engines/tony/mpal/mpaldll.h | 232 ++++++++++++++++++-------------------------- 2 files changed, 188 insertions(+), 256 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index aea441138b..358b4e3505 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -370,10 +370,10 @@ static char *DuplicateDialogPeriod(uint32 nPeriod) { for (j = 0; dialog->Periods[j] != NULL; j++) if (dialog->PeriodNums[j] == nPeriod) { - /* Trovata la frase, va duplicata */ + /* Found the phrase, it should be duplicated */ origmsg = (const char *)GlobalLock(dialog->Periods[j]); - /* Calcola la lunghezza e alloca la memoria */ + /* Calculate the length and allocate memory */ i = 0; while (origmsg[i] != '\0') i++; @@ -448,13 +448,13 @@ static uint32 *GetSelectList(uint32 i) { int j,k,num; LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; - /* Conta quanti select attivi ci sono */ + /* Count how many are active selects */ num = 0; for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) if (dialog->Choice[i].Select[j].curActive) num++; - /* Se sono 0, e' un errore */ + /* If there are 0, it's a mistake */ if (num == 0) return NULL; @@ -462,7 +462,7 @@ static uint32 *GetSelectList(uint32 i) { if (sl == NULL) return NULL; - /* Copia il dato di ogni select attivo dentro la lista */ + /* Copy all the data inside the active select list */ k = 0; for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) if (dialog->Choice[i].Select[j].curActive) @@ -509,7 +509,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { char *patlength; uint32 dim; - // Lo zeroinit e' obbligatorio!!!! + // Zeroing out the allocated memory is required!!! ret = (LPITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); if (ret == NULL) return NULL; @@ -519,16 +519,16 @@ static LPITEM GetItemData(uint32 nOrdItem) { dat = (char *)GlobalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { - i = dat[3]; // Versione!! Per ora 1.0 + i = dat[3]; // For version 1.0!! dat += 4; - if (i >= 0x10) { // Dalla 1.0 c'e' il punto di destinazione per ogni oggetto + if (i >= 0x10) { // From 1.0, there's a destination point for each object ret->destX = (int16)READ_LE_UINT16(dat); ret->destY = (int16)READ_LE_UINT16(dat + 2); dat+=4; } - if (i >= 0x11) {// Dalla 1.1 c'e' la velocita' di animazione + if (i >= 0x11) { // From 1.1, there's animation speed ret->speed = READ_LE_UINT16(dat); dat += 2; } else @@ -539,21 +539,21 @@ static LPITEM GetItemData(uint32 nOrdItem) { ret->numpattern=*dat++; ret->Zvalue=*dat++; - // Carica le coordinate left&top di ogni frame + // Upload the left & top co-ordinates of each frame for (i = 0; i < ret->numframe; i++) { ret->frameslocations[i].left = (int16)READ_LE_UINT16(dat); ret->frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); dat += 4; } - // Carica le dimensioni di ogni frame e calcola right&bottom + // Upload the size of each frame and calculate the right & bottom for (i = 0; i < ret->numframe; i++) { ret->frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->frameslocations[i].left; ret->frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->frameslocations[i].top; dat+=4; } - // Carica i bounding box di ogni frame + // Upload the bounding boxes of each frame for (i = 0; i < ret->numframe; i++) { ret->bbox[i].left = (int16)READ_LE_UINT16(dat); ret->bbox[i].top = (int16)READ_LE_UINT16(dat + 2); @@ -562,7 +562,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { dat+=8; } - // Carica i pattern di animazione + // Load the animation pattern patlength = dat; dat+=ret->numpattern; @@ -573,7 +573,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { dat += patlength[i]; } - // Carica i singoli frame di animazione + // Upload the individual frames of animations for (i = 1; i < ret->numframe; i++) { dim=(uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); @@ -585,7 +585,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { dat += dim; } - // Controlla se siamo arrivati fino alla fine del file + // Check if we've got to the end of the file i = READ_LE_UINT16(dat); if (i != 0xABCD) return NULL; @@ -678,7 +678,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->p->arg3=s->Command[_ctx->k].arg3; _ctx->p->arg4=s->Command[_ctx->k].arg4; - // !!! Nuova gestione dei thread + // !!! New process management if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { GLOBALS.mpalError = 1; @@ -845,16 +845,14 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - /* Tanto per cominciare, e' necessario richiedere la lista degli item - presenti nella locazione. */ + /* To begin with, we need to request the item list from the location */ _ctx->il = mpalQueryItemList(GLOBALS.nPollingLocations[id]); - /* Contiamo gli items */ + /* Count the items */ for (_ctx->numitems = 0; _ctx->il[_ctx->numitems] != 0; _ctx->numitems++) ; - /* Cerchiamo gli items della locazione senza idle actions e li eliminiamo - dalla lista */ + /* We look for items without idle actions, and eliminate them from the list */ LockItems(); _ctx->nIdleActions = 0; _ctx->nRealItems = 0; @@ -873,7 +871,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->nIdleActions += _ctx->k; if (_ctx->k == 0) - /* Possiamo eliminare questo item dalla lista */ + /* We can remove this item from the list */ _ctx->il[_ctx->i] = (uint32)NULL; else _ctx->nRealItems++; @@ -894,13 +892,9 @@ void LocationPollThread(CORO_PARAM, const void *param) { return; } - /* Inizializziamo le routine random */ - //curTime = _vm->GetTime(); - //srand(curTime); - - /* Abbiamo appurato che esiste almeno un item che contiene idle actions. - Ora creaiamo le copie speculari delle idle actions */ + /* We have established that there is at least one item that contains idle actions. + Now we created the mirrored copies of the idle actions. */ _ctx->MyActions = (MYACTION *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); if (_ctx->MyActions == NULL) { GlobalFree(_ctx->MyThreads); @@ -937,11 +931,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { UnlockItems(); - /* La item list non ci serve piu' */ + /* We don't need the item list anymore */ GlobalFree(_ctx->il); - /* Eccoci al ciclo principale. */ + /* Here's the main loop */ while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ @@ -955,9 +949,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } else _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); - /* Ci addormentiamo, ma controllando sempre l'evento che viene settato - quando viene richiesta la nostra chiusura */ - + /* We fall alseep, but always checking that the event is set when prompted for closure */ CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS.hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); //if (_ctx->k == WAIT_OBJECT_0) @@ -968,28 +960,26 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->MyThreads[_ctx->i].nItem != 0) { CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); - // if result ) == WAIT_OBJECT_0) + // if result == WAIT_OBJECT_0) if (!_ctx->delayExpired) _ctx->MyThreads[_ctx->i].nItem = 0; } _ctx->curTime = _vm->GetTime(); - /* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */ + /* Loop through all the necessary idle actions */ for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; - /* E' _ctx->il momento di tirare _ctx->il nostro dado virtuale, e controllare - se la sorte e' dalla parte della idle action */ + /* It's time to check to see if fortune is on the side of the idle action */ byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); if (randomVal < _ctx->MyActions[_ctx->k].perc) { - /* Controlliamo se c'e' una action in esecuzione sull'item */ + /* Check if there is an action running on the item */ if ((GLOBALS.bExecutingAction) && (GLOBALS.nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) continue; - /* Controlliamo se c'e' gia' un'altra idle function in esecuzione - sullo stesso item */ + /* Check to see if there already another idle funning running on the item */ for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem == _ctx->MyActions[_ctx->k].nItem) break; @@ -997,11 +987,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->i < _ctx->nRealItems) continue; - /* Ok, siamo gli unici :) */ + /* Ok, we are the only ones :) */ LockItems(); _ctx->curItem=GLOBALS.lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); - /* Controlliamo se c'e' un esperessione WhenExecute */ + /* Check if there is a WhenExecute expression */ _ctx->j=_ctx->MyActions[_ctx->k].nAction; if (_ctx->curItem->Action[_ctx->j].when != NULL) if (!EvaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { @@ -1009,8 +999,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { continue; } - /* Ok, possiamo eseguire la azione. Per comodita' lo facciamo in - un nuovo thread */ + /* Ok, we can perform the action. For convenience, we do it in a new process */ _ctx->newItem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (_ctx->newItem == false) { GlobalFree(_ctx->MyThreads); @@ -1023,21 +1012,20 @@ void LocationPollThread(CORO_PARAM, const void *param) { CopyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); UnlockItems(); - /* Copiamo l'azione nella #0 */ + /* We copy the action in #0 */ // _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; // CopyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); _ctx->newItem->dwRes=_ctx->j; - /* Creaiamo l'action thread. Provvedera' lui a liberare la memoria - allocata per _ctx->il nuovo item */ + /* We will create an action, and will provide the necessary details */ for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem == 0) break; _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; - // !!! Nuova gestione dei thread - if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == 0) { + // Create the process + if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) { //if ((_ctx->MyThreads[_ctx->i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))==(void*)-1) GlobalFree(_ctx->newItem); GlobalFree(_ctx->MyThreads); @@ -1047,23 +1035,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { return; } - /* Skippa tutte le idle action dello stesso item */ + /* Skip all idle actions of the same item */ } } } - /* Chiude tutti _ctx->i thread interni */ - - /* - - CODICE OBSOLETO: ANDIAMO DI SKIP CHE RULLA - - for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) - if (_ctx->MyThreads[_ctx->i].nItem != 0) { - TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); - CloseHandle(_ctx->MyThreads[_ctx->i].hThread); - } -*/ // Set idle skip on CORO_INVOKE_4(GLOBALS.lplpFunctions[200], 0, 0, 0, 0); @@ -1083,7 +1059,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Set idle skip off CORO_INVOKE_4(GLOBALS.lplpFunctions[201], 0, 0, 0, 0); - /* Abbiamo finito */ + /* We're finished */ GlobalFree(_ctx->MyThreads); GlobalFree(_ctx->MyActions); @@ -1218,20 +1194,20 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CODE(_ctx); - /* Locka _ctx->i dialoghi */ + /* Lock the dialogs */ LockDialogs(); - /* Trova il puntatore al dialogo corrente */ - _ctx->dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; + /* Get a pointer to the current dialog */ + _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; - /* Cerca la scelta richiesta tra quelle nel dialogo */ + /* Search the choice between those required in the dialog */ for (_ctx->i = 0; _ctx->dialog->Choice[_ctx->i].nChoice != 0; _ctx->i++) if (_ctx->dialog->Choice[_ctx->i].nChoice == nChoice) break; - /* Se non l'ha trovata, esce con errore */ + /* If nothing has been found, exit with an error */ if (_ctx->dialog->Choice[_ctx->i].nChoice == 0) { - /* Se siamo qui, non abbiamo trovato la choice richiesta */ + /* If we're here, we did not find the required choice */ GLOBALS.mpalError = 1; UnlockDialogs(); @@ -1239,16 +1215,14 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { return; } - /* Abbiamo trova la choice richiesta. Ricordiamoci qual e' nella - variabile globale */ + /* We've found the requested choice. Remember what in global variables */ GLOBALS.nExecutingChoice = _ctx->i; while (1) { GLOBALS.nExecutingChoice = _ctx->i; _ctx->k = 0; - /* Calcoliamo le when expression di ciascun select, per vedere se sono - attivi o disattivi */ + /* Calculate the expression of each selection, to see if they're active or inactive */ for (_ctx->j = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].dwData != 0; _ctx->j++) if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].when == NULL) { _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 1; @@ -1259,42 +1233,41 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { } else _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 0; - /* Se non ci sono scelte attivate, la scelta e' finita */ + /* If there are no choices activated, then the dialog is finished. */ if (_ctx->k == 0) { UnlockDialogs(); break; } - /* Avvertiamo il gioco che c'e' una scelta da far fare all'utente, - e restiamo in attesa della risposta */ + /* There are choices available to the user, so wait for them to make one */ CoroScheduler.resetEvent(GLOBALS.hDoneChoice); CoroScheduler.setEvent(GLOBALS.hAskChoice); CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.hDoneChoice, CORO_INFINITE); - /* Ora che la scelta e' stata effettuata, possiamo eseguire _ctx->i gruppi - associati con la scelta */ + /* Now that the choice has been made, we can run the groups associated with the choice tbontbtitq + */ _ctx->j = GLOBALS.nSelectedChoice; for (_ctx->k = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { _ctx->nGroup = _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); } - /* Controllo sugli attributi */ + /* Control attribute */ if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 0)) { - /* Bit 0 settato: fine della scelta */ + /* Bit 0 set: the end of the choice */ UnlockDialogs(); break; } if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 1)) { - /* Bit 1 settato: fine del dialogo */ + /* Bit 1 set: the end of the dialog */ UnlockDialogs(); CORO_KILL_SELF(); return; } - /* Fine della scelta senza attributi: bisogna rifarla */ + /* End of choic ewithout attributes. We must do it again */ } // If we're here, we found an end choice. Return to the caller group @@ -1339,23 +1312,23 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { continue; } - // Ora abbiamo trova l'azione giusta che deve essere eseguita. - // Duplichiamo l'item corrente e copiamo la azione #i nella #0 + // Now we find the right action to be performed + // Duplicate the item and copy the current action in #i into #0 newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (newitem == NULL) return CORO_INVALID_PID_VALUE; - // Nella nuova versione scriviamo il numero dell'azione in dwRes + // In the new version number of the action in writing dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); /* newitem->Action[0].nCmds=item->Action[i].nCmds; CopyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); */ newitem->dwRes = i; - // E finalmente possiamo richiamare il thread, che eseguira' l'azione - // 0 dell'item, e poi liberera' la memoria con la GlobalFree() + // And finally we can laucnh the process that will execute the action, + // and a second process to free up the memory when the action is finished. - // !!! New thread management + // !!! New process management if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; @@ -1420,7 +1393,7 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { * @returns True if everything is OK, false on failure */ bool DoSelection(uint32 i, uint32 dwData) { - LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; + LPMPALDIALOG dialog = GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; int j; for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) @@ -1461,15 +1434,15 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, //printf("Script: %lu\n", sizeof(MPALSCRIPT)); //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); - /* Si salva l'array delle funzioni custom */ + /* Save the array of custom functions */ GLOBALS.lplpFunctions = lplpcfArray; GLOBALS.lplpFunctionStrings = lpcfStrings; - /* Apre il file MPC in lettura */ + /* OPen the MPC file for reading */ if (!hMpc.open(lpszMpcFileName)) return false; - /* Legge e controlla l'header */ + /* Read and check the header */ nBytesRead = hMpc.read(buf, 5); if (nBytesRead != 5) return false; @@ -1479,7 +1452,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, bCompress = buf[4]; - /* Legge la dimensione del file decompresso, e alloca la memoria */ + /* Reads the size of the uncompressed file, and allocate memory */ dwSizeDecomp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1489,8 +1462,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, return false; if (bCompress) { - /* Se il file e' compresso, guarda quanto e' grande e alloca la - memoria temporanea per la decompressione */ + /* Get the compressed size and read the data in */ dwSizeComp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1503,30 +1475,29 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != dwSizeComp) return false; - /* Decomprime l'immagine */ + /* Decompress the data */ lzo1x_decompress(cmpbuf, dwSizeComp, lpMpcImage, &nBytesRead); if (nBytesRead != dwSizeDecomp) return false; GlobalFree(cmpbuf); } else { - /* Se il file non e' compresso, lo legge all'interno della memoria gia' - allocata */ + /* If the file is not compressed, we directly read in the data */ nBytesRead = hMpc.read(lpMpcImage, dwSizeDecomp); if (nBytesRead != dwSizeDecomp) return false; } - /* Chiude il file */ + /* Close the file */ hMpc.close(); - /* Parsa l'immagine */ + /* Process the data */ if (ParseMpc(lpMpcImage) == false) return false; GlobalFree(lpMpcImage); - /* Calcola utilizzo di memoria */ + /* Calculate memory usage */ /* { char errbuf[256]; @@ -1541,11 +1512,11 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, } */ - /* Apre il file MPR in lettura */ + /* Open the MPR file */ if (!GLOBALS.hMpr.open(lpszMprFileName)) return false; - /* Si posiziona a 8 byte dalla fine del file */ + /* Seek to the end of the file to read overall information */ GLOBALS.hMpr.seek(-12, SEEK_END); dwSizeComp = GLOBALS.hMpr.readUint32LE(); @@ -1563,7 +1534,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (buf[0] !='E' || buf[1] != 'N' || buf[2] != 'D' || buf[3] != '0') return false; - /* Si posiziona all'inizio dell'header delle risorse */ + /* Move to the start of the resources header */ GLOBALS.hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); GLOBALS.lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS.nResources * 8); @@ -1584,18 +1555,17 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, GlobalFree(cmpbuf); - /* Si riposiziona all'inizio lasciando il file di risorse aperto */ + /* Reset back to the start of the file, leaving it open */ GLOBALS.hMpr.seek(0, SEEK_SET); - /* Non c'e' nessuna azione ne' dialogo in esecuzione */ + /* There is no action or dialog running by default */ GLOBALS.bExecutingAction = false; GLOBALS.bExecutingDialog = false; - /* Non c'e' nessuna locazione in polling */ + /* There's no polling location */ Common::fill(GLOBALS.nPollingLocations, GLOBALS.nPollingLocations + MAXPOLLINGLOCATIONS, 0); - /* Crea l'evento che verra' utilizzato per avvertire il gioco che c'e' - da effettuare una scelta */ + /* Create the event that will be used to co-ordinate making choices and choices finishing */ GLOBALS.hAskChoice = CoroScheduler.createEvent(true, false); GLOBALS.hDoneChoice = CoroScheduler.createEvent(true, false); @@ -2030,7 +2000,7 @@ bool mpalExecuteScript(int nScript) { CopyMemory(s, GLOBALS.lpmsScripts + n, sizeof(MPALSCRIPT)); UnlockScripts(); - // !!! Nuova gestione dei thread + // !!! New process management if (CoroScheduler.createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == CORO_INVALID_PID_VALUE) return false; @@ -2070,7 +2040,7 @@ bool mpalStartIdlePoll(int nLoc) { GLOBALS.nPollingLocations[i] = nLoc; GLOBALS.hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); -// !!! Nuova gestione dei thread +// !!! New process management if ((GLOBALS.PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) // if ((GLOBALS.hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) return false; @@ -2150,7 +2120,7 @@ void mpalSaveState(byte *buf) { * @returns Length of the state buffer in bytes */ int mpalLoadState(byte *buf) { - // Dobbiamo distruggere tutte le variabili e ricrearle + // We must destroy and recreate all the variables GlobalFree(GLOBALS.hVars); GLOBALS.nVars = READ_LE_UINT32(buf); @@ -2325,20 +2295,20 @@ void mpalDumpMessages(void) { OutputStartMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); while (1) { - // Trova la fine del periodo corrente + // Find the end of the current period while (*p != '\0') p++; - // Se c'e' un altro '\0' siamo alla fine del messaggio + // If there is another '\0' at the end of the message, then finish p++; if (*p == '\0') break; - // Altrimenti c'e' un altro periodo, e ci ricordiamo il suo inizio + // Otherwise there is another line, so remember the next one's start lpPeriods[nPeriods++] = p; } - // Ora fa un ciclo su tutti i periodi + // Now make a loop over all the periods for (j = 0;jGroup[g].nCmds; c++) { curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; - // Se è una funzione custom, e richiama la SendDialogMessage(nPers, nMsg) + // If it's a custom function, call SendDialogMessage(nPers, nMsg) if (curCmd->type == 1 && curCmd->nCf == 71) { sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->arg2); diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 69e58720a4..dc42b597bc 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -66,7 +66,7 @@ namespace MPAL { #define HEX_VERSION 0x0170 /* - SICURA + Safe #define MAX_ACTIONS_PER_ITEM 40 #define MAX_COMMANDS_PER_ITEM 256 @@ -90,7 +90,7 @@ namespace MPAL { /* - Versione sicura! + Secure version! #define MAX_GROUPS_PER_DIALOG 128 #define MAX_COMMANDS_PER_DIALOG 640 @@ -111,7 +111,7 @@ namespace MPAL { #define MAX_PERIODS_PER_DIALOG 400 /* - Prima di Rufus: + Before Rufus: #define MAX_GROUPS_PER_DIALOG 128 #define MAX_COMMANDS_PER_DIALOG 512 @@ -131,90 +131,75 @@ namespace MPAL { #include "common/pack-start.h" -/****************************************************************************\ -* typedef MPALVAR -* --------------- -* Description: Variabile globale di MPAL -\****************************************************************************/ - +/** + * MPAL global variables + */ struct MPALVAR { - uint32 dwVal; // Valore della variabile - char lpszVarName[33]; // Nome della variabile + uint32 dwVal; // Variable value + char lpszVarName[33]; // Variable name } PACKED_STRUCT; -typedef MPALVAR* LPMPALVAR; -typedef LPMPALVAR* LPLPMPALVAR; - +typedef MPALVAR *LPMPALVAR; +typedef LPMPALVAR *LPLPMPALVAR; -/****************************************************************************\ -* typedef MPALMSG -* --------------- -* Description: Messaggio di MPAL -\****************************************************************************/ +/** + * MPAL Messages + */ struct MPALMSG { - HGLOBAL hText; // Handle al testo del messaggio - uint16 wNum; // Numero del messaggio + HGLOBAL hText; // Handle to the message text + uint16 wNum; // Message number } PACKED_STRUCT; -typedef MPALMSG* LPMPALMSG; -typedef LPMPALMSG* LPLPMPALMSG; +typedef MPALMSG *LPMPALMSG; +typedef LPMPALMSG *LPLPMPALMSG; -/****************************************************************************\ -* typedef MPALLOCATION -* -------------------- -* Description: Locazione di MPAL -\****************************************************************************/ - +/** + * MPAL Locations + */ struct MPALLOCATION { - uint32 nObj; // Numero della locazione - uint32 dwXlen, dwYlen; // Dimensione - uint32 dwPicRes; // Risorsa che contiene l'immagine + uint32 nObj; // Location number + uint32 dwXlen, dwYlen; // Dimensions + uint32 dwPicRes; // Resource that contains the image } PACKED_STRUCT; -typedef MPALLOCATION* LPMPALLOCATION; -typedef LPMPALLOCATION* LPLPMPALLOCATION; - +typedef MPALLOCATION *LPMPALLOCATION; +typedef LPMPALLOCATION *LPLPMPALLOCATION; -/****************************************************************************\ -* struct command -* -------------- -* Description: Gestisce un comando, cioe' le tag utilizzate dalle OnAction -* negli item, dalle Time negli script e dai Group nei Dialog -\****************************************************************************/ +/** + * All the data for a command, ie. tags used by OnAction in the item, the time + * in the script, and in the group dialog. + */ struct command { /* - * Tipi di comandi riconosciuti: + * Types of commands that are recognised * - * #1 -> Chiamata a funzione custom (ITEM, SCRIPT, DIALOG) - * #2 -> Assegnazione di variabile (ITEM, SCRIPT, DIALOG) - * #3 -> Esecuzione di una scelta (DIALOG) + * #1 -> Custom function call (ITEM, SCRIPT, DIALOG) + * #2 -> Variable assignment (ITEM, SCRIPT, DIALOG) + * #3 -> Making a choice (DIALOG) * */ - byte type; // Tipo di comando + byte type; // Type of control union { - int32 nCf; // Numero funzione custom [#1] - char *lpszVarName; // Nome variabile [#2] - int32 nChoice; // Numero di scelta da fare [#3] + int32 nCf; // Custom function call [#1] + char *lpszVarName; // Variable name [#2] + int32 nChoice; // Number of choice you make [#3] }; union { - int32 arg1; // Argomento 1 funzione custom [#1] - HGLOBAL expr; // Espressione da assegnare alla - // variabile [#2] + int32 arg1; // Argument for custom function [#1] + HGLOBAL expr; // Expression to assign to a variable [#2] }; - int32 arg2,arg3,arg4; // Argomenti per funzione custom [#1] + int32 arg2, arg3, arg4; // Arguments for custom function [#1] } PACKED_STRUCT; -/****************************************************************************\ -* typedef MPALDIALOG -* ------------------ -* Description: Dialog di MPAL -\****************************************************************************/ +/** + * MPAL dialog + */ struct MPALDIALOG { - uint32 nObj; // Numero dialog + uint32 nObj; // Dialog number struct command Command[MAX_COMMANDS_PER_DIALOG]; @@ -227,11 +212,10 @@ struct MPALDIALOG { } Group[MAX_GROUPS_PER_DIALOG]; struct { - // L'ultima choice ha nChoice==0 + // The last choice has nChoice == 0 uint16 nChoice; - // Non c'e' il numero di Select (siamo abbastanza avari di RAM). L'ultimo - // select ha dwData==0 + // The select number (we're pretty stingy with RAM). The last select has dwData == 0 struct { HGLOBAL when; uint32 dwData; @@ -240,8 +224,8 @@ struct MPALDIALOG { // Bit 0=endchoice Bit 1=enddialog byte attr; - // Modificata a run-time: 0 se il select e' correntemente disabilitato, - // 1 se e' correntemente attivato + // Modified at run-time: 0 if the select is currently disabled, + // and 1 if currently active byte curActive; } Select[MAX_SELECTS_PER_CHOICE]; @@ -251,50 +235,48 @@ struct MPALDIALOG { HGLOBAL Periods[MAX_PERIODS_PER_DIALOG]; } PACKED_STRUCT; -typedef MPALDIALOG* LPMPALDIALOG; -typedef LPMPALDIALOG* LPLPMPALDIALOG; +typedef MPALDIALOG *LPMPALDIALOG; +typedef LPMPALDIALOG *LPLPMPALDIALOG; -/****************************************************************************\ -* typedef MPALITEM -* ---------------- -* Description: Item di MPAL -\****************************************************************************/ +/** + * MPAL Item + */ struct ItemAction { - byte num; // Numero dell'azione - uint16 wTime; // In caso di idle, il tempo che deve passare - byte perc; // Percentuale di eseguire l'idle - HGLOBAL when; // Espressione da calcolare: se !=0, allora - // l'azione puo' essere eseguita - uint16 wParm; // Parametro per l'azione - - byte nCmds; // Numero comandi da eseguire - uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Comando da eseguire + byte num; // Action number + uint16 wTime; // If idle, the time which must pass + byte perc; // Percentage of the idle run + HGLOBAL when; // Expression to compute. If != 0, then + // action can be done + uint16 wParm; // Parameter for action + + byte nCmds; // Number of commands to be executed + uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Commands to execute } PACKED_STRUCT; struct MPALITEM { - uint32 nObj; // Numero item + uint32 nObj; // Item number - byte lpszDescribe[MAX_DESCRIBE_SIZE]; // Nome - byte nActions; // Numero delle azioni gestite - uint32 dwRes; // Risorsa che contiene frame e pattern + byte lpszDescribe[MAX_DESCRIBE_SIZE]; // Name + byte nActions; // Number of managed actions + uint32 dwRes; // Resource that contains frames and patterns struct command Command[MAX_COMMANDS_PER_ITEM]; - // Array di strutture contenenti le varie azioni gestite. In pratica, di - // ogni azione sappiamo quali comandi eseguire, tra quelli definiti nella - // struttura qui sopra + // Array of structures containing various managed activities. In practice, of + // every action we know what commands to run, including those defined in + // structures above /* struct { - byte num; // Numero dell'azione - uint16 wTime; // In caso di idle, il tempo che deve passare - byte perc; // Percentuale di eseguire l'idle - HGLOBAL when; // Espressione da calcolare: se !=0, allora - // l'azione puo' essere eseguita - uint16 wParm; // Parametro per l'azione - - byte nCmds; // Numero comandi da eseguire + byte num; // Numero dell'azione + uint16 wTime; // In caso di idle, il tempo che deve passare + byte perc; // Percentuale di eseguire l'idle + HGLOBAL when; // Espressione da calcolare: se !=0, allora + // l'azione puo' essere eseguita + uint16 wParm; // Parametro per l'azione + + byte nCmds; // Numero comandi da eseguire uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Comando da eseguire } Action[MAX_ACTIONS_PER_ITEM]; @@ -306,12 +288,9 @@ typedef MPALITEM* LPMPALITEM; typedef LPMPALITEM* LPLPMPALITEM; -/****************************************************************************\ -* typedef MPALSCRIPT -* ------------------ -* Description: Script di MPAL -\****************************************************************************/ - +/** + * MPAL Script + */ struct MPALSCRIPT { uint32 nObj; @@ -335,44 +314,27 @@ typedef LPMPALSCRIPT* LPLPMPALSCRIPT; /****************************************************************************\ -* Prototipi di funzione -\****************************************************************************/ - -/****************************************************************************\ -* -* Function: int32 varGetValue(const char *lpszVarName); -* -* Description: Restituisce il valore corrente di una variabile globale -* -* Input: const char *lpszVarName Nome della variabile -* -* Return: Valore corrente -* -* Note: Prima di questa funzione, bisogna richiamare LockVar() che -* locka le variabili globali per l'utilizzo. Dopo inoltre bi- -* sogna ricordarsi di chiamare UnlockVar() -* +* Function prototypes \****************************************************************************/ -int32 varGetValue(const char *lpszVarName); - - -/****************************************************************************\ -* -* Function: void varSetValue(const char *lpszVarName, int32 val); -* -* Description: Setta un nuovo valore per una variabile globale di MPAL -* -* Input: const char *lpszVarName Nome della variabile -* int32 val Valore da settare -* -\****************************************************************************/ +/** + * Returns the current value of a global variable + * + * @param lpszVarName Name of the variable + * @returns Current value + * @remarks Before using this method, you must call LockVar() to + * lock the global variablves for use. Then afterwards, you will + * need to remember to call UnlockVar() + */ +extern int32 varGetValue(const char *lpszVarName); -void varSetValue(const char *lpszVarName, int32 val); -/****************************************************************************\ -* Includes the various modules -\****************************************************************************/ +/** + * Sets the value of a MPAL global variable + * @param lpszVarName Name of the variable + * @param val Value to set + */ +extern void varSetValue(const char *lpszVarName, int32 val); } // end of namespace MPAL -- cgit v1.2.3 From f3398ee0104622a7ab0598507894c9d74a7a30e2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 19:54:04 +1000 Subject: TONY: Formatting fixes --- engines/tony/mpal/mpal.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 358b4e3505..d74248911e 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -67,11 +67,11 @@ namespace MPAL { \****************************************************************************/ const char *mpalCopyright = - "\n\nMPAL - MultiPurpose Adventure Language for Windows 95\n" - "Copyright 1997-98 Giovanni Bajo and Luca Giusti\n" - "ALL RIGHTS RESERVED\n" - "\n" - "\n"; + "\n\nMPAL - MultiPurpose Adventure Language for Windows 95\n" + "Copyright 1997-98 Giovanni Bajo and Luca Giusti\n" + "ALL RIGHTS RESERVED\n" + "\n" + "\n"; /****************************************************************************\ * Internal functions @@ -344,7 +344,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { j++; j += 2; - clonemsg=(char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, j); + clonemsg = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, j); if (clonemsg == NULL) return NULL; @@ -483,7 +483,7 @@ static uint32 *GetItemList(uint32 nLoc) { num++; } - il=(uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + il = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); if (il == NULL) return NULL; @@ -569,15 +569,15 @@ static LPITEM GetItemData(uint32 nOrdItem) { for (i = 1; i < ret->numpattern; i++) { for (j = 0; j < patlength[i]; j++) ret->pattern[i][j] = dat[j]; - ret->pattern[i][(int)patlength[i]] = 255; // Termina i pattern + ret->pattern[i][(int)patlength[i]] = 255; // Terminate pattern dat += patlength[i]; } // Upload the individual frames of animations for (i = 1; i < ret->numframe; i++) { - dim=(uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * + dim = (uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); - ret->frames[i]=(char *)GlobalAlloc(GMEM_FIXED,dim); + ret->frames[i] = (char *)GlobalAlloc(GMEM_FIXED,dim); if (ret->frames[i] == NULL) return NULL; @@ -664,7 +664,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j]; if (s->Command[_ctx->k].type == 1) { - _ctx->p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); + _ctx->p = (LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) { GLOBALS.mpalError = 1; @@ -1026,7 +1026,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Create the process if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) { - //if ((_ctx->MyThreads[_ctx->i].hThread=(void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))==(void*)-1) + //if ((_ctx->MyThreads[_ctx->i].hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))= = (void*)-1) GlobalFree(_ctx->newItem); GlobalFree(_ctx->MyThreads); GlobalFree(_ctx->MyActions); @@ -1457,7 +1457,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (hMpc.err()) return false; - byte *lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeDecomp+16); + byte *lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED, dwSizeDecomp + 16); if (lpMpcImage == NULL) return false; @@ -1467,7 +1467,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (hMpc.err()) return false; - cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED,dwSizeComp); + cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED, dwSizeComp); if (cmpbuf == NULL) return false; @@ -1550,7 +1550,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, return false; lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)GLOBALS.lpResources, (uint32 *)&nBytesRead); - if (nBytesRead != (uint32)GLOBALS.nResources*8) + if (nBytesRead != (uint32)GLOBALS.nResources * 8) return false; GlobalFree(cmpbuf); @@ -2042,7 +2042,7 @@ bool mpalStartIdlePoll(int nLoc) { GLOBALS.hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); // !!! New process management if ((GLOBALS.PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) -// if ((GLOBALS.hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) +// if ((GLOBALS.hEndPollingLocations[i] = (void*)_beginthread(LocationPollThread, 10240,(void *)i))= = (void*)-1) return false; return true; @@ -2130,7 +2130,7 @@ int mpalLoadState(byte *buf) { CopyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); UnlockVar(); - return GLOBALS.nVars*sizeof(MPALVAR)+4; + return GLOBALS.nVars * sizeof(MPALVAR) + 4; } bool bDontOutput; -- cgit v1.2.3 From c402426117e83fa833fdadcc6ad81f418d195c7e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 19 May 2012 20:29:53 +1000 Subject: TONY: Converted some warning calls to debugC --- engines/tony/mpal/mpal.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index d74248911e..5cb6546343 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -645,7 +645,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->dwStartTime = _vm->GetTime(); _ctx->numHandles = 0; -// warning("PlayScript(): Moments: %u\n",s->nMoments); +// debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) { // Dorme il tempo necessario per arrivare al momento successivo if (s->Moment[_ctx->i].dwTime == -1) { @@ -654,7 +654,7 @@ void ScriptThread(CORO_PARAM, const void *param) { } else { _ctx->dwCurTime = _vm->GetTime(); if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { - // warning("PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); + // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); } } @@ -2199,7 +2199,7 @@ void OutputStartMsgComment(uint16 wNum, Common::OutSaveFile *f) { for (i = 0; MsgComments[i].wStart != 0; i++) if (MsgComments[i].wStart == wNum) { - warning("Start: %d\n", wNum); + debugC(DEBUG_BASIC, kTonyDebugMPAL, "Start: %d\n", wNum); f->writeString("
\n

\n

\n"); @@ -2217,7 +2217,7 @@ void OutputEndMsgComment(uint16 wNum, Common::OutSaveFile *f) { for (i = 0; MsgComments[i].wEnd != 0; i++) if (MsgComments[i].wEnd == wNum) { -warning("End: %d\n", wNum); + debugC(DEBUG_BASIC, kTonyDebugMPAL, "End: %d\n", wNum); if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { f->writeString("\n

\n"); @@ -2276,7 +2276,7 @@ void mpalDumpMessages(void) { bDontOutput = false; - warning("Dumping MESSAGES.HTM...\n"); + debugC(DEBUG_BASIC, kTonyDebugMPAL, "Dumping MESSAGES.HTM...\n"); f = g_system->getSavefileManager()->openForSaving("Messages.htm"); f->writeString("\n\n\n"); @@ -2369,7 +2369,7 @@ void mpalDumpOthers(void) { bDontOutput = false; - warning("Dumping OTHERS.HTM...\n"); + debugC(DEBUG_BASIC, kTonyDebugMPAL, "Dumping OTHERS.HTM...\n"); f->writeString("\n\n"); -- cgit v1.2.3 From 8322da03c04d7994601973364599081447a7ccde Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 20 May 2012 16:03:09 +1000 Subject: TONY: Converting Italian comments to English --- engines/tony/mpal/mpal.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 5cb6546343..0b56317f6f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -647,7 +647,7 @@ void ScriptThread(CORO_PARAM, const void *param) { // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) { - // Dorme il tempo necessario per arrivare al momento successivo + // Sleep for the required time if (s->Moment[_ctx->i].dwTime == -1) { CORO_INVOKE_4(CoroScheduler.waitForMultipleObjects, _ctx->numHandles, cfHandles, true, CORO_INFINITE); _ctx->dwStartTime = _vm->GetTime(); @@ -878,7 +878,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } UnlockItems(); - /* Se non e' rimasto nessuno possiamo uscire */ + /* If there is nothing left, we can exit */ if (_ctx->nRealItems == 0) { GlobalFree(_ctx->il); CORO_KILL_SELF(); @@ -1170,7 +1170,7 @@ void GroupThread(CORO_PARAM, const void *param) { } } - /* Se siamo qui, vuol dire che non abbiamo trovato il gruppo richiesto */ + /* If we are here, it means that we have not found the requested group */ GLOBALS.mpalError = 1; UnlockDialogs(); @@ -2750,7 +2750,7 @@ const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, case num: \ if (nPers >= (int)(sizeof(DLG##num) / sizeof(const char *)) || DLG##num[nPers] == NULL) \ { \ - warning("ERROR: Il personaggio #%d non esiste nel dialogo %d!\n", nPers, nDlg); \ + warning("ERROR: The character #%d does not exist in dialog %d!\n", nPers, nDlg); \ return "ERROR"; \ } \ else \ @@ -2819,7 +2819,7 @@ const char *GetPersonName(uint16 nDlg, int nPers) { HANDLE_DIALOG(600); default: - warning("ERROR: Il dialogo %d non esiste!\n", (int)nDlg); + warning("ERROR: Dialog %d does not exist!", (int)nDlg); return "ERROR"; } } @@ -2872,7 +2872,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { break; if (dlg->Periods[j] == NULL) - warning("ERROR: Dialogo %d, Periodo %d non trovato!\n", (int)dlg->nObj, (int)curCmd->arg2); + warning("ERROR: Dialog %d, Period %d not found!", (int)dlg->nObj, (int)curCmd->arg2); else { frase = (char *)GlobalLock(dlg->Periods[j]); strcpy(copia, frase); -- cgit v1.2.3 From c38bbce20cf69748012863dcd08c575ba6b56c9d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 20 May 2012 16:11:25 +1000 Subject: TONY: Remove original header --- engines/tony/mpal/expr.cpp | 31 +++++-------------------------- engines/tony/mpal/expr.h | 31 +++++-------------------------- engines/tony/mpal/loadmpc.cpp | 31 +++++-------------------------- engines/tony/mpal/loadmpc.h | 31 +++++-------------------------- engines/tony/mpal/mpal.cpp | 31 +++++-------------------------- engines/tony/mpal/mpal.h | 40 ++-------------------------------------- engines/tony/mpal/mpaldll.h | 31 +++++-------------------------- 7 files changed, 32 insertions(+), 194 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index cf688341be..aaec74fb4c 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: Expression gestor...... * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Gestisce le espressioni * - * 4> ^R$oue# d matematiche............ * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ #include "tony/mpal/mpal.h" #include "tony/mpal/memory.h" diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 3a9f0f3208..7d7ca09c41 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: Expression gestor heade * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Gestisce le espressioni * - * 4> ^R$oue# d matematiche............ * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ #ifndef MPAL_EXPR_H #define MPAL_EXPR_H diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 6329a2090a..a60c9f5f16 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: MPC Loader............. * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Legge un file compilato * - * 4> ^R$oue# d di MPAL................ * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ /* #include "lzo1x.h" diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index 6aea3de16b..2f8a1121ec 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: MPC Loader Header...... * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Legge un file compilato * - * 4> ^R$oue# d MPC.................... * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ #ifndef __LOADMPC_H #define __LOADMPC_H diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 0b56317f6f..a5b7593e68 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: Mpal Query Library..... * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Libreria principale di * - * 4> ^R$oue# d MPAL, contenente il * - * '$ "" @ codice per le query.... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ #include "common/scummsys.h" #include "common/file.h" diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index a14bfd1895..1bf19ef1bb 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -20,46 +20,10 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: MPAL Main Include file. * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Main Include file for * - * 4> ^R$oue# d using MPAL.DLL......... * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ - - -/****************************************************************************\ -* Copyright Notice -\****************************************************************************/ - /* - * A Spyral Software Production: - * - * MPAL - MultiPurpose Adventure Language - * (C) 1997 Giovanni Bajo and Luca Giusti - * ALL RIGHTS RESERVED - * + * This code is based on original Tony Tough source code * + * Copyright (c) 1997-2003 Nayma Software */ diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index dc42b597bc..8216e7b166 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -20,32 +20,11 @@ * * */ -/************************************************************************** - * ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * ... Spyral Software snc * - * . x#""*$Nu -= We create much MORE than ALL =- * - * d*#R$. R ^#$o ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * .F ^$k $ "$b * - * ." $b u "$ #$L * - * P $c :*$L"$L '$k Project: MPAL................... * - * d @$N. $. d ^$b^$k $c * - * F 4 "$c '$ $ #$u#$u '$ Module: MPAL DLL Header........ * - * 4 4k *N #b .> '$N'*$u * * - * M $L #$ $ 8 "$c'#$b.. .@ Author: Giovanni Bajo.......... * - * M '$u "$u :" *$. "#*#" * - * M '$N. " F ^$k Desc: Header per i moduli per * - * 4> ^R$oue# d la DLL di query di MPAL * - * '$ "" @ ....................... * - * #b u# * - * $b .@" OS: [ ] DOS [X] WIN95 [ ] OS/2 * - * #$u .d" * - * '*$e. .zR".@ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * "*$$beooee$*" @"M This source code is * - * """ '$.? Copyright (C) Spyral Software * - * '$d> ALL RIGHTS RESERVED * - * '$> ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ * - * * - **************************************************************************/ +/* + * This code is based on original Tony Tough source code + * + * Copyright (c) 1997-2003 Nayma Software + */ #ifndef __MPALDLL_H #define __MPALDLL_H -- cgit v1.2.3 From 29cbb3f824a7dc197c396e44de4efc702f04c89a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 20 May 2012 17:01:20 +1000 Subject: TONY: Miscellaneous comment translations and comment cleanup --- engines/tony/mpal/mpaldll.h | 62 ++++----------------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 8216e7b166..90fa31ef1d 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -44,20 +44,11 @@ namespace MPAL { #define HEX_VERSION 0x0170 -/* - Safe - -#define MAX_ACTIONS_PER_ITEM 40 -#define MAX_COMMANDS_PER_ITEM 256 -#define MAX_COMMANDS_PER_ACTION 64 -#define MAX_DESCRIBE_SIZE 128 -*/ #define MAX_ACTIONS_PER_ITEM 40 #define MAX_COMMANDS_PER_ITEM 128 #define MAX_COMMANDS_PER_ACTION 128 -#define MAX_DESCRIBE_SIZE 64 - +#define MAX_DESCRIBE_SIZE 64 #define MAX_MOMENTS_PER_SCRIPT 256 @@ -65,22 +56,6 @@ namespace MPAL { #define MAX_COMMANDS_PER_MOMENT 32 - - - -/* - Secure version! - -#define MAX_GROUPS_PER_DIALOG 128 -#define MAX_COMMANDS_PER_DIALOG 640 -#define MAX_COMMANDS_PER_GROUP 64 -#define MAX_CHOICES_PER_DIALOG 64 -#define MAX_SELECTS_PER_CHOICE 33 -#define MAX_PLAYGROUPS_PER_SELECT 9 -#define MAX_PERIODS_PER_DIALOG 640 - -*/ - #define MAX_GROUPS_PER_DIALOG 128 #define MAX_COMMANDS_PER_DIALOG 480 #define MAX_COMMANDS_PER_GROUP 64 @@ -89,17 +64,6 @@ namespace MPAL { #define MAX_PLAYGROUPS_PER_SELECT 9 #define MAX_PERIODS_PER_DIALOG 400 -/* - Before Rufus: - -#define MAX_GROUPS_PER_DIALOG 128 -#define MAX_COMMANDS_PER_DIALOG 512 -#define MAX_COMMANDS_PER_GROUP 32 -#define MAX_CHOICES_PER_DIALOG 64 -#define MAX_SELECTS_PER_CHOICE 32 -#define MAX_PLAYGROUPS_PER_SELECT 4 -#define MAX_PERIODS_PER_DIALOG 512 -*/ #define NEED_LOCK_MSGS @@ -242,29 +206,13 @@ struct MPALITEM { struct command Command[MAX_COMMANDS_PER_ITEM]; - // Array of structures containing various managed activities. In practice, of - // every action we know what commands to run, including those defined in - // structures above -/* - struct - { - byte num; // Numero dell'azione - uint16 wTime; // In caso di idle, il tempo che deve passare - byte perc; // Percentuale di eseguire l'idle - HGLOBAL when; // Espressione da calcolare: se !=0, allora - // l'azione puo' essere eseguita - uint16 wParm; // Parametro per l'azione - - byte nCmds; // Numero comandi da eseguire - uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Comando da eseguire - - } Action[MAX_ACTIONS_PER_ITEM]; - */ + // Pointer to array of structures containing various managed activities. In practice, of + // every action we know what commands to run, including those defined in structures above struct ItemAction *Action; } PACKED_STRUCT; -typedef MPALITEM* LPMPALITEM; -typedef LPMPALITEM* LPLPMPALITEM; +typedef MPALITEM *LPMPALITEM; +typedef LPMPALITEM *LPLPMPALITEM; /** -- cgit v1.2.3 From 75a0b0c6296af6600ce1a4e585fb7c5b9a0ea203 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 23 May 2012 00:19:46 +0200 Subject: TONY: Some more code formatting --- engines/tony/mpal/expr.cpp | 64 +++++++++++----------- engines/tony/mpal/expr.h | 2 - engines/tony/mpal/loadmpc.cpp | 124 ++++++++++++++++++++++++++---------------- engines/tony/mpal/mpal.cpp | 44 +++++++-------- engines/tony/mpal/mpaldll.h | 4 +- 5 files changed, 131 insertions(+), 107 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index aaec74fb4c..ae6dfac482 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -43,37 +43,36 @@ namespace MPAL { * @defgroup Mathamatical operations */ -#define OP_MUL ((1<<4)|0) -#define OP_DIV ((1<<4)|1) -#define OP_MODULE ((1<<4)|2) -#define OP_ADD ((2<<4)|0) -#define OP_SUB ((2<<4)|1) -#define OP_SHL ((3<<4)|0) -#define OP_SHR ((3<<4)|1) -#define OP_MINOR ((4<<4)|0) -#define OP_MAJOR ((4<<4)|1) -#define OP_MINEQ ((4<<4)|2) -#define OP_MAJEQ ((4<<4)|3) -#define OP_EQUAL ((5<<4)|0) -#define OP_NOEQUAL ((5<<4)|1) -#define OP_BITAND ((6<<4)|0) -#define OP_BITXOR ((7<<4)|0) -#define OP_BITOR ((8<<4)|0) -#define OP_AND ((9<<4)|0) -#define OP_OR ((10<<4)|0) +#define OP_MUL ((1 << 4) | 0) +#define OP_DIV ((1 << 4) | 1) +#define OP_MODULE ((1 << 4) | 2) +#define OP_ADD ((2 << 4) | 0) +#define OP_SUB ((2 << 4) | 1) +#define OP_SHL ((3 << 4) | 0) +#define OP_SHR ((3 << 4) | 1) +#define OP_MINOR ((4 << 4) | 0) +#define OP_MAJOR ((4 << 4) | 1) +#define OP_MINEQ ((4 << 4) | 2) +#define OP_MAJEQ ((4 << 4) | 3) +#define OP_EQUAL ((5 << 4) | 0) +#define OP_NOEQUAL ((5 << 4) | 1) +#define OP_BITAND ((6 << 4) | 0) +#define OP_BITXOR ((7 << 4) | 0) +#define OP_BITOR ((8 << 4) | 0) +#define OP_AND ((9 << 4) | 0) +#define OP_OR ((10 << 4) | 0) /** * Object types that can be contained in an EXPRESSION structure */ enum ExprListTypes { - ELT_NUMBER = 1, - ELT_VAR = 2, - ELT_PARENTH = 3, + ELT_NUMBER = 1, + ELT_VAR = 2, + ELT_PARENTH = 3, ELT_PARENTH2 = 4 }; - /** * @defgroup Structures */ @@ -95,7 +94,7 @@ typedef struct { byte symbol; // Simbolo matematico (vedi #define OP_*) } EXPRESSION; -typedef EXPRESSION* LPEXPRESSION; +typedef EXPRESSION *LPEXPRESSION; /** @@ -186,13 +185,13 @@ static void Solve(LPEXPRESSION one, int num) { while (num > 1) { two=one + 1; if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { - two->val.num=Compute(one->val.num, two->val.num,one->symbol); + two->val.num = Compute(one->val.num, two->val.num,one->symbol); CopyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); num--; } else { j = 1; three = two + 1; - while ((three->symbol != 0) && (two->symbol & 0xF0)>(three->symbol & 0xF0)) { + while ((three->symbol != 0) && (two->symbol & 0xF0) > (three->symbol & 0xF0)) { two++; three++; j++; @@ -221,10 +220,10 @@ static int EvaluateAndFreeExpression(byte *expr) { one = (LPEXPRESSION)(expr + 1); // 1) Sostituzioni delle variabili - for (i=0, cur=one; i < num; i++, cur++) { - if (cur->type==ELT_VAR) { - cur->type=ELT_NUMBER; - cur->val.num=varGetValue(cur->val.name); + for (i = 0, cur = one; i < num; i++, cur++) { + if (cur->type == ELT_VAR) { + cur->type = ELT_NUMBER; + cur->val.num = varGetValue(cur->val.name); } } @@ -265,7 +264,7 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { return NULL; *h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); - if (*h==NULL) + if (*h == NULL) return NULL; start = (byte *)GlobalLock(*h); @@ -332,7 +331,6 @@ int EvaluateExpression(HGLOBAL h) { return ret; } - /** * Compare two mathematical expressions together * @@ -356,8 +354,8 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { return false; } - one = (LPEXPRESSION)(e1+1); - two = (LPEXPRESSION)(e2+1); + one = (LPEXPRESSION)(e1 + 1); + two = (LPEXPRESSION)(e2 + 1); for (i = 0; i < num1; i++) { if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 7d7ca09c41..17e9c1264b 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -47,7 +47,6 @@ namespace MPAL { */ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); - /** * Calculate the value of a mathamatical expression * @@ -56,7 +55,6 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); */ int EvaluateExpression(HGLOBAL h); - /** * Compare two mathematical expressions together * diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index a60c9f5f16..a80c85eb75 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -38,7 +38,6 @@ namespace Tony { namespace MPAL { - /****************************************************************************\ * Funzioni statiche \****************************************************************************/ @@ -54,7 +53,6 @@ static bool CompareCommands(struct command *cmd1, struct command *cmd2) { return (memcmp(cmd1, cmd2, sizeof(struct command)) == 0); } - /** * Parses a script from the MPC file, and inserts its data into a structure * @@ -64,7 +62,7 @@ static bool CompareCommands(struct command *cmd1, struct command *cmd2) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { - int curCmd,j,len; + int curCmd, j, len; uint i; lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf); @@ -76,31 +74,40 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { curCmd = 0; for (i = 0; i < lpmsScript->nMoments; i++) { - lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Moment[i].nCmds = *lpBuf; lpBuf++; + lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmsScript->Moment[i].nCmds = *lpBuf; + lpBuf++; for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) { - lpmsScript->Command[curCmd].type = *lpBuf; lpBuf++; + lpmsScript->Command[curCmd].type = *lpBuf; + lpBuf++; switch (lpmsScript->Command[curCmd].type) { case 1: - lpmsScript->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmsScript->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmsScript->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpBuf += 2; + lpmsScript->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmsScript->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmsScript->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmsScript->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; break; case 2: // Variable assign - len=*lpBuf; lpBuf++; - lpmsScript->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,len+1); + len = *lpBuf; + lpBuf++; + lpmsScript->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmsScript->Command[curCmd].lpszVarName == NULL) return NULL; CopyMemory(lpmsScript->Command[curCmd].lpszVarName, lpBuf, len); - lpBuf+=len; + lpBuf += len; lpBuf = ParseExpression(lpBuf, &lpmsScript->Command[curCmd].expr); if (lpBuf == NULL) - return NULL; + return NULL; break; default: @@ -111,11 +118,9 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { curCmd++; } } - return lpBuf; } - /** * Parses a dialog from the MPC file, and inserts its data into a structure * @@ -131,16 +136,19 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 curCmd; uint32 len; - lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->nObj = READ_LE_UINT32(lpBuf); + lpBuf += 4; /* Periodi */ - num = READ_LE_UINT16(lpBuf); lpBuf += 2; + num = READ_LE_UINT16(lpBuf); + lpBuf += 2; if (num >= MAX_PERIODS_PER_DIALOG - 1) error("Too much periods in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); + lpBuf += 2; lpmdDialog->Periods[i] = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); lpLock = (byte *)GlobalLock(lpmdDialog->Periods[i]); Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock); @@ -152,14 +160,16 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->Periods[i] = NULL; /* Gruppi */ - num = READ_LE_UINT16(lpBuf); lpBuf += 2; + num = READ_LE_UINT16(lpBuf); + lpBuf += 2; curCmd = 0; if (num >= MAX_GROUPS_PER_DIALOG) error("Too much groups in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); + lpBuf += 2; lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++; if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) @@ -172,11 +182,16 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { switch (lpmdDialog->Command[curCmd].type) { // Call custom function case 1: - lpmdDialog->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->Command[curCmd].arg1 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg2 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg3 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg4 = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpBuf += 2; + lpmdDialog->Command[curCmd].arg1 = READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmdDialog->Command[curCmd].arg2 = READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmdDialog->Command[curCmd].arg3 = READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmdDialog->Command[curCmd].arg4 = READ_LE_UINT32(lpBuf); + lpBuf += 4; break; // Variable assign @@ -197,7 +212,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { // Do Choice case 3: - lpmdDialog->Command[curCmd].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Command[curCmd].nChoice = READ_LE_UINT16(lpBuf); + lpBuf += 2; break; default: @@ -222,13 +238,15 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { error("Too much commands in dialog #%d",lpmdDialog->nObj); /* Choices */ - num = READ_LE_UINT16(lpBuf); lpBuf += 2; + num = READ_LE_UINT16(lpBuf); + lpBuf += 2; if (num >= MAX_CHOICES_PER_DIALOG) error("Too much choices in dialog #%d",lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); + lpBuf += 2; num2 = *lpBuf++; @@ -256,16 +274,19 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->Choice[i].Select[j].attr = *lpBuf++; // Data - lpmdDialog->Choice[i].Select[j].dwData = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmdDialog->Choice[i].Select[j].dwData = READ_LE_UINT32(lpBuf); + lpBuf += 4; // PlayGroup - num3 = *lpBuf; *lpBuf++; + num3 = *lpBuf; + *lpBuf++; if (num3 >= MAX_PLAYGROUPS_PER_SELECT) error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); for (z = 0; z < num3; z++) { - lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; + lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); + lpBuf += 2; } lpmdDialog->Choice[i].Select[j].wPlayGroup[num3] = 0; @@ -353,11 +374,16 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpBuf++; switch (lpmiItem->Command[curCmd].type) { case 1: // Call custom function - lpmiItem->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmiItem->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmiItem->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpBuf += 2; + lpmiItem->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmiItem->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmiItem->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; + lpmiItem->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpBuf += 4; break; case 2: // Variable assign @@ -385,7 +411,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } } - if (kk==curCmd) { + if (kk == curCmd) { lpmiItem->Action[i].CmdNum[j] = curCmd; curCmd++; @@ -397,7 +423,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } } - lpmiItem->dwRes = READ_LE_UINT32(lpBuf); lpBuf += 4; + lpmiItem->dwRes = READ_LE_UINT32(lpBuf); + lpBuf += 4; return lpBuf; } @@ -418,7 +445,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) lpBuf += 2; lpmlLocation->dwYlen = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmlLocation->dwPicRes = READ_LE_UINT32(lpBuf); + lpmlLocation->dwPicRes = READ_LE_UINT32(lpBuf); lpBuf += 4; return lpBuf; @@ -551,14 +578,15 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.nItems = 0; GLOBALS.hItems = GLOBALS.lpmiItems = NULL; if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4)==0) { - GLOBALS.nItems = READ_LE_UINT16(lpBuf); lpBuf += 2; + GLOBALS.nItems = READ_LE_UINT16(lpBuf); + lpBuf += 2; // Allocate memory and read them in GLOBALS.hItems = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); if (GLOBALS.hItems == NULL) return false; - GLOBALS.lpmiItems=(LPMPALITEM)GlobalLock(GLOBALS.hItems); + GLOBALS.lpmiItems = (LPMPALITEM)GlobalLock(GLOBALS.hItems); for (i = 0; i < GLOBALS.nItems; i++) if ((lpBuf = ParseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL) @@ -570,8 +598,9 @@ bool ParseMpc(const byte *lpBuf) { // Check the locations GLOBALS.nLocations = 0; GLOBALS.hLocations = GLOBALS.lpmlLocations = NULL; - if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8)==0) { - GLOBALS.nLocations = READ_LE_UINT16(lpBuf); lpBuf += 2; + if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8) == 0) { + GLOBALS.nLocations = READ_LE_UINT16(lpBuf); + lpBuf += 2; // Allocate memory and read them in GLOBALS.hLocations=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); @@ -591,7 +620,8 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.nScripts = 0; GLOBALS.hScripts = GLOBALS.lpmsScripts = NULL; if (*(lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Script", 6) == 0) { - GLOBALS.nScripts = READ_LE_UINT16(lpBuf); lpBuf += 2; + GLOBALS.nScripts = READ_LE_UINT16(lpBuf); + lpBuf += 2; // Allocate memory GLOBALS.hScripts = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); @@ -611,7 +641,6 @@ bool ParseMpc(const byte *lpBuf) { //sizeof(GLOBALS.lpmsScripts[i].Moment[0]), //(int (*)(const void *, const void *))CompareMoments //); - } GlobalUnlock(GLOBALS.hScripts); @@ -623,7 +652,6 @@ bool ParseMpc(const byte *lpBuf) { return true; } - } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index a5b7593e68..12fc78c60c 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -345,7 +345,7 @@ static char *DuplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; LPMPALDIALOG dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; - int i,j; + int i, j; for (j = 0; dialog->Periods[j] != NULL; j++) if (dialog->PeriodNums[j] == nPeriod) { @@ -457,7 +457,7 @@ static uint32 *GetItemList(uint32 nLoc) { LPMPALVAR v = GLOBALS.lpmvVars; num = 0; - for (i = 0; i < GLOBALS.nVars; i++,v++) { + for (i = 0; i < GLOBALS.nVars; i++, v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } @@ -468,8 +468,8 @@ static uint32 *GetItemList(uint32 nLoc) { v = GLOBALS.lpmvVars; j = 0; - for (i = 0; i < GLOBALS.nVars; i++,v++) { - if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) { + for (i = 0; i < GLOBALS.nVars; i++, v++) { + if (strncmp(v->lpszVarName, "Location", 8) == 0 && v->dwVal == nLoc) { sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; } @@ -504,7 +504,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { if (i >= 0x10) { // From 1.0, there's a destination point for each object ret->destX = (int16)READ_LE_UINT16(dat); ret->destY = (int16)READ_LE_UINT16(dat + 2); - dat+=4; + dat += 4; } if (i >= 0x11) { // From 1.1, there's animation speed @@ -514,9 +514,9 @@ static LPITEM GetItemData(uint32 nOrdItem) { ret->speed = 150; } - ret->numframe=*dat++; - ret->numpattern=*dat++; - ret->Zvalue=*dat++; + ret->numframe = *dat++; + ret->numpattern = *dat++; + ret->Zvalue = *dat++; // Upload the left & top co-ordinates of each frame for (i = 0; i < ret->numframe; i++) { @@ -529,7 +529,7 @@ static LPITEM GetItemData(uint32 nOrdItem) { for (i = 0; i < ret->numframe; i++) { ret->frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->frameslocations[i].left; ret->frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->frameslocations[i].top; - dat+=4; + dat += 4; } // Upload the bounding boxes of each frame @@ -538,12 +538,12 @@ static LPITEM GetItemData(uint32 nOrdItem) { ret->bbox[i].top = (int16)READ_LE_UINT16(dat + 2); ret->bbox[i].right = (int16)READ_LE_UINT16(dat + 4); ret->bbox[i].bottom = (int16)READ_LE_UINT16(dat + 6); - dat+=8; + dat += 8; } // Load the animation pattern patlength = dat; - dat+=ret->numpattern; + dat += ret->numpattern; for (i = 1; i < ret->numpattern; i++) { for (j = 0; j < patlength[i]; j++) @@ -639,7 +639,7 @@ void ScriptThread(CORO_PARAM, const void *param) { } _ctx->numHandles = 0; - for (_ctx->j = 0; _ctx->jMoment[_ctx->i].nCmds; _ctx->j++) { + for (_ctx->j = 0; _ctx->j < s->Moment[_ctx->i].nCmds; _ctx->j++) { _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j]; if (s->Command[_ctx->k].type == 1) { @@ -1048,9 +1048,6 @@ void LocationPollThread(CORO_PARAM, const void *param) { } - - - /** * Wait for the end of the dialog execution thread, and then restore global * variables indicating that the dialogue has finished. @@ -1847,7 +1844,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) - n[0]='\0'; + n[0] = '\0'; else { LockItems(); y = itemGetOrderFromNum(x); @@ -2288,7 +2285,7 @@ void mpalDumpMessages(void) { } // Now make a loop over all the periods - for (j = 0;j= MAX_PLAYGROUPS_PER_SELECT) + if (num3 >= MAX_PLAYGROUPS_PER_SELECT) error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); for (z = 0; z < num3; z++) { -- cgit v1.2.3 From a1f6f8ceb19d65619dfd8e2477bffad773ba49ba Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jun 2012 23:45:36 +0200 Subject: TONY: Rename variables and functions in tony.h --- engines/tony/mpal/mpal.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 12fc78c60c..16c530206c 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -621,7 +621,7 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - _ctx->dwStartTime = _vm->GetTime(); + _ctx->dwStartTime = _vm->getTime(); _ctx->numHandles = 0; // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); @@ -629,9 +629,9 @@ void ScriptThread(CORO_PARAM, const void *param) { // Sleep for the required time if (s->Moment[_ctx->i].dwTime == -1) { CORO_INVOKE_4(CoroScheduler.waitForMultipleObjects, _ctx->numHandles, cfHandles, true, CORO_INFINITE); - _ctx->dwStartTime = _vm->GetTime(); + _ctx->dwStartTime = _vm->getTime(); } else { - _ctx->dwCurTime = _vm->GetTime(); + _ctx->dwCurTime = _vm->getTime(); if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); @@ -771,7 +771,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { _ctx->slotNumber = _vm->_initialLoadSlotNumber; _vm->_initialLoadSlotNumber = -1; - CORO_INVOKE_1(_vm->LoadState, _ctx->slotNumber); + CORO_INVOKE_1(_vm->loadState, _ctx->slotNumber); } @@ -903,7 +903,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - _ctx->MyActions[_ctx->k].dwLastTime = _vm->GetTime(); + _ctx->MyActions[_ctx->k].dwLastTime = _vm->getTime(); _ctx->k++; } } @@ -918,7 +918,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ - _ctx->curTime = _vm->GetTime(); + _ctx->curTime = _vm->getTime(); _ctx->dwSleepTime = (uint32)-1L; for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) @@ -944,7 +944,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads[_ctx->i].nItem = 0; } - _ctx->curTime = _vm->GetTime(); + _ctx->curTime = _vm->getTime(); /* Loop through all the necessary idle actions */ for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) -- cgit v1.2.3 From f12ab3e521b01ed2b40e7d517753dd14bc6e6f0f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 7 Jun 2012 08:42:35 +0200 Subject: TONY: Rename variables and functions in utils.h --- engines/tony/mpal/mpalutils.cpp | 36 ++++++++++++++++++------------------ engines/tony/mpal/mpalutils.h | 14 +++++++------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index 2e3bd07383..edc6e65ca1 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -37,42 +37,42 @@ namespace MPAL { * @param resId MPAL resource to open */ RMRes::RMRes(uint32 resID) { - m_h = _vm->_resUpdate.QueryResource(resID); - if (m_h == NULL) - m_h = mpalQueryResource(resID); - if (m_h != NULL) - m_buf = (byte *)GlobalLock(m_h); + _h = _vm->_resUpdate.queryResource(resID); + if (_h == NULL) + _h = mpalQueryResource(resID); + if (_h != NULL) + _buf = (byte *)GlobalLock(_h); } /** * Destructor */ RMRes::~RMRes() { - if (m_h != NULL) { - GlobalUnlock(m_h); - GlobalFree(m_h); + if (_h != NULL) { + GlobalUnlock(_h); + GlobalFree(_h); } } /** * Returns a pointer to the resource */ -const byte *RMRes::DataPointer() { - return m_buf; +const byte *RMRes::dataPointer() { + return _buf; } /** * Returns a pointer to the resource */ RMRes::operator const byte *() { - return DataPointer(); + return dataPointer(); } /** * Returns the size of the resource */ -unsigned int RMRes::Size() { - return GlobalSize(m_h); +unsigned int RMRes::size() { + return GlobalSize(_h); } /****************************************************************************\ @@ -86,19 +86,19 @@ RMResRaw::~RMResRaw() { } const byte *RMResRaw::DataPointer() { - return m_buf + 8; + return _buf + 8; } RMResRaw::operator const byte *() { return DataPointer(); } -int RMResRaw::Width() { - return READ_LE_UINT16(m_buf + 4); +int RMResRaw::width() { + return READ_LE_UINT16(_buf + 4); } -int RMResRaw::Height() { - return READ_LE_UINT16(m_buf + 6); +int RMResRaw::height() { + return READ_LE_UINT16(_buf + 6); } } // end of namespace MPAL diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index a9f8403fcd..a428a40a64 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -33,17 +33,17 @@ namespace MPAL { class RMRes { protected: - HGLOBAL m_h; - byte *m_buf; + HGLOBAL _h; + byte *_buf; public: RMRes(uint32 resID); virtual ~RMRes(); // Attributes - unsigned int Size(); - const byte *DataPointer(); - bool IsValid() { return m_h != NULL; } + unsigned int size(); + const byte *dataPointer(); + bool isValid() { return _h != NULL; } // Casting for access to data operator const byte*(); @@ -57,8 +57,8 @@ public: const byte *DataPointer(); operator const byte*(); - int Width(); - int Height(); + int width(); + int height(); }; } // end of namespace MPAL -- cgit v1.2.3 From cd15e483ed64274049142a2e6838962d794c3ff5 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 7 Jun 2012 21:14:59 +0200 Subject: TONY: Some more renaming --- engines/tony/mpal/expr.cpp | 78 +++---- engines/tony/mpal/expr.h | 6 +- engines/tony/mpal/loadmpc.cpp | 184 +++++++-------- engines/tony/mpal/memory.cpp | 12 +- engines/tony/mpal/memory.h | 20 +- engines/tony/mpal/mpal.cpp | 482 ++++++++++++++++++++-------------------- engines/tony/mpal/mpal.h | 4 +- engines/tony/mpal/mpaldll.h | 16 +- engines/tony/mpal/mpalutils.cpp | 8 +- 9 files changed, 405 insertions(+), 405 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index ae6dfac482..0b51724330 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -103,32 +103,32 @@ typedef EXPRESSION *LPEXPRESSION; * @param h Handle to the original expression * @retruns Pointer to the cloned expression */ -static byte *DuplicateExpression(HGLOBAL h) { +static byte *duplicateExpression(HGLOBAL h) { int i, num; byte *orig, *clone; LPEXPRESSION one, two; - orig = (byte *)GlobalLock(h); + orig = (byte *)globalLock(h); num = *(byte *)orig; one = (LPEXPRESSION)(orig+1); - clone = (byte *)GlobalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); + clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); two = (LPEXPRESSION)(clone + 1); - CopyMemory(clone, orig, sizeof(EXPRESSION) * num + 1); + copyMemory(clone, orig, sizeof(EXPRESSION) * num + 1); for (i = 0; i < num; i++) { if (one->type == ELT_PARENTH) { two->type = ELT_PARENTH2; - two->val.pson = DuplicateExpression(two->val.son); + two->val.pson = duplicateExpression(two->val.son); } one++; two++; } - GlobalUnlock(h); + globalUnlock(h); return clone; } @@ -178,7 +178,7 @@ static int Compute(int a, int b, byte symbol) { return 0; } -static void Solve(LPEXPRESSION one, int num) { +static void solve(LPEXPRESSION one, int num) { LPEXPRESSION two, three; int j; @@ -186,7 +186,7 @@ static void Solve(LPEXPRESSION one, int num) { two=one + 1; if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { two->val.num = Compute(one->val.num, two->val.num,one->symbol); - CopyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); + copyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); num--; } else { j = 1; @@ -198,7 +198,7 @@ static void Solve(LPEXPRESSION one, int num) { } three->val.num = Compute(two->val.num, three->val.num, two->symbol); - CopyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION)); + copyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION)); num--; } } @@ -212,7 +212,7 @@ static void Solve(LPEXPRESSION one, int num) { * @param expr Pointer to an expression duplicated by DuplicateExpression * @returns Value */ -static int EvaluateAndFreeExpression(byte *expr) { +static int evaluateAndFreeExpression(byte *expr) { int i,num,val; LPEXPRESSION one,cur; @@ -231,14 +231,14 @@ static int EvaluateAndFreeExpression(byte *expr) { for (i = 0, cur = one; i < num; i++, cur++) { if (cur->type == ELT_PARENTH2) { cur->type = ELT_NUMBER; - cur->val.num = EvaluateAndFreeExpression(cur->val.pson); + cur->val.num = evaluateAndFreeExpression(cur->val.pson); } } // 3) Risoluzione algebrica - Solve(one, num); + solve(one, num); val = one->val.num; - GlobalFree(expr); + globalFree(expr); return val; } @@ -252,7 +252,7 @@ static int EvaluateAndFreeExpression(byte *expr) { * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ -const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { +const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { LPEXPRESSION cur; byte *start; uint32 num, i; @@ -263,11 +263,11 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { if (num == 0) return NULL; - *h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); + *h = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); if (*h == NULL) return NULL; - start = (byte *)GlobalLock(*h); + start = (byte *)globalLock(*h); *start = (byte)num; cur = (LPEXPRESSION)(start + 1); @@ -283,15 +283,15 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { break; case ELT_VAR: - cur->val.name = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); + cur->val.name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); if (cur->val.name == NULL) return NULL; - CopyMemory(cur->val.name, lpBuf + 1, *lpBuf); + copyMemory(cur->val.name, lpBuf + 1, *lpBuf); lpBuf += *lpBuf + 1; break; case ELT_PARENTH: - lpBuf=ParseExpression(lpBuf, &cur->val.son); + lpBuf = parseExpression(lpBuf, &cur->val.son); if (lpBuf == NULL) return NULL; break; @@ -321,12 +321,12 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h) { * @param h Handle to the expression * @returns Numeric value */ -int EvaluateExpression(HGLOBAL h) { +int evaluateExpression(HGLOBAL h) { int ret; - LockVar(); - ret=EvaluateAndFreeExpression(DuplicateExpression(h)); - UnlockVar(); + lockVar(); + ret = evaluateAndFreeExpression(duplicateExpression(h)); + unlockVar(); return ret; } @@ -337,20 +337,20 @@ int EvaluateExpression(HGLOBAL h) { * @param h1 Expression to be compared * @param h2 Expression to be compared */ -bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { +bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { int i, num1, num2; byte *e1, *e2; LPEXPRESSION one, two; - e1 = (byte *)GlobalLock(h1); - e2 = (byte *)GlobalLock(h2); + e1 = (byte *)globalLock(h1); + e2 = (byte *)globalLock(h2); num1 = *(byte *)e1; num2 = *(byte *)e2; if (num1 != num2) { - GlobalUnlock(h1); - GlobalUnlock(h2); + globalUnlock(h1); + globalUnlock(h2); return false; } @@ -359,32 +359,32 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { for (i = 0; i < num1; i++) { if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { - GlobalUnlock(h1); - GlobalUnlock(h2); + globalUnlock(h1); + globalUnlock(h2); return false; } switch (one->type) { case ELT_NUMBER: if (one->val.num != two->val.num) { - GlobalUnlock(h1); - GlobalUnlock(h2); + globalUnlock(h1); + globalUnlock(h2); return false; } break; case ELT_VAR: if (strcmp(one->val.name, two->val.name) != 0) { - GlobalUnlock(h1); - GlobalUnlock(h2); + globalUnlock(h1); + globalUnlock(h2); return false; } break; case ELT_PARENTH: - if (!CompareExpressions(one->val.son, two->val.son)) { - GlobalUnlock(h1); - GlobalUnlock(h2); + if (!compareExpressions(one->val.son, two->val.son)) { + globalUnlock(h1); + globalUnlock(h2); return false; } break; @@ -394,8 +394,8 @@ bool CompareExpressions(HGLOBAL h1, HGLOBAL h2) { two++; } - GlobalUnlock(h1); - GlobalUnlock(h2); + globalUnlock(h1); + globalUnlock(h2); return true; } diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 17e9c1264b..7d33e5c8ca 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -45,7 +45,7 @@ namespace MPAL { * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ -const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); +const byte *parseExpression(const byte *lpBuf, HGLOBAL *h); /** * Calculate the value of a mathamatical expression @@ -53,7 +53,7 @@ const byte *ParseExpression(const byte *lpBuf, HGLOBAL *h); * @param h Handle to the expression * @returns Numeric value */ -int EvaluateExpression(HGLOBAL h); +int evaluateExpression(HGLOBAL h); /** * Compare two mathematical expressions together @@ -61,7 +61,7 @@ int EvaluateExpression(HGLOBAL h); * @param h1 Expression to be compared * @param h2 Expression to be compared */ -bool CompareExpressions(HGLOBAL h1, HGLOBAL h2); +bool compareExpressions(HGLOBAL h1, HGLOBAL h2); } // end of namespace MPAL diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 02571bd30f..8f07102aa3 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -42,10 +42,10 @@ namespace MPAL { * Funzioni statiche \****************************************************************************/ -static bool CompareCommands(struct command *cmd1, struct command *cmd2) { +static bool compareCommands(struct command *cmd1, struct command *cmd2) { if (cmd1->type == 2 && cmd2->type == 2) { if (strcmp(cmd1->lpszVarName, cmd2->lpszVarName) == 0 && - CompareExpressions(cmd1->expr, cmd2->expr)) + compareExpressions(cmd1->expr, cmd2->expr)) return true; else return false; @@ -80,32 +80,32 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpBuf++; for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) { - lpmsScript->Command[curCmd].type = *lpBuf; + lpmsScript->_command[curCmd].type = *lpBuf; lpBuf++; - switch (lpmsScript->Command[curCmd].type) { + switch (lpmsScript->_command[curCmd].type) { case 1: - lpmsScript->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmsScript->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmsScript->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; case 2: // Variable assign len = *lpBuf; lpBuf++; - lpmsScript->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmsScript->Command[curCmd].lpszVarName == NULL) + lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmsScript->_command[curCmd].lpszVarName == NULL) return NULL; - CopyMemory(lpmsScript->Command[curCmd].lpszVarName, lpBuf, len); + copyMemory(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len); lpBuf += len; - lpBuf = ParseExpression(lpBuf, &lpmsScript->Command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd].expr); if (lpBuf == NULL) return NULL; break; @@ -129,7 +129,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { * data of the dialog. * @returns Pointer to the buffer after the item, or NULL on failure. */ -static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { +static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 i, j, z, kk; uint32 num, num2, num3; byte *lpLock; @@ -147,17 +147,17 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { error("Too much periods in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); + lpmdDialog->_periodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->Periods[i] = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); - lpLock = (byte *)GlobalLock(lpmdDialog->Periods[i]); + lpmdDialog->_periods[i] = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); + lpLock = (byte *)globalLock(lpmdDialog->_periods[i]); Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock); - GlobalUnlock(lpmdDialog->Periods[i]); + globalUnlock(lpmdDialog->_periods[i]); lpBuf += (*lpBuf) + 1; } - lpmdDialog->PeriodNums[i] = 0; - lpmdDialog->Periods[i] = NULL; + lpmdDialog->_periodNums[i] = 0; + lpmdDialog->_periods[i] = NULL; /* Gruppi */ num = READ_LE_UINT16(lpBuf); @@ -168,29 +168,29 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { error("Too much groups in dialog #%d", lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); + lpmdDialog->_group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++; + lpmdDialog->_group[i].nCmds = *lpBuf; lpBuf++; - if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) - error("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); + if (lpmdDialog->_group[i].nCmds >= MAX_COMMANDS_PER_GROUP) + error("Too much commands in group #%d in dialog #%d",lpmdDialog->_group[i].num,lpmdDialog->nObj); - for (j = 0; j < lpmdDialog->Group[i].nCmds; j++) { - lpmdDialog->Command[curCmd].type = *lpBuf; + for (j = 0; j < lpmdDialog->_group[i].nCmds; j++) { + lpmdDialog->_command[curCmd].type = *lpBuf; lpBuf++; - switch (lpmdDialog->Command[curCmd].type) { + switch (lpmdDialog->_command[curCmd].type) { // Call custom function case 1: - lpmdDialog->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmdDialog->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->Command[curCmd].arg1 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd].arg1 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg2 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd].arg2 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg3 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd].arg3 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->Command[curCmd].arg4 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd].arg4 = READ_LE_UINT32(lpBuf); lpBuf += 4; break; @@ -198,21 +198,21 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { case 2: len = *lpBuf; lpBuf++; - lpmdDialog->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmdDialog->Command[curCmd].lpszVarName == NULL) + lpmdDialog->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmdDialog->_command[curCmd].lpszVarName == NULL) return NULL; - Common::copy(lpBuf, lpBuf + len, lpmdDialog->Command[curCmd].lpszVarName); + Common::copy(lpBuf, lpBuf + len, lpmdDialog->_command[curCmd].lpszVarName); lpBuf += len; - lpBuf = ParseExpression(lpBuf, &lpmdDialog->Command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmdDialog->_command[curCmd].expr); if (lpBuf == NULL) return NULL; break; // Do Choice case 3: - lpmdDialog->Command[curCmd].nChoice = READ_LE_UINT16(lpBuf); + lpmdDialog->_command[curCmd].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; break; @@ -221,14 +221,14 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { } for (kk = 0;kk < curCmd; kk++) { - if (CompareCommands(&lpmdDialog->Command[kk], &lpmdDialog->Command[curCmd])) { - lpmdDialog->Group[i].CmdNum[j] = kk; + if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) { + lpmdDialog->_group[i].CmdNum[j] = kk; break; } } if (kk == curCmd) { - lpmdDialog->Group[i].CmdNum[j] = curCmd; + lpmdDialog->_group[i].CmdNum[j] = curCmd; curCmd++; } } @@ -245,23 +245,23 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { error("Too much choices in dialog #%d",lpmdDialog->nObj); for (i = 0; i < num; i++) { - lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); + lpmdDialog->_choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; num2 = *lpBuf++; if (num2 >= MAX_SELECTS_PER_CHOICE) - error("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); + error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); for (j = 0; j < num2; j++) { // When switch (*lpBuf++) { case 0: - lpmdDialog->Choice[i].Select[j].when = NULL; + lpmdDialog->_choice[i]._select[j].when = NULL; break; case 1: - lpBuf = ParseExpression(lpBuf,&lpmdDialog->Choice[i].Select[j].when); + lpBuf = parseExpression(lpBuf, &lpmdDialog->_choice[i]._select[j].when); if (lpBuf == NULL) return NULL; break; @@ -271,31 +271,31 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { } // Attrib - lpmdDialog->Choice[i].Select[j].attr = *lpBuf++; + lpmdDialog->_choice[i]._select[j].attr = *lpBuf++; // Data - lpmdDialog->Choice[i].Select[j].dwData = READ_LE_UINT32(lpBuf); + lpmdDialog->_choice[i]._select[j].dwData = READ_LE_UINT32(lpBuf); lpBuf += 4; // PlayGroup num3 = *lpBuf++; if (num3 >= MAX_PLAYGROUPS_PER_SELECT) - error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); + error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); for (z = 0; z < num3; z++) { - lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); + lpmdDialog->_choice[i]._select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; } - lpmdDialog->Choice[i].Select[j].wPlayGroup[num3] = 0; + lpmdDialog->_choice[i]._select[j].wPlayGroup[num3] = 0; } // Mark the last selection - lpmdDialog->Choice[i].Select[num2].dwData = 0; + lpmdDialog->_choice[i]._select[num2].dwData = 0; } - lpmdDialog->Choice[num].nChoice = 0; + lpmdDialog->_choice[num].nChoice = 0; return lpBuf; } @@ -311,7 +311,7 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { * @remarks It's necessary that the structure that is passed has been * completely initialised to 0 beforehand. */ -static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { +static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { byte len; uint32 i, j, kk; uint32 curCmd; @@ -321,7 +321,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { len = *lpBuf; lpBuf++; - CopyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); + copyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); lpBuf += len; if (len >= MAX_DESCRIBE_SIZE) @@ -332,7 +332,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { /* Alloca le azioni */ if (lpmiItem->nActions > 0) - lpmiItem->Action = (ItemAction *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); + lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); curCmd = 0; @@ -357,7 +357,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->Action[i].when = NULL; } else { lpBuf++; - lpBuf = ParseExpression(lpBuf,&lpmiItem->Action[i].when); + lpBuf = parseExpression(lpBuf,&lpmiItem->Action[i].when); if (lpBuf == NULL) return NULL; } @@ -369,32 +369,32 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); for (j = 0; j < lpmiItem->Action[i].nCmds; j++) { - lpmiItem->Command[curCmd].type = *lpBuf; + lpmiItem->_command[curCmd].type = *lpBuf; lpBuf++; - switch (lpmiItem->Command[curCmd].type) { + switch (lpmiItem->_command[curCmd].type) { case 1: // Call custom function - lpmiItem->Command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmiItem->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmiItem->Command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->Command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; case 2: // Variable assign len = *lpBuf; lpBuf++; - lpmiItem->Command[curCmd].lpszVarName = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmiItem->Command[curCmd].lpszVarName == NULL) + lpmiItem->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmiItem->_command[curCmd].lpszVarName == NULL) return NULL; - CopyMemory(lpmiItem->Command[curCmd].lpszVarName, lpBuf, len); + copyMemory(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len); lpBuf += len; - lpBuf=ParseExpression(lpBuf, &lpmiItem->Command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd].expr); if (lpBuf == NULL) return NULL; break; @@ -404,7 +404,7 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } for (kk = 0; kk < curCmd; kk++) { - if (CompareCommands(&lpmiItem->Command[kk],&lpmiItem->Command[curCmd])) { + if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) { lpmiItem->Action[i].CmdNum[j] = kk; break; } @@ -478,16 +478,16 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.nVars = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS.hVars = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars); + GLOBALS.hVars = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars); if (GLOBALS.hVars == NULL) return false; - GLOBALS.lpmvVars = (LPMPALVAR)GlobalLock(GLOBALS.hVars); + GLOBALS.lpmvVars = (LPMPALVAR)globalLock(GLOBALS.hVars); for (i = 0; i < GLOBALS.nVars; i++) { wLen = *(const byte *)lpBuf; lpBuf++; - CopyMemory(GLOBALS.lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); + copyMemory(GLOBALS.lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; GLOBALS.lpmvVars->dwVal = READ_LE_UINT32(lpBuf); lpBuf += 4; @@ -496,7 +496,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.lpmvVars++; } - GlobalUnlock(GLOBALS.hVars); + globalUnlock(GLOBALS.hVars); /* 2. Messages */ if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S') @@ -507,11 +507,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; #ifdef NEED_LOCK_MSGS - GLOBALS.hMsgs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs); + GLOBALS.hMsgs = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs); if (GLOBALS.hMsgs == NULL) return false; - GLOBALS.lpmmMsgs = (LPMPALMSG)GlobalLock(GLOBALS.hMsgs); + GLOBALS.lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); #else GLOBALS.lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)GLOBALS.nMsgs); if (GLOBALS.lpmmMsgs==NULL) @@ -525,11 +525,11 @@ bool ParseMpc(const byte *lpBuf) { for (j = 0; lpBuf[j] != 0;) j += lpBuf[j] + 1; - GLOBALS.lpmmMsgs->hText = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); - lpTemp2 = lpTemp = (byte *)GlobalLock(GLOBALS.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]); + copyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]); lpTemp += lpBuf[j]; *lpTemp ++= '\0'; j += lpBuf[j] + 1; @@ -538,12 +538,12 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += j + 1; *lpTemp = '\0'; - GlobalUnlock(GLOBALS.lpmmMsgs->hText); + globalUnlock(GLOBALS.lpmmMsgs->hText); GLOBALS.lpmmMsgs++; } #ifdef NEED_LOCK_MSGS - GlobalUnlock(GLOBALS.hMsgs); + globalUnlock(GLOBALS.hMsgs); #endif /* 3. Objects */ @@ -560,17 +560,17 @@ bool ParseMpc(const byte *lpBuf) { if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) { GLOBALS.nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS.hDialogs = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG)); + GLOBALS.hDialogs = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG)); if (GLOBALS.hDialogs == NULL) return false; - GLOBALS.lpmdDialogs = (LPMPALDIALOG)GlobalLock(GLOBALS.hDialogs); + GLOBALS.lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); for (i = 0;i < GLOBALS.nDialogs; i++) - if ((lpBuf = ParseDialog(lpBuf + 7, &GLOBALS.lpmdDialogs[i])) == NULL) + if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS.lpmdDialogs[i])) == NULL) return false; - GlobalUnlock(GLOBALS.hDialogs); + globalUnlock(GLOBALS.hDialogs); } // Check the items @@ -581,17 +581,17 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS.hItems = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); + GLOBALS.hItems = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); if (GLOBALS.hItems == NULL) return false; - GLOBALS.lpmiItems = (LPMPALITEM)GlobalLock(GLOBALS.hItems); + GLOBALS.lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); for (i = 0; i < GLOBALS.nItems; i++) - if ((lpBuf = ParseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL) + if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL) return false; - GlobalUnlock(GLOBALS.hItems); + globalUnlock(GLOBALS.hItems); } // Check the locations @@ -602,17 +602,17 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS.hLocations=GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); + GLOBALS.hLocations = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); if (GLOBALS.hLocations == NULL) return false; - GLOBALS.lpmlLocations = (LPMPALLOCATION)GlobalLock(GLOBALS.hLocations); + GLOBALS.lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS.hLocations); for (i = 0; i < GLOBALS.nLocations; i++) if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS.lpmlLocations[i])) == NULL) return false; - GlobalUnlock(GLOBALS.hLocations); + globalUnlock(GLOBALS.hLocations); } // Check the scripts @@ -623,11 +623,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory - GLOBALS.hScripts = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); + GLOBALS.hScripts = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); if (GLOBALS.hScripts == NULL) return false; - GLOBALS.lpmsScripts = (LPMPALSCRIPT)GlobalLock(GLOBALS.hScripts); + GLOBALS.lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); for (i = 0; i < GLOBALS.nScripts; i++) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS.lpmsScripts[i])) == NULL) @@ -642,7 +642,7 @@ bool ParseMpc(const byte *lpBuf) { //); } - GlobalUnlock(GLOBALS.hScripts); + globalUnlock(GLOBALS.hScripts); } if (lpBuf[0] != 'E' || lpBuf[1] != 'N' || lpBuf[2] != 'D' || lpBuf[3] != '0') diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 04cb906431..b5bd77f838 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -53,7 +53,7 @@ MemoryItem::~MemoryItem() { * Returns a pointer to the resource */ MemoryItem::operator void *() { - return DataPointer(); + return dataPointer(); } /****************************************************************************\ @@ -81,7 +81,7 @@ MemoryManager::~MemoryManager() { MemoryItem &MemoryManager::allocate(uint32 size, uint flags) { MemoryItem *newItem = new MemoryItem(size); if ((flags & GMEM_ZEROINIT) != 0) { - byte *dataP = (byte *)newItem->DataPointer(); + byte *dataP = (byte *)newItem->dataPointer(); Common::fill(dataP, dataP + size, 0); } @@ -96,7 +96,7 @@ MemoryItem &MemoryManager::allocate(uint32 size, uint flags) { */ HGLOBAL MemoryManager::alloc(uint32 size, uint flags) { MemoryItem &newItem = allocate(size, flags); - return (HGLOBAL)newItem.DataPointer(); + return (HGLOBAL)newItem.dataPointer(); } /** @@ -107,7 +107,7 @@ MemoryItem &MemoryManager::getItem(HGLOBAL handle) { Common::List::iterator i; for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) { MemoryItem *item = *i; - if (item->DataPointer() == handle) + if (item->dataPointer() == handle) return *item; } @@ -127,7 +127,7 @@ MemoryItem &MemoryManager::operator[](HGLOBAL handle) { */ uint32 MemoryManager::getSize(HGLOBAL handle) { MemoryItem &item = getItem(handle); - return item.Size(); + return item.size(); } /** @@ -150,7 +150,7 @@ void MemoryManager::erase(HGLOBAL handle) { * Stand-alone methods \****************************************************************************/ -void CopyMemory(void *dst, const void *first, int size) { +void copyMemory(void *dst, const void *first, int size) { Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst); } diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index 8d8411c6a1..7f95f8d86f 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -42,9 +42,9 @@ public: MemoryItem(uint32 size); virtual ~MemoryItem(); - uint32 Size() { return _size; } - void *DataPointer() { return (void *)_buffer; } - bool IsValid() { return _buffer != NULL; } + uint32 size() { return _size; } + void *dataPointer() { return (void *)_buffer; } + bool isValid() { return _buffer != NULL; } // Casting for access to data operator void *(); @@ -68,19 +68,19 @@ public: }; // defines -#define GlobalAlloc(flags, size) _vm->_memoryManager.alloc(size, flags) -#define GlobalAllocate(size) _vm->_memoryManager.allocate(size, 0) -#define GlobalFree(handle) _vm->_memoryManager.erase(handle) -#define GlobalLock(handle) (_vm->_memoryManager.getItem(handle).DataPointer()) -#define GlobalUnlock(handle) {} -#define GlobalSize(handle) (_vm->_memoryManager.getItem(handle).Size()) +#define globalAlloc(flags, size) _vm->_memoryManager.alloc(size, flags) +#define globalAllocate(size) _vm->_memoryManager.allocate(size, 0) +#define globalFree(handle) _vm->_memoryManager.erase(handle) +#define globalLock(handle) (_vm->_memoryManager.getItem(handle).dataPointer()) +#define globalUnlock(handle) {} +#define globalSize(handle) (_vm->_memoryManager.getItem(handle).size()) #define GMEM_FIXED 1 #define GMEM_MOVEABLE 2 #define GMEM_ZEROINIT 4 // Stand-alone methods -extern void CopyMemory(void *dst, const void *first, int size); +extern void copyMemory(void *dst, const void *first, int size); } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 16c530206c..95c0b067d5 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -59,16 +59,16 @@ const char *mpalCopyright = /** * Locks the variables for access */ -void LockVar(void) { - GLOBALS.lpmvVars = (LPMPALVAR)GlobalLock(GLOBALS.hVars); +void lockVar(void) { + GLOBALS.lpmvVars = (LPMPALVAR)globalLock(GLOBALS.hVars); } /** * Unlocks variables after use */ -void UnlockVar(void) { - GlobalUnlock(GLOBALS.hVars); +void unlockVar(void) { + globalUnlock(GLOBALS.hVars); } @@ -77,7 +77,7 @@ void UnlockVar(void) { */ static void LockMsg(void) { #ifdef NEED_LOCK_MSGS - GLOBALS.lpmmMsgs = (LPMPALMSG)GlobalLock(GLOBALS.hMsgs); + GLOBALS.lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); #endif } @@ -87,7 +87,7 @@ static void LockMsg(void) { */ static void UnlockMsg(void) { #ifdef NEED_LOCK_MSGS - GlobalUnlock(GLOBALS.hMsgs); + globalUnlock(GLOBALS.hMsgs); #endif } @@ -95,48 +95,48 @@ static void UnlockMsg(void) { /** * Locks the dialogs for access */ -static void LockDialogs(void) { - GLOBALS.lpmdDialogs = (LPMPALDIALOG)GlobalLock(GLOBALS.hDialogs); +static void lockDialogs(void) { + GLOBALS.lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); } /** * Unlocks the dialogs after use */ -static void UnlockDialogs(void) { - GlobalUnlock(GLOBALS.hDialogs); +static void unlockDialogs(void) { + globalUnlock(GLOBALS.hDialogs); } /** * Locks the location data structures for access */ -static void LockLocations(void) { - GLOBALS.lpmlLocations = (LPMPALLOCATION)GlobalLock(GLOBALS.hLocations); +static void lockLocations(void) { + GLOBALS.lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS.hLocations); } /** * Unlocks the location structures after use */ -static void UnlockLocations(void) { - GlobalUnlock(GLOBALS.hLocations); +static void unlockLocations(void) { + globalUnlock(GLOBALS.hLocations); } /** * Locks the items structures for use */ -static void LockItems(void) { - GLOBALS.lpmiItems = (LPMPALITEM)GlobalLock(GLOBALS.hItems); +static void lockItems(void) { + GLOBALS.lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); } /** * Unlocks the items structures after use */ -static void UnlockItems(void) { - GlobalUnlock(GLOBALS.hItems); +static void unlockItems(void) { + globalUnlock(GLOBALS.hItems); } @@ -144,15 +144,15 @@ static void UnlockItems(void) { * Locks the script data structures for use */ static void LockScripts(void) { - GLOBALS.lpmsScripts = (LPMPALSCRIPT)GlobalLock(GLOBALS.hScripts); + GLOBALS.lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); } /** * Unlocks the script data structures after use */ -static void UnlockScripts(void) { - GlobalUnlock(GLOBALS.hScripts); +static void unlockScripts(void) { + globalUnlock(GLOBALS.hScripts); } @@ -161,7 +161,7 @@ static void UnlockScripts(void) { * * @param lpszVarName Name of the variable * @returns Current value - * @remarks Before using this method, you must call LockVar() to + * @remarks Before using this method, you must call lockVar() to * lock the global variablves for use. Then afterwards, you will * need to remember to call UnlockVar() */ @@ -316,19 +316,19 @@ static char *DuplicateMessage(uint32 nMsgOrd) { if (nMsgOrd == (uint32)-1) return NULL; - origmsg = (const char *)GlobalLock(GLOBALS.lpmmMsgs[nMsgOrd].hText); + origmsg = (const char *)globalLock(GLOBALS.lpmmMsgs[nMsgOrd].hText); j = 0; while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') j++; j += 2; - clonemsg = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, j); + clonemsg = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, j); if (clonemsg == NULL) return NULL; - CopyMemory(clonemsg, origmsg, j); - GlobalUnlock(GLOBALS.lpmmMsgs[nMsgOrd].hText); + copyMemory(clonemsg, origmsg, j); + globalUnlock(GLOBALS.lpmmMsgs[nMsgOrd].hText); return clonemsg; } @@ -341,28 +341,28 @@ static char *DuplicateMessage(uint32 nMsgOrd) { * @returns Pointer to the duplicated phrase. Remember to free it * when done with it. */ -static char *DuplicateDialogPeriod(uint32 nPeriod) { +static char *duplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; LPMPALDIALOG dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; int i, j; - for (j = 0; dialog->Periods[j] != NULL; j++) - if (dialog->PeriodNums[j] == nPeriod) { + for (j = 0; dialog->_periods[j] != NULL; j++) + if (dialog->_periodNums[j] == nPeriod) { /* Found the phrase, it should be duplicated */ - origmsg = (const char *)GlobalLock(dialog->Periods[j]); + origmsg = (const char *)globalLock(dialog->_periods[j]); /* Calculate the length and allocate memory */ i = 0; while (origmsg[i] != '\0') i++; - clonemsg = (char *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, i + 1); + clonemsg = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, i + 1); if (clonemsg == NULL) return NULL; - CopyMemory(clonemsg, origmsg, i); + copyMemory(clonemsg, origmsg, i); - GlobalUnlock(dialog->Periods[j]); + globalUnlock(dialog->_periods[j]); return clonemsg; } @@ -402,9 +402,9 @@ HGLOBAL resLoad(uint32 dwId) { if (GLOBALS.hMpr.err()) return NULL; - h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); - buf = (byte *)GlobalLock(h); - temp = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); + h = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); + buf = (byte *)globalLock(h); + temp = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); nBytesRead = GLOBALS.hMpr.read(temp, nSizeComp); if (nBytesRead != nSizeComp) @@ -414,38 +414,38 @@ HGLOBAL resLoad(uint32 dwId) { if (nBytesRead != nSizeDecomp) return NULL; - GlobalFree(temp); - GlobalUnlock(h); + globalFree(temp); + globalUnlock(h); return h; } return NULL; } -static uint32 *GetSelectList(uint32 i) { +static uint32 *getSelectList(uint32 i) { uint32 *sl; - int j,k,num; - LPMPALDIALOG dialog=GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; + int j, k, num; + LPMPALDIALOG dialog = GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; /* Count how many are active selects */ num = 0; - for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) - if (dialog->Choice[i].Select[j].curActive) + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + if (dialog->_choice[i]._select[j].curActive) num++; /* If there are 0, it's a mistake */ if (num == 0) return NULL; - sl= (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + sl= (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); if (sl == NULL) return NULL; /* Copy all the data inside the active select list */ k = 0; - for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) - if (dialog->Choice[i].Select[j].curActive) - sl[k++] = dialog->Choice[i].Select[j].dwData; + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + if (dialog->_choice[i]._select[j].curActive) + sl[k++] = dialog->_choice[i]._select[j].dwData; sl[k] = (uint32)NULL; return sl; @@ -462,7 +462,7 @@ static uint32 *GetItemList(uint32 nLoc) { num++; } - il = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + il = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); if (il == NULL) return NULL; @@ -479,7 +479,7 @@ static uint32 *GetItemList(uint32 nLoc) { return il; } -static LPITEM GetItemData(uint32 nOrdItem) { +static LPITEM getItemData(uint32 nOrdItem) { LPMPALITEM curitem = GLOBALS.lpmiItems+nOrdItem; LPITEM ret; HGLOBAL hDat; @@ -489,13 +489,13 @@ static LPITEM GetItemData(uint32 nOrdItem) { uint32 dim; // Zeroing out the allocated memory is required!!! - ret = (LPITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); + ret = (LPITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); if (ret == NULL) return NULL; ret->speed = 150; hDat = resLoad(curitem->dwRes); - dat = (char *)GlobalLock(hDat); + dat = (char *)globalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { i = dat[3]; // For version 1.0!! @@ -556,11 +556,11 @@ static LPITEM GetItemData(uint32 nOrdItem) { for (i = 1; i < ret->numframe; i++) { dim = (uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); - ret->frames[i] = (char *)GlobalAlloc(GMEM_FIXED,dim); + ret->frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); if (ret->frames[i] == NULL) return NULL; - CopyMemory(ret->frames[i], dat, dim); + copyMemory(ret->frames[i], dat, dim); dat += dim; } @@ -569,8 +569,8 @@ static LPITEM GetItemData(uint32 nOrdItem) { if (i != 0xABCD) return NULL; - GlobalUnlock(hDat); - GlobalFree(hDat); + globalUnlock(hDat); + globalFree(hDat); return ret; } @@ -594,7 +594,7 @@ void CustomThread(CORO_PARAM, const void *param) { CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4); - GlobalFree(_ctx->p); + globalFree(_ctx->p); CORO_END_CODE; } @@ -642,8 +642,8 @@ void ScriptThread(CORO_PARAM, const void *param) { for (_ctx->j = 0; _ctx->j < s->Moment[_ctx->i].nCmds; _ctx->j++) { _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j]; - if (s->Command[_ctx->k].type == 1) { - _ctx->p = (LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); + if (s->_command[_ctx->k].type == 1) { + _ctx->p = (LPCFCALL)globalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) { GLOBALS.mpalError = 1; @@ -651,11 +651,11 @@ void ScriptThread(CORO_PARAM, const void *param) { return; } - _ctx->p->nCf=s->Command[_ctx->k].nCf; - _ctx->p->arg1=s->Command[_ctx->k].arg1; - _ctx->p->arg2=s->Command[_ctx->k].arg2; - _ctx->p->arg3=s->Command[_ctx->k].arg3; - _ctx->p->arg4=s->Command[_ctx->k].arg4; + _ctx->p->nCf=s->_command[_ctx->k].nCf; + _ctx->p->arg1=s->_command[_ctx->k].arg1; + _ctx->p->arg2=s->_command[_ctx->k].arg2; + _ctx->p->arg3=s->_command[_ctx->k].arg3; + _ctx->p->arg4=s->_command[_ctx->k].arg4; // !!! New process management if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { @@ -664,17 +664,17 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_KILL_SELF(); return; } - } else if (s->Command[_ctx->k].type == 2) { - LockVar(); + } else if (s->_command[_ctx->k].type == 2) { + lockVar(); varSetValue( - s->Command[_ctx->k].lpszVarName, - EvaluateExpression(s->Command[_ctx->k].expr) + s->_command[_ctx->k].lpszVarName, + evaluateExpression(s->_command[_ctx->k].expr) ); - UnlockVar(); + unlockVar(); } else { GLOBALS.mpalError = 1; - GlobalFree(s); + globalFree(s); CORO_KILL_SELF(); return; @@ -682,7 +682,7 @@ void ScriptThread(CORO_PARAM, const void *param) { } } - GlobalFree(s); + globalFree(s); CORO_KILL_SELF(); @@ -711,29 +711,29 @@ void ActionThread(CORO_PARAM, const void *param) { for (_ctx->j = 0; _ctx->j < item->Action[item->dwRes].nCmds; _ctx->j++) { _ctx->k = item->Action[item->dwRes].CmdNum[_ctx->j]; - if (item->Command[_ctx->k].type == 1) { + if (item->_command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - CoroScheduler.getCurrentPID(), GLOBALS.lplpFunctionStrings[item->Command[_ctx->k].nCf].c_str(), - item->Command[_ctx->k].arg1, item->Command[_ctx->k].arg2, - item->Command[_ctx->k].arg3, item->Command[_ctx->k].arg4 + CoroScheduler.getCurrentPID(), GLOBALS.lplpFunctionStrings[item->_command[_ctx->k].nCf].c_str(), + item->_command[_ctx->k].arg1, item->_command[_ctx->k].arg2, + item->_command[_ctx->k].arg3, item->_command[_ctx->k].arg4 ); - CORO_INVOKE_4(GLOBALS.lplpFunctions[item->Command[_ctx->k].nCf], - item->Command[_ctx->k].arg1, - item->Command[_ctx->k].arg2, - item->Command[_ctx->k].arg3, - item->Command[_ctx->k].arg4 + CORO_INVOKE_4(GLOBALS.lplpFunctions[item->_command[_ctx->k].nCf], + item->_command[_ctx->k].arg1, + item->_command[_ctx->k].arg2, + item->_command[_ctx->k].arg3, + item->_command[_ctx->k].arg4 ); - } else if (item->Command[_ctx->k].type == 2) { + } else if (item->_command[_ctx->k].type == 2) { // Variable assign debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", - CoroScheduler.getCurrentPID(), item->Command[_ctx->k].lpszVarName); + CoroScheduler.getCurrentPID(), item->_command[_ctx->k].lpszVarName); - LockVar(); - varSetValue(item->Command[_ctx->k].lpszVarName, EvaluateExpression(item->Command[_ctx->k].expr)); - UnlockVar(); + lockVar(); + varSetValue(item->_command[_ctx->k].lpszVarName, evaluateExpression(item->_command[_ctx->k].expr)); + unlockVar(); } else { GLOBALS.mpalError = 1; @@ -741,7 +741,7 @@ void ActionThread(CORO_PARAM, const void *param) { } } - GlobalFree(item); + globalFree(item); debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); @@ -832,7 +832,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { ; /* We look for items without idle actions, and eliminate them from the list */ - LockItems(); + lockItems(); _ctx->nIdleActions = 0; _ctx->nRealItems = 0; for (_ctx->i = 0; _ctx->i < _ctx->numitems; _ctx->i++) { @@ -855,18 +855,18 @@ void LocationPollThread(CORO_PARAM, const void *param) { else _ctx->nRealItems++; } - UnlockItems(); + unlockItems(); /* If there is nothing left, we can exit */ if (_ctx->nRealItems == 0) { - GlobalFree(_ctx->il); + globalFree(_ctx->il); CORO_KILL_SELF(); return; } - _ctx->MyThreads = (MYTHREAD *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); + _ctx->MyThreads = (MYTHREAD *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); if (_ctx->MyThreads == NULL) { - GlobalFree(_ctx->il); + globalFree(_ctx->il); CORO_KILL_SELF(); return; } @@ -874,15 +874,15 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* We have established that there is at least one item that contains idle actions. Now we created the mirrored copies of the idle actions. */ - _ctx->MyActions = (MYACTION *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); + _ctx->MyActions = (MYACTION *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); if (_ctx->MyActions == NULL) { - GlobalFree(_ctx->MyThreads); - GlobalFree(_ctx->il); + globalFree(_ctx->MyThreads); + globalFree(_ctx->il); CORO_KILL_SELF(); return; } - LockItems(); + lockItems(); _ctx->k = 0; for (_ctx->i = 0; _ctx->i < _ctx->numitems; _ctx->i++) { @@ -900,7 +900,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyActions[_ctx->k].perc = _ctx->curItem->Action[_ctx->j].perc; _ctx->MyActions[_ctx->k].when = _ctx->curItem->Action[_ctx->j].when; _ctx->MyActions[_ctx->k].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; - CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, + copyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); _ctx->MyActions[_ctx->k].dwLastTime = _vm->getTime(); @@ -908,10 +908,10 @@ void LocationPollThread(CORO_PARAM, const void *param) { } } - UnlockItems(); + unlockItems(); /* We don't need the item list anymore */ - GlobalFree(_ctx->il); + globalFree(_ctx->il); /* Here's the main loop */ @@ -967,33 +967,33 @@ void LocationPollThread(CORO_PARAM, const void *param) { continue; /* Ok, we are the only ones :) */ - LockItems(); + lockItems(); _ctx->curItem=GLOBALS.lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); /* Check if there is a WhenExecute expression */ _ctx->j=_ctx->MyActions[_ctx->k].nAction; if (_ctx->curItem->Action[_ctx->j].when != NULL) - if (!EvaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { - UnlockItems(); + if (!evaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { + unlockItems(); continue; } /* Ok, we can perform the action. For convenience, we do it in a new process */ - _ctx->newItem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + _ctx->newItem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (_ctx->newItem == false) { - GlobalFree(_ctx->MyThreads); - GlobalFree(_ctx->MyActions); + globalFree(_ctx->MyThreads); + globalFree(_ctx->MyActions); CORO_KILL_SELF(); return; } - CopyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); - UnlockItems(); + copyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); + unlockItems(); /* We copy the action in #0 */ // _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; -// CopyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); +// copyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); _ctx->newItem->dwRes=_ctx->j; /* We will create an action, and will provide the necessary details */ @@ -1006,9 +1006,9 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Create the process if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) { //if ((_ctx->MyThreads[_ctx->i].hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))= = (void*)-1) - GlobalFree(_ctx->newItem); - GlobalFree(_ctx->MyThreads); - GlobalFree(_ctx->MyActions); + globalFree(_ctx->newItem); + globalFree(_ctx->MyThreads); + globalFree(_ctx->MyActions); CORO_KILL_SELF(); return; @@ -1039,8 +1039,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_INVOKE_4(GLOBALS.lplpFunctions[201], 0, 0, 0, 0); /* We're finished */ - GlobalFree(_ctx->MyThreads); - GlobalFree(_ctx->MyActions); + globalFree(_ctx->MyThreads); + globalFree(_ctx->MyActions); CORO_KILL_SELF(); @@ -1078,7 +1078,7 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_END_CODE; } -void DoChoice(CORO_PARAM, uint32 nChoice); +void doChoice(CORO_PARAM, uint32 nChoice); /** @@ -1097,41 +1097,41 @@ void GroupThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); // Lock the _ctx->dialog - LockDialogs(); + lockDialogs(); // Find the pointer to the current _ctx->dialog _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; // Search inside the group requesting the _ctx->dialog - for (_ctx->i = 0; _ctx->dialog->Group[_ctx->i].num != 0; _ctx->i++) { - if (_ctx->dialog->Group[_ctx->i].num == nGroup) { + for (_ctx->i = 0; _ctx->dialog->_group[_ctx->i].num != 0; _ctx->i++) { + if (_ctx->dialog->_group[_ctx->i].num == nGroup) { // Cycle through executing the commands of the group - for (_ctx->j = 0; _ctx->j < _ctx->dialog->Group[_ctx->i].nCmds; _ctx->j++) { - _ctx->k = _ctx->dialog->Group[_ctx->i].CmdNum[_ctx->j]; + for (_ctx->j = 0; _ctx->j < _ctx->dialog->_group[_ctx->i].nCmds; _ctx->j++) { + _ctx->k = _ctx->dialog->_group[_ctx->i].CmdNum[_ctx->j]; - _ctx->type = _ctx->dialog->Command[_ctx->k].type; + _ctx->type = _ctx->dialog->_command[_ctx->k].type; if (_ctx->type == 1) { // Call custom function - CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->dialog->Command[_ctx->k].nCf], - _ctx->dialog->Command[_ctx->k].arg1, - _ctx->dialog->Command[_ctx->k].arg2, - _ctx->dialog->Command[_ctx->k].arg3, - _ctx->dialog->Command[_ctx->k].arg4 + CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->dialog->_command[_ctx->k].nCf], + _ctx->dialog->_command[_ctx->k].arg1, + _ctx->dialog->_command[_ctx->k].arg2, + _ctx->dialog->_command[_ctx->k].arg3, + _ctx->dialog->_command[_ctx->k].arg4 ); } else if (_ctx->type == 2) { // Set a variable - LockVar(); - varSetValue(_ctx->dialog->Command[_ctx->k].lpszVarName, EvaluateExpression(_ctx->dialog->Command[_ctx->k].expr)); - UnlockVar(); + lockVar(); + varSetValue(_ctx->dialog->_command[_ctx->k].lpszVarName, evaluateExpression(_ctx->dialog->_command[_ctx->k].expr)); + unlockVar(); } else if (_ctx->type == 3) { // DoChoice: call the chosen function - CORO_INVOKE_1(DoChoice, (uint32)_ctx->dialog->Command[_ctx->k].nChoice); + CORO_INVOKE_1(doChoice, (uint32)_ctx->dialog->_command[_ctx->k].nChoice); } else { GLOBALS.mpalError = 1; - UnlockDialogs(); + unlockDialogs(); CORO_KILL_SELF(); return; @@ -1148,7 +1148,7 @@ void GroupThread(CORO_PARAM, const void *param) { /* If we are here, it means that we have not found the requested group */ GLOBALS.mpalError = 1; - UnlockDialogs(); + unlockDialogs(); CORO_KILL_SELF(); @@ -1161,7 +1161,7 @@ void GroupThread(CORO_PARAM, const void *param) { * * @param nChoice Number of choice to perform */ -void DoChoice(CORO_PARAM, uint32 nChoice) { +void doChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CONTEXT; LPMPALDIALOG dialog; int i, j, k; @@ -1171,21 +1171,21 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CODE(_ctx); /* Lock the dialogs */ - LockDialogs(); + lockDialogs(); /* Get a pointer to the current dialog */ _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; /* Search the choice between those required in the dialog */ - for (_ctx->i = 0; _ctx->dialog->Choice[_ctx->i].nChoice != 0; _ctx->i++) - if (_ctx->dialog->Choice[_ctx->i].nChoice == nChoice) + for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) + if (_ctx->dialog->_choice[_ctx->i].nChoice == nChoice) break; /* If nothing has been found, exit with an error */ - if (_ctx->dialog->Choice[_ctx->i].nChoice == 0) { + if (_ctx->dialog->_choice[_ctx->i].nChoice == 0) { /* If we're here, we did not find the required choice */ GLOBALS.mpalError = 1; - UnlockDialogs(); + unlockDialogs(); CORO_KILL_SELF(); return; @@ -1199,19 +1199,19 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { _ctx->k = 0; /* Calculate the expression of each selection, to see if they're active or inactive */ - for (_ctx->j = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].dwData != 0; _ctx->j++) - if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].when == NULL) { - _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 1; + for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].dwData != 0; _ctx->j++) + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when == NULL) { + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; _ctx->k++; - } else if (EvaluateExpression(_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].when)) { - _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 1; + } else if (evaluateExpression(_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when)) { + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; _ctx->k++; } else - _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].curActive = 0; + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 0; /* If there are no choices activated, then the dialog is finished. */ if (_ctx->k == 0) { - UnlockDialogs(); + unlockDialogs(); break; } @@ -1223,21 +1223,21 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { /* Now that the choice has been made, we can run the groups associated with the choice tbontbtitq */ _ctx->j = GLOBALS.nSelectedChoice; - for (_ctx->k = 0; _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { - _ctx->nGroup = _ctx->dialog->Choice[_ctx->i].Select[_ctx->j].wPlayGroup[_ctx->k]; + for (_ctx->k = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { + _ctx->nGroup = _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); } /* Control attribute */ - if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 0)) { + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 0)) { /* Bit 0 set: the end of the choice */ - UnlockDialogs(); + unlockDialogs(); break; } - if (_ctx->dialog->Choice[_ctx->i].Select[_ctx->j].attr & (1 << 1)) { + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 1)) { /* Bit 1 set: the end of the dialog */ - UnlockDialogs(); + unlockDialogs(); CORO_KILL_SELF(); return; @@ -1265,7 +1265,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) { * the itemGetOrderFromNum() function. The items list must first be locked * by calling LockItem(). */ -static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { +static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = GLOBALS.lpmiItems; int i; LPMPALITEM newitem; @@ -1284,20 +1284,20 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { continue; if (item->Action[i].when != NULL) { - if (!EvaluateExpression(item->Action[i].when)) + if (!evaluateExpression(item->Action[i].when)) continue; } // Now we find the right action to be performed // Duplicate the item and copy the current action in #i into #0 - newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + newitem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (newitem == NULL) return CORO_INVALID_PID_VALUE; // In the new version number of the action in writing dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); /* newitem->Action[0].nCmds=item->Action[i].nCmds; - CopyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); + copyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); */ newitem->dwRes = i; @@ -1331,7 +1331,7 @@ static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * so that must inform through an event and when 'necessary to you make a choice. * The data on the choices may be obtained through various queries. */ -static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { +static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { uint32 h; // Store the running dialog in a global variable @@ -1368,15 +1368,15 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) { * @param dwData Since combined with select selection * @returns True if everything is OK, false on failure */ -bool DoSelection(uint32 i, uint32 dwData) { +bool doSelection(uint32 i, uint32 dwData) { LPMPALDIALOG dialog = GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; int j; - for (j = 0; dialog->Choice[i].Select[j].dwData != 0; j++) - if (dialog->Choice[i].Select[j].dwData == dwData && dialog->Choice[i].Select[j].curActive != 0) + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + if (dialog->_choice[i]._select[j].dwData == dwData && dialog->_choice[i]._select[j].curActive != 0) break; - if (dialog->Choice[i].Select[j].dwData == 0) + if (dialog->_choice[i]._select[j].dwData == 0) return false; GLOBALS.nSelectedChoice = j; @@ -1433,7 +1433,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (hMpc.err()) return false; - byte *lpMpcImage = (byte *)GlobalAlloc(GMEM_FIXED, dwSizeDecomp + 16); + byte *lpMpcImage = (byte *)globalAlloc(GMEM_FIXED, dwSizeDecomp + 16); if (lpMpcImage == NULL) return false; @@ -1443,7 +1443,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (hMpc.err()) return false; - cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED, dwSizeComp); + cmpbuf = (byte *)globalAlloc(GMEM_FIXED, dwSizeComp); if (cmpbuf == NULL) return false; @@ -1456,7 +1456,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != dwSizeDecomp) return false; - GlobalFree(cmpbuf); + globalFree(cmpbuf); } else { /* If the file is not compressed, we directly read in the data */ nBytesRead = hMpc.read(lpMpcImage, dwSizeDecomp); @@ -1471,7 +1471,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (ParseMpc(lpMpcImage) == false) return false; - GlobalFree(lpMpcImage); + globalFree(lpMpcImage); /* Calculate memory usage */ /* @@ -1513,11 +1513,11 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, /* Move to the start of the resources header */ GLOBALS.hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); - GLOBALS.lpResources = (uint32 *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS.nResources * 8); + GLOBALS.lpResources = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS.nResources * 8); if (GLOBALS.lpResources == NULL) return false; - cmpbuf = (byte *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); + cmpbuf = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); if (cmpbuf == NULL) return false; @@ -1529,7 +1529,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != (uint32)GLOBALS.nResources * 8) return false; - GlobalFree(cmpbuf); + globalFree(cmpbuf); /* Reset back to the start of the file, leaving it open */ GLOBALS.hMpr.seek(0, SEEK_SET); @@ -1580,9 +1580,9 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName); */ - LockVar(); + lockVar(); dwRet = (uint32)varGetValue(GETARG(char *)); - UnlockVar(); + unlockVar(); } else if (wQueryType == MPQ_MESSAGE) { /* @@ -1595,16 +1595,16 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); */ - LockVar(); + lockVar(); buf = Common::String::format("Pattern.%u", GETARG(uint32)); dwRet = (uint32)varGetValue(buf.c_str()); - UnlockVar(); + unlockVar(); } else if (wQueryType == MPQ_LOCATION_SIZE) { /* * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); */ - LockLocations(); + lockLocations(); x = locGetOrderFromNum(GETARG(uint32)); y = GETARG(uint32); if (x != -1) { @@ -1617,7 +1617,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { } else GLOBALS.mpalError = 1; - UnlockLocations(); + unlockLocations(); } else if (wQueryType == MPQ_LOCATION_IMAGE) { /* @@ -1647,7 +1647,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); */ - LockVar(); + lockVar(); x = GETARG(uint32); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) @@ -1655,26 +1655,26 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { else dwRet = (uint32)true; - UnlockVar(); + unlockVar(); } else if (wQueryType == MPQ_ITEM_NAME) { /* * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); */ - LockVar(); + lockVar(); x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0]='\0'; else { - LockItems(); + lockItems(); y = itemGetOrderFromNum(x); - CopyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); - UnlockItems(); + copyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + unlockItems(); } - UnlockVar(); + unlockVar(); } else if (wQueryType == MPQ_DIALOG_PERIOD) { /* @@ -1698,43 +1698,43 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); */ - LockDialogs(); + lockDialogs(); x = GETARG(uint32); y = GETARG(uint32); - dwRet = (uint32)DoSelection(x, y); + dwRet = (uint32)doSelection(x, y); - UnlockDialogs(); + unlockDialogs(); } else if (wQueryType == MPQ_DO_ACTION) { /* * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam); */ - LockItems(); - LockVar(); + lockItems(); + lockVar(); x = GETARG(uint32); z = GETARG(uint32); y = itemGetOrderFromNum(z); if (y != -1) { - dwRet = DoAction(x, y, GETARG(uint32)); + dwRet = doAction(x, y, GETARG(uint32)); } else { dwRet = CORO_INVALID_PID_VALUE; GLOBALS.mpalError = 1; } - UnlockVar(); - UnlockItems(); + unlockVar(); + unlockItems(); } else if (wQueryType == MPQ_DO_DIALOG) { /* * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); */ if (!GLOBALS.bExecutingDialog) { - LockDialogs(); + lockDialogs(); x = dialogGetOrderFromNum(GETARG(uint32)); y = GETARG(uint32); - dwRet = DoDialog(x, y); - UnlockDialogs(); + dwRet = doDialog(x, y); + unlockDialogs(); } } else { /* @@ -1802,10 +1802,10 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); */ - LockLocations(); + lockLocations(); x = locGetOrderFromNum(GETARG(uint32)); hRet = resLoad(GLOBALS.lpmlLocations[x].dwPicRes); - UnlockLocations(); + unlockLocations(); } else if (wQueryType == MPQ_RESOURCE) { /* @@ -1817,17 +1817,17 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc); */ - LockVar(); + lockVar(); hRet = GetItemList(GETARG(uint32)); - LockVar(); + lockVar(); } else if (wQueryType == MPQ_ITEM_DATA) { /* * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); */ - LockItems(); - hRet = GetItemData(itemGetOrderFromNum(GETARG(uint32))); - UnlockItems(); + lockItems(); + hRet = getItemData(itemGetOrderFromNum(GETARG(uint32))); + unlockItems(); } else if (wQueryType == MPQ_ITEM_IS_ACTIVE) { /* @@ -1839,29 +1839,29 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char *lpszName); */ - LockVar(); + lockVar(); x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0] = '\0'; else { - LockItems(); + lockItems(); y = itemGetOrderFromNum(x); - CopyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); - UnlockItems(); + copyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + unlockItems(); } - UnlockVar(); + unlockVar(); } else if (wQueryType == MPQ_DIALOG_PERIOD) { /* * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); */ - LockDialogs(); + lockDialogs(); y = GETARG(uint32); - hRet = DuplicateDialogPeriod(y); - UnlockDialogs(); + hRet = duplicateDialogPeriod(y); + unlockDialogs(); } else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) { /* @@ -1873,9 +1873,9 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice); */ - LockDialogs(); - hRet = GetSelectList(GETARG(uint32)); - UnlockDialogs(); + lockDialogs(); + hRet = getSelectList(GETARG(uint32)); + unlockDialogs(); } else if (wQueryType == MPQ_DIALOG_SELECTION) { /* @@ -1969,12 +1969,12 @@ bool mpalExecuteScript(int nScript) { LockScripts(); n = scriptGetOrderFromNum(nScript); - s = (LPMPALSCRIPT)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); + s = (LPMPALSCRIPT)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); if (s == NULL) return false; - CopyMemory(s, GLOBALS.lpmsScripts + n, sizeof(MPALSCRIPT)); - UnlockScripts(); + copyMemory(s, GLOBALS.lpmsScripts + n, sizeof(MPALSCRIPT)); + unlockScripts(); // !!! New process management if (CoroScheduler.createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == CORO_INVALID_PID_VALUE) @@ -2082,10 +2082,10 @@ int mpalGetSaveStateSize(void) { * @param buf Buffer where to store the state */ void mpalSaveState(byte *buf) { - LockVar(); + lockVar(); WRITE_LE_UINT32(buf, GLOBALS.nVars); - CopyMemory(buf + 4, (byte *)GLOBALS.lpmvVars, GLOBALS.nVars * sizeof(MPALVAR)); - UnlockVar(); + copyMemory(buf + 4, (byte *)GLOBALS.lpmvVars, GLOBALS.nVars * sizeof(MPALVAR)); + unlockVar(); } @@ -2097,14 +2097,14 @@ void mpalSaveState(byte *buf) { */ int mpalLoadState(byte *buf) { // We must destroy and recreate all the variables - GlobalFree(GLOBALS.hVars); + globalFree(GLOBALS.hVars); GLOBALS.nVars = READ_LE_UINT32(buf); - GLOBALS.hVars = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); - LockVar(); - CopyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); - UnlockVar(); + GLOBALS.hVars = globalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); + lockVar(); + copyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); + unlockVar(); return GLOBALS.nVars * sizeof(MPALVAR) + 4; } @@ -2170,7 +2170,7 @@ const MsgCommentsStruct MsgComments[] = { { 0, 0, NULL } }; -void OutputStartMsgComment(uint16 wNum, Common::OutSaveFile *f) { +void outputStartMsgComment(uint16 wNum, Common::OutSaveFile *f) { int i; for (i = 0; MsgComments[i].wStart != 0; i++) @@ -2225,7 +2225,7 @@ int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { } -void OutputEndOther(uint16 wNum, Common::OutSaveFile *f) { +void outputEndOther(uint16 wNum, Common::OutSaveFile *f) { int i; for (i = 0; MsgComments[i].wStart != 0; i++) @@ -2258,7 +2258,7 @@ void mpalDumpMessages(void) { f->writeString("\n\n
\n"); for (i = 0; i < GLOBALS.nMsgs; i++) { - lpMessage = (char*)GlobalLock(GLOBALS.lpmmMsgs[i].hText); + lpMessage = (char *)globalLock(GLOBALS.lpmmMsgs[i].hText); if (*lpMessage != '\0') { // bernie: debug /*if (GLOBALS.lpmmMsgs[i].wNum == 1950) { @@ -2266,9 +2266,9 @@ void mpalDumpMessages(void) { }*/ nPeriods = 1; - p=lpPeriods[0] = lpMessage; + p = lpPeriods[0] = lpMessage; - OutputStartMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); + outputStartMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); while (1) { // Find the end of the current period @@ -2313,7 +2313,7 @@ void mpalDumpMessages(void) { OutputEndMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); - GlobalUnlock(GLOBALS.lpmmMsgs[i].hText); + globalUnlock(GLOBALS.lpmmMsgs[i].hText); } } @@ -2351,10 +2351,10 @@ void mpalDumpOthers(void) { f->writeString("\n\n"); for (i = 0; i < GLOBALS.nMsgs; i++) { - lpMessage = (char*)GlobalLock(GLOBALS.lpmmMsgs[i].hText); + lpMessage = (char *)globalLock(GLOBALS.lpmmMsgs[i].hText); if (*lpMessage != '\0') { nPeriods = 1; - p=lpPeriods[0] = lpMessage; + p = lpPeriods[0] = lpMessage; if (OutputStartOther(GLOBALS.lpmmMsgs[i].wNum, f)) { while (1) { @@ -2399,9 +2399,9 @@ void mpalDumpOthers(void) { } } - OutputEndOther(GLOBALS.lpmmMsgs[i].wNum, f); + outputEndOther(GLOBALS.lpmmMsgs[i].wNum, f); - GlobalUnlock(GLOBALS.lpmmMsgs[i].hText); + globalUnlock(GLOBALS.lpmmMsgs[i].hText); } } @@ -2735,7 +2735,7 @@ case num: \ return DLG##num[nPers]; -const char *GetPersonName(uint16 nDlg, int nPers) { +const char *getPersonName(uint16 nDlg, int nPers) { switch (nDlg) { HANDLE_DIALOG(10); HANDLE_DIALOG(51); @@ -2821,11 +2821,11 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { f->writeString("\n\n"); - for (g = 0;dlg->Group[g].num != 0; g++) { + for (g = 0; dlg->_group[g].num != 0; g++) { bAtLeastOne = false; - for (c = 0; cGroup[g].nCmds; c++) { - curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; + for (c = 0; c_group[g].nCmds; c++) { + curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; if (curCmd->type == 1 && curCmd->nCf == 71) { bAtLeastOne = true; break; @@ -2838,23 +2838,23 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { f->writeString(Common::String::format("

\n

Group %d

\n

\n", g)); f->writeString("

\n"); - for (c = 0;cGroup[g].nCmds; c++) { - curCmd = &dlg->Command[dlg->Group[g].CmdNum[c]]; + for (c = 0; c < dlg->_group[g].nCmds; c++) { + curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; // If it's a custom function, call SendDialogMessage(nPers, nMsg) if (curCmd->type == 1 && curCmd->nCf == 71) { sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->arg2); - for (j = 0; dlg->Periods[j] != NULL; j++) - if (dlg->PeriodNums[j] == curCmd->arg2) + for (j = 0; dlg->_periods[j] != NULL; j++) + if (dlg->_periodNums[j] == curCmd->arg2) break; - if (dlg->Periods[j] == NULL) + if (dlg->_periods[j] == NULL) warning("ERROR: Dialog %d, Period %d not found!", (int)dlg->nObj, (int)curCmd->arg2); else { - frase = (char *)GlobalLock(dlg->Periods[j]); + frase = (char *)globalLock(dlg->_periods[j]); strcpy(copia, frase); - GlobalUnlock(dlg->Periods[j]); + globalUnlock(dlg->_periods[j]); while ((p = strchr(copia,'^')) != NULL) *p = '\"'; @@ -2869,7 +2869,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { f->writeString("\t\n"); f->writeString(Common::String::format("\t\t\n", fname)); f->writeString(Common::String::format("\t\t\n", - GetPersonName(dlg->nObj, curCmd->arg1))); + getPersonName(dlg->nObj, curCmd->arg1))); f->writeString(Common::String::format("\t\t\n",copia)); f->writeString("\t\n"); //fprintf(f, "(%s) <%s> %s\n", fname, GetPersonName(dlg->nObj, curCmd->arg1), copia); @@ -2890,12 +2890,12 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { void mpalDumpDialogs(void) { int i; - LockDialogs(); + lockDialogs(); for (i = 0; i < GLOBALS.nDialogs; i++) mpalDumpDialog(&GLOBALS.lpmdDialogs[i]); - UnlockDialogs(); + unlockDialogs(); } } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 1bf19ef1bb..fb3d019051 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -519,13 +519,13 @@ int mpalGetSaveStateSize(void); /** * Locks the variables for access */ -void LockVar(void); +void lockVar(void); /** * Unlocks variables after use */ -void UnlockVar(void); +void unlockVar(void); } // end of namespace MPAL diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 44d817d748..e331335315 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -144,7 +144,7 @@ struct command { struct MPALDIALOG { uint32 nObj; // Dialog number - struct command Command[MAX_COMMANDS_PER_DIALOG]; + struct command _command[MAX_COMMANDS_PER_DIALOG]; struct { uint16 num; @@ -152,7 +152,7 @@ struct MPALDIALOG { byte nCmds; uint16 CmdNum[MAX_COMMANDS_PER_GROUP]; - } Group[MAX_GROUPS_PER_DIALOG]; + } _group[MAX_GROUPS_PER_DIALOG]; struct { // The last choice has nChoice == 0 @@ -170,12 +170,12 @@ struct MPALDIALOG { // Modified at run-time: 0 if the select is currently disabled, // and 1 if currently active byte curActive; - } Select[MAX_SELECTS_PER_CHOICE]; + } _select[MAX_SELECTS_PER_CHOICE]; - } Choice[MAX_CHOICES_PER_DIALOG]; + } _choice[MAX_CHOICES_PER_DIALOG]; - uint16 PeriodNums[MAX_PERIODS_PER_DIALOG]; - HGLOBAL Periods[MAX_PERIODS_PER_DIALOG]; + uint16 _periodNums[MAX_PERIODS_PER_DIALOG]; + HGLOBAL _periods[MAX_PERIODS_PER_DIALOG]; } PACKED_STRUCT; typedef MPALDIALOG *LPMPALDIALOG; @@ -204,7 +204,7 @@ struct MPALITEM { byte nActions; // Number of managed actions uint32 dwRes; // Resource that contains frames and patterns - struct command Command[MAX_COMMANDS_PER_ITEM]; + struct command _command[MAX_COMMANDS_PER_ITEM]; // Pointer to array of structures containing various managed activities. In practice, of // every action we know what commands to run, including those defined in structures above @@ -223,7 +223,7 @@ struct MPALSCRIPT { uint32 nMoments; - struct command Command[MAX_COMMANDS_PER_SCRIPT]; + struct command _command[MAX_COMMANDS_PER_SCRIPT]; struct { int32 dwTime; diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index edc6e65ca1..bce623e43c 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -41,7 +41,7 @@ RMRes::RMRes(uint32 resID) { if (_h == NULL) _h = mpalQueryResource(resID); if (_h != NULL) - _buf = (byte *)GlobalLock(_h); + _buf = (byte *)globalLock(_h); } /** @@ -49,8 +49,8 @@ RMRes::RMRes(uint32 resID) { */ RMRes::~RMRes() { if (_h != NULL) { - GlobalUnlock(_h); - GlobalFree(_h); + globalUnlock(_h); + globalFree(_h); } } @@ -72,7 +72,7 @@ RMRes::operator const byte *() { * Returns the size of the resource */ unsigned int RMRes::size() { - return GlobalSize(_h); + return globalSize(_h); } /****************************************************************************\ -- cgit v1.2.3 From 1866cbd0fb0d7df1c1a4059e98b5d0f6d851c2d4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 8 Jun 2012 08:44:14 +0200 Subject: TONY: start renaming globals --- engines/tony/mpal/mpalutils.cpp | 4 ++-- engines/tony/mpal/mpalutils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index bce623e43c..aba92a86cd 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -85,12 +85,12 @@ RMResRaw::RMResRaw(uint32 resID) : RMRes(resID) { RMResRaw::~RMResRaw() { } -const byte *RMResRaw::DataPointer() { +const byte *RMResRaw::dataPointer() { return _buf + 8; } RMResRaw::operator const byte *() { - return DataPointer(); + return dataPointer(); } int RMResRaw::width() { diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index a428a40a64..19810cf3a1 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -54,7 +54,7 @@ public: RMResRaw(uint32 resID); virtual ~RMResRaw(); - const byte *DataPointer(); + const byte *dataPointer(); operator const byte*(); int width(); -- cgit v1.2.3 From d4777379d23b70aa07feec3ef2e90fcf376f4117 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 8 Jun 2012 23:00:48 +1000 Subject: TONY: Refactored the memory manager to increase performance --- engines/tony/mpal/expr.cpp | 4 +- engines/tony/mpal/expr.h | 2 + engines/tony/mpal/loadmpc.cpp | 16 +++--- engines/tony/mpal/memory.cpp | 128 +++++++++++++++++------------------------- engines/tony/mpal/memory.h | 53 ++++++++--------- engines/tony/mpal/mpal.cpp | 15 ++--- engines/tony/mpal/mpal.h | 7 +-- 7 files changed, 96 insertions(+), 129 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 0b51724330..5ba2fff442 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -238,7 +238,7 @@ static int evaluateAndFreeExpression(byte *expr) { // 3) Risoluzione algebrica solve(one, num); val = one->val.num; - globalFree(expr); + globalDestroy(expr); return val; } @@ -263,7 +263,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { if (num == 0) return NULL; - *h = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); + *h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); if (*h == NULL) return NULL; diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 7d33e5c8ca..9844add822 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -29,6 +29,8 @@ #ifndef MPAL_EXPR_H #define MPAL_EXPR_H +#include "tony/mpal/memory.h" + namespace Tony { namespace MPAL { diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 8f07102aa3..5a338b24b0 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -149,7 +149,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { for (i = 0; i < num; i++) { lpmdDialog->_periodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->_periods[i] = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); + lpmdDialog->_periods[i] = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, *lpBuf + 1); lpLock = (byte *)globalLock(lpmdDialog->_periods[i]); Common::copy(lpBuf + 1, lpBuf + 1 + *lpBuf, lpLock); globalUnlock(lpmdDialog->_periods[i]); @@ -478,7 +478,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS.nVars = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS.hVars = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars); + GLOBALS.hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars); if (GLOBALS.hVars == NULL) return false; @@ -507,7 +507,7 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; #ifdef NEED_LOCK_MSGS - GLOBALS.hMsgs = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs); + GLOBALS.hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs); if (GLOBALS.hMsgs == NULL) return false; @@ -525,7 +525,7 @@ bool ParseMpc(const byte *lpBuf) { for (j = 0; lpBuf[j] != 0;) j += lpBuf[j] + 1; - GLOBALS.lpmmMsgs->hText = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); + GLOBALS.lpmmMsgs->hText = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); lpTemp2 = lpTemp = (byte *)globalLock(GLOBALS.lpmmMsgs->hText); for (j = 0; lpBuf[j] != 0;) { @@ -560,7 +560,7 @@ bool ParseMpc(const byte *lpBuf) { if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) { GLOBALS.nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS.hDialogs = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG)); + GLOBALS.hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG)); if (GLOBALS.hDialogs == NULL) return false; @@ -581,7 +581,7 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS.hItems = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); + GLOBALS.hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); if (GLOBALS.hItems == NULL) return false; @@ -602,7 +602,7 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS.hLocations = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); + GLOBALS.hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); if (GLOBALS.hLocations == NULL) return false; @@ -623,7 +623,7 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory - GLOBALS.hScripts = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); + GLOBALS.hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); if (GLOBALS.hScripts == NULL) return false; diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index b5bd77f838..b50f9d7c37 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -29,123 +29,101 @@ namespace Tony { namespace MPAL { -/****************************************************************************\ -* MemoryItem methods -\****************************************************************************/ - -/** - * Constructor - * @param Data sizee - */ -MemoryItem::MemoryItem(uint32 size) { - _size = size; - _buffer = (size == 0) ? NULL : new byte[size]; -} - -/** - * Destructor - */ -MemoryItem::~MemoryItem() { - delete[] _buffer; -} - -/** - * Returns a pointer to the resource - */ -MemoryItem::operator void *() { - return dataPointer(); -} - /****************************************************************************\ * MemoryManager methods \****************************************************************************/ -MemoryManager::MemoryManager() { -} - -/** - * Destructor - */ -MemoryManager::~MemoryManager() { - Common::List::iterator i; - for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) { - MemoryItem *item = *i; - delete item; - } -} +const int BLOCK_ID = 0x12345678; /** * Allocates a new memory block - * @returns Returns a MemoryItem instance for the new block + * @return Returns a MemoryItem instance for the new block */ -MemoryItem &MemoryManager::allocate(uint32 size, uint flags) { - MemoryItem *newItem = new MemoryItem(size); +HANDLE MemoryManager::allocate(uint32 size, uint flags) { + MemoryItem *newItem = (MemoryItem *)malloc(sizeof(MemoryItem) + size); + newItem->_id = BLOCK_ID; + newItem->_size = size; + newItem->_lockCount = 0; + + // If requested, clear the allocated data block if ((flags & GMEM_ZEROINIT) != 0) { - byte *dataP = (byte *)newItem->dataPointer(); + byte *dataP = newItem->_data; Common::fill(dataP, dataP + size, 0); } - _memoryBlocks.push_back(newItem); - - return *newItem; + return (HANDLE)newItem; } /** * Allocates a new memory block and returns its data pointer - * @returns Data pointer to allocated block + * @return Data pointer to allocated block */ -HGLOBAL MemoryManager::alloc(uint32 size, uint flags) { - MemoryItem &newItem = allocate(size, flags); - return (HGLOBAL)newItem.dataPointer(); +void *MemoryManager::alloc(uint32 size, uint flags) { + MemoryItem *item = (MemoryItem *)allocate(size, flags); + ++item->_lockCount; + return &item->_data[0]; } +#define OFFSETOF(type, field) ((unsigned long) &(((type *) 0)->field)) + /** * Returns a reference to the MemoryItem for a gien byte pointer * @param block Byte pointer */ -MemoryItem &MemoryManager::getItem(HGLOBAL handle) { - Common::List::iterator i; - for (i = _memoryBlocks.begin(); i != _memoryBlocks.end(); ++i) { - MemoryItem *item = *i; - if (item->dataPointer() == handle) - return *item; - } - - error("Could not locate a memory block"); +MemoryItem *MemoryManager::getItem(HGLOBAL handle) { + MemoryItem *rec = (MemoryItem *)((byte *)handle - OFFSETOF(MemoryItem, _data)); + assert(rec->_id == BLOCK_ID); + return rec; } /** - * Square bracketes operator - * @param block Byte pointer + * Returns a size of a memory block given its pointer */ -MemoryItem &MemoryManager::operator[](HGLOBAL handle) { - return getItem(handle); +uint32 MemoryManager::getSize(HANDLE handle) { + MemoryItem *item = (MemoryItem *)handle; + assert(item->_id == BLOCK_ID); + return item->_size; } /** - * Returns a size of a memory block given its pointer + * Erases a given item */ -uint32 MemoryManager::getSize(HGLOBAL handle) { - MemoryItem &item = getItem(handle); - return item.size(); +void MemoryManager::freeBlock(HANDLE handle) { + MemoryItem *item = (MemoryItem *)handle; + assert(item->_id == BLOCK_ID); + free(item); } /** * Erases a given item */ -void MemoryManager::erase(MemoryItem *item) { - delete item; - _memoryBlocks.remove(item); +void MemoryManager::destroyItem(HANDLE handle) { + MemoryItem *item = getItem(handle); + assert(item->_id == BLOCK_ID); + free(item); } /** - * Erases a given item + * Locks an item for access */ -void MemoryManager::erase(HGLOBAL handle) { - MemoryItem &item = getItem(handle); - erase(&item); +byte *MemoryManager::lockItem(HANDLE handle) { + MemoryItem *item = (MemoryItem *)handle; + assert(item->_id == BLOCK_ID); + ++item->_lockCount; + return &item->_data[0]; } +/** + * Unlocks a locked item + */ +void MemoryManager::unlockItem(HANDLE handle) { + MemoryItem *item = (MemoryItem *)handle; + assert(item->_id == BLOCK_ID); + assert(item->_lockCount > 0); + --item->_lockCount; +} + + /****************************************************************************\ * Stand-alone methods \****************************************************************************/ diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index 7f95f8d86f..52d527544a 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -34,46 +34,37 @@ namespace MPAL { typedef void *HANDLE; typedef HANDLE HGLOBAL; -class MemoryItem { -protected: - byte *_buffer; +struct MemoryItem { + uint32 _id; uint32 _size; -public: - MemoryItem(uint32 size); - virtual ~MemoryItem(); - - uint32 size() { return _size; } - void *dataPointer() { return (void *)_buffer; } - bool isValid() { return _buffer != NULL; } - - // Casting for access to data - operator void *(); + int _lockCount; + byte _data[1]; + + // Casting for access to data + operator void *() { return &_data[0]; } }; class MemoryManager { private: - Common::List _memoryBlocks; + static MemoryItem *getItem(HGLOBAL handle); public: - MemoryManager(); - virtual ~MemoryManager(); - - MemoryItem &allocate(uint32 size, uint flags); - HGLOBAL alloc(uint32 size, uint flags); - MemoryItem &getItem(HGLOBAL handle); - MemoryItem &operator[](HGLOBAL handle); - void erase(MemoryItem *item); - void erase(HGLOBAL handle); - - uint32 getSize(HANDLE handle); + static HANDLE allocate(uint32 size, uint flags); + static void *alloc(uint32 size, uint flags); + static void freeBlock(HANDLE handle); + static void destroyItem(HANDLE handle); + static uint32 getSize(HANDLE handle); + static byte *lockItem(HANDLE handle); + static void unlockItem(HANDLE handle); }; // defines -#define globalAlloc(flags, size) _vm->_memoryManager.alloc(size, flags) -#define globalAllocate(size) _vm->_memoryManager.allocate(size, 0) -#define globalFree(handle) _vm->_memoryManager.erase(handle) -#define globalLock(handle) (_vm->_memoryManager.getItem(handle).dataPointer()) -#define globalUnlock(handle) {} -#define globalSize(handle) (_vm->_memoryManager.getItem(handle).size()) +#define globalAlloc(flags, size) MemoryManager::alloc(size, flags) +#define globalAllocate(flags, size) MemoryManager::allocate(size, flags) +#define globalFree(handle) MemoryManager::freeBlock(handle) +#define globalDestroy(handle) MemoryManager::destroyItem(handle) +#define globalLock(handle) MemoryManager::lockItem(handle) +#define globalUnlock(handle) MemoryManager::unlockItem(handle) +#define globalSize(handle) MemoryManager::getSize(handle) #define GMEM_FIXED 1 #define GMEM_MOVEABLE 2 diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 95c0b067d5..425fe187fc 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -402,7 +402,7 @@ HGLOBAL resLoad(uint32 dwId) { if (GLOBALS.hMpr.err()) return NULL; - h = globalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); + h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); buf = (byte *)globalLock(h); temp = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); @@ -414,7 +414,7 @@ HGLOBAL resLoad(uint32 dwId) { if (nBytesRead != nSizeDecomp) return NULL; - globalFree(temp); + globalDestroy(temp); globalUnlock(h); return h; } @@ -741,7 +741,7 @@ void ActionThread(CORO_PARAM, const void *param) { } } - globalFree(item); + globalDestroy(item); debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); @@ -803,6 +803,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } MYTHREAD; CORO_BEGIN_CONTEXT; + // TODO: Requires endian fix uint32 *il; int i, j, k; int numitems; @@ -859,7 +860,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* If there is nothing left, we can exit */ if (_ctx->nRealItems == 0) { - globalFree(_ctx->il); + globalDestroy(_ctx->il); CORO_KILL_SELF(); return; } @@ -1456,7 +1457,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != dwSizeDecomp) return false; - globalFree(cmpbuf); + globalDestroy(cmpbuf); } else { /* If the file is not compressed, we directly read in the data */ nBytesRead = hMpc.read(lpMpcImage, dwSizeDecomp); @@ -1471,7 +1472,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (ParseMpc(lpMpcImage) == false) return false; - globalFree(lpMpcImage); + globalDestroy(lpMpcImage); /* Calculate memory usage */ /* @@ -1529,7 +1530,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != (uint32)GLOBALS.nResources * 8) return false; - globalFree(cmpbuf); + globalDestroy(cmpbuf); /* Reset back to the start of the file, leaving it open */ GLOBALS.hMpr.seek(0, SEEK_SET); diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index fb3d019051..f23eaf8e4a 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -85,17 +85,12 @@ #include "common/coroutines.h" #include "common/rect.h" #include "common/str.h" +#include "tony/mpal/memory.h" namespace Tony { namespace MPAL { -/****************************************************************************\ -* Type definitions -\****************************************************************************/ - -typedef void *HANDLE; - /****************************************************************************\ * Macro definitions and structures \****************************************************************************/ -- cgit v1.2.3 From 739983f42fae768dfee574122adbac93ac8b15d2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 8 Jun 2012 23:21:12 +1000 Subject: TONY: Fixed sign of block identifier constant --- engines/tony/mpal/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index b50f9d7c37..c5e752d390 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -33,7 +33,7 @@ namespace MPAL { * MemoryManager methods \****************************************************************************/ -const int BLOCK_ID = 0x12345678; +const uint32 BLOCK_ID = 0x12345678; /** * Allocates a new memory block -- cgit v1.2.3 From 83f1cad02be38e56161350aabc29176f24c901a0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 01:20:08 +1000 Subject: TONY: Added code to free parsed MPC file data when the game ends --- engines/tony/mpal/expr.cpp | 30 +++++++++++- engines/tony/mpal/expr.h | 7 +++ engines/tony/mpal/loadmpc.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++ engines/tony/mpal/loadmpc.h | 4 ++ engines/tony/mpal/mpal.cpp | 1 - 5 files changed, 148 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 5ba2fff442..a9d48e2016 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -84,7 +84,7 @@ typedef struct { byte type; // Tipo di oggetto (vedi enum ExprListTypes) byte unary; // Unary operatore (NON SUPPORTATO) - union { + union { int num; // Numero (se type==ELT_NUMBER) char *name; // Nome variabile (se type==ELT_VAR) HGLOBAL son; // Handle a espressione (type==ELT_PARENTH) @@ -400,6 +400,34 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { return true; } +/** + * Frees an expression that was previously parsed + * + * @param h Handle for the expression + */ +void freeExpression(HGLOBAL h) { + byte *data = (byte *)globalLock(h); + int num = *data; + LPEXPRESSION cur = (LPEXPRESSION)(data + 1); + + for (int i = 0; i < num; ++i, ++cur) { + switch (cur->type) { + case ELT_VAR: + globalDestroy(cur->val.name); + break; + + case ELT_PARENTH: + freeExpression(cur->val.son); + break; + + default: + break; + } + } + + globalUnlock(h); + globalFree(h); +} } // end of namespace MPAL diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 9844add822..3130539000 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -65,6 +65,13 @@ int evaluateExpression(HGLOBAL h); */ bool compareExpressions(HGLOBAL h1, HGLOBAL h2); +/** + * Frees an expression that was previously parsed + * + * @param h Handle for the expression + */ +void freeExpression(HGLOBAL h); + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 5a338b24b0..aa048c0b2f 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -121,6 +121,21 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { return lpBuf; } +/** + * Frees a script allocated via a previous call to ParseScript + * + * @param lpmsScript Pointer to a script structure + */ +static void FreeScript(LPMPALSCRIPT lpmsScript) { + for (int i = 0; i < MAX_COMMANDS_PER_SCRIPT && (lpmsScript->_command[i].type); ++i, ++lpmsScript) { + if (lpmsScript->_command[i].type == 2) { + // Variable Assign + globalDestroy(lpmsScript->_command[i].lpszVarName); + freeExpression(lpmsScript->_command[i].expr); + } + } +} + /** * Parses a dialog from the MPC file, and inserts its data into a structure * @@ -428,6 +443,25 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { return lpBuf; } +/** + * Frees an item parsed from a prior call to ParseItem + * + * @param lpmiItem Pointer to an item structure + */ +static void freeItem(LPMPALITEM lpmiItem) { + // Free the actions + if (lpmiItem->Action) + globalDestroy(lpmiItem->Action); + + // Free the commands + for (int i = 0; i < MAX_COMMANDS_PER_ITEM && (lpmiItem->_command[i].type); ++i, ++lpmiItem) { + if (lpmiItem->_command[i].type == 2) { + // Variable Assign + globalDestroy(lpmiItem->_command[i].lpszVarName); + freeExpression(lpmiItem->_command[i].expr); + } + } +} /** * Parses a location from the MPC file, and inserts its data into a structure @@ -651,6 +685,80 @@ bool ParseMpc(const byte *lpBuf) { return true; } +/** + * Free the given dialog + */ +static void freeDialog(LPMPALDIALOG lpmdDialog) { + // Free the periods + int i; + + for (i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) + globalFree(lpmdDialog->_periods[i]); + + for (i = 0; i < MAX_COMMANDS_PER_GROUP && (lpmdDialog->_command[i].type); i++) { + if (lpmdDialog->_command[i].type == 2) { + // Variable assign + globalDestroy(lpmdDialog->_command[i].lpszVarName); + freeExpression(lpmdDialog->_command[i].expr); + } + } +} + +/** + * Frees any data allocated from the parsing of the MPC file + */ +void FreeMpc() { + int i; + + // Free variables + globalFree(GLOBALS.hVars); + + // Free messages + LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); + for (i = 0; i < GLOBALS.nMsgs; i++, ++lpmmMsgs) + globalFree(lpmmMsgs->hText); + + globalUnlock(GLOBALS.hMsgs); + globalFree(GLOBALS.hMsgs); + + // Free objects + if (GLOBALS.hDialogs) { + LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); + + for (i = 0; i < GLOBALS.nDialogs; i++, ++lpmdDialogs) + freeDialog(lpmdDialogs); + + globalFree(GLOBALS.hDialogs); + } + + // Free items + if (GLOBALS.hItems) { + LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); + + for (i = 0; i < GLOBALS.nItems; ++i, ++lpmiItems) + freeItem(lpmiItems); + + globalUnlock(GLOBALS.hItems); + globalFree(GLOBALS.hItems); + } + + // Free the locations + if (GLOBALS.hLocations) { + globalFree(GLOBALS.hLocations); + } + + // Free the scripts + if (GLOBALS.hScripts) { + LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); + + for (i = 0; i < GLOBALS.nScripts; ++i, ++lpmsScripts) { + FreeScript(lpmsScripts); + } + + globalUnlock(GLOBALS.hScripts); + } +} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index 2f8a1121ec..83463f0092 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -46,6 +46,10 @@ namespace MPAL { */ bool ParseMpc(const byte *lpBuf); +/** + * Frees any data allocated from the parsing of the MPC file + */ +void FreeMpc(); } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 425fe187fc..04d562ffc9 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -803,7 +803,6 @@ void LocationPollThread(CORO_PARAM, const void *param) { } MYTHREAD; CORO_BEGIN_CONTEXT; - // TODO: Requires endian fix uint32 *il; int i, j, k; int numitems; -- cgit v1.2.3 From dd8b4b519a2a61e010d9aa4d71b5f123dfeffc6b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 10:44:51 +1000 Subject: TONY: Added more freeing of MPC data when the game ends --- engines/tony/mpal/loadmpc.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index aa048c0b2f..e222891170 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -690,7 +690,7 @@ bool ParseMpc(const byte *lpBuf) { */ static void freeDialog(LPMPALDIALOG lpmdDialog) { // Free the periods - int i; + int i, j; for (i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) globalFree(lpmdDialog->_periods[i]); @@ -702,6 +702,14 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { freeExpression(lpmdDialog->_command[i].expr); } } + + // Free the choices + for (i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { + for (j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { + if (lpmdDialog->_choice[i]._select[j].when) + freeExpression(lpmdDialog->_choice[i]._select[j].when); + } + } } /** -- cgit v1.2.3 From 5e062ce86c87c0253fc237c6c26ed9d9293ef571 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 11:57:07 +1000 Subject: TONY: Properly free items during loading when there is duplicates --- engines/tony/mpal/loadmpc.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index e222891170..bb2c999984 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -421,6 +421,16 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { for (kk = 0; kk < curCmd; kk++) { if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) { lpmiItem->Action[i].CmdNum[j] = kk; + + // Free any data allocated for the duplictaed command + if (lpmiItem->_command[curCmd].type == 2) { + globalDestroy(lpmiItem->_command[curCmd].lpszVarName); + freeExpression(lpmiItem->_command[curCmd].expr); + + lpmiItem->_command[curCmd].lpszVarName = NULL; + lpmiItem->_command[curCmd].expr = 0; + lpmiItem->_command[curCmd].type = 0; + } break; } } -- cgit v1.2.3 From 8d6f50463ee0541e2d4609f80443537adefdd35e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 12:29:34 +1000 Subject: TONY: Properly free dialog commands during loading when there is duplicates --- engines/tony/mpal/loadmpc.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index bb2c999984..d0b6a75f72 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -238,6 +238,16 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { for (kk = 0;kk < curCmd; kk++) { if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) { lpmdDialog->_group[i].CmdNum[j] = kk; + + // Free any data allocated for the duplictaed command + if (lpmdDialog->_command[curCmd].type == 2) { + globalDestroy(lpmdDialog->_command[curCmd].lpszVarName); + freeExpression(lpmdDialog->_command[curCmd].expr); + + lpmdDialog->_command[curCmd].lpszVarName = NULL; + lpmdDialog->_command[curCmd].expr = 0; + lpmdDialog->_command[curCmd].type = 0; + } break; } } -- cgit v1.2.3 From a50b1f32c1de667cd2d73535b07e62b000cf4483 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 13:05:48 +1000 Subject: TONY: Fixes for deallocating MPC and MPAL data --- engines/tony/mpal/loadmpc.cpp | 12 +++++++++--- engines/tony/mpal/mpal.cpp | 7 +++++++ engines/tony/mpal/mpal.h | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index d0b6a75f72..1f610a8d2c 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -470,11 +470,17 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { */ static void freeItem(LPMPALITEM lpmiItem) { // Free the actions - if (lpmiItem->Action) + if (lpmiItem->Action) { + for (int i = 0; i < lpmiItem->nActions; ++i) { + if (lpmiItem->Action[i].when != 0) + freeExpression(lpmiItem->Action[i].when); + } + globalDestroy(lpmiItem->Action); + } // Free the commands - for (int i = 0; i < MAX_COMMANDS_PER_ITEM && (lpmiItem->_command[i].type); ++i, ++lpmiItem) { + for (int i = 0; i < MAX_COMMANDS_PER_ITEM && (lpmiItem->_command[i].type); ++i) { if (lpmiItem->_command[i].type == 2) { // Variable Assign globalDestroy(lpmiItem->_command[i].lpszVarName); @@ -715,7 +721,7 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { for (i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) globalFree(lpmdDialog->_periods[i]); - for (i = 0; i < MAX_COMMANDS_PER_GROUP && (lpmdDialog->_command[i].type); i++) { + for (i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { if (lpmdDialog->_command[i].type == 2) { // Variable assign globalDestroy(lpmdDialog->_command[i].lpszVarName); diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 04d562ffc9..4aac53bb8e 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1548,6 +1548,13 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, return true; } +/** + * Frees resources allocated by the MPAL subsystem + */ +void mpalFree() { + // Free the resource list + globalDestroy(GLOBALS.lpResources); +} /** * This is a general function to communicate with the library, to request information diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index f23eaf8e4a..198083f851 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -402,6 +402,10 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; bool mpalInit(const char *lpszFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings); +/** + * Frees resources allocated by the MPAL subsystem + */ +void mpalFree(); /** * This is a general function to communicate with the library, to request information -- cgit v1.2.3 From 10621fded8eee2da03a2a9f93bfa1546bcb7c748 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 17:51:58 +1000 Subject: TONY: Fix some calls from globalFree to globalDestroy --- engines/tony/mpal/mpal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 4aac53bb8e..9f9a4c203b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -911,7 +911,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { unlockItems(); /* We don't need the item list anymore */ - globalFree(_ctx->il); + globalDestroy(_ctx->il); /* Here's the main loop */ @@ -2108,7 +2108,7 @@ int mpalLoadState(byte *buf) { GLOBALS.nVars = READ_LE_UINT32(buf); - GLOBALS.hVars = globalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); + GLOBALS.hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); lockVar(); copyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); unlockVar(); -- cgit v1.2.3 From 4a3518dc92762cbcd8bda8786c975af021564b37 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 9 Jun 2012 22:20:16 +1000 Subject: TONY: Fix data freeing in LocationPollThread --- engines/tony/mpal/mpal.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 9f9a4c203b..5a4310c15b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -866,7 +866,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads = (MYTHREAD *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); if (_ctx->MyThreads == NULL) { - globalFree(_ctx->il); + globalDestroy(_ctx->il); CORO_KILL_SELF(); return; } @@ -876,8 +876,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { Now we created the mirrored copies of the idle actions. */ _ctx->MyActions = (MYACTION *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); if (_ctx->MyActions == NULL) { - globalFree(_ctx->MyThreads); - globalFree(_ctx->il); + globalDestroy(_ctx->MyThreads); + globalDestroy(_ctx->il); CORO_KILL_SELF(); return; } @@ -981,8 +981,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ok, we can perform the action. For convenience, we do it in a new process */ _ctx->newItem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (_ctx->newItem == false) { - globalFree(_ctx->MyThreads); - globalFree(_ctx->MyActions); + globalDestroy(_ctx->MyThreads); + globalDestroy(_ctx->MyActions); CORO_KILL_SELF(); return; @@ -1006,9 +1006,9 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Create the process if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) { //if ((_ctx->MyThreads[_ctx->i].hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))= = (void*)-1) - globalFree(_ctx->newItem); - globalFree(_ctx->MyThreads); - globalFree(_ctx->MyActions); + globalDestroy(_ctx->newItem); + globalDestroy(_ctx->MyThreads); + globalDestroy(_ctx->MyActions); CORO_KILL_SELF(); return; @@ -1039,8 +1039,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_INVOKE_4(GLOBALS.lplpFunctions[201], 0, 0, 0, 0); /* We're finished */ - globalFree(_ctx->MyThreads); - globalFree(_ctx->MyActions); + globalDestroy(_ctx->MyThreads); + globalDestroy(_ctx->MyActions); CORO_KILL_SELF(); -- cgit v1.2.3 From 2b02a45ce16960644e1d5e297066f8040cd48cbc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 10 Jun 2012 22:02:31 +0200 Subject: TONY: Rename variables in globals.h --- engines/tony/mpal/expr.cpp | 2 +- engines/tony/mpal/loadmpc.cpp | 195 ++++++++++----------- engines/tony/mpal/mpal.cpp | 389 +++++++++++++++++++++--------------------- engines/tony/mpal/mpaldll.h | 10 +- 4 files changed, 299 insertions(+), 297 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index a9d48e2016..516da98bb1 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -171,7 +171,7 @@ static int Compute(int a, int b, byte symbol) { case OP_OR: return a || b; default: - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; break; } diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 1f610a8d2c..6ed4545d67 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -84,15 +84,15 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpBuf++; switch (lpmsScript->_command[curCmd].type) { case 1: - lpmsScript->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmsScript->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmsScript->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd]._arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd]._arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd]._arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpmsScript->_command[curCmd]._arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; @@ -197,15 +197,15 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { switch (lpmdDialog->_command[curCmd].type) { // Call custom function case 1: - lpmdDialog->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmdDialog->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->_command[curCmd].arg1 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd]._arg1 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->_command[curCmd].arg2 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd]._arg2 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->_command[curCmd].arg3 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd]._arg3 = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmdDialog->_command[curCmd].arg4 = READ_LE_UINT32(lpBuf); + lpmdDialog->_command[curCmd]._arg4 = READ_LE_UINT32(lpBuf); lpBuf += 4; break; @@ -398,15 +398,15 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpBuf++; switch (lpmiItem->_command[curCmd].type) { case 1: // Call custom function - lpmiItem->_command[curCmd].nCf = READ_LE_UINT16(lpBuf); + lpmiItem->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmiItem->_command[curCmd].arg1 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd]._arg1 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->_command[curCmd].arg2 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd]._arg2 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->_command[curCmd].arg3 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd]._arg3 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmiItem->_command[curCmd].arg4 = (int32)READ_LE_UINT32(lpBuf); + lpmiItem->_command[curCmd]._arg4 = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; @@ -535,58 +535,58 @@ bool ParseMpc(const byte *lpBuf) { return false; lpBuf += 4; - GLOBALS.nVars = READ_LE_UINT16(lpBuf); + GLOBALS._nVars = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS.hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS.nVars); - if (GLOBALS.hVars == NULL) + GLOBALS._hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS._nVars); + if (GLOBALS._hVars == NULL) return false; - GLOBALS.lpmvVars = (LPMPALVAR)globalLock(GLOBALS.hVars); + GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); - for (i = 0; i < GLOBALS.nVars; i++) { + for (i = 0; i < GLOBALS._nVars; i++) { wLen = *(const byte *)lpBuf; lpBuf++; - copyMemory(GLOBALS.lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); + copyMemory(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; - GLOBALS.lpmvVars->dwVal = READ_LE_UINT32(lpBuf); + GLOBALS._lpmvVars->dwVal = READ_LE_UINT32(lpBuf); lpBuf += 4; lpBuf++; // Salta 'ext' - GLOBALS.lpmvVars++; + GLOBALS._lpmvVars++; } - globalUnlock(GLOBALS.hVars); + globalUnlock(GLOBALS._hVars); /* 2. Messages */ if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S') return false; lpBuf += 4; - GLOBALS.nMsgs = READ_LE_UINT16(lpBuf); + GLOBALS._nMsgs = READ_LE_UINT16(lpBuf); lpBuf += 2; #ifdef NEED_LOCK_MSGS - GLOBALS.hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS.nMsgs); - if (GLOBALS.hMsgs == NULL) + GLOBALS._hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS._nMsgs); + if (GLOBALS._hMsgs == NULL) return false; - GLOBALS.lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); + GLOBALS._lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); #else - GLOBALS.lpmmMsgs=(LPMPALMSG)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,sizeof(MPALMSG)*(uint32)GLOBALS.nMsgs); - if (GLOBALS.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 < GLOBALS.nMsgs; i++) { - GLOBALS.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; - GLOBALS.lpmmMsgs->hText = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); - lpTemp2 = lpTemp = (byte *)globalLock(GLOBALS.lpmmMsgs->hText); + GLOBALS._lpmmMsgs->_hText = globalAllocate(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]); @@ -598,12 +598,12 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += j + 1; *lpTemp = '\0'; - globalUnlock(GLOBALS.lpmmMsgs->hText); - GLOBALS.lpmmMsgs++; + globalUnlock(GLOBALS._lpmmMsgs->_hText); + GLOBALS._lpmmMsgs++; } #ifdef NEED_LOCK_MSGS - globalUnlock(GLOBALS.hMsgs); + globalUnlock(GLOBALS._hMsgs); #endif /* 3. Objects */ @@ -611,86 +611,89 @@ bool ParseMpc(const byte *lpBuf) { return false; lpBuf += 4; - GLOBALS.nObjs = READ_LE_UINT16(lpBuf); + GLOBALS._nObjs = READ_LE_UINT16(lpBuf); lpBuf += 2; // Check out the dialogs - GLOBALS.nDialogs = 0; - GLOBALS.hDialogs = GLOBALS.lpmdDialogs = NULL; + GLOBALS._nDialogs = 0; + GLOBALS._hDialogs = GLOBALS._lpmdDialogs = NULL; if (*((const byte *)lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Dialog", 6) == 0) { - GLOBALS.nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2; + GLOBALS._nDialogs = READ_LE_UINT16(lpBuf); + lpBuf += 2; - GLOBALS.hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nDialogs * sizeof(MPALDIALOG)); - if (GLOBALS.hDialogs == NULL) + GLOBALS._hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nDialogs * sizeof(MPALDIALOG)); + if (GLOBALS._hDialogs == NULL) return false; - GLOBALS.lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); + GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0;i < GLOBALS.nDialogs; i++) - if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS.lpmdDialogs[i])) == NULL) + for (i = 0;i < GLOBALS._nDialogs; i++) + if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS._lpmdDialogs[i])) == NULL) return false; - globalUnlock(GLOBALS.hDialogs); + globalUnlock(GLOBALS._hDialogs); } // Check the items - GLOBALS.nItems = 0; - GLOBALS.hItems = GLOBALS.lpmiItems = NULL; - if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4)==0) { - GLOBALS.nItems = READ_LE_UINT16(lpBuf); + GLOBALS._nItems = 0; + GLOBALS._hItems = GLOBALS._lpmiItems = NULL; + if (*(lpBuf + 2) == 4 && strncmp((const char *)lpBuf + 3, "Item", 4) == 0) { + GLOBALS._nItems = READ_LE_UINT16(lpBuf); lpBuf += 2; // Allocate memory and read them in - GLOBALS.hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nItems * sizeof(MPALITEM)); - if (GLOBALS.hItems == NULL) + GLOBALS._hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nItems * sizeof(MPALITEM)); + if (GLOBALS._hItems == NULL) return false; - GLOBALS.lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); + GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS.nItems; i++) - if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS.lpmiItems[i])) == NULL) + for (i = 0; i < GLOBALS._nItems; i++) { + if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS._lpmiItems[i])) == NULL) return false; + } - globalUnlock(GLOBALS.hItems); + globalUnlock(GLOBALS._hItems); } // Check the locations - GLOBALS.nLocations = 0; - GLOBALS.hLocations = GLOBALS.lpmlLocations = NULL; + GLOBALS._nLocations = 0; + GLOBALS._hLocations = GLOBALS._lpmlLocations = NULL; if (*(lpBuf + 2) == 8 && strncmp((const char *)lpBuf + 3, "Location", 8) == 0) { - GLOBALS.nLocations = READ_LE_UINT16(lpBuf); + GLOBALS._nLocations = READ_LE_UINT16(lpBuf); lpBuf += 2; // Allocate memory and read them in - GLOBALS.hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nLocations*sizeof(MPALLOCATION)); - if (GLOBALS.hLocations == NULL) + GLOBALS._hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nLocations * sizeof(MPALLOCATION)); + if (GLOBALS._hLocations == NULL) return false; - GLOBALS.lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS.hLocations); + GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); - for (i = 0; i < GLOBALS.nLocations; i++) - if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS.lpmlLocations[i])) == NULL) + for (i = 0; i < GLOBALS._nLocations; i++) { + if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS._lpmlLocations[i])) == NULL) return false; + } - globalUnlock(GLOBALS.hLocations); + globalUnlock(GLOBALS._hLocations); } // Check the scripts - GLOBALS.nScripts = 0; - GLOBALS.hScripts = GLOBALS.lpmsScripts = NULL; + GLOBALS._nScripts = 0; + GLOBALS._hScripts = GLOBALS._lpmsScripts = NULL; if (*(lpBuf + 2) == 6 && strncmp((const char *)lpBuf + 3, "Script", 6) == 0) { - GLOBALS.nScripts = READ_LE_UINT16(lpBuf); + GLOBALS._nScripts = READ_LE_UINT16(lpBuf); lpBuf += 2; // Allocate memory - GLOBALS.hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS.nScripts * sizeof(MPALSCRIPT)); - if (GLOBALS.hScripts == NULL) + GLOBALS._hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nScripts * sizeof(MPALSCRIPT)); + if (GLOBALS._hScripts == NULL) return false; - GLOBALS.lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); + GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS.nScripts; i++) { - if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS.lpmsScripts[i])) == NULL) + for (i = 0; i < GLOBALS._nScripts; i++) { + if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS._lpmsScripts[i])) == NULL) return false; // Sort the various moments of the script @@ -702,7 +705,7 @@ bool ParseMpc(const byte *lpBuf) { //); } - globalUnlock(GLOBALS.hScripts); + globalUnlock(GLOBALS._hScripts); } if (lpBuf[0] != 'E' || lpBuf[1] != 'N' || lpBuf[2] != 'D' || lpBuf[3] != '0') @@ -745,51 +748,51 @@ void FreeMpc() { int i; // Free variables - globalFree(GLOBALS.hVars); + globalFree(GLOBALS._hVars); // Free messages - LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); - for (i = 0; i < GLOBALS.nMsgs; i++, ++lpmmMsgs) - globalFree(lpmmMsgs->hText); + LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); + for (i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) + globalFree(lpmmMsgs->_hText); - globalUnlock(GLOBALS.hMsgs); - globalFree(GLOBALS.hMsgs); + globalUnlock(GLOBALS._hMsgs); + globalFree(GLOBALS._hMsgs); // Free objects - if (GLOBALS.hDialogs) { - LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); + if (GLOBALS._hDialogs) { + LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0; i < GLOBALS.nDialogs; i++, ++lpmdDialogs) + for (i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) freeDialog(lpmdDialogs); - globalFree(GLOBALS.hDialogs); + globalFree(GLOBALS._hDialogs); } // Free items - if (GLOBALS.hItems) { - LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); + if (GLOBALS._hItems) { + LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS.nItems; ++i, ++lpmiItems) + for (i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) freeItem(lpmiItems); - globalUnlock(GLOBALS.hItems); - globalFree(GLOBALS.hItems); + globalUnlock(GLOBALS._hItems); + globalFree(GLOBALS._hItems); } // Free the locations - if (GLOBALS.hLocations) { - globalFree(GLOBALS.hLocations); + if (GLOBALS._hLocations) { + globalFree(GLOBALS._hLocations); } // Free the scripts - if (GLOBALS.hScripts) { - LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); + if (GLOBALS._hScripts) { + LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS.nScripts; ++i, ++lpmsScripts) { + for (i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { FreeScript(lpmsScripts); } - globalUnlock(GLOBALS.hScripts); + globalUnlock(GLOBALS._hScripts); } } diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 5a4310c15b..162ba4c776 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -60,24 +60,22 @@ const char *mpalCopyright = * Locks the variables for access */ void lockVar(void) { - GLOBALS.lpmvVars = (LPMPALVAR)globalLock(GLOBALS.hVars); + GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); } - /** * Unlocks variables after use */ void unlockVar(void) { - globalUnlock(GLOBALS.hVars); + globalUnlock(GLOBALS._hVars); } - /** * Locks the messages for access */ static void LockMsg(void) { #ifdef NEED_LOCK_MSGS - GLOBALS.lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS.hMsgs); + GLOBALS._lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); #endif } @@ -87,7 +85,7 @@ static void LockMsg(void) { */ static void UnlockMsg(void) { #ifdef NEED_LOCK_MSGS - globalUnlock(GLOBALS.hMsgs); + globalUnlock(GLOBALS._hMsgs); #endif } @@ -96,7 +94,7 @@ static void UnlockMsg(void) { * Locks the dialogs for access */ static void lockDialogs(void) { - GLOBALS.lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS.hDialogs); + GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); } @@ -104,7 +102,7 @@ static void lockDialogs(void) { * Unlocks the dialogs after use */ static void unlockDialogs(void) { - globalUnlock(GLOBALS.hDialogs); + globalUnlock(GLOBALS._hDialogs); } @@ -112,7 +110,7 @@ static void unlockDialogs(void) { * Locks the location data structures for access */ static void lockLocations(void) { - GLOBALS.lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS.hLocations); + GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); } @@ -120,7 +118,7 @@ static void lockLocations(void) { * Unlocks the location structures after use */ static void unlockLocations(void) { - globalUnlock(GLOBALS.hLocations); + globalUnlock(GLOBALS._hLocations); } @@ -128,7 +126,7 @@ static void unlockLocations(void) { * Locks the items structures for use */ static void lockItems(void) { - GLOBALS.lpmiItems = (LPMPALITEM)globalLock(GLOBALS.hItems); + GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); } @@ -136,7 +134,7 @@ static void lockItems(void) { * Unlocks the items structures after use */ static void unlockItems(void) { - globalUnlock(GLOBALS.hItems); + globalUnlock(GLOBALS._hItems); } @@ -144,7 +142,7 @@ static void unlockItems(void) { * Locks the script data structures for use */ static void LockScripts(void) { - GLOBALS.lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS.hScripts); + GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); } @@ -152,7 +150,7 @@ static void LockScripts(void) { * Unlocks the script data structures after use */ static void unlockScripts(void) { - globalUnlock(GLOBALS.hScripts); + globalUnlock(GLOBALS._hScripts); } @@ -167,13 +165,13 @@ static void unlockScripts(void) { */ int32 varGetValue(const char *lpszVarName) { int i; - LPMPALVAR v=GLOBALS.lpmvVars; + LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS.nVars; v++, i++) + for (i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) return v->dwVal; - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; return 0; } @@ -185,24 +183,24 @@ int32 varGetValue(const char *lpszVarName) { */ void varSetValue(const char *lpszVarName, int32 val) { uint i; - LPMPALVAR v = GLOBALS.lpmvVars; + LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS.nVars; v++, i++) + for (i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) { v->dwVal = val; - if (GLOBALS.lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { + if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { i = 0; sscanf(v->lpszVarName, "Pattern.%u", &i); - GLOBALS.lpiifCustom(i, val, -1); - } else if (GLOBALS.lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { + GLOBALS._lpiifCustom(i, val, -1); + } else if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { i = 0; sscanf(v->lpszVarName,"Status.%u", &i); - GLOBALS.lpiifCustom(i, -1, val); + GLOBALS._lpiifCustom(i, -1, val); } return; } - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; return; } @@ -217,9 +215,9 @@ void varSetValue(const char *lpszVarName, int32 val) { */ static int locGetOrderFromNum(uint32 nLoc) { int i; - LPMPALLOCATION loc = GLOBALS.lpmlLocations; + LPMPALLOCATION loc = GLOBALS._lpmlLocations; - for (i = 0; i < GLOBALS.nLocations; i++, loc++) + for (i = 0; i < GLOBALS._nLocations; i++, loc++) if (loc->nObj == nLoc) return i; @@ -236,10 +234,10 @@ static int locGetOrderFromNum(uint32 nLoc) { */ static int msgGetOrderFromNum(uint32 nMsg) { int i; - LPMPALMSG msg = GLOBALS.lpmmMsgs; + LPMPALMSG msg = GLOBALS._lpmmMsgs; - for (i = 0; i < GLOBALS.nMsgs; i++, msg++) - if (msg->wNum == nMsg) + for (i = 0; i < GLOBALS._nMsgs; i++, msg++) + if (msg->_wNum == nMsg) return i; return -1; @@ -254,9 +252,9 @@ static int msgGetOrderFromNum(uint32 nMsg) { */ static int itemGetOrderFromNum(uint32 nItem) { int i; - LPMPALITEM item = GLOBALS.lpmiItems; + LPMPALITEM item = GLOBALS._lpmiItems; - for (i = 0; i < GLOBALS.nItems; i++, item++) + for (i = 0; i < GLOBALS._nItems; i++, item++) if (item->nObj == nItem) return i; @@ -273,9 +271,9 @@ static int itemGetOrderFromNum(uint32 nItem) { */ static int scriptGetOrderFromNum(uint32 nScript) { int i; - LPMPALSCRIPT script = GLOBALS.lpmsScripts; + LPMPALSCRIPT script = GLOBALS._lpmsScripts; - for (i = 0; i < GLOBALS.nScripts; i++, script++) + for (i = 0; i < GLOBALS._nScripts; i++, script++) if (script->nObj == nScript) return i; @@ -292,9 +290,9 @@ static int scriptGetOrderFromNum(uint32 nScript) { */ static int dialogGetOrderFromNum(uint32 nDialog) { int i; - LPMPALDIALOG dialog = GLOBALS.lpmdDialogs; + LPMPALDIALOG dialog = GLOBALS._lpmdDialogs; - for (i = 0; i < GLOBALS.nDialogs; i++, dialog++) + for (i = 0; i < GLOBALS._nDialogs; i++, dialog++) if (dialog->nObj == nDialog) return i; @@ -316,7 +314,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { if (nMsgOrd == (uint32)-1) return NULL; - origmsg = (const char *)globalLock(GLOBALS.lpmmMsgs[nMsgOrd].hText); + origmsg = (const char *)globalLock(GLOBALS._lpmmMsgs[nMsgOrd]._hText); j = 0; while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') @@ -328,7 +326,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { return NULL; copyMemory(clonemsg, origmsg, j); - globalUnlock(GLOBALS.lpmmMsgs[nMsgOrd].hText); + globalUnlock(GLOBALS._lpmmMsgs[nMsgOrd]._hText); return clonemsg; } @@ -344,7 +342,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { static char *duplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; - LPMPALDIALOG dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; + LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; int i, j; for (j = 0; dialog->_periods[j] != NULL; j++) @@ -385,28 +383,28 @@ HGLOBAL resLoad(uint32 dwId) { uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; - for (i = 0; i < GLOBALS.nResources; i++) - if (GLOBALS.lpResources[i * 2] == dwId) { - GLOBALS.hMpr.seek(GLOBALS.lpResources[i * 2 + 1]); - nBytesRead = GLOBALS.hMpr.read(head, 4); + for (i = 0; i < GLOBALS._nResources; i++) + if (GLOBALS._lpResources[i * 2] == dwId) { + GLOBALS._hMpr.seek(GLOBALS._lpResources[i * 2 + 1]); + nBytesRead = GLOBALS._hMpr.read(head, 4); if (nBytesRead != 4) return NULL; if (head[0] != 'R' || head[1] != 'E' || head[2] != 'S' || head[3] != 'D') return NULL; - nSizeDecomp = GLOBALS.hMpr.readUint32LE(); - if (GLOBALS.hMpr.err()) + nSizeDecomp = GLOBALS._hMpr.readUint32LE(); + if (GLOBALS._hMpr.err()) return NULL; - nSizeComp = GLOBALS.hMpr.readUint32LE(); - if (GLOBALS.hMpr.err()) + nSizeComp = GLOBALS._hMpr.readUint32LE(); + if (GLOBALS._hMpr.err()) return NULL; h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); buf = (byte *)globalLock(h); temp = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); - nBytesRead = GLOBALS.hMpr.read(temp, nSizeComp); + nBytesRead = GLOBALS._hMpr.read(temp, nSizeComp); if (nBytesRead != nSizeComp) return NULL; @@ -425,7 +423,7 @@ HGLOBAL resLoad(uint32 dwId) { static uint32 *getSelectList(uint32 i) { uint32 *sl; int j, k, num; - LPMPALDIALOG dialog = GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; + LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; /* Count how many are active selects */ num = 0; @@ -454,10 +452,10 @@ static uint32 *getSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; uint32 num,i,j; - LPMPALVAR v = GLOBALS.lpmvVars; + LPMPALVAR v = GLOBALS._lpmvVars; num = 0; - for (i = 0; i < GLOBALS.nVars; i++, v++) { + for (i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } @@ -466,9 +464,9 @@ static uint32 *GetItemList(uint32 nLoc) { if (il == NULL) return NULL; - v = GLOBALS.lpmvVars; + v = GLOBALS._lpmvVars; j = 0; - for (i = 0; i < GLOBALS.nVars; i++, v++) { + for (i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName, "Location", 8) == 0 && v->dwVal == nLoc) { sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; @@ -480,7 +478,7 @@ static uint32 *GetItemList(uint32 nLoc) { } static LPITEM getItemData(uint32 nOrdItem) { - LPMPALITEM curitem = GLOBALS.lpmiItems+nOrdItem; + LPMPALITEM curitem = GLOBALS._lpmiItems + nOrdItem; LPITEM ret; HGLOBAL hDat; char *dat; @@ -592,7 +590,7 @@ void CustomThread(CORO_PARAM, const void *param) { _ctx->p = *(LPCFCALL *)param; - CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4); + CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->p->_nCf], _ctx->p->_arg1, _ctx->p->_arg2, _ctx->p->_arg3, _ctx->p->_arg4); globalFree(_ctx->p); @@ -645,21 +643,21 @@ void ScriptThread(CORO_PARAM, const void *param) { if (s->_command[_ctx->k].type == 1) { _ctx->p = (LPCFCALL)globalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) { - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; CORO_KILL_SELF(); return; } - _ctx->p->nCf=s->_command[_ctx->k].nCf; - _ctx->p->arg1=s->_command[_ctx->k].arg1; - _ctx->p->arg2=s->_command[_ctx->k].arg2; - _ctx->p->arg3=s->_command[_ctx->k].arg3; - _ctx->p->arg4=s->_command[_ctx->k].arg4; + _ctx->p->_nCf = s->_command[_ctx->k]._nCf; + _ctx->p->_arg1 = s->_command[_ctx->k]._arg1; + _ctx->p->_arg2 = s->_command[_ctx->k]._arg2; + _ctx->p->_arg3 = s->_command[_ctx->k]._arg3; + _ctx->p->_arg4 = s->_command[_ctx->k]._arg4; // !!! New process management if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; CORO_KILL_SELF(); return; @@ -673,7 +671,7 @@ void ScriptThread(CORO_PARAM, const void *param) { unlockVar(); } else { - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; globalFree(s); CORO_KILL_SELF(); @@ -707,23 +705,23 @@ void ActionThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - GLOBALS.mpalError = 0; + GLOBALS._mpalError = 0; for (_ctx->j = 0; _ctx->j < item->Action[item->dwRes].nCmds; _ctx->j++) { _ctx->k = item->Action[item->dwRes].CmdNum[_ctx->j]; if (item->_command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - CoroScheduler.getCurrentPID(), GLOBALS.lplpFunctionStrings[item->_command[_ctx->k].nCf].c_str(), - item->_command[_ctx->k].arg1, item->_command[_ctx->k].arg2, - item->_command[_ctx->k].arg3, item->_command[_ctx->k].arg4 + CoroScheduler.getCurrentPID(), GLOBALS._lplpFunctionStrings[item->_command[_ctx->k]._nCf].c_str(), + item->_command[_ctx->k]._arg1, item->_command[_ctx->k]._arg2, + item->_command[_ctx->k]._arg3, item->_command[_ctx->k]._arg4 ); - CORO_INVOKE_4(GLOBALS.lplpFunctions[item->_command[_ctx->k].nCf], - item->_command[_ctx->k].arg1, - item->_command[_ctx->k].arg2, - item->_command[_ctx->k].arg3, - item->_command[_ctx->k].arg4 + CORO_INVOKE_4(GLOBALS._lplpFunctions[item->_command[_ctx->k]._nCf], + item->_command[_ctx->k]._arg1, + item->_command[_ctx->k]._arg2, + item->_command[_ctx->k]._arg3, + item->_command[_ctx->k]._arg4 ); } else if (item->_command[_ctx->k].type == 2) { @@ -736,7 +734,7 @@ void ActionThread(CORO_PARAM, const void *param) { unlockVar(); } else { - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; break; } } @@ -765,7 +763,7 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); - GLOBALS.bExecutingAction = false; + GLOBALS._bExecutingAction = false; if (_vm->_initialLoadSlotNumber != -1) { _ctx->slotNumber = _vm->_initialLoadSlotNumber; @@ -825,7 +823,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); /* To begin with, we need to request the item list from the location */ - _ctx->il = mpalQueryItemList(GLOBALS.nPollingLocations[id]); + _ctx->il = mpalQueryItemList(GLOBALS._nPollingLocations[id]); /* Count the items */ for (_ctx->numitems = 0; _ctx->il[_ctx->numitems] != 0; _ctx->numitems++) @@ -840,7 +838,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->ord == -1) continue; - _ctx->curItem = GLOBALS.lpmiItems + _ctx->ord; + _ctx->curItem = GLOBALS._lpmiItems + _ctx->ord; _ctx->k = 0; for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) @@ -889,9 +887,9 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->il[_ctx->i] == 0) continue; - _ctx->curItem = GLOBALS.lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); + _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); - for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) + for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) { if (_ctx->curItem->Action[_ctx->j].num == 0xFF) { _ctx->MyActions[_ctx->k].nItem = _ctx->il[_ctx->i]; _ctx->MyActions[_ctx->k].nAction = _ctx->j; @@ -906,6 +904,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyActions[_ctx->k].dwLastTime = _vm->getTime(); _ctx->k++; } + } } unlockItems(); @@ -929,7 +928,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); /* We fall alseep, but always checking that the event is set when prompted for closure */ - CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS.hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS._hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); //if (_ctx->k == WAIT_OBJECT_0) if (!_ctx->expired) @@ -955,7 +954,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); if (randomVal < _ctx->MyActions[_ctx->k].perc) { /* Check if there is an action running on the item */ - if ((GLOBALS.bExecutingAction) && (GLOBALS.nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) + if ((GLOBALS._bExecutingAction) && (GLOBALS._nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) continue; /* Check to see if there already another idle funning running on the item */ @@ -968,7 +967,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Ok, we are the only ones :) */ lockItems(); - _ctx->curItem=GLOBALS.lpmiItems+itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); + _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); /* Check if there is a WhenExecute expression */ _ctx->j=_ctx->MyActions[_ctx->k].nAction; @@ -1021,7 +1020,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Set idle skip on - CORO_INVOKE_4(GLOBALS.lplpFunctions[200], 0, 0, 0, 0); + CORO_INVOKE_4(GLOBALS._lplpFunctions[200], 0, 0, 0, 0); for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) if (_ctx->MyThreads[_ctx->i].nItem != 0) { @@ -1036,7 +1035,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } // Set idle skip off - CORO_INVOKE_4(GLOBALS.lplpFunctions[201], 0, 0, 0, 0); + CORO_INVOKE_4(GLOBALS._lplpFunctions[201], 0, 0, 0, 0); /* We're finished */ globalDestroy(_ctx->MyThreads); @@ -1067,11 +1066,11 @@ void ShutUpDialogThread(CORO_PARAM, const void *param) { CORO_INVOKE_2(CoroScheduler.waitForSingleObject, pid, CORO_INFINITE); - GLOBALS.bExecutingDialog = false; - GLOBALS.nExecutingDialog = 0; - GLOBALS.nExecutingChoice = 0; + GLOBALS._bExecutingDialog = false; + GLOBALS._nExecutingDialog = 0; + GLOBALS._nExecutingChoice = 0; - CoroScheduler.setEvent(GLOBALS.hAskChoice); + CoroScheduler.setEvent(GLOBALS._hAskChoice); CORO_KILL_SELF(); @@ -1100,7 +1099,7 @@ void GroupThread(CORO_PARAM, const void *param) { lockDialogs(); // Find the pointer to the current _ctx->dialog - _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; + _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; // Search inside the group requesting the _ctx->dialog for (_ctx->i = 0; _ctx->dialog->_group[_ctx->i].num != 0; _ctx->i++) { @@ -1112,11 +1111,11 @@ void GroupThread(CORO_PARAM, const void *param) { _ctx->type = _ctx->dialog->_command[_ctx->k].type; if (_ctx->type == 1) { // Call custom function - CORO_INVOKE_4(GLOBALS.lplpFunctions[_ctx->dialog->_command[_ctx->k].nCf], - _ctx->dialog->_command[_ctx->k].arg1, - _ctx->dialog->_command[_ctx->k].arg2, - _ctx->dialog->_command[_ctx->k].arg3, - _ctx->dialog->_command[_ctx->k].arg4 + CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->dialog->_command[_ctx->k]._nCf], + _ctx->dialog->_command[_ctx->k]._arg1, + _ctx->dialog->_command[_ctx->k]._arg2, + _ctx->dialog->_command[_ctx->k]._arg3, + _ctx->dialog->_command[_ctx->k]._arg4 ); } else if (_ctx->type == 2) { @@ -1130,7 +1129,7 @@ void GroupThread(CORO_PARAM, const void *param) { CORO_INVOKE_1(doChoice, (uint32)_ctx->dialog->_command[_ctx->k].nChoice); } else { - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; unlockDialogs(); CORO_KILL_SELF(); @@ -1147,7 +1146,7 @@ void GroupThread(CORO_PARAM, const void *param) { } /* If we are here, it means that we have not found the requested group */ - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; unlockDialogs(); CORO_KILL_SELF(); @@ -1174,7 +1173,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { lockDialogs(); /* Get a pointer to the current dialog */ - _ctx->dialog = GLOBALS.lpmdDialogs + GLOBALS.nExecutingDialog; + _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; /* Search the choice between those required in the dialog */ for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) @@ -1184,7 +1183,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { /* If nothing has been found, exit with an error */ if (_ctx->dialog->_choice[_ctx->i].nChoice == 0) { /* If we're here, we did not find the required choice */ - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; unlockDialogs(); CORO_KILL_SELF(); @@ -1192,10 +1191,10 @@ void doChoice(CORO_PARAM, uint32 nChoice) { } /* We've found the requested choice. Remember what in global variables */ - GLOBALS.nExecutingChoice = _ctx->i; + GLOBALS._nExecutingChoice = _ctx->i; while (1) { - GLOBALS.nExecutingChoice = _ctx->i; + GLOBALS._nExecutingChoice = _ctx->i; _ctx->k = 0; /* Calculate the expression of each selection, to see if they're active or inactive */ @@ -1216,13 +1215,13 @@ void doChoice(CORO_PARAM, uint32 nChoice) { } /* There are choices available to the user, so wait for them to make one */ - CoroScheduler.resetEvent(GLOBALS.hDoneChoice); - CoroScheduler.setEvent(GLOBALS.hAskChoice); - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.hDoneChoice, CORO_INFINITE); + CoroScheduler.resetEvent(GLOBALS._hDoneChoice); + CoroScheduler.setEvent(GLOBALS._hAskChoice); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._hDoneChoice, CORO_INFINITE); /* Now that the choice has been made, we can run the groups associated with the choice tbontbtitq */ - _ctx->j = GLOBALS.nSelectedChoice; + _ctx->j = GLOBALS._nSelectedChoice; for (_ctx->k = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { _ctx->nGroup = _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); @@ -1266,7 +1265,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { * by calling LockItem(). */ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { - LPMPALITEM item = GLOBALS.lpmiItems; + LPMPALITEM item = GLOBALS._lpmiItems; int i; LPMPALITEM newitem; uint32 h; @@ -1311,8 +1310,8 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; - GLOBALS.nExecutingAction = item->nObj; - GLOBALS.bExecutingAction = true; + GLOBALS._nExecutingAction = item->nObj; + GLOBALS._bExecutingAction = true; return h; } @@ -1335,13 +1334,13 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { uint32 h; // Store the running dialog in a global variable - GLOBALS.nExecutingDialog = nDlgOrd; + GLOBALS._nExecutingDialog = nDlgOrd; // Enables the flag to indicate that there is' a running dialogue - GLOBALS.bExecutingDialog = true; + GLOBALS._bExecutingDialog = true; - CoroScheduler.resetEvent(GLOBALS.hAskChoice); - CoroScheduler.resetEvent(GLOBALS.hDoneChoice); + CoroScheduler.resetEvent(GLOBALS._hAskChoice); + CoroScheduler.resetEvent(GLOBALS._hDoneChoice); // Create a thread that performs the dialogue group @@ -1369,7 +1368,7 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { * @returns True if everything is OK, false on failure */ bool doSelection(uint32 i, uint32 dwData) { - LPMPALDIALOG dialog = GLOBALS.lpmdDialogs+GLOBALS.nExecutingDialog; + LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; int j; for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) @@ -1379,8 +1378,8 @@ bool doSelection(uint32 i, uint32 dwData) { if (dialog->_choice[i]._select[j].dwData == 0) return false; - GLOBALS.nSelectedChoice = j; - CoroScheduler.setEvent(GLOBALS.hDoneChoice); + GLOBALS._nSelectedChoice = j; + CoroScheduler.setEvent(GLOBALS._hDoneChoice); return true; } @@ -1411,8 +1410,8 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); /* Save the array of custom functions */ - GLOBALS.lplpFunctions = lplpcfArray; - GLOBALS.lplpFunctionStrings = lpcfStrings; + GLOBALS._lplpFunctions = lplpcfArray; + GLOBALS._lplpFunctionStrings = lpcfStrings; /* OPen the MPC file for reading */ if (!hMpc.open(lpszMpcFileName)) @@ -1489,61 +1488,61 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, */ /* Open the MPR file */ - if (!GLOBALS.hMpr.open(lpszMprFileName)) + if (!GLOBALS._hMpr.open(lpszMprFileName)) return false; /* Seek to the end of the file to read overall information */ - GLOBALS.hMpr.seek(-12, SEEK_END); + GLOBALS._hMpr.seek(-12, SEEK_END); - dwSizeComp = GLOBALS.hMpr.readUint32LE(); - if (GLOBALS.hMpr.err()) + dwSizeComp = GLOBALS._hMpr.readUint32LE(); + if (GLOBALS._hMpr.err()) return false; - GLOBALS.nResources = GLOBALS.hMpr.readUint32LE(); - if (GLOBALS.hMpr.err()) + GLOBALS._nResources = GLOBALS._hMpr.readUint32LE(); + if (GLOBALS._hMpr.err()) return false; - nBytesRead = GLOBALS.hMpr.read(buf, 4); - if (GLOBALS.hMpr.err()) + nBytesRead = GLOBALS._hMpr.read(buf, 4); + if (GLOBALS._hMpr.err()) return false; if (buf[0] !='E' || buf[1] != 'N' || buf[2] != 'D' || buf[3] != '0') return false; /* Move to the start of the resources header */ - GLOBALS.hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); + GLOBALS._hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); - GLOBALS.lpResources = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS.nResources * 8); - if (GLOBALS.lpResources == NULL) + GLOBALS._lpResources = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS._nResources * 8); + if (GLOBALS._lpResources == NULL) return false; cmpbuf = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSizeComp); if (cmpbuf == NULL) return false; - nBytesRead = GLOBALS.hMpr.read(cmpbuf, dwSizeComp); + nBytesRead = GLOBALS._hMpr.read(cmpbuf, dwSizeComp); if (nBytesRead != dwSizeComp) return false; - lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)GLOBALS.lpResources, (uint32 *)&nBytesRead); - if (nBytesRead != (uint32)GLOBALS.nResources * 8) + lzo1x_decompress((const byte *)cmpbuf, dwSizeComp, (byte *)GLOBALS._lpResources, (uint32 *)&nBytesRead); + if (nBytesRead != (uint32)GLOBALS._nResources * 8) return false; globalDestroy(cmpbuf); /* Reset back to the start of the file, leaving it open */ - GLOBALS.hMpr.seek(0, SEEK_SET); + GLOBALS._hMpr.seek(0, SEEK_SET); /* There is no action or dialog running by default */ - GLOBALS.bExecutingAction = false; - GLOBALS.bExecutingDialog = false; + GLOBALS._bExecutingAction = false; + GLOBALS._bExecutingDialog = false; /* There's no polling location */ - Common::fill(GLOBALS.nPollingLocations, GLOBALS.nPollingLocations + MAXPOLLINGLOCATIONS, 0); + Common::fill(GLOBALS._nPollingLocations, GLOBALS._nPollingLocations + MAXPOLLINGLOCATIONS, 0); /* Create the event that will be used to co-ordinate making choices and choices finishing */ - GLOBALS.hAskChoice = CoroScheduler.createEvent(true, false); - GLOBALS.hDoneChoice = CoroScheduler.createEvent(true, false); + GLOBALS._hAskChoice = CoroScheduler.createEvent(true, false); + GLOBALS._hDoneChoice = CoroScheduler.createEvent(true, false); return true; } @@ -1553,7 +1552,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, */ void mpalFree() { // Free the resource list - globalDestroy(GLOBALS.lpResources); + globalDestroy(GLOBALS._lpResources); } /** @@ -1574,7 +1573,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { va_list v; va_start(v, wQueryType); - GLOBALS.mpalError = OK; + GLOBALS._mpalError = OK; if (wQueryType == MPQ_VERSION) { @@ -1616,13 +1615,13 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { y = GETARG(uint32); if (x != -1) { if (y == MPQ_X) - dwRet = GLOBALS.lpmlLocations[x].dwXlen; + dwRet = GLOBALS._lpmlLocations[x].dwXlen; else if (y == MPQ_Y) - dwRet = GLOBALS.lpmlLocations[x].dwYlen; + dwRet = GLOBALS._lpmlLocations[x].dwYlen; else - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; } else - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; unlockLocations(); @@ -1677,7 +1676,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { else { lockItems(); y = itemGetOrderFromNum(x); - copyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1725,7 +1724,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { dwRet = doAction(x, y, GETARG(uint32)); } else { dwRet = CORO_INVALID_PID_VALUE; - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; } unlockVar(); @@ -1735,7 +1734,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup); */ - if (!GLOBALS.bExecutingDialog) { + if (!GLOBALS._bExecutingDialog) { lockDialogs(); x = dialogGetOrderFromNum(GETARG(uint32)); @@ -1747,7 +1746,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { /* * DEFAULT -> ERROR */ - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; } va_end(v); @@ -1771,7 +1770,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { va_start(v, wQueryType); void *hRet = NULL; - GLOBALS.mpalError = OK; + GLOBALS._mpalError = OK; if (wQueryType == MPQ_VERSION) { /* @@ -1811,7 +1810,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { */ lockLocations(); x = locGetOrderFromNum(GETARG(uint32)); - hRet = resLoad(GLOBALS.lpmlLocations[x].dwPicRes); + hRet = resLoad(GLOBALS._lpmlLocations[x].dwPicRes); unlockLocations(); } else if (wQueryType == MPQ_RESOURCE) { @@ -1855,7 +1854,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { else { lockItems(); y = itemGetOrderFromNum(x); - copyMemory(n, (char *)(GLOBALS.lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1905,7 +1904,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { /* * DEFAULT -> ERROR */ - GLOBALS.mpalError = 1; + GLOBALS._mpalError = 1; } va_end(v); @@ -1936,12 +1935,12 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { /* * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE); */ - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.hAskChoice, CORO_INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._hAskChoice, CORO_INFINITE); - CoroScheduler.resetEvent(GLOBALS.hAskChoice); + CoroScheduler.resetEvent(GLOBALS._hAskChoice); - if (GLOBALS.bExecutingDialog) - *dwRet = (uint32)GLOBALS.nExecutingChoice; + if (GLOBALS._bExecutingDialog) + *dwRet = (uint32)GLOBALS._nExecutingChoice; else *dwRet = (uint32)((int)-1); } else { @@ -1960,7 +1959,7 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { * @returns Error code */ uint32 mpalGetError(void) { - return GLOBALS.mpalError; + return GLOBALS._mpalError; } @@ -1980,7 +1979,7 @@ bool mpalExecuteScript(int nScript) { if (s == NULL) return false; - copyMemory(s, GLOBALS.lpmsScripts + n, sizeof(MPALSCRIPT)); + copyMemory(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT)); unlockScripts(); // !!! New process management @@ -1998,7 +1997,7 @@ bool mpalExecuteScript(int nScript) { * @param lpiifCustom Custom function to install */ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { - GLOBALS.lpiifCustom = lpiifCus; + GLOBALS._lpiifCustom = lpiifCus; } @@ -2015,16 +2014,16 @@ bool mpalStartIdlePoll(int nLoc) { uint32 i; for (i = 0; i < MAXPOLLINGLOCATIONS; i++) - if (GLOBALS.nPollingLocations[i] == (uint32)nLoc) + if (GLOBALS._nPollingLocations[i] == (uint32)nLoc) return false; for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { - if (GLOBALS.nPollingLocations[i] == 0) { - GLOBALS.nPollingLocations[i] = nLoc; + if (GLOBALS._nPollingLocations[i] == 0) { + GLOBALS._nPollingLocations[i] = nLoc; - GLOBALS.hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); + GLOBALS._hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); // !!! New process management - if ((GLOBALS.PollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) + if ((GLOBALS._pollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) // if ((GLOBALS.hEndPollingLocations[i] = (void*)_beginthread(LocationPollThread, 10240,(void *)i))= = (void*)-1) return false; @@ -2051,13 +2050,13 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { CORO_BEGIN_CODE(_ctx); for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { - if (GLOBALS.nPollingLocations[_ctx->i] == (uint32)nLoc) { - CoroScheduler.setEvent(GLOBALS.hEndPollingLocations[_ctx->i]); + if (GLOBALS._nPollingLocations[_ctx->i] == (uint32)nLoc) { + CoroScheduler.setEvent(GLOBALS._hEndPollingLocations[_ctx->i]); - CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS.PollingThreads[_ctx->i], CORO_INFINITE); + CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._pollingThreads[_ctx->i], CORO_INFINITE); - CoroScheduler.closeEvent(GLOBALS.hEndPollingLocations[_ctx->i]); - GLOBALS.nPollingLocations[_ctx->i] = 0; + CoroScheduler.closeEvent(GLOBALS._hEndPollingLocations[_ctx->i]); + GLOBALS._nPollingLocations[_ctx->i] = 0; if (result) *result = true; @@ -2078,7 +2077,7 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { * @returns Length in bytes */ int mpalGetSaveStateSize(void) { - return GLOBALS.nVars * sizeof(MPALVAR) + 4; + return GLOBALS._nVars * sizeof(MPALVAR) + 4; } @@ -2090,8 +2089,8 @@ int mpalGetSaveStateSize(void) { */ void mpalSaveState(byte *buf) { lockVar(); - WRITE_LE_UINT32(buf, GLOBALS.nVars); - copyMemory(buf + 4, (byte *)GLOBALS.lpmvVars, GLOBALS.nVars * sizeof(MPALVAR)); + WRITE_LE_UINT32(buf, GLOBALS._nVars); + copyMemory(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR)); unlockVar(); } @@ -2104,16 +2103,16 @@ void mpalSaveState(byte *buf) { */ int mpalLoadState(byte *buf) { // We must destroy and recreate all the variables - globalFree(GLOBALS.hVars); + globalFree(GLOBALS._hVars); - GLOBALS.nVars = READ_LE_UINT32(buf); + GLOBALS._nVars = READ_LE_UINT32(buf); - GLOBALS.hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS.nVars * sizeof(MPALVAR)); + GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MPALVAR)); lockVar(); - copyMemory((byte *)GLOBALS.lpmvVars, buf + 4, GLOBALS.nVars * sizeof(MPALVAR)); + copyMemory((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR)); unlockVar(); - return GLOBALS.nVars * sizeof(MPALVAR) + 4; + return GLOBALS._nVars * sizeof(MPALVAR) + 4; } bool bDontOutput; @@ -2264,8 +2263,8 @@ void mpalDumpMessages(void) { f = g_system->getSavefileManager()->openForSaving("Messages.htm"); f->writeString("\n\n
%s %s %s
\n"); - for (i = 0; i < GLOBALS.nMsgs; i++) { - lpMessage = (char *)globalLock(GLOBALS.lpmmMsgs[i].hText); + for (i = 0; i < GLOBALS._nMsgs; i++) { + lpMessage = (char *)globalLock(GLOBALS._lpmmMsgs[i]._hText); if (*lpMessage != '\0') { // bernie: debug /*if (GLOBALS.lpmmMsgs[i].wNum == 1950) { @@ -2275,7 +2274,7 @@ void mpalDumpMessages(void) { nPeriods = 1; p = lpPeriods[0] = lpMessage; - outputStartMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); + outputStartMsgComment(GLOBALS._lpmmMsgs[i]._wNum, f); while (1) { // Find the end of the current period @@ -2294,9 +2293,9 @@ void mpalDumpMessages(void) { // Now make a loop over all the periods for (j = 0; j < nPeriods; j++) { if (nPeriods == 1) - sprintf(fname, "000-%05d.WAV", GLOBALS.lpmmMsgs[i].wNum); + sprintf(fname, "000-%05d.WAV", GLOBALS._lpmmMsgs[i]._wNum); else - sprintf(fname, "000-%05d-%02d.WAV", GLOBALS.lpmmMsgs[i].wNum,j); + sprintf(fname, "000-%05d-%02d.WAV", GLOBALS._lpmmMsgs[i]._wNum,j); strcpy(frase, lpPeriods[j]); @@ -2318,9 +2317,9 @@ void mpalDumpMessages(void) { } } - OutputEndMsgComment(GLOBALS.lpmmMsgs[i].wNum, f); + OutputEndMsgComment(GLOBALS._lpmmMsgs[i]._wNum, f); - globalUnlock(GLOBALS.lpmmMsgs[i].hText); + globalUnlock(GLOBALS._lpmmMsgs[i]._hText); } } @@ -2357,13 +2356,13 @@ void mpalDumpOthers(void) { f->writeString("\n\n"); - for (i = 0; i < GLOBALS.nMsgs; i++) { - lpMessage = (char *)globalLock(GLOBALS.lpmmMsgs[i].hText); + for (i = 0; i < GLOBALS._nMsgs; i++) { + lpMessage = (char *)globalLock(GLOBALS._lpmmMsgs[i]._hText); if (*lpMessage != '\0') { nPeriods = 1; p = lpPeriods[0] = lpMessage; - if (OutputStartOther(GLOBALS.lpmmMsgs[i].wNum, f)) { + if (OutputStartOther(GLOBALS._lpmmMsgs[i]._wNum, f)) { while (1) { // Find the end of the current period while (*p != '\0') @@ -2381,9 +2380,9 @@ void mpalDumpOthers(void) { // Now loop over all the periods for (j = 0; j < nPeriods; j++) { if (nPeriods == 1) - sprintf(fname, "000-%05d.WAV", GLOBALS.lpmmMsgs[i].wNum); + sprintf(fname, "000-%05d.WAV", GLOBALS._lpmmMsgs[i]._wNum); else - sprintf(fname, "000-%05d-%02d.WAV", GLOBALS.lpmmMsgs[i].wNum,j); + sprintf(fname, "000-%05d-%02d.WAV", GLOBALS._lpmmMsgs[i]._wNum,j); strcpy(frase,lpPeriods[j]); @@ -2406,9 +2405,9 @@ void mpalDumpOthers(void) { } } - outputEndOther(GLOBALS.lpmmMsgs[i].wNum, f); + outputEndOther(GLOBALS._lpmmMsgs[i]._wNum, f); - globalUnlock(GLOBALS.lpmmMsgs[i].hText); + globalUnlock(GLOBALS._lpmmMsgs[i]._hText); } } @@ -2833,7 +2832,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { for (c = 0; c_group[g].nCmds; c++) { curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; - if (curCmd->type == 1 && curCmd->nCf == 71) { + if (curCmd->type == 1 && curCmd->_nCf == 71) { bAtLeastOne = true; break; } @@ -2849,15 +2848,15 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; // If it's a custom function, call SendDialogMessage(nPers, nMsg) - if (curCmd->type == 1 && curCmd->nCf == 71) { - sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->arg2); + if (curCmd->type == 1 && curCmd->_nCf == 71) { + sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->_arg2); for (j = 0; dlg->_periods[j] != NULL; j++) - if (dlg->_periodNums[j] == curCmd->arg2) + if (dlg->_periodNums[j] == curCmd->_arg2) break; if (dlg->_periods[j] == NULL) - warning("ERROR: Dialog %d, Period %d not found!", (int)dlg->nObj, (int)curCmd->arg2); + warning("ERROR: Dialog %d, Period %d not found!", (int)dlg->nObj, (int)curCmd->_arg2); else { frase = (char *)globalLock(dlg->_periods[j]); strcpy(copia, frase); @@ -2876,7 +2875,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { f->writeString("\t\n"); f->writeString(Common::String::format("\t\t\n", fname)); f->writeString(Common::String::format("\t\t\n", - getPersonName(dlg->nObj, curCmd->arg1))); + getPersonName(dlg->nObj, curCmd->_arg1))); f->writeString(Common::String::format("\t\t\n",copia)); f->writeString("\t\n"); //fprintf(f, "(%s) <%s> %s\n", fname, GetPersonName(dlg->nObj, curCmd->arg1), copia); @@ -2899,8 +2898,8 @@ void mpalDumpDialogs(void) { lockDialogs(); - for (i = 0; i < GLOBALS.nDialogs; i++) - mpalDumpDialog(&GLOBALS.lpmdDialogs[i]); + for (i = 0; i < GLOBALS._nDialogs; i++) + mpalDumpDialog(&GLOBALS._lpmdDialogs[i]); unlockDialogs(); } diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index e331335315..952a0957c5 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -89,8 +89,8 @@ typedef LPMPALVAR *LPLPMPALVAR; * MPAL Messages */ struct MPALMSG { - HGLOBAL hText; // Handle to the message text - uint16 wNum; // Message number + HGLOBAL _hText; // Handle to the message text + uint16 _wNum; // Message number } PACKED_STRUCT; typedef MPALMSG *LPMPALMSG; typedef LPMPALMSG *LPLPMPALMSG; @@ -124,17 +124,17 @@ struct command { byte type; // Type of control union { - int32 nCf; // Custom function call [#1] + int32 _nCf; // Custom function call [#1] char *lpszVarName; // Variable name [#2] int32 nChoice; // Number of choice you make [#3] }; union { - int32 arg1; // Argument for custom function [#1] + int32 _arg1; // Argument for custom function [#1] HGLOBAL expr; // Expression to assign to a variable [#2] }; - int32 arg2, arg3, arg4; // Arguments for custom function [#1] + int32 _arg2, _arg3, _arg4; // Arguments for custom function [#1] } PACKED_STRUCT; -- cgit v1.2.3 From 44ee26e6c99383dd9cec1392afae958faaf87b12 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 10 Jun 2012 23:56:37 +0200 Subject: TONY: Rename variables in loc.h and mpal.h --- engines/tony/mpal/mpal.cpp | 58 +++++++++++++++++++++++----------------------- engines/tony/mpal/mpal.h | 48 +++++++++++++++++++------------------- 2 files changed, 53 insertions(+), 53 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 162ba4c776..3b798b8071 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -490,7 +490,7 @@ static LPITEM getItemData(uint32 nOrdItem) { ret = (LPITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); if (ret == NULL) return NULL; - ret->speed = 150; + ret->_speed = 150; hDat = resLoad(curitem->dwRes); dat = (char *)globalLock(hDat); @@ -500,65 +500,65 @@ static LPITEM getItemData(uint32 nOrdItem) { dat += 4; if (i >= 0x10) { // From 1.0, there's a destination point for each object - ret->destX = (int16)READ_LE_UINT16(dat); - ret->destY = (int16)READ_LE_UINT16(dat + 2); + ret->_destX = (int16)READ_LE_UINT16(dat); + ret->_destY = (int16)READ_LE_UINT16(dat + 2); dat += 4; } if (i >= 0x11) { // From 1.1, there's animation speed - ret->speed = READ_LE_UINT16(dat); + ret->_speed = READ_LE_UINT16(dat); dat += 2; } else - ret->speed = 150; + ret->_speed = 150; } - ret->numframe = *dat++; - ret->numpattern = *dat++; - ret->Zvalue = *dat++; + ret->_numframe = *dat++; + ret->_numpattern = *dat++; + ret->_destZ = *dat++; // Upload the left & top co-ordinates of each frame - for (i = 0; i < ret->numframe; i++) { - ret->frameslocations[i].left = (int16)READ_LE_UINT16(dat); - ret->frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); + for (i = 0; i < ret->_numframe; i++) { + ret->_frameslocations[i].left = (int16)READ_LE_UINT16(dat); + ret->_frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); dat += 4; } // Upload the size of each frame and calculate the right & bottom - for (i = 0; i < ret->numframe; i++) { - ret->frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->frameslocations[i].left; - ret->frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->frameslocations[i].top; + for (i = 0; i < ret->_numframe; i++) { + ret->_frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->_frameslocations[i].left; + ret->_frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->_frameslocations[i].top; dat += 4; } // Upload the bounding boxes of each frame - for (i = 0; i < ret->numframe; i++) { - ret->bbox[i].left = (int16)READ_LE_UINT16(dat); - ret->bbox[i].top = (int16)READ_LE_UINT16(dat + 2); - ret->bbox[i].right = (int16)READ_LE_UINT16(dat + 4); - ret->bbox[i].bottom = (int16)READ_LE_UINT16(dat + 6); + for (i = 0; i < ret->_numframe; i++) { + ret->_bbox[i].left = (int16)READ_LE_UINT16(dat); + ret->_bbox[i].top = (int16)READ_LE_UINT16(dat + 2); + ret->_bbox[i].right = (int16)READ_LE_UINT16(dat + 4); + ret->_bbox[i].bottom = (int16)READ_LE_UINT16(dat + 6); dat += 8; } // Load the animation pattern patlength = dat; - dat += ret->numpattern; + dat += ret->_numpattern; - for (i = 1; i < ret->numpattern; i++) { + for (i = 1; i < ret->_numpattern; i++) { for (j = 0; j < patlength[i]; j++) - ret->pattern[i][j] = dat[j]; - ret->pattern[i][(int)patlength[i]] = 255; // Terminate pattern + ret->_pattern[i][j] = dat[j]; + ret->_pattern[i][(int)patlength[i]] = 255; // Terminate pattern dat += patlength[i]; } // Upload the individual frames of animations - for (i = 1; i < ret->numframe; i++) { - dim = (uint32)(ret->frameslocations[i].right-ret->frameslocations[i].left) * - (uint32)(ret->frameslocations[i].bottom-ret->frameslocations[i].top); - ret->frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); + for (i = 1; i < ret->_numframe; i++) { + dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * + (uint32)(ret->_frameslocations[i].bottom - ret->_frameslocations[i].top); + ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); - if (ret->frames[i] == NULL) + if (ret->_frames[i] == NULL) return NULL; - copyMemory(ret->frames[i], dat, dim); + copyMemory(ret->_frames[i], dat, dim); dat += dim; } diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 198083f851..9ea0c40bbc 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -152,19 +152,19 @@ enum QueryTypes { * Framework to manage the animation of an item */ typedef struct { - char *frames[MAXFRAMES]; - Common::Rect frameslocations[MAXFRAMES]; - Common::Rect bbox[MAXFRAMES]; - short pattern[MAXPATTERN][MAXFRAMES]; - short speed; - char numframe; - char numpattern; - char curframe; - char curpattern; - short destX, destY; - signed char Zvalue; - short objectID; - char TAG; + char *_frames[MAXFRAMES]; + Common::Rect _frameslocations[MAXFRAMES]; + Common::Rect _bbox[MAXFRAMES]; + short _pattern[MAXPATTERN][MAXFRAMES]; + short _speed; + char _numframe; + char _numpattern; + char _curframe; + char _curpattern; + short _destX, _destY; + signed char _destZ; + short _objectID; +// char TAG; } ITEM; typedef ITEM *LPITEM; @@ -247,7 +247,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @returns Size */ #define mpalQueryLocationSize(nLoc,dwCoord) \ - mpalQueryDWORD(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord)) + mpalQueryDWORD(MPQ_LOCATION_SIZE, (uint32)(nLoc), (uint32)(dwCoord)) /** @@ -258,7 +258,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; */ // TODO: Determine if this is endian safe #define mpalQueryItemList(nLoc) \ - (uint32 *)mpalQueryHANDLE(MPQ_ITEM_LIST,(uint32)(nLoc)) + (uint32 *)mpalQueryHANDLE(MPQ_ITEM_LIST, (uint32)(nLoc)) /** @@ -268,7 +268,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @returns Structure filled with requested information */ #define mpalQueryItemData(nItem) \ - (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA,(uint32)(nItem)) + (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA, (uint32)(nItem)) /** @@ -279,7 +279,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @remarks By default, the pattern of 0 indicates that we should do nothing. */ #define mpalQueryItemPattern(nItem) \ - mpalQueryDWORD(MPQ_ITEM_PATTERN,(uint32)(nItem)) + mpalQueryDWORD(MPQ_ITEM_PATTERN, (uint32)(nItem)) /** @@ -289,7 +289,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @returns TRUE if the item is active, FALSE otherwise */ #define mpalQueryItemIsActive(nItem) \ - (bool)mpalQueryDWORD(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem)) + (bool)mpalQueryDWORD(MPQ_ITEM_IS_ACTIVE, (uint32)(nItem)) /** @@ -302,7 +302,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * is less than or equal to 0), the string will be empty. */ #define mpalQueryItemName(nItem, lpszName) \ - mpalQueryHANDLE(MPQ_ITEM_NAME,(uint32)(nItem), (LPSTR)(lpszName)) + mpalQueryHANDLE(MPQ_ITEM_NAME, (uint32)(nItem), (LPSTR)(lpszName)) /** @@ -337,7 +337,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * The pointer msut be freed after use using the memory memory. */ #define mpalQueryDialogSelectList(nChoice) \ - (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice)) + (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST, (uint32)(nChoice)) /** @@ -351,11 +351,11 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * Groups according to the execution of the dialogue. And necessary so the game * remains on hold again for another chosen by mpalQueryDialogWaitForChoice (). */ -#define mpalQueryDialogSelection(nChoice,dwData) \ - (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) +#define mpalQueryDialogSelection(nChoice, dwData) \ + (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION, (uint32)(nChoice), (uint32)(dwData)) -#define mpalQueryDialogSelectionDWORD(nChoice,dwData) \ - mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData)) +#define mpalQueryDialogSelectionDWORD(nChoice, dwData) \ + mpalQueryDWORD(MPQ_DIALOG_SELECTION, (uint32)(nChoice), (uint32)(dwData)) /** -- cgit v1.2.3 From d4e9aa78aba58ba96d99595410fd46dd351b8aca Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 14 Jun 2012 08:08:13 +0200 Subject: TONY: Silent more CppCheck warnings --- engines/tony/mpal/expr.cpp | 22 +++++++++++----------- engines/tony/mpal/mpal.cpp | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 516da98bb1..52751120f6 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -124,8 +124,8 @@ static byte *duplicateExpression(HGLOBAL h) { two->val.pson = duplicateExpression(two->val.son); } - one++; - two++; + ++one; + ++two; } globalUnlock(h); @@ -183,23 +183,23 @@ static void solve(LPEXPRESSION one, int num) { int j; while (num > 1) { - two=one + 1; + two = one + 1; if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { - two->val.num = Compute(one->val.num, two->val.num,one->symbol); + two->val.num = Compute(one->val.num, two->val.num, one->symbol); copyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); - num--; + --num; } else { j = 1; three = two + 1; while ((three->symbol != 0) && (two->symbol & 0xF0) > (three->symbol & 0xF0)) { - two++; - three++; - j++; + ++two; + ++three; + ++j; } three->val.num = Compute(two->val.num, three->val.num, two->symbol); copyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION)); - num--; + --num; } } } @@ -390,8 +390,8 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { break; } - one++; - two++; + ++one; + ++two; } globalUnlock(h1); diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 3b798b8071..92ece3b0b4 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1565,7 +1565,7 @@ void mpalFree() { * method that returns numeric results. */ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { - int x, y, z; + int x, y; Common::String buf; uint32 dwRet = 0; char *n; @@ -1718,7 +1718,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { lockItems(); lockVar(); x = GETARG(uint32); - z = GETARG(uint32); + int z = GETARG(uint32); y = itemGetOrderFromNum(z); if (y != -1) { dwRet = doAction(x, y, GETARG(uint32)); -- cgit v1.2.3 From 37f772c2d7acf314fa1b347aae410daa1337edc2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jun 2012 18:33:38 +1000 Subject: TONY: Bugfix for hanging after giving 'shrimp' to the parrot --- engines/tony/mpal/mpal.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 92ece3b0b4..7e1831ec4d 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1937,6 +1937,12 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { */ CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._hAskChoice, CORO_INFINITE); + // WORKAROUND: Introduce a single frame delay so that if there are multiple actions running, + // they all have time to be signalled before resetting the event. This fixes a problem where + // if you try to use the 'shrimp' on the parrot a second time after trying to first use it + // whilst the parrot was talking, the cursor wouldn't be re-enabled afterwards + CORO_SLEEP(1); + CoroScheduler.resetEvent(GLOBALS._hAskChoice); if (GLOBALS._bExecutingDialog) -- cgit v1.2.3 From 8335c25cb96f970bbc546caecd845d05df06a778 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 17 Jun 2012 08:45:38 +1000 Subject: TONY: Fix memory leak in ActionThread if game exists whilst it is active --- engines/tony/mpal/mpal.cpp | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 7e1831ec4d..3b98acea59 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -699,38 +699,45 @@ void ActionThread(CORO_PARAM, const void *param) { // COROUTINE CORO_BEGIN_CONTEXT; int j, k; - CORO_END_CONTEXT(_ctx); + LPMPALITEM item; - const LPMPALITEM item = *(const LPMPALITEM *)param; + ~CoroContextTag() { + if (item) globalDestroy(item); + } + CORO_END_CONTEXT(_ctx); CORO_BEGIN_CODE(_ctx); + // The ActionThread owns the data block pointed to, so we need to make sure it's + // freed when the process exits + _ctx->item = *(LPMPALITEM *)param; + GLOBALS._mpalError = 0; - for (_ctx->j = 0; _ctx->j < item->Action[item->dwRes].nCmds; _ctx->j++) { - _ctx->k = item->Action[item->dwRes].CmdNum[_ctx->j]; + for (_ctx->j = 0; _ctx->j < _ctx->item->Action[_ctx->item->dwRes].nCmds; _ctx->j++) { + _ctx->k = _ctx->item->Action[_ctx->item->dwRes].CmdNum[_ctx->j]; - if (item->_command[_ctx->k].type == 1) { + if (_ctx->item->_command[_ctx->k].type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", - CoroScheduler.getCurrentPID(), GLOBALS._lplpFunctionStrings[item->_command[_ctx->k]._nCf].c_str(), - item->_command[_ctx->k]._arg1, item->_command[_ctx->k]._arg2, - item->_command[_ctx->k]._arg3, item->_command[_ctx->k]._arg4 + CoroScheduler.getCurrentPID(), GLOBALS._lplpFunctionStrings[_ctx->item->_command[_ctx->k]._nCf].c_str(), + _ctx->item->_command[_ctx->k]._arg1, _ctx->item->_command[_ctx->k]._arg2, + _ctx->item->_command[_ctx->k]._arg3, _ctx->item->_command[_ctx->k]._arg4 ); - CORO_INVOKE_4(GLOBALS._lplpFunctions[item->_command[_ctx->k]._nCf], - item->_command[_ctx->k]._arg1, - item->_command[_ctx->k]._arg2, - item->_command[_ctx->k]._arg3, - item->_command[_ctx->k]._arg4 + CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->item->_command[_ctx->k]._nCf], + _ctx->item->_command[_ctx->k]._arg1, + _ctx->item->_command[_ctx->k]._arg2, + _ctx->item->_command[_ctx->k]._arg3, + _ctx->item->_command[_ctx->k]._arg4 ); - } else if (item->_command[_ctx->k].type == 2) { + } else if (_ctx->item->_command[_ctx->k].type == 2) { // Variable assign debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", - CoroScheduler.getCurrentPID(), item->_command[_ctx->k].lpszVarName); + CoroScheduler.getCurrentPID(), _ctx->item->_command[_ctx->k].lpszVarName); lockVar(); - varSetValue(item->_command[_ctx->k].lpszVarName, evaluateExpression(item->_command[_ctx->k].expr)); + varSetValue(_ctx->item->_command[_ctx->k].lpszVarName, evaluateExpression(_ctx->item->_command[_ctx->k].expr)); unlockVar(); } else { @@ -739,7 +746,8 @@ void ActionThread(CORO_PARAM, const void *param) { } } - globalDestroy(item); + globalDestroy(_ctx->item); + _ctx->item = NULL; debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); -- cgit v1.2.3 From a91553efeb0e2beaf942fc3f7db30868ac8c6afa Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 17 Jun 2012 09:09:18 +1000 Subject: TONY: Cleaned up the @defgroup comments --- engines/tony/mpal/expr.cpp | 5 +++++ engines/tony/mpal/loadmpc.cpp | 3 +++ engines/tony/mpal/mpal.cpp | 3 +++ engines/tony/mpal/mpal.h | 6 +++++- 4 files changed, 16 insertions(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 52751120f6..c2fadd63df 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -42,6 +42,7 @@ namespace MPAL { /** * @defgroup Mathamatical operations */ +//@{ #define OP_MUL ((1 << 4) | 0) #define OP_DIV ((1 << 4) | 1) @@ -73,9 +74,12 @@ enum ExprListTypes { ELT_PARENTH2 = 4 }; +//@} + /** * @defgroup Structures */ +//@{ /** * Mathamatical framework to manage operations @@ -96,6 +100,7 @@ typedef struct { } EXPRESSION; typedef EXPRESSION *LPEXPRESSION; +//@} /** * Duplicate a mathematical expression. diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 6ed4545d67..b589827a5a 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -517,6 +517,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) /** * @defgroup Exported functions */ +//@{ /** * Reads and interprets the MPC file, and create structures for various directives @@ -796,6 +797,8 @@ void FreeMpc() { } } +//@} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 3b98acea59..72d8d3045c 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1395,6 +1395,7 @@ bool doSelection(uint32 i, uint32 dwData) { /** * @defgroup Exported functions */ +//@{ /** * Initialises the MPAL library and opens the .MPC file, which will be used for all queries. @@ -2918,6 +2919,8 @@ void mpalDumpDialogs(void) { unlockDialogs(); } +//@} + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 9ea0c40bbc..1ec96c97d0 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -187,6 +187,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * * The following are defines used for simplifying calling the mpalQuery variants */ +//@{ /** * Gets the current version of MPAL @@ -386,11 +387,12 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDoDialog(nDialog,nGroup) \ mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) +//@} /** * @defgroup Functions exported to the main game */ - +//@{ /** * Initializes the MPAL library, and opens an .MPC file, which will be 'used for all queries @@ -526,6 +528,8 @@ void lockVar(void); */ void unlockVar(void); +//@} + } // end of namespace MPAL } // end of namespace Tony -- cgit v1.2.3 From d24fc8b5d895b595ec62ba1588d734392bc3a5e7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 17 Jun 2012 17:42:29 +1000 Subject: TONY: Fix memory leak in LocationPollThread --- engines/tony/mpal/mpal.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 72d8d3045c..07042ec077 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -824,12 +824,24 @@ void LocationPollThread(CORO_PARAM, const void *param) { MYACTION *MyActions; MYTHREAD *MyThreads; + + ~CoroContextTag() { + // Free data blocks + if (MyThreads) + globalDestroy(MyThreads); + if (MyActions) + globalDestroy(MyActions); + } CORO_END_CONTEXT(_ctx); uint32 id = *((const uint32 *)param); CORO_BEGIN_CODE(_ctx); + /* Initialise data pointers */ + _ctx->MyActions = NULL; + _ctx->MyThreads = NULL; + /* To begin with, we need to request the item list from the location */ _ctx->il = mpalQueryItemList(GLOBALS._nPollingLocations[id]); @@ -1045,12 +1057,6 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Set idle skip off CORO_INVOKE_4(GLOBALS._lplpFunctions[201], 0, 0, 0, 0); - /* We're finished */ - globalDestroy(_ctx->MyThreads); - globalDestroy(_ctx->MyActions); - - CORO_KILL_SELF(); - CORO_END_CODE; } -- cgit v1.2.3 From b36b66630086044c54f745acfb64f91d90713045 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 17 Jun 2012 18:36:23 +0200 Subject: TONY: American-ification of English used --- engines/tony/mpal/loadmpc.cpp | 2 +- engines/tony/mpal/mpal.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index b589827a5a..1ec921dbd4 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -334,7 +334,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { * data of the item. * @returns Pointer to the buffer after the item, or NULL on failure. * @remarks It's necessary that the structure that is passed has been - * completely initialised to 0 beforehand. + * completely initialized to 0 beforehand. */ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { byte len; diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 07042ec077..bb3df1662f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -838,7 +838,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - /* Initialise data pointers */ + /* Initialize data pointers */ _ctx->MyActions = NULL; _ctx->MyThreads = NULL; @@ -1404,7 +1404,7 @@ bool doSelection(uint32 i, uint32 dwData) { //@{ /** - * Initialises the MPAL library and opens the .MPC file, which will be used for all queries. + * Initializes the MPAL library and opens the .MPC file, which will be used for all queries. * * @param lpszMpcFileName Name of the MPC file * @param lpszMprFileName Name of the MPR file -- cgit v1.2.3 From 31c0210f22bb4cc839abb9fa59539fd97d3a74f6 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 17 Jun 2012 18:38:34 +0200 Subject: TONY: Missed one word in previous commit (thanks clone2727) --- engines/tony/mpal/mpaldll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 952a0957c5..fe1eb2b34a 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -114,7 +114,7 @@ typedef LPMPALLOCATION *LPLPMPALLOCATION; */ struct command { /* - * Types of commands that are recognised + * Types of commands that are recognized * * #1 -> Custom function call (ITEM, SCRIPT, DIALOG) * #2 -> Variable assignment (ITEM, SCRIPT, DIALOG) -- cgit v1.2.3 From e8a6f61f8815fcf36e7a43383695c74b8925993f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 18 Jun 2012 08:24:33 +0200 Subject: TONY: Remove useless void in function declaration --- engines/tony/mpal/mpal.cpp | 56 ++++++++++++++-------------------------------- engines/tony/mpal/mpal.h | 25 ++++----------------- 2 files changed, 21 insertions(+), 60 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index bb3df1662f..7385e60b66 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -59,101 +59,91 @@ const char *mpalCopyright = /** * Locks the variables for access */ -void lockVar(void) { +void lockVar() { GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); } /** * Unlocks variables after use */ -void unlockVar(void) { +void unlockVar() { globalUnlock(GLOBALS._hVars); } /** * Locks the messages for access */ -static void LockMsg(void) { +static void LockMsg() { #ifdef NEED_LOCK_MSGS GLOBALS._lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); #endif } - /** * Unlocks the messages after use */ -static void UnlockMsg(void) { +static void UnlockMsg() { #ifdef NEED_LOCK_MSGS globalUnlock(GLOBALS._hMsgs); #endif } - /** * Locks the dialogs for access */ -static void lockDialogs(void) { +static void lockDialogs() { GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); } - /** * Unlocks the dialogs after use */ -static void unlockDialogs(void) { +static void unlockDialogs() { globalUnlock(GLOBALS._hDialogs); } - /** * Locks the location data structures for access */ -static void lockLocations(void) { +static void lockLocations() { GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); } - /** * Unlocks the location structures after use */ -static void unlockLocations(void) { +static void unlockLocations() { globalUnlock(GLOBALS._hLocations); } - /** * Locks the items structures for use */ -static void lockItems(void) { +static void lockItems() { GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); } - /** * Unlocks the items structures after use */ -static void unlockItems(void) { +static void unlockItems() { globalUnlock(GLOBALS._hItems); } - /** * Locks the script data structures for use */ -static void LockScripts(void) { +static void LockScripts() { GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); } - /** * Unlocks the script data structures after use */ -static void unlockScripts(void) { +static void unlockScripts() { globalUnlock(GLOBALS._hScripts); } - /** * Returns the current value of a global variable * @@ -175,7 +165,6 @@ int32 varGetValue(const char *lpszVarName) { return 0; } - /** * Sets the value of a MPAL global variable * @param lpszVarName Name of the variable @@ -204,7 +193,6 @@ void varSetValue(const char *lpszVarName, int32 val) { return; } - /** * Find the index of a location within the location array. Remember to call LockLoc() beforehand. * @@ -1973,17 +1961,15 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { va_end(v); } - /** * Returns the current MPAL error code * * @returns Error code */ -uint32 mpalGetError(void) { +uint32 mpalGetError() { return GLOBALS._mpalError; } - /** * Execute a script. The script runs on multitasking by a thread. * @@ -2091,17 +2077,15 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { CORO_END_CODE; } - /** * Retrieve the length of a save state * * @returns Length in bytes */ -int mpalGetSaveStateSize(void) { +int mpalGetSaveStateSize() { return GLOBALS._nVars * sizeof(MPALVAR) + 4; } - /** * Store the save state into a buffer. The buffer must be * length at least the size specified with mpalGetSaveStateSize @@ -2251,7 +2235,6 @@ int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { return 0; } - void outputEndOther(uint16 wNum, Common::OutSaveFile *f) { int i; @@ -2262,8 +2245,7 @@ void outputEndOther(uint16 wNum, Common::OutSaveFile *f) { } } - -void mpalDumpMessages(void) { +void mpalDumpMessages() { int i, j; char *lpMessage; char *p; @@ -2354,9 +2336,7 @@ void mpalDumpMessages(void) { UnlockMsg(); } - - -void mpalDumpOthers(void) { +void mpalDumpOthers() { int i,j; char *lpMessage; char *p; @@ -2914,7 +2894,7 @@ void mpalDumpDialog(LPMPALDIALOG dlg) { delete v1; } -void mpalDumpDialogs(void) { +void mpalDumpDialogs() { int i; lockDialogs(); @@ -2925,8 +2905,6 @@ void mpalDumpDialogs(void) { unlockDialogs(); } -//@} - } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 1ec96c97d0..251e78afdf 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -327,7 +327,6 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDialogWaitForChoice(dwRet) \ CORO_INVOKE_2(mpalQueryCORO, MPQ_DIALOG_WAITFORCHOICE, dwRet) - /** * Requires a list of various options for some choice within the current dialog. * @@ -340,7 +339,6 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDialogSelectList(nChoice) \ (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST, (uint32)(nChoice)) - /** * Warns the library that the user has selected, in a certain choice of the current dialog, * corresponding option at a certain given. @@ -358,7 +356,6 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDialogSelectionDWORD(nChoice, dwData) \ mpalQueryDWORD(MPQ_DIALOG_SELECTION, (uint32)(nChoice), (uint32)(dwData)) - /** * Warns the library an action was performed on a Object. * The library will call custom functions, if necessary. @@ -375,7 +372,6 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDoAction(nAction, nItem, dwParam) \ mpalQueryDWORD(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam)) - /** * Warns the library a dialogue was required. * @@ -387,8 +383,6 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; #define mpalQueryDoDialog(nDialog,nGroup) \ mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) -//@} - /** * @defgroup Functions exported to the main game */ @@ -442,7 +436,6 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...); */ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...); - /** * Execute a script. The script runs on multitasking by a thread. * @@ -451,14 +444,12 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...); */ bool mpalExecuteScript(int nScript); - /** * Returns the current MPAL error code * * @returns Error code */ -uint32 mpalGetError(void); - +uint32 mpalGetError(); /** * Install a custom routine That will be called by MPAL every time the pattern @@ -468,7 +459,6 @@ uint32 mpalGetError(void); */ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); - /** * Process the idle actions of the items on one location. * @@ -480,7 +470,6 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); */ bool mpalStartIdlePoll(int nLoc); - /** * Stop processing the idle actions of the items on one location. * @@ -499,7 +488,6 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result); */ int mpalLoadState(byte *buf); - /** * Store the save state into a buffer. The buffer must be * length at least the size specified with mpalGetSaveStateSize @@ -508,27 +496,22 @@ int mpalLoadState(byte *buf); */ void mpalSaveState(byte *buf); - /** * Retrieve the length of a save state * * @returns Length in bytes */ -int mpalGetSaveStateSize(void); - +int mpalGetSaveStateSize(); /** * Locks the variables for access */ -void lockVar(void); - +void lockVar(); /** * Unlocks variables after use */ -void unlockVar(void); - -//@} +void unlockVar(); } // end of namespace MPAL -- cgit v1.2.3 From 0aa3d39cf7034dc35cda9e5062469886b0eb74d2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 18 Jun 2012 19:56:28 +1000 Subject: TONY: Remove unused stubs for LZO compression --- engines/tony/mpal/lzo.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/lzo.cpp b/engines/tony/mpal/lzo.cpp index 17b059455c..48a0d8ea87 100644 --- a/engines/tony/mpal/lzo.cpp +++ b/engines/tony/mpal/lzo.cpp @@ -506,19 +506,6 @@ lookbehind_overrun: #endif } -int lzo1x_1_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem) { - warning("TODO: lzo1x_1_compress"); - return 0; -} - -/** - * better compression ratio at the cost of more memory and time - */ -int lzo1x_999_compress(const byte *src, uint32 src_len, byte *dst, uint32 *dst_len, void *wrkmem) { - warning("TODO: lzo1x_999_compress"); - return 0; -} - } // end of namespace MPAL } // end of namespace Tony -- cgit v1.2.3 From 3b40d141529160d48da954397fa7b58659b46da5 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Tue, 31 Jul 2012 20:36:48 +0200 Subject: TONY: Whitespace changes. --- engines/tony/mpal/expr.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index c2fadd63df..7cf2cb3fc8 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -141,41 +141,41 @@ static int Compute(int a, int b, byte symbol) { switch (symbol) { case OP_MUL: return a * b; - case OP_DIV: + case OP_DIV: return a / b; - case OP_MODULE: + case OP_MODULE: return a % b; - case OP_ADD: + case OP_ADD: return a + b; - case OP_SUB: + case OP_SUB: return a - b; - case OP_SHL: + case OP_SHL: return a << b; - case OP_SHR: + case OP_SHR: return a >> b; - case OP_MINOR: + case OP_MINOR: return a < b; - case OP_MAJOR: + case OP_MAJOR: return a > b; - case OP_MINEQ: + case OP_MINEQ: return a <= b; - case OP_MAJEQ: + case OP_MAJEQ: return a >= b; - case OP_EQUAL: + case OP_EQUAL: return a == b; - case OP_NOEQUAL: + case OP_NOEQUAL: return a != b; - case OP_BITAND: + case OP_BITAND: return a & b; - case OP_BITXOR: + case OP_BITXOR: return a ^ b; - case OP_BITOR: + case OP_BITOR: return a | b; - case OP_AND: + case OP_AND: return a && b; - case OP_OR: + case OP_OR: return a || b; - default: + default: GLOBALS._mpalError = 1; break; } -- cgit v1.2.3 From fab814b7747be31278fbbfa1d46e28115cd6624e Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Tue, 31 Jul 2012 21:29:25 +0200 Subject: TONY: Remove unused variable. It wasn't used in the original engine either. --- engines/tony/mpal/loadmpc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 1ec921dbd4..371a94e24a 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -529,7 +529,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) bool ParseMpc(const byte *lpBuf) { uint16 i, j; uint16 wLen; - byte *lpTemp, *lpTemp2; + byte *lpTemp; /* 1. Variables */ if (lpBuf[0] != 'V' || lpBuf[1] != 'A' || lpBuf[2] != 'R' || lpBuf[3] != 'S') @@ -587,7 +587,7 @@ bool ParseMpc(const byte *lpBuf) { j += lpBuf[j] + 1; GLOBALS._lpmmMsgs->_hText = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, j + 1); - lpTemp2 = lpTemp = (byte *)globalLock(GLOBALS._lpmmMsgs->_hText); + lpTemp = (byte *)globalLock(GLOBALS._lpmmMsgs->_hText); for (j = 0; lpBuf[j] != 0;) { copyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]); -- cgit v1.2.3 From c3407390013b1e1826bdb31979a50f5e8a957f04 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Wed, 22 Aug 2012 14:00:46 +0200 Subject: TONY: Replace _vm with g_vm. --- engines/tony/mpal/mpal.cpp | 22 +++++++++++----------- engines/tony/mpal/mpalutils.cpp | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 7385e60b66..20c28c5c93 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -607,7 +607,7 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - _ctx->dwStartTime = _vm->getTime(); + _ctx->dwStartTime = g_vm->getTime(); _ctx->numHandles = 0; // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); @@ -615,9 +615,9 @@ void ScriptThread(CORO_PARAM, const void *param) { // Sleep for the required time if (s->Moment[_ctx->i].dwTime == -1) { CORO_INVOKE_4(CoroScheduler.waitForMultipleObjects, _ctx->numHandles, cfHandles, true, CORO_INFINITE); - _ctx->dwStartTime = _vm->getTime(); + _ctx->dwStartTime = g_vm->getTime(); } else { - _ctx->dwCurTime = _vm->getTime(); + _ctx->dwCurTime = g_vm->getTime(); if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); @@ -761,11 +761,11 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { GLOBALS._bExecutingAction = false; - if (_vm->_initialLoadSlotNumber != -1) { - _ctx->slotNumber = _vm->_initialLoadSlotNumber; - _vm->_initialLoadSlotNumber = -1; + if (g_vm->_initialLoadSlotNumber != -1) { + _ctx->slotNumber = g_vm->_initialLoadSlotNumber; + g_vm->_initialLoadSlotNumber = -1; - CORO_INVOKE_1(_vm->loadState, _ctx->slotNumber); + CORO_INVOKE_1(g_vm->loadState, _ctx->slotNumber); } @@ -909,7 +909,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { copyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - _ctx->MyActions[_ctx->k].dwLastTime = _vm->getTime(); + _ctx->MyActions[_ctx->k].dwLastTime = g_vm->getTime(); _ctx->k++; } } @@ -925,7 +925,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { while (1) { /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per l'esecuzione */ - _ctx->curTime = _vm->getTime(); + _ctx->curTime = g_vm->getTime(); _ctx->dwSleepTime = (uint32)-1L; for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) @@ -951,7 +951,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyThreads[_ctx->i].nItem = 0; } - _ctx->curTime = _vm->getTime(); + _ctx->curTime = g_vm->getTime(); /* Loop through all the necessary idle actions */ for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) @@ -959,7 +959,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; /* It's time to check to see if fortune is on the side of the idle action */ - byte randomVal = (byte)_vm->_randomSource.getRandomNumber(99); + byte randomVal = (byte)g_vm->_randomSource.getRandomNumber(99); if (randomVal < _ctx->MyActions[_ctx->k].perc) { /* Check if there is an action running on the item */ if ((GLOBALS._bExecutingAction) && (GLOBALS._nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index aba92a86cd..aa22456a4b 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -37,7 +37,7 @@ namespace MPAL { * @param resId MPAL resource to open */ RMRes::RMRes(uint32 resID) { - _h = _vm->_resUpdate.queryResource(resID); + _h = g_vm->_resUpdate.queryResource(resID); if (_h == NULL) _h = mpalQueryResource(resID); if (_h != NULL) -- cgit v1.2.3 From a9828c88184a4c1a9161ca1fe80f5e6fff9c4f4e Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 25 Aug 2012 10:06:10 +0200 Subject: TONY: Replace copyMemory with memcpy. --- engines/tony/mpal/expr.cpp | 8 ++++---- engines/tony/mpal/loadmpc.cpp | 10 +++++----- engines/tony/mpal/memory.cpp | 9 --------- engines/tony/mpal/memory.h | 3 --- engines/tony/mpal/mpal.cpp | 24 ++++++++++++------------ 5 files changed, 21 insertions(+), 33 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 7cf2cb3fc8..eb6b485ef6 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -121,7 +121,7 @@ static byte *duplicateExpression(HGLOBAL h) { clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); two = (LPEXPRESSION)(clone + 1); - copyMemory(clone, orig, sizeof(EXPRESSION) * num + 1); + memcpy(clone, orig, sizeof(EXPRESSION) * num + 1); for (i = 0; i < num; i++) { if (one->type == ELT_PARENTH) { @@ -191,7 +191,7 @@ static void solve(LPEXPRESSION one, int num) { two = one + 1; if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { two->val.num = Compute(one->val.num, two->val.num, one->symbol); - copyMemory(one, two, (num - 1) * sizeof(EXPRESSION)); + memcpy(one, two, (num - 1) * sizeof(EXPRESSION)); --num; } else { j = 1; @@ -203,7 +203,7 @@ static void solve(LPEXPRESSION one, int num) { } three->val.num = Compute(two->val.num, three->val.num, two->symbol); - copyMemory(two, three, (num - j - 1) * sizeof(EXPRESSION)); + memcpy(two, three, (num - j - 1) * sizeof(EXPRESSION)); --num; } } @@ -291,7 +291,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { cur->val.name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); if (cur->val.name == NULL) return NULL; - copyMemory(cur->val.name, lpBuf + 1, *lpBuf); + memcpy(cur->val.name, lpBuf + 1, *lpBuf); lpBuf += *lpBuf + 1; break; diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 371a94e24a..a0dff2927a 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -102,7 +102,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmsScript->_command[curCmd].lpszVarName == NULL) return NULL; - copyMemory(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len); + memcpy(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len); lpBuf += len; lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd].expr); @@ -346,7 +346,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { len = *lpBuf; lpBuf++; - copyMemory(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); + memcpy(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); lpBuf += len; if (len >= MAX_DESCRIBE_SIZE) @@ -416,7 +416,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmiItem->_command[curCmd].lpszVarName == NULL) return NULL; - copyMemory(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len); + memcpy(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len); lpBuf += len; lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd].expr); @@ -548,7 +548,7 @@ bool ParseMpc(const byte *lpBuf) { for (i = 0; i < GLOBALS._nVars; i++) { wLen = *(const byte *)lpBuf; lpBuf++; - copyMemory(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); + memcpy(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; GLOBALS._lpmvVars->dwVal = READ_LE_UINT32(lpBuf); lpBuf += 4; @@ -590,7 +590,7 @@ bool ParseMpc(const byte *lpBuf) { lpTemp = (byte *)globalLock(GLOBALS._lpmmMsgs->_hText); for (j = 0; lpBuf[j] != 0;) { - copyMemory(lpTemp, &lpBuf[j + 1], lpBuf[j]); + memcpy(lpTemp, &lpBuf[j + 1], lpBuf[j]); lpTemp += lpBuf[j]; *lpTemp ++= '\0'; j += lpBuf[j] + 1; diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index c5e752d390..3a68ecb559 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -124,15 +124,6 @@ void MemoryManager::unlockItem(HANDLE handle) { } -/****************************************************************************\ -* Stand-alone methods -\****************************************************************************/ - -void copyMemory(void *dst, const void *first, int size) { - Common::copy((const byte *)first, (const byte *)first + size, (byte *)dst); -} - - } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index 52d527544a..c7e4896cf9 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -70,9 +70,6 @@ public: #define GMEM_MOVEABLE 2 #define GMEM_ZEROINIT 4 -// Stand-alone methods -extern void copyMemory(void *dst, const void *first, int size); - } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 20c28c5c93..76ca8a5db3 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -313,7 +313,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { if (clonemsg == NULL) return NULL; - copyMemory(clonemsg, origmsg, j); + memcpy(clonemsg, origmsg, j); globalUnlock(GLOBALS._lpmmMsgs[nMsgOrd]._hText); return clonemsg; @@ -346,7 +346,7 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { if (clonemsg == NULL) return NULL; - copyMemory(clonemsg, origmsg, i); + memcpy(clonemsg, origmsg, i); globalUnlock(dialog->_periods[j]); @@ -546,7 +546,7 @@ static LPITEM getItemData(uint32 nOrdItem) { if (ret->_frames[i] == NULL) return NULL; - copyMemory(ret->_frames[i], dat, dim); + memcpy(ret->_frames[i], dat, dim); dat += dim; } @@ -906,7 +906,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->MyActions[_ctx->k].perc = _ctx->curItem->Action[_ctx->j].perc; _ctx->MyActions[_ctx->k].when = _ctx->curItem->Action[_ctx->j].when; _ctx->MyActions[_ctx->k].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; - copyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, + memcpy(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); _ctx->MyActions[_ctx->k].dwLastTime = g_vm->getTime(); @@ -995,12 +995,12 @@ void LocationPollThread(CORO_PARAM, const void *param) { return; } - copyMemory(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); + memcpy(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); unlockItems(); /* We copy the action in #0 */ // _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; -// copyMemory(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); +// memcpy(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); _ctx->newItem->dwRes=_ctx->j; /* We will create an action, and will provide the necessary details */ @@ -1298,7 +1298,7 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // In the new version number of the action in writing dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); /* newitem->Action[0].nCmds=item->Action[i].nCmds; - copyMemory(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); + memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); */ newitem->dwRes = i; @@ -1679,7 +1679,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { else { lockItems(); y = itemGetOrderFromNum(x); - copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1857,7 +1857,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { else { lockItems(); y = itemGetOrderFromNum(x); - copyMemory(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1986,7 +1986,7 @@ bool mpalExecuteScript(int nScript) { if (s == NULL) return false; - copyMemory(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT)); + memcpy(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT)); unlockScripts(); // !!! New process management @@ -2095,7 +2095,7 @@ int mpalGetSaveStateSize() { void mpalSaveState(byte *buf) { lockVar(); WRITE_LE_UINT32(buf, GLOBALS._nVars); - copyMemory(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR)); + memcpy(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR)); unlockVar(); } @@ -2114,7 +2114,7 @@ int mpalLoadState(byte *buf) { GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MPALVAR)); lockVar(); - copyMemory((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR)); + memcpy((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR)); unlockVar(); return GLOBALS._nVars * sizeof(MPALVAR) + 4; -- cgit v1.2.3 From 6805c2cec20cb41f20abdbd4ecb8b2dfa52f2143 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 27 Aug 2012 13:07:34 +0200 Subject: TONY: Translate some minor Italian comments --- engines/tony/mpal/loadmpc.cpp | 2 +- engines/tony/mpal/loadmpc.h | 2 +- engines/tony/mpal/mpaldll.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index a0dff2927a..ed4ad9d228 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -39,7 +39,7 @@ namespace Tony { namespace MPAL { /****************************************************************************\ -* Funzioni statiche +* Static functions \****************************************************************************/ static bool compareCommands(struct command *cmd1, struct command *cmd2) { diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index 83463f0092..b805b1e7a1 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -34,7 +34,7 @@ namespace Tony { namespace MPAL { /****************************************************************************\ -* Prototipi di funzione +* Function prototypes \****************************************************************************/ /** diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index fe1eb2b34a..e637362bdf 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -69,7 +69,7 @@ namespace MPAL { /****************************************************************************\ -* Strutture +* Structures \****************************************************************************/ #include "common/pack-start.h" -- cgit v1.2.3 From 18b1f6d7c6e5a70d2073178cffbde53236225b4b Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Tue, 28 Aug 2012 13:33:24 +0200 Subject: TONY: Remove unused data dumping code. --- engines/tony/mpal/mpal.cpp | 785 --------------------------------------------- 1 file changed, 785 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 76ca8a5db3..16d8a3213b 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -2120,791 +2120,6 @@ int mpalLoadState(byte *buf) { return GLOBALS._nVars * sizeof(MPALVAR) + 4; } -bool bDontOutput; - -struct MsgCommentsStruct { - uint16 wStart; - uint16 wEnd; - const char *pComment; -}; -const MsgCommentsStruct MsgComments[] = { - { 10, 16, "###" }, - { 560, 563, "@@@ BUTCH & DUDLEY:" }, - { 551, 553, "@@@ JACK'S LETTER (JACK'S VOICE):" }, - { 679, 679, "@@@ OFF-SCREEN VOICE:" }, - { 799, 799, "###" }, - { 830, 838, "RE-HASHING (FROM MACBETH):" }, - { 890, 894, "@@@ BEARDED LADY FROM WITHIN HER ROOM:" }, - { 1175, 1175, "###" }, - { 1210, 1210, "###" }, - { 1347, 1349, "###" }, - { 1175, 1175, "###" }, - { 1342, 1343, "###" }, - { 1742, 1742, "@@@ OFF-SCREEN VOICE:" }, - { 1749, 1749, "###" }, - { 1759, 1759, "###" }, - { 2165, 2166, "@@@ MORTIMER:" }, - { 2370, 2372, "@@@ ELECTRONIC VOICE FROM AN AUTOMATIC PICTURE MACHINE:" }, - { 2580, 2589, "@@@ BIFF:" }, - { 2590, 2593, "@@@ BARTENDER:" }, - { 2596, 2596, "@@@ SAD PIRATE:" }, - { 2760, 2767, "@@@ EGGHEAD:" }, - { 2959, 2959, "@@@ MONSTROUS VOICE FROM BEHIND A LOCKED DOOR:" }, - { 3352, 3352, "@@@ POLLY:" }, - { 3378, 3379, "@@@ POLLY:" }, - { 3461, 3469, "@@@ RANDALL:" }, - { 3571, 3574, "@@@ CAPTAIN'S JOURNAL (CAPTAIN'S VOICE):" }, - { 3646, 3646, "NOTE: THIS SENTENCE ENDS THE STORY TOLD IN SENTENCES 03640 - 03643:" }, - { 3647, 3648, "TONY SPEAKS TRYING TO IMITATE CAPTAIN CORNELIUS' VOICE:" }, - { 3670, 3671, "###" }, - { 3652, 3652, "###" }, - { 3656, 3657, "@@@ GATEKEEPER:" }, - { 3658, 3659, "@@@ GATEKEEPER (FAR AWAY):" }, - { 3790, 3795, "@@@ GATEKEEPER:" }, - { 3798, 3799, "@@@ OFF-SCREEN VOICE:" }, - { 4384, 4384, "###" }, - { 4394, 4395, "###" }, - { 4780, 4780, "###" }, - { 5089, 5089, "TONY PLAYING SOMEONE ELSE, WITH A DEEPER TONE:" }, - { 5090, 5090, "NORMAL TONY:" }, - { 5091, 5091, "TONY PLAYING SOMEONE ELSE, WITH A DEEPER TONE:" }, - { 5262, 5262, "@@@ OFF-SCREEN VOICE" }, - { 5276, 5277, "###" }, - { 5326, 5326, "###" }, - { 5472, 5472, "LYRICS FROM THE SONG \"I AM ONE\", BY SMASHING PUMPKINS:" }, - { 5488, 5488, "LYRICS FROM THE SONG \"I AM ONE\", BY SMASHING PUMPKINS:" }, - { 5652, 5653, "###" }, -//bernie { 11000, 15000, "###" }, - { 11000, 11111, "###" }, - - - { 0, 0, NULL } -}; - -void outputStartMsgComment(uint16 wNum, Common::OutSaveFile *f) { - int i; - - for (i = 0; MsgComments[i].wStart != 0; i++) - if (MsgComments[i].wStart == wNum) { - debugC(DEBUG_BASIC, kTonyDebugMPAL, "Start: %d\n", wNum); - - f->writeString("
%s %s %s
\n

\n

\n"); - - if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { - f->writeString(Common::String::format("%s\n", MsgComments[i].pComment)); - f->writeString("

\n

\n\n"); - } else - bDontOutput = true; - return; - } -} - -void OutputEndMsgComment(uint16 wNum, Common::OutSaveFile *f) { - int i; - - for (i = 0; MsgComments[i].wEnd != 0; i++) - if (MsgComments[i].wEnd == wNum) { - debugC(DEBUG_BASIC, kTonyDebugMPAL, "End: %d\n", wNum); - - if (strcmp(MsgComments[i].pComment, "###") != 0 && strncmp(MsgComments[i].pComment, "@@@", 3) != 0) { - f->writeString("
\n

\n"); - } else - bDontOutput = false; - - f->writeString("

\n

\n\n"); - return; - } -} - - -int OutputStartOther(uint16 wNum, Common::OutSaveFile *f) { - int i; - - for (i = 0; MsgComments[i].wStart != 0; i++) - if (MsgComments[i].wStart <= wNum && MsgComments[i].wEnd >= wNum) { - if (strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { - if (MsgComments[i].wStart == wNum) { - f->writeString(Common::String::format("%s\n", MsgComments[i].pComment + 4)); - f->writeString("

\n

\n

\n"); - } - - return 1; - } - } - - return 0; -} - -void outputEndOther(uint16 wNum, Common::OutSaveFile *f) { - int i; - - for (i = 0; MsgComments[i].wStart != 0; i++) - if (MsgComments[i].wEnd == wNum && strncmp(MsgComments[i].pComment, "@@@", 3) == 0) { - f->writeString("
\n

\n"); - break; - } -} - -void mpalDumpMessages() { - int i, j; - char *lpMessage; - char *p; - char *lpPeriods[30]; - char fname[64]; - char frase[2048]; - int nPeriods; - Common::OutSaveFile *f, *v1; - - v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); - - LockMsg(); - - bDontOutput = false; - - debugC(DEBUG_BASIC, kTonyDebugMPAL, "Dumping MESSAGES.HTM...\n"); - - f = g_system->getSavefileManager()->openForSaving("Messages.htm"); - f->writeString("\n\n\n"); - - for (i = 0; i < GLOBALS._nMsgs; i++) { - lpMessage = (char *)globalLock(GLOBALS._lpmmMsgs[i]._hText); - if (*lpMessage != '\0') { - // bernie: debug - /*if (GLOBALS.lpmmMsgs[i].wNum == 1950) { - int a = 1; - }*/ - - nPeriods = 1; - p = lpPeriods[0] = lpMessage; - - outputStartMsgComment(GLOBALS._lpmmMsgs[i]._wNum, f); - - while (1) { - // Find the end of the current period - while (*p != '\0') - p++; - - // If there is another '\0' at the end of the message, then finish - p++; - if (*p == '\0') - break; - - // Otherwise there is another line, so remember the next one's start - lpPeriods[nPeriods++] = p; - } - - // Now make a loop over all the periods - for (j = 0; j < nPeriods; j++) { - if (nPeriods == 1) - sprintf(fname, "000-%05d.WAV", GLOBALS._lpmmMsgs[i]._wNum); - else - sprintf(fname, "000-%05d-%02d.WAV", GLOBALS._lpmmMsgs[i]._wNum,j); - - strcpy(frase, lpPeriods[j]); - - while ((p = strchr(frase,'^')) != NULL) - *p = '\"'; - - p = frase; - while (*p == ' ') - p++; - if (*p == '\0') - continue; - - if (!bDontOutput) { - v1->writeString(Common::String::format("%s\n", fname)); - f->writeString("\t\n"); - f->writeString(Common::String::format("\t\t\n", fname)); - f->writeString(Common::String::format("\t\t\n", frase)); - f->writeString("\t\n"); - } - } - - OutputEndMsgComment(GLOBALS._lpmmMsgs[i]._wNum, f); - - globalUnlock(GLOBALS._lpmmMsgs[i]._hText); - } - } - - f->writeString("
%s %s
\n\n\n"); - - f->finalize(); - v1->finalize(); - delete f; - delete v1; - - UnlockMsg(); -} - -void mpalDumpOthers() { - int i,j; - char *lpMessage; - char *p; - char *lpPeriods[30]; - char fname[64]; - char frase[2048]; - int nPeriods; - - Common::OutSaveFile *f, *v1; - - v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); - f = g_system->getSavefileManager()->openForSaving("Others.htm"); - LockMsg(); - - bDontOutput = false; - - debugC(DEBUG_BASIC, kTonyDebugMPAL, "Dumping OTHERS.HTM...\n"); - - f->writeString("\n\n"); - - for (i = 0; i < GLOBALS._nMsgs; i++) { - lpMessage = (char *)globalLock(GLOBALS._lpmmMsgs[i]._hText); - if (*lpMessage != '\0') { - nPeriods = 1; - p = lpPeriods[0] = lpMessage; - - if (OutputStartOther(GLOBALS._lpmmMsgs[i]._wNum, f)) { - while (1) { - // Find the end of the current period - while (*p != '\0') - p++; - - // If there is another '0' at the end, then the message is finished - p++; - if (*p == '\0') - break; - - // Remember the start of the next line - lpPeriods[nPeriods++] = p; - } - - // Now loop over all the periods - for (j = 0; j < nPeriods; j++) { - if (nPeriods == 1) - sprintf(fname, "000-%05d.WAV", GLOBALS._lpmmMsgs[i]._wNum); - else - sprintf(fname, "000-%05d-%02d.WAV", GLOBALS._lpmmMsgs[i]._wNum,j); - - strcpy(frase,lpPeriods[j]); - - while ((p = strchr(frase, '^')) != NULL) - *p = '\"'; - - p = frase; - while (*p == ' ') - p++; - if (*p == '\0') - continue; - - if (!bDontOutput) { - v1->writeString(Common::String::format("%s\n", fname)); - f->writeString("\t\n"); - f->writeString(Common::String::format("\t\t %s \n", fname)); - f->writeString(Common::String::format("\t\t %s \n", frase)); - f->writeString("\t\n"); - } - } - } - - outputEndOther(GLOBALS._lpmmMsgs[i]._wNum, f); - - globalUnlock(GLOBALS._lpmmMsgs[i]._hText); - } - } - - f->writeString("\n\n"); - - f->finalize(); - v1->finalize(); - - delete f; - delete v1; - UnlockMsg(); -} - - -#if 0 // English names -const char *DLG10[] = { "Tony", NULL }; -const char *DLG51[] = { "Tony", "Butch", "Dudley" }; -const char *DLG52[] = { "Tony", NULL }; -const char *DLG61[] = { "Tony", "Old lady 1", NULL }; -const char *DLG71[] = { "Tony", "Timothy", "Convict", NULL, NULL, "Jack (with microphone)", "Old lady 1", NULL }; -const char *DLG90[] = { "Tony", "Bearded lady", NULL }; -const char *DLG110[] = { "Tony", "Lorenz", NULL }; -const char *DLG111[] = { "Tony", "Lorenz", NULL }; -const char *DLG130[] = { "Tony", "Piranha", NULL }; -const char *DLG150[] = { "Tony", "Rufus", "Snowman", NULL }; -const char *DLG151[] = { "Tony", "Rufus", "Snowman", NULL }; -const char *DLG152[] = { "Tony", "Rufus", "Snowman", NULL }; -const char *DLG153[] = { "Tony", "Rufus", "Snowman", NULL }; -const char *DLG154[] = { "Tony", "Rufus", "Snowman", NULL }; -const char *DLG160[] = { "Tony", "Shmiley", NULL }; -const char *DLG161[] = { "Tony", "Shmiley", NULL }; -const char *DLG162[] = { "Tony", "Shmiley", NULL }; -const char *DLG163[] = { "Tony", "Shmiley", NULL }; -const char *DLG180[] = { "Tony", "Beast", NULL }; -const char *DLG190[] = { "Tony", "Beast", NULL }; -const char *DLG191[] = { "Tony", "Beast", NULL }; -const char *DLG201[] = { "Tony", NULL }; -const char *DLG210[] = { "Tony", "Mortimer", NULL }; -const char *DLG211[] = { "Tony", "Mortimer", NULL }; -const char *DLG212[] = { "Tony", "Mortimer", NULL }; -const char *DLG240[] = { "Tony", "Isabella", NULL }; -const char *DLG250[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; -const char *DLG251[] = { "Tony", "Bartender", "Sad pirate", "Anchorman", "Biff", NULL }; -const char *DLG260[] = { "Tony", "Captain", "Captain (tale)", NULL }; -const char *DLG270[] = { "Tony", "Egghead", NULL }; -const char *DLG271[] = { "Tony", "Egghead", NULL }; -const char *DLG272[] = { "Tony", "Egghead", NULL }; -const char *DLG290[] = { "Tony", "Old lady 2", NULL }; -const char *DLG310[] = { "Tony", "Wally", NULL }; -const char *DLG330[] = { "Tony", "Polly", "Captain (off scene)", NULL }; -const char *DLG340[] = { "Tony", "Randall", NULL }; -const char *DLG360[] = { "Tony", NULL }; -const char *DLG361[] = { "Tony", NULL }; -const char *DLG370[] = { "Tony", "Gatekeeper", NULL }; -const char *DLG371[] = { "Tony", "Gatekeeper", NULL }; -const char *DLG372[] = { "Tony", "Gatekeeper", NULL }; -const char *DLG373[] = { "Tony", "Gatekeeper", NULL }; -const char *DLG380[] = { "Tony", NULL }; -const char *DLG410[] = { "Tony", "Gwendel", NULL }; -const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -const char *DLG460[] = { "Tony", NULL }; -const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG480[] = { "Tony", "Pin-up", NULL }; -const char *DLG490[] = { "Tony", "Gwendel", NULL }; -const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -const char *DLG550[] = { "Tony", "Mr. Wishing Well", "Tony (from the top of the well)", NULL }; -const char *DLG560[] = { "Tony", "Superintendent", NULL }; -const char *DLG590[] = { "Tony", "Pantagruel", NULL }; -const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Storyteller", "Mr. Wishing Well", NULL }; -#endif - -#if 0 // Polish names -const char *DLG10[] = { "Tony", NULL }; -const char *DLG51[] = { "Tony", "Butch", "Dudley" }; -const char *DLG52[] = { "Tony", NULL }; -const char *DLG61[] = { "Tony", "Staruszka 1", NULL }; -const char *DLG71[] = { "Tony", "Timothy", "Skazaniec", NULL, NULL, "£ebster (przez mikrofon)", "Staruszka 1", NULL }; -const char *DLG90[] = { "Tony", "Kobieta z Brod¹", NULL }; -const char *DLG110[] = { "Tony", "Lorenz", NULL }; -const char *DLG111[] = { "Tony", "Lorenz", NULL }; -const char *DLG130[] = { "Tony", "Pirania", NULL }; -const char *DLG150[] = { "Tony", "Rufus", "Ba³wan", NULL }; -const char *DLG151[] = { "Tony", "Rufus", "Ba³wan", NULL }; -const char *DLG152[] = { "Tony", "Rufus", "Ba³wan", NULL }; -const char *DLG153[] = { "Tony", "Rufus", "Ba³wan", NULL }; -const char *DLG154[] = { "Tony", "Rufus", "Ba³wan", NULL }; -const char *DLG160[] = { "Tony", "Œmiechozol", NULL }; -const char *DLG161[] = { "Tony", "Œmiechozol", NULL }; -const char *DLG162[] = { "Tony", "Œmiechozol", NULL }; -const char *DLG163[] = { "Tony", "Œmiechozol", NULL }; -const char *DLG180[] = { "Tony", "Wycz", NULL }; -const char *DLG190[] = { "Tony", "Wycz", NULL }; -const char *DLG191[] = { "Tony", "Wycz", NULL }; -const char *DLG201[] = { "Tony", NULL }; -const char *DLG210[] = { "Tony", "Mortimer (Okropny)", NULL }; -const char *DLG211[] = { "Tony", "Mortimer (Okropny)", NULL }; -const char *DLG212[] = { "Tony", "Mortimer (Okropny)", NULL }; -const char *DLG240[] = { "Tony", "Isabella", NULL }; -const char *DLG250[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; -const char *DLG251[] = { "Tony", "Barman", "Smutny Pirat", "Wodzirej", "Biff", NULL }; -const char *DLG260[] = { "Tony", "Kapitan", "Captain (opowieœæ)", NULL }; -const char *DLG270[] = { "Tony", "Jajog³owy", NULL }; -const char *DLG271[] = { "Tony", "Jajog³owy", NULL }; -const char *DLG272[] = { "Tony", "Jajog³owy", NULL }; -const char *DLG290[] = { "Tony", "Staruszka 2", NULL }; -const char *DLG310[] = { "Tony", "Wally", NULL }; -const char *DLG330[] = { "Tony", "Polly", "Kapitan (zza sceny)", NULL }; -const char *DLG340[] = { "Tony", "Randall", NULL }; -const char *DLG360[] = { "Tony", NULL }; -const char *DLG361[] = { "Tony", NULL }; -const char *DLG370[] = { "Tony", "Stra¿nik", NULL }; -const char *DLG371[] = { "Tony", "Stra¿nik", NULL }; -const char *DLG372[] = { "Tony", "Stra¿nik", NULL }; -const char *DLG373[] = { "Tony", "Stra¿nik", NULL }; -const char *DLG380[] = { "Tony", NULL }; -const char *DLG410[] = { "Tony", "Gwendel", NULL }; -const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Gospodyni (zza sceny)", NULL }; -const char *DLG460[] = { "Tony", NULL }; -const char *DLG470[] = { "Tony", "Gospodyni", "Mirror", NULL }; -const char *DLG471[] = { "Tony", "Gospodyni", "Mirror", NULL }; -const char *DLG472[] = { "Tony", "Gospodyni", "Mirror", NULL }; -const char *DLG473[] = { "Tony", "Gospodyni", "Mirror", NULL }; -const char *DLG474[] = { "Tony", "Gospodyni", "Mirror", NULL }; -const char *DLG480[] = { "Tony", "Pin-up", NULL }; -const char *DLG490[] = { "Tony", "Gwendel", NULL }; -const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -const char *DLG550[] = { "Tony", "Pan Studnia ¯yczeñ", "Tony (nad studni¹)", NULL }; -const char *DLG560[] = { "Tony", "Inspektor", NULL }; -const char *DLG590[] = { "Tony", "Pantaloniarz", NULL }; -const char *DLG600[] = { "Tony", "£ebster", "£ebster", NULL, "£ebster", NULL, NULL, NULL, "Narrator", "Pan Studnia ¯yczeñ", NULL }; -#endif // Polish - - -#if 0 // Russian -const char *DLG10[] = { "Òîíè", NULL }; -const char *DLG51[] = { "Òîíè", "Áó÷", "Äàäëè" }; -const char *DLG52[] = { "Òîíè", NULL }; -const char *DLG61[] = { "Òîíè", "Ñòàðóøêà 1", NULL }; -const char *DLG71[] = { "Òîíè", "Òèìîòè", "Îñóæäåííûé", NULL, NULL, "Äæåê (ñ ìèêðîôîíîì)", "Ñòàðóøêà 1", NULL }; -const char *DLG90[] = { "Òîíè", "Áîðîäàòàÿ æåíùèíà", NULL }; -const char *DLG110[] = { "Òîíè", "Ëîðåíö", NULL }; -const char *DLG111[] = { "Òîíè", "Ëîðåíö", NULL }; -const char *DLG130[] = { "Òîíè", "Ïèðàíüÿ", NULL }; -const char *DLG150[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -const char *DLG151[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -const char *DLG152[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -const char *DLG153[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -const char *DLG154[] = { "Òîíè", "Ðóôóñ", "Ñíåãîâèê", NULL }; -const char *DLG160[] = { "Òîíè", "Øìàéëè", NULL }; -const char *DLG161[] = { "Òîíè", "Øìàéëè", NULL }; -const char *DLG162[] = { "Òîíè", "Øìàéëè", NULL }; -const char *DLG163[] = { "Òîíè", "Øìàéëè", NULL }; -const char *DLG180[] = { "Òîíè", "×óäîâèùå", NULL }; -const char *DLG190[] = { "Òîíè", "×óäîâèùå", NULL }; -const char *DLG191[] = { "Òîíè", "×óäîâèùå", NULL }; -const char *DLG201[] = { "Òîíè", NULL }; -const char *DLG210[] = { "Òîíè", "Ìîðòèìåð", NULL }; -const char *DLG211[] = { "Òîíè", "Ìîðòèìåð", NULL }; -const char *DLG212[] = { "Òîíè", "Ìîðòèìåð", NULL }; -const char *DLG240[] = { "Òîíè", "Èçàáåëëà", NULL }; -const char *DLG250[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; -const char *DLG251[] = { "Òîíè", "Áàðìåí", "Ãðóñòíûé ïèðàò", "Âåäóùèé", "Áèôô", NULL }; -const char *DLG260[] = { "Òîíè", "Êàïèòàí", "Êàïèòàí (ðàññêàç)", NULL }; -const char *DLG270[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -const char *DLG271[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -const char *DLG272[] = { "Òîíè", "ßéöåãîëîâûé", NULL }; -const char *DLG290[] = { "Òîíè", "Ñòàðóøêà 2", NULL }; -const char *DLG310[] = { "Òîíè", "Óîëëè", NULL }; -const char *DLG330[] = { "Òîíè", "Ïîëëè", "Êàïèòàí (çà ñöåíîé)", NULL }; -const char *DLG340[] = { "Òîíè", "Ðýíäàë", NULL }; -const char *DLG360[] = { "Òîíè", NULL }; -const char *DLG361[] = { "Òîíè", NULL }; -const char *DLG370[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -const char *DLG371[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -const char *DLG372[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -const char *DLG373[] = { "Òîíè", "Ïðèâðàòíèê", NULL }; -const char *DLG380[] = { "Òîíè", NULL }; -const char *DLG410[] = { "Òîíè", "Ãâåíäåëü", NULL }; -const char *DLG430[] = { "Òîíè", "Ãàðîëüä", "×àê", "Pigeons", "Housekeeper (off scene)", NULL }; -const char *DLG460[] = { "Òîíè", NULL }; -const char *DLG470[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -const char *DLG471[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -const char *DLG472[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -const char *DLG473[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -const char *DLG474[] = { "Òîíè", "Housekeeper", "Mirror", NULL }; -const char *DLG480[] = { "Òîíè", "Pin-up", NULL }; -const char *DLG490[] = { "Òîíè", "Ãâåíäåëü", NULL }; -const char *DLG530[] = { "Òîíè", "Ãàðîëüä", "×àê", NULL }; -const char *DLG550[] = { "Òîíè", "Ãîñïîäèí Êîëîäåö æåëàíèé", "Òîíè (ñ âåðøèíû êîëîäöà)", NULL }; -const char *DLG560[] = { "Òîíè", "Íà÷àëüíèê îõðàíû", NULL }; -const char *DLG590[] = { "Òîíè", "Ïàíòàãðþýëü", NULL }; -const char *DLG600[] = { "Òîíè", "Äæåê", "Äæåê", NULL, "Äæåê", NULL, NULL, NULL, "Ðàññêàç÷èê", "Ãîñïîäèí Êîëîäåö æåëàíèé", NULL }; -#endif // Russian - - -#if 0 // Czech names -const char *DLG10[] = { "Tony", NULL }; -const char *DLG51[] = { "Tony", "Butch", "Dudley" }; -const char *DLG52[] = { "Tony", NULL }; -const char *DLG61[] = { "Tony", "Stará paní 1", NULL }; -const char *DLG71[] = { "Tony", "Timothy", "Trestanec", NULL, NULL, "Jack (s mikrofonem)", "Stará paní 1", NULL }; -const char *DLG90[] = { "Tony", "Vousatá žena", NULL }; -const char *DLG110[] = { "Tony", "Lorenz", NULL }; -const char *DLG111[] = { "Tony", "Lorenz", NULL }; -const char *DLG130[] = { "Tony", "Piraòa", NULL }; -const char *DLG150[] = { "Tony", "Rufus", "Snìhulák", NULL }; -const char *DLG151[] = { "Tony", "Rufus", "Snìhulák", NULL }; -const char *DLG152[] = { "Tony", "Rufus", "Snìhulák", NULL }; -const char *DLG153[] = { "Tony", "Rufus", "Snìhulák", NULL }; -const char *DLG154[] = { "Tony", "Rufus", "Snìhulák", NULL }; -const char *DLG160[] = { "Tony", "Shmiley", NULL }; -const char *DLG161[] = { "Tony", "Shmiley", NULL }; -const char *DLG162[] = { "Tony", "Shmiley", NULL }; -const char *DLG163[] = { "Tony", "Shmiley", NULL }; -const char *DLG180[] = { "Tony", "Zvíøe", NULL }; -const char *DLG190[] = { "Tony", "Zvíøe", NULL }; -const char *DLG191[] = { "Tony", "Zvíøe", NULL }; -const char *DLG201[] = { "Tony", NULL }; -const char *DLG210[] = { "Tony", "Mortimer", NULL }; -const char *DLG211[] = { "Tony", "Mortimer", NULL }; -const char *DLG212[] = { "Tony", "Mortimer", NULL }; -const char *DLG240[] = { "Tony", "Isabella", NULL }; -const char *DLG250[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; -const char *DLG251[] = { "Tony", "Barman", "Smutný pirát", "Moderátor", "Biff", NULL }; -const char *DLG260[] = { "Tony", "Kapitán", "Kapitán (pøíbìh)", NULL }; -const char *DLG270[] = { "Tony", "Intelektuál", NULL }; -const char *DLG271[] = { "Tony", "Intelektuál", NULL }; -const char *DLG272[] = { "Tony", "Intelektuál", NULL }; -const char *DLG290[] = { "Tony", "Stará paní 2", NULL }; -const char *DLG310[] = { "Tony", "Wally", NULL }; -const char *DLG330[] = { "Tony", "Lóra", "Kapitán (mimo scénu)", NULL }; -const char *DLG340[] = { "Tony", "Randall", NULL }; -const char *DLG360[] = { "Tony", NULL }; -const char *DLG361[] = { "Tony", NULL }; -const char *DLG370[] = { "Tony", "Strážný", NULL }; -const char *DLG371[] = { "Tony", "Strážný", NULL }; -const char *DLG372[] = { "Tony", "Strážný", NULL }; -const char *DLG373[] = { "Tony", "Strážný", NULL }; -const char *DLG380[] = { "Tony", NULL }; -const char *DLG410[] = { "Tony", "Gwendel", NULL }; -const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -const char *DLG460[] = { "Tony", NULL }; -const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG480[] = { "Tony", "Pin-up", NULL }; -const char *DLG490[] = { "Tony", "Gwendel", NULL }; -const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -const char *DLG550[] = { "Tony", "Pan Studna pøání", "Tony (z vrcholu studny)", NULL }; -const char *DLG560[] = { "Tony", "Správce", NULL }; -const char *DLG590[] = { "Tony", "Pantagruel", NULL }; -const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Vypravìè", "Pan Studna pøání", NULL }; -#endif // Czech names - -#if 1 // Deutsch names -const char *DLG10[] = { "Tony", NULL }; -const char *DLG51[] = { "Tony", "Butch", "Dudley" }; -const char *DLG52[] = { "Tony", NULL }; -const char *DLG61[] = { "Tony", "Alte Dame 1", NULL }; -const char *DLG71[] = { "Tony", "Timothy", "Sträfling", NULL, NULL, "Jack (mit Mikrofon)", "Alte Dame 1", NULL }; -const char *DLG90[] = { "Tony", "Bärtige Dame", NULL }; -const char *DLG110[] = { "Tony", "Lorenz", NULL }; -const char *DLG111[] = { "Tony", "Lorenz", NULL }; -const char *DLG130[] = { "Tony", "Piranha", NULL }; -const char *DLG150[] = { "Tony", "Rufus", "Schneemann", NULL }; -const char *DLG151[] = { "Tony", "Rufus", "Schneemann", NULL }; -const char *DLG152[] = { "Tony", "Rufus", "Schneemann", NULL }; -const char *DLG153[] = { "Tony", "Rufus", "Schneemann", NULL }; -const char *DLG154[] = { "Tony", "Rufus", "Schneemann", NULL }; -const char *DLG160[] = { "Tony", "Shmiley", NULL }; -const char *DLG161[] = { "Tony", "Shmiley", NULL }; -const char *DLG162[] = { "Tony", "Shmiley", NULL }; -const char *DLG163[] = { "Tony", "Shmiley", NULL }; -const char *DLG180[] = { "Tony", "Biest", NULL }; -const char *DLG190[] = { "Tony", "Biest", NULL }; -const char *DLG191[] = { "Tony", "Biest", NULL }; -const char *DLG201[] = { "Tony", NULL }; -const char *DLG210[] = { "Tony", "Mortimer", NULL }; -const char *DLG211[] = { "Tony", "Mortimer", NULL }; -const char *DLG212[] = { "Tony", "Mortimer", NULL }; -const char *DLG240[] = { "Tony", "Isabella", NULL }; -const char *DLG250[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; -const char *DLG251[] = { "Tony", "Barmann", "Trauriger Pirat", "Chefanimateur", "Biff", NULL }; -const char *DLG260[] = { "Tony", "Kapitän", "Kapitän (Erzählung)", NULL }; -const char *DLG270[] = { "Tony", "Eierkopf", NULL }; -const char *DLG271[] = { "Tony", "Eierkopf", NULL }; -const char *DLG272[] = { "Tony", "Eierkopf", NULL }; -const char *DLG290[] = { "Tony", "Alte Dame 2", NULL }; -const char *DLG310[] = { "Tony", "Wally", NULL }; -const char *DLG330[] = { "Tony", "Polly", "Kapitän (im Off)", NULL }; -const char *DLG340[] = { "Tony", "Randall", NULL }; -const char *DLG360[] = { "Tony", NULL }; -const char *DLG361[] = { "Tony", NULL }; -const char *DLG370[] = { "Tony", "Pförtner", NULL }; -const char *DLG371[] = { "Tony", "Pförtner", NULL }; -const char *DLG372[] = { "Tony", "Pförtner", NULL }; -const char *DLG373[] = { "Tony", "Pförtner", NULL }; -const char *DLG380[] = { "Tony", NULL }; -const char *DLG410[] = { "Tony", "Gwendel", NULL }; -const char *DLG430[] = { "Tony", "Harold", "Chuck", "Pigeons", "Housekeeper (off scene)", NULL }; -const char *DLG460[] = { "Tony", NULL }; -const char *DLG470[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG471[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG472[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG473[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG474[] = { "Tony", "Housekeeper", "Mirror", NULL }; -const char *DLG480[] = { "Tony", "Pin-up", NULL }; -const char *DLG490[] = { "Tony", "Gwendel", NULL }; -const char *DLG530[] = { "Tony", "Harold", "Chuck", NULL }; -const char *DLG550[] = { "Tony", "Herr Wunschbrunnen", "Tony (über dem Brunnen)", NULL }; -const char *DLG560[] = { "Tony", "Verwalter", NULL }; -const char *DLG590[] = { "Tony", "Pantagruel", NULL }; -const char *DLG600[] = { "Tony", "Jack", "Jack", NULL, "Jack", NULL, NULL, NULL, "Erzähler", "Herr Wunschbrunnen", NULL }; -#endif - - -#define HANDLE_DIALOG(num) \ -case num: \ - if (nPers >= (int)(sizeof(DLG##num) / sizeof(const char *)) || DLG##num[nPers] == NULL) \ - { \ - warning("ERROR: The character #%d does not exist in dialog %d!\n", nPers, nDlg); \ - return "ERROR"; \ - } \ - else \ - return DLG##num[nPers]; - - -const char *getPersonName(uint16 nDlg, int nPers) { - switch (nDlg) { - HANDLE_DIALOG(10); - HANDLE_DIALOG(51); - HANDLE_DIALOG(52); - HANDLE_DIALOG(61); - HANDLE_DIALOG(71); - HANDLE_DIALOG(90); - HANDLE_DIALOG(110); - HANDLE_DIALOG(111); - HANDLE_DIALOG(130); - HANDLE_DIALOG(150); - HANDLE_DIALOG(151); - HANDLE_DIALOG(152); - HANDLE_DIALOG(153); - HANDLE_DIALOG(154); - HANDLE_DIALOG(160); - HANDLE_DIALOG(161); - HANDLE_DIALOG(162); - HANDLE_DIALOG(163); - HANDLE_DIALOG(180); - HANDLE_DIALOG(190); - HANDLE_DIALOG(191); - HANDLE_DIALOG(201); - HANDLE_DIALOG(210); - HANDLE_DIALOG(211); - HANDLE_DIALOG(212); - HANDLE_DIALOG(240); - HANDLE_DIALOG(250); - HANDLE_DIALOG(251); - HANDLE_DIALOG(260); - HANDLE_DIALOG(270); - HANDLE_DIALOG(271); - HANDLE_DIALOG(272); - HANDLE_DIALOG(290); - HANDLE_DIALOG(310); - HANDLE_DIALOG(330); - HANDLE_DIALOG(340); - HANDLE_DIALOG(360); - HANDLE_DIALOG(361); - HANDLE_DIALOG(370); - HANDLE_DIALOG(371); - HANDLE_DIALOG(372); - HANDLE_DIALOG(373); - HANDLE_DIALOG(380); - HANDLE_DIALOG(410); - HANDLE_DIALOG(430); - HANDLE_DIALOG(460); - HANDLE_DIALOG(470); - HANDLE_DIALOG(471); - HANDLE_DIALOG(472); - HANDLE_DIALOG(473); - HANDLE_DIALOG(474); - HANDLE_DIALOG(480); - HANDLE_DIALOG(490); - HANDLE_DIALOG(530); - HANDLE_DIALOG(550); - HANDLE_DIALOG(560); - HANDLE_DIALOG(590); - HANDLE_DIALOG(600); - - default: - warning("ERROR: Dialog %d does not exist!", (int)nDlg); - return "ERROR"; - } -} - -void mpalDumpDialog(LPMPALDIALOG dlg) { - char dfn[64]; - char fname[64]; - int g,c,j; - struct command* curCmd; - char *frase; char *p; - char copia[2048]; - bool bAtLeastOne; - Common::OutSaveFile *f, *v1; - - v1 = g_system->getSavefileManager()->openForSaving("voicelist.txt"); - - sprintf(dfn,"DIALOG%03d.HTM", dlg->nObj); - warning("Dumping %s...\n", dfn); - - f = g_system->getSavefileManager()->openForSaving(dfn); - - f->writeString("\n\n"); - - for (g = 0; dlg->_group[g].num != 0; g++) { - bAtLeastOne = false; - - for (c = 0; c_group[g].nCmds; c++) { - curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; - if (curCmd->type == 1 && curCmd->_nCf == 71) { - bAtLeastOne = true; - break; - } - } - - if (!bAtLeastOne) - continue; - - f->writeString(Common::String::format("

\n

Group %d

\n

\n", g)); - f->writeString("\n"); - - for (c = 0; c < dlg->_group[g].nCmds; c++) { - curCmd = &dlg->_command[dlg->_group[g].CmdNum[c]]; - - // If it's a custom function, call SendDialogMessage(nPers, nMsg) - if (curCmd->type == 1 && curCmd->_nCf == 71) { - sprintf(fname, "%03d-%05d.WAV", dlg->nObj, curCmd->_arg2); - - for (j = 0; dlg->_periods[j] != NULL; j++) - if (dlg->_periodNums[j] == curCmd->_arg2) - break; - - if (dlg->_periods[j] == NULL) - warning("ERROR: Dialog %d, Period %d not found!", (int)dlg->nObj, (int)curCmd->_arg2); - else { - frase = (char *)globalLock(dlg->_periods[j]); - strcpy(copia, frase); - globalUnlock(dlg->_periods[j]); - - while ((p = strchr(copia,'^')) != NULL) - *p = '\"'; - - p = frase; - while (*p == ' ') - p++; - if (*p == '\0') - continue; - - v1->writeString(Common::String::format("%s\n", fname)); - f->writeString("\t\n"); - f->writeString(Common::String::format("\t\t\n", fname)); - f->writeString(Common::String::format("\t\t\n", - getPersonName(dlg->nObj, curCmd->_arg1))); - f->writeString(Common::String::format("\t\t\n",copia)); - f->writeString("\t\n"); - //fprintf(f, "(%s) <%s> %s\n", fname, GetPersonName(dlg->nObj, curCmd->arg1), copia); - } - } - } - - f->writeString("
%s %s %s

\n"); - //fprintf(f,"\n\n\n\n"); - } - - f->finalize(); - v1->finalize(); - delete f; - delete v1; -} - -void mpalDumpDialogs() { - int i; - - lockDialogs(); - - for (i = 0; i < GLOBALS._nDialogs; i++) - mpalDumpDialog(&GLOBALS._lpmdDialogs[i]); - - unlockDialogs(); -} - } // end of namespace MPAL } // end of namespace Tony -- cgit v1.2.3 From 35fd91793b34b72624a89f2a76f45bc8e59020d2 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Tue, 28 Aug 2012 14:26:00 +0200 Subject: TONY: Get rid of RMDataStream. --- engines/tony/mpal/mpalutils.cpp | 5 +++++ engines/tony/mpal/mpalutils.h | 6 ++++++ 2 files changed, 11 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index aa22456a4b..bfc97a5f3d 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -23,6 +23,7 @@ #include "tony/mpal/mpalutils.h" #include "tony/tony.h" +#include "common/memstream.h" namespace Tony { @@ -75,6 +76,10 @@ unsigned int RMRes::size() { return globalSize(_h); } +Common::SeekableReadStream *RMRes::getReadStream() { + return new Common::MemoryReadStream(_buf, size()); +} + /****************************************************************************\ * RMResRaw methods \****************************************************************************/ diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index 19810cf3a1..19e4fa7778 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -27,6 +27,10 @@ #include "common/scummsys.h" #include "tony/mpal/memory.h" +namespace Common { + class SeekableReadStream; +} + namespace Tony { namespace MPAL { @@ -47,6 +51,8 @@ public: // Casting for access to data operator const byte*(); + + Common::SeekableReadStream *getReadStream(); }; class RMResRaw : public RMRes { -- cgit v1.2.3 From cdeecf1521e95a8ad250bc18a398b32fd2886c36 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 28 Aug 2012 22:47:10 +0200 Subject: TONY: Replace overlapping memcpy with memmove --- engines/tony/mpal/expr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index eb6b485ef6..772d3da075 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -191,7 +191,7 @@ static void solve(LPEXPRESSION one, int num) { two = one + 1; if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { two->val.num = Compute(one->val.num, two->val.num, one->symbol); - memcpy(one, two, (num - 1) * sizeof(EXPRESSION)); + memmove(one, two, (num - 1) * sizeof(EXPRESSION)); --num; } else { j = 1; @@ -203,7 +203,7 @@ static void solve(LPEXPRESSION one, int num) { } three->val.num = Compute(two->val.num, three->val.num, two->symbol); - memcpy(two, three, (num - j - 1) * sizeof(EXPRESSION)); + memmove(two, three, (num - j - 1) * sizeof(EXPRESSION)); --num; } } -- cgit v1.2.3 From 56f4bc0225653be13813c662115b67152e78cf1a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 28 Aug 2012 23:05:48 +0200 Subject: TONY: Fix some for and if statements with bad coding style --- engines/tony/mpal/loadmpc.cpp | 3 +- engines/tony/mpal/mpal.cpp | 70 ++++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 25 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index ed4ad9d228..2d2f8ecd00 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -628,9 +628,10 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0;i < GLOBALS._nDialogs; i++) + for (i = 0;i < GLOBALS._nDialogs; i++) { if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS._lpmdDialogs[i])) == NULL) return false; + } globalUnlock(GLOBALS._hDialogs); } diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 16d8a3213b..721552b80c 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -224,9 +224,10 @@ static int msgGetOrderFromNum(uint32 nMsg) { int i; LPMPALMSG msg = GLOBALS._lpmmMsgs; - for (i = 0; i < GLOBALS._nMsgs; i++, msg++) + for (i = 0; i < GLOBALS._nMsgs; i++, msg++) { if (msg->_wNum == nMsg) return i; + } return -1; } @@ -242,9 +243,10 @@ static int itemGetOrderFromNum(uint32 nItem) { int i; LPMPALITEM item = GLOBALS._lpmiItems; - for (i = 0; i < GLOBALS._nItems; i++, item++) + for (i = 0; i < GLOBALS._nItems; i++, item++) { if (item->nObj == nItem) return i; + } return -1; } @@ -261,9 +263,10 @@ static int scriptGetOrderFromNum(uint32 nScript) { int i; LPMPALSCRIPT script = GLOBALS._lpmsScripts; - for (i = 0; i < GLOBALS._nScripts; i++, script++) + for (i = 0; i < GLOBALS._nScripts; i++, script++) { if (script->nObj == nScript) return i; + } return -1; } @@ -280,9 +283,10 @@ static int dialogGetOrderFromNum(uint32 nDialog) { int i; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs; - for (i = 0; i < GLOBALS._nDialogs; i++, dialog++) + for (i = 0; i < GLOBALS._nDialogs; i++, dialog++) { if (dialog->nObj == nDialog) return i; + } return -1; } @@ -333,14 +337,15 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; int i, j; - for (j = 0; dialog->_periods[j] != NULL; j++) + for (j = 0; dialog->_periods[j] != NULL; j++) { if (dialog->_periodNums[j] == nPeriod) { /* Found the phrase, it should be duplicated */ origmsg = (const char *)globalLock(dialog->_periods[j]); /* Calculate the length and allocate memory */ i = 0; - while (origmsg[i] != '\0') i++; + while (origmsg[i] != '\0') + i++; clonemsg = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, i + 1); if (clonemsg == NULL) @@ -352,7 +357,8 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { return clonemsg; } - + } + return NULL; } @@ -415,9 +421,10 @@ static uint32 *getSelectList(uint32 i) { /* Count how many are active selects */ num = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) num++; + } /* If there are 0, it's a mistake */ if (num == 0) @@ -429,9 +436,10 @@ static uint32 *getSelectList(uint32 i) { /* Copy all the data inside the active select list */ k = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) sl[k++] = dialog->_choice[i]._select[j].dwData; + } sl[k] = (uint32)NULL; return sl; @@ -690,7 +698,8 @@ void ActionThread(CORO_PARAM, const void *param) { LPMPALITEM item; ~CoroContextTag() { - if (item) globalDestroy(item); + if (item) + globalDestroy(item); } CORO_END_CONTEXT(_ctx); @@ -844,14 +853,16 @@ void LocationPollThread(CORO_PARAM, const void *param) { for (_ctx->i = 0; _ctx->i < _ctx->numitems; _ctx->i++) { _ctx->ord = itemGetOrderFromNum(_ctx->il[_ctx->i]); - if (_ctx->ord == -1) continue; + if (_ctx->ord == -1) + continue; _ctx->curItem = GLOBALS._lpmiItems + _ctx->ord; _ctx->k = 0; - for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) + for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) { if (_ctx->curItem->Action[_ctx->j].num == 0xFF) _ctx->k++; + } _ctx->nIdleActions += _ctx->k; @@ -928,12 +939,13 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->curTime = g_vm->getTime(); _ctx->dwSleepTime = (uint32)-1L; - for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) + for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) { if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { _ctx->dwSleepTime = 0; break; - } else + } else _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); + } /* We fall alseep, but always checking that the event is set when prompted for closure */ CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS._hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); @@ -942,7 +954,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (!_ctx->expired) break; - for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem != 0) { CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); @@ -950,11 +962,12 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (!_ctx->delayExpired) _ctx->MyThreads[_ctx->i].nItem = 0; } + } _ctx->curTime = g_vm->getTime(); /* Loop through all the necessary idle actions */ - for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) + for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) { if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; @@ -966,9 +979,10 @@ void LocationPollThread(CORO_PARAM, const void *param) { continue; /* Check to see if there already another idle funning running on the item */ - for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem == _ctx->MyActions[_ctx->k].nItem) break; + } if (_ctx->i < _ctx->nRealItems) continue; @@ -979,11 +993,12 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Check if there is a WhenExecute expression */ _ctx->j=_ctx->MyActions[_ctx->k].nAction; - if (_ctx->curItem->Action[_ctx->j].when != NULL) + if (_ctx->curItem->Action[_ctx->j].when != NULL) { if (!evaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { unlockItems(); continue; } + } /* Ok, we can perform the action. For convenience, we do it in a new process */ _ctx->newItem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); @@ -1004,9 +1019,10 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->newItem->dwRes=_ctx->j; /* We will create an action, and will provide the necessary details */ - for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem == 0) break; + } _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; @@ -1024,13 +1040,14 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Skip all idle actions of the same item */ } } + } } // Set idle skip on CORO_INVOKE_4(GLOBALS._lplpFunctions[200], 0, 0, 0, 0); - for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) + for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem != 0) { CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); @@ -1041,6 +1058,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { */ CoroScheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); } + } // Set idle skip off CORO_INVOKE_4(GLOBALS._lplpFunctions[201], 0, 0, 0, 0); @@ -1178,9 +1196,10 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; /* Search the choice between those required in the dialog */ - for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) + for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) { if (_ctx->dialog->_choice[_ctx->i].nChoice == nChoice) break; + } /* If nothing has been found, exit with an error */ if (_ctx->dialog->_choice[_ctx->i].nChoice == 0) { @@ -1200,7 +1219,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->k = 0; /* Calculate the expression of each selection, to see if they're active or inactive */ - for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].dwData != 0; _ctx->j++) + for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].dwData != 0; _ctx->j++) { if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when == NULL) { _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; _ctx->k++; @@ -1209,6 +1228,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->k++; } else _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 0; + } /* If there are no choices activated, then the dialog is finished. */ if (_ctx->k == 0) { @@ -1373,9 +1393,10 @@ bool doSelection(uint32 i, uint32 dwData) { LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; int j; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) + for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].dwData == dwData && dialog->_choice[i]._select[j].curActive != 0) break; + } if (dialog->_choice[i]._select[j].dwData == 0) return false; @@ -2020,9 +2041,10 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { bool mpalStartIdlePoll(int nLoc) { uint32 i; - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) + for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == (uint32)nLoc) return false; + } for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == 0) { -- cgit v1.2.3 From d2b33ca4cce2794e7b4fcf3ccb3f00dc74fff68d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 28 Aug 2012 23:25:50 +0200 Subject: TONY: Janitorial - remove trailing spaces --- engines/tony/mpal/expr.cpp | 16 +++++----- engines/tony/mpal/expr.h | 2 +- engines/tony/mpal/loadmpc.cpp | 8 ++--- engines/tony/mpal/loadmpc.h | 2 +- engines/tony/mpal/mpal.cpp | 70 +++++++++++++++++++++---------------------- engines/tony/mpal/mpal.h | 44 +++++++++++++-------------- engines/tony/mpal/mpaldll.h | 2 +- 7 files changed, 72 insertions(+), 72 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 772d3da075..ef58208d3f 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -88,7 +88,7 @@ typedef struct { byte type; // Tipo di oggetto (vedi enum ExprListTypes) byte unary; // Unary operatore (NON SUPPORTATO) - union { + union { int num; // Numero (se type==ELT_NUMBER) char *name; // Nome variabile (se type==ELT_VAR) HGLOBAL son; // Handle a espressione (type==ELT_PARENTH) @@ -179,7 +179,7 @@ static int Compute(int a, int b, byte symbol) { GLOBALS._mpalError = 1; break; } - + return 0; } @@ -211,7 +211,7 @@ static void solve(LPEXPRESSION one, int num) { /** - * Calculates the result of a mathematical expression, replacing the current + * Calculates the result of a mathematical expression, replacing the current * value of any variable. * * @param expr Pointer to an expression duplicated by DuplicateExpression @@ -253,7 +253,7 @@ static int evaluateAndFreeExpression(byte *expr) { * Parses a mathematical expression from the MPC file * * @param buf Buffer containing the expression to evaluate - * @param h Pointer to a handle that, at the end of execution, + * @param h Pointer to a handle that, at the end of execution, * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ @@ -377,7 +377,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { return false; } break; - + case ELT_VAR: if (strcmp(one->val.name, two->val.name) != 0) { globalUnlock(h1); @@ -385,7 +385,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { return false; } break; - + case ELT_PARENTH: if (!compareExpressions(one->val.son, two->val.son)) { globalUnlock(h1); @@ -395,13 +395,13 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { break; } - ++one; + ++one; ++two; } globalUnlock(h1); globalUnlock(h2); - + return true; } diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 3130539000..f9c8a7c48f 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -43,7 +43,7 @@ namespace MPAL { * Parses a mathematical expression from the MPC file * * @param buf Buffer containing the expression to evaluate - * @param h Pointer to a handle that, at the end of execution, + * @param h Pointer to a handle that, at the end of execution, * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 2d2f8ecd00..9da2cc121e 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -157,7 +157,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { /* Periodi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; - + if (num >= MAX_PERIODS_PER_DIALOG - 1) error("Too much periods in dialog #%d", lpmdDialog->nObj); @@ -252,7 +252,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { } } - if (kk == curCmd) { + if (kk == curCmd) { lpmdDialog->_group[i].CmdNum[j] = curCmd; curCmd++; } @@ -445,7 +445,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { } } - if (kk == curCmd) { + if (kk == curCmd) { lpmiItem->Action[i].CmdNum[j] = curCmd; curCmd++; @@ -520,7 +520,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) //@{ /** - * Reads and interprets the MPC file, and create structures for various directives + * Reads and interprets the MPC file, and create structures for various directives * in the global variables * * @param lpBuf Buffer containing the MPC file data, excluding the header. diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index b805b1e7a1..c0e2ca7fb5 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -38,7 +38,7 @@ namespace MPAL { \****************************************************************************/ /** - * Reads and interprets the MPC file, and create structures for various directives + * Reads and interprets the MPC file, and create structures for various directives * in the global variables * * @param lpBuf Buffer containing the MPC file data, excluding the header. diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 721552b80c..be2f6db43f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -31,7 +31,7 @@ #include "common/savefile.h" #include "common/system.h" #include "tony/tony.h" -#include "tony/mpal/lzo.h" +#include "tony/mpal/lzo.h" #include "tony/mpal/mpal.h" #include "tony/mpal/mpaldll.h" @@ -358,7 +358,7 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { return clonemsg; } } - + return NULL; } @@ -551,7 +551,7 @@ static LPITEM getItemData(uint32 nOrdItem) { dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * (uint32)(ret->_frameslocations[i].bottom - ret->_frameslocations[i].top); ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); - + if (ret->_frames[i] == NULL) return NULL; memcpy(ret->_frames[i], dat, dim); @@ -570,7 +570,7 @@ static LPITEM getItemData(uint32 nOrdItem) { } -/** +/** * Thread that calls a custom function. It is used in scripts, so that each script * function is executed without delaying the others. * @@ -685,7 +685,7 @@ void ScriptThread(CORO_PARAM, const void *param) { /** - * Thread that performs an action on an item. the thread always executes the action, + * Thread that performs an action on an item. the thread always executes the action, * so it should create a new item in which the action is the one required. * Furthermore, the expression is not checked, but it is always performed the action. * @@ -745,7 +745,7 @@ void ActionThread(CORO_PARAM, const void *param) { globalDestroy(_ctx->item); _ctx->item = NULL; - + debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d ended", CoroScheduler.getCurrentPID()); CORO_END_CODE; @@ -855,7 +855,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->ord == -1) continue; - + _ctx->curItem = GLOBALS._lpmiItems + _ctx->ord; _ctx->k = 0; @@ -1005,7 +1005,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->newItem == false) { globalDestroy(_ctx->MyThreads); globalDestroy(_ctx->MyActions); - + CORO_KILL_SELF(); return; } @@ -1032,7 +1032,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { globalDestroy(_ctx->newItem); globalDestroy(_ctx->MyThreads); globalDestroy(_ctx->MyActions); - + CORO_KILL_SELF(); return; } @@ -1068,10 +1068,10 @@ void LocationPollThread(CORO_PARAM, const void *param) { /** - * Wait for the end of the dialog execution thread, and then restore global + * Wait for the end of the dialog execution thread, and then restore global * variables indicating that the dialogue has finished. * - * @param param Pointer to a handle to the dialog + * @param param Pointer to a handle to the dialog * @remarks This additional process is used, instead of clearing variables * within the same dialog thread, because due to the recursive nature of a dialog, * it would be difficult to know within it when the dialog is actually ending. @@ -1132,9 +1132,9 @@ void GroupThread(CORO_PARAM, const void *param) { if (_ctx->type == 1) { // Call custom function CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->dialog->_command[_ctx->k]._nCf], - _ctx->dialog->_command[_ctx->k]._arg1, + _ctx->dialog->_command[_ctx->k]._arg1, _ctx->dialog->_command[_ctx->k]._arg2, - _ctx->dialog->_command[_ctx->k]._arg3, + _ctx->dialog->_command[_ctx->k]._arg3, _ctx->dialog->_command[_ctx->k]._arg4 ); @@ -1143,22 +1143,22 @@ void GroupThread(CORO_PARAM, const void *param) { lockVar(); varSetValue(_ctx->dialog->_command[_ctx->k].lpszVarName, evaluateExpression(_ctx->dialog->_command[_ctx->k].expr)); unlockVar(); - + } else if (_ctx->type == 3) { // DoChoice: call the chosen function CORO_INVOKE_1(doChoice, (uint32)_ctx->dialog->_command[_ctx->k].nChoice); - + } else { GLOBALS._mpalError = 1; unlockDialogs(); - + CORO_KILL_SELF(); return; } } /* The gruop is finished, so we can return to the calling function. - * If the group was the first called, then the process will automatically + * If the group was the first called, then the process will automatically * end. Otherwise it returns to the caller method */ return; @@ -1168,7 +1168,7 @@ void GroupThread(CORO_PARAM, const void *param) { /* If we are here, it means that we have not found the requested group */ GLOBALS._mpalError = 1; unlockDialogs(); - + CORO_KILL_SELF(); CORO_END_CODE; @@ -1259,7 +1259,7 @@ void doChoice(CORO_PARAM, uint32 nChoice) { if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 1)) { /* Bit 1 set: the end of the dialog */ unlockDialogs(); - + CORO_KILL_SELF(); return; } @@ -1348,8 +1348,8 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * @param nGroup Number of the group to perform * @returns The process Id of the process running the dialog * or CORO_INVALID_PID_VALUE on error - * @remarks The dialogue runs in a thread created on purpose, - * so that must inform through an event and when 'necessary to you make a choice. + * @remarks The dialogue runs in a thread created on purpose, + * so that must inform through an event and when 'necessary to you make a choice. * The data on the choices may be obtained through various queries. */ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { @@ -1382,7 +1382,7 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { /** - * Takes note of the selection chosen by the user, and warns the process that was running + * Takes note of the selection chosen by the user, and warns the process that was running * the box that it can continue. * * @param nChoice Number of choice that was in progress @@ -1420,7 +1420,7 @@ bool doSelection(uint32 i, uint32 dwData) { * @param lplpcfArray Array of pointers to custom functions. * @returns True if everything is OK, false on failure */ -bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, +bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings) { Common::File hMpc; byte buf[5]; @@ -1620,7 +1620,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { */ error("mpalQuery(MPQ_MESSAGE, uint32 nMsg) used incorrect method variant"); - + } else if (wQueryType == MPQ_ITEM_PATTERN) { /* * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); @@ -1629,7 +1629,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { buf = Common::String::format("Pattern.%u", GETARG(uint32)); dwRet = (uint32)varGetValue(buf.c_str()); unlockVar(); - + } else if (wQueryType == MPQ_LOCATION_SIZE) { /* * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); @@ -1648,7 +1648,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { GLOBALS._mpalError = 1; unlockLocations(); - + } else if (wQueryType == MPQ_LOCATION_IMAGE) { /* * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); @@ -1815,19 +1815,19 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { LockMsg(); hRet = DuplicateMessage(msgGetOrderFromNum(GETARG(uint32))); UnlockMsg(); - + } else if (wQueryType == MPQ_ITEM_PATTERN) { /* * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem); */ error("mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem) used incorrect variant"); - + } else if (wQueryType == MPQ_LOCATION_SIZE) { /* * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); */ error("mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord) used incorrect variant"); - + } else if (wQueryType == MPQ_LOCATION_IMAGE) { /* * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); @@ -1961,9 +1961,9 @@ void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) { */ CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._hAskChoice, CORO_INFINITE); - // WORKAROUND: Introduce a single frame delay so that if there are multiple actions running, + // WORKAROUND: Introduce a single frame delay so that if there are multiple actions running, // they all have time to be signalled before resetting the event. This fixes a problem where - // if you try to use the 'shrimp' on the parrot a second time after trying to first use it + // if you try to use the 'shrimp' on the parrot a second time after trying to first use it // whilst the parrot was talking, the cursor wouldn't be re-enabled afterwards CORO_SLEEP(1); @@ -2019,7 +2019,7 @@ bool mpalExecuteScript(int nScript) { /** - * Install a custom routine That will be called by MPAL every time the pattern + * Install a custom routine That will be called by MPAL every time the pattern * of an item has been changed. * * @param lpiifCustom Custom function to install @@ -2032,7 +2032,7 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { /** * Process the idle actions of the items on one location. * - * @param nLoc Number of the location whose items must be processed + * @param nLoc Number of the location whose items must be processed * for idle actions. * @returns TRUE if all OK, and FALSE if it exceeded the maximum limit. * @remarks The maximum number of locations that can be polled @@ -2118,7 +2118,7 @@ void mpalSaveState(byte *buf) { lockVar(); WRITE_LE_UINT32(buf, GLOBALS._nVars); memcpy(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR)); - unlockVar(); + unlockVar(); } @@ -2133,7 +2133,7 @@ int mpalLoadState(byte *buf) { globalFree(GLOBALS._hVars); GLOBALS._nVars = READ_LE_UINT32(buf); - + GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MPALVAR)); lockVar(); memcpy((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR)); diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 251e78afdf..20f2b0b170 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -34,9 +34,9 @@ /* * MPAL (MultiPurpose Adventure Language) is a high level language * for the definition of adventure. Through the use of MPAL you can describe - * storyboard the adventure, and then use it with any user interface. - * In fact, unlike many other similar products, MPAL is not programmed through - * the whole adventure, but are defined only the locations, objects, as they may + * storyboard the adventure, and then use it with any user interface. + * In fact, unlike many other similar products, MPAL is not programmed through + * the whole adventure, but are defined only the locations, objects, as they may * interact with each other, etc.. thus making MPAL useful for any type of adventure. */ @@ -64,16 +64,16 @@ /* * A custom function and a function specified by the program that uses the * library, to perform the particular code. The custom functions are - * retrieved from the library as specified in the source MPAL, and in particular + * retrieved from the library as specified in the source MPAL, and in particular * in defining the behavior of an item with some action. * * To use the custom functions, you need to prepare an array of - * pointers to functions (such as using the type casting LPCUSTOMFUNCTION, + * pointers to functions (such as using the type casting LPCUSTOMFUNCTION, * (defined below), and pass it as second parameter to mpalInit (). Note you - * must specify the size of the array, as elements of pointers and which do not - * contain the same: the library will call it only those functions specified in - * the source MPAL. It can be useful, for debugging reasons, do not bet - * the shares of arrays used to debugging function, to avoid unpleasant crash, + * must specify the size of the array, as elements of pointers and which do not + * contain the same: the library will call it only those functions specified in + * the source MPAL. It can be useful, for debugging reasons, do not bet + * the shares of arrays used to debugging function, to avoid unpleasant crash, * if it has been made an error in source and / or some oversight in the code. * */ @@ -115,7 +115,7 @@ enum QueryCoordinates { /** - * Query can be used with mpalQuery methods. In practice corresponds all claims + * Query can be used with mpalQuery methods. In practice corresponds all claims * that can do at the library */ enum QueryTypes { @@ -176,7 +176,7 @@ typedef void (*LPCUSTOMFUNCTION)(CORO_PARAM, uint32, uint32, uint32, uint32); typedef LPCUSTOMFUNCTION *LPLPCUSTOMFUNCTION; /** - * + * * Define an IRQ of an item that is called when the pattern changes or the status of an item */ typedef void (*LPITEMIRQFUNCTION)(uint32, int, int); @@ -202,8 +202,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * * @param lpszVarName Nome della variabile (ASCIIZ) * @returns Global variable value - * @remarks This query was implemented for debugging. The program, - * if well designed, should not need to access variables from + * @remarks This query was implemented for debugging. The program, + * if well designed, should not need to access variables from * within the library. */ #define mpalQueryGlobalVar(lpszVarName) \ @@ -313,7 +313,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @param nPeriod Number of words * @returns A pointer to the string of words, or NULL on failure. * @remarks The string must be freed after use using the memory manager. - * Unlike normal messages, the sentences of dialogue are formed by a single + * Unlike normal messages, the sentences of dialogue are formed by a single * string terminated with 0. */ #define mpalQueryDialogPeriod(nPeriod) \ @@ -340,14 +340,14 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST, (uint32)(nChoice)) /** - * Warns the library that the user has selected, in a certain choice of the current dialog, + * Warns the library that the user has selected, in a certain choice of the current dialog, * corresponding option at a certain given. * * @param nChoice Choice number of the choice that was in progress * @param dwData Option that was selected by the user. * @returns TRUE if all OK, FALSE on failure. - * @remarks After execution of this query, MPAL continue - * Groups according to the execution of the dialogue. And necessary so the game + * @remarks After execution of this query, MPAL continue + * Groups according to the execution of the dialogue. And necessary so the game * remains on hold again for another chosen by mpalQueryDialogWaitForChoice (). */ #define mpalQueryDialogSelection(nChoice, dwData) \ @@ -357,15 +357,15 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; mpalQueryDWORD(MPQ_DIALOG_SELECTION, (uint32)(nChoice), (uint32)(dwData)) /** - * Warns the library an action was performed on a Object. + * Warns the library an action was performed on a Object. * The library will call custom functions, if necessary. * * @param nAction Action number * @param nItem Item number * @param dwParam Action parameter - * @returns Handle to the thread that is performing the action, or CORO_INVALID_PID_VALUE + * @returns Handle to the thread that is performing the action, or CORO_INVALID_PID_VALUE * if the action is not defined for the item, or the item is inactive. - * @remarks The parameter is used primarily to implement actions + * @remarks The parameter is used primarily to implement actions * as "U.S." involving two objects together. The action will be executed only * if the item is active, ie if its status is a positive number greater than 0. */ @@ -452,7 +452,7 @@ bool mpalExecuteScript(int nScript); uint32 mpalGetError(); /** - * Install a custom routine That will be called by MPAL every time the pattern + * Install a custom routine That will be called by MPAL every time the pattern * of an item has been changed. * * @param lpiifCustom Custom function to install @@ -462,7 +462,7 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCustom); /** * Process the idle actions of the items on one location. * - * @param nLoc Number of the location whose items must be processed + * @param nLoc Number of the location whose items must be processed * for idle actions. * @returns TRUE if all OK, and FALSE if it exceeded the maximum limit. * @remarks The maximum number of locations that can be polled diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index e637362bdf..a95003ef97 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -230,7 +230,7 @@ struct MPALSCRIPT { byte nCmds; uint32 CmdNum[MAX_COMMANDS_PER_MOMENT]; - + } Moment[MAX_MOMENTS_PER_SCRIPT]; } PACKED_STRUCT; -- cgit v1.2.3 From b12ccad9943c99ecfc4edc6f4a46e4d88db609cf Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Aug 2012 00:30:07 +0200 Subject: TONY: Reduce scope of some variables --- engines/tony/mpal/expr.cpp | 30 +++++------ engines/tony/mpal/loadmpc.cpp | 88 +++++++++++++----------------- engines/tony/mpal/mpal.cpp | 121 +++++++++++++++++------------------------- 3 files changed, 102 insertions(+), 137 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index ef58208d3f..2b2dbf2529 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -109,13 +109,12 @@ typedef EXPRESSION *LPEXPRESSION; * @retruns Pointer to the cloned expression */ static byte *duplicateExpression(HGLOBAL h) { - int i, num; byte *orig, *clone; LPEXPRESSION one, two; orig = (byte *)globalLock(h); - num = *(byte *)orig; + int num = *(byte *)orig; one = (LPEXPRESSION)(orig+1); clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); @@ -123,7 +122,7 @@ static byte *duplicateExpression(HGLOBAL h) { memcpy(clone, orig, sizeof(EXPRESSION) * num + 1); - for (i = 0; i < num; i++) { + for (int i = 0; i < num; i++) { if (one->type == ELT_PARENTH) { two->type = ELT_PARENTH2; two->val.pson = duplicateExpression(two->val.son); @@ -218,14 +217,14 @@ static void solve(LPEXPRESSION one, int num) { * @returns Value */ static int evaluateAndFreeExpression(byte *expr) { - int i,num,val; - LPEXPRESSION one,cur; + LPEXPRESSION one, cur; - num = *expr; + int num = *expr; one = (LPEXPRESSION)(expr + 1); // 1) Sostituzioni delle variabili - for (i = 0, cur = one; i < num; i++, cur++) { + cur = one; + for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_VAR) { cur->type = ELT_NUMBER; cur->val.num = varGetValue(cur->val.name); @@ -233,7 +232,8 @@ static int evaluateAndFreeExpression(byte *expr) { } // 2) Sostituzioni delle parentesi (tramite ricorsione) - for (i = 0, cur = one; i < num; i++, cur++) { + cur = one; + for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_PARENTH2) { cur->type = ELT_NUMBER; cur->val.num = evaluateAndFreeExpression(cur->val.pson); @@ -242,7 +242,7 @@ static int evaluateAndFreeExpression(byte *expr) { // 3) Risoluzione algebrica solve(one, num); - val = one->val.num; + int val = one->val.num; globalDestroy(expr); return val; @@ -260,9 +260,8 @@ static int evaluateAndFreeExpression(byte *expr) { const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { LPEXPRESSION cur; byte *start; - uint32 num, i; - num = *lpBuf; + uint32 num = *lpBuf; lpBuf++; if (num == 0) @@ -277,7 +276,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { cur = (LPEXPRESSION)(start + 1); - for (i = 0;i < num; i++) { + for (uint32 i = 0;i < num; i++) { cur->type = *(lpBuf); cur->unary = *(lpBuf + 1); lpBuf += 2; @@ -343,15 +342,14 @@ int evaluateExpression(HGLOBAL h) { * @param h2 Expression to be compared */ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { - int i, num1, num2; byte *e1, *e2; LPEXPRESSION one, two; e1 = (byte *)globalLock(h1); e2 = (byte *)globalLock(h2); - num1 = *(byte *)e1; - num2 = *(byte *)e2; + int num1 = *(byte *)e1; + int num2 = *(byte *)e2; if (num1 != num2) { globalUnlock(h1); @@ -362,7 +360,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { one = (LPEXPRESSION)(e1 + 1); two = (LPEXPRESSION)(e2 + 1); - for (i = 0; i < num1; i++) { + for (int i = 0; i < num1; i++) { if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { globalUnlock(h1); globalUnlock(h2); diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 9da2cc121e..790d8d4903 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -62,24 +62,21 @@ static bool compareCommands(struct command *cmd1, struct command *cmd2) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { - int curCmd, j, len; - uint i; - lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; lpmsScript->nMoments = READ_LE_UINT16(lpBuf); lpBuf += 2; - curCmd = 0; + int curCmd = 0; - for (i = 0; i < lpmsScript->nMoments; i++) { + for (uint i = 0; i < lpmsScript->nMoments; i++) { lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; lpmsScript->Moment[i].nCmds = *lpBuf; lpBuf++; - for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) { + for (int j = 0; j < lpmsScript->Moment[i].nCmds; j++) { lpmsScript->_command[curCmd].type = *lpBuf; lpBuf++; switch (lpmsScript->_command[curCmd].type) { @@ -96,8 +93,8 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpBuf += 4; break; - case 2: // Variable assign - len = *lpBuf; + case 2: { // Variable assign + int len = *lpBuf; lpBuf++; lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmsScript->_command[curCmd].lpszVarName == NULL) @@ -109,7 +106,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { if (lpBuf == NULL) return NULL; break; - + } default: return NULL; } @@ -145,22 +142,20 @@ static void FreeScript(LPMPALSCRIPT lpmsScript) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { - uint32 i, j, z, kk; - uint32 num, num2, num3; + uint32 num2, num3; byte *lpLock; - uint32 curCmd; - uint32 len; lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; /* Periodi */ - num = READ_LE_UINT16(lpBuf); + uint32 num = READ_LE_UINT16(lpBuf); lpBuf += 2; if (num >= MAX_PERIODS_PER_DIALOG - 1) error("Too much periods in dialog #%d", lpmdDialog->nObj); + uint32 i; for (i = 0; i < num; i++) { lpmdDialog->_periodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -177,7 +172,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { /* Gruppi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; - curCmd = 0; + uint32 curCmd = 0; if (num >= MAX_GROUPS_PER_DIALOG) error("Too much groups in dialog #%d", lpmdDialog->nObj); @@ -190,7 +185,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (lpmdDialog->_group[i].nCmds >= MAX_COMMANDS_PER_GROUP) error("Too much commands in group #%d in dialog #%d",lpmdDialog->_group[i].num,lpmdDialog->nObj); - for (j = 0; j < lpmdDialog->_group[i].nCmds; j++) { + for (uint32 j = 0; j < lpmdDialog->_group[i].nCmds; j++) { lpmdDialog->_command[curCmd].type = *lpBuf; lpBuf++; @@ -210,8 +205,8 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { break; // Variable assign - case 2: - len = *lpBuf; + case 2: { + uint32 len = *lpBuf; lpBuf++; lpmdDialog->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmdDialog->_command[curCmd].lpszVarName == NULL) @@ -224,7 +219,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (lpBuf == NULL) return NULL; break; - + } // Do Choice case 3: lpmdDialog->_command[curCmd].nChoice = READ_LE_UINT16(lpBuf); @@ -235,6 +230,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { return NULL; } + uint32 kk; for (kk = 0;kk < curCmd; kk++) { if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) { lpmdDialog->_group[i].CmdNum[j] = kk; @@ -278,7 +274,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (num2 >= MAX_SELECTS_PER_CHOICE) error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); - for (j = 0; j < num2; j++) { + for (uint32 j = 0; j < num2; j++) { // When switch (*lpBuf++) { case 0: @@ -308,7 +304,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (num3 >= MAX_PLAYGROUPS_PER_SELECT) error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); - for (z = 0; z < num3; z++) { + for (uint32 z = 0; z < num3; z++) { lpmdDialog->_choice[i]._select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; } @@ -337,14 +333,10 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { * completely initialized to 0 beforehand. */ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { - byte len; - uint32 i, j, kk; - uint32 curCmd; - lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - len = *lpBuf; + byte len = *lpBuf; lpBuf++; memcpy(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); lpBuf += len; @@ -359,9 +351,9 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { if (lpmiItem->nActions > 0) lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); - curCmd = 0; + uint32 curCmd = 0; - for (i = 0; i < lpmiItem->nActions; i++) { + for (uint32 i = 0; i < lpmiItem->nActions; i++) { lpmiItem->Action[i].num = *lpBuf; lpBuf++; @@ -393,7 +385,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); - for (j = 0; j < lpmiItem->Action[i].nCmds; j++) { + for (uint32 j = 0; j < lpmiItem->Action[i].nCmds; j++) { lpmiItem->_command[curCmd].type = *lpBuf; lpBuf++; switch (lpmiItem->_command[curCmd].type) { @@ -428,6 +420,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { return NULL; } + uint32 kk; for (kk = 0; kk < curCmd; kk++) { if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) { lpmiItem->Action[i].CmdNum[j] = kk; @@ -527,8 +520,6 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) * @returns True if succeeded OK, false if failure. */ bool ParseMpc(const byte *lpBuf) { - uint16 i, j; - uint16 wLen; byte *lpTemp; /* 1. Variables */ @@ -545,8 +536,8 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); - for (i = 0; i < GLOBALS._nVars; i++) { - wLen = *(const byte *)lpBuf; + for (uint16 i = 0; i < GLOBALS._nVars; i++) { + uint16 wLen = *(const byte *)lpBuf; lpBuf++; memcpy(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; @@ -579,10 +570,11 @@ bool ParseMpc(const byte *lpBuf) { return false; #endif - for (i = 0; i < GLOBALS._nMsgs; i++) { + for (uint16 i = 0; i < GLOBALS._nMsgs; i++) { GLOBALS._lpmmMsgs->_wNum = READ_LE_UINT16(lpBuf); lpBuf += 2; + uint16 j; for (j = 0; lpBuf[j] != 0;) j += lpBuf[j] + 1; @@ -628,7 +620,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0;i < GLOBALS._nDialogs; i++) { + for (uint16 i = 0; i < GLOBALS._nDialogs; i++) { if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS._lpmdDialogs[i])) == NULL) return false; } @@ -650,7 +642,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS._nItems; i++) { + for (uint16 i = 0; i < GLOBALS._nItems; i++) { if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS._lpmiItems[i])) == NULL) return false; } @@ -672,7 +664,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); - for (i = 0; i < GLOBALS._nLocations; i++) { + for (uint16 i = 0; i < GLOBALS._nLocations; i++) { if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS._lpmlLocations[i])) == NULL) return false; } @@ -694,7 +686,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS._nScripts; i++) { + for (uint16 i = 0; i < GLOBALS._nScripts; i++) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS._lpmsScripts[i])) == NULL) return false; @@ -721,12 +713,10 @@ bool ParseMpc(const byte *lpBuf) { */ static void freeDialog(LPMPALDIALOG lpmdDialog) { // Free the periods - int i, j; - - for (i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) + for (int i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) globalFree(lpmdDialog->_periods[i]); - for (i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { + for (int i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { if (lpmdDialog->_command[i].type == 2) { // Variable assign globalDestroy(lpmdDialog->_command[i].lpszVarName); @@ -735,8 +725,8 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { } // Free the choices - for (i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { - for (j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { + for (int i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { + for (int j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { if (lpmdDialog->_choice[i]._select[j].when) freeExpression(lpmdDialog->_choice[i]._select[j].when); } @@ -747,14 +737,12 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { * Frees any data allocated from the parsing of the MPC file */ void FreeMpc() { - int i; - // Free variables globalFree(GLOBALS._hVars); // Free messages LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); - for (i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) + for (int i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) globalFree(lpmmMsgs->_hText); globalUnlock(GLOBALS._hMsgs); @@ -764,7 +752,7 @@ void FreeMpc() { if (GLOBALS._hDialogs) { LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) + for (int i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) freeDialog(lpmdDialogs); globalFree(GLOBALS._hDialogs); @@ -774,7 +762,7 @@ void FreeMpc() { if (GLOBALS._hItems) { LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) + for (int i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) freeItem(lpmiItems); globalUnlock(GLOBALS._hItems); @@ -790,7 +778,7 @@ void FreeMpc() { if (GLOBALS._hScripts) { LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { + for (int i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { FreeScript(lpmsScripts); } diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index be2f6db43f..540dee664f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -154,10 +154,9 @@ static void unlockScripts() { * need to remember to call UnlockVar() */ int32 varGetValue(const char *lpszVarName) { - int i; LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS._nVars; v++, i++) + for (int i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) return v->dwVal; @@ -171,10 +170,9 @@ int32 varGetValue(const char *lpszVarName) { * @param val Value to set */ void varSetValue(const char *lpszVarName, int32 val) { - uint i; LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS._nVars; v++, i++) + for (uint i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) { v->dwVal = val; if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { @@ -202,10 +200,9 @@ void varSetValue(const char *lpszVarName, int32 val) { * first been locked with a call to LockLoc(). */ static int locGetOrderFromNum(uint32 nLoc) { - int i; LPMPALLOCATION loc = GLOBALS._lpmlLocations; - for (i = 0; i < GLOBALS._nLocations; i++, loc++) + for (int i = 0; i < GLOBALS._nLocations; i++, loc++) if (loc->nObj == nLoc) return i; @@ -221,10 +218,9 @@ static int locGetOrderFromNum(uint32 nLoc) { * first been locked with a call to LockMsg() */ static int msgGetOrderFromNum(uint32 nMsg) { - int i; LPMPALMSG msg = GLOBALS._lpmmMsgs; - for (i = 0; i < GLOBALS._nMsgs; i++, msg++) { + for (int i = 0; i < GLOBALS._nMsgs; i++, msg++) { if (msg->_wNum == nMsg) return i; } @@ -240,10 +236,9 @@ static int msgGetOrderFromNum(uint32 nMsg) { * first been locked with a call to LockItems() */ static int itemGetOrderFromNum(uint32 nItem) { - int i; LPMPALITEM item = GLOBALS._lpmiItems; - for (i = 0; i < GLOBALS._nItems; i++, item++) { + for (int i = 0; i < GLOBALS._nItems; i++, item++) { if (item->nObj == nItem) return i; } @@ -260,10 +255,9 @@ static int itemGetOrderFromNum(uint32 nItem) { * first been locked with a call to LockScripts() */ static int scriptGetOrderFromNum(uint32 nScript) { - int i; LPMPALSCRIPT script = GLOBALS._lpmsScripts; - for (i = 0; i < GLOBALS._nScripts; i++, script++) { + for (int i = 0; i < GLOBALS._nScripts; i++, script++) { if (script->nObj == nScript) return i; } @@ -280,10 +274,9 @@ static int scriptGetOrderFromNum(uint32 nScript) { * first been locked with a call to LockDialogs() */ static int dialogGetOrderFromNum(uint32 nDialog) { - int i; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs; - for (i = 0; i < GLOBALS._nDialogs; i++, dialog++) { + for (int i = 0; i < GLOBALS._nDialogs; i++, dialog++) { if (dialog->nObj == nDialog) return i; } @@ -301,14 +294,13 @@ static int dialogGetOrderFromNum(uint32 nDialog) { static char *DuplicateMessage(uint32 nMsgOrd) { const char *origmsg; char *clonemsg; - int j; if (nMsgOrd == (uint32)-1) return NULL; origmsg = (const char *)globalLock(GLOBALS._lpmmMsgs[nMsgOrd]._hText); - j = 0; + int j = 0; while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') j++; j += 2; @@ -335,15 +327,14 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; - int i, j; - for (j = 0; dialog->_periods[j] != NULL; j++) { + for (int j = 0; dialog->_periods[j] != NULL; j++) { if (dialog->_periodNums[j] == nPeriod) { /* Found the phrase, it should be duplicated */ origmsg = (const char *)globalLock(dialog->_periods[j]); /* Calculate the length and allocate memory */ - i = 0; + int i = 0; while (origmsg[i] != '\0') i++; @@ -370,14 +361,13 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { * @returns Handle to the loaded resource */ HGLOBAL resLoad(uint32 dwId) { - int i; HGLOBAL h; char head[4]; uint32 nBytesRead; uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; - for (i = 0; i < GLOBALS._nResources; i++) + for (int i = 0; i < GLOBALS._nResources; i++) if (GLOBALS._lpResources[i * 2] == dwId) { GLOBALS._hMpr.seek(GLOBALS._lpResources[i * 2 + 1]); nBytesRead = GLOBALS._hMpr.read(head, 4); @@ -416,12 +406,11 @@ HGLOBAL resLoad(uint32 dwId) { static uint32 *getSelectList(uint32 i) { uint32 *sl; - int j, k, num; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; /* Count how many are active selects */ - num = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { + int num = 0; + for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) num++; } @@ -430,13 +419,13 @@ static uint32 *getSelectList(uint32 i) { if (num == 0) return NULL; - sl= (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + sl = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); if (sl == NULL) return NULL; /* Copy all the data inside the active select list */ - k = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { + int k = 0; + for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) sl[k++] = dialog->_choice[i]._select[j].dwData; } @@ -447,11 +436,10 @@ static uint32 *getSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; - uint32 num,i,j; LPMPALVAR v = GLOBALS._lpmvVars; - num = 0; - for (i = 0; i < GLOBALS._nVars; i++, v++) { + uint32 num = 0; + for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } @@ -461,8 +449,8 @@ static uint32 *GetItemList(uint32 nLoc) { return NULL; v = GLOBALS._lpmvVars; - j = 0; - for (i = 0; i < GLOBALS._nVars; i++, v++) { + uint32 j = 0; + for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName, "Location", 8) == 0 && v->dwVal == nLoc) { sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; @@ -478,9 +466,7 @@ static LPITEM getItemData(uint32 nOrdItem) { LPITEM ret; HGLOBAL hDat; char *dat; - int i, j; char *patlength; - uint32 dim; // Zeroing out the allocated memory is required!!! ret = (LPITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); @@ -492,7 +478,7 @@ static LPITEM getItemData(uint32 nOrdItem) { dat = (char *)globalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { - i = dat[3]; // For version 1.0!! + int i = dat[3]; // For version 1.0!! dat += 4; if (i >= 0x10) { // From 1.0, there's a destination point for each object @@ -513,21 +499,21 @@ static LPITEM getItemData(uint32 nOrdItem) { ret->_destZ = *dat++; // Upload the left & top co-ordinates of each frame - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_frameslocations[i].left = (int16)READ_LE_UINT16(dat); ret->_frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); dat += 4; } // Upload the size of each frame and calculate the right & bottom - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->_frameslocations[i].left; ret->_frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->_frameslocations[i].top; dat += 4; } // Upload the bounding boxes of each frame - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_bbox[i].left = (int16)READ_LE_UINT16(dat); ret->_bbox[i].top = (int16)READ_LE_UINT16(dat + 2); ret->_bbox[i].right = (int16)READ_LE_UINT16(dat + 4); @@ -539,16 +525,16 @@ static LPITEM getItemData(uint32 nOrdItem) { patlength = dat; dat += ret->_numpattern; - for (i = 1; i < ret->_numpattern; i++) { - for (j = 0; j < patlength[i]; j++) + for (int i = 1; i < ret->_numpattern; i++) { + for (int j = 0; j < patlength[i]; j++) ret->_pattern[i][j] = dat[j]; ret->_pattern[i][(int)patlength[i]] = 255; // Terminate pattern dat += patlength[i]; } // Upload the individual frames of animations - for (i = 1; i < ret->_numframe; i++) { - dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * + for (int i = 1; i < ret->_numframe; i++) { + uint32 dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * (uint32)(ret->_frameslocations[i].bottom - ret->_frameslocations[i].top); ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); @@ -559,7 +545,7 @@ static LPITEM getItemData(uint32 nOrdItem) { } // Check if we've got to the end of the file - i = READ_LE_UINT16(dat); + int i = READ_LE_UINT16(dat); if (i != 0xABCD) return NULL; @@ -1288,16 +1274,14 @@ void doChoice(CORO_PARAM, uint32 nChoice) { */ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = GLOBALS._lpmiItems; - int i; LPMPALITEM newitem; - uint32 h; item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); if (varGetValue(buf.c_str()) <= 0) return CORO_INVALID_PID_VALUE; - for (i = 0; i < item->nActions; i++) { + for (int i = 0; i < item->nActions; i++) { if (item->Action[i].num != nAction) continue; @@ -1326,6 +1310,7 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // and a second process to free up the memory when the action is finished. // !!! New process management + uint32 h; if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; @@ -1353,8 +1338,6 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * The data on the choices may be obtained through various queries. */ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { - uint32 h; - // Store the running dialog in a global variable GLOBALS._nExecutingDialog = nDlgOrd; @@ -1367,6 +1350,7 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { // Create a thread that performs the dialogue group // Create the process + uint32 h; if ((h = CoroScheduler.createProcess(GroupThread, &nGroup, sizeof(uint32))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; @@ -1589,7 +1573,6 @@ void mpalFree() { * method that returns numeric results. */ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { - int x, y; Common::String buf; uint32 dwRet = 0; char *n; @@ -1635,8 +1618,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); */ lockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); + int x = locGetOrderFromNum(GETARG(uint32)); + int y = GETARG(uint32); if (x != -1) { if (y == MPQ_X) dwRet = GLOBALS._lpmlLocations[x].dwXlen; @@ -1678,7 +1661,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) dwRet = (uint32)false; @@ -1692,14 +1675,14 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0]='\0'; else { lockItems(); - y = itemGetOrderFromNum(x); + int y = itemGetOrderFromNum(x); memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1729,8 +1712,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); */ lockDialogs(); - x = GETARG(uint32); - y = GETARG(uint32); + int x = GETARG(uint32); + int y = GETARG(uint32); dwRet = (uint32)doSelection(x, y); unlockDialogs(); @@ -1741,9 +1724,9 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { */ lockItems(); lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); int z = GETARG(uint32); - y = itemGetOrderFromNum(z); + int y = itemGetOrderFromNum(z); if (y != -1) { dwRet = doAction(x, y, GETARG(uint32)); } else { @@ -1761,8 +1744,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { if (!GLOBALS._bExecutingDialog) { lockDialogs(); - x = dialogGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); + int x = dialogGetOrderFromNum(GETARG(uint32)); + int y = GETARG(uint32); dwRet = doDialog(x, y); unlockDialogs(); } @@ -1787,7 +1770,6 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * method that returns a pointer or handle. */ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { - int x, y; char *n; Common::String buf; va_list v; @@ -1833,7 +1815,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); */ lockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); + int x = locGetOrderFromNum(GETARG(uint32)); hRet = resLoad(GLOBALS._lpmlLocations[x].dwPicRes); unlockLocations(); @@ -1870,14 +1852,14 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char *lpszName); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0] = '\0'; else { lockItems(); - y = itemGetOrderFromNum(x); + int y = itemGetOrderFromNum(x); memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1889,7 +1871,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); */ lockDialogs(); - y = GETARG(uint32); + int y = GETARG(uint32); hRet = duplicateDialogPeriod(y); unlockDialogs(); @@ -1998,11 +1980,10 @@ uint32 mpalGetError() { * @returns TRUE if the script 'was launched, FALSE on failure */ bool mpalExecuteScript(int nScript) { - int n; LPMPALSCRIPT s; LockScripts(); - n = scriptGetOrderFromNum(nScript); + int n = scriptGetOrderFromNum(nScript); s = (LPMPALSCRIPT)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); if (s == NULL) return false; @@ -2039,14 +2020,12 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { * simultaneously is defined defined by MAXPOLLINGFUNCIONS */ bool mpalStartIdlePoll(int nLoc) { - uint32 i; - - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { + for (uint32 i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == (uint32)nLoc) return false; } - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { + for (uint32 i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == 0) { GLOBALS._nPollingLocations[i] = nLoc; -- cgit v1.2.3 From 92a9820f3371037fa9009e4b2c9831f169cd8809 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Aug 2012 08:11:52 +0200 Subject: TONY: Translate some remaining italian comments --- engines/tony/mpal/expr.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 2b2dbf2529..5f3026144c 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -222,7 +222,7 @@ static int evaluateAndFreeExpression(byte *expr) { int num = *expr; one = (LPEXPRESSION)(expr + 1); - // 1) Sostituzioni delle variabili + // 1) Substitutions of variables cur = one; for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_VAR) { @@ -231,7 +231,7 @@ static int evaluateAndFreeExpression(byte *expr) { } } - // 2) Sostituzioni delle parentesi (tramite ricorsione) + // 2) Replacement of brackets (using recursive calls) cur = one; for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_PARENTH2) { @@ -240,7 +240,7 @@ static int evaluateAndFreeExpression(byte *expr) { } } - // 3) Risoluzione algebrica + // 3) algebraic resolution solve(one, num); int val = one->val.num; globalDestroy(expr); -- cgit v1.2.3 From a29f1fb04ca4ee84986c359f1a1743d16c675487 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Aug 2012 08:14:41 +0200 Subject: TONY: Remove some dead code --- engines/tony/mpal/mpal.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 540dee664f..862ea53824 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -637,7 +637,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->p->_arg3 = s->_command[_ctx->k]._arg3; _ctx->p->_arg4 = s->_command[_ctx->k]._arg4; - // !!! New process management + // !!! New process management if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { GLOBALS._mpalError = 1; @@ -1413,10 +1413,6 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, uint32 dwSizeDecomp, dwSizeComp; byte *cmpbuf; - //printf("Item: %lu\n", sizeof(MPALITEM)); - //printf("Script: %lu\n", sizeof(MPALSCRIPT)); - //printf("Dialog: %lu\n", sizeof(MPALDIALOG)); - /* Save the array of custom functions */ GLOBALS._lplpFunctions = lplpcfArray; GLOBALS._lplpFunctionStrings = lpcfStrings; @@ -1480,21 +1476,6 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, globalDestroy(lpMpcImage); - /* Calculate memory usage */ - /* - { - char errbuf[256]; - wsprintf(errbuf,"Utilizzo in RAM: VAR %lu, MSG %lu, DLG %lu, ITM %lu, LOC %lu, SCR %lu", - GLOBALS.nVars*sizeof(MPALVAR), - GLOBALS.nMsgs*sizeof(MPALMSG), - GLOBALS.nDialogs*sizeof(MPALDIALOG), - GLOBALS.nItems*sizeof(MPALITEM), - GLOBALS.nLocations*sizeof(MPALLOCATION), - GLOBALS.nScripts*sizeof(MPALSCRIPT)); - MessageBox(NULL,errbuf,"Dump",MB_OK); - } -*/ - /* Open the MPR file */ if (!GLOBALS._hMpr.open(lpszMprFileName)) return false; -- cgit v1.2.3 From 766eadeef98e6adcd52e5fb5325a1f7586572402 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Aug 2012 22:47:33 +0200 Subject: TONY: Translate some remaining Italian comments --- engines/tony/mpal/loadmpc.cpp | 13 +++++-------- engines/tony/mpal/mpal.cpp | 3 +-- engines/tony/mpal/mpal.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 790d8d4903..e23197144b 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -26,9 +26,6 @@ * Copyright (c) 1997-2003 Nayma Software */ -/* -#include "lzo1x.h" -*/ #include "mpal.h" #include "mpaldll.h" #include "memory.h" @@ -148,7 +145,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; - /* Periodi */ + /* Periods */ uint32 num = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -169,7 +166,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->_periodNums[i] = 0; lpmdDialog->_periods[i] = NULL; - /* Gruppi */ + /* Groups */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; uint32 curCmd = 0; @@ -347,7 +344,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->nActions=*lpBuf; lpBuf++; - /* Alloca le azioni */ + /* Allocation action */ if (lpmiItem->nActions > 0) lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); @@ -544,7 +541,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmvVars->dwVal = READ_LE_UINT32(lpBuf); lpBuf += 4; - lpBuf++; // Salta 'ext' + lpBuf++; // Skip 'ext' GLOBALS._lpmvVars++; } @@ -688,7 +685,7 @@ bool ParseMpc(const byte *lpBuf) { for (uint16 i = 0; i < GLOBALS._nScripts; i++) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS._lpmsScripts[i])) == NULL) - return false; + return false; // Sort the various moments of the script //qsort( diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 862ea53824..b4b18749ef 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -920,8 +920,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { /* Here's the main loop */ while (1) { - /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per - l'esecuzione */ + // Searching for idle actions requiring time to execute _ctx->curTime = g_vm->getTime(); _ctx->dwSleepTime = (uint32)-1L; diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 20f2b0b170..4c8ca481b0 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -200,7 +200,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; /** * Gets the numerical value of a global variable * - * @param lpszVarName Nome della variabile (ASCIIZ) + * @param lpszVarName Variable name (ASCIIZ) * @returns Global variable value * @remarks This query was implemented for debugging. The program, * if well designed, should not need to access variables from -- cgit v1.2.3 From 825e0896dc52c26e7e31447a434619e190e5c183 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Aug 2012 23:25:14 +0200 Subject: TONY: Replace C-style comments by C++-style ones. Also translate some more Italian comments --- engines/tony/mpal/expr.cpp | 4 -- engines/tony/mpal/loadmpc.cpp | 14 ++--- engines/tony/mpal/mpal.cpp | 141 +++++++++++++++++++++--------------------- engines/tony/mpal/mpal.h | 12 ++-- 4 files changed, 83 insertions(+), 88 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 5f3026144c..31abeb0810 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -31,10 +31,6 @@ #include "tony/mpal/mpaldll.h" #include "tony/tony.h" -/* -#include "lzo1x.h" -*/ - namespace Tony { namespace MPAL { diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index e23197144b..9927f9fe8e 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -145,7 +145,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; - /* Periods */ + // Periods uint32 num = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -166,7 +166,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpmdDialog->_periodNums[i] = 0; lpmdDialog->_periods[i] = NULL; - /* Groups */ + // Groups num = READ_LE_UINT16(lpBuf); lpBuf += 2; uint32 curCmd = 0; @@ -255,7 +255,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (curCmd >= MAX_COMMANDS_PER_DIALOG) error("Too much commands in dialog #%d",lpmdDialog->nObj); - /* Choices */ + // Choices num = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -344,7 +344,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { lpmiItem->nActions=*lpBuf; lpBuf++; - /* Allocation action */ + // Allocation action if (lpmiItem->nActions > 0) lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); @@ -519,7 +519,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) bool ParseMpc(const byte *lpBuf) { byte *lpTemp; - /* 1. Variables */ + // 1. Variables if (lpBuf[0] != 'V' || lpBuf[1] != 'A' || lpBuf[2] != 'R' || lpBuf[3] != 'S') return false; @@ -547,7 +547,7 @@ bool ParseMpc(const byte *lpBuf) { globalUnlock(GLOBALS._hVars); - /* 2. Messages */ + // 2. Messages if (lpBuf[0] != 'M' || lpBuf[1] != 'S' || lpBuf[2] != 'G' || lpBuf[3] != 'S') return false; @@ -596,7 +596,7 @@ bool ParseMpc(const byte *lpBuf) { globalUnlock(GLOBALS._hMsgs); #endif - /* 3. Objects */ + // 3. Objects if (lpBuf[0] != 'O' || lpBuf[1] != 'B' || lpBuf[2] != 'J' || lpBuf[3] != 'S') return false; diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index b4b18749ef..514001eda7 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -330,10 +330,10 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { for (int j = 0; dialog->_periods[j] != NULL; j++) { if (dialog->_periodNums[j] == nPeriod) { - /* Found the phrase, it should be duplicated */ + // Found the phrase, it should be duplicated origmsg = (const char *)globalLock(dialog->_periods[j]); - /* Calculate the length and allocate memory */ + // Calculate the length and allocate memory int i = 0; while (origmsg[i] != '\0') i++; @@ -408,14 +408,14 @@ static uint32 *getSelectList(uint32 i) { uint32 *sl; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; - /* Count how many are active selects */ + // Count how many are active selects int num = 0; for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) num++; } - /* If there are 0, it's a mistake */ + // If there are 0, it's a mistake if (num == 0) return NULL; @@ -423,7 +423,7 @@ static uint32 *getSelectList(uint32 i) { if (sl == NULL) return NULL; - /* Copy all the data inside the active select list */ + // Copy all the data inside the active select list int k = 0; for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) @@ -821,18 +821,18 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - /* Initialize data pointers */ + // Initialize data pointers _ctx->MyActions = NULL; _ctx->MyThreads = NULL; - /* To begin with, we need to request the item list from the location */ + // To begin with, we need to request the item list from the location _ctx->il = mpalQueryItemList(GLOBALS._nPollingLocations[id]); - /* Count the items */ + // Count the items for (_ctx->numitems = 0; _ctx->il[_ctx->numitems] != 0; _ctx->numitems++) ; - /* We look for items without idle actions, and eliminate them from the list */ + // We look for items without idle actions, and eliminate them from the list lockItems(); _ctx->nIdleActions = 0; _ctx->nRealItems = 0; @@ -853,14 +853,14 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->nIdleActions += _ctx->k; if (_ctx->k == 0) - /* We can remove this item from the list */ + // We can remove this item from the list _ctx->il[_ctx->i] = (uint32)NULL; else _ctx->nRealItems++; } unlockItems(); - /* If there is nothing left, we can exit */ + // If there is nothing left, we can exit if (_ctx->nRealItems == 0) { globalDestroy(_ctx->il); CORO_KILL_SELF(); @@ -875,8 +875,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { } - /* We have established that there is at least one item that contains idle actions. - Now we created the mirrored copies of the idle actions. */ + // We have established that there is at least one item that contains idle actions. + // Now we created the mirrored copies of the idle actions. _ctx->MyActions = (MYACTION *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); if (_ctx->MyActions == NULL) { globalDestroy(_ctx->MyThreads); @@ -914,11 +914,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { unlockItems(); - /* We don't need the item list anymore */ + // We don't need the item list anymore globalDestroy(_ctx->il); - /* Here's the main loop */ + // Here's the main loop while (1) { // Searching for idle actions requiring time to execute _ctx->curTime = g_vm->getTime(); @@ -932,7 +932,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); } - /* We fall alseep, but always checking that the event is set when prompted for closure */ + // We fall alseep, but always checking that the event is set when prompted for closure CORO_INVOKE_3(CoroScheduler.waitForSingleObject, GLOBALS._hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired); //if (_ctx->k == WAIT_OBJECT_0) @@ -951,19 +951,19 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->curTime = g_vm->getTime(); - /* Loop through all the necessary idle actions */ + // Loop through all the necessary idle actions for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) { if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; - /* It's time to check to see if fortune is on the side of the idle action */ + // It's time to check to see if fortune is on the side of the idle action byte randomVal = (byte)g_vm->_randomSource.getRandomNumber(99); if (randomVal < _ctx->MyActions[_ctx->k].perc) { - /* Check if there is an action running on the item */ + // Check if there is an action running on the item if ((GLOBALS._bExecutingAction) && (GLOBALS._nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) continue; - /* Check to see if there already another idle funning running on the item */ + // Check to see if there already another idle funning running on the item for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem == _ctx->MyActions[_ctx->k].nItem) break; @@ -972,11 +972,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->i < _ctx->nRealItems) continue; - /* Ok, we are the only ones :) */ + // Ok, we are the only ones :) lockItems(); _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); - /* Check if there is a WhenExecute expression */ + // Check if there is a WhenExecute expression _ctx->j=_ctx->MyActions[_ctx->k].nAction; if (_ctx->curItem->Action[_ctx->j].when != NULL) { if (!evaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { @@ -985,7 +985,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { } } - /* Ok, we can perform the action. For convenience, we do it in a new process */ + // Ok, we can perform the action. For convenience, we do it in a new process _ctx->newItem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); if (_ctx->newItem == false) { globalDestroy(_ctx->MyThreads); @@ -998,12 +998,12 @@ void LocationPollThread(CORO_PARAM, const void *param) { memcpy(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); unlockItems(); - /* We copy the action in #0 */ -// _ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; -// memcpy(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); + // We copy the action in #0 + //_ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; + //memcpy(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); _ctx->newItem->dwRes=_ctx->j; - /* We will create an action, and will provide the necessary details */ + // We will create an action, and will provide the necessary details for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { if (_ctx->MyThreads[_ctx->i].nItem == 0) break; @@ -1022,7 +1022,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { return; } - /* Skip all idle actions of the same item */ + // Skip all idle actions of the same item } } } @@ -1036,11 +1036,10 @@ void LocationPollThread(CORO_PARAM, const void *param) { if (_ctx->MyThreads[_ctx->i].nItem != 0) { CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); -/* //if (result != WAIT_OBJECT_0) - if (_ctx->delayExpired) - TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); -*/ + //if (_ctx->delayExpired) + // TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); + CoroScheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); } } @@ -1142,15 +1141,15 @@ void GroupThread(CORO_PARAM, const void *param) { } } - /* The gruop is finished, so we can return to the calling function. - * If the group was the first called, then the process will automatically - * end. Otherwise it returns to the caller method - */ + // The gruop is finished, so we can return to the calling function. + // If the group was the first called, then the process will automatically + // end. Otherwise it returns to the caller method + return; } } - /* If we are here, it means that we have not found the requested group */ + // If we are here, it means that we have not found the requested group GLOBALS._mpalError = 1; unlockDialogs(); @@ -1174,21 +1173,21 @@ void doChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CODE(_ctx); - /* Lock the dialogs */ + // Lock the dialogs lockDialogs(); - /* Get a pointer to the current dialog */ + // Get a pointer to the current dialog _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; - /* Search the choice between those required in the dialog */ + // Search the choice between those required in the dialog for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) { if (_ctx->dialog->_choice[_ctx->i].nChoice == nChoice) break; } - /* If nothing has been found, exit with an error */ + // If nothing has been found, exit with an error if (_ctx->dialog->_choice[_ctx->i].nChoice == 0) { - /* If we're here, we did not find the required choice */ + // If we're here, we did not find the required choice GLOBALS._mpalError = 1; unlockDialogs(); @@ -1196,14 +1195,14 @@ void doChoice(CORO_PARAM, uint32 nChoice) { return; } - /* We've found the requested choice. Remember what in global variables */ + // We've found the requested choice. Remember what in global variables GLOBALS._nExecutingChoice = _ctx->i; while (1) { GLOBALS._nExecutingChoice = _ctx->i; _ctx->k = 0; - /* Calculate the expression of each selection, to see if they're active or inactive */ + // Calculate the expression of each selection, to see if they're active or inactive for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].dwData != 0; _ctx->j++) { if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when == NULL) { _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; @@ -1215,41 +1214,40 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 0; } - /* If there are no choices activated, then the dialog is finished. */ + // If there are no choices activated, then the dialog is finished. if (_ctx->k == 0) { unlockDialogs(); break; } - /* There are choices available to the user, so wait for them to make one */ + // There are choices available to the user, so wait for them to make one CoroScheduler.resetEvent(GLOBALS._hDoneChoice); CoroScheduler.setEvent(GLOBALS._hAskChoice); CORO_INVOKE_2(CoroScheduler.waitForSingleObject, GLOBALS._hDoneChoice, CORO_INFINITE); - /* Now that the choice has been made, we can run the groups associated with the choice tbontbtitq - */ + // Now that the choice has been made, we can run the groups associated with the choice tbontbtitq _ctx->j = GLOBALS._nSelectedChoice; for (_ctx->k = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { _ctx->nGroup = _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); } - /* Control attribute */ + // Control attribute if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 0)) { - /* Bit 0 set: the end of the choice */ + // Bit 0 set: the end of the choice unlockDialogs(); break; } if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 1)) { - /* Bit 1 set: the end of the dialog */ + // Bit 1 set: the end of the dialog unlockDialogs(); CORO_KILL_SELF(); return; } - /* End of choic ewithout attributes. We must do it again */ + // End of choic ewithout attributes. We must do it again } // If we're here, we found an end choice. Return to the caller group @@ -1300,9 +1298,10 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // In the new version number of the action in writing dwRes Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); -/* newitem->Action[0].nCmds=item->Action[i].nCmds; - memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); -*/ + + //newitem->Action[0].nCmds=item->Action[i].nCmds; + //memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); + newitem->dwRes = i; // And finally we can laucnh the process that will execute the action, @@ -1412,15 +1411,15 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, uint32 dwSizeDecomp, dwSizeComp; byte *cmpbuf; - /* Save the array of custom functions */ + // Save the array of custom functions GLOBALS._lplpFunctions = lplpcfArray; GLOBALS._lplpFunctionStrings = lpcfStrings; - /* OPen the MPC file for reading */ + // OPen the MPC file for reading if (!hMpc.open(lpszMpcFileName)) return false; - /* Read and check the header */ + // Read and check the header nBytesRead = hMpc.read(buf, 5); if (nBytesRead != 5) return false; @@ -1430,7 +1429,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, bCompress = buf[4]; - /* Reads the size of the uncompressed file, and allocate memory */ + // Reads the size of the uncompressed file, and allocate memory dwSizeDecomp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1440,7 +1439,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, return false; if (bCompress) { - /* Get the compressed size and read the data in */ + // Get the compressed size and read the data in dwSizeComp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1453,33 +1452,33 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (nBytesRead != dwSizeComp) return false; - /* Decompress the data */ + // Decompress the data lzo1x_decompress(cmpbuf, dwSizeComp, lpMpcImage, &nBytesRead); if (nBytesRead != dwSizeDecomp) return false; globalDestroy(cmpbuf); } else { - /* If the file is not compressed, we directly read in the data */ + // If the file is not compressed, we directly read in the data nBytesRead = hMpc.read(lpMpcImage, dwSizeDecomp); if (nBytesRead != dwSizeDecomp) return false; } - /* Close the file */ + // Close the file hMpc.close(); - /* Process the data */ + // Process the data if (ParseMpc(lpMpcImage) == false) return false; globalDestroy(lpMpcImage); - /* Open the MPR file */ + // Open the MPR file if (!GLOBALS._hMpr.open(lpszMprFileName)) return false; - /* Seek to the end of the file to read overall information */ + // Seek to the end of the file to read overall information GLOBALS._hMpr.seek(-12, SEEK_END); dwSizeComp = GLOBALS._hMpr.readUint32LE(); @@ -1497,7 +1496,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (buf[0] !='E' || buf[1] != 'N' || buf[2] != 'D' || buf[3] != '0') return false; - /* Move to the start of the resources header */ + // Move to the start of the resources header GLOBALS._hMpr.seek(-(12 + (int)dwSizeComp), SEEK_END); GLOBALS._lpResources = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, GLOBALS._nResources * 8); @@ -1518,17 +1517,17 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, globalDestroy(cmpbuf); - /* Reset back to the start of the file, leaving it open */ + // Reset back to the start of the file, leaving it open GLOBALS._hMpr.seek(0, SEEK_SET); - /* There is no action or dialog running by default */ + // There is no action or dialog running by default GLOBALS._bExecutingAction = false; GLOBALS._bExecutingDialog = false; - /* There's no polling location */ + // There's no polling location Common::fill(GLOBALS._nPollingLocations, GLOBALS._nPollingLocations + MAXPOLLINGLOCATIONS, 0); - /* Create the event that will be used to co-ordinate making choices and choices finishing */ + // Create the event that will be used to co-ordinate making choices and choices finishing GLOBALS._hAskChoice = CoroScheduler.createEvent(true, false); GLOBALS._hDoneChoice = CoroScheduler.createEvent(true, false); diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 4c8ca481b0..492889d88a 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -95,7 +95,7 @@ namespace MPAL { * Macro definitions and structures \****************************************************************************/ -/* OK value for the error codes */ +// OK value for the error codes #define OK 0 #define MAXFRAMES 400 // frame animation of an object @@ -119,31 +119,31 @@ enum QueryCoordinates { * that can do at the library */ enum QueryTypes { - /* General Query */ + // General Query MPQ_VERSION=10, MPQ_GLOBAL_VAR=50, MPQ_RESOURCE, MPQ_MESSAGE, - /* Query on leases */ + // Query on leases MPQ_LOCATION_IMAGE=100, MPQ_LOCATION_SIZE, - /* Queries about items */ + // Queries about items MPQ_ITEM_LIST=200, MPQ_ITEM_DATA, MPQ_ITEM_PATTERN, MPQ_ITEM_NAME, MPQ_ITEM_IS_ACTIVE, - /* Query dialog */ + // Query dialog MPQ_DIALOG_PERIOD=300, MPQ_DIALOG_WAITFORCHOICE, MPQ_DIALOG_SELECTLIST, MPQ_DIALOG_SELECTION, - /* Query execution */ + // Query execution MPQ_DO_ACTION=400, MPQ_DO_DIALOG }; -- cgit v1.2.3 From 7fbfbc8e6b57729e1a5008d256b28b0571f1c3b6 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 31 Aug 2012 23:08:02 +0200 Subject: TONY: Rename some more variables and structures --- engines/tony/mpal/loadmpc.cpp | 276 ++++++++++++++++---------------- engines/tony/mpal/loadmpc.h | 4 +- engines/tony/mpal/mpal.cpp | 355 +++++++++++++++++++++--------------------- engines/tony/mpal/mpal.h | 13 +- engines/tony/mpal/mpaldll.h | 170 +++++++++----------- 5 files changed, 397 insertions(+), 421 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 9927f9fe8e..b3c4193414 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -39,15 +39,15 @@ namespace MPAL { * Static functions \****************************************************************************/ -static bool compareCommands(struct command *cmd1, struct command *cmd2) { - if (cmd1->type == 2 && cmd2->type == 2) { - if (strcmp(cmd1->lpszVarName, cmd2->lpszVarName) == 0 && - compareExpressions(cmd1->expr, cmd2->expr)) +static bool compareCommands(struct Command *cmd1, struct Command *cmd2) { + if (cmd1->_type == 2 && cmd2->_type == 2) { + if (strcmp(cmd1->_lpszVarName, cmd2->_lpszVarName) == 0 && + compareExpressions(cmd1->_expr, cmd2->_expr)) return true; else return false; } else - return (memcmp(cmd1, cmd2, sizeof(struct command)) == 0); + return (memcmp(cmd1, cmd2, sizeof(struct Command)) == 0); } /** @@ -58,25 +58,25 @@ static bool compareCommands(struct command *cmd1, struct command *cmd2) { * data of the script. * @returns Pointer to the buffer after the item, or NULL on failure. */ -static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { - lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf); +static const byte *ParseScript(const byte *lpBuf, LpMpalScript lpmsScript) { + lpmsScript->_nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->nMoments = READ_LE_UINT16(lpBuf); + lpmsScript->_nMoments = READ_LE_UINT16(lpBuf); lpBuf += 2; int curCmd = 0; - for (uint i = 0; i < lpmsScript->nMoments; i++) { - lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); + for (uint i = 0; i < lpmsScript->_nMoments; i++) { + lpmsScript->_moment[i]._dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmsScript->Moment[i].nCmds = *lpBuf; + lpmsScript->_moment[i]._nCmds = *lpBuf; lpBuf++; - for (int j = 0; j < lpmsScript->Moment[i].nCmds; j++) { - lpmsScript->_command[curCmd].type = *lpBuf; + for (int j = 0; j < lpmsScript->_moment[i]._nCmds; j++) { + lpmsScript->_command[curCmd]._type = *lpBuf; lpBuf++; - switch (lpmsScript->_command[curCmd].type) { + switch (lpmsScript->_command[curCmd]._type) { case 1: lpmsScript->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -93,13 +93,13 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { case 2: { // Variable assign int len = *lpBuf; lpBuf++; - lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmsScript->_command[curCmd].lpszVarName == NULL) + lpmsScript->_command[curCmd]._lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmsScript->_command[curCmd]._lpszVarName == NULL) return NULL; - memcpy(lpmsScript->_command[curCmd].lpszVarName, lpBuf, len); + memcpy(lpmsScript->_command[curCmd]._lpszVarName, lpBuf, len); lpBuf += len; - lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmsScript->_command[curCmd]._expr); if (lpBuf == NULL) return NULL; break; @@ -108,7 +108,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { return NULL; } - lpmsScript->Moment[i].CmdNum[j] = curCmd; + lpmsScript->_moment[i]._cmdNum[j] = curCmd; curCmd++; } } @@ -120,12 +120,12 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { * * @param lpmsScript Pointer to a script structure */ -static void FreeScript(LPMPALSCRIPT lpmsScript) { - for (int i = 0; i < MAX_COMMANDS_PER_SCRIPT && (lpmsScript->_command[i].type); ++i, ++lpmsScript) { - if (lpmsScript->_command[i].type == 2) { +static void FreeScript(LpMpalScript lpmsScript) { + for (int i = 0; i < MAX_COMMANDS_PER_SCRIPT && (lpmsScript->_command[i]._type); ++i, ++lpmsScript) { + if (lpmsScript->_command[i]._type == 2) { // Variable Assign - globalDestroy(lpmsScript->_command[i].lpszVarName); - freeExpression(lpmsScript->_command[i].expr); + globalDestroy(lpmsScript->_command[i]._lpszVarName); + freeExpression(lpmsScript->_command[i]._expr); } } } @@ -138,11 +138,11 @@ static void FreeScript(LPMPALSCRIPT lpmsScript) { * data of the dialog. * @returns Pointer to the buffer after the item, or NULL on failure. */ -static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { +static const byte *parseDialog(const byte *lpBuf, LpMpalDialog lpmdDialog) { uint32 num2, num3; byte *lpLock; - lpmdDialog->nObj = READ_LE_UINT32(lpBuf); + lpmdDialog->_nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; // Periods @@ -150,7 +150,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { lpBuf += 2; if (num >= MAX_PERIODS_PER_DIALOG - 1) - error("Too much periods in dialog #%d", lpmdDialog->nObj); + error("Too much periods in dialog #%d", lpmdDialog->_nObj); uint32 i; for (i = 0; i < num; i++) { @@ -172,21 +172,21 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 curCmd = 0; if (num >= MAX_GROUPS_PER_DIALOG) - error("Too much groups in dialog #%d", lpmdDialog->nObj); + error("Too much groups in dialog #%d", lpmdDialog->_nObj); for (i = 0; i < num; i++) { - lpmdDialog->_group[i].num = READ_LE_UINT16(lpBuf); + lpmdDialog->_group[i]._num = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmdDialog->_group[i].nCmds = *lpBuf; lpBuf++; + lpmdDialog->_group[i]._nCmds = *lpBuf; lpBuf++; - if (lpmdDialog->_group[i].nCmds >= MAX_COMMANDS_PER_GROUP) - error("Too much commands in group #%d in dialog #%d",lpmdDialog->_group[i].num,lpmdDialog->nObj); + if (lpmdDialog->_group[i]._nCmds >= MAX_COMMANDS_PER_GROUP) + error("Too much commands in group #%d in dialog #%d", lpmdDialog->_group[i]._num, lpmdDialog->_nObj); - for (uint32 j = 0; j < lpmdDialog->_group[i].nCmds; j++) { - lpmdDialog->_command[curCmd].type = *lpBuf; + for (uint32 j = 0; j < lpmdDialog->_group[i]._nCmds; j++) { + lpmdDialog->_command[curCmd]._type = *lpBuf; lpBuf++; - switch (lpmdDialog->_command[curCmd].type) { + switch (lpmdDialog->_command[curCmd]._type) { // Call custom function case 1: lpmdDialog->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); @@ -205,21 +205,21 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { case 2: { uint32 len = *lpBuf; lpBuf++; - lpmdDialog->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmdDialog->_command[curCmd].lpszVarName == NULL) + lpmdDialog->_command[curCmd]._lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmdDialog->_command[curCmd]._lpszVarName == NULL) return NULL; - Common::copy(lpBuf, lpBuf + len, lpmdDialog->_command[curCmd].lpszVarName); + Common::copy(lpBuf, lpBuf + len, lpmdDialog->_command[curCmd]._lpszVarName); lpBuf += len; - lpBuf = parseExpression(lpBuf, &lpmdDialog->_command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmdDialog->_command[curCmd]._expr); if (lpBuf == NULL) return NULL; break; } // Do Choice case 3: - lpmdDialog->_command[curCmd].nChoice = READ_LE_UINT16(lpBuf); + lpmdDialog->_command[curCmd]._nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; break; @@ -230,56 +230,56 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { uint32 kk; for (kk = 0;kk < curCmd; kk++) { if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) { - lpmdDialog->_group[i].CmdNum[j] = kk; + lpmdDialog->_group[i]._cmdNum[j] = kk; // Free any data allocated for the duplictaed command - if (lpmdDialog->_command[curCmd].type == 2) { - globalDestroy(lpmdDialog->_command[curCmd].lpszVarName); - freeExpression(lpmdDialog->_command[curCmd].expr); + if (lpmdDialog->_command[curCmd]._type == 2) { + globalDestroy(lpmdDialog->_command[curCmd]._lpszVarName); + freeExpression(lpmdDialog->_command[curCmd]._expr); - lpmdDialog->_command[curCmd].lpszVarName = NULL; - lpmdDialog->_command[curCmd].expr = 0; - lpmdDialog->_command[curCmd].type = 0; + lpmdDialog->_command[curCmd]._lpszVarName = NULL; + lpmdDialog->_command[curCmd]._expr = 0; + lpmdDialog->_command[curCmd]._type = 0; } break; } } if (kk == curCmd) { - lpmdDialog->_group[i].CmdNum[j] = curCmd; + lpmdDialog->_group[i]._cmdNum[j] = curCmd; curCmd++; } } } if (curCmd >= MAX_COMMANDS_PER_DIALOG) - error("Too much commands in dialog #%d",lpmdDialog->nObj); + error("Too much commands in dialog #%d",lpmdDialog->_nObj); // Choices num = READ_LE_UINT16(lpBuf); lpBuf += 2; if (num >= MAX_CHOICES_PER_DIALOG) - error("Too much choices in dialog #%d",lpmdDialog->nObj); + error("Too much choices in dialog #%d",lpmdDialog->_nObj); for (i = 0; i < num; i++) { - lpmdDialog->_choice[i].nChoice = READ_LE_UINT16(lpBuf); + lpmdDialog->_choice[i]._nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; num2 = *lpBuf++; if (num2 >= MAX_SELECTS_PER_CHOICE) - error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); + error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i]._nChoice, lpmdDialog->_nObj); for (uint32 j = 0; j < num2; j++) { // When switch (*lpBuf++) { case 0: - lpmdDialog->_choice[i]._select[j].when = NULL; + lpmdDialog->_choice[i]._select[j]._when = NULL; break; case 1: - lpBuf = parseExpression(lpBuf, &lpmdDialog->_choice[i]._select[j].when); + lpBuf = parseExpression(lpBuf, &lpmdDialog->_choice[i]._select[j]._when); if (lpBuf == NULL) return NULL; break; @@ -289,31 +289,31 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { } // Attrib - lpmdDialog->_choice[i]._select[j].attr = *lpBuf++; + lpmdDialog->_choice[i]._select[j]._attr = *lpBuf++; // Data - lpmdDialog->_choice[i]._select[j].dwData = READ_LE_UINT32(lpBuf); + lpmdDialog->_choice[i]._select[j]._dwData = READ_LE_UINT32(lpBuf); lpBuf += 4; // PlayGroup num3 = *lpBuf++; if (num3 >= MAX_PLAYGROUPS_PER_SELECT) - error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); + error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i]._nChoice, lpmdDialog->_nObj); for (uint32 z = 0; z < num3; z++) { - lpmdDialog->_choice[i]._select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); + lpmdDialog->_choice[i]._select[j]._wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; } - lpmdDialog->_choice[i]._select[j].wPlayGroup[num3] = 0; + lpmdDialog->_choice[i]._select[j]._wPlayGroup[num3] = 0; } // Mark the last selection - lpmdDialog->_choice[i]._select[num2].dwData = 0; + lpmdDialog->_choice[i]._select[num2]._dwData = 0; } - lpmdDialog->_choice[num].nChoice = 0; + lpmdDialog->_choice[num]._nChoice = 0; return lpBuf; } @@ -329,63 +329,63 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { * @remarks It's necessary that the structure that is passed has been * completely initialized to 0 beforehand. */ -static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { - lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf); +static const byte *parseItem(const byte *lpBuf, LpMpalItem lpmiItem) { + lpmiItem->_nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; byte len = *lpBuf; lpBuf++; - memcpy(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); + memcpy(lpmiItem->_lpszDescribe, lpBuf, MIN((byte)127, len)); lpBuf += len; if (len >= MAX_DESCRIBE_SIZE) - error("Describe too long in item #%d", lpmiItem->nObj); + error("Describe too long in item #%d", lpmiItem->_nObj); - lpmiItem->nActions=*lpBuf; + lpmiItem->_nActions=*lpBuf; lpBuf++; // Allocation action - if (lpmiItem->nActions > 0) - lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); + if (lpmiItem->_nActions > 0) + lpmiItem->_action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->_nActions); uint32 curCmd = 0; - for (uint32 i = 0; i < lpmiItem->nActions; i++) { - lpmiItem->Action[i].num = *lpBuf; + for (uint32 i = 0; i < lpmiItem->_nActions; i++) { + lpmiItem->_action[i]._num = *lpBuf; lpBuf++; - lpmiItem->Action[i].wParm = READ_LE_UINT16(lpBuf); + lpmiItem->_action[i]._wParm = READ_LE_UINT16(lpBuf); lpBuf += 2; - if (lpmiItem->Action[i].num == 0xFF) { - lpmiItem->Action[i].wTime = READ_LE_UINT16(lpBuf); + if (lpmiItem->_action[i]._num == 0xFF) { + lpmiItem->_action[i]._wTime = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmiItem->Action[i].perc = *lpBuf; + lpmiItem->_action[i]._perc = *lpBuf; lpBuf++; } if (*lpBuf == 0) { lpBuf++; - lpmiItem->Action[i].when = NULL; + lpmiItem->_action[i]._when = NULL; } else { lpBuf++; - lpBuf = parseExpression(lpBuf,&lpmiItem->Action[i].when); + lpBuf = parseExpression(lpBuf,&lpmiItem->_action[i]._when); if (lpBuf == NULL) return NULL; } - lpmiItem->Action[i].nCmds=*lpBuf; + lpmiItem->_action[i]._nCmds=*lpBuf; lpBuf++; - if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) - error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); + if (lpmiItem->_action[i]._nCmds >= MAX_COMMANDS_PER_ACTION) + error("Too much commands in action #%d in item #%d",lpmiItem->_action[i]._num, lpmiItem->_nObj); - for (uint32 j = 0; j < lpmiItem->Action[i].nCmds; j++) { - lpmiItem->_command[curCmd].type = *lpBuf; + for (uint32 j = 0; j < lpmiItem->_action[i]._nCmds; j++) { + lpmiItem->_command[curCmd]._type = *lpBuf; lpBuf++; - switch (lpmiItem->_command[curCmd].type) { + switch (lpmiItem->_command[curCmd]._type) { case 1: // Call custom function lpmiItem->_command[curCmd]._nCf = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -402,13 +402,13 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { case 2: // Variable assign len = *lpBuf; lpBuf++; - lpmiItem->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); - if (lpmiItem->_command[curCmd].lpszVarName == NULL) + lpmiItem->_command[curCmd]._lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); + if (lpmiItem->_command[curCmd]._lpszVarName == NULL) return NULL; - memcpy(lpmiItem->_command[curCmd].lpszVarName, lpBuf, len); + memcpy(lpmiItem->_command[curCmd]._lpszVarName, lpBuf, len); lpBuf += len; - lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd].expr); + lpBuf = parseExpression(lpBuf, &lpmiItem->_command[curCmd]._expr); if (lpBuf == NULL) return NULL; break; @@ -420,34 +420,34 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { uint32 kk; for (kk = 0; kk < curCmd; kk++) { if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) { - lpmiItem->Action[i].CmdNum[j] = kk; + lpmiItem->_action[i]._cmdNum[j] = kk; // Free any data allocated for the duplictaed command - if (lpmiItem->_command[curCmd].type == 2) { - globalDestroy(lpmiItem->_command[curCmd].lpszVarName); - freeExpression(lpmiItem->_command[curCmd].expr); + if (lpmiItem->_command[curCmd]._type == 2) { + globalDestroy(lpmiItem->_command[curCmd]._lpszVarName); + freeExpression(lpmiItem->_command[curCmd]._expr); - lpmiItem->_command[curCmd].lpszVarName = NULL; - lpmiItem->_command[curCmd].expr = 0; - lpmiItem->_command[curCmd].type = 0; + lpmiItem->_command[curCmd]._lpszVarName = NULL; + lpmiItem->_command[curCmd]._expr = 0; + lpmiItem->_command[curCmd]._type = 0; } break; } } if (kk == curCmd) { - lpmiItem->Action[i].CmdNum[j] = curCmd; + lpmiItem->_action[i]._cmdNum[j] = curCmd; curCmd++; if (curCmd >= MAX_COMMANDS_PER_ITEM) { - error("Too much commands in item #%d",lpmiItem->nObj); + error("Too much commands in item #%d", lpmiItem->_nObj); //curCmd=0; } } } } - lpmiItem->dwRes = READ_LE_UINT32(lpBuf); + lpmiItem->_dwRes = READ_LE_UINT32(lpBuf); lpBuf += 4; return lpBuf; @@ -458,23 +458,23 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { * * @param lpmiItem Pointer to an item structure */ -static void freeItem(LPMPALITEM lpmiItem) { +static void freeItem(LpMpalItem lpmiItem) { // Free the actions - if (lpmiItem->Action) { - for (int i = 0; i < lpmiItem->nActions; ++i) { - if (lpmiItem->Action[i].when != 0) - freeExpression(lpmiItem->Action[i].when); + if (lpmiItem->_action) { + for (int i = 0; i < lpmiItem->_nActions; ++i) { + if (lpmiItem->_action[i]._when != 0) + freeExpression(lpmiItem->_action[i]._when); } - globalDestroy(lpmiItem->Action); + globalDestroy(lpmiItem->_action); } // Free the commands - for (int i = 0; i < MAX_COMMANDS_PER_ITEM && (lpmiItem->_command[i].type); ++i) { - if (lpmiItem->_command[i].type == 2) { + for (int i = 0; i < MAX_COMMANDS_PER_ITEM && (lpmiItem->_command[i]._type); ++i) { + if (lpmiItem->_command[i]._type == 2) { // Variable Assign - globalDestroy(lpmiItem->_command[i].lpszVarName); - freeExpression(lpmiItem->_command[i].expr); + globalDestroy(lpmiItem->_command[i]._lpszVarName); + freeExpression(lpmiItem->_command[i]._expr); } } } @@ -487,14 +487,14 @@ static void freeItem(LPMPALITEM lpmiItem) { * data of the location. * @returns Pointer to the buffer after the location, or NULL on failure. */ -static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) { - lpmlLocation->nObj = (int32)READ_LE_UINT32(lpBuf); +static const byte *ParseLocation(const byte *lpBuf, LpMpalLocation lpmlLocation) { + lpmlLocation->_nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - lpmlLocation->dwXlen = READ_LE_UINT16(lpBuf); + lpmlLocation->_dwXlen = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmlLocation->dwYlen = READ_LE_UINT16(lpBuf); + lpmlLocation->_dwYlen = READ_LE_UINT16(lpBuf); lpBuf += 2; - lpmlLocation->dwPicRes = READ_LE_UINT32(lpBuf); + lpmlLocation->_dwPicRes = READ_LE_UINT32(lpBuf); lpBuf += 4; return lpBuf; @@ -516,7 +516,7 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) * @param lpBuf Buffer containing the MPC file data, excluding the header. * @returns True if succeeded OK, false if failure. */ -bool ParseMpc(const byte *lpBuf) { +bool parseMpc(const byte *lpBuf) { byte *lpTemp; // 1. Variables @@ -527,18 +527,18 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._nVars = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS._hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALVAR) * (uint32)GLOBALS._nVars); + GLOBALS._hVars = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MpalVar) * (uint32)GLOBALS._nVars); if (GLOBALS._hVars == NULL) return false; - GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); + GLOBALS._lpmvVars = (LpMpalVar)globalLock(GLOBALS._hVars); for (uint16 i = 0; i < GLOBALS._nVars; i++) { uint16 wLen = *(const byte *)lpBuf; lpBuf++; - memcpy(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); + memcpy(GLOBALS._lpmvVars->_lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; - GLOBALS._lpmvVars->dwVal = READ_LE_UINT32(lpBuf); + GLOBALS._lpmvVars->_dwVal = READ_LE_UINT32(lpBuf); lpBuf += 4; lpBuf++; // Skip 'ext' @@ -556,11 +556,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; #ifdef NEED_LOCK_MSGS - GLOBALS._hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS._nMsgs); + GLOBALS._hMsgs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(MpalMsg) * (uint32)GLOBALS._nMsgs); if (GLOBALS._hMsgs == NULL) return false; - GLOBALS._lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); + GLOBALS._lpmmMsgs = (LpMpalMsg)globalLock(GLOBALS._hMsgs); #else GLOBALS._lpmmMsgs=(LPMPALMSG)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALMSG) * (uint32)GLOBALS._nMsgs); if (GLOBALS._lpmmMsgs==NULL) @@ -611,11 +611,11 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._nDialogs = READ_LE_UINT16(lpBuf); lpBuf += 2; - GLOBALS._hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nDialogs * sizeof(MPALDIALOG)); + GLOBALS._hDialogs = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nDialogs * sizeof(MpalDialog)); if (GLOBALS._hDialogs == NULL) return false; - GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); + GLOBALS._lpmdDialogs = (LpMpalDialog)globalLock(GLOBALS._hDialogs); for (uint16 i = 0; i < GLOBALS._nDialogs; i++) { if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS._lpmdDialogs[i])) == NULL) @@ -633,11 +633,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS._hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nItems * sizeof(MPALITEM)); + GLOBALS._hItems = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nItems * sizeof(MpalItem)); if (GLOBALS._hItems == NULL) return false; - GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); + GLOBALS._lpmiItems = (LpMpalItem)globalLock(GLOBALS._hItems); for (uint16 i = 0; i < GLOBALS._nItems; i++) { if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS._lpmiItems[i])) == NULL) @@ -655,11 +655,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory and read them in - GLOBALS._hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nLocations * sizeof(MPALLOCATION)); + GLOBALS._hLocations = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nLocations * sizeof(MpalLocation)); if (GLOBALS._hLocations == NULL) return false; - GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); + GLOBALS._lpmlLocations = (LpMpalLocation)globalLock(GLOBALS._hLocations); for (uint16 i = 0; i < GLOBALS._nLocations; i++) { if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS._lpmlLocations[i])) == NULL) @@ -677,11 +677,11 @@ bool ParseMpc(const byte *lpBuf) { lpBuf += 2; // Allocate memory - GLOBALS._hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nScripts * sizeof(MPALSCRIPT)); + GLOBALS._hScripts = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, (uint32)GLOBALS._nScripts * sizeof(MpalScript)); if (GLOBALS._hScripts == NULL) return false; - GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); + GLOBALS._lpmsScripts = (LpMpalScript)globalLock(GLOBALS._hScripts); for (uint16 i = 0; i < GLOBALS._nScripts; i++) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS._lpmsScripts[i])) == NULL) @@ -708,24 +708,24 @@ bool ParseMpc(const byte *lpBuf) { /** * Free the given dialog */ -static void freeDialog(LPMPALDIALOG lpmdDialog) { +static void freeDialog(LpMpalDialog lpmdDialog) { // Free the periods for (int i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) globalFree(lpmdDialog->_periods[i]); - for (int i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { - if (lpmdDialog->_command[i].type == 2) { + for (int i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i]._type); i++) { + if (lpmdDialog->_command[i]._type == 2) { // Variable assign - globalDestroy(lpmdDialog->_command[i].lpszVarName); - freeExpression(lpmdDialog->_command[i].expr); + globalDestroy(lpmdDialog->_command[i]._lpszVarName); + freeExpression(lpmdDialog->_command[i]._expr); } } // Free the choices for (int i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { for (int j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { - if (lpmdDialog->_choice[i]._select[j].when) - freeExpression(lpmdDialog->_choice[i]._select[j].when); + if (lpmdDialog->_choice[i]._select[j]._when) + freeExpression(lpmdDialog->_choice[i]._select[j]._when); } } } @@ -733,12 +733,12 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { /** * Frees any data allocated from the parsing of the MPC file */ -void FreeMpc() { +void freeMpc() { // Free variables globalFree(GLOBALS._hVars); // Free messages - LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); + LpMpalMsg lpmmMsgs = (LpMpalMsg)globalLock(GLOBALS._hMsgs); for (int i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) globalFree(lpmmMsgs->_hText); @@ -747,7 +747,7 @@ void FreeMpc() { // Free objects if (GLOBALS._hDialogs) { - LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); + LpMpalDialog lpmdDialogs = (LpMpalDialog)globalLock(GLOBALS._hDialogs); for (int i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) freeDialog(lpmdDialogs); @@ -757,7 +757,7 @@ void FreeMpc() { // Free items if (GLOBALS._hItems) { - LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); + LpMpalItem lpmiItems = (LpMpalItem)globalLock(GLOBALS._hItems); for (int i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) freeItem(lpmiItems); @@ -773,7 +773,7 @@ void FreeMpc() { // Free the scripts if (GLOBALS._hScripts) { - LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); + LpMpalScript lpmsScripts = (LpMpalScript)globalLock(GLOBALS._hScripts); for (int i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { FreeScript(lpmsScripts); diff --git a/engines/tony/mpal/loadmpc.h b/engines/tony/mpal/loadmpc.h index c0e2ca7fb5..20956288aa 100644 --- a/engines/tony/mpal/loadmpc.h +++ b/engines/tony/mpal/loadmpc.h @@ -44,12 +44,12 @@ namespace MPAL { * @param lpBuf Buffer containing the MPC file data, excluding the header. * @returns True if succeeded OK, false if failure. */ -bool ParseMpc(const byte *lpBuf); +bool parseMpc(const byte *lpBuf); /** * Frees any data allocated from the parsing of the MPC file */ -void FreeMpc(); +void freeMpc(); } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 514001eda7..9a92fd7766 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -60,7 +60,7 @@ const char *mpalCopyright = * Locks the variables for access */ void lockVar() { - GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); + GLOBALS._lpmvVars = (LpMpalVar)globalLock(GLOBALS._hVars); } /** @@ -75,7 +75,7 @@ void unlockVar() { */ static void LockMsg() { #ifdef NEED_LOCK_MSGS - GLOBALS._lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); + GLOBALS._lpmmMsgs = (LpMpalMsg)globalLock(GLOBALS._hMsgs); #endif } @@ -92,7 +92,7 @@ static void UnlockMsg() { * Locks the dialogs for access */ static void lockDialogs() { - GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); + GLOBALS._lpmdDialogs = (LpMpalDialog)globalLock(GLOBALS._hDialogs); } /** @@ -106,7 +106,7 @@ static void unlockDialogs() { * Locks the location data structures for access */ static void lockLocations() { - GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); + GLOBALS._lpmlLocations = (LpMpalLocation)globalLock(GLOBALS._hLocations); } /** @@ -120,7 +120,7 @@ static void unlockLocations() { * Locks the items structures for use */ static void lockItems() { - GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); + GLOBALS._lpmiItems = (LpMpalItem)globalLock(GLOBALS._hItems); } /** @@ -134,7 +134,7 @@ static void unlockItems() { * Locks the script data structures for use */ static void LockScripts() { - GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); + GLOBALS._lpmsScripts = (LpMpalScript)globalLock(GLOBALS._hScripts); } /** @@ -154,11 +154,11 @@ static void unlockScripts() { * need to remember to call UnlockVar() */ int32 varGetValue(const char *lpszVarName) { - LPMPALVAR v = GLOBALS._lpmvVars; + LpMpalVar v = GLOBALS._lpmvVars; for (int i = 0; i < GLOBALS._nVars; v++, i++) - if (strcmp(lpszVarName, v->lpszVarName) == 0) - return v->dwVal; + if (strcmp(lpszVarName, v->_lpszVarName) == 0) + return v->_dwVal; GLOBALS._mpalError = 1; return 0; @@ -170,18 +170,18 @@ int32 varGetValue(const char *lpszVarName) { * @param val Value to set */ void varSetValue(const char *lpszVarName, int32 val) { - LPMPALVAR v = GLOBALS._lpmvVars; + LpMpalVar v = GLOBALS._lpmvVars; for (uint i = 0; i < GLOBALS._nVars; v++, i++) - if (strcmp(lpszVarName, v->lpszVarName) == 0) { - v->dwVal = val; - if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { + if (strcmp(lpszVarName, v->_lpszVarName) == 0) { + v->_dwVal = val; + if (GLOBALS._lpiifCustom != NULL && strncmp(v->_lpszVarName, "Pattern.", 8) == 0) { i = 0; - sscanf(v->lpszVarName, "Pattern.%u", &i); + sscanf(v->_lpszVarName, "Pattern.%u", &i); GLOBALS._lpiifCustom(i, val, -1); - } else if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Status.", 7) == 0) { + } else if (GLOBALS._lpiifCustom != NULL && strncmp(v->_lpszVarName, "Status.", 7) == 0) { i = 0; - sscanf(v->lpszVarName,"Status.%u", &i); + sscanf(v->_lpszVarName,"Status.%u", &i); GLOBALS._lpiifCustom(i, -1, val); } return; @@ -200,10 +200,10 @@ void varSetValue(const char *lpszVarName, int32 val) { * first been locked with a call to LockLoc(). */ static int locGetOrderFromNum(uint32 nLoc) { - LPMPALLOCATION loc = GLOBALS._lpmlLocations; + LpMpalLocation loc = GLOBALS._lpmlLocations; for (int i = 0; i < GLOBALS._nLocations; i++, loc++) - if (loc->nObj == nLoc) + if (loc->_nObj == nLoc) return i; return -1; @@ -218,7 +218,7 @@ static int locGetOrderFromNum(uint32 nLoc) { * first been locked with a call to LockMsg() */ static int msgGetOrderFromNum(uint32 nMsg) { - LPMPALMSG msg = GLOBALS._lpmmMsgs; + LpMpalMsg msg = GLOBALS._lpmmMsgs; for (int i = 0; i < GLOBALS._nMsgs; i++, msg++) { if (msg->_wNum == nMsg) @@ -236,10 +236,10 @@ static int msgGetOrderFromNum(uint32 nMsg) { * first been locked with a call to LockItems() */ static int itemGetOrderFromNum(uint32 nItem) { - LPMPALITEM item = GLOBALS._lpmiItems; + LpMpalItem item = GLOBALS._lpmiItems; for (int i = 0; i < GLOBALS._nItems; i++, item++) { - if (item->nObj == nItem) + if (item->_nObj == nItem) return i; } @@ -255,10 +255,10 @@ static int itemGetOrderFromNum(uint32 nItem) { * first been locked with a call to LockScripts() */ static int scriptGetOrderFromNum(uint32 nScript) { - LPMPALSCRIPT script = GLOBALS._lpmsScripts; + LpMpalScript script = GLOBALS._lpmsScripts; for (int i = 0; i < GLOBALS._nScripts; i++, script++) { - if (script->nObj == nScript) + if (script->_nObj == nScript) return i; } @@ -274,10 +274,10 @@ static int scriptGetOrderFromNum(uint32 nScript) { * first been locked with a call to LockDialogs() */ static int dialogGetOrderFromNum(uint32 nDialog) { - LPMPALDIALOG dialog = GLOBALS._lpmdDialogs; + LpMpalDialog dialog = GLOBALS._lpmdDialogs; for (int i = 0; i < GLOBALS._nDialogs; i++, dialog++) { - if (dialog->nObj == nDialog) + if (dialog->_nObj == nDialog) return i; } @@ -326,7 +326,7 @@ static char *DuplicateMessage(uint32 nMsgOrd) { static char *duplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; - LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; + LpMpalDialog dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; for (int j = 0; dialog->_periods[j] != NULL; j++) { if (dialog->_periodNums[j] == nPeriod) { @@ -386,7 +386,7 @@ HGLOBAL resLoad(uint32 dwId) { h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, nSizeDecomp + (nSizeDecomp / 1024) * 16); buf = (byte *)globalLock(h); - temp = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT,nSizeComp); + temp = (byte *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, nSizeComp); nBytesRead = GLOBALS._hMpr.read(temp, nSizeComp); if (nBytesRead != nSizeComp) @@ -406,12 +406,12 @@ HGLOBAL resLoad(uint32 dwId) { static uint32 *getSelectList(uint32 i) { uint32 *sl; - LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; + LpMpalDialog dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; // Count how many are active selects int num = 0; - for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { - if (dialog->_choice[i]._select[j].curActive) + for (int j = 0; dialog->_choice[i]._select[j]._dwData != 0; j++) { + if (dialog->_choice[i]._select[j]._curActive) num++; } @@ -425,9 +425,9 @@ static uint32 *getSelectList(uint32 i) { // Copy all the data inside the active select list int k = 0; - for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { - if (dialog->_choice[i]._select[j].curActive) - sl[k++] = dialog->_choice[i]._select[j].dwData; + for (int j = 0; dialog->_choice[i]._select[j]._dwData != 0; j++) { + if (dialog->_choice[i]._select[j]._curActive) + sl[k++] = dialog->_choice[i]._select[j]._dwData; } sl[k] = (uint32)NULL; @@ -436,11 +436,11 @@ static uint32 *getSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; - LPMPALVAR v = GLOBALS._lpmvVars; + LpMpalVar v = GLOBALS._lpmvVars; uint32 num = 0; for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { - if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) + if (strncmp(v->_lpszVarName, "Location", 8) == 0 && v->_dwVal == nLoc) num++; } @@ -451,8 +451,8 @@ static uint32 *GetItemList(uint32 nLoc) { v = GLOBALS._lpmvVars; uint32 j = 0; for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { - if (strncmp(v->lpszVarName, "Location", 8) == 0 && v->dwVal == nLoc) { - sscanf(v->lpszVarName, "Location.%u", &il[j]); + if (strncmp(v->_lpszVarName, "Location", 8) == 0 && v->_dwVal == nLoc) { + sscanf(v->_lpszVarName, "Location.%u", &il[j]); j++; } } @@ -462,7 +462,7 @@ static uint32 *GetItemList(uint32 nLoc) { } static LPITEM getItemData(uint32 nOrdItem) { - LPMPALITEM curitem = GLOBALS._lpmiItems + nOrdItem; + LpMpalItem curitem = GLOBALS._lpmiItems + nOrdItem; LPITEM ret; HGLOBAL hDat; char *dat; @@ -474,7 +474,7 @@ static LPITEM getItemData(uint32 nOrdItem) { return NULL; ret->_speed = 150; - hDat = resLoad(curitem->dwRes); + hDat = resLoad(curitem->_dwRes); dat = (char *)globalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { @@ -597,7 +597,7 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_END_CONTEXT(_ctx); static uint32 cfHandles[MAX_COMMANDS_PER_MOMENT]; - LPMPALSCRIPT s = *(const LPMPALSCRIPT *)param; + LpMpalScript s = *(const LpMpalScript *)param; CORO_BEGIN_CODE(_ctx); @@ -605,24 +605,24 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->numHandles = 0; // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); - for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) { + for (_ctx->i = 0; _ctx->i < s->_nMoments; _ctx->i++) { // Sleep for the required time - if (s->Moment[_ctx->i].dwTime == -1) { + if (s->_moment[_ctx->i]._dwTime == -1) { CORO_INVOKE_4(CoroScheduler.waitForMultipleObjects, _ctx->numHandles, cfHandles, true, CORO_INFINITE); _ctx->dwStartTime = g_vm->getTime(); } else { _ctx->dwCurTime = g_vm->getTime(); - if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) { + if (_ctx->dwCurTime < _ctx->dwStartTime + (s->_moment[_ctx->i]._dwTime * 100)) { // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); - CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime); + CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->_moment[_ctx->i]._dwTime * 100) - _ctx->dwCurTime); } } _ctx->numHandles = 0; - for (_ctx->j = 0; _ctx->j < s->Moment[_ctx->i].nCmds; _ctx->j++) { - _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j]; + for (_ctx->j = 0; _ctx->j < s->_moment[_ctx->i]._nCmds; _ctx->j++) { + _ctx->k = s->_moment[_ctx->i]._cmdNum[_ctx->j]; - if (s->_command[_ctx->k].type == 1) { + if (s->_command[_ctx->k]._type == 1) { _ctx->p = (LPCFCALL)globalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) { GLOBALS._mpalError = 1; @@ -644,11 +644,11 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_KILL_SELF(); return; } - } else if (s->_command[_ctx->k].type == 2) { + } else if (s->_command[_ctx->k]._type == 2) { lockVar(); varSetValue( - s->_command[_ctx->k].lpszVarName, - evaluateExpression(s->_command[_ctx->k].expr) + s->_command[_ctx->k]._lpszVarName, + evaluateExpression(s->_command[_ctx->k]._expr) ); unlockVar(); @@ -681,7 +681,7 @@ void ActionThread(CORO_PARAM, const void *param) { // COROUTINE CORO_BEGIN_CONTEXT; int j, k; - LPMPALITEM item; + LpMpalItem item; ~CoroContextTag() { if (item) @@ -693,13 +693,13 @@ void ActionThread(CORO_PARAM, const void *param) { // The ActionThread owns the data block pointed to, so we need to make sure it's // freed when the process exits - _ctx->item = *(LPMPALITEM *)param; + _ctx->item = *(LpMpalItem *)param; GLOBALS._mpalError = 0; - for (_ctx->j = 0; _ctx->j < _ctx->item->Action[_ctx->item->dwRes].nCmds; _ctx->j++) { - _ctx->k = _ctx->item->Action[_ctx->item->dwRes].CmdNum[_ctx->j]; + for (_ctx->j = 0; _ctx->j < _ctx->item->_action[_ctx->item->_dwRes]._nCmds; _ctx->j++) { + _ctx->k = _ctx->item->_action[_ctx->item->_dwRes]._cmdNum[_ctx->j]; - if (_ctx->item->_command[_ctx->k].type == 1) { + if (_ctx->item->_command[_ctx->k]._type == 1) { // Custom function debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Call=%s params=%d,%d,%d,%d", CoroScheduler.getCurrentPID(), GLOBALS._lplpFunctionStrings[_ctx->item->_command[_ctx->k]._nCf].c_str(), @@ -714,13 +714,13 @@ void ActionThread(CORO_PARAM, const void *param) { _ctx->item->_command[_ctx->k]._arg4 ); - } else if (_ctx->item->_command[_ctx->k].type == 2) { + } else if (_ctx->item->_command[_ctx->k]._type == 2) { // Variable assign debugC(DEBUG_DETAILED, kTonyDebugActions, "Action Process %d Variable=%s", - CoroScheduler.getCurrentPID(), _ctx->item->_command[_ctx->k].lpszVarName); + CoroScheduler.getCurrentPID(), _ctx->item->_command[_ctx->k]._lpszVarName); lockVar(); - varSetValue(_ctx->item->_command[_ctx->k].lpszVarName, evaluateExpression(_ctx->item->_command[_ctx->k].expr)); + varSetValue(_ctx->item->_command[_ctx->k]._lpszVarName, evaluateExpression(_ctx->item->_command[_ctx->k]._expr)); unlockVar(); } else { @@ -775,20 +775,19 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { */ void LocationPollThread(CORO_PARAM, const void *param) { typedef struct { - uint32 nItem, nAction; - - uint16 wTime; - byte perc; - HGLOBAL when; - byte nCmds; - uint16 CmdNum[MAX_COMMANDS_PER_ACTION]; - - uint32 dwLastTime; + uint32 _nItem, _nAction; + + uint16 _wTime; + byte _perc; + HGLOBAL _when; + byte _nCmds; + uint16 _cmdNum[MAX_COMMANDS_PER_ACTION]; + uint32 _dwLastTime; } MYACTION; typedef struct { - uint32 nItem; - uint32 hThread; + uint32 _nItem; + uint32 _hThread; } MYTHREAD; CORO_BEGIN_CONTEXT; @@ -796,7 +795,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { int i, j, k; int numitems; int nRealItems; - LPMPALITEM curItem,newItem; + LpMpalItem curItem,newItem; int nIdleActions; uint32 curTime; uint32 dwSleepTime; @@ -805,15 +804,15 @@ void LocationPollThread(CORO_PARAM, const void *param) { bool delayExpired; bool expired; - MYACTION *MyActions; - MYTHREAD *MyThreads; + MYACTION *myActions; + MYTHREAD *myThreads; ~CoroContextTag() { // Free data blocks - if (MyThreads) - globalDestroy(MyThreads); - if (MyActions) - globalDestroy(MyActions); + if (myThreads) + globalDestroy(myThreads); + if (myActions) + globalDestroy(myActions); } CORO_END_CONTEXT(_ctx); @@ -822,8 +821,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); // Initialize data pointers - _ctx->MyActions = NULL; - _ctx->MyThreads = NULL; + _ctx->myActions = NULL; + _ctx->myThreads = NULL; // To begin with, we need to request the item list from the location _ctx->il = mpalQueryItemList(GLOBALS._nPollingLocations[id]); @@ -845,8 +844,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->curItem = GLOBALS._lpmiItems + _ctx->ord; _ctx->k = 0; - for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) { - if (_ctx->curItem->Action[_ctx->j].num == 0xFF) + for (_ctx->j = 0; _ctx->j < _ctx->curItem->_nActions; _ctx->j++) { + if (_ctx->curItem->_action[_ctx->j]._num == 0xFF) _ctx->k++; } @@ -867,8 +866,8 @@ void LocationPollThread(CORO_PARAM, const void *param) { return; } - _ctx->MyThreads = (MYTHREAD *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); - if (_ctx->MyThreads == NULL) { + _ctx->myThreads = (MYTHREAD *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nRealItems * sizeof(MYTHREAD)); + if (_ctx->myThreads == NULL) { globalDestroy(_ctx->il); CORO_KILL_SELF(); return; @@ -877,9 +876,9 @@ void LocationPollThread(CORO_PARAM, const void *param) { // We have established that there is at least one item that contains idle actions. // Now we created the mirrored copies of the idle actions. - _ctx->MyActions = (MYACTION *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); - if (_ctx->MyActions == NULL) { - globalDestroy(_ctx->MyThreads); + _ctx->myActions = (MYACTION *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, _ctx->nIdleActions * sizeof(MYACTION)); + if (_ctx->myActions == NULL) { + globalDestroy(_ctx->myThreads); globalDestroy(_ctx->il); CORO_KILL_SELF(); return; @@ -894,19 +893,19 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->il[_ctx->i]); - for (_ctx->j = 0; _ctx->j < _ctx->curItem->nActions; _ctx->j++) { - if (_ctx->curItem->Action[_ctx->j].num == 0xFF) { - _ctx->MyActions[_ctx->k].nItem = _ctx->il[_ctx->i]; - _ctx->MyActions[_ctx->k].nAction = _ctx->j; + for (_ctx->j = 0; _ctx->j < _ctx->curItem->_nActions; _ctx->j++) { + if (_ctx->curItem->_action[_ctx->j]._num == 0xFF) { + _ctx->myActions[_ctx->k]._nItem = _ctx->il[_ctx->i]; + _ctx->myActions[_ctx->k]._nAction = _ctx->j; - _ctx->MyActions[_ctx->k].wTime = _ctx->curItem->Action[_ctx->j].wTime; - _ctx->MyActions[_ctx->k].perc = _ctx->curItem->Action[_ctx->j].perc; - _ctx->MyActions[_ctx->k].when = _ctx->curItem->Action[_ctx->j].when; - _ctx->MyActions[_ctx->k].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; - memcpy(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, + _ctx->myActions[_ctx->k]._wTime = _ctx->curItem->_action[_ctx->j]._wTime; + _ctx->myActions[_ctx->k]._perc = _ctx->curItem->_action[_ctx->j]._perc; + _ctx->myActions[_ctx->k]._when = _ctx->curItem->_action[_ctx->j]._when; + _ctx->myActions[_ctx->k]._nCmds = _ctx->curItem->_action[_ctx->j]._nCmds; + memcpy(_ctx->myActions[_ctx->k]._cmdNum, _ctx->curItem->_action[_ctx->j]._cmdNum, MAX_COMMANDS_PER_ACTION * sizeof(uint16)); - _ctx->MyActions[_ctx->k].dwLastTime = g_vm->getTime(); + _ctx->myActions[_ctx->k]._dwLastTime = g_vm->getTime(); _ctx->k++; } } @@ -925,11 +924,11 @@ void LocationPollThread(CORO_PARAM, const void *param) { _ctx->dwSleepTime = (uint32)-1L; for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) { - if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { + if (_ctx->curTime >= _ctx->myActions[_ctx->k]._dwLastTime + _ctx->myActions[_ctx->k]._wTime) { _ctx->dwSleepTime = 0; break; } else - _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime - _ctx->curTime); + _ctx->dwSleepTime = MIN(_ctx->dwSleepTime, _ctx->myActions[_ctx->k]._dwLastTime + _ctx->myActions[_ctx->k]._wTime - _ctx->curTime); } // We fall alseep, but always checking that the event is set when prompted for closure @@ -940,12 +939,12 @@ void LocationPollThread(CORO_PARAM, const void *param) { break; for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { - if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 0, &_ctx->delayExpired); + if (_ctx->myThreads[_ctx->i]._nItem != 0) { + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->myThreads[_ctx->i]._hThread, 0, &_ctx->delayExpired); // if result == WAIT_OBJECT_0) if (!_ctx->delayExpired) - _ctx->MyThreads[_ctx->i].nItem = 0; + _ctx->myThreads[_ctx->i]._nItem = 0; } } @@ -953,19 +952,19 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Loop through all the necessary idle actions for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) { - if (_ctx->curTime >= _ctx->MyActions[_ctx->k].dwLastTime + _ctx->MyActions[_ctx->k].wTime) { - _ctx->MyActions[_ctx->k].dwLastTime += _ctx->MyActions[_ctx->k].wTime; + if (_ctx->curTime >= _ctx->myActions[_ctx->k]._dwLastTime + _ctx->myActions[_ctx->k]._wTime) { + _ctx->myActions[_ctx->k]._dwLastTime += _ctx->myActions[_ctx->k]._wTime; // It's time to check to see if fortune is on the side of the idle action byte randomVal = (byte)g_vm->_randomSource.getRandomNumber(99); - if (randomVal < _ctx->MyActions[_ctx->k].perc) { + if (randomVal < _ctx->myActions[_ctx->k]._perc) { // Check if there is an action running on the item - if ((GLOBALS._bExecutingAction) && (GLOBALS._nExecutingAction == _ctx->MyActions[_ctx->k].nItem)) + if ((GLOBALS._bExecutingAction) && (GLOBALS._nExecutingAction == _ctx->myActions[_ctx->k]._nItem)) continue; // Check to see if there already another idle funning running on the item for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { - if (_ctx->MyThreads[_ctx->i].nItem == _ctx->MyActions[_ctx->k].nItem) + if (_ctx->myThreads[_ctx->i]._nItem == _ctx->myActions[_ctx->k]._nItem) break; } @@ -974,49 +973,49 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Ok, we are the only ones :) lockItems(); - _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->MyActions[_ctx->k].nItem); + _ctx->curItem = GLOBALS._lpmiItems + itemGetOrderFromNum(_ctx->myActions[_ctx->k]._nItem); // Check if there is a WhenExecute expression - _ctx->j=_ctx->MyActions[_ctx->k].nAction; - if (_ctx->curItem->Action[_ctx->j].when != NULL) { - if (!evaluateExpression(_ctx->curItem->Action[_ctx->j].when)) { + _ctx->j=_ctx->myActions[_ctx->k]._nAction; + if (_ctx->curItem->_action[_ctx->j]._when != NULL) { + if (!evaluateExpression(_ctx->curItem->_action[_ctx->j]._when)) { unlockItems(); continue; } } // Ok, we can perform the action. For convenience, we do it in a new process - _ctx->newItem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + _ctx->newItem = (LpMpalItem)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MpalItem)); if (_ctx->newItem == false) { - globalDestroy(_ctx->MyThreads); - globalDestroy(_ctx->MyActions); + globalDestroy(_ctx->myThreads); + globalDestroy(_ctx->myActions); CORO_KILL_SELF(); return; } - memcpy(_ctx->newItem,_ctx->curItem, sizeof(MPALITEM)); + memcpy(_ctx->newItem,_ctx->curItem, sizeof(MpalItem)); unlockItems(); // We copy the action in #0 //_ctx->newItem->Action[0].nCmds = _ctx->curItem->Action[_ctx->j].nCmds; //memcpy(_ctx->newItem->Action[0].CmdNum,_ctx->curItem->Action[_ctx->j].CmdNum,_ctx->newItem->Action[0].nCmds*sizeof(_ctx->newItem->Action[0].CmdNum[0])); - _ctx->newItem->dwRes=_ctx->j; + _ctx->newItem->_dwRes = _ctx->j; // We will create an action, and will provide the necessary details for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { - if (_ctx->MyThreads[_ctx->i].nItem == 0) + if (_ctx->myThreads[_ctx->i]._nItem == 0) break; } - _ctx->MyThreads[_ctx->i].nItem = _ctx->MyActions[_ctx->k].nItem; + _ctx->myThreads[_ctx->i]._nItem = _ctx->myActions[_ctx->k]._nItem; // Create the process - if ((_ctx->MyThreads[_ctx->i].hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) { - //if ((_ctx->MyThreads[_ctx->i].hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem))= = (void*)-1) + if ((_ctx->myThreads[_ctx->i]._hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LpMpalItem))) == CORO_INVALID_PID_VALUE) { + //if ((_ctx->myThreads[_ctx->i]._hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem)) == (void*)-1) globalDestroy(_ctx->newItem); - globalDestroy(_ctx->MyThreads); - globalDestroy(_ctx->MyActions); + globalDestroy(_ctx->myThreads); + globalDestroy(_ctx->myActions); CORO_KILL_SELF(); return; @@ -1033,14 +1032,14 @@ void LocationPollThread(CORO_PARAM, const void *param) { CORO_INVOKE_4(GLOBALS._lplpFunctions[200], 0, 0, 0, 0); for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) { - if (_ctx->MyThreads[_ctx->i].nItem != 0) { - CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->MyThreads[_ctx->i].hThread, 5000, &_ctx->delayExpired); + if (_ctx->myThreads[_ctx->i]._nItem != 0) { + CORO_INVOKE_3(CoroScheduler.waitForSingleObject, _ctx->myThreads[_ctx->i]._hThread, 5000, &_ctx->delayExpired); //if (result != WAIT_OBJECT_0) //if (_ctx->delayExpired) // TerminateThread(_ctx->MyThreads[_ctx->i].hThread, 0); - CoroScheduler.killMatchingProcess(_ctx->MyThreads[_ctx->i].hThread); + CoroScheduler.killMatchingProcess(_ctx->myThreads[_ctx->i]._hThread); } } @@ -1090,7 +1089,7 @@ void doChoice(CORO_PARAM, uint32 nChoice); */ void GroupThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; - LPMPALDIALOG dialog; + LpMpalDialog dialog; int i, j, k; int type; CORO_END_CONTEXT(_ctx); @@ -1106,13 +1105,13 @@ void GroupThread(CORO_PARAM, const void *param) { _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; // Search inside the group requesting the _ctx->dialog - for (_ctx->i = 0; _ctx->dialog->_group[_ctx->i].num != 0; _ctx->i++) { - if (_ctx->dialog->_group[_ctx->i].num == nGroup) { + for (_ctx->i = 0; _ctx->dialog->_group[_ctx->i]._num != 0; _ctx->i++) { + if (_ctx->dialog->_group[_ctx->i]._num == nGroup) { // Cycle through executing the commands of the group - for (_ctx->j = 0; _ctx->j < _ctx->dialog->_group[_ctx->i].nCmds; _ctx->j++) { - _ctx->k = _ctx->dialog->_group[_ctx->i].CmdNum[_ctx->j]; + for (_ctx->j = 0; _ctx->j < _ctx->dialog->_group[_ctx->i]._nCmds; _ctx->j++) { + _ctx->k = _ctx->dialog->_group[_ctx->i]._cmdNum[_ctx->j]; - _ctx->type = _ctx->dialog->_command[_ctx->k].type; + _ctx->type = _ctx->dialog->_command[_ctx->k]._type; if (_ctx->type == 1) { // Call custom function CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->dialog->_command[_ctx->k]._nCf], @@ -1125,12 +1124,12 @@ void GroupThread(CORO_PARAM, const void *param) { } else if (_ctx->type == 2) { // Set a variable lockVar(); - varSetValue(_ctx->dialog->_command[_ctx->k].lpszVarName, evaluateExpression(_ctx->dialog->_command[_ctx->k].expr)); + varSetValue(_ctx->dialog->_command[_ctx->k]._lpszVarName, evaluateExpression(_ctx->dialog->_command[_ctx->k]._expr)); unlockVar(); } else if (_ctx->type == 3) { // DoChoice: call the chosen function - CORO_INVOKE_1(doChoice, (uint32)_ctx->dialog->_command[_ctx->k].nChoice); + CORO_INVOKE_1(doChoice, (uint32)_ctx->dialog->_command[_ctx->k]._nChoice); } else { GLOBALS._mpalError = 1; @@ -1166,7 +1165,7 @@ void GroupThread(CORO_PARAM, const void *param) { */ void doChoice(CORO_PARAM, uint32 nChoice) { CORO_BEGIN_CONTEXT; - LPMPALDIALOG dialog; + LpMpalDialog dialog; int i, j, k; uint32 nGroup; CORO_END_CONTEXT(_ctx); @@ -1180,13 +1179,13 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; // Search the choice between those required in the dialog - for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i].nChoice != 0; _ctx->i++) { - if (_ctx->dialog->_choice[_ctx->i].nChoice == nChoice) + for (_ctx->i = 0; _ctx->dialog->_choice[_ctx->i]._nChoice != 0; _ctx->i++) { + if (_ctx->dialog->_choice[_ctx->i]._nChoice == nChoice) break; } // If nothing has been found, exit with an error - if (_ctx->dialog->_choice[_ctx->i].nChoice == 0) { + if (_ctx->dialog->_choice[_ctx->i]._nChoice == 0) { // If we're here, we did not find the required choice GLOBALS._mpalError = 1; unlockDialogs(); @@ -1203,15 +1202,15 @@ void doChoice(CORO_PARAM, uint32 nChoice) { _ctx->k = 0; // Calculate the expression of each selection, to see if they're active or inactive - for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].dwData != 0; _ctx->j++) { - if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when == NULL) { - _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; + for (_ctx->j = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._dwData != 0; _ctx->j++) { + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._when == NULL) { + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._curActive = 1; _ctx->k++; - } else if (evaluateExpression(_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].when)) { - _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 1; + } else if (evaluateExpression(_ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._when)) { + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._curActive = 1; _ctx->k++; } else - _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].curActive = 0; + _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._curActive = 0; } // If there are no choices activated, then the dialog is finished. @@ -1227,19 +1226,19 @@ void doChoice(CORO_PARAM, uint32 nChoice) { // Now that the choice has been made, we can run the groups associated with the choice tbontbtitq _ctx->j = GLOBALS._nSelectedChoice; - for (_ctx->k = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k] != 0; _ctx->k++) { - _ctx->nGroup = _ctx->dialog->_choice[_ctx->i]._select[_ctx->j].wPlayGroup[_ctx->k]; + for (_ctx->k = 0; _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._wPlayGroup[_ctx->k] != 0; _ctx->k++) { + _ctx->nGroup = _ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._wPlayGroup[_ctx->k]; CORO_INVOKE_1(GroupThread, &_ctx->nGroup); } // Control attribute - if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 0)) { + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._attr & (1 << 0)) { // Bit 0 set: the end of the choice unlockDialogs(); break; } - if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j].attr & (1 << 1)) { + if (_ctx->dialog->_choice[_ctx->i]._select[_ctx->j]._attr & (1 << 1)) { // Bit 1 set: the end of the dialog unlockDialogs(); @@ -1270,52 +1269,52 @@ void doChoice(CORO_PARAM, uint32 nChoice) { * by calling LockItem(). */ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { - LPMPALITEM item = GLOBALS._lpmiItems; - LPMPALITEM newitem; + LpMpalItem item = GLOBALS._lpmiItems; + LpMpalItem newitem; item+=ordItem; - Common::String buf = Common::String::format("Status.%u", item->nObj); + Common::String buf = Common::String::format("Status.%u", item->_nObj); if (varGetValue(buf.c_str()) <= 0) return CORO_INVALID_PID_VALUE; - for (int i = 0; i < item->nActions; i++) { - if (item->Action[i].num != nAction) + for (int i = 0; i < item->_nActions; i++) { + if (item->_action[i]._num != nAction) continue; - if (item->Action[i].wParm != dwParam) + if (item->_action[i]._wParm != dwParam) continue; - if (item->Action[i].when != NULL) { - if (!evaluateExpression(item->Action[i].when)) + if (item->_action[i]._when != NULL) { + if (!evaluateExpression(item->_action[i]._when)) continue; } // Now we find the right action to be performed // Duplicate the item and copy the current action in #i into #0 - newitem = (LPMPALITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM)); + newitem = (LpMpalItem)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MpalItem)); if (newitem == NULL) return CORO_INVALID_PID_VALUE; // In the new version number of the action in writing dwRes - Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem); + Common::copy((byte *)item, (byte *)item + sizeof(MpalItem), (byte *)newitem); //newitem->Action[0].nCmds=item->Action[i].nCmds; //memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); - newitem->dwRes = i; + newitem->_dwRes = i; // And finally we can laucnh the process that will execute the action, // and a second process to free up the memory when the action is finished. // !!! New process management uint32 h; - if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) + if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LpMpalItem))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; if (CoroScheduler.createProcess(ShutUpActionThread, &h, sizeof(uint32)) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; - GLOBALS._nExecutingAction = item->nObj; + GLOBALS._nExecutingAction = item->_nObj; GLOBALS._bExecutingAction = true; return h; @@ -1372,15 +1371,15 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { * @returns True if everything is OK, false on failure */ bool doSelection(uint32 i, uint32 dwData) { - LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; + LpMpalDialog dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; int j; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { - if (dialog->_choice[i]._select[j].dwData == dwData && dialog->_choice[i]._select[j].curActive != 0) + for (j = 0; dialog->_choice[i]._select[j]._dwData != 0; j++) { + if (dialog->_choice[i]._select[j]._dwData == dwData && dialog->_choice[i]._select[j]._curActive != 0) break; } - if (dialog->_choice[i]._select[j].dwData == 0) + if (dialog->_choice[i]._select[j]._dwData == 0) return false; GLOBALS._nSelectedChoice = j; @@ -1469,7 +1468,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, hMpc.close(); // Process the data - if (ParseMpc(lpMpcImage) == false) + if (parseMpc(lpMpcImage) == false) return false; globalDestroy(lpMpcImage); @@ -1601,9 +1600,9 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { int y = GETARG(uint32); if (x != -1) { if (y == MPQ_X) - dwRet = GLOBALS._lpmlLocations[x].dwXlen; + dwRet = GLOBALS._lpmlLocations[x]._dwXlen; else if (y == MPQ_Y) - dwRet = GLOBALS._lpmlLocations[x].dwYlen; + dwRet = GLOBALS._lpmlLocations[x]._dwYlen; else GLOBALS._mpalError = 1; } else @@ -1662,7 +1661,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { else { lockItems(); int y = itemGetOrderFromNum(x); - memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + memcpy(n, (char *)(GLOBALS._lpmiItems + y)->_lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1795,7 +1794,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { */ lockLocations(); int x = locGetOrderFromNum(GETARG(uint32)); - hRet = resLoad(GLOBALS._lpmlLocations[x].dwPicRes); + hRet = resLoad(GLOBALS._lpmlLocations[x]._dwPicRes); unlockLocations(); } else if (wQueryType == MPQ_RESOURCE) { @@ -1839,7 +1838,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { else { lockItems(); int y = itemGetOrderFromNum(x); - memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); + memcpy(n, (char *)(GLOBALS._lpmiItems + y)->_lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1959,25 +1958,24 @@ uint32 mpalGetError() { * @returns TRUE if the script 'was launched, FALSE on failure */ bool mpalExecuteScript(int nScript) { - LPMPALSCRIPT s; + LpMpalScript s; LockScripts(); int n = scriptGetOrderFromNum(nScript); - s = (LPMPALSCRIPT)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); + s = (LpMpalScript)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MpalScript)); if (s == NULL) return false; - memcpy(s, GLOBALS._lpmsScripts + n, sizeof(MPALSCRIPT)); + memcpy(s, GLOBALS._lpmsScripts + n, sizeof(MpalScript)); unlockScripts(); // !!! New process management - if (CoroScheduler.createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == CORO_INVALID_PID_VALUE) + if (CoroScheduler.createProcess(ScriptThread, &s, sizeof(LpMpalScript)) == CORO_INVALID_PID_VALUE) return false; return true; } - /** * Install a custom routine That will be called by MPAL every time the pattern * of an item has been changed. @@ -1988,7 +1986,6 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { GLOBALS._lpiifCustom = lpiifCus; } - /** * Process the idle actions of the items on one location. * @@ -2063,7 +2060,7 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) { * @returns Length in bytes */ int mpalGetSaveStateSize() { - return GLOBALS._nVars * sizeof(MPALVAR) + 4; + return GLOBALS._nVars * sizeof(MpalVar) + 4; } /** @@ -2075,7 +2072,7 @@ int mpalGetSaveStateSize() { void mpalSaveState(byte *buf) { lockVar(); WRITE_LE_UINT32(buf, GLOBALS._nVars); - memcpy(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MPALVAR)); + memcpy(buf + 4, (byte *)GLOBALS._lpmvVars, GLOBALS._nVars * sizeof(MpalVar)); unlockVar(); } @@ -2092,12 +2089,12 @@ int mpalLoadState(byte *buf) { GLOBALS._nVars = READ_LE_UINT32(buf); - GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MPALVAR)); + GLOBALS._hVars = globalAllocate(GMEM_ZEROINIT | GMEM_MOVEABLE, GLOBALS._nVars * sizeof(MpalVar)); lockVar(); - memcpy((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MPALVAR)); + memcpy((byte *)GLOBALS._lpmvVars, buf + 4, GLOBALS._nVars * sizeof(MpalVar)); unlockVar(); - return GLOBALS._nVars * sizeof(MPALVAR) + 4; + return GLOBALS._nVars * sizeof(MpalVar) + 4; } } // end of namespace MPAL diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 492889d88a..1af0f2c9e9 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -120,31 +120,31 @@ enum QueryCoordinates { */ enum QueryTypes { // General Query - MPQ_VERSION=10, + MPQ_VERSION = 10, - MPQ_GLOBAL_VAR=50, + MPQ_GLOBAL_VAR = 50, MPQ_RESOURCE, MPQ_MESSAGE, // Query on leases - MPQ_LOCATION_IMAGE=100, + MPQ_LOCATION_IMAGE = 100, MPQ_LOCATION_SIZE, // Queries about items - MPQ_ITEM_LIST=200, + MPQ_ITEM_LIST = 200, MPQ_ITEM_DATA, MPQ_ITEM_PATTERN, MPQ_ITEM_NAME, MPQ_ITEM_IS_ACTIVE, // Query dialog - MPQ_DIALOG_PERIOD=300, + MPQ_DIALOG_PERIOD = 300, MPQ_DIALOG_WAITFORCHOICE, MPQ_DIALOG_SELECTLIST, MPQ_DIALOG_SELECTION, // Query execution - MPQ_DO_ACTION=400, + MPQ_DO_ACTION = 400, MPQ_DO_DIALOG }; @@ -164,7 +164,6 @@ typedef struct { short _destX, _destY; signed char _destZ; short _objectID; -// char TAG; } ITEM; typedef ITEM *LPITEM; diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index a95003ef97..853b5b2dac 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -42,32 +42,27 @@ namespace MPAL { * Defines \****************************************************************************/ -#define HEX_VERSION 0x0170 - - -#define MAX_ACTIONS_PER_ITEM 40 -#define MAX_COMMANDS_PER_ITEM 128 -#define MAX_COMMANDS_PER_ACTION 128 -#define MAX_DESCRIBE_SIZE 64 - - -#define MAX_MOMENTS_PER_SCRIPT 256 -#define MAX_COMMANDS_PER_SCRIPT 256 -#define MAX_COMMANDS_PER_MOMENT 32 - - -#define MAX_GROUPS_PER_DIALOG 128 -#define MAX_COMMANDS_PER_DIALOG 480 -#define MAX_COMMANDS_PER_GROUP 64 -#define MAX_CHOICES_PER_DIALOG 64 -#define MAX_SELECTS_PER_CHOICE 64 +#define HEX_VERSION 0x0170 + +#define MAX_ACTIONS_PER_ITEM 40 +#define MAX_COMMANDS_PER_ITEM 128 +#define MAX_COMMANDS_PER_ACTION 128 +#define MAX_DESCRIBE_SIZE 64 + +#define MAX_MOMENTS_PER_SCRIPT 256 +#define MAX_COMMANDS_PER_SCRIPT 256 +#define MAX_COMMANDS_PER_MOMENT 32 + +#define MAX_GROUPS_PER_DIALOG 128 +#define MAX_COMMANDS_PER_DIALOG 480 +#define MAX_COMMANDS_PER_GROUP 64 +#define MAX_CHOICES_PER_DIALOG 64 +#define MAX_SELECTS_PER_CHOICE 64 #define MAX_PLAYGROUPS_PER_SELECT 9 -#define MAX_PERIODS_PER_DIALOG 400 - +#define MAX_PERIODS_PER_DIALOG 400 #define NEED_LOCK_MSGS - /****************************************************************************\ * Structures \****************************************************************************/ @@ -77,42 +72,36 @@ namespace MPAL { /** * MPAL global variables */ -struct MPALVAR { - uint32 dwVal; // Variable value - char lpszVarName[33]; // Variable name +struct MpalVar { + uint32 _dwVal; // Variable value + char _lpszVarName[33]; // Variable name } PACKED_STRUCT; -typedef MPALVAR *LPMPALVAR; -typedef LPMPALVAR *LPLPMPALVAR; - +typedef MpalVar *LpMpalVar; /** * MPAL Messages */ -struct MPALMSG { - HGLOBAL _hText; // Handle to the message text - uint16 _wNum; // Message number +struct MpalMsg { + HGLOBAL _hText; // Handle to the message text + uint16 _wNum; // Message number } PACKED_STRUCT; -typedef MPALMSG *LPMPALMSG; -typedef LPMPALMSG *LPLPMPALMSG; - +typedef MpalMsg *LpMpalMsg; /** * MPAL Locations */ -struct MPALLOCATION { - uint32 nObj; // Location number - uint32 dwXlen, dwYlen; // Dimensions - uint32 dwPicRes; // Resource that contains the image +struct MpalLocation { + uint32 _nObj; // Location number + uint32 _dwXlen, _dwYlen; // Dimensions + uint32 _dwPicRes; // Resource that contains the image } PACKED_STRUCT; -typedef MPALLOCATION *LPMPALLOCATION; -typedef LPMPALLOCATION *LPLPMPALLOCATION; - +typedef MpalLocation *LpMpalLocation; /** * All the data for a command, ie. tags used by OnAction in the item, the time * in the script, and in the group dialog. */ -struct command { +struct Command { /* * Types of commands that are recognized * @@ -121,55 +110,54 @@ struct command { * #3 -> Making a choice (DIALOG) * */ - byte type; // Type of control + byte _type; // Type of control union { - int32 _nCf; // Custom function call [#1] - char *lpszVarName; // Variable name [#2] - int32 nChoice; // Number of choice you make [#3] + int32 _nCf; // Custom function call [#1] + char *_lpszVarName; // Variable name [#2] + int32 _nChoice; // Number of choice you make [#3] }; union { - int32 _arg1; // Argument for custom function [#1] - HGLOBAL expr; // Expression to assign to a variable [#2] + int32 _arg1; // Argument for custom function [#1] + HGLOBAL _expr; // Expression to assign to a variable [#2] }; - int32 _arg2, _arg3, _arg4; // Arguments for custom function [#1] + int32 _arg2, _arg3, _arg4; // Arguments for custom function [#1] } PACKED_STRUCT; /** * MPAL dialog */ -struct MPALDIALOG { - uint32 nObj; // Dialog number +struct MpalDialog { + uint32 _nObj; // Dialog number - struct command _command[MAX_COMMANDS_PER_DIALOG]; + struct Command _command[MAX_COMMANDS_PER_DIALOG]; struct { - uint16 num; - - byte nCmds; - uint16 CmdNum[MAX_COMMANDS_PER_GROUP]; + uint16 _num; + byte _nCmds; + uint16 _cmdNum[MAX_COMMANDS_PER_GROUP]; } _group[MAX_GROUPS_PER_DIALOG]; struct { // The last choice has nChoice == 0 - uint16 nChoice; + uint16 _nChoice; // The select number (we're pretty stingy with RAM). The last select has dwData == 0 struct { - HGLOBAL when; - uint32 dwData; - uint16 wPlayGroup[MAX_PLAYGROUPS_PER_SELECT]; + HGLOBAL _when; + uint32 _dwData; + uint16 _wPlayGroup[MAX_PLAYGROUPS_PER_SELECT]; // Bit 0=endchoice Bit 1=enddialog - byte attr; + byte _attr; // Modified at run-time: 0 if the select is currently disabled, // and 1 if currently active - byte curActive; + byte _curActive; } _select[MAX_SELECTS_PER_CHOICE]; } _choice[MAX_CHOICES_PER_DIALOG]; @@ -178,68 +166,60 @@ struct MPALDIALOG { HGLOBAL _periods[MAX_PERIODS_PER_DIALOG]; } PACKED_STRUCT; -typedef MPALDIALOG *LPMPALDIALOG; -typedef LPMPALDIALOG *LPLPMPALDIALOG; - +typedef MpalDialog *LpMpalDialog; /** * MPAL Item */ struct ItemAction { - byte num; // Action number - uint16 wTime; // If idle, the time which must pass - byte perc; // Percentage of the idle run - HGLOBAL when; // Expression to compute. If != 0, then + byte _num; // Action number + uint16 _wTime; // If idle, the time which must pass + byte _perc; // Percentage of the idle run + HGLOBAL _when; // Expression to compute. If != 0, then // action can be done - uint16 wParm; // Parameter for action + uint16 _wParm; // Parameter for action - byte nCmds; // Number of commands to be executed - uint32 CmdNum[MAX_COMMANDS_PER_ACTION]; // Commands to execute + byte _nCmds; // Number of commands to be executed + uint32 _cmdNum[MAX_COMMANDS_PER_ACTION]; // Commands to execute } PACKED_STRUCT; -struct MPALITEM { - uint32 nObj; // Item number +struct MpalItem { + uint32 _nObj; // Item number - byte lpszDescribe[MAX_DESCRIBE_SIZE]; // Name - byte nActions; // Number of managed actions - uint32 dwRes; // Resource that contains frames and patterns + byte _lpszDescribe[MAX_DESCRIBE_SIZE]; // Name + byte _nActions; // Number of managed actions + uint32 _dwRes; // Resource that contains frames and patterns - struct command _command[MAX_COMMANDS_PER_ITEM]; + struct Command _command[MAX_COMMANDS_PER_ITEM]; // Pointer to array of structures containing various managed activities. In practice, of // every action we know what commands to run, including those defined in structures above - struct ItemAction *Action; + struct ItemAction *_action; } PACKED_STRUCT; -typedef MPALITEM *LPMPALITEM; -typedef LPMPALITEM *LPLPMPALITEM; - +typedef MpalItem *LpMpalItem; /** * MPAL Script */ -struct MPALSCRIPT { - uint32 nObj; - - uint32 nMoments; +struct MpalScript { + uint32 _nObj; + uint32 _nMoments; - struct command _command[MAX_COMMANDS_PER_SCRIPT]; + struct Command _command[MAX_COMMANDS_PER_SCRIPT]; struct { - int32 dwTime; + int32 _dwTime; + byte _nCmds; + uint32 _cmdNum[MAX_COMMANDS_PER_MOMENT]; - byte nCmds; - uint32 CmdNum[MAX_COMMANDS_PER_MOMENT]; - - } Moment[MAX_MOMENTS_PER_SCRIPT]; + } _moment[MAX_MOMENTS_PER_SCRIPT]; } PACKED_STRUCT; -typedef MPALSCRIPT *LPMPALSCRIPT; -typedef LPMPALSCRIPT *LPLPMPALSCRIPT; +typedef MpalScript *LpMpalScript; #include "common/pack-end.h" - /****************************************************************************\ * Function prototypes \****************************************************************************/ -- cgit v1.2.3 From f2df769aab10e719cc4fba6cb71e1500eb3acae4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 1 Sep 2012 00:25:35 +0200 Subject: TONY: More renaming --- engines/tony/mpal/expr.cpp | 128 +++++++++++++++++++++--------------------- engines/tony/mpal/expr.h | 8 +-- engines/tony/mpal/loadmpc.cpp | 6 +- engines/tony/mpal/lzo.cpp | 32 +++++------ engines/tony/mpal/memory.cpp | 16 +++--- engines/tony/mpal/memory.h | 17 +++--- engines/tony/mpal/mpal.cpp | 62 ++++++++++---------- engines/tony/mpal/mpal.h | 24 ++++---- engines/tony/mpal/mpaldll.h | 26 ++++----- engines/tony/mpal/mpalutils.h | 2 +- 10 files changed, 158 insertions(+), 163 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 31abeb0810..7923d263c0 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -81,20 +81,20 @@ enum ExprListTypes { * Mathamatical framework to manage operations */ typedef struct { - byte type; // Tipo di oggetto (vedi enum ExprListTypes) - byte unary; // Unary operatore (NON SUPPORTATO) + byte _type; // Tipo di oggetto (vedi enum ExprListTypes) + byte _unary; // Unary operatore (NON SUPPORTATO) union { - int num; // Numero (se type==ELT_NUMBER) - char *name; // Nome variabile (se type==ELT_VAR) - HGLOBAL son; // Handle a espressione (type==ELT_PARENTH) - byte *pson; // Handle lockato (type==ELT_PARENTH2) - } val; + int _num; // Numero (se type==ELT_NUMBER) + char *_name; // Nome variabile (se type==ELT_VAR) + MpalHandle _son; // Handle a espressione (type==ELT_PARENTH) + byte *_pson; // Handle lockato (type==ELT_PARENTH2) + } _val; - byte symbol; // Simbolo matematico (vedi #define OP_*) + byte _symbol; // Simbolo matematico (vedi #define OP_*) -} EXPRESSION; -typedef EXPRESSION *LPEXPRESSION; +} Expression; +typedef Expression *LpExpression; //@} @@ -104,24 +104,24 @@ typedef EXPRESSION *LPEXPRESSION; * @param h Handle to the original expression * @retruns Pointer to the cloned expression */ -static byte *duplicateExpression(HGLOBAL h) { +static byte *duplicateExpression(MpalHandle h) { byte *orig, *clone; - LPEXPRESSION one, two; + LpExpression one, two; orig = (byte *)globalLock(h); int num = *(byte *)orig; - one = (LPEXPRESSION)(orig+1); + one = (LpExpression)(orig+1); - clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); - two = (LPEXPRESSION)(clone + 1); + clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(Expression) * num + 1); + two = (LpExpression)(clone + 1); - memcpy(clone, orig, sizeof(EXPRESSION) * num + 1); + memcpy(clone, orig, sizeof(Expression) * num + 1); for (int i = 0; i < num; i++) { - if (one->type == ELT_PARENTH) { - two->type = ELT_PARENTH2; - two->val.pson = duplicateExpression(two->val.son); + if (one->_type == ELT_PARENTH) { + two->_type = ELT_PARENTH2; + two->_val._pson = duplicateExpression(two->_val._son); } ++one; @@ -178,27 +178,27 @@ static int Compute(int a, int b, byte symbol) { return 0; } -static void solve(LPEXPRESSION one, int num) { - LPEXPRESSION two, three; +static void solve(LpExpression one, int num) { + LpExpression two, three; int j; while (num > 1) { two = one + 1; - if ((two->symbol == 0) || (one->symbol & 0xF0) <= (two->symbol & 0xF0)) { - two->val.num = Compute(one->val.num, two->val.num, one->symbol); - memmove(one, two, (num - 1) * sizeof(EXPRESSION)); + if ((two->_symbol == 0) || (one->_symbol & 0xF0) <= (two->_symbol & 0xF0)) { + two->_val._num = Compute(one->_val._num, two->_val._num, one->_symbol); + memmove(one, two, (num - 1) * sizeof(Expression)); --num; } else { j = 1; three = two + 1; - while ((three->symbol != 0) && (two->symbol & 0xF0) > (three->symbol & 0xF0)) { + while ((three->_symbol != 0) && (two->_symbol & 0xF0) > (three->_symbol & 0xF0)) { ++two; ++three; ++j; } - three->val.num = Compute(two->val.num, three->val.num, two->symbol); - memmove(two, three, (num - j - 1) * sizeof(EXPRESSION)); + three->_val._num = Compute(two->_val._num, three->_val._num, two->_symbol); + memmove(two, three, (num - j - 1) * sizeof(Expression)); --num; } } @@ -213,32 +213,32 @@ static void solve(LPEXPRESSION one, int num) { * @returns Value */ static int evaluateAndFreeExpression(byte *expr) { - LPEXPRESSION one, cur; + LpExpression one, cur; int num = *expr; - one = (LPEXPRESSION)(expr + 1); + one = (LpExpression)(expr + 1); // 1) Substitutions of variables cur = one; for (int i = 0; i < num; i++, cur++) { - if (cur->type == ELT_VAR) { - cur->type = ELT_NUMBER; - cur->val.num = varGetValue(cur->val.name); + if (cur->_type == ELT_VAR) { + cur->_type = ELT_NUMBER; + cur->_val._num = varGetValue(cur->_val._name); } } // 2) Replacement of brackets (using recursive calls) cur = one; for (int i = 0; i < num; i++, cur++) { - if (cur->type == ELT_PARENTH2) { - cur->type = ELT_NUMBER; - cur->val.num = evaluateAndFreeExpression(cur->val.pson); + if (cur->_type == ELT_PARENTH2) { + cur->_type = ELT_NUMBER; + cur->_val._num = evaluateAndFreeExpression(cur->_val._pson); } } // 3) algebraic resolution solve(one, num); - int val = one->val.num; + int val = one->_val._num; globalDestroy(expr); return val; @@ -253,8 +253,8 @@ static int evaluateAndFreeExpression(byte *expr) { * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ -const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { - LPEXPRESSION cur; +const byte *parseExpression(const byte *lpBuf, MpalHandle *h) { + LpExpression cur; byte *start; uint32 num = *lpBuf; @@ -263,35 +263,35 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { if (num == 0) return NULL; - *h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(EXPRESSION) + 1); + *h = globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(Expression) + 1); if (*h == NULL) return NULL; start = (byte *)globalLock(*h); *start = (byte)num; - cur = (LPEXPRESSION)(start + 1); + cur = (LpExpression)(start + 1); for (uint32 i = 0;i < num; i++) { - cur->type = *(lpBuf); - cur->unary = *(lpBuf + 1); + cur->_type = *(lpBuf); + cur->_unary = *(lpBuf + 1); lpBuf += 2; - switch (cur->type) { + switch (cur->_type) { case ELT_NUMBER: - cur->val.num = (int32)READ_LE_UINT32(lpBuf); + cur->_val._num = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; break; case ELT_VAR: - cur->val.name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); - if (cur->val.name == NULL) + cur->_val._name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1); + if (cur->_val._name == NULL) return NULL; - memcpy(cur->val.name, lpBuf + 1, *lpBuf); + memcpy(cur->_val._name, lpBuf + 1, *lpBuf); lpBuf += *lpBuf + 1; break; case ELT_PARENTH: - lpBuf = parseExpression(lpBuf, &cur->val.son); + lpBuf = parseExpression(lpBuf, &cur->_val._son); if (lpBuf == NULL) return NULL; break; @@ -300,7 +300,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { return NULL; } - cur->symbol = *lpBuf; + cur->_symbol = *lpBuf; lpBuf++; cur++; @@ -321,7 +321,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { * @param h Handle to the expression * @returns Numeric value */ -int evaluateExpression(HGLOBAL h) { +int evaluateExpression(MpalHandle h) { int ret; lockVar(); @@ -337,9 +337,9 @@ int evaluateExpression(HGLOBAL h) { * @param h1 Expression to be compared * @param h2 Expression to be compared */ -bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { +bool compareExpressions(MpalHandle h1, MpalHandle h2) { byte *e1, *e2; - LPEXPRESSION one, two; + LpExpression one, two; e1 = (byte *)globalLock(h1); e2 = (byte *)globalLock(h2); @@ -353,19 +353,19 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { return false; } - one = (LPEXPRESSION)(e1 + 1); - two = (LPEXPRESSION)(e2 + 1); + one = (LpExpression)(e1 + 1); + two = (LpExpression)(e2 + 1); for (int i = 0; i < num1; i++) { - if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { + if (one->_type != two->_type || (i != num1 - 1 && one->_symbol != two->_symbol)) { globalUnlock(h1); globalUnlock(h2); return false; } - switch (one->type) { + switch (one->_type) { case ELT_NUMBER: - if (one->val.num != two->val.num) { + if (one->_val._num != two->_val._num) { globalUnlock(h1); globalUnlock(h2); return false; @@ -373,7 +373,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { break; case ELT_VAR: - if (strcmp(one->val.name, two->val.name) != 0) { + if (strcmp(one->_val._name, two->_val._name) != 0) { globalUnlock(h1); globalUnlock(h2); return false; @@ -381,7 +381,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { break; case ELT_PARENTH: - if (!compareExpressions(one->val.son, two->val.son)) { + if (!compareExpressions(one->_val._son, two->_val._son)) { globalUnlock(h1); globalUnlock(h2); return false; @@ -404,19 +404,19 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { * * @param h Handle for the expression */ -void freeExpression(HGLOBAL h) { +void freeExpression(MpalHandle h) { byte *data = (byte *)globalLock(h); int num = *data; - LPEXPRESSION cur = (LPEXPRESSION)(data + 1); + LpExpression cur = (LpExpression)(data + 1); for (int i = 0; i < num; ++i, ++cur) { - switch (cur->type) { + switch (cur->_type) { case ELT_VAR: - globalDestroy(cur->val.name); + globalDestroy(cur->_val._name); break; case ELT_PARENTH: - freeExpression(cur->val.son); + freeExpression(cur->_val._son); break; default: diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index f9c8a7c48f..9036099993 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -47,7 +47,7 @@ namespace MPAL { * will point to the area of memory containing the parsed expression * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ -const byte *parseExpression(const byte *lpBuf, HGLOBAL *h); +const byte *parseExpression(const byte *lpBuf, MpalHandle *h); /** * Calculate the value of a mathamatical expression @@ -55,7 +55,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h); * @param h Handle to the expression * @returns Numeric value */ -int evaluateExpression(HGLOBAL h); +int evaluateExpression(MpalHandle h); /** * Compare two mathematical expressions together @@ -63,14 +63,14 @@ int evaluateExpression(HGLOBAL h); * @param h1 Expression to be compared * @param h2 Expression to be compared */ -bool compareExpressions(HGLOBAL h1, HGLOBAL h2); +bool compareExpressions(MpalHandle h1, MpalHandle h2); /** * Frees an expression that was previously parsed * * @param h Handle for the expression */ -void freeExpression(HGLOBAL h); +void freeExpression(MpalHandle h); } // end of namespace MPAL diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index b3c4193414..953820be74 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -253,14 +253,14 @@ static const byte *parseDialog(const byte *lpBuf, LpMpalDialog lpmdDialog) { } if (curCmd >= MAX_COMMANDS_PER_DIALOG) - error("Too much commands in dialog #%d",lpmdDialog->_nObj); + error("Too much commands in dialog #%d", lpmdDialog->_nObj); // Choices num = READ_LE_UINT16(lpBuf); lpBuf += 2; if (num >= MAX_CHOICES_PER_DIALOG) - error("Too much choices in dialog #%d",lpmdDialog->_nObj); + error("Too much choices in dialog #%d", lpmdDialog->_nObj); for (i = 0; i < num; i++) { lpmdDialog->_choice[i]._nChoice = READ_LE_UINT16(lpBuf); @@ -380,7 +380,7 @@ static const byte *parseItem(const byte *lpBuf, LpMpalItem lpmiItem) { lpBuf++; if (lpmiItem->_action[i]._nCmds >= MAX_COMMANDS_PER_ACTION) - error("Too much commands in action #%d in item #%d",lpmiItem->_action[i]._num, lpmiItem->_nObj); + error("Too much commands in action #%d in item #%d", lpmiItem->_action[i]._num, lpmiItem->_nObj); for (uint32 j = 0; j < lpmiItem->_action[i]._nCmds; j++) { lpmiItem->_command[curCmd]._type = *lpBuf; diff --git a/engines/tony/mpal/lzo.cpp b/engines/tony/mpal/lzo.cpp index 48a0d8ea87..3d0751a5ca 100644 --- a/engines/tony/mpal/lzo.cpp +++ b/engines/tony/mpal/lzo.cpp @@ -69,10 +69,10 @@ namespace Tony { namespace MPAL { -#define pd(a,b) ((uint32) ((a)-(b))) +#define pd(a, b) ((uint32) ((a) - (b))) #define TEST_IP (ip < ip_end) -#define TEST_OP 1 +#define TEST_OP 1 #define NEED_IP(x) ((void) 0) #define NEED_OP(x) ((void) 0) #define TEST_LB(m_pos) ((void) 0) @@ -83,7 +83,7 @@ namespace MPAL { /** * Decompresses an LZO compressed resource */ -int lzo1x_decompress(const byte *in , uint32 in_len, byte *out, uint32 *out_len) { +int lzo1x_decompress(const byte *in, uint32 in_len, byte *out, uint32 *out_len) { register byte *op; register const byte *ip; register uint32 t = 0; @@ -155,12 +155,12 @@ int lzo1x_decompress(const byte *in , uint32 in_len, byte *out, uint32 *out_len) t += 3; if (t >= 8) do { - UA_COPY64(op,ip); + UA_COPY64(op, ip); op += 8; ip += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY32(op,ip); + UA_COPY32(op, ip); op += 4; ip += 4; t -= 4; } if (t > 0) @@ -170,17 +170,17 @@ int lzo1x_decompress(const byte *in , uint32 in_len, byte *out, uint32 *out_len) } #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) #if !defined(LZO_UNALIGNED_OK_4) - if (PTR_ALIGNED2_4(op,ip)) + if (PTR_ALIGNED2_4(op, ip)) { #endif - UA_COPY32(op,ip); + UA_COPY32(op, ip); op += 4; ip += 4; if (--t > 0) { if (t >= 4) { do { - UA_COPY32(op,ip); + UA_COPY32(op, ip); op += 4; ip += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *ip++; while (--t > 0); @@ -213,7 +213,7 @@ first_literal_run: m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); #endif NEED_OP(3); - t = 3; COPY_DICT(t,m_off) + t = 3; COPY_DICT(t, m_off) #else #if defined(LZO1Z) t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); @@ -382,7 +382,7 @@ match: m_off = 1 + (t >> 2) + (*ip++ << 2); #endif NEED_OP(2); - t = 2; COPY_DICT(t,m_off) + t = 2; COPY_DICT(t, m_off) #else #if defined(LZO1Z) t = 1 + (t << 6) + (*ip++ >> 2); @@ -402,7 +402,7 @@ match: #if defined(COPY_DICT) NEED_OP(t+3-1); - t += 3-1; COPY_DICT(t,m_off) + t += 3-1; COPY_DICT(t, m_off) #else @@ -413,12 +413,12 @@ match: t += (3 - 1); if (t >= 8) do { - UA_COPY64(op,m_pos); + UA_COPY64(op, m_pos); op += 8; m_pos += 8; t -= 8; } while (t >= 8); if (t >= 4) { - UA_COPY32(op,m_pos); + UA_COPY32(op, m_pos); op += 4; m_pos += 4; t -= 4; } if (t > 0) @@ -430,17 +430,17 @@ match: else #elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) #if !defined(LZO_UNALIGNED_OK_4) - if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op, m_pos)) { assert((op - m_pos) >= 4); #else if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) { #endif - UA_COPY32(op,m_pos); + UA_COPY32(op, m_pos); op += 4; m_pos += 4; t -= 4 - (3 - 1); do { - UA_COPY32(op,m_pos); + UA_COPY32(op, m_pos); op += 4; m_pos += 4; t -= 4; } while (t >= 4); if (t > 0) do *op++ = *m_pos++; while (--t > 0); diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 3a68ecb559..428c07b3b7 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -39,7 +39,7 @@ const uint32 BLOCK_ID = 0x12345678; * Allocates a new memory block * @return Returns a MemoryItem instance for the new block */ -HANDLE MemoryManager::allocate(uint32 size, uint flags) { +MpalHandle MemoryManager::allocate(uint32 size, uint flags) { MemoryItem *newItem = (MemoryItem *)malloc(sizeof(MemoryItem) + size); newItem->_id = BLOCK_ID; newItem->_size = size; @@ -51,7 +51,7 @@ HANDLE MemoryManager::allocate(uint32 size, uint flags) { Common::fill(dataP, dataP + size, 0); } - return (HANDLE)newItem; + return (MpalHandle)newItem; } /** @@ -70,7 +70,7 @@ void *MemoryManager::alloc(uint32 size, uint flags) { * Returns a reference to the MemoryItem for a gien byte pointer * @param block Byte pointer */ -MemoryItem *MemoryManager::getItem(HGLOBAL handle) { +MemoryItem *MemoryManager::getItem(MpalHandle handle) { MemoryItem *rec = (MemoryItem *)((byte *)handle - OFFSETOF(MemoryItem, _data)); assert(rec->_id == BLOCK_ID); return rec; @@ -79,7 +79,7 @@ MemoryItem *MemoryManager::getItem(HGLOBAL handle) { /** * Returns a size of a memory block given its pointer */ -uint32 MemoryManager::getSize(HANDLE handle) { +uint32 MemoryManager::getSize(MpalHandle handle) { MemoryItem *item = (MemoryItem *)handle; assert(item->_id == BLOCK_ID); return item->_size; @@ -88,7 +88,7 @@ uint32 MemoryManager::getSize(HANDLE handle) { /** * Erases a given item */ -void MemoryManager::freeBlock(HANDLE handle) { +void MemoryManager::freeBlock(MpalHandle handle) { MemoryItem *item = (MemoryItem *)handle; assert(item->_id == BLOCK_ID); free(item); @@ -97,7 +97,7 @@ void MemoryManager::freeBlock(HANDLE handle) { /** * Erases a given item */ -void MemoryManager::destroyItem(HANDLE handle) { +void MemoryManager::destroyItem(MpalHandle handle) { MemoryItem *item = getItem(handle); assert(item->_id == BLOCK_ID); free(item); @@ -106,7 +106,7 @@ void MemoryManager::destroyItem(HANDLE handle) { /** * Locks an item for access */ -byte *MemoryManager::lockItem(HANDLE handle) { +byte *MemoryManager::lockItem(MpalHandle handle) { MemoryItem *item = (MemoryItem *)handle; assert(item->_id == BLOCK_ID); ++item->_lockCount; @@ -116,7 +116,7 @@ byte *MemoryManager::lockItem(HANDLE handle) { /** * Unlocks a locked item */ -void MemoryManager::unlockItem(HANDLE handle) { +void MemoryManager::unlockItem(MpalHandle handle) { MemoryItem *item = (MemoryItem *)handle; assert(item->_id == BLOCK_ID); assert(item->_lockCount > 0); diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index c7e4896cf9..b557743512 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -31,8 +31,7 @@ namespace Tony { namespace MPAL { -typedef void *HANDLE; -typedef HANDLE HGLOBAL; +typedef void *MpalHandle; struct MemoryItem { uint32 _id; @@ -46,15 +45,15 @@ struct MemoryItem { class MemoryManager { private: - static MemoryItem *getItem(HGLOBAL handle); + static MemoryItem *getItem(MpalHandle handle); public: - static HANDLE allocate(uint32 size, uint flags); + static MpalHandle allocate(uint32 size, uint flags); static void *alloc(uint32 size, uint flags); - static void freeBlock(HANDLE handle); - static void destroyItem(HANDLE handle); - static uint32 getSize(HANDLE handle); - static byte *lockItem(HANDLE handle); - static void unlockItem(HANDLE handle); + static void freeBlock(MpalHandle handle); + static void destroyItem(MpalHandle handle); + static uint32 getSize(MpalHandle handle); + static byte *lockItem(MpalHandle handle); + static void unlockItem(MpalHandle handle); }; // defines diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 9a92fd7766..533a4d22b9 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -360,8 +360,8 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { * @param dwId ID of the resource to load * @returns Handle to the loaded resource */ -HGLOBAL resLoad(uint32 dwId) { - HGLOBAL h; +MpalHandle resLoad(uint32 dwId) { + MpalHandle h; char head[4]; uint32 nBytesRead; uint32 nSizeComp, nSizeDecomp; @@ -461,15 +461,15 @@ static uint32 *GetItemList(uint32 nLoc) { return il; } -static LPITEM getItemData(uint32 nOrdItem) { +static LpItem getItemData(uint32 nOrdItem) { LpMpalItem curitem = GLOBALS._lpmiItems + nOrdItem; - LPITEM ret; - HGLOBAL hDat; + LpItem ret; + MpalHandle hDat; char *dat; char *patlength; // Zeroing out the allocated memory is required!!! - ret = (LPITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); + ret = (LpItem)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(Item)); if (ret == NULL) return NULL; ret->_speed = 150; @@ -536,7 +536,7 @@ static LPITEM getItemData(uint32 nOrdItem) { for (int i = 1; i < ret->_numframe; i++) { uint32 dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * (uint32)(ret->_frameslocations[i].bottom - ret->_frameslocations[i].top); - ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); + ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED, dim); if (ret->_frames[i] == NULL) return NULL; @@ -565,12 +565,12 @@ static LPITEM getItemData(uint32 nOrdItem) { */ void CustomThread(CORO_PARAM, const void *param) { CORO_BEGIN_CONTEXT; - LPCFCALL p; + LpCfCall p; CORO_END_CONTEXT(_ctx); CORO_BEGIN_CODE(_ctx); - _ctx->p = *(LPCFCALL *)param; + _ctx->p = *(LpCfCall *)param; CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->p->_nCf], _ctx->p->_arg1, _ctx->p->_arg2, _ctx->p->_arg3, _ctx->p->_arg4); @@ -593,7 +593,7 @@ void ScriptThread(CORO_PARAM, const void *param) { uint32 dwCurTime; uint32 dwId; int numHandles; - LPCFCALL p; + LpCfCall p; CORO_END_CONTEXT(_ctx); static uint32 cfHandles[MAX_COMMANDS_PER_MOMENT]; @@ -604,7 +604,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->dwStartTime = g_vm->getTime(); _ctx->numHandles = 0; -// debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n",s->nMoments); +// debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Moments: %u\n", s->_nMoments); for (_ctx->i = 0; _ctx->i < s->_nMoments; _ctx->i++) { // Sleep for the required time if (s->_moment[_ctx->i]._dwTime == -1) { @@ -613,8 +613,8 @@ void ScriptThread(CORO_PARAM, const void *param) { } else { _ctx->dwCurTime = g_vm->getTime(); if (_ctx->dwCurTime < _ctx->dwStartTime + (s->_moment[_ctx->i]._dwTime * 100)) { - // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime); - CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime+(s->_moment[_ctx->i]._dwTime * 100) - _ctx->dwCurTime); + // debugC(DEBUG_BASIC, kTonyDebugMPAL, "PlayScript(): Sleeping %lums\n",_ctx->dwStartTime + (s->_moment[_ctx->i]._dwTime*100) - _ctx->dwCurTime); + CORO_INVOKE_1(CoroScheduler.sleep, _ctx->dwStartTime + (s->_moment[_ctx->i]._dwTime * 100) - _ctx->dwCurTime); } } @@ -623,7 +623,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->k = s->_moment[_ctx->i]._cmdNum[_ctx->j]; if (s->_command[_ctx->k]._type == 1) { - _ctx->p = (LPCFCALL)globalAlloc(GMEM_FIXED, sizeof(CFCALL)); + _ctx->p = (LpCfCall)globalAlloc(GMEM_FIXED, sizeof(CfCall)); if (_ctx->p == NULL) { GLOBALS._mpalError = 1; @@ -638,7 +638,7 @@ void ScriptThread(CORO_PARAM, const void *param) { _ctx->p->_arg4 = s->_command[_ctx->k]._arg4; // !!! New process management - if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) { + if ((cfHandles[_ctx->numHandles++] = CoroScheduler.createProcess(CustomThread, &_ctx->p, sizeof(LpCfCall))) == 0) { GLOBALS._mpalError = 1; CORO_KILL_SELF(); @@ -775,14 +775,14 @@ void ShutUpActionThread(CORO_PARAM, const void *param) { */ void LocationPollThread(CORO_PARAM, const void *param) { typedef struct { - uint32 _nItem, _nAction; - - uint16 _wTime; - byte _perc; - HGLOBAL _when; - byte _nCmds; - uint16 _cmdNum[MAX_COMMANDS_PER_ACTION]; - uint32 _dwLastTime; + uint32 _nItem, _nAction; + + uint16 _wTime; + byte _perc; + MpalHandle _when; + byte _nCmds; + uint16 _cmdNum[MAX_COMMANDS_PER_ACTION]; + uint32 _dwLastTime; } MYACTION; typedef struct { @@ -795,7 +795,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { int i, j, k; int numitems; int nRealItems; - LpMpalItem curItem,newItem; + LpMpalItem curItem, newItem; int nIdleActions; uint32 curTime; uint32 dwSleepTime; @@ -1012,7 +1012,7 @@ void LocationPollThread(CORO_PARAM, const void *param) { // Create the process if ((_ctx->myThreads[_ctx->i]._hThread = CoroScheduler.createProcess(ActionThread, &_ctx->newItem, sizeof(LpMpalItem))) == CORO_INVALID_PID_VALUE) { - //if ((_ctx->myThreads[_ctx->i]._hThread = (void*)_beginthread(ActionThread, 10240,(void *)_ctx->newItem)) == (void*)-1) + //if ((_ctx->myThreads[_ctx->i]._hThread = (void*)_beginthread(ActionThread, 10240, (void *)_ctx->newItem)) == (void*)-1) globalDestroy(_ctx->newItem); globalDestroy(_ctx->myThreads); globalDestroy(_ctx->myActions); @@ -1298,8 +1298,8 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // In the new version number of the action in writing dwRes Common::copy((byte *)item, (byte *)item + sizeof(MpalItem), (byte *)newitem); - //newitem->Action[0].nCmds=item->Action[i].nCmds; - //memcpy(newitem->Action[0].CmdNum,item->Action[i].CmdNum,newitem->Action[0].nCmds*sizeof(newitem->Action[0].CmdNum[0])); + //newitem->_action[0]._nCmds=item->_action[i]._nCmds; + //memcpy(newitem->_action[0]._cmdNum, item->_action[i]._cmdNum, newitem->Action[0].nCmds * sizeof(newitem->_action[0]._cmdNum[0])); newitem->_dwRes = i; @@ -1630,7 +1630,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { } else if (wQueryType == MPQ_ITEM_DATA) { /* - * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); + * LpItem mpalQuery(MPQ_ITEM_DATA, uint32 nItem); */ error("mpalQuery(MPQ_ITEM_DATA, uint32 nItem) used incorrect variant"); @@ -1747,7 +1747,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * @remarks This is the specialised version of the original single mpalQuery * method that returns a pointer or handle. */ -HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { +MpalHandle mpalQueryHANDLE(uint16 wQueryType, ...) { char *n; Common::String buf; va_list v; @@ -1813,7 +1813,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { } else if (wQueryType == MPQ_ITEM_DATA) { /* - * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem); + * LpItem mpalQuery(MPQ_ITEM_DATA, uint32 nItem); */ lockItems(); hRet = getItemData(itemGetOrderFromNum(GETARG(uint32))); @@ -2008,7 +2008,7 @@ bool mpalStartIdlePoll(int nLoc) { GLOBALS._hEndPollingLocations[i] = CoroScheduler.createEvent(true, false); // !!! New process management if ((GLOBALS._pollingThreads[i] = CoroScheduler.createProcess(LocationPollThread, &i, sizeof(uint32))) == CORO_INVALID_PID_VALUE) -// if ((GLOBALS.hEndPollingLocations[i] = (void*)_beginthread(LocationPollThread, 10240,(void *)i))= = (void*)-1) +// if ((GLOBALS.hEndPollingLocations[i] = (void*)_beginthread(LocationPollThread, 10240, (void *)i))= = (void*)-1) return false; return true; diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index 1af0f2c9e9..c5f505063f 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -100,11 +100,8 @@ namespace MPAL { #define MAXFRAMES 400 // frame animation of an object #define MAXPATTERN 40 // pattern of animation of an object - #define MAXPOLLINGLOCATIONS 64 -#define LPSTR char * - /** * Macro for use with queries that may refer to X and Y co-ordinates */ @@ -113,7 +110,6 @@ enum QueryCoordinates { MPQ_Y }; - /** * Query can be used with mpalQuery methods. In practice corresponds all claims * that can do at the library @@ -164,8 +160,8 @@ typedef struct { short _destX, _destY; signed char _destZ; short _objectID; -} ITEM; -typedef ITEM *LPITEM; +} Item; +typedef Item *LpItem; /** @@ -228,7 +224,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * after use. The message will be in ASCIIZ format. */ #define mpalQueryMessage(nMsg) \ - (LPSTR)mpalQueryHANDLE(MPQ_MESSAGE, (uint32)(nMsg)) + (char *)mpalQueryHANDLE(MPQ_MESSAGE, (uint32)(nMsg)) /** @@ -246,7 +242,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @param dwCoord MPQ_X or MPQ_Y coordinate to retrieve * @returns Size */ -#define mpalQueryLocationSize(nLoc,dwCoord) \ +#define mpalQueryLocationSize(nLoc, dwCoord) \ mpalQueryDWORD(MPQ_LOCATION_SIZE, (uint32)(nLoc), (uint32)(dwCoord)) @@ -268,7 +264,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @returns Structure filled with requested information */ #define mpalQueryItemData(nItem) \ - (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA, (uint32)(nItem)) + (LpItem)mpalQueryHANDLE(MPQ_ITEM_DATA, (uint32)(nItem)) /** @@ -302,7 +298,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * is less than or equal to 0), the string will be empty. */ #define mpalQueryItemName(nItem, lpszName) \ - mpalQueryHANDLE(MPQ_ITEM_NAME, (uint32)(nItem), (LPSTR)(lpszName)) + mpalQueryHANDLE(MPQ_ITEM_NAME, (uint32)(nItem), (char *)(lpszName)) /** @@ -316,7 +312,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * string terminated with 0. */ #define mpalQueryDialogPeriod(nPeriod) \ - (LPSTR)mpalQueryHANDLE(MPQ_DIALOG_PERIOD, (uint32)(nPeriod)) + (char *)mpalQueryHANDLE(MPQ_DIALOG_PERIOD, (uint32)(nPeriod)) /** @@ -379,8 +375,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION; * @returns Handle to the thread that is running the box, or * CORO_INVALID_PID_VALUE if the dialogue does not exist. */ -#define mpalQueryDoDialog(nDialog,nGroup) \ - mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup)) +#define mpalQueryDoDialog(nDialog, nGroup) \ + mpalQueryDWORD(MPQ_DO_DIALOG, (uint32)(nDialog), (uint32)(nGroup)) /** * @defgroup Functions exported to the main game @@ -422,7 +418,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...); * @remarks This is the specialised version of the original single mpalQuery * method that returns a pointer or handle. */ -HANDLE mpalQueryHANDLE(uint16 wQueryType, ...); +MpalHandle mpalQueryHANDLE(uint16 wQueryType, ...); /** * This is a general function to communicate with the library, to request information diff --git a/engines/tony/mpal/mpaldll.h b/engines/tony/mpal/mpaldll.h index 853b5b2dac..8897096f51 100644 --- a/engines/tony/mpal/mpaldll.h +++ b/engines/tony/mpal/mpaldll.h @@ -82,8 +82,8 @@ typedef MpalVar *LpMpalVar; * MPAL Messages */ struct MpalMsg { - HGLOBAL _hText; // Handle to the message text - uint16 _wNum; // Message number + MpalHandle _hText; // Handle to the message text + uint16 _wNum; // Message number } PACKED_STRUCT; typedef MpalMsg *LpMpalMsg; @@ -110,7 +110,7 @@ struct Command { * #3 -> Making a choice (DIALOG) * */ - byte _type; // Type of control + byte _type; // Type of control union { int32 _nCf; // Custom function call [#1] @@ -120,10 +120,10 @@ struct Command { union { int32 _arg1; // Argument for custom function [#1] - HGLOBAL _expr; // Expression to assign to a variable [#2] + MpalHandle _expr; // Expression to assign to a variable [#2] }; - int32 _arg2, _arg3, _arg4; // Arguments for custom function [#1] + int32 _arg2, _arg3, _arg4; // Arguments for custom function [#1] } PACKED_STRUCT; @@ -148,7 +148,7 @@ struct MpalDialog { // The select number (we're pretty stingy with RAM). The last select has dwData == 0 struct { - HGLOBAL _when; + MpalHandle _when; uint32 _dwData; uint16 _wPlayGroup[MAX_PLAYGROUPS_PER_SELECT]; @@ -163,7 +163,7 @@ struct MpalDialog { } _choice[MAX_CHOICES_PER_DIALOG]; uint16 _periodNums[MAX_PERIODS_PER_DIALOG]; - HGLOBAL _periods[MAX_PERIODS_PER_DIALOG]; + MpalHandle _periods[MAX_PERIODS_PER_DIALOG]; } PACKED_STRUCT; typedef MpalDialog *LpMpalDialog; @@ -175,20 +175,20 @@ struct ItemAction { byte _num; // Action number uint16 _wTime; // If idle, the time which must pass byte _perc; // Percentage of the idle run - HGLOBAL _when; // Expression to compute. If != 0, then - // action can be done + MpalHandle _when; // Expression to compute. If != 0, then + // action can be done uint16 _wParm; // Parameter for action - byte _nCmds; // Number of commands to be executed + byte _nCmds; // Number of commands to be executed uint32 _cmdNum[MAX_COMMANDS_PER_ACTION]; // Commands to execute } PACKED_STRUCT; struct MpalItem { - uint32 _nObj; // Item number + uint32 _nObj; // Item number byte _lpszDescribe[MAX_DESCRIBE_SIZE]; // Name - byte _nActions; // Number of managed actions - uint32 _dwRes; // Resource that contains frames and patterns + byte _nActions; // Number of managed actions + uint32 _dwRes; // Resource that contains frames and patterns struct Command _command[MAX_COMMANDS_PER_ITEM]; diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index 19e4fa7778..8bc3e1d7c6 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -37,7 +37,7 @@ namespace MPAL { class RMRes { protected: - HGLOBAL _h; + MpalHandle _h; byte *_buf; public: -- cgit v1.2.3 From 3ab8ebc4f72e54a5ffcabaa22d3cf8e250062457 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 1 Sep 2012 02:27:31 +0200 Subject: TONY: Move some more code from .h to .cpp files --- engines/tony/mpal/memory.h | 14 +++++++------- engines/tony/mpal/mpalutils.cpp | 4 ++++ engines/tony/mpal/mpalutils.h | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index b557743512..ba7865938f 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -57,13 +57,13 @@ public: }; // defines -#define globalAlloc(flags, size) MemoryManager::alloc(size, flags) -#define globalAllocate(flags, size) MemoryManager::allocate(size, flags) -#define globalFree(handle) MemoryManager::freeBlock(handle) -#define globalDestroy(handle) MemoryManager::destroyItem(handle) -#define globalLock(handle) MemoryManager::lockItem(handle) -#define globalUnlock(handle) MemoryManager::unlockItem(handle) -#define globalSize(handle) MemoryManager::getSize(handle) +#define globalAlloc(flags, size) MemoryManager::alloc(size, flags) +#define globalAllocate(flags, size) MemoryManager::allocate(size, flags) +#define globalFree(handle) MemoryManager::freeBlock(handle) +#define globalDestroy(handle) MemoryManager::destroyItem(handle) +#define globalLock(handle) MemoryManager::lockItem(handle) +#define globalUnlock(handle) MemoryManager::unlockItem(handle) +#define globalSize(handle) MemoryManager::getSize(handle) #define GMEM_FIXED 1 #define GMEM_MOVEABLE 2 diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index bfc97a5f3d..92d4af37fc 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -80,6 +80,10 @@ Common::SeekableReadStream *RMRes::getReadStream() { return new Common::MemoryReadStream(_buf, size()); } +bool RMRes::isValid() { + return _h != NULL; +} + /****************************************************************************\ * RMResRaw methods \****************************************************************************/ diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index 8bc3e1d7c6..629e157e29 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -47,7 +47,7 @@ public: // Attributes unsigned int size(); const byte *dataPointer(); - bool isValid() { return _h != NULL; } + bool isValid(); // Casting for access to data operator const byte*(); @@ -63,8 +63,8 @@ public: const byte *dataPointer(); operator const byte*(); - int width(); - int height(); + int width(); + int height(); }; } // end of namespace MPAL -- cgit v1.2.3 From 35a7e79614673509870ad9421020e34fccbede71 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Sep 2012 20:47:32 +1000 Subject: TONY: Change to hopefully fix Mingw 64 compilation errors --- engines/tony/mpal/mpal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 533a4d22b9..10f5753540 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -570,7 +570,7 @@ void CustomThread(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - _ctx->p = *(LpCfCall *)param; + _ctx->p = *(const LpCfCall *)param; CORO_INVOKE_4(GLOBALS._lplpFunctions[_ctx->p->_nCf], _ctx->p->_arg1, _ctx->p->_arg2, _ctx->p->_arg3, _ctx->p->_arg4); @@ -693,7 +693,7 @@ void ActionThread(CORO_PARAM, const void *param) { // The ActionThread owns the data block pointed to, so we need to make sure it's // freed when the process exits - _ctx->item = *(LpMpalItem *)param; + _ctx->item = *(const LpMpalItem *)param; GLOBALS._mpalError = 0; for (_ctx->j = 0; _ctx->j < _ctx->item->_action[_ctx->item->_dwRes]._nCmds; _ctx->j++) { -- cgit v1.2.3 From 220e945d6746ce22c655b2893f7ce0c001d811a6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 5 Sep 2012 22:32:02 +1000 Subject: TONY: Bugfix for OFFSETOF macro on 64-bit systems --- engines/tony/mpal/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 428c07b3b7..78b036e657 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -64,7 +64,7 @@ void *MemoryManager::alloc(uint32 size, uint flags) { return &item->_data[0]; } -#define OFFSETOF(type, field) ((unsigned long) &(((type *) 0)->field)) +#define OFFSETOF(type, field) ((size_t) &(((type *) 0)->field)) /** * Returns a reference to the MemoryItem for a gien byte pointer -- cgit v1.2.3 From 25f4a3fb0838a8ed658e76eabd78f3ce2f5661e6 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 6 Sep 2012 00:23:59 +0200 Subject: TONY: Misc cleanup --- engines/tony/mpal/expr.cpp | 92 ++++++------------------------------------- engines/tony/mpal/expr.h | 61 ++++++++++++++++++++++++++++ engines/tony/mpal/loadmpc.cpp | 6 +-- engines/tony/mpal/memory.cpp | 2 - engines/tony/mpal/memory.h | 2 + engines/tony/mpal/mpal.cpp | 27 +++---------- engines/tony/mpal/mpal.h | 2 + 7 files changed, 84 insertions(+), 108 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index 7923d263c0..824cd91651 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -35,68 +35,6 @@ namespace Tony { namespace MPAL { -/** - * @defgroup Mathamatical operations - */ -//@{ - -#define OP_MUL ((1 << 4) | 0) -#define OP_DIV ((1 << 4) | 1) -#define OP_MODULE ((1 << 4) | 2) -#define OP_ADD ((2 << 4) | 0) -#define OP_SUB ((2 << 4) | 1) -#define OP_SHL ((3 << 4) | 0) -#define OP_SHR ((3 << 4) | 1) -#define OP_MINOR ((4 << 4) | 0) -#define OP_MAJOR ((4 << 4) | 1) -#define OP_MINEQ ((4 << 4) | 2) -#define OP_MAJEQ ((4 << 4) | 3) -#define OP_EQUAL ((5 << 4) | 0) -#define OP_NOEQUAL ((5 << 4) | 1) -#define OP_BITAND ((6 << 4) | 0) -#define OP_BITXOR ((7 << 4) | 0) -#define OP_BITOR ((8 << 4) | 0) -#define OP_AND ((9 << 4) | 0) -#define OP_OR ((10 << 4) | 0) - - -/** - * Object types that can be contained in an EXPRESSION structure - */ -enum ExprListTypes { - ELT_NUMBER = 1, - ELT_VAR = 2, - ELT_PARENTH = 3, - ELT_PARENTH2 = 4 -}; - -//@} - -/** - * @defgroup Structures - */ -//@{ - -/** - * Mathamatical framework to manage operations - */ -typedef struct { - byte _type; // Tipo di oggetto (vedi enum ExprListTypes) - byte _unary; // Unary operatore (NON SUPPORTATO) - - union { - int _num; // Numero (se type==ELT_NUMBER) - char *_name; // Nome variabile (se type==ELT_VAR) - MpalHandle _son; // Handle a espressione (type==ELT_PARENTH) - byte *_pson; // Handle lockato (type==ELT_PARENTH2) - } _val; - - byte _symbol; // Simbolo matematico (vedi #define OP_*) - -} Expression; -typedef Expression *LpExpression; - -//@} /** * Duplicate a mathematical expression. @@ -106,15 +44,14 @@ typedef Expression *LpExpression; */ static byte *duplicateExpression(MpalHandle h) { byte *orig, *clone; - LpExpression one, two; orig = (byte *)globalLock(h); int num = *(byte *)orig; - one = (LpExpression)(orig+1); + LpExpression one = (LpExpression)(orig+1); clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(Expression) * num + 1); - two = (LpExpression)(clone + 1); + LpExpression two = (LpExpression)(clone + 1); memcpy(clone, orig, sizeof(Expression) * num + 1); @@ -180,7 +117,6 @@ static int Compute(int a, int b, byte symbol) { static void solve(LpExpression one, int num) { LpExpression two, three; - int j; while (num > 1) { two = one + 1; @@ -189,7 +125,7 @@ static void solve(LpExpression one, int num) { memmove(one, two, (num - 1) * sizeof(Expression)); --num; } else { - j = 1; + int j = 1; three = two + 1; while ((three->_symbol != 0) && (two->_symbol & 0xF0) > (three->_symbol & 0xF0)) { ++two; @@ -213,13 +149,11 @@ static void solve(LpExpression one, int num) { * @returns Value */ static int evaluateAndFreeExpression(byte *expr) { - LpExpression one, cur; - int num = *expr; - one = (LpExpression)(expr + 1); + LpExpression one = (LpExpression)(expr + 1); // 1) Substitutions of variables - cur = one; + LpExpression cur = one; for (int i = 0; i < num; i++, cur++) { if (cur->_type == ELT_VAR) { cur->_type = ELT_NUMBER; @@ -254,7 +188,6 @@ static int evaluateAndFreeExpression(byte *expr) { * @returns Pointer to the buffer immediately after the expression, or NULL if error. */ const byte *parseExpression(const byte *lpBuf, MpalHandle *h) { - LpExpression cur; byte *start; uint32 num = *lpBuf; @@ -270,12 +203,14 @@ const byte *parseExpression(const byte *lpBuf, MpalHandle *h) { start = (byte *)globalLock(*h); *start = (byte)num; - cur = (LpExpression)(start + 1); + LpExpression cur = (LpExpression)(start + 1); for (uint32 i = 0;i < num; i++) { cur->_type = *(lpBuf); - cur->_unary = *(lpBuf + 1); + + // *(lpBuf + 1) contains the unary operator, unused => skipped lpBuf += 2; + switch (cur->_type) { case ELT_NUMBER: cur->_val._num = (int32)READ_LE_UINT32(lpBuf); @@ -322,10 +257,8 @@ const byte *parseExpression(const byte *lpBuf, MpalHandle *h) { * @returns Numeric value */ int evaluateExpression(MpalHandle h) { - int ret; - lockVar(); - ret = evaluateAndFreeExpression(duplicateExpression(h)); + int ret = evaluateAndFreeExpression(duplicateExpression(h)); unlockVar(); return ret; @@ -339,7 +272,6 @@ int evaluateExpression(MpalHandle h) { */ bool compareExpressions(MpalHandle h1, MpalHandle h2) { byte *e1, *e2; - LpExpression one, two; e1 = (byte *)globalLock(h1); e2 = (byte *)globalLock(h2); @@ -353,8 +285,8 @@ bool compareExpressions(MpalHandle h1, MpalHandle h2) { return false; } - one = (LpExpression)(e1 + 1); - two = (LpExpression)(e2 + 1); + LpExpression one = (LpExpression)(e1 + 1); + LpExpression two = (LpExpression)(e2 + 1); for (int i = 0; i < num1; i++) { if (one->_type != two->_type || (i != num1 - 1 && one->_symbol != two->_symbol)) { diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h index 9036099993..405624b4fe 100644 --- a/engines/tony/mpal/expr.h +++ b/engines/tony/mpal/expr.h @@ -35,6 +35,67 @@ namespace Tony { namespace MPAL { +/** + * @defgroup Mathamatical operations + */ +//@{ + +#define OP_MUL ((1 << 4) | 0) +#define OP_DIV ((1 << 4) | 1) +#define OP_MODULE ((1 << 4) | 2) +#define OP_ADD ((2 << 4) | 0) +#define OP_SUB ((2 << 4) | 1) +#define OP_SHL ((3 << 4) | 0) +#define OP_SHR ((3 << 4) | 1) +#define OP_MINOR ((4 << 4) | 0) +#define OP_MAJOR ((4 << 4) | 1) +#define OP_MINEQ ((4 << 4) | 2) +#define OP_MAJEQ ((4 << 4) | 3) +#define OP_EQUAL ((5 << 4) | 0) +#define OP_NOEQUAL ((5 << 4) | 1) +#define OP_BITAND ((6 << 4) | 0) +#define OP_BITXOR ((7 << 4) | 0) +#define OP_BITOR ((8 << 4) | 0) +#define OP_AND ((9 << 4) | 0) +#define OP_OR ((10 << 4) | 0) + +//@} + +/** + * @defgroup Structures + */ + +//@{ +/** + * Mathamatical framework to manage operations + */ +typedef struct { + byte _type; // Object Type (see enum ExprListTypes) + + union { + int _num; // Identifier (if type == ELT_NUMBER) + char *_name; // Variable name (if type == ELT_VAR) + MpalHandle _son; // Handle expressions (if type == ELT_PARENTH) + byte *_pson; // Handle lockato (if type == ELT_PARENTH2) + } _val; + + byte _symbol; // Mathematic symbols (see #define OP_*) + +} Expression; +typedef Expression *LpExpression; + +//@} + +/** + * Object types that can be contained in an EXPRESSION structure + */ +enum ExprListTypes { + ELT_NUMBER = 1, + ELT_VAR = 2, + ELT_PARENTH = 3, + ELT_PARENTH2 = 4 +}; + /****************************************************************************\ * Function Prototypes \****************************************************************************/ diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 953820be74..9c45cdf982 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -139,7 +139,6 @@ static void FreeScript(LpMpalScript lpmsScript) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *parseDialog(const byte *lpBuf, LpMpalDialog lpmdDialog) { - uint32 num2, num3; byte *lpLock; lpmdDialog->_nObj = READ_LE_UINT32(lpBuf); @@ -266,7 +265,7 @@ static const byte *parseDialog(const byte *lpBuf, LpMpalDialog lpmdDialog) { lpmdDialog->_choice[i]._nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; - num2 = *lpBuf++; + uint32 num2 = *lpBuf++; if (num2 >= MAX_SELECTS_PER_CHOICE) error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i]._nChoice, lpmdDialog->_nObj); @@ -296,7 +295,7 @@ static const byte *parseDialog(const byte *lpBuf, LpMpalDialog lpmdDialog) { lpBuf += 4; // PlayGroup - num3 = *lpBuf++; + uint32 num3 = *lpBuf++; if (num3 >= MAX_PLAYGROUPS_PER_SELECT) error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i]._nChoice, lpmdDialog->_nObj); @@ -365,7 +364,6 @@ static const byte *parseItem(const byte *lpBuf, LpMpalItem lpmiItem) { lpBuf++; } - if (*lpBuf == 0) { lpBuf++; lpmiItem->_action[i]._when = NULL; diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp index 78b036e657..dfbf16e789 100644 --- a/engines/tony/mpal/memory.cpp +++ b/engines/tony/mpal/memory.cpp @@ -33,8 +33,6 @@ namespace MPAL { * MemoryManager methods \****************************************************************************/ -const uint32 BLOCK_ID = 0x12345678; - /** * Allocates a new memory block * @return Returns a MemoryItem instance for the new block diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h index ba7865938f..9c21cc20e6 100644 --- a/engines/tony/mpal/memory.h +++ b/engines/tony/mpal/memory.h @@ -69,6 +69,8 @@ public: #define GMEM_MOVEABLE 2 #define GMEM_ZEROINIT 4 +const uint32 BLOCK_ID = 0x12345678; + } // end of namespace MPAL } // end of namespace Tony diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index 10f5753540..da18b538d5 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -39,19 +39,6 @@ namespace Tony { namespace MPAL { -#define GETARG(type) va_arg(v, type) - -/****************************************************************************\ -* Copyright -\****************************************************************************/ - -const char *mpalCopyright = - "\n\nMPAL - MultiPurpose Adventure Language for Windows 95\n" - "Copyright 1997-98 Giovanni Bajo and Luca Giusti\n" - "ALL RIGHTS RESERVED\n" - "\n" - "\n"; - /****************************************************************************\ * Internal functions \****************************************************************************/ @@ -363,24 +350,22 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { MpalHandle resLoad(uint32 dwId) { MpalHandle h; char head[4]; - uint32 nBytesRead; - uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; for (int i = 0; i < GLOBALS._nResources; i++) if (GLOBALS._lpResources[i * 2] == dwId) { GLOBALS._hMpr.seek(GLOBALS._lpResources[i * 2 + 1]); - nBytesRead = GLOBALS._hMpr.read(head, 4); + uint32 nBytesRead = GLOBALS._hMpr.read(head, 4); if (nBytesRead != 4) return NULL; if (head[0] != 'R' || head[1] != 'E' || head[2] != 'S' || head[3] != 'D') return NULL; - nSizeDecomp = GLOBALS._hMpr.readUint32LE(); + uint32 nSizeDecomp = GLOBALS._hMpr.readUint32LE(); if (GLOBALS._hMpr.err()) return NULL; - nSizeComp = GLOBALS._hMpr.readUint32LE(); + uint32 nSizeComp = GLOBALS._hMpr.readUint32LE(); if (GLOBALS._hMpr.err()) return NULL; @@ -463,18 +448,16 @@ static uint32 *GetItemList(uint32 nLoc) { static LpItem getItemData(uint32 nOrdItem) { LpMpalItem curitem = GLOBALS._lpmiItems + nOrdItem; - LpItem ret; - MpalHandle hDat; char *dat; char *patlength; // Zeroing out the allocated memory is required!!! - ret = (LpItem)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(Item)); + LpItem ret = (LpItem)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(Item)); if (ret == NULL) return NULL; ret->_speed = 150; - hDat = resLoad(curitem->_dwRes); + MpalHandle hDat = resLoad(curitem->_dwRes); dat = (char *)globalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h index c5f505063f..5e1b02b3fc 100644 --- a/engines/tony/mpal/mpal.h +++ b/engines/tony/mpal/mpal.h @@ -102,6 +102,8 @@ namespace MPAL { #define MAXPATTERN 40 // pattern of animation of an object #define MAXPOLLINGLOCATIONS 64 +#define GETARG(type) va_arg(v, type) + /** * Macro for use with queries that may refer to X and Y co-ordinates */ -- cgit v1.2.3 From c91a72a9d5cf5b4f73fc0544231aefe2258f9e52 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 6 Sep 2012 08:26:08 +0200 Subject: TONY: Some more cleanup --- engines/tony/mpal/mpal.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index da18b538d5..e9964203c8 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -1386,11 +1386,7 @@ bool doSelection(uint32 i, uint32 dwData) { */ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, LPLPCUSTOMFUNCTION lplpcfArray, Common::String *lpcfStrings) { - Common::File hMpc; byte buf[5]; - uint32 nBytesRead; - bool bCompress; - uint32 dwSizeDecomp, dwSizeComp; byte *cmpbuf; // Save the array of custom functions @@ -1398,21 +1394,22 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, GLOBALS._lplpFunctionStrings = lpcfStrings; // OPen the MPC file for reading + Common::File hMpc; if (!hMpc.open(lpszMpcFileName)) return false; // Read and check the header - nBytesRead = hMpc.read(buf, 5); + uint32 nBytesRead = hMpc.read(buf, 5); if (nBytesRead != 5) return false; if (buf[0] != 'M' || buf[1] != 'P' || buf[2] != 'C' || buf[3] != 0x20) return false; - bCompress = buf[4]; + bool bCompress = buf[4]; // Reads the size of the uncompressed file, and allocate memory - dwSizeDecomp = hMpc.readUint32LE(); + uint32 dwSizeDecomp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1422,7 +1419,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, if (bCompress) { // Get the compressed size and read the data in - dwSizeComp = hMpc.readUint32LE(); + uint32 dwSizeComp = hMpc.readUint32LE(); if (hMpc.err()) return false; @@ -1463,7 +1460,7 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName, // Seek to the end of the file to read overall information GLOBALS._hMpr.seek(-12, SEEK_END); - dwSizeComp = GLOBALS._hMpr.readUint32LE(); + uint32 dwSizeComp = GLOBALS._hMpr.readUint32LE(); if (GLOBALS._hMpr.err()) return false; @@ -1941,11 +1938,9 @@ uint32 mpalGetError() { * @returns TRUE if the script 'was launched, FALSE on failure */ bool mpalExecuteScript(int nScript) { - LpMpalScript s; - LockScripts(); int n = scriptGetOrderFromNum(nScript); - s = (LpMpalScript)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MpalScript)); + LpMpalScript s = (LpMpalScript)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MpalScript)); if (s == NULL) return false; -- cgit v1.2.3 From 05fbc2876748acecd17f61e3ccec2634edd03a0c Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 7 Sep 2012 20:51:17 +0200 Subject: TONY: Wait for events to pulse in 'threads'. This fixes some missing animations, which weren't getting an opportunity to start. --- engines/tony/mpal/mpal.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index e9964203c8..8d83363c24 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -642,6 +642,9 @@ void ScriptThread(CORO_PARAM, const void *param) { CORO_KILL_SELF(); return; } + + // WORKAROUND: Wait for events to pulse. + CORO_SLEEP(1); } } @@ -710,6 +713,9 @@ void ActionThread(CORO_PARAM, const void *param) { GLOBALS._mpalError = 1; break; } + + // WORKAROUND: Wait for events to pulse. + CORO_SLEEP(1); } globalDestroy(_ctx->item); @@ -1121,6 +1127,9 @@ void GroupThread(CORO_PARAM, const void *param) { CORO_KILL_SELF(); return; } + + // WORKAROUND: Wait for events to pulse. + CORO_SLEEP(1); } // The gruop is finished, so we can return to the calling function. -- cgit v1.2.3 From 89abab97e3124fa25eb4c7d3e8b38501747a8d17 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 26 Sep 2012 04:17:31 +0200 Subject: JANITORIAL: Remove trailing whitespaces. Powered by: git ls-files "*.cpp" "*.h" "*.m" "*.mm" | xargs sed -i -e 's/[ \t]*$//' --- engines/tony/mpal/mpalutils.cpp | 2 +- engines/tony/mpal/mpalutils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/tony/mpal') diff --git a/engines/tony/mpal/mpalutils.cpp b/engines/tony/mpal/mpalutils.cpp index 92d4af37fc..0919aed5ac 100644 --- a/engines/tony/mpal/mpalutils.cpp +++ b/engines/tony/mpal/mpalutils.cpp @@ -81,7 +81,7 @@ Common::SeekableReadStream *RMRes::getReadStream() { } bool RMRes::isValid() { - return _h != NULL; + return _h != NULL; } /****************************************************************************\ diff --git a/engines/tony/mpal/mpalutils.h b/engines/tony/mpal/mpalutils.h index 629e157e29..d92bb6f9a2 100644 --- a/engines/tony/mpal/mpalutils.h +++ b/engines/tony/mpal/mpalutils.h @@ -59,7 +59,7 @@ class RMResRaw : public RMRes { public: RMResRaw(uint32 resID); virtual ~RMResRaw(); - + const byte *dataPointer(); operator const byte*(); -- cgit v1.2.3