changed prefixes for imgui draw options and gpu memory leaks
This commit is contained in:
parent
697018422c
commit
7850871955
8 changed files with 59 additions and 56 deletions
|
|
@ -19,7 +19,7 @@ namespace Configs {
|
|||
std::string m_display;
|
||||
};
|
||||
|
||||
inline void imguiDrawOpts(std::string id,std::vector<std::string> opts,std::string &val){
|
||||
inline void g_imguiDrawOpts(std::string id, std::vector<std::string> opts, std::string &val){
|
||||
if(ImGui::BeginCombo(id.c_str(),val.c_str())){
|
||||
for(const std::string &opt: opts) {
|
||||
if (ImGui::Selectable((opt + "##" + id).c_str()))
|
||||
|
|
@ -31,7 +31,7 @@ namespace Configs {
|
|||
}
|
||||
|
||||
template<typename t>
|
||||
inline void imguiDrawOpts(std::string id,std::vector<ValueDisplayOptions<t>> opts,t &val){
|
||||
void g_imguiDrawOpts(std::string id, std::vector<ValueDisplayOptions<t>> opts, t &val){
|
||||
auto selOpt = std::find_if(opts.begin(), opts.end(),[&](const ValueDisplayOptions<t> &opt){
|
||||
return val == opt.m_val;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@
|
|||
#include<imgui.h>
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "glm/gtx/string_cast.hpp"
|
||||
|
||||
#include<algorithm>
|
||||
#include<cmath>
|
||||
#include"Config/Configs.h"
|
||||
|
||||
MainViewport *MainVP;
|
||||
|
||||
|
|
@ -32,18 +33,9 @@ glm::vec3 ToGlmVec3(Vector3 Vec3) {
|
|||
}
|
||||
|
||||
bool IsArea(const std::string& Type) {
|
||||
if (Type == "Area" ||
|
||||
Type == "Area_Yellow" ||
|
||||
Type == "Area_Pink" ||
|
||||
Type == "StageArea" ||
|
||||
Type == "GeneralArea" ||
|
||||
Type == "PaintedArea" ||
|
||||
Type == "GachihokoHikikomoriArea" ||
|
||||
Type == "GachihokoHikikomoriArea2" ||
|
||||
Type == "SearchableArea" ||
|
||||
Type == "PaintTargetArea")
|
||||
return true;
|
||||
return false;
|
||||
return std::any_of(Configs::g_areas.begin(), Configs::g_areas.end(),[&](const std::string &areatype){
|
||||
return Type == areatype;
|
||||
});
|
||||
}
|
||||
|
||||
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f), defaultShader("ForwardPass"), flatShader("FlatForwardPass") {
|
||||
|
|
@ -66,8 +58,8 @@ MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true),
|
|||
Graphics::Shader("ShadowPass"),
|
||||
Math::Vector2i(8192,8192));
|
||||
|
||||
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
|
||||
glBindTexture(GL_TEXTURE_2D, tex.m_texture.getId());
|
||||
auto& tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
|
||||
glBindTexture(GL_TEXTURE_2D, tex.m_texture->getId());
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
|
@ -281,8 +273,8 @@ void MainViewport::Draw() {
|
|||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
|
||||
tex.m_texture.setActive(5);
|
||||
auto &tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
|
||||
tex.m_texture->setActive(5);
|
||||
|
||||
GLint SunVpLoc = m_internalFramebuf->m_shader.getUniformLocation("SunVP");
|
||||
|
||||
|
|
@ -857,6 +849,30 @@ glm::vec2 MainViewport::CalcGizmoDir(glm::vec3 dir) {
|
|||
return DirPosVPSpace - ObjPosVPSpace;
|
||||
}
|
||||
|
||||
MainViewport *GetMainViewport() {
|
||||
void MainViewport::clearModels() {
|
||||
MdlFromObj.clear();
|
||||
}
|
||||
|
||||
void MainViewport::cleanUnnescessary() {
|
||||
auto &map = GetMainWindow()->loadedMap;
|
||||
|
||||
for(auto mdlPairIter = MdlFromObj.begin(); mdlPairIter != MdlFromObj.end(); ){
|
||||
auto nextiter = mdlPairIter;
|
||||
nextiter++;
|
||||
|
||||
if(nextiter == MdlFromObj.end())
|
||||
break;
|
||||
|
||||
if(std::none_of(map.Objects.begin(), map.Objects.end(),[&](const LevelObject &obj){
|
||||
return obj.Type == nextiter->first;
|
||||
})){
|
||||
MdlFromObj.erase(nextiter);
|
||||
} else {
|
||||
mdlPairIter = nextiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainViewport *g_getMainViewport() {
|
||||
return MainVP;
|
||||
}
|
||||
|
|
@ -27,6 +27,11 @@ public:
|
|||
glm::vec3 camPos = glm::vec3(0,0,0);
|
||||
glm::vec2 camrot = glm::vec2(0,0);
|
||||
|
||||
void clearModels();
|
||||
|
||||
void cleanUnnescessary();
|
||||
private:
|
||||
|
||||
float shadowArea = 750.0f;
|
||||
|
||||
Graphics::Shader flatShader;
|
||||
|
|
@ -46,7 +51,7 @@ public:
|
|||
|
||||
GizmoType CurrentGizmoType = Move;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
unsigned int HoveredObjId = 0;
|
||||
|
||||
|
|
@ -77,6 +82,6 @@ private:
|
|||
};
|
||||
|
||||
|
||||
MainViewport* GetMainViewport();
|
||||
MainViewport* g_getMainViewport();
|
||||
|
||||
#endif //SPOONTOOL_MAINVIEWPORT_H
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
|
|||
|
||||
auto mapSelectSaveExplorer = addWidget(new Graphics::FileSelectDialog("Select/Save Map", {".yaml"},[&](boost::filesystem::path path){
|
||||
selectedElem = nullptr;
|
||||
loadedMap = ConvertFromYaml(path);
|
||||
GetMainWindow()->loadedMap = ConvertFromYaml(path);
|
||||
|
||||
MainViewport* vp = g_getMainViewport();
|
||||
vp->cleanUnnescessary();
|
||||
},[&](boost::filesystem::path path){
|
||||
loadedMap.Export(path);
|
||||
}));
|
||||
|
|
@ -90,6 +93,7 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
|
|||
AddMenuItem("Game", "Gambit(1)", [&](){
|
||||
gameSetting = GameMode::Gambit;
|
||||
Configs::g_loadConfigs(GameMode::ToString(gameSetting));
|
||||
g_getMainViewport()->clearModels();
|
||||
});
|
||||
AddMenuItem("Game", "Blitz(2)", [&](){
|
||||
gameSetting = GameMode::Blitz;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
#include<glm/vec2.hpp>
|
||||
|
||||
Model::Model(std::string modelname) {
|
||||
CopyCount = new unsigned(1);
|
||||
|
||||
auto modeltoload = boost::filesystem::current_path() / "Models" / modelname / (modelname + ".dae");
|
||||
|
||||
Assimp::Importer importer;
|
||||
|
|
@ -42,7 +40,7 @@ Model::Model(std::string modelname) {
|
|||
auto mesh = scene->mMeshes[i];
|
||||
auto mat = scene->mMaterials[mesh->mMaterialIndex];
|
||||
|
||||
Materials.push_back(new Graphics::Material(mat,boost::filesystem::current_path() / "Models" / modelname));
|
||||
Materials.push_back(std::make_unique<Graphics::Material>(mat,boost::filesystem::current_path() / "Models" / modelname));
|
||||
|
||||
auto vertices = std::vector<glm::vec3>();
|
||||
auto texcoords = std::vector<glm::vec2>();
|
||||
|
|
@ -78,7 +76,7 @@ Model::Model(std::string modelname) {
|
|||
indices.push_back(mesh->mFaces[i3].mIndices[i4]);
|
||||
}
|
||||
|
||||
Meshes.push_back(new Graphics::Mesh(vertices,indices,texcoords,normals,tangents,bitangents));
|
||||
Meshes.push_back(std::make_unique<Graphics::Mesh>(vertices,indices,texcoords,normals,tangents,bitangents));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +117,7 @@ void Model::Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4
|
|||
GLuint RotationMatrixID = shader.getUniformLocation("NormalRotationMatrix");
|
||||
glUniformMatrix4fv(RotationMatrixID,1,GL_FALSE,&nrmRotationMatrix[0][0]);
|
||||
|
||||
mesh->Draw(Materials[texnum]);
|
||||
mesh->Draw(*Materials[texnum]);
|
||||
texnum++;
|
||||
}
|
||||
|
||||
|
|
@ -153,9 +151,7 @@ void Model::DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP)
|
|||
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
|
||||
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
|
||||
|
||||
|
||||
|
||||
mesh->Draw(Materials[texnum]);
|
||||
mesh->Draw(*Materials[texnum]);
|
||||
texnum++;
|
||||
}
|
||||
|
||||
|
|
@ -164,20 +160,4 @@ void Model::DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP)
|
|||
|
||||
}
|
||||
|
||||
Model::~Model() {
|
||||
(*CopyCount)--;
|
||||
|
||||
if((*CopyCount) == 0) {
|
||||
for (Graphics::Material *mat: Materials)
|
||||
delete mat;
|
||||
|
||||
for (Graphics::Mesh *mesh: Meshes)
|
||||
delete mesh;
|
||||
}
|
||||
}
|
||||
|
||||
Model::Model(const Model &mdl): CopyCount(mdl.CopyCount), Meshes(mdl.Meshes), Materials(mdl.Materials) {
|
||||
(*CopyCount)++;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
10
src/Model.h
10
src/Model.h
|
|
@ -16,18 +16,16 @@ class Model {
|
|||
public:
|
||||
Model(std::string modelName);
|
||||
|
||||
Model(const Model& mdl);
|
||||
Model(const Model& mdl) = delete;
|
||||
|
||||
~Model();
|
||||
|
||||
unsigned *CopyCount;
|
||||
Model(Model&&) = default;
|
||||
|
||||
void Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP);
|
||||
|
||||
void DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
|
||||
protected:
|
||||
std::list<Graphics::Mesh*> Meshes;
|
||||
std::vector<Graphics::Material*> Materials;
|
||||
std::list<std::unique_ptr<Graphics::Mesh>> Meshes;
|
||||
std::vector<std::unique_ptr<Graphics::Material>> Materials;
|
||||
|
||||
//std::map<std::string,Graphics::Texture> TexturesForName;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
|
|||
auto &link = *linkIter;
|
||||
if (ImGui::CollapsingHeader(("Link " + std::to_string(i) + "##" + Id).c_str())) {
|
||||
ImGui::Indent();
|
||||
Configs::imguiDrawOpts("Link Type##" + std::to_string(i) + Id, Configs::g_linkOpts, link.Name);
|
||||
Configs::g_imguiDrawOpts("Link Type##" + std::to_string(i) + Id, Configs::g_linkOpts, link.Name);
|
||||
ImGui::InputText(("Destination##PropWindLink" + std::to_string(i) + Id).c_str(), &link.Destination);
|
||||
|
||||
if(Element* gotoElem = GetMainWindow()->loadedMap.GetElementById(link.Destination)) {
|
||||
|
|
@ -171,7 +171,7 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
|
|||
if(levelObject) {
|
||||
//ImGuiDrawTeamSelect(levelObject,Id);
|
||||
ImGuiDrawSelection("Team##"+Id,levelObject->Team,Teams::AllOptions.begin(), Teams::AllOptions.end(),Teams::TeamToText);
|
||||
Configs::imguiDrawOpts("Drop##"+Id, Configs::g_dropIdOpts,levelObject->DropId);
|
||||
Configs::g_imguiDrawOpts("Drop##" + Id, Configs::g_dropIdOpts, levelObject->DropId);
|
||||
}
|
||||
|
||||
if(railPoint){
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ void RailSelectWidget::Draw() {
|
|||
if(ImGui::Button(ICON_FA_PLUS)){
|
||||
wind->selectedElem = nullptr;
|
||||
|
||||
auto vp = GetMainViewport();
|
||||
auto vp = g_getMainViewport();
|
||||
Vector3 pos = {vp->camPos.x, -vp->camPos.y, vp->camPos.z};
|
||||
wind->loadedMap.Rails.emplace_back(pos);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue