Skip to content

Commit

Permalink
Add engine namespace (#28)
Browse files Browse the repository at this point in the history
Close #24. Basically, add every file under the `src/engine` path to the
namespace `Engine`.

Also add to fix a bunch of other files to fit with the new namespace
(basically just appended `Engine::...` to a bunch of stuff).

If it compiles, it should be good to go and good enough for a review.
Try to check if I missed any file, but should be a-ok.

Choose to go with CamlCase for namespace format, because it looks
prettier imo. Can be changed back to `engine` with a simple Ctrl+F
anyway.
  • Loading branch information
gbrivady authored May 18, 2023
1 parent e4a0e39 commit 32ba057
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 52 deletions.
6 changes: 6 additions & 0 deletions include/engine/box/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <cmath>
#include <vector>

namespace Engine
{

/**
* @brief Container for all the information about an intersection of two boxes.
*
Expand Down Expand Up @@ -94,4 +97,7 @@ class Box

#include "../src/engine/box/box.tpp" //TODO : find a better way to include this

} //namespace Engine


#endif
5 changes: 5 additions & 0 deletions include/engine/box/rectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include "engine/box/box.h"

namespace Engine
{

/**
* @brief A rectangle, defined by 4 vertices, starting from bottom-left, and then
* progressing in trigonometric order.
Expand Down Expand Up @@ -56,4 +59,6 @@ class Rectangle: public Box<T>

#include "../src/engine/box/rectangle.tpp" //Todo : same as box.tpp todo

} //namespace Engine

#endif
4 changes: 4 additions & 0 deletions include/engine/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "engine/physics/phxbox.h"
#include "engine/box/box.h"

namespace Engine
{

class InputHandler;

/**
Expand Down Expand Up @@ -92,5 +95,6 @@ class Entity

};

} // namespace Engine

#endif
4 changes: 4 additions & 0 deletions include/engine/input/input_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "engine/entity.h"

namespace Engine
{

struct UniversalInput
{
Expand Down Expand Up @@ -47,4 +49,6 @@ class InputHandler

};

} //namespace Engine

#endif
5 changes: 5 additions & 0 deletions include/engine/physics/kinematics.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <vector>

namespace Engine
{

#define PHX_CST_G -1

/**
Expand All @@ -21,4 +24,6 @@
*/
void gravity(std::pair<double, double>* vel, double* mass);

} //namespace Engine

#endif
4 changes: 4 additions & 0 deletions include/engine/physics/phxbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <utility>
#include "engine/box/box.h"

namespace Engine
{

class Entity;

/**
Expand Down Expand Up @@ -65,5 +68,6 @@ class PhxBox{
void linkVel(std::pair<double, double>* owner_vel);
};

} //namespace Engine

#endif
5 changes: 5 additions & 0 deletions include/engine/physics/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include "engine/physics/kinematics.h"

namespace Engine
{

/**
* @brief Parameters of a point object, used to compute forces
*
Expand Down Expand Up @@ -61,4 +64,6 @@ class Point
void linkPos(std::pair<double, double>* pos);
};

} //namespace Engine

#endif
5 changes: 5 additions & 0 deletions include/engine/universe_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

#include "settings/input_reader.h"

namespace Engine
{

typedef std::list<Entity*> EntityStack;

typedef std::list<Point*> PointStack;
Expand Down Expand Up @@ -77,4 +80,6 @@ class UniverseMaster

};

} //namespace Engine

#endif
4 changes: 2 additions & 2 deletions include/game/entity/dev/blue_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include "engine/entity.h"
#include "engine/box/rectangle.h"
#include "engine/physics/phxbox.h"
class BlueTerrain: public Entity{
class BlueTerrain: public Engine::Entity{
public:
BlueTerrain();
void collPhxNotify(Entity* ett) override {ett->getPoint()->is_falling=false;}
void collPhxNotify(Engine::Entity* ett) override {ett->getPoint()->is_falling=false;}
};

#endif
7 changes: 4 additions & 3 deletions include/game/entity/dev/controllable.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef GAME_ENTITY_DEV_CONTROLLABLE_H
#define GAME_ENTITY_DEV_CONTROLLABLE_H

#include "engine/input/input_handler.h"
#include "engine/input/input_handler.h"

class DevControllable : public InputHandler
class DevControllable : public Engine::InputHandler
{
private:
int amplitude;

public:
void setAmplitude(int amp) {this->amplitude = amp;};
void setAmplitude(int amp) { this->amplitude = amp; };
void doInput(int actionId) override;
};

Expand Down
4 changes: 2 additions & 2 deletions include/game/entity/dev/red_square.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "engine/physics/phxbox.h"
#include "game/entity/dev/controllable.h"

class RedSquare: public Entity
class RedSquare: public Engine::Entity
{
private:
/* data */
public:
RedSquare(int size);
void collPhxNotify(Entity* ett) {}
void collPhxNotify(Engine::Entity* ett) {}
};


Expand Down
4 changes: 2 additions & 2 deletions include/settings/input_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
* @param path input file
* @return std::list<Keybind>
*/
std::list<Keybind> make_keybinds(std::string path);
std::list<Engine::Keybind> make_keybinds(std::string path);

/**
* @brief Read the players part of the inputs
*
* @param keybinds
* @param file
*/
void read_player_input(std::list<Keybind>& keybinds, std::ifstream& file);
void read_player_input(std::list<Engine::Keybind>& keybinds, std::ifstream& file);

/**
* @brief Transforms a string to an sfml key
Expand Down
8 changes: 5 additions & 3 deletions src/engine/box/rectangle.tpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "engine/box/rectangle.h"

using namespace Engine;

template<typename T>
Rectangle<T>::Rectangle(double x, double y){
Engine::Rectangle<T>::Rectangle(double x, double y){
this->relVertices.push_back(std::pair<double, double>(0, 0));
this->relVertices.push_back(std::pair<double, double>(x, 0));
this->relVertices.push_back(std::pair<double, double>(x, y));
Expand All @@ -10,7 +12,7 @@ Rectangle<T>::Rectangle(double x, double y){

// Bottom-left point first; then counter clockwise
template<typename T>
Rectangle<T>::Rectangle(double x1, double x2, double y1, double y2){
Engine::Rectangle<T>::Rectangle(double x1, double x2, double y1, double y2){
if (x1<x2) //x1 is minx
{
if (y1<y2) //y1 is miny
Expand Down Expand Up @@ -43,7 +45,7 @@ Rectangle<T>::Rectangle(double x1, double x2, double y1, double y2){
}

template<typename T>
Intersection<T> Rectangle<T>::checkIntersection(Rectangle<T>* r){
Engine::Intersection<T> Rectangle<T>::checkIntersection(Rectangle<T>* r){
std::pair<double, double>* this_pos = this->getPos();
std::pair<double, double>* that_pos = r->getPos();

Expand Down
24 changes: 13 additions & 11 deletions src/engine/entity.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
#include "engine/entity.h"

Entity::Entity(){
using namespace Engine;

Engine::Entity::Entity(){
this->point = NULL;
this->sprite = NULL;
}

Entity::Entity(std::string name): Entity() {
Engine::Entity::Entity(std::string name): Entity() {
this->name = name;
}

void Entity::addPoint(){
void Engine::Entity::addPoint(){
this->point = new Point();
this->point->linkPos(&(this->pos));
}

Point* Entity::getPoint(){
Point* Engine::Entity::getPoint(){
return this->point;
}

void Entity::addSprite(){
void Engine::Entity::addSprite(){
sf::CircleShape* circle = new sf::CircleShape(10);
circle->setPosition(1, 1);
this->sprite = circle;
}
void Entity::addSprite(sf::Drawable* sprite){
void Engine::Entity::addSprite(sf::Drawable* sprite){
this->sprite = sprite;
}

sf::Drawable* Entity::getSprite(){
sf::Drawable* Engine::Entity::getSprite(){
return this->sprite;
}

//Dangerous adder : only private
void Entity::addPhxBox(PhxBox* pb){
void Engine::Entity::addPhxBox(PhxBox* pb){
this->phxbox = pb;
pb->linkPos(&(this->pos));
pb->linkVel(&(this->vel));
pb->linkOwner(this);
}

void Entity::addPhxBox(Box<PhxBox>* pb, PhxBox::CollisionBehaviour ct){
void Engine::Entity::addPhxBox(Box<PhxBox>* pb, PhxBox::CollisionBehaviour ct){
PhxBox* phxbox = new PhxBox();
this->addPhxBox(phxbox);
phxbox->linkBox(pb);
phxbox->setCollisionType(ct);
}

PhxBox* Entity::getPhxBox(){
PhxBox* Engine::Entity::getPhxBox(){
return this->phxbox;
}

void Entity::move(double dx, double dy){
void Engine::Entity::move(double dx, double dy){
this->pos.first += dx;
this->pos.second += dy;
}
4 changes: 3 additions & 1 deletion src/engine/physics/kinematics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "engine/physics/kinematics.h"

void gravity(std::pair<double, double>* vel, double* mass){
using namespace Engine;

void Engine::gravity(std::pair<double, double>* vel, double* mass){
vel->second += *mass * PHX_CST_G;
}
16 changes: 9 additions & 7 deletions src/engine/physics/phxbox.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#include "engine/physics/phxbox.h"

void PhxBox::setCollisionType(CollisionBehaviour ct){
using namespace Engine;

void Engine::PhxBox::setCollisionType(CollisionBehaviour ct){
this->type = ct;
}

void PhxBox::linkOwner(Entity* owner){
void Engine::PhxBox::linkOwner(Entity* owner){
this->owner = owner;
}

void PhxBox::linkBox(Box<PhxBox>* box){
void Engine::PhxBox::linkBox(Box<PhxBox>* box){
this->box = box;
box->linkOwner(this);
box->linkPos(this->owner_pos);
}

void PhxBox::solveCollision(Intersection<PhxBox>& coll_pb){
void Engine::PhxBox::solveCollision(Intersection<PhxBox>& coll_pb){
PhxBox* that = coll_pb.intersected;
//internal logic
switch (type)
Expand Down Expand Up @@ -45,14 +47,14 @@ void PhxBox::solveCollision(Intersection<PhxBox>& coll_pb){
coll_pb.intersectionVector.second *= -1;
}

void PhxBox::linkPos(std::pair<double, double>* owner_pos){
void Engine::PhxBox::linkPos(std::pair<double, double>* owner_pos){
this->owner_pos = owner_pos;
}

void PhxBox::linkVel(std::pair<double, double>* owner_vel){
void Engine::PhxBox::linkVel(std::pair<double, double>* owner_vel){
this->owner_vel = owner_vel;
}

Entity* PhxBox::getOwner(){
Entity* Engine::PhxBox::getOwner(){
return this->owner;
}
6 changes: 4 additions & 2 deletions src/engine/physics/point.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "engine/physics/point.h"

void Point::linkPos(std::pair<double, double>* pos){
using namespace Engine;

void Engine::Point::linkPos(std::pair<double, double>* pos){
this->pos = pos;
}

void Point::update(){
void Engine::Point::update(){
if(is_falling){
gravity(pos, &(phxParam.mass));
}
Expand Down
Loading

0 comments on commit 32ba057

Please sign in to comment.