Optimize *all* of the imports across *every single file*.. damn.

master
Nicole Collings 2020-07-06 18:34:59 -07:00
parent 2380c7ea31
commit 4ed852255d
228 changed files with 753 additions and 874 deletions

2
.gitignore vendored
View File

@ -4,5 +4,5 @@ cmake-build-release
.hidden
lib/*/*
lib
worlds

View File

@ -4,12 +4,14 @@
<component name="CidrRootsConfiguration">
<sourceRoots>
<file path="$PROJECT_DIR$/src" />
<file path="$PROJECT_DIR$/subgames" />
<file path="$PROJECT_DIR$/test" />
</sourceRoots>
<libraryRoots>
<file path="$PROJECT_DIR$/lib" />
</libraryRoots>
<excludeRoots>
<file path="$PROJECT_DIR$/.idea" />
<file path="$PROJECT_DIR$/Libraries" />
<file path="$PROJECT_DIR$/cmake-build-install" />
</excludeRoots>

View File

@ -233,9 +233,8 @@ set(ZEPHA_SRC
def/texture/RawTexData.h
game/hud/components/compound/GuiImageButton.cpp
game/hud/components/compound/GuiImageButton.h
game/ClientState.cpp
game/scene/menu/Subgame.cpp
game/scene/menu/Subgame.h
game/ClientState.cpp
game/scene/menu/Subgame.h
game/scene/menu/SubgameConfig.h
game/scene/menu/MenuSandbox.cpp
game/scene/menu/MenuSandbox.h
@ -320,17 +319,9 @@ set(ZEPHA_SRC
util/net/PacketView.h
lua/api/modules/create_structure.h
util/Any.h
game/scene/world/graph/MeshFarMap.cpp
game/scene/world/graph/MeshFarMap.h
def/gen/MapGenProps.cpp
def/gen/MapGenProps.cpp
def/gen/MapGenProps.h
def/gen/FarMapGen.cpp
def/gen/FarMapGen.h
def/gen/FarMapJob.h
game/scene/world/graph/FarMeshGenerator.cpp
game/scene/world/graph/FarMeshGenerator.h
game/scene/world/FarMapMeshDetails.h
lua/api/class/LuaGuiElement.cpp
lua/api/class/LuaGuiElement.h world/Dimension.cpp world/Dimension.h world/fs/FileManipulator.cpp world/fs/FileManipulator.h)
lua/api/class/LuaGuiElement.cpp
lua/api/class/LuaGuiElement.h world/Dimension.cpp world/Dimension.h world/fs/FileManipulator.cpp world/fs/FileManipulator.h def/item/BlockModel.cpp)
add_library (Zepha_Core ${ZEPHA_SRC})

View File

@ -11,6 +11,10 @@
#define STB_IMAGE_IMPLEMENTATION
#define CUTE_FILES_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image/stb_image.h>
#include <cute_files/cute_files.h>
#pragma clang diagnostic pop
#include "StartGame.h"

View File

@ -4,9 +4,12 @@
#pragma once
#include <iostream>
#include "util/Log.h"
#include "util/Util.h"
#include "game/Client.h"
#include "server/Server.h"
#include "util/Log.h"
enum class Mode { INVALID, CLIENT, SERVER };
@ -20,13 +23,13 @@ std::map<std::string, std::string> parseArgs(int argc, char* argv[]) {
std::string first = (equals == -1) ? arg : arg.substr(0, equals);
if (args.count(first)) {
std::cerr << "Duplicate argument '" << first << "'" << std::endl;
std::cout << Log::err << "Duplicate argument '" << first << "'" << Log::endl;
exit(1);
}
if (equals == -1) args.emplace(first, "");
else {
if (equals == arg.length() - 1) {
std::cerr << "Empty argument '" << first << "'" << std::endl;
std::cout << Log::err << "Empty argument '" << first << "'" << Log::endl;
exit(1);
}
args.emplace(first, arg.substr(equals + 1, arg.length()));

View File

@ -4,58 +4,42 @@
#include "DefinitionAtlas.h"
ItemDef& DefinitionAtlas::fromId(unsigned int id) const {
if (id > defs.size()) {
std::cout << Log::err << "Undefined def #" << id << " requested, returning invalid." << Log::endl;
return *defs.at(INVALID);
}
#include "ItemDef.h"
#include "item/BlockDef.h"
#include "item/CraftItemDef.h"
ItemDef& DefinitionAtlas::fromId(unsigned int id) const {
if (id > defs.size()) throw std::runtime_error("Undefined definition id " + std::to_string(id) + " requested.");
return *defs.at(static_cast<unsigned long>(id));
}
ItemDef &DefinitionAtlas::fromStr(const std::string& identifier) const {
if (identifier == "") return *defs.at(AIR);
if (defTable.count(identifier) <= 0) {
std::cout << Log::err << "Undefined identifier \"" << identifier << "\" requested, returning invalid." << Log::endl;
return *defs.at(INVALID);
}
if (defTable.count(identifier) <= 0) throw std::runtime_error("Undefined definition identifier " + identifier + " requested.");
return *defs.at(static_cast<unsigned long>(defTable.at(identifier)));
}
BlockDef& DefinitionAtlas::blockFromId(unsigned int index) const {
ItemDef& def = fromId(index);
if (def.type != ItemDef::Type::BLOCK) {
std::cout << Log::err << "Invalid block id." << Log::endl;
exit(0);
}
if (def.type != ItemDef::Type::BLOCK) throw std::runtime_error(std::to_string(index) + " is not a block.");
return static_cast<BlockDef&>(def);
}
BlockDef &DefinitionAtlas::blockFromStr(const std::string& identifier) const {
ItemDef& def = fromStr(identifier);
if (def.type != ItemDef::Type::BLOCK) {
std::cout << Log::err << "Invalid block id." << Log::endl;
exit(0);
}
if (def.type != ItemDef::Type::BLOCK) throw std::runtime_error(identifier + " is not a block.");
return static_cast<BlockDef&>(def);
}
CraftItemDef& DefinitionAtlas::craftItemFromId(unsigned int index) const {
ItemDef& def = fromId(index);
if (def.type != ItemDef::Type::CRAFTITEM) {
std::cout << Log::err << "Invalid item id." << Log::endl;
exit(0);
}
if (def.type != ItemDef::Type::CRAFTITEM) throw std::runtime_error(std::to_string(index) + " is not a craftitem.");
return static_cast<CraftItemDef&>(def);
}
CraftItemDef &DefinitionAtlas::craftItemFromStr(const std::string& identifier) const {
ItemDef& def = fromStr(identifier);
if (def.type != ItemDef::Type::CRAFTITEM) {
std::cout << Log::err << "Invalid item id." << Log::endl;
exit(0);
}
if (def.type != ItemDef::Type::CRAFTITEM) throw std::runtime_error(identifier + " is not a craftitem.");
return static_cast<CraftItemDef&>(def);
}

View File

@ -5,9 +5,12 @@
#pragma once
#include <string>
#include "item/BlockDef.h"
#include "ItemDef.h"
#include "item/CraftItemDef.h"
#include <vector>
#include <unordered_map>
class ItemDef;
class BlockDef;
class CraftItemDef;
class DefinitionAtlas {
public:

View File

@ -4,6 +4,9 @@
#include "LocalDefinitionAtlas.h"
#include "item/BlockDef.h"
#include "texture/TextureAtlas.h"
LocalDefinitionAtlas::LocalDefinitionAtlas(TextureAtlas& atlas) {
//Invalid Node
BlockModel invalidModel = BlockModel::createCube({atlas["_missing"]}, {}, {});
@ -26,10 +29,7 @@ void LocalDefinitionAtlas::setIdentifiers(const std::vector<std::string>& identi
}
void LocalDefinitionAtlas::registerDef(ItemDef* def) {
if (!defTable.count(def->identifier)) {
std::cout << Log::err << "Client/Server block identifier desync: " + def->identifier + ". Exiting." << Log::endl;
exit(1);
}
if (!defTable.count(def->identifier)) throw std::runtime_error("Client/Server definition desync: " + def->identifier + ".");
def->index = defTable[def->identifier];
defs[def->index] = def;
}

View File

@ -4,11 +4,10 @@
#pragma once
#include <vector>
#include "item/BlockDef.h"
#include "texture/TextureAtlas.h"
#include "DefinitionAtlas.h"
class TextureAtlas;
class LocalDefinitionAtlas : public DefinitionAtlas {
public:
LocalDefinitionAtlas(TextureAtlas& atlas);

View File

@ -4,6 +4,8 @@
#include "ServerDefinitionAtlas.h"
#include "item/BlockDef.h"
ServerDefinitionAtlas::ServerDefinitionAtlas() {
//Invalid Node

View File

@ -4,11 +4,6 @@
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
#include "item/BlockDef.h"
#include "DefinitionAtlas.h"
class ServerDefinitionAtlas : public DefinitionAtlas {

View File

@ -2,7 +2,12 @@
// Created by aurailus on 10/06/19.
//
#include <iostream>
#include <cute_files/cute_files.h>
#include "ServerGame.h"
#include "../util/Log.h"
#include "../server/conn/ClientList.h"
ServerGame::ServerGame(const std::string& subgame, unsigned int seed) :

View File

@ -4,7 +4,6 @@
#pragma once
#include "gen/ServerBiomeAtlas.h"
#include "ServerDefinitionAtlas.h"
#include "../server/asset/AssetStorage.h"

View File

@ -3,7 +3,8 @@
//
#include "BiomeAtlas.h"
#include "../../util/Log.h"
#include "BiomeDef.h"
void BiomeAtlas::generateVoronoi() {
std::vector<glm::vec3> points {};
@ -11,30 +12,18 @@ void BiomeAtlas::generateVoronoi() {
auto& biome = defs[i];
points.emplace_back(
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, (biome->temperature + 1) / 2 * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, biome->humidity * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, biome->roughness * voronoiSize))));
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, (biome->temperature + 1) / 2 * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, biome->humidity * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, biome->roughness * voronoiSize))));
}
voronoi.setPoints(points);
// voronoi.setColorValues({{0, 0, 0}, {0.5, 0.5, 0.5}, {1, 1, 1}, {0.7, 0.7, 0.7}, {0.3, 0.3, 0.3}, {0.15, 0.15, 0.15}});
// voronoi.generateImage(0);
// voronoi.generateImage(7);
// voronoi.generateImage(15);
// voronoi.generateImage(23);
// voronoi.generateImage(31);
// voronoi.generateImage(39);
// voronoi.generateImage(47);
// voronoi.generateImage(55);
// voronoi.generateImage(63);
}
BiomeDef& BiomeAtlas::getBiomeAt(float temperature, float humidity, float roughness) {
return biomeFromId(voronoi.getPoint(
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, (temperature + 1) / 2 * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, humidity * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, roughness * voronoiSize)))
));
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, (temperature + 1) / 2 * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, humidity * voronoiSize))),
static_cast<unsigned short>(std::fmin(voronoiSize - 1, std::fmax(0, roughness * voronoiSize)))));
}
unsigned int BiomeAtlas::size() {
@ -42,19 +31,11 @@ unsigned int BiomeAtlas::size() {
}
BiomeDef& BiomeAtlas::biomeFromId(unsigned int index) {
if (index >= defs.size()) {
std::cout << Log::err << "Undefined biome #" << index << " requested! Throwing." << Log::endl;
throw "Oops";
}
if (index >= defs.size()) throw std::runtime_error("Undefined biome ID " + std::to_string(index) + " requested.");
return *defs.at(static_cast<unsigned long>(index));
}
BiomeDef& BiomeAtlas::biomeFromStr(const std::string& identifier) {
if (defTable.count(identifier) <= 0) {
std::cout << Log::err << "Undefined identifier \"" << identifier << "\" requested! Throwing." << Log::endl;
throw "Oops";
}
if (defTable.count(identifier) <= 0) throw std::runtime_error("Undefined biome identifier " + identifier + "requested.");
return *defs.at(static_cast<unsigned long>(defTable.at(identifier)));
}

View File

@ -1,15 +1,16 @@
//
// Manages biome definitions and Voronoi map.
// Created by aurailus on 2019-11-13.
//
#pragma once
#include <map>
#include <vector>
#include <unordered_map>
#include "BiomeDef.h"
#include "../../util/Voronoi3D.h"
class BiomeDef;
class BiomeAtlas {
public:
BiomeAtlas() = default;

View File

@ -1,4 +1,6 @@
//
// Stores properties, blocks, and noise generation
// for a biome defined using the Lua API.
// Created by aurailus on 2019-11-13.
//
@ -10,7 +12,7 @@
#include <glm/glm.hpp>
#include <noise/module/modulebase.h>
#include "../../game/scene/world/Schematic.h"
class Schematic;
struct BiomeDef {
BiomeDef() = default;

View File

@ -1,53 +0,0 @@
//
// Created by aurailus on 2020-04-05.
//
#include "FarMapGen.h"
FarMapGen::FarMapGen(unsigned int seed, DefinitionAtlas& defs, BiomeAtlas& biomes, std::shared_ptr<MapGenProps> props) :
seed(seed),
defs(defs),
props(props),
biomes(biomes) {}
MeshFarMap FarMapGen::generateFarMap(glm::ivec3 mbPos, unsigned short downScale) {
auto job = new FarMapJob();
job->downScale = downScale;
buildDensityMap(job, mbPos);
delete job;
}
void FarMapGen::buildDensityMap(FarMapJob *job, glm::ivec3 mbPos) {
job->temperature = {}; job->humidity = {}; job->roughness = {};
job->temperature.fill([&](glm::ivec3 pos) {
return props->temperature.GetValue(mbPos.x * 4 + pos.x / 4.f, 0, mbPos.z * 4 + pos.z / 4.f); }, 4);
job->humidity.fill([&](glm::ivec3 pos) {
return props->humidity.GetValue(mbPos.x * 4 + pos.x / 4.f, 0, mbPos.z * 4 + pos.z / 4.f); }, 4);
job->roughness.fill([&](glm::ivec3 pos) {
return props->roughness.GetValue(mbPos.x * 4 + pos.x / 4.f, 0, mbPos.z * 4 + pos.z / 4.f); }, 4);
NoiseSample volume = {}, heightmap = {};
volume.fill([&](glm::ivec3 pos) {
auto& biome = biomes.getBiomeAt(job->temperature.get(pos), job->humidity.get(pos), job->roughness.get(pos));
return biome.volume[biome.volume.size() - 1]->GetValue(mbPos.x * 4 + pos.x / 4.f, mbPos.y * 4 + pos.y / 4.f, mbPos.z * 4 + pos.z / 4.f);
}, {4, 4});
heightmap.fill([&](glm::ivec3 pos) {
auto& biome = biomes.getBiomeAt(job->temperature.get(pos), job->humidity.get(pos), job->roughness.get(pos));
return biome.heightmap[biome.heightmap.size() - 1]->GetValue(mbPos.x * 4 + pos.x / 4.f, 0, mbPos.z * 4 + pos.z / 4.f);
}, 4);
int sampleWid = 64 / job->downScale;
float factor = (job->downScale == 2 ? 0.5f : job->downScale == 4 ? 1 : 2);
for (int m = 0; m < pow(sampleWid, 3); m++) {
glm::ivec3 lp = Space::Block::fromIndex(m);
job->density[m] = (volume.get(glm::vec3(lp) * factor) + heightmap.get(glm::vec3(lp) * factor)) - (static_cast<float>(lp.y) * factor + mbPos.y * 64);
}
}

View File

@ -1,36 +0,0 @@
//
// Created by aurailus on 2020-04-05.
//
#pragma once
#include "FarMapJob.h"
#include "BiomeAtlas.h"
#include "NoiseSample.h"
#include "MapGenProps.h"
#include "../../util/Vec.h"
#include "../DefinitionAtlas.h"
#include "../../game/scene/world/graph/MeshFarMap.h"
class FarMapGen {
FarMapGen(unsigned int seed, DefinitionAtlas& defs, BiomeAtlas& biomes, std::shared_ptr<MapGenProps> props);
MeshFarMap generateFarMap(glm::ivec3 mbPos, unsigned short downScale);
private:
// Build the density map for a job.
void buildDensityMap(FarMapJob* job, glm::ivec3 mbPos);
// Build the elevation map for a job.
void buildElevationMap(FarMapJob& job);
// Generate blocks and structures on a chunk, respectively. generateStructures can create partials.
// void generateBlocks(chunk_partial& chunk);
// void generateStructures(chunk_partials_map& chunks, chunk_partial& chunk);
unsigned int seed = 0;
DefinitionAtlas& defs;
BiomeAtlas& biomes;
std::shared_ptr<MapGenProps> props;
};

View File

@ -1,18 +0,0 @@
//
// Created by aurailus on 2020-04-05.
//
#pragma once
#include <vector>
#include <glm/vec3.hpp>
#include "NoiseSample.h"
struct FarMapJob {
std::vector<float> density {};
std::vector<float> depth {};
unsigned short downScale;
NoiseSample temperature, humidity, roughness;
};

View File

@ -4,6 +4,8 @@
#include "LocalBiomeAtlas.h"
#include "BiomeDef.h"
LocalBiomeAtlas::LocalBiomeAtlas() {
//Invalid Biome
BiomeDef* invalid = new BiomeDef("invalid", 0, -1, -1, -1, 0, 0, 0, {}, {}, {}, {});
@ -19,10 +21,7 @@ void LocalBiomeAtlas::setIdentifiers(const std::vector<std::string>& identifiers
}
void LocalBiomeAtlas::registerBiome(BiomeDef *def) {
if (!defTable.count(def->identifier)) {
std::cout << Log::err << "Client/Server biome identifier desync: " + def->identifier + ". Exiting." << Log::endl;
exit(1);
}
if (!defTable.count(def->identifier)) throw std::runtime_error("Client/Server biome desync: " + def->identifier + ".");
def->index = defTable[def->identifier];
defs[def->index] = def;
}

View File

@ -4,15 +4,11 @@
#pragma once
#include <string>
#include "BiomeDef.h"
#include "BiomeAtlas.h"
#include "../../util/Log.h"
class LocalBiomeAtlas : public BiomeAtlas {
public:
LocalBiomeAtlas();
void registerBiome(BiomeDef* def) override;
void setIdentifiers(const std::vector<std::string>& identifiers);
};

View File

@ -7,12 +7,15 @@
#include "MapGen.h"
#include "BiomeAtlas.h"
#include "BiomeDef.h"
#include "MapGenJob.h"
#include "BiomeAtlas.h"
#include "MapGenProps.h"
#include "NoiseSample.h"
#include "../item/BlockDef.h"
#include "../DefinitionAtlas.h"
#include "../../world/chunk/Chunk.h"
#include "../../game/scene/world/Schematic.h"
MapGen::MapGen(unsigned int seed, DefinitionAtlas& defs, BiomeAtlas& biomes, std::shared_ptr<MapGenProps> props) :
seed(seed),

View File

@ -1,4 +1,5 @@
//
// Generates terrain in the form of MapBlocks.
// Created by aurailus on 28/01/19.
//
@ -9,14 +10,14 @@
#include <glm/vec3.hpp>
#include <unordered_map>
#include "../../util/Vec.h"
class Chunk;
class MapGenJob;
class BiomeAtlas;
class MapGenProps;
class DefinitionAtlas;
#include "../../util/Vec.h"
class MapGen {
public:
typedef std::pair<MapGenJob*, Chunk*> chunk_partial;

View File

@ -5,7 +5,7 @@
#pragma once
#include <array>
#include <glm/vec3.hpp>
#include "NoiseSample.h"
class MapGenJob {

View File

@ -15,7 +15,7 @@ MapGenProps::MapGenProps(unsigned int seed) : seed(seed) {
temperature.SetScale(0.35);
temperature.SetBias(0.25);
humidityBase.SetSeed(seed + 5);
humidityBase.SetSeed(seed + 1);
humidityBase.SetFrequency(0.02);
humidityBase.SetOctaveCount(4);
humidityTurbulence.SetSourceModule(0, humidityBase);
@ -25,7 +25,7 @@ MapGenProps::MapGenProps(unsigned int seed) : seed(seed) {
humidity.SetScale(0.5);
humidity.SetBias(0.5);
roughnessBase.SetSeed(seed + 10);
roughnessBase.SetSeed(seed - 1);
roughnessBase.SetFrequency(0.02);
roughnessBase.SetOctaveCount(4);
roughnessTurbulence.SetSourceModule(0, roughnessBase);

View File

@ -6,23 +6,21 @@
#include <noise/noise.h>
using namespace noise;
class MapGenProps {
public:
MapGenProps(unsigned int seed);
unsigned int seed;
module::Perlin temperatureBase;
module::Turbulence temperatureTurbulence;
module::ScaleBias temperature;
noise::module::Perlin temperatureBase;
noise::module::Turbulence temperatureTurbulence;
noise::module::ScaleBias temperature;
module::Perlin humidityBase;
module::Turbulence humidityTurbulence;
module::ScaleBias humidity;
noise::module::Perlin humidityBase;
noise::module::Turbulence humidityTurbulence;
noise::module::ScaleBias humidity;
module::Perlin roughnessBase;
module::Turbulence roughnessTurbulence;
module::ScaleBias roughness;
noise::module::Perlin roughnessBase;
noise::module::Turbulence roughnessTurbulence;
noise::module::ScaleBias roughness;
};

View File

@ -1,9 +1,11 @@
//
// Created by aurailus on 15/02/19.
//
#include "NoiseSample.h"
#include <glm/glm.hpp>
#include "NoiseSample.h"
#include "../../util/Interp.h"
void NoiseSample::fill(const NoiseSample::fill_function &fun, float precision) {

View File

@ -4,6 +4,8 @@
#include "ServerBiomeAtlas.h"
#include "BiomeDef.h"
ServerBiomeAtlas::ServerBiomeAtlas(unsigned int seed) :
seed(seed) {
//Invalid Biome

View File

@ -5,7 +5,6 @@
#pragma once
#include "BiomeAtlas.h"
#include "BiomeDef.h"
class ServerBiomeAtlas : public BiomeAtlas {
public:

View File

@ -11,6 +11,7 @@
#include "BlockModel.h"
#include "SelectionBox.h"
#include "../../util/Util.h"
#include "../../lua/Callback.h"
class BlockDef : public ItemDef {

View File

@ -0,0 +1,95 @@
//
// Created by aurailus on 2020-07-06.
//
#include "BlockModel.h"
#include "../../util/Dir.h"
BlockModel
BlockModel::createCube(std::vector<std::shared_ptr<AtlasRef>> textureRefs,
std::vector<unsigned int> blendInds, std::vector<std::shared_ptr<AtlasRef>> blendMaskRefs) {
BlockModel blockModel;
blockModel.visible = true;
blockModel.culls = true;
std::vector<BlockModelVertex> vertices {};
std::vector<unsigned int> indices {};
unsigned int accessInd;
for (auto& ref : textureRefs) if (ref != nullptr) blockModel.textureRefs.insert(ref);
if (textureRefs.empty()) textureRefs.emplace_back(nullptr);
if (blendInds.empty()) blendInds.emplace_back(0);
if (blendMaskRefs.empty()) blendMaskRefs.emplace_back(nullptr);
//Left Face
vertices = {
{{0, 0, 0}, {}, {0, 1}, {0, 1}},
{{0, 0, 1}, {}, {1, 1}, {1, 1}},
{{0, 1, 1}, {}, {1, 0}, {1, 0}},
{{0, 1, 0}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 2));
MeshPart leftMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::LEFT)].push_back(leftMeshPart);
//Right Face
vertices = {
{{1, 1, 1}, {}, {1, 0}, {1, 0}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{1, 0, 0}, {}, {0, 1}, {0, 1}},
{{1, 1, 0}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 3));
MeshPart rightMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::RIGHT)].push_back(rightMeshPart);
//Top Face
vertices = {
{{0, 1, 0}, {}, {0, 0}, {0, 0}},
{{0, 1, 1}, {}, {0, 1}, {0, 1}},
{{1, 1, 1}, {}, {1, 1}, {1, 1}},
{{1, 1, 0}, {}, {1, 0}, {1, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 0));
MeshPart topMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::TOP)].push_back(topMeshPart);
//Bottom Face
vertices = {
{{0, 0, 0}, {}, {0, 0}, {0, 0}},
{{1, 0, 0}, {}, {1, 0}, {1, 0}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{0, 0, 1}, {}, {0, 1}, {0, 1}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 1));
MeshPart bottomMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::BOTTOM)].push_back(bottomMeshPart);
//Front Face
vertices = {
{{0, 0, 1}, {}, {0, 1}, {0, 1}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{1, 1, 1}, {}, {1, 0}, {1, 0}},
{{0, 1, 1}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 4));
MeshPart frontMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::FRONT)].push_back(frontMeshPart);
//Back Face
vertices = {
{{0, 0, 0}, {}, {0, 1}, {0, 1}},
{{0, 1, 0}, {}, {0, 0}, {0, 0}},
{{1, 1, 0}, {}, {1, 0}, {1, 0}},
{{1, 0, 0}, {}, {1, 1}, {1, 1}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 5));
MeshPart backMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::BACK)].push_back(backMeshPart);
return blockModel;
}

View File

@ -6,10 +6,8 @@
#include <set>
#include <vector>
#include "MeshPart.h"
#include "../../util/Dir.h"
#include <algorithm>
#include <limits>
struct BlockModel {
std::array<std::vector<MeshPart>, 7> parts {};
@ -20,88 +18,5 @@ struct BlockModel {
bool visible = false;
static BlockModel createCube(std::vector<std::shared_ptr<AtlasRef>> textureRefs,
std::vector<unsigned int> blendInds, std::vector<std::shared_ptr<AtlasRef>> blendMaskRefs) {
BlockModel blockModel;
blockModel.visible = true;
blockModel.culls = true;
std::vector<BlockModelVertex> vertices {};
std::vector<unsigned int> indices {};
unsigned int accessInd;
for (auto& ref : textureRefs) if (ref != nullptr) blockModel.textureRefs.insert(ref);
if (textureRefs.empty()) textureRefs.emplace_back(nullptr);
if (blendInds.empty()) blendInds.emplace_back(0);
if (blendMaskRefs.empty()) blendMaskRefs.emplace_back(nullptr);
//Left Face
vertices = {
{{0, 0, 0}, {}, {0, 1}, {0, 1}},
{{0, 0, 1}, {}, {1, 1}, {1, 1}},
{{0, 1, 1}, {}, {1, 0}, {1, 0}},
{{0, 1, 0}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 2));
MeshPart leftMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::LEFT)].push_back(leftMeshPart);
//Right Face
vertices = {
{{1, 1, 1}, {}, {1, 0}, {1, 0}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{1, 0, 0}, {}, {0, 1}, {0, 1}},
{{1, 1, 0}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 3));
MeshPart rightMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::RIGHT)].push_back(rightMeshPart);
//Top Face
vertices = {
{{0, 1, 0}, {}, {0, 0}, {0, 0}},
{{0, 1, 1}, {}, {0, 1}, {0, 1}},
{{1, 1, 1}, {}, {1, 1}, {1, 1}},
{{1, 1, 0}, {}, {1, 0}, {1, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 0));
MeshPart topMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::TOP)].push_back(topMeshPart);
//Bottom Face
vertices = {
{{0, 0, 0}, {}, {0, 0}, {0, 0}},
{{1, 0, 0}, {}, {1, 0}, {1, 0}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{0, 0, 1}, {}, {0, 1}, {0, 1}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 1));
MeshPart bottomMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::BOTTOM)].push_back(bottomMeshPart);
//Front Face
vertices = {
{{0, 0, 1}, {}, {0, 1}, {0, 1}},
{{1, 0, 1}, {}, {1, 1}, {1, 1}},
{{1, 1, 1}, {}, {1, 0}, {1, 0}},
{{0, 1, 1}, {}, {0, 0}, {0, 0}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 4));
MeshPart frontMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::FRONT)].push_back(frontMeshPart);
//Back Face
vertices = {
{{0, 0, 0}, {}, {0, 1}, {0, 1}},
{{0, 1, 0}, {}, {0, 0}, {0, 0}},
{{1, 1, 0}, {}, {1, 0}, {1, 0}},
{{1, 0, 0}, {}, {1, 1}, {1, 1}}};
indices = {0, 1, 2, 2, 3, 0};
accessInd = (std::max)(0, (std::min)(static_cast<int>(textureRefs.size() - 1), 5));
MeshPart backMeshPart(vertices, indices, textureRefs[accessInd], blendInds[accessInd], blendMaskRefs[accessInd]);
blockModel.parts[static_cast<int>(Dir::BACK)].push_back(backMeshPart);
return blockModel;
};
std::vector<unsigned int> blendInds, std::vector<std::shared_ptr<AtlasRef>> blendMaskRefs);
};

View File

@ -4,8 +4,8 @@
#pragma once
#include <glm/vec3.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
struct BlockModelVertex {
glm::vec3 pos;

View File

@ -4,6 +4,9 @@
#include "CraftItemDef.h"
#include "../texture/AtlasRef.h"
#include "../texture/TextureAtlas.h"
CraftItemDef::CraftItemDef(const std::string &identifier, const std::string &name, unsigned short maxStackSize,
const std::vector<std::string>& textures, const std::vector<std::shared_ptr<AtlasRef>>& textureRefs) :
CraftItemDef(identifier, 0, name, maxStackSize, textures, textureRefs) {}

View File

@ -8,7 +8,8 @@
#include "../ItemDef.h"
#include "../texture/AtlasRef.h"
class AtlasRef;
class TextureAtlas;
class CraftItemDef : public ItemDef {
public:

View File

@ -2,8 +2,13 @@
// Created by aurailus on 02/12/18.
//
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/normal.hpp>
#include "MeshPart.h"
#include "../texture/AtlasRef.h";
MeshPart::MeshPart(const std::vector<BlockModelVertex>& vertices, const std::vector<unsigned int>& indices,
std::shared_ptr<AtlasRef> texture, unsigned int blendInd, std::shared_ptr<AtlasRef> blendMask) :
vertices(vertices),

View File

@ -2,35 +2,28 @@
// Created by aurailus on 02/12/18.
//
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#pragma once
#define GLM_ENABLE_EXPERIMENTAL
#include <vector>
#include <glm/vec4.hpp>
#include <glm/gtx/normal.hpp>
#include <memory>
#include "ShaderMod.h"
#include "../texture/TextureAtlas.h"
#include "BlockModelVertex.h"
class AtlasRef;
struct MeshPart {
MeshPart(const std::vector<BlockModelVertex>& vertices, const std::vector<unsigned int>& indices,
std::shared_ptr<AtlasRef> texture, unsigned int blendInd, std::shared_ptr<AtlasRef> blendMask);
std::shared_ptr<AtlasRef> texture, unsigned int blendInd, std::shared_ptr<AtlasRef> blendMask);
std::vector<BlockModelVertex> vertices;
std::vector<unsigned int> indices;
std::shared_ptr<AtlasRef> texture;
unsigned int blendInd = 0;
std::shared_ptr<AtlasRef> blendMask;
ShaderMod shaderMod = ShaderMod::NONE;
float modValue = 0;
};
#pragma clang diagnostic pop
};

View File

@ -6,10 +6,6 @@
#pragma once
#include <iostream>
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
#include "../../util/Util.h"
#include "../../util/Dir.h"
class SelectionBox {

View File

@ -5,6 +5,7 @@
#pragma once
#include <map>
#include "SerializedModel.h"
class ModelStore {

View File

@ -4,10 +4,6 @@
#pragma once
#include <glm/vec4.hpp>
#include <string>
struct AtlasRef {
int tileX = 0;
int tileY = 0;

View File

@ -2,8 +2,13 @@
// Created by aurailus on 13/08/19.
//
#include <cmath>
#include "Font.h"
#include "AtlasRef.h"
#include "TextureAtlas.h"
Font::Font(TextureAtlas& atlas, std::shared_ptr<AtlasRef> tex) :
fontTex(std::move(tex)),
atlasSize(atlas.pixelSize) {
@ -13,10 +18,7 @@ Font::Font(TextureAtlas& atlas, std::shared_ptr<AtlasRef> tex) :
unsigned int Font::getCharWidth(char c) {
unsigned int index = static_cast<unsigned int>(c) - 32;
if (index >= amountOfChars) {
std::cout << Log::err << "Invalid char index!" << std::endl;
return 0;
}
if (index >= amountOfChars) throw "Invalid char index.";
return charWidths[index];
}
@ -55,20 +57,15 @@ void Font::getCharWidths(TextureAtlas &atlas) {
glm::vec4 Font::getCharUVs(char c) {
unsigned int index = static_cast<unsigned int>(c) - 32;
if (index >= amountOfChars) {
std::cout << Log::err << "Invalid char index!" << std::endl;
return {};
}
if (index >= amountOfChars) throw "Invalid char index.";
glm::vec4 uv;
glm::vec2 charPos = {((index % 18) * charWidth),
(std::floor(index / 18) * charHeight)};
uv.x = fontTex->uv.x + (charPos.x) / atlasSize.x;
uv.y = fontTex->uv.y + (charPos.y) / atlasSize.y;
uv.z = fontTex->uv.x + (charPos.x + getCharWidth(c) + 1) / atlasSize.x;
uv.w = fontTex->uv.y + (charPos.y + charHeight) / atlasSize.y;
glm::vec2 charPos = {(index % 18) * charWidth, std::floor(index / 18) * charHeight};
glm::vec4 uv = {
fontTex->uv.x + (charPos.x) / atlasSize.x,
fontTex->uv.y + (charPos.y) / atlasSize.y,
fontTex->uv.x + (charPos.x + getCharWidth(c) + 1) / atlasSize.x,
fontTex->uv.y + (charPos.y + charHeight) / atlasSize.y
};
return uv;
}

View File

@ -5,8 +5,11 @@
#pragma once
#include <memory>
#include "AtlasRef.h"
#include "../ClientGame.h"
#include <glm/vec2.hpp>
#include <glm/vec4.hpp>
class AtlasRef;
class TextureAtlas;
class Font {
public:

View File

@ -2,8 +2,16 @@
// Created by aurailus on 16/04/19.
//
#include "TextureAtlas.h"
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stb_image/stb_image.h>
#include <cute_files/cute_files.h>
#include "TextureAtlas.h"
#include "AtlasRef.h"
#include "../../util/Log.h"
TextureAtlas::TextureAtlas(unsigned int width, unsigned int height) :
pixelSize(width, (height == 0 ? width : height)),
@ -104,11 +112,7 @@ std::shared_ptr<AtlasRef> TextureAtlas::addImage(unsigned char *data, const std:
ref->tileHeight = tileHeight;
auto space = findImageSpace(tileWidth, tileHeight);
if (space.x < 0) {
std::cout << Log::err << "Failed to find space in dynamic defs." << Log::endl;
return nullptr;
}
if (space.x < 0) throw std::runtime_error("Failed to find space in the dynamic definition atlas.");
textureSlotsUsed += tileWidth * tileHeight;
@ -154,7 +158,7 @@ std::shared_ptr<AtlasRef> TextureAtlas::operator[](const std::string &name) {
std::shared_ptr<AtlasRef> gen = generateTexture(name);
if (gen) return gen;
std::cout << Log::err << "Invalid texture name: \"" << name << "\"." << Log::endl;
throw std::runtime_error("Invalid texture name " + name + ".");
return textures["_missing"];
}
@ -163,8 +167,7 @@ std::shared_ptr<AtlasRef> TextureAtlas::generateTexture(std::string req) {
if (req.find_first_of('(') != std::string::npos) {
if (req.find_last_of(')') == std::string::npos) {
std::cout << Log::err << "Mismatched braces." << Log::endl;
return nullptr;
throw "Miasmatched braces.";
}
std::string::size_type paramsBegin = req.find_first_of('(');
@ -182,7 +185,7 @@ std::shared_ptr<AtlasRef> TextureAtlas::generateTexture(std::string req) {
params.push_back(paramsString);
if (paramName == "crop") {
if (params.size() != 5) std::cout << Log::err << "crop needs 5 params." << Log::endl;
if (params.size() != 5) throw std::runtime_error("crop() requires 5 parameters.");
glm::ivec4 loc = {atof(params[0].data()), atof(params[1].data()), atof(params[2].data()), atof(params[3].data())};
std::shared_ptr<AtlasRef> src = operator[](params[4]);
@ -190,7 +193,7 @@ std::shared_ptr<AtlasRef> TextureAtlas::generateTexture(std::string req) {
return addImage(data, req, false, loc.z, loc.w);
}
else {
std::cout << Log::err << "Invalid param." << Log::endl;
throw std::runtime_error("Invalid parameter.");
return nullptr;
}
}

View File

@ -5,19 +5,16 @@
#pragma once
#include <map>
#include <cmath>
#include <memory>
#include <vector>
#include <algorithm>
#include <GL/glew.h>
#include <glm/vec2.hpp>
#include <cute_files/cute_files.h>
#include <glm/vec4.hpp>
#include "AtlasRef.h"
#include "RawTexData.h"
#include "../../util/Log.h"
#include "../../game/graph/Texture.h"
class AtlasRef;
class TextureAtlas {
public:
TextureAtlas() = default;

View File

@ -2,13 +2,17 @@
// Created by aurailus on 06/01/19.
//
#include <iostream>
#include "Client.h"
#include "../util/Log.h"
#include "../util/Timer.h"
#include "../server/LocalServerInstance.h"
#include "scene/GameScene.h"
#include "scene/ConnectScene.h"
#include "scene/MainMenuScene.h"
#include "scene/LuaErrorScene.h"
Client::Client(const std::string& path, const Address &addr, glm::ivec2 dims) :
state(path.substr(0, path.find_last_of('/') + 1), renderer),
@ -30,7 +34,7 @@ void Client::loop() {
if (state.desiredState == "local") {
state.desiredState = "connect";
localServer = std::make_unique<LocalServerInstance>(executablePath, addr.port, state.subgame);
localServer = std::make_shared<LocalServerInstance>(executablePath, addr.port, state.subgame);
localServer->start();
}

View File

@ -6,8 +6,10 @@
#include "ClientState.h"
#include "graph/Renderer.h"
#include "../util/net/Address.h"
#include "graph/scene/SceneManager.h"
#include "../server/LocalServerInstance.h"
class LocalServerInstance;
class Client {
public:
@ -22,7 +24,7 @@ private:
ClientState state;
SceneManager sceneManager;
std::unique_ptr<LocalServerInstance> localServer = nullptr;
std::shared_ptr<LocalServerInstance> localServer = nullptr;
double timeElapsed = 0.0f;
};

View File

@ -5,9 +5,9 @@
#pragma once
#include <string>
#include <assimp/quaternion.h>
#include <glm/vec3.hpp>
#include <vector>
#include <glm/vec3.hpp>
#include <assimp/quaternion.h>
class AnimChannel {
public:

View File

@ -4,6 +4,10 @@
#include "AnimationState.h"
#include "Model.h"
#include "ModelAnimation.h"
#include "AnimationSegment.h"
AnimationState::AnimationState(Model &source) {
const ModelAnimation& animation = source.getAnimation();

View File

@ -4,9 +4,13 @@
#pragma once
#include "Model.h"
#include "ModelAnimation.h"
#include "AnimationSegment.h"
#include <map>
#include <vector>
#include <string>
#include <glm/vec2.hpp>
class Model;
class AnimationSegment;
class AnimationState {
public:

View File

@ -2,7 +2,12 @@
// Created by aurailus on 2019-10-28.
//
#include <glm/common.hpp>
#include "Collidable.h"
#include "../../def/ClientGame.h"
#include "../../def/item/BlockDef.h"
#include "../scene/world/LocalWorld.h"
Collidable::Collidable(LocalWorld &world, ClientGame& defs, const SelectionBox& collisionBox) :
world(world),
@ -66,16 +71,16 @@ bool Collidable::collidesAt(glm::vec3& pos, float stepUpMax) {
if (def.solid)
for (auto &cBox : def.cBoxes)
stepUpAmount = (std::max)(cBox.b.y + offsetPos.y - pos.y, stepUpAmount);
stepUpAmount = std::fmax(cBox.b.y + offsetPos.y - pos.y, stepUpAmount);
if (offset.z == collisionBox.b.z) break;
offset.z = (std::min)(std::floor(offset.z + 1), collisionBox.b.z);
offset.z = std::fmin(std::floor(offset.z + 1), collisionBox.b.z);
}
if (offset.y == collisionBox.a.y + stepUpMax + 0.025f) break; // Hack for precision errors
offset.y = (std::min)(std::floor(offset.y + 1), collisionBox.a.y + stepUpMax + 0.025f);
offset.y = std::fmin(std::floor(offset.y + 1), collisionBox.a.y + stepUpMax + 0.025f);
}
if (offset.x == collisionBox.b.x) break;
offset.x = (std::min)(std::floor(offset.x + 1), collisionBox.b.x);
offset.x = std::fmin(std::floor(offset.x + 1), collisionBox.b.x);
}
}

View File

@ -4,7 +4,12 @@
#pragma once
#include "../scene/world/LocalWorld.h"
#include <glm/vec3.hpp>
#include "../../def/item/SelectionBox.h"
class LocalWorld;
class ClientGame;
class Collidable {
public:

View File

@ -1,12 +1,16 @@
#include <utility>
//
// Created by aurailus on 25/11/18.
//
#include <utility>
#include <glm/gtc/matrix_transform.hpp>
#include "Entity.h"
#include "Model.h"
#include "AnimationSegment.h"
#include "../graph/Renderer.h"
#include "../graph/meshtypes/EntityMesh.h"
Entity::Entity() : model(std::make_unique<Model>()) {}

View File

@ -4,14 +4,16 @@
#pragma once
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
#include <memory>
#include <glm/vec3.hpp>
#include <glm/mat4x4.hpp>
#include "../graph/meshtypes/EntityMesh.h"
#include "../graph/drawable/Drawable.h"
#include "Model.h"
#include "AnimationState.h"
#include "AnimationSegment.h"
#include "../graph/drawable/Drawable.h"
class Model;
class Entity : public Drawable {
public:

View File

@ -3,8 +3,19 @@
// Created by aurailus on 22/08/19.
//
#include <iostream>
#include <glm/glm.hpp>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <glm/gtc/matrix_transform.hpp>
#include "Model.h"
#include "../../util/Log.h"
#include "../../util/Mat4Conv.h"
#include "../../def/texture/AtlasRef.h"
#include "../../def/model/SerializedModel.h"
void Model::fromMesh(std::unique_ptr<EntityMesh> mesh) {
meshes.clear();
meshes.push_back(std::move(mesh));

View File

@ -4,21 +4,18 @@
#pragma once
#include <string>
#include <utility>
#include <iostream>
#include <assimp/Importer.hpp>
#include <memory>
#include <vector>
#include <glm/vec2.hpp>
#include <glm/mat4x4.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include "ModelBone.h"
#include "ModelAnimation.h"
#include "../graph/meshtypes/EntityMesh.h"
#include "../../def/texture/TextureAtlas.h"
#include "../../util/Mat4Conv.h"
#include "../../def/model/SerializedModel.h"
class AtlasRef;
class SerializedModel;
class Model {
public:

View File

@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include "AnimChannel.h"
class ModelAnimation {

View File

@ -2,8 +2,15 @@
// Created by aurailus on 14/04/19.
//
#include <glm/glm.hpp>
#include "BlockCrackEntity.h"
#include "../../../def/ClientGame.h"
#include "../../../def/item/MeshPart.h"
#include "../../../def/item/BlockDef.h"
#include "../../../def/texture/AtlasRef.h"
#include "../../../def/item/BlockModelVertex.h"
BlockCrackEntity::BlockCrackEntity(ClientGame &defs, glm::vec3 blockPos, unsigned int blockID) :
defs(defs),

View File

@ -5,7 +5,11 @@
#pragma once
#include "../Entity.h"
#include "../../../def/ClientGame.h"
class ClientGame;
class EntityVertex;
class AtlasRef;
class MeshPart;
class BlockCrackEntity : public Entity {
public:

View File

@ -2,19 +2,16 @@
// Created by aurailus on 15/05/19.
//
#include <cmath>
#include <random>
#include <glm/glm.hpp>
#include "ParticleEntity.h"
#include "../../../def/item/BlockDef.h"
#include "../../../def/texture/AtlasRef.h"
ParticleEntity::ParticleEntity(glm::vec3 pos, BlockDef &block) {
setPos(pos + glm::vec3(.5,.3,.5));
// setPos(getPos() + glm::vec3(
// (static_cast<float>(rand()) / static_cast<float>(RAND_MAX / 2) - 1) / 3.f,
// (static_cast<float>(rand()) / static_cast<float>(RAND_MAX / 2) - 1) / 3.f,
// (static_cast<float>(rand()) / static_cast<float>(RAND_MAX / 2) - 1) / 3.f
// ));
std::set<std::shared_ptr<AtlasRef>>& textureRefs = block.model.textureRefs;
auto it = textureRefs.cbegin();
advance(it, rand() % textureRefs.size());

View File

@ -4,9 +4,9 @@
#pragma once
#include <glm/glm.hpp>
#include "../Entity.h"
#include "../../../def/item/BlockDef.h"
class BlockDef;
class ParticleEntity : public Entity {
public:

View File

@ -4,9 +4,7 @@
#pragma once
#include <memory>
#include "../Entity.h"
#include "../../../def/texture/AtlasRef.h"
class PlayerEntity : public Entity {
public:

View File

@ -4,6 +4,9 @@
#include "WireframeEntity.h"
#include "../Model.h"
#include "../Entity.h"
#include "../../graph/meshtypes/EntityMesh.h"
WireframeEntity::WireframeEntity(const std::vector<SelectionBox>& boxes, float width, glm::vec3 color) :
width(width),

View File

@ -4,9 +4,10 @@
#pragma once
#include <glm/vec3.hpp>
#include "../Entity.h"
#include "../../../def/item/SelectionBox.h"
#include "../../graph/meshtypes/EntityVertex.h"
class WireframeEntity : public Entity {
public:

View File

@ -2,6 +2,8 @@
// Created by aurailus on 27/11/18.
//
#include <glm/gtc/matrix_transform.hpp>
#include "Camera.h"
Camera::Camera() = default;

View File

@ -4,10 +4,9 @@
#pragma once
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <GLFW/glfw3.h>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/mat4x4.hpp>
#include "frustum/Frustum.h"
class Camera {

View File

@ -2,6 +2,9 @@
// Created by aurailus on 29/11/18.
//
#include <stb_image/stb_image.h>
#include <stdexcept>
#include "Texture.h"
Texture::Texture(const std::string& file) :
@ -11,14 +14,8 @@ Texture::Texture(const std::string& file) :
void Texture::loadFromFile(std::string file) {
unsigned char *texData = stbi_load(file.c_str(), &width, &height, &bitDepth, 0);
if (!texData) {
printf("Failed to find texture at '%s'\n", file.c_str());
return;
}
if (!texData) throw std::runtime_error("Failed to find texture at " + file + ".");
loadFromBytes(texData, width, height);
stbi_image_free(texData);
}

View File

@ -4,9 +4,8 @@
#pragma once
#include <string>
#include <GL/glew.h>
#include <iostream>
#include <stb_image/stb_image.h>
class Texture {
public:

View File

@ -2,6 +2,8 @@
// Created by aurailus on 02/03/19.
//
#include <cmath>
#include "Frustum.h"
void Frustum::setCamInternals(float fov, float ratio, float nearD, float farD) {

View File

@ -4,7 +4,6 @@
#pragma once
#include <glm/vec3.hpp>
#include "FrustumPlane.h"
#include "FrustumAABB.h"

View File

@ -4,7 +4,6 @@
#pragma once
#include <glm/vec3.hpp>
class FrustumAABB {

View File

@ -2,11 +2,10 @@
// Created by aurailus on 02/03/19.
//
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/normal.hpp>
#include "FrustumPlane.h"
void FrustumPlane::setPoints(glm::vec3 &v1, glm::vec3 &v2, glm::vec3 &v3) {
@ -17,6 +16,4 @@ void FrustumPlane::setPoints(glm::vec3 &v1, glm::vec3 &v2, glm::vec3 &v3) {
float FrustumPlane::distance(glm::vec3 &p) {
return (d + glm::dot(normal, p));
}
#pragma clang diagnostic pop
}

View File

@ -4,9 +4,7 @@
#pragma once
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
class FrustumPlane {
public:

View File

@ -5,7 +5,9 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "EntityVertex.h"
class EntityMesh : public Mesh {

View File

@ -4,8 +4,7 @@
#pragma once
#include "../../../game/ClientState.h"
#include <iostream>
class ClientState;
class Scene {
public:

View File

@ -4,9 +4,10 @@
#pragma once
#include "Scene.h"
#include <memory>
#include "Scene.h"
class SceneManager {
public:
SceneManager() = default;

View File

@ -4,7 +4,6 @@
#pragma once
#include <GL/glew.h>
#include <glm/mat4x4.hpp>

View File

@ -2,9 +2,9 @@
// Created by aurailus on 24/09/19.
//
#include "LightingShader.h"
#include <stdexcept>
#include "../../../util/Log.h"
#include "LightingShader.h"
LightingShader::LightingShader(glm::ivec2 windowSize, float bufferScale) : Shader(),
windowSize(windowSize),
@ -60,9 +60,8 @@ void LightingShader::postCreate() {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
std::cout << Log::err << "Lighting framebuffer incomplete!" << std::endl;
}
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
throw std::runtime_error("Lighting framebuffer incomplete.");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
@ -94,7 +93,7 @@ void LightingShader::windowResized(glm::ivec2 windowSize) {
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
std::cout << Log::err << "-- Lighting framebuffer incomplete! --" << std::endl;
throw std::runtime_error("Lighting framebuffer incomplete.");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);

View File

@ -5,8 +5,8 @@
#pragma once
#include <array>
#include <glm/vec2.hpp>
#include <functional>
#include <glm/vec2.hpp>
class Input {
public:

View File

@ -2,8 +2,6 @@
// Created by aurailus on 26/11/18.
//
#include <iostream>
#include "Window.h"
#include "../../../util/Log.h"
@ -14,9 +12,8 @@ Window::Window(glm::ivec2 win) :
win(win), center(win.x / 2, win.y / 2) {
if (!glfwInit()) {
std::cout << Log::err << "Failed to initialize GLFW context." << Log::endl;
glfwTerminate();
exit(1);
throw std::runtime_error("Failed to initialize GLFW context.");
}
// Version 3.3
@ -29,9 +26,8 @@ Window::Window(glm::ivec2 win) :
// Create the window
if (!(mainWindow = glfwCreateWindow(win.x, win.y, "Zepha", nullptr, nullptr))) {
std::cout << Log::err << "Failed to initialize GLFW window." << Log::endl;
glfwTerminate();
exit(1);
throw std::runtime_error("Failed to initialize GLFW window.");
}
glfwGetFramebufferSize(mainWindow, &win.x, &win.y);
@ -43,11 +39,10 @@ Window::Window(glm::ivec2 win) :
// Initialize GLEW
GLenum error;
if ((error = glewInit()) != GLEW_OK) {
printf("GLEW init failed.");
std::cout << Log::err << "GLEW Encountered a fatal error:\n" << glewGetErrorString(error) << Log::endl;
glfwDestroyWindow(mainWindow);
glfwTerminate();
exit(1);
glfwDestroyWindow(mainWindow);
throw std::runtime_error("GLEW Fatal error.");
printf("%s", reinterpret_cast<const char *>(glewGetErrorString(error)));
}
glEnable(GL_DEPTH_TEST);

View File

@ -5,8 +5,6 @@
#pragma once
#include <map>
#include <functional>
#include <glm/vec2.hpp>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

View File

@ -3,8 +3,16 @@
//
#include "DebugGui.h"
#include "../../def/ClientGame.h"
#include "../scene/world/Player.h"
#include "../../def/texture/Font.h"
#include "components/compound/GuiInventoryList.h"
#include "../../def/gen/BiomeDef.h"
#include "../../def/item/BlockDef.h"
#include "components/basic/GuiText.h"
#include "../scene/world/LocalWorld.h"
#include "components/compound/GuiLabelledGraph.h"
DebugGui::DebugGui(glm::vec2 bufferSize, ClientGame& defs) :
displayMode(0) {

View File

@ -4,18 +4,11 @@
#pragma once
#include <sstream>
#include "../graph/window/Window.h"
#include "../graph/drawable/DrawableGroup.h"
#include "../../util/Space.h"
#include "../../util/Util.h"
#include "../../util/Ray.h"
#include "components/compound/GuiLabelledGraph.h"
#include "components/basic/GuiRect.h"
#include "components/basic/GuiGraph.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiContainer.h"
#include "../inventory/ServerInventoryList.h"
class Player;
class ClientGame;
class LocalWorld;
class DebugGui : public GuiContainer {
public:

View File

@ -2,10 +2,9 @@
// Created by aurailus on 2019-12-12.
//
#include <array>
#include "GameGuiBuilder.h"
#include "../../util/Util.h"
#include "components/compound/GuiInventoryList.h"
std::shared_ptr<GuiComponent> GameGuiBuilder::createComponent(LuaGuiElement& elem, glm::ivec2 bounds) {

View File

@ -4,6 +4,7 @@
#include "GuiBuilder.h"
#include "../../util/Util.h"
#include "components/basic/GuiRect.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiModel.h"

View File

@ -4,7 +4,6 @@
#pragma once
#include "../GuiComponent.h"
class GuiContainer : public GuiComponent {

View File

@ -2,8 +2,14 @@
// Created by aurailus on 08/02/19.
//
#include <cmath>
#include "GuiGraph.h"
#include "../../../entity/Model.h"
#include "../../../../def/texture/AtlasRef.h"
#include "../../../graph/meshtypes/EntityMesh.h"
#include "../../../graph/meshtypes/EntityVertex.h"
GuiGraph::GuiGraph(const std::string &key) : GuiComponent(key) {}
void GuiGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <AtlasRef> texture,

View File

@ -4,9 +4,9 @@
#pragma once
#include "../GuiComponent.h"
#include "../../../../def/texture/AtlasRef.h"
class AtlasRef;
class GuiGraph : public GuiComponent {
public:

View File

@ -8,6 +8,8 @@
#include "GuiRect.h"
#include "GuiModel.h"
#include "../../../../def/texture/Font.h"
#include "../../../../def/item/BlockDef.h"
#include "../../../../def/item/CraftItemDef.h"
GuiInventoryItem::GuiInventoryItem(const std::string &key) : GuiContainer(key) {}

View File

@ -5,9 +5,11 @@
#include "GuiModel.h"
#include "../../SerialGui.h"
#include "../../../entity/Model.h"
#include "../../../graph/Renderer.h"
#include "../../../../def/ClientGame.h"
#include "../../../../def/model/ModelStore.h"
#include "../../../../def/texture/TextureAtlas.h"
GuiModel::GuiModel(const std::string &key) : GuiComponent(key) {}

View File

@ -10,6 +10,7 @@
class ClientGame;
class ModelStore;
class TextureAtlas;
class LuaGuiElement;
class GuiModel : public GuiComponent {

View File

@ -5,7 +5,11 @@
#include "GuiRect.h"
#include "../../SerialGui.h"
#include "../../../entity/Model.h"
#include "../../../../util/Util.h"
#include "../../../../def/texture/AtlasRef.h"
#include "../../../../def/texture/TextureAtlas.h"
#include "../../../graph/meshtypes/EntityMesh.h"
GuiRect::GuiRect(const std::string &key) : GuiComponent(key) {}

View File

@ -5,10 +5,11 @@
#pragma once
#include "../GuiComponent.h"
#include "../../../../def/texture/AtlasRef.h"
#include "../../../../lua/api/class/LuaGuiElement.h"
class AtlasRef;
class ClientGame;
class TextureAtlas;
class LuaGuiElement;
class GuiRect : public GuiComponent {
public:

View File

@ -6,6 +6,13 @@
#include "GuiText.h"
#include "../../SerialGui.h"
#include "../../../../util/Util.h"
#include "../../../entity/Model.h"
#include "../../../entity/AnimationSegment.h"
#include "../../../../def/texture/AtlasRef.h"
#include "../../../../def/texture/TextureAtlas.h"
GuiText::GuiText(const std::string &key) : GuiComponent(key) {}
void GuiText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm::vec4 color, Font font) {

View File

@ -4,13 +4,14 @@
#pragma once
#include <utility>
//#include <utility>
#include "../GuiComponent.h"
#include "../../SerialGui.h"
#include "../../../../def/texture/Font.h"
#include "../../../../def/texture/AtlasRef.h"
class TextureAtlas;
class LuaGuiElement;
class GuiText : public GuiComponent {
public:

View File

@ -4,8 +4,11 @@
#include "GuiImageButton.h"
#include "../../../../def/ClientGame.h"
#include "../../SerialGui.h"
#include "../basic/GuiText.h"
#include "../../../entity/Model.h"
#include "../../../../def/ClientGame.h"
#include "../../../../def/texture/AtlasRef.h"
GuiImageButton::GuiImageButton(const std::string &key) : GuiRect(key) {}

View File

@ -4,9 +4,14 @@
#include "GuiInventoryList.h"
#include "../../SerialGui.h"
#include "../basic/GuiRect.h"
#include "../basic/GuiInventoryItem.h"
#include "../../../../def/ClientGame.h"
#include "../../../../def/texture/Font.h"
#include "../../../inventory/LocalInventoryList.cpp"
#include "../../../inventory/LocalInventoryList.h"
#include "../../../inventory/LocalInventoryRefs.h"
#include "../../../inventory/LocalInventoryList.h"
GuiInventoryList::GuiInventoryList(const std::string &key) : GuiContainer(key) {}

View File

@ -4,14 +4,13 @@
#pragma once
#include "../basic/GuiRect.h"
#include "../basic/GuiContainer.h"
#include "../basic/GuiRect.h"
#include "../../SerialGui.h"
#include "../../../../def/ClientGame.h"
#include "../../../inventory/Inventory.h"
#include "../../../inventory/LocalInventoryList.h"
#include "../../../inventory/LocalInventoryRefs.h"
class ClientGame;
class LuaGuiElement;
class LocalInventoryRefs;
class LocalInventoryList;
class GuiInventoryList : public GuiContainer {
public:

View File

@ -4,6 +4,8 @@
#include "InventoryList.h"
#include "../../def/ItemDef.h"
#include "../../def/DefinitionAtlas.h"
#include "../../lua/api/class/LuaItemStack.h"
InventoryList::InventoryList(DefinitionAtlas &defs) : defs(defs) {

View File

@ -5,9 +5,11 @@
#pragma once
#include <string>
#include <sol2/sol.hpp>
#include "ItemStack.h"
#include "../../def/DefinitionAtlas.h"
class DefinitionAtlas;
class InventoryList {
public:

View File

@ -5,6 +5,7 @@
#include "InventoryRefs.h"
#include "ServerInventoryList.h"
#include "../../def/ServerDefinitionAtlas.h"
InventoryRefs::InventoryRefs(ServerDefinitionAtlas &defs, ClientList* clients) :
defs(defs), clients(clients) {}

Some files were not shown because too many files have changed in this diff Show More