1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Cleanum & formatting

This commit is contained in:
Ivan Savenko 2023-02-19 23:09:19 +02:00
parent ca13e7dedf
commit 685cc91029
3 changed files with 51 additions and 57 deletions

View File

@ -30,40 +30,34 @@
struct NeighborTilesInfo
{
bool d7, //789
d8, //456
d9, //123
d4,
d5,
d6,
d1,
d2,
d3;
NeighborTilesInfo( const IMapRendererContext & context, const int3 & pos)
{
auto getTile = [&](int dx, int dy)->bool
{
if ( dx + pos.x < 0 || dx + pos.x >= context.getMapSize().x
|| dy + pos.y < 0 || dy + pos.y >= context.getMapSize().y)
return false;
//567
//3 4
//012
std::bitset<8> d;
//FIXME: please do not read settings for every tile...
return context.isVisible( pos + int3(dx, dy, 0));
NeighborTilesInfo(const IMapRendererContext & context, const int3 & pos)
{
auto checkTile = [&](int dx, int dy)
{
return context.isVisible(pos + int3(dx, dy, 0));
};
d7 = getTile(-1, -1); //789
d8 = getTile( 0, -1); //456
d9 = getTile(+1, -1); //123
d4 = getTile(-1, 0);
d5 = getTile( 0, 0);
d6 = getTile(+1, 0);
d1 = getTile(-1, +1);
d2 = getTile( 0, +1);
d3 = getTile(+1, +1);
// sides
d[1] = checkTile(0, +1);
d[3] = checkTile(-1, 0);
d[4] = checkTile(+1, 0);
d[6] = checkTile(0, -1);
// corners - select visible image if either corner or adjacent sides are visible
d[0] = d[1] || d[3] || checkTile(-1, +1);
d[2] = d[1] || d[4] || checkTile(+1, +1);
d[5] = d[3] || d[6] || checkTile(-1, -1);
d[7] = d[4] || d[6] || checkTile(+1, -1);
}
bool areAllHidden() const
{
return !(d1 || d2 || d3 || d4 || d5 || d6 || d7 || d8 || d9);
return d.none();
}
int getBitmapID() const
@ -89,7 +83,7 @@ struct NeighborTilesInfo
13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10 //256
};
return visBitmaps[d1 + d2 * 2 + d3 * 4 + d4 * 8 + d6 * 16 + d7 * 32 + d8 * 64 + d9 * 128]; // >=0 -> partial hide, <0 - full hide
return visBitmaps[d.to_ulong()]; // >=0 -> partial hide, <0 - full hide
}
};
@ -482,7 +476,7 @@ void MapRendererObjects::renderImage(const IMapRendererContext & context, Canvas
}
}
void MapRendererObjects::renderObject(const IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance* instance)
void MapRendererObjects::renderObject(const IMapRendererContext & context, Canvas & target, const int3 & coordinates, const CGObjectInstance * instance)
{
renderImage(context, target, coordinates, instance, getImage(context, instance, getBaseAnimation(instance)));
renderImage(context, target, coordinates, instance, getImage(context, instance, getFlagAnimation(instance)));
@ -614,7 +608,7 @@ void MapRenderer::renderTile(const IMapRendererContext & context, Canvas & targe
const NeighborTilesInfo neighborInfo(context, coordinates);
if(neighborInfo.areAllHidden())
if(!context.isVisible(coordinates) && neighborInfo.areAllHidden())
{
rendererFow.renderTile(context, target, coordinates);
}

View File

@ -400,7 +400,7 @@ size_t MapRendererContext::objectGroupIndex(ObjectInstanceID objectID) const
if(obj->ID == Obj::HERO)
{
const auto * hero = dynamic_cast<const CGHeroInstance *>(obj);
if (movementAnimation && movementAnimation->target == objectID)
if(movementAnimation && movementAnimation->target == objectID)
return moveGroups[hero->moveDir];
return idleGroups[hero->moveDir];
}
@ -411,7 +411,7 @@ size_t MapRendererContext::objectGroupIndex(ObjectInstanceID objectID) const
uint8_t direction = boat->hero ? boat->hero->moveDir : boat->direction;
if (movementAnimation && movementAnimation->target == objectID)
if(movementAnimation && movementAnimation->target == objectID)
return moveGroups[direction];
return idleGroups[direction];
}
@ -420,13 +420,13 @@ size_t MapRendererContext::objectGroupIndex(ObjectInstanceID objectID) const
Point MapRendererContext::objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const
{
if (movementAnimation && movementAnimation->target == objectID)
if(movementAnimation && movementAnimation->target == objectID)
{
int3 offsetTilesFrom = movementAnimation->tileFrom - coordinates;
int3 offsetTilesDest = movementAnimation->tileDest - coordinates;
Point offsetPixelsFrom = Point(offsetTilesFrom) * Point(32,32);
Point offsetPixelsDest = Point(offsetTilesDest) * Point(32,32);
Point offsetPixelsFrom = Point(offsetTilesFrom) * Point(32, 32);
Point offsetPixelsDest = Point(offsetTilesDest) * Point(32, 32);
Point result = vstd::lerp(offsetPixelsFrom, offsetPixelsDest, movementAnimation->progress);
@ -442,21 +442,21 @@ double MapRendererContext::objectTransparency(ObjectInstanceID objectID) const
{
const CGObjectInstance * object = getObject(objectID);
if (object && object->ID == Obj::HERO)
if(object && object->ID == Obj::HERO)
{
const auto * hero = dynamic_cast<const CGHeroInstance *>(object);
if (hero->inTownGarrison)
if(hero->inTownGarrison)
return 0;
if (hero->boat)
if(hero->boat)
return 0;
}
if (fadeOutAnimation && objectID == fadeOutAnimation->target)
if(fadeOutAnimation && objectID == fadeOutAnimation->target)
return 1.0 - fadeOutAnimation->progress;
if (fadeInAnimation && objectID == fadeInAnimation->target)
if(fadeInAnimation && objectID == fadeInAnimation->target)
return fadeInAnimation->progress;
return 1.0;
@ -482,7 +482,7 @@ void MapViewController::update(uint32_t timeDelta)
//FIXME: remove code duplication?
if (context->movementAnimation)
if(context->movementAnimation)
{
// TODO: enemyMoveTime
double heroMoveTime = settings["adventure"]["heroMoveTime"].Float();
@ -496,7 +496,7 @@ void MapViewController::update(uint32_t timeDelta)
setViewCenter(positionCurr, context->movementAnimation->tileDest.z);
if (context->movementAnimation->progress >= 1.0)
if(context->movementAnimation->progress >= 1.0)
{
setViewCenter(context->movementAnimation->tileDest);
@ -506,27 +506,27 @@ void MapViewController::update(uint32_t timeDelta)
}
}
if (context->teleportAnimation)
if(context->teleportAnimation)
{
context->teleportAnimation->progress += timeDelta / heroTeleportDuration;
if (context->teleportAnimation->progress >= 1.0)
if(context->teleportAnimation->progress >= 1.0)
context->teleportAnimation.reset();
}
if (context->fadeOutAnimation)
if(context->fadeOutAnimation)
{
context->fadeOutAnimation->progress += timeDelta / fadeOutDuration;
if (context->fadeOutAnimation->progress >= 1.0)
if(context->fadeOutAnimation->progress >= 1.0)
{
context->removeObject(context->getObject(context->fadeOutAnimation->target));
context->fadeOutAnimation.reset();
}
}
if (context->fadeInAnimation)
if(context->fadeInAnimation)
{
context->fadeInAnimation->progress += timeDelta / fadeInDuration;
if (context->fadeInAnimation->progress >= 1.0)
if(context->fadeInAnimation->progress >= 1.0)
context->fadeInAnimation.reset();
}
@ -560,7 +560,7 @@ void MapViewController::onObjectInstantRemove(const CGObjectInstance * obj)
void MapViewController::onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
{
assert(!context->teleportAnimation);
context->teleportAnimation = HeroAnimationState{ obj->id, from, dest, 0.0 };
context->teleportAnimation = HeroAnimationState{obj->id, from, dest, 0.0};
}
void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest)
@ -568,15 +568,15 @@ void MapViewController::onHeroMoved(const CGHeroInstance * obj, const int3 & fro
assert(!context->movementAnimation);
const CGObjectInstance * movingObject = obj;
if (obj->boat)
if(obj->boat)
movingObject = obj->boat;
context->removeObject(movingObject);
if (settings["adventure"]["heroMoveTime"].Float() > 1)
if(settings["adventure"]["heroMoveTime"].Float() > 1)
{
context->addMovingObject(movingObject, from, dest);
context->movementAnimation = HeroAnimationState{ movingObject->id, from, dest, 0.0 };
context->movementAnimation = HeroAnimationState{movingObject->id, from, dest, 0.0};
}
else
{

View File

@ -9,9 +9,9 @@
*/
#pragma once
#include "MapRendererContext.h"
#include "../gui/CIntObject.h"
#include "../lib/int3.h"
#include "MapRendererContext.h"
class IImage;
class Canvas;
@ -155,9 +155,9 @@ private:
void onObjectFadeOut(const CGObjectInstance * obj) override;
void onObjectInstantAdd(const CGObjectInstance * obj) override;
void onObjectInstantRemove(const CGObjectInstance * obj) override;
void onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
void onHeroRotated(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
void onHeroTeleported(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
void onHeroMoved(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
void onHeroRotated(const CGHeroInstance * obj, const int3 & from, const int3 & dest) override;
public:
MapViewController(std::shared_ptr<MapRendererContext> context, std::shared_ptr<MapViewModel> model);