Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
draw.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /Commando/Library/Draw.cpp $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/22/97 11:37a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * Blit_Block -- Blit a block of data to the surface. *
36 * Draw_Shape -- Draw a shape to the surface. *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#include "always.h"
40#include "blit.h"
41#include "blitblit.h"
42#include "blitter.h"
43#include "bsurface.h"
44#include "draw.h"
45#include "dsurface.h"
46#include "hsv.h"
47#include "rlerle.h"
48#include "shapeset.h"
49
50
51/***********************************************************************************************
52 * Draw_Shape -- Draw a shape to the surface. *
53 * *
54 * This is the largely general purpose shape drawing routine for the game. All non-voxel *
55 * shape drawing will pass through this routine. *
56 * *
57 * INPUT: surface -- The destination surface for the draw. *
58 * *
59 * convert -- The converter to use for the pixel transformation. *
60 * *
61 * shapefile -- Pointer to the shapefile data block. *
62 * *
63 * shapenum -- The shape number within the shape file data block specified. *
64 * *
65 * point -- The draw point for this shape on the destination surface. This point *
66 * is relative to the clipping window. *
67 * *
68 * window -- The clipping window to use for this draw. *
69 * *
70 * flags -- Shape draw control flags. These flags are used to extract the *
71 * proper blitter from the converter object. *
72 * *
73 * remap -- Auxiliary remap table used for the draw process. House ownership can *
74 * be controlled with this parameter. *
75 * *
76 * OUTPUT: none *
77 * *
78 * WARNINGS: none *
79 * *
80 * HISTORY: *
81 * 05/27/1997 JLB : Created. *
82 *=============================================================================================*/
83void Draw_Shape(Surface & surface, ConvertClass & convert, ShapeSet const * shapefile, int shapenum, Point2D const & point, Rect const & window, ShapeFlags_Type flags, unsigned char const * remap)
84{
85 assert((flags & SHAPE_PREDATOR) == 0); // Not yet supported.
86 assert(shapefile != NULL);
87 assert(shapenum != -1);
88
89 convert.Set_Remap(remap);
90 int x = point.X;
91 int y = point.Y;
92 Rect rect = shapefile->Get_Rect(shapenum);
93 void const * buffer = shapefile->Get_Data(shapenum);
94 int width = shapefile->Get_Width();
95 int height = shapefile->Get_Height();
96 BSurface const shape(rect.Width, rect.Height, 1, (void *)buffer);
97
98 /*
99 ** Centered shapes must have their start position adjusted
100 ** according to their width and height.
101 */
102 if (flags & SHAPE_CENTER) {
103 x -= width/2;
104 y -= height/2;
105 }
106
107 /*
108 ** Factor the offset of the shape data (logical) into the draw
109 ** position. Since the actual embedded shape pixels have no
110 ** (transparent) offset, remove the offset coefficient.
111 */
112 x += rect.X;
113 y += rect.Y;
114 rect.X = 0;
115 rect.Y = 0;
116
117 /*
118 ** If the remap table supplied is not NULL, then set the remap flag so that
119 ** the appropriate blitter will be selected.
120 */
121 if (remap != NULL) {
122 flags = ShapeFlags_Type(flags | SHAPE_REMAP);
123 }
124
125 /*
126 ** Blit the pixels according to the flags specified and whether this is
127 ** an RLE compressed shape. RLE compression uses different blitter routines
128 ** than the normal method.
129 */
130 if (shapefile->Is_RLE_Compressed(shapenum)) {
131 RLEBlitter const * blitter = convert.RLEBlitter_From_Flags(flags);
132 if (blitter != NULL) {
133 RLE_Blit(surface, window, Rect(x, y, rect.Width, rect.Height), shape, rect, rect, *blitter);
134
135 }
136 } else {
137 Blitter const * blitter = convert.Blitter_From_Flags(flags);
138 if (blitter != NULL) {
139 Bit_Blit(surface, window, Rect(x, y, rect.Width, rect.Height), shape, shape.Get_Rect(), rect, *blitter);
140 }
141 }
142}
143
144
145/***********************************************************************************************
146 * Blit_Block -- Blit a block of data to the surface. *
147 * *
148 * This function serves as a wrapper to the normal Bit_Blit function. It is used to control *
149 * the blitter according to remap parameter specified. *
150 * *
151 * INPUT: surface -- The destination surface of this blit. *
152 * *
153 * convert -- The convert class for pixel transformation. *
154 * *
155 * source -- The source surface to blit from. *
156 * *
157 * sourcerect -- The source rectangle within the source surface to blit from. *
158 * *
159 * point -- The draw point of this blit (upper left corner). *
160 * *
161 * window -- The clipping window for this blit. The destination rectangle is *
162 * relative to this clipping window. *
163 * *
164 * remap -- The remapping table pointer (optional) to be used for ownership *
165 * remapping control. *
166 * *
167 * blitter -- Preexisting blitter to use. If this parameter is NULL, then a blitter *
168 * object is created from the convert object supplied. *
169 * *
170 * OUTPUT: none *
171 * *
172 * WARNINGS: none *
173 * *
174 * HISTORY: *
175 * 05/27/1997 JLB : Created. *
176 *=============================================================================================*/
177void Blit_Block(Surface & surface, ConvertClass & convert, Surface const & source, Rect const & sourcerect, Point2D const & point, Rect const & window, unsigned char const * remap, Blitter const * blitter)
178{
179 convert.Set_Remap(remap);
180
181 if (blitter == NULL) {
182 blitter = convert.Blitter_From_Flags((remap != NULL) ? SHAPE_REMAP : SHAPE_NORMAL);
183 }
184
185 /*
186 ** Submit the image to the destination surface.
187 */
188 Bit_Blit(surface, window, Rect(point.X, point.Y, sourcerect.Width, sourcerect.Height), source, source.Get_Rect(), sourcerect, *blitter);
189}
190
#define NULL
Definition BaseType.h:92
ShapeFlags_Type
Definition Convert.h:50
@ SHAPE_CENTER
Definition Convert.h:55
@ SHAPE_NORMAL
Definition Convert.h:51
@ SHAPE_PREDATOR
Definition Convert.h:61
@ SHAPE_REMAP
Definition Convert.h:62
bool Bit_Blit(Surface &dest, Rect const &destrect, Surface const &source, Rect const &sourcerect, Blitter const &blitter)
Definition blit.cpp:167
bool RLE_Blit(Surface &dest, Rect const &destrect, Surface const &source, Rect const &sourcerect, RLEBlitter const &blitter)
Definition blit.cpp:303
void Set_Remap(unsigned char const *remap)
Definition Convert.h:122
RLEBlitter const * RLEBlitter_From_Flags(ShapeFlags_Type flags) const
Definition convert.cpp:234
Blitter const * Blitter_From_Flags(ShapeFlags_Type flags) const
Definition convert.cpp:207
int Get_Width(void) const
Definition shapeset.h:78
Rect Get_Rect(int shape) const
Definition shapeset.h:224
int Get_Height(void) const
Definition shapeset.h:83
bool Is_RLE_Compressed(int shape) const
Definition shapeset.h:260
void * Get_Data(int shape) const
Definition shapeset.h:200
virtual Rect Get_Rect(void) const
Definition Surface.h:102
T Width
Definition trect.h:115
T Y
Definition trect.h:109
T Height
Definition trect.h:116
T X
Definition trect.h:108
void Draw_Shape(Surface &surface, ConvertClass &convert, ShapeSet const *shapefile, int shapenum, Point2D const &point, Rect const &window, ShapeFlags_Type flags, unsigned char const *remap)
Definition draw.cpp:83
void Blit_Block(Surface &surface, ConvertClass &convert, Surface const &source, Rect const &sourcerect, Point2D const &point, Rect const &window, unsigned char const *remap, Blitter const *blitter)
Definition draw.cpp:177
TRect< int > Rect
Definition trect.h:221