Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Caitlin Wilks committed Jan 13, 2015
2 parents e226f85 + 65f6fd0 commit b6842d6
Show file tree
Hide file tree
Showing 22 changed files with 386 additions and 127 deletions.
2 changes: 2 additions & 0 deletions coment/coment.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<ClInclude Include="include\coment\util\combined_hash.h" />
<ClInclude Include="include\coment\util\dynamic_bitset.h" />
<ClInclude Include="include\coment\util\EntityMap.h" />
<ClInclude Include="include\coment\util\PriorityComparator.h" />
<ClInclude Include="include\coment\util\TypeEnumerator.h" />
<ClInclude Include="include\coment\util\TypeMap.h" />
<ClInclude Include="include\coment\World.h" />
Expand All @@ -110,6 +111,7 @@
<None Include="include\coment\Entity.inl" />
<None Include="include\coment\managers\ComponentManager.inl" />
<None Include="include\coment\managers\EntityManager.inl" />
<None Include="include\coment\managers\Manager.inl" />
<None Include="include\coment\systems\EntitySystem.inl" />
<None Include="include\coment\util\EntityMap.inl" />
<None Include="include\coment\util\TypeEnumerator.inl" />
Expand Down
6 changes: 6 additions & 0 deletions coment/coment.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<ClInclude Include="include\coment\util\TypeMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\coment\util\PriorityComparator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\managers\EntityManager.cpp">
Expand Down Expand Up @@ -130,5 +133,8 @@
<None Include="include\coment\World.inl">
<Filter>Header Files</Filter>
</None>
<None Include="include\coment\managers\Manager.inl">
<Filter>Header Files</Filter>
</None>
</ItemGroup>
</Project>
7 changes: 5 additions & 2 deletions coment/include/coment/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "coment/systems/System.h"
#include "coment/util/TypeMap.h"
#include "coment/util/EntityMap.h"
#include "coment/util/PriorityComparator.h"

namespace coment
{
Expand Down Expand Up @@ -39,7 +40,7 @@ namespace coment

/** Remove a manager from the world */
template <typename T>
void removeManager() const;
void removeManager();

/** Add a system to the world, initialised with Args... */
template <typename T, typename... Args>
Expand All @@ -51,7 +52,7 @@ namespace coment

/** Remove a system from the world */
template <typename T>
void removeSystem() const;
void removeSystem();

/* Proxy API for EntityManager */

Expand Down Expand Up @@ -84,9 +85,11 @@ namespace coment

/** A map of managers */
TypeMap<Manager> mManagerMap;
std::multiset<Manager*, PriorityComparator<Manager>> mManagerSet;

/** A map of systems */
TypeMap<System> mSystemMap;
std::multiset<System*, PriorityComparator<System>> mSystemSet;

};
}
Expand Down
34 changes: 30 additions & 4 deletions coment/include/coment/World.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "coment/Entity.h"

#include <type_traits>

namespace coment
{
/* Manager/System management */
Expand All @@ -13,9 +15,12 @@ namespace coment
// Create manager
T* ptr = mManagerMap.add<T>(args...);

// Add manager to set
mManagerSet.insert(ptr);

// Give vector pointer to systems/managers for callbacks
ptr->mManagers = mManagerMap.getVector();
ptr->mSystems = mSystemMap.getVector();
ptr->mManagers = &mManagerSet;
ptr->mSystems = &mSystemSet;

// Update manager pointer if it's cached
updateManagerPointer(ptr);
Expand All @@ -33,9 +38,20 @@ namespace coment

/** Remove a manager from the world */
template <typename T>
void World::removeManager() const
void World::removeManager()
{
const char* err = "Can not remove default managers";
static_assert(T != EntityManager, err);
static_assert(T != SystemManager, err);

// Get manager ptr
T* ptr = getManager<T>();

// Remove manager from map
mManagerMap.remove<T>();

// Remove manager from set
mManagerSet.erase(ptr);
}

/** Add a system to the world, initialised with Args... */
Expand All @@ -45,6 +61,9 @@ namespace coment
// Create system
T* ptr = mSystemMap.add<T>(args...);

// Add system to set
mSystemSet.insert(ptr);

// Give it a pointer to this world
ptr->mWorld = this;

Expand All @@ -61,9 +80,16 @@ namespace coment

/** Remove a system from the world */
template <typename T>
void World::removeSystem() const
void World::removeSystem()
{
// Get system ptr
T* ptr = getSystem<T>();

// Remove system from map
mSystemMap.remove<T>();

// Remove system from map
mSystemSet.erase(ptr);
}

/* Specilisations for default managers */
Expand Down
22 changes: 19 additions & 3 deletions coment/include/coment/managers/Manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

#include <vector>
#include <set>

#include "coment/util/PriorityComparator.h"

namespace coment
{
Expand All @@ -11,6 +14,14 @@ namespace coment
{
public:

/** Allows the derived class to specify a priority for updates to the manager.
A higher priority means that this manager will be processed first */
Manager(int priority = 0)
: mPriority(priority) {}

/** Get the priority of this manager */
int getPriority() const;

/* Manager callbacks. Callbacks named on* do not have any guarantees
as to what order they are run in. Callbacks named pre* or post* run
before or after their associated event */
Expand All @@ -31,11 +42,16 @@ namespace coment

friend class World;

/** The priority of updates to this manager */
int mPriority;

/** All managers known by this manager's world */
const std::vector<Manager*>* mManagers;
const std::multiset<Manager*, PriorityComparator<Manager>>* mManagers;

/** All systems known by this manager's world */
const std::vector<System*>* mSystems;
const std::multiset<System*, PriorityComparator<System>>* mSystems;

};
}
}

#include "coment/managers/Manager.inl"
27 changes: 27 additions & 0 deletions coment/include/coment/managers/Manager.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "coment/managers/Manager.h"
#include "coment/systems/System.h"

namespace coment
{
/** Get the priority of this manager */
inline int Manager::getPriority() const
{
return mPriority;
}

struct SystemPtrComparator
{
bool operator()(const System* lhs, const System* rhs)
{
return lhs->getPriority() > rhs->getPriority();
}
};

struct ManagerPtrComparator
{
bool operator()(const Manager* lhs, const Manager* rhs)
{
return lhs->getPriority() > rhs->getPriority();
}
};
}
23 changes: 23 additions & 0 deletions coment/include/coment/systems/EntitySystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "coment/systems/System.h"

namespace coment
{
template <typename... ComponentTypes>
class EntitySystem
: public System
{
public:

/** Intitialises this system with the given component types */
EntitySystem();

private:

/** The entity map for this system */

};
}

#include "coment/systems/EntitySystem.inl"
11 changes: 11 additions & 0 deletions coment/include/coment/systems/EntitySystem.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "coment/systems/EntitySystem.h"

namespace coment
{
/** Intitialises this system with the given component types */
template <typename... ComponentTypes>
EntitySystem::EntitySystem()
{

}
}
30 changes: 28 additions & 2 deletions coment/include/coment/systems/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ namespace coment
{
public:

/** Create a system with a given priority. Higher priority causes
the system to execute earlier */
System(int priority = 0)
: mPriority(priority) {}

/** Get the world this system is managed by */
World* getWorld();

/** Get the priority of this system */
int getPriority() const;

/* Manager callbacks. Callbacks named on* do not have any guarantees
as to what order they are run in. Callbacks named pre* or post* run
before or after their associated event */
Expand All @@ -29,12 +40,27 @@ namespace coment
/** Called after the world is updated */
virtual void postUpdate() {}

protected:
private:

friend World;

/** A pointer to the world this system belongs to */
/** A pointer to the world this system is managed by */
World* mWorld = nullptr;

/** The execution priority of this system */
int mPriority;

};

/** Get the world this system is managed by */
inline World* System::getWorld()
{
return mWorld;
}

/** Get the priority of this system */
inline int System::getPriority() const
{
return mPriority;
}
}
20 changes: 19 additions & 1 deletion coment/include/coment/util/EntityMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@ namespace coment
/** Create a new entity map from a given bitset and container */
EntityMap(dynamic_bitset<> componentTypes, std::shared_ptr<std::vector<Entity>> entities);

//private:
/** Get the entities in this map */
std::vector<Entity>* getEntities();

/** Get the entities in this map */
const std::vector<Entity>* getEntities() const;

/** begin() proxy for range based for */
std::vector<Entity>::iterator begin();

/** begin() proxy for range based for */
std::vector<Entity>::iterator begin() const;

/** end() proxy for range based for */
std::vector<Entity>::iterator end();

/** end() proxy for range based for */
std::vector<Entity>::iterator end() const;

private:

/** The component types that these entities include */
dynamic_bitset<> mComponentTypes;
Expand Down
42 changes: 42 additions & 0 deletions coment/include/coment/util/EntityMap.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,46 @@ namespace coment
{

}

/** Get the entities in this map */
template <typename... ComponentTypes>
std::vector<Entity>* EntityMap<ComponentTypes...>::getEntities()
{
return mEntities.get();
}

/** Get the entities in this map */
template <typename... ComponentTypes>
const std::vector<Entity>* EntityMap<ComponentTypes...>::getEntities() const
{
return mEntities.get();
}

/** begin() proxy for range based for */
template <typename... ComponentTypes>
std::vector<Entity>::iterator EntityMap<ComponentTypes...>::begin()
{
return mEntities->begin();
}

/** begin() proxy for range based for */
template <typename... ComponentTypes>
std::vector<Entity>::iterator EntityMap<ComponentTypes...>::begin() const
{
return mEntities->begin();
}

/** end() proxy for range based for */
template <typename... ComponentTypes>
std::vector<Entity>::iterator EntityMap<ComponentTypes...>::end()
{
return mEntities->end();
}

/** end() proxy for range based for */
template <typename... ComponentTypes>
std::vector<Entity>::iterator EntityMap<ComponentTypes...>::end() const
{
return mEntities->end();
}
}
Loading

0 comments on commit b6842d6

Please sign in to comment.