1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
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.
21  *
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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_REMORA_SPRITE_H_INCLUDED
29 #define ICB_REMORA_SPRITE_H_INCLUDED
30 
31 #include "engines/icb/p4.h"
32 #include "engines/icb/debug.h"
33 #include "engines/icb/string_vest.h"
34 #include "engines/icb/common/px_clu_api.h"
35 #include "engines/icb/common/px_string.h"
36 #include "engines/icb/common/px_common.h"
37 #include "engines/icb/common/px_bitmap.h"
38 
39 namespace ICB {
40 
41 // Use this structure to pass extra information into the Remora sprite drawing functions.
42 struct _rs_params {
43 	uint32 nW, nH;    // PSX only.  Width to draw (use values in sprite if nW==0 and nH==0.
44 	bool8 bAllFrames; // PSX only.  Used for decompression.
45 	uint8 r, g, b;    // PSX only.  RGB scaling values.
46 	bool8 bCentre;    // PC & PSX.  If true, sprite is centred on coordinate.
47 	uint8 nOpacity;   // PC only (I think).  If not 255, sprite is blended into surface.
48 	bool8 bUpdate;    // PC & PSX.  If true, frame count is automatically updated.
49 	uint8 nPad1;
50 
51 	// Initialisation.
_rs_params_rs_params52 	_rs_params() {
53 		nW = 0;              // Defaults to zero, so value is read from the sprite.
54 		nH = 0;              // Ditto.
55 		bAllFrames = FALSE8; // Whatever it is, it's off.
56 		r = 128;             // I'll have to check these.  I think 128 means 'no colour scale'.
57 		g = 128;             // Ditto.
58 		b = 128;             // Ditto.
59 		bCentre = TRUE8;     // Centre the sprite by default.
60 		nOpacity = 255;      // Draw it with no transparency.
61 		bUpdate = TRUE8;     // Update the frame counter, so it animates.
62 	}
63 };
64 
65 class _remora_sprite {
66 public:
67 	// Constructor and destructor.
68 	_remora_sprite();
~_remora_sprite()69 	~_remora_sprite() { ; }
70 
71 	// Copy constructor and assignment.
72 	_remora_sprite(const _remora_sprite &oX);
73 	const _remora_sprite &operator=(const _remora_sprite &oOpB);
74 
75 	// This sets up the object for a particular animating bitmap.
76 	void InitialiseFromBitmapName(const char *pcBitmapName, const char *pcClusterName, uint32 nClusterash);
77 
78 	// These return the size of a loaded sprite.
79 	uint32 GetHeight();
80 	uint32 GetWidth();
81 
82 	// These draw sprites on the Remora's screen.
83 	inline void DrawSprite(const _rs_params *pParams = NULL);
84 	inline void DrawXYSprite(int32 nX, int32 nY, const _rs_params *pParams = NULL);
85 
86 	inline bool8 FitsOnScreen(int32 nX, int32 nZ, int32 nScreenWidth, int32 nScreenHeight) const;
87 
88 private:
89 	char m_pcName[MAXLEN_URL]; // The full path and name of the sprite.
90 
91 	uint32 m_nNameHash;                       // The hash version of the name of the sprite.
92 	char m_pcClusterName[MAXLEN_CLUSTER_URL]; // Name of the cluster the sprite is coming from.
93 	uint32 m_nClusterHash;                    // Hash of the cluster the sprite is coming from.
94 
95 	uint32 m_nFramePC;   // Frame counter for running animations.
96 	uint32 m_nNumFrames; // Number of frames in the animation.
97 
98 	int32 m_nHalfSpriteWidth;  // These two store half the sprite's width and height
99 	int32 m_nHalfSpriteHeight; // so we can work out an area that they can legally be plotted.
100 
101 	// Private functions used only in this class.
102 	void GenericSpriteDraw(int32 nX, int32 nY, bool8 bPosition, const _rs_params *pParams);
103 };
104 
DrawSprite(const _rs_params * pParams)105 inline void _remora_sprite::DrawSprite(const _rs_params *pParams) { GenericSpriteDraw(0, 0, FALSE8, pParams); }
106 
DrawXYSprite(int32 nX,int32 nY,const _rs_params * pParams)107 inline void _remora_sprite::DrawXYSprite(int32 nX, int32 nY, const _rs_params *pParams) { GenericSpriteDraw(nX, nY, TRUE8, pParams); }
108 
FitsOnScreen(int32 nX,int32 nZ,int32 nScreenWidth,int32 nScreenHeight)109 inline bool8 _remora_sprite::FitsOnScreen(int32 nX, int32 nZ, int32 nScreenWidth, int32 nScreenHeight) const {
110 	if ((nX > m_nHalfSpriteWidth) && (nX < (nScreenWidth - m_nHalfSpriteWidth)) && (nZ > m_nHalfSpriteHeight) && (nZ < (nScreenHeight - m_nHalfSpriteHeight)))
111 		return (TRUE8);
112 	else
113 		return (FALSE8);
114 
115 }
116 
117 } // End of namespace ICB
118 
119 #endif // #if !defined( REMORA_SPRITE_H_INCLUDED )
120