Skip to content

Commit

Permalink
Refactor|Resources: Cleaned up Sprite resource building
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 18, 2013
1 parent 9176ccf commit 12441fc
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 287 deletions.
5 changes: 3 additions & 2 deletions doomsday/client/client.pro
Expand Up @@ -295,6 +295,7 @@ DENG_HEADERS += \
include/render/biassource.h \
include/render/biassurface.h \
include/render/biastracker.h \
include/render/billboard.h \
include/render/blockmapvisual.h \
include/render/decoration.h \
include/render/drawlist.h \
Expand Down Expand Up @@ -322,7 +323,6 @@ DENG_HEADERS += \
include/render/shadowedge.h \
include/render/sky.h \
include/render/skyfixedge.h \
include/render/sprite.h \
include/render/surfacedecorator.h \
include/render/trianglestripbuilder.h \
include/render/vignette.h \
Expand Down Expand Up @@ -652,6 +652,7 @@ SOURCES += \
src/render/biassource.cpp \
src/render/biassurface.cpp \
src/render/biastracker.cpp \
src/render/billboard.cpp \
src/render/blockmapvisual.cpp \
src/render/decoration.cpp \
src/render/drawlist.cpp \
Expand Down Expand Up @@ -679,7 +680,6 @@ SOURCES += \
src/render/shadowedge.cpp \
src/render/sky.cpp \
src/render/skyfixedge.cpp \
src/render/sprite.cpp \
src/render/surfacedecorator.cpp \
src/render/trianglestripbuilder.cpp \
src/render/vignette.cpp \
Expand Down Expand Up @@ -715,6 +715,7 @@ SOURCES += \
src/resource/pcx.cpp \
src/resource/rawtexture.cpp \
src/resource/resourcesystem.cpp \
src/resource/sprite.cpp \
src/resource/sprites.cpp \
src/resource/texture.cpp \
src/resource/texturemanifest.cpp \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/de_render.h
Expand Up @@ -40,7 +40,7 @@
#include "render/rend_dynlight.h"
#include "render/rendpoly.h"
#include "render/sky.h"
#include "render/sprite.h"
#include "render/billboard.h"
#include "render/vignette.h"
#include "render/vissprite.h"
#include "render/vlight.h"
Expand Down
@@ -1,8 +1,7 @@
/**
* @file render/sprite.h Rendering Map Objects as 2D Sprites.
/** @file billboard.h Rendering billboard "sprites".
*
* @author Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2007-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -19,8 +18,8 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_RENDER_SPRITE_H
#define LIBDENG_RENDER_SPRITE_H
#ifndef DENG_CLIENT_RENDER_BILLBOARD_H
#define DENG_CLIENT_RENDER_BILLBOARD_H

#include "dd_types.h"

Expand Down Expand Up @@ -85,4 +84,4 @@ void Rend_Draw3DPlayerSprites(void);

///@}

#endif /* LIBDENG_RENDER_SPRITE_H */
#endif // DENG_CLIENT_RENDER_BILLBOARD_H
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/sprites.h
Expand Up @@ -23,7 +23,7 @@
#ifndef DENG_RESOURCE_SPRITES_H
#define DENG_RESOURCE_SPRITES_H

#include <de/libdeng1.h>
#include "dd_types.h"
#include <de/String>
#include <QList>

Expand Down
@@ -1,4 +1,4 @@
/** @file sprite.cpp Sprite Renderer.
/** @file billboard.cpp Rendering billboard "sprites".
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -40,7 +40,7 @@

#include "render/vissprite.h"

#include "render/sprite.h"
#include "render/billboard.h"

using namespace de;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_main.cpp
Expand Up @@ -71,7 +71,7 @@
#include "TriangleStripBuilder"
#include "WallEdge"
#include "render/blockmapvisual.h"
#include "render/sprite.h"
#include "render/billboard.h"
#include "render/vissprite.h"

#include "gl/sys_opengl.h"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/models.cpp
Expand Up @@ -50,7 +50,7 @@
# include "render/r_things.h"
#endif
#include "render/rend_model.h"
#include "render/sprite.h"
#include "render/billboard.h"

#include "resource/models.h"

Expand Down
93 changes: 93 additions & 0 deletions doomsday/client/src/resource/sprite.cpp
@@ -0,0 +1,93 @@
/** @file sprite.cpp 3D-Sprite resource.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#include "de_platform.h"
#include "resource/sprites.h"

#ifdef __CLIENT__
# include "MaterialSnapshot"
# include "TextureManifest"

# include "gl/gl_tex.h"
# include "gl/gl_texmanager.h"

# include "Lumobj"
# include "render/billboard.h"
#endif

using namespace de;

Sprite::Sprite()
: _rotate(0)
{
zap(_mats);
zap(_flip);
}

Material *Sprite::material(int rotation, bool *flipX, bool *flipY) const
{
if(flipX) *flipX = false;
if(flipY) *flipY = false;

if(rotation < 0 || rotation >= max_angles)
{
return 0;
}

if(flipX) *flipX = CPP_BOOL(_flip[rotation]);

return _mats[rotation];
}

Material *Sprite::material(angle_t mobjAngle, angle_t angleToEye,
bool noRotation, bool *flipX, bool *flipY) const
{
int rotation = 0; // Use single rotation for all viewing angles (default).

if(!noRotation && _rotate)
{
// Rotation is determined by the relative angle to the viewer.
rotation = (angleToEye - mobjAngle + (unsigned) (ANG45 / 2) * 9) >> 29;
}

return material(rotation, flipX, flipY);
}

#ifdef __CLIENT__
Lumobj *Sprite::generateLumobj() const
{
// Always use rotation zero.
/// @todo We could do better here...
Material *mat = material();
if(!mat) return 0;

// Ensure we have up-to-date information about the material.
MaterialSnapshot const &ms = mat->prepare(Rend_SpriteMaterialSpec());
if(!ms.hasTexture(MTU_PRIMARY)) return 0; // Unloadable texture?
Texture &tex = ms.texture(MTU_PRIMARY).generalCase();

pointlight_analysis_t const *pl = reinterpret_cast<pointlight_analysis_t const *>(ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(Texture::BrightPointAnalysis));
if(!pl) throw Error("Sprite::generateLumobj", QString("Texture \"%1\" has no BrightPointAnalysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri()));

// Apply the auto-calculated color.
return &(new Lumobj(Vector3d(), pl->brightMul, pl->color.rgb))
->setZOffset(-tex.origin().y - pl->originY * ms.height());
}
#endif // __CLIENT__

0 comments on commit 12441fc

Please sign in to comment.