TIny cleanup

This commit is contained in:
2023-02-22 15:55:14 -08:00
parent 389a290362
commit 5dcf20a282
9 changed files with 97 additions and 57 deletions

View File

@ -1,24 +1,26 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Color {
float_t r, g, b, a;
};
#define COLOR_WHITE { 1, 1, 1, 1 }
#define COLOR_RED { 1, 0, 0, 1 }
#define COLOR_GREEN { 0, 255, 0, 1 }
#define COLOR_BLUE { 0, 0, 255, 1 }
#define COLOR_BLACK { 0, 0, 0, 1 }
#define COLOR_MAGENTA { 1, 0, 1, 1 }
#define COLOR_CORNFLOWER_BLUE { 0.39215686274f, 0.58431372549f, 0.9294117647f, 1.0f }
#define COLOR_WHITE_TRANSPARENT { 1, 1, 1, 0 }
#define COLOR_BLACK_TRANSPARENT { 0, 0, 0, 0 }
#define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Color {
float_t r, g, b, a;
};
#define COLOR_WHITE { 1, 1, 1, 1 }
#define COLOR_RED { 1, 0, 0, 1 }
#define COLOR_GREEN { 0, 255, 0, 1 }
#define COLOR_BLUE { 0, 0, 255, 1 }
#define COLOR_BLACK { 0, 0, 0, 1 }
#define COLOR_MAGENTA { 1, 0, 1, 1 }
#define COLOR_DARK_GREY { 0.2f, 0.2f, 0.2f, 1 }
#define COLOR_LIGHT_GREY { 0.8f, 0.8f, 0.8f, 1 }
#define COLOR_CORNFLOWER_BLUE { 0.39215686274f, 0.58431372549f, 0.9294117647f, 1.0f }
#define COLOR_WHITE_TRANSPARENT { 1, 1, 1, 0 }
#define COLOR_BLACK_TRANSPARENT { 0, 0, 0, 0 }
#define COLOR_TRANSPARENT COLOR_BLACK_TRANSPARENT
}

View File

@ -166,21 +166,24 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
// Debug Lines
#if DAWN_DEBUG_BUILD
Mesh lineMesh;
int32_t lineIndex = 0;
lineMesh.createBuffers(
scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT,
scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT
);
auto itDebugLine = scene->debugLines.begin();
while(itDebugLine != scene->debugLines.end()) {
auto item = itDebugLine->createShaderItem(
&lineMesh,
&lineIndex,
camera,
&this->renderManager->simpleShader
if(scene->debugLines.size() > 0) {
int32_t lineIndex = 0;
lineMesh.createBuffers(
scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT,
scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT
);
shaderPassItems.push_back(item);
++itDebugLine;
auto itDebugLine = scene->debugLines.begin();
while(itDebugLine != scene->debugLines.end()) {
auto item = itDebugLine->createShaderItem(
&lineMesh,
&lineIndex,
camera,
&this->renderManager->simpleShader
);
shaderPassItems.push_back(item);
itDebugLine = scene->debugLines.erase(itDebugLine);
lineIndex++;
}
}
#endif

View File

@ -26,6 +26,11 @@ void Scene::update() {
++it;
}
this->itemsNotInitialized.clear();
#if DAWN_DEBUG_BUILD
this->debugGrid();
this->debugOrigin();
#endif
// TODO: Cleanup old scene items

View File

@ -136,6 +136,8 @@ namespace Dawn {
std::vector<struct SceneDebugLine> debugLines;
void debugLine(struct SceneDebugLine line);
void debugCube(struct SceneDebugCube cube);
void debugOrigin();
void debugGrid();
#endif
/**

View File

@ -29,13 +29,11 @@ ExampleSpin::ExampleSpin(SceneItem *item) :
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
}
void ExampleSpin::onUnpausedUpdate() {
auto quat = this->transform->getLocalRotation();
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
this->transform->setLocalRotation(quat);
}

View File

@ -17,20 +17,19 @@ struct ShaderPassItem SceneDebugLine::createShaderItem(
SimpleTexturedShader *shader
) {
struct ShaderPassItem item;
item.priority = SCENE_DEBUG_LINE_PRIORITY;
item.priority = this->priority;
item.shaderProgram = &shader->program;
item.colorValues[shader->program.paramColor] = this->color;
item.matrixValues[shader->program.paramModel] = this->translation;
item.matrixValues[shader->program.paramModel] = this->transform;
item.matrixValues[shader->program.paramView] = camera->transform->getWorldTransform();
item.matrixValues[shader->program.paramProjection] = camera->projection;
item.boolValues[shader->program.paramHasTexture] = false;
item.renderFlags = 0x00;
auto i = *lineIndex;
item.mesh = mesh;
item.drawMode = MESH_DRAW_MODE_LINES;
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND | RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST;
item.start = i * SCENE_DEBUG_LINE_INDICE_COUNT;
item.count = SCENE_DEBUG_LINE_INDICE_COUNT;
@ -50,8 +49,6 @@ struct ShaderPassItem SceneDebugLine::createShaderItem(
indices,
SCENE_DEBUG_LINE_INDICE_COUNT
);
(*lineIndex)++;
return item;
}
@ -66,7 +63,7 @@ void Scene::debugCube(struct SceneDebugCube cube) {
struct SceneDebugLine line;
line.color = cube.color;
line.translation = cube.translation;
line.transform = cube.transform;
// Bottom Face
line.v0 = glm::vec3(min.x, min.y, min.z), line.v1 = glm::vec3(max.x, min.y, min.z);
@ -97,4 +94,42 @@ void Scene::debugCube(struct SceneDebugCube cube) {
this->debugLine(line);
line.v0 = glm::vec3(max.x, min.y, max.z), line.v1 = glm::vec3(max.x, max.y, max.z);
this->debugLine(line);
}
void Scene::debugOrigin() {
struct SceneDebugLine line;
line.v1 = glm::vec3(1, 0, 0), line.color = COLOR_RED;
this->debugLine(line);
line.v1 = glm::vec3(0, 1, 0), line.color = COLOR_GREEN;
this->debugLine(line);
line.v1 = glm::vec3(0, 0, 1), line.color = COLOR_BLUE;
this->debugLine(line);
}
void Scene::debugGrid() {
float_t s = 10.0f;
float_t t = 1.0f;
struct SceneDebugLine line;
line.color = COLOR_LIGHT_GREY;
line.color.a = 0.2f;
line.v0 = glm::vec3(-s, 0, -s), line.v1 = glm::vec3(s, 0, -s);
this->debugLine(line);
line.v0 = glm::vec3(-s, 0, -s), line.v1 = glm::vec3(-s, 0, s);
this->debugLine(line);
line.v0 = glm::vec3(s, 0, -s), line.v1 = glm::vec3(s, 0, s);
this->debugLine(line);
line.v0 = glm::vec3(-s, 0, s), line.v1 = glm::vec3(s, 0, s);
this->debugLine(line);
for(float_t x = -s+t; x < s; x += t) {
line.v0 = glm::vec3(x, 0, -s), line.v1 = glm::vec3(x, 0, s);
this->debugLine(line);
}
for(float_t z = -s+t; z < s; z += t) {
line.v0 = glm::vec3(-s, 0, z), line.v1 = glm::vec3(s, 0, z);
this->debugLine(line);
}
}

View File

@ -10,7 +10,7 @@
#define SCENE_DEBUG_LINE_VERTICE_COUNT 2
#define SCENE_DEBUG_LINE_INDICE_COUNT 2
#define SCENE_DEBUG_LINE_PRIORITY 100
#define SCENE_DEBUG_LINE_PRIORITY 1
namespace Dawn {
class SimpleTexturedShader;
@ -20,14 +20,16 @@ namespace Dawn {
glm::vec3 min;
glm::vec3 max;
struct Color color = COLOR_RED;
glm::mat4 translation = glm::mat4(1.0f);
glm::mat4 transform = glm::mat4(1.0f);
};
struct SceneDebugLine {
glm::vec3 v0 = glm::vec3(0, 0, 0);
glm::vec3 v1 = glm::vec3(1, 1, 1);
struct Color color = COLOR_RED;
glm::mat4 translation = glm::mat4(1.0f);
glm::mat4 transform = glm::mat4(1.0f);
int32_t priority = SCENE_DEBUG_LINE_PRIORITY;
/**
* Creates a renderable shader item for this debug line.

View File

@ -11,7 +11,6 @@ using namespace Dawn;
TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {}
void TicTacToeGame::onStart() {
std::cout << "Test" << std::endl;
this->tiles = getScene()->findComponents<TicTacToeTile>();
getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate);

View File

@ -29,7 +29,7 @@ namespace Dawn {
camera->orthoLeft = -s * ratio;
camera->orthoRight = s * ratio;
// auto cube = SimpleSpinningCubePrefab::create(this);
auto cube = SimpleSpinningCubePrefab::create(this);
// TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
// SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16);
@ -44,12 +44,6 @@ namespace Dawn {
// tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
}
}
this->debugCube((struct SceneDebugCube){
.min = glm::vec3(-0.5f, -0.5f, -0.5f),
.max = glm::vec3(0.5f, 0.5f, 0.5f),
COLOR_BLUE
});
}
std::vector<Asset*> getRequiredAssets() override {