Finish lecture 82: Implement the World class
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
8
LightYearsEngine/src/EntryPoint.cpp
Normal file
8
LightYearsEngine/src/EntryPoint.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "EntryPoint.h"
|
||||
#include "framework/Application.h"
|
||||
|
||||
int main() {
|
||||
ly::Application* app = GetApplication();
|
||||
app->Run();
|
||||
delete app;
|
||||
}
|
||||
65
LightYearsEngine/src/framework/Application.cpp
Normal file
65
LightYearsEngine/src/framework/Application.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "framework/Application.h"
|
||||
#include "framework/Core.h"
|
||||
#include "framework/World.h"
|
||||
|
||||
namespace ly {
|
||||
Application::Application():
|
||||
mWindow{sf::VideoMode(1440,1024), "LightYears"},
|
||||
mTargetFrameRate{60.0f},
|
||||
mTickClock{},
|
||||
currentWorld{nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
void Application::Run()
|
||||
{
|
||||
mTickClock.restart();
|
||||
float accumulatedTime = 0.0f;
|
||||
float targetDeltaTime = 1.f / mTargetFrameRate;
|
||||
while (mWindow.isOpen()) {
|
||||
sf::Event windowEvent;
|
||||
while (mWindow.pollEvent(windowEvent)) {
|
||||
if (windowEvent.type == sf::Event::EventType::Closed) {
|
||||
mWindow.close();
|
||||
}
|
||||
}
|
||||
float frameDeltaTime = mTickClock.restart().asSeconds();
|
||||
accumulatedTime += frameDeltaTime;
|
||||
while (accumulatedTime > targetDeltaTime) {
|
||||
accumulatedTime -= targetDeltaTime;
|
||||
TickInternal(targetDeltaTime);
|
||||
RenderInternal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::TickInternal(float deltaTime)
|
||||
{
|
||||
Tick(deltaTime);
|
||||
if (currentWorld) {
|
||||
currentWorld->TickInternal(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::Tick(float deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
void Application::RenderInternal()
|
||||
{
|
||||
mWindow.clear();
|
||||
|
||||
Render();
|
||||
|
||||
mWindow.display();
|
||||
}
|
||||
|
||||
void Application::Render()
|
||||
{
|
||||
sf::RectangleShape rect{ sf::Vector2f{100,100} };
|
||||
rect.setFillColor(sf::Color::Green);
|
||||
rect.setOrigin(50, 50);
|
||||
rect.setPosition(mWindow.getSize().x / 2, mWindow.getSize().y / 2);
|
||||
mWindow.draw(rect);
|
||||
}
|
||||
}
|
||||
0
LightYearsEngine/src/framework/Core.cpp
Normal file
0
LightYearsEngine/src/framework/Core.cpp
Normal file
36
LightYearsEngine/src/framework/World.cpp
Normal file
36
LightYearsEngine/src/framework/World.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "framework/World.h"
|
||||
#include "framework/Core.h"
|
||||
|
||||
namespace ly {
|
||||
World::World(Application* owningApp) : mOwningApp{ owningApp }, mBeganPlay{ false } {
|
||||
|
||||
}
|
||||
|
||||
void World::BeginPlayInternal() {
|
||||
if (!mBeganPlay) {
|
||||
mBeganPlay = true;
|
||||
BeginPlay();
|
||||
}
|
||||
}
|
||||
|
||||
World::~World()
|
||||
{
|
||||
}
|
||||
|
||||
void World::TickInternal(float deltaTime)
|
||||
{
|
||||
Tick(deltaTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void World::BeginPlay()
|
||||
{
|
||||
LOG("Began Play");
|
||||
}
|
||||
|
||||
void World::Tick(float deltaTime)
|
||||
{
|
||||
LOG("Ticking at frame rate: %f", 1.f / deltaTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user