Commit 53ba3c7b authored by Johannes Braun's avatar Johannes Braun
Browse files

Made Project fully self-contained even after build and fixed game executable

parent f79061d1
#ifndef __GLARE_INCLUDE_CORE
#define __GLARE_INCLUDE_CORE
//Core Main
#include <core/time.h>
#include <core/window.h>
#include <core/state.h>
#include <util/console.h>
//Core Animation
#include <core/anim/animations.h>
//Core Graphics
#include <core/res/fonts.h>
#include <core/res/texture2d.h>
#include <core/base/framebuffer.h>
#include <core/base/program.h>
#include <core/base/shader.h>
#include <core/base/buffer.h>
#include <core/objects/camera.h>
#include <core/objects/light.h>
#include <core/objects/material.h>
#include <core/objects/mesh.h>
#include <core/objects/skybox.h>
#include <core/rendering/mesh_renderer.h>
#include <core/rendering/gbuffer.h>
#include <core/rendering/texture_renderer.h>
#endif //!__GLARE_INCLUDE_CORE
\ No newline at end of file
#ifndef __GLARE_INCLUDE_GUI
#define __GLARE_INCLUDE_GUI
#ifdef GLARE_LEGACY_GUI
#include <gui/CanvasNodeComponent.h>
#include <gui/CanvasView.h>
#include <gui/CanvasViewGroup.h>
#include <gui/GuiImage.h>
#include <gui/Image.h>
#include <gui/LayoutInflater.h>
#include <gui/LinearLayout.h>
#include <gui/TextView.h>
#include <gui/ViewUtilities.h>
#include <gui/DrawList.h>
#include <gui/GUI.h>
#include <gui/drawables/RoundedRectangle.h>
#include <gui/drawables/RoundedRectangleMask.h>
#include <gui/widgets/Panel.h>
#else
#include <imgui/imgui_glfw.h>
#endif
#endif //!__GLARE_INCLUDE_GUI
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include <core/state.h>
#include <core/rendering/gbuffer.h>
#include <core/rendering/batch_renderer.h>
#include <core/objects/skybox.h>
#include <core/objects/light.h>
#include <core/res/res.h>
......@@ -19,8 +20,8 @@ const fs::path skybox_files_path = files::asset("/textures/ryfjallet/");
int main(int argc, char* argv[])
{
core::state::initialize(engine_settings_path);
core::state::skybox->reset(core::Skybox::collectFilesFrom(skybox_files_path));
core::Context::createAsCurrent(engine_settings_path);
core::Context::current().skybox()->reset(skybox_files_path);
// Load the map
game::Map map(files::asset("/maps/test01/map.xml"));
......@@ -28,38 +29,39 @@ int main(int argc, char* argv[])
// Build node tree
{
// custom camera
auto cam_node = std::make_shared<core::GraphNode>("custom_camera");
cam_node->addComponent(core::state::camera);
auto cam_node = std::make_shared<core::SceneNode>("custom_camera");
cam_node->addComponent(core::Context::current().camera());
cam_node->makeComponent<component::PlayerController>();
cam_node->makeComponent<component::FramerateCounter>();
//Attach plane as child in front of the camera.
auto plane = core::global_resources::scenes.get(files::asset("meshes/scenery/cbox.dae"), 1.0f)->find("#Cube_001-mesh");
auto plane = core::global_resources::scenes.get(files::asset("meshes/scenery/cube.dae"), 1.0f)->find("#Cube-mesh");
cam_node->attach(plane);
plane->transform.position = { 0, -2.f, -15 };
plane->transform.rotate({ glm::radians(-90.f), glm::radians(90.f), 0.f });
// add the terrain
auto terrain_node = std::make_shared<core::GraphNode>("terrain");
terrain_node->addComponent(map.getMesh());
auto terrain_node = std::make_shared<core::SceneNode>("terrain");
auto renderer = terrain_node->makeComponent<core::BatchRenderer>();
renderer->setDrawable(map.getMesh());
//Initialize root node
core::state::graph_root->attach(terrain_node);
core::state::graph_root->attach(cam_node);
core::Context::current().graph()->attach(terrain_node);
core::Context::current().graph()->attach(cam_node);
}
// Sun light source
auto sun_node = std::make_shared<core::GraphNode>("light_sun");
auto sun_node = std::make_shared<core::SceneNode>("light_sun");
sun_node->transform.rotate({ glm::radians(80.f), 0, 0 });
auto light_sun = sun_node->makeComponent<core::LightComponent>(color::rgba32f{ 0.4f, 0.4f, 0.4f, 1.f }, core::LightParameters::makeDirectionalLight(0.1f));
// Make Environment lighting node
auto lighting_node = std::make_shared<core::GraphNode>("environment");
auto lighting_node = std::make_shared<core::SceneNode>("environment");
lighting_node->attach(sun_node);
core::state::graph_root->attach(lighting_node);
core::Context::current().graph()->attach(lighting_node);
// Start it up!
glare::core::state::mainLoop([&]()
core::Context::current().loop([&]()
{
// Rotate the sun on keypress
if (controls::keyState(controls::Key::eF) == controls::ButtonAction::ePress) {
......@@ -67,11 +69,9 @@ int main(int argc, char* argv[])
}
// Set the light position to the player camera position
lighting_node->transform.position = core::state::camera->owner()->transform.position * glm::vec3(1, 0, 1);
core::state::gbuffer->activate();
glare::core::state::graph_root->draw();
core::state::gbuffer->draw();
lighting_node->transform.position = core::Context::current().camera()->owner()->transform.position * glm::vec3(1, 0, 1);
core::Context::current().draw(core::Context::DrawMode::eGBuffer);
});
return 0;
......
#include "map.h"
#include <pugixml/pugixml.hpp>
#include <core/res/resources.h>
#include <core/res/res.h>
#include <util/color.h>
#include <util/files.h>
#include <core/res/texture2d.h>
#include <core/res/image.h>
namespace glare
{
......@@ -37,28 +37,28 @@ namespace glare
m_team_to_pcolor.emplace(team_id, mapto_color);
}
auto data = core::textures::loadData<core::TextureDataRGBA_32F>(m_heightmap_path);
core::Image<float> data(m_heightmap_path);
m_width = unsigned(data->width());
m_height = unsigned(data->height());
m_width = unsigned(data.width());
m_height = unsigned(data.height());
m_heights.resize(data->width() + 1);
m_heights.resize(data.width() + 1);
for (int x = 0; x < int(data->width()) + 1; ++x) {
m_heights[x].resize(int(data->height()) + 1);
for (int y = 0; y < int(data->height()) + 1; ++y) {
if (int(data->width()) == x || int(data->height()) == y) {
m_heights[x][y] = data->get({ glm::max(0, x - 1), glm::max(y - 1, 0) }).r*m_height_scale;
for (int x = 0; x < int(data.width()) + 1; ++x) {
m_heights[x].resize(int(data.height()) + 1);
for (int y = 0; y < int(data.height()) + 1; ++y) {
if (int(data.width()) == x || int(data.height()) == y) {
m_heights[x][y] = std::get<0>(data[{ glm::max(0, x - 1), glm::max(y - 1, 0) }])*m_height_scale;
}
else
{
m_heights[x][y] = data->get({ x, y }).r*m_height_scale;
m_heights[x][y] = std::get<0>(data[{x, y}])*m_height_scale;
}
}
}
}
std::shared_ptr<core::MeshRenderer> Map::getMesh(bool rebuild)
std::shared_ptr<core::MeshDrawable> Map::getMesh(bool rebuild)
{
if (!rebuild && m_mesh_renderer)
{
......@@ -242,10 +242,10 @@ namespace glare
}
}
auto mesh = std::make_shared<core::Mesh>(m_vertices, m_indices);
m_mesh_renderer = std::make_shared<core::MeshRenderer>(mesh, makeMaterial());
m_mesh_renderer = std::make_shared<core::MeshDrawable>();
m_mesh_renderer->mesh = std::make_shared<core::Mesh>(m_vertices, m_indices);
m_mesh_renderer->material = makeMaterial();
return m_mesh_renderer;
}
......@@ -255,10 +255,10 @@ namespace glare
std::shared_ptr<core::Material> material = std::make_shared<core::Material>("terrain");
material->base.value = color::preset::white.rgb;
material->roughness.value = 0.2f;
material->base.texture = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048.png"));
material->map_normal = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_n.png"));
material->map_displacement = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_h.png"));
material->roughness.texture = core::Resources::getInstance().getTexture(files::asset("meshes/scenery/gravel_medium2048_s.png"));
/*material->base.texture = core::global_resources::textures.get(files::asset("meshes/scenery/gravel_medium2048.png"));
material->map_normal = core::global_resources::textures.get(files::asset("meshes/scenery/gravel_medium2048_n.png"));
material->map_displacement = core::global_resources::textures.get(files::asset("meshes/scenery/gravel_medium2048_h.png"));
material->roughness.texture = core::global_resources::textures.get(files::asset("meshes/scenery/gravel_medium2048_s.png"));*/
return material;
}
......
......@@ -4,7 +4,7 @@
#include <filesystem>
#include <map>
#include <core/rendering/mesh_renderer.h>
#include <core/rendering/mesh_drawable.h>
namespace glare
{
......@@ -17,14 +17,14 @@ namespace glare
public:
Map(const fs::path &path);
std::shared_ptr<core::MeshRenderer> getMesh(bool rebuild = true);
std::shared_ptr<core::MeshDrawable> getMesh(bool rebuild = true);
glm::vec3 getSectorCenter(unsigned x, unsigned z) const;
private:
std::shared_ptr<core::Material> makeMaterial() const;
std::shared_ptr<core::MeshRenderer> m_mesh_renderer;
std::shared_ptr<core::MeshDrawable> m_mesh_renderer;
std::vector<std::vector<float>> m_heights;
std::string m_version;
......
......@@ -197,13 +197,14 @@ namespace glare::core
assert(m_samples == 0);
assert(pixel.size() == m_extents.size());
if (m_data.empty()) throw std::out_of_range("This texture has no data. Cannot fetch a pixel for an empty texture.");
glm::ivec3 position(pixel.width, pixel.height, pixel.depth);
if (pixel.size() <= 1) pixel.height = 0;
if (pixel.size() <= 2) pixel.depth = 0;
// Debug bounds check.
assert(position.x >= 0 && position.x < m_extents.width);
assert(position.y >= 0 && position.y < m_extents.height);
assert(position.z >= 0 && position.z < m_extents.depth);
assert(pixel.width >= 0 && pixel.width < m_extents.width);
assert(pixel.height >= 0 && pixel.height < m_extents.height);
assert(pixel.depth >= 0 && pixel.depth < m_extents.depth);
glm::tvec4<TBase> result(0);
for (int i = 0; i < m_components; ++i)
......@@ -213,13 +214,13 @@ namespace glare::core
}
m_ignore = 0;
auto get = [this](const glm::ivec3 position, int offset) -> TBase&
auto get = [this, &pixel](int offset) -> TBase&
{
return offset >= m_components ? m_ignore : m_data[m_extents.linearize(pixel)*m_components + offset];
};
return std::tie(get(position, 0), get(position, 1), get(position, 2), get(position, 3));
return std::tie(get(0), get(1), get(2), get(3));
}
template <typename TBase>
......
......@@ -258,6 +258,8 @@ namespace ImGui {
m_wrapper.reset(new ImGuiWrapper);
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = "../assets/imgui/config.ini";
io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
......
......@@ -6,12 +6,12 @@ namespace files
{
fs::path asset(fs::path path) noexcept
{
return fs::path(ASSETS_PATH) / path;
return fs::current_path() / fs::path("../assets") / path;
}
fs::path shader(fs::path path) noexcept
{
return fs::path(ASSETS_PATH) / "shaders" / path;
return fs::current_path() / fs::path("../assets/shaders") / path;
}
fs::path relative(fs::path base, fs::path relative_to)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment