Skip to content

Commit

Permalink
Headless benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealrann committed Jun 17, 2019
1 parent 07f0673 commit ccf107d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ subprojects {
apply plugin: 'eclipse'
apply plugin: "org.javamodularity.moduleplugin"

version "1.2.1"
version "1.2.2"

sourceCompatibility = 11
targetCompatibility = 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ public interface VSandPackage extends EPackage
*/
int VSAND_APPLICATION__RESIZEABLE = ApplicationPackage.APPLICATION__RESIZEABLE;

/**
* The feature id for the '<em><b>Headless</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int VSAND_APPLICATION__HEADLESS = ApplicationPackage.APPLICATION__HEADLESS;

/**
* The feature id for the '<em><b>Title</b></em>' attribute.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sheepy.vsand;

import org.eclipse.emf.ecore.util.EcoreUtil;
import org.sheepy.lily.core.api.application.ApplicationLauncher;
import org.sheepy.lily.vulkan.model.VulkanEngine;

public class VSandHeadlessBenchmarkLauncher
{
public static void main(String[] args)
{
final var application = VSandBenchmarkLauncher.createTestApplication();
application.setHeadless(true);
final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
EcoreUtil.delete(vulkanEngine.getProcesses().get(1));

final var mainLoop = VSandMainLoop.createBenchmark(application, 1400);

ApplicationLauncher.launch(application, mainLoop);
}
}
51 changes: 31 additions & 20 deletions org.sheepy.vsand/src/main/java/org/sheepy/vsand/VSandMainLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,33 @@ public void load(Application _application)
{
final var vulkanEngine = (VulkanEngine) application.getEngines().get(0);
engineAdapter = IVulkanEngineAdapter.adapt(vulkanEngine);
final Window window = engineAdapter.getWindow();
frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9);
inputManager = engineAdapter.getInputManager();
if (application.isHeadless() == false)
{
final Window window = engineAdapter.getWindow();
frameDurationNs = (long) ((1. / window.getRefreshRate()) * 1e9);
inputManager = engineAdapter.getInputManager();
if (benchmarkMode == false)
{
final var boardSize = new Vector2i(application.getSize());
final var mainDrawManager = new DrawManager(application, inputManager, boardSize);
final var secondaryDrawManager = new DrawManager(application, inputManager,
boardSize);
final var vsandInputManager = new VSandInputManager(window, application,
mainDrawManager, secondaryDrawManager);
inputManager.addListener(vsandInputManager);
}
}

gatherProcesses(vulkanEngine);

final var boardSize = new Vector2i(application.getSize());
final var mainDrawManager = new DrawManager(application, inputManager, boardSize);
final var secondaryDrawManager = new DrawManager(application, inputManager, boardSize);
startNs = System.nanoTime();
nextRenderDate = System.nanoTime() + frameDurationNs;


if (benchmarkMode == false)
if (benchmarkMode == true)
{
final var vsandInputManager = new VSandInputManager(window, application,
mainDrawManager, secondaryDrawManager);
inputManager.addListener(vsandInputManager);
System.out.println("VSand benchmark is running...");
}

startNs = System.nanoTime();
nextRenderDate = System.nanoTime() + frameDurationNs;
}

private void gatherProcesses(VulkanEngine vulkanEngine)
Expand Down Expand Up @@ -106,16 +114,19 @@ public void step(Application _application)
application.setPaused(true);
}

if (benchmarkMode == false)
if (renderProcessAdapter != null)
{
renderProcessAdapter.prepareNextAndExecute();
}
else
{
if (nextRenderDate < System.nanoTime())
if (benchmarkMode == false)
{
renderProcessAdapter.prepareNextAndExecute();
nextRenderDate = System.nanoTime() + frameDurationNs;
}
else
{
if (nextRenderDate < System.nanoTime())
{
renderProcessAdapter.prepareNextAndExecute();
nextRenderDate = System.nanoTime() + frameDurationNs;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,17 @@ public void updateBuffer()
buffer.putInt(application.isShowSleepZones() ? 1 : 0);
buffer.putInt(size.getSize() >> 1);

final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition());
buffer.putInt(cursorPosition.x);
buffer.putInt(cursorPosition.y);
if (inputManager != null)
{
final var cursorPosition = convertToBoardPosition(inputManager.getCursorPosition());
buffer.putInt(cursorPosition.x);
buffer.putInt(cursorPosition.y);
}
else
{
buffer.putInt(0);
buffer.putInt(0);
}

final Material mainMaterial = application.getMainMaterial();
final int index = application.getMaterials().getMaterials().indexOf(mainMaterial);
Expand Down

0 comments on commit ccf107d

Please sign in to comment.