@@ -11,7 +11,6 @@ import {
11
11
} from "@core/model-effects" ;
12
12
import { SpriteEntities } from "@core/sprite-entities" ;
13
13
import { UnitEntities } from "@core/unit-entities" ;
14
- import { terrainComposer } from "@image/generate-map/terrain-composer" ;
15
14
import BaseScene from "@render/base-scene" ;
16
15
import {
17
16
imageIsDoodad ,
@@ -24,72 +23,51 @@ import {
24
23
import { Janitor , JanitorLogLevel } from "three-janitor" ;
25
24
import { spriteIsHidden , spriteSortOrder } from "@utils/sprite-utils" ;
26
25
import { calculateFollowedUnitsTarget , unitIsCompleted , unitIsFlying } from "@utils/unit-utils" ;
27
- import { drawFunctions , imageTypes , unitTypes } from "common/enums" ;
28
- import { ImageStruct , UnitStruct , UnitTileScale } from "common/types" ;
26
+ import { drawFunctions , imageTypes } from "common/enums" ;
27
+ import { ImageStruct , UnitStruct } from "common/types" ;
29
28
import { Assets } from "@image/assets" ;
30
- import { floor32 , makePxToWorld } from "common/utils/conversions" ;
29
+ import { PxToWorld , floor32 } from "common/utils/conversions" ;
31
30
import { Color , MathUtils , Vector2 , Vector3 } from "three" ;
32
31
import { World } from "./world" ;
33
32
import { Unit } from "@core/unit" ;
34
33
import { IterableSet } from "@utils/data-structures/iterable-set" ;
35
34
import { borrow , Borrowed } from "@utils/object-utils" ;
36
35
import { getJanitorLogLevel } from "@ipc/global" ;
37
- import { getMapTiles } from "@utils/chk-utils" ;
38
36
import { ImageBase } from ".." ;
39
37
import { ImageHDMaterial } from "@core/image-hd-material" ;
40
38
import { calculateImagesFromTechTreeUnit } from "@utils/preload-map-units-and-sprites" ;
41
39
import { IterableMap } from "@utils/data-structures/iteratible-map" ;
42
40
import { SimpleQuadtree } from "@utils/data-structures/simple-quadtree" ;
43
41
import { settingsStore } from "@stores/settings-store" ;
42
+ import { HeightMaps } from "@image/generate-map" ;
43
+ import { Terrain } from "@core/terrain" ;
44
+ import { ViewControllerComposer } from "./view-controller-composer" ;
45
+ import gameStore from "@stores/game-store" ;
44
46
45
47
export type SceneComposer = Awaited < ReturnType < typeof createSceneComposer > > ;
46
48
export type SceneComposerApi = SceneComposer [ "api" ] ;
47
49
48
50
const white = new Color ( 0xffffff ) ;
49
51
52
+ type AdditionalSceneParams = {
53
+ terrain : Terrain ;
54
+ heightMaps : HeightMaps ,
55
+ pxToWorld : PxToWorld
56
+ }
57
+
50
58
// Primarily concerned about converting OpenBW state to three objects and animations
51
- export const createSceneComposer = async ( world : World , assets : Assets ) => {
59
+ export const createSceneComposer = async ( world : World , assets : Assets , viewController : ViewControllerComposer , { terrain , pxToWorld , heightMaps } : AdditionalSceneParams ) => {
52
60
const janitor = new Janitor ( "SceneComposer" ) ;
53
-
54
- const { terrain, ...terrainExtra } = janitor . mop (
55
- await terrainComposer (
56
- ...world . map . size ,
57
- world . map . tileset ,
58
- getMapTiles ( world . map ) ,
59
- UnitTileScale . HD
60
- ) ,
61
- "terrain"
62
- ) ;
63
-
64
- const pxToWorld = makePxToWorld ( ...world . map . size , terrain . getTerrainY ) ;
65
- const pxToWorldFlat = makePxToWorld ( ...world . map . size , ( ) => 0 ) ;
66
-
67
- const startLocations = world . map . units
68
- . filter ( ( u ) => u . unitId === unitTypes . startLocation )
69
- . map ( ( u ) => {
70
- const location = pxToWorld . xyz ( u . x , u . y , new Vector3 ( ) ) ;
71
-
72
- const player = world . players . find ( ( p ) => p . id === u . player ) ;
73
- if ( player ) {
74
- player . startLocation = ( new Vector3 ) . copy ( location ) ;
75
- }
76
-
77
- return location
78
- } )
79
-
80
- const playerWithStartLocation = world . players . find ( p => p . startLocation ) ;
81
- const initialStartLocation = playerWithStartLocation ? playerWithStartLocation . startLocation ?? new Vector3 ( ) : startLocations [ 0 ] ?? new Vector3 ( ) ;
82
-
83
61
const _world = borrow ( world ) ;
84
62
85
63
const units = new UnitEntities ( ) ;
86
64
units . externalOnClearUnits = ( ) => _world . events ! . emit ( "units-cleared" ) ;
87
65
units . externalOnCreateUnit = ( unit ) => _world . events ! . emit ( "unit-created" , unit ) ;
88
66
89
67
world . openBW . uploadHeightMap (
90
- terrainExtra . heightMaps . singleChannel ,
91
- ( terrainExtra . heightMaps . texture . image as ImageData ) . width ,
92
- ( terrainExtra . heightMaps . texture . image as ImageData ) . height
68
+ heightMaps . singleChannel ,
69
+ ( heightMaps . texture . image as ImageData ) . width ,
70
+ ( heightMaps . texture . image as ImageData ) . height
93
71
) ;
94
72
95
73
const scene = janitor . mop (
@@ -312,6 +290,12 @@ export const createSceneComposer = async ( world: World, assets: Assets ) => {
312
290
313
291
if ( unit ) {
314
292
images . setUnit ( image , unit ) ;
293
+ if ( unit . isAttacking ) {
294
+ const weapon = gameStore ( ) . assets ?. bwDat . weapons [ unit . extras . dat . groundWeapon ] || gameStore ( ) . assets ?. bwDat . weapons [ unit . extras . dat . airWeapon ] ;
295
+ if ( weapon ) {
296
+ viewController . doShakeCalculation ( weapon . explosionType , weapon . damageType , sprite . position ) ;
297
+ }
298
+ }
315
299
}
316
300
317
301
if ( isImage3d ( image ) ) {
@@ -331,7 +315,6 @@ export const createSceneComposer = async ( world: World, assets: Assets ) => {
331
315
applyRenderModeToSprite (
332
316
spriteStruct . typeId ,
333
317
sprite ,
334
- terrain . getTerrainY ( sprite . position . x , sprite . position . z )
335
318
) ;
336
319
337
320
sprite . updateMatrix ( ) ;
@@ -370,7 +353,6 @@ export const createSceneComposer = async ( world: World, assets: Assets ) => {
370
353
Janitor . logLevel = getJanitorLogLevel ( ) ;
371
354
} ) ;
372
355
373
- const pxToWorldInverse = makePxToWorld ( ...world . map . size , terrain . getTerrainY , true ) ;
374
356
375
357
return {
376
358
images,
@@ -381,15 +363,8 @@ export const createSceneComposer = async ( world: World, assets: Assets ) => {
381
363
selectedUnits,
382
364
followedUnits,
383
365
scene,
384
- terrain,
385
- terrainExtra,
386
- pxToWorld,
387
- pxToWorldInverse,
388
- pxToWorldFlat,
389
- startLocations,
390
366
onFrame (
391
367
delta : number ,
392
- elapsed : number ,
393
368
renderMode3D : boolean ,
394
369
) {
395
370
@@ -452,16 +427,13 @@ export const createSceneComposer = async ( world: World, assets: Assets ) => {
452
427
_world . fogOfWar ! . forceInstantUpdate = true ;
453
428
} ,
454
429
pxToWorld,
455
- pxToWorldFlat,
456
430
get units ( ) : IterableMap < number , Unit > {
457
431
return units . units
458
432
} ,
459
433
imageQuadtree,
460
434
unitQuadtree,
461
435
scene,
462
436
followedUnits,
463
- startLocations,
464
- initialStartLocation,
465
437
//TODO: extend followedunits instead
466
438
getFollowedUnitsCenterPosition : ( ) => calculateFollowedUnitsTarget ( followedUnits , pxToWorld ) ,
467
439
selectedUnits,
0 commit comments