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

View file

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

View file

@ -22,7 +22,7 @@ class RenderSystem {
class Builder {
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){
if(dimension == 1)
@ -75,7 +75,7 @@ class RenderSystem {
}
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:
@ -92,12 +92,9 @@ class RenderSystem {
std::string frag;
bool cullingEnabled{false};
Engine &xeEngine;
};
RenderSystem(
Engine &xeEngine,
std::string vert,
std::string frag,
std::map<uint32_t, uint32_t> uniformBindings,

View file

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

View file

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

View file

@ -16,16 +16,16 @@ struct PushConstant {
alignas(16) glm::mat4 normalMatrix{1.f};
};
class SimpleRenderer {
class ChunkRenderer {
public:
SimpleRenderer(xe::Engine &xeEngine, std::vector<xe::Image*> &images);
ChunkRenderer(std::vector<xe::Image*> &images);
~SimpleRenderer() {};
~ChunkRenderer() {};
SimpleRenderer(const SimpleRenderer&) = delete;
SimpleRenderer operator=(const SimpleRenderer&) = delete;
ChunkRenderer(const ChunkRenderer&) = delete;
ChunkRenderer operator=(const ChunkRenderer&) = delete;
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 <iostream>
#include <stdexcept>
int main() {
app::FirstApp app{};
app::Minecraft app{};
try {
app.run();

View file

@ -1,15 +1,15 @@
#include "first_app.hpp"
#include "minecraft.hpp"
#include <chrono>
using namespace std::chrono;
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();
@ -19,13 +19,13 @@ void FirstApp::run() {
createGameObjects(viewerObject);
SimpleRenderer renderer{xeEngine, Chunk::getTextures()};
ChunkRenderer renderer{Chunk::getTextures()};
xe::Sound sound{"res/sound/when_the_world_ends.wav"};
sound.setLooping(true);
sound.play();
KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject};
PlayerController cameraController{xeEngine.getInput(), viewerObject};
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;
loadedChunks.clear();
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));
viewZ = static_cast<int>(floor(viewer.transform.translation.z / Chunk::CHUNK_SIZE.z));
int width = 2*RENDER_DISTANCE+1;

View file

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

View file

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

View file

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