#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2010 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Ninject;
using Ninject.Activation;
using Ninject.Modules;
using SynapseGaming.LightingSystem.Core;
using SynapseGaming.LightingSystem.Editor;
using SynapseGaming.LightingSystem.Lights;
using SynapseGaming.LightingSystem.Rendering;
using SynapseGaming.LightingSystem.Rendering.Forward;
using SynapseGaming.LightingSystem.Shadows;
using SynapseGaming.LightingSystem.Audio;
using SynapseGaming.LightingSystem.Collision;
namespace Nuclex.Ninject.Sunburn {
/// Sets up service bindings for the IslandWar game
public class SunburnModule : NinjectModule {
/// Called when the module is loaded into the kernel
public override void Load() {
Kernel.Bind().ToSelf().InSingletonScope();
Kernel.Bind().ToSelf().InSingletonScope();
Kernel.Bind().ToSelf().InSingletonScope();
Kernel.Bind().ToSelf().InSingletonScope();
Kernel.Bind().ToMethod(getSceneInterface).InSingletonScope();
Kernel.Bind().ToMethod(getSceneInterface).InSingletonScope();
Kernel.Bind().To().InSingletonScope();
Kernel.Bind().ToMethod(getAudioManager).InSingletonScope();
#if !WINDOWS_PHONE
Kernel.Bind().ToMethod(getAvatarManager).InSingletonScope();
Kernel.Bind().ToMethod(getShadowMapManager).InSingletonScope();
#endif
Kernel.Bind().ToMethod(getCollisionManager).InSingletonScope();
Kernel.Bind().ToMethod(getLightManager).InSingletonScope();
Kernel.Bind().ToMethod(getObjectManager).InSingletonScope();
Kernel.Bind().ToMethod(getPostProcessManager).InSingletonScope();
Kernel.Bind().ToMethod(getRenderManager).InSingletonScope();
Kernel.Bind().ToMethod(getResourceManager).InSingletonScope();
Kernel.Bind().ToMethod(getFrameBuffers).InSingletonScope();
setupSplashScreenComponent();
#if DEBUG
Kernel.Bind().ToSelf().InSingletonScope();
setupLightingSystemEditor();
#endif
}
/// Gets the scene interface of the Sunburn system
///
/// Context containing the kernel and informations about the request
///
/// The scene interface
private static SceneInterface getSceneInterface(IContext context) {
var sceneInterface = new SceneInterface(
context.Kernel.Get()
);
// This will create a default instance if none has been registered by the user
var sceneOptions = context.Kernel.Get();
sceneInterface.CreateDefaultManagers(
sceneOptions.UseDeferredRendering
);
return sceneInterface;
}
#if !WINDOWS_PHONE
/// Gets the scene interface's avatar manager
///
/// Context containing the kernel and informations about the request
///
/// The avatar manager
private static IAvatarManager getAvatarManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.AvatarManager;
}
/// Gets the scene interface's shadow map manager
///
/// Context containing the kernel and informations about the request
///
/// The shadow map manager
private static IShadowMapManager getShadowMapManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.ShadowMapManager;
}
#endif
/// Gets the scene interface's audio manager
///
/// Context containing the kernel and informations about the request
///
/// The audio manager
private static IAudioManager getAudioManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.AudioManager;
}
/// Gets the scene interface's collision manager
///
/// Context containing the kernel and informations about the request
///
/// The collision manager
private static ICollisionManager getCollisionManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.CollisionManager;
}
/// Gets the scene interface's light manager
///
/// Context containing the kernel and informations about the request
///
/// The light manager
private static ILightManager getLightManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.LightManager;
}
/// Gets the scene interface's object manager
///
/// Context containing the kernel and informations about the request
///
/// The object manager
private static IObjectManager getObjectManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.ObjectManager;
}
/// Gets the scene interface's post processing effect manager
///
/// Context containing the kernel and informations about the request
///
/// The post processing effect manager
private static IPostProcessManager getPostProcessManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.PostProcessManager;
}
/// Gets the scene interface's rendering manager
///
/// Context containing the kernel and informations about the request
///
/// The rendering manager
private static IRenderManager getRenderManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.RenderManager;
}
/// Gets the scene interface's resource manager
///
/// Context containing the kernel and informations about the request
///
/// The resource manager
private static IResourceManager getResourceManager(IContext context) {
var sceneInterface = context.Kernel.Get();
return sceneInterface.ResourceManager;
}
/// Gets the frame buffers used for rendering
///
/// Context containing the kernel and informations about the request
///
/// The new frame buffers
private static FrameBuffers getFrameBuffers(IContext context) {
var graphicsDeviceService = context.Kernel.Get();
// This will create a default instance if none has been registered by the user
var sceneOptions = context.Kernel.Get();
return new FrameBuffers(
graphicsDeviceService, sceneOptions.Precision, sceneOptions.Lighting
);
}
/// Adds the splash screen component to the game
private void setupSplashScreenComponent() {
var gameComponents = Kernel.Get();
var splashScreen = Kernel.Get();
Kernel.Bind().ToConstant(splashScreen);
gameComponents.Add(splashScreen);
}
/// Adds the lighting system editor to the scene
///
/// With the lighting system editor added, the scene's lighting settings can be
/// configured visually using the Sunburn
///
private void setupLightingSystemEditor() {
var lightingSystemEditor = Kernel.Get();
var sceneInterface = Kernel.Get();
sceneInterface.AddManager(lightingSystemEditor);
var gameComponents = Kernel.Get();
var lightingSystemEditorComponent = Kernel.Get();
gameComponents.Add(lightingSystemEditorComponent);
}
}
} // namespace Nuclex.Ninject.Sunburn