I want to create a simple 2D game. I don t want to use threads. The programming language will be Java (but could be any language, does not really matter...).
如果我使用像<条码>(真实性)这样的主要通道,是否有可能避免使用CPU。
I want to create a simple 2D game. I don t want to use threads. The programming language will be Java (but could be any language, does not really matter...).
如果我使用像<条码>(真实性)这样的主要通道,是否有可能避免使用CPU。
在一场游戏中,你通常拥有一个能够管理一切的主要通道。 然而,为了避免做不必要的事情,通常只能以某种框架的形式更新游戏(例如60个框架)。
大部分游戏都取得了这一成绩,使邮联睡觉,直到需要计算/提取新框架。 在python游戏图书馆,pyega, 采用
一定数量的微秒将暂停使用。 这项职能为将处理员与其他方案分享的过程提供了方便。 哪怕只剩下几毫秒的节目将耗费很少的加工时间。
为了说明Darthfett的答案,青少年游戏的主要通道通常会看一看:
#define FRAMELENGTH (1.0 / 60.0) // 60hz = 16.6ms per NTSC frame. Different for PAL.
while ( !QuitSignalled() )
{
double frameStartTime = GetTime(); // imagine microsecond precision
HandleUserInput( PollController() );
SimulateEntities();
Physics();
Render();
Sound();
etc();
double timeUntilNextFrameShouldStart = GetTime() - frameStartTime + FRAMELENGTH;
sleep( timeUntilNextFrameShouldStart );
}
// if down here, we got the quit signal
ExitToDesktop();
当然,如果一个框架需要16.6万多人执行,那么上述漏洞就会消失,因此,我们有特别的守则可以发现这一点,并赶上或缩小范围,但这符合基本的想法。 而且,直到最近,我们才实际使用浮动点号码,但固定点微观秒。
你们都必须做的是“投入的锁定”......并且你获得
简言之,任何袖珍计划都将有类似之处:
while (true) {
select ()
...
您可以轻而易地等待“getchar(
)”或“。
人们可以认为,“I/O的锁”实际上是optimal设计战略。 它是“污染”的替代物之一(Polling is Evil)。
IMHO。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...