-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract render stats and fix any lingering resources
- Loading branch information
Showing
11 changed files
with
129 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/EngineStats.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2024, Emanuel Rabina (http://www.ultraq.net.nz/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nz.net.ultraq.redhorizon.engine | ||
|
||
import nz.net.ultraq.redhorizon.engine.audio.AudioRenderer | ||
import nz.net.ultraq.redhorizon.engine.audio.AudioRendererEvent | ||
import nz.net.ultraq.redhorizon.engine.audio.BufferCreatedEvent | ||
import nz.net.ultraq.redhorizon.engine.audio.BufferDeletedEvent | ||
import nz.net.ultraq.redhorizon.engine.audio.SourceCreatedEvent | ||
import nz.net.ultraq.redhorizon.engine.audio.SourceDeletedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.DrawEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.FramebufferCreatedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.FramebufferDeletedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRenderer | ||
import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRendererEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.MeshCreatedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.MeshDeletedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.TextureCreatedEvent | ||
import nz.net.ultraq.redhorizon.engine.graphics.TextureDeletedEvent | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
/** | ||
* A record of several stats that we want to track for debugging purposes. | ||
* | ||
* @author Emanuel Rabina | ||
*/ | ||
@Singleton | ||
class EngineStats { | ||
|
||
final AtomicInteger drawCalls = new AtomicInteger() | ||
final AtomicInteger activeFramebuffers = new AtomicInteger() | ||
final AtomicInteger activeMeshes = new AtomicInteger() | ||
final AtomicInteger activeTextures = new AtomicInteger() | ||
|
||
final AtomicInteger activeSources = new AtomicInteger() | ||
final AtomicInteger activeBuffers = new AtomicInteger() | ||
|
||
/** | ||
* Add the audio renderer to get stats on audio sources, buffers, etc. | ||
*/ | ||
EngineStats attachAudioRenderer(AudioRenderer audioRenderer) { | ||
|
||
audioRenderer.on(AudioRendererEvent) { event -> | ||
switch (event) { | ||
case BufferCreatedEvent -> activeBuffers.incrementAndGet() | ||
case BufferDeletedEvent -> activeBuffers.decrementAndGet() | ||
case SourceCreatedEvent -> activeSources.incrementAndGet() | ||
case SourceDeletedEvent -> activeSources.decrementAndGet() | ||
} | ||
} | ||
return this | ||
} | ||
|
||
/** | ||
* Add the graphics renderer to get stats on draws, textures, etc. | ||
*/ | ||
EngineStats attachGraphicsRenderer(GraphicsRenderer graphicsRenderer) { | ||
|
||
graphicsRenderer.on(GraphicsRendererEvent) { event -> | ||
switch (event) { | ||
case DrawEvent -> drawCalls.incrementAndGet() | ||
case FramebufferCreatedEvent -> activeFramebuffers.incrementAndGet() | ||
case FramebufferDeletedEvent -> activeFramebuffers.decrementAndGet() | ||
case MeshCreatedEvent -> activeMeshes.incrementAndGet() | ||
case MeshDeletedEvent -> activeMeshes.decrementAndGet() | ||
case TextureCreatedEvent -> activeTextures.incrementAndGet() | ||
case TextureDeletedEvent -> activeTextures.decrementAndGet() | ||
} | ||
} | ||
return this | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.