diff --git a/doomsday/engine/engine.pro b/doomsday/engine/engine.pro index 569a157e27..6c5f1b4d4b 100644 --- a/doomsday/engine/engine.pro +++ b/doomsday/engine/engine.pro @@ -297,6 +297,7 @@ DENG_HEADERS += \ include/resource/lumpcache.h \ include/resource/material.h \ include/resource/materials.h \ + include/resource/materialsnapshot.h \ include/resource/materialvariant.h \ include/resource/models.h \ include/resource/patch.h \ @@ -530,7 +531,7 @@ SOURCES += \ src/map/plane.c \ src/map/polyobj.c \ src/map/propertyvalue.cpp \ - src/map/r_world.c \ + src/map/r_world.cpp \ src/map/sector.c \ src/map/sidedef.c \ src/map/surface.c \ @@ -556,14 +557,14 @@ SOURCES += \ src/render/r_things.cpp \ src/render/rend_bias.c \ src/render/rend_clip.cpp \ - src/render/rend_console.c \ + src/render/rend_console.cpp \ src/render/rend_decor.c \ src/render/rend_dynlight.c \ - src/render/rend_fakeradio.c \ + src/render/rend_fakeradio.cpp \ src/render/rend_font.c \ src/render/rend_halo.c \ - src/render/rend_list.c \ - src/render/rend_main.c \ + src/render/rend_list.cpp \ + src/render/rend_main.cpp \ src/render/rend_model.cpp \ src/render/rend_particle.c \ src/render/rend_shadow.c \ @@ -582,6 +583,7 @@ SOURCES += \ src/resource/image.cpp \ src/resource/material.cpp \ src/resource/materialarchive.c \ + src/resource/materialsnapshot.cpp \ src/resource/materials.cpp \ src/resource/materialvariant.cpp \ src/resource/models.cpp \ diff --git a/doomsday/engine/include/gl/gl_texmanager.h b/doomsday/engine/include/gl/gl_texmanager.h index f0f147313e..7e093936d8 100644 --- a/doomsday/engine/include/gl/gl_texmanager.h +++ b/doomsday/engine/include/gl/gl_texmanager.h @@ -129,7 +129,7 @@ void GL_ReleaseTexturesByScheme(char const *schemeName); * Release all textures associated with the specified @a texture. * @param texture Logical Texture. Can be @c NULL, in which case this is a null-op. */ -void GL_ReleaseGLTexturesByTexture(Texture *texture); +void GL_ReleaseGLTexturesByTexture(struct texture_s *texture); /** * Release all textures associated with the specified variant @a texture. @@ -142,7 +142,7 @@ void GL_ReleaseVariantTexture(struct texturevariant_s *texture); * @param texture Logical Texture to process. Can be @c NULL, in which case this is a null-op. * @param spec Specification to match. Comparision mode is exact and not fuzzy. */ -void GL_ReleaseVariantTexturesBySpec(Texture *tex, texturevariantspecification_t *spec); +void GL_ReleaseVariantTexturesBySpec(struct texture_s *tex, texturevariantspecification_t *spec); /// Release all textures associated with the identified colorpalette @a paletteId. void GL_ReleaseTexturesByColorPalette(colorpaletteid_t paletteId); @@ -262,14 +262,14 @@ typedef enum { * * @return GL-name of the prepared texture if successful else @c 0 */ -DGLuint GL_PrepareTexture2(Texture *tex, texturevariantspecification_t *spec, preparetextureresult_t *returnOutcome); -DGLuint GL_PrepareTexture(Texture *tex, texturevariantspecification_t *spec/*, returnOutcome = 0 */); +DGLuint GL_PrepareTexture2(struct texture_s *tex, texturevariantspecification_t *spec, preparetextureresult_t *returnOutcome); +DGLuint GL_PrepareTexture(struct texture_s *tex, texturevariantspecification_t *spec/*, returnOutcome = 0 */); /** * Same as GL_PrepareTexture(2) except for visibility of TextureVariant. */ -struct texturevariant_s *GL_PrepareTextureVariant2(Texture *tex, texturevariantspecification_t *spec, preparetextureresult_t *returnOutcome); -struct texturevariant_s *GL_PrepareTextureVariant(Texture *tex, texturevariantspecification_t *spec/*, returnOutcome = 0 */); +struct texturevariant_s *GL_PrepareTextureVariant2(struct texture_s *tex, texturevariantspecification_t *spec, preparetextureresult_t *returnOutcome); +struct texturevariant_s *GL_PrepareTextureVariant(struct texture_s *tex, texturevariantspecification_t *spec/*, returnOutcome = 0 */); /** * Bind this texture to the currently active texture unit. @@ -310,8 +310,8 @@ DGLuint GL_PrepareLightmap(Uri const *path); DGLuint GL_PrepareLSTexture(lightingtexid_t which); DGLuint GL_PrepareRawTexture(rawtex_t *rawTex); -struct texturevariant_s *GL_PreparePatchTexture2(Texture *tex, int wrapS, int wrapT); -struct texturevariant_s *GL_PreparePatchTexture(Texture *tex); +struct texturevariant_s *GL_PreparePatchTexture2(struct texture_s *tex, int wrapS, int wrapT); +struct texturevariant_s *GL_PreparePatchTexture(struct texture_s *tex); /** * Attempt to locate and prepare a flare texture. diff --git a/doomsday/engine/include/map/polyobj.h b/doomsday/engine/include/map/polyobj.h index 34fb293538..6b1ffe30b9 100644 --- a/doomsday/engine/include/map/polyobj.h +++ b/doomsday/engine/include/map/polyobj.h @@ -32,6 +32,10 @@ DD_BASE_POLYOBJ_ELEMENTS() #define POLYOBJ_SIZE gx.polyobjSize +#ifdef __cplusplus +extern "C" { +#endif + /** * Translate the origin in the map coordinate space. * @@ -87,4 +91,8 @@ boolean Polyobj_GetProperty(const Polyobj* po, setargs_t* args); boolean Polyobj_SetProperty(Polyobj* po, const setargs_t* args); #endif +#ifdef __cplusplus +} // extern "C" +#endif + #endif /// LIBDENG_MAP_POLYOB_H diff --git a/doomsday/engine/include/map/r_world.h b/doomsday/engine/include/map/r_world.h index ad4f2c6ae9..3692d20987 100644 --- a/doomsday/engine/include/map/r_world.h +++ b/doomsday/engine/include/map/r_world.h @@ -51,6 +51,7 @@ extern byte rendSkyLightAuto; // cvar extern float rendLightWallAngle; extern byte rendLightWallAngleSmooth; extern boolean ddMapSetup; +extern boolean firstFrameAfterLoad; // Sky flags. #define SIF_DRAW_SPHERE 0x1 // Always draw the sky sphere. @@ -89,7 +90,12 @@ void R_UpdatePlanes(void); void R_ClearSectorFlags(void); void R_MapInitSurfaceLists(void); -void R_OrderVertices(const LineDef* line, const Sector* sector, Vertex* verts[2]); +/** + * Returns pointers to the line's vertices in such a fashion that @c verts[0] + * is the leftmost vertex and @c verts[1] is the rightmost vertex, when the + * @a line lies at the edge of @a sector. + */ +void R_OrderVertices(LineDef const *line, Sector const *sector, Vertex *verts[2]); /** * Determine the map space Z coordinates of a wall section. diff --git a/doomsday/engine/include/render/r_draw.h b/doomsday/engine/include/render/r_draw.h index 0f233efbf1..ea19e04ec9 100644 --- a/doomsday/engine/include/render/r_draw.h +++ b/doomsday/engine/include/render/r_draw.h @@ -39,11 +39,11 @@ void R_SetBorderGfx(Uri const *const *paths); */ void R_DrawViewBorder(void); -void R_DrawPatch(Texture *texture, int x, int y); -void R_DrawPatch2(Texture *texture, int x, int y, int w, int h); -void R_DrawPatch3(Texture *texture, int x, int y, int w, int h, boolean useOffsets); +void R_DrawPatch(struct texture_s *texture, int x, int y); +void R_DrawPatch2(struct texture_s *texture, int x, int y, int w, int h); +void R_DrawPatch3(struct texture_s *texture, int x, int y, int w, int h, boolean useOffsets); -void R_DrawPatchTiled(Texture *texture, int x, int y, int w, int h, int wrapS, int wrapT); +void R_DrawPatchTiled(struct texture_s *texture, int x, int y, int w, int h, int wrapS, int wrapT); #ifdef __cplusplus } // extern "C" diff --git a/doomsday/engine/include/render/rend_dynlight.h b/doomsday/engine/include/render/rend_dynlight.h index 1cc1bb8d52..4a75c927d4 100644 --- a/doomsday/engine/include/render/rend_dynlight.h +++ b/doomsday/engine/include/render/rend_dynlight.h @@ -28,30 +28,38 @@ /// Paramaters for Rend_RenderLightProjections (POD). typedef struct { uint lastIdx; - const rvertex_t* rvertices; + rvertex_t const *rvertices; uint numVertices, realNumVertices; - const coord_t* texTL, *texBR; + coord_t const *texTL, *texBR; boolean isWall; struct { struct { - walldivnode_t* firstDiv; + walldivnode_t *firstDiv; uint divCount; } left; struct { - walldivnode_t* firstDiv; + walldivnode_t *firstDiv; uint divCount; } right; } wall; } renderlightprojectionparams_t; +#ifdef __cplusplus +extern "C" { +#endif + /** * Render all dynlights in projection list @a listIdx according to @a paramaters * writing them to the renderering lists for the current frame. * - * \note If multi-texturing is being used for the first light; it is skipped. + * @note If multi-texturing is being used for the first light; it is skipped. * * @return Number of lights rendered. */ -uint Rend_RenderLightProjections(uint listIdx, renderlightprojectionparams_t* paramaters); +uint Rend_RenderLightProjections(uint listIdx, renderlightprojectionparams_t *paramaters); + +#ifdef __cplusplus +} // extern "C" +#endif #endif /* LIBDENG_RENDER_DYNLIGHT_H */ diff --git a/doomsday/engine/include/render/rend_main.h b/doomsday/engine/include/render/rend_main.h index 42af0ad351..6598eb78cf 100644 --- a/doomsday/engine/include/render/rend_main.h +++ b/doomsday/engine/include/render/rend_main.h @@ -73,6 +73,9 @@ extern int shadowMaxDistance; extern int useShinySurfaces; +extern byte devRendSkyAlways; +extern byte freezeRLs; + void Rend_Register(void); void Rend_Init(void); @@ -105,6 +108,8 @@ void Rend_CalcLightModRange(void); */ uint Rend_NumFanVerticesForBspLeaf(BspLeaf* bspLeaf); +void R_DrawLightRange(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/doomsday/engine/include/render/rend_shadow.h b/doomsday/engine/include/render/rend_shadow.h index 845e11d401..82e0d3b016 100644 --- a/doomsday/engine/include/render/rend_shadow.h +++ b/doomsday/engine/include/render/rend_shadow.h @@ -25,6 +25,10 @@ #ifndef LIBDENG_RENDER_MOBJ_SHADOW_H #define LIBDENG_RENDER_MOBJ_SHADOW_H +#ifdef __cplusplus +extern "C" { +#endif + /** * This value defines the offset from the shadowed surface applied to * shadows rendered with the simple drop-to-highest-floor method. @@ -67,4 +71,8 @@ typedef struct { */ void Rend_RenderShadowProjections(uint listIdx, rendershadowprojectionparams_t* paramaters); +#ifdef __cplusplus +} // extern "C" +#endif + #endif /* LIBDENG_RENDER_MOBJ_SHADOW_H */ diff --git a/doomsday/engine/include/resource/bitmapfont.h b/doomsday/engine/include/resource/bitmapfont.h index a47bab317e..7fb8f16472 100644 --- a/doomsday/engine/include/resource/bitmapfont.h +++ b/doomsday/engine/include/resource/bitmapfont.h @@ -111,7 +111,7 @@ void BitmapCompositeFont_SetDefinition(font_t* font, struct ded_compositefont_s* patchid_t BitmapCompositeFont_CharPatch(font_t* font, unsigned char ch); void BitmapCompositeFont_CharSetPatch(font_t* font, unsigned char ch, const char* patchName); -struct texturevariant_s* BitmapCompositeFont_CharTexture(font_t* font, unsigned char ch); +struct texturevariant_s *BitmapCompositeFont_CharTexture(font_t* font, unsigned char ch); void BitmapCompositeFont_ReleaseTextures(font_t* font); uint8_t BitmapCompositeFont_CharBorder(font_t* font, unsigned char chr); diff --git a/doomsday/engine/include/resource/materials.h b/doomsday/engine/include/resource/materials.h index d934b9c58d..b9b4137836 100644 --- a/doomsday/engine/include/resource/materials.h +++ b/doomsday/engine/include/resource/materials.h @@ -110,6 +110,8 @@ AutoStr* Materials_ComposePath(materialid_t materialId); /// @return Unique name/path-to this material. Must be destroyed with Uri_Delete(). Uri* Materials_ComposeUri(materialid_t materialId); +void Materials_UpdateTextureLinks(materialid_t materialId); + /** * Update @a material according to the supplied definition @a def. * To be called after an engine update/reset. diff --git a/doomsday/engine/include/resource/materialsnapshot.h b/doomsday/engine/include/resource/materialsnapshot.h new file mode 100644 index 0000000000..29dd056b2e --- /dev/null +++ b/doomsday/engine/include/resource/materialsnapshot.h @@ -0,0 +1,123 @@ +/** @file materialsnapshot.h Material Snapshot. + * + * @author Copyright © 2011-2012 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 + */ + +#ifndef LIBDENG_RESOURCE_MATERIALSNAPSHOT_H +#define LIBDENG_RESOURCE_MATERIALSNAPSHOT_H + +// Material texture unit idents: +enum { + MTU_PRIMARY, + MTU_DETAIL, + MTU_REFLECTION, + MTU_REFLECTION_MASK, + NUM_MATERIAL_TEXTURE_UNITS +}; + +#ifdef __cplusplus + +#include +#include +#include "de/vector1.h" +#include "resource/materialvariant.h" +#include "resource/texturevariant.h" +#include "render/rendpoly.h" + +namespace de { + + /** + * @ingroup resource + */ + class MaterialSnapshot + { + public: + /// Invalid texture unit referenced. @ingroup errors + DENG2_ERROR(InvalidUnitError); + + public: + /** + * Construct a new material snapshot instance. + * @param material Material to capture to produce the snapshot. + */ + MaterialSnapshot(MaterialVariant &material); + + ~MaterialSnapshot(); + + /** + * Returns the material variant of the material snapshot. + */ + MaterialVariant &material() const; + + /** + * Returns the dimensions in the world coordinate space for the material snapshot. + */ + QSize const &dimensions() const; + + /** + * Returns @c true if the material snapshot is completely opaque. + */ + bool isOpaque() const; + + /** + * Returns the glow strength multiplier for the material snapshot. + */ + float glowStrength() const; + + /** + * Returns the minimum ambient light color for the material snapshot. + */ + vec3f_t const &reflectionMinColor() const; + + /** + * Returns @c true if a texture with @a index is set for the material snapshot. + */ + bool hasTexture(int index) const; + + /** + * Lookup a material snapshot texture unit texture by index. + * + * @param index Index of the texture unit to lookup. + * @return The texture associated with the texture unit. + */ + TextureVariant &texture(int index) const; + + /** + * Lookup a material snapshot texture unit by index. + * + * @param index Index of the texture unit to lookup. + * @return The associated texture unit. + */ + rtexmapunit_t const &unit(int index) const; + + /** + * Prepare all textures and update property values. + */ + void update(); + + private: + struct Instance; + Instance *d; + }; + +} // namespace de + +struct materialsnapshot_s; // The material snapshot instance (opaque). + +#endif + +#endif /* LIBDENG_RESOURCE_MATERIALSNAPSHOT_H */ diff --git a/doomsday/engine/include/resource/materialvariant.h b/doomsday/engine/include/resource/materialvariant.h index 551bfd2873..bb713d13ca 100644 --- a/doomsday/engine/include/resource/materialvariant.h +++ b/doomsday/engine/include/resource/materialvariant.h @@ -1,8 +1,6 @@ -/** - * @file materialvariant.h - * Logical material variant. @ingroup resource +/** @file materialvariant.h Logical Material Variant. * - * @authors Copyright © 2012 Daniel Swanson + * @authors Copyright © 2011-2012 Daniel Swanson * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -35,54 +33,14 @@ struct materialvariant_s; typedef struct materialvariantspecification_s { materialcontext_t context; - struct texturevariantspecification_s* primarySpec; + struct texturevariantspecification_s *primarySpec; } materialvariantspecification_t; #define MATERIALVARIANT_MAXLAYERS DDMAX_MATERIAL_LAYERS -// Material texture unit idents: -enum { - MTU_PRIMARY, - MTU_DETAIL, - MTU_REFLECTION, - MTU_REFLECTION_MASK, - NUM_MATERIAL_TEXTURE_UNITS -}; - -typedef struct materialsnapshot_s { - /// Variant Material used to derive this snapshot. - struct materialvariant_s* material; - - /// @c true= this material is entirely opaque. - boolean isOpaque; - - /// Size in world units. - Size2Raw size; - - /// Glow strength multiplier. - float glowing; - - /// Minimum sector light color for shiny texturing. - vec3f_t shinyMinColor; - - /// Textures used on each texture unit. - struct texturevariant_s* textures[NUM_MATERIAL_TEXTURE_UNITS]; - - /// Texture unit configuration. - rtexmapunit_t units[NUM_MATERIAL_TEXTURE_UNITS]; -} materialsnapshot_t; - -// Helper macros for accessing MaterialSnapshot data elements. -#define MST(ms, u) ((ms)->textures[u]) -#define MSU(ms, u) ((ms)->units[u]) - -#define MSU_texture(ms, u) (MST(ms, u)? TextureVariant_GeneralCase(MST(ms, u)) : NULL) -#define MSU_gltexture(ms, u) (MST(ms, u)? TextureVariant_GLName(MST(ms, u)) : 0) -#define MSU_texturespec(ms, u) (MST(ms, u)? TextureVariant_Spec(MST(ms, u)) : NULL) - typedef struct materialvariant_layer_s { int stage; // -1 => layer not in use. - struct texture_s* texture; + struct texture_s *texture; float texOrigin[2]; /// Origin of the texture in material-space. float glow; short tics; @@ -93,13 +51,19 @@ typedef struct materialvariant_layer_s { #endif #ifdef __cplusplus + namespace de { +class MaterialSnapshot; + +/** + * @ingroup resource + */ class MaterialVariant { public: - MaterialVariant(material_t& generalCase, const materialvariantspecification_t& spec, - const ded_material_t& def); + MaterialVariant(material_t &generalCase, materialvariantspecification_t const &spec, + ded_material_t const &def); ~MaterialVariant(); /** @@ -114,31 +78,31 @@ class MaterialVariant void resetAnim(); /// @return Material from which this variant is derived. - material_t* generalCase() const { return material; } + material_t *generalCase() const { return material; } /// @return MaterialVariantSpecification from which this variant is derived. - const materialvariantspecification_t* spec() const { return varSpec; } + materialvariantspecification_t const *spec() const { return varSpec; } /** * Retrieve a handle for a staged animation layer form this variant. * @param layer Index of the layer to retrieve. * @return MaterialVariantLayer for the specified layer index. */ - const materialvariant_layer_t* layer(int layer); + materialvariant_layer_t const *layer(int layer); /** * Attach MaterialSnapshot data to this. MaterialVariant is given ownership of @a materialSnapshot. * @return Same as @a materialSnapshot for caller convenience. */ - materialsnapshot_t& attachSnapshot(materialsnapshot_t& materialSnapshot); + MaterialSnapshot &attachSnapshot(MaterialSnapshot &snapshot); /** * Detach MaterialSnapshot data from this. Ownership of the data is relinquished to the caller. */ - materialsnapshot_t* detachSnapshot(); + MaterialSnapshot *detachSnapshot(); /// @return MaterialSnapshot data associated with this. - materialsnapshot_t* snapshot() const { return snapshot_; } + MaterialSnapshot *snapshot() const { return snapshot_; } /// @return Frame count when the snapshot was last prepared/updated. int snapshotPrepareFrame() const { return snapshotPrepareFrame_; } @@ -150,10 +114,10 @@ class MaterialVariant void setSnapshotPrepareFrame(int frame); /// @return Translated 'next' (or target) MaterialVariant if set, else this. - MaterialVariant* translationNext(); + MaterialVariant *translationNext(); /// @return Translated 'current' MaterialVariant if set, else this. - MaterialVariant* translationCurrent(); + MaterialVariant *translationCurrent(); /// @return Translation position [0..1] float translationPoint(); @@ -164,7 +128,7 @@ class MaterialVariant * @param current Translated 'current' MaterialVariant. * @param next Translated 'next' (or target) MaterialVariant. */ - void setTranslation(MaterialVariant* current, MaterialVariant* next); + void setTranslation(MaterialVariant *current, MaterialVariant *next); /** * Change the translation point for this variant. @@ -174,19 +138,19 @@ class MaterialVariant private: /// Superior Material of which this is a derivative. - material_t* material; + material_t *material; /// For "smoothed" Material animation: bool hasTranslation; - MaterialVariant* current; - MaterialVariant* next; + MaterialVariant *current; + MaterialVariant *next; float inter; /// Specification used to derive this variant. - const materialvariantspecification_t* varSpec; + materialvariantspecification_t const *varSpec; /// Cached copy of current state if any. - materialsnapshot_t* snapshot_; + MaterialSnapshot *snapshot_; /// Frame count when the snapshot was last prepared/updated. int snapshotPrepareFrame_; @@ -218,9 +182,9 @@ material_t* MaterialVariant_GeneralCase(MaterialVariant* mat); const materialvariantspecification_t* MaterialVariant_Spec(const MaterialVariant* mat); const materialvariant_layer_t* MaterialVariant_Layer(MaterialVariant* mat, int layer); -materialsnapshot_t* MaterialVariant_AttachSnapshot(MaterialVariant* mat, materialsnapshot_t* materialSnapshot); -materialsnapshot_t* MaterialVariant_DetachSnapshot(MaterialVariant* mat); -materialsnapshot_t* MaterialVariant_Snapshot(const MaterialVariant* mat); +struct materialsnapshot_s *MaterialVariant_AttachSnapshot(MaterialVariant* mat, struct materialsnapshot_s *materialSnapshot); +struct materialsnapshot_s *MaterialVariant_DetachSnapshot(MaterialVariant* mat); +struct materialsnapshot_s *MaterialVariant_Snapshot(const MaterialVariant* mat); int MaterialVariant_SnapshotPrepareFrame(const MaterialVariant* mat); void MaterialVariant_SetSnapshotPrepareFrame(MaterialVariant* mat, int frame); diff --git a/doomsday/engine/include/resource/r_data.h b/doomsday/engine/include/resource/r_data.h index 589ae0bf90..2db128f1bb 100644 --- a/doomsday/engine/include/resource/r_data.h +++ b/doomsday/engine/include/resource/r_data.h @@ -28,9 +28,8 @@ #include "dd_def.h" #include "thinker.h" #include "def_data.h" -#include "textures.h" +#include "resource/textures.h" -struct texture_s; struct font_s; /** @@ -89,8 +88,8 @@ AutoStr *R_ComposePatchPath(patchid_t id); #endif #ifdef __cplusplus -struct texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, QSize const &dimensions); -struct texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri); +de::Texture *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, QSize const &dimensions); +de::Texture *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri); #endif #endif /// LIBDENG_REFRESH_DATA_H diff --git a/doomsday/engine/include/resource/texture.h b/doomsday/engine/include/resource/texture.h index 7fe3ee9543..fab5a16e66 100644 --- a/doomsday/engine/include/resource/texture.h +++ b/doomsday/engine/include/resource/texture.h @@ -58,208 +58,169 @@ typedef enum { namespace de { -class TextureManifest; + class TextureManifest; -/** - * Logical texture object. - * @ingroup resource - */ -class Texture -{ -public: /** - * Classification/processing flags + * Logical texture object. + * @ingroup resource */ - enum Flag + class Texture { - /// Texture is not to be drawn. - NoDraw = 0x1, - - /// Texture is "custom" (i.e., not an original game resource). - Custom = 0x2, - - /// Apply the monochrome filter to the processed image. - Monochrome = 0x4, - - /// Apply the upscaleAndSharpen filter to the processed image. - UpscaleAndSharpen = 0x8 + public: + /** + * Classification/processing flags + */ + enum Flag + { + /// Texture is not to be drawn. + NoDraw = 0x1, + + /// Texture is "custom" (i.e., not an original game resource). + Custom = 0x2, + + /// Apply the monochrome filter to the processed image. + Monochrome = 0x4, + + /// Apply the upscaleAndSharpen filter to the processed image. + UpscaleAndSharpen = 0x8 + }; + Q_DECLARE_FLAGS(Flags, Flag) + + typedef std::list Variants; + + public: + /** + * @param manifest Manifest derived to yield the texture. + * @param userData User data to associate with the resultant texture. + */ + Texture(TextureManifest &manifest, void *userData = 0); + + ~Texture(); + + /// @return Provides access to the classification/processing flags. + Flags const &flags() const; + + /// @return Provides access to the classification/processing flags. + Flags &flags(); + + /** + * Returns the TextureManifest derived to yield the texture. + */ + TextureManifest &manifest() const; + + /** + * Retrieve the value of the associated user data pointer. + * @return Associated data pointer value. + */ + void *userDataPointer() const; + + /** + * Set the user data pointer value. Ownership of the data is not given to + * this instance. + * + * @note If already set the old value will be replaced (so if it points + * to some dynamically constructed data/resource it is the caller's + * responsibility to release it beforehand). + * + * @param userData User data pointer value. + */ + void setUserDataPointer(void *userData); + + /** + * Add a new prepared variant to the list of resources for this Texture. + * Texture takes ownership of the variant. + * + * @param variant Variant instance to add to the resource list. + */ + TextureVariant &addVariant(TextureVariant &variant); + + /// @return Number of variants for the texture. + uint variantCount() const; + + /// Destroy all analyses for the texture. + void clearAnalyses(); + + /// Destroy all prepared variants for the texture. + void clearVariants(); + + /** + * Retrieve the value of an identified @a analysis data pointer. + * @return Associated data pointer value. + **/ + void *analysisDataPointer(texture_analysisid_t analysis) const; + + /** + * Set the value of an identified @a analysis data pointer. Ownership of + * the data is not given to this instance. + * + * @note If already set the old value will be replaced (so if it points + * to some dynamically constructed data/resource it is the caller's + * responsibility to release it beforehand). + * + * @param analysis Identifier of the data being attached. + * @param data Data to be attached. + */ + void setAnalysisDataPointer(texture_analysisid_t analysis, void *data); + + /** + * Returns the world width of the texture in map coordinate space units. + */ + int width() const; + + /** + * Returns the world height of the texture in map coordinate space units. + */ + int height() const; + + /** + * Returns the world dimensions [width, height] of the texture in map + * coordinate space units. + */ + QSize const &dimensions() const; + + /** + * Change the world width of the texture. + * @param newWidth New width in map coordinate space units. + */ + void setWidth(int newWidth); + + /** + * Change the world height of the texture. + * @param newHeight New height in map coordinate space units. + */ + void setHeight(int newHeight); + + /** + * Change the world dimensions of the texture. + * @param newDimensions New dimensions [width, height] in map coordinate space units. + */ + void setDimensions(QSize const &newDimensions); + + /** + * Returns the world origin offset of texture in map coordinate space units. + */ + QPoint const &origin() const; + + /** + * Change the world origin offset of the texture. + * @param newOrigin New origin in map coordinate space units. + */ + void setOrigin(QPoint const &newOrigin); + + /** + * Provides access to the list of variant textures for efficent traversals. + */ + Variants const &variantList() const; + + private: + struct Instance; + Instance *d; }; - Q_DECLARE_FLAGS(Flags, Flag) - - typedef std::list Variants; - -public: - /** - * @param manifest Manifest derived to yield the texture. - * @param userData User data to associate with the resultant texture. - */ - Texture(TextureManifest &manifest, void *userData = 0); - - ~Texture(); - - /// @return Provides access to the classification/processing flags. - Flags const &flags() const; - - /// @return Provides access to the classification/processing flags. - Flags &flags(); - - /** - * Returns the TextureManifest derived to yield the texture. - */ - TextureManifest &manifest() const; - - /** - * Retrieve the value of the associated user data pointer. - * @return Associated data pointer value. - */ - void *userDataPointer() const; - - /** - * Set the user data pointer value. Ownership of the data is not given to - * this instance. - * - * @note If already set the old value will be replaced (so if it points - * to some dynamically constructed data/resource it is the caller's - * responsibility to release it beforehand). - * - * @param userData User data pointer value. - */ - void setUserDataPointer(void *userData); - - /** - * Add a new prepared variant to the list of resources for this Texture. - * Texture takes ownership of the variant. - * - * @param variant Variant instance to add to the resource list. - */ - TextureVariant &addVariant(TextureVariant &variant); - - /// @return Number of variants for the texture. - uint variantCount() const; - - /// Destroy all analyses for the texture. - void clearAnalyses(); - - /// Destroy all prepared variants for the texture. - void clearVariants(); - - /** - * Retrieve the value of an identified @a analysis data pointer. - * @return Associated data pointer value. - **/ - void *analysisDataPointer(texture_analysisid_t analysis) const; - - /** - * Set the value of an identified @a analysis data pointer. Ownership of - * the data is not given to this instance. - * - * @note If already set the old value will be replaced (so if it points - * to some dynamically constructed data/resource it is the caller's - * responsibility to release it beforehand). - * - * @param analysis Identifier of the data being attached. - * @param data Data to be attached. - */ - void setAnalysisDataPointer(texture_analysisid_t analysis, void *data); - - /** - * Returns the world width of the texture in map coordinate space units. - */ - int width() const; - - /** - * Returns the world height of the texture in map coordinate space units. - */ - int height() const; - - /** - * Returns the world dimensions [width, height] of the texture in map - * coordinate space units. - */ - QSize const &dimensions() const; - - /** - * Change the world width of the texture. - * @param newWidth New width in map coordinate space units. - */ - void setWidth(int newWidth); - - /** - * Change the world height of the texture. - * @param newHeight New height in map coordinate space units. - */ - void setHeight(int newHeight); - - /** - * Change the world dimensions of the texture. - * @param newDimensions New dimensions [width, height] in map coordinate space units. - */ - void setDimensions(QSize const &newDimensions); - - /** - * Returns the world origin offset of texture in map coordinate space units. - */ - QPoint const &origin() const; - - /** - * Change the world origin offset of the texture. - * @param newOrigin New origin in map coordinate space units. - */ - void setOrigin(QPoint const &newOrigin); - - /** - * Provides access to the list of variant textures for efficent traversals. - */ - Variants const &variantList() const; - -private: - struct Instance; - Instance *d; -}; } // namespace de -extern "C" { #endif // __cplusplus -/** - * C wrapper API: - */ - struct texture_s; // The texture instance (opaque). -typedef struct texture_s Texture; - -void* Texture_UserDataPointer(Texture const *tex); -void Texture_SetUserDataPointer(Texture *tex, void *userData); - -void Texture_ClearVariants(Texture *tex); -uint Texture_VariantCount(Texture const *tex); -struct texturevariant_s *Texture_AddVariant(Texture *tex, struct texturevariant_s *variant); - -void* Texture_AnalysisDataPointer(Texture const *tex, texture_analysisid_t analysis); -void Texture_SetAnalysisDataPointer(Texture *tex, texture_analysisid_t analysis, void *data); - -int Texture_Width(Texture const *tex); -int Texture_Height(Texture const *tex); -void Texture_SetWidth(Texture *tex, int width); -void Texture_SetHeight(Texture *tex, int height); - -/** - * Iterate over all derived TextureVariants, making a callback for each. - * Iteration ends once all variants have been visited, or immediately upon - * a callback returning non-zero. - * - * @param tex Texture instance. - * @param callback Callback to make for each processed variant. - * @param parameters Passed to the callback. - * - * @return @c 0 iff iteration completed wholly. - */ -int Texture_IterateVariants(Texture *tex, - int (*callback)(struct texturevariant_s *instance, void *parameters), void *parameters); - -#ifdef __cplusplus -} // extern "C" -#endif #endif /// LIBDENG_RESOURCE_TEXTURE_H diff --git a/doomsday/engine/include/resource/texturevariant.h b/doomsday/engine/include/resource/texturevariant.h index 7ca9cc3df3..35d96a14a5 100644 --- a/doomsday/engine/include/resource/texturevariant.h +++ b/doomsday/engine/include/resource/texturevariant.h @@ -1,8 +1,6 @@ -/** - * @file texture.h - * Logical texture variant. @ingroup resource +/** @file texturevariant.h Logical Texture Variant. * - * @authors Copyright © 2012 Daniel Swanson + * @authors Copyright © 2011-2012 Daniel Swanson * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -30,121 +28,89 @@ namespace de { -class Texture; + class Texture; -class TextureVariant -{ -private: - enum Flag - { - /// Texture contains alpha. - Masked = 0x1, - - /// Texture has been uploaded to GL. - Uploaded = 0x2 - }; - Q_DECLARE_FLAGS(Flags, Flag) - -public: /** - * @param generalCase Texture from which this variant is derived. - * @param spec Specification used to derive this variant. - * Ownership is NOT given to the resultant TextureVariant - * @param source Source of this variant. + * @ingroup resource */ - TextureVariant(Texture &generalCase, texturevariantspecification_t &spec, - TexSource source = TEXS_NONE); - - /// @return Superior Texture of which this is a derivative. - Texture &generalCase() const { return texture; } - - /// @return Source of this variant. - TexSource source() const { return texSource; } - - /** - * Change the source of this variant. - * @param newSource New TextureSource. - */ - void setSource(TexSource newSource); - - /// @return TextureVariantSpecification used to derive this variant. - texturevariantspecification_t *spec() const { return varSpec; } - - bool isMasked() const { return !!(flags & Masked); } - - void flagMasked(bool yes); - - bool isUploaded() const { return !!(flags & Uploaded); } - - void flagUploaded(bool yes); - - bool isPrepared() const; + class TextureVariant + { + private: + enum Flag + { + /// Texture contains alpha. + Masked = 0x1, - void coords(float *s, float *t) const; - void setCoords(float s, float t); + /// Texture has been uploaded to GL. + Uploaded = 0x2 + }; + Q_DECLARE_FLAGS(Flags, Flag) - uint glName() const { return glTexName; } + public: + /** + * @param generalCase Texture from which this variant is derived. + * @param spec Specification used to derive this variant. + * Ownership is NOT given to the resultant TextureVariant + * @param source Source of this variant. + */ + TextureVariant(Texture &generalCase, texturevariantspecification_t &spec, + TexSource source = TEXS_NONE); - void setGLName(uint glName); + /// @return Superior Texture of which this is a derivative. + Texture &generalCase() const { return texture; } -private: - /// Superior Texture of which this is a derivative. - Texture &texture; + /// @return Source of this variant. + TexSource source() const { return texSource; } - /// Source of this texture. - TexSource texSource; + /** + * Change the source of this variant. + * @param newSource New TextureSource. + */ + void setSource(TexSource newSource); - Flags flags; + /// @return TextureVariantSpecification used to derive this variant. + texturevariantspecification_t *spec() const { return varSpec; } - /// Name of the associated GL texture object. - uint glTexName; + bool isMasked() const { return !!(flags & Masked); } - /// Prepared coordinates for the bottom right of the texture minus border. - float s, t; + void flagMasked(bool yes); - /// Specification used to derive this variant. - texturevariantspecification_t *varSpec; -}; + bool isUploaded() const { return !!(flags & Uploaded); } -} // namespace de + void flagUploaded(bool yes); -extern "C" { -#endif + bool isPrepared() const; -/** - * C wrapper API: - */ -struct texture_s; + void coords(float *s, float *t) const; + void setCoords(float s, float t); -struct texturevariant_s; // The texturevariant instance (opaque). -typedef struct texturevariant_s TextureVariant; + uint glName() const { return glTexName; } -TextureVariant *TextureVariant_New(struct texture_s *generalCase, texturevariantspecification_t *spec, TexSource source); -void TextureVariant_Delete(TextureVariant *tex); + void setGLName(uint glName); -struct texture_s *TextureVariant_GeneralCase(TextureVariant const *tex); + private: + /// Superior Texture of which this is a derivative. + Texture &texture; -TexSource TextureVariant_Source(TextureVariant const *tex); -void TextureVariant_SetSource(TextureVariant *tex, TexSource source); + /// Source of this texture. + TexSource texSource; -texturevariantspecification_t *TextureVariant_Spec(TextureVariant const *tex); + Flags flags; -boolean TextureVariant_IsMasked(TextureVariant const *tex); -void TextureVariant_FlagMasked(TextureVariant *tex, boolean yes); + /// Name of the associated GL texture object. + uint glTexName; -boolean TextureVariant_IsUploaded(TextureVariant const *tex); -void TextureVariant_FlagUploaded(TextureVariant *tex, boolean yes); + /// Prepared coordinates for the bottom right of the texture minus border. + float s, t; -boolean TextureVariant_IsPrepared(TextureVariant const *tex); + /// Specification used to derive this variant. + texturevariantspecification_t *varSpec; + }; -void TextureVariant_Coords(TextureVariant const *tex, float *s, float *t); -void TextureVariant_SetCoords(TextureVariant *tex, float s, float t); +} // namespace de -uint TextureVariant_GLName(TextureVariant const *tex); -void TextureVariant_SetGLName(TextureVariant *tex, uint glName); +#endif // __cplusplus -#ifdef __cplusplus -} // extern "C" -#endif +struct texturevariant_s; // The texture variant instance (opaque). #endif /* LIBDENG_RESOURCE_TEXTUREVARIANT_H */ diff --git a/doomsday/engine/src/gl/dgl_common.cpp b/doomsday/engine/src/gl/dgl_common.cpp index eac6b7479a..fa7dcc60e1 100644 --- a/doomsday/engine/src/gl/dgl_common.cpp +++ b/doomsday/engine/src/gl/dgl_common.cpp @@ -723,7 +723,7 @@ void DGL_SetPatch(patchid_t id, DGLint wrapS, DGLint wrapT) { try { - Texture *tex = reinterpret_cast(App_Textures()->scheme("Patches").findByUniqueId(id).texture()); + struct texture_s *tex = reinterpret_cast(App_Textures()->scheme("Patches").findByUniqueId(id).texture()); if(!tex) return; GL_BindTexture(GL_PreparePatchTexture2(tex, DGL_ToGLWrapCap(wrapS), DGL_ToGLWrapCap(wrapT))); diff --git a/doomsday/engine/src/gl/gl_main.cpp b/doomsday/engine/src/gl/gl_main.cpp index 1cd821355c..b4bc41766f 100644 --- a/doomsday/engine/src/gl/gl_main.cpp +++ b/doomsday/engine/src/gl/gl_main.cpp @@ -1,5 +1,4 @@ -/** - * @file gl_main.cpp GL-Graphics Subsystem +/** @file gl_main.cpp GL-Graphics Subsystem * @ingroup gl * * @author Copyright © 2003-2012 Jaakko Keränen @@ -38,8 +37,9 @@ #include "gl/texturecontent.h" #include "resource/colorpalettes.h" -#include "resource/texturevariant.h" +#include "resource/materialsnapshot.h" #include "resource/materialvariant.h" +#include "resource/texturevariant.h" #include "ui/displaymode.h" D_CMD(Fog); @@ -737,15 +737,13 @@ int GL_GetTexAnisoMul(int level) void GL_SetMaterialUI2(material_t* mat, int wrapS, int wrapT) { - const materialvariantspecification_t* spec; - const materialsnapshot_t* ms; - if(!mat) return; // @todo we need a "NULL material". - spec = Materials_VariantSpecificationForContext(MC_UI, 0, 1, 0, 0, - wrapS, wrapT, 0, 1, 0, false, false, false, false); - ms = Materials_Prepare(mat, spec, true); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + materialvariantspecification_t const *spec = + Materials_VariantSpecificationForContext(MC_UI, 0, 1, 0, 0, wrapS, wrapT, + 0, 1, 0, false, false, false, false); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); } void GL_SetMaterialUI(material_t* mat) @@ -755,15 +753,13 @@ void GL_SetMaterialUI(material_t* mat) void GL_SetPSprite(material_t* mat, int tClass, int tMap) { - const materialvariantspecification_t* spec; - const materialsnapshot_t* ms; - if(!mat) return; // @todo we need a "NULL material". - spec = Materials_VariantSpecificationForContext(MC_PSPRITE, 0, 1, tClass, - tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 1, 0, false, true, true, false); - ms = Materials_Prepare(mat, spec, true); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + materialvariantspecification_t const *spec = + Materials_VariantSpecificationForContext(MC_PSPRITE, 0, 1, tClass, tMap, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, + 0, 1, 0, false, true, true, false); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); } void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT) diff --git a/doomsday/engine/src/gl/gl_texmanager.cpp b/doomsday/engine/src/gl/gl_texmanager.cpp index 4fcba0f057..6dac4078d6 100644 --- a/doomsday/engine/src/gl/gl_texmanager.cpp +++ b/doomsday/engine/src/gl/gl_texmanager.cpp @@ -3222,7 +3222,7 @@ texturevariant_s *GL_PrepareTextureVariant(texture_s *tex, texturevariantspecifi DGLuint GL_PrepareTexture2(struct texture_s *tex, texturevariantspecification_t *spec, preparetextureresult_t *returnOutcome) { - de::TextureVariant const *variant = reinterpret_cast(GL_PrepareTextureVariant2(tex, spec, returnOutcome)); + de::TextureVariant const *variant = reinterpret_cast(GL_PrepareTextureVariant2(tex, spec, returnOutcome)); if(!variant) return 0; return variant->glName(); } @@ -3232,21 +3232,21 @@ DGLuint GL_PrepareTexture(struct texture_s *tex, texturevariantspecification_t * return GL_PrepareTexture2(tex, spec, 0); } -void GL_BindTexture(texturevariant_s *tex) +void GL_BindTexture(texturevariant_s *_tex) { texturevariantspecification_t *spec = 0; if(BusyMode_InWorkerThread()) return; + de::TextureVariant *tex = reinterpret_cast(_tex); if(tex) { - de::TextureVariant *variant = reinterpret_cast(tex); - spec = variant->spec(); + spec = tex->spec(); // Ensure we've prepared this. - if(!variant->isPrepared()) + if(!tex->isPrepared()) { - de::TextureVariant **hndl = &variant; - if(!tryLoadImageAndPrepareVariant(variant->generalCase(), spec, hndl)) + de::TextureVariant **hndl = &tex; + if(!tryLoadImageAndPrepareVariant(tex->generalCase(), spec, hndl)) { tex = 0; } @@ -3263,7 +3263,7 @@ void GL_BindTexture(texturevariant_s *tex) LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); - glBindTexture(GL_TEXTURE_2D, TextureVariant_GLName(tex)); + glBindTexture(GL_TEXTURE_2D, tex->glName()); Sys_GLCheckError(); // Apply dynamic adjustments to the GL texture state according to our spec. diff --git a/doomsday/engine/src/map/r_world.c b/doomsday/engine/src/map/r_world.cpp similarity index 70% rename from doomsday/engine/src/map/r_world.c rename to doomsday/engine/src/map/r_world.cpp index 6b9447bea9..b0ba738176 100644 --- a/doomsday/engine/src/map/r_world.c +++ b/doomsday/engine/src/map/r_world.cpp @@ -1,36 +1,26 @@ -/**\file r_world.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file r_world.cpp World Setup/Refresh. * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 + * 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 */ -/** - * World Setup and Refresh. - */ - -// HEADER FILES ------------------------------------------------------------ - -#include -#include -#include +#include +#include +#include #include "de_base.h" #include "de_console.h" @@ -42,68 +32,37 @@ #include "de_audio.h" #include "de_misc.h" +#include "resource/materialsnapshot.h" #include "resource/materialvariant.h" -// MACROS ------------------------------------------------------------------ - // $smoothplane: Maximum speed for a smoothed plane. #define MAX_SMOOTH_PLANE_MOVE (64) // $smoothmatoffset: Maximum speed for a smoothed material offset. #define MAX_SMOOTH_MATERIAL_MOVE (8) -// TYPES ------------------------------------------------------------------- - -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - -float rendLightWallAngle = 1.2f; // Intensity of angle-based wall lighting. +float rendLightWallAngle = 1.2f; // Intensity of angle-based wall lighting. byte rendLightWallAngleSmooth = true; -float rendSkyLight = .2f; // Intensity factor. -byte rendSkyLightAuto = true; +float rendSkyLight = .2f; // Intensity factor. +byte rendSkyLightAuto = true; boolean firstFrameAfterLoad; boolean ddMapSetup; -// PRIVATE DATA DEFINITIONS ------------------------------------------------ - -static surfacelistnode_t* unusedSurfaceListNodes = 0; - -// CODE -------------------------------------------------------------------- +static surfacelistnode_t *unusedSurfaceListNodes = 0; /** * Allocate a new surface list node. */ -static surfacelistnode_t* allocListNode(void) -{ - surfacelistnode_t* node = Z_Calloc(sizeof(*node), PU_APPSTATIC, 0); - return node; -} - -#if 0 -/** - * Free all memory acquired for the given surface list node. - * - * @todo This function is never called anywhere? - */ -static void freeListNode(surfacelistnode_t* node) +static inline surfacelistnode_t *allocListNode() { - if(node) - Z_Free(node); + return (surfacelistnode_t *) Z_Calloc(sizeof(surfacelistnode_t), PU_APPSTATIC, 0); } -#endif -surfacelistnode_t* R_SurfaceListNodeCreate(void) +surfacelistnode_t *R_SurfaceListNodeCreate() { - surfacelistnode_t* node; + surfacelistnode_t *node; // Is there a free node in the unused list? if(unusedSurfaceListNodes) @@ -116,33 +75,30 @@ surfacelistnode_t* R_SurfaceListNodeCreate(void) node = allocListNode(); } - node->data = NULL; - node->next = NULL; + node->data = 0; + node->next = 0; return node; } -void R_SurfaceListNodeDestroy(surfacelistnode_t* node) +void R_SurfaceListNodeDestroy(surfacelistnode_t *node) { // Move it to the list of unused nodes. - node->data = NULL; + node->data = 0; node->next = unusedSurfaceListNodes; unusedSurfaceListNodes = node; } -void R_SurfaceListAdd(surfacelist_t* sl, Surface* suf) +void R_SurfaceListAdd(surfacelist_t *sl, Surface *suf) { - surfacelistnode_t* node; - - if(!sl || !suf) - return; + if(!sl || !suf) return; // Check whether this surface is already in the list. - node = sl->head; + surfacelistnode_t *node = sl->head; while(node) { - if((Surface*) node->data == suf) - return; // Yep. + if((Surface *) node->data == suf) return; // Yep. + node = node->next; } @@ -155,17 +111,15 @@ void R_SurfaceListAdd(surfacelist_t* sl, Surface* suf) sl->num++; } -boolean R_SurfaceListRemove(surfacelist_t* sl, const Surface* suf) +boolean R_SurfaceListRemove(surfacelist_t *sl, Surface const *suf) { - surfacelistnode_t* last, *n; - if(!sl || !suf) return false; - last = sl->head; + surfacelistnode_t *last = sl->head; if(last) { - n = last->next; + surfacelistnode_t *n = last->next; while(n) { if((Surface*) n->data == suf) @@ -184,35 +138,32 @@ boolean R_SurfaceListRemove(surfacelist_t* sl, const Surface* suf) return false; } -void R_SurfaceListClear(surfacelist_t* sl) +void R_SurfaceListClear(surfacelist_t *sl) { - if(sl) + if(!sl) return; + + surfacelistnode_t *node = sl->head; + while(node) { - surfacelistnode_t* node, *next; - node = sl->head; - while(node) - { - next = node->next; - R_SurfaceListRemove(sl, (Surface*)node->data); - node = next; - } + surfacelistnode_t *next = node->next; + R_SurfaceListRemove(sl, (Surface *)node->data); + node = next; } } -boolean R_SurfaceListIterate(surfacelist_t* sl, boolean (*callback) (Surface* suf, void*), - void* context) +boolean R_SurfaceListIterate(surfacelist_t *sl, boolean (*callback) (Surface *suf, void *), + void *context) { - boolean result = true; - surfacelistnode_t* n, *np; + boolean result = true; if(sl) { - n = sl->head; + surfacelistnode_t *n = sl->head; while(n) { - np = n->next; - if((result = callback((Surface*) n->data, context)) == 0) - break; + surfacelistnode_t *np = n->next; + result = callback((Surface *) n->data, context); + if(!result) break; n = np; } } @@ -220,7 +171,7 @@ boolean R_SurfaceListIterate(surfacelist_t* sl, boolean (*callback) (Surface* su return result; } -boolean updateSurfaceScroll(Surface* suf, void* context) +boolean updateSurfaceScroll(Surface *suf, void * /*context*/) { // X Offset suf->oldOffset[0][0] = suf->oldOffset[0][1]; @@ -250,17 +201,17 @@ boolean updateSurfaceScroll(Surface* suf, void* context) /** * $smoothmatoffset: Roll the surface material offset tracker buffers. */ -void R_UpdateSurfaceScroll(void) +void R_UpdateSurfaceScroll() { - surfacelist_t* slist; if(!theMap) return; - slist = GameMap_ScrollingSurfaces(theMap); + + surfacelist_t *slist = GameMap_ScrollingSurfaces(theMap); if(!slist) return; - R_SurfaceListIterate(slist, updateSurfaceScroll, NULL); + R_SurfaceListIterate(slist, updateSurfaceScroll, 0); } -boolean resetSurfaceScroll(Surface* suf, void* context) +boolean resetSurfaceScroll(Surface *suf, void * /*context*/) { // X Offset. suf->visOffsetDelta[0] = 0; @@ -277,7 +228,7 @@ boolean resetSurfaceScroll(Surface* suf, void* context) return true; } -boolean interpSurfaceScroll(Surface* suf, void* context) +boolean interpSurfaceScroll(Surface *suf, void * /*context*/) { // X Offset. suf->visOffsetDelta[0] = @@ -310,34 +261,31 @@ boolean interpSurfaceScroll(Surface* suf, void* context) */ void R_InterpolateSurfaceScroll(boolean resetNextViewer) { - surfacelist_t* slist; - if(!theMap) return; - slist = GameMap_ScrollingSurfaces(theMap); + + surfacelist_t *slist = GameMap_ScrollingSurfaces(theMap); if(!slist) return; if(resetNextViewer) { // Reset the material offset trackers. - R_SurfaceListIterate(slist, resetSurfaceScroll, NULL); + R_SurfaceListIterate(slist, resetSurfaceScroll, 0); } // While the game is paused there is no need to calculate any // visual material offsets. else //if(!clientPaused) { // Set the visible material offsets. - R_SurfaceListIterate(slist, interpSurfaceScroll, NULL); + R_SurfaceListIterate(slist, interpSurfaceScroll, 0); } } -void R_AddTrackedPlane(planelist_t* plist, Plane *pln) +void R_AddTrackedPlane(planelist_t *plist, Plane *pln) { - uint i; - if(!plist || !pln) return; // Check whether we are already tracking this plane. - for(i = 0; i < plist->num; ++i) + for(uint i = 0; i < plist->num; ++i) { if(plist->array[i] == pln) return; // Yes we are. @@ -354,30 +302,27 @@ void R_AddTrackedPlane(planelist_t* plist, Plane *pln) if(!plist->maxNum) plist->maxNum = 8; - plist->array = Z_Realloc(plist->array, sizeof(Plane*) * (plist->maxNum + 1), PU_MAP); + plist->array = (Plane **) Z_Realloc(plist->array, sizeof(Plane *) * (plist->maxNum + 1), PU_MAP); } // Add the plane to the list. - plist->array[plist->num-1] = pln; + plist->array[plist->num - 1] = pln; plist->array[plist->num] = NULL; // Terminate. } -boolean R_RemoveTrackedPlane(planelist_t *plist, const Plane *pln) +boolean R_RemoveTrackedPlane(planelist_t *plist, Plane const *pln) { - uint i; + if(!plist || !pln) return false; - if(!plist || !pln) - return false; - - for(i = 0; i < plist->num; ++i) + for(uint i = 0; i < plist->num; ++i) { if(plist->array[i] == pln) { if(i == plist->num - 1) - plist->array[i] = NULL; + plist->array[i] = 0; else - memmove(&plist->array[i], &plist->array[i+1], - sizeof(Plane*) * (plist->num - 1 - i)); + std::memmove(&plist->array[i], &plist->array[i + 1], sizeof(Plane *) * (plist->num - 1 - i)); + plist->num--; return true; } @@ -389,29 +334,29 @@ boolean R_RemoveTrackedPlane(planelist_t *plist, const Plane *pln) /** * $smoothplane: Roll the height tracker buffers. */ -void R_UpdateTrackedPlanes(void) +void R_UpdateTrackedPlanes() { - planelist_t* plist; - uint i; - if(!theMap) return; - plist = GameMap_TrackedPlanes(theMap); + + planelist_t* plist = GameMap_TrackedPlanes(theMap); if(!plist) return; - for(i = 0; i < plist->num; ++i) + for(uint i = 0; i < plist->num; ++i) { - Plane* pln = plist->array[i]; + Plane *pln = plist->array[i]; pln->oldHeight[0] = pln->oldHeight[1]; pln->oldHeight[1] = pln->height; if(pln->oldHeight[0] != pln->oldHeight[1]) + { if(fabs(pln->oldHeight[0] - pln->oldHeight[1]) >= MAX_SMOOTH_PLANE_MOVE) { // Too fast: make an instantaneous jump. pln->oldHeight[0] = pln->oldHeight[1]; } + } } } @@ -420,20 +365,17 @@ void R_UpdateTrackedPlanes(void) */ void R_InterpolateTrackedPlanes(boolean resetNextViewer) { - planelist_t* plist; - Plane* pln; - uint i; - if(!theMap) return; - plist = GameMap_TrackedPlanes(theMap); + + planelist_t* plist = GameMap_TrackedPlanes(theMap); if(!plist) return; if(resetNextViewer) { // $smoothplane: Reset the plane height trackers. - for(i = 0; i < plist->num; ++i) + for(uint i = 0; i < plist->num; ++i) { - pln = plist->array[i]; + Plane *pln = plist->array[i]; pln->visHeightDelta = 0; pln->visHeight = pln->oldHeight[0] = pln->oldHeight[1] = pln->height; @@ -452,9 +394,9 @@ void R_InterpolateTrackedPlanes(boolean resetNextViewer) else //if(!clientPaused) { // $smoothplane: Set the visible offsets. - for(i = 0; i < plist->num; ++i) + for(uint i = 0; i < plist->num; ++i) { - pln = plist->array[i]; + Plane *pln = plist->array[i]; pln->visHeightDelta = pln->oldHeight[0] * (1 - frameTimePos) + pln->height * frameTimePos - @@ -483,10 +425,8 @@ void R_InterpolateTrackedPlanes(boolean resetNextViewer) * decoration origins for surfaces whose material offset is dependant upon * the given plane. */ -void R_MarkDependantSurfacesForDecorationUpdate(Plane* pln) +void R_MarkDependantSurfacesForDecorationUpdate(Plane *pln) { - LineDef** linep; - if(!pln || !pln->sector->lineDefs) return; // "Middle" planes have no dependent surfaces. @@ -494,11 +434,10 @@ void R_MarkDependantSurfacesForDecorationUpdate(Plane* pln) // Mark the decor lights on the sides of this plane as requiring // an update. - linep = pln->sector->lineDefs; - + LineDef **linep = pln->sector->lineDefs; while(*linep) { - LineDef* li = *linep; + LineDef *li = *linep; Surface_Update(&li->L_frontsidedef->SW_surface(SS_MIDDLE)); Surface_Update(&li->L_frontsidedef->SW_surface(SS_BOTTOM)); @@ -515,9 +454,9 @@ void R_MarkDependantSurfacesForDecorationUpdate(Plane* pln) } } -static boolean markSurfaceForDecorationUpdate(Surface* surface, void* paramaters) +static boolean markSurfaceForDecorationUpdate(Surface *surface, void *paramaters) { - material_t* material = (material_t*) paramaters; + material_t *material = (material_t *) paramaters; if(material == surface->material) { Surface_Update(surface); @@ -525,12 +464,11 @@ static boolean markSurfaceForDecorationUpdate(Surface* surface, void* paramaters return 1; // Continue iteration. } -void R_UpdateMapSurfacesOnMaterialChange(material_t* material) +void R_UpdateMapSurfacesOnMaterialChange(material_t *material) { - surfacelist_t* slist; - if(!material || !theMap || ddMapSetup) return; - slist = GameMap_DecoratedSurfaces(theMap); + + surfacelist_t *slist = GameMap_DecoratedSurfaces(theMap); if(!slist) return; // Light decorations will need a refresh. @@ -548,19 +486,15 @@ void R_UpdateMapSurfacesOnMaterialChange(material_t* material) * * @return Ptr to the newly created plane. */ -Plane* R_NewPlaneForSector(Sector* sec) +Plane *R_NewPlaneForSector(Sector *sec) { - Surface* suf; - Plane* plane; - - if(!sec) - return NULL; // Do wha? + if(!sec) return NULL; // Do wha? // Allocate the new plane. - plane = Z_Malloc(sizeof(Plane), PU_MAP, 0); + Plane *plane = (Plane *) Z_Malloc(sizeof(Plane), PU_MAP, 0); // Resize this sector's plane list. - sec->planes = Z_Realloc(sec->planes, sizeof(Plane*) * (++sec->planeCount + 1), PU_MAP); + sec->planes = (Plane **) Z_Realloc(sec->planes, sizeof(Plane *) * (++sec->planeCount + 1), PU_MAP); // Add the new plane to the end of the list. sec->planes[sec->planeCount-1] = plane; sec->planes[sec->planeCount] = NULL; // Terminate. @@ -572,15 +506,15 @@ Plane* R_NewPlaneForSector(Sector* sec) plane->sector = sec; plane->height = plane->oldHeight[0] = plane->oldHeight[1] = 0; plane->visHeight = plane->visHeightDelta = 0; - memset(&plane->PS_base.thinker, 0, sizeof(plane->PS_base.thinker)); + std::memset(&plane->PS_base.thinker, 0, sizeof(plane->PS_base.thinker)); plane->speed = 0; plane->target = 0; plane->type = PLN_MID; plane->planeID = sec->planeCount-1; // Initialize the surface. - memset(&plane->surface, 0, sizeof(plane->surface)); - suf = &plane->surface; + std::memset(&plane->surface, 0, sizeof(plane->surface)); + Surface *suf = &plane->surface; suf->header.type = DMU_SURFACE; // Setup header for DMU. suf->normal[VZ] = 1; V3f_BuildTangents(suf->tangent, suf->bitangent, suf->normal); @@ -601,15 +535,13 @@ Plane* R_NewPlaneForSector(Sector* sec) */ if(sec->bspLeafs && *sec->bspLeafs) { - BspLeaf** ssecIter = sec->bspLeafs; + BspLeaf **ssecIter = sec->bspLeafs; do { - BspLeaf* bspLeaf = *ssecIter; - biassurface_t** newList; + BspLeaf *bspLeaf = *ssecIter; uint n = 0; - newList = Z_Calloc(sec->planeCount * sizeof(biassurface_t*), PU_MAP, NULL); - + biassurface_t **newList = (biassurface_t **) Z_Calloc(sec->planeCount * sizeof(biassurface_t *), PU_MAP, 0); // Copy the existing list? if(bspLeaf->bsuf) { @@ -622,13 +554,13 @@ Plane* R_NewPlaneForSector(Sector* sec) if(!ddMapSetup) { - biassurface_t* bsuf = SB_CreateSurface(); + biassurface_t *bsuf = SB_CreateSurface(); bsuf->size = Rend_NumFanVerticesForBspLeaf(bspLeaf); - bsuf->illum = Z_Calloc(sizeof(vertexillum_t) * bsuf->size, PU_MAP, 0); + bsuf->illum = (vertexillum_t *) Z_Calloc(sizeof(vertexillum_t) * bsuf->size, PU_MAP, 0); - { uint i; - for(i = 0; i < bsuf->size; ++i) + for(uint i = 0; i < bsuf->size; ++i) + { SB_InitVertexIllum(&bsuf->illum[i]); } @@ -652,31 +584,24 @@ Plane* R_NewPlaneForSector(Sector* sec) * @param id The sector, plane id to be destroyed. * @param sec Ptr to sector for which a plane will be destroyed. */ -void R_DestroyPlaneOfSector(uint id, Sector* sec) +void R_DestroyPlaneOfSector(uint id, Sector *sec) { - Plane* plane, **newList = NULL; - surfacelist_t* slist; - planelist_t* plist; - uint i; - if(!sec) return; // Do wha? - if(id >= sec->planeCount) Con_Error("P_DestroyPlaneOfSector: Plane id #%i is not valid for " "sector #%u", id, (uint) GET_SECTOR_IDX(sec)); - plane = sec->planes[id]; + Plane *plane = sec->planes[id]; // Create a new plane list? + Plane **newList = 0; if(sec->planeCount > 1) { - uint n; - - newList = Z_Malloc(sizeof(Plane**) * sec->planeCount, PU_MAP, 0); + newList = (Plane **) Z_Malloc(sizeof(*newList) * sec->planeCount, PU_MAP, 0); // Copy ptrs to the planes. - n = 0; - for(i = 0; i < sec->planeCount; ++i) + uint n = 0; + for(uint i = 0; i < sec->planeCount; ++i) { if(i == id) continue; newList[n++] = sec->planes[i]; @@ -685,11 +610,11 @@ void R_DestroyPlaneOfSector(uint id, Sector* sec) } // If this plane is currently being watched, remove it. - plist = GameMap_TrackedPlanes(theMap); + planelist_t *plist = GameMap_TrackedPlanes(theMap); if(plist) R_RemoveTrackedPlane(plist, plane); // If this plane's surface is in the moving list, remove it. - slist = GameMap_ScrollingSurfaces(theMap); + surfacelist_t *slist = GameMap_ScrollingSurfaces(theMap); if(slist) R_SurfaceListRemove(slist, &plane->surface); // If this plane's surface is in the deocrated list, remove it. @@ -701,14 +626,15 @@ void R_DestroyPlaneOfSector(uint id, Sector* sec) if(slist) R_SurfaceListRemove(slist, &plane->surface); // Destroy the biassurfaces for this plane. - { BspLeaf** bspLeafIter; - for(bspLeafIter = sec->bspLeafs; *bspLeafIter; bspLeafIter++) + for(BspLeaf **bspLeafIter = sec->bspLeafs; *bspLeafIter; bspLeafIter++) { - BspLeaf* bspLeaf = *bspLeafIter; + BspLeaf *bspLeaf = *bspLeafIter; SB_DestroySurface(bspLeaf->bsuf[id]); if(id < sec->planeCount) - memmove(bspLeaf->bsuf + id, bspLeaf->bsuf + id + 1, sizeof(biassurface_t*)); - }} + { + std::memmove(bspLeaf->bsuf + id, bspLeaf->bsuf + id + 1, sizeof(biassurface_t *)); + } + } // Destroy the specified plane. Z_Free(plane); @@ -719,63 +645,57 @@ void R_DestroyPlaneOfSector(uint id, Sector* sec) sec->planes = newList; } -surfacedecor_t* R_CreateSurfaceDecoration(Surface* suf) +surfacedecor_t *R_CreateSurfaceDecoration(Surface *suf) { - surfacedecor_t* d, *s, *decorations; - uint i; + if(!suf) return 0; - if(!suf) return NULL; - - decorations = Z_Malloc(sizeof(*decorations) * (++suf->numDecorations), PU_MAP, 0); + surfacedecor_t *decorations = (surfacedecor_t *) Z_Malloc(sizeof(*decorations) * (++suf->numDecorations), PU_MAP, 0); if(suf->numDecorations > 1) { // Copy the existing decorations. - for(i = 0; i < suf->numDecorations - 1; ++i) + for(uint i = 0; i < suf->numDecorations - 1; ++i) { - d = &decorations[i]; - s = &suf->decorations[i]; + surfacedecor_t *d = &decorations[i]; + surfacedecor_t *s = &suf->decorations[i]; - memcpy(d, s, sizeof(*d)); + std::memcpy(d, s, sizeof(*d)); } Z_Free(suf->decorations); } // Add the new decoration. - d = &decorations[suf->numDecorations - 1]; - + surfacedecor_t *d = &decorations[suf->numDecorations - 1]; suf->decorations = decorations; return d; } -void R_ClearSurfaceDecorations(Surface* suf) +void R_ClearSurfaceDecorations(Surface *suf) { if(!suf) return; if(suf->decorations) - Z_Free(suf->decorations); - suf->decorations = NULL; + { + Z_Free(suf->decorations); suf->decorations = 0; + } suf->numDecorations = 0; } -void GameMap_UpdateSkyFixForSector(GameMap* map, Sector* sec) +void GameMap_UpdateSkyFixForSector(GameMap *map, Sector *sec) { - boolean skyFloor, skyCeil; - assert(map); + DENG_ASSERT(map); if(!sec || 0 == sec->lineDefCount) return; - skyFloor = Surface_IsSkyMasked(&sec->SP_floorsurface); - skyCeil = Surface_IsSkyMasked(&sec->SP_ceilsurface); + boolean skyFloor = Surface_IsSkyMasked(&sec->SP_floorsurface); + boolean skyCeil = Surface_IsSkyMasked(&sec->SP_ceilsurface); if(!skyFloor && !skyCeil) return; if(skyCeil) { - mobj_t* mo; - // Adjust for the plane height. if(sec->SP_ceilvisheight > map->skyFix[PLN_CEILING].height) { @@ -784,7 +704,7 @@ void GameMap_UpdateSkyFixForSector(GameMap* map, Sector* sec) } // Check that all the mobjs in the sector fit in. - for(mo = sec->mobjList; mo; mo = mo->sNext) + for(mobj_t *mo = sec->mobjList; mo; mo = mo->sNext) { float extent = mo->origin[VZ] + mo->height; @@ -810,15 +730,15 @@ void GameMap_UpdateSkyFixForSector(GameMap* map, Sector* sec) // floor and/or ceiling of their front and/or back sectors. if(sec->lineDefs && *sec->lineDefs) { - LineDef** linePtr = sec->lineDefs; + LineDef **linePtr = sec->lineDefs; do { - LineDef* li = *linePtr; + LineDef *li = *linePtr; // Must be twosided. if(li->L_frontsidedef && li->L_backsidedef) { - SideDef* si = li->L_frontsector == sec? li->L_frontsidedef : li->L_backsidedef; + SideDef *si = li->L_frontsector == sec? li->L_frontsidedef : li->L_backsidedef; if(si->SW_middlematerial) { @@ -851,26 +771,24 @@ void GameMap_UpdateSkyFixForSector(GameMap* map, Sector* sec) } } -void GameMap_InitSkyFix(GameMap* map) +void GameMap_InitSkyFix(GameMap *map) { - uint i; - assert(map); + DENG_ASSERT(map); map->skyFix[PLN_FLOOR].height = DDMAXFLOAT; map->skyFix[PLN_CEILING].height = DDMINFLOAT; // Update for sector plane heights and mobjs which intersect the ceiling. - for(i = 0; i < map->numSectors; ++i) + for(uint i = 0; i < map->numSectors; ++i) { GameMap_UpdateSkyFixForSector(map, map->sectors + i); } } /** - * @return Ptr to the lineowner for this line for this vertex - * else @c NULL. + * @return Lineowner for this line for this vertex; otherwise @c 0. */ -lineowner_t* R_GetVtxLineOwner(const Vertex *v, const LineDef *line) +lineowner_t *R_GetVtxLineOwner(Vertex const *v, LineDef const *line) { if(v == line->L_v1) return line->L_vo1; @@ -878,7 +796,7 @@ lineowner_t* R_GetVtxLineOwner(const Vertex *v, const LineDef *line) if(v == line->L_v2) return line->L_vo2; - return NULL; + return 0; } /// @note Part of the Doomsday public API. @@ -893,18 +811,13 @@ void R_SetupFog(float start, float end, float density, float *rgb) } /// @note Part of the Doomsday public API. -void R_SetupFogDefaults(void) +void R_SetupFogDefaults() { // Go with the defaults. Con_Execute(CMDS_DDAY,"fog off", true, false); } -/** - * Returns pointers to the line's vertices in such a fashion that verts[0] - * is the leftmost vertex and verts[1] is the rightmost vertex, when the - * line lies at the edge of `sector.' - */ -void R_OrderVertices(const LineDef* line, const Sector* sector, Vertex* verts[2]) +void R_OrderVertices(LineDef const *line, Sector const *sector, Vertex *verts[2]) { byte edge = (sector == line->L_frontsector? 0:1); verts[0] = line->L_v(edge); @@ -912,11 +825,11 @@ void R_OrderVertices(const LineDef* line, const Sector* sector, Vertex* verts[2] } boolean R_FindBottomTop2(SideDefSection section, int lineFlags, - Sector* frontSec, Sector* backSec, SideDef* frontDef, SideDef* backDef, - coord_t* low, coord_t* hi, float matOffset[2]) + Sector *frontSec, Sector *backSec, SideDef *frontDef, SideDef *backDef, + coord_t *low, coord_t *hi, float matOffset[2]) { - const boolean unpegBottom = !!(lineFlags & DDLF_DONTPEGBOTTOM); - const boolean unpegTop = !!(lineFlags & DDLF_DONTPEGTOP); + bool const unpegBottom = !!(lineFlags & DDLF_DONTPEGBOTTOM); + bool const unpegTop = !!(lineFlags & DDLF_DONTPEGTOP); // Single sided? if(!frontSec || !backSec || !backDef/*front side of a "window"*/) @@ -926,7 +839,7 @@ boolean R_FindBottomTop2(SideDefSection section, int lineFlags, if(matOffset) { - Surface* suf = &frontDef->SW_middlesurface; + Surface *suf = &frontDef->SW_middlesurface; matOffset[0] = suf->visOffset[0]; matOffset[1] = suf->visOffset[1]; if(unpegBottom) @@ -937,12 +850,12 @@ boolean R_FindBottomTop2(SideDefSection section, int lineFlags, } else { - const boolean stretchMiddle = !!(frontDef->flags & SDF_MIDDLE_STRETCH); - Plane* ffloor = frontSec->SP_plane(PLN_FLOOR); - Plane* fceil = frontSec->SP_plane(PLN_CEILING); - Plane* bfloor = backSec->SP_plane(PLN_FLOOR); - Plane* bceil = backSec->SP_plane(PLN_CEILING); - Surface* suf = &frontDef->SW_surface(section); + boolean const stretchMiddle = !!(frontDef->flags & SDF_MIDDLE_STRETCH); + Plane *ffloor = frontSec->SP_plane(PLN_FLOOR); + Plane *fceil = frontSec->SP_plane(PLN_CEILING); + Plane *bfloor = backSec->SP_plane(PLN_FLOOR); + Plane *bceil = backSec->SP_plane(PLN_CEILING); + Surface *suf = &frontDef->SW_surface(section); switch(section) { @@ -967,7 +880,9 @@ boolean R_FindBottomTop2(SideDefSection section, int lineFlags, break; case SS_BOTTOM: { - const boolean raiseToBackFloor = (Surface_IsSkyMasked(&fceil->surface) && Surface_IsSkyMasked(&bceil->surface) && fceil->visHeight < bceil->visHeight); + bool const raiseToBackFloor = (Surface_IsSkyMasked(&fceil->surface) && Surface_IsSkyMasked(&bceil->surface) && + fceil->visHeight < bceil->visHeight && + bfloor->visHeight > fceil->visHeight); coord_t t = bfloor->visHeight; *low = ffloor->visHeight; @@ -1011,13 +926,13 @@ boolean R_FindBottomTop2(SideDefSection section, int lineFlags, if(suf->material && !stretchMiddle) { - const boolean clipBottom = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && Surface_IsSkyMasked(&ffloor->surface) && Surface_IsSkyMasked(&bfloor->surface)); - const boolean clipTop = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && Surface_IsSkyMasked(&fceil->surface) && Surface_IsSkyMasked(&bceil->surface)); + boolean const clipBottom = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && Surface_IsSkyMasked(&ffloor->surface) && Surface_IsSkyMasked(&bfloor->surface)); + boolean const clipTop = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && Surface_IsSkyMasked(&fceil->surface) && Surface_IsSkyMasked(&bceil->surface)); - const coord_t openBottom = *low; - const coord_t openTop = *hi; - const int matHeight = Material_Height(suf->material); - const coord_t matYOffset = suf->visOffset[VY]; + coord_t const openBottom = *low; + coord_t const openTop = *hi; + int const matHeight = Material_Height(suf->material); + coord_t const matYOffset = suf->visOffset[VY]; if(openTop > openBottom) { @@ -1061,19 +976,18 @@ boolean R_FindBottomTop2(SideDefSection section, int lineFlags, } boolean R_FindBottomTop(SideDefSection section, int lineFlags, - Sector* frontSec, Sector* backSec, SideDef* frontDef, SideDef* backDef, - coord_t* low, coord_t* hi) + Sector *frontSec, Sector *backSec, SideDef *frontDef, SideDef *backDef, + coord_t *low, coord_t *hi) { return R_FindBottomTop2(section, lineFlags, frontSec, backSec, frontDef, backDef, low, hi, 0/*offset not needed*/); } -coord_t R_OpenRange(Sector const* frontSec, Sector const* backSec, coord_t* retBottom, coord_t* retTop) +coord_t R_OpenRange(Sector const *frontSec, Sector const *backSec, coord_t *retBottom, coord_t *retTop) { - coord_t bottom, top; - DENG_ASSERT(frontSec); + coord_t top; if(backSec && backSec->SP_ceilheight < frontSec->SP_ceilheight) { top = backSec->SP_ceilheight; @@ -1083,6 +997,7 @@ coord_t R_OpenRange(Sector const* frontSec, Sector const* backSec, coord_t* retB top = frontSec->SP_ceilheight; } + coord_t bottom; if(backSec && backSec->SP_floorheight > frontSec->SP_floorheight) { bottom = backSec->SP_floorheight; @@ -1098,12 +1013,11 @@ coord_t R_OpenRange(Sector const* frontSec, Sector const* backSec, coord_t* retB return top - bottom; } -coord_t R_VisOpenRange(Sector const* frontSec, Sector const* backSec, coord_t* retBottom, coord_t* retTop) +coord_t R_VisOpenRange(Sector const *frontSec, Sector const *backSec, coord_t *retBottom, coord_t *retTop) { - coord_t bottom, top; - DENG_ASSERT(frontSec); + coord_t top; if(backSec && backSec->SP_ceilvisheight < frontSec->SP_ceilvisheight) { top = backSec->SP_ceilvisheight; @@ -1113,6 +1027,7 @@ coord_t R_VisOpenRange(Sector const* frontSec, Sector const* backSec, coord_t* r top = frontSec->SP_ceilvisheight; } + coord_t bottom; if(backSec && backSec->SP_floorvisheight > frontSec->SP_floorvisheight) { bottom = backSec->SP_floorvisheight; @@ -1128,20 +1043,18 @@ coord_t R_VisOpenRange(Sector const* frontSec, Sector const* backSec, coord_t* r return top - bottom; } -boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector* frontSec, Sector* backSec, - SideDef* frontDef, SideDef* backDef, boolean ignoreOpacity) +boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector *frontSec, Sector *backSec, + SideDef *frontDef, SideDef *backDef, boolean ignoreOpacity) { - material_t* material; - const materialsnapshot_t* ms; - if(!frontSec || !frontDef) return false; // Never. - material = frontDef->SW_middlematerial; + material_t *material = frontDef->SW_middlematerial; if(!material) return false; // Ensure we have up to date info about the material. - ms = Materials_Prepare(material, Rend_MapSurfaceDiffuseMaterialSpec(), true); - if(ignoreOpacity || (ms->isOpaque && !frontDef->SW_middleblendmode && frontDef->SW_middlergba[3] >= 1)) + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(material, Rend_MapSurfaceDiffuseMaterialSpec(), true)); + + if(ignoreOpacity || (ms.isOpaque() && !frontDef->SW_middleblendmode && frontDef->SW_middlergba[3] >= 1)) { coord_t openRange, openBottom, openTop; @@ -1150,7 +1063,7 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector* frontSec, Sector* b // Might the material cover the opening? openRange = R_VisOpenRange(frontSec, backSec, &openBottom, &openTop); - if(ms->size.height >= openRange) + if(ms.dimensions().height() >= openRange) { // Possibly; check the placement. coord_t bottom, top; @@ -1165,22 +1078,21 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector* frontSec, Sector* b return false; } -boolean R_MiddleMaterialCoversLineOpening(LineDef* line, int side, boolean ignoreOpacity) +boolean R_MiddleMaterialCoversLineOpening(LineDef *line, int side, boolean ignoreOpacity) { DENG_ASSERT(line); -{ - Sector* frontSec = line->L_sector(side); - Sector* backSec = line->L_sector(side^1); - SideDef* frontDef = line->L_sidedef(side); - SideDef* backDef = line->L_sidedef(side^1); + Sector *frontSec = line->L_sector(side); + Sector *backSec = line->L_sector(side ^ 1); + SideDef *frontDef = line->L_sidedef(side); + SideDef *backDef = line->L_sidedef(side ^ 1); return R_MiddleMaterialCoversOpening(line->flags, frontSec, backSec, frontDef, backDef, ignoreOpacity); -}} +} -LineDef* R_FindLineNeighbor(const Sector* sector, const LineDef* line, - const lineowner_t* own, boolean antiClockwise, binangle_t *diff) +LineDef *R_FindLineNeighbor(Sector const *sector, LineDef const *line, + lineowner_t const *own, boolean antiClockwise, binangle_t *diff) { - lineowner_t* cown = own->link[!antiClockwise]; - LineDef* other = cown->lineDef; + lineowner_t *cown = own->link[!antiClockwise]; + LineDef *other = cown->lineDef; if(other == line) return NULL; @@ -1205,11 +1117,11 @@ LineDef* R_FindLineNeighbor(const Sector* sector, const LineDef* line, return R_FindLineNeighbor(sector, line, cown, antiClockwise, diff); } -LineDef* R_FindSolidLineNeighbor(const Sector* sector, const LineDef* line, - const lineowner_t* own, boolean antiClockwise, binangle_t* diff) +LineDef *R_FindSolidLineNeighbor(Sector const *sector, LineDef const *line, + lineowner_t const *own, boolean antiClockwise, binangle_t *diff) { - lineowner_t* cown = own->link[!antiClockwise]; - LineDef* other = cown->lineDef; + lineowner_t *cown = own->link[!antiClockwise]; + LineDef *other = cown->lineDef; int side; if(other == line) return NULL; @@ -1267,14 +1179,13 @@ LineDef* R_FindSolidLineNeighbor(const Sector* sector, const LineDef* line, return R_FindSolidLineNeighbor(sector, line, cown, antiClockwise, diff); } -LineDef* R_FindLineBackNeighbor(const Sector* sector, const LineDef* line, - const lineowner_t* own, boolean antiClockwise, binangle_t* diff) +LineDef *R_FindLineBackNeighbor(Sector const *sector, LineDef const *line, + lineowner_t const *own, boolean antiClockwise, binangle_t *diff) { - lineowner_t* cown = own->link[!antiClockwise]; - LineDef* other = cown->lineDef; + lineowner_t *cown = own->link[!antiClockwise]; + LineDef *other = cown->lineDef; - if(other == line) - return NULL; + if(other == line) return 0; if(diff) *diff += (antiClockwise? cown->angle : own->angle); @@ -1290,10 +1201,10 @@ LineDef* R_FindLineBackNeighbor(const Sector* sector, const LineDef* line, return R_FindLineBackNeighbor(sector, line, cown, antiClockwise, diff); } -LineDef* R_FindLineAlignNeighbor(const Sector* sec, const LineDef* line, - const lineowner_t* own, boolean antiClockwise, int alignment) +LineDef *R_FindLineAlignNeighbor(Sector const *sec, LineDef const *line, + lineowner_t const *own, boolean antiClockwise, int alignment) { -#define SEP 10 + int const SEP = 10; lineowner_t* cown = own->link[!antiClockwise]; LineDef* other = cown->lineDef; @@ -1320,58 +1231,13 @@ LineDef* R_FindLineAlignNeighbor(const Sector* sec, const LineDef* line, // Not suitable, try the next. return R_FindLineAlignNeighbor(sec, line, cown, antiClockwise, alignment); - -#undef SEP -} - -/** - * The test is done on BSP leafs. - */ -#if 0 /* Currently unused. */ -static Sector *getContainingSectorOf(GameMap* map, Sector* sec) -{ - uint i; - float cdiff = -1, diff; - float inner[4], outer[4]; - Sector* other, *closest = NULL; - - memcpy(inner, sec->bBox, sizeof(inner)); - - // Try all sectors that fit in the bounding box. - for(i = 0, other = map->sectors; i < map->numSectors; other++, ++i) - { - if(!other->lineDefCount) - continue; - - if(other == sec) - continue; // Don't try on self! - - memcpy(outer, other->bBox, sizeof(outer)); - if(inner[BOXLEFT] >= outer[BOXLEFT] && - inner[BOXRIGHT] <= outer[BOXRIGHT] && - inner[BOXTOP] <= outer[BOXTOP] && - inner[BOXBOTTOM]>= outer[BOXBOTTOM]) - { - // Sec is totally and completely inside other! - diff = M_BoundingBoxDiff(inner, outer); - if(cdiff < 0 || diff <= cdiff) - { - closest = other; - cdiff = diff; - } - } - } - return closest; } -#endif -static __inline void initSurfaceMaterialOffset(Surface* suf) +static inline void initSurfaceMaterialOffset(Surface *suf) { - assert(suf); - suf->visOffset[VX] = suf->oldOffset[0][VX] = - suf->oldOffset[1][VX] = suf->offset[VX]; - suf->visOffset[VY] = suf->oldOffset[0][VY] = - suf->oldOffset[1][VY] = suf->offset[VY]; + DENG_ASSERT(suf); + suf->visOffset[VX] = suf->oldOffset[0][VX] = suf->oldOffset[1][VX] = suf->offset[VX]; + suf->visOffset[VY] = suf->oldOffset[0][VY] = suf->oldOffset[1][VY] = suf->offset[VY]; } /** @@ -1382,34 +1248,32 @@ void R_MapInitSurfaces(boolean forceUpdate) { if(novideo) return; - { uint i; - for(i = 0; i < NUM_SECTORS; ++i) + for(uint i = 0; i < NUM_SECTORS; ++i) { - Sector* sec = SECTOR_PTR(i); - uint j; + Sector *sec = SECTOR_PTR(i); R_UpdateSector(sec, forceUpdate); - for(j = 0; j < sec->planeCount; ++j) + + for(uint j = 0; j < sec->planeCount; ++j) { - Plane* pln = sec->SP_plane(j); + Plane *pln = sec->SP_plane(j); pln->visHeight = pln->oldHeight[0] = pln->oldHeight[1] = pln->height; initSurfaceMaterialOffset(&pln->surface); } - }} + } - { uint i; - for(i = 0; i < NUM_SIDEDEFS; ++i) + for(uint i = 0; i < NUM_SIDEDEFS; ++i) { - SideDef* si = SIDE_PTR(i); + SideDef *si = SIDE_PTR(i); initSurfaceMaterialOffset(&si->SW_topsurface); initSurfaceMaterialOffset(&si->SW_middlesurface); initSurfaceMaterialOffset(&si->SW_bottomsurface); - }} + } } -static void addToSurfaceLists(Surface* suf, material_t* mat) +static void addToSurfaceLists(Surface *suf, material_t *mat) { if(!suf || !mat) return; @@ -1417,35 +1281,32 @@ static void addToSurfaceLists(Surface* suf, material_t* mat) if(Materials_HasDecorations(mat)) R_SurfaceListAdd(GameMap_DecoratedSurfaces(theMap), suf); } -void R_MapInitSurfaceLists(void) +void R_MapInitSurfaceLists() { if(novideo) return; R_SurfaceListClear(GameMap_DecoratedSurfaces(theMap)); R_SurfaceListClear(GameMap_GlowingSurfaces(theMap)); - { uint i; - for(i = 0; i < NUM_SIDEDEFS; ++i) + for(uint i = 0; i < NUM_SIDEDEFS; ++i) { - SideDef* side = SIDE_PTR(i); + SideDef *side = SIDE_PTR(i); addToSurfaceLists(&side->SW_middlesurface, side->SW_middlematerial); addToSurfaceLists(&side->SW_topsurface, side->SW_topmaterial); addToSurfaceLists(&side->SW_bottomsurface, side->SW_bottommaterial); - }} + } - { uint i; - for(i = 0; i < NUM_SECTORS; ++i) + for(uint i = 0; i < NUM_SECTORS; ++i) { - Sector* sec = SECTOR_PTR(i); - if(0 == sec->lineDefCount) - continue; + Sector *sec = SECTOR_PTR(i); + if(!sec->lineDefCount) continue; - { uint j; - for(j = 0; j < sec->planeCount; ++j) + for(uint j = 0; j < sec->planeCount; ++j) + { addToSurfaceLists(&sec->SP_planesurface(j), sec->SP_planematerial(j)); } - }} + } } void R_SetupMap(int mode, int flags) @@ -1462,7 +1323,7 @@ void R_SetupMap(int mode, int flags) return; case DDSMM_AFTER_LOADING: - assert(theMap); + DENG_ASSERT(theMap); // Update everything again. Its possible that after loading we // now have more HOMs to fix, etc.. @@ -1473,12 +1334,7 @@ void R_SetupMap(int mode, int flags) return; case DDSMM_FINALIZE: { - ded_mapinfo_t* mapInfo; - float startTime; - char cmd[80]; - int i; - - assert(theMap); + DENG_ASSERT(theMap); if(gameTime > 20000000 / TICSPERSEC) { @@ -1503,7 +1359,7 @@ void R_SetupMap(int mode, int flags) R_MapInitSurfaces(true); R_MapInitSurfaceLists(); - startTime = Timer_Seconds(); + float startTime = Timer_Seconds(); Rend_CacheForMap(); Materials_ProcessCacheQueue(); VERBOSE( Con_Message("Precaching took %.2f seconds.\n", Timer_Seconds() - startTime) ) @@ -1513,20 +1369,20 @@ void R_SetupMap(int mode, int flags) // Map setup has been completed. // Run any commands specified in Map Info. - mapInfo = Def_GetMapInfo(GameMap_Uri(theMap)); + ded_mapinfo_t *mapInfo = Def_GetMapInfo(GameMap_Uri(theMap)); if(mapInfo && mapInfo->execute) { Con_Execute(CMDS_SCRIPT, mapInfo->execute, true, false); } // Run the special map setup command, which the user may alias to do something useful. - { AutoStr* mapPath = Uri_Resolved(GameMap_Uri(theMap)); - sprintf(cmd, "init-%s", Str_Text(mapPath)); + AutoStr *mapPath = Uri_Resolved(GameMap_Uri(theMap)); + char cmd[80]; + dd_snprintf(cmd, 80, "init-%s", Str_Text(mapPath)); if(Con_IsValidCommand(cmd)) { Con_Executef(CMDS_SCRIPT, false, "%s", cmd); } - } // Clear any input events that might have accumulated during the // setup period. @@ -1537,10 +1393,10 @@ void R_SetupMap(int mode, int flags) DD_ResetTimer(); // Kill all local commands and determine the invoid status of players. - for(i = 0; i < DDMAXPLAYERS; ++i) + for(int i = 0; i < DDMAXPLAYERS; ++i) { - player_t* plr = &ddPlayers[i]; - ddplayer_t* ddpl = &plr->shared; + player_t *plr = &ddPlayers[i]; + ddplayer_t *ddpl = &plr->shared; //clients[i].numTics = 0; @@ -1548,11 +1404,16 @@ void R_SetupMap(int mode, int flags) ddpl->inVoid = true; if(ddpl->mo) { - BspLeaf* bspLeaf = P_BspLeafAtPoint(ddpl->mo->origin); - - /// @todo $nplanes - if(bspLeaf && ddpl->mo->origin[VZ] >= bspLeaf->sector->SP_floorvisheight && ddpl->mo->origin[VZ] < bspLeaf->sector->SP_ceilvisheight - 4) - ddpl->inVoid = false; + BspLeaf *bspLeaf = P_BspLeafAtPoint(ddpl->mo->origin); + if(bspLeaf) + { + /// @todo $nplanes + if(ddpl->mo->origin[VZ] >= bspLeaf->sector->SP_floorvisheight && + ddpl->mo->origin[VZ] < bspLeaf->sector->SP_ceilvisheight - 4) + { + ddpl->inVoid = false; + } + } } } @@ -1566,8 +1427,7 @@ void R_SetupMap(int mode, int flags) firstFrameAfterLoad = true; Z_PrintStatus(); - return; - } + return; } default: Con_Error("R_SetupMap: Unknown setup mode %i", mode); @@ -1575,29 +1435,27 @@ void R_SetupMap(int mode, int flags) } } -void R_ClearSectorFlags(void) +void R_ClearSectorFlags() { - uint i; - for(i = 0; i < NUM_SECTORS; ++i) + for(uint i = 0; i < NUM_SECTORS; ++i) { - Sector* sec = SECTOR_PTR(i); + Sector *sec = SECTOR_PTR(i); // Clear all flags that can be cleared before each frame. sec->frameFlags &= ~SIF_FRAME_CLEAR; } } -boolean R_IsGlowingPlane(const Plane* pln) +boolean R_IsGlowingPlane(Plane const *pln) { #ifdef __CLIENT__ /// @todo We should not need to prepare to determine this. - material_t* mat = pln->surface.material; + material_t *mat = pln->surface.material; if(mat) { - const materialvariantspecification_t* spec = Materials_VariantSpecificationForContext( - MC_MAPSURFACE, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, -1, -1, -1, true, true, false, false); - const materialsnapshot_t* ms = Materials_Prepare(mat, spec, true); + materialvariantspecification_t const *spec = Rend_MapSurfaceDiffuseMaterialSpec(); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - if(!Material_IsDrawable(mat) || ms->glowing > 0) return true; + if(!Material_IsDrawable(mat) || ms.glowStrength() > 0) return true; } return Surface_IsSkyMasked(&pln->surface); #else @@ -1605,20 +1463,19 @@ boolean R_IsGlowingPlane(const Plane* pln) #endif } -float R_GlowStrength(const Plane* pln) +float R_GlowStrength(Plane const *pln) { #ifdef __CLIENT__ - material_t* mat = pln->surface.material; + material_t *mat = pln->surface.material; if(mat) { if(Material_IsDrawable(mat) && !Surface_IsSkyMasked(&pln->surface)) { /// @todo We should not need to prepare to determine this. - const materialvariantspecification_t* spec = Materials_VariantSpecificationForContext( - MC_MAPSURFACE, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, -1, -1, -1, true, true, false, false); - const materialsnapshot_t* ms = Materials_Prepare(mat, spec, true); + materialvariantspecification_t const *spec = Rend_MapSurfaceDiffuseMaterialSpec(); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - return ms->glowing; + return ms.glowStrength(); } } #endif @@ -1628,10 +1485,10 @@ float R_GlowStrength(const Plane* pln) /** * Does the specified sector contain any sky surfaces? * - * @return @c true, if one or more surfaces in the given sector - * use the special sky mask material. + * @return @c true, if one or more surfaces in the given sector use the + * special sky mask material. */ -boolean R_SectorContainsSkySurfaces(const Sector* sec) +boolean R_SectorContainsSkySurfaces(Sector const *sec) { boolean sectorContainsSkySurfaces = false; uint n = 0; @@ -1654,13 +1511,13 @@ boolean R_SectorContainsSkySurfaces(const Sector* sec) * Non-animated materials are preferred. * Sky materials are ignored. */ -static material_t* chooseFixMaterial(SideDef* s, SideDefSection section) +static material_t *chooseFixMaterial(SideDef *s, SideDefSection section) { - material_t* choice1 = 0, *choice2 = 0; - LineDef* line = s->line; + material_t *choice1 = 0, *choice2 = 0; + LineDef *line = s->line; byte side = (line->L_frontsidedef == s? FRONT : BACK); - Sector* frontSec = line->L_sector(side); - Sector* backSec = line->L_sidedef(side^1)? line->L_sector(side^1) : 0; + Sector *frontSec = line->L_sector(side); + Sector *backSec = line->L_sidedef(side ^ 1)? line->L_sector(side ^ 1) : 0; if(backSec) { @@ -1691,7 +1548,7 @@ static material_t* chooseFixMaterial(SideDef* s, SideDefSection section) { // Our first choice is a material on an adjacent wall section. // Try the left neighbor first. - LineDef* other = R_FindLineNeighbor(frontSec, line, line->L_vo(side), + LineDef *other = R_FindLineNeighbor(frontSec, line, line->L_vo(side), false /*next clockwise*/, NULL/*angle delta is irrelevant*/); if(!other) // Try the right neighbor. @@ -1708,8 +1565,8 @@ static material_t* chooseFixMaterial(SideDef* s, SideDefSection section) else { // Compare the relative heights to decide. - SideDef* otherSide = other->L_sidedef(other->L_frontsector == frontSec? FRONT : BACK); - Sector* otherSec = other->L_sector(other->L_frontsector == frontSec? BACK : FRONT); + SideDef *otherSide = other->L_sidedef(other->L_frontsector == frontSec? FRONT : BACK); + Sector *otherSec = other->L_sector(other->L_frontsector == frontSec? BACK : FRONT); if(otherSec->SP_ceilheight <= frontSec->SP_floorheight) choice1 = otherSide->SW_topmaterial; else if(otherSec->SP_floorheight >= frontSec->SP_ceilheight) @@ -1746,12 +1603,10 @@ static material_t* chooseFixMaterial(SideDef* s, SideDefSection section) return Materials_ToMaterial(Materials_ResolveUriCString("System:missing")); } -static void addMissingMaterial(SideDef* s, SideDefSection section) +static void addMissingMaterial(SideDef *s, SideDefSection section) { - Surface* suf; - // A material must be missing for this test to apply. - suf = &s->sections[section]; + Surface *suf = &s->sections[section]; if(suf->material) return; // Look for a suitable replacement. @@ -1762,8 +1617,8 @@ static void addMissingMaterial(SideDef* s, SideDefSection section) if(ddMapSetup) { VERBOSE( - Uri* uri = suf->material? Materials_ComposeUri(Materials_Id(suf->material)) : 0; - AutoStr* path = uri? Uri_ToString(uri) : 0; + Uri *uri = suf->material? Materials_ComposeUri(Materials_Id(suf->material)) : 0; + AutoStr *path = uri? Uri_ToString(uri) : 0; Con_Message("Warning: SideDef #%u is missing a material for the %s section.\n" " %s was chosen to complete the definition.\n", s->buildData.index-1, (section == SS_MIDDLE? "middle" : section == SS_TOP? "top" : "bottom"), @@ -1773,24 +1628,19 @@ static void addMissingMaterial(SideDef* s, SideDefSection section) } } -void R_UpdateLinedefsOfSector(Sector* sec) +void R_UpdateLinedefsOfSector(Sector *sec) { - uint i; - if(!sec) return; - for(i = 0; i < sec->lineDefCount; ++i) + for(uint i = 0; i < sec->lineDefCount; ++i) { - LineDef* li = sec->lineDefs[i]; - SideDef* front, *back; - Sector* frontSec, *backSec; - + LineDef *li = sec->lineDefs[i]; if(LINE_SELFREF(li)) continue; - front = li->L_frontsidedef; - back = li->L_backsidedef; - frontSec = li->L_frontsector; - backSec = li->L_backsector; + SideDef *front = li->L_frontsidedef; + SideDef *back = li->L_backsidedef; + Sector *frontSec = li->L_frontsector; + Sector *backSec = li->L_backsector; // Do not fix "windows". if(!front || (!back && backSec)) continue; @@ -1823,9 +1673,9 @@ void R_UpdateLinedefsOfSector(Sector* sec) } } -boolean R_UpdatePlane(Plane* pln, boolean forceUpdate) +boolean R_UpdatePlane(Plane *pln, boolean forceUpdate) { - Sector* sec = pln->sector; + Sector *sec = pln->sector; boolean changed = false; // Geometry change? @@ -1834,11 +1684,10 @@ boolean R_UpdatePlane(Plane* pln, boolean forceUpdate) // Check if there are any camera players in this sector. If their // height is now above the ceiling/below the floor they are now in // the void. - { uint i; - for(i = 0; i < DDMAXPLAYERS; ++i) + for(uint i = 0; i < DDMAXPLAYERS; ++i) { - player_t* plr = &ddPlayers[i]; - ddplayer_t* ddpl = &plr->shared; + player_t *plr = &ddPlayers[i]; + ddplayer_t *ddpl = &plr->shared; if(!ddpl->inGame || !ddpl->mo || !ddpl->mo->bspLeaf) continue; @@ -1849,14 +1698,13 @@ boolean R_UpdatePlane(Plane* pln, boolean forceUpdate) { ddpl->inVoid = true; } - }} + } // Update the base origins for this plane and all relevant sidedef surfaces. Surface_UpdateBaseOrigin(&pln->surface); - { uint i; - for(i = 0; i < sec->lineDefCount; ++i) + for(uint i = 0; i < sec->lineDefCount; ++i) { - LineDef* line = sec->lineDefs[i]; + LineDef *line = sec->lineDefs[i]; if(line->L_frontsidedef) // $degenleaf { SideDef_UpdateBaseOrigins(line->L_frontsidedef); @@ -1865,24 +1713,23 @@ boolean R_UpdatePlane(Plane* pln, boolean forceUpdate) { SideDef_UpdateBaseOrigins(line->L_backsidedef); } - }} + } // Inform the shadow bias of changed geometry. if(sec->bspLeafs && *sec->bspLeafs) { - BspLeaf** bspLeafIter = sec->bspLeafs; + BspLeaf **bspLeafIter = sec->bspLeafs; for(; *bspLeafIter; bspLeafIter++) { - BspLeaf* bspLeaf = *bspLeafIter; + BspLeaf *bspLeaf = *bspLeafIter; if(bspLeaf->hedge) { - HEdge* hedge = bspLeaf->hedge; + HEdge *hedge = bspLeaf->hedge; do { if(hedge->lineDef) { - uint i; - for(i = 0; i < 3; ++i) + for(uint i = 0; i < 3; ++i) { SB_SurfaceMoved(hedge->bsuf[i]); } @@ -1903,20 +1750,9 @@ boolean R_UpdatePlane(Plane* pln, boolean forceUpdate) return changed; } -#if 0 -/** - * Stub. - */ -boolean R_UpdateBspLeaf(BspLeaf* bspLeaf, boolean forceUpdate) -{ - return false; // Not changed. -} -#endif - -boolean R_UpdateSector(Sector* sec, boolean forceUpdate) +boolean R_UpdateSector(Sector *sec, boolean forceUpdate) { boolean changed = false, planeChanged = false; - uint i; // Check if there are any lightlevel or color changes. if(forceUpdate || @@ -1927,7 +1763,7 @@ boolean R_UpdateSector(Sector* sec, boolean forceUpdate) { sec->frameFlags |= SIF_LIGHT_CHANGED; sec->oldLightLevel = sec->lightLevel; - memcpy(sec->oldRGB, sec->rgb, sizeof(sec->oldRGB)); + std::memcpy(sec->oldRGB, sec->rgb, sizeof(sec->oldRGB)); LG_SectorChanged(sec); changed = true; @@ -1938,7 +1774,7 @@ boolean R_UpdateSector(Sector* sec, boolean forceUpdate) } // For each plane. - for(i = 0; i < sec->planeCount; ++i) + for(uint i = 0; i < sec->planeCount; ++i) { if(R_UpdatePlane(sec->planes[i], forceUpdate)) { @@ -1957,27 +1793,24 @@ boolean R_UpdateSector(Sector* sec, boolean forceUpdate) return planeChanged; } -/** - * Stub. - */ -boolean R_UpdateLinedef(LineDef* line, boolean forceUpdate) +boolean R_UpdateLinedef(LineDef *line, boolean forceUpdate) { + // Stub. + DENG_UNUSED(line); DENG_UNUSED(forceUpdate); return false; // Not changed. } -/** - * Stub. - */ -boolean R_UpdateSidedef(SideDef* side, boolean forceUpdate) +boolean R_UpdateSidedef(SideDef *side, boolean forceUpdate) { + // Stub. + DENG_UNUSED(side); DENG_UNUSED(forceUpdate); return false; // Not changed. } -/** - * Stub. - */ boolean R_UpdateSurface(Surface* suf, boolean forceUpdate) { + // Stub. + DENG_UNUSED(suf); DENG_UNUSED(forceUpdate); return false; // Not changed. } @@ -1985,7 +1818,7 @@ boolean R_UpdateSurface(Surface* suf, boolean forceUpdate) * All links will be updated every frame (sectorheights may change at * any time without notice). */ -void R_UpdatePlanes(void) +void R_UpdatePlanes() { // Nothing to do. } @@ -2002,13 +1835,11 @@ float R_DistAttenuateLightLevel(float distToViewer, float lightLevel) { if(distToViewer > 0 && rendLightDistanceAttentuation > 0) { - float real, minimum; - - real = lightLevel - + float real = lightLevel - (distToViewer - 32) / rendLightDistanceAttentuation * (1 - lightLevel); - minimum = lightLevel * lightLevel + (lightLevel - .63f) * .5f; + float minimum = lightLevel * lightLevel + (lightLevel - .63f) * .5f; if(real < minimum) real = minimum; // Clamp it. @@ -2018,7 +1849,7 @@ float R_DistAttenuateLightLevel(float distToViewer, float lightLevel) return lightLevel; } -float R_ExtraLightDelta(void) +float R_ExtraLightDelta() { return extraLightDelta; } @@ -2033,13 +1864,13 @@ float R_CheckSectorLight(float lightlevel, float min, float max) #ifdef __CLIENT__ -const float* R_GetSectorLightColor(const Sector* sector) +float const *R_GetSectorLightColor(Sector const *sector) { static vec3f_t skyLightColor, oldSkyAmbientColor = { -1, -1, -1 }; static float oldRendSkyLight = -1; if(rendSkyLight > .001f && R_SectorContainsSkySurfaces(sector)) { - const ColorRawf* ambientColor = Sky_AmbientColor(); + ColorRawf const *ambientColor = Sky_AmbientColor(); if(rendSkyLight != oldRendSkyLight || !INRANGE_OF(ambientColor->red, oldSkyAmbientColor[CR], .001f) || !INRANGE_OF(ambientColor->green, oldSkyAmbientColor[CG], .001f) || @@ -2065,9 +1896,9 @@ const float* R_GetSectorLightColor(const Sector* sector) #endif // __CLIENT__ -coord_t R_SkyCapZ(BspLeaf* bspLeaf, int skyCap) +coord_t R_SkyCapZ(BspLeaf *bspLeaf, int skyCap) { - const planetype_t plane = (skyCap & SKYCAP_UPPER)? PLN_CEILING : PLN_FLOOR; + planetype_t const plane = (skyCap & SKYCAP_UPPER)? PLN_CEILING : PLN_FLOOR; if(!bspLeaf) Con_Error("R_SkyCapZ: Invalid bspLeaf argument (=NULL)."); if(!bspLeaf->sector || !P_IsInVoid(viewPlayer)) return GameMap_SkyFix(theMap, plane == PLN_CEILING); return bspLeaf->sector->SP_planevisheight(plane); diff --git a/doomsday/engine/src/network/net_main.c b/doomsday/engine/src/network/net_main.c index ced35f98bf..4ab337fe0c 100644 --- a/doomsday/engine/src/network/net_main.c +++ b/doomsday/engine/src/network/net_main.c @@ -46,6 +46,7 @@ #ifdef __CLIENT__ # include "render/rend_bias.h" # include "render/rend_console.h" +# include "render/rend_main.h" # include "render/r_lgrid.h" # include "map/blockmapvisual.h" #endif @@ -70,7 +71,6 @@ D_CMD(Login); // in cl_main.c D_CMD(Logout); // in sv_main.c D_CMD(Ping); // in net_ping.c -void R_DrawLightRange(void); int Sv_GetRegisteredMobj(pool_t *, thid_t, mobjdelta_t *); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- diff --git a/doomsday/engine/src/render/lumobj.cpp b/doomsday/engine/src/render/lumobj.cpp index 2fb39b26ff..997148ae6c 100644 --- a/doomsday/engine/src/render/lumobj.cpp +++ b/doomsday/engine/src/render/lumobj.cpp @@ -33,9 +33,10 @@ #include "de_defs.h" #include "gl/sys_opengl.h" +#include "resource/materialsnapshot.h" +#include "resource/materialvariant.h" #include "resource/texture.h" #include "resource/texturevariant.h" -#include "resource/materialvariant.h" BEGIN_PROF_TIMERS() PROF_LUMOBJ_INIT_ADD, @@ -746,14 +747,14 @@ static void addLuminous(mobj_t *mo) // Ensure we have up-to-date information about the material. materialvariantspecification_t const *spec = Sprite_MaterialSpec(0/*tclass*/, 0/*tmap*/); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); - if(!MSU_texture(ms, MTU_PRIMARY)) return; // An invalid sprite texture. + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); + if(!ms.hasTexture(MTU_PRIMARY)) return; // An invalid sprite texture. - pl = (pointlight_analysis_t const *) Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), TA_SPRITE_AUTOLIGHT); - if(!pl) throw de::Error("addLuminous", QString("Texture \"%1\" has no TA_SPRITE_AUTOLIGHT analysis").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText())); + pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_SPRITE_AUTOLIGHT); + if(!pl) throw de::Error("addLuminous", QString("Texture \"%1\" has no TA_SPRITE_AUTOLIGHT analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); size = pl->brightMul; - yOffset = ms->size.height * pl->originY; + yOffset = ms.dimensions().height() * pl->originY; // Does the mobj have an active light definition? if(def) { @@ -763,11 +764,11 @@ static void addLuminous(mobj_t *mo) yOffset = def->offset[VY]; } - de::Texture &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); + de::Texture &tex = ms.texture(MTU_PRIMARY).generalCase(); center = -tex.origin().y() - mo->floorClip - R_GetBobOffset(mo) - yOffset; // Will the sprite be allowed to go inside the floor? - mul = mo->origin[VZ] + -tex.origin().y() - (float) ms->size.height - mo->bspLeaf->sector->SP_floorheight; + mul = mo->origin[VZ] + -tex.origin().y() - (float) ms.dimensions().height() - mo->bspLeaf->sector->SP_floorheight; if(!(mo->ddFlags & DDMF_NOFITBOTTOM) && mul < 0) { // Must adjust. @@ -961,11 +962,11 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*paramaters*/) // Are we glowing at this moment in time? materialvariantspecification_t const *spec = Rend_MapSurfaceDiffuseMaterialSpec(); - materialsnapshot_t const *ms = Materials_Prepare(suf->material, spec, true); - if(!(ms->glowing > .001f)) return true; // Continue iteration. + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(suf->material, spec, true)); + if(!(ms.glowStrength() > .001f)) return true; // Continue iteration. - averagecolor_analysis_t const *avgColorAmplified = (averagecolor_analysis_t const *) Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), TA_COLOR_AMPLIFIED); - if(!avgColorAmplified) throw de::Error("createGlowLightForSurface", QString("Texture \"%1\" has no TA_COLOR_AMPLIFIED analysis)").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText())); + averagecolor_analysis_t const *avgColorAmplified = (averagecolor_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_COLOR_AMPLIFIED); + if(!avgColorAmplified) throw de::Error("createGlowLightForSurface", QString("Texture \"%1\" has no TA_COLOR_AMPLIFIED analysis)").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); // @note Plane lights do not spread so simply link to all BspLeafs of this sector. lumobj_t *lum = createLuminous(LT_PLANE, sec->bspLeafs[0]); @@ -974,7 +975,7 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*paramaters*/) V3f_Copy(LUM_PLANE(lum)->normal, pln->PS_normal); V3f_Copy(LUM_PLANE(lum)->color, avgColorAmplified->color.rgb); - LUM_PLANE(lum)->intensity = ms->glowing; + LUM_PLANE(lum)->intensity = ms.glowStrength(); LUM_PLANE(lum)->tex = GL_PrepareLSTexture(LST_GRADIENT); lum->maxDistance = 0; lum->decorSource = 0; diff --git a/doomsday/engine/src/render/r_draw.cpp b/doomsday/engine/src/render/r_draw.cpp index bf6d6bd1e7..6ea2449ab8 100644 --- a/doomsday/engine/src/render/r_draw.cpp +++ b/doomsday/engine/src/render/r_draw.cpp @@ -26,6 +26,7 @@ #include "de_play.h" #include "de_resource.h" +#include "resource/materialsnapshot.h" #include "render/r_draw.h" #include "gl/sys_opengl.h" @@ -126,7 +127,7 @@ void R_ShutdownViewWindow(void) inited = false; } -void R_DrawPatch3(Texture *_tex, int x, int y, int w, int h, boolean useOffsets) +void R_DrawPatch3(struct texture_s *_tex, int x, int y, int w, int h, boolean useOffsets) { if(!_tex) return; de::Texture &tex = reinterpret_cast(*_tex); @@ -150,22 +151,26 @@ void R_DrawPatch3(Texture *_tex, int x, int y, int w, int h, boolean useOffsets) GL_DrawRectf2Color(x, y, w, h, 1, 1, 1, 1); } -void R_DrawPatch2(Texture *tex, int x, int y, int w, int h) +void R_DrawPatch2(struct texture_s *tex, int x, int y, int w, int h) { R_DrawPatch3(tex, x, y, w, h, true); } -void R_DrawPatch(Texture *tex, int x, int y) +void R_DrawPatch(struct texture_s *_tex, int x, int y) { - R_DrawPatch2(tex, x, y, Texture_Width(tex), Texture_Height(tex)); + if(!_tex) return; + de::Texture &tex = reinterpret_cast(*_tex); + + R_DrawPatch2(_tex, x, y, tex.width(), tex.height()); } -void R_DrawPatchTiled(Texture *tex, int x, int y, int w, int h, int wrapS, int wrapT) +void R_DrawPatchTiled(struct texture_s *_tex, int x, int y, int w, int h, int wrapS, int wrapT) { - if(!tex) return; + if(!_tex) return; + de::Texture &tex = reinterpret_cast(*_tex); - GL_BindTexture(GL_PreparePatchTexture2(tex, wrapS, wrapT)); - GL_DrawRectf2Tiled(x, y, w, h, Texture_Width(tex), Texture_Height(tex)); + GL_BindTexture(GL_PreparePatchTexture2(_tex, wrapS, wrapT)); + GL_DrawRectf2Tiled(x, y, w, h, tex.width(), tex.height()); } materialvariantspecification_t const *Ui_MaterialSpec() @@ -212,10 +217,10 @@ void R_DrawViewBorder(void) material_t *mat = Materials_ToMaterial(Materials_ResolveUri2(borderGraphicsNames[BG_BACKGROUND], true/*quiet please*/)); if(mat) { - materialsnapshot_t const *ms = Materials_Prepare(mat, Ui_MaterialSpec(), true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, Ui_MaterialSpec(), true)); - GL_BindTexture(MST(ms, MTU_PRIMARY)); - GL_DrawCutRectf2Tiled(0, 0, port->geometry.size.width, port->geometry.size.height, ms->size.width, ms->size.height, 0, 0, + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); + GL_DrawCutRectf2Tiled(0, 0, port->geometry.size.width, port->geometry.size.height, ms.dimensions().width(), ms.dimensions().height(), 0, 0, vd->window.origin.x - border, vd->window.origin.y - border, vd->window.size.width + 2 * border, vd->window.size.height + 2 * border); } diff --git a/doomsday/engine/src/render/r_main.c b/doomsday/engine/src/render/r_main.c index ca3f0b82b8..50a54f0889 100644 --- a/doomsday/engine/src/render/r_main.c +++ b/doomsday/engine/src/render/r_main.c @@ -67,7 +67,6 @@ D_CMD(ViewGrid); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- extern byte freezeRLs; -extern boolean firstFrameAfterLoad; // PUBLIC DATA DEFINITIONS ------------------------------------------------- @@ -1140,8 +1139,6 @@ void R_RenderBlankView(void) */ void R_RenderPlayerView(int num) { - extern boolean firstFrameAfterLoad; - int oldFlags = 0; player_t* player; viewdata_t* vd; diff --git a/doomsday/engine/src/render/r_things.cpp b/doomsday/engine/src/render/r_things.cpp index 0a7f4643d7..38fddad2e3 100644 --- a/doomsday/engine/src/render/r_things.cpp +++ b/doomsday/engine/src/render/r_things.cpp @@ -40,6 +40,7 @@ #include "def_main.h" #include "m_stack.h" +#include "resource/materialsnapshot.h" #include @@ -460,10 +461,10 @@ boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t *info) Materials_VariantSpecificationForContext(MC_PSPRITE, 0, 1, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 1, -1, false, true, true, false); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, false); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, false)); - de::Texture &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); - variantspecification_t const *texSpec = TS_GENERAL(MSU_texturespec(ms, MTU_PRIMARY)); + de::Texture &tex = ms.texture(MTU_PRIMARY).generalCase(); + variantspecification_t const *texSpec = TS_GENERAL(ms.texture(MTU_PRIMARY).spec()); DENG_ASSERT(texSpec); info->numFrames = sprDef->numFrames; @@ -471,9 +472,9 @@ boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t *info) info->flip = sprFrame->flip[0]; info->geometry.origin.x = -tex.origin().x() + -texSpec->border; info->geometry.origin.y = -tex.origin().y() + texSpec->border; - info->geometry.size.width = ms->size.width + texSpec->border*2; - info->geometry.size.height = ms->size.height + texSpec->border*2; - TextureVariant_Coords(MST(ms, MTU_PRIMARY), &info->texCoord[0], &info->texCoord[1]); + info->geometry.size.width = ms.dimensions().width() + texSpec->border*2; + info->geometry.size.height = ms.dimensions().height() + texSpec->border*2; + ms.texture(MTU_PRIMARY).coords(&info->texCoord[0], &info->texCoord[1]); return true; } @@ -502,8 +503,8 @@ coord_t R_VisualRadius(mobj_t *mo) // Use the sprite frame's width? if(material_t *material = R_GetMaterialForSprite(mo->sprite, mo->frame)) { - materialsnapshot_t const *ms = Materials_Prepare(material, Sprite_MaterialSpec(0/*tclass*/, 0/*tmap*/), true); - return ms->size.width / 2; + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(material, Sprite_MaterialSpec(0/*tclass*/, 0/*tmap*/), true)); + return ms.dimensions().width() / 2; } // Use the physical radius. @@ -545,12 +546,12 @@ float R_ShadowStrength(mobj_t *mo) if(mat) { // Ensure we've prepared this. - materialsnapshot_t const *ms = Materials_Prepare(mat, Sprite_MaterialSpec(0/*tclass*/, 0/*tmap*/), true); - averagealpha_analysis_t const *aa = (averagealpha_analysis_t const *) Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), TA_ALPHA); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, Sprite_MaterialSpec(0/*tclass*/, 0/*tmap*/), true)); + averagealpha_analysis_t const *aa = (averagealpha_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_ALPHA); float weightedSpriteAlpha; if(!aa) { - QByteArray uri = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText().toUtf8(); + QByteArray uri = ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri().asText().toUtf8(); Con_Error("R_ShadowStrength: Texture \"%s\" has no TA_ALPHA analysis", uri.constData()); } @@ -968,7 +969,6 @@ void R_ProjectSprite(mobj_t *mo) uint vLightListIdx = 0; material_t *mat; materialvariantspecification_t const *spec; - materialsnapshot_t const *ms; viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers); coord_t moPos[3]; @@ -1049,10 +1049,10 @@ void R_ProjectSprite(mobj_t *mo) matFlipT = false; spec = Sprite_MaterialSpec(mo->tclass, mo->tmap); - ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); // An invalid sprite texture? - de::Texture &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); + de::Texture &tex = ms.texture(MTU_PRIMARY).generalCase(); if(tex.manifest().schemeName().compareWithoutCase("Sprites")) return; // Align to the view plane? @@ -1219,27 +1219,27 @@ void R_ProjectSprite(mobj_t *mo) // We must find the correct positioning using the sector floor // and ceiling heights as an aid. - if(ms->size.height < secCeil - secFloor) + if(ms.dimensions().height() < secCeil - secFloor) { // Sprite fits in, adjustment possible? // Check top. if(fitTop && gzt > secCeil) gzt = secCeil; // Check bottom. - if(floorAdjust && fitBottom && gzt - ms->size.height < secFloor) - gzt = secFloor + ms->size.height; + if(floorAdjust && fitBottom && gzt - ms.dimensions().height() < secFloor) + gzt = secFloor + ms.dimensions().height(); } // Adjust by the floor clip. gzt -= floorClip; getLightingParams(vis->origin[VX], vis->origin[VY], - gzt - ms->size.height / 2.0f, + gzt - ms.dimensions().height() / 2.0f, mo->bspLeaf, vis->distance, fullBright, ambientColor, &vLightListIdx); setupSpriteParamsForVisSprite(&vis->data.sprite, vis->origin[VX], vis->origin[VY], - gzt - ms->size.height / 2.0f, + gzt - ms.dimensions().height() / 2.0f, vis->distance, visOff[VX], visOff[VY], visOff[VZ], secFloor, secCeil, @@ -1279,7 +1279,6 @@ void R_ProjectSprite(mobj_t *mo) spriteframe_t* sprFrame; material_t* mat; const materialvariantspecification_t* spec; - const materialsnapshot_t* ms; const pointlight_analysis_t* pl; // Determine the sprite frame lump of the source. @@ -1302,12 +1301,12 @@ void R_ProjectSprite(mobj_t *mo) // Ensure we have up-to-date information about the material. spec = Materials_VariantSpecificationForContext(MC_SPRITE, 0, 1, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 1,-2, -1, true, true, true, false); - ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - pl = (pointlight_analysis_t const *) Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), TA_SPRITE_AUTOLIGHT); + pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_SPRITE_AUTOLIGHT); if(!pl) { - QByteArray uri = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText().toUtf8(); + QByteArray uri = ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri().asText().toUtf8(); Con_Error("R_ProjectSprite: Texture \"%s\" has no TA_SPRITE_AUTOLIGHT analysis", uri.constData()); } @@ -1324,7 +1323,7 @@ void R_ProjectSprite(mobj_t *mo) flareSize = pl->brightMul; // X offset to the flare position. - xOffset = ms->size.width * pl->originX - -tex.origin().x(); + xOffset = ms.dimensions().width() * pl->originX - -tex.origin().x(); // Does the mobj have an active light definition? if(def) diff --git a/doomsday/engine/src/render/rend_console.c b/doomsday/engine/src/render/rend_console.cpp similarity index 78% rename from doomsday/engine/src/render/rend_console.c rename to doomsday/engine/src/render/rend_console.cpp index 44d6f685b9..e219cb1250 100644 --- a/doomsday/engine/src/render/rend_console.c +++ b/doomsday/engine/src/render/rend_console.cpp @@ -1,32 +1,25 @@ -/**\file rend_console.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file rend_console.cpp Console Rendering. * - *\author Copyright © 2006-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2005-2012 Daniel Swanson * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 + * 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 */ -/** - * Console rendering. - */ - -#include +#include +#include #include "de_base.h" #include "de_console.h" @@ -35,6 +28,7 @@ #include "de_resource.h" #include "de_ui.h" +#include "resource/materialsnapshot.h" #include "cbuffer.h" // Console (display) Modes: @@ -45,14 +39,14 @@ typedef enum { CM_CUSTOM // Some other offset positioned by the user. } consolemode_t; -void Rend_ConsoleUpdateBackground(void); +void Rend_ConsoleUpdateBackground(); float ConsoleOpenY; // Where the console bottom is when open. float consoleMoveSpeed = .5f; // Speed of console opening/closing. float consoleBackgroundAlpha = .75f; float consoleBackgroundLight = .14f; -Uri* consoleBackgroundMaterialUri = NULL; +Uri *consoleBackgroundMaterialUri; int consoleBackgroundTurn = 0; // The rotation variable. float consoleBackgroundZoom = 1.0f; @@ -68,34 +62,33 @@ static float ConsoleDestY; // Where the console bottom should be? static float ConsoleBlink; // Cursor blink timer (35 Hz tics). static boolean openingOrClosing; static float consoleAlpha, consoleAlphaTarget; -static material_t* consoleBackgroundMaterial; +static material_t *consoleBackgroundMaterial; static float fontSy; // Font size Y. static float funnyAng; -static const float CcolYellow[3] = { 1, .85f, .3f }; -static const char* consoleTitle = DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT; +static float const CcolYellow[3] = { 1, .85f, .3f }; +static char const *consoleTitle = DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT; static char secondaryTitleText[256]; static char statusText[256]; -void Rend_ConsoleRegister(void) +void Rend_ConsoleRegister() { - C_VAR_FLOAT("con-background-alpha", &consoleBackgroundAlpha, 0, 0, 1); - C_VAR_FLOAT("con-background-light", &consoleBackgroundLight, 0, 0, 1); - C_VAR_URIPTR2("con-background-material", &consoleBackgroundMaterialUri, - 0, 0, 0, Rend_ConsoleUpdateBackground); - C_VAR_INT("con-background-turn", &consoleBackgroundTurn, CVF_NO_MIN|CVF_NO_MAX, 0, 0); - C_VAR_FLOAT("con-background-zoom", &consoleBackgroundZoom, 0, 0.1f, 100.0f); - C_VAR_BYTE("con-fps", &consoleShowFPS, 0, 0, 1); - C_VAR_FLOAT("con-move-speed", &consoleMoveSpeed, 0, 0, 1); - C_VAR_BYTE("con-text-shadow", &consoleTextShadow, 0, 0, 1); + C_VAR_FLOAT ("con-background-alpha", &consoleBackgroundAlpha, 0, 0, 1); + C_VAR_FLOAT ("con-background-light", &consoleBackgroundLight, 0, 0, 1); + C_VAR_URIPTR2("con-background-material", &consoleBackgroundMaterialUri, 0, 0, 0, Rend_ConsoleUpdateBackground); + C_VAR_INT ("con-background-turn", &consoleBackgroundTurn, CVF_NO_MIN|CVF_NO_MAX, 0, 0); + C_VAR_FLOAT ("con-background-zoom", &consoleBackgroundZoom, 0, 0.1f, 100.0f); + C_VAR_BYTE ("con-fps", &consoleShowFPS, 0, 0, 1); + C_VAR_FLOAT ("con-move-speed", &consoleMoveSpeed, 0, 0, 1); + C_VAR_BYTE ("con-text-shadow", &consoleTextShadow, 0, 0, 1); } -static float calcConsoleTitleBarHeight(void) +static float calcConsoleTitleBarHeight() { int oldFont, border = Window_Width(theWindow) / 120, height; - assert(inited); + DENG_ASSERT(inited); oldFont = FR_Font(); FR_SetFont(fontVariable[FS_BOLD]); @@ -104,16 +97,17 @@ static float calcConsoleTitleBarHeight(void) return height; } -static __inline int calcConsoleMinHeight(void) +static inline int calcConsoleMinHeight() { - assert(inited); + DENG_ASSERT(inited); return fontSy * 1.5f + calcConsoleTitleBarHeight() / Window_Height(theWindow) * SCREENHEIGHT; } -void Rend_ConsoleInit(void) +void Rend_ConsoleInit() { if(!inited) - { // First init. + { + // First init. consoleMode = CM_HALFSCREEN; ConsoleY = 0; ConsoleOpenY = SCREENHEIGHT/2; @@ -124,8 +118,8 @@ void Rend_ConsoleInit(void) consoleAlphaTarget = 0; funnyAng = 0; ConsoleBlink = 0; - memset(secondaryTitleText, 0, sizeof(secondaryTitleText)); - memset(statusText, 0, sizeof(statusText)); + std::memset(secondaryTitleText, 0, sizeof(secondaryTitleText)); + std::memset(statusText, 0, sizeof(statusText)); } consoleBackgroundMaterial = 0; @@ -180,7 +174,7 @@ boolean Rend_ConsoleResize(boolean force) return needResize; } -void Rend_ConsoleCursorResetBlink(void) +void Rend_ConsoleCursorResetBlink() { if(!inited) return; ConsoleBlink = 0; @@ -189,11 +183,11 @@ void Rend_ConsoleCursorResetBlink(void) // Calculate the average of the given color flags. static void calcAvgColor(int fl, float rgb[3]) { - int count = 0; - assert(inited && rgb); + DENG_ASSERT(inited && rgb); rgb[CR] = rgb[CG] = rgb[CB] = 0; + int count = 0; if(fl & CBLF_BLACK) { ++count; @@ -256,15 +250,13 @@ static void calcAvgColor(int fl, float rgb[3]) static void drawRuler(int x, int y, int lineWidth, int lineHeight, float alpha) { - int xoff = 3, yoff = lineHeight / 4, rh = MIN_OF(5, lineHeight / 2); - Point2Raw origin; - Size2Raw size; - assert(inited); + DENG_ASSERT(inited); - origin.x = x + xoff; - origin.y = y + yoff + (lineHeight - rh) / 2; - size.width = lineWidth - 2 * xoff; - size.height = rh; + int xoff = 3; + int yoff = lineHeight / 4; + int rh = MIN_OF(5, lineHeight / 2); + Point2Raw origin(x + xoff, y + yoff + (lineHeight - rh) / 2); + Size2Raw size(lineWidth - 2 * xoff, rh); UI_GradientEx(&origin, &size, rh / 3, UI_Color(UIC_SHADOW), UI_Color(UIC_BG_DARK), alpha / 2, alpha); UI_DrawRectEx(&origin, &size, -rh / 3, false, UI_Color(UIC_BRD_HI), 0, 0, alpha / 3); @@ -274,42 +266,44 @@ static void drawRuler(int x, int y, int lineWidth, int lineHeight, float alpha) * Initializes the Doomsday console user interface. This is called when * engine startup is complete. */ -void Rend_ConsoleUpdateTitle(void) +void Rend_ConsoleUpdateTitle() { if(isDedicated || !inited) return; // Update the secondary title and the game status. if(DD_GameLoaded()) { - dd_snprintf(secondaryTitleText, sizeof(secondaryTitleText)-1, "%s", (char*) gx.GetVariable(DD_PLUGIN_NICENAME)); + dd_snprintf(secondaryTitleText, sizeof(secondaryTitleText)-1, "%s", (char *) gx.GetVariable(DD_PLUGIN_NICENAME)); strncpy(statusText, Str_Text(Game_Title(App_CurrentGame())), sizeof(statusText) - 1); return; } // No game currently loaded. - memset(secondaryTitleText, 0, sizeof(secondaryTitleText)); - memset(statusText, 0, sizeof(statusText)); + std::memset(secondaryTitleText, 0, sizeof(secondaryTitleText)); + std::memset(statusText, 0, sizeof(statusText)); } -void Rend_ConsoleUpdateBackground(void) +void Rend_ConsoleUpdateBackground() { - assert(inited); + DENG_ASSERT(inited); if(!consoleBackgroundMaterialUri || Str_IsEmpty(Uri_Path(consoleBackgroundMaterialUri))) return; consoleBackgroundMaterial = Materials_ToMaterial(Materials_ResolveUri(consoleBackgroundMaterialUri)); } -void Rend_ConsoleToggleFullscreen(void) +void Rend_ConsoleToggleFullscreen() { - float y; - if(isDedicated || !inited) return; if(needResize) { - /// \todo enqueue toggle (don't resize here, do it in the ticker). + /// @todo enqueue toggle (don't resize here, do it in the ticker). return; } - if(++consoleMode > CM_SINGLELINE) consoleMode = CM_HALFSCREEN; + // Cycle to the next mode. + consoleMode = consolemode_t(int(consoleMode) + 1); + if(consoleMode > CM_SINGLELINE) consoleMode = CM_HALFSCREEN; + + float y; switch(consoleMode) { case CM_HALFSCREEN: default: y = SCREENHEIGHT/2; break; @@ -381,11 +375,9 @@ void Rend_ConsoleMove(int numLines) void Rend_ConsoleTicker(timespan_t time) { - float step; - if(isDedicated || !inited) return; - step = time * 35; + float step = time * 35; // Move the console alpha to the target. if(consoleAlphaTarget > consoleAlpha) @@ -443,12 +435,9 @@ void Rend_ConsoleTicker(timespan_t time) ConsoleBlink += step; // Cursor blink timer (0 = visible). } -void Rend_ConsoleFPS(const Point2Raw* origin) +void Rend_ConsoleFPS(Point2Raw const *origin) { - Point2Raw topLeft, labelOrigin; - char buf[160]; - Size2Raw size; - assert(origin); + DENG_ASSERT(origin); if(isDedicated || !inited) return; if(!consoleShowFPS) return; @@ -456,27 +445,26 @@ void Rend_ConsoleFPS(const Point2Raw* origin) // Try to fulfill any pending resize. if(Rend_ConsoleResize(false/*no force*/)) return; // No FPS counter for you... - sprintf(buf, "%.1f FPS", DD_GetFrameRate()); + char buf[160]; + dd_snprintf(buf, 160, "%.1f FPS", DD_GetFrameRate()); FR_SetFont(fontFixed); FR_PushAttrib(); FR_LoadDefaultAttrib(); FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET); FR_SetShadowStrength(UI_SHADOW_STRENGTH); - size.width = FR_TextWidth(buf) + 16; - size.height = FR_SingleLineHeight(buf) + 16; + + Size2Raw size(FR_TextWidth(buf) + 16, FR_SingleLineHeight(buf) + 16); LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); glEnable(GL_TEXTURE_2D); - topLeft.x = origin->x - size.width; - topLeft.y = origin->y; + Point2Raw topLeft(origin->x - size.width, origin->y); UI_GradientEx(&topLeft, &size, 6, UI_Color(UIC_BG_MEDIUM), UI_Color(UIC_BG_LIGHT), .5f, .8f); UI_DrawRectEx(&topLeft, &size, 6, false, UI_Color(UIC_BRD_HI), UI_Color(UIC_BG_MEDIUM), .2f, -1); - labelOrigin.x = origin->x - 8; - labelOrigin.y = origin->y + size.height / 2; + Point2Raw labelOrigin(origin->x - 8, origin->y + size.height / 2); UI_SetColor(UI_Color(UIC_TEXT)); UI_TextOutEx2(buf, &labelOrigin, UI_Color(UIC_TITLE), 1, ALIGN_RIGHT, DTF_ONLY_SHADOW); @@ -487,15 +475,12 @@ void Rend_ConsoleFPS(const Point2Raw* origin) static void drawConsoleTitleBar(float alpha) { - int border, barHeight; - Point2Raw origin; - Size2Raw size; - assert(inited); + DENG_ASSERT(inited); if(alpha < .0001f) return; - border = Window_Width(theWindow) / 120; - barHeight = calcConsoleTitleBarHeight(); + int border = Window_Width(theWindow) / 120; + int barHeight = calcConsoleTitleBarHeight(); LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -504,10 +489,8 @@ static void drawConsoleTitleBar(float alpha) glPushMatrix(); glEnable(GL_TEXTURE_2D); - origin.x = 0; - origin.y = 0; - size.width = Window_Width(theWindow); - size.height = barHeight; + Point2Raw origin(0, 0); + Size2Raw size(Window_Width(theWindow), barHeight); UI_Gradient(&origin, &size, UI_Color(UIC_BG_MEDIUM), UI_Color(UIC_BG_LIGHT), .95f * alpha, alpha); origin.x = 0; @@ -554,21 +537,22 @@ static void drawConsoleTitleBar(float alpha) glPopMatrix(); } -static void drawConsoleBackground(const Point2Raw* origin, const Size2Raw* size, float closeFade) +static void drawConsoleBackground(Point2Raw const *origin, Size2Raw const *size, float closeFade) { + DENG_ASSERT(inited); + int bgX = 0, bgY = 0; - assert(inited); if(consoleBackgroundMaterial) { - const materialvariantspecification_t* spec = Materials_VariantSpecificationForContext( + materialvariantspecification_t const *spec = Materials_VariantSpecificationForContext( MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, 0, 1, 0, false, false, false, false); - const materialsnapshot_t* ms = Materials_Prepare(consoleBackgroundMaterial, spec, Con_IsActive()); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(consoleBackgroundMaterial, spec, Con_IsActive())); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); - bgX = (int) (ms->size.width * consoleBackgroundZoom); - bgY = (int) (ms->size.height * consoleBackgroundZoom); + bgX = int(ms.dimensions().width() * consoleBackgroundZoom); + bgY = int(ms.dimensions().height() * consoleBackgroundZoom); glEnable(GL_TEXTURE_2D); if(consoleBackgroundTurn != 0) @@ -598,30 +582,32 @@ static void drawConsoleBackground(const Point2Raw* origin, const Size2Raw* size, /** * Draw a 'side' text in the console. This is intended for extra * information about the current game mode. - * - * \note Currently unused. */ -static void drawSideText(const char* text, int line, float alpha) +#if 0 +static void drawSideText(char const *text, int line, float alpha) { - float gtosMulY = Window_Height(theWindow) / 200.0f, fontScaledY, y, scale[2]; - char buf[300]; - int ssw; - assert(inited); + DENG_ASSERT(inited); + + float const gtosMulY = Window_Height(theWindow) / 200.0f; FR_SetFont(Con_Font()); FR_PushAttrib(); FR_LoadDefaultAttrib(); + + float scale[2]; Con_FontScale(&scale[0], &scale[1]); - fontScaledY = FR_SingleLineHeight("Con") * scale[1]; - y = ConsoleY * gtosMulY - fontScaledY * (1 + line); + + float fontScaledY = FR_SingleLineHeight("Con") * scale[1]; + float y = ConsoleY * gtosMulY - fontScaledY * (1 + line); if(y > -fontScaledY) { con_textfilter_t printFilter = Con_PrintFilter(); // Scaled screen width. - ssw = (int) (Window_Width(theWindow) / scale[0]); + int ssw = int(Window_Width(theWindow) / scale[0]); + char buf[300]; if(printFilter) { strncpy(buf, text, sizeof(buf)); @@ -635,14 +621,14 @@ static void drawSideText(const char* text, int line, float alpha) FR_PopAttrib(); } +#endif -static void escapeFormatting(ddstring_t* dest, const char* src, int maxSourceLen) +static void escapeFormatting(ddstring_t *dest, char const *src, int maxSourceLen) { - int i = 0; - if(!src) return; + Str_Clear(dest); - for(; *src; ++src, ++i) + for(int i = 0; *src; ++src, ++i) { if(maxSourceLen && i == maxSourceLen) break; if(*src == '{') @@ -653,10 +639,10 @@ static void escapeFormatting(ddstring_t* dest, const char* src, int maxSourceLen } } -static void applyFilter(char* buff) +static void applyFilter(char *buff) { con_textfilter_t printFilter = Con_PrintFilter(); - ddstring_t* escaped = Str_New(); + ddstring_t *escaped = Str_New(); escapeFormatting(escaped, buff, 0); strcpy(buff, Str_Text(escaped)); @@ -669,29 +655,30 @@ static void applyFilter(char* buff) } /** - * \note Slightly messy... + * @note Slightly messy... */ static void drawConsole(float consoleAlpha) { -#define XORIGIN (0) -#define YORIGIN (0) -#define PADDING (2) -#define LOCALBUFFSIZE (CMDLINE_SIZE +1/*prompt length*/ +1/*terminator*/) + DENG_ASSERT(inited); + + int const XORIGIN = 0; + int const YORIGIN = 0; + int const PADDING = 2; + int const LOCALBUFFSIZE = (CMDLINE_SIZE +1/*prompt length*/ +1/*terminator*/); - static const cbline_t** lines = 0; + static cbline_t const **lines = 0; static int bufferSize = 0; - CBuffer* buffer = Con_HistoryBuffer(); + CBuffer *buffer = Con_HistoryBuffer(); uint cmdCursor = Con_CommandLineCursorPosition(); - char* cmdLine = Con_CommandLine(); + char *cmdLine = Con_CommandLine(); float scale[2], y, fontScaledY, gtosMulY = Window_Height(theWindow) / 200.0f; char buff[LOCALBUFFSIZE]; - font_t* cfont; + font_t *cfont; int lineHeight, textOffsetY; uint reqLines, maxLineLength; Point2Raw origin; Size2Raw size; - assert(inited); LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -756,7 +743,7 @@ static void drawConsole(float consoleAlpha) // Need to enlarge the buffer? if(reqLines > (uint) bufferSize) { - lines = Z_Realloc((void*) lines, sizeof(cbline_t *) * (reqLines + 1), PU_APPSTATIC); + lines = (cbline_t const **) Z_Realloc((void *) lines, sizeof(cbline_t *) * (reqLines + 1), PU_APPSTATIC); bufferSize = reqLines; } @@ -765,10 +752,9 @@ static void drawConsole(float consoleAlpha) { glEnable(GL_TEXTURE_2D); - { uint i; - for(i = count; i-- > 0;) + for(uint i = count; i-- > 0;) { - const cbline_t* line = lines[i]; + cbline_t const *line = lines[i]; if(line->flags & CBLF_RULER) { @@ -783,7 +769,7 @@ static void drawConsole(float consoleAlpha) short textFlags = DTF_NO_TYPEIN|DTF_NO_GLITTER|(!consoleTextShadow?DTF_NO_SHADOW:0); float xOffset; - memset(buff, 0, sizeof(buff)); + std::memset(buff, 0, sizeof(buff)); strncpy(buff, line->text, LOCALBUFFSIZE-1); if(line->flags & CBLF_CENTER) @@ -812,14 +798,14 @@ static void drawConsole(float consoleAlpha) // Move up. y -= fontScaledY; - }} + } glDisable(GL_TEXTURE_2D); } } // The command line. - { boolean abbrevLeft = 0, abbrevRight = 0; + boolean abbrevLeft = 0, abbrevRight = 0; int offset = 0; uint cmdLineLength; @@ -849,18 +835,16 @@ static void drawConsole(float consoleAlpha) // Apply filtering. /// @todo Clean this up; use a common applyFilter() function. - { - ddstring_t* escaped = Str_New(); - escapeFormatting(escaped, cmdLine + offset, maxLineLength); + ddstring_t *escaped = Str_New(); + escapeFormatting(escaped, cmdLine + offset, maxLineLength); - dd_snprintf(buff, LOCALBUFFSIZE - 1/*terminator*/, ">%s%s%s", - abbrevLeft? "{alpha=.5}[...]{alpha=1}" : "", - Str_Text(escaped), - abbrevRight? "{alpha=.5}[...]" : ""); + dd_snprintf(buff, LOCALBUFFSIZE - 1/*terminator*/, ">%s%s%s", + abbrevLeft? "{alpha=.5}[...]{alpha=1}" : "", + Str_Text(escaped), + abbrevRight? "{alpha=.5}[...]" : ""); - Str_Delete(escaped); - if(Con_PrintFilter()) (Con_PrintFilter())(buff); - } + Str_Delete(escaped); + if(Con_PrintFilter()) (Con_PrintFilter())(buff); glEnable(GL_TEXTURE_2D); if(Font_Flags(cfont) & FF_COLORIZE) @@ -883,7 +867,7 @@ static void drawConsole(float consoleAlpha) char temp[LOCALBUFFSIZE]; // Where is the cursor? - memset(temp, 0, sizeof(temp)); + std::memset(temp, 0, sizeof(temp)); //strncpy(temp, cmdLine + offset, MIN_OF(LOCALBUFFSIZE -1/*prompt length*/ /*-1*//*vis clamp*/, cmdCursor-offset + (abbrevLeft? 24/*abbrev length*/:0) + 1)); strcpy(temp, ">"); if(abbrevLeft) strcat(temp, "[...]"); @@ -915,14 +899,9 @@ static void drawConsole(float consoleAlpha) // Restore the original matrices. glMatrixMode(GL_MODELVIEW); glPopMatrix(); - } -#undef LOCALBUFFSIZE -#undef PADDING -#undef YORIGIN -#undef XORIGIN } -void Rend_Console(void) +void Rend_Console() { boolean consoleShow; @@ -948,9 +927,8 @@ void Rend_Console(void) if(consoleShowFPS && !UI_IsActive()) { - Point2Raw origin; - origin.x = Window_Width(theWindow) - 10; - origin.y = 10 + (ConsoleY > 0? ROUND(consoleAlpha * calcConsoleTitleBarHeight()) : 0); + Point2Raw origin(Window_Width(theWindow) - 10, + 10 + (ConsoleY > 0? ROUND(consoleAlpha * calcConsoleTitleBarHeight()) : 0)); Rend_ConsoleFPS(&origin); } diff --git a/doomsday/engine/src/render/rend_fakeradio.c b/doomsday/engine/src/render/rend_fakeradio.cpp similarity index 74% rename from doomsday/engine/src/render/rend_fakeradio.c rename to doomsday/engine/src/render/rend_fakeradio.cpp index b39547b08c..23fd89cebd 100644 --- a/doomsday/engine/src/render/rend_fakeradio.c +++ b/doomsday/engine/src/render/rend_fakeradio.cpp @@ -1,27 +1,25 @@ -/**\file rend_fakeradio.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file rend_fakeradio.cpp Faked Radiosity Lighting. * - *\author Copyright © 2004-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2004-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 + * 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 */ +#include + #include "de_base.h" #include "de_console.h" #include "de_render.h" @@ -31,6 +29,7 @@ #include "gl/sys_opengl.h" #include +#include "resource/materialsnapshot.h" #include "resource/materialvariant.h" #include "render/rendpoly.h" @@ -45,26 +44,26 @@ typedef struct edge_s { boolean done; - LineDef* line; - Sector* sector; + LineDef *line; + Sector *sector; float length; binangle_t diff; } edge_t; static void scanEdges(shadowcorner_t topCorners[2], shadowcorner_t bottomCorners[2], - shadowcorner_t sideCorners[2], edgespan_t spans[2], const LineDef* line, boolean backSide); + shadowcorner_t sideCorners[2], edgespan_t spans[2], LineDef const *line, boolean backSide); int rendFakeRadio = true; ///< cvar float rendFakeRadioDarkness = 1.2f; ///< cvar static byte devFakeRadioUpdate = true; ///< cvar -void Rend_RadioRegister(void) +void Rend_RadioRegister() { - C_VAR_INT("rend-fakeradio", &rendFakeRadio, 0, 0, 2); - C_VAR_FLOAT("rend-fakeradio-darkness", &rendFakeRadioDarkness, 0, 0, 2); + C_VAR_INT ("rend-fakeradio", &rendFakeRadio, 0, 0, 2); + C_VAR_FLOAT("rend-fakeradio-darkness", &rendFakeRadioDarkness, 0, 0, 2); - C_VAR_BYTE("rend-dev-fakeradio-update", &devFakeRadioUpdate, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-fakeradio-update", &devFakeRadioUpdate, CVF_NO_ARCHIVE, 0, 1); } float Rend_RadioCalcShadowDarkness(float lightLevel) @@ -72,26 +71,23 @@ float Rend_RadioCalcShadowDarkness(float lightLevel) return (0.6f - lightLevel * 0.4f) * 0.65f * rendFakeRadioDarkness; } -void Rend_RadioUpdateLinedef(LineDef* line, boolean backSide) +void Rend_RadioUpdateLinedef(LineDef *line, boolean backSide) { - SideDef* s; - uint i; - - // Fakeradio disabled? + // Disabled completely? if(!rendFakeRadio || levelFullBright) return; - // Update disabled? + // Updates are disabled? if(!devFakeRadioUpdate) return; // Sides without sectors don't need updating. $degenleaf if(!line || !line->L_sector(backSide)) return; // Have already determined the shadow properties on this side? - s = line->L_sidedef(backSide); + SideDef *s = line->L_sidedef(backSide); if(s->fakeRadioUpdateCount == frameCount) return; // Not yet - Calculate now. - for(i = 0; i < 2; ++i) + for(uint i = 0; i < 2; ++i) { s->spans[i].length = line->length; s->spans[i].shift = 0; @@ -104,11 +100,11 @@ void Rend_RadioUpdateLinedef(LineDef* line, boolean backSide) /** * Set the vertex colors in the rendpoly. */ -static void setRendpolyColor(ColorRawf* rcolors, uint num, const float shadowRGB[3], float darkness) +static void setRendpolyColor(ColorRawf *rcolors, uint num, float const shadowRGB[3], float darkness) { - uint i; darkness = MINMAX_OF(0, darkness, 1); - for(i = 0; i < num; ++i) + + for(uint i = 0; i < num; ++i) { rcolors[i].rgba[CR] = shadowRGB[CR]; rcolors[i].rgba[CG] = shadowRGB[CG]; @@ -118,7 +114,7 @@ static void setRendpolyColor(ColorRawf* rcolors, uint num, const float shadowRGB } /// @return @c true, if there is open space in the sector. -static __inline boolean isSectorOpen(Sector* sector) +static inline boolean isSectorOpen(Sector *sector) { return (sector && sector->SP_ceilheight > sector->SP_floorheight); } @@ -128,7 +124,7 @@ static __inline boolean isSectorOpen(Sector* sector) * * @param length If negative; implies that the texture is flipped horizontally. */ -static __inline float calcTexCoordX(float lineLength, float segOffset) +static inline float calcTexCoordX(float lineLength, float segOffset) { if(lineLength > 0) return segOffset; return lineLength + segOffset; @@ -139,27 +135,27 @@ static __inline float calcTexCoordX(float lineLength, float segOffset) * * @param size If negative; implies that the texture is flipped vertically. */ -static __inline float calcTexCoordY(float z, float bottom, float top, float texHeight) +static inline float calcTexCoordY(float z, float bottom, float top, float texHeight) { if(texHeight > 0) return top - z; return bottom - z; } /// @todo This algorithm should be rewritten to work at HEdge level. -static void scanNeighbor(boolean scanTop, const LineDef* line, uint side, - edge_t* edge, boolean toLeft) +static void scanNeighbor(boolean scanTop, LineDef const *line, uint side, + edge_t *edge, boolean toLeft) { -#define SEP (10) + int const SEP = 10; - LineDef* iter; - lineowner_t* own; + LineDef *iter; + lineowner_t *own; binangle_t diff = 0; coord_t lengthDelta = 0, gap = 0; coord_t iFFloor, iFCeil; coord_t iBFloor, iBCeil; int scanSecSide = side; - Sector* startSector = line->L_sector(side); - Sector* scanSector; + Sector *startSector = line->L_sector(side); + Sector *scanSector; boolean clockwise = toLeft; boolean stopScan = false; boolean closed; @@ -364,34 +360,27 @@ static void scanNeighbor(boolean scanTop, const LineDef* line, uint side, edge->line->vo[(edge->line->L_backsidedef && edge->line->L_backsector == edge->sector)^!toLeft], !toLeft, &edge->diff); } - -#undef SEP } static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2], - const LineDef* line, uint side, edgespan_t spans[2], boolean toLeft) + LineDef const *line, uint side, edgespan_t spans[2], boolean toLeft) { - uint i; - edge_t edges[2], *edge; // {bottom, top} - edgespan_t* span; - shadowcorner_t* corner; - coord_t fCeil, fFloor; - if(LINE_SELFREF(line)) return; - fFloor = line->L_sector(side)->SP_floorvisheight; - fCeil = line->L_sector(side)->SP_ceilvisheight; + coord_t fFloor = line->L_sector(side)->SP_floorvisheight; + coord_t fCeil = line->L_sector(side)->SP_ceilvisheight; - memset(edges, 0, sizeof(edges)); + edge_t edges[2]; // {bottom, top} + std::memset(edges, 0, sizeof(edges)); scanNeighbor(false, line, side, &edges[0], toLeft); scanNeighbor(true, line, side, &edges[1], toLeft); - for(i = 0; i < 2; ++i) // 0=bottom, 1=top + for(uint i = 0; i < 2; ++i) { - corner = (i == 0 ? &bottom[!toLeft] : &top[!toLeft]); - edge = &edges[i]; - span = &spans[i]; + shadowcorner_t *corner = (i == 0 ? &bottom[!toLeft] : &top[!toLeft]); + edge_t *edge = &edges[i]; + edgespan_t *span = &spans[i]; // Increment the apparent line length/offset. span->length += edge->length; @@ -403,15 +392,18 @@ static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2], if(edge->line && edge->line != line) { if(edge->diff > BANG_180) - { // The corner between the walls faces outwards. + { + // The corner between the walls faces outwards. corner->corner = -1; } else if(edge->diff == BANG_180) - { // Perfectly coaligned? Great. + { + // Perfectly coaligned? Great. corner->corner = 0; } else if(edge->diff < BANG_45 / 5) - { // The difference is too small, there won't be a shadow. + { + // The difference is too small, there won't be a shadow. corner->corner = 0; } // 90 degrees is the largest effective difference. @@ -425,7 +417,8 @@ static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2], } } else - { // Consider it coaligned. + { + // Consider it coaligned. corner->corner = 0; } @@ -465,33 +458,26 @@ static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2], * but in most cases this won't take long. Aligned neighbours are relatively * rare. */ -static void scanEdges(shadowcorner_t topCorners[2], - shadowcorner_t bottomCorners[2], - shadowcorner_t sideCorners[2], edgespan_t spans[2], - const LineDef* line, boolean backSide) +static void scanEdges(shadowcorner_t topCorners[2], shadowcorner_t bottomCorners[2], + shadowcorner_t sideCorners[2], edgespan_t spans[2], LineDef const *line, + boolean backSide) { - uint i, sid = (backSide? BACK : FRONT); - SideDef* side; - LineDef* other; - - side = line->L_sidedef(sid); + uint const sid = (backSide? BACK : FRONT); - memset(sideCorners, 0, sizeof(shadowcorner_t) * 2); + std::memset(sideCorners, 0, sizeof(shadowcorner_t) * 2); // Find the sidecorners first: left and right neighbour. - for(i = 0; i < 2; ++i) + for(uint i = 0; i < 2; ++i) { - binangle_t diff = 0; - lineowner_t *vo; - - vo = line->L_vo(i^sid); + binangle_t diff = 0; + lineowner_t* vo = line->L_vo(i ^ sid); - other = R_FindSolidLineNeighbor(line->L_sector(sid), line, - vo, i, &diff); + LineDef* other = R_FindSolidLineNeighbor(line->L_sector(sid), line, vo, i, &diff); if(other && other != line) { if(diff > BANG_180) - { // The corner between the walls faces outwards. + { + // The corner between the walls faces outwards. sideCorners[i].corner = -1; } else if(diff == BANG_180) @@ -499,11 +485,13 @@ static void scanEdges(shadowcorner_t topCorners[2], sideCorners[i].corner = 0; } else if(diff < BANG_45 / 5) - { // The difference is too small, there won't be a shadow. + { + // The difference is too small, there won't be a shadow. sideCorners[i].corner = 0; } else if(diff > BANG_90) - { // 90 degrees is the largest effective difference. + { + // 90 degrees is the largest effective difference. sideCorners[i].corner = (float) BANG_90 / diff; } else @@ -521,23 +509,19 @@ static void scanEdges(shadowcorner_t topCorners[2], } typedef struct { - lightingtexid_t texture; - boolean horizontal; - float shadowMul; - float texWidth; - float texHeight; - float texOffset[2]; - float wallLength; + lightingtexid_t texture; + boolean horizontal; + float shadowMul; + float texWidth; + float texHeight; + float texOffset[2]; + float wallLength; } rendershadowseg_params_t; -static void setTopShadowParams(rendershadowseg_params_t* p, float size, - coord_t top, - const coord_t* xOffset, const coord_t* segLength, - const coord_t* fFloor, const coord_t* fCeil, - const shadowcorner_t* botCn, - const shadowcorner_t* topCn, - const shadowcorner_t* sideCn, - const edgespan_t* spans) +static void setTopShadowParams(rendershadowseg_params_t *p, float size, coord_t top, + coord_t const *xOffset, coord_t const *segLength, coord_t const *fFloor, coord_t const *fCeil, + shadowcorner_t const *botCn, shadowcorner_t const *topCn, shadowcorner_t const *sideCn, + edgespan_t const *spans) { p->shadowMul = 1; p->horizontal = false; @@ -557,13 +541,16 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, if((sideCn[0].corner == -1 && sideCn[1].corner == -1) || (topCn[0].corner == -1 && topCn[1].corner == -1)) - { // Both corners face outwards + { + // Both corners face outwards p->texture = LST_RADIO_OO;//CC; } else if(sideCn[1].corner == -1) - { // right corner faces outwards + { + // right corner faces outwards if(-topCn[0].pOffset < 0 && botCn[0].pHeight < *fCeil) - {// Must flip horizontally! + { + // Must flip horizontally! p->texWidth = -spans[TOP].length; p->texOffset[VX] = calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset); @@ -579,25 +566,30 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, } } else - { // Corners WITH a neighbour backsector + { + // Corners WITH a neighbour backsector p->texWidth = spans[TOP].length; - p->texOffset[VX] = - calcTexCoordX(spans[TOP].length, spans[TOP].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(spans[TOP].length, spans[TOP].shift + *xOffset); + if(topCn[0].corner == -1 && topCn[1].corner == -1) - { // Both corners face outwards + { + // Both corners face outwards p->texture = LST_RADIO_OO;//CC; } else if(topCn[1].corner == -1 && topCn[0].corner > MIN_OPEN) - { // Right corner faces outwards + { + // Right corner faces outwards p->texture = LST_RADIO_OO; } else if(topCn[0].corner == -1 && topCn[1].corner > MIN_OPEN) - { // Left corner faces outwards + { + // Left corner faces outwards p->texture = LST_RADIO_OO; } // Open edges else if(topCn[0].corner <= MIN_OPEN && topCn[1].corner <= MIN_OPEN) - { // Both edges are open + { + // Both edges are open p->texture = LST_RADIO_OO; if(topCn[0].proximity && topCn[1].proximity) { @@ -608,13 +600,13 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, if(size > -topCn[0].pOffset) { if(-topCn[0].pOffset < INDIFF) + { p->texture = LST_RADIO_OE; + } else { p->texHeight = -topCn[0].pOffset; - p->texOffset[VY] = - calcTexCoordY(top, *fFloor, *fCeil, - p->texHeight); + p->texOffset[VY] = calcTexCoordY(top, *fFloor, *fCeil, p->texHeight); } } } @@ -623,20 +615,19 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, // Must flip horizontally! p->texture = LST_RADIO_CO; p->texWidth = -spans[TOP].length; - p->texOffset[VX] = - calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset); // The shadow can't go over the higher edge. if(size > -topCn[1].pOffset) { if(-topCn[1].pOffset < INDIFF) + { p->texture = LST_RADIO_OE; + } else { p->texHeight = -topCn[1].pOffset; - p->texOffset[VY] = - calcTexCoordY(top, *fFloor, *fCeil, - p->texHeight); + p->texOffset[VY] = calcTexCoordY(top, *fFloor, *fCeil, p->texHeight); } } } @@ -648,12 +639,12 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, // Must flip horizontally! p->texture = LST_RADIO_OE; p->texWidth = -spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(-spans[BOTTOM].length, - spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); } else if(-topCn[1].pOffset < -MINDIFF) + { p->texture = LST_RADIO_OE; + } } } else if(topCn[0].corner <= MIN_OPEN) @@ -665,8 +656,7 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, // Must flip horizontally! p->texWidth = -spans[TOP].length; - p->texOffset[VX] = - calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset); } else if(topCn[1].corner <= MIN_OPEN) { @@ -682,14 +672,10 @@ static void setTopShadowParams(rendershadowseg_params_t* p, float size, } } -static void setBottomShadowParams(rendershadowseg_params_t *p, float size, - coord_t top, - const coord_t* xOffset, const coord_t* segLength, - const coord_t* fFloor, const coord_t* fCeil, - const shadowcorner_t* botCn, - const shadowcorner_t* topCn, - const shadowcorner_t* sideCn, - const edgespan_t* spans) +static void setBottomShadowParams(rendershadowseg_params_t *p, float size, coord_t top, + coord_t const *xOffset, coord_t const *segLength, coord_t const *fFloor, coord_t const *fCeil, + shadowcorner_t const *botCn, shadowcorner_t const *topCn, shadowcorner_t const *sideCn, + edgespan_t const *spans) { p->shadowMul = 1; p->horizontal = false; @@ -700,29 +686,31 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, p->texture = LST_RADIO_OO; // Corners without a neighbour backsector if(sideCn[0].corner == -1 || sideCn[1].corner == -1) - { // At least one corner faces outwards + { + // At least one corner faces outwards p->texture = LST_RADIO_OO; p->texWidth = spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); if((sideCn[0].corner == -1 && sideCn[1].corner == -1) || (botCn[0].corner == -1 && botCn[1].corner == -1) ) - { // Both corners face outwards + { + // Both corners face outwards p->texture = LST_RADIO_OO;//CC; } else if(sideCn[1].corner == -1) // right corner faces outwards { if(botCn[0].pOffset < 0 && topCn[0].pHeight > *fFloor) - { // Must flip horizontally! + { + // Must flip horizontally! p->texWidth = -spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); p->texture = LST_RADIO_OE; } } else - { // left corner faces outwards + { + // left corner faces outwards if(botCn[1].pOffset < 0 && topCn[1].pHeight > *fFloor) { p->texture = LST_RADIO_OE; @@ -732,23 +720,26 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, else { // Corners WITH a neighbour backsector p->texWidth = spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); if(botCn[0].corner == -1 && botCn[1].corner == -1) - { // Both corners face outwards + { + // Both corners face outwards p->texture = LST_RADIO_OO;//CC; } else if(botCn[1].corner == -1 && botCn[0].corner > MIN_OPEN) - { // Right corner faces outwards + { + // Right corner faces outwards p->texture = LST_RADIO_OO; } else if(botCn[0].corner == -1 && botCn[1].corner > MIN_OPEN) - { // Left corner faces outwards + { + // Left corner faces outwards p->texture = LST_RADIO_OO; } // Open edges else if(botCn[0].corner <= MIN_OPEN && botCn[1].corner <= MIN_OPEN) - { // Both edges are open + { + // Both edges are open p->texture = LST_RADIO_OO; if(botCn[0].proximity && botCn[1].proximity) @@ -760,13 +751,13 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, if(size > botCn[0].pOffset) { if(botCn[0].pOffset < INDIFF) + { p->texture = LST_RADIO_OE; + } else { p->texHeight = -botCn[0].pOffset; - p->texOffset[VY] = - calcTexCoordY(top, *fFloor, *fCeil, - p->texHeight); + p->texOffset[VY] = calcTexCoordY(top, *fFloor, *fCeil, p->texHeight); } } } @@ -775,20 +766,18 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, // Must flip horizontally! p->texture = LST_RADIO_CO; p->texWidth = -spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(-spans[BOTTOM].length, - spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); if(size > botCn[1].pOffset) { if(botCn[1].pOffset < INDIFF) + { p->texture = LST_RADIO_OE; + } else { p->texHeight = -botCn[1].pOffset; - p->texOffset[VY] = - calcTexCoordY(top, *fFloor, *fCeil, - p->texHeight); + p->texOffset[VY] = calcTexCoordY(top, *fFloor, *fCeil, p->texHeight); } } } @@ -800,12 +789,12 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, // Must flip horizontally! p->texture = LST_RADIO_OE; p->texWidth = -spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(-spans[BOTTOM].length, - spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); } else if(botCn[1].pOffset < -MINDIFF) + { p->texture = LST_RADIO_OE; + } } } else if(botCn[0].corner <= MIN_OPEN) // Right Corner is Closed @@ -817,8 +806,7 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, // Must flip horizontally! p->texWidth = -spans[BOTTOM].length; - p->texOffset[VX] = - calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); + p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset); } else if(botCn[1].corner <= MIN_OPEN) // Left Corner is closed { @@ -834,15 +822,11 @@ static void setBottomShadowParams(rendershadowseg_params_t *p, float size, } } -static void setSideShadowParams(rendershadowseg_params_t* p, - float size, coord_t bottom, coord_t top, - boolean rightSide, boolean bottomGlow, - boolean topGlow, - const coord_t* xOffset, const coord_t* segLength, - const coord_t* fFloor, const coord_t* fCeil, - const coord_t* bFloor, const coord_t* bCeil, - const coord_t* lineLength, - const shadowcorner_t* sideCn) +static void setSideShadowParams(rendershadowseg_params_t *p, float size, coord_t bottom, + coord_t top, boolean rightSide, boolean bottomGlow, boolean topGlow, + coord_t const *xOffset, coord_t const *segLength, coord_t const *fFloor, + coord_t const *fCeil, coord_t const *bFloor, coord_t const *bCeil, coord_t const *lineLength, + shadowcorner_t const *sideCn) { p->shadowMul = sideCn[rightSide? 1 : 0].corner * .8f; p->shadowMul *= p->shadowMul * p->shadowMul; @@ -852,7 +836,8 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->wallLength = *segLength; if(rightSide) - { // Right shadow. + { + // Right shadow. p->texOffset[VX] = -(*lineLength) + *xOffset; // Make sure the shadow isn't too big if(size > *lineLength) @@ -863,10 +848,13 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texWidth = -((*lineLength) / 2); } else + { p->texWidth = -size; + } } else - { // Left shadow. + { + // Left shadow. p->texOffset[VX] = *xOffset; // Make sure the shadow isn't too big if(size > *lineLength) @@ -877,11 +865,14 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texWidth = (*lineLength) / 2; } else + { p->texWidth = size; + } } if(bFloor) - { // There is a backside. + { + // There is a backside. if(*bFloor > *fFloor && *bCeil < *fCeil) { if(!bottomGlow && !topGlow) @@ -895,7 +886,9 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texture = LST_RADIO_CO; } else + { p->texture = LST_RADIO_CO; + } } else if(*bFloor > *fFloor) { @@ -910,7 +903,9 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texture = LST_RADIO_CO; } else + { p->texture = LST_RADIO_CO; + } } else if(*bCeil < *fCeil) { @@ -925,7 +920,9 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texture = LST_RADIO_CO; } else + { p->texture = LST_RADIO_CO; + } } } else @@ -937,21 +934,26 @@ static void setSideShadowParams(rendershadowseg_params_t* p, p->texture = LST_RADIO_CO; } else if(topGlow) + { p->texture = LST_RADIO_CO; + } else + { p->texture = LST_RADIO_CC; + } } } -static void quadTexCoords(rtexcoord_t* tc, const rvertex_t* rverts, - float wallLength, float texWidth, float texHeight, - float texOrigin[2][3], const float texOffset[2], - boolean horizontal) +static void quadTexCoords(rtexcoord_t *tc, rvertex_t const *rverts, float wallLength, + float texWidth, float texHeight, float texOrigin[2][3], float const texOffset[2], + boolean horizontal) { if(horizontal) - { // Special horizontal coordinates for wall shadows. + { + // Special horizontal coordinates for wall shadows. tc[0].st[0] = tc[2].st[0] = rverts[0].pos[VX] - texOrigin[0][VX] + texOffset[VY] / texHeight; tc[0].st[1] = tc[1].st[1] = rverts[0].pos[VY] - texOrigin[0][VY] + texOffset[VX] / texWidth; + tc[1].st[0] = tc[0].st[0] + (rverts[1].pos[VZ] - texOrigin[1][VZ]) / texHeight; tc[3].st[0] = tc[0].st[0] + (rverts[3].pos[VZ] - texOrigin[1][VZ]) / texHeight; tc[3].st[1] = tc[0].st[1] + wallLength / texWidth; @@ -959,22 +961,20 @@ static void quadTexCoords(rtexcoord_t* tc, const rvertex_t* rverts, return; } - tc[0].st[0] = tc[1].st[0] = rverts[0].pos[VX] - texOrigin[0][VX] + - texOffset[VX] / texWidth; - tc[3].st[1] = tc[1].st[1] = rverts[0].pos[VY] - texOrigin[0][VY] + - texOffset[VY] / texHeight; + tc[0].st[0] = tc[1].st[0] = rverts[0].pos[VX] - texOrigin[0][VX] + texOffset[VX] / texWidth; + tc[3].st[1] = tc[1].st[1] = rverts[0].pos[VY] - texOrigin[0][VY] + texOffset[VY] / texHeight; + tc[3].st[0] = tc[2].st[0] = tc[0].st[0] + wallLength / texWidth; tc[2].st[1] = tc[3].st[1] + (rverts[1].pos[VZ] - rverts[0].pos[VZ]) / texHeight; tc[0].st[1] = tc[3].st[1] + (rverts[3].pos[VZ] - rverts[2].pos[VZ]) / texHeight; } -static void renderShadowSeg(const rvertex_t* origVertices, - const rendershadowseg_params_t* segp, - const rendsegradio_params_t* p) +static void renderShadowSeg(rvertex_t const *origVertices, rendershadowseg_params_t const *segp, + rendsegradio_params_t const *p) { float texOrigin[2][3]; - ColorRawf* rcolors; - rtexcoord_t* rtexcoords; + ColorRawf *rcolors; + rtexcoord_t *rtexcoords; uint realNumVertices = 4; if(p->wall.left.divCount || p->wall.right.divCount) @@ -1010,26 +1010,24 @@ static void renderShadowSeg(const rvertex_t* origVertices, if(p->wall.left.divCount || p->wall.right.divCount) { - float bL, tL, bR, tR; - rvertex_t* rvertices; - rtexcoord_t origTexCoords[4]; - ColorRawf origColors[4]; - - /** + /* * Need to swap indices around into fans set the position * of the division vertices, interpolate texcoords and * color. */ - rvertices = R_AllocRendVertices(realNumVertices); + rvertex_t *rvertices = R_AllocRendVertices(realNumVertices); + + rtexcoord_t origTexCoords[4]; + std::memcpy(origTexCoords, rtexcoords, sizeof(rtexcoord_t) * 4); - memcpy(origTexCoords, rtexcoords, sizeof(rtexcoord_t) * 4); - memcpy(origColors, rcolors, sizeof(ColorRawf) * 4); + ColorRawf origColors[4]; + std::memcpy(origColors, rcolors, sizeof(ColorRawf) * 4); - bL = origVertices[0].pos[VZ]; - tL = origVertices[1].pos[VZ]; - bR = origVertices[2].pos[VZ]; - tR = origVertices[3].pos[VZ]; + float const bL = origVertices[0].pos[VZ]; + float const tL = origVertices[1].pos[VZ]; + float const bR = origVertices[2].pos[VZ]; + float const tR = origVertices[3].pos[VZ]; R_DivVerts(rvertices, origVertices, p->wall.left.firstDiv, p->wall.left.divCount, p->wall.right.firstDiv, p->wall.right.divCount); R_DivTexCoords(rtexcoords, origTexCoords, p->wall.left.firstDiv, p->wall.left.divCount, p->wall.right.firstDiv, p->wall.right.divCount, bL, tL, bR, tR); @@ -1057,26 +1055,15 @@ static void renderShadowSeg(const rvertex_t* origVertices, /** * Create the appropriate FakeRadio shadow polygons for the wall segment. */ -static void rendRadioSegSection(const rvertex_t* rvertices, - const rendsegradio_params_t* p) +static void rendRadioSegSection(rvertex_t const *rvertices, rendsegradio_params_t const *p) { - const coord_t* fFloor, *fCeil, *bFloor, *bCeil; - boolean bottomGlow, topGlow; - - bottomGlow = R_IsGlowingPlane(p->frontSec->SP_plane(PLN_FLOOR)); - topGlow = R_IsGlowingPlane(p->frontSec->SP_plane(PLN_CEILING)); + coord_t const *fFloor = &p->frontSec->SP_floorvisheight; + coord_t const *fCeil = &p->frontSec->SP_ceilvisheight; + coord_t const *bFloor = (p->backSec? &p->backSec->SP_floorvisheight : 0); + coord_t const *bCeil = (p->backSec? &p->backSec->SP_ceilvisheight : 0); - fFloor = &p->frontSec->SP_floorvisheight; - fCeil = &p->frontSec->SP_ceilvisheight; - if(p->backSec) - { - bFloor = &p->backSec->SP_floorvisheight; - bCeil = &p->backSec->SP_ceilvisheight; - } - else - { - bFloor = bCeil = NULL; - } + boolean const bottomGlow = R_IsGlowingPlane(p->frontSec->SP_plane(PLN_FLOOR)); + boolean const topGlow = R_IsGlowingPlane(p->frontSec->SP_plane(PLN_CEILING)); /* * Top Shadow. @@ -1149,7 +1136,7 @@ static void rendRadioSegSection(const rvertex_t* rvertices, } } -void Rend_RadioSegSection(const rvertex_t* rvertices, const rendsegradio_params_t* params) +void Rend_RadioSegSection(rvertex_t const *rvertices, rendsegradio_params_t const *params) { if(!rvertices || !params) return; // Disabled? @@ -1184,33 +1171,33 @@ static float radioEdgeOpenness(float fz, float bz, float bhz) return 2; } -static void setRelativeHeights(const Sector* front, const Sector* back, boolean isCeiling, - coord_t* fz, coord_t* bz, coord_t* bhz) +static void setRelativeHeights(Sector const *front, Sector const *back, boolean isCeiling, + coord_t *fz, coord_t *bz, coord_t *bhz) { if(fz) { - *fz = front->planes[isCeiling? PLN_CEILING:PLN_FLOOR]->visHeight; + *fz = front->planes[isCeiling? PLN_CEILING:PLN_FLOOR]->visHeight; if(isCeiling) *fz = -(*fz); } if(bz) { - *bz = back->planes[isCeiling? PLN_CEILING:PLN_FLOOR]->visHeight; + *bz = back->planes[isCeiling? PLN_CEILING:PLN_FLOOR]->visHeight; if(isCeiling) *bz = -(*bz); } if(bhz) { - *bhz = back->planes[isCeiling? PLN_FLOOR:PLN_CEILING]->visHeight; + *bhz = back->planes[isCeiling? PLN_FLOOR:PLN_CEILING]->visHeight; if(isCeiling) *bhz = -(*bhz); } } -static uint radioEdgeHackType(const LineDef* line, const Sector* front, const Sector* back, +static uint radioEdgeHackType(LineDef const *line, Sector const *front, Sector const *back, int backside, boolean isCeiling, float fz, float bz) { - Surface* surface = &line->L_sidedef(backside)->sections[isCeiling? SS_TOP:SS_BOTTOM]; + Surface *surface = &line->L_sidedef(backside)->sections[isCeiling? SS_TOP:SS_BOTTOM]; if(fz < bz && !surface->material && !(surface->inFlags & SUIF_FIX_MISSING_MATERIAL)) @@ -1225,13 +1212,15 @@ static uint radioEdgeHackType(const LineDef* line, const Sector* front, const Se return 3; // Consider it fully open. } else + { return 1; // Consider it fully closed. + } } // Check for unmasked midtextures on twosided lines that completely // fill the gap between floor and ceiling (we don't want to give away // the location of any secret areas (false walls)). - if(R_MiddleMaterialCoversLineOpening((LineDef*)line, backside, false)) + if(R_MiddleMaterialCoversLineOpening(const_cast(line), backside, false)) return 1; // Consider it fully closed. return 0; @@ -1241,27 +1230,24 @@ static uint radioEdgeHackType(const LineDef* line, const Sector* front, const Se * Construct and write a new shadow polygon to the rendering lists. */ static void addShadowEdge(vec2d_t inner[2], vec2d_t outer[2], coord_t innerLeftZ, - coord_t innerRightZ, coord_t outerLeftZ, coord_t outerRightZ, const float sideOpen[2], - const float edgeOpen[2], boolean isFloor, const float shadowRGB[3], float shadowDark) + coord_t innerRightZ, coord_t outerLeftZ, coord_t outerRightZ, float const sideOpen[2], + float const edgeOpen[2], boolean isFloor, float const shadowRGB[3], float shadowDark) { - static const uint floorIndices[][4] = {{0, 1, 2, 3}, {1, 2, 3, 0}}; - static const uint ceilIndices[][4] = {{0, 3, 2, 1}, {1, 0, 3, 2}}; + static uint const floorIndices[][4] = {{0, 1, 2, 3}, {1, 2, 3, 0}}; + static uint const ceilIndices[][4] = {{0, 3, 2, 1}, {1, 0, 3, 2}}; - rvertex_t rvertices[4]; - ColorRawf rcolors[4]; vec2f_t outerAlpha; - const uint* idx; - uint i, winding; // Winding: 0 = left, 1 = right - V2f_Set(outerAlpha, MIN_OF(shadowDark * (1 - edgeOpen[0]), 1), MIN_OF(shadowDark * (1 - edgeOpen[1]), 1)); if(!(outerAlpha[0] > .0001 && outerAlpha[1] > .0001)) return; - // What vertex winding order? + // What vertex winding order? (0 = left, 1 = right) // (for best results, the cross edge should always be the shortest). - winding = (V2d_Distance(inner[1], outer[1]) > V2d_Distance(inner[0], outer[0])? 1 : 0); + uint winding = (V2d_Distance(inner[1], outer[1]) > V2d_Distance(inner[0], outer[0])? 1 : 0); + uint const *idx = (isFloor ? floorIndices[winding] : ceilIndices[winding]); - idx = (isFloor ? floorIndices[winding] : ceilIndices[winding]); + rvertex_t rvertices[4]; + ColorRawf rcolors[4]; // Left outer corner. rvertices[idx[0]].pos[VX] = outer[0][VX]; @@ -1284,7 +1270,7 @@ static void addShadowEdge(vec2d_t inner[2], vec2d_t outer[2], coord_t innerLeftZ rvertices[idx[3]].pos[VZ] = innerLeftZ; // Light this polygon. - for(i = 0; i < 4; ++i) + for(uint i = 0; i < 4; ++i) { rcolors[idx[i]].rgba[CR] = (renderWireframe? 1 : shadowRGB[CR]); rcolors[idx[i]].rgba[CG] = (renderWireframe? 1 : shadowRGB[CG]); @@ -1313,46 +1299,40 @@ static void addShadowEdge(vec2d_t inner[2], vec2d_t outer[2], coord_t innerLeftZ RL_AddPoly(PT_FAN, RPF_DEFAULT | (!renderWireframe? RPF_SHADOW : 0), 4, rvertices, rcolors); } -static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, +static void processEdgeShadow(BspLeaf const *bspLeaf, LineDef const *lineDef, uint side, uint planeId, float shadowDark) { - const Plane* pln = lineDef->L_sector(side)->SP_plane(planeId); - vec2d_t inner[2], outer[2]; - vec2f_t edgeOpen, sideOpen; - const materialvariantspecification_t* spec; - const materialsnapshot_t* ms; - coord_t plnHeight, fz, bz, bhz; - Sector* front, *back; - const Surface* suf; - vec3f_t shadowRGB; - int i; - assert(bspLeaf && lineDef && (side == FRONT || side == BACK) && lineDef->L_sidedef(side) && planeId <= lineDef->L_sector(side)->planeCount); + DENG_ASSERT(bspLeaf); + DENG_ASSERT(lineDef && (side == FRONT || side == BACK) && lineDef->L_sidedef(side)); + DENG_ASSERT(planeId <= lineDef->L_sector(side)->planeCount); if(!(shadowDark > .0001)) return; - suf = &pln->surface; - plnHeight = pln->visHeight; + Plane const *pln = lineDef->L_sector(side)->SP_plane(planeId); + Surface const *suf = &pln->surface; + coord_t plnHeight = pln->visHeight; // Glowing surfaces or missing textures shouldn't have shadows. if((suf->inFlags & SUIF_NO_RADIO) || !suf->material || Surface_IsSkyMasked(suf)) return; - spec = Materials_VariantSpecificationForContext(MC_MAPSURFACE, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, - -1, -1, -1, true, true, false, false); - ms = Materials_Prepare(pln->PS_material, spec, true); - if(ms->glowing > 0) return; + materialvariantspecification_t const *spec = Rend_MapSurfaceDiffuseMaterialSpec(); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(pln->PS_material, spec, true)); + if(ms.glowStrength() > 0) return; // Determine the openness of the lineDef. If this edge is edgeOpen, // there won't be a shadow at all. Open neighbours cause some // changes in the polygon corner vertices (placement, colour). + vec2d_t inner[2], outer[2]; + vec2f_t edgeOpen, sideOpen; + Sector *front = 0, *back = 0; + coord_t fz = 0, bz = 0, bhz = 0; if(lineDef->L_backsidedef) { - uint hackType; - front = lineDef->L_sector(side); back = lineDef->L_sector(side ^ 1); setRelativeHeights(front, back, planeId == PLN_CEILING, &fz, &bz, &bhz); - hackType = radioEdgeHackType(lineDef, front, back, side, planeId == PLN_CEILING, fz, bz); + uint hackType = radioEdgeHackType(lineDef, front, back, side, planeId == PLN_CEILING, fz, bz); if(hackType) { V2f_Set(edgeOpen, hackType - 1, hackType - 1); @@ -1372,13 +1352,10 @@ static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, // Find the neighbors of this edge and determine their 'openness'. sideOpen[0] = sideOpen[1] = 0; - for(i = 0; i < 2; ++i) + for(int i = 0; i < 2; ++i) { - lineowner_t* vo; - LineDef* neighbor; - - vo = lineDef->L_vo(side^i)->link[i^1]; - neighbor = vo->lineDef; + lineowner_t* vo = lineDef->L_vo(side^i)->link[i^1]; + LineDef* neighbor = vo->lineDef; if(neighbor != lineDef && !neighbor->L_backsidedef && (neighbor->inFlags & LF_BSPWINDOW) && @@ -1389,7 +1366,7 @@ static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, } else if(!(neighbor == lineDef || !neighbor->L_backsidedef)) { - Sector* othersec; + Sector *othersec; byte otherSide; otherSide = (lineDef->L_v(i^side) == neighbor->L_v1? i : i^1); @@ -1404,7 +1381,8 @@ static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, sideOpen[i] = 1; } else - { // Its a normal neighbor. + { + // Its a normal neighbor. if(neighbor->L_sector(otherSide) != lineDef->L_sector(side) && !((pln->type == PLN_FLOOR && othersec->SP_ceilvisheight <= pln->visHeight) || (pln->type == PLN_CEILING && othersec->SP_floorheight >= pln->visHeight))) @@ -1421,8 +1399,7 @@ static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, if(sideOpen[i] < 1) { vo = lineDef->L_vo(i^side); - if(i) - vo = vo->LO_prev; + if(i) vo = vo->LO_prev; V2d_Sum(inner[i], lineDef->L_vorigin(i^side), vo->shadowOffsets.inner); } @@ -1435,31 +1412,37 @@ static void processEdgeShadow(const BspLeaf* bspLeaf, const LineDef* lineDef, V2d_Copy(outer[0], lineDef->L_vorigin(side)); V2d_Copy(outer[1], lineDef->L_vorigin(side^1)); // Shadows are black + vec3f_t shadowRGB; V3f_Set(shadowRGB, 0, 0, 0); - addShadowEdge(inner, outer, plnHeight, plnHeight, plnHeight, plnHeight, sideOpen, edgeOpen, suf->normal[VZ] > 0, shadowRGB, shadowDark); + addShadowEdge(inner, outer, plnHeight, plnHeight, plnHeight, plnHeight, sideOpen, edgeOpen, + suf->normal[VZ] > 0, shadowRGB, shadowDark); } -static void drawLinkedEdgeShadows(const BspLeaf* bspLeaf, shadowlink_t* link, - const byte* doPlanes, float shadowDark) +static void drawLinkedEdgeShadows(BspLeaf const *bspLeaf, shadowlink_t *link, + byte const *doPlanes, float shadowDark) { - uint pln; - assert(bspLeaf && link && doPlanes); + DENG_ASSERT(bspLeaf && link && doPlanes); if(!(shadowDark > .0001f)) return; if(doPlanes[PLN_FLOOR]) + { processEdgeShadow(bspLeaf, link->lineDef, link->side, PLN_FLOOR, shadowDark); + } + if(doPlanes[PLN_CEILING]) + { processEdgeShadow(bspLeaf, link->lineDef, link->side, PLN_CEILING, shadowDark); + } - for(pln = PLN_MID; pln < bspLeaf->sector->planeCount; ++pln) + for(uint pln = PLN_MID; pln < bspLeaf->sector->planeCount; ++pln) { processEdgeShadow(bspLeaf, link->lineDef, link->side, pln, shadowDark); } // Mark it rendered for this frame. - link->lineDef->L_side(link->side).shadowVisFrame = (ushort) frameCount; + link->lineDef->L_side(link->side).shadowVisFrame = ushort(frameCount); } /** @@ -1469,29 +1452,28 @@ static void drawLinkedEdgeShadows(const BspLeaf* bspLeaf, shadowlink_t* link, * Don't use the global radio state in here, the BSP leaf can be part of * any sector, not the one chosen for wall rendering. */ -static void radioBspLeafEdges(const BspLeaf* bspLeaf) +static void radioBspLeafEdges(BspLeaf const *bspLeaf) { static size_t doPlaneSize = 0; - static byte* doPlanes = NULL; + static byte *doPlanes = 0; float sectorlight = bspLeaf->sector->lightLevel; - float shadowWallSize, shadowDark; boolean workToDo = false; - float vec[3]; Rend_ApplyLightAdaptation(§orlight); - if(sectorlight == 0) - return; // No point drawing shadows in a PITCH black sector. + // No point drawing shadows in a PITCH black sector. + if(sectorlight == 0) return; // Determine the shadow properties. /// @todo Make cvars out of constants. - shadowWallSize = 2 * (8 + 16 - sectorlight * 16); - shadowDark = Rend_RadioCalcShadowDarkness(sectorlight); + //float shadowWallSize = 2 * (8 + 16 - sectorlight * 16); + float shadowDark = Rend_RadioCalcShadowDarkness(sectorlight); // Any need to continue? if(!(shadowDark > .0001f)) return; + float vec[3]; vec[VX] = vOrigin[VX] - bspLeaf->midPoint[VX]; vec[VY] = vOrigin[VZ] - bspLeaf->midPoint[VY]; vec[VZ] = 0; @@ -1504,43 +1486,40 @@ static void radioBspLeafEdges(const BspLeaf* bspLeaf) else doPlaneSize *= 2; - doPlanes = Z_Realloc(doPlanes, doPlaneSize, PU_APPSTATIC); + doPlanes = (byte *) Z_Realloc(doPlanes, doPlaneSize, PU_APPSTATIC); } - memset(doPlanes, 0, doPlaneSize); + std::memset(doPlanes, 0, doPlaneSize); // See if any of this BspLeaf's planes will get shadows. - { uint pln; - for(pln = 0; pln < bspLeaf->sector->planeCount; ++pln) + for(uint pln = 0; pln < bspLeaf->sector->planeCount; ++pln) { - const Plane* plane = bspLeaf->sector->planes[pln]; + Plane const *plane = bspLeaf->sector->planes[pln]; vec[VZ] = vOrigin[VY] - plane->visHeight; // Don't bother with planes facing away from the camera. - if(V3f_DotProduct(vec, plane->PS_normal) < 0) - continue; + if(V3f_DotProduct(vec, plane->PS_normal) < 0) continue; doPlanes[pln] = true; workToDo = true; - }} + } - if(!workToDo) - return; + if(!workToDo) return; // We need to check all the shadow lines linked to this BspLeaf for // the purpose of fakeradio shadowing. - { shadowlink_t* link; - for(link = bspLeaf->shadows; link != NULL; link = link->next) + for(shadowlink_t *link = bspLeaf->shadows; link != NULL; link = link->next) { // Already rendered during the current frame? We only want to // render each shadow once per frame. if(link->lineDef->L_side(link->side).shadowVisFrame == (ushort) frameCount) continue; + drawLinkedEdgeShadows(bspLeaf, link, doPlanes, shadowDark); - }} + } } -void Rend_RadioBspLeafEdges(BspLeaf* bspLeaf) +void Rend_RadioBspLeafEdges(BspLeaf *bspLeaf) { if(!rendFakeRadio || levelFullBright) return; @@ -1550,13 +1529,11 @@ void Rend_RadioBspLeafEdges(BspLeaf* bspLeaf) #if _DEBUG static void drawPoint(coord_t pos[3], int radius, const float color[4]) { - const viewdata_t* viewData = R_ViewData(viewPlayer - ddPlayers); - coord_t viewToCenter[3], finalPos[3], leftOff[3], rightOff[3]; - float scale, radX, radY; - int i; + viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers); - // viewSideVec is to the left. - for(i = 0; i < 3; ++i) + // viewData->sideVec is to the left. + coord_t leftOff[3], rightOff[3], viewToCenter[3]; + for(int i = 0; i < 3; ++i) { leftOff[i] = viewData->upVec[i] + viewData->sideVec[i]; rightOff[i] = viewData->upVec[i] - viewData->sideVec[i]; @@ -1564,16 +1541,17 @@ static void drawPoint(coord_t pos[3], int radius, const float color[4]) viewToCenter[i] = pos[i] - vOrigin[i]; } - scale = (float) V3d_DotProductf(viewToCenter, viewData->frontVec) / - V3f_DotProduct(viewData->frontVec, viewData->frontVec); + //float scale = float(V3d_DotProductf(viewToCenter, viewData->frontVec)) / + // V3f_DotProduct(viewData->frontVec, viewData->frontVec); + coord_t finalPos[3]; finalPos[VX] = pos[VX]; finalPos[VY] = pos[VZ]; finalPos[VZ] = pos[VY]; // The final radius. - radX = radius * 1; - radY = radX / 1.2f; + float radX = radius * 1; + float radY = radX / 1.2f; LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -1600,13 +1578,10 @@ static void drawPoint(coord_t pos[3], int radius, const float color[4]) glEnd(); } -void Rend_DrawShadowOffsetVerts(void) +void Rend_DrawShadowOffsetVerts() { - static const float red[4] = { 1.f, .2f, .2f, 1.f}; - static const float yellow[4] = {.7f, .7f, .2f, 1.f}; - - uint i, j, k; - coord_t pos[3]; + static const float red[4] = { 1.f, .2f, .2f, 1.f}; + static const float yellow[4] = {.7f, .7f, .2f, 1.f}; LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -1617,17 +1592,18 @@ void Rend_DrawShadowOffsetVerts(void) GL_BindTextureUnmanaged(GL_PrepareLSTexture(LST_DYNAMIC), GL_LINEAR); glEnable(GL_TEXTURE_2D); - for(i = 0; i < NUM_LINEDEFS; ++i) + for(uint i = 0; i < NUM_LINEDEFS; ++i) { - LineDef* line = &lineDefs[i]; + LineDef *line = &lineDefs[i]; - for(k = 0; k < 2; ++k) + for(uint k = 0; k < 2; ++k) { - Vertex* vtx = line->L_v(k); - lineowner_t* vo = vtx->lineOwners; + Vertex *vtx = line->L_v(k); + lineowner_t *vo = vtx->lineOwners; - for(j = 0; j < vtx->numLineOwners; ++j) + for(uint j = 0; j < vtx->numLineOwners; ++j) { + coord_t pos[3]; pos[VZ] = vo->lineDef->L_frontsector->SP_floorvisheight; V2d_Sum(pos, vtx->origin, vo->shadowOffsets.extended); diff --git a/doomsday/engine/src/render/rend_list.c b/doomsday/engine/src/render/rend_list.cpp similarity index 82% rename from doomsday/engine/src/render/rend_list.c rename to doomsday/engine/src/render/rend_list.cpp index 7c9bdb7ac1..90ca25779a 100644 --- a/doomsday/engine/src/render/rend_list.c +++ b/doomsday/engine/src/render/rend_list.cpp @@ -1,54 +1,46 @@ -/**\file rend_list.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html - * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson - *\author Copyright © 2006 Jamie Jones - * - * 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 - */ - -/** - * Doomsday Rendering Lists v3.3 +/** @file rend_list.cpp Rendering Lists v3.3 * * 3.3 -- Texture unit write state and revised primitive write interface. * 3.2 -- Shiny walls and floors * 3.1 -- Support for multiple shadow textures * 3.0 -- Multitexturing + * + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2005-2012 Daniel Swanson + * @author Copyright © 2006 Jamie Jones + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 */ -// HEADER FILES ------------------------------------------------------------ - -#include +#include +#include #include "de_base.h" #include "de_console.h" #include "de_render.h" #include "de_play.h" #include "de_graphics.h" -#include "de_misc.h" +//#include "de_misc.h" + +#include +#include #include "def_main.h" #include "resource/texturevariant.h" #include "m_profiler.h" -// MACROS ------------------------------------------------------------------ - BEGIN_PROF_TIMERS() PROF_RL_ADD_POLY, PROF_RL_GET_LIST, @@ -93,8 +85,6 @@ END_PROF_TIMERS() #define DCF_NO_COLOR 0x00000800 #define DCF_SKIP 0x80000000 -// TYPES ------------------------------------------------------------------- - // List Modes. typedef enum listmode_e { LM_SKYMASK, @@ -173,7 +163,7 @@ typedef struct primhdr_s { // All indices in the range indices[0]...indices[n] are used by this // primitive (some are shared). ushort numIndices; - uint* indices; + uint *indices; byte flags; // PF_* primitive flags. @@ -192,7 +182,7 @@ typedef struct primhdr_s { // Helper macro for accessing rendlist texmap units. #define TU(x, n) (&((x)->texmapunits[(n)])) -// \note: Slighty different representation than that passed to RL_AddPoly. +/// @note Slighty different representation than that passed to RL_AddPoly. typedef struct rendlist_texmapunit_s { rtexmapunit_texture_t texture; float opacity; // Blend amount. @@ -204,33 +194,20 @@ typedef struct rendlist_texmapunit_s { * need to be restored so that they point to the new list. */ typedef struct rendlist_s { - struct rendlist_s* next; + struct rendlist_s *next; rendlist_texmapunit_t texmapunits[NUM_TEXTURE_UNITS]; size_t size; // Number of bytes allocated for the data. - byte* data; // Data for a number of polygons (The List). - byte* cursor; // A pointer to data, for reading/writing. - primhdr_t* last; // Pointer to the last primitive (or NULL). + byte *data; // Data for a number of polygons (The List). + byte *cursor; // A pointer to data, for reading/writing. + primhdr_t *last; // Pointer to the last primitive (or NULL). } rendlist_t; typedef struct listhash_s { - rendlist_t* first, *last; + rendlist_t *first, *last; } listhash_t; -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -extern byte devRendSkyAlways; extern boolean usingFog; -extern byte freezeRLs; - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - int renderTextures = true; int renderWireframe = false; int useMultiTexLights = true; @@ -246,24 +223,22 @@ float detailScale = 4; float torchColor[3] = {1, 1, 1}; int torchAdditive = true; -// PRIVATE DATA DEFINITIONS ------------------------------------------------ - static boolean initedOk = false; // Logical texture unit state. Used with RL_LoadDefaultRtus and RL_CopyRtu static rtexmapunit_t rtuDefault; static rtexmapunit_t rtuState[NUM_TEXMAP_UNITS]; -static rtexmapunit_t const* rtuMap[NUM_TEXMAP_UNITS]; +static rtexmapunit_t const *rtuMap[NUM_TEXMAP_UNITS]; // GL texture unit state used during write. Global for performance reasons. -static rtexmapunit_t const* texunits[NUM_TEXTURE_UNITS]; +static rtexmapunit_t const *texunits[NUM_TEXTURE_UNITS]; /** * The vertex arrays. */ -static dgl_vertex_t* vertices; -static dgl_texcoord_t* texCoords[NUM_TEXCOORD_ARRAYS]; -static dgl_color_t* colors; +static dgl_vertex_t *vertices; +static dgl_texcoord_t *texCoords[NUM_TEXCOORD_ARRAYS]; +static dgl_color_t *colors; static uint numVertices, maxVertices; static boolean rDrawSky; @@ -288,28 +263,26 @@ static rendlist_t skyMaskList; static float blackColor[4] = { 0, 0, 0, 0 }; -// CODE -------------------------------------------------------------------- - -void RL_Register(void) +void RL_Register() { - // \todo Move cvars here. + /// @todo Move cvars here. C_VAR_INT("rend-light-multitex", &useMultiTexLights, 0, 0, 1); C_VAR_INT("rend-light-blend", &dynlightBlend, 0, 0, 2); } -static __inline boolean unitHasTexture(const rtexmapunit_texture_t* tu) +static inline boolean unitHasTexture(rtexmapunit_texture_t const *tu) { if(tu->flags & TUF_TEXTURE_IS_MANAGED) - return TextureVariant_GLName(tu->variant) != 0; + return reinterpret_cast(tu->variant)->glName() != 0; return tu->gl.name != 0; } -static __inline ushort unitHashForTexture(const rtexmapunit_texture_t* tu) +static inline ushort unitHashForTexture(rtexmapunit_texture_t const *tu) { DGLuint glName; if(tu->flags & TUF_TEXTURE_IS_MANAGED) { - glName = tu->variant? TextureVariant_GLName(tu->variant) : 0; + glName = tu->variant? reinterpret_cast(tu->variant)->glName() : 0; } else { @@ -318,8 +291,8 @@ static __inline ushort unitHashForTexture(const rtexmapunit_texture_t* tu) return glName % RL_HASH_SIZE; } -static boolean compareUnitTexture(const rtexmapunit_texture_t* ltu, - const rtexmapunit_texture_t* rtu) +static boolean compareUnitTexture(rtexmapunit_texture_t const *ltu, + rtexmapunit_texture_t const *rtu) { if(unitHasTexture(ltu) != unitHasTexture(rtu)) return false; if((ltu->flags & TUF_TEXTURE_IS_MANAGED) != (rtu->flags & TUF_TEXTURE_IS_MANAGED)) return false; @@ -335,41 +308,33 @@ static boolean compareUnitTexture(const rtexmapunit_texture_t* ltu, return true; } -static __inline boolean compareUnit(const rendlist_texmapunit_t* ltu, const rtexmapunit_t* rtu) +static inline boolean compareUnit(rendlist_texmapunit_t const *ltu, rtexmapunit_t const *rtu) { if(!compareUnitTexture(<u->texture, &rtu->texture)) return false; if(ltu->opacity != rtu->opacity) return false; return true; } -static __inline void copyUnit(rendlist_texmapunit_t* ltu, const rtexmapunit_t* rtu) +static inline void copyUnit(rendlist_texmapunit_t *ltu, rtexmapunit_t const *rtu) { - memcpy(<u->texture, &rtu->texture, sizeof(ltu->texture)); + std::memcpy(<u->texture, &rtu->texture, sizeof(ltu->texture)); ltu->blendMode = rtu->blendMode; ltu->opacity = MINMAX_OF(0, rtu->opacity, 1); } static void rlBindUnmanaged(DGLuint glName, int magMode) { -#ifdef _DEBUG - GLenum error; -#endif - GL_BindTextureUnmanaged(!renderTextures? 0 : glName, magMode); -#if _DEBUG - error = glGetError(); +#ifdef DENG_DEBUG + GLenum error = glGetError(); if(error != GL_NO_ERROR) Con_Error("OpenGL error: %i\n", error); #endif } -static void rlBind(const rendlist_texmapunit_t* tmu) +static void rlBind(rendlist_texmapunit_t const *tmu) { -#ifdef _DEBUG - GLenum error; -#endif - if(!unitHasTexture(&tmu->texture)) return; if(!renderTextures) { @@ -384,30 +349,32 @@ static void rlBind(const rendlist_texmapunit_t* tmu) GL_BindTexture(tmu->texture.variant); -#if _DEBUG - error = glGetError(); +#ifdef DENG_DEBUG + GLenum error = glGetError(); if(error != GL_NO_ERROR) Con_Error("OpenGL error: %i\n", error); #endif } -static void rlBindTo(int unit, const rendlist_texmapunit_t* tmu) +static void rlBindTo(int unit, rendlist_texmapunit_t const *tmu) { + DENG_ASSERT(tmu); if(!unitHasTexture(&tmu->texture)) return; LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); - glActiveTexture(GL_TEXTURE0 + (byte)unit); + glActiveTexture(GL_TEXTURE0 + byte(unit)); rlBind(tmu); } -static void clearHash(listhash_t* hash) +static void clearHash(listhash_t *hash) { - memset(hash, 0, sizeof(listhash_t) * RL_HASH_SIZE); + DENG_ASSERT(hash); + std::memset(hash, 0, sizeof(listhash_t) * RL_HASH_SIZE); } -void RL_Init(void) +void RL_Init() { if(initedOk) return; // Already been here. @@ -417,54 +384,55 @@ void RL_Init(void) clearHash(shadowHash); clearHash(shinyHash); - memset(&skyMaskList, 0, sizeof(skyMaskList)); + std::memset(&skyMaskList, 0, sizeof(skyMaskList)); Rtu_Init(&rtuDefault); RL_LoadDefaultRtus(); initedOk = true; } -void RL_Shutdown(void) +void RL_Shutdown() { // Stub. - /// \todo Rework list memory management so we explicitly free it, rather + /// @todo Rework list memory management so we explicitly free it, rather /// than depend on it being free'd by the Zone when it is shutdown. initedOk = false; } -boolean RL_IsMTexLights(void) +boolean RL_IsMTexLights() { return IS_MTEX_LIGHTS; } -boolean RL_IsMTexDetails(void) +boolean RL_IsMTexDetails() { return IS_MTEX_DETAILS; } -static void clearVertices(void) +static void clearVertices() { numVertices = 0; } -static void destroyVertices(void) +static void destroyVertices() { - uint i; - numVertices = maxVertices = 0; if(vertices) - M_Free(vertices); - vertices = NULL; + { + M_Free(vertices); vertices = 0; + } if(colors) - M_Free(colors); - colors = NULL; + { + M_Free(colors); colors = 0; + } - for(i = 0; i < NUM_TEXCOORD_ARRAYS; ++i) + for(uint i = 0; i < NUM_TEXCOORD_ARRAYS; ++i) { if(texCoords[i]) - M_Free(texCoords[i]); - texCoords[i] = NULL; + { + M_Free(texCoords[i]); texCoords[i] = 0; + } } } @@ -473,7 +441,7 @@ static void destroyVertices(void) */ static uint allocateVertices(uint count) { - uint i, base = numVertices; + uint base = numVertices; // Do we need to allocate more memory? numVertices += count; @@ -488,43 +456,44 @@ static uint allocateVertices(uint count) maxVertices *= 2; } - vertices = M_Realloc(vertices, sizeof(dgl_vertex_t) * maxVertices); - colors = M_Realloc(colors, sizeof(dgl_color_t) * maxVertices); - for(i = 0; i < NUM_TEXCOORD_ARRAYS; ++i) + vertices = (dgl_vertex_t *) M_Realloc(vertices, sizeof(dgl_vertex_t) * maxVertices); + colors = (dgl_color_t *) M_Realloc(colors, sizeof(dgl_color_t) * maxVertices); + for(uint i = 0; i < NUM_TEXCOORD_ARRAYS; ++i) { - texCoords[i] = - M_Realloc(texCoords[i], sizeof(dgl_texcoord_t) * maxVertices); + texCoords[i] = (dgl_texcoord_t *) M_Realloc(texCoords[i], sizeof(dgl_texcoord_t) * maxVertices); } } return base; } -static void destroyList(rendlist_t* rl) +static void destroyList(rendlist_t *rl) { + DENG_ASSERT(rl); + // All the list data will be destroyed. if(rl->data) - Z_Free(rl->data); - rl->data = NULL; + { + Z_Free(rl->data); rl->data = 0; + } -#if _DEBUG +#ifdef DENG_DEBUG Z_CheckHeap(); #endif rl->cursor = NULL; TU(rl, TU_INTER_DETAIL)->texture.gl.name = 0; - TU(rl, TU_INTER_DETAIL)->texture.flags = 0; - rl->last = NULL; + TU(rl, TU_INTER_DETAIL)->texture.flags = 0; + rl->last = 0; rl->size = 0; } static void deleteHash(listhash_t* hash) { - rendlist_t* list, *next; - uint i; + rendlist_t *next; - for(i = 0; i < RL_HASH_SIZE; ++i) + for(uint i = 0; i < RL_HASH_SIZE; ++i) { - for(list = hash[i].first; list; list = next) + for(rendlist_t *list = hash[i].first; list; list = next) { next = list->next; destroyList(list); @@ -537,7 +506,7 @@ static void deleteHash(listhash_t* hash) /** * All lists will be destroyed. */ -void RL_DeleteLists(void) +void RL_DeleteLists() { // Delete all lists. deleteHash(plainHash); @@ -550,7 +519,7 @@ void RL_DeleteLists(void) destroyVertices(); -#ifdef _DEBUG +#ifdef DENG_DEBUG Z_CheckHeap(); #endif @@ -568,37 +537,39 @@ PRINT_PROF( PROF_RL_RENDER_SKYMASK ); /** * Set the R/W cursor to the beginning. */ -static void rewindList(rendlist_t* rl) +static void rewindList(rendlist_t *rl) { + DENG_ASSERT(rl); + rl->cursor = rl->data; rl->last = NULL; // The interpolation target must be explicitly set (in RL_AddPoly). TU(rl, TU_INTER)->texture.gl.name = 0; - TU(rl, TU_INTER)->texture.flags = 0; - TU(rl, TU_INTER)->opacity = 0; + TU(rl, TU_INTER)->texture.flags = 0; + TU(rl, TU_INTER)->opacity = 0; TU(rl, TU_INTER_DETAIL)->texture.gl.name = 0; - TU(rl, TU_INTER_DETAIL)->texture.flags = 0; - TU(rl, TU_INTER_DETAIL)->opacity = 0; + TU(rl, TU_INTER_DETAIL)->texture.flags = 0; + TU(rl, TU_INTER_DETAIL)->opacity = 0; } -static void rewindHash(listhash_t* hash) +static void rewindHash(listhash_t *hash) { - uint i; - rendlist_t* list; - - for(i = 0; i < RL_HASH_SIZE; ++i) + DENG_ASSERT(hash); + for(uint i = 0; i < RL_HASH_SIZE; ++i) { - for(list = hash[i].first; list; list = list->next) + for(rendlist_t *list = hash[i].first; list; list = list->next) + { rewindList(list); + } } } /** * Called before rendering a frame. */ -void RL_ClearLists(void) +void RL_ClearLists() { rewindHash(plainHash); rewindHash(litHash); @@ -615,9 +586,9 @@ void RL_ClearLists(void) rDrawSky = false; } -static rendlist_t* createList(listhash_t* hash) +static rendlist_t *createList(listhash_t *hash) { - rendlist_t* list = Z_Calloc(sizeof(rendlist_t), PU_APPSTATIC, 0); + rendlist_t* list = (rendlist_t *) Z_Calloc(sizeof(rendlist_t), PU_APPSTATIC, 0); if(hash->last) hash->last->next = list; @@ -627,10 +598,10 @@ static rendlist_t* createList(listhash_t* hash) return list; } -static rendlist_t* getListFor(rendpolytype_t polyType, boolean isLit) +static rendlist_t *getListFor(rendpolytype_t polyType, boolean isLit) { - listhash_t* list, *table; - rendlist_t* dest, *convertable = NULL; + listhash_t *list, *table; + rendlist_t *dest, *convertable = 0; // Check for specialized rendering lists first. if(polyType == PT_SKY_MASK) @@ -687,7 +658,8 @@ static rendlist_t* getListFor(rendpolytype_t polyType, boolean isLit) // Did we find a convertable list? if(convertable) - { // This list is currently empty. + { + // This list is currently empty. if(polyType == PT_SHINY) { copyUnit(TU(convertable, TU_INTER), texunits[TU_INTER]); @@ -727,29 +699,26 @@ static rendlist_t* getListFor(rendpolytype_t polyType, boolean isLit) } /** - * @return Pointer to the start of the allocated data. + * @return Start of the allocated data. */ -static void* allocateData(rendlist_t* list, int bytes) +static void* allocateData(rendlist_t *list, int bytes) { - size_t required; - int startOffset = list->cursor - list->data; - primhdr_t* hdr; - if(bytes <= 0) - return NULL; + return 0; // We require the extra bytes because we want that the end of the // list data is always safe for writing-in-advance. This is needed // when the 'end of data' marker is written in RL_AddPoly. - required = startOffset + bytes + LIST_DATA_PADDING; + int startOffset = list->cursor - list->data; + size_t required = startOffset + bytes + LIST_DATA_PADDING; // First check that the data buffer of the list is large enough. if(required > list->size) { // Offsets must be preserved. - byte* oldData = list->data; - int cursorOffset = -1; - int lastOffset = -1; + byte *oldData = list->data; + int cursorOffset = -1; + int lastOffset = -1; if(list->cursor) cursorOffset = list->cursor - oldData; @@ -762,32 +731,28 @@ static void* allocateData(rendlist_t* list, int bytes) while(list->size < required) list->size *= 2; - list->data = Z_Realloc(list->data, list->size, PU_APPSTATIC); + list->data = (byte *) Z_Realloc(list->data, list->size, PU_APPSTATIC); // Restore main pointers. - list->cursor = - (cursorOffset >= 0 ? list->data + cursorOffset : list->data); - list->last = - (lastOffset >= 0 ? (primhdr_t *) (list->data + lastOffset) : NULL); + list->cursor = (cursorOffset >= 0 ? list->data + cursorOffset : list->data); + list->last = (lastOffset >= 0 ? (primhdr_t *) (list->data + lastOffset) : NULL); // Restore in-list pointers. if(oldData) { - hdr = (primhdr_t *) list->data; + primhdr_t *hdr = (primhdr_t *) list->data; while(hdr <= list->last) { if(hdr->indices != NULL) { - hdr->indices = - (uint *) (list->data + - ((byte *) hdr->indices - oldData)); + hdr->indices = (uint *) (list->data + ((byte *) hdr->indices - oldData)); } // Check here in the end; primitive composition may be // in progress. - if(hdr->size == 0) - break; - hdr = (primhdr_t*) ((byte*) hdr + hdr->size); + if(hdr->size == 0) break; + + hdr = (primhdr_t *) ((byte *) hdr + hdr->size); } } } @@ -798,40 +763,38 @@ static void* allocateData(rendlist_t* list, int bytes) return list->data + startOffset; } -static void allocateIndices(rendlist_t* list, uint numIndices) +static void allocateIndices(rendlist_t *list, uint numIndices) { - void* indices; + void *indices; list->last->numIndices = numIndices; indices = allocateData(list, sizeof(uint) * numIndices); // list->last may change during allocateData. - list->last->indices = indices; + list->last->indices = (uint *) indices; } -static void endWrite(rendlist_t* list) +static void endWrite(rendlist_t *list) { // The primitive has been written, update the size in the header. - list->last->size = list->cursor - (byte*) list->last; + list->last->size = list->cursor - (byte *) list->last; // Write the end marker (which will be overwritten by the next // primitive). The idea is that this zero is interpreted as the // size of the following primhdr. - *(int*) list->cursor = 0; + *(int *) list->cursor = 0; } -static void writePrimitive(const rendlist_t* list, uint base, - const rvertex_t* rvertices, const rtexcoord_t* coords, - const rtexcoord_t* coords1, const rtexcoord_t* coords2, - const ColorRawf* rcolors, uint numElements, rendpolytype_t type) +static void writePrimitive(rendlist_t const *list, uint base, + rvertex_t const *rvertices, rtexcoord_t const *coords, + rtexcoord_t const *coords1, rtexcoord_t const *coords2, + ColorRawf const *rcolors, uint numElements, rendpolytype_t type) { - uint i; - - for(i = 0; i < numElements; ++i) + for(uint i = 0; i < numElements; ++i) { // Vertex. - const rvertex_t* rvtx = &rvertices[i]; - dgl_vertex_t* vtx = &vertices[base + i]; + rvertex_t const *rvtx = &rvertices[i]; + dgl_vertex_t *vtx = &vertices[base + i]; vtx->xyz[0] = rvtx->pos[VX]; vtx->xyz[1] = rvtx->pos[VZ]; @@ -843,8 +806,8 @@ static void writePrimitive(const rendlist_t* list, uint base, // Primary texture coordinates. if(unitHasTexture(&TU(list, TU_PRIMARY)->texture)) { - const rtexcoord_t* rtc = &coords[i]; - dgl_texcoord_t* tc = &texCoords[TCA_MAIN][base + i]; + rtexcoord_t const *rtc = &coords[i]; + dgl_texcoord_t *tc = &texCoords[TCA_MAIN][base + i]; tc->st[0] = rtc->st[0]; tc->st[1] = rtc->st[1]; @@ -853,8 +816,8 @@ static void writePrimitive(const rendlist_t* list, uint base, // Secondary texture coordinates. if(unitHasTexture(&TU(list, TU_INTER)->texture)) { - const rtexcoord_t* rtc = &coords1[i]; - dgl_texcoord_t* tc = &texCoords[TCA_BLEND][base + i]; + rtexcoord_t const *rtc = &coords1[i]; + dgl_texcoord_t *tc = &texCoords[TCA_BLEND][base + i]; tc->st[0] = rtc->st[0]; tc->st[1] = rtc->st[1]; @@ -863,17 +826,16 @@ static void writePrimitive(const rendlist_t* list, uint base, // First light texture coordinates. if((list->last->flags & PF_IS_LIT) && IS_MTEX_LIGHTS) { - const rtexcoord_t* rtc = &coords2[i]; - dgl_texcoord_t* tc = &texCoords[TCA_LIGHT][base + i]; + rtexcoord_t const *rtc = &coords2[i]; + dgl_texcoord_t *tc = &texCoords[TCA_LIGHT][base + i]; tc->st[0] = rtc->st[0]; tc->st[1] = rtc->st[1]; } // Color. - { - const ColorRawf* rcolor = &rcolors[i]; - dgl_color_t* color = &colors[base + i]; + ColorRawf const *rcolor = &rcolors[i]; + dgl_color_t *color = &colors[base + i]; if(rcolors) { @@ -886,7 +848,6 @@ static void writePrimitive(const rendlist_t* list, uint base, { color->rgba[CR] = color->rgba[CG] = color->rgba[CB] = color->rgba[CA] = 255; } - } } } @@ -895,14 +856,14 @@ static void writePrimitive(const rendlist_t* list, uint base, * @pre Caller knows what they are doing. Arguments are not validity checked. */ static void writePoly2(primtype_t type, rendpolytype_t polyType, int flags, - uint numElements, const rvertex_t* vertices, const ColorRawf* colors, - const rtexcoord_t* primaryCoords, const rtexcoord_t* interCoords, - DGLuint modTex, const ColorRawf* modColor, const rtexcoord_t* modCoords) + uint numElements, rvertex_t const *vertices, ColorRawf const *colors, + rtexcoord_t const *primaryCoords, rtexcoord_t const *interCoords, + DGLuint modTex, ColorRawf const *modColor, rtexcoord_t const *modCoords) { - const boolean isLit = (polyType != PT_LIGHT && (modTex || !!(flags & RPF_HAS_DYNLIGHTS))); + boolean const isLit = (polyType != PT_LIGHT && (modTex || !!(flags & RPF_HAS_DYNLIGHTS))); uint i, base, primSize, numIndices; - rendlist_t* li; - primhdr_t* hdr; + rendlist_t *li; + primhdr_t *hdr; if(polyType == PT_SKY_MASK) rDrawSky = true; @@ -920,8 +881,8 @@ END_PROF( PROF_RL_GET_LIST ); numIndices = numElements; base = allocateVertices(primSize); - hdr = allocateData(li, sizeof(primhdr_t)); - assert(hdr); + hdr = (primhdr_t *) allocateData(li, sizeof(primhdr_t)); + DENG_ASSERT(hdr); li->last = hdr; // This becomes the new last primitive. // Primitive-specific blending mode. @@ -991,61 +952,61 @@ END_PROF( PROF_RL_ADD_POLY ); * interface with this. */ static void writePoly(primtype_t type, rendpolytype_t polyType, int flags, - uint numElements, const rvertex_t* vertices, const ColorRawf* colors, - const rtexcoord_t* primaryCoords, const rtexcoord_t* interCoords, - DGLuint modTex, const ColorRawf* modColor, const rtexcoord_t* modCoords) + uint numElements, rvertex_t const *vertices, ColorRawf const *colors, + rtexcoord_t const *primaryCoords, rtexcoord_t const *interCoords, + DGLuint modTex, ColorRawf const *modColor, rtexcoord_t const *modCoords) { if(numElements < 3) return; // huh? - /// \todo Logical disconnect: modulation VS dynlight multitexture state. + /// @todo Logical disconnect: modulation VS dynlight multitexture state. if(modTex && !RL_IsMTexLights()) Con_Error("RL_AddPoly: Attempt to write modulated primitive with multitexture disabled."); if(flags & RPF_SKYMASK) { - flags &= ~(RPF_LIGHT|RPF_SHADOW|RPF_HAS_DYNLIGHTS); - colors = NULL; + flags &= ~(RPF_LIGHT|RPF_SHADOW|RPF_HAS_DYNLIGHTS); + colors = NULL; primaryCoords = NULL; interCoords = NULL; - modTex = 0; - modColor = NULL; - modCoords = NULL; + modTex = 0; + modColor = NULL; + modCoords = NULL; } else if(flags & RPF_LIGHT) { - flags &= ~(RPF_SHADOW|RPF_HAS_DYNLIGHTS); + flags &= ~(RPF_SHADOW|RPF_HAS_DYNLIGHTS); interCoords = NULL; - modTex = 0; - modColor = NULL; - modCoords = NULL; + modTex = 0; + modColor = NULL; + modCoords = NULL; } else if(flags & RPF_SHADOW) { - flags &= ~RPF_HAS_DYNLIGHTS; + flags &= ~RPF_HAS_DYNLIGHTS; interCoords = NULL; - modTex = 0; - modColor = NULL; - modCoords = NULL; + modTex = 0; + modColor = NULL; + modCoords = NULL; } // Flush the write. writePoly2(type, polyType, flags, numElements, vertices, - colors, primaryCoords, interCoords, modTex, modColor, modCoords); + colors, primaryCoords, interCoords, modTex, modColor, modCoords); } -static __inline boolean validRTUIndex(uint idx) +static inline boolean validRTUIndex(uint idx) { return idx < NUM_TEXMAP_UNITS; } -static __inline void errorIfNotValidRTUIndex(uint idx, const char* callerName) +static inline void errorIfNotValidRTUIndex(uint idx, char const *callerName) { if(validRTUIndex(idx)) return; Con_Error("%s: Invalid texture unit index %u.", callerName, idx); exit(1); // Unreachable. } -static __inline boolean isWriteStateRTU(const rtexmapunit_t* ptr) +static inline boolean isWriteStateRTU(rtexmapunit_t const *ptr) { // Note that the default texture unit is not considered as being // part of the write state. @@ -1062,27 +1023,26 @@ static __inline boolean isWriteStateRTU(const rtexmapunit_t* ptr) */ static void copyMappedRtuToState(uint idx) { - assert(validRTUIndex(idx)); + DENG_ASSERT(validRTUIndex(idx)); if(isWriteStateRTU(rtuMap[idx])) return; RL_CopyRtu(idx, rtuMap[idx]); } -void RL_LoadDefaultRtus(void) +void RL_LoadDefaultRtus() { - int i; - for(i = 0; i < NUM_TEXMAP_UNITS; ++i) + for(int i = 0; i < NUM_TEXMAP_UNITS; ++i) { rtuMap[i] = &rtuDefault; } } -void RL_MapRtu(uint idx, const rtexmapunit_t* rtu) +void RL_MapRtu(uint idx, rtexmapunit_t const *rtu) { errorIfNotValidRTUIndex(idx, "RL_MapRtu"); rtuMap[idx] = (rtu? rtu : &rtuDefault); } -void RL_CopyRtu(uint idx, const rtexmapunit_t* rtu) +void RL_CopyRtu(uint idx, rtexmapunit_t const *rtu) { errorIfNotValidRTUIndex(idx, "RL_CopyRtu"); if(!rtu) @@ -1091,8 +1051,9 @@ void RL_CopyRtu(uint idx, const rtexmapunit_t* rtu) rtuMap[idx] = &rtuDefault; return; } - // Some _DEBUG error checking here wouldn't go amiss! - memcpy(rtuState + idx, rtu, sizeof rtuState[0]); + + // Some debug error checking here wouldn't go amiss! + std::memcpy(rtuState + idx, rtu, sizeof rtuState[0]); // Map this unit to that owned by the write state. rtuMap[idx] = rtuState + idx; } @@ -1165,7 +1126,7 @@ void RL_Rtu_SetTextureUnmanaged(uint idx, DGLuint glName) * Choose a specialised polytype from the specified primitive configuration. * @param flags @ref rendpolyFlags */ -static __inline rendpolytype_t choosePolyType(int flags) +static inline rendpolytype_t choosePolyType(int flags) { return ((flags & RPF_SKYMASK)? PT_SKY_MASK : (flags & RPF_LIGHT) ? PT_LIGHT : @@ -1174,7 +1135,7 @@ static __inline rendpolytype_t choosePolyType(int flags) // Prepare the final texture unit map for writing "normal" polygons, filling // any gaps using a default configured texture unit. -static void prepareTextureUnitMap(void) +static void prepareTextureUnitMap() { // Map logical texture units to "real" ones known to the GL renderer. texunits[TU_PRIMARY] = rtuMap[RTU_PRIMARY]; @@ -1185,7 +1146,7 @@ static void prepareTextureUnitMap(void) // Prepare the final texture unit map for writing "shiny" polygons, filling // any gaps using a default configured texture unit. -static void prepareTextureUnitMapForShinyPoly(void) +static void prepareTextureUnitMapForShinyPoly() { // Map logical texture units to "real" ones known to the GL renderer. texunits[TU_PRIMARY] = rtuMap[RTU_REFLECTION]; @@ -1195,15 +1156,15 @@ static void prepareTextureUnitMapForShinyPoly(void) } void RL_AddPolyWithCoordsModulationReflection(primtype_t primType, int flags, - uint numElements, const rvertex_t* vertices, const ColorRawf* colors, - const rtexcoord_t* primaryCoords, const rtexcoord_t* interCoords, - DGLuint modTex, const ColorRawf* modColor, const rtexcoord_t* modCoords, - const ColorRawf* reflectionColors, const rtexcoord_t* reflectionCoords, - const rtexcoord_t* reflectionMaskCoords) + uint numElements, rvertex_t const *vertices, ColorRawf const *colors, + rtexcoord_t const *primaryCoords, rtexcoord_t const *interCoords, + DGLuint modTex, ColorRawf const *modColor, rtexcoord_t const *modCoords, + ColorRawf const *reflectionColors, rtexcoord_t const *reflectionCoords, + rtexcoord_t const *reflectionMaskCoords) { prepareTextureUnitMap(); writePoly(primType, choosePolyType(flags), flags, numElements, - vertices, colors, primaryCoords, interCoords, modTex, modColor, modCoords); + vertices, colors, primaryCoords, interCoords, modTex, modColor, modCoords); // We are currently limited to two texture units, therefore shiny effects // must be drawn in a separate pass using a new primitive. @@ -1211,43 +1172,43 @@ void RL_AddPolyWithCoordsModulationReflection(primtype_t primType, int flags, prepareTextureUnitMapForShinyPoly(); writePoly(primType, PT_SHINY, flags & ~RPF_HAS_DYNLIGHTS, numElements, - vertices, reflectionColors, reflectionCoords, reflectionMaskCoords, 0, NULL, NULL); + vertices, reflectionColors, reflectionCoords, reflectionMaskCoords, 0, NULL, NULL); } void RL_AddPolyWithCoordsModulation(primtype_t primType, int flags, uint numElements, - const rvertex_t* vertices, const ColorRawf* colors, const rtexcoord_t* primaryCoords, - const rtexcoord_t* interCoords, - DGLuint modTex, const ColorRawf* modColor, const rtexcoord_t* modCoords) + rvertex_t const *vertices, ColorRawf const *colors, rtexcoord_t const *primaryCoords, + rtexcoord_t const *interCoords, + DGLuint modTex, ColorRawf const *modColor, rtexcoord_t const *modCoords) { prepareTextureUnitMap(); writePoly(primType, choosePolyType(flags), flags, numElements, - vertices, colors, primaryCoords, interCoords, modTex, modColor, modCoords); + vertices, colors, primaryCoords, interCoords, modTex, modColor, modCoords); } void RL_AddPolyWithCoords(primtype_t primType, int flags, uint numElements, - const rvertex_t* vertices, const ColorRawf* colors, - const rtexcoord_t* primaryCoords, const rtexcoord_t* interCoords) + rvertex_t const *vertices, ColorRawf const *colors, + rtexcoord_t const *primaryCoords, rtexcoord_t const *interCoords) { prepareTextureUnitMap(); writePoly(primType, choosePolyType(flags), flags, numElements, - vertices, colors, primaryCoords, interCoords, 0, NULL, NULL); + vertices, colors, primaryCoords, interCoords, 0, NULL, NULL); } void RL_AddPolyWithModulation(primtype_t primType, int flags, uint numElements, - const rvertex_t* vertices, const ColorRawf* colors, - DGLuint modTex, const ColorRawf* modColor, const rtexcoord_t* modCoords) + rvertex_t const *vertices, ColorRawf const *colors, + DGLuint modTex, ColorRawf const *modColor, rtexcoord_t const *modCoords) { prepareTextureUnitMap(); writePoly(primType, choosePolyType(flags), flags, numElements, - vertices, colors, NULL, NULL, modTex, modColor, modCoords); + vertices, colors, NULL, NULL, modTex, modColor, modCoords); } -void RL_AddPoly(primtype_t primType, int flags, uint numElements, const rvertex_t* vertices, - const ColorRawf* colors) +void RL_AddPoly(primtype_t primType, int flags, uint numElements, rvertex_t const *vertices, + ColorRawf const *colors) { prepareTextureUnitMap(); writePoly(primType, choosePolyType(flags), flags, numElements, - vertices, colors, NULL, NULL, 0, NULL, NULL); + vertices, colors, NULL, NULL, 0, NULL, NULL); } /** @@ -1255,20 +1216,15 @@ void RL_AddPoly(primtype_t primType, int flags, uint numElements, const rvertex_ * are given, all primitives are considered eligible. */ static void drawPrimitives(int conditions, uint coords[MAX_TEX_UNITS], - const rendlist_t* list) + rendlist_t const *list) { - primhdr_t* hdr; - boolean skip, bypass = false; - ushort i; - int j; - // Should we just skip all this? - if(conditions & DCF_SKIP) - return; + if(conditions & DCF_SKIP) return; LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); + boolean bypass = false; if(unitHasTexture(&TU(list, TU_INTER)->texture)) { // Is blending allowed? @@ -1293,8 +1249,8 @@ static void drawPrimitives(int conditions, uint coords[MAX_TEX_UNITS], } // Compile our list of indices. - hdr = (primhdr_t *) list->data; - skip = false; + primhdr_t *hdr = (primhdr_t *) list->data; + boolean skip = false; while(hdr->size != 0) { // Check for skip conditions. @@ -1373,10 +1329,10 @@ static void drawPrimitives(int conditions, uint coords[MAX_TEX_UNITS], } glBegin(hdr->type); - for(i = 0; i < hdr->numIndices; ++i) + for(short i = 0; i < hdr->numIndices; ++i) { - const uint index = hdr->indices[i]; - for(j = 0; j < numTexUnits; ++j) + uint const index = hdr->indices[i]; + for(short j = 0; j < numTexUnits; ++j) { if(coords[j]) glMultiTexCoord2fv(GL_TEXTURE0 + j, texCoords[coords[j] - 1][index].st); @@ -1419,10 +1375,10 @@ static void drawPrimitives(int conditions, uint coords[MAX_TEX_UNITS], } } - assert(!Sys_GLCheckError()); + DENG_ASSERT(!Sys_GLCheckError()); } - hdr = (primhdr_t*) ((byte*) hdr + hdr->size); + hdr = (primhdr_t *) ((byte *) hdr + hdr->size); } } @@ -1431,19 +1387,17 @@ static void drawPrimitives(int conditions, uint coords[MAX_TEX_UNITS], */ static void selectTexUnits(int count) { - int i; - LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); - for(i = numTexUnits - 1; i >= count; i--) + for(int i = numTexUnits - 1; i >= count; i--) { glActiveTexture(GL_TEXTURE0 + i); glDisable(GL_TEXTURE_2D); } // Enable the selected units. - for(i = count - 1; i >= 0; i--) + for(int i = count - 1; i >= 0; i--) { if(i >= numTexUnits) continue; @@ -1457,7 +1411,7 @@ static void selectTexUnits(int count) * * @return The conditions to select primitives. */ -static int setupListState(listmode_t mode, rendlist_t* list) +static int setupListState(listmode_t mode, rendlist_t *list) { LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -1472,12 +1426,10 @@ static int setupListState(listmode_t mode, rendlist_t* list) // Should we do blending? if(unitHasTexture(&TU(list, TU_INTER)->texture)) { - float color[4]; - // Blend between two textures, modulate with primary color. -#ifdef _DEBUG -if(numTexUnits < 2) - Con_Error("setupListState: Not enough texture units.\n"); +#ifdef DENG_DEBUG + if(numTexUnits < 2) + Con_Error("setupListState: Not enough texture units.\n"); #endif selectTexUnits(2); @@ -1485,6 +1437,7 @@ if(numTexUnits < 2) rlBindTo(1, TU(list, TU_INTER)); GL_ModulateTexture(2); + float color[4]; color[0] = color[1] = color[2] = 0; color[3] = TU(list, TU_INTER)->opacity; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); @@ -1517,15 +1470,12 @@ if(numTexUnits < 2) // and all primitives which will have a blended texture. return DCF_SET_LIGHT_ENV0 | DCF_MANY_LIGHTS | DCF_BLEND; - case LM_BLENDED: - { - float color[4]; - + case LM_BLENDED: { // Only render the blended surfaces. if(!unitHasTexture(&TU(list, TU_INTER)->texture)) return DCF_SKIP; -#ifdef _DEBUG +#ifdef DENG_DEBUG if(numTexUnits < 2) Con_Error("setupListState: Not enough texture units.\n"); #endif @@ -1537,10 +1487,11 @@ if(numTexUnits < 2) GL_ModulateTexture(2); + float color[4]; color[0] = color[1] = color[2] = 0; color[3] = TU(list, TU_INTER)->opacity; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); - return DCF_SET_MATRIX_TEXTURE0 | DCF_SET_MATRIX_TEXTURE1; - } + return DCF_SET_MATRIX_TEXTURE0 | DCF_SET_MATRIX_TEXTURE1; } + case LM_BLENDED_FIRST_LIGHT: // Only blended surfaces. if(!unitHasTexture(&TU(list, TU_INTER)->texture)) @@ -1566,11 +1517,9 @@ if(numTexUnits < 2) // Should we do blending? if(unitHasTexture(&TU(list, TU_INTER)->texture)) { - float color[4]; - // Mode 3 actually just disables the second texture stage, // which would modulate with primary color. -#ifdef _DEBUG +#ifdef DENG_DEBUG if(numTexUnits < 2) Con_Error("setupListState: Not enough texture units.\n"); #endif @@ -1581,6 +1530,7 @@ if(numTexUnits < 2) GL_ModulateTexture(3); + float color[4]; color[0] = color[1] = color[2] = 0; color[3] = TU(list, TU_INTER)->opacity; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); // Render all primitives. @@ -1644,10 +1594,7 @@ if(numTexUnits < 2) } break; - case LM_BLENDED_DETAILS: - { - float color[4]; - + case LM_BLENDED_DETAILS: { // We'll only render blended primitives. if(!unitHasTexture(&TU(list, TU_INTER)->texture)) break; if(!unitHasTexture(&TU(list, TU_PRIMARY_DETAIL)->texture) || @@ -1657,10 +1604,11 @@ if(numTexUnits < 2) rlBindTo(0, TU(list, TU_PRIMARY_DETAIL)); rlBindTo(1, TU(list, TU_INTER_DETAIL)); + float color[4]; color[0] = color[1] = color[2] = 0; color[3] = TU(list, TU_INTER_DETAIL)->opacity; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); - return DCF_SET_MATRIX_DTEXTURE0 | DCF_SET_MATRIX_DTEXTURE1; - } + return DCF_SET_MATRIX_DTEXTURE0 | DCF_SET_MATRIX_DTEXTURE1; } + case LM_SHADOW: // Render all primitives. if(unitHasTexture(&TU(list, TU_PRIMARY)->texture)) @@ -1691,6 +1639,9 @@ if(numTexUnits < 2) color[0] = color[1] = color[2] = 0; color[3] = 1.0f; glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); } } + + // Intentional fall-through. + case LM_ALL_SHINY: case LM_SHINY: rlBindTo(0, TU(list, TU_PRIMARY)); @@ -1712,7 +1663,7 @@ if(numTexUnits < 2) return DCF_SKIP; } -static void finishListState(listmode_t mode, rendlist_t* list) +static void finishListState(listmode_t mode, rendlist_t *list) { switch(mode) { @@ -1766,7 +1717,7 @@ static void finishPassState(listmode_t mode) */ static void setupPassState(listmode_t mode, uint coords[MAX_TEX_UNITS]) { - memset(coords, 0, sizeof(*coords) * MAX_TEX_UNITS); + std::memset(coords, 0, sizeof(*coords) * MAX_TEX_UNITS); switch(mode) { @@ -1942,9 +1893,8 @@ static void setupPassState(listmode_t mode, uint coords[MAX_TEX_UNITS]) // Use fog to fade the details, if fog is enabled. if(usingFog) { - float midGray[4]; - glEnable(GL_FOG); + float midGray[4]; midGray[0] = midGray[1] = midGray[2] = .5f; midGray[3] = fogColor[3]; // The alpha is probably meaningless? glFogfv(GL_FOG_COLOR, midGray); @@ -1967,9 +1917,8 @@ static void setupPassState(listmode_t mode, uint coords[MAX_TEX_UNITS]) // Use fog to fade the details, if fog is enabled. if(usingFog) { - float midGray[4]; - glEnable(GL_FOG); + float midGray[4]; midGray[0] = midGray[1] = midGray[2] = .5f; midGray[3] = fogColor[3]; // The alpha is probably meaningless? glFogfv(GL_FOG_COLOR, midGray); @@ -2042,24 +1991,20 @@ static void setupPassState(listmode_t mode, uint coords[MAX_TEX_UNITS]) /** * Renders the given lists. They must not be empty. */ -static void renderLists(listmode_t mode, rendlist_t** lists, uint num) +static void renderLists(listmode_t mode, rendlist_t **lists, uint num) { - uint i; - rendlist_t* list; - uint coords[MAX_TEX_UNITS]; - // If the first list is empty, we do nothing. Normally we expect // all lists to contain something. - if(num == 0 || lists[0]->last == NULL) - return; + if(!num || !lists[0]->last) return; // Setup GL state that's common to all the lists in this mode. + uint coords[MAX_TEX_UNITS]; setupPassState(mode, coords); // Draw each given list. - for(i = 0; i < num; ++i) + for(uint i = 0; i < num; ++i) { - list = lists[i]; + rendlist_t *list = lists[i]; // Setup GL state for this list, and draw the necessary subset of // primitives on the list. @@ -2075,24 +2020,21 @@ static void renderLists(listmode_t mode, rendlist_t** lists, uint num) /** * Extracts a selection of lists from the hash. */ -static uint collectLists(listhash_t* table, rendlist_t** lists) +static uint collectLists(listhash_t *table, rendlist_t **lists) { - uint i, count; - rendlist_t* it; - // Collect a list of rendering lists. - count = 0; - for(i = 0; i < RL_HASH_SIZE; ++i) + uint count = 0; + for(uint i = 0; i < RL_HASH_SIZE; ++i) { - for(it = table[i].first; it; it = it->next) + for(rendlist_t *it = table[i].first; it; it = it->next) { // Only non-empty lists are collected. if(it->last != NULL) { if(count == MAX_RLISTS) { -#ifdef _DEBUG -Con_Error("collectLists: Ran out of MAX_RLISTS.\n"); +#ifdef DENG_DEBUG + Con_Error("collectLists: Exhausted MAX_RLISTS.\n"); #endif return count; } @@ -2108,13 +2050,13 @@ Con_Error("collectLists: Ran out of MAX_RLISTS.\n"); * details and dynamic lights. Details take precedence (they always cover * entire primitives, and usually *all* of the surfaces in a scene). */ -void RL_RenderAllLists(void) +void RL_RenderAllLists() { // Pointers to all the rendering lists. - rendlist_t* lists[MAX_RLISTS]; + rendlist_t *lists[MAX_RLISTS]; uint count; - assert(!Sys_GLCheckError()); + DENG_ASSERT(!Sys_GLCheckError()); LIBDENG_ASSERT_IN_MAIN_THREAD(); LIBDENG_ASSERT_GL_CONTEXT_ACTIVE(); @@ -2352,7 +2294,6 @@ END_PROF( PROF_RL_RENDER_SHINY ); /** * Shadow Pass: Objects and FakeRadio */ - { int oldr = renderTextures; renderTextures = true; @@ -2365,7 +2306,6 @@ BEGIN_PROF( PROF_RL_RENDER_SHADOW ); END_PROF( PROF_RL_RENDER_SHADOW ); renderTextures = oldr; - } // Return to the normal GL state. selectTexUnits(1); @@ -2398,5 +2338,5 @@ BEGIN_PROF( PROF_RL_RENDER_MASKED ); END_PROF( PROF_RL_RENDER_MASKED ); END_PROF( PROF_RL_RENDER_ALL ); - assert(!Sys_GLCheckError()); + DENG_ASSERT(!Sys_GLCheckError()); } diff --git a/doomsday/engine/src/render/rend_main.c b/doomsday/engine/src/render/rend_main.cpp similarity index 88% rename from doomsday/engine/src/render/rend_main.c rename to doomsday/engine/src/render/rend_main.cpp index cb41af3de3..13d49851d0 100644 --- a/doomsday/engine/src/render/rend_main.c +++ b/doomsday/engine/src/render/rend_main.cpp @@ -1,31 +1,27 @@ -/**\file rend_main.c - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file rend_main.cpp Map Renderer. * - *\author Copyright © 2003-2012 Jaakko Keränen - *\author Copyright © 2006-2012 Daniel Swanson - *\author Copyright © 2006 Jamie Jones + * @author Copyright © 2003-2012 Jaakko Keränen + * @author Copyright © 2006-2012 Daniel Swanson + * @author Copyright © 2006 Jamie Jones * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 + * 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 */ -#include -#include -#include +#include +#include +#include #include "de_base.h" #include "de_console.h" @@ -38,8 +34,9 @@ #include "de_system.h" #include "network/net_main.h" -#include "resource/texturevariant.h" +#include "resource/materialsnapshot.h" #include "resource/materialvariant.h" +#include "resource/texturevariant.h" #include "map/blockmapvisual.h" // Surface (tangent-space) Vector Flags. @@ -63,10 +60,10 @@ void Rend_DrawBBox(coord_t const pos[3], coord_t w, coord_t l, coord_t h, float void Rend_DrawArrow(coord_t const pos[3], float a, float s, float const color3f[3], float alpha); -static void Rend_RenderBoundingBoxes(void); +static void Rend_RenderBoundingBoxes(); static DGLuint constructBBox(DGLuint name, float br); -static uint Rend_BuildBspLeafPlaneGeometry(BspLeaf* leaf, boolean antiClockwise, - coord_t height, rvertex_t** verts, uint* vertsSize); +static uint Rend_BuildBspLeafPlaneGeometry(BspLeaf *leaf, boolean antiClockwise, + coord_t height, rvertex_t **verts, uint *vertsSize); boolean usingFog = false; // Is the fog in use? float fogColor[4]; @@ -134,56 +131,56 @@ byte devSoundOrigins = 0; ///< cvar @c 1= Draw sound origin debug display. byte devSurfaceVectors = 0; byte devNoTexFix = 0; -static BspLeaf* currentBspLeaf; // BSP leaf currently being drawn. +static BspLeaf *currentBspLeaf; // BSP leaf currently being drawn. static boolean firstBspLeaf; // No range checking for the first one. -void Rend_Register(void) +void Rend_Register() { #ifdef __CLIENT - C_VAR_FLOAT("rend-camera-fov", &fieldOfView, 0, 1, 179); - - C_VAR_FLOAT("rend-glow", &glowFactor, 0, 0, 2); - C_VAR_INT("rend-glow-height", &glowHeightMax, 0, 0, 1024); - C_VAR_FLOAT("rend-glow-scale", &glowHeightFactor, 0, 0.1f, 10); - C_VAR_INT("rend-glow-wall", &useWallGlow, 0, 0, 1); - - C_VAR_INT2("rend-light", &useDynLights, 0, 0, 1, LO_UnlinkMobjLumobjs); - C_VAR_INT2("rend-light-ambient", &ambientLight, 0, 0, 255, Rend_CalcLightModRange); - C_VAR_FLOAT("rend-light-attenuation", &rendLightDistanceAttentuation, CVF_NO_MAX, 0, 0); - C_VAR_FLOAT("rend-light-bright", &dynlightFactor, 0, 0, 1); - C_VAR_FLOAT2("rend-light-compression", &lightRangeCompression, 0, -1, 1, Rend_CalcLightModRange); - C_VAR_FLOAT("rend-light-fog-bright", &dynlightFogBright, 0, 0, 1); - C_VAR_FLOAT2("rend-light-sky", &rendSkyLight, 0, 0, 1, LG_MarkAllForUpdate); - C_VAR_BYTE2("rend-light-sky-auto", &rendSkyLightAuto, 0, 0, 1, LG_MarkAllForUpdate); - C_VAR_FLOAT("rend-light-wall-angle", &rendLightWallAngle, CVF_NO_MAX, 0, 0); - C_VAR_BYTE("rend-light-wall-angle-smooth", &rendLightWallAngleSmooth, 0, 0, 1); - - C_VAR_BYTE("rend-map-material-precache", &precacheMapMaterials, 0, 0, 1); - - C_VAR_INT("rend-shadow", &useShadows, 0, 0, 1); - C_VAR_FLOAT("rend-shadow-darkness", &shadowFactor, 0, 0, 2); - C_VAR_INT("rend-shadow-far", &shadowMaxDistance, CVF_NO_MAX, 0, 0); - C_VAR_INT("rend-shadow-radius-max", &shadowMaxRadius, CVF_NO_MAX, 0, 0); - - C_VAR_BYTE("rend-tex-anim-smooth", &smoothTexAnim, 0, 0, 1); - C_VAR_INT("rend-tex-shiny", &useShinySurfaces, 0, 0, 1); - - C_VAR_INT("rend-dev-sky", &devRendSkyMode, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-sky-always", &devRendSkyAlways, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-freeze", &freezeRLs, CVF_NO_ARCHIVE, 0, 1); - C_VAR_INT("rend-dev-cull-leafs", &devNoCulling, CVF_NO_ARCHIVE,0,1); - C_VAR_INT("rend-dev-mobj-bbox", &devMobjBBox, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-mobj-show-vlights", &devMobjVLights, CVF_NO_ARCHIVE, 0, 1); - C_VAR_INT("rend-dev-polyobj-bbox", &devPolyobjBBox, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-light-mod", &devLightModRange, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-tex-showfix", &devNoTexFix, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-blockmap-debug", &bmapShowDebug, CVF_NO_ARCHIVE, 0, 4); - C_VAR_FLOAT("rend-dev-blockmap-debug-size", &bmapDebugSize, CVF_NO_ARCHIVE, .1f, 100); - C_VAR_BYTE("rend-dev-vertex-show-indices", &devVertexIndices, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-vertex-show-bars", &devVertexBars, CVF_NO_ARCHIVE, 0, 1); - C_VAR_BYTE("rend-dev-surface-show-vectors", &devSurfaceVectors, CVF_NO_ARCHIVE, 0, 7); - C_VAR_BYTE("rend-dev-soundorigins", &devSoundOrigins, CVF_NO_ARCHIVE, 0, 7); + C_VAR_FLOAT ("rend-camera-fov", &fieldOfView, 0, 1, 179); + + C_VAR_FLOAT ("rend-glow", &glowFactor, 0, 0, 2); + C_VAR_INT ("rend-glow-height", &glowHeightMax, 0, 0, 1024); + C_VAR_FLOAT ("rend-glow-scale", &glowHeightFactor, 0, 0.1f, 10); + C_VAR_INT ("rend-glow-wall", &useWallGlow, 0, 0, 1); + + C_VAR_INT2 ("rend-light", &useDynLights, 0, 0, 1, LO_UnlinkMobjLumobjs); + C_VAR_INT2 ("rend-light-ambient", &ambientLight, 0, 0, 255, Rend_CalcLightModRange); + C_VAR_FLOAT ("rend-light-attenuation", &rendLightDistanceAttentuation, CVF_NO_MAX, 0, 0); + C_VAR_FLOAT ("rend-light-bright", &dynlightFactor, 0, 0, 1); + C_VAR_FLOAT2("rend-light-compression", &lightRangeCompression, 0, -1, 1, Rend_CalcLightModRange); + C_VAR_FLOAT ("rend-light-fog-bright", &dynlightFogBright, 0, 0, 1); + C_VAR_FLOAT2("rend-light-sky", &rendSkyLight, 0, 0, 1, LG_MarkAllForUpdate); + C_VAR_BYTE2 ("rend-light-sky-auto", &rendSkyLightAuto, 0, 0, 1, LG_MarkAllForUpdate); + C_VAR_FLOAT ("rend-light-wall-angle", &rendLightWallAngle, CVF_NO_MAX, 0, 0); + C_VAR_BYTE ("rend-light-wall-angle-smooth", &rendLightWallAngleSmooth, 0, 0, 1); + + C_VAR_BYTE ("rend-map-material-precache", &precacheMapMaterials, 0, 0, 1); + + C_VAR_INT ("rend-shadow", &useShadows, 0, 0, 1); + C_VAR_FLOAT ("rend-shadow-darkness", &shadowFactor, 0, 0, 2); + C_VAR_INT ("rend-shadow-far", &shadowMaxDistance, CVF_NO_MAX, 0, 0); + C_VAR_INT ("rend-shadow-radius-max", &shadowMaxRadius, CVF_NO_MAX, 0, 0); + + C_VAR_BYTE ("rend-tex-anim-smooth", &smoothTexAnim, 0, 0, 1); + C_VAR_INT ("rend-tex-shiny", &useShinySurfaces, 0, 0, 1); + + C_VAR_INT ("rend-dev-sky", &devRendSkyMode, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-sky-always", &devRendSkyAlways, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-freeze", &freezeRLs, CVF_NO_ARCHIVE, 0, 1); + C_VAR_INT ("rend-dev-cull-leafs", &devNoCulling, CVF_NO_ARCHIVE,0,1); + C_VAR_INT ("rend-dev-mobj-bbox", &devMobjBBox, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-mobj-show-vlights", &devMobjVLights, CVF_NO_ARCHIVE, 0, 1); + C_VAR_INT ("rend-dev-polyobj-bbox", &devPolyobjBBox, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-light-mod", &devLightModRange, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-tex-showfix", &devNoTexFix, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-blockmap-debug", &bmapShowDebug, CVF_NO_ARCHIVE, 0, 4); + C_VAR_FLOAT ("rend-dev-blockmap-debug-size", &bmapDebugSize, CVF_NO_ARCHIVE, .1f, 100); + C_VAR_BYTE ("rend-dev-vertex-show-indices", &devVertexIndices, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-vertex-show-bars", &devVertexBars, CVF_NO_ARCHIVE, 0, 1); + C_VAR_BYTE ("rend-dev-surface-show-vectors", &devSurfaceVectors, CVF_NO_ARCHIVE, 0, 7); + C_VAR_BYTE ("rend-dev-soundorigins", &devSoundOrigins, CVF_NO_ARCHIVE, 0, 7); RL_Register(); LO_Register(); @@ -206,25 +203,27 @@ void Rend_Register(void) */ coord_t Rend_PointDist3D(coord_t const point[3]) { - return M_ApproxDistance3(vOrigin[VX] - point[VX], vOrigin[VZ] - point[VY], 1.2 * (vOrigin[VY] - point[VZ])); + return M_ApproxDistance3(vOrigin[VX] - point[VX], + vOrigin[VZ] - point[VY], + 1.2 * (vOrigin[VY] - point[VZ])); } #ifdef __CLIENT__ -void Rend_Init(void) +void Rend_Init() { C_Init(); RL_Init(); Sky_Init(); } -void Rend_Shutdown(void) +void Rend_Shutdown() { RL_Shutdown(); } /// World/map renderer reset. -void Rend_Reset(void) +void Rend_Reset() { LO_Clear(); // Free lumobj stuff. if(dlBBox) @@ -236,7 +235,7 @@ void Rend_Reset(void) void Rend_ModelViewMatrix(boolean useAngles) { - const viewdata_t* viewData = R_ViewData(viewPlayer - ddPlayers); + viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers); vOrigin[VX] = viewData->current.origin[VX]; vOrigin[VY] = viewData->current.origin[VZ]; @@ -258,40 +257,38 @@ void Rend_ModelViewMatrix(boolean useAngles) glTranslatef(-vOrigin[VX], -vOrigin[VY], -vOrigin[VZ]); } -static __inline double viewFacingDot(coord_t v1[2], coord_t v2[2]) +static inline double viewFacingDot(coord_t v1[2], coord_t v2[2]) { // The dot product. return (v1[VY] - v2[VY]) * (v1[VX] - vOrigin[VX]) + (v2[VX] - v1[VX]) * (v1[VY] - vOrigin[VZ]); } -const materialvariantspecification_t* Rend_MapSurfaceDiffuseMaterialSpec(void) +materialvariantspecification_t const *Rend_MapSurfaceDiffuseMaterialSpec() { return Materials_VariantSpecificationForContext(MC_MAPSURFACE, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, -1, -1, -1, true, true, false, false); } -void Rend_VertexColorsGlow(ColorRawf* colors, size_t num, float glow) +void Rend_VertexColorsGlow(ColorRawf *colors, size_t num, float glow) { - size_t i; - for(i = 0; i < num; ++i) + for(size_t i = 0; i < num; ++i) { - ColorRawf* c = &colors[i]; + ColorRawf *c = &colors[i]; c->rgba[CR] = c->rgba[CG] = c->rgba[CB] = glow; } } -void Rend_VertexColorsAlpha(ColorRawf* colors, size_t num, float alpha) +void Rend_VertexColorsAlpha(ColorRawf *colors, size_t num, float alpha) { - size_t i; - for(i = 0; i < num; ++i) + for(size_t i = 0; i < num; ++i) { colors[i].rgba[CA] = alpha; } } -void Rend_ApplyTorchLight(float* color, float distance) +void Rend_ApplyTorchLight(float *color, float distance) { - ddplayer_t* ddpl = &viewPlayer->shared; + ddplayer_t *ddpl = &viewPlayer->shared; // Disabled? if(!ddpl->fixedColorMap) return; @@ -319,10 +316,10 @@ void Rend_ApplyTorchLight(float* color, float distance) } } -static void lightVertex(ColorRawf* color, const rvertex_t* vtx, float lightLevel, - const float* ambientColor) +static void lightVertex(ColorRawf *color, rvertex_t const *vtx, float lightLevel, + float const *ambientColor) { - float dist = Rend_PointDist2D(vtx->pos); + float dist = Rend_PointDist2D(vtx->pos); float lightVal = R_DistAttenuateLightLevel(dist, lightLevel); // Add extra light. @@ -336,29 +333,26 @@ static void lightVertex(ColorRawf* color, const rvertex_t* vtx, float lightLevel color->rgba[CB] = lightVal * ambientColor[CB]; } -static void lightVertices(size_t num, ColorRawf* colors, const rvertex_t* verts, - float lightLevel, const float* ambientColor) +static void lightVertices(size_t num, ColorRawf *colors, rvertex_t const *verts, + float lightLevel, float const *ambientColor) { - size_t i; - for(i = 0; i < num; ++i) + for(size_t i = 0; i < num; ++i) { lightVertex(colors+i, verts+i, lightLevel, ambientColor); } } -void Rend_VertexColorsApplyTorchLight(ColorRawf* colors, const rvertex_t* vertices, +void Rend_VertexColorsApplyTorchLight(ColorRawf *colors, rvertex_t const *vertices, size_t numVertices) { - ddplayer_t* ddpl = &viewPlayer->shared; - size_t i; - // Disabled? + ddplayer_t* ddpl = &viewPlayer->shared; if(!ddpl->fixedColorMap) return; - for(i = 0; i < numVertices; ++i) + for(size_t i = 0; i < numVertices; ++i) { - const rvertex_t* vtx = &vertices[i]; - ColorRawf* c = &colors[i]; + rvertex_t const *vtx = &vertices[i]; + ColorRawf *c = &colors[i]; Rend_ApplyTorchLight(c->rgba, Rend_PointDist2D(vtx->pos)); } } @@ -372,7 +366,7 @@ void Rend_VertexColorsApplyTorchLight(ColorRawf* colors, const rvertex_t* vertic * * @return @ref sideSectionFlags denoting which sections are potentially visible. */ -static byte pvisibleLineSections(LineDef* line, int backSide) +static byte pvisibleLineSections(LineDef *line, int backSide) { byte sections = 0; @@ -385,13 +379,13 @@ static byte pvisibleLineSections(LineDef* line, int backSide) } else { - const SideDef* sideDef = line->L_sidedef(backSide); - const Sector* fsec = line->L_sector(backSide); - const Sector* bsec = line->L_sector(backSide^1); - const Plane* fceil = fsec->SP_plane(PLN_CEILING); - const Plane* ffloor = fsec->SP_plane(PLN_FLOOR); - const Plane* bceil = bsec->SP_plane(PLN_CEILING); - const Plane* bfloor = bsec->SP_plane(PLN_FLOOR); + SideDef const *sideDef = line->L_sidedef(backSide); + Sector const *fsec = line->L_sector(backSide); + Sector const *bsec = line->L_sector(backSide^1); + Plane const *fceil = fsec->SP_plane(PLN_CEILING); + Plane const *ffloor = fsec->SP_plane(PLN_FLOOR); + Plane const *bceil = bsec->SP_plane(PLN_CEILING); + Plane const *bfloor = bsec->SP_plane(PLN_FLOOR); sections |= SSF_MIDDLE | SSF_BOTTOM | SSF_TOP; @@ -415,62 +409,67 @@ static byte pvisibleLineSections(LineDef* line, int backSide) return sections; } -static void selectSurfaceColors(const float** topColor, - const float** bottomColor, SideDef* side, SideDefSection section) +static void selectSurfaceColors(float const **topColor, + float const **bottomColor, SideDef *side, SideDefSection section) { switch(section) { case SS_MIDDLE: if(side->flags & SDF_BLENDMIDTOTOP) { - *topColor = side->SW_toprgba; + *topColor = side->SW_toprgba; *bottomColor = side->SW_middlergba; } else if(side->flags & SDF_BLENDMIDTOBOTTOM) { - *topColor = side->SW_middlergba; + *topColor = side->SW_middlergba; *bottomColor = side->SW_bottomrgba; } else { - *topColor = side->SW_middlergba; - *bottomColor = NULL; + *topColor = side->SW_middlergba; + *bottomColor = 0; } break; case SS_TOP: if(side->flags & SDF_BLENDTOPTOMID) { - *topColor = side->SW_toprgba; + *topColor = side->SW_toprgba; *bottomColor = side->SW_middlergba; } else { - *topColor = side->SW_toprgba; - *bottomColor = NULL; + *topColor = side->SW_toprgba; + *bottomColor = 0; } break; case SS_BOTTOM: if(side->flags & SDF_BLENDBOTTOMTOMID) { - *topColor = side->SW_middlergba; + *topColor = side->SW_middlergba; *bottomColor = side->SW_bottomrgba; } else { - *topColor = side->SW_bottomrgba; - *bottomColor = NULL; + *topColor = side->SW_bottomrgba; + *bottomColor = 0; } break; - default: - break; + default: break; } } -static __inline const materialvariantspecification_t* -mapSurfaceMaterialSpec(int wrapS, int wrapT) +int RIT_FirstDynlightIterator(dynlight_t const *dyn, void *paramaters) +{ + dynlight_t const **ptr = (dynlight_t const **)paramaters; + *ptr = dyn; + return 1; // Stop iteration. +} + +static inline materialvariantspecification_t const *mapSurfaceMaterialSpec(int wrapS, int wrapT) { return Materials_VariantSpecificationForContext(MC_MAPSURFACE, 0, 0, 0, 0, wrapS, wrapT, -1, -1, -1, @@ -492,11 +491,11 @@ int RIT_FirstDynlightIterator(const dynlight_t* dyn, void* paramaters) * of sprites. This is necessary because all masked polygons must be * rendered back-to-front, or there will be alpha artifacts along edges. */ -void Rend_AddMaskedPoly(const rvertex_t* rvertices, const ColorRawf* rcolors, - coord_t wallLength, MaterialVariant* material, float const texOffset[2], +void Rend_AddMaskedPoly(rvertex_t const *rvertices, ColorRawf const *rcolors, + coord_t wallLength, MaterialVariant *material, float const texOffset[2], blendmode_t blendMode, uint lightListIdx, float glow) { - vissprite_t* vis = R_NewVisSprite(); + vissprite_t *vis = R_NewVisSprite(); int i, c; vis->type = VSPR_MASKED_WALL; @@ -519,16 +518,16 @@ void Rend_AddMaskedPoly(const rvertex_t* rvertices, const ColorRawf* rcolors, // wrapping. if(renderTextures) { - const materialsnapshot_t* ms = Materials_PrepareVariant(material); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_PrepareVariant(material)); int wrapS = GL_REPEAT, wrapT = GL_REPEAT; - VS_WALL(vis)->texCoord[0][VX] = VS_WALL(vis)->texOffset[0] / ms->size.width; - VS_WALL(vis)->texCoord[1][VX] = VS_WALL(vis)->texCoord[0][VX] + wallLength / ms->size.width; - VS_WALL(vis)->texCoord[0][VY] = VS_WALL(vis)->texOffset[1] / ms->size.height; + VS_WALL(vis)->texCoord[0][VX] = VS_WALL(vis)->texOffset[0] / ms.dimensions().width(); + VS_WALL(vis)->texCoord[1][VX] = VS_WALL(vis)->texCoord[0][VX] + wallLength / ms.dimensions().width(); + VS_WALL(vis)->texCoord[0][VY] = VS_WALL(vis)->texOffset[1] / ms.dimensions().height(); VS_WALL(vis)->texCoord[1][VY] = VS_WALL(vis)->texCoord[0][VY] + - (rvertices[3].pos[VZ] - rvertices[0].pos[VZ]) / ms->size.height; + (rvertices[3].pos[VZ] - rvertices[0].pos[VZ]) / ms.dimensions().height(); - if(ms && !ms->isOpaque) + if(!ms.isOpaque()) { if(!(VS_WALL(vis)->texCoord[0][VX] < 0 || VS_WALL(vis)->texCoord[0][VX] > 1 || VS_WALL(vis)->texCoord[1][VX] < 0 || VS_WALL(vis)->texCoord[1][VX] > 1)) @@ -572,7 +571,7 @@ void Rend_AddMaskedPoly(const rvertex_t* rvertices, const ColorRawf* rcolors, if(glow < 1 && lightListIdx && numTexUnits > 1 && envModAdd && !(rcolors[0].rgba[CA] < 1)) { - const dynlight_t* dyn = NULL; + dynlight_t const *dyn = NULL; /** * The dynlights will have already been sorted so that the brightest @@ -586,7 +585,9 @@ void Rend_AddMaskedPoly(const rvertex_t* rvertices, const ColorRawf* rcolors, VS_WALL(vis)->modTexCoord[1][0] = dyn->t[0]; VS_WALL(vis)->modTexCoord[1][1] = dyn->t[1]; for(c = 0; c < 4; ++c) + { VS_WALL(vis)->modColor[c] = dyn->color.rgba[c]; + } } else { @@ -596,19 +597,17 @@ void Rend_AddMaskedPoly(const rvertex_t* rvertices, const ColorRawf* rcolors, #endif // __CLIENT__ -static void quadTexCoords(rtexcoord_t* tc, const rvertex_t* rverts, +static void quadTexCoords(rtexcoord_t *tc, rvertex_t const *rverts, coord_t wallLength, coord_t const topLeft[3]) { - tc[0].st[0] = tc[1].st[0] = - rverts[0].pos[VX] - topLeft[VX]; - tc[3].st[1] = tc[1].st[1] = - rverts[0].pos[VY] - topLeft[VY]; + tc[0].st[0] = tc[1].st[0] = rverts[0].pos[VX] - topLeft[VX]; + tc[3].st[1] = tc[1].st[1] = rverts[0].pos[VY] - topLeft[VY]; tc[3].st[0] = tc[2].st[0] = tc[0].st[0] + wallLength; tc[2].st[1] = tc[3].st[1] + (rverts[1].pos[VZ] - rverts[0].pos[VZ]); tc[0].st[1] = tc[3].st[1] + (rverts[3].pos[VZ] - rverts[2].pos[VZ]); } -static void quadLightCoords(rtexcoord_t* tc, float const s[2], float const t[2]) +static void quadLightCoords(rtexcoord_t *tc, float const s[2], float const t[2]) { tc[1].st[0] = tc[0].st[0] = s[0]; tc[1].st[1] = tc[3].st[1] = t[0]; @@ -621,8 +620,8 @@ static float shinyVertical(float dy, float dx) return ((atan(dy/dx) / (PI/2)) + 1) / 2; } -static void quadShinyTexCoords(rtexcoord_t* tc, const rvertex_t* topLeft, - const rvertex_t* bottomRight, coord_t wallLength) +static void quadShinyTexCoords(rtexcoord_t *tc, rvertex_t const *topLeft, + rvertex_t const *bottomRight, coord_t wallLength) { vec2f_t surface, normal, projected, s, reflected, view; float distance, angle, prevAngle = 0; @@ -677,7 +676,7 @@ static void quadShinyTexCoords(rtexcoord_t* tc, const rvertex_t* topLeft, } } -static void flatShinyTexCoords(rtexcoord_t* tc, const float xyz[3]) +static void flatShinyTexCoords(rtexcoord_t *tc, float const xyz[3]) { float distance, offset; vec2f_t view, start; @@ -703,25 +702,25 @@ static void flatShinyTexCoords(rtexcoord_t* tc, const float xyz[3]) tc->st[1] = shinyVertical(vOrigin[VY] - xyz[VZ], distance); } -static float getSnapshots(const materialsnapshot_t** msA, - const materialsnapshot_t** msB, material_t* mat) +static float getSnapshots(de::MaterialSnapshot const **msA, + de::MaterialSnapshot const **msB, material_t *mat) { - const materialvariantspecification_t* spec = mapSurfaceMaterialSpec(GL_REPEAT, GL_REPEAT); + materialvariantspecification_t const *spec = mapSurfaceMaterialSpec(GL_REPEAT, GL_REPEAT); float interPos = 0; - assert(msA); + DENG_ASSERT(msA); - *msA = Materials_Prepare(mat, spec, true); + *msA = reinterpret_cast(Materials_Prepare(mat, spec, true)); // Smooth Texture Animation? if(msB) { - MaterialVariant* variant = Materials_ChooseVariant(mat, spec, false, false); + MaterialVariant *variant = Materials_ChooseVariant(mat, spec, false, false); if(MaterialVariant_TranslationCurrent(variant) != MaterialVariant_TranslationNext(variant)) { - MaterialVariant* matB = MaterialVariant_TranslationNext(variant); + MaterialVariant *matB = MaterialVariant_TranslationNext(variant); // Prepare the inter texture. - *msB = Materials_PrepareVariant(matB); + *msB = reinterpret_cast(Materials_PrepareVariant(matB)); // If fog is active, inter=0 is accepted as well. Otherwise // flickering may occur if the rendering passes don't match for @@ -747,15 +746,15 @@ typedef struct { int flags; /// @see rendpolyFlags blendmode_t blendMode; pvec3d_t texTL, texBR; - const float* texOffset; - const float* texScale; - const float* normal; // Surface normal. + float const *texOffset; + float const *texScale; + float const *normal; // Surface normal. float alpha; float sectorLightLevel; float surfaceLightLevelDL; float surfaceLightLevelDR; - const float* sectorLightColor; - const float* surfaceColor; + float const *sectorLightColor; + float const *surfaceColor; uint lightListIdx; // List of lights that affect this poly. uint shadowListIdx; // List of shadows that affect this poly. @@ -763,28 +762,28 @@ typedef struct { boolean forceOpaque; // For bias: - void* mapObject; + void *mapObject; uint elmIdx; - biassurface_t* bsuf; + biassurface_t *bsuf; // Wall only: struct { - const coord_t* segLength; - const float* surfaceColor2; // Secondary color. + coord_t const *segLength; + float const *surfaceColor2; // Secondary color. struct { - walldivnode_t* firstDiv; + walldivnode_t *firstDiv; uint divCount; } left; struct { - walldivnode_t* firstDiv; + walldivnode_t *firstDiv; uint divCount; } right; } wall; } rendworldpoly_params_t; -static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices, - const rendworldpoly_params_t* p, const materialsnapshot_t* msA, float inter, - const materialsnapshot_t* msB) +static boolean renderWorldPoly(rvertex_t *rvertices, uint numVertices, + rendworldpoly_params_t const *p, de::MaterialSnapshot const *msA, float inter, + de::MaterialSnapshot const *msB) { boolean useLights = false, useShadows = false, hasDynlights = false; rtexcoord_t* primaryCoords = NULL, *interCoords = NULL, *modCoords = NULL; @@ -793,22 +792,22 @@ static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices, ColorRawf* shinyColors = NULL; rtexcoord_t* shinyTexCoords = NULL; float modTexTC[2][2] = {{ 0, 0 }, { 0, 0 }}; - ColorRawf modColor = { 0, 0, 0, 0 }; + ColorRawf modColor; DGLuint modTex = 0; float glowing = p->glowing; boolean drawAsVisSprite = false; - boolean skyMaskedMaterial = ((p->flags & RPF_SKYMASK) || (msA && Material_IsSkyMasked(MaterialVariant_GeneralCase(msA->material)))); + boolean skyMaskedMaterial = ((p->flags & RPF_SKYMASK) || (msA && Material_IsSkyMasked(msA->material().generalCase()))); // Map RTU configuration from prepared MaterialSnapshot(s). - const rtexmapunit_t* primaryRTU = (!(p->flags & RPF_SKYMASK))? &MSU(msA, MTU_PRIMARY) : NULL; - const rtexmapunit_t* primaryDetailRTU = (r_detail && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&MSU(msA, MTU_DETAIL)))? &MSU(msA, MTU_DETAIL) : NULL; - const rtexmapunit_t* interRTU = (!(p->flags & RPF_SKYMASK) && msB && Rtu_HasTexture(&MSU(msB, MTU_PRIMARY)))? &MSU(msB, MTU_PRIMARY) : NULL; - const rtexmapunit_t* interDetailRTU = (r_detail && !(p->flags & RPF_SKYMASK) && msB && Rtu_HasTexture(&MSU(msB, MTU_DETAIL)))? &MSU(msB, MTU_DETAIL) : NULL; - const rtexmapunit_t* shinyRTU = (useShinySurfaces && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&MSU(msA, MTU_REFLECTION)))? &MSU(msA, MTU_REFLECTION) : NULL; - const rtexmapunit_t* shinyMaskRTU = (useShinySurfaces && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&MSU(msA, MTU_REFLECTION)) && Rtu_HasTexture(&MSU(msA, MTU_REFLECTION_MASK)))? &MSU(msA, MTU_REFLECTION_MASK) : NULL; + const rtexmapunit_t* primaryRTU = (!(p->flags & RPF_SKYMASK))? &msA->unit(MTU_PRIMARY) : NULL; + const rtexmapunit_t* primaryDetailRTU = (r_detail && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&msA->unit(MTU_DETAIL)))? &msA->unit(MTU_DETAIL) : NULL; + const rtexmapunit_t* interRTU = (!(p->flags & RPF_SKYMASK) && msB && Rtu_HasTexture(&msB->unit(MTU_PRIMARY)))? &msB->unit(MTU_PRIMARY) : NULL; + const rtexmapunit_t* interDetailRTU = (r_detail && !(p->flags & RPF_SKYMASK) && msB && Rtu_HasTexture(&msB->unit(MTU_DETAIL)))? &msB->unit(MTU_DETAIL) : NULL; + const rtexmapunit_t* shinyRTU = (useShinySurfaces && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&msA->unit(MTU_REFLECTION)))? &msA->unit(MTU_REFLECTION) : NULL; + const rtexmapunit_t* shinyMaskRTU = (useShinySurfaces && !(p->flags & RPF_SKYMASK) && Rtu_HasTexture(&msA->unit(MTU_REFLECTION)) && Rtu_HasTexture(&msA->unit(MTU_REFLECTION_MASK)))? &msA->unit(MTU_REFLECTION_MASK) : NULL; if(!p->forceOpaque && !(p->flags & RPF_SKYMASK) && - (!msA->isOpaque || p->alpha < 1 || p->blendMode > 0)) + (!msA->isOpaque() || p->alpha < 1 || p->blendMode > 0)) drawAsVisSprite = true; if(!skyMaskedMaterial) @@ -1016,14 +1015,13 @@ static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices, if(shinyRTU && !drawAsVisSprite) { - uint i; - // Strength of the shine. - for(i = 0; i < numVertices; ++i) + vec3f_t const &minColor = msA->reflectionMinColor(); + for(uint i = 0; i < numVertices; ++i) { - shinyColors[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], msA->shinyMinColor[CR]); - shinyColors[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], msA->shinyMinColor[CG]); - shinyColors[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], msA->shinyMinColor[CB]); + shinyColors[i].rgba[CR] = MAX_OF(rcolors[i].rgba[CR], minColor[CR]); + shinyColors[i].rgba[CG] = MAX_OF(rcolors[i].rgba[CG], minColor[CG]); + shinyColors[i].rgba[CB] = MAX_OF(rcolors[i].rgba[CB], minColor[CB]); shinyColors[i].rgba[CA] = shinyRTU->opacity; } } @@ -1061,14 +1059,14 @@ static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices, if(drawAsVisSprite) { - assert(p->isWall); + DENG_ASSERT(p->isWall); /** * Masked polys (walls) get a special treatment (=> vissprite). * This is needed because all masked polys must be sorted (sprites * are masked polys). Otherwise there will be artifacts. */ - Rend_AddMaskedPoly(rvertices, rcolors, *p->wall.segLength, msA->material, + Rend_AddMaskedPoly(rvertices, rcolors, *p->wall.segLength, reinterpret_cast(&msA->material()), p->texOffset, p->blendMode, p->lightListIdx, glowing); R_FreeRendTexCoords(primaryCoords); @@ -1267,7 +1265,7 @@ static boolean renderWorldPoly(rvertex_t* rvertices, uint numVertices, R_FreeRendColors(shinyColors); return (p->forceOpaque || skyMaskedMaterial || - !(p->alpha < 1 || !msA->isOpaque || p->blendMode > 0)); + !(p->alpha < 1 || !msA->isOpaque() || p->blendMode > 0)); } static boolean doRenderHEdge(HEdge* hedge, const pvec3f_t normal, @@ -1278,12 +1276,12 @@ static boolean doRenderHEdge(HEdge* hedge, const pvec3f_t normal, float const texOffset[2], float const texScale[2], blendmode_t blendMode, const float* color, const float* color2, biassurface_t* bsuf, uint elmIdx /*tmp*/, - const materialsnapshot_t* msA, float inter, const materialsnapshot_t* msB, + de::MaterialSnapshot const *msA, float inter, de::MaterialSnapshot const *msB, boolean isTwosidedMiddle) { rendworldpoly_params_t params; - SideDef* side = (hedge->lineDef? HEDGE_SIDEDEF(hedge) : NULL); - rvertex_t* rvertices; + SideDef *side = (hedge->lineDef? HEDGE_SIDEDEF(hedge) : NULL); + rvertex_t *rvertices; // Init the params. memset(¶ms, 0, sizeof(params)); @@ -1305,7 +1303,7 @@ static boolean doRenderHEdge(HEdge* hedge, const pvec3f_t normal, params.sectorLightColor = lightColor; params.surfaceColor = color; params.wall.surfaceColor2 = color2; - params.glowing = msA? msA->glowing : 0; + params.glowing = msA? msA->glowStrength() : 0; params.blendMode = blendMode; params.texOffset = texOffset; params.texScale = texScale; @@ -1441,7 +1439,7 @@ static void renderPlane(BspLeaf* bspLeaf, planetype_t type, coord_t height, boolean blended = false; Sector* sec = bspLeaf->sector; material_t* mat = NULL; - const materialsnapshot_t* msA = NULL, *msB = NULL; + de::MaterialSnapshot const *msA = NULL, *msB = NULL; memset(¶ms, 0, sizeof(params)); @@ -1509,16 +1507,16 @@ static void renderPlane(BspLeaf* bspLeaf, planetype_t type, coord_t height, if(texMode != 2) { - params.glowing = msA->glowing; + params.glowing = msA->glowStrength(); } else { - Surface* suf = &bspLeaf->sector->planes[elmIdx]->surface; + Surface *suf = &bspLeaf->sector->planes[elmIdx]->surface; material_t *mat = suf->material? suf->material : Materials_ToMaterial(Materials_ResolveUriCString("System:missing")); materialvariantspecification_t const *spec = Rend_MapSurfaceDiffuseMaterialSpec(); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); - params.glowing = ms->glowing; + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); + params.glowing = ms.glowStrength(); } // Dynamic lights? @@ -1662,7 +1660,7 @@ static boolean rendHEdgeSection(HEdge* hedge, SideDefSection section, boolean isTwoSided = (hedge->lineDef && hedge->lineDef->L_frontsidedef && hedge->lineDef->L_backsidedef)? true:false; blendmode_t blendMode = BM_NORMAL; const float* color = NULL, *color2 = NULL; - const materialsnapshot_t* msA = NULL, *msB = NULL; + de::MaterialSnapshot const *msA = NULL, *msB = NULL; texScale[0] = ((surface->flags & DDSUF_MATERIAL_FLIPH)? -1 : 1); texScale[1] = ((surface->flags & DDSUF_MATERIAL_FLIPV)? -1 : 1); @@ -1746,7 +1744,7 @@ static boolean rendHEdgeSection(HEdge* hedge, SideDefSection section, // Dynamic Lights? if((flags & RHF_ADD_DYNLIGHTS) && - msA->glowing < 1 && !(!useDynLights && !useWallGlow)) + msA->glowStrength() < 1 && !(!useDynLights && !useWallGlow)) { lightListIdx = LO_ProjectToSurface(((section == SS_MIDDLE && isTwoSided)? PLF_SORT_LUMINOSITY_DESC : 0), currentBspLeaf, 1, texTL, texBR, HEDGE_SIDEDEF(hedge)->SW_middletangent, HEDGE_SIDEDEF(hedge)->SW_middlebitangent, HEDGE_SIDEDEF(hedge)->SW_middlenormal); @@ -1754,14 +1752,14 @@ static boolean rendHEdgeSection(HEdge* hedge, SideDefSection section, // Dynamic shadows? if((flags & RHF_ADD_DYNSHADOWS) && - msA->glowing < 1 && Rend_MobjShadowsEnabled()) + msA->glowStrength() < 1 && Rend_MobjShadowsEnabled()) { // Glowing planes inversely diminish shadow strength. - shadowListIdx = R_ProjectShadowsToSurface(currentBspLeaf, 1 - msA->glowing, texTL, texBR, + shadowListIdx = R_ProjectShadowsToSurface(currentBspLeaf, 1 - msA->glowStrength(), texTL, texBR, HEDGE_SIDEDEF(hedge)->SW_middletangent, HEDGE_SIDEDEF(hedge)->SW_middlebitangent, HEDGE_SIDEDEF(hedge)->SW_middlenormal); } - if(msA->glowing > 0) + if(msA->glowStrength() > 0) flags &= ~RHF_ADD_RADIO; selectSurfaceColors(&color, &color2, HEDGE_SIDEDEF(hedge), section); @@ -2244,19 +2242,19 @@ static int chooseHEdgeSkyFixes(HEdge* hedge, int skyCap) return fixes; } -static __inline void Rend_BuildBspLeafSkyFixStripEdge(coord_t const vXY[2], +static inline void Rend_BuildBspLeafSkyFixStripEdge(coord_t const vXY[2], coord_t v1Z, coord_t v2Z, float texS, rvertex_t* v1, rvertex_t* v2, rtexcoord_t* t1, rtexcoord_t* t2) { if(v1) { - assert(vXY); + DENG_ASSERT(vXY); V2f_Copyd(v1->pos, vXY); v1->pos[VZ] = v1Z; } if(v2) { - assert(vXY); + DENG_ASSERT(vXY); V2f_Copyd(v2->pos, vXY); v2->pos[VZ] = v2Z; } @@ -2323,7 +2321,7 @@ static void Rend_BuildBspLeafSkyFixStripGeometry(BspLeaf* leaf, HEdge* startNode coord_t zBottom, zTop; skyFixZCoords(hedge, skyCap, &zBottom, &zTop); - assert(zBottom < zTop); + DENG_ASSERT(zBottom < zTop); if(n == 0) { @@ -2383,11 +2381,11 @@ static void Rend_WriteBspLeafSkyFixStripGeometry(BspLeaf* leaf, HEdge* startNode else { // Map RTU configuration from prepared MaterialSnapshot(s). - const materialvariantspecification_t* spec = mapSurfaceMaterialSpec(GL_REPEAT, GL_REPEAT); - const materialsnapshot_t* ms = Materials_Prepare(material, spec, true); + materialvariantspecification_t const *spec = mapSurfaceMaterialSpec(GL_REPEAT, GL_REPEAT); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(material, spec, true)); RL_LoadDefaultRtus(); - RL_MapRtu(RTU_PRIMARY, &MSU(ms, MTU_PRIMARY)); + RL_MapRtu(RTU_PRIMARY, &ms.unit(MTU_PRIMARY)); RL_AddPolyWithCoords(PT_TRIANGLE_STRIP, rendPolyFlags, vertsSize, verts, NULL, coords, NULL); } @@ -2708,7 +2706,7 @@ static void Rend_RenderSkySurfaces(int skyCap) } } -static void Rend_RenderWalls(void) +static void Rend_RenderWalls() { BspLeaf* leaf = currentBspLeaf; HEdge* hedge; @@ -2745,7 +2743,7 @@ static void Rend_RenderWalls(void) } while((hedge = hedge->next) != leaf->hedge); } -static void Rend_RenderPolyobjs(void) +static void Rend_RenderPolyobjs() { BspLeaf* leaf = currentBspLeaf; LineDef* line; @@ -2774,7 +2772,7 @@ static void Rend_RenderPolyobjs(void) } } -static void Rend_RenderPlanes(void) +static void Rend_RenderPlanes() { BspLeaf* leaf = currentBspLeaf; Sector* sect; @@ -2847,31 +2845,27 @@ static void Rend_RenderPlanes(void) * the remaining faces, i.e. the forward facing edges. This is done before * rendering edges, so solid segments cut out all unnecessary oranges. */ -static void occludeBspLeaf(const BspLeaf* bspLeaf, boolean forwardFacing) +static void occludeBspLeaf(BspLeaf const *bspLeaf, bool forwardFacing) { - coord_t fFloor, fCeil, bFloor, bCeil; - const coord_t* startv, *endv; - Sector* front, *back; - HEdge* hedge; - if(devNoCulling || !bspLeaf || !bspLeaf->hedge || P_IsInVoid(viewPlayer)) return; - front = bspLeaf->sector; - fFloor = front->SP_floorheight; - fCeil = front->SP_ceilheight; + Sector *front = bspLeaf->sector; + coord_t const fFloor = front->SP_floorheight; + coord_t const fCeil = front->SP_ceilheight; - hedge = bspLeaf->hedge; + HEdge *hedge = bspLeaf->hedge; do { // Occlusions can only happen where two sectors contact. if(hedge->lineDef && HEDGE_BACK_SECTOR(hedge) && (forwardFacing == ((hedge->frameFlags & HEDGEINF_FACINGFRONT)? true : false))) { - back = HEDGE_BACK_SECTOR(hedge); - bFloor = back->SP_floorheight; - bCeil = back->SP_ceilheight; + Sector *back = HEDGE_BACK_SECTOR(hedge); + coord_t const bFloor = back->SP_floorheight; + coord_t const bCeil = back->SP_ceilheight; // Choose start and end vertices so that it's facing forward. + coord_t const *startv, *endv; if(forwardFacing) { startv = hedge->HE_v1origin; @@ -2912,7 +2906,7 @@ static void occludeBspLeaf(const BspLeaf* bspLeaf, boolean forwardFacing) } while((hedge = hedge->next) != bspLeaf->hedge); } -static __inline boolean isNullLeaf(BspLeaf* leaf) +static inline boolean isNullLeaf(BspLeaf* leaf) { Sector* sec = leaf? leaf->sector : NULL; if(!sec) return true; // An orphan leaf? @@ -3022,7 +3016,7 @@ static void Rend_RenderNode(runtime_mapdata_header_t* bspPtr) } } -static void drawVector(const_pvec3f_t origin, const_pvec3f_t normal, float scalar, const float color[3]) +static void drawVector(const_pvec3f_t normal, float scalar, const float color[3]) { static const float black[4] = { 0, 0, 0, 0 }; @@ -3034,34 +3028,32 @@ static void drawVector(const_pvec3f_t origin, const_pvec3f_t normal, float scala glEnd(); } -static void drawSurfaceTangentSpaceVectors(Surface* suf, const_pvec3f_t origin) +static void drawSurfaceTangentSpaceVectors(Surface *suf, const_pvec3f_t origin) { -#define VISUAL_LENGTH (20) + int const VISUAL_LENGTH = 20; - static const float red[3] = { 1, 0, 0 }; - static const float green[3] = { 0, 1, 0 }; - static const float blue[3] = { 0, 0, 1 }; + static float const red[3] = { 1, 0, 0 }; + static float const green[3] = { 0, 1, 0 }; + static float const blue[3] = { 0, 0, 1 }; - assert(origin && suf); + DENG_ASSERT(origin && suf); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(origin[VX], origin[VZ], origin[VY]); - if(devSurfaceVectors & SVF_TANGENT) drawVector(origin, suf->tangent, VISUAL_LENGTH, red); - if(devSurfaceVectors & SVF_BITANGENT) drawVector(origin, suf->bitangent, VISUAL_LENGTH, green); - if(devSurfaceVectors & SVF_NORMAL) drawVector(origin, suf->normal, VISUAL_LENGTH, blue); + if(devSurfaceVectors & SVF_TANGENT) drawVector(suf->tangent, VISUAL_LENGTH, red); + if(devSurfaceVectors & SVF_BITANGENT) drawVector(suf->bitangent, VISUAL_LENGTH, green); + if(devSurfaceVectors & SVF_NORMAL) drawVector(suf->normal, VISUAL_LENGTH, blue); glMatrixMode(GL_MODELVIEW); glPopMatrix(); - -#undef VISUAL_LENGTH } /** * Draw the surface normals, primarily for debug. */ -void Rend_RenderSurfaceVectors(void) +void Rend_RenderSurfaceVectors() { uint i; @@ -3180,16 +3172,12 @@ void Rend_RenderSurfaceVectors(void) static void drawSoundOrigin(coord_t const origin[3], const char* label, coord_t const eye[3]) { -#define MAX_SOUNDORIGIN_DIST 384 ///< Maximum distance from origin to eye in map coordinates. - - const Point2Raw labelOrigin = { 2, 2 }; - coord_t dist; - float alpha; + int const MAX_SOUNDORIGIN_DIST = 384; ///< Maximum distance from origin to eye in map coordinates. if(!origin || !label || !eye) return; - dist = V3d_Distance(origin, eye); - alpha = 1.f - MIN_OF(dist, MAX_SOUNDORIGIN_DIST) / MAX_SOUNDORIGIN_DIST; + coord_t dist = V3d_Distance(origin, eye); + float alpha = 1.f - MIN_OF(dist, MAX_SOUNDORIGIN_DIST) / MAX_SOUNDORIGIN_DIST; if(alpha > 0) { @@ -3203,13 +3191,12 @@ static void drawSoundOrigin(coord_t const origin[3], const char* label, coord_t glRotatef(vpitch, 1, 0, 0); glScalef(-scale, -scale, 1); + Point2Raw const labelOrigin(2, 2); UI_TextOutEx(label, &labelOrigin, UI_Color(UIC_TITLE), alpha); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } - -#undef MAX_SOUNDORIGIN_DIST } static int drawSideDefSoundOrigins(SideDef* side, void* parameters) @@ -3218,17 +3205,17 @@ static int drawSideDefSoundOrigins(SideDef* side, void* parameters) char buf[80]; dd_snprintf(buf, 80, "Side #%i (middle)", idx); - drawSoundOrigin(side->SW_middlesurface.base.origin, buf, parameters); + drawSoundOrigin(side->SW_middlesurface.base.origin, buf, (coord_t const*) parameters); dd_snprintf(buf, 80, "Side #%i (bottom)", idx); - drawSoundOrigin(side->SW_bottomsurface.base.origin, buf, parameters); + drawSoundOrigin(side->SW_bottomsurface.base.origin, buf, (coord_t const*) parameters); dd_snprintf(buf, 80, "Side #%i (top)", idx); - drawSoundOrigin(side->SW_topsurface.base.origin, buf, parameters); + drawSoundOrigin(side->SW_topsurface.base.origin, buf, (coord_t const*) parameters); return false; // Continue iteration. } -static int drawSectorSoundOrigins(Sector* sec, void* parameters) +static int drawSectorSoundOrigins(Sector *sec, void *parameters) { uint idx = GameMap_SectorIndex(theMap, sec); /// @todo Do not assume current map. char buf[80]; @@ -3240,14 +3227,14 @@ static int drawSectorSoundOrigins(Sector* sec, void* parameters) { Plane* pln = sec->SP_plane(i); dd_snprintf(buf, 80, "Sector #%i (pln:%i)", idx, i); - drawSoundOrigin(pln->PS_base.origin, buf, parameters); + drawSoundOrigin(pln->PS_base.origin, buf, (coord_t const*) parameters); } } if(devSoundOrigins & SOF_SECTOR) { dd_snprintf(buf, 80, "Sector #%i", idx); - drawSoundOrigin(sec->base.origin, buf, parameters); + drawSoundOrigin(sec->base.origin, buf, (coord_t const*) parameters); } return false; // Continue iteration. @@ -3256,7 +3243,7 @@ static int drawSectorSoundOrigins(Sector* sec, void* parameters) /** * Debugging aid for visualizing sound origins. */ -void Rend_RenderSoundOrigins(void) +void Rend_RenderSoundOrigins() { coord_t eye[3]; @@ -3323,9 +3310,9 @@ static void drawVertexPoint(const Vertex* vtx, coord_t z, float alpha) glEnd(); } -static void drawVertexBar(const Vertex* vtx, coord_t bottom, coord_t top, float alpha) +static void drawVertexBar(Vertex const *vtx, coord_t bottom, coord_t top, float alpha) { -#define EXTEND_DIST 64 + int const EXTEND_DIST = 64; static const float black[4] = { 0, 0, 0, 0 }; @@ -3340,13 +3327,11 @@ static void drawVertexBar(const Vertex* vtx, coord_t bottom, coord_t top, float glColor4fv(black); glVertex3f(vtx->origin[VX], top + EXTEND_DIST, vtx->origin[VY]); glEnd(); - -#undef EXTEND_DIST } -static void drawVertexIndex(const Vertex* vtx, coord_t z, float scale, float alpha) +static void drawVertexIndex(Vertex const *vtx, coord_t z, float scale, float alpha) { - const Point2Raw origin = { 2, 2 }; + Point2Raw const origin(2, 2); char buf[80]; FR_SetFont(fontFixed); @@ -3375,10 +3360,10 @@ static void drawVertexIndex(const Vertex* vtx, coord_t z, float scale, float alp #define MAX_VERTEX_POINT_DIST 1280 -static int drawVertex1(LineDef* li, void* context) +static int drawVertex1(LineDef *li, void *context) { - Vertex* vtx = li->L_v1; - Polyobj* po = context; + Vertex *vtx = li->L_v1; + Polyobj *po = (Polyobj *) context; coord_t dist2D = M_ApproxDistance(vOrigin[VX] - vtx->origin[VX], vOrigin[VZ] - vtx->origin[VY]); if(dist2D < MAX_VERTEX_POINT_DIST) @@ -3388,7 +3373,7 @@ static int drawVertex1(LineDef* li, void* context) if(alpha > 0) { coord_t bottom = po->bspLeaf->sector->SP_floorvisheight; - coord_t top = po->bspLeaf->sector->SP_ceilvisheight; + coord_t top = po->bspLeaf->sector->SP_ceilvisheight; if(devVertexBars) drawVertexBar(vtx, bottom, top, MIN_OF(alpha, .15f)); @@ -3421,7 +3406,7 @@ static int drawVertex1(LineDef* li, void* context) return false; // Continue iteration. } -int drawPolyObjVertexes(Polyobj* po, void* context) +static int drawPolyObjVertexes(Polyobj *po, void * /*context*/) { return Polyobj_LineIterator(po, drawVertex1, po); } @@ -3429,7 +3414,7 @@ int drawPolyObjVertexes(Polyobj* po, void* context) /** * Draw the various vertex debug aids. */ -void Rend_Vertexes(void) +void Rend_Vertexes() { float oldPointSize, oldLineWidth = 1; uint i; @@ -3553,7 +3538,7 @@ void Rend_Vertexes(void) glEnable(GL_DEPTH_TEST); } -void Rend_RenderMap(void) +void Rend_RenderMap() { binangle_t viewside; @@ -3651,7 +3636,7 @@ void Rend_RenderMap(void) * The offsets in the lightRangeModTables are added to the sector->lightLevel * during rendering (both positive and negative). */ -void Rend_CalcLightModRange(void) +void Rend_CalcLightModRange() { GameMap* map = theMap; int j, mapAmbient; @@ -3728,7 +3713,7 @@ void Rend_ApplyLightAdaptation(float* val) /** * Draws the lightModRange (for debug) */ -void R_DrawLightRange(void) +void R_DrawLightRange() { #define BLOCK_WIDTH (1.0f) #define BLOCK_HEIGHT (BLOCK_WIDTH * 255.0f) @@ -3916,13 +3901,13 @@ void Rend_DrawArrow(coord_t const pos[3], float a, float s, float const color[3] glPopMatrix(); } -static int drawMobjBBox(thinker_t* th, void* context) +static int drawMobjBBox(thinker_t *th, void * /*context*/) { - static const float red[3] = { 1, 0.2f, 0.2f}; // non-solid objects - static const float green[3] = { 0.2f, 1, 0.2f}; // solid objects - static const float yellow[3] = {0.7f, 0.7f, 0.2f}; // missiles + static float const red[3] = { 1, 0.2f, 0.2f}; // non-solid objects + static float const green[3] = { 0.2f, 1, 0.2f}; // solid objects + static float const yellow[3] = {0.7f, 0.7f, 0.2f}; // missiles - mobj_t* mo = (mobj_t*) th; + mobj_t* mo = (mobj_t *) th; coord_t eye[3], size; float alpha; @@ -3959,20 +3944,18 @@ static int drawMobjBBox(thinker_t* th, void* context) * Depth test is disabled to show all mobjs that are being rendered, regardless * if they are actually vissible (hidden by previously drawn map geometry). */ -static void Rend_RenderBoundingBoxes(void) +static void Rend_RenderBoundingBoxes() { - //static const float red[3] = { 1, 0.2f, 0.2f}; // non-solid objects - static const float green[3] = { 0.2f, 1, 0.2f}; // solid objects - static const float yellow[3] = {0.7f, 0.7f, 0.2f}; // missiles + //static float const red[3] = { 1, 0.2f, 0.2f}; // non-solid objects + static float const green[3] = { 0.2f, 1, 0.2f}; // solid objects + static float const yellow[3] = {0.7f, 0.7f, 0.2f}; // missiles - const materialvariantspecification_t* spec; - const materialsnapshot_t* ms; - material_t* mat; + materialvariantspecification_t const *spec; + material_t *mat; coord_t eye[3]; uint i; - if(!devMobjBBox && !devPolyobjBBox) - return; + if(!devMobjBBox && !devPolyobjBBox) return; #ifndef _DEBUG // Bounding boxes are not allowed in non-debug netgames. @@ -3993,9 +3976,9 @@ static void Rend_RenderBoundingBoxes(void) mat = Materials_ToMaterial(Materials_ResolveUriCString("System:bbox")); spec = Materials_VariantSpecificationForContext(MC_SPRITE, 0, 0, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 1, -2, -1, true, true, true, false); - ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); GL_BlendMode(BM_ADD); if(devMobjBBox) @@ -4004,26 +3987,24 @@ static void Rend_RenderBoundingBoxes(void) if(devPolyobjBBox) for(i = 0; i < NUM_POLYOBJS; ++i) { - const Polyobj* po = polyObjs[i]; - const Sector* sec = po->bspLeaf->sector; + Polyobj const *po = polyObjs[i]; + Sector const *sec = po->bspLeaf->sector; coord_t width = (po->aaBox.maxX - po->aaBox.minX)/2; coord_t length = (po->aaBox.maxY - po->aaBox.minY)/2; coord_t height = (sec->SP_ceilheight - sec->SP_floorheight)/2; - coord_t pos[3]; - float alpha; + coord_t pos[3]; pos[VX] = po->aaBox.minX + width; pos[VY] = po->aaBox.minY + length; pos[VZ] = sec->SP_floorheight; - alpha = 1 - ((V3d_Distance(pos, eye) / (Window_Width(theWindow)/2)) / 4); + float alpha = 1 - ((V3d_Distance(pos, eye) / (Window_Width(theWindow)/2)) / 4); if(alpha < .25f) alpha = .25f; // Don't make them totally invisible. Rend_DrawBBox(pos, width, length, height, 0, yellow, alpha, .08f, true); - {uint j; - for(j = 0; j < po->lineCount; ++j) + for(uint j = 0; j < po->lineCount; ++j) { LineDef* line = po->lines[j]; coord_t width = (line->aaBox.maxX - line->aaBox.minX)/2; @@ -4041,10 +4022,10 @@ static void Rend_RenderBoundingBoxes(void) pos[VY] = (line->L_v2origin[VY] + line->L_v1origin[VY])/2; pos[VZ] = sec->SP_floorheight; width = 0; - length = line->length/2; + length = line->length / 2; Rend_DrawBBox(pos, width, length, height, BANG2DEG(BANG_90 - line->angle), green, alpha, 0, true); - }} + } } GL_BlendMode(BM_NORMAL); diff --git a/doomsday/engine/src/render/rend_model.cpp b/doomsday/engine/src/render/rend_model.cpp index cf0275646f..bf7d3bf87d 100644 --- a/doomsday/engine/src/render/rend_model.cpp +++ b/doomsday/engine/src/render/rend_model.cpp @@ -40,9 +40,10 @@ #include #include "network/net_main.h" // for gametic +#include "resource/materialsnapshot.h" +#include "resource/materialvariant.h" #include "resource/texture.h" #include "resource/texturevariant.h" -#include "resource/materialvariant.h" #define DOTPROD(a, b) (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]) #define QATAN2(y,x) qatan2(y,x) @@ -864,7 +865,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) float normYaw, normPitch, shinyAng, shinyPnt; float inter = parm->inter; blendmode_t blending; - TextureVariant *skinTexture = NULL, *shinyTexture = NULL; + de::TextureVariant *skinTexture = NULL, *shinyTexture = NULL; int zSign = (parm->mirror? -1 : 1); LIBDENG_ASSERT_IN_MAIN_THREAD(); @@ -1063,10 +1064,10 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) // Ensure we've prepared the shiny skin. if(shininess > 0) { - Texture *tex = mf->sub[number].shinySkin; + struct texture_s *tex = mf->sub[number].shinySkin; if(tex) { - shinyTexture = GL_PrepareTextureVariant(tex, Rend_ModelShinyTextureSpec()); + shinyTexture = reinterpret_cast(GL_PrepareTextureVariant(tex, Rend_ModelShinyTextureSpec())); } else { @@ -1141,9 +1142,9 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) { materialvariantspecification_t const *spec = Materials_VariantSpecificationForContext( MC_MODELSKIN, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, 1, -2, -1, true, true, false, false); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - skinTexture = MST(ms, MTU_PRIMARY); + skinTexture = &ms.texture(MTU_PRIMARY); } else { @@ -1152,12 +1153,12 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) } else { - Texture *tex = mdl->skins[useSkin].texture; + struct texture_s *tex = mdl->skins[useSkin].texture; skinTexture = 0; if(tex) { - skinTexture = GL_PrepareTextureVariant(tex, Rend_ModelDiffuseTextureSpec(!mdl->allowTexComp)); + skinTexture = reinterpret_cast(GL_PrepareTextureVariant(tex, Rend_ModelDiffuseTextureSpec(!mdl->allowTexComp))); } } @@ -1183,7 +1184,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) { Mod_SelectTexUnits(1); GL_BlendMode(blending); - GL_BindTexture(renderTextures? skinTexture : 0); + GL_BindTexture(renderTextures? reinterpret_cast(skinTexture) : 0); Mod_RenderCommands(RC_COMMAND_COORDS, mdl->lods[activeLod].glCommands, /*numVerts,*/ @@ -1211,10 +1212,10 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) GL_ModulateTexture(11); glActiveTexture(GL_TEXTURE1); - GL_BindTexture(renderTextures ? shinyTexture : 0); + GL_BindTexture(renderTextures ? reinterpret_cast(shinyTexture) : 0); glActiveTexture(GL_TEXTURE0); - GL_BindTexture(renderTextures ? skinTexture : 0); + GL_BindTexture(renderTextures ? reinterpret_cast(skinTexture) : 0); Mod_RenderCommands(RC_BOTH_COORDS, mdl->lods[activeLod].glCommands, /*numVerts,*/ @@ -1227,7 +1228,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) { // Empty spots will get shine, too. Mod_SelectTexUnits(1); - GL_BindTexture(renderTextures ? shinyTexture : 0); + GL_BindTexture(renderTextures ? reinterpret_cast(shinyTexture) : 0); Mod_RenderCommands(RC_OTHER_COORDS, mdl->lods[activeLod].glCommands, /*numVerts,*/ modelVertices, modelColors, modelTexCoords); @@ -1245,7 +1246,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) GL_ModulateTexture(10); glActiveTexture(GL_TEXTURE1); - GL_BindTexture(renderTextures ? shinyTexture : 0); + GL_BindTexture(renderTextures ? reinterpret_cast(shinyTexture) : 0); // Multiply by shininess. for(c = 0; c < 3; ++c) @@ -1253,7 +1254,7 @@ static void Mod_RenderSubModel(uint number, rendmodelparams_t const *parm) glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); glActiveTexture(GL_TEXTURE0); - GL_BindTexture(renderTextures ? skinTexture : 0); + GL_BindTexture(renderTextures ? reinterpret_cast(skinTexture) : 0); Mod_RenderCommands(RC_BOTH_COORDS, mdl->lods[activeLod].glCommands, /*numVerts,*/ modelVertices, modelColors, diff --git a/doomsday/engine/src/render/rendpoly.cpp b/doomsday/engine/src/render/rendpoly.cpp index 98271aa10c..e1ec44abef 100644 --- a/doomsday/engine/src/render/rendpoly.cpp +++ b/doomsday/engine/src/render/rendpoly.cpp @@ -329,10 +329,10 @@ void Rtu_Init(rtexmapunit_t* rtu) rtu->offset[0] = rtu->offset[1] = 0; } -boolean Rtu_HasTexture(rtexmapunit_t const* rtu) +boolean Rtu_HasTexture(rtexmapunit_t const *rtu) { if(rtu->texture.flags & TUF_TEXTURE_IS_MANAGED) - return TextureVariant_GLName(rtu->texture.variant) != 0; + return reinterpret_cast(rtu->texture.variant)->glName() != 0; return rtu->texture.gl.name != 0; } diff --git a/doomsday/engine/src/render/sky.cpp b/doomsday/engine/src/render/sky.cpp index 73ef603ba7..51830330de 100644 --- a/doomsday/engine/src/render/sky.cpp +++ b/doomsday/engine/src/render/sky.cpp @@ -32,9 +32,10 @@ #include +#include "resource/materialsnapshot.h" +#include "resource/materialvariant.h" #include "resource/texture.h" #include "resource/texturevariant.h" -#include "resource/materialvariant.h" #include "render/sky.h" @@ -201,30 +202,26 @@ static void calculateSkyAmbientColor() avgCount = 0; for(i = 0, slayer = &skyLayers[firstSkyLayer]; i < MAX_SKY_LAYERS; ++i, slayer++) { - materialvariantspecification_t const *spec; - materialsnapshot_t const *ms; - if(!(slayer->flags & SLF_ACTIVE) || !slayer->material) continue; - spec = Sky_SphereMaterialSpec(!!(slayer->flags & SLF_MASKED)); - ms = Materials_Prepare(slayer->material, spec, false); + materialvariantspecification_t const *spec = Sky_SphereMaterialSpec(!!(slayer->flags & SLF_MASKED)); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(slayer->material, spec, false)); - if(MSU_texture(ms, MTU_PRIMARY)) + if(ms.hasTexture(MTU_PRIMARY)) { - averagecolor_analysis_t const *avgColor = (averagecolor_analysis_t const *) - Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), TA_COLOR); - if(!avgColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_COLOR analysis").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText())); + de::Texture const &tex = ms.texture(MTU_PRIMARY).generalCase(); + averagecolor_analysis_t const *avgColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_COLOR); + if(!avgColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_COLOR analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); if(i == firstSkyLayer) { - Texture const *tex = MSU_texture(ms, MTU_PRIMARY); - averagecolor_analysis_t const *avgLineColor = (averagecolor_analysis_t const *) Texture_AnalysisDataPointer(tex, TA_LINE_TOP_COLOR); - if(!avgLineColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_TOP_COLOR analysis").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText())); + averagecolor_analysis_t const *avgLineColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_LINE_TOP_COLOR); + if(!avgLineColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_TOP_COLOR analysis").arg(tex.manifest().composeUri())); V3f_Copy(topCapColor.rgb, avgLineColor->color.rgb); - avgLineColor = (averagecolor_analysis_t const *) Texture_AnalysisDataPointer(tex, TA_LINE_BOTTOM_COLOR); - if(!avgLineColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_BOTTOM_COLOR analysis").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText())); + avgLineColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_LINE_BOTTOM_COLOR); + if(!avgLineColor) throw de::Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_BOTTOM_COLOR analysis").arg(tex.manifest().composeUri())); V3f_Copy(bottomCapColor.rgb, avgLineColor->color.rgb); } @@ -801,14 +798,14 @@ static void configureRenderHemisphereStateForLayer(int layer, hemispherecap_t se DENG_ASSERT(mat); materialvariantspecification_t const *spec = Sky_SphereMaterialSpec(Sky_LayerMasked(layer)); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - rs.texSize.width = Texture_Width(MSU_texture(ms, MTU_PRIMARY)); - rs.texSize.height = Texture_Height(MSU_texture(ms, MTU_PRIMARY)); + rs.texSize.width = ms.texture(MTU_PRIMARY).generalCase().width(); + rs.texSize.height = ms.texture(MTU_PRIMARY).generalCase().height(); if(rs.texSize.width && rs.texSize.height) { rs.texOffset = Sky_LayerOffset(layer); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); } else { @@ -820,10 +817,9 @@ static void configureRenderHemisphereStateForLayer(int layer, hemispherecap_t se if(setupCap != HC_NONE) { averagecolor_analysis_t const *avgLineColor = (averagecolor_analysis_t const *) - Texture_AnalysisDataPointer(MSU_texture(ms, MTU_PRIMARY), - (setupCap == HC_TOP? TA_LINE_TOP_COLOR : TA_LINE_BOTTOM_COLOR)); + ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer((setupCap == HC_TOP? TA_LINE_TOP_COLOR : TA_LINE_BOTTOM_COLOR)); float const fadeoutLimit = Sky_LayerFadeoutLimit(layer); - if(!avgLineColor) throw de::Error("configureRenderHemisphereStateForLayer", QString("Texture \"%1\" has no %2 analysis").arg(reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)).manifest().composeUri().asText()).arg(setupCap == HC_TOP? "TA_LINE_TOP_COLOR" : "TA_LINE_BOTTOM_COLOR")); + if(!avgLineColor) throw de::Error("configureRenderHemisphereStateForLayer", QString("Texture \"%1\" has no %2 analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri()).arg(setupCap == HC_TOP? "TA_LINE_TOP_COLOR" : "TA_LINE_BOTTOM_COLOR")); V3f_Copy(rs.capColor.rgb, avgLineColor->color.rgb); // Is the colored fadeout in use? diff --git a/doomsday/engine/src/render/sprite.cpp b/doomsday/engine/src/render/sprite.cpp index dc5b2eb021..39017e22e4 100644 --- a/doomsday/engine/src/render/sprite.cpp +++ b/doomsday/engine/src/render/sprite.cpp @@ -29,9 +29,10 @@ #include "de_misc.h" #include "de_ui.h" +#include "resource/materialsnapshot.h" +#include "resource/materialvariant.h" #include "resource/texture.h" #include "resource/texturevariant.h" -#include "resource/materialvariant.h" #define DOTPROD(a, b) (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]) @@ -287,7 +288,6 @@ static void setupPSpriteParams(rendpspriteparams_t *params, vispsprite_t *spr) float offScaleY = weaponOffsetScaleY / 1000.0f; spritedef_t const *sprDef; spriteframe_t const *sprFrame; - materialsnapshot_t const *ms; materialvariantspecification_t const *spec; boolean flip; @@ -306,18 +306,18 @@ static void setupPSpriteParams(rendpspriteparams_t *params, vispsprite_t *spr) spec = Materials_VariantSpecificationForContext(MC_PSPRITE, 0, 1, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, -2, 0, false, true, true, false); - ms = Materials_Prepare(sprFrame->mats[0], spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(sprFrame->mats[0], spec, true)); - de::Texture const &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); - variantspecification_t const *texSpec = TS_GENERAL(MSU_texturespec(ms, MTU_PRIMARY)); + de::Texture const &tex = ms.texture(MTU_PRIMARY).generalCase(); + variantspecification_t const *texSpec = TS_GENERAL(ms.texture(MTU_PRIMARY).spec()); DENG_ASSERT(spec); params->pos[VX] = psp->pos[VX] - -tex.origin().x() + pspOffset[VX] + -texSpec->border; params->pos[VY] = offScaleY * (psp->pos[VY] - -tex.origin().y()) + pspOffset[VY] + -texSpec->border; - params->width = ms->size.width + texSpec->border*2; - params->height = ms->size.height + texSpec->border*2; + params->width = ms.dimensions().width() + texSpec->border*2; + params->height = ms.dimensions().height() + texSpec->border*2; - TextureVariant_Coords(MST(ms, MTU_PRIMARY), ¶ms->texOffset[0], ¶ms->texOffset[1]); + ms.texture(MTU_PRIMARY).coords(¶ms->texOffset[0], ¶ms->texOffset[1]); params->texFlip[0] = flip; params->texFlip[1] = false; @@ -392,9 +392,9 @@ void Rend_DrawPSprite(rendpspriteparams_t const *params) // For lighting debug, render all solid surfaces using the gray texture. material_t *mat = Materials_ToMaterial(Materials_ResolveUriCString("System:gray")); materialvariantspecification_t const *spec = PSprite_MaterialSpec(); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); glEnable(GL_TEXTURE_2D); } @@ -541,14 +541,14 @@ static void selectTexUnits(int count) void Rend_RenderMaskedWall(rendmaskedwallparams_t const *p) { GLenum normalTarget, dynTarget; - TextureVariant *tex = 0; + de::TextureVariant *tex = 0; boolean withDyn = false; int normal = 0, dyn = 1; if(renderTextures) { - materialsnapshot_t const *ms = Materials_PrepareVariant(p->material); - tex = MST(ms, MTU_PRIMARY); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_PrepareVariant(p->material)); + tex = &ms.texture(MTU_PRIMARY); } // Do we have a dynamic light to blend with? @@ -578,7 +578,7 @@ void Rend_RenderMaskedWall(rendmaskedwallparams_t const *p) // The actual texture. glActiveTexture(IS_MUL ? GL_TEXTURE1 : GL_TEXTURE0); - GL_BindTexture(tex); + GL_BindTexture(reinterpret_cast(tex)); withDyn = true; } @@ -586,7 +586,7 @@ void Rend_RenderMaskedWall(rendmaskedwallparams_t const *p) { GL_ModulateTexture(1); glEnable(GL_TEXTURE_2D); - GL_BindTexture(tex); + GL_BindTexture(reinterpret_cast(tex)); normal = 0; } @@ -896,7 +896,7 @@ void Rend_RenderSprite(rendspriteparams_t const *params) coord_t spriteCenter[3]; coord_t surfaceNormal[3]; MaterialVariant *mat = 0; - materialsnapshot_t const *ms = 0; + de::MaterialSnapshot const *ms = 0; float s = 1, t = 1; ///< Bottom right coords. int i; @@ -906,17 +906,17 @@ void Rend_RenderSprite(rendspriteparams_t const *params) variantspecification_t const *texSpec; // Ensure this variant has been prepared. - ms = Materials_PrepareVariant(params->material); + ms = reinterpret_cast(Materials_PrepareVariant(params->material)); - texSpec = TS_GENERAL(MSU_texturespec(ms, MTU_PRIMARY)); + texSpec = TS_GENERAL(ms->texture(MTU_PRIMARY).spec()); DENG_ASSERT(texSpec); - size.width = ms->size.width + texSpec->border*2; - size.height = ms->size.height + texSpec->border*2; + size.width = ms->dimensions().width() + texSpec->border*2; + size.height = ms->dimensions().height() + texSpec->border*2; viewOffset.x = -size.width/2; - TextureVariant_Coords(MST(ms, MTU_PRIMARY), &s, &t); + ms->texture(MTU_PRIMARY).coords(&s, &t); - de::Texture &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); + de::Texture &tex = ms->texture(MTU_PRIMARY).generalCase(); viewOffset.x += float(-tex.origin().x()); } @@ -924,12 +924,12 @@ void Rend_RenderSprite(rendspriteparams_t const *params) mat = chooseSpriteMaterial(params); if(mat != params->material) { - ms = mat? Materials_PrepareVariant(mat) : NULL; + ms = mat? reinterpret_cast(Materials_PrepareVariant(mat)) : NULL; } if(ms) { - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms->texture(MTU_PRIMARY))); glEnable(GL_TEXTURE_2D); } else diff --git a/doomsday/engine/src/resource/bitmapfont.cpp b/doomsday/engine/src/resource/bitmapfont.cpp index 66fc86d86e..d6cf28d7e0 100644 --- a/doomsday/engine/src/resource/bitmapfont.cpp +++ b/doomsday/engine/src/resource/bitmapfont.cpp @@ -558,7 +558,7 @@ void BitmapCompositeFont_Prepare(font_t *font) de::Texture *tex = App_Textures()->scheme("Patches").findByUniqueId(patch).texture(); ch->tex = GL_PrepareTextureVariant(reinterpret_cast(tex), BitmapCompositeFont_CharSpec()); - if(ch->tex && TextureVariant_Source(ch->tex) == TEXS_ORIGINAL) + if(ch->tex && reinterpret_cast(ch->tex)->source() == TEXS_ORIGINAL) { // Upscale & Sharpen will have been applied. ch->border = 1; @@ -615,7 +615,7 @@ void BitmapCompositeFont_SetDefinition(font_t *font, struct ded_compositefont_s cf->_def = def; } -TextureVariant *BitmapCompositeFont_CharTexture(font_t *font, unsigned char ch) +struct texturevariant_s *BitmapCompositeFont_CharTexture(font_t *font, unsigned char ch) { DENG_ASSERT(font->_type == FT_BITMAPCOMPOSITE); bitmapcompositefont_t *cf = (bitmapcompositefont_t *)font; diff --git a/doomsday/engine/src/resource/material.cpp b/doomsday/engine/src/resource/material.cpp index c979d91500..0c03e59389 100644 --- a/doomsday/engine/src/resource/material.cpp +++ b/doomsday/engine/src/resource/material.cpp @@ -27,6 +27,7 @@ #include "audio/s_environ.h" #include "gl/sys_opengl.h" // TODO: get rid of this +#include "resource/materialsnapshot.h" #include @@ -211,11 +212,11 @@ boolean Material_HasGlow(material_t* mat) if(novideo) return false; /// @todo We should not need to prepare to determine this. - const materialvariantspecification_t* spec = Materials_VariantSpecificationForContext( + materialvariantspecification_t const *spec = Materials_VariantSpecificationForContext( MC_MAPSURFACE, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, -1, -1, -1, true, true, false, false); - const materialsnapshot_t* ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - return (ms->glowing > .0001f); + return (ms.glowStrength() > .0001f); } boolean Material_HasTranslation(const material_t* mat) @@ -276,13 +277,13 @@ void Material_SetEnvironmentClass(material_t* mat, material_env_class_t envClass mat->_envClass = envClass; } -Texture* Material_DetailTexture(material_t* mat) +struct texture_s *Material_DetailTexture(material_t *mat) { DENG2_ASSERT(mat); return mat->_detailTex; } -void Material_SetDetailTexture(material_t* mat, Texture* tex) +void Material_SetDetailTexture(material_t *mat, struct texture_s *tex) { DENG2_ASSERT(mat); mat->_detailTex = tex; @@ -312,13 +313,13 @@ void Material_SetDetailScale(material_t* mat, float scale) mat->_detailScale = MINMAX_OF(0, scale, 1); } -Texture* Material_ShinyTexture(material_t* mat) +struct texture_s *Material_ShinyTexture(material_t *mat) { DENG2_ASSERT(mat); return mat->_shinyTex; } -void Material_SetShinyTexture(material_t* mat, Texture* tex) +void Material_SetShinyTexture(material_t *mat, struct texture_s *tex) { DENG2_ASSERT(mat); mat->_shinyTex = tex; @@ -362,13 +363,13 @@ void Material_SetShinyStrength(material_t* mat, float strength) mat->_shinyStrength = MINMAX_OF(0, strength, 1); } -Texture* Material_ShinyMaskTexture(material_t* mat) +struct texture_s *Material_ShinyMaskTexture(material_t *mat) { DENG2_ASSERT(mat); return mat->_shinyMaskTex; } -void Material_SetShinyMaskTexture(material_t* mat, Texture* tex) +void Material_SetShinyMaskTexture(material_t* mat, struct texture_s *tex) { DENG2_ASSERT(mat); mat->_shinyMaskTex = tex; diff --git a/doomsday/engine/src/resource/materials.cpp b/doomsday/engine/src/resource/materials.cpp index 1d02e22029..f08448645f 100644 --- a/doomsday/engine/src/resource/materials.cpp +++ b/doomsday/engine/src/resource/materials.cpp @@ -31,8 +31,9 @@ #include "de_audio.h" // For texture, environmental audio properties. #include "de_resource.h" -#include "resource/materials.h" #include "gl/sys_opengl.h" // TODO: get rid of this +#include "resource/materials.h" +#include "resource/materialsnapshot.h" #include #include @@ -1127,216 +1128,23 @@ static void updateMaterialTextureLinks(MaterialBind &mb) Material_SetShinyStrength(mat, (refDef? refDef->shininess : 0)); } -static void setTexUnit(materialsnapshot_t* ms, byte unit, TextureVariant* texture, - blendmode_t blendMode, float sScale, float tScale, float sOffset, - float tOffset, float opacity) -{ - rtexmapunit_t* tu; - DENG2_ASSERT(ms && unit < NUM_MATERIAL_TEXTURE_UNITS); - - ms->textures[unit] = texture; - tu = &ms->units[unit]; - tu->texture.variant = texture; - tu->texture.flags = TUF_TEXTURE_IS_MANAGED; - tu->blendMode = blendMode; - V2f_Set(tu->scale, sScale, tScale); - V2f_Set(tu->offset, sOffset, tOffset); - tu->opacity = MINMAX_OF(0, opacity, 1); -} - -void Materials_InitSnapshot(materialsnapshot_t* ms) +void Materials_UpdateTextureLinks(materialid_t materialId) { - DENG2_ASSERT(ms); - -#ifdef __CLIENT__ - for(int i = 0; i < NUM_MATERIAL_TEXTURE_UNITS; ++i) - { - Rtu_Init(&ms->units[i]); - ms->textures[i] = NULL; - } -#else - DENG_UNUSED(ms); -#endif - - ms->material = NULL; - ms->size.width = ms->size.height = 0; - ms->glowing = 0; - ms->isOpaque = true; - V3f_Set(ms->shinyMinColor, 0, 0, 0); + MaterialBind *bind = getMaterialBindForId(materialId); + if(!bind) return; + updateMaterialTextureLinks(*bind); } -/// @return Same as @a snapshot for caller convenience. -materialsnapshot_t const* updateMaterialSnapshot(MaterialVariant* variant, - materialsnapshot_t* snapshot) -{ - static struct materialtextureunit_s { - TextureVariant* tex; - } texUnits[NUM_MATERIAL_TEXTURE_UNITS]; - material_t* mat = MaterialVariant_GeneralCase(variant); - materialvariantspecification_t const* spec = MaterialVariant_Spec(variant); - DENG2_ASSERT(snapshot); - - memset(texUnits, 0, sizeof texUnits); - - // Ensure all resources needed to visualize this Material's layers have been prepared. - int layerCount = Material_LayerCount(mat); - for(int i = 0; i < layerCount; ++i) - { - materialvariant_layer_t const* ml = MaterialVariant_Layer(variant, i); - preparetextureresult_t result; - - if(!ml->texture) continue; - - // Pick the instance matching the specified context. - texUnits[i].tex = GL_PrepareTextureVariant2(ml->texture, spec->primarySpec, &result); - - if(0 == i && (PTR_UPLOADED_ORIGINAL == result || PTR_UPLOADED_EXTERNAL == result)) - { - // Primary texture was (re)prepared. - Material_SetPrepared(mat, result == PTR_UPLOADED_ORIGINAL? 1 : 2); - - if(MaterialBind* bind = getMaterialBindForId(Material_PrimaryBind(mat))) - { - updateMaterialTextureLinks(*bind); - } - - // Are we inheriting the logical dimensions from the texture? - if(0 == Material_Width(mat) && 0 == Material_Height(mat)) - { - Size2Raw texSize(Texture_Width(ml->texture), - Texture_Height(ml->texture)); - Material_SetSize(mat, &texSize); - } - } - } - -#ifdef __CLIENT__ - // Do we need to prepare a DetailTexture? - Texture* tex = Material_DetailTexture(mat); - if(tex) - { - float const contrast = Material_DetailStrength(mat) * detailFactor; - texturevariantspecification_t* texSpec = GL_DetailTextureVariantSpecificationForContext(contrast); - - texUnits[MTU_DETAIL].tex = GL_PrepareTextureVariant(tex, texSpec); - } - - // Do we need to prepare a shiny texture (and possibly a mask)? - tex = Material_ShinyTexture(mat); - if(tex) - { - texturevariantspecification_t* texSpec = - GL_TextureVariantSpecificationForContext(TC_MAPSURFACE_REFLECTION, - TSF_NO_COMPRESSION, 0, 0, 0, GL_REPEAT, GL_REPEAT, 1, 1, -1, - false, false, false, false); - - texUnits[MTU_REFLECTION].tex = GL_PrepareTextureVariant(tex, texSpec); - - // We are only interested in a mask if we have a shiny texture. - if(texUnits[MTU_REFLECTION].tex && (tex = Material_ShinyMaskTexture(mat))) - { - texSpec = GL_TextureVariantSpecificationForContext( - TC_MAPSURFACE_REFLECTIONMASK, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, - -1, -1, -1, true, false, false, false); - texUnits[MTU_REFLECTION_MASK].tex = GL_PrepareTextureVariant(tex, texSpec); - } - } -#endif - - MaterialVariant_SetSnapshotPrepareFrame(variant, frameCount); - - Materials_InitSnapshot(snapshot); - snapshot->material = variant; - memcpy(&snapshot->size, Material_Size(mat), sizeof snapshot->size); - - if(0 == snapshot->size.width && 0 == snapshot->size.height) return snapshot; - - snapshot->glowing = MaterialVariant_Layer(variant, 0)->glow * glowFactor; - snapshot->isOpaque = NULL != texUnits[MTU_PRIMARY].tex && - !TextureVariant_IsMasked(texUnits[MTU_PRIMARY].tex); - - // Setup the primary texture unit. - if(texUnits[MTU_PRIMARY].tex) - { - TextureVariant* tex = texUnits[MTU_PRIMARY].tex; - const float sScale = 1.f / snapshot->size.width; - const float tScale = 1.f / snapshot->size.height; - - setTexUnit(snapshot, MTU_PRIMARY, tex, BM_NORMAL, - sScale, tScale, MaterialVariant_Layer(variant, 0)->texOrigin[0], - MaterialVariant_Layer(variant, 0)->texOrigin[1], 1); - } - -#ifdef __CLIENT__ - /** - * If skymasked, we need only need to update the primary tex unit - * (this is due to it being visible when skymask debug drawing is - * enabled). - */ - if(!Material_IsSkyMasked(mat)) - { - // Setup the detail texture unit? - if(texUnits[MTU_DETAIL].tex && snapshot->isOpaque) - { - TextureVariant* tex = texUnits[MTU_DETAIL].tex; - const float width = Texture_Width(TextureVariant_GeneralCase(tex)); - const float height = Texture_Height(TextureVariant_GeneralCase(tex)); - float scale = Material_DetailScale(mat); - - // Apply the global scaling factor. - if(detailScale > .0001f) - scale *= detailScale; - - setTexUnit(snapshot, MTU_DETAIL, tex, BM_NORMAL, - 1.f / width * scale, 1.f / height * scale, 0, 0, 1); - } - - // Setup the shiny texture units? - if(texUnits[MTU_REFLECTION].tex) - { - TextureVariant* tex = texUnits[MTU_REFLECTION].tex; - const blendmode_t blendmode = Material_ShinyBlendmode(mat); - const float strength = Material_ShinyStrength(mat); - - setTexUnit(snapshot, MTU_REFLECTION, tex, blendmode, 1, 1, 0, 0, strength); - } - - if(texUnits[MTU_REFLECTION_MASK].tex) - { - TextureVariant* tex = texUnits[MTU_REFLECTION_MASK].tex; - - setTexUnit(snapshot, MTU_REFLECTION_MASK, tex, BM_NORMAL, - 1.f / (snapshot->size.width * Texture_Width(TextureVariant_GeneralCase(tex))), - 1.f / (snapshot->size.height * Texture_Height(TextureVariant_GeneralCase(tex))), - snapshot->units[MTU_PRIMARY].offset[0], snapshot->units[MTU_PRIMARY].offset[1], 1); - } - } - - if(MC_MAPSURFACE == spec->context && texUnits[MTU_REFLECTION].tex) - { - const float* minColor = Material_ShinyMinColor(mat); - snapshot->shinyMinColor[CR] = minColor[CR]; - snapshot->shinyMinColor[CG] = minColor[CG]; - snapshot->shinyMinColor[CB] = minColor[CB]; - } -#endif - - return snapshot; -} - -const materialsnapshot_t* Materials_PrepareVariant2(MaterialVariant* variant, boolean updateSnapshot) +materialsnapshot_s const *Materials_PrepareVariant2(MaterialVariant *variant, boolean updateSnapshot) { // Acquire the snapshot we are interested in. - materialsnapshot_t* snapshot = MaterialVariant_Snapshot(variant); + de::MaterialSnapshot *snapshot = reinterpret_cast(MaterialVariant_Snapshot(variant)); if(!snapshot) { // Time to allocate the snapshot. - snapshot = (materialsnapshot_t*)M_Malloc(sizeof *snapshot); - if(!snapshot) - Con_Error("Materials::Prepare: Failed on allocation of %lu bytes for new MaterialSnapshot.", (unsigned long) sizeof *snapshot); - snapshot = MaterialVariant_AttachSnapshot(variant, snapshot); - Materials_InitSnapshot(snapshot); - snapshot->material = variant; + snapshot = new de::MaterialSnapshot(reinterpret_cast(*variant)); + + MaterialVariant_AttachSnapshot(variant, reinterpret_cast(snapshot)); // Update the snapshot right away. updateSnapshot = true; @@ -1347,25 +1155,28 @@ const materialsnapshot_t* Materials_PrepareVariant2(MaterialVariant* variant, bo updateSnapshot = true; } - // If we aren't updating a snapshot; get out of here. - if(!updateSnapshot) return snapshot; + // We have work to do? + if(updateSnapshot) + { + MaterialVariant_SetSnapshotPrepareFrame(variant, frameCount); + snapshot->update(); + } - // We have work to do... - return updateMaterialSnapshot(variant, snapshot); + return reinterpret_cast(snapshot); } -const materialsnapshot_t* Materials_PrepareVariant(MaterialVariant* variant) +const materialsnapshot_s* Materials_PrepareVariant(MaterialVariant* variant) { return Materials_PrepareVariant2(variant, false/*do not force a snapshot update*/); } -const materialsnapshot_t* Materials_Prepare2(material_t* mat, const materialvariantspecification_t* spec, +const materialsnapshot_s* Materials_Prepare2(material_t* mat, const materialvariantspecification_t* spec, boolean smooth, boolean updateSnapshot) { return Materials_PrepareVariant2(Materials_ChooseVariant(mat, spec, smooth, true), updateSnapshot); } -const materialsnapshot_t* Materials_Prepare(material_t* mat, const materialvariantspecification_t* spec, +const materialsnapshot_s* Materials_Prepare(material_t* mat, const materialvariantspecification_t* spec, boolean smooth) { return Materials_Prepare2(mat, spec, smooth, false/*do not force a snapshot update*/); diff --git a/doomsday/engine/src/resource/materialsnapshot.cpp b/doomsday/engine/src/resource/materialsnapshot.cpp new file mode 100644 index 0000000000..ce1bf9c326 --- /dev/null +++ b/doomsday/engine/src/resource/materialsnapshot.cpp @@ -0,0 +1,304 @@ +/** @file materialsnapshot.cpp Material Snapshot. + * + * @author Copyright © 2011-2012 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 + */ + +#include "de_base.h" +#include "de_graphics.h" +#include "de_render.h" + +#include +#include +#include + +#include "resource/material.h" +#include "resource/texture.h" + +#include "resource/materialsnapshot.h" + +namespace de { + +struct MaterialSnapshot::Instance +{ + /// Variant Material used to derive this snapshot. + MaterialVariant *material; + + /// @c true= this material is completely opaque. + bool isOpaque; + + /// Glow strength factor. + float glowStrength; + + /// Dimensions in the world coordinate space. + QSize dimensions; + + /// Minimum ambient light color for reflections. + vec3f_t reflectionMinColor; + + /// Textures used on each texture unit. + TextureVariant *textures[NUM_MATERIAL_TEXTURE_UNITS]; + + /// Texture unit configuration. + rtexmapunit_t units[NUM_MATERIAL_TEXTURE_UNITS]; + + Instance(MaterialVariant &_material) + : material(&_material), isOpaque(true), glowStrength(0), dimensions(0, 0) + { + V3f_Set(reflectionMinColor, 0, 0, 0); + + for(int i = 0; i < NUM_MATERIAL_TEXTURE_UNITS; ++i) + { + Rtu_Init(&units[i]); + textures[i] = NULL; + } + } + + void setupTexUnit(byte unit, TextureVariant *texture, + blendmode_t blendMode, float sScale, float tScale, float sOffset, + float tOffset, float opacity) + { + DENG2_ASSERT(unit < NUM_MATERIAL_TEXTURE_UNITS); + + textures[unit] = texture; + rtexmapunit_t *tu = &units[unit]; + tu->texture.variant = reinterpret_cast(texture); + tu->texture.flags = TUF_TEXTURE_IS_MANAGED; + tu->blendMode = blendMode; + V2f_Set(tu->scale, sScale, tScale); + V2f_Set(tu->offset, sOffset, tOffset); + tu->opacity = MINMAX_OF(0, opacity, 1); + } +}; + +MaterialSnapshot::MaterialSnapshot(MaterialVariant &_material) +{ + d = new Instance(_material); +} + +MaterialSnapshot::~MaterialSnapshot() +{ + delete d; +} + +MaterialVariant &MaterialSnapshot::material() const +{ + return *d->material; +} + +QSize const &MaterialSnapshot::dimensions() const +{ + return d->dimensions; +} + +bool MaterialSnapshot::isOpaque() const +{ + return d->isOpaque; +} + +float MaterialSnapshot::glowStrength() const +{ + return d->glowStrength; +} + +vec3f_t const &MaterialSnapshot::reflectionMinColor() const +{ + return d->reflectionMinColor; +} + +bool MaterialSnapshot::hasTexture(int index) const +{ + if(index < 0 || index >= NUM_MATERIAL_TEXTURE_UNITS) return false; + return d->textures[index] != 0; +} + +TextureVariant &MaterialSnapshot::texture(int index) const +{ + if(!hasTexture(index)) + { + /// @throws InvalidUnitError Attempt to dereference with an invalid index. + throw InvalidUnitError("MaterialSnapshot::texture", QString("Invalid unit index %1").arg(index)); + } + return *d->textures[index]; +} + +rtexmapunit_t const &MaterialSnapshot::unit(int index) const +{ + if(index < 0 || index >= NUM_MATERIAL_TEXTURE_UNITS) + { + /// @throws InvalidUnitError Attempt to obtain a reference to a unit with an invalid index. + throw InvalidUnitError("MaterialSnapshot::unit", QString("Invalid unit index %1").arg(index)); + } + return d->units[index]; +} + +void MaterialSnapshot::update() +{ + TextureVariant *prepTextures[NUM_MATERIAL_TEXTURE_UNITS]; + material_t *mat = d->material->generalCase(); + materialvariantspecification_t const *spec = d->material->spec(); + + std::memset(prepTextures, 0, sizeof prepTextures); + + // Ensure all resources needed to visualize this Material's layers have been prepared. + int layerCount = Material_LayerCount(mat); + for(int i = 0; i < layerCount; ++i) + { + materialvariant_layer_t const *ml = d->material->layer(i); + preparetextureresult_t result; + + if(!ml->texture) continue; + + // Pick the instance matching the specified context. + prepTextures[i] = reinterpret_cast(GL_PrepareTextureVariant2(ml->texture, spec->primarySpec, &result)); + + if(0 == i && (PTR_UPLOADED_ORIGINAL == result || PTR_UPLOADED_EXTERNAL == result)) + { + // Primary texture was (re)prepared. + Material_SetPrepared(mat, result == PTR_UPLOADED_ORIGINAL? 1 : 2); + + materialid_t matId = Material_PrimaryBind(mat); + if(matId != NOMATERIALID) + { + Materials_UpdateTextureLinks(matId); + } + + // Are we inheriting the logical dimensions from the texture? + if(0 == Material_Width(mat) && 0 == Material_Height(mat)) + { + Texture &tex = reinterpret_cast(*ml->texture); + Size2Raw texSize(tex.width(), tex.height()); + Material_SetSize(mat, &texSize); + } + } + } + + // Do we need to prepare a DetailTexture? + texture_s *tex = Material_DetailTexture(mat); + if(tex) + { + float const contrast = Material_DetailStrength(mat) * detailFactor; + texturevariantspecification_t *texSpec = GL_DetailTextureVariantSpecificationForContext(contrast); + + prepTextures[MTU_DETAIL] = reinterpret_cast(GL_PrepareTextureVariant(tex, texSpec)); + } + + // Do we need to prepare a shiny texture (and possibly a mask)? + tex = Material_ShinyTexture(mat); + if(tex) + { + texturevariantspecification_t *texSpec = + GL_TextureVariantSpecificationForContext(TC_MAPSURFACE_REFLECTION, + TSF_NO_COMPRESSION, 0, 0, 0, GL_REPEAT, GL_REPEAT, 1, 1, -1, + false, false, false, false); + + prepTextures[MTU_REFLECTION] = reinterpret_cast(GL_PrepareTextureVariant(tex, texSpec)); + + // We are only interested in a mask if we have a shiny texture. + if(prepTextures[MTU_REFLECTION] && (tex = Material_ShinyMaskTexture(mat))) + { + texSpec = GL_TextureVariantSpecificationForContext( + TC_MAPSURFACE_REFLECTIONMASK, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, + -1, -1, -1, true, false, false, false); + prepTextures[MTU_REFLECTION_MASK] = reinterpret_cast(GL_PrepareTextureVariant(tex, texSpec)); + } + } + + for(int i = 0; i < NUM_MATERIAL_TEXTURE_UNITS; ++i) + { + Rtu_Init(&d->units[i]); + d->textures[i] = NULL; + } + + Size2 const *materialDimensions = Material_Size(d->material->generalCase()); + d->dimensions.setWidth(Size2_Width(materialDimensions)); + d->dimensions.setHeight(Size2_Height(materialDimensions)); + + d->glowStrength = 0; + d->isOpaque = true; + V3f_Set(d->reflectionMinColor, 0, 0, 0); + + if(d->dimensions.isEmpty()) return; + + d->glowStrength = d->material->layer(0)->glow * glowFactor; + d->isOpaque = NULL != prepTextures[MTU_PRIMARY] && !prepTextures[MTU_PRIMARY]->isMasked(); + + // Setup the primary texture unit. + if(prepTextures[MTU_PRIMARY]) + { + TextureVariant *tex = prepTextures[MTU_PRIMARY]; + float const sScale = 1.f / d->dimensions.width(); + float const tScale = 1.f / d->dimensions.height(); + + d->setupTexUnit(MTU_PRIMARY, tex, BM_NORMAL, + sScale, tScale, d->material->layer(0)->texOrigin[0], + d->material->layer(0)->texOrigin[1], 1); + } + + /** + * If skymasked, we need only need to update the primary tex unit + * (this is due to it being visible when skymask debug drawing is + * enabled). + */ + if(!Material_IsSkyMasked(d->material->generalCase())) + { + // Setup the detail texture unit? + if(prepTextures[MTU_DETAIL] && d->isOpaque) + { + TextureVariant *tex = prepTextures[MTU_DETAIL]; + float const width = tex->generalCase().width(); + float const height = tex->generalCase().height(); + float scale = Material_DetailScale(d->material->generalCase()); + + // Apply the global scaling factor. + if(detailScale > .0001f) + scale *= detailScale; + + d->setupTexUnit(MTU_DETAIL, tex, BM_NORMAL, + 1.f / width * scale, 1.f / height * scale, 0, 0, 1); + } + + // Setup the shiny texture units? + if(prepTextures[MTU_REFLECTION]) + { + TextureVariant *tex = prepTextures[MTU_REFLECTION]; + blendmode_t const blendmode = Material_ShinyBlendmode(mat); + float const strength = Material_ShinyStrength(mat); + + d->setupTexUnit(MTU_REFLECTION, tex, blendmode, 1, 1, 0, 0, strength); + } + + if(prepTextures[MTU_REFLECTION_MASK]) + { + TextureVariant *tex = prepTextures[MTU_REFLECTION_MASK]; + + d->setupTexUnit(MTU_REFLECTION_MASK, tex, BM_NORMAL, + 1.f / (d->dimensions.width() * tex->generalCase().width()), + 1.f / (d->dimensions.height() * tex->generalCase().height()), + d->units[MTU_PRIMARY].offset[0], d->units[MTU_PRIMARY].offset[1], 1); + } + } + + if(MC_MAPSURFACE == spec->context && prepTextures[MTU_REFLECTION]) + { + float const *minColor = Material_ShinyMinColor(mat); + d->reflectionMinColor[CR] = minColor[CR]; + d->reflectionMinColor[CG] = minColor[CG]; + d->reflectionMinColor[CB] = minColor[CB]; + } +} + +} // namespace de diff --git a/doomsday/engine/src/resource/materialvariant.cpp b/doomsday/engine/src/resource/materialvariant.cpp index 622f6ba2ef..266f41744f 100644 --- a/doomsday/engine/src/resource/materialvariant.cpp +++ b/doomsday/engine/src/resource/materialvariant.cpp @@ -1,8 +1,6 @@ -/** - * @file materialvariant.cpp - * Logical material variant. @ingroup resource +/** @file materialvariant.cpp Logical Material Variant. * - * @authors Copyright © 2012 Daniel Swanson + * @author Copyright © 2011-2012 Daniel Swanson * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -19,15 +17,18 @@ * 02110-1301 USA */ +#include +#include +#include +#include + #include "de_base.h" #include "de_console.h" #include "de_resource.h" + #include "m_misc.h" +#include "resource/materialsnapshot.h" #include "render/r_main.h" -#include -#include -#include -#include namespace de { @@ -112,11 +113,11 @@ void MaterialVariant::ticker(timespan_t /*time*/) inter = 1.0f - (layer->tics - frameTimePos) / (float) lsDef->tics; } - /* Texture const *glTex; + /* Texture const *tex; de::Uri *texUri = reinterpret_cast(lsDef->texture); - if(texUri && (glTex = Textures::resolveUri(*texUri))) + if(texUri && (tex = Textures::resolveUri(*texUri))) { - layer->tex = Texture_Id(glTex); + layer->tex = tex->id(); setTranslationPoint(inter); } else @@ -161,7 +162,7 @@ materialvariant_layer_t const *MaterialVariant::layer(int layer) return 0; } -materialsnapshot_t &MaterialVariant::attachSnapshot(materialsnapshot_t &newSnapshot) +MaterialSnapshot &MaterialVariant::attachSnapshot(MaterialSnapshot &newSnapshot) { if(snapshot_) { @@ -173,9 +174,9 @@ materialsnapshot_t &MaterialVariant::attachSnapshot(materialsnapshot_t &newSnaps return newSnapshot; } -materialsnapshot_t *MaterialVariant::detachSnapshot() +MaterialSnapshot *MaterialVariant::detachSnapshot() { - materialsnapshot_t *detachedSnapshot = snapshot_; + MaterialSnapshot *detachedSnapshot = snapshot_; snapshot_ = 0; return detachedSnapshot; } @@ -301,24 +302,24 @@ const materialvariant_layer_t* MaterialVariant_Layer(MaterialVariant* mat, int l return self->layer(layer); } -materialsnapshot_t* MaterialVariant_AttachSnapshot(MaterialVariant* mat, materialsnapshot_t* snapshot) +struct materialsnapshot_s *MaterialVariant_AttachSnapshot(MaterialVariant *mat, struct materialsnapshot_s *snapshot) { if(!snapshot) LegacyCore_FatalError("MaterialVariant_AttachSnapshot: Attempted with invalid snapshot argument (=NULL)."); SELF(mat); - return &self->attachSnapshot(*snapshot); + return reinterpret_cast(&self->attachSnapshot(reinterpret_cast(*snapshot))); } -materialsnapshot_t* MaterialVariant_DetachSnapshot(MaterialVariant* mat) +struct materialsnapshot_s *MaterialVariant_DetachSnapshot(MaterialVariant *mat) { SELF(mat); - return self->detachSnapshot(); + return reinterpret_cast(self->detachSnapshot()); } -materialsnapshot_t* MaterialVariant_Snapshot(const MaterialVariant* mat) +struct materialsnapshot_s *MaterialVariant_Snapshot(MaterialVariant const *mat) { SELF_CONST(mat); - return self->snapshot(); + return reinterpret_cast(self->snapshot()); } int MaterialVariant_SnapshotPrepareFrame(const MaterialVariant* mat) diff --git a/doomsday/engine/src/resource/models.cpp b/doomsday/engine/src/resource/models.cpp index 62ad2c324a..5e104fec7c 100644 --- a/doomsday/engine/src/resource/models.cpp +++ b/doomsday/engine/src/resource/models.cpp @@ -43,6 +43,8 @@ #include "def_main.h" #include "m_misc.h" // for M_CycleIntoRange() +#include "resource/materialsnapshot.h" + #include "render/r_things.h" #include "render/rend_model.h" #include "render/sprite.h" @@ -501,12 +503,12 @@ static short defineSkinAndAddToModelIndex(model_t &mdl, Path const &skinPath) { int const newSkin = mdl.info.numSkins; - if(texture_s *tex = R_DefineTexture("ModelSkins", de::Uri(skinPath))) + if(Texture *tex = R_DefineTexture("ModelSkins", de::Uri(skinPath))) { // A duplicate? (return existing skin number) for(int i = 0; i < mdl.info.numSkins; ++i) { - if(mdl.skins[i].texture == tex) return i; + if(mdl.skins[i].texture == reinterpret_cast(tex)) return i; } // Add this new skin. @@ -516,7 +518,7 @@ static short defineSkinAndAddToModelIndex(model_t &mdl, Path const &skinPath) QByteArray pathUtf8 = skinPath.toString().toUtf8(); qstrncpy(mdl.skins[newSkin].name, pathUtf8.constData(), 256); - mdl.skins[newSkin].texture = tex; + mdl.skins[newSkin].texture = reinterpret_cast(tex); } return newSkin; @@ -535,7 +537,7 @@ static void defineAllSkins(model_t &mdl) { de::Uri foundResourceUri(Path(findSkinPath(mdl.skins[i].name, modelFilePath))); - mdl.skins[i].texture = R_DefineTexture("ModelSkins", foundResourceUri); + mdl.skins[i].texture = reinterpret_cast(R_DefineTexture("ModelSkins", foundResourceUri)); // We have found one more skin for this model. numFoundSkins += 1; @@ -924,10 +926,10 @@ static void scaleModelToSprite(modeldef_t &mf, int sprite, int frame) if(!spr.numFrames || spr.spriteFrames == NULL) return; materialvariantspecification_t const* spec = Sprite_MaterialSpec(0, 0); - materialsnapshot_t const* ms = Materials_Prepare(spr.spriteFrames[frame].mats[0], spec, true); - de::Texture const &tex = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); - int off = MAX_OF(0, -tex.origin().y() - ms->size.height); - scaleModel(mf, ms->size.height, off); + MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(spr.spriteFrames[frame].mats[0], spec, true)); + de::Texture const &tex = ms.texture(MTU_PRIMARY).generalCase(); + int off = MAX_OF(0, -tex.origin().y() - ms.dimensions().height()); + scaleModel(mf, ms.dimensions().height(), off); } static float calcModelVisualRadius(modeldef_t* def) @@ -1157,7 +1159,7 @@ static void setupModel(ded_model_t& def) { de::Uri foundResourceUri(Path(findSkinPath(skinFilePath, modelFilePath))); - sub->shinySkin = R_DefineTexture("ModelReflectionSkins", foundResourceUri); + sub->shinySkin = reinterpret_cast(R_DefineTexture("ModelReflectionSkins", foundResourceUri)); } catch(FS1::NotFoundError const &) { diff --git a/doomsday/engine/src/resource/r_data.cpp b/doomsday/engine/src/resource/r_data.cpp index a815dbfe7d..bce6a8a60a 100644 --- a/doomsday/engine/src/resource/r_data.cpp +++ b/doomsday/engine/src/resource/r_data.cpp @@ -843,8 +843,8 @@ void R_InitSpriteTextures() LOG_INFO(String("R_InitSpriteTextures: Done in %1 seconds.").arg(begunAt.since(), 0, 'g', 2)); } -texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, - QSize const &dimensions) +Texture *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, + QSize const &dimensions) { LOG_AS("R_DefineTexture"); @@ -855,7 +855,7 @@ texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, try { de::Texture *tex = scheme.findByResourceUri(resourceUri).texture(); - if(tex) return reinterpret_cast(tex); + if(tex) return tex; } catch(Textures::Scheme::NotFoundError const &) {} // Ignore this error. @@ -874,10 +874,10 @@ texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri, if(!manifest) return 0; // Invalid URI? /// @todo Defer until necessary (manifest texture is first referenced). - return reinterpret_cast( deriveTexture(*manifest) ); + return deriveTexture(*manifest); } -texture_s *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri) +de::Texture *R_DefineTexture(de::String schemeName, de::Uri const &resourceUri) { return R_DefineTexture(schemeName, resourceUri, QSize()); } diff --git a/doomsday/engine/src/resource/texture.cpp b/doomsday/engine/src/resource/texture.cpp index 44aea1603e..acf78eb3be 100644 --- a/doomsday/engine/src/resource/texture.cpp +++ b/doomsday/engine/src/resource/texture.cpp @@ -30,8 +30,6 @@ #include #include -#include -#include namespace de { @@ -227,111 +225,3 @@ Texture::Flags &Texture::flags() } } // namespace de - -/** - * C Wrapper API: - */ - -#define TOINTERNAL(inst) \ - (inst) != 0? reinterpret_cast(inst) : NULL - -#define TOINTERNAL_CONST(inst) \ - (inst) != 0? reinterpret_cast(inst) : NULL - -#define SELF(inst) \ - DENG2_ASSERT(inst); \ - de::Texture *self = TOINTERNAL(inst) - -#define SELF_CONST(inst) \ - DENG2_ASSERT(inst); \ - de::Texture const *self = TOINTERNAL_CONST(inst) - -void *Texture_UserDataPointer(Texture const *tex) -{ - SELF_CONST(tex); - return self->userDataPointer(); -} - -void Texture_SetUserDataPointer(Texture *tex, void *newUserData) -{ - SELF(tex); - self->setUserDataPointer(newUserData); -} - -void Texture_ClearVariants(Texture *tex) -{ - SELF(tex); - self->clearVariants(); -} - -uint Texture_VariantCount(Texture const *tex) -{ - SELF_CONST(tex); - return self->variantCount(); -} - -TextureVariant *Texture_AddVariant(Texture *tex, TextureVariant *variant) -{ - SELF(tex); - if(!variant) - { - LOG_AS("Texture_AddVariant"); - LOG_WARNING("Invalid variant argument, ignoring."); - return variant; - } - self->addVariant(*reinterpret_cast(variant)); - return variant; -} - -void *Texture_AnalysisDataPointer(Texture const *tex, texture_analysisid_t analysisId) -{ - SELF_CONST(tex); - return self->analysisDataPointer(analysisId); -} - -void Texture_SetAnalysisDataPointer(Texture *tex, texture_analysisid_t analysis, void *data) -{ - SELF(tex); - self->setAnalysisDataPointer(analysis, data); -} - -int Texture_Width(Texture const *tex) -{ - SELF_CONST(tex); - return self->width(); -} - -void Texture_SetWidth(Texture *tex, int newWidth) -{ - SELF(tex); - self->setWidth(newWidth); -} - -int Texture_Height(Texture const *tex) -{ - SELF_CONST(tex); - return self->height(); -} - -void Texture_SetHeight(Texture *tex, int newHeight) -{ - SELF(tex); - self->setHeight(newHeight); -} - -int Texture_IterateVariants(Texture *tex, - int (*callback)(TextureVariant *variant, void *parameters), void *parameters) -{ - SELF(tex); - int result = 0; - if(callback) - { - DENG2_FOR_EACH_CONST(de::Texture::Variants, i, self->variantList()) - { - de::TextureVariant *variant = const_cast(*i); - result = callback(reinterpret_cast(variant), parameters); - if(result) break; - } - } - return result; -} diff --git a/doomsday/engine/src/resource/texturevariant.cpp b/doomsday/engine/src/resource/texturevariant.cpp index 0055c2f096..5a2a262231 100644 --- a/doomsday/engine/src/resource/texturevariant.cpp +++ b/doomsday/engine/src/resource/texturevariant.cpp @@ -22,7 +22,6 @@ #include "de_base.h" #include "resource/texture.h" #include "resource/texturevariant.h" -#include namespace de { @@ -75,117 +74,3 @@ void TextureVariant::setGLName(uint newGLName) } } // namespace de - -/** - * C Wrapper API: - */ - -#define TOINTERNAL(inst) \ - (inst) != 0? reinterpret_cast(inst) : NULL - -#define TOINTERNAL_CONST(inst) \ - (inst) != 0? reinterpret_cast(inst) : NULL - -#define SELF(inst) \ - DENG2_ASSERT(inst); \ - de::TextureVariant *self = TOINTERNAL(inst) - -#define SELF_CONST(inst) \ - DENG2_ASSERT(inst); \ - de::TextureVariant const *self = TOINTERNAL_CONST(inst) - -TextureVariant *TextureVariant_New(Texture *generalCase, - texturevariantspecification_t *spec, TexSource source) -{ - if(!generalCase) LegacyCore_FatalError("TextureVariant_New: Attempted with invalid generalCase argument (=NULL)."); - if(!spec) LegacyCore_FatalError("TextureVariant_New: Attempted with invalid spec argument (=NULL)."); - - return reinterpret_cast(new de::TextureVariant(reinterpret_cast(*generalCase), *spec, source)); -} - -void TextureVariant_Delete(TextureVariant *tex) -{ - if(tex) - { - SELF(tex); - delete self; - } -} - -struct texture_s *TextureVariant_GeneralCase(TextureVariant const *tex) -{ - SELF_CONST(tex); - return reinterpret_cast(&self->generalCase()); -} - -TexSource TextureVariant_Source(TextureVariant const *tex) -{ - SELF_CONST(tex); - return self->source(); -} - -void TextureVariant_SetSource(TextureVariant *tex, TexSource source) -{ - SELF(tex); - self->setSource(source); -} - -boolean TextureVariant_IsMasked(TextureVariant const *tex) -{ - SELF_CONST(tex); - return CPP_BOOL(self->isMasked()); -} - -void TextureVariant_FlagMasked(TextureVariant *tex, boolean yes) -{ - SELF(tex); - self->flagMasked(bool(yes)); -} - -boolean TextureVariant_IsUploaded(TextureVariant const *tex) -{ - SELF_CONST(tex); - return CPP_BOOL(self->isUploaded()); -} - -void TextureVariant_FlagUploaded(TextureVariant *tex, boolean yes) -{ - SELF(tex); - self->flagUploaded(bool(yes)); -} - -boolean TextureVariant_IsPrepared(TextureVariant const *tex) -{ - SELF_CONST(tex); - return CPP_BOOL(self->isPrepared()); -} - -void TextureVariant_Coords(TextureVariant const *tex, float *s, float *t) -{ - SELF_CONST(tex); - self->coords(s, t); -} - -void TextureVariant_SetCoords(TextureVariant *tex, float s, float t) -{ - SELF(tex); - self->setCoords(s, t); -} - -texturevariantspecification_t *TextureVariant_Spec(TextureVariant const *tex) -{ - SELF_CONST(tex); - return self->spec(); -} - -uint TextureVariant_GLName(TextureVariant const *tex) -{ - SELF_CONST(tex); - return self->glName(); -} - -void TextureVariant_SetGLName(TextureVariant *tex, uint glName) -{ - SELF(tex); - self->setGLName(glName); -} diff --git a/doomsday/engine/src/ui/ui2_main.cpp b/doomsday/engine/src/ui/ui2_main.cpp index 74f2df13d2..21a47e2d18 100644 --- a/doomsday/engine/src/ui/ui2_main.cpp +++ b/doomsday/engine/src/ui/ui2_main.cpp @@ -32,6 +32,8 @@ #include #include // memcpy, memmove +#include "resource/materialsnapshot.h" + fidata_text_t *P_CreateText(fi_objectid_t id, char const *name, fontid_t fontNum); void P_DestroyText(fidata_text_t *text); @@ -523,9 +525,9 @@ static void drawPageBackground(fi_page_t *p, float x, float y, float width, floa { materialvariantspecification_t const *spec = Materials_VariantSpecificationForContext( MC_UI, 0, 0, 0, 0, GL_REPEAT, GL_REPEAT, 0, 1, 0, false, false, false, false); - materialsnapshot_t const *ms = Materials_Prepare(p->_bg.material, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(p->_bg.material, spec, true)); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); glEnable(GL_TEXTURE_2D); } @@ -1014,22 +1016,22 @@ static void drawPicFrame(fidata_pic_t *p, uint frame, float const _origin[3], { materialvariantspecification_t const *spec = Materials_VariantSpecificationForContext( MC_UI, 0, 0, 0, 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, -3, 0, false, false, false, false); - materialsnapshot_t const *ms = Materials_Prepare(mat, spec, true); + de::MaterialSnapshot const &ms = reinterpret_cast(*Materials_Prepare(mat, spec, true)); - GL_BindTexture(MST(ms, MTU_PRIMARY)); + GL_BindTexture(reinterpret_cast(&ms.texture(MTU_PRIMARY))); glEnable(GL_TEXTURE_2D); textureEnabled = true; - texturevariantspecification_t const *texSpec = MSU_texturespec(ms, MTU_PRIMARY); + texturevariantspecification_t const *texSpec = ms.texture(MTU_PRIMARY).spec(); /// @todo Utilize *all* properties of the Material. V3f_Set(dimensions, - ms->size.width + TS_GENERAL(texSpec)->border*2, - ms->size.height + TS_GENERAL(texSpec)->border*2, 0); + ms.dimensions().width() + TS_GENERAL(texSpec)->border*2, + ms.dimensions().height() + TS_GENERAL(texSpec)->border*2, 0); V2f_Set(rotateCenter, dimensions[VX]/2, dimensions[VY]/2); - TextureVariant_Coords(MST(ms, MTU_PRIMARY), &texScale[VX], &texScale[VY]); + ms.texture(MTU_PRIMARY).coords(&texScale[VX], &texScale[VY]); - de::Texture const &texture = reinterpret_cast(*MSU_texture(ms, MTU_PRIMARY)); + de::Texture const &texture = ms.texture(MTU_PRIMARY).generalCase(); de::Uri uri = texture.manifest().composeUri(); if(!uri.scheme().compareWithoutCase("Sprites")) { @@ -1046,8 +1048,7 @@ static void drawPicFrame(fidata_pic_t *p, uint frame, float const _origin[3], de::Texture *texture = App_Textures()->scheme("Patches").findByUniqueId(f->texRef.patch).texture(); if(texture) { - TextureVariant *tex = GL_PreparePatchTexture(reinterpret_cast(texture)); - GL_BindTexture(tex); + GL_BindTexture(GL_PreparePatchTexture(reinterpret_cast(texture))); glEnable(GL_TEXTURE_2D); textureEnabled = true;