Skip to content

Commit ccf107d

Browse files
committed
Headless benchmark
1 parent 07f0673 commit ccf107d

File tree

6 files changed

+73
-25
lines changed

6 files changed

+73
-25
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ subprojects {
3535
apply plugin: 'eclipse'
3636
apply plugin: "org.javamodularity.moduleplugin"
3737

38-
version "1.2.1"
38+
version "1.2.2"
3939

4040
sourceCompatibility = 11
4141
targetCompatibility = 11

org.sheepy.vsand/src/generated/java/org/sheepy/vsand/model/VSandPackage.java

+9
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ public interface VSandPackage extends EPackage
123123
*/
124124
int VSAND_APPLICATION__RESIZEABLE = ApplicationPackage.APPLICATION__RESIZEABLE;
125125

126+
/**
127+
* The feature id for the '<em><b>Headless</b></em>' attribute.
128+
* <!-- begin-user-doc -->
129+
* <!-- end-user-doc -->
130+
* @generated
131+
* @ordered
132+
*/
133+
int VSAND_APPLICATION__HEADLESS = ApplicationPackage.APPLICATION__HEADLESS;
134+
126135
/**
127136
* The feature id for the '<em><b>Title</b></em>' attribute.
128137
* <!-- begin-user-doc -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.sheepy.vsand;
2+
3+
import org.eclipse.emf.ecore.util.EcoreUtil;
4+
import org.sheepy.lily.core.api.application.ApplicationLauncher;
5+
import org.sheepy.lily.vulkan.model.VulkanEngine;
6+
7+
public class VSandHeadlessBenchmarkLauncher
8+
{
9+
public static void main(String[] args)
10+
{
11+
final var application = VSandBenchmarkLauncher.createTestApplication();
12+
application.setHeadless(true);
13+
final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
14+
EcoreUtil.delete(vulkanEngine.getProcesses().get(1));
15+
16+
final var mainLoop = VSandMainLoop.createBenchmark(application, 1400);
17+
18+
ApplicationLauncher.launch(application, mainLoop);
19+
}
20+
}

org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java

+31-20
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,33 @@ public void load(Application _application)
5656
{
5757
final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
5858
engineAdapter = IVulkanEngineAdapter.adapt(vulkanEngine);
59-
final Window window = engineAdapter.getWindow();
60-
frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9);
61-
inputManager = engineAdapter.getInputManager();
59+
if (application.isHeadless() == false)
60+
{
61+
final Window window = engineAdapter.getWindow();
62+
frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9);
63+
inputManager = engineAdapter.getInputManager();
64+
if (benchmarkMode == false)
65+
{
66+
final var boardSize = new Vector2i(application.getSize());
67+
final var mainDrawManager = new DrawManager(application, inputManager, boardSize);
68+
final var secondaryDrawManager = new DrawManager(application, inputManager,
69+
boardSize);
70+
final var vsandInputManager = new VSandInputManager(window, application,
71+
mainDrawManager, secondaryDrawManager);
72+
inputManager.addListener(vsandInputManager);
73+
}
74+
}
6275

6376
gatherProcesses(vulkanEngine);
6477

65-
final var boardSize = new Vector2i(application.getSize());
66-
final var mainDrawManager = new DrawManager(application, inputManager, boardSize);
67-
final var secondaryDrawManager = new DrawManager(application, inputManager, boardSize);
78+
startNs = System.nanoTime();
79+
nextRenderDate = System.nanoTime() + frameDurationNs;
80+
6881

69-
if (benchmarkMode == false)
82+
if (benchmarkMode == true)
7083
{
71-
final var vsandInputManager = new VSandInputManager(window, application,
72-
mainDrawManager, secondaryDrawManager);
73-
inputManager.addListener(vsandInputManager);
84+
System.out.println("VSand benchmark is running...");
7485
}
75-
76-
startNs = System.nanoTime();
77-
nextRenderDate = System.nanoTime() + frameDurationNs;
7886
}
7987

8088
private void gatherProcesses(VulkanEngine vulkanEngine)
@@ -106,16 +114,19 @@ public void step(Application _application)
106114
application.setPaused(true);
107115
}
108116

109-
if (benchmarkMode == false)
117+
if (renderProcessAdapter != null)
110118
{
111-
renderProcessAdapter.prepareNextAndExecute();
112-
}
113-
else
114-
{
115-
if (nextRenderDate < System.nanoTime())
119+
if (benchmarkMode == false)
116120
{
117121
renderProcessAdapter.prepareNextAndExecute();
118-
nextRenderDate = System.nanoTime() + frameDurationNs;
122+
}
123+
else
124+
{
125+
if (nextRenderDate < System.nanoTime())
126+
{
127+
renderProcessAdapter.prepareNextAndExecute();
128+
nextRenderDate = System.nanoTime() + frameDurationNs;
129+
}
119130
}
120131
}
121132

org.sheepy.vsand/src/main/java/org/sheepy/vsand/constants/VSandPushConstantAdapter.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,17 @@ public void updateBuffer()
9393
buffer.putInt(application.isShowSleepZones() ? 1 : 0);
9494
buffer.putInt(size.getSize() >> 1);
9595

96-
final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition());
97-
buffer.putInt(cursorPosition.x);
98-
buffer.putInt(cursorPosition.y);
96+
if (inputManager != null)
97+
{
98+
final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition());
99+
buffer.putInt(cursorPosition.x);
100+
buffer.putInt(cursorPosition.y);
101+
}
102+
else
103+
{
104+
buffer.putInt(0);
105+
buffer.putInt(0);
106+
}
99107

100108
final Material mainMaterial = application.getMainMaterial();
101109
final int index = application.getMaterials().getMaterials().indexOf(mainMaterial);

0 commit comments

Comments
 (0)