Cub3d 학습일지 - 6 - 게임 루프 만들기

)대표 사진

 

Raycasting Development with C

Create a raycasting 3D scene using C programming language

courses.pikuma.com

제 6강 Creating a Game Loop 게임 루프 만들기

6.1 Game Loop Overview 게임 루프 살펴보기
6.2
Coding a Fixed Time Step Game Loop Fixed Time Step 게임 루프 코딩하기
6.3
SDL Delay SDL 딜레이

6.1 Game Loop Overview 게임 루프 살펴보기

DeltaTime 델타시간

// difference in ticks from last frame converted to seconds

float deltaTime = (SDL_GetTicks() - ticksLastFrame) / 1000.0f

DeltaTIme is the amount elapsed since the last frame.

We dont think how many pixels-per-frame... but insted we think how many pixels-per-second.

델타시간은 지난 프레임 이후로 얼마나 경과됬는지를 나타내는 양입니다.

우리는 프레임당 몇 픽셀이냐고 생각하지 않고, 초당 몇 픽셀이냐고 생각하잖아요.

// the projectile will move 20 pixels per seconds

projectile.position.x += 20 * deltaTime;

Now our game objects will move correctly regardless of the frame rate.

As a rule. all obj in the scene should be updated as a function of a delta time.


6.2 Coding a Fixed Time Step Game Loop Fixed Time Step 게임 루프 코딩하기

이 코드로 지연시킵니다.

while (!SDL_TICKS_PASSED(SDL_GetTicks(), ticksLastFrame + FRAME_TIME_LENGTH));

6.2 Coding a Fixed Time Step Game Loop Fixed Time Step 게임 루프 코딩하기

아까 while문으로 지연시켰는데, 이렇게 하면 성능에 문제가 생길 수 있습니다.

그래서 SDL_Delay라는 함수를 사용하도록 변경하였습니다.

int				timeToWait = FRAME_TIME_LENGTH - (SDL_GetTicks() - ticksLastFrame);

if (timeToWait > 0 && timeToWait <= FRAME_TIME_LENGTH)
	SDL_Delay(timeToWait);