[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3781 - in trunk/pingus/src: . components display screen
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3781 - in trunk/pingus/src: . components display screen |
Date: |
Fri, 11 Jul 2008 12:07:44 +0200 |
Author: grumbel
Date: 2008-07-11 12:07:43 +0200 (Fri, 11 Jul 2008)
New Revision: 3781
Modified:
trunk/pingus/src/components/action_button.cpp
trunk/pingus/src/components/pingus_counter.cpp
trunk/pingus/src/config_manager.cpp
trunk/pingus/src/display/display.cpp
trunk/pingus/src/display/display.hpp
trunk/pingus/src/display/framebuffer.cpp
trunk/pingus/src/display/framebuffer.hpp
trunk/pingus/src/pingus_main.cpp
trunk/pingus/src/screen/screen_manager.cpp
Log:
Made Display use Framebuffer
Modified: trunk/pingus/src/components/action_button.cpp
===================================================================
--- trunk/pingus/src/components/action_button.cpp 2008-07-11 10:06:35 UTC
(rev 3780)
+++ trunk/pingus/src/components/action_button.cpp 2008-07-11 10:07:43 UTC
(rev 3781)
@@ -20,7 +20,6 @@
#include "../game_session.hpp"
#include "../world.hpp"
#include "../display/drawing_context.hpp"
-#include "../display/display.hpp"
#include "../fonts.hpp"
#include "../string_util.hpp"
#include "../math/vector3f.hpp"
Modified: trunk/pingus/src/components/pingus_counter.cpp
===================================================================
--- trunk/pingus/src/components/pingus_counter.cpp 2008-07-11 10:06:35 UTC
(rev 3780)
+++ trunk/pingus/src/components/pingus_counter.cpp 2008-07-11 10:07:43 UTC
(rev 3781)
@@ -15,7 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
-#include "../display/display.hpp"
#include "../gettext.h"
#include "../resource.hpp"
#include "../world.hpp"
Modified: trunk/pingus/src/config_manager.cpp
===================================================================
--- trunk/pingus/src/config_manager.cpp 2008-07-11 10:06:35 UTC (rev 3780)
+++ trunk/pingus/src/config_manager.cpp 2008-07-11 10:07:43 UTC (rev 3781)
@@ -81,7 +81,7 @@
{
screen_width = size.width;
screen_height = size.height;
- Display::set_video_mode(screen_width, screen_height);
+ Display::set_video_mode(screen_width, screen_height, fullscreen_enabled);
on_resolution_change(size);
}
}
@@ -102,7 +102,7 @@
if (v != get_fullscreen())
{
fullscreen_enabled = v;
- Display::set_video_mode(screen_width, screen_height);
+ Display::set_video_mode(screen_width, screen_height, fullscreen_enabled);
on_fullscreen_change(v);
}
}
Modified: trunk/pingus/src/display/display.cpp
===================================================================
--- trunk/pingus/src/display/display.cpp 2008-07-11 10:06:35 UTC (rev
3780)
+++ trunk/pingus/src/display/display.cpp 2008-07-11 10:07:43 UTC (rev
3781)
@@ -22,402 +22,84 @@
#include "../math/rect.hpp"
#include "../math/color.hpp"
#include "../math.hpp"
+#include "framebuffer.hpp"
#include "display.hpp"
-std::vector<SDL_Rect> Display::cliprect_stack;
-SDL_Surface* Display::screen;
-
-namespace {
-SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
+std::auto_ptr<Framebuffer> Display::framebuffer;
+
+void
+Display::draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color)
{
- SDL_Rect rect;
- rect.x = Math::max(r1->x, r2->x);
- rect.y = Math::max(r1->y, r2->y);
- int endx = Math::min(r1->x + r1->w, r2->x + r2->w);
- rect.w = Math::max(endx - rect.x, 0);
- int endy = Math::min(r1->y + r1->h, r2->y + r2->h);
- rect.h = Math::max(endy - rect.y, 0);
- return rect;
+ framebuffer->draw_line(pos1, pos2, color);
}
-} // namespace
void
-Display::flip_display(bool sync)
+Display::draw_rect(const Rect& rect, const Color& color)
{
- SDL_Flip(screen);
+ framebuffer->draw_rect(rect, color);
}
void
-Display::set_video_mode(int width, int height)
+Display::fill_rect(const Rect& rect, const Color& color)
{
- Uint32 flags = SDL_RESIZABLE;
+ framebuffer->fill_rect(rect, color);
+}
- if (fullscreen_enabled)
- flags |= SDL_FULLSCREEN;
-
- screen = SDL_SetVideoMode(width, height, 0, flags);
-
- if (screen == NULL)
- {
- std::cout << "Unable to set video mode: " << SDL_GetError() << std::endl;
- exit(1);
- }
+void
+Display::flip_display()
+{
+ return framebuffer->flip();
}
int
Display::get_width()
{
- return screen->w;
+ return framebuffer->get_size().width;
}
int
Display::get_height()
{
- return screen->h;
+ return framebuffer->get_size().height;
}
Size
Display::get_size()
{
- return Size(screen->w, screen->h);
+ return framebuffer->get_size();
}
void
-Display::clear()
+Display::set_video_mode(int width, int height, bool fullscreen)
{
- SDL_FillRect(screen, NULL, SDL_MapRGB(Display::get_screen()->format, 0, 0,
0));
-}
+ if (!framebuffer.get())
+ framebuffer = std::auto_ptr<Framebuffer>(new Framebuffer());
-static void draw_pixel16(int x, int y, const Color& c)
-{
- Uint32 color = SDL_MapRGBA(Display::get_screen()->format, c.r, c.g, c.b,
c.a);
-
- if (c.a < 255) {
- Uint16 *p;
- unsigned long dp;
- unsigned char alpha;
-
- // Loses precision for speed
- alpha = (255 - c.a) >> 3;
-
- p = &((Uint16 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w];
- color = (((color << 16) | color) & 0x07E0F81F);
- dp = *p;
- dp = ((dp << 16) | dp) & 0x07E0F81F;
- dp = ((((dp - color) * alpha) >> 5) + color) & 0x07E0F81F;
- *p = (Uint16)((dp >> 16) | dp);
- } else {
- ((Uint16 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w] = color;
- }
+ framebuffer->set_video_mode(width, height, fullscreen);
}
-static void draw_pixel32(int x, int y, const Color& c)
-{
- Uint32 color = SDL_MapRGBA(Display::get_screen()->format, c.r, c.g, c.b,
c.a);
-
- if (c.a < 255) {
- Uint32 *p;
- unsigned long sp2;
- unsigned long dp1;
- unsigned long dp2;
- unsigned char alpha;
-
- alpha = 255 - c.a;
-
- p = &((Uint32*)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w];
-
- sp2 = (color & 0xFF00FF00) >> 8;
- color &= 0x00FF00FF;
-
- dp1 = *p;
- dp2 = (dp1 & 0xFF00FF00) >> 8;
- dp1 &= 0x00FF00FF;
-
- dp1 = ((((dp1 - color) * alpha) >> 8) + color) & 0x00FF00FF;
- dp2 = ((((dp2 - sp2) * alpha) >> 8) + sp2) & 0x00FF00FF;
- *p = (dp1 | (dp2 << 8));
- } else {
- ((Uint32 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w] = color;
- }
-}
-
-typedef void (*draw_pixel_func)(int, int, const Color&);
-static draw_pixel_func get_draw_pixel()
-{
- switch (Display::get_screen()->format->BitsPerPixel)
- {
- case 16:
- return draw_pixel16;
- case 32:
- return draw_pixel32;
- }
- return NULL;
-}
-
-static void draw_vline(int x, int y, int length, const Color& color)
-{
- draw_pixel_func draw_pixel = get_draw_pixel();
- if (!draw_pixel)
- return;
-
- SDL_LockSurface(Display::get_screen());
- for (int i = 0; i < length; ++i) {
- draw_pixel(x, y + i, color);
- }
- SDL_UnlockSurface(Display::get_screen());
-}
-
-static void draw_hline(int x, int y, int length, const Color& color)
-{
- draw_pixel_func draw_pixel = get_draw_pixel();
- if (!draw_pixel)
- return;
-
- SDL_LockSurface(Display::get_screen());
- for (int i = 0; i < length; ++i) {
- draw_pixel(x + i, y, color);
- }
- SDL_UnlockSurface(Display::get_screen());
-}
-
-static
-void clip(int& i, int min, int max)
-{
- if (i < min)
- i = min;
- else if (i > max)
- i = max;
-}
-
+
void
-Display::draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color)
+Display::clear()
{
- int x, y, xlen, ylen, incr;
- int sx = pos1.x;
- int sy = pos1.y;
- int dx = pos2.x;
- int dy = pos2.y;
- void (*draw_pixel)(int x, int y, const Color& color);
- int clipx1, clipx2, clipy1, clipy2;
- SDL_Rect rect;
-
- SDL_GetClipRect(Display::get_screen(), &rect);
- clipx1 = rect.x;
- clipx2 = rect.x + rect.w - 1;
- clipy1 = rect.y;
- clipy2 = rect.y + rect.h - 1;
-
- // vertical line
- if (sx == dx) {
- if (sx < clipx1 || sx > clipx2 || (sy < clipy1 && dy < clipy1) || (sy >
clipy2 && dy > clipy2)) {
- return;
- }
- clip(sy, clipy1, clipy2);
- clip(dy, clipy1, clipy2);
- if (sy < dy) {
- draw_vline(sx, sy, dy - sy + 1, color);
- } else {
- draw_vline(dx, dy, sy - dy + 1, color);
- }
- return;
- }
-
- // horizontal
- if (sy == dy) {
- if (sy < clipy1 || sy > clipy2 || (sx < clipx1 && dx < clipx1) || (sx >
clipx2 && dx > clipx2)) {
- return;
- }
- clip(sx, clipx1, clipx2);
- clip(dx, clipx1, clipx2);
- if (sx < dx) {
- draw_hline(sx, sy, dx - sx + 1, color);
- } else {
- draw_hline(dx, dy, sx - dx + 1, color);
- }
- return;
- }
-
- draw_pixel = get_draw_pixel();
- if (!draw_pixel) {
- return;
- }
-
- // exchange coordinates
- if (sy > dy) {
- int t = dx;
- dx = sx;
- sx = t;
- t = dy;
- dy = sy;
- sy = t;
- }
- ylen = dy - sy;
-
- if (sx > dx) {
- xlen = sx - dx;
- incr = -1;
- } else {
- xlen = dx - sx;
- incr = 1;
- }
-
- y = sy;
- x = sx;
-
- if (xlen > ylen) {
- if (sx > dx) {
- int t = sx;
- sx = dx;
- dx = t;
- y = dy;
- }
-
- int p = (ylen << 1) - xlen;
-
- SDL_LockSurface(screen);
- for (x = sx; x < dx; ++x) {
- if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
- }
- if (p >= 0) {
- y += incr;
- p += (ylen - xlen) << 1;
- } else {
- p += (ylen << 1);
- }
- }
- SDL_UnlockSurface(screen);
- return;
- }
-
- if (ylen > xlen) {
- int p = (xlen << 1) - ylen;
-
- SDL_LockSurface(screen);
- for (y = sy; y < dy; ++y) {
- if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
- }
- if (p >= 0) {
- x += incr;
- p += (xlen - ylen) << 1;
- } else {
- p += (xlen << 1);
- }
- }
- SDL_UnlockSurface(screen);
- return;
- }
-
- // Draw a diagonal line
- if (ylen == xlen) {
- SDL_LockSurface(screen);
- while (y != dy) {
- if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
- }
- x += incr;
- ++y;
- }
- SDL_UnlockSurface(screen);
- }
+ framebuffer->clear();
}
-void
-Display::draw_rect(const Rect& rect, const Color& color)
+SDL_Surface*
+Display::get_screen()
{
- draw_line(Vector2i(rect.left, rect.top), Vector2i(rect.right-1,
rect.top), color);
- draw_line(Vector2i(rect.left, rect.bottom-1), Vector2i(rect.right-1,
rect.bottom-1), color);
- draw_line(Vector2i(rect.left, rect.top), Vector2i(rect.left,
rect.bottom-1), color);
- draw_line(Vector2i(rect.right-1, rect.top), Vector2i(rect.right-1,
rect.bottom-1), color);
+ return framebuffer->get_screen();
}
void
-Display::fill_rect(const Rect& rect_, const Color& color)
-{
- Rect rect = rect_;
- rect.normalize();
-
- if (color.a == 255)
- {
- SDL_Rect srcrect;
-
- srcrect.x = rect.left;
- srcrect.y = rect.top;
- srcrect.w = rect.get_width();
- srcrect.h = rect.get_height();
-
- SDL_FillRect(screen, &srcrect, SDL_MapRGB(screen->format, color.r,
color.g, color.b));
- }
- else if (color.a != 0)
- {
- int top, bottom, left, right;
- int clipx1, clipx2, clipy1, clipy2;
- SDL_Rect cliprect;
-
- SDL_GetClipRect(Display::get_screen(), &cliprect);
- clipx1 = cliprect.x;
- clipx2 = cliprect.x + cliprect.w - 1;
- clipy1 = cliprect.y;
- clipy2 = cliprect.y + cliprect.h - 1;
-
- if (rect.right < clipx1 || rect.left > clipx2 || rect.bottom < clipy1 ||
rect.top > clipy2)
- return;
-
- top = rect.top < clipy1 ? clipy1 : rect.top;
- bottom = rect.bottom > clipy2 ? clipy2 : rect.bottom;
- left = rect.left < clipx1 ? clipx1 : rect.left;
- right = rect.right > clipx2 ? clipx2 : rect.right;
-
- draw_pixel_func draw_pixel = get_draw_pixel();
- if (!draw_pixel)
- return;
-
- SDL_LockSurface(Display::get_screen());
- for (int j = top; j <= bottom; ++j) {
- for (int i = left; i <= right; ++i) {
- draw_pixel(i, j, color);
- }
- }
- SDL_UnlockSurface(Display::get_screen());
- }
-}
-
-void
Display::push_cliprect(const Rect& rect)
{
- SDL_Rect sdl_rect;
- sdl_rect.x = rect.left;
- sdl_rect.y = rect.top;
- sdl_rect.w = rect.get_width();
- sdl_rect.h = rect.get_height();
-
- if (!cliprect_stack.empty())
- sdl_rect = Intersection(&cliprect_stack.back(), &sdl_rect);
-
- cliprect_stack.push_back(sdl_rect);
- SDL_SetClipRect(screen, &cliprect_stack.back());
+ framebuffer->push_cliprect(rect);
}
void
Display::pop_cliprect()
{
- cliprect_stack.pop_back();
- if (cliprect_stack.empty())
- SDL_SetClipRect(screen, NULL);
- else
- SDL_SetClipRect(screen, &cliprect_stack.back());
+ framebuffer->pop_cliprect();
}
-
-void
-Display::draw_surface(SDL_Surface* sur, const Vector2i& pos)
-{
-
-}
-
-void
-Display::draw_surface(SDL_Surface* sur, const Vector2i& pos, const Rect& rect)
-{
-
-}
-
+
/* EOF */
Modified: trunk/pingus/src/display/display.hpp
===================================================================
--- trunk/pingus/src/display/display.hpp 2008-07-11 10:06:35 UTC (rev
3780)
+++ trunk/pingus/src/display/display.hpp 2008-07-11 10:07:43 UTC (rev
3781)
@@ -17,7 +17,7 @@
#ifndef HEADER_PINGUS_DISPLAY_HPP
#define HEADER_PINGUS_DISPLAY_HPP
-#include "../pingus.hpp"
+#include <memory>
#include "SDL.h"
#include <list>
#include <vector>
@@ -26,34 +26,30 @@
class Vector2i;
class Rect;
class Color;
-class DisplayHook;
+class Framebuffer;
class Display
{
private:
- static std::vector<SDL_Rect> cliprect_stack;
- static SDL_Surface* screen;
+ static std::auto_ptr<Framebuffer> framebuffer;
public:
- static void draw_surface(SDL_Surface* sur, const Vector2i& pos);
- static void draw_surface(SDL_Surface* sur, const Vector2i& pos, const Rect&
rect);
-
static void draw_line(const Vector2i& pos1, const Vector2i& pos2, const
Color& color);
static void draw_rect(const Rect& rect, const Color& color);
static void fill_rect(const Rect& rect, const Color& color);
- static void flip_display(bool sync=false);
+ static void flip_display();
static int get_width();
static int get_height();
static Size get_size();
- static void set_video_mode(int width, int height);
+ static void set_video_mode(int width, int height, bool fullscreen);
static void clear();
- static SDL_Surface* get_screen() { return screen; }
+ static SDL_Surface* get_screen();
static void push_cliprect(const Rect&);
static void pop_cliprect();
Modified: trunk/pingus/src/display/framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/framebuffer.cpp 2008-07-11 10:06:35 UTC (rev
3780)
+++ trunk/pingus/src/display/framebuffer.cpp 2008-07-11 10:07:43 UTC (rev
3781)
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <iostream>
#include "../math.hpp"
#include "display.hpp"
#include "framebuffer.hpp"
@@ -134,8 +135,8 @@
} // namespace
-Framebuffer::Framebuffer(SDL_Surface* screen_)
- : screen(screen_)
+Framebuffer::Framebuffer()
+ : screen(0)
{
}
@@ -360,8 +361,20 @@
}
void
-Framebuffer::set_video_mode(int width, int height)
+Framebuffer::set_video_mode(int width, int height, bool fullscreen)
{
+ Uint32 flags = SDL_RESIZABLE;
+
+ if (fullscreen)
+ flags |= SDL_FULLSCREEN;
+
+ screen = SDL_SetVideoMode(width, height, 0, flags);
+
+ if (screen == NULL)
+ {
+ std::cout << "Unable to set video mode: " << SDL_GetError() << std::endl;
+ exit(1);
+ }
}
void
Modified: trunk/pingus/src/display/framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/framebuffer.hpp 2008-07-11 10:06:35 UTC (rev
3780)
+++ trunk/pingus/src/display/framebuffer.hpp 2008-07-11 10:07:43 UTC (rev
3781)
@@ -31,10 +31,10 @@
std::vector<SDL_Rect> cliprect_stack;
public:
- Framebuffer(SDL_Surface* screen_);
+ Framebuffer();
~Framebuffer();
- void set_video_mode(int width, int height);
+ void set_video_mode(int width, int height, bool fullscreen);
void flip();
void clear();
@@ -50,7 +50,8 @@
void fill_rect(const Rect& rect, const Color& color);
Size get_size();
-
+
+ SDL_Surface* get_screen() { return screen; }
private:
Framebuffer (const Framebuffer&);
Framebuffer& operator= (const Framebuffer&);
Modified: trunk/pingus/src/pingus_main.cpp
===================================================================
--- trunk/pingus/src/pingus_main.cpp 2008-07-11 10:06:35 UTC (rev 3780)
+++ trunk/pingus/src/pingus_main.cpp 2008-07-11 10:07:43 UTC (rev 3781)
@@ -725,7 +725,7 @@
exit(1);
}
atexit(SDL_Quit);
- Display::set_video_mode(screen_width, screen_height);
+ Display::set_video_mode(screen_width, screen_height, fullscreen_enabled);
SDL_WM_SetCaption("Pingus " VERSION " - SDL Edition", 0 /* icon */);
Modified: trunk/pingus/src/screen/screen_manager.cpp
===================================================================
--- trunk/pingus/src/screen/screen_manager.cpp 2008-07-11 10:06:35 UTC (rev
3780)
+++ trunk/pingus/src/screen/screen_manager.cpp 2008-07-11 10:07:43 UTC (rev
3781)
@@ -382,7 +382,8 @@
// FIXME: Calling this causes horrible flicker, since the screen
// goes black on a size change. Seems to be an SDL issue.
- Display::set_video_mode(size.width, size.height);
+ // This call also shouldn't be part of ScreenManager, but
Framebuffer/Display internal
+ Display::set_video_mode(size.width, size.height, fullscreen_enabled);
// FIXME: We need to resize the other screens too
get_current_screen()->resize(size);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3781 - in trunk/pingus/src: . components display screen,
grumbel at BerliOS <=