Finished lecture 82

Signed-off-by: Daniel Henry <iamdanhenry@gmail.com>
This commit is contained in:
2025-09-02 09:32:30 -05:00
parent 7d2cd86fd4
commit c545d800d2
7 changed files with 149 additions and 92 deletions

View 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

View File

@@ -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

View File

@@ -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