1
// -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi:tw=80:et:ts=2:sts=2
4
// -----------------------------------------------------------------------
6
// This file is part of RLVM, a RealLive virtual machine clone.
8
// -----------------------------------------------------------------------
10
// Copyright (C) 2009 Elliot Glaysher
12
// This program is free software; you can redistribute it and/or modify
13
// it under the terms of the GNU General Public License as published by
14
// the Free Software Foundation; either version 3 of the License, or
15
// (at your option) any later version.
17
// This program is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
// GNU General Public License for more details.
22
// You should have received a copy of the GNU General Public License
23
// along with this program; if not, write to the Free Software
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25
// -----------------------------------------------------------------------
27
#include "Utilities/Graphics.hpp"
32
#include <boost/assign/list_of.hpp>
34
#include "MachineBase/RLMachine.hpp"
35
#include "Systems/Base/Rect.hpp"
36
#include "Systems/Base/System.hpp"
37
#include "Systems/Base/SystemError.hpp"
38
#include "libReallive/gameexe.h"
41
using namespace boost::assign;
43
std::vector<int> getSELEffect(RLMachine& machine, int selNum) {
44
Gameexe& gexe = machine.system().gameexe();
45
vector<int> selEffect;
47
if (gexe("SEL", selNum).exists()) {
48
selEffect = gexe("SEL", selNum).to_intVector();
49
grpToRecCoordinates(selEffect[0], selEffect[1],
50
selEffect[2], selEffect[3]);
51
} else if (gexe("SELR", selNum).exists()) {
52
selEffect = gexe("SELR", selNum).to_intVector();
54
// Can't find the specified #SEL effect. See if there's a #SEL.000 effect:
55
if (gexe("SEL", 0).exists()) {
56
selEffect = gexe("SEL", 0).to_intVector();
57
grpToRecCoordinates(selEffect[0], selEffect[1],
58
selEffect[2], selEffect[3]);
59
} else if (gexe("SELR", 0).exists()) {
60
selEffect = gexe("SELR", 0).to_intVector();
62
// Crap! Couldn't fall back on the default one either, so instead return
63
// a SEL vector that is a screenwide, short fade because we absolutely
65
Size screen = getScreenSize(gexe);
66
selEffect = list_of(0)(0)(screen.width())(screen.height())(0)(0)(1000)
67
(000)(0)(0)(0)(0)(0)(0)(255)(0);
74
void getSELPointAndRect(RLMachine& machine, int selNum, Rect& rect,
76
vector<int> selEffect = getSELEffect(machine, selNum);
77
rect = Rect::REC(selEffect[0], selEffect[1], selEffect[2], selEffect[3]);
78
point = Point(selEffect[4], selEffect[5]);
81
Size getScreenSize(Gameexe& gameexe) {
82
std::vector<int> graphicsMode = gameexe("SCREENSIZE_MOD");
83
if (graphicsMode.size()) {
84
if (graphicsMode[0] == 0) {
85
return Size(640, 480);
86
} else if (graphicsMode[0] == 1) {
87
return Size(800, 600);
88
} else if (graphicsMode[0] == 999 && graphicsMode.size() >= 3) {
89
return Size(graphicsMode[1], graphicsMode[2]);
92
oss << "Illegal #SCREENSIZE_MOD value: " << graphicsMode[0] << endl;
93
throw SystemError(oss.str());
98
oss << "Missing #SCREENSIZE_MOD key";
99
throw SystemError(oss.str());
102
void clamp(float& var, float min, float max) {
109
void ClipDestination(const Rect& clip_rect, Rect& src, Rect& dest) {
110
Rect intersection = clip_rect.intersection(dest);
111
if (intersection.size().isEmpty()) {
117
// TODO(erg): Doesn't deal with clipping the right side because we don't
118
// really want an intersection here; we want it clipped to.
120
if (src.size() == dest.size()) {
121
Size top_left_offset = intersection.origin() - dest.origin();
123
src = Rect(src.origin() + top_left_offset, intersection.size());
125
cerr << "Doesn't deal with different sizes in ClipDestination!" << endl;