Hello, I am trying to figure out the best way to manage my game objects.
I have tried using unique_pointer, but to no avail...
I want to have multiple lists to reference the same objects, for example:
I want to have a main list for all my objects, but a seperate list that only references objects that I want to have rendered, like this
std::vector<std::unique_ptr<Object>> ObjectList;
std::vector<std::unique_ptr<Object>> RendeObjects;
I've tried adding objects to the lists, but cannot remove them, and don't know how to remove objects from the second list that no longer exist in the first.
Here's a simple program I've made that is supposed to create two vectors, and add objects and delete them:
#include <iostream>
#include <vector>
#include <memory>
class Object
{
public:
float x;
float y;
float z;
bool dynamic;
Object(bool canCollide)
{
dynamic = canCollide;
if(dynamic == true)
{
std::cout << "Dynamic Object Created" << std::endl;
}
if(dynamic == false)
{
std::cout << "Object Created" << std::endl;
}
}
};
int main()
{
std::vector<std::unique_ptr<Object>> ObjectList;
std::vector<std::unique_ptr<Object>> CollidableObjects;
Object o(true);
std::unique_ptr<Object> obj(&o);
ObjectList.push_back(std::move(obj));
Object oo(false);
std::unique_ptr<Object> oobj(&oo);
ObjectList.push_back(std::move(oobj));
Object ooo(false);
std::unique_ptr<Object> ooobj(&ooo);
ObjectList.push_back(std::move(ooobj));
Object oooo(false);
std::unique_ptr<Object> oooobj(&oooo);
ObjectList.push_back(std::move(oooobj));
for(int i = 0; i < ObjectList.size(); i++)
{
ObjectList.erase(ObjectList.begin() + i);
}
for(int i = 0; i < ObjectList.size(); i++)
{
std::cout << "object is left";
}
while(true)
{
}
return 0;
}
It is just so confusing. Does anyone know where I can find a tutorial on game data management or something? Thanks.