From b9d402199c46dba9ab5ca448ff84ea89bf1e6894 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Sat, 14 Jan 2017 18:10:20 +0100 Subject: [PATCH 1/6] Get rid of a lot of gcc warnings Mostly signed/unsigned comparisons. Also some bugs, but I don't remember where :D --- Aquaria/AnimationEditor.cpp | 47 ++--- Aquaria/AquariaComboBox.cpp | 20 +- Aquaria/AquariaMenuItem.h | 6 +- Aquaria/AutoMap.cpp | 3 - Aquaria/Avatar.cpp | 76 ++++--- Aquaria/Avatar.h | 8 +- Aquaria/BitBlotLogo.cpp | 8 +- Aquaria/CollideEntity.cpp | 2 +- Aquaria/Continuity.cpp | 104 +++++----- Aquaria/Credits.cpp | 8 +- Aquaria/DSQ.cpp | 63 +++--- Aquaria/DSQ.h | 30 +-- Aquaria/Demo.cpp | 1 - Aquaria/Element.cpp | 12 +- Aquaria/Element.h | 2 +- Aquaria/Emote.cpp | 4 +- Aquaria/Entity.cpp | 28 +-- Aquaria/Entity.h | 4 +- Aquaria/FlockEntity.cpp | 6 +- Aquaria/FlockEntity.h | 2 +- Aquaria/Game.cpp | 230 +++++++++++----------- Aquaria/Game.h | 32 +-- Aquaria/GridRender.cpp | 6 +- Aquaria/Hair.cpp | 8 +- Aquaria/Intro.cpp | 8 +- Aquaria/MiniMapRender.cpp | 4 +- Aquaria/ModDownloader.cpp | 3 +- Aquaria/ModSelector.cpp | 10 +- Aquaria/ModSelector.h | 4 +- Aquaria/Network.h | 3 +- Aquaria/Path.cpp | 14 +- Aquaria/Path.h | 6 +- Aquaria/PathFinding.cpp | 13 +- Aquaria/PathFinding.h | 2 +- Aquaria/PathRender.cpp | 10 +- Aquaria/RecipeMenuEntry.cpp | 30 +-- Aquaria/SceneEditor.cpp | 106 +++++----- Aquaria/ScriptInterface.cpp | 27 +-- Aquaria/ScriptedEntity.cpp | 18 +- Aquaria/ScriptedEntity.h | 10 +- Aquaria/Segmented.cpp | 12 +- Aquaria/Segmented.h | 4 +- Aquaria/States.cpp | 4 +- Aquaria/States.h | 4 +- Aquaria/StatsAndAchievements.cpp | 10 +- Aquaria/Strand.cpp | 6 +- Aquaria/StringBank.cpp | 2 +- Aquaria/UserSettings.cpp | 10 +- Aquaria/UserSettings.h | 4 +- Aquaria/Web.cpp | 27 ++- Aquaria/Web.h | 4 +- Aquaria/WorldMapRender.cpp | 2 +- Aquaria/WorldMapTiles.cpp | 12 +- BBGE/ActionMapper.cpp | 6 +- BBGE/ActionSet.cpp | 8 +- BBGE/AfterEffect.cpp | 4 +- BBGE/Base.cpp | 24 +-- BBGE/Base.h | 2 +- BBGE/BitmapFont.cpp | 12 +- BBGE/BitmapFont.h | 6 +- BBGE/Core.cpp | 53 ++--- BBGE/Core.h | 12 +- BBGE/DebugFont.cpp | 4 +- BBGE/FmodOpenALBridge.cpp | 4 +- BBGE/LensFlare.cpp | 2 +- BBGE/MathFunctions.h | 2 +- BBGE/ParticleManager.cpp | 14 +- BBGE/Particles.h | 12 +- BBGE/Precacher.cpp | 7 +- BBGE/Quad.cpp | 45 ++--- BBGE/Quad.h | 4 +- BBGE/RenderObject.cpp | 16 +- BBGE/RenderObject.h | 10 +- BBGE/RenderObjectLayer.cpp | 38 ++-- BBGE/Shader.cpp | 2 +- BBGE/Shader.h | 4 +- BBGE/SkeletalSprite.cpp | 124 ++++++------ BBGE/SkeletalSprite.h | 34 ++-- BBGE/SoundManager.cpp | 4 +- BBGE/StateManager.cpp | 6 +- BBGE/Strings.cpp | 2 +- BBGE/TTFFont.cpp | 4 +- BBGE/Texture.cpp | 20 +- BBGE/Vector.cpp | 16 +- BBGE/Vector.h | 4 +- BBGE/bithacks.h | 2 +- ExternalLibs/ByteBuffer.h | 2 +- ExternalLibs/ttvfs_cfileapi/ttvfs_stdio.h | 2 +- 88 files changed, 780 insertions(+), 810 deletions(-) diff --git a/Aquaria/AnimationEditor.cpp b/Aquaria/AnimationEditor.cpp index a5aa7a2..fb761ca 100644 --- a/Aquaria/AnimationEditor.cpp +++ b/Aquaria/AnimationEditor.cpp @@ -503,11 +503,12 @@ void AnimationEditor::undo() if (core->getCtrlState()) { - if (undoEntry >= 0 && undoEntry < undoHistory.size()) + if (undoEntry < undoHistory.size()) { editSprite->animations = undoHistory[undoEntry].animations; - undoEntry--; - if (undoEntry<0) undoEntry = 0; + if(undoEntry > 0) { + undoEntry--; + } } } } @@ -519,9 +520,8 @@ void AnimationEditor::redo() if (core->getCtrlState()) { undoEntry++; - if (undoEntry >= 0 && undoEntry < undoHistory.size()) + if (undoEntry < undoHistory.size()) { - editSprite->animations = undoHistory[undoEntry].animations; } else @@ -587,7 +587,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); @@ -709,7 +709,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) @@ -828,14 +828,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(); } @@ -858,15 +859,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(); } @@ -1014,7 +1015,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) @@ -1027,9 +1028,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) @@ -1114,7 +1115,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) @@ -1126,9 +1127,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) @@ -1196,7 +1197,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) @@ -1208,9 +1209,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) @@ -1366,7 +1367,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/AquariaComboBox.cpp b/Aquaria/AquariaComboBox.cpp index ef47181..803af98 100644 --- a/Aquaria/AquariaComboBox.cpp +++ b/Aquaria/AquariaComboBox.cpp @@ -77,7 +77,7 @@ void AquariaComboBox::enqueueSelectItem(int index) enqueuedSelectItem = index; } -void AquariaComboBox::setScroll(int sc) +void AquariaComboBox::setScroll(size_t sc) { scroll = sc; } @@ -93,10 +93,8 @@ void AquariaComboBox::doScroll(int t) { if (t == 0) { - scroll--; - if (scroll < 0) scroll = 0; - else - { + if(scroll > 0) { + scroll--; close(0); open(0); } @@ -229,7 +227,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()) { @@ -254,7 +252,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); } @@ -262,7 +260,7 @@ void AquariaComboBox::close(float t) if (t>0) dsq->main(t); - for(int i = 0; i < shownItems.size(); i++) + for(size_t i = 0; i < shownItems.size(); i++) { removeChild(shownItems[i]); shownItems[i]->destroy(); @@ -277,7 +275,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) { @@ -300,9 +298,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.h b/Aquaria/AquariaMenuItem.h index fc8beb4..fdc9ad5 100644 --- a/Aquaria/AquariaMenuItem.h +++ b/Aquaria/AquariaMenuItem.h @@ -221,13 +221,13 @@ 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); protected: void onUpdate(float dt); - int numDrops; + size_t numDrops; bool mb, isopen; int scroll; @@ -239,7 +239,7 @@ protected: Quad *bar, *window, *scrollBtnUp, *scrollBtnDown, *scrollBar; BitmapText *selectedItemLabel; - int selectedItem; + size_t selectedItem; float scrollDelay; bool firstScroll; Vector textscale; diff --git a/Aquaria/AutoMap.cpp b/Aquaria/AutoMap.cpp index 5e32162..0a5a280 100644 --- a/Aquaria/AutoMap.cpp +++ b/Aquaria/AutoMap.cpp @@ -171,9 +171,6 @@ void AutoMap::onUpdate(float dt) const float maxScale=1.25, minScale=0.5; blip.update(dt); - - - Vector sTarget=scale; float spd = 0.5; if (core->mouse.scrollWheelChange < 0) { diff --git a/Aquaria/Avatar.cpp b/Aquaria/Avatar.cpp index 0ff37d2..5e6e6af 100644 --- a/Aquaria/Avatar.cpp +++ b/Aquaria/Avatar.cpp @@ -43,9 +43,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; @@ -233,7 +233,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; @@ -269,7 +269,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) { @@ -302,7 +302,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; @@ -571,7 +571,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()) @@ -622,7 +622,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()) @@ -1216,7 +1216,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) { @@ -1284,7 +1284,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(); } @@ -1310,7 +1310,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(); } @@ -1320,7 +1320,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) { @@ -1347,7 +1347,7 @@ void Avatar::openSingingInterface() 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(); } @@ -1380,7 +1380,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(); } @@ -1470,7 +1470,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(); @@ -1622,17 +1622,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(); @@ -1756,7 +1754,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) @@ -1803,7 +1801,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)) @@ -1830,7 +1828,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; @@ -1887,7 +1885,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) @@ -1905,7 +1903,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) @@ -1949,7 +1947,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() @@ -2009,7 +2007,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) @@ -2031,7 +2029,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) @@ -2063,7 +2061,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) { @@ -2104,7 +2102,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) { @@ -2215,7 +2213,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) @@ -2858,9 +2856,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) @@ -2884,14 +2882,14 @@ void Avatar::doShock(const std::string &shotName) - int c = 0; + size_t c = 0; //int maxHit = 2 + dsq->continuity.getSpellLevel(SPELL_SHOCK)*2; //int maxHit = 4; std::vector entitiesToHit; std::vector localTargets; bool clearTargets = true; - int thits = getNumShots(); + size_t thits = getNumShots(); /* if (skeletalSprite.getAnimationLayer(ANIMLAYER_FLOURISH)->getCurrentAnimation()) @@ -2903,7 +2901,7 @@ void Avatar::doShock(const std::string &shotName) 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); } @@ -2945,7 +2943,7 @@ void Avatar::doShock(const std::string &shotName) { while (entitiesToHit.size()game->fireShot(shotName, this, 0); @@ -2984,7 +2982,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; @@ -3833,7 +3831,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); @@ -7022,7 +7020,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 ccdee0e..264f345 100644 --- a/Aquaria/Avatar.h +++ b/Aquaria/Avatar.h @@ -76,7 +76,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: @@ -86,9 +86,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 f94573e..8975b7a 100644 --- a/Aquaria/BitBlotLogo.cpp +++ b/Aquaria/BitBlotLogo.cpp @@ -143,7 +143,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; } @@ -164,7 +164,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; } @@ -174,11 +174,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 0e7904f..1fef254 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -58,7 +58,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) { @@ -93,7 +93,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) { @@ -103,7 +103,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) { @@ -117,7 +117,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]; } @@ -181,15 +181,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]; } @@ -225,7 +225,7 @@ void Recipe::learn() void Recipe::addName(const std::string &name) { - int i = 0; + size_t i = 0; for (; i < names.size(); i++) { if (names[i].name == name) @@ -240,7 +240,7 @@ void Recipe::addName(const std::string &name) void Recipe::addType(IngredientType type, const std::string &typeName) { - int i = 0; + size_t i = 0; for (; i < types.size(); i++) { if (types[i].type == type) @@ -325,14 +325,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) @@ -349,7 +349,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) { @@ -371,7 +371,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) @@ -382,7 +382,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(); @@ -493,7 +493,7 @@ 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 ""; @@ -620,7 +620,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"; } @@ -633,7 +633,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]; @@ -1004,8 +1004,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)); @@ -1102,7 +1102,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] == '+') @@ -1358,7 +1358,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]; @@ -1659,7 +1659,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()) @@ -1694,13 +1694,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]); } @@ -1726,7 +1726,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]) @@ -1735,9 +1735,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; @@ -1791,7 +1792,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) { @@ -1814,21 +1815,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]; @@ -2137,11 +2138,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]); @@ -2221,7 +2222,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); } @@ -2281,7 +2282,7 @@ void Continuity::loadPetData() in.close(); } -PetData *Continuity::getPetData(int idx) +PetData *Continuity::getPetData(size_t idx) { if (idx < 0 || idx >= petData.size()) { @@ -2459,7 +2460,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] << " "; @@ -2541,7 +2542,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 << " "; @@ -2550,7 +2551,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 << " "; @@ -2558,7 +2559,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() << " "; } @@ -2738,15 +2739,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) { @@ -2754,8 +2746,6 @@ void Continuity::loadFile(int slot) e = e->NextSiblingElement("Flag"); } - - XMLElement *efx = doc.FirstChildElement("EFX"); if (efx) { @@ -3067,7 +3057,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; @@ -3475,7 +3465,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) { @@ -3602,9 +3592,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/Credits.cpp b/Aquaria/Credits.cpp index d058308..a26a639 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 d0f0773..e7543a7 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -129,8 +129,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 @@ -339,15 +339,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; } @@ -1869,7 +1880,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]; } @@ -1878,7 +1889,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'; } @@ -1890,7 +1901,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) @@ -1959,7 +1970,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; } @@ -1995,7 +2006,7 @@ void DSQ::applyPatches() loadMods(); for (std::set::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); @@ -2054,7 +2065,7 @@ 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]; if(files.find(r->name) != files.end()) @@ -2440,7 +2451,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); @@ -2508,7 +2519,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; } @@ -2582,7 +2593,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); @@ -2814,13 +2825,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; @@ -2914,7 +2925,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); } @@ -2927,7 +2938,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) { @@ -2953,7 +2964,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(); } @@ -2963,7 +2974,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(); } @@ -3002,7 +3013,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]; @@ -3445,7 +3456,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]) { @@ -4438,7 +4449,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) { @@ -4449,11 +4460,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]); @@ -4478,7 +4489,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); @@ -4543,7 +4554,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 13c0698..d00defc 100644 --- a/Aquaria/DSQ.h +++ b/Aquaria/DSQ.h @@ -229,7 +229,7 @@ public: typedef std::vector SubLines; SubLines subLines; - int curLine; + size_t curLine; protected: bool vis, hidden; }; @@ -432,7 +432,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; @@ -578,7 +578,7 @@ struct WorldMap void revealMap(const std::string &name); WorldMapTile *getWorldMapTile(const std::string &name); int getNumWorldMapTiles(); - WorldMapTile *getWorldMapTile(int index); + WorldMapTile *getWorldMapTile(size_t index); WorldMapTile *getWorldMapTileByIndex(int index); void revealMapIndex(int index); @@ -887,7 +887,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); @@ -920,7 +920,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(); @@ -963,7 +963,7 @@ public: float getStory(); void setStory(float v); - float getSpeedType(int speedType); + float getSpeedType(size_t speedType); void setNaijaModel(std::string model); @@ -1036,8 +1036,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; @@ -1086,13 +1086,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; @@ -1199,7 +1199,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; @@ -1276,12 +1276,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;} @@ -1382,7 +1382,7 @@ public: bool canOpenEditor() const; void loadElementEffects(); - ElementEffect getElementEffectByIndex(int e); + ElementEffect getElementEffectByIndex(size_t e); typedef std::vector ElementEffects; ElementEffects elementEffects; @@ -1464,7 +1464,7 @@ public: std::vector modEntries; std::set activePatches; - int selectedMod; + size_t selectedMod; ModSelectorScreen *modSelectorScr; void startSelectedMod(); 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 0eda8cb..83a3828 100644 --- a/Aquaria/Emote.cpp +++ b/Aquaria/Emote.cpp @@ -44,9 +44,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 baef273..0e22ecd 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]; @@ -1837,7 +1837,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) { @@ -1892,9 +1892,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]; } @@ -1983,9 +1983,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; @@ -2287,7 +2287,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()) @@ -2331,9 +2331,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); @@ -2552,7 +2552,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 114210e..cf82ebb 100644 --- a/Aquaria/Entity.h +++ b/Aquaria/Entity.h @@ -335,7 +335,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); @@ -424,7 +424,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 e7ff89d..f6802e8 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -69,7 +69,7 @@ std::string getSceneFilename(const std::string &scene) return ""; } -PetSlot::PetSlot(int pet) : AquariaGuiQuad() +PetSlot::PetSlot(size_t pet) : AquariaGuiQuad() { PetData *p = dsq->continuity.getPetData(pet); if (p) @@ -451,7 +451,7 @@ void FoodSlot::eatMe() { if (ingredient && !dsq->isNested()) { - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { if (!foodHolders[i]->isTrash() && !foodHolders[i]->isEmpty()) { @@ -556,7 +556,7 @@ void FoodSlot::onUpdate(float dt) else { bool droppedIn = false; - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { bool in = (foodHolders[i]->getWorldPosition() - wp).isLength2DIn(32); if (in) @@ -903,11 +903,11 @@ void TreasureSlot::refresh() std::string parse = dsq->continuity.stringBank.get(flag); - int p1 = parse.find_first_of('['); + size_t p1 = parse.find_first_of('['); if (p1 != std::string::npos) { p1++; - int p2 = parse.find_first_of(']'); + size_t p2 = parse.find_first_of(']'); treasureName = parse.substr(p1,p2-p1); p1 = parse.find_last_of('['); @@ -1047,7 +1047,7 @@ int Game::getNumberOfEntitiesNamed(const std::string &name) return c; } -void Game::playSongInMenu(int songType, bool override) +void Game::playSongInMenu(size_t songType, bool override) { if (playingSongInMenu == -1 || override) { @@ -1082,7 +1082,7 @@ void Game::flipSceneVertical(int flipY) Entity *e = *itr; flipRenderObjectVertical(e, flipY); } - int i = 0; + size_t i = 0; int flipTY = (flipY/TILE_SIZE)-1; for (i = 0; i < obsRows.size(); i++) { @@ -1359,7 +1359,7 @@ void Game::showInGameMenu(bool ignoreInput, bool optionsOnly, MenuPage menuPage) else liCrystal->alphaMod = 0; - int i = 0; + size_t i = 0; for (i = 0; i < songSlots.size(); i++) @@ -1422,12 +1422,12 @@ void Game::showInGameMenu(bool ignoreInput, bool optionsOnly, MenuPage menuPage) eYes->setHidden(false); eNo->setHidden(false); menuIconGlow->setHidden(false); - for (int i = 0; i < menu.size(); i++) + for (size_t i = 0; i < menu.size(); i++) menu[i]->setHidden(false); - for (int i = 0; i < treasureSlots.size(); i++) + for (size_t i = 0; i < treasureSlots.size(); i++) treasureSlots[i]->setHidden(false); treasureDescription->setHidden(false); - for (int i = 0; i < foodSlots.size(); i++) + for (size_t i = 0; i < foodSlots.size(); i++) foodSlots[i]->setHidden(false); @@ -1576,7 +1576,7 @@ void Game::hideInGameMenu(bool effects, bool cancel) t = 0; //if (avatar->isEntityDead()) return; - int i = 0; + size_t i = 0; for (i = 0; i < foodHolders.size(); i++) { @@ -1652,12 +1652,12 @@ void Game::hideInGameMenu(bool effects, bool cancel) inGameMenu = false; //toggleMiniMapRender(1); - for (int i = 0; i < songTips.size(); i++) + for (size_t i = 0; i < songTips.size(); i++) songTips[i]->alpha = 0; - for (int i = 0; i < dropIngrNames.size(); i++) + for (size_t i = 0; i < dropIngrNames.size(); i++) { dsq->game->spawnIngredient(dropIngrNames[i], avatar->position + Vector(0,-96), 1, 1); } @@ -1696,12 +1696,12 @@ void Game::hideInGameMenu(bool effects, bool cancel) eYes->setHidden(true); eNo->setHidden(true); menuIconGlow->setHidden(true); - for (int i = 0; i < menu.size(); i++) + for (size_t i = 0; i < menu.size(); i++) menu[i]->setHidden(true); - for (int i = 0; i < treasureSlots.size(); i++) + for (size_t i = 0; i < treasureSlots.size(); i++) treasureSlots[i]->setHidden(true); treasureDescription->setHidden(true); - for (int i = 0; i < foodSlots.size(); i++) + for (size_t i = 0; i < foodSlots.size(); i++) foodSlots[i]->setHidden(true); } @@ -1878,9 +1878,9 @@ 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++) + for (size_t i = 0; i < elementTemplates.size(); i++) { if (elementTemplates[i].idx == idx) { @@ -2031,10 +2031,10 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim) // obs now empty int sides = 0; - for (int i = 0; i < obsCopy.size(); i++) + for (size_t i = 0; i < obsCopy.size(); i++) { sides = 0; - for (int j = 0; j < obsCopy.size(); j++) + for (size_t j = 0; j < obsCopy.size(); j++) { if (i != j) { @@ -2060,7 +2060,7 @@ void Game::fillGridFromQuad(Quad *q, ObsType obsType, bool trim) glPushMatrix(); - for (int i = 0; i < obs.size(); i++) + for (size_t i = 0; i < obs.size(); i++) { glLoadIdentity(); @@ -2137,7 +2137,7 @@ void Game::reconstructGrid(bool force) if (!force && isSceneEditorActive()) return; clearGrid(); - int i = 0; + size_t i = 0; for (i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); @@ -2347,7 +2347,7 @@ Vector Game::getWallNormal(Vector pos, int sampleArea, float *dist, int obs) } } int sz = (TILE_SIZE*(sampleArea-1)); - for (int i = 0; i < vs.size(); i++) + for (size_t i = 0; i < vs.size(); i++) { float len = vs[i].getLength2D(); if (len < sz) @@ -2425,13 +2425,13 @@ bool Game::removeEntity(Entity *selected) e = e->NextSiblingElement("Enemy"); } - for (int i = 0; i < entitySaveData.size(); i++) + for (size_t i = 0; i < entitySaveData.size(); i++) { if (entitySaveData[i].x == int(selected->startPos.x) && entitySaveData[i].y == int(selected->startPos.y)) { std::vector copy = entitySaveData; entitySaveData.clear(); - for (int j = 0; j < copy.size(); j++) + for (size_t j = 0; j < copy.size(); j++) { if (j != i) entitySaveData.push_back(copy[j]); @@ -2560,7 +2560,7 @@ void Game::loadEntityTypeList() EntityClass *Game::getEntityClassForEntityType(const std::string &type) { - for (int i = 0; i < entityTypeList.size(); i++) + for (size_t i = 0; i < entityTypeList.size(); i++) { /* std::ostringstream os; @@ -2577,7 +2577,7 @@ int Game::getIdxForEntityType(std::string type) { //if (!type.empty() && type[0] == '@') return -1; - for (int i = 0; i < entityTypeList.size(); i++) + for (size_t i = 0; i < entityTypeList.size(); i++) { if (nocasecmp(entityTypeList[i].name, type)==0) return entityTypeList[i].idx; @@ -2588,7 +2588,7 @@ int Game::getIdxForEntityType(std::string type) Entity *Game::createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType et, bool doPostInit) { std::string type; - for (int i = 0; i < dsq->game->entityTypeList.size(); i++) + for (size_t i = 0; i < dsq->game->entityTypeList.size(); i++) { EntityClass *ec = &dsq->game->entityTypeList[i]; if (ec->idx == idx) @@ -2726,7 +2726,7 @@ void Game::initEntities() EntitySaveData *Game::getEntitySaveDataForEntity(Entity *e, Vector pos) { - for (int i = 0; i < entitySaveData.size(); i++) + for (size_t i = 0; i < entitySaveData.size(); i++) { if (entitySaveData[i].e == e) { @@ -2884,12 +2884,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]); @@ -2905,7 +2905,7 @@ void Game::clearPaths() int Game::getIndexOfPath(Path *p) { - for (int i = 0; i < paths.size(); i++) + for (size_t i = 0; i < paths.size(); i++) { if (paths[i] == p) return i; @@ -2969,7 +2969,7 @@ Path *Game::getNearestPath(const Vector &pos, const std::string &s, const Path * float smallestDist = HUGE_VALF; std::string st = s; stringToLower(st); - for (int i = 0; i < dsq->game->paths.size(); i++) + for (size_t i = 0; i < dsq->game->paths.size(); i++) { Path *cp = dsq->game->paths[i]; if (cp != ignore && !cp->nodes.empty() && (st.empty() || st == cp->label)) @@ -3016,7 +3016,7 @@ Path *Game::getNearestPath(Path *p, std::string s) Path *Game::getPathByName(std::string name) { stringToLowerUserData(name); - for (int i = 0; i < paths.size(); i++) + for (size_t i = 0; i < paths.size(); i++) { if (paths[i]->label == name) return paths[i]; @@ -3224,7 +3224,7 @@ void Game::sortFood() std::vector foodHolderNames; foodHolderNames.resize(foodHolders.size()); - for (int i = 0; i < foodHolders.size(); i++) { + for (size_t i = 0; i < foodHolders.size(); i++) { IngredientData *ing = foodHolders[i]->getIngredient(); if (ing) { foodHolderNames[i] = ing->name; @@ -3252,7 +3252,7 @@ void Game::sortFood() dsq->sound->playSfx("menu-switch", 0.5); dsq->spawnParticleEffect("menu-switch", worldLeftCenter, 0, 0, LR_HUD3, 1); - for (int i = 0; i < foodHolders.size(); i++) { + for (size_t i = 0; i < foodHolders.size(); i++) { if (!foodHolderNames[i].empty()) { IngredientData *ing = dsq->continuity.getIngredientHeldByName(foodHolderNames[i]); foodHolders[i]->setIngredient(ing, false); @@ -3275,7 +3275,7 @@ void Game::sortFood() void Game::createInGameMenu() { float menuz = 4; - int i = 0; + size_t i = 0; menuBg = new Quad; @@ -3294,7 +3294,6 @@ void Game::createInGameMenu() menuBg2->position = Vector(0, 240); menuBg->addChild(menuBg2, PM_POINTER); - float scale = menuBg->scale.x; /* songDescription = new BitmapText(&dsq->font); songDescription->position = Vector(0,100); @@ -3454,7 +3453,6 @@ void Game::createInGameMenu() options->followCamera = 1; addRenderObject(options, LR_MENU); - scale = 1; songSlots.clear(); //songSlots.resize(3); songSlots.resize(10); @@ -3750,7 +3748,7 @@ void Game::createInGameMenu() addRenderObject(circlePageNum, LR_MENU); foodHolders.resize(3); - int holders=0; + size_t holders=0; for (i = 0; i < foodHolders.size(); i++) { foodHolders[i] = new FoodHolder(i); @@ -4699,10 +4697,8 @@ bool Game::loadSceneXML(std::string scene) waSF->SetAttribute("y", a.position.y = atoi(warpArea->Attribute("y"))); if (warpArea->Attribute("radius")) waSF->SetAttribute("radius", a.radius = atoi(warpArea->Attribute("radius"))); - bool isRect = false; if (warpArea->Attribute("w")) { - isRect = true; waSF->SetAttribute("w", a.w = atoi(warpArea->Attribute("w"))); waSF->SetAttribute("h", a.h = atoi(warpArea->Attribute("h"))); } @@ -5193,7 +5189,7 @@ void Game::findMaxCameraValues() cameraMin.y = 20; cameraMax.x = -1; cameraMax.y = -1; - int i = 0; + size_t i = 0; for (i = 0; i < obsRows.size(); i++) { ObsRow *r = &obsRows[i]; @@ -5386,7 +5382,7 @@ bool Game::saveScene(std::string scene) */ std::ostringstream obs; - int i = 0; + size_t i = 0; for (i = 0; i < obsRows.size(); i++) { obs << obsRows[i].tx << " " << obsRows[i].ty << " " << obsRows[i].len << " "; @@ -5402,7 +5398,7 @@ bool Game::saveScene(std::string scene) Path *p = dsq->game->getPath(i); pathXml->SetAttribute("name", p->name.c_str()); //pathXml->SetAttribute("active", p->active); - for (int n = 0; n < p->nodes.size(); n++) + for (size_t n = 0; n < p->nodes.size(); n++) { XMLElement *nodeXml = saveFile.NewElement("Node"); std::ostringstream os; @@ -5478,7 +5474,7 @@ bool Game::saveScene(std::string scene) XMLElement *entitiesNode = saveFile.NewElement("Entities"); std::ostringstream os; - for (int i = 0; i < dsq->game->entitySaveData.size(); i++) + for (size_t i = 0; i < dsq->game->entitySaveData.size(); i++) { EntitySaveData *e = &dsq->game->entitySaveData[i]; os << e->idx << " "; @@ -5504,7 +5500,7 @@ bool Game::saveScene(std::string scene) { XMLElement *simpleElementsXML = saveFile.NewElement("SE"); simpleElementsXML->SetAttribute("k", s.c_str()); - simpleElementsXML->SetAttribute("l", i); + simpleElementsXML->SetAttribute("l", (unsigned int) i); std::string repeatScaleStr = simpleElements_repeatScale[i].str(); if(!repeatScaleStr.empty()) simpleElementsXML->SetAttribute("repeatScale", repeatScaleStr.c_str()); @@ -5606,7 +5602,7 @@ bool Game::isValidTarget(Entity *e, Entity *me) void Game::updateMiniMapHintPosition() { miniMapHintPosition = Vector(0,0,0); - for (int i = 0; i < warpAreas.size(); i++) + for (size_t i = 0; i < warpAreas.size(); i++) { if (this->sceneName == miniMapHint.scene) { @@ -5895,7 +5891,7 @@ void Game::rebuildElementUpdateList() elementUpdateList.clear(); elementInteractionList.clear(); - for (int i = 0; i < dsq->getNumElements(); i++) + for (size_t i = 0; i < dsq->getNumElements(); i++) { Element *e = dsq->getElement(i); const int eeidx = e->getElementEffectIndex(); @@ -5940,7 +5936,7 @@ float Game::getHalfTimer(float mod) void Game::action(int id, int state) { - for (int i = 0; i < paths.size(); i++) + for (size_t i = 0; i < paths.size(); i++) { if (paths[i]->catchActions) { @@ -6048,7 +6044,7 @@ void Game::action(int id, int state) } else { - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { if (!foodHolders[i]->isTrash() && !foodHolders[i]->isEmpty()) { @@ -6066,7 +6062,7 @@ void Game::action(int id, int state) } else { - for (int i = 0; i < foodSlots.size(); i++) + for (size_t i = 0; i < foodSlots.size(); i++) { if (foodSlots[i]->isCursorIn() && foodSlots[i]->getIngredient()) { @@ -6085,7 +6081,7 @@ void Game::action(int id, int state) else { int trashIndex = -1; - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { if (foodHolders[i]->isValid() && foodHolders[i]->isTrash()) { @@ -6095,8 +6091,8 @@ void Game::action(int id, int state) } if (trashIndex >= 0) { - int ingrIndex = -1; - for (int i = 0; i < foodSlots.size(); i++) + size_t ingrIndex = -1; + for (size_t i = 0; i < foodSlots.size(); i++) { if (foodSlots[i]->isCursorIn() && foodSlots[i]->getIngredient()) { @@ -6104,7 +6100,7 @@ void Game::action(int id, int state) break; } } - if (ingrIndex >= 0) + if (ingrIndex != -1) { foodSlots[ingrIndex]->discard(); } @@ -6507,7 +6503,7 @@ void Game::applyState() if (!warpAreaType.empty()) { - for (int i = 0; i < warpAreas.size(); i++) + for (size_t i = 0; i < warpAreas.size(); i++) { WarpArea *a = &warpAreas[i]; if (a->warpAreaType == warpAreaType) @@ -6653,7 +6649,7 @@ void Game::applyState() Path *closest = 0; Vector closestPushOut; bool doFlip = false; - 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); Vector pos = p->nodes[0].position; @@ -7035,10 +7031,10 @@ void Game::bindInput() worldMapRender->bindInput(); } -bool ingType(const std::vector &list, IngredientType type, int amount=1) +bool ingType(const std::vector &list, IngredientType type, size_t amount=1) { - int c = 0; - for (int i = 0; i < list.size(); i++) + size_t c = 0; + for (size_t i = 0; i < list.size(); i++) { IngredientData *data = list[i]; if ((data->marked < data->held) && (data->type == type || type == IT_ANYTHING)) @@ -7053,10 +7049,10 @@ bool ingType(const std::vector &list, IngredientType type, int return false; } -bool ingName(const std::vector &list, const std::string &name, int amount=1) +bool ingName(const std::vector &list, const std::string &name, size_t amount=1) { - int c = 0; - for (int i = 0; i < list.size(); i++) + size_t c = 0; + for (size_t i = 0; i < list.size(); i++) { IngredientData *data = list[i]; if ((data->marked < data->held) && (nocasecmp(data->name, name)==0))//data->name == name) @@ -7070,7 +7066,7 @@ bool ingName(const std::vector &list, const std::string &name, return false; } -const int numTreasures = 16*2; +const size_t numTreasures = 16*2; void Game::onPrevTreasurePage() { @@ -7120,7 +7116,7 @@ void Game::onNextTreasurePage() void Game::onPrevFoodPage() { - int lastFoodPage = currentFoodPage; + size_t lastFoodPage = currentFoodPage; if (currentFoodPage > 0) { currentFoodPage--; @@ -7148,7 +7144,7 @@ void Game::onPrevFoodPage() void Game::onNextFoodPage() { - int lastFoodPage = currentFoodPage; + size_t lastFoodPage = currentFoodPage; if ((currentFoodPage+1)*foodPageSize < dsq->continuity.ingredientCount()) { currentFoodPage++; @@ -7194,17 +7190,14 @@ Recipe *Game::findRecipe(const std::vector &list) // there will be a number of types and a number of names // the types and names DO NOT overlap - int rc = 0; + size_t rc = 0; Recipe *r = 0; - Recipe *tr = 0; - int q = 0, q2 = 0; + size_t q = 0, q2 = 0; for ( rc = 0; rc < dsq->continuity.recipes.size(); rc++) { - for (int i = 0; i < list.size(); i++) list[i]->marked = 0; + for (size_t i = 0; i < list.size(); i++) list[i]->marked = 0; - tr = 0; r = &dsq->continuity.recipes[rc]; - tr = r; q = 0; // get the amount of ingredients provided by the player @@ -7213,16 +7206,16 @@ Recipe *Game::findRecipe(const std::vector &list) // get the amount of ingredients required int recipeAmount = 0; - for (int i = 0; i < r->types.size(); i++) + for (size_t i = 0; i < r->types.size(); i++) recipeAmount += r->types[i].amount; - for (int i = 0; i < r->names.size(); i++) + for (size_t i = 0; i < r->names.size(); i++) recipeAmount += r->names[i].amount; if (listAmount != recipeAmount) continue; - for (int c = 0; c < r->types.size(); c++) + for (size_t c = 0; c < r->types.size(); c++) { RecipeType *t = &r->types[c]; if (ingType(list, t->type, t->amount)) @@ -7245,7 +7238,7 @@ Recipe *Game::findRecipe(const std::vector &list) if (q == r->types.size()) { q2 = 0; - for (int c = 0; c < r->names.size(); c++) + for (size_t c = 0; c < r->names.size(); c++) { RecipeName *n = &r->names[c]; if (ingName(list, n->name, n->amount)) @@ -7273,7 +7266,7 @@ Recipe *Game::findRecipe(const std::vector &list) } } - for (int i = 0; i < list.size(); i++) list[i]->marked = 0; + for (size_t i = 0; i < list.size(); i++) list[i]->marked = 0; if (rc == dsq->continuity.recipes.size()) { @@ -7292,7 +7285,7 @@ Recipe *Game::findRecipe(const std::vector &list) void Game::updateCookList() { cookList.clear(); - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { IngredientData *ing = foodHolders[i]->getIngredient(); if (!foodHolders[i]->isTrash() && ing) @@ -7450,7 +7443,7 @@ void Game::onCook() dsq->sound->playSfx("boil"); - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { if (!foodHolders[i]->isEmpty()) dsq->spawnParticleEffect("cook-ingredient", foodHolders[i]->getWorldPosition(), 0, 0, LR_HUD3, 1); @@ -7462,7 +7455,7 @@ void Game::onCook() dsq->main(0.2); bool haveLeftovers = true; - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { if (!foodHolders[i]->isEmpty()) { IngredientData *ing = foodHolders[i]->getIngredient(); @@ -7473,7 +7466,7 @@ void Game::onCook() } } } - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { IngredientData *ing = foodHolders[i]->getIngredient(); if (ing) @@ -7489,7 +7482,7 @@ void Game::onCook() dsq->sound->playSfx("Cook"); - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) if (foodHolders[i]->isValid() && !foodHolders[i]->isTrash()) foodHolders[i]->animateLid(false); @@ -7566,7 +7559,7 @@ void Game::overrideZoom(float sz, float t) FoodSlot* getFoodSlotFromIndex() { - for (int i = 0; i < dsq->game->foodSlots.size(); i++) + for (size_t i = 0; i < dsq->game->foodSlots.size(); i++) { if (dsq->game->foodSlots[i]->slot == FoodSlot::foodSlotIndex) { @@ -7606,7 +7599,7 @@ void Game::clearControlHint() controlHint_image->alpha.interpolateTo(0, hintTransTime); } - for (int i = 0; i < controlHintNotes.size(); i++) + for (size_t i = 0; i < controlHintNotes.size(); i++) { controlHintNotes[i]->alpha.interpolateTo(0, hintTransTime); } @@ -7670,7 +7663,7 @@ void Game::setControlHint(const std::string &h, bool left, bool right, bool midd p += Vector(100, 0); - for (int i = 0; i < song->notes.size(); i++) + for (size_t i = 0; i < song->notes.size(); i++) { int note = song->notes[i]; @@ -7757,7 +7750,7 @@ void Game::setControlHint(const std::string &h, bool left, bool right, bool midd controlHint_mouseBody->alpha.interpolateTo(0.5, hintTransTime); } - for (int i = 0; i < controlHintNotes.size(); i++) + for (size_t i = 0; i < controlHintNotes.size(); i++) { controlHintNotes[i]->alpha.interpolateTo(alphaOn, hintTransTime); } @@ -8305,7 +8298,7 @@ Bone *Game::collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, fl { //float smallestDist = HUGE_VALF; 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]; /* @@ -8317,7 +8310,7 @@ Bone *Game::collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, fl // 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)) { @@ -8384,7 +8377,7 @@ Bone *Game::collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius) float smallestDist = HUGE_VALF; Bone *closest = 0; if (!(pos - skeletal->position).isLength2DIn(2000)) return 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]; @@ -8400,7 +8393,7 @@ Bone *Game::collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius) { if (dist < checkRadius) { - for (int i = 0; i < b->transformedCollisionMask.size(); i++) + for (size_t i = 0; i < b->transformedCollisionMask.size(); i++) { if ((b->transformedCollisionMask[i] - pos).isLength2DIn(radius+b->collideRadius*skeletal->scale.x)) { @@ -8836,7 +8829,7 @@ void Game::onOptionsCancel() void Game::refreshFoodSlots(bool effects) { - for (int i = 0; i < foodSlots.size(); i++) + for (size_t i = 0; i < foodSlots.size(); i++) { foodSlots[i]->refresh(effects); } @@ -8844,7 +8837,7 @@ void Game::refreshFoodSlots(bool effects) void Game::refreshTreasureSlots() { - for (int i = 0; i < treasureSlots.size(); i++) + for (size_t i = 0; i < treasureSlots.size(); i++) { treasureSlots[i]->refresh(); } @@ -8868,14 +8861,12 @@ void Game::togglePetMenu(bool f) toggleMainMenu(false); - bool hasPet = false; - for (int i = 0; i < petSlots.size(); i++) + for (size_t i = 0; i < petSlots.size(); i++) { petSlots[i]->alpha = 1; bool has = dsq->continuity.getFlag(petSlots[i]->petFlag); if (has) { - hasPet = true; /* for (int j = 0; j < petSlots.size(); j++) { @@ -8922,7 +8913,7 @@ void Game::togglePetMenu(bool f) } - for (int i = 0; i < petTips.size(); i++) + for (size_t i = 0; i < petTips.size(); i++) { /* if (hasPet && i == 0) @@ -8948,12 +8939,12 @@ void Game::togglePetMenu(bool f) } else if (!f && petMenu) { - for (int i = 0; i < petSlots.size(); i++) + for (size_t i = 0; i < petSlots.size(); i++) { petSlots[i]->alpha = 0; } - for (int i = 0; i < petTips.size(); i++) + for (size_t i = 0; i < petTips.size(); i++) { petTips[i]->alpha = 0; } @@ -8990,7 +8981,7 @@ void Game::toggleTreasureMenu(bool f) refreshTreasureSlots(); - for (int i = 0; i < treasureTips.size(); i++) + for (size_t i = 0; i < treasureTips.size(); i++) treasureTips[i]->alpha = 1; if (treasureSlots.size() > 8) @@ -9016,7 +9007,7 @@ void Game::toggleTreasureMenu(bool f) { treasureMenu = false; - for (int i = 0; i < treasureTips.size(); i++) + for (size_t i = 0; i < treasureTips.size(); i++) treasureTips[i]->alpha = 0; menu[0]->setDirMove(DIR_UP, 0); @@ -9027,7 +9018,7 @@ void Game::toggleTreasureMenu(bool f) circlePageNum->alpha = 0; } - for (int i = 0; i < treasureSlots.size(); i++) + for (size_t i = 0; i < treasureSlots.size(); i++) { if (f) treasureSlots[i]->alpha = 1; @@ -9072,7 +9063,7 @@ void Game::toggleFoodMenu(bool f) toggleTreasureMenu(false); - for (int i = 0; i < foodHolders.size(); i++) + for (size_t i = 0; i < foodHolders.size(); i++) { foodHolders[i]->toggleValid(f); } @@ -9116,7 +9107,7 @@ void Game::toggleFoodMenu(bool f) foodSort->alpha = 1; - for (int i = 0; i < foodTips.size(); i++) + for (size_t i = 0; i < foodTips.size(); i++) foodTips[i]->alpha = 1; if (foodSlots.size() >= 16) @@ -9168,7 +9159,7 @@ void Game::toggleFoodMenu(bool f) liCrystal->alpha = 0; - for (int i = 0; i < foodTips.size(); i++) + for (size_t i = 0; i < foodTips.size(); i++) foodTips[i]->alpha = 0; menu[5]->setDirMove(DIR_LEFT, 0); @@ -9178,7 +9169,7 @@ void Game::toggleFoodMenu(bool f) previewRecipe->alpha = 0; } - for (int i = 0; i < foodSlots.size(); i++) + for (size_t i = 0; i < foodSlots.size(); i++) { foodSlots[i]->toggle(f); } @@ -9205,7 +9196,7 @@ void Game::toggleMainMenu(bool f) if (f) { currentMenuPage = MENUPAGE_SONGS; - for (int i = 0; i < songSlots.size(); i++) + for (size_t i = 0; i < songSlots.size(); i++) { //songSlots[i]->alpha.interpolateTo(1, t); songSlots[i]->alphaMod = 1; @@ -9213,14 +9204,14 @@ void Game::toggleMainMenu(bool f) songBubbles->alpha.interpolateTo(1,t); energyIdol->alpha.interpolateTo(1,t); liCrystal->alpha.interpolateTo(1, t); - for (int i = 0; i < songTips.size(); i++) + for (size_t i = 0; i < songTips.size(); i++) songTips[i]->alpha = 1; menuBg2->alpha.interpolateTo(1, t); int sm=-900; SongSlot *ss=0; - for (int i = 0; i < songSlots.size(); i++) + for (size_t i = 0; i < songSlots.size(); i++) { if (dsq->continuity.hasSong(dsq->continuity.getSongTypeBySlot(i))) { @@ -9248,12 +9239,12 @@ void Game::toggleMainMenu(bool f) { ((AquariaMenuItem*)menu[5])->setDirMove(DIR_LEFT, 0); - for (int i = 0; i < songSlots.size(); i++) + for (size_t i = 0; i < songSlots.size(); i++) { songSlots[i]->alphaMod = 0; } - for (int i = 0; i < songTips.size(); i++) + for (size_t i = 0; i < songTips.size(); i++) songTips[i]->alpha = 0; songBubbles->alpha.interpolateTo(0, t); @@ -9643,7 +9634,7 @@ void Game::updateInGameMenu(float dt) songMenuPlayDelay = 0; - if (currentSongMenuNote >= 0 && currentSongMenuNote < s.notes.size()) + if (currentSongMenuNote < s.notes.size()) { /* std::ostringstream os; @@ -10130,7 +10121,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); @@ -10401,7 +10392,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); @@ -10646,9 +10636,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) { @@ -10677,7 +10667,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); /* @@ -10814,7 +10804,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 06a7c06..91c828b 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -67,7 +67,7 @@ struct RecipeMenu void goNextPage(); void goPrevPage(); int getNumPages(); - int getNumKnown(); + size_t getNumKnown(); int currentPage; @@ -253,11 +253,11 @@ protected: class PetSlot : public AquariaGuiQuad { public: - PetSlot(int pet); + PetSlot(size_t pet); int petFlag; protected: bool wasSlot; - int petidx; + size_t petidx; bool mouseDown; void onUpdate(float dt); }; @@ -313,7 +313,7 @@ public: void setGrid(Vector position); bool cull; float alpha; - int idx; + size_t idx; }; class MiniMapHint @@ -470,8 +470,8 @@ public: Path *editingPath; void toggleWarpAreaRender(); - int selectedIdx; - int selectedNode; + size_t selectedIdx; + size_t selectedNode; Path *getSelectedPath(); void changeDepth(); void updateEntitySaveData(Entity *editingEntity); @@ -492,7 +492,7 @@ public: SelectedEntity selectedEntity; - int entityPageNum; + size_t entityPageNum; void checkForRebuild(); void createAquarian(); @@ -572,7 +572,7 @@ protected: void mouseButtonLeft(); void mouseButtonRight(); - int curElement, selectedVariation, possibleSelectedIdx; + size_t curElement, selectedVariation, possibleSelectedIdx; Quad *placer; DebugFont *text; @@ -703,7 +703,7 @@ public: std::vector elementTemplates; std::string sceneName, sceneDisplayName; - ElementTemplate *getElementTemplateByIdx(int idx); + ElementTemplate *getElementTemplateByIdx(size_t idx); bool saveScene(std::string scene); typedef std::vector WarpAreas; @@ -790,10 +790,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); @@ -822,7 +822,7 @@ public: bool optionsOnly; MenuPage currentMenuPage; - int currentFoodPage, currentTreasurePage; + size_t currentFoodPage, currentTreasurePage; Precacher tileCache; @@ -865,7 +865,7 @@ public: void colorTest(); - void playSongInMenu(int songType, bool override=false); + void playSongInMenu(size_t songType, bool override=false); bool trace(Vector start, Vector target); @@ -1127,8 +1127,8 @@ protected: void updateCursor(float dt); void updateInGameMenu(float dt); float songMenuPlayDelay; - int currentSongMenuNote; - int playingSongInMenu; + size_t currentSongMenuNote; + size_t playingSongInMenu; Quad *controlHint_mouseLeft, *controlHint_mouseRight, *controlHint_mouseBody, *controlHint_mouseMiddle, *controlHint_bg, *controlHint_image; Quad *controlHint_shine; bool controlHint_ignoreClear; diff --git a/Aquaria/GridRender.cpp b/Aquaria/GridRender.cpp index cfe67da..155fc75 100644 --- a/Aquaria/GridRender.cpp +++ b/Aquaria/GridRender.cpp @@ -122,7 +122,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); @@ -155,10 +155,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 b1479a2..9a2c0d7 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/Intro.cpp b/Aquaria/Intro.cpp index 281d624..e571561 100644 --- a/Aquaria/Intro.cpp +++ b/Aquaria/Intro.cpp @@ -29,7 +29,7 @@ namespace IntroStuff { //Mappy *m; bool quitFlag; -}; +} using namespace IntroStuff; @@ -198,7 +198,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); @@ -255,7 +255,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") { @@ -272,7 +272,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 be4fed0..e68014f 100644 --- a/Aquaria/MiniMapRender.cpp +++ b/Aquaria/MiniMapRender.cpp @@ -402,7 +402,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)) { @@ -595,7 +595,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 8aab707..49c00aa 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 b74ee5d..db76af8 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 3849cf7..8100fac 100644 --- a/Aquaria/ModSelector.h +++ b/Aquaria/ModSelector.h @@ -147,7 +147,7 @@ public: void init(); void close(); - void showPanel(int id); + void showPanel(size_t id); void updateFade(); void initModAndPatchPanel(); @@ -169,7 +169,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 0f6cd4b..ce79b28 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 ed04ae3..51272dd 100644 --- a/Aquaria/Path.h +++ b/Aquaria/Path.h @@ -86,14 +86,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); 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 41b12e9..7278a6c 100644 --- a/Aquaria/PathRender.cpp +++ b/Aquaria/PathRender.cpp @@ -30,11 +30,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 @@ -45,7 +45,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]; @@ -54,7 +54,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 85c3b0d..4b94469 100644 --- a/Aquaria/RecipeMenuEntry.cpp +++ b/Aquaria/RecipeMenuEntry.cpp @@ -69,20 +69,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); @@ -118,7 +120,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++) @@ -182,7 +184,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) @@ -206,9 +208,9 @@ void RecipeMenuEntry::onUpdate(float dt) glow->alphaMod = 0; selected = 0; - int n=0; + size_t n=0; - for (int i = 0; i < game->recipeMenu.recipeMenuEntries.size(); i++) + for (size_t i = 0; i < game->recipeMenu.recipeMenuEntries.size(); i++) { if (!game->recipeMenu.recipeMenuEntries[i]->selected) n++; @@ -246,10 +248,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()) { @@ -430,7 +432,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 9223b3a..e4d9e69 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -93,7 +93,7 @@ std::string getMapTemplateFilename() void WarpAreaRender::onRender() { - for (int i = 0; i < dsq->game->warpAreas.size(); i++) + for (size_t i = 0; i < dsq->game->warpAreas.size(); i++) { WarpArea *a = &dsq->game->warpAreas[i]; glTranslatef(a->position.x, a->position.y,0); @@ -498,7 +498,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(); @@ -779,7 +779,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') @@ -798,7 +798,7 @@ void SceneEditor::createAquarian() Path *SceneEditor::getSelectedPath() { - if (selectedIdx >= 0 && selectedIdx < dsq->game->getNumPaths()) + if (selectedIdx < dsq->game->getNumPaths()) { return dsq->game->getPath(selectedIdx); } @@ -869,7 +869,7 @@ void SceneEditor::toggleWarpAreaRender() 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); @@ -913,7 +913,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]); @@ -933,7 +933,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]); @@ -1039,7 +1039,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]); @@ -1129,7 +1129,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) { @@ -1152,7 +1152,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]); @@ -1174,7 +1174,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); @@ -1222,7 +1222,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); @@ -1255,7 +1255,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); @@ -1338,7 +1338,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(); @@ -1352,7 +1352,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; @@ -1576,12 +1576,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) @@ -1618,7 +1618,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); @@ -1675,7 +1675,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) @@ -1692,7 +1692,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); @@ -1704,10 +1704,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) @@ -1728,7 +1728,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) @@ -1747,7 +1747,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]; @@ -1780,7 +1780,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); @@ -1789,7 +1789,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 @@ -1887,7 +1887,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; @@ -2013,7 +2013,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); @@ -2065,7 +2065,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) @@ -2220,7 +2220,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(); } @@ -2249,7 +2249,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); @@ -2260,7 +2260,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) @@ -2385,9 +2385,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; @@ -2409,9 +2409,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) { @@ -2421,7 +2421,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) @@ -2459,7 +2459,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; } @@ -2471,7 +2471,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]); } @@ -2519,7 +2519,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]); } @@ -2566,7 +2566,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) @@ -2606,8 +2606,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) @@ -2671,7 +2671,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; @@ -2937,7 +2937,7 @@ void SceneEditor::endDrawingWarpArea(char c) 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; } @@ -3066,9 +3066,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(); @@ -3150,7 +3153,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(); @@ -3158,7 +3161,6 @@ void SceneEditor::update(float dt) if (len < closest) { closest = len; - idx = i; } } } @@ -3261,7 +3263,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 3338cdc..3518fea 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -908,8 +908,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) @@ -2537,7 +2537,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; @@ -6059,7 +6060,7 @@ luaFunc(entity_setVel2Len) if(e) e->vel2.setLength2D(lua_tonumber(L, 2)); luaReturnNil(); -}; +} luaFunc(entity_getVel2) { @@ -7585,7 +7586,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(); @@ -8427,7 +8428,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; @@ -8438,7 +8439,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); @@ -8461,10 +8462,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); @@ -8480,7 +8481,7 @@ 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()) @@ -8499,7 +8500,7 @@ luaFunc(setGemBlink) luaFunc(removeGem) { - int gemId = lua_tointeger(L, 1); + size_t gemId = lua_tointeger(L, 1); if(gemId >= 0 && gemId < dsq->continuity.gems.size()) { Continuity::Gems::iterator it = dsq->continuity.gems.begin(); @@ -8574,10 +8575,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 e7f9ad1..4ae58be 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -139,7 +139,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) { @@ -155,7 +155,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; @@ -166,7 +166,7 @@ void ScriptedEntity::startEmitter(int emit) } } -void ScriptedEntity::stopEmitter(int emit) +void ScriptedEntity::stopEmitter(size_t emit) { if(emit >= emitters.size()) return; @@ -177,12 +177,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(); } @@ -199,7 +199,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()-1; i >= 0 ; i--) { Quad *q = new Quad; if (i == segments.size()-1) @@ -257,7 +257,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; @@ -392,7 +392,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) @@ -786,7 +786,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 bd04cb6..9e2c121 100644 --- a/Aquaria/ScriptedEntity.h +++ b/Aquaria/ScriptedEntity.h @@ -78,11 +78,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 071e791..173f3f5 100644 --- a/Aquaria/States.cpp +++ b/Aquaria/States.cpp @@ -310,7 +310,7 @@ namespace NagStuff const float screenTime = 3; const float nagFadeTime = 1; -}; +} using namespace NagStuff; @@ -442,7 +442,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/States.h b/Aquaria/States.h index 144c7b9..601839a 100644 --- a/Aquaria/States.h +++ b/Aquaria/States.h @@ -206,7 +206,7 @@ public: std::deque undoHistory; - int undoEntry; + size_t undoEntry; int currentKey; @@ -243,7 +243,7 @@ public: SkeletalKeyframe buffer; bool editingStrip; - int selectedStripPoint; + size_t selectedStripPoint; void reverseAnim(); diff --git a/Aquaria/StatsAndAchievements.cpp b/Aquaria/StatsAndAchievements.cpp index be5f35d..40eb0af 100644 --- a/Aquaria/StatsAndAchievements.cpp +++ b/Aquaria/StatsAndAchievements.cpp @@ -228,7 +228,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] ); } @@ -251,7 +251,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) @@ -270,7 +270,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) @@ -383,7 +383,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()) { @@ -396,7 +396,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 5047146..a30eeae 100644 --- a/Aquaria/Strand.cpp +++ b/Aquaria/Strand.cpp @@ -20,11 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "Segmented.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; } @@ -34,7 +34,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 f106f94..00d7700 100644 --- a/Aquaria/StringBank.cpp +++ b/Aquaria/StringBank.cpp @@ -63,7 +63,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 4300987..ec994a1 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -206,7 +206,7 @@ void UserSettings::save() XMLElement *xml_actionSet = doc.NewElement("ActionSet"); { - for (int i = 0; i < control.actionSet.inputSet.size(); i++) + for (size_t i = 0; i < control.actionSet.inputSet.size(); i++) { XMLElement *xml_action = doc.NewElement("Action"); ActionInput *actionInput = &control.actionSet.inputSet[i]; @@ -244,8 +244,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::set::iterator it = dsq->activePatches.begin(); it != dsq->activePatches.end(); ++it) @@ -506,8 +506,8 @@ 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); + xml_data->QueryUnsignedAttribute("savePage", (unsigned int *)&data.savePage); + xml_data->QueryUnsignedAttribute("saveSlot", (unsigned int *)&data.saveSlot); if(const char *patchlist = xml_data->Attribute("activePatches")) { diff --git a/Aquaria/UserSettings.h b/Aquaria/UserSettings.h index cdd19f4..da53012 100644 --- a/Aquaria/UserSettings.h +++ b/Aquaria/UserSettings.h @@ -165,8 +165,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 8512f31..651574f 100644 --- a/Aquaria/Web.cpp +++ b/Aquaria/Web.cpp @@ -76,16 +76,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; } @@ -122,9 +122,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)) { @@ -154,14 +154,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 8236ac8..440026d 100644 --- a/Aquaria/Web.h +++ b/Aquaria/Web.h @@ -29,8 +29,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/WorldMapRender.cpp b/Aquaria/WorldMapRender.cpp index 2c1a9f1..dfd2d1b 100644 --- a/Aquaria/WorldMapRender.cpp +++ b/Aquaria/WorldMapRender.cpp @@ -1262,7 +1262,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 1eab978..0f4d483 100644 --- a/Aquaria/WorldMapTiles.cpp +++ b/Aquaria/WorldMapTiles.cpp @@ -280,7 +280,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; @@ -315,7 +315,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) { @@ -327,7 +327,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) { @@ -341,7 +341,7 @@ 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; } @@ -352,9 +352,9 @@ int 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/ActionMapper.cpp b/BBGE/ActionMapper.cpp index 27974ed..dbf62af 100644 --- a/BBGE/ActionMapper.cpp +++ b/BBGE/ActionMapper.cpp @@ -102,7 +102,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; @@ -113,7 +113,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]; } @@ -326,7 +326,7 @@ void ActionMapper::removeAllActions() { deleteList.push_back(i->id); } - for (int c = 0; c < deleteList.size(); c++) + for (size_t c = 0; c < deleteList.size(); c++) { removeAction (deleteList[c]); } diff --git a/BBGE/ActionSet.cpp b/BBGE/ActionSet.cpp index 53a0593..eeacdc4 100644 --- a/BBGE/ActionSet.cpp +++ b/BBGE/ActionSet.cpp @@ -44,7 +44,7 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int { if (!mapper) return; - for (int i = 0; i < inputSet.size(); i++) + for (size_t i = 0; i < inputSet.size(); i++) { ActionInput *actionInput = &inputSet[i]; if (actionInput->name == name) @@ -68,7 +68,7 @@ void ActionSet::importAction(ActionMapper *mapper, const std::string &name, Even { if (!mapper) return; - for (int i = 0; i < inputSet.size(); i++) + for (size_t i = 0; i < inputSet.size(); i++) { ActionInput *actionInput = &inputSet[i]; if (actionInput->name == name) @@ -108,8 +108,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/AfterEffect.cpp b/BBGE/AfterEffect.cpp index ca74cb1..6e5466e 100644 --- a/BBGE/AfterEffect.cpp +++ b/BBGE/AfterEffect.cpp @@ -85,7 +85,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]) { @@ -137,7 +137,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 764ec29..bbfd5b2 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -161,7 +161,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] != ' ') { @@ -175,7 +175,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; @@ -235,7 +235,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) { @@ -257,7 +257,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; @@ -266,7 +266,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"; } @@ -282,13 +282,13 @@ bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord 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]); } @@ -388,7 +388,7 @@ void exit_error(const std::string &message) std::string parseCommand(const std::string &line, const std::string &command) { - int stringPos = line.find(command); + size_t stringPos = line.find(command); if (stringPos != std::string::npos) { return line.substr((command.length()), line.length()); @@ -470,7 +470,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; @@ -539,7 +539,7 @@ void doSingleFile(const std::string &path, const std::string &type, std::string 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) { @@ -1071,7 +1071,7 @@ Vector colorRGB(int r, int g, int b) 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; } @@ -1079,7 +1079,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 c50ce40..9559c51 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -152,7 +152,7 @@ struct IntPair #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); bool chancef(float p); void initCharTranslationTables(const std::map& tab); diff --git a/BBGE/BitmapFont.cpp b/BBGE/BitmapFont.cpp index 4770dbe..4323334 100644 --- a/BBGE/BitmapFont.cpp +++ b/BBGE/BitmapFont.cpp @@ -161,7 +161,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; @@ -207,10 +207,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); } @@ -278,7 +278,7 @@ 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)) @@ -314,7 +314,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) @@ -336,7 +336,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 e764320..2325691 100644 --- a/BBGE/BitmapFont.h +++ b/BBGE/BitmapFont.h @@ -67,7 +67,7 @@ public: std::string getText(); int getWidthOnScreen(); void loadSpacingMap(const std::string &file); - Vector getColorIndex(int i, int j); + Vector getColorIndex(size_t i, size_t j); void updateWordColoring(); void autoKern(); void setBitmapFontEffect(BitmapFontEffect bfe); @@ -88,8 +88,8 @@ protected: void onUpdate(float dt); float scrollDelay; bool scrolling; - int currentScrollLine; - int currentScrollChar; + size_t currentScrollLine; + size_t currentScrollChar; Align align; float alignWidth; typedef std::map SpacingMap; diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 2a0093a..fa0e820 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -111,7 +111,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(); @@ -129,7 +129,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(); @@ -507,7 +507,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"); @@ -1415,7 +1415,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; } @@ -1427,8 +1427,6 @@ void Core::setDockIcon(const std::string &ident) void Core::setMousePosition(const Vector &p) { - Vector lp = core->mouse.position; - core->mouse.position = p; float px = p.x + virtualOffX; float py = p.y; @@ -1438,15 +1436,12 @@ void Core::setMousePosition(const Vector &p) #else SDL_WarpMouse( px * (float(width)/float(virtualWidth)), py * (float(height)/float(virtualHeight))); #endif - - - } // 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]; @@ -1557,7 +1552,7 @@ void Core::main(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]; @@ -2190,11 +2185,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; @@ -2205,13 +2198,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 '_': @@ -2461,11 +2447,6 @@ void Core::print(int x, int y, const char *str, float sz) default: break; - } - if (isLower) - { - wasLower = true; - } c++; xx += 1.4f; @@ -2536,7 +2517,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]; @@ -2633,7 +2614,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(); @@ -2857,11 +2838,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 << "]"; @@ -2880,7 +2861,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(); } @@ -2892,7 +2873,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(); } @@ -3179,8 +3160,8 @@ void Core::save64x64ScreenshotTGA(const std::string &filename) // saves an array of pixels as a TGA image (frees the image data passed in) int 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) { @@ -3282,8 +3263,8 @@ int Core::tgaSaveSeries(char *filename, // saves an array of pixels as a TGA image (frees the image data passed in) int 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 be5faa6..5066d54 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -378,9 +378,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 @@ -439,7 +439,7 @@ public: void toggleScreenMode(int t=0); void enable2D(int pixelScaleX=0, int pixelScaleY=0, bool forcePixelScale=false); - 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); @@ -690,8 +690,8 @@ public: CoreSettings settings; - int tgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData); - int zgaSave(const char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData); + int tgaSave(const char *filename, short unsigned int width, short unsigned int height, unsigned char pixelDepth, unsigned char *imageData); + int zgaSave(const char *filename, short unsigned int width, short unsigned int height, unsigned char pixelDepth, unsigned char *imageData); volatile int dbg_numThreadDecoders; static unsigned int dbg_numRenderCalls; diff --git a/BBGE/DebugFont.cpp b/BBGE/DebugFont.cpp index bc6777a..9cc771f 100644 --- a/BBGE/DebugFont.cpp +++ b/BBGE/DebugFont.cpp @@ -90,7 +90,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; @@ -132,7 +132,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; diff --git a/BBGE/FmodOpenALBridge.cpp b/BBGE/FmodOpenALBridge.cpp index ddba21e..2334cb7 100644 --- a/BBGE/FmodOpenALBridge.cpp +++ b/BBGE/FmodOpenALBridge.cpp @@ -1379,7 +1379,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); @@ -1739,7 +1739,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/ParticleManager.cpp b/BBGE/ParticleManager.cpp index 39fab8a..b6e24ae 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]; } @@ -363,7 +363,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..9f8b244 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(); @@ -223,9 +223,9 @@ public: 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 b4d9b5c..cd54c0d 100644 --- a/BBGE/Precacher.cpp +++ b/BBGE/Precacher.cpp @@ -62,9 +62,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 f008534..87abfb7 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,7 +104,7 @@ 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) { @@ -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 2a24991..f1a898b 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -31,7 +31,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; @@ -473,7 +473,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; @@ -560,7 +560,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; @@ -649,7 +649,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); @@ -786,7 +786,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]; @@ -839,11 +839,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 edcebfc..aeca581 100644 --- a/BBGE/RenderObject.h +++ b/BBGE/RenderObject.h @@ -133,8 +133,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(); @@ -215,13 +215,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() @@ -329,7 +329,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 2e1df3b..bc50580 100644 --- a/BBGE/RenderObjectLayer.cpp +++ b/BBGE/RenderObjectLayer.cpp @@ -64,7 +64,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. @@ -86,8 +86,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; @@ -108,9 +108,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]) @@ -123,7 +123,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); @@ -133,12 +133,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; @@ -147,13 +147,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. @@ -171,9 +171,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]) @@ -197,19 +197,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 b793383..0e5546f 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -368,7 +368,7 @@ 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) { diff --git a/BBGE/Shader.h b/BBGE/Shader.h index 9e112f0..add57dc 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -46,7 +46,7 @@ protected: std::string vertFile, fragFile; std::string vertSrc, fragSrc; GLuint g_programObj; - int numUniforms; + size_t 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 ba191af..b292bd0 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -87,7 +87,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); @@ -241,7 +241,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) @@ -411,7 +411,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) { @@ -489,7 +489,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?"; @@ -507,7 +507,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; @@ -561,14 +561,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]; } @@ -608,9 +608,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) { @@ -622,11 +622,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++) @@ -634,20 +634,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; @@ -655,9 +655,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) { @@ -669,8 +669,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) { @@ -682,15 +682,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) { @@ -703,8 +701,6 @@ SkeletalKeyframe *Animation::getNextKeyframe(float t) return 0; if (kf >= keyframes.size()) kf = keyframes.size()-1; - if (kf < 0) - kf = 0; return &keyframes[kf]; } @@ -714,7 +710,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; } @@ -742,9 +738,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]; } @@ -764,7 +760,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++) { @@ -775,7 +771,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]); } @@ -846,7 +842,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(); @@ -857,7 +853,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] << " "; } @@ -866,7 +862,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] << " "; } @@ -886,7 +882,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()); @@ -964,7 +960,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()) @@ -980,12 +976,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 << " "; } @@ -1008,9 +1004,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; @@ -1018,9 +1014,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; } @@ -1028,7 +1024,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]; @@ -1039,9 +1035,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]; @@ -1112,7 +1108,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]; @@ -1215,7 +1211,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(); } @@ -1435,7 +1431,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) @@ -1535,7 +1531,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; @@ -1609,7 +1605,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)) { @@ -1630,12 +1626,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; @@ -1643,7 +1639,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)) @@ -1656,13 +1652,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; @@ -1698,7 +1694,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(); } @@ -1710,7 +1706,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]; @@ -1762,7 +1758,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)); } @@ -1784,7 +1780,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(); } @@ -1811,7 +1807,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()) { @@ -1835,7 +1831,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; @@ -1844,7 +1840,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); } @@ -1861,7 +1857,7 @@ void SkeletalSprite::setSelectedBone(int b) void SkeletalSprite::selectPrevBone() { - const int oldsel = selectedBone; + const size_t oldsel = selectedBone; do { selectedBone++; @@ -1876,7 +1872,7 @@ void SkeletalSprite::selectPrevBone() void SkeletalSprite::selectNextBone() { - const int oldsel = selectedBone; + const size_t oldsel = selectedBone; do { selectedBone--; diff --git a/BBGE/SkeletalSprite.h b/BBGE/SkeletalSprite.h index f37ca3b..72841ec 100644 --- a/BBGE/SkeletalSprite.h +++ b/BBGE/SkeletalSprite.h @@ -59,7 +59,8 @@ public: void destroy(); std::string gfx; std::string name; - int boneIdx, pidx, rbp; + size_t boneIdx; + int pidx, rbp; std::map emitters; std::string prt; std::vector changeStrip; @@ -106,7 +107,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; @@ -124,7 +126,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; @@ -138,17 +140,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; }; @@ -197,7 +199,7 @@ public: //HACK: should be a lerped float InterpolatedVector timeMultiplier; float animationLength; - int currentAnimation; + size_t currentAnimation; bool animating; @@ -212,13 +214,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); @@ -232,7 +234,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(); @@ -259,9 +261,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); @@ -274,7 +276,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 f387be6..7002980 100644 --- a/BBGE/SoundManager.cpp +++ b/BBGE/SoundManager.cpp @@ -1388,8 +1388,8 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s f = core->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 987b3c1..251b594 100644 --- a/BBGE/StateManager.cpp +++ b/BBGE/StateManager.cpp @@ -72,7 +72,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]; @@ -115,7 +115,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()) @@ -278,7 +278,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 index 5bbeb26..ca21f7b 100644 --- a/BBGE/Strings.cpp +++ b/BBGE/Strings.cpp @@ -147,7 +147,7 @@ std::string getInputCodeToUserString(int key) if ((*i).second == key) { std::string use = (*i).first; - int idx = 0; + size_t idx = 0; idx = use.find("KEY_"); if (idx != std::string::npos) { diff --git a/BBGE/TTFFont.cpp b/BBGE/TTFFont.cpp index 00e1376..89c8c56 100644 --- a/BBGE/TTFFont.cpp +++ b/BBGE/TTFFont.cpp @@ -221,7 +221,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) { @@ -235,7 +235,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 bd57538..92dfbc4 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -156,7 +156,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++) @@ -164,9 +164,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; } } @@ -183,17 +183,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; } } @@ -453,9 +453,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 0b7a328..ad5c8e0 100644 --- a/BBGE/Vector.cpp +++ b/BBGE/Vector.cpp @@ -165,7 +165,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(); @@ -188,7 +188,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(); @@ -205,7 +205,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++) @@ -226,7 +226,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++) @@ -235,7 +235,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()); } @@ -245,7 +245,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++) @@ -256,7 +256,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]); } @@ -278,7 +278,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 6d3ceb4..a8e0158 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 6754ae3..476fd19 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; From 4c7c4c240ed2a540566ee7496c28353efb19cd87 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Sat, 14 Jan 2017 18:23:53 +0100 Subject: [PATCH 2/6] Fix some more warnings --- Aquaria/AquariaComboBox.cpp | 2 +- Aquaria/Continuity.cpp | 4 ++-- Aquaria/DSQ.cpp | 2 +- Aquaria/SceneEditor.cpp | 12 ++++-------- Aquaria/ScriptInterface.cpp | 4 ++-- Aquaria/ScriptedEntity.cpp | 2 +- BBGE/BitmapFont.cpp | 7 ++----- BBGE/ParticleManager.cpp | 12 +++++++----- BBGE/Particles.h | 2 +- BBGE/Quad.cpp | 2 +- BBGE/SkeletalSprite.cpp | 4 ++-- 11 files changed, 24 insertions(+), 29 deletions(-) diff --git a/Aquaria/AquariaComboBox.cpp b/Aquaria/AquariaComboBox.cpp index 803af98..4b5ba97 100644 --- a/Aquaria/AquariaComboBox.cpp +++ b/Aquaria/AquariaComboBox.cpp @@ -84,7 +84,7 @@ void AquariaComboBox::setScroll(size_t sc) std::string AquariaComboBox::getSelectedItemString() { - if (selectedItem >= 0 && selectedItem < items.size()) + if (selectedItem < items.size()) return items[selectedItem]; return ""; } diff --git a/Aquaria/Continuity.cpp b/Aquaria/Continuity.cpp index 1fef254..101ff74 100644 --- a/Aquaria/Continuity.cpp +++ b/Aquaria/Continuity.cpp @@ -495,7 +495,7 @@ void Continuity::setFishPoison(float m, float t) 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; @@ -2284,7 +2284,7 @@ void Continuity::loadPetData() 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"; diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index e7543a7..5c495f3 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2875,7 +2875,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(); diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index e4d9e69..fc1ecbf 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -1468,7 +1468,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()) { @@ -2317,7 +2317,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(); @@ -2540,12 +2540,9 @@ void SceneEditor::doPrevElement() { int oldCur = curElement; curElement--; - if (curElement < 0) + if (curElement >= game->elementTemplates.size()) curElement = dsq->game->elementTemplates.size()-1; - if (curElement < 0) - return; - if (dsq->game->elementTemplates[curElement].idx < 1024) { placer->setTexture(dsq->game->elementTemplates[curElement].gfx); @@ -3106,8 +3103,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: diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 3518fea..481d36f 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -8484,7 +8484,7 @@ luaFunc(setGemBlink) 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); @@ -8501,7 +8501,7 @@ luaFunc(setGemBlink) luaFunc(removeGem) { size_t gemId = lua_tointeger(L, 1); - 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); diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 4ae58be..a692a80 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -199,7 +199,7 @@ void ScriptedEntity::initSegments(int numSegments, int minDist, int maxDist, std this->minDist = minDist; this->maxDist = maxDist; segments.resize(numSegments); - for (size_t i = segments.size()-1; i >= 0 ; i--) + for (size_t i = segments.size(); i-- >= 0 ; ) { Quad *q = new Quad; if (i == segments.size()-1) diff --git a/BBGE/BitmapFont.cpp b/BBGE/BitmapFont.cpp index 4323334..1e43482 100644 --- a/BBGE/BitmapFont.cpp +++ b/BBGE/BitmapFont.cpp @@ -281,12 +281,9 @@ void BitmapText::onUpdate(float dt) 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; } diff --git a/BBGE/ParticleManager.cpp b/BBGE/ParticleManager.cpp index b6e24ae..ac67281 100644 --- a/BBGE/ParticleManager.cpp +++ b/BBGE/ParticleManager.cpp @@ -207,14 +207,16 @@ 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) + if (free != ~0UL) { this->free = free; } diff --git a/BBGE/Particles.h b/BBGE/Particles.h index 9f8b244..7ce9503 100644 --- a/BBGE/Particles.h +++ b/BBGE/Particles.h @@ -217,7 +217,7 @@ public: void endParticle(Particle *p); - void setFree(int free); + void setFree(size_t free); int getFree() { return free; } int getNumActive() { return numActive; } diff --git a/BBGE/Quad.cpp b/BBGE/Quad.cpp index 87abfb7..2ae330f 100644 --- a/BBGE/Quad.cpp +++ b/BBGE/Quad.cpp @@ -106,7 +106,7 @@ void Quad::createGrid(int xd, int yd) 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; } diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index b292bd0..597605b 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -1093,7 +1093,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; } @@ -1878,7 +1878,7 @@ void SkeletalSprite::selectNextBone() selectedBone--; if(selectedBone == oldsel) break; - if (selectedBone < 0) + if (selectedBone >= bones.size()) selectedBone = bones.size()-1; } while (!bones[selectedBone]->selectable); From d57d98996384675b07e99ea33a5f35fb0ee7dc5f Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Sat, 14 Jan 2017 18:30:58 +0100 Subject: [PATCH 3/6] This one slipped through --- Aquaria/ScriptedEntity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index a692a80..d811a26 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -199,7 +199,7 @@ void ScriptedEntity::initSegments(int numSegments, int minDist, int maxDist, std this->minDist = minDist; this->maxDist = maxDist; segments.resize(numSegments); - for (size_t i = segments.size(); i-- >= 0 ; ) + for (size_t i = segments.size(); i-- > 0 ; ) { Quad *q = new Quad; if (i == segments.size()-1) From c3f1058ff278b40da37736e444b0374e6de0eef2 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Sat, 14 Jan 2017 20:10:42 +0100 Subject: [PATCH 4/6] Change some stuff for butt-endian architectures --- Aquaria/UserSettings.cpp | 8 ++++++-- BBGE/Shader.cpp | 6 +++--- BBGE/Shader.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Aquaria/UserSettings.cpp b/Aquaria/UserSettings.cpp index ec994a1..c708c82 100644 --- a/Aquaria/UserSettings.cpp +++ b/Aquaria/UserSettings.cpp @@ -506,8 +506,12 @@ void UserSettings::load(bool doApply, const std::string &overrideFile) XMLElement *xml_data = doc.FirstChildElement("Data"); if (xml_data) { - xml_data->QueryUnsignedAttribute("savePage", (unsigned int *)&data.savePage); - xml_data->QueryUnsignedAttribute("saveSlot", (unsigned int *)&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/BBGE/Shader.cpp b/BBGE/Shader.cpp index 0e5546f..874384c 100644 --- a/BBGE/Shader.cpp +++ b/BBGE/Shader.cpp @@ -370,7 +370,7 @@ void Shader::_queryUniforms() { glGetObjectParameterivARB(g_programObj, GL_OBJECT_ACTIVE_UNIFORMS_ARB , (GLint*)&numUniforms); - if (numUniforms <= 0) + if (numUniforms == 0 || numUniforms == -1) { uniforms.clear(); return; @@ -426,7 +426,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()) @@ -444,7 +444,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 add57dc..8e29b7a 100644 --- a/BBGE/Shader.h +++ b/BBGE/Shader.h @@ -46,7 +46,7 @@ protected: std::string vertFile, fragFile; std::string vertSrc, fragSrc; GLuint g_programObj; - size_t numUniforms; + unsigned int numUniforms; private: static void staticInit(); From 812848e38216048a826036d08d6d1ddefe1d8f5d Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 11 Jan 2021 19:26:32 +0100 Subject: [PATCH 5/6] Fix crash on startup --- Aquaria/SceneEditor.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index fc1ecbf..a5fba4a 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -2538,12 +2538,18 @@ void SceneEditor::prevElement() void SceneEditor::doPrevElement() { - int oldCur = curElement; - curElement--; - if (curElement >= game->elementTemplates.size()) - curElement = dsq->game->elementTemplates.size()-1; + size_t oldCur = curElement; + size_t maxn = dsq->game->elementTemplates.size(); - if (dsq->game->elementTemplates[curElement].idx < 1024) + if(curElement) + curElement--; + else if(maxn) + curElement = maxn-1; + + if (maxn && curElement >= maxn) + curElement = maxn-1; + + if (maxn && dsq->game->elementTemplates[curElement].idx < 1024) { placer->setTexture(dsq->game->elementTemplates[curElement].gfx); } From 25696c44363c28538ea5bd746e2d89dc8532b5dd Mon Sep 17 00:00:00 2001 From: fgenesis Date: Mon, 11 Jan 2021 19:27:54 +0100 Subject: [PATCH 6/6] Enable msvc signed/unsigned mismatch warnings and fix remaining cases --- BBGE/Base.h | 4 ++-- BBGE/ParticleManager.cpp | 15 +++------------ BBGE/Particles.h | 3 +-- BBGE/Texture.cpp | 4 ++-- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/BBGE/Base.h b/BBGE/Base.h index 9559c51..3fe5382 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -66,7 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning(disable:4005) #pragma warning(disable:4305) -#pragma warning(disable:4018) // signed/unsigned mismatch +//#pragma warning(disable:4018) // signed/unsigned mismatch #pragma warning(disable:4244) // conversion from types with possible loss of data #pragma warning(disable:4800) // forcing value to bool 'true' or 'false (performance warning) @@ -77,7 +77,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning(disable:4127) // conditional expression is constant #pragma warning(disable:4706) // assignment within conditional expression -#pragma warning(disable:4389) // signed/unsigned mismatch +//#pragma warning(disable:4389) // signed/unsigned mismatch #pragma warning(disable:4189) // UqqqqSEFUL: local variable is initialized but not referenced #endif diff --git a/BBGE/ParticleManager.cpp b/BBGE/ParticleManager.cpp index ac67281..82caad9 100644 --- a/BBGE/ParticleManager.cpp +++ b/BBGE/ParticleManager.cpp @@ -198,22 +198,13 @@ void ParticleManager::endParticle(Particle *p) p->reset(); } -void ParticleManager::nextFree(int jump) +void ParticleManager::nextFree(size_t jump) { free+=jump; if (free >= size) free -= size; } -void ParticleManager::prevFree(int jump) -{ - if(free < jump) { - free = free + size - jump; - } else { - free -= jump; - } -} - void ParticleManager::setFree(size_t free) { if (free != ~0UL) @@ -222,8 +213,8 @@ void ParticleManager::setFree(size_t free) } } -const int spread = 8; -const int spreadCheck = 128; +static const size_t spread = 8; +static const size_t spreadCheck = 128; // travel the list until you find an empty or give up Particle *ParticleManager::stomp() diff --git a/BBGE/Particles.h b/BBGE/Particles.h index 7ce9503..14ce8f3 100644 --- a/BBGE/Particles.h +++ b/BBGE/Particles.h @@ -237,8 +237,7 @@ protected: size_t numActive; Particle* stomp(); - void nextFree(int f=1); - void prevFree(int f=1); + void nextFree(size_t f=1); size_t oldFree; diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index 92dfbc4..472c691 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -449,7 +449,7 @@ ImageTGA *Texture::TGAloadMem(void *mem, int size) ByteBuffer bb(mem, size, ByteBuffer::REUSE); ImageTGA *pImageData = NULL; // This stores our important image data - WORD width = 0, height = 0; // The dimensions of the image + uint16_t width = 0, height = 0; // The dimensions of the image 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) @@ -604,7 +604,7 @@ ImageTGA *Texture::TGAloadMem(void *mem, int size) byte *pColors = new byte [channels]; // Load in all the pixel data - while(i < width*height) + while(i < size_t(width)*height) { // Read in the current color count + 1 bb >> rleID;