Saving work #1
This commit is contained in:
parent
ad63c5d2c5
commit
54a1a095e7
@ -77,6 +77,7 @@ namespace polygun::world {
|
||||
m_loading_opacity(0.0f),
|
||||
m_unloaded(false),
|
||||
m_chunk_lightmap(),
|
||||
m_chunk_sun_lightmap(),
|
||||
#endif
|
||||
m_chunk_data()
|
||||
{
|
||||
@ -96,9 +97,11 @@ namespace polygun::world {
|
||||
m_loading_opacity(0.0f),
|
||||
m_unloaded(false),
|
||||
m_chunk_lightmap(),
|
||||
m_chunk_sun_lightmap(),
|
||||
m_chunk_data()
|
||||
{
|
||||
memset(m_chunk_lightmap, 0xFF, sizeof(m_chunk_lightmap));
|
||||
memset(m_chunk_lightmap, 0, sizeof(m_chunk_lightmap));
|
||||
memset(m_chunk_sun_lightmap, 0, sizeof(m_chunk_sun_lightmap));
|
||||
memset(m_chunk_data, 0, sizeof(m_chunk_data));
|
||||
}
|
||||
|
||||
@ -114,9 +117,11 @@ namespace polygun::world {
|
||||
m_loading_opacity(other.m_loading_opacity),
|
||||
m_unloaded(false),
|
||||
m_chunk_lightmap(),
|
||||
m_chunk_sun_lightmap(),
|
||||
m_chunk_data()
|
||||
{
|
||||
memcpy(m_chunk_lightmap, other.m_chunk_lightmap, sizeof(m_chunk_lightmap));
|
||||
memcpy(m_chunk_sun_lightmap, other.m_chunk_sun_lightmap, sizeof(m_chunk_sun_lightmap));
|
||||
memcpy(m_chunk_data, other.m_chunk_data, sizeof(m_chunk_data));
|
||||
}
|
||||
|
||||
@ -310,17 +315,33 @@ namespace polygun::world {
|
||||
}
|
||||
|
||||
#if defined(BUILD_CLIENT)
|
||||
void Chunk::set_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val) {
|
||||
void Chunk::set_emitted_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val) {
|
||||
const size_t index = (pos[2]*CHUNK_SIZE*CHUNK_SIZE+pos[1]*CHUNK_SIZE+pos[0])*3+side/2;
|
||||
const unsigned char offset_in_byte = (side%2)*4;
|
||||
m_chunk_lightmap[index] |= (val<<offset_in_byte)&(0xF<<offset_in_byte);
|
||||
}
|
||||
|
||||
uint8_t Chunk::get_light_value(const math::Vector3i& pos, NodeSide side) const {
|
||||
void Chunk::set_sunlight_value(const math::Vector3i& pos, NodeSide side, uint8_t val) {
|
||||
const size_t index = (pos[2]*CHUNK_SIZE*CHUNK_SIZE+pos[1]*CHUNK_SIZE+pos[0])*3+side/2;
|
||||
const unsigned char offset_in_byte = (side%2)*4;
|
||||
m_chunk_sun_lightmap[index] |= (val<<offset_in_byte)&(0xF<<offset_in_byte);
|
||||
}
|
||||
|
||||
uint8_t Chunk::get_emitted_light_value(const math::Vector3i& pos, NodeSide side) const {
|
||||
const size_t index = (pos[2]*CHUNK_SIZE*CHUNK_SIZE+pos[1]*CHUNK_SIZE+pos[0])*3+side/2;
|
||||
const unsigned char offset_in_byte = (side%2)*4;
|
||||
return (m_chunk_lightmap[index]>>offset_in_byte)&0xF;
|
||||
}
|
||||
|
||||
uint8_t Chunk::get_sunlight_value(const math::Vector3i& pos, NodeSide side) const {
|
||||
const size_t index = (pos[2]*CHUNK_SIZE*CHUNK_SIZE+pos[1]*CHUNK_SIZE+pos[0])*3+side/2;
|
||||
const unsigned char offset_in_byte = (side%2)*4;
|
||||
return (m_chunk_sun_lightmap[index]>>offset_in_byte)&0xF;
|
||||
}
|
||||
|
||||
uint8_t Chunk::get_light_value(const math::Vector3i& pos, NodeSide side) const {
|
||||
return std::max(get_emitted_light_value(pos,side), get_sunlight_value(pos, side));
|
||||
}
|
||||
#endif
|
||||
|
||||
void Chunk::serialize(network::NetworkPacket& packet) const {
|
||||
|
@ -100,7 +100,10 @@ namespace polygun::world {
|
||||
#if defined(BUILD_CLIENT)
|
||||
bool has_mesh() const { return m_mesh; }
|
||||
float get_loading_opacity() const { return m_loading_opacity; }
|
||||
void set_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val);
|
||||
void set_emitted_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val);
|
||||
void set_sunlight_value(const math::Vector3i& pos, NodeSide side, uint8_t val);
|
||||
uint8_t get_emitted_light_value(const math::Vector3i& pos, NodeSide side) const;
|
||||
uint8_t get_sunlight_value(const math::Vector3i& pos, NodeSide side) const;
|
||||
uint8_t get_light_value(const math::Vector3i& pos, NodeSide side) const;
|
||||
#endif
|
||||
|
||||
@ -123,6 +126,7 @@ namespace polygun::world {
|
||||
bool m_unloaded;
|
||||
// Each light value is in 0-15 range so 2 node faces are stored in one byte
|
||||
uint8_t m_chunk_lightmap[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE*3];
|
||||
uint8_t m_chunk_sun_lightmap[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE*3];
|
||||
#endif
|
||||
uint16_t m_chunk_data[CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE];
|
||||
};
|
||||
|
@ -76,12 +76,12 @@ Chunk& ChunkManagerBase::get_chunk_with_node(const math::Vector3i& node_pos) {
|
||||
}
|
||||
|
||||
#if defined(BUILD_CLIENT)
|
||||
void ChunkManagerBase::set_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val) {
|
||||
get_chunk_with_node(pos).set_light_value(node_pos_to_local_node_pos(pos), side, val);
|
||||
void ChunkManagerBase::set_emitted_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val) {
|
||||
get_chunk_with_node(pos).set_emitted_light_value(node_pos_to_local_node_pos(pos), side, val);
|
||||
}
|
||||
|
||||
uint8_t ChunkManagerBase::get_light_node(const math::Vector3i& pos, NodeSide side) {
|
||||
return get_chunk_with_node(pos).get_light_value(node_pos_to_local_node_pos(pos), side);
|
||||
uint8_t ChunkManagerBase::get_emitted_light_value(const math::Vector3i& pos, NodeSide side) {
|
||||
return get_chunk_with_node(pos).get_emitted_light_value(node_pos_to_local_node_pos(pos), side);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -46,8 +46,8 @@ namespace polygun::world {
|
||||
uint16_t get_node(const math::Vector3i& node_pos);
|
||||
Chunk& get_chunk_with_node(const math::Vector3i& node_pos);
|
||||
#if defined(BUILD_CLIENT)
|
||||
void set_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val);
|
||||
uint8_t get_light_node(const math::Vector3i& pos, NodeSide side);
|
||||
void set_emitted_light_value(const math::Vector3i& pos, NodeSide side, uint8_t val);
|
||||
uint8_t get_emitted_light_value(const math::Vector3i& pos, NodeSide side);
|
||||
#endif
|
||||
math::Rect3D get_node_bbox(const math::Vector3i& node_pos);
|
||||
|
||||
|
@ -88,7 +88,7 @@ void GameSessionScreen::begin() {
|
||||
m_resource_manager = new engine::ResourceManager(m_engine->get_master_renderer());
|
||||
m_content_registry = new engine::ContentRegistry;
|
||||
m_texture_atlas = new engine::TextureAtlas(m_engine->get_master_renderer(), *m_content_registry, *m_resource_manager);
|
||||
m_chunk_manager.reset(new world::ChunkManager(m_engine, *m_texture_atlas));
|
||||
m_chunk_manager.reset(new world::ChunkManager(m_engine, *m_texture_atlas, *m_content_registry));
|
||||
m_player_manager.reset(new world::PlayerManager(m_engine, *m_chunk_manager));
|
||||
m_physic_manager.reset(new world::PhysicManager(m_chunk_manager.get()));
|
||||
m_engine->get_mesh_renderer()->invalidate_cache();
|
||||
@ -140,7 +140,7 @@ void GameSessionScreen::update(double delta) {
|
||||
m_player_manager->update(delta);
|
||||
if(m_player_manager->get_master_local_player().has_mode_changed())
|
||||
switch_hud(m_player_manager->get_master_local_player().get_mode());
|
||||
m_chunk_manager->update_chunks(delta, *m_content_registry);
|
||||
m_chunk_manager->update_chunks(delta);
|
||||
m_physic_manager->update(delta);
|
||||
default:
|
||||
break;
|
||||
|
@ -40,11 +40,12 @@ SOFTWARE.
|
||||
|
||||
using namespace polygun::world;
|
||||
|
||||
ChunkManager::ChunkManager(engine::Engine* engine, engine::TextureAtlas& texture_atlas) :
|
||||
ChunkManager::ChunkManager(engine::Engine* engine, engine::TextureAtlas& texture_atlas, engine::ContentRegistry& content_registry) :
|
||||
utils::ThreadSafe(),
|
||||
world::ChunkManagerBase(),
|
||||
m_engine(engine),
|
||||
m_texture_atlas(texture_atlas),
|
||||
m_content_registry(content_registry),
|
||||
m_loaded_area_offset(0),
|
||||
m_pending_chunks(),
|
||||
m_loaded_chunks(new Chunk*[VIEW_AREA_SIZE*VIEW_AREA_SIZE*VIEW_AREA_SIZE]),
|
||||
@ -206,7 +207,7 @@ void ChunkManager::on_local_player_move(const LocalPlayer& player) {
|
||||
release();
|
||||
}
|
||||
|
||||
void ChunkManager::update_chunks(float delta, engine::ContentRegistry& content_registry) {
|
||||
void ChunkManager::update_chunks(float delta) {
|
||||
acquire();
|
||||
for(size_t i = 0; i<m_unloaded_chunks.size(); i++) {
|
||||
Chunk* const chunk = m_unloaded_chunks[i];
|
||||
@ -221,7 +222,7 @@ void ChunkManager::update_chunks(float delta, engine::ContentRegistry& content_r
|
||||
Chunk* const chunk = m_loaded_chunks[i];
|
||||
if(chunk) {
|
||||
if(chunk->is_modified()) {
|
||||
chunk->generate_mesh(content_registry);
|
||||
chunk->generate_mesh(m_content_registry);
|
||||
chunk->set_modified(false);
|
||||
m_updated_chunks--;
|
||||
break;
|
||||
@ -233,6 +234,10 @@ void ChunkManager::update_chunks(float delta, engine::ContentRegistry& content_r
|
||||
release();
|
||||
}
|
||||
|
||||
void ChunkManager::generate_column_sun_lightmap(const math::Vector2i& pos) {
|
||||
|
||||
}
|
||||
|
||||
void ChunkManager::render() {
|
||||
acquire();
|
||||
renderer::MeshRenderer* const mesh_renderer = m_engine->get_mesh_renderer();
|
||||
|
@ -49,12 +49,13 @@ namespace polygun::world {
|
||||
namespace polygun::world {
|
||||
class ChunkManager final : public utils::ThreadSafe, public world::ChunkManagerBase {
|
||||
public:
|
||||
ChunkManager(engine::Engine* engine, engine::TextureAtlas& texture_atlas);
|
||||
ChunkManager(engine::Engine* engine, engine::TextureAtlas& texture_atlas, engine::ContentRegistry& content_registry);
|
||||
~ChunkManager();
|
||||
|
||||
void on_packet(network::NetworkPacket& packet);
|
||||
void on_local_player_move(const LocalPlayer& player);
|
||||
void update_chunks(float delta, engine::ContentRegistry& content_registry);
|
||||
void update_chunks(float delta);
|
||||
void generate_column_sun_lightmap(const math::Vector2i& pos);
|
||||
void render();
|
||||
void try_place(const math::Vector3i& node_pos, uint16_t node);
|
||||
void try_fill_node(const math::Vector3i& from, const math::Vector3i& to, uint16_t node);
|
||||
@ -68,6 +69,7 @@ namespace polygun::world {
|
||||
private:
|
||||
engine::Engine* m_engine;
|
||||
engine::TextureAtlas& m_texture_atlas;
|
||||
engine::ContentRegistry& m_content_registry;
|
||||
math::Vector3i m_loaded_area_offset;
|
||||
std::vector<math::Vector3i> m_pending_chunks;
|
||||
Chunk** m_loaded_chunks;
|
||||
|
Loading…
x
Reference in New Issue
Block a user