implement nextEntityID save/load
This commit is contained in:
parent
f4d3e62b3f
commit
cf2faa4a01
@ -85,7 +85,8 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
L" visible: "+std::to_wstring(level->chunks->visible);
|
||||
}));
|
||||
panel->add(create_label([=]() {
|
||||
return L"entities: "+std::to_wstring(level->entities->size());
|
||||
return L"entities: "+std::to_wstring(level->entities->size())+L" next: "+
|
||||
std::to_wstring(level->entities->peekNextID());
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
const auto& vox = player->selection.vox;
|
||||
|
||||
@ -192,9 +192,17 @@ public:
|
||||
void despawn(entityid_t id);
|
||||
dynamic::Value serialize(const Entity& entity);
|
||||
|
||||
void setNextID(entityid_t id) {
|
||||
nextID = id;
|
||||
}
|
||||
|
||||
inline size_t size() const {
|
||||
return entities.size();
|
||||
}
|
||||
|
||||
inline entityid_t peekNextID() const {
|
||||
return nextID;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OBJECTS_ENTITIES_HPP_
|
||||
|
||||
@ -26,6 +26,7 @@ Level::Level(
|
||||
entities(std::make_unique<Entities>(this)),
|
||||
settings(settings)
|
||||
{
|
||||
entities->setNextID(this->world->nextEntityId);
|
||||
auto inv = std::make_shared<Inventory>(
|
||||
this->world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE
|
||||
);
|
||||
|
||||
@ -9,10 +9,12 @@
|
||||
#include "../files/WorldFiles.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../voxels/Chunk.hpp"
|
||||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/ChunksStorage.hpp"
|
||||
#include "../world/WorldGenerators.hpp"
|
||||
#include "Level.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
@ -52,6 +54,7 @@ void World::updateTimers(float delta) {
|
||||
void World::write(Level* level) {
|
||||
const Content* content = level->content;
|
||||
level->chunks->saveAll();
|
||||
nextEntityId = level->entities->peekNextID();
|
||||
wfile->write(this, content);
|
||||
auto playerFile = dynamic::Map();
|
||||
|
||||
@ -193,6 +196,7 @@ void World::deserialize(dynamic::Map* root) {
|
||||
weatherobj->num("fog", fog);
|
||||
}
|
||||
nextInventoryId = root->get("next-inventory-id", 2);
|
||||
nextEntityId = root->get("next-entity-id", 1);
|
||||
}
|
||||
|
||||
std::unique_ptr<dynamic::Map> World::serialize() const {
|
||||
@ -215,5 +219,6 @@ std::unique_ptr<dynamic::Map> World::serialize() const {
|
||||
weatherobj.put("fog", fog);
|
||||
|
||||
root->put("next-inventory-id", nextInventoryId);
|
||||
root->put("next-entity-id", nextEntityId);
|
||||
return root;
|
||||
}
|
||||
|
||||
@ -51,6 +51,8 @@ public:
|
||||
/// @brief will be replaced with weather in future
|
||||
float fog = 0.0f;
|
||||
|
||||
entityid_t nextEntityId = 0;
|
||||
|
||||
World(
|
||||
std::string name,
|
||||
std::string generator,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user