Finished lecture 82
Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
20
LightYearsEngine/include/framework/Actor.h
Normal file
20
LightYearsEngine/include/framework/Actor.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
class World;
|
||||
|
||||
namespace ly {
|
||||
|
||||
class Actor {
|
||||
public:
|
||||
Actor(World *owningWorld);
|
||||
|
||||
void BeginPlayInternal();
|
||||
virtual void BeginPlay();
|
||||
virtual void Tick(float deltaTime);
|
||||
|
||||
private:
|
||||
World *mOwningWorld;
|
||||
bool mHasBeganPlay;
|
||||
};
|
||||
|
||||
} // namespace ly
|
||||
@@ -1,34 +1,38 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "World.h"
|
||||
#include "framework/Core.h"
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
namespace ly {
|
||||
|
||||
class World;
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
void Run();
|
||||
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();
|
||||
template <typename WorldType>
|
||||
weak<World> LoadWorld();
|
||||
|
||||
virtual void Render();
|
||||
virtual void Tick(float deltaTime);
|
||||
private:
|
||||
void TickInternal(float deltaTime);
|
||||
void RenderInternal();
|
||||
|
||||
sf::RenderWindow mWindow;
|
||||
float mTargetFrameRate;
|
||||
sf::Clock mTickClock;
|
||||
virtual void Render();
|
||||
virtual void Tick(float deltaTime);
|
||||
|
||||
shared<World> currentWorld;
|
||||
};
|
||||
sf::RenderWindow mWindow;
|
||||
float mTargetFrameRate;
|
||||
sf::Clock mTickClock;
|
||||
|
||||
}
|
||||
shared<World> currentWorld;
|
||||
};
|
||||
|
||||
template <typename WorldType>
|
||||
inline weak<World> Application::LoadWorld() {
|
||||
shared<WorldType> newWorld{new WorldType{this}};
|
||||
currentWorld = newWorld;
|
||||
currentWorld->BeginPlayInternal();
|
||||
return newWorld;
|
||||
}
|
||||
|
||||
} // namespace ly
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "framework/Core.h"
|
||||
class Application;
|
||||
class Actor;
|
||||
|
||||
namespace ly {
|
||||
class Application;
|
||||
|
||||
class World {
|
||||
public:
|
||||
World(Application *owningApp);
|
||||
class World {
|
||||
public:
|
||||
World(Application *owningApp);
|
||||
|
||||
void BeginPlayInternal();
|
||||
void TickInternal(float deltaTime);
|
||||
void BeginPlayInternal();
|
||||
void TickInternal(float deltaTime);
|
||||
|
||||
virtual ~World();
|
||||
virtual ~World();
|
||||
|
||||
private:
|
||||
void BeginPlay();
|
||||
void Tick(float deltaTime);
|
||||
Application* mOwningApp;
|
||||
bool mBeganPlay;
|
||||
};
|
||||
}
|
||||
template <typename ActorType>
|
||||
weak<ActorType> SpawnActor() {
|
||||
shared<ActorType> newActor{new ActorType{this}};
|
||||
mPendingActors.push_back(newActor);
|
||||
return newActor;
|
||||
}
|
||||
|
||||
private:
|
||||
void BeginPlay();
|
||||
void Tick(float deltaTime);
|
||||
Application *mOwningApp;
|
||||
bool mBeganPlay;
|
||||
List<shared<Actor>> mActors;
|
||||
List<shared<Actor>> mPendingActors;
|
||||
};
|
||||
} // namespace ly
|
||||
|
||||
Reference in New Issue
Block a user