forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.h
More file actions
171 lines (141 loc) · 7.3 KB
/
Image.h
File metadata and controls
171 lines (141 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: Image.h //////////////////////////////////////////////////////////////////////////////////
// Created: Colin Day, June 2001
// Desc: High level representation of images, this is currently being
// written so we have a way to refer to images in the windows GUI.
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "Common/AsciiString.h"
#include "Common/GameMemory.h"
#include "Common/SubsystemInterface.h"
#include <map>
struct FieldParse;
class INI;
//-------------------------------------------------------------------------------------------------
/** Image status bits. Keep in sync with imageStatusNames[] */
//-------------------------------------------------------------------------------------------------
typedef enum
{
IMAGE_STATUS_NONE = 0x00000000,
IMAGE_STATUS_ROTATED_90_CLOCKWISE = 0x00000001, // image should be treated as rotated
IMAGE_STATUS_RAW_TEXTURE = 0x00000002, // image struct contains raw texture data
} ImageStatus;
#ifdef DEFINE_IMAGE_STATUS_NAMES
static const char *const imageStatusNames[] =
{
"ROTATED_90_CLOCKWISE",
"RAW_TEXTURE",
nullptr
};
#endif // end DEFINE_IMAGE_STATUS_NAMES
//-------------------------------------------------------------------------------------------------
/** Image bitmap information */
//-------------------------------------------------------------------------------------------------
class Image : public MemoryPoolObject
{
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( Image, "Image" );
public:
Image();
// virtual destructor defined by memory pool object
void setName( AsciiString name ); ///< set image name
AsciiString getName() const; ///< return name
void setFilename( AsciiString filename ); ///< set filename
AsciiString getFilename() const; ///< return filename
void setUV( Region2D *uv ); ///< set UV coord range
const Region2D *getUV() const; ///< get UV coords
void setTextureWidth( Int width ); ///< set width of texture page this image is on
void setTextureHeight( Int height ); ///< set height of texture page this image is on
const ICoord2D *getTextureSize() const; ///< return the texture size defined
void setImageSize( ICoord2D *size ); ///< set image width and height
const ICoord2D *getImageSize() const; ///< get size
Int getImageWidth() const; ///< get width
Int getImageHeight() const; ///< get height
void setRawTextureData( void *data ); ///< set raw texture data
const void *getRawTextureData() const; ///< get raw texture data
UnsignedInt setStatus( UnsignedInt bit ); ///< set status bit
UnsignedInt clearStatus( UnsignedInt bit ); ///< clear status bit
UnsignedInt getStatus() const; ///< get status bits
// for parsing from INI
const FieldParse *getFieldParse() const { return m_imageFieldParseTable; }
static void parseImageCoords( INI* ini, void *instance, void *store, const void* /*userData*/ );
static void parseImageStatus( INI* ini, void *instance, void *store, const void* /*userData*/ );
protected:
friend class ImageCollection;
AsciiString m_name; ///< name for this image
AsciiString m_filename; ///< texture filename this image is in
ICoord2D m_textureSize; ///< size of the texture this image is a part of
Region2D m_UVCoords; ///< texture UV coords for image
ICoord2D m_imageSize; ///< dimensions of image
void *m_rawTextureData; ///< raw texture data
UnsignedInt m_status; ///< status bits from ImageStatus
static const FieldParse m_imageFieldParseTable[]; ///< the parse table for INI definition
};
//-------------------------------------------------------------------------------------------------
/** A collection of images */
//-------------------------------------------------------------------------------------------------
class ImageCollection : public SubsystemInterface
{
typedef std::map<NameKeyType, Image *> ImageMap;
public:
ImageCollection();
virtual ~ImageCollection() override;
virtual void init() override { }; ///< initialize system
virtual void reset() override { }; ///< reset system
virtual void update() override { }; ///< update system
void load( Int textureSize ); ///< load images
const Image *findImage( NameKeyType namekey ) const; ///< find image based on name key
const Image *findImageByName( const AsciiString& name ) const; ///< find image based on name
const Image *findImageByName( const char* name ) const; ///< find image based on name
/// adds the given image to the collection, transfers ownership to this object
void addImage(Image *image);
/// enumerates the list of existing images
Image *Enum(unsigned index)
{
for (ImageMap::iterator i=m_imageMap.begin();i!=m_imageMap.end();++i)
if (!index--)
return i->second;
return nullptr;
}
protected:
ImageMap m_imageMap; ///< maps named keys to images
};
// INLINING ///////////////////////////////////////////////////////////////////////////////////////
inline void Image::setName( AsciiString name ) { m_name = name; }
inline AsciiString Image::getName() const { return m_name; }
inline void Image::setFilename( AsciiString name ) { m_filename = name; }
inline AsciiString Image::getFilename() const { return m_filename; }
inline void Image::setUV( Region2D *uv ) { if( uv ) m_UVCoords = *uv; }
inline const Region2D *Image::getUV() const { return &m_UVCoords; }
inline void Image::setTextureWidth( Int width ) { m_textureSize.x = width; }
inline void Image::setTextureHeight( Int height ) { m_textureSize.y = height; }
inline void Image::setImageSize( ICoord2D *size ) { m_imageSize = *size; }
inline const ICoord2D *Image::getImageSize() const { return &m_imageSize; }
inline const ICoord2D *Image::getTextureSize() const { return &m_textureSize; }
inline Int Image::getImageWidth() const { return m_imageSize.x; }
inline Int Image::getImageHeight() const { return m_imageSize.y; }
inline void Image::setRawTextureData( void *data ) { m_rawTextureData = data; }
inline const void *Image::getRawTextureData() const { return m_rawTextureData; }
inline UnsignedInt Image::getStatus() const { return m_status; }
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern ImageCollection *TheMappedImageCollection; ///< mapped images