diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index 2da0b02..15941c4 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -506,13 +506,14 @@ void AnimationEditor::undo() if (core->getCtrlState()) { - if (undoEntry >= 0 && undoEntry < undoHistory.size()) + if (undoEntry < undoHistory.size()) { std::list::iterator it = undoHistory.begin(); std::advance(it, undoEntry); editSprite->animations = it->animations; - undoEntry--; - if (undoEntry<0) undoEntry = 0; + if(undoEntry > 0) { + undoEntry--; + } } } } @@ -524,7 +525,7 @@ void AnimationEditor::redo() if (core->getCtrlState()) { undoEntry++; - if (undoEntry >= 0 && undoEntry < undoHistory.size()) + if (undoEntry < undoHistory.size()) { std::list::iterator it = undoHistory.begin(); std::advance(it, undoEntry); @@ -592,7 +593,7 @@ void AnimationEditor::reorderKeys() void AnimationEditor::rebuildKeyframeWidgets() { int offx=0; - for (int i = 0; i < keyframeWidgets.size(); i++) + for (size_t i = 0; i < keyframeWidgets.size(); i++) { keyframeWidgets[i]->setLife(0.03); keyframeWidgets[i]->setDecayRate(1); @@ -714,7 +715,7 @@ void AnimationEditor::update(float dt) text->setText(os.str()); char t2buf[128]; - sprintf(t2buf, "Bone x: %.3f, y: %.3f, rot: %.3f strip: %d pass: %d (%d)", ebdata.x, ebdata.y, ebdata.z, selectedStripPoint, pass, origpass); + sprintf(t2buf, "Bone x: %.3f, y: %.3f, rot: %.3f strip: %lu pass: %d (%d)", ebdata.x, ebdata.y, ebdata.z, selectedStripPoint, pass, origpass); text2->setText(t2buf); if (core->mouse.buttons.middle) @@ -831,14 +832,15 @@ void AnimationEditor::nextKey() if (editingStrip) { selectedStripPoint++; - if (selectedStripPoint >= editSprite->getSelectedBone(false)->changeStrip.size()) + if (selectedStripPoint >= editSprite->getSelectedBone(false)->changeStrip.size() + && selectedStripPoint > 0) selectedStripPoint --; } else { if (core->getCtrlState()) { - for (int i = 0; i < keyframeWidgets.size(); i++) + for (size_t i = 0; i < keyframeWidgets.size(); i++) { keyframeWidgets[i]->shiftLeft(); } @@ -861,15 +863,15 @@ void AnimationEditor::prevKey() if (editingStrip) { - selectedStripPoint--; - if (selectedStripPoint < 0) - selectedStripPoint = 0; + if(selectedStripPoint > 0) { + selectedStripPoint--; + } } else { if (core->getCtrlState()) { - for (int i = 0; i < keyframeWidgets.size(); i++) + for (size_t i = 0; i < keyframeWidgets.size(); i++) { keyframeWidgets[i]->shiftRight(); } @@ -1017,7 +1019,7 @@ void AnimationEditor::applyTranslation() if(!core->getCtrlState()) { // all bones in one anim mode - for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1030,9 +1032,9 @@ void AnimationEditor::applyTranslation() else { // all bones in all anims mode - for (int a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editSprite->animations.size(); ++a) { - for (int i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1117,7 +1119,7 @@ void AnimationEditor::flipRot() { if (!core->getCtrlState()) { - for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1129,9 +1131,9 @@ void AnimationEditor::flipRot() else { // all bones in all anims mode - for (int a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editSprite->animations.size(); ++a) { - for (int i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1199,7 +1201,7 @@ void AnimationEditor::rmbu() int rotdiff = editingBone->rotation.z - bcur->rot; if (!core->getCtrlState()) { - for (int i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->getCurrentAnimation()->getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->getCurrentAnimation()->getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1211,9 +1213,9 @@ void AnimationEditor::rmbu() else { // all bones in all anims mode - for (int a = 0; a < editSprite->animations.size(); ++a) + for (size_t a = 0; a < editSprite->animations.size(); ++a) { - for (int i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) + for (size_t i = 0; i < editSprite->animations[a].getNumKeyframes(); ++i) { BoneKeyframe *b = editSprite->animations[a].getKeyframe(i)->getBoneKeyframe(editingBone->boneIdx); if (b) @@ -1369,7 +1371,7 @@ void AnimationEditor::moveNextWidgets(float dt) int s = 0; KeyframeWidget *w=0; - for (int i = 0; i < keyframeWidgets.size(); i++) + for (size_t i = 0; i < keyframeWidgets.size(); i++) { w = keyframeWidgets[i]; if (s) diff --git a/Aquaria/AnimationEditor.h b/Aquaria/AnimationEditor.h index 6ba6e68..12cc5a6 100644 --- a/Aquaria/AnimationEditor.h +++ b/Aquaria/AnimationEditor.h @@ -131,7 +131,7 @@ public: SkeletalKeyframe buffer; bool editingStrip; - int selectedStripPoint; + size_t selectedStripPoint; void reverseAnim(); diff --git a/Aquaria/AquariaComboBox.cpp b/Aquaria/AquariaComboBox.cpp index 40961d5..f06c018 100644 --- a/Aquaria/AquariaComboBox.cpp +++ b/Aquaria/AquariaComboBox.cpp @@ -72,14 +72,14 @@ void AquariaComboBox::enqueueSelectItem(int index) enqueuedSelectItem = index; } -void AquariaComboBox::setScroll(int sc) +void AquariaComboBox::setScroll(size_t sc) { scroll = sc; } std::string AquariaComboBox::getSelectedItemString() { - if (selectedItem >= 0 && selectedItem < items.size()) + if (selectedItem < items.size()) return items[selectedItem]; return ""; } @@ -88,10 +88,8 @@ void AquariaComboBox::doScroll(int t) { if (t == 0) { - scroll--; - if (scroll < 0) scroll = 0; - else - { + if(scroll > 0) { + scroll--; close(0); open(0); } @@ -241,7 +239,7 @@ void AquariaComboBox::open(float t) { shownItems.clear(); - for (int i = scroll; i < scroll + numDrops; i++) + for (size_t i = scroll; i < scroll + numDrops; i++) { if (i < items.size()) { @@ -266,7 +264,7 @@ void AquariaComboBox::close(float t) isopen = false; - for (int i = 0; i < shownItems.size(); i++) + for (size_t i = 0; i < shownItems.size(); i++) { shownItems[i]->alpha.interpolateTo(0, t); } @@ -274,7 +272,7 @@ void AquariaComboBox::close(float t) if (t>0) dsq->run(t); - for(int i = 0; i < shownItems.size(); i++) + for(size_t i = 0; i < shownItems.size(); i++) { removeChild(shownItems[i]); shownItems[i]->destroy(); @@ -289,7 +287,7 @@ void AquariaComboBox::close(float t) bool AquariaComboBox::setSelectedItem(const std::string &item) { - for (int i = 0; i < items.size(); i++) + for (size_t i = 0; i < items.size(); i++) { if (items[i] == item) { @@ -312,9 +310,9 @@ void AquariaComboBox::setSelectedItem(int index) { doScroll(0); } - else + else if(index > 0) { - if (index >= 0 && index < items.size()) + if ((size_t) index < items.size()) { selectedItem = index; selectedItemLabel->setText(items[index]); diff --git a/Aquaria/AquariaMenuItem.cpp b/Aquaria/AquariaMenuItem.cpp index b842d98..c61ca69 100644 --- a/Aquaria/AquariaMenuItem.cpp +++ b/Aquaria/AquariaMenuItem.cpp @@ -591,13 +591,13 @@ void AquariaKeyConfig::onUpdate(float dt) switch(inputSetType) { case INPUTSET_KEY: - k = &ai->key[inputIdx]; + k = &ai->data.single.key[inputIdx]; break; case INPUTSET_MOUSE: - k = &ai->mse[inputIdx]; + k = &ai->data.single.mse[inputIdx]; break; case INPUTSET_JOY: - k = &ai->joy[inputIdx]; + k = &ai->data.single.joy[inputIdx]; break; default: k = 0; @@ -1186,7 +1186,7 @@ void AquariaButton::goDown() buttonlabel->position = Vector(0, 7); } -void AquariaButton::action(int actionID, int state, int source) +void AquariaButton::action(int actionID, int state, int source, InputDevice device) { if(actionID == ACTION_PRIMARY) { diff --git a/Aquaria/AquariaMenuItem.h b/Aquaria/AquariaMenuItem.h index ef17f74..e8f617b 100644 --- a/Aquaria/AquariaMenuItem.h +++ b/Aquaria/AquariaMenuItem.h @@ -225,14 +225,14 @@ public: bool setSelectedItem(const std::string &item); int getSelectedItem(); void enqueueSelectItem(int index); - void setScroll(int sc); + void setScroll(size_t sc); std::string getSelectedItemString(); void doScroll(int dir); bool isOpen() const { return isopen; } protected: void onUpdate(float dt); - int numDrops; + size_t numDrops; bool mb, isopen; int scroll; @@ -243,7 +243,7 @@ protected: Quad *bar, *scrollBtnUp, *scrollBtnDown; BitmapText *selectedItemLabel; - int selectedItem; + size_t selectedItem; float scrollDelay; bool firstScroll; Vector textscale; @@ -269,7 +269,7 @@ public: protected: - virtual void action(int actionID, int state, int source); + virtual void action(int actionID, int state, int source, InputDevice device); virtual void onUpdate(float dt); virtual void onToggleHighlight(bool on); diff --git a/Aquaria/AutoMap.cpp b/Aquaria/AutoMap.cpp new file mode 100644 index 0000000..0a5a280 --- /dev/null +++ b/Aquaria/AutoMap.cpp @@ -0,0 +1,286 @@ +/* +Copyright (C) 2007, 2010 - Bit-Blot + +This file is part of Aquaria. + +Aquaria is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "AutoMap.h" +#include "DSQ.h" +#include "Game.h" +#include "Avatar.h" + +#define AUTOMAP_GRIDTILE 512 + + + +AutoMap::AutoMap() : RenderObject(), ActionMapper() +{ + + followCamera = 1; + scale = Vector(0.4, 0.4); + position = Vector(400,300); + alpha = 0; + vis = false; + + blip = Vector(1,1); + blip.interpolateTo(Vector(4,4), 0.75, -1, 1, 1); + + initedGrid = false; + + + setTexture("particles/glow"); + + paintColor = Vector(1,1,1); + autoMapMode = 0; + + addAction(MakeFunctionEvent(AutoMap, lmb), ActionMapper::MOUSE_BUTTON_LEFT); + + shadowTex = 0; +} + + + +void AutoMap::destroy() +{ + RenderObject::destroy(); + if (shadowTex) + { + shadowTex->destroy(); + delete shadowTex; + shadowTex = 0; + } +} + +bool AutoMap::isOn() +{ + return vis; +} + +void AutoMap::toggle(bool on) +{ + const float t = 0.2; + if (on) + { + autoMapMode = 0; + dsq->game->togglePause(true); + dsq->fade(1, t); + dsq->main(t); + core->overrideStartLayer = LR_AFTER_EFFECTS; + core->overrideEndLayer = LR_MAX; + vis = true; + + + + alpha = 1; + + dsq->fade(0, t); + dsq->main(t); + } + else + { + dsq->fade(1, t); + dsq->main(t); + + core->overrideStartLayer = 0; + core->overrideEndLayer = 0; + vis = false; + alpha.interpolateTo(0, 0.5); + alpha = 0; + dsq->game->togglePause(false); + + dsq->fade(0, t); + dsq->main(t); + } +} + +void AutoMap::setGridFromWorld(Vector worldPos, int gridValue) +{ + int gx = worldPos.x / AUTOMAP_GRIDTILE; + int gy = worldPos.y / AUTOMAP_GRIDTILE; + + if (gx<0 || gy<0 || gx >= MAX_AUTOMAP_GRID || gy >= MAX_AUTOMAP_GRID) + { + std::ostringstream os; + os << "AutoMap::setGridFromWorld - exceeded grid size"; + os << "(" << gx <<", " << gy << ")"; + debugLog(os.str()); + return; + } + + grid[gx][gy] = gridValue; +} + +void AutoMap::initGrid() +{ + + + for (int x=0;xsetLife(1); + q->setDecayRate(0.5); + q->color = paintColor; + q->followCamera = 1; + q->setWidthHeight(8,8); + dsq->game->addRenderObject(q, this->layer); +} + +void AutoMap::onUpdate(float dt) +{ + RenderObject::onUpdate(dt); + + if (!initedGrid) + { + initGrid(); + } + + + if (dsq->game->avatar) + { + setGridFromWorld(dsq->game->avatar->position, 0); + } + + + if (vis && alpha.x == 1) + { + const float maxScale=1.25, minScale=0.5; + blip.update(dt); + + float spd = 0.5; + if (core->mouse.scrollWheelChange < 0) + { + scale -= Vector(spd*0.05f,spd*0.05f); + } + else if (core->mouse.scrollWheelChange > 0) + { + scale += Vector(spd*0.05f,spd*0.05f); + } + if (scale.x < minScale) + scale = Vector(minScale, minScale); + if (scale.x > maxScale) + scale = Vector(maxScale, maxScale); + if (core->mouse.buttons.middle) + { + offset += core->mouse.change*scale; + } + + } +} + +void AutoMap::lmb() +{ + if (autoMapMode == 0) + autoMapMode = 1; + else + autoMapMode = 0; +} + +void AutoMap::onRender() +{ + + if (alpha.x == 0) return; + + glBindTexture(GL_TEXTURE_2D, 0); + RenderObject::lastTextureApplied = 0; + float alphaValue = alpha.x; + + + + int ysz = dsq->game->cameraMax.y/TILE_SIZE; + int xsz = dsq->game->cameraMax.x/TILE_SIZE; + + + TileVector t(Vector(dsq->game->cameraMax.x/2, dsq->game->cameraMax.y/2)); + + + + int skip = 4; + glLineWidth(skip); + + if (alphaValue > 0) + { + + + + for (int y = 0; y < ysz; y += skip) + { + float f = float(y)/float(ysz); + f = 0.8f-(f*0.5f); + glColor4f(0.5f*f, 0.75f*f, 1*f, alphaValue); + + glBegin(GL_LINES); + int rowStart = -1; + int x = 0; + + for (x = 0; x < xsz; x++) + { + if (dsq->game->getGrid(TileVector(x,y))!=OT_BLACK) + { + if (rowStart == -1) + { + rowStart = x; + } + } + else + { + if (rowStart != -1) + { + glVertex3f((rowStart-t.x), (y-t.y),0); + glVertex3f((x-t.x), (y-t.y),0); + rowStart = -1; + } + } + } + if (rowStart != -1) + { + glVertex3f((rowStart-t.x), (y-t.y),0); + glVertex3f((x-t.x), (y-t.y),0); + } + glEnd(); + } + + + + } + + TileVector nt(dsq->game->avatar->position); + + glTranslatef(nt.x - t.x, nt.y - t.y,0); + glColor4f(0.5,0.7,1, alphaValue); + glPointSize(4); + + glBegin(GL_POINTS); + glVertex2f(0,0); + glEnd(); + + glColor4f(0.5,0.75,1, alphaValue*0.5f); + drawCircle(blip.x*16, 8); + + +} + diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 436359d..ddcde1d 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -45,9 +45,9 @@ const float JELLYCOSTUME_HEALAMOUNT = 0.5; const float biteTimerBiteRange = 0.6; const float biteTimerMax = 3; const float biteDelayPeriod = 0.08; -const int normalTendrilHits = 3; -const int rollTendrilHits = 4; -const int maxTendrilHits = 6; +const size_t normalTendrilHits = 3; +const size_t rollTendrilHits = 4; +const size_t maxTendrilHits = 6; const float fireDelayTime = 0.2; const int maxShieldPoints = 8; @@ -215,7 +215,7 @@ Vector randCirclePos(Vector position, int radius) return position + Vector(sinf(a), cosf(a))*radius; } -SongIconParticle::SongIconParticle(Vector color, Vector pos, int note) +SongIconParticle::SongIconParticle(Vector color, Vector pos, size_t note) : note(note) { cull = false; @@ -251,7 +251,7 @@ SongIconParticle::SongIconParticle(Vector color, Vector pos, int note) float smallestDist = HUGE_VALF; SongIcon *closest = 0; - for (int i = 0; i < avatar->songIcons.size(); i++) + for (size_t i = 0; i < avatar->songIcons.size(); i++) { if (i != note) { @@ -284,7 +284,7 @@ void SongIconParticle::onUpdate(float dt) } } -SongIcon::SongIcon(int note) : Quad(), note(note) +SongIcon::SongIcon(size_t note) : Quad(), note(note) { open = false; alphaMod = 0.9; @@ -553,7 +553,7 @@ void SongIcon::openNote() e->songNote(note); } } - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { Path *p = dsq->game->getPath(i); if (!p->nodes.empty()) @@ -604,7 +604,7 @@ void SongIcon::closeNote() e->songNoteDone(note, len); } } - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { Path *p = dsq->game->getPath(i); if (!p->nodes.empty()) @@ -1198,7 +1198,7 @@ void Avatar::lostTarget(int i, Entity *e) void Avatar::entityDied(Entity *e) { Entity::entityDied(e); - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { if (targets[i].e == e) { @@ -1266,7 +1266,7 @@ void Avatar::enableInput() if (dsq->continuity.form == FORM_ENERGY) { - for (int i = 0; i < targetQuads.size(); i++) + for (size_t i = 0; i < targetQuads.size(); i++) targetQuads[i]->start(); } @@ -1292,7 +1292,7 @@ void Avatar::disableInput() dsq->setMousePosition(Vector(400,300)); } - for (int i = 0; i < targetQuads.size(); i++) + for (size_t i = 0; i < targetQuads.size(); i++) { targetQuads[i]->stop(); } @@ -1302,7 +1302,7 @@ void Avatar::disableInput() void Avatar::clearTargets() { - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { if (targets[i].e) { @@ -1329,7 +1329,7 @@ void Avatar::openSingingInterface(InputDevice device) currentSongIdx = SONG_NONE; // make the singing icons appear - for (int i = 0; i < songIcons.size(); i++) + for (size_t i = 0; i < songIcons.size(); i++) { songIcons[i]->openInterface(); } @@ -1362,7 +1362,7 @@ void Avatar::closeSingingInterface() applyRidingPosition(); singing = false; - for (int i = 0; i < songIcons.size(); i++) + for (size_t i = 0; i < songIcons.size(); i++) { songIcons[i]->closeInterface(); } @@ -1452,7 +1452,7 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF os2 << "lastForm: " << lastForm; debugLog(os2.str()); - for (int i = 0; i < targetQuads.size(); i++) + for (size_t i = 0; i < targetQuads.size(); i++) { if (targetQuads[i]) targetQuads[i]->stop(); @@ -1604,17 +1604,15 @@ void Avatar::changeForm(FormType form, bool effects, bool onInit, FormType lastF dsq->game->sceneColor3.interpolateTo(Vector(1,1,1), 0.2); } */ - float lastHairAlphaMod = 0; if (hair) { hair->alphaMod = 0; - lastHairAlphaMod = hair->alphaMod; } switch (form) { case FORM_ENERGY: refreshModel("Naija", "EnergyForm"); - for (int i = 0; i < targetQuads.size(); i++) + for (size_t i = 0; i < targetQuads.size(); i++) targetQuads[i]->start(); leftHandEmitter->load("EnergyFormHandGlow"); leftHandEmitter->start(); @@ -1738,7 +1736,7 @@ void Avatar::updateSingingInterface(float dt) { float smallestDist = HUGE_VALF; int closest = -1; - for (int i = 0; i < songIcons.size(); i++) + for (size_t i = 0; i < songIcons.size(); i++) { float dist = (songIcons[i]->position - core->mouse.position).getSquaredLength2D(); if (dist < smallestDist) @@ -1793,7 +1791,7 @@ void Avatar::updateSingingInterface(float dt) if (!setNote) { bool alreadyAtNote = false; - for (int i = 0; i < songIcons.size(); i++) + for (size_t i = 0; i < songIcons.size(); i++) { const float dist = (songIcons[i]->position - core->mouse.position).getSquaredLength2D(); if (dist <= sqr(NOTE_ACCEPT_DISTANCE)) @@ -1820,7 +1818,7 @@ void Avatar::setSongIconPositions() { float radIncr = (2*PI)/float(songIcons.size()); float rad = 0; - for (int i = 0; i < songIcons.size(); i++) + for (size_t i = 0; i < songIcons.size(); i++) { songIcons[i]->position = Vector(400,300)+/*this->position + */Vector(sinf(rad)*singingInterfaceRadius, cosf(rad)*singingInterfaceRadius); rad += radIncr; @@ -1877,7 +1875,7 @@ Target Avatar::getNearestTarget(const Vector &checkPos, const Vector &distPos, E { if (ignore) { - int j = 0; + size_t j = 0; for (; j < ignore->size(); j++) { if ((*ignore)[j].e == e) @@ -1895,7 +1893,7 @@ Target Avatar::getNearestTarget(const Vector &checkPos, const Vector &distPos, E { if (ignore) { - int j = 0; + size_t j = 0; for (; j < ignore->size(); j++) { if ((*ignore)[j].e == e && (*ignore)[j].targetPt == i) @@ -1939,7 +1937,7 @@ bool wasDown = false; void Avatar::updateTargets(float dt, bool override) { DamageType damageType = DT_AVATAR_ENERGYBLAST; - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { if (!targets[i].e || !targets[i].e->isPresent() @@ -1999,7 +1997,7 @@ void Avatar::updateTargets(float dt, bool override) } if (targets.empty()) { - for (int i = 0; i < oldTargets.size(); i++) + for (size_t i = 0; i < oldTargets.size(); i++) { Entity *e = oldTargets[i].e; if (e) @@ -2021,7 +2019,7 @@ void Avatar::updateTargets(float dt, bool override) } else { - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { Entity *e = targets[i].e; if (e) @@ -2053,7 +2051,7 @@ void Avatar::updateTargetQuads(float dt) static Entity *lastTargetE = 0; const float tt = 0.02; - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { if (targets[i].e) { @@ -2094,7 +2092,7 @@ void Avatar::updateTargetQuads(float dt) if (targets.empty()) { - for (int i = 0; i < targetQuads.size(); i++) + for (size_t i = 0; i < targetQuads.size(); i++) { if (lastTargetE != 0) { @@ -2205,7 +2203,7 @@ bool Avatar::fireAtNearestValidEntity(const std::string &shot) if (!targets.empty()) { //homing = home; - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { /* if (!aimAt) @@ -2832,9 +2830,9 @@ Vector Avatar::getTendrilAimVector(int i, int max) return aim; } -int Avatar::getNumShots() +size_t Avatar::getNumShots() { - int thits = normalTendrilHits; + size_t thits = normalTendrilHits; if (flourishPowerTimer.isActive()) { if (lastBurstType == BURST_WALL) @@ -2855,17 +2853,17 @@ int Avatar::getNumShots() void Avatar::doShock(const std::string &shotName) { - int c = 0; + size_t c = 0; std::vector entitiesToHit; std::vector localTargets; bool clearTargets = true; - int thits = getNumShots(); + size_t thits = getNumShots(); if (!targets.empty() && targets[0].e != 0) { clearTargets = false; - for (int i = 0; i < thits; i++) + for (size_t i = 0; i < thits; i++) { entitiesToHit.push_back(targets[0].e); } @@ -2894,7 +2892,7 @@ void Avatar::doShock(const std::string &shotName) { while (entitiesToHit.size()game->fireShot(shotName, this, 0); @@ -2932,7 +2930,7 @@ void Avatar::doShock(const std::string &shotName) Shot *s = dsq->game->fireShot(shotName, this, e); if (!targets.empty()) { - for (int j = 0; j < targets.size(); j++) + for (size_t j = 0; j < targets.size(); j++) { if (targets[j].e == e) s->targetPt = targets[j].targetPt; @@ -3744,7 +3742,7 @@ Avatar::Avatar() : Entity(), ActionMapper() dsq->game->addRenderObject(tripper, LR_AFTER_EFFECTS); songIcons.resize(8); - int i = 0; + size_t i = 0; for (i = 0; i < songIcons.size(); i++) { songIcons[i] = new SongIcon(i); @@ -6908,7 +6906,7 @@ void Avatar::onWarp() bool Avatar::checkWarpAreas() { - int i = 0; + size_t i = 0; for (i = 0; i < dsq->game->getNumPaths(); i++) { bool warp = false; diff --git a/Aquaria/Avatar.h b/Aquaria/Avatar.h index cc58159..9d1e14e 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -74,7 +74,7 @@ enum SeeMapMode class SongIconParticle : public Quad { public: - SongIconParticle(Vector color, Vector pos, int note); + SongIconParticle(Vector color, Vector pos, size_t note); int note; SongIcon *toIcon; protected: @@ -84,9 +84,9 @@ protected: class SongIcon : public Quad { public: - SongIcon(int note); + SongIcon(size_t note); void destroy(); - int note; + size_t note; void openNote(); void closeNote(); void openInterface(); @@ -340,7 +340,7 @@ protected: Timer webBitTimer; int curWebPoint; void checkUpgradeForShot(Shot *s); - int getNumShots(); + size_t getNumShots(); void lockToWallCommon(); void onSetBoneLock(); void onUpdateBoneLock(); diff --git a/Aquaria/BitBlotLogo.cpp b/Aquaria/BitBlotLogo.cpp index 84732f3..558e453 100644 --- a/Aquaria/BitBlotLogo.cpp +++ b/Aquaria/BitBlotLogo.cpp @@ -141,7 +141,7 @@ void BitBlotLogo::applyState() dragon->loadSkeletal("bb-dragon"); dragon->animate("idle", -1); dragon->position = Vector(300 , -100); - for (int i = 0; i < dragon->bones.size(); i++) + for (size_t i = 0; i < dragon->bones.size(); i++) { dragon->getBoneByIdx(i)->shareAlphaWithChildren = 1; } @@ -162,7 +162,7 @@ void BitBlotLogo::applyState() landscape->addChild(windmill, PM_POINTER, RBP_OFF); windmill->update((rand()%100)*0.1f); windmill->scale = Vector(0.7, 0.7); - for (int i = 0; i < windmill->bones.size(); i++) + for (size_t i = 0; i < windmill->bones.size(); i++) { windmill->getBoneByIdx(i)->alpha = 0.7; } @@ -172,11 +172,11 @@ void BitBlotLogo::applyState() if (windmills.size() >= 2) { - for (int i = 0; i < windmills.size()-1; i++) + for (size_t i = 0; i < windmills.size()-1; i++) { if (windmills[i]->position.y < 4000) { - for (int j = i+1; j < windmills.size(); j++) + for (size_t j = i+1; j < windmills.size(); j++) { if (windmills[j]->position.y < 4000) { diff --git a/Aquaria/CollideEntity.cpp b/Aquaria/CollideEntity.cpp index d3012e4..e540ec0 100644 --- a/Aquaria/CollideEntity.cpp +++ b/Aquaria/CollideEntity.cpp @@ -189,7 +189,7 @@ void CollideEntity::updateMovement(float dt) { vel += Vector(0, weight*dt); } - for (int i = 0; i < attachedEntities.size(); i++) + for (size_t i = 0; i < attachedEntities.size(); i++) { attachedEntities[i]->position = this->position + attachedEntitiesOffsets[i]; attachedEntities[i]->rotation = this->rotation; diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 9345c1d..609e0a2 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -60,7 +60,7 @@ Continuity::Continuity() bool Continuity::isIngredientFull(IngredientData *data) { - for (int i = 0; i < ingredients.size(); i++) + for (size_t i = 0; i < ingredients.size(); i++) { if (nocasecmp(ingredients[i]->name, data->name)==0) { @@ -95,7 +95,7 @@ void Continuity::pickupIngredient(IngredientData *d, int amount, bool effects, b int Continuity::indexOfIngredientData(const IngredientData* data) const { - for (int i = 0; i < ingredientData.size(); i++) + for (size_t i = 0; i < ingredientData.size(); i++) { if (ingredientData[i]->name == data->name) { @@ -105,7 +105,7 @@ int Continuity::indexOfIngredientData(const IngredientData* data) const return -1; } -#define FOR_INGREDIENTDATA(x) for (int x = 0; x < ingredientData.size(); x++) +#define FOR_INGREDIENTDATA(x) for (size_t x = 0; x < ingredientData.size(); x++) IngredientData *Continuity::getIngredientDataByName(const std::string &name) { @@ -119,7 +119,7 @@ IngredientData *Continuity::getIngredientDataByName(const std::string &name) IngredientData *Continuity::getIngredientHeldByName(const std::string &name) const { - for (int i = 0; i < ingredients.size(); i++) { + for (size_t i = 0; i < ingredients.size(); i++) { if (nocasecmp(ingredients[i]->name, name)==0) return ingredients[i]; } @@ -183,15 +183,15 @@ std::string Continuity::getIngredientDisplayName(const std::string& name) const return splitCamelCase(name); } -IngredientData *Continuity::getIngredientHeldByIndex(int idx) const +IngredientData *Continuity::getIngredientHeldByIndex(size_t idx) const { - if (idx < 0 || idx >= ingredients.size()) return 0; + if (idx >= ingredients.size()) return 0; return ingredients[idx]; } -IngredientData *Continuity::getIngredientDataByIndex(int idx) +IngredientData *Continuity::getIngredientDataByIndex(size_t idx) { - if (idx < 0 || idx >= ingredientData.size()) return 0; + if (idx >= ingredientData.size()) return 0; return ingredientData[idx]; } @@ -277,14 +277,14 @@ void Continuity::sortFood() std::vector sort; - for (int i = 0; i < dsq->continuity.ingredients.size(); i++) + for (size_t i = 0; i < dsq->continuity.ingredients.size(); i++) { dsq->continuity.ingredients[i]->sorted = false; } - for (int j = 0; j < sortOrder.size(); j++) + for (size_t j = 0; j < sortOrder.size(); j++) { - for (int i = 0; i < dsq->continuity.ingredients.size(); i++) + for (size_t i = 0; i < dsq->continuity.ingredients.size(); i++) { IngredientData *data = dsq->continuity.ingredients[i]; if (!data->sorted) @@ -301,7 +301,7 @@ void Continuity::sortFood() } else if (sortOrder[j].effectType != IET_NONE) { - for (int c = 0; c < data->effects.size(); c++) + for (size_t c = 0; c < data->effects.size(); c++) { if (data->effects[c].type == sortOrder[j].effectType) { @@ -323,7 +323,7 @@ void Continuity::sortFood() } } - for (int i = 0; i < dsq->continuity.ingredients.size(); i++) + for (size_t i = 0; i < dsq->continuity.ingredients.size(); i++) { IngredientData *data = dsq->continuity.ingredients[i]; if (!data->sorted) @@ -334,7 +334,7 @@ void Continuity::sortFood() } ingredients.clear(); - for (int i = 0; i < sort.size(); i++) { + for (size_t i = 0; i < sort.size(); i++) { ingredients.push_back(sort[i]); } sort.clear(); @@ -445,9 +445,9 @@ void Continuity::setFishPoison(float m, float t) fishPoison = m; } -std::string Continuity::getIEString(IngredientData *data, int i) +std::string Continuity::getIEString(IngredientData *data, size_t i) { - if (i < 0 || i >= data->effects.size()) return ""; + if (i >= data->effects.size()) return ""; IngredientEffect fx = data->effects[i]; IngredientEffectType useType = fx.type; @@ -572,7 +572,7 @@ std::string Continuity::getAllIEString(IngredientData *data) { std::ostringstream os; - for (int i = 0; i < data->effects.size(); i++) + for (size_t i = 0; i < data->effects.size(); i++) { os << getIEString(data, i) << "\n"; } @@ -585,7 +585,7 @@ bool Continuity::applyIngredientEffects(IngredientData *data) { bool eaten = true; float y =0; - for (int i = 0; i < data->effects.size(); i++) + for (size_t i = 0; i < data->effects.size(); i++) { y = 300 + i * 40; IngredientEffect fx = data->effects[i]; @@ -955,8 +955,8 @@ void Continuity::loadIngredientData(const std::string &file) if (!effects.empty()) { - int p1 = effects.find("("); - int p2 = effects.find(")"); + size_t p1 = effects.find("("); + size_t p2 = effects.find(")"); if (p1 != std::string::npos && p2 != std::string::npos) { effects = effects.substr(p1+1, p2-(p1+1)); @@ -1053,7 +1053,7 @@ void Continuity::loadIngredientData(const std::string &file) fx.type = IET_SCRIPT; } - int c = 0; + size_t c = 0; while (c < bit.size()) { if (bit[c] == '+') @@ -1309,7 +1309,7 @@ std::string Continuity::getVoxForSongSlot(int songSlot) EatData *Continuity::getEatData(const std::string &name) { - for (int i = 0; i < eats.size(); i++) + for (size_t i = 0; i < eats.size(); i++) { if (eats[i].name == name) return &eats[i]; @@ -1607,7 +1607,7 @@ void Continuity::castSong(int num) e->song((SongType)num); } } - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { Path *p = dsq->game->getPath(i); if (p && !p->nodes.empty()) @@ -1642,13 +1642,13 @@ bool Continuity::isSongTypeForm(SongType s) return (s == SONG_ENERGYFORM || s == SONG_BEASTFORM || s == SONG_NATUREFORM || s == SONG_SUNFORM || s == SONG_SPIRITFORM || s == SONG_FISHFORM || s== SONG_DUALFORM); } -void Continuity::shortenSong(Song &song, int size) +void Continuity::shortenSong(Song &song, size_t size) { if (song.notes.size() > size) { Song copy = song; song.notes.clear(); - for (int i = copy.notes.size()-size; i < copy.notes.size(); i++) + for (size_t i = copy.notes.size()-size; i < copy.notes.size(); i++) { song.notes.push_back(copy.notes[i]); } @@ -1674,7 +1674,7 @@ int Continuity::checkSongAssisted(const Song &s) shortenSong(song, 64); std::vector songChecks; - for (int c = 0; c < songBank.size(); c++) + for (size_t c = 0; c < songBank.size(); c++) { int i = songSlotsToType[c]; if (knowsSong[i]) @@ -1683,9 +1683,10 @@ int Continuity::checkSongAssisted(const Song &s) songChecks.push_back(SongCheck(i, s)); } } - for (int i = 0; i < songChecks.size(); i++) + for (size_t i = 0; i < songChecks.size(); i++) { - int j=0,c=0,m=0,last=0,rank=0; + size_t j = 0; + int c=0,m=0,last=0,rank=0; int ms=songChecks[i].song->notes.size(); j = 0; @@ -1739,7 +1740,7 @@ loop: goto loop; } int songIdx = SONG_NONE, lowestRank = -1; - for (int i = 0; i < songChecks.size(); i++) + for (size_t i = 0; i < songChecks.size(); i++) { if (songChecks[i].pass) { @@ -1762,21 +1763,21 @@ int Continuity::checkSong(const Song &song) bool knowAllSongs = false; // way too long song if (song.notes.size() > 64) return SONG_NONE; - for (int c = 0; c < songBank.size(); c++) + for (size_t c = 0; c < songBank.size(); c++) { int i = songSlotsToType[c]; if ((knowAllSongs || knowsSong[i])) { Song *s = &songBank[i]; if (s->notes.empty()) continue; - int j = 0; + size_t j = 0; { bool foundSong = false; - int currentNote = 0; + size_t currentNote = 0; for (j = 0; j < song.notes.size(); j++) { - if (currentNote >= 0 && currentNote < (*s).notes.size()) + if (currentNote < (*s).notes.size()) { int bankNote = (*s).notes[currentNote]; int songNote = song.notes[j]; @@ -2083,11 +2084,11 @@ void Continuity::eatBeast(const EatData &eatData) } } -void Continuity::removeNaijaEat(int idx) +void Continuity::removeNaijaEat(size_t idx) { std::vector copy = naijaEats; naijaEats.clear(); - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { if (i != idx) naijaEats.push_back(copy[i]); @@ -2167,7 +2168,7 @@ void Continuity::initAvatar(Avatar *a) void Continuity::spawnAllIngredients(const Vector &position) { - for (int i = 0; i < ingredientData.size(); i++) + for (size_t i = 0; i < ingredientData.size(); i++) { dsq->game->spawnIngredient(ingredientData[i]->name, position, 4, 0); } @@ -2227,9 +2228,9 @@ void Continuity::loadPetData() in.close(); } -PetData *Continuity::getPetData(int idx) +PetData *Continuity::getPetData(size_t idx) { - if (idx < 0 || idx >= petData.size()) + if (idx >= petData.size()) { std::ostringstream os; os << "getPetData(" << idx << ") index out of range"; @@ -2405,7 +2406,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, XMLElement *vox = doc.NewElement("VO"); { std::ostringstream os; - for (int i = 0; i < dsq->continuity.voiceOversPlayed.size(); i++) + for (size_t i = 0; i < dsq->continuity.voiceOversPlayed.size(); i++) { os << dsq->continuity.voiceOversPlayed[i] << " "; @@ -2487,7 +2488,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, // new format as used by android version std::ostringstream ingrNames; - for (int i = 0; i < ingredients.size(); i++) + for (size_t i = 0; i < ingredients.size(); i++) { IngredientData *data = ingredients[i]; ingrNames << data->name << " " << data->amount << " "; @@ -2496,7 +2497,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, // for compatibility with older versions std::ostringstream ingrOs; - for (int i = 0; i < ingredients.size(); i++) + for (size_t i = 0; i < ingredients.size(); i++) { IngredientData *data = ingredients[i]; ingrOs << data->getIndex() << " " << data->amount << " "; @@ -2504,7 +2505,7 @@ void Continuity::saveFile(int slot, Vector position, unsigned char *scrShotData, startData->SetAttribute("ingr", ingrOs.str().c_str()); std::ostringstream recOs; - for (int i = 0; i < recipes.size(); i++) + for (size_t i = 0; i < recipes.size(); i++) { recOs << recipes[i].isKnown() << " "; } @@ -2684,15 +2685,6 @@ void Continuity::loadFile(int slot) this->reset(); - int versionMajor=-1, versionMinor=-1, versionRevision=-1; - XMLElement *xmlVersion = doc.FirstChildElement("Version"); - if (xmlVersion) - { - versionMajor = atoi(xmlVersion->Attribute("major")); - versionMinor = atoi(xmlVersion->Attribute("minor")); - versionRevision = atoi(xmlVersion->Attribute("revision")); - } - XMLElement *e = doc.FirstChildElement("Flag"); while (e) { @@ -2700,8 +2692,6 @@ void Continuity::loadFile(int slot) e = e->NextSiblingElement("Flag"); } - - XMLElement *efx = doc.FirstChildElement("EFX"); if (efx) { @@ -3013,7 +3003,7 @@ void Continuity::loadFile(int slot) { std::istringstream is(startData->Attribute("rec")); - for (int i = 0; i < recipes.size(); i++) + for (size_t i = 0; i < recipes.size(); i++) { bool known = false; is >> known; @@ -3421,7 +3411,7 @@ void Continuity::learnRecipe(Recipe *r, bool effects) void Continuity::learnRecipe(const std::string &result, bool effects) { - for (int i = 0; i < recipes.size(); i++) + for (size_t i = 0; i < recipes.size(); i++) { if (nocasecmp(recipes[i].result, result)==0) { @@ -3540,9 +3530,9 @@ void Continuity::reset() core->resetTimer(); } -float Continuity::getSpeedType(int speedType) +float Continuity::getSpeedType(size_t speedType) { - if (speedType >= speedTypes.size() || speedType < 0) + if (speedType >= speedTypes.size()) { std::ostringstream os; os << "speedType: " << speedType << " out of range"; diff --git a/Aquaria/Continuity.h b/Aquaria/Continuity.h index f675712..6227023 100644 --- a/Aquaria/Continuity.h +++ b/Aquaria/Continuity.h @@ -43,7 +43,7 @@ public: void setCostume(const std::string &c); - void shortenSong(Song &song, int size); + void shortenSong(Song &song, size_t size); void warpLiToAvatar(); void flingMonkey(Entity *e); @@ -76,7 +76,7 @@ public: std::string getDescriptionForSongSlot(int songSlot); std::string getVoxForSongSlot(int songSlot); - std::string getIEString(IngredientData *data, int i); + std::string getIEString(IngredientData *data, size_t i); std::string getAllIEString(IngredientData *data); std::string getInternalFormName(); @@ -119,7 +119,7 @@ public: float getStory(); void setStory(float v); - float getSpeedType(int speedType); + float getSpeedType(size_t speedType); void setNaijaModel(std::string model); @@ -192,8 +192,8 @@ public: IngredientData *getIngredientHeldByName(const std::string &name) const; // an ingredient that the player actually has; in the ingredients list IngredientData *getIngredientDataByName(const std::string &name); // an ingredient in the general data list; ingredientData - IngredientData *getIngredientHeldByIndex(int idx) const; - IngredientData *getIngredientDataByIndex(int idx); + IngredientData *getIngredientHeldByIndex(size_t idx) const; + IngredientData *getIngredientDataByIndex(size_t idx); int getIngredientDataSize() const; int getIngredientHeldSize() const; @@ -242,13 +242,13 @@ public: float speedMult2; void eatBeast(const EatData &eatData); - void removeNaijaEat(int idx); + void removeNaijaEat(size_t idx); void removeLastNaijaEat(); EatData *getLastNaijaEat(); bool isNaijaEatsEmpty(); void loadPetData(); - PetData *getPetData(int idx); + PetData *getPetData(size_t idx); std::vector naijaEats; diff --git a/Aquaria/Credits.cpp b/Aquaria/Credits.cpp index bfdffc9..1f27fe9 100644 --- a/Aquaria/Credits.cpp +++ b/Aquaria/Credits.cpp @@ -30,11 +30,11 @@ namespace AQCredits std::vector slides; - void watchSlide(int slide) + void watchSlide(size_t slide) { float t = 10; - if (!(slide >= 0 && slide < slides.size())) return; + if (slide >= slides.size()) return; Quad *q = slides[slide]; @@ -64,7 +64,7 @@ namespace AQCredits else cred->alpha.interpolateTo(0, t, 0, 0, 1); } -}; +} using namespace AQCredits; @@ -127,7 +127,7 @@ void Credits::applyState() slides.resize(numSlides); - for (int i = 0; i < slides.size(); i++) + for (size_t i = 0; i < slides.size(); i++) { slides[i] = new Quad("credits/slide-" + numToZeroString(i, 4), Vector(400, 300)); slides[i]->alpha = 0; diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index 3baf93c..37ec957 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -131,8 +131,8 @@ static void Linux_CopyTree(const char *src, const char *dst) #endif -const int saveSlotPageSize = 4; -int maxPages = 15; +const size_t saveSlotPageSize = 4; +size_t maxPages = 15; #ifdef AQUARIA_BUILD_CONSOLE const int MAX_CONSOLELINES = 18; #endif @@ -325,15 +325,26 @@ void DSQ::loadElementEffects() inFile.close(); } -ElementEffect DSQ::getElementEffectByIndex(int e) +ElementEffect DSQ::getElementEffectByIndex(size_t e) { - if (e < elementEffects.size() && e >= 0) + if (e < elementEffects.size()) { return elementEffects[e]; } ElementEffect empty; empty.type = EFX_NONE; + empty.alpha = 0; + empty.blendType = 0; + empty.color = 0; + empty.segsx = empty.segsy = 0; + empty.segs_dgmx = empty.segs_dgmy = 0; + empty.segs_dgo = 0; + empty.segs_dgox = empty.segs_dgoy = 0; + empty.segs_dgtm = 0; + empty.wavy_flip = false; + empty.wavy_max = empty.wavy_min = 0; + empty.wavy_radius = 0; return empty; } @@ -1703,6 +1714,8 @@ void DSQ::setInputMode(InputDevice mode) break; case INPUT_KEYBOARD: break; + case INPUT_NODEVICE: + break; } } @@ -1756,7 +1769,7 @@ void DSQ::debugLog(const std::string &s) if (consoleLines.size() > MAX_CONSOLELINES) { - for (int i = 0; i < consoleLines.size()-1; i++) + for (size_t i = 0; i < consoleLines.size()-1; i++) { consoleLines[i] = consoleLines[i+1]; } @@ -1765,7 +1778,7 @@ void DSQ::debugLog(const std::string &s) if (console) { std::string text; - for (int i = 0; i < consoleLines.size(); i++) + for (size_t i = 0; i < consoleLines.size(); i++) { text += consoleLines[i] + '\n'; } @@ -1777,7 +1790,7 @@ void DSQ::debugLog(const std::string &s) int DSQ::getEntityTypeIndexByName(std::string s) { - for (int i = 0; i < game->entityTypeList.size(); i++) + for (size_t i = 0; i < game->entityTypeList.size(); i++) { EntityClass *t = &game->entityTypeList[i]; if (t->name == s) @@ -1841,7 +1854,7 @@ void DSQ::startSelectedMod() ModEntry* DSQ::getSelectedModEntry() { - if (!modEntries.empty() && selectedMod >= 0 && selectedMod < modEntries.size()) + if (!modEntries.empty() && selectedMod < modEntries.size()) return &modEntries[selectedMod]; return 0; } @@ -1877,7 +1890,7 @@ void DSQ::applyPatches() loadMods(); for (std::vector::iterator it = activePatches.begin(); it != activePatches.end(); ++it) - for(int i = 0; i < modEntries.size(); ++i) + for(size_t i = 0; i < modEntries.size(); ++i) if(modEntries[i].type == MODTYPE_PATCH) if(!nocasecmp(modEntries[i].path.c_str(), it->c_str())) _applyPatch(modEntries[i].path); @@ -1940,10 +1953,9 @@ void DSQ::refreshResourcesForPatch(const std::string& name) int reloaded = 0; if(files.size()) { - for(int i = 0; i < dsq->resources.size(); ++i) + for(size_t i = 0; i < dsq->resources.size(); ++i) { Texture *r = dsq->resources[i]; - bool found = false; for(size_t i = 0; i < files.size(); ++i) if(files[i] == r->name) { @@ -2344,7 +2356,7 @@ void DSQ::playNoEffect() void DSQ::clearMenu(float t) { - for (int i = 0; i < menu.size(); i++) + for (size_t i = 0; i < menu.size(); i++) { menu[i]->setLife(1); menu[i]->setDecayRate(1/t); @@ -2412,7 +2424,7 @@ bool DSQ::onPickedSaveSlot(AquariaSaveSlot *slot) } } - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i]->mbDown = false; } @@ -2486,7 +2498,7 @@ bool DSQ::modIsKnown(const std::string& name) std::string nlower = name; stringToLower(nlower); - for(int i = 0; i < modEntries.size(); ++i) + for(size_t i = 0; i < modEntries.size(); ++i) { std::string elower = modEntries[i].path; stringToLower(elower); @@ -2718,13 +2730,13 @@ void DSQ::title(bool fade) void DSQ::createSaveSlotPage() { - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i]->safeKill(); } saveSlots.resize(saveSlotPageSize); - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i] = new AquariaSaveSlot(i + user.data.savePage * saveSlotPageSize); saveSlots[i]->followCamera = 1; @@ -2764,7 +2776,7 @@ void DSQ::prevSaveSlotPage() if (saveSlots.empty()) return; user.data.savePage--; - if (user.data.savePage < 0) + if (user.data.savePage > maxPages) user.data.savePage = maxPages; createSaveSlotPage(); @@ -2814,7 +2826,7 @@ void DSQ::clearSaveSlots(bool trans) saveSlotPageCount->fadeAlphaWithLife = 1; } - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i]->close(trans); } @@ -2827,7 +2839,7 @@ void DSQ::clearSaveSlots(bool trans) { disableMiniMapOnNoInput = false; - for (int i = 0; i < menu.size(); i++) + for (size_t i = 0; i < menu.size(); i++) { if (i != 1) { @@ -2853,7 +2865,7 @@ void DSQ::clearSaveSlots(bool trans) void DSQ::hideSaveSlots() { - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i]->hide(); } @@ -2863,7 +2875,7 @@ void DSQ::transitionSaveSlots() { hideSaveSlotCrap(); - for (int i = 0; i < saveSlots.size(); i++) + for (size_t i = 0; i < saveSlots.size(); i++) { saveSlots[i]->transition(); } @@ -2902,7 +2914,7 @@ void DSQ::doSaveSlotMenu(SaveSlotMode ssm, const Vector &position) saveSlotMode = SSM_NONE; createSaveSlots(ssm); - const int firstSaveSlot = user.data.savePage * saveSlotPageSize; + const size_t firstSaveSlot = user.data.savePage * saveSlotPageSize; if (user.data.saveSlot >= firstSaveSlot && user.data.saveSlot < firstSaveSlot + saveSlots.size()) { selectedSaveSlot = saveSlots[user.data.saveSlot - firstSaveSlot]; @@ -3344,7 +3356,7 @@ bool DSQ::playedVoice(const std::string &file) { std::string f = file; stringToUpper(f); - for (int i = 0; i < dsq->continuity.voiceOversPlayed.size(); i++) + for (size_t i = 0; i < dsq->continuity.voiceOversPlayed.size(); i++) { if (f == dsq->continuity.voiceOversPlayed[i]) { @@ -3733,13 +3745,13 @@ void DSQ::updateActionButtons() if (/*inputMode != INPUT_KEYBOARD &&*/ game->isActive()) { for(size_t i = 0; i < almb.size(); ++i) - if (ActionMapper::getKeyState(almb[i]->key[0]) || ActionMapper::getKeyState(almb[i]->key[1])) + if (ActionMapper::getKeyState(almb[i]->data.single.key[0]) || ActionMapper::getKeyState(almb[i]->data.single.key[1])) { mouse.buttons.left = DOWN; break; } for(size_t i = 0; i < armb.size(); ++i) - if (ActionMapper::getKeyState(armb[i]->key[0]) || ActionMapper::getKeyState(armb[i]->key[1])) + if (ActionMapper::getKeyState(armb[i]->data.single.key[0]) || ActionMapper::getKeyState(armb[i]->data.single.key[1])) { mouse.buttons.right = DOWN; break; @@ -3749,13 +3761,13 @@ void DSQ::updateActionButtons() if (joystickAsMouse) { for(size_t i = 0; i < almb.size(); ++i) - if (ActionMapper::getKeyState(almb[i]->joy[0])) + if (ActionMapper::getKeyState(almb[i]->data.single.joy[0])) { mouse.buttons.left = DOWN; break; } for(size_t i = 0; i < armb.size(); ++i) - if (ActionMapper::getKeyState(armb[i]->joy[0])) + if (ActionMapper::getKeyState(armb[i]->data.single.joy[0])) { mouse.buttons.right = DOWN; break; @@ -3936,6 +3948,8 @@ void DSQ::onUpdate(float dt) break; case INPUT_KEYBOARD: break; + case INPUT_NODEVICE: + break; } os << std::endl; Bone *b = dsq->game->avatar->skeletalSprite.getBoneByIdx(1); @@ -4248,7 +4262,7 @@ void DSQ::modifyDt(float &dt) void DSQ::removeElement(Element *element) { - for (int i = 0; i < dsq->elements.size(); i++) + for (size_t i = 0; i < dsq->elements.size(); i++) { if (dsq->elements[i] == element) { @@ -4259,11 +4273,11 @@ void DSQ::removeElement(Element *element) } // only happens in editor, no need to optimize -void DSQ::removeElement(int idx) +void DSQ::removeElement(size_t idx) { ElementContainer copy = elements; clearElements(); - int i = 0; + size_t i = 0; for (i = 0; i < idx; i++) { addElement(copy[i]); @@ -4288,7 +4302,7 @@ void DSQ::clearElements() void DSQ::addEntity(Entity *entity) { - int i; + size_t i; for (i = 0; entities[i] != 0; i++) {} if (i+1 >= entities.size()) entities.resize(entities.size()*2, 0); @@ -4353,7 +4367,7 @@ void DSQ::updatepecue(float dt) { int nz = 0; - for (int i = 0; i < pecue.size(); i++) + for (size_t i = 0; i < pecue.size(); i++) { PECue *p = &pecue[i]; if (p->t > 0) diff --git a/Aquaria/DSQ.h b/Aquaria/DSQ.h index 0431983..b1423a7 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -79,7 +79,6 @@ public: void capture(); }; - struct SFXLoops { SFXLoops(); @@ -116,7 +115,6 @@ public: void load(); }; - class Profile { public: @@ -164,7 +162,7 @@ public: void save(const std::string &name); void load(const std::string &name); - int frame; + unsigned int frame; float time; float timeDiff; std::vector frames; @@ -237,12 +235,12 @@ public: int getEntityLayerToLayer(int layer); void addElement(Element *e); - int getNumElements() const {return elements.size();} + size_t getNumElements() const {return elements.size();} Element *getElement(int idx) const {return elements[idx];} Element *getFirstElementOnLayer(int layer) const {return layer<0 || layer>15 ? 0 : firstElementOnLayer[layer];} void clearElements(); // Used only by scene editor: - void removeElement(int idx); + void removeElement(size_t idx); void removeElement(Element *e); ElementContainer getElementsCopy() const {return elements;} @@ -335,7 +333,7 @@ public: bool canOpenEditor() const; void loadElementEffects(); - ElementEffect getElementEffectByIndex(int e); + ElementEffect getElementEffectByIndex(size_t e); typedef std::vector ElementEffects; ElementEffects elementEffects; @@ -414,7 +412,7 @@ public: std::vector modEntries; std::vector activePatches; - int selectedMod; + size_t selectedMod; ModSelectorScreen *modSelectorScr; void startSelectedMod(); diff --git a/Aquaria/Damage.h b/Aquaria/Damage.h index 0630234..7a87101 100644 --- a/Aquaria/Damage.h +++ b/Aquaria/Damage.h @@ -7,7 +7,6 @@ class Shot; class Bone; class Entity; -enum FormType; enum DamageType { diff --git a/Aquaria/Demo.cpp b/Aquaria/Demo.cpp index 1a57bf7..7e6509c 100644 --- a/Aquaria/Demo.cpp +++ b/Aquaria/Demo.cpp @@ -131,7 +131,6 @@ void Demo::update(float dt) } else if (mode == DEMOMODE_PLAYBACK) { - while (frame < frames.size()) { DemoFrame *f = &frames[frame]; diff --git a/Aquaria/Element.cpp b/Aquaria/Element.cpp index 59e86d3..18af377 100644 --- a/Aquaria/Element.cpp +++ b/Aquaria/Element.cpp @@ -127,7 +127,7 @@ void Element::updateEffects(float dt) float magRedSpd = 48; float lerpSpd = 5.0; float wavySz = float(eff->wavy.size()); - for (int i = 0; i < eff->wavy.size(); i++) + for (size_t i = 0; i < eff->wavy.size(); i++) { float weight = float(i)/wavySz; if (eff->wavyFlip) @@ -211,13 +211,13 @@ void Element::setGridFromWavy() { const float w = float(getWidth()); - for (int x = 0; x < xDivs-1; x++) + for (size_t x = 0; x < xDivs-1; x++) { - for (int y = 0; y < yDivs; y++) + for (size_t y = 0; y < yDivs; y++) { const int wavy_y = (yDivs - y)-1; const float tmp = eff->wavy[wavy_y].x / w; - if (wavy_y < eff->wavy.size()) + if (wavy_y < 0 || (size_t) wavy_y < eff->wavy.size()) { drawGrid[x][y].x = tmp - 0.5f; @@ -264,7 +264,7 @@ void Element::setElementEffectByIndex(int eidx) eff->wavy.resize(e.segsy); float bity = float(getHeight())/float(e.segsy); - for (int i = 0; i < eff->wavy.size(); i++) + for (size_t i = 0; i < eff->wavy.size(); i++) { eff->wavy[i] = Vector(0, -(i*bity)); } @@ -300,7 +300,7 @@ void Element::render() renderBorderColor = Vector(0.5,0.5,0.5); if (!dsq->game->sceneEditor.selectedElements.empty()) { - for (int i = 0; i < dsq->game->sceneEditor.selectedElements.size(); i++) + for (size_t i = 0; i < dsq->game->sceneEditor.selectedElements.size(); i++) { if (this == dsq->game->sceneEditor.selectedElements[i]) renderBorderColor = Vector(1,1,1); diff --git a/Aquaria/Element.h b/Aquaria/Element.h index 32422be..267bb7a 100644 --- a/Aquaria/Element.h +++ b/Aquaria/Element.h @@ -63,7 +63,7 @@ public: ~Element(); void destroy(); void update(float dt); - int templateIdx; + size_t templateIdx; int bgLayer; Element *bgLayerNext; void render(); diff --git a/Aquaria/Emote.cpp b/Aquaria/Emote.cpp index 3b0acdf..72e3d4c 100644 --- a/Aquaria/Emote.cpp +++ b/Aquaria/Emote.cpp @@ -45,9 +45,9 @@ void Emote::load(const std::string &file) emoteTimer = 0; } -void Emote::playSfx(int index) +void Emote::playSfx(size_t index) { - if (index < 0 || index >= emotes.size()) return; + if (index >= emotes.size()) return; if (emoteTimer > 0) return; int r = 0; diff --git a/Aquaria/Entity.cpp b/Aquaria/Entity.cpp index bd01331..3b81967 100644 --- a/Aquaria/Entity.cpp +++ b/Aquaria/Entity.cpp @@ -45,7 +45,7 @@ void Entity::setIngredientData(const std::string &name) void Entity::entityDied(Entity *e) { - for (int i = 0; i < targets.size(); i++) + for (size_t i = 0; i < targets.size(); i++) { targets[i] = 0; } @@ -73,7 +73,7 @@ void Entity::generateCollisionMask(int ovrCollideRadius) { if (this->skeletalSprite.isLoaded()) { - for (int i = 0; i < skeletalSprite.bones.size(); i++) + for (size_t i = 0; i < skeletalSprite.bones.size(); i++) { if (skeletalSprite.bones[i]->generateCollisionMask) { @@ -196,7 +196,7 @@ Entity::Entity() dropChance = 0; inCurrent = false; entityProperties.resize(EP_MAX); - for (int i = 0; i < entityProperties.size(); i++) + for (size_t i = 0; i < entityProperties.size(); i++) { entityProperties[i] = false; } @@ -428,7 +428,7 @@ float Entity::followPath(Path *p, float speed, int dir, bool deleteOnEnd) } else { - for (int i = 0; i < p->nodes.size(); i++) + for (size_t i = 0; i < p->nodes.size(); i++) { PathNode pn = p->nodes[i]; position.data->path.addPathNode(pn.position, float(i/float(p->nodes.size()))); @@ -1265,7 +1265,7 @@ bool Entity::updateCurrents(float dt) { if (p->active) { - for (int n = 1; n < p->nodes.size(); n++) + for (size_t n = 1; n < p->nodes.size(); n++) { PathNode *node2 = &p->nodes[n]; PathNode *node1 = &p->nodes[n-1]; @@ -1849,7 +1849,7 @@ void Entity::detachEntity(Entity *e) attachedEntities.clear(); attachedEntitiesOffsets.clear(); - for (int i = 0; i < copyEnts.size(); i++) + for (size_t i = 0; i < copyEnts.size(); i++) { if (copyEnts[i] != e) { @@ -1904,9 +1904,9 @@ int Entity::getNumTargetPoints() return targetPoints.size(); } -Vector Entity::getTargetPoint(int i) +Vector Entity::getTargetPoint(size_t i) { - if (i >= targetPoints.size() || i < 0) + if (i >= targetPoints.size()) return getEnergyShotTargetPosition(); return targetPoints[i]; } @@ -1995,9 +1995,9 @@ Vector Entity::getEnergyShotTargetPosition() return getWorldPosition(); } -bool Entity::isTargetInRange(int range, int t) +bool Entity::isTargetInRange(int range, size_t t) { - if (t < 0 || t >= targets.size()) + if (t >= targets.size()) { std::ostringstream os; os << "isTargetInRange: invalid target index: " << t; @@ -2299,7 +2299,7 @@ bool Entity::canSetState(int state) bool Entity::updateLocalWarpAreas(bool affectAvatar) { - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { Path *p = dsq->game->getPath(i); if (!p->nodes.empty()) @@ -2343,9 +2343,9 @@ void Entity::warpLastPosition() void Entity::spawnParticlesFromCollisionMask(const std::string &p, int intv) { - for (int i = 0; i < skeletalSprite.bones.size(); i++) + for (size_t i = 0; i < skeletalSprite.bones.size(); i++) { - for (int j = 0; j < skeletalSprite.bones[i]->collisionMask.size(); j+=intv) + for (size_t j = 0; j < skeletalSprite.bones[i]->collisionMask.size(); j+=intv) { Vector pos = skeletalSprite.bones[i]->getWorldCollidePosition(skeletalSprite.bones[i]->collisionMask[j]); dsq->spawnParticleEffect(p, pos); @@ -2564,7 +2564,7 @@ void Entity::doSpellAvoidance(float dt, int range, float mod) if (s->isActive() && (s->position - this->position).getSquaredLength2D() < sqr(range)) { - for (int j = 0; j < ignoreShotDamageTypes.size(); j++) + for (size_t j = 0; j < ignoreShotDamageTypes.size(); j++) { if (s->getDamageType() == ignoreShotDamageTypes[j]) { diff --git a/Aquaria/Entity.h b/Aquaria/Entity.h index 2adf03d..b9fb50f 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -181,7 +181,7 @@ public: Entity *findTarget(int dist, int type, int t=0); bool hasTarget(int t=0); - bool isTargetInRange(int range, int t=0); + bool isTargetInRange(int range, size_t t=0); void doGlint(const Vector &position, const Vector &scale=Vector(2,2), const std::string &tex="Glint", RenderObject::BlendTypes bt=BLEND_DEFAULT); Entity *getTargetEntity(int t=0); void setTargetEntity(Entity *e, int t=0); @@ -266,7 +266,7 @@ public: void clearTargetPoints(); void addTargetPoint(const Vector &point); int getNumTargetPoints(); - Vector getTargetPoint(int i); + Vector getTargetPoint(size_t i); int targetPriority; virtual void shiftWorlds(WorldType lastWorld, WorldType worldType){} void setCanLeaveWater(bool v); diff --git a/Aquaria/FlockEntity.cpp b/Aquaria/FlockEntity.cpp index 31c8a32..ebba190 100644 --- a/Aquaria/FlockEntity.cpp +++ b/Aquaria/FlockEntity.cpp @@ -36,13 +36,13 @@ FlockEntity::FlockEntity() : CollideEntity() collideRadius = 8; } -void FlockEntity::addToFlock(int id) +void FlockEntity::addToFlock(size_t id) { if (id >= flocks.size()) { int curSize = flocks.size(); flocks.resize(id+1); - for (int i = curSize; i < id+1; i++) + for (size_t i = curSize; i < id+1; i++) flocks[i] = 0; } if (!flocks[id]) @@ -113,7 +113,7 @@ void FlockEntity::destroy() void FlockEntity::updateFlockData(void) { - for (int flockID = 0; flockID < flocks.size(); flockID++) + for (size_t flockID = 0; flockID < flocks.size(); flockID++) { Flock *flock = flocks[flockID]; if (flock) diff --git a/Aquaria/FlockEntity.h b/Aquaria/FlockEntity.h index aa68f69..9c6ddfe 100644 --- a/Aquaria/FlockEntity.h +++ b/Aquaria/FlockEntity.h @@ -46,7 +46,7 @@ public: FLOCK_FISH = 0, MAX_FLOCKTYPES }; - void addToFlock(int id); + void addToFlock(size_t id); void removeFromFlock(); void destroy(); diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 34ef784..8375b83 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -318,7 +318,7 @@ void Game::transitionToScene(std::string scene) core->enqueueJumpState("Game", false); } -ElementTemplate *Game::getElementTemplateByIdx(int idx) +ElementTemplate *Game::getElementTemplateByIdx(size_t idx) { for (int i = 0; i < elementTemplates.size(); i++) { @@ -330,7 +330,7 @@ ElementTemplate *Game::getElementTemplateByIdx(int idx) return 0; } -Element* Game::createElement(int idx, Vector position, int bgLayer, RenderObject *copy, ElementTemplate *et) +Element* Game::createElement(size_t idx, Vector position, size_t bgLayer, RenderObject *copy, ElementTemplate *et) { if (idx == -1) return 0; @@ -1169,12 +1169,12 @@ void Game::addPath(Path *p) } } -void Game::removePath(int idx) +void Game::removePath(size_t idx) { - if (idx >= 0 && idx < paths.size()) paths[idx]->destroy(); + if (idx < paths.size()) paths[idx]->destroy(); std::vector copy = this->paths; clearPaths(); - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { if (i != idx) addPath(copy[i]); @@ -1377,6 +1377,7 @@ bool Game::loadSceneXML(std::string scene) levelSF->SetAttribute("airSfxLoop", airSfxLoop.c_str()); } if (level->Attribute("bnat")) + { bNatural = atoi(level->Attribute("bnat")); levelSF->SetAttribute("bnat", 1); @@ -2170,7 +2171,6 @@ bool Game::saveScene(std::string scene) std::ostringstream simpleElements[LR_MAX]; std::ostringstream simpleElements_repeatScale[LR_MAX]; - for (i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); @@ -3122,7 +3122,6 @@ void Game::applyState() createPets(); - postInitEntities(); bool musicchanged = updateMusic(); @@ -3813,12 +3812,7 @@ void Game::onPressEscape(int source, InputDevice device) void Game::toggleDamageSprite(bool on) { - if (on) - { - damageSprite->alphaMod = 1; - } - else - damageSprite->alphaMod = 0; + damageSprite->alphaMod = (float) on; } void Game::togglePause(bool v) @@ -3899,14 +3893,14 @@ Bone *Game::collideSkeletalVsCircle(Entity *skeletal, RenderObject *circle) Bone *Game::collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, float radius) { Bone *closest = 0; - for (int i = 0; i < skeletal->skeletalSprite.bones.size(); i++) + for (size_t i = 0; i < skeletal->skeletalSprite.bones.size(); i++) { Bone *b = skeletal->skeletalSprite.bones[i]; // MULTIPLE CIRCLES METHOD if (!b->collisionMask.empty() && b->alpha.x == 1 && b->renderQuad) { - for (int i = 0; i < b->transformedCollisionMask.size(); i++) + for (size_t i = 0; i < b->transformedCollisionMask.size(); i++) { if (isTouchingLine(start, end, b->transformedCollisionMask[i], radius+b->collideRadius)) { @@ -4589,7 +4583,7 @@ void Game::update(float dt) } - int i = 0; + size_t i = 0; for (i = 0; i < dsq->game->getNumPaths(); i++) { dsq->game->getPath(i)->update(dt); @@ -4761,7 +4755,6 @@ void Game::update(float dt) //cameraLerpDelay = 0.15; cameraLerpDelay = vars->defaultCameraLerpDelay; } - Vector oldCamPos = dsq->cameraPos; cameraInterp.stop(); cameraInterp.interpolateTo(dest, cameraLerpDelay); dsq->cameraPos = getCameraPositionFor(cameraInterp); @@ -4924,9 +4917,9 @@ void Game::loadElementTemplates(std::string pack) } in.close(); - for (int i = 0; i < elementTemplates.size(); i++) + for (size_t i = 0; i < elementTemplates.size(); i++) { - for (int j = i; j < elementTemplates.size(); j++) + for (size_t j = i; j < elementTemplates.size(); j++) { if (elementTemplates[i].idx > elementTemplates[j].idx) { @@ -4955,7 +4948,7 @@ void Game::resetFromTitle() void Game::setGrid(ElementTemplate *et, Vector position, float rot360) { - for (int i = 0; i < et->grid.size(); i++) + for (size_t i = 0; i < et->grid.size(); i++) { TileVector t(position); int x = et->grid[i].x; @@ -5067,7 +5060,7 @@ void Game::removeState() dsq->globalScale = Vector(1,1); core->globalScaleChanged(); - for (int i = 0; i < getNumPaths(); i++) + for (size_t i = 0; i < getNumPaths(); i++) { Path *p = getPath(i); p->destroy(); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index ce63864..95640b0 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -125,7 +125,7 @@ public: void setGrid(Vector position); bool cull; float alpha; - int idx; + size_t idx; }; class ObsRow @@ -258,8 +258,9 @@ public: Entity *editingEntity; Path *editingPath; - int selectedIdx; - int selectedNode; + size_t selectedIdx; + size_t selectedNode; + Path *getSelectedPath(); void changeDepth(); void updateEntitySaveData(Entity *editingEntity); @@ -280,7 +281,7 @@ public: SelectedEntity selectedEntity; - int entityPageNum; + size_t entityPageNum; void checkForRebuild(); void createAquarian(); @@ -353,7 +354,7 @@ protected: void mouseButtonLeft(); void mouseButtonRight(); - int curElement, selectedVariation, possibleSelectedIdx; + size_t curElement, selectedVariation, possibleSelectedIdx; Quad *placer; DebugFont *text; @@ -413,7 +414,7 @@ public: InGameMenu *getInGameMenu() { return themenu; } void loadElementTemplates(std::string pack); - Element* createElement(int etidx, Vector position, int bgLayer=0, RenderObject *copy=0, ElementTemplate *et=0); + Element* createElement(size_t etidx, Vector position, size_t bgLayer=0, RenderObject *copy=0, ElementTemplate *et=0); void setGrid(ElementTemplate *et, Vector position, float rot360=0); void updateParticlePause(); @@ -440,7 +441,7 @@ public: std::vector elementTemplates; std::string sceneName, sceneDisplayName; - ElementTemplate *getElementTemplateByIdx(int idx); + ElementTemplate *getElementTemplateByIdx(size_t idx); bool saveScene(std::string scene); @@ -509,10 +510,10 @@ protected: Path *firstPathOfType[PATH_MAX]; public: void addPath(Path *p); - void removePath(int idx); + void removePath(size_t idx); void clearPaths(); - int getNumPaths() const {return paths.size();} - Path *getPath(int idx) const {return paths[idx];} + size_t getNumPaths() const {return paths.size();} + Path *getPath(size_t idx) const {return paths[idx];} Path *getFirstPathOfType(PathType type) const {return firstPathOfType[type];} Path *getPathByName(std::string name); int getIndexOfPath(Path *p); diff --git a/Aquaria/GameStructs.h b/Aquaria/GameStructs.h index 217e130..d74ef53 100644 --- a/Aquaria/GameStructs.h +++ b/Aquaria/GameStructs.h @@ -147,7 +147,7 @@ class Emote public: Emote(); void load(const std::string &file); - void playSfx(int index); + void playSfx(size_t index); void update(float dt); float emoteTimer; @@ -159,7 +159,7 @@ public: struct IngredientEffect { - IngredientEffect() : type(IET_NONE), magnitude(0) {} + IngredientEffect() : magnitude(0), type(IET_NONE) {} float magnitude; IngredientEffectType type; std::string string; diff --git a/Aquaria/GridRender.cpp b/Aquaria/GridRender.cpp index 0966171..0548097 100644 --- a/Aquaria/GridRender.cpp +++ b/Aquaria/GridRender.cpp @@ -123,7 +123,7 @@ SongLineRender::SongLineRender() void SongLineRender::newPoint(const Vector &pt, const Vector &color) { - int maxx = 40; + size_t maxx = 40; bool inRange = true; if (pts.size() > 1) inRange = (pt - pts[pts.size()-2].pt).isLength2DIn(4); @@ -156,10 +156,10 @@ void SongLineRender::onRender() if (ls < 0) ls = 1; glLineWidth(ls); - const int alphaLine = pts.size()*(0.9f); + const unsigned int alphaLine = pts.size()*(0.9f); float a = 1; glBegin(GL_LINE_STRIP); - for (int i = 0; i < pts.size(); i++) + for (size_t i = 0; i < pts.size(); i++) { if (i < alphaLine) a = float(i)/float(alphaLine); diff --git a/Aquaria/Hair.cpp b/Aquaria/Hair.cpp index d095373..c72c8b5 100644 --- a/Aquaria/Hair.cpp +++ b/Aquaria/Hair.cpp @@ -35,7 +35,7 @@ Hair::Hair(int nodes, float segmentLength, float hairWidth) : RenderObject() hairNodes.resize(nodes); - for (int i = 0; i < hairNodes.size(); i++) + for (size_t i = 0; i < hairNodes.size(); i++) { float perc = (float(i)/(float(hairNodes.size()))); if (perc < 0) @@ -81,7 +81,7 @@ void Hair::onRender() float texBits = 1.0f / (hairNodes.size()-1); Vector pl, pr; - for (int i = 0; i < hairNodes.size(); i++) + for (size_t i = 0; i < hairNodes.size(); i++) { @@ -122,7 +122,7 @@ void Hair::updatePositions() BBGE_PROF(Hair_updatePositions); - for (int i = 1; i < hairNodes.size(); i++) + for (size_t i = 1; i < hairNodes.size(); i++) { Vector diff = hairNodes[i].position - hairNodes[i-1].position; @@ -149,7 +149,7 @@ void Hair::updatePositions() void Hair::returnToDefaultPositions(float dt) { - for (int i = 0; i < hairNodes.size(); i++) + for (size_t i = 0; i < hairNodes.size(); i++) { Vector mov = hairNodes[i].defaultPosition - hairNodes[i].position; if (!mov.isLength2DIn(2)) diff --git a/Aquaria/InGameMenu.cpp b/Aquaria/InGameMenu.cpp index c84d6e1..189b5f7 100644 --- a/Aquaria/InGameMenu.cpp +++ b/Aquaria/InGameMenu.cpp @@ -24,10 +24,9 @@ std::vector petSlots; static const float MENUPAGETRANSTIME = 0.2; const Vector menuBgScale(800.0f/1024.0f, 800.0f/1024.0f); -const int foodPageSize = 16; -const int treasurePageSize = 16; -const int ITEMS_PER_PAGE = 12; -const int numTreasures = 16*2; +const size_t foodPageSize = 16; +const size_t treasurePageSize = 16; +const size_t numTreasures = 16*2; const Vector worldLeftCenter(217,250), worldRightCenter(575, 250); const Vector opt_save_original = Vector(350, 350), opt_cancel_original = Vector(450, 350); @@ -107,7 +106,7 @@ protected: class FoodHolder : public Quad { public: - FoodHolder(int slot, bool trash=false); + FoodHolder(size_t slot, bool trash=false); bool isValid() const; void toggleValid(bool b); @@ -125,7 +124,7 @@ protected: Quad *lid; - int slot; + size_t slot; private: IngredientData *foodHolderIngredient; }; @@ -232,7 +231,7 @@ void PetSlot::onUpdate(float dt) } } -FoodHolder::FoodHolder(int slot, bool trash) : Quad(), slot(slot), trash(trash) +FoodHolder::FoodHolder(size_t slot, bool trash) : Quad(), trash(trash), slot(slot) { foodHolderIngredient = 0; buttonDown = false; @@ -4265,7 +4264,6 @@ void InGameMenu::nextJoystick() int i = as.joystickID; Joystick *j = NULL; const int N = core->getNumJoysticks(); - bool looped = false; do { ++i; diff --git a/Aquaria/InGameMenu.h b/Aquaria/InGameMenu.h index d178034..10fe01b 100644 --- a/Aquaria/InGameMenu.h +++ b/Aquaria/InGameMenu.h @@ -51,8 +51,8 @@ struct RecipeMenu void destroyPage(); void goNextPage(); void goPrevPage(); - int getNumPages(); - int getNumKnown(); + size_t getNumPages(); + size_t getNumKnown(); int currentPage; diff --git a/Aquaria/Intro.cpp b/Aquaria/Intro.cpp index eed82f2..5cbb09d 100644 --- a/Aquaria/Intro.cpp +++ b/Aquaria/Intro.cpp @@ -32,7 +32,7 @@ namespace IntroStuff { //Mappy *m; bool quitFlag; -}; +} using namespace IntroStuff; @@ -201,7 +201,7 @@ void Intro::createMeteor(int layer, Vector pos, Vector off, Vector sz) void Intro::clearMeteors() { - for (int i = 0; i < meteors.size(); i++) + for (size_t i = 0; i < meteors.size(); i++) { meteors[i]->setLife(1); meteors[i]->setDecayRate(100); @@ -258,7 +258,7 @@ void Intro::update(float dt) citybg->offset = Vector(-100, 0); citybg->scale = Vector(0.6, 0.6); citybg->alpha = 0; - for (int i = 0; i < citybg->bones.size(); i++) + for (size_t i = 0; i < citybg->bones.size(); i++) { if (citybg->bones[i]->name != "meteor") { @@ -275,7 +275,7 @@ void Intro::update(float dt) eric->position = Vector(50, 400); eric->alpha = 0; eric->scale = Vector(0.4, 0.4); - for (int i = 0; i < eric->bones.size(); i++) + for (size_t i = 0; i < eric->bones.size(); i++) { eric->bones[i]->color = eric->color; } diff --git a/Aquaria/MiniMapRender.cpp b/Aquaria/MiniMapRender.cpp index 8e90a99..f11e51c 100644 --- a/Aquaria/MiniMapRender.cpp +++ b/Aquaria/MiniMapRender.cpp @@ -403,7 +403,7 @@ void MiniMapRender::onUpdate(float dt) if (!dsq->game->worldMapRender->isOn()) { - for (int i = 0; i < buttons.size(); i++) + for (size_t i = 0; i < buttons.size(); i++) { if ((buttons[i]->getWorldPosition() - core->mouse.position).isLength2DIn(BUTTON_RADIUS)) { @@ -596,7 +596,7 @@ void MiniMapRender::onRender() if (!radarHide) { - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { Path *p = dsq->game->getPath(i); if (!p->nodes.empty() && p->minimapIcon) diff --git a/Aquaria/ModDownloader.cpp b/Aquaria/ModDownloader.cpp index 8b0bc02..4210750 100644 --- a/Aquaria/ModDownloader.cpp +++ b/Aquaria/ModDownloader.cpp @@ -310,14 +310,13 @@ bool ModDL::ParseModXML(const std::string& fn, bool allowChaining) ModPackageType pkgtype = MPT_MOD; int serverSize = 0; int serverIconSize = 0; - XMLElement *fullname, *desc, *icon, *pkg, *confirm, *props, *web; + XMLElement *fullname, *desc, *icon, *pkg, *confirm, *props; fullname = modx->FirstChildElement("Fullname"); desc = modx->FirstChildElement("Description"); icon = modx->FirstChildElement("Icon"); pkg = modx->FirstChildElement("Package"); confirm = modx->FirstChildElement("Confirm"); props = modx->FirstChildElement("Properties"); - web = modx->FirstChildElement("Web"); if(fullname && fullname->Attribute("text")) namestr = fullname->Attribute("text"); diff --git a/Aquaria/ModSelector.cpp b/Aquaria/ModSelector.cpp index 562c50c..5e4fed3 100644 --- a/Aquaria/ModSelector.cpp +++ b/Aquaria/ModSelector.cpp @@ -131,7 +131,7 @@ void ModSelectorScreen::onUpdate(float dt) } } -void ModSelectorScreen::showPanel(int id) +void ModSelectorScreen::showPanel(size_t id) { if(id == currentPanel) return; @@ -140,7 +140,7 @@ void ModSelectorScreen::showPanel(int id) IconGridPanel *newgrid = panels[id]; // fade in selected panel - if(currentPanel < 0) // just bringing up? + if(currentPanel == -1) // just bringing up? { newgrid->scale = Vector(0.8f,0.8f); newgrid->alpha = 0; @@ -155,7 +155,7 @@ void ModSelectorScreen::updateFade() { // fade out background panels // necessary to do all of them, that icon alphas are 0... they would trigger otherwise, even if invisible because parent panel is not shown - for(int i = 0; i < panels.size(); ++i) + for(size_t i = 0; i < panels.size(); ++i) panels[i]->fade(i == currentPanel, true); } @@ -206,7 +206,7 @@ void ModSelectorScreen::init() addChild(&rightbar, PM_STATIC); } - for(int i = 0; i < panels.size(); ++i) + for(size_t i = 0; i < panels.size(); ++i) { if(panels[i]) continue; @@ -326,7 +326,7 @@ void ModSelectorScreen::initModAndPatchPanel() } std::sort(tv.begin(), tv.end(), _modname_cmp); - for(int i = 0; i < tv.size(); ++i) + for(size_t i = 0; i < tv.size(); ++i) { if(!tv[i]->getParent()) // ensure it was not added earlier { diff --git a/Aquaria/ModSelector.h b/Aquaria/ModSelector.h index 526e14f..8b73e2e 100644 --- a/Aquaria/ModSelector.h +++ b/Aquaria/ModSelector.h @@ -148,7 +148,7 @@ public: void init(); void close(); - void showPanel(int id); + void showPanel(size_t id); void updateFade(); void initModAndPatchPanel(); @@ -172,7 +172,7 @@ protected: virtual void onUpdate(float dt); MenuIconBar leftbar; MenuBasicBar rightbar; - int currentPanel; + size_t currentPanel; BitmapText subtext; Quad subbox; float subFadeT; diff --git a/Aquaria/Network.h b/Aquaria/Network.h index a96a708..6edf53b 100644 --- a/Aquaria/Network.h +++ b/Aquaria/Network.h @@ -37,8 +37,7 @@ namespace Network void download(RequestData *rq); void update(); void shutdown(); -}; - +} #endif diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index 9dca68e..225e6b2 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -85,9 +85,9 @@ void Path::clampPosition(Vector *pos, float radius) } } -PathNode *Path::getPathNode(int idx) +PathNode *Path::getPathNode(size_t idx) { - if (idx < 0 || idx >= nodes.size()) return 0; + if (idx >= nodes.size()) return 0; return &nodes[idx]; } @@ -661,30 +661,30 @@ void Path::activate(Entity *e) } } -void Path::removeNode(int idx) +void Path::removeNode(size_t idx) { std::vector copy = nodes; nodes.clear(); - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { if (idx != i) nodes.push_back(copy[i]); } } -void Path::addNode(int idx) +void Path::addNode(size_t idx) { std::vector copy = nodes; nodes.clear(); bool added = false; - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { nodes.push_back(copy[i]); if (idx == i) { added = true; PathNode p; - int j = i + 1; + size_t j = i + 1; if (j < copy.size()) { Vector add = copy[j].position - copy[i].position; diff --git a/Aquaria/Path.h b/Aquaria/Path.h index 3e68f20..f445733 100644 --- a/Aquaria/Path.h +++ b/Aquaria/Path.h @@ -87,14 +87,14 @@ public: std::string name; // full node string std::string label; // first part only (the actual node name) std::vectornodes; - void removeNode(int idx); - void addNode(int idx); + void removeNode(size_t idx); + void addNode(size_t idx); void update(float dt); void setActive(bool v); bool action(int id, int state, int source, InputDevice device); void setEmitter(const std::string& name); - PathNode *getPathNode(int idx); + PathNode *getPathNode(size_t idx); bool isCoordinateInside(const Vector &pos, int rad=0); void reverseNodes(); diff --git a/Aquaria/PathFinding.cpp b/Aquaria/PathFinding.cpp index f9c10a1..fa43d38 100644 --- a/Aquaria/PathFinding.cpp +++ b/Aquaria/PathFinding.cpp @@ -67,11 +67,11 @@ void PathFinding::forceMinimumPath(VectorPath &path, const Vector &start, const void PathFinding::molestPath(VectorPath &path) { - int sz=path.getNumPathNodes(); + size_t sz=path.getNumPathNodes(); if(!sz) return; - int i = 0; + size_t i = 0; // make normals std::vector normals; normals.resize(sz); @@ -108,8 +108,11 @@ void PathFinding::molestPath(VectorPath &path) // use wall normal to push out node a bit std::vector newNormals; newNormals.resize(normals.size()); - for (i = 1; i < normals.size()-1; i++) - newNormals[i] = (normals[i] + normals[i-1] + normals[i+1])/3.0f; + if(normals.size() > 0) { + for (i = 1; i < normals.size()-1; i++) { + newNormals[i] = (normals[i] + normals[i-1] + normals[i+1])/3.0f; + } + } for (i = 1; i < sz-1; i++) path.getPathNode(i)->value += newNormals[i]; @@ -132,7 +135,7 @@ void PathFinding::molestPath(VectorPath &path) lastSuccessNode = 0; hadSuccess = false; Vector node = path.getPathNode(i)->value; - for (int j = sz-1; j >= i+adjust; j--) + for (size_t j = sz-1; j >= i+adjust; j--) { Vector target = path.getPathNode(j)->value; if (dsq->game->trace(node, target)) diff --git a/Aquaria/PathFinding.h b/Aquaria/PathFinding.h index 4366a89..6965cee 100644 --- a/Aquaria/PathFinding.h +++ b/Aquaria/PathFinding.h @@ -48,7 +48,7 @@ namespace PathFinding bool finishFindPath(State *state, VectorPath& path, unsigned step = 0); void getStats(State *state, unsigned& stepsDone, unsigned& nodesExpanded); void purgeFindPath(PathFinding::State *state); -}; +} #endif diff --git a/Aquaria/PathRender.cpp b/Aquaria/PathRender.cpp index 1582586..aeabcd1 100644 --- a/Aquaria/PathRender.cpp +++ b/Aquaria/PathRender.cpp @@ -32,11 +32,11 @@ PathRender::PathRender() : RenderObject() void PathRender::onRender() { - const int pathcount = dsq->game->getNumPaths(); - if (pathcount <= 0) + const size_t pathcount = dsq->game->getNumPaths(); + if (pathcount == 0) return; - for (int i = 0; i < pathcount; i++) + for (size_t i = 0; i < pathcount; i++) { Path *p = dsq->game->getPath(i); #ifdef AQUARIA_BUILD_SCENEEDITOR @@ -47,7 +47,7 @@ void PathRender::onRender() glColor4f(1, 0.5, 0.5, 0.75); glBegin(GL_LINES); - for (int n = 0; n < p->nodes.size()-1; n++) + for (size_t n = 0; n < p->nodes.size()-1; n++) { PathNode *nd = &p->nodes[n]; PathNode *nd2 = &p->nodes[n+1]; @@ -56,7 +56,7 @@ void PathRender::onRender() } glEnd(); - for (int n = 0; n < p->nodes.size(); n++) + for (size_t n = 0; n < p->nodes.size(); n++) { PathNode *nd = &p->nodes[n]; diff --git a/Aquaria/RecipeMenuEntry.cpp b/Aquaria/RecipeMenuEntry.cpp index d49dfc0..cd1038f 100644 --- a/Aquaria/RecipeMenuEntry.cpp +++ b/Aquaria/RecipeMenuEntry.cpp @@ -73,20 +73,22 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe equals->scale = Vector(0.7, 0.7); addChild(equals, PM_POINTER); - int c = 0; + size_t c = 0; - int size=0; + size_t size=0; - for (int i = 0; i < recipe->names.size(); i++) + for (size_t i = 0; i < recipe->names.size(); i++) size += recipe->names[i].amount; - for (int j = 0; j < recipe->types.size(); j++) + for (size_t j = 0; j < recipe->types.size(); j++) size += recipe->types[j].amount; - size --; + if(size > 0) { + size --; + } - for (int i = 0; i < recipe->names.size(); i++) + for (size_t i = 0; i < recipe->names.size(); i++) { debugLog("recipe name: " + recipe->names[i].name); IngredientData *data = dsq->continuity.getIngredientDataByName(recipe->names[i].name); @@ -122,7 +124,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe } } - for (int i = 0; i < recipe->types.size(); i++) + for (size_t i = 0; i < recipe->types.size(); i++) { for (int j = 0; j < recipe->types[i].amount; j++) @@ -188,7 +190,7 @@ void RecipeMenuEntry::onUpdate(float dt) std::ostringstream ds; - for (int i = 0; i < data->effects.size(); i++) + for (size_t i = 0; i < data->effects.size(); i++) { ds << dsq->continuity.getIEString(data, i); if (i == data->effects.size()-1) @@ -212,9 +214,9 @@ void RecipeMenuEntry::onUpdate(float dt) glow->alphaMod = 0; selected = 0; - int n=0; + size_t n=0; - for (int i = 0; i < recipeMenu.recipeMenuEntries.size(); i++) + for (size_t i = 0; i < recipeMenu.recipeMenuEntries.size(); i++) { if (!recipeMenu.recipeMenuEntries[i]->selected) n++; @@ -252,10 +254,10 @@ void RecipeMenu::slide(RenderObject *r, bool in, float t) } } -int RecipeMenu::getNumKnown() +size_t RecipeMenu::getNumKnown() { - int num = 0; - for (int i = 0; i < dsq->continuity.recipes.size(); i++) + size_t num = 0; + for (size_t i = 0; i < dsq->continuity.recipes.size(); i++) { if (dsq->continuity.recipes[i].isKnown()) { @@ -265,10 +267,10 @@ int RecipeMenu::getNumKnown() return num; } -int RecipeMenu::getNumPages() +size_t RecipeMenu::getNumPages() { - int numKnown = dsq->continuity.recipes.size(); - int numPages = (numKnown/pageSize); + size_t numKnown = dsq->continuity.recipes.size(); + size_t numPages = (numKnown/pageSize); @@ -436,7 +438,7 @@ void RecipeMenu::createPage(int p) void RecipeMenu::destroyPage() { - for (int i = 0; i < recipeMenuEntries.size(); i++) + for (size_t i = 0; i < recipeMenuEntries.size(); i++) { recipeMenuEntries[i]->setLife(1); recipeMenuEntries[i]->setDecayRate(20); diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index fb9b7e3..2577b7b 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -94,6 +94,7 @@ std::string getMapTemplateFilename() return ""; } + SceneEditor::SceneEditor() : ActionMapper(), on(false) { autoSaveFile = 0; @@ -448,7 +449,7 @@ void SceneEditor::openMainMenu() void SceneEditor::closeMainMenu() { inMainMenu = false; - for (int i = 0; i < mainMenu.size(); i++) + for (size_t i = 0; i < mainMenu.size(); i++) { mainMenu[i]->alpha = 0; mainMenu[i]->safeKill(); @@ -709,7 +710,7 @@ void SceneEditor::createAquarian() std::string t = dsq->getUserInputString("Enter Aquarian:", ""); stringToUpper(t); Vector startPos = dsq->getGameCursorPosition(); - for (int i = 0; i < t.size(); i++) + for (size_t i = 0; i < t.size(); i++) { int v = 0; if (t[i] >= 'A' && t[i] <= 'Z') @@ -728,7 +729,7 @@ void SceneEditor::createAquarian() Path *SceneEditor::getSelectedPath() { - if (selectedIdx >= 0 && selectedIdx < dsq->game->getNumPaths()) + if (selectedIdx < dsq->game->getNumPaths()) { return dsq->game->getPath(selectedIdx); } @@ -789,7 +790,7 @@ void SceneEditor::reversePath() void SceneEditor::setGridPattern(int gi) { if (selectedElements.size()) - for (int i = 0; i < selectedElements.size(); ++i) + for (size_t i = 0; i < selectedElements.size(); ++i) selectedElements[i]->setElementEffectByIndex(gi); else if (editingElement) editingElement->setElementEffectByIndex(gi); @@ -833,7 +834,7 @@ void SceneEditor::moveToFront() dsq->clearElements(); // move to the foreground ... this means that the editing element should be last in the list (Added last) - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { if (copy[i] != editingElement) dsq->addElement(copy[i]); @@ -853,7 +854,7 @@ void SceneEditor::moveToBack() // move to the background ... this means that the editing element should be first in the list (Added first) dsq->addElement(editingElement); - for (int i = 0; i < copy.size(); i++) + for (size_t i = 0; i < copy.size(); i++) { if (copy[i] != editingElement) dsq->addElement(copy[i]); @@ -959,7 +960,7 @@ void SceneEditor::deleteSelected() { if (selectedElements.size()>0) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->safeKill(); dsq->removeElement(selectedElements[i]); @@ -1049,7 +1050,7 @@ void SceneEditor::checkForRebuild() if (editType == ET_ELEMENTS && state != ES_SELECTING && !selectedElements.empty()) { bool rebuild = false; - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { if (selectedElements[i]->elementFlag == EF_SOLID || selectedElements[i]->elementFlag == EF_HURT) { @@ -1072,7 +1073,7 @@ void SceneEditor::exitMoveState() { if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position = selectedElements[i]->getWorldPosition(); dummy.removeChild(selectedElements[i]); @@ -1094,7 +1095,7 @@ void SceneEditor::enterMoveState() dummy.rotation = Vector(0,0,0); cursorOffset = dsq->getGameCursorPosition(); groupCenter = getSelectedElementsCenter(); - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position -= groupCenter; dummy.addChild(selectedElements[i], PM_NONE); @@ -1142,7 +1143,7 @@ void SceneEditor::enterRotateState() oldRotation = dummy.rotation; cursorOffset = dsq->getGameCursorPosition(); groupCenter = getSelectedElementsCenter(); - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position -= groupCenter; dummy.addChild(selectedElements[i], PM_NONE); @@ -1175,7 +1176,7 @@ void SceneEditor::enterScaleState() oldRepeatScale = Vector(1, 1); // not handled for multi-selection cursorOffset = dsq->getGameCursorPosition(); groupCenter = getSelectedElementsCenter(); - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position -= groupCenter; dummy.addChild(selectedElements[i], PM_NONE); @@ -1258,7 +1259,7 @@ void SceneEditor::mouseButtonRightUp() { if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position = selectedElements[i]->getWorldPosition(); selectedElements[i]->rotation = selectedElements[i]->getAbsoluteRotation(); @@ -1272,7 +1273,7 @@ void SceneEditor::mouseButtonRightUp() if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->position = selectedElements[i]->getWorldPosition(); selectedElements[i]->scale = selectedElements[i]->scale * dummy.scale; @@ -1388,7 +1389,7 @@ void SceneEditor::mouseButtonLeft() { Path *p = getSelectedPath(); editingPath = p; - if (p && selectedNode >= 0 && selectedNode < p->nodes.size()) + if (p && selectedNode < p->nodes.size()) { if (core->getShiftState()) { @@ -1496,12 +1497,12 @@ public: int rows; }; -bool getGrassPixel(pngRawInfo *png, int x, int y) +bool getGrassPixel(pngRawInfo *png, size_t x, size_t y) { - if (x >= png->Width || y >= png->Height || x < 0 || y < 0) return false; + if (x >= png->Width || y >= png->Height) return false; - int c = (y*png->Width)*png->Components + x*png->Components; + size_t c = (y*png->Width)*png->Components + x*png->Components; if (png->Data[c] == 128 && png->Data[c+1] == 255 && png->Data[c+2] == 128) @@ -1538,7 +1539,7 @@ void SceneEditor::skinLevel() void SceneEditor::skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int maxY) { std::vector deleteElements; - int i = 0; + size_t i = 0; for (i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); @@ -1595,7 +1596,7 @@ void SceneEditor::skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int m offset.z = 0; bool skip = false; - for (int i = 0; i < dsq->getNumElements(); i++) + for (size_t i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); if (e->templateIdx <= 4 && e->templateIdx >= 1) @@ -1612,7 +1613,7 @@ void SceneEditor::skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int m { std::vector cantUse; cantUse.resize(4); - int i = 0; + size_t i = 0; for (i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); @@ -1624,10 +1625,10 @@ void SceneEditor::skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int m } } } - int useIdx = rand()%cantUse.size()+1; + size_t useIdx = rand()%cantUse.size()+1; for (i = 0; i < cantUse.size(); i++) { - int check = i + idxCount; + size_t check = i + idxCount; if (check >= cantUse.size()) check -= cantUse.size(); if (cantUse[check]<=0) @@ -1648,7 +1649,7 @@ void SceneEditor::skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int m } } } - for (int i = 0; i < dsq->getNumElements(); i++) + for (size_t i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); if (e->bgLayer == 4 && e->templateIdx >= 1 && e->templateIdx <= 4) @@ -1667,7 +1668,7 @@ void SceneEditor::generateLevel() - int maxX=0, maxY=0; + size_t maxX=0, maxY=0; const int YELLOW=0, RED=1, GREEN=2, BLUE=3, PURPLE=4, ORANGE=5, BROWN=6, MAX=7; int firstColorX[MAX], firstColorY[MAX]; int lastColorX[MAX], lastColorY[MAX]; @@ -1700,7 +1701,7 @@ void SceneEditor::generateLevel() int scale = TILE_SIZE; int c = 0; - for (int y = 0; y < rawinfo.Height; y++) + for (size_t y = 0; y < rawinfo.Height; y++) { Vector lastElement; lastElement = Vector(0,0,0); @@ -1709,7 +1710,7 @@ void SceneEditor::generateLevel() Row row; rowCount = 0; positions.clear(); - for (int x = 0; x < rawinfo.Width; x++) + for (size_t x = 0; x < rawinfo.Width; x++) { Vector *e = 0; if @@ -1807,7 +1808,7 @@ void SceneEditor::generateLevel() } dsq->game->clearObsRows(); - int i = 0; + size_t i = 0; for (i = 0; i < rows.size(); i++) { int w = rows[i].x2 - rows[i].x1; @@ -1893,7 +1894,7 @@ void SceneEditor::moveElementToLayer(Element *e, int bgLayer) { if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { Element *e = selectedElements[i]; core->removeRenderObject(e, Core::DO_NOT_DESTROY_RENDER_OBJECT); @@ -1945,7 +1946,7 @@ void SceneEditor::updateMultiSelect() selectedElements.clear(); - for (int i = 0; i < dsq->getNumElements(); i++) + for (size_t i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); if (e->bgLayer == bgLayer && e->position.x >= p1.x && e->position.y >= p1.y && e->position.x <= p2.x && e->position.y <= p2.y) @@ -2100,7 +2101,7 @@ void destroyEntityPage() se_grad->fadeAlphaWithLife = 1; se_grad = 0; } - for (int i = 0; i < qs.size(); i++) + for (size_t i = 0; i < qs.size(); i++) { qs[i]->safeKill(); } @@ -2129,7 +2130,7 @@ void createEntityPage() EntityGroup &group = game->entityGroups[game->sceneEditor.entityPageNum]; - for (int i = 0; i < group.entities.size(); i++) + for (size_t i = 0; i < group.entities.size(); i++) { EntityGroupEntity ent = group.entities[i]; EntityClass *ec = dsq->game->getEntityClassForEntityType(ent.name); @@ -2140,7 +2141,7 @@ void createEntityPage() int type = -1; if (ec) { - int j=0; + size_t j=0; for (j = 0; j < dsq->game->entityTypeList.size(); j++) { if (ec->idx == dsq->game->entityTypeList[j].idx) @@ -2197,7 +2198,7 @@ void nextEntityPage() void prevEntityPage() { game->sceneEditor.entityPageNum--; - if (game->sceneEditor.entityPageNum < 0) + if (game->sceneEditor.entityPageNum >= game->entityGroups.size()) game->sceneEditor.entityPageNum = game->entityGroups.size()-1; createEntityPage(); @@ -2265,9 +2266,9 @@ void SceneEditor::updateEntityPlacer() Element* SceneEditor::cycleElementNext(Element *e1) { - int ce = e1->templateIdx; + size_t ce = e1->templateIdx; int idx=0; - for (int i = 0; i < dsq->game->elementTemplates.size(); i++) + for (size_t i = 0; i < dsq->game->elementTemplates.size(); i++) { if (dsq->game->elementTemplates[i].idx == ce) idx = i; @@ -2289,9 +2290,9 @@ Element* SceneEditor::cycleElementNext(Element *e1) Element* SceneEditor::cycleElementPrev(Element *e1) { - int ce = e1->templateIdx; - int idx=0; - for (int i = 0; i < dsq->game->elementTemplates.size(); i++) + size_t ce = e1->templateIdx; + size_t idx=0; + for (size_t i = 0; i < dsq->game->elementTemplates.size(); i++) { if (dsq->game->elementTemplates[i].idx == ce) { @@ -2301,7 +2302,7 @@ Element* SceneEditor::cycleElementPrev(Element *e1) } ce = idx; ce--; - if (ce < 0) + if (ce == -1) ce = dsq->game->elementTemplates.size()-1; idx = dsq->game->elementTemplates[ce].idx; if (idx < 1024) @@ -2339,7 +2340,7 @@ void SceneEditor::nextElement() { if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i]->rotation.z = 0; } @@ -2351,7 +2352,7 @@ void SceneEditor::nextElement() } else if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i] = cycleElementNext(selectedElements[i]); } @@ -2399,7 +2400,7 @@ void SceneEditor::prevElement() if (dsq->game->elementTemplates.empty()) return; if (!selectedElements.empty()) { - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { selectedElements[i] = cycleElementPrev(selectedElements[i]); } @@ -2418,13 +2419,17 @@ void SceneEditor::prevElement() void SceneEditor::doPrevElement() { - int oldCur = curElement; - curElement--; - if (curElement < 0) - curElement = dsq->game->elementTemplates.size()-1; + size_t oldCur = curElement; - if (curElement < 0) + if(dsq->game->elementTemplates.size() == 0) { return; + } + + if(curElement > 0) { + curElement--; + } + if (curElement >= game->elementTemplates.size()) + curElement = dsq->game->elementTemplates.size()-1; if (dsq->game->elementTemplates[curElement].idx < 1024) { @@ -2446,7 +2451,7 @@ void SceneEditor::moveLayer() is >> fromLayer >> toLayer; toLayer--; fromLayer--; - for (int i = 0; i < dsq->getNumElements(); i++) + for (size_t i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); if (e) @@ -2486,8 +2491,8 @@ void SceneEditor::selectEnd() if (dsq->game->elementTemplates.empty()) return; if (!editingElement) { - int largest = 0; - for (int i = 0; i < dsq->game->elementTemplates.size(); i++) + size_t largest = 0; + for (size_t i = 0; i < dsq->game->elementTemplates.size(); i++) { ElementTemplate et = dsq->game->elementTemplates[i]; if (et.idx < 1024 && i > largest) @@ -2551,7 +2556,7 @@ void SceneEditor::cloneSelectedElement() { std::vectorcopy; Vector groupCenter = this->getSelectedElementsCenter(); - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { Element *e1 = selectedElements[i]; Vector dist = e1->position - groupCenter; @@ -2751,7 +2756,7 @@ void SceneEditor::updateText() Vector SceneEditor::getSelectedElementsCenter() { Vector c; - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) { c += selectedElements[i]->position; } @@ -2880,9 +2885,12 @@ void SceneEditor::update(float dt) selectedIdx = -1; selectedNode = -1; float smallestDist = sqr(64); - for (int i = 0; i < dsq->game->getNumPaths(); i++) + for (size_t i = 0; i < dsq->game->getNumPaths(); i++) { - for (int n = dsq->game->getPath(i)->nodes.size()-1; n >=0; n--) + if(dsq->game->getPath(i)->nodes.size() == 0) { + continue; + } + for (size_t n = dsq->game->getPath(i)->nodes.size(); n-- > 0; ) { Vector v = dsq->game->getPath(i)->nodes[n].position - dsq->getGameCursorPosition(); float dist = v.getSquaredLength2D(); @@ -2917,8 +2925,7 @@ void SceneEditor::update(float dt) } break; case ES_MOVING: - if (selectedIdx >= 0) - dsq->game->getPath(selectedIdx)->nodes[selectedNode].position = dsq->getGameCursorPosition() + cursorOffset; + dsq->game->getPath(selectedIdx)->nodes[selectedNode].position = dsq->getGameCursorPosition() + cursorOffset; break; case ES_ROTATING: case ES_MAX: @@ -2964,7 +2971,7 @@ void SceneEditor::update(float dt) case ES_SELECTING: { float closest = sqr(800); - int idx = -1, i = 0; + size_t i = 0; for (i = 0; i < dsq->getNumElements(); i++) { Vector dist = dsq->getElement(i)->getFollowCameraPosition() - dsq->getGameCursorPosition(); @@ -2972,7 +2979,6 @@ void SceneEditor::update(float dt) if (len < closest) { closest = len; - idx = i; } } } @@ -3075,7 +3081,7 @@ void SceneEditor::update(float dt) dummy.scale.y = MIN_SIZE; } - for (int i = 0; i < selectedElements.size(); i++) + for (size_t i = 0; i < selectedElements.size(); i++) selectedElements[i]->refreshRepeatTextureToFill(); } else if (editingElement) diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 4fdecfb..3331cfb 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -940,8 +940,8 @@ luaFunc(getInterfaceFunctionNames) #define MakeTypeCheckFunc(fname, ty) luaFunc(fname) \ { ScriptObject *r = (ScriptObject*)lua_touserdata(L, 1); luaReturnBool(r ? r->isType(ty) : false); } -MakeTypeCheckFunc(isNode, SCO_PATH); -MakeTypeCheckFunc(isObject, SCO_RENDEROBJECT); +MakeTypeCheckFunc(isNode, SCO_PATH) +MakeTypeCheckFunc(isObject, SCO_RENDEROBJECT) MakeTypeCheckFunc(isEntity, SCO_ENTITY) MakeTypeCheckFunc(isScriptedEntity, SCO_SCRIPTED_ENTITY) MakeTypeCheckFunc(isBone, SCO_BONE) @@ -2576,7 +2576,8 @@ static size_t _shotFilter(lua_State *L) { if (dt == DT_NONE || s->getDamageType() == dt) { - if (skipRadiusCheck || (distsq = (s->position - p).getSquaredLength2D()) <= sqrRadius) + distsq = (s->position - p).getSquaredLength2D(); + if (skipRadiusCheck || distsq <= sqrRadius) { filteredShots.push_back(std::make_pair(s, distsq)); ++added; @@ -6083,7 +6084,7 @@ luaFunc(entity_setVel2Len) if(e) e->vel2.setLength2D(lua_tonumber(L, 2)); luaReturnNil(); -}; +} luaFunc(entity_getVel2) { @@ -7600,7 +7601,7 @@ luaFunc(entity_getNearestBoneToPosition) Bone *closest = 0; if (me) { - for (int i = 0; i < me->skeletalSprite.bones.size(); i++) + for (size_t i = 0; i < me->skeletalSprite.bones.size(); i++) { Bone *b = me->skeletalSprite.bones[i]; float dist = (b->getWorldPosition() - p).getSquaredLength2D(); @@ -8455,7 +8456,7 @@ luaFunc(pickupGem) luaFunc(setGemPosition) { - int gemId = lua_tointeger(L, 1); + size_t gemId = lua_tointeger(L, 1); std::string mapname = getString(L, 4); if(mapname.empty()) mapname = dsq->game->sceneName; @@ -8466,7 +8467,7 @@ luaFunc(setGemPosition) if(tile) { pos = dsq->game->worldMapRender->getWorldToTile(tile, pos, true, true); - if(gemId >= 0 && gemId < dsq->continuity.gems.size()) + if(gemId < dsq->continuity.gems.size()) { Continuity::Gems::iterator it = dsq->continuity.gems.begin(); std::advance(it, gemId); @@ -8489,10 +8490,10 @@ luaFunc(setGemPosition) luaFunc(setGemName) { - int gemId = lua_tointeger(L, 1); + size_t gemId = lua_tointeger(L, 1); bool result = false; - if(gemId >= 0 && gemId < dsq->continuity.gems.size()) + if(gemId < dsq->continuity.gems.size()) { Continuity::Gems::iterator it = dsq->continuity.gems.begin(); std::advance(it, gemId); @@ -8508,10 +8509,10 @@ luaFunc(setGemName) luaFunc(setGemBlink) { - int gemId = lua_tointeger(L, 1); + size_t gemId = lua_tointeger(L, 1); bool result = false; - if(gemId >= 0 && gemId < dsq->continuity.gems.size()) + if(gemId < dsq->continuity.gems.size()) { Continuity::Gems::iterator it = dsq->continuity.gems.begin(); std::advance(it, gemId); @@ -8527,8 +8528,8 @@ luaFunc(setGemBlink) luaFunc(removeGem) { - int gemId = lua_tointeger(L, 1); - if(gemId >= 0 && gemId < dsq->continuity.gems.size()) + size_t gemId = lua_tointeger(L, 1); + if(gemId < dsq->continuity.gems.size()) { Continuity::Gems::iterator it = dsq->continuity.gems.begin(); std::advance(it, gemId); @@ -8602,10 +8603,10 @@ luaFunc(setCostume) luaFunc(setLayerRenderPass) { - int layer = lua_tointeger(L, 1); + size_t layer = lua_tointeger(L, 1); int startPass = lua_tointeger(L, 2); int endPass = lua_tointeger(L, 3); - if(layer >= 0 && layer < core->renderObjectLayers.size()) + if(layer < core->renderObjectLayers.size()) { core->renderObjectLayers[layer].startPass = startPass; core->renderObjectLayers[layer].endPass = endPass; diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index de4a507..75eeb57 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -140,7 +140,7 @@ void ScriptedEntity::postInit() Entity::postInit(); } -void ScriptedEntity::initEmitter(int emit, const std::string &file) +void ScriptedEntity::initEmitter(size_t emit, const std::string &file) { if (emitters.size() <= emit) { @@ -156,7 +156,7 @@ void ScriptedEntity::initEmitter(int emit, const std::string &file) emitters[emit]->load(file); } -void ScriptedEntity::startEmitter(int emit) +void ScriptedEntity::startEmitter(size_t emit) { if(emit >= emitters.size()) return; @@ -167,7 +167,7 @@ void ScriptedEntity::startEmitter(int emit) } } -void ScriptedEntity::stopEmitter(int emit) +void ScriptedEntity::stopEmitter(size_t emit) { if(emit >= emitters.size()) return; @@ -178,12 +178,12 @@ void ScriptedEntity::stopEmitter(int emit) } } -ParticleEffect *ScriptedEntity::getEmitter(int emit) +ParticleEffect *ScriptedEntity::getEmitter(size_t emit) { return (size_t(emit) < emitters.size()) ? emitters[emit] : NULL; } -int ScriptedEntity::getNumEmitters() const +size_t ScriptedEntity::getNumEmitters() const { return emitters.size(); } @@ -200,7 +200,7 @@ void ScriptedEntity::initSegments(int numSegments, int minDist, int maxDist, std this->minDist = minDist; this->maxDist = maxDist; segments.resize(numSegments); - for (int i = segments.size()-1; i >= 0 ; i--) + for (size_t i = segments.size(); i-- > 0 ; ) { Quad *q = new Quad; if (i == segments.size()-1) @@ -258,7 +258,7 @@ void ScriptedEntity::initStrands(int num, int segs, int dist, int strandSpacing, { this->strandSpacing = strandSpacing; strands.resize(num); - for (int i = 0; i < strands.size(); i++) + for (size_t i = 0; i < strands.size(); i++) { strands[i] = new Strand(position, segs, dist); strands[i]->color = color; @@ -393,7 +393,7 @@ void ScriptedEntity::updateStrands(float dt) angle = (PI*(360-(angle-90)))/180.0; float sz = (strands.size()/2); - for (int i = 0; i < strands.size(); i++) + for (size_t i = 0; i < strands.size(); i++) { float diff = (i-sz)*strandSpacing; if (diff < 0) @@ -787,7 +787,7 @@ void ScriptedEntity::onEnterState(int action) destroySegments(1); - for (int i = 0; i < strands.size(); i++) + for (size_t i = 0; i < strands.size(); i++) { strands[i]->safeKill(); } diff --git a/Aquaria/ScriptedEntity.h b/Aquaria/ScriptedEntity.h index f93f2e3..ff3dfde 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -80,11 +80,11 @@ public: ParticleEffect pullEmitter; float manaBallAmount; - void initEmitter(int emit, const std::string &file); - void startEmitter(int emit); - void stopEmitter(int emit); - ParticleEffect *getEmitter(int emit); - int getNumEmitters() const; + void initEmitter(size_t emit, const std::string &file); + void startEmitter(size_t emit); + void stopEmitter(size_t emit); + ParticleEffect *getEmitter(size_t emit); + size_t getNumEmitters() const; void shiftWorlds(WorldType lastWorld, WorldType worldType); void setAutoSkeletalUpdate(bool v); diff --git a/Aquaria/Segmented.cpp b/Aquaria/Segmented.cpp index b09d06b..0f232b9 100644 --- a/Aquaria/Segmented.cpp +++ b/Aquaria/Segmented.cpp @@ -36,14 +36,14 @@ void Segmented::setMaxDist(float m) void Segmented::initSegments(const Vector &position) { - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) segments[i]->position = position; numSegments = segments.size(); } void Segmented::destroySegments(float life) { - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i]->setLife(life); segments[i]->setDecayRate(1.0f); @@ -52,9 +52,9 @@ void Segmented::destroySegments(float life) segments.clear(); } -RenderObject *Segmented::getSegment(int seg) +RenderObject *Segmented::getSegment(size_t seg) { - if (seg < 0 || seg >= segments.size()) + if (seg >= segments.size()) return 0; return segments[seg]; } @@ -85,7 +85,7 @@ void Segmented::updateSegment(int i, const Vector &diff) void Segmented::updateAlpha(float a) { - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i]->alpha = a; } @@ -93,7 +93,7 @@ void Segmented::updateAlpha(float a) void Segmented::warpSegments(const Vector &position) { - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i]->position = position; } diff --git a/Aquaria/Segmented.h b/Aquaria/Segmented.h index c9fb81d..039a41d 100644 --- a/Aquaria/Segmented.h +++ b/Aquaria/Segmented.h @@ -27,7 +27,7 @@ class Segmented { public: Segmented(float minDist, float maxDist); - RenderObject *getSegment(int seg); + RenderObject *getSegment(size_t seg); void updateAlpha(float a); void warpSegments(const Vector &position); void setMaxDist(float m); @@ -47,7 +47,7 @@ protected: class Strand : public RenderObject, public Segmented { public: - Strand(const Vector &position, int segs, int dist=32); + Strand(const Vector &position, size_t segs, size_t dist=32); void destroy(); protected: void onUpdate(float dt); diff --git a/Aquaria/States.cpp b/Aquaria/States.cpp index 03e3c72..32fa74c 100644 --- a/Aquaria/States.cpp +++ b/Aquaria/States.cpp @@ -292,7 +292,7 @@ namespace NagStuff const float screenTime = 3; const float nagFadeTime = 1; -}; +} using namespace NagStuff; @@ -424,7 +424,7 @@ void Nag::update(float dt) ic ++; if (ic >= numScreens) ic = 0; - for (int i = 0; i < irot.size(); i++) irot[i]->alpha.interpolateTo(0, nagFadeTime); + for (size_t i = 0; i < irot.size(); i++) irot[i]->alpha.interpolateTo(0, nagFadeTime); irot[ic]->alpha.interpolateTo(1, nagFadeTime); } } diff --git a/Aquaria/StatsAndAchievements.cpp b/Aquaria/StatsAndAchievements.cpp index 9a873fe..b9c9696 100644 --- a/Aquaria/StatsAndAchievements.cpp +++ b/Aquaria/StatsAndAchievements.cpp @@ -229,7 +229,7 @@ void StatsAndAchievements::RunFrame() // but only if we're not in a mod if (!dsq->mod.isActive()) { - for ( int iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) { EvaluateAchievement( g_rgAchievements[iAch] ); } @@ -252,7 +252,7 @@ void StatsAndAchievements::appendStringData(std::string &data) count = 0; data += "Unlocked:\n\n"; - for ( int iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) { const Achievement &ach = g_rgAchievements[iAch]; if (!ach.achieved) @@ -271,7 +271,7 @@ void StatsAndAchievements::appendStringData(std::string &data) count = 0; data += "Locked:\n\n"; - for ( int iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) + for (size_t iAch = 0; iAch < ARRAYSIZE( g_rgAchievements ); ++iAch ) { const Achievement &ach = g_rgAchievements[iAch]; if (ach.achieved) @@ -384,7 +384,7 @@ void StatsAndAchievements::EvaluateAchievement( Achievement &achievement ) bool didPoisonLoaf = false; bool didVeggieSoup = false; - for (int i = 0; i < dsq->continuity.recipes.size(); i++ ) + for (size_t i = 0; i < dsq->continuity.recipes.size(); i++ ) { if (dsq->continuity.recipes[i].isKnown()) { @@ -397,7 +397,7 @@ void StatsAndAchievements::EvaluateAchievement( Achievement &achievement ) } } } - for (int i = 0; i < dsq->continuity.recipes.size(); i++ ) + for (size_t i = 0; i < dsq->continuity.recipes.size(); i++ ) { if (!dsq->continuity.recipes[i].isKnown()) { diff --git a/Aquaria/Strand.cpp b/Aquaria/Strand.cpp index 180240d..c22e56d 100644 --- a/Aquaria/Strand.cpp +++ b/Aquaria/Strand.cpp @@ -21,11 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Segmented.h" #include "RenderBase.h" -Strand::Strand(const Vector &position, int segs, int dist) : RenderObject(), Segmented(dist, dist) +Strand::Strand(const Vector &position, size_t segs, size_t dist) : RenderObject(), Segmented(dist, dist) { cull = false; segments.resize(segs); - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i] = new RenderObject; } @@ -35,7 +35,7 @@ Strand::Strand(const Vector &position, int segs, int dist) : RenderObject(), Seg void Strand::destroy() { RenderObject::destroy(); - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i]->destroy(); delete segments[i]; diff --git a/Aquaria/StringBank.cpp b/Aquaria/StringBank.cpp index e03275c..1ae7203 100644 --- a/Aquaria/StringBank.cpp +++ b/Aquaria/StringBank.cpp @@ -65,7 +65,7 @@ void StringBank::_load(const std::string &file) if (!line.empty() && line[0] == ' ') line = line.substr(1, line.size()); - for (int i = 0; i < line.size(); i++) + for (size_t i = 0; i < line.size(); i++) { if (line[i] == '|') line[i] = '\n'; diff --git a/Aquaria/UserSettings.cpp b/Aquaria/UserSettings.cpp index 07d64f9..0bce7d8 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -200,30 +200,28 @@ void UserSettings::save() { const ActionSet& as = control.actionSets[i]; XMLElement *xml_actionSet = doc.NewElement("ActionSet"); + xml_actionSet->SetAttribute("enabled", as.enabled); + xml_actionSet->SetAttribute("name", as.name.c_str()); + xml_actionSet->SetAttribute("joystickName", as.joystickName.c_str()); + xml_actionSet->SetAttribute("joystickGUID", as.joystickGUID.c_str()); + XMLElement *xml_joyAxes = doc.NewElement("JoyAxes"); { - xml_actionSet->SetAttribute("enabled", as.enabled); - xml_actionSet->SetAttribute("name", as.name.c_str()); - xml_actionSet->SetAttribute("joystickName", as.joystickName.c_str()); - xml_actionSet->SetAttribute("joystickGUID", as.joystickGUID.c_str()); - XMLElement *xml_joyAxes = doc.NewElement("JoyAxes"); - { - xml_joyAxes->SetAttribute("s1ax", as.joycfg.s1ax); - xml_joyAxes->SetAttribute("s1ay", as.joycfg.s1ay); - xml_joyAxes->SetAttribute("s2ax", as.joycfg.s2ax); - xml_joyAxes->SetAttribute("s2ay", as.joycfg.s2ay); - xml_joyAxes->SetAttribute("s1dead", as.joycfg.s1dead); - xml_joyAxes->SetAttribute("s2dead", as.joycfg.s2dead); - } - xml_actionSet->InsertEndChild(xml_joyAxes); - for (int i = 0; i < as.inputSet.size(); i++) - { - XMLElement *xml_action = doc.NewElement("Action"); - const ActionInput& ai = as.inputSet[i]; - xml_action->SetAttribute("name", ai.name.c_str()); - xml_action->SetAttribute("input", ai.toString().c_str()); + xml_joyAxes->SetAttribute("s1ax", as.joycfg.s1ax); + xml_joyAxes->SetAttribute("s1ay", as.joycfg.s1ay); + xml_joyAxes->SetAttribute("s2ax", as.joycfg.s2ax); + xml_joyAxes->SetAttribute("s2ay", as.joycfg.s2ay); + xml_joyAxes->SetAttribute("s1dead", as.joycfg.s1dead); + xml_joyAxes->SetAttribute("s2dead", as.joycfg.s2dead); + } + xml_actionSet->InsertEndChild(xml_joyAxes); + for (int i = 0; i < as.inputSet.size(); i++) + { + XMLElement *xml_action = doc.NewElement("Action"); + const ActionInput& ai = as.inputSet[i]; + xml_action->SetAttribute("name", ai.name.c_str()); + xml_action->SetAttribute("input", ai.toString().c_str()); - xml_actionSet->InsertEndChild(xml_action); - } + xml_actionSet->InsertEndChild(xml_action); } xml_control->InsertEndChild(xml_actionSet); } @@ -254,8 +252,8 @@ void UserSettings::save() XMLElement *xml_data = doc.NewElement("Data"); { - xml_data->SetAttribute("savePage", data.savePage); - xml_data->SetAttribute("saveSlot", data.saveSlot); + xml_data->SetAttribute("savePage", (unsigned int) data.savePage); + xml_data->SetAttribute("saveSlot", (unsigned int) data.saveSlot); std::ostringstream ss; for (std::vector::iterator it = dsq->activePatches.begin(); it != dsq->activePatches.end(); ++it) @@ -544,8 +542,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile) XMLElement *xml_data = doc.FirstChildElement("Data"); if (xml_data) { - xml_data->QueryIntAttribute("savePage", &data.savePage); - xml_data->QueryIntAttribute("saveSlot", &data.saveSlot); + // use a temporary variable so we don't get into trouble on big-endian architectures + unsigned int tmp; + xml_data->QueryUnsignedAttribute("savePage", &tmp); + data.savePage = tmp; + xml_data->QueryUnsignedAttribute("saveSlot", &tmp); + data.saveSlot = tmp; if(const char *patchlist = xml_data->Attribute("activePatches")) { diff --git a/Aquaria/UserSettings.h b/Aquaria/UserSettings.h index fed0acb..76e28f3 100644 --- a/Aquaria/UserSettings.h +++ b/Aquaria/UserSettings.h @@ -117,8 +117,8 @@ public: struct Data { Data() { savePage=0; saveSlot=0; } - int savePage; - int saveSlot; + size_t savePage; + size_t saveSlot; } data; struct Version diff --git a/Aquaria/Web.cpp b/Aquaria/Web.cpp index ddffc59..8df1336 100644 --- a/Aquaria/Web.cpp +++ b/Aquaria/Web.cpp @@ -77,16 +77,16 @@ int Web::addPoint(const Vector &point) return points.size()-1; } -void Web::setPoint(int pt, const Vector &v) +void Web::setPoint(size_t pt, const Vector &v) { - if (pt < 0 || pt >= points.size()) return; + if (pt >= points.size()) return; points[pt] = v; } -Vector Web::getPoint(int pt) const +Vector Web::getPoint(size_t pt) const { Vector v; - if (pt >= 0 || pt < points.size()) + if ( pt < points.size()) v = points[pt]; return v; } @@ -123,9 +123,9 @@ void Web::onUpdate(float dt) Entity *e = (*i); if ((e->getEntityType() == ET_ENEMY || e->getEntityType() == ET_AVATAR) && e->isDamageTarget(DT_ENEMY_WEB)) { - if (parentEntity != e) + if (parentEntity != e && points.size() > 0) { - for (int j = 0; j < points.size()-1; j++) + for (size_t j = 0; j < points.size()-1; j++) { if (game->collideCircleVsLine(e, points[j], points[j+1], 4)) { @@ -155,14 +155,13 @@ void Web::onRender() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); - for (int i = 0; i < points.size()-1; i++) - { - - glColor4f(1, 1, 1, 0.5f*alpha.x); - glVertex3f(points[i].x, points[i].y, 0); - glColor4f(1, 1, 1, 0.5f*alpha.x); - glVertex3f(points[i+1].x, points[i+1].y, 0); - + if(points.size() > 0) { + for (size_t i = 0; i < points.size()-1; i++) { + glColor4f(1, 1, 1, 0.5f*alpha.x); + glVertex3f(points[i].x, points[i].y, 0); + glColor4f(1, 1, 1, 0.5f*alpha.x); + glVertex3f(points[i+1].x, points[i+1].y, 0); + } } glEnd(); } diff --git a/Aquaria/Web.h b/Aquaria/Web.h index 443f502..c7d38a8 100644 --- a/Aquaria/Web.h +++ b/Aquaria/Web.h @@ -30,8 +30,8 @@ class Web : public RenderObject public: Web(); int addPoint(const Vector &point = Vector(0,0)); - void setPoint(int pt, const Vector &v); - Vector getPoint(int pt) const; + void setPoint(size_t pt, const Vector &v); + Vector getPoint(size_t pt) const; void setParentEntity(Entity *e); int getNumPoints(); typedef std::list Webs; diff --git a/Aquaria/WorldMap.h b/Aquaria/WorldMap.h index f15f1fe..238d39c 100644 --- a/Aquaria/WorldMap.h +++ b/Aquaria/WorldMap.h @@ -40,8 +40,8 @@ struct WorldMap void hideMap(); void revealMap(const std::string &name); WorldMapTile *getWorldMapTile(const std::string &name); - int getNumWorldMapTiles(); - WorldMapTile *getWorldMapTile(int index); + size_t getNumWorldMapTiles(); + WorldMapTile *getWorldMapTile(size_t index); WorldMapTile *getWorldMapTileByIndex(int index); void revealMapIndex(int index); diff --git a/Aquaria/WorldMapRender.cpp b/Aquaria/WorldMapRender.cpp index 292fd4c..5a0d83e 100644 --- a/Aquaria/WorldMapRender.cpp +++ b/Aquaria/WorldMapRender.cpp @@ -1282,7 +1282,7 @@ void WorldMapRender::fixGems() void WorldMapRender::addAllGems() { - int c = 0; + size_t c = 0; for (Continuity::Gems::reverse_iterator i = dsq->continuity.gems.rbegin(); i != dsq->continuity.gems.rend(); i++) { GemMover *g = addGem(&(*i)); diff --git a/Aquaria/WorldMapTiles.cpp b/Aquaria/WorldMapTiles.cpp index cbf87eb..cabb598 100644 --- a/Aquaria/WorldMapTiles.cpp +++ b/Aquaria/WorldMapTiles.cpp @@ -282,7 +282,7 @@ void WorldMap::save() if (out) { - for (int i = 0; i < worldMapTiles.size(); i++) + for (size_t i = 0; i < worldMapTiles.size(); i++) { WorldMapTile *t = &worldMapTiles[i]; out << t->index << " " << t->stringIndex << " " << t->name << " " << t->layer << " " << t->scale << " " << t->gridPos.x << " " << t->gridPos.y << " " << t->prerevealed << " " << t->scale2 << std::endl; @@ -317,7 +317,7 @@ WorldMapTile *WorldMap::getWorldMapTile(const std::string &name) { std::string n = name; stringToUpper(n); - for (int i = 0; i < worldMapTiles.size(); i++) + for (size_t i = 0; i < worldMapTiles.size(); i++) { if (worldMapTiles[i].name == n) { @@ -329,7 +329,7 @@ WorldMapTile *WorldMap::getWorldMapTile(const std::string &name) WorldMapTile *WorldMap::getWorldMapTileByIndex(int index) { - for (int i = 0; i < worldMapTiles.size(); i++) + for (size_t i = 0; i < worldMapTiles.size(); i++) { if (worldMapTiles[i].index == index) { @@ -343,20 +343,20 @@ WorldMapTile *WorldMap::getWorldMapTileByIndex(int index) void WorldMap::hideMap() { - for (int i = 0; i < worldMapTiles.size(); i++) + for (size_t i = 0; i < worldMapTiles.size(); i++) { worldMapTiles[i].revealed = false; } } -int WorldMap::getNumWorldMapTiles() +size_t WorldMap::getNumWorldMapTiles() { return worldMapTiles.size(); } -WorldMapTile *WorldMap::getWorldMapTile(int index) +WorldMapTile *WorldMap::getWorldMapTile(size_t index) { - if (index < 0 || index >= worldMapTiles.size()) return 0; + if (index >= worldMapTiles.size()) return 0; return &worldMapTiles[index]; } diff --git a/BBGE/ActionInput.cpp b/BBGE/ActionInput.cpp index c6071b0..281e78f 100644 --- a/BBGE/ActionInput.cpp +++ b/BBGE/ActionInput.cpp @@ -177,9 +177,9 @@ int getStringToInputCode(const std::string& s) ActionInput::ActionInput() { - for (int i = 0; i < INP_MSESIZE; i++) mse[i] = 0; - for (int i = 0; i < INP_KEYSIZE; i++) key[i] = 0; - for (int i = 0; i < INP_JOYSIZE; i++) joy[i] = 0; + for (int i = 0; i < INP_MSESIZE; i++) data.single.mse[i] = 0; + for (int i = 0; i < INP_KEYSIZE; i++) data.single.key[i] = 0; + for (int i = 0; i < INP_JOYSIZE; i++) data.single.joy[i] = 0; } std::string ActionInput::toString() const @@ -188,15 +188,15 @@ std::string ActionInput::toString() const for (int i = 0; i < INP_MSESIZE; i++) { - os << getInputCodeToString(mse[i]) << " "; + os << getInputCodeToString(data.single.mse[i]) << " "; } for (int i = 0; i < INP_KEYSIZE; i++) { - os << getInputCodeToString(key[i]) << " "; + os << getInputCodeToString(data.single.key[i]) << " "; } for (int i = 0; i < INP_JOYSIZE; i++) { - os << getInputCodeToString(joy[i]) << " "; + os << getInputCodeToString(data.single.joy[i]) << " "; } return os.str(); @@ -209,17 +209,17 @@ void ActionInput::fromString(const std::string &read) for (int i = 0; i < INP_MSESIZE; i++) { is >> str; - mse[i] = getStringToInputCode(str); + data.single.mse[i] = getStringToInputCode(str); } for (int i = 0; i < INP_KEYSIZE; i++) { is >> str; - key[i] = getStringToInputCode(str); + data.single.key[i] = getStringToInputCode(str); } for (int i = 0; i < INP_JOYSIZE; i++) { is >> str; - joy[i] = getStringToInputCode(str); + data.single.joy[i] = getStringToInputCode(str); } } diff --git a/BBGE/ActionInput.h b/BBGE/ActionInput.h index 4939089..4b99a97 100644 --- a/BBGE/ActionInput.h +++ b/BBGE/ActionInput.h @@ -49,9 +49,9 @@ public: int mse[INP_MSESIZE]; int key[INP_KEYSIZE]; int joy[INP_JOYSIZE]; - }; + } single; int all[INP_COMBINED_SIZE]; - }; + } data; std::string toString() const; void fromString(const std::string &read); diff --git a/BBGE/ActionMapper.cpp b/BBGE/ActionMapper.cpp index 99b45ca..51b025f 100644 --- a/BBGE/ActionMapper.cpp +++ b/BBGE/ActionMapper.cpp @@ -113,7 +113,7 @@ void ActionMapper::addAction(Event *event, int k, int state) Event* ActionMapper::addCreatedEvent(Event *event) { - for (int i = 0; i < createdEvents.size(); i++) + for (size_t i = 0; i < createdEvents.size(); i++) { if (createdEvents[i] == event) return event; @@ -124,7 +124,7 @@ Event* ActionMapper::addCreatedEvent(Event *event) void ActionMapper::clearCreatedEvents() { - for (int i = 0; i < createdEvents.size(); i++) + for (size_t i = 0; i < createdEvents.size(); i++) { delete createdEvents[i]; } diff --git a/BBGE/ActionSet.cpp b/BBGE/ActionSet.cpp index 974ce8f..1553d0a 100644 --- a/BBGE/ActionSet.cpp +++ b/BBGE/ActionSet.cpp @@ -148,14 +148,14 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int if (!enabled) return; if (!mapper) return; - for (int i = 0; i < inputSet.size(); i++) + for (size_t i = 0; i < inputSet.size(); i++) { const ActionInput *actionInput = &inputSet[i]; if (actionInput->name == name) { for (int i = 0; i < INP_COMBINED_SIZE; i++) - if (actionInput->all[i]) - mapper->addAction(actionID, actionInput->all[i], sourceID); + if (actionInput->data.all[i]) + mapper->addAction(actionID, actionInput->data.all[i], sourceID); return; } } @@ -166,14 +166,14 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Even if (!enabled) return; if (!mapper) return; - for (int i = 0; i < inputSet.size(); i++) + for (size_t i = 0; i < inputSet.size(); i++) { const ActionInput *actionInput = &inputSet[i]; if (actionInput->name == name) { for (int i = 0; i < INP_COMBINED_SIZE; i++) - if (actionInput->all[i]) - mapper->addAction(event, actionInput->all[i], state); + if (actionInput->data.all[i]) + mapper->addAction(event, actionInput->data.all[i], state); return; } } @@ -196,8 +196,8 @@ std::string ActionSet::insertInputIntoString(const std::string &string) { std::string str = string; - int start = str.find('{'); - int end = str.find('}'); + size_t start = str.find('{'); + size_t end = str.find('}'); if (start == std::string::npos || end == std::string::npos) return string; std::string code = str.substr(start+1, end - start); diff --git a/BBGE/ActionStatus.cpp b/BBGE/ActionStatus.cpp index 1e8158e..5d559cd 100644 --- a/BBGE/ActionStatus.cpp +++ b/BBGE/ActionStatus.cpp @@ -20,8 +20,8 @@ void ActionButtonStatus::import(const ActionSet& as) { const ActionInput& inp = as.inputSet[i]; for(int j = 0; j < INP_COMBINED_SIZE; ++j) - if(unsigned(inp.all[j]) < ACTION_BUTTON_ENUM_SIZE) - found[inp.all[j]] = 1; + if(unsigned(inp.data.all[j]) < ACTION_BUTTON_ENUM_SIZE) + found[inp.data.all[j]] = 1; } toQuery.clear(); diff --git a/BBGE/AfterEffect.cpp b/BBGE/AfterEffect.cpp index c9a7fd6..c126bcb 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -81,7 +81,7 @@ AfterEffectManager::~AfterEffectManager() void AfterEffectManager::deleteEffects() { - for (int i = 0; i < effects.size(); i++) + for (size_t i = 0; i < effects.size(); i++) { if (effects[i]) { @@ -132,7 +132,7 @@ void AfterEffectManager::update(float dt) else active = false; - for (int i = 0; i < effects.size(); i++) + for (size_t i = 0; i < effects.size(); i++) { Effect *e = effects[i]; if (e) diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index d11b31b..8199566 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -50,7 +50,7 @@ int randRange(int n1, int n2) std::string removeSpaces(const std::string &input) { std::string result; - for (int i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); i++) { if (input[i] != ' ') { @@ -64,7 +64,7 @@ unsigned hash(const std::string &string) { unsigned hash = 5381; - for (int i = 0; i < string.size(); i++) + for (size_t i = 0; i < string.size(); i++) hash = ((hash << 5) + hash) + (unsigned char)string[i]; return hash; @@ -127,7 +127,7 @@ std::string splitCamelCase(const std::string &input) { std::string result; int last = 0; - for (int i = 0; i < input.size(); i++) + for (size_t i = 0; i < input.size(); i++) { if (last == 1) { @@ -149,7 +149,7 @@ std::string splitCamelCase(const std::string &input) return result; } -std::string numToZeroString(int num, int zeroes) +std::string numToZeroString(int num, size_t zeroes) { std::ostringstream num_os; num_os << num; @@ -158,7 +158,7 @@ std::string numToZeroString(int num, int zeroes) if (num_os.str().size() <= zeroes) { - for (int j = 0; j < zeroes - num_os.str().size(); j++) + for (size_t j = 0; j < zeroes - num_os.str().size(); j++) { os << "0"; } @@ -169,13 +169,13 @@ std::string numToZeroString(int num, int zeroes) void stringToUpper(std::string &s) { - for (int i = 0; i < s.size(); i++) + for (size_t i = 0; i < s.size(); i++) s[i] = charToUpper(s[i]); } void stringToLower(std::string &s) { - for (int i = 0; i < s.size(); i++) + for (size_t i = 0; i < s.size(); i++) s[i] = charToLower(s[i]); } @@ -319,7 +319,7 @@ char *readFile(const std::string& path, unsigned long *size_ret) return NULL; } - long bytesRead = vfread(buffer, 1, fileSize, f); + size_t bytesRead = vfread(buffer, 1, fileSize, f); if (bytesRead != fileSize) { std::ostringstream os; @@ -340,7 +340,7 @@ char *readFile(const std::string& path, unsigned long *size_ret) std::string stripEndlineForUnix(const std::string &in) { std::string out; - for (int i = 0; i < in.size(); i++) + for (size_t i = 0; i < in.size(); i++) { if (int(in[i]) != 13) { @@ -405,7 +405,7 @@ float lerp(const float &v1, const float &v2, float dt, int lerpType) std::string underscoresToSpaces(const std::string &str) { std::string s = str; - for (int i = 0; i < s.size(); i++) + for (size_t i = 0; i < s.size(); i++) if (s[i] == '_') s[i] = ' '; return s; } @@ -413,7 +413,7 @@ std::string underscoresToSpaces(const std::string &str) std::string spacesToUnderscores(const std::string &str) { std::string s = str; - for (int i = 0; i < s.size(); i++) + for (size_t i = 0; i < s.size(); i++) if (s[i] == ' ') s[i] = '_'; return s; } diff --git a/BBGE/Base.h b/BBGE/Base.h index 000dd7d..1ae6e76 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -103,7 +103,7 @@ typedef int CharTranslationTable[256]; // -1 entries are skipped #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) -std::string numToZeroString(int num, int zeroes); +std::string numToZeroString(int num, size_t zeroes); bool chance(int perc); void initCharTranslationTables(const CharTranslationTable *ptab); void stringToUpper(std::string &s); diff --git a/BBGE/BitmapFont.cpp b/BBGE/BitmapFont.cpp index 8ff5d0c..2735099 100644 --- a/BBGE/BitmapFont.cpp +++ b/BBGE/BitmapFont.cpp @@ -148,7 +148,7 @@ void BitmapText::formatText() float currentWidth = 0; alignWidth = 0; maxW = 0; - for (int i = 0; i < text.size(); i++) + for (size_t i = 0; i < text.size(); i++) { float sz = bmpFont->font->GetCharWidth(text[i])*bmpFont->scale; @@ -194,10 +194,10 @@ void BitmapText::setBitmapFontEffect(BitmapFontEffect bfe) void BitmapText::updateWordColoring() { colorIndices.resize(lines.size()); - for (int i = 0; i < colorIndices.size(); i++) + for (size_t i = 0; i < colorIndices.size(); i++) { colorIndices[i].resize(lines[i].size()); - for (int j = 0; j < colorIndices[i].size(); j++) + for (size_t j = 0; j < colorIndices[i].size(); j++) { colorIndices[i][j] = Vector(1,1,1); } @@ -265,15 +265,12 @@ void BitmapText::onUpdate(float dt) } } -Vector BitmapText::getColorIndex(int i, int j) +Vector BitmapText::getColorIndex(size_t i, size_t j) { Vector c(1,1,1); - if (!(i < 0 || j < 0)) + if ( i < colorIndices.size() && j < colorIndices[i].size()) { - if ( i < colorIndices.size() && j < colorIndices[i].size()) - { - c = colorIndices[i][j]; - } + c = colorIndices[i][j]; } return c; } @@ -301,7 +298,7 @@ void BitmapText::onRender() if (scrolling) { - for (int i = 0; i <= currentScrollLine; i++) + for (size_t i = 0; i <= currentScrollLine; i++) { std::string theLine = lines[i]; if (i == currentScrollLine) @@ -323,7 +320,7 @@ void BitmapText::onRender() } else { - for (int i = 0; i < lines.size(); i++) + for (size_t i = 0; i < lines.size(); i++) { x=0; if (align == ALIGN_CENTER) diff --git a/BBGE/BitmapFont.h b/BBGE/BitmapFont.h index e97e5a6..7f3f450 100644 --- a/BBGE/BitmapFont.h +++ b/BBGE/BitmapFont.h @@ -66,7 +66,7 @@ public: virtual void setAlign(Align align); std::string getText(); int getWidthOnScreen(); - Vector getColorIndex(int i, int j); + Vector getColorIndex(size_t i, size_t j); void updateWordColoring(); void autoKern(); void setBitmapFontEffect(BitmapFontEffect bfe); @@ -87,8 +87,8 @@ protected: void onUpdate(float dt); float scrollDelay; bool scrolling; - int currentScrollLine; - int currentScrollChar; + size_t currentScrollLine; + size_t currentScrollChar; Align align; float alignWidth; void formatText(); diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 314914e..da8e920 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -89,7 +89,7 @@ ParticleEffect* Core::createParticleEffect(const std::string &name, const Vector void Core::unloadDevice() { - for (int i = 0; i < renderObjectLayers.size(); i++) + for (size_t i = 0; i < renderObjectLayers.size(); i++) { RenderObjectLayer *r = &renderObjectLayers[i]; RenderObject *robj = r->getFirst(); @@ -107,7 +107,7 @@ void Core::unloadDevice() void Core::reloadDevice() { - for (int i = 0; i < renderObjectLayers.size(); i++) + for (size_t i = 0; i < renderObjectLayers.size(); i++) { RenderObjectLayer *r = &renderObjectLayers[i]; r->reloadDevice(); @@ -574,7 +574,7 @@ void Core::initPlatform(const std::string &filesystem) char path[PATH_MAX]; // always a symlink to this process's binary, on modern Linux systems. const ssize_t rc = readlink("/proc/self/exe", path, sizeof (path)); - if ( (rc == -1) || (rc >= sizeof (path)) ) + if ( (rc == -1) || (rc >= (ssize_t) sizeof (path)) ) { // error! debugLog("readlink"); @@ -698,7 +698,9 @@ void Core::init() if((SDL_Init(SDL_INIT_EVERYTHING))==-1) { - exit_error("Failed to init SDL"); + std::string msg("Failed to init SDL: "); + msg.append(SDL_GetError()); + exit_error(msg); } loopDone = false; @@ -1222,7 +1224,7 @@ void Core::resetTimer() { nowTicks = thenTicks = SDL_GetTicks(); - for (int i = 0; i < avgFPS.size(); i++) + for (size_t i = 0; i < avgFPS.size(); i++) { avgFPS[i] = 0; } @@ -1230,8 +1232,6 @@ void Core::resetTimer() void Core::setMousePosition(const Vector &p) { - Vector lp = core->mouse.position; - core->mouse.position = p; float px = p.x + virtualOffX; float py = p.y; @@ -1246,7 +1246,7 @@ void Core::setMousePosition(const Vector &p) // used to update all render objects either uniformly or as part of a time sliced update process void Core::updateRenderObjects(float dt) { - for (int c = 0; c < renderObjectLayers.size(); c++) + for (size_t c = 0; c < renderObjectLayers.size(); c++) { RenderObjectLayer *rl = &renderObjectLayers[c]; @@ -1335,7 +1335,7 @@ void Core::run(float runTime) if (!avgFPS.empty()) { - int i = 0; + size_t i = 0; for (i = avgFPS.size()-1; i > 0; i--) { avgFPS[i] = avgFPS[i-1]; @@ -1796,11 +1796,9 @@ void Core::print(int x, int y, const char *str, float sz) float xx = x; - float yy = y; glTranslatef(x, y-0.5f*sz, 0); x = y = 0; - xx = 0; yy = 0; - bool isLower = false, wasLower = false; + xx = 0; int c=0; @@ -1811,13 +1809,6 @@ void Core::print(int x, int y, const char *str, float sz) while (str[c] != '\0') { - if (str[c] <= 'z' && str[c] >= 'a') - isLower = true; - else - isLower = false; - - - switch(toupper(str[c])) { case '_': @@ -2067,11 +2058,6 @@ void Core::print(int x, int y, const char *str, float sz) default: break; - } - if (isLower) - { - wasLower = true; - } c++; xx += 1.4f; @@ -2142,7 +2128,7 @@ void Core::render(int startLayer, int endLayer, bool useFrameBufferIfAvail) RenderObject::rlayer = 0; - for (int c = 0; c < renderObjectLayerOrder.size(); c++) + for (size_t c = 0; c < renderObjectLayerOrder.size(); c++) { int i = renderObjectLayerOrder[c]; @@ -2239,7 +2225,7 @@ void Core::shutdownJoystickLibrary() void Core::clearRenderObjects() { - for (int i = 0; i < renderObjectLayers.size(); i++) + for (size_t i = 0; i < renderObjectLayers.size(); i++) { RenderObject *r = renderObjectLayers[i].getFirst(); @@ -2454,11 +2440,11 @@ CountedPtr Core::addTexture(const std::string &textureName) return ptex; } -void Core::addRenderObject(RenderObject *o, int layer) +void Core::addRenderObject(RenderObject *o, size_t layer) { if (!o) return; o->layer = layer; - if (layer < 0 || layer >= renderObjectLayers.size()) + if (layer >= renderObjectLayers.size()) { std::ostringstream os; os << "attempted to add render object to invalid layer [" << layer << "]"; @@ -2477,7 +2463,7 @@ void Core::switchRenderObjectLayer(RenderObject *o, int toLayer) void Core::unloadResources() { - for (int i = 0; i < resources.size(); i++) + for (size_t i = 0; i < resources.size(); i++) { resources[i]->unload(); } @@ -2489,7 +2475,7 @@ void Core::onReloadResources() void Core::reloadResources() { - for (int i = 0; i < resources.size(); i++) + for (size_t i = 0; i < resources.size(); i++) { resources[i]->reload(); } @@ -2645,8 +2631,8 @@ bool Core::saveScreenshot(const std::string &filename, bool png) // saves an array of pixels as a TGA image bool Core::tgaSave( const char *filename, - short int width, - short int height, + short unsigned int width, + short unsigned int height, unsigned char pixelDepth, unsigned char *imageData) { @@ -2712,8 +2698,8 @@ void Core::screenshot() // saves an array of pixels as a TGA image (frees the image data passed in) bool Core::zgaSave( const char *filename, - short int w, - short int h, + short unsigned int w, + short unsigned int h, unsigned char depth, unsigned char *imageData) { diff --git a/BBGE/Core.h b/BBGE/Core.h index c7d398a..ab2ea95 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -190,9 +190,9 @@ protected: std::vector displayList; RenderObjects renderObjects; - int objectCount; - int firstFreeIdx; - int iter; + size_t objectCount; + size_t firstFreeIdx; + size_t iter; }; class Core : public ActionMapper, public StateManager @@ -244,7 +244,7 @@ public: void setFullscreen(bool full); void enable2D(int pixelScaleX, int pixelScaleY); - void addRenderObject(RenderObject *o, int layer=0); + void addRenderObject(RenderObject *o, size_t layer=0); void switchRenderObjectLayer(RenderObject *o, int toLayer); void addTexture(Texture *r); CountedPtr findTexture(const std::string &name); @@ -435,9 +435,10 @@ public: CoreSettings settings; - bool tgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData); - bool zgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData); + bool tgaSave(const char *filename, short unsigned int width, short unsigned int height, unsigned char pixelDepth, unsigned char *imageData); + bool zgaSave(const char *filename, short unsigned int width, short unsigned int height, unsigned char pixelDepth, unsigned char *imageData); bool pngSave(const char *filename, unsigned width, unsigned height, unsigned char *data); + volatile int dbg_numThreadDecoders; virtual void onBackgroundUpdate(); diff --git a/BBGE/DebugFont.cpp b/BBGE/DebugFont.cpp index ef8eccb..27777d9 100644 --- a/BBGE/DebugFont.cpp +++ b/BBGE/DebugFont.cpp @@ -92,7 +92,7 @@ void DebugFont::formatText() int lastSpace = -1; float currentWidth = 0; maxW = 0; - for (int i = 0; i < text.size(); i++) + for (size_t i = 0; i < text.size(); i++) { currentWidth += fontDrawSize; @@ -134,7 +134,7 @@ void DebugFont::onRender() { const float vspc = 1.5; - for (int i = 0; i < lines.size(); i++) + for (size_t i = 0; i < lines.size(); i++) { float width = (lines[i].size()) * fontDrawSize * 1.4f * 0.75f; @@ -167,12 +167,12 @@ DebugButton::DebugButton(int buttonID, DebugButtonReceiver *receiver, int bgWidt : RenderObject() , label(0) , buttonID(buttonID) - , highlight(0) - , receiver(receiver) , activeAlpha(0.5f) , activeColor(1,1,1) , inactiveAlpha(0.5f) , inactiveColor(0,0,0) + , highlight(0) + , receiver(receiver) { if (bgWidth == 0) bgWidth = 150; diff --git a/BBGE/FmodOpenALBridge.cpp b/BBGE/FmodOpenALBridge.cpp index 6bcfd5d..18d325d 100644 --- a/BBGE/FmodOpenALBridge.cpp +++ b/BBGE/FmodOpenALBridge.cpp @@ -1378,7 +1378,7 @@ static void *decode_to_pcm(VFILE *io, ALenum &format, ALsizei &size, ALuint &fre if (rc > 0) { size += rc; - if (size >= allocated) + if ((size_t) size >= allocated) { allocated *= 2; ALubyte *tmp = (ALubyte *) realloc(retval, allocated); @@ -1738,7 +1738,7 @@ FMOD_RESULT OpenALSystem::update() } ALBRIDGE(System, set3DListenerAttributes, (int listener, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel, const FMOD_VECTOR *forward, const FMOD_VECTOR *up), - (listener, pos, vel, forward, up)); + (listener, pos, vel, forward, up)) FMOD_RESULT OpenALSystem::set3DListenerAttributes(int listener, const FMOD_VECTOR *pos, const FMOD_VECTOR *vel, const FMOD_VECTOR *forward, const FMOD_VECTOR *up) { // ignore listener parameter; there is only one listener in OpenAL. diff --git a/BBGE/LensFlare.cpp b/BBGE/LensFlare.cpp index daec1f2..48801ea 100644 --- a/BBGE/LensFlare.cpp +++ b/BBGE/LensFlare.cpp @@ -56,7 +56,7 @@ void LensFlare::onUpdate(float dt) Vector vbit = v; vbit *= inc; - for (int i = 0; i < flares.size(); i++) + for (size_t i = 0; i < flares.size(); i++) { flares[i]->position = vbit*i; flares[i]->alpha = a; diff --git a/BBGE/MathFunctions.h b/BBGE/MathFunctions.h index a76c1a2..e79b65c 100644 --- a/BBGE/MathFunctions.h +++ b/BBGE/MathFunctions.h @@ -58,5 +58,5 @@ namespace MathFunctions return angle; } -}; +} diff --git a/BBGE/OSFunctions.cpp b/BBGE/OSFunctions.cpp index 4d8c45d..ab1de98 100644 --- a/BBGE/OSFunctions.cpp +++ b/BBGE/OSFunctions.cpp @@ -234,7 +234,7 @@ void forEachFile(const std::string& inpath, std::string type, void callback(cons dirent *file=0; while ( (file=readdir(dir)) != NULL ) { - if (file->d_name && strlen(file->d_name) > 4) + if (strlen(file->d_name) > 4) { debugLog(file->d_name); char *extension=strrchr(file->d_name,'.'); diff --git a/BBGE/ParticleManager.cpp b/BBGE/ParticleManager.cpp index f3da448..a868e80 100644 --- a/BBGE/ParticleManager.cpp +++ b/BBGE/ParticleManager.cpp @@ -44,10 +44,10 @@ ParticleManager::ParticleManager(int size) setSize(size); } -void ParticleManager::setSize(int size) +void ParticleManager::setSize(size_t size) { // dangerous! - for (int i = 0; i < particles.size(); i++) + for (size_t i = 0; i < particles.size(); i++) { Particle *p = &particles[i]; if (p->emitter) @@ -71,15 +71,15 @@ void ParticleManager::setNumSuckPositions(int num) suckPositions.resize(num); } -void ParticleManager::setSuckPosition(int idx, const Vector &pos) +void ParticleManager::setSuckPosition(size_t idx, const Vector &pos) { - if (idx < 0 || idx >= suckPositions.size()) return; + if (idx >= suckPositions.size()) return; suckPositions[idx] = pos; } -Vector *ParticleManager::getSuckPosition(int idx) +Vector *ParticleManager::getSuckPosition(size_t idx) { - if (idx < 0 || idx >= suckPositions.size()) return 0; + if (idx >= suckPositions.size()) return 0; return &suckPositions[idx]; } @@ -207,12 +207,14 @@ void ParticleManager::nextFree(int jump) void ParticleManager::prevFree(int jump) { - free -= jump; - if (free < 0) - free += size; + if(free < jump) { + free = free + size - jump; + } else { + free -= jump; + } } -void ParticleManager::setFree(int free) +void ParticleManager::setFree(size_t free) { if (free != -1) { @@ -363,7 +365,7 @@ void ParticleManager::update(float dt) { BBGE_PROF(ParticleManager_update); numActive = 0; - for (int i = 0; i < particles.size(); i++) + for (size_t i = 0; i < particles.size(); i++) { if (particles[i].active) { diff --git a/BBGE/Particles.h b/BBGE/Particles.h index 4673257..7ce9503 100644 --- a/BBGE/Particles.h +++ b/BBGE/Particles.h @@ -198,7 +198,7 @@ class ParticleManager { public: ParticleManager(int size); - void setSize(int size); + void setSize(size_t size); void loadParticleBank(const std::string &bank1, const std::string &bank2); void clearParticleBank(); @@ -217,15 +217,15 @@ public: void endParticle(Particle *p); - void setFree(int free); + void setFree(size_t free); int getFree() { return free; } int getNumActive() { return numActive; } void setNumSuckPositions(int num); - void setSuckPosition(int idx, const Vector &pos); + void setSuckPosition(size_t idx, const Vector &pos); - Vector *getSuckPosition(int idx); + Vector *getSuckPosition(size_t idx); static std::string particleBankPath; @@ -234,18 +234,18 @@ protected: std::vector suckPositions; - int numActive; + size_t numActive; Particle* stomp(); void nextFree(int f=1); void prevFree(int f=1); - int oldFree; + size_t oldFree; typedef std::vector Influences; Influences influences; - int size, used, free, halfSize; + size_t size, used, free, halfSize; Particles particles; diff --git a/BBGE/Precacher.cpp b/BBGE/Precacher.cpp index 3e965d2..3602012 100644 --- a/BBGE/Precacher.cpp +++ b/BBGE/Precacher.cpp @@ -63,9 +63,10 @@ void Precacher::loadTextureRange(const std::string &file, const std::string &typ std::ostringstream os; os << file; - for (int j = 0; j < 4 - num_os.str().size(); j++) - { - os << "0"; + if(num_os.str().size() <= 4) { + for (size_t j = 0; j < 4 - num_os.str().size(); j++) { + os << "0"; + } } os << t; diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index cbbf700..92b3fde 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -74,7 +74,7 @@ void Quad::createStrip(bool vert, int num) void Quad::setStrip(const std::vector &st) { resetStrip(); - for (int i = 0; i < st.size(); i++) + for (size_t i = 0; i < st.size(); i++) { if (i < strip.size()) { @@ -92,10 +92,10 @@ void Quad::createGrid(int xd, int yd) yDivs = yd; drawGrid = new Vector * [xDivs]; - for (int i = 0; i < xDivs; i++) + for (size_t i = 0; i < xDivs; i++) { drawGrid[i] = new Vector [yDivs]; - for (int j = 0; j < yDivs; j++) + for (size_t j = 0; j < yDivs; j++) { drawGrid[i][j].z = 1; } @@ -104,9 +104,9 @@ void Quad::createGrid(int xd, int yd) resetGrid(); } -void Quad::setDrawGridAlpha(int x, int y, float alpha) +void Quad::setDrawGridAlpha(size_t x, size_t y, float alpha) { - if (x < xDivs && x >= 0 && y < yDivs && y >= 0) + if (x < xDivs && y < yDivs) { drawGrid[x][y].z = alpha; } @@ -116,13 +116,13 @@ void Quad::setGridPoints(bool vert, const std::vector &points) { if (!drawGrid) return; resetGrid(); - for (int i = 0; i < points.size(); i++) + for (size_t i = 0; i < points.size(); i++) { if (!vert) // horz { - for (int y = 0; y < yDivs; y++) + for (size_t y = 0; y < yDivs; y++) { - for (int x = 0; x < xDivs; x++) + for (size_t x = 0; x < xDivs; x++) { if (x < points.size()) { @@ -133,9 +133,9 @@ void Quad::setGridPoints(bool vert, const std::vector &points) } else { - for (int x = 0; x < xDivs; x++) + for (size_t x = 0; x < xDivs; x++) { - for (int y = 0; y < yDivs; y++) + for (size_t y = 0; y < yDivs; y++) { if (y < points.size()) { @@ -156,7 +156,7 @@ void Quad::resetStrip() { if (!stripVert) { - for (int i = 0; i < strip.size(); i++) + for (size_t i = 0; i < strip.size(); i++) { float v = (i/(float(strip.size()))); @@ -172,9 +172,9 @@ void Quad::resetStrip() void Quad::resetGrid() { - for (int i = 0; i < xDivs; i++) + for (size_t i = 0; i < xDivs; i++) { - for (int j = 0; j < yDivs; j++) + for (size_t j = 0; j < yDivs; j++) { drawGrid[i][j].x = i/(float)(xDivs-1)-0.5f; drawGrid[i][j].y = j/(float)(yDivs-1)-0.5f; @@ -226,7 +226,7 @@ void Quad::deleteGrid() { if (drawGrid) { - for (int i = 0; i < xDivs; i++) + for (size_t i = 0; i < xDivs; i++) { delete[] drawGrid[i]; } @@ -308,14 +308,14 @@ void Quad::updateGrid(float dt) { gridTimer += dt * drawGridTimeMultiplier; resetGrid(); - int hx = xDivs/2; - for (int x = 0; x < xDivs; x++) + size_t hx = xDivs/2; + for (size_t x = 0; x < xDivs; x++) { float yoffset = x * drawGridOffsetY; float addY = 0; if (drawGridModY != 0) addY = cosf(gridTimer+yoffset)*drawGridModY; - for (int y = 0; y < yDivs; y++) + for (size_t y = 0; y < yDivs; y++) { float xoffset = y * drawGridOffsetX; if (drawGridModX != 0) @@ -366,11 +366,11 @@ void Quad::renderGrid() glBegin(GL_QUADS); float u0 = baseX; float u1 = u0 + incX; - for (int i = 0; i < (xDivs-1); i++, u0 = u1, u1 += incX) + for (size_t 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) + for (size_t 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) { @@ -410,9 +410,10 @@ void Quad::renderGrid() glPointSize(2); glColor3f(1,0,0); glBegin(GL_POINTS); - for (int i = 0; i < (xDivs-1); i++) + if(xDivs > 0 && yDivs > 0) + for (size_t i = 0; i < (xDivs-1); i++) { - for (int j = 0; j < (yDivs-1); j++) + for (size_t 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); @@ -453,7 +454,7 @@ void Quad::onRender() if (!stripVert) { - for (int i = 0; i < strip.size(); i++) + for (size_t i = 0; i < strip.size(); i++) { glTexCoord2f(texBits*i, 0); glVertex2f(strip[i].x*width-_w2, strip[i].y*_h2*10 - _h2); @@ -469,7 +470,7 @@ void Quad::onRender() glPointSize(64); glBegin(GL_POINTS); - for (int i = 0; i < strip.size(); i++) + for (size_t i = 0; i < strip.size(); i++) { glVertex2f((strip[i].x*width)-_w2, strip[i].y*height); } diff --git a/BBGE/Quad.h b/BBGE/Quad.h index 861cd88..a443332 100644 --- a/BBGE/Quad.h +++ b/BBGE/Quad.h @@ -59,7 +59,7 @@ public: int getHeight() const {return int(height);} 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 setDrawGridAlpha(size_t x, size_t y, float alpha); void repeatTextureToFill(bool on); void refreshRepeatTextureToFill(); bool isRepeatingTextureToFill() const { return repeatingTextureToFill; } @@ -99,7 +99,7 @@ public: protected: bool repeatingTextureToFill; float gridTimer; - int xDivs, yDivs; + size_t xDivs, yDivs; Vector ** drawGrid; void resetGrid(); diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index 9feb216..f8a7fc9 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -32,7 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif bool RenderObject::renderCollisionShape = false; -int RenderObject::lastTextureApplied = 0; +size_t RenderObject::lastTextureApplied = 0; bool RenderObject::lastTextureRepeat = false; bool RenderObject::renderPaths = false; @@ -474,7 +474,7 @@ void RenderObject::enableMotionBlur(int sz, int off) motionBlurPositions.resize(sz); motionBlurFrameOffsetCounter = 0; motionBlurFrameOffset = off; - for (int i = 0; i < motionBlurPositions.size(); i++) + for (size_t i = 0; i < motionBlurPositions.size(); i++) { motionBlurPositions[i].position = position; motionBlurPositions[i].rotz = rotation.z; @@ -561,7 +561,7 @@ void RenderObject::render() Vector oldPos = position; float oldAlpha = alpha.x; float oldRotZ = rotation.z; - for (int i = 0; i < motionBlurPositions.size(); i++) + for (size_t i = 0; i < motionBlurPositions.size(); i++) { position = motionBlurPositions[i].position; rotation.z = motionBlurPositions[i].rotz; @@ -650,7 +650,7 @@ void RenderObject::renderCall() glLineWidth(4); glEnable(GL_BLEND); - int i = 0; + size_t i = 0; glColor4f(1.0f, 1.0f, 1.0f, 0.5f); glBindTexture(GL_TEXTURE_2D, 0); @@ -787,7 +787,7 @@ void RenderObject::renderCollision() glColor4f(1,1,0,0.5); - for (int i = 0; i < transformedCollisionMask.size(); i++) + for (size_t i = 0; i < transformedCollisionMask.size(); i++) { Vector collide = this->transformedCollisionMask[i]; @@ -840,11 +840,11 @@ void RenderObject::deathNotify(RenderObject *r) deathNotifications.remove(r); } -Vector RenderObject::getCollisionMaskNormal(int index) +Vector RenderObject::getCollisionMaskNormal(size_t index) { Vector sum; - int num=0; - for (int i = 0; i < this->transformedCollisionMask.size(); i++) + size_t num=0; + for (size_t i = 0; i < this->transformedCollisionMask.size(); i++) { if (i != index) { diff --git a/BBGE/RenderObject.h b/BBGE/RenderObject.h index f37ec44..b3f9927 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -135,8 +135,8 @@ public: bool isfhr(); bool isfvr(); - int getIdx() const { return idx; } - void setIdx(int idx) { this->idx = idx; } + size_t getIdx() const { return idx; } + void setIdx(size_t idx) { this->idx = idx; } void moveToFront(); void moveToBack(); @@ -217,13 +217,13 @@ public: virtual void unloadDevice(); virtual void reloadDevice(); - Vector getCollisionMaskNormal(int index); + Vector getCollisionMaskNormal(size_t index); //-------------------------------- Methods above, fields below static bool renderCollisionShape; static bool renderPaths; - static int lastTextureApplied; + static size_t lastTextureApplied; static bool lastTextureRepeat; float width, height; // Only used by Quads, but stored here for getCullRadius() @@ -331,7 +331,7 @@ protected: bool _static; bool _fv, _fh; - int idx; + size_t idx; RenderObject *parent; StateData *stateData; float decayRate; diff --git a/BBGE/RenderObjectLayer.cpp b/BBGE/RenderObjectLayer.cpp index 30ceb29..858fda3 100644 --- a/BBGE/RenderObjectLayer.cpp +++ b/BBGE/RenderObjectLayer.cpp @@ -63,7 +63,7 @@ void RenderObjectLayer::setOptimizeStatic(bool opt) void RenderObjectLayer::add(RenderObject* r) { - int size = renderObjects.size(); + size_t size = renderObjects.size(); if (firstFreeIdx >= size) { size += size/2; // Increase size by 50% each time we fill up. @@ -85,8 +85,8 @@ void RenderObjectLayer::add(RenderObject* r) void RenderObjectLayer::remove(RenderObject* r) { - const int idx = r->getIdx(); - if (idx < 0 || idx >= renderObjects.size()) + const size_t idx = r->getIdx(); + if (idx >= renderObjects.size()) { errorLog("Trying to remove RenderObject with invalid index"); return; @@ -107,9 +107,9 @@ void RenderObjectLayer::remove(RenderObject* r) void RenderObjectLayer::moveToFront(RenderObject *r) { - const int size = renderObjects.size(); - const int curIdx = r->getIdx(); - int lastUsed; + const size_t size = renderObjects.size(); + const size_t curIdx = r->getIdx(); + size_t lastUsed; for (lastUsed = size-1; lastUsed > curIdx; lastUsed--) { if (renderObjects[lastUsed]) @@ -122,7 +122,7 @@ void RenderObjectLayer::moveToFront(RenderObject *r) } else if (lastUsed < size-1) { - const int newIdx = lastUsed + 1; + const size_t newIdx = lastUsed + 1; renderObjects[curIdx] = 0; renderObjects[newIdx] = r; r->setIdx(newIdx); @@ -132,12 +132,12 @@ void RenderObjectLayer::moveToFront(RenderObject *r) else if (objectCount == size) { // Expand the array so future calls have a bit of breathing room. - const int newSize = size + 10; + const size_t newSize = size + 10; renderObjects.resize(newSize); renderObjects[curIdx] = 0; renderObjects[size] = r; r->setIdx(size); - for (int i = size+1; i < newSize; i++) + for (size_t i = size+1; i < newSize; i++) renderObjects[i] = 0; if (firstFreeIdx > curIdx) firstFreeIdx = curIdx; @@ -146,13 +146,13 @@ void RenderObjectLayer::moveToFront(RenderObject *r) { // Need to shift elements downward to make room for the new one. renderObjects[curIdx] = 0; - int lastFree; + size_t lastFree; for (lastFree = lastUsed-1; lastFree > curIdx; lastFree--) { if (!renderObjects[lastFree]) break; } - for (int i = lastFree + 1; i <= lastUsed; i++) + for (size_t i = lastFree + 1; i <= lastUsed; i++) { renderObjects[i-1] = renderObjects[i]; renderObjects[i-1]->setIdx(i-1); // Known to be non-NULL. @@ -170,9 +170,9 @@ void RenderObjectLayer::moveToFront(RenderObject *r) void RenderObjectLayer::moveToBack(RenderObject *r) { - const int size = renderObjects.size(); - const int curIdx = r->getIdx(); - int firstUsed; + const size_t size = renderObjects.size(); + const size_t curIdx = r->getIdx(); + size_t firstUsed; for (firstUsed = 0; firstUsed < curIdx; firstUsed++) { if (renderObjects[firstUsed]) @@ -196,19 +196,19 @@ void RenderObjectLayer::moveToBack(RenderObject *r) } else if (objectCount == size) { - const int newSize = size + 10; - const int sizeDiff = newSize - size; - const int newIdx = sizeDiff - 1; + const size_t newSize = size + 10; + const size_t sizeDiff = newSize - size; + const size_t newIdx = sizeDiff - 1; renderObjects.resize(newSize); renderObjects[curIdx] = 0; - for (int i = newSize - 1; i >= sizeDiff; i--) + for (size_t i = newSize - 1; i >= sizeDiff; i--) { renderObjects[i] = renderObjects[i - sizeDiff]; if(renderObjects[i]) renderObjects[i]->setIdx(i); } - for (int i = 0; i < newIdx; i++) + for (size_t i = 0; i < newIdx; i++) renderObjects[i] = 0; renderObjects[newIdx] = r; r->setIdx(newIdx); diff --git a/BBGE/Shader.cpp b/BBGE/Shader.cpp index b2a22aa..dccf685 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -327,9 +327,9 @@ bool Shader::Uniform::operator< (const Uniform& b) const void Shader::_queryUniforms() { - glGetObjectParameterivARB(g_programObj, GL_OBJECT_ACTIVE_UNIFORMS_ARB , &numUniforms); + glGetObjectParameterivARB(g_programObj, GL_OBJECT_ACTIVE_UNIFORMS_ARB , (GLint*)&numUniforms); - if (numUniforms <= 0) + if (numUniforms == 0 || numUniforms == -1) { uniforms.clear(); return; @@ -385,7 +385,7 @@ int Shader::_getUniformIndex(const char *name) void Shader::setInt(const char *name, int x, int y /* = 0 */, int z /* = 0 */, int w /* = 0 */) { #if BBGE_BUILD_SHADERS - if(!g_programObj || numUniforms <= 0) + if(!g_programObj || numUniforms == 0 || numUniforms == -1) return; int idx = _getUniformIndex(name); if(unsigned(idx) >= uniforms.size()) @@ -403,7 +403,7 @@ void Shader::setInt(const char *name, int x, int y /* = 0 */, int z /* = 0 */, i void Shader::setFloat(const char *name, float x, float y /* = 0 */, float z /* = 0 */, float w /* = 0 */) { #if BBGE_BUILD_SHADERS - if(!g_programObj || numUniforms <= 0) + if(!g_programObj || numUniforms == 0 || numUniforms == -1) return; int idx = _getUniformIndex(name); if(unsigned(idx) >= uniforms.size()) diff --git a/BBGE/Shader.h b/BBGE/Shader.h index eb9153d..4190224 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -46,7 +46,7 @@ protected: std::string vertFile, fragFile; std::string vertSrc, fragSrc; unsigned g_programObj; - int numUniforms; + unsigned numUniforms; private: static void staticInit(); @@ -58,7 +58,7 @@ private: struct Uniform { int location; // GL location variable - int type; + size_t type; bool dirty; // need to flush if true union { diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 003865a..a23978b 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -92,7 +92,7 @@ void Bone::destroy() { Quad::destroy(); - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { segments[i]->setLife(1.0); segments[i]->setDecayRate(10); @@ -246,7 +246,7 @@ void Bone::updateSegments() if (!reverse) { - for (int i = 0; i < segments.size(); i++) + for (size_t i = 0; i < segments.size(); i++) { Vector diff; if (i == 0) @@ -416,7 +416,7 @@ void AnimationLayer::animate(const std::string &a, int loop) stringToLower(animation); bool played = false; - for (int i = 0; i < s->animations.size(); i++) + for (size_t i = 0; i < s->animations.size(); i++) { if (s->animations[i].name == animation) { @@ -494,7 +494,7 @@ Animation* AnimationLayer::getCurrentAnimation() { if (currentAnimation == -1) return &blendAnimation; - if (currentAnimation < 0 || currentAnimation >= s->animations.size()) + if (currentAnimation >= s->animations.size()) { std::ostringstream os; os << "skel: " << s->filenameLoaded << " currentAnimation: " << currentAnimation << " is out of range\n error in anim file?"; @@ -512,7 +512,7 @@ bool AnimationLayer::createTransitionAnimation(const std::string& anim, float ti blendAnimation.keyframes.clear(); SkeletalKeyframe k; k.t = 0; - for (int i = 0; i < s->bones.size(); i++) + for (size_t i = 0; i < s->bones.size(); i++) { BoneKeyframe b; b.idx = s->bones[i]->boneIdx; @@ -566,14 +566,14 @@ Animation::Animation() { } -int Animation::getNumKeyframes() +size_t Animation::getNumKeyframes() { return keyframes.size(); } -SkeletalKeyframe *Animation::getKeyframe(int key) +SkeletalKeyframe *Animation::getKeyframe(size_t key) { - if (key < 0 || key >= keyframes.size()) return 0; + if (key >= keyframes.size()) return 0; return &keyframes[key]; } @@ -613,9 +613,9 @@ SkeletalKeyframe *Animation::getFirstKeyframe() void Animation::reorderKeyframes() { - for (int i = 0; i < keyframes.size(); i++) + for (size_t i = 0; i < keyframes.size(); i++) { - for (int j = 0; j < keyframes.size()-1; j++) + for (size_t j = 0; j < keyframes.size()-1; j++) { if (keyframes[j].t > keyframes[j+1].t) { @@ -627,11 +627,11 @@ void Animation::reorderKeyframes() } } -void Animation::cloneKey(int key, float toffset) +void Animation::cloneKey(size_t key, float toffset) { std::vector copy = this->keyframes; keyframes.clear(); - int i = 0; + size_t i = 0; for (i = 0; i <= key; i++) keyframes.push_back(copy[i]); for (i = key; i < copy.size(); i++) @@ -639,20 +639,20 @@ void Animation::cloneKey(int key, float toffset) keyframes[key+1].t += toffset; } -void Animation::deleteKey(int key) +void Animation::deleteKey(size_t key) { std::vector copy = this->keyframes; keyframes.clear(); - int i = 0; + size_t i = 0; for (i = 0; i < key; i++) keyframes.push_back(copy[i]); for (i = key+1; i < copy.size(); i++) keyframes.push_back(copy[i]); } -int Animation::getSkeletalKeyframeIndex(SkeletalKeyframe *skey) +size_t Animation::getSkeletalKeyframeIndex(SkeletalKeyframe *skey) { - for (int i = 0; i < keyframes.size(); i++) + for (size_t i = 0; i < keyframes.size(); i++) { if (&keyframes[i] == skey) return i; @@ -660,9 +660,9 @@ int Animation::getSkeletalKeyframeIndex(SkeletalKeyframe *skey) return -1; } -BoneKeyframe *SkeletalKeyframe::getBoneKeyframe(int idx) +BoneKeyframe *SkeletalKeyframe::getBoneKeyframe(size_t idx) { - for (int i = 0; i < keyframes.size(); i++) + for (size_t i = 0; i < keyframes.size(); i++) { if (keyframes[i].idx == idx) { @@ -674,8 +674,8 @@ BoneKeyframe *SkeletalKeyframe::getBoneKeyframe(int idx) SkeletalKeyframe *Animation::getPrevKeyframe(float t) { - int kf = -1; - for (int i = keyframes.size()-1; i >= 0; i--) + size_t kf = -1; + for (size_t i = keyframes.size(); i-- > 0; ) { if (t >= keyframes[i].t) { @@ -687,15 +687,13 @@ SkeletalKeyframe *Animation::getPrevKeyframe(float t) return 0; if (kf >= keyframes.size()) kf = keyframes.size()-1; - if (kf < 0) - kf = 0; return &keyframes[kf]; } SkeletalKeyframe *Animation::getNextKeyframe(float t) { - int kf = -1; - for (int i = 0; i < keyframes.size(); i++) + size_t kf = -1; + for (size_t i = 0; i < keyframes.size(); i++) { if (t <= keyframes[i].t) { @@ -708,8 +706,6 @@ SkeletalKeyframe *Animation::getNextKeyframe(float t) return 0; if (kf >= keyframes.size()) kf = keyframes.size()-1; - if (kf < 0) - kf = 0; return &keyframes[kf]; } @@ -719,7 +715,7 @@ SkeletalSprite::SkeletalSprite() : RenderObject() animKeyNotify = 0; loaded = false; animLayers.resize(10); - for (int i = 0; i < animLayers.size(); i++) + for (size_t i = 0; i < animLayers.size(); i++) animLayers[i].setSkeletalSprite(this); selectedBone = -1; } @@ -747,9 +743,9 @@ float SkeletalSprite::transitionAnimate(const std::string& anim, float time, int return 0; } -AnimationLayer* SkeletalSprite::getAnimationLayer(int l) +AnimationLayer* SkeletalSprite::getAnimationLayer(size_t l) { - if (l >= 0 && l < animLayers.size()) + if (l < animLayers.size()) { return &animLayers[l]; } @@ -769,7 +765,7 @@ void SkeletalSprite::onUpdate(float dt) if (frozen) return; RenderObject::onUpdate(dt); - int i = 0; + size_t i = 0; for (i = 0; i < bones.size(); i++) { @@ -780,7 +776,7 @@ void SkeletalSprite::onUpdate(float dt) { b->transformedCollisionMask.resize(b->collisionMask.size()); } - for (int i = 0; i < b->collisionMask.size(); i++) + for (size_t i = 0; i < b->collisionMask.size(); i++) { b->transformedCollisionMask[i] = b->getWorldCollidePosition(b->collisionMask[i]); } @@ -851,7 +847,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) file = animationPath + filename + ".xml"; } - int i = 0; + size_t i = 0; XMLDocument *xml = _retrieveSkeletalXML(file, true); xml->Clear(); @@ -862,7 +858,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) if (animLayers[i].ignoreBones.size() > 0) { std::ostringstream os; - for (int j = 0; j < animLayers[i].ignoreBones.size(); j++) + for (size_t j = 0; j < animLayers[i].ignoreBones.size(); j++) { os << animLayers[i].ignoreBones[j] << " "; } @@ -871,7 +867,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) if (animLayers[i].includeBones.size() > 0) { std::ostringstream os; - for (int j = 0; j < animLayers[i].includeBones.size(); j++) + for (size_t j = 0; j < animLayers[i].includeBones.size(); j++) { os << animLayers[i].includeBones[j] << " "; } @@ -891,7 +887,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) for (i = 0; i < this->bones.size(); i++) { XMLElement *bone = xml->NewElement("Bone"); - bone->SetAttribute("idx", this->bones[i]->boneIdx); + bone->SetAttribute("idx", (unsigned int) this->bones[i]->boneIdx); bone->SetAttribute("gfx", this->bones[i]->gfx.c_str()); bone->SetAttribute("pidx", this->bones[i]->pidx); bone->SetAttribute("name", this->bones[i]->name.c_str()); @@ -969,7 +965,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) animation->SetAttribute("name", a->name.c_str()); if(a->resetPassOnEnd) animation->SetAttribute("resetPassOnEnd", a->resetPassOnEnd); - for (int j = 0; j < a->keyframes.size(); j++) + for (size_t j = 0; j < a->keyframes.size(); j++) { XMLElement *key = xml->NewElement("Key"); if (!a->keyframes[j].sound.empty()) @@ -985,12 +981,12 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) std::ostringstream os; os << a->keyframes[j].t << " "; std::ostringstream szos; - for (int k = 0; k < a->keyframes[j].keyframes.size(); k++) + for (size_t k = 0; k < a->keyframes[j].keyframes.size(); k++) { BoneKeyframe *b = &a->keyframes[j].keyframes[k]; os << b->idx << " " << b->x << " " << b->y << " " << b->rot << " "; os << b->strip.size() << " "; - for (int i = 0; i < b->strip.size(); i++) + for (size_t i = 0; i < b->strip.size(); i++) { os << b->strip[i].x << " " << b->strip[i].y << " "; } @@ -1013,9 +1009,9 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) return xml->SaveFile(file.c_str()) == XML_SUCCESS; } -int SkeletalSprite::getBoneIdx(Bone *b) +size_t SkeletalSprite::getBoneIdx(Bone *b) { - for (int i = 0; i < bones.size(); i++) + for (size_t i = 0; i < bones.size(); i++) { if (bones[i] == b) return i; @@ -1023,9 +1019,9 @@ int SkeletalSprite::getBoneIdx(Bone *b) return -1; } -void SkeletalSprite::toggleBone(int idx, int v) +void SkeletalSprite::toggleBone(size_t idx, int v) { - if (idx >= 0 && idx < bones.size()) + if (idx < bones.size()) { bones[idx]->alpha.x = v; } @@ -1033,7 +1029,7 @@ void SkeletalSprite::toggleBone(int idx, int v) Bone *SkeletalSprite::getBoneByName(const std::string &name) { - for (int i = 0; i < bones.size(); i++) + for (size_t i = 0; i < bones.size(); i++) { if (bones[i]->name == name) return bones[i]; @@ -1044,9 +1040,9 @@ Bone *SkeletalSprite::getBoneByName(const std::string &name) return 0; } -Bone *SkeletalSprite::getBoneByIdx(int idx) +Bone *SkeletalSprite::getBoneByIdx(size_t idx) { - for (int i = 0; i < bones.size(); i++) + for (size_t i = 0; i < bones.size(); i++) { if (bones[i]->boneIdx == idx) return bones[i]; @@ -1102,7 +1098,7 @@ void SkeletalSprite::prevAnimation() { stopAnimation(); animLayers[0].currentAnimation--; - if (animLayers[0].currentAnimation < 0) + if (animLayers[0].currentAnimation >= animations.size()) animLayers[0].currentAnimation = animations.size()-1; } @@ -1117,7 +1113,7 @@ void SkeletalSprite::deleteBones() Animation *SkeletalSprite::getAnimation(const std::string& anim) { - for (int i = 0; i < animations.size(); i++) + for (size_t i = 0; i < animations.size(); i++) { if (animations[i].name == anim) return &animations[i]; @@ -1220,7 +1216,7 @@ void SkeletalSprite::stopAnimation(int layer) void SkeletalSprite::stopAllAnimations() { - for (int i = 0; i < animLayers.size(); i++) + for (size_t i = 0; i < animLayers.size(); i++) { animLayers[i].stopAnimation(); } @@ -1445,7 +1441,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) bone = bone->NextSiblingElement("Bone"); } // attach bones - for (int i = 0; i < this->bones.size(); i++) + for (size_t i = 0; i < this->bones.size(); i++) { Bone *b = this->bones[i]; if (b->pidx != -1) @@ -1545,7 +1541,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) if (strip>0) { b.strip.resize(strip); - for (int i = 0; i < b.strip.size(); i++) + for (size_t i = 0; i < b.strip.size(); i++) { is >> b.strip[i].x >> b.strip[i].y; @@ -1619,7 +1615,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) } } // generate empty bone keys - for (int i = 0; i < this->bones.size(); i++) + for (size_t i = 0; i < this->bones.size(); i++) { if (newSkeletalKeyframe.getBoneKeyframe(this->bones[i]->boneIdx)) { @@ -1640,12 +1636,12 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) } } -Animation *SkeletalSprite::getCurrentAnimation(int layer) +Animation *SkeletalSprite::getCurrentAnimation(size_t layer) { return layer < animLayers.size() ? animLayers[layer].getCurrentAnimation() : NULL; } -void SkeletalSprite::setTime(float time, int layer) +void SkeletalSprite::setTime(float time, size_t layer) { if(layer < animLayers.size()) animLayers[layer].timer = time; @@ -1653,7 +1649,7 @@ void SkeletalSprite::setTime(float time, int layer) void AnimationLayer::resetPass() { - for (int i = 0; i < s->bones.size(); i++) + for (size_t i = 0; i < s->bones.size(); i++) { Bone *b = s->bones[i]; if (contains(b)) @@ -1666,13 +1662,13 @@ bool AnimationLayer::contains(const Bone *b) const const int idx = b->boneIdx; if (!ignoreBones.empty()) { - for (int j = 0; j < ignoreBones.size(); j++) + for (size_t j = 0; j < ignoreBones.size(); j++) if (idx == ignoreBones[j]) return false; } else if (!includeBones.empty()) { - for (int j = 0; j < includeBones.size(); j++) + for (size_t j = 0; j < includeBones.size(); j++) if (idx == includeBones[j]) return true; return false; @@ -1708,7 +1704,7 @@ void AnimationLayer::updateBones() } if (!key2->commands.empty()) { - for (int i = 0; i < key2->commands.size(); i++) + for (size_t i = 0; i < key2->commands.size(); i++) { key2->commands[i].run(); } @@ -1720,7 +1716,7 @@ void AnimationLayer::updateBones() } lastNewKey = key2; - for (int i = 0; i < s->bones.size(); i++) + for (size_t i = 0; i < s->bones.size(); i++) { Bone *b = s->bones[i]; @@ -1772,7 +1768,7 @@ void AnimationLayer::updateBones() bkey2->strip.resize(b->changeStrip.size()); if (bkey1->strip.size() < b->changeStrip.size()) bkey1->strip.resize(b->changeStrip.size()); - for (int i = 0; i < b->changeStrip.size(); i++) + for (size_t i = 0; i < b->changeStrip.size(); i++) { b->changeStrip[i] = Vector(lerp(bkey1->strip[i].x, bkey2->strip[i].x, dt, lerpType), lerp(bkey1->strip[i].y, bkey2->strip[i].y, dt, lerpType)); } @@ -1794,7 +1790,7 @@ void SkeletalSprite::updateBones() { if (!frozen) { - for (int i = 0; i < animLayers.size(); i++) + for (size_t i = 0; i < animLayers.size(); i++) { animLayers[i].updateBones(); } @@ -1821,7 +1817,7 @@ Bone* SkeletalSprite::getSelectedBone(bool mouseBased) float closestDist = HUGE_VALF; Bone *b = 0; Vector p = core->mouse.position; - for (int i = 0; i < bones.size(); i++) + for (size_t i = 0; i < bones.size(); i++) { if (bones[i]->renderQuad || core->getShiftState()) { @@ -1845,7 +1841,7 @@ Bone* SkeletalSprite::getSelectedBone(bool mouseBased) return b; } // else - if (!bones.empty() && selectedBone >= 0 && selectedBone < bones.size()) + if (!bones.empty() && selectedBone < bones.size()) return bones[selectedBone]; return 0; @@ -1854,7 +1850,7 @@ Bone* SkeletalSprite::getSelectedBone(bool mouseBased) void SkeletalSprite::updateSelectedBoneColor() { - for (int i = 0; i < bones.size(); i++) + for (size_t i = 0; i < bones.size(); i++) { bones[i]->color = Vector(1,1,1); } @@ -1871,7 +1867,7 @@ void SkeletalSprite::setSelectedBone(int b) void SkeletalSprite::selectPrevBone() { - const int oldsel = selectedBone; + const size_t oldsel = selectedBone; do { selectedBone++; @@ -1886,13 +1882,13 @@ void SkeletalSprite::selectPrevBone() void SkeletalSprite::selectNextBone() { - const int oldsel = selectedBone; + const size_t oldsel = selectedBone; do { selectedBone--; if(selectedBone == oldsel) break; - if (selectedBone < 0) + if (selectedBone >= bones.size()) selectedBone = bones.size()-1; } while (!bones[selectedBone]->selectable); diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index fc92a9c..869e1fb 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -60,7 +60,8 @@ public: void destroy(); std::string gfx; std::string name; - int boneIdx, pidx, rbp; + size_t boneIdx; + int pidx, rbp; std::string prt; std::vector changeStrip; @@ -109,7 +110,8 @@ class BoneKeyframe { public: BoneKeyframe() : idx(0), x(0), y(0), rot(0), sx(1), sy(1), doScale(0) {} - int idx, x, y, rot; + size_t idx; + int x, y, rot; float sx, sy; bool doScale; std::vector strip; @@ -127,7 +129,7 @@ public: float t; std::string sound; std::vector keyframes; - BoneKeyframe *getBoneKeyframe(int idx); + BoneKeyframe *getBoneKeyframe(size_t idx); std::string cmd; std::vector commands; @@ -141,17 +143,17 @@ public: std::string name; typedef std::vector Keyframes; Keyframes keyframes; - SkeletalKeyframe *getKeyframe(int key); + SkeletalKeyframe *getKeyframe(size_t key); SkeletalKeyframe *getLastKeyframe(); SkeletalKeyframe *getFirstKeyframe(); SkeletalKeyframe *getPrevKeyframe(float t); SkeletalKeyframe *getNextKeyframe(float t); - void cloneKey(int key, float toffset); - void deleteKey(int key); + void cloneKey(size_t key, float toffset); + void deleteKey(size_t key); void reorderKeyframes(); float getAnimationLength(); - int getSkeletalKeyframeIndex(SkeletalKeyframe *skey); - int getNumKeyframes(); + size_t getSkeletalKeyframeIndex(SkeletalKeyframe *skey); + size_t getNumKeyframes(); void reverse(); bool resetPassOnEnd; }; @@ -200,7 +202,7 @@ public: //HACK: should be a lerped float InterpolatedVector timeMultiplier; float animationLength; - int currentAnimation; + size_t currentAnimation; bool animating; @@ -215,13 +217,13 @@ public: bool saveSkeletal(const std::string &fn); void loadSkin(const std::string &fn); - Bone *getBoneByIdx(int idx); + Bone *getBoneByIdx(size_t idx); Bone *getBoneByName(const std::string &name); void animate(const std::string &animation, int loop = 0, int layer=0); - void setTime(float time, int layer=0); + void setTime(float time, size_t layer=0); void updateBones(); void playCurrentAnimation(int loop=0, int layer=0); @@ -235,7 +237,7 @@ public: void setTimeMultiplier(float t, int layer=0); Bone* getSelectedBone(bool mouseBased = true); - Animation *getCurrentAnimation(int layer=0); + Animation *getCurrentAnimation(size_t layer=0); void nextAnimation(); @@ -262,9 +264,9 @@ public: bool isLoaded(); int getNumAnimLayers() const { return animLayers.size(); } - AnimationLayer* getAnimationLayer(int l); - int getBoneIdx(Bone *b); - void toggleBone(int idx, int v); + AnimationLayer* getAnimationLayer(size_t l); + size_t getBoneIdx(Bone *b); + void toggleBone(size_t idx, int v); void setAnimationKeyNotify(RenderObject *r); @@ -277,7 +279,7 @@ protected: bool frozen; RenderObject *animKeyNotify; bool loaded; - int selectedBone; + size_t selectedBone; friend class AnimationLayer; std::vector animLayers; Bone* initBone(int idx, std::string gfx, int pidx, int rbp=0, std::string name="", float cr=0, bool fh=false, bool fv=false); diff --git a/BBGE/SoundManager.cpp b/BBGE/SoundManager.cpp index a8d0c37..f64dfc7 100644 --- a/BBGE/SoundManager.cpp +++ b/BBGE/SoundManager.cpp @@ -1373,8 +1373,8 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s f = adjustFilenameCase(f); } - int loc = f.find_last_of('/'); - int loc2 = f.rfind('.'); + size_t loc = f.find_last_of('/'); + size_t loc2 = f.rfind('.'); if (loc != std::string::npos && loc2 != std::string::npos) { name = f.substr(loc+1, loc2-(loc+1)); diff --git a/BBGE/StateManager.cpp b/BBGE/StateManager.cpp index 9188e0b..979daa3 100644 --- a/BBGE/StateManager.cpp +++ b/BBGE/StateManager.cpp @@ -68,7 +68,7 @@ StateData::StateData() StateData::~StateData() { - for (int i = 0; i < renderObjects.size(); i++) + for (size_t i = 0; i < renderObjects.size(); i++) { removeRenderObject (renderObjects[i]); delete renderObjects[i]; @@ -111,7 +111,7 @@ void StateData::eraseRenderObjects() // why clear garbage here? //core->clearGarbage(); - for (int i = 0; i < renderObjects.size(); i++) + for (size_t i = 0; i < renderObjects.size(); i++) { RenderObject *r = renderObjects[i]; if (r && !r->isDead()) @@ -274,7 +274,7 @@ StateObject *StateManager::addStateInstance(StateObject *s) void StateManager::clearStateInstances() { - for (int i = 0; i < stateInstances.size(); i++) + for (size_t i = 0; i < stateInstances.size(); i++) { StateObject *obj = stateInstances[i]; delete obj; diff --git a/BBGE/Strings.cpp b/BBGE/Strings.cpp new file mode 100644 index 0000000..ca21f7b --- /dev/null +++ b/BBGE/Strings.cpp @@ -0,0 +1,173 @@ +/* +Copyright (C) 2007, 2010 - Bit-Blot + +This file is part of Aquaria. + +Aquaria is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "Core.h" + +typedef std::map InputCodeMap; + +InputCodeMap inputCodeMap; + +void initInputCodeMap() +{ + inputCodeMap["0"] = 0; + + inputCodeMap["KEY_A"] = KEY_A; + inputCodeMap["KEY_B"] = KEY_B; + inputCodeMap["KEY_C"] = KEY_C; + inputCodeMap["KEY_D"] = KEY_D; + inputCodeMap["KEY_E"] = KEY_E; + inputCodeMap["KEY_F"] = KEY_F; + inputCodeMap["KEY_G"] = KEY_G; + inputCodeMap["KEY_H"] = KEY_H; + inputCodeMap["KEY_I"] = KEY_I; + inputCodeMap["KEY_J"] = KEY_J; + inputCodeMap["KEY_K"] = KEY_K; + inputCodeMap["KEY_L"] = KEY_L; + inputCodeMap["KEY_M"] = KEY_M; + inputCodeMap["KEY_N"] = KEY_N; + inputCodeMap["KEY_O"] = KEY_O; + inputCodeMap["KEY_P"] = KEY_P; + inputCodeMap["KEY_Q"] = KEY_Q; + inputCodeMap["KEY_R"] = KEY_R; + inputCodeMap["KEY_S"] = KEY_S; + inputCodeMap["KEY_T"] = KEY_T; + inputCodeMap["KEY_U"] = KEY_U; + inputCodeMap["KEY_V"] = KEY_V; + inputCodeMap["KEY_W"] = KEY_W; + inputCodeMap["KEY_X"] = KEY_X; + inputCodeMap["KEY_Y"] = KEY_Y; + inputCodeMap["KEY_Z"] = KEY_Z; + + inputCodeMap["KEY_1"] = KEY_1; + inputCodeMap["KEY_2"] = KEY_2; + inputCodeMap["KEY_3"] = KEY_3; + inputCodeMap["KEY_4"] = KEY_4; + inputCodeMap["KEY_5"] = KEY_5; + inputCodeMap["KEY_6"] = KEY_6; + inputCodeMap["KEY_7"] = KEY_7; + inputCodeMap["KEY_8"] = KEY_8; + inputCodeMap["KEY_9"] = KEY_9; + inputCodeMap["KEY_0"] = KEY_0; + + inputCodeMap["KEY_NUMPAD1"] = KEY_NUMPAD1; + inputCodeMap["KEY_NUMPAD2"] = KEY_NUMPAD2; + inputCodeMap["KEY_NUMPAD3"] = KEY_NUMPAD3; + inputCodeMap["KEY_NUMPAD4"] = KEY_NUMPAD4; + inputCodeMap["KEY_NUMPAD5"] = KEY_NUMPAD5; + inputCodeMap["KEY_NUMPAD6"] = KEY_NUMPAD6; + inputCodeMap["KEY_NUMPAD7"] = KEY_NUMPAD7; + inputCodeMap["KEY_NUMPAD8"] = KEY_NUMPAD8; + inputCodeMap["KEY_NUMPAD9"] = KEY_NUMPAD9; + inputCodeMap["KEY_NUMPAD0"] = KEY_NUMPAD0; + + inputCodeMap["KEY_F1"] = KEY_F1; + inputCodeMap["KEY_F2"] = KEY_F2; + inputCodeMap["KEY_F3"] = KEY_F3; + inputCodeMap["KEY_F4"] = KEY_F4; + inputCodeMap["KEY_F5"] = KEY_F5; + inputCodeMap["KEY_F6"] = KEY_F6; + inputCodeMap["KEY_F7"] = KEY_F7; + inputCodeMap["KEY_F8"] = KEY_F8; + inputCodeMap["KEY_F9"] = KEY_F9; + inputCodeMap["KEY_F10"] = KEY_F10; + inputCodeMap["KEY_F11"] = KEY_F11; + inputCodeMap["KEY_F12"] = KEY_F12; + + inputCodeMap["KEY_LEFT"] = KEY_LEFT; + inputCodeMap["KEY_RIGHT"] = KEY_RIGHT; + inputCodeMap["KEY_UP"] = KEY_UP; + inputCodeMap["KEY_DOWN"] = KEY_DOWN; + + inputCodeMap["KEY_SPACE"] = KEY_SPACE; + inputCodeMap["KEY_LCONTROL"] = KEY_LCONTROL; + inputCodeMap["KEY_RCONTROL"] = KEY_RCONTROL; + inputCodeMap["KEY_LSHIFT"] = KEY_LSHIFT; + inputCodeMap["KEY_RSHIFT"] = KEY_RSHIFT; + inputCodeMap["KEY_LMETA"] = KEY_LMETA; + inputCodeMap["KEY_RMETA"] = KEY_RMETA; + inputCodeMap["KEY_LALT"] = KEY_LALT; + inputCodeMap["KEY_RALT"] = KEY_RALT; + inputCodeMap["KEY_RETURN"] = KEY_RETURN; + inputCodeMap["KEY_TAB"] = KEY_TAB; + + inputCodeMap["KEY_ESCAPE"] = KEY_ESCAPE; + + inputCodeMap["MOUSE_BUTTON_LEFT"] = ActionMapper::MOUSE_BUTTON_LEFT; + inputCodeMap["MOUSE_BUTTON_RIGHT"] = ActionMapper::MOUSE_BUTTON_RIGHT; + inputCodeMap["MOUSE_BUTTON_MIDDLE"] = ActionMapper::MOUSE_BUTTON_MIDDLE; + + for (int i = 0; i < 17; i++) + { + std::ostringstream os; + os << "JOY_BUTTON_" << i; + inputCodeMap[os.str()] = ActionMapper::JOY1_BUTTON_0+i; + } +} + +void clearInputCodeMap() +{ + inputCodeMap.clear(); +} + +std::string getInputCodeToString(int key) +{ + for (InputCodeMap::iterator i = inputCodeMap.begin(); i != inputCodeMap.end(); i++) + { + if ((*i).second == key) + { + return (*i).first; + } + } + return ""; +} + +// FIXME: Move stringbank to BBGE and move these strings into it. -- fg + +std::string getInputCodeToUserString(int key) +{ + for (InputCodeMap::iterator i = inputCodeMap.begin(); i != inputCodeMap.end(); i++) + { + if ((*i).second == key) + { + std::string use = (*i).first; + size_t idx = 0; + idx = use.find("KEY_"); + if (idx != std::string::npos) + { + use = use.substr(4, use.size()); + } + if (use == "MOUSE_BUTTON_LEFT") + use = "Left Mouse Button"; + if (use == "MOUSE_BUTTON_RIGHT") + use = "Right Mouse Button"; + if (use == "MOUSE_BUTTON_MIDDLE") + use = "Middle Mouse Button"; + + return use; + + } + } + return ""; +} + +int getStringToInputCode(const std::string &string) +{ + return inputCodeMap[string]; +} diff --git a/BBGE/TTFFont.cpp b/BBGE/TTFFont.cpp index 1501b99..a80b801 100644 --- a/BBGE/TTFFont.cpp +++ b/BBGE/TTFFont.cpp @@ -235,7 +235,7 @@ float TTFText::getLineHeight() int TTFText::findLine(const std::string &label) { - for (int i = 0; i < text.size(); i++) + for (size_t i = 0; i < text.size(); i++) { if (text[i].find(label) != std::string::npos) { @@ -249,7 +249,7 @@ void TTFText::onRender() { - for (int i = 0; i < text.size(); i++) + for (size_t i = 0; i < text.size(); i++) { if (shadow) { diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index a9af97b..69ef2e0 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -147,7 +147,7 @@ int Texture::getPixelWidth() if (!data) return 0; - int smallestx = -1, largestx = -1; + size_t smallestx = -1, largestx = 0; for (unsigned int x = 0; x < unsigned(w); x++) { for (unsigned int y = 0; y < unsigned(h); y++) @@ -155,9 +155,9 @@ int Texture::getPixelWidth() unsigned int p = (y*unsigned(w)*4) + (x*4) + 3; if (p < size && data[p] >= 254) { - if (smallestx == -1 || x < smallestx) + if (x < smallestx) smallestx = x; - if (largestx == -1 || x > largestx) + if (x > largestx) largestx = x; } } @@ -174,17 +174,17 @@ int Texture::getPixelHeight() if (!data) return 0; - int smallesty = -1, largesty = -1; + size_t smallesty = -1, largesty = 0; for (unsigned int x = 0; x < unsigned(w); x++) { for (unsigned int y = 0; y < unsigned(h); y++) { - int p = (y*unsigned(w)*4) + (x*4) + 3; + size_t p = (y*unsigned(w)*4) + (x*4) + 3; if (p < size && data[p] >= 254) { - if (smallesty == -1 || y < smallesty) + if (y < smallesty) smallesty = y; - if (largesty == -1 || y > largesty) + if (y > largesty) largesty = y; } } @@ -427,9 +427,9 @@ ImageTGA *Texture::TGAloadMem(void *mem, int size) byte length = 0; // The length in bytes to the pixels byte imageType = 0; // The image type (RLE, RGB, Alpha...) byte bits = 0; // The bits per pixel for the image (16, 24, 32) - int channels = 0; // The channels of the image (3 = RGA : 4 = RGBA) - int stride = 0; // The stride (channels * width) - int i = 0; // A counter + uint32_t channels = 0; // The channels of the image (3 = RGA : 4 = RGBA) + uint32_t stride = 0; // The stride (channels * width) + size_t i = 0; // A counter // This function loads in a TARGA (.TGA) file and returns its data to be // used as a texture or what have you. This currently loads in a 16, 24 diff --git a/BBGE/Vector.cpp b/BBGE/Vector.cpp index bb365c4..ad163ae 100644 --- a/BBGE/Vector.cpp +++ b/BBGE/Vector.cpp @@ -179,7 +179,7 @@ void VectorPath::realPercentageCalc() { float totalLen = getLength(); float len = 0; - for (int i = 1; i < pathNodes.size(); i++) + for (size_t i = 1; i < pathNodes.size(); i++) { Vector diff = pathNodes[i].value - pathNodes[i-1].value; len += diff.getLength2D(); @@ -202,7 +202,7 @@ float VectorPath::getSubSectionLength(int startIncl, int endIncl) float VectorPath::getLength() { float len = 0; - for (int i = 1; i < pathNodes.size(); i++) + for (size_t i = 1; i < pathNodes.size(); i++) { Vector diff = pathNodes[i].value - pathNodes[i-1].value; len += diff.getLength2D(); @@ -219,7 +219,7 @@ void VectorPath::splice(const VectorPath &path, int sz) { std::vector copy = pathNodes; pathNodes.clear(); - int i = 0; + size_t i = 0; for (i = 0; i < path.pathNodes.size(); i++) pathNodes.push_back(path.pathNodes[i]); for (i = sz+1; i < copy.size(); i++) @@ -240,7 +240,7 @@ void VectorPath::prepend(const VectorPath &path) { std::vector copy = pathNodes; pathNodes.clear(); - int i = 0; + size_t i = 0; for (i = 0; i < path.pathNodes.size(); i++) pathNodes.push_back(path.pathNodes[i]); for (i = 0; i < copy.size(); i++) @@ -249,7 +249,7 @@ void VectorPath::prepend(const VectorPath &path) void VectorPath::calculatePercentages() { - for (int i = 0; i < pathNodes.size(); i++) + for (size_t i = 0; i < pathNodes.size(); i++) { pathNodes[i].percent = i/float(pathNodes.size()); } @@ -259,7 +259,7 @@ void VectorPath::append(const VectorPath &path) { std::vector copy = pathNodes; pathNodes.clear(); - int i = 0; + size_t i = 0; for (i = 0; i < copy.size(); i++) pathNodes.push_back(copy[i]); for (i = 0; i < path.pathNodes.size(); i++) @@ -270,7 +270,7 @@ void VectorPath::cut(int n) { std::vector copy = pathNodes; pathNodes.clear(); - for (int i = 0; i < copy.size(); i+=n) + for (size_t i = 0; i < copy.size(); i+=n) { pathNodes.push_back(copy[i]); } @@ -292,7 +292,7 @@ Vector VectorPath::getValue(float usePercent) VectorPathNode *target = 0; VectorPathNode *from = &pathNodes[0]; - for (int i = 0; i < pathNodes.size(); ++i) + for (size_t i = 0; i < pathNodes.size(); ++i) { if (pathNodes[i].percent >= usePercent) { diff --git a/BBGE/Vector.h b/BBGE/Vector.h index cd57b9b..51a147a 100644 --- a/BBGE/Vector.h +++ b/BBGE/Vector.h @@ -375,9 +375,9 @@ public: void clear(); void addPathNode(Vector v, float p); Vector getValue(float percent); - int getNumPathNodes() { return pathNodes.size(); } + size_t getNumPathNodes() { return pathNodes.size(); } void resizePathNodes(int sz) { pathNodes.resize(sz); } - VectorPathNode *getPathNode(int i) { if (i= 0) return &pathNodes[i]; return 0; } + VectorPathNode *getPathNode(size_t i) { if (i void ToLittleEndian(T*); // will generate link error template void ToBigEndian(T*); // will generate link error -}; +} #ifdef BB_OLD_GNUC # define BB_MAKE_WRITE_OP(T) inline ByteBuffer& operator<<(T val) { appendT(&val, sizeof(T)); return *this; } diff --git a/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.h b/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.h index 1e5b1fc..85580e1 100644 --- a/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.h +++ b/ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.h @@ -30,7 +30,7 @@ namespace ttvfs { class File; class Root; -}; +} typedef ttvfs::File VFILE;