#pragma once #include <vector> #include "Ray.h" #include "CollisionDetection.h" #include "QuadTree.h" #include "Layer.h" namespace NCL { class Camera; using Maths::Ray; namespace CSC8503 { class GameObject; class Constraint; typedef std::function<void(GameObject*)> GameObjectFunc; typedef std::vector<GameObject*>::const_iterator GameObjectIterator; class GameWorld { public: GameWorld(); ~GameWorld(); void Clear(); void ClearAndErase(); void AddGameObject(GameObject* o); void RemoveGameObject(GameObject* o, bool andDelete = false); void AddConstraint(Constraint* c); void RemoveConstraint(Constraint* c, bool andDelete = false); Camera* GetMainCamera() const { return mainCamera; } void ShuffleConstraints(bool state) { shuffleConstraints = state; } void ShuffleObjects(bool state) { shuffleObjects = state; } bool Raycast(Ray& r, RayCollision& closestCollision, bool closestObject = false) const; virtual void UpdateWorld(float dt); void OperateOnContents(GameObjectFunc f); void GetObjectIterators( GameObjectIterator& first, GameObjectIterator& last) const; void GetConstraintIterators( std::vector<Constraint*>::const_iterator& first, std::vector<Constraint*>::const_iterator& last) const; void DrawBoundingVolumes() const; unsigned UpdateWorldLayers(unsigned layerIndex, const std::vector<Layer>& newConfig); std::vector<std::vector<Layer>>& GetWorldLayers() { return worldLayers; } const std::vector<std::vector<Layer>>& GetConstWorldLayers() const { return worldLayers; } const std::vector<Layer>& GetConstLayer(unsigned layerIndex) const { return worldLayers[layerIndex]; } protected: std::vector<GameObject*> gameObjects; std::vector<Constraint*> constraints; Camera* mainCamera; bool shuffleConstraints; bool shuffleObjects; int worldIDCounter; std::vector<std::vector<Layer>> worldLayers; }; } }