From 69ae4bdb2092674375dd88f0887842cf5c5acff8 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 31 May 2023 15:23:21 +0200 Subject: [PATCH] Fix uninitialized glLineWidth() when rendering nodes; use green color for nodes that have a script That would explain why nodes were drawn with thin lines whenever DebugText was on screen... --- Aquaria/Path.cpp | 2 +- Aquaria/Path.h | 2 +- Aquaria/PathRender.cpp | 39 +++++++++++++++++++++++++++------------ BBGE/Rect.h | 12 +++++------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index 50769a1..3193a34 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -222,7 +222,7 @@ Path::~Path() destroy(); } -bool Path::hasScript() +bool Path::hasScript() const { return script != 0; } diff --git a/Aquaria/Path.h b/Aquaria/Path.h index dbf142a..785debf 100644 --- a/Aquaria/Path.h +++ b/Aquaria/Path.h @@ -84,7 +84,7 @@ public: void song(SongType song); void songNote(int note); void songNoteDone(int note, float len); - bool hasScript(); + bool hasScript() const; std::string name; // full node string std::string label; // first part only (the actual node name) std::vectornodes; diff --git a/Aquaria/PathRender.cpp b/Aquaria/PathRender.cpp index 58e5fc2..592e8c8 100644 --- a/Aquaria/PathRender.cpp +++ b/Aquaria/PathRender.cpp @@ -36,28 +36,40 @@ void PathRender::onRender(const RenderState& rs) const if (pathcount == 0) return; + glLineWidth(4); + + const size_t selidx = dsq->game->sceneEditor.selectedIdx; + for (size_t i = 0; i < pathcount; i++) { - Path *p = dsq->game->getPath(i); + const Path *p = dsq->game->getPath(i); - if (dsq->game->sceneEditor.selectedIdx == i) - glColor4f(1, 1, 1, 0.75); + if (selidx == i) + glColor4f(1, 1, 1, 0.75f); + else if(p->hasScript()) + glColor4f(0.5f, 0.8f, 0.5f, 0.75f); else - glColor4f(1, 0.5, 0.5, 0.75); + glColor4f(1, 0.5f, 0.5f, 0.75f); glBegin(GL_LINES); for (size_t n = 0; n < p->nodes.size()-1; n++) { - PathNode *nd = &p->nodes[n]; - PathNode *nd2 = &p->nodes[n+1]; + const PathNode *nd = &p->nodes[n]; + const PathNode *nd2 = &p->nodes[n+1]; glVertex3f(nd->position.x, nd->position.y, 0); glVertex3f(nd2->position.x, nd2->position.y, 0); } glEnd(); + } + + glLineWidth(1); + for (size_t i = 0; i < pathcount; i++) + { + const Path *p = dsq->game->getPath(i); for (size_t n = 0; n < p->nodes.size(); n++) { - PathNode *nd = &p->nodes[n]; + const PathNode *nd = &p->nodes[n]; if (n == 0) { @@ -85,22 +97,25 @@ void PathRender::onRender(const RenderState& rs) const } else { - glColor4f(0.5f, 0.5f, 1, 0.5f); + glColor4f(0.5f, 0.5f, 1, 0.4f); glTranslatef(nd->position.x, nd->position.y, 0); drawCircle(p->rect.getWidth()*0.5f, 16); glTranslatef(-nd->position.x, -nd->position.y, 0); } } + Vector color = p->hasScript() ? Vector(0.5f, 0.8f, 0.5f) : Vector(1, 0.5f, 0.5f); float a = 0.75f; if (!p->active) + { a = 0.3f; + color *= 0.5f; + } - if (dsq->game->sceneEditor.selectedIdx == i) - glColor4f(1, 1, 1, a); - else - glColor4f(1, 0.5, 0.5, a); + if (selidx == i) + color.x = color.y = color.z = 1; + glColor4f(color.x, color.y, color.z, a); glPushMatrix(); glTranslatef(nd->position.x, nd->position.y, 0); drawCircle(32); diff --git a/BBGE/Rect.h b/BBGE/Rect.h index 19d72cc..4ae1d5f 100644 --- a/BBGE/Rect.h +++ b/BBGE/Rect.h @@ -31,8 +31,8 @@ public: { x1 = y1 = x2 = y2 = 0; } - int getWidth() { return x2-x1; } - int getHeight() { return y2-y1; } + int getWidth() const { return x2-x1; } + int getHeight() const { return y2-y1; } void setWidth(int v) { x1 = -v/2; @@ -45,8 +45,6 @@ public: } void setCWH(int x, int y, int w, int h) { - - const int w2 = w / 2; const int h2 = h / 2; x1 = x - w2; @@ -54,18 +52,18 @@ public: x2 = x + w2; y2 = y + h2; } - void getCWH(int *x, int *y, int *w, int *h) + void getCWH(int *x, int *y, int *w, int *h) const { *w = x2 - x1; *h = y2 - y1; *x = x1 + ((*w) / 2); *y = y1 + ((*h) / 2); } - bool isCoordinateInside(const Vector &vec, int radius=0) + bool isCoordinateInside(const Vector &vec, int radius=0) const { return ((vec.x >= x1-radius && vec.x <= x2+radius) && (vec.y >= y1-radius && vec.y <= y2+radius)); } - bool isEmpty() + bool isEmpty() const { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }