Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Merged
merged 62 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9cec635
Create basic build system using cmake.
Tastyep Mar 3, 2021
1c52b1e
Define a .clang-tidy file.
Tastyep Mar 3, 2021
8931ab5
Add the default generated .clang-format file.
Tastyep Mar 3, 2021
d143d52
Add support for compiling with ccache.
Tastyep Mar 3, 2021
d400fd8
Set compiler flags.
Tastyep Mar 3, 2021
c89d402
Prevent in source builds.
Tastyep Mar 3, 2021
f9dffb0
Add sanitizer support
Tastyep Mar 3, 2021
d9de119
Add doxygen support
Tastyep Mar 3, 2021
bd55232
Add support for static analyzers
Tastyep Mar 3, 2021
fcae42c
Add the formatting target
Tastyep Mar 3, 2021
7eea6bb
Set up dependency management using Conan
Tastyep Mar 4, 2021
0cc35d7
Set a default project configuration (RelWithDebInfo)
Tastyep Mar 4, 2021
f291ace
Fix finding of SFML libraries.
Tastyep Mar 4, 2021
f86667c
Format cmake files using cmake-format
Tastyep Mar 4, 2021
9e0ccf0
Use conan to fetch SFML and Imgui-SFML dependencies
Tastyep Mar 4, 2021
3c56205
Encapsulate the window object.
Tastyep Mar 6, 2021
88063ed
Add a SFML event convertor
Tastyep Mar 6, 2021
24c86b2
Implement a FPS based game loop
Tastyep Mar 6, 2021
39eeeee
Add action definitions
Tastyep Mar 7, 2021
3711206
Convert interface events to actions
Tastyep Mar 7, 2021
018094a
Move Timepoint and Clock concept away from the gamestate
Tastyep Mar 9, 2021
f1926eb
Implement the tile parser
Tastyep Mar 9, 2021
4e01797
Import entt (build system)
Tastyep Mar 9, 2021
88a7aba
Define the entity factory and their components.
Tastyep Mar 9, 2021
493528b
Define the View concept
Tastyep Mar 9, 2021
45d3170
Implement the game view
Tastyep Mar 9, 2021
f666c67
Implement the FPS view
Tastyep Mar 9, 2021
ca31b59
Implement a basic map parser
Tastyep Mar 9, 2021
faadec2
Define a Timer object
Tastyep Mar 10, 2021
552abaf
Add the tmxlite dependency to the build system
Tastyep Mar 11, 2021
37a5828
Improve the interface of the tile loader
Tastyep Mar 11, 2021
daae2a1
Store views with shared instead of unique ptrs
Tastyep Mar 11, 2021
97166e7
Implement the map object
Tastyep Mar 11, 2021
031d9ec
Refactor components into graphical and physical categories
Tastyep Mar 12, 2021
770ac6f
Provide calculus operator overloads for Vector2
Tastyep Mar 12, 2021
1a1f32f
Implement basic motion support
Tastyep Mar 12, 2021
e995437
Provide a ActionCode to Action factory function
Tastyep Mar 13, 2021
1b08163
Add support for key released events
Tastyep Mar 13, 2021
a707f7d
Implement the event controller
Tastyep Mar 13, 2021
7339997
Implement the controller mapper
Tastyep Mar 19, 2021
889b6dc
Provide names for actions and keys
Tastyep Mar 19, 2021
598abe8
Implement the control view
Tastyep Mar 19, 2021
f61a76d
Switch to fixed timestep and unlimited FPS
Tastyep Mar 27, 2021
f7f818b
Add collision shape definitions
Tastyep Mar 28, 2021
9882603
Add PlayRho build dependency
Tastyep Mar 28, 2021
e9d5f2c
Convert the tile ID to entity ID
Tastyep Mar 29, 2021
86ffc47
Use std::holds_alternative when handling a single type
Tastyep Apr 1, 2021
1895ec7
Implement the shape config manager
Tastyep Apr 1, 2021
fdf46d2
Parse bounding boxes from the map
Tastyep Apr 1, 2021
b43bfd1
Add pixel <-> meter convertion functions
Tastyep Apr 1, 2021
a045afd
Rewrite existing components to carry playrho body info
Tastyep Apr 1, 2021
bc30079
Update the gameview following components update
Tastyep Apr 1, 2021
5f98b65
Apply basic transformations on the simulated bodies
Tastyep Apr 1, 2021
7cc3909
Implement a BoudingBox view
Tastyep Apr 1, 2021
61268cf
Update object initializations
Tastyep Apr 1, 2021
dccbce9
Load walls as entities
Tastyep Apr 3, 2021
624b208
Use playrho to apply angular and linear forces
Tastyep Apr 6, 2021
fcf4bc7
Change storage of tiles from sf::Sprite to Tile
Tastyep Apr 6, 2021
bfa5e9f
Draw map tiles using vertex arrays
Tastyep Apr 6, 2021
3743c70
Update style (clang format & tidy files).
Tastyep Jun 2, 2021
8915fa9
Draw sprites in a tile layer
Tastyep Jun 2, 2021
2089304
Define a basic map with the required tile resources.
Tastyep Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Load walls as entities
  - Draw bounding boxes of all components
  • Loading branch information
Tastyep committed Apr 3, 2021
commit dccbce959d2a5fb47e0b32de9fdfc7a30bf09901
4 changes: 3 additions & 1 deletion include/interface/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define INTERFACE_MAP_HPP

#include "domain/Vector.hpp"
#include "domain/entity/Factory.hpp"
#include "domain/physic/ShapeConfManager.hpp"
#include "interface/Tile.hpp"
#include "interface/view/View.hpp"
Expand All @@ -20,7 +21,8 @@ class Map : public View::View {

void render(sf::RenderWindow &window) override;
bool load(const std::string & path,
std::shared_ptr<Domain::Physic::ShapeConfManager> shapeConfManager);
std::shared_ptr<Domain::Physic::ShapeConfManager> shapeConfManager,
std::shared_ptr<Domain::Entity::Factory> entityFactory);

private:
std::pair<Domain::Vector2f, float> parseEllipse(const tmx::Object &object);
Expand Down
59 changes: 48 additions & 11 deletions src/interface/Map.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "interface/Map.hpp"
#include "domain/Coordinate.hpp"
#include "domain/Vector.hpp"
#include "domain/entity/Factory.hpp"
#include "domain/entity/Identity.hpp"
#include "interface/Tile.hpp"

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <memory>

Expand All @@ -18,13 +20,16 @@ Map::Map(std::shared_ptr<TileManager> tileManager)

bool Map::load(
const std::string & path,
std::shared_ptr<Domain::Physic::ShapeConfManager> shapeConfManager) {
std::shared_ptr<Domain::Physic::ShapeConfManager> shapeConfManager,
std::shared_ptr<Domain::Entity::Factory> entityFactory) {
if (!_map.load(path)) {
return false;
}

const auto &tileSets = _map.getTilesets();
for (size_t count = 0; const auto &tileSet : tileSets) {
// TODO: Check that id doesn't become bigger than Count(EntityId)
std::vector<std::uint32_t> entityTileIds;
const auto & tileSets = _map.getTilesets();
for (size_t id = 0; const auto &tileSet : tileSets) {
const auto &tileSetPath = tileSet.getImagePath();
const auto &tileSize = tileSet.getTileSize();
const auto tileCount = tileSet.getTileCount();
Expand All @@ -46,26 +51,25 @@ bool Map::load(

if (objects.size() > 1) {
const auto polygons = this->parseMultiPolygon(objects);
shapeConfManager->load(static_cast<Domain::Entity::ID>(count),
polygons);
shapeConfManager->load(static_cast<Domain::Entity::ID>(id), polygons);
} else {
for (const auto &object : objects) {
switch (object.getShape()) {
case tmx::Object::Shape::Ellipse: {
const auto [center, radius] = this->parseEllipse(object);
shapeConfManager->load(static_cast<Domain::Entity::ID>(count),
center, radius);
shapeConfManager->load(static_cast<Domain::Entity::ID>(id), center,
radius);
break;
}
case tmx::Object::Shape::Polygon: {
const auto polygon = this->parsePolygon(object);
shapeConfManager->load(static_cast<Domain::Entity::ID>(count),
shapeConfManager->load(static_cast<Domain::Entity::ID>(id),
polygon);
break;
}
case tmx::Object::Shape::Rectangle: {
const auto polygon = this->parseRectangle(object);
shapeConfManager->load(static_cast<Domain::Entity::ID>(count),
shapeConfManager->load(static_cast<Domain::Entity::ID>(id),
polygon);
break;
}
Expand All @@ -75,7 +79,40 @@ bool Map::load(
}
}
}
++count;
// Only increment the entityID if collision objects are available
if (!objects.empty()) {
++id;
entityTileIds.push_back(tile.ID);
}
}
}

const auto &layers = _map.getLayers();
const auto &tileSize = _map.getTileSize();
const auto tileCount = _map.getTileCount();
for (const auto &layer : layers) {
const auto &tileLayer = layer->getLayerAs<tmx::TileLayer>();
const auto &tiles = tileLayer.getTiles();

for (unsigned int y = 0; y < tileCount.y; ++y) {
for (unsigned int x = 0; x < tileCount.x; ++x) {
const auto &tile = tiles[y * tileCount.x + x];
// Empty tile or no associated object
if (tile.ID == 0 ||
std::find(entityTileIds.begin(), entityTileIds.end(), tile.ID) ==
entityTileIds.end()) {
continue;
}

const auto entityId = static_cast<Domain::Entity::ID>(tile.ID - 1);
if (entityId >= Domain::Entity::ID::URDLWall &&
entityId <= Domain::Entity::ID::BallWall) {

entityFactory->wall(Domain::Coordinate::toMeter(Domain::Vector2u{
x * tileSize.x, y * tileSize.y}),
entityId);
}
}
}
}

Expand All @@ -93,7 +130,7 @@ void Map::render(sf::RenderWindow &window) {

for (unsigned int y = 0; y < tileCount.y; ++y) {
for (unsigned int x = 0; x < tileCount.x; ++x) {
const auto tile = tiles[y * tileCount.x + x];
const auto &tile = tiles[y * tileCount.x + x];
if (tile.ID == 0) { // Empty
continue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/interface/view/BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ void BoundingBox::drawCircle(sf::RenderWindow & window,
const auto radius = shape.GetRadius();

sf::CircleShape circle(radius);
circle.setPosition({pixelCoor.x, pixelCoor.y});
circle.setPosition({pixelCoor.x - radius, pixelCoor.y - radius});
circle.setOutlineThickness(1);
circle.setFillColor({0, 0, 0, 0});
circle.setOutlineColor({0xFF, 0xFF, 0xFF, 0xFF});
window.draw(circle);
}

Expand Down
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ int main() {
// Graphical resource loading
auto tileManager = std::make_shared<Interface::TileManager>();
auto shapeConfManager = std::make_shared<Domain::Physic::ShapeConfManager>();
Domain::Entity::Factory entFactory(registry, world, shapeConfManager);
auto map = std::make_shared<Interface::Map>(tileManager);
map->load("../asset/map.tmx", shapeConfManager);
entFactory.tank({1, 1});
auto entFactory = std::make_shared<Domain::Entity::Factory>(registry, world,
shapeConfManager);
auto map = std::make_shared<Interface::Map>(tileManager);
map->load("../asset/map.tmx", shapeConfManager, entFactory);
entFactory->tank({1, 1});

// Controller mapping
namespace Event = Interface::Event;
Expand Down