Skip to content

Commit

Permalink
Fixed player lifting, fixed Lori animations, adjusted ambient light t…
Browse files Browse the repository at this point in the history
…ransition, fixed `JoyMappedStateImpl`
  • Loading branch information
deathkiller committed Nov 12, 2023
1 parent 3d461ab commit d8bbeb0
Show file tree
Hide file tree
Showing 28 changed files with 266 additions and 164 deletions.
4 changes: 2 additions & 2 deletions Content/Metadata/Interactive/PlayerJazz.res
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@
"States": [ 131072 ]
},
"LiftStart": {
"Path": "Jazz/lift_jump_heavy.aura",
"Path": "Jazz/lift_start.aura",
"FrameRate": 16,
"States": [ 1073741859 ]
},
"LiftEnd": {
"Path": "Jazz/lift_jump_light.aura",
"Path": "Jazz/lift_end.aura",
"States": [ 1073741860 ]
},
"Ledge": {
Expand Down
4 changes: 2 additions & 2 deletions Content/Metadata/Interactive/PlayerLori.res
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@
"States": [ 131072 ]
},
"LiftStart": {
"Path": "Lori/lift_jump_heavy.aura",
"Path": "Lori/lift_start.aura",
"FrameRate": 16,
"States": [ 1073741859 ]
},
"LiftEnd": {
"Path": "Lori/lift_jump_light.aura",
"Path": "Lori/lift_end.aura",
"States": [ 1073741860 ]
},
"Ledge": {
Expand Down
4 changes: 2 additions & 2 deletions Content/Metadata/Interactive/PlayerSpaz.res
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@
"States": [ 131072 ]
},
"LiftStart": {
"Path": "Spaz/lift_jump_heavy.aura",
"Path": "Spaz/lift_start.aura",
"FrameRate": 16,
"States": [ 1073741859 ]
},
"LiftEnd": {
"Path": "Spaz/lift_jump_light.aura",
"Path": "Spaz/lift_end.aura",
"States": [ 1073741860 ]
},
"Ledge": {
Expand Down
13 changes: 11 additions & 2 deletions Sources/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ namespace Jazz2::Actors
{
bool perPixel = (_state & ActorState::SkipPerPixelCollisions) != ActorState::SkipPerPixelCollisions;
if (!perPixel) {
AABBf inter2 = AABBf::Intersect(aabb, AABBInner);
return (inter2.R > 0 && inter2.B > 0);
return aabb.Overlaps(AABBInner);
} else if (std::abs(_renderer.rotation()) > 0.1f) {
return IsCollidingWithAngled(aabb);
}
Expand Down Expand Up @@ -1189,6 +1188,16 @@ namespace Jazz2::Actors
_externalForce.Y += y;
}

ActorBase::ActorRenderer::ActorRenderer(ActorBase* owner)
: BaseSprite(nullptr, nullptr, 0.0f, 0.0f), AnimPaused(false), FrameConfiguration(), FrameDimensions(),
LoopMode(AnimationLoopMode::Loop), FirstFrame(0), FrameCount(0), AnimDuration(0.0f), AnimTime(0.0f),
CurrentFrame(0), Hotspot(), _owner(owner), _rendererType((ActorRendererType)-1), _rendererTransition(0.0f)
{
type_ = ObjectType::Sprite;
renderCommand_.setType(RenderCommand::CommandTypes::Sprite);
Initialize(ActorRendererType::Default);
}

void ActorBase::ActorRenderer::Initialize(ActorRendererType type)
{
if (_rendererType == type) {
Expand Down
9 changes: 1 addition & 8 deletions Sources/Jazz2/Actors/ActorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,7 @@ namespace Jazz2::Actors
friend class ActorBase;

public:
ActorRenderer(ActorBase* owner)
: BaseSprite(nullptr, nullptr, 0.0f, 0.0f), AnimPaused(false), FrameConfiguration(), FrameDimensions(),
LoopMode(AnimationLoopMode::Loop), FirstFrame(0), FrameCount(0), AnimDuration(0.0f), AnimTime(0.0f),
CurrentFrame(0), Hotspot(), _owner(owner), _rendererType((ActorRendererType)-1), _rendererTransition(0.0f)
{
type_ = ObjectType::Sprite;
Initialize(ActorRendererType::Default);
}
ActorRenderer(ActorBase* owner);

bool AnimPaused;
Vector2i FrameConfiguration;
Expand Down
21 changes: 8 additions & 13 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,10 @@ namespace Jazz2::Actors
_playerIndex = details.Params[1];

switch (_playerType) {
case PlayerType::Jazz:
async_await RequestMetadataAsync("Interactive/PlayerJazz"_s);
break;
case PlayerType::Spaz:
async_await RequestMetadataAsync("Interactive/PlayerSpaz"_s);
break;
case PlayerType::Lori:
async_await RequestMetadataAsync("Interactive/PlayerLori"_s);
break;
case PlayerType::Frog:
async_await RequestMetadataAsync("Interactive/PlayerFrog"_s);
break;
case PlayerType::Jazz: async_await RequestMetadataAsync("Interactive/PlayerJazz"_s); break;
case PlayerType::Spaz: async_await RequestMetadataAsync("Interactive/PlayerSpaz"_s); break;
case PlayerType::Lori: async_await RequestMetadataAsync("Interactive/PlayerLori"_s); break;
case PlayerType::Frog: async_await RequestMetadataAsync("Interactive/PlayerFrog"_s); break;
}

SetAnimation(AnimState::Fall);
Expand Down Expand Up @@ -1729,9 +1721,11 @@ namespace Jazz2::Actors
}
}
} else if (GetState(ActorState::IsSolidObject)) {
AABBf aabb = AABBf(AABBInner.L, AABBInner.T - 2.0f, AABBInner.R, AABBInner.T + 6.0f);
AABBf aabb = AABBf(AABBInner.L, AABBInner.T - 20.0f, AABBInner.R, AABBInner.T + 6.0f);
TileCollisionParams params = { TileDestructType::None, false };
ActorBase* collider;
ActorState prevState = GetState();
SetState(ActorState::CollideWithTileset, false);
if (!_levelHandler->IsPositionEmpty(this, aabb, params, &collider)) {
if (auto solidObject = dynamic_cast<SolidObjectBase*>(collider)) {
if (AABBInner.T >= solidObject->AABBInner.T && !_isLifting && std::abs(_speed.Y) < 1.0f) {
Expand All @@ -1744,6 +1738,7 @@ namespace Jazz2::Actors
} else {
_isLifting = false;
}
SetState(prevState);
} else {
_isLifting = false;
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Jazz2/Compatibility/AnimSetMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ namespace Jazz2::Compatibility
m.Add("Jazz"_s, "jump"_s);
m.Add("Jazz"_s, "ledge"_s);
m.Add("Jazz"_s, "lift"_s);
m.Add("Jazz"_s, "lift_jump_light"_s);
m.Add("Jazz"_s, "lift_jump_heavy"_s);
m.Add("Jazz"_s, "lift_end"_s);
m.Add("Jazz"_s, "lift_start"_s);
m.Add("Jazz"_s, "lookup_start"_s);
//m.Add(JJ2Version::BaseGame | JJ2Version::HH, "Jazz"_s, "unused_run_diag_upright"_s);
//m.Add(JJ2Version::BaseGame | JJ2Version::HH, "Jazz"_s, "unused_run_ver_up"_s);
Expand Down Expand Up @@ -687,8 +687,8 @@ namespace Jazz2::Compatibility
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "jump"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "ledge"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lift"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lift_jump_light"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lift_jump_heavy"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lift_end"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lift_start"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "lookup_start"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "dizzy_walk"_s);
m.Add(JJ2Version::TSF | JJ2Version::CC, "Lori"_s, "push"_s);
Expand Down Expand Up @@ -1033,8 +1033,8 @@ namespace Jazz2::Compatibility
m.Add("Spaz"_s, "jump"_s);
m.Add("Spaz"_s, "ledge"_s);
m.Add("Spaz"_s, "lift"_s);
m.Add("Spaz"_s, "lift_jump_light"_s);
m.Add("Spaz"_s, "lift_jump_heavy"_s);
m.Add("Spaz"_s, "lift_end"_s);
m.Add("Spaz"_s, "lift_start"_s);
m.Add("Spaz"_s, "lookup_start"_s);
//m.Add(JJ2Version::BaseGame | JJ2Version::HH, "Spaz"_s, "unused_run_diag_upright"_s);
//m.Add(JJ2Version::BaseGame | JJ2Version::HH, "Spaz"_s, "unused_run_ver_up"_s);
Expand Down
49 changes: 28 additions & 21 deletions Sources/Jazz2/Compatibility/JJ2Anims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ namespace Jazz2::Compatibility
// TODO: Hardcoded name
bool applyToasterPowerUpFix = (entry->Category == "Object"_s && entry->Name == "powerup_upgrade_toaster"_s);
if (applyToasterPowerUpFix) {
LOGI("Applying \"Toaster PowerUp\" palette fix");
LOGI("Applying \"Toaster PowerUp\" palette fix to %i:%u", anim.Set, anim.Anim);
}

bool applyVineFix = (entry->Category == "Object" && entry->Name == "vine");
bool applyVineFix = (entry->Category == "Object"_s && entry->Name == "vine"_s);
if (applyVineFix) {
LOGI("Applying \"Vine\" palette fix");
LOGI("Applying \"Vine\" palette fix to %i:%u", anim.Set, anim.Anim);
}

String filename;
Expand Down Expand Up @@ -413,9 +413,16 @@ namespace Jazz2::Compatibility
}
}

bool applyLoriLiftFix = (entry->Category == "Lori"_s && (entry->Name == "lift"_s || entry->Name == "lift_start"_s || entry->Name == "lift_end"_s));
if (applyLoriLiftFix) {
LOGI("Applying \"Lori\" hotspot fix to %i:%u", anim.Set, anim.Anim);
anim.NormalizedHotspotX = 20;
anim.NormalizedHotspotY = 4;
}

// TODO: Use single channel instead
String fullPath = fs::CombinePath(targetPath, filename);
WriteImageToFile(fullPath, pixels.get(), sizeX, sizeY, 4, &anim, entry);
WriteImageToFile(fullPath, pixels.get(), sizeX, sizeY, 4, anim, entry);

/*if (!string.IsNullOrEmpty(data.Name) && !data.SkipNormalMap) {
PngWriter normalMap = NormalMapGenerator.FromSprite(img,
Expand Down Expand Up @@ -498,7 +505,7 @@ namespace Jazz2::Compatibility
}
}

void JJ2Anims::WriteImageToFile(const StringView& targetPath, const uint8_t* data, int32_t width, int32_t height, int32_t channelCount, 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 Expand Up @@ -530,35 +537,35 @@ namespace Jazz2::Compatibility

// Include Sprite extension
if (entry != nullptr) {
so->WriteValue<uint8_t>(anim->FrameConfigurationX);
so->WriteValue<uint8_t>(anim->FrameConfigurationY);
so->WriteValue<uint16_t>(anim->FrameCount);
so->WriteValue<uint16_t>((uint16_t)(anim->FrameRate == 0 ? 0 : 256 * 5 / anim->FrameRate));

if (anim->NormalizedHotspotX != 0 || anim->NormalizedHotspotY != 0) {
so->WriteValue<uint16_t>(anim->NormalizedHotspotX + AddBorder);
so->WriteValue<uint16_t>(anim->NormalizedHotspotY + AddBorder);
so->WriteValue<uint8_t>(anim.FrameConfigurationX);
so->WriteValue<uint8_t>(anim.FrameConfigurationY);
so->WriteValue<uint16_t>(anim.FrameCount);
so->WriteValue<uint16_t>((uint16_t)(anim.FrameRate == 0 ? 0 : 256 * 5 / anim.FrameRate));

if (anim.NormalizedHotspotX != 0 || anim.NormalizedHotspotY != 0) {
so->WriteValue<uint16_t>(anim.NormalizedHotspotX + AddBorder);
so->WriteValue<uint16_t>(anim.NormalizedHotspotY + AddBorder);
} else {
so->WriteValue<uint16_t>(UINT16_MAX);
so->WriteValue<uint16_t>(UINT16_MAX);
}
if (anim->Frames[0].ColdspotX != 0 || anim->Frames[0].ColdspotY != 0) {
so->WriteValue<uint16_t>((anim->NormalizedHotspotX + anim->Frames[0].HotspotX) - anim->Frames[0].ColdspotX + AddBorder);
so->WriteValue<uint16_t>((anim->NormalizedHotspotY + anim->Frames[0].HotspotY) - anim->Frames[0].ColdspotY + AddBorder);
if (anim.Frames[0].ColdspotX != 0 || anim.Frames[0].ColdspotY != 0) {
so->WriteValue<uint16_t>((anim.NormalizedHotspotX + anim.Frames[0].HotspotX) - anim.Frames[0].ColdspotX + AddBorder);
so->WriteValue<uint16_t>((anim.NormalizedHotspotY + anim.Frames[0].HotspotY) - anim.Frames[0].ColdspotY + AddBorder);
} else {
so->WriteValue<uint16_t>(UINT16_MAX);
so->WriteValue<uint16_t>(UINT16_MAX);
}
if (anim->Frames[0].GunspotX != 0 || anim->Frames[0].GunspotY != 0) {
so->WriteValue<uint16_t>((anim->NormalizedHotspotX + anim->Frames[0].HotspotX) - anim->Frames[0].GunspotX + AddBorder);
so->WriteValue<uint16_t>((anim->NormalizedHotspotY + anim->Frames[0].HotspotY) - anim->Frames[0].GunspotY + AddBorder);
if (anim.Frames[0].GunspotX != 0 || anim.Frames[0].GunspotY != 0) {
so->WriteValue<uint16_t>((anim.NormalizedHotspotX + anim.Frames[0].HotspotX) - anim.Frames[0].GunspotX + AddBorder);
so->WriteValue<uint16_t>((anim.NormalizedHotspotY + anim.Frames[0].HotspotY) - anim.Frames[0].GunspotY + AddBorder);
} else {
so->WriteValue<uint16_t>(UINT16_MAX);
so->WriteValue<uint16_t>(UINT16_MAX);
}

width *= anim->FrameConfigurationX;
height *= anim->FrameConfigurationY;
width *= anim.FrameConfigurationX;
height *= anim.FrameConfigurationY;
}

WriteImageToFileInternal(so, data, width, height, channelCount);
Expand Down
4 changes: 2 additions & 2 deletions 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 = 9;
static constexpr uint16_t CacheVersion = 10;

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

Expand Down Expand Up @@ -69,6 +69,6 @@ namespace Jazz2::Compatibility
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, 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);
};
}
9 changes: 7 additions & 2 deletions Sources/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ namespace Jazz2
void LevelHandler::SetAmbientLight(float value)
{
_ambientLightTarget = value;

// Skip transition if it was changed at the beginning of level
if (_elapsedFrames < FrameTimer::FramesPerSecond * 0.25f) {
_ambientColor.W = value;
}
}

void LevelHandler::AttachComponents(LevelDescriptor&& descriptor)
Expand All @@ -182,7 +187,7 @@ namespace Jazz2
if (!descriptor.DisplayName.empty()) {
theApplication().gfxDevice().setWindowTitle(StringView(NCINE_APP_NAME " - ", countof(NCINE_APP_NAME " - ") - 1) + descriptor.DisplayName);
} else {
theApplication().gfxDevice().setWindowTitle({ NCINE_APP_NAME, countof(NCINE_APP_NAME) - 1 });
theApplication().gfxDevice().setWindowTitle(StringView(NCINE_APP_NAME, countof(NCINE_APP_NAME) - 1));
}

_defaultNextLevel = std::move(descriptor.NextLevel);
Expand Down Expand Up @@ -453,7 +458,7 @@ namespace Jazz2
if (std::abs(_ambientColor.W - _ambientLightTarget) < step) {
_ambientColor.W = _ambientLightTarget;
} else {
_ambientColor.W += step * ((_ambientLightTarget < _ambientColor.W) ? -1 : 1);
_ambientColor.W += step * ((_ambientLightTarget < _ambientColor.W) ? -1.0f : 1.0f);
}
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/Jazz2/Tiles/TileMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ namespace Jazz2::Tiles
}

auto command = RentRenderCommand(layer.Description.RendererType);
command->setType(RenderCommand::CommandTypes::TileMap);
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Vector2i texSize = tileSet->TextureDiffuse->size();
Expand Down Expand Up @@ -1262,6 +1263,7 @@ namespace Jazz2::Tiles

for (auto& debris : _debrisList) {
auto command = RentRenderCommand(LayerRendererType::Default);
command->setType(RenderCommand::CommandTypes::Particle);

if ((debris.Flags & DebrisFlags::AdditiveBlending) == DebrisFlags::AdditiveBlending) {
command->material().setBlendingFactors(GL_SRC_ALPHA, GL_ONE);
Expand Down
2 changes: 2 additions & 0 deletions Sources/Jazz2/UI/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ namespace Jazz2::UI
{
if (_renderCommandsCount < _renderCommands.size()) {
RenderCommand* command = _renderCommands[_renderCommandsCount].get();
command->setType(RenderCommand::CommandTypes::Sprite);
_renderCommandsCount++;
return command;
} else {
std::unique_ptr<RenderCommand>& command = _renderCommands.emplace_back(std::make_unique<RenderCommand>());
command->setType(RenderCommand::CommandTypes::Sprite);
command->material().setBlendingEnabled(true);
_renderCommandsCount++;
return command.get();
Expand Down
1 change: 1 addition & 0 deletions Sources/Jazz2/UI/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ namespace Jazz2::UI
texCoords.Z *= -1;

auto command = canvas->RentRenderCommand();
command->setType(RenderCommand::CommandTypes::Text);
bool shaderChanged = (colorizeShader
? command->material().setShader(colorizeShader)
: command->material().setShaderProgramType(Material::ShaderProgramType::SPRITE));
Expand Down
2 changes: 1 addition & 1 deletion Sources/TermLogo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

static constexpr unsigned char TermLogo[] = {
static const unsigned char TermLogo[] = {
0x20, 0x20, 0x20, 0x20, 0x20, 0x1b, 0x5b, 0x30, 0x6d, 0x20, 0x20, 0x20, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x32, 0x3b, 0x31, 0x35, 0x34, 0x3b, 0x31,
0x36, 0x38, 0x3b, 0x31, 0x35, 0x36, 0x6d, 0xe2, 0x96, 0x83, 0x1b, 0x5b, 0x37, 0x6d, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x32, 0x3b, 0x37, 0x31, 0x3b,
0x31, 0x32, 0x33, 0x3b, 0x38, 0x34, 0x6d, 0xe2, 0x96, 0x80, 0x1b, 0x5b, 0x30, 0x6d, 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x32, 0x3b, 0x39, 0x30, 0x3b,
Expand Down
2 changes: 2 additions & 0 deletions Sources/nCine/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ namespace nCine
#endif
vaoPoolSize(16),
renderCommandPoolSize(32),
#if defined(WITH_IMGUI)
withDebugOverlay(false),
#endif
withAudio(true),
withThreads(false),
withScenegraph(true),
Expand Down
2 changes: 2 additions & 0 deletions Sources/nCine/AppConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ namespace nCine
/// The initial size for the pool of render commands
unsigned int renderCommandPoolSize;

#if defined(WITH_IMGUI)
/// The flag is `true` if the debug overlay is enabled
bool withDebugOverlay;
#endif
/// The flag is `true` if the audio subsystem is enabled
bool withAudio;
/// The flag is `true` if the threading subsystem is enabled
Expand Down
Loading

0 comments on commit d8bbeb0

Please sign in to comment.