Remove cute_headers
parent
b2087fda66
commit
b26126e0fb
|
@ -37,10 +37,6 @@
|
|||
path = lib/gzip-hpp
|
||||
url = git@github.com:mapbox/gzip-hpp.git
|
||||
branch = master
|
||||
[submodule "cute_headers"]
|
||||
path = lib/cute_headers
|
||||
url = git@github.com:RandyGaul/cute_headers.git
|
||||
branch = master
|
||||
[submodule "FastNoise2"]
|
||||
path = lib/FastNoise2
|
||||
url = git@github.com:Auburn/FastNoise2.git
|
||||
|
|
|
@ -43,7 +43,7 @@ add_executable(${MAIN_EXEC_NAME} ${SOURCE_FILES})
|
|||
|
||||
target_include_directories(${MAIN_EXEC_NAME} PUBLIC src)
|
||||
|
||||
target_link_libraries(${MAIN_EXEC_NAME} PUBLIC glfw glm enet glad assimp FastNoise nothings-stb gzip cute_headers nlohmann_json stdc++fs)
|
||||
target_link_libraries(${MAIN_EXEC_NAME} PUBLIC glfw glm enet glad assimp FastNoise nothings-stb gzip nlohmann_json stdc++fs)
|
||||
target_link_libraries(${MAIN_EXEC_NAME} PUBLIC lua sol2)
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
@ -204,16 +204,6 @@ if(NOT TARGET gzip)
|
|||
target_include_directories(gzip INTERFACE gzip-hpp/include)
|
||||
endif()
|
||||
|
||||
#------------------------------
|
||||
# cute_headers
|
||||
# Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
|
||||
#------------------------------
|
||||
if(NOT TARGET cute_headers)
|
||||
project(cute_headers)
|
||||
add_library(cute_headers INTERFACE)
|
||||
target_include_directories(cute_headers INTERFACE cute_headers)
|
||||
endif()
|
||||
|
||||
#--------------------------------
|
||||
# nlohmann JSON
|
||||
# JSON for Modern C++
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 2daadfc0b64491c040d5b9cb011b38dd8d768b6d
|
|
@ -3,11 +3,9 @@
|
|||
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define CUTE_FILES_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <stb_image.h>
|
||||
#include <cute_files.h>
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "Client.h"
|
||||
|
||||
//#include "LocalServerInstance.h"
|
||||
|
||||
#include "util/Types.h"
|
||||
#include "util/Timer.h"
|
||||
//#include "scene/GameScene.h"
|
||||
#include "scene/ConnectScene.h"
|
||||
#include "scene/MainMenuScene.h"
|
||||
|
||||
|
@ -44,5 +39,7 @@ void Client::loop() {
|
|||
|
||||
scene.update();
|
||||
renderer.update(delta);
|
||||
game->textures.update();
|
||||
|
||||
renderer.swapBuffers();
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cute_files.h>
|
||||
#include <client/gui/TextElement.h>
|
||||
|
||||
#include "MenuSandbox.h"
|
||||
|
@ -114,7 +113,6 @@ sol::protected_function_result MenuSandbox::require(sol::this_environment thisEn
|
|||
}
|
||||
|
||||
sol::protected_function_result MenuSandbox::loadFile(const string& path) {
|
||||
std::cout << "load " << path << std::endl;
|
||||
let it = mod.files.find(path);
|
||||
if (it == mod.files.end()) throw sol::error("Error opening '" + path + "', file not found.");
|
||||
let& file = it->second;
|
||||
|
@ -134,7 +132,7 @@ void MenuSandbox::loadMod(const std::filesystem::path& path) {
|
|||
mod = { path, true };
|
||||
|
||||
if (std::filesystem::exists(path / "textures"))
|
||||
menuAssets = client.game->textures.loadDirectory((path / "textures").string(), false, true);
|
||||
menuAssets = client.game->textures.loadDirectory((path / "textures").string(), false);
|
||||
|
||||
loadFile("/main");
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ ConnectScene::ConnectScene(Client& client, Address addr) : Scene(client),
|
|||
}
|
||||
|
||||
void ConnectScene::update() {
|
||||
client.game->textures.update();
|
||||
root.update();
|
||||
|
||||
switch (state) {
|
||||
|
|
|
@ -27,7 +27,6 @@ LuaErrorScene::LuaErrorScene(Client& client, const std::string& err) : Scene(cli
|
|||
}
|
||||
|
||||
void LuaErrorScene::update() {
|
||||
client.game->textures.update();
|
||||
root.update();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cute_files.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "MainMenuScene.h"
|
||||
|
@ -79,8 +78,46 @@ MainMenuScene::MainMenuScene(Client& client) : Scene(client),
|
|||
{ Gui::Prop::SIZE, array<Expr, 2> { Expr("1dp"), Expr("10dp") } },
|
||||
{ Gui::Prop::MARGIN, array<Expr, 4> { Expr("2dp"), Expr("3dp"), Expr("2dp"), Expr("3dp") } }
|
||||
}});
|
||||
|
||||
findSubgames();
|
||||
|
||||
let subgamesPath = std::filesystem::path("..") / "subgames";
|
||||
std::filesystem::directory_iterator iter(subgamesPath);
|
||||
|
||||
for (let& file : iter) {
|
||||
if (!file.is_directory()) continue;
|
||||
|
||||
try {
|
||||
if (!std::filesystem::exists(file.path() / "conf.json")) throw std::runtime_error("Missing a conf.json");
|
||||
if (!std::filesystem::exists(file.path() / "mods")) throw std::runtime_error("Missing a mods folder");
|
||||
|
||||
nlohmann::json json {};
|
||||
try {
|
||||
std::ifstream(file.path() / "conf.json") >> json;
|
||||
}
|
||||
catch (...) {
|
||||
throw std::runtime_error("conf.json has a syntax error");
|
||||
}
|
||||
|
||||
if (!json.is_object())
|
||||
throw std::runtime_error("conf.json has a syntax error.");
|
||||
if (!json["name"].is_string() || json["name"] == "")
|
||||
throw std::runtime_error("conf.json is missing 'name'");
|
||||
if (!json["version"].is_string() || json["version"] == "")
|
||||
throw std::runtime_error("conf.json is missing 'version'");
|
||||
|
||||
const let icon = std::filesystem::exists(file.path() / "icon.png")
|
||||
? client.game->textures.loadImage((file.path() / "icon.png").string(), json["name"])
|
||||
: client.game->textures["menu_flag_missing"];
|
||||
|
||||
subgames.push_back({ icon, { json["name"], json["description"], json["version"] }, file.path().string() });
|
||||
}
|
||||
catch(const std::runtime_error& e) {
|
||||
std::cout << Log::err << "Failed to load subgame '"
|
||||
<< file.path().filename().string() << "', " << e.what() << "." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(subgames.begin(), subgames.end(),
|
||||
[](SubgameDef& a, SubgameDef& b) { return a.config.name < b.config.name; });
|
||||
|
||||
for (usize i = 0; i < subgames.size(); i++) {
|
||||
let& subgame = subgames[i];
|
||||
|
@ -123,82 +160,8 @@ MainMenuScene::MainMenuScene(Client& client) : Scene(client),
|
|||
});
|
||||
}
|
||||
|
||||
void MainMenuScene::findSubgames() {
|
||||
string subgamesPath = "../subgames";
|
||||
|
||||
cf_dir_t subgamesDir;
|
||||
cf_dir_open(&subgamesDir, subgamesPath.data());
|
||||
while (subgamesDir.has_next) {
|
||||
cf_file_t subgameFolder;
|
||||
cf_read_file(&subgamesDir, &subgameFolder);
|
||||
if (!subgameFolder.is_dir || strncmp(subgameFolder.name, ".", 1) == 0) {
|
||||
cf_dir_next(&subgamesDir);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
bool hasConf = false, hasIcon = false, hasMods = false;
|
||||
|
||||
cf_dir_t subgame;
|
||||
cf_dir_open(&subgame, subgameFolder.path);
|
||||
while (subgame.has_next) {
|
||||
cf_file_t file;
|
||||
cf_read_file(&subgame, &file);
|
||||
|
||||
if (!file.is_dir && strncmp(file.name, "icon.png\0", 9) == 0) hasIcon = true;
|
||||
if (!file.is_dir && strncmp(file.name, "conf.json\0", 10) == 0) hasConf = true;
|
||||
if (file.is_dir && strncmp(file.name, "mods\0", 5) == 0) hasMods = true;
|
||||
|
||||
cf_dir_next(&subgame);
|
||||
}
|
||||
cf_dir_close(&subgame);
|
||||
|
||||
if (!hasConf) throw std::runtime_error(
|
||||
string("Subgame ") + string(subgameFolder.name) + " is missing a conf.json.");
|
||||
if (!hasMods) throw std::runtime_error(
|
||||
string("Subgame ") + string(subgameFolder.name) + " is missing a 'mods' directory.");
|
||||
|
||||
nlohmann::json j{};
|
||||
try {
|
||||
std::ifstream(string(subgameFolder.path) + "/conf.json") >> j;
|
||||
}
|
||||
catch (...) {
|
||||
throw std::runtime_error(string(subgameFolder.name) + "/conf.json is not a valid JSON object.");
|
||||
}
|
||||
|
||||
if (!j.is_object())
|
||||
throw std::runtime_error(string(subgameFolder.name) + "/conf.json is not a valid JSON object.");
|
||||
if (!j["name"].is_string() || j["name"] == "")
|
||||
throw std::runtime_error(
|
||||
"The 'name' property in " + string(subgameFolder.name) + "/conf.json is missing or invalid.");
|
||||
if (!j["version"].is_string() || j["version"] == "")
|
||||
throw std::runtime_error("The 'version' property in " + string(subgameFolder.name) +
|
||||
"/conf.json is missing or invalid.");
|
||||
|
||||
string name = j["name"];
|
||||
string description = (j["description"].is_string() ? j["description"] : "");
|
||||
string version = j["version"];
|
||||
|
||||
std::shared_ptr<AtlasRef> icon = client.game->textures["menu_flag_missing"];
|
||||
if (hasIcon) icon = client.game->textures.loadImage(string(subgameFolder.path) + "/icon.png", name);
|
||||
|
||||
subgames.push_back({ icon, { name, description, version }, subgameFolder.path });
|
||||
}
|
||||
catch (const std::runtime_error& e) {
|
||||
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e.what() << Log::endl;
|
||||
}
|
||||
|
||||
cf_dir_next(&subgamesDir);
|
||||
}
|
||||
cf_dir_close(&subgamesDir);
|
||||
|
||||
std::sort(subgames.begin(), subgames.end(),
|
||||
[](SubgameDef& a, SubgameDef& b) { return a.config.name < b.config.name; });
|
||||
}
|
||||
|
||||
void MainMenuScene::update() {
|
||||
root.update();
|
||||
client.game->textures.update();
|
||||
sandbox.update(client.getDelta());
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "Scene.h"
|
||||
|
||||
#include "util/Types.h"
|
||||
#include "client/Window.h"
|
||||
#include "client/gui/Root.h"
|
||||
#include "client/menu/SubgameDef.h"
|
||||
#include "client/menu/MenuSandbox.h"
|
||||
|
@ -24,9 +23,7 @@ public:
|
|||
void draw() override;
|
||||
|
||||
private:
|
||||
/** Find valid subgames in the subgames folder. */
|
||||
void findSubgames();
|
||||
|
||||
|
||||
/** The GUI root. */
|
||||
Gui::Root root;
|
||||
|
||||
|
|
|
@ -41,5 +41,4 @@ void LocalSubgame::init(WorldPtr world, PlayerPtr player, Client& client) {
|
|||
|
||||
void LocalSubgame::update(double delta) {
|
||||
lua->update(delta);
|
||||
textures.update();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
//
|
||||
// Created by aurailus on 10/06/19.
|
||||
//
|
||||
|
||||
#include <cute_files.h>
|
||||
|
||||
#include "ServerSubgame.h"
|
||||
|
||||
#include "server/ServerClients.h"
|
||||
|
@ -15,7 +9,7 @@ ServerSubgame::ServerSubgame(const string& subgame, usize seed) :
|
|||
lua(make_unique<ServerLuaParser>(*this)) {
|
||||
|
||||
if (subgame.empty()) throw std::runtime_error("No subgame specified.");
|
||||
if (!cf_file_exists(subgamePath.data())) throw std::runtime_error("Subgame does not exist.");
|
||||
if (!std::filesystem::exists(subgamePath)) throw std::runtime_error("Subgame does not exist.");
|
||||
}
|
||||
|
||||
void ServerSubgame::init(WorldPtr world) {
|
||||
|
@ -25,5 +19,3 @@ void ServerSubgame::init(WorldPtr world) {
|
|||
void ServerSubgame::update(double delta) {
|
||||
lua->update(delta);
|
||||
}
|
||||
|
||||
ServerSubgame::~ServerSubgame() {}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
ServerSubgame(const string& subgame, usize seed);
|
||||
|
||||
~ServerSubgame();
|
||||
~ServerSubgame() {};
|
||||
|
||||
void init(WorldPtr world);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <stb_image.h>
|
||||
#include <cute_files.h>
|
||||
|
||||
#include "TextureAtlas.h"
|
||||
|
||||
|
@ -81,27 +81,12 @@ TextureAtlas::TextureAtlas(uvec2 size) :
|
|||
createMissingTexture();
|
||||
}
|
||||
|
||||
vec<sptr<AtlasRef>> TextureAtlas::loadDirectory(const string& path, bool base, bool recurse) {
|
||||
vec<sptr<AtlasRef>> TextureAtlas::loadDirectory(const string& path, bool base) {
|
||||
vec<sptr<AtlasRef>> refs {};
|
||||
|
||||
cf_dir_t dir;
|
||||
cf_dir_open(&dir, (path).c_str());
|
||||
|
||||
while (dir.has_next) {
|
||||
cf_file_t file;
|
||||
cf_read_file(&dir, &file);
|
||||
std::string_view name = file.name;
|
||||
|
||||
if (!file.is_dir && strcmp(file.ext, ".png") == 0)
|
||||
refs.push_back(loadImage(file.path, string(name.substr(0, name.size() - 4)), base));
|
||||
|
||||
if (recurse && file.is_dir && name.data()[0] != '.') {
|
||||
let vec = loadDirectory(file.path, base, true);
|
||||
refs.insert(refs.end(), vec.begin(), vec.end());
|
||||
}
|
||||
cf_dir_next(&dir);
|
||||
}
|
||||
cf_dir_close(&dir);
|
||||
for (let file : std::filesystem::recursive_directory_iterator(path))
|
||||
if (file.path().extension() == ".png") refs.push_back(
|
||||
loadImage(file.path().string(), file.path().stem().string(), base));
|
||||
|
||||
return refs;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
void update();
|
||||
|
||||
vec<sptr<AtlasRef>> loadDirectory(const string& path, bool base = true, bool recurse = true);
|
||||
vec<sptr<AtlasRef>> loadDirectory(const string& path, bool base = true);
|
||||
|
||||
sptr<AtlasRef> loadImage(const string& path, const string& name, bool base = false);
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
Mod::Mod(const std::filesystem::path& path, bool noConfig) {
|
||||
nlohmann::json json {};
|
||||
|
||||
std::ifstream(path / "conf.json") >> json;
|
||||
|
||||
rawPath = path;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "FileManipulator.h"
|
||||
|
||||
|
@ -104,7 +105,7 @@ void FileManipulator::createRegionFileIfNotExists(glm::ivec3 pos) {
|
|||
std::string fileName = std::to_string(pos.x) + "_" + std::to_string(pos.y) + "_" + std::to_string(pos.z);
|
||||
std::string filePath = path + fileName;
|
||||
|
||||
if (cf_file_exists(filePath.data())) return;
|
||||
if (std::filesystem::exists(filePath.data())) return;
|
||||
|
||||
std::fstream file(filePath, std::ios::out | std::ios::binary);
|
||||
if (!file.is_open()) throw std::runtime_error("Couldn't open file.");
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <array>
|
||||
#include <string>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <cute_files.h>
|
||||
|
||||
class Chunk;
|
||||
|
||||
|
|
|
@ -124,14 +124,14 @@ table.insert(structures, zepha.create_structure({
|
|||
for i = 1, 5 do
|
||||
table.insert(structures, zepha.create_structure({
|
||||
origin = V(),
|
||||
probability = 0.025,
|
||||
probability = 0.05,
|
||||
layout = {{{ "zeus:default:tall_grass_" .. tostring(i) }}}
|
||||
}))
|
||||
end
|
||||
|
||||
table.insert(structures, zepha.create_structure({
|
||||
origin = V(),
|
||||
probability = 0.35,
|
||||
probability = 0.55,
|
||||
layout = {{{ "zeus:flowers:clover" }}}
|
||||
}))
|
||||
table.insert(structures, zepha.create_structure({
|
||||
|
|
Loading…
Reference in New Issue