[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3832 - in trunk/pingus/src: . display worldobjs
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3832 - in trunk/pingus/src: . display worldobjs |
Date: |
Wed, 16 Jul 2008 12:23:11 +0200 |
Author: grumbel
Date: 2008-07-16 12:23:09 +0200 (Wed, 16 Jul 2008)
New Revision: 3832
Modified:
trunk/pingus/src/display/delta_framebuffer.cpp
trunk/pingus/src/display/delta_framebuffer.hpp
trunk/pingus/src/display/framebuffer.hpp
trunk/pingus/src/display/framebuffer_surface.hpp
trunk/pingus/src/display/sdl_framebuffer.cpp
trunk/pingus/src/display/sdl_framebuffer.hpp
trunk/pingus/src/display/sdl_framebuffer_surface_impl.cpp
trunk/pingus/src/display/sdl_framebuffer_surface_impl.hpp
trunk/pingus/src/font.cpp
trunk/pingus/src/pingus_menu.cpp
trunk/pingus/src/resource.cpp
trunk/pingus/src/sprite.cpp
trunk/pingus/src/sprite.hpp
trunk/pingus/src/sprite_impl.cpp
trunk/pingus/src/sprite_impl.hpp
trunk/pingus/src/surface.cpp
trunk/pingus/src/surface.hpp
trunk/pingus/src/worldobjs/surface_background.cpp
Log:
integrated FramebufferSurface, #if 0'ed some stuff in the process, so game is
currently a little broken
Modified: trunk/pingus/src/display/delta_framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/delta_framebuffer.cpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/display/delta_framebuffer.cpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -21,9 +21,9 @@
#include "delta_framebuffer.hpp"
struct SurfaceDrawOp {
- Vector2i pos;
- SDL_Surface* surface;
- Rect rect;
+ Vector2i pos;
+ FramebufferSurface surface;
+ Rect rect;
void render(Framebuffer& fb) {
fb.draw_surface(surface, rect, pos);
@@ -151,7 +151,7 @@
}
FramebufferSurface
-DeltaFramebuffer::create_surface(SDL_Surface* surface)
+DeltaFramebuffer::create_surface(const Surface& surface)
{
return framebuffer->create_surface(surface);
}
@@ -184,17 +184,17 @@
}
void
-DeltaFramebuffer::draw_surface(SDL_Surface* src, const Vector2i& pos)
+DeltaFramebuffer::draw_surface(const FramebufferSurface& src, const Vector2i&
pos)
{
SurfaceDrawOp op;
op.pos = pos;
op.surface = src;
- op.rect = Rect(Vector2i(0, 0), Size(src->w, src->h));
+ op.rect = Rect(Vector2i(0, 0), src.get_size());
backbuffer->add(op);
}
void
-DeltaFramebuffer::draw_surface(SDL_Surface* src, const Rect& srcrect, const
Vector2i& pos)
+DeltaFramebuffer::draw_surface(const FramebufferSurface& src, const Rect&
srcrect, const Vector2i& pos)
{
SurfaceDrawOp op;
op.pos = pos;
Modified: trunk/pingus/src/display/delta_framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/delta_framebuffer.hpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/display/delta_framebuffer.hpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -35,7 +35,7 @@
public:
DeltaFramebuffer();
- FramebufferSurface create_surface(SDL_Surface* surface);
+ FramebufferSurface create_surface(const Surface& surface);
void set_video_mode(const Size& size, bool fullscreen);
void flip();
@@ -43,8 +43,8 @@
void push_cliprect(const Rect&);
void pop_cliprect();
- void draw_surface(SDL_Surface* src, const Vector2i& pos);
- void draw_surface(SDL_Surface* src, const Rect& srcrect, const Vector2i&
pos);
+ void draw_surface(const FramebufferSurface& src, const Vector2i& pos);
+ void draw_surface(const FramebufferSurface& src, const Rect& srcrect, const
Vector2i& pos);
void draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color);
Modified: trunk/pingus/src/display/framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/framebuffer.hpp 2008-07-16 10:13:14 UTC (rev
3831)
+++ trunk/pingus/src/display/framebuffer.hpp 2008-07-16 10:23:09 UTC (rev
3832)
@@ -24,11 +24,13 @@
#include "math/size.hpp"
#include "math/rect.hpp"
#include "framebuffer_surface.hpp"
+
+class Surface;
class Framebuffer
{
public:
- virtual FramebufferSurface create_surface(SDL_Surface* surface) =0;
+ virtual FramebufferSurface create_surface(const Surface& surface) =0;
virtual void set_video_mode(const Size& size, bool fullscreen) =0;
virtual void flip() =0;
@@ -36,8 +38,8 @@
virtual void push_cliprect(const Rect&) =0;
virtual void pop_cliprect() =0;
- virtual void draw_surface(SDL_Surface* src, const Vector2i& pos) =0;
- virtual void draw_surface(SDL_Surface* src, const Rect& srcrect, const
Vector2i& pos) =0;
+ virtual void draw_surface(const FramebufferSurface& src, const Vector2i&
pos) =0;
+ virtual void draw_surface(const FramebufferSurface& src, const Rect&
srcrect, const Vector2i& pos) =0;
virtual void draw_line(const Vector2i& pos1, const Vector2i& pos2, const
Color& color) =0;
Modified: trunk/pingus/src/display/framebuffer_surface.hpp
===================================================================
--- trunk/pingus/src/display/framebuffer_surface.hpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/display/framebuffer_surface.hpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -18,6 +18,7 @@
#define HEADER_FRAMEBUFFER_SURFACE_HPP
#include <boost/smart_ptr.hpp>
+#include "../math/size.hpp"
class FramebufferSurfaceImpl
{
@@ -30,12 +31,17 @@
class FramebufferSurface
{
public:
+ FramebufferSurface() {}
FramebufferSurface(FramebufferSurfaceImpl* impl) : impl(impl) {}
~FramebufferSurface() {}
- int get_width() const { return impl->get_width(); }
- int get_height() const { return impl->get_height(); }
+ int get_width() const { return impl->get_width(); }
+ int get_height() const { return impl->get_height(); }
+ Size get_size() const { return Size(impl->get_width(),
impl->get_height()); }
+ FramebufferSurfaceImpl* get_impl() const { return impl.get(); }
+
+ bool operator==(const FramebufferSurface& other) const { return impl ==
other.impl; }
private:
boost::shared_ptr<FramebufferSurfaceImpl> impl;
};
Modified: trunk/pingus/src/display/sdl_framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/sdl_framebuffer.cpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/display/sdl_framebuffer.cpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -16,6 +16,7 @@
#include <iostream>
#include "../math.hpp"
+#include "../surface.hpp"
#include "display.hpp"
#include "sdl_framebuffer.hpp"
#include "sdl_framebuffer_surface_impl.hpp"
@@ -147,14 +148,17 @@
}
FramebufferSurface
-SDLFramebuffer::create_surface(SDL_Surface* surface)
+SDLFramebuffer::create_surface(const Surface& surface)
{
- return FramebufferSurface(new SDLFramebufferSurfaceImpl(surface));
+ return FramebufferSurface(new
SDLFramebufferSurfaceImpl(surface.get_surface()));
}
void
-SDLFramebuffer::draw_surface(SDL_Surface* src, const Vector2i& pos)
+SDLFramebuffer::draw_surface(const FramebufferSurface& surface, const
Vector2i& pos)
{
+ SDLFramebufferSurfaceImpl* impl =
dynamic_cast<SDLFramebufferSurfaceImpl*>(surface.get_impl());
+ SDL_Surface* src = impl->get_surface();
+
SDL_Rect dstrect;
dstrect.x = (Sint16)pos.x;
dstrect.y = (Sint16)pos.y;
@@ -165,8 +169,11 @@
}
void
-SDLFramebuffer::draw_surface(SDL_Surface* src, const Rect& srcrect, const
Vector2i& pos)
+SDLFramebuffer::draw_surface(const FramebufferSurface& surface, const Rect&
srcrect, const Vector2i& pos)
{
+ SDLFramebufferSurfaceImpl* impl =
dynamic_cast<SDLFramebufferSurfaceImpl*>(surface.get_impl());
+ SDL_Surface* src = impl->get_surface();
+
SDL_Rect dstrect;
dstrect.x = (Sint16)pos.x;
dstrect.y = (Sint16)pos.y;
Modified: trunk/pingus/src/display/sdl_framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/sdl_framebuffer.hpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/display/sdl_framebuffer.hpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -34,7 +34,7 @@
SDLFramebuffer();
~SDLFramebuffer();
- FramebufferSurface create_surface(SDL_Surface* surface);
+ FramebufferSurface create_surface(const Surface& surface);
void set_video_mode(const Size& size, bool fullscreen);
void flip();
@@ -43,8 +43,8 @@
void push_cliprect(const Rect&);
void pop_cliprect();
- void draw_surface(SDL_Surface* src, const Vector2i& pos);
- void draw_surface(SDL_Surface* src, const Rect& srcrect, const Vector2i&
pos);
+ void draw_surface(const FramebufferSurface& src, const Vector2i& pos);
+ void draw_surface(const FramebufferSurface& src, const Rect& srcrect, const
Vector2i& pos);
void draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color);
Modified: trunk/pingus/src/display/sdl_framebuffer_surface_impl.cpp
===================================================================
--- trunk/pingus/src/display/sdl_framebuffer_surface_impl.cpp 2008-07-16
10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/display/sdl_framebuffer_surface_impl.cpp 2008-07-16
10:23:09 UTC (rev 3832)
@@ -18,8 +18,10 @@
SDLFramebufferSurfaceImpl::SDLFramebufferSurfaceImpl(SDL_Surface* src)
{
- surface = SDL_DisplayFormat(src);
- //surface = SDL_DisplayFormatAlpha();;
+ if (src->format->Amask != 0 || (src->flags & SDL_SRCCOLORKEY))
+ surface = SDL_DisplayFormatAlpha(src);
+ else
+ surface = SDL_DisplayFormat(src);
}
SDLFramebufferSurfaceImpl::~SDLFramebufferSurfaceImpl()
Modified: trunk/pingus/src/display/sdl_framebuffer_surface_impl.hpp
===================================================================
--- trunk/pingus/src/display/sdl_framebuffer_surface_impl.hpp 2008-07-16
10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/display/sdl_framebuffer_surface_impl.hpp 2008-07-16
10:23:09 UTC (rev 3832)
@@ -32,6 +32,8 @@
int get_width() const { return surface->w; }
int get_height() const { return surface->h; }
+
+ SDL_Surface* get_surface() const { return surface; }
};
#endif
Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/font.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -19,9 +19,11 @@
#include "SDL.h"
#include "SDL_image.h"
#include "font.hpp"
+#include "surface.hpp"
#include "line_iterator.hpp"
#include "font_description.hpp"
#include "display/framebuffer.hpp"
+#include "display/display.hpp"
static bool vline_empty(SDL_Surface* surface, int x, Uint8 threshold)
{
@@ -44,22 +46,23 @@
class FontImpl
{
public:
- SDL_Surface* surface;
+ FramebufferSurface framebuffer_surface;
Rect chrs[256];
int space_length;
float char_spacing;
float vertical_spacing;
FontImpl(const FontDescription& desc)
- : surface(0),
- space_length(desc.space_length),
+ : space_length(desc.space_length),
char_spacing(desc.char_spacing)
{
//std::cout << "desc.image: " << desc.image << std::endl;
//std::cout << "desc.space: " << desc.space_length << std::endl;
//std::cout << "Characters: " << desc.characters << std::endl;
- surface = IMG_Load(desc.image.get_sys_path().c_str());
+ Surface software_surface(desc.image);
+ SDL_Surface* surface = software_surface.get_surface();
+
if (!surface)
{
std::cout << "IMG: " << desc.image.str() << std::endl;
@@ -149,11 +152,12 @@
}
SDL_UnlockSurface(surface);
+
+ framebuffer_surface =
Display::get_framebuffer().create_surface(software_surface);
}
~FontImpl()
{
- SDL_FreeSurface(surface);
}
void render(Origin origin, int x, int y_, const std::string& text,
Framebuffer& fb)
@@ -185,7 +189,7 @@
Rect& srcrect = chrs[static_cast<unsigned char>(text[i])];
if (srcrect.get_width() != 0 && srcrect.get_height() != 0)
{
- fb.draw_surface(surface, srcrect, Vector2i(dstx, dsty));
+ fb.draw_surface(framebuffer_surface, srcrect, Vector2i(dstx,
dsty));
dstx += srcrect.get_width() + char_spacing;
}
else
@@ -198,7 +202,7 @@
int get_height() const
{
- return surface->h;
+ return framebuffer_surface.get_height();
}
int get_width(char idx) const
@@ -231,7 +235,7 @@
Size get_size(const std::string& text) const
{
- return Size(get_width(text), surface->h);
+ return Size(get_width(text), get_height());
}
Rect bounding_rect(int x, int y, const std::string& str) const
Modified: trunk/pingus/src/pingus_menu.cpp
===================================================================
--- trunk/pingus/src/pingus_menu.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/pingus_menu.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -220,6 +220,7 @@
// resolution is not default
if (w != default_screen_width && h != default_screen_height)
{
+#if 0 // FIXME: Wed Jul 16 11:40:53 2008
layer1.scale(w, 185 * h / default_screen_height);
layer2.scale(w, 362 * h / default_screen_height);
layer3.scale(w, 306 * h / default_screen_height);
@@ -231,6 +232,7 @@
background->add_layer(layer3, 0, 200 * (float)h / default_screen_height,
50, 0);
background->add_layer(layer4, 0, 429 * (float)h / default_screen_height,
100, 0);
background->add_layer(layer5, 0, 500 * (float)h / default_screen_height,
200, 0);
+#endif
}
else
{
Modified: trunk/pingus/src/resource.cpp
===================================================================
--- trunk/pingus/src/resource.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/resource.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -137,7 +137,9 @@
else
thumb_size.height = 48;
+#if 0 // FIXME: Wed Jul 16 11:40:53 2008
sprite.scale(thumb_size.width, thumb_size.height);
+#endif
sprite.set_hotspot(origin_top_left, (48 - sprite.get_width())/2, (48 -
sprite.get_height())/2);
Modified: trunk/pingus/src/sprite.cpp
===================================================================
--- trunk/pingus/src/sprite.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/sprite.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -186,6 +186,7 @@
impl->finish();
}
+#if 0 // FIXME: Wed Jul 16 11:40:53 2008
void
Sprite::scale(int w, int h)
{
@@ -195,7 +196,6 @@
if (impl->frame_size.width != w || impl->frame_size.height != h)
{
boost::shared_ptr<SpriteImpl> new_impl(new SpriteImpl());
-
if ((impl->frame_size.width * impl->array.width) ==
impl->surface.get_width() &&
(impl->frame_size.height * impl->array.height) ==
impl->surface.get_height())
@@ -262,6 +262,7 @@
impl = new_impl;
}
}
+#endif
Vector2i
Sprite::get_offset() const
@@ -282,6 +283,7 @@
}
}
+#if 0 // FIXME
void
Sprite::apply_mod(ResourceModifierNS::ResourceModifier mod)
{
@@ -305,5 +307,7 @@
}
}
}
+#endif
+
/* EOF */
Modified: trunk/pingus/src/sprite.hpp
===================================================================
--- trunk/pingus/src/sprite.hpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/sprite.hpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -45,9 +45,9 @@
int get_width() const;
int get_height() const;
+ void render(float x, float y, Framebuffer& target);
void update(float delta = 0.033f);
- void render(float x, float y, Framebuffer& target);
void set_hotspot(Origin origin, int x, int y);
Vector2i get_offset() const;
void set_frame(int i);
@@ -60,21 +60,6 @@
void finish();
operator bool();
- /** Resizes the Sprite to the given size. This is a destructive
- operation. The original Surface will be lost. */
- void scale(int w, int h);
-
- /** Fills the Sprite with the given color. Transparent areas aren't
- touched. This is a destructive operation. The original Surface
- will be lost. */
- void fill(const Color& color);
-
- /** Duplicate the underlying SDL_Surface to allow manipulation
- without affecting other references to it */
- void make_single_user();
-
- void apply_mod(ResourceModifierNS::ResourceModifier mod);
-
private:
boost::shared_ptr<SpriteImpl> impl;
};
Modified: trunk/pingus/src/sprite_impl.cpp
===================================================================
--- trunk/pingus/src/sprite_impl.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/sprite_impl.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "display/framebuffer.hpp"
+#include "display/display.hpp"
#include "sprite_description.hpp"
#include "sprite_impl.hpp"
@@ -23,12 +24,11 @@
}
SpriteImpl::SpriteImpl(const SpriteDescription& desc,
ResourceModifierNS::ResourceModifier mod)
- : optimized(false),
- finished(false),
+ : finished(false),
frame(0),
tick_count(0)
{
- surface = Surface(desc.filename);
+ Surface surface(desc.filename);
if (mod != ResourceModifierNS::ROT0)
surface = surface.mod(mod);
@@ -39,6 +39,8 @@
if (!surface) assert(!"Surface Couldn't find 404");
}
+ framebuffer_surface = Display::get_framebuffer().create_surface(surface);
+
frame_pos = desc.frame_pos;
array = desc.array;
@@ -55,9 +57,8 @@
}
-SpriteImpl::SpriteImpl(const Surface& surface_)
- : surface(surface_),
- optimized(false),
+SpriteImpl::SpriteImpl(const Surface& surface)
+ : framebuffer_surface(Display::get_framebuffer().create_surface(surface)),
offset(0,0),
frame_pos(0,0),
frame_size(surface.get_width(), surface.get_height()),
@@ -76,13 +77,6 @@
}
void
-SpriteImpl::optimize()
-{
- surface = surface.optimize();
- optimized = true;
-}
-
-void
SpriteImpl::update(float delta)
{
if (finished)
@@ -113,10 +107,7 @@
void
SpriteImpl::render(float x, float y, Framebuffer& fb)
{
- if (!optimized)
- optimize();
-
- fb.draw_surface(surface.get_surface(),
+ fb.draw_surface(framebuffer_surface,
Rect(frame_pos + Vector2i(frame_size.width *
(frame%array.width),
frame_size.height *
(frame/array.width)),
frame_size),
Modified: trunk/pingus/src/sprite_impl.hpp
===================================================================
--- trunk/pingus/src/sprite_impl.hpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/sprite_impl.hpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -18,9 +18,9 @@
#define HEADER_PINGUS_SPRITE_IMPL_HPP
#include "surface.hpp"
+#include "display/framebuffer_surface.hpp"
#include "math/vector2i.hpp"
-class Framebuffer;
class SpriteDescription;
class SpriteImpl
@@ -28,8 +28,7 @@
private:
friend class Sprite;
- Surface surface;
- bool optimized;
+ FramebufferSurface framebuffer_surface;
Vector2i offset;
Vector2i frame_pos;
@@ -52,7 +51,6 @@
SpriteImpl(const Surface& surface_);
~SpriteImpl();
- void optimize();
void update(float delta);
void render(float x, float y, Framebuffer& fb);
Modified: trunk/pingus/src/surface.cpp
===================================================================
--- trunk/pingus/src/surface.cpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/surface.cpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -250,26 +250,6 @@
}
Surface
-Surface::optimize()
-{
- if (impl.get())
- {
- SDL_Surface* new_surface;
-
- if (impl->surface->format->Amask != 0 || (impl->surface->flags &
SDL_SRCCOLORKEY))
- new_surface = SDL_DisplayFormatAlpha(impl->surface);
- else
- new_surface = SDL_DisplayFormat(impl->surface);
-
- return Surface(new_surface);
- }
- else
- {
- return Surface();
- }
-}
-
-Surface
Surface::scale(int w, int h)
{
return Surface(boost::shared_ptr<SurfaceImpl>
Modified: trunk/pingus/src/surface.hpp
===================================================================
--- trunk/pingus/src/surface.hpp 2008-07-16 10:13:14 UTC (rev 3831)
+++ trunk/pingus/src/surface.hpp 2008-07-16 10:23:09 UTC (rev 3832)
@@ -64,7 +64,6 @@
Color get_pixel(int x, int y) const;
void fill(const Color& color);
- Surface optimize();
Surface scale(int w, int h);
Surface mod(ResourceModifierNS::ResourceModifier mod);
Modified: trunk/pingus/src/worldobjs/surface_background.cpp
===================================================================
--- trunk/pingus/src/worldobjs/surface_background.cpp 2008-07-16 10:13:14 UTC
(rev 3831)
+++ trunk/pingus/src/worldobjs/surface_background.cpp 2008-07-16 10:23:09 UTC
(rev 3832)
@@ -57,6 +57,7 @@
reader.read_bool("keep-aspect", keep_aspect);
bg_surface = Sprite(desc);
+#if 0 // FIXME: Wed Jul 16 11:40:53 2008
bg_surface.fill(color);
// Scaling Code
@@ -88,6 +89,7 @@
bg_surface.scale(bg_surface.get_width(), world->get_height());
}
}
+#endif
}
float
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3832 - in trunk/pingus/src: . display worldobjs,
grumbel at BerliOS <=