public void AddObjectToLvl(LevelObject lo, bool remove) { if (!remove) { worldObjects.Add(lo.Name, lo); if (ObjectInstanceAdded != null) { LevelEventArgs e = new LevelEventArgs(); e.lo = lo; ObjectInstanceAdded(this, e); } } else { worldObjects.Remove(lo.Name); if (ObjectInstanceRemoved != null) { LevelEventArgs e = new LevelEventArgs(); e.lo = lo; ObjectInstanceRemoved(this, e); } } }
public DrawableLevelObjectInstance(LevelObject lo, LevelObjectData data, ServiceManager services) { m_lo = lo; m_services = services; Init(data); }
public void LoadLevelFile(System.IO.Stream stream) { System.IO.BinaryReader br = new System.IO.BinaryReader(stream); /* Get Current App Version For Comparison */ String currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); /* Check Loading File's Version To Current */ String fileVersion = br.ReadString(); if (fileVersion != currentVersion) { /* ERROR: File Version Out of Date */ throw new IncorrectFileVersionException(); } /* Load the Level Attributes */ levelName = br.ReadString(); /* Load the Object Type Palette */ List<FileOps.LevelObjectTypeDefinition> types = FileOps.ReadObjectPalette(br); /* Level Terrain */ int numTerrainChunks = br.ReadInt32(); for (int i = 0; i < numTerrainChunks; i++) { LevelTerrain terrain = new LevelTerrain(); terrain.Name = br.ReadString(); terrain.Position = FileOps.ReadVec3(br); Scale scale = new Scale(); scale.scales = FileOps.ReadVec3(br); terrain.Scaling = scale; Point pt = new Point(); pt.X = br.ReadInt32(); pt.Y = br.ReadInt32(); terrain.HeightMapDimensions = pt; int numSamples = terrain.HeightMapDimensions.X * terrain.HeightMapDimensions.Y; byte[] heightMap = new byte[numSamples]; br.Read(heightMap, 0, numSamples); terrain.HeightMap = heightMap; terrainObjects.Add(terrain.Name, terrain); } /* Load Level Object Instances */ int levelCnt = br.ReadInt32(); System.Collections.Generic.List<LevelObject> lvlObjs = new List<LevelObject>(); for (int i = 0; i < levelCnt; i++) { LevelObject lo = new LevelObject(); /* Save Object Instance Attributes */ lo.Index = br.ReadInt32(); lo.Name = br.ReadString(); lo.TypeId = new Guid(br.ReadString()); /* Object Instance Transforms */ lo.Rotation = FileOps.ReadVec3(br); lo.Scale = FileOps.ReadVec3(br); lo.Position = FileOps.ReadVec3(br); lvlObjs.Add(lo); m_nextUnusedObID = Math.Max(lo.Index, m_nextUnusedObID); m_nextUnusedObID++; } br.Close(); /* Load the Level Object Types Definitions From * Files For Each Type in Level's Object Palette */ foreach (FileOps.LevelObjectTypeDefinition t in types) { /* Try to Open the Type's File */ String typeFilename = levelFileName; int idx = typeFilename.LastIndexOf('\\')+1; typeFilename = typeFilename.Substring(0, idx); typeFilename += t.FileName; System.IO.FileStream typeFile = null; try { typeFile = System.IO.File.Open(typeFilename, System.IO.FileMode.Open); /* Fill Out a New Object Type from The File Definition */ LevelObjectType lot = LoadTypeFile(typeFile); /* Verify the Type Matches the Guid From the Level Type Palette */ if (lot.TypeID == t.TypeId) { this.objectPalette.Add(lot.Name, lot); } else { System.Diagnostics.Debug.Assert(true); } /* Increment the Type ID counter */ m_nextUnusedTypeID = Math.Max(lot.Index, m_nextUnusedTypeID); m_nextUnusedTypeID++; } finally { typeFile.Close(); } } /* Add the object to the level linked to their type */ foreach (LevelObject lo in lvlObjs) { AddObjectToLvl(lo, false); } }
public void GroundClampObject(LevelObject lo) { Vector3 objectPosition = lo.Position; TerrainInfo localTerrain = null; /* find the terrain chunk that contains the object's (X,Z) position */ foreach (KeyValuePair<String, LevelTerrain> kv in terrainObjects) { LevelTerrain lt = kv.Value; TerrainInfo ti = new TerrainInfo(lt); if (ti.ContainsPointXZ(objectPosition)) { localTerrain = ti; break; } } /* find the Y position at the object's X,Z * location and adjust to sit above ground */ if (localTerrain != null) { float? newY = localTerrain.GetTerrainHeightAtXZ(objectPosition.X, objectPosition.Z); lo.Position = new Vector3(lo.Position.X, newY.Value, lo.Position.Z); } }
public LevelObject CreateNewLevelObjectInstance() { /* Generate a new unique ID */ int objID = GetNextObjectIdx(); /* Create a fake name * (TODO: this can come from create object dialog) */ String name = "NEWOBJECT" + objID; /* Create the new level object */ LevelObject lo = new LevelObject(); lo.Index = objID; lo.Name = name; lo.Scale = new Vector3(1.0f, 1.0f, 1.0f); return lo; }
public void AddObjectInstanceToScene(LevelObject lo, LevelObjectData data) { DrawableLevelObjectInstance drawLo = new DrawableLevelObjectInstance(lo, data, Services); m_scene.Add(lo.Name, drawLo); }