1 |
|
2 |
|
3 |
|
4 |
|
5 | import 'reflect-metadata';
|
6 | import { Container } from 'inversify';
|
7 | import getDecorators from 'inversify-inject-decorators';
|
8 | import { ComponentManager } from './ComponentManager';
|
9 | import { ResourcePool } from './components/framegraph/ResourcePool';
|
10 | import { FrameGraphSystem } from './components/framegraph/System';
|
11 | import { GeometryComponent } from './components/geometry/GeometryComponent';
|
12 | import { GeometrySystem } from './components/geometry/System';
|
13 |
|
14 | import { MaterialComponent } from './components/material/MaterialComponent';
|
15 | import { MaterialSystem } from './components/material/System';
|
16 | import { CullableComponent } from './components/mesh/CullableComponent';
|
17 | import { MeshComponent } from './components/mesh/MeshComponent';
|
18 | import { MeshSystem } from './components/mesh/System';
|
19 | import { CopyPass } from './components/renderer/passes/CopyPass';
|
20 | import { PixelPickingPass } from './components/renderer/passes/PixelPickingPass';
|
21 | import { RenderPass } from './components/renderer/passes/RenderPass';
|
22 | import { RendererSystem } from './components/renderer/System';
|
23 | import { HierarchyComponent } from './components/scenegraph/HierarchyComponent';
|
24 | import { NameComponent } from './components/scenegraph/NameComponent';
|
25 | import { SceneGraphSystem } from './components/scenegraph/System';
|
26 | import { TransformComponent } from './components/scenegraph/TransformComponent';
|
27 | import { IDENTIFIER } from './identifier';
|
28 | import { ConfigService } from './services/config/ConfigService';
|
29 | import { InteractorService } from './services/interactor/IteractorService';
|
30 | import ShaderModuleService from './services/shader-module/ShaderModuleService';
|
31 |
|
32 | export var container = new Container();
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var DECORATORS = getDecorators(container, false);
|
39 |
|
40 |
|
41 |
|
42 | export var lazyInject = function lazyInject(serviceIdentifier) {
|
43 | var original = DECORATORS.lazyInject(serviceIdentifier);
|
44 |
|
45 |
|
46 | return function (proto, key, descriptor) {
|
47 |
|
48 | original.call(this, proto, key);
|
49 |
|
50 | if (descriptor) {
|
51 | descriptor.initializer = function () {
|
52 | return proto[key];
|
53 | };
|
54 | }
|
55 | };
|
56 | };
|
57 | export var lazyMultiInject = function lazyMultiInject(serviceIdentifier) {
|
58 | var original = DECORATORS.lazyMultiInject(serviceIdentifier);
|
59 |
|
60 |
|
61 | return function (proto, key, descriptor) {
|
62 |
|
63 | original.call(this, proto, key);
|
64 |
|
65 | if (descriptor) {
|
66 |
|
67 | descriptor.initializer = function () {
|
68 | return proto[key];
|
69 | };
|
70 | }
|
71 | };
|
72 | };
|
73 |
|
74 |
|
75 | container.bind(IDENTIFIER.ShaderModuleService).to(ShaderModuleService).inSingletonScope();
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | container.bind(IDENTIFIER.NameComponentManager).toConstantValue(new ComponentManager(NameComponent));
|
81 | container.bind(IDENTIFIER.HierarchyComponentManager).toConstantValue(new ComponentManager(HierarchyComponent));
|
82 | container.bind(IDENTIFIER.TransformComponentManager).toConstantValue(new ComponentManager(TransformComponent));
|
83 | container.bind(IDENTIFIER.MeshComponentManager).toConstantValue(new ComponentManager(MeshComponent));
|
84 | container.bind(IDENTIFIER.CullableComponentManager).toConstantValue(new ComponentManager(CullableComponent));
|
85 | container.bind(IDENTIFIER.GeometryComponentManager).toConstantValue(new ComponentManager(GeometryComponent));
|
86 | container.bind(IDENTIFIER.MaterialComponentManager).toConstantValue(new ComponentManager(MaterialComponent));
|
87 |
|
88 | export function createWorldContainer() {
|
89 | var worldContainer = new Container();
|
90 | worldContainer.parent = container;
|
91 | |
92 |
|
93 |
|
94 |
|
95 | worldContainer.bind(IDENTIFIER.Systems).to(SceneGraphSystem).inSingletonScope().whenTargetNamed(IDENTIFIER.SceneGraphSystem);
|
96 | worldContainer.bind(IDENTIFIER.Systems).to(FrameGraphSystem).inSingletonScope().whenTargetNamed(IDENTIFIER.FrameGraphSystem);
|
97 | worldContainer.bind(IDENTIFIER.Systems).to(MeshSystem).inSingletonScope().whenTargetNamed(IDENTIFIER.MeshSystem);
|
98 | worldContainer.bind(IDENTIFIER.Systems).to(GeometrySystem).inSingletonScope().whenTargetNamed(IDENTIFIER.GeometrySystem);
|
99 | worldContainer.bind(IDENTIFIER.Systems).to(MaterialSystem).inSingletonScope().whenTargetNamed(IDENTIFIER.MaterialSystem);
|
100 | worldContainer.bind(IDENTIFIER.Systems).to(RendererSystem).inSingletonScope().whenTargetNamed(IDENTIFIER.RendererSystem);
|
101 |
|
102 | worldContainer.bind(IDENTIFIER.ResourcePool).to(ResourcePool).inSingletonScope();
|
103 | worldContainer.bind(IDENTIFIER.ConfigService).to(ConfigService).inSingletonScope();
|
104 | worldContainer.bind(IDENTIFIER.InteractorService).to(InteractorService).inSingletonScope();
|
105 | |
106 |
|
107 |
|
108 |
|
109 | worldContainer.bind(IDENTIFIER.RenderPass).to(RenderPass).inSingletonScope().whenTargetNamed(RenderPass.IDENTIFIER);
|
110 | worldContainer.bind(IDENTIFIER.RenderPass).to(CopyPass).inSingletonScope().whenTargetNamed(CopyPass.IDENTIFIER);
|
111 | worldContainer.bind(IDENTIFIER.RenderPass).to(PixelPickingPass).inSingletonScope().whenTargetNamed(PixelPickingPass.IDENTIFIER);
|
112 | worldContainer.bind(IDENTIFIER.RenderPassFactory).toFactory(function (context) {
|
113 | return function (name) {
|
114 | return context.container.getNamed(IDENTIFIER.RenderPass, name);
|
115 | };
|
116 | });
|
117 | return worldContainer;
|
118 | }
|
119 |
|
\ | No newline at end of file |