ScummVM API documentation
speech.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * aint32 with this program; if not, write to the Free Software
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_SPEECH_H
27 #define SAGA2_SPEECH_H
28 
29 #include "saga2/objects.h"
30 
31 namespace Saga2 {
32 
33 #define MAX_SPEECH_PTRS 20
34 #define MAX_SAMPLES 50
35 #define CHARSPERSECOND 22
36 #define SHORTEST_DURATION TICKSPERSECOND
37 
38 void updateSpeech();
39 bool isVisible(GameObject *obj);
40 
41 #ifdef FRANKC
42 void sentenceGenerator(char *);
43 void abortSpeech();
44 void abortAllSpeeches();
45 void queueActorSpeech(
46  GameObject *obj,
47  char *text,
48  int count,
49  int32 sampleID,
50  int flags
51 );
52 #endif
53 
54 bool sayVoice(uint32 s[]);
55 
56 // REM: This function is no longer used by the speech code,
57 // but it may be useful for other things.
58 
59 extern int16 speechButtonCount; // count of speech buttons
60 
61 // Actor speech enums -- move these to include file
62 
63 enum {
64  kSpeakContinued = (1 << 0), // Append next speech
65  kSpeakNoAnimate = (1 << 1), // Don't animate speaking
66  kSpeakWait = (1 << 2), // wait until speech finished
67  kSpeakLock = (1 << 3) // lock UI while speech in progress
68 };
69 
70 class Speech {
71 private:
72  friend class SpeechTaskList;
73  friend void setNextActive();
74  friend void deleteSpeech(ObjectID id); // voice sound sample ID
75  friend void updateSpeech();
76  friend void queueActorSpeech(
77  GameObject *obj,
78  char *text,
79  int count,
80  int32 sampleID,
81  int flags
82  );
83 
84  int16 _sampleCount, // number of sound samples
85  _charCount; // number of characters in buffer
86 
87  Rect16 _bounds; // bounds of speech.
88  uint16 _penColor, // penColor to draw in
89  _outlineColor; // pen color for outline
90 
91  ObjectID _objID; // ID of speaking object
92  ThreadID _thread; // SAGA thread to wake up when done
93 
94  int16 _speechFlags; // flags from speaking
95  uint32 _sampleID[MAX_SAMPLES];// voice sound sample ID
96  char _speechBuffer[512];// longest possible speech
97 
98 public:
99  int16 _selectedButton; // which button was hit
100  gPixelMap _speechImage;
101  gPort _textPort;
102 
103 private:
104  // Reconstruct this SpeechTask from an archive buffer
105  void read(Common::InSaveFile *in);
106 
107  // Return the number of bytes needed to archive this SpeechTask
108  int32 archiveSize();
109 
110  // Archive this SpeechTask in a buffer
111  void *archive(void *buf);
112 
113  void write(Common::MemoryWriteStreamDynamic *out);
114 
115  bool setupActive(); // render speech into temp image
116  bool displayText();
117  int16 fits(int16 space);
118  void setWidth();
119  bool calcPosition(StaticPoint16 &p); // calculate position
120  void remove(); // Remove from active list
121 
122 public:
123 
124  enum SpeechFlags {
125  kSpNoAnimate = (1 << 0), // Don't animate actor
126  kSpHasVoice = (1 << 1), // The audio interface is playing this voice
127  kSpQueued = (1 << 2), // In active queue
128  kSpActive = (1 << 3), // Is current active speech
129  kSpLock = (1 << 4) // Lock UI while speaking
130  };
131 
132  // remove speech, dealloc resources
133  void dispose();
134 
135  // Append text and samples to speech
136  bool append(char *text, int32 sampID);
137 
138  // Move speech to active list
139  bool activate();
140 
141  // Set speech to wake up thread when done
142  void setWakeUp(ThreadID th) {
143  _thread = th;
144  }
145 
146  // See if its time to kill it
147  bool longEnough();
148 
149  // Abort the current speech.
150  void abortSpeech();
151 };
152 
154  friend void setNextActive();
155  friend void deleteSpeech(ObjectID id); // voice sound sample ID
156  friend void updateSpeech();
157  friend class Speech;
158  friend void queueActorSpeech(
159  GameObject *obj,
160  char *text,
161  int count,
162  int32 sampleID,
163  int flags
164  );
165 
167  _inactiveList;
168 
169  int8 _lockFlag;
170 
171  void SetLock(int newState);
172 
173 public:
174 
175  // Constructor
176  SpeechTaskList();
177 
178  // Constructor -- reconstruct from archive buffer
179  SpeechTaskList(void **buf);
180 
182 
183  // Return the number of bytes needed to archive the speech tasks
184  int32 archiveSize();
185 
186  // Create an archive of the speech tasks in an archive buffer
187  void *archive(void *buf);
188 
189  void write(Common::MemoryWriteStreamDynamic *out);
190 
191  // Cleanup the speech tasks
192  void cleanup();
193 
194  // Allocate a new speech task
195  Speech *newTask(ObjectID id, uint16 flags);
196 
197  // Find a non-active speech for a given actor
198  Speech *findSpeech(ObjectID id);
199 
200  Speech *currentActive() {
201  if (_list.size() > 0)
202  return _list.front();
203  return nullptr;
204  }
205 
206  int32 activeCount() {
207  return _list.size();
208  }
209 
210  int speechCount() {
211  return _list.size() + _inactiveList.size();
212  }
213 
214  void remove(Speech *p);
215 };
216 
217 extern SpeechTaskList &speechList;
218 
219 
220 // Initialize the speech task list
221 void initSpeechTasks();
222 
223 // Save the speech tasks in a save file
224 void saveSpeechTasks(Common::OutSaveFile *outS);
225 void loadSpeechTasks(Common::InSaveFile *in, int32 chunkSize);
226 
227 // Cleanup the speech task list
228 void cleanupSpeechTasks();
229 
230 } // end of namespace Saga2
231 
232 #endif
Definition: savefile.h:54
Definition: actor.h:32
Definition: gdraw.h:56
Definition: gdraw.h:178
Definition: list.h:44
size_type size() const
Definition: list.h:198
Definition: memstream.h:194
Definition: stream.h:745
Definition: speech.h:70
Definition: objects.h:118
t_T & front()
Definition: list.h:157
Definition: speech.h:153
Definition: rect.h:33
Definition: rect.h:290