Finish lecture 82: Implement the World class
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
7
LightYearsEngine/include/EntryPoint.h
Normal file
7
LightYearsEngine/include/EntryPoint.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace ly {
|
||||
class Application;
|
||||
}
|
||||
|
||||
extern ly::Application* GetApplication();
|
||||
34
LightYearsEngine/include/framework/Application.h
Normal file
34
LightYearsEngine/include/framework/Application.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "framework/Core.h"
|
||||
|
||||
namespace ly {
|
||||
|
||||
class World;
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
void Run();
|
||||
|
||||
template<typename WorldType>
|
||||
weak<World> LoadWorld() {
|
||||
shared<WorldType> newWorld{ new WorldType{this} };
|
||||
currentWorld = newWorld;
|
||||
currentWorld->BeginPlayInternal();
|
||||
return newWorld;
|
||||
}
|
||||
private:
|
||||
void TickInternal(float deltaTime);
|
||||
void RenderInternal();
|
||||
|
||||
virtual void Render();
|
||||
virtual void Tick(float deltaTime);
|
||||
|
||||
sf::RenderWindow mWindow;
|
||||
float mTargetFrameRate;
|
||||
sf::Clock mTickClock;
|
||||
|
||||
shared<World> currentWorld;
|
||||
};
|
||||
|
||||
}
|
||||
30
LightYearsEngine/include/framework/Core.h
Normal file
30
LightYearsEngine/include/framework/Core.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace ly {
|
||||
|
||||
template<typename T>
|
||||
using unique = std::unique_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using shared = std::shared_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using weak = std::weak_ptr<T>;
|
||||
|
||||
template<typename T>
|
||||
using List = std::vector<T>;
|
||||
|
||||
template<typename keyType, typename valueType, typename Pr = std::less<keyType>>
|
||||
using Map = std::map<keyType, valueType, Pr>;
|
||||
|
||||
template<typename keyType, typename valueType, typename Hasher = std::hash<keyType>>
|
||||
using Dictionary = std::map<keyType, valueType, Hasher>;
|
||||
|
||||
// Logging Macro
|
||||
#define LOG(M, ...) printf(M "\n", ##__VA_ARGS__)
|
||||
}
|
||||
21
LightYearsEngine/include/framework/World.h
Normal file
21
LightYearsEngine/include/framework/World.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
namespace ly {
|
||||
class Application;
|
||||
|
||||
class World {
|
||||
public:
|
||||
World(Application *owningApp);
|
||||
|
||||
void BeginPlayInternal();
|
||||
void TickInternal(float deltaTime);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
private:
|
||||
void BeginPlay();
|
||||
void Tick(float deltaTime);
|
||||
Application* mOwningApp;
|
||||
bool mBeganPlay;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user