2 using System.Collections.Generic;
5 using System.Reflection;
6 using System.Runtime.CompilerServices;
10 using Paradox.Effects;
12 using Paradox.EntityModel;
13 using Paradox.Framework;
14 using Paradox.Framework.Graphics;
15 using Paradox.Framework.Mathematics;
16 using Paradox.Framework.MicroThreading;
17 using Paradox.Framework.PropertyModel;
18 using Paradox.Framework.Serialization;
19 using Paradox.Framework.Serialization.Contents;
26 using NGit.Revwalk.Filter;
29 using NGit.Treewalk.Filter;
41 private static MemoryStream memoryStream =
new MemoryStream();
42 private static Serializer Serializer;
46 Serializer = Serializer.Default;
51 List<EntityDefinition> entities = null;
52 var rw =
new BinarySerializationReader(stream);
53 rw.Context.Serializer = Serializer;
54 rw.SerializeClass(null, ref entities, ArchiveMode.Deserialize);
59 public static void SaveAssets(EngineContext engineContext)
61 var entities =
new List<EntityDefinition>();
63 foreach (var entity
in engineContext.EntityManager.Entities.OrderBy(x => x.Guid).Where(x => x.Name ==
"him"))
65 var entityDefinition =
new EntityDefinition(entity.Guid);
66 entities.Add(entityDefinition);
68 foreach (var entityComponent
in entity.Properties.Where(x => x.Value is EntityComponent).OrderBy(x => x.Key.Name))
70 var componentDefinition =
new EntityComponentDefinition { Name = entityComponent.Key.Name, Properties =
new List<EntityComponentProperty>() };
71 entityDefinition.Components.Add(componentDefinition);
73 var entityComponentValue = entityComponent.Value as EntityComponent;
75 foreach (var field
in entityComponentValue.GetType().GetFields())
77 if (field.GetCustomAttributes(typeof(VersionableAttribute),
true).Length == 0)
80 componentDefinition.Properties.Add(
new EntityComponentProperty(
EntityComponentPropertyType.Field, field.Name, Encode(field.GetValue(entityComponentValue))));
83 foreach (var property
in entityComponentValue.GetType().GetProperties())
85 if (property.GetCustomAttributes(typeof(VersionableAttribute),
true).Length == 0)
88 componentDefinition.Properties.Add(
new EntityComponentProperty(
EntityComponentPropertyType.Property, property.Name, Encode(property.GetValue(entityComponentValue, null))));
91 componentDefinition.Properties = componentDefinition.Properties.OrderBy(x => x.Name).ToList();
95 var fileStream =
new FileStream(
@"C:\DEV\hotei_scene\scene.hotei",
FileMode.Create, FileAccess.Write);
96 var stream =
new BinarySerializationWriter(fileStream);
97 stream.Context.Serializer = Serializer;
98 stream.SerializeClass(null, ref entities, ArchiveMode.Serialize);
104 public string Url {
get; set; }
108 public static void MergeTest(EngineContext engineContext)
111 var db =
new FileRepository(
new FilePath(
@"C:\DEV\hotei_scene",
Constants.DOT_GIT));
112 var git =
new Git(db);
113 var tree1Ref = db.GetRef(
"test");
114 var tree2Ref = db.GetRef(Constants.HEAD);
115 var tree1CommitId = tree1Ref.GetObjectId();
116 var tree2CommitId = tree2Ref.GetObjectId();
119 var mergeResult = git.Merge().Include(tree1CommitId).Call();
121 if (mergeResult.GetMergeStatus() == MergeStatus.CONFLICTING)
123 foreach (var conflict
in mergeResult.GetConflicts())
125 if (conflict.Key.EndsWith(
".hotei"))
128 var walk =
new RevWalk(db);
129 walk.SetRevFilter(RevFilter.MERGE_BASE);
130 walk.MarkStart(walk.ParseCommit(tree1CommitId));
131 walk.MarkStart(walk.ParseCommit(tree2CommitId));
132 var baseTree = walk.Next();
134 var tw =
new NameConflictTreeWalk(db);
135 tw.AddTree(
new RevWalk(db).ParseTree(tree1CommitId).ToObjectId());
136 tw.AddTree(
new RevWalk(db).ParseTree(tree2CommitId).ToObjectId());
137 if (baseTree != null)
138 tw.AddTree(
new RevWalk(db).ParseTree(baseTree.ToObjectId()).ToObjectId());
139 tw.Filter = PathFilter.Create(conflict.Key);
144 var tree0 = baseTree != null ? tw.GetTree<AbstractTreeIterator>(2) : null;
145 var tree1 = tw.GetTree<AbstractTreeIterator>(0);
146 var tree2 = tw.GetTree<AbstractTreeIterator>(1);
149 var data0 = baseTree != null ?
LoadEntities(
new MemoryStream(tw.ObjectReader.Open(tree0.EntryObjectId).GetBytes())) : null;
150 var data1 =
LoadEntities(
new MemoryStream(tw.ObjectReader.Open(tree1.EntryObjectId).GetBytes()));
151 var data2 =
LoadEntities(
new MemoryStream(tw.ObjectReader.Open(tree2.EntryObjectId).GetBytes()));
154 var entities =
new List<EntityDefinition>();
158 var fileStream =
new FileStream(
new FilePath(db.WorkTree, conflict.Key),
FileMode.Create, FileAccess.Write);
159 var stream =
new BinarySerializationWriter(fileStream);
160 stream.Context.Serializer = Serializer;
161 stream.SerializeClass(null, ref entities, ArchiveMode.Serialize);
166 git.Add().AddFilepattern(conflict.Key).Call();
174 public static void ResolveEntityConflicts(ThreeWayConflictType conflictType, IList<EntityDefinition>[] lists,
int[] indices, IList<EntityDefinition> result)
176 switch (conflictType)
178 case ThreeWayConflictType.Modified1And2:
179 var entityDefinition =
new EntityDefinition(lists[0][indices[0]].Guid);
180 ThreeWayMergeOrdered.Merge(entityDefinition.Components, lists[0][indices[0]].Components, lists[1][indices[1]].Components, lists[2][indices[2]].Components, x => x.Name, (x,
y) => x ==
y,
ResolveComponentConflicts);
181 result.Add(entityDefinition);
184 throw new NotImplementedException();
189 public static void ResolveComponentConflicts(ThreeWayConflictType conflictType, IList<EntityComponentDefinition>[] lists,
int[] indices, IList<EntityComponentDefinition> result)
191 switch (conflictType)
193 case ThreeWayConflictType.Modified1And2:
194 var componentDefinition =
new EntityComponentDefinition { Name = lists[0][indices[0]].Name, Properties =
new List<EntityComponentProperty>() };
195 ThreeWayMergeOrdered.Merge(componentDefinition.Properties, lists[0][indices[0]].Properties, lists[1][indices[1]].Properties, lists[2][indices[2]].Properties, x => x.Name, (x,
y) => x ==
y,
ResolvePropertyConflicts);
196 result.Add(componentDefinition);
199 throw new NotImplementedException();
204 public static void ResolvePropertyConflicts(ThreeWayConflictType conflictType, IList<EntityComponentProperty>[] lists,
int[] indices, IList<EntityComponentProperty> result)
206 switch (conflictType)
208 case ThreeWayConflictType.Modified1And2:
209 result.Add(lists[1][indices[1]]);
212 throw new NotImplementedException();
218 var fileStream =
new FileStream(
@"C:\DEV\hotei_scene\scene.hotei",
FileMode.Open, FileAccess.Read);
222 foreach (var entityDefinition
in entities)
224 var entity = engineContext.EntityManager.Entities.FirstOrDefault(x => x.Guid == entityDefinition.Guid);
227 entity =
new Entity(entityDefinition.Guid);
228 engineContext.EntityManager.AddEntity(entity);
231 foreach (var componentDefinition
in entityDefinition.Components)
233 EntityComponent component = null;
234 if (componentDefinition.Name ==
"TransformationComponent")
236 component = entity.Get(TransformationComponent.Key);
237 if (component == null)
239 component =
new TransformationTRSComponent();
240 entity.Set(TransformationComponent.Key, (TransformationComponent)component);
248 foreach (var componentProperty
in componentDefinition.Properties)
250 switch (componentProperty.Type)
252 case EntityComponentPropertyType.Field:
253 var field = component.GetType().GetField(componentProperty.Name);
254 field.SetValue(component, Decode(componentProperty.Data));
256 case EntityComponentPropertyType.Property:
257 var
property = component.GetType().GetProperty(componentProperty.Name);
258 property.SetValue(component, Decode(componentProperty.Data), null);
261 throw new NotImplementedException();
268 private static object LoadAssetFromUrl(ContentManager contentManager,
string url)
270 throw new NotImplementedException();
273 private static byte[] Encode(
object obj, Serializer serializer = null)
275 var result =
new MemoryStream();
276 var stream =
new BinarySerializationWriter(result);
277 if (serializer != null)
278 stream.Context.Serializer = serializer;
279 stream.SerializeExtended(null, ref obj, ArchiveMode.Serialize);
281 return result.ToArray();
284 private static object Decode(byte[] data, Serializer serializer = null)
286 object result = null;
287 var stream =
new BinarySerializationReader(
new MemoryStream(data));
288 if (serializer != null)
289 stream.Context.Serializer = serializer;
290 stream.SerializeExtended(null, ref result, ArchiveMode.Deserialize);
static void ResolvePropertyConflicts(ThreeWayConflictType conflictType, IList< EntityComponentProperty >[] lists, int[] indices, IList< EntityComponentProperty > result)
static void ResolveEntityConflicts(ThreeWayConflictType conflictType, IList< EntityDefinition >[] lists, int[] indices, IList< EntityDefinition > result)
System.IO.FileMode FileMode
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
global::MonoTouch.Constants Constants
static void LoadAssets(EngineContext engineContext)
static void ResolveComponentConflicts(ThreeWayConflictType conflictType, IList< EntityComponentDefinition >[] lists, int[] indices, IList< EntityComponentDefinition > result)
static void SaveAssets(EngineContext engineContext)
static void MergeTest(EngineContext engineContext)
static List< EntityDefinition > LoadEntities(Stream stream)
EntityComponentPropertyType