MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / MigrateGraphics

Method MigrateGraphics

Sources/Jazz2/ContentResolver.cpp:1851–1965  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1849
1850#if defined(DEATH_DEBUG)
1851 void ContentResolver::MigrateGraphics(StringView path)
1852 {
1853 String auraPath = fs::CombinePath({ GetContentPath(), "Animations"_s, String(path.exceptSuffix(4) + ".aura"_s) });
1854 if (fs::FileExists(auraPath)) {
1855 return;
1856 }
1857
1858 auto s = fs::Open(fs::CombinePath({ GetContentPath(), "Animations"_s, String(path + ".res"_s) }), FileAccess::Read);
1859 auto fileSize = s->GetSize();
1860 if (fileSize < 4 || fileSize > 64 * 1024 * 1024) {
1861 // 64 MB file size limit, also if not found try to use cache
1862 return;
1863 }
1864
1865 auto buffer = std::make_unique<char[]>(fileSize);
1866 s->Read(buffer.get(), fileSize);
1867 s->Dispose();
1868
1869 Json::CharReaderBuilder builder;
1870 auto reader = std::unique_ptr<Json::CharReader>(builder.newCharReader());
1871 Json::Value doc; std::string errors;
1872 if (reader->parse(buffer.get(), buffer.get() + fileSize, &doc, &errors)) {
1873 String fullPath = fs::CombinePath({ GetContentPath(), "Animations"_s, path });
1874 std::unique_ptr<ITextureLoader> texLoader = ITextureLoader::createFromFile(fullPath);
1875 if (texLoader->hasLoaded()) {
1876 auto texFormat = texLoader->texFormat().internalFormat();
1877 if (texFormat != GL_RGBA8 && texFormat != GL_RGB8) {
1878 return;
1879 }
1880
1881 std::int32_t w = texLoader->width();
1882 std::int32_t h = texLoader->height();
1883 const std::uint32_t* palette = _palettes;
1884 bool needsMask = true;
1885
1886 std::int64_t originalFlags;
1887 if (doc["Flags"].get(originalFlags) == Json::SUCCESS) {
1888 // Palette already applied, keep as is
1889 if ((originalFlags & 0x01) != 0x01) {
1890 palette = nullptr;
1891 }
1892 if ((originalFlags & 0x08) == 0x08) {
1893 needsMask = false;
1894 }
1895 }
1896
1897 // TODO: Use FrameDuration instead
1898 double animDuration;
1899 if (doc["Duration"].get(animDuration) != Json::SUCCESS) {
1900 animDuration = 0.0;
1901 }
1902
1903 std::int64_t frameCount;
1904 if (doc["FrameCount"].get(frameCount) != Json::SUCCESS || frameCount < 0) {
1905 frameCount = 0;
1906 }
1907
1908 Vector2i frameDimensions = GetVector2iFromJson(doc["FrameSize"]);

Callers

nothing calls this directly

Calls 15

GetVector2iFromJsonFunction · 0.85
newCharReaderMethod · 0.80
internalFormatMethod · 0.80
StringClass · 0.50
exceptSuffixMethod · 0.45
GetSizeMethod · 0.45
ReadMethod · 0.45
getMethod · 0.45
DisposeMethod · 0.45
parseMethod · 0.45
hasLoadedMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected