Turned DrawingEffect into a proper bitset, used to be a mix of enum/bitset before...
authorIngo Ruhnke <grumbel@gmail.com>
Mon, 11 Aug 2014 22:46:45 +0000 (00:46 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Mon, 11 Aug 2014 22:48:41 +0000 (00:48 +0200)
src/badguy/badguy.cpp
src/supertux/flip_level_transformer.cpp
src/supertux/sector.cpp
src/video/sdl/sdl_painter.cpp
src/video/texture.hpp

index 8f08ea7..1901ccf 100644 (file)
@@ -127,7 +127,7 @@ BadGuy::draw(DrawingContext& context)
     return;
   if(state == STATE_FALLING) {
     DrawingEffect old_effect = context.get_drawing_effect();
-    context.set_drawing_effect((DrawingEffect) (old_effect | VERTICAL_FLIP));
+    context.set_drawing_effect(old_effect | VERTICAL_FLIP);
     sprite->draw(context, get_pos(), layer);
     context.set_drawing_effect(old_effect);
   } else {
index 4bed1f9..53f285a 100644 (file)
@@ -78,10 +78,10 @@ FlipLevelTransformer::transform_sector(Sector* sector)
 DrawingEffect
 FlipLevelTransformer::transform_drawing_effect(DrawingEffect effect)
 {
-  if(effect != 0) {
-    return NO_EFFECT;
+  if (effect & VERTICAL_FLIP) {
+    return effect & ~VERTICAL_FLIP;
   } else {
-    return VERTICAL_FLIP;
+    return effect | VERTICAL_FLIP;
   }
 }
 
index 4be9329..ac5f76d 100644 (file)
@@ -1013,7 +1013,7 @@ Sector::collision_tilemap(collision::Constraints* constraints,
         if(tile->is_slope ()) { // slope tile
           AATriangle triangle;
           int slope_data = tile->getData();
-          if (solids->get_drawing_effect() == VERTICAL_FLIP)
+          if (solids->get_drawing_effect() & VERTICAL_FLIP)
             slope_data = AATriangle::vertical_flip(slope_data);
           triangle = AATriangle(tile_bbox, slope_data);
 
index b6dbbe0..6ba8f42 100644 (file)
@@ -76,13 +76,14 @@ SDLPainter::draw_surface(SDL_Renderer* renderer, const DrawingRequest& request)
   SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend));
 
   SDL_RendererFlip flip = SDL_FLIP_NONE;
-  if (surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP)
+  if (surface->get_flipx() || request.drawing_effect & HORIZONTAL_FLIP)
   {
-    flip = SDL_FLIP_HORIZONTAL;
+    flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_HORIZONTAL);
   }
-  else if (request.drawing_effect == VERTICAL_FLIP)
+
+  if (request.drawing_effect & VERTICAL_FLIP)
   {
-    flip = SDL_FLIP_VERTICAL;
+    flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_VERTICAL);
   }
 
   SDL_RenderCopyEx(renderer, sdltexture->get_texture(), NULL, &dst_rect, request.angle, NULL, flip);
@@ -118,13 +119,14 @@ SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& requ
   SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend));
 
   SDL_RendererFlip flip = SDL_FLIP_NONE;
-  if (surface->surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP)
+  if (surface->surface->get_flipx() || request.drawing_effect & HORIZONTAL_FLIP)
   {
-    flip = SDL_FLIP_HORIZONTAL;
+    flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_HORIZONTAL);
   }
-  else if (request.drawing_effect == VERTICAL_FLIP)
+
+  if (request.drawing_effect & VERTICAL_FLIP)
   {
-    flip = SDL_FLIP_VERTICAL;
+    flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_VERTICAL);
   }
 
   SDL_RenderCopyEx(renderer, sdltexture->get_texture(), &src_rect, &dst_rect, request.angle, NULL, flip);
@@ -133,7 +135,7 @@ SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& requ
 void
 SDLPainter::draw_gradient(SDL_Renderer* renderer, const DrawingRequest& request)
 {
-  const GradientRequest* gradientrequest 
+  const GradientRequest* gradientrequest
     = (GradientRequest*) request.request_data;
   const Color& top = gradientrequest->top;
   const Color& bottom = gradientrequest->bottom;
@@ -244,7 +246,7 @@ void
 SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& request)
 {
   const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data;
-  
+
   float x = request.pos.x;
   float w = ellipse->size.x;
   float h = ellipse->size.y;
@@ -256,7 +258,7 @@ SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& r
   int slices = std::min(static_cast<int>(ellipse->size.y), max_slices);
   for(int i = 0; i < slices; ++i)
   {
-    float p = ((static_cast<float>(i) + 0.5f) / static_cast<float>(slices)) * 2.0f - 1.0f; 
+    float p = ((static_cast<float>(i) + 0.5f) / static_cast<float>(slices)) * 2.0f - 1.0f;
     int xoff = static_cast<int>(sqrtf(1.0f - p*p) * w / 2);
 
     SDL_Rect& left  = rects[2*i+0];
index e814547..ca0b68c 100644 (file)
 #include "video/texture_manager.hpp"
 
 /// bitset for drawing effects
-enum DrawingEffect {
+enum {
   /** Don't apply anything */
-  NO_EFFECT,
+  NO_EFFECT = 0,
   /** Draw the Surface upside down */
-  VERTICAL_FLIP,
+  VERTICAL_FLIP = (1<<1),
   /** Draw the Surface from left to down */
-  HORIZONTAL_FLIP,
+  HORIZONTAL_FLIP = (1<<2),
   NUM_EFFECTS
 };
 
+typedef unsigned int DrawingEffect;
+
 /**
  * This class is a wrapper around a texture handle. It stores the texture width
  * and height and provides convenience functions for uploading SDL_Surfaces