PhxRuntimeEnvironment(PhxPath path, PhxPath fallbackPath) { Path = path; FallbackPath = fallbackPath; Stage = EnvStage.Init; WorldLevel = null; LuaRT = new PhxLuaRuntime(); EnvCon = new LibSWBF2.Wrappers.Container(); Loader.SetGlobalContainer(EnvCon); }
public void Run(string initScript, string initFn = null, string postLoadFn = null) { Debug.Assert(Stage == EnvStage.Init); Loader.ResetAllLoaders(); InitScriptName = initScript; InitFunctionName = initFn; PostLoadFunctionName = postLoadFn; LoadscreenHandle = ScheduleLVLRel(GetLoadscreenPath()); EnvCon.LoadLevels(); Stage = EnvStage.LoadingBase; }
void CreateScene() { Debug.Assert(Stage == EnvStage.CreateScene); // WorldLevel will be null for Main Menu if (WorldLevel != null) { RTScene.Import(WorldLevel.Get <LibSWBF2.Wrappers.World>()); } // 4 - execute post load function AFTER scene has been created if (!string.IsNullOrEmpty(PostLoadFunctionName) && LuaRT.CallLuaFunction(PostLoadFunctionName, 0) == null) { Debug.LogErrorFormat("Executing lua post load function '{0}' failed!", PostLoadFunctionName); } Stage = EnvStage.Loaded; OnLoaded?.Invoke(); }
void RunMain() { Debug.Assert(Stage == EnvStage.ExecuteMain); // 1 - execute the main script if (!string.IsNullOrEmpty(InitScriptName) && !Execute(InitScriptName)) { Debug.LogErrorFormat("Executing lua main script '{0}' failed!", InitScriptName); return; } OnExecuteMain?.Invoke(); // 2 - execute the main function -> will call ReadDataFile multiple times if (!string.IsNullOrEmpty(InitFunctionName) && LuaRT.CallLuaFunction(InitFunctionName, 0) == null) { Debug.LogErrorFormat("Executing lua main function '{0}' failed!", InitFunctionName); return; } // 3 - load the (via ReadDataFile) scheduled lvl files EnvCon.LoadLevels(); Stage = EnvStage.LoadingWorld; }
public void Tick(float deltaTime) { for (int i = 0; i < LoadingLVLs.Count; ++i) { if (LoadingLVLs[i].bIsSoundBank) { if (EnvCon.GetStatus(LoadingLVLs[i].Handle) == ELoadStatus.Loaded) { LoadingLVLs.RemoveAt(i); } else if (EnvCon.GetStatus(LoadingLVLs[i].Handle) == ELoadStatus.Failed) { Debug.LogErrorFormat("Loading '{0}' failed!", LoadingLVLs[i].PathPartial); LoadingLVLs.RemoveAt(i); } } else { // will return a Level instance ONLY IF loaded var lvl = EnvCon.GetLevel(LoadingLVLs[i].Handle); if (lvl != null) { LVLs.Add(new LevelST { Level = lvl, RelativePath = LoadingLVLs[i].PathPartial, bIsFallback = LoadingLVLs[i].bIsFallback }); if (lvl.IsWorldLevel) { if (WorldLevel != null) { Debug.LogErrorFormat("Encounterred another world lvl '{0}' in environment! Previously found world lvl: '{1}'", lvl.Name, WorldLevel.Name); } else { WorldLevel = lvl; } } // grab lvl localizations, if any Localizations.AddRange(lvl.Get <LibSWBF2.Wrappers.Localization>()); LoadingLVLs.RemoveAt(i); break; // do not further iterate altered list } } } if (Stage == EnvStage.LoadingBase) { if (LoadscreenLVL == null) { LoadscreenLVL = EnvCon.GetLevel(LoadscreenHandle); if (LoadscreenLVL != null) { var textures = LoadscreenLVL.Get <LibSWBF2.Wrappers.Texture>(); int texIdx = UnityEngine.Random.Range(0, textures.Length - 1); OnLoadscreenLoaded?.Invoke(TextureLoader.Instance.ImportUITexture(textures[texIdx].Name)); } } if (EnvCon.IsDone() && LoadingLVLs.Count == 0) { Stage = EnvStage.ExecuteMain; RunMain(); } } if (Stage == EnvStage.LoadingWorld && EnvCon.IsDone() && LoadingLVLs.Count == 0) { for (int i = 0; i < Localizations.Count; ++i) { string locName = Localizations[i].Name; if (LocalizationLookup.TryGetValue(locName, out var loc)) { loc.Add(Localizations[i]); } else { LocalizationLookup.Add(locName, new List <LibSWBF2.Wrappers.Localization> { Localizations[i] }); } } // apply queued Lua calls like "AddUnitClass" Match?.ApplySchedule(); Stage = EnvStage.CreateScene; CreateScene(); } Match?.Tick(deltaTime); RTScene.Tick(deltaTime); }
private void Initialise(bool restart) { fperiod = 100.0 / (_patch.StartFrequency * _patch.StartFrequency + 0.001); period = (int)fperiod; fmaxperiod = 100.0 / (_patch.MinimumFrequency * _patch.MinimumFrequency + 0.001); fslide = 1.0 - Math.Pow(_patch.FrequencySlide, 3.0) * 0.01; fdslide = -Math.Pow(_patch.FrequencyDeltaSlide, 3.0) * 0.000001; square_duty = 0.5f - _patch.SquareWaveDuty * 0.5f; square_slide = -_patch.SquareWaveDutySweep * 0.00005f; if (_patch.ArpMod >= 0f) { arp_mod = 1.0 - Math.Pow(_patch.ArpMod, 2.0) * 0.9; } else { arp_mod = 1.0 + Math.Pow(_patch.ArpMod, 2.0) * 10.0; } arp_time = 0; arp_limit = (int)(Math.Pow(1f - _patch.ArpSpeed, 2f) * 20000 + 32); if (_patch.ArpSpeed == 1f) { arp_limit = 0; } if (!restart) { _phase = 0; // reset filter fltp = 0f; fltdp = 0f; fltw = (float)Math.Pow(_patch.LpfCutoffFrequency, 3f) * 0.1f; fltw_d = 1f + _patch.LpfCutoffSweep * 0.0001f; fltdmp = 5f / (1f + (float)Math.Pow(_patch.LpfResonance, 2f) * 20f) * (0.01f + fltw); if (fltdmp > 0.8f) { fltdmp = 0.8f; } fltphp = 0f; flthp = (float)Math.Pow(_patch.HpfCutoffFrequency, 2f) * 0.1f; flthp_d = 1f + _patch.HpfSweep * 0.0003f; // reset vibrato vib_phase = 0f; vib_speed = (float)Math.Pow(_patch.VibratoSpeed, 2f) * 0.01f; vib_amp = _patch.VibratoDepth * 0.5f; // reset envelope env_vol = 0f; env_stage = EnvStage.Attack; env_time = 0; env_length[(int)EnvStage.Attack] = (int)(_patch.EnvelopeAttackTime * _patch.EnvelopeAttackTime * 100000f); env_length[(int)EnvStage.Sustain] = (int)(_patch.EnvelopeSustainTime * _patch.EnvelopeSustainTime * 100000f); env_length[(int)EnvStage.Decay] = (int)(_patch.EnvelopeDecayTime * _patch.EnvelopeDecayTime * 100000f); fphase = (float)Math.Pow(_patch.PhaserOffset, 2f) * 1020f; if (_patch.PhaserOffset < 0f) { fphase = -fphase; } fdphase = (float)Math.Pow(_patch.PhaserSweep, 2f) * 1f; if (_patch.PhaserSweep < 0f) { fdphase = -fdphase; } iphase = Math.Abs((int)fphase); ipp = 0; Array.Clear(phaser_buffer, 0, PhaserBufferLength); for (var i = 0; i < NoiseBufferLength; i++) { noise_buffer[i] = (float)_random.NextDouble() * 2f - 1f; } rep_time = 0; rep_limit = (int)(Math.Pow(1f - _patch.RepeatSpeed, 2f) * 20000 + 32); if (_patch.RepeatSpeed == 0f) { rep_limit = 0; } } }