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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show 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 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 using System.Diagnostics;
8
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 try
27 {
28 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 }
34 catch (Exception ex)
35 {
36 StackTrace st = new StackTrace(true);
37 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
38 return default(Skeleton);
39 }
40 }
41
42 internal static Skeleton ReadFromNative(native.Skeleton native)
43 {
44 try
45 {
46 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 }
64 catch (Exception ex)
65 {
66 StackTrace st = new StackTrace(true);
67 Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
68 return default(Skeleton);
69 }
70 }
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