refactoring

This commit is contained in:
Nick Fisher
2025-03-19 12:27:13 +08:00
parent d5bffd5ad2
commit 627447f8b0
65 changed files with 2304 additions and 3005 deletions

View File

@@ -1,5 +1,3 @@
#if __APPLE__
#include "TargetConditionals.h"
#endif
@@ -48,57 +46,39 @@ namespace thermion
using std::string;
static constexpr filament::math::float4 sFullScreenTriangleVertices[3] = {
{-1.0f, -1.0f, 1.0f, 1.0f},
{3.0f, -1.0f, 1.0f, 1.0f},
{-1.0f, 3.0f, 1.0f, 1.0f}};
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
void RenderTicker::setRenderable(SwapChain *swapChain, View **views, uint8_t numViews) {
{
std::lock_guard lock(mMutex);
auto swapChainViews = mRenderable[swapChain];
// Find if this swapChain already exists in our collection
auto it = std::find_if(mRenderable.begin(), mRenderable.end(),
[swapChain](const auto& pair) { return pair.first == swapChain; });
swapChainViews.clear();
// Prepare the vector of views
std::vector<View*> swapChainViews;
for(int i = 0; i < numViews; i++) {
swapChainViews.push_back(views[i]);
}
mRenderable[swapChain] = swapChainViews;
// Keep track of the swapchains, so we can iterate them in the render method.
bool found = false;
for (auto existingSwapChain : mSwapChains) {
if (existingSwapChain == swapChain) {
found = true;
break;
}
}
if (!found) {
mSwapChains.push_back(swapChain);
if (it != mRenderable.end()) {
// Update existing entry
it->second = swapChainViews;
} else {
// Add new entry
mRenderable.emplace_back(swapChain, swapChainViews);
}
}
}
void RenderTicker::render(uint64_t frameTimeInNanos)
{
std::lock_guard lock(mMutex);
// Update all animation managers
for (auto animationManager : mAnimationManagers) {
if (animationManager) { // Check for nullptr just in case
animationManager->update(frameTimeInNanos * 1e-9);
}
animationManager->update(frameTimeInNanos * 1e-9);
}
for (auto swapChain : mSwapChains)
for (const auto& [swapChain, views] : mRenderable)
{
auto views = mRenderable[swapChain];
if (views.size() > 0)
if (!views.empty())
{
bool beginFrame = mRenderer->beginFrame(swapChain, frameTimeInNanos);
if (beginFrame)
@@ -116,19 +96,19 @@ namespace thermion
#endif
}
void RenderTicker::addAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
mAnimationManagers.push_back(animationManager);
}
void RenderTicker::addAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
mAnimationManagers.push_back(animationManager);
}
void RenderTicker::removeAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
auto it = std::find(mAnimationManagers.begin(), mAnimationManagers.end(), animationManager);
if (it != mAnimationManagers.end()) {
mAnimationManagers.erase(it);
}
void RenderTicker::removeAnimationManager(AnimationManager* animationManager) {
std::lock_guard<std::mutex> lock(mMutex);
auto it = std::find(mAnimationManagers.begin(), mAnimationManagers.end(), animationManager);
if (it != mAnimationManagers.end()) {
mAnimationManagers.erase(it);
}
}
RenderTicker::~RenderTicker() {}
RenderTicker::~RenderTicker() {}
} // namespace thermion