Optimize several imports

master
Nicole Collings 2020-06-24 16:35:01 -07:00
parent 10b9bdb95d
commit 72d0b8d697
23 changed files with 97 additions and 41 deletions

View File

@ -32,7 +32,7 @@ DebugGui::DebugGui(glm::vec2 bufferSize, ClientGame& defs) :
add(meshGraph);
auto genGraph = std::make_shared<GuiLabelledGraph>("genGraph");
genGraph->create({244, 64}, {}, "Gen", 120, 256, genericHistogramRef, f);
genGraph->create({244, 64}, {}, "Gen", 120, 16, genericHistogramRef, f);
add(genGraph);
auto packetGraph = std::make_shared<GuiLabelledGraph>("packetGraph");

View File

@ -6,6 +6,9 @@
#include "ConnectScene.h"
#include "../../util/net/Packet.h"
#include "../../util/net/PacketType.h"
#include "../../util/net/PacketView.h"
#include "../../server/asset/AssetType.h"
#include "../hud/components/basic/GuiText.h"
#include "../hud/components/basic/GuiRect.h"

View File

@ -4,6 +4,9 @@
#include "GameScene.h"
#include "../../util/net/Packet.h"
#include "../../util/net/PacketView.h"
GameScene::GameScene(ClientState& state) : Scene(state),
game(state.defs),
world(game, &net),

View File

@ -4,7 +4,9 @@
#include "MeshGenStream.h"
#include "ChunkMeshDetails.h"
#include "graph/ChunkMeshGenerator.h"
#include "../../../world/chunk/Chunk.h"
#include "../../../world/LocalDimension.h"
MeshGenStream::MeshGenStream(ClientGame& game, LocalDimension &dimension) :
@ -73,6 +75,10 @@ std::vector<ChunkMeshDetails*> MeshGenStream::update() {
return std::move(finishedChunks);
}
MeshGenStream::Unit::Unit() {
meshDetails = new ChunkMeshDetails();
}
MeshGenStream::Thread::Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSamplers) :
game(defs), offsetSamplers(offsetSamplers), thread(std::bind(&MeshGenStream::Thread::exec, this)) {}
@ -122,4 +128,4 @@ MeshGenStream::~MeshGenStream() {
t.keepAlive = false;
t.thread.join();
}
}
}

View File

@ -4,16 +4,16 @@
#pragma once
#include <thread>
#include <glm/vec3.hpp>
#include <unordered_set>
#include "ChunkMeshDetails.h"
#include "../../../util/Vec.h"
#include "../../../def/ClientGame.h"
#include "../../../def/gen/NoiseSample.h"
#include "../../../world/chunk/Chunk.h"
class Chunk;
class ChunkMeshDetails;
class LocalDimension;
@ -37,10 +37,12 @@ public:
std::vector<ChunkMeshDetails*> update();
struct Unit {
Unit();
std::shared_ptr<Chunk> thisChunk = nullptr;
std::array<std::shared_ptr<Chunk>, 6> adjacentChunks {};
ChunkMeshDetails* meshDetails = new ChunkMeshDetails();
ChunkMeshDetails* meshDetails;
bool busy = false;
};

View File

@ -5,15 +5,16 @@
#include "Player.h"
#include "../../../util/Ray.h"
#include "../../../world/chunk/Chunk.h"
Player::Player(LocalWorld& world, ClientGame& defs, Renderer& renderer, LocalInventoryRefs& refs) :
Collidable(world, defs, {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}}),
Collidable(world, defs, {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}}),
refs(refs),
game(defs),
renderer(renderer),
wireframe({}, 0.01, {1, 1, 1}),
gameGui(refs, renderer.window.getSize(), defs, renderer) {
refs(refs),
game(defs),
renderer(renderer),
wireframe({}, 0.01, {1, 1, 1}),
gameGui(refs, renderer.window.getSize(), defs, renderer) {
handItemModel.parent = &handModel;
renderer.window.addResizeCallback("player", [&](glm::ivec2 win) {

View File

@ -4,13 +4,17 @@
#pragma once
#include "../../hud/GameGui.h"
#include "../../entity/Collidable.h"
#include "../../hud/GameGuiBuilder.h"
#include "../../graph/drawable/Drawable.h"
#include "../../hud/GameGui.h"
#include "../../../world/block/PointedThing.h"
#include "../../entity/engine/WireframeEntity.h"
class LuaGuiElement;
class LocalInventory;
class LocalInventoryRefs;
class Player : Collidable, public Drawable {
public:
static constexpr float MOUSE_SENSITIVITY = 0.1f;

View File

@ -58,6 +58,14 @@ sol::object LuaGuiElement::call(sol::this_state s, sol::function fun) {
return fun(this);
}
sol::object LuaGuiElement::pcall(sol::this_state s, sol::protected_function fun) {
sol::table tbl = sol::state_view(s)["zepha"]["__builtin"]["gui_env"];
sol::environment env(s, sol::create, tbl);
sol::set_environment(env, fun);
return fun(this);
}
sol::object LuaGuiElement::get_child(sol::this_state s, sol::object key) {
if (key.is<float>() && key.as<float>() <= children.size()) {
auto begin = children.begin();

View File

@ -20,6 +20,7 @@ public:
sol::object set_trait(const std::string& key, sol::object val);
sol::object call(sol::this_state s, sol::function fun);
sol::object pcall(sol::this_state s, sol::protected_function fun);
sol::object get_child(sol::this_state s, sol::object key);
void append(sol::this_state s, sol::object elem);
@ -63,7 +64,7 @@ namespace ClientApi {
sol::meta_function::index, &LuaGuiElement::get_trait,
sol::meta_function::new_index, &LuaGuiElement::set_trait,
sol::meta_function::call, &LuaGuiElement::call,
sol::meta_function::call, sol::overload(&LuaGuiElement::call, &LuaGuiElement::pcall),
"get", &LuaGuiElement::get_child,
"append", &LuaGuiElement::append,

View File

@ -7,9 +7,10 @@
#include "ServerWorld.h"
#include "ServerGenStream.h"
#include "../conn/ClientList.h"
#include "../conn/ServerClient.h"
#include "../../util/Timer.h"
#include "../../world/chunk/MapBlock.h"
ServerWorld::ServerWorld(unsigned int seed, ServerGame& game, ClientList& clients) :
clientList(clients),
@ -57,7 +58,7 @@ void ServerWorld::update(double delta) {
dimension.update(clientList.clients);
auto finished = genStream->update();
generatedChunks = static_cast<int>(finished->size());
generatedMapBlocks = static_cast<int>(finished->size());
std::unordered_set<glm::ivec3, Vec::ivec3> changed {};
@ -90,7 +91,7 @@ void ServerWorld::update(double delta) {
// Send the # of generated chunks to the client (debug),
// and trigger new chunks to be generated if a player has changed MapBlocks.
Packet r(PacketType::SERVER_INFO);
r.data = Serializer().append(generatedChunks).data;
r.data = Serializer().append(generatedMapBlocks).data;
for (auto& client : clientList.clients) {
if (client->hasPlayer) {
@ -175,7 +176,8 @@ void ServerWorld::sendChunksToPlayer(ServerClient& client) {
void ServerWorld::sendChunk(const std::shared_ptr<Chunk>& chunk, ServerClient &peer) {
if (chunk == nullptr || !chunk->generated) return;
Packet r = chunk->serialize();
Packet r(PacketType::CHUNK);
r.data = chunk->serialize();
r.sendTo(peer.peer, PacketChannel::CHUNK);
}

View File

@ -8,13 +8,17 @@
#include "../../game/scene/world/World.h"
#include "ServerGenStream.h"
#include "../../world/ServerDimension.h"
class ServerGame;
class ClientList;
class ServerClient;
class ServerGenStream;
class ServerWorld : public World {
public:
const static int MB_GEN_H = 3, MB_GEN_V = 3;
const static int CHUNK_SEND_H = 8, CHUNK_SEND_V = 8;
const static int MB_GEN_H = 4, MB_GEN_V = 4;
const static int CHUNK_SEND_H = 10, CHUNK_SEND_V = 10;
explicit ServerWorld(unsigned int seed, ServerGame& game, ClientList& clients);
@ -35,13 +39,13 @@ private:
static void sendChunk(const std::shared_ptr<Chunk>& chunk, ServerClient& client);
std::unique_ptr<ServerGenStream> genStream = nullptr;
std::shared_ptr<ServerGenStream> genStream = nullptr;
unsigned int seed;
ServerGame& game;
ClientList& clientList;
unsigned int generatedChunks = 0;
unsigned int generatedMapBlocks = 0;
std::vector<glm::ivec3> generateOrder;
};

View File

@ -4,6 +4,8 @@
#include "Dimension.h"
#include "chunk/Chunk.h"
bool Dimension::setBlock(glm::ivec3 pos, unsigned int block) {
if (!DimensionBase::setBlock(pos, block)) return false;

View File

@ -4,6 +4,11 @@
#include "DimensionBase.h"
#include "chunk/Chunk.h"
#include "chunk/Region.h"
#include "chunk/MapBlock.h"
#include "../def/DefinitionAtlas.h"
DimensionBase::DimensionBase(DefinitionAtlas &defs) : defs(defs) {}
std::shared_ptr<Region> DimensionBase::getRegion(glm::ivec3 regionPosition) {

View File

@ -7,9 +7,14 @@
#pragma once
#include <memory>
#include <unordered_map>
#include "../util/Vec.h"
#include "chunk/Region.h"
class Chunk;
class Region;
class MapBlock;
class DefinitionAtlas;
class DimensionBase {
public:

View File

@ -4,10 +4,17 @@
#include "LocalDimension.h"
#include "../world/chunk/Chunk.h"
#include "../world/chunk/Region.h"
#include "../world/chunk/MapBlock.h"
#include "../lua/api/class/LocalLuaEntity.h"
#include "../game/scene/world/MeshGenStream.h"
#include "../game/scene/world/graph/MeshChunk.h"
#include "../game/scene/world/ChunkMeshDetails.h"
#include "../lua/api/class/ServerLocalLuaEntity.h"
LocalDimension::LocalDimension(ClientGame &game) : Dimension(game.defs),
meshGenStream(std::make_unique<MeshGenStream>(game, *this)),
meshGenStream(std::make_shared<MeshGenStream>(game, *this)),
game(game) {}
void LocalDimension::update(double delta, glm::vec3 playerPos) {

View File

@ -4,15 +4,19 @@
#pragma once
#include <list>
#include "Dimension.h"
#include "../lua/api/class/LocalLuaEntity.h"
#include "../game/scene/world/MeshGenStream.h"
#include "../def/ClientGame.h"
#include "../game/entity/engine/PlayerEntity.h"
#include "../lua/api/class/ServerLocalLuaEntity.h"
#include "../game/scene/world/graph/ChunkRenderElem.h"
class Renderer;
class MeshChunk;
class MeshGenStream;
class ChunkRenderElem;
class LocalLuaEntity;
class ServerLocalLuaEntity;
class LocalDimension : public Dimension {
public:
@ -58,7 +62,7 @@ private:
ClientGame& game;
std::unique_ptr<MeshGenStream> meshGenStream = nullptr;
std::shared_ptr<MeshGenStream> meshGenStream;
std::vector<glm::vec3> pendingMesh {};
std::unordered_map<unsigned int, local_ent_ref> localEntityRefs {};

View File

@ -4,6 +4,8 @@
#include "ServerDimension.h"
#include "chunk/Region.h"
#include "chunk/MapBlock.h"
#include "../def/gen/MapGen.h"
#include "../server/conn/ServerClient.h"
#include "../server/world/ServerWorld.h"

View File

@ -38,7 +38,7 @@ const std::vector<unsigned short> &Chunk::cGetBiomes() const {
return biomes;
}
Packet Chunk::serialize() {
std::string Chunk::serialize() {
std::vector<unsigned short> blockLight = std::vector<unsigned short>(4096);
std::vector<unsigned char> sunLight = std::vector<unsigned char>(2048);
@ -58,9 +58,7 @@ Packet Chunk::serialize() {
std::string temp = Serializer().append(pos).append(blocks).append(biomes).append(blockLight).append(sunLight).data;
s.append<std::string>(gzip::compress(temp.data(), temp.size()));
std::cout << s.data.length() << std::endl;
return s.packet(PacketType::CHUNK);
return s.data;
}
void Chunk::deserialize(PacketView& packet) {

View File

@ -10,7 +10,6 @@
#include "../../util/RIE.h"
#include "../../util/Space.h"
#include "../../util/net/Packet.h"
#include "../../def/gen/BiomeAtlas.h"
#include "../../def/DefinitionAtlas.h"
#include "../../util/net/PacketView.h"
@ -59,7 +58,7 @@ public:
inline unsigned char getLight(unsigned int ind, unsigned char channel);
inline void setLight(unsigned int ind, unsigned char channel, unsigned char light);
Packet serialize();
std::string serialize();
void deserialize(PacketView& packet);
void recalculateRenderableBlocks();

View File

@ -4,7 +4,7 @@
#include "MapBlock.h"
#include "../../util/Space.h"
#include "Chunk.h"
MapBlock::MapBlock(glm::ivec3 pos) :
pos(pos) {

View File

@ -8,7 +8,7 @@
#include <memory>
#include <glm/vec3.hpp>
#include "Chunk.h"
class Chunk;
class MapBlock {
public:

View File

@ -4,7 +4,7 @@
#include "Region.h"
#include "../../util/Space.h"
#include "MapBlock.h"
Region::Region(glm::ivec3 pos) :
pos(pos) {

View File

@ -8,7 +8,7 @@
#include <memory>
#include <glm/vec3.hpp>
#include "MapBlock.h"
class MapBlock;
class Region {
public: