1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Temp commit, some WIP things:

- QuadGrid draft
- Fix minimap_setHealthBarTex accidentally calling MiniMapRender::setAvatarTex
- don't trunkcate to int in entity_rotateTo*() functions
This commit is contained in:
fgenesis 2022-05-06 19:14:47 +02:00
parent c81d880b41
commit ce4ca7f794
7 changed files with 225 additions and 22 deletions

View file

@ -60,6 +60,7 @@ extern "C" {
#include "Spore.h"
#include "Shader.h"
#include "ActionMapper.h"
#include "QuadGrid.h"
#include "MathFunctions.h"
@ -655,6 +656,16 @@ ParticleEffect *getParticle(lua_State *L, int slot = 1)
return q;
}
static inline
QuadGrid *getQuadGrid(lua_State *L, int slot = 1)
{
QuadGrid *q = (QuadGrid*)lua_touserdata(L, slot);
ENSURE_TYPE(q, SCO_QUAD_GRID);
if (!q)
scriptDebug(L, "Invalid QuadGrid");
return q;
}
static bool looksLikeGlobal(const char *s)
{
for( ; *s; ++s)
@ -1002,6 +1013,7 @@ MakeTypeCheckFunc(isBeam, SCO_BEAM)
MakeTypeCheckFunc(isText, SCO_TEXT)
MakeTypeCheckFunc(isShader, SCO_SHADER)
MakeTypeCheckFunc(isParticleEffect, SCO_PARTICLE_EFFECT)
MakeTypeCheckFunc(isQuadGrid, SCO_QUAD_GRID)
#undef MakeTypeCheckFunc
@ -5661,7 +5673,7 @@ luaFunc(entity_rotateToVel)
{
if (!e->vel.isZero())
{
e->rotateToVec(e->vel, lua_tonumber(L, 2), lua_tointeger(L, 3));
e->rotateToVec(e->vel, lua_tonumber(L, 2), lua_tonumber(L, 3));
}
}
luaReturnNil();
@ -5677,7 +5689,7 @@ luaFunc(entity_rotateToEntity)
Vector vec = e2->position - e->position;
if (!vec.isZero())
{
e->rotateToVec(vec, lua_tonumber(L, 3), lua_tointeger(L, 4));
e->rotateToVec(vec, lua_tonumber(L, 3), lua_tonumber(L, 4));
}
}
luaReturnNil();
@ -5691,7 +5703,7 @@ luaFunc(entity_rotateToVec)
{
if (!vec.isZero())
{
e->rotateToVec(vec, lua_tonumber(L, 4), lua_tointeger(L, 5));
e->rotateToVec(vec, lua_tonumber(L, 4), lua_tonumber(L, 5));
}
}
luaReturnNil();
@ -5977,18 +5989,23 @@ luaFunc(entity_isInRect)
luaReturnBool(v);
}
luaFunc(createQuad)
static void setupQuadCommon(lua_State *L, RenderObject *q, int idx)
{
PauseQuad *q = new PauseQuad();
q->setTexture(getString(L, 1));
int layer = lua_tointeger(L, 2);
q->setTexture(getString(L, idx));
int layer = lua_tointeger(L, idx + 1);
if (layer == 13)
layer = 13;
else
layer = (LR_PARTICLES+1) - LR_ELEMENTS1;
dsq->game->addRenderObject(q, LR_ELEMENTS1+(layer-1));
q->moveToFront();
}
luaFunc(createQuad)
{
PauseQuad *q = new PauseQuad();
setupQuadCommon(L, q, 1);
luaReturnPtr(q);
}
@ -9536,6 +9553,50 @@ luaFunc(getPerformanceFreq)
#endif
}
// ----------- Grid Quad -----------------------
luaFunc(createQuadGrid)
{
QuadGrid *q = QuadGrid::New(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
if(q)
setupQuadCommon(L, q, 3);
luaReturnPtr(q);
}
luaFunc(quadgrid_numPoints)
{
QuadGrid *q = getQuadGrid(L);
lua_pushinteger(L, q->pointsX());
lua_pushinteger(L, q->pointsY());
return 2;
}
luaFunc(quadgrid_setPoint)
{
QuadGrid *q = getQuadGrid(L);
size_t ix = luaL_checkinteger(L, 2);
size_t iy = luaL_checkinteger(L, 3);
if(ix < q->pointsX() && iy < q->pointsY())
{
QuadGrid::Point &p = (*q)(ix, iy);
if(!lua_isnoneornil(L, 4))
p.x = lua_tonumber(L, 4);
if(!lua_isnoneornil(L, 5))
p.y = lua_tonumber(L, 5);
if(!lua_isnoneornil(L, 6))
p.u = lua_tonumber(L, 6);
if(!lua_isnoneornil(L, 7))
p.v = lua_tonumber(L, 7);
luaReturnNil();
}
return luaL_error(L, "out of range");
}
q;
// TODO: interp texOffset, setPauseLevel
// ---------- Minimap related ------------------
luaFunc(getMinimapRender)
@ -9561,7 +9622,7 @@ luaFunc(minimap_setAvatarIconTex)
}
luaFunc(minimap_setHealthBarTex)
{
luaReturnBool(MiniMapRender::setAvatarTex(getString(L)));
luaReturnBool(MiniMapRender::setHealthBarTex(getString(L)));
}
luaFunc(minimap_setMaxHealthMarkerTex)
{

View file

@ -61,6 +61,8 @@ set(BBGE_SRCS
Precacher.h
Quad.cpp
Quad.h
QuadGrid.cpp
QuadGrid.h
QuadTrail.cpp
QuadTrail.h
ReadXML.cpp

View file

@ -71,19 +71,6 @@ void Quad::createStrip(bool vert, int num)
resetStrip();
}
void Quad::setStrip(const std::vector<Vector> &st)
{
resetStrip();
for (size_t i = 0; i < st.size(); i++)
{
if (i < strip.size())
{
strip[i].x += st[i].x;
strip[i].y += st[i].y;
}
}
}
void Quad::createGrid(int xd, int yd)
{
deleteGrid();

View file

@ -64,7 +64,6 @@ public:
void refreshRepeatTextureToFill();
bool isRepeatingTextureToFill() const { return repeatingTextureToFill; }
void setGridPoints(bool vert, const std::vector<Vector> &points);
void setStrip(const std::vector<Vector> &strip);
virtual void createStrip(bool stripVert, int num);
float getStripSegmentSize();
void resetStrip();

84
BBGE/QuadGrid.cpp Normal file
View file

@ -0,0 +1,84 @@
#include "QuadGrid.h"
#include "Texture.h"
#include "RenderBase.h"
#include "Core.h"
QuadGrid::QuadGrid(size_t w, size_t h)
: pauseLevel(0), _w(w), _h(h)
{
addType(SCO_QUAD_GRID);
_points.resize((w+1) * (h+1));
}
QuadGrid* QuadGrid::New(size_t w, size_t h)
{
return w && h ? new QuadGrid(w, h) : NULL;
}
QuadGrid::~QuadGrid()
{
}
void QuadGrid::resetUV(float xmul, float ymul)
{
const float incX = 1.0f / float(_w + 1);
const float incY = 1.0f / float(_h + 1);
float u0 = 0, u1 = incX, v0 = 0, v1 = incY;
// go over points, so <= to compare boundaries
for(size_t y = 0; y <= _h; ++y, v0 = v1, v1 += incY)
{
Point *row = &_points[y * _w];
for(size_t x = 0; x <= _w; ++x, u0 = u1, u1 += incX)
{
row[x].u = u0;
row[y].v = v0;
}
}
}
static inline void drawOnePoint(const QuadGrid::Point& p, float ox, float oy)
{
glTexCoord2f(p.u + ox, p.v + oy);
glVertex2f(p.x, p.y);
}
void QuadGrid::onRender()
{
glBindTexture(GL_TEXTURE_2D, texture->textures[0]);
glColor4f(color.x, color.y, color.z, alpha.x * alphaMod);
const float ox = texOffset.x;
const float oy = texOffset.y;
const size_t NX = _w + 1;
// go over grids, so < to compare boundaries
for(size_t y = 0; y < _h; ++y)
{
Point * const row0 = &_points[y * NX];
Point * const row1 = row0 + NX;
for(size_t x = 0; x < _w; ++x)
{
glBegin(GL_QUADS);
drawOnePoint(row0[x], ox, oy);
drawOnePoint(row0[x+1], ox, oy);
drawOnePoint(row1[x+1], ox, oy);
drawOnePoint(row1[x], ox, oy);
glEnd();
}
}
}
void QuadGrid::onUpdate(float dt)
{
if(pauseLevel < core->particlesPaused)
return;
texOffset.update(dt);
RenderObject::onUpdate(dt);
}

69
BBGE/QuadGrid.h Normal file
View file

@ -0,0 +1,69 @@
#ifndef BBGE_QUADGRID_H
#define BBGE_QUADGRID_H
#include <vector>
#include "RenderObject.h"
/*
This class is an extension for Quad, where coordinates and UV coords can be set freely.
Yes, the Quad class also has a grid function that's used for quad strips, segmented animation and so on, but this is different.
TODO:
In *most* cases a full Quad (as it's implemented right now) isn't needed.
A Quad *should* be just a dumb texture with a center point that can be slapped somewhere and scaled/rotated/etc. Like a normal map tile (Element) without any specials applied.
Only some Elements are worthy of being grid Quads -- those with a wavy tile effect applied.
Same goes for bones. Most bones don't have any strip animation so they don't need what a Quad provides.
Strip anim is just a 2xN or Nx2 grid, btw.
A future goal is to eventually rip all strip/xy-grid/segs functionality out of the Quad, make the Quad dumb,
and make this QuadGrid class derive from Quad (or probably PauseQuad) instead of RenderObject.
The Bone and Element classes need to be fixed to accompany for this of course but
*/
class QuadGrid : public RenderObject
{
public:
static QuadGrid *New(size_t w, size_t h);
virtual ~QuadGrid();
struct Point
{
float x, y, u, v;
};
inline Point& operator()(size_t x, size_t y)
{
return _points[y * _w + x];
}
inline const Point& operator()(size_t x, size_t y) const
{
return _points[y * _w + x];
}
virtual void onRender();
virtual void onUpdate(float dt);
void resetUV(float xmul = 1, float ymul = 1);
inline size_t quadsX() const { return _w; }
inline size_t quadsY() const { return _h; }
inline size_t pointsX() const { return _w + 1; }
inline size_t pointsY() const { return _h + 1; }
public:
InterpolatedVector texOffset;
int pauseLevel;
private:
QuadGrid(size_t w, size_t h);
const size_t _w, _h;
std::vector<Point> _points;
};
#endif

View file

@ -42,6 +42,7 @@ enum ScriptObjectType
SCO_PAUSEQUAD = 0x1000,
SCO_SHADER = 0x2000,
SCO_PARTICLE_EFFECT = 0x4000,
SCO_QUAD_GRID = 0x8000,
SCO_FORCE_32BIT = 0xFFFFFFFF
};