c++ features
This commit is contained in:
parent
f9eb278c33
commit
0d0df75c87
72
slides.tex
72
slides.tex
@ -91,7 +91,7 @@ Hate
|
||||
|
||||
\subsection{ECS}
|
||||
% ECS slides, split into 3 sections
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS}
|
||||
\begin{frame}[fragile]{We made an ECS}
|
||||
Why an ECS - Entity Component System?
|
||||
\begin{itemize}
|
||||
\item Encourages reusable code
|
||||
@ -143,7 +143,7 @@ public:
|
||||
\item TypeID: increments through all components - copied from video tutorial
|
||||
\item NOT beginner friendly
|
||||
}
|
||||
\begin{frame}[allowframebreaks, fragile]{We made an ECS - Usage}
|
||||
\begin{frame}[fragile]{We made an ECS - Usage}
|
||||
Very easy to use:
|
||||
\begin{minted}[linenos,autogobble]{c++}
|
||||
auto& projectile(this->manager->addEntity());
|
||||
@ -188,7 +188,67 @@ However it does solve memory management\footnote{For \texttt{Entity} classes onl
|
||||
\item classic example of good on surface level only for a beginner; transition to more such examples
|
||||
}
|
||||
|
||||
% Beginner traps
|
||||
\subsection{C++ beginner traps}
|
||||
\begin{frame}[fragile]{C++ - Friend or Foe?}
|
||||
\enquote{I just learned about \underline{\hspace{1cm}}, so I'm going to use it everywhere\dots}
|
||||
|
||||
Please do not take any of our claims as factually accurate or best practice
|
||||
\end{frame}
|
||||
\begin{frame}[fragile]{C++ - Friend or Foe? - Ternary operator}
|
||||
If used in moderation:
|
||||
\begin{minted}[linenos,autogobble,samepage=false,breaklines]{c}
|
||||
void TextureManager::draw( /* ... */, bool flipped)
|
||||
{
|
||||
SDL_FlipMode flip = flipped ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
|
||||
// ...
|
||||
}
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\begin{frame}[allowframebreaks, fragile]{C++ - Friend or Foe? - \texttt{std::ranges}}
|
||||
\begin{minted}[linenos,autogobble,samepage=false,breaklines]{c++}
|
||||
// for each tile set
|
||||
auto tileConstructorRange = std::views::iota(0)
|
||||
| std::views::take(this->mapData.tileSets->size())
|
||||
// return the tile set metadata
|
||||
| std::views::transform([&](uint16_t i) { /* ... */ })
|
||||
| std::views::transform([=, this](const TileSetData& data) {
|
||||
// for each tile on the tile set
|
||||
return std::views::iota(0)
|
||||
| std::views::take(this->mapData.mapSize->x * this->mapData.mapSize->y)
|
||||
// only take tiles that are on the ID range of the tile set
|
||||
| std::views::filter([=](uint16_t idx) { /* ... */ })
|
||||
// extract tile data
|
||||
| std::views::transform([=, this](uint16_t idx) {
|
||||
/* ... */
|
||||
return std::function<Entity*()>(
|
||||
[tilePosX, tilePosY, capture0 = *this->mapData.mapTileSize, u, v, zIndex, capture1 = data.texturePath, collision] {
|
||||
return Map::addTile(tilePosX, tilePosY, capture0, u, v, zIndex, capture1, collision);
|
||||
}
|
||||
);
|
||||
});
|
||||
})
|
||||
// 2D view to 1D vector
|
||||
| std::views::join
|
||||
| std::ranges::to<std::vector>();
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\note[itemize]{
|
||||
\item context:
|
||||
\item readable (sort of), efficient (not really due to to<vector>)
|
||||
\item issues with c++23 (requires at least gcc14)
|
||||
}
|
||||
\begin{frame}[fragile]{C++ - Friend or Foe? - \texttt{std::bitset}}
|
||||
Might be efficient, but\dots
|
||||
\begin{minted}[linenos,autogobble,samepage=false,breaklines]{c++}
|
||||
IntersectionBitSet intersections =
|
||||
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(positionChange.x, 0)) |
|
||||
(this->entity->getManager().getGame()->collisionHandler ->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(positionChange.x, 0), colliders)) & IntersectionBitSet("0011")) |
|
||||
(CollisionHandler::getIntersectionWithBounds(entity, Vector2D(0, positionChange.y)) |
|
||||
(this->entity->getManager().getGame()->collisionHandler ->getAnyIntersection<IntersectionBitSet>(entity, Vector2D(0, positionChange.y), colliders)) & IntersectionBitSet("1100"));
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\note{\dots not very readable}
|
||||
|
||||
%code example
|
||||
\begin{frame}[fragile]{Hello, World!}
|
||||
@ -202,12 +262,6 @@ int main()
|
||||
}
|
||||
\end{minted}
|
||||
\end{frame}
|
||||
\begin{frame}
|
||||
\begin{enumerate}
|
||||
\item Eins
|
||||
\item Zwei
|
||||
\item Drei
|
||||
\end{enumerate}
|
||||
\end{frame}
|
||||
\note{This is just a slide for testing the minted package}
|
||||
|
||||
\end{document}
|
||||
Loading…
x
Reference in New Issue
Block a user