tomato/src/texture_cache.cpp
Green Sky 3647ff3d54
Some checks are pending
ContinuousDelivery / linux-ubuntu (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run
update deps and last seen first seen
2025-01-07 21:30:40 +01:00

59 lines
1.4 KiB
C++

#include "./texture_cache.hpp"
#include <array>
#include <limits>
int64_t TextureEntry::doAnimation(const int64_t ts_now) {
if (frame_duration.size() > 1) { // is animation
do { // why is this loop so ugly
const int64_t duration = getDuration();
if (ts_now - timestamp_last_rendered >= duration) {
timestamp_last_rendered += duration;
next();
} else {
// return ts for next frame
return timestamp_last_rendered + duration;
}
} while (true);
} else {
timestamp_last_rendered = ts_now;
return std::numeric_limits<int64_t>::max(); // static image
}
}
TextureEntry generateTestAnim(TextureUploaderI& tu) {
TextureEntry new_entry;
new_entry.timestamp_last_rendered = getTimeMS();
new_entry.current_texture = 0;
for (size_t i = 0; i < 4; i++) {
// hack
// generate frame
const size_t width {2};
const size_t height {2};
std::array<uint8_t, width*height*4> pixels;
for (size_t pen = 0; pen < width*height; pen++) {
if (pen == i) {
pixels[pen*4+0] = 0xff;
pixels[pen*4+1] = 0xff;
pixels[pen*4+2] = 0xff;
pixels[pen*4+3] = 0xff;
} else {
pixels[pen*4+0] = 0x00;
pixels[pen*4+1] = 0x00;
pixels[pen*4+2] = 0x00;
pixels[pen*4+3] = 0xff;
}
}
const auto n_t = tu.upload(pixels.data(), width, height);
// this is so ugly
new_entry.textures.emplace_back(n_t);
new_entry.frame_duration.emplace_back(250);
}
new_entry.width = 0;
new_entry.height = 0;
return new_entry;
}