Skip to content

Commit

Permalink
Refactor: Added C++ material_t class
Browse files Browse the repository at this point in the history
Note that the class was not named Material to try and minimize the
number of potential conflicts in branch 'revise-texture-animation'.
  • Loading branch information
danij-deng committed Jan 16, 2013
1 parent 1d86d90 commit a2de07a
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 91 deletions.
85 changes: 43 additions & 42 deletions doomsday/engine/api/api_gl.h
Expand Up @@ -25,6 +25,7 @@

#include <de/rect.h>
#include "dd_share.h"
#include "api_map.h" // material_t

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -272,10 +273,10 @@ DENG_API_TYPEDEF(GL)
void (*DeleteLists)(DGLuint list, int range);

void (*SetNoMaterial)(void);
void (*SetMaterialUI)(struct material_s* mat, DGLint wrapS, DGLint wrapT);
void (*SetMaterialUI)(material_t *mat, DGLint wrapS, DGLint wrapT);
void (*SetPatch)(patchid_t id, DGLint wrapS, DGLint wrapT);
void (*SetPSprite)(struct material_s* mat);
void (*SetPSprite2)(struct material_s* mat, int tclass, int tmap);
void (*SetPSprite)(material_t *mat);
void (*SetPSprite2)(material_t *mat, int tclass, int tmap);
void (*SetRawImage)(lumpnum_t lumpNum, DGLint wrapS, DGLint wrapT);

void (*BlendOp)(int op);
Expand Down Expand Up @@ -345,52 +346,52 @@ DENG_API_T(GL);
#ifndef DENG_NO_API_MACROS_GL
#define DGL_Enable _api_GL.Enable
#define DGL_Disable _api_GL.Disable
#define DGL_GetIntegerv _api_GL.GetIntegerv
#define DGL_GetInteger _api_GL.GetInteger
#define DGL_SetInteger _api_GL.SetInteger
#define DGL_GetFloatv _api_GL.GetFloatv
#define DGL_GetFloat _api_GL.GetFloat
#define DGL_SetFloat _api_GL.SetFloat
#define DGL_GetIntegerv _api_GL.GetIntegerv
#define DGL_GetInteger _api_GL.GetInteger
#define DGL_SetInteger _api_GL.SetInteger
#define DGL_GetFloatv _api_GL.GetFloatv
#define DGL_GetFloat _api_GL.GetFloat
#define DGL_SetFloat _api_GL.SetFloat
#define DGL_Ortho _api_GL.Ortho
#define DGL_Scissor _api_GL.Scissor
#define DGL_SetScissor _api_GL.SetScissor
#define DGL_SetScissor2 _api_GL.SetScissor2
#define DGL_MatrixMode _api_GL.MatrixMode
#define DGL_PushMatrix _api_GL.PushMatrix
#define DGL_PopMatrix _api_GL.PopMatrix
#define DGL_LoadIdentity _api_GL.LoadIdentity
#define DGL_Translatef _api_GL.Translatef
#define DGL_SetScissor _api_GL.SetScissor
#define DGL_SetScissor2 _api_GL.SetScissor2
#define DGL_MatrixMode _api_GL.MatrixMode
#define DGL_PushMatrix _api_GL.PushMatrix
#define DGL_PopMatrix _api_GL.PopMatrix
#define DGL_LoadIdentity _api_GL.LoadIdentity
#define DGL_Translatef _api_GL.Translatef
#define DGL_Rotatef _api_GL.Rotatef
#define DGL_Scalef _api_GL.Scalef
#define DGL_Begin _api_GL.Begin
#define DGL_End _api_GL.End
#define DGL_NewList _api_GL.NewList
#define DGL_EndList _api_GL.EndList
#define DGL_CallList _api_GL.CallList
#define DGL_DeleteLists _api_GL.DeleteLists
#define DGL_SetNoMaterial _api_GL.SetNoMaterial
#define DGL_SetMaterialUI _api_GL.SetMaterialUI
#define DGL_SetPatch _api_GL.SetPatch
#define DGL_SetPSprite _api_GL.SetPSprite
#define DGL_SetPSprite2 _api_GL.SetPSprite2
#define DGL_SetRawImage _api_GL.SetRawImage
#define DGL_CallList _api_GL.CallList
#define DGL_DeleteLists _api_GL.DeleteLists
#define DGL_SetNoMaterial _api_GL.SetNoMaterial
#define DGL_SetMaterialUI _api_GL.SetMaterialUI
#define DGL_SetPatch _api_GL.SetPatch
#define DGL_SetPSprite _api_GL.SetPSprite
#define DGL_SetPSprite2 _api_GL.SetPSprite2
#define DGL_SetRawImage _api_GL.SetRawImage
#define DGL_BlendOp _api_GL.BlendOp
#define DGL_BlendFunc _api_GL.BlendFunc
#define DGL_BlendMode _api_GL.BlendMode
#define DGL_Color3ub _api_GL.Color3ub
#define DGL_Color3ubv _api_GL.Color3ubv
#define DGL_Color4ub _api_GL.Color4ub
#define DGL_Color4ubv _api_GL.Color4ubv
#define DGL_BlendFunc _api_GL.BlendFunc
#define DGL_BlendMode _api_GL.BlendMode
#define DGL_Color3ub _api_GL.Color3ub
#define DGL_Color3ubv _api_GL.Color3ubv
#define DGL_Color4ub _api_GL.Color4ub
#define DGL_Color4ubv _api_GL.Color4ubv
#define DGL_Color3f _api_GL.Color3f
#define DGL_Color3fv _api_GL.Color3fv
#define DGL_Color3fv _api_GL.Color3fv
#define DGL_Color4f _api_GL.Color4f
#define DGL_Color4fv _api_GL.Color4fv
#define DGL_TexCoord2f _api_GL.TexCoord2f
#define DGL_TexCoord2fv _api_GL.TexCoord2fv
#define DGL_Vertex2f _api_GL.Vertex2f
#define DGL_Vertex2fv _api_GL.Vertex2fv
#define DGL_Vertex3f _api_GL.Vertex3f
#define DGL_Vertex3fv _api_GL.Vertex3fv
#define DGL_Color4fv _api_GL.Color4fv
#define DGL_TexCoord2f _api_GL.TexCoord2f
#define DGL_TexCoord2fv _api_GL.TexCoord2fv
#define DGL_Vertex2f _api_GL.Vertex2f
#define DGL_Vertex2fv _api_GL.Vertex2fv
#define DGL_Vertex3f _api_GL.Vertex3f
#define DGL_Vertex3fv _api_GL.Vertex3fv
#define DGL_Vertices2ftv _api_GL.Vertices2ftv
#define DGL_Vertices3ftv _api_GL.Vertices3ftv
#define DGL_Vertices3fctv _api_GL.Vertices3fctv
Expand All @@ -401,11 +402,11 @@ DENG_API_T(GL);
#define DGL_DrawRectf2 _api_GL.DrawRectf2
#define DGL_DrawRectf2Color _api_GL.DrawRectf2Color
#define DGL_DrawRectf2Tiled _api_GL.DrawRectf2Tiled
#define DGL_DrawCutRectfTiled _api_GL.DrawCutRectfTiled
#define DGL_DrawCutRectf2Tiled _api_GL.DrawCutRectf2Tiled
#define DGL_DrawCutRectfTiled _api_GL.DrawCutRectfTiled
#define DGL_DrawCutRectf2Tiled _api_GL.DrawCutRectf2Tiled
#define DGL_DrawQuadOutline _api_GL.DrawQuadOutline
#define DGL_DrawQuad2Outline _api_GL.DrawQuad2Outline
#define DGL_NewTextureWithParams _api_GL.NewTextureWithParams
#define DGL_DrawQuad2Outline _api_GL.DrawQuad2Outline
#define DGL_NewTextureWithParams _api_GL.NewTextureWithParams
#define DGL_Bind _api_GL.Bind
#define DGL_DeleteTextures _api_GL.DeleteTextures
#define GL_UseFog _api_GL.UseFog
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/api/api_map.h
Expand Up @@ -130,6 +130,7 @@ struct plane_s;
struct sector_s;
struct sidedef_s;
struct vertex_s;
struct material_s;

typedef struct bspleaf_s BspLeaf;
typedef struct bspnode_s BspNode;
Expand All @@ -139,13 +140,15 @@ typedef struct plane_s Plane;
typedef struct sector_s Sector;
typedef struct sidedef_s SideDef;
typedef struct vertex_s Vertex;
typedef struct material_s material_t;

#elif defined __cplusplus

// Foward declarations.
class BspLeaf;
class LineDef;
class Sector;
class material_t;

#endif

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/api/api_material.h
Expand Up @@ -38,7 +38,7 @@ DENG_API_TYPEDEF(Material)
{
de_api_t api;

struct material_s *(*ForTextureUri)(Uri const *textureUri);
material_t *(*ForTextureUri)(Uri const *textureUri);
Uri *(*ComposeUri)(materialid_t materialId);
materialid_t (*ResolveUri)(const Uri* uri);
materialid_t (*ResolveUriCString)(const char* path);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/api/api_materialarchive.h
Expand Up @@ -59,7 +59,7 @@ DENG_API_TYPEDEF(MaterialArchive)
/**
* @return A new (unused) SerialId for the specified material.
*/
materialarchive_serialid_t (*FindUniqueSerialId)(MaterialArchive const *arc, struct material_s *mat);
materialarchive_serialid_t (*FindUniqueSerialId)(MaterialArchive const *arc, material_t *mat);

/**
* Finds and returns a material with the identifier @a serialId.
Expand All @@ -70,7 +70,7 @@ DENG_API_TYPEDEF(MaterialArchive)
*
* @return Pointer to a material instance. Ownership not given.
*/
struct material_s *(*Find)(MaterialArchive const *arc, materialarchive_serialid_t serialId, int group);
material_t *(*Find)(MaterialArchive const *arc, materialarchive_serialid_t serialId, int group);

/**
* Returns the number of materials in the archive.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/api/dd_share.h
Expand Up @@ -960,7 +960,7 @@ typedef struct {

/// Sprite Info
typedef struct {
struct material_s* material;
material_t *material;
int flip;
RectRaw geometry;
float texCoord[2]; // Prepared texture coordinates.
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/api/dd_types.h
Expand Up @@ -65,8 +65,6 @@ typedef void (*con_textfilter_t) (char* text);
// Forward declarations for map data types.
struct polyblock_s;
struct polyobj_s;
struct surface_s;
struct material_s;

#include <de/str.h>
#include <de/strutil.h>
Expand Down
9 changes: 5 additions & 4 deletions doomsday/engine/include/gl/gl_main.h
Expand Up @@ -30,10 +30,11 @@
#include "render/r_main.h"

struct colorpalette_s;
struct material_s;
struct colorpalette_s;
struct ColorRawf_s;

class material_t;

#define MAX_TEX_UNITS 2 // More aren't currently used.

DENG_EXTERN_C int numTexUnits;
Expand Down Expand Up @@ -173,10 +174,10 @@ void GL_CallList(DGLuint list);

void GL_DeleteLists(DGLuint list, int range);

void GL_SetMaterialUI2(struct material_s *mat, int wrapS, int wrapT);
void GL_SetMaterialUI(struct material_s *mat);
void GL_SetMaterialUI2(material_t *mat, int wrapS, int wrapT);
void GL_SetMaterialUI(material_t *mat);

void GL_SetPSprite(struct material_s *mat, int tclass, int tmap);
void GL_SetPSprite(material_t *mat, int tclass, int tmap);

void GL_SetRawImage(lumpnum_t lumpNum, int wrapS, int wrapT);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/render/sprite.h
Expand Up @@ -32,7 +32,7 @@ typedef struct rendpspriteparams_s
float pos[2]; // {X, Y} Screen-space position.
float width, height;

struct material_s* mat;
material_t *mat;
float texOffset[2];
boolean texFlip[2]; // {X, Y} Flip along the specified axis.

Expand Down
25 changes: 22 additions & 3 deletions doomsday/engine/include/resource/material.h
Expand Up @@ -21,6 +21,11 @@
#ifndef LIBDENG_RESOURCE_MATERIAL_H
#define LIBDENG_RESOURCE_MATERIAL_H

#ifndef __cplusplus
# error "resource/material.h requires C++"
#endif

#include "MapElement"
#include "map/p_mapdata.h"
#include "map/p_dmu.h"

Expand All @@ -38,8 +43,15 @@ typedef enum {

struct material_variantlist_node_s;

typedef struct material_s {
runtime_mapdata_header_t header;
struct material_s; // Opaque type

/**
* Logical material resource.
* @todo Rename as Material
*/
class material_t : public de::MapElement
{
public:
struct ded_material_s* _def;
struct material_variantlist_node_s* _variants;
material_env_class_t _envClass; // Environmental sound class.
Expand All @@ -57,7 +69,14 @@ typedef struct material_s {
float _shinyStrength;
struct texture_s* _shinyMaskTex;
byte _prepared;
} material_t;

material_t();
~material_t();

operator material_s &() {
return (material_s &) *this;
}
};

#ifdef __cplusplus

Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/include/resource/materialarchive.h
Expand Up @@ -30,7 +30,7 @@
#include <de/writer.h>
#include <de/reader.h>

struct material_s;
class material_t;

namespace de {

Expand All @@ -51,7 +51,7 @@ class MaterialArchive
/**
* @return A new (unused) SerialId for the specified material.
*/
materialarchive_serialid_t findUniqueSerialId(struct material_s *mat) const;
materialarchive_serialid_t findUniqueSerialId(material_t *mat) const;

/**
* Finds and returns a material with the identifier @a serialId.
Expand All @@ -61,7 +61,7 @@ class MaterialArchive
*
* @return Pointer to a material instance. Ownership not given.
*/
struct material_s *find(materialarchive_serialid_t serialId, int group) const;
material_t *find(materialarchive_serialid_t serialId, int group) const;

/**
* Returns the number of materials in the archive.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/resource/materials.h
Expand Up @@ -373,7 +373,7 @@ void Materials_Shutdown(void);

void Materials_Ticker(timespan_t elapsed);
uint Materials_Size(void);
materialid_t Materials_Id(material_t *material);
materialid_t Materials_Id(material_t const *material);
material_t *Materials_ToMaterial(materialid_t materialId);
struct uri_s *Materials_ComposeUri(materialid_t materialId);
materialid_t Materials_ResolveUri(struct uri_s const *uri);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/include/resource/materialvariant.h
Expand Up @@ -132,7 +132,7 @@ class MaterialVariant
DENG2_ERROR(InvalidLayerError);

public:
MaterialVariant(struct material_s &generalCase, MaterialVariantSpec const &spec,
MaterialVariant(material_t &generalCase, MaterialVariantSpec const &spec,
ded_material_t const &def);
~MaterialVariant();

Expand All @@ -158,7 +158,7 @@ class MaterialVariant
void resetAnim();

/// @return Material from which this variant is derived.
struct material_s &generalCase() const;
material_t &generalCase() const;

/// @return MaterialVariantSpec from which this variant is derived.
MaterialVariantSpec const &spec() const;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/server/sv_def.h
Expand Up @@ -109,7 +109,7 @@ boolean Sv_CanTrustClientPos(int plrNum);
/**
* Returns a unique id for material @a mat that can be passed on to clients.
*/
unsigned int Sv_IdForMaterial(struct material_s* mat);
unsigned int Sv_IdForMaterial(material_t *mat);

#ifdef __cplusplus
} // extern "C"
Expand Down
10 changes: 6 additions & 4 deletions doomsday/engine/include/ui/dd_ui.h
Expand Up @@ -30,6 +30,8 @@
#include "api_fontrender.h"
#include "api_svg.h"

#include "resource/material.h"

/**
* @defgroup gui GUI
*/
Expand Down Expand Up @@ -141,7 +143,7 @@ typedef struct fi_page_s {
struct fi_page_s *previous;

struct fi_page_background_s {
struct material_s *material;
material_t *material;
animatorvector4_t topColor;
animatorvector4_t bottomColor;
} _bg;
Expand Down Expand Up @@ -172,7 +174,7 @@ struct fi_object_s *FIPage_RemoveObject(fi_page_t *page, struct fi_object_s *obj
boolean FIPage_HasObject(fi_page_t *page, struct fi_object_s *obj);

/// Current background Material.
struct material_s *FIPage_BackgroundMaterial(fi_page_t *page);
material_t *FIPage_BackgroundMaterial(fi_page_t *page);

/// Sets the 'is-visible' state.
void FIPage_MakeVisible(fi_page_t *page, boolean yes);
Expand All @@ -181,7 +183,7 @@ void FIPage_MakeVisible(fi_page_t *page, boolean yes);
void FIPage_Pause(fi_page_t *page, boolean yes);

/// Sets the background Material.
void FIPage_SetBackgroundMaterial(fi_page_t *page, struct material_s *mat);
void FIPage_SetBackgroundMaterial(fi_page_t *page, material_t *mat);

/// Sets the background top color.
void FIPage_SetBackgroundTopColor(fi_page_t *page, float red, float green, float blue, int steps);
Expand Down Expand Up @@ -238,7 +240,7 @@ typedef struct fidata_pic_frame_s {
char flip:1;
} flags;
union {
struct material_s *material;
material_t *material;
patchid_t patch;
lumpnum_t lumpNum;
DGLuint tex;
Expand Down

0 comments on commit a2de07a

Please sign in to comment.