restore missiles
This commit is contained in:
parent
614d34b382
commit
3a83666b9f
|
@ -59,17 +59,19 @@ namespace Otc
|
||||||
|
|
||||||
enum DrawFlags {
|
enum DrawFlags {
|
||||||
DrawGround = 1,
|
DrawGround = 1,
|
||||||
DrawWalls = 2,
|
DrawGroundBorders = 2,
|
||||||
DrawCommonItems = 4,
|
DrawOnBottom = 4,
|
||||||
DrawCreatures = 8,
|
DrawOnTop = 8,
|
||||||
DrawEffects = 16,
|
DrawItems = 16,
|
||||||
DrawMissiles = 32,
|
DrawCreatures = 32,
|
||||||
DrawCreaturesInformation = 64,
|
DrawEffects = 64,
|
||||||
DrawStaticTexts = 128,
|
DrawMissiles = 128,
|
||||||
DrawAnimatedTexts = 256,
|
DrawCreaturesInformation = 256,
|
||||||
DrawAnimations = 512,
|
DrawStaticTexts = 512,
|
||||||
DrawGroundBorders = 1024,
|
DrawAnimatedTexts = 1024,
|
||||||
DrawEverything = DrawGround | DrawGroundBorders | DrawWalls | DrawCommonItems |
|
DrawAnimations = 2048,
|
||||||
|
DrawWalls = DrawOnBottom | DrawOnTop,
|
||||||
|
DrawEverything = DrawGround | DrawGroundBorders | DrawWalls | DrawItems |
|
||||||
DrawCreatures | DrawEffects | DrawMissiles |
|
DrawCreatures | DrawEffects | DrawMissiles |
|
||||||
DrawCreaturesInformation | DrawStaticTexts | DrawAnimatedTexts | DrawAnimations
|
DrawCreaturesInformation | DrawStaticTexts | DrawAnimatedTexts | DrawAnimations
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
Position getCentralPosition() { return m_centralPosition; }
|
Position getCentralPosition() { return m_centralPosition; }
|
||||||
int getFirstAwareFloor();
|
int getFirstAwareFloor();
|
||||||
int getLastAwareFloor();
|
int getLastAwareFloor();
|
||||||
|
const std::vector<MissilePtr>& getFloorMissiles(int z) { return m_floorMissiles[z]; }
|
||||||
|
|
||||||
std::vector<AnimatedTextPtr> getAnimatedTexts() { return m_animatedTexts; }
|
std::vector<AnimatedTextPtr> getAnimatedTexts() { return m_animatedTexts; }
|
||||||
std::vector<StaticTextPtr> getStaticTexts() { return m_staticTexts; }
|
std::vector<StaticTextPtr> getStaticTexts() { return m_staticTexts; }
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "statictext.h"
|
#include "statictext.h"
|
||||||
#include "animatedtext.h"
|
#include "animatedtext.h"
|
||||||
|
#include "missile.h"
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
MapView::MapView()
|
MapView::MapView()
|
||||||
|
@ -58,30 +59,40 @@ void MapView::draw(const Rect& rect)
|
||||||
float scaleFactor = m_tileSize/(float)Otc::TILE_PIXELS;
|
float scaleFactor = m_tileSize/(float)Otc::TILE_PIXELS;
|
||||||
Position cameraPosition = getCameraPosition();
|
Position cameraPosition = getCameraPosition();
|
||||||
|
|
||||||
int tileDrawFlags = 0;
|
int drawFlags = 0;
|
||||||
if(m_viewRange == NEAR_VIEW)
|
if(m_viewRange == NEAR_VIEW)
|
||||||
tileDrawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | Otc::DrawCommonItems | Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawAnimations;
|
drawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls |
|
||||||
|
Otc::DrawItems | Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawMissiles | Otc::DrawAnimations;
|
||||||
else if(m_viewRange == MID_VIEW)
|
else if(m_viewRange == MID_VIEW)
|
||||||
tileDrawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | Otc::DrawCommonItems;
|
drawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls | Otc::DrawItems;
|
||||||
else if(m_viewRange == FAR_VIEW)
|
else if(m_viewRange == FAR_VIEW)
|
||||||
tileDrawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls;
|
drawFlags = Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawWalls;
|
||||||
else if(m_tileSize >= 4) // HUGE_VIEW 1
|
else if(m_tileSize >= 4) // HUGE_VIEW 1
|
||||||
tileDrawFlags = Otc::DrawGround | Otc::DrawGroundBorders;
|
drawFlags = Otc::DrawGround | Otc::DrawGroundBorders;
|
||||||
else // HUGE_VIEW 2
|
else // HUGE_VIEW 2
|
||||||
tileDrawFlags = Otc::DrawGround;
|
drawFlags = Otc::DrawGround;
|
||||||
|
|
||||||
bool animate = m_animated;
|
if(m_mustDrawVisibleTilesCache || (drawFlags & Otc::DrawAnimations)) {
|
||||||
|
|
||||||
// only animate in near views
|
|
||||||
if(m_viewRange != NEAR_VIEW)
|
|
||||||
animate = false;
|
|
||||||
|
|
||||||
if(m_mustDrawVisibleTilesCache || animate) {
|
|
||||||
m_framebuffer->bind(m_mustCleanFramebuffer);
|
m_framebuffer->bind(m_mustCleanFramebuffer);
|
||||||
|
|
||||||
for(const TilePtr& tile : m_cachedVisibleTiles) {
|
auto it = m_cachedVisibleTiles.begin();
|
||||||
tile->draw(transformPositionTo2D(tile->getPosition()), scaleFactor, tileDrawFlags);
|
auto end = m_cachedVisibleTiles.end();
|
||||||
//TODO: restore missiles
|
for(int z=m_cachedLastVisibleFloor;z>=m_cachedFirstVisibleFloor;--z) {
|
||||||
|
while(it != end) {
|
||||||
|
const TilePtr& tile = *it;
|
||||||
|
if(tile->getPosition().z != z)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
++it;
|
||||||
|
|
||||||
|
tile->draw(transformPositionTo2D(tile->getPosition()), scaleFactor, drawFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(drawFlags & Otc::DrawMissiles) {
|
||||||
|
for(const MissilePtr& missile : g_map.getFloorMissiles(z)) {
|
||||||
|
missile->draw(transformPositionTo2D(missile->getPosition()), scaleFactor, drawFlags & Otc::DrawAnimations);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_framebuffer->generateMipmaps();
|
m_framebuffer->generateMipmaps();
|
||||||
m_framebuffer->release();
|
m_framebuffer->release();
|
||||||
|
|
|
@ -27,54 +27,43 @@
|
||||||
#include <framework/core/clock.h>
|
#include <framework/core/clock.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
void Missile::draw(const Point& p, const Rect&)
|
void Missile::draw(const Point& dest, float scaleFactor, bool animate)
|
||||||
{
|
{
|
||||||
if(m_id == 0)
|
if(m_id == 0 || !animate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
|
||||||
float time = (g_clock.ticks() - m_startTicks) / m_duration;
|
|
||||||
|
|
||||||
int xPattern = 0, yPattern = 0;
|
int xPattern = 0, yPattern = 0;
|
||||||
if(direction == Otc::NorthWest) {
|
if(m_direction == Otc::NorthWest) {
|
||||||
xPattern = 0;
|
xPattern = 0;
|
||||||
yPattern = 0;
|
yPattern = 0;
|
||||||
}
|
} else if(m_direction == Otc::North) {
|
||||||
else if(direction == Otc::North) {
|
xPattern = 1;
|
||||||
m_xPattern = 1;
|
yPattern = 0;
|
||||||
m_yPattern = 0;
|
} else if(m_direction == Otc::NorthEast) {
|
||||||
}
|
xPattern = 2;
|
||||||
else if(direction == Otc::NorthEast) {
|
yPattern = 0;
|
||||||
m_xPattern = 2;
|
} else if(m_direction == Otc::East) {
|
||||||
m_yPattern = 0;
|
xPattern = 2;
|
||||||
}
|
yPattern = 1;
|
||||||
else if(direction == Otc::East) {
|
} else if(m_direction == Otc::SouthEast) {
|
||||||
m_xPattern = 2;
|
xPattern = 2;
|
||||||
m_yPattern = 1;
|
yPattern = 2;
|
||||||
}
|
} else if(m_direction == Otc::South) {
|
||||||
else if(direction == Otc::SouthEast) {
|
xPattern = 1;
|
||||||
m_xPattern = 2;
|
yPattern = 2;
|
||||||
m_yPattern = 2;
|
} else if(m_direction == Otc::SouthWest) {
|
||||||
}
|
xPattern = 0;
|
||||||
else if(direction == Otc::South) {
|
yPattern = 2;
|
||||||
m_xPattern = 1;
|
} else if(m_direction == Otc::West) {
|
||||||
m_yPattern = 2;
|
xPattern = 0;
|
||||||
}
|
yPattern = 1;
|
||||||
else if(direction == Otc::SouthWest) {
|
} else {
|
||||||
m_xPattern = 0;
|
xPattern = 1;
|
||||||
m_yPattern = 2;
|
yPattern = 1;
|
||||||
}
|
|
||||||
else if(direction == Otc::West) {
|
|
||||||
m_xPattern = 0;
|
|
||||||
m_yPattern = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_xPattern = 1;
|
|
||||||
m_yPattern = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//internalDraw(p + Point(m_deltax * time, m_deltay * time), 0, 0);
|
float fraction = m_animationTimer.ticksElapsed() / m_duration;
|
||||||
*/
|
internalDraw(dest + m_delta * fraction * scaleFactor, scaleFactor, xPattern, yPattern, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Missile::setPath(const Position& fromPosition, const Position& toPosition)
|
void Missile::setPath(const Position& fromPosition, const Position& toPosition)
|
||||||
|
@ -82,11 +71,9 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
|
||||||
m_direction = fromPosition.getDirectionFromPosition(toPosition);
|
m_direction = fromPosition.getDirectionFromPosition(toPosition);
|
||||||
|
|
||||||
m_position = fromPosition;
|
m_position = fromPosition;
|
||||||
m_deltax = toPosition.x - fromPosition.x;
|
m_delta = Point(toPosition.x - fromPosition.x, toPosition.y - fromPosition.y);
|
||||||
m_deltay = toPosition.y - fromPosition.y;
|
m_duration = 150 * std::sqrt(m_delta.length());
|
||||||
m_duration = 150 * std::sqrt(Point(m_deltax, m_deltay).length());
|
m_delta *= Otc::TILE_PIXELS;
|
||||||
m_deltax *= Otc::TILE_PIXELS;
|
|
||||||
m_deltay *= Otc::TILE_PIXELS;
|
|
||||||
m_animationTimer.restart();
|
m_animationTimer.restart();
|
||||||
|
|
||||||
// schedule removal
|
// schedule removal
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Missile : public Thing
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void draw(const Point& p, const Rect&);
|
void draw(const Point& dest, float scaleFactor, bool animate);
|
||||||
|
|
||||||
void updateAnimation();
|
void updateAnimation();
|
||||||
|
|
||||||
|
@ -47,8 +47,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Timer m_animationTimer;
|
Timer m_animationTimer;
|
||||||
int m_deltax;
|
Point m_delta;
|
||||||
int m_deltay;
|
|
||||||
float m_duration;
|
float m_duration;
|
||||||
uint16 m_id;
|
uint16 m_id;
|
||||||
Otc::Direction m_direction;
|
Otc::Direction m_direction;
|
||||||
|
|
|
@ -42,14 +42,14 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||||
bool animate = drawFlags & Otc::DrawAnimations;
|
bool animate = drawFlags & Otc::DrawAnimations;
|
||||||
|
|
||||||
// first bottom items
|
// first bottom items
|
||||||
if(drawFlags & Otc::DrawGround || drawFlags & Otc::DrawGroundBorders || drawFlags & Otc::DrawCommonItems) {
|
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
|
||||||
for(const ThingPtr& thing : m_things) {
|
for(const ThingPtr& thing : m_things) {
|
||||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
|
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
|
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
|
||||||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
|
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
|
||||||
(thing->isOnBottom() && drawFlags & Otc::DrawCommonItems))
|
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom))
|
||||||
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate);
|
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate);
|
||||||
|
|
||||||
drawElevation += thing->getElevation();
|
drawElevation += thing->getElevation();
|
||||||
|
@ -58,10 +58,10 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int redrawPreviousOnTopW = 0;
|
int redrawPreviousTopW = 0;
|
||||||
int redrawPreviousOnTopH = 0;
|
int redrawPreviousTopH = 0;
|
||||||
|
|
||||||
if(drawFlags & Otc::DrawCommonItems) {
|
if(drawFlags & Otc::DrawItems) {
|
||||||
// now common items in reverse order
|
// now common items in reverse order
|
||||||
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
||||||
const ThingPtr& thing = *it;
|
const ThingPtr& thing = *it;
|
||||||
|
@ -70,8 +70,8 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||||
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate);
|
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate);
|
||||||
|
|
||||||
if(thing->isLyingCorpse()) {
|
if(thing->isLyingCorpse()) {
|
||||||
redrawPreviousOnTopW = std::max(thing->getDimensionWidth(), redrawPreviousOnTopW);
|
redrawPreviousTopW = std::max(thing->getDimensionWidth(), redrawPreviousTopW);
|
||||||
redrawPreviousOnTopH = std::max(thing->getDimensionHeight(), redrawPreviousOnTopH);
|
redrawPreviousTopH = std::max(thing->getDimensionHeight(), redrawPreviousTopH);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawElevation += thing->getElevation();
|
drawElevation += thing->getElevation();
|
||||||
|
@ -80,18 +80,17 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// must redraw previous creatures/ontop above lying corpses
|
// after we render 2x2 lying corpses, we must redraw previous creatures/ontop above them
|
||||||
if(redrawPreviousOnTopH > 0 || redrawPreviousOnTopW > 0) {
|
if(redrawPreviousTopH > 0 || redrawPreviousTopW > 0) {
|
||||||
int onTopRedrawFlags = drawFlags & (Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawWalls);
|
int topRedrawFlags = drawFlags & (Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawOnTop | Otc::DrawAnimations);
|
||||||
if(onTopRedrawFlags) {
|
if(topRedrawFlags) {
|
||||||
for(int y=-redrawPreviousOnTopH;y<=0;++y) {
|
for(int y=-redrawPreviousTopH;y<=0;++y) {
|
||||||
for(int x=-redrawPreviousOnTopW;x<=0;++x) {
|
for(int x=-redrawPreviousTopW;x<=0;++x) {
|
||||||
if(x == 0 && y == 0)
|
if(x == 0 && y == 0)
|
||||||
continue;
|
continue;
|
||||||
const TilePtr& tile = g_map.getTile(m_position.translated(x,y));
|
const TilePtr& tile = g_map.getTile(m_position.translated(x,y));
|
||||||
if(tile) {
|
if(tile)
|
||||||
tile->draw(dest + Point(x*Otc::TILE_PIXELS, y*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, onTopRedrawFlags);
|
tile->draw(dest + Point(x*Otc::TILE_PIXELS, y*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, topRedrawFlags);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +120,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// top items
|
// top items
|
||||||
if(drawFlags & Otc::DrawWalls) {
|
if(drawFlags & Otc::DrawOnTop) {
|
||||||
for(const ThingPtr& thing : m_things) {
|
for(const ThingPtr& thing : m_things) {
|
||||||
if(thing->isOnTop())
|
if(thing->isOnTop())
|
||||||
thing->draw(dest - drawElevation, scaleFactor, animate);
|
thing->draw(dest - drawElevation, scaleFactor, animate);
|
||||||
|
|
Loading…
Reference in New Issue