1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef BLADERUNNER_SLICE_RENDERER_H
24 #define BLADERUNNER_SLICE_RENDERER_H
25 
26 #include "bladerunner/color.h"
27 #include "bladerunner/vector.h"
28 #include "bladerunner/view.h"
29 #include "bladerunner/matrix.h"
30 
31 #include "common/rect.h"
32 
33 #include "graphics/surface.h"
34 
35 namespace Common {
36 class MemoryReadStream;
37 }
38 
39 namespace BladeRunner {
40 
41 class ScreenEffects;
42 class BladeRunnerEngine;
43 class Lights;
44 class SetEffects;
45 
46 class SliceRenderer {
47 	BladeRunnerEngine *_vm;
48 
49 	int       _animation;
50 	int       _frame;
51 	Vector3   _position;
52 	float     _facing;
53 	float     _scale;
54 
55 	ScreenEffects *_screenEffects;
56 	View          *_view;
57 	Lights        *_lights;
58 	SetEffects    *_setEffects;
59 
60 	void *_sliceFramePtr;
61 
62 	// Animation frame data
63 	Vector2 _frameScale;
64 	float   _frameBottomZ;
65 	Vector2 _framePos;
66 	float   _frameSliceHeight;
67 	uint32  _framePaletteIndex;
68 	uint32  _frameSliceCount;
69 
70 	Matrix3x2    _mvpMatrix;
71 	Vector3      _startScreenVector;
72 	Vector3      _endScreenVector;
73 	float        _startSlice;
74 	float        _endSlice;
75 	Common::Rect _screenRectangle;
76 
77 	int _m11lookup[256];
78 	int _m12lookup[256];
79 	int _m13;
80 	int _m21lookup[256];
81 	int _m22lookup[256];
82 	int _m23;
83 
84 	bool _animationsShadowEnabled[997];
85 
86 	Vector3 _shadowPolygonDefault[12];
87 	Vector3 _shadowPolygonCurrent[12];
88 
89 	Color _setEffectColor;
90 	Color _lightsColor;
91 
92 	Graphics::PixelFormat _pixelFormat;
93 
94 public:
95 	SliceRenderer(BladeRunnerEngine *vm);
96 	~SliceRenderer();
97 
98 	void setScreenEffects(ScreenEffects *aesc);
99 	void setView(View *view);
100 	void setLights(Lights *lights);
101 	void setSetEffects(SetEffects *setEffects);
102 
103 	void setupFrameInWorld(int animationId, int animationFrame, Vector3 position, float facing, float scale = 1.0f);
104 	void getScreenRectangle(Common::Rect *screenRectangle, int animationId, int animationFrame, Vector3 position, float facing, float scale);
105 	void drawInWorld(int animationId, int animationFrame, Vector3 position, float facing, float scale, Graphics::Surface &surface, uint16 *zbuffer);
106 	void drawOnScreen(int animationId, int animationFrame, int screenX, int screenY, float facing, float scale, Graphics::Surface &surface);
107 
108 	void preload(int animationId);
109 
110 	void disableShadows(int *animationsIdsList, int listSize);
111 
112 private:
113 	void calculateBoundingRect();
114 	Matrix3x2 calculateFacingRotationMatrix();
115 	void loadFrame(int animation, int frame);
116 
117 	void drawSlice(int slice, bool advanced, int y, Graphics::Surface &surface, uint16 *zbufferLine);
118 	void drawShadowInWorld(int transparency, Graphics::Surface &surface, uint16 *zbuffer);
119 	void drawShadowPolygon(int transparency, Graphics::Surface &surface, uint16 *zbuffer);
120 };
121 
122 class SliceRendererLights {
123 	Lights *_lights;
124 	Color   _cacheColor[20];
125 	float   _cacheCounter[20];
126 	float   _cacheStart[20];
127 	int     _cacheRecalculation;
128 
129 public:
130 	Color   _finalColor;
131 
132 public:
133 	SliceRendererLights(Lights *lights);
134 
135 	void calculateColorBase(Vector3 position1, Vector3 position2, float height);
136 	void calculateColorSlice(Vector3 position);
137 };
138 
139 } // End of namespace BladeRunner
140 
141 #endif
142