Beispiel #1
0
        private void m_gameDocumentRegistry_DocumentAdded(object sender, ItemInsertedEventArgs <IGameDocument> e)
        {
            IGameDocument document = e.Item;
            IGame         game     = document.Cast <IGame>();

            if (document == m_gameDocumentRegistry.MasterDocument)
            {
                NativeObjectAdapter gameLevel = document.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();

                //create vertex buffer for grid.
                IGrid        grid       = document.As <IGame>().Grid;
                GridRenderer gridRender = grid.Cast <GridRenderer>();
                gridRender.CreateVertices();

                m_designView.Context = document.Cast <IGameContext>();
            }
            DomNode masterNode    = m_gameDocumentRegistry.MasterDocument.As <DomNode>();
            DomNode rooFolderNode = game.RootGameObjectFolder.Cast <DomNode>();

            NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>();

            gworld.Insert(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"), -1);
        }
        private void m_gameDocumentRegistry_DocumentRemoved(object sender, ItemRemovedEventArgs <IGameDocument> e)
        {
            IGameDocument document = e.Item;

            document.DirtyChanged -= m_document_DirtyChanged;
            document.UriChanged   -= m_document_UriChanged;

            IGame game = document.Cast <IGame>();

            if (document == m_designView.Context.Cast <IGameDocument>())
            {// master document.
                IGrid        grid       = document.As <IGame>().Grid;
                GridRenderer gridRender = grid.Cast <GridRenderer>();
                gridRender.DeleteVertexBuffer();
                m_designView.Context = null;
                GameEngine.DestroyObject(game.Cast <NativeObjectAdapter>());
                GameEngine.Clear();
            }
            else
            {// sub document.
                DomNode masterNode            = m_gameDocumentRegistry.MasterDocument.As <DomNode>();
                DomNode rooFolderNode         = game.RootGameObjectFolder.Cast <DomNode>();
                NativeGameWorldAdapter gworld = masterNode.Cast <NativeGameWorldAdapter>();
                gworld.Remove(masterNode, rooFolderNode, masterNode.Type.GetChildInfo("gameObjectFolder"));
            }
        }
Beispiel #3
0
        private void MoveBtnClick(object sender, EventArgs e)
        {
            TerrainGob gob     = (TerrainGob)m_cmboxTerrain.SelectedItem;
            ListBox    listbox = GetActiveList();

            if (listbox == null || listbox.SelectedItem == null || gob == null)
            {
                return;
            }


            int lastIndex      = listbox.Items.Count - 1;
            int selectedIndex  = listbox.SelectedIndex;
            int insertionIndex = -1;

            if (sender == m_moveUpBtn && selectedIndex > 0)
            {
                insertionIndex = selectedIndex - 1;
            }
            else if (sender == m_moveDownBtn && selectedIndex < lastIndex)
            {
                insertionIndex = selectedIndex + 1;
            }

            if (insertionIndex >= 0)
            {
                // todo: move class NativeGameWorldAdapter to LevelEditorCore
                //       and create an interface for accessing class GameEngine
                RenderingInterop.NativeGameWorldAdapter
                    gw = GameContext.As <RenderingInterop.NativeGameWorldAdapter>();
                try
                {
                    gw.ManageNativeObjectLifeTime = false;
                    object item = listbox.Items[selectedIndex];
                    GameContext.As <ITransactionContext>().DoTransaction(() =>
                    {
                        // the item must be terrain map.
                        DomNode node          = item.As <DomNode>();
                        DomNode parentNode    = node.Parent;
                        IList <DomNode> items = parentNode.GetChildList(node.ChildInfo);
                        int itemIndex         = items.IndexOf(node);
                        System.Diagnostics.Debug.Assert(itemIndex == selectedIndex);
                        items.RemoveAt(itemIndex);
                        items.Insert(insertionIndex, node);
                    }, "Move Map");
                    listbox.SelectedItem = item;
                }
                finally
                {
                    gw.ManageNativeObjectLifeTime = true;
                }
            }
        }
Beispiel #4
0
        private void Init()
        {
            if (m_game != null)
            {
                return;
            }

            NativeObjectAdapter curLevel = GameEngine.GetGameLevel();

            try
            {
                // create new document by creating a Dom node of the root type defined by the schema
                DomNode   rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
                INameable nameable = rootNode.As <INameable>();
                nameable.Name = "Game";
                NativeObjectAdapter gameLevel = rootNode.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();
                NativeGameWorldAdapter gworld = rootNode.Cast <NativeGameWorldAdapter>();
                m_game = rootNode.Cast <IGame>();
                IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
                m_renderSurface.Game            = m_game;
                m_renderSurface.GameEngineProxy = m_gameEngine;
            }
            finally
            {
                GameEngine.SetGameLevel(curLevel);
            }


            m_mainWindow.Closed += delegate
            {
                GameEngine.DestroyObject(m_game.Cast <NativeObjectAdapter>());
                m_renderSurface.Dispose();
            };
        }
Beispiel #5
0
        private void Init()
        {
            NativeObjectAdapter curLevel = GameEngine.GetGameLevel();

            try
            {
                // create new document by creating a Dom node of the root type defined by the schema
                DomNode   rootNode = new DomNode(m_schemaLoader.GameType, m_schemaLoader.GameRootElement);
                INameable nameable = rootNode.Cast <INameable>();
                nameable.Name = "ThumbnailGenerator";

                NativeObjectAdapter gameLevel = rootNode.Cast <NativeObjectAdapter>();
                GameEngine.CreateObject(gameLevel);
                GameEngine.SetGameLevel(gameLevel);
                gameLevel.UpdateNativeOjbect();
                NativeGameWorldAdapter gworld = rootNode.Cast <NativeGameWorldAdapter>();

                m_game = rootNode.Cast <IGame>();
                IGameObjectFolder rootFolder = m_game.RootGameObjectFolder;
                m_renderSurface          = new TextureRenderSurface(96, 96);
                m_renderState            = new RenderState();
                m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows;
            }
            finally
            {
                GameEngine.SetGameLevel(curLevel);
            }


            m_mainWindow.Closed += delegate
            {
                GameEngine.DestroyObject(m_game.Cast <NativeObjectAdapter>());
                m_renderSurface.Dispose();
                m_renderState.Dispose();
            };
        }