There is a memory leak

This commit is contained in:
Dynamitos
2023-11-30 11:51:53 +01:00
parent d1475d506e
commit 1493627ceb
20 changed files with 91 additions and 102 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
{
}
std::string outMatFilename = matCode["name"].get<std::string>().append(".asset");
std::string outMatFilename = matCode["name"].get<std::string>().append(".json");
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
outMatFile << std::setw(4) << matCode;
outMatFile.flush();
+4 -4
View File
@@ -217,14 +217,14 @@ int main()
WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280;
mainWindowInfo.height = 720;
mainWindowInfo.width = 1920;
mainWindowInfo.height = 1080;
mainWindowInfo.numSamples = 1;
mainWindowInfo.preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB;
auto window = windowManager->addWindow(graphics, mainWindowInfo);
ViewportCreateInfo sceneViewInfo;
sceneViewInfo.dimensions.size.x = 1280;
sceneViewInfo.dimensions.size.y = 720;
sceneViewInfo.dimensions.size.x = 1920;
sceneViewInfo.dimensions.size.y = 1080;
sceneViewInfo.dimensions.offset.x = 0;
sceneViewInfo.dimensions.offset.y = 0;
OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string());
+1 -1
View File
@@ -7,7 +7,7 @@ CameraActor::CameraActor(PScene scene)
: Actor(scene)
{
attachComponent<Component::Camera>();
accessComponent<Component::Transform>().setRelativeLocation(Vector(10, 5, 14));
accessComponent<Component::Transform>().setPosition(Vector(10, 5, 14));
}
CameraActor::~CameraActor()
+11 -14
View File
@@ -11,8 +11,8 @@ Camera::Camera()
: viewMatrix(Matrix4())
, bNeedsViewBuild(false)
{
yaw = 0;
pitch = 0.2;
yaw = 3.1415f/2;
pitch = 0;
}
Camera::~Camera()
@@ -21,40 +21,37 @@ Camera::~Camera()
void Camera::mouseMove(float deltaYaw, float deltaPitch)
{
yaw -= deltaYaw / 500.f;
yaw += deltaYaw / 500.f;
pitch += deltaPitch / 500.f;
//std::cout << "Yaw: " << yaw << " Pitch: " << pitch << std::endl;
Vector cameraDirection = glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
Vector xyz = glm::cross(cameraDirection, Vector(0, 0, 1));
Quaternion result = Quaternion(glm::dot(cameraDirection, Vector(0, 0, 1)) + 1, xyz.x, xyz.y, xyz.z);
//std::cout << "Result " << Vector(0, 0, 1) * glm::normalize(result) << " cameraDirection: " << cameraDirection << std::endl;
getTransform().setRelativeRotation(result);
Matrix4 viewMat = glm::lookAt(getTransform().getPosition(), getTransform().getPosition() + cameraDirection, Vector(0, 1, 0));
getTransform().setRotation(viewMat); // quaternion from matrix, janky but im bad at math
bNeedsViewBuild = true;
}
void Camera::mouseScroll(float x)
{
getTransform().addRelativeLocation(getTransform().getForward()*x);
getTransform().translate(getTransform().getForward()*x);
bNeedsViewBuild = true;
}
void Camera::moveX(float amount)
{
getTransform().addRelativeLocation(getTransform().getForward()*amount);
getTransform().translate(getTransform().getForward()*amount);
bNeedsViewBuild = true;
}
void Camera::moveY(float amount)
{
getTransform().addRelativeLocation(getTransform().getRight()*amount);
getTransform().translate(getTransform().getRight()*amount);
bNeedsViewBuild = true;
}
void Camera::buildViewMatrix()
{
Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition();
Vector lookAt = eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch)));
Vector eyePos = getTransform().getPosition();
Vector lookAt = eyePos + getTransform().getForward();
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
cameraPos = eyePos;
bNeedsViewBuild = false;
}
+3 -1
View File
@@ -21,7 +21,7 @@ struct Camera
}
Vector getCameraPosition() const
{
return Vector(viewMatrix[3]);
return cameraPos;
}
void mouseMove(float deltaX, float deltaY);
void mouseScroll(float x);
@@ -29,6 +29,8 @@ struct Camera
void moveY(float amount);
void buildViewMatrix();
Matrix4 viewMatrix;
Vector cameraPos;
Vector cameraDirection;
//Transforms relative to actor
float yaw;
float pitch;
+6 -24
View File
@@ -4,7 +4,6 @@ using namespace Seele::Component;
DEFINE_COMPONENT(Transform)
void Transform::setPosition(Vector pos)
{
transform.setPosition(pos);
@@ -19,32 +18,15 @@ void Transform::setScale(Vector scale)
{
transform.setScale(scale);
}
void Transform::setRelativeLocation(Vector location)
void Transform::translate(Vector direction)
{
transform = Math::Transform(location, transform.getRotation(), transform.getScale());
transform.setPosition(transform.getPosition() + direction);
}
void Transform::setRelativeRotation(Vector rotation)
void Transform::rotate(Quaternion quat)
{
transform = Math::Transform(transform.getPosition(), Quaternion(rotation), transform.getScale());
transform.setRotation(transform.getRotation() * quat);
}
void Transform::setRelativeRotation(Quaternion rotation)
void Transform::scale(Vector scale)
{
transform = Math::Transform(transform.getPosition(), rotation, transform.getScale());
}
void Transform::setRelativeScale(Vector scale)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation(), scale);
}
void Transform::addRelativeLocation(Vector translation)
{
transform = Math::Transform(transform.getPosition() + translation, transform.getRotation(), transform.getScale());
}
void Transform::addRelativeRotation(Vector rotation)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation() * Quaternion(rotation), transform.getScale());
}
void Transform::addRelativeRotation(Quaternion rotation)
{
transform = Math::Transform(transform.getPosition(), transform.getRotation() * rotation, transform.getScale());
transform.setScale(transform.getScale() + scale);
}
+3 -9
View File
@@ -21,15 +21,9 @@ struct Transform
void setPosition(Vector pos);
void setRotation(Quaternion quat);
void setScale(Vector scale);
void setRelativeLocation(Vector location);
void setRelativeRotation(Quaternion rotation);
void setRelativeRotation(Vector rotation);
void setRelativeScale(Vector scale);
void addRelativeLocation(Vector translation);
void addRelativeRotation(Quaternion rotation);
void addRelativeRotation(Vector rotation);
void translate(Vector direction);
void rotate(Quaternion quat);
void scale(Vector scale);
private:
Math::Transform transform;
};
+2 -1
View File
@@ -165,8 +165,9 @@ void BasePass::render()
{
if (meshData.numIndices > 0)
{
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset++);
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
}
instanceOffset++;
}
}
}
+2 -2
View File
@@ -10,7 +10,7 @@
using namespace Seele;
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 16 * 1024;
constexpr static uint64 NUM_DEFAULT_ELEMENTS = 1024 * 1024;
void VertexData::resetMeshData()
{
@@ -166,7 +166,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices)
head += numVertices;
if (head > verticesAllocated)
{
verticesAllocated = head;
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS);
resizeBuffers();
}
return res;
+9 -5
View File
@@ -62,12 +62,10 @@ void DescriptorLayout::create()
PipelineLayout::~PipelineLayout()
{
if (layoutHandle != VK_NULL_HANDLE)
{
vkDestroyPipelineLayout(graphics->getDevice(), layoutHandle, nullptr);
}
}
Map<uint32, VkPipelineLayout> cachedLayouts;
void PipelineLayout::create()
{
vulkanDescriptorLayouts.resize(descriptorSetLayouts.size());
@@ -105,7 +103,14 @@ void PipelineLayout::create()
layoutHash = CRC::Calculate(createInfo.pPushConstantRanges, sizeof(VkPushConstantRange) * createInfo.pushConstantRangeCount, CRC::CRC_32());
layoutHash = CRC::Calculate(createInfo.pSetLayouts, sizeof(VkDescriptorSetLayout) * createInfo.setLayoutCount, CRC::CRC_32(), layoutHash);
if (cachedLayouts.contains(layoutHash))
{
layoutHandle = cachedLayouts[layoutHash];
return;
}
VK_CHECK(vkCreatePipelineLayout(graphics->getDevice(), &createInfo, nullptr, &layoutHandle));
cachedLayouts[layoutHash] = layoutHandle;
}
void PipelineLayout::reset()
@@ -391,7 +396,6 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet()
{
//If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
std::cout << "New descriptor " << cachedHandles[setIndex]->setHandle << std::endl;
}
cachedHandles[setIndex]->allocate();
+1
View File
@@ -1,5 +1,6 @@
#include "Transform.h"
#include <glm/gtx/quaternion.hpp>
#include "Transform.h"
using namespace Seele;
using namespace Seele::Math;
-4
View File
@@ -60,10 +60,6 @@ void LightEnvironment::addPointLight(Component::PointLight pointLight)
void LightEnvironment::commit()
{
dirs.add(Component::DirectionalLight{
.color = Vector4(1, 1, 1, 1),
.direction = Vector4(1, 0, 1, 0),
});
lightEnv.numDirectionalLights = dirs.size();
lightEnv.numPointLights = points.size();
lightEnvBuffer->updateContents(DataSource{
-1
View File
@@ -25,7 +25,6 @@ Scene::~Scene()
void Scene::update(float deltaTime)
{
lightEnv->reset();
physics.update(deltaTime);
}
+4 -4
View File
@@ -22,6 +22,10 @@ void KeyboardInput::update(Component::KeyboardInput& input)
input.mouseY = mouseY;
input.mouse1 = mouse1;
input.mouse2 = mouse2;
deltaX = mouseX - lastMouseX;
deltaY = mouseY - lastMouseY;
lastMouseX = mouseX;
lastMouseY = mouseY;
}
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
@@ -33,10 +37,6 @@ void KeyboardInput::mouseCallback(double x, double y)
{
mouseX = x;
mouseY = y;
deltaX = x - lastMouseX;
deltaY = y - lastMouseY;
lastMouseX = x;
lastMouseY = y;
}
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
+7
View File
@@ -15,4 +15,11 @@ LightGather::~LightGather()
void LightGather::update()
{
lightEnv->reset();
scene->view<Component::PointLight>([this](Component::PointLight& pointLight) {
lightEnv->addPointLight(pointLight);
});
scene->view<Component::DirectionalLight>([this](Component::DirectionalLight& dirLight) {
lightEnv->addDirectionalLight(dirLight);
});
}