Fixed aspect ratio on split screen views
This commit is contained in:
parent
77dc2f0ceb
commit
6f49fecab4
3 changed files with 17 additions and 31 deletions
8
TODO.md
8
TODO.md
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
## Next
|
## Next
|
||||||
|
|
||||||
- Mutliplayer viewports wrong aspect ratio
|
- Player spawns initially at (0,0) and almost fails to jump to target spawn
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
||||||
- Player spawns initially at (0,0) and almost fails to jump to target spawn
|
|
||||||
- Player disconnect in multiplayer sometimes targeting disconnected player or something like that
|
- Player disconnect in multiplayer sometimes targeting disconnected player or something like that
|
||||||
|
|
||||||
## High priority
|
## High priority
|
||||||
|
@ -14,13 +13,14 @@
|
||||||
- Procedural level generation
|
- Procedural level generation
|
||||||
- Physics
|
- Physics
|
||||||
- Damage other players on contact
|
- Damage other players on contact
|
||||||
- Menu (At least before the game starts a player-join-screen)
|
- Players-join-screen before the game starts
|
||||||
- Game over screen
|
- Game over screen
|
||||||
- Score
|
|
||||||
- Proper player graphics
|
- Proper player graphics
|
||||||
- Collectables with graphics
|
- Collectables with graphics
|
||||||
|
|
||||||
## Low priority
|
## Low priority
|
||||||
|
|
||||||
|
- Score
|
||||||
- Player actions like shrinking hole or throwing bomb
|
- Player actions like shrinking hole or throwing bomb
|
||||||
|
- Menu
|
||||||
- Sound
|
- Sound
|
||||||
|
|
|
@ -3,11 +3,9 @@
|
||||||
#include "../player/player_collection.hpp"
|
#include "../player/player_collection.hpp"
|
||||||
|
|
||||||
TrackingView::TrackingView(TrackingViewOptions options) : options(options),
|
TrackingView::TrackingView(TrackingViewOptions options) : options(options),
|
||||||
view(nullptr),
|
view(new sf::View()),
|
||||||
hasViewChanged(false),
|
|
||||||
trackables({})
|
trackables({})
|
||||||
{
|
{
|
||||||
initializeView();
|
|
||||||
marker = new CircleObject(DB_CIRCLE_RADIUS, sf::Color::Yellow);
|
marker = new CircleObject(DB_CIRCLE_RADIUS, sf::Color::Yellow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,20 +24,6 @@ void TrackingView::lateUpdate()
|
||||||
followTrackables();
|
followTrackables();
|
||||||
adjustSizeToTrackables();
|
adjustSizeToTrackables();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update window if necessary
|
|
||||||
if (hasViewChanged)
|
|
||||||
{
|
|
||||||
this->setViewForWindow();
|
|
||||||
hasViewChanged = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackingView::initializeView()
|
|
||||||
{
|
|
||||||
auto size = Game::getInstance()->window->getView().getSize();
|
|
||||||
view = new sf::View({0, 0}, size);
|
|
||||||
hasViewChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackingView::setSize(sf::Vector2f newSize)
|
void TrackingView::setSize(sf::Vector2f newSize)
|
||||||
|
@ -67,7 +51,6 @@ void TrackingView::setSize(sf::Vector2f newSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
view->setSize(newSize);
|
view->setSize(newSize);
|
||||||
hasViewChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f TrackingView::getSize() const
|
sf::Vector2f TrackingView::getSize() const
|
||||||
|
@ -75,10 +58,11 @@ sf::Vector2f TrackingView::getSize() const
|
||||||
return view->getSize();
|
return view->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f TrackingView::getWindowSize() const
|
sf::Vector2f TrackingView::getSizeInWindow() const
|
||||||
{
|
{
|
||||||
auto size = Game::getInstance()->window->getSize();
|
auto size = Game::getInstance()->window->getSize();
|
||||||
return {static_cast<float>(size.x), static_cast<float>(size.y)};
|
auto viewPort = view->getViewport();
|
||||||
|
return {static_cast<float>(size.x * viewPort.width), static_cast<float>(size.y * viewPort.height)};
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f TrackingView::getCenter() const
|
sf::Vector2f TrackingView::getCenter() const
|
||||||
|
@ -125,7 +109,6 @@ void TrackingView::moveCenter(sf::Vector2<float> delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
view->move(delta);
|
view->move(delta);
|
||||||
hasViewChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackingView::draw(sf::RenderWindow *window)
|
void TrackingView::draw(sf::RenderWindow *window)
|
||||||
|
@ -141,6 +124,12 @@ void TrackingView::draw(sf::RenderWindow *window)
|
||||||
void TrackingView::addTrackable(const std::shared_ptr<ITrackable> &trackable)
|
void TrackingView::addTrackable(const std::shared_ptr<ITrackable> &trackable)
|
||||||
{
|
{
|
||||||
trackables.push_back(trackable);
|
trackables.push_back(trackable);
|
||||||
|
|
||||||
|
// Set initial values if first trackable
|
||||||
|
if (trackables.size() == 1)
|
||||||
|
{
|
||||||
|
view->setCenter(trackable->getTrackablePosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackingView::processTrackableStates()
|
void TrackingView::processTrackableStates()
|
||||||
|
@ -199,7 +188,7 @@ void TrackingView::adjustSizeToTrackables()
|
||||||
newViewSize = restrainToBounds(newViewSize);
|
newViewSize = restrainToBounds(newViewSize);
|
||||||
|
|
||||||
// Extend view to match aspect ratio
|
// Extend view to match aspect ratio
|
||||||
auto windowSize = getWindowSize();
|
auto windowSize = getSizeInWindow();
|
||||||
auto aspectRatio = windowSize.x / windowSize.y;
|
auto aspectRatio = windowSize.x / windowSize.y;
|
||||||
if (newViewSize.x / newViewSize.y > aspectRatio)
|
if (newViewSize.x / newViewSize.y > aspectRatio)
|
||||||
{
|
{
|
||||||
|
@ -261,7 +250,7 @@ float TrackingView::getRadius(float threshold) const
|
||||||
return threshold;
|
return threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto windowSize = getWindowSize();
|
auto windowSize = getSizeInWindow();
|
||||||
float smallestSide = std::min(windowSize.x, windowSize.y);
|
float smallestSide = std::min(windowSize.x, windowSize.y);
|
||||||
|
|
||||||
// Only half of the side, since we are calculating radius
|
// Only half of the side, since we are calculating radius
|
||||||
|
|
|
@ -35,14 +35,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sf::View *view{};
|
sf::View *view{};
|
||||||
bool hasViewChanged{};
|
|
||||||
TrackingViewOptions options;
|
TrackingViewOptions options;
|
||||||
std::vector<std::shared_ptr<ITrackable>> trackables;
|
std::vector<std::shared_ptr<ITrackable>> trackables;
|
||||||
|
|
||||||
CircleObject *marker;
|
CircleObject *marker;
|
||||||
|
|
||||||
void initializeView();
|
|
||||||
|
|
||||||
void followTrackables();
|
void followTrackables();
|
||||||
|
|
||||||
void moveCenter(sf::Vector2<float> delta);
|
void moveCenter(sf::Vector2<float> delta);
|
||||||
|
@ -61,7 +58,7 @@ private:
|
||||||
|
|
||||||
float getRadius(float threshold) const;
|
float getRadius(float threshold) const;
|
||||||
|
|
||||||
sf::Vector2f getWindowSize() const;
|
sf::Vector2f getSizeInWindow() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue