/[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 86 - (show annotations) (download)
Fri Jul 16 23:35:21 2010 UTC (10 years, 10 months ago) by william
File size: 2924 byte(s)
Add Try/Catch blocks in to all API 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
8 namespace gr2lib.core.coretypes.implementation
9 {
10 public class Skeleton : ISkeleton
11 {
12
13 public Skeleton()
14 {
15 this.SkeletonName = "Skeleton";
16 this.Bones = new List<Bone>();
17 this.LodType = 0;
18 //this.NativePointer = IntPtr.Zero;
19 //this.ExtendedData = IntPtr.Zero;
20 }
21
22
23 internal static Skeleton ReadFromMemory(IntPtr pointer)
24 {
25 try
26 {
27 if (pointer == IntPtr.Zero) return null;
28 native.Skeleton native = Helpers.ReadFromMemory<native.Skeleton>(pointer);
29 Skeleton managed = ReadFromNative(native);
30 managed.NativePointer = pointer;
31 return managed;
32 }
33 catch (Exception ex)
34 {
35 Console.WriteLine(ex.ToString());
36 return default(Skeleton);
37 }
38 }
39
40 internal static Skeleton ReadFromNative(native.Skeleton native)
41 {
42 try
43 {
44 Skeleton managed = new Skeleton();
45 managed.SkeletonName = string.IsNullOrEmpty(native.Name) ? "{null}" : native.Name;
46 IntPtr[] bones = Helpers.ReadPtrArrayFromMemory<native.Bone>(native.Bones);
47 int boneLength = bones.Length;
48
49 foreach (IntPtr ptr in bones)
50 {
51 managed.Bones.Add(new Bone());
52 }
53
54 for (int i = 0; i < boneLength; i++)
55 {
56 managed.Bones[i] = Bone.ReadFromMemory(bones[i]);
57 }
58 managed.LodType = native.LodType;
59 managed.ExtendedData = native.ExtendedData;
60 return managed;
61 }
62 catch (Exception ex)
63 {
64 Console.WriteLine(ex.ToString());
65 return default(Skeleton);
66 }
67 }
68
69 #region ISkeleton Members
70
71 private string _SkeletonName;
72 private List<Bone> _Bones;
73 private int _LodType;
74
75 public string SkeletonName { get { return _SkeletonName; } set { _SkeletonName = value; } }
76 public List<Bone> Bones { get { return _Bones; } set { _Bones = value; } }
77 public int LodType { get { return _LodType; } set { _LodType = value; } }
78 #endregion
79
80 #region INativePointer Members
81 private IntPtr _NativePointer;
82 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
83 #endregion
84
85 #region IExtendedData Members
86 private IntPtr _ExtendedData;
87 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
88 #endregion
89 }
90 }

  ViewVC Help
Powered by ViewVC 1.1.22