2010-12-27 6 views
1

게임 응용 프로그램에서 초당 프레임 수를 계산하는 방법을 찾고 있는데 문제는 그 중 하나의 응용 프로그램에 대한 소스 코드가 없다는 것입니다. 내부에 이러한 기능이 구현되어 있지 않습니다. 솔직히 말해서 나는 이것이 가능할 것이라고 기대하지는 않지만 묻는 것은 가치가 있었다.안드로이드 게임에서 프레임 초당 계산

FPS를 계산하려면 기본 그림 루프의 기본 지식과 코드가 필요하다는 것을 완전히 이해해야합니다.

안부

답변

0

내가 너무 안드로이드 게임 개발 지식이 있지만, Java2D에에 (그것은 해키 약간의 있지만 ... 작동) 나는 렌더링을 제어하는 ​​편집 JRE 클래스와 항아리를 xboot 것 아니에요 (예 : Canvas)을 프로세스에 추가하십시오.

1

메인 페인트 루프가있을 때 FPS를 계산하는 문제는 무엇입니까?

저는 Android 기능에 익숙하지 않지만 모든 OS의 모든 게임에서 동일하게 수행됩니다. 게임을 만드는 가장 쉬운 방법은 2 개의 스레드를 만드는 것입니다. 첫 번째는 논리 동작 (궤도 계산, 시간 경과에 따른 객체 위치 변경 등)입니다. 두 번째 스레드는 현재 게임 상태 (첫 번째 스레드에 의해 계산 됨)를 취하여 화면에 그립니다.

//Class that contain current game state 
class GameState { 
    private Point objectPosition; 

    public Point getObjectPosition() { 
     return objectPosition; 
    } 

    public void setObjectPosition(Point pos) { 
     this.objectPosition = pos; 
    } 
} 

//Runnable for thread that will calculate changes in game state 
class GameLogics implements Runnable { 
    private GameState gameState; //State of the game 

    public GameLogics(GameState gameState) { 
     this.gameState = gameState; 
    } 

    public void run() { 
     //Main thread loop 
     while (true) { //Some exit check code should be here 
      synchronize (gameState) { 
       gameState.setObjectPosition(gameState.getObjectPosition()+1); //Move object by 1 unit 
      } 
      Thread.sleep(1000); //Wait 1 second until next movement 
     } 
    } 
} 

//Runnable for thread that will draw the game state on the screen 
class GamePainter implements Runnable { 
    private Canvas canvas; //Some kind of canvas to draw object on 
    private GameState gameState; //State of the game 

    public GamePainter(Canvas canvas, GameState gameState) { 
     this.canvas = canvas; 
     this.gameState = gameState; 
    } 

    public void drawStateOnCanvas() { 
     //Some code that is rendering the gameState on canvas 
     canvas.drawLine(...); 
     canvas.drawOtherLine(...); 
     .... 
    } 

    public void run() { 
     //Last time we updated our FPS 
     long lastFpsTime = 0; 
     //How many frames were in last FPS update 
     int frameCounter = 0; 

     //Main thread loop 
        //Main thread loop 
     while (true) { //Some exit check code should be here 
      synchronize (gameState) { 
       //Draw the state on the canvas 
       drawStateOnCanvas(); 
      } 

      //Increment frame counter 
      frameCounter++; 

      int delay = (int)(System.getCurrentTimeMillis() - lastFpsTime); 
      //If last FPS was calculated more than 1 second ago 
      if (delay > 1000) { 
       //Calculate FPS 
       double FPS = (((double)frameCounter)/delay)*1000; //delay is in milliseconds, that's why *1000 
       frameCounter = 0; //Reset frame counter 
       lastFpsTime = System.getCurrentTimeMillis(); //Reset fps timer 

       log.debug("FPS: "+FPS); 
      } 
     } 
    } 
} 
+1

문제는 내가 소스 코드에 액세스 할 수 없다는 것입니다. apk에있는 애플리케이션을 컴파일했을 때만 소스 코드에 액세스 할 수 있기 때문에 쉽게 설명 할 수 있습니다. – ajoz

+0

이런 쓰레기. 메시지에 그 부분을 알리지 않았습니다. 결국 크리스마스 이후 월요일 :) – bezmax

0

This is a good read 게임 루프 : 여기

는 FPS 카운터와 두 스레드 에 주석 코드입니다. 게임 루프의 다양한 구현 및 장단점을 설명합니다.

this is a good tutorial은 Android에서 gameloop + FPS 카운터를 구현하는 데 사용됩니다.

+1

게임 루프 기사는 좋지만 정말 구식입니다. 하나의 스레드에 update()와 render()를 넣는 것은 나쁘다. 특히 스레드를 만들고 관리 할 때 현대 언어 에서처럼 쉽다. – bezmax

관련 문제