aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
authorMax Horn2004-01-13 01:26:18 +0000
committerMax Horn2004-01-13 01:26:18 +0000
commitb04dac03f2d0029ca9675a6489296773523afedc (patch)
tree508c2504fead3150b1afd72ab36ba45cc569923f /sword2
parent9471d58720a41cfa0ba8b526b4c479b3a3d74af0 (diff)
downloadscummvm-rg350-b04dac03f2d0029ca9675a6489296773523afedc.tar.gz
scummvm-rg350-b04dac03f2d0029ca9675a6489296773523afedc.tar.bz2
scummvm-rg350-b04dac03f2d0029ca9675a6489296773523afedc.zip
added legal header; fixed incorrect fscanf use; C++ification (the code still is quite Cish, though :-)
svn-id: r12351
Diffstat (limited to 'sword2')
-rw-r--r--sword2/driver/animation.cpp95
-rw-r--r--sword2/driver/animation.h29
-rw-r--r--sword2/driver/d_draw.cpp12
-rw-r--r--sword2/driver/d_draw.h13
4 files changed, 101 insertions, 48 deletions
diff --git a/sword2/driver/animation.cpp b/sword2/driver/animation.cpp
index 6426624218..365457be25 100644
--- a/sword2/driver/animation.cpp
+++ b/sword2/driver/animation.cpp
@@ -1,3 +1,24 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2004 The ScummVM project
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
#include "common/stdafx.h"
#include "sword2/sword2.h"
#include "sword2/driver/menu.h"
@@ -8,48 +29,48 @@
namespace Sword2 {
// Build 'Best-Match' RGB lookup table
-void MoviePlayer::buildlookup(AnimationState * st, int p, int lines) {
+void AnimationState::buildLookup(int p, int lines) {
int y, cb;
int r, g, b, ii;
- if (p != st->curpal) {
- st->curpal = p;
- st->cr = 0;
- st->pos = 0;
+ if (p != curpal) {
+ curpal = p;
+ cr = 0;
+ pos = 0;
}
- if (st->cr >= BITDEPTH)
+ if (cr >= BITDEPTH)
return;
for (ii = 0; ii < lines; ii++) {
- r = (-16*256 + (int)(256*1.596) * ((st->cr<<SHIFT)-128)) / 256;
+ r = (-16*256 + (int)(256*1.596) * ((cr<<SHIFT)-128)) / 256;
for (cb = 0; cb < BITDEPTH; cb++) {
- g = (-16*256 - (int)(0.813*256) * ((st->cr<<SHIFT)-128) - (int)(0.391*256) * ((cb<<SHIFT)-128)) / 256;
+ g = (-16*256 - (int)(0.813*256) * ((cr<<SHIFT)-128) - (int)(0.391*256) * ((cb<<SHIFT)-128)) / 256;
b = (-16*256 + (int)(2.018*256) * ((cb<<SHIFT)-128)) / 256;
for (y = 0; y < BITDEPTH; y++) {
int idx, bst = 0;
- int dis = 2*SQR(r-st->palettes[p].pal[0])+4*SQR(g-st->palettes[p].pal[1])+SQR(b-st->palettes[p].pal[2]);
+ int dis = 2*SQR(r-palettes[p].pal[0])+4*SQR(g-palettes[p].pal[1])+SQR(b-palettes[p].pal[2]);
for (idx = 1; idx < 256; idx++) {
- long d2 = 2*SQR(r-st->palettes[p].pal[4*idx])+4*SQR(g-st->palettes[p].pal[4*idx+1])+SQR(b-st->palettes[p].pal[4*idx+2]);
+ long d2 = 2*SQR(r-palettes[p].pal[4*idx])+4*SQR(g-palettes[p].pal[4*idx+1])+SQR(b-palettes[p].pal[4*idx+2]);
if (d2 < dis) {
bst = idx;
dis = d2;
+ }
}
+ lut2[pos++] = bst;
+
+ r += (1 << SHIFT);
+ g += (1 << SHIFT);
+ b += (1 << SHIFT);
}
- st->lut2[st->pos++] = bst;
-
- r += (1 << SHIFT);
- g += (1 << SHIFT);
- b += (1 << SHIFT);
+ r -= 256;
}
- r -= 256;
- }
- st->cr++;
- if (st->cr >= BITDEPTH)
- return;
+ cr++;
+ if (cr >= BITDEPTH)
+ return;
}
}
@@ -66,12 +87,12 @@ void MoviePlayer::checkPaletteSwitch(AnimationState * st) {
}
#ifndef USE_MPEG2
-bool MoviePlayer::pic(AnimationState * st) {
+bool MoviePlayer::decodeFrame(AnimationState * st) {
// Dummy for MPEG2-less builds
return false;
}
#else
-bool MoviePlayer::pic(AnimationState * st) {
+bool MoviePlayer::decodeFrame(AnimationState * st) {
mpeg2_state_t state;
const mpeg2_sequence_t *sequence_i;
size_t size = (size_t)-1;
@@ -92,13 +113,13 @@ bool MoviePlayer::pic(AnimationState * st) {
checkPaletteSwitch(st);
_vm->_graphics->plotYUV(st->lut, sequence_i->width, sequence_i->height, st->info->display_fbuf->buf);
st->framenum++;
- buildlookup(st, st->palnum+1, st->lutcalcnum);
+ st->buildLookup(st->palnum+1, st->lutcalcnum);
return true;
}
break;
default:
- break;
+ break;
}
} while (size);
@@ -107,11 +128,11 @@ bool MoviePlayer::pic(AnimationState * st) {
#endif
#ifndef USE_MPEG2
-AnimationState *MoviePlayer::initanimation(char *name) {
+AnimationState *MoviePlayer::initAnimation(const char *name) {
return 0;
}
#else
-AnimationState *MoviePlayer::initanimation(char *name) {
+AnimationState *MoviePlayer::initAnimation(const char *name) {
char basename[512], tempFile[512];
AnimationState *st = new AnimationState;
int i, p;
@@ -127,15 +148,19 @@ AnimationState *MoviePlayer::initanimation(char *name) {
if (!f) {
warning("Cutscene: %s.pal palette missing", basename);
return 0;
- }
+ }
p = 0;
while (!feof(f)) {
fscanf(f, "%i %i", &st->palettes[p].end, &st->palettes[p].cnt);
for (i = 0; i < st->palettes[p].cnt; i++) {
- fscanf(f, "%i", &st->palettes[p].pal[4*i]);
- fscanf(f, "%i", &st->palettes[p].pal[4*i+1]);
- fscanf(f, "%i", &st->palettes[p].pal[4*i+2]);
+ int r, g, b;
+ fscanf(f, "%i", &r);
+ fscanf(f, "%i", &g);
+ fscanf(f, "%i", &b);
+ st->palettes[p].pal[4*i] = r;
+ st->palettes[p].pal[4*i+1] = g;
+ st->palettes[p].pal[4*i+2] = b;
}
p++;
}
@@ -146,7 +171,7 @@ AnimationState *MoviePlayer::initanimation(char *name) {
st->lut = st->lut2 = st->lookup[0];
st->curpal = -1;
st->cr = 0;
- buildlookup(st, st->palnum, 256);
+ st->buildLookup(st->palnum, 256);
st->lut2 = st->lookup[1];
// Open MPEG2 stream
@@ -174,20 +199,24 @@ AnimationState *MoviePlayer::initanimation(char *name) {
/* Play audio - TODO: Sync with video?*/
+ // Another TODO: There is no reason that this only allows OGG, and not MP3, or any other format
+ // the mixer might support one day... is there?
File *sndFile = new File;
sprintf(tempFile, "%s.ogg", basename);
if (sndFile->open(tempFile))
_vm->_mixer->playVorbis(&st->bgSound, sndFile, 100000000);
+ // FIXME: This leaks (sndFile will never be deleted)
+
return st;
}
#endif
#ifndef USE_MPEG2
-void MoviePlayer::doneanimation(AnimationState *st) {
+void MoviePlayer::doneAnimation(AnimationState *st) {
}
#else
-void MoviePlayer::doneanimation(AnimationState *st) {
+void MoviePlayer::doneAnimation(AnimationState *st) {
_vm->_mixer->stopHandle(st->bgSound);
mpeg2_close (st->decoder);
diff --git a/sword2/driver/animation.h b/sword2/driver/animation.h
index 0f48d9a4b9..a6890df3c4 100644
--- a/sword2/driver/animation.h
+++ b/sword2/driver/animation.h
@@ -1,3 +1,24 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2004 The ScummVM project
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
#ifndef ANIMATION_H
#define ANIMATION_H
@@ -21,7 +42,8 @@ namespace Sword2 {
#define BUFFER_SIZE 4096
-typedef struct {
+class AnimationState {
+public:
int palnum;
byte lookup[2][BITDEPTH * BITDEPTH * BITDEPTH];
@@ -51,7 +73,10 @@ typedef struct {
PlayingSoundHandle bgSound;
-} AnimationState;
+public:
+ void buildLookup(int p, int lines);
+
+};
} // End of namespace Sword2
diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp
index 208d3872cc..a56b60af9e 100644
--- a/sword2/driver/d_draw.cpp
+++ b/sword2/driver/d_draw.cpp
@@ -140,7 +140,7 @@ void MoviePlayer::drawTextObject(MovieTextObject *obj) {
* @param musicOut lead-out music
*/
-int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut) {
+int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], uint8 *musicOut) {
#ifdef USE_MPEG2
int frameCounter = 0, textCounter = 0;
PlayingSoundHandle handle;
@@ -150,7 +150,7 @@ int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut
uint8 oldPal[1024];
memcpy(oldPal, _vm->_graphics->_palCopy, 1024);
- AnimationState * anim = initanimation(filename);
+ AnimationState * anim = initAnimation(filename);
if (!anim) {
// Missing Files? Use the old 'Narration Only' hack
playDummy(filename, text, musicOut);
@@ -166,7 +166,7 @@ int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut
#endif
while (1) {
- if (!pic(anim)) break;
+ if (!decodeFrame(anim)) break;
_vm->_graphics->setNeedFullRedraw();
if (text && text[textCounter]) {
@@ -240,7 +240,7 @@ int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut
_vm->_graphics->setPalette(0, 256, oldPal, RDPAL_INSTANT);
- doneanimation(anim);
+ doneAnimation(anim);
// Lead-in and lead-out music are, as far as I can tell, only used for
// the animated cut-scenes, so this seems like a good place to close
@@ -258,7 +258,7 @@ int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut
}
// This just plays the cutscene with voiceovers / subtitles, in case the files are missing
-int32 MoviePlayer::playDummy(char *filename, MovieTextObject *text[], uint8 *musicOut) {
+int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], uint8 *musicOut) {
int frameCounter = 0, textCounter = 0;
if (text) {
uint8 oldPal[1024];
@@ -310,7 +310,7 @@ int32 MoviePlayer::playDummy(char *filename, MovieTextObject *text[], uint8 *mus
tmpPal[255 * 4 + 2] = 255;
_vm->_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
-PlayingSoundHandle handle;
+ PlayingSoundHandle handle;
bool skipCutscene = false;
diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h
index eefb71ca30..f98e77999c 100644
--- a/sword2/driver/d_draw.h
+++ b/sword2/driver/d_draw.h
@@ -68,23 +68,22 @@ struct MouseAnim {
class MoviePlayer {
private:
Sword2Engine *_vm;
-
uint8 *_textSurface;
+
void openTextObject(MovieTextObject *obj);
void closeTextObject(MovieTextObject *obj);
void drawTextObject(MovieTextObject *obj);
- void buildlookup(AnimationState * st, int p, int lines);
void checkPaletteSwitch(AnimationState * st);
- AnimationState * initanimation(char *name);
- void doneanimation(AnimationState * st);
- bool pic(AnimationState * st);
+ AnimationState * initAnimation(const char *name);
+ void doneAnimation(AnimationState * st);
+ bool decodeFrame(AnimationState * st);
public:
MoviePlayer(Sword2Engine *vm) : _vm(vm), _textSurface(NULL) {}
- int32 play(char *filename, MovieTextObject *text[], uint8 *musicOut);
- int32 playDummy(char *filename, MovieTextObject *text[], uint8 *musicOut);
+ int32 play(const char *filename, MovieTextObject *text[], uint8 *musicOut);
+ int32 playDummy(const char *filename, MovieTextObject *text[], uint8 *musicOut);
};
struct BlockSurface {