aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llagentpilot.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llagentpilot.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llagentpilot.cpp')
-rw-r--r--linden/indra/newview/llagentpilot.cpp269
1 files changed, 269 insertions, 0 deletions
diff --git a/linden/indra/newview/llagentpilot.cpp b/linden/indra/newview/llagentpilot.cpp
new file mode 100644
index 0000000..45c1770
--- /dev/null
+++ b/linden/indra/newview/llagentpilot.cpp
@@ -0,0 +1,269 @@
1/**
2 * @file llagentpilot.cpp
3 * @brief LLAgentPilot class implementation
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include <iostream>
31#include <fstream>
32#include <iomanip>
33
34#include "llagentpilot.h"
35#include "llagent.h"
36#include "llframestats.h"
37#include "viewer.h"
38#include "llviewercontrol.h"
39
40LLAgentPilot gAgentPilot;
41
42BOOL LLAgentPilot::sLoop = TRUE;
43
44LLAgentPilot::LLAgentPilot()
45{
46 mRecording = FALSE;
47 mPlaying = FALSE;
48 mStarted = FALSE;
49 mNumRuns = -1;
50}
51
52LLAgentPilot::~LLAgentPilot()
53{
54}
55
56void LLAgentPilot::load(const char *filename)
57{
58 llifstream file;
59
60 file.open(filename);
61
62 if (!file)
63 {
64 llinfos << "Couldn't open " << filename << ", aborting agentpilot load!" << llendl;
65 return;
66 }
67 else
68 {
69 llinfos << "Opening pilot file " << filename << llendl;
70 }
71
72 S32 num_actions;
73
74 file >> num_actions;
75
76 S32 i;
77 for (i = 0; i < num_actions; i++)
78 {
79 S32 action_type;
80 Action new_action;
81 file >> new_action.mTime >> action_type;
82 file >> new_action.mTarget.mdV[VX] >> new_action.mTarget.mdV[VY] >> new_action.mTarget.mdV[VZ];
83 new_action.mType = (EActionType)action_type;
84 mActions.put(new_action);
85 }
86
87 file.close();
88}
89
90void LLAgentPilot::save(const char *filename)
91{
92 llofstream file;
93 file.open(filename);
94
95 if (!file)
96 {
97 llinfos << "Couldn't open " << filename << ", aborting agentpilot save!" << llendl;
98 }
99
100 file << mActions.count() << '\n';
101
102 S32 i;
103 for (i = 0; i < mActions.count(); i++)
104 {
105 file << mActions[i].mTime << "\t" << mActions[i].mType << "\t";
106 file << std::setprecision(32) << mActions[i].mTarget.mdV[VX] << "\t" << mActions[i].mTarget.mdV[VY] << "\t" << mActions[i].mTarget.mdV[VZ] << '\n';
107 }
108
109 file.close();
110}
111
112void LLAgentPilot::startRecord()
113{
114 mActions.reset();
115 mTimer.reset();
116 addAction(STRAIGHT);
117 mRecording = TRUE;
118}
119
120void LLAgentPilot::stopRecord()
121{
122 gAgentPilot.addAction(STRAIGHT);
123 gAgentPilot.save(gSavedSettings.getString("StatsPilotFile").c_str());
124 mRecording = FALSE;
125}
126
127void LLAgentPilot::addAction(enum EActionType action_type)
128{
129 llinfos << "Adding waypoint: " << gAgent.getPositionGlobal() << llendl;
130 Action action;
131 action.mType = action_type;
132 action.mTarget = gAgent.getPositionGlobal();
133 action.mTime = mTimer.getElapsedTimeF32();
134 mLastRecordTime = (F32)action.mTime;
135 mActions.put(action);
136}
137
138void LLAgentPilot::startPlayback()
139{
140 if (!mPlaying)
141 {
142 mPlaying = TRUE;
143 mCurrentAction = 0;
144 mTimer.reset();
145
146 if (mActions.count())
147 {
148 llinfos << "Starting playback, moving to waypoint 0" << llendl;
149 gAgent.startAutoPilotGlobal(mActions[0].mTarget);
150 mStarted = FALSE;
151 }
152 else
153 {
154 llinfos << "No autopilot data, cancelling!" << llendl;
155 mPlaying = FALSE;
156 }
157 }
158}
159
160void LLAgentPilot::stopPlayback()
161{
162 if (mPlaying)
163 {
164 mPlaying = FALSE;
165 mCurrentAction = 0;
166 mTimer.reset();
167 gAgent.stopAutoPilot();
168 }
169}
170
171void LLAgentPilot::updateTarget()
172{
173 if (mPlaying)
174 {
175 if (mCurrentAction < mActions.count())
176 {
177 if (0 == mCurrentAction)
178 {
179 if (gAgent.getAutoPilot())
180 {
181 // Wait until we get to the first location before starting.
182 return;
183 }
184 else
185 {
186 if (!mStarted)
187 {
188 llinfos << "At start, beginning playback" << llendl;
189 mTimer.reset();
190 LLFrameStats::startLogging(NULL);
191 mStarted = TRUE;
192 }
193 }
194 }
195 if (mTimer.getElapsedTimeF32() > mActions[mCurrentAction].mTime)
196 {
197 //gAgent.stopAutoPilot();
198 mCurrentAction++;
199
200 if (mCurrentAction < mActions.count())
201 {
202 gAgent.startAutoPilotGlobal(mActions[mCurrentAction].mTarget);
203 }
204 else
205 {
206 stopPlayback();
207 LLFrameStats::stopLogging(NULL);
208 mNumRuns--;
209 if (sLoop)
210 {
211 if ((mNumRuns < 0) || (mNumRuns > 0))
212 {
213 llinfos << "Looping, restarting playback" << llendl;
214 startPlayback();
215 }
216 else if (mQuitAfterRuns)
217 {
218 llinfos << "Done with all runs, quitting viewer!" << llendl;
219 app_force_quit(NULL);
220 }
221 else
222 {
223 llinfos << "Done with all runs, disabling pilot" << llendl;
224 stopPlayback();
225 }
226 }
227 }
228 }
229 }
230 else
231 {
232 stopPlayback();
233 }
234 }
235 else if (mRecording)
236 {
237 if (mTimer.getElapsedTimeF32() - mLastRecordTime > 1.f)
238 {
239 addAction(STRAIGHT);
240 }
241 }
242}
243
244// static
245void LLAgentPilot::startRecord(void *)
246{
247 gAgentPilot.startRecord();
248}
249
250void LLAgentPilot::saveRecord(void *)
251{
252 gAgentPilot.stopRecord();
253}
254
255void LLAgentPilot::addWaypoint(void *)
256{
257 gAgentPilot.addAction(STRAIGHT);
258}
259
260void LLAgentPilot::startPlayback(void *)
261{
262 gAgentPilot.mNumRuns = -1;
263 gAgentPilot.startPlayback();
264}
265
266void LLAgentPilot::stopPlayback(void *)
267{
268 gAgentPilot.stopPlayback();
269}