Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <vector>
- #include <memory>
- #include "basicobject.h"
- class objcontainer
- {
- using objpair = std::pair<std::unique_ptr<basicobject>, bool >;
- std::vector < objpair> m_objects;
- public:
- objcontainer();
- ~objcontainer();
- void Draw(drawinfo* info);
- void Run(float deltatime, tickinfo* info);
- void Remove(class basicobject* obj);
- void ShowInfo(std::string info);
- void setActive();
- void Possess(class playable* victim);
- class playable* m_possessed = nullptr;
- class basicobject* MakeObject(class basicobject* obj, bool ShouldDraw = true);
- /*
- template<class obj, typename... us> obj* MakeObject(us... args)
- {
- m_objects.push_back(new obj(args...));
- return dynamic_cast<obj*>(m_objects.back());
- }*/
- };
- namespace usefullstuff
- {
- extern objcontainer* container;
- extern objmanager* manager;
- class basicobject* MakeObject(class basicobject* obj, bool ShouldDraw = true);
- void Remove(class basicobject* obj);
- }
- #include "objcontainer.h"
- #include "entity.h"
- #include "playable.h"
- #include "objmanager.h"
- #include "chunk.h"
- #include <iostream>
- #include "basicobject.h"
- namespace usefullstuff
- {
- objcontainer* container =nullptr;
- objmanager* manager = nullptr;
- basicobject* MakeObject(basicobject* obj, bool ShouldDraw)
- {
- return container->MakeObject(obj, ShouldDraw);
- }
- void Remove(basicobject* obj)
- {
- container->Remove(obj);
- }
- }
- objcontainer::objcontainer()
- {
- }
- objcontainer::~objcontainer()
- {
- }
- void objcontainer::Draw(drawinfo* info)
- {
- for (int i = 0; i < m_objects.size(); i++)
- m_objects[i].first->Draw(info);
- }
- void objcontainer::Run(float deltatime, tickinfo* info)
- {
- for (int i = 0; i < m_objects.size(); i++)
- m_objects[i].first->Tick(deltatime, info);
- }
- /*
- Deletes pointer, and deletes it from its container if it has any
- */
- void objcontainer::Remove(basicobject* obj)
- {
- /*
- int debug = 0;
- for (int i = 0; i < m_objects.size(); i++)
- if (dynamic_cast<chunk*>(m_objects[i].first))
- debug++;
- std::cout << "DELETING: \n";*/
- /*
- for (int i = 0; i < m_objects.size(); i++)
- if (obj == m_objects[i].first.get())
- {
- m_objects.erase(m_objects.begin() + i);
- return;
- }*/
- std::cout << m_objects.size();
- auto object =
- find_if(m_objects.begin(), m_objects.end(), [&](objpair& ob) { return ob.first.get() == obj; });
- m_objects.erase(std::remove(m_objects.begin(), m_objects.end(), *object));
- std::cout << ' ' << m_objects.size() << std::endl;
- //delete obj;
- }
- void objcontainer::ShowInfo(std::string info)
- {
- std::cout << info << m_objects.size() << std::endl;
- }
- void objcontainer::setActive()
- {
- usefullstuff::container = this;
- }
- void objcontainer::Possess(playable* victim)
- {
- m_possessed = victim;
- }
- basicobject* objcontainer::MakeObject(basicobject* obj, bool ShouldDraw)
- {
- m_objects.push_back(objpair(std::unique_ptr<basicobject>(obj), ShouldDraw));
- return obj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement