refactor: player cameras are resources now
This commit is contained in:
parent
9623f35862
commit
9a18476437
@ -29,11 +29,14 @@ Player::Player(Level* level, glm::vec3 position, float speed,
|
|||||||
position(position),
|
position(position),
|
||||||
inventory(std::move(inv)),
|
inventory(std::move(inv)),
|
||||||
eid(eid),
|
eid(eid),
|
||||||
camera(std::make_shared<Camera>(position, glm::radians(90.0f))),
|
camera(level->getCamera("base:first-person")),
|
||||||
spCamera(std::make_shared<Camera>(position, glm::radians(90.0f))),
|
spCamera(level->getCamera("base:third-person-front")),
|
||||||
tpCamera(std::make_shared<Camera>(position, glm::radians(90.0f))),
|
tpCamera(level->getCamera("base:third-person-back")),
|
||||||
currentCamera(camera)
|
currentCamera(camera)
|
||||||
{
|
{
|
||||||
|
camera->setFov(glm::radians(90.0f));
|
||||||
|
spCamera->setFov(glm::radians(90.0f));
|
||||||
|
tpCamera->setFov(glm::radians(90.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player() {
|
Player::~Player() {
|
||||||
|
|||||||
@ -20,7 +20,9 @@ public:
|
|||||||
bool flipped = false;
|
bool flipped = false;
|
||||||
float aspect = 0.0f;
|
float aspect = 0.0f;
|
||||||
|
|
||||||
Camera() {}
|
Camera() {
|
||||||
|
updateVectors();
|
||||||
|
}
|
||||||
Camera(glm::vec3 position, float fov);
|
Camera(glm::vec3 position, float fov);
|
||||||
|
|
||||||
void rotate(float x, float y, float z);
|
void rotate(float x, float y, float z);
|
||||||
|
|||||||
@ -28,6 +28,23 @@ Level::Level(
|
|||||||
entities(std::make_unique<Entities>(this)),
|
entities(std::make_unique<Entities>(this)),
|
||||||
settings(settings)
|
settings(settings)
|
||||||
{
|
{
|
||||||
|
auto& cameraIndices = content->getIndices(ResourceType::CAMERA);
|
||||||
|
std::cout << cameraIndices.size() << std::endl;
|
||||||
|
for (size_t i = 0; i < cameraIndices.size(); i++) {
|
||||||
|
auto camera = std::make_shared<Camera>();
|
||||||
|
if (auto map = cameraIndices.getSavedData(i)) {
|
||||||
|
dynamic::get_vec(map, "pos", camera->position);
|
||||||
|
dynamic::get_mat(map, "rot", camera->rotation);
|
||||||
|
map->flag("perspective", camera->perspective);
|
||||||
|
map->flag("flipped", camera->flipped);
|
||||||
|
map->num("zoom", camera->zoom);
|
||||||
|
float fov = camera->getFov();
|
||||||
|
map->num("fov", fov);
|
||||||
|
camera->setFov(fov);
|
||||||
|
}
|
||||||
|
cameras.push_back(std::move(camera));
|
||||||
|
}
|
||||||
|
|
||||||
if (world->nextEntityId) {
|
if (world->nextEntityId) {
|
||||||
entities->setNextID(world->nextEntityId);
|
entities->setNextID(world->nextEntityId);
|
||||||
}
|
}
|
||||||
@ -53,22 +70,6 @@ Level::Level(
|
|||||||
|
|
||||||
inventories = std::make_unique<Inventories>(*this);
|
inventories = std::make_unique<Inventories>(*this);
|
||||||
inventories->store(player->getInventory());
|
inventories->store(player->getInventory());
|
||||||
|
|
||||||
auto& cameraIndices = content->getIndices(ResourceType::CAMERA);
|
|
||||||
for (size_t i = 0; i < cameraIndices.size(); i++) {
|
|
||||||
auto camera = std::make_shared<Camera>();
|
|
||||||
if (auto map = cameraIndices.getSavedData(i)) {
|
|
||||||
dynamic::get_vec(map, "pos", camera->position);
|
|
||||||
dynamic::get_mat(map, "rot", camera->rotation);
|
|
||||||
map->flag("perspective", camera->perspective);
|
|
||||||
map->flag("flipped", camera->flipped);
|
|
||||||
map->num("zoom", camera->zoom);
|
|
||||||
float fov = camera->getFov();
|
|
||||||
map->num("fov", fov);
|
|
||||||
camera->setFov(fov);
|
|
||||||
}
|
|
||||||
cameras.push_back(std::move(camera));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::~Level(){
|
Level::~Level(){
|
||||||
@ -106,3 +107,11 @@ void Level::onSave() {
|
|||||||
cameraIndices.saveData(i, std::move(map));
|
cameraIndices.saveData(i, std::move(map));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Camera> Level::getCamera(const std::string& name) {
|
||||||
|
size_t index = content->getIndices(ResourceType::CAMERA).indexOf(name);
|
||||||
|
if (index == ResourceIndices::MISSING) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return cameras.at(index);
|
||||||
|
}
|
||||||
|
|||||||
@ -75,6 +75,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onSave();
|
void onSave();
|
||||||
|
|
||||||
|
std::shared_ptr<Camera> getCamera(const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WORLD_LEVEL_HPP_ */
|
#endif /* WORLD_LEVEL_HPP_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user