private static void processYaks(int timeNow, int elapsedTime) { for (int i = 0; i < _yaks.Count; i++) { if (_yaks[i] != null) { if (_yaks[i].IsPlaying == false) { // done playing the yak, so we can remove it _yaks[i] = null; } else { int timeSinceStart = timeNow - _yaks[i].TimeAtPlayStart; int startIndex, count; AnimationResource.GetAllFramesSince(_yaks[i].Gk3Section, timeSinceStart, elapsedTime, AnimationResource.MillisecondsPerFrame, out startIndex, out count); Actor actor = null; for (int lineIndex = startIndex; lineIndex < startIndex + count; lineIndex++) { string param1 = _yaks[i].Gk3Section.Lines[lineIndex].Params[0].StringValue; if (param1.Equals("LIPSYNCH", StringComparison.OrdinalIgnoreCase)) { if (actor == null) { actor = SceneManager.GetActor(_yaks[i].Speaker); if (actor == null) { break; // couldn't find this actor for some reason, so give up } } string param3 = _yaks[i].Gk3Section.Lines[lineIndex].Params[2].StringValue; actor.SetMouth(param3); } } } } } }
private void play(int timeSinceStart, int duration) { int startIndex, count; // play model visibility if (_modelVisibilitySection != null) { GetAllFramesSince(_modelVisibilitySection, timeSinceStart, duration, MillisecondsPerFrame, out startIndex, out count); for (int i = startIndex; i < startIndex + count; i++) { string model = _modelVisibilitySection.Lines[i].Params[0].StringValue; string onoff = _modelVisibilitySection.Lines[i].Params[1].StringValue; bool visible = onoff.Equals("on", StringComparison.OrdinalIgnoreCase); SceneManager.SetSceneModelVisibility(model, visible); } } if (_modelTexturesSection != null) { GetAllFramesSince(_modelTexturesSection, timeSinceStart, duration, MillisecondsPerFrame, out startIndex, out count); for (int i = startIndex; i < startIndex + count; i++) { string model = _modelTexturesSection.Lines[i].Params[0].StringValue; int meshIndex = _modelTexturesSection.Lines[i].Params[1].IntValue; int groupIndex = _modelTexturesSection.Lines[i].Params[2].IntValue; string texture = _modelTexturesSection.Lines[i].Params[3].StringValue; SceneManager.SetModelTexture(model, meshIndex, groupIndex, texture); } } // play sounds if (_soundSection != null) { GetAllFramesSince(_soundSection, timeSinceStart, duration, MillisecondsPerFrame, out startIndex, out count); for (int i = startIndex; i < startIndex + count; i++) { // the indices in the little sound list *should* match "i" Sound.SoundManager.PlaySound2DToChannel(_sounds[i], Sound.SoundTrackChannel.SFX); } } // play the dialog if (_gk3Section != null) { GetAllFramesSince(_gk3Section, timeSinceStart, duration, MillisecondsPerFrame, out startIndex, out count); for (int i = startIndex; i < startIndex + count; i++) { string command = _gk3Section.Lines[i].Params[0].StringValue; if (command.Equals("DIALOGUE", StringComparison.OrdinalIgnoreCase)) { string yak = _gk3Section.Lines[i].Params[1].StringValue; DialogManager.PlayDialogue(yak, 1, yak.StartsWith("E", StringComparison.OrdinalIgnoreCase), false); } else if (command.Equals("LIPSYNCH", StringComparison.OrdinalIgnoreCase)) { string param2 = _gk3Section.Lines[i].Params[1].StringValue; Actor actor = SceneManager.GetActor(param2); if (actor == null) { continue; // couldn't find this actor for some reason, so give up } string param3 = _gk3Section.Lines[i].Params[2].StringValue; actor.SetMouth(param3); } } } // add any new ACT files if (_actionSection != null) { GetAllFramesSince(_actionSection, timeSinceStart, duration, MillisecondsPerFrame, out startIndex, out count); for (int i = startIndex; i < startIndex + count; i++) { string actName = _actionSection.Lines[i].Params[0].StringValue; if (actName.Length > 31) { actName = actName.Substring(0, 31); // we can get FileNotFound without this } if (actName.EndsWith(".ACT", StringComparison.OrdinalIgnoreCase) == false) { actName += ".ACT"; } MomAct act = new MomAct(); act.Act = _content.Load <Graphics.ActResource>(actName); act.Model = SceneManager.GetSceneModel(act.Act.ModelName); // check if this is an absolute animation or contains a transformation if (_actionSection.Lines[i].Params.Count > 1) { act.IsAbsolute = true; Math.Matrix transform = Math.Matrix.Translate(-_actionSection.Lines[i].Params[1].FloatValue, -_actionSection.Lines[i].Params[3].FloatValue, -_actionSection.Lines[i].Params[2].FloatValue); transform = transform * Math.Matrix.RotateY(Utils.DegreesToRadians(-_actionSection.Lines[i].Params[4].FloatValue + _actionSection.Lines[i].Params[8].FloatValue)); transform = transform * Math.Matrix.Translate(_actionSection.Lines[i].Params[5].FloatValue, _actionSection.Lines[i].Params[7].FloatValue, _actionSection.Lines[i].Params[6].FloatValue); act.Transformation = transform; } else { act.Transformation = Math.Matrix.Identity; } if (act.Model == null) { continue; } // add the act file to the list bool added = false; for (int j = 0; j < _acts.Count; j++) { if (_acts[j].HasValue == false) { _acts[j] = act; added = true; break; } } if (added == false) { _acts.Add(act); } } } // animate models using ACT files for (int i = 0; i < _acts.Count; i++) { if (_acts[i].HasValue) { _acts[i].Value.Model.TempTransform = _acts[i].Value.Transformation; if (_acts[i].Value.Act.Animate(_acts[i].Value.Model, timeSinceStart, duration, true, _acts[i].Value.IsAbsolute) == false) { _acts[i] = null; } } } }