rename src files, move .o to /bin

This commit is contained in:
tylermurphy534 2022-10-01 14:35:16 -04:00
parent a82704af88
commit 6a001c4840
12 changed files with 45 additions and 49 deletions

View file

@ -19,10 +19,10 @@ LDFLAGS += -lalut
LDFLAGS += -lvulkan LDFLAGS += -lvulkan
LDFLAGS += $(INCFLAGS) LDFLAGS += $(INCFLAGS)
BIN = bin
SRC = $(shell find src -name "*.cpp") SRC = $(shell find src -name "*.cpp")
SRC += $(shell find engine -name "*.cpp") SRC += $(shell find engine -name "*.cpp")
OBJ = $(SRC:.cpp=.o) OBJ = $(SRC:%.cpp=$(BIN)/%.o)
BIN = bin
VERTSRC = $(shell find ./res/shaders -type f -name "*.vert") VERTSRC = $(shell find ./res/shaders -type f -name "*.vert")
VERTOBJ = $(patsubst %.vert, %.vert.spv, $(VERTSRC)) VERTOBJ = $(patsubst %.vert, %.vert.spv, $(VERTSRC))
@ -35,7 +35,8 @@ all: dirs shader build
dirs: dirs:
mkdir -p ./$(BIN) mkdir -p ./$(BIN)
mkdir -p ./$(BIN)/src
mkdir -p ./$(BIN)/engine
shader: $(VERTOBJ) $(FRAGOBJ) shader: $(VERTOBJ) $(FRAGOBJ)
@ -48,11 +49,10 @@ build: dirs shader ${OBJ}
%.spv: % %.spv: %
glslc -o $@ $< glslc -o $@ $<
%.o: %.cpp $(BIN)/%.o: %.cpp
$(CC) -o $@ -c $< $(CCFLAGS) $(CC) -o $@ -c $< $(CCFLAGS)
clean: clean:
rm -rf app rm -rf app
rm -rf $(BIN) $(OBJ) rm -rf $(BIN)
rm -rf res/shaders/*.spv rm -rf res/shaders/*.spv
rm -rf lib/glfw/CMakeCache.txt

View file

@ -3,7 +3,6 @@
namespace xe { namespace xe {
RenderSystem::RenderSystem( RenderSystem::RenderSystem(
Engine &xeEngine,
std::string vert, std::string vert,
std::string frag, std::string frag,
std::map<uint32_t, uint32_t> uniformBindings, std::map<uint32_t, uint32_t> uniformBindings,
@ -13,8 +12,8 @@ RenderSystem::RenderSystem(
bool cullingEnabled, bool cullingEnabled,
std::vector<VkVertexInputAttributeDescription> attributeDescptions, std::vector<VkVertexInputAttributeDescription> attributeDescptions,
uint32_t vertexSize uint32_t vertexSize
) : xeDevice{xeEngine.xeDevice}, ) : xeDevice{Engine::getInstance()->xeDevice},
xeRenderer{xeEngine.xeRenderer}, xeRenderer{Engine::getInstance()->xeRenderer},
pushCunstantDataSize{pushCunstantDataSize}, pushCunstantDataSize{pushCunstantDataSize},
uniformBindings{uniformBindings}, uniformBindings{uniformBindings},
imageBindings{imageBindings}, imageBindings{imageBindings},

View file

@ -22,7 +22,7 @@ class RenderSystem {
class Builder { class Builder {
public: public:
Builder(Engine &xeEngine, std::string vert, std::string frag) : xeEngine{xeEngine}, vert{vert}, frag{frag} {} Builder(std::string vert, std::string frag) : vert{vert}, frag{frag} {}
Builder& addVertexBindingf(uint32_t binding, uint32_t dimension, uint32_t offset){ Builder& addVertexBindingf(uint32_t binding, uint32_t dimension, uint32_t offset){
if(dimension == 1) if(dimension == 1)
@ -75,7 +75,7 @@ class RenderSystem {
} }
std::unique_ptr<RenderSystem> build() { std::unique_ptr<RenderSystem> build() {
return std::make_unique<RenderSystem>(xeEngine, std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(imageArrayBindings), std::move(pushCunstantDataSize), std::move(cullingEnabled), std::move(attributeDescptions), std::move(vertexSize)); return std::make_unique<RenderSystem>(std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(imageArrayBindings), std::move(pushCunstantDataSize), std::move(cullingEnabled), std::move(attributeDescptions), std::move(vertexSize));
} }
private: private:
@ -92,12 +92,9 @@ class RenderSystem {
std::string frag; std::string frag;
bool cullingEnabled{false}; bool cullingEnabled{false};
Engine &xeEngine;
}; };
RenderSystem( RenderSystem(
Engine &xeEngine,
std::string vert, std::string vert,
std::string frag, std::string frag,
std::map<uint32_t, uint32_t> uniformBindings, std::map<uint32_t, uint32_t> uniformBindings,

View file

@ -4,7 +4,7 @@
#include "xe_engine.hpp" #include "xe_engine.hpp"
#include "xe_image.hpp" #include "xe_image.hpp"
#include "PerlinNoise.hpp" #include "chunk_noise.hpp"
#include <glm/common.hpp> #include <glm/common.hpp>
#include <glm/fwd.hpp> #include <glm/fwd.hpp>

View file

@ -1,10 +1,10 @@
#include "simple_renderer.hpp" #include "chunk_renderer.hpp"
#include "chunk.hpp" #include "chunk.hpp"
namespace app { namespace app {
SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, std::vector<xe::Image*> &images) { ChunkRenderer::ChunkRenderer(std::vector<xe::Image*> &images) {
xeRenderSystem = xe::RenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv") xeRenderSystem = xe::RenderSystem::Builder("res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
.addVertexBindingf(0, 3, 0) // position .addVertexBindingf(0, 3, 0) // position
.addVertexBindingf(1, 3, 12) // normal .addVertexBindingf(1, 3, 12) // normal
.addVertexBindingf(2, 2, 24) // uvs .addVertexBindingf(2, 2, 24) // uvs
@ -17,7 +17,7 @@ SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, std::vector<xe::Image*> &im
.build(); .build();
} }
void SimpleRenderer::render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera) { void ChunkRenderer::render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera) {
xeRenderSystem->start(); xeRenderSystem->start();

View file

@ -16,16 +16,16 @@ struct PushConstant {
alignas(16) glm::mat4 normalMatrix{1.f}; alignas(16) glm::mat4 normalMatrix{1.f};
}; };
class SimpleRenderer { class ChunkRenderer {
public: public:
SimpleRenderer(xe::Engine &xeEngine, std::vector<xe::Image*> &images); ChunkRenderer(std::vector<xe::Image*> &images);
~SimpleRenderer() {}; ~ChunkRenderer() {};
SimpleRenderer(const SimpleRenderer&) = delete; ChunkRenderer(const ChunkRenderer&) = delete;
SimpleRenderer operator=(const SimpleRenderer&) = delete; ChunkRenderer operator=(const ChunkRenderer&) = delete;
void render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera); void render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera);

View file

@ -1,11 +1,11 @@
#include "first_app.hpp" #include "minecraft.hpp"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
int main() { int main() {
app::FirstApp app{}; app::Minecraft app{};
try { try {
app.run(); app.run();

View file

@ -1,15 +1,15 @@
#include "first_app.hpp" #include "minecraft.hpp"
#include <chrono> #include <chrono>
using namespace std::chrono; using namespace std::chrono;
namespace app { namespace app {
FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Minecraft Vulkan", "res/image/icon.png"} {}; Minecraft::Minecraft() : xeEngine{WIDTH, HEIGHT, "Minecraft Vulkan", "res/image/icon.png"} {};
FirstApp::~FirstApp() {} Minecraft::~Minecraft() {}
void FirstApp::run() { void Minecraft::run() {
Chunk::load(); Chunk::load();
@ -19,13 +19,13 @@ void FirstApp::run() {
createGameObjects(viewerObject); createGameObjects(viewerObject);
SimpleRenderer renderer{xeEngine, Chunk::getTextures()}; ChunkRenderer renderer{Chunk::getTextures()};
xe::Sound sound{"res/sound/when_the_world_ends.wav"}; xe::Sound sound{"res/sound/when_the_world_ends.wav"};
sound.setLooping(true); sound.setLooping(true);
sound.play(); sound.play();
KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject}; PlayerController cameraController{xeEngine.getInput(), viewerObject};
while (xeEngine.poll()) { while (xeEngine.poll()) {
@ -49,7 +49,7 @@ void FirstApp::run() {
} }
void FirstApp::createGameObjects(xe::GameObject& viewer) { void Minecraft::createGameObjects(xe::GameObject& viewer) {
int width = 2*RENDER_DISTANCE+1; int width = 2*RENDER_DISTANCE+1;
loadedChunks.clear(); loadedChunks.clear();
for(int32_t x = 0; x < width; x++) { for(int32_t x = 0; x < width; x++) {
@ -61,7 +61,7 @@ void FirstApp::createGameObjects(xe::GameObject& viewer) {
} }
} }
void FirstApp::reloadLoadedChunks(xe::GameObject& viewer) { void Minecraft::reloadLoadedChunks(xe::GameObject& viewer) {
viewX = static_cast<int>(floor(viewer.transform.translation.x / Chunk::CHUNK_SIZE.x)); viewX = static_cast<int>(floor(viewer.transform.translation.x / Chunk::CHUNK_SIZE.x));
viewZ = static_cast<int>(floor(viewer.transform.translation.z / Chunk::CHUNK_SIZE.z)); viewZ = static_cast<int>(floor(viewer.transform.translation.z / Chunk::CHUNK_SIZE.z));
int width = 2*RENDER_DISTANCE+1; int width = 2*RENDER_DISTANCE+1;

View file

@ -2,8 +2,8 @@
#include "xe_engine.hpp" #include "xe_engine.hpp"
#include "keyboard_movement_controller.hpp" #include "player_controller.hpp"
#include "simple_renderer.hpp" #include "chunk_renderer.hpp"
#include "chunk.hpp" #include "chunk.hpp"
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
@ -17,14 +17,14 @@
#include <iostream> #include <iostream>
namespace app { namespace app {
class FirstApp { class Minecraft {
public: public:
FirstApp(); Minecraft();
~FirstApp(); ~Minecraft();
FirstApp(const FirstApp &) = delete; Minecraft(const Minecraft &) = delete;
FirstApp operator=(const FirstApp &) = delete; Minecraft operator=(const Minecraft &) = delete;
void run(); void run();

View file

@ -1,13 +1,13 @@
#include "keyboard_movement_controller.hpp" #include "player_controller.hpp"
namespace app { namespace app {
KeyboardMovementController::KeyboardMovementController(xe::Input &input, xe::GameObject &viewerObject) PlayerController::PlayerController(xe::Input &input, xe::GameObject &viewerObject)
: input{input}, viewerObject{viewerObject} {}; : input{input}, viewerObject{viewerObject} {};
KeyboardMovementController::~KeyboardMovementController() {}; PlayerController::~PlayerController() {};
void KeyboardMovementController::update(float dt) { void PlayerController::update(float dt) {
glm::vec3 rotate{0}; glm::vec3 rotate{0};
if(input.isKeyPressed(keys.lookRight)) rotate.y += 1.f; if(input.isKeyPressed(keys.lookRight)) rotate.y += 1.f;
if(input.isKeyPressed(keys.lookLeft)) rotate.y -= 1.f; if(input.isKeyPressed(keys.lookLeft)) rotate.y -= 1.f;

View file

@ -10,12 +10,12 @@
namespace app { namespace app {
class KeyboardMovementController { class PlayerController {
public: public:
KeyboardMovementController(xe::Input &input, xe::GameObject &viewerObject); PlayerController(xe::Input &input, xe::GameObject &viewerObject);
~KeyboardMovementController(); ~PlayerController();
struct KeyMappings { struct KeyMappings {
int moveLeft = KEY_A; int moveLeft = KEY_A;