hey guys,
I was looking for a while for a decent winform implement and this is my little "hack", anyone knows how to hack the GameTime-thingie?

namespace Engine.Device_handeling
{
public partial class IceGameForm : Form
{
private ContentManager content;
public ContentManager ContentManager { get { return content; } }
protected GraphicsDevice myGraphicsDevice;
private Control myRenderControl;
public Control IceControl { get { return myRenderControl; } set { myRenderControl = value; } }
private IcePostProcessor myPostProcessor;
public IcePostProcessor PostProcessor { get { return myPostProcessor; } }
protected GameTime gameTime;
private DateTime oldTime, currentTime, startTime;
private TimeSpan delta;
private bool done = false;
private const float timeStep = 1000f / 60f; // 60 fps update
private float nextUpdate = 0;
private bool isFixedTimeStep = false;
public IceGameForm()
{
}
protected virtual void Initialize()
{
FormClosing += new FormClosingEventHandler(ShutDown);
startTime = currentTime = DateTime.Now;
gameTime = new GameTime();
if (myRenderControl == null)
throw new Exception("No Control to render to");
CreateDevice();
content = new ContentManager(new GraphicsDeviceService(myGraphicsDevice));
myPostProcessor = new IcePostProcessor();
}
public void CreateDevice()
{
PresentationParameters pp = new PresentationParameters();
pp.IsFullScreen = false;
pp.BackBufferCount = 1;
pp.BackBufferHeight = myRenderControl.Height;
pp.BackBufferWidth = myRenderControl.Width;
myGraphicsDevice = new GraphicsDevice(
GraphicsAdapter.Adapters[0],
DeviceType.Hardware,
myRenderControl.Handle,
CreateOptions.HardwareVertexProcessing,
pp);
}
protected void ShutDown(object sender, FormClosingEventArgs e)
{
done = true;
e.Cancel = true;
}
protected virtual void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
}
myPostProcessor.LoadGraphicsContent(myGraphicsDevice, content);
IceShaderManager.LoadGraphicsContent(content);
}
protected virtual void UnLoadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
content.Unload();
}
}
public virtual void Update(GameTime gametime)
{
}
public virtual void Draw(GameTime gametime)
{
if (myPostProcessor.Effect != null)
{
myPostProcessor.PreRender(myGraphicsDevice);
}
//Do your rendering over here...
if (myPostProcessor.Effect != null)
{
myPostProcessor.PostRender(myGraphicsDevice);
}
myGraphicsDevice.Present();
}
private void ResizeWindow(object sender, EventArgs e)
{
if (myRenderControl.Width < 1 || myRenderControl.Height < 1)
return;
myGraphicsDevice.PresentationParameters.BackBufferWidth = myRenderControl.Width;
myGraphicsDevice.PresentationParameters.BackBufferHeight = myRenderControl.Height;
myGraphicsDevice.Reset();
}
private void UpdateGameTime()
{
}
public void Run()
{
Initialize();
LoadGraphicsContent(true);
while (!done)
{
oldTime = currentTime;
currentTime = DateTime.Now;
delta = currentTime - oldTime;
if (isFixedTimeStep)
{
if (gameTime.ElapsedRealTime.TotalMilliseconds > nextUpdate)
{
Update(gameTime);
}
}
else
{
Update(gameTime);
}
Draw(gameTime);
Application.DoEvents();
}
UnLoadGraphicsContent(true);
Close();
}
}
#region GraphicsDeviceService
public class GraphicsDeviceService : IGraphicsDeviceService, IServiceProvider
{
private GraphicsDevice graphicsDevice = null;
public GraphicsDeviceService(GraphicsDevice GraphicsDevice)
{
graphicsDevice = GraphicsDevice;
}
public GraphicsDevice GraphicsDevice
{
get { return graphicsDevice; }
}
public event EventHandler DeviceCreated;
public event EventHandler DeviceDisposing;
public event EventHandler DeviceReset;
public event EventHandler DeviceResetting;
public event EventHandler<PreparingDeviceSettingsEventArgs> PreparingDeviceSettings;
public Object GetService(System.Type ServiceType)
{
if (ServiceType == typeof(IGraphicsDeviceService))
return this;
else
throw new ArgumentException(); ;
}
}
#endregion
}
and in my editor I do:
public partial class Editor : IceGameForm
{
public Editor()
{
InitializeComponent();
}
protected override void Initialize()
{
IceControl = this.splitContainer1.Panel1;
base.Initialize();
SetupScene();
}
public override void Draw(Microsoft.Xna.Framework.GameTime gametime)
{
myGraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gametime);
}
private void SetupScene()
{
}
}
does anyone see a point to change/runit better... plss don't say delete and start over, did a while to get to this point

greetz!!!