DIRECTOR: LINGO: move XPlayAnim to XObject

XPlayAnim is an XObject. It was only used as a regular builtin during
development.
This commit is contained in:
Roland van Laar 2022-03-06 12:01:06 +01:00
parent d22859680a
commit 1902b94c13
6 changed files with 169 additions and 71 deletions

View File

@ -22,8 +22,6 @@
#include "common/system.h"
#include "common/tokenizer.h"
#include "video/paco_decoder.h"
#include "gui/message.h"
#include "graphics/macgui/macwindowmanager.h"
@ -226,8 +224,6 @@ static BuiltinProto builtins[] = {
{ "scummvmAssert", LB::b_scummvmassert,1, 2, 200, HBLTIN },
{ "scummvmAssertEqual", LB::b_scummvmassertequal,2,3,200,HBLTIN },
// Expose Paco
{ "XPlayAnim", LB::b_xPlayAnim, 3,3, 300, HBLTIN },
// XCMD/XFCN (HyperCard), normally exposed
{ "GetVolumes", LB::b_getVolumes, 0, 0, 400, FBLTIN },
@ -2727,70 +2723,6 @@ void LB::b_scummvmassertequal(int nargs) {
assert(result == 1);
}
void LB::b_xPlayAnim(int nargs){
int y = g_lingo->pop().asInt();
int x = g_lingo->pop().asInt();
Common::String filename = g_lingo->pop().asString();
debugN(5, "LB::b_xPlayAnim: x: %i y: %i", x, y);
Video::PacoDecoder *video = new Video::PacoDecoder();
video->loadFile(Common::Path(filename, g_director->_dirSeparator));
// save the current palette
byte origPalette[256 * 3];
uint16 origCount = g_director->getPaletteColorCount();
if (origCount > 256) {
warning("b_xPlayAnim: too big palette, %d > 256", origCount);
origCount = 256;
}
memcpy(origPalette, g_director->getPalette(), origCount * 3);
Graphics::Surface const *frame;
Common::Event event;
bool keepPlaying = true;
video->start();
while (!video->endOfVideo()) {
if (g_system->getEventManager()->pollEvent(event)) {
switch(event.type) {
case Common::EVENT_QUIT:
g_director->processEventQUIT();
// fallthrough
case Common::EVENT_KEYDOWN:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_LBUTTONDOWN:
keepPlaying = false;
break;
default:
break;
}
}
if (!keepPlaying)
break;
if (video->needsUpdate()) {
frame = video->decodeNextFrame();
g_system->copyRectToScreen(frame->getPixels(), frame->pitch, x, y, frame->w, frame->h);
}
if (video->hasDirtyPalette()) {
byte *palette = const_cast<byte *>(video->getPalette());
g_director->setPalette(palette, 256);
}
g_system->updateScreen();
g_system->delayMillis(10);
}
// Display the last frame after the video is done
g_director->getCurrentWindow()->getSurface()->copyRectToSurface(
frame->getPixels(), frame->pitch, x, y, frame->w, frame->h
);
video->close();
delete video;
// restore the palette
g_director->setPalette(origPalette, origCount);
}
void LB::b_getVolumes(int nargs) {
// Right now, only "Journeyman Project 2: Buried in Time" is known to check
// for its volume name.

View File

@ -194,8 +194,6 @@ void b_numberofwords(int nargs);
void b_scummvmassert(int nargs);
void b_scummvmassertequal(int nargs);
void b_xPlayAnim(int nargs);
// XCMD/XFCN (HyperCard), normally exposed
void b_getVolumes(int nargs);

View File

@ -48,6 +48,7 @@
#include "director/lingo/xlibs/soundjam.h"
#include "director/lingo/xlibs/videodiscxobj.h"
#include "director/lingo/xlibs/winxobj.h"
#include "director/lingo/xlibs/xplayanim.h"
namespace Director {
@ -131,6 +132,7 @@ static struct XLibProto {
{ VideodiscXObj::fileNames, VideodiscXObj::open, VideodiscXObj::close, kXObj, 200 }, // D2
{ RearWindowXObj::fileNames, RearWindowXObj::open, RearWindowXObj::close, kXObj, 400 }, // D4
{ MoveMouseXObj::fileNames, MoveMouseXObj::open, MoveMouseXObj::close, kXObj, 400 }, // D4
{ XPlayAnim::fileNames, XPlayAnim::open, XPlayAnim::close, kXObj, 300 }, // D3
{ nullptr, nullptr, nullptr, 0, 0 }
};

View File

@ -0,0 +1,115 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "video/paco_decoder.h"
#include "director/director.h"
#include "director/window.h"
#include "director/lingo/lingo.h"
#include "director/lingo/lingo-object.h"
#include "director/lingo/xlibs/xplayanim.h"
namespace Director {
const char *XPlayAnim::xlibName = "XPlayAnim";
const char *XPlayAnim::fileNames[] = {
"XPlayAnim",
nullptr
};
static BuiltinProto builtins[] = {
{ "XPlayAnim", XPlayAnim::b_xplayanim, 3, 3, 300, HBLTIN },
{ nullptr, nullptr, 0, 0, 0, VOIDSYM }
};
void XPlayAnim::open(int type) {
g_lingo->initBuiltIns(builtins);
}
void XPlayAnim::close(int type) {
g_lingo->cleanupBuiltIns();
}
void XPlayAnim::b_xplayanim(int nargs) {
int y = g_lingo->pop().asInt();
int x = g_lingo->pop().asInt();
Common::String filename = g_lingo->pop().asString();
debugN(5, "LB::b_xPlayAnim: x: %i y: %i", x, y);
Video::PacoDecoder *video = new Video::PacoDecoder();
video->loadFile(Common::Path(filename, g_director->_dirSeparator));
// save the current palette
byte origPalette[256 * 3];
uint16 origCount = g_director->getPaletteColorCount();
if (origCount > 256) {
warning("b_xPlayAnim: too big palette, %d > 256", origCount);
origCount = 256;
}
memcpy(origPalette, g_director->getPalette(), origCount * 3);
Graphics::Surface const *frame;
Common::Event event;
bool keepPlaying = true;
video->start();
while (!video->endOfVideo()) {
if (g_system->getEventManager()->pollEvent(event)) {
switch(event.type) {
case Common::EVENT_QUIT:
g_director->processEventQUIT();
// fallthrough
case Common::EVENT_KEYDOWN:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_LBUTTONDOWN:
keepPlaying = false;
break;
default:
break;
}
}
if (!keepPlaying)
break;
if (video->needsUpdate()) {
frame = video->decodeNextFrame();
g_system->copyRectToScreen(frame->getPixels(), frame->pitch, x, y, frame->w, frame->h);
}
if (video->hasDirtyPalette()) {
byte *palette = const_cast<byte *>(video->getPalette());
g_director->setPalette(palette, 256);
}
g_system->updateScreen();
g_system->delayMillis(10);
}
// Display the last frame after the video is done
g_director->getCurrentWindow()->getSurface()->copyRectToSurface(
frame->getPixels(), frame->pitch, x, y, frame->w, frame->h
);
video->close();
delete video;
// restore the palette
g_director->setPalette(origPalette, origCount);
}
} // End of namespace Director

View File

@ -0,0 +1,50 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*************************************
*
* Xobject to play PACo video files
*
* USED IN:
* Hell Cab, Journeyman Mac, Iron Helix Mac
*
*************************************/
#ifndef DIRECTOR_LINGO_XLIBS_XPLAYANIMXOBJ_H
#define DIRECTOR_LINGO_XLIBS_XPLAYANIMXOBJ_H
namespace Director {
namespace XPlayAnim {
extern const char *xlibName;
extern const char *fileNames[];
void open(int type);
void close(int type);
void b_xplayanim(int nargs);
} // End of namespace XPlayAnim
} // End of namespace Director
#endif

View File

@ -50,7 +50,8 @@ MODULE_OBJS = \
lingo/xlibs/serialportxobj.o \
lingo/xlibs/soundjam.o \
lingo/xlibs/videodiscxobj.o \
lingo/xlibs/winxobj.o
lingo/xlibs/winxobj.o \
lingo/xlibs/xplayanim.o
# HACK: Skip this when including the file for detection objects.
ifeq "$(USE_RULES)" "1"