1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-05 05:42:18 +00:00

Misc code cleanups, little SkeletalSprite loading improvement.

- Removed some unused member variables.

- The BBGE_BUILD_WIDESCREEN define is now gone.

- Added an TiXMLDocument cache to prevent parsing the same file
once for each entity on the map with the same skeletal.

- Removed Lua func entity_warpToPathStart, which was essentially a no-op
because Entity::followingPath was always NULL. Removed related code.

- Set texture wrap only when required.

(Some changes taken from https://bitbucket.org/mattbierner/ios-aquaria,
special thanks for changeset 72d6460d9e60)
This commit is contained in:
fgenesis 2012-02-19 04:57:04 +01:00
commit 9b63b400d5
23 changed files with 209 additions and 764 deletions

View file

@ -215,68 +215,28 @@ void AfterEffectManager::capture()
}
void AfterEffectManager::render()
{
//if (!core->frameBuffer.isInited() && numEffects==0) return;
#ifdef BBGE_BUILD_OPENGL
if (active || core->frameBuffer.isInited())
{
glPushMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDisable (GL_ALPHA_TEST);
glDisable(GL_BLEND);
glPushMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDisable (GL_ALPHA_TEST);
glDisable(GL_BLEND);
capture();
glTranslatef(core->cameraPos.x, core->cameraPos.y, 0);
glScalef(core->invGlobalScale, core->invGlobalScale,0);
/*
static float angle=0;
angle += 0.03f;
*/
//glRotatef(angle, 0, 0, 1);
//glColor4f(1,1,1,0.75);
glColor4f(1,1,1,1);
if (core->mode == Core::MODE_2D)
{
renderGrid();
// renderGridPoints();
}
glPopMatrix();
}
else
{
glPushMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDisable (GL_ALPHA_TEST);
glDisable(GL_BLEND);
capture();
glTranslatef(core->cameraPos.x, core->cameraPos.y, 0);
glScalef(core->invGlobalScale, core->invGlobalScale,0);
/*
static float angle;
angle += 0.03f;
*/
//glRotatef(angle, 0, 0, 1);
//glColor4f(1,1,1,0.75);
glColor4f(1,1,1,1);
if (core->mode == Core::MODE_2D)
{
renderGrid();
// renderGridPoints();
}
glPopMatrix();
}
capture();
glTranslatef(core->cameraPos.x, core->cameraPos.y, 0);
glScalef(core->invGlobalScale, core->invGlobalScale,0);
/*
else
{
core->frameBuffer.endCapture();
}
static float angle;
angle += 0.03f;
*/
//glRotatef(angle, 0, 0, 1);
//glColor4f(1,1,1,0.75);
glColor4f(1,1,1,1);
renderGrid();
//renderGridPoints();
glPopMatrix();
#endif
}
@ -360,68 +320,65 @@ void AfterEffectManager::renderGrid()
int offx = -core->getVirtualOffX();
int offy = -core->getVirtualOffY();
if (core->mode == Core::MODE_2D)
//float div = xDivs;
for (int i = 0; i < (xDivs-1); i++)
{
//float div = xDivs;
for (int i = 0; i < (xDivs-1); i++)
{
for (int j = 0; j < (yDivs-1); j++)
{
glBegin(GL_QUADS);
//glColor3f(i/div, i/div, i/div);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(offx + vw*drawGrid[i][j].x, offy + vh*drawGrid[i][j].y);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(offx + vw*drawGrid[i][j+1].x, offy + vh*drawGrid[i][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(offx + vw*drawGrid[i+1][j+1].x, offy + vh*drawGrid[i+1][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(offx + vw*drawGrid[i+1][j].x, offy + vh*drawGrid[i+1][j].y);
glEnd();
}
for (int j = 0; j < (yDivs-1); j++)
{
glBegin(GL_QUADS);
//glColor3f(i/div, i/div, i/div);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(offx + vw*drawGrid[i][j].x, offy + vh*drawGrid[i][j].y);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(offx + vw*drawGrid[i][j+1].x, offy + vh*drawGrid[i][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(offx + vw*drawGrid[i+1][j+1].x, offy + vh*drawGrid[i+1][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(offx + vw*drawGrid[i+1][j].x, offy + vh*drawGrid[i+1][j].y);
glEnd();
}
// uncomment to render grid points
/*
glBindTexture(GL_TEXTURE_2D, 0);
glPointSize(2);
glColor4f(1, 0, 0, 0.5);
for (int i = 0; i < (xDivs-1); i++)
{
for (int j = 0; j < (yDivs-1); j++)
{
glBegin(GL_POINTS);
//glColor3f(i/div, i/div, i/div);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(800*drawGrid[i][j].x, 600*drawGrid[i][j].y);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(800*drawGrid[i][j+1].x, 600*drawGrid[i][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(800*drawGrid[i+1][j+1].x, 600*drawGrid[i+1][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(800*drawGrid[i+1][j].x, 600*drawGrid[i+1][j].y);
glEnd();
}
}
*/
}
// uncomment to render grid points
/*
glBindTexture(GL_TEXTURE_2D, 0);
glPointSize(2);
glColor4f(1, 0, 0, 0.5);
for (int i = 0; i < (xDivs-1); i++)
{
for (int j = 0; j < (yDivs-1); j++)
{
glBegin(GL_POINTS);
//glColor3f(i/div, i/div, i/div);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(800*drawGrid[i][j].x, 600*drawGrid[i][j].y);
glTexCoord2f(i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,i/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(800*drawGrid[i][j+1].x, 600*drawGrid[i][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j+1)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(800*drawGrid[i+1][j+1].x, 600*drawGrid[i+1][j+1].y);
glTexCoord2f((i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB,(i+1)/(float)(xDivs-1)*percentX, 1*percentY-(j)/(float)(yDivs-1)*percentY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(800*drawGrid[i+1][j].x, 600*drawGrid[i+1][j].y);
glEnd();
}
}
*/
//glDisable(GL_TEXTURE_2D);
RenderObject::lastTextureApplied = 0;
glBindTexture(GL_TEXTURE_2D, 0);

View file

@ -8,7 +8,6 @@
#define BBGE_BUILD_SHADERS 1
#define BBGE_BUILD_OPENGL 1
#define BBGE_BUILD_OPENGL_DYNAMIC 1
#define BBGE_BUILD_WIDESCREEN 1
#define BBGE_BUILD_FMOD_OPENAL_BRIDGE 1
#define BBGE_BUILD_ACHIEVEMENTS_INTERNAL 1

View file

@ -102,7 +102,7 @@ public:
sprintf(errbuf, "Exception in ByteBuffer: '%s', rpos: %u, wpos: %u, cursize: %u, sizeparam: %u", \
__e.action, __e.rpos, __e.wpos, __e.cursize, __e.sizeparam); errorLog(errbuf); abort(); }
#else
#define BYTEBUFFER_EXCEPT(bb, desc, sz) throw ByteBufferException(bb, desc, sz)
#define BYTEBUFFER_EXCEPT(bb, desc, sz) throw Exception(bb, desc, sz)
#endif
protected:

View file

@ -135,8 +135,6 @@ void Core::reloadDevice()
void Core::resetGraphics(int w, int h, int fullscreen, int vsync, int bpp)
{
int lastMode = mode;
if (fullscreen == -1)
fullscreen = _fullscreen;
@ -159,19 +157,7 @@ void Core::resetGraphics(int w, int h, int fullscreen, int vsync, int bpp)
initGraphicsLibrary(w, h, fullscreen, vsync, bpp);
switch(lastMode)
{
case MODE_2D:
#ifdef BBGE_BUILD_WIDESCREEN
enable2DWide(w, h);
#else
enable2D(virtualWidth, virtualHeight, true);
#endif
break;
case MODE_3D:
enable3D();
break;
}
enable2DWide(w, h);
reloadResources();
reloadDevice();
@ -1032,7 +1018,6 @@ Core::Core(const std::string &filesystem, int numRenderLayers, const std::string
nestedMains = 0;
afterEffectManager = 0;
loopDone = false;
mode = 0;
core = this;
#ifdef BBGE_BUILD_WINDOWS
@ -1051,12 +1036,6 @@ Core::Core(const std::string &filesystem, int numRenderLayers, const std::string
globalResolutionScale = globalScale = Vector(1,1,1);
lights.resize(8);
for (int i = 0; i < lights.size(); i++)
{
lights[i].num = i;
}
initRenderObjectLayers(numRenderLayers);
initPlatform(filesystem);
@ -1805,14 +1784,6 @@ void Core::onUpdate(float dt)
afterEffectManager->update(dt);
}
for (int i = 0; i < lights.size(); i++)
{
if (lights[i].enabled)
{
lights[i].update(dt);
}
}
if (!sortFlag)
{
if (sortTimer>0)
@ -1906,13 +1877,11 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync
{
static bool didOnce = false;
//#ifdef BBGE_BUILD_WIDESCREEN
aspectX = width;
aspectY = height;
aspect = (aspectX/aspectY);
//#endif
this->width = width;
@ -2135,7 +2104,6 @@ void Core::shutdownGraphicsLibrary(bool killVideo)
#endif
_hasFocus = false;
mode = MODE_NONE;
lib_graphics = false;
@ -2341,70 +2309,6 @@ bbgePerspective(float fovy, float aspect, float zNear, float zFar)
glMultMatrixf(&m[0][0]);
}
// don't want to support resizing
void Core::resize3D()
{
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
bbgePerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
/*
//width/height = aspect;
if (aspect)
{
width = int(float(height)*aspect);
}
this->width = width;
this->height = height;
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
#ifdef BBGE_BUILD_OPENGL
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
#ifdef BBGE_BUILD_GLFW
if (mode == MODE_3D)
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
#endif
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
if (this->mode == Core::MODE_2D)
enable2D();
onResetScene();
//if (!fullscreen)
//{
//DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
//DWORD dwStyle=WS_OVERLAPPEDWINDOW;
//RECT r = {0,0,width,height};
//AdjustWindowRectEx(&r,dwStyle,false,dwExStyle);
//}
#endif
*/
}
void Core::setPixelScale(int pixelScaleX, int pixelScaleY)
{
/*
@ -2462,13 +2366,6 @@ void Core::enable2DWide(int rx, int ry)
//vh = MAX(vh, baseVirtualHeight);
core->enable2D(baseVirtualWidth, vh, 1);
}
//else
//{
// int vh = int(float(baseVirtualWidth) * (float(ry)/float(rx)));
// vh = MAX(vh, baseVirtualHeight);
// core->enable2D(baseVirtualWidth, vh, 1);
//}
}
static void bbgeOrtho2D(float left, float right, float bottom, float top)
@ -2498,8 +2395,6 @@ void Core::enable2D(int pixelScaleX, int pixelScaleY, bool forcePixelScale)
return;
}
*/
mode = MODE_2D;
#ifdef BBGE_BUILD_OPENGL
@ -2510,15 +2405,6 @@ void Core::enable2D(int pixelScaleX, int pixelScaleY, bool forcePixelScale)
//glPushMatrix();
glLoadIdentity();
//#ifdef BBGE_BUILD_WIDESCREEN
//int offx=0,offy=0;
// hackish
//float vw = float((viewPort[2] * baseVirtualHeight)) / float(viewPort[3]);
//float vw = float(aspectX * viewPort[3]) / float(aspectY);
//- baseVirtualWidth;
//offx = float(vw)*0.1f;
float vw=0,vh=0;
viewOffX = viewOffY = 0;
@ -2704,47 +2590,6 @@ void Core::enable2D(int pixelScaleX, int pixelScaleY, bool forcePixelScale)
}
void Core::enable3D()
{
if (mode == MODE_3D) return;
else if (mode == MODE_2D)
{
/*
#ifdef BBGE_BUILD_OPENGL
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
#endif
*/
}
mode = MODE_3D;
glClearDepth(1.0); // Depth Buffer Setup
glLoadIdentity();
resize3D();
/*
int viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//glOrtho(0.0f,viewPort[2],viewPort[3],0.0f,-1000.0f,1000.0f);
glOrtho(0.0f,viewPort[2],viewPort[3],0.0f,-1.0f,1.0f);
//glOrtho(0, viewPort[2], 0, viewPort[3], -100, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
*/
}
void Core::quitNestedMain()
{
if (getNestedMains() > 1)
@ -3963,16 +3808,6 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
}
setupRenderPositionAndScale();
bool e = false;
for (int i = 0; i < lights.size(); i++)
{
lights[i].apply();
if (lights[i].enabled) e = true;
}
if (e)
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
#endif
#ifdef BBGE_BUILD_DIRECTX
@ -4050,20 +3885,6 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail)
RenderObject::rlayer = r;
if (r->visible)
{
if (r->mode != mode)
{
switch(r->mode)
{
case MODE_2D:
enable2DWide(width, height);
glLoadIdentity();
setupRenderPositionAndScale();
break;
case MODE_3D:
enable3D();
break;
}
}
if (r->startPass == r->endPass)
{
r->renderPass(RenderObject::RENDER_ALL);

View file

@ -983,7 +983,6 @@ public:
//bool createGlWindow(char* title, int width, int height, int bits, bool fullscreenflag);
bool createWindow(int width, int height, int bits, bool fullscreen, std::string windowTitle="");
//void setWindowTitle(const std::string &title); // func not yet written
void resize3D();
void clearBuffers();
void render(int startLayer=-1, int endLayer=-1, bool useFrameBufferIfAvail=true);
void showBuffer();
@ -1023,7 +1022,6 @@ public:
void toggleScreenMode(int t=0);
void enable2D(int pixelScaleX=0, int pixelScaleY=0, bool forcePixelScale=false);
void enable3D();
void addRenderObject(RenderObject *o, int layer=0);
void switchRenderObjectLayer(RenderObject *o, int toLayer);
void addResource(Resource *r);
@ -1123,8 +1121,6 @@ public:
int width, height;
int mode;
enum Modes { MODE_NONE=-1, MODE_3D=0, MODE_2D };
InterpolatedVector globalScale;
@ -1140,9 +1136,6 @@ public:
int fps;
bool loopDone;
std::vector<Light> lights;
Mouse mouse;
AfterEffectManager *afterEffectManager;

View file

@ -23,30 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <assert.h>
std::vector<QuadLight> QuadLight::quadLights;
bool Quad::flipTY = true;
int Quad::_w2 = 0;
int Quad::_h2 = 0;
QuadLight::QuadLight(Vector position, Vector color, int dist)
{
this->dist = dist;
this->color = color;
this->position = position;
}
void QuadLight::clearQuadLights()
{
quadLights.clear();
}
void QuadLight::addQuadLight(const QuadLight &quadLight)
{
quadLights.push_back(quadLight);
}
Vector Quad::renderBorderColor = Vector(1,1,1);
Quad::Quad(const std::string &tex, const Vector &pos)
@ -267,13 +243,9 @@ void Quad::initQuad()
//debugLog("Quad::initQuad()");
repeatingTextureToFill = false;
_w2 = _h2 = 0;
drawGrid = 0;
lightingColor = Vector(1,1,1);
quadLighting = false;
renderBorder = false;
renderCenter = true;
width = 2; height = 2;
@ -439,108 +411,80 @@ void Quad::renderGrid()
const float blue = this->color.z;
const float alpha = this->alpha.x * this->alphaMod;
if (core->mode == Core::MODE_2D)
/*
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
*/
glBegin(GL_QUADS);
float u0 = baseX;
float u1 = u0 + incX;
for (int i = 0; i < (xDivs-1); i++, u0 = u1, u1 += incX)
{
/*
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
*/
glBegin(GL_QUADS);
float u0 = baseX;
float u1 = u0 + incX;
for (int i = 0; i < (xDivs-1); i++, u0 = u1, u1 += incX)
float v0 = 1 - percentY + baseY;
float v1 = v0 + incY;
for (int j = 0; j < (yDivs-1); j++, v0 = v1, v1 += incY)
{
float v0 = 1 - percentY + baseY;
float v1 = v0 + incY;
for (int j = 0; j < (yDivs-1); j++, v0 = v1, v1 += incY)
if (drawGrid[i][j].z != 0 || drawGrid[i][j+1].z != 0 || drawGrid[i+1][j].z != 0 || drawGrid[i+1][j+1].z != 0)
{
if (drawGrid[i][j].z != 0 || drawGrid[i][j+1].z != 0 || drawGrid[i+1][j].z != 0 || drawGrid[i+1][j+1].z != 0)
{
glColor4f(red, green, blue, alpha*drawGrid[i][j].z);
glTexCoord2f(u0, v0);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v0-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glColor4f(red, green, blue, alpha*drawGrid[i][j].z);
glTexCoord2f(u0, v0);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v0-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
glVertex2f(w*drawGrid[i][j].x, h*drawGrid[i][j].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i][j+1].z);
glTexCoord2f(u0, v1);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v1-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(w*drawGrid[i][j+1].x, h*drawGrid[i][j+1].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i+1][j+1].z);
glTexCoord2f(u1, v1);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v1-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(w*drawGrid[i+1][j+1].x, h*drawGrid[i+1][j+1].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i+1][j].z);
glTexCoord2f(u1, v0);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v0-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(w*drawGrid[i+1][j].x, h*drawGrid[i+1][j].y);
}
}
}
glEnd();
// debug points
if (RenderObject::renderCollisionShape)
{
glBindTexture(GL_TEXTURE_2D, 0);
glPointSize(2);
glColor3f(1,0,0);
glBegin(GL_POINTS);
for (int i = 0; i < (xDivs-1); i++)
{
for (int j = 0; j < (yDivs-1); j++)
{
glVertex2f(w*drawGrid[i][j].x, h*drawGrid[i][j].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i][j+1].z);
glTexCoord2f(u0, v1);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v1-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(w*drawGrid[i][j+1].x, h*drawGrid[i][j+1].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i+1][j+1].z);
glTexCoord2f(u1, v1);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v1-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
glVertex2f(w*drawGrid[i+1][j+1].x, h*drawGrid[i+1][j+1].y);
//
glColor4f(red, green, blue, alpha*drawGrid[i+1][j].z);
glTexCoord2f(u1, v0);
//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v0-baseY);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
glVertex2f(w*drawGrid[i+1][j].x, h*drawGrid[i+1][j].y);
}
}
}
glEnd();
// debug points
if (RenderObject::renderCollisionShape)
{
glBindTexture(GL_TEXTURE_2D, 0);
glPointSize(2);
glColor3f(1,0,0);
glBegin(GL_POINTS);
for (int i = 0; i < (xDivs-1); i++)
{
for (int j = 0; j < (yDivs-1); j++)
{
glVertex2f(w*drawGrid[i][j].x, h*drawGrid[i][j].y);
glVertex2f(w*drawGrid[i][j+1].x, h*drawGrid[i][j+1].y);
glVertex2f(w*drawGrid[i+1][j+1].x, h*drawGrid[i+1][j+1].y);
glVertex2f(w*drawGrid[i+1][j].x, h*drawGrid[i+1][j].y);
}
}
glEnd();
if (texture)
glBindTexture(GL_TEXTURE_2D, texture->textures[0]);
}
if (texture)
glBindTexture(GL_TEXTURE_2D, texture->textures[0]);
}
#endif
}
Vector oldQuadColor;
void Quad::render()
{
if (lightingColor.x != 1.0f || lightingColor.y != 1.0f || lightingColor.z != 1.0f)
{
oldQuadColor = color;
color *= lightingColor;
RenderObject::render();
color = oldQuadColor;
}
else
{
RenderObject::render();
}
}
void Quad::repeatTextureToFill(bool on)
{
if (on)
{
repeatingTextureToFill = true;
repeatTexture = true;
refreshRepeatTextureToFill();
}
else
{
repeatingTextureToFill = false;
repeatTexture = false;
refreshRepeatTextureToFill();
}
repeatingTextureToFill = on;
repeatTexture = on;
refreshRepeatTextureToFill();
}
void Quad::onRender()
@ -549,8 +493,8 @@ void Quad::onRender()
#ifdef BBGE_BUILD_OPENGL
_w2 = width/2;
_h2 = height/2;
float _w2 = width/2.0f;
float _h2 = height/2.0f;
if (!strip.empty())
{
@ -563,23 +507,8 @@ void Quad::onRender()
if (!stripVert)
{
Vector pl, pr;
for (int i = 0; i < strip.size(); i++)
{
//glNormal3f( 0.0f, 0.0f, 1.0f);
if (i == strip.size()-1)
{
}
else //if (i == 0)
{
Vector diffVec = strip[i+1] - strip[i];
diffVec.setLength2D(_h2);
pl = diffVec.getPerpendicularLeft();
pr = diffVec.getPerpendicularRight();
}
glTexCoord2f(texBits*i, 0);
glVertex2f(strip[i].x*width-_w2, strip[i].y*_h2*10 - _h2);
glTexCoord2f(texBits*i, 1);
@ -602,51 +531,27 @@ void Quad::onRender()
}
else
{
if (core->mode == Core::MODE_2D)
if (!drawGrid)
{
if (!drawGrid)
glBegin(GL_QUADS);
{
if (Quad::flipTY)
{
glBegin(GL_QUADS);
{
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(-_w2, +_h2);
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(-_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(+_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
glVertex2f(+_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(+_w2, -_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(+_w2, -_h2);
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(-_w2, -_h2);
}
glEnd();
}
else
{
glBegin(GL_QUADS);
{
glTexCoord2f(upperLeftTextureCoordinates.x, upperLeftTextureCoordinates.y);
glVertex2f(-_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, upperLeftTextureCoordinates.y);
glVertex2f(+_w2, +_h2);
glTexCoord2f(lowerRightTextureCoordinates.x, lowerRightTextureCoordinates.y);
glVertex2f(+_w2, -_h2);
glTexCoord2f(upperLeftTextureCoordinates.x, lowerRightTextureCoordinates.y);
glVertex2f(-_w2, -_h2);
}
glEnd();
}
}
else
{
renderGrid();
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
glVertex2f(-_w2, -_h2);
}
glEnd();
}
else
{
renderGrid();
}
}
@ -820,24 +725,6 @@ void Quad::flipVertical()
RenderObject::flipVertical();
}
void Quad::calculateQuadLighting()
{
Vector total;
int c=0;
for (int i = 0; i < QuadLight::quadLights.size(); i++)
{
QuadLight *q = &QuadLight::quadLights[i];
Vector dist = q->position - position;
if (dist.isLength2DIn(q->dist))
{
total += q->color;
c++;
}
}
if (c > 0)
lightingColor = total/c;
}
void Quad::refreshRepeatTextureToFill()
{
if (repeatingTextureToFill)
@ -883,11 +770,6 @@ void Quad::onUpdate(float dt)
{
updateGrid(dt);
}
if (quadLighting)
{
calculateQuadLighting();
}
}
void Quad::setWidthHeight(float w, float h)
@ -915,8 +797,6 @@ void Quad::onSetTexture()
{
width = this->texture->width;
height = this->texture->height;
_w2 = this->texture->width/2.0f;
_h2 = this->texture->height/2.0f;
}
}

View file

@ -23,19 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "RenderObject.h"
class QuadLight
{
public:
QuadLight(Vector position, Vector color, int dist);
Vector position, color;
int dist;
static std::vector<QuadLight> quadLights;
static void addQuadLight(const QuadLight &quadLight);
static void clearQuadLights();
};
class OutlineRect : public RenderObject
{
public:
@ -78,7 +65,6 @@ public:
void setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo);
void setDrawGridAlpha(int x, int y, float alpha);
void calculateQuadLighting();
void render();
void repeatTextureToFill(bool on);
void refreshRepeatTextureToFill();
bool isRepeatingTextureToFill() const { return repeatingTextureToFill; }
@ -88,8 +74,6 @@ public:
float getStripSegmentSize();
void resetStrip();
Vector ** getDrawGrid() { return drawGrid; }
static bool flipTY;
void reloadDevice();
@ -110,7 +94,6 @@ public:
char autoWidth, autoHeight; // char to save space
bool quadLighting;
bool renderQuad, renderBorder, renderCenter;
bool stripVert;
std::vector<Vector>strip;
@ -121,7 +104,6 @@ public:
protected:
bool repeatingTextureToFill;
Vector lightingColor;
float gridTimer;
int xDivs, yDivs;
Vector ** drawGrid;
@ -138,7 +120,6 @@ protected:
float drawGridTimeMultiplier;
bool drawGridOut;
static int _w2, _h2;
static Vector renderBorderColor;
void onSetTexture();

View file

@ -168,7 +168,6 @@ RenderObject::RenderObject()
alphaMod = 1;
collisionMaskRadius = 0;
collideRadius = 0;
useCollisionMask = false;
motionBlurTransition = false;
motionBlurFrameOffsetCounter = 0;
motionBlurFrameOffset = 0;
@ -634,12 +633,6 @@ void RenderObject::renderCall()
glRotatef(180, 0, 1, 0);
}
if (core->mode == Core::MODE_3D)
{
glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
#endif
#ifdef BBGE_BUILD_DIRECTX
@ -665,11 +658,6 @@ void RenderObject::renderCall()
glDisable(GL_CULL_FACE);
glRotatef(180, 0, 1, 0);
}
if (core->mode == Core::MODE_3D)
{
glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
#endif
#ifdef BBGE_BUILD_DIRECTX
@ -723,12 +711,6 @@ void RenderObject::renderCall()
#endif
#ifdef BBGE_BUILD_OPENGL
if (core->mode == Core::MODE_3D)
{
glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
}
glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
if (isfh())
{
@ -753,10 +735,7 @@ void RenderObject::renderCall()
#ifdef BBGE_BUILD_OPENGL
glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, beforeScaleOffset.z);
if (core->mode == Core::MODE_3D)
glScalef(scale.x, scale.y, scale.z);
else
glScalef(scale.x, scale.y, 1);
glScalef(scale.x, scale.y, 1);
glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z);
#endif
#ifdef BBGE_BUILD_DIRECTX

View file

@ -189,9 +189,6 @@ public:
const RenderObject &operator=(const RenderObject &r);
void enableProjectCollision();
void disableProjectCollision();
void toggleCull(bool value);
void safeKill();
@ -293,8 +290,6 @@ public:
int collideRadius;
Vector collidePosition;
bool useCollisionMask;
//Vector collisionMaskHalfVector;
std::vector<Vector> collisionMask;
std::vector<Vector> transformedCollisionMask;

View file

@ -30,6 +30,21 @@ std::string SkeletalSprite::skinPath = "skins/";
std::string SkeletalSprite::secondaryAnimationPath = "";
static std::map<std::string, TiXmlDocument> skelCache;
static TiXmlDocument& _retrieveSkeletalXML(const std::string& name)
{
TiXmlDocument& doc = skelCache[name];
if (!doc.RootElement())
doc.LoadFile(name);
return doc;
}
void SkeletalSprite::clearCache()
{
skelCache.clear();
}
void SkeletalKeyframe::copyAllButTime(SkeletalKeyframe *copy)
{
@ -842,7 +857,8 @@ void SkeletalSprite::saveSkeletal(const std::string &fn)
file = animationPath + filename + ".xml";
int i = 0;
TiXmlDocument xml;
TiXmlDocument& xml = _retrieveSkeletalXML(file);
xml.Clear();
TiXmlElement animationLayers("AnimationLayers");
for (i = 0; i < animLayers.size(); i++)
@ -1141,8 +1157,6 @@ Animation *SkeletalSprite::getAnimation(std::string anim)
void SkeletalSprite::loadSkin(const std::string &fn)
{
TiXmlDocument d;
std::string file;
if (!secondaryAnimationPath.empty())
@ -1162,7 +1176,7 @@ void SkeletalSprite::loadSkin(const std::string &fn)
errorLog("Could not load skin[" + file + "]");
return;
}
d.LoadFile(file);
TiXmlDocument& d = _retrieveSkeletalXML(file);
TiXmlElement *bonesXml = d.FirstChildElement("Bones");
if (bonesXml)
@ -1294,7 +1308,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
loaded = true;
TiXmlDocument xml;
TiXmlDocument& xml = _retrieveSkeletalXML(file);
xml.LoadFile(file.c_str());
TiXmlElement *bones = xml.FirstChildElement("Bones");

View file

@ -259,6 +259,7 @@ public:
std::string filenameLoaded;
static std::string animationPath, skinPath, secondaryAnimationPath;
static void clearCache();
protected:
bool frozen;

View file

@ -58,7 +58,6 @@ TexErr Texture::textureError = TEXERR_OK;
Texture::Texture() : Resource()
{
components = 0;
#ifdef BBGE_BUILD_OPENGL
textures[0] = 0;
#endif
@ -68,6 +67,7 @@ Texture::Texture() : Resource()
width = height = 0;
repeat = false;
repeating = false;
pngSetStandardOrientation(0);
imageData = 0;
@ -291,20 +291,14 @@ void Texture::reload()
Resource::reload();
debugLog("RELOADING TEXTURE: " + name + " with loadName " + loadName + "...");
if (true)
{
unload();
load(loadName);
if (ow != -1 && oh != -1)
{
width = ow;
height = oh;
}
}
else
unload();
load(loadName);
if (ow != -1 && oh != -1)
{
debugLog("name was too short, didn't load");
width = ow;
height = oh;
}
debugLog("DONE");
}
@ -419,13 +413,21 @@ void Texture::apply(bool repeatOverride)
glBindTexture(GL_TEXTURE_2D, textures[0]);
if (repeat || repeatOverride)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (!repeating)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
repeating = true;
}
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (repeating)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
repeating = false;
}
}
#endif
#ifdef BBGE_BUILD_DIRECTX
@ -473,18 +475,6 @@ void Texture::loadPNG(const std::string &file)
textures[0] = pngBind(file.c_str(), PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter);
}
if (info.Alpha)
components = 4;
else
components = 3;
/*
pngRawInfo rawinfo;
bool success = pngLoadRaw(file.c_str(), &rawinfo);
glBindTexture(GL_TEXTURE_2D, id);
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, rawinfo.Width, rawinfo.Height,
GL_RGB, GL_UNSIGNED_BYTE, rawinfo.Data);
*/
if (textures[0] != 0)
{
width = info.Width;

View file

@ -62,9 +62,8 @@ public:
static ImageTGA *TGAloadMem(void *mem, int size);
static bool useMipMaps;
bool repeat;
bool repeat, repeating;
int components;
#ifdef BBGE_BUILD_OPENGL
static GLint filter;
static GLint format;