diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-03-05 03:23:24 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-03-05 03:23:24 +0300 |
commit | 3f43bdd12b50a2ff3afb687fd3d2101865e946f2 (patch) | |
tree | 218051a0398f77ea3ca555ba706daea82a32f8e0 | |
parent | 31782ba3cdeced9baa91739c55e9ae819d70d616 (diff) | |
download | manaverse-3f43bdd12b50a2ff3afb687fd3d2101865e946f2.tar.gz manaverse-3f43bdd12b50a2ff3afb687fd3d2101865e946f2.tar.bz2 manaverse-3f43bdd12b50a2ff3afb687fd3d2101865e946f2.tar.xz manaverse-3f43bdd12b50a2ff3afb687fd3d2101865e946f2.zip |
Use in most places int being positions and not float.
-rw-r--r-- | src/actormanager.cpp | 2 | ||||
-rw-r--r-- | src/being/being.cpp | 40 | ||||
-rw-r--r-- | src/being/flooritem.cpp | 12 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 99 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 26 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 25 |
6 files changed, 101 insertions, 103 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp index 3769eceee..471d8d72e 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -87,6 +87,8 @@ class FindBeingFunctor final const unsigned other_y = y + ((b->getType() == ActorType::Npc) ? 1 : 0); const Vector &pos = b->getPixelPositionF(); + // +++ probably here need use int positions and not float? + // but for now correct int positions only in Being return (CAST_U32(pos.x) / mapTileSize == x && (CAST_U32(pos.y) / mapTileSize == y || CAST_U32(pos.y) / mapTileSize == other_y) && diff --git a/src/being/being.cpp b/src/being/being.cpp index c45616ee8..319bf34eb 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -630,8 +630,8 @@ void Being::setSpeech(const std::string &restrict text, { delete mText; mText = new Text(mSpeech, - CAST_S32(mPos.x), - CAST_S32(mPos.y) - getHeight(), + mPixelX, + mPixelY - getHeight(), Graphics::CENTER, &userPalette->getColor(UserColorId::PARTICLE), Speech_true); @@ -755,8 +755,8 @@ void Being::takeDamage(Being *restrict const attacker, { // Show damage number particleEngine->addTextSplashEffect(damage, - CAST_S32(mPos.x), - CAST_S32(mPos.y) - 16, + mPixelX, + mPixelY - 16, color, font, true); @@ -1296,8 +1296,8 @@ void Being::fireMissile(Being *restrict const victim, Particle *restrict const missile = target->addEffect( particle, - CAST_S32(mPos.x), - CAST_S32(mPos.y)); + mPixelX, + mPixelY); if (missile) { @@ -2071,8 +2071,8 @@ void Being::drawEmotion(Graphics *restrict const graphics, const int offsetX, const int offsetY) const restrict2 { - const int px = CAST_S32(mPos.x) - offsetX - mapTileSize / 2; - const int py = CAST_S32(mPos.y) - offsetY - mapTileSize * 2 - mapTileSize; + const int px = mPixelX - offsetX - mapTileSize / 2; + const int py = mPixelY - offsetY - mapTileSize * 2 - mapTileSize; if (mAnimationEffect) mAnimationEffect->draw(graphics, px, py); if (mShowBadges && mBadgesCount) @@ -2115,8 +2115,8 @@ void Being::drawSpeech(const int offsetX, if (mSpeech.empty()) return; - const int px = CAST_S32(mPos.x) - offsetX; - const int py = CAST_S32(mPos.y) - offsetY; + const int px = mPixelX - offsetX; + const int py = mPixelY - offsetY; const int speech = mSpeechType; // Draw speech above this being @@ -2147,8 +2147,8 @@ void Being::drawSpeech(const int offsetX, if (!mText && userPalette) { mText = new Text(mSpeech, - CAST_S32(mPos.x), - CAST_S32(mPos.y) - getHeight(), + mPixelX, + mPixelY - getHeight(), Graphics::CENTER, &theme->getColor(ThemeColorId::BUBBLE_TEXT, 255), Speech_true); @@ -2204,8 +2204,8 @@ void Being::updateCoords() restrict2 if (!mDispName) return; - int offsetX = CAST_S32(mPos.x); - int offsetY = CAST_S32(mPos.y); + int offsetX = mPixelX; + int offsetY = mPixelY; if (mInfo) { offsetX += mInfo->getNameOffsetX(); @@ -2309,8 +2309,8 @@ void Being::showName() restrict2 if (mInfo) { mDispName = new FlashText(displayName, - CAST_S32(mPos.x) + mInfo->getNameOffsetX(), - CAST_S32(mPos.y) + mInfo->getNameOffsetY(), + mPixelX + mInfo->getNameOffsetX(), + mPixelY + mInfo->getNameOffsetY(), Graphics::CENTER, mNameColor, font); @@ -2318,8 +2318,8 @@ void Being::showName() restrict2 else { mDispName = new FlashText(displayName, - CAST_S32(mPos.x), - CAST_S32(mPos.y), + mPixelX, + mPixelY, Graphics::CENTER, mNameColor, font); @@ -2867,9 +2867,9 @@ void Being::draw(Graphics *restrict const graphics, if (!mErased) { // getActorX() + offsetX; - const int px = CAST_S32(mPos.x) - mapTileSize / 2 + offsetX; + const int px = mPixelX - mapTileSize / 2 + offsetX; // getActorY() + offsetY; - const int py = CAST_S32(mPos.y) - mapTileSize + offsetY; + const int py = mPixelY - mapTileSize + offsetY; #ifdef EATHENA_SUPPORT if (mHorseInfo) { diff --git a/src/being/flooritem.cpp b/src/being/flooritem.cpp index a33a5b09b..05352c40f 100644 --- a/src/being/flooritem.cpp +++ b/src/being/flooritem.cpp @@ -99,14 +99,18 @@ void FloorItem::postInit(Map *const map, int subX, int subY) } mHeightPosDiff = map->getHeightOffset(mX, mY) * 16; - mPos.x = static_cast<float>(mX * map->getTileWidth() - + subX + mapTileSize / 2); - mPos.y = static_cast<float>(mY * map->getTileHeight() - + subY + mapTileSize - mHeightPosDiff); + mPixelX = mX * map->getTileWidth() + + subX + mapTileSize / 2; + mPixelY = mY * map->getTileHeight() + + subY + mapTileSize - mHeightPosDiff; + mPos.x = static_cast<float>(mPixelX); + mPos.y = static_cast<float>(mPixelY); mYDiff = 31 - mHeightPosDiff; } else { + mPixelX = 0; + mPixelY = 0; mPos.x = 0; mPos.y = 0; mYDiff = 31; diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 87b2d8213..ecc3b20e4 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -278,8 +278,8 @@ void LocalPlayer::logic() { particleEngine->addTextRiseFadeOutEffect( info.first, - CAST_S32(mPos.x), - CAST_S32(mPos.y) - 48, + mPixelX, + mPixelY - 48, &userPalette->getColor(info.second), gui->getInfoParticleFont(), true); @@ -497,11 +497,13 @@ bool LocalPlayer::pickUp(FloorItem *const item) } else if (pickUpType >= 4 && pickUpType <= 6) { - const Vector &playerPos = getPixelPositionF(); const Path debugPath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - item->getTileX(), item->getTileY(), getBlockWalkMask(), 0); + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, + item->getTileX(), + item->getTileY(), + getBlockWalkMask(), + 0); if (!debugPath.empty()) navigateTo(item->getTileX(), item->getTileY()); else @@ -684,15 +686,14 @@ void LocalPlayer::stopWalking(const bool sendToServer) { mWalkingDir = 0; mPickUpTarget = nullptr; - - const Vector &pos = getPixelPositionF(); - setDestination(CAST_S32(pos.x), - CAST_S32(pos.y)); + setDestination(mPixelX, + mPixelY); if (sendToServer) { playerHandler->setDestination( - CAST_S32(pos.x), - CAST_S32(pos.y), -1); + mPixelX, + mPixelY, + -1); } setAction(BeingAction::STAND); } @@ -1203,7 +1204,6 @@ void LocalPlayer::moveToTarget(int dist) bool gotPos(false); Path debugPath; - const Vector &playerPos = getPixelPositionF(); unsigned int limit(0); if (dist == -1) @@ -1237,9 +1237,9 @@ void LocalPlayer::moveToTarget(int dist) { if (mMap) { - debugPath = mMap->findPath(CAST_S32( - playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, + debugPath = mMap->findPath( + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, mTarget->getTileX(), mTarget->getTileY(), getBlockWalkMask(), @@ -1422,12 +1422,13 @@ bool LocalPlayer::isReachable(Being *const being, return true; } - const Vector &playerPos = getPixelPositionF(); - const Path debugPath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - being->getTileX(), being->getTileY(), getBlockWalkMask(), maxCost); + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, + being->getTileX(), + being->getTileY(), + getBlockWalkMask(), + maxCost); being->setDistance(CAST_S32(debugPath.size())); if (!debugPath.empty()) @@ -1967,10 +1968,9 @@ bool LocalPlayer::navigateTo(const int x, const int y) if (!tmpLayer) return false; - const Vector &playerPos = getPixelPositionF(); mShowNavigePath = true; - mOldX = CAST_S32(playerPos.x); - mOldY = CAST_S32(playerPos.y); + mOldX = mPixelX; + mOldY = mPixelY; mOldTileX = mX; mOldTileY = mY; mNavigateX = x; @@ -1978,9 +1978,12 @@ bool LocalPlayer::navigateTo(const int x, const int y) mNavigateId = BeingId_zero; mNavigatePath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - x, y, getBlockWalkMask(), 0); + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, + x, + y, + getBlockWalkMask(), + 0); if (mDrawPath) tmpLayer->addRoad(mNavigatePath); @@ -2031,9 +2034,8 @@ void LocalPlayer::updateCoords() { Being::updateCoords(); - const Vector &playerPos = getPixelPositionF(); // probably map not loaded. - if (!playerPos.x || !playerPos.y) + if (!mPixelX || !mPixelY) return; if (mX != mOldTileX || mY != mOldTileY) @@ -2051,10 +2053,8 @@ void LocalPlayer::updateCoords() if (!tmpLayer) return; - const int x = CAST_S32(playerPos.x - mapTileSize / 2) - / mapTileSize; - const int y = CAST_S32(playerPos.y - mapTileSize) - / mapTileSize; + const int x = (mPixelX - mapTileSize / 2) / mapTileSize; + const int y = (mPixelY - mapTileSize) / mapTileSize; if (mNavigateId != BeingId_zero) { if (!actorManager) @@ -2101,8 +2101,8 @@ void LocalPlayer::updateCoords() } } } - mOldX = CAST_S32(playerPos.x); - mOldY = CAST_S32(playerPos.y); + mOldX = mPixelX; + mOldY = mPixelY; mOldTileX = mX; mOldTileY = mY; } @@ -2129,13 +2129,13 @@ int LocalPlayer::getPathLength(const Being *const being) const if (!mMap || !being) return 0; - const Vector &playerPos = getPixelPositionF(); - if (being->mX == mX && being->mY == mY) return 0; - if (being->mX - 1 <= mX && being->mX + 1 >= mX - && being->mY - 1 <= mY && being->mY + 1 >= mY) + if (being->mX - 1 <= mX && + being->mX + 1 >= mX && + being->mY - 1 <= mY && + being->mY + 1 >= mY) { return 1; } @@ -2143,10 +2143,12 @@ int LocalPlayer::getPathLength(const Being *const being) const if (mTargetOnlyReachable) { const Path debugPath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - being->getTileX(), being->getTileY(), - getBlockWalkMask(), 0); + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, + being->getTileX(), + being->getTileY(), + getBlockWalkMask(), + 0); return CAST_S32(debugPath.size()); } else @@ -2526,12 +2528,13 @@ void LocalPlayer::fixAttackTarget() return; } - const Vector &playerPos = getPixelPositionF(); const Path debugPath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - mTarget->getTileX(), mTarget->getTileY(), - getBlockWalkMask(), 0); + (mPixelX - mapTileSize / 2) / mapTileSize, + (mPixelY - mapTileSize) / mapTileSize, + mTarget->getTileX(), + mTarget->getTileY(), + getBlockWalkMask(), + 0); if (!debugPath.empty()) { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 23afa9bfd..7dddb4414 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -141,9 +141,8 @@ void Viewport::draw(Graphics *const graphics) // Calculate viewpoint - const Vector &playerPos = localPlayer->getPixelPositionF(); - const int player_x = CAST_S32(playerPos.x) - mMidTileX; - const int player_y = CAST_S32(playerPos.y) - mMidTileY; + const int player_x = localPlayer->mPixelX - mMidTileX; + const int player_y = localPlayer->mPixelY - mMidTileY; if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero @@ -314,12 +313,11 @@ void Viewport::drawDebugPath(Graphics *const graphics) if (mouseDestination.x != lastMouseDestination.x || mouseDestination.y != lastMouseDestination.y) { - const Vector &playerPos = localPlayer->getPixelPositionF(); - debugPath = mMap->findPath( - CAST_S32(playerPos.x - mapTileSize / 2) / mapTileSize, - CAST_S32(playerPos.y - mapTileSize) / mapTileSize, - mousePosX / mapTileSize, mousePosY / mapTileSize, + CAST_S32(localPlayer->mPixelX - mapTileSize / 2) / mapTileSize, + CAST_S32(localPlayer->mPixelY - mapTileSize) / mapTileSize, + mousePosX / mapTileSize, + mousePosY / mapTileSize, localPlayer->getBlockWalkMask(), 500); lastMouseDestination = mouseDestination; @@ -983,11 +981,9 @@ void Viewport::moveCameraToActor(const BeingId actorId, const Actor *const actor = actorManager->findBeing(actorId); if (!actor) return; - const Vector &actorPos = actor->getPixelPositionF(); - const Vector &playerPos = localPlayer->getPixelPositionF(); settings.cameraMode = 1; - mCameraRelativeX = CAST_S32(actorPos.x - playerPos.x) + x; - mCameraRelativeY = CAST_S32(actorPos.y - playerPos.y) + y; + mCameraRelativeX = actor->mPixelX - localPlayer->mPixelX + x; + mCameraRelativeY = actor->mPixelY - localPlayer->mPixelY + y; updateMidVars(); } @@ -996,11 +992,9 @@ void Viewport::moveCameraToPosition(const int x, const int y) if (!localPlayer) return; - const Vector &playerPos = localPlayer->getPixelPositionF(); settings.cameraMode = 1; - - mCameraRelativeX = x - CAST_S32(playerPos.x); - mCameraRelativeY = y - CAST_S32(playerPos.y); + mCameraRelativeX = x - localPlayer->mPixelX; + mCameraRelativeY = y - localPlayer->mPixelY; updateMidVars(); } diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index 3f0f4c14e..291cb7a7a 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -281,12 +281,11 @@ void Minimap::draw2(Graphics *const graphics) const int h = rect.h; if (w > a.width || h > a.height) { - const Vector &p = localPlayer->getPixelPositionF(); - mMapOriginX = (a.width / 2) - (p.x + static_cast<float>( - viewport->getCameraRelativeX()) * mWidthProportion) / 32; + mMapOriginX = (a.width / 2) - (localPlayer->mPixelX + + viewport->getCameraRelativeX() * mWidthProportion) / 32; - mMapOriginY = (a.height / 2) - (p.y + static_cast<float>( - viewport->getCameraRelativeY()) * mHeightProportion) / 32; + mMapOriginY = (a.height / 2) - (localPlayer->mPixelY + + viewport->getCameraRelativeY() * mHeightProportion) / 32; const int minOriginX = a.width - w; const int minOriginY = a.height - h; @@ -382,12 +381,10 @@ void Minimap::draw2(Graphics *const graphics) dotSize - 1) * mHeightProportion); const int offsetWidth = CAST_S32(static_cast<float>( dotSize - 1) * mWidthProportion); - const Vector &pos = being->getPixelPositionF(); - graphics->fillRectangle(Rect( - static_cast<float>(pos.x * mWidthProportion) / 32 + (being->mPixelX * mWidthProportion) / 32 + mMapOriginX - offsetWidth, - static_cast<float>(pos.y * mHeightProportion) / 32 + (being->mPixelY * mHeightProportion) / 32 + mMapOriginY - offsetHeight, dotSize, dotSize)); } @@ -435,16 +432,14 @@ void Minimap::draw2(Graphics *const graphics) } } - const Vector &pos = localPlayer->getPixelPositionF(); - const int gw = graphics->getWidth(); const int gh = graphics->getHeight(); - int x = static_cast<float>((pos.x - (gw / 2) + int x = (localPlayer->mPixelX - (gw / 2) + viewport->getCameraRelativeX()) - * mWidthProportion) / 32 + mMapOriginX; - int y = static_cast<float>((pos.y - (gh / 2) + * mWidthProportion / 32 + mMapOriginX; + int y = (localPlayer->mPixelY - (gh / 2) + viewport->getCameraRelativeY()) - * mHeightProportion) / 32 + mMapOriginY; + * mHeightProportion / 32 + mMapOriginY; const int w = CAST_S32(static_cast<float>( gw) * mWidthProportion / 32); |