1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-04-07 23:27:12 +00:00

deduplicate CurrentRender and SteamRender into QuadSegmentRender

This commit is contained in:
fgenesis 2025-04-01 23:26:02 +02:00
parent ecc03ca14b
commit 7dda47101e
10 changed files with 130 additions and 201 deletions

View file

@ -17,7 +17,6 @@ SET(AQUARIA_SRCS
Continuity.cpp
Continuity.h
Credits.cpp
CurrentRender.cpp
custom-fields.h
Damage.h
DSQ.cpp
@ -64,6 +63,8 @@ SET(AQUARIA_SRCS
PathFinding.cpp
PathFinding.h
PathRender.cpp
QuadSegmentRender.cpp
QuadSegmentRender.h
RecipeMenuEntry.cpp
RecipeMenuEntry.h
SceneEditor.cpp
@ -87,7 +88,6 @@ SET(AQUARIA_SRCS
States.h
StatsAndAchievements.cpp
StatsAndAchievements.h
SteamRender.cpp
StringBank_gen.h
SubtitlePlayer.cpp
SubtitlePlayer.h

View file

@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderBase.h"
#include "GridRender.h"
#include "QuadSegmentRender.h"
#include "WaterSurfaceRender.h"
#include "ScriptedEntity.h"
#include "FlockEntity.h"

View file

@ -478,5 +478,38 @@ enum BounceType
BOUNCE_REAL = 1
};
enum PathType
{
PATH_NONE = 0,
PATH_CURRENT = 1,
PATH_STEAM = 2,
PATH_LI = 3,
PATH_SAVEPOINT = 4,
PATH_WARP = 5,
PATH_SPIRITPORTAL = 6,
PATH_BGSFXLOOP = 7,
PATH_RADARHIDE = 8,
PATH_COOK = 9,
PATH_WATERBUBBLE = 10,
PATH_GEM = 11,
PATH_SETING = 12,
PATH_SETENT = 13,
PATH_ZOOM = 14,
PATH_MAX
};
enum LocalWarpType
{
LOCALWARP_NONE = 0,
LOCALWARP_IN = 1,
LOCALWARP_OUT = 2
};
enum PathShape
{
PATHSHAPE_RECT = 0,
PATHSHAPE_CIRCLE = 1
};
#endif

View file

@ -112,28 +112,6 @@ protected:
std::vector<DrawCallParams> drawcalls;
};
class CurrentRender : public RenderObject
{
public:
CurrentRender();
protected:
float rippleDelay;
void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt) OVERRIDE;
size_t writeVBOData(float *p);
DynamicGPUBuffer vbo;
size_t _verticesToRender;
};
class SteamRender : public RenderObject
{
public:
SteamRender();
protected:
float rippleDelay;
void onRender(const RenderState& rs) const OVERRIDE;
};
struct SongLinePoint
{
Vector color;

View file

@ -387,6 +387,8 @@ void Path::refreshScript()
is >> v;
if (v != 0)
currentMod = v;
amount = 1; // Used to modulate alpha when rendering -> always visible
}
else if (label == "warpnode")
{

View file

@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../BBGE/ScriptObject.h"
#include "Rect.h"
#include "Scriptable.h"
#include "GameEnums.h"
#undef PATH_MAX // May be set by a system header.
@ -40,39 +41,6 @@ public:
int maxSpeed;
};
enum PathType
{
PATH_NONE = 0,
PATH_CURRENT = 1,
PATH_STEAM = 2,
PATH_LI = 3,
PATH_SAVEPOINT = 4,
PATH_WARP = 5,
PATH_SPIRITPORTAL = 6,
PATH_BGSFXLOOP = 7,
PATH_RADARHIDE = 8,
PATH_COOK = 9,
PATH_WATERBUBBLE = 10,
PATH_GEM = 11,
PATH_SETING = 12,
PATH_SETENT = 13,
PATH_ZOOM = 14,
PATH_MAX
};
enum LocalWarpType
{
LOCALWARP_NONE = 0,
LOCALWARP_IN = 1,
LOCALWARP_OUT = 2
};
enum PathShape
{
PATHSHAPE_RECT = 0,
PATHSHAPE_CIRCLE = 1
};
class Path : public ScriptObject, public Scriptable
{
public:

View file

@ -18,26 +18,51 @@ 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "GridRender.h"
#include "QuadSegmentRender.h"
#include "RenderBase.h"
#include "Path.h"
#include "Game.h"
#include "../BBGE/AfterEffect.h"
CurrentRender::CurrentRender()
: RenderObject()
, vbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
: QuadSegmentRender(PATH_CURRENT, true)
{
cull = false;
setTexture("Particles/Current");
repeatTexture = true;
rippleDelay = 2;
_verticesToRender = 0;
setTexture("particles/current");
}
void CurrentRender::onRender(const RenderState& rs) const
CurrentRender::~CurrentRender()
{
}
SteamRender::SteamRender()
: QuadSegmentRender(PATH_STEAM, false)
{
setTexture("particles/steam");
alpha = 0.7f;
setBlendType(BLEND_ADD);
}
SteamRender::~SteamRender()
{
}
QuadSegmentRender::QuadSegmentRender(PathType pt, bool shortenSegs)
: RenderObject()
, vbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
, _verticesToRender(0)
, pathtype(pt)
, _shortenSegs(shortenSegs)
{
cull = false;
repeatTexture = true;
}
QuadSegmentRender::~QuadSegmentRender()
{
}
void QuadSegmentRender::onRender(const RenderState& rs) const
{
if(const size_t N = _verticesToRender)
{
@ -49,14 +74,14 @@ void CurrentRender::onRender(const RenderState& rs) const
}
}
void CurrentRender::onUpdate(float dt)
void QuadSegmentRender::onUpdate(float dt)
{
// Ideally we wouldn't have to update this per-frame.
// With a specialized shader and a uniform texcoordOffset variable the actual vertex data
// could be map-static and this would all be so much simpler...
size_t num = 0;
for (const Path *P = game->getFirstPathOfType(PATH_CURRENT); P; P = P->nextOfType)
for (const Path *P = game->getFirstPathOfType(pathtype); P; P = P->nextOfType)
{
if (!P->active)
continue;
@ -84,17 +109,20 @@ void CurrentRender::onUpdate(float dt)
_verticesToRender = verts;
}
size_t CurrentRender::writeVBOData(float *p)
size_t QuadSegmentRender::writeVBOData(float *p)
{
size_t ret = 0;
const bool shorten = _shortenSegs;
for (const Path *P = game->getFirstPathOfType(PATH_CURRENT); P; P = P->nextOfType)
for (const Path *P = game->getFirstPathOfType(pathtype); P; P = P->nextOfType)
{
if (!P->active)
continue;
const float w = P->rect.getWidth();
const float w2 = w * 0.5f;
const float ao = P->animOffset;
const float a = P->amount * alpha.x;
size_t sz = P->nodes.size()-1;
for (size_t n = 0; n < sz; n++)
@ -104,10 +132,13 @@ size_t CurrentRender::writeVBOData(float *p)
Vector p1 = n1->position;
Vector p2 = n2->position;
Vector diff = p2-p1;
Vector d = diff;
d.setLength2D(w);
p1 -= d*0.75f;
p2 += d*0.75f;
if(shorten)
{
Vector d = diff;
d.setLength2D(w);
p1 -= d*0.75f;
p2 += d*0.75f;
}
diff = p2 - p1;
if (diff.isZero())
@ -131,8 +162,6 @@ size_t CurrentRender::writeVBOData(float *p)
Vector r7 = p2+pl;
Vector r8 = p2+pr;
const float ao = P->animOffset;
const float a = P->amount;
const float len = diff.getLength2D();
const float texScale = len/256.0f;

View file

@ -0,0 +1,39 @@
#ifndef QUADSEGMENTRENDER_H
#define QUADSEGMENTRENDER_H
#include "RenderObject.h"
#include "VertexBuffer.h"
#include "GameEnums.h"
class QuadSegmentRender : public RenderObject
{
public:
QuadSegmentRender(PathType pt, bool shortenSegs);
virtual ~QuadSegmentRender();
protected:
void onRender(const RenderState& rs) const OVERRIDE;
void onUpdate(float dt) OVERRIDE;
size_t writeVBOData(float *p);
DynamicGPUBuffer vbo;
size_t _verticesToRender;
const PathType pathtype;
const bool _shortenSegs;
};
class CurrentRender : public QuadSegmentRender
{
public:
CurrentRender();
virtual ~CurrentRender();
};
class SteamRender : public QuadSegmentRender
{
public:
SteamRender();
virtual ~SteamRender();
};
#endif

View file

@ -1,121 +0,0 @@
/*
Copyright (C) 2007, 2010 - Bit-Blot
This file is part of Aquaria.
Aquaria 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "GridRender.h"
#include "RenderBase.h"
#include "../BBGE/AfterEffect.h"
#include "Game.h"
SteamRender::SteamRender() : RenderObject()
{
cull = false;
alpha = 0.7f;
setTexture("Particles/Steam");
repeatTexture = true;
rippleDelay = 2;
setBlendType(BLEND_ADD);
}
void SteamRender::onRender(const RenderState& rs) const
{
if(!game) return;
for (Path *p = game->getFirstPathOfType(PATH_STEAM); p; p = p->nextOfType)
{
if (p->active)
{
const float w2 = p->rect.getWidth()/2;
if (true)
{
const size_t sz = p->nodes.size()-1;
for (size_t n = 0; n < sz; n++)
{
const PathNode *n1 = &p->nodes[n];
const PathNode *n2 = &p->nodes[n+1];
const Vector p1 = n1->position;
const Vector p2 = n2->position;
Vector diff = p2-p1;
if (!diff.isZero())
{
Vector pl = diff.getPerpendicularLeft();
Vector pr = diff.getPerpendicularRight();
pl.setLength2D(w2);
pr.setLength2D(w2);
if (isTouchingLine(p1, p2, dsq->screenCenter, dsq->cullRadius + p->rect.getWidth()/2.0f))
{
const Vector p15 = n1->position + diff * 0.25f;
const Vector p25 = n2->position - diff * 0.25f;
const Vector r1 = p1+pl;
const Vector r2 = p1+pr;
const Vector r3 = p15+pl;
const Vector r4 = p15+pr;
const Vector r5 = p25+pl;
const Vector r6 = p25+pr;
const Vector r7 = p2+pl;
const Vector r8 = p2+pr;
const float len = diff.getLength2D();
const float texScale = len/256.0f;
glBegin(GL_QUAD_STRIP);
glColor4f(1,1,1,0);
glTexCoord2f((0)*texScale+p->animOffset, 0);
glVertex2f(r1.x, r1.y);
glTexCoord2f((0)*texScale+p->animOffset, 1);
glVertex2f(r2.x, r2.y);
glColor4f(1,1,1,alpha.x);
glTexCoord2f((0+0.25f)*texScale+p->animOffset, 0);
glVertex2f(r3.x, r3.y);
glTexCoord2f((0+0.25f)*texScale+p->animOffset, 1);
glVertex2f(r4.x, r4.y);
glColor4f(1,1,1,alpha.x);
glTexCoord2f((1-0.25f)*texScale+p->animOffset, 0);
glVertex2f(r5.x, r5.y);
glTexCoord2f((1-0.25f)*texScale+p->animOffset, 1);
glVertex2f(r6.x, r6.y);
glColor4f(1,1,1,0);
glTexCoord2f((1)*texScale+p->animOffset, 0);
glVertex2f(r7.x, r7.y);
glTexCoord2f((1)*texScale+p->animOffset, 1);
glVertex2f(r8.x, r8.y);
glEnd();
}
}
}
}
}
}
}

View file

@ -207,7 +207,7 @@ void DynamicGPUBuffer::updatePartial(size_t offset, const void * data, size_t si
if(_h_data)
{
assert(offset + size <= _h_cap);
memcpy((char*)_h_data + offset, data, size);
memcpy((char*)_h_data + offset, data, size);
}
}