Example #1
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            if (!VM.UseWorld) return VMPrimitiveExitCode.GOTO_TRUE;

            var operand = (VMPlaySoundOperand)args;
            FWAV fwav = context.ScopeResource.Get<FWAV>(operand.EventID);
            if (fwav == null) fwav = context.VM.Context.Globals.Resource.Get<FWAV>(operand.EventID);

            if (fwav != null)
            {
                var thread = HITVM.Get().PlaySoundEvent(fwav.Name);
                if (thread != null)
                {
                    var owner = (operand.StackObjAsSource)?context.StackObject:context.Caller;
                    if (owner == null) return VMPrimitiveExitCode.GOTO_TRUE;
                    if (!thread.AlreadyOwns(owner.ObjectID)) thread.AddOwner(owner.ObjectID);

                    if (owner is VMAvatar && thread is HITThread) ((VMAvatar)owner).SubmitHITVars((HITThread)thread);

                    var entry = new VMSoundEntry()
                    {
                        Sound = thread,
                        Pan = !operand.NoPan,
                        Zoom = !operand.NoZoom,
                        Loop = operand.Loop,
                        Name = fwav.Name
                    };
                    owner.SoundThreads.Add(entry);
                    if (owner.Thread != null) owner.TickSounds();
                }
            }

            return VMPrimitiveExitCode.GOTO_TRUE;
        }
Example #2
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context)
        {
            var operand = context.GetCurrentOperand<VMPlaySoundOperand>();
            FWAV fwav = context.CodeOwner.Get<FWAV>(operand.EventID);
            if (fwav == null) fwav = context.VM.Context.Globals.Resource.Get<FWAV>(operand.EventID);

            if (fwav != null)
            {
                var thread = HITVM.Get().PlaySoundEvent(fwav.Name);
                if (thread != null)
                {
                    var owner = (operand.StackObjAsSource)?context.StackObject:context.Caller;

                    if (!thread.AlreadyOwns(owner.ObjectID)) thread.AddOwner(owner.ObjectID);

                    var entry = new VMSoundEntry()
                    {
                        Thread = thread,
                        Pan = !operand.NoPan,
                        Zoom = !operand.NoZoom,
                        Loop = operand.Loop,
                        Name = fwav.Name
                    };
                    owner.SoundThreads.Add(entry);
                    owner.TickSounds();
                }
            }

            return VMPrimitiveExitCode.GOTO_TRUE;
        }
Example #3
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            if (!VM.UseWorld)
            {
                return(VMPrimitiveExitCode.GOTO_TRUE);
            }

            var  operand = (VMPlaySoundOperand)args;
            FWAV fwav    = context.ScopeResource.Get <FWAV>(operand.EventID);

            if (fwav == null)
            {
                fwav = context.VM.Context.Globals.Resource.Get <FWAV>(operand.EventID);
            }

            var owner = (operand.StackObjAsSource) ? context.StackObject : context.Caller;

            if (fwav != null && owner.SoundThreads.FirstOrDefault(x => x.Name == fwav.Name) == null)
            {
                var thread = HITVM.Get().PlaySoundEvent(fwav.Name);
                if (thread != null)
                {
                    if (owner == null)
                    {
                        return(VMPrimitiveExitCode.GOTO_TRUE);
                    }
                    if (!thread.AlreadyOwns(owner.ObjectID))
                    {
                        thread.AddOwner(owner.ObjectID);
                    }

                    if (owner is VMAvatar && thread is HITThread)
                    {
                        ((VMAvatar)owner).SubmitHITVars((HITThread)thread);
                    }

                    var entry = new VMSoundEntry()
                    {
                        Sound = thread,
                        Pan   = !operand.NoPan,
                        Zoom  = !operand.NoZoom,
                        Loop  = operand.Loop,
                        Name  = fwav.Name
                    };
                    owner.SoundThreads.Add(entry);
                    if (owner.Thread != null)
                    {
                        owner.TickSounds();
                    }
                }
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
Example #4
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context)
        {
            var  operand = context.GetCurrentOperand <VMPlaySoundOperand>();
            FWAV fwav    = context.CodeOwner.Get <FWAV>(operand.EventID);

            if (fwav == null)
            {
                fwav = context.VM.Context.Globals.Resource.Get <FWAV>(operand.EventID);
            }

            if (fwav != null)
            {
                var thread = HITVM.Get().PlaySoundEvent(fwav.Name);
                if (thread != null)
                {
                    var owner = (operand.StackObjAsSource)?context.StackObject:context.Caller;

                    if (!thread.AlreadyOwns(owner.ObjectID))
                    {
                        thread.AddOwner(owner.ObjectID);
                    }

                    var entry = new VMSoundEntry()
                    {
                        Thread = thread,
                        Pan    = !operand.NoPan,
                        Zoom   = !operand.NoZoom,
                        Loop   = operand.Loop,
                        Name   = fwav.Name
                    };
                    owner.SoundThreads.Add(entry);
                    owner.TickSounds();
                }
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
Example #5
0
 public VMSoundTransfer(short id, uint guid, VMSoundEntry sfx)
 {
     SourceID   = id;
     SourceGUID = guid;
     SFX        = sfx;
 }
Example #6
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            if (!VM.UseWorld)
            {
                return(VMPrimitiveExitCode.GOTO_TRUE);
            }

            var  operand = (VMPlaySoundOperand)args;
            FWAV fwav    = context.ScopeResource.Get <FWAV>(operand.EventID);

            if (fwav == null)
            {
                fwav = context.VM.Context.Globals.Resource.Get <FWAV>(operand.EventID);
            }

            var owner = (operand.StackObjAsSource) ? context.StackObject : context.Caller;

            if (owner == null)
            {
                return(VMPrimitiveExitCode.GOTO_TRUE);
            }
            var lastThread = owner.SoundThreads.FirstOrDefault(x => x?.Name == fwav?.Name);

            if ((lastThread?.Sound as HITThread)?.Interruptable == true)
            {
                lastThread = null;
            }
            if (fwav != null && lastThread == null)
            {
                var thread = HITVM.Get.PlaySoundEvent(fwav.Name);
                if (thread != null)
                {
                    if (owner == null)
                    {
                        return(VMPrimitiveExitCode.GOTO_TRUE);
                    }
                    if (!thread.AlreadyOwns(owner.ObjectID))
                    {
                        thread.AddOwner(owner.ObjectID);
                    }

                    var entry = new VMSoundEntry()
                    {
                        Sound = thread,
                        Pan   = !operand.NoPan,
                        Zoom  = !operand.NoZoom,
                        Loop  = operand.Loop || fwav.Name == "piano_play",
                        Name  = fwav.Name
                    };

                    if (thread is HITThread)
                    {
                        if (!((HITThread)thread).LoopDefined || fwav.Name == "piano_play")
                        {
                            ((HITThread)thread).Loop       = entry.Loop;
                            ((HITThread)thread).HasSetLoop = fwav.Name == "piano_play";
                        }
                        owner.SubmitHITVars((HITThread)thread);
                    }

                    owner.SoundThreads.Add(entry);
                    context.VM.SoundEntities.Add(owner);
                    if (owner.Thread != null)
                    {
                        owner.TickSounds();
                    }
                }
            }

            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
Example #7
0
        public void TickSounds()
        {
            if (!UseWorld) return;
            if (Thread != null)
            {
                var worldState = Thread.Context.World.State;
                var worldSpace = worldState.WorldSpace;
                var scrPos = WorldUI.GetScreenPos(worldState);
                scrPos -= new Vector2(worldSpace.WorldPxWidth/2, worldSpace.WorldPxHeight/2);
                for (int i = 0; i < SoundThreads.Count; i++)
                {
                    if (SoundThreads[i].Sound.Dead)
                    {
                        var old = SoundThreads[i];
                        SoundThreads.RemoveAt(i--);
                        if (old.Loop)
                        {
                            var thread = HITVM.Get().PlaySoundEvent(old.Name);
                            if (thread != null)
                            {
                                var owner = this;
                                if (!thread.AlreadyOwns(owner.ObjectID)) thread.AddOwner(owner.ObjectID);

                                var entry = new VMSoundEntry()
                                {
                                    Sound = thread,
                                    Pan = old.Pan,
                                    Zoom = old.Zoom,
                                    Loop = old.Loop,
                                    Name = old.Name
                                };
                                owner.SoundThreads.Add(entry);
                            }
                        }
                        continue;
                    }

                    float pan = (SoundThreads[i].Pan) ? Math.Max(-1.0f, Math.Min(1.0f, scrPos.X / worldSpace.WorldPxWidth)) : 0;
                    float volume = (SoundThreads[i].Pan) ? 1 - (float)Math.Max(0, Math.Min(1, Math.Sqrt(scrPos.X * scrPos.X + scrPos.Y * scrPos.Y) / worldSpace.WorldPxWidth)) : 1;

                    if (SoundThreads[i].Zoom) volume /= 4 - (int)worldState.Zoom;
                    if (Position.Level > worldState.Level) volume /= 4;
                    else if (Position.Level != worldState.Level) volume /= 2;

                    SoundThreads[i].Sound.SetVolume(volume, pan);

                }
            }
        }