GRIM: Implemented iris animation.

This commit is contained in:
Giulio Camuffo 2011-07-17 18:17:07 +02:00
parent f6d30ca6dd
commit 68427fdad4
8 changed files with 161 additions and 2 deletions

View file

@ -381,6 +381,7 @@ GrimEngine::GrimEngine(OSystem *syst, uint32 gameFlags, GrimGameType gameType, C
_listFilesIter = NULL; _listFilesIter = NULL;
_savedState = NULL; _savedState = NULL;
_fps[0] = 0; _fps[0] = 0;
_iris = new Iris();
Color *c = new Color(0, 0, 0); Color *c = new Color(0, 0, 0);
registerColor(c); registerColor(c);
@ -455,6 +456,7 @@ GrimEngine::~GrimEngine() {
g_resourceloader = NULL; g_resourceloader = NULL;
delete g_driver; delete g_driver;
g_driver = NULL; g_driver = NULL;
delete _iris;
} }
Common::Error GrimEngine::run() { 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() { void GrimEngine::luaUpdate() {
if (_savegameLoadRequest || _savegameSaveRequest) if (_savegameLoadRequest || _savegameSaveRequest)
return; return;
@ -996,6 +1002,7 @@ void GrimEngine::updateDisplayScene() {
_currScene->drawBitmaps(ObjectState::OBJSTATE_OVERLAY); _currScene->drawBitmaps(ObjectState::OBJSTATE_OVERLAY);
drawPrimitives(); drawPrimitives();
_iris->draw();
} else if (_mode == ENGINE_MODE_DRAW) { } else if (_mode == ENGINE_MODE_DRAW) {
_doFlip = false; _doFlip = false;
_prevSmushFrame = 0; _prevSmushFrame = 0;

View file

@ -31,6 +31,7 @@
#include "engines/advancedDetector.h" #include "engines/advancedDetector.h"
#include "engines/grim/textobject.h" #include "engines/grim/textobject.h"
#include "engines/grim/iris.h"
namespace Grim { namespace Grim {
@ -118,6 +119,7 @@ public:
bool getFlipEnable() { return _flipEnable; } bool getFlipEnable() { return _flipEnable; }
void refreshDrawMode() { _refreshDrawNeeded = true; } void refreshDrawMode() { _refreshDrawNeeded = true; }
void drawPrimitives(); void drawPrimitives();
void playIrisAnimation(Iris::Direction dir, int x, int y, int time);
void mainLoop(); void mainLoop();
unsigned getFrameStart() const { return _frameStart; } unsigned getFrameStart() const { return _frameStart; }
@ -272,6 +274,7 @@ private:
Actor *_selectedActor; Actor *_selectedActor;
Actor *_talkingActor; Actor *_talkingActor;
Iris *_iris;
SceneListType _scenes; SceneListType _scenes;
ActorListType _actors; ActorListType _actors;

79
engines/grim/iris.cpp Normal file
View file

@ -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);
}
}

52
engines/grim/iris.h Normal file
View file

@ -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

View file

@ -277,6 +277,8 @@ void L1_SetLightIntensity();
void L1_SetLightPosition(); void L1_SetLightPosition();
void L1_TurnLightOn(); void L1_TurnLightOn();
void L1_RenderModeUser(); void L1_RenderModeUser();
void L1_IrisUp();
void L1_IrisDown();
void L1_SetGamma(); void L1_SetGamma();
void L1_Display(); void L1_Display();
void L1_EngineDisplay(); void L1_EngineDisplay();

View file

@ -1299,8 +1299,6 @@ STUB_FUNC(L1_NukeResources)
STUB_FUNC(L1_ResetTextures) STUB_FUNC(L1_ResetTextures)
STUB_FUNC(L1_AttachToResources) STUB_FUNC(L1_AttachToResources)
STUB_FUNC(L1_DetachFromResources) STUB_FUNC(L1_DetachFromResources)
STUB_FUNC(L1_IrisUp)
STUB_FUNC(L1_IrisDown)
STUB_FUNC(L1_SetActorClipPlane) STUB_FUNC(L1_SetActorClipPlane)
STUB_FUNC(L1_SetActorClipActive) STUB_FUNC(L1_SetActorClipActive)
STUB_FUNC(L1_SetActorCollisionScale) STUB_FUNC(L1_SetActorCollisionScale)

View file

@ -32,6 +32,7 @@
#include "engines/grim/colormap.h" #include "engines/grim/colormap.h"
#include "engines/grim/bitmap.h" #include "engines/grim/bitmap.h"
#include "engines/grim/primitives.h" #include "engines/grim/primitives.h"
#include "engines/grim/iris.h"
#include "engines/grim/movie/movie.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 } // end of namespace Grim

View file

@ -50,6 +50,7 @@ MODULE_OBJS := \
gfx_opengl.o \ gfx_opengl.o \
gfx_tinygl.o \ gfx_tinygl.o \
grim.o \ grim.o \
iris.o \
keyframe.o \ keyframe.o \
lab.o \ lab.o \
lipsync.o \ lipsync.o \