XNA Game Development Forums
2012/02/09 14:57:18 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: 1 [2]
  Print  
Author Topic: XNA Scene Editor  (Read 11243 times)
Mike2
Newbie
*
Offline Offline

Posts: 16


View Profile
« Reply #15 on: 2007/08/23 13:12:34 »

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?  Cool  Cool Cool

Code:
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:

Code:
   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   Grin

greetz!!!
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Hazy Mind Scene Editor Hazy Mind Scene Editor mikeschuld 5 4495 Last post 2006/11/10 23:34:51
by AndroiD
Saving scene Hazy Mind Scene Editor Requests « 1 2 » Hunefalk 27 11362 Last post 2011/04/30 10:06:26
by gunther6616
Tutorial 2 :: Scene Graph and Object Framework Tutorial Discussion « 1 2 » mikeschuld 18 9718 Last post 2008/07/31 22:50:22
by mikeschuld
How can i edit in science editor General Discussion satsatsat 1 1576 Last post 2006/10/15 20:54:37
by mikeschuld
Crytek Engine 2 level editor General Discussion Cdy7e 7 2569 Last post 2007/03/15 18:55:36
by Chr0n1x
Scene graph Hazy Mind XNA Engine EclipsE 3 1754 Last post 2007/03/13 18:24:26
by mikeschuld
XNA Animation Component Library in XNA HMEngine Hazy Mind XNA Engine dotslash 0 2514 Last post 2007/05/31 13:53:12
by dotslash
Physics simulation: BulletX (Bullet for XNA) physics and Hazy Mind Xna Engine Hazy Mind XNA Engine Yubastard 6 5317 Last post 2007/08/12 08:57:21
by Yubastard
XNA Editor Load while already running Hazy Mind Scene Editor Mike2 11 4588 Last post 2007/08/22 16:10:32
by muchrejoicing
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.212 seconds with 20 queries.