Moved class member initializations into class definitions.
This commit is contained in:
parent
854a6438f7
commit
fdf20428b0
11 changed files with 32 additions and 40 deletions
|
@ -16,17 +16,13 @@
|
|||
#include "util/ResourceManager.h"
|
||||
#include "util/Yaml.h"
|
||||
|
||||
const int Game::FPS_GOAL = 60;
|
||||
|
||||
/**
|
||||
* Initializes game, including window and objects (sprites).
|
||||
*/
|
||||
Game::Game(tgui::Window& window) :
|
||||
mWindow(window),
|
||||
mWorldView(Vector2f(0, 0), mWindow.getView().getSize()),
|
||||
mGenerator(mWorld, mPathfinder),
|
||||
mQuit(false),
|
||||
mPaused(false) {
|
||||
mGenerator(mWorld, mPathfinder) {
|
||||
mWindow.setFramerateLimit(FPS_GOAL);
|
||||
mWindow.setKeyRepeatEnabled(false);
|
||||
srand(time(nullptr));
|
||||
|
@ -169,7 +165,8 @@ Game::input() {
|
|||
case sf::Event::MouseMoved:
|
||||
mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x,
|
||||
event.mouseMove.y));
|
||||
mCrosshair.setPosition(Vector2f(sf::Mouse::getPosition(mWindow) - Vector2i(mCrosshair.getTextureRect().width, mCrosshair.getTextureRect().height) / 2));
|
||||
mCrosshair.setPosition(Vector2f(sf::Mouse::getPosition(mWindow) -
|
||||
Vector2i(mCrosshair.getTextureRect().width, mCrosshair.getTextureRect().height) / 2));
|
||||
break;
|
||||
case sf::Event::MouseWheelMoved:
|
||||
mPlayer->toggleWeapon();
|
||||
|
|
|
@ -41,7 +41,7 @@ private:
|
|||
void initPlayer();
|
||||
|
||||
private:
|
||||
static const int FPS_GOAL;
|
||||
static const int FPS_GOAL = 60;
|
||||
|
||||
tgui::Window& mWindow;
|
||||
sf::Clock mClock;
|
||||
|
@ -60,8 +60,8 @@ private:
|
|||
Generator mGenerator;
|
||||
std::shared_ptr<Player> mPlayer;
|
||||
|
||||
bool mQuit;
|
||||
bool mPaused;
|
||||
bool mQuit = false;
|
||||
bool mPaused = false;
|
||||
};
|
||||
|
||||
#endif /* DG_GAME_H_ */
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include "util/Interval.h"
|
||||
#include "sprites/Tile.h"
|
||||
|
||||
const float Pathfinder::WALL_DISTANCE_MULTIPLIER = 1.5f;
|
||||
|
||||
/**
|
||||
* Runs the A* path finding algorithm with areas as nodes and portals as edges.
|
||||
*
|
||||
|
@ -242,4 +240,4 @@ Pathfinder::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
|||
target.draw(rect);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* RELEASE */
|
||||
|
|
|
@ -36,8 +36,11 @@ private:
|
|||
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
|
||||
private:
|
||||
static const float WALL_DISTANCE_MULTIPLIER;
|
||||
std::vector<Area> mAreas; //< This has to be a vector as objects are compared by address.
|
||||
/// character radius multiplied with this gives movement distance
|
||||
// from the nearest wall.
|
||||
static constexpr float WALL_DISTANCE_MULTIPLIER = 1.5f;
|
||||
//< This has to be a vector as objects are compared by address.
|
||||
std::vector<Area> mAreas;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,9 +21,6 @@
|
|||
#include "../sprites/Enemy.h"
|
||||
#include "../util/Log.h"
|
||||
|
||||
const int Generator::GENERATE_AREA_SIZE = 4;
|
||||
const float Generator::GENERATE_AREA_RANGE = 4.0f;
|
||||
|
||||
/**
|
||||
* Generates new random seed.
|
||||
*/
|
||||
|
@ -125,10 +122,9 @@ Generator::createMinimalSpanningTree(const Vector2i& start,
|
|||
* Using basically Dijkstra on infinite graph/A* without destination node.
|
||||
*
|
||||
* @param start Tile to start path generation from (must be floor).
|
||||
* @param limit Maximum weight of each path.
|
||||
*/
|
||||
void
|
||||
Generator::connectRooms(const Vector2i& start, float limit) {
|
||||
Generator::connectRooms(const Vector2i& start) {
|
||||
std::set<Vector2i> open;
|
||||
std::set<Vector2i> closed;
|
||||
std::map<Vector2i, Vector2i> previous;
|
||||
|
@ -163,7 +159,7 @@ Generator::connectRooms(const Vector2i& start, float limit) {
|
|||
destinations.insert(current);
|
||||
break;
|
||||
}
|
||||
else if (distance.at(current) < limit) {
|
||||
else if (distance.at(current) < ROOM_CONNECTION_VALUE) {
|
||||
process(Vector2i(current.x + 1, current.y), current);
|
||||
process(Vector2i(current.x, current.y + 1), current);
|
||||
process(Vector2i(current.x - 1, current.y), current);
|
||||
|
@ -173,7 +169,7 @@ Generator::connectRooms(const Vector2i& start, float limit) {
|
|||
|
||||
// take min length paths and set tiles
|
||||
float totalValue = 0.0f;
|
||||
while (totalValue < limit && !destinations.empty()) {
|
||||
while (totalValue < ROOM_CONNECTION_VALUE && !destinations.empty()) {
|
||||
std::vector<Vector2i> path;
|
||||
float pathValue = 0;
|
||||
Vector2i current = *destinations.begin();
|
||||
|
@ -220,7 +216,7 @@ Generator::generateTiles(const sf::IntRect& area) {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<Vector2i> selected = createMinimalSpanningTree(start, 12.0f);
|
||||
std::vector<Vector2i> selected = createMinimalSpanningTree(start, ROOM_SIZE_VALUE);
|
||||
|
||||
// For rooms, take minimum bounding box of spanning tree.
|
||||
|
||||
|
@ -244,7 +240,7 @@ Generator::generateTiles(const sf::IntRect& area) {
|
|||
if (mTiles[x].count(y) == 0)
|
||||
mTiles[x][y] = Tile::Type::FLOOR;
|
||||
|
||||
connectRooms(start, 5.0f);
|
||||
connectRooms(start);
|
||||
|
||||
for (int x = area.left; x < area.left + area.width; x++)
|
||||
for (int y = area.top; y < area.top + area.height; y++)
|
||||
|
@ -354,12 +350,12 @@ Generator::findClosestFloor(const Vector2i& start) const {
|
|||
return Vector2i();
|
||||
}
|
||||
|
||||
#ifndef RELEASE
|
||||
/**
|
||||
* Debug only: Draws paths generated by connectRooms.
|
||||
*
|
||||
* mPaths is only required for this function.
|
||||
*/
|
||||
#ifndef RELEASE
|
||||
void
|
||||
Generator::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
||||
for (auto& p : mPaths) {
|
||||
|
@ -371,4 +367,4 @@ Generator::draw(sf::RenderTarget& target, sf::RenderStates states) const {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif /* NDEBUG */
|
||||
#endif /* RELEASE */
|
||||
|
|
|
@ -38,12 +38,14 @@ private:
|
|||
Vector2i findClosestFloor(const Vector2i& start) const;
|
||||
std::vector<Vector2i> createMinimalSpanningTree(
|
||||
const Vector2i& start, const float limit);
|
||||
void connectRooms(const Vector2i& start, float limit);
|
||||
void connectRooms(const Vector2i& start);
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
|
||||
private:
|
||||
static const int GENERATE_AREA_SIZE;
|
||||
static const float GENERATE_AREA_RANGE;
|
||||
static constexpr int GENERATE_AREA_SIZE = 4;
|
||||
static constexpr float GENERATE_AREA_RANGE = 4.0f;
|
||||
static constexpr float ROOM_SIZE_VALUE = 12.0f;
|
||||
static constexpr float ROOM_CONNECTION_VALUE = 5.0f;
|
||||
|
||||
World& mWorld;
|
||||
Pathfinder& mPathfinder;
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
Player::Player(World& world, Pathfinder& pathfinder,
|
||||
const Vector2f& position, const EquippedItems& items) :
|
||||
Character(position, CATEGORY_ACTOR, MASK_ALL, Yaml("player.yaml"), world,
|
||||
pathfinder, items),
|
||||
mDirection(0) {
|
||||
pathfinder, items) {
|
||||
}
|
||||
|
||||
Vector2f
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
* Movement directions that can be set via Player::setDirection().
|
||||
*/
|
||||
enum Direction : unsigned char {
|
||||
NONE = 0,
|
||||
RIGHT = 1 << 0,
|
||||
LEFT = 1 << 1,
|
||||
UP = 1 << 2,
|
||||
|
@ -58,7 +59,7 @@ private:
|
|||
|
||||
private:
|
||||
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
|
||||
unsigned char mDirection; //< Current movement direction for direct control.
|
||||
unsigned char mDirection = NONE; //< Current movement direction for direct control.
|
||||
};
|
||||
|
||||
#endif /* DG_PLAYER_H_ */
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
#include "../../World.h"
|
||||
#include "../../Pathfinder.h"
|
||||
|
||||
const float Character::VISION_DISTANCE = 500.0f;
|
||||
const float Character::POINT_REACHED_DISTANCE = 1.0f;
|
||||
const float Character::ITEM_PICKUP_MAX_DISTANCE = 50.0f;
|
||||
|
||||
/**
|
||||
* Saves pointer to this instance in static var for think().
|
||||
*/
|
||||
|
|
|
@ -36,9 +36,9 @@ public:
|
|||
};
|
||||
|
||||
/// Maximum distance where an enemy will be detected.
|
||||
static const float VISION_DISTANCE;
|
||||
static constexpr float VISION_DISTANCE = 500.0f;
|
||||
/// Maximum distance from character where an item can be picked up.
|
||||
static const float ITEM_PICKUP_MAX_DISTANCE;
|
||||
static constexpr float ITEM_PICKUP_MAX_DISTANCE = 50.0f;
|
||||
|
||||
public:
|
||||
explicit Character(const Vector2f& position, Category category,
|
||||
|
@ -87,7 +87,7 @@ private:
|
|||
|
||||
/// Distance to a path point where it will be considered as reached (to
|
||||
/// avoid floating point equality check).
|
||||
static const float POINT_REACHED_DISTANCE;
|
||||
static constexpr float POINT_REACHED_DISTANCE = 1.0f;
|
||||
friend class World;
|
||||
World& mWorld;
|
||||
Pathfinder& mPathfinder;
|
||||
|
|
|
@ -26,7 +26,7 @@ protected:
|
|||
GadgetType getType() const override;
|
||||
|
||||
private:
|
||||
static const int WAVES_PER_USE = 3;
|
||||
static constexpr int WAVES_PER_USE = 3;
|
||||
int mCurrentWave = WAVES_PER_USE + 1;
|
||||
|
||||
Character* mCharacter;
|
||||
|
|
Reference in a new issue