Skip to content

Commit

Permalink
Fixed build, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jul 5, 2024
1 parent c44f1bf commit 1fa0d75
Show file tree
Hide file tree
Showing 69 changed files with 585 additions and 589 deletions.
120 changes: 60 additions & 60 deletions Sources/Jazz2/ContentResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ namespace Jazz2
_cachedSounds.clear();
#endif

for (int32_t i = 0; i < (int32_t)FontType::Count; i++) {
for (std::int32_t i = 0; i < (std::int32_t)FontType::Count; i++) {
_fonts[i] = nullptr;
}

for (int32_t i = 0; i < (int32_t)PrecompiledShader::Count; i++) {
for (std::int32_t i = 0; i < (std::int32_t)PrecompiledShader::Count; i++) {
_precompiledShaders[i] = nullptr;
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ namespace Jazz2

ondemand::object animations;
if (doc["Animations"].get(animations) == SUCCESS) {
size_t count;
std::size_t count;
if (animations.count_fields().get(count) == SUCCESS) {
metadata->Animations.reserve(count);
}
Expand Down Expand Up @@ -600,7 +600,7 @@ namespace Jazz2
// Don't load sounds in headless mode
ondemand::object sounds;
if (doc["Sounds"].get(sounds) == SUCCESS) {
size_t count;
std::size_t count;
if (sounds.count_fields().get(count) == SUCCESS) {
metadata->Sounds.reserve(count);
}
Expand Down Expand Up @@ -689,14 +689,14 @@ namespace Jazz2
return nullptr;
}

int32_t w = texLoader->width();
int32_t h = texLoader->height();
uint32_t* pixels = (uint32_t*)texLoader->pixels();
const uint32_t* palette = _palettes + paletteOffset;
std::int32_t w = texLoader->width();
std::int32_t h = texLoader->height();
std::uint32_t* pixels = (std::uint32_t*)texLoader->pixels();
const std::uint32_t* palette = _palettes + paletteOffset;
bool linearSampling = false;
bool needsMask = true;

uint64_t flags;
std::uint64_t flags;
if (doc["Flags"].get(flags) == SUCCESS) {
// Palette already applied, keep as is
if ((flags & 0x01) != 0x01) {
Expand All @@ -712,19 +712,19 @@ namespace Jazz2
}

if (needsMask) {
graphics->Mask = std::make_unique<uint8_t[]>(w * h);
graphics->Mask = std::make_unique<std::uint8_t[]>(w * h);

for (int32_t i = 0; i < w * h; i++) {
for (std::int32_t i = 0; i < w * h; i++) {
// Save original alpha value for collision checking
graphics->Mask[i] = ((pixels[i] >> 24) & 0xff);
if (palette != nullptr) {
uint32_t color = palette[pixels[i] & 0xff];
std::uint32_t color = palette[pixels[i] & 0xff];
pixels[i] = (color & 0xffffff) | ((((color >> 24) & 0xff) * ((pixels[i] >> 24) & 0xff) / 255) << 24);
}
}
} else if (palette != nullptr) {
for (int32_t i = 0; i < w * h; i++) {
uint32_t color = palette[pixels[i] & 0xff];
for (std::int32_t i = 0; i < w * h; i++) {
std::uint32_t color = palette[pixels[i] & 0xff];
pixels[i] = (color & 0xffffff) | ((((color >> 24) & 0xff) * ((pixels[i] >> 24) & 0xff) / 255) << 24);
}
}
Expand All @@ -743,11 +743,11 @@ namespace Jazz2
}
graphics->AnimDuration = (float)animDuration;

int64_t frameCount;
std::int64_t frameCount;
if (doc["FrameCount"].get(frameCount) != SUCCESS) {
frameCount = 0;
}
graphics->FrameCount = (int32_t)frameCount;
graphics->FrameCount = (std::int32_t)frameCount;

graphics->FrameDimensions = GetVector2iFromJson(doc["FrameSize"]);
graphics->FrameConfiguration = GetVector2iFromJson(doc["FrameConfiguration"]);
Expand All @@ -766,7 +766,7 @@ namespace Jazz2
return nullptr;
}

GenericGraphicResource* ContentResolver::RequestGraphicsAura(const StringView path, uint16_t paletteOffset)
GenericGraphicResource* ContentResolver::RequestGraphicsAura(const StringView path, std::uint16_t paletteOffset)
{
auto s = OpenContentFile(fs::CombinePath("Animations"_s, path));

Expand All @@ -776,44 +776,44 @@ namespace Jazz2
return nullptr;
}

uint64_t signature1 = s->ReadValue<uint64_t>();
uint32_t signature2 = s->ReadValue<uint16_t>();
uint8_t version = s->ReadValue<uint8_t>();
uint8_t flags = s->ReadValue<uint8_t>();
std::uint64_t signature1 = s->ReadValue<std::uint64_t>();
std::uint32_t signature2 = s->ReadValue<std::uint16_t>();
std::uint8_t version = s->ReadValue<std::uint8_t>();
std::uint8_t flags = s->ReadValue<std::uint8_t>();

if (signature1 != 0xB8EF8498E2BFBBEF || signature2 != 0x208F || version != 2 || (flags & 0x80) != 0x80) {
return nullptr;
}

uint8_t channelCount = s->ReadValue<uint8_t>();
uint32_t frameDimensionsX = s->ReadValue<uint32_t>();
uint32_t frameDimensionsY = s->ReadValue<uint32_t>();
std::uint8_t channelCount = s->ReadValue<std::uint8_t>();
std::uint32_t frameDimensionsX = s->ReadValue<std::uint32_t>();
std::uint32_t frameDimensionsY = s->ReadValue<std::uint32_t>();

uint8_t frameConfigurationX = s->ReadValue<uint8_t>();
uint8_t frameConfigurationY = s->ReadValue<uint8_t>();
uint16_t frameCount = s->ReadValue<uint16_t>();
uint16_t animDuration = s->ReadValue<uint16_t>();
std::uint8_t frameConfigurationX = s->ReadValue<std::uint8_t>();
std::uint8_t frameConfigurationY = s->ReadValue<std::uint8_t>();
std::uint16_t frameCount = s->ReadValue<std::uint16_t>();
std::uint16_t animDuration = s->ReadValue<std::uint16_t>();

uint16_t hotspotX = s->ReadValue<uint16_t>();
uint16_t hotspotY = s->ReadValue<uint16_t>();
std::uint16_t hotspotX = s->ReadValue<std::uint16_t>();
std::uint16_t hotspotY = s->ReadValue<std::uint16_t>();

uint16_t coldspotX = s->ReadValue<uint16_t>();
uint16_t coldspotY = s->ReadValue<uint16_t>();
std::uint16_t coldspotX = s->ReadValue<std::uint16_t>();
std::uint16_t coldspotY = s->ReadValue<std::uint16_t>();

uint16_t gunspotX = s->ReadValue<uint16_t>();
uint16_t gunspotY = s->ReadValue<uint16_t>();
std::uint16_t gunspotX = s->ReadValue<std::uint16_t>();
std::uint16_t gunspotY = s->ReadValue<std::uint16_t>();

uint32_t width = frameDimensionsX * frameConfigurationX;
uint32_t height = frameDimensionsY * frameConfigurationY;
std::uint32_t width = frameDimensionsX * frameConfigurationX;
std::uint32_t height = frameDimensionsY * frameConfigurationY;

std::unique_ptr<uint32_t[]> pixels = std::make_unique<uint32_t[]>(width * height);
std::unique_ptr<std::uint32_t[]> pixels = std::make_unique<std::uint32_t[]>(width * height);

ReadImageFromFile(s, (uint8_t*)pixels.get(), width, height, channelCount);
ReadImageFromFile(s, (std::uint8_t*)pixels.get(), width, height, channelCount);

std::unique_ptr<GenericGraphicResource> graphics = std::make_unique<GenericGraphicResource>();
graphics->Flags |= GenericGraphicResourceFlags::Referenced;

const uint32_t* palette = _palettes + paletteOffset;
const std::uint32_t* palette = _palettes + paletteOffset;
bool linearSampling = false;
bool needsMask = true;
if ((flags & 0x01) == 0x01) {
Expand All @@ -825,19 +825,19 @@ namespace Jazz2
}

if (needsMask) {
graphics->Mask = std::make_unique<uint8_t[]>(width * height);
graphics->Mask = std::make_unique<std::uint8_t[]>(width * height);

for (uint32_t i = 0; i < width * height; i++) {
for (std::uint32_t i = 0; i < width * height; i++) {
// Save original alpha value for collision checking
graphics->Mask[i] = ((pixels[i] >> 24) & 0xff);
if (palette != nullptr) {
uint32_t color = palette[pixels[i] & 0xff];
std::uint32_t color = palette[pixels[i] & 0xff];
pixels[i] = (color & 0xffffff) | ((((color >> 24) & 0xff) * ((pixels[i] >> 24) & 0xff) / 255) << 24);
}
}
} else if (palette != nullptr) {
for (uint32_t i = 0; i < width * height; i++) {
uint32_t color = palette[pixels[i] & 0xff];
for (std::uint32_t i = 0; i < width * height; i++) {
std::uint32_t color = palette[pixels[i] & 0xff];
pixels[i] = (color & 0xffffff) | ((((color >> 24) & 0xff) * ((pixels[i] >> 24) & 0xff) / 255) << 24);
}
}
Expand Down Expand Up @@ -877,7 +877,7 @@ namespace Jazz2
return _cachedGraphics.emplace(Pair(String(path), paletteOffset), std::move(graphics)).first->second.get();
}

void ContentResolver::ReadImageFromFile(std::unique_ptr<Stream>& s, uint8_t* data, int32_t width, int32_t height, int32_t channelCount)
void ContentResolver::ReadImageFromFile(std::unique_ptr<Stream>& s, std::uint8_t* data, std::int32_t width, std::int32_t height, std::int32_t channelCount)
{
typedef union {
struct {
Expand All @@ -899,38 +899,38 @@ namespace Jazz2

rgba_t index[64] { };
rgba_t px;
int32_t run = 0;
int32_t px_len = width * height * channelCount;
std::int32_t run = 0;
std::int32_t px_len = width * height * channelCount;

px.rgba.r = 0;
px.rgba.g = 0;
px.rgba.b = 0;
px.rgba.a = 255;

for (int32_t px_pos = 0; px_pos < px_len; px_pos += channelCount) {
for (std::int32_t px_pos = 0; px_pos < px_len; px_pos += channelCount) {
if (run > 0) {
run--;
} else {
int32_t b1 = s->ReadValue<uint8_t>();
std::int32_t b1 = s->ReadValue<std::uint8_t>();

if (b1 == QOI_OP_RGB) {
px.rgba.r = s->ReadValue<uint8_t>();
px.rgba.g = s->ReadValue<uint8_t>();
px.rgba.b = s->ReadValue<uint8_t>();
px.rgba.r = s->ReadValue<std::uint8_t>();
px.rgba.g = s->ReadValue<std::uint8_t>();
px.rgba.b = s->ReadValue<std::uint8_t>();
} else if (b1 == QOI_OP_RGBA) {
px.rgba.r = s->ReadValue<uint8_t>();
px.rgba.g = s->ReadValue<uint8_t>();
px.rgba.b = s->ReadValue<uint8_t>();
px.rgba.a = s->ReadValue<uint8_t>();
px.rgba.r = s->ReadValue<std::uint8_t>();
px.rgba.g = s->ReadValue<std::uint8_t>();
px.rgba.b = s->ReadValue<std::uint8_t>();
px.rgba.a = s->ReadValue<std::uint8_t>();
} else if ((b1 & QOI_MASK_2) == QOI_OP_INDEX) {
px = index[b1];
} else if ((b1 & QOI_MASK_2) == QOI_OP_DIFF) {
px.rgba.r += ((b1 >> 4) & 0x03) - 2;
px.rgba.g += ((b1 >> 2) & 0x03) - 2;
px.rgba.b += (b1 & 0x03) - 2;
} else if ((b1 & QOI_MASK_2) == QOI_OP_LUMA) {
int32_t b2 = s->ReadValue<uint8_t>();
int32_t vg = (b1 & 0x3f) - 32;
std::int32_t b2 = s->ReadValue<std::uint8_t>();
std::int32_t vg = (b1 & 0x3f) - 32;
px.rgba.r += vg - 8 + ((b2 >> 4) & 0x0f);
px.rgba.g += vg;
px.rgba.b += vg - 8 + (b2 & 0x0f);
Expand All @@ -945,7 +945,7 @@ namespace Jazz2
}
}

std::unique_ptr<Tiles::TileSet> ContentResolver::RequestTileSet(const StringView path, uint16_t captionTileId, bool applyPalette, const uint8_t* paletteRemapping)
std::unique_ptr<Tiles::TileSet> ContentResolver::RequestTileSet(const StringView path, std::uint16_t captionTileId, bool applyPalette, const std::uint8_t* paletteRemapping)
{
// Try "Content" directory first, then "Cache" directory
String fullPath = fs::CombinePath({ GetContentPath(), "Tilesets"_s, String(path + ".j2t"_s) });
Expand Down Expand Up @@ -1566,7 +1566,7 @@ namespace Jazz2
// If the UBO is smaller than 64kb and fixed batch size is disabled, batched shaders need to be compiled twice to determine safe `BATCH_SIZE` define value
const bool compileTwice = (maxUniformBlockSize < 64 * 1024 && appCfg.fixedBatchSize <= 0 && introspection == Shader::Introspection::NoUniformsInBlocks);

int32_t batchSize;
std::int32_t batchSize;
if (appCfg.fixedBatchSize > 0 && introspection == Shader::Introspection::NoUniformsInBlocks) {
batchSize = appCfg.fixedBatchSize;
} else if (compileTwice) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/Jazz2/ContentResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ namespace Jazz2

void PreloadMetadataAsync(const StringView path);
Metadata* RequestMetadata(const StringView path);
GenericGraphicResource* RequestGraphics(const StringView path, uint16_t paletteOffset);
GenericGraphicResource* RequestGraphics(const StringView path, std::uint16_t paletteOffset);

std::unique_ptr<Tiles::TileSet> RequestTileSet(const StringView path, uint16_t captionTileId, bool applyPalette, const uint8_t* paletteRemapping = nullptr);
std::unique_ptr<Tiles::TileSet> RequestTileSet(const StringView path, std::uint16_t captionTileId, bool applyPalette, const std::uint8_t* paletteRemapping = nullptr);
bool LevelExists(const StringView episodeName, const StringView levelName);
bool TryLoadLevel(const StringView path, GameDifficulty difficulty, LevelDescriptor& descriptor);
void ApplyDefaultPalette();
Expand Down Expand Up @@ -107,8 +107,8 @@ namespace Jazz2

void InitializePaths();

GenericGraphicResource* RequestGraphicsAura(const StringView path, uint16_t paletteOffset);
static void ReadImageFromFile(std::unique_ptr<Stream>& s, uint8_t* data, int32_t width, int32_t height, int32_t channelCount);
GenericGraphicResource* RequestGraphicsAura(const StringView path, std::uint16_t paletteOffset);
static void ReadImageFromFile(std::unique_ptr<Stream>& s, std::uint8_t* data, std::int32_t width, std::int32_t height, std::int32_t channelCount);

std::unique_ptr<Shader> CompileShader(const char* shaderName, Shader::DefaultVertex vertex, const char* fragment, Shader::Introspection introspection = Shader::Introspection::Enabled);
std::unique_ptr<Shader> CompileShader(const char* shaderName, const char* vertex, const char* fragment, Shader::Introspection introspection = Shader::Introspection::Enabled);
Expand All @@ -120,7 +120,7 @@ namespace Jazz2

bool _isHeadless;
bool _isLoading;
uint32_t _palettes[PaletteCount * ColorsPerPalette];
std::uint32_t _palettes[PaletteCount * ColorsPerPalette];
HashMap<Reference<String>, std::unique_ptr<Metadata>, FNV1aHashFunc<String>, StringRefEqualTo> _cachedMetadata;
HashMap<Pair<String, uint16_t>, std::unique_ptr<GenericGraphicResource>> _cachedGraphics;
#if defined(WITH_AUDIO)
Expand Down
Loading

0 comments on commit 1fa0d75

Please sign in to comment.