Some cleanup
This commit is contained in:
1 parent
4e40a1825a
commit
c1be26023b
20 files changed
+451
-1330
No files matched your search
+10
-21
@@ -352,9 +352,8 @@ messages contain numbered command bundles.
|
|||||||
- Locations are keyed by location ID.
|
- Locations are keyed by location ID.
|
||||||
- Each location stores NPC and interactive-object state in ID-keyed objects.
|
- Each location stores NPC and interactive-object state in ID-keyed objects.
|
||||||
- Pending interaction targets and character references use stable IDs.
|
- Pending interaction targets and character references use stable IDs.
|
||||||
- Character navigation persistence includes waypoints, actual previous-tick
|
- Character navigation persistence includes waypoints, the retry timer, and the
|
||||||
movement, blocked/retry state, the blocker ID, and the NPC cooldown sequence
|
NPC cooldown sequence and cursor.
|
||||||
and cursor.
|
|
||||||
- Immutable content such as meshes, initial taxi configuration, and object
|
- Immutable content such as meshes, initial taxi configuration, and object
|
||||||
definitions is reconstructed from campaign configuration.
|
definitions is reconstructed from campaign configuration.
|
||||||
- Configuration is loaded first and mutable saved state is overlaid in place.
|
- Configuration is loaded first and mutable saved state is overlaid in place.
|
||||||
@@ -497,25 +496,15 @@ cmake --build proj-windows/build --config Debug --target ShadowOverBishkekDemo -
|
|||||||
- A lockstep compatibility fingerprint must match before the client accepts the
|
- A lockstep compatibility fingerprint must match before the client accepts the
|
||||||
initial state.
|
initial state.
|
||||||
|
|
||||||
### Dynamic Navigation Occupancy
|
### Navigation Replanning
|
||||||
|
|
||||||
`LocationGameState` is the authoritative boundary for character-aware planning.
|
`CharacterState::setTarget` and `CharacterState::forceReplan` share one path
|
||||||
It collects enabled, living, stationary players and NPCs in stable ID order and
|
computation. Movement along the resulting waypoints is resolved by the ORCA
|
||||||
passes their positions and collision radii to `LocationNetworkState` and
|
solver in `LocationGameState::update` (see `PATHFINDING.md`). An NPC that
|
||||||
`PathFinder`. The requester is excluded; moving characters are transparent to
|
cannot find a path waits for the next deterministic, ID-shuffled cooldown from
|
||||||
planning. “Moving” here means actual previous-tick displacement
|
its serialized retry sequence before replanning; the retry timer, cooldown
|
||||||
(`movedLastTick`), not merely owning an active path, so visually stalled
|
sequence, and cursor are serialized character state. Static navigation topology
|
||||||
characters remain planning obstacles. Route planning uses full avoidance radii;
|
changes route through the same centralized replanning path.
|
||||||
the movement guard uses smaller contact radii.
|
|
||||||
|
|
||||||
Every character movement step is guarded against stable-ID-ordered reservations
|
|
||||||
initialized from tick-start geometry. Accepted steps update their reservation
|
|
||||||
before later characters advance, preventing two movers from ending a tick
|
|
||||||
overlapped. Blocked/retry counters, cooldown sequence/cursor, and blocker ID are
|
|
||||||
serialized character state. Head-on players and bots cancel their commands;
|
|
||||||
NPCs retain their targets and consume the next deterministic, ID-shuffled
|
|
||||||
cooldown before replanning. Static navigation topology changes route through
|
|
||||||
the same centralized replanning path.
|
|
||||||
|
|
||||||
## Main Files
|
## Main Files
|
||||||
|
|
||||||
|
|||||||
+2
-5
@@ -208,9 +208,6 @@ its closest boundary.
|
|||||||
After ORCA:
|
After ORCA:
|
||||||
|
|
||||||
- accepted position and `newVel` become authoritative state;
|
- accepted position and `newVel` become authoritative state;
|
||||||
- `movedLastTick` is set from actual displacement;
|
|
||||||
- `movementBlockedTicks` is reset after movement or incremented when a desired
|
|
||||||
move produced no displacement;
|
|
||||||
- walking/standing animation state follows actual movement;
|
- walking/standing animation state follows actual movement;
|
||||||
- facing follows the accepted ORCA velocity.
|
- facing follows the accepted ORCA velocity.
|
||||||
|
|
||||||
@@ -221,11 +218,11 @@ not initialize its raw integer.
|
|||||||
## 9. Deterministic lockstep requirements
|
## 9. Deterministic lockstep requirements
|
||||||
|
|
||||||
All clients must begin a tick with identical state. The following movement
|
All clients must begin a tick with identical state. The following movement
|
||||||
history is serialized in schema version 6:
|
history is serialized in schema version 7:
|
||||||
|
|
||||||
- exact raw fixed-point `velocity` components;
|
- exact raw fixed-point `velocity` components;
|
||||||
- path targets, waypoints, and waypoint index;
|
- path targets, waypoints, and waypoint index;
|
||||||
- `movedLastTick` and blocked/retry counters;
|
- the navigation retry timer;
|
||||||
- deterministic retry sequence and cursor;
|
- deterministic retry sequence and cursor;
|
||||||
- animation frame, state, `resetAnim`, and attack phase;
|
- animation frame, state, `resetAnim`, and attack phase;
|
||||||
- facing and target-facing angles.
|
- facing and target-facing angles.
|
||||||
|
|||||||
@@ -271,12 +271,11 @@ submission, and contiguous tick consumption.
|
|||||||
|
|
||||||
- Paths are calculated independently on every lockstep participant from the
|
- Paths are calculated independently on every lockstep participant from the
|
||||||
same ordered commands and tick-start occupancy. Integer A* costs, stable
|
same ordered commands and tick-start occupancy. Integer A* costs, stable
|
||||||
character IDs, serialized previous-tick movement and blocked/retry state, and deterministic
|
character IDs, serialized retry state, and deterministic nearest-reachable
|
||||||
nearest-reachable ties keep route selection aligned.
|
ties keep route selection aligned.
|
||||||
- Moving characters are omitted from A* but remain solid to the authoritative
|
- Movement between waypoints is resolved by the ORCA solver. NPCs that cannot
|
||||||
movement guard. After three blocked ticks, players/bots cancel movement while
|
find a path consume the next serialized cooldown from their deterministic
|
||||||
NPCs stop and consume the next serialized cooldown from their deterministic
|
retry sequence before replanning.
|
||||||
retry sequence before replanning around the blocker.
|
|
||||||
- Opposing traffic can wait in a one-character-wide corridor because the
|
- Opposing traffic can wait in a one-character-wide corridor because the
|
||||||
current policy does not reserve future space-time cells.
|
current policy does not reserve future space-time cells.
|
||||||
- Only preconfigured player slots can connect; dynamic join/spawn commands are
|
- Only preconfigured player slots can connect; dynamic join/spawn commands are
|
||||||
|
|||||||
@@ -505,8 +505,6 @@
|
|||||||
-15.038200378417969
|
-15.038200378417969
|
||||||
],
|
],
|
||||||
"hp": 100.0,
|
"hp": 100.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
10,
|
10,
|
||||||
@@ -599,7 +597,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"money": 5500,
|
"money": 5500,
|
||||||
"playerMaxHp": 200.0,
|
|
||||||
"players": {
|
"players": {
|
||||||
"player1": {
|
"player1": {
|
||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
@@ -621,8 +618,6 @@
|
|||||||
0.0
|
0.0
|
||||||
],
|
],
|
||||||
"hp": 200.0,
|
"hp": 200.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [],
|
"navigationRetryCooldownTicks": [],
|
||||||
"navigationRetryTicks": 0,
|
"navigationRetryTicks": 0,
|
||||||
@@ -797,7 +792,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-10 20:38",
|
"savedAt": "2026-11-10 20:38",
|
||||||
"schemaVersion": 6,
|
"schemaVersion": 7,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
@@ -147,8 +147,6 @@
|
|||||||
-12.0
|
-12.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -204,8 +202,6 @@
|
|||||||
-12.0
|
-12.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -261,8 +257,6 @@
|
|||||||
-12.5
|
-12.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -318,8 +312,6 @@
|
|||||||
-12.5
|
-12.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
3,
|
3,
|
||||||
@@ -375,8 +367,6 @@
|
|||||||
-13.0
|
-13.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -432,8 +422,6 @@
|
|||||||
-13.0
|
-13.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
7,
|
7,
|
||||||
@@ -489,8 +477,6 @@
|
|||||||
-14.0
|
-14.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -546,8 +532,6 @@
|
|||||||
-14.0
|
-14.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -603,8 +587,6 @@
|
|||||||
-14.5
|
-14.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -660,8 +642,6 @@
|
|||||||
-14.5
|
-14.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
3,
|
3,
|
||||||
@@ -717,8 +697,6 @@
|
|||||||
-15.0
|
-15.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -774,8 +752,6 @@
|
|||||||
-15.0
|
-15.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
7,
|
7,
|
||||||
@@ -846,7 +822,6 @@
|
|||||||
},
|
},
|
||||||
"money": 5500,
|
"money": 5500,
|
||||||
"playerHp": 200.0,
|
"playerHp": 200.0,
|
||||||
"playerMaxHp": 200.0,
|
|
||||||
"players": {
|
"players": {
|
||||||
"player1": {
|
"player1": {
|
||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
@@ -1038,7 +1013,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-05 17:43",
|
"savedAt": "2026-11-05 17:43",
|
||||||
"schemaVersion": 6,
|
"schemaVersion": 7,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
@@ -147,8 +147,6 @@
|
|||||||
-12.0
|
-12.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -204,8 +202,6 @@
|
|||||||
-12.0
|
-12.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -261,8 +257,6 @@
|
|||||||
-12.5
|
-12.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -318,8 +312,6 @@
|
|||||||
-12.5
|
-12.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
3,
|
3,
|
||||||
@@ -375,8 +367,6 @@
|
|||||||
-13.0
|
-13.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -432,8 +422,6 @@
|
|||||||
-13.0
|
-13.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
7,
|
7,
|
||||||
@@ -489,8 +477,6 @@
|
|||||||
-14.0
|
-14.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -546,8 +532,6 @@
|
|||||||
-14.0
|
-14.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -603,8 +587,6 @@
|
|||||||
-14.5
|
-14.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
2,
|
2,
|
||||||
@@ -660,8 +642,6 @@
|
|||||||
-14.5
|
-14.5
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
3,
|
3,
|
||||||
@@ -717,8 +697,6 @@
|
|||||||
-15.0
|
-15.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
8,
|
8,
|
||||||
@@ -774,8 +752,6 @@
|
|||||||
-15.0
|
-15.0
|
||||||
],
|
],
|
||||||
"hp": 35.0,
|
"hp": 35.0,
|
||||||
"movedLastTick": false,
|
|
||||||
"movementBlockedTicks": 0,
|
|
||||||
"navigationRetryCooldownIndex": 0,
|
"navigationRetryCooldownIndex": 0,
|
||||||
"navigationRetryCooldownTicks": [
|
"navigationRetryCooldownTicks": [
|
||||||
7,
|
7,
|
||||||
@@ -846,7 +822,6 @@
|
|||||||
},
|
},
|
||||||
"money": 5500,
|
"money": 5500,
|
||||||
"playerHp": 200.0,
|
"playerHp": 200.0,
|
||||||
"playerMaxHp": 200.0,
|
|
||||||
"players": {
|
"players": {
|
||||||
"player1": {
|
"player1": {
|
||||||
"animationFrame": 0.0,
|
"animationFrame": 0.0,
|
||||||
@@ -1038,7 +1013,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"savedAt": "2026-11-05 17:43",
|
"savedAt": "2026-11-05 17:43",
|
||||||
"schemaVersion": 6,
|
"schemaVersion": 7,
|
||||||
"taxiIsCalled": false,
|
"taxiIsCalled": false,
|
||||||
"tutorialJournalScreenOpened": false,
|
"tutorialJournalScreenOpened": false,
|
||||||
"tutorialNeedOpenTaxiScreen": false,
|
"tutorialNeedOpenTaxiScreen": false,
|
||||||
|
|||||||
@@ -348,13 +348,13 @@ int main()
|
|||||||
FRG::AnimationState::ACTION_IDLE, 0, 100);
|
FRG::AnimationState::ACTION_IDLE, 0, 100);
|
||||||
FRG::CharacterObservation attackTarget{
|
FRG::CharacterObservation attackTarget{
|
||||||
point(0.f, 0.f, 1.f), 100.f};
|
point(0.f, 0.f, 1.f), 100.f};
|
||||||
drawAnimation.update(100, {{"player1", &attackTarget}, nullptr});
|
drawAnimation.update(100, {&attackTarget, nullptr});
|
||||||
if (drawAnimation.currentState != FRG::AnimationState::STAND_TO_ACTION ||
|
if (drawAnimation.currentState != FRG::AnimationState::STAND_TO_ACTION ||
|
||||||
std::abs(drawAnimation.animationFrame - 8.333333f) > 0.001f ||
|
std::abs(drawAnimation.animationFrame - 8.333333f) > 0.001f ||
|
||||||
drawAnimation.showWeapon) {
|
drawAnimation.showWeapon) {
|
||||||
return fail("Weapon draw animation did not advance at 2x speed");
|
return fail("Weapon draw animation did not advance at 2x speed");
|
||||||
}
|
}
|
||||||
drawAnimation.update(200, {{"player1", &attackTarget}, nullptr});
|
drawAnimation.update(200, {&attackTarget, nullptr});
|
||||||
if (!drawAnimation.showWeapon) {
|
if (!drawAnimation.showWeapon) {
|
||||||
return fail("Weapon draw animation did not use its frame visibility threshold");
|
return fail("Weapon draw animation did not use its frame visibility threshold");
|
||||||
}
|
}
|
||||||
@@ -365,13 +365,13 @@ int main()
|
|||||||
sheathAnimation.currentState = FRG::AnimationState::ACTION_IDLE;
|
sheathAnimation.currentState = FRG::AnimationState::ACTION_IDLE;
|
||||||
sheathAnimation.setAnimationMetadata(
|
sheathAnimation.setAnimationMetadata(
|
||||||
FRG::AnimationState::ACTION_TO_STAND, 0, 100);
|
FRG::AnimationState::ACTION_TO_STAND, 0, 100);
|
||||||
sheathAnimation.update(100, {{"player1", nullptr}, nullptr});
|
sheathAnimation.update(100, {nullptr, nullptr});
|
||||||
if (sheathAnimation.currentState != FRG::AnimationState::ACTION_TO_STAND ||
|
if (sheathAnimation.currentState != FRG::AnimationState::ACTION_TO_STAND ||
|
||||||
std::abs(sheathAnimation.animationFrame - 8.333333f) > 0.001f ||
|
std::abs(sheathAnimation.animationFrame - 8.333333f) > 0.001f ||
|
||||||
!sheathAnimation.showWeapon) {
|
!sheathAnimation.showWeapon) {
|
||||||
return fail("Weapon sheath animation did not advance at 2x speed");
|
return fail("Weapon sheath animation did not advance at 2x speed");
|
||||||
}
|
}
|
||||||
sheathAnimation.update(300, {{"player1", nullptr}, nullptr});
|
sheathAnimation.update(300, {nullptr, nullptr});
|
||||||
if (sheathAnimation.showWeapon) {
|
if (sheathAnimation.showWeapon) {
|
||||||
return fail("Weapon sheath animation did not hide at its frame visibility threshold");
|
return fail("Weapon sheath animation did not hide at its frame visibility threshold");
|
||||||
}
|
}
|
||||||
@@ -382,7 +382,7 @@ int main()
|
|||||||
ordinaryAnimation.currentState = FRG::AnimationState::STAND;
|
ordinaryAnimation.currentState = FRG::AnimationState::STAND;
|
||||||
ordinaryAnimation.setAnimationMetadata(
|
ordinaryAnimation.setAnimationMetadata(
|
||||||
FRG::AnimationState::STAND, 0, 100);
|
FRG::AnimationState::STAND, 0, 100);
|
||||||
ordinaryAnimation.update(100, {{"player1", nullptr}, nullptr});
|
ordinaryAnimation.update(100, {nullptr, nullptr});
|
||||||
if (std::abs(ordinaryAnimation.animationFrame - 4.1666665f) > 0.001f) {
|
if (std::abs(ordinaryAnimation.animationFrame - 4.1666665f) > 0.001f) {
|
||||||
return fail("Ordinary animation playback rate changed unexpectedly");
|
return fail("Ordinary animation playback rate changed unexpectedly");
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ int main()
|
|||||||
FRG::AnimationState::ACTION_IDLE, 0, 30);
|
FRG::AnimationState::ACTION_IDLE, 0, 30);
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
completedDrawAnimation.update(
|
completedDrawAnimation.update(
|
||||||
100, {{"player1", &attackTarget}, nullptr});
|
100, {&attackTarget, nullptr});
|
||||||
if (completedDrawAnimation.currentState !=
|
if (completedDrawAnimation.currentState !=
|
||||||
FRG::AnimationState::ACTION_IDLE) {
|
FRG::AnimationState::ACTION_IDLE) {
|
||||||
return fail("Accelerated weapon draw animation did not complete");
|
return fail("Accelerated weapon draw animation did not complete");
|
||||||
@@ -410,7 +410,7 @@ int main()
|
|||||||
FRG::AnimationState::ACTION_TO_STAND, 0, 30);
|
FRG::AnimationState::ACTION_TO_STAND, 0, 30);
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
completedSheathAnimation.update(
|
completedSheathAnimation.update(
|
||||||
100, {{"player1", nullptr}, nullptr});
|
100, {nullptr, nullptr});
|
||||||
if (completedSheathAnimation.currentState != FRG::AnimationState::STAND) {
|
if (completedSheathAnimation.currentState != FRG::AnimationState::STAND) {
|
||||||
return fail("Accelerated weapon sheath animation did not complete");
|
return fail("Accelerated weapon sheath animation did not complete");
|
||||||
}
|
}
|
||||||
@@ -425,9 +425,7 @@ int main()
|
|||||||
guardedMover.save(guardedJson);
|
guardedMover.save(guardedJson);
|
||||||
FRG::CharacterState restoredGuardedMover;
|
FRG::CharacterState restoredGuardedMover;
|
||||||
restoredGuardedMover.load(guardedJson);
|
restoredGuardedMover.load(guardedJson);
|
||||||
if (restoredGuardedMover.movementBlockedTicks !=
|
if (restoredGuardedMover.navigationRetryTicks !=
|
||||||
guardedMover.movementBlockedTicks ||
|
|
||||||
restoredGuardedMover.navigationRetryTicks !=
|
|
||||||
guardedMover.navigationRetryTicks ||
|
guardedMover.navigationRetryTicks ||
|
||||||
restoredGuardedMover.velocity.x.raw_value() != 12345 ||
|
restoredGuardedMover.velocity.x.raw_value() != 12345 ||
|
||||||
restoredGuardedMover.velocity.y.raw_value() != -6789 ||
|
restoredGuardedMover.velocity.y.raw_value() != -6789 ||
|
||||||
|
|||||||
+187
-587
@@ -14,9 +14,6 @@
|
|||||||
#include "Location.h"
|
#include "Location.h"
|
||||||
|
|
||||||
namespace FRG {
|
namespace FRG {
|
||||||
extern float x;
|
|
||||||
extern float y;
|
|
||||||
|
|
||||||
Dialogue::TranslationDatabase Character::nameTranslations;
|
Dialogue::TranslationDatabase Character::nameTranslations;
|
||||||
|
|
||||||
std::shared_ptr<const CharacterState> Character::stateSnapshot() const {
|
std::shared_ptr<const CharacterState> Character::stateSnapshot() const {
|
||||||
@@ -49,7 +46,7 @@ Eigen::Vector3f Character::renderPosition() const {
|
|||||||
|
|
||||||
float Character::getHp() const {
|
float Character::getHp() const {
|
||||||
auto state = stateSnapshot();
|
auto state = stateSnapshot();
|
||||||
return state ? state->getHp() : 0.f;
|
return state ? state->hp : 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile) {
|
void Character::loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile) {
|
||||||
@@ -114,30 +111,6 @@ std::unique_ptr<Character> Character::createFromState(const CharacterState& st,
|
|||||||
if (tex) c->setTexture(meshName, tex);
|
if (tex) c->setTexture(meshName, tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!st.creationInfo.weaponMeshPath.empty()) {
|
|
||||||
const std::string& wp = st.creationInfo.weaponMeshPath;
|
|
||||||
try {
|
|
||||||
if (wp.size() >= 4 && wp.substr(wp.size() - 4) == ".bin")
|
|
||||||
c->weaponMesh.data = LoadModelFromBinFile(wp, zip);
|
|
||||||
else
|
|
||||||
c->weaponMesh.data = LoadFromTextFile02(wp, zip);
|
|
||||||
|
|
||||||
if (st.creationInfo.weaponMeshMove != Eigen::Vector3f::Zero())
|
|
||||||
c->weaponMesh.data.Move(st.creationInfo.weaponMeshMove);
|
|
||||||
if (st.creationInfo.weaponMeshScale != 1.0f)
|
|
||||||
c->weaponMesh.data.Scale(st.creationInfo.weaponMeshScale);
|
|
||||||
|
|
||||||
c->weaponMesh.RefreshVBO();
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "Character::createFromState: failed to load weapon mesh '" << wp << "': " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c->weaponTexture = loadTex(st.creationInfo.weaponTexturePath);
|
|
||||||
c->weaponAttachBoneName = st.creationInfo.weaponAttachBoneName;
|
|
||||||
c->weaponInitialPosition = st.creationInfo.weaponInitialPosition;
|
|
||||||
c->weaponInitialRotation = st.creationInfo.weaponInitialRotation.toRotationMatrix();
|
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +181,6 @@ void Character::updateAnimationForRender(const CharacterState& state) {
|
|||||||
anim.gpuSkinningShaderData.ComputeSkinningMatrices(
|
anim.gpuSkinningShaderData.ComputeSkinningMatrices(
|
||||||
anim.model.startBones, anim.model.animations[0].keyFrames,
|
anim.model.startBones, anim.model.animations[0].keyFrames,
|
||||||
anim.currentFrame);
|
anim.currentFrame);
|
||||||
if (!state.useGpuSkinning)
|
|
||||||
anim.model.Interpolate(anim.currentFrame);
|
|
||||||
}
|
}
|
||||||
anim.lastFrame = anim.currentFrame;
|
anim.lastFrame = anim.currentFrame;
|
||||||
}
|
}
|
||||||
@@ -257,97 +228,117 @@ void Character::update(int64_t deltaMs, const CharacterUpdateEvents* events) {
|
|||||||
updateAnimationForRender(state);
|
updateAnimationForRender(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::draw(Renderer& renderer) {
|
// ==================== Draw helpers ====================
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
|
||||||
glDisable(GL_BLEND);
|
|
||||||
|
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
namespace {
|
||||||
if (!stateSnapshot) return;
|
|
||||||
CharacterState state = interpolatedState(*stateSnapshot);
|
void setPlayerEyePos(Renderer& renderer) {
|
||||||
if (!state.enabled) return;
|
const float playerEyePos[3] = { 0.0f, 0.0f, -Environment::zoom };
|
||||||
|
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushCharacterProjection(Renderer& renderer) {
|
||||||
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||||
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model-space transform shared by every character pass (mesh and weapon).
|
||||||
|
void applyModelTransform(Renderer& renderer, const CharacterState& state) {
|
||||||
|
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
||||||
|
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||||
|
renderer.ScaleMatrix(state.modelScale);
|
||||||
|
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
void bindShadowMap(GLuint shadowMapTex) {
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, shadowMapTex);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NightLights {
|
||||||
|
const float* posEye;
|
||||||
|
const float* dirEye;
|
||||||
|
const float* colors;
|
||||||
|
int count;
|
||||||
|
const float* worldXZ;
|
||||||
|
const float* limitXZ;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Uniforms shared by the "night_fog" family of shaders (without shadows).
|
||||||
|
void applyNightUniforms(Renderer& renderer, const NightLights& lights,
|
||||||
|
const float* ambientColor, const float* fogColor) {
|
||||||
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
||||||
|
renderer.RenderUniform3fv("uFogColor", fogColor);
|
||||||
|
setPlayerEyePos(renderer);
|
||||||
|
renderer.RenderUniform1i("uPointLightCount", lights.count);
|
||||||
|
if (lights.count > 0) {
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightPos[0]", lights.count, lights.posEye);
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightDir[0]", lights.count, lights.dirEye);
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightColor[0]", lights.count, lights.colors);
|
||||||
|
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", lights.count, lights.worldXZ);
|
||||||
|
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", lights.count, lights.limitXZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uniforms shared by the "night_fog_*_shadow" family of shaders.
|
||||||
|
void applyNightShadowUniforms(Renderer& renderer, const NightLights& lights,
|
||||||
|
const Eigen::Matrix4f& lightFromCamera,
|
||||||
|
const float* ambientColor, const float* fogColor) {
|
||||||
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
renderer.RenderUniform1i("uShadowMap", 1);
|
||||||
|
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
||||||
|
renderer.RenderUniform3fv("uFogColor", fogColor);
|
||||||
|
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
||||||
|
if (lights.count > 0) renderer.RenderUniform3fv("uLightDir", lights.dirEye);
|
||||||
|
setPlayerEyePos(renderer);
|
||||||
|
renderer.RenderUniform1i("uPointLightCount", lights.count);
|
||||||
|
if (lights.count > 0) {
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightPos[0]", lights.count, lights.posEye);
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightDir[0]", lights.count, lights.dirEye);
|
||||||
|
renderer.RenderUniform3fvArray("uPointLightColor[0]", lights.count, lights.colors);
|
||||||
|
}
|
||||||
|
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", lights.count, lights.worldXZ);
|
||||||
|
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", lights.count, lights.limitXZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool Character::prepareForDraw(CharacterState& state) {
|
||||||
|
auto snapshot = stateSnapshot();
|
||||||
|
if (!snapshot) return false;
|
||||||
|
state = interpolatedState(*snapshot);
|
||||||
|
if (!state.enabled) return false;
|
||||||
|
updateAnimationForRender(state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Character::drawHitSparks(Renderer& renderer) {
|
||||||
if (hitSparkEmitter.isConfigured() && hitSparkEmitter.getActiveParticleCount() > 0) {
|
if (hitSparkEmitter.isConfigured() && hitSparkEmitter.getActiveParticleCount() > 0) {
|
||||||
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
|
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
|
||||||
}
|
}
|
||||||
updateAnimationForRender(state);
|
|
||||||
|
|
||||||
if (state.useGpuSkinning) {
|
|
||||||
drawGpuSkinning(renderer, state);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("fog");
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
const float playerEyePos[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePos);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
|
||||||
for (const auto& name : anim.model.meshNamesOrdered) {
|
|
||||||
auto mit = anim.model.meshes.find(name);
|
|
||||||
if (mit == anim.model.meshes.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
modelMutable.AssignFrom(mit->second.mesh);
|
|
||||||
modelMutable.RefreshVBO();
|
|
||||||
renderer.DrawVertexRenderStruct(modelMutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawGpuSkinning(Renderer& renderer, const CharacterState& state) {
|
BoneAnimationDataNew* Character::prepareGpuSkinning(const CharacterState& state) {
|
||||||
AnimationState drawState = resolveActiveState(state);
|
auto it = animations.find(resolveActiveState(state));
|
||||||
auto it = animations.find(drawState);
|
if (it == animations.end()) return nullptr;
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
auto& anim = it->second;
|
||||||
anim.gpuSkinningShaderData.prepareGpuSkinningVBOs(anim.model);
|
anim.gpuSkinningShaderData.prepareGpuSkinningVBOs(anim.model);
|
||||||
|
|
||||||
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) {
|
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) {
|
||||||
if (anim.model.animations.empty() || anim.model.animations[0].keyFrames.empty()) return;
|
if (anim.model.animations.empty() || anim.model.animations[0].keyFrames.empty()) return nullptr;
|
||||||
anim.gpuSkinningShaderData.ComputeSkinningMatrices(
|
anim.gpuSkinningShaderData.ComputeSkinningMatrices(
|
||||||
anim.model.startBones, anim.model.animations[0].keyFrames,
|
anim.model.startBones, anim.model.animations[0].keyFrames,
|
||||||
anim.currentFrame);
|
anim.currentFrame);
|
||||||
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) return;
|
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) return nullptr;
|
||||||
}
|
}
|
||||||
|
return &anim;
|
||||||
|
}
|
||||||
|
|
||||||
static const std::string skinningShaderName = "fog_skinning";
|
void Character::drawSkinnedMeshes(Renderer& renderer, BoneAnimationDataNew& anim, bool bindTextures) {
|
||||||
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(skinningShaderName);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
const float playerEyePosSkin[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosSkin);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
||||||
static_cast<int>(anim.gpuSkinningShaderData.skinningMatrices.size()), false,
|
static_cast<int>(anim.gpuSkinningShaderData.skinningMatrices.size()), false,
|
||||||
anim.gpuSkinningShaderData.skinningMatrices[0].data());
|
anim.gpuSkinningShaderData.skinningMatrices[0].data());
|
||||||
@@ -357,37 +348,18 @@ void Character::drawGpuSkinning(Renderer& renderer, const CharacterState& state)
|
|||||||
if (pit == anim.gpuSkinningShaderData.perMesh.end()) continue;
|
if (pit == anim.gpuSkinningShaderData.perMesh.end()) continue;
|
||||||
auto tit = meshTextures.find(name);
|
auto tit = meshTextures.find(name);
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
if (tit == meshTextures.end() || !tit->second) continue;
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
if (bindTextures) glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
||||||
pit->second.RenderVBO(renderer);
|
pit->second.RenderVBO(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("fog");
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosSkin);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Character::prepareGpuSkinning(const CharacterState& state) {
|
// Draws the weapon with the plain "fog" shader (used after the skinned mesh).
|
||||||
AnimationState drawState = resolveActiveState(state);
|
void Character::drawFogWeapon(Renderer& renderer, const CharacterState& state) {
|
||||||
auto it = animations.find(drawState);
|
renderer.shaderManager.PushShader("fog");
|
||||||
if (it == animations.end()) return false;
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
setPlayerEyePos(renderer);
|
||||||
auto& anim = it->second;
|
drawAttachedWeapon(renderer, state);
|
||||||
anim.gpuSkinningShaderData.prepareGpuSkinningVBOs(anim.model);
|
renderer.shaderManager.PopShader();
|
||||||
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) {
|
|
||||||
if (anim.model.animations.empty() || anim.model.animations[0].keyFrames.empty()) return false;
|
|
||||||
anim.gpuSkinningShaderData.ComputeSkinningMatrices(
|
|
||||||
anim.model.startBones, anim.model.animations[0].keyFrames,
|
|
||||||
anim.currentFrame);
|
|
||||||
if (anim.gpuSkinningShaderData.skinningMatrices.empty()) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawAttachedWeapon(Renderer& renderer, const CharacterState& state) {
|
void Character::drawAttachedWeapon(Renderer& renderer, const CharacterState& state) {
|
||||||
@@ -407,10 +379,7 @@ void Character::drawAttachedWeapon(Renderer& renderer, const CharacterState& sta
|
|||||||
Eigen::Matrix4f currentBone = anim.gpuSkinningShaderData.skinningMatrices[boneIdx] * bindBone;
|
Eigen::Matrix4f currentBone = anim.gpuSkinningShaderData.skinningMatrices[boneIdx] * bindBone;
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
applyModelTransform(renderer, state);
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
renderer.TranslateMatrix(Eigen::Vector3f(currentBone.block<3, 1>(0, 3)));
|
renderer.TranslateMatrix(Eigen::Vector3f(currentBone.block<3, 1>(0, 3)));
|
||||||
renderer.RotateMatrix(Eigen::Matrix3f(currentBone.block<3, 3>(0, 0)));
|
renderer.RotateMatrix(Eigen::Matrix3f(currentBone.block<3, 3>(0, 0)));
|
||||||
renderer.TranslateMatrix(weaponInitialPosition);
|
renderer.TranslateMatrix(weaponInitialPosition);
|
||||||
@@ -421,83 +390,61 @@ void Character::drawAttachedWeapon(Renderer& renderer, const CharacterState& sta
|
|||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== Main pass ====================
|
||||||
|
|
||||||
|
void Character::draw(Renderer& renderer) {
|
||||||
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
CharacterState state;
|
||||||
|
if (!prepareForDraw(state)) return;
|
||||||
|
drawHitSparks(renderer);
|
||||||
|
drawGpuSkinning(renderer, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Character::drawGpuSkinning(Renderer& renderer, const CharacterState& state) {
|
||||||
|
BoneAnimationDataNew* anim = prepareGpuSkinning(state);
|
||||||
|
if (!anim) return;
|
||||||
|
|
||||||
|
static const std::string skinningShaderName = "fog_skinning";
|
||||||
|
|
||||||
|
renderer.shaderManager.PushShader(skinningShaderName);
|
||||||
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
|
setPlayerEyePos(renderer);
|
||||||
|
|
||||||
|
pushCharacterProjection(renderer);
|
||||||
|
|
||||||
|
renderer.PushMatrix();
|
||||||
|
applyModelTransform(renderer, state);
|
||||||
|
drawSkinnedMeshes(renderer, *anim, true);
|
||||||
|
renderer.PopMatrix();
|
||||||
|
|
||||||
|
drawFogWeapon(renderer, state);
|
||||||
|
|
||||||
|
renderer.PopProjectionMatrix();
|
||||||
|
renderer.shaderManager.PopShader();
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== Shadow depth pass ====================
|
// ==================== Shadow depth pass ====================
|
||||||
|
|
||||||
void Character::drawShadowDepth(Renderer& renderer) {
|
void Character::drawShadowDepth(Renderer& renderer) {
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
CharacterState state;
|
||||||
if (!stateSnapshot) return;
|
if (!prepareForDraw(state)) return;
|
||||||
CharacterState state = interpolatedState(*stateSnapshot);
|
drawShadowDepthGpuSkinning(renderer, state);
|
||||||
if (!state.enabled) return;
|
|
||||||
updateAnimationForRender(state);
|
|
||||||
if (state.useGpuSkinning) {
|
|
||||||
drawShadowDepthGpuSkinning(renderer, state);
|
|
||||||
} else {
|
|
||||||
drawShadowDepthCpu(renderer, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Character::drawShadowDepthCpu(Renderer& renderer, const CharacterState& state) {
|
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
|
||||||
for (const auto& name : anim.model.meshNamesOrdered) {
|
|
||||||
auto mit = anim.model.meshes.find(name);
|
|
||||||
if (mit == anim.model.meshes.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
modelMutable.AssignFrom(mit->second.mesh);
|
|
||||||
modelMutable.RefreshVBO();
|
|
||||||
renderer.DrawVertexRenderStruct(modelMutable);
|
|
||||||
}
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawShadowDepthGpuSkinning(Renderer& renderer, const CharacterState& state) {
|
void Character::drawShadowDepthGpuSkinning(Renderer& renderer, const CharacterState& state) {
|
||||||
CheckGlError(__FILE__, __LINE__);
|
CheckGlError(__FILE__, __LINE__);
|
||||||
AnimationState drawState = resolveActiveState(state);
|
BoneAnimationDataNew* anim = prepareGpuSkinning(state);
|
||||||
auto it = animations.find(drawState);
|
if (!anim) return;
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
if (!prepareGpuSkinning(state)) return;
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
|
|
||||||
static const std::string shadowSkinningShader = "shadow_depth_skinning";
|
static const std::string shadowSkinningShader = "shadow_depth_skinning";
|
||||||
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(shadowSkinningShader);
|
renderer.shaderManager.PushShader(shadowSkinningShader);
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
applyModelTransform(renderer, state);
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
drawSkinnedMeshes(renderer, *anim, false);
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
|
||||||
static_cast<int>(it->second.gpuSkinningShaderData.skinningMatrices.size()), false,
|
|
||||||
it->second.gpuSkinningShaderData.skinningMatrices[0].data());
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
for (const auto& name : it->second.model.meshNamesOrdered) {
|
|
||||||
auto pit = it->second.gpuSkinningShaderData.perMesh.find(name);
|
|
||||||
if (pit == it->second.gpuSkinningShaderData.perMesh.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
pit->second.RenderVBO(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
@@ -508,145 +455,42 @@ void Character::drawShadowDepthGpuSkinning(Renderer& renderer, const CharacterSt
|
|||||||
// ==================== Main pass with shadows ====================
|
// ==================== Main pass with shadows ====================
|
||||||
|
|
||||||
void Character::drawWithShadow(Renderer& renderer, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
|
void Character::drawWithShadow(Renderer& renderer, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
CharacterState state;
|
||||||
if (!stateSnapshot) return;
|
if (!prepareForDraw(state)) return;
|
||||||
CharacterState state = interpolatedState(*stateSnapshot);
|
drawHitSparks(renderer);
|
||||||
if (!state.enabled) return;
|
|
||||||
updateAnimationForRender(state);
|
|
||||||
if (hitSparkEmitter.isConfigured() && hitSparkEmitter.getActiveParticleCount() > 0) {
|
|
||||||
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
if (state.useGpuSkinning) {
|
drawGpuSkinningWithShadow(renderer, state, lightFromCamera, shadowMapTex, lightDirCamera);
|
||||||
drawGpuSkinningWithShadow(renderer, state, lightFromCamera, shadowMapTex, lightDirCamera);
|
|
||||||
} else {
|
|
||||||
drawCpuWithShadow(renderer, state, lightFromCamera, shadowMapTex, lightDirCamera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Character::drawCpuWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
|
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
static const std::string shadowShader = "fog_shadow";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(shadowShader);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform1i("uShadowMap", 1);
|
|
||||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
|
||||||
renderer.RenderUniform3fv("uLightDir", lightDirCamera.data());
|
|
||||||
const float playerEyePosShadow[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosShadow);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowMapTex);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
|
||||||
for (const auto& name : anim.model.meshNamesOrdered) {
|
|
||||||
auto mit = anim.model.meshes.find(name);
|
|
||||||
if (mit == anim.model.meshes.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
modelMutable.AssignFrom(mit->second.mesh);
|
|
||||||
modelMutable.RefreshVBO();
|
|
||||||
renderer.DrawVertexRenderStruct(modelMutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("fog");
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosShadow);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawGpuSkinningWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
|
void Character::drawGpuSkinningWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
if (!prepareGpuSkinning(state)) return;
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
CheckGlError(__FILE__, __LINE__);
|
||||||
|
BoneAnimationDataNew* anim = prepareGpuSkinning(state);
|
||||||
|
if (!anim) return;
|
||||||
|
|
||||||
static const std::string skinningShadowShader = "fog_skinning_shadow";
|
static const std::string skinningShadowShader = "fog_skinning_shadow";
|
||||||
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(skinningShadowShader);
|
renderer.shaderManager.PushShader(skinningShadowShader);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
renderer.RenderUniform1i("uShadowMap", 1);
|
renderer.RenderUniform1i("uShadowMap", 1);
|
||||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
||||||
renderer.RenderUniform3fv("uLightDir", lightDirCamera.data());
|
renderer.RenderUniform3fv("uLightDir", lightDirCamera.data());
|
||||||
const float playerEyePosSkinShadow[3] = { 0.0f, 0.0f, -Environment::zoom };
|
setPlayerEyePos(renderer);
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosSkinShadow);
|
bindShadowMap(shadowMapTex);
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
pushCharacterProjection(renderer);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowMapTex);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
applyModelTransform(renderer, state);
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
drawSkinnedMeshes(renderer, *anim, true);
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
|
||||||
static_cast<int>(it->second.gpuSkinningShaderData.skinningMatrices.size()), false,
|
|
||||||
it->second.gpuSkinningShaderData.skinningMatrices[0].data());
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
|
|
||||||
for (const auto& name : it->second.model.meshNamesOrdered) {
|
|
||||||
auto pit = it->second.gpuSkinningShaderData.perMesh.find(name);
|
|
||||||
if (pit == it->second.gpuSkinningShaderData.perMesh.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
pit->second.RenderVBO(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("fog");
|
drawFogWeapon(renderer, state);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosSkinShadow);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
CheckGlError(__FILE__, __LINE__);
|
CheckGlError(__FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -659,25 +503,15 @@ void Character::drawNight(Renderer& renderer,
|
|||||||
const Eigen::Matrix4f& cameraViewInverse,
|
const Eigen::Matrix4f& cameraViewInverse,
|
||||||
const float* ambientColor, const float* fogColor)
|
const float* ambientColor, const float* fogColor)
|
||||||
{
|
{
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
CharacterState state;
|
||||||
if (!stateSnapshot) return;
|
if (!prepareForDraw(state)) return;
|
||||||
CharacterState state = interpolatedState(*stateSnapshot);
|
drawHitSparks(renderer);
|
||||||
if (!state.enabled) return;
|
|
||||||
updateAnimationForRender(state);
|
|
||||||
if (hitSparkEmitter.isConfigured() && hitSparkEmitter.getActiveParticleCount() > 0) {
|
|
||||||
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
if (state.useGpuSkinning) {
|
drawNightGpuSkinning(renderer, state, pointLightPosEye, pointLightDirEye, pointLightColors, pointLightCount,
|
||||||
drawNightGpuSkinning(renderer, state, pointLightPosEye, pointLightDirEye, pointLightColors, pointLightCount,
|
pointLightWorldXZ, pointLightLimitXZ, cameraViewInverse, ambientColor, fogColor);
|
||||||
pointLightWorldXZ, pointLightLimitXZ, cameraViewInverse, ambientColor, fogColor);
|
|
||||||
} else {
|
|
||||||
drawNightCpu(renderer, state, pointLightPosEye, pointLightDirEye, pointLightColors, pointLightCount,
|
|
||||||
pointLightWorldXZ, pointLightLimitXZ, cameraViewInverse, ambientColor, fogColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawNightGpuSkinning(Renderer& renderer,
|
void Character::drawNightGpuSkinning(Renderer& renderer,
|
||||||
@@ -686,69 +520,25 @@ void Character::drawNightGpuSkinning(Renderer& renderer,
|
|||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
||||||
const float* ambientColor, const float* fogColor)
|
const float* ambientColor, const float* fogColor)
|
||||||
{
|
{
|
||||||
AnimationState drawState = resolveActiveState(state);
|
BoneAnimationDataNew* anim = prepareGpuSkinning(state);
|
||||||
auto it = animations.find(drawState);
|
if (!anim) return;
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
if (!prepareGpuSkinning(state)) return;
|
|
||||||
|
|
||||||
|
const NightLights lights{ plPosEye, plDirEye, plColors, plCount, plWorldXZ, plLimitXZ };
|
||||||
static const std::string nightSkinningShader = "night_fog_skinning";
|
static const std::string nightSkinningShader = "night_fog_skinning";
|
||||||
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(nightSkinningShader);
|
renderer.shaderManager.PushShader(nightSkinningShader);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
applyNightUniforms(renderer, lights, ambientColor, fogColor);
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
const float playerEyePosNight[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNight);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
}
|
|
||||||
renderer.RenderUniformMatrix4fv("uViewInverse", false, cameraViewInverse.data());
|
renderer.RenderUniformMatrix4fv("uViewInverse", false, cameraViewInverse.data());
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
pushCharacterProjection(renderer);
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
applyModelTransform(renderer, state);
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
drawSkinnedMeshes(renderer, *anim, true);
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
|
||||||
static_cast<int>(it->second.gpuSkinningShaderData.skinningMatrices.size()), false,
|
|
||||||
it->second.gpuSkinningShaderData.skinningMatrices[0].data());
|
|
||||||
|
|
||||||
for (const auto& name : it->second.model.meshNamesOrdered) {
|
|
||||||
auto pit = it->second.gpuSkinningShaderData.perMesh.find(name);
|
|
||||||
if (pit == it->second.gpuSkinningShaderData.perMesh.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
pit->second.RenderVBO(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("night_fog");
|
renderer.shaderManager.PushShader("night_fog");
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
applyNightUniforms(renderer, lights, ambientColor, fogColor);
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNight);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
}
|
|
||||||
drawAttachedWeapon(renderer, state);
|
drawAttachedWeapon(renderer, state);
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
@@ -756,64 +546,6 @@ void Character::drawNightGpuSkinning(Renderer& renderer,
|
|||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawNightCpu(Renderer& renderer,
|
|
||||||
const CharacterState& state,
|
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
|
||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
|
||||||
const float* ambientColor, const float* fogColor)
|
|
||||||
{
|
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
static const std::string nightShader = "night_fog";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(nightShader);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
const float playerEyePosNight[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNight);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
|
||||||
for (const auto& name : anim.model.meshNamesOrdered) {
|
|
||||||
auto mit = anim.model.meshes.find(name);
|
|
||||||
if (mit == anim.model.meshes.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
modelMutable.AssignFrom(mit->second.mesh);
|
|
||||||
modelMutable.RefreshVBO();
|
|
||||||
renderer.DrawVertexRenderStruct(modelMutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNight);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== Night pass with spot-light + shadow ====================
|
// ==================== Night pass with spot-light + shadow ====================
|
||||||
|
|
||||||
void Character::drawNightWithShadow(Renderer& renderer,
|
void Character::drawNightWithShadow(Renderer& renderer,
|
||||||
@@ -823,26 +555,15 @@ void Character::drawNightWithShadow(Renderer& renderer,
|
|||||||
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex,
|
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex,
|
||||||
const float* ambientColor, const float* fogColor)
|
const float* ambientColor, const float* fogColor)
|
||||||
{
|
{
|
||||||
auto stateSnapshot = this->stateSnapshot();
|
CharacterState state;
|
||||||
if (!stateSnapshot) return;
|
if (!prepareForDraw(state)) return;
|
||||||
CharacterState state = interpolatedState(*stateSnapshot);
|
drawHitSparks(renderer);
|
||||||
if (!state.enabled) return;
|
|
||||||
updateAnimationForRender(state);
|
|
||||||
if (hitSparkEmitter.isConfigured() && hitSparkEmitter.getActiveParticleCount() > 0) {
|
|
||||||
hitSparkEmitter.draw(renderer, 1.0f, Environment::width, Environment::height, false);
|
|
||||||
}
|
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
if (state.useGpuSkinning) {
|
drawNightGpuSkinningWithShadow(renderer, state, plPosEye, plDirEye, plColors, plCount,
|
||||||
drawNightGpuSkinningWithShadow(renderer, state, plPosEye, plDirEye, plColors, plCount,
|
plWorldXZ, plLimitXZ, cameraViewInverse,
|
||||||
plWorldXZ, plLimitXZ, cameraViewInverse,
|
lightFromCamera, shadowMapTex, ambientColor, fogColor);
|
||||||
lightFromCamera, shadowMapTex, ambientColor, fogColor);
|
|
||||||
} else {
|
|
||||||
drawNightCpuWithShadow(renderer, state, plPosEye, plDirEye, plColors, plCount,
|
|
||||||
plWorldXZ, plLimitXZ, cameraViewInverse,
|
|
||||||
lightFromCamera, shadowMapTex, ambientColor, fogColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawNightGpuSkinningWithShadow(Renderer& renderer,
|
void Character::drawNightGpuSkinningWithShadow(Renderer& renderer,
|
||||||
@@ -853,79 +574,26 @@ void Character::drawNightGpuSkinningWithShadow(Renderer& renderer,
|
|||||||
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex,
|
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex,
|
||||||
const float* ambientColor, const float* fogColor)
|
const float* ambientColor, const float* fogColor)
|
||||||
{
|
{
|
||||||
AnimationState drawState = resolveActiveState(state);
|
BoneAnimationDataNew* anim = prepareGpuSkinning(state);
|
||||||
auto it = animations.find(drawState);
|
if (!anim) return;
|
||||||
if (it == animations.end()) return;
|
|
||||||
if (!prepareGpuSkinning(state)) return;
|
|
||||||
|
|
||||||
|
const NightLights lights{ plPosEye, plDirEye, plColors, plCount, plWorldXZ, plLimitXZ };
|
||||||
static const std::string nightShadowSkinningShader = "night_fog_skinning_shadow";
|
static const std::string nightShadowSkinningShader = "night_fog_skinning_shadow";
|
||||||
static const std::string boneMatricesUniform = "uBoneMatrices[0]";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(nightShadowSkinningShader);
|
renderer.shaderManager.PushShader(nightShadowSkinningShader);
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
applyNightShadowUniforms(renderer, lights, lightFromCamera, ambientColor, fogColor);
|
||||||
renderer.RenderUniform1i("uShadowMap", 1);
|
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
|
||||||
if (plCount > 0) renderer.RenderUniform3fv("uLightDir", plDirEye);
|
|
||||||
|
|
||||||
const float playerEyePosNightShadow[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNightShadow);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
}
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
renderer.RenderUniformMatrix4fv("uViewInverse", false, cameraViewInverse.data());
|
renderer.RenderUniformMatrix4fv("uViewInverse", false, cameraViewInverse.data());
|
||||||
|
bindShadowMap(shadowMapTex);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
pushCharacterProjection(renderer);
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowMapTex);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
applyModelTransform(renderer, state);
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
drawSkinnedMeshes(renderer, *anim, true);
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
renderer.RenderUniformMatrix4fvArray(boneMatricesUniform,
|
|
||||||
static_cast<int>(it->second.gpuSkinningShaderData.skinningMatrices.size()), false,
|
|
||||||
it->second.gpuSkinningShaderData.skinningMatrices[0].data());
|
|
||||||
|
|
||||||
for (const auto& name : it->second.model.meshNamesOrdered) {
|
|
||||||
auto pit = it->second.gpuSkinningShaderData.perMesh.find(name);
|
|
||||||
if (pit == it->second.gpuSkinningShaderData.perMesh.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
pit->second.RenderVBO(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
renderer.shaderManager.PushShader("night_fog_shadow");
|
renderer.shaderManager.PushShader("night_fog_shadow");
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
applyNightShadowUniforms(renderer, lights, lightFromCamera, ambientColor, fogColor);
|
||||||
renderer.RenderUniform1i("uShadowMap", 1);
|
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
|
||||||
if (plCount > 0) renderer.RenderUniform3fv("uLightDir", plDirEye);
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNightShadow);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
}
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
drawAttachedWeapon(renderer, state);
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
@@ -933,74 +601,6 @@ void Character::drawNightGpuSkinningWithShadow(Renderer& renderer,
|
|||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::drawNightCpuWithShadow(Renderer& renderer,
|
|
||||||
const CharacterState& state,
|
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
|
||||||
const float* plWorldXZ, const float* plLimitXZ,
|
|
||||||
const Eigen::Matrix4f& cameraViewInverse,
|
|
||||||
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex,
|
|
||||||
const float* ambientColor, const float* fogColor)
|
|
||||||
{
|
|
||||||
AnimationState drawState = resolveActiveState(state);
|
|
||||||
auto it = animations.find(drawState);
|
|
||||||
if (it == animations.end()) return;
|
|
||||||
|
|
||||||
static const std::string nightShadowShader = "night_fog_shadow";
|
|
||||||
|
|
||||||
renderer.shaderManager.PushShader(nightShadowShader);
|
|
||||||
renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
renderer.RenderUniform1i("uShadowMap", 1);
|
|
||||||
renderer.RenderUniform3fv("uAmbientColor", ambientColor);
|
|
||||||
renderer.RenderUniform3fv("uFogColor", fogColor);
|
|
||||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
|
||||||
if (plCount > 0) renderer.RenderUniform3fv("uLightDir", plDirEye);
|
|
||||||
|
|
||||||
const float playerEyePosNightShadow[3] = { 0.0f, 0.0f, -Environment::zoom };
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNightShadow);
|
|
||||||
renderer.RenderUniform1i("uPointLightCount", plCount);
|
|
||||||
if (plCount > 0) {
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightPos[0]", plCount, plPosEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightDir[0]", plCount, plDirEye);
|
|
||||||
renderer.RenderUniform3fvArray("uPointLightColor[0]", plCount, plColors);
|
|
||||||
}
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightWorldXZ[0]", plCount, plWorldXZ);
|
|
||||||
renderer.RenderUniform2fvArray("uPointLightLimitXZ[0]", plCount, plLimitXZ);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, shadowMapTex);
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
|
|
||||||
renderer.PushMatrix();
|
|
||||||
renderer.TranslateMatrix({ static_cast<float>(state.position.x), static_cast<float>(state.position.y), static_cast<float>(state.position.z) });
|
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-static_cast<float>(state.facingAngle), Eigen::Vector3f::UnitY())).toRotationMatrix());
|
|
||||||
renderer.ScaleMatrix(state.modelScale);
|
|
||||||
renderer.RotateMatrix(state.modelCorrectionRotation.toRotationMatrix());
|
|
||||||
|
|
||||||
auto& anim = it->second;
|
|
||||||
for (const auto& name : anim.model.meshNamesOrdered) {
|
|
||||||
auto mit = anim.model.meshes.find(name);
|
|
||||||
if (mit == anim.model.meshes.end()) continue;
|
|
||||||
auto tit = meshTextures.find(name);
|
|
||||||
if (tit == meshTextures.end() || !tit->second) continue;
|
|
||||||
glBindTexture(GL_TEXTURE_2D, tit->second->getTexID());
|
|
||||||
modelMutable.AssignFrom(mit->second.mesh);
|
|
||||||
modelMutable.RefreshVBO();
|
|
||||||
renderer.DrawVertexRenderStruct(modelMutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.PopMatrix();
|
|
||||||
|
|
||||||
renderer.RenderUniform3fv("uPlayerEyePos", playerEyePosNightShadow);
|
|
||||||
drawAttachedWeapon(renderer, state);
|
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
|
||||||
renderer.shaderManager.PopShader();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Character::setupHitSparks(std::shared_ptr<Texture> sparkTexture) {
|
void Character::setupHitSparks(std::shared_ptr<Texture> sparkTexture) {
|
||||||
hitSparkEmitter.setTexture(sparkTexture);
|
hitSparkEmitter.setTexture(sparkTexture);
|
||||||
hitSparkEmitter.setShaderProgramName("spark");
|
hitSparkEmitter.setShaderProgramName("spark");
|
||||||
|
|||||||
+10
-20
@@ -31,7 +31,6 @@ public:
|
|||||||
// The aliasing shared_ptr keeps the owning GameSnapshot alive for as long
|
// The aliasing shared_ptr keeps the owning GameSnapshot alive for as long
|
||||||
// as the returned CharacterState is being read.
|
// as the returned CharacterState is being read.
|
||||||
std::shared_ptr<const CharacterState> stateSnapshot() const;
|
std::shared_ptr<const CharacterState> stateSnapshot() const;
|
||||||
static constexpr float kAttackRange = 1.25f;
|
|
||||||
|
|
||||||
// ---- Asset loading ----
|
// ---- Asset loading ----
|
||||||
void loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile = "");
|
void loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile = "");
|
||||||
@@ -43,7 +42,7 @@ public:
|
|||||||
void setTexture(std::shared_ptr<FRG::Texture> texture);
|
void setTexture(std::shared_ptr<FRG::Texture> texture);
|
||||||
|
|
||||||
// Creates a fully-loaded Character from a CharacterState (including its creationInfo).
|
// Creates a fully-loaded Character from a CharacterState (including its creationInfo).
|
||||||
// Loads all animations, textures, and weapon mesh/texture from the paths stored in creationInfo.
|
// Loads all animations and textures from the paths stored in creationInfo.
|
||||||
static std::unique_ptr<Character> createFromState(
|
static std::unique_ptr<Character> createFromState(
|
||||||
const CharacterState& initialState, IGameServer& server,
|
const CharacterState& initialState, IGameServer& server,
|
||||||
const std::string& locationId, const std::string& entityId,
|
const std::string& locationId, const std::string& entityId,
|
||||||
@@ -111,16 +110,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class Game;
|
friend class Game;
|
||||||
friend class Location;
|
friend class Location;
|
||||||
friend class ScriptEngine;
|
|
||||||
friend class LocationEditor;
|
|
||||||
friend class PathVisualization;
|
|
||||||
IGameServer& gameServer_;
|
IGameServer& gameServer_;
|
||||||
std::string locationId_;
|
std::string locationId_;
|
||||||
std::string entityId_;
|
std::string entityId_;
|
||||||
std::function<void()> onDeathAnimComplete;
|
std::function<void()> onDeathAnimComplete;
|
||||||
std::function<void(float, float, const std::string&)> onHpChanged;
|
std::function<void(float, float, const std::string&)> onHpChanged;
|
||||||
std::map<AnimationState, BoneAnimationDataNew> animations;
|
std::map<AnimationState, BoneAnimationDataNew> animations;
|
||||||
VertexRenderStruct modelMutable;
|
|
||||||
VertexRenderStruct healthBarMesh;
|
VertexRenderStruct healthBarMesh;
|
||||||
std::unordered_map<std::string, std::shared_ptr<Texture>> meshTextures;
|
std::unordered_map<std::string, std::shared_ptr<Texture>> meshTextures;
|
||||||
|
|
||||||
@@ -140,34 +135,29 @@ private:
|
|||||||
AnimationState resolveActiveState(const CharacterState& state) const;
|
AnimationState resolveActiveState(const CharacterState& state) const;
|
||||||
CharacterState interpolatedState(const CharacterState& state) const;
|
CharacterState interpolatedState(const CharacterState& state) const;
|
||||||
void updateAnimationForRender(const CharacterState& state);
|
void updateAnimationForRender(const CharacterState& state);
|
||||||
bool prepareGpuSkinning(const CharacterState& state);
|
// Interpolates the state for rendering and refreshes skinning data.
|
||||||
void drawAttachedWeapon(Renderer& renderer, const CharacterState& state);
|
// Returns false when there is nothing to draw (no state / disabled).
|
||||||
|
bool prepareForDraw(CharacterState& state);
|
||||||
|
void drawHitSparks(Renderer& renderer);
|
||||||
|
// Uploads skinning data for the active animation; nullptr if unavailable.
|
||||||
|
BoneAnimationDataNew* prepareGpuSkinning(const CharacterState& state);
|
||||||
|
void drawSkinnedMeshes(Renderer& renderer, BoneAnimationDataNew& anim, bool bindTextures);
|
||||||
|
void drawAttachedWeapon(Renderer& renderer, const CharacterState& state);
|
||||||
|
void drawFogWeapon(Renderer& renderer, const CharacterState& state);
|
||||||
|
|
||||||
void drawGpuSkinning(Renderer& renderer, const CharacterState& state);
|
void drawGpuSkinning(Renderer& renderer, const CharacterState& state);
|
||||||
void drawShadowDepthGpuSkinning(Renderer& renderer, const CharacterState& state);
|
void drawShadowDepthGpuSkinning(Renderer& renderer, const CharacterState& state);
|
||||||
void drawShadowDepthCpu(Renderer& renderer, const CharacterState& state);
|
|
||||||
void drawGpuSkinningWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera);
|
void drawGpuSkinningWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera);
|
||||||
void drawCpuWithShadow(Renderer& renderer, const CharacterState& state, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera);
|
|
||||||
void drawNightGpuSkinning(Renderer& renderer,
|
void drawNightGpuSkinning(Renderer& renderer,
|
||||||
const CharacterState& state,
|
const CharacterState& state,
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
||||||
const float* ambientColor, const float* fogColor);
|
const float* ambientColor, const float* fogColor);
|
||||||
void drawNightCpu(Renderer& renderer,
|
|
||||||
const CharacterState& state,
|
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
|
||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
|
||||||
const float* ambientColor, const float* fogColor);
|
|
||||||
void drawNightGpuSkinningWithShadow(Renderer& renderer,
|
void drawNightGpuSkinningWithShadow(Renderer& renderer,
|
||||||
const CharacterState& state,
|
const CharacterState& state,
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
||||||
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const float* ambientColor, const float* fogColor);
|
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const float* ambientColor, const float* fogColor);
|
||||||
void drawNightCpuWithShadow(Renderer& renderer,
|
|
||||||
const CharacterState& state,
|
|
||||||
const float* plPosEye, const float* plDirEye, const float* plColors, int plCount,
|
|
||||||
const float* plWorldXZ, const float* plLimitXZ, const Eigen::Matrix4f& cameraViewInverse,
|
|
||||||
const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const float* ambientColor, const float* fogColor);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FRG
|
} // namespace FRG
|
||||||
+62
-118
@@ -7,18 +7,16 @@
|
|||||||
namespace FRG {
|
namespace FRG {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
constexpr float kPi = 3.14159265358979323846f;
|
||||||
// Tick counts are authoritative and therefore independent of render rate.
|
// Tick counts are authoritative and therefore independent of render rate.
|
||||||
constexpr float ATTACK_COOLDOWN_TIME = 1.6f;
|
constexpr float ATTACK_COOLDOWN_TIME = 1.6f;
|
||||||
constexpr float HOME_DRIFT_CHECK_INTERVAL = 5.0f;
|
constexpr float HOME_DRIFT_CHECK_INTERVAL = 5.0f;
|
||||||
fp HOME_DRIFT_CHECK_INTERVAL_FP = static_cast<fp>(HOME_DRIFT_CHECK_INTERVAL);
|
const fp HOME_DRIFT_CHECK_INTERVAL_FP = static_cast<fp>(HOME_DRIFT_CHECK_INTERVAL);
|
||||||
|
// An NPC farther than this from its home position (squared) walks back.
|
||||||
|
const fp MAX_HOME_DRIFT_SQUARED = static_cast<fp>(3.f * 3.f);
|
||||||
constexpr float TARGET_REPLAN_THRESHOLD = 0.25f;
|
constexpr float TARGET_REPLAN_THRESHOLD = 0.25f;
|
||||||
|
|
||||||
fp TARGET_REPLAN_THRESHOLD_SQUARED = static_cast<fp>(TARGET_REPLAN_THRESHOLD * TARGET_REPLAN_THRESHOLD);
|
const fp TARGET_REPLAN_THRESHOLD_SQUARED = static_cast<fp>(TARGET_REPLAN_THRESHOLD * TARGET_REPLAN_THRESHOLD);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constexpr float PI = 3.14159265358979323846f;
|
|
||||||
constexpr int BLOCKED_REPLAN_TICKS = 3;
|
|
||||||
|
|
||||||
std::uint32_t stableIdHash(const std::string& value)
|
std::uint32_t stableIdHash(const std::string& value)
|
||||||
{
|
{
|
||||||
@@ -36,8 +34,8 @@ void CharacterState::configureAsPlayer() {
|
|||||||
rotationSpeed = static_cast < fp>(8.0f);
|
rotationSpeed = static_cast < fp>(8.0f);
|
||||||
modelScale = 1.f;
|
modelScale = 1.f;
|
||||||
modelCorrectionRotation = Eigen::Quaternionf(
|
modelCorrectionRotation = Eigen::Quaternionf(
|
||||||
Eigen::AngleAxisf(PI, Eigen::Vector3f::UnitY()) *
|
Eigen::AngleAxisf(kPi, Eigen::Vector3f::UnitY()) *
|
||||||
Eigen::AngleAxisf(-PI * 0.5f, Eigen::Vector3f::UnitX()));
|
Eigen::AngleAxisf(-kPi * 0.5f, Eigen::Vector3f::UnitX()));
|
||||||
canAttack = true;
|
canAttack = true;
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
animationPlaybackRates.fill(1.0f);
|
animationPlaybackRates.fill(1.0f);
|
||||||
@@ -95,20 +93,46 @@ void CharacterState::stopInPlace() {
|
|||||||
currentWaypointIndex = 0;
|
currentWaypointIndex = 0;
|
||||||
onArrivedCallbackName.clear();
|
onArrivedCallbackName.clear();
|
||||||
navigationOutcome = PathFinder::PathOutcome::ReachedExactGoal;
|
navigationOutcome = PathFinder::PathOutcome::ReachedExactGoal;
|
||||||
movementBlockedTicks = 0;
|
|
||||||
navigationRetryTicks = 0;
|
navigationRetryTicks = 0;
|
||||||
velocity = Vec2fp(fp(0), fp(0));
|
velocity = Vec2fp(fp(0), fp(0));
|
||||||
preferredVelocity = Vec2fp(fp(0), fp(0));
|
preferredVelocity = Vec2fp(fp(0), fp(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CharacterState::applyPathTo(
|
||||||
|
const Vec3fp& target, const LocationNetworkState& location)
|
||||||
|
{
|
||||||
|
if (location.activeNavigationIndex < 0 ||
|
||||||
|
location.activeNavigationIndex >= static_cast<int>(location.navigationMaps.size())) {
|
||||||
|
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
||||||
|
navigationOutcome = PathFinder::PathOutcome::NoPath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto pathResult = location.navigationMaps[location.activeNavigationIndex]
|
||||||
|
.findPathResult(this->position, target);
|
||||||
|
pathWaypoints = pathResult.waypoints;
|
||||||
|
navigationOutcome = pathResult.outcome;
|
||||||
|
|
||||||
|
// Сразу целимся во второй элемент (индекс 1), так как индекс 0 — это точка старта
|
||||||
|
currentWaypointIndex = (pathWaypoints.size() > 1) ? 1 : 0;
|
||||||
|
navigationRetryTicks = 0;
|
||||||
|
|
||||||
|
if (!pathWaypoints.empty()) {
|
||||||
|
for (Vec3fp& waypoint : pathWaypoints)
|
||||||
|
waypoint.y = static_cast<fp>(0.f);
|
||||||
|
walkTarget = pathWaypoints.back();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
||||||
|
if (!isPlayer) scheduleNextNavigationRetry();
|
||||||
|
}
|
||||||
|
|
||||||
void CharacterState::setTarget(
|
void CharacterState::setTarget(
|
||||||
const Vec3fp& target,
|
const Vec3fp& target,
|
||||||
std::string callbackName,
|
std::string callbackName,
|
||||||
const LocationNetworkState& location,
|
const LocationNetworkState& location)
|
||||||
const std::string& entityId)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
const Vec3fp normalizedTarget(target.x, static_cast<fp>(0.f), target.z);
|
const Vec3fp normalizedTarget(target.x, static_cast<fp>(0.f), target.z);
|
||||||
const bool sameRequestedTarget =
|
const bool sameRequestedTarget =
|
||||||
(normalizedTarget - requestedWalkTarget).normSquared() <= TARGET_REPLAN_THRESHOLD_SQUARED;
|
(normalizedTarget - requestedWalkTarget).normSquared() <= TARGET_REPLAN_THRESHOLD_SQUARED;
|
||||||
@@ -125,71 +149,30 @@ void CharacterState::setTarget(
|
|||||||
|
|
||||||
requestedWalkTarget = normalizedTarget;
|
requestedWalkTarget = normalizedTarget;
|
||||||
onArrivedCallbackName = std::move(callbackName);
|
onArrivedCallbackName = std::move(callbackName);
|
||||||
movementBlockedTicks = 0;
|
|
||||||
navigationRetryTicks = 0;
|
navigationRetryTicks = 0;
|
||||||
|
applyPathTo(normalizedTarget, location);
|
||||||
// В setTarget и forceReplan:
|
|
||||||
if (location.activeNavigationIndex < 0 ||
|
|
||||||
location.activeNavigationIndex >= static_cast<int>(location.navigationMaps.size())) {
|
|
||||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
|
||||||
navigationOutcome = PathFinder::PathOutcome::NoPath;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pathResult = location.navigationMaps[location.activeNavigationIndex]
|
|
||||||
.findPathResult(this->position, normalizedTarget);
|
|
||||||
pathWaypoints = pathResult.waypoints;
|
|
||||||
navigationOutcome = pathResult.outcome;
|
|
||||||
|
|
||||||
// Сразу целимся во второй элемент (индекс 1), так как индекс 0 — это точка старта
|
|
||||||
currentWaypointIndex = (pathWaypoints.size() > 1) ? 1 : 0;
|
|
||||||
|
|
||||||
if (!pathWaypoints.empty()) {
|
|
||||||
for (Vec3fp& waypoint : pathWaypoints)
|
|
||||||
{
|
|
||||||
waypoint.y = static_cast<fp>(0.f);
|
|
||||||
}
|
|
||||||
walkTarget = pathWaypoints.back();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
|
||||||
if (!isPlayer) scheduleNextNavigationRetry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterState::forceReplan(
|
void CharacterState::forceReplan(const LocationNetworkState& location)
|
||||||
const LocationNetworkState& location,
|
|
||||||
const std::string& entityId)
|
|
||||||
{
|
{
|
||||||
const Vec3fp normalizedTarget(
|
const Vec3fp normalizedTarget(
|
||||||
requestedWalkTarget.x, static_cast<fp>(0.f), requestedWalkTarget.z);
|
requestedWalkTarget.x, static_cast<fp>(0.f), requestedWalkTarget.z);
|
||||||
|
applyPathTo(normalizedTarget, location);
|
||||||
|
}
|
||||||
|
|
||||||
if (location.activeNavigationIndex < 0 ||
|
void CharacterState::updateFaceTarget(const CharacterObservation* faceTarget)
|
||||||
location.activeNavigationIndex >= static_cast<int>(location.navigationMaps.size())) {
|
{
|
||||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
if (faceTarget) {
|
||||||
navigationOutcome = PathFinder::PathOutcome::NoPath;
|
Vec3fp toFace = faceTarget->position - position;
|
||||||
return;
|
toFace.y = fp(0);
|
||||||
|
const fp distanceToFace = fpm::sqrt(toFace.normSquared());
|
||||||
|
targetFacingAngle = distanceToFace > static_cast<fp>(1e-3f)
|
||||||
|
? fpm::atan2(toFace.x / distanceToFace, -toFace.z / distanceToFace)
|
||||||
|
: facingAngle;
|
||||||
}
|
}
|
||||||
|
else if (!faceTargetId.empty()) {
|
||||||
const auto pathResult = location.navigationMaps[location.activeNavigationIndex]
|
faceTargetId.clear();
|
||||||
.findPathResult(this->position, normalizedTarget);
|
|
||||||
pathWaypoints = pathResult.waypoints;
|
|
||||||
navigationOutcome = pathResult.outcome;
|
|
||||||
|
|
||||||
currentWaypointIndex = (pathWaypoints.size() > 1) ? 1 : 0;
|
|
||||||
movementBlockedTicks = 0;
|
|
||||||
navigationRetryTicks = 0;
|
|
||||||
|
|
||||||
if (!pathWaypoints.empty()) {
|
|
||||||
for (Vec3fp& waypoint : pathWaypoints) {
|
|
||||||
waypoint.y = static_cast<fp>(0.f);
|
|
||||||
}
|
|
||||||
walkTarget = pathWaypoints.back();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
|
||||||
if (!isPlayer) scheduleNextNavigationRetry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterState::stopAndRotateToTarget(std::string characterId)
|
void CharacterState::stopAndRotateToTarget(std::string characterId)
|
||||||
@@ -239,9 +222,7 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
std::int64_t deltaMs, const CharacterUpdateContext& context)
|
std::int64_t deltaMs, const CharacterUpdateContext& context)
|
||||||
{
|
{
|
||||||
CharacterUpdateEvents events;
|
CharacterUpdateEvents events;
|
||||||
movedLastTick = false;
|
|
||||||
if (!enabled) return events;
|
if (!enabled) return events;
|
||||||
bool navigationPausedThisTick = false;
|
|
||||||
|
|
||||||
const CharacterObservation* attackTarget = context.attackTarget;
|
const CharacterObservation* attackTarget = context.attackTarget;
|
||||||
const CharacterObservation* faceTarget = context.faceTarget;
|
const CharacterObservation* faceTarget = context.faceTarget;
|
||||||
@@ -251,27 +232,21 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
attackTargetId.clear();
|
attackTargetId.clear();
|
||||||
} else {
|
} else {
|
||||||
const fp distanceSquared = (attackTarget->position - position).normSquared();
|
const fp distanceSquared = (attackTarget->position - position).normSquared();
|
||||||
if (distanceSquared >= visibleRange* visibleRange) {
|
if (distanceSquared >= visibleRange * visibleRange ||
|
||||||
|
distanceSquared >= static_cast<fp>(kAttackRange * kAttackRange)) {
|
||||||
|
// Out of attack range: chase the target.
|
||||||
if ((attackTarget->position - requestedWalkTarget).normSquared() >
|
if ((attackTarget->position - requestedWalkTarget).normSquared() >
|
||||||
TARGET_REPLAN_THRESHOLD_SQUARED) {
|
TARGET_REPLAN_THRESHOLD_SQUARED) {
|
||||||
events.navigationRequested = true;
|
events.navigationRequested = true;
|
||||||
events.navigationTarget = attackTarget->position;
|
events.navigationTarget = attackTarget->position;
|
||||||
}
|
}
|
||||||
battle_state = 0;
|
battle_state = 0;
|
||||||
} else if (distanceSquared >= static_cast<fp>(1.25f*1.25f)) {
|
|
||||||
if ((attackTarget->position - requestedWalkTarget).normSquared() > TARGET_REPLAN_THRESHOLD_SQUARED) {
|
|
||||||
events.navigationRequested = true;
|
|
||||||
events.navigationTarget = attackTarget->position;
|
|
||||||
}
|
|
||||||
battle_state = 0;
|
|
||||||
} else {
|
} else {
|
||||||
battle_state = 1;
|
battle_state = 1;
|
||||||
velocity = Vec2fp(fp(0), fp(0));
|
velocity = Vec2fp(fp(0), fp(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vec3fp activeTarget = getCurrentNavigationTarget();
|
|
||||||
|
|
||||||
preferredVelocity = Vec2fp(fp(0), fp(0));
|
preferredVelocity = Vec2fp(fp(0), fp(0));
|
||||||
|
|
||||||
if (hp > 0.f && battle_state == 0 && !pathWaypoints.empty() &&
|
if (hp > 0.f && battle_state == 0 && !pathWaypoints.empty() &&
|
||||||
@@ -341,17 +316,7 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
navigationOutcome != PathFinder::PathOutcome::ReachedExactGoal) {
|
navigationOutcome != PathFinder::PathOutcome::ReachedExactGoal) {
|
||||||
onArrivedCallbackName.clear();
|
onArrivedCallbackName.clear();
|
||||||
}
|
}
|
||||||
if (faceTarget) {
|
updateFaceTarget(faceTarget);
|
||||||
Vec3fp toFace = faceTarget->position - position;
|
|
||||||
toFace.y = fp(0);
|
|
||||||
const fp distanceToFace = fpm::sqrt(toFace.normSquared());
|
|
||||||
targetFacingAngle = distanceToFace > static_cast<fp>(1e-3f)
|
|
||||||
? fpm::atan2(toFace.x / distanceToFace, -toFace.z / distanceToFace)
|
|
||||||
: facingAngle;
|
|
||||||
}
|
|
||||||
else if (!faceTargetId.empty()) {
|
|
||||||
faceTargetId.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (hp > 0.f && battle_state == 0 && pathWaypoints.empty() &&
|
else if (hp > 0.f && battle_state == 0 && pathWaypoints.empty() &&
|
||||||
@@ -363,21 +328,10 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
currentState = AnimationState::STAND;
|
currentState = AnimationState::STAND;
|
||||||
resetAnim = true;
|
resetAnim = true;
|
||||||
}
|
}
|
||||||
if (faceTarget) {
|
updateFaceTarget(faceTarget);
|
||||||
Vec3fp toFace = faceTarget->position - position;
|
|
||||||
toFace.y = fp(0);
|
|
||||||
const fp distanceToFace = fpm::sqrt(toFace.normSquared());
|
|
||||||
targetFacingAngle = distanceToFace > static_cast<fp>(1e-3f)
|
|
||||||
? fpm::atan2(toFace.x / distanceToFace, -toFace.z / distanceToFace)
|
|
||||||
: facingAngle;
|
|
||||||
}
|
|
||||||
else if (!faceTargetId.empty()) {
|
|
||||||
faceTargetId.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isPlayer && pathWaypoints.empty() &&
|
||||||
if (!isPlayer && !navigationPausedThisTick && pathWaypoints.empty() &&
|
|
||||||
(requestedWalkTarget - position).normSquared() > TARGET_REPLAN_THRESHOLD_SQUARED &&
|
(requestedWalkTarget - position).normSquared() > TARGET_REPLAN_THRESHOLD_SQUARED &&
|
||||||
!events.navigationRequested) {
|
!events.navigationRequested) {
|
||||||
if (navigationRetryTicks > 0) --navigationRetryTicks;
|
if (navigationRetryTicks > 0) --navigationRetryTicks;
|
||||||
@@ -424,7 +378,7 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fp angleDiff = targetFacingAngle - facingAngle;
|
fp angleDiff = targetFacingAngle - facingAngle;
|
||||||
const fp PIfp = static_cast<fp>(PI);
|
const fp PIfp = static_cast<fp>(kPi);
|
||||||
while (angleDiff > PIfp) angleDiff -= static_cast<fp>(2.f) * PIfp;
|
while (angleDiff > PIfp) angleDiff -= static_cast<fp>(2.f) * PIfp;
|
||||||
while (angleDiff < -PIfp) angleDiff += static_cast<fp>(2.f) * PIfp;
|
while (angleDiff < -PIfp) angleDiff += static_cast<fp>(2.f) * PIfp;
|
||||||
const fp rotationStep = rotationSpeed * static_cast<fp>(deltaMs) / static_cast<fp>(1000.f);
|
const fp rotationStep = rotationSpeed * static_cast<fp>(deltaMs) / static_cast<fp>(1000.f);
|
||||||
@@ -435,13 +389,13 @@ CharacterUpdateEvents CharacterState::update(
|
|||||||
facingAngle += angleDiff > static_cast<fp>(0.f) ? rotationStep : -rotationStep;
|
facingAngle += angleDiff > static_cast<fp>(0.f) ? rotationStep : -rotationStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPlayer && hp > 0.f && battle_state == 0 && maxHomeDriftSquared > static_cast<fp>(0.f)) {
|
if (!isPlayer && hp > 0.f && battle_state == 0) {
|
||||||
homeDriftCheckTimer -= static_cast<fp>(deltaMs) / static_cast<fp>(1000.f);
|
homeDriftCheckTimer -= static_cast<fp>(deltaMs) / static_cast<fp>(1000.f);
|
||||||
if (homeDriftCheckTimer <= static_cast <fp>(0.f)) {
|
if (homeDriftCheckTimer <= static_cast <fp>(0.f)) {
|
||||||
homeDriftCheckTimer = HOME_DRIFT_CHECK_INTERVAL_FP;
|
homeDriftCheckTimer = HOME_DRIFT_CHECK_INTERVAL_FP;
|
||||||
Vec3fp toHome = homePosition - position;
|
Vec3fp toHome = homePosition - position;
|
||||||
toHome.y = static_cast<fp>(0.f);
|
toHome.y = static_cast<fp>(0.f);
|
||||||
if (!isMoving() && toHome.normSquared() > maxHomeDriftSquared) {
|
if (!isMoving() && toHome.normSquared() > MAX_HOME_DRIFT_SQUARED) {
|
||||||
events.navigationRequested = true;
|
events.navigationRequested = true;
|
||||||
events.navigationTarget = homePosition;
|
events.navigationTarget = homePosition;
|
||||||
}
|
}
|
||||||
@@ -538,9 +492,7 @@ void CharacterState::save(nlohmann::json& out) const
|
|||||||
out["currentWaypointIndex"] = currentWaypointIndex;
|
out["currentWaypointIndex"] = currentWaypointIndex;
|
||||||
out["navigationOutcome"] = static_cast<int>(navigationOutcome);
|
out["navigationOutcome"] = static_cast<int>(navigationOutcome);
|
||||||
out["homeDriftCheckTimer"] = static_cast<double>(homeDriftCheckTimer);
|
out["homeDriftCheckTimer"] = static_cast<double>(homeDriftCheckTimer);
|
||||||
out["movementBlockedTicks"] = movementBlockedTicks;
|
|
||||||
out["navigationRetryTicks"] = navigationRetryTicks;
|
out["navigationRetryTicks"] = navigationRetryTicks;
|
||||||
out["movedLastTick"] = movedLastTick;
|
|
||||||
out["velocity"] = {
|
out["velocity"] = {
|
||||||
velocity.x.raw_value(),
|
velocity.x.raw_value(),
|
||||||
velocity.y.raw_value()
|
velocity.y.raw_value()
|
||||||
@@ -556,12 +508,6 @@ void CharacterState::save(nlohmann::json& out) const
|
|||||||
|
|
||||||
void CharacterState::load(const nlohmann::json& in)
|
void CharacterState::load(const nlohmann::json& in)
|
||||||
{
|
{
|
||||||
auto readVec3 = [](const nlohmann::json& j, Eigen::Vector3f def) -> Eigen::Vector3f {
|
|
||||||
if (j.is_array() && j.size() == 3)
|
|
||||||
return { j[0].get<float>(), j[1].get<float>(), j[2].get<float>() };
|
|
||||||
return def;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto readVec3fp = [](const nlohmann::json& j, Vec3fp def) -> Vec3fp {
|
auto readVec3fp = [](const nlohmann::json& j, Vec3fp def) -> Vec3fp {
|
||||||
if (j.is_array() && j.size() == 3)
|
if (j.is_array() && j.size() == 3)
|
||||||
return Vec3fp{ static_cast<fp>(j[0].get<double>()), static_cast<fp>(j[1].get<double>()), static_cast<fp>(j[2].get<double>()) };
|
return Vec3fp{ static_cast<fp>(j[0].get<double>()), static_cast<fp>(j[1].get<double>()), static_cast<fp>(j[2].get<double>()) };
|
||||||
@@ -597,9 +543,7 @@ void CharacterState::load(const nlohmann::json& in)
|
|||||||
navigationOutcome = static_cast<PathFinder::PathOutcome>(
|
navigationOutcome = static_cast<PathFinder::PathOutcome>(
|
||||||
in.value("navigationOutcome", static_cast<int>(navigationOutcome)));
|
in.value("navigationOutcome", static_cast<int>(navigationOutcome)));
|
||||||
homeDriftCheckTimer = static_cast<fp>(in.value("homeDriftCheckTimer", static_cast<double>(homeDriftCheckTimer)));
|
homeDriftCheckTimer = static_cast<fp>(in.value("homeDriftCheckTimer", static_cast<double>(homeDriftCheckTimer)));
|
||||||
movementBlockedTicks = in.value("movementBlockedTicks", movementBlockedTicks);
|
|
||||||
navigationRetryTicks = in.value("navigationRetryTicks", navigationRetryTicks);
|
navigationRetryTicks = in.value("navigationRetryTicks", navigationRetryTicks);
|
||||||
movedLastTick = in.value("movedLastTick", movedLastTick);
|
|
||||||
const auto& velocityValue = in.at("velocity");
|
const auto& velocityValue = in.at("velocity");
|
||||||
if (!velocityValue.is_array() || velocityValue.size() != 2 ||
|
if (!velocityValue.is_array() || velocityValue.size() != 2 ||
|
||||||
!velocityValue[0].is_number_integer() ||
|
!velocityValue[0].is_number_integer() ||
|
||||||
|
|||||||
+11
-21
@@ -14,7 +14,12 @@
|
|||||||
namespace FRG {
|
namespace FRG {
|
||||||
|
|
||||||
constexpr float VISIBLE_RANGE = 6.f;
|
constexpr float VISIBLE_RANGE = 6.f;
|
||||||
|
// Distance at which a character starts attacking its target.
|
||||||
|
constexpr float kAttackRange = 1.25f;
|
||||||
|
// How close the player must be to a peaceful NPC to start a conversation.
|
||||||
|
constexpr float kNpcTalkDistance = 1.35f;
|
||||||
|
|
||||||
|
struct CharacterObservation;
|
||||||
struct CharacterUpdateContext;
|
struct CharacterUpdateContext;
|
||||||
struct CharacterUpdateEvents;
|
struct CharacterUpdateEvents;
|
||||||
struct LocationNetworkState;
|
struct LocationNetworkState;
|
||||||
@@ -42,16 +47,6 @@ struct CharacterCreationInfo {
|
|||||||
std::unordered_map<std::string, std::string> meshTexturePaths;
|
std::unordered_map<std::string, std::string> meshTexturePaths;
|
||||||
// Single shared texture path (used when setTexture(shared_ptr) was called on all meshes).
|
// Single shared texture path (used when setTexture(shared_ptr) was called on all meshes).
|
||||||
std::string singleTexturePath;
|
std::string singleTexturePath;
|
||||||
// Weapon asset paths and attachment setup
|
|
||||||
std::string weaponMeshPath;
|
|
||||||
std::string weaponTexturePath;
|
|
||||||
std::string weaponAttachBoneName = "RightHand";
|
|
||||||
Eigen::Vector3f weaponInitialPosition = Eigen::Vector3f::Zero();
|
|
||||||
// Weapon orientation stored as a quaternion (serializable as 4 floats).
|
|
||||||
Eigen::Quaternionf weaponInitialRotation = Eigen::Quaternionf::Identity();
|
|
||||||
// Optional mesh-space transformations applied after loading the weapon mesh.
|
|
||||||
Eigen::Vector3f weaponMeshMove = Eigen::Vector3f::Zero();
|
|
||||||
float weaponMeshScale = 1.0f;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// All serializable authoritative state for a character. GameState or
|
// All serializable authoritative state for a character. GameState or
|
||||||
@@ -99,7 +94,6 @@ public:
|
|||||||
|
|
||||||
// --- Home position for drift recovery ---
|
// --- Home position for drift recovery ---
|
||||||
Vec3fp homePosition;
|
Vec3fp homePosition;
|
||||||
fp maxHomeDriftSquared = static_cast<fp>(3.f*3.f);
|
|
||||||
|
|
||||||
// --- Authoritative logical animation clock ---
|
// --- Authoritative logical animation clock ---
|
||||||
// Frame counts are immutable metadata copied from loaded clips during
|
// Frame counts are immutable metadata copied from loaded clips during
|
||||||
@@ -117,7 +111,6 @@ public:
|
|||||||
|
|
||||||
float modelScale = 0.12f;
|
float modelScale = 0.12f;
|
||||||
Eigen::Quaternionf modelCorrectionRotation = Eigen::Quaternionf::Identity();
|
Eigen::Quaternionf modelCorrectionRotation = Eigen::Quaternionf::Identity();
|
||||||
bool useGpuSkinning = true;
|
|
||||||
|
|
||||||
//fp collisionRadius = static_cast<fp>(0.4f); // Радиус капсулы персонажа
|
//fp collisionRadius = static_cast<fp>(0.4f); // Радиус капсулы персонажа
|
||||||
fp collisionRadius = static_cast<fp>(kCharacterAgentRadius); // Радиус капсулы персонажа
|
fp collisionRadius = static_cast<fp>(kCharacterAgentRadius); // Радиус капсулы персонажа
|
||||||
@@ -128,7 +121,6 @@ public:
|
|||||||
Vec2fp preferredVelocity{ fp(0), fp(0) }; // Желаемая скорость к waypoint'у на текущем тике
|
Vec2fp preferredVelocity{ fp(0), fp(0) }; // Желаемая скорость к waypoint'у на текущем тике
|
||||||
|
|
||||||
fp interactionRadius = static_cast<fp>(0.0f);
|
fp interactionRadius = static_cast<fp>(0.0f);
|
||||||
bool movedLastTick = false;
|
|
||||||
|
|
||||||
// --- Pathfinding data (serializable parts) ---
|
// --- Pathfinding data (serializable parts) ---
|
||||||
Vec3fp walkTarget;
|
Vec3fp walkTarget;
|
||||||
@@ -140,7 +132,6 @@ public:
|
|||||||
|
|
||||||
// Internal drift-check timer (serializable so it survives save/load).
|
// Internal drift-check timer (serializable so it survives save/load).
|
||||||
fp homeDriftCheckTimer = static_cast<fp>(5.0f);
|
fp homeDriftCheckTimer = static_cast<fp>(5.0f);
|
||||||
int movementBlockedTicks = 0;
|
|
||||||
int navigationRetryTicks = 0;
|
int navigationRetryTicks = 0;
|
||||||
std::vector<int> navigationRetryCooldownTicks;
|
std::vector<int> navigationRetryCooldownTicks;
|
||||||
std::size_t navigationRetryCooldownIndex = 0;
|
std::size_t navigationRetryCooldownIndex = 0;
|
||||||
@@ -158,20 +149,16 @@ public:
|
|||||||
const std::string& entityId,
|
const std::string& entityId,
|
||||||
std::vector<int> cooldownTicks = {});
|
std::vector<int> cooldownTicks = {});
|
||||||
bool isMoving() const;
|
bool isMoving() const;
|
||||||
const Vec3fp& getRequestedWalkTarget() const { return requestedWalkTarget; }
|
|
||||||
PathFinder::PathOutcome getNavigationOutcome() const { return navigationOutcome; }
|
PathFinder::PathOutcome getNavigationOutcome() const { return navigationOutcome; }
|
||||||
Vec3fp getCurrentNavigationTarget() const;
|
Vec3fp getCurrentNavigationTarget() const;
|
||||||
void stopInPlace();
|
void stopInPlace();
|
||||||
void setTarget(const Vec3fp& target,
|
void setTarget(const Vec3fp& target,
|
||||||
std::string callbackName,
|
std::string callbackName,
|
||||||
const LocationNetworkState& location,
|
const LocationNetworkState& location);
|
||||||
const std::string& entityId);
|
void forceReplan(const LocationNetworkState& location);
|
||||||
void forceReplan(const LocationNetworkState& location,
|
|
||||||
const std::string& entityId);
|
|
||||||
void stopAndRotateToTarget(std::string characterId);
|
void stopAndRotateToTarget(std::string characterId);
|
||||||
void resetPlayerAfterDeath();
|
void resetPlayerAfterDeath();
|
||||||
void tryAttackCombo();
|
void tryAttackCombo();
|
||||||
float getHp() const { return hp; }
|
|
||||||
void setHp(float newHp);
|
void setHp(float newHp);
|
||||||
CharacterUpdateEvents update(std::int64_t deltaMs, const CharacterUpdateContext& context);
|
CharacterUpdateEvents update(std::int64_t deltaMs, const CharacterUpdateContext& context);
|
||||||
void setAnimationMetadata(AnimationState state, int startFrame, int frameCount);
|
void setAnimationMetadata(AnimationState state, int startFrame, int frameCount);
|
||||||
@@ -181,6 +168,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void scheduleNextNavigationRetry();
|
void scheduleNextNavigationRetry();
|
||||||
|
// Queries the active navigation map for a path to `target` and applies it.
|
||||||
|
void applyPathTo(const Vec3fp& target, const LocationNetworkState& location);
|
||||||
|
// Points targetFacingAngle at `faceTarget`, or clears a stale faceTargetId.
|
||||||
|
void updateFaceTarget(const CharacterObservation* faceTarget);
|
||||||
};
|
};
|
||||||
|
|
||||||
using PlayerStateMap =
|
using PlayerStateMap =
|
||||||
@@ -192,7 +183,6 @@ struct CharacterObservation {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CharacterUpdateContext {
|
struct CharacterUpdateContext {
|
||||||
std::string characterId;
|
|
||||||
const CharacterObservation* attackTarget = nullptr;
|
const CharacterObservation* attackTarget = nullptr;
|
||||||
const CharacterObservation* faceTarget = nullptr;
|
const CharacterObservation* faceTarget = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -763,16 +763,9 @@ namespace FRG
|
|||||||
std::shared_ptr<Location> Game::createLocation(const LocationConfig& config)
|
std::shared_ptr<Location> Game::createLocation(const LocationConfig& config)
|
||||||
{
|
{
|
||||||
LocationSetup params;
|
LocationSetup params;
|
||||||
params.gameObjectsJsonPath = config.gameObjectsJsonPath;
|
|
||||||
params.interactiveObjectsJsonPath = config.interactiveObjectsJsonPath;
|
|
||||||
params.npcsJsonPath = config.npcsJsonPath;
|
|
||||||
params.dialoguesJsonPath = config.dialoguesJsonPath;
|
params.dialoguesJsonPath = config.dialoguesJsonPath;
|
||||||
//params.navigationJsonPaths = config.navigationJsonPaths;
|
//params.navigationJsonPaths = config.navigationJsonPaths;
|
||||||
params.scriptPath = config.scriptPath;
|
params.scriptPath = config.scriptPath;
|
||||||
params.teleportsJsonPath = config.teleportsJsonPath;
|
|
||||||
params.triggerZonesJsonPath = config.triggerZonesJsonPath;
|
|
||||||
params.lightsJsonPath = config.lightsJsonPath;
|
|
||||||
params.playerPosition = config.playerPosition;
|
|
||||||
params.player = player;
|
params.player = player;
|
||||||
|
|
||||||
auto loc = std::make_shared<Location>(
|
auto loc = std::make_shared<Location>(
|
||||||
|
|||||||
+8
-30
@@ -4,6 +4,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace FRG {
|
namespace FRG {
|
||||||
|
|
||||||
@@ -14,16 +15,6 @@ bool GameState::completeTutorialStep(TutorialStep step)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterState* GameState::findCharacter(
|
|
||||||
const std::string& locationId, const std::string& characterId)
|
|
||||||
{
|
|
||||||
auto player = players.find(characterId);
|
|
||||||
if (player != players.end() && player->second) return player->second.get();
|
|
||||||
auto location = locations.find(locationId);
|
|
||||||
return location == locations.end()
|
|
||||||
? nullptr : location->second.findCharacter(characterId, players);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CharacterState* GameState::findCharacter(
|
const CharacterState* GameState::findCharacter(
|
||||||
const std::string& locationId, const std::string& characterId) const
|
const std::string& locationId, const std::string& characterId) const
|
||||||
{
|
{
|
||||||
@@ -34,6 +25,13 @@ const CharacterState* GameState::findCharacter(
|
|||||||
? nullptr : location->second.findCharacter(characterId, players);
|
? nullptr : location->second.findCharacter(characterId, players);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CharacterState* GameState::findCharacter(
|
||||||
|
const std::string& locationId, const std::string& characterId)
|
||||||
|
{
|
||||||
|
return const_cast<CharacterState*>(
|
||||||
|
std::as_const(*this).findCharacter(locationId, characterId));
|
||||||
|
}
|
||||||
|
|
||||||
void GameState::save(nlohmann::json& out) const
|
void GameState::save(nlohmann::json& out) const
|
||||||
{
|
{
|
||||||
out["schemaVersion"] = kSchemaVersion;
|
out["schemaVersion"] = kSchemaVersion;
|
||||||
@@ -52,8 +50,6 @@ void GameState::save(nlohmann::json& out) const
|
|||||||
out["isDawn"] = isDawn;
|
out["isDawn"] = isDawn;
|
||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
//out["playerHp"] = playerHp;
|
|
||||||
out["playerMaxHp"] = playerMaxHp;
|
|
||||||
out["money"] = money;
|
out["money"] = money;
|
||||||
|
|
||||||
// --- Script globals ---
|
// --- Script globals ---
|
||||||
@@ -124,7 +120,6 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"Unsupported game-state schema version: " +
|
"Unsupported game-state schema version: " +
|
||||||
std::to_string(schemaVersion));
|
std::to_string(schemaVersion));
|
||||||
//logger() << "GameState::load step 1" << std::endl;
|
|
||||||
|
|
||||||
// --- World ---
|
// --- World ---
|
||||||
campaignId = in.at("campaignId").get<std::string>();
|
campaignId = in.at("campaignId").get<std::string>();
|
||||||
@@ -133,23 +128,15 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
isNight = in.value("isNight", isNight);
|
isNight = in.value("isNight", isNight);
|
||||||
isDawn = in.value("isDawn", isDawn);
|
isDawn = in.value("isDawn", isDawn);
|
||||||
|
|
||||||
//() << "GameState::load step 2" << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
//playerHp = in.value("playerHp", playerHp);
|
|
||||||
playerMaxHp = in.value("playerMaxHp", playerMaxHp);
|
|
||||||
money = in.value("money", money);
|
money = in.value("money", money);
|
||||||
|
|
||||||
//logger() << "GameState::load step 3" << std::endl;
|
|
||||||
|
|
||||||
// --- Script globals ---
|
// --- Script globals ---
|
||||||
globalInts.clear();
|
globalInts.clear();
|
||||||
if (in.contains("globalInts") && in["globalInts"].is_object()) {
|
if (in.contains("globalInts") && in["globalInts"].is_object()) {
|
||||||
for (const auto& [k, v] : in["globalInts"].items())
|
for (const auto& [k, v] : in["globalInts"].items())
|
||||||
globalInts[k] = v.get<int>();
|
globalInts[k] = v.get<int>();
|
||||||
}
|
}
|
||||||
//logger() << "GameState::load step 4" << std::endl;
|
|
||||||
|
|
||||||
globalFloats.clear();
|
globalFloats.clear();
|
||||||
if (in.contains("globalFloats") && in["globalFloats"].is_object()) {
|
if (in.contains("globalFloats") && in["globalFloats"].is_object()) {
|
||||||
@@ -157,7 +144,6 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
globalFloats[k] = v.get<float>();
|
globalFloats[k] = v.get<float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//logger() << "GameState::load step 5" << std::endl;
|
|
||||||
|
|
||||||
// --- Tutorial ---
|
// --- Tutorial ---
|
||||||
tutorialStep = static_cast<TutorialStep>(
|
tutorialStep = static_cast<TutorialStep>(
|
||||||
@@ -167,20 +153,17 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
tutorialNeedOpenTaxiScreen = in.value("tutorialNeedOpenTaxiScreen", tutorialNeedOpenTaxiScreen);
|
tutorialNeedOpenTaxiScreen = in.value("tutorialNeedOpenTaxiScreen", tutorialNeedOpenTaxiScreen);
|
||||||
tutorialTaxiHintDone = in.value("tutorialTaxiHintDone", false);
|
tutorialTaxiHintDone = in.value("tutorialTaxiHintDone", false);
|
||||||
|
|
||||||
//logger() << "GameState::load step 6" << std::endl;
|
|
||||||
|
|
||||||
// --- Phone / chat ---
|
// --- Phone / chat ---
|
||||||
if (in.contains("chatUnread") && in["chatUnread"].is_array()) {
|
if (in.contains("chatUnread") && in["chatUnread"].is_array()) {
|
||||||
for (int i = 0; i < 3 && i < static_cast<int>(in["chatUnread"].size()); ++i)
|
for (int i = 0; i < 3 && i < static_cast<int>(in["chatUnread"].size()); ++i)
|
||||||
chatUnread[i] = in["chatUnread"][i].get<bool>();
|
chatUnread[i] = in["chatUnread"][i].get<bool>();
|
||||||
}
|
}
|
||||||
//logger() << "GameState::load step 7" << std::endl;
|
|
||||||
|
|
||||||
if (in.contains("chatPreviewMsg") && in["chatPreviewMsg"].is_array()) {
|
if (in.contains("chatPreviewMsg") && in["chatPreviewMsg"].is_array()) {
|
||||||
for (int i = 0; i < 3 && i < static_cast<int>(in["chatPreviewMsg"].size()); ++i)
|
for (int i = 0; i < 3 && i < static_cast<int>(in["chatPreviewMsg"].size()); ++i)
|
||||||
chatPreviewMsg[i] = in["chatPreviewMsg"][i].get<std::string>();
|
chatPreviewMsg[i] = in["chatPreviewMsg"][i].get<std::string>();
|
||||||
}
|
}
|
||||||
//logger() << "GameState::load step 8" << std::endl;
|
|
||||||
|
|
||||||
if (in.contains("chatHistory") && in["chatHistory"].is_array()) {
|
if (in.contains("chatHistory") && in["chatHistory"].is_array()) {
|
||||||
for (int i = 0; i < 3 && i < static_cast<int>(in["chatHistory"].size()); ++i) {
|
for (int i = 0; i < 3 && i < static_cast<int>(in["chatHistory"].size()); ++i) {
|
||||||
@@ -196,17 +179,14 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//logger() << "GameState::load step 8" << std::endl;
|
|
||||||
|
|
||||||
// --- Inventory ---
|
// --- Inventory ---
|
||||||
if (in.contains("inventory")) inventory.load(in["inventory"]);
|
if (in.contains("inventory")) inventory.load(in["inventory"]);
|
||||||
|
|
||||||
//logger() << "GameState::load step 9" << std::endl;
|
|
||||||
|
|
||||||
// --- Quest journal ---
|
// --- Quest journal ---
|
||||||
if (in.contains("questJournal")) questJournal.load(in["questJournal"]);
|
if (in.contains("questJournal")) questJournal.load(in["questJournal"]);
|
||||||
|
|
||||||
logger() << "GameState::load step 10" << std::endl;
|
|
||||||
|
|
||||||
// --- Players ---
|
// --- Players ---
|
||||||
const auto& playerValues = in.at("players");
|
const auto& playerValues = in.at("players");
|
||||||
@@ -238,12 +218,10 @@ void GameState::load(const nlohmann::json& in)
|
|||||||
if (!locationValues.contains(it->first)) it = locations.erase(it);
|
if (!locationValues.contains(it->first)) it = locations.erase(it);
|
||||||
else ++it;
|
else ++it;
|
||||||
}
|
}
|
||||||
//logger() << "GameState::load step 11" << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
// --- Taxi ---
|
// --- Taxi ---
|
||||||
taxiIsCalled = in.value("taxiIsCalled", taxiIsCalled);
|
taxiIsCalled = in.value("taxiIsCalled", taxiIsCalled);
|
||||||
//logger() << "GameState::load step 12" << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -33,7 +33,7 @@ struct StoredChatMessage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GameState : public ISaveable {
|
struct GameState : public ISaveable {
|
||||||
static constexpr int kSchemaVersion = 6;
|
static constexpr int kSchemaVersion = 7;
|
||||||
|
|
||||||
// --- World ---
|
// --- World ---
|
||||||
// Campaign being played (see CampaignRegistry).
|
// Campaign being played (see CampaignRegistry).
|
||||||
@@ -50,8 +50,6 @@ struct GameState : public ISaveable {
|
|||||||
|
|
||||||
// --- Player resources ---
|
// --- Player resources ---
|
||||||
Inventory inventory;
|
Inventory inventory;
|
||||||
//float playerHp = 200.f;
|
|
||||||
float playerMaxHp = 200.f;
|
|
||||||
int money = 5500;
|
int money = 5500;
|
||||||
|
|
||||||
// --- Script globals ---
|
// --- Script globals ---
|
||||||
|
|||||||
+39
-304
@@ -11,9 +11,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <unordered_set>
|
|
||||||
#include "GameConstants.h"
|
#include "GameConstants.h"
|
||||||
#include "Character.h"
|
#include "Character.h"
|
||||||
#include "game_server/IGameServer.h"
|
#include "game_server/IGameServer.h"
|
||||||
@@ -24,35 +22,10 @@ namespace FRG
|
|||||||
{
|
{
|
||||||
extern const char* CONST_ZIP_FILE;
|
extern const char* CONST_ZIP_FILE;
|
||||||
|
|
||||||
extern float x;
|
|
||||||
|
|
||||||
constexpr float CONST_TAXI_CAR_SCALE = 0.6f;
|
constexpr float CONST_TAXI_CAR_SCALE = 0.6f;
|
||||||
|
|
||||||
|
|
||||||
static constexpr float CAMERA_FOV_Y = 1.0f / 1.5f;
|
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.35f;
|
|
||||||
|
|
||||||
static constexpr float RENDER_DISTRANCE = 50.f;
|
|
||||||
|
|
||||||
static float distancePointToSegmentXZ(const Eigen::Vector3f& p,
|
|
||||||
const Eigen::Vector3f& a,
|
|
||||||
const Eigen::Vector3f& b)
|
|
||||||
{
|
|
||||||
const Eigen::Vector2f p2(p.x(), p.z());
|
|
||||||
const Eigen::Vector2f a2(a.x(), a.z());
|
|
||||||
const Eigen::Vector2f b2(b.x(), b.z());
|
|
||||||
const Eigen::Vector2f ab = b2 - a2;
|
|
||||||
const float abLenSq = ab.squaredNorm();
|
|
||||||
if (abLenSq <= 1e-8f) {
|
|
||||||
return (p2 - a2).norm();
|
|
||||||
}
|
|
||||||
const float t = std::clamp((p2 - a2).dot(ab) / abLenSq, 0.0f, 1.0f);
|
|
||||||
const Eigen::Vector2f closest = a2 + ab * t;
|
|
||||||
return (p2 - closest).norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
Location::Location(Renderer& iRenderer, IGameServer& server,
|
Location::Location(Renderer& iRenderer, IGameServer& server,
|
||||||
std::string locationId)
|
std::string locationId)
|
||||||
: renderer(iRenderer)
|
: renderer(iRenderer)
|
||||||
@@ -151,11 +124,6 @@ namespace FRG
|
|||||||
locationId_, character.entityId(), std::move(targetId)});
|
locationId_, character.entityId(), std::move(targetId)});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::replanCharacter(Character& character)
|
|
||||||
{
|
|
||||||
gameServer_.submit(ReplanCharacterCommand{locationId_, character.entityId()});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Location::resetCharacterAfterDeath(Character& character)
|
void Location::resetCharacterAfterDeath(Character& character)
|
||||||
{
|
{
|
||||||
gameServer_.submit(
|
gameServer_.submit(
|
||||||
@@ -589,188 +557,37 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::loadTeleportZones(const std::string& jsonPath, const char* zipFile)
|
void Location::prepareCharacterSparks(const Eigen::Matrix4f& cameraViewMatrix)
|
||||||
{
|
{
|
||||||
if (jsonPath.empty()) return;
|
if (player) player->prepareHitSparksForDraw(cameraViewMatrix);
|
||||||
|
for (auto& [id, remote] : remotePlayers_)
|
||||||
std::string content;
|
if (remote) remote->prepareHitSparksForDraw(cameraViewMatrix);
|
||||||
try {
|
for (auto& npc : npcs) npc->prepareHitSparksForDraw(cameraViewMatrix);
|
||||||
if (!zipFile || zipFile[0] == '\0') {
|
|
||||||
content = readTextFile(jsonPath);
|
|
||||||
} else {
|
|
||||||
auto buf = readFileFromZIP(jsonPath, zipFile);
|
|
||||||
if (buf.empty()) {
|
|
||||||
std::cerr << "[TELEPORT] Failed to read " << jsonPath << " from zip" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content.assign(buf.begin(), buf.end());
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[TELEPORT] Failed to open " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
json j;
|
|
||||||
try {
|
|
||||||
j = json::parse(content);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[TELEPORT] JSON parse error in " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!j.contains("teleports") || !j["teleports"].is_array()) return;
|
|
||||||
|
|
||||||
auto activeTex = renderer.textureManager.LoadFromPng("resources/w/star.png", zipFile ? zipFile : "");
|
|
||||||
auto inactiveTex = renderer.textureManager.LoadFromPng("resources/w/star_red.png", zipFile ? zipFile : "");
|
|
||||||
|
|
||||||
std::unordered_set<std::string> ids;
|
|
||||||
for (const auto& item : j["teleports"]) {
|
|
||||||
TeleportZone tz;
|
|
||||||
tz.id = item.at("id").get<std::string>();
|
|
||||||
if (tz.id.empty() || !ids.insert(tz.id).second)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Missing or duplicate teleport id in " + jsonPath);
|
|
||||||
tz.active = item.value("active", false);
|
|
||||||
tz.position = Eigen::Vector3f(
|
|
||||||
item.value("positionX", 0.0f),
|
|
||||||
item.value("positionY", 0.0f),
|
|
||||||
item.value("positionZ", 0.0f)
|
|
||||||
);
|
|
||||||
tz.radius = item.value("radius", 0.0f);
|
|
||||||
tz.automatic = item.value("automatic", false);
|
|
||||||
tz.automaticRadius = item.value("automaticRadius", tz.radius);
|
|
||||||
tz.destinationLocation = item.value("destinationLocation", "");
|
|
||||||
tz.destinationPosition = Eigen::Vector3f(
|
|
||||||
item.value("destinationPositionX", 0.0f),
|
|
||||||
item.value("destinationPositionY", 0.0f),
|
|
||||||
item.value("destinationPositionZ", 0.0f)
|
|
||||||
);
|
|
||||||
tz.destinationRotationY = item.value("destinationRotationY", 0.0f);
|
|
||||||
tz.initSparks(activeTex, inactiveTex);
|
|
||||||
teleportZones.push_back(std::move(tz));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger() << "[TELEPORT] Loaded " << teleportZones.size() << " teleport(s) from " << jsonPath << std::endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::loadTriggerZones(const std::string& jsonPath, const char* zipFile)
|
void Location::drawCharacters()
|
||||||
{
|
{
|
||||||
if (jsonPath.empty()) return;
|
if (player) player->draw(renderer);
|
||||||
|
for (auto& [id, remote] : remotePlayers_)
|
||||||
std::string content;
|
if (remote) remote->draw(renderer);
|
||||||
try {
|
for (auto& npc : npcs) npc->draw(renderer);
|
||||||
if (!zipFile || zipFile[0] == '\0') {
|
|
||||||
content = readTextFile(jsonPath);
|
|
||||||
} else {
|
|
||||||
auto buf = readFileFromZIP(jsonPath, zipFile);
|
|
||||||
if (buf.empty()) {
|
|
||||||
std::cerr << "[TRIGGER] Failed to read " << jsonPath << " from zip" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content.assign(buf.begin(), buf.end());
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[TRIGGER] Failed to open " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
json j;
|
|
||||||
try {
|
|
||||||
j = json::parse(content);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[TRIGGER] JSON parse error in " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!j.contains("trigger_zones") || !j["trigger_zones"].is_array()) return;
|
|
||||||
|
|
||||||
std::unordered_set<std::string> ids;
|
|
||||||
for (const auto& item : j["trigger_zones"]) {
|
|
||||||
TriggerZone tz;
|
|
||||||
tz.id = item.at("id").get<std::string>();
|
|
||||||
if (tz.id.empty() || !ids.insert(tz.id).second)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Missing or duplicate trigger-zone id in " + jsonPath);
|
|
||||||
tz.enabled = item.value("enabled", true);
|
|
||||||
tz.radius = item.value("radius", 1.5f);
|
|
||||||
tz.hysteresis = item.value("hysteresis", 0.3f);
|
|
||||||
tz.position = Eigen::Vector3f(
|
|
||||||
item.value("positionX", 0.0f),
|
|
||||||
item.value("positionY", 0.0f),
|
|
||||||
item.value("positionZ", 0.0f)
|
|
||||||
);
|
|
||||||
triggerZones.push_back(std::move(tz));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
logger() << "[TRIGGER] Loaded " << triggerZones.size() << " trigger zone(s) from " << jsonPath << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::loadPointLights(const std::string& jsonPath, const char* zipFile)
|
void Location::drawCharacterOverlays(const Eigen::Matrix4f& cameraViewMatrix)
|
||||||
{
|
{
|
||||||
if (jsonPath.empty()) return;
|
if (!npcNameText) return;
|
||||||
|
const Eigen::Matrix4f proj = MakePerspectiveMatrix(1.0f / 1.5f,
|
||||||
std::string content;
|
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||||
try {
|
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||||
if (!zipFile || zipFile[0] == '\0') {
|
drawRemotePlayerNames(cameraViewMatrix, proj);
|
||||||
content = readTextFile(jsonPath);
|
for (auto& npc : npcs) {
|
||||||
} else {
|
if (npc) npc->drawName(*npcNameText, cameraViewMatrix, proj);
|
||||||
auto buf = readFileFromZIP(jsonPath, zipFile);
|
|
||||||
if (buf.empty()) {
|
|
||||||
std::cerr << "[LIGHTS] Failed to read " << jsonPath << " from zip" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
content.assign(buf.begin(), buf.end());
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[LIGHTS] Failed to open " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (player) player->drawHealthBar(renderer, cameraViewMatrix, proj);
|
||||||
using json = nlohmann::json;
|
for (auto& npc : npcs) {
|
||||||
json j;
|
if (npc) npc->drawHealthBar(renderer, cameraViewMatrix, proj);
|
||||||
try {
|
|
||||||
j = json::parse(content);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
std::cerr << "[LIGHTS] JSON parse error in " << jsonPath << ": " << e.what() << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!j.contains("lights") || !j["lights"].is_array()) return;
|
|
||||||
|
|
||||||
for (const auto& item : j["lights"]) {
|
|
||||||
PointLight pl;
|
|
||||||
pl.id = item.value("id", "");
|
|
||||||
pl.autoLight = item.value("autoLight", false);
|
|
||||||
pl.autoLightDistance = item.value("autoLightDistance", -1.0f);
|
|
||||||
pl.limitX = item.value("limitX", 99999.f);
|
|
||||||
pl.limitY = item.value("limitY", 99999.f);
|
|
||||||
pl.autoLightLimitX = item.value("autoLightLimitX", -1.0f);
|
|
||||||
pl.autoLightLimitY = item.value("autoLightLimitY", -1.0f);
|
|
||||||
pl.position = Eigen::Vector3f(
|
|
||||||
item.value("positionX", 0.0f),
|
|
||||||
item.value("positionY", 0.0f),
|
|
||||||
item.value("positionZ", 0.0f)
|
|
||||||
);
|
|
||||||
pl.direction = Eigen::Vector3f(
|
|
||||||
item.value("directionX", 0.0f),
|
|
||||||
item.value("directionY", -1.0f),
|
|
||||||
item.value("directionZ", 0.0f)
|
|
||||||
);
|
|
||||||
pl.color = Eigen::Vector3f(
|
|
||||||
item.value("colorR", 1.0f),
|
|
||||||
item.value("colorG", 1.0f),
|
|
||||||
item.value("colorB", 1.0f)
|
|
||||||
);
|
|
||||||
pointLights.push_back(std::move(pl));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger() << "[LIGHTS] Loaded " << pointLights.size() << " light(s) from " << jsonPath << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::updateTriggerZones(const Eigen::Vector3f& playerPos)
|
void Location::updateTriggerZones(const Eigen::Vector3f& playerPos)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < static_cast<int>(triggerZones.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(triggerZones.size()); ++i) {
|
||||||
@@ -1019,11 +836,6 @@ namespace FRG
|
|||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::setPathVisualizationEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
pathVisualization.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Location::drawGame()
|
void Location::drawGame()
|
||||||
{
|
{
|
||||||
auto locationState = stateSnapshot();
|
auto locationState = stateSnapshot();
|
||||||
@@ -1076,16 +888,10 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
||||||
if (player) player->prepareHitSparksForDraw(currentView);
|
prepareCharacterSparks(currentView);
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->prepareHitSparksForDraw(currentView);
|
|
||||||
for (auto& npc : npcs) npc->prepareHitSparksForDraw(currentView);
|
|
||||||
for (auto& tz : teleportZones) tz.prepareForDraw(currentView);
|
for (auto& tz : teleportZones) tz.prepareForDraw(currentView);
|
||||||
|
|
||||||
if (player) player->draw(renderer);
|
drawCharacters();
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->draw(renderer);
|
|
||||||
for (auto& npc : npcs) npc->draw(renderer);
|
|
||||||
|
|
||||||
drawNpcCar();
|
drawNpcCar();
|
||||||
|
|
||||||
@@ -1106,19 +912,7 @@ namespace FRG
|
|||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
if (npcNameText) {
|
drawCharacterOverlays(currentView);
|
||||||
Eigen::Matrix4f proj = MakePerspectiveMatrix(1.0f / 1.5f,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
drawRemotePlayerNames(currentView, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawName(*npcNameText, currentView, proj);
|
|
||||||
}
|
|
||||||
if (player) player->drawHealthBar(renderer, currentView, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawHealthBar(renderer, currentView, proj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::drawShadowDepthPass()
|
void Location::drawShadowDepthPass()
|
||||||
@@ -1202,6 +996,7 @@ namespace FRG
|
|||||||
glClearColor(0.53, 0.81, 0.92, 1.0f);
|
glClearColor(0.53, 0.81, 0.92, 1.0f);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
Eigen::Matrix4f cameraViewMatrix = Eigen::Matrix4f::Identity();
|
||||||
#ifdef DEBUG_LIGHT
|
#ifdef DEBUG_LIGHT
|
||||||
// Debug mode: render from the light's point of view using the plain
|
// Debug mode: render from the light's point of view using the plain
|
||||||
// textured shader so we can see what the shadow map "sees".
|
// textured shader so we can see what the shadow map "sees".
|
||||||
@@ -1293,24 +1088,15 @@ namespace FRG
|
|||||||
// but from the light's viewpoint — projection/view already on stack).
|
// but from the light's viewpoint — projection/view already on stack).
|
||||||
{
|
{
|
||||||
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
||||||
if (player) player->prepareHitSparksForDraw(currentView);
|
prepareCharacterSparks(currentView);
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->prepareHitSparksForDraw(currentView);
|
|
||||||
for (auto& npc : npcs) npc->prepareHitSparksForDraw(currentView);
|
|
||||||
}
|
}
|
||||||
if (player) player->draw(renderer);
|
drawCharacters();
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->draw(renderer);
|
|
||||||
for (auto& npc : npcs) npc->draw(renderer);
|
|
||||||
drawNpcCar();
|
drawNpcCar();
|
||||||
#else
|
#else
|
||||||
// Characters use their own shadow-aware shaders
|
// Characters use their own shadow-aware shaders
|
||||||
CheckGlError(__FILE__, __LINE__);
|
CheckGlError(__FILE__, __LINE__);
|
||||||
|
|
||||||
if (player) player->prepareHitSparksForDraw(cameraViewMatrix);
|
prepareCharacterSparks(cameraViewMatrix);
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->prepareHitSparksForDraw(cameraViewMatrix);
|
|
||||||
for (auto& npc : npcs) npc->prepareHitSparksForDraw(cameraViewMatrix);
|
|
||||||
for (auto& tz : teleportZones) tz.prepareForDraw(cameraViewMatrix);
|
for (auto& tz : teleportZones) tz.prepareForDraw(cameraViewMatrix);
|
||||||
|
|
||||||
if (player) player->drawWithShadow(renderer, lightFromCamera, shadowMap->getDepthTexture(), lightDirCamera);
|
if (player) player->drawWithShadow(renderer, lightFromCamera, shadowMap->getDepthTexture(), lightDirCamera);
|
||||||
@@ -1341,19 +1127,7 @@ namespace FRG
|
|||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
if (npcNameText) {
|
drawCharacterOverlays(cameraViewMatrix);
|
||||||
Eigen::Matrix4f proj = MakePerspectiveMatrix(1.0f / 1.5f,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
drawRemotePlayerNames(cameraViewMatrix, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawName(*npcNameText, cameraViewMatrix, proj);
|
|
||||||
}
|
|
||||||
if (player) player->drawHealthBar(renderer, cameraViewMatrix, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawHealthBar(renderer, cameraViewMatrix, proj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::drawGameDarklands()
|
void Location::drawGameDarklands()
|
||||||
@@ -1403,16 +1177,10 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
const Eigen::Matrix4f currentView = renderer.GetCurrentModelViewMatrix();
|
||||||
if (player) player->prepareHitSparksForDraw(currentView);
|
prepareCharacterSparks(currentView);
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->prepareHitSparksForDraw(currentView);
|
|
||||||
for (auto& npc : npcs) npc->prepareHitSparksForDraw(currentView);
|
|
||||||
for (auto& tz : teleportZones) tz.prepareForDraw(currentView);
|
for (auto& tz : teleportZones) tz.prepareForDraw(currentView);
|
||||||
|
|
||||||
if (player) player->draw(renderer);
|
drawCharacters();
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->draw(renderer);
|
|
||||||
for (auto& npc : npcs) npc->draw(renderer);
|
|
||||||
|
|
||||||
//drawNpcCar();
|
//drawNpcCar();
|
||||||
|
|
||||||
@@ -1431,19 +1199,7 @@ namespace FRG
|
|||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
if (npcNameText) {
|
drawCharacterOverlays(currentView);
|
||||||
Eigen::Matrix4f proj = MakePerspectiveMatrix(1.0f / 1.5f,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
drawRemotePlayerNames(currentView, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawName(*npcNameText, currentView, proj);
|
|
||||||
}
|
|
||||||
if (player) player->drawHealthBar(renderer, currentView, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawHealthBar(renderer, currentView, proj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::drawNightShadowDepthPass(const PointLight& light)
|
void Location::drawNightShadowDepthPass(const PointLight& light)
|
||||||
@@ -1551,7 +1307,7 @@ namespace FRG
|
|||||||
interpolatedNpcCarPresentation(locationState->taxiCar);
|
interpolatedNpcCarPresentation(locationState->taxiCar);
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
renderer.TranslateMatrix(car.position);
|
renderer.TranslateMatrix(car.position);
|
||||||
renderer.TranslateMatrix({ 0, 0.7f - 0.25f +x, 0 });
|
renderer.TranslateMatrix({ 0, 0.7f - 0.25f, 0 });
|
||||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(car.rotation, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(car.rotation, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||||
glBindTexture(GL_TEXTURE_2D, carTexture->getTexID());
|
glBindTexture(GL_TEXTURE_2D, carTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(carMesh);
|
renderer.DrawVertexRenderStruct(carMesh);
|
||||||
@@ -1687,7 +1443,7 @@ namespace FRG
|
|||||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||||
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
||||||
|
|
||||||
cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
|
const Eigen::Matrix4f cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
|
||||||
|
|
||||||
// Transform active spot lights to eye space and build uniform arrays
|
// Transform active spot lights to eye space and build uniform arrays
|
||||||
float plPosEye[MAX_POINT_LIGHTS * 3] = {};
|
float plPosEye[MAX_POINT_LIGHTS * 3] = {};
|
||||||
@@ -1772,10 +1528,7 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||||
if (player) player->prepareHitSparksForDraw(cameraViewMatrix);
|
prepareCharacterSparks(cameraViewMatrix);
|
||||||
for (auto& [id, remote] : remotePlayers_)
|
|
||||||
if (remote) remote->prepareHitSparksForDraw(cameraViewMatrix);
|
|
||||||
for (auto& npc : npcs) npc->prepareHitSparksForDraw(cameraViewMatrix);
|
|
||||||
for (auto& tz : teleportZones) tz.prepareForDraw(cameraViewMatrix);
|
for (auto& tz : teleportZones) tz.prepareForDraw(cameraViewMatrix);
|
||||||
|
|
||||||
if (hasShadows) {
|
if (hasShadows) {
|
||||||
@@ -1818,19 +1571,7 @@ namespace FRG
|
|||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
if (npcNameText) {
|
drawCharacterOverlays(cameraViewMatrix);
|
||||||
Eigen::Matrix4f proj = MakePerspectiveMatrix(1.0f / 1.5f,
|
|
||||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
|
||||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
|
||||||
drawRemotePlayerNames(cameraViewMatrix, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawName(*npcNameText, cameraViewMatrix, proj);
|
|
||||||
}
|
|
||||||
if (player) player->drawHealthBar(renderer, cameraViewMatrix, proj);
|
|
||||||
for (auto& npc : npcs) {
|
|
||||||
if (npc) npc->drawHealthBar(renderer, cameraViewMatrix, proj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Location::setNavigationAreaAvailable(const std::string& areaName, bool available)
|
bool Location::setNavigationAreaAvailable(const std::string& areaName, bool available)
|
||||||
@@ -1896,7 +1637,6 @@ namespace FRG
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (const CharacterSimulationEvent& event : events.characters) {
|
for (const CharacterSimulationEvent& event : events.characters) {
|
||||||
Character* character = findRuntimeCharacter(event.characterId);
|
|
||||||
if (!event.events.arrivedCallbackName.empty()) {
|
if (!event.events.arrivedCallbackName.empty()) {
|
||||||
try {
|
try {
|
||||||
scriptEngine.callFunction(event.events.arrivedCallbackName);
|
scriptEngine.callFunction(event.events.arrivedCallbackName);
|
||||||
@@ -2124,7 +1864,7 @@ namespace FRG
|
|||||||
gameServer_.submit(SetLocationTargetsCommand{
|
gameServer_.submit(SetLocationTargetsCommand{
|
||||||
locationId_, std::string(), std::string(), std::string()});
|
locationId_, std::string(), std::string(), std::string()});
|
||||||
|
|
||||||
if (distance >= Character::kAttackRange) {
|
if (distance >= kAttackRange) {
|
||||||
setCharacterTarget(*player, clickedNpcState->position);
|
setCharacterTarget(*player, clickedNpcState->position);
|
||||||
pathVisualization.start(
|
pathVisualization.start(
|
||||||
*player,
|
*player,
|
||||||
@@ -2146,7 +1886,7 @@ namespace FRG
|
|||||||
// Peaceful NPC: walk to them, fire on_npc_interact when within talk distance.
|
// Peaceful NPC: walk to them, fire on_npc_interact when within talk distance.
|
||||||
clearCharacterAttackTarget(*player);
|
clearCharacterAttackTarget(*player);
|
||||||
|
|
||||||
if (distance <= NPC_TALK_DISTANCE) {
|
if (distance <= kNpcTalkDistance) {
|
||||||
// Already in talk range — fire immediately, stop, and face the player.
|
// Already in talk range — fire immediately, stop, and face the player.
|
||||||
//logger() << "[CLICK] *** SUCCESS: Clicked on NPC index: " << npcIndex << " (in range) ***" << std::endl;
|
//logger() << "[CLICK] *** SUCCESS: Clicked on NPC index: " << npcIndex << " (in range) ***" << std::endl;
|
||||||
setCharacterTarget(*player, playerState->position);
|
setCharacterTarget(*player, playerState->position);
|
||||||
@@ -2159,7 +1899,7 @@ namespace FRG
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//logger() << "[CLICK] NPC " << npcIndex << " out of talk range (distance " << distance
|
//logger() << "[CLICK] NPC " << npcIndex << " out of talk range (distance " << distance
|
||||||
// << " > " << NPC_TALK_DISTANCE << "); walking to NPC..." << std::endl;
|
// << " > " << kNpcTalkDistance << "); walking to NPC..." << std::endl;
|
||||||
setCharacterTarget(*player, clickedNpcState->position);
|
setCharacterTarget(*player, clickedNpcState->position);
|
||||||
pathVisualization.start(
|
pathVisualization.start(
|
||||||
*player, clickedNpcState->position.toEigen(),
|
*player, clickedNpcState->position.toEigen(),
|
||||||
@@ -2267,11 +2007,6 @@ namespace FRG
|
|||||||
return dialogueSystem.startCutscene(cutsceneId);
|
return dialogueSystem.startCutscene(cutsceneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Location::setOnCutsceneFinished(std::function<void(const std::string&)> cb)
|
|
||||||
{
|
|
||||||
dialogueSystem.setOnCutsceneFinished(std::move(cb));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Location::setDialogueFlag(const std::string& flag, int value)
|
void Location::setDialogueFlag(const std::string& flag, int value)
|
||||||
{
|
{
|
||||||
dialogueSystem.setFlag(flag, value);
|
dialogueSystem.setFlag(flag, value);
|
||||||
|
|||||||
+5
-17
@@ -55,16 +55,9 @@ namespace FRG
|
|||||||
struct LocationSetup
|
struct LocationSetup
|
||||||
{
|
{
|
||||||
std::shared_ptr<const LocationDefinition> definition;
|
std::shared_ptr<const LocationDefinition> definition;
|
||||||
std::string gameObjectsJsonPath;
|
|
||||||
std::string interactiveObjectsJsonPath;
|
|
||||||
std::string npcsJsonPath;
|
|
||||||
std::string dialoguesJsonPath;
|
std::string dialoguesJsonPath;
|
||||||
//std::vector<std::string> navigationJsonPaths;
|
//std::vector<std::string> navigationJsonPaths;
|
||||||
std::string scriptPath;
|
std::string scriptPath;
|
||||||
std::string teleportsJsonPath;
|
|
||||||
std::string triggerZonesJsonPath;
|
|
||||||
std::string lightsJsonPath;
|
|
||||||
Vec3fp playerPosition;
|
|
||||||
// Player shared by all locations of a campaign (see Location::createPlayer);
|
// Player shared by all locations of a campaign (see Location::createPlayer);
|
||||||
// setup() creates a private one when this is null.
|
// setup() creates a private one when this is null.
|
||||||
std::shared_ptr<Character> player;
|
std::shared_ptr<Character> player;
|
||||||
@@ -108,7 +101,6 @@ namespace FRG
|
|||||||
IGameServer& server, const std::string& playerId);
|
IGameServer& server, const std::string& playerId);
|
||||||
|
|
||||||
std::shared_ptr<ShadowMap> shadowMap;
|
std::shared_ptr<ShadowMap> shadowMap;
|
||||||
Eigen::Matrix4f cameraViewMatrix = Eigen::Matrix4f::Identity();
|
|
||||||
|
|
||||||
std::unique_ptr<TextRenderer> npcNameText;
|
std::unique_ptr<TextRenderer> npcNameText;
|
||||||
|
|
||||||
@@ -179,7 +171,6 @@ namespace FRG
|
|||||||
void clearCharacterAttackTarget(Character& character);
|
void clearCharacterAttackTarget(Character& character);
|
||||||
void stopCharacter(Character& character);
|
void stopCharacter(Character& character);
|
||||||
void faceCharacter(Character& character, std::string targetId);
|
void faceCharacter(Character& character, std::string targetId);
|
||||||
void replanCharacter(Character& character);
|
|
||||||
void resetCharacterAfterDeath(Character& character);
|
void resetCharacterAfterDeath(Character& character);
|
||||||
void tryCharacterAttackCombo(Character& character);
|
void tryCharacterAttackCombo(Character& character);
|
||||||
void setCharacterHp(Character& character, float hp);
|
void setCharacterHp(Character& character, float hp);
|
||||||
@@ -211,10 +202,6 @@ namespace FRG
|
|||||||
|
|
||||||
void update(int64_t deltaMs, const LocationSimulationEvents& events);
|
void update(int64_t deltaMs, const LocationSimulationEvents& events);
|
||||||
void updatePresentation(int64_t deltaMs);
|
void updatePresentation(int64_t deltaMs);
|
||||||
// Purely visual feedback for click-triggered player routes. Disabling it
|
|
||||||
// also cancels an animation that is currently playing.
|
|
||||||
void setPathVisualizationEnabled(bool enabled);
|
|
||||||
bool isPathVisualizationEnabled() const { return pathVisualization.isEnabled(); }
|
|
||||||
|
|
||||||
void handleDown(int64_t fingerId, int eventX, int eventY, int mx, int my);
|
void handleDown(int64_t fingerId, int eventX, int eventY, int mx, int my);
|
||||||
void handleUp(int64_t fingerId, int mx, int my);
|
void handleUp(int64_t fingerId, int mx, int my);
|
||||||
@@ -222,7 +209,6 @@ namespace FRG
|
|||||||
|
|
||||||
bool requestDialogueStart(const std::string& dialogueId);
|
bool requestDialogueStart(const std::string& dialogueId);
|
||||||
bool requestCutsceneStart(const std::string& cutsceneId);
|
bool requestCutsceneStart(const std::string& cutsceneId);
|
||||||
void setOnCutsceneFinished(std::function<void(const std::string&)> cb);
|
|
||||||
void setDialogueFlag(const std::string& flag, int value);
|
void setDialogueFlag(const std::string& flag, int value);
|
||||||
int getDialogueFlag(const std::string& flag) const;
|
int getDialogueFlag(const std::string& flag) const;
|
||||||
|
|
||||||
@@ -255,9 +241,11 @@ namespace FRG
|
|||||||
void drawInstancedStatics(const std::string& instancedShaderName, InstancedTexture textureKind,
|
void drawInstancedStatics(const std::string& instancedShaderName, InstancedTexture textureKind,
|
||||||
const std::function<void()>& setUniforms = {});
|
const std::function<void()>& setUniforms = {});
|
||||||
|
|
||||||
void loadTeleportZones(const std::string& jsonPath, const char* zipFile);
|
// Per-frame character passes shared by every drawGame* variant.
|
||||||
void loadTriggerZones(const std::string& jsonPath, const char* zipFile);
|
void prepareCharacterSparks(const Eigen::Matrix4f& cameraViewMatrix);
|
||||||
void loadPointLights(const std::string& jsonPath, const char* zipFile);
|
void drawCharacters();
|
||||||
|
// Names and health bars drawn over the finished 3D scene.
|
||||||
|
void drawCharacterOverlays(const Eigen::Matrix4f& cameraViewMatrix);
|
||||||
void updateTriggerZones(const Eigen::Vector3f& playerPos);
|
void updateTriggerZones(const Eigen::Vector3f& playerPos);
|
||||||
void captureAuxiliaryState(LocationGameState& out) const;
|
void captureAuxiliaryState(LocationGameState& out) const;
|
||||||
void applyAuxiliaryState(const LocationGameState& in);
|
void applyAuxiliaryState(const LocationGameState& in);
|
||||||
|
|||||||
+97
-113
@@ -2,14 +2,77 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <utility>
|
||||||
#include "OrcaSolver.h"
|
#include "OrcaSolver.h"
|
||||||
|
|
||||||
namespace FRG {
|
namespace FRG {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr float PI = 3.14159265358979323846f;
|
constexpr float kPi = 3.14159265358979323846f;
|
||||||
constexpr float NPC_TALK_DISTANCE = 1.35f;
|
constexpr fp NPC_TALK_DISTANCE_FP_SQUARED() { return fp(kNpcTalkDistance * kNpcTalkDistance); };
|
||||||
constexpr fp NPC_TALK_DISTANCE_FP_SQUARED() { return fp(NPC_TALK_DISTANCE * NPC_TALK_DISTANCE); };
|
|
||||||
|
// Rebuilds each configured state from content defaults while keeping any
|
||||||
|
// runtime values already present (loaded from a save). Entries that are not in
|
||||||
|
// the content are an error.
|
||||||
|
template <class State, class Data, class MakeDefaults>
|
||||||
|
void applyContentDefaults(
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<State>>& states,
|
||||||
|
const std::vector<Data>& content,
|
||||||
|
const char* kind,
|
||||||
|
MakeDefaults makeDefaults)
|
||||||
|
{
|
||||||
|
std::unordered_set<std::string> configured;
|
||||||
|
for (const Data& data : content) {
|
||||||
|
configured.insert(data.id);
|
||||||
|
State defaults = makeDefaults(data);
|
||||||
|
auto& state = states[data.id];
|
||||||
|
if (!state) {
|
||||||
|
state = std::make_shared<State>(std::move(defaults));
|
||||||
|
} else {
|
||||||
|
nlohmann::json runtime;
|
||||||
|
state->save(runtime);
|
||||||
|
*state = std::move(defaults);
|
||||||
|
state->load(runtime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto& entry : states)
|
||||||
|
if (configured.count(entry.first) == 0)
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string("Saved location contains unknown ") + kind +
|
||||||
|
" '" + entry.first + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loads `values` into `states`. When `states` is already populated from
|
||||||
|
// content, the saved IDs must match it exactly.
|
||||||
|
template <class State>
|
||||||
|
void loadStates(
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<State>>& states,
|
||||||
|
const nlohmann::json& values,
|
||||||
|
const char* kind,
|
||||||
|
const char* key)
|
||||||
|
{
|
||||||
|
if (!values.is_object())
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string("Location ") + key + " must be an object");
|
||||||
|
if (!states.empty()) {
|
||||||
|
for (const auto& entry : states)
|
||||||
|
if (!values.contains(entry.first))
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string("Saved location is missing ") + kind +
|
||||||
|
" '" + entry.first + "'");
|
||||||
|
for (const auto& [id, value] : values.items())
|
||||||
|
if (states.count(id) == 0)
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string("Saved location contains unknown ") + kind +
|
||||||
|
" '" + id + "'");
|
||||||
|
}
|
||||||
|
for (const auto& [id, value] : values.items()) {
|
||||||
|
auto& state = states[id];
|
||||||
|
if (!state) state = std::make_shared<State>();
|
||||||
|
state->load(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocationGameState::setup(
|
bool LocationGameState::setup(
|
||||||
@@ -37,46 +100,17 @@ bool LocationGameState::setup(
|
|||||||
if (initializeRuntimeFields) resetTaxi();
|
if (initializeRuntimeFields) resetTaxi();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<std::string, bool> configuredNpcs;
|
applyContentDefaults(
|
||||||
for (const NpcData& data : content.npcs) {
|
npcs, content.npcs, "NPC", [&](const NpcData& data) {
|
||||||
configuredNpcs.emplace(data.id, true);
|
CharacterState defaults = data.toCharacterState();
|
||||||
CharacterState defaults = data.toCharacterState();
|
loadCharacterAnimationMetadata(defaults, zipFile);
|
||||||
loadCharacterAnimationMetadata(defaults, zipFile);
|
return defaults;
|
||||||
auto& state = npcs[data.id];
|
});
|
||||||
if (!state) {
|
applyContentDefaults(
|
||||||
state = std::make_shared<CharacterState>(std::move(defaults));
|
interactiveObjects, content.interactiveObjects,
|
||||||
} else {
|
"interactive object", [](const InteractiveObjectData& data) {
|
||||||
nlohmann::json runtime;
|
return data.toInteractiveObjectState();
|
||||||
state->save(runtime);
|
});
|
||||||
*state = std::move(defaults);
|
|
||||||
state->load(runtime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const auto& [id, state] : npcs)
|
|
||||||
if (configuredNpcs.count(id) == 0)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location contains unknown NPC '" + id + "'");
|
|
||||||
|
|
||||||
std::unordered_map<std::string, bool> configuredObjects;
|
|
||||||
for (const InteractiveObjectData& data : content.interactiveObjects) {
|
|
||||||
configuredObjects.emplace(data.id, true);
|
|
||||||
InteractiveObjectState defaults = data.toInteractiveObjectState();
|
|
||||||
auto& state = interactiveObjects[data.id];
|
|
||||||
if (!state) {
|
|
||||||
state =
|
|
||||||
std::make_shared<InteractiveObjectState>(std::move(defaults));
|
|
||||||
} else {
|
|
||||||
nlohmann::json runtime;
|
|
||||||
state->save(runtime);
|
|
||||||
*state = std::move(defaults);
|
|
||||||
state->load(runtime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const auto& [id, state] : interactiveObjects)
|
|
||||||
if (configuredObjects.count(id) == 0)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location contains unknown interactive object '" +
|
|
||||||
id + "'");
|
|
||||||
|
|
||||||
std::unordered_map<std::string, TriggerZoneGameState> newTriggers;
|
std::unordered_map<std::string, TriggerZoneGameState> newTriggers;
|
||||||
for (const TriggerZoneDefinition& data : content.triggerZones) {
|
for (const TriggerZoneDefinition& data : content.triggerZones) {
|
||||||
@@ -106,17 +140,6 @@ bool LocationGameState::setup(
|
|||||||
return initializeRuntimeFields;
|
return initializeRuntimeFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterState* LocationGameState::findCharacter(
|
|
||||||
const std::string& id, PlayerStateMap& players)
|
|
||||||
{
|
|
||||||
if (id.empty()) return nullptr;
|
|
||||||
auto entity = players.find(id);
|
|
||||||
if (entity != players.end() && entity->second) return entity->second.get();
|
|
||||||
auto npc = npcs.find(id);
|
|
||||||
if (npc != npcs.end() && npc->second) return npc->second.get();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const CharacterState* LocationGameState::findCharacter(
|
const CharacterState* LocationGameState::findCharacter(
|
||||||
const std::string& id, const PlayerStateMap& players) const
|
const std::string& id, const PlayerStateMap& players) const
|
||||||
{
|
{
|
||||||
@@ -128,17 +151,22 @@ const CharacterState* LocationGameState::findCharacter(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CharacterState* LocationGameState::findCharacter(
|
||||||
|
const std::string& id, PlayerStateMap& players)
|
||||||
|
{
|
||||||
|
return const_cast<CharacterState*>(
|
||||||
|
std::as_const(*this).findCharacter(id, players));
|
||||||
|
}
|
||||||
|
|
||||||
bool LocationGameState::setCharacterDestination(
|
bool LocationGameState::setCharacterDestination(
|
||||||
const std::string& id,
|
const std::string& id,
|
||||||
const Vec3fp& target,
|
const Vec3fp& target,
|
||||||
std::string callbackName,
|
std::string callbackName,
|
||||||
PlayerStateMap& players,
|
PlayerStateMap& players)
|
||||||
const std::string& forcedObstacleId)
|
|
||||||
{
|
{
|
||||||
CharacterState* character = findCharacter(id, players);
|
CharacterState* character = findCharacter(id, players);
|
||||||
if (!character || !location) return false;
|
if (!character || !location) return false;
|
||||||
character->setTarget(
|
character->setTarget(target, std::move(callbackName), *location);
|
||||||
target, std::move(callbackName), *location, id);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +177,7 @@ bool LocationGameState::replanCharacter(
|
|||||||
CharacterState* character = findCharacter(id, players);
|
CharacterState* character = findCharacter(id, players);
|
||||||
if (!character || !location) return false;
|
if (!character || !location) return false;
|
||||||
|
|
||||||
character->forceReplan(*location, id);
|
character->forceReplan(*location);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,8 +276,8 @@ bool LocationGameState::updateNpcCar(std::int64_t deltaMs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
float angleDiff = targetHeading - car.rotation;
|
float angleDiff = targetHeading - car.rotation;
|
||||||
while (angleDiff > PI) angleDiff -= 2.f * PI;
|
while (angleDiff > kPi) angleDiff -= 2.f * kPi;
|
||||||
while (angleDiff < -PI) angleDiff += 2.f * PI;
|
while (angleDiff < -kPi) angleDiff += 2.f * kPi;
|
||||||
|
|
||||||
const float turnIntent = (std::max)(-1.f, (std::min)(1.f, angleDiff * 2.f));
|
const float turnIntent = (std::max)(-1.f, (std::min)(1.f, angleDiff * 2.f));
|
||||||
const float targetSteer = turnIntent * NpcCar::maxSteerAngle;
|
const float targetSteer = turnIntent * NpcCar::maxSteerAngle;
|
||||||
@@ -285,8 +313,8 @@ bool LocationGameState::updateNpcCar(std::int64_t deltaMs)
|
|||||||
car.position += stepDelta;
|
car.position += stepDelta;
|
||||||
|
|
||||||
car.wheelAngle += car.velocity * 4.f * dt;
|
car.wheelAngle += car.velocity * 4.f * dt;
|
||||||
while (car.wheelAngle > 2.f * PI)
|
while (car.wheelAngle > 2.f * kPi)
|
||||||
car.wheelAngle -= 2.f * PI;
|
car.wheelAngle -= 2.f * kPi;
|
||||||
|
|
||||||
if (!location->taxiArrivedCallbackCalled) {
|
if (!location->taxiArrivedCallbackCalled) {
|
||||||
const Eigen::Vector3f toArrival =
|
const Eigen::Vector3f toArrival =
|
||||||
@@ -396,8 +424,6 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
// 2. ФАЗА 1: Обновляем логику каждого персонажа (вычисляется preferredVelocity)
|
// 2. ФАЗА 1: Обновляем логику каждого персонажа (вычисляется preferredVelocity)
|
||||||
for (auto& entry : allChars) {
|
for (auto& entry : allChars) {
|
||||||
CharacterUpdateContext context;
|
CharacterUpdateContext context;
|
||||||
context.characterId = entry.id;
|
|
||||||
|
|
||||||
|
|
||||||
auto attack = observations.find(entry.state->attackTargetId);
|
auto attack = observations.find(entry.state->attackTargetId);
|
||||||
if (attack != observations.end()) context.attackTarget = &attack->second;
|
if (attack != observations.end()) context.attackTarget = &attack->second;
|
||||||
@@ -456,13 +482,12 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
st->position.z = agent.pos.y;
|
st->position.z = agent.pos.y;
|
||||||
st->velocity = agent.newVel;
|
st->velocity = agent.newVel;
|
||||||
|
|
||||||
st->movedLastTick = (movedDistSq > fp(0.0005f));
|
const bool moved = (movedDistSq > fp(0.0005f));
|
||||||
|
|
||||||
// Если персонаж хотел идти, проверяем — продвинулся ли он или уперся в глухую пробку
|
// Если персонаж хотел идти, проверяем — продвинулся ли он или уперся в глухую пробку
|
||||||
const bool wantedToMove = st->preferredVelocity.lengthSq() > fp(0.01f);
|
const bool wantedToMove = st->preferredVelocity.lengthSq() > fp(0.01f);
|
||||||
if (wantedToMove) {
|
if (wantedToMove) {
|
||||||
if (st->movedLastTick) {
|
if (moved) {
|
||||||
st->movementBlockedTicks = 0;
|
|
||||||
if (st->currentState == AnimationState::STAND) {
|
if (st->currentState == AnimationState::STAND) {
|
||||||
st->currentState = AnimationState::WALK;
|
st->currentState = AnimationState::WALK;
|
||||||
st->resetAnim = true;
|
st->resetAnim = true;
|
||||||
@@ -473,7 +498,6 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
st->movementBlockedTicks++;
|
|
||||||
if (st->currentState == AnimationState::WALK) {
|
if (st->currentState == AnimationState::WALK) {
|
||||||
st->currentState = AnimationState::STAND;
|
st->currentState = AnimationState::STAND;
|
||||||
st->resetAnim = true;
|
st->resetAnim = true;
|
||||||
@@ -491,7 +515,6 @@ LocationSimulationEvents LocationGameState::update(
|
|||||||
result.damage.push_back({
|
result.damage.push_back({
|
||||||
source.events.attackTargetId,
|
source.events.attackTargetId,
|
||||||
source.characterId,
|
source.characterId,
|
||||||
damage,
|
|
||||||
target->hp,
|
target->hp,
|
||||||
target->initialHp,
|
target->initialHp,
|
||||||
source.events.attackDirection });
|
source.events.attackDirection });
|
||||||
@@ -583,49 +606,10 @@ void LocationGameState::load(const nlohmann::json& in)
|
|||||||
if (!location) location = std::make_shared<LocationNetworkState>();
|
if (!location) location = std::make_shared<LocationNetworkState>();
|
||||||
location->load(in.at("state"));
|
location->load(in.at("state"));
|
||||||
|
|
||||||
const auto& npcValues = in.at("npcs");
|
loadStates(npcs, in.at("npcs"), "NPC", "npcs");
|
||||||
if (!npcValues.is_object())
|
loadStates(
|
||||||
throw std::runtime_error("Location npcs must be an object");
|
interactiveObjects, in.at("interactiveObjects"),
|
||||||
{
|
"interactive object", "interactiveObjects");
|
||||||
const auto& values = npcValues;
|
|
||||||
if (!npcs.empty()) {
|
|
||||||
for (const auto& [id, npc] : npcs)
|
|
||||||
if (!values.contains(id))
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location is missing NPC '" + id + "'");
|
|
||||||
for (const auto& [id, value] : values.items())
|
|
||||||
if (npcs.count(id) == 0)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location contains unknown NPC '" + id + "'");
|
|
||||||
}
|
|
||||||
for (const auto& [id, value] : values.items()) {
|
|
||||||
auto& npc = npcs[id];
|
|
||||||
if (!npc) npc = std::make_shared<CharacterState>();
|
|
||||||
npc->load(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto& objectValues = in.at("interactiveObjects");
|
|
||||||
if (!objectValues.is_object())
|
|
||||||
throw std::runtime_error("Location interactiveObjects must be an object");
|
|
||||||
{
|
|
||||||
const auto& values = objectValues;
|
|
||||||
if (!interactiveObjects.empty()) {
|
|
||||||
for (const auto& [id, object] : interactiveObjects)
|
|
||||||
if (!values.contains(id))
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location is missing interactive object '" + id + "'");
|
|
||||||
for (const auto& [id, value] : values.items())
|
|
||||||
if (interactiveObjects.count(id) == 0)
|
|
||||||
throw std::runtime_error(
|
|
||||||
"Saved location contains unknown interactive object '" + id + "'");
|
|
||||||
}
|
|
||||||
for (const auto& [id, value] : values.items()) {
|
|
||||||
auto& object = interactiveObjects[id];
|
|
||||||
if (!object) object = std::make_shared<InteractiveObjectState>();
|
|
||||||
object->load(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogue = in.at("dialogue");
|
dialogue = in.at("dialogue");
|
||||||
scriptGlobals = in.at("scriptGlobals");
|
scriptGlobals = in.at("scriptGlobals");
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ struct CharacterSimulationEvent {
|
|||||||
struct CharacterDamageEvent {
|
struct CharacterDamageEvent {
|
||||||
std::string targetId;
|
std::string targetId;
|
||||||
std::string attackerId;
|
std::string attackerId;
|
||||||
float amount = 0.f;
|
|
||||||
float hp = 0.f;
|
float hp = 0.f;
|
||||||
float maxHp = 0.f;
|
float maxHp = 0.f;
|
||||||
Vec3fp direction;
|
Vec3fp direction;
|
||||||
@@ -68,8 +67,7 @@ struct LocationGameState {
|
|||||||
const std::string& id,
|
const std::string& id,
|
||||||
const Vec3fp& target,
|
const Vec3fp& target,
|
||||||
std::string callbackName,
|
std::string callbackName,
|
||||||
PlayerStateMap& players,
|
PlayerStateMap& players);
|
||||||
const std::string& forcedObstacleId = {});
|
|
||||||
bool replanCharacter(
|
bool replanCharacter(
|
||||||
const std::string& id,
|
const std::string& id,
|
||||||
PlayerStateMap& players);
|
PlayerStateMap& players);
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ struct LocationNetworkState : public ISaveable {
|
|||||||
Eigen::Vector3f taxiCarTriggerPosition = Eigen::Vector3f(0,0,0);
|
Eigen::Vector3f taxiCarTriggerPosition = Eigen::Vector3f(0,0,0);
|
||||||
std::vector<Eigen::Vector3f> taxiCarWaypoints;
|
std::vector<Eigen::Vector3f> taxiCarWaypoints;
|
||||||
|
|
||||||
// (trigger/teleport zone runtime flags are serialised by id directly in Location::save/load)
|
// (trigger/teleport zone runtime flags live in LocationGameState)
|
||||||
|
|
||||||
// ---- Serialisation ----
|
// ---- Serialisation ----
|
||||||
void save(nlohmann::json& out) const override;
|
void save(nlohmann::json& out) const override;
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ void InternalGameServer::startCampaign(
|
|||||||
state_.locations.clear();
|
state_.locations.clear();
|
||||||
state_.players.clear();
|
state_.players.clear();
|
||||||
state_.questJournal.loadFromFile(campaign.questsPath, zipFile);
|
state_.questJournal.loadFromFile(campaign.questsPath, zipFile);
|
||||||
//state_.globalFloats["player_hp"] = 200.f;
|
|
||||||
|
|
||||||
if (createLocalPlayer) {
|
if (createLocalPlayer) {
|
||||||
auto player = std::make_shared<CharacterState>();
|
auto player = std::make_shared<CharacterState>();
|
||||||
@@ -142,12 +141,9 @@ void InternalGameServer::resetCampaign(
|
|||||||
state_.isDarklands = false;
|
state_.isDarklands = false;
|
||||||
state_.isNight = false;
|
state_.isNight = false;
|
||||||
state_.isDawn = false;
|
state_.isDawn = false;
|
||||||
//state_.playerHp = 200.f;
|
|
||||||
state_.playerMaxHp = 200.f;
|
|
||||||
state_.money = 5500;
|
state_.money = 5500;
|
||||||
state_.globalInts.clear();
|
state_.globalInts.clear();
|
||||||
state_.globalFloats.clear();
|
state_.globalFloats.clear();
|
||||||
//state_.globalFloats["player_hp"] = 200.f;
|
|
||||||
state_.tutorialStep = TutorialStep::AdvanceDialogue;
|
state_.tutorialStep = TutorialStep::AdvanceDialogue;
|
||||||
state_.tutorialPhoneChatScreenOpened = false;
|
state_.tutorialPhoneChatScreenOpened = false;
|
||||||
state_.tutorialJournalScreenOpened = false;
|
state_.tutorialJournalScreenOpened = false;
|
||||||
@@ -176,8 +172,7 @@ bool InternalGameServer::prepareLocation(const LocationConfig& config)
|
|||||||
if (player != state_.players.end() && player->second) {
|
if (player != state_.players.end() && player->second) {
|
||||||
player->second->position = config.playerPosition;
|
player->second->position = config.playerPosition;
|
||||||
player->second->setTarget(
|
player->second->setTarget(
|
||||||
config.playerPosition, std::string(), *authoritative.location,
|
config.playerPosition, std::string(), *authoritative.location);
|
||||||
localPlayerId_);
|
|
||||||
}
|
}
|
||||||
publishMutation();
|
publishMutation();
|
||||||
return initializeLocation;
|
return initializeLocation;
|
||||||
|
|||||||
Reference in new issue
Block a user