From 9b63b400d5299f027f13d8e4c8f2838f5e6c194d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sun, 19 Feb 2012 04:57:04 +0100 Subject: [PATCH] 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) --- Aquaria/AnimationEditor.cpp | 1 + Aquaria/Avatar.cpp | 5 - Aquaria/DSQ.cpp | 5 +- Aquaria/Entity.cpp | 130 ++--------------- Aquaria/Entity.h | 16 --- Aquaria/Game.cpp | 8 +- Aquaria/Game.h | 12 -- Aquaria/SceneEditor.cpp | 2 - Aquaria/ScriptInterface.cpp | 18 --- BBGE/AfterEffect.cpp | 189 ++++++++++--------------- BBGE/BBGECompileConfig.h | 1 - BBGE/ByteBuffer.h | 2 +- BBGE/Core.cpp | 181 +----------------------- BBGE/Core.h | 7 - BBGE/Quad.cpp | 268 ++++++++++-------------------------- BBGE/Quad.h | 19 --- BBGE/RenderObject.cpp | 23 +--- BBGE/RenderObject.h | 5 - BBGE/SkeletalSprite.cpp | 24 +++- BBGE/SkeletalSprite.h | 1 + BBGE/Texture.cpp | 48 +++---- BBGE/Texture.h | 3 +- CMakeLists.txt | 5 +- 23 files changed, 209 insertions(+), 764 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 5066bde..1f07d73 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -1201,6 +1201,7 @@ void AnimationEditor::saveFile() void AnimationEditor::loadFile() { + SkeletalSprite::clearCache(); lastSelectedBone = 0; editingBone = 0; clearUndoHistory(); diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 8bc293e..0f76c8f 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -3996,7 +3996,6 @@ void Avatar::lockToWallCommon() dsq->spawnParticleEffect("LockToWall", position); stopBurst(); stopRoll(); - disableOverideMaxSpeed(); core->sound->playSfx("LockToWall", 1.0, 0);//, (1000+rand()%100)/1000.0f); //bursting = false; animatedBurst = false; @@ -4307,7 +4306,6 @@ void Avatar::lockToWall() void Avatar::applyTripEffects() { color.interpolateTo(BLIND_COLOR, 0.5); - currentColor = BLIND_COLOR; tripper->alpha.interpolateTo(1, 8); @@ -4334,7 +4332,6 @@ void Avatar::applyTripEffects() void Avatar::removeTripEffects() { color.interpolateTo(Vector(1,1,1),0.5); - currentColor = Vector(1,1,1); tripper->alpha.interpolateTo(0, 4); if (dsq->loops.trip != BBGE_AUDIO_NOCHANNEL) @@ -4350,7 +4347,6 @@ void Avatar::applyBlindEffects() // character black color.interpolateTo(BLIND_COLOR, 0.5); - currentColor = BLIND_COLOR; blinder->alpha.interpolateTo(1, 0.5); blinder->rotation.z = 0; @@ -4364,7 +4360,6 @@ void Avatar::applyBlindEffects() void Avatar::removeBlindEffects() { color.interpolateTo(Vector(1,1,1),0.5); - currentColor = Vector(1,1,1); blinder->alpha.interpolateTo(0, 0.5); //dsq->toggleMuffleSound(0); } diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 0f9032e..bb7bc5f 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -1057,11 +1057,7 @@ This build is not yet final, and as such there are a couple things lacking. They debugLog("Init Graphics Library..."); initGraphicsLibrary(user.video.resx, user.video.resy, fullscreen, user.video.vsync, user.video.bits); -#ifdef BBGE_BUILD_WIDESCREEN core->enable2DWide(user.video.resx, user.video.resy); -#else - core->enable2D(800, 600, 1); -#endif core->initFrameBuffer(); debugLog("OK"); @@ -2245,6 +2241,7 @@ void DSQ::shutdown() core->particleManager->clearParticleBank(); Shot::clearShotBank(); + SkeletalSprite::clearCache(); cursor->setTexturePointer(0, RenderObject::NO_ADD_REF); diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index 5b59fe6..6645bec 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -232,7 +232,6 @@ Entity::Entity() : StateMachine(), DFSprite() } entityTypeIdx = -1; damageTime = vars->entityDamageTime; - pushAvatar= false; slowingToStopPathTimer = 0; slowingToStopPath = 0; followPos = 0; @@ -240,21 +239,16 @@ Entity::Entity() : StateMachine(), DFSprite() swimPath = false; currentEntityTarget = 0; deleteOnPathEnd = false; - overideMaxSpeedValue= 0; - overideMaxSpeedTime=0; - followingPath = 0; multColor = Vector(1,1,1); collideRadius = 24; entityType = EntityType(0); targets.resize(10); attachedTo = 0; - currentPathNode = -1; //target = 0; frozenTimer = 0; canBeTargetedByAvatar = false; activationRange = 0; activationType = ACT_NONE; - currentColor = Vector(1,1,1); pushDamage = 0; //debugLog("dsq->addEntity()"); @@ -262,7 +256,6 @@ Entity::Entity() : StateMachine(), DFSprite() dsq->addEntity(this); maxSpeed = oldMaxSpeed = 300; entityDead = false; - takeDamage = true; health = maxHealth = 5; invincibleBreak = false; activationRadius = 40; @@ -485,7 +478,6 @@ void Entity::setName(const std::string &name) void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd) { - //Path *p = dsq->game->getPathByName(name); if (p) { deleteOnPathEnd = deleteOnEnd; @@ -514,15 +506,6 @@ void Entity::followPath(Path *p, int speedType, int dir, bool deleteOnEnd) debugLog("Starting"); position.data->path.getPathNode(0)->value = position; position.startPath(time);//, 1.0f/2.0f); - //swimPath = true; - /* - currentPathNode = 1; - followingPath = p; - setMaxSpeed(spd); - pathDefaultMaxSpeed = spd; - lastPathMaxSpeed = spd; - followingPathLoop = loop; - */ } } @@ -538,16 +521,16 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim) position.stop(); swimPath = swim; - debugLog("Generating path to: " + path->name); + //debugLog("Generating path to: " + path->name); dsq->pathFinding.generatePath(this, TileVector(start), TileVector(dest)); int sz = position.data->path.getNumPathNodes(); position.data->path.addPathNode(path->nodes[0].position, 1); VectorPath old = position.data->path; - std::ostringstream os; + /*std::ostringstream os; os << "Path length: " << sz; - debugLog(os.str()); + debugLog(os.str());*/ - debugLog("Regenerating section"); + //debugLog("Regenerating section"); //int ms = sz % 12; /* @@ -561,19 +544,19 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim) */ this->vel = 0; - debugLog("Molesting Path"); + //debugLog("Molesting Path"); dsq->pathFinding.molestPath(position.data->path); //position.data->path.realPercentageCalc(); //position.data->path.cut(4); - debugLog("forcing path to minimum 2 nodes"); + //debugLog("forcing path to minimum 2 nodes"); dsq->pathFinding.forceMinimumPath(position.data->path, start, dest); - debugLog("Done"); + //debugLog("Done"); - debugLog("Calculating Time"); + //debugLog("Calculating Time"); float time = position.data->path.getLength()/(float)dsq->continuity.getSpeedType(speedType); - debugLog("Starting"); + //debugLog("Starting"); position.data->path.getPathNode(0)->value = position; position.startPath(time);//, 1.0f/2.0f); @@ -582,10 +565,10 @@ void Entity::moveToNode(Path *path, int speedType, int dieOnPathEnd, bool swim) position.endOfPathEvent.set(MakeFunctionEvent(Entity, safeKill)); */ - debugLog("Set delete on Path end"); + //debugLog("Set delete on Path end"); deleteOnPathEnd = dieOnPathEnd; - debugLog("End of Generate Path"); + //debugLog("End of Generate Path"); //position.startSpeedPath(dsq->continuity.getSpeedType(speedType)); //position.startPath(((position.data->path.getNumPathNodes()*TILE_SIZE*4)-2)/dsq->continuity.getSpeedType(speedType)); @@ -624,7 +607,6 @@ void Entity::setNodeGroupActive(int group, bool v) void Entity::stopFollowingPath() { - followingPath = 0; position.stopPath(); } @@ -693,12 +675,6 @@ bool Entity::hasTarget(int t) return (targets[t]!=0); } -void Entity::warpToPathStart() -{ - if (followingPath && !followingPath->nodes.empty()) - position = followingPath->nodes[0].position; -} - void Entity::watchEntity(Entity *e) { watchingEntity = e; @@ -1396,7 +1372,7 @@ bool Entity::pathBurst(bool wallJump) bool Entity::isFollowingPath() { - return followingPath != 0 || position.isFollowingPath(); + return position.isFollowingPath(); } void Entity::onPathEnd() @@ -1820,15 +1796,6 @@ void Entity::onUpdate(float dt) //vel2=0; Vector lastPos = position; - if (overideMaxSpeedTime > 0) - { - overideMaxSpeedTime-= dt; - if (overideMaxSpeedTime < 0) - { - overideMaxSpeedTime = 0; - overideMaxSpeedValue = 0; - } - } if (ridingOnEntity) { @@ -1953,56 +1920,6 @@ void Entity::onUpdate(float dt) } */ - if (followingPath && currentPathNode != -1 && life == 1) - { - PathNode *node = &followingPath->nodes[currentPathNode]; - Vector v = node->position - this->position; - v.setLength2D(1000*dt); - vel += v; - - - int ms = pathDefaultMaxSpeed; - if (node->maxSpeed != -1) - { - ms = node->maxSpeed; - } - if (ms != lastPathMaxSpeed) - { - float distFromNode = 0, distBetweenNodes = 0; - distFromNode = (node->position - this->position).getLength2D(); - if (currentPathNode > 0) - { - PathNode *previousNode = &followingPath->nodes[currentPathNode-1]; - distBetweenNodes = (node->position - previousNode->position).getLength2D(); - } - setMaxSpeed(lastPathMaxSpeed + (ms - lastPathMaxSpeed)*(1.0f-(distFromNode/distBetweenNodes))); - } - //setMaxSpeed(ms); - Vector diffVec = (node->position - this->position); - if (diffVec.getSquaredLength2D() < sqr(200)) - { - currentPathNode ++; - lastPathMaxSpeed = ms; - if (currentPathNode >= followingPath->nodes.size()) - { - if (followingPathLoop == -1) - { - warpToPathStart(); - currentPathNode = 1; - } - else - { - if (deleteOnPathEnd) - this->safeKill(); - position.interpolateTo(followingPath->nodes[followingPath->nodes.size()-1].position, 0.5); - //position = followingPath->nodes[followingPath->nodes.size()-1].position; - vel = 0; - followingPath = 0; - } - } - } - } - if (getState() == STATE_PUSH) { //vel = pushVec * this->time; @@ -2415,24 +2332,9 @@ void Entity::setMaxSpeed(int ms) maxSpeed = oldMaxSpeed = ms; } -void Entity::overideMaxSpeed(int ms, float time) -{ - overideMaxSpeedTime = time; - overideMaxSpeedValue = ms; -} - -void Entity::disableOverideMaxSpeed() -{ - overideMaxSpeedValue =0; - overideMaxSpeedTime = 0; -} - int Entity::getMaxSpeed() { - if (overideMaxSpeedValue) - return overideMaxSpeedValue; - else - return maxSpeed; + return maxSpeed; } void Entity::songNote(int note) @@ -2450,10 +2352,6 @@ void Entity::sound(const std::string &sound, float freq, float fadeOut) Vector Entity::getEnergyShotTargetPosition() { - if (!energyShotTargetPosition.isZero()) - { - return energyShotTargetPosition; - } return getWorldPosition(); } @@ -2883,7 +2781,7 @@ bool Entity::damage(const DamageData &dmgData) if (d.damageType == DT_NONE) return false; //if () return true; - if (!takeDamage || isEntityDead()) + if (isEntityDead()) { //DUPE: same as below //HACK: hackish diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index faf8b42..4b0b697 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -277,7 +277,6 @@ public: void freeze(float time); - int leaches; virtual void onSceneFlipped() {} bool isNearObstruction(int sz, int type=0, TileVector *hitTile=0); @@ -308,10 +307,7 @@ public: virtual void onNotify(Entity *notify){} //void followPath(Path *p, int spd, int loop, bool deleteOnEnd = false); void followPath(Path *p, int speedType, int dir, bool deleteOnEnd = false); - void warpToPathStart(); - int currentPathNode; Entity *attachedTo; - Path *followingPath; bool touchAvatarDamage(int radius, float dmg, const Vector &override=Vector(-1,-1,-1), int speed=0, float pushTime = 0, Vector collidePos = Vector(0,0,0)); void moveTowards(Vector p, float dt, int spd); @@ -372,7 +368,6 @@ public: void slowToStopPath(float t); bool isSlowingToStopPath(); Vector lastMove; - int pushAvatar; float damageTime; void setEntityProperty(EntityProperty ep, bool value=true); @@ -419,7 +414,6 @@ public: Vector getEnergyShotTargetPosition(); int getRandomTargetPoint(); - Vector energyShotTargetPosition; Vector ridingOnEntityOffset; void moveOutOfWall(); bool isSittingOnInvisibleIn(); @@ -458,7 +452,6 @@ public: bool checkSplash(const Vector &override=Vector(0,0,0)); EatData eatData; InterpolatedVector flipScale; - SkeletalSprite copySkel; bool beautyFlip; void attachLance(); void setInvincible(bool inv); @@ -564,18 +557,11 @@ protected: virtual void onPathEnd(); bool swimPath; bool deleteOnPathEnd; - int overideMaxSpeedValue; - float overideMaxSpeedTime; InterpolatedVector multColor; EntityType entityType; std::vector attachedEntities; std::vector attachedEntitiesOffsets; - int pathDefaultMaxSpeed; - int lastPathMaxSpeed; - int followingPathLoop; - - virtual void onFreeze(){} //Entity *target; @@ -587,8 +573,6 @@ protected: void doDeathEffects(int manaBallEnergy=0, bool die=true); - Vector currentColor; - bool takeDamage; void onEnterState(int action); void onExitState(int action); //virtual bool onDamage(int amount, Spell *spell, Entity *attacker); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 78ef675..8c2cb53 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -2845,7 +2845,6 @@ void Game::generateCollisionMask(Quad *q, int overrideCollideRadius) q->collideRadius = overrideCollideRadius; else q->collideRadius = TILE_SIZE/2; - q->useCollisionMask = true; q->collisionMask.clear(); std::vector obs; TileVector tpos(q->position); @@ -4295,7 +4294,6 @@ bool Game::loadSceneXML(std::string scene) addProgress(); clearObsRows(); - jetStreams.clear(); warpAreas.clear(); TiXmlElement *lensFlare = doc.FirstChildElement("LensFlare"); while (lensFlare) @@ -6481,10 +6479,8 @@ void Game::applyState() //dsq->getRenderObjectLayer(LR_ELEMENTS5)->update = false; backgroundImageRepeat = 1; - jetStreams.clear(); grad = 0; maxZoom = -1; - followSym = 0; saveFile = 0; deathTimer = 0.9; runGameOverScript = false; @@ -6495,6 +6491,7 @@ void Game::applyState() elementTemplatePack =""; clearGrid(); clearPointers(); + SkeletalSprite::clearCache(); StateObject::applyState(); @@ -10976,9 +10973,6 @@ void Game::removeState() clearControlHint(); dsq->overlay->color = 0; - if (dsq->game->avatar->attachedTo) - avatarTransit = dsq->game->avatar->attachedTo->name; - //dsq->overlay->alpha = 0; dsq->overlay->alpha.interpolateTo(1, fadeTime); dsq->main(fadeTime); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index c53143b..a505640 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -73,7 +73,6 @@ struct RecipeMenu std::vector recipeMenuEntries; }; -class JetStream; class Avatar; class Gradient; class CurrentRender; @@ -134,14 +133,6 @@ enum EditTypes }; #endif -class FollowSym : public Quad -{ -public: - FollowSym(); -protected: - void onUpdate(float dt); -}; - class ManaBall : public Quad { public: @@ -739,8 +730,6 @@ public: TiXmlDocument *saveFile; - std::vector jetStreams; - FollowSym *followSym; Vector positionToAvatar; float getCoverage(Vector pos, int sampleArea = 5); @@ -800,7 +789,6 @@ public: Path *getNearestPath(const Vector &pos, PathType pathType=PATH_NONE); Path *getNearestPath(Path *p, std::string name); - std::string avatarTransit; #ifdef AQUARIA_BUILD_SCENEEDITOR SceneEditor sceneEditor; bool isSceneEditorActive() {return sceneEditor.isOn();} diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index e207a3b..e35557e 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -2394,8 +2394,6 @@ void SceneEditor::removeEntity() void SceneEditor::placeAvatar() { dsq->game->avatar->position = dsq->getGameCursorPosition(); - QuadLight::clearQuadLights(); - QuadLight::addQuadLight(QuadLight(Vector(dsq->game->avatar->position), Vector(1, 0, 0), 1200)); } void SceneEditor::scaleElementUp() diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index e091731..3cad9e8 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -2672,23 +2672,6 @@ luaFunc(entity_followPath) luaReturnNil(); } -luaFunc(entity_warpToPathStart) -{ - ScriptedEntity *e = scriptedEntity(L); - std::string s; - if (lua_isstring(L, 2)) - s = lua_tostring(L, 2); - if (s.empty()) - e->warpToPathStart(); - else - { - //e->followPath(s, 0, 0); - e->warpToPathStart(); - e->stopFollowingPath(); - } - luaReturnNil(); -} - luaFunc(getIngredientGfx) { luaReturnStr(dsq->continuity.getIngredientGfx(getString(L, 1)).c_str()); @@ -7482,7 +7465,6 @@ static const struct { luaRegister(entity_setAnimLayerTimeMult), luaRegister(entity_setCurrentTarget), - luaRegister(entity_warpToPathStart), luaRegister(entity_stopInterpolating), luaRegister(entity_followPath), diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index 4053df6..2879cf8 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -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); diff --git a/BBGE/BBGECompileConfig.h b/BBGE/BBGECompileConfig.h index 1f8048c..62fb262 100644 --- a/BBGE/BBGECompileConfig.h +++ b/BBGE/BBGECompileConfig.h @@ -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 diff --git a/BBGE/ByteBuffer.h b/BBGE/ByteBuffer.h index 4c7a780..b82a58c 100644 --- a/BBGE/ByteBuffer.h +++ b/BBGE/ByteBuffer.h @@ -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: diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 9ecabe9..12331fd 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -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); diff --git a/BBGE/Core.h b/BBGE/Core.h index e9ccede..90759bb 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -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 lights; - Mouse mouse; AfterEffectManager *afterEffectManager; diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 304b618..5fa50ee 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -23,30 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -std::vector 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; } } diff --git a/BBGE/Quad.h b/BBGE/Quad.h index 9c3898b..8c8ad98 100644 --- a/BBGE/Quad.h +++ b/BBGE/Quad.h @@ -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 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::vectorstrip; @@ -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(); diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index a0eb86c..fa9acdc 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -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 diff --git a/BBGE/RenderObject.h b/BBGE/RenderObject.h index d7b72c7..3b4fec1 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -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 collisionMask; std::vector transformedCollisionMask; diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 7de3872..8bc22a2 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -30,6 +30,21 @@ std::string SkeletalSprite::skinPath = "skins/"; std::string SkeletalSprite::secondaryAnimationPath = ""; +static std::map 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"); diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index c811791..668c92f 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -259,6 +259,7 @@ public: std::string filenameLoaded; static std::string animationPath, skinPath, secondaryAnimationPath; + static void clearCache(); protected: bool frozen; diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index c9c5461..d4234f9 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -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; diff --git a/BBGE/Texture.h b/BBGE/Texture.h index 936a381..44b6cf2 100644 --- a/BBGE/Texture.h +++ b/BBGE/Texture.h @@ -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; diff --git a/CMakeLists.txt b/CMakeLists.txt index e35d69b..ee72437 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,7 +215,6 @@ ADD_DEFINITIONS(-DBBGE_BUILD_FRAMEBUFFER=1) #ADD_DEFINITIONS(-DBBGE_BUILD_SHADERS=1) ADD_DEFINITIONS(-DBBGE_BUILD_OPENGL=1) ADD_DEFINITIONS(-DBBGE_BUILD_OPENGL_DYNAMIC=1) -ADD_DEFINITIONS(-DBBGE_BUILD_WIDESCREEN=1) ADD_DEFINITIONS(-DBBGE_BUILD_FMOD_OPENAL_BRIDGE=1) IF(AQUARIA_DEVELOPER_BUILD) @@ -384,8 +383,6 @@ SET(BBGE_SRCS ${BBGEDIR}/Interpolator.cpp ${BBGEDIR}/Joystick.cpp ${BBGEDIR}/LensFlare.cpp - ${BBGEDIR}/LightCone.cpp - ${BBGEDIR}/Light.cpp ${BBGEDIR}/Math.cpp ${BBGEDIR}/ParticleEffect.cpp ${BBGEDIR}/ParticleManager.cpp @@ -454,6 +451,8 @@ SET(BBGE_SRCS_UNUSED ${BBGEDIR}/CShim.cpp ${BBGEDIR}/Cutscene.cpp ${BBGEDIR}/FileVars.cpp + ${BBGEDIR}/Light.cpp + ${BBGEDIR}/LightCone.cpp ${BBGEDIR}/Model.cpp ${BBGEDIR}/OggStream.cpp ${BBGEDIR}/PackRead.cpp