From 4690d99d2bec493f809c7065b222eaf18f46df60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Fri, 23 Dec 2016 01:22:15 +0100 Subject: [PATCH] Added an enum for decal type --- Source/Environment/Terrain.cpp | 78 +++++++++++++++++----------------- Source/Environment/Terrain.hpp | 13 +----- Source/Graphic/Decal.cpp | 4 +- Source/Graphic/Decal.hpp | 15 ++++++- 4 files changed, 56 insertions(+), 54 deletions(-) diff --git a/Source/Environment/Terrain.cpp b/Source/Environment/Terrain.cpp index d22ecdf..5d74d54 100644 --- a/Source/Environment/Terrain.cpp +++ b/Source/Environment/Terrain.cpp @@ -1014,44 +1014,46 @@ void Terrain::drawdecals() for (unsigned int i = 0; i < decals.size(); i++) { if (decals[i].type == blooddecalfast && decals[i].alivetime < 2) decals[i].alivetime = 2; - if ((decals[i].type == shadowdecal || decals[i].type == shadowdecalpermanent) && decals[i].type != lasttype) { - shadowtexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (decals[i].type != lasttype) { + if (decals[i].type == shadowdecal || decals[i].type == shadowdecalpermanent) { + shadowtexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } } - } - if (decals[i].type == footprintdecal && decals[i].type != lasttype) { - footprinttexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (decals[i].type == footprintdecal) { + footprinttexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } } - } - if (decals[i].type == bodyprintdecal && decals[i].type != lasttype) { - bodyprinttexture.bind(); - if (!blend) { - blend = 1; - glAlphaFunc(GL_GREATER, 0.0001); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (decals[i].type == bodyprintdecal) { + bodyprinttexture.bind(); + if (!blend) { + blend = 1; + glAlphaFunc(GL_GREATER, 0.0001); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } } - } - if ((decals[i].type == blooddecal || decals[i].type == blooddecalslow) && decals[i].type != lasttype) { - bloodtexture.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.15); - glBlendFunc(GL_ONE, GL_ZERO); + if (decals[i].type == blooddecal || decals[i].type == blooddecalslow) { + bloodtexture.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.15); + glBlendFunc(GL_ONE, GL_ZERO); + } } - } - if ((decals[i].type == blooddecalfast) && decals[i].type != lasttype) { - bloodtexture2.bind(); - if (blend) { - blend = 0; - glAlphaFunc(GL_GREATER, 0.15); - glBlendFunc(GL_ONE, GL_ZERO); + if (decals[i].type == blooddecalfast) { + bloodtexture2.bind(); + if (blend) { + blend = 0; + glAlphaFunc(GL_GREATER, 0.15); + glBlendFunc(GL_ONE, GL_ZERO); + } } } if (decals[i].type == shadowdecal || decals[i].type == shadowdecalpermanent) { @@ -1126,11 +1128,9 @@ void Terrain::drawdecals() void Terrain::deleteDeadDecals() { - for (unsigned int i = 0; i < decals.size(); ) { + for (int i = decals.size() - 1; i >= 0; i--) { if ((decals[i].type == blooddecal || decals[i].type == blooddecalslow) && decals[i].alivetime < 2) { DeleteDecal(i); - } else { - i++; } } } @@ -1176,7 +1176,7 @@ void Terrain::DeleteDecal(int which) } } -void Terrain::MakeDecal(int type, XYZ where, float size, float opacity, float rotation) +void Terrain::MakeDecal(decal_type type, XYZ where, float size, float opacity, float rotation) { if (decalstoggle) { if (opacity > 0 && size > 0) { @@ -1210,7 +1210,7 @@ void Terrain::MakeDecal(int type, XYZ where, float size, float opacity, float ro } } -void Terrain::MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation) +void Terrain::MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation) { if (decalstoggle) { XYZ rot = getLighting(where.x, where.z); diff --git a/Source/Environment/Terrain.hpp b/Source/Environment/Terrain.hpp index 3afaa28..8cf68e1 100644 --- a/Source/Environment/Terrain.hpp +++ b/Source/Environment/Terrain.hpp @@ -40,15 +40,6 @@ along with Lugaru. If not, see . #define max_decals 1000 -#define shadowdecal 0 -#define footprintdecal 1 -#define blooddecal 2 -#define blooddecalfast 3 -#define shadowdecalpermanent 4 -#define breakdecal 5 -#define blooddecalslow 6 -#define bodyprintdecal 7 - #define snowyenvironment 0 #define grassyenvironment 1 #define desertenvironment 2 @@ -98,8 +89,8 @@ public: void AddObject(XYZ where, float radius, int id); void DeleteDecal(int which); - void MakeDecal(int type, XYZ where, float size, float opacity, float rotation); - void MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation); + void MakeDecal(decal_type type, XYZ where, float size, float opacity, float rotation); + void MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation); int lineTerrain(XYZ p1, XYZ p2, XYZ *p); float getHeight(float pointx, float pointz); float getOpacity(float pointx, float pointz); diff --git a/Source/Graphic/Decal.cpp b/Source/Graphic/Decal.cpp index a535dee..de3388f 100644 --- a/Source/Graphic/Decal.cpp +++ b/Source/Graphic/Decal.cpp @@ -24,7 +24,7 @@ along with Lugaru. If not, see . Decal::Decal() : position(), - type(0), + type(shadowdecal), opacity(0), rotation(0), alivetime(0), @@ -32,7 +32,7 @@ Decal::Decal() : { } -Decal::Decal(XYZ _position, int _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) : +Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) : position(_position), type(_type), opacity(_opacity), diff --git a/Source/Graphic/Decal.hpp b/Source/Graphic/Decal.hpp index 34f2a2b..ae3862f 100644 --- a/Source/Graphic/Decal.hpp +++ b/Source/Graphic/Decal.hpp @@ -25,11 +25,22 @@ class Terrain; #include "Math/Quaternions.hpp" +enum decal_type { + shadowdecal = 0, + footprintdecal = 1, + blooddecal = 2, + blooddecalfast = 3, + shadowdecalpermanent = 4, + breakdecal = 5, + blooddecalslow = 6, + bodyprintdecal = 7 +}; + class Decal { public: XYZ position; - int type; + decal_type type; float opacity; float rotation; float alivetime; @@ -39,7 +50,7 @@ public: XYZ vertex[3]; Decal(); - Decal(XYZ position, int type, float opacity, float rotation, float brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first); + Decal(XYZ position, decal_type type, float opacity, float rotation, float brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first); }; #endif -- 2.39.5