MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GFX_DrawTile

Function GFX_DrawTile

src/gfx.c:210–270  ·  view source on GitHub ↗

* Draw a tile on the screen. * @param tileID The tile to draw. * @param x The x-coordinate to draw the sprite. * @param y The y-coordinate to draw the sprite. * @param houseID The house the sprite belongs (for recolouring). */

Source from the content-addressed store, hash-verified

208 * @param houseID The house the sprite belongs (for recolouring).
209 */
210void GFX_DrawTile(uint16 tileID, uint16 x, uint16 y, uint8 houseID)
211{
212 int i, j;
213 uint8 *icon_palette;
214 uint8 *wptr;
215 uint8 *rptr;
216 uint8 local_palette[16];
217
218 assert(houseID < HOUSE_MAX);
219
220 if (s_tileMode == 4) return;
221
222 icon_palette = g_iconRPAL + (g_iconRTBL[tileID] << 4);
223
224 if (houseID != 0) {
225 /* Remap colors for the right house */
226 for (i = 0; i < 16; i++) {
227 uint8 colour = icon_palette[i];
228
229 /* ENHANCEMENT -- Dune2 recolours too many colours, causing clear graphical glitches in the IX building */
230 if ((colour & 0xF0) == 0x90) {
231 if (colour <= 0x96 || !g_dune2_enhanced) colour += houseID << 4;
232 }
233 local_palette[i] = colour;
234 }
235 icon_palette = local_palette;
236 }
237
238 wptr = GFX_Screen_GetActive();
239 wptr += y * SCREEN_WIDTH + x;
240 rptr = g_tilesPixels + (tileID * s_tileByteSize);
241
242 /* tiles with transparent pixels : [1 : 33] U [108 : 122] and 124
243 * palettes 1 to 18 and 22 and 24 */
244 /*if (tileID <= 33 || (tileID >= 108 && tileID <= 124)) {*/
245 /* We've found that all "transparent" icons/tiles have 0 (transparent) as color 0 */
246 if (icon_palette[0] == 0) {
247 for (j = 0; j < s_tileHeight; j++) {
248 for (i = 0; i < s_tileWidth; i++) {
249 uint8 left = icon_palette[(*rptr) >> 4];
250 uint8 right = icon_palette[(*rptr) & 0xF];
251 rptr++;
252
253 if (left != 0) *wptr = left;
254 wptr++;
255 if (right != 0) *wptr = right;
256 wptr++;
257 }
258 wptr += s_tileSpacing;
259 }
260 } else {
261 for (j = 0; j < s_tileHeight; j++) {
262 for (i = 0; i < s_tileWidth; i++) {
263 *wptr++ = icon_palette[(*rptr) >> 4];
264 *wptr++ = icon_palette[(*rptr) & 0xF];
265 rptr++;
266 }
267 wptr += s_tileSpacing;

Callers 2

GUI_Widget_DrawFunction · 0.85
GUI_Widget_Viewport_DrawFunction · 0.85

Calls 1

GFX_Screen_GetActiveFunction · 0.85

Tested by

no test coverage detected