2
* Copyright (C) 2002-2004 by the Wide Lands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#ifndef included_sw16_graphic_h
21
#define included_sw16_graphic_h
29
#include "rendertarget.h"
35
namespace Renderer_Software16
38
SDL_Surface* LoadImage(std::string filename);
43
The graphics belonging to an animation
58
AnimationGfx(const AnimationData* data);
61
inline int get_nrframes() const { return m_nrframes; }
62
inline const AnimFrame* get_frame(int i) const
63
{ assert(i>=0 && i<m_nrframes); return &m_frames[i]; }
66
void encode(AnimFrame* frame, SDL_Surface* bmp, const EncodeData* encdata);
73
Represents a simple bitmap without managing its memory.
74
The rendering functions do NOT perform any clipping; this is up to the caller.
84
void draw_rect(Rect rc, RGBColor clr);
85
void fill_rect(Rect rc, RGBColor clr);
86
void brighten_rect(Rect rc, int factor);
88
void blit(Point dst, Bitmap* src, Rect srcrc);
90
void draw_minimap(Editor_Game_Base* egbase, const std::vector<bool>* visibility, Rect rc, Coords viewpt, uint flags);
91
void draw_animframe(Point dst, const AnimFrame* frame, Rect rc, const RGBColor* plrclrs);
94
void draw_field(Field * const f, Field * const rf, Field * const fl, Field * const rfl,
95
Field * const lf, Field * const ft,
96
const int posx, const int rposx, const int posy,
97
const int blposx, const int rblposx, const int blposy,
98
uchar roads, bool render_r, bool render_b);
104
* Colormap contains a palette and lookup table for use with ground textures.
107
// friend class Texture;
110
SDL_Color palette[256];
112
unsigned short *colormap; // maps 8 bit color and brightness value to the shaded 16 bit color
113
// NOTE: brightness is currently 8 bits. Restricting brightness
114
// to 64 or less shades would greatly reduce the size of this
115
// table, and thus improve memory cache impact inside the renderer.
118
Colormap (const SDL_Color *);
121
SDL_Color* get_palette() { return palette; }
123
unsigned short *get_colormap () const { return colormap; }
129
* Texture represents are terrain texture, which is strictly
130
* TEXTURE_W by TEXTURE_H pixels in size. It uses 8 bit color, and a pointer
131
* to the corresponding palette and color lookup table is provided.
133
* Currently, this is initialized from a 16 bit bitmap. This should be
134
* changed to load 8 bit bitmaps directly.
138
Colormap* m_colormap;
140
unsigned char* m_pixels;
142
unsigned char* m_curframe;
143
std::string m_texture_picture;
146
Texture (const char* fnametempl, uint frametime);
149
inline const char* get_texture_picture(void) { return m_texture_picture.c_str(); }
151
unsigned char *get_pixels () const { return m_pixels; }
152
unsigned char* get_curpixels() const { return m_curframe; }
153
unsigned short *get_colormap () const { return m_colormap->get_colormap(); }
155
unsigned short get_minimap_color(char shade);
157
void animate(uint time);
161
* This contains all the road textures needed to render roads
163
struct Road_Textures {
164
uint pic_road_normal;
169
class RenderTargetImpl
171
The 16-bit software renderer implementation of the RenderTarget interface
173
class RenderTargetImpl : public RenderTarget {
174
Bitmap* m_bitmap; // the target surface
175
Rect m_rect; // the current clip rectangle
176
Point m_offset; // drawing offset
179
RenderTargetImpl(Bitmap* bmp);
180
virtual ~RenderTargetImpl();
184
virtual void get_window(Rect* rc, Point* ofs) const;
185
virtual void set_window(const Rect& rc, const Point& ofs);
186
virtual bool enter_window(const Rect& rc, Rect* previous, Point* prevofs);
188
virtual int get_w() const;
189
virtual int get_h() const;
191
virtual void draw_line(int x1, int y1, int x2, int y2, RGBColor color);
192
virtual void draw_rect(int x, int y, int w, int h, RGBColor clr);
193
virtual void fill_rect(int x, int y, int w, int h, RGBColor clr);
194
virtual void brighten_rect(int x, int y, int w, int h, int factor);
195
virtual void clear();
197
void doblit(Point dst, Bitmap* src, Rect srcrc);
199
virtual void blit(int dstx, int dsty, uint picture);
200
virtual void blitrect(int dstx, int dsty, uint picture,
201
int srcx, int srcy, int w, int h);
202
virtual void tile(int x, int y, int w, int h, uint picture, int ofsx, int ofsy);
204
virtual void rendermap(Editor_Game_Base* egbase, const std::vector<bool>* visibility, Point viewofs);
205
virtual void renderminimap(Editor_Game_Base* egbase, const std::vector<bool>* visibility, Coords viewpt, uint flags);
207
virtual void drawanim(int dstx, int dsty, uint animation, uint time, const RGBColor* plrclrs = 0);
208
virtual void drawanimrect(int dstx, int dsty, uint animation, uint time,
209
const RGBColor* plrclrs, int srcx, int srcy, int w, int h);
216
The 16-bit software renderer implementation of the Graphic interface.
220
class GraphicImpl : public Graphic {
222
GraphicImpl(int w, int h, bool fullscreen);
223
virtual ~GraphicImpl();
225
// General management
226
virtual int get_xres();
227
virtual int get_yres();
228
virtual RenderTarget* get_render_target();
229
virtual void update_fullscreen();
230
virtual void update_rectangle(int x, int y, int w, int h);
231
virtual bool need_update();
232
virtual void refresh();
234
virtual void flush(int mod);
237
virtual uint get_picture(int mod, const char* fname, bool);
238
virtual void use_clrkey(uint pic, bool);
239
virtual bool has_clrkey(uint);
240
virtual void flush_picture(uint pic);
241
virtual void get_picture_size(uint pic, int* pw, int* ph);
242
virtual uint create_surface(int w, int h);
243
virtual uint create_surface(int w, int h, RGBColor clrkey);
244
virtual void free_surface(uint pic);
245
virtual RenderTarget* get_surface_renderer(uint pic);
246
virtual void save_pic_to_file(uint, FileWrite*);
247
virtual uint load_pic_from_file(FileRead*, int);
249
Bitmap* get_picture_bitmap(uint id);
252
virtual uint get_maptexture(const char* fnametempl, uint frametime);
253
virtual void animate_maptextures(uint time);
254
Texture* get_maptexture_data(uint id);
257
Bitmap* get_road_texture( int );
260
virtual void load_animations();
261
AnimationGfx* get_animation(uint anim);
262
virtual int get_animation_nr_frames(uint anim);
263
virtual void get_animation_size(uint anim, uint time, int* w, int* h);
266
virtual void screenshot(const char* fname);
268
virtual uint get_picture(int mod, int w, int h, const ushort* data, RGBColor clrkey);
269
virtual const char* get_maptexture_picture(uint id);
272
uint find_free_picture();
275
int mod; // 0 if unused, -1 for surfaces, PicMod_* bitmask for pictures
280
RenderTargetImpl* rendertarget;
283
Picture() { mod = 0; u.fname = 0; bitmap.pixels = 0; }
285
typedef std::map<std::string, uint> picmap_t;
287
SDL_Surface* m_sdlsurface;
288
int m_screen_pixels_size_in_bytes;
289
bool m_lock_sdl_surface;
291
RenderTargetImpl* m_rendertarget;
292
SDL_Rect m_update_rects[MAX_RECTS];
293
int m_nr_update_rects;
294
bool m_update_fullscreen;
296
std::vector<Picture> m_pictures;
297
picmap_t m_picturemap; // hash of filename/picture ID pairs
299
Road_Textures* m_roadtextures;
300
std::vector<Texture*> m_maptextures;
301
std::vector<AnimationGfx*> m_animations;
304
#define get_graphicimpl() (static_cast<Renderer_Software16::GraphicImpl*>(g_gr))
309
#endif // included_sw16_graphic_h