Added covers, cross-fade

This commit is contained in:
Vladislav Khorev committed 2026-05-15 14:59:58 +03:00
1 parent 0f2b2e55af
commit e618c91415
29 files changed
+40462 -29

No files matched your search

+6 -2
View File
@@ -13,6 +13,7 @@ namespace ZL {
extern float x;
extern float y;
const float ATTACK_RANGE = 1.25f;
const float VISIBLE_RANGE = 6.f;
void Character::loadAnimation(AnimationState state, const std::string& filename, const std::string& zipFile) {
auto& data = animations[state];
@@ -180,7 +181,7 @@ void Character::update(int64_t deltaMs) {
if (attackTarget != nullptr)
{
float distToGhost = (attackTarget->position - position).norm();
if (distToGhost >= 10.f)
if (distToGhost >= VISIBLE_RANGE)
{
if (isPlayer)
{
@@ -189,7 +190,7 @@ void Character::update(int64_t deltaMs) {
battle_state = 0;
}
else if (distToGhost < 10.0f && distToGhost >= ATTACK_RANGE) {
else if (distToGhost < VISIBLE_RANGE && distToGhost >= ATTACK_RANGE) {
setTarget(attackTarget->position);
battle_state = 0;
}
@@ -721,6 +722,9 @@ void Character::drawWithShadow(Renderer& renderer, const Eigen::Matrix4f& lightF
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
}
renderer.RenderUniform1f("uAlpha", 1.0f);
glDisable(GL_BLEND);
if (!isPlayer && hp <= 0)
{
return;
-2
View File
@@ -173,7 +173,6 @@ namespace ZL
uniInteriorParams.interactiveObjectsJsonPath = "resources/config2/interactive_objects_uni_interior.json";
uniInteriorParams.playerPosition = Eigen::Vector3f(0.942694, 0, -9.63104);
locations["uni_interior"] = std::make_shared<Location>(renderer, inventory);
locations["uni_interior"]->setup(uniInteriorParams);
@@ -511,7 +510,6 @@ namespace ZL
}
}
if (event.type == SDL_KEYDOWN && event.key.repeat == 0) {
switch (event.key.keysym.sym) {
case SDLK_1:
+5 -2
View File
@@ -24,7 +24,7 @@ namespace ZL
static constexpr float CAMERA_FOV_Y = 1.0f / 1.5f;
// How close the player needs to be to a peaceful NPC before the
// on_npc_interact callback fires and the conversation begins.
static constexpr float NPC_TALK_DISTANCE = 1.25f;
static constexpr float NPC_TALK_DISTANCE = 1.35f;
static float distancePointToSegmentXZ(const Eigen::Vector3f& p,
const Eigen::Vector3f& a,
@@ -654,6 +654,7 @@ namespace ZL
//glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
//renderer.DrawVertexRenderStruct(roomMesh);
renderer.RenderUniform1f("uAlpha", 1.0f);
for (auto& [name, gameObj] : gameObjects) {
glBindTexture(GL_TEXTURE_2D, gameObj.texture->getTexID());
renderer.DrawVertexRenderStruct(gameObj.mesh);
@@ -664,7 +665,7 @@ namespace ZL
intObj.draw(renderer);
}
}
renderer.RenderUniform1f("uAlpha", 1.0f);
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
if (player) player->prepareHitSparksForDraw(currentView);
for (auto& npc : npcs) npc->prepareHitSparksForDraw(currentView);
@@ -832,6 +833,7 @@ namespace ZL
//renderer.DrawVertexRenderStruct(roomMesh);
CheckGlError(__FILE__, __LINE__);
renderer.RenderUniform1f("uAlpha", 1.0f);
for (auto& [name, gameObj] : gameObjects) {
glBindTexture(GL_TEXTURE_2D, gameObj.texture->getTexID());
renderer.DrawVertexRenderStruct(gameObj.mesh);
@@ -845,6 +847,7 @@ namespace ZL
}
CheckGlError(__FILE__, __LINE__);
#ifdef DEBUG_LIGHT
// In debug-light mode characters use the plain shaders (draw normally
// but from the light's viewpoint — projection/view already on stack).
+27
View File
@@ -240,6 +240,33 @@ namespace ZL {
std::cerr << "[script] rotate_object: object '" << name << "' not found\n";
});
// fade_object(name, target_alpha, duration_sec [, on_complete])
api.set_function("fade_object",
[game](const std::string& name, float targetAlpha,
float durationSec, sol::object onComplete) {
for (auto& intObj : game->interactiveObjects) {
if (intObj.loadedObject.name != name) continue;
if (intObj.isAnimating) {
std::cerr << "[script] fade_object: '" << name << "' is already animating\n";
return;
}
std::function<void()> cb;
if (onComplete.is<sol::protected_function>()) {
sol::protected_function fn = onComplete.as<sol::protected_function>();
cb = [fn]() mutable {
auto res = fn();
if (!res.valid()) {
sol::error err = res;
std::cerr << "[script] fade_object on_complete error: " << err.what() << "\n";
}
};
}
intObj.fadeTo(targetAlpha, durationSec, std::move(cb));
return;
}
std::cerr << "[script] fade_object: object '" << name << "' not found\n";
});
// scale_object(name, target_scale, duration_sec [, on_complete])
api.set_function("scale_object",
[game](const std::string& name, float targetScale,
+30
View File
@@ -63,6 +63,23 @@ namespace ZL {
isAnimating = true;
}
void InteractiveObject::fadeTo(float targetAlpha, float durationSec, std::function<void()> onComplete) {
if (isAnimating) return;
AnimTask task;
task.type = AnimTask::Type::Fade;
task.startPos = position;
task.startRotY = rotationY;
task.startScale = alpha; // reuse startScale to hold start alpha
task.targetPos = position;
task.targetRotY = rotationY;
task.targetScale = targetAlpha; // reuse targetScale to hold target alpha
task.durationMs = durationSec * 1000.f;
task.elapsedMs = 0.f;
task.onComplete = std::move(onComplete);
animTask = std::move(task);
isAnimating = true;
}
void InteractiveObject::update(int64_t deltaMs) {
if (!isAnimating || !animTask) return;
@@ -81,6 +98,9 @@ namespace ZL {
case AnimTask::Type::Scale:
scale = task.startScale + (task.targetScale - task.startScale) * t;
break;
case AnimTask::Type::Fade:
alpha = task.startScale + (task.targetScale - task.startScale) * t;
break;
}
if (t >= 1.0f) {
@@ -99,6 +119,12 @@ namespace ZL {
void InteractiveObject::draw(Renderer& renderer) const {
if (!isActive || !loadedObject.texture) return;
if (alpha < 0.999f) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
renderer.PushMatrix();
renderer.TranslateMatrix(position);
if (rotationY != 0.f) {
@@ -109,9 +135,13 @@ namespace ZL {
if (scale != 1.f)
renderer.ScaleMatrix(scale);
renderer.RenderUniform1i(textureUniformName, 0);
renderer.RenderUniform1f("uAlpha", alpha);
glBindTexture(GL_TEXTURE_2D, loadedObject.texture->getTexID());
renderer.DrawVertexRenderStruct(loadedObject.mesh);
renderer.PopMatrix();
// Restore uAlpha so subsequent fog-shader users (character weapons, etc.) are not affected.
renderer.RenderUniform1f("uAlpha", 1.0f);
}
} // namespace ZL
+3 -1
View File
@@ -23,13 +23,14 @@ namespace ZL {
Eigen::Vector3f pivot = Eigen::Vector3f::Zero(); // local-space offset to rotation pivot
float rotationY = 0.0f; // Y-axis rotation in radians
float scale = 1.0f; // uniform scale
float alpha = 1.0f; // opacity: 1=opaque, 0=fully transparent
float interactionRadius;
bool isActive = true;
bool isAnimating = false; // true while a timed animation is running
std::string activateFunctionName;
struct AnimTask {
enum class Type { Move, Rotate, Scale } type;
enum class Type { Move, Rotate, Scale, Fade } type;
Eigen::Vector3f startPos;
float startRotY;
float startScale;
@@ -48,6 +49,7 @@ namespace ZL {
void moveTo(const Eigen::Vector3f& target, float durationSec, std::function<void()> onComplete = {});
void rotateTo(float targetRotY, float durationSec, std::function<void()> onComplete = {});
void scaleTo(float targetScale, float durationSec, std::function<void()> onComplete = {});
void fadeTo(float targetAlpha, float durationSec, std::function<void()> onComplete = {});
void update(int64_t deltaMs);
void draw(Renderer& renderer) const;
};