Compare commits
No commits in common. "72a07395c75600694f5847255d75aa237ab4dfa4" and "b57c137dafb70d35f93c7e493260e8460e6f66f7" have entirely different histories.
72a07395c7
...
b57c137daf
|
@ -6,4 +6,3 @@ banner.txt
|
||||||
print.d
|
print.d
|
||||||
intro.d
|
intro.d
|
||||||
sleep.d
|
sleep.d
|
||||||
game.d
|
|
||||||
|
|
26
src/game.cpp
26
src/game.cpp
|
@ -1,26 +0,0 @@
|
||||||
#include "include/game.h"
|
|
||||||
|
|
||||||
void Game::gameloop(){
|
|
||||||
//This is the main game loop.
|
|
||||||
const int target_fps = 15;
|
|
||||||
const std::chrono::duration<double> target_frame_duration = chrono::duration<double>(1.0 / target_fps);
|
|
||||||
auto previous_time = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
|
|
||||||
while(true){
|
|
||||||
auto current_time = std::chrono::steady_clock::now();
|
|
||||||
chrono::duration<double> elapsed_time = current_time - previous_time;
|
|
||||||
|
|
||||||
// Game logic and rendering here
|
|
||||||
system("clear");
|
|
||||||
cout << "Frame time: " << elapsed_time.count() << " seconds" << endl;
|
|
||||||
|
|
||||||
if (elapsed_time < target_frame_duration) {
|
|
||||||
chrono::duration<double> sleep_time = target_frame_duration - elapsed_time;
|
|
||||||
this_thread::sleep_for(sleep_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
previous_time = chrono::steady_clock::now();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include <cstdlib>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
|
|
||||||
class Game{
|
|
||||||
public:
|
|
||||||
void gameloop();
|
|
||||||
|
|
||||||
};
|
|
|
@ -2,5 +2,4 @@
|
||||||
#include "intro.h"
|
#include "intro.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "game.h"
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -5,9 +5,7 @@ int main (){
|
||||||
//Title title;
|
//Title title;
|
||||||
Title::mainTitle();
|
Title::mainTitle();
|
||||||
//Intro intro;
|
//Intro intro;
|
||||||
//Intro::mainIntro();
|
Intro::mainIntro();
|
||||||
Game game;
|
//cin >> ;
|
||||||
game.gameloop();
|
|
||||||
cin.get();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue