Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

PlannedDialog.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "PlannedDialog.h"
00010 
00011 #include "Dialog.h"
00012 #include "TimerAgent.h"
00013 
00014 //-----------------------------------------------------------------
00015 /**
00016  * Structure to store planned dialog.
00017  * @param actor who will talk
00018  * @param dialog what will talk, shared resource
00019  * @param minTime minimal time to talk when sound resource is not available
00020  */
00021 PlannedDialog::PlannedDialog(int actor, const Dialog *dialog, int minTime)
00022 {
00023     m_actor = actor;
00024     m_dialog = dialog;
00025     m_channel = -1;
00026     m_endtime = 0;
00027     m_minTime = minTime;
00028 }
00029 //-----------------------------------------------------------------
00030 /**
00031  * Run talk.
00032  * @param volume sound volume
00033  * @param loops numer of loops. 0=play once, 1=play twice, -1=play infinite
00034  */
00035 void
00036 PlannedDialog::talk(int volume, int loops)
00037 {
00038     m_channel = m_dialog->talk(volume, loops);
00039     if (loops == -1) {
00040         m_endtime = 1 << 30;
00041     }
00042     else {
00043         m_endtime = m_minTime * (loops + 1) + TimerAgent::agent()->getCycles();
00044     }
00045 }
00046 
00047 //-----------------------------------------------------------------
00048 bool
00049 PlannedDialog::equalsActor(int other) const
00050 {
00051     return m_actor == other;
00052 }
00053 //-----------------------------------------------------------------
00054 /**
00055  * Stop talking.
00056  */
00057 void
00058 PlannedDialog::killTalk()
00059 {
00060     if (isPlaying()) {
00061         Mix_HaltChannel(m_channel);
00062     }
00063 }
00064 //-----------------------------------------------------------------
00065 /**
00066  * Return true when our channel is playing and
00067  * our chunk is the last one on this channel.
00068  */
00069 bool
00070 PlannedDialog::isPlaying() const
00071 {
00072     bool result = false;
00073     if (m_channel > -1) {
00074         if (Mix_Playing(m_channel)) {
00075             result = m_dialog->equalSound(Mix_GetChunk(m_channel));
00076         }
00077     }
00078     return result;
00079 }
00080 //-----------------------------------------------------------------
00081 /**
00082  * Return true when is playing or 
00083  * return true for minimal time according subtitle length.
00084  */
00085 bool
00086 PlannedDialog::isTalking() const
00087 {
00088     bool result = false;
00089     if (m_channel > -1) {
00090         result = isPlaying();
00091     }
00092     else {
00093         result = m_endtime > TimerAgent::agent()->getCycles();
00094     }
00095 
00096     return result;
00097 }
00098 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2