AMFP Enhanced
C++ reference: the code this unofficial fork added
Loading...
Searching...
No Matches
LuxStorySkip.h
Go to the documentation of this file.
1/*
2 * AMFP-2026: story-scene skip. Story first: nothing is shown until the player presses
3 * Esc / B; the first press shows "press again to skip", a second press within a few seconds
4 * fast-forwards the scene, and the prompt fades away if no second press comes.
5 * Pure state machine, unit tested in tests/cpp/test_story_skip.cpp.
6 */
7#ifndef LUX_STORY_SKIP_H
8#define LUX_STORY_SKIP_H
9
10static const float kLuxSkipPromptTime = 3.0f; // seconds the prompt stays up
11static const float kLuxSkipMaxTime = 240.0f; // game seconds of fast-forward at most
12
14{
15 eLuxSkipResult_NotHandled, // not a story scene: let Esc do what it normally does
19};
20
21/** A story scene the skip can fast-forward: the player has no control, is held still by a
22 * script, or crawls in silence (slow walk while the level script has the world sound off,
23 * like waking up in the intro). Slow walking with sound on is gameplay. */
24inline bool LuxIsStoryScene(bool abPlayerActive, float afMoveSpeedMul, float afScriptWorldVolume)
25{
26 if(abPlayerActive == false || afMoveSpeedMul <= 0.001f) return true;
27 return afMoveSpeedMul < 0.3f && afScriptWorldVolume < 0.2f;
28}
29
31{
32public:
33 cLuxStorySkip() : mbPrompt(false), mfPromptTime(0), mbSkipping(false), mfSkipTime(0) {}
34
35 eLuxSkipResult OnPress(bool abStoryScene)
36 {
37 if(mbSkipping) { mbSkipping = false; return eLuxSkipResult_Cancel; }
38 if(abStoryScene == false) return eLuxSkipResult_NotHandled;
39 if(mbPrompt)
40 {
41 mbPrompt = false;
42 mbSkipping = true;
43 mfSkipTime = 0;
45 }
46 mbPrompt = true;
47 mfPromptTime = 0;
49 }
50
51 void Update(float afTimeStep, bool abStoryScene)
52 {
53 if(abStoryScene == false) { mbPrompt = false; mbSkipping = false; return; }
54 if(mbPrompt)
55 {
56 mfPromptTime += afTimeStep;
57 if(mfPromptTime >= kLuxSkipPromptTime) mbPrompt = false;
58 }
59 if(mbSkipping)
60 {
61 mfSkipTime += afTimeStep;
62 if(mfSkipTime >= kLuxSkipMaxTime) mbSkipping = false;
63 }
64 }
65
66 bool IsPromptVisible() const { return mbPrompt; }
67 bool IsSkipping() const { return mbSkipping; }
68
69 /** Fades in over 0.2 s and out over the last 0.6 s. */
70 float PromptAlpha() const
71 {
72 if(mbPrompt == false) return 0.0f;
73 float fIn = mfPromptTime / 0.2f;
74 float fOut = (kLuxSkipPromptTime - mfPromptTime) / 0.6f;
75 float a = fIn < fOut ? fIn : fOut;
76 return a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a);
77 }
78
79private:
80 bool mbPrompt;
81 float mfPromptTime;
82 bool mbSkipping;
83 float mfSkipTime;
84};
85
86#endif
bool LuxIsStoryScene(bool abPlayerActive, float afMoveSpeedMul, float afScriptWorldVolume)
A story scene the skip can fast-forward: the player has no control, is held still by a script,...
static const float kLuxSkipPromptTime
static const float kLuxSkipMaxTime
eLuxSkipResult
@ eLuxSkipResult_NotHandled
@ eLuxSkipResult_Skip
@ eLuxSkipResult_Shown
@ eLuxSkipResult_Cancel
void Update(float afTimeStep, bool abStoryScene)
bool IsPromptVisible() const
eLuxSkipResult OnPress(bool abStoryScene)
float PromptAlpha() const
Fades in over 0.2 s and out over the last 0.6 s.
bool IsSkipping() const
cLuxStorySkip()