Skip to content

Commit

Permalink
Legacy main menu, cinematics SFX, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Jan 9, 2024
1 parent aee82ac commit 583d099
Show file tree
Hide file tree
Showing 32 changed files with 567 additions and 123 deletions.
13 changes: 13 additions & 0 deletions Content/Metadata/UI/MainMenu.res
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@
"States": [ 56 ]
},

"Menu16": {
"Path": "UI/menu16.aura",
"States": [ 70 ]
},
"Menu32": {
"Path": "UI/menu32.aura",
"States": [ 71 ]
},
"Menu128": {
"Path": "UI/menu128.aura",
"States": [ 72 ]
},

"LoriExistsCheck": {
"Path": "Lori/corpse.aura",
"States": [ 80 ]
Expand Down
43 changes: 33 additions & 10 deletions Sources/Jazz2/Compatibility/AnimSetMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Jazz2::Compatibility
{
AnimSetMapping::AnimSetMapping(JJ2Version version)
: _version(version), _currentItem(0), _currentSet(0), _currentOrdinal(0)
{
}

AnimSetMapping AnimSetMapping::GetAnimMapping(JJ2Version version)
{
AnimSetMapping m(version);
Expand Down Expand Up @@ -1951,47 +1956,52 @@ namespace Jazz2::Compatibility
return m;
}

void AnimSetMapping::DiscardItems(int advanceBy, JJ2Version appliesTo)
void AnimSetMapping::DiscardItems(std::uint32_t advanceBy, JJ2Version appliesTo)
{
if ((_version & appliesTo) != JJ2Version::Unknown) {
for (int i = 0; i < advanceBy; i++) {
for (std::uint32_t i = 0; i < advanceBy; i++) {
Entry entry;
entry.Category = Discard;

int32_t key = (_currentSet << 16) | _currentItem;
std::int32_t key = (_currentSet << 16) | _currentItem;
_entries.emplace(key, std::move(entry));

_currentItem++;
_currentOrdinal++;
}
}
}

void AnimSetMapping::SkipItems(int advanceBy)
void AnimSetMapping::SkipItems(std::uint32_t advanceBy)
{
_currentItem += advanceBy;
_currentOrdinal += advanceBy;
}

void AnimSetMapping::NextSet(int advanceBy, JJ2Version appliesTo)
void AnimSetMapping::NextSet(std::uint32_t advanceBy, JJ2Version appliesTo)
{
if ((_version & appliesTo) != JJ2Version::Unknown) {
_currentSet += advanceBy;
_currentItem = 0;
}
}

void AnimSetMapping::Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette) {
void AnimSetMapping::Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette, bool skipNormalMap, bool allowRealtimePalette)
{
if ((_version & appliesTo) != JJ2Version::Unknown) {
Entry entry;
entry.Category = category;
entry.Name = name;
entry.Ordinal = _currentOrdinal;
entry.Palette = palette;
entry.SkipNormalMap = skipNormalMap;
entry.AllowRealtimePalette = allowRealtimePalette;

int32_t key = (_currentSet << 16) | _currentItem;
std::uint32_t key = (_currentSet << 16) | _currentItem;
_entries.emplace(key, std::move(entry));

_currentItem++;
_currentOrdinal++;
}
}

Expand All @@ -2000,28 +2010,41 @@ namespace Jazz2::Compatibility
Entry entry;
entry.Category = category;
entry.Name = name;
entry.Ordinal = _currentOrdinal;
entry.Palette = palette;
entry.SkipNormalMap = skipNormalMap;
entry.AllowRealtimePalette = allowRealtimePalette;

int32_t key = (_currentSet << 16) | _currentItem;
std::uint32_t key = (_currentSet << 16) | _currentItem;
_entries.emplace(key, std::move(entry));

_currentItem++;
_currentOrdinal++;
}

AnimSetMapping::Entry* AnimSetMapping::Get(int32_t set, int32_t item)
AnimSetMapping::Entry* AnimSetMapping::Get(std::uint32_t set, std::uint32_t item)
{
if (set > UINT16_MAX || item > UINT16_MAX) {
return nullptr;
}

int32_t key = (set << 16) | item;
std::uint32_t key = (set << 16) | item;
auto it = _entries.find(key);
if (it != _entries.end()) {
return &it->second;
} else {
return nullptr;
}
}

AnimSetMapping::Entry* AnimSetMapping::GetByOrdinal(std::uint32_t index)
{
for (auto& [key, entry] : _entries) {
if (entry.Ordinal == index) {
return &entry;
}
}

return nullptr;
}
}
85 changes: 41 additions & 44 deletions Sources/Jazz2/Compatibility/AnimSetMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,45 @@ using namespace nCine;

namespace Jazz2::Compatibility
{
enum class JJ2DefaultPalette {
Sprite,
Menu
};

class AnimSetMapping
{
public:
static constexpr char Discard[] = ":discard";

struct Entry {
String Category;
String Name;

JJ2DefaultPalette Palette;
bool SkipNormalMap;
bool AllowRealtimePalette;
};

AnimSetMapping(JJ2Version version)
:
_version(version),
_currentItem(0),
_currentSet(0)
{
}

Entry* Get(int32_t set, int32_t item);

static AnimSetMapping GetAnimMapping(JJ2Version version);
static AnimSetMapping GetSampleMapping(JJ2Version version);

private:
JJ2Version _version;
HashMap<int32_t, Entry> _entries;
int _currentItem;
int _currentSet;

void DiscardItems(int advanceBy, JJ2Version appliesTo = JJ2Version::All);
void SkipItems(int advanceBy = 1);
void NextSet(int advanceBy = 1, JJ2Version appliesTo = JJ2Version::All);
void Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
void Add(const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
};
enum class JJ2DefaultPalette {
Sprite,
Menu
};

class AnimSetMapping
{
public:
static constexpr char Discard[] = ":discard";

struct Entry {
String Category;
String Name;
std::uint32_t Ordinal;

JJ2DefaultPalette Palette;
bool SkipNormalMap;
bool AllowRealtimePalette;
};

Entry* Get(std::uint32_t set, std::uint32_t item);
Entry* GetByOrdinal(std::uint32_t index);

static AnimSetMapping GetAnimMapping(JJ2Version version);
static AnimSetMapping GetSampleMapping(JJ2Version version);

private:
JJ2Version _version;
HashMap<std::uint32_t, Entry> _entries;
std::uint32_t _currentItem;
std::uint32_t _currentSet;
std::uint32_t _currentOrdinal;

AnimSetMapping(JJ2Version version);

void DiscardItems(std::uint32_t advanceBy, JJ2Version appliesTo = JJ2Version::All);
void SkipItems(std::uint32_t advanceBy = 1);
void NextSet(std::uint32_t advanceBy = 1, JJ2Version appliesTo = JJ2Version::All);
void Add(JJ2Version appliesTo, const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
void Add(const StringView& category, const StringView& name, JJ2DefaultPalette palette = JJ2DefaultPalette::Sprite, bool skipNormalMap = false, bool allowRealtimePalette = false);
};
}
15 changes: 8 additions & 7 deletions Sources/Jazz2/Compatibility/JJ2Anims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace Death::IO;

namespace Jazz2::Compatibility
{
bool JJ2Anims::Convert(const StringView& path, const StringView& targetPath, bool isPlus)
JJ2Version JJ2Anims::Convert(const StringView path, const StringView targetPath, bool isPlus)
{
JJ2Version version;
SmallVector<AnimSection, 0> anims;
Expand Down Expand Up @@ -260,7 +260,7 @@ namespace Jazz2::Compatibility
version = JJ2Version::TSF | JJ2Version::SharewareDemo;
// TODO: This version is not supported (yet)
LOGE("Detected Jazz Jackrabbit 2: The Secret Files Demo - This version is not supported!");
return false;
return JJ2Version::Unknown;
} else if (seemsLikeCC) {
version = JJ2Version::CC;
LOGI("Detected Jazz Jackrabbit 2: Christmas Chronicles");
Expand All @@ -275,7 +275,7 @@ namespace Jazz2::Compatibility
version = JJ2Version::PlusExtension;
if (!isPlus) {
LOGE("Detected Jazz Jackrabbit 2 Plus extension - This version is not supported!");
return false;
return JJ2Version::Unknown;
}
} else {
version = JJ2Version::Unknown;
Expand All @@ -284,10 +284,11 @@ namespace Jazz2::Compatibility

ImportAnimations(targetPath, version, anims);
ImportAudioSamples(targetPath, version, samples);
return true;

return version;
}

void JJ2Anims::ImportAnimations(const StringView& targetPath, JJ2Version version, SmallVectorImpl<AnimSection>& anims)
void JJ2Anims::ImportAnimations(const StringView targetPath, JJ2Version version, SmallVectorImpl<AnimSection>& anims)
{
if (anims.empty()) {
return;
Expand Down Expand Up @@ -444,7 +445,7 @@ namespace Jazz2::Compatibility
}
}

void JJ2Anims::ImportAudioSamples(const StringView& targetPath, JJ2Version version, SmallVectorImpl<SampleSection>& samples)
void JJ2Anims::ImportAudioSamples(const StringView targetPath, JJ2Version version, SmallVectorImpl<SampleSection>& samples)
{
if (samples.empty()) {
return;
Expand Down Expand Up @@ -515,7 +516,7 @@ namespace Jazz2::Compatibility
}
}

void JJ2Anims::WriteImageToFile(const StringView& targetPath, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount, const AnimSection& anim, AnimSetMapping::Entry* entry)
void JJ2Anims::WriteImageToFile(const StringView targetPath, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount, const AnimSection& anim, AnimSetMapping::Entry* entry)
{
auto so = fs::Open(targetPath, FileAccessMode::Write);
ASSERT_MSG(so->IsValid(), "Cannot open file for writing");
Expand Down
10 changes: 5 additions & 5 deletions Sources/Jazz2/Compatibility/JJ2Anims.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace Jazz2::Compatibility
class JJ2Anims // .j2a
{
public:
static constexpr uint16_t CacheVersion = 14;
static constexpr uint16_t CacheVersion = 15;

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

static void WriteImageToFileInternal(std::unique_ptr<Stream>& so, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount);

Expand Down Expand Up @@ -66,9 +66,9 @@ namespace Jazz2::Compatibility

JJ2Anims();

static void ImportAnimations(const StringView& targetPath, JJ2Version version, SmallVectorImpl<AnimSection>& anims);
static void ImportAudioSamples(const StringView& targetPath, JJ2Version version, SmallVectorImpl<SampleSection>& samples);
static void ImportAnimations(const StringView targetPath, JJ2Version version, SmallVectorImpl<AnimSection>& anims);
static void ImportAudioSamples(const StringView targetPath, JJ2Version version, SmallVectorImpl<SampleSection>& samples);

static void WriteImageToFile(const StringView& targetPath, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount, const AnimSection& anim, AnimSetMapping::Entry* entry);
static void WriteImageToFile(const StringView targetPath, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount, const AnimSection& anim, AnimSetMapping::Entry* entry);
};
}
Loading

0 comments on commit 583d099

Please sign in to comment.