예제 #1
0
        private static void InitializeRuntime(GameStartInfo gameStartInfo)
        {
            if (gameStartInfo.Adapter == null)
            {
                var adapters = GpuAdapter.EnumerateGraphicsAdapter();

                LogEmitter.Assert(adapters.Count > 0, LogLevel.Error, "[Initialize Graphics Device Failed without Support Adapter] from [GameSystems]");

                GpuDevice = new GpuDevice(adapters[0]);
            }
            else
            {
                GpuDevice = new GpuDevice(gameStartInfo.Adapter);
            }

            EngineWindow = new EngineWindow(
                gameStartInfo.WindowName,
                gameStartInfo.IconName,
                gameStartInfo.WindowSize);
            EngineWindow.Show();

            PresentRender = new PresentRender(GpuDevice, EngineWindow.Handle, EngineWindow.Size);

            //init resize event
            EngineWindow.OnSizeChangeEvent += (sender, eventArg) =>
            {
                PresentRender.ReSize(eventArg.After);
                VisualGuiSystem.Area = new Rectangle <int>(0, 0, eventArg.After.Width, eventArg.After.Height);
            };
        }
예제 #2
0
        /// <summary>
        /// Set Transform, Result is Transform = Matrix
        /// </summary>
        /// <param name="matrix">Transform</param>
        public virtual void SetTransform(Matrix4x4 matrix)
        {
            mMatrix = matrix;

            bool result = Matrix4x4.Invert(mMatrix, out mInvert);

            LogEmitter.Assert(result, LogLevel.Error, "[Invert Gui Transform Failed]");
        }
예제 #3
0
        public Package(string name, string path) : base(name)
        {
            AddComponent(mPackageComponent = new PackageComponent());

            Path = path;

            LogEmitter.Apply(LogLevel.Information, "[Initialize PackageProvider Finish] from [{0}]", Name);
        }
예제 #4
0
        internal void RemoveAssetDescription(AssetDescription description)
        {
            LogEmitter.Apply(LogLevel.Information, "[Remove Asset Description] [Type = {0}] [Name = {1}] from [{2}]", description.Type, description.Name, Name);

            description.Package = null;

            mPackageComponent.RemoveAssetDescription(description);
        }
예제 #5
0
        public EngineWindow(string name, string icon, Size size)
        {
            Name = name; Icon = icon;
            Size = size;

            mWndProc = WindowProc;

            LogEmitter.Apply(LogLevel.Information, "[Start Create Window] [Name = {0}] from [EngineWindow]", Name);

            //get instance
            var hInstance = APILibrary.Win32.Internal.GetModuleHandle(null);

            //create app info(WNDCLASS)s, default setting
            var appInfo = new APILibrary.Win32.AppInfo()
            {
                style         = (uint)APILibrary.Win32.AppInfoStyle.CS_DBLCLKS,
                lpfnWndProc   = mWndProc,
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = hInstance,
                hIcon         = APILibrary.Win32.Internal.LoadImage(IntPtr.Zero, Icon, 1, 0, 0, 0x00000010),
                hbrBackground = APILibrary.Win32.Internal.GetStockObject(0),
                hCursor       = APILibrary.Win32.Internal.LoadCursor(IntPtr.Zero, (uint)APILibrary.Win32.CursorType.IDC_ARROW),
                lpszMenuName  = null,
                lpszClassName = Name
            };

            //register app info(WNDCLASS)
            APILibrary.Win32.Internal.RegisterAppinfo(ref appInfo);

            APILibrary.Win32.Rect rect = new APILibrary.Win32.Rect()
            {
                top = 0, left = 0, right = Size.Width, bottom = Size.Height
            };

            //get real rect
            APILibrary.Win32.Internal.AdjustWindowRect(ref rect, (uint)APILibrary.Win32.WindowStyles.WS_OVERLAPPEDWINDOW, false);

            //create window
            mHandle = APILibrary.Win32.Internal.CreateWindowEx(0, Name, Name,
                                                               (uint)APILibrary.Win32.WindowStyles.WS_OVERLAPPEDWINDOW, 0x80000000, 0x80000000,
                                                               rect.right - rect.left, rect.bottom - rect.top, IntPtr.Zero, IntPtr.Zero,
                                                               hInstance, IntPtr.Zero);

            LogEmitter.Apply(LogLevel.Information, "[Finish Create Window] [Width = {0}] [Height = {1}] from [EngineWindow]",
                             Size.Width, Size.Height);

            //get window rect property
            APILibrary.Win32.Internal.GetWindowRect(mHandle, ref rect);

            //set event forwarder
            mEventForwardInputEmitter = new EventForwardInputEmitter(this);

            //set position and size
            Position  = new Point2(rect.left, rect.top);
            Size      = new Size(rect.right - rect.left, rect.bottom - rect.top);
            IsExisted = true;
        }
예제 #6
0
        public static void Initialize(GameStartInfo gameStartInfo)
        {
            GameName = gameStartInfo.Name;

            IsExist = true;

            InitializeRuntime(gameStartInfo);

            Gui.Initialize();

            LogEmitter.Apply(LogLevel.Information, "[Initialize Game Systems Finish] from [GameSystems]");
        }
예제 #7
0
        internal void AddAssetDescription(AssetDescription description)
        {
            LogEmitter.Apply(LogLevel.Information, "[Add Asset Description] [Type = {0}] [Name = {1}] from [{2}]", description.Type, description.Name, Name);

            //if the asset has been in the other package
            //we change the package asset in
            if (description.Package != null)
            {
                LogEmitter.Apply(LogLevel.Warning, "[Add Asset Description and Change the Package] [Type = {0}] [Name = {1}] from [{2}]",
                                 description.Type, description.Name, Name);

                description.Package.RemoveAssetDescription(description);
            }

            description.Package = this;

            mPackageComponent.AddAssetDescription(description);
        }
예제 #8
0
        public void CopyFromImage(Point2 destination, Image image, Rectangle region)
        {
            var copySize = new Size(
                region.Right - region.Left,
                region.Bottom - region.Top);

            LogEmitter.Assert(
                image.Size.Width >= region.Right &&
                image.Size.Height >= region.Bottom &&
                destination.X + copySize.Width <= Size.Width &&
                destination.Y + copySize.Height <= Size.Height,
                LogLevel.Warning, "[Copy From Image Failed with Invalid Size]");

            //do not need copy, because the size is zero
            if (region.Left == region.Right || region.Top == region.Bottom)
            {
                return;
            }

            mTexture.CopyFromGpuTexture2D(destination, image.mTexture, region);
        }
예제 #9
0
        public static void Initialize(GameStartInfo gameStartInfo)
        {
            GameName = gameStartInfo.GameName;

            BehaviorSystems = new List <BehaviorSystem>();

            IsExist = true;

            SystemScene = new GameScene("SystemScene");

            InitializeRuntime(gameStartInfo);

            //add system
            AddBehaviorSystem(AssetSystem     = new AssetSystem());
            AddBehaviorSystem(LogicGuiSystem  = new LogicGuiSystem());
            AddBehaviorSystem(VisualGuiSystem = new VisualGuiSystem(GpuDevice, new Rectangle <int>(0, 0, EngineWindow.Size.Width, EngineWindow.Size.Height)));

            EngineWindow.AddEventListener(LogicGuiSystem);

            LogEmitter.Apply(LogLevel.Information, "[Initialize GameSystems Finish] from [GameSystems]");
        }
예제 #10
0
        private static void InitializeRuntime(GameStartInfo gameStartInfo)
        {
            if (gameStartInfo.Adapter == null)
            {
                var adapters = GpuAdapter.EnumerateGraphicsAdapter();

                LogEmitter.Assert(adapters.Count > 0, LogLevel.Error, "[Initialize Graphics Device Failed without Support Adapter] from [GameSystems]");

                GpuDevice = new GpuDevice(adapters[0]);
            }
            else
            {
                GpuDevice = new GpuDevice(gameStartInfo.Adapter);
            }

            EngineWindow = new EngineWindow(
                gameStartInfo.Window.Name,
                gameStartInfo.Window.Icon,
                gameStartInfo.Window.Size);
            EngineWindow.Show();

            PresentRender = new PresentRender(GpuDevice, EngineWindow.Handle, EngineWindow.Size);
        }
예제 #11
0
        internal static void Initialize()
        {
            mRender = new GuiRender(GameSystems.GpuDevice);

            ///auto size, if true means when window size is changed, the canvas size is also changed.
            ///false means we do not change the size when window size changed.
            AutoSize = true;

            ///resize the canvas size
            ReSizeCanvas(GameSystems.EngineWindow.Size);

            GameSystems.EngineWindow.OnSizeChangeEvent += (sender, eventArg) =>
            {
                if (AutoSize == false)
                {
                    return;
                }

                ReSizeCanvas(eventArg.After);
            };

            ///add input mapped
            ///axis input mapped
            InputMapped.Mapped(InputProperty.MouseX, GuiProperty.InputMoveX);
            InputMapped.Mapped(InputProperty.MouseY, GuiProperty.InputMoveY);
            InputMapped.Mapped(InputProperty.MouseWheel, GuiProperty.InputWheel);
            ///button input mapped
            InputMapped.Mapped(InputProperty.LeftButton, GuiProperty.InputClick);
            ///mapped the keycode to input key
            foreach (var keycode in InputProperty.KeyCodeMapped)
            {
                InputMapped.Mapped(keycode.Value, GuiProperty.InputKey);
            }

            LogEmitter.Apply(LogLevel.Information, "[Initialize Gui System Finish] from [Gui]");
        }
예제 #12
0
        public static void RemoveBehaviorSystem(BehaviorSystem behaviorSystem)
        {
            BehaviorSystems.Remove(behaviorSystem);

            LogEmitter.Apply(LogLevel.Information, "[Remove Behavior System] [Name = {0}] from [GameSystems]", behaviorSystem.Name);
        }