Permalink
Browse files

Video: Migrate generic methods to base

there is no point in overriding these methods
  • Loading branch information...
1 parent f35159f commit 4abe68535629848970ed6026093e96a4fe1b8384 @bradallred bradallred committed Jun 21, 2013
Showing with 108 additions and 119 deletions.
  1. +101 −0 gemrb/core/Video.cpp
  2. +7 −9 gemrb/core/Video.h
  3. +0 −108 gemrb/plugins/SDLVideo/SDLVideo.cpp
  4. +0 −2 gemrb/plugins/SDLVideo/SDLVideo.h
View
101 gemrb/core/Video.cpp
@@ -273,4 +273,105 @@ void Video::MoveViewportTo(int x, int y)
}
}
+void Video::FreeSprite(Sprite2D*& spr)
+{
+ if (spr) {
+ spr->release();
+ spr = NULL;
+ }
+}
+
+void Video::InitSpriteCover(SpriteCover* sc, int flags)
+{
+ int i;
+ sc->flags = flags;
+ sc->pixels = new unsigned char[sc->Width * sc->Height];
+ for (i = 0; i < sc->Width*sc->Height; ++i)
+ sc->pixels[i] = 0;
+
+}
+
+// flags: 0 - never dither (full cover)
+// 1 - dither if polygon wants it
+// 2 - always dither
+void Video::AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly)
+{
+
+ // possible TODO: change the cover to use a set of intervals per line?
+ // advantages: faster
+ // disadvantages: makes the blitter much more complex
+
+ int xoff = sc->worldx - sc->XPos;
+ int yoff = sc->worldy - sc->YPos;
+
+ std::list<Trapezoid>::iterator iter;
+ for (iter = poly->trapezoids.begin(); iter != poly->trapezoids.end();
+ ++iter)
+ {
+ int y_top = iter->y1 - yoff; // inclusive
+ int y_bot = iter->y2 - yoff; // exclusive
+
+ if (y_top < 0) y_top = 0;
+ if ( y_bot > sc->Height) y_bot = sc->Height;
+ if (y_top >= y_bot) continue; // clipped
+
+ int ledge = iter->left_edge;
+ int redge = iter->right_edge;
+ Point& a = poly->points[ledge];
+ Point& b = poly->points[(ledge+1)%(poly->count)];
+ Point& c = poly->points[redge];
+ Point& d = poly->points[(redge+1)%(poly->count)];
+
+ unsigned char* line = sc->pixels + (y_top)*sc->Width;
+ for (int sy = y_top; sy < y_bot; ++sy) {
+ int py = sy + yoff;
+
+ // TODO: maybe use a 'real' line drawing algorithm to
+ // compute these values faster.
+
+ int lt = (b.x * (py - a.y) + a.x * (b.y - py))/(b.y - a.y);
+ int rt = (d.x * (py - c.y) + c.x * (d.y - py))/(d.y - c.y) + 1;
+
+ lt -= xoff;
+ rt -= xoff;
+
+ if (lt < 0) lt = 0;
+ if (rt > sc->Width) rt = sc->Width;
+ if (lt >= rt) { line += sc->Width; continue; } // clipped
+ int dither;
+
+ if (sc->flags == 1) {
+ dither = poly->wall_flag & WF_DITHER;
+ } else {
+ dither = sc->flags;
+ }
+ if (dither) {
+ unsigned char* pix = line + lt;
+ unsigned char* end = line + rt;
+
+ if ((lt + xoff + sy + yoff) % 2) pix++; // CHECKME: aliasing?
+ for (; pix < end; pix += 2)
+ *pix = 1;
+ } else {
+ // we hope memset is faster
+ // condition: lt < rt is true
+ memset (line+lt, 1, rt-lt);
+ }
+ line += sc->Width;
+ }
+ }
+}
+
+void Video::DestroySpriteCover(SpriteCover* sc)
+{
+ delete[] sc->pixels;
+ sc->pixels = NULL;
+}
+
+void Video::GetMousePos(int &x, int &y)
+{
+ x = CursorPos.x;
+ y = CursorPos.y;
+}
+
}
View
16 gemrb/core/Video.h
@@ -30,17 +30,15 @@
#include "globals.h"
#include "Plugin.h"
+#include "Polygon.h"
#include "ScriptedAnimation.h"
namespace GemRB {
-class AnimationFactory;
class EventMgr;
class Font;
-class Gem_Polygon;
class Palette;
class SpriteCover;
-class Wall_Polygon;
// Note: not all these flags make sense together. Specifically:
// NOSHADOW overrides TRANSSHADOW, and BLIT_GREY overrides BLIT_SEPIA
@@ -126,10 +124,10 @@ class GEM_EXPORT Video : public Plugin {
/** Displays or hides a virtual (software) keyboard*/
virtual void ShowSoftKeyboard() = 0;
virtual void HideSoftKeyboard() = 0;
-
- virtual void InitSpriteCover(SpriteCover* sc, int flags) = 0;
- virtual void AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly) = 0;
- virtual void DestroySpriteCover(SpriteCover* sc) = 0;
+
+ void InitSpriteCover(SpriteCover* sc, int flags);
+ void AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly);
+ void DestroySpriteCover(SpriteCover* sc);
virtual Sprite2D* CreateSprite(int w, int h, int bpp, ieDword rMask,
ieDword gMask, ieDword bMask, ieDword aMask, void* pixels,
@@ -139,7 +137,7 @@ class GEM_EXPORT Video : public Plugin {
virtual Sprite2D* CreatePalettedSprite(int w, int h, int bpp, void* pixels,
Color* palette, bool cK = false, int index = 0) = 0;
virtual bool SupportsBAMSprites() { return false; }
- virtual void FreeSprite(Sprite2D* &spr) = 0;
+ void FreeSprite(Sprite2D* &spr);
virtual void BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x, int y, const Region* clip, unsigned int flags) = 0;
virtual void BlitSprite(const Sprite2D* spr, int x, int y, bool anchor = false,
const Region* clip = NULL, Palette* palette = NULL) = 0;
@@ -198,7 +196,7 @@ class GEM_EXPORT Video : public Plugin {
/** Gets Clip Rectangle */
virtual void GetClipRect(Region& clip) = 0;
/** returns the current mouse coordinates */
- virtual void GetMousePos(int &x, int &y) = 0;
+ void GetMousePos(int &x, int &y);
/** clicks the mouse forcibly */
virtual void ClickMouse(unsigned int button) = 0;
/** moves the mouse forcibly */
View
108 gemrb/plugins/SDLVideo/SDLVideo.cpp
@@ -19,7 +19,6 @@
*/
#include "SDLVideo.h"
-
#include "SDLSurfaceSprite2D.h"
#include "TileRenderer.inl"
@@ -30,16 +29,12 @@
#include "GameData.h"
#include "Interface.h"
#include "Palette.h"
-#include "Polygon.h"
-#include "SpriteCover.h"
#include "GUI/Button.h"
#include "GUI/Console.h"
#include "GUI/Window.h"
#include <cmath>
-#include <cassert>
-#include <cstdio>
using namespace GemRB;
@@ -305,94 +300,6 @@ int SDLVideoDriver::ProcessEvent(const SDL_Event & event)
return GEM_OK;
}
-void SDLVideoDriver::InitSpriteCover(SpriteCover* sc, int flags)
-{
- int i;
- sc->flags = flags;
- sc->pixels = new unsigned char[sc->Width * sc->Height];
- for (i = 0; i < sc->Width*sc->Height; ++i)
- sc->pixels[i] = 0;
-
-}
-
-void SDLVideoDriver::DestroySpriteCover(SpriteCover* sc)
-{
- delete[] sc->pixels;
- sc->pixels = NULL;
-}
-
-
-// flags: 0 - never dither (full cover)
-// 1 - dither if polygon wants it
-// 2 - always dither
-void SDLVideoDriver::AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly)
-{
-
- // possible TODO: change the cover to use a set of intervals per line?
- // advantages: faster
- // disadvantages: makes the blitter much more complex
-
- int xoff = sc->worldx - sc->XPos;
- int yoff = sc->worldy - sc->YPos;
-
- std::list<Trapezoid>::iterator iter;
- for (iter = poly->trapezoids.begin(); iter != poly->trapezoids.end();
- ++iter)
- {
- int y_top = iter->y1 - yoff; // inclusive
- int y_bot = iter->y2 - yoff; // exclusive
-
- if (y_top < 0) y_top = 0;
- if ( y_bot > sc->Height) y_bot = sc->Height;
- if (y_top >= y_bot) continue; // clipped
-
- int ledge = iter->left_edge;
- int redge = iter->right_edge;
- Point& a = poly->points[ledge];
- Point& b = poly->points[(ledge+1)%(poly->count)];
- Point& c = poly->points[redge];
- Point& d = poly->points[(redge+1)%(poly->count)];
-
- unsigned char* line = sc->pixels + (y_top)*sc->Width;
- for (int sy = y_top; sy < y_bot; ++sy) {
- int py = sy + yoff;
-
- // TODO: maybe use a 'real' line drawing algorithm to
- // compute these values faster.
-
- int lt = (b.x * (py - a.y) + a.x * (b.y - py))/(b.y - a.y);
- int rt = (d.x * (py - c.y) + c.x * (d.y - py))/(d.y - c.y) + 1;
-
- lt -= xoff;
- rt -= xoff;
-
- if (lt < 0) lt = 0;
- if (rt > sc->Width) rt = sc->Width;
- if (lt >= rt) { line += sc->Width; continue; } // clipped
- int dither;
-
- if (sc->flags == 1) {
- dither = poly->wall_flag & WF_DITHER;
- } else {
- dither = sc->flags;
- }
- if (dither) {
- unsigned char* pix = line + lt;
- unsigned char* end = line + rt;
-
- if ((lt + xoff + sy + yoff) % 2) pix++; // CHECKME: aliasing?
- for (; pix < end; pix += 2)
- *pix = 1;
- } else {
- // we hope memset is faster
- // condition: lt < rt is true
- memset (line+lt, 1, rt-lt);
- }
- line += sc->Width;
- }
- }
-}
-
Sprite2D* SDLVideoDriver::CreateSprite(int w, int h, int bpp, ieDword rMask,
ieDword gMask, ieDword bMask, ieDword aMask, void* pixels, bool cK, int index)
{
@@ -421,14 +328,6 @@ Sprite2D* SDLVideoDriver::CreatePalettedSprite(int w, int h, int bpp, void* pixe
return spr;
}
-void SDLVideoDriver::FreeSprite(Sprite2D*& spr)
-{
- if (spr) {
- spr->release();
- spr = NULL;
- }
-}
-
void SDLVideoDriver::BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x, int y, const Region* clip, unsigned int flags)
{
if (spr->BAM) {
@@ -1615,13 +1514,6 @@ void SDLVideoDriver::GetClipRect(Region& clip)
clip.h = tmp.h;
}
-
-void SDLVideoDriver::GetMousePos(int &x, int &y)
-{
- x=CursorPos.x;
- y=CursorPos.y;
-}
-
void SDLVideoDriver::MouseMovement(int x, int y)
{
lastMouseMoveTime = GetTickCount();
View
2 gemrb/plugins/SDLVideo/SDLVideo.h
@@ -80,7 +80,6 @@ class SDLVideoDriver : public Video {
void AddPolygonToSpriteCover(SpriteCover* sc, Wall_Polygon* poly);
void DestroySpriteCover(SpriteCover* sc);
- void GetMousePos(int &x, int &y);
void MouseMovement(int x, int y);
void ClickMouse(unsigned int button);
void MouseClickEvent(SDL_EventType type, Uint8 button);
@@ -92,7 +91,6 @@ class SDLVideoDriver : public Video {
Sprite2D* CreatePalettedSprite(int w, int h, int bpp, void* pixels,
Color* palette, bool cK = false, int index = 0);
bool SupportsBAMSprites() { return true; }
- void FreeSprite(Sprite2D* &spr);
void BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x, int y, const Region* clip, unsigned int flags);
void BlitSprite(const Sprite2D* spr, int x, int y, bool anchor = false,
const Region* clip = NULL, Palette* palette = NULL);

0 comments on commit 4abe685

Please sign in to comment.