저는 C++를 사용하여 게임을 작성하고 있습니다. 내 게임 루프를 어떻게 최적화 할 수 있을지 궁금해. 예를 들어, 메인 루프가있는 게임은 다음과 같습니다.콜백 및 주요 게임 루프. 좋은 습관입니까?
while (gameContinue) {
if (SCENE == HELP_SCENE) {
renderHelpScene();
} else if (SCENE == SCORE_SCENE) {
renderScoreScene();
} else if (SCENE == MAIN_GAME_SCENE) {
renderMainGameScene();
} // .... and many others scenes
}
이 코드를 더 빠르고 가볍게 만드는 방법을 생각하고 있습니다. 우리는 if-case가 많이 필요하지 않도록 콜백을 사용한다고 생각합니다. 다음과 같은 내용 :
typedef void (*callback_function)(void);
callback_function renderFunc;
void renderMainGameScene() {
renderFunc = renderScoreScene(); // set to another scene if we need this
}
void renderScoreScene() {
renderFunc = renderAnyAnotherSceneWeNeedNow();
}
renderFunc = renderMainGameScene();
while (gameContinue) {
renderFunc();
}
당신은 어떻게 생각하십니까? 메인 루프를 어떻게 구성합니까?
게임에서 병목 현상이 발생하면 기쁘게 생각합니다. –
가상'render' 메소드를 사용하는'AbstractScene'을 가지고 있지 않은 이유는 무엇입니까? 또한 위의 의견에 동의합니다. – Nbr44