mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-03 08:40:59 +00:00
TONY: Implemented RMGameBoxes class and all dependent classes
This commit is contained in:
parent
4784367deb
commit
118f5ca010
269
engines/tony/loc.cpp
Normal file
269
engines/tony/loc.cpp
Normal file
@ -0,0 +1,269 @@
|
||||
/* 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.
|
||||
*
|
||||
*/
|
||||
/**************************************************************************
|
||||
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* Nayma Software srl *
|
||||
* e -= We create much MORE than ALL =- *
|
||||
* u- z$$$c '. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* .d" d$$$$$b "b. *
|
||||
* .z$* d$$$$$$$L ^*$c. *
|
||||
* #$$$. $$$$$$$$$ .$$$" Project: Roasted Moths........ *
|
||||
* ^*$b 4$$$$$$$$$F .d$*" *
|
||||
* ^$$. 4$$$$$$$$$F .$P" Module: Loc.CPP.............. *
|
||||
* *$. '$$$$$$$$$ 4$P 4 *
|
||||
* J *$ "$$$$$$$" $P r Author: Giovanni Bajo........ *
|
||||
* z$ '$$$P*4c.*$$$*.z@*R$$$ $. *
|
||||
* z$" "" #$F^ "" '$c Desc: Classi di gestione *
|
||||
* z$$beu .ue=" $ "=e.. .zed$$c dei dati di una loca- *
|
||||
* "#$e z$*" . `. ^*Nc e$"" zione................ *
|
||||
* "$$". .r" ^4. .^$$" ..................... *
|
||||
* ^.@*"6L=\ebu^+C$"*b." *
|
||||
* "**$. "c 4$$$ J" J$P*" OS: [ ] DOS [X] WIN95 [ ] PORT *
|
||||
* ^"--.^ 9$" .--"" COMP: [ ] WATCOM [X] VISUAL C++ *
|
||||
* " [ ] EIFFEL [ ] GCC/GXX/DJGPP *
|
||||
* *
|
||||
* This source code is Copyright (C) Nayma Software. ALL RIGHTS RESERVED *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "tony/loc.h"
|
||||
#include "tony/utils.h"
|
||||
#include "tony/mpal/lzo.h"
|
||||
#include "tony/mpal/mpalutils.h"
|
||||
|
||||
namespace Tony {
|
||||
|
||||
using namespace ::Tony::MPAL;
|
||||
|
||||
/****************************************************************************\
|
||||
* RMBox Methods
|
||||
\****************************************************************************/
|
||||
|
||||
void RMBox::ReadFromStream(RMDataStream &ds) {
|
||||
uint16 w;
|
||||
int i;
|
||||
byte b;
|
||||
|
||||
// Bbox
|
||||
ds >> left;
|
||||
ds >> top;
|
||||
ds >> right;
|
||||
ds >> bottom;
|
||||
|
||||
// Adiacenza
|
||||
for (i = 0; i < MAXBOXES; i++)
|
||||
{
|
||||
ds >> adj[i];
|
||||
}
|
||||
|
||||
// Misc
|
||||
ds >> numhotspot;
|
||||
ds >> Zvalue;
|
||||
ds >> b;
|
||||
attivo = b;
|
||||
ds >> b;
|
||||
bReversed = b;
|
||||
|
||||
// Spazio di espansione
|
||||
ds+=30;
|
||||
|
||||
// Hotspots
|
||||
for (i = 0; i < numhotspot; i++) {
|
||||
ds >> w; hotspot[i].hotx = w;
|
||||
ds >> w; hotspot[i].hoty = w;
|
||||
ds >> w; hotspot[i].destination = w;
|
||||
}
|
||||
}
|
||||
|
||||
RMDataStream& operator>>(RMDataStream &ds, RMBox &box) {
|
||||
box.ReadFromStream(ds);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
/****************************************************************************\
|
||||
* RMBoxLoc Methods
|
||||
\****************************************************************************/
|
||||
|
||||
void RMBoxLoc::ReadFromStream(RMDataStream& ds) {
|
||||
int i;
|
||||
char buf[2];
|
||||
byte ver;
|
||||
|
||||
// ID and versione
|
||||
ds >> buf[0] >> buf[1] >> ver;
|
||||
assert(buf[0] == 'B' && buf[1] == 'X');
|
||||
assert(ver == 3);
|
||||
|
||||
// Numero dei box
|
||||
ds >> numbbox;
|
||||
|
||||
// Alloca la memoria per i box
|
||||
boxes = new RMBox[numbbox];
|
||||
|
||||
// Li legge da disco
|
||||
for (i = 0; i < numbbox; i++)
|
||||
ds >> boxes[i];
|
||||
}
|
||||
|
||||
|
||||
void RMBoxLoc::RecalcAllAdj(void) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < numbbox; i++) {
|
||||
Common::fill(boxes[i].adj, boxes[i].adj + MAXBOXES, 0);
|
||||
|
||||
for (j=0; j < boxes[i].numhotspot; j++)
|
||||
if (boxes[boxes[i].hotspot[j].destination].attivo)
|
||||
boxes[i].adj[boxes[i].hotspot[j].destination] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
RMDataStream &operator>>(RMDataStream &ds, RMBoxLoc &bl) {
|
||||
bl.ReadFromStream(ds);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
/****************************************************************************\
|
||||
* RMGameBoxes methods
|
||||
\****************************************************************************/
|
||||
|
||||
void RMGameBoxes::Init(void) {
|
||||
int i;
|
||||
RMString fn;
|
||||
RMDataStream ds;
|
||||
|
||||
// Load boxes from disk
|
||||
m_nLocBoxes = 130;
|
||||
for (i=1; i <= m_nLocBoxes; i++) {
|
||||
RMRes res(10000 + i);
|
||||
|
||||
ds.OpenBuffer(res);
|
||||
|
||||
m_allBoxes[i] = new RMBoxLoc();
|
||||
ds >> *m_allBoxes[i];
|
||||
|
||||
m_allBoxes[i]->RecalcAllAdj();
|
||||
|
||||
ds.Close();
|
||||
}
|
||||
}
|
||||
|
||||
void RMGameBoxes::Close(void) {
|
||||
}
|
||||
|
||||
RMBoxLoc *RMGameBoxes::GetBoxes(int nLoc) {
|
||||
return m_allBoxes[nLoc];
|
||||
}
|
||||
|
||||
bool RMGameBoxes::IsInBox(int nLoc, int nBox, RMPoint pt) {
|
||||
RMBoxLoc *cur = GetBoxes(nLoc);
|
||||
|
||||
if ((pt.x >= cur->boxes[nBox].left) && (pt.x <= cur->boxes[nBox].right) &&
|
||||
(pt.y >= cur->boxes[nBox].top) && (pt.y <= cur->boxes[nBox].bottom))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
int RMGameBoxes::WhichBox(int nLoc, RMPoint punto) {
|
||||
int i;
|
||||
RMBoxLoc *cur = GetBoxes(nLoc);
|
||||
|
||||
if (!cur) return -1;
|
||||
|
||||
for (i=0; i<cur->numbbox; i++)
|
||||
if (cur->boxes[i].attivo)
|
||||
if ((punto.x >= cur->boxes[i].left) && (punto.x <= cur->boxes[i].right) &&
|
||||
(punto.y >= cur->boxes[i].top) && (punto.y <= cur->boxes[i].bottom))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void RMGameBoxes::ChangeBoxStatus(int nLoc, int nBox, int status) {
|
||||
m_allBoxes[nLoc]->boxes[nBox].attivo=status;
|
||||
m_allBoxes[nLoc]->RecalcAllAdj();
|
||||
}
|
||||
|
||||
|
||||
int RMGameBoxes::GetSaveStateSize(void) {
|
||||
int size;
|
||||
int i;
|
||||
|
||||
size=4;
|
||||
|
||||
for (i=1; i <= m_nLocBoxes; i++) {
|
||||
size += 4;
|
||||
size += m_allBoxes[i]->numbbox;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void RMGameBoxes::SaveState(byte *state) {
|
||||
int i,j;
|
||||
|
||||
// Save the number of locations with boxes
|
||||
WRITE_LE_UINT32(state, m_nLocBoxes);
|
||||
state += 4;
|
||||
|
||||
// For each location, write out the number of boxes and their status
|
||||
for (i=1; i <= m_nLocBoxes; i++) {
|
||||
WRITE_LE_UINT32(state, m_allBoxes[i]->numbbox);
|
||||
state+=4;
|
||||
|
||||
for (j=0; j < m_allBoxes[i]->numbbox; j++)
|
||||
*state++ = m_allBoxes[i]->boxes[j].attivo;
|
||||
}
|
||||
}
|
||||
|
||||
void RMGameBoxes::LoadState(byte *state) {
|
||||
int i,j;
|
||||
int nloc,nbox;
|
||||
|
||||
// Load number of locations with box
|
||||
nloc = *(int*)state;
|
||||
state+=4;
|
||||
|
||||
// Controlla che siano meno di quelli correnti
|
||||
assert(nloc <= m_nLocBoxes);
|
||||
|
||||
// Per ogni locazione, salva il numero di box e il loro stato
|
||||
for (i = 1; i <= nloc; i++) {
|
||||
nbox = READ_LE_UINT32(state);
|
||||
state += 4;
|
||||
|
||||
for (j=0; j<nbox ; j++)
|
||||
{
|
||||
if (j < m_allBoxes[i]->numbbox)
|
||||
m_allBoxes[i]->boxes[j].attivo = *state;
|
||||
|
||||
state++;
|
||||
}
|
||||
|
||||
m_allBoxes[i]->RecalcAllAdj();
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Tony
|
127
engines/tony/loc.h
Normal file
127
engines/tony/loc.h
Normal file
@ -0,0 +1,127 @@
|
||||
/* 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.
|
||||
*
|
||||
*/
|
||||
/**************************************************************************
|
||||
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* Nayma Software srl *
|
||||
* e -= We create much MORE than ALL =- *
|
||||
* u- z$$$c '. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* .d" d$$$$$b "b. *
|
||||
* .z$* d$$$$$$$L ^*$c. *
|
||||
* #$$$. $$$$$$$$$ .$$$" Project: Roasted Moths........ *
|
||||
* ^*$b 4$$$$$$$$$F .d$*" *
|
||||
* ^$$. 4$$$$$$$$$F .$P" Module: Loc.CPP.............. *
|
||||
* *$. '$$$$$$$$$ 4$P 4 *
|
||||
* J *$ "$$$$$$$" $P r Author: Giovanni Bajo........ *
|
||||
* z$ '$$$P*4c.*$$$*.z@*R$$$ $. *
|
||||
* z$" "" #$F^ "" '$c Desc: Classi di gestione *
|
||||
* z$$beu .ue=" $ "=e.. .zed$$c dei dati di una loca- *
|
||||
* "#$e z$*" . `. ^*Nc e$"" zione................ *
|
||||
* "$$". .r" ^4. .^$$" ..................... *
|
||||
* ^.@*"6L=\ebu^+C$"*b." *
|
||||
* "**$. "c 4$$$ J" J$P*" OS: [ ] DOS [X] WIN95 [ ] PORT *
|
||||
* ^"--.^ 9$" .--"" COMP: [ ] WATCOM [X] VISUAL C++ *
|
||||
* " [ ] EIFFEL [ ] GCC/GXX/DJGPP *
|
||||
* *
|
||||
* This source code is Copyright (C) Nayma Software. ALL RIGHTS RESERVED *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TONY_LOC_H
|
||||
#define TONY_LOC_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace Tony {
|
||||
|
||||
#define MAXBOXES 50 // Non si puo' cambiare, comanda cosi' il boxed
|
||||
#define MAXHOTSPOT 20 // Idem
|
||||
|
||||
class RMBox {
|
||||
public:
|
||||
struct T_HOTSPOT {
|
||||
int hotx, hoty; // coordinate HotSpot
|
||||
int destination; // destinazione HotSpot
|
||||
};
|
||||
|
||||
public:
|
||||
int left,top,right,bottom; // Vertici BoundingBox
|
||||
int adj[MAXBOXES]; // Lista di adjacenza
|
||||
int numhotspot; // Numero HotSpot
|
||||
uint8 Zvalue; // Zvalue per quel BoundingBox
|
||||
T_HOTSPOT hotspot[MAXHOTSPOT]; // Lista degli HotSpot
|
||||
|
||||
bool attivo;
|
||||
bool bReversed;
|
||||
|
||||
private:
|
||||
void ReadFromStream(RMDataStream &ds);
|
||||
|
||||
public:
|
||||
friend RMDataStream &operator>>(RMDataStream &ds, RMBox &box);
|
||||
};
|
||||
|
||||
|
||||
class RMBoxLoc {
|
||||
public:
|
||||
int numbbox;
|
||||
RMBox *boxes;
|
||||
|
||||
private:
|
||||
void ReadFromStream(RMDataStream& ds);
|
||||
|
||||
public:
|
||||
friend RMDataStream& operator >>(RMDataStream &ds, RMBoxLoc &bl);
|
||||
void RecalcAllAdj(void);
|
||||
};
|
||||
|
||||
|
||||
class RMGameBoxes {
|
||||
protected:
|
||||
RMBoxLoc *m_allBoxes[200];
|
||||
int m_nLocBoxes;
|
||||
|
||||
public:
|
||||
void Init(void);
|
||||
void Close(void);
|
||||
|
||||
// Prende i box di una locazione
|
||||
RMBoxLoc *GetBoxes(int nLoc);
|
||||
|
||||
// Calcola in quale box si trova il punto
|
||||
int WhichBox(int nLoc, RMPoint pt);
|
||||
|
||||
// Controlla che il punto sia dentro un certo box
|
||||
bool IsInBox(int nLoc, int nBox, RMPoint pt);
|
||||
|
||||
// Cambia lo stato di un box
|
||||
void ChangeBoxStatus(int nLoc, int nBox, int status);
|
||||
|
||||
// Salvataggi
|
||||
int GetSaveStateSize(void);
|
||||
void SaveState(byte *buf);
|
||||
void LoadState(byte *buf);
|
||||
};
|
||||
|
||||
} // End of namespace Tony
|
||||
|
||||
#endif /* TONY_H */
|
@ -2,11 +2,14 @@ MODULE := engines/tony
|
||||
|
||||
MODULE_OBJS := \
|
||||
detection.o \
|
||||
loc.o \
|
||||
tony.o \
|
||||
utils.o \
|
||||
mpal/expr.o \
|
||||
mpal/loadmpc.o \
|
||||
mpal/memory.o \
|
||||
mpal/mpal.o \
|
||||
mpal/mpalutils.o \
|
||||
mpal/lzo.o \
|
||||
mpal/stubs.o
|
||||
|
||||
|
@ -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);
|
||||
|
@ -52,6 +52,8 @@
|
||||
*/
|
||||
#include "mpal.h"
|
||||
#include "mpaldll.h"
|
||||
#include "memory.h"
|
||||
#include "tony/tony.h"
|
||||
|
||||
namespace Tony {
|
||||
|
||||
|
145
engines/tony/mpal/memory.cpp
Normal file
145
engines/tony/mpal/memory.cpp
Normal file
@ -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<MemoryItem *>::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<MemoryItem *>::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
|
82
engines/tony/mpal/memory.h
Normal file
82
engines/tony/mpal/memory.h
Normal file
@ -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<MemoryItem *> _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
|
@ -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) {
|
||||
/*
|
||||
|
@ -51,6 +51,7 @@
|
||||
#define __MPALDLL_H
|
||||
|
||||
#include "common/file.h"
|
||||
#include "memory.h"
|
||||
#include "stubs.h"
|
||||
|
||||
namespace Tony {
|
||||
|
106
engines/tony/mpal/mpalutils.cpp
Normal file
106
engines/tony/mpal/mpalutils.cpp
Normal file
@ -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
|
69
engines/tony/mpal/mpalutils.h
Normal file
69
engines/tony/mpal/mpalutils.h
Normal file
@ -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
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -78,9 +78,13 @@ Common::ErrorCode TonyEngine::Init() {
|
||||
// Initialise the music
|
||||
InitMusic();
|
||||
|
||||
// Initialise the voices database
|
||||
if (!OpenVoiceDatabase())
|
||||
return Common::kReadingFailed;
|
||||
|
||||
// Initialise the boxes
|
||||
_theBoxes.Init();
|
||||
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "engines/engine.h"
|
||||
|
||||
#include "tony/mpal/mpal.h"
|
||||
#include "tony/mpal/memory.h"
|
||||
#include "tony/loc.h"
|
||||
#include "tony/utils.h"
|
||||
|
||||
/**
|
||||
@ -83,9 +85,12 @@ protected:
|
||||
public:
|
||||
LPCUSTOMFUNCTION FuncList[300];
|
||||
Common::RandomSource _randomSource;
|
||||
MPAL::MemoryManager _memoryManager;
|
||||
RMResUpdate _resUpdate;
|
||||
Common::File _vdbFP;
|
||||
Common::Array<VoiceHeader> _voices;
|
||||
// Bounding box list manager
|
||||
RMGameBoxes _theBoxes;
|
||||
public:
|
||||
TonyEngine(OSystem *syst, const TonyGameDescription *gameDesc);
|
||||
virtual ~TonyEngine();
|
||||
|
@ -19,12 +19,889 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
/**************************************************************************
|
||||
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* Nayma Software srl *
|
||||
* e -= We create much MORE than ALL =- *
|
||||
* u- z$$$c '. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* .d" d$$$$$b "b. *
|
||||
* .z$* d$$$$$$$L ^*$c. *
|
||||
* #$$$. $$$$$$$$$ .$$$" Project: Roasted Moths........ *
|
||||
* ^*$b 4$$$$$$$$$F .d$*" *
|
||||
* ^$$. 4$$$$$$$$$F .$P" Module: Loc.CPP.............. *
|
||||
* *$. '$$$$$$$$$ 4$P 4 *
|
||||
* J *$ "$$$$$$$" $P r Author: Giovanni Bajo........ *
|
||||
* z$ '$$$P*4c.*$$$*.z@*R$$$ $. *
|
||||
* z$" "" #$F^ "" '$c Desc: Classi di gestione *
|
||||
* z$$beu .ue=" $ "=e.. .zed$$c dei dati di una loca- *
|
||||
* "#$e z$*" . `. ^*Nc e$"" zione................ *
|
||||
* "$$". .r" ^4. .^$$" ..................... *
|
||||
* ^.@*"6L=\ebu^+C$"*b." *
|
||||
* "**$. "c 4$$$ J" J$P*" OS: [ ] DOS [X] WIN95 [ ] PORT *
|
||||
* ^"--.^ 9$" .--"" COMP: [ ] WATCOM [X] VISUAL C++ *
|
||||
* " [ ] EIFFEL [ ] GCC/GXX/DJGPP *
|
||||
* *
|
||||
* This source code is Copyright (C) Nayma Software. ALL RIGHTS RESERVED *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "tony/utils.h"
|
||||
#include "mpal/lzo.h"
|
||||
#include "tony/tony.h"
|
||||
#include "tony/mpal/lzo.h"
|
||||
|
||||
namespace Tony {
|
||||
|
||||
/****************************************************************************\
|
||||
* RMString methods
|
||||
\****************************************************************************/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RMString::RMString() {
|
||||
m_string=NULL;
|
||||
m_length=0;
|
||||
m_realLength=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
RMString::~RMString() {
|
||||
if (m_string != NULL)
|
||||
delete[] m_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
RMString::RMString(const RMString &str) {
|
||||
// Richiama l'overload su '=' per copiare
|
||||
m_string = NULL;
|
||||
m_length = 0;
|
||||
m_realLength = 0;
|
||||
*this = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor from a char *
|
||||
*/
|
||||
RMString::RMString(const char* str) {
|
||||
// Use the overloaded '=' when copying
|
||||
m_string = NULL;
|
||||
m_length = 0;
|
||||
m_realLength = 0;
|
||||
*this = str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with a single passed character
|
||||
*/
|
||||
RMString::RMString(const int ch) {
|
||||
// Use the overloaded '=' when copying
|
||||
m_string = NULL;
|
||||
m_length = 0;
|
||||
m_realLength = 0;
|
||||
*this = ch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the string
|
||||
* @returns Length
|
||||
*/
|
||||
int RMString::Length() {
|
||||
return m_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the character at the given index
|
||||
* @param nIndex Position of the character to return
|
||||
* @returns Character
|
||||
*/
|
||||
char RMString::GetAt(int nIndex) {
|
||||
assert(nIndex < m_length);
|
||||
return m_string[nIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character at the given index
|
||||
* @param nIndex Position of the character to change
|
||||
* @param c Character
|
||||
*/
|
||||
void RMString::SetAt(int nIndex, char c) {
|
||||
assert(nIndex < m_length);
|
||||
m_string[nIndex] = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded square brackets operator for accessing characters within the string
|
||||
* @param nIndex Position of the charactre to reference
|
||||
* @params Reference to the character
|
||||
*/
|
||||
char &RMString::operator[](int nIndex) {
|
||||
assert(nIndex < m_length);
|
||||
return m_string[nIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a string
|
||||
* @param str String to copy
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString &RMString::operator=(const RMString &str) {
|
||||
// Set the new length
|
||||
m_length = str.m_length;
|
||||
|
||||
// If the source is empty, then destroy the current string buffer
|
||||
if (m_length == 0) {
|
||||
if (m_realLength > 0) {
|
||||
delete[] m_string;
|
||||
m_string = NULL;
|
||||
m_realLength = 0;
|
||||
}
|
||||
} else {
|
||||
// Resize if necessary
|
||||
Resize(m_length + 1);
|
||||
|
||||
// Copy the string
|
||||
Common::copy(str.m_string, str.m_string + m_length + 1, m_string);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a char * string
|
||||
* @param str String to copy
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString& RMString::operator=(const char* str) {
|
||||
// If the source is empty, then destroy the current string buffer
|
||||
if (str == NULL) {
|
||||
if (m_realLength > 0) {
|
||||
delete[] m_string;
|
||||
m_string = NULL;
|
||||
m_realLength = m_length = 0;
|
||||
}
|
||||
} else {
|
||||
// Calculate the new length
|
||||
m_length = strlen(str);
|
||||
|
||||
// Resize if necessary
|
||||
Resize(m_length + 1);
|
||||
|
||||
// Copy the string
|
||||
Common::copy(str, str + m_length + 1, m_string);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a string from a passed character
|
||||
* @param ch Character to copy
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString& RMString::operator=(const int ch) {
|
||||
if (ch=='\0') {
|
||||
// Destroy the current string
|
||||
if (m_realLength > 0) {
|
||||
delete [] m_string;
|
||||
m_string=NULL;
|
||||
m_length=m_realLength=0;
|
||||
}
|
||||
} else {
|
||||
// Resize if necessary
|
||||
Resize(2);
|
||||
|
||||
m_string[0] = ch;
|
||||
m_string[1] = '\0';
|
||||
m_length = 1;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate a string into the current one
|
||||
* @param str String to concatenate
|
||||
* @param size Length of the string
|
||||
*/
|
||||
void RMString::Connect(const char *str, int size) {
|
||||
int nlen;
|
||||
|
||||
if (size > 0) {
|
||||
// Calculate the new lenght
|
||||
nlen=m_length+size;
|
||||
|
||||
// Resize
|
||||
Resize(nlen + 1, true);
|
||||
|
||||
// Linkage with '\0'
|
||||
Common::copy(str, str + size + 1, m_string + m_length);
|
||||
|
||||
// Save the new length
|
||||
m_length = nlen;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate a string
|
||||
* @param str String to concatenate
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString &RMString::operator+=(RMString &str) {
|
||||
Connect(str,str.Length());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate a string
|
||||
* @param str String to concatenate
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString &RMString::operator+=(const char *str) {
|
||||
Connect(str,strlen(str));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate a character
|
||||
* @param ch Character to concatenate
|
||||
* @returns Refrence to our string
|
||||
*/
|
||||
const RMString &RMString::operator+=(const int ch) {
|
||||
char str[2];
|
||||
|
||||
// Create a simple string buffer to hold the single character
|
||||
str[0] = ch;
|
||||
str[1] = '\0';
|
||||
|
||||
Connect(str, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a string as char *
|
||||
* @returns char * reference to string
|
||||
*/
|
||||
RMString::operator char*() const {
|
||||
return m_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize a string as necessary
|
||||
* @param size New size necessary (in bytes)
|
||||
* @param bMaintain If TRUE we must keep the original string,
|
||||
if FALSE we can destroy.
|
||||
*/
|
||||
void RMString::Resize(int size, bool bMantain) {
|
||||
if (m_realLength == 0) {
|
||||
m_string = new char[size];
|
||||
m_realLength = size;
|
||||
} else if (size > m_realLength) {
|
||||
if (bMantain) {
|
||||
char* app;
|
||||
|
||||
app = new char[size];
|
||||
Common::copy(m_string, m_string + m_length + 1, app);
|
||||
delete[] m_string;
|
||||
m_string = app;
|
||||
} else {
|
||||
delete[] m_string;
|
||||
m_string = new char[size];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compacts the string to occupy less memory if possible.
|
||||
*/
|
||||
void RMString::Compact(void) {
|
||||
if (m_realLength + 1 > m_length) {
|
||||
char *app;
|
||||
|
||||
app = new char[m_length + 1];
|
||||
Common::copy(m_string, m_string + m_length + 1, app);
|
||||
|
||||
delete[] m_string;
|
||||
m_string = app;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator to concatenate two strings
|
||||
*/
|
||||
RMString operator+(const RMString &str1, const RMString &str2) {
|
||||
RMString ret(str1);
|
||||
|
||||
return (ret += str2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator to concatenate a character to a string
|
||||
*/
|
||||
RMString operator+(RMString &str, const int ch) {
|
||||
RMString ret(str);
|
||||
|
||||
return (ret += ch);
|
||||
}
|
||||
|
||||
RMString operator+(const int ch, RMString &str) {
|
||||
RMString ret(ch);
|
||||
|
||||
return (ret += str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Operator to concatenate a char * string to an RMString
|
||||
*/
|
||||
RMString operator+(RMString &str, const char *s) {
|
||||
RMString ret(str);
|
||||
|
||||
return (ret += s);
|
||||
}
|
||||
|
||||
RMString operator+(const char *s, RMString &str) {
|
||||
RMString ret(s);
|
||||
|
||||
return (ret+=str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a string from a data stream
|
||||
* @param df data stream
|
||||
* @param var String
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, RMString &var) {
|
||||
uint8 len;
|
||||
int i;
|
||||
|
||||
df >> len;
|
||||
var.Resize(len + 1);
|
||||
var.m_length=len+1;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
df >> var[i];
|
||||
|
||||
var[i] = '\0';
|
||||
var.m_length = len;
|
||||
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string
|
||||
*/
|
||||
void RMString::Format(char* str, ...) {
|
||||
warning("TODO: Refactor RMString::Format if needed");
|
||||
/*
|
||||
static char buf[2048];
|
||||
va_list argList;
|
||||
|
||||
va_start(argList,str);
|
||||
wvsprintf(buf,str,argList);
|
||||
va_end(argList);
|
||||
*this = buf;
|
||||
*/
|
||||
}
|
||||
|
||||
/****************************************************************************\
|
||||
* RMDataStream methods
|
||||
\****************************************************************************/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RMDataStream::RMDataStream() {
|
||||
m_length = 0;
|
||||
m_pos = 0;
|
||||
m_bError = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
RMDataStream::~RMDataStream() {
|
||||
Close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a stream
|
||||
*/
|
||||
void RMDataStream::Close(void) {
|
||||
m_length = 0;
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the address of the buffer from which will be read the data.
|
||||
* @param lpBuf Data buffer
|
||||
* @param size Size of the buffer
|
||||
* @remarks If the length of the buffer is not known, and cannot be
|
||||
* specified, then EOF() and Seek() to end won't work.
|
||||
*/
|
||||
void RMDataStream::OpenBuffer(const byte *lpBuf, int size) {
|
||||
m_length = size;
|
||||
m_buf = lpBuf;
|
||||
m_bError = false;
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the stream
|
||||
* @returns Stream length
|
||||
*/
|
||||
int RMDataStream::Length() {
|
||||
return m_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the end of the stream has been reached
|
||||
* @returns TRUE if end of stream reached, FALSE if not
|
||||
*/
|
||||
bool RMDataStream::IsEOF() {
|
||||
return (m_pos >= m_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, char &var) {
|
||||
df.Read(&var, 1);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, uint8 &var) {
|
||||
df.Read(&var, 1);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, uint16 &var) {
|
||||
uint16 v;
|
||||
df.Read(&v, 2);
|
||||
|
||||
var = FROM_LE_16(v);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, int16 &var) {
|
||||
uint16 v;
|
||||
df.Read(&v, 2);
|
||||
|
||||
var = (int16)FROM_LE_16(v);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, int &var) {
|
||||
uint32 v;
|
||||
df.Read(&v, 4);
|
||||
|
||||
var = (int)FROM_LE_32(v);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts data from the stream
|
||||
* @param df Stream
|
||||
* @param var Variable of a supported type
|
||||
* @returns Value read from the stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &df, uint32 &var) {
|
||||
uint32 v;
|
||||
df.Read(&v, 4);
|
||||
|
||||
var = FROM_LE_32(v);
|
||||
return df;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a series of data from the stream in a buffer
|
||||
* @param lpBuf Data buffer
|
||||
* @param size Size of the buffer
|
||||
* @returns TRUE if we have reached the end, FALSE if not
|
||||
*/
|
||||
bool RMDataStream::Read(void *lpBuf, int size) {
|
||||
byte *dest = (byte *)lpBuf;
|
||||
|
||||
if ((m_pos + size) > m_length) {
|
||||
Common::copy(m_buf + m_pos, m_buf + m_pos + (m_length - m_pos), dest);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Common::copy(m_buf + m_pos, m_buf + m_pos + size, dest);
|
||||
|
||||
m_pos += size;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips a number of bytes in the stream
|
||||
* @param nBytres Number of bytes to skip
|
||||
* @returns The stream
|
||||
*/
|
||||
RMDataStream &RMDataStream::operator+=(int nBytes) {
|
||||
m_pos+=nBytes;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks to a position within the stream
|
||||
* @param nBytes Number of bytes from specified origin
|
||||
* @param origin Origin to do offset from
|
||||
* @returns The absolute current position in bytes
|
||||
*/
|
||||
int RMDataStream::Seek(int nBytes, RMDSPos origin) {
|
||||
switch (origin) {
|
||||
case CUR:
|
||||
break;
|
||||
|
||||
case START:
|
||||
m_pos=0;
|
||||
break;
|
||||
|
||||
case END:
|
||||
if (m_length == SIZENOTKNOWN)
|
||||
return m_pos;
|
||||
m_pos=m_length;
|
||||
break;
|
||||
}
|
||||
|
||||
m_pos+=nBytes;
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current position of the stream
|
||||
* @returns The current position
|
||||
*/
|
||||
int RMDataStream::Pos() {
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an error occurred during reading the stream
|
||||
* @returns TRUE if there was an error, false otherwise
|
||||
*/
|
||||
bool RMDataStream::IsError() {
|
||||
return m_bError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an error code for the stream
|
||||
* @param code Error code
|
||||
*/
|
||||
void RMDataStream::SetError(int code) {
|
||||
m_bError = true;
|
||||
m_ecode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error code for the stream
|
||||
* @returns Error code
|
||||
*/
|
||||
int RMDataStream::GetError() {
|
||||
return m_ecode;
|
||||
}
|
||||
|
||||
/****************************************************************************\
|
||||
* RMPoint methods
|
||||
\****************************************************************************/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RMPoint::RMPoint() {
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
RMPoint::RMPoint(const RMPoint &p) {
|
||||
x=p.x;
|
||||
y=p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with integer parameters
|
||||
*/
|
||||
RMPoint::RMPoint(int x1, int y1) {
|
||||
x = x1;
|
||||
y = y1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy operator
|
||||
*/
|
||||
RMPoint &RMPoint::operator=(RMPoint p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offsets the point by another point
|
||||
*/
|
||||
void RMPoint::Offset(RMPoint p) {
|
||||
x += p.x;
|
||||
y += p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offsets the point by a specified offset
|
||||
*/
|
||||
void RMPoint::Offset(int xOff, int yOff) {
|
||||
x += xOff;
|
||||
y += yOff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums together two points
|
||||
*/
|
||||
RMPoint operator+(RMPoint p1, RMPoint p2) {
|
||||
RMPoint p(p1);
|
||||
|
||||
return (p += p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts two points
|
||||
*/
|
||||
RMPoint operator-(RMPoint p1, RMPoint p2) {
|
||||
RMPoint p(p1);
|
||||
|
||||
return (p -= p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum (offset) of a point
|
||||
*/
|
||||
RMPoint &RMPoint::operator+=(RMPoint p) {
|
||||
Offset(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract (offset) of a point
|
||||
*/
|
||||
RMPoint& RMPoint::operator-=(RMPoint p) {
|
||||
Offset(-p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts a point
|
||||
*/
|
||||
RMPoint RMPoint::operator-() {
|
||||
RMPoint p;
|
||||
|
||||
p.x = -x;
|
||||
p.y = -y;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equality operator
|
||||
*/
|
||||
bool RMPoint::operator==(RMPoint p) {
|
||||
return ((x == p.x) && (y == p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equal operator
|
||||
*/
|
||||
bool RMPoint::operator!=(RMPoint p) {
|
||||
return ((x != p.x) || (y != p.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a point from a stream
|
||||
*/
|
||||
RMDataStream &operator>>(RMDataStream &ds, RMPoint &p) {
|
||||
ds >> p.x >> p.y;
|
||||
return ds;
|
||||
}
|
||||
|
||||
/****************************************************************************\
|
||||
* RMRect methods
|
||||
\****************************************************************************/
|
||||
|
||||
RMRect::RMRect() {
|
||||
SetEmpty();
|
||||
}
|
||||
|
||||
void RMRect::SetEmpty(void) {
|
||||
x1 = y1 = x2 = y2 = 0;
|
||||
}
|
||||
|
||||
RMRect::RMRect(RMPoint p1, RMPoint p2) {
|
||||
SetRect(p1, p2);
|
||||
}
|
||||
|
||||
RMRect::RMRect(int X1, int Y1, int X2, int Y2) {
|
||||
SetRect(X1, Y1, X2, Y2);
|
||||
}
|
||||
|
||||
RMRect::RMRect(const RMRect &rc) {
|
||||
CopyRect(rc);
|
||||
}
|
||||
|
||||
void RMRect::SetRect(RMPoint p1, RMPoint p2) {
|
||||
x1 = p1.x;
|
||||
y1 = p1.y;
|
||||
x2 = p2.x;
|
||||
y2 = p2.y;
|
||||
}
|
||||
|
||||
void RMRect::SetRect(int X1, int Y1, int X2, int Y2) {
|
||||
x1 = X1;
|
||||
y1 = Y1;
|
||||
x2 = X2;
|
||||
y2 = Y2;
|
||||
}
|
||||
|
||||
void RMRect::SetRect(const RMRect &rc) {
|
||||
CopyRect(rc);
|
||||
}
|
||||
|
||||
void RMRect::CopyRect(const RMRect &rc) {
|
||||
x1 = rc.x1;
|
||||
y1 = rc.y1;
|
||||
x2 = rc.x2;
|
||||
y2 = rc.y2;
|
||||
}
|
||||
|
||||
RMPoint &RMRect::TopLeft() {
|
||||
// FIXME: This seems very bad
|
||||
return *((RMPoint *)this);
|
||||
}
|
||||
|
||||
RMPoint& RMRect::BottomRight() {
|
||||
// FIXME: This seems very bad
|
||||
return *((RMPoint*)this + 1);
|
||||
}
|
||||
|
||||
RMPoint RMRect::Center() {
|
||||
return RMPoint((x2 - x1) / 2,(y2 - y1) / 2);
|
||||
}
|
||||
|
||||
int RMRect::Width() {
|
||||
return x2 - x1;
|
||||
}
|
||||
|
||||
int RMRect::Height() {
|
||||
return y2 - y1;
|
||||
}
|
||||
|
||||
int RMRect::Size() {
|
||||
return Width() * Height();
|
||||
}
|
||||
|
||||
bool RMRect::IsEmpty() {
|
||||
return (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0);
|
||||
}
|
||||
|
||||
const RMRect& RMRect::operator=(const RMRect &rc) {
|
||||
CopyRect(rc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RMRect::Offset(int xOff, int yOff) {
|
||||
x1 += xOff;
|
||||
y1 += yOff;
|
||||
x2 += xOff;
|
||||
y2 += yOff;
|
||||
}
|
||||
|
||||
void RMRect::Offset(RMPoint p) {
|
||||
x1 += p.x;
|
||||
y1 += p.y;
|
||||
x2 += p.x;
|
||||
y2 += p.y;
|
||||
}
|
||||
|
||||
const RMRect &RMRect::operator+=(RMPoint p) {
|
||||
Offset(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const RMRect &RMRect::operator-=(RMPoint p) {
|
||||
Offset(-p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
RMRect operator+(const RMRect &rc, RMPoint p) {
|
||||
RMRect r(rc);
|
||||
return (r += p);
|
||||
}
|
||||
|
||||
RMRect operator-(const RMRect& rc, RMPoint p) {
|
||||
RMRect r(rc);
|
||||
|
||||
return (r -= p);
|
||||
}
|
||||
|
||||
RMRect operator+(RMPoint p, const RMRect& rc) {
|
||||
RMRect r(rc);
|
||||
|
||||
return (r+=p);
|
||||
}
|
||||
|
||||
RMRect operator-(RMPoint p, const RMRect& rc) {
|
||||
RMRect r(rc);
|
||||
|
||||
return (r+=p);
|
||||
}
|
||||
|
||||
bool RMRect::operator==(const RMRect& rc) {
|
||||
return ((x1 == rc.x1) && (y1 == rc.y1) && (x2 == rc.x2) && (y2 == rc.y2));
|
||||
}
|
||||
|
||||
bool RMRect::operator!=(const RMRect& rc) {
|
||||
return ((x1 != rc.x1) || (y1 != rc.y1) || (x2 != rc.x2) || (y2 != rc.y2));
|
||||
}
|
||||
|
||||
void RMRect::NormalizeRect(void) {
|
||||
SetRect(MIN(x1,x2), MIN(y1,y2), MAX(x1,x2), MAX(y1,y2));
|
||||
}
|
||||
|
||||
RMDataStream &operator>>(RMDataStream &ds, RMRect &rc) {
|
||||
ds >> rc.x1 >> rc.y1 >> rc.x2 >> rc.y2;
|
||||
return ds;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************\
|
||||
* Resource Update
|
||||
\****************************************************************************/
|
||||
@ -68,7 +945,7 @@ void RMResUpdate::Init(const Common::String &fileName) {
|
||||
}
|
||||
}
|
||||
|
||||
const byte *RMResUpdate::QueryResource(uint32 dwRes) {
|
||||
HGLOBAL RMResUpdate::QueryResource(uint32 dwRes) {
|
||||
// If there isn't an update file, return NULL
|
||||
if (!_hFile.isOpen())
|
||||
return NULL;
|
||||
@ -98,7 +975,8 @@ const byte *RMResUpdate::QueryResource(uint32 dwRes) {
|
||||
}
|
||||
|
||||
// Allocate space for the output resource
|
||||
byte *lpDestBuf = new byte[info.size];
|
||||
HGLOBAL destBuf = GlobalAllocate(info.size);
|
||||
byte *lpDestBuf = (byte *)GlobalLock(destBuf);
|
||||
uint32 dwSize;
|
||||
|
||||
// Decompress the data
|
||||
@ -108,6 +986,7 @@ const byte *RMResUpdate::QueryResource(uint32 dwRes) {
|
||||
delete [] cmpBuf;
|
||||
|
||||
// Return the resource
|
||||
GlobalUnlock(destBuf);
|
||||
return lpDestBuf;
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,261 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
/**************************************************************************
|
||||
* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* Nayma Software srl *
|
||||
* e -= We create much MORE than ALL =- *
|
||||
* u- z$$$c '. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ *
|
||||
* .d" d$$$$$b "b. *
|
||||
* .z$* d$$$$$$$L ^*$c. *
|
||||
* #$$$. $$$$$$$$$ .$$$" Project: Roasted Moths........ *
|
||||
* ^*$b 4$$$$$$$$$F .d$*" *
|
||||
* ^$$. 4$$$$$$$$$F .$P" Module: Loc.CPP.............. *
|
||||
* *$. '$$$$$$$$$ 4$P 4 *
|
||||
* J *$ "$$$$$$$" $P r Author: Giovanni Bajo........ *
|
||||
* z$ '$$$P*4c.*$$$*.z@*R$$$ $. *
|
||||
* z$" "" #$F^ "" '$c Desc: Classi di gestione *
|
||||
* z$$beu .ue=" $ "=e.. .zed$$c dei dati di una loca- *
|
||||
* "#$e z$*" . `. ^*Nc e$"" zione................ *
|
||||
* "$$". .r" ^4. .^$$" ..................... *
|
||||
* ^.@*"6L=\ebu^+C$"*b." *
|
||||
* "**$. "c 4$$$ J" J$P*" OS: [ ] DOS [X] WIN95 [ ] PORT *
|
||||
* ^"--.^ 9$" .--"" COMP: [ ] WATCOM [X] VISUAL C++ *
|
||||
* " [ ] EIFFEL [ ] GCC/GXX/DJGPP *
|
||||
* *
|
||||
* This source code is Copyright (C) Nayma Software. ALL RIGHTS RESERVED *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef TONY_UTILS_H
|
||||
#define TONY_UTILS_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/file.h"
|
||||
#include "common/rect.h"
|
||||
#include "common/str.h"
|
||||
#include "tony/mpal/memory.h"
|
||||
|
||||
namespace Tony {
|
||||
|
||||
using namespace ::Tony::MPAL;
|
||||
|
||||
/**
|
||||
* Data stream for reading data
|
||||
*/
|
||||
class RMDataStream {
|
||||
protected:
|
||||
const byte *m_buf;
|
||||
int m_length;
|
||||
int m_pos;
|
||||
bool m_bError;
|
||||
int m_ecode;
|
||||
|
||||
public:
|
||||
enum RMDSPos {
|
||||
CUR,
|
||||
START,
|
||||
END
|
||||
};
|
||||
|
||||
private:
|
||||
enum {
|
||||
SIZENOTKNOWN = 0x7FFFFFFF
|
||||
};
|
||||
|
||||
public:
|
||||
// Constructor and destructor
|
||||
RMDataStream();
|
||||
virtual ~RMDataStream();
|
||||
|
||||
// Loading buffer
|
||||
void OpenBuffer(const byte *buf, int size = SIZENOTKNOWN);
|
||||
void Close(void);
|
||||
|
||||
// Attributi
|
||||
int Length();
|
||||
virtual int Pos();
|
||||
|
||||
// EOF
|
||||
virtual bool IsEOF();
|
||||
|
||||
// Read methods
|
||||
friend RMDataStream &operator>>(RMDataStream &df, char &var);
|
||||
friend RMDataStream &operator>>(RMDataStream &df, byte &var);
|
||||
friend RMDataStream &operator>>(RMDataStream &df, uint16 &var);
|
||||
friend RMDataStream &operator>>(RMDataStream &df, int16 &var);
|
||||
friend RMDataStream &operator>>(RMDataStream &df, int &var);
|
||||
friend RMDataStream &operator>>(RMDataStream &df, uint32 &var);
|
||||
|
||||
// Lettura generica
|
||||
virtual bool Read(void *buf, int size);
|
||||
|
||||
// Skipping & Seeking
|
||||
virtual RMDataStream &operator+=(int nBytes);
|
||||
virtual int Seek(int nBytes, RMDSPos origin = CUR);
|
||||
|
||||
// Gestione errori
|
||||
void SetError(int ecode);
|
||||
int GetError();
|
||||
bool IsError();
|
||||
};
|
||||
|
||||
/**
|
||||
* String class
|
||||
*/
|
||||
class RMString {
|
||||
private:
|
||||
char *m_string;
|
||||
int m_length;
|
||||
int m_realLength;
|
||||
|
||||
public:
|
||||
RMString();
|
||||
~RMString();
|
||||
|
||||
// Assignment constructors
|
||||
RMString(const RMString &str);
|
||||
RMString(const char *str);
|
||||
RMString(const int ch);
|
||||
|
||||
// Metodi generici
|
||||
int Length();
|
||||
void Compact();
|
||||
|
||||
// Access characters within string
|
||||
char GetAt(int nIndex);
|
||||
void SetAt(int nIndex, char c);
|
||||
char& operator[](int nIndex);
|
||||
|
||||
// String cast
|
||||
operator char*() const;
|
||||
|
||||
// String assignments
|
||||
const RMString &operator=(const RMString &str);
|
||||
const RMString &operator=(const char *str);
|
||||
const RMString &operator=(const int ch);
|
||||
|
||||
// String concatenation
|
||||
const RMString &operator+=(RMString &str);
|
||||
const RMString &operator+=(const char *str);
|
||||
const RMString &operator+=(const int ch);
|
||||
|
||||
// Concatentation of string or character
|
||||
friend RMString operator+(const RMString &str1, const RMString &str2);
|
||||
|
||||
friend RMString operator+(RMString& str, const int ch);
|
||||
friend RMString operator+(const int ch, RMString &str);
|
||||
|
||||
friend RMString operator+(RMString &str, const char *s);
|
||||
friend RMString operator+(const char *s, RMString &str);
|
||||
|
||||
// Estrazione da data stream
|
||||
friend RMDataStream& operator>>(RMDataStream& df, RMString &var);
|
||||
|
||||
// Formattazione di stringa
|
||||
void Format(char *str, ...);
|
||||
|
||||
private:
|
||||
void Resize(int size, bool bMantain = false);
|
||||
void Connect(const char* str, int size);
|
||||
};
|
||||
|
||||
/**
|
||||
* Point class
|
||||
*/
|
||||
class RMPoint {
|
||||
public:
|
||||
int x, y;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
RMPoint();
|
||||
RMPoint(const RMPoint &p);
|
||||
RMPoint(int x1, int y1);
|
||||
|
||||
// Copia
|
||||
RMPoint& operator=(RMPoint p);
|
||||
|
||||
// Set
|
||||
void Set(int x1, int y1) { x=x1; y=y1; }
|
||||
|
||||
// Offset
|
||||
void Offset(int xOff, int yOff);
|
||||
void Offset(RMPoint p);
|
||||
friend RMPoint operator+(RMPoint p1, RMPoint p2);
|
||||
friend RMPoint operator-(RMPoint p1, RMPoint p2);
|
||||
RMPoint &operator+=(RMPoint p);
|
||||
RMPoint &operator-=(RMPoint p);
|
||||
RMPoint operator-();
|
||||
|
||||
// Confronti
|
||||
bool operator==(RMPoint p);
|
||||
bool operator!=(RMPoint p);
|
||||
|
||||
// Casting a POINT
|
||||
operator Common::Point() const;
|
||||
|
||||
// Extraction from data streams
|
||||
friend RMDataStream& operator>>(RMDataStream &ds, RMPoint &p);
|
||||
};
|
||||
|
||||
class RMRect {
|
||||
public:
|
||||
int x1,y1;
|
||||
int x2,y2;
|
||||
|
||||
public:
|
||||
RMRect();
|
||||
RMRect(int x1, int y1, int x2, int y2);
|
||||
RMRect(RMPoint p1, RMPoint p2);
|
||||
RMRect(const RMRect &rc);
|
||||
|
||||
// Attributes
|
||||
RMPoint &TopLeft();
|
||||
RMPoint &BottomRight();
|
||||
RMPoint Center();
|
||||
int Width();
|
||||
int Height();
|
||||
bool IsEmpty();
|
||||
int Size();
|
||||
|
||||
// Set
|
||||
void SetRect(int x1, int y1, int x2, int y2);
|
||||
void SetRect(RMPoint p1, RMPoint p2);
|
||||
void SetEmpty(void);
|
||||
|
||||
// Copiers
|
||||
void SetRect(const RMRect &rc);
|
||||
void CopyRect(const RMRect &rc);
|
||||
const RMRect &operator=(const RMRect &rc);
|
||||
|
||||
// Offset
|
||||
void Offset(int xOff, int yOff);
|
||||
void Offset(RMPoint p);
|
||||
friend RMRect operator+(const RMRect &rc, RMPoint p);
|
||||
friend RMRect operator-(const RMRect &rc, RMPoint p);
|
||||
friend RMRect operator+(RMPoint p, const RMRect &rc);
|
||||
friend RMRect operator-(RMPoint p, const RMRect &rc);
|
||||
const RMRect &operator+=(RMPoint p);
|
||||
const RMRect &operator-=(RMPoint p);
|
||||
|
||||
// Comparison
|
||||
bool operator==(const RMRect &rc);
|
||||
bool operator!=(const RMRect &rc);
|
||||
|
||||
// Normalise
|
||||
void NormalizeRect();
|
||||
|
||||
// Point in rect
|
||||
bool PtInRect(RMPoint pt) { return (pt.x>=x1 && pt.x<=x2 && pt.y>=y1 && pt.y<=y2); }
|
||||
|
||||
// Extract from data stream
|
||||
friend RMDataStream &operator>>(RMDataStream& ds, RMRect &rc);
|
||||
};
|
||||
|
||||
/**
|
||||
* Resource update manager
|
||||
*/
|
||||
class RMResUpdate {
|
||||
struct ResUpdInfo {
|
||||
uint32 dwRes;
|
||||
@ -46,7 +291,7 @@ public:
|
||||
~RMResUpdate();
|
||||
|
||||
void Init(const Common::String &fileName);
|
||||
const byte *QueryResource(uint32 dwRes);
|
||||
HGLOBAL QueryResource(uint32 dwRes);
|
||||
};
|
||||
|
||||
} // End of namespace Tony
|
||||
|
Loading…
x
Reference in New Issue
Block a user