Skip to content

Commit

Permalink
Episode logos, fixed Esc in main menu, improved Sounds menu, custom l…
Browse files Browse the repository at this point in the history
…evels list async loading, minor changes
  • Loading branch information
deathkiller committed Dec 10, 2023
1 parent 8f83e2a commit e0c76d4
Show file tree
Hide file tree
Showing 28 changed files with 420 additions and 118 deletions.
8 changes: 4 additions & 4 deletions Sources/Jazz2/Actors/Solid/PowerUpMorphMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace Jazz2::Actors::Solid
auto& players = _levelHandler->GetPlayers();
for (auto& player : players) {
std::optional<PlayerType> playerType = GetTargetType(player->GetPlayerType());
if (playerType.has_value()) {
switch (playerType.value()) {
if (playerType) {
switch (*playerType) {
case PlayerType::Jazz: PreloadMetadataAsync("Interactive/PlayerJazz"_s); break;
case PlayerType::Spaz: PreloadMetadataAsync("Interactive/PlayerSpaz"_s); break;
case PlayerType::Lori: PreloadMetadataAsync("Interactive/PlayerLori"_s); break;
Expand Down Expand Up @@ -108,8 +108,8 @@ namespace Jazz2::Actors::Solid
void PowerUpMorphMonitor::DestroyAndApplyToPlayer(Player* player)
{
std::optional<PlayerType> playerType = GetTargetType(player->GetPlayerType());
if (playerType.has_value()) {
player->MorphTo(playerType.value());
if (playerType) {
player->MorphTo(*playerType);

DecreaseHealth(INT32_MAX, player);
PlaySfx("Break"_s);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Compatibility/JJ2Anims.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Jazz2::Compatibility
class JJ2Anims // .j2a
{
public:
static constexpr uint16_t CacheVersion = 11;
static constexpr uint16_t CacheVersion = 12;

static bool Convert(const StringView& path, const StringView& targetPath, bool isPlus);

Expand Down
61 changes: 49 additions & 12 deletions Sources/Jazz2/Compatibility/JJ2Episode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "JJ2Episode.h"
#include "JJ2Anims.h"
#include "JJ2Anims.Palettes.h"
#include "../ContentResolver.h"

#include "../../nCine/Base/Algorithms.h"
Expand All @@ -9,6 +11,16 @@ using namespace Death::IO;

namespace Jazz2::Compatibility
{
JJ2Episode::JJ2Episode()
: Position(0), TitleWidth(0), TitleHeight(0)
{
}

JJ2Episode::JJ2Episode(const String& name, const String& displayName, const String& firstLevel, int32_t position)
: Name(name), DisplayName(displayName), FirstLevel(firstLevel), Position(position), TitleWidth(0), TitleHeight(0)
{
}

bool JJ2Episode::Open(const StringView& path)
{
auto s = fs::Open(path, FileAccessMode::Read);
Expand Down Expand Up @@ -67,30 +79,32 @@ namespace Jazz2::Compatibility
FirstLevel = String(tmpBuffer, length);
lowercaseInPlace(FirstLevel);

// TODO: Episode images are not supported yet
/*int32_t width =*/ s->ReadValue<int32_t>();
/*int32_t height =*/ s->ReadValue<int32_t>();
/*int32_t unknown2 =*/ s->ReadValue<int32_t>();
/*int32_t unknown3 =*/ s->ReadValue<int32_t>();

/*int32_t titleWidth =*/ s->ReadValue<int32_t>();
/*int32_t titleHeight =*/ s->ReadValue<int32_t>();
TitleWidth = s->ReadValue<int32_t>();
TitleHeight = s->ReadValue<int32_t>();
/*int32_t unknown4 =*/ s->ReadValue<int32_t>();
/*int32_t unknown5 =*/ s->ReadValue<int32_t>();

// TODO
/*{
int imagePackedSize = s->ReadValue<int32_t>();
int imageUnpackedSize = width * height;
JJ2Block imageBlock(s, imagePackedSize, imageUnpackedSize);
{
int32_t imagePackedSize = s->ReadValue<int32_t>();
//int imageUnpackedSize = width * height;
//JJ2Block imageBlock(s, imagePackedSize, imageUnpackedSize);
//episode.image = ConvertIndicesToRgbaBitmap(width, height, imageBlock, false);

// Skip it for now
s->Seek(imagePackedSize, SeekOrigin::Current);
}
{
int titleLightPackedSize = s->ReadValue<int32_t>();
int titleLightUnpackedSize = titleWidth * titleHeight;
int32_t titleLightPackedSize = s->ReadValue<int32_t>();
int32_t titleLightUnpackedSize = TitleWidth * TitleHeight;
JJ2Block titleLightBlock(s, titleLightPackedSize, titleLightUnpackedSize);
episode.titleLight = ConvertIndicesToRgbaBitmap(titleWidth, titleHeight, titleLightBlock, true);
}*/
TitleData = std::make_unique<uint8_t[]>(titleLightUnpackedSize);
titleLightBlock.ReadRawBytes(TitleData.get(), titleLightUnpackedSize);
}
//{
// int titleDarkPackedSize = r.ReadInt32();
// int titleDarkUnpackedSize = titleWidth * titleHeight;
Expand Down Expand Up @@ -161,5 +175,28 @@ namespace Jazz2::Compatibility
so->WriteValue<uint8_t>(0);
so->WriteValue<uint8_t>(0);
}

// Write episode logo
so->WriteValue<uint16_t>((uint16_t)TitleWidth);
so->WriteValue<uint16_t>((uint16_t)TitleHeight);

uint32_t titlePixelsCount = TitleWidth * TitleHeight;
std::unique_ptr<uint8_t[]> titlePixels = std::make_unique<uint8_t[]>(titlePixelsCount * 4);
for (uint32_t i = 0; i < titlePixelsCount; i++) {
uint8_t colorIdx = TitleData[i];

// Remove shadow
if (colorIdx == 63 || colorIdx == 143) {
colorIdx = 0;
}

const Color& src = MenuPalette[colorIdx];
titlePixels[i * 4] = src.R;
titlePixels[i * 4 + 1] = src.G;
titlePixels[i * 4 + 2] = src.B;
titlePixels[i * 4 + 3] = src.A;
}

JJ2Anims::WriteImageToFileInternal(so, titlePixels.get(), TitleWidth, TitleHeight, 4);
}
}
14 changes: 5 additions & 9 deletions Sources/Jazz2/Compatibility/JJ2Episode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ namespace Jazz2::Compatibility
String FirstLevel;
String PreviousEpisode;
String NextEpisode;
int32_t TitleWidth;
int32_t TitleHeight;
std::unique_ptr<uint8_t[]> TitleData;

JJ2Episode() { }

JJ2Episode(const String& name, const String& displayName, const String& firstLevel, int position)
: Name(name), DisplayName(displayName), FirstLevel(firstLevel), Position(position)
{
}
JJ2Episode();
JJ2Episode(const String& name, const String& displayName, const String& firstLevel, int32_t position);

bool Open(const StringView& path);

void Convert(const String& targetPath, std::function<JJ2Level::LevelToken(const StringView&)> levelTokenConversion = nullptr, std::function<String(JJ2Episode*)> episodeNameConversion = nullptr, std::function<Pair<String, String>(JJ2Episode*)> episodePrevNext = nullptr);

private:
//std::unique_ptr<uint8_t[]> _titleLight;
};
}
6 changes: 3 additions & 3 deletions Sources/Jazz2/Compatibility/JJ2Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace Death::Containers::Literals;
using namespace Death::IO;
using namespace nCine;

static constexpr uint16_t Windows1250_Utf8[256] = {
static const uint16_t Windows1250_Utf8[256] = {
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
Expand All @@ -27,7 +27,7 @@ static constexpr uint16_t Windows1250_Utf8[256] = {
0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9
};

static constexpr uint32_t DefaultFontColors[] = {
static const uint32_t DefaultFontColors[] = {
0x707485,
0x409062,
0x629040,
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace Jazz2::Compatibility
colorFrozen = false;
colorIndex = 0;
}
} else if (current == '|' && colorRandom) {
} else if (current == '|') {
// Skip one color
if (!colorFrozen) {
colorIndex++;
Expand Down
18 changes: 16 additions & 2 deletions Sources/Jazz2/ContentResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ namespace Jazz2
}
}

std::optional<Episode> ContentResolver::GetEpisode(const StringView& name)
std::optional<Episode> ContentResolver::GetEpisode(const StringView& name, bool withLogo)
{
String fullPath = fs::CombinePath({ GetContentPath(), "Episodes"_s, name + ".j2e"_s });
if (!fs::IsReadableFile(fullPath)) {
Expand All @@ -1238,7 +1238,7 @@ namespace Jazz2
return GetEpisodeByPath(fullPath);
}

std::optional<Episode> ContentResolver::GetEpisodeByPath(const StringView& path)
std::optional<Episode> ContentResolver::GetEpisodeByPath(const StringView& path, bool withLogo)
{
auto s = fs::Open(path, FileAccessMode::Read);
if (s->GetSize() < 16) {
Expand Down Expand Up @@ -1274,6 +1274,20 @@ namespace Jazz2
episode.NextEpisode = String(NoInit, nameLength);
s->Read(episode.NextEpisode.data(), nameLength);

if (withLogo && !_isHeadless) {
std::uint16_t titleWidth = s->ReadValue<std::uint16_t>();
std::uint16_t titleHeight = s->ReadValue<std::uint16_t>();
if (titleWidth > 0 && titleHeight > 0) {
std::unique_ptr<std::uint32_t[]> pixels = std::make_unique<std::uint32_t[]>(titleWidth * titleHeight);
ReadImageFromFile(s, (std::uint8_t*)pixels.get(), titleWidth, titleHeight, 4);

episode.TitleLogo = std::make_unique<Texture>(path.data(), Texture::Format::RGBA8, titleWidth, titleHeight);
episode.TitleLogo->loadFromTexels((unsigned char*)pixels.get(), 0, 0, titleWidth, titleHeight);
episode.TitleLogo->setMinFiltering(SamplerFilter::Nearest);
episode.TitleLogo->setMagFiltering(SamplerFilter::Nearest);
}
}

return episode;
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/ContentResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ namespace Jazz2
bool TryLoadLevel(const StringView& path, GameDifficulty difficulty, LevelDescriptor& descriptor);
void ApplyDefaultPalette();

std::optional<Episode> GetEpisode(const StringView& name);
std::optional<Episode> GetEpisodeByPath(const StringView& path);
std::optional<Episode> GetEpisode(const StringView& name, bool withLogo = false);
std::optional<Episode> GetEpisodeByPath(const StringView& path, bool withLogo = false);
std::unique_ptr<AudioStreamPlayer> GetMusic(const StringView& path);
UI::Font* GetFont(FontType fontType);
Shader* GetShader(PrecompiledShader shader);
Expand Down
4 changes: 4 additions & 0 deletions Sources/Jazz2/PreferencesCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ namespace Jazz2

void PreferencesCache::RemoveEpisodeContinue(const StringView& episodeName)
{
if (episodeName.empty() || episodeName == "unknown"_s) {
return;
}

_episodeContinue.erase(String::nullTerminatedView(episodeName));
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace Jazz2
String PreviousEpisode;
String NextEpisode;
std::uint16_t Position;
std::unique_ptr<Texture> TitleLogo;

Episode() noexcept;
};
Expand Down
18 changes: 12 additions & 6 deletions Sources/Jazz2/UI/Menu/AboutSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endif

#if defined(WITH_SDL)
# define _i6 ", SDL"
# define _i6 ", SDL2"
#else
# define _i6 ""
#endif
Expand Down Expand Up @@ -87,19 +87,25 @@
# define _i13 ""
#endif

#if defined(DEATH_CPU_USE_RUNTIME_DISPATCH)
# define _i14 ", GNU IFUNC"
#if defined(WITH_MULTIPLAYER)
# define _i14 ", ENet"
#else
# define _i14 ""
#endif

#if defined(WITH_TRACY)
# define _i15 "\n\nTracy integration is enabled!"
#if defined(DEATH_CPU_USE_RUNTIME_DISPATCH)
# define _i15 ", GNU IFUNC"
#else
# define _i15 ""
#endif

#define ADDITIONAL_INFO _i1 _i2 _i3 _i4 _i5 _i6 _i7 _i8 _i9 _i10 _i11 _i12 _i13 _i14 _i15
#if defined(WITH_TRACY)
# define _i16 "\n\nTracy integration is enabled!"
#else
# define _i16 ""
#endif

#define ADDITIONAL_INFO _i1 _i2 _i3 _i4 _i5 _i6 _i7 _i8 _i9 _i10 _i11 _i12 _i13 _i14 _i15 _i16

using namespace Jazz2::UI::Menu::Resources;

Expand Down
4 changes: 2 additions & 2 deletions Sources/Jazz2/UI/Menu/BeginSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ namespace Jazz2::UI::Menu
ExecuteSelected();
} else if (_root->ActionHit(PlayerActions::Menu)) {
#if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS) && !defined(DEATH_TARGET_SWITCH)
if (_selectedIndex != (int32_t)Item::Quit) {
if (_selectedIndex != (int32_t)_items.size() - 1) {
_root->PlaySfx("MenuSelect"_s, 0.6f);
_animation = 0.0f;
_selectedIndex = (int32_t)Item::Quit;
_selectedIndex = (int32_t)_items.size() - 1;
}
#endif
} else if (_root->ActionHit(PlayerActions::Up)) {
Expand Down
Loading

0 comments on commit e0c76d4

Please sign in to comment.