CGE: Standardised Sprite::seq on always allocating/freeing data

This commit is contained in:
Paul Gilbert 2011-07-11 20:37:37 +10:00
parent 10ca53a00c
commit 18077762d7
5 changed files with 42 additions and 15 deletions

View File

@ -1587,7 +1587,10 @@ void CGEEngine::runGame() {
{ 1, 6, 0, 0, 4 },
{ 0, 1, 0, 0, 16 },
};
_pocLight->setSeq(pocSeq);
Seq *seq = (Seq *)malloc(7 * sizeof(Seq));
Common::copy(&pocSeq[0], &pocSeq[7], seq);
_pocLight->setSeq(seq);
_pocLight->_flags._tran = true;
_pocLight->_time = 1;
_pocLight->_z = 120;

View File

@ -142,11 +142,6 @@ void Keyboard::newKeyboard(Common::Event &event) {
/*----------------- MOUSE interface -----------------*/
Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) {
static Seq ms[] = {
{ 0, 0, 0, 0, 1 },
{ 1, 1, 0, 0, 1 }
};
_hold = NULL;
_hx = 0;
_hy = 0;
@ -155,7 +150,14 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0)
_busy = NULL;
_active = false;
_flags._kill = false;
setSeq(ms);
static Seq ms[] = {
{ 0, 0, 0, 0, 1 },
{ 1, 1, 0, 0, 1 }
};
Seq *seq = (Seq *)malloc(2 * sizeof(Seq));
Common::copy(&ms[0], &ms[2], seq);
setSeq(seq);
BMP_PTR *MC = new BMP_PTR[3];
MC[0] = new Bitmap("MOUSE", true);

View File

@ -310,7 +310,12 @@ void InfoLine::update(const char *tx) {
// clear whole rectangle
memset(v + 2, TEXT_BG, dsiz); // data bytes
memmove(v + lsiz, v, psiz - lsiz);
for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz)
*pDest = 0;
// Common::set_to(pDest, pDest + lsiz, 0);
//Common::copy(v, v + lsiz, pDest);
*(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16
memmove(v + psiz, v, 3 * psiz);

View File

@ -60,8 +60,6 @@ static VgaRegBlk VideoMode[] = {
};
bool SpeedTest = false;
Seq _seq1[] = { { 0, 0, 0, 0, 0 } };
Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } };
extern "C" void SNDMIDIPlay();
@ -383,6 +381,23 @@ BMP_PTR Sprite::shp() {
return NULL;
}
Seq *Sprite::getConstantSeq(bool seqFlag) {
Seq seq1[] = { { 0, 0, 0, 0, 0 } };
Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } };
// Make a copy of the given seq list and return it
Seq *seq;
if (seqFlag) {
seq = (Seq *)malloc(sizeof(Seq));
seq[0] = seq1[0];
} else {
seq = (Seq *)malloc(2 * sizeof(Seq));
seq[0] = seq2[0];
seq[1] = seq2[1];
}
return seq;
}
BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) {
BMP_PTR *r = (_ext) ? _ext->_shpList : NULL;
@ -405,7 +420,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) {
_ext->_shpList = shpP;
_flags._bDel = true;
if (!_ext->_seq)
setSeq((_shpCnt < 2) ? _seq1 : _seq2);
setSeq(getConstantSeq(_shpCnt < 2));
}
return r;
}
@ -590,7 +605,7 @@ Sprite *Sprite::expand() {
error("Bad JUMP in SEQ [%s]", fname);
setSeq(seq);
} else
setSeq((_shpCnt == 1) ? _seq1 : _seq2);
setSeq(getConstantSeq(_shpCnt == 1));
//disable(); // disable interupt
setShapeList(shplist);
@ -621,8 +636,8 @@ Sprite *Sprite::contract() {
delete e->_shpList[i];
delete[] e->_shpList;
}
if (memType(e->_seq) == NEAR_MEM)
free(e->_seq);
free(e->_seq);
if (e->_near)
free(e->_near);
if (e->_take)
@ -1384,7 +1399,7 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) {
Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) {
// Set the sprite list
BMP_PTR *SP = new BMP_PTR[2];
BMP_PTR *SP = new BMP_PTR[3];
SP[0] = new Bitmap("SPK_L", true);
SP[1] = new Bitmap("SPK_R", true);
SP[2] = NULL;

View File

@ -166,6 +166,8 @@ public:
class Sprite {
private:
Seq *getConstantSeq(bool seqFlag);
protected:
SprExt *_ext;
public: