src/blitter/32bpp_anim.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6870 ca3fd1fbe311
child 10724 68a692eacf22
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
       
     1 /* $Id$ */
       
     2 
     1 #include "../stdafx.h"
     3 #include "../stdafx.h"
     2 #include "../zoom.hpp"
     4 #include "../core/alloc_func.hpp"
     3 #include "../gfx.h"
     5 #include "../gfx_func.h"
       
     6 #include "../zoom_func.h"
     4 #include "../debug.h"
     7 #include "../debug.h"
     5 #include "../table/sprites.h"
       
     6 #include "../video/video_driver.hpp"
     8 #include "../video/video_driver.hpp"
     7 #include "32bpp_anim.hpp"
     9 #include "32bpp_anim.hpp"
     8 
    10 
       
    11 #include "../table/sprites.h"
       
    12 
     9 static FBlitter_32bppAnim iFBlitter_32bppAnim;
    13 static FBlitter_32bppAnim iFBlitter_32bppAnim;
    10 
    14 
    11 void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    15 void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    12 {
    16 {
    13 	if (bp->dst < _screen.dst_ptr || bp->dst > (uint32 *)_screen.dst_ptr + _screen.width * _screen.height) {
    17 	if (_screen_disable_anim) {
    14 		/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent Draw() */
    18 		/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent Draw() */
    15 		Blitter_32bppOptimized::Draw(bp, mode, zoom);
    19 		Blitter_32bppOptimized::Draw(bp, mode, zoom);
    16 		return;
    20 		return;
    17 	}
    21 	}
    18 
    22 
    93 	}
    97 	}
    94 }
    98 }
    95 
    99 
    96 void Blitter_32bppAnim::DrawColorMappingRect(void *dst, int width, int height, int pal)
   100 void Blitter_32bppAnim::DrawColorMappingRect(void *dst, int width, int height, int pal)
    97 {
   101 {
       
   102 	if (_screen_disable_anim) {
       
   103 		/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawColorMappingRect() */
       
   104 		Blitter_32bppOptimized::DrawColorMappingRect(dst, width, height, pal);
       
   105 		return;
       
   106 	}
       
   107 
    98 	uint32 *udst = (uint32 *)dst;
   108 	uint32 *udst = (uint32 *)dst;
    99 	uint8 *anim;
   109 	uint8 *anim;
   100 
   110 
   101 	anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr);
   111 	anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr);
   102 
   112 
   131 }
   141 }
   132 
   142 
   133 void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 color)
   143 void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 color)
   134 {
   144 {
   135 	*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
   145 	*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
   136 	/* Set the color in the anim-buffer too */
   146 
       
   147 	/* Set the color in the anim-buffer too, if we are rendering to the screen */
       
   148 	if (_screen_disable_anim) return;
   137 	this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = color;
   149 	this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = color;
   138 }
   150 }
   139 
   151 
   140 void Blitter_32bppAnim::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
   152 void Blitter_32bppAnim::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
   141 {
   153 {
   142 	uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
   154 	uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
   143 	if (*dst == 0) {
   155 	if (*dst == 0) {
   144 		*dst = LookupColourInPalette(color);
   156 		*dst = LookupColourInPalette(color);
   145 		/* Set the color in the anim-buffer too */
   157 		/* Set the color in the anim-buffer too, if we are rendering to the screen */
       
   158 		if (_screen_disable_anim) return;
   146 		this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = color;
   159 		this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = color;
   147 	}
   160 	}
   148 }
   161 }
   149 
   162 
   150 void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 color)
   163 void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 color)
   151 {
   164 {
       
   165 	if (_screen_disable_anim) {
       
   166 		/* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent DrawRect() */
       
   167 		Blitter_32bppOptimized::DrawRect(video, width, height, color);
       
   168 		return;
       
   169 	}
       
   170 
   152 	uint32 color32 = LookupColourInPalette(color);
   171 	uint32 color32 = LookupColourInPalette(color);
   153 	uint8 *anim_line;
   172 	uint8 *anim_line;
   154 
   173 
   155 	anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf;
   174 	anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf;
   156 
   175 
   170 	} while (--height);
   189 	} while (--height);
   171 }
   190 }
   172 
   191 
   173 void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, int height)
   192 void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, int height)
   174 {
   193 {
       
   194 	assert(!_screen_disable_anim);
   175 	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
   195 	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
   176 	uint32 *dst = (uint32 *)video;
   196 	uint32 *dst = (uint32 *)video;
   177 	uint32 *usrc = (uint32 *)src;
   197 	uint32 *usrc = (uint32 *)src;
   178 	uint8 *anim_line;
   198 	uint8 *anim_line;
   179 
   199 
   193 	this->PaletteAnimate(217, _use_dos_palette ? 38 : 28);
   213 	this->PaletteAnimate(217, _use_dos_palette ? 38 : 28);
   194 }
   214 }
   195 
   215 
   196 void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, int height)
   216 void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, int height)
   197 {
   217 {
       
   218 	assert(!_screen_disable_anim);
   198 	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
   219 	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
   199 	uint32 *udst = (uint32 *)dst;
   220 	uint32 *udst = (uint32 *)dst;
   200 	uint32 *src = (uint32 *)video;
   221 	uint32 *src = (uint32 *)video;
   201 	uint8 *anim_line;
   222 	uint8 *anim_line;
   202 
   223 
   215 	}
   236 	}
   216 }
   237 }
   217 
   238 
   218 void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
   239 void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
   219 {
   240 {
       
   241 	assert(!_screen_disable_anim);
       
   242 	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
   220 	uint8 *dst, *src;
   243 	uint8 *dst, *src;
   221 
   244 
   222 	/* We need to scroll the anim-buffer too */
   245 	/* We need to scroll the anim-buffer too */
   223 	if (scroll_y > 0) {
   246 	if (scroll_y > 0) {
   224 		dst = this->anim_buf + left + (top + height - 1) * this->anim_buf_width;
   247 		dst = this->anim_buf + left + (top + height - 1) * this->anim_buf_width;
   263 	return width * height * (sizeof(uint32) + sizeof(uint8));
   286 	return width * height * (sizeof(uint32) + sizeof(uint8));
   264 }
   287 }
   265 
   288 
   266 void Blitter_32bppAnim::PaletteAnimate(uint start, uint count)
   289 void Blitter_32bppAnim::PaletteAnimate(uint start, uint count)
   267 {
   290 {
       
   291 	assert(!_screen_disable_anim);
   268 	uint8 *anim = this->anim_buf;
   292 	uint8 *anim = this->anim_buf;
   269 
   293 
   270 	/* Never repaint the transparency pixel */
   294 	/* Never repaint the transparency pixel */
   271 	if (start == 0) start++;
   295 	if (start == 0) start++;
   272 
   296