Compare commits
7 Commits
4ebd63f9ea
...
e3c11e064f
Author | SHA1 | Date | |
---|---|---|---|
e3c11e064f | |||
1ef6bc560e | |||
966fe26e10 | |||
50c5238219 | |||
c1afe4de62 | |||
0561ed005a | |||
7b633a6a63 |
Binary file not shown.
Before ![]() (image error) Size: 682 B |
BIN
res/textures/bricks.png
Normal file
BIN
res/textures/bricks.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 314 B |
Binary file not shown.
Before ![]() (image error) Size: 376 B |
BIN
res/textures/dirt.png
Normal file
BIN
res/textures/dirt.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 234 B |
Binary file not shown.
Before ![]() (image error) Size: 423 B After ![]() (image error) Size: 226 B ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 857 B |
BIN
res/textures/leaves.png
Normal file
BIN
res/textures/leaves.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 301 B |
Binary file not shown.
Before ![]() (image error) Size: 685 B |
Binary file not shown.
Before ![]() (image error) Size: 692 B |
BIN
res/textures/stone.png
Normal file
BIN
res/textures/stone.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 188 B |
BIN
res/textures/wood.png
Normal file
BIN
res/textures/wood.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 232 B |
19
src/game/ecs/base_component.hpp
Normal file
19
src/game/ecs/base_component.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef POLYGUN_ECS_BASE_COMPONENT_HPP
|
||||
#define POLYGUN_ECS_BASE_COMPONENT_HPP
|
||||
|
||||
#include "ecs_types.hpp"
|
||||
|
||||
namespace polygun::ecs {
|
||||
struct BaseComponent {
|
||||
BaseComponent() = default;
|
||||
~BaseComponent() = default;
|
||||
|
||||
inline const EntityID get_id() const { return m_entity_id; }
|
||||
|
||||
private:
|
||||
EntityID m_entity_id = -1;
|
||||
friend class EntityManager;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_ECS_BASE_COMPONENT_HPP
|
36
src/game/ecs/base_system.hpp
Normal file
36
src/game/ecs/base_system.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef POLYGUN_ECS_BASE_SYSTEM_HPP
|
||||
#define POLYGUN_ECS_BASE_SYSTEM_HPP
|
||||
|
||||
#include "ecs_types.hpp"
|
||||
|
||||
namespace polygun::ecs {
|
||||
|
||||
class BaseSystem {
|
||||
public:
|
||||
BaseSystem() = default;
|
||||
virtual ~BaseSystem() = default;
|
||||
|
||||
inline const Signature get_signature() const { return m_signature; }
|
||||
|
||||
inline void erase_entity(const EntityID entity) { m_entities.erase(entity); }
|
||||
inline void push_entity(const EntityID entity) { m_entities.insert(entity); }
|
||||
|
||||
template<typename T>
|
||||
inline void add_component_signature() { m_signature.insert(CompType<T>()); }
|
||||
|
||||
inline const bool is_empty() const { return (m_entities.size() == 0);}
|
||||
inline const bool has_entity(EntityID entity) const { return (m_entities.count(entity) > 0);}
|
||||
|
||||
virtual void stop() {}
|
||||
virtual void start() {}
|
||||
virtual void render() {}
|
||||
virtual void update() {}
|
||||
virtual void awake() {}
|
||||
|
||||
protected:
|
||||
Signature m_signature;
|
||||
std::set<EntityID> m_entities;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_ECS_BASE_SYSTEM_HPP
|
60
src/game/ecs/component_factory.hpp
Normal file
60
src/game/ecs/component_factory.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef POLYGUN_ECS_BASE_COMPONENT_HPP
|
||||
#define POLYGUN_ECS_BASE_COMPONENT_HPP
|
||||
|
||||
#include "base_component.hpp"
|
||||
#include "game/core.hpp"
|
||||
|
||||
namespace polygun::ecs {
|
||||
|
||||
using Constructor = std::function<FactoryType()>;
|
||||
|
||||
class ComponentFactory {
|
||||
|
||||
public:
|
||||
~ComponentFactory() = default;
|
||||
ComponentFactory(const ComponentFactory&) = delete;
|
||||
ComponentFactory& operator=(const ComponentFactory&) = delete;
|
||||
static ComponentFactory& ref() {
|
||||
static ComponentFactory reference;
|
||||
return reference;
|
||||
}
|
||||
|
||||
auto create_component(const char* type_name) {
|
||||
auto it = m_registry_funcs.find(type_name);
|
||||
assert(it != m_registry_funcs.end() && "Component Type not found in registry");
|
||||
auto component = it->second();
|
||||
return component;
|
||||
}
|
||||
|
||||
void register_type(ComponentTypeID comp_type, const char* type_name, Constructor callback) {
|
||||
m_registry_funcs[type_name] = callback;
|
||||
m_registry_types[type_name] = comp_type;
|
||||
}
|
||||
|
||||
const ComponentTypeID get_type_id(const char* type_name) {
|
||||
assert(m_registry_types.find(type_name) != m_registry_types.end() && "Typename out of range");
|
||||
return m_registry_types.at(type_name);
|
||||
}
|
||||
|
||||
private:
|
||||
ComponentFactory() = default;
|
||||
|
||||
private:
|
||||
std::map<const char*, Constructor> m_registry_funcs;
|
||||
std::map<const char*, ComponentTypeID> m_registry_types;
|
||||
};
|
||||
|
||||
static ComponentFactory& CompFactory = ComponentFactory::ref();
|
||||
|
||||
template<typename T>
|
||||
class Registrar {
|
||||
public:
|
||||
Registrar(const char* type_name) {
|
||||
const ComponentTypeID comp_type = CompType<T>();
|
||||
CompFactory.register_type(comp_type, type_name, []()->FactoryType{ return std::move(std::make_shared<T>()); });
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // POLYGUN_ECS_BASE_COMPONENT_HPP
|
53
src/game/ecs/component_list.hpp
Normal file
53
src/game/ecs/component_list.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef POLYGUN_ECS_COMP_LIST_HPP
|
||||
#define POLYGUN_ECS_COMP_LIST_HPP
|
||||
|
||||
#include "ecs_types.hpp"
|
||||
|
||||
namespace polygun::ecs {
|
||||
|
||||
class ICompList {
|
||||
public:
|
||||
ICompList() = default;
|
||||
virtual ~ICompList() = default;
|
||||
virtual void erase(const EntityID entity) { }
|
||||
virtual void insert(BaseComponent* component) { }
|
||||
const ComponentTypeID get_data_type() const { return m_type_id; }
|
||||
protected:
|
||||
ComponentTypeID m_type_id = INVALID_TYPE_ID;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CompList : public ICompList {
|
||||
|
||||
public:
|
||||
~CompList() = default;
|
||||
CompList(): m_data({}) {
|
||||
m_type_id = CompType<T>();
|
||||
}
|
||||
|
||||
void insert(BaseComponent* component) override {
|
||||
T comp = *(static_cast<T*>(component));
|
||||
auto it = std::find_if(m_data.begin(), m_data.end(), [&comp](const T& c) { return c.get_id() == comp.get_id(); });
|
||||
assert(it == m_data.end() && "Trying to insert duplicate of component!");
|
||||
m_data.push_back(comp);
|
||||
}
|
||||
|
||||
T& get(const EntityID entity) {
|
||||
auto it = std::find_if(m_data.begin(), m_data.end(), [&](const T& comp) { return comp.get_id() == entity; });
|
||||
assert(it != m_data.end() && "Trying to get non-existing component!");
|
||||
return *it;
|
||||
}
|
||||
|
||||
void erase(const EntityID entity) override {
|
||||
auto it = std::find_if(m_data.begin(), m_data.end(), [&entity](const T& comp) { return comp.get_id() == entity; });
|
||||
if (it != m_data.end()) {
|
||||
m_data.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T> m_data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // POLYGUN_ECS_COMP_LIST_HPP
|
49
src/game/ecs/ecs_types.hpp
Normal file
49
src/game/ecs/ecs_types.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef POLYGUN_ECS_TYPES_HPP
|
||||
#define POLYGUN_ECS_TYPES_HPP
|
||||
|
||||
#include "game/core.hpp"
|
||||
|
||||
namespace polygun::ecs {
|
||||
|
||||
class Entity;
|
||||
class BaseSystem;
|
||||
class BaseComponent;
|
||||
class EntityManager;
|
||||
|
||||
// global constantes
|
||||
constexpr int INVALID_TYPE_ID = 0;
|
||||
constexpr int INVALID_ENTITY = -1;
|
||||
constexpr int MAX_COMP_COUNT = 32;
|
||||
constexpr int MAX_ENTITY_COUNT = 5000;
|
||||
|
||||
// typedefs
|
||||
using EntityID = int;
|
||||
using SystemTypeID = int;
|
||||
using ComponentTypeID = int;
|
||||
using Signature = std::set<ComponentTypeID>;
|
||||
using FactoryType = std::shared_ptr<BaseComponent>;
|
||||
using EntityList = std::vector<Entity>;
|
||||
using EntityIDList = std::vector<EntityID>;
|
||||
|
||||
// Runtime type
|
||||
inline int get_runtime_type_id() {
|
||||
static int type_id = 1u;
|
||||
return type_id++;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline SystemTypeID system_type() noexcept {
|
||||
static_assert((std::is_base_of<BaseSystem, T>::value && !std::is_same<BaseSystem, T>::value), "Invalid template type");
|
||||
static const SystemTypeID type_id = get_runtime_type_id();
|
||||
return type_id;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline ComponentTypeID comp_type() noexcept {
|
||||
static_assert((std::is_base_of<BaseComponent, T>::value && !std::is_same<BaseComponent, T>::value), "Invalid template type");
|
||||
static const ComponentTypeID type_id = get_runtime_type_id();
|
||||
return type_id;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // POLYGUN_ECS_TYPES_HPP
|
@ -1,3 +1,27 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "engine.hpp"
|
||||
|
||||
#include "game/audio/audio.hpp"
|
||||
|
@ -1,3 +1,27 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_ENGINE_HPP
|
||||
#define POLYGUN_ENGINE_HPP
|
||||
|
||||
|
@ -2,8 +2,129 @@
|
||||
|
||||
namespace polygun::engine {
|
||||
cuboid_list greedy_merging::merge(world::Chunk& chunk) {
|
||||
// code here
|
||||
//cuboid_list list; EXAMPLE
|
||||
//return list;
|
||||
|
||||
// create copy of chunk
|
||||
world::Chunk chunk_copy = chunk;
|
||||
|
||||
cuboid_list cuboids;
|
||||
cuboid cuboid_to_append;
|
||||
|
||||
for (y = 0; y < voxel_count; y++) {
|
||||
for (z = 0; z < voxel_count; z++) {
|
||||
last_material = 0;
|
||||
|
||||
for (x = 0; x < voxel_count; x++) {
|
||||
cuboid_ended = false;
|
||||
|
||||
// if material changed
|
||||
if (chunk_copy.get_node(glm::vec3(z, y, x)) != last_material) {
|
||||
// if cuboid ended
|
||||
// material switch NOT from air
|
||||
if (last_material != 0) {
|
||||
cuboid_end_x = x;
|
||||
cuboid_ended = true;
|
||||
}
|
||||
|
||||
// if new cuboid just started AND NOT cuboid ended while new one starting
|
||||
if (chunk_copy.get_node(glm::vec3(z, y, x)) != 0 && !cuboid_ended) {
|
||||
cuboid_start_x = x;
|
||||
}
|
||||
}
|
||||
|
||||
// if cuboid ended
|
||||
// end of map row on NOT air
|
||||
if (x == voxel_max_idx && chunk_copy.get_node(glm::vec3(z, y, x)) != 0) {
|
||||
cuboid_end_x = x + 1;
|
||||
cuboid_ended = true;
|
||||
last_material = chunk_copy.get_node(glm::vec3(z, y, x));
|
||||
}
|
||||
|
||||
if (cuboid_ended) {
|
||||
// scanning for other rows under existing row that can be included in the cuboid
|
||||
cuboid_end_z = z;
|
||||
invalid_row = false;
|
||||
while (true) {
|
||||
cuboid_end_z++;
|
||||
|
||||
// if the end of the map is reached, break the loop
|
||||
if (cuboid_end_z == voxel_count) {
|
||||
break;
|
||||
}
|
||||
|
||||
// check if all materials in row are the same as the cuboid's material
|
||||
for (x_s = cuboid_start_x; x_s < cuboid_end_x; x_s++) {
|
||||
if (chunk_copy.get_node(glm::vec3(cuboid_end_z, y, x_s)) != last_material) {
|
||||
invalid_row = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (invalid_row) {
|
||||
break;
|
||||
}
|
||||
|
||||
// set all values of next row that will be added to the cuboid to 0 to prevent them from being treated as a new cuboid in the next z loop iteration
|
||||
for (x_s = cuboid_start_x; x_s < cuboid_end_x; x_s++) {
|
||||
chunk_copy.add_node(0, glm::vec3(cuboid_end_z, y, x_s));
|
||||
}
|
||||
}
|
||||
|
||||
// x, z sizes have been found. now check the size of the y axis
|
||||
cuboid_end_y = y;
|
||||
invalid_plane = false;
|
||||
while (true) {
|
||||
cuboid_end_y++;
|
||||
|
||||
// if the end of the map is reached, break the loop
|
||||
if (cuboid_end_y == voxel_count) {
|
||||
break;
|
||||
}
|
||||
|
||||
// check if all materials in a "plane" under the current cuboid are the same as the cuboid's material
|
||||
for (z_s = z; z_s < cuboid_end_z; z_s++) {
|
||||
for (x_s = cuboid_start_x; x_s < cuboid_end_x; x_s++) {
|
||||
if (chunk_copy.get_node(glm::vec3(z_s, cuboid_end_y, x_s)) != last_material) {
|
||||
invalid_plane = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invalid_plane) {
|
||||
break;
|
||||
}
|
||||
|
||||
// set all values of next plane that will be added to the cuboid to 0 to prevent them from being treated as a new cuboid in the next y loop iteration
|
||||
for (z_s = z; z_s < cuboid_end_z; z_s++) {
|
||||
for (x_s = cuboid_start_x; x_s < cuboid_end_x; x_s++) {
|
||||
chunk_copy.add_node(0, glm::vec3(z_s, cuboid_end_y, x_s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add cuboid to cuboids list
|
||||
cuboid_to_append = {
|
||||
cuboid_start_x, y, z,
|
||||
cuboid_end_x, cuboid_end_y, cuboid_end_z,
|
||||
last_material
|
||||
};
|
||||
cuboids.cuboids.push_back(cuboid_to_append);
|
||||
|
||||
|
||||
// if last cuboid is touching current cuboid, use current position as current cuboid's start position
|
||||
if (chunk_copy.get_node(glm::vec3(z, y, x)) != 0) {
|
||||
cuboid_start_x = x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
last_material = chunk_copy.get_node(glm::vec3(z, y, x));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cuboids;
|
||||
|
||||
}
|
||||
}
|
@ -1,3 +1,28 @@
|
||||
/*
|
||||
PolyGun
|
||||
|
||||
Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
|
||||
Copyright (c) 2023 Looki2000 https://looki2000.cubesoftware.xyz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef POLYGUN_ENGINE_GREEDY_MERGING_HPP
|
||||
#define POLYGUN_ENGINE_GREEDY_MERGING_HPP
|
||||
|
||||
@ -9,18 +34,25 @@ namespace polygun::engine {
|
||||
};
|
||||
|
||||
struct cuboid_list {
|
||||
cuboid* cuboids;
|
||||
int count;
|
||||
std::vector<cuboid> cuboids;
|
||||
};
|
||||
|
||||
class greedy_merging {
|
||||
public:
|
||||
greedy_merging() = default;
|
||||
~greedy_merging() = default;
|
||||
public:
|
||||
greedy_merging() = default;
|
||||
~greedy_merging() = default;
|
||||
|
||||
cuboid_list merge(world::Chunk& chunk);
|
||||
private:
|
||||
cuboid_list merge(world::Chunk& chunk);
|
||||
|
||||
private:
|
||||
const int voxel_count = 32;
|
||||
const int voxel_max_idx = voxel_count - 1;
|
||||
|
||||
int x, y, z, x_s, z_s; // for "for" loops
|
||||
|
||||
int last_material, cuboid_start_x, cuboid_end_x, cuboid_end_z, cuboid_end_y;
|
||||
bool cuboid_ended, invalid_row, invalid_plane;
|
||||
|
||||
// greedy merging variables
|
||||
};
|
||||
}
|
||||
|
||||
|
0
src/game/renderer/vertex_array.cpp
Normal file
0
src/game/renderer/vertex_array.cpp
Normal file
@ -35,6 +35,10 @@ SOFTWARE.
|
||||
|
||||
using namespace polygun::screens;
|
||||
|
||||
int x_d, y_d, z_d, id_d;
|
||||
|
||||
|
||||
|
||||
static const std::vector<float> vertices = {
|
||||
-0.1f , -0.1f, -0.1f,
|
||||
0.1f , -0.1f, -0.1f,
|
||||
@ -129,11 +133,11 @@ GameSessionScreen::GameSessionScreen() :
|
||||
m_node_mesh(nullptr),
|
||||
m_chnk(),
|
||||
m_camera(),
|
||||
m_texture_atlas(nullptr),
|
||||
m_is_esc_pressed(false),
|
||||
m_was_camera_locked(false),
|
||||
m_connection_thread(),
|
||||
m_running(true)
|
||||
m_running(true),
|
||||
m_texture_atlas()
|
||||
{}
|
||||
|
||||
void GameSessionScreen::begin() {
|
||||
@ -145,21 +149,23 @@ void GameSessionScreen::begin() {
|
||||
indices.push_back((int)i/3);
|
||||
m_node_mesh->load_from_memory(vertices, indices, uvs);
|
||||
|
||||
m_texture_atlas = m_engine->get_master_renderer().create_texture();
|
||||
for(int i = 0; i<sizeof(world::nodes); i++) {
|
||||
m_texture_atlas[i] = m_engine->get_master_renderer().create_texture();
|
||||
|
||||
int width, height, nrChannels;
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
unsigned char *data = stbi_load(world::nodes[i-1].texture.c_str(), &width, &height, &nrChannels, 0);
|
||||
if (data) {
|
||||
m_texture_atlas[i]->load_from_pixel_data(data, width, height, nrChannels);
|
||||
}
|
||||
else {
|
||||
data = stbi_load("res/textures/empty.png", &width, &height, &nrChannels, 0);
|
||||
m_texture_atlas[i]->load_from_pixel_data(data, width, height, nrChannels);
|
||||
}
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
m_engine->get_mesh_renderer()->set_3d_rendering_mode(true);
|
||||
|
||||
int width, height, nrChannels;
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
unsigned char *data = stbi_load("res/textures/gold.png", &width, &height, &nrChannels, 0);
|
||||
if (data) {
|
||||
m_texture_atlas->load_from_pixel_data(data, width, height, nrChannels);
|
||||
}
|
||||
else {
|
||||
std::cout << "Failed to load texture" << std::endl;
|
||||
}
|
||||
stbi_image_free(data);
|
||||
|
||||
glfwSetCursorPosCallback(m_engine->get_window(), m_camera.mouse_callback);
|
||||
glfwSetInputMode(m_engine->get_window(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
||||
@ -180,7 +186,7 @@ void GameSessionScreen::render() {
|
||||
for (unsigned int z = 0; z < 32; z++) {
|
||||
if (m_chnk.get_node(glm::vec3(x,y,z))!= 0) {
|
||||
mesh_renderer->translate(glm::vec3(x/5.0f, y/5.0f, z/5.0f));
|
||||
mesh_renderer->render_textured(m_node_mesh, m_texture_atlas);
|
||||
mesh_renderer->render_textured(m_node_mesh, m_texture_atlas[m_chnk.get_node(glm::vec3(x,y,z))]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,14 +208,14 @@ void GameSessionScreen::render() {
|
||||
// Camera rot
|
||||
ImGui::Text("Player Rot: %.3f, %.3f", m_camera.m_yaw, m_camera.m_pitch);
|
||||
|
||||
int x_d, y_d, z_d, id_d;
|
||||
|
||||
ImGui::InputInt("ID", &id_d);
|
||||
|
||||
ImGui::InputInt("X", &x_d);
|
||||
ImGui::InputInt("Y", &y_d);
|
||||
ImGui::InputInt("Z", &z_d);
|
||||
|
||||
// camera fov
|
||||
ImGui::InputFloat("FOV", &m_camera.m_fov);
|
||||
|
||||
if (ImGui::Button("Place Block")) {
|
||||
m_chnk.add_node(id_d, glm::vec3(x_d, y_d, z_d));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace polygun::screens {
|
||||
renderer::Mesh* m_node_mesh;
|
||||
world::Chunk m_chnk;
|
||||
engine::PlayerCamera m_camera;
|
||||
renderer::Texture* m_texture_atlas;
|
||||
renderer::Texture* m_texture_atlas[sizeof(world::nodes)];
|
||||
bool m_is_esc_pressed, m_was_camera_locked;
|
||||
std::unique_ptr<std::thread> m_connection_thread;
|
||||
std::atomic<bool> m_running;
|
||||
|
@ -5,7 +5,7 @@ namespace polygun::world {
|
||||
for (int x = 0; x < CHUNK_SIZE; x++) {
|
||||
for (int y = 0; y < CHUNK_SIZE; y++) {
|
||||
for (int z = 0; z < CHUNK_SIZE; z++) {
|
||||
chunk_data[x][y][z] = 1;
|
||||
chunk_data[x][y][z] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,12 @@ namespace polygun::world {
|
||||
};
|
||||
|
||||
static NodeType nodes[] = {
|
||||
{"air", "none"},
|
||||
{"cobble stone", "res/textures/cobble.png"},
|
||||
{"iron block", "res/textures/iron.png"},
|
||||
//{"air", "none"},
|
||||
{"dirt", "res/textures/dirt.png"},
|
||||
{"grass", "res/textures/grass.png"},
|
||||
{"bricks", "res/textures/bricks.png"},
|
||||
{"gold", "res/textures/gold.png"},
|
||||
{"iron", "res/textures/iron.png"},
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user