我正在通过进化计算对应用程序进行编码,如果我以60fps渲染每次迭代需要花费大量时间,因此我以这种方式更改了DesktopLauncher:
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height = 800;
config.width = 800;
config.vSyncEnabled = false; // Setting to false disables vertical sync
//config.foregroundFPS = 60; // Setting to 60 fps throttling
config.foregroundFPS = 0; // Setting to 0 disables foreground fps throttling
config.backgroundFPS = 0; // Setting to 0 disables background fps throttling
new LwjglApplication(new MyApp(), config);
}
}
现在让我们说吧;每次迭代完成后,我希望我的应用程序限制为60 fps(或启用V-Sync),如何访问/修改配置?
public class RandomScreenClass {
...
@Override
public void render(float deltaTime) {
if(..)
{
//modify the fps / turn on v-sync
}
答案 0 :(得分:2)
我找不到一个"幻想"改变LwjglConfig的方法,我找不到一个吸气剂,但这有效:
在核心项目中创建一个包含两个方法的接口,比如说setForegroundFPS和setBackgroundFPS:
SELECT SUBSTRING(description,
CHARINDEX('BuildNumber', description) + 11, --The position after BuildNumber: (a)
CHARINDEX('][SubBuild', description) - 3 - CHARINDEX('BuildNumber', description) + 11)) --The distance from (a) to the square brackets before SubBuild
将Callback添加为游戏类的成员,并创建一个合适的构造函数来接收它
public interface Callback {
void setForegroundFPS(int foregroundFPS);
void setBackgroundFPS(int backgroundFPS);
}
在您的桌面项目中,实现回调,如此
public YourGame(Callback callback) {
this.callback = callback;
...
}
请注意,我忽略了vSync,因为它已在:
中提供 public static void main(String[] arg) {
final LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
new LwjglApplication(new YourGame(new Callback() {
@Override
public void setForegroundFPS(int foregroundFPS) {
config.foregroundFPS = foregroundFPS;
}
@Override
public void setBackgroundFPS(int backgroundFPS) {
config.backgroundFPS = backgroundFPS;
}
}), config);
}