Skip to content

Commit

Permalink
Replaced usage of std::map with std::unordered_map in Entity, EntityO…
Browse files Browse the repository at this point in the history
…bject classes and the Utility source files.
  • Loading branch information
harrand committed Mar 21, 2017
1 parent d6df252 commit 39e7865
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion res/runtime/data/worlds/random.world
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object10.rot: [0.3, 18.9416, 0]
object10.scale: [0.05, 0.05, 0.05]
object11.mesh: sphere
object11.texture: lava
object11.normalmap: default_normalmap
object11.normalmap: lava_normalmap
object11.pos: [86.4294, 32.143, 49.7597]
object11.rot: [3.85, 22.4415, 0]
object11.scale: [44, 44, 44]
Expand Down
7 changes: 6 additions & 1 deletion res/runtime/resources.data
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ speed: 2.5



played: 117065





played: 117303
4 changes: 2 additions & 2 deletions src/entity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "entity.hpp"

Entity::Entity(float mass, Vector3F position, Vector3F velocity, std::map<std::string, Force> forces): mass(mass), position(position), velocity(velocity), forces(forces){}
Entity::Entity(float mass, Vector3F position, Vector3F velocity, std::unordered_map<std::string, Force> forces): mass(mass), position(position), velocity(velocity), forces(forces){}

void Entity::setPosition(Vector3F position)
{
Expand Down Expand Up @@ -49,7 +49,7 @@ Vector3F Entity::getAcceleration() const
return Vector3F(resultant.getSize() / this->mass);
}

std::map<std::string, Force> Entity::getForces() const
std::unordered_map<std::string, Force> Entity::getForces() const
{
return this->forces;
}
Expand Down
6 changes: 3 additions & 3 deletions src/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Entity
{
public:
Entity(float mass = 1.0f, Vector3F position = Vector3F(), Vector3F velocity = Vector3F(), std::map<std::string, Force> forces = std::map<std::string, Force>());
Entity(float mass = 1.0f, Vector3F position = Vector3F(), Vector3F velocity = Vector3F(), std::unordered_map<std::string, Force> forces = std::unordered_map<std::string, Force>());
virtual void setPosition(Vector3F position);
void setVelocity(Vector3F velocity);
void applyForce(std::string forceName, Force f);
Expand All @@ -15,12 +15,12 @@ class Entity
float getMass() const;
Vector3F getVelocity() const;
Vector3F getAcceleration() const;
std::map<std::string, Force> getForces() const;
std::unordered_map<std::string, Force> getForces() const;
virtual void updateMotion(unsigned int fps);
protected:
float mass;
Vector3F velocity;
std::map<std::string, Force> forces;
std::unordered_map<std::string, Force> forces;
private:
Vector3F position;
//Position is private because a child (Player) will not need an instance of position. getters and setters should mean that other children keep this instance of position.
Expand Down
2 changes: 1 addition & 1 deletion src/entityobject.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "entityobject.hpp"

EntityObject::EntityObject(std::string meshLink, std::string textureLink, std::string normalMapLink, float mass, Vector3F position, Vector3F rotation, Vector3F scale, Vector3F velocity, std::map<std::string, Force> forces): Entity(mass, position, velocity, forces), Object(meshLink, textureLink, normalMapLink, position, rotation, scale){}
EntityObject::EntityObject(std::string meshLink, std::string textureLink, std::string normalMapLink, float mass, Vector3F position, Vector3F rotation, Vector3F scale, Vector3F velocity, std::unordered_map<std::string, Force> forces): Entity(mass, position, velocity, forces), Object(meshLink, textureLink, normalMapLink, position, rotation, scale){}

void EntityObject::setPosition(Vector3F pos)
{
Expand Down
2 changes: 1 addition & 1 deletion src/entityobject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class EntityObject: public Entity, public Object
{
public:
EntityObject(std::string meshLink, std::string textureLink, std::string normalMapLink, float mass = 1.0f, Vector3F position = Vector3F(), Vector3F rotation = Vector3F(), Vector3F scale = Vector3F(1, 1, 1), Vector3F velocity = Vector3F(), std::map<std::string, Force> forces = std::map<std::string, Force>());
EntityObject(std::string meshLink, std::string textureLink, std::string normalMapLink, float mass = 1.0f, Vector3F position = Vector3F(), Vector3F rotation = Vector3F(), Vector3F scale = Vector3F(1, 1, 1), Vector3F velocity = Vector3F(), std::unordered_map<std::string, Force> forces = std::unordered_map<std::string, Force>());
void setPosition(Vector3F position);
Vector3F getPosition() const;
void updateMotion(unsigned int fps);
Expand Down
2 changes: 1 addition & 1 deletion src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::vector<std::string> StringUtility::splitString(std::string split, char deli
const char* str = split.c_str();
std::vector<std::string> ret;
unsigned int numcount = 0;
std::map<unsigned int, unsigned int> num_pos;
std::unordered_map<unsigned int, unsigned int> num_pos;
for(unsigned int i = 0; i < strsize; i++)
{
char cur = str[i];
Expand Down
2 changes: 1 addition & 1 deletion src/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include "vector.hpp"

namespace StringUtility
Expand Down

0 comments on commit 39e7865

Please sign in to comment.