Commits

Anonymous committed f14df91

AppDecouple Merge fix #1

Comments (0)

Files changed (4)

DarkMotion/EngineLayer.cs

             cfg.EngineFlags = EngineFlags.Debug | EngineFlags.Dev | 
                 EngineFlags.DisableBackgroundLoading;
 
-            Engine.Init("DarkMotion", cfg, control);
+            App.InitD3D("DarkMotion", cfg, control);
+            Engine.Init("DarkMotion", cfg);
+            App.ShowWindow();
 
-            Engine.Update += EngineUpdate;
-
+            App.Update += EngineUpdate;
+            
             Engine.ActiveScene = Engine.CreateScene("Main");
 
             GameObject cam = Engine.ActiveScene.CreateObject("Camera", GameObjectType.Camera);
             var w = control.ClientSize.Width;
             var h = control.ClientSize.Height;
             Resize(w, h);
-            Engine.Run();
+            App.Run();
         }
 
-        static void EngineUpdate(float dt)
+        static void EngineUpdate()
         {
             if (Update != null)
-                Update(dt);
+                Update();
         }
 
         public static void ResetScene(AnimController controller)
             cam.GetComponent<Transfrom>().Position = new Vec3(0, 1, -5);
             cam.AddBehavior<OrbitCam>();
             if (controller != null) {
-                Engine.AddVdir(controller.RootPath, true);
+                Engine.AddVirtualPath(controller.RootPath, true);
                 var h3da = controller.ReelPath;
                 var h3dm = h3da.Substring(0, h3da.Length - 1) + "m";
                 if (!File.Exists(h3dm)) {
         public static void Resize(int w, int h)
         {
             if (Engine.Initialized)
-                Engine.SetViewSize(w, h);
+                App.ResizeView((uint)w, (uint)h);
         }
 
         public static void SetFloat(string name, float value)
         {
             if (Engine.Initialized && CharacterAnimator != null) {
                 CharacterAnimator.SetFloat(name, value);
-                Engine.OnUpdate();
+                Engine.Update();
             }
         }
 
         {
             if (Engine.Initialized && CharacterAnimator != null) {
                 CharacterAnimator.SetInt(name, value);
-                Engine.OnUpdate();
+                Engine.Update();
             }
         }
 
         {
             if (Engine.Initialized && CharacterAnimator != null) {
                 CharacterAnimator.SetBool(name, value);
-                Engine.OnUpdate();
+                Engine.Update();
             }
         }
 
         #endregion
 
         #region Fields
-        public static event UpdateHandler Update;
+        public static event App.UpdateHandler Update;
         static Label _stateLabel = null;
         #endregion
     }

DarkMotion/Forms/MainForm.cs

 
 namespace DarkMotion
 {
-	public partial class MainForm : Form
-	{
+    public partial class MainForm : Form
+    {
         public MainForm()
         {
             InitializeComponent();
                     cmbClips.DataBindings[0].WriteValue();
             };
 
-            btnSync.Click += (s, e) => {
-                try {
-                    var jsonFmt = JsonFormat.Create(_animController);
-                    jsonFmt.Export(_animController.RootPath + "/tmp-animator.json");
-
-
-                    var obj = Engine.ActiveScene.FindObject("Model");
-                    var mdl = obj.GetComponent<Model>().FilePath;
-                    Engine.ActiveScene.DestroyObject(obj);
-
-                    obj = Engine.ActiveScene.CreateModel("Model", mdl);
-                    obj.AddComponent<Animator>().FilePath = "tmp-animator.json";
-                } catch (Exception ex) {
-                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
-                }
-            };
-
+            engView.Resize += (s, e) => EngineLayer.Resize(engView.ClientSize.Width, engView.ClientSize.Height);
+            btnSync.Click += (s, e) => EngineLayer.Sync(_animController);
         }
 
         #region Methods
         protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
         {
             base.OnClosing(e);
-            hmrView.ReleaseEngine();
+            //hmrView.ReleaseEngine();
+            EngineLayer.ReleaseEngine();
         }
 
         private void AnimLayerViewInit()
 
         private void grdParams_CellEndEdit(object sender, DataGridViewCellEventArgs e)
         {
-            if (e.ColumnIndex == 0)
-                grdParams[e.ColumnIndex, e.RowIndex].Value =
-					(grdParams[e.ColumnIndex, e.RowIndex].Value as string).Trim();
-            else if (e.ColumnIndex == 1) // type column
-			{
-                switch ((ParamType)grdParams[e.ColumnIndex, e.RowIndex].Value) {
-                    case ParamType.Bool:
-                        var chk = new DataGridViewCheckBoxCell();
-                        grdParams[2, e.RowIndex] = chk;
-                        break;
-                    default:
-                        var txt = new DataGridViewTextBoxCell();
-                        txt.Value = 0;
-                        grdParams[2, e.RowIndex] = txt;
-                        break;
-                }
-            }
+            var name = grdParams[0, e.RowIndex].Value as string;
+            var type = ((ParamType)grdParams[1, e.RowIndex].Value);
+
+            switch (e.ColumnIndex)
+	        {
+                case 0: // name column
+                    name = name.Trim();
+                    break;
+                case 1: // type column
+                    switch (type) {
+                        case ParamType.Bool:
+                            var chk = new DataGridViewCheckBoxCell();
+                            grdParams[2, e.RowIndex] = chk;
+                            break;
+                        default:
+                            var txt = new DataGridViewTextBoxCell();
+                            txt.Value = 0;
+                            grdParams[2, e.RowIndex] = txt;
+                            break;
+                    }
+                    break;
+	        }
         }
 
         private void grdParams_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
         {
+            var name = grdParams[0, e.RowIndex].Value as string;
+            var type = ((ParamType)grdParams[1, e.RowIndex].Value);
+            var value = grdParams[2, e.RowIndex].Value;
+
             if (e.ColumnIndex == 0) // name column
 			{
                 var edVal = e.FormattedValue as string;
                     }
                 }
             } else if (e.ColumnIndex == 2) {
-                switch ((ParamType)grdParams[1, e.RowIndex].Value) {
+                switch (type) {
                     case ParamType.Int:
                         int i;
-                        if (!int.TryParse(e.FormattedValue.ToString(), out i))
+                        if (!int.TryParse(e.FormattedValue.ToString(), out i)) {
                             grdParams.CancelEdit();
+                        } else {
+                            EngineLayer.SetInt(name, i);
+                        }
                         break;
 
                     case ParamType.Float:
                         float f;
-                        if (!float.TryParse(e.FormattedValue.ToString(), out f))
+                        if (!float.TryParse(e.FormattedValue.ToString(), out f)) {
                             grdParams.CancelEdit();
+                        } else {
+                            EngineLayer.SetFloat(name, f);
+                        }
+                        break;
+
+                    case ParamType.Bool:
+                        bool b;
+                        try {
+                            b = (bool)e.FormattedValue;
+                            EngineLayer.SetBool(name, b);
+                        } catch {
+                            grdParams.CancelEdit();
+                        }
                         break;
                 }
             }
 
         private void hmrview_reset()
         {
-            hmrView.ResetEngine();
-            Engine.AddVirtualPath(_animController.RootPath, true);
-            var h3da = _animController.ReelPath;
-            var h3dm = h3da.Substring(0, h3da.Length - 1) + "m";
-            if (!File.Exists(h3dm)) {
-                // handles the case where h3dm doesnt exist
-            }
-            var mdl = Engine.ActiveScene.CreateModel("Model", h3dm);
-            Animation mdlAnim = mdl.AddComponent<Animation>();
-            mdlAnim.FilePath = h3da;
-            AnimController.Clips = mdlAnim.Clips;
-            AnimController.Bones = mdlAnim.Bones;
-            var orbitCam = Engine.ActiveScene.FindObject("cam1").GetBehavior<BehaviorEx.OrbitCam>();
-            orbitCam.Target = mdl.GetComponent<Bounds>().Sphere.Xyz;
+            //hmrView.ResetEngine();
+            EngineLayer.ResetScene(_animController);
+
+            //Engine.AddVdir(_animController.RootPath, true);
+            //var h3da = _animController.ReelPath;
+            //var h3dm = h3da.Substring(0, h3da.Length - 1) + "m";
+            //if (!File.Exists(h3dm)) {
+            //    // handles the case where h3dm doesnt exist
+            //}
+            //var mdl = Engine.ActiveScene.CreateModel("Character", h3dm);
+            //Animation mdlAnim = mdl.AddComponent<Animation>();
+            //mdlAnim.FilePath = h3da;
+            //AnimController.Clips = mdlAnim.Clips;
+            //AnimController.Bones = mdlAnim.Bones;
+            //var orbitCam = Engine.ActiveScene.FindObject("Camera").GetBehavior<BehaviorEx.OrbitCam>();
+            //orbitCam.Target = mdl.GetComponent<Bounds>().Sphere.Xyz;
         }
 
         private void lstLayers_KeyDown(object sender, KeyEventArgs e)
 
         private void MainForm_Load(object sender, EventArgs e)
         {
-            hmrView.InitEngine("../../data");
+            EngineLayer.InitEngine("../../data", engView);
+
+            //hmrView.InitEngine("../../data");
 
             showWelcomeScreen();
             grdParamsInit();
             using (StreamReader sr = new StreamReader(file))
             using (JsonReader reader = new JsonTextReader(sr)) {
                 _animController = serializer.Deserialize<AnimController>(reader);
-                hmrview_reset();
+                //hmrview_reset();
+                EngineLayer.ResetScene(_animController);
             }
 
             try {
                     break;
                 case WelcomScreenResult.CreateNew:
                     _animController = AnimController.CreateController(dlg.RootPath, dlg.ReelPath);
-                    hmrview_reset();
+                    //hmrview_reset();
+                    EngineLayer.ResetScene(_animController);
                     break;
             }
         }
         #region Fields
         private AnimController _animController;
         #endregion
+
     }
 }

DarkMotion/UserControls/AnimLayerView.cs

             _selectedTransPen.CustomEndCap = new AdjustableArrowCap(4, 6);
             _selectedTransPen.DashStyle = DashStyle.Dash;
 
-            EngineLayer.Update += (dt) => {
+            EngineLayer.Update += () => {
                 if (_editStateMachine == null)
                     return;
                 var layer = _editStateMachine.Name;
                     var rect = getStateRect(s);
 
                     g.FillRectangle((s == _editStateMachine.DefaultState) ?
-										_defaultStateBrush : _stateBrush, rect);
+                                             _defaultStateBrush : _stateBrush, rect);
                     var overlayBrush = new LinearGradientBrush(rect, Color.FromArgb(100, 0, 0, 0),
                                              Color.FromArgb(0, 255, 255, 255), 270f);
                     g.FillRectangle(overlayBrush, rect);
                     g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);
                     g.DrawString(s.Name, Font, Brushes.Black, s.Position.X, s.Position.Y, _centerAlign);
 
-                    if (s.Sequence is BlendTree)
-                        g.DrawImage(_treeIcon, rect.Right - _treeIcon.Width, rect.Bottom - _treeIcon.Height, _treeIcon.Width, _treeIcon.Height);
+                    if (s.Sequence is BlendTree) {
+                        g.DrawImage(_treeIcon, rect.Right - _treeIcon.Width, rect.Bottom - _treeIcon.Height,
+                            _treeIcon.Width, _treeIcon.Height);
+                    }
                     if (_selected == s) {
                         rect.X -= 3;
                         rect.Y -= 3;

SharpHammer/NativeCalls.cs

 #if DEBUG
         const string _coreDll   = "dhcore-dbg.dll";
         const string _engineDll = "dheng-dbg.dll";
-        const string _appDll = "dhapp-dbg.dll";
+        const string _appDll    = "dhapp-dbg.dll";
 #else
-		const string _coreDll = "dhcore.dll";
+		const string _coreDll   = "dhcore.dll";
 		const string _engineDll = "dheng.dll";
-        const string _appDll = "dhapp.dll"
+        const string _appDll    = "dhapp.dll"
 #endif
         internal static bool IS_FAIL(int r) { return r <= 0; }
 
 
         #region dh_engine
 
-        #region delegates
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        public delegate void pfn_app_update();
-
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        public delegate void pfn_app_keypress(byte charcode, uint vkeycode);
-
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        public delegate void pfn_app_active(int active);
-
-        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
-        public delegate void pfn_app_resize(uint width, uint height);
-        #endregion
-
         #region eng
         [DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
         public static extern int eng_init([In] IntPtr @params);
         #endregion
 
         #region component
+        [DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "cmp_animchar_get_curstate")]
+        private static extern uint _cmp_animchar_get_curstate(ulong hdl,
+            [In] [MarshalAs(UnmanagedType.LPStr)] string layer, System.IntPtr state, ref float progress);
+
+        public static bool cmp_animchar_get_curstate(ulong hdl, string layer, out string state, out float progress)
+        {
+            if (_tmpStringBuffer1 == IntPtr.Zero) {
+                _tmpStringBuffer1 = Marshal.AllocHGlobal(256);
+            }
+            float f = 0;
+            uint r = _cmp_animchar_get_curstate(hdl, layer, _tmpStringBuffer1, ref f);
+            state = Marshal.PtrToStringAnsi(_tmpStringBuffer1);
+            progress = f;
+            return (r != 0u);
+        }
+
+        [DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "cmp_animchar_get_curtransition")]
+        private static extern uint _cmp_animchar_get_curtransition(ulong hdl,
+            [In] [MarshalAs(UnmanagedType.LPStr)] string layer, System.IntPtr s1, System.IntPtr s2, ref float f);
+
+        public static bool cmp_animchar_get_curtransition(ulong hdl, string layer, out string state1, out string state2, out float progress)
+        {
+            if (_tmpStringBuffer1 == IntPtr.Zero) {
+                _tmpStringBuffer1 = Marshal.AllocHGlobal(256);
+            }
+            if (_tmpStringBuffer2 == IntPtr.Zero) {
+                _tmpStringBuffer2 = Marshal.AllocHGlobal(256);
+            }
+
+            float f = 0;
+            uint r = _cmp_animchar_get_curtransition(hdl, layer, _tmpStringBuffer1, _tmpStringBuffer2, ref f);
+            state1 = Marshal.PtrToStringAnsi(_tmpStringBuffer1);
+            state2 = Marshal.PtrToStringAnsi(_tmpStringBuffer2);
+            progress = f;
+            return (r != 0u);
+        }
+
         [DllImport(_engineDll, CallingConvention = CallingConvention.Cdecl)]
         public static extern IntPtr cmp_findname([In] [MarshalAs(UnmanagedType.LPStr)] string name);
 
         #endregion
 
         #region dh_app
+
+        #region delegates
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void pfn_app_update();
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void pfn_app_keypress(byte charcode, uint vkeycode);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void pfn_app_active(int active);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void pfn_app_resize(uint width, uint height);
+        #endregion
+
         #region app
+        
+        
+
         [DllImport(_appDll, CallingConvention = CallingConvention.Cdecl)]
         public static extern IntPtr app_config_load(
             [In] [MarshalAs(UnmanagedType.LPStr)] string cfg_jsonfile);
         #endregion
         
         #endregion
+
+        #region Fields
+        private static IntPtr _tmpStringBuffer1 = IntPtr.Zero;
+        private static IntPtr _tmpStringBuffer2 = IntPtr.Zero;
+        #endregion
+
     }
 
     internal enum variant_type
 
         [FieldOffsetAttribute(0)]
         public Color4 color4;
-
-        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16, ArraySubType = UnmanagedType.I1)]
-        //[FieldOffsetAttribute(0)]
-        //public byte[16] str;
     }
 
     [StructLayout(LayoutKind.Sequential)]