/[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 106 - (show annotations) (download)
Sat Jul 17 14:52:37 2010 UTC (10 years, 9 months ago) by william
File size: 3214 byte(s)
implement Granny2ExceptionWriter

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

  ViewVC Help
Powered by ViewVC 1.1.22