game-loop

Setting off a interval on application launch in a Haskell Servant app

送分小仙女□ 提交于 2019-12-11 07:24:06
问题 I'm trying to build the backend for a browser based game using Servant, I want to have some kind of game loop that lets me fire out requests every x seconds. I already have some game state contained in an IORef , and as an initial attempt to get something working I am trying to update my state value every 2 seconds. Here is what I have: {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE

std::chrono - fixed time step loop

送分小仙女□ 提交于 2019-12-11 04:23:05
问题 I'm trying to make fixed time step loop with using < chrono >. This is my code: #include <iostream> #include <chrono> int main() { std::chrono::steady_clock::time_point start; const double timePerFrame = 1.0 / 60.0; double accumulator = 0.0; int i = 0; while(true) { start = std::chrono::steady_clock::now(); while(accumulator >= timePerFrame) { accumulator -= timePerFrame; std::cout << ++i << std::endl; //update(); } accumulator += std::chrono::duration_cast<std::chrono::duration<double>>(std:

C++ game loop example

一笑奈何 提交于 2019-12-10 19:51:11
问题 Can someone write up a source for a program that just has a "game loop", which just keeps looping until you press Esc, and the program shows a basic image. Heres the source I have right now but I have to use SDL_Delay(2000); to keep the program alive for 2 seconds, during which the program is frozen. #include "SDL.h" int main(int argc, char* args[]) { SDL_Surface* hello = NULL; SDL_Surface* screen = NULL; SDL_Init(SDL_INIT_EVERYTHING); screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

How to safely decouple rendering from updating the model?

风流意气都作罢 提交于 2019-12-09 16:02:26
问题 Talking with some game developers, they suggested that a performant OpenGL ES based game engine does not handle everything on the main thread. This allows the game engine to perform better on devices with multiple CPU cores. They said that I could decouple updates from rendering. So if I understood this correct, a game engine run loop can work like this: Setup a CADisplayLink which calls a render method. render method renders current world model in background. render method then calls update

Animation ist only smooth when ontouchevent is called

跟風遠走 提交于 2019-12-08 09:29:07
问题 i'm making my first 2d sidescroller game using a surfaceview and a canvas to draw things on (a lot of primitives put in different path objects). my game loop uses fixed timesteps with linear interpolation. i don't create any objects during the game. i've been improving my code for 3 weeks now, but my animation is still not all the time smooth. it's ok, but every few seconds there are a lot of little hicks for about 1 or 2 seconds. what i recognized is when i move my player (this means

create game loop thread

限于喜欢 提交于 2019-12-06 11:29:26
问题 Hi I have just been messing about polygons and awt. I have created a Jframe and can draw the polygons ok and have one of them move with keypresses. I'm wondering how to start a gameloop thread(and where to put it!) that will update the jframe independently. From googling im led to believe that I should have one thread for user input and one for the game itself. At the moment I have implemented KeyListener on the board class(code shown below),should I put that out into its own class and make

Some questions regarding game loop, tick and real time programming

喜你入骨 提交于 2019-12-06 07:50:03
问题 First I want to apologize for my approximate English, as I'm French. I'm currently making a real-time game in java, using LWJGL. I have some questions regarding game loops: I'm running the rendering routine in a thread. Is it a good idea? Usually, the rendering routine is fairly slow and should not slow down the world update (tick) routine, which is way more important. So I guess using a thread here seems like a good idea (minus the complications from using a thread). In the world update

Windows Game Loop 50% CPU on Dual Core

≡放荡痞女 提交于 2019-12-06 04:25:53
问题 The game loop alone is using 50% of CPU Usage, I haven't done any rendering work yet. What I'm doing here? while(true) { if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT || msg.message == WM_CLOSE || msg.message == WM_DESTROY) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { //Run game code, break out of loop when the game is over } } 回答1: Classic busy/wait loop. Your CPU is busily checking (and rechecking ad infinitum) for messages. You need to wait for

How to appear and disappear an object on screen using game loop for every five second

十年热恋 提交于 2019-12-05 03:14:42
问题 I am trying to learn game development in android. First I am trying to appear and disappear an object on screen using game loop for every five second. But I did not get succeed. I have read different tutorials and forums. I applied all things as in tutorials but still object is drawing continuously. It is not disappearing. I a not getting what I am missing? Please guide me. The complete code is here: MainGameActivity.java package com.example.showandhideobject; import android.app.Activity;

Android SurfaceView slows if no touch events occur

£可爱£侵袭症+ 提交于 2019-12-05 02:11:27
问题 I am making a game and all is going well except for the game loop. I am using a SurfaceView and drawing 2D Sprites (Bitmaps). Currently the game is a ship moving through an asteroid field. The ship stays in the center of the screen and the phone is tilted in either direction to move the the asteroids (asteroids change location instead of player). New asteroids spawn as old ones fall off the screen creating an infinite asteroid field feeling. Running on my Nexus 5, I noticed that after about 3