//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DW.UserInterface_2D;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using DarkWynter.Engine.Menus;
using DWGame.Globals;
using DWGame;
using DWControllerDemo;
using System.Diagnostics;
using System.Xml;
using DWGame.Player;
namespace DW.Stream
{
// Renderer is a sub-system static structure that drives all graphics-card related functions
// This library is specifically split from the engine so it can be swapped out on alt. platforms (eg- DirectX, OpenGL, Mobile)
// If designed correctly, a single game then only needs to "re-skin" with a different rendering system to port platforms.
// In more advanced systems, this class holds draw-order dependency and shader-related information as well.
public static class Renderer
{
///
/// Global Window Settings
///
public struct Dimensions
{
public static bool RESIZABLE = false;
public static Rectangle CLIENTBOUNDS = new Rectangle(0,0,1152,720);
}
///
/// Global Font Struct
///
public struct SystemFonts
{
public static SpriteFont Arial;
public static SpriteFont ComicSans;
public static SpriteFont ComicSansSmall;
}
///
/// Variables
///
public static Window window;
public static SpriteBatch spriteBatch;
public static GraphicsDeviceManager graphics;
public static ContentManager content;
public static Viewport view;
public static Human human;
public static AI ai;
public static Collision colDect;
///
/// Setup
///
public static void Initialize()
{
Renderer.view = graphics.GraphicsDevice.Viewport;
Renderer.spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
}
///
/// Load the new Window
///
public static void Load()
{
Renderer.window = new Window();
window.Load("_xml/GameConfiguration.xml");
SystemFonts.Arial = content.Load("_fonts/Arial");
Renderer.human = new Human();
Renderer.ai = new AI();
Renderer.colDect = new Collision();
}
///
/// Drop all content
///
public static void Unload()
{
}
///
/// Mathematical formula for splitting the screen
///
/// Number of players
/// List of Rectangles holding the viewports for each pane
public static List GetRectangles(int frameCount)
{
List rects = new List();
switch (frameCount)
{
case 1:
rects.Add(new Rectangle(0, 0, view.Width, view.Height));
break;
case 2: // 2 players split vertically
rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height));
rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height));
break;
case 3: // 3 player split
rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height / 2));
rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height / 2));
rects.Add(new Rectangle(0, view.Height / 2, view.Width / 2, view.Height / 2));
break;
case 4: // 4 players
rects.Add(new Rectangle(0, 0, view.Width / 2, view.Height / 2));
rects.Add(new Rectangle(view.Width / 2, 0, view.Width / 2, view.Height / 2));
rects.Add(new Rectangle(0, view.Height / 2, view.Width / 2, view.Height / 2));
rects.Add(new Rectangle(view.Width / 2, view.Height / 2, view.Width / 2, view.Height / 2));
break;
default:
break;
}
return rects;
}
///
/// Resize the windows and down into the panes
///
/// Bounding on the game window
public static void Resize(Rectangle clientBounds)
{
window.Resize(clientBounds);
}
///
/// Game Loop
///
/// Passed down from engine, controls the HUD timer
/// Provides a snapshot of timing values
public static void Update(Stopwatch gameTimer, GameTime gametime)
{
window.Update(gameTimer, gametime);
AI.Update();
Human.Update(gameTimer, gametime);
Collision.Update(Human.getSpicy(), AI.getCars(), gametime);
}
///
/// Main Draw portion of the game, all objects should draw themselves,
/// Renderer just controls when it happens
///
/// Provides a snapshot of timing values
public static void Draw(GameTime gametime)
{
graphics.GraphicsDevice.Clear(Color.LightGray);
Renderer.spriteBatch.Begin();
window.Draw(view);
AI.Draw();
Human.Draw();
Renderer.spriteBatch.End();
}
}
}