ECS slides
This commit is contained in:
parent
0a7deada40
commit
1d7f54494a
63
slides.tex
63
slides.tex
@ -6,6 +6,8 @@
|
||||
|
||||
\usetheme{metropolis}
|
||||
|
||||
\usepackage{outlines}
|
||||
|
||||
\usepackage{minted}
|
||||
\setminted{fontsize=\footnotesize,samepage=true}
|
||||
%\usepackage{xcolor}
|
||||
@ -66,12 +68,69 @@ Hate
|
||||
\item git-modules - do not bloat contributions
|
||||
}
|
||||
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS - almost?}
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS}
|
||||
Why an ECS - Entity Component System?
|
||||
\begin{itemize}
|
||||
\item Encourages reusable code
|
||||
\item "Plug-and-play" to add functionality
|
||||
\item We found a video tutorial series for it
|
||||
\item Simplified implementation: Entities propagate updates to the components
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
\note[itemize]{
|
||||
\item Reusable code mainly on engine side, but also applies to game dev components
|
||||
\item plug and play mostly an advantage for game dev - i.e. "I want physics, here are physics"
|
||||
\item \say{video series} - tease issue of abruptly ending
|
||||
\item Components usually only have data, and are querried by the system (hence ecS)
|
||||
\item System part used for rendering
|
||||
}
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS - Implementation}
|
||||
\begin{minted}[linenos,autogobble,samepage=false]{c++}
|
||||
class Entity {
|
||||
private:
|
||||
std::vector<std::unique_ptr<Component>> components;
|
||||
ComponentArray componentArray = {};
|
||||
ComponentBitSet componentBitSet;
|
||||
public:
|
||||
void update(uint_fast16_t diffTime) const;
|
||||
template <typename T> bool hasComponent() const {
|
||||
return componentBitSet[getComponentTypeID<T>()];
|
||||
}
|
||||
template <typename T> T& getComponent() const {
|
||||
auto ptr(componentArray[getComponentTypeID<T>()]);
|
||||
return *static_cast<T*>(ptr);
|
||||
}
|
||||
template <typename T, typename...TArgs> T& addComponent(TArgs&&...mArgs) {
|
||||
T* c(new T(std::forward<TArgs>(mArgs)...));
|
||||
c->entity = this;
|
||||
std::unique_ptr<Component> uPtr{ c };
|
||||
this->components.emplace_back(std::move(uPtr));
|
||||
|
||||
componentArray[getComponentTypeID<T>()] = c;
|
||||
componentBitSet[getComponentTypeID<T>()] = true;
|
||||
|
||||
c->init();
|
||||
return *c;
|
||||
};
|
||||
};
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\note[itemize]{
|
||||
\item appologize for formatting - for the sake of compactness
|
||||
\item TypeID: increments through all components - copied from video tutorial
|
||||
\item NOT beginner friendly
|
||||
}
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS - Usage}
|
||||
Very easy to use:
|
||||
\begin{minted}[linenos,autogobble]{c++}
|
||||
auto& projectile(this->manager->addEntity());
|
||||
projectile.addComponent<TransformComponent>(pos.x, pos.y, 32, 32, scale);
|
||||
projectile.addComponent<SpriteComponent>(texture, 4); // 4 => zIndex
|
||||
projectile.addComponent<ProjectileComponent>(range, speed, velocity, owner);
|
||||
projectile.addComponent<ColliderComponent>(0.6f);
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\note{mention: this ease of use is our goal}
|
||||
\begin{frame}[allowframebreaks, fragile]{Memory Management}
|
||||
\begin{minted}[linenos,autogobble]{c++}
|
||||
class Manager
|
||||
@ -99,7 +158,7 @@ Does that solve memory management? Not quite:
|
||||
\end{frame}
|
||||
|
||||
%code example
|
||||
\begin{frame}[fragile]
|
||||
\begin{frame}[fragile]{Hello, World!}
|
||||
\begin{minted}[linenos,autogobble]{c}
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user