diff --git a/docs/item-data.md b/docs/item-data.md index d107adb528..a04cc78b09 100644 --- a/docs/item-data.md +++ b/docs/item-data.md @@ -1610,7 +1610,7 @@ drawing hands the look. | `kind` | `texture`: the mesh's own texture, or the layer's; `reflection`: a reflection that moves over the mesh (chrome); `flatColor`: the mesh in the light alone, without a texture | | `motion` | How a reflection moves: `slowDrift` (left out), `fastSweep`, `followsLight`, `swirl`, `strongSwirl`, `stripes`, `verySlowDrift`, `oilSheen`, `stillShine` | | `where` | Where a reflection goes: `over` the texture (left out), or `underHoles`: on a mesh whose texture has holes, drawn before the texture, solid and on both faces, so it fills the holes (the Magic Gladiator sets); over a texture without holes, a glowing mesh and a see-through item it goes over with its blend. A look with such a layer draws mesh by mesh, every layer of a mesh before the next mesh, and the layer leaves the light as it found it | -| `blend` | `normal` (left out), `glow` (added to what is below), `asDrawing` (the drawing's own: a doppelganger draws see-through) | +| `blend` | `normal` (left out), `glow` (added to what is below), `darken` (darkens what is below, the Pumpkin of Luck's reflection), `asDrawing` (the drawing's own: a doppelganger draws see-through) | | `meshes` | Left out: every mesh, with the model's texture scripts, without the item's hidden mesh; `"allEvenHidden"`: every mesh, the hidden one too; `[0, 2]`: those meshes; `{"allBut": [2]}`: every mesh but those; `"none"`: no mesh, a layer that draws nothing, the default of a layer the values of some items turn on | | `texture` | A texture file under `Data` (`Effect/Chrome01.jpg`) instead of the mesh's own: a `.jpg` or a `.tga`, which the game reads from its `.OZJ` or `.OZT` file | | `light` | The light the layer is drawn in: `[red, green, blue]`, or `{"tint": [red, green, blue]}`, the item's light times those; each a number or a shape. `{"brightness": 0.8}` is the item's light scaled so its brightest channel is 0.8 (a grey for a black light). It stays for the layers after it, and `{"tint": [1, 1, 1]}` is the item's light again. Left out: the light the layer before left | @@ -1653,7 +1653,10 @@ item's value times the shape (`"timesItem": true`), as the Phoenix Soul items pulse their own opacity and glow strength. Its numbers give the code's values exactly, so a look moved from code keeps them: `{"shape": "wave", "from": -0.2, "to": 1, "seconds": 6.283185}` is the -code's `sin(WorldTime * 0.001f) * 0.6f + 0.4f`. +code's `sin(WorldTime * 0.001f) * 0.6f + 0.4f`. A layer's opacity, glow +strength or scroll can also be the item's value times a fixed number, +`{"itemTimes": 1.5}`, as the Cursed Castle Water glows at 1.5 and 0.25 of +the item's. | Shape | Fields | Value | |---|---|---| @@ -1720,6 +1723,53 @@ look (a layer's `"drawing"`; the Devil's Eye draws at 2), and update puts on the item's object, which the ground item's next draw adds to its light (the Devil's Eye's pulse). A field of an entry can be one each item sets, which the model entry sets in `itemEffectValues`. +`animationSpeed` plays the item object's animation in the update at that +speed, as the Cursed Castle Water's ground item moves; without it the update +plays none. + +`onBones` lists the **things** an item effect creates on the item's bones in +every update, from the item's pose in that update: sprites, particles, +lightning and effects of the effect catalogue, each by its name there (the +**Effect Browser** lists them) with a `subType` number. + +```json +{"name": "wingOfStorm", "onBones": [ + {"sprite": "cloud64", "subType": 1, "bones": [9, 20, 19], "scale": 0.5, "rotation": {"shape": "scroll", "perSecond": 10}}, + {"together": {"bones": [11, 21, 29], "chance": {"oneIn": 2, "per": "once"}}, + "things": [{"effect": "fenrirThunder", "subType": 1, "color": [0.6, 0.6, 0.9], "chance": {"oneIn": 20, "draw": "plain"}}]}]}, +{"name": "wingsOfDarkness", "onBones": [ + {"together": {"between": [[30, 22], [29, 21]], "chance": {"oneIn": 1}}, + "things": [{"joint": "jointThunder", "subType": 14, "scale": 20}, + {"joint": "jointSpirit", "subType": 4, "reversed": true, "scale": 25}]}]} +``` + +An entry is one thing, named by its kind (`"sprite"`, `"particle"`, +`"joint"` for lightning, `"effect"`), with its places and values; or a group, +`"together"` with the places and the chance its `"things"` share, so they +come together (the Wings of Darkness' two lightnings strike at once). + +| Field | Values | +|---|---| +| `bones` | The bone numbers of the item's model the thing is created at, each once a frame; 0 to 199 | +| `between` | Lightning only: pairs of bones, `[from, to]`, 0 to 199, the lightning goes from the first to the second | +| `at` | `"origin"`: once at the item object's own place (Rena's spark) | +| `subType` | The SubType the type is created with, 0 to 1000 (left out: 0) | +| `scale` | A number or a shape (left out: 1) | +| `color` | `[red, green, blue]`, each a number or a shape: a sprite's color, the light of a particle, lightning or effect | +| `rotation` | A sprite's rotation in degrees, a number or a shape | +| `reversed` | Lightning from the second bone of each pair to the first | +| `chance` | `{"oneIn": N}`, N from 1 to 10000: once in N frames at the game's reference frame rate, the same at any frame rate; `"draw": "plain"`: a plain random draw each update, as the monster sounds draw theirs; `"per": "once"`: one roll for the entry instead of one for each bone or pair. A thing inside a group can roll its own chance after the group's (the Wing of Storm's thunder), once each time the group's holds, so it has no `"per"` | + +An entry names exactly one of `bones`, `between` and `at`. The checks: +**fatal** a thing of an unknown kind, lightning at bones or a thing that +isn't lightning between bones, places named twice or not at all, a bone, +SubType or `oneIn` out of its range, a chance without `oneIn`, `"per"` on +the chance of a thing inside a group; **error** a type the effect catalogue +doesn't have (it is not created, and the game logs it when it loads its +data); **warning** a bone an item's model doesn't have (about that item: +nothing is created at it, nor lightning of a pair with it). The things are created as the game moves them, so they look as in +the game; the Devil's Key's and Invitation's sparks sit on their bones as +the item is scaled, as every other thing on bones. ### Shared models @@ -2194,12 +2244,48 @@ The picked look shows: change over time. - The items that use the look; a click selects one. -A picked **item effect** shows, instead of parts and layers, its entries -**Before drawing** in their order (**Add**, **Remove**, **Move up**, **Move -down**), each with its Only when, the item values it sets (no light), the -drawing's opacity, the level the item glows like and Each item sets, and the -**Object light** as the last line. Its preview runs the edited effect on the -picked item; Apply, Revert and the problems work as for a render style. +A picked **item effect** shows, instead of parts and layers, its lines: its +entries **Before drawing** in their order, each with its Only when, the item +values it sets (no light), the drawing's opacity, the level the item glows +like and Each item sets; the **Object light**; the **Animation speed**; and +its entries **On bones**. **Add** beside Before drawing and beside On bones +adds an entry to that list, and **Copy**, **Move up**, **Move down** and +**Remove** change the picked one. An entry on bones has: + +- where its things go: **At bones**, **Between bones** (lightning, from the + first bone of a pair to the second) or **At the item's place**, with its + bones as number fields (**+ Bone**, **+ Pair**, `x` takes one out); +- its **Chance**: **Once in** so many frames, drawn **At the game's frame + rate** or **Plain**, and **Once for all** bones or pairs; +- **Together**, a group whose things share the entry's places and chance, + each thing with **Its own chance**; +- each thing's **Kind**, its **Type** from the effect catalogue (a list with + a filter), **SubType**, **Scale**, **Color**, a sprite's **Rotation** and + lightning's **From the second bone to the first**. + +The views of the preview show the things on bones **live**: each view runs +its own effect (the item's, the chosen look, the edited one) in the game's +own effect lists, so they move and fade as in the game, and the views can be +compared. They are created at your character's place, which the world +doesn't draw them at, and each view draws only its own. **Stop time** stops +them too: lightning and particles hold still, sprites and lights follow the +time slider. A view creates nothing while the game's effect lists are +nearly full, so the game's own effects come first. The Item Model window's +preview shows them too. + +**Show bones**, beside Stop time, draws the item's skeleton over each view: +each bone a dot joined by a line to the bone it hangs on, with its number and +name when the mouse points at it. The picked entry's bones are orange with +their numbers, its pairs joined from start to end, and a bone the mouse +points at in the entry's fields is ringed. **Pick in the preview**, above the +entry's fields, makes a click on a bone's dot add the bone or take it out; +between bones, click the start of the lightning, then its end, which adds the +pair or, when the entry has it, takes it out. Armor has no bones of its own +there: it is drawn on the character's skeleton, and the game creates nothing +on bones for it. + +Its preview runs the edited effect on the picked item; Apply, Revert and the +problems work as for a render style. Each change of the looks or their folders is a step of the item undo history and reaches the game at once. **Save Items** writes diff --git a/docs/superpowers/specs/2026-11-01-looks-in-data-design.md b/docs/superpowers/specs/2026-11-01-looks-in-data-design.md index 53bacfedd0..2cf9a1434a 100644 --- a/docs/superpowers/specs/2026-11-01-looks-in-data-design.md +++ b/docs/superpowers/specs/2026-11-01-looks-in-data-design.md @@ -98,6 +98,15 @@ Made while reviewing sven-n/MuMain#915, 2026-11-01. | L48 | The glow values on the ground (Q-L36, 2026-11-08) | **They pulse everywhere.** `ItemObjectAttribute` sets the glow values of L27 on every drawing of a held, worn or inventory item, but once at the drop for a ground item, so a pulsing or random glow freezes on the ground at the value of the drop. As item values before the drawing (item effects, L27) they apply on every drawing, so ground items pulse like held ones: a quirk fix in its own commit, with the recorder's expected differences and an in-game before/after (L16). Rejected: a condition that keeps the drop's value on the ground, and leaving the 39 item types in code for a later step. | | L49 | Item values before the shadow (Q-L37, 2026-11-08) | **The shadow pass applies the item effect's values first.** A held item's shadow (`RenderPartObjectEffect`, `RenderBodyShadow`) reads the hidden mesh before the item effect runs; with the hidden meshes of L27 in an item effect (the Rune Blade, Elemental Mace and Elemental Shield hide mesh 2, the Dragon Spear mesh 1), the shadow pass applies the item values first, so their shadows stay as today. Items whose item effect hides a mesh by level (the siege potion, the contract, the life stone) then hide it in a shadow too; they cast none in play. Rejected: keeping the four hidden meshes in `ItemObjectAttribute`. | | L50 | Where part models are edited (Q-L38, 2026-11-10) | **In the Item Model window's list.** A group "Part models" after the item groups lists the 11 entries of `PartModels.json` (L28); picking one shows a note on where the game draws it, its Model file (file and texture folders), the mesh list and its render style with "Open in Style Editor", edited like a shared model, with the preview. It has no inventory, ground, glow or item effect. Rejected: listing part models with a look's users in the Style Editor only (file and folders hand-edited), and no editor in pull request 3. | +| L51 | How the preview shows things on bones (Q-L39, 2026-11-11; FX1.7c) | **The game's own effect lists, marked for a preview.** The things a previewed item effect creates (sprites, particles, lightning, effects) are made by the game's own create calls into its effect lists and moved by its own update, so they behave as in the game. In editor builds each of them carries a mark of the view it belongs to: the world's draw loops (`RenderEffects`, `RenderParticles`, `RenderJoints`, `RenderSprites`, `RenderAfterEffects`) skip marked ones, `CullEffects` counts them as seen, and the view's capture draws only its own, with the view's camera. Not chosen: a copy of the lists per view swapped in each frame (costly, random sequences to save), sprites only (lightning, particles and the Storm's thunder missing), and showing the item on the character in the world (no side-by-side preview). | +| L52 | Which preview views show things on bones (Q-L40, 2026-11-11) | **Each view its own.** Every view of the Style Editor's preview (as applied, as edited) keeps its own copy of the item object with its own bones, creates its own things from its own look and draws only those, so an edited look is seen next to the one applied. Two views use about twice the slots of the game's effect lists. Not chosen: only the edited view (no comparison), and a checkbox per view to turn them off. | +| L53 | Where the preview's item stands (Q-L41, 2026-11-11) | **At the player's character.** The hidden preview item of each view is placed at the character's position, as the effect browser's world preview places its owner, so what its things read from the world (ground height, light) is real, as for the item in the game; the world does not draw them (L51). Not chosen: the map's origin corner (odd ground reads), and high above the character (falling particles fall far). | +| L54 | Things on bones while the preview's time stops (Q-L42, 2026-11-11) | **They stop too.** While a view's time is stopped, the game's update skips that view's things and the view creates none; sprites and lights, made from the clock each frame, follow the slider; moving the slider does not wind lightning or particles back. Not chosen: running on with the game's time, and hiding them while time is stopped. | +| L55 | How things on bones name their bones (Q-L43, 2026-11-11) | **One entry, a list of bones.** An entry of an item effect's things on bones (`"onBones"`) names its bones as a list (`"bones": [22, 23, 25]`), and lightning as a list of pairs, from and to (`"between": [[30, 22], [29, 21]]`); the entry's values hold for each of them. The 11 looks take about 25 entries. Not chosen: one entry per bone (about 200 entries), and named bone groups in the look (no two entries share a list today). | +| L56 | Chances of things on bones (Q-L44, 2026-11-11) | **A chance per entry, and groups that share one.** A chance is `{"oneIn": N}`, once in N frames at the game's reference frame rate (`rand_fps_check`), or with `"draw": "plain"` the other draw (`Random::Rand() % N == 0`), as the monster sounds write it; `"per"` says whether it rolls for each bone or pair, or once for the entry. A `"together"` group holds bones (or pairs) and a chance that its things share, so the Wings of Darkness' two lightnings strike together; a thing inside can roll again, as the Storm's thunder does. All 11 looks are copied exactly. Not chosen: a chance per bone only (two looks change), and named chances in the look. | +| L57 | The Devil's Key's and Invitation's sparks (Q-L45, 2026-11-11) | **On the bones, fixed.** The two items placed their sparks at bones without the model's scale (`SpawnDevilsKey`, `SpawnDevilsInvitation`), about a quarter farther from the item's center than the bones on the ground (scale 0.8). Their entries place them on the scaled bones like every other thing on bones; the old position is an expected difference with an in-game before and after, as the quirks of L16. Not chosen: an entry flag `"unscaledBones"` only these two would use. | +| L58 | Picking bones in the Style Editor (Q-L46, 2026-11-11) | **Click them in the preview.** An entry's bones are number fields; the bone under the mouse in the list is ringed in the preview with its number, and "Show bones" draws every bone of the previewed model as a dot with its number on hover. A pick mode adds or removes a bone by clicking its dot; lightning pairs are picked by clicking two bones, from and to. Not chosen: the marks without picking, and numbers only. | +| L59 | The item's value times a number (Q-L47, 2026-11-11) | **`{"itemTimes": 1.5}`.** A layer's opacity, glow strength or scroll can be the item's value times a fixed number, as the Cursed Castle Water glows at 1.5 and 0.25 of the item's; the Style Editor's "the item's" gets a factor field. Not chosen: a wave from 1.5 to 1.5 times the item's (a wave that doesn't wave), and keeping its drawing in code. | ## Current state @@ -549,6 +558,76 @@ unknown glow color (L30). - **Data Checks** (L23, L24): the new areas Render styles and Item effects; the graphics area renamed Graphics look. +### 7a. The live preview of things on bones (FX1.7c, step 2) + +From the survey of 2026-11-11 (main `9b50e946a`) and L51 to L54. In editor +builds only; the game's own code paths stay as they are. + +- **Where it runs in the frame.** Sprites live one update: `UpdateActiveScene` + clears them first (`SceneManager.cpp:487`), and the editor's previews are + recorded after the world's draw (`SceneManager.cpp:1241`). So each view's + item creates its things in a new editor hook inside the game's update, + after `ClearSprites` and the world's moves, from the view's own copy of the + item object and its own bones (L52), at the character's position (L53), + through the same `SpawnPartObjectEffect` the game uses. The editor's own + `Update` runs before `ClearSprites` and is too early. +- **The mark.** Each slot of the effect, particle, joint and sprite lists + carries the view it belongs to (none for the game). The world's draw loops + skip marked slots; `CullEffects` counts a marked effect as seen, so its + children are created as in the game (`UpdateEffectModelEffects` creates them + only for effects the last cull saw). Particles carry no owner, so what a + spawn creates is found by comparing the lists before and after it. A slot keeps + its mark while its view keeps the thing in it; each create call takes the + mark off the slot it fills, so a thing the game creates in a slot a view's + thing just left (the game's own lightning of the same type) stays the + game's. +- **The capture.** A view draws only its own slots, after its item, with the + view's camera put into `g_Camera` around it (`SaveCameraPerspective` / + `RestoreCameraPerspective`), the draw-time frustum tests of particles and + lightning off, and its own sprite marks (the world's per-frame marks would + hide sprites the world drew). +- **Time.** While a view's time is stopped, the game's moves skip its slots + from the view's draw on (so lightning that lives a frame stops as it is), + and it creates only its sprites; a view that has made nothing yet makes + its whole effect once, to stop on (L54). +- **The Item Model window.** Its preview is a view of its own too, beside + the Style Editor's three (asked for on 2026-11-13), with the item effect + its item runs; it has no stopped time. +- **When they go.** A view's things are removed when its look, item, level or + pose changes, when the view closes, when the map changes + (`OnWorldClearing`) and when the editor closes; as the world preview + does it (`EffectPreviewTracker`), with the things that follow them. +- **Room in the lists.** The game comes first: a view creates nothing while + a list has fewer than a quarter of its slots free, and the views together + use at most a quarter of each list. +- **Sounds and random numbers.** Things a view creates play no sound (as the + world preview mutes them). They draw from the game's random sequences as + in the game; the preview is an editor tool, and the recorder's tests pin + the sequences anyway. +- **cppcheck.** `ZzzEffectJoint.cpp` and `zzzeffectsprite.cpp` are checked + as whole files once they change, so they are checked first. + +### 7b. Things on bones in the item effect file (step 3) + +From the survey of 2026-11-11 (main `9b50e946a`) and L55 to L57. The 9 +item effects and the bone parts of `pumpkinOfLuck` and `cursedCastleWater` +(L29) move; `helperNpcPlate` lights the helper NPC, not an item, and moves +with the monsters' looks (MN8). + +- **Kinds.** `"sprite"`, `"particle"`, `"joint"` (lightning) and + `"effect"` (the Storm's `fenrirThunder`), each by its FX1 name with a + `"subType"` number (D30); all names the 11 looks use are in the catalogue. +- **Values.** Scale, color (`"light"` for effects), sprite rotation; each a + number or a shape of section 2 (wave, bounce, scroll are used). Offsets + from the bone are allowed (none of the 11 uses one). +- **Places.** `"bones"` or `"between"` (L55), or `"at": "origin"` for the + item object's own place (`rena`). +- **Copied as they are, no special fields:** the Wing of Illusion's last light + sits at bone 33 (the old code reused the last loop's bone); the Pumpkin of + Luck's sprites repeat the wave of the object light the look sets (both come + from the same clock); the Cursed Castle Water's animation speed is a field + of the item effect (L29). + ### 8. The move and its proof Looks move by building block (L17), in the pull requests of section 9. Each @@ -611,7 +690,7 @@ Answered one by one, each with the current state, every option with an example, and a recommendation. Answered: Q-L1 (L7), Q-L2a (L8), Q-L2b (L9, L10), Q-L2c (L11), Q-L3 (L12), -Q-L4a (L13), Q-L4b (L14), Q-L4c (L15), Q-L5a (L16), Q-L5b (L17), Q-L6a to Q-L6c (L18 to L20), Q-L7a and Q-L7b (L21, L22), Q-L8 (L23), Q-L12 (L24), Q-L9 (L25), Q-L10 (L26), Q-L11 (L27), Q-L13 (L28), all on 2026-11-01; Q-L14 (L29), Q-L15 (L30) and Q-L16 (L31) on 2026-11-03; Q-L17 (L32) on 2026-11-04; Q-L18 (L33) and Q-L19 (L34) on 2026-11-05; Q-L20 (L35), Q-L21 (L36), Q-L25 (L37), Q-L22 (L38), Q-L23 (L39) and Q-L24 (L40) on 2026-11-06; Q-L26 and Q-L27 (L41), Q-L28 to Q-L30 (L42) and Q-L31 (L43) on 2026-11-07; Q-L32 (L44), Q-L33 (L45), Q-L34 (L46), Q-L35 (L47), Q-L36 (L48) and Q-L37 (L49) on 2026-11-08; Q-L38 (L50) on 2026-11-10. All questions are answered. +Q-L4a (L13), Q-L4b (L14), Q-L4c (L15), Q-L5a (L16), Q-L5b (L17), Q-L6a to Q-L6c (L18 to L20), Q-L7a and Q-L7b (L21, L22), Q-L8 (L23), Q-L12 (L24), Q-L9 (L25), Q-L10 (L26), Q-L11 (L27), Q-L13 (L28), all on 2026-11-01; Q-L14 (L29), Q-L15 (L30) and Q-L16 (L31) on 2026-11-03; Q-L17 (L32) on 2026-11-04; Q-L18 (L33) and Q-L19 (L34) on 2026-11-05; Q-L20 (L35), Q-L21 (L36), Q-L25 (L37), Q-L22 (L38), Q-L23 (L39) and Q-L24 (L40) on 2026-11-06; Q-L26 and Q-L27 (L41), Q-L28 to Q-L30 (L42) and Q-L31 (L43) on 2026-11-07; Q-L32 (L44), Q-L33 (L45), Q-L34 (L46), Q-L35 (L47), Q-L36 (L48) and Q-L37 (L49) on 2026-11-08; Q-L38 (L50) on 2026-11-10; Q-L39 (L51), Q-L40 (L52), Q-L41 (L53) Q-L42 (L54), Q-L43 (L55), Q-L44 (L56), Q-L45 (L57), Q-L46 (L58) and Q-L47 (L59) on 2026-11-11. ## Tasks @@ -622,9 +701,9 @@ The design, then the pull requests of L26 and L27: 2026-11-03. 2. [x] Pull request 0, the design: this document, for review (#954). 3. [x] Pull request 1, the mesh list (L21, L22) and the names of L24 (#970). -4. [ ] Pull request 2, step 1 part 1: the machinery, the Style Editor, L17's +4. [x] Pull request 2, step 1 part 1: the machinery, the Style Editor, L17's groups 1 and 2 without the six render styles of L33. -5. [ ] Pull request 3, step 1 part 2: L17's groups 3 to 5 (#915 is +5. [x] Pull request 3, step 1 part 2: L17's groups 3 to 5 (#915 is merged), with `ItemObjectAttribute`'s glow values (L27), and the part models with the 3 looks of `RenderModelWithoutStyle` (L28), and the shines below +3 and the Deadly Staff's glow pass as glow data (L30), diff --git a/src/Localization/Editor.de.resx b/src/Localization/Editor.de.resx index cd343e486a..a4a6e04b54 100644 --- a/src/Localization/Editor.de.resx +++ b/src/Localization/Editor.de.resx @@ -673,6 +673,12 @@ Addiert ihr Licht zu dem, was vor ihr gezeichnet wurde: Helles leuchtet, Dunkles bleibt durchsichtig. + + Abdunkeln + + + Dunkelt ab, was vor ihr gezeichnet wurde, nach ihrem Licht: eine dunkle Ebene wirft einen Schatten. + Überblendet, wie die Zeichnung des Gegenstands es wählt, wie seine eigene Textur. @@ -5383,4 +5389,145 @@ Ein Gesprächsschritt nennt diesen Satz: er bleibt. + + Auf Knochen + + + Jeder Eintrag erzeugt seine Dinge in jedem Update auf den Knochen des Items: an jedem Knochen, zwischen jedem Knochenpaar (Blitze, vom ersten zum zweiten) oder am Ort des Items selbst. Die Ansichten der Vorschau zeigen sie live, jede aus ihrem eigenen Look. + + + Animationsgeschwindigkeit + + + Wie schnell das Update die Animation des Items abspielt, wie sich das Bodenitem Cursed Castle Water bewegt; ohne spielt es keine. + + + Sprite + + + Partikel + + + Blitz + + + Effekt + + + Was erzeugt wird: ein Sprite (lebt ein Bild lang), ein Partikel, ein Blitz zwischen zwei Knochen oder ein Effekt. + + + Typ + + + Der Typ mit seinem Namen im Effektkatalog (der Effekt-Browser listet sie). + + + Typ wählen + + + Filter + + + Der SubType, mit dem der Typ erzeugt wird; der Code des Typs liest ihn. + + + Die Größe des Dings, eine Zahl oder eine Form. + + + Die Drehung des Sprites in Grad, eine Zahl oder eine Form. + + + Vom zweiten Knochen zum ersten + + + Der Blitz läuft vom zweiten Knochen jedes Paars zum ersten. + + + An Knochen + + + Zwischen Knochen + + + Am Ort des Items + + + Wo die Dinge des Eintrags erzeugt werden: an jedem seiner Knochen, zwischen jedem seiner Knochenpaare oder einmal am Ort des Item-Objekts. + + + Ein Knochen des Item-Modells mit seiner Nummer; die Vorschau umkreist ihn, solange die Maus hier ist. + + + + Knochen + + + + Paar + + + x + + + In der Vorschau wählen + + + Ein Klick auf den Punkt eines Knochens in einer Ansicht fügt den Knochen hinzu oder nimmt ihn heraus; zwischen Knochen erst den Anfang des Blitzes klicken, dann sein Ende. + + + Jetzt das Ende des Blitzes ab Knochen {0} klicken. + + + Knochen zeigen + + + Zeichnet jeden Knochen des gezeigten Items als Punkt; zeigt man auf einen, erscheinen seine Nummer und sein Name. + + + Dieses Item wird auf dem Skelett des Charakters gezeichnet: das Spiel erzeugt keine Dinge auf Knochen dafür. + + + Chance + + + Ohne Chance kommt das Ding in jedem Update. + + + Einmal in + + + Einmal in so vielen Bildern. + + + Ziehung + + + Bei der Bildrate des Spiels + + + Einmal in N Bildern bei der Referenz-Bildrate des Spiels, gleich bei jeder Bildrate. + + + Einfach + + + Eine einfache Zufallsziehung in jedem Update, wie die Monstergeräusche ziehen: bei höherer Bildrate öfter. + + + Einmal für alle + + + Würfelt einmal für den Eintrag, nicht für jeden Knochen oder jedes Paar. + + + Zusammen + + + Die Dinge des Eintrags teilen seine Orte und seine Chance, sodass sie zusammen kommen (die zwei Blitze der Wings of Darkness); ein Ding darin kann danach eine eigene Chance würfeln. + + + + Ding + + + Eigene Chance + diff --git a/src/Localization/Editor.en.resx b/src/Localization/Editor.en.resx index 66b55681da..c2eb9945e6 100644 --- a/src/Localization/Editor.en.resx +++ b/src/Localization/Editor.en.resx @@ -760,6 +760,12 @@ Adds its light to what is drawn before it: bright places glow, dark ones stay see-through. + + Darken + + + Darkens what is drawn before it by its light: a dark layer makes a shadow. + Blends as the item's drawing chooses, as the item's own texture does. @@ -5665,4 +5671,145 @@ A talk step names this set: it stays. + + On bones + + + Each entry creates its things on the item's bones in every update: at each bone, between each pair of bones (lightning, from the first to the second) or at the item's own place. The preview's views show them live, each from its own look. + + + Animation speed + + + How fast the update plays the item's animation, as the Cursed Castle Water's ground item moves; without one it plays none. + + + Sprite + + + Particle + + + Lightning + + + Effect + + + What is created: a sprite (it lives one frame), a particle, lightning between two bones, or an effect. + + + Type + + + The type by its name in the effect catalogue (the Effect Browser lists them). + + + Pick a type + + + Filter + + + The SubType the type is created with; the type's code reads it. + + + The thing's scale, a number or a shape. + + + The sprite's rotation in degrees, a number or a shape. + + + From the second bone to the first + + + The lightning runs from the second bone of each pair to the first. + + + At bones + + + Between bones + + + At the item's place + + + Where the entry's things are created: at each of its bones, between each of its pairs of bones, or once at the item object's own place. + + + A bone of the item's model by its number; the preview rings it while the mouse is here. + + + + Bone + + + + Pair + + + x + + + Pick in the preview + + + A click on a bone's dot in a view adds the bone or takes it out; between bones, click the start of the lightning, then its end. + + + Now click the end of the lightning from bone {0}. + + + Show bones + + + Draws every bone of the previewed item as a dot; pointing at one shows its number and name. + + + This item is drawn on the character's skeleton: the game creates no things on bones for it. + + + Chance + + + Without a chance the thing comes in every update. + + + Once in + + + Once in this many frames. + + + Draw + + + At the game's frame rate + + + Once in N frames at the game's reference frame rate, the same at any frame rate. + + + Plain + + + A plain random draw in each update, as the monster sounds draw theirs: more often at a higher frame rate. + + + Once for all + + + Rolls once for the entry, not for each bone or pair. + + + Together + + + The entry's things share its places and its chance, so they come together (the Wings of Darkness' two lightnings); a thing inside can roll a chance of its own after it. + + + + Thing + + + Its own chance + diff --git a/src/MuEditor/Core/MuEditorCore.cpp b/src/MuEditor/Core/MuEditorCore.cpp index 73fcec83e6..35bf5e725e 100644 --- a/src/MuEditor/Core/MuEditorCore.cpp +++ b/src/MuEditor/Core/MuEditorCore.cpp @@ -19,6 +19,7 @@ #include "Core/Input/SyntheticInput.h" #include "../Config/MuEditorConfig.h" #include "../MuEditor/UI/Colors/MuColorsUI.h" +#include "../MuEditor/UI/StyleEditor/BoneThingsPreview.h" #include "../MuEditor/UI/StyleEditor/MuStyleEditorUI.h" #include "../MuEditor/UI/Common/MuEditorCenterPaneUI.h" #include "../MuEditor/UI/DataChecks/MuDataChecksUI.h" @@ -57,6 +58,7 @@ #include "GameLogic/Monsters/MonsterModelChanges.h" #include "Render/Items/ItemEffects.h" #include "Render/Items/ItemRenderStyles.h" +#include "Core/Utilities/EffectSpawnHook.h" #include "Core/Utilities/WorldClearing.h" #include "Core/Utilities/StringUtils.h" #include "World/MapInfra/MapManager.h" @@ -495,9 +497,17 @@ void CMuEditorCore::ConnectGameHooks() // The effect browser shows what loaded each model and texture; the // records take the map of the moment from the map manager. Core::AssetLoadWorld::SetSource([] { return gMapManager.WorldActive; }); - // The effect browser's world preview removes its objects before the game - // clears its pools. - Core::WorldClearing::SetListener([] { g_MuEffectBrowserUI.OnWorldClearing(); }); + // The effect browser's world preview and the Style Editor's views remove + // their objects before the game clears its pools. + Core::WorldClearing::SetListener( + [] + { + g_MuEffectBrowserUI.OnWorldClearing(); + MuEditor::Looks::g_BoneThingsPreview.OnWorldClearing(); + }); + // The Style Editor's views create their items' things on bones in the + // game's update (design section 7a). + Core::EffectSpawnHook::SetListener([] { MuEditor::Looks::g_BoneThingsPreview.Update(); }); // The game's key reads leave out what is pressed in the editor's own windows. Core::Input::SetOtherWindowQuery([](int virtualKey) { return g_MuEditorCore.IsWithEditorWindow(virtualKey); }); // The cloth of worn pants keeps data of its model's slot: it goes before diff --git a/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.cpp b/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.cpp index f8bd118224..81b24bcc17 100644 --- a/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.cpp +++ b/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.cpp @@ -135,7 +135,8 @@ PreviewFraming EffectPreviewScene::Prepare(const EffectPreviewRequest& request) return {CenterOf(min, max), std::max(RadiusOf(min, max), MinFramingRadius)}; } -void EffectPreviewScene::Draw(const EffectPreviewRequest& request, const EffectPreviewCamera& camera, float aspect) +void EffectPreviewScene::Draw(const EffectPreviewRequest& request, const EffectPreviewCamera& camera, float aspect, + const std::function& afterItem) { const SavedGameRenderState savedState; mu::IMuRenderer& renderer = mu::GetRenderer(); @@ -154,6 +155,8 @@ void EffectPreviewScene::Draw(const EffectPreviewRequest& request, const EffectP DrawBase(request, RadiusOf(extent.min, extent.max)); if (request.showOn == PreviewShowOn::Item) DrawItem(request); + if (afterItem) + afterItem(); DrawSubject(request, camera); CoverAlpha(camera, aspect); @@ -262,28 +265,23 @@ void EffectPreviewScene::DrawBase(const EffectPreviewRequest& request, float sub // the scale it has on the ground: turned as it lies on the ground, or upright // as the inventory turns it, facing the camera. The item's own sprites, // particles and effects are removed again. -void EffectPreviewScene::DrawItem(const EffectPreviewRequest& request) +PreviewItemModels PreviewItemModelsOf(const EffectPreviewRequest& request) +{ + return request.modelSlot >= 0 ? PreviewItemModels{request.modelSlot, request.modelSlot, 0} + : GetPreviewItemModels(request.itemType, request.itemLevel); +} + +void PosePreviewItem(const EffectPreviewRequest& request, const PreviewItemModels& models, float turnDegrees, OBJECT& o, + vec34_t* bones) { - const PreviewItemModels models = request.modelSlot >= 0 ? PreviewItemModels{request.modelSlot, request.modelSlot, 0} - : GetPreviewItemModels(request.itemType, request.itemLevel); - if (!models.CanDraw()) - return; - // Armor is drawn with its own meshes on the bones of the skeleton; both - // keep their fields. BMD& b = Models[models.skeleton]; - const ScopedModelState savedSkeleton(b); - const ScopedModelState savedModel(Models[models.model]); const Render::Items::Display::GroundDisplay ground = Render::Items::Display::GetGroundDisplay(models.model); - - CHARACTER item; - OBJECT* o = &item.Object; - o->Type = models.model; - ItemObjectAttribute(o); - o->LightEnable = false; - item.Class = CLASS_ELF; + o.Type = models.model; + ItemObjectAttribute(&o); + o.LightEnable = false; if (ground.scale) - o->Scale = *ground.scale; - Vector(0.0f, 0.0f, 0.0f, o->Position); + o.Scale = *ground.scale; + Vector(0.0f, 0.0f, 0.0f, o.Position); b.CurrentAction = 0; if (request.itemPose == PreviewItemPose::Inventory) { @@ -296,20 +294,37 @@ void EffectPreviewScene::DrawItem(const EffectPreviewRequest& request) float sceneMatrix[3][4]; float root[3][4]; AngleMatrix(inventoryAngle, inventoryMatrix); - InventoryViewToScene(m_turnDegrees, sceneMatrix); + InventoryViewToScene(turnDegrees, sceneMatrix); R_ConcatTransforms(sceneMatrix, inventoryMatrix, root); b.BodyHeight = inventory.bodyHeight; - b.Animation(BoneTransform, 0.0f, 0.0f, 0, o->Angle, o->HeadAngle, true, false, root); + b.Animation(bones, 0.0f, 0.0f, 0, o.Angle, o.HeadAngle, true, false, root); } else { - Vector(ground.rotation[0], ground.rotation[1], ground.rotation[2] + m_turnDegrees, o->Angle); + Vector(ground.rotation[0], ground.rotation[1], ground.rotation[2] + turnDegrees, o.Angle); b.BodyHeight = ground.bodyHeight; - b.Animation(BoneTransform, 0.0f, 0.0f, 0, o->Angle, o->HeadAngle, false, false); - if (request.itemGroundPlane) - { - DrawGroundUnderItem(models.model); - } + b.Animation(bones, 0.0f, 0.0f, 0, o.Angle, o.HeadAngle, false, false); + } +} + +void EffectPreviewScene::DrawItem(const EffectPreviewRequest& request) +{ + const PreviewItemModels models = PreviewItemModelsOf(request); + if (!models.CanDraw()) + return; + // Armor is drawn with its own meshes on the bones of the skeleton; both + // keep their fields. + BMD& b = Models[models.skeleton]; + const ScopedModelState savedSkeleton(b); + const ScopedModelState savedModel(Models[models.model]); + + CHARACTER item; + OBJECT* o = &item.Object; + item.Class = CLASS_ELF; + PosePreviewItem(request, models, m_turnDegrees, *o, BoneTransform); + if (request.itemPose == PreviewItemPose::Ground && request.itemGroundPlane) + { + DrawGroundUnderItem(models.model); } vec3_t light = {1.0f, 1.0f, 1.0f}; diff --git a/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.h b/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.h index 480dea8263..337113a667 100644 --- a/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.h +++ b/src/MuEditor/UI/EffectBrowser/EffectPreviewScene.h @@ -3,11 +3,14 @@ #ifdef _EDITOR #include "EffectPreviewCamera.h" +#include "EffectPreviewItems.h" #include "EffectPreviewSubject.h" +#include "Core/Globals/_types.h" #include "Data/GameData/EffectData/EffectKind.h" #include +#include #include class OBJECT; @@ -71,6 +74,15 @@ struct EffectPreviewRequest bool turn = true; }; +// The models the scene draws the item of `request` with. +PreviewItemModels PreviewItemModelsOf(const EffectPreviewRequest& request); + +// Poses the item of `request` as the scene draws it, turned by `turnDegrees`: its object at the origin (the model's +// type, ItemObjectAttribute, the scale and angle of the pose) and the bones of `models.skeleton` in `bones`. The model +// fields it sets (the action, the body height) are the caller's to keep (ScopedModelState). +void PosePreviewItem(const EffectPreviewRequest& request, const PreviewItemModels& models, float turnDegrees, OBJECT& o, + vec34_t* bones); + // Where the camera looks and the size of what it shows. struct PreviewFraming { @@ -91,8 +103,16 @@ class EffectPreviewScene PreviewFraming Prepare(const EffectPreviewRequest& request); // Draws `request` as `camera` sees it, at the aspect width / height of - // the view. Leaves the game's render state as it was. - void Draw(const EffectPreviewRequest& request, const EffectPreviewCamera& camera, float aspect); + // the view, running `afterItem` (if set) right after the item, with the + // view's matrices. Leaves the game's render state as it was. + void Draw(const EffectPreviewRequest& request, const EffectPreviewCamera& camera, float aspect, + const std::function& afterItem = {}); + + // How far the turn has turned the item, in degrees. + float GetTurnDegrees() const + { + return m_turnDegrees; + } // The PreviewNote flags of the effect's object. std::uint16_t GetObjectNotes() const diff --git a/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.cpp b/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.cpp index 153ce5d223..ddefcfde4f 100644 --- a/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.cpp +++ b/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.cpp @@ -4,6 +4,8 @@ #include "EffectPreviewTracker.h" +#include "Render/Effects/ZzzEffect.h" + #include #include #include @@ -75,6 +77,12 @@ int SlotOf(std::span pool, const OBJECT* object) } } // namespace +void RemoveGameEffect(OBJECT& effect) +{ + RemoveObjectBlurs(&effect, 0); + EffectDestructor(&effect); +} + void EffectPreviewTracker::Fit(const EffectPools& pools) { m_keptTypes[IndexOf(EffectPool::Effect)].resize(pools.effects.size(), NotKept); @@ -244,6 +252,19 @@ void EffectPreviewTracker::Forget() } } +void EffectPreviewTracker::ForgetSlots(const std::function& notOurs) +{ + std::erase_if(m_kept, + [&](const EffectPoolSlot& slot) + { + if (!notOurs(slot)) + return false; + m_keptTypes[IndexOf(slot.pool)][static_cast(slot.index)] = NotKept; + return true; + }); + std::erase_if(m_created, notOurs); +} + EffectPreviewCounts EffectPreviewTracker::Count() const { EffectPreviewCounts counts; diff --git a/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.h b/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.h index ca07e2f9bc..fc6d92c1b4 100644 --- a/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.h +++ b/src/MuEditor/UI/EffectBrowser/EffectPreviewTracker.h @@ -5,6 +5,7 @@ #include "EffectPoolSnapshot.h" #include +#include #include namespace MuEditor::Effects @@ -16,6 +17,9 @@ struct EffectPreviewCounts int joints = 0; }; +// Removes an effect as the game does when its life ends, with its trails: what the previews pass to RemoveAll. +void RemoveGameEffect(OBJECT& effect); + // What the world preview created and what that created in turn, followed from // frame to frame, to remove it all when the preview stops. Sprites are not // kept: a sprite lives until the next RenderSprites. @@ -36,6 +40,11 @@ class EffectPreviewTracker void Update(const EffectPools& pools); // Whether a slot the last create call filled is still the preview's. bool AnyCreatedLive(const EffectPools& pools) const; + // Every slot the preview keeps, sprites left out. + const std::vector& GetKept() const + { + return m_kept; + } // The slots the last create call filled that are still the preview's, // sprites left out. const std::vector& GetCreated() const @@ -47,6 +56,9 @@ class EffectPreviewTracker void RemoveAll(const EffectPools& pools, RemoveEffect removeEffect); // Forgets everything without touching the pools. void Forget(); + // Forgets the slots `notOurs` says are no longer the tracked effects' (their things ended and the slot was + // taken again), without touching them. + void ForgetSlots(const std::function& notOurs); EffectPreviewCounts Count() const; bool IsEmpty() const diff --git a/src/MuEditor/UI/EffectBrowser/EffectWorldPreview.cpp b/src/MuEditor/UI/EffectBrowser/EffectWorldPreview.cpp index 4d4272d8ee..c6ff2e2cd2 100644 --- a/src/MuEditor/UI/EffectBrowser/EffectWorldPreview.cpp +++ b/src/MuEditor/UI/EffectBrowser/EffectWorldPreview.cpp @@ -97,13 +97,6 @@ void CopyCharacter(OBJECT& copy, const OBJECT& character, std::unique_ptr ClickedRay(const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, - const ImVec2& max) +// After the view: a left click that did not turn it gives the clicked point. The second click of a double click puts +// the view back (EffectPreviewInput) and gives none. +std::optional ClickedPoint(const ImVec2& min, const ImVec2& max) { if (!ImGui::IsItemDeactivated() || !ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { @@ -65,6 +64,20 @@ std::optional ClickedRay(const MuEditor::Effects::EffectPrevie { return std::nullopt; } + return io.MousePos; +} + +std::optional RayThrough(const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, + const ImVec2& max, const std::optional& point) +{ + if (!point) + { + return std::nullopt; + } + const float width = max.x - min.x; + const float height = max.y - min.y; + const float viewX = (point->x - min.x) / width * 2.0f - 1.0f; + const float viewY = 1.0f - (point->y - min.y) / height * 2.0f; return MeshPicking::RayThroughView(camera, width / height, viewX, viewY); } @@ -91,7 +104,7 @@ bool CItemModelPreview::ShowsListedModel(int itemType) const return ListedModelInView(itemType, m_level) != nullptr; } -void CItemModelPreview::Render(int itemType) +void CItemModelPreview::Render(int itemType, const AfterItem& afterItem) { RenderControls(); const MuEditor::Effects::EffectPreviewRequest request = MakeRequest(itemType); @@ -100,7 +113,13 @@ void CItemModelPreview::Render(int itemType) // the scrollbar show and hide by turns (as the effect browser's view). const ImGuiStyle& style = ImGui::GetStyle(); const float widthInWindow = ImGui::GetWindowWidth() - 2.0f * style.WindowPadding.x - style.ScrollbarSize; - RenderView(request, m_views[0], "##ModelView", width, ViewHeight(widthInWindow), nullptr); + View& view = m_views[0]; + std::function after; + if (afterItem) + { + after = [&afterItem, &request, &view, this] { afterItem(0, request, view.scene.GetTurnDegrees(), m_camera); }; + } + RenderView(request, view, "##ModelView", width, ViewHeight(widthInWindow), nullptr, after); } void CItemModelPreview::RenderModelSlot(int modelSlot) @@ -115,7 +134,8 @@ void CItemModelPreview::RenderModelSlot(int modelSlot) RenderView(request, m_views[0], "##ModelView", width, ViewHeight(widthInWindow), nullptr); } -void CItemModelPreview::RenderSideBySide(int itemType, int count, const Header& header, const DrawIn& drawIn) +void CItemModelPreview::RenderSideBySide(int itemType, int count, const Header& header, const DrawIn& drawIn, + const AfterItem& afterItem, const Overlay& overlay) { RenderControls(); count = std::clamp(count, 1, MaxViews); @@ -138,8 +158,22 @@ void CItemModelPreview::RenderSideBySide(int itemType, int count, const Header& const float top = ImGui::GetCursorPosY(); header(view, width); ImGui::SetCursorPosY(std::max(ImGui::GetCursorPosY(), top + ImGui::GetFrameHeightWithSpacing())); - RenderView(request, m_views[static_cast(view)], "##ModelView", width, height, - [&drawIn, view](const std::function& draw) { drawIn(view, draw); }); + View& shown = m_views[static_cast(view)]; + std::function after; + if (afterItem) + { + after = [&afterItem, &request, &shown, view, this] + { afterItem(view, request, shown.scene.GetTurnDegrees(), m_camera); }; + } + std::function over; + if (overlay) + { + over = [&overlay, &request, &shown, view, this](const ViewOnScreen& screen) + { overlay(view, request, shown.scene.GetTurnDegrees(), m_camera, screen); }; + } + RenderView( + request, shown, "##ModelView", width, height, + [&drawIn, view](const std::function& draw) { drawIn(view, draw); }, after, over); ImGui::PopID(); ImGui::EndGroup(); } @@ -198,7 +232,9 @@ float CItemModelPreview::ViewHeight(float widthInWindow) const void CItemModelPreview::RenderView(const MuEditor::Effects::EffectPreviewRequest& request, View& view, const char* id, float width, float height, - const std::function&)>& drawIn) + const std::function&)>& drawIn, + const std::function& afterItem, + const std::function& overlay) { if (width < 1.0f) { @@ -208,8 +244,11 @@ void CItemModelPreview::RenderView(const MuEditor::Effects::EffectPreviewRequest TakeBackPickOnDoubleClick(); const ImVec2 min = ImGui::GetItemRectMin(); const ImVec2 max = ImGui::GetItemRectMax(); - const std::optional pickRay = ClickedRay(m_camera, min, max); - if (ImGui::IsItemHovered() && !ImGui::IsItemActive()) + const std::optional click = ClickedPoint(min, max); + const bool hovered = ImGui::IsItemHovered(); + const std::optional pickRay = + m_meshPicking ? RayThrough(m_camera, min, max, click) : std::nullopt; + if (hovered && !ImGui::IsItemActive()) { // Over the effect browser's controls text, which RenderView set. ImGui::SetTooltip("%s %s", I18N::Editor::PreviewControls, I18N::Editor::PreviewPickNote); @@ -239,7 +278,7 @@ void CItemModelPreview::RenderView(const MuEditor::Effects::EffectPreviewRequest return; } const MuEditor::ScopedOffscreenCapture endCapture; - const auto draw = [&] { DrawScene(request, view, width / height, pickRay); }; + const auto draw = [&] { DrawScene(request, view, width / height, pickRay, afterItem); }; if (drawIn) { drawIn(draw); @@ -258,17 +297,22 @@ void CItemModelPreview::RenderView(const MuEditor::Effects::EffectPreviewRequest { ImGui::GetWindowDrawList()->AddImage((ImTextureID)(intptr_t)pointer, min, max); } + if (overlay) + { + overlay({min, max, click, hovered}); + } } void CItemModelPreview::DrawScene(const MuEditor::Effects::EffectPreviewRequest& request, View& view, float aspect, - const std::optional& pickRay) + const std::optional& pickRay, + const std::function& afterItem) { const BMD* model = ListedModelInView(request.itemType, request.itemLevel); std::optional hitMesh; { // Without the listed model the drawer leaves every draw alone. CItemMeshPreviewDrawer drawer(model, g_ItemMeshFocus.Shown(), pickRay); - view.scene.Draw(request, m_camera, aspect); + view.scene.Draw(request, m_camera, aspect, afterItem); hitMesh = drawer.HitMesh(); } // A click on another model finds none of the listed meshes, so it keeps the kept one. diff --git a/src/MuEditor/UI/ItemTools/ItemModelPreview.h b/src/MuEditor/UI/ItemTools/ItemModelPreview.h index edcaa0de72..d53ff73c5b 100644 --- a/src/MuEditor/UI/ItemTools/ItemModelPreview.h +++ b/src/MuEditor/UI/ItemTools/ItemModelPreview.h @@ -6,6 +6,7 @@ #include "../MuEditor/UI/EffectBrowser/EffectPreviewScene.h" #include "../MuEditor/UI/EffectBrowser/EffectPreviewTarget.h" #include "ItemMeshPicking.h" +#include "imgui.h" #include #include @@ -26,7 +27,13 @@ namespace MuEditor::Items class CItemModelPreview { public: - void Render(int itemType); + // Runs right after view `view` drew its item, with the view's matrices: what the view drew (`request`, turned by + // `turnDegrees`) and its camera. + using AfterItem = std::function; + + // The item in one view; `afterItem` (if set) runs in it, as view 0. + void Render(int itemType, const AfterItem& afterItem = {}); // The model of a slot that is no item's, a part model (design L50), with the same controls. void RenderModelSlot(int modelSlot); // The most views RenderSideBySide draws. @@ -35,9 +42,29 @@ class CItemModelPreview using Header = std::function; // Runs `draw`, the drawing of view `view`, inside what that view needs. using DrawIn = std::function& draw)>; + // Where a view's picture stands in the window, and the point a left click that did not turn it clicked. + struct ViewOnScreen + { + ImVec2 min; + ImVec2 max; + std::optional click; + bool hovered = false; + }; + // Runs right after view `view`'s picture is put into the window, to draw over it: what the view drew (`request`, + // turned by `turnDegrees`), its camera and where it stands. + using Overlay = + std::function; // `count` views of the item side by side (at most MaxViews), each below its `header`: one set of controls and one - // camera, so a drag in any turns all; each is drawn inside `drawIn`. - void RenderSideBySide(int itemType, int count, const Header& header, const DrawIn& drawIn); + // camera, so a drag in any turns all; each is drawn inside `drawIn`, `afterItem` (if set) runs in each and + // `overlay` (if set) over each. + void RenderSideBySide(int itemType, int count, const Header& header, const DrawIn& drawIn, + const AfterItem& afterItem = {}, const Overlay& overlay = {}); + // Whether a click in a view keeps the mesh it hits (on at first); off while a click means something else. + void SetMeshPicking(bool picking) + { + m_meshPicking = picking; + } // The item level and looks the controls chose, for the inventory grid. int GetLevel() const @@ -82,9 +109,11 @@ class CItemModelPreview // The view's height for a width the window gives it. [[nodiscard]] float ViewHeight(float widthInWindow) const; void RenderView(const MuEditor::Effects::EffectPreviewRequest& request, View& view, const char* id, float width, - float height, const std::function&)>& drawIn); + float height, const std::function&)>& drawIn, + const std::function& afterItem = {}, + const std::function& overlay = {}); void DrawScene(const MuEditor::Effects::EffectPreviewRequest& request, View& view, float aspect, - const std::optional& pickRay); + const std::optional& pickRay, const std::function& afterItem); void TakeBackPickOnDoubleClick() const; MuEditor::Effects::EffectPreviewCamera m_camera; @@ -95,6 +124,7 @@ class CItemModelPreview bool m_ancient = false; bool m_turn = false; bool m_asDoppelganger = false; + bool m_meshPicking = true; MuEditor::Effects::PreviewItemPose m_pose = MuEditor::Effects::PreviewItemPose::Inventory; // ImGui::GetTime() of the last click that picked a mesh; long ago before the first one. double m_pickTime = std::numeric_limits::lowest(); diff --git a/src/MuEditor/UI/ItemTools/MuItemModelUI.cpp b/src/MuEditor/UI/ItemTools/MuItemModelUI.cpp index 93947ffb7a..859bcd45ac 100644 --- a/src/MuEditor/UI/ItemTools/MuItemModelUI.cpp +++ b/src/MuEditor/UI/ItemTools/MuItemModelUI.cpp @@ -14,6 +14,7 @@ #include "ItemToolWindow.h" #include "../MuEditor/UI/Common/MuEditorWindowIds.h" +#include "../MuEditor/UI/StyleEditor/BoneThingsPreview.h" #include "../MuEditor/UI/StyleEditor/MuStyleEditorUI.h" #include "Data/DataHandler/ItemData/ItemDataHandler.h" #include "Data/GameData/ItemData/PartModelSlots.h" @@ -25,6 +26,7 @@ #include "Data/GameData/ItemData/ItemType.h" #include "I18N/All.h" #include "Render/Items/ItemDisplay.h" +#include "Render/Items/ItemEffects.h" #include "Render/Items/ItemRenderStyles.h" #include "Render/Models/ZzzBMD.h" #include "imgui.h" @@ -265,7 +267,17 @@ void CMuItemModelUI::RenderPreview(const ItemModelDefinition* model, int itemTyp if ((model != nullptr || drawnByCode) && ImGui::CollapsingHeader(I18N::Editor::Preview, ImGuiTreeNodeFlags_DefaultOpen)) { - m_preview.Render(itemType); + // The item's things on bones, as the Style Editor's views show them (design section 7a). + m_preview.Render(itemType, + [](int, const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, + const MuEditor::Effects::EffectPreviewCamera& camera) + { + const int drawn = MuEditor::Effects::PreviewItemModelsOf(request).model; + MuEditor::Looks::g_BoneThingsPreview.Draw( + MuEditor::Looks::BoneThingsPreview::ItemModelView, + {request, Render::Items::ItemEffects::EffectOf(drawn), turnDegrees, std::nullopt}, + camera); + }); } } diff --git a/src/MuEditor/UI/StyleEditor/BoneMarks.cpp b/src/MuEditor/UI/StyleEditor/BoneMarks.cpp new file mode 100644 index 0000000000..bb07de5b72 --- /dev/null +++ b/src/MuEditor/UI/StyleEditor/BoneMarks.cpp @@ -0,0 +1,350 @@ +#include "stdafx.h" + +#ifdef _EDITOR + +#include "BoneMarks.h" + +#include "../MuEditor/UI/EffectBrowser/EffectPreviewItems.h" +#include "../MuEditor/UI/EffectBrowser/PreviewModelPose.h" +#include "Render/Models/ZzzBMD.h" + +#include +#include +#include +#include + +namespace MuEditor::Looks::BoneMarks +{ +namespace +{ +constexpr float DotRadius = 3.0f; +constexpr float RingRadius = 8.0f; +// How far from a dot the mouse may be to point at it, in pixels before the UI scale. +constexpr float PickRadius = 7.0f; + +constexpr ImU32 DotColor = IM_COL32(235, 235, 235, 220); +constexpr ImU32 DotOutline = IM_COL32(0, 0, 0, 200); +constexpr ImU32 UsedColor = IM_COL32(255, 170, 40, 255); +constexpr ImU32 RingColor = IM_COL32(255, 230, 60, 255); +constexpr ImU32 FromColor = IM_COL32(90, 200, 255, 255); +constexpr ImU32 TextBack = IM_COL32(0, 0, 0, 170); +constexpr ImU32 LinkColor = IM_COL32(170, 170, 165, 170); +constexpr float NumberGap = 4.0f; + +void Label(ImDrawList& list, const ImVec2& at, const std::string& text, ImU32 color) +{ + const ImVec2 size = ImGui::CalcTextSize(text.c_str()); + const ImVec2 corner{at.x + RingRadius, at.y - RingRadius - size.y}; + list.AddRectFilled({corner.x - 2.0f, corner.y - 1.0f}, {corner.x + size.x + 2.0f, corner.y + size.y + 1.0f}, + TextBack, 2.0f); + list.AddText(corner, color, text.c_str()); +} +// A bone's number right beside its dot. +void Number(ImDrawList& list, const ImVec2& at, int number, float scale) +{ + const std::string text = std::to_string(number); + const ImVec2 size = ImGui::CalcTextSize(text.c_str()); + const ImVec2 corner{at.x + NumberGap * scale, at.y - NumberGap * scale - size.y}; + list.AddRectFilled({corner.x - 1.0f, corner.y}, {corner.x + size.x + 1.0f, corner.y + size.y}, TextBack, 2.0f); + list.AddText(corner, UsedColor, text.c_str()); +} +} // namespace + +void BonesOf(const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, std::vector& shown) +{ + const MuEditor::Effects::PreviewItemModels models = MuEditor::Effects::PreviewItemModelsOf(request); + if (!models.CanDraw() || models.skeleton != models.model) + { + shown.clear(); + return; + } + BMD& b = Models[models.model]; + if (b.NumBones <= 0 || b.Bones == nullptr) + { + shown.clear(); + return; + } + const MuEditor::Effects::ScopedModelState saved(b); + OBJECT o; + // The pose, made once: the marks are drawn on the editor's one thread. + static const std::unique_ptr bones = std::make_unique(MAX_BONES); + MuEditor::Effects::PosePreviewItem(request, models, turnDegrees, o, bones.get()); + const int count = std::min(b.NumBones, MAX_BONES); + // Resized, never cleared before, so the bones of the last frame and their names keep their room. + shown.resize(static_cast(count)); + for (int bone = 0; bone < count; ++bone) + { + // As the game places things on bones (TransformPosition with the model's scale), at the scene's origin. + ShownBone& entry = shown[static_cast(bone)]; + entry.number = bone; + entry.parent = b.Bones[bone].Parent; + entry.name.assign(b.Bones[bone].Name, strnlen(b.Bones[bone].Name, sizeof(b.Bones[bone].Name))); + for (int axis = 0; axis < 3; ++axis) + { + entry.place[static_cast(axis)] = bones[bone][axis][3] * o.Scale; + } + } +} + +std::optional ToScreen(const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, + const ImVec2& max, const MuEditor::Effects::PreviewVector& place) +{ + const float width = max.x - min.x; + const float height = max.y - min.y; + if (width <= 0.0f || height <= 0.0f) + { + return std::nullopt; + } + const MuEditor::Effects::EffectPreviewCamera::Basis basis = camera.GetBasis(); + const MuEditor::Effects::PreviewVector eye = camera.Eye(); + float right = 0.0f; + float up = 0.0f; + float forward = 0.0f; + for (std::size_t axis = 0; axis < 3; ++axis) + { + const float d = place[axis] - eye[axis]; + right += d * basis.right[axis]; + up += d * basis.up[axis]; + forward += d * basis.forward[axis]; + } + if (forward <= camera.Near()) + { + return std::nullopt; + } + // As MeshPicking::RayThroughView casts its rays, the other way. + const float halfHeight = std::tan(MuEditor::Effects::EffectPreviewCamera::FieldOfViewDegrees * 0.5f * + std::numbers::pi_v / 180.0f); + const float viewX = right / (forward * halfHeight * (width / height)); + const float viewY = up / (forward * halfHeight); + return ImVec2{min.x + (viewX + 1.0f) * 0.5f * width, min.y + (1.0f - viewY) * 0.5f * height}; +} + +std::optional NearestWithin(const std::vector& points, const ImVec2& mouse, float radius) +{ + std::optional nearest; + float best = radius * radius; + for (std::size_t i = 0; i < points.size(); ++i) + { + const float dx = points[i].x - mouse.x; + const float dy = points[i].y - mouse.y; + const float distance = dx * dx + dy * dy; + if (distance <= best) + { + best = distance; + nearest = i; + } + } + return nearest; +} + +bool PickBone(Data::Looks::BonePlaces& places, bool between, std::optional& from, int bone) +{ + if (!between) + { + from.reset(); + if (const auto at = std::ranges::find(places.bones, bone); at != places.bones.end()) + { + places.bones.erase(at); + } + else + { + places.bones.push_back(bone); + } + return true; + } + if (!from) + { + from = bone; + return false; + } + const int start = *from; + from.reset(); + if (start == bone) + { + return false; + } + const std::pair pair{start, bone}; + if (const auto at = std::ranges::find(places.between, pair); at != places.between.end()) + { + places.between.erase(at); + } + else + { + places.between.push_back(pair); + } + return true; +} + +bool PickTakeBack::Pick(Data::Looks::BonePlaces& places, bool between, std::optional& from, int bone, double time) +{ + m_places = places; + m_from = from; + m_time = time; + return PickBone(places, between, from, bone); +} + +bool PickTakeBack::TakeBack(Data::Looks::BonePlaces& places, std::optional& from, double time, + double doubleClickTime) +{ + if (!m_places || time - m_time > doubleClickTime) + { + return false; + } + places = *m_places; + from = m_from; + m_places.reset(); + return true; +} + +std::optional Draw(const std::vector& bones, const Marks& marks, + const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, const ImVec2& max, + const std::optional& click, bool hovered) +{ + // Reused each frame (the marks are drawn on the editor's one thread), so drawing allocates nothing once they grew. + static std::vector points; + static std::vector seen; + static std::vector seenPoints; + static std::vector seenBones; + static std::vector used; + points.assign(bones.size(), ImVec2{}); + seen.assign(bones.size(), false); + seenPoints.clear(); + seenBones.clear(); + for (std::size_t i = 0; i < bones.size(); ++i) + { + if (const std::optional point = ToScreen(camera, min, max, bones[i].place)) + { + points[i] = *point; + seen[i] = true; + seenPoints.push_back(*point); + seenBones.push_back(i); + } + } + const auto placeOf = [&](int bone) -> std::optional + { + if (bone < 0 || static_cast(bone) >= bones.size() || !seen[static_cast(bone)]) + { + return std::nullopt; + } + return points[static_cast(bone)]; + }; + + ImDrawList& list = *ImGui::GetWindowDrawList(); + list.PushClipRect(min, max, true); + // The marks grow with the editor's font. + const float scale = std::max(1.0f, ImGui::GetFontSize() / 13.0f); + // The bones the picked entry names, at bones or in its pairs. + used.assign(marks.bones.begin(), marks.bones.end()); + for (const auto& [start, end] : marks.pairs) + { + used.push_back(start); + used.push_back(end); + } + std::ranges::sort(used); + const auto [last, end] = std::ranges::unique(used); + used.erase(last, end); + const auto isUsed = [&](int bone) { return std::ranges::binary_search(used, bone); }; + if (marks.dots) + { + // The skeleton: each bone joined to the one it hangs on, the picked entry's in its color. + for (const ShownBone& bone : bones) + { + const std::optional child = placeOf(bone.number); + const std::optional parent = placeOf(bone.parent); + if (child && parent) + { + const bool picked = isUsed(bone.number); + list.AddLine(*parent, *child, picked ? UsedColor : LinkColor, picked ? 1.6f : 1.0f); + } + } + for (const ImVec2& point : seenPoints) + { + list.AddCircleFilled(point, DotRadius * scale + 1.0f, DotOutline); + list.AddCircleFilled(point, DotRadius * scale, DotColor); + } + } + for (const auto& [start, end] : marks.pairs) + { + const std::optional a = placeOf(start); + const std::optional b = placeOf(end); + if (a && b) + { + list.AddLine(*a, *b, UsedColor, 1.5f); + // The end: where the lightning goes. + list.AddCircle(*b, DotRadius * scale + 2.0f, UsedColor, 0, 1.5f); + } + } + for (const int bone : marks.bones) + { + if (const std::optional point = placeOf(bone)) + { + list.AddCircleFilled(*point, DotRadius * scale + 1.0f, UsedColor); + } + } + for (const auto& [start, end] : marks.pairs) + { + for (const int bone : {start, end}) + { + if (const std::optional point = placeOf(bone)) + { + list.AddCircleFilled(*point, DotRadius * scale + 1.0f, UsedColor); + } + } + } + // The picked entry's bones with their numbers; a ringed one gets its own. + for (const int bone : used) + { + if (bone == marks.ringed || bone == marks.from) + { + continue; + } + if (const std::optional point = placeOf(bone)) + { + Number(list, *point, bone, scale); + } + } + if (marks.from) + { + if (const std::optional point = placeOf(*marks.from)) + { + list.AddCircle(*point, RingRadius * scale, FromColor, 0, 2.0f); + Label(list, *point, std::to_string(*marks.from), FromColor); + } + } + if (marks.ringed) + { + if (const std::optional point = placeOf(*marks.ringed)) + { + list.AddCircle(*point, RingRadius * scale, RingColor, 0, 2.0f); + Label(list, *point, std::to_string(*marks.ringed), RingColor); + } + } + std::optional hit; + if (marks.dots) + { + const float radius = PickRadius * scale; + if (hovered) + { + if (const std::optional under = NearestWithin(seenPoints, ImGui::GetIO().MousePos, radius)) + { + const ShownBone& bone = bones[seenBones[*under]]; + list.AddCircle(seenPoints[*under], RingRadius * scale, DotColor, 0, 1.5f); + Label(list, seenPoints[*under], + bone.name.empty() ? std::to_string(bone.number) : std::to_string(bone.number) + " " + bone.name, + DotColor); + } + } + if (click) + { + if (const std::optional under = NearestWithin(seenPoints, *click, radius)) + { + hit = bones[seenBones[*under]].number; + } + } + } + list.PopClipRect(); + return hit; +} +} // namespace MuEditor::Looks::BoneMarks + +#endif // _EDITOR diff --git a/src/MuEditor/UI/StyleEditor/BoneMarks.h b/src/MuEditor/UI/StyleEditor/BoneMarks.h new file mode 100644 index 0000000000..85e863e419 --- /dev/null +++ b/src/MuEditor/UI/StyleEditor/BoneMarks.h @@ -0,0 +1,85 @@ +#pragma once + +#ifdef _EDITOR + +#include "../MuEditor/UI/EffectBrowser/EffectPreviewCamera.h" +#include "../MuEditor/UI/EffectBrowser/EffectPreviewScene.h" +#include "Data/GameData/LookData/LookDefinition.h" +#include "imgui.h" + +#include +#include +#include + +// The bones of the item a preview view shows, marked over the view (design L58): every bone as a dot joined to the +// bone it hangs on by a line, with its number and name on hover ("Show bones"), the bones of the picked entry of an +// item effect's things on bones, the bone the mouse points at in the entry's fields ringed with its number, and the +// pick mode that adds or removes a bone by clicking its dot. +namespace MuEditor::Looks::BoneMarks +{ +// A bone of the shown item: its number and name, and where the view's scene has it. +struct ShownBone +{ + int number = 0; + // The bone it hangs on, -1 for a root: the marks join them with a line (design L58). + int parent = -1; + std::string name; + MuEditor::Effects::PreviewVector place{}; +}; + +// The bones of the item of `request` as its view poses it, turned by `turnDegrees`, at the scene's origin, into +// `shown` (whose room and names are reused each frame); none for an item drawn on another skeleton (armor), whose +// things on bones the game creates nowhere. +void BonesOf(const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, std::vector& shown); + +// Where `place` shows in a view standing at `min` to `max` in the window, as `camera` sees it; nullopt behind the eye. +std::optional ToScreen(const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, + const ImVec2& max, const MuEditor::Effects::PreviewVector& place); + +// The index in `points` of the one nearest `mouse` within `radius` pixels; nullopt for none. +std::optional NearestWithin(const std::vector& points, const ImVec2& mouse, float radius); + +// A click on bone `bone` in pick mode: at bones (`between` false) it adds the bone or takes it out; between bones the +// first click is the lightning's start (`from`), the second its end, which adds the pair or, when the entry has it, +// takes it out; a second click on the start lets it go. True when the places changed. +bool PickBone(Data::Looks::BonePlaces& places, bool between, std::optional& from, int bone); + +// The pick mode's clicks, which a double click (it puts the view back) takes back as a mesh pick's +// (CItemMeshFocus::TakeBackPick): each pick keeps the places and pair start it changed, and when. +class PickTakeBack +{ +public: + // PickBone at `time`, keeping what was before it. + bool Pick(Data::Looks::BonePlaces& places, bool between, std::optional& from, int bone, double time); + // A double click at `time`: puts back what the last pick changed when it came at most `doubleClickTime` before, + // once. True when it put something back. + bool TakeBack(Data::Looks::BonePlaces& places, std::optional& from, double time, double doubleClickTime); + +private: + std::optional m_places; + std::optional m_from; + double m_time = 0.0; +}; + +// What the marks of a view show. +struct Marks +{ + // Every bone as a dot ("Show bones" or the pick mode). + bool dots = false; + // The bones the picked entry names, and its pairs, drawn as lines from start to end; each with its number. + std::vector bones; + std::vector> pairs; + // The bone the entry's fields point at, ringed with its number. + std::optional ringed; + // The start of a pair being picked. + std::optional from; +}; + +// Draws the marks over the view standing at `min` to `max`; returns the bone a click (`click`) hit, if any. With +// `hovered`, the dot under the mouse shows its number and name. +std::optional Draw(const std::vector& bones, const Marks& marks, + const MuEditor::Effects::EffectPreviewCamera& camera, const ImVec2& min, const ImVec2& max, + const std::optional& click, bool hovered); +} // namespace MuEditor::Looks::BoneMarks + +#endif // _EDITOR diff --git a/src/MuEditor/UI/StyleEditor/BoneThingsPreview.cpp b/src/MuEditor/UI/StyleEditor/BoneThingsPreview.cpp new file mode 100644 index 0000000000..f365859084 --- /dev/null +++ b/src/MuEditor/UI/StyleEditor/BoneThingsPreview.cpp @@ -0,0 +1,393 @@ +#include "stdafx.h" + +#ifdef _EDITOR + +#include "BoneThingsPreview.h" + +#include "WorldTimeScope.h" + +#include "../MuEditor/UI/EffectBrowser/EffectWorldPreview.h" +#include "../MuEditor/UI/EffectBrowser/PreviewModelPose.h" +#include "../MuEditor/UI/ItemTools/ItemModelPreview.h" +#include "Audio/EditorSoundMute.h" +#include "Camera/CameraState.h" +#include "Core/Globals/_define.h" +#include "Engine/Object/ZzzCharacter.h" +#include "Render/Effects/PreviewSlots.h" +#include "Render/Effects/ZzzEffect.h" +#include "Render/Models/ZzzBMD.h" +#include "Render/Renderer/MuRenderer.h" +#include "Render/Textures/ZzzOpenglUtil.h" + +#include +#include + +namespace MuEditor::Looks +{ +static_assert(BoneThingsPreview::ItemModelView == MuEditor::Items::CItemModelPreview::MaxViews, + "the Item Model window's view comes after the Style Editor's, which are as many as a preview shows"); +static_assert(BoneThingsPreview::MaxViews == BoneThingsPreview::ItemModelView + 1, + "the Item Model window's view is the last"); +BoneThingsPreview g_BoneThingsPreview; + +namespace +{ +using MuEditor::Effects::EffectPool; +using MuEditor::Effects::EffectPools; +using MuEditor::Effects::EffectPoolSlot; +using Render::Effects::PreviewSlots::List; + +// The mark of a view's slots: 0 is the game's. +Render::Effects::PreviewSlots::View MarkOf(int view) +{ + return static_cast(view + 1); +} + +// The effect with its sprites only: what a view creates while its time is stopped (design L54). Its light stays. +Data::Looks::LookDefinition SpritesOnly(const Data::Looks::LookDefinition& effect) +{ + Data::Looks::LookDefinition sprites = effect; + sprites.animationSpeed.reset(); + for (Data::Looks::OnBones& entry : sprites.onBones) + { + std::erase_if(entry.things, [](const Data::Looks::BoneThing& thing) + { return thing.kind != Data::Looks::BoneThingKind::Sprite; }); + } + std::erase_if(sprites.onBones, [](const Data::Looks::OnBones& entry) { return entry.things.empty(); }); + return sprites; +} + +template int CountFree(std::span pool) +{ + return static_cast(std::ranges::count_if(pool, [](const Object& object) { return !object.Live; })); +} + +// The sprite slots live now that weren't before. +void NewSprites(std::span sprites, const std::vector& liveBefore, std::vector& created) +{ + created.clear(); + for (std::size_t i = 0; i < sprites.size(); ++i) + { + if (sprites[i].Live && !liveBefore[i]) + { + created.push_back(static_cast(i)); + } + } +} + +// The list and index of a pool's slot as the marks count them. +std::pair MarkedSlot(const EffectPoolSlot& slot) +{ + switch (slot.pool) + { + case EffectPool::Effect: + return {List::Effect, slot.index}; + case EffectPool::SkillEffect: + // RenderEffects counts the skill effects after the effects. + return {List::Effect, MAX_EFFECTS + slot.index}; + case EffectPool::Particle: + return {List::Particle, slot.index}; + case EffectPool::Joint: + return {List::Joint, slot.index}; + case EffectPool::Sprite: + break; + } + return {List::Sprite, slot.index}; +} + +void MarkSlot(const EffectPoolSlot& slot, Render::Effects::PreviewSlots::View view) +{ + const auto [list, index] = MarkedSlot(slot); + Render::Effects::PreviewSlots::Mark(list, index, view); +} + +// Takes the view's mark off a slot it no longer keeps: the slot is the game's again. A slot a create call took again +// (PreviewSlots::Born) or another view marked keeps its mark. +void UnmarkSlot(List list, int index, Render::Effects::PreviewSlots::View view) +{ + if (Render::Effects::PreviewSlots::ViewOf(list, index) == view) + { + Render::Effects::PreviewSlots::Mark(list, index, 0); + } +} + +void UnmarkSlots(const std::vector& slots, Render::Effects::PreviewSlots::View view) +{ + for (const EffectPoolSlot& slot : slots) + { + const auto [list, index] = MarkedSlot(slot); + UnmarkSlot(list, index, view); + } +} +} // namespace + +void BoneThingsPreview::Draw(int view, const BoneThingsShown& shown, + const MuEditor::Effects::EffectPreviewCamera& camera) +{ + if (view < 0 || view >= MaxViews) + { + return; + } + ViewThings& things = m_views[static_cast(view)]; + things.updatesSinceDraw = 0; + things.request = shown.request; + things.turnDegrees = shown.turnDegrees; + things.stoppedAt = shown.stoppedAt; + // From the next move on, not one update later: what lives a frame (the Wings of Darkness' lightning) stops as it + // is instead of ending before the update sees the time stopped. + Render::Effects::PreviewSlots::SetStopped(MarkOf(view), shown.stoppedAt.has_value()); + // The effect is copied (and its types found) only when it changes, not every frame. + const bool same = shown.effect == nullptr ? !things.effect.has_value() + : things.effect.has_value() && *things.effect == *shown.effect; + if (!same) + { + ++things.effectVersion; + things.effect.reset(); + things.types.clear(); + things.spritesOnly = {}; + things.spriteTypes.clear(); + if (shown.effect != nullptr) + { + things.effect = *shown.effect; + things.types = Render::Items::Looks::ResolveBoneThingTypes(*things.effect); + things.spritesOnly = SpritesOnly(*things.effect); + things.spriteTypes = Render::Items::Looks::ResolveBoneThingTypes(things.spritesOnly); + } + } + things.shown = {MuEditor::Effects::PreviewItemModelsOf(shown.request).model, shown.request.itemPose, + things.effectVersion}; + if (!things.tracker.IsEmpty() || !things.sprites.empty()) + { + Capture(view, things, camera); + } +} + +void BoneThingsPreview::Update() +{ + const EffectPools pools = MuEditor::Effects::GetGamePools(); + const bool ready = MuEditor::Effects::IsWorldReadyForPreview(); + for (int view = 0; view < MaxViews; ++view) + { + ViewThings& things = m_views[static_cast(view)]; + for (const int sprite : things.sprites) + { + UnmarkSlot(List::Sprite, sprite, MarkOf(view)); + } + things.sprites.clear(); + } + // Every view forgets what ended before any creates: a slot one view's thing left can be filled by another view's + // of the same type, which the first would take for its own. + std::array creates{}; + for (int view = 0; view < MaxViews; ++view) + { + ViewThings& things = m_views[static_cast(view)]; + const bool drawn = things.updatesSinceDraw < UpdatesWithoutDraw; + things.updatesSinceDraw = std::min(things.updatesSinceDraw + 1, UpdatesWithoutDraw); + // A slot whose thing ended and that a create call took again (PreviewSlots::Born) is not the view's any more, + // even with a thing of the same type in it: the game's own lightning, which the game creates while a view's + // lightning of a frame ends. It is neither drawn by the view nor removed with its things. + things.tracker.ForgetSlots( + [view](const EffectPoolSlot& slot) + { + const auto [list, index] = MarkedSlot(slot); + return Render::Effects::PreviewSlots::ViewOf(list, index) != MarkOf(view); + }); + if (!ready || !drawn || (things.made && *things.made != things.shown)) + { + Remove(things, view); + } + Render::Effects::PreviewSlots::SetStopped(MarkOf(view), drawn && things.stoppedAt.has_value()); + if (ready && drawn) + { + m_keptBefore.assign(things.tracker.GetKept().begin(), things.tracker.GetKept().end()); + things.tracker.Update(pools); + const std::vector& kept = things.tracker.GetKept(); + for (const EffectPoolSlot& slot : m_keptBefore) + { + if (std::ranges::find(kept, slot) == kept.end()) + { + const auto [list, index] = MarkedSlot(slot); + UnmarkSlot(list, index, MarkOf(view)); + } + } + creates[static_cast(view)] = true; + } + } + for (int view = 0; view < MaxViews; ++view) + { + if (creates[static_cast(view)] && HasRoom()) + { + Create(m_views[static_cast(view)], pools); + } + } + for (int view = 0; view < MaxViews; ++view) + { + const ViewThings& things = m_views[static_cast(view)]; + for (const EffectPoolSlot& slot : things.tracker.GetKept()) + { + MarkSlot(slot, MarkOf(view)); + } + for (const int sprite : things.sprites) + { + Render::Effects::PreviewSlots::Mark(List::Sprite, sprite, MarkOf(view)); + } + } +} + +void BoneThingsPreview::OnWorldClearing() +{ + RemoveAll(); +} + +void BoneThingsPreview::RemoveAll() +{ + for (int view = 0; view < MaxViews; ++view) + { + Remove(m_views[static_cast(view)], view); + } + Render::Effects::PreviewSlots::Clear(); +} + +MuEditor::Effects::EffectPreviewCounts BoneThingsPreview::GetCounts(int view) const +{ + if (view < 0 || view >= MaxViews) + { + return {}; + } + return m_views[static_cast(view)].tracker.Count(); +} + +void BoneThingsPreview::Remove(ViewThings& things, int view) +{ + UnmarkSlots(things.tracker.GetKept(), MarkOf(view)); + for (const int sprite : things.sprites) + { + UnmarkSlot(List::Sprite, sprite, MarkOf(view)); + } + if (!things.tracker.IsEmpty()) + { + things.tracker.RemoveAll(MuEditor::Effects::GetGamePools(), &MuEditor::Effects::RemoveGameEffect); + } + for (const int sprite : things.sprites) + { + Sprites[sprite].Live = false; + } + things.sprites.clear(); + things.made.reset(); +} + +// The view's item, posed as the view draws it, at the character; its effect creates this frame's things there. +void BoneThingsPreview::Create(ViewThings& things, const EffectPools& pools) +{ + const MuEditor::Effects::PreviewItemModels models = MuEditor::Effects::PreviewItemModelsOf(things.request); + // While the time is stopped, what the view made stays as it was and only the sprites (made from the clock) come + // again; a view that has made nothing yet (its item, pose or effect just changed) makes all once, to stop on. + const bool spritesOnly = things.stoppedAt && things.made; + const Data::Looks::LookDefinition* effect = spritesOnly ? &things.spritesOnly : nullptr; + const Render::Items::Looks::BoneThingTypes* types = spritesOnly ? &things.spriteTypes : &things.types; + if (!spritesOnly && things.effect) + { + effect = &*things.effect; + } + // Armor is drawn on the character skeleton: the game creates nothing for it on the ground either. + if (effect == nullptr || Hero == nullptr || !models.CanDraw() || models.skeleton != models.model) + { + return; + } + if (!things.bones) + { + things.bones = std::make_unique(MAX_BONES); + } + BMD& b = Models[models.model]; + const MuEditor::Effects::ScopedModelState savedModel(b); + OBJECT& o = things.object; + MuEditor::Effects::PosePreviewItem(things.request, models, things.turnDegrees, o, things.bones.get()); + o.Live = true; + o.Owner = nullptr; + o.BoneTransform = things.bones.get(); + VectorCopy(Hero->Object.Position, o.Position); + things.place = {o.Position[0], o.Position[1], o.Position[2]}; + b.BodyScale = o.Scale; + VectorCopy(o.Position, b.BodyOrigin); + + m_spritesBefore.resize(pools.sprites.size()); + for (std::size_t i = 0; i < pools.sprites.size(); ++i) + { + m_spritesBefore[i] = pools.sprites[i].Live; + } + { + // The views play no sound effects, as the world preview. + const Audio::EditorMute::Scope mute; + const WorldTimeScope time(things.stoppedAt); + things.tracker.BeginCreate(pools); + Render::Items::Looks::SpawnItemEffect(*effect, *types, &b, &o, things.bones.get()); + things.tracker.EndCreate(pools); + } + NewSprites(pools.sprites, m_spritesBefore, things.sprites); + things.made = things.shown; +} + +// The view's things, drawn as its camera sees them: the view drew its item at the scene's origin, its things stand +// around the copy at the character, so the camera is moved there. The draw loops draw only the view's slots, with no +// test against the world's view, and the world's per-frame sprite marks are kept. +void BoneThingsPreview::Capture(int view, const ViewThings& things, + const MuEditor::Effects::EffectPreviewCamera& camera) +{ + std::array matrix = camera.View(); + for (int row = 0; row < 4; ++row) + { + matrix[12 + row] -= + matrix[row] * things.place[0] + matrix[4 + row] * things.place[1] + matrix[8 + row] * things.place[2]; + } + mu::IMuRenderer& renderer = mu::GetRenderer(); + renderer.SetMatrixMode(GL_MODELVIEW); + renderer.PushMatrix(); + renderer.LoadMatrix(matrix.data()); + // Kept here, not in SaveCameraPerspective's one slot, which the game's item windows use. + const CameraState worldCamera = g_Camera; + for (int row = 0; row < 3; ++row) + { + for (int column = 0; column < 4; ++column) + { + g_Camera.Matrix[row][column] = matrix[column * 4 + row]; + } + } + const SpriteDrawFlags worldSprites = SpritesDrawnThisFrame(); + { + const Render::Effects::PreviewSlots::CaptureScope capture(MarkOf(view)); + BeginSpriteDraws(); + RenderJoints(); + RenderEffects(); + BeginSprite(); + RenderSprites(); + RenderParticles(); + EndSprite(); + } + SetSpritesDrawnThisFrame(worldSprites); + g_Camera = worldCamera; + renderer.SetMatrixMode(GL_MODELVIEW); + renderer.PopMatrix(); +} + +bool BoneThingsPreview::HasRoom() const +{ + const EffectPools pools = MuEditor::Effects::GetGamePools(); + MuEditor::Effects::EffectPreviewCounts ours; + int ourSprites = 0; + for (const ViewThings& things : m_views) + { + const MuEditor::Effects::EffectPreviewCounts counts = things.tracker.Count(); + ours.effects += counts.effects; + ours.particles += counts.particles; + ours.joints += counts.joints; + ourSprites += static_cast(things.sprites.size()); + } + const auto fits = [](int size, int free, int used) { return free >= size / 4 && used < size / 4; }; + return fits(static_cast(pools.effects.size()), CountFree(pools.effects), ours.effects) && + fits(static_cast(pools.particles.size()), CountFree(pools.particles), ours.particles) && + fits(static_cast(pools.joints.size()), CountFree(pools.joints), ours.joints) && + fits(static_cast(pools.sprites.size()), CountFree(pools.sprites), ourSprites); +} +} // namespace MuEditor::Looks + +#endif // _EDITOR diff --git a/src/MuEditor/UI/StyleEditor/BoneThingsPreview.h b/src/MuEditor/UI/StyleEditor/BoneThingsPreview.h new file mode 100644 index 0000000000..d04bd49008 --- /dev/null +++ b/src/MuEditor/UI/StyleEditor/BoneThingsPreview.h @@ -0,0 +1,116 @@ +#pragma once + +#ifdef _EDITOR + +#include "../MuEditor/UI/EffectBrowser/EffectPreviewCamera.h" +#include "../MuEditor/UI/EffectBrowser/EffectPreviewScene.h" +#include "../MuEditor/UI/EffectBrowser/EffectPreviewTracker.h" +#include "Data/GameData/LookData/LookDefinition.h" +#include "Engine/Object/w_ObjectInfo.h" +#include "Render/Items/LookDrawing.h" + +#include +#include +#include +#include + +namespace MuEditor::Looks +{ +// What a view of the Style Editor's preview drew, for its things on bones. +struct BoneThingsShown +{ + MuEditor::Effects::EffectPreviewRequest request; + // The item effect the view's item runs (Render::Items::ItemEffects::EffectOf while the view draws); nullptr: none. + const Data::Looks::LookDefinition* effect = nullptr; + // How far the view's turn has turned the item. + float turnDegrees = 0.0f; + // The preview's stopped time, in milliseconds of WorldTime; nullopt while time runs. + std::optional stoppedAt; +}; + +// The things on bones of the items the Style Editor's preview and the Item Model window's preview show (FX1.7c, design +// section 7a, L51 to L54). Each view +// keeps its own copy of the item object with its own bones at the player's character (L52, L53); in the game's update +// it creates the things its item effect creates there, with the game's own calls into the game's effect lists, which +// move them as in the game. Their slots carry the view's mark (Render::Effects::PreviewSlots): the world doesn't draw +// them, and the view draws only its own, right after its item, with its camera. While the preview's time stops the +// game moves none of a view's things and the view creates only its sprites and light, made from the stopped clock +// (L54). A view's things are removed when its item or effect changes, when it is no longer drawn, and when the world +// is cleared. The game comes first: a view creates nothing while a list has less than a quarter of its slots free, +// and the views together keep to a quarter of each list. +class BoneThingsPreview +{ +public: + // The Style Editor's three views, then the Item Model window's. + static constexpr int MaxViews = 4; + static constexpr int ItemModelView = 3; + // How many of the game's updates a view's things live on without the view being drawn: the editor's windows skip + // frames the GPU is behind on. + static constexpr int UpdatesWithoutDraw = 10; + + // In view `view`'s draw, right after its item, with the view's matrices: keeps what the view shows for the next + // update and draws the view's things with `camera`. + void Draw(int view, const BoneThingsShown& shown, const MuEditor::Effects::EffectPreviewCamera& camera); + // Once a frame in the game's update (Core::EffectSpawnHook): removes what is no longer shown, takes in what the + // views' things created, and creates this frame's things. + void Update(); + // The game is about to clear its effect lists. + void OnWorldClearing(); + // Removes every view's things. + void RemoveAll(); + + MuEditor::Effects::EffectPreviewCounts GetCounts(int view) const; + +private: + // What a view's things were made for: when it changes they are removed. + struct Made + { + int model = -1; + MuEditor::Effects::PreviewItemPose pose = MuEditor::Effects::PreviewItemPose::Inventory; + int effectVersion = 0; + + bool operator==(const Made&) const = default; + }; + + struct ViewThings + { + MuEditor::Effects::EffectPreviewTracker tracker; + // The view's copy of the item: the owner and target of its things. + OBJECT object; + std::unique_ptr bones; + // What the view showed last. + MuEditor::Effects::EffectPreviewRequest request; + float turnDegrees = 0.0f; + std::optional stoppedAt; + Made shown; + // What its things were made for, while it has any. + std::optional made; + // The effect it draws, and the same with its sprites only (time stopped), each with its catalogue types. + std::optional effect; + Render::Items::Looks::BoneThingTypes types; + Data::Looks::LookDefinition spritesOnly; + Render::Items::Looks::BoneThingTypes spriteTypes; + int effectVersion = 0; + // The sprite slots the last update created: a sprite lives one frame. + std::vector sprites; + // Where the item stood in the last update: the view draws its things around it. + MuEditor::Effects::PreviewVector place{}; + int updatesSinceDraw = UpdatesWithoutDraw; + }; + + void Remove(ViewThings& things, int view); + void Create(ViewThings& things, const MuEditor::Effects::EffectPools& pools); + static void Capture(int view, const ViewThings& things, const MuEditor::Effects::EffectPreviewCamera& camera); + bool HasRoom() const; + + std::array m_views; + // Reused by each update, so it allocates nothing once they have grown: the sprite slots that lived before a view + // created its things, and the slots a view kept before the update. + std::vector m_spritesBefore; + std::vector m_keptBefore; +}; + +extern BoneThingsPreview g_BoneThingsPreview; +} // namespace MuEditor::Looks + +#endif // _EDITOR diff --git a/src/MuEditor/UI/StyleEditor/LookFields.cpp b/src/MuEditor/UI/StyleEditor/LookFields.cpp index 1fcfc2060a..5a3bf61617 100644 --- a/src/MuEditor/UI/StyleEditor/LookFields.cpp +++ b/src/MuEditor/UI/StyleEditor/LookFields.cpp @@ -7,8 +7,12 @@ #include "../MuEditor/Core/MuEditorCore.h" #include "../MuEditor/UI/ItemTools/ItemTextInput.h" #include "Data/GameData/Common/MeshLimits.h" +#include "Data/GameData/EffectData/EffectTypeCatalogue.h" +#include "Data/GameData/LookData/BoneThingTypes.h" +#include "Data/GameData/LookData/LookJson.h" #include "I18N/All.h" #include "Render/Items/LookDrawing.h" +#include "Render/Models/ZzzBMD.h" #include "imgui.h" #include @@ -169,6 +173,7 @@ const Names& BlendNames() { static const Names names{{Blend::Normal, &I18N::Editor::Normal}, {Blend::Glow, &I18N::Editor::Glow}, + {Blend::Darken, &I18N::Editor::Darken}, {Blend::AsDrawing, &I18N::Editor::AsTheDrawingAsks}}; return names; } @@ -177,6 +182,7 @@ const Names& BlendTips() { static const Names tips{{Blend::Normal, &I18N::Editor::BlendNormalTooltip}, {Blend::Glow, &I18N::Editor::BlendGlowTooltip}, + {Blend::Darken, &I18N::Editor::BlendDarkenTooltip}, {Blend::AsDrawing, &I18N::Editor::BlendAsTheDrawingAsksTooltip}}; return tips; } @@ -452,6 +458,16 @@ bool ValueField(const char* label, Value& value, const char* tip, bool drawing, changed |= ImGui::DragFloat("##Number", number, ValueSpeed, 0.0f, 0.0f, "%.7g"); Tip(tip, true); } + else if (FromItem* fromItem = std::get_if(&value)) + { + // The item's value times a number (design L59), 1 for the item's as it is. + ImGui::SameLine(); + ImGui::TextUnformatted("x"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(Scaled(NumberWidth)); + changed |= ImGui::DragFloat("##Times", &fromItem->times, ValueSpeed, 0.0f, 0.0f, "%.7g"); + Tip(tip, true); + } else if (Shape* shape = std::get_if(&value)) { changed |= ShapeFields(*shape, item); @@ -1540,6 +1556,448 @@ std::string DescribeItemValuesBefore(const Data::Looks::ItemValuesBefore& entry) return text.empty() ? std::string(I18N::Editor::None) : text; } +namespace +{ +// A bone number field's width before the UI scale, and the most bones a model has. +constexpr float BoneWidth = 45.0f; +constexpr int LastBone = Data::MaxModelBones - 1; +constexpr float MaxAnimationSpeed = 10.0f; +// The slowest speed too: the files take only speeds above 0. +constexpr float AnimationSpeedStep = 0.005f; +constexpr float NewAnimationSpeed = 0.25f; +constexpr int NewOneIn = 2; + +const Names& BoneThingKindNames() +{ + static const Names names{{BoneThingKind::Sprite, &I18N::Editor::BoneThingSprite}, + {BoneThingKind::Particle, &I18N::Editor::BoneThingParticle}, + {BoneThingKind::Joint, &I18N::Editor::BoneThingLightning}, + {BoneThingKind::Effect, &I18N::Editor::BoneThingEffect}}; + return names; +} + +const Names& ChanceDrawNames() +{ + static const Names names{{ChanceDraw::Fps, &I18N::Editor::ChanceAtTheFrameRate}, + {ChanceDraw::Plain, &I18N::Editor::ChancePlain}}; + return names; +} + +const Names& ChanceDrawTips() +{ + static const Names tips{{ChanceDraw::Fps, &I18N::Editor::ChanceAtTheFrameRateTooltip}, + {ChanceDraw::Plain, &I18N::Editor::ChancePlainTooltip}}; + return tips; +} + +enum class PlaceMode +{ + Bones, + Between, + Origin, +}; + +// Puts the next item on this line while `width` more fits, else on the next. +void SameLineIfFits(float width) +{ + ImGui::SameLine(); + const float right = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x; + if (ImGui::GetCursorScreenPos().x + width > right) + { + ImGui::NewLine(); + } +} + +// One bone by its number; `pointed` gets it while the mouse is on it or it is typed into, for the preview's ring. +bool BoneNumber(const char* id, int& bone, std::optional& pointed) +{ + ImGui::SetNextItemWidth(Scaled(BoneWidth)); + const bool changed = ImGui::InputInt(id, &bone, 0, 0); + if (changed) + { + bone = std::clamp(bone, 0, LastBone); + } + if (ImGui::IsItemHovered() || ImGui::IsItemActive()) + { + pointed = bone; + } + Tip(I18N::Editor::BoneNumberTooltip); + return changed; +} + +bool BonesField(std::vector& bones, std::optional& pointed) +{ + bool changed = false; + std::optional takenOut; + const ImGuiStyle& style = ImGui::GetStyle(); + const float itemWidth = Scaled(BoneWidth) + ImGui::GetFrameHeight() + style.ItemSpacing.x; + for (std::size_t i = 0; i < bones.size(); ++i) + { + ImGui::PushID(static_cast(i)); + if (i > 0) + { + SameLineIfFits(itemWidth); + } + ImGui::BeginGroup(); + changed |= BoneNumber("##Bone", bones[i], pointed); + ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); + if (ImGui::SmallButton(I18N::Editor::TakeOut)) + { + takenOut = i; + } + ImGui::EndGroup(); + ImGui::PopID(); + } + if (!bones.empty()) + { + SameLineIfFits(ImGui::CalcTextSize(I18N::Editor::AddBone).x + 2.0f * style.FramePadding.x); + } + if (ImGui::SmallButton(I18N::Editor::AddBone)) + { + bones.push_back(bones.empty() ? 0 : std::min(bones.back() + 1, LastBone)); + changed = true; + } + if (takenOut) + { + bones.erase(bones.begin() + static_cast(*takenOut)); + changed = true; + } + return changed; +} + +bool PairsField(std::vector>& pairs, std::optional& pointed) +{ + bool changed = false; + std::optional takenOut; + const float inner = ImGui::GetStyle().ItemInnerSpacing.x; + for (std::size_t i = 0; i < pairs.size(); ++i) + { + ImGui::PushID(static_cast(i)); + changed |= BoneNumber("##From", pairs[i].first, pointed); + ImGui::SameLine(0.0f, inner); + ImGui::TextUnformatted("->"); + ImGui::SameLine(0.0f, inner); + changed |= BoneNumber("##To", pairs[i].second, pointed); + ImGui::SameLine(0.0f, inner); + if (ImGui::SmallButton(I18N::Editor::TakeOut)) + { + takenOut = i; + } + ImGui::PopID(); + } + if (ImGui::SmallButton(I18N::Editor::AddBonePair)) + { + pairs.push_back(pairs.empty() ? std::pair{0, 1} : pairs.back()); + changed = true; + } + if (takenOut) + { + pairs.erase(pairs.begin() + static_cast(*takenOut)); + changed = true; + } + return changed; +} + +// A chance per frame (design L56); `forEach` offers rolling once for all bones or pairs. +bool ChanceFields(const char* label, std::optional& chance, bool forEach) +{ + namespace Text = I18N::Editor; + ImGui::PushID(label); + bool set = chance.has_value(); + bool changed = false; + if (ImGui::Checkbox(label, &set)) + { + chance = set ? std::optional(Chance{.oneIn = NewOneIn}) : std::nullopt; + changed = true; + } + Tip(Text::ChanceTooltip); + if (chance) + { + ImGui::Indent(); + ImGui::SetNextItemWidth(Scaled(NumberWidth)); + changed |= ImGui::DragInt(Text::OnceIn, &chance->oneIn, CountSpeed, 1, MaxBoneThingOneIn, "%d", + ImGuiSliderFlags_AlwaysClamp); + Tip(Text::OnceInTooltip, true); + const char* const* drawTip = Find(&ChanceDrawTips(), chance->draw); + changed |= Choice(Text::ChanceDraw, chance->draw, ChanceDrawNames(), drawTip != nullptr ? *drawTip : "", + &ChanceDrawTips()); + if (forEach) + { + changed |= ImGui::Checkbox(Text::OnceForAll, &chance->once); + Tip(Text::OnceForAllTooltip); + } + ImGui::Unindent(); + } + ImGui::PopID(); + return changed; +} + +// The type by its name, from the effect catalogue's types of the thing's kind, with a filter. +bool TypeField(BoneThingKind kind, std::string& type) +{ + namespace Text = I18N::Editor; + ImGui::SetNextItemWidth(Scaled(ComboWidth)); + if (!ImGui::BeginCombo(Text::BoneThingType, type.empty() ? Text::BoneThingTypeMissing : type.c_str(), + ImGuiComboFlags_HeightLarge)) + { + Tip(Text::BoneThingTypeTooltip); + return false; + } + static ImGuiTextFilter filter; + if (ImGui::IsWindowAppearing()) + { + filter.Clear(); + ImGui::SetKeyboardFocusHere(); + } + filter.Draw(Text::BoneThingFilter); + bool changed = false; + for (const std::string_view name : g_EffectTypeCatalogue.GetNames(CatalogueKindOf(kind))) + { + const std::string text(name); + if (!filter.PassFilter(text.c_str())) + { + continue; + } + if (ImGui::Selectable(text.c_str(), text == type) && text != type) + { + type = text; + changed = true; + } + } + ImGui::EndCombo(); + return changed; +} + +bool ThingFields(BoneThing& thing, bool ownChance) +{ + namespace Text = I18N::Editor; + bool changed = false; + BoneThingKind kind = thing.kind; + if (Choice(Text::Kind, kind, BoneThingKindNames(), Text::BoneThingKindTooltip)) + { + ChangeKind(thing, kind); + changed = true; + } + changed |= TypeField(thing.kind, thing.type); + ImGui::SetNextItemWidth(Scaled(NumberWidth)); + changed |= ImGui::DragInt(Text::SubType, &thing.subType, CountSpeed, 0, MaxBoneThingSubType, "%d", + ImGuiSliderFlags_AlwaysClamp); + Tip(Text::BoneThingSubtypeTooltip, true); + changed |= NumberField(Text::Scale, thing.scale, Text::BoneThingScaleTooltip); + changed |= ColorField(thing.color); + if (thing.kind == BoneThingKind::Sprite) + { + changed |= NumberField(Text::Rotation, thing.rotation, Text::BoneThingRotationTooltip); + } + if (thing.kind == BoneThingKind::Joint) + { + changed |= ImGui::Checkbox(Text::ReversedLightning, &thing.reversed); + Tip(Text::ReversedLightningTooltip); + } + if (ownChance) + { + changed |= ChanceFields(Text::ThingChance, thing.chance, false); + } + return changed; +} + +std::string DescribeThing(const BoneThing& thing) +{ + std::string text = NameIn(BoneThingKindNames(), thing.kind) + " " + (thing.type.empty() ? "?" : thing.type); + if (thing.subType != 0) + { + text += " (" + std::to_string(thing.subType) + ")"; + } + return text; +} +} // namespace + +void ChangeKind(Data::Looks::BoneThing& thing, Data::Looks::BoneThingKind kind) +{ + const BoneThing fresh; + thing.kind = kind; + thing.type.clear(); + thing.rotation = fresh.rotation; + thing.reversed = fresh.reversed; +} + +bool OnBonesEntry(Data::Looks::OnBones& entry, OnBonesShown& shown) +{ + namespace Text = I18N::Editor; + bool changed = false; + // An entry with no bones yet keeps the choice in the ID scope it is drawn in. + bool& chosenBetween = *ImGui::GetStateStorage()->GetBoolRef(ImGui::GetID("##Between"), false); + BonePlaces& places = entry.places; + PlaceMode mode = PlaceMode::Bones; + if (places.origin) + { + mode = PlaceMode::Origin; + } + else if (!places.between.empty() || (places.bones.empty() && chosenBetween)) + { + mode = PlaceMode::Between; + } + const auto radio = [&](const char* label, PlaceMode choice) + { + if (ImGui::RadioButton(label, mode == choice) && mode != choice) + { + mode = choice; + places = {}; + places.origin = choice == PlaceMode::Origin; + chosenBetween = choice == PlaceMode::Between; + // The item's place is one place: Once for all, hidden there, would be written and mean nothing. + if (places.origin && entry.chance) + { + entry.chance->once = false; + } + changed = true; + } + Tip(Text::BonePlacesTooltip); + }; + radio(Text::AtBones, PlaceMode::Bones); + ImGui::SameLine(); + radio(Text::BetweenBones, PlaceMode::Between); + ImGui::SameLine(); + radio(Text::AtTheItemSPlace, PlaceMode::Origin); + shown.between = mode == PlaceMode::Between; + if (mode == PlaceMode::Bones) + { + changed |= BonesField(places.bones, shown.pointedBone); + } + else if (mode == PlaceMode::Between) + { + changed |= PairsField(places.between, shown.pointedBone); + } + changed |= ChanceFields(Text::Chance, entry.chance, mode != PlaceMode::Origin); + + // A group keeps Together while it has more than one thing. + ImGui::BeginDisabled(entry.together && entry.things.size() > 1); + if (ImGui::Checkbox(Text::Together, &entry.together)) + { + if (!entry.together) + { + for (BoneThing& thing : entry.things) + { + thing.chance.reset(); + } + } + changed = true; + } + ImGui::EndDisabled(); + Tip(Text::TogetherTooltip); + if (!entry.together) + { + if (entry.things.empty()) + { + entry.things.emplace_back(); + changed = true; + } + ImGui::PushID("Thing"); + changed |= ThingFields(entry.things.front(), false); + ImGui::PopID(); + return changed; + } + std::optional removed; + for (std::size_t i = 0; i < entry.things.size(); ++i) + { + ImGui::PushID(static_cast(i)); + const std::string header = std::to_string(i + 1) + ". " + DescribeThing(entry.things[i]); + if (ImGui::TreeNodeEx("##Thing", ImGuiTreeNodeFlags_DefaultOpen, "%s", header.c_str())) + { + ImGui::BeginDisabled(entry.things.size() <= 1); + if (ImGui::SmallButton(Text::Remove)) + { + removed = i; + } + ImGui::EndDisabled(); + changed |= ThingFields(entry.things[i], true); + ImGui::TreePop(); + } + ImGui::PopID(); + } + if (removed) + { + entry.things.erase(entry.things.begin() + static_cast(*removed)); + changed = true; + } + if (ImGui::SmallButton(Text::AddThing)) + { + BoneThing thing = entry.things.empty() ? BoneThing{} : entry.things.back(); + thing.chance.reset(); + entry.things.push_back(std::move(thing)); + changed = true; + } + return changed; +} + +bool AnimationSpeed(std::optional& speed) +{ + namespace Text = I18N::Editor; + ImGui::PushID("AnimationSpeed"); + bool set = speed.has_value(); + bool changed = ImGui::Checkbox(Text::AnimationSpeed, &set); + Tip(Text::AnimationSpeedTooltip); + if (changed) + { + speed = set ? std::optional(NewAnimationSpeed) : std::nullopt; + } + if (speed) + { + ImGui::SameLine(); + ImGui::SetNextItemWidth(Scaled(NumberWidth)); + changed |= ImGui::DragFloat("##Speed", &*speed, AnimationSpeedStep, AnimationSpeedStep, MaxAnimationSpeed, + "%.3f", ImGuiSliderFlags_AlwaysClamp); + Tip(Text::AnimationSpeedTooltip, true); + } + ImGui::PopID(); + return changed; +} + +std::string DescribeOnBones(const Data::Looks::OnBones& entry, bool betweenChosen) +{ + std::string text; + for (const BoneThing& thing : entry.things) + { + AddPart(text, DescribeThing(thing), " + "); + } + if (text.empty()) + { + text = I18N::Editor::None; + } + const BonePlaces& places = entry.places; + if (places.origin) + { + text += std::string(", ") + I18N::Editor::AtTheItemSPlace; + } + else if (!places.between.empty() || (places.bones.empty() && betweenChosen)) + { + std::string pairs; + for (const auto& [from, to] : places.between) + { + AddPart(pairs, std::to_string(from) + "->" + std::to_string(to)); + } + text += std::string(", ") + I18N::Editor::BetweenBones + " " + pairs; + } + else + { + text += std::string(", ") + I18N::Editor::AtBones + " " + JoinMeshes(places.bones); + } + if (entry.chance) + { + text += std::string(", ") + I18N::Editor::OnceIn + " " + std::to_string(entry.chance->oneIn); + } + return text; +} + +namespace +{ +// A layer value the look sets: anything but the item's own value (the item's value times a number is set). +template bool SetsValue(const T& value) +{ + return value != T{FromItem{}}; +} +} // namespace + std::string DescribeLayer(const Data::Looks::Layer& layer) { std::string text = NameIn(KindNames(), layer.kind); @@ -1565,23 +2023,23 @@ std::string DescribeLayer(const Data::Looks::Layer& layer) { AddPart(fields, I18N::Editor::Light); } - if (!std::holds_alternative(layer.opacity)) + if (SetsValue(layer.opacity)) { AddPart(fields, I18N::Editor::Opacity); } - if (!std::holds_alternative(layer.glowMesh)) + if (SetsValue(layer.glowMesh)) { AddPart(fields, I18N::Editor::GlowMesh); } - if (!std::holds_alternative(layer.glowStrength)) + if (SetsValue(layer.glowStrength)) { AddPart(fields, I18N::Editor::GlowStrength); } - if (!std::holds_alternative(layer.scrollU)) + if (SetsValue(layer.scrollU)) { AddPart(fields, I18N::Editor::ScrollU); } - if (!std::holds_alternative(layer.scrollV)) + if (SetsValue(layer.scrollV)) { AddPart(fields, I18N::Editor::ScrollV); } diff --git a/src/MuEditor/UI/StyleEditor/LookFields.h b/src/MuEditor/UI/StyleEditor/LookFields.h index bccd5bc327..9460ce74ef 100644 --- a/src/MuEditor/UI/StyleEditor/LookFields.h +++ b/src/MuEditor/UI/StyleEditor/LookFields.h @@ -6,6 +6,7 @@ #include "Data/GameData/LookData/LookEffects.h" #include "LookParts.h" +#include #include #include @@ -28,6 +29,28 @@ bool ItemValuesBeforeEntry(Data::Looks::ItemValuesBefore& entry, const std::vect bool ObjectLight(std::optional>& light); // One line for an entry of the item effect's list: "Only when: glow mesh, glows like level +7". std::string DescribeItemValuesBefore(const Data::Looks::ItemValuesBefore& entry); + +// What the fields of an entry of things on bones showed in this frame, for the preview's marks (design L58). +struct OnBonesShown +{ + // Whether its places are pairs of bones (lightning). + bool between = false; + // The bone a number field points at (the mouse on it, or typed into). + std::optional pointedBone; +}; +// An entry of an item effect's things on bones (design L55, L56, section 7b): where (at bones, between pairs of bones, +// at the item's place) with its bones as number fields, its chance, Together, and its things, each with its kind, its +// type by name from the effect catalogue, SubType, scale, color, a sprite's rotation, lightning's direction and, in a +// group, its own chance. +bool OnBonesEntry(Data::Looks::OnBones& entry, OnBonesShown& shown); +// A thing of things on bones made a thing of `kind`: no type yet (a name is a type of one kind), and without a +// sprite's rotation and lightning's direction, which belong to their kinds and would be written and refused. +void ChangeKind(Data::Looks::BoneThing& thing, Data::Looks::BoneThingKind kind); +// The speed the update plays the item's animation at (design L29); none plays none. +bool AnimationSpeed(std::optional& speed); +// An entry of things on bones on one line: its things, where and its chance. +// `betweenChosen`: Between bones is chosen for the entry while it has no bones yet, as its fields show it. +std::string DescribeOnBones(const Data::Looks::OnBones& entry, bool betweenChosen = false); // A layer as its effect (design L35, L40): its meshes, then only the fields of its main effect and of what else it // does, as `effect` describes it (a pulse's strength with its curve, a shine's motion, an overlay's texture). bool Effect(Data::Looks::Layer& layer, const Data::Looks::LayerEffect& effect, const std::vector& parts = {}); diff --git a/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.cpp b/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.cpp index f33b7a9fd4..ff5f740481 100644 --- a/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.cpp +++ b/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.cpp @@ -4,10 +4,13 @@ #include "MuStyleEditorUI.h" +#include "BoneMarks.h" +#include "BoneThingsPreview.h" #include "LookEdits.h" #include "LookFields.h" #include "LookParts.h" #include "RenderStyleCheckArea.h" +#include "WorldTimeScope.h" #include "../MuEditor/Core/MuEditorCore.h" #include "../MuEditor/UI/Common/MuEditorToolWindows.h" @@ -175,31 +178,6 @@ std::vector RowLayers(const LookDefinition& look, int part) return layers; } -// The clock of the game for one drawing: the preview's stopped time. -class WorldTimeScope -{ -public: - explicit WorldTimeScope(std::optional milliseconds) : m_previous(WorldTime), m_set(milliseconds.has_value()) - { - if (m_set) - { - WorldTime = *milliseconds; - } - } - ~WorldTimeScope() - { - if (m_set) - { - WorldTime = m_previous; - } - } - WorldTimeScope(const WorldTimeScope&) = delete; - WorldTimeScope& operator=(const WorldTimeScope&) = delete; - -private: - double m_previous; - bool m_set; -}; } // namespace namespace MuEditor::Looks @@ -911,38 +889,131 @@ void CMuStyleEditorUI::RenderLayers() ImGui::PopID(); } -void CMuStyleEditorUI::RenderItemEffect() +namespace { - std::vector& entries = m_draft.itemValuesBefore; +// Copy, Move up, Move down and Remove for the picked line `line`, the entry `line - first` of `list`; disabled +// without a list (another line is picked). +template void EntryButtons(std::vector* list, std::size_t first, std::size_t& line) +{ + ImGui::BeginDisabled(list == nullptr); + const bool copy = ImGui::SmallButton(I18N::Editor::Copy); + ImGui::SameLine(); + const bool up = ImGui::SmallButton(I18N::Editor::MoveUp); + ImGui::SameLine(); + const bool down = ImGui::SmallButton(I18N::Editor::MoveDown); + ImGui::SameLine(); + const bool remove = ImGui::SmallButton(I18N::Editor::Remove); + ImGui::EndDisabled(); + if (list == nullptr) + { + return; + } + const std::size_t index = line - first; + const auto at = [&](std::size_t i) { return list->begin() + static_cast(i); }; + if (copy) + { + list->insert(at(index + 1), (*list)[index]); + ++line; + } + else if (up && index > 0) + { + std::swap((*list)[index], (*list)[index - 1]); + --line; + } + else if (down && index + 1 < list->size()) + { + std::swap((*list)[index], (*list)[index + 1]); + ++line; + } + else if (remove) + { + list->erase(at(index)); + // The next entry, else the one before, else the line before the list. + if (list->empty()) + { + line = first == 0 ? 0 : first - 1; + } + else + { + line = std::min(line, first + list->size() - 1); + } + } +} +} // namespace + +Data::Looks::OnBones* CMuStyleEditorUI::PickedOnBones() +{ + if (m_draftKind != Data::Looks::LookKind::ItemEffect) + { + return nullptr; + } + // After the entries before the drawing come the object's light and the animation speed. + const std::size_t first = m_draft.itemValuesBefore.size() + 2; + if (m_line < first || m_line - first >= m_draft.onBones.size()) + { + return nullptr; + } + return &m_draft.onBones[m_line - first]; +} + +void CMuStyleEditorUI::RenderItemEffectToolbar() +{ + std::vector& before = m_draft.itemValuesBefore; + std::vector& onBones = m_draft.onBones; + const std::size_t firstBones = before.size() + 2; + const bool beforePicked = m_line < before.size(); + const bool bonesPicked = PickedOnBones() != nullptr; + ImGui::TextUnformatted(I18N::Editor::BeforeDrawing); ImGui::SameLine(); + ImGui::PushID("Before"); if (ImGui::SmallButton(I18N::Editor::Add)) { - const std::size_t at = std::min(m_line + 1, entries.size()); - entries.insert(entries.begin() + static_cast(at), Data::Looks::ItemValuesBefore{}); + const std::size_t at = beforePicked ? m_line + 1 : before.size(); + before.insert(before.begin() + static_cast(at), Data::Looks::ItemValuesBefore{}); m_line = at; } - const bool entry = m_line < entries.size(); - ImGui::BeginDisabled(!entry); + ImGui::PopID(); + ImGui::SameLine(); + ImGui::TextUnformatted(I18N::Editor::OnBones); ImGui::SameLine(); - if (ImGui::SmallButton(I18N::Editor::Remove) && entry) + ImGui::PushID("OnBones"); + if (ImGui::SmallButton(I18N::Editor::Add)) { - entries.erase(entries.begin() + static_cast(m_line)); + const std::size_t at = bonesPicked ? m_line - firstBones + 1 : onBones.size(); + Data::Looks::OnBones entry; + entry.things.emplace_back(); + onBones.insert(onBones.begin() + static_cast(at), std::move(entry)); + m_line = before.size() + 2 + at; } + ImGui::PopID(); + ImGui::SameLine(); + ImGui::TextDisabled("|"); ImGui::SameLine(); - if (ImGui::SmallButton(I18N::Editor::MoveUp) && entry && m_line > 0) + if (m_line < before.size()) { - std::swap(entries[m_line], entries[m_line - 1]); - --m_line; + EntryButtons(&before, 0, m_line); } - ImGui::SameLine(); - if (ImGui::SmallButton(I18N::Editor::MoveDown) && entry && m_line + 1 < entries.size()) + else if (PickedOnBones() != nullptr) { - std::swap(entries[m_line], entries[m_line + 1]); - ++m_line; + EntryButtons(&onBones, before.size() + 2, m_line); } - ImGui::EndDisabled(); + else + { + EntryButtons(nullptr, 0, m_line); + } +} + +void CMuStyleEditorUI::RenderItemEffect() +{ + RenderItemEffectToolbar(); RenderNote(I18N::Editor::BeforeDrawingNote); + RenderNote(I18N::Editor::OnBonesNote); + std::vector& entries = m_draft.itemValuesBefore; + const std::size_t lightLine = entries.size(); + const std::size_t speedLine = entries.size() + 1; + const std::size_t firstBones = entries.size() + 2; + const std::size_t pickedBefore = m_line; const float height = LayerListLines * ImGui::GetFrameHeightWithSpacing(); if (ImGui::BeginChild("##Entries", ImVec2(0.0f, height), ImGuiChildFlags_Borders)) @@ -960,30 +1031,134 @@ void CMuStyleEditorUI::RenderItemEffect() } const std::string light = std::string(I18N::Editor::ObjectLight) + ": " + (m_draft.objectLight ? "" : I18N::Editor::None); - if (ImGui::Selectable(light.c_str(), m_line >= entries.size())) + if (ImGui::Selectable(light.c_str(), m_line == lightLine)) + { + m_line = lightLine; + } + char speed[32] = {}; + if (m_draft.animationSpeed) + { + std::snprintf(speed, sizeof(speed), "%.3g", *m_draft.animationSpeed); + } + const std::string speedText = + std::string(I18N::Editor::AnimationSpeed) + ": " + (m_draft.animationSpeed ? speed : I18N::Editor::None); + if (ImGui::Selectable(speedText.c_str(), m_line == speedLine)) + { + m_line = speedLine; + } + ImGui::PushID("OnBones"); + for (std::size_t index = 0; index < m_draft.onBones.size(); ++index) { - m_line = entries.size(); + ImGui::PushID(static_cast(index)); + // The picked entry as its fields show it, Between bones chosen before its first pair too. + const bool betweenChosen = m_line == firstBones + index && m_entryBetween; + const std::string line = std::string(I18N::Editor::OnBones) + " " + std::to_string(index + 1) + ": " + + MuEditor::Looks::Fields::DescribeOnBones(m_draft.onBones[index], betweenChosen); + if (ImGui::Selectable(line.c_str(), m_line == firstBones + index)) + { + m_line = firstBones + index; + } + ImGui::PopID(); } + ImGui::PopID(); } ImGui::EndChild(); + // Past the last line (an entry removed elsewhere, an undo): the last one. + m_line = std::min(m_line, firstBones + m_draft.onBones.size() - 1); + if (m_line != pickedBefore) + { + m_pairFrom.reset(); + } ImGui::PushID("Entry"); ImGui::PushID(m_draftOf.c_str()); ImGui::PushID(static_cast(m_line)); const std::vector parts = MuEditor::Looks::PartsOf(g_ItemSelection.GetItemType()); + m_pointedBone.reset(); if (m_line < entries.size()) { MuEditor::Looks::Fields::ItemValuesBeforeEntry(entries[m_line], parts); } - else + else if (m_line == lightLine) { MuEditor::Looks::Fields::ObjectLight(m_draft.objectLight); } + else if (m_line == speedLine) + { + MuEditor::Looks::Fields::AnimationSpeed(m_draft.animationSpeed); + } + else if (Data::Looks::OnBones* entry = PickedOnBones()) + { + ImGui::BeginDisabled(entry->places.origin); + ImGui::Checkbox(I18N::Editor::PickInThePreview, &m_pickBones); + ImGui::EndDisabled(); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip | ImGuiHoveredFlags_AllowWhenDisabled)) + { + ImGui::SetTooltip("%s", I18N::Editor::PickInThePreviewTooltip); + } + if (m_pickBones && m_pairFrom) + { + ImGui::SameLine(); + ImGui::TextDisabled("%s", + I18N::Format(I18N::Editor::PickTheEndFrom0, {std::to_string(*m_pairFrom)}).c_str()); + } + if ((m_pickBones || m_showBones) && m_noBones) + { + RenderNote(I18N::Editor::NoBonesForThisItem); + } + MuEditor::Looks::Fields::OnBonesShown shown; + MuEditor::Looks::Fields::OnBonesEntry(*entry, shown); + if (shown.between != m_entryBetween || !m_pickBones) + { + m_pairFrom.reset(); + } + m_entryBetween = shown.between; + m_pointedBone = shown.pointedBone; + } ImGui::PopID(); ImGui::PopID(); ImGui::PopID(); } +void CMuStyleEditorUI::RenderBoneMarks(const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, + const MuEditor::Effects::EffectPreviewCamera& camera, + const MuEditor::Items::CItemModelPreview::ViewOnScreen& screen) +{ + namespace BoneMarks = MuEditor::Looks::BoneMarks; + Data::Looks::OnBones* entry = PickedOnBones(); + const bool picking = m_pickBones && entry != nullptr && !entry->places.origin; + if (!m_showBones && entry == nullptr) + { + return; + } + std::vector& bones = m_shownBones; + BoneMarks::BonesOf(request, turnDegrees, bones); + m_noBones = bones.empty(); + if (bones.empty()) + { + return; + } + BoneMarks::Marks marks; + marks.dots = m_showBones || picking; + if (entry != nullptr) + { + marks.bones = entry->places.bones; + marks.pairs = entry->places.between; + marks.ringed = m_pointedBone; + marks.from = m_pairFrom; + } + const std::optional hit = BoneMarks::Draw(bones, marks, camera, screen.min, screen.max, + picking ? screen.click : std::nullopt, screen.hovered); + if (picking && screen.hovered && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + m_pickTakeBack.TakeBack(entry->places, m_pairFrom, ImGui::GetTime(), ImGui::GetIO().MouseDoubleClickTime); + } + if (hit && picking) + { + m_pickTakeBack.Pick(entry->places, m_entryBetween, m_pairFrom, *hit, ImGui::GetTime()); + } +} + void CMuStyleEditorUI::RenderLayerToolbar() { const std::size_t count = m_draft.layers.size(); @@ -1331,6 +1506,12 @@ void CMuStyleEditorUI::RenderPreview(const LookDefinition* look) ImGui::EndDisabled(); ImGui::SameLine(); ImGui::Checkbox(I18N::Editor::DrawAsADoppelganger, &m_asDoppelganger); + ImGui::SameLine(); + ImGui::Checkbox(I18N::Editor::ShowBones, &m_showBones); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip)) + { + ImGui::SetTooltip("%s", I18N::Editor::ShowBonesTooltip); + } const int itemType = g_ItemSelection.GetItemType(); if (g_ItemDatabase.Find(itemType) == nullptr || g_ItemModelDatabase.Find(itemType) == nullptr) { @@ -1343,7 +1524,11 @@ void CMuStyleEditorUI::RenderPreview(const LookDefinition* look) const LookDefinition shown = look != nullptr ? MuEditor::Looks::WithoutHiddenLayers(*look, m_hiddenLayers) : LookDefinition{}; // All views at the same moment. - const WorldTimeScope time(m_stopTime ? std::optional(m_seconds * 1000.0) : std::nullopt); + const std::optional stoppedAt = m_stopTime ? std::optional(m_seconds * 1000.0) : std::nullopt; + const MuEditor::Looks::WorldTimeScope time(stoppedAt); + // While bones are picked a click in a view picks a bone, not a mesh. + const Data::Looks::OnBones* pickedEntry = look != nullptr ? PickedOnBones() : nullptr; + m_preview.SetMeshPicking(!(m_pickBones && pickedEntry != nullptr && !pickedEntry->places.origin)); if (look == nullptr) { // A look in code: the item as the game draws it. @@ -1398,7 +1583,20 @@ void CMuStyleEditorUI::RenderPreview(const LookDefinition* look) } const Render::Items::Styles::PreviewLook preview(slot, *drawn); draw(); - }); + }, + // Each view's things on bones, from the item effect its item runs while it is drawn (design L51, L52). + [stoppedAt](int view, const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, + const MuEditor::Effects::EffectPreviewCamera& camera) + { + const int model = MuEditor::Effects::PreviewItemModelsOf(request).model; + MuEditor::Looks::g_BoneThingsPreview.Draw( + view, {request, Render::Items::ItemEffects::EffectOf(model), turnDegrees, stoppedAt}, camera); + }, + // The item's bones over each view (design L58). + [this](int, const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, + const MuEditor::Effects::EffectPreviewCamera& camera, + const MuEditor::Items::CItemModelPreview::ViewOnScreen& screen) + { RenderBoneMarks(request, turnDegrees, camera, screen); }); } void CMuStyleEditorUI::RenderViewHeader(int view, float width) diff --git a/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.h b/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.h index 683fef71e0..05024f7529 100644 --- a/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.h +++ b/src/MuEditor/UI/StyleEditor/MuStyleEditorUI.h @@ -2,6 +2,7 @@ #ifdef _EDITOR +#include "BoneMarks.h" #include "LookEdits.h" #include "LookParts.h" #include "LooksRoot.h" @@ -136,9 +137,16 @@ class CMuStyleEditorUI [[nodiscard]] std::string UnusedLookName(const std::string& base) const; void RenderLayers(); void RenderLayerToolbar(); - // An item effect: its entries before the drawing in their order, then the object's light, and the picked line's - // fields. + // An item effect: its entries before the drawing in their order, the object's light, the animation speed and its + // things on bones (design section 7b), and the picked line's fields. void RenderItemEffect(); + void RenderItemEffectToolbar(); + // The picked entry of the draft's things on bones, or nullptr. + [[nodiscard]] Data::Looks::OnBones* PickedOnBones(); + // The marks of the item's bones over a view of the preview, and a click on one in pick mode (design L58). + void RenderBoneMarks(const MuEditor::Effects::EffectPreviewRequest& request, float turnDegrees, + const MuEditor::Effects::EffectPreviewCamera& camera, + const MuEditor::Items::CItemModelPreview::ViewOnScreen& screen); void RenderParts(); void RenderPartRow(const char* label, int part, const std::vector& layers); void RenderEffectChip(std::size_t layer, int part); @@ -220,6 +228,20 @@ class CMuStyleEditorUI int m_checkedModels = -1; bool m_checked = false; + // The bones of the previewed item (design L58): "Show bones", the pick mode, the start of a pair being picked, + // and what the fields of the picked entry of things on bones showed in the last frame. + bool m_showBones = false; + bool m_pickBones = false; + std::optional m_pairFrom; + bool m_entryBetween = false; + std::optional m_pointedBone; + // The last pick, taken back when its click was the first of a double click (which puts the view back). + MuEditor::Looks::BoneMarks::PickTakeBack m_pickTakeBack; + // The bones a view shows, reused by each view and frame. + std::vector m_shownBones; + // The last view's item had no bones of its own (armor) while marks were asked for. + bool m_noBones = false; + bool m_stopTime = false; float m_seconds = 0.0f; bool m_asDoppelganger = false; diff --git a/src/MuEditor/UI/StyleEditor/RenderStyleCheckArea.cpp b/src/MuEditor/UI/StyleEditor/RenderStyleCheckArea.cpp index 8ccda5a8e4..8a5d4d2a7b 100644 --- a/src/MuEditor/UI/StyleEditor/RenderStyleCheckArea.cpp +++ b/src/MuEditor/UI/StyleEditor/RenderStyleCheckArea.cpp @@ -16,6 +16,7 @@ #include "Data/GameData/ItemData/ItemModelDatabase.h" #include "Data/GameData/ItemData/ItemModelSlots.h" #include "Data/GameData/ItemData/ItemType.h" +#include "Data/GameData/LookData/BoneThingTypes.h" #include "Data/GameData/LookData/LookJson.h" #include "I18N/All.h" #include "Render/Models/ZzzBMD.h" @@ -52,6 +53,16 @@ int MeshCount(int itemType) return Models[Data::Items::ToModelSlot(itemType)].NumMeshs; } +int BoneCount(int itemType) +{ + return Models[Data::Items::ToModelSlot(itemType)].NumBones; +} + +bool EffectTypeExists(Data::Looks::BoneThingKind kind, const std::string& type) +{ + return Data::Looks::FindBoneThingType(kind, type).has_value(); +} + bool IsAboutAnItem(const ItemDataIssue& issue) { return Data::Items::IsValidItemId(issue.group, issue.number); @@ -174,7 +185,9 @@ Data::Looks::RenderStyleCheckInput MakeEditorCheckInput() return {.models = g_ItemModelDatabase.GetAllSlots(), .partModels = g_ItemModelDatabase.GetPartModels(), .textureExists = TextureFileExists, - .meshCount = MeshCount}; + .meshCount = MeshCount, + .typeExists = EffectTypeExists, + .boneCount = BoneCount}; } std::unique_ptr CreateRenderStyleCheckArea() diff --git a/src/MuEditor/UI/StyleEditor/WorldTimeScope.h b/src/MuEditor/UI/StyleEditor/WorldTimeScope.h new file mode 100644 index 0000000000..599a826ac2 --- /dev/null +++ b/src/MuEditor/UI/StyleEditor/WorldTimeScope.h @@ -0,0 +1,39 @@ +#pragma once + +#ifdef _EDITOR + +#include "Render/Textures/ZzzOpenglUtil.h" + +#include + +namespace MuEditor::Looks +{ +// The clock of the game while it lives: the Style Editor preview's stopped time, in milliseconds of WorldTime; +// without one the clock runs on. +class WorldTimeScope +{ +public: + explicit WorldTimeScope(std::optional milliseconds) : m_previous(WorldTime), m_set(milliseconds.has_value()) + { + if (m_set) + { + WorldTime = *milliseconds; + } + } + ~WorldTimeScope() + { + if (m_set) + { + WorldTime = m_previous; + } + } + WorldTimeScope(const WorldTimeScope&) = delete; + WorldTimeScope& operator=(const WorldTimeScope&) = delete; + +private: + double m_previous; + bool m_set; +}; +} // namespace MuEditor::Looks + +#endif // _EDITOR diff --git a/src/bin/Data/Effects/ItemEffects.json b/src/bin/Data/Effects/ItemEffects.json index cce909723f..849b5c6e82 100644 --- a/src/bin/Data/Effects/ItemEffects.json +++ b/src/bin/Data/Effects/ItemEffects.json @@ -2,6 +2,13 @@ "formatVersion": 1, "kind": "itemEffect", "looks": [ + { + "name": "cursedCastleWater", + "onBones": [ + {"sprite": "light", "bones": [1], "scale": 3, "color": [1, 0, 0]} + ], + "animationSpeed": 0.2857143 + }, { "name": "devilsEye", "itemValuesBefore": [ @@ -9,6 +16,18 @@ ], "objectLight": [{"shape": "wave", "from": 1.13, "to": 5.13, "seconds": 3.14159265}, {"shape": "wave", "from": 1.13, "to": 5.13, "seconds": 3.14159265}, {"shape": "wave", "from": 1.13, "to": 5.13, "seconds": 3.14159265}] }, + { + "name": "devilsInvitation", + "onBones": [ + {"sprite": "spark3", "bones": [9, 10], "scale": {"shape": "wave", "from": 0.24, "to": 0.8, "seconds": 3.14159265}, "color": [{"shape": "wave", "from": 0.6, "to": 2, "seconds": 3.14159265}, {"shape": "wave", "from": 0.096, "to": 0.32, "seconds": 3.14159265}, {"shape": "wave", "from": 0.096, "to": 0.32, "seconds": 3.14159265}]} + ] + }, + { + "name": "devilsKey", + "onBones": [ + {"sprite": "spark3", "bones": [1, 2], "scale": {"shape": "wave", "from": 0.24, "to": 0.8, "seconds": 3.14159265}, "color": [{"shape": "wave", "from": 0.6, "to": 2, "seconds": 3.14159265}, {"shape": "wave", "from": 0.096, "to": 0.32, "seconds": 3.14159265}, {"shape": "wave", "from": 0.096, "to": 0.32, "seconds": 3.14159265}]} + ] + }, { "name": "divineSet", "itemValuesBefore": [ @@ -58,12 +77,26 @@ {"glowMesh": {"eachItem": "glowMesh", "default": 1}, "glowStrength": {"eachItem": "glowStrength", "default": {"shape": "wave", "from": 0.4, "to": 1, "seconds": 1.5707963}}} ] }, + { + "name": "pumpkinOfLuck", + "objectLight": [{"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.3, "to": 0.4, "seconds": 1.570796327}], + "onBones": [ + {"sprite": "light", "bones": [8], "scale": 1.5, "color": [{"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.3, "to": 0.4, "seconds": 1.570796327}], "rotation": 0.5}, + {"sprite": "light", "bones": [10, 11], "scale": 0.5, "color": [{"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.3, "to": 0.4, "seconds": 1.570796327}], "rotation": 0.5} + ] + }, { "name": "redSpirit", "itemValuesBefore": [ {"glowStrength": {"shape": "wave", "from": 0.2, "to": 1, "seconds": 6.283185}} ] }, + { + "name": "rena", + "onBones": [ + {"sprite": "spark3", "at": "origin", "scale": 2.5, "color": [{"shape": "wave", "from": 0.5, "to": 1, "seconds": 3.14159265}, {"shape": "wave", "from": 0.25, "to": 0.5, "seconds": 3.14159265}, 0]} + ] + }, { "name": "scrollingDown", "itemValuesBefore": [ @@ -88,6 +121,57 @@ {"glowMesh": 2, "glowStrength": {"shape": "wave", "from": 0.4, "to": 1, "seconds": 1.5707963}} ] }, + { + "name": "wingOfDimension", + "onBones": [ + {"sprite": "flare", "bones": [7, 30], "scale": {"shape": "bounce", "from": 2, "to": 2.2, "seconds": 1.570796327}, "color": [{"shape": "bounce", "from": 0.5, "to": 0.7, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.35, "to": 0.55, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.1, "to": 0.3, "seconds": 1.570796327}]}, + {"sprite": "flare", "bones": [31, 43, 8, 20], "scale": {"shape": "bounce", "from": 0.5, "to": 0.7, "seconds": 1.570796327}, "color": [{"shape": "bounce", "from": 0.25, "to": 0.35, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.175, "to": 0.275, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.05, "to": 0.15, "seconds": 1.570796327}]}, + {"sprite": "flare", "bones": [29, 38, 42, 19, 15, 6], "scale": {"shape": "bounce", "from": 2, "to": 2.2, "seconds": 1.570796327}, "color": [{"shape": "bounce", "from": 0.25, "to": 0.45, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.05, "to": 0.25, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.2, "to": 0.4, "seconds": 1.570796327}]} + ] + }, + { + "name": "wingOfEternal", + "onBones": [ + {"sprite": "light", "bones": [24, 31, 15, 8, 53, 35], "scale": {"shape": "bounce", "from": 1.3, "to": 1.5, "seconds": 1.047197551}, "color": [{"shape": "bounce", "from": 0.5, "to": 0.8, "seconds": 1.047197551}, {"shape": "bounce", "from": 0.5, "to": 0.8, "seconds": 1.047197551}, {"shape": "bounce", "from": 0.6, "to": 0.9, "seconds": 1.047197551}]}, + {"sprite": "light", "bones": [22, 23, 25, 29, 30, 28, 32, 13, 16, 14, 12, 9, 7, 6, 57, 58, 40, 39], "scale": {"shape": "bounce", "from": 1.5, "to": 1.7, "seconds": 1.047197551}, "color": [0.1, 0.1, 0.9]}, + {"sprite": "light", "bones": [56, 38, 51, 45], "scale": {"shape": "bounce", "from": 0.5, "to": 0.7, "seconds": 1.047197551}, "color": [0.1, 0.1, 0.9]} + ] + }, + { + "name": "wingOfIllusion", + "onBones": [ + {"sprite": "flare", "bones": [5, 6, 7, 8, 18, 19, 23, 24, 25, 27, 37, 38], "scale": {"shape": "bounce", "from": 0.6, "to": 0.8, "seconds": 1.570796327}, "color": [{"shape": "bounce", "from": 0.5, "to": 0.9, "seconds": 1.570796327}, {"shape": "bounce", "from": 0, "to": 0.4, "seconds": 1.570796327}, {"shape": "bounce", "from": 0, "to": 0.4, "seconds": 1.570796327}]}, + {"sprite": "light", "bones": [4, 9, 13, 14, 26, 32, 31, 33], "scale": 1.3, "color": [{"shape": "bounce", "from": 0, "to": 0.4, "seconds": 1.570796327}, {"shape": "bounce", "from": 0.5, "to": 0.9, "seconds": 1.570796327}, {"shape": "bounce", "from": 0, "to": 0.4, "seconds": 1.570796327}]}, + {"sprite": "light", "bones": [33], "scale": 0.4, "color": [{"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.3, "to": 0.4, "seconds": 1.570796327}], "rotation": 0.5}, + {"together": {"bones": [13, 31], "chance": {"oneIn": 2, "per": "once"}}, "things": [{"particle": "shiny", "subType": 5, "scale": 0.5, "color": [{"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.8, "to": 0.9, "seconds": 1.570796327}, {"shape": "wave", "from": 0.3, "to": 0.4, "seconds": 1.570796327}]}]} + ] + }, + { + "name": "wingOfRuin", + "onBones": [ + {"sprite": "light", "bones": [6, 15, 24, 56, 47, 38], "scale": {"shape": "bounce", "from": 1.5, "to": 1.7, "seconds": 1.047197551}, "color": [{"shape": "bounce", "from": 0.7, "to": 1, "seconds": 1.047197551}, {"shape": "bounce", "from": 0.5, "to": 0.8, "seconds": 1.047197551}, {"shape": "bounce", "from": 0.8, "to": 1.1, "seconds": 1.047197551}]}, + {"particle": "chromeEnergy2", "bones": [7, 16, 25, 57, 48, 39], "scale": 0.1, "color": [0.6, 0.4, 0.7], "chance": {"oneIn": 1}}, + {"particle": "chromeEnergy2", "bones": [11, 22, 31, 63, 54, 40, 10, 21, 30, 62, 53, 41], "scale": 0.3, "color": [0.6, 0.4, 0.7], "chance": {"oneIn": 1}}, + {"particle": "chromeEnergy2", "bones": [9, 20, 29, 61, 52, 42, 8, 19, 28, 60, 51, 43], "scale": 0.5, "color": [0.6, 0.4, 0.7], "chance": {"oneIn": 1}}, + {"particle": "chromeEnergy2", "bones": [18, 27, 59, 50, 17, 26, 58, 49], "scale": 0.7, "color": [0.6, 0.4, 0.7], "chance": {"oneIn": 1}} + ] + }, + { + "name": "wingOfStorm", + "onBones": [ + {"sprite": "cloud64", "subType": 1, "bones": [9, 20, 19, 10, 18, 28, 27, 36, 35, 38, 37, 53, 48, 62, 70, 72, 71, 78, 79, 80, 87, 90, 91, 106, 102], "scale": 0.5, "color": [{"shape": "bounce", "from": 0.5, "to": 0.9, "seconds": 7.853981634}, {"shape": "bounce", "from": 0.5, "to": 0.9, "seconds": 7.853981634}, {"shape": "bounce", "from": 0.5, "to": 0.9, "seconds": 7.853981634}], "rotation": {"shape": "scroll", "perSecond": 10}}, + {"together": {"bones": [11, 21, 29, 63, 81, 89], "chance": {"oneIn": 2, "per": "once"}}, "things": [{"effect": "fenrirThunder", "subType": 1, "color": [0.6, 0.6, 0.9], "chance": {"oneIn": 20, "draw": "plain"}}]}, + {"sprite": "light", "bones": [64, 98, 12, 52], "scale": {"shape": "bounce", "from": 1.4, "to": 1.6, "seconds": 1.047197551}, "color": [0.9, 0, 0]}, + {"sprite": "light", "bones": [61, 69, 77, 86, 97, 99, 104, 103, 105, 8, 17, 26, 34, 44, 51, 50, 49, 45], "scale": {"shape": "bounce", "from": 0.3, "to": 0.5, "seconds": 1.047197551}, "color": [0.8, 0.5, 0.2]} + ] + }, + { + "name": "wingsOfDarkness", + "onBones": [ + {"together": {"between": [[30, 22], [29, 21], [28, 20], [27, 19], [26, 18], [11, 7], [12, 6], [13, 5], [14, 4], [15, 3]], "chance": {"oneIn": 1}}, "things": [{"joint": "jointThunder", "subType": 14, "scale": {"shape": "wave", "from": 20, "to": 26, "seconds": 1.570796327}}, {"joint": "jointSpirit", "subType": 4, "reversed": true, "scale": {"shape": "wave", "from": 25, "to": 31, "seconds": 1.570796327}}]}, + {"sprite": "flareBlue", "bones": [22, 21, 20, 19, 18, 7, 6, 5, 4, 3], "scale": {"shape": "wave", "from": 0.7142857142857143, "to": 0.9285714285714286, "seconds": 1.570796327}, "color": [0.6, 0.3, 0.8]} + ] + }, { "name": "wingsOfDragon", "itemValuesBefore": [ diff --git a/src/bin/Data/Effects/RenderStyles.json b/src/bin/Data/Effects/RenderStyles.json index e603460789..209fd81039 100644 --- a/src/bin/Data/Effects/RenderStyles.json +++ b/src/bin/Data/Effects/RenderStyles.json @@ -188,6 +188,13 @@ ], "itemValuesAfter": {"scrollingMesh": 1} }, + { + "name": "cursedCastleWater", + "layers": [ + {"kind": "texture", "blend": "asDrawing", "meshes": "allEvenHidden", "opacity": "drawing", "glowStrength": {"itemTimes": 1.5}}, + {"kind": "texture", "blend": "glow", "meshes": {"allBut": [0]}, "opacity": "drawing", "glowStrength": {"itemTimes": 0.25}, "scrollU": {"shape": "scroll", "perSecond": 5}, "scrollV": {"shape": "scroll", "perSecond": -5}} + ] + }, { "name": "darkHorse", "layers": [ @@ -720,6 +727,13 @@ ], "itemValuesAfter": {"hiddenMesh": 1} }, + { + "name": "pumpkinOfLuck", + "layers": [ + {"kind": "texture"}, + {"kind": "reflection", "motion": "slowDrift", "blend": "darken", "meshes": [1], "texture": "Effect/Chrome01.jpg", "scrollU": {"shape": "scroll", "perSecond": -0.2}} + ] + }, { "name": "rareItemTicket", "layers": [ diff --git a/src/bin/Data/Items/Models/Group14_Potion.json b/src/bin/Data/Items/Models/Group14_Potion.json index e8bb13a5db..4a5f26a617 100644 --- a/src/bin/Data/Items/Models/Group14_Potion.json +++ b/src/bin/Data/Items/Models/Group14_Potion.json @@ -544,7 +544,8 @@ "rotation": [0, 0, 90], "scale": 0.9 }, - "renderStyle": "pumpkinOfLuck" + "renderStyle": "pumpkinOfLuck", + "itemEffect": "pumpkinOfLuck" }, { "number": 46, @@ -777,7 +778,8 @@ "shineHiddenMesh": 0, "shineBelowPlus3": "cursedCastleWater" }, - "renderStyle": "cursedCastleWater" + "renderStyle": "cursedCastleWater", + "itemEffect": "cursedCastleWater" }, { "number": 65, diff --git a/src/source/Audio/EditorSoundMute.h b/src/source/Audio/EditorSoundMute.h index 34f7d804d8..1a05747613 100644 --- a/src/source/Audio/EditorSoundMute.h +++ b/src/source/Audio/EditorSoundMute.h @@ -9,6 +9,25 @@ namespace Audio::EditorMute { void SetMuted(bool muted); [[nodiscard]] bool IsMuted(); + +// While it lives, muted; afterwards as before. +class Scope +{ +public: + Scope() : m_wasMuted(IsMuted()) + { + SetMuted(true); + } + ~Scope() + { + SetMuted(m_wasMuted); + } + Scope(const Scope&) = delete; + Scope& operator=(const Scope&) = delete; + +private: + bool m_wasMuted; +}; } // namespace Audio::EditorMute #endif // _EDITOR diff --git a/src/source/Core/Utilities/EffectSpawnHook.cpp b/src/source/Core/Utilities/EffectSpawnHook.cpp new file mode 100644 index 0000000000..191f918b1c --- /dev/null +++ b/src/source/Core/Utilities/EffectSpawnHook.cpp @@ -0,0 +1,26 @@ +#include "stdafx.h" + +#ifdef _EDITOR + +#include "EffectSpawnHook.h" + +namespace Core::EffectSpawnHook +{ +namespace +{ +Listener g_listener = nullptr; +} + +void SetListener(Listener listener) +{ + g_listener = listener; +} + +void Notify() +{ + if (g_listener != nullptr) + g_listener(); +} +} // namespace Core::EffectSpawnHook + +#endif // _EDITOR diff --git a/src/source/Core/Utilities/EffectSpawnHook.h b/src/source/Core/Utilities/EffectSpawnHook.h new file mode 100644 index 0000000000..695ce7ce2e --- /dev/null +++ b/src/source/Core/Utilities/EffectSpawnHook.h @@ -0,0 +1,19 @@ +#pragma once + +#ifdef _EDITOR + +// Lets the editor create things in the game's effect lists inside the game's update: after the sprites of the last +// frame are cleared and the world's effects moved and spawned theirs, before the world is culled and drawn (design +// section 7a). The Style Editor's views create their items' things on bones here. The scene code does not know the +// editor, so the editor sets the listener. +namespace Core::EffectSpawnHook +{ +using Listener = void (*)(); + +void SetListener(Listener listener); + +// Called by the main scene's update once a frame. +void Notify(); +} // namespace Core::EffectSpawnHook + +#endif // _EDITOR diff --git a/src/source/Data/GameData/Common/MeshLimits.h b/src/source/Data/GameData/Common/MeshLimits.h index 8eb32c399a..34507cece9 100644 --- a/src/source/Data/GameData/Common/MeshLimits.h +++ b/src/source/Data/GameData/Common/MeshLimits.h @@ -5,4 +5,8 @@ namespace Data // A model has at most this many meshes: MAX_MESH of the model drawing (Render/Models/ZzzBMD.h; LookDrawing.cpp checks // that the two agree). The data that names a mesh takes the numbers below it. inline constexpr int MaxModelMeshes = 50; + +// A model has at most this many bones: MAX_BONES of the model drawing, the size of every bone buffer a pose fills +// (LookDrawing.cpp checks that the two agree). The data that names a bone takes the numbers below it. +inline constexpr int MaxModelBones = 200; } // namespace Data diff --git a/src/source/Data/GameData/EffectData/EffectTypeCatalogue.cpp b/src/source/Data/GameData/EffectData/EffectTypeCatalogue.cpp index 3f7d4e88a1..9dc10ba17b 100644 --- a/src/source/Data/GameData/EffectData/EffectTypeCatalogue.cpp +++ b/src/source/Data/GameData/EffectData/EffectTypeCatalogue.cpp @@ -86,6 +86,18 @@ size_t EffectTypeCatalogue::GetTypeCount(EffectKind kind) const return m_byName[ToIndex(kind)].size(); } +std::vector EffectTypeCatalogue::GetNames(EffectKind kind) const +{ + std::vector names; + const std::vector& byName = m_byName[ToIndex(kind)]; + names.reserve(byName.size()); + for (const NamedType& named : byName) + { + names.emplace_back(named.name); + } + return names; +} + std::span EffectTypeCatalogue::GetCreateParams() const { return m_createParams; diff --git a/src/source/Data/GameData/EffectData/EffectTypeCatalogue.h b/src/source/Data/GameData/EffectData/EffectTypeCatalogue.h index aadc37961e..567d2165ad 100644 --- a/src/source/Data/GameData/EffectData/EffectTypeCatalogue.h +++ b/src/source/Data/GameData/EffectData/EffectTypeCatalogue.h @@ -34,6 +34,8 @@ class EffectTypeCatalogue std::string_view GetName(EffectKind kind, int type) const; size_t GetTypeCount(EffectKind kind) const; + // The names of the types of `kind`, sorted. + std::vector GetNames(EffectKind kind) const; // The effect types with creation values, sorted by number. std::span GetCreateParams() const; diff --git a/src/source/Data/GameData/LookData/BoneThingTypes.cpp b/src/source/Data/GameData/LookData/BoneThingTypes.cpp new file mode 100644 index 0000000000..bb69335b19 --- /dev/null +++ b/src/source/Data/GameData/LookData/BoneThingTypes.cpp @@ -0,0 +1,45 @@ +#include "stdafx.h" + +#include "BoneThingTypes.h" + +#include "Data/GameData/EffectData/EffectTypeCatalogue.h" + +namespace Data::Looks +{ +Effects::EffectKind CatalogueKindOf(BoneThingKind kind) +{ + switch (kind) + { + case BoneThingKind::Sprite: + return Effects::EffectKind::Sprite; + case BoneThingKind::Particle: + return Effects::EffectKind::Particle; + case BoneThingKind::Joint: + return Effects::EffectKind::Joint; + case BoneThingKind::Effect: + return Effects::EffectKind::Effect; + } + return Effects::EffectKind::Effect; +} + +const char* BoneThingKey(BoneThingKind kind) +{ + switch (kind) + { + case BoneThingKind::Sprite: + return "sprite"; + case BoneThingKind::Particle: + return "particle"; + case BoneThingKind::Joint: + return "joint"; + case BoneThingKind::Effect: + return "effect"; + } + return ""; +} + +std::optional FindBoneThingType(BoneThingKind kind, std::string_view type) +{ + return g_EffectTypeCatalogue.FindType(CatalogueKindOf(kind), type); +} +} // namespace Data::Looks diff --git a/src/source/Data/GameData/LookData/BoneThingTypes.h b/src/source/Data/GameData/LookData/BoneThingTypes.h new file mode 100644 index 0000000000..0e8de4d279 --- /dev/null +++ b/src/source/Data/GameData/LookData/BoneThingTypes.h @@ -0,0 +1,21 @@ +#pragma once + +#include "Data/GameData/EffectData/EffectKind.h" +#include "Data/GameData/LookData/LookDefinition.h" + +#include +#include + +// The effect catalogue's types of the things on bones (design L7, step 3): a thing names its type as FX1 named them +// (D30), and the game creates it by the type's number. +namespace Data::Looks +{ +// The catalogue's kind of a thing on bones. +Effects::EffectKind CatalogueKindOf(BoneThingKind kind); + +// The key a thing names its type with in the files ("sprite", "particle", "joint", "effect"). +const char* BoneThingKey(BoneThingKind kind); + +// The number of the thing's type in the effect catalogue, or nullopt for a name it doesn't have. +std::optional FindBoneThingType(BoneThingKind kind, std::string_view type); +} // namespace Data::Looks diff --git a/src/source/Data/GameData/LookData/LookChecks.cpp b/src/source/Data/GameData/LookData/LookChecks.cpp index 63ea1e3d2e..bba505b500 100644 --- a/src/source/Data/GameData/LookData/LookChecks.cpp +++ b/src/source/Data/GameData/LookData/LookChecks.cpp @@ -3,6 +3,7 @@ #include "LookChecks.h" #include "Data/GameData/ItemData/ItemType.h" +#include "Data/GameData/LookData/BoneThingTypes.h" #include "Data/GameData/LookData/LookJson.h" #include @@ -36,6 +37,72 @@ std::string LayerField(std::size_t look, std::size_t layer) return LookField(look) + ".layers[" + std::to_string(layer) + "]"; } +// A bone a thing on bones names and the field it is in. +struct NamedBone +{ + std::string field; + int bone = 0; +}; + +std::string OnBonesField(std::size_t look, std::size_t entry) +{ + return LookField(look) + ".onBones[" + std::to_string(entry) + "]"; +} + +// The field of an entry's places: its own, or its group's. +std::string PlacesField(const OnBones& entry, std::size_t look, std::size_t index) +{ + return OnBonesField(look, index) + (entry.together ? ".together" : ""); +} + +std::vector NamedBones(const LookDefinition& look, std::size_t index) +{ + std::vector named; + for (std::size_t i = 0; i < look.onBones.size(); ++i) + { + const OnBones& entry = look.onBones[i]; + const std::string field = PlacesField(entry, index, i); + for (const int bone : entry.places.bones) + { + named.push_back({field + ".bones", bone}); + } + for (const auto& [from, to] : entry.places.between) + { + named.push_back({field + ".between", from}); + named.push_back({field + ".between", to}); + } + } + return named; +} + +// A type the effect catalogue doesn't have is an error: the game creates nothing of that thing. +void CheckBoneThingTypes(const LookDefinition& look, std::size_t index, const std::string& source, + const RenderStyleCheckInput& input, std::vector& issues) +{ + if (!input.typeExists) + { + return; + } + for (std::size_t i = 0; i < look.onBones.size(); ++i) + { + const OnBones& entry = look.onBones[i]; + for (std::size_t j = 0; j < entry.things.size(); ++j) + { + const BoneThing& thing = entry.things[j]; + if (input.typeExists(thing.kind, thing.type)) + { + continue; + } + const std::string field = + OnBonesField(index, i) + (entry.together ? ".things[" + std::to_string(j) + "]" : ""); + issues.push_back({ItemDataIssueSeverity::Error, source, ItemDataIssue::NoItem, ItemDataIssue::NoItem, + field + "." + BoneThingKey(thing.kind), + "\"" + thing.type + "\" is no " + BoneThingKey(thing.kind) + + " type of the effect catalogue; it is not created"}); + } + } +} + // The meshes of a look that an item's model must have; "none" and "every mesh" are none of them. std::vector NamedMeshes(const LookDefinition& look, std::size_t index) { @@ -186,6 +253,7 @@ void CheckUsers(const LookDefinition& look, std::size_t index, const std::string { const bool effect = kind == LookKind::ItemEffect; const std::vector named = NamedMeshes(look, index); + const std::vector bones = NamedBones(look, index); bool used = false; for (const Items::ItemModelDefinition& model : input.models) { @@ -200,7 +268,20 @@ void CheckUsers(const LookDefinition& look, std::size_t index, const std::string { itemNamed = NamedMeshes(CheckItemValues(look, index, source, input, model, kind, issues), index); } - const int meshCount = input.meshCount ? input.meshCount(Items::MakeItemType(model.group, model.number)) : 0; + const int itemType = Items::MakeItemType(model.group, model.number); + if (const int boneCount = input.boneCount ? input.boneCount(itemType) : 0; boneCount > 0) + { + for (const NamedBone& bone : bones) + { + if (bone.bone >= boneCount) + { + issues.push_back({ItemDataIssueSeverity::Warning, source, model.group, model.number, bone.field, + "bone " + std::to_string(bone.bone) + " is not in this item's model, which has " + + std::to_string(boneCount) + (boneCount == 1 ? " bone" : " bones")}); + } + } + } + const int meshCount = input.meshCount ? input.meshCount(itemType) : 0; if (meshCount <= 0) { continue; @@ -255,6 +336,7 @@ void CheckItemEffects(std::span looks, const std::string& { for (std::size_t i = 0; i < looks.size(); ++i) { + CheckBoneThingTypes(looks[i], i, source, input, issues); CheckUsers(looks[i], i, source, input, LookKind::ItemEffect, issues); } } diff --git a/src/source/Data/GameData/LookData/LookChecks.h b/src/source/Data/GameData/LookData/LookChecks.h index b4a10c13e0..23bff641a2 100644 --- a/src/source/Data/GameData/LookData/LookChecks.h +++ b/src/source/Data/GameData/LookData/LookChecks.h @@ -25,6 +25,10 @@ struct RenderStyleCheckInput // The number of meshes of an item's model (by item type); 0 when the model is not loaded, which skips its mesh // checks. std::function meshCount; + // Whether the effect catalogue has a type of this kind and name (things on bones); none skips the check. + std::function typeExists; + // The number of bones of an item's model; 0 when the model is not loaded, which skips its bone checks. + std::function boneCount; }; // Appends the problems of `looks`, the looks of `source` as read without a fatal problem (so looks[i] is the file's @@ -34,7 +38,9 @@ void CheckRenderStyles(std::span looks, const std::string& const RenderStyleCheckInput& input, std::vector& issues); // Appends the problems of the item effects `looks`: a mesh number an item's model doesn't have (warning, about that -// item), a value an item sets that the effect doesn't let it set, an effect no item uses (warning). +// item), a value an item sets that the effect doesn't let it set, an effect no item uses (warning), a thing on bones +// of a type the effect catalogue doesn't have (error: it is not created), a bone an item's model doesn't have +// (warning, about that item). void CheckItemEffects(std::span looks, const std::string& source, const RenderStyleCheckInput& input, std::vector& issues); diff --git a/src/source/Data/GameData/LookData/LookDefinition.h b/src/source/Data/GameData/LookData/LookDefinition.h index c9dd01eb5c..649bc21120 100644 --- a/src/source/Data/GameData/LookData/LookDefinition.h +++ b/src/source/Data/GameData/LookData/LookDefinition.h @@ -53,6 +53,8 @@ enum class Blend Normal, // Added (RENDER_BRIGHT). Glow, + // Darkens what is below it (RENDER_DARK), as the Pumpkin of Luck's reflection. + Darken, // The drawing's own render type, which a doppelganger or a monster's hands set (RenderBody(RenderType, ...)). AsDrawing, }; @@ -125,6 +127,9 @@ using Number = std::variant; // drawing's opacity, a number, or a shape. struct FromItem { + // The item's value times this (design L59): the Cursed Castle Water glows at 1.5 and 0.25 of the item's. + float times = 1.f; + bool operator==(const FromItem&) const = default; }; struct FromDrawing @@ -301,6 +306,77 @@ struct ItemValuesBefore bool operator==(const ItemValuesBefore&) const = default; }; +// What a thing on bones is (design L7, step 3; section 7b): a type of the effect catalogue (FX1) of this kind. +enum class BoneThingKind +{ + Sprite, + Particle, + // Lightning between two bones (CreateJoint). + Joint, + Effect, +}; + +// How a chance draws (design L56): once in `oneIn` frames at the game's reference frame rate (rand_fps_check), or +// Random::Rand() % oneIn == 0, as the monster sounds draw theirs. +enum class ChanceDraw +{ + Fps, + Plain, +}; + +// A chance per frame (design L56), for each bone or pair, or once for all of them. +struct Chance +{ + int oneIn = 1; + ChanceDraw draw = ChanceDraw::Fps; + bool once = false; + + bool operator==(const Chance&) const = default; +}; + +// Where things on bones are created (design L55): at each bone, between each pair of bones (lightning, from the first +// to the second), or at the item object's own place. +struct BonePlaces +{ + std::vector bones; + std::vector> between; + bool origin = false; + + bool operator==(const BonePlaces&) const = default; +}; + +// One thing an item effect creates on the item's bones each frame (section 7b), in the update from the item's pose. +struct BoneThing +{ + BoneThingKind kind = BoneThingKind::Sprite; + // The type's name in the effect catalogue. + std::string type; + int subType = 0; + Number scale = 1.f; + // Red, green and blue: the sprite's color, the light of a particle, lightning or effect. + std::array color{1.f, 1.f, 1.f}; + // A sprite's rotation. + Number rotation = 0.f; + // Lightning from the second bone of each pair to the first. + bool reversed = false; + // A thing of a group rolls this too, after the group's (the Wing of Storm's thunder). + std::optional chance; + + bool operator==(const BoneThing&) const = default; +}; + +// An entry of "onBones": one thing, or a group of things ("together") that share its places and its chance, so they +// come together (design L56). A single thing's chance is the entry's. +struct OnBones +{ + BonePlaces places; + std::optional chance; + std::vector things; + bool together = false; + + bool operator==(const OnBones&) const = default; +}; + struct LookDefinition { std::string name; @@ -317,6 +393,11 @@ struct LookDefinition // light. std::vector itemValuesBefore; std::optional> objectLight; + // The things it creates on the item's bones each frame (design L7, step 3). + std::vector onBones; + // How fast the update plays the item object's animation (BMD::PlayAnimation), as the Cursed Castle Water's ground + // item moves (design L29); without one the update plays none. + std::optional animationSpeed; bool operator==(const LookDefinition&) const = default; }; diff --git a/src/source/Data/GameData/LookData/LookJson.cpp b/src/source/Data/GameData/LookData/LookJson.cpp index 9a3544b5ae..71c08c8298 100644 --- a/src/source/Data/GameData/LookData/LookJson.cpp +++ b/src/source/Data/GameData/LookData/LookJson.cpp @@ -71,6 +71,24 @@ constexpr const char* DrawingOpacity = "drawingOpacity"; constexpr const char* GlowsLikeLevel = "glowsLikeLevel"; constexpr const char* ObjectLight = "objectLight"; constexpr const char* DrawsAlone = "drawsAlone"; +constexpr const char* OnBones = "onBones"; +constexpr const char* SubType = "subType"; +constexpr const char* Bones = "bones"; +constexpr const char* Between = "between"; +constexpr const char* At = "at"; +constexpr const char* Origin = "origin"; +constexpr const char* Scale = "scale"; +constexpr const char* Color = "color"; +constexpr const char* Rotation = "rotation"; +constexpr const char* Reversed = "reversed"; +constexpr const char* Chance = "chance"; +constexpr const char* OneIn = "oneIn"; +constexpr const char* Draw = "draw"; +constexpr const char* Per = "per"; +constexpr const char* Together = "together"; +constexpr const char* Things = "things"; +constexpr const char* ItemTimes = "itemTimes"; +constexpr const char* AnimationSpeed = "animationSpeed"; } // namespace Keys constexpr const char* RenderStyleKind = "renderStyle"; @@ -102,9 +120,10 @@ constexpr std::array, 9> MotionNames{{ {Motion::StillShine, "stillShine"}, }}; -constexpr std::array, 3> BlendNames{{ +constexpr std::array, 4> BlendNames{{ {Blend::Normal, "normal"}, {Blend::Glow, "glow"}, + {Blend::Darken, "darken"}, {Blend::AsDrawing, "asDrawing"}, }}; @@ -147,6 +166,25 @@ constexpr std::array, 1> BuffNames{{ {LookBuff::InfinityArrow, "infinityArrow"}, }}; +// The key of a thing on bones names its kind; its value is the type's name in the effect catalogue. +constexpr std::array, 4> BoneThingKindNames{{ + {BoneThingKind::Sprite, "sprite"}, + {BoneThingKind::Particle, "particle"}, + {BoneThingKind::Joint, "joint"}, + {BoneThingKind::Effect, "effect"}, +}}; + +constexpr std::array, 2> ChanceDrawNames{{ + {ChanceDraw::Fps, "fps"}, + {ChanceDraw::Plain, "plain"}, +}}; + +constexpr const char* PerEach = "each"; +constexpr const char* PerOnce = "once"; + +// The highest bone number a thing on bones names; a model's own bones are checked when it is created. +constexpr int MaxBone = MaxModelBones - 1; + // The highest item level, for a layer's level condition. constexpr long long MaxItemLevel = 15; @@ -280,6 +318,15 @@ class LookReader void ReadNotFor(const OrderedJson& json, const std::string& field, NotFor& notFor); OrderedJson TakeEachItem(const OrderedJson& json, const std::string& field, EachItemFields& eachItem); void ReadOnlyWhen(const OrderedJson& json, const std::string& field, OnlyWhen& onlyWhen); + void ReadOnBones(const OrderedJson& json, const std::string& field, std::vector& onBones); + bool ReadOnBonesEntry(const OrderedJson& json, const std::string& field, OnBones& entry); + bool ReadBoneThing(const OrderedJson& json, const std::string& field, bool inGroup, BoneThing& thing); + bool ReadBonePlaces(const OrderedJson& json, const std::string& field, BonePlaces& places); + bool ReadChance(const OrderedJson& json, const std::string& field, std::optional& chance, + bool ofPlaces = true); + bool ReadColor(const OrderedJson& json, const std::string& field, std::array& color); + // Whether the thing's kind fits the places: lightning goes between pairs, everything else at bones or the origin. + bool PlacesFit(const BoneThing& thing, const BonePlaces& places, const std::string& field); template bool ReadName(const OrderedJson& json, const char* key, const std::string& field, @@ -395,13 +442,16 @@ void LookReader::ReadRenderStyleParts(const OrderedJson& json, const std::string AddFatal(field + "." + Keys::ItemValuesBefore, "is a part of item effects; a render style leaves its item values after drawing (itemValuesAfter)"); } - if (json.contains(Keys::ObjectLight)) + for (const char* part : {Keys::ObjectLight, Keys::OnBones, Keys::AnimationSpeed}) { - AddFatal(field + "." + Keys::ObjectLight, "is a part of item effects"); + if (json.contains(part)) + { + AddFatal(field + "." + part, "is a part of item effects"); + } } WarnAboutUnknownKeys(json, {Keys::Name, Keys::NotFor, Keys::DrawsAlone, Keys::Layers, Keys::ItemValuesAfter, - Keys::ItemValuesBefore, Keys::ObjectLight}, + Keys::ItemValuesBefore, Keys::ObjectLight, Keys::OnBones, Keys::AnimationSpeed}, field); } @@ -451,17 +501,360 @@ void LookReader::ReadItemEffectParts(const OrderedJson& json, const std::string& look.objectLight = color; } } - if (look.itemValuesBefore.empty() && !look.objectLight) + ReadOnBones(json, field, look.onBones); + if (const auto speed = json.find(Keys::AnimationSpeed); speed != json.end()) + { + if (!speed->is_number() || speed->get() <= 0.f) + { + AddFatal(field + "." + Keys::AnimationSpeed, + "must be a number above 0: how fast the object's animation plays"); + } + else + { + look.animationSpeed = speed->get(); + } + } + if (look.itemValuesBefore.empty() && !look.objectLight && look.onBones.empty() && !look.animationSpeed) { AddIssue(ItemDataIssueSeverity::Warning, field, - "does nothing: no item values before the drawing, no object light"); + "does nothing: no item values before the drawing, no object light, nothing on bones, no animation"); } WarnAboutUnknownKeys(json, - {Keys::Name, Keys::ItemValuesBefore, Keys::ObjectLight, Keys::Layers, Keys::NotFor, - Keys::DrawsAlone, Keys::ItemValuesAfter}, + {Keys::Name, Keys::ItemValuesBefore, Keys::ObjectLight, Keys::OnBones, Keys::AnimationSpeed, + Keys::Layers, Keys::NotFor, Keys::DrawsAlone, Keys::ItemValuesAfter}, field); } +// The things an item effect creates on the item's bones (section 7b): a list of entries, each one thing or a group. +void LookReader::ReadOnBones(const OrderedJson& json, const std::string& field, std::vector& onBones) +{ + const auto list = json.find(Keys::OnBones); + if (list == json.end()) + { + return; + } + const std::string listField = field + "." + Keys::OnBones; + if (!list->is_array()) + { + AddFatal(listField, "must be a list of things on bones"); + return; + } + for (std::size_t i = 0; i < list->size(); ++i) + { + OnBones entry; + if (ReadOnBonesEntry((*list)[i], listField + "[" + std::to_string(i) + "]", entry)) + { + onBones.push_back(std::move(entry)); + } + } +} + +bool LookReader::PlacesFit(const BoneThing& thing, const BonePlaces& places, const std::string& field) +{ + const bool joint = thing.kind == BoneThingKind::Joint; + if (joint == !places.between.empty()) + { + return true; + } + AddFatal(field, joint ? "is lightning: it goes between pairs of bones (\"between\")" + : "goes at bones or at the origin: only lightning goes between pairs of bones"); + return false; +} + +bool LookReader::ReadOnBonesEntry(const OrderedJson& json, const std::string& field, OnBones& entry) +{ + if (!json.is_object()) + { + AddFatal(field, "must be a thing on bones, e.g. {\"sprite\": \"light\", \"bones\": [8]}, or a group"); + return false; + } + const auto together = json.find(Keys::Together); + if (together == json.end()) + { + // One thing: its places and its chance are the entry's. + BoneThing thing; + if (!ReadBoneThing(json, field, false, thing)) + { + return false; + } + if (!ReadBonePlaces(json, field, entry.places) || !PlacesFit(thing, entry.places, field)) + { + return false; + } + entry.chance = thing.chance; + thing.chance.reset(); + entry.things.push_back(std::move(thing)); + return true; + } + // A group: its places and chance in "together", its things in "things". + entry.together = true; + const std::string groupField = field + "." + Keys::Together; + if (!together->is_object()) + { + AddFatal(groupField, "must hold the group's places (\"bones\", \"between\" or \"at\") and its chance"); + return false; + } + const bool placesRead = ReadBonePlaces(*together, groupField, entry.places); + bool valid = ReadChance(*together, groupField, entry.chance) && placesRead; + WarnAboutUnknownKeys(*together, {Keys::Bones, Keys::Between, Keys::At, Keys::Chance}, groupField); + WarnAboutUnknownKeys(json, {Keys::Together, Keys::Things}, field); + const auto things = json.find(Keys::Things); + const std::string thingsField = field + "." + Keys::Things; + if (things == json.end() || !things->is_array() || things->empty()) + { + AddFatal(thingsField, "must be a list of the things the group creates together"); + return false; + } + for (std::size_t i = 0; i < things->size(); ++i) + { + const std::string thingField = thingsField + "[" + std::to_string(i) + "]"; + BoneThing thing; + if (!ReadBoneThing((*things)[i], thingField, true, thing)) + { + valid = false; + continue; + } + // Against places that were read (a fault in them is named already), whatever failed before this thing. + if (placesRead) + { + valid = PlacesFit(thing, entry.places, thingField) && valid; + } + entry.things.push_back(std::move(thing)); + } + return valid; +} + +// The kind and type, sub type, values and (in a group) the thing's own chance; places are read by the caller. +bool LookReader::ReadBoneThing(const OrderedJson& json, const std::string& field, bool inGroup, BoneThing& thing) +{ + if (!json.is_object()) + { + AddFatal(field, "must be a thing on bones, e.g. {\"sprite\": \"light\"}"); + return false; + } + int kinds = 0; + for (const auto& [kind, key] : BoneThingKindNames) + { + const auto type = json.find(key); + if (type == json.end()) + { + continue; + } + ++kinds; + thing.kind = kind; + if (!type->is_string() || type->get_ref().empty()) + { + AddFatal(field + "." + key, "must be the name of a type in the effect catalogue"); + return false; + } + thing.type = type->get(); + } + if (kinds != 1) + { + AddFatal(field, "must name one type: " + ListOf(BoneThingKindNames)); + return false; + } + const auto addFatal = [this](const std::string& at, const std::string& message) { AddFatal(at, message); }; + bool valid = true; + if (const auto subType = json.find(Keys::SubType); subType != json.end()) + { + valid = Items::Json::ReadWholeNumberInRange(*subType, field + "." + Keys::SubType, 0, MaxBoneThingSubType, + thing.subType, addFatal); + } + if (const auto scale = json.find(Keys::Scale); scale != json.end()) + { + valid = ReadNumber(*scale, field + "." + Keys::Scale, thing.scale) && valid; + } + if (const auto color = json.find(Keys::Color); color != json.end()) + { + valid = ReadColor(*color, field + "." + Keys::Color, thing.color) && valid; + } + if (const auto rotation = json.find(Keys::Rotation); rotation != json.end()) + { + if (thing.kind != BoneThingKind::Sprite) + { + AddFatal(field + "." + Keys::Rotation, "is only for a sprite"); + valid = false; + } + valid = ReadNumber(*rotation, field + "." + Keys::Rotation, thing.rotation) && valid; + } + if (const auto reversed = json.find(Keys::Reversed); reversed != json.end()) + { + if (!reversed->is_boolean() || thing.kind != BoneThingKind::Joint) + { + AddFatal(field + "." + Keys::Reversed, "is true or false, only for lightning"); + valid = false; + } + else + { + thing.reversed = reversed->get(); + } + } + valid = ReadChance(json, field, thing.chance, !inGroup) && valid; + Items::Json::KeySet known{Keys::SubType, Keys::Scale, Keys::Color, Keys::Rotation, Keys::Reversed, Keys::Chance}; + for (const auto& [kind, key] : BoneThingKindNames) + { + known.insert(key); + } + if (inGroup) + { + for (const char* key : {Keys::Bones, Keys::Between, Keys::At}) + { + if (json.contains(key)) + { + AddFatal(field + "." + key, "is the group's: the things of a group share its places"); + valid = false; + } + } + } + else + { + known.insert({Keys::Bones, Keys::Between, Keys::At}); + } + WarnAboutUnknownKeys(json, known, field); + return valid; +} + +// "bones": [8, 9], "between": [[30, 22]] or "at": "origin", exactly one of them. +bool LookReader::ReadBonePlaces(const OrderedJson& json, const std::string& field, BonePlaces& places) +{ + const auto bones = json.find(Keys::Bones); + const auto between = json.find(Keys::Between); + const auto at = json.find(Keys::At); + const int named = (bones != json.end() ? 1 : 0) + (between != json.end() ? 1 : 0) + (at != json.end() ? 1 : 0); + if (named != 1) + { + AddFatal(field, "must name its places once: \"bones\", \"between\" or \"at\": \"origin\""); + return false; + } + const auto addFatal = [this](const std::string& at, const std::string& message) { AddFatal(at, message); }; + if (at != json.end()) + { + if (!at->is_string() || at->get_ref() != Keys::Origin) + { + AddFatal(field + "." + Keys::At, "must be \"origin\": the item object's own place"); + return false; + } + places.origin = true; + return true; + } + if (bones != json.end()) + { + const std::string bonesField = field + "." + Keys::Bones; + if (!bones->is_array() || bones->empty()) + { + AddFatal(bonesField, "must be a list of bone numbers"); + return false; + } + bool valid = true; + for (std::size_t i = 0; i < bones->size(); ++i) + { + int bone = 0; + valid = Items::Json::ReadWholeNumberInRange((*bones)[i], bonesField + "[" + std::to_string(i) + "]", 0, + MaxBone, bone, addFatal) && + valid; + places.bones.push_back(bone); + } + return valid; + } + const std::string betweenField = field + "." + Keys::Between; + if (!between->is_array() || between->empty()) + { + AddFatal(betweenField, "must be a list of pairs of bones, [from, to]"); + return false; + } + bool valid = true; + for (std::size_t i = 0; i < between->size(); ++i) + { + const std::string pairField = betweenField + "[" + std::to_string(i) + "]"; + const OrderedJson& pair = (*between)[i]; + if (!pair.is_array() || pair.size() != 2) + { + AddFatal(pairField, "must be a pair of bones, [from, to]"); + valid = false; + continue; + } + std::pair bonePair; + valid = Items::Json::ReadWholeNumberInRange(pair[0], pairField + "[0]", 0, MaxBone, bonePair.first, addFatal) && + valid; + valid = + Items::Json::ReadWholeNumberInRange(pair[1], pairField + "[1]", 0, MaxBone, bonePair.second, addFatal) && + valid; + places.between.push_back(bonePair); + } + return valid; +} + +// "chance": {"oneIn": 2, "draw": "plain", "per": "once"}; without draw and per: rand_fps_check for each place. A +// thing's own chance in a group (not ofPlaces) rolls once each time the group's holds, so it has no "per". +bool LookReader::ReadChance(const OrderedJson& json, const std::string& field, std::optional& chance, + bool ofPlaces) +{ + const auto entry = json.find(Keys::Chance); + if (entry == json.end()) + { + return true; + } + const std::string chanceField = field + "." + Keys::Chance; + if (!entry->is_object()) + { + AddFatal(chanceField, "must be {\"oneIn\": N}: once in N frames"); + return false; + } + const auto oneIn = entry->find(Keys::OneIn); + if (oneIn == entry->end()) + { + AddFatal(chanceField + "." + Keys::OneIn, "is missing: once in how many frames"); + return false; + } + const auto addFatal = [this](const std::string& at, const std::string& message) { AddFatal(at, message); }; + Chance read; + bool valid = Items::Json::ReadWholeNumberInRange(*oneIn, chanceField + "." + Keys::OneIn, 1, MaxBoneThingOneIn, + read.oneIn, addFatal); + if (entry->contains(Keys::Draw)) + { + valid = ReadName(*entry, Keys::Draw, chanceField, ChanceDrawNames, read.draw) && valid; + } + if (const auto per = entry->find(Keys::Per); per != entry->end() && !ofPlaces) + { + AddFatal(chanceField + "." + Keys::Per, + "is the group's: a thing's own chance rolls once each time the group's chance holds"); + valid = false; + } + else if (per != entry->end()) + { + const std::string text = per->is_string() ? per->get() : std::string(); + read.once = text == PerOnce; + if (text != PerEach && text != PerOnce) + { + AddFatal(chanceField + "." + Keys::Per, + std::string("must be \"") + PerEach + "\" (each place) or \"" + PerOnce + "\" (all at once)"); + valid = false; + } + } + WarnAboutUnknownKeys(*entry, {Keys::OneIn, Keys::Draw, Keys::Per}, chanceField); + if (valid) + { + chance = read; + } + return valid; +} + +bool LookReader::ReadColor(const OrderedJson& json, const std::string& field, std::array& color) +{ + if (!json.is_array() || json.size() != 3) + { + AddFatal(field, "must be [red, green, blue]: three numbers or shapes"); + return false; + } + bool valid = true; + for (std::size_t i = 0; i < 3; ++i) + { + valid = ReadNumber(json[i], field + "[" + std::to_string(i) + "]", color[i]) && valid; + } + return valid; +} + void LookReader::ReadItemValuesBefore(const OrderedJson& marked, const std::string& field, ItemValuesBefore& entry) { if (!marked.is_object()) @@ -757,6 +1150,20 @@ void LookReader::ReadValue(const OrderedJson& json, const char* key, const std:: value = FromDrawing{}; return; } + if (entry->is_object() && entry->contains(Keys::ItemTimes)) + { + // The item's value times a number (design L59). + const OrderedJson& times = (*entry)[Keys::ItemTimes]; + if (!times.is_number()) + { + AddFatal(field + "." + key + "." + Keys::ItemTimes, + "must be a number: the item's value is multiplied by it"); + return; + } + WarnAboutUnknownKeys(*entry, {Keys::ItemTimes}, field + "." + key); + value = FromItem{times.get()}; + return; + } if (entry->is_object()) { Shape shape; @@ -1063,6 +1470,116 @@ OrderedJson WriteNumber(const Number& number) return WriteFloat(std::get(number)); } +OrderedJson WriteColor(const std::array& color) +{ + OrderedJson json = OrderedJson::array(); + for (const Number& channel : color) + { + json.push_back(WriteNumber(channel)); + } + return json; +} + +void WriteBonePlaces(const BonePlaces& places, OrderedJson& json) +{ + if (places.origin) + { + json[Keys::At] = Keys::Origin; + } + else if (!places.between.empty()) + { + OrderedJson pairs = OrderedJson::array(); + for (const auto& [from, to] : places.between) + { + pairs.push_back(OrderedJson::array({from, to})); + } + json[Keys::Between] = std::move(pairs); + } + else + { + json[Keys::Bones] = places.bones; + } +} + +void WriteChance(const std::optional& chance, OrderedJson& json) +{ + if (!chance) + { + return; + } + OrderedJson written = OrderedJson::object(); + written[Keys::OneIn] = chance->oneIn; + if (chance->draw != ChanceDraw::Fps) + { + written[Keys::Draw] = NameOf(ChanceDrawNames, chance->draw); + } + if (chance->once) + { + written[Keys::Per] = PerOnce; + } + json[Keys::Chance] = std::move(written); +} + +// A thing's kind and type, sub type and values that are not the defaults; its places go after, or to the group. +OrderedJson WriteBoneThing(const BoneThing& thing) +{ + OrderedJson json = OrderedJson::object(); + json[NameOf(BoneThingKindNames, thing.kind)] = thing.type; + if (thing.subType != 0) + { + json[Keys::SubType] = thing.subType; + } + if (thing.reversed) + { + json[Keys::Reversed] = true; + } + return json; +} + +void WriteBoneThingValues(const BoneThing& thing, OrderedJson& json) +{ + if (thing.scale != Number{1.f}) + { + json[Keys::Scale] = WriteNumber(thing.scale); + } + if (thing.color != std::array{1.f, 1.f, 1.f}) + { + json[Keys::Color] = WriteColor(thing.color); + } + if (thing.rotation != Number{0.f}) + { + json[Keys::Rotation] = WriteNumber(thing.rotation); + } +} + +OrderedJson WriteOnBones(const OnBones& entry) +{ + if (!entry.together && entry.things.size() == 1) + { + const BoneThing& thing = entry.things.front(); + OrderedJson json = WriteBoneThing(thing); + WriteBonePlaces(entry.places, json); + WriteBoneThingValues(thing, json); + WriteChance(entry.chance, json); + return json; + } + OrderedJson group = OrderedJson::object(); + WriteBonePlaces(entry.places, group); + WriteChance(entry.chance, group); + OrderedJson things = OrderedJson::array(); + for (const BoneThing& thing : entry.things) + { + OrderedJson json = WriteBoneThing(thing); + WriteBoneThingValues(thing, json); + WriteChance(thing.chance, json); + things.push_back(std::move(json)); + } + OrderedJson json = OrderedJson::object(); + json[Keys::Together] = std::move(group); + json[Keys::Things] = std::move(things); + return json; +} + OrderedJson WriteValue(const Value& value) { if (std::holds_alternative(value)) @@ -1073,12 +1590,19 @@ OrderedJson WriteValue(const Value& value) { return WriteShape(*shape); } + if (const FromItem* item = std::get_if(&value)) + { + OrderedJson json = OrderedJson::object(); + json[Keys::ItemTimes] = WriteFloat(item->times); + return json; + } return WriteFloat(std::get(value)); } void PutValue(OrderedJson& json, const char* key, const Value& value) { - if (!std::holds_alternative(value)) + // The item's value as it is is a layer's default. + if (value != Value{FromItem{}}) { json[key] = WriteValue(value); } @@ -1520,6 +2044,19 @@ std::string WriteLookFileJson(LookKind kind, std::vector looks, } json[Keys::ObjectLight] = std::move(light); } + if (!look.onBones.empty()) + { + OrderedJson onBones = OrderedJson::array(); + for (const OnBones& entry : look.onBones) + { + onBones.push_back(WriteOnBones(entry)); + } + json[Keys::OnBones] = std::move(onBones); + } + if (look.animationSpeed) + { + json[Keys::AnimationSpeed] = WriteFloat(*look.animationSpeed); + } list.push_back(std::move(json)); continue; } @@ -1560,6 +2097,7 @@ std::string WriteLookFileJson(LookKind kind, std::vector looks, text = Items::Json::PutObjectsOnOneLine(text, Keys::ItemValuesAfter); text = Items::Json::PutListEntriesOnOneLine(text, Keys::ItemValuesBefore); text = Items::Json::PutListsOnOneLine(text, Keys::ObjectLight); + text = Items::Json::PutListEntriesOnOneLine(text, Keys::OnBones); return text + "\n"; } diff --git a/src/source/Data/GameData/LookData/LookJson.h b/src/source/Data/GameData/LookData/LookJson.h index a52ee0714c..ee89b5f93a 100644 --- a/src/source/Data/GameData/LookData/LookJson.h +++ b/src/source/Data/GameData/LookData/LookJson.h @@ -24,6 +24,10 @@ namespace Data::Looks { constexpr int LookFileFormatVersion = 1; +// The highest SubType and "oneIn" of a thing on bones the files take; the Style Editor's fields keep to them. +constexpr int MaxBoneThingSubType = 1000; +constexpr int MaxBoneThingOneIn = 10000; + // "RenderStyles.json". std::string_view GetRenderStylesFileName(); diff --git a/src/source/Engine/Object/ZzzObject.cpp b/src/source/Engine/Object/ZzzObject.cpp index 0b46775f4d..2c7f2c7f64 100644 --- a/src/source/Engine/Object/ZzzObject.cpp +++ b/src/source/Engine/Object/ZzzObject.cpp @@ -7338,7 +7338,7 @@ static bool IsSparkingEventModel(const OBJECT* o) bool PartObjectSpawns(const OBJECT* o, int Type) { - return Render::Items::ItemEffects::Spawns(Type) || Render::Items::Styles::Spawns(Type) || IsSparkingEventModel(o); + return Render::Items::ItemEffects::Spawns(Type) || IsSparkingEventModel(o); } void SpawnPartObjectEffect(BMD* b, OBJECT* o, int Type, vec34_t* bones) @@ -7348,11 +7348,6 @@ void SpawnPartObjectEffect(BMD* b, OBJECT* o, int Type, vec34_t* bones) Render::Items::ItemEffects::Spawn(b, o, Type, bones); return; } - if (Render::Items::Styles::Spawns(Type)) - { - Render::Items::Styles::Spawn(b, o, Type, bones); - return; - } if (!IsSparkingEventModel(o)) return; diff --git a/src/source/Engine/Object/ZzzOpenData.cpp b/src/source/Engine/Object/ZzzOpenData.cpp index 340a217e01..dfdc032898 100644 --- a/src/source/Engine/Object/ZzzOpenData.cpp +++ b/src/source/Engine/Object/ZzzOpenData.cpp @@ -2131,6 +2131,7 @@ static void OpenBasicDataStep5() { OpenItemTextures(); Render::Items::Looks::PrepareTextures(); + Render::Items::Looks::LogUnknownBoneThingTypes(); } static void OpenBasicDataStep6() diff --git a/src/source/Render/Effects/PreviewSlots.cpp b/src/source/Render/Effects/PreviewSlots.cpp new file mode 100644 index 0000000000..f825a51924 --- /dev/null +++ b/src/source/Render/Effects/PreviewSlots.cpp @@ -0,0 +1,115 @@ +#include "stdafx.h" + +#ifdef _EDITOR + +#include "PreviewSlots.h" + +#include "Audio/EditorSoundMute.h" + +#include +#include +#include + +namespace Render::Effects::PreviewSlots +{ +namespace +{ +// Per list and slot, the view it belongs to; slots past the end are the game's. +std::array, ListCount> s_marks; +// Whether each view's time is stopped, by view. +std::array s_stopped{}; +View s_captured = 0; +bool s_anyMarked = false; + +std::vector& MarksOf(List list) +{ + return s_marks[static_cast(list)]; +} +} // namespace + +void Clear() +{ + if (!s_anyMarked) + { + return; + } + for (std::vector& marks : s_marks) + { + marks.assign(marks.size(), 0); + } + s_anyMarked = false; +} + +void Mark(List list, int index, View view) +{ + if (index < 0) + { + return; + } + std::vector& marks = MarksOf(list); + if (static_cast(index) >= marks.size()) + { + marks.resize(static_cast(index) + 1, 0); + } + marks[static_cast(index)] = view; + s_anyMarked = s_anyMarked || view != 0; +} + +void Born(List list, int index) +{ + std::vector& marks = MarksOf(list); + if (index >= 0 && static_cast(index) < marks.size()) + { + marks[static_cast(index)] = 0; + } +} + +View ViewOf(List list, int index) +{ + const std::vector& marks = MarksOf(list); + return index >= 0 && static_cast(index) < marks.size() ? marks[static_cast(index)] : 0; +} + +bool Draws(List list, int index) +{ + return ViewOf(list, index) == s_captured; +} + +bool Moves(List list, int index) +{ + const View view = ViewOf(list, index); + return view == 0 || !s_stopped[view]; +} + +void SetStopped(View view, bool stopped) +{ + s_stopped[view] = stopped && view != 0; +} + +bool IsCapturing() +{ + return s_captured != 0; +} + +CaptureScope::CaptureScope(View view) : m_previous(s_captured) +{ + s_captured = view; +} + +CaptureScope::~CaptureScope() +{ + s_captured = m_previous; +} + +MoveSoundScope::MoveSoundScope(List list, int index) +{ + if (ViewOf(list, index) != 0) + { + m_mute.emplace(); + } +} + +MoveSoundScope::~MoveSoundScope() = default; +} // namespace Render::Effects::PreviewSlots + +#endif // _EDITOR diff --git a/src/source/Render/Effects/PreviewSlots.h b/src/source/Render/Effects/PreviewSlots.h new file mode 100644 index 0000000000..ca950dce74 --- /dev/null +++ b/src/source/Render/Effects/PreviewSlots.h @@ -0,0 +1,93 @@ +#pragma once + +#include "Audio/EditorSoundMute.h" + +#include +#include + +// The slots of the game's effect lists that belong to a view of an editor preview (design L51): the Style Editor's +// views create their items' things on bones with the game's own calls into the game's lists, and the game moves them, +// but the world doesn't draw them; each view draws only its own, after its item. Each slot carries the view it belongs +// to, 0 for the game's own. The draw loops ask Draws, the move loops Moves. In game builds nothing is marked. +namespace Render::Effects::PreviewSlots +{ +enum class List : std::uint8_t +{ + // The effects, then the skill effects, as RenderEffects counts them. + Effect, + Particle, + Joint, + Sprite, +}; + +inline constexpr int ListCount = 4; + +// A view of a preview; 0 is the game. +using View = std::uint8_t; + +#ifdef _EDITOR +// Forgets every mark. +void Clear(); +void Mark(List list, int index, View view); +// A create call took the slot for something new: whoever creates it, it is the game's until a view marks it. A view +// whose thing ended in the slot sees that the slot is no longer its own, even when the new thing has the same type. +void Born(List list, int index); +[[nodiscard]] View ViewOf(List list, int index); +// Whether the draw loops draw the slot now: the game's slots, or only the captured view's while one is captured. +[[nodiscard]] bool Draws(List list, int index); +// Whether the game moves the slot: not while its view's time is stopped (design L54). +[[nodiscard]] bool Moves(List list, int index); +void SetStopped(View view, bool stopped); +// Whether a view is being captured: its things are drawn whatever the world's camera sees. +[[nodiscard]] bool IsCapturing(); + +// While it lives, the draw loops draw only the slots of `view`. +class CaptureScope +{ +public: + explicit CaptureScope(View view); + ~CaptureScope(); + CaptureScope(const CaptureScope&) = delete; + CaptureScope& operator=(const CaptureScope&) = delete; + +private: + View m_previous; +}; + +// While it lives, a view's slot plays no sound as it moves: the views are muted, as the world preview is. +class MoveSoundScope +{ +public: + MoveSoundScope(List list, int index); + ~MoveSoundScope(); + MoveSoundScope(const MoveSoundScope&) = delete; + MoveSoundScope& operator=(const MoveSoundScope&) = delete; + +private: + std::optional m_mute; +}; +#else +inline void Born(List, int) {} +inline View ViewOf(List, int) +{ + return 0; +} +inline bool Draws(List, int) +{ + return true; +} +inline bool Moves(List, int) +{ + return true; +} +inline bool IsCapturing() +{ + return false; +} +class MoveSoundScope +{ +public: + MoveSoundScope(List, int) {} +}; +#endif +} // namespace Render::Effects::PreviewSlots diff --git a/src/source/Render/Effects/ZzzEffect.cpp b/src/source/Render/Effects/ZzzEffect.cpp index 463f802f3c..c2f68dff44 100644 --- a/src/source/Render/Effects/ZzzEffect.cpp +++ b/src/source/Render/Effects/ZzzEffect.cpp @@ -28,6 +28,7 @@ #include "UI/Core/WindowSystem.h" #include "Engine/Object/ZzzInterface.h" #include "Scenes/MainScene.h" +#include "Render/Effects/PreviewSlots.h" PARTICLE Particles[MAX_PARTICLES]; #ifdef DEVIAS_XMAS_EVENT @@ -402,6 +403,11 @@ void CreateEffect(int Type, vec3_t Position, vec3_t Angle, vec3_t Light, int Sub if (!o->Live) { o->Live = true; + // RenderEffects counts the skill effects after the effects. + Render::Effects::PreviewSlots::Born(Render::Effects::PreviewSlots::List::Effect, + o >= Effects && o < Effects + MAX_EFFECTS + ? static_cast(o - Effects) + : MAX_EFFECTS + static_cast(o - g_SkillEffects.GetEffect(0))); // Not tested yet: a reused slot must not draw in a pass that trusts last frame's visibility. o->Visible = false; Audio::RememberMaker(o); @@ -7736,8 +7742,10 @@ void MoveEffects() for (int i = 0; i < MAX_EFFECTS; i++) { OBJECT* o = &Effects[i]; - if (o->Live) + if (o->Live && Render::Effects::PreviewSlots::Moves(Render::Effects::PreviewSlots::List::Effect, i)) { + const Render::Effects::PreviewSlots::MoveSoundScope previewSound( + Render::Effects::PreviewSlots::List::Effect, i); // The sounds an effect plays as it moves are marked at it, typed by // its maker. std::optional place; @@ -7834,6 +7842,9 @@ void CullEffects() o->Visible = TestFrustrum(o->Position, 400.f); if (gMapManager.WorldActive == WD_39KANTURU_3RD && (o->Type == MODEL_STORM3 || o->Type == MODEL_MAYASTAR)) o->Visible = true; + // A preview view's effect is seen by its view, so its children are created as in the game (design 7a). + if (Render::Effects::PreviewSlots::ViewOf(Render::Effects::PreviewSlots::List::Effect, i) != 0) + o->Visible = true; if (o->Visible) o->DrawnFrame = s_effectCullFrame; } @@ -7861,6 +7872,10 @@ void RenderEffects(bool bRenderBlendMesh) } o = g_SkillEffects.GetEffect(i - MAX_EFFECTS); } + if (!Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Effect, i)) + { + continue; + } if (o->Live) { @@ -8935,7 +8950,8 @@ void UpdateEffectModelEffects() for (int i = 0; i < iEffectSize; ++i) { OBJECT* o = i < MAX_EFFECTS ? &Effects[i] : g_SkillEffects.GetEffect(i - MAX_EFFECTS); - if (!o->Live || o->DrawnFrame != s_effectCullFrame) + if (!o->Live || o->DrawnFrame != s_effectCullFrame || + !Render::Effects::PreviewSlots::Moves(Render::Effects::PreviewSlots::List::Effect, i)) continue; if (o->Type >= MAX_MODELS) { @@ -8977,7 +8993,8 @@ void RenderAfterEffects() o = g_SkillEffects.GetEffect(i - MAX_EFFECTS); } // CullEffects marked it. - if (o->Live && IsSentAfterCharacter(o)) + if (o->Live && IsSentAfterCharacter(o) && + Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Effect, i)) { if (o->Visible) { @@ -9398,7 +9415,7 @@ void RenderEffectShadows() { o = g_SkillEffects.GetEffect(i - MAX_EFFECTS); } - if (o->Live) + if (o->Live && Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Effect, i)) { if (o->Visible) { diff --git a/src/source/Render/Effects/ZzzEffectJoint.cpp b/src/source/Render/Effects/ZzzEffectJoint.cpp index 2bc33a9dd9..74bf041ff5 100644 --- a/src/source/Render/Effects/ZzzEffectJoint.cpp +++ b/src/source/Render/Effects/ZzzEffectJoint.cpp @@ -2,6 +2,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" +#include "Render/Effects/PreviewSlots.h" #include "Core/Utilities/Random.h" #include "Render/Effects/EffectDraw.h" #include "Core/Utilities/DrawSpawnCheck.h" @@ -135,6 +136,7 @@ void CreateJoint(int Type, vec3_t Position, vec3_t TargetPosition, vec3_t Angle, if (!o->Live) { o->Live = true; + Render::Effects::PreviewSlots::Born(Render::Effects::PreviewSlots::List::Joint, i); Audio::RememberMaker(o); std::memset(o->Tails, 0, sizeof(o->Tails)); o->TailFrames = 0.f; @@ -7032,7 +7034,8 @@ static void UpdateDrawnJointEffects() for (int i = 0; i < MAX_JOINTS; i++) { JOINT* o = &Joints[i]; - if (!o->Live || o->NumTails <= 0 || o->RenderFace == 0) + if (!o->Live || o->NumTails <= 0 || o->RenderFace == 0 || + !Render::Effects::PreviewSlots::Moves(Render::Effects::PreviewSlots::List::Joint, i)) continue; if (o->Type == BITMAP_JOINT_ENERGY && o->SubType == 54 && o->Target->CurrentAction != MONSTER01_ATTACK1) continue; @@ -7107,8 +7110,10 @@ void MoveJoints() for (int i = 0; i < MAX_JOINTS; i++) { JOINT* o = &Joints[i]; - if (o->Live) + if (o->Live && Render::Effects::PreviewSlots::Moves(Render::Effects::PreviewSlots::List::Joint, i)) { + const Render::Effects::PreviewSlots::MoveSoundScope previewSound(Render::Effects::PreviewSlots::List::Joint, + i); // The sounds a joint plays as it moves are marked at it, typed by // its maker (Charon's energy sparks reaching her hand). std::optional place; @@ -7168,7 +7173,7 @@ void DescribeJoint(const JOINT& joint, Render::EffectDrawing::EffectDrawer& out) // Runs of segments outside the view frustum are skipped. Not for the trails that fade their // light per drawn segment, add sprites larger than the trail, or draw translated from it. const bool cullOffscreen = - !IsEffectCullingDisabledDebug() && + !IsEffectCullingDisabledDebug() && !Render::Effects::PreviewSlots::IsCapturing() && !(o->Type == BITMAP_JOINT_HEALING && (o->SubType == 9 || o->SubType == 10)) && !(o->Type == MODEL_SPEARSKILL && (o->SubType == 0 || o->SubType == 4 || o->SubType == 9)) && !(o->Type == BITMAP_FLARE + 1 && (o->SubType == 6 || o->SubType == 8)) && @@ -7404,6 +7409,8 @@ void RenderJoints(BYTE bRenderOneMore) for (int i = 0; i < MAX_JOINTS; i++) { const JOINT* o = &Joints[i]; + if (!Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Joint, i)) + continue; if (o->Type == BITMAP_JOINT_ENERGY && o->SubType == 54 && o->Target->CurrentAction != MONSTER01_ATTACK1) continue; if (o->Live && o->NumTails > 0 && o->RenderFace != 0) diff --git a/src/source/Render/Effects/ZzzEffectParticle.cpp b/src/source/Render/Effects/ZzzEffectParticle.cpp index 9139765690..087bede842 100644 --- a/src/source/Render/Effects/ZzzEffectParticle.cpp +++ b/src/source/Render/Effects/ZzzEffectParticle.cpp @@ -2,6 +2,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" +#include "Render/Effects/PreviewSlots.h" #include "Core/Utilities/Random.h" #include "Render/Effects/EffectDraw.h" #include "Core/Utilities/DrawSpawnCheck.h" @@ -73,6 +74,7 @@ int CreateParticle(int Type, vec3_t Position, vec3_t Angle, vec3_t Light, int Su if (!o->Live) { o->Live = true; + Render::Effects::PreviewSlots::Born(Render::Effects::PreviewSlots::List::Particle, i); o->Type = Type; o->TexType = Type; o->SubType = SubType; @@ -3880,8 +3882,10 @@ void MoveParticles() { PARTICLE* o = &Particles[i]; - if (o->Live) + if (o->Live && Render::Effects::PreviewSlots::Moves(Render::Effects::PreviewSlots::List::Particle, i)) { + const Render::Effects::PreviewSlots::MoveSoundScope previewSound( + Render::Effects::PreviewSlots::List::Particle, i); count++; o->LifeTime -= FPS_ANIMATION_FACTOR; if (o->LifeTime <= 0) @@ -9334,7 +9338,8 @@ void DescribeParticle(const PARTICLE& particle, int i, float Width, float Height void RenderParticles(BYTE byRenderOneMore) { - if (!g_pOption->GetRenderAllEffects()) + // As RenderSprites: without the option window (a test, the editor's preview before the UI) every effect draws. + if (g_pOption && !g_pOption->GetRenderAllEffects()) { return; } @@ -9347,7 +9352,8 @@ void RenderParticles(BYTE byRenderOneMore) static Entry drawOrder[MAX_PARTICLES]; static Entry drawOrderScratch[MAX_PARTICLES]; - const bool cullOffscreen = !IsEffectCullingDisabledDebug(); + // A preview view's capture draws its particles whatever the world's camera sees (design 7a). + const bool cullOffscreen = !IsEffectCullingDisabledDebug() && !Render::Effects::PreviewSlots::IsCapturing(); const bool sortDraws = GameConfig::GetInstance().GetSortParticleDraws(); std::size_t drawCount = MAX_PARTICLES; if (sortDraws) @@ -9361,7 +9367,7 @@ void RenderParticles(BYTE byRenderOneMore) { const int i = sortDraws ? drawOrder[drawIndex].particleIndex : static_cast(drawIndex); const PARTICLE* o = &Particles[i]; - if (o->Live) + if (o->Live && Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Particle, i)) { if (byRenderOneMore == 1) { diff --git a/src/source/Render/Effects/zzzeffectsprite.cpp b/src/source/Render/Effects/zzzeffectsprite.cpp index c7956ed1b6..bc9c0198b9 100644 --- a/src/source/Render/Effects/zzzeffectsprite.cpp +++ b/src/source/Render/Effects/zzzeffectsprite.cpp @@ -2,6 +2,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" +#include "Render/Effects/PreviewSlots.h" #include "Core/Utilities/DrawSpawnCheck.h" #include "Render/Textures/ZzzOpenglUtil.h" #include "Render/Models/ZzzBMD.h" @@ -88,6 +89,7 @@ int CreateSprite(int Type, vec3_t Position, float Scale, vec3_t Light, OBJECT* O if (!o->Live) { o->Live = true; + Render::Effects::PreviewSlots::Born(Render::Effects::PreviewSlots::List::Sprite, i); o->Type = Type; o->SubType = SubType; o->Owner = Owner; @@ -215,6 +217,11 @@ void RenderSprites(BYTE byRenderOneMore) for (int i = 0; i < MAX_SPRITES; i++) { const OBJECT* o = &Sprites[i]; + // A preview view's sprites are drawn by its view only (design L51). + if (!Render::Effects::PreviewSlots::Draws(Render::Effects::PreviewSlots::List::Sprite, i)) + { + continue; + } if (byRenderOneMore == 1) { if (o->Position[2] > 350.f) diff --git a/src/source/Render/Items/ItemEffects.cpp b/src/source/Render/Items/ItemEffects.cpp index 29b5173888..5b9c5ee9d9 100644 --- a/src/source/Render/Items/ItemEffects.cpp +++ b/src/source/Render/Items/ItemEffects.cpp @@ -1,19 +1,15 @@ #include "stdafx.h" -#include "Core/Utilities/Random.h" #include "ItemEffects.h" #include "ItemModelTable.h" #include "LookDrawing.h" -#include "Core/Globals/_enum.h" #include "Data/GameData/ItemData/ItemModelDatabase.h" #include "Data/GameData/ItemData/ItemType.h" #include "Data/GameData/LookData/LookJson.h" #include "Data/GameData/LookData/LookStore.h" #include "Engine/Object/w_ObjectInfo.h" -#include "Engine/Object/ZzzCharacter.h" -#include "Render/Effects/ZzzEffect.h" #include "Render/Models/ZzzBMD.h" #include @@ -33,347 +29,19 @@ namespace Render::Items::ItemEffects { namespace { -// An effect runs before the model is drawn, and may change the level the -// model glows like and the alpha it is drawn with. Drawn: it drew the model -// itself, nothing more is drawn. -using EffectFunction = Result (*)(BMD* b, const OBJECT* o, DrawLook& look, int Type, float& Alpha, int& Level); -// Spawns the effect's sprites, particles and lightning from the model's pose, in the update. -using SpawnFunction = void (*)(BMD* b, OBJECT* o, vec34_t* bones); - -struct ItemEffect -{ - const char* name; - EffectFunction apply; - SpawnFunction spawn = nullptr; -}; - -// ------------------------------------------------ the effects - -// For effects that only spawn: the model is drawn as usual. -Result ApplyNothing(BMD*, const OBJECT*, DrawLook&, int, float&, int&) -{ - return Result::Applied; -} - -void SpawnDevilsKey(BMD* b, OBJECT* o, vec34_t* bones) -{ - float Luminosity = (float)sinf((WorldTime) * 0.002f) * 0.35f + 0.65f; - vec3_t p, Position, EffLight; - Vector(0.f, 0.f, 0.f, p); - - float Scale = Luminosity * 0.8f; - Vector(Luminosity * 2, Luminosity * 0.32f, Luminosity * 0.32f, EffLight); - - b->TransformPosition(bones[1], p, Position); - VectorAdd(Position, o->Position, Position); - CreateSprite(BITMAP_SPARK + 1, Position, Scale, EffLight, o); - - b->TransformPosition(bones[2], p, Position); - VectorAdd(Position, o->Position, Position); - CreateSprite(BITMAP_SPARK + 1, Position, Scale, EffLight, o); -} - -void SpawnDevilsInvitation(BMD* b, OBJECT* o, vec34_t* bones) -{ - float Luminosity = (float)sinf((WorldTime) * 0.002f) * 0.35f + 0.65f; - vec3_t p, Position, EffLight; - Vector(0.f, 0.f, 0.f, p); - - float Scale = Luminosity * 0.8f; - Vector(Luminosity * 2, Luminosity * 0.32f, Luminosity * 0.32f, EffLight); - - b->TransformPosition(bones[9], p, Position); - VectorAdd(Position, o->Position, Position); - CreateSprite(BITMAP_SPARK + 1, Position, Scale, EffLight, o); - - b->TransformPosition(bones[10], p, Position); - VectorAdd(Position, o->Position, Position); - CreateSprite(BITMAP_SPARK + 1, Position, Scale, EffLight, o); -} - -void SpawnRena(BMD* b, OBJECT* o, vec34_t* bones) -{ - float Luminosity = (float)sinf((WorldTime) * 0.002f) * 0.25f + 0.75f; - vec3_t EffLight; - - Vector(Luminosity * 1.f, Luminosity * 0.5f, Luminosity * 0.f, EffLight); - CreateSprite(BITMAP_SPARK + 1, o->Position, 2.5f, EffLight, o); -} - -void SpawnWingsOfDarkness(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t posCenter, p, Position, Light; - float Scale = sinf(WorldTime * 0.004f) * 0.3f + 0.3f; - - Scale = (Scale * 10.f) + 20.f; - - Vector(0.6f, 0.3f, 0.8f, Light); - - Vector(0.f, 0.f, 0.f, p); - - for (int i = 0; i < 5; ++i) - { - b->TransformPosition(bones[22 - i], p, posCenter, true); - b->TransformPosition(bones[30 - i], p, Position, true); - if (rand_fps_check(1)) - { - CreateJoint(BITMAP_JOINT_THUNDER, Position, posCenter, o->Angle, 14, o, Scale); - CreateJoint(BITMAP_JOINT_SPIRIT, posCenter, Position, o->Angle, 4, o, Scale + 5); - } - - CreateSprite(BITMAP_FLARE_BLUE, posCenter, Scale / 28.f, Light, o); - } - - for (int i = 0; i < 5; ++i) - { - b->TransformPosition(bones[7 - i], p, posCenter, true); - b->TransformPosition(bones[11 + i], p, Position, true); - if (rand_fps_check(1)) - { - CreateJoint(BITMAP_JOINT_THUNDER, Position, posCenter, o->Angle, 14, o, Scale); - CreateJoint(BITMAP_JOINT_SPIRIT, posCenter, Position, o->Angle, 4, o, Scale + 5); - } - - CreateSprite(BITMAP_FLARE_BLUE, posCenter, Scale / 28.f, Light, o); - } -} - -void SpawnWingOfStorm(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t vRelativePos, vPos, vLight; - Vector(0.f, 0.f, 0.f, vRelativePos); - Vector(0.f, 0.f, 0.f, vPos); - Vector(0.f, 0.f, 0.f, vLight); - - float fLuminosity = absf(sinf(WorldTime * 0.0004f)) * 0.4f; - Vector(0.5f + fLuminosity, 0.5f + fLuminosity, 0.5f + fLuminosity, vLight); - int iBone[] = {9, 20, 19, 10, 18, 28, 27, 36, 35, 38, 37, 53, 48, 62, 70, 72, 71, 78, 79, 80, 87, 90, 91, 106, 102}; - float fScale = 0.f; - - for (int i = 0; i < 25; ++i) - { - b->TransformPosition(bones[iBone[i]], vRelativePos, vPos, true); - fScale = 0.5f; // (Random::Rand()%10) * 0.05f + 0.3f; - CreateSprite(BITMAP_CLUD64, vPos, fScale, vLight, o, WorldTime * 0.01f, 1); - } - - int iBoneThunder[] = {11, 21, 29, 63, 81, 89}; - if (rand_fps_check(2)) - { - for (int i = 0; i < 6; ++i) - { - b->TransformPosition(bones[iBoneThunder[i]], vRelativePos, vPos, true); - if (Random::Rand() % 20 == 0) - { - Vector(0.6f, 0.6f, 0.9f, vLight); - CreateEffect(MODEL_FENRIR_THUNDER, vPos, o->Angle, vLight, 1, o); - } - } - } - - int iBoneLight[] = {64, 61, 69, 77, 86, 98, 97, 99, 104, 103, 105, 12, 8, 17, 26, 34, 52, 44, 51, 50, 49, 45}; - - fScale = absf(sinf(WorldTime * 0.003f)) * 0.2f; - - for (int i = 0; i < 22; ++i) - { - b->TransformPosition(bones[iBoneLight[i]], vRelativePos, vPos, true); - if (iBoneLight[i] == 12 || iBoneLight[i] == 64 || iBoneLight[i] == 98 || iBoneLight[i] == 52) - { - Vector(0.9f, 0.0f, 0.0f, vLight); - CreateSprite(BITMAP_LIGHT, vPos, fScale + 1.4f, vLight, o); - } - else - { - Vector(0.8f, 0.5f, 0.2f, vLight); - CreateSprite(BITMAP_LIGHT, vPos, fScale + 0.3f, vLight, o); - } - } -} - -void SpawnWingOfEternal(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t p, Position, Light; - Vector(0.f, 0.f, 0.f, p); - float Scale = absf(sinf(WorldTime * 0.003f)) * 0.2f; - float Luminosity = absf(sinf(WorldTime * 0.003f)) * 0.3f; - - Vector(0.5f + Luminosity, 0.5f + Luminosity, 0.6f + Luminosity, Light); - // int iRedFlarePos[] = { 25, 32, 53, 15, 9, 35 }; - int iRedFlarePos[] = {24, 31, 15, 8, 53, 35}; - for (int i = 0; i < 6; ++i) - { - b->TransformPosition(bones[iRedFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_LIGHT, Position, Scale + 1.3f, Light, o); - } - - Vector(0.1f, 0.1f, 0.9f, Light); - // int iGreenFlarePos[] = { 23, 22, 24, 34, 5, 31, 14, 12, 27, 8, 6, 7, 16, 13, 56, 37, 58, 40, 39, 38 }; - int iGreenFlarePos[] = {22, 23, 25, 29, 30, 28, 32, 13, 16, 14, 12, 9, 7, 6, 57, 58, 40, 39}; - - for (int i = 0; i < 18; ++i) - { - b->TransformPosition(bones[iGreenFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_LIGHT, Position, Scale + 1.5f, Light, o); - } - int iGreenFlarePos2[] = {56, 38, 51, 45}; - - for (int i = 0; i < 4; ++i) - { - b->TransformPosition(bones[iGreenFlarePos2[i]], p, Position, true); - CreateSprite(BITMAP_LIGHT, Position, Scale + 0.5f, Light, o); - } -} - -void SpawnWingOfIllusion(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t p, Position, Light; - Vector(0.f, 0.f, 0.f, p); - float Scale = absf(sinf(WorldTime * 0.002f)) * 0.2f; - float Luminosity = absf(sinf(WorldTime * 0.002f)) * 0.4f; - - Vector(0.5f + Luminosity, 0.0f + Luminosity, 0.0f + Luminosity, Light); - int iRedFlarePos[] = {5, 6, 7, 8, 18, 19, 23, 24, 25, 27, 37, 38}; - for (int i = 0; i < 12; ++i) - { - b->TransformPosition(bones[iRedFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_FLARE, Position, Scale + 0.6f, Light, o); - } - - Vector(0.0f + Luminosity, 0.5f + Luminosity, 0.0f + Luminosity, Light); - int iGreenFlarePos[] = {4, 9, 13, 14, 26, 32, 31, 33}; - - for (int i = 0; i < 8; ++i) - { - b->TransformPosition(bones[iGreenFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_LIGHT, Position, 1.3f, Light, o); - } - - Vector(1.0f, 1.0f, 1.0f, Light); - float fLumi = (sinf(WorldTime * 0.004f) + 1.0f) * 0.05f; - Vector(0.8f + fLumi, 0.8f + fLumi, 0.3f + fLumi, Light); - CreateSprite(BITMAP_LIGHT, Position, 0.4f, Light, o, 0.5f); - if (rand_fps_check(2)) - { - b->TransformPosition(bones[13], p, Position, true); - CreateParticle(BITMAP_SHINY, Position, o->Angle, Light, 5, 0.5f); - b->TransformPosition(bones[31], p, Position, true); - CreateParticle(BITMAP_SHINY, Position, o->Angle, Light, 5, 0.5f); - } -} - -void SpawnWingOfRuin(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t p, Position, Light; - Vector(0.f, 0.f, 0.f, p); - float Scale = absf(sinf(WorldTime * 0.003f)) * 0.2f; - float Luminosity = absf(sinf(WorldTime * 0.003f)) * 0.3f; - - Vector(0.7f + Luminosity, 0.5f + Luminosity, 0.8f + Luminosity, Light); - int iRedFlarePos[] = {6, 15, 24, 56, 47, 38}; - for (int i = 0; i < 6; ++i) - { - b->TransformPosition(bones[iRedFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_LIGHT, Position, Scale + 1.5f, Light, o); - } - - Vector(0.6f, 0.4f, 0.7f, Light); - int iSparkPos[] = {7, 16, 25, 57, 48, 39, 11, 22, 31, 63, 54, 40, 10, 21, 30, 62, 53, 41, 9, - 20, 29, 61, 52, 42, 8, 19, 28, 60, 51, 43, 18, 27, 59, 50, 17, 26, 58, 49}; - int iNumParticle = 1; - - for (int i = 0; i < 6; ++i) - { - b->TransformPosition(bones[iSparkPos[i]], p, Position, true); - for (int j = 0; j < iNumParticle; ++j) - if (rand_fps_check(1)) - CreateParticle(BITMAP_CHROME_ENERGY2, Position, o->Angle, Light, 0, 0.1f); - } - - for (int i = 6; i < 18; ++i) - { - b->TransformPosition(bones[iSparkPos[i]], p, Position, true); - for (int j = 0; j < iNumParticle; ++j) - if (rand_fps_check(1)) - CreateParticle(BITMAP_CHROME_ENERGY2, Position, o->Angle, Light, 0, 0.3f); - } - - for (int i = 18; i < 30; ++i) - { - b->TransformPosition(bones[iSparkPos[i]], p, Position, true); - for (int j = 0; j < iNumParticle; ++j) - if (rand_fps_check(1)) - CreateParticle(BITMAP_CHROME_ENERGY2, Position, o->Angle, Light, 0, 0.5f); - } - - for (int i = 30; i < 38; ++i) - { - b->TransformPosition(bones[iSparkPos[i]], p, Position, true); - for (int j = 0; j < iNumParticle; ++j) - if (rand_fps_check(1)) - CreateParticle(BITMAP_CHROME_ENERGY2, Position, o->Angle, Light, 0, 0.7f); - } -} - -void SpawnWingOfDimension(BMD* b, OBJECT* o, vec34_t* bones) +// The item effect of an item, as the item has it (it can set values of it), with the catalogue types of its things on +// bones. +struct ItemEffectOf { - vec3_t p, Position, Light; - Vector(0.f, 0.f, 0.f, p); - float Scale = absf(sinf(WorldTime * 0.002f)) * 0.2f; - float Luminosity = absf(sinf(WorldTime * 0.002f)) * 0.4f; - - Vector((1.0f + Luminosity) / 2.f, (0.7f + Luminosity) / 2.f, (0.2f + Luminosity) / 2.f, Light); - int iFlarePos0[] = {7, 30, 31, 43, 8, 20}; - - int icnt; - for (icnt = 0; icnt < 2; ++icnt) - { - b->TransformPosition(bones[iFlarePos0[icnt]], p, Position, true); - CreateSprite(BITMAP_FLARE, Position, Scale + 2.0f, Light, o); - } - Vector((1.0f + Luminosity) / 4.f, (0.7f + Luminosity) / 4.f, (0.2f + Luminosity) / 4.f, Light); - for (; icnt < 6; ++icnt) - { - b->TransformPosition(bones[iFlarePos0[icnt]], p, Position, true); - CreateSprite(BITMAP_FLARE, Position, Scale + 0.5f, Light, o); - } - - Vector((0.5f + Luminosity) / 2.f, (0.1f + Luminosity) / 2.f, (0.4f + Luminosity) / 2.f, Light); - int iGreenFlarePos[] = {29, 38, 42, 19, 15, 6}; - - for (int i = 0; i < 6; ++i) - { - b->TransformPosition(bones[iGreenFlarePos[i]], p, Position, true); - CreateSprite(BITMAP_FLARE, Position, Scale + 2.0f, Light, o); - } -} - -// ------------------------------------------------ the names - -const ItemEffect ItemEffects[] = { - {"devilsKey", ApplyNothing, SpawnDevilsKey}, - {"devilsInvitation", ApplyNothing, SpawnDevilsInvitation}, - {"rena", ApplyNothing, SpawnRena}, - {"wingsOfDarkness", ApplyNothing, SpawnWingsOfDarkness}, - {"wingOfStorm", ApplyNothing, SpawnWingOfStorm}, - {"wingOfEternal", ApplyNothing, SpawnWingOfEternal}, - {"wingOfIllusion", ApplyNothing, SpawnWingOfIllusion}, - {"wingOfRuin", ApplyNothing, SpawnWingOfRuin}, - {"wingOfDimension", ApplyNothing, SpawnWingOfDimension}, + const Data::Looks::LookDefinition* data = nullptr; + Looks::BoneThingTypes types; }; -const ItemEffect* FindEffect(std::string_view name) -{ - const auto found = std::find_if(std::begin(ItemEffects), std::end(ItemEffects), - [name](const ItemEffect& effect) { return effect.name == name; }); - return found != std::end(ItemEffects) ? found : nullptr; -} - -// The item effect of an item: one still in code, or one that is data as the item has it. -struct ItemEffectOf +// What drawing an item takes from its ItemEffectOf, without copying the types: `types` is null for none. +struct EffectView { - const ItemEffect* code = nullptr; const Data::Looks::LookDefinition* data = nullptr; + const Looks::BoneThingTypes* types = nullptr; }; // An item effect that is data as an item that sets values of it has it (design L12); those are made again with the @@ -395,22 +63,23 @@ const Data::Looks::LookDefinition* DataEffectOfItem(const Data::Items::ItemModel // The effect of every item type, taken from the item model database after // each build of it and after each change of the looks that are data. -ItemModelTable g_itemEffects{[](const Data::Items::ItemModelDefinition& model) -> ItemEffectOf - { - if (model.itemEffect.empty()) - { - return {}; - } - if (const Data::Looks::LookDefinition* data = - Data::Looks::g_LookStore.FindItemEffect(model.itemEffect)) - { - return {nullptr, DataEffectOfItem(model, *data)}; - } - // Names that are not effects are drawn without one; the - // model loader reports them. - return {FindEffect(model.itemEffect), nullptr}; - }, - [] { return Data::Looks::g_LookStore.GetVersion(); }}; +ItemModelTable g_itemEffects{ + [](const Data::Items::ItemModelDefinition& model) -> ItemEffectOf + { + if (model.itemEffect.empty()) + { + return {}; + } + if (const Data::Looks::LookDefinition* data = Data::Looks::g_LookStore.FindItemEffect(model.itemEffect)) + { + const Data::Looks::LookDefinition* effect = DataEffectOfItem(model, *data); + return {effect, Looks::ResolveBoneThingTypes(*effect)}; + } + // Names that are not effects are drawn without one; the + // model loader reports them. + return {}; + }, + [] { return Data::Looks::g_LookStore.GetVersion(); }}; #ifdef _EDITOR // PreviewEffect's model and effect, while one lives. @@ -419,15 +88,17 @@ const Data::Looks::LookDefinition* s_previewEffect = nullptr; #endif // The model's effect, or the one the Style Editor previews on it. -ItemEffectOf EffectOfModel(int modelType) +EffectView EffectOfModel(int modelType) { #ifdef _EDITOR if (s_previewEffect != nullptr && modelType == s_previewModel) { - return {nullptr, s_previewEffect}; + // Its things on bones are the Style Editor's to create (MuEditor::Looks::BoneThingsPreview), not the game's. + return {s_previewEffect, nullptr}; } #endif - return g_itemEffects.Find(modelType); + const ItemEffectOf& effect = g_itemEffects.Find(modelType); + return {effect.data, &effect.types}; } } // namespace @@ -447,12 +118,13 @@ PreviewEffect::~PreviewEffect() bool Exists(std::string_view name) { - return Data::Looks::g_LookStore.FindItemEffect(name) != nullptr || FindEffect(name) != nullptr; + return Data::Looks::g_LookStore.FindItemEffect(name) != nullptr; } -bool ExistsInCode(std::string_view name) +bool ExistsInCode(std::string_view) { - return FindEffect(name) != nullptr; + // Every item effect is data since the things on bones moved (step 3). + return false; } std::span GetNames() @@ -463,51 +135,45 @@ std::span GetNames() { version = Data::Looks::g_LookStore.GetVersion(); names.clear(); - for (const ItemEffect& effect : ItemEffects) - { - names.emplace_back(effect.name); - } for (const Data::Looks::LookDefinition& look : Data::Looks::g_LookStore.GetItemEffects()) { names.emplace_back(look.name); } std::ranges::sort(names); - names.erase(std::unique(names.begin(), names.end()), names.end()); } return names; } Result Apply(BMD* b, const OBJECT* o, DrawLook& look, int modelType, float& alpha, int& level) { - const ItemEffectOf effect = EffectOfModel(modelType); - if (effect.data != nullptr) + const EffectView effect = EffectOfModel(modelType); + if (effect.data == nullptr) { - Looks::ApplyItemEffect(*effect.data, b, o, look, alpha, level); - return Result::Applied; + return Result::None; } - return effect.code != nullptr ? effect.code->apply(b, o, look, modelType, alpha, level) : Result::None; + Looks::ApplyItemEffect(*effect.data, b, o, look, alpha, level); + return Result::Applied; +} + +const Data::Looks::LookDefinition* EffectOf(int modelType) +{ + return EffectOfModel(modelType).data; } bool Spawns(int modelType) { - const ItemEffectOf effect = EffectOfModel(modelType); - if (effect.data != nullptr) - { - return effect.data->objectLight.has_value(); - } - return effect.code != nullptr && effect.code->spawn != nullptr; + const EffectView effect = EffectOfModel(modelType); + return effect.data != nullptr && (effect.data->objectLight.has_value() || !effect.data->onBones.empty() || + effect.data->animationSpeed.has_value()); } void Spawn(BMD* b, OBJECT* o, int modelType, float (*bones)[3][4]) { - const ItemEffectOf effect = EffectOfModel(modelType); + const EffectView effect = EffectOfModel(modelType); if (effect.data != nullptr) { - Looks::SpawnItemEffect(*effect.data, o); - } - else if (effect.code != nullptr && effect.code->spawn != nullptr) - { - effect.code->spawn(b, o, bones); + static const Looks::BoneThingTypes noTypes; + Looks::SpawnItemEffect(*effect.data, effect.types ? *effect.types : noTypes, b, o, bones); } } } // namespace Render::Items::ItemEffects diff --git a/src/source/Render/Items/ItemEffects.h b/src/source/Render/Items/ItemEffects.h index efbadce77d..b826d43a16 100644 --- a/src/source/Render/Items/ItemEffects.h +++ b/src/source/Render/Items/ItemEffects.h @@ -12,9 +12,8 @@ class OBJECT; // What item models do before they are drawn: sprites, particles and // lightning on their bones, a pulsing glow mesh, a mesh hidden by level, the // level they glow like (a model drawn alone has a render style that draws -// alone, design L47; only the event models' effects still draw). An -// effect is data (Data/Effects/ItemEffects.json, looked up first, design L14) -// or code, with a name; the model entry of an item names its effect +// alone, design L47). Every effect is data (Data/Effects/ItemEffects.json), +// with a name; the model entry of an item names its effect // (Data/Items/Models, "itemEffect"). Items with the same effect share it. namespace Render::Items::ItemEffects { @@ -22,7 +21,8 @@ namespace Render::Items::ItemEffects // of the model entries with it. bool Exists(std::string_view name); -// Whether an item effect of this name is still code. +// Whether an item effect of this name is still code: none is since the things on bones moved into data (step 3); +// the editor's lists mark the looks of both kinds alike. bool ExistsInCode(std::string_view name); // The names of all item effects, sorted, for the item editor's lists. @@ -49,6 +49,10 @@ bool Spawns(int modelType); // Spawns them from the model's pose, in the update; b is placed where the model is drawn. void Spawn(BMD* b, OBJECT* o, int modelType, float (*bones)[3][4]); +// The item effect the model runs, as the item has it (the one the Style Editor previews on it while a PreviewEffect +// lives); nullptr without one. +const Data::Looks::LookDefinition* EffectOf(int modelType); + #ifdef _EDITOR // While it lives, the model `modelType` runs `effect` instead of its own item effect: the Style Editor's preview of an // item effect before it is applied. The effect must outlive it; one at a time. Editor builds only. diff --git a/src/source/Render/Items/ItemModelTable.h b/src/source/Render/Items/ItemModelTable.h index 9611d1f6ea..3cf536e3b3 100644 --- a/src/source/Render/Items/ItemModelTable.h +++ b/src/source/Render/Items/ItemModelTable.h @@ -26,11 +26,13 @@ template class ItemModelTable explicit ItemModelTable(Take take, Version version = nullptr) : m_take(take), m_version(version) {} // The value of the item a model slot is drawn like (GetItemTypeOfModel); - // T{} for models that are not items and for slots without a model. - T Find(int modelType) + // T{} for models that are not items and for slots without a model. It + // lives until the values are taken again. + const T& Find(int modelType) { + static const T none{}; const int itemType = GetItemTypeOfModel(modelType); - return itemType >= 0 ? Values()[itemType] : T{}; + return itemType >= 0 ? Values()[itemType] : none; } private: diff --git a/src/source/Render/Items/ItemRenderStyles.cpp b/src/source/Render/Items/ItemRenderStyles.cpp index 9545cd2bc0..ed07893ca3 100644 --- a/src/source/Render/Items/ItemRenderStyles.cpp +++ b/src/source/Render/Items/ItemRenderStyles.cpp @@ -55,49 +55,6 @@ struct RenderStyle // ------------------------------------------------ the recipes -bool RenderPumpkinOfLuck(BMD* b, const OBJECT* o, DrawLook& look, int Type, float Alpha, int RenderType) -{ - b->RenderBody(RENDER_TEXTURE, look.alpha, look.blendMesh, look.blendMeshLight, look.blendMeshU, look.blendMeshV, - look.hiddenMesh); - b->RenderMesh(1, RENDER_DARK | RENDER_CHROME, look.alpha, look.blendMesh, look.blendMeshLight, -WorldTime * 0.0002f, - look.blendMeshV, BITMAP_CHROME); - return true; -} - -void SpawnPumpkinOfLuck(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t vPos, vRelativePos; - Vector(0.f, 0.f, 0.f, vRelativePos); - b->TransformPosition(bones[8], vRelativePos, vPos, true); - float fLumi = (sinf(WorldTime * 0.004f) + 1.0f) * 0.05f; - Vector(0.8f + fLumi, 0.8f + fLumi, 0.3f + fLumi, o->Light); - CreateSprite(BITMAP_LIGHT, vPos, 1.5f, o->Light, o, 0.5f); - b->TransformPosition(bones[10], vRelativePos, vPos, true); - CreateSprite(BITMAP_LIGHT, vPos, 0.5f, o->Light, o, 0.5f); - b->TransformPosition(bones[11], vRelativePos, vPos, true); - CreateSprite(BITMAP_LIGHT, vPos, 0.5f, o->Light, o, 0.5f); -} - -bool RenderCursedCastleWater(BMD* b, const OBJECT* o, DrawLook& look, int Type, float Alpha, int RenderType) -{ - b->RenderBody(RenderType, Alpha, look.blendMesh, look.blendMeshLight * 1.5f, look.blendMeshU, look.blendMeshV); - b->RenderBody(RENDER_TEXTURE | RENDER_BRIGHT, Alpha, look.blendMesh, look.blendMeshLight / 4.0f, WorldTime * 0.005f, - -WorldTime * 0.005f, 0); - return true; -} - -void SpawnCursedCastleWater(BMD* b, OBJECT* o, vec34_t* bones) -{ - vec3_t Light; - vec3_t vRelativePos, vWorldPos; - Vector(0.f, 0.f, 0.f, vRelativePos); - Vector(1.f, 0.f, 0.0f, Light); - - b->TransformPosition(bones[1], vRelativePos, vWorldPos, true); - CreateSprite(BITMAP_LIGHT, vWorldPos, 3.f, Light, o, 0.f); - b->PlayAnimation(&o->AnimationFrame, &o->PriorAnimationFrame, &o->PriorAction, 2.f / 7.f, o->Position, o->Angle); -} - bool RenderHelperNpcPlate(BMD* b, const OBJECT* o, DrawLook& look, int Type, float Alpha, int RenderType) { // Only on the helper NPCs (Luke and Leo the Helper, Helper Ellen), the only @@ -122,31 +79,9 @@ bool RenderHelperNpcPlate(BMD* b, const OBJECT* o, DrawLook& look, int Type, flo // ------------------------------------------------ the names const RenderStyle RenderStyles[] = { - {"pumpkinOfLuck", RenderPumpkinOfLuck}, - {"cursedCastleWater", RenderCursedCastleWater}, {"helperNpcPlate", RenderHelperNpcPlate}, }; -using SpawnFunction = void (*)(BMD* b, OBJECT* o, vec34_t* bones); - -// The styles whose items spawn lights or animate where they are drawn. -const struct -{ - const char* name; - SpawnFunction spawn; -} StyleSpawns[] = { - {"pumpkinOfLuck", SpawnPumpkinOfLuck}, - {"cursedCastleWater", SpawnCursedCastleWater}, -}; - -ItemModelTable g_itemSpawns{[](const Data::Items::ItemModelDefinition& model) - { - for (const auto& style : StyleSpawns) - if (model.renderStyle == style.name) - return style.spawn; - return SpawnFunction{}; - }}; - // The render styles that are data, one entry per look of g_LookStore; built again when the looks change. const std::vector& DataStyles() { @@ -376,14 +311,4 @@ bool DrawsAlone(int modelType) return style != nullptr && style->data != nullptr && style->data->drawsAlone; } -bool Spawns(int modelType) -{ - return g_itemSpawns.Find(modelType) != nullptr; -} - -void Spawn(BMD* b, OBJECT* o, int modelType, float (*bones)[3][4]) -{ - if (const SpawnFunction spawn = g_itemSpawns.Find(modelType)) - spawn(b, o, bones); -} } // namespace Render::Items::Styles diff --git a/src/source/Render/Items/ItemRenderStyles.h b/src/source/Render/Items/ItemRenderStyles.h index 3b292e47e9..eadbedbec8 100644 --- a/src/source/Render/Items/ItemRenderStyles.h +++ b/src/source/Render/Items/ItemRenderStyles.h @@ -58,11 +58,6 @@ class PreviewLook }; #endif -// Whether the item's style spawns lights or animates where it is drawn. -bool Spawns(int modelType); -// Spawns them from the model's pose, in the update; b is placed where the model is drawn. -void Spawn(BMD* b, OBJECT* o, int modelType, float (*bones)[3][4]); - // The lights and tint the helper NPCs' plate armor keeps on them, for the update to spawn while it is drawn. void SpawnHelperNpcPlateLights(OBJECT* o); } // namespace Render::Items::Styles diff --git a/src/source/Render/Items/LookDrawing.cpp b/src/source/Render/Items/LookDrawing.cpp index d93ad19c5c..7ce9d2eae8 100644 --- a/src/source/Render/Items/LookDrawing.cpp +++ b/src/source/Render/Items/LookDrawing.cpp @@ -9,7 +9,10 @@ #include "Core/Utilities/_GlobalFunctions.h" #include "Engine/Object/w_ObjectInfo.h" #include "Data/GameData/Common/MeshLimits.h" +#include "Data/GameData/LookData/BoneThingTypes.h" #include "Data/GameData/LookData/LookStore.h" +#include "Engine/Object/ZzzCharacter.h" +#include "Render/Effects/ZzzEffect.h" #include "Render/Models/ZzzBMD.h" #include "Render/Sprites/GlobalBitmap.h" #include "Render/Textures/ZzzOpenglUtil.h" @@ -32,6 +35,7 @@ using namespace Data::Looks; constexpr double Pi = 3.14159265358979323846; static_assert(Data::MaxModelMeshes == MAX_MESH, "the data names the meshes a model can have"); +static_assert(Data::MaxModelBones == MAX_BONES, "the data names the bones a pose buffer holds"); // The texture index of each texture file a layer names; BITMAP_UNKNOWN for a file that is missing. std::unordered_map s_textures; @@ -72,7 +76,11 @@ int LayerFlags(const Layer& layer, int renderType) const int flags = layer.kind == LayerKind::Texture ? RENDER_TEXTURE : layer.kind == LayerKind::FlatColor ? RENDER_COLOR : MotionFlag(layer.motion); - return layer.blend == Blend::Glow ? flags | RENDER_BRIGHT : flags; + if (layer.blend == Blend::Glow) + { + return flags | RENDER_BRIGHT; + } + return layer.blend == Blend::Darken ? flags | RENDER_DARK : flags; } // The object of one drawing, which random values are drawn for; each random value of a look takes the next salt. @@ -206,7 +214,11 @@ float ValueOf(const Value& value, float item, float drawing, Moment& moment) { return shape->timesItem ? item * ValueAt(*shape, moment) : ValueAt(*shape, moment); } - return std::holds_alternative(value) ? drawing : item; + if (const FromItem* fromItem = std::get_if(&value)) + { + return item * fromItem->times; + } + return drawing; } int GlowMeshOf(const GlowMesh& mesh, int item) @@ -705,16 +717,156 @@ void ApplyItemEffect(const LookDefinition& effect, BMD* b, const OBJECT* o, Draw look.level = level; } -void SpawnItemEffect(const LookDefinition& effect, OBJECT* o) +namespace +{ +// Whether a chance of a thing on bones holds this time (design L56). +bool Rolls(const Chance& chance) +{ + if (chance.draw == ChanceDraw::Plain) + { + return Random::Rand() % chance.oneIn == 0; + } + return rand_fps_check(chance.oneIn); +} + +// Where a thing on bones is created: a bone's place in the world, as the item's pose puts it. False for a bone the +// model doesn't have (Data Checks warns about it): its pose holds nothing there. +bool BonePlace(BMD* b, float (*bones)[3][4], int bone, vec3_t place) +{ + if (bone < 0 || bone >= b->NumBones || bone >= MAX_BONES) + { + return false; + } + vec3_t zero{0.f, 0.f, 0.f}; + b->TransformPosition(bones[bone], zero, place, true); + return true; +} + +void CreateThing(const BoneThing& thing, int type, OBJECT* o, vec3_t place, vec3_t target, Moment& moment) +{ + vec3_t color; + for (int channel = 0; channel < 3; ++channel) + { + color[channel] = NumberAt(thing.color[channel], moment); + } + const float scale = NumberAt(thing.scale, moment); + switch (thing.kind) + { + case BoneThingKind::Sprite: + CreateSprite(type, place, scale, color, o, NumberAt(thing.rotation, moment), thing.subType); + break; + case BoneThingKind::Particle: + CreateParticle(type, place, o->Angle, color, thing.subType, scale); + break; + case BoneThingKind::Joint: + { + // Lightning in white takes the joint's own light, as the looks in code created it. + const bool white = color[0] == 1.f && color[1] == 1.f && color[2] == 1.f; + CreateJoint(type, thing.reversed ? target : place, thing.reversed ? place : target, o->Angle, thing.subType, o, + scale, -1, 0, 0, -1, white ? nullptr : color); + break; + } + case BoneThingKind::Effect: + CreateEffect(type, place, o->Angle, color, thing.subType, o); + break; + } +} + +// Creates an entry's things at one of its places, each whose own chance holds. +void CreateAt(const OnBones& entry, const std::vector& types, OBJECT* o, vec3_t place, vec3_t target, + Moment& moment) { - if (!effect.objectLight) + for (std::size_t i = 0; i < entry.things.size(); ++i) + { + const BoneThing& thing = entry.things[i]; + if (types[i] < 0 || (thing.chance && !Rolls(*thing.chance))) + { + continue; + } + CreateThing(thing, types[i], o, place, target, moment); + } +} + +void CreateOnBones(const OnBones& entry, const std::vector& types, BMD* b, OBJECT* o, float (*bones)[3][4], + Moment& moment) +{ + const bool eachPlace = entry.chance && !entry.chance->once; + if (entry.chance && entry.chance->once && !Rolls(*entry.chance)) + { + return; + } + if (entry.places.origin) + { + if (!eachPlace || Rolls(*entry.chance)) + { + CreateAt(entry, types, o, o->Position, o->Position, moment); + } + return; + } + if (bones == nullptr) { return; } + vec3_t place; + for (const int bone : entry.places.bones) + { + if (!BonePlace(b, bones, bone, place)) + { + continue; + } + if (!eachPlace || Rolls(*entry.chance)) + { + CreateAt(entry, types, o, place, place, moment); + } + } + vec3_t target; + for (const auto& [from, to] : entry.places.between) + { + if (!BonePlace(b, bones, from, place) || !BonePlace(b, bones, to, target)) + { + continue; + } + if (!eachPlace || Rolls(*entry.chance)) + { + CreateAt(entry, types, o, place, target, moment); + } + } +} +} // namespace + +BoneThingTypes ResolveBoneThingTypes(const LookDefinition& effect) +{ + BoneThingTypes types; + types.reserve(effect.onBones.size()); + for (const OnBones& entry : effect.onBones) + { + std::vector& entryTypes = types.emplace_back(); + for (const BoneThing& thing : entry.things) + { + entryTypes.push_back(Data::Looks::FindBoneThingType(thing.kind, thing.type).value_or(-1)); + } + } + return types; +} + +void SpawnItemEffect(const LookDefinition& effect, const BoneThingTypes& types, BMD* b, OBJECT* o, float (*bones)[3][4]) +{ Moment moment{.object = o}; - for (int channel = 0; channel < 3; ++channel) + if (effect.objectLight) + { + for (int channel = 0; channel < 3; ++channel) + { + o->Light[channel] = NumberAt((*effect.objectLight)[channel], moment); + } + } + for (std::size_t i = 0; i < effect.onBones.size() && i < types.size(); ++i) + { + CreateOnBones(effect.onBones[i], types[i], b, o, bones, moment); + } + if (effect.animationSpeed && b != nullptr) { - o->Light[channel] = NumberAt((*effect.objectLight)[channel], moment); + b->PlayAnimation(&o->AnimationFrame, &o->PriorAnimationFrame, &o->PriorAction, *effect.animationSpeed, + o->Position, o->Angle); } } @@ -732,6 +884,30 @@ void PrepareTextures() } } +void LogUnknownBoneThingTypes() +{ + for (const LookDefinition& effect : g_LookStore.GetItemEffects()) + { + for (std::size_t entry = 0; entry < effect.onBones.size(); ++entry) + { + const OnBones& onBones = effect.onBones[entry]; + for (std::size_t i = 0; i < onBones.things.size(); ++i) + { + const BoneThing& thing = onBones.things[i]; + if (!Data::Looks::FindBoneThingType(thing.kind, thing.type)) + { + // Named as Data Checks names it. + const std::string group = onBones.together ? ".things[" + std::to_string(i) + "]" : ""; + MU_LOG_ERROR(mu::log::Get("data"), + "Item effect data error: {}: onBones[{}]{}.{}: \"{}\" is not in the effect " + "catalogue; it is not created", + effect.name, entry, group, Data::Looks::BoneThingKey(thing.kind), thing.type); + } + } + } + } +} + void PrepareTextures(const LookDefinition& style) { PrepareMissingTextures(style, true); diff --git a/src/source/Render/Items/LookDrawing.h b/src/source/Render/Items/LookDrawing.h index d851d0ed27..59e79ed76c 100644 --- a/src/source/Render/Items/LookDrawing.h +++ b/src/source/Render/Items/LookDrawing.h @@ -3,6 +3,8 @@ #include "Data/GameData/LookData/LookDefinition.h" #include "Render/Models/DrawLook.h" +#include + class BMD; class OBJECT; @@ -46,12 +48,24 @@ class InventoryDrawing // item glows like (`level`, which the later entries' conditions read). void ApplyItemEffect(const Data::Looks::LookDefinition& effect, BMD* b, const OBJECT* o, DrawLook& look, float& alpha, int& level); -// Puts the light of an item effect that is data on the item's object, in the update (design L45). -void SpawnItemEffect(const Data::Looks::LookDefinition& effect, OBJECT* o); +// The effect catalogue's type numbers of an item effect's things on bones, by entry and thing; -1 for a name the +// catalogue doesn't have (Data Checks names it), which creates nothing. Resolved when the effect table is built, not +// per frame. +using BoneThingTypes = std::vector>; +BoneThingTypes ResolveBoneThingTypes(const Data::Looks::LookDefinition& effect); + +// What an item effect that is data does in the update: puts its light on the item's object (design L45) and creates +// its things on bones (section 7b) at `bones`, the item's pose in this update (its bone matrices, placed by the +// model's BodyOrigin and BodyScale); without bones only the things at the origin. +void SpawnItemEffect(const Data::Looks::LookDefinition& effect, const BoneThingTypes& types, BMD* b, OBJECT* o, + float (*bones)[3][4]); // Finds the texture each layer names, loading the ones no code loaded; done after the item textures are loaded. A layer // whose texture is missing is skipped, and that is logged as an error. void PrepareTextures(); +// Logs as an error each thing on bones of the item effects whose type the effect catalogue doesn't have, which is not +// created; done when the looks and the catalogue are loaded (Data Checks names them too). +void LogUnknownBoneThingTypes(); // The same for one look when the looks change (an edit, an undo): the textures not found yet, also those missing // before, as their file may have come since. A missing texture is logged once. void PrepareTextures(const Data::Looks::LookDefinition& style); diff --git a/src/source/Scenes/MainScene.cpp b/src/source/Scenes/MainScene.cpp index 3c85ea9698..8eefbb51fb 100644 --- a/src/source/Scenes/MainScene.cpp +++ b/src/source/Scenes/MainScene.cpp @@ -30,6 +30,7 @@ #include "Core/Utilities/Log/muConsoleDebug.h" #include "Core/Utilities/Log/MuLogger.h" #include "Core/Utilities/FrameProfiler.h" +#include "Core/Utilities/EffectSpawnHook.h" #include "Network/Server/WSclient.h" #include "Network/Reconnect/ReconnectManager.h" #include "Engine/AI/GOBoid.h" @@ -344,6 +345,10 @@ static void UpdateGameEntities() UpdateTerrainEffects(); UpdateTerrainWaterSpots(); } +#ifdef _EDITOR + // The Style Editor's views create their items' things on bones (design section 7a). + Core::EffectSpawnHook::Notify(); +#endif MoveWaterTerrain(); g_Direction.CheckDirection(); diff --git a/tests/data/CMakeLists.txt b/tests/data/CMakeLists.txt index 5e99ab226c..462e2f3d2a 100644 --- a/tests/data/CMakeLists.txt +++ b/tests/data/CMakeLists.txt @@ -363,6 +363,7 @@ mu_add_test( test_look_effects.cpp test_look_drawing.cpp test_look_recorder.cpp + test_bone_things_preview.cpp LookRecorder.cpp ${CMAKE_SOURCE_DIR}/src/source/App/Platform/Windows/Winmain.cpp LINK_LIBS @@ -371,6 +372,7 @@ mu_add_test( target_compile_definitions(render_style_tests PRIVATE MU_TEST_DATA_DIR="${CMAKE_SOURCE_DIR}/src/bin/Data" MU_RENDER_STYLE_BASELINE="${CMAKE_CURRENT_SOURCE_DIR}/baseline/RenderStyleDraws.txt" + MU_SPAWN_BASELINE="${CMAKE_CURRENT_SOURCE_DIR}/baseline/ItemEffectSpawns.txt" ) # Each case of the data tests once more, with the shipped client data read from a storage of the test's own and the diff --git a/tests/data/LookRecorder.cpp b/tests/data/LookRecorder.cpp index 195581892f..b58f366da4 100644 --- a/tests/data/LookRecorder.cpp +++ b/tests/data/LookRecorder.cpp @@ -16,6 +16,7 @@ #include "Data/GameData/LookData/LookStore.h" #include "Engine/Object/ZzzObject.h" #include "Engine/Object/ZzzOpenData.h" +#include "Render/Effects/ZzzEffect.h" #include "Render/Items/ItemEffects.h" #include "Render/Items/ItemRenderStyles.h" #include "Render/Items/LookDrawing.h" @@ -625,6 +626,192 @@ Record RecordItemWithCode(int itemType, const Situation& situation, std::string_ return record; } +namespace +{ +std::string Numbers(const float* values, int count) +{ + std::string text; + for (int i = 0; i < count; ++i) + { + text += (i == 0 ? "" : " ") + Number(values[i]); + } + return text; +} + +// Every live slot of the lists a look creates things in, one entry each, its fields in a fixed order. +std::vector> LiveThings(const OBJECT& object) +{ + std::vector> things; + const auto ownedBy = [&object](const OBJECT* owner) + { + return owner == &object ? "item" : owner ? "other" : "none"; + }; + for (int i = 0; i < MAX_SPRITES; ++i) + { + const OBJECT& o = Sprites[i]; + if (o.Live) + { + things.push_back({{"kind", "sprite"}, + {"type", std::to_string(o.Type)}, + {"subType", std::to_string(o.SubType)}, + {"position", Numbers(o.Position, 3)}, + {"scale", Number(o.Scale)}, + {"light", Numbers(o.Light, 3)}, + {"angle", Numbers(o.Angle, 3)}, + {"owner", ownedBy(o.Owner)}}); + } + } + for (int i = 0; i < MAX_PARTICLES; ++i) + { + const PARTICLE& o = Particles[i]; + if (o.Live) + { + things.push_back({{"kind", "particle"}, + {"type", std::to_string(o.Type)}, + {"subType", std::to_string(o.SubType)}, + {"position", Numbers(o.Position, 3)}, + {"scale", Number(o.Scale)}, + {"light", Numbers(o.Light, 3)}, + {"angle", Numbers(o.Angle, 3)}, + {"lifeTime", Number(o.LifeTime)}, + {"velocity", Numbers(o.Velocity, 3)}, + {"target", ownedBy(o.Target)}}); + } + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + const JOINT& o = Joints[i]; + if (o.Live) + { + things.push_back({{"kind", "joint"}, + {"type", std::to_string(o.Type)}, + {"subType", std::to_string(o.SubType)}, + {"position", Numbers(o.Position, 3)}, + {"targetPosition", Numbers(o.TargetPosition, 3)}, + {"scale", Number(o.Scale)}, + {"light", Numbers(o.Light, 3)}, + {"angle", Numbers(o.Angle, 3)}, + {"lifeTime", Number(o.LifeTime)}, + {"target", ownedBy(o.Target)}}); + } + } + for (int i = 0; i < MAX_EFFECTS; ++i) + { + const OBJECT& o = Effects[i]; + if (o.Live) + { + things.push_back({{"kind", "effect"}, + {"type", std::to_string(o.Type)}, + {"subType", std::to_string(o.SubType)}, + {"position", Numbers(o.Position, 3)}, + {"scale", Number(o.Scale)}, + {"light", Numbers(o.Light, 3)}, + {"angle", Numbers(o.Angle, 3)}, + {"lifeTime", Number(o.LifeTime)}, + {"owner", ownedBy(o.Owner)}}); + } + } + std::ranges::sort(things, + [](const std::vector& a, const std::vector& b) { return Join(a) < Join(b); }); + return things; +} + +void ClearThingLists() +{ + // Whole objects, not only Live: a create call leaves fields it doesn't set as the slot's last thing had them, so a + // record would depend on what ran before it. + for (int i = 0; i < MAX_SPRITES; ++i) + { + Sprites[i] = OBJECT{}; + } + for (int i = 0; i < MAX_PARTICLES; ++i) + { + Particles[i] = PARTICLE{}; + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + Joints[i] = JOINT{}; + } + for (int i = 0; i < MAX_EFFECTS; ++i) + { + Effects[i] = OBJECT{}; + } +} + +// A digest of the engine sequence's state: equal when both drew as many numbers. It is taken from the next numbers a +// copy of the engine gives, which the standard fixes for std::mt19937, hashed with 64-bit FNV-1a: the same on every +// platform, unlike the engine's written state and std::hash. +std::string EngineState() +{ + std::mt19937 engine = Random::Snapshot(); + std::string text; + for (int i = 0; i < 8; ++i) + { + text += std::to_string(engine()) + " "; + } + std::uint64_t hash = 14695981039346656037ull; + for (const char c : text) + { + hash = (hash ^ static_cast(c)) * 1099511628211ull; + } + return "x" + std::to_string(hash); +} +} // namespace + +Record RecordSpawn(int itemType, double worldTime, std::uint32_t seed) +{ + const int slot = Data::Items::ToModelSlot(itemType); + BMD& model = Models[slot]; + OBJECT& object = DrawnObject(); + const Random::DrawnAs fixedKey(&object, FixedDrawKey()); + const double previousWorldTime = WorldTime; + const float previousFactor = FPS_ANIMATION_FACTOR; + WorldTime = worldTime; + FPS_ANIMATION_FACTOR = 1.f; + object.Initialize(); + object.Type = slot; + object.Live = true; + ItemObjectAttribute(&object); + Vector(13120.25f, 12480.5f, 140.75f, object.Position); + ClearThingLists(); + Random::Seed(seed); + Random::SeedRand(seed); + + // As SpawnGroundItemEffects poses a ground item. + model.CurrentAction = object.CurrentAction; + model.Animation(BoneTransform, object.AnimationFrame, object.PriorAnimationFrame, object.PriorAction, object.Angle, + object.HeadAngle, false, false); + model.BodyScale = object.Scale; + VectorCopy(object.Position, model.BodyOrigin); + SpawnPartObjectEffect(&model, &object, slot, BoneTransform); + + Record record; + record.meshDraws = LiveThings(object); + record.modelAfter = {{"objectLight", Numbers(object.Light, 3)}, + {"animationFrame", Number(object.AnimationFrame)}, + {"randState", "x" + std::to_string(Random::RandState())}, + {"engineState", EngineState()}}; + ClearThingLists(); + WorldTime = previousWorldTime; + FPS_ANIMATION_FACTOR = previousFactor; + return record; +} + +Record RecordSpawnWithCode(int itemType, double worldTime, std::uint32_t seed, std::string_view look, + Data::Looks::LookKind kind) +{ + using Data::Looks::g_LookStore; + const std::vector looks(g_LookStore.GetLooks(kind).begin(), + g_LookStore.GetLooks(kind).end()); + std::vector without; + std::ranges::copy_if(looks, std::back_inserter(without), + [look](const Data::Looks::LookDefinition& other) { return other.name != look; }); + g_LookStore.SetLooks(kind, std::move(without)); + Record record = RecordSpawn(itemType, worldTime, seed); + g_LookStore.SetLooks(kind, looks); + return record; +} + std::string FirstDifference(const Record& code, const Record& data) { std::string gpuDifference; diff --git a/tests/data/LookRecorder.h b/tests/data/LookRecorder.h index b67ab8bf7b..8841720734 100644 --- a/tests/data/LookRecorder.h +++ b/tests/data/LookRecorder.h @@ -110,6 +110,19 @@ Record RecordItem(int itemType, const Situation& situation); Record RecordItemWithCode(int itemType, const Situation& situation, std::string_view renderStyle, Data::Looks::LookKind kind = Data::Looks::LookKind::RenderStyle); +// Lets the item's look create its things in the update as the game does for an item on the ground +// (SpawnGroundItemEffects through SpawnPartObjectEffect): the model posed at the pinned clock, the random sequences +// seeded with `seed` and the frame factor at 1. The record holds one entry per thing alive in the effect, sprite, +// particle and joint lists afterwards, sorted (which slot a thing takes is not the look's), and, as "the model after", +// the object's light and animation frame and the states of the random sequences, so a look that draws one random +// number more or less shows. +Record RecordSpawn(int itemType, double worldTime, std::uint32_t seed); + +// RecordSpawn with the look of its name taken from the code: the data look of that name and kind is left out of +// g_LookStore while it creates its things. +Record RecordSpawnWithCode(int itemType, double worldTime, std::uint32_t seed, std::string_view look, + Data::Looks::LookKind kind); + // How far a number of a mesh draw may be from the code's when every GPU call is the same (design L34): a pulse the // code wrote as (sin + 1.2) * 0.4 and the data draws as sin * 0.4 + 0.48 rounds in another order, a few float steps // (units in the last place) away. diff --git a/tests/data/baseline/ItemEffectSpawns.txt b/tests/data/baseline/ItemEffectSpawns.txt new file mode 100644 index 0000000000..190c40aae6 --- /dev/null +++ b/tests/data/baseline/ItemEffectSpawns.txt @@ -0,0 +1,94 @@ +# What the looks whose things on bones moved from code into Data/Effects/ItemEffects.json create in the update: +# one line per item, clock time and random seed, the look, the item and the moment, then the number of things +# and five digests of them and of what the look left on the object, rounded on five grids +# (tests/data/LookRecorder.h). Recorded from the old code before each look moved +# (MU_SPAWN_RECORDER_WRITE=), so a moved look still creates what its code did. The Devil's Key's and +# Invitation's lines were written again when their sparks moved onto the scaled bones (design L57). +spawn cursedCastleWater (14,64) t=0.00 seed=1 1 39c3f7546c05b237 39c3f7546c05b237 ab2ac1ff8fa1e5d9 39c3f7546c05b237 39c3f7546c05b237 +spawn cursedCastleWater (14,64) t=0.00 seed=5 1 8a695df9b8596ad2 8a695df9b8596ad2 5355550c281e4974 8a695df9b8596ad2 8a695df9b8596ad2 +spawn cursedCastleWater (14,64) t=1000.25 seed=2 1 263080d8709c997b 263080d8709c997b 7744fd23f2037ea9 263080d8709c997b 263080d8709c997b +spawn cursedCastleWater (14,64) t=1000.25 seed=6 1 e38adc8f2478c2f5 e38adc8f2478c2f5 353da9a7e97197fb e38adc8f2478c2f5 e38adc8f2478c2f5 +spawn cursedCastleWater (14,64) t=2718.50 seed=3 1 0a614df4deb6af66 0a614df4deb6af66 862812c4b9774078 0a614df4deb6af66 0a614df4deb6af66 +spawn cursedCastleWater (14,64) t=2718.50 seed=7 1 07bdf8f127276cae 07bdf8f127276cae e1ee11f937ac17fc 07bdf8f127276cae 07bdf8f127276cae +spawn cursedCastleWater (14,64) t=65536.75 seed=4 1 f8b1ac617ca69595 f8b1ac617ca69595 f488d04b508711ff f8b1ac617ca69595 f8b1ac617ca69595 +spawn cursedCastleWater (14,64) t=65536.75 seed=8 1 23b07efe55198522 23b07efe55198522 1528929b9c8bbd58 23b07efe55198522 23b07efe55198522 +spawn devilsInvitation (14,19) t=0.00 seed=1 2 d114007b2e0cf64f d114007b2e0cf64f d114007b2e0cf64f 6e50de8b82bcc95f d114007b2e0cf64f +spawn devilsInvitation (14,19) t=0.00 seed=5 2 2d6286d4ecf7a18a 2d6286d4ecf7a18a 2d6286d4ecf7a18a 611fee496288bcda 2d6286d4ecf7a18a +spawn devilsInvitation (14,19) t=1000.25 seed=2 2 74d0369b7ca03b93 76202d54af0af323 942b67db2775ba8f c53669fea987090b 2e0df01579e39e3b +spawn devilsInvitation (14,19) t=1000.25 seed=6 2 d3a7505c9f2ce1dd c06e0e3510b3766d 22e15652c6acafb9 e4ecb0116b5b3b85 a83f73a8fe6cd3b5 +spawn devilsInvitation (14,19) t=2718.50 seed=3 2 525c401af75e4816 5ac012f1105216c8 5ac012f1105216c8 484e6da63ef3657e c62054f4506ef0bc +spawn devilsInvitation (14,19) t=2718.50 seed=7 2 9894f878b40d339e ea5daa1e1719a8cc ea5daa1e1719a8cc 9fe603d1cb6e0876 f1a957aa2ba30dd0 +spawn devilsInvitation (14,19) t=65536.75 seed=4 2 d94e58126690dfab aeb204b91dddfb39 aeb204b91dddfb39 68600f4fb9e788a3 2ebc2f1199b46e37 +spawn devilsInvitation (14,19) t=65536.75 seed=8 2 66daeafa02f3eb94 e5cfab28e0227136 e5cfab28e0227136 40226302340ddd2c 27f8789eb6094e70 +spawn devilsKey (14,18) t=0.00 seed=1 2 9b04668361795c9e 9b04668361795c9e f1e1c40deb471f2e 9b04668361795c9e 9b04668361795c9e +spawn devilsKey (14,18) t=0.00 seed=5 2 84c00be19bd883d1 84c00be19bd883d1 b06f58c78c2357a1 84c00be19bd883d1 84c00be19bd883d1 +spawn devilsKey (14,18) t=1000.25 seed=2 2 3a4218187be952b8 4705bfa3921ec8ac 496b403ceff627bc 3c7fa69cd967e8f4 3c7fa69cd967e8f4 +spawn devilsKey (14,18) t=1000.25 seed=6 2 101d2f0623564cd2 e622b16c05b7e406 a3781f016d725316 9537c86d3123a17e 9537c86d3123a17e +spawn devilsKey (14,18) t=2718.50 seed=3 2 bcb0538a1415f7a7 819861a85ee36085 441db7e763184ca7 96c835ddbd430c55 96c835ddbd430c55 +spawn devilsKey (14,18) t=2718.50 seed=7 2 387fdfb0828cecf3 23b1d802ac1598ad bfed440dd18f41f3 46556d47dddb107d 46556d47dddb107d +spawn devilsKey (14,18) t=65536.75 seed=4 2 ba71bcff06d01a50 7494df2a35c7b3ce 5e85fd1eef81de44 8ca71ecea30e899e 1ff016433d040a60 +spawn devilsKey (14,18) t=65536.75 seed=8 2 3fb20c58914f54f1 d3006f80fd1d7763 d2498ef5151aade5 58baf7792080db73 7d3151a6c31a73c1 +spawn pumpkinOfLuck (14,45) t=0.00 seed=1 3 eeaa27e8f6fd2c57 407fe510c178ce26 31cd8357d7f92ef9 1d2fda03e53044d8 eeaa27e8f6fd2c57 +spawn pumpkinOfLuck (14,45) t=0.00 seed=5 3 ad1183817057ff72 77632b4211b05699 16705f823743cf94 a114c989b248d6d3 ad1183817057ff72 +spawn pumpkinOfLuck (14,45) t=1000.25 seed=2 3 95a598a260ea072b 4319568d8a3aeb04 a63b8cc33a1b24c1 c1f31fdcc51b84fe 95a598a260ea072b +spawn pumpkinOfLuck (14,45) t=1000.25 seed=6 3 04ce51d91d25eba5 d2db9122e424194e fe7c0a99997c7563 fcae858bd3b0f7c0 04ce51d91d25eba5 +spawn pumpkinOfLuck (14,45) t=2718.50 seed=3 3 ef77c428c7768182 9b08f0c1b5d530a7 04d51ab46f08af00 b244bb0623cc3eb9 ee731a64f940101a +spawn pumpkinOfLuck (14,45) t=2718.50 seed=7 3 2b2b8a8be478b69a 16d87ce8244c25f3 8e937fcee18f5c74 c9d9eddf82cbed91 48250f350878c362 +spawn pumpkinOfLuck (14,45) t=65536.75 seed=4 3 4447a3b1a5aab331 26d444d19004e4e6 637d7d8aed65db0f 532efa1f250ca538 4447a3b1a5aab331 +spawn pumpkinOfLuck (14,45) t=65536.75 seed=8 3 295d0354443961ae 36d29a3814cae3bb 7cec8eec6eacfae8 62e48497046264b9 295d0354443961ae +spawn rena (14,21) t=0.00 seed=1 1 5701976ce8f3bddb 5701976ce8f3bddb 5701976ce8f3bddb 5701976ce8f3bddb 5701976ce8f3bddb +spawn rena (14,21) t=0.00 seed=5 1 1efba3eccc8db336 1efba3eccc8db336 1efba3eccc8db336 1efba3eccc8db336 1efba3eccc8db336 +spawn rena (14,21) t=1000.25 seed=2 1 e68aa37f2f167c32 a424e508b493e4bf a424e508b493e4bf 07cc264e62f9b475 e68aa37f2f167c32 +spawn rena (14,21) t=1000.25 seed=6 1 6b6d05169462b864 2336662724476ae9 2336662724476ae9 4c9da144ce61b7a7 6b6d05169462b864 +spawn rena (14,21) t=2718.50 seed=3 1 53f2726662d2577d 53f2726662d2577d 22297b43b91d3e6c 53f2726662d2577d 53f2726662d2577d +spawn rena (14,21) t=2718.50 seed=7 1 fa9582adf4a281d5 fa9582adf4a281d5 e41f7ee8f26de540 fa9582adf4a281d5 fa9582adf4a281d5 +spawn rena (14,21) t=65536.75 seed=4 1 fb0f6c701594a66a fb0f6c701594a66a fb0f6c701594a66a 7279c9e30280e378 fb0f6c701594a66a +spawn rena (14,21) t=65536.75 seed=8 1 760eb1f5e3f24fcf 760eb1f5e3f24fcf 760eb1f5e3f24fcf af4c76f9c858fc79 760eb1f5e3f24fcf +spawn wingOfDimension (12,43) t=0.00 seed=1 12 4c7b5d9e148a4c6a cb617729d217efa1 8632378c7e293c9c af3498eff566c588 467838b397f477c5 +spawn wingOfDimension (12,43) t=0.00 seed=5 12 fb476ecb4bc524ad b23b0253a7ca32fc 69b5752bdab2dd57 2b1969f7cc1b2cc3 fffb40906f983520 +spawn wingOfDimension (12,43) t=1000.25 seed=2 12 ff213745dc700da6 d2136cd5af36834d cabf99948038ddf6 551ee1400f0c3b54 894027d029b4a929 +spawn wingOfDimension (12,43) t=1000.25 seed=6 12 a4d82be63eb807d8 01152638acc944ef b6fa88091dbe28a8 a86c655912c04ade 4738d4542122c27b +spawn wingOfDimension (12,43) t=2718.50 seed=3 12 297d68ac73e167ad 95dc6d988fdfd5b4 c004307d9e3a3699 54e4ab124adc0ecb d7f02712b37978e0 +spawn wingOfDimension (12,43) t=2718.50 seed=7 12 f0e82f8a078a1205 d0a138f9ee175d18 081de322e84bdaf1 9b7588c1d35d9527 e5095c1da3412154 +spawn wingOfDimension (12,43) t=65536.75 seed=4 12 ffc4ef15b781ca98 ff463455b4d12d43 674bebfbccbb531c 8f18c0e66bb8321a edfdb5450247e4bf +spawn wingOfDimension (12,43) t=65536.75 seed=8 12 bd12dbd85d70c299 73e1057f0a65dbcc 5057a3a2a27cde1d 27563549291129bf 93446a959fbc6498 +spawn wingOfEternal (12,37) t=0.00 seed=1 28 9a1a004f77b95fe1 e2b31ab9acfa28d3 ae72a2d600cf0735 aa32d63e543c93b6 0d1547d9e7242831 +spawn wingOfEternal (12,37) t=0.00 seed=5 28 924bf1d0580a40bc 47458463a0945b8e 359ee7eb5e05b150 d3345e9cc087c369 80dfc8ab9b39a18c +spawn wingOfEternal (12,37) t=1000.25 seed=2 28 11d051105bfd8397 e58a7c1d7105c6dd 23db0a50eaf5bd4f 7e2f04d452174d24 74adc634e458db23 +spawn wingOfEternal (12,37) t=1000.25 seed=6 28 c4ebef03171c0051 6699e1b0a573ed7f f80d3b1de95f8e79 537fa7421afabe6e befba71546015e6d +spawn wingOfEternal (12,37) t=2718.50 seed=3 28 ea85ff0331fcf91a 80f2917485225730 0e8a83c560cc496a 14f4ae8494f07ad9 f0c51367de658b1e +spawn wingOfEternal (12,37) t=2718.50 seed=7 28 4437f3d34135ac62 bfe8289600d2de64 74689abb0c0d3672 df724ce8c233d031 f0bf99fc1a635616 +spawn wingOfEternal (12,37) t=65536.75 seed=4 28 d1169c722571e681 4d6c6be39c6c96cd 9edce226c26af227 0f6859a39095e67c 644fd13164c3d6f9 +spawn wingOfEternal (12,37) t=65536.75 seed=8 28 1aee1ea8b26f753e f85b172b69e4877a ff8b478390c85360 ceb25f9e7b2f3d7d 69e0803aa0e93676 +spawn wingOfIllusion (12,38) t=0.00 seed=1 21 d4c60e9333a7b3fa ef109444c5130d2b 9ec68a74b837b4ae 1a17da0dc242333c 8f354010840b8bb6 +spawn wingOfIllusion (12,38) t=0.00 seed=5 23 14d3d672eaae9516 72c177f03eea7e15 f81dfc7bf8367b62 52815f4643a4217b ad7c9f88d065eea9 +spawn wingOfIllusion (12,38) t=1000.25 seed=2 23 96219c3850364264 19159d071027d317 99125a74f2c0770b 7a1a037e6fd08e9b 79ce5e7791371929 +spawn wingOfIllusion (12,38) t=1000.25 seed=6 21 f70d2de66392450f ae836a67d6d4af26 d6b72b4bd9636206 7bbf8e807665f245 3732b87c5e328c8b +spawn wingOfIllusion (12,38) t=2718.50 seed=3 23 4f6eb06f0031bbd4 4493c770cbe78291 e40aaef055d98394 346f58484f78f4f2 7942c0591427ec8c +spawn wingOfIllusion (12,38) t=2718.50 seed=7 23 841e0bd5a134f27b c9ac10f50699ed9c e4c7fea72c49d58b 42242ea86bf5f38d 538d77dee99f3ca7 +spawn wingOfIllusion (12,38) t=65536.75 seed=4 21 3d12681ee39f2813 6d9bbd3a032a28de 59e406b49ab5f3cf 5c2399d46fc0d362 290292fa5439198f +spawn wingOfIllusion (12,38) t=65536.75 seed=8 23 4476a651ceb06195 35b3f997b884761c cb5a620e90f83c1d f4b33de3c3a6fd11 7f24f124227f5594 +spawn wingOfRuin (12,39) t=0.00 seed=1 44 80c4eff3e90d3c07 92bfb6630c6a729d e51d8896c6cb75b7 0958145679e9e2ad 61e198aa6e8fc75e +spawn wingOfRuin (12,39) t=0.00 seed=5 44 5fc31e0dc22d2ec2 eb20cf9bbd81862e 50a1e72a8a8064c6 7eeb18ac94b1746c 952fc1611ce80d3d +spawn wingOfRuin (12,39) t=1000.25 seed=2 44 5b19a8b2da352876 a11c9e5a50dac610 8294fca3cfb69196 8f26a971e6d00392 468979877a453c43 +spawn wingOfRuin (12,39) t=1000.25 seed=6 44 b4ed12aee350c456 c5f930c55c5676d2 2c821f345a5f1c2c 9ecc0dee6abb96e6 401f0f7e7838cd5d +spawn wingOfRuin (12,39) t=2718.50 seed=3 44 8240cee7f6b52f83 69fa5fb09f3e3c23 fd80fce7273eb52f 06c2588b0be0d8ff b621c0a47608cc50 +spawn wingOfRuin (12,39) t=2718.50 seed=7 44 abc64d4c759d2819 dfb1a4d356a9e21b e2f96d60ed0430e1 4a769037188c3ec1 a1eba191a34435ec +spawn wingOfRuin (12,39) t=65536.75 seed=4 44 cfa87c0931293a1a 6870fbcd23be49e4 4131a7c204ac365a c83a236f0bb71914 8cc77983d9699055 +spawn wingOfRuin (12,39) t=65536.75 seed=8 44 aa68675d4d24cca6 3627a36756aaa980 71fd229c9629d798 d467b12312bc79ce 9e714e19181ff121 +spawn wingOfStorm (12,36) t=0.00 seed=1 47 349e2b2bb3f17ed3 c0cb35d9b1a17707 a5cd8d5358620c8b 08af0d8a9864a4b2 dabb099e24f843f4 +spawn wingOfStorm (12,36) t=0.00 seed=5 49 5d3fc79c8e17e8ae 222f89055bd958f0 9362a8253c49e51c dc4c4f3e3f644e9f 595443f096859033 +spawn wingOfStorm (12,36) t=1000.25 seed=2 47 6e6b3cb6b21f7f8f 636396ab0afc88c5 0ae7ce5919fb94cd 9df7f1731edb128e 71e91f844fd252e4 +spawn wingOfStorm (12,36) t=1000.25 seed=6 47 349711fe48512938 1abf182aa32b2516 bd297c10755ef38e cba007fe40425c8b 82bc10684422eff9 +spawn wingOfStorm (12,36) t=2718.50 seed=3 47 7093d6d8dd127ee4 804c9462d5f9df3a 7e0f30546d0d252e 9ba7965883e47c52 165e775d790da7ac +spawn wingOfStorm (12,36) t=2718.50 seed=7 49 bff419e98634ffaa d1e1b789b5cbf946 8e0bc7c9b8302e2e d52264edbf6ef452 d743994b460c8f9e +spawn wingOfStorm (12,36) t=65536.75 seed=4 47 9e4c316f22fab041 07ff6a47c9ddf865 df1a639cc1bfa945 827e8dd6a5b1d071 272dd81191462547 +spawn wingOfStorm (12,36) t=65536.75 seed=8 47 62cfb3bf040ed474 29ef3379bcffdcf0 5df01c257934ddd0 2b681f65894e6fa4 d3a6f908693cb04a +spawn wingsOfDarkness (12,6) t=0.00 seed=1 30 e9a92ae9c296e04d 35f1fab7e5d13172 21f622ba3357a13f e9a92ae9c296e04d e9a92ae9c296e04d +spawn wingsOfDarkness (12,6) t=0.00 seed=5 30 07d805c91d3be59b 287b276d95b3232c ff7f5325388a935d 07d805c91d3be59b 07d805c91d3be59b +spawn wingsOfDarkness (12,6) t=1000.25 seed=2 30 3fa3704ddc9176a9 d5d54dc5db5f964a 3baab43ca89e6d53 b4fdb9c87090bb5b 3fa3704ddc9176a9 +spawn wingsOfDarkness (12,6) t=1000.25 seed=6 30 37311a440c58823c 30a5c965c0bc60f7 8d0ce8c4295ac9ae 694f0a5e712559e6 37311a440c58823c +spawn wingsOfDarkness (12,6) t=2718.50 seed=3 30 f4e1c62dfb9de52e b7ec51262fc39adb 02c5c1f15311e474 b5874d5aff8d8128 f4e1c62dfb9de52e +spawn wingsOfDarkness (12,6) t=2718.50 seed=7 30 b6758d993a3b3511 b1cd8a5bef046770 c85fb7cd89b918f3 ccf119bcfd3d2cf7 b6758d993a3b3511 +spawn wingsOfDarkness (12,6) t=65536.75 seed=4 30 d28f1b420e596b85 226603dad7330d9a f8faffac43353277 d28f1b420e596b85 d28f1b420e596b85 +spawn wingsOfDarkness (12,6) t=65536.75 seed=8 30 db284404ede645a4 eea61e4e44bf5727 517e3bd01d8e6ade db284404ede645a4 db284404ede645a4 diff --git a/tests/data/baseline/RenderStyleDraws.txt b/tests/data/baseline/RenderStyleDraws.txt index 8d0733aab6..130a63ec0a 100644 --- a/tests/data/baseline/RenderStyleDraws.txt +++ b/tests/data/baseline/RenderStyleDraws.txt @@ -635,6 +635,20 @@ crossShield (6,21) +15 at 1234.567 s 8 69bb5e3f158fb548 69bb5e3f158fb548 69bb5e3 crossShield (6,21) +7 at 1234.567 s 4 67a5eafc6fc7eb0f 67a5eafc6fc7eb0f 67a5eafc6fc7eb0f 67a5eafc6fc7eb0f 67a5eafc6fc7eb0f crossShield (6,21) +9 at 1234.567 s 5 339563777c5f9c80 339563777c5f9c80 339563777c5f9c80 339563777c5f9c80 339563777c5f9c80 crossShield (6,21) +9 at 1235.817 s 5 fcd35d1459c3f300 fcd35d1459c3f300 fcd35d1459c3f300 fcd35d1459c3f300 fcd35d1459c3f300 +cursedCastleWater (14,64) +0 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +0 at 1234.567 s, doppelganger 5 5cdccc61ab13c8e2 607f16ac027a6b76 607f16ac027a6b76 0d786e2bdc7f4696 0d786e2bdc7f4696 +cursedCastleWater (14,64) +0 at 1234.567 s, excellent 7 08410842f1d19e7d 6b49c95be7d307cd c670cdd191aea67c cab696dec64f4792 a8a5002bfebbb25d +cursedCastleWater (14,64) +0 at 1234.567 s, fading 0.5 5 957d25f7ee1143ea 7ace71ce478e162e 7ace71ce478e162e e35eff7f077d218e e35eff7f077d218e +cursedCastleWater (14,64) +0 at 1234.567 s, in a monster's hands 5 a1798cdd5fa18913 5d33027df7645b37 5d33027df7645b37 091e0b88c8a5ec97 091e0b88c8a5ec97 +cursedCastleWater (14,64) +0 at 1234.567 s, without the skin 5 08ae5e0c48fbdb75 89d8c8c2aadf3b09 89d8c8c2aadf3b09 1a1441efbc1d7b69 1a1441efbc1d7b69 +cursedCastleWater (14,64) +0 at 1235.817 s 5 5cdf5ca8b3feecf8 efa13338bcae2a88 efa13338bcae2a88 90d1b63ded556e58 90d1b63ded556e58 +cursedCastleWater (14,64) +0 at 1238.267 s 5 f9ae26caedbc7f74 1c81b6f82e3e9d14 1c81b6f82e3e9d14 6028af4ff87fb854 6028af4ff87fb854 +cursedCastleWater (14,64) +11 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +13 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +15 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +7 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +9 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +cursedCastleWater (14,64) +9 at 1235.817 s 5 5cdf5ca8b3feecf8 efa13338bcae2a88 efa13338bcae2a88 90d1b63ded556e58 90d1b63ded556e58 darkHorse (13,4) +0 at 1234.567 s 4 7067a57fca105bee 7067a57fca105bee 7067a57fca105bee 7067a57fca105bee 7067a57fca105bee darkHorse (13,4) +0 at 1234.567 s, doppelganger 4 6011a012f8f54442 6011a012f8f54442 6011a012f8f54442 6011a012f8f54442 6011a012f8f54442 darkHorse (13,4) +0 at 1234.567 s, excellent 6 677b34489be83a19 677b34489be83a19 a90142afa7bf06c6 601113cbc5ae78b8 677b34489be83a19 @@ -971,6 +985,20 @@ dragonSpear (3,10) +15 at 1234.567 s 10 3247ffb9e7255f6f def107d8719b2b88 153a3e dragonSpear (3,10) +7 at 1234.567 s 5 6a50d9c3f8bc54fe 72bbca58cae55761 a5b88908758d80ca 6a50d9c3f8bc54fe 6a50d9c3f8bc54fe dragonSpear (3,10) +9 at 1234.567 s 7 359f6a9b07fae055 b41fb25a5f8e1826 5c9c16027d8d5d21 359f6a9b07fae055 359f6a9b07fae055 dragonSpear (3,10) +9 at 1235.817 s 7 f1489d87334207ae a2d533b50781bd9d 2f0e501037fa349a f1489d87334207ae f1489d87334207ae +effect cursedCastleWater (14,64) +0 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +0 at 1234.567 s, doppelganger 5 5cdccc61ab13c8e2 607f16ac027a6b76 607f16ac027a6b76 0d786e2bdc7f4696 0d786e2bdc7f4696 +effect cursedCastleWater (14,64) +0 at 1234.567 s, excellent 7 08410842f1d19e7d 6b49c95be7d307cd c670cdd191aea67c cab696dec64f4792 a8a5002bfebbb25d +effect cursedCastleWater (14,64) +0 at 1234.567 s, fading 0.5 5 957d25f7ee1143ea 7ace71ce478e162e 7ace71ce478e162e e35eff7f077d218e e35eff7f077d218e +effect cursedCastleWater (14,64) +0 at 1234.567 s, in a monster's hands 5 a1798cdd5fa18913 5d33027df7645b37 5d33027df7645b37 091e0b88c8a5ec97 091e0b88c8a5ec97 +effect cursedCastleWater (14,64) +0 at 1234.567 s, without the skin 5 08ae5e0c48fbdb75 89d8c8c2aadf3b09 89d8c8c2aadf3b09 1a1441efbc1d7b69 1a1441efbc1d7b69 +effect cursedCastleWater (14,64) +0 at 1235.817 s 5 5cdf5ca8b3feecf8 efa13338bcae2a88 efa13338bcae2a88 90d1b63ded556e58 90d1b63ded556e58 +effect cursedCastleWater (14,64) +0 at 1238.267 s 5 f9ae26caedbc7f74 1c81b6f82e3e9d14 1c81b6f82e3e9d14 6028af4ff87fb854 6028af4ff87fb854 +effect cursedCastleWater (14,64) +11 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +13 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +15 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +7 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +9 at 1234.567 s 5 e3eaacca366411a8 edcad84d85cf76b8 edcad84d85cf76b8 a3407042afaef688 a3407042afaef688 +effect cursedCastleWater (14,64) +9 at 1235.817 s 5 5cdf5ca8b3feecf8 efa13338bcae2a88 efa13338bcae2a88 90d1b63ded556e58 90d1b63ded556e58 effect devilsEye (14,17) +0 at 1234.567 s 2 0deb3acf8c4d5af9 a0de21137ee3aa91 a0de21137ee3aa91 0deb3acf8c4d5af9 0deb3acf8c4d5af9 effect devilsEye (14,17) +0 at 1234.567 s, doppelganger 2 34391f8c4ff92871 21a874bf3767b40f 21a874bf3767b40f 34391f8c4ff92871 34391f8c4ff92871 effect devilsEye (14,17) +0 at 1234.567 s, excellent 4 73391f62617970d6 76de59791d87455e 9f4ef3e014248607 88492ea8367d094d 73391f62617970d6 @@ -985,6 +1013,34 @@ effect devilsEye (14,17) +15 at 1234.567 s 8 8788f28ae5f02876 85d4faaed0b0e89c 8 effect devilsEye (14,17) +7 at 1234.567 s 8 8788f28ae5f02876 85d4faaed0b0e89c 85d4faaed0b0e89c 8788f28ae5f02876 8788f28ae5f02876 effect devilsEye (14,17) +9 at 1234.567 s 8 8788f28ae5f02876 85d4faaed0b0e89c 85d4faaed0b0e89c 8788f28ae5f02876 8788f28ae5f02876 effect devilsEye (14,17) +9 at 1235.817 s 8 aa8fd7e9239384f8 aa8fd7e9239384f8 aa8fd7e9239384f8 f78c766f6b71bfb6 aa8fd7e9239384f8 +effect devilsInvitation (14,19) +0 at 1234.567 s 2 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 +effect devilsInvitation (14,19) +0 at 1234.567 s, doppelganger 2 c792aaa51a2df8c5 c792aaa51a2df8c5 c792aaa51a2df8c5 c792aaa51a2df8c5 c792aaa51a2df8c5 +effect devilsInvitation (14,19) +0 at 1234.567 s, excellent 4 8b1b39507392f87e 8b1b39507392f87e 84e536871d9574b1 acfac2e5b1b0f1af 8b1b39507392f87e +effect devilsInvitation (14,19) +0 at 1234.567 s, fading 0.5 2 b37d69da1e5d1615 b37d69da1e5d1615 b37d69da1e5d1615 b37d69da1e5d1615 b37d69da1e5d1615 +effect devilsInvitation (14,19) +0 at 1234.567 s, in a monster's hands 2 91a1fcaccf0b0847 91a1fcaccf0b0847 91a1fcaccf0b0847 91a1fcaccf0b0847 91a1fcaccf0b0847 +effect devilsInvitation (14,19) +0 at 1234.567 s, without the skin 2 da725e1642b40293 da725e1642b40293 da725e1642b40293 da725e1642b40293 da725e1642b40293 +effect devilsInvitation (14,19) +0 at 1235.817 s 2 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 +effect devilsInvitation (14,19) +0 at 1238.267 s 2 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 0f6acad15c038ab1 +effect devilsInvitation (14,19) +11 at 1234.567 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsInvitation (14,19) +13 at 1234.567 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsInvitation (14,19) +15 at 1234.567 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsInvitation (14,19) +7 at 1234.567 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsInvitation (14,19) +9 at 1234.567 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsInvitation (14,19) +9 at 1235.817 s 8 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 bc620a403f7334d3 +effect devilsKey (14,18) +0 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect devilsKey (14,18) +0 at 1234.567 s, doppelganger 1 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a +effect devilsKey (14,18) +0 at 1234.567 s, excellent 2 62c7579ca5427cae 62c7579ca5427cae 1ca157025693d60e 813fbae077d698da 62c7579ca5427cae +effect devilsKey (14,18) +0 at 1234.567 s, fading 0.5 1 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff +effect devilsKey (14,18) +0 at 1234.567 s, in a monster's hands 1 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 +effect devilsKey (14,18) +0 at 1234.567 s, without the skin 1 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 +effect devilsKey (14,18) +0 at 1235.817 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect devilsKey (14,18) +0 at 1238.267 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect devilsKey (14,18) +11 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect devilsKey (14,18) +13 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect devilsKey (14,18) +15 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect devilsKey (14,18) +7 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect devilsKey (14,18) +9 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect devilsKey (14,18) +9 at 1235.817 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad effect divineSet (10,19) +0 at 1234.567 s 3 2ad71a874133f182 2ad71a874133f182 2ad71a874133f182 2ad71a874133f182 2ad71a874133f182 effect divineSet (10,19) +0 at 1234.567 s, doppelganger 3 bf111a13f094d9b9 bf111a13f094d9b9 bf111a13f094d9b9 bf111a13f094d9b9 bf111a13f094d9b9 effect divineSet (10,19) +0 at 1234.567 s, excellent 6 3fde668f9975e890 3fde668f9975e890 c3885e919f682ee2 d1d5400d1ea21c46 3fde668f9975e890 @@ -1669,6 +1725,20 @@ effect pulsingGlow (6,13) +15 at 1234.567 s 8 34cde423f4c72451 34cde423f4c72451 effect pulsingGlow (6,13) +7 at 1234.567 s 4 ee4cfc57c4cee30b ee4cfc57c4cee30b ee4cfc57c4cee30b 13e82a90d0010add 13e82a90d0010add effect pulsingGlow (6,13) +9 at 1234.567 s 6 eea0350a22a1887a eea0350a22a1887a eea0350a22a1887a cf36acecb34bb406 cf36acecb34bb406 effect pulsingGlow (6,13) +9 at 1235.817 s 6 93242a175ea535fa 93242a175ea535fa 93242a175ea535fa 93242a175ea535fa 93242a175ea535fa +effect pumpkinOfLuck (14,45) +0 at 1234.567 s 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +effect pumpkinOfLuck (14,45) +0 at 1234.567 s, doppelganger 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +effect pumpkinOfLuck (14,45) +0 at 1234.567 s, excellent 5 be9649a031afb609 be9649a031afb609 1619c95455c5f1e0 31ce8a01fe4c8261 3ad1d092224f1f86 +effect pumpkinOfLuck (14,45) +0 at 1234.567 s, fading 0.5 3 43ad17ae5399252b 43ad17ae5399252b 43ad17ae5399252b 2078e56cd3a47e48 2078e56cd3a47e48 +effect pumpkinOfLuck (14,45) +0 at 1234.567 s, in a monster's hands 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +effect pumpkinOfLuck (14,45) +0 at 1234.567 s, without the skin 3 13156e5a60fe2eb8 13156e5a60fe2eb8 13156e5a60fe2eb8 aea35318025396db aea35318025396db +effect pumpkinOfLuck (14,45) +0 at 1235.817 s 3 7cef69f36b7d3e19 7cef69f36b7d3e19 7cef69f36b7d3e19 e1c74622e73cade6 e1c74622e73cade6 +effect pumpkinOfLuck (14,45) +0 at 1238.267 s 3 fee74c024ef29b3b fee74c024ef29b3b fee74c024ef29b3b 716bffc31584a118 716bffc31584a118 +effect pumpkinOfLuck (14,45) +11 at 1234.567 s 9 752d26db8f39c7a0 752d26db8f39c7a0 752d26db8f39c7a0 641abe309a0b0f51 641abe309a0b0f51 +effect pumpkinOfLuck (14,45) +13 at 1234.567 s 9 c6b3d406972c0f0a c6b3d406972c0f0a c6b3d406972c0f0a 0afb9bbc87399087 0afb9bbc87399087 +effect pumpkinOfLuck (14,45) +15 at 1234.567 s 9 c6b3d406972c0f0a c6b3d406972c0f0a c6b3d406972c0f0a 0afb9bbc87399087 0afb9bbc87399087 +effect pumpkinOfLuck (14,45) +7 at 1234.567 s 5 dc7758a0e31933a9 dc7758a0e31933a9 dc7758a0e31933a9 8ef2aa959d337a08 8ef2aa959d337a08 +effect pumpkinOfLuck (14,45) +9 at 1234.567 s 7 b8cd2e643587214e b8cd2e643587214e b8cd2e643587214e 210dd1230adc3f59 210dd1230adc3f59 +effect pumpkinOfLuck (14,45) +9 at 1235.817 s 7 ab1d844065f922b8 ab1d844065f922b8 ab1d844065f922b8 351925472b56155b 351925472b56155b effect redSpirit (7,24) +0 at 1234.567 s 4 82678add10b118e3 82678add10b118e3 1e6ecbbdff09e861 82678add10b118e3 82678add10b118e3 effect redSpirit (7,24) +0 at 1234.567 s, doppelganger 4 c21da4c6ca0d4063 c21da4c6ca0d4063 e401c469ba03b0d1 c21da4c6ca0d4063 c21da4c6ca0d4063 effect redSpirit (7,24) +0 at 1234.567 s, excellent 8 729d012e2d12b6ea 729d012e2d12b6ea f4dcf153effdf9d5 061b8c7f2bb9a0b7 729d012e2d12b6ea @@ -1697,6 +1767,20 @@ effect redSpirit (9,24) +15 at 1234.567 s 16 42a9db3bee0dcf2c 42a9db3bee0dcf2c 6 effect redSpirit (9,24) +7 at 1234.567 s 8 a8b108cf605b8908 a8b108cf605b8908 8e68d1ca4952d10c a8b108cf605b8908 a8b108cf605b8908 effect redSpirit (9,24) +9 at 1234.567 s 12 6f328931c50ad6cd 6f328931c50ad6cd 2ff20e22e0689b0f 6f328931c50ad6cd 6f328931c50ad6cd effect redSpirit (9,24) +9 at 1235.817 s 12 17ada1e057836aaf 17ada1e057836aaf 17ada1e057836aaf 992c36bc9e037ebd 17ada1e057836aaf +effect rena (14,21) +0 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect rena (14,21) +0 at 1234.567 s, doppelganger 1 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a +effect rena (14,21) +0 at 1234.567 s, excellent 2 62c7579ca5427cae 62c7579ca5427cae 1ca157025693d60e 813fbae077d698da 62c7579ca5427cae +effect rena (14,21) +0 at 1234.567 s, fading 0.5 1 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff +effect rena (14,21) +0 at 1234.567 s, in a monster's hands 1 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 +effect rena (14,21) +0 at 1234.567 s, without the skin 1 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 +effect rena (14,21) +0 at 1235.817 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect rena (14,21) +0 at 1238.267 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect rena (14,21) +11 at 1234.567 s 4 380cbb06c383b232 380cbb06c383b232 380cbb06c383b232 380cbb06c383b232 380cbb06c383b232 +effect rena (14,21) +13 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect rena (14,21) +15 at 1234.567 s 4 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad 8ae0ad60563c54ad +effect rena (14,21) +7 at 1234.567 s 2 631103c141e90d89 631103c141e90d89 631103c141e90d89 631103c141e90d89 631103c141e90d89 +effect rena (14,21) +9 at 1234.567 s 3 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff +effect rena (14,21) +9 at 1235.817 s 3 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff 94180c2225e487ff effect scrollingDown (3,9) +0 at 1234.567 s 2 c83faaa84a36d324 c83faaa84a36d324 c83faaa84a36d324 c83faaa84a36d324 c83faaa84a36d324 effect scrollingDown (3,9) +0 at 1234.567 s, doppelganger 2 7f749adc12056ccf 7f749adc12056ccf 7f749adc12056ccf 7f749adc12056ccf 7f749adc12056ccf effect scrollingDown (3,9) +0 at 1234.567 s, excellent 3 3aef9234ae5fd0ce 3aef9234ae5fd0ce 7ed95d2c4f521cae a3fddc17d76242fa 3aef9234ae5fd0ce @@ -1767,6 +1851,90 @@ effect staffOfKundun (5,11) +15 at 1234.567 s 15 ef43f423364c2ac1 cb73d447d4cae1 effect staffOfKundun (5,11) +7 at 1234.567 s 9 7cac45de4f9ea6bb 2405c8e50bd194a2 2405c8e50bd194a2 2a343797461c8fb2 2a343797461c8fb2 effect staffOfKundun (5,11) +9 at 1234.567 s 12 a331a25ef127ec7e 659ec86d22755f29 659ec86d22755f29 b0568c4d145fd16a b0568c4d145fd16a effect staffOfKundun (5,11) +9 at 1235.817 s 12 595bce62412bacf6 595bce62412bacf6 595bce62412bacf6 dfd6cbb842395d6a 595bce62412bacf6 +effect wingOfDimension (12,43) +0 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +0 at 1234.567 s, doppelganger 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +0 at 1234.567 s, excellent 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +0 at 1234.567 s, fading 0.5 4 4f3ffddf8bdb31d8 4f3ffddf8bdb31d8 4f3ffddf8bdb31d8 4f3ffddf8bdb31d8 4f3ffddf8bdb31d8 +effect wingOfDimension (12,43) +0 at 1234.567 s, in a monster's hands 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +0 at 1234.567 s, without the skin 4 134a6608d939fb3c 134a6608d939fb3c 134a6608d939fb3c 134a6608d939fb3c 134a6608d939fb3c +effect wingOfDimension (12,43) +0 at 1235.817 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +0 at 1238.267 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +11 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +13 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +15 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +7 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +9 at 1234.567 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfDimension (12,43) +9 at 1235.817 s 4 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a 881f4720de72fb2a +effect wingOfEternal (12,37) +0 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +0 at 1234.567 s, doppelganger 1 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a 207ebf6839212d3a +effect wingOfEternal (12,37) +0 at 1234.567 s, excellent 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +0 at 1234.567 s, fading 0.5 1 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff 30bfae87701377ff +effect wingOfEternal (12,37) +0 at 1234.567 s, in a monster's hands 1 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 9e6341693896da54 +effect wingOfEternal (12,37) +0 at 1234.567 s, without the skin 1 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 3647418b17139f56 +effect wingOfEternal (12,37) +0 at 1235.817 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +0 at 1238.267 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +11 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +13 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +15 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +7 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +9 at 1234.567 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfEternal (12,37) +9 at 1235.817 s 1 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 a4037696b8ee1e89 +effect wingOfIllusion (12,38) +0 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +0 at 1234.567 s, doppelganger 1 eb7ce8e14dfa2a82 eb7ce8e14dfa2a82 eb7ce8e14dfa2a82 eb7ce8e14dfa2a82 eb7ce8e14dfa2a82 +effect wingOfIllusion (12,38) +0 at 1234.567 s, excellent 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +0 at 1234.567 s, fading 0.5 1 a1d73f614a2c606d a1d73f614a2c606d a1d73f614a2c606d a1d73f614a2c606d a1d73f614a2c606d +effect wingOfIllusion (12,38) +0 at 1234.567 s, in a monster's hands 1 7652d615d257ec28 7652d615d257ec28 7652d615d257ec28 7652d615d257ec28 7652d615d257ec28 +effect wingOfIllusion (12,38) +0 at 1234.567 s, without the skin 1 5d978b5197cafaf0 5d978b5197cafaf0 5d978b5197cafaf0 5d978b5197cafaf0 5d978b5197cafaf0 +effect wingOfIllusion (12,38) +0 at 1235.817 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +0 at 1238.267 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +11 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +13 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +15 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +7 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +9 at 1234.567 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfIllusion (12,38) +9 at 1235.817 s 1 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb 553fe2c520ecd6fb +effect wingOfRuin (12,39) +0 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +0 at 1234.567 s, doppelganger 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +0 at 1234.567 s, excellent 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +0 at 1234.567 s, fading 0.5 3 350c0b1b7518af1d 350c0b1b7518af1d 350c0b1b7518af1d 735b23a4f2415cbc cea2ab26ca1e3447 +effect wingOfRuin (12,39) +0 at 1234.567 s, in a monster's hands 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +0 at 1234.567 s, without the skin 3 8b8d9a8f7855018c 8b8d9a8f7855018c 8b8d9a8f7855018c 0e69d6413048447f a46776a72274a84e +effect wingOfRuin (12,39) +0 at 1235.817 s 3 aac5ea9b1afa7d3b aac5ea9b1afa7d3b 792bfb697dc9ce33 725e35cccf6a51f6 aac5ea9b1afa7d3b +effect wingOfRuin (12,39) +0 at 1238.267 s 3 89761b48152f5543 89761b48152f5543 89761b48152f5543 dde5ba2655ba1dc0 89761b48152f5543 +effect wingOfRuin (12,39) +11 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +13 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +15 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +7 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +9 at 1234.567 s 3 dcfca1519fe329a3 dcfca1519fe329a3 dcfca1519fe329a3 744fc803ac675578 e906e2189ef7e335 +effect wingOfRuin (12,39) +9 at 1235.817 s 3 aac5ea9b1afa7d3b aac5ea9b1afa7d3b 792bfb697dc9ce33 725e35cccf6a51f6 aac5ea9b1afa7d3b +effect wingOfStorm (12,36) +0 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +0 at 1234.567 s, doppelganger 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +0 at 1234.567 s, excellent 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +0 at 1234.567 s, fading 0.5 3 5d6cdf6563cb958c 5d6cdf6563cb958c 5d6cdf6563cb958c 5d6cdf6563cb958c 5d6cdf6563cb958c +effect wingOfStorm (12,36) +0 at 1234.567 s, in a monster's hands 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +0 at 1234.567 s, without the skin 3 33fc0cd60761fb11 33fc0cd60761fb11 33fc0cd60761fb11 33fc0cd60761fb11 33fc0cd60761fb11 +effect wingOfStorm (12,36) +0 at 1235.817 s 3 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a +effect wingOfStorm (12,36) +0 at 1238.267 s 3 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a +effect wingOfStorm (12,36) +11 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +13 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +15 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +7 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +9 at 1234.567 s 3 aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a aacf8d3ce70f0d3a +effect wingOfStorm (12,36) +9 at 1235.817 s 3 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a 9a04fff7e84a039a +effect wingsOfDarkness (12,6) +0 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +0 at 1234.567 s, doppelganger 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +0 at 1234.567 s, excellent 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +0 at 1234.567 s, fading 0.5 2 18dc23c9af2e9005 18dc23c9af2e9005 18dc23c9af2e9005 18dc23c9af2e9005 18dc23c9af2e9005 +effect wingsOfDarkness (12,6) +0 at 1234.567 s, in a monster's hands 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +0 at 1234.567 s, without the skin 2 df7b506d3836441a df7b506d3836441a df7b506d3836441a df7b506d3836441a df7b506d3836441a +effect wingsOfDarkness (12,6) +0 at 1235.817 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +0 at 1238.267 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +11 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +13 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +15 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +7 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +9 at 1234.567 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 +effect wingsOfDarkness (12,6) +9 at 1235.817 s 2 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 38b790513ce24878 effect wingsOfDragon (12,5) +0 at 1234.567 s 2 332e8a0e0ce8fd08 04836f7f8a5110ba 04836f7f8a5110ba 332e8a0e0ce8fd08 332e8a0e0ce8fd08 effect wingsOfDragon (12,5) +0 at 1234.567 s, doppelganger 2 4afdb02981d59262 e2a86bb0b410695a e2a86bb0b410695a 4afdb02981d59262 4afdb02981d59262 effect wingsOfDragon (12,5) +0 at 1234.567 s, excellent 2 332e8a0e0ce8fd08 04836f7f8a5110ba 04836f7f8a5110ba 332e8a0e0ce8fd08 332e8a0e0ce8fd08 @@ -3511,6 +3679,20 @@ platinaStaff (5,13) +15 at 1234.567 s 8 a5f6c210a0a8fcec a5f6c210a0a8fcec a5f6c2 platinaStaff (5,13) +7 at 1234.567 s 4 f768923d591117c6 f768923d591117c6 f768923d591117c6 f288685a3d6d64f6 f768923d591117c6 platinaStaff (5,13) +9 at 1234.567 s 6 2b73e3cca6ed38d5 2b73e3cca6ed38d5 2b73e3cca6ed38d5 091cda881fb5ce25 2b73e3cca6ed38d5 platinaStaff (5,13) +9 at 1235.817 s 6 af4556ca266b37ad af4556ca266b37ad af4556ca266b37ad f8a0f45bd122d141 af4556ca266b37ad +pumpkinOfLuck (14,45) +0 at 1234.567 s 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +pumpkinOfLuck (14,45) +0 at 1234.567 s, doppelganger 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +pumpkinOfLuck (14,45) +0 at 1234.567 s, excellent 5 be9649a031afb609 be9649a031afb609 1619c95455c5f1e0 31ce8a01fe4c8261 3ad1d092224f1f86 +pumpkinOfLuck (14,45) +0 at 1234.567 s, fading 0.5 3 43ad17ae5399252b 43ad17ae5399252b 43ad17ae5399252b 2078e56cd3a47e48 2078e56cd3a47e48 +pumpkinOfLuck (14,45) +0 at 1234.567 s, in a monster's hands 3 f5ed50e71c89e4fb f5ed50e71c89e4fb f5ed50e71c89e4fb e2efc53cb5a4f8d8 e2efc53cb5a4f8d8 +pumpkinOfLuck (14,45) +0 at 1234.567 s, without the skin 3 13156e5a60fe2eb8 13156e5a60fe2eb8 13156e5a60fe2eb8 aea35318025396db aea35318025396db +pumpkinOfLuck (14,45) +0 at 1235.817 s 3 7cef69f36b7d3e19 7cef69f36b7d3e19 7cef69f36b7d3e19 e1c74622e73cade6 e1c74622e73cade6 +pumpkinOfLuck (14,45) +0 at 1238.267 s 3 fee74c024ef29b3b fee74c024ef29b3b fee74c024ef29b3b 716bffc31584a118 716bffc31584a118 +pumpkinOfLuck (14,45) +11 at 1234.567 s 9 752d26db8f39c7a0 752d26db8f39c7a0 752d26db8f39c7a0 641abe309a0b0f51 641abe309a0b0f51 +pumpkinOfLuck (14,45) +13 at 1234.567 s 9 c6b3d406972c0f0a c6b3d406972c0f0a c6b3d406972c0f0a 0afb9bbc87399087 0afb9bbc87399087 +pumpkinOfLuck (14,45) +15 at 1234.567 s 9 c6b3d406972c0f0a c6b3d406972c0f0a c6b3d406972c0f0a 0afb9bbc87399087 0afb9bbc87399087 +pumpkinOfLuck (14,45) +7 at 1234.567 s 5 dc7758a0e31933a9 dc7758a0e31933a9 dc7758a0e31933a9 8ef2aa959d337a08 8ef2aa959d337a08 +pumpkinOfLuck (14,45) +9 at 1234.567 s 7 b8cd2e643587214e b8cd2e643587214e b8cd2e643587214e 210dd1230adc3f59 210dd1230adc3f59 +pumpkinOfLuck (14,45) +9 at 1235.817 s 7 ab1d844065f922b8 ab1d844065f922b8 ab1d844065f922b8 351925472b56155b 351925472b56155b rareItemTicket (14,62) +0 at 1234.567 s 3 fd2a05d186f2bd2f fd2a05d186f2bd2f fd2a05d186f2bd2f d49e6bcb00513e26 fd2a05d186f2bd2f rareItemTicket (14,62) +0 at 1234.567 s, doppelganger 3 fd2a05d186f2bd2f fd2a05d186f2bd2f fd2a05d186f2bd2f d49e6bcb00513e26 fd2a05d186f2bd2f rareItemTicket (14,62) +0 at 1234.567 s, excellent 5 9e9eb84ce98dba10 9e9eb84ce98dba10 0bf2b56029e9c337 c06ef010d393839e 9e9eb84ce98dba10 diff --git a/tests/data/test_bone_things_preview.cpp b/tests/data/test_bone_things_preview.cpp new file mode 100644 index 0000000000..0f7536d60e --- /dev/null +++ b/tests/data/test_bone_things_preview.cpp @@ -0,0 +1,712 @@ +#include "stdafx.h" + +#include "doctest.h" + +// The live preview of things on bones (FX1.7c, design section 7a, L51 to L54): the marks of the effect lists that the +// game's draw and move loops ask, and the Style Editor's views creating their items' things in the game's lists. + +#ifdef _EDITOR + +#include "LookRecorder.h" +#include "../gamelogic/ShippedLooksScope.h" + +#include "Core/Globals/_TextureIndex.h" +#include "Core/Globals/_define.h" +#include "Data/GameData/ItemData/ItemModelSlots.h" +#include "Engine/Object/ZzzCharacter.h" +#include "Engine/Object/ZzzInterface.h" +#include "Render/Drawing/DrawCallLog.h" +#include "Render/Effects/EffectDraw.h" +#include "Render/Effects/PreviewSlots.h" +#include "Render/Effects/ZzzEffect.h" +#include "Render/Items/ItemEffects.h" +#include "Render/Renderer/MuRenderer.h" +#include "Render/Textures/ZzzOpenglUtil.h" +#include "Scenes/SceneCommon.h" +#include "Scenes/SceneCore.h" +#include "UI/EffectBrowser/EffectPreviewCamera.h" +#include "UI/EffectBrowser/EffectPreviewScene.h" +#include "UI/ItemTools/ItemMeshPicking.h" +#include "UI/StyleEditor/BoneMarks.h" +#include "UI/StyleEditor/BoneThingsPreview.h" + +#include +#include +#include +#include +#include + +namespace +{ +using Render::Effects::PreviewSlots::List; +namespace PreviewSlots = Render::Effects::PreviewSlots; + +// Counts the sprites and lightning quads the draw loops hand it. +class CountingDrawer final : public Render::EffectDrawing::EffectDrawer +{ +public: + int sprites = 0; + int quads = 0; + + void SetState(const Render::EffectDrawing::EffectState&) override {} + void DrawSprite(const Render::EffectDrawing::SpriteDraw&) override + { + ++sprites; + } + void DrawQuads(const Render::EffectDrawing::QuadsDraw&) override + { + ++quads; + } + void DrawDecal(const Render::EffectDrawing::DecalDraw&) override {} + void DrawCircle(const Render::EffectDrawing::CircleDraw&) override {} + void DrawPlane(const Render::EffectDrawing::PlaneDraw&) override {} +}; + +// The draw loops draw into `drawer` and the renderer is a log while it lives. +class DrawScope +{ +public: + explicit DrawScope(CountingDrawer& drawer) + { + Render::EffectDrawing::SetEffectDrawer(&drawer); + mu::SetRendererOverride(&m_log); + } + ~DrawScope() + { + mu::SetRendererOverride(nullptr); + Render::EffectDrawing::SetEffectDrawer(nullptr); + } + DrawScope(const DrawScope&) = delete; + DrawScope& operator=(const DrawScope&) = delete; + +private: + Render::Drawing::DrawCallLog m_log; +}; + +void ClearLists() +{ + for (int i = 0; i < MAX_SPRITES; ++i) + { + Sprites[i].Live = false; + } + for (int i = 0; i < MAX_PARTICLES; ++i) + { + Particles[i].Live = false; + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + Joints[i].Live = false; + } + for (int i = 0; i < MAX_EFFECTS; ++i) + { + Effects[i].Live = false; + } + PreviewSlots::Clear(); +} + +// The world the Style Editor's views create in: a character standing in the main scene. +class PreviewWorld +{ +public: + PreviewWorld() + : m_character(std::make_unique()), m_hero(Hero), m_scene(SceneFlag), m_loading(LoadingWorld), + m_render(EnableMainRender), m_factor(FPS_ANIMATION_FACTOR) + { + m_character->Object.Live = true; + Vector(13120.0f, 12480.0f, 140.0f, m_character->Object.Position); + Hero = m_character.get(); + SceneFlag = MAIN_SCENE; + LoadingWorld = 0; + EnableMainRender = true; + FPS_ANIMATION_FACTOR = 1.0f; + ClearLists(); + } + ~PreviewWorld() + { + ClearLists(); + Hero = m_hero; + SceneFlag = m_scene; + LoadingWorld = m_loading; + EnableMainRender = m_render; + FPS_ANIMATION_FACTOR = m_factor; + } + PreviewWorld(const PreviewWorld&) = delete; + PreviewWorld& operator=(const PreviewWorld&) = delete; + + const float* Place() const + { + return m_character->Object.Position; + } + +private: + std::unique_ptr m_character; + CHARACTER* m_hero; + EGameScene m_scene; + int m_loading; + bool m_render; + float m_factor; +}; + +std::vector LiveSprites() +{ + std::vector live; + for (int i = 0; i < MAX_SPRITES; ++i) + { + if (Sprites[i].Live) + { + live.push_back(i); + } + } + return live; +} + +std::vector LiveJoints() +{ + std::vector live; + for (int i = 0; i < MAX_JOINTS; ++i) + { + if (Joints[i].Live) + { + live.push_back(i); + } + } + return live; +} + +float DistanceTo(const float* a, const float* b) +{ + const float dx = a[0] - b[0]; + const float dy = a[1] - b[1]; + const float dz = a[2] - b[2]; + return std::sqrt(dx * dx + dy * dy + dz * dz); +} + +// What view 0 shows of `item`: the item effect its model runs. +MuEditor::Looks::BoneThingsShown Shown(int item, MuEditor::Effects::PreviewItemPose pose, + std::optional stoppedAt = std::nullopt) +{ + MuEditor::Looks::BoneThingsShown shown; + shown.request.showOn = MuEditor::Effects::PreviewShowOn::Item; + shown.request.itemType = item; + shown.request.itemPose = pose; + shown.effect = Render::Items::ItemEffects::EffectOf(MuEditor::Effects::PreviewItemModelsOf(shown.request).model); + shown.stoppedAt = stoppedAt; + return shown; +} + +// One frame of the game for the views, in the game's order: the sprites of the last frame cleared, the lightning moved +// (lightning that lives a frame ends), then the views' update. A view's draw comes after, in the editor's render. +void Frame(MuEditor::Looks::BoneThingsPreview& preview) +{ + ClearSprites(); + MoveJoints(); + preview.Update(); +} + +// The live joints marked for a view. +int JointsOf(int view) +{ + int count = 0; + for (int i = 0; i < MAX_JOINTS; ++i) + { + if (Joints[i].Live && PreviewSlots::ViewOf(List::Joint, i) == view + 1) + { + ++count; + } + } + return count; +} +} // namespace + +TEST_CASE("The draw loops draw the game's slots and a preview view's only in its capture, and a stopped view's don't " + "move (design L51, L54) [looks][preview]") +{ + ClearLists(); + vec3_t place{0.0f, 0.0f, 0.0f}; + vec3_t light{1.0f, 1.0f, 1.0f}; + const int game = CreateSprite(BITMAP_LIGHT, place, 1.0f, light, nullptr); + const int previewed = CreateSprite(BITMAP_LIGHT, place, 1.0f, light, nullptr); + REQUIRE(previewed != game); + PreviewSlots::Mark(List::Sprite, previewed, 2); + CHECK(PreviewSlots::ViewOf(List::Sprite, previewed) == 2); + CHECK(PreviewSlots::ViewOf(List::Sprite, game) == 0); + // Slots past those ever marked are the game's. + CHECK(PreviewSlots::ViewOf(List::Joint, MAX_JOINTS - 1) == 0); + + CountingDrawer world; + { + const DrawScope draw(world); + BeginSpriteDraws(); + RenderSprites(); + } + CHECK(world.sprites == 1); + CHECK_FALSE(PreviewSlots::IsCapturing()); + + CountingDrawer view; + { + const DrawScope draw(view); + const PreviewSlots::CaptureScope capture(2); + CHECK(PreviewSlots::IsCapturing()); + CHECK(PreviewSlots::Draws(List::Sprite, previewed)); + CHECK_FALSE(PreviewSlots::Draws(List::Sprite, game)); + BeginSpriteDraws(); + RenderSprites(); + } + CHECK(view.sprites == 1); + CHECK_FALSE(PreviewSlots::IsCapturing()); + + // Another view's capture draws neither. + CountingDrawer other; + { + const DrawScope draw(other); + const PreviewSlots::CaptureScope capture(1); + BeginSpriteDraws(); + RenderSprites(); + } + CHECK(other.sprites == 0); + + CHECK(PreviewSlots::Moves(List::Sprite, previewed)); + PreviewSlots::SetStopped(2, true); + CHECK_FALSE(PreviewSlots::Moves(List::Sprite, previewed)); + CHECK(PreviewSlots::Moves(List::Sprite, game)); + // The game itself never stops. + PreviewSlots::SetStopped(0, true); + CHECK(PreviewSlots::Moves(List::Sprite, game)); + PreviewSlots::SetStopped(2, false); + CHECK(PreviewSlots::Moves(List::Sprite, previewed)); + + PreviewSlots::Clear(); + CHECK(PreviewSlots::ViewOf(List::Sprite, previewed) == 0); + ClearLists(); +} + +TEST_CASE("A Style Editor view creates its item's things on bones at the character, in the game's lists and marked " + "for it, draws only those, and removes them when it changes or is no longer drawn (design L51 to L53) " + "[looks][preview]") +{ + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); + const std::vector items = LookRecorder::ItemsUsing("wingsOfDarkness", Data::Looks::LookKind::ItemEffect); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + const int item = items.front(); + const PreviewWorld world; + auto preview = std::make_unique(); + MuEditor::Effects::EffectPreviewCamera camera; + camera.Frame({0.0f, 0.0f, 0.0f}, 100.0f); + + const MuEditor::Looks::BoneThingsShown inventory = Shown(item, MuEditor::Effects::PreviewItemPose::Inventory); + REQUIRE(inventory.effect != nullptr); + // Nothing is created before the view was drawn. + Frame(*preview); + CHECK(LiveSprites().empty()); + + CountingDrawer firstDraw; + { + const DrawScope draw(firstDraw); + preview->Draw(0, inventory, camera); + } + // It had nothing to draw yet. + CHECK(firstDraw.sprites == 0); + Frame(*preview); + const std::vector sprites = LiveSprites(); + REQUIRE_FALSE(sprites.empty()); + for (const int sprite : sprites) + { + CAPTURE(sprite); + CHECK(PreviewSlots::ViewOf(List::Sprite, sprite) == 1); + CHECK_FALSE(PreviewSlots::Draws(List::Sprite, sprite)); + CHECK(Sprites[sprite].Owner != nullptr); + // The copy of the item stands at the character, the wings' bones within a few hundred units of it. + CHECK(DistanceTo(Sprites[sprite].Position, world.Place()) < 400.0f); + } + + // The world draws none of them; the view draws them all, after its item. + CountingDrawer worldDraw; + { + const DrawScope draw(worldDraw); + BeginSpriteDraws(); + RenderSprites(); + } + CHECK(worldDraw.sprites == 0); + CountingDrawer viewDraw; + { + const DrawScope draw(viewDraw); + preview->Draw(0, inventory, camera); + } + CHECK(viewDraw.sprites == static_cast(sprites.size())); + + // Its lightning comes by chance; it is kept and marked like the sprites. + std::vector joints; + for (int frame = 0; frame < 400 && joints.empty(); ++frame) + { + preview->Draw(0, inventory, camera); + Frame(*preview); + joints = LiveJoints(); + } + REQUIRE_FALSE(joints.empty()); + for (const int joint : joints) + { + CHECK(PreviewSlots::ViewOf(List::Joint, joint) == 1); + } + CHECK(preview->GetCounts(0).joints == static_cast(joints.size())); + + SUBCASE("While the time is stopped, the game moves none of its things and it creates only its sprites (L54)") + { + const MuEditor::Looks::BoneThingsShown stopped = + Shown(item, MuEditor::Effects::PreviewItemPose::Inventory, 2500.0); + const float lifeTime = Joints[joints.front()].LifeTime; + // Ticked in the view's draw: the next move already leaves the lightning, which lives a frame, as it is. + for (int frame = 0; frame < 50; ++frame) + { + preview->Draw(0, stopped, camera); + Frame(*preview); + } + CHECK(Joints[joints.front()].LifeTime == lifeTime); + CHECK(LiveJoints() == joints); + CHECK(preview->GetCounts(0).joints == static_cast(joints.size())); + CHECK_FALSE(LiveSprites().empty()); + // And the view still draws it. + CountingDrawer stoppedDraw; + { + const DrawScope draw(stoppedDraw); + preview->Draw(0, stopped, camera); + } + CHECK(stoppedDraw.quads == static_cast(joints.size())); + // Time runs again: the next move moves it on. + preview->Draw(0, inventory, camera); + CHECK(PreviewSlots::Moves(List::Joint, joints.front())); + } + SUBCASE("Another pose of the item removes what the view made, before it makes it anew") + { + // With the time stopped the old lightning would stay: the view makes its effect once anew, to stop on. + preview->Draw(0, Shown(item, MuEditor::Effects::PreviewItemPose::Ground, 2500.0), camera); + Frame(*preview); + CHECK(LiveJoints().size() == joints.size()); + CHECK(preview->GetCounts(0).joints == static_cast(joints.size())); + CHECK(JointsOf(0) == static_cast(joints.size())); + CHECK_FALSE(LiveSprites().empty()); + } + SUBCASE("A view that is no longer drawn loses its things") + { + for (int frame = 0; frame < MuEditor::Looks::BoneThingsPreview::UpdatesWithoutDraw; ++frame) + { + Frame(*preview); + } + CHECK(LiveSprites().empty()); + CHECK(LiveJoints().empty()); + CHECK(preview->GetCounts(0).joints == 0); + CHECK(PreviewSlots::ViewOf(List::Joint, joints.front()) == 0); + } + SUBCASE("The world being cleared removes them") + { + preview->OnWorldClearing(); + CHECK(LiveJoints().empty()); + CHECK(preview->GetCounts(0).joints == 0); + } + SUBCASE("Outside the main scene the view creates nothing") + { + const EGameScene scene = SceneFlag; + SceneFlag = CHARACTER_SCENE; + preview->Draw(0, inventory, camera); + Frame(*preview); + CHECK(LiveSprites().empty()); + CHECK(LiveJoints().empty()); + SceneFlag = scene; + } + preview->RemoveAll(); +} + +TEST_CASE("Each view keeps its own lightning, and the game's lightning of the same type in slots a view left stays " + "the game's (design L52) [looks][preview]") +{ + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); + const std::vector items = LookRecorder::ItemsUsing("wingsOfDarkness", Data::Looks::LookKind::ItemEffect); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + const PreviewWorld world; + auto preview = std::make_unique(); + MuEditor::Effects::EffectPreviewCamera camera; + camera.Frame({0.0f, 0.0f, 0.0f}, 100.0f); + const MuEditor::Looks::BoneThingsShown shown = Shown(items.front(), MuEditor::Effects::PreviewItemPose::Inventory); + constexpr int Views = MuEditor::Looks::BoneThingsPreview::MaxViews; + const auto drawAll = [&] + { + for (int view = 0; view < Views; ++view) + { + preview->Draw(view, shown, camera); + } + }; + drawAll(); + Frame(*preview); + drawAll(); + // The Wings of Darkness' lightning lives a frame: each view makes the same anew every frame. + const int perView = JointsOf(0); + REQUIRE(perView > 0); + for (int view = 0; view < Views; ++view) + { + CHECK(JointsOf(view) == perView); + } + + // The game's own lightning takes the first free slots, of the same type and SubType as the views' (the + // character's Wings of Darkness): created after the views' lightning of the last frame ended, in slots the views + // had. They stay the game's: no view takes them for its own, draws them or removes them. + ClearSprites(); + MoveJoints(); + std::vector gameJoints; + for (int i = 0; i < perView; ++i) + { + vec3_t from{100.0f, 100.0f, 0.0f}; + vec3_t to{200.0f, 100.0f, 0.0f}; + vec3_t angle{0.0f, 0.0f, 0.0f}; + CreateJoint(BITMAP_JOINT_THUNDER, from, to, angle, 14, nullptr, 1.0f); + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + if (Joints[i].Live) + { + gameJoints.push_back(i); + } + } + REQUIRE(static_cast(gameJoints.size()) == perView); + preview->Update(); + for (int view = 0; view < Views; ++view) + { + CAPTURE(view); + CHECK(JointsOf(view) == perView); + CHECK(preview->GetCounts(view).joints == perView); + } + for (const int joint : gameJoints) + { + CAPTURE(joint); + CHECK(Joints[joint].Live); + CHECK(PreviewSlots::ViewOf(List::Joint, joint) == 0); + } + // Removing the views' things leaves the game's. + preview->RemoveAll(); + for (const int joint : gameJoints) + { + CHECK(Joints[joint].Live); + } + for (const int joint : gameJoints) + { + Joints[joint].Live = false; + } +} + +TEST_CASE("A double click in pick mode takes back the pick of its first click, once (design L58) [looks][preview]") +{ + namespace BoneMarks = MuEditor::Looks::BoneMarks; + constexpr double DoubleClick = 0.3; + BoneMarks::PickTakeBack pick; + Data::Looks::BonePlaces places; + places.bones = {4}; + std::optional from; + // Nothing picked yet: nothing to take back. + CHECK_FALSE(pick.TakeBack(places, from, 1.0, DoubleClick)); + CHECK(pick.Pick(places, false, from, 22, 1.0)); + CHECK(places.bones == std::vector{4, 22}); + CHECK(pick.TakeBack(places, from, 1.2, DoubleClick)); + CHECK(places.bones == std::vector{4}); + // Only once. + CHECK_FALSE(pick.TakeBack(places, from, 1.25, DoubleClick)); + CHECK(places.bones == std::vector{4}); + + // A double click long after the pick is not its. + pick.Pick(places, false, from, 22, 2.0); + CHECK_FALSE(pick.TakeBack(places, from, 3.0, DoubleClick)); + CHECK(places.bones == std::vector{4, 22}); + + // Between bones the start of a pair comes back too. + Data::Looks::BonePlaces pairs; + pick.Pick(pairs, true, from, 30, 4.0); + pick.Pick(pairs, true, from, 22, 5.0); + CHECK(pairs.between.size() == 1); + CHECK(pick.TakeBack(pairs, from, 5.1, DoubleClick)); + CHECK(pairs.between.empty()); + CHECK(from == 30); +} + +TEST_CASE("A click in pick mode adds a bone or takes it out, and picks lightning pairs start first (design L58) " + "[looks][preview]") +{ + namespace BoneMarks = MuEditor::Looks::BoneMarks; + Data::Looks::BonePlaces places; + std::optional from; + CHECK(BoneMarks::PickBone(places, false, from, 22)); + CHECK(BoneMarks::PickBone(places, false, from, 25)); + CHECK(places.bones == std::vector{22, 25}); + CHECK(BoneMarks::PickBone(places, false, from, 22)); + CHECK(places.bones == std::vector{25}); + + Data::Looks::BonePlaces pairs; + // The start waits for the end. + CHECK_FALSE(BoneMarks::PickBone(pairs, true, from, 30)); + CHECK(from == 30); + CHECK(BoneMarks::PickBone(pairs, true, from, 22)); + CHECK_FALSE(from.has_value()); + CHECK(pairs.between == std::vector>{{30, 22}}); + // The same pair again takes it out; the other way round is another pair. + BoneMarks::PickBone(pairs, true, from, 22); + CHECK(BoneMarks::PickBone(pairs, true, from, 30)); + CHECK(pairs.between == std::vector>{{30, 22}, {22, 30}}); + BoneMarks::PickBone(pairs, true, from, 30); + CHECK(BoneMarks::PickBone(pairs, true, from, 22)); + CHECK(pairs.between == std::vector>{{22, 30}}); + // A second click on the start lets it go. + BoneMarks::PickBone(pairs, true, from, 5); + CHECK_FALSE(BoneMarks::PickBone(pairs, true, from, 5)); + CHECK_FALSE(from.has_value()); + CHECK(pairs.between.size() == 1); +} + +TEST_CASE("The bone marks project as the preview's camera sees and find the dot under the mouse (design L58) " + "[looks][preview]") +{ + namespace BoneMarks = MuEditor::Looks::BoneMarks; + MuEditor::Effects::EffectPreviewCamera camera; + camera.Frame({0.0f, 0.0f, 0.0f}, 100.0f); + const ImVec2 min{100.0f, 50.0f}; + const ImVec2 max{500.0f, 350.0f}; + const std::optional center = BoneMarks::ToScreen(camera, min, max, camera.Center()); + REQUIRE(center.has_value()); + CHECK(center->x == doctest::Approx(300.0f)); + CHECK(center->y == doctest::Approx(200.0f)); + // Right and up on the screen are right and up of the view. + const MuEditor::Effects::EffectPreviewCamera::Basis basis = camera.GetBasis(); + MuEditor::Effects::PreviewVector rightUp{}; + for (std::size_t axis = 0; axis < 3; ++axis) + { + rightUp[axis] = camera.Center()[axis] + 20.0f * basis.right[axis] + 20.0f * basis.up[axis]; + } + const std::optional point = BoneMarks::ToScreen(camera, min, max, rightUp); + REQUIRE(point.has_value()); + CHECK(point->x > center->x); + CHECK(point->y < center->y); + // As a click's ray goes the other way. + const float width = max.x - min.x; + const float height = max.y - min.y; + const MuEditor::Items::MeshPicking::Ray ray = MuEditor::Items::MeshPicking::RayThroughView( + camera, width / height, (point->x - min.x) / width * 2.0f - 1.0f, 1.0f - (point->y - min.y) / height * 2.0f); + float along = 0.0f; + float off = 0.0f; + for (std::size_t axis = 0; axis < 3; ++axis) + { + along += (rightUp[axis] - ray.origin[axis]) * ray.direction[axis]; + } + for (std::size_t axis = 0; axis < 3; ++axis) + { + const float d = rightUp[axis] - ray.origin[axis] - along * ray.direction[axis]; + off += d * d; + } + CHECK(std::sqrt(off) < 0.01f * along); + // Behind the eye: nowhere. + MuEditor::Effects::PreviewVector behind{}; + const MuEditor::Effects::PreviewVector eye = camera.Eye(); + for (std::size_t axis = 0; axis < 3; ++axis) + { + behind[axis] = eye[axis] - 10.0f * basis.forward[axis]; + } + CHECK_FALSE(BoneMarks::ToScreen(camera, min, max, behind).has_value()); + + const std::vector dots{{10.0f, 10.0f}, {20.0f, 10.0f}, {40.0f, 40.0f}}; + CHECK(BoneMarks::NearestWithin(dots, {18.0f, 11.0f}, 7.0f) == 1u); + CHECK_FALSE(BoneMarks::NearestWithin(dots, {30.0f, 25.0f}, 7.0f).has_value()); +} + +TEST_CASE("The bone marks find the bones of a shown item as its view poses them (design L58) [looks][preview]") +{ + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); + const std::vector items = LookRecorder::ItemsUsing("wingsOfDarkness", Data::Looks::LookKind::ItemEffect); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + const MuEditor::Looks::BoneThingsShown shown = Shown(items.front(), MuEditor::Effects::PreviewItemPose::Inventory); + std::vector bones; + MuEditor::Looks::BoneMarks::BonesOf(shown.request, 0.0f, bones); + const MuEditor::Effects::PreviewItemModels models = MuEditor::Effects::PreviewItemModelsOf(shown.request); + REQUIRE(models.CanDraw()); + CHECK(static_cast(bones.size()) == Models[models.model].NumBones); + // Each with the bone it hangs on, for the skeleton's lines. + for (const auto& bone : bones) + { + CHECK(bone.parent == Models[models.model].Bones[bone.number].Parent); + } + CHECK(bones.front().parent == -1); + // The wings spread: their bones are not all in one place. + const auto apart = std::ranges::any_of(bones, [&](const auto& bone) { return bone.place != bones.front().place; }); + CHECK(apart); + // Turned, they move. + std::vector turned; + MuEditor::Looks::BoneMarks::BonesOf(shown.request, 90.0f, turned); + REQUIRE(turned.size() == bones.size()); + CHECK(turned.back().place != bones.back().place); +} + +TEST_CASE("The bone marks sit where a view creates its things on those bones (design L58) [looks][preview]") +{ + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); + const std::vector items = LookRecorder::ItemsUsing("wingsOfDarkness", Data::Looks::LookKind::ItemEffect); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + const PreviewWorld world; + // The Wings of Darkness' sprites, alone: one at each of their bones. + const Data::Looks::LookDefinition* shippedEffect = Render::Items::ItemEffects::EffectOf( + MuEditor::Effects::PreviewItemModelsOf( + Shown(items.front(), MuEditor::Effects::PreviewItemPose::Inventory).request) + .model); + REQUIRE(shippedEffect != nullptr); + Data::Looks::LookDefinition sprites = *shippedEffect; + std::erase_if(sprites.onBones, [](const Data::Looks::OnBones& entry) { return entry.places.bones.empty(); }); + REQUIRE(sprites.onBones.size() == 1); + const std::vector bones = sprites.onBones.front().places.bones; + + for (const auto pose : {MuEditor::Effects::PreviewItemPose::Inventory, MuEditor::Effects::PreviewItemPose::Ground}) + { + CAPTURE(static_cast(pose)); + for (const float turn : {0.0f, 70.0f}) + { + CAPTURE(turn); + ClearSprites(); + auto preview = std::make_unique(); + MuEditor::Effects::EffectPreviewCamera camera; + camera.Frame({0.0f, 0.0f, 0.0f}, 100.0f); + MuEditor::Looks::BoneThingsShown shown = Shown(items.front(), pose); + shown.effect = &sprites; + shown.turnDegrees = turn; + preview->Draw(0, shown, camera); + Frame(*preview); + std::vector marks; + MuEditor::Looks::BoneMarks::BonesOf(shown.request, turn, marks); + std::vector> created; + for (int i = 0; i < MAX_SPRITES; ++i) + { + if (Sprites[i].Live) + { + created.push_back({Sprites[i].Position[0] - Hero->Object.Position[0], + Sprites[i].Position[1] - Hero->Object.Position[1], + Sprites[i].Position[2] - Hero->Object.Position[2]}); + } + } + REQUIRE(created.size() == bones.size()); + for (std::size_t i = 0; i < bones.size(); ++i) + { + CAPTURE(bones[i]); + const auto& mark = marks[static_cast(bones[i])].place; + for (std::size_t axis = 0; axis < 3; ++axis) + { + CHECK(created[i][axis] == doctest::Approx(mark[axis]).epsilon(0.001)); + } + } + preview->RemoveAll(); + } + } +} + +#endif // _EDITOR diff --git a/tests/data/test_item_model_files.cpp b/tests/data/test_item_model_files.cpp index b5c28906cd..67df335bd9 100644 --- a/tests/data/test_item_model_files.cpp +++ b/tests/data/test_item_model_files.cpp @@ -1829,7 +1829,9 @@ TEST_CASE("Shipped item models keep the item effects of the old drawing code [da CHECK(effectOf(13, 43).empty()); CHECK(effectOf(13, 17).empty()); CHECK(effectOf(13, 18).empty()); - CHECK(effectOf(14, 64).empty()); + // The things on the bones of two render styles became item effects of their names (design L29). + CHECK(effectOf(14, 64) == "cursedCastleWater"); + CHECK(effectOf(14, 45) == "pumpkinOfLuck"); // The socket seeds and spheres and zen glow like level 0, whatever their // level (the old code set their level to 0, or drew zen plainly). diff --git a/tests/data/test_look_checks.cpp b/tests/data/test_look_checks.cpp index be8dec97ca..6d6418ceb2 100644 --- a/tests/data/test_look_checks.cpp +++ b/tests/data/test_look_checks.cpp @@ -250,6 +250,51 @@ TEST_CASE("Item effects are checked against the items that name them: meshes, va CHECK(Count(issues, ItemDataIssueSeverity::Warning, "looks[0].name") == 0); } +TEST_CASE("Things on bones are checked: a type the effect catalogue doesn't have is an error, a bone an item's model " + "doesn't have a warning about the item (design L55) [looks][checks]") +{ + LookDefinition effect{"wings"}; + OnBones flares; + flares.places.bones = {3, 12}; + flares.things.push_back({.kind = BoneThingKind::Sprite, .type = "flare"}); + OnBones lightning; + lightning.together = true; + lightning.places.between = {{2, 30}}; + lightning.things.push_back({.kind = BoneThingKind::Joint, .type = "jointThunder"}); + lightning.things.push_back({.kind = BoneThingKind::Joint, .type = "noSuchJoint"}); + effect.onBones = {flares, lightning}; + ItemModelDefinition model = Model(12, 6, ""); + model.itemEffect = "wings"; + const std::vector models{model}; + std::vector issues; + const RenderStyleCheckInput input{ + .models = models, + .typeExists = [](BoneThingKind kind, const std::string& type) + { return kind == BoneThingKind::Sprite ? type == "flare" : type == "jointThunder"; }, + .boneCount = [](int) { return 10; }}; + CheckItemEffects(std::vector{effect}, Source, input, issues); + INFO(Describe(issues)); + REQUIRE(issues.size() == 3); + CHECK(Count(issues, ItemDataIssueSeverity::Error, "looks[0].onBones[1].things[1].joint") == 1); + // Bones 12 and 30 are not in the item's model of ten bones; 2 and 3 are. + CHECK(Count(issues, ItemDataIssueSeverity::Warning, "looks[0].onBones[0].bones") == 1); + CHECK(Count(issues, ItemDataIssueSeverity::Warning, "looks[0].onBones[1].together.between") == 1); + for (const ItemDataIssue& issue : issues) + { + if (issue.severity == ItemDataIssueSeverity::Warning) + { + CHECK(issue.group == 12); + CHECK(issue.number == 6); + } + } + + // A model that is not loaded skips the bone checks. + issues.clear(); + const RenderStyleCheckInput unloaded{.models = models, .boneCount = [](int) { return 0; }}; + CheckItemEffects(std::vector{effect}, Source, unloaded, issues); + CHECK(issues.empty()); +} + TEST_CASE("The shipped item effects are used by items [looks][checks]") { const std::filesystem::path data = MU_TEST_DATA_DIR; diff --git a/tests/data/test_look_drawing.cpp b/tests/data/test_look_drawing.cpp index 346558ce0d..eac41d5b10 100644 --- a/tests/data/test_look_drawing.cpp +++ b/tests/data/test_look_drawing.cpp @@ -7,12 +7,15 @@ #include "Core/Globals/_enum.h" #include "Core/Utilities/Random.h" +#include "Data/GameData/EffectData/EffectTypeCatalogue.h" #include "Data/GameData/EffectData/GlowColorList.h" #include "Data/GameData/ItemData/ItemModelDatabase.h" #include "Data/GameData/ItemData/ItemModelDefinition.h" #include "Data/GameData/ItemData/PartModel.h" #include "Data/GameData/LookData/LookEffects.h" #include "Data/GameData/LookData/LookStore.h" +#include "Engine/Object/ZzzCharacter.h" +#include "Render/Effects/ZzzEffect.h" #include "Render/Items/ItemEffects.h" #include "Render/Items/ItemRenderStyles.h" #include "Render/Items/LookDrawing.h" @@ -541,41 +544,180 @@ TEST_CASE("An item effect that is data sets the item values of its entries whose CHECK(look.hiddenMesh == 1); CHECK(alpha == 2.f); } - Render::Items::Looks::SpawnItemEffect(effect, &object); + Render::Items::Looks::SpawnItemEffect(effect, {}, &model, &object, nullptr); CHECK(object.Light[0] == 0.5f); CHECK(object.Light[1] == 0.25f); CHECK(object.Light[2] == 1.f); } -TEST_CASE("An item names an item effect that is data before one still in code (design L14) [looks]") +TEST_CASE("An item effect creates its things on bones at the item's posed bones, between pairs and at the origin, " + "and nothing of a type the catalogue doesn't have or at a bone the model doesn't have (section 7b) [looks]") { - // wingsOfDarkness stays code until its things on bones move (step 3): it spawns and sets no value. - LookDefinition effect{"wingsOfDarkness", {}, {}}; - effect.itemValuesBefore = {{.values = {.glowStrength = 0.25f}}}; - g_LookStore.SetItemEffects({effect}); - REQUIRE(Render::Items::ItemEffects::ExistsInCode("wingsOfDarkness")); - ItemModelDatabaseScope database; - Data::Items::ItemModelDefinition entry; - entry.group = 0; - entry.number = 0; - entry.file = "Data/Item/Sword01.bmd"; - entry.itemEffect = "wingsOfDarkness"; - g_ItemModelDatabase.Build(std::span(&entry, 1), Data::Effects::GlowColorList{}); + const auto clear = [] + { + for (int i = 0; i < MAX_SPRITES; ++i) + { + Sprites[i].Live = false; + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + Joints[i].Live = false; + } + }; + clear(); + LookDefinition effect{"wings", {}, {}}; + OnBones lights; + lights.places.bones = {1, 0}; + lights.things.push_back({.kind = BoneThingKind::Sprite, + .type = "light", + .scale = 0.5f, + .color = {0.25f, 0.5f, 0.75f}, + .rotation = 0.5f}); + OnBones spark; + spark.places.origin = true; + spark.things.push_back({.kind = BoneThingKind::Sprite, .type = "spark3", .scale = 2.5f}); + spark.things.push_back({.kind = BoneThingKind::Sprite, .type = "noSuchSprite"}); + OnBones lightning; + lightning.together = true; + lightning.places.between = {{1, 0}}; + lightning.chance = Chance{.oneIn = 1, .draw = ChanceDraw::Plain}; + lightning.things.push_back({.kind = BoneThingKind::Joint, .type = "jointThunder", .subType = 14}); + lightning.things.push_back({.kind = BoneThingKind::Joint, .type = "jointSpirit", .subType = 4, .reversed = true}); + effect.onBones = {lights, spark, lightning}; + // No catalogue is built here; the numbers are the game's. + CHECK(Render::Items::Looks::ResolveBoneThingTypes(effect)[1][1] == -1); + const Render::Items::Looks::BoneThingTypes types{ + {BITMAP_LIGHT}, {BITMAP_SPARK + 1, -1}, {BITMAP_JOINT_THUNDER, BITMAP_JOINT_SPIRIT}}; + BMD model; + model.NumBones = 2; + model.BodyScale = 2.f; + Vector(100.f, 0.f, 0.f, model.BodyOrigin); + float bones[2][3][4] = {}; + for (int bone = 0; bone < 2; ++bone) + { + for (int axis = 0; axis < 3; ++axis) + { + bones[bone][axis][axis] = 1.f; + } + bones[bone][2][3] = 10.f * static_cast(bone + 1); + } OBJECT object; - DrawLook look; - float alpha = 1.f; - int level = 0; - CHECK(Render::Items::ItemEffects::Apply(&model, &object, look, MODEL_SWORD, alpha, level) == - Render::Items::ItemEffects::Result::Applied); - CHECK(look.blendMeshLight == 0.25f); - CHECK_FALSE(Render::Items::ItemEffects::Spawns(MODEL_SWORD)); + Vector(7.f, 8.f, 9.f, object.Position); + Render::Items::Looks::SpawnItemEffect(effect, types, &model, &object, bones); + + // Bone 1 is at height 20, bone 0 at 10, scaled by 2 and moved by the model's origin. + std::vector lightSprites; + const OBJECT* sparkSprite = nullptr; + for (int i = 0; i < MAX_SPRITES; ++i) + { + if (!Sprites[i].Live) + { + continue; + } + CHECK(Sprites[i].Owner == &object); + if (Sprites[i].Type == BITMAP_LIGHT) + { + lightSprites.push_back(&Sprites[i]); + } + else + { + CHECK(Sprites[i].Type == BITMAP_SPARK + 1); + sparkSprite = &Sprites[i]; + } + } + REQUIRE(lightSprites.size() == 2); + CHECK(lightSprites[0]->Position[0] == doctest::Approx(100.f)); + CHECK(lightSprites[0]->Position[2] == doctest::Approx(40.f)); + CHECK(lightSprites[1]->Position[2] == doctest::Approx(20.f)); + CHECK(lightSprites[0]->Scale == doctest::Approx(0.5f)); + CHECK(lightSprites[0]->Light[2] == doctest::Approx(0.75f)); + CHECK(lightSprites[0]->Angle[2] == doctest::Approx(0.5f)); + REQUIRE(sparkSprite != nullptr); + CHECK(sparkSprite->Position[1] == doctest::Approx(8.f)); + + // Thunder from bone 1 to bone 0, the spirit the other way. + std::vector joints; + for (int i = 0; i < MAX_JOINTS; ++i) + { + if (Joints[i].Live) + { + joints.push_back(&Joints[i]); + } + } + REQUIRE(joints.size() == 2); + const auto byType = [&joints](int type) + { return *std::ranges::find(joints, type, [](const JOINT* joint) { return joint->Type; }); }; + CHECK(byType(BITMAP_JOINT_THUNDER)->SubType == 14); + CHECK(byType(BITMAP_JOINT_THUNDER)->Target == &object); + // As the game's own calls with those places create them. + const JOINT thunder = *byType(BITMAP_JOINT_THUNDER); + const JOINT spirit = *byType(BITMAP_JOINT_SPIRIT); + for (int i = 0; i < MAX_JOINTS; ++i) + { + Joints[i].Live = false; + } + vec3_t from{100.f, 0.f, 40.f}; + vec3_t to{100.f, 0.f, 20.f}; + CreateJoint(BITMAP_JOINT_THUNDER, from, to, object.Angle, 14, &object, 1.f); + CreateJoint(BITMAP_JOINT_SPIRIT, to, from, object.Angle, 4, &object, 1.f); + for (int axis = 0; axis < 3; ++axis) + { + CHECK(thunder.Position[axis] == doctest::Approx(Joints[0].Position[axis])); + CHECK(thunder.TargetPosition[axis] == doctest::Approx(Joints[0].TargetPosition[axis])); + CHECK(spirit.Position[axis] == doctest::Approx(Joints[1].Position[axis])); + CHECK(spirit.TargetPosition[axis] == doctest::Approx(Joints[1].TargetPosition[axis])); + } + + const auto liveThings = [] + { + int live = 0; + for (int i = 0; i < MAX_SPRITES; ++i) + { + live += Sprites[i].Live ? 1 : 0; + } + for (int i = 0; i < MAX_JOINTS; ++i) + { + live += Joints[i].Live ? 1 : 0; + } + return live; + }; + // Without bones only the things at the origin. + clear(); + Render::Items::Looks::SpawnItemEffect(effect, types, &model, &object, nullptr); + CHECK(liveThings() == 1); + + // A bone the model doesn't have, or a pair with one, creates nothing: the pose holds nothing there. + clear(); + model.NumBones = 1; + Render::Items::Looks::SpawnItemEffect(effect, types, &model, &object, bones); + CHECK(liveThings() == 2); + clear(); +} + +TEST_CASE("A thing on bones whose type the effect catalogue doesn't have is logged when the looks load, the others " + "not (section 7b) [looks]") +{ + const std::vector sprites{{"light", "BITMAP_LIGHT"}}; + g_EffectTypeCatalogue.Build(Data::Effects::EffectKind::Sprite, sprites); + LookDefinition effect{"wings", {}, {}}; + OnBones lights; + lights.places.bones = {1}; + lights.together = true; + lights.things.push_back({.kind = BoneThingKind::Sprite, .type = "light"}); + lights.things.push_back({.kind = BoneThingKind::Sprite, .type = "noSuchSprite"}); + effect.onBones = {lights}; + g_LookStore.SetItemEffects({effect}); + { + const LogCapture log("data"); + Render::Items::Looks::LogUnknownBoneThingTypes(); + const std::string line = log.LineWith("noSuchSprite"); + // Named as Data Checks names it. + CHECK(line.find("wings: onBones[0].things[1].sprite") != std::string::npos); + CHECK(log.LineWith("\"light\"").empty()); + } g_LookStore.SetItemEffects({}); - look = {}; - look.blendMeshLight = 0.5f; - Render::Items::ItemEffects::Apply(&model, &object, look, MODEL_SWORD, alpha, level); - CHECK(look.blendMeshLight == 0.5f); - CHECK(Render::Items::ItemEffects::Spawns(MODEL_SWORD)); + g_EffectTypeCatalogue.Build(Data::Effects::EffectKind::Sprite, {}); } TEST_CASE("An item says whether its render style draws alone (design L47) [looks]") diff --git a/tests/data/test_look_files.cpp b/tests/data/test_look_files.cpp index 08c5921d2f..987c2e996d 100644 --- a/tests/data/test_look_files.cpp +++ b/tests/data/test_look_files.cpp @@ -209,6 +209,168 @@ TEST_CASE("An item effect sets item values before the drawing, by level, and the CHECK(again.looks[0] == eye); } +TEST_CASE("An item effect's things on bones are read, single and in groups, and written back as they were read " + "(design L55, L56) [looks][files]") +{ + const ReadResult result = ReadEffects(EffectFile(R"([ + {"name": "wings", "onBones": [ + {"together": {"between": [[30, 22], [29, 21]], "chance": {"oneIn": 1}}, + "things": [{"joint": "jointThunder", "subType": 14, + "scale": {"shape": "wave", "from": 20, "to": 26, "seconds": 1.5707963}}, + {"joint": "jointSpirit", "subType": 4, "reversed": true, "scale": 25}]}, + {"sprite": "flareBlue", "bones": [22, 21], "scale": 0.75, "color": [0.6, 0.3, 0.8]}, + {"together": {"bones": [11, 21], "chance": {"oneIn": 2, "per": "once"}}, + "things": [{"effect": "fenrirThunder", "subType": 1, "color": [0.6, 0.6, 0.9], + "chance": {"oneIn": 20, "draw": "plain"}}]}, + {"particle": "chromeEnergy2", "bones": [7], "scale": 0.1, "chance": {"oneIn": 1}}, + {"sprite": "cloud64", "at": "origin", "subType": 1, "rotation": {"shape": "scroll", "perSecond": 10}}]}])")); + INFO(Describe(result.issues)); + CHECK(result.issues.empty()); + REQUIRE(result.looks.size() == 1); + const std::vector& onBones = result.looks[0].onBones; + REQUIRE(onBones.size() == 5); + + const OnBones& lightning = onBones[0]; + CHECK(lightning.together); + CHECK(lightning.places.between == std::vector>{{30, 22}, {29, 21}}); + REQUIRE(lightning.chance); + CHECK(lightning.chance->oneIn == 1); + CHECK_FALSE(lightning.chance->once); + REQUIRE(lightning.things.size() == 2); + CHECK(lightning.things[0].kind == BoneThingKind::Joint); + CHECK(lightning.things[0].type == "jointThunder"); + CHECK(lightning.things[0].subType == 14); + CHECK(std::holds_alternative(lightning.things[0].scale)); + CHECK(lightning.things[1].reversed); + CHECK(lightning.things[1].scale == Number{25.f}); + + const OnBones& flares = onBones[1]; + CHECK_FALSE(flares.together); + CHECK(flares.places.bones == std::vector{22, 21}); + CHECK_FALSE(flares.chance); + REQUIRE(flares.things.size() == 1); + CHECK(flares.things[0].color[1] == Number{0.3f}); + + const OnBones& thunder = onBones[2]; + REQUIRE(thunder.chance); + CHECK(thunder.chance->once); + CHECK(thunder.chance->oneIn == 2); + REQUIRE(thunder.things[0].chance); + CHECK(thunder.things[0].chance->draw == ChanceDraw::Plain); + CHECK(thunder.things[0].chance->oneIn == 20); + CHECK(thunder.things[0].kind == BoneThingKind::Effect); + + // A single thing's chance is its entry's. + REQUIRE(onBones[3].chance); + CHECK_FALSE(onBones[3].things[0].chance); + CHECK(onBones[4].places.origin); + CHECK(std::holds_alternative(onBones[4].things[0].rotation)); + + const std::string text = WriteLookFileJson(LookKind::ItemEffect, result.looks); + CHECK(text.find(R"({"sprite": "flareBlue", "bones": [22, 21], "scale": 0.75, "color": [0.6, 0.3, 0.8]})") != + std::string::npos); + CHECK(text.find(R"("chance": {"oneIn": 20, "draw": "plain"})") != std::string::npos); + CHECK(text.find(R"("at": "origin")") != std::string::npos); + const ReadResult again = ReadEffects(text); + INFO(text); + CHECK(again.issues.empty()); + REQUIRE(again.looks.size() == 1); + CHECK(again.looks[0] == result.looks[0]); + CHECK(WriteLookFileJson(LookKind::ItemEffect, again.looks) == text); +} + +TEST_CASE("A layer value can be the item's times a number, a layer can darken, and an item effect can play the " + "object's animation (design L59, L29) [looks][files]") +{ + const ReadResult styles = Read(File(R"([{"name": "water", "layers": [ + {"kind": "texture", "glowStrength": {"itemTimes": 1.5}}, + {"kind": "reflection", "blend": "darken", "meshes": [1], "opacity": {"itemTimes": 0.25}}]}])")); + INFO(Describe(styles.issues)); + CHECK(styles.issues.empty()); + REQUIRE(styles.looks.size() == 1); + REQUIRE(styles.looks[0].layers.size() == 2); + CHECK(styles.looks[0].layers[0].glowStrength == Value{FromItem{1.5f}}); + CHECK(styles.looks[0].layers[1].blend == Blend::Darken); + CHECK(styles.looks[0].layers[1].opacity == Value{FromItem{0.25f}}); + const std::string text = WriteLookFileJson(LookKind::RenderStyle, styles.looks); + CHECK(text.find(R"("glowStrength": {"itemTimes": 1.5})") != std::string::npos); + CHECK(text.find(R"("blend": "darken")") != std::string::npos); + CHECK(Read(text).looks == styles.looks); + + const ReadResult effects = ReadEffects(EffectFile(R"([{"name": "water", "animationSpeed": 0.2857143}])")); + CHECK(effects.issues.empty()); + REQUIRE(effects.looks.size() == 1); + CHECK(effects.looks[0].animationSpeed == 0.2857143f); + CHECK(WriteLookFileJson(LookKind::ItemEffect, effects.looks).find(R"("animationSpeed": 0.2857143)") != + std::string::npos); + + CHECK(Find(Read(File(R"([{"name": "a", "layers": [{"kind": "texture", "opacity": {"itemTimes": "x"}}]}])")) + .issues, + ItemDataIssueSeverity::Fatal, "looks[0].layers[0].opacity.itemTimes") != nullptr); + CHECK(Find(ReadEffects(EffectFile(R"([{"name": "a", "animationSpeed": 0}])")).issues, ItemDataIssueSeverity::Fatal, + "looks[0].animationSpeed") != nullptr); + CHECK(Find(Read(File(R"([{"name": "a", "layers": [], "animationSpeed": 1}])")).issues, + ItemDataIssueSeverity::Fatal, "looks[0].animationSpeed") != nullptr); +} + +TEST_CASE("Things on bones that can't be created as written are fatal and name their field (design L55, L56) " + "[looks][files]") +{ + const struct + { + const char* onBones; + const char* field; + } cases[] = { + {R"({"onBones": {"sprite": "light"}})", "looks[0].onBones"}, + {R"({"onBones": [{"bones": [1]}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"sprite": "light", "particle": "shiny", "bones": [1]}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"sprite": "", "bones": [1]}]})", "looks[0].onBones[0].sprite"}, + {R"({"onBones": [{"sprite": "light"}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "at": "origin"}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"sprite": "light", "bones": []}]})", "looks[0].onBones[0].bones"}, + {R"({"onBones": [{"sprite": "light", "bones": [-1]}]})", "looks[0].onBones[0].bones[0]"}, + {R"({"onBones": [{"sprite": "light", "bones": [200]}]})", "looks[0].onBones[0].bones[0]"}, + {R"({"onBones": [{"joint": "jointThunder", "between": [[1, 200]]}]})", "looks[0].onBones[0].between[0][1]"}, + {R"({"onBones": [{"sprite": "light", "at": "hand"}]})", "looks[0].onBones[0].at"}, + {R"({"onBones": [{"sprite": "light", "between": [[1, 2]]}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"joint": "jointThunder", "bones": [1]}]})", "looks[0].onBones[0]"}, + {R"({"onBones": [{"joint": "jointThunder", "between": [[1]]}]})", "looks[0].onBones[0].between[0]"}, + {R"({"onBones": [{"particle": "shiny", "bones": [1], "rotation": 1}]})", "looks[0].onBones[0].rotation"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "reversed": true}]})", "looks[0].onBones[0].reversed"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "color": [1, 1]}]})", "looks[0].onBones[0].color"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "subType": 1.5}]})", "looks[0].onBones[0].subType"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "chance": {}}]})", "looks[0].onBones[0].chance.oneIn"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "chance": {"oneIn": 0}}]})", + "looks[0].onBones[0].chance.oneIn"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "chance": {"oneIn": 2, "draw": "dice"}}]})", + "looks[0].onBones[0].chance.draw"}, + {R"({"onBones": [{"sprite": "light", "bones": [1], "chance": {"oneIn": 2, "per": "bone"}}]})", + "looks[0].onBones[0].chance.per"}, + {R"({"onBones": [{"together": {"bones": [1]}, "things": []}]})", "looks[0].onBones[0].things"}, + {R"({"onBones": [{"together": {"bones": [1]}, "things": [{"sprite": "light", "bones": [2]}]}]})", + "looks[0].onBones[0].things[0].bones"}, + {R"({"onBones": [{"together": {"bones": [1]}, "things": [{"joint": "jointThunder"}]}]})", + "looks[0].onBones[0].things[0]"}, + {R"({"onBones": [{"together": {}, "things": [{"sprite": "light"}]}]})", "looks[0].onBones[0].together"}, + // A thing that doesn't fit the places is named after another that failed before it. + {R"({"onBones": [{"together": {"between": [[1, 2]]}, "things": [{"joint": "jointThunder", "subType": 5000}, {"sprite": "light"}]}]})", + "looks[0].onBones[0].things[1]"}, + {R"({"onBones": [{"together": {"bones": [1]}, "things": [{"sprite": "light", "chance": {"oneIn": 2, "per": "each"}}]}]})", + "looks[0].onBones[0].things[0].chance.per"}, + }; + for (const auto& item : cases) + { + const std::string look = std::string(R"([{"name": "a", )") + (item.onBones + 1) + "]"; + CAPTURE(look); + const ReadResult result = ReadEffects(EffectFile(look)); + INFO(Describe(result.issues)); + CHECK(Find(result.issues, ItemDataIssueSeverity::Fatal, item.field) != nullptr); + } + // Render styles have no things on bones. + CHECK(Find(Read(File(R"([{"name": "a", "layers": [], "onBones": []}])")).issues, ItemDataIssueSeverity::Fatal, + "looks[0].onBones") != nullptr); +} + TEST_CASE("A look file has only its kind's parts: render style parts in an item effect and the other way round are " "fatal (design L23) [looks][files]") { diff --git a/tests/data/test_look_recorder.cpp b/tests/data/test_look_recorder.cpp index 1e830685aa..222897af06 100644 --- a/tests/data/test_look_recorder.cpp +++ b/tests/data/test_look_recorder.cpp @@ -5,8 +5,10 @@ #include "LookRecorder.h" #include "ItemModelDatabaseScope.h" +#include "Data/DataHandler/EffectData/EffectTypeStorage.h" #include "Data/DataHandler/ItemData/ItemJsonStorage.h" #include "Data/DataHandler/LookData/LookDataHandler.h" +#include "Data/GameData/EffectData/EffectTypeCatalogue.h" #include "Data/GameData/EffectData/GlowColorList.h" #include "Data/GameData/ItemData/ItemDataIssue.h" #include "Data/GameData/ItemData/ItemModelDatabase.h" @@ -219,6 +221,123 @@ std::map RecordLook(const ShippedLook& look) return lines; } +// The baseline of the things on bones (tests/data/baseline/ItemEffectSpawns.txt, section 7b): one line per item and +// moment of each look whose things on bones moved into data, recorded from its old code before it moved +// (MU_SPAWN_RECORDER_WRITE= records those looks as they create their things now), so a moved +// look still creates what its code created. +const std::filesystem::path SpawnBaseline = MU_SPAWN_BASELINE; + +constexpr const char* SpawnBaselineHeader = + "# What the looks whose things on bones moved from code into Data/Effects/ItemEffects.json create in the update:\n" + "# one line per item, clock time and random seed, the look, the item and the moment, then the number of things\n" + "# and five digests of them and of what the look left on the object, rounded on five grids\n" + "# (tests/data/LookRecorder.h). Recorded from the old code before each look moved\n" + "# (MU_SPAWN_RECORDER_WRITE=), so a moved look still creates what its code did. The Devil's Key's and\n" + "# Invitation's lines were written again when their sparks moved onto the scaled bones (design L57).\n"; + +// The looks whose things on bones move into data in step 3 (section 7b): the item effects, and the two render styles +// whose things became item effects of the same name (design L29). +constexpr std::array SpawnLooks{ + "devilsKey", "devilsInvitation", "rena", "wingsOfDarkness", "wingOfStorm", "wingOfEternal", + "wingOfIllusion", "wingOfRuin", "wingOfDimension", "pumpkinOfLuck", "cursedCastleWater", +}; + +// The clock times and random seeds the looks create their things at: a seed of its own for each, so the chances of +// the looks pass at some and fail at others. +struct SpawnMoment +{ + double time = 0.0; + std::uint32_t seed = 0; +}; +constexpr std::array SpawnMoments{{ + {0.0, 1}, + {1000.25, 2}, + {2718.5, 3}, + {65536.75, 4}, + {0.0, 5}, + {1000.25, 6}, + {2718.5, 7}, + {65536.75, 8}, +}}; + +std::string SpawnKey(std::string_view look, int item, double time, std::uint32_t seed) +{ + char moment[64]; + std::snprintf(moment, sizeof(moment), " t=%.2f seed=%u", time, seed); + return "spawn " + std::string(look) + " " + LookRecorder::DescribeItem(item) + moment; +} + +// The effect catalogue of the test data while it lives, which things on bones name their types in; none afterwards. +struct ShippedEffectTypes +{ + ShippedEffectTypes() + { + if (!built) + { + return; + } + const Data::Effects::EffectTypesLoadResult types = + Data::Effects::LoadEffectTypeFiles(DataDirectory / "Effects"); + REQUIRE_FALSE(Data::Items::HasFatal(types.issues)); + for (const Data::Effects::EffectKind kind : Data::Effects::EffectKinds) + { + g_EffectTypeCatalogue.Build(kind, types.types[Data::Effects::ToIndex(kind)]); + } + } + ~ShippedEffectTypes() + { + if (!built) + { + return; + } + for (const Data::Effects::EffectKind kind : Data::Effects::EffectKinds) + { + g_EffectTypeCatalogue.Build(kind, {}); + } + } + ShippedEffectTypes(const ShippedEffectTypes&) = delete; + ShippedEffectTypes& operator=(const ShippedEffectTypes&) = delete; + + // Whether it loads the catalogue (none was loaded), which it then empties again. + bool built = g_EffectTypeCatalogue.GetTypeCount(Data::Effects::EffectKind::Sprite) == 0; +}; + +std::map ReadSpawnBaseline() +{ + std::map lines; + std::ifstream in(SpawnBaseline); + std::string line; + while (std::getline(in, line)) + { + if (!line.empty() && line.back() == '\r') + { + line.pop_back(); + } + const size_t tab = line.rfind('\t'); + if (line.empty() || line[0] == '#' || tab == std::string::npos) + { + continue; + } + lines[line.substr(0, tab)] = line.substr(tab + 1); + } + return lines; +} + +// The items that create the look's things: those whose item effect, or (a look moved from a render style's things) +// whose render style, it is. +std::vector SpawningItems(std::string_view look) +{ + std::vector items = LookRecorder::ItemsUsing(look, LookKind::ItemEffect); + for (const int item : LookRecorder::ItemsUsing(look, LookKind::RenderStyle)) + { + if (item >= 0 && std::ranges::find(items, item) == items.end()) + { + items.push_back(item); + } + } + return items; +} + // "effect:potion" names the item effect, any other name the render style. ShippedLook LookNamed(const std::string& name) { @@ -520,3 +639,92 @@ TEST_CASE("The Devil's Eye puts the pulse of its code on its object in the updat } WorldTime = previousWorldTime; } + +TEST_CASE("Item effects whose things on bones moved into data create what their old code creates, while both are " + "there (section 7b) [looks][recorder]") +{ + const ShippedLooksScope looks; + const ShippedEffectTypes types; + for (const std::string_view name : SpawnLooks) + { + const LookDefinition* data = g_LookStore.FindItemEffect(name); + // A render style's things (design L29) are still in its code while that is. + const bool inCode = + Render::Items::ItemEffects::ExistsInCode(name) || Render::Items::Styles::ExistsInCode(name); + if (data == nullptr || data->onBones.empty() || !inCode) + { + continue; + } + const std::vector items = SpawningItems(name); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + for (const int item : items) + { + for (const auto& [time, seed] : SpawnMoments) + { + CAPTURE(SpawnKey(name, item, time, seed)); + const Record code = LookRecorder::RecordSpawnWithCode(item, time, seed, name, LookKind::ItemEffect); + const Record moved = LookRecorder::RecordSpawn(item, time, seed); + CHECK_FALSE(code.meshDraws.empty()); + CHECK(LookRecorder::FirstDifference(code, moved) == ""); + } + } + } +} + +TEST_CASE("Item effects whose things on bones moved into data create what their old code created (the baseline) " + "[looks][recorder]") +{ + std::map baseline = ReadSpawnBaseline(); + const ShippedLooksScope looks; + const ShippedEffectTypes types; + if (const char* write = std::getenv("MU_SPAWN_RECORDER_WRITE")) + { + for (const std::string& name : SplitNames(write)) + { + std::erase_if(baseline, [&](const auto& line) { return line.first.rfind("spawn " + name + " (", 0) == 0; }); + const std::vector items = SpawningItems(name); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + for (const int item : items) + { + for (const auto& [time, seed] : SpawnMoments) + { + baseline[SpawnKey(name, item, time, seed)] = + LookRecorder::Digest(LookRecorder::RecordSpawn(item, time, seed)); + } + } + } + std::filesystem::create_directories(SpawnBaseline.parent_path()); + std::ofstream out(SpawnBaseline, std::ios::binary | std::ios::trunc); + out << SpawnBaselineHeader; + for (const auto& [key, digest] : baseline) + { + out << key << '\t' << digest << '\n'; + } + MESSAGE("Wrote " << SpawnBaseline.string()); + return; + } + + REQUIRE_FALSE(baseline.empty()); + for (const std::string_view name : SpawnLooks) + { + const std::vector items = SpawningItems(name); + REQUIRE_FALSE(items.empty()); + LookRecorder::ShippedItems shipped; + shipped.Open(items); + for (const int item : items) + { + for (const auto& [time, seed] : SpawnMoments) + { + const std::string key = SpawnKey(name, item, time, seed); + CAPTURE(key); + const auto line = baseline.find(key); + REQUIRE(line != baseline.end()); + CHECK(LookRecorder::SameDigest(LookRecorder::Digest(LookRecorder::RecordSpawn(item, time, seed)), + line->second)); + } + } + } +} diff --git a/tests/data/test_style_editor.cpp b/tests/data/test_style_editor.cpp index d349568d4e..8e6e9c4c38 100644 --- a/tests/data/test_style_editor.cpp +++ b/tests/data/test_style_editor.cpp @@ -420,6 +420,49 @@ TEST_CASE("Every field of a look draws, as drag fields, part checkboxes and drop } } +TEST_CASE("A layer's line names the values it sets, the item's value times a number too (design L59) " + "[editor][looks]") +{ + using namespace Data::Looks; + Layer layer; + const std::string itemOwn = MuEditor::Looks::Fields::DescribeLayer(layer); + CHECK(itemOwn.find(I18N::Editor::GlowStrength) == std::string::npos); + layer.glowStrength = FromItem{.times = 1.5f}; + layer.opacity = FromItem{.times = 0.25f}; + const std::string times = MuEditor::Looks::Fields::DescribeLayer(layer); + CHECK(times.find(I18N::Editor::GlowStrength) != std::string::npos); + CHECK(times.find(I18N::Editor::Opacity) != std::string::npos); +} + +TEST_CASE("An entry on bones' line says where its things go, Between bones before its first pair too (design L58) " + "[editor][looks]") +{ + using namespace Data::Looks; + OnBones entry; + entry.things.push_back({.kind = BoneThingKind::Joint, .type = "jointThunder"}); + CHECK(MuEditor::Looks::Fields::DescribeOnBones(entry).find(I18N::Editor::AtBones) != std::string::npos); + CHECK(MuEditor::Looks::Fields::DescribeOnBones(entry, true).find(I18N::Editor::BetweenBones) != std::string::npos); + entry.places.bones = {3}; + CHECK(MuEditor::Looks::Fields::DescribeOnBones(entry, true).find(I18N::Editor::AtBones) != std::string::npos); +} + +TEST_CASE("A thing on bones made another kind drops its type and what only its kind has, and keeps the rest " + "(design L58) [editor][looks]") +{ + using namespace Data::Looks; + BoneThing sprite{.kind = BoneThingKind::Sprite, .type = "light", .subType = 2, .scale = 0.5f, .rotation = 45.f}; + MuEditor::Looks::Fields::ChangeKind(sprite, BoneThingKind::Particle); + CHECK(sprite.kind == BoneThingKind::Particle); + CHECK(sprite.type.empty()); + CHECK(sprite.rotation == Number{0.f}); + CHECK(sprite.subType == 2); + CHECK(sprite.scale == Number{0.5f}); + + BoneThing lightning{.kind = BoneThingKind::Joint, .type = "jointSpirit", .reversed = true}; + MuEditor::Looks::Fields::ChangeKind(lightning, BoneThingKind::Effect); + CHECK_FALSE(lightning.reversed); +} + TEST_CASE("A field of a look says what it does while the mouse rests on it (design L42) [editor][looks]") { TestImGuiContext context; diff --git a/tests/gamelogic/ShippedLooksScope.h b/tests/gamelogic/ShippedLooksScope.h index a068240e71..dbd406d335 100644 --- a/tests/gamelogic/ShippedLooksScope.h +++ b/tests/gamelogic/ShippedLooksScope.h @@ -1,6 +1,8 @@ #pragma once +#include "Data/DataHandler/EffectData/EffectTypeStorage.h" #include "Data/DataHandler/LookData/LookDataHandler.h" +#include "Data/GameData/EffectData/EffectTypeCatalogue.h" #include "Data/GameData/ItemData/ItemDataIssue.h" #include "Data/GameData/LookData/LookStore.h" @@ -8,7 +10,8 @@ #include // The shipped looks (Data/Effects/RenderStyles.json and ItemEffects.json) in the game's look store for as long as it -// lives, and the looks from before again afterwards: the item looks that are data draw only with them. +// lives, and the looks from before again afterwards: the item looks that are data draw only with them. The effect +// catalogue, which things on bones name their types in, is loaded too while it lives, unless it was. class ShippedLooksScope { public: @@ -25,10 +28,27 @@ class ShippedLooksScope m_complete = m_complete && !Data::Items::HasFatal(shipped.issues); Data::Looks::g_LookStore.SetLooks(kind, std::move(shipped.looks)); } + m_builtCatalogue = g_EffectTypeCatalogue.GetTypeCount(Data::Effects::EffectKind::Sprite) == 0; + if (m_builtCatalogue) + { + const Data::Effects::EffectTypesLoadResult types = Data::Effects::LoadEffectTypeFiles(effects); + m_complete = m_complete && !Data::Items::HasFatal(types.issues); + for (const Data::Effects::EffectKind kind : Data::Effects::EffectKinds) + { + g_EffectTypeCatalogue.Build(kind, types.types[Data::Effects::ToIndex(kind)]); + } + } } ~ShippedLooksScope() { + if (m_builtCatalogue) + { + for (const Data::Effects::EffectKind kind : Data::Effects::EffectKinds) + { + g_EffectTypeCatalogue.Build(kind, {}); + } + } Data::Looks::g_LookStore.SetRenderStyles(std::move(m_renderStyles)); Data::Looks::g_LookStore.SetItemEffects(std::move(m_itemEffects)); } @@ -46,4 +66,5 @@ class ShippedLooksScope std::vector m_renderStyles; std::vector m_itemEffects; bool m_complete = true; + bool m_builtCatalogue = false; }; diff --git a/tests/gamelogic/test_character_effects_phase.cpp b/tests/gamelogic/test_character_effects_phase.cpp index c37666f31e..a82c4058bc 100644 --- a/tests/gamelogic/test_character_effects_phase.cpp +++ b/tests/gamelogic/test_character_effects_phase.cpp @@ -580,6 +580,9 @@ TEST_CASE("A character's mark spawns its sprite in the update, and its draw spaw TEST_CASE("A wing's item effect spawns its lights on the bones it is given, and its draw spawns none [effects]") { FenrirScope scope; + // The Wing of Eternal's lights are data (section 7b). + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); ItemModelDatabaseScope restoreModels; Data::Items::ItemModelDefinition eternal; eternal.group = 12; @@ -588,6 +591,8 @@ TEST_CASE("A wing's item effect spawns its lights on the bones it is given, and eternal.itemEffect = "wingOfEternal"; g_ItemModelDatabase.Build(std::vector{eternal}, Data::Effects::GlowColorList{}); BMD* b = &Models[MODEL_WING_OF_ETERNAL]; + // The scope's models aren't loaded: the wing has as many bones as its pose holds. + b->NumBones = MAX_BONES; b->BodyScale = 1.f; Vector(0.f, 0.f, 0.f, b->BodyOrigin); OBJECT wing; @@ -1332,15 +1337,21 @@ TEST_CASE("A character drawn before the update posed it is posed into draw bones TEST_CASE("Cursed Castle Water lights the bone it is given from the update, and its draw spawns none [effects]") { FenrirScope scope; + // Its look and its light are data (design L29, section 7b). + const ShippedLooksScope looks; + REQUIRE(looks.IsComplete()); ItemModelDatabaseScope restoreModels; Data::Items::ItemModelDefinition water; water.group = 14; water.number = 64; water.file = "Data/Item/Water.bmd"; water.renderStyle = "cursedCastleWater"; + water.itemEffect = "cursedCastleWater"; g_ItemModelDatabase.Build(std::vector{water}, Data::Effects::GlowColorList{}); const int model = Data::Items::ToModelSlot(Data::Items::MakeItemType(14, 64)); BMD* b = &Models[model]; + // The scope's models aren't loaded: the water has as many bones as its pose holds. + b->NumBones = MAX_BONES; b->BodyScale = 1.f; Vector(0.f, 0.f, 0.f, b->BodyOrigin); OBJECT item; @@ -1355,8 +1366,8 @@ TEST_CASE("Cursed Castle Water lights the bone it is given from the update, and for (int i = 0; i < MAX_SPRITES; ++i) CHECK_FALSE(Sprites[i].Live); - REQUIRE(Render::Items::Styles::Spawns(model)); - Render::Items::Styles::Spawn(b, &item, model, scope.bones.get()); + REQUIRE(Render::Items::ItemEffects::Spawns(model)); + Render::Items::ItemEffects::Spawn(b, &item, model, scope.bones.get()); int onPose = 0; for (int i = 0; i < MAX_SPRITES; ++i) {