Skip to content

Commit 98bebe5

Browse files
committed
general app improvements
1 parent 4bf6720 commit 98bebe5

File tree

13 files changed

+48
-14
lines changed

13 files changed

+48
-14
lines changed

src/app.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ App& App::get() {
2020
logInfo("Creating App", "App");
2121
appSingleton.emplace();
2222
appSingleton->newMainWindow();
23-
appSingleton->windows.back()->getActiveCircuitViewWidget()->newCircuit();
23+
if (appSingleton->windows.back()->getActiveCircuitViewWidget()) appSingleton->windows.back()->getActiveCircuitViewWidget()->newCircuit();
2424
}
2525
return *appSingleton;
2626
}
@@ -97,6 +97,11 @@ const char* const addLoopTracyName = "appLoop";
9797

9898
void App::runLoop() {
9999
logInfo("Starting App loop", "App");
100+
if (windows.empty()) {
101+
logError("Killing App loop. No windows Found!", "App");
102+
App::kill();
103+
return;
104+
}
100105
Network::get().checkForUpdates(get().windows[0]->getPopUpManager());
101106
running = true;
102107
while (running) {

src/cli/commands/helpCommand.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "helpCommand.h"
22

3-
#include "environment/environment.h"
43
#include "../commandManager.h"
54
#include "util/runAtStartup.h"
65

src/cli/commands/testCircuitCommand.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include "testCircuitCommand.h"
22

3-
#include "environment/environment.h"
43
#include "util/runAtStartup.h"
54
#include "../commandManager.h"
65
#include "backend/circuitTestCase/circuitTestCase.h"
7-
#include "backend/container/block/blockDefs.h"
86

97
runAtStartup(CommandManager::get().registerCommand(std::make_unique<TestCircuitCommand>());)
108

src/cli/commands/versionCommand.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "versionCommand.h"
22

3-
#include "environment/environment.h"
43
#include "../commandManager.h"
54
#include "util/runAtStartup.h"
65
#include "util/version.h"

src/environment/blockRenderDataFeeder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "blockRenderDataFeeder.h"
22

3+
#include "gpu/blockRenderDataManager.h"
34
#include "backend/backend.h"
45
#include "gpu/freetype/freetype.h"
56
#include "gpu/mainRenderer.h"

src/environment/blockRenderDataFeeder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#ifndef blockRenderDataFeeder_h
22
#define blockRenderDataFeeder_h
33

4-
#include "gpu/blockRenderDataManager.h"
54
#include "gpu/cpuImageEditor/cpuImage.h"
65
#include "backend/container/block/blockDefs.h"
76
#include "backend/container/block/connectionEnd.h"
87
#include "backend/dataUpdateEventManager.h"
98
#include "blockTextureGenerator.h"
109

10+
typedef uint32_t BlockRenderDataId;
11+
typedef uint32_t BlockPortRenderDataId;
12+
typedef uint32_t BlockTextureId;
13+
1114
class Font;
1215
class Backend;
1316
class BlockData;

src/gpu/renderer/viewport/blockTextureManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ BlockTextureId BlockTextureManager::addTexture(const std::string& path) {
5353
rectId = layerRectPackers[layer].tryAddRect({textureWidth, textureHeight});
5454
if (!rectId) {
5555
logError("Could not fit texture with size ({}, {})", "BlockTextureManager", textureWidth, textureHeight);
56+
stbi_image_free(pixels);
5657
return 0;
5758
}
5859
}
@@ -81,7 +82,8 @@ void BlockTextureManager::refreshBlockTexture(const std::string& path) {
8182
int textureWidth, texHeight, texChannels;
8283
stbi_uc* pixels = stbi_load(path.c_str(), &textureWidth, &texHeight, &texChannels, STBI_rgb_alpha);
8384
if (!pixels) {
84-
throwFatalError("Failed to load texture: " + path);
85+
logError("Failed to load texture: {}", "", path);
86+
return;
8587
}
8688

8789
if (blockTexture.textureSize.x != textureWidth || blockTexture.textureSize.y != texHeight) {
@@ -94,6 +96,7 @@ void BlockTextureManager::refreshBlockTexture(const std::string& path) {
9496
textureWidth,
9597
texHeight
9698
);
99+
stbi_image_free(pixels);
97100
return;
98101
}
99102

src/gpu/renderer/viewport/blockTextureManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct BlockTextureArray {
2525
~BlockTextureArray();
2626
};
2727

28-
typedef unsigned int BlockTextureId;
28+
typedef uint32_t BlockTextureId;
2929

3030
struct BlockTexture {
3131
public:

src/gpu/renderer/viewport/logic/chunking/vulkanChunker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "gpu/mainRenderer.h"
1212
#include "gpu/renderer/viewport/blockTextureManager.h"
1313

14-
const int CHUNK_SIZE = 16;
14+
const int CHUNK_SIZE = 32;
1515
coordinate_t getChunk(coordinate_t in) { return std::floor((float)in / (float)CHUNK_SIZE) * (int)CHUNK_SIZE; }
1616
Position getChunk(Position in) {
1717
in.x = getChunk(in.x);
@@ -551,18 +551,18 @@ std::vector<std::shared_ptr<VulkanLogicAllocation>> VulkanChunker::getAllocation
551551
max = getChunk(max + Vector(1));
552552

553553
// go through each chunk in view and collect it if it exists and has an allocation
554-
std::set<LogicGroup*> logicGroups;
554+
std::set<LogicGroup*> logicGroupsToRender;
555555
for (coordinate_t chunkX = min.x; chunkX <= max.x; chunkX += CHUNK_SIZE) {
556556
for (coordinate_t chunkY = min.y; chunkY <= max.y; chunkY += CHUNK_SIZE) {
557557
auto groupsAtChunkIter = chunkToGroups.find({ chunkX, chunkY });
558558
if (groupsAtChunkIter == chunkToGroups.end()) continue;
559559
for (LogicGroup* group : groupsAtChunkIter->second) {
560-
if (group->getAllocation().has_value()) logicGroups.insert(group);
560+
if (group->getAllocation().has_value()) logicGroupsToRender.insert(group);
561561
}
562562
}
563563
}
564564
std::vector<std::shared_ptr<VulkanLogicAllocation>> seen;
565-
for (LogicGroup* group : logicGroups) {
565+
for (LogicGroup* group : logicGroupsToRender) {
566566
seen.push_back(group->getAllocation().value());
567567
}
568568

src/gpu/renderer/viewport/viewportRenderer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ void ViewportRenderer::render(Frame& frame, ViewportRenderData* viewport) {
2222
#endif
2323
// get view data
2424
ViewportViewData viewData = viewport->getViewData();
25+
if (viewData.viewport.height == 0 || viewData.viewport.width == 0) {
26+
return; // sometimes it wont be the correct size immediately
27+
}
2528

2629
// set dynamic state
2730
vkCmdSetViewport(frame.mainCommandBuffer, 0, 1, &viewData.viewport);

0 commit comments

Comments
 (0)