/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Skeleton.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/coretypes/implementation/Skeleton.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (hide annotations) (download)
Sat Jul 17 05:10:22 2010 UTC (10 years, 10 months ago) by william
File size: 3151 byte(s)
add StackTrace support for error handling (to see the stack calls)

1 william 83 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using gr2lib.core.interfaces;
6     using gr2lib.core.helpers;
7 william 95 using System.Diagnostics;
8 william 83
9     namespace gr2lib.core.coretypes.implementation
10     {
11     public class Skeleton : ISkeleton
12     {
13    
14     public Skeleton()
15     {
16     this.SkeletonName = "Skeleton";
17     this.Bones = new List<Bone>();
18     this.LodType = 0;
19     //this.NativePointer = IntPtr.Zero;
20     //this.ExtendedData = IntPtr.Zero;
21     }
22    
23    
24     internal static Skeleton ReadFromMemory(IntPtr pointer)
25     {
26 william 86 try
27     {
28 william 83 if (pointer == IntPtr.Zero) return null;
29     native.Skeleton native = Helpers.ReadFromMemory<native.Skeleton>(pointer);
30     Skeleton managed = ReadFromNative(native);
31     managed.NativePointer = pointer;
32     return managed;
33 william 86 }
34     catch (Exception ex)
35     {
36 william 95 StackTrace st = new StackTrace(true);
37     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
38 william 86 return default(Skeleton);
39     }
40 william 83 }
41    
42     internal static Skeleton ReadFromNative(native.Skeleton native)
43     {
44 william 86 try
45     {
46 william 83 Skeleton managed = new Skeleton();
47     managed.SkeletonName = string.IsNullOrEmpty(native.Name) ? "{null}" : native.Name;
48     IntPtr[] bones = Helpers.ReadPtrArrayFromMemory<native.Bone>(native.Bones);
49     int boneLength = bones.Length;
50    
51     foreach (IntPtr ptr in bones)
52     {
53     managed.Bones.Add(new Bone());
54     }
55    
56     for (int i = 0; i < boneLength; i++)
57     {
58     managed.Bones[i] = Bone.ReadFromMemory(bones[i]);
59     }
60     managed.LodType = native.LodType;
61     managed.ExtendedData = native.ExtendedData;
62     return managed;
63 william 86 }
64     catch (Exception ex)
65     {
66 william 95 StackTrace st = new StackTrace(true);
67     Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
68 william 86 return default(Skeleton);
69     }
70 william 83 }
71    
72     #region ISkeleton Members
73    
74     private string _SkeletonName;
75     private List<Bone> _Bones;
76     private int _LodType;
77    
78     public string SkeletonName { get { return _SkeletonName; } set { _SkeletonName = value; } }
79     public List<Bone> Bones { get { return _Bones; } set { _Bones = value; } }
80     public int LodType { get { return _LodType; } set { _LodType = value; } }
81     #endregion
82    
83     #region INativePointer Members
84     private IntPtr _NativePointer;
85     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
86     #endregion
87    
88     #region IExtendedData Members
89     private IntPtr _ExtendedData;
90     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
91     #endregion
92     }
93     }

  ViewVC Help
Powered by ViewVC 1.1.22