protected override void OnLoad(EventArgs e) { base.WindowBorder = WindowBorder.Hidden; base.OnLoad(e); Title = "SageCS - BFME II"; Renderer.shaders.Add("textured", new Shader(Resource.GetShader("tex.vert"), Resource.GetShader("tex.frag"))); Renderer.activeShader = "textured"; try { Texture t = new Texture(); t.Load(File.Open("GermanSplash.jpg", FileMode.Open)); Renderer.textures.Add("splash", t); } catch { Texture t = new Texture(); t.Load(File.Open("EnglishSplash.jpg", FileMode.Open)); Renderer.textures.Add("splash", t); } Sprite background = new Sprite("splash"); Renderer.initProgram(Width, Height); Renderer.render(); base.SwapBuffers(); FileSystem.Init(); AudioSystem.Init(); Stopwatch stopwatch = Stopwatch.StartNew(); Texture tex = new Texture(); var texS = FileSystem.Open("art\\compiledtextures\\al\\all_faction_banners.dds"); tex.Load(texS); // W3DLoader.Load(FileSystem.Open("art\\w3d\\gu\\gumaarms_skn.w3d")); //W3DLoader.Load(FileSystem.Open("art\\w3d\\gu\\gumaarms_runa.w3d")); //W3DLoader.Load(FileSystem.Open("art\\w3d\\gu\\gumaarms_skl.w3d")); //INIManager.ParseINIs(); new MapLoader(FileSystem.Open("maps\\map mp fords of isen ii\\map mp fords of isen ii.map")); //FileSystem.OpenAllW3D(); var buffer = WavLoader.Load(FileSystem.Open("data\\audio\\speech\\ucheer.wav")); Audio.Sound testSound = new Audio.Sound(buffer); testSound.Play(); stopwatch.Stop(); Console.WriteLine("total loading time: " + stopwatch.ElapsedMilliseconds + "ms"); }
/// <summary> /// Loads this scene node from a given binary reader. /// </summary> /// <param name="reader">Binary reader to load this scene node from.</param> public override void Load(BinaryReader reader) { // Load all the basic entity details. base.Load(reader); // Load all the scripted specific details. if (reader.ReadBoolean() == true) { string url = reader.ReadString(); // Load the objects script from the memory stream we dumped it into. ScriptProcess process = VirtualMachine.GlobalInstance.LoadScript(url); #region Property Loading int propertyCount = reader.ReadInt16(); for (int i = 0; i < propertyCount; i++) { string identifier = reader.ReadString(); DataTypeValue dataTypeValue = new DataTypeValue((DataType)reader.ReadByte(), false, false); bool isArray = reader.ReadBoolean(); // Look through the script processes global variables to see if this // variable exists. VariableSymbol variableSymbol = null; if (process != null) { foreach (Symbol symbol in process.GlobalScope.Symbols) { if (symbol is VariableSymbol == false || ((VariableSymbol)symbol).Identifier != identifier || ((VariableSymbol)symbol).DataType != dataTypeValue) { continue; } variableSymbol = symbol as VariableSymbol; break; } } // Quickly find out the meta data of this symbol. string editMethod = ""; if (variableSymbol != null) { foreach (Symbol subSymbol in variableSymbol.Symbols) { if (subSymbol is MetaDataSymbol) { if (((MetaDataSymbol)subSymbol).Identifier.ToLower() == "editmethod") { editMethod = ((MetaDataSymbol)subSymbol).Value; break; } } } } // Read in value based on data type. if (isArray == true && reader.ReadBoolean() == true) { int arrayLength = reader.ReadInt32(); int arrayIndex = process == null ? 0 : process[0].AllocateArray(dataTypeValue.DataType, arrayLength); for (int k = 0; k < arrayLength; k++) { switch (dataTypeValue.DataType) { case DataType.Bool: { bool value = reader.ReadBoolean(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Byte: { byte value = reader.ReadByte(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Double: { double value = reader.ReadDouble(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Float: { float value = reader.ReadSingle(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Int: { int value = reader.ReadInt32(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Long: { long value = reader.ReadInt64(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Short: { short value = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.String: { string value = reader.ReadString(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, value); } } break; case DataType.Object: { if (reader.ReadBoolean() == true) { int type = reader.ReadByte(); if (type == 0) { string imageUrl = reader.ReadString(); int cellWidth = reader.ReadInt32(); int cellHeight = reader.ReadInt32(); int hSpacing = reader.ReadInt16(); int vSpacing = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, new Fusion.Engine.ScriptingFunctions.ImageScriptObject(GraphicsManager.LoadImage(imageUrl, cellWidth, cellHeight, hSpacing, vSpacing, 0))); } } else if (type == 1) { string soundUrl = reader.ReadString(); int freq = reader.ReadInt32(); float innerRadius = reader.ReadSingle(); float outerRadius = reader.ReadSingle(); bool loop = reader.ReadBoolean(); float pan = reader.ReadSingle(); float volume = reader.ReadSingle(); bool streaming = reader.ReadBoolean(); bool positional = reader.ReadBoolean(); Audio.SoundFlags flags = 0; if (streaming == true) { flags |= Audio.SoundFlags.Streamed; } if (positional == true) { flags |= Audio.SoundFlags.Positional; } Audio.Sound sound = Audio.AudioManager.LoadSound(soundUrl, flags); sound.Frequency = freq; sound.InnerRadius = innerRadius; sound.OuterRadius = outerRadius; sound.Looping = loop; sound.Pan = pan; sound.Volume = volume; if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, new Fusion.Engine.ScriptingFunctions.SoundScriptObject(sound)); } } } } break; } } } else { switch (dataTypeValue.DataType) { case DataType.Bool: { bool value = reader.ReadBoolean(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Byte: { byte value = reader.ReadByte(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Double: { double value = reader.ReadDouble(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Float: { float value = reader.ReadSingle(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Int: { int value = reader.ReadInt32(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Long: { long value = reader.ReadInt64(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Short: { short value = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.String: { string value = reader.ReadString(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Object: { if (reader.ReadBoolean() == true) { int type = reader.ReadByte(); if (type == 0) { string imageUrl = reader.ReadString(); int cellWidth = reader.ReadInt32(); int cellHeight = reader.ReadInt32(); int hSpacing = reader.ReadInt16(); int vSpacing = reader.ReadInt16(); if (ResourceManager.ResourceExists(imageUrl) == true && process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, new Fusion.Engine.ScriptingFunctions.ImageScriptObject(GraphicsManager.LoadImage(imageUrl, cellWidth, cellHeight, hSpacing, vSpacing, 0))); } } else if (type == 1) { string soundUrl = reader.ReadString(); int freq = reader.ReadInt32(); float innerRadius = reader.ReadSingle(); float outerRadius = reader.ReadSingle(); bool loop = reader.ReadBoolean(); float pan = reader.ReadSingle(); float volume = reader.ReadSingle(); bool streaming = reader.ReadBoolean(); bool positional = reader.ReadBoolean(); Audio.SoundFlags flags = 0; if (streaming == true) { flags |= Audio.SoundFlags.Streamed; } if (positional == true) { flags |= Audio.SoundFlags.Positional; } if (ResourceManager.ResourceExists(soundUrl) == true && process != null && variableSymbol != null) { Audio.Sound sound = Audio.AudioManager.LoadSound(soundUrl, flags); sound.Frequency = freq; sound.InnerRadius = innerRadius; sound.OuterRadius = outerRadius; sound.Looping = loop; sound.Pan = pan; sound.Volume = volume; process[0].SetGlobalVariable(identifier, new Fusion.Engine.ScriptingFunctions.SoundScriptObject(sound)); } } } } break; } } } #endregion // Now set the process! _process.Process = process; if (_process.Process != null) { _process.Process.OnStateChange += OnStateChange; } if (_process.Process != null && _process.Process.State != null) { OnStateChange(_process.Process, _process.Process.State); } SyncCollisionEvents(); } }
/// <summary> /// Saves this entity into a given binary writer. /// </summary> /// <param name="writer">Binary writer to save this entity into.</param> public override void Save(BinaryWriter writer) { // Save all the basic entity details. base.Save(writer); // Save all the scripted entity specific details. writer.Write((_process.Process != null && _process.Process.Url != null)); if ((_process.Process != null && _process.Process.Url != null)) { writer.Write(_process.Process.Url); int propertyCount = 0; foreach (Symbol symbol in _process.Process.GlobalScope.Symbols) { if (symbol is VariableSymbol == false || ((VariableSymbol)symbol).IsProperty == false) { continue; } propertyCount++; } writer.Write((short)propertyCount); // Write in the value of all the properties stored in the process. foreach (Symbol symbol in _process.Process.GlobalScope.Symbols) { if (symbol is VariableSymbol == false || ((VariableSymbol)symbol).IsProperty == false) { continue; } VariableSymbol variableSymbol = symbol as VariableSymbol; // Quickly find out the meta data of this symbol. string editMethod = ""; foreach (Symbol subSymbol in symbol.Symbols) { if (subSymbol is MetaDataSymbol) { if (((MetaDataSymbol)subSymbol).Identifier.ToLower() == "editmethod") { editMethod = ((MetaDataSymbol)subSymbol).Value; break; } } } writer.Write(variableSymbol.Identifier); writer.Write((byte)variableSymbol.DataType.DataType); writer.Write(variableSymbol.IsArray); if (variableSymbol.IsArray == true) { int arrayIndex = _process.Process[0].GetArrayGlobal(variableSymbol.Identifier); writer.Write(arrayIndex != 0); if (arrayIndex != 0) { int arrayLength = _process.Process[0].GetArrayLength(arrayIndex); writer.Write(arrayLength); for (int i = 0; i < arrayLength; i++) { switch (variableSymbol.DataType.DataType) { case DataType.Bool: writer.Write(_process.Process[0].GetBooleanArrayElement(arrayIndex, i)); break; case DataType.Byte: writer.Write(_process.Process[0].GetByteArrayElement(arrayIndex, i)); break; case DataType.Double: writer.Write(_process.Process[0].GetDoubleArrayElement(arrayIndex, i)); break; case DataType.Float: writer.Write(_process.Process[0].GetFloatArrayElement(arrayIndex, i)); break; case DataType.Int: writer.Write(_process.Process[0].GetIntArrayElement(arrayIndex, i)); break; case DataType.Long: writer.Write(_process.Process[0].GetLongArrayElement(arrayIndex, i)); break; case DataType.Short: writer.Write(_process.Process[0].GetShortArrayElement(arrayIndex, i)); break; case DataType.String: writer.Write(_process.Process[0].GetStringArrayElement(arrayIndex, i)); break; case DataType.Object: RuntimeObject obj = _process.Process[0].GetObjectArrayElement(arrayIndex, i); if (obj != null) { if (editMethod.ToLower() == "image") { if (obj is NativeObject && ((Graphics.Image)((NativeObject)obj).Object) != null) { Graphics.Image img = ((Graphics.Image)((NativeObject)obj).Object); writer.Write(true); writer.Write((byte)0); writer.Write(img.URL); writer.Write(img.Width); writer.Write(img.Height); writer.Write((short)img.VerticalSpacing); writer.Write((short)img.HorizontalSpacing); } else { writer.Write(false); } } else if (editMethod.ToLower() == "sound") { if (obj is NativeObject && ((Audio.Sound)((NativeObject)obj).Object) != null) { Audio.Sound sound = ((Audio.Sound)((NativeObject)obj).Object); writer.Write(true); writer.Write((byte)1); writer.Write(sound.URL); writer.Write(sound.Frequency); writer.Write(sound.InnerRadius); writer.Write(sound.Looping); writer.Write(sound.OuterRadius); writer.Write(sound.Pan); writer.Write(sound.Volume); writer.Write(sound.Streaming); writer.Write(sound.Positional); } else { writer.Write(false); } } else { writer.Write(false); } } else { writer.Write(false); } break; } } } } else { switch (variableSymbol.DataType.DataType) { case DataType.Bool: writer.Write(_process.Process[0].GetBooleanGlobal(variableSymbol.Identifier)); break; case DataType.Byte: writer.Write(_process.Process[0].GetByteGlobal(variableSymbol.Identifier)); break; case DataType.Double: writer.Write(_process.Process[0].GetDoubleGlobal(variableSymbol.Identifier)); break; case DataType.Float: writer.Write(_process.Process[0].GetFloatGlobal(variableSymbol.Identifier)); break; case DataType.Int: writer.Write(_process.Process[0].GetIntegerGlobal(variableSymbol.Identifier)); break; case DataType.Long: writer.Write(_process.Process[0].GetLongGlobal(variableSymbol.Identifier)); break; case DataType.Short: writer.Write(_process.Process[0].GetShortGlobal(variableSymbol.Identifier)); break; case DataType.String: string value = _process.Process[0].GetStringGlobal(variableSymbol.Identifier); writer.Write(value == null || value == "" ? "" : value); break; case DataType.Object: RuntimeObject obj = _process.Process[0].GetObjectGlobal(variableSymbol.Identifier); if (obj != null) { if (editMethod.ToLower() == "image") { if (obj is NativeObject && ((Graphics.Image)((NativeObject)obj).Object) != null) { Graphics.Image img = ((Graphics.Image)((NativeObject)obj).Object); writer.Write(true); writer.Write((byte)0); writer.Write(img.URL); writer.Write(img.Width); writer.Write(img.Height); writer.Write((short)img.VerticalSpacing); writer.Write((short)img.HorizontalSpacing); } else { writer.Write(false); } } else if (editMethod.ToLower() == "sound") { if (obj is NativeObject && ((Audio.Sound)((NativeObject)obj).Object) != null) { Audio.Sound sound = ((Audio.Sound)((NativeObject)obj).Object); writer.Write(true); writer.Write((byte)1); writer.Write(sound.URL); writer.Write(sound.Frequency); writer.Write(sound.InnerRadius); writer.Write(sound.Looping); writer.Write(sound.OuterRadius); writer.Write(sound.Pan); writer.Write(sound.Volume); writer.Write(sound.Streaming); writer.Write(sound.Positional); } else { writer.Write(false); } } else { writer.Write(false); } } else { writer.Write(false); } break; } } } } }