From b2afe9f0005c9d4f745225d2a64e224c9c8cd1ef Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Tue, 12 Aug 2014 22:16:02 +0200 Subject: [PATCH] Moved some declarations from drawing_requests.hpp to drawing_context.hpp to reduce include dependencies --- src/video/drawing_context.cpp | 8 +++---- src/video/drawing_context.hpp | 54 +++++++++++++++++++++++++++++++++++-------- src/video/drawing_request.hpp | 46 +----------------------------------- src/video/font.cpp | 37 ++++++++++++++--------------- src/video/gl/gl_lightmap.cpp | 17 ++++++++++---- 5 files changed, 82 insertions(+), 80 deletions(-) diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index e4b9ebcfe..57057b843 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -326,8 +326,9 @@ DrawingContext::do_drawing() target_stack.clear(); //Use Lightmap if ambient color is not white. - bool use_lightmap = ( ambient_color.red != 1.0f || ambient_color.green != 1.0f || - ambient_color.blue != 1.0f ); + bool use_lightmap = ( ambient_color.red != 1.0f || + ambient_color.green != 1.0f || + ambient_color.blue != 1.0f ); // PART1: create lightmap if(use_lightmap) { @@ -341,10 +342,9 @@ DrawingContext::do_drawing() request->layer = LAYER_HUD - 1; drawing_requests.push_back(request); } + handle_drawing_requests(drawing_requests); clear_drawing_requests(lightmap_requests); - - handle_drawing_requests(drawing_requests); clear_drawing_requests(drawing_requests); obstack_free(&obst, NULL); diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 6b782c2eb..99982e301 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -26,24 +26,60 @@ #include "math/rectf.hpp" #include "math/vector.hpp" #include "video/color.hpp" -#include "video/drawing_request.hpp" #include "video/font.hpp" #include "video/font_ptr.hpp" #include "video/texture.hpp" +class DrawingRequest; +class Lightmap; +class Renderer; class Surface; class Texture; -class Renderer; -class Lightmap; -inline int next_po2(int val) +// some constants for predefined layer values +enum { + // Image/gradient backgrounds (should cover entire screen) + LAYER_BACKGROUND0 = -300, + // Particle backgrounds + LAYER_BACKGROUND1 = -200, + // Tilemap backgrounds + LAYER_BACKGROUNDTILES = -100, + // Solid tilemaps + LAYER_TILES = 0, + // Ordinary objects + LAYER_OBJECTS = 50, + // Objects that pass through walls + LAYER_FLOATINGOBJECTS = 150, + // + LAYER_FOREGROUNDTILES = 200, + // + LAYER_FOREGROUND0 = 300, + // + LAYER_FOREGROUND1 = 400, + // Hitpoints, time, coins, etc. + LAYER_HUD = 500, + // Menus, mouse, console etc. + LAYER_GUI = 600 +}; + +class Blend { - int result = 1; - while(result < val) - result *= 2; +public: + GLenum sfactor; + GLenum dfactor; + + Blend() + : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA) + {} - return result; -} + Blend(GLenum s, GLenum d) + : sfactor(s), dfactor(d) + {} +}; + +enum Target { + NORMAL, LIGHTMAP +}; /** * This class provides functions for drawing things on screen. It also diff --git a/src/video/drawing_request.hpp b/src/video/drawing_request.hpp index 669c923fd..59b977b26 100644 --- a/src/video/drawing_request.hpp +++ b/src/video/drawing_request.hpp @@ -25,56 +25,12 @@ #include "math/vector.hpp" #include "video/color.hpp" +#include "video/drawing_context.hpp" #include "video/font.hpp" #include "video/glutil.hpp" class Surface; -// some constants for predefined layer values -enum { - // Image/gradient backgrounds (should cover entire screen) - LAYER_BACKGROUND0 = -300, - // Particle backgrounds - LAYER_BACKGROUND1 = -200, - // Tilemap backgrounds - LAYER_BACKGROUNDTILES = -100, - // Solid tilemaps - LAYER_TILES = 0, - // Ordinary objects - LAYER_OBJECTS = 50, - // Objects that pass through walls - LAYER_FLOATINGOBJECTS = 150, - // - LAYER_FOREGROUNDTILES = 200, - // - LAYER_FOREGROUND0 = 300, - // - LAYER_FOREGROUND1 = 400, - // Hitpoints, time, coins, etc. - LAYER_HUD = 500, - // Menus, mouse, console etc. - LAYER_GUI = 600 -}; - -class Blend -{ -public: - GLenum sfactor; - GLenum dfactor; - - Blend() - : sfactor(GL_SRC_ALPHA), dfactor(GL_ONE_MINUS_SRC_ALPHA) - {} - - Blend(GLenum s, GLenum d) - : sfactor(s), dfactor(d) - {} -}; - -enum Target { - NORMAL, LIGHTMAP -}; - enum RequestType { SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, DRAW_LIGHTMAP, GETLIGHT diff --git a/src/video/font.cpp b/src/video/font.cpp index 638f2e09b..ed431e2d0 100644 --- a/src/video/font.cpp +++ b/src/video/font.cpp @@ -32,6 +32,7 @@ #include "util/log.hpp" #include "util/utf8_iterator.hpp" #include "video/drawing_context.hpp" +#include "video/drawing_request.hpp" #include "video/font.hpp" #include "video/renderer.hpp" @@ -81,7 +82,7 @@ Font::Font(GlyphWidth glyph_width_, PHYSFS_freeList(rc); } -void +void Font::loadFontFile(const std::string &filename) { lisp::Parser parser; @@ -100,7 +101,7 @@ Font::loadFontFile(const std::string &filename) if( !config_l->get("glyph-width",def_char_width) ) { log_warning << "Font:"<< filename << ": misses default glyph-width" << std::endl; } - + if( !config_l->get("glyph-height",char_height) ) { std::ostringstream msg; msg << "Font:" << filename << ": misses glyph-height"; @@ -158,7 +159,7 @@ Font::loadFontFile(const std::string &filename) } } -void +void Font::loadFontSurface( const std::string &glyphimage, const std::string &shadowimage, @@ -176,9 +177,9 @@ Font::loadFontSurface( int row=0, col=0; int wrap = glyph_surface->get_width() / char_width; - + SDL_Surface *surface = NULL; - + if( glyph_width == VARIABLE ) { //this does not work: // surface = ((SDL::Texture *)glyph_surface.get_texture())->get_texture(); @@ -197,17 +198,17 @@ Font::loadFontSurface( int x = col * (char_width + 2*border) + border; if( ++col == wrap ) { col=0; row++; } if( *chr == 0x0020 && glyphs[0x20].surface_idx != -1) continue; - + Glyph glyph; glyph.surface_idx = surface_idx; - - if( glyph_width == FIXED ) + + if( glyph_width == FIXED ) { glyph.rect = Rectf(x, y, x + char_width, y + char_height); glyph.offset = Vector(0, 0); glyph.advance = char_width; } - else + else { if (y + char_height > surface->h) { @@ -221,13 +222,13 @@ Font::loadFontSurface( int right = x + char_width - 1; while (right > left && vline_empty(surface, right, y, y + char_height, 64)) right -= 1; - - if (left <= right) + + if (left <= right) { glyph.offset = Vector(x-left, 0); glyph.advance = right - left + 1 + 1; // FIXME: might be useful to make spacing configurable - } - else + } + else { // glyph is completly transparent glyph.offset = Vector(0, 0); glyph.advance = char_width + 1; // FIXME: might be useful to make spacing configurable @@ -238,7 +239,7 @@ Font::loadFontSurface( glyphs[*chr] = glyph; } - if( col>0 && col <= wrap ) { + if( col>0 && col <= wrap ) { col = 0; row++; } @@ -272,7 +273,7 @@ Font::get_text_width(const std::string& text) const { if( glyphs.at(*it).surface_idx != -1 ) curr_width += glyphs[*it].advance; - else + else curr_width += glyphs[0x20].advance; } } @@ -344,7 +345,7 @@ Font::wrap_to_width(const std::string& s_, float width, std::string* overflow) return s.substr(0, i); } } - + // FIXME: hard-wrap at width, taking care of multibyte characters if (overflow) *overflow = ""; return s; @@ -393,7 +394,7 @@ Font::draw_text(Renderer *renderer, const std::string& text, const Vector& pos, DrawingEffect drawing_effect, Color color, float alpha) const { if(shadowsize > 0) - draw_chars(renderer, false, text, + draw_chars(renderer, false, text, pos + Vector(shadowsize, shadowsize), drawing_effect, Color(1,1,1), alpha); draw_chars(renderer, true, text, pos, drawing_effect, color, alpha); @@ -422,7 +423,7 @@ Font::draw_chars(Renderer *renderer, bool notshadow, const std::string& text, Glyph glyph; if( glyphs.at(*it).surface_idx != -1 ) glyph = glyphs[*it]; - else + else glyph = glyphs[0x20]; DrawingRequest request; diff --git a/src/video/gl/gl_lightmap.cpp b/src/video/gl/gl_lightmap.cpp index 8cf8494c0..d3fa72126 100644 --- a/src/video/gl/gl_lightmap.cpp +++ b/src/video/gl/gl_lightmap.cpp @@ -41,6 +41,15 @@ #include "video/surface.hpp" #include "video/texture_manager.hpp" +inline int next_po2(int val) +{ + int result = 1; + while(result < val) + result *= 2; + + return result; +} + GLLightmap::GLLightmap() : lightmap(), lightmap_width(), @@ -67,7 +76,7 @@ GLLightmap::~GLLightmap() void GLLightmap::start_draw(const Color &ambient_color) { - + glGetFloatv(GL_VIEWPORT, old_viewport); //save viewport glViewport(old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height); glMatrixMode(GL_PROJECTION); @@ -90,7 +99,7 @@ GLLightmap::end_draw() glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, lightmap->get_handle()); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, old_viewport[0], old_viewport[3] - lightmap_height + old_viewport[1], lightmap_width, lightmap_height); - + glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -193,7 +202,7 @@ GLLightmap::draw_surface_part(const DrawingRequest& request) void GLLightmap::draw_gradient(const DrawingRequest& request) { - const GradientRequest* gradientrequest + const GradientRequest* gradientrequest = (GradientRequest*) request.request_data; const Color& top = gradientrequest->top; const Color& bottom = gradientrequest->bottom; @@ -261,7 +270,7 @@ GLLightmap::draw_filled_rect(const DrawingRequest& request) void GLLightmap::get_light(const DrawingRequest& request) const { - const GetLightRequest* getlightrequest + const GetLightRequest* getlightrequest = (GetLightRequest*) request.request_data; float pixels[3]; -- 2.11.0