Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScriptContext.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Threading.Tasks;
5 
6 using SiliconStudio.Core.Mathematics;
7 using SiliconStudio.Paradox.Effects;
8 using SiliconStudio.Paradox.Engine;
9 using SiliconStudio.Paradox.EntityModel;
10 using SiliconStudio.Paradox.Games;
11 using SiliconStudio.Paradox.Graphics;
12 using SiliconStudio.Core;
13 using SiliconStudio.Core.Serialization.Assets;
14 using SiliconStudio.Paradox.Input;
15 using SiliconStudio.Paradox.UI;
16 
17 namespace SiliconStudio.Paradox
18 {
20  {
21  IServiceRegistry Services { get; }
22 
23  object Parameter { get; set; }
24 
25  IGame Game { get; }
26 
27  AssetManager Asset { get; }
28 
30 
31  InputManager Input { get; }
32 
33  EntitySystem Entities { get; }
34 
36 
38 
40 
41  AudioSystem Audio { get; }
42 
43  UISystem UI { get; }
44  }
45 
46  public interface IScript : IScriptContext
47  {
48  Task Execute();
49  }
50 
51  public abstract class ScriptContext : ComponentBase, IScriptContext
52  {
53  private readonly IGraphicsDeviceService graphicsDeviceService;
54 
55  private readonly IVirtualResolution virtualResolutionProvider;
56 
57  protected ScriptContext(IServiceRegistry registry)
58  {
59  Services = registry;
60 
61  graphicsDeviceService = Services.GetSafeServiceAs<IGraphicsDeviceService>();
62 
63  Game = Services.GetSafeServiceAs<IGame>();
64  virtualResolutionProvider = Services.GetSafeServiceAs<IVirtualResolution>();
65  Asset = (AssetManager)Services.GetSafeServiceAs<IAssetManager>();
66  Input = Services.GetSafeServiceAs<InputManager>();
67  Entities = Services.GetSafeServiceAs<EntitySystem>();
68  Script = Services.GetSafeServiceAs<ScriptSystem>();
69  RenderSystem = Services.GetSafeServiceAs<RenderSystem>();
70  EffectSystem = Services.GetSafeServiceAs<EffectSystem>();
71  Audio = Services.GetSafeServiceAs<AudioSystem>();
72  UI = Services.GetSafeServiceAs<UISystem>();
73  }
74 
75  public AudioSystem Audio { get; private set; }
76 
77  public IServiceRegistry Services { get; private set; }
78 
79  public object Parameter { get; set; }
80 
81  public IGame Game { get; private set; }
82 
83  public AssetManager Asset { get; private set; }
84 
86  {
87  get
88  {
89  return graphicsDeviceService.GraphicsDevice;
90  }
91  }
92 
93  public UISystem UI { get; private set; }
94 
95  public InputManager Input { get; private set; }
96 
97  public EntitySystem Entities { get; private set; }
98 
99  public ScriptSystem Script { get; private set; }
100 
101  public RenderSystem RenderSystem { get; private set; }
102 
103  public EffectSystem EffectSystem { get; private set; }
104 
105  protected override void Destroy()
106  {
107  }
108 
109  public Vector3 VirtualResolution
110  {
111  get { return virtualResolutionProvider.VirtualResolution; }
112  set { virtualResolutionProvider.VirtualResolution = value; }
113  }
114 
115  public event EventHandler<EventArgs> VirtualResolutionChanged
116  {
117  add { virtualResolutionProvider.VirtualResolutionChanged += value;}
118  remove { virtualResolutionProvider.VirtualResolutionChanged -= value; }
119  }
120  }
121 }
Service providing method to access GraphicsDevice life-cycle.
Interface providing services to deal with the virtual resolution of the game. The virtual resolution ...
ScriptContext(IServiceRegistry registry)
Represents a three dimensional mathematical vector.
Definition: Vector3.cs:42
A service registry is a IServiceProvider that provides methods to register and unregister services...
The script system handles scripts scheduling in a game.
Definition: ScriptSystem.cs:16
Base class for a framework component.
Main Game class system.
Definition: Game.cs:32
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
Renders its RenderSystem.Pipeline, which will usually result in drawing all meshes, UI, etc...
Definition: RenderSystem.cs:18
Manage a collection of entities.
Definition: EntitySystem.cs:22
Interface of the UI system.
Definition: UISystem.cs:20
override void Destroy()
Disposes of object resources.
The Audio System. It creates an underlying instance of AudioEngine.
Definition: AudioSystem.cs:16