| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "PlannedDialog.h" |
| 10 |
|
| 11 |
#include "Dialog.h" |
| 12 |
#include "TimerAgent.h" |
| 13 |
|
| 14 |
//----------------------------------------------------------------- |
| 15 |
/** |
| 16 |
* Structure to store planned dialog. |
| 17 |
* @param actor who will talk |
| 18 |
* @param dialog what will talk, shared resource |
| 19 |
* @param minTime minimal time to talk when sound resource is not available |
| 20 |
*/ |
| 21 |
PlannedDialog::PlannedDialog(int actor, const Dialog *dialog, int minTime) |
| 22 |
{ |
| 23 |
m_actor = actor; |
| 24 |
m_dialog = dialog; |
| 25 |
m_channel = -1; |
| 26 |
m_endtime = 0; |
| 27 |
m_minTime = minTime; |
| 28 |
} |
| 29 |
//----------------------------------------------------------------- |
| 30 |
/** |
| 31 |
* Run talk. |
| 32 |
* @param volume sound volume |
| 33 |
* @param loops numer of loops. 0=play once, 1=play twice, -1=play infinite |
| 34 |
*/ |
| 35 |
void |
| 36 |
PlannedDialog::talk(int volume, int loops) |
| 37 |
{ |
| 38 |
m_channel = m_dialog->talk(volume, loops); |
| 39 |
if (loops == -1) { |
| 40 |
m_endtime = 1 << 30; |
| 41 |
} |
| 42 |
else { |
| 43 |
m_endtime = m_minTime * (loops + 1) + TimerAgent::agent()->getCycles(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
//----------------------------------------------------------------- |
| 48 |
bool |
| 49 |
PlannedDialog::equalsActor(int other) const |
| 50 |
{ |
| 51 |
return m_actor == other; |
| 52 |
} |
| 53 |
//----------------------------------------------------------------- |
| 54 |
/** |
| 55 |
* Stop talking. |
| 56 |
*/ |
| 57 |
void |
| 58 |
PlannedDialog::killTalk() |
| 59 |
{ |
| 60 |
if (isPlaying()) { |
| 61 |
Mix_HaltChannel(m_channel); |
| 62 |
} |
| 63 |
} |
| 64 |
//----------------------------------------------------------------- |
| 65 |
/** |
| 66 |
* Return true when our channel is playing and |
| 67 |
* our chunk is the last one on this channel. |
| 68 |
*/ |
| 69 |
bool |
| 70 |
PlannedDialog::isPlaying() const |
| 71 |
{ |
| 72 |
bool result = false; |
| 73 |
if (m_channel > -1) { |
| 74 |
if (Mix_Playing(m_channel)) { |
| 75 |
result = m_dialog->equalSound(Mix_GetChunk(m_channel)); |
| 76 |
} |
| 77 |
} |
| 78 |
return result; |
| 79 |
} |
| 80 |
//----------------------------------------------------------------- |
| 81 |
/** |
| 82 |
* Return true when is playing or |
| 83 |
* return true for minimal time according subtitle length. |
| 84 |
*/ |
| 85 |
bool |
| 86 |
PlannedDialog::isTalking() const |
| 87 |
{ |
| 88 |
bool result = false; |
| 89 |
if (m_channel > -1) { |
| 90 |
result = isPlaying(); |
| 91 |
} |
| 92 |
else { |
| 93 |
result = m_endtime > TimerAgent::agent()->getCycles(); |
| 94 |
} |
| 95 |
|
| 96 |
return result; |
| 97 |
} |
| 98 |
|