From 68427fdad4476b67286d0ba36cdff1fa79fc6951 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sun, 17 Jul 2011 18:17:07 +0200 Subject: [PATCH] GRIM: Implemented iris animation. --- engines/grim/grim.cpp | 7 +++ engines/grim/grim.h | 3 ++ engines/grim/iris.cpp | 79 ++++++++++++++++++++++++++++++++ engines/grim/iris.h | 52 +++++++++++++++++++++ engines/grim/lua.h | 2 + engines/grim/lua_v1.cpp | 2 - engines/grim/lua_v1_graphics.cpp | 17 +++++++ engines/grim/module.mk | 1 + 8 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 engines/grim/iris.cpp create mode 100644 engines/grim/iris.h diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp index 4b80ea599f5..ecfbd14ea96 100644 --- a/engines/grim/grim.cpp +++ b/engines/grim/grim.cpp @@ -381,6 +381,7 @@ GrimEngine::GrimEngine(OSystem *syst, uint32 gameFlags, GrimGameType gameType, C _listFilesIter = NULL; _savedState = NULL; _fps[0] = 0; + _iris = new Iris(); Color *c = new Color(0, 0, 0); registerColor(c); @@ -455,6 +456,7 @@ GrimEngine::~GrimEngine() { g_resourceloader = NULL; delete g_driver; g_driver = NULL; + delete _iris; } Common::Error GrimEngine::run() { @@ -858,6 +860,10 @@ void GrimEngine::drawPrimitives() { } } +void GrimEngine::playIrisAnimation(Iris::Direction dir, int x, int y, int time) { + _iris->play(dir, x, y, time); +} + void GrimEngine::luaUpdate() { if (_savegameLoadRequest || _savegameSaveRequest) return; @@ -996,6 +1002,7 @@ void GrimEngine::updateDisplayScene() { _currScene->drawBitmaps(ObjectState::OBJSTATE_OVERLAY); drawPrimitives(); + _iris->draw(); } else if (_mode == ENGINE_MODE_DRAW) { _doFlip = false; _prevSmushFrame = 0; diff --git a/engines/grim/grim.h b/engines/grim/grim.h index 8a99dfd1f38..f2ab37c5a21 100644 --- a/engines/grim/grim.h +++ b/engines/grim/grim.h @@ -31,6 +31,7 @@ #include "engines/advancedDetector.h" #include "engines/grim/textobject.h" +#include "engines/grim/iris.h" namespace Grim { @@ -118,6 +119,7 @@ public: bool getFlipEnable() { return _flipEnable; } void refreshDrawMode() { _refreshDrawNeeded = true; } void drawPrimitives(); + void playIrisAnimation(Iris::Direction dir, int x, int y, int time); void mainLoop(); unsigned getFrameStart() const { return _frameStart; } @@ -272,6 +274,7 @@ private: Actor *_selectedActor; Actor *_talkingActor; + Iris *_iris; SceneListType _scenes; ActorListType _actors; diff --git a/engines/grim/iris.cpp b/engines/grim/iris.cpp new file mode 100644 index 00000000000..8c6c8588c3d --- /dev/null +++ b/engines/grim/iris.cpp @@ -0,0 +1,79 @@ +/* Residual - A 3D game interpreter + * + * Residual 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#include "engines/grim/iris.h" +#include "engines/grim/gfx_base.h" +#include "engines/grim/grim.h" + +namespace Grim { + +Iris::Iris() : + _playing(false), _direction(Open) { + +} + +Iris::~Iris() { + +} + +void Iris::play(Iris::Direction dir, int x, int y, int lenght) { + _playing = true; + _direction = dir; + _x = x; + _y = y; + _lenght = lenght; + _currTime = 0; +} + +void Iris::draw() { + if (!_playing) { + if (_direction == Close) { + g_driver->dimRegion(0, 0, 640, 479, 0); + } + return; + } + + _currTime += g_grim->getFrameTime(); + if (_currTime >= _lenght) { + _playing = false; + if (_direction == Close) { + g_driver->dimRegion(0, 0, 640, 479, 0); + } + return; + } + + float factor = (float)_currTime / (float)_lenght; + if (_direction == Open) { + factor = 1 - factor; + } + + int y = _y * factor; + int x = _x * factor; + + // Why doesn't 480 work here?? + g_driver->dimRegion(0, 0, 640, y, 0); + g_driver->dimRegion(0, y, x, 479 - y, 0); + g_driver->dimRegion(x, 479 - y, 640 - x, y, 0); + g_driver->dimRegion(640 - x, y, x, 479 - y, 0); +} + +} diff --git a/engines/grim/iris.h b/engines/grim/iris.h new file mode 100644 index 00000000000..eef327b9b4d --- /dev/null +++ b/engines/grim/iris.h @@ -0,0 +1,52 @@ +/* Residual - A 3D game interpreter + * + * Residual 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#ifndef GRIM_IRIS_H +#define GRIM_IRIS_H + +namespace Grim { + +class Iris { +public: + enum Direction { + Open, + Close + }; + + Iris(); + ~Iris(); + + void play(Direction dir, int x, int y, int lenght); + void draw(); + +private: + bool _playing; + Direction _direction; + int _x; + int _y; + int _lenght; + int _currTime; +}; + +} // end of namespace Grim + +#endif diff --git a/engines/grim/lua.h b/engines/grim/lua.h index 216c13192b4..bc70aaf98e7 100644 --- a/engines/grim/lua.h +++ b/engines/grim/lua.h @@ -277,6 +277,8 @@ void L1_SetLightIntensity(); void L1_SetLightPosition(); void L1_TurnLightOn(); void L1_RenderModeUser(); +void L1_IrisUp(); +void L1_IrisDown(); void L1_SetGamma(); void L1_Display(); void L1_EngineDisplay(); diff --git a/engines/grim/lua_v1.cpp b/engines/grim/lua_v1.cpp index 625b07cfdfa..ff55ba4c4e0 100644 --- a/engines/grim/lua_v1.cpp +++ b/engines/grim/lua_v1.cpp @@ -1299,8 +1299,6 @@ STUB_FUNC(L1_NukeResources) STUB_FUNC(L1_ResetTextures) STUB_FUNC(L1_AttachToResources) STUB_FUNC(L1_DetachFromResources) -STUB_FUNC(L1_IrisUp) -STUB_FUNC(L1_IrisDown) STUB_FUNC(L1_SetActorClipPlane) STUB_FUNC(L1_SetActorClipActive) STUB_FUNC(L1_SetActorCollisionScale) diff --git a/engines/grim/lua_v1_graphics.cpp b/engines/grim/lua_v1_graphics.cpp index f62e9feef0e..b8718da066d 100644 --- a/engines/grim/lua_v1_graphics.cpp +++ b/engines/grim/lua_v1_graphics.cpp @@ -32,6 +32,7 @@ #include "engines/grim/colormap.h" #include "engines/grim/bitmap.h" #include "engines/grim/primitives.h" +#include "engines/grim/iris.h" #include "engines/grim/movie/movie.h" @@ -538,4 +539,20 @@ void L1_RenderModeUser() { } } +void L1_IrisUp() { + lua_Object xObj = lua_getparam(1); + lua_Object yObj = lua_getparam(2); + lua_Object timeObj = lua_getparam(3); + + g_grim->playIrisAnimation(Iris::Open, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj)); +} + +void L1_IrisDown() { + lua_Object xObj = lua_getparam(1); + lua_Object yObj = lua_getparam(2); + lua_Object timeObj = lua_getparam(3); + + g_grim->playIrisAnimation(Iris::Close, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj)); +} + } // end of namespace Grim diff --git a/engines/grim/module.mk b/engines/grim/module.mk index 2e862eca9dc..658dd5dbe3c 100644 --- a/engines/grim/module.mk +++ b/engines/grim/module.mk @@ -50,6 +50,7 @@ MODULE_OBJS := \ gfx_opengl.o \ gfx_tinygl.o \ grim.o \ + iris.o \ keyframe.o \ lab.o \ lipsync.o \