summaryrefslogtreecommitdiff
path: root/NET/worlds/console/BlackBox.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/BlackBox.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/BlackBox.java')
-rw-r--r--NET/worlds/console/BlackBox.java474
1 files changed, 474 insertions, 0 deletions
diff --git a/NET/worlds/console/BlackBox.java b/NET/worlds/console/BlackBox.java
new file mode 100644
index 0000000..bd44e80
--- /dev/null
+++ b/NET/worlds/console/BlackBox.java
@@ -0,0 +1,474 @@
+/* */ package NET.worlds.console;
+/* */
+/* */ import NET.worlds.core.IniFile;
+/* */ import NET.worlds.core.Std;
+/* */ import NET.worlds.network.Galaxy;
+/* */ import NET.worlds.network.URL;
+/* */ import NET.worlds.scape.Camera;
+/* */ import NET.worlds.scape.Drone;
+/* */ import NET.worlds.scape.FrameEvent;
+/* */ import NET.worlds.scape.FrameHandler;
+/* */ import NET.worlds.scape.HoloPilot;
+/* */ import NET.worlds.scape.Pilot;
+/* */ import NET.worlds.scape.Point3Temp;
+/* */ import NET.worlds.scape.Postrenderable;
+/* */ import NET.worlds.scape.SmoothDriver;
+/* */ import NET.worlds.scape.Sound;
+/* */ import NET.worlds.scape.SoundPlayer;
+/* */ import NET.worlds.scape.WMPSoundPlayer;
+/* */ import NET.worlds.scape.WavSoundPlayer;
+/* */ import java.awt.FileDialog;
+/* */ import java.awt.Frame;
+/* */ import java.io.DataInputStream;
+/* */ import java.io.DataOutputStream;
+/* */ import java.io.EOFException;
+/* */ import java.io.File;
+/* */ import java.io.FileInputStream;
+/* */ import java.io.FileOutputStream;
+/* */ import java.io.PrintStream;
+/* */ import java.util.Enumeration;
+/* */ import java.util.Properties;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class BlackBox
+/* */ implements BlackBoxCallback, FrameHandler, Postrenderable
+/* */ {
+/* 41 */ private static BlackBox instance = new BlackBox();
+/* */
+/* */ public static BlackBox getInstance() {
+/* 44 */ return instance;
+/* */ }
+/* */
+/* 47 */ private boolean disable = IniFile.gamma().getIniInt("disableRecorder", 0) == 1;
+/* */
+/* 49 */ private String autoFile = null;
+/* 50 */ private SoundPlayer autoSound = null;
+/* */ static final int PLAYING = 0;
+/* */
+/* 53 */ private BlackBox() { this.state = 2;
+/* 54 */ this.commandList = new Vector();
+/* 55 */ this.pendingCommand = 0;
+/* */
+/* 57 */ this.autoFile = IniFile.override().getIniString("AutoPlaybackFile", "");
+/* 58 */ if (!this.autoFile.equals("")) {
+/* 59 */ play();
+/* */ } else {
+/* 61 */ this.autoFile = null;
+/* */ }
+/* */
+/* 64 */ String soundFile = IniFile.override().getIniString("AutoPlaybackSound",
+/* 65 */ "");
+/* 66 */ if (!soundFile.equals("")) {
+/* 67 */ Sound owner = new Sound(URL.make(soundFile));
+/* 68 */ if (soundFile.toLowerCase().endsWith(".wav")) {
+/* 69 */ this.autoSound = new WavSoundPlayer(owner);
+/* */ } else {
+/* 71 */ this.autoSound = new WMPSoundPlayer(owner);
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */ public void finalize()
+/* */ {
+/* 78 */ stop();
+/* */ }
+/* */
+/* */ public void postrender(Camera cam) {
+/* 82 */ if (this.disable) {
+/* 83 */ return;
+/* */ }
+/* */
+/* 86 */ if (Std.getSynchronizedTime() % 2 == 0) {
+/* 87 */ return;
+/* */ }
+/* 89 */ if (isPlaying()) {
+/* 90 */ cam.nDrawText(Console.message("PLAY"), 10, 10, 18, 16711680);
+/* 91 */ } else if (isRecording()) {
+/* 92 */ cam.nDrawText(Console.message("REC"), 10, 10, 18, 16711680);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */ static final int RECORDING = 1;
+/* */
+/* */ static final int STOPPED = 2;
+/* */
+/* */ private int state;
+/* */
+/* */ static final int CHATCMD = 0;
+/* */
+/* */ static final int TELEPORTCMD = 1;
+/* */ static final int ACTORLISTCMD = 2;
+/* */ static final int MOVEDRONECMD = 3;
+/* */ static final int OBJCLICKEDCMD = 4;
+/* */ static final int APPEARDRONECMD = 5;
+/* */ static final int DISAPPEARDRONECMD = 6;
+/* */ static final int DRONEBITMAPCMD = 7;
+/* */ static final int DRONEDELTACMD = 8;
+/* */ static final int ANIMATECMD = 9;
+/* */ public static final String PilotID = "@Pilot";
+/* */ private Vector<BlackBoxCommand> commandList;
+/* */ private int commandIdx;
+/* */ private long basetime;
+/* */ static final int NOCMD = 0;
+/* */ static final int PLAYCMD = 1;
+/* */ static final int RECCMD = 2;
+/* */ static final int STOPCMD = 3;
+/* */ private int pendingCommand;
+/* */ static final int FILE_VERSION = 1;
+/* */ public synchronized void record()
+/* */ {
+/* 126 */ this.pendingCommand = 2;
+/* */ }
+/* */
+/* */ private boolean doRecord() {
+/* 130 */ if (this.state != 2) {
+/* 131 */ stop();
+/* */ }
+/* 133 */ this.commandList.removeAllElements();
+/* */
+/* */
+/* 136 */ this.basetime = Std.getFastTime();
+/* */
+/* */
+/* 139 */ String url = "";
+/* 140 */ Pilot pilot = Pilot.getActive();
+/* 141 */ if (pilot == null) {
+/* 142 */ return false;
+/* */ }
+/* 144 */ url = pilot.getURL();
+/* */
+/* 146 */ this.state = 1;
+/* */
+/* 148 */ submitEvent(new BBTeleportCommand(url));
+/* */
+/* */
+/* 151 */ URL avatar = Console.getActive().getAvatarName();
+/* 152 */ if (avatar != null) {
+/* 153 */ submitEvent(new BBDroneBitmapCommand("@Pilot",
+/* 154 */ avatar.toString()));
+/* */ }
+/* */
+/* */
+/* 158 */ ArmyOfZombies.instance().zombify();
+/* */
+/* 160 */ return true;
+/* */ }
+/* */
+/* */ public synchronized void play() {
+/* 164 */ this.pendingCommand = 1;
+/* */ }
+/* */
+/* */ public synchronized void play(URL recFile) {
+/* 168 */ this.autoFile = recFile.unalias();
+/* 169 */ this.pendingCommand = 1;
+/* */ }
+/* */
+/* */ private void doPlay() {
+/* 173 */ if (this.state != 2) {
+/* 174 */ stop();
+/* */ }
+/* 176 */ if (!restore()) {
+/* 177 */ return;
+/* */ }
+/* 179 */ Galaxy.forceOffline(false);
+/* 180 */ Console.getActive().setChatname("");
+/* */
+/* 182 */ Pilot p = Pilot.getActive();
+/* 183 */ if ((p instanceof HoloPilot)) {
+/* 184 */ HoloPilot hp = (HoloPilot)p;
+/* 185 */ hp.removeSmoothDriver();
+/* */ }
+/* */
+/* 188 */ if (this.autoSound != null) {
+/* 189 */ this.autoSound.start(1);
+/* 190 */ this.autoSound = null;
+/* */ }
+/* */
+/* 193 */ this.commandIdx = 0;
+/* */
+/* 195 */ this.basetime = Std.getFastTime();
+/* */
+/* 197 */ this.state = 0;
+/* */ }
+/* */
+/* */ public void commandCompleted(BlackBoxCommand c, boolean ok) {
+/* 201 */ if (ok) {
+/* 202 */ this.commandIdx += 1;
+/* */ } else {
+/* 204 */ System.out.println("Failed command!");
+/* 205 */ stop();
+/* */ }
+/* */ }
+/* */
+/* */ public boolean handle(FrameEvent e) {
+/* 210 */ if (this.disable) {
+/* 211 */ return false;
+/* */ }
+/* 213 */ switch (this.pendingCommand) {
+/* */ case 1:
+/* 215 */ doPlay();
+/* 216 */ this.pendingCommand = 0;
+/* 217 */ break;
+/* */
+/* */ case 2:
+/* 220 */ doRecord();
+/* 221 */ this.pendingCommand = 0;
+/* 222 */ break;
+/* */
+/* */ case 3:
+/* 225 */ doStop();
+/* 226 */ this.pendingCommand = 0;
+/* */ }
+/* */
+/* */
+/* 230 */ if (isPlaying()) {
+/* 231 */ if (this.commandIdx >= this.commandList.size()) {
+/* 232 */ stop();
+/* 233 */ return false;
+/* */ }
+/* */
+/* 236 */ long elapsedTime = Std.getFastTime() - this.basetime;
+/* */
+/* 238 */ BlackBoxCommand c =
+/* 239 */ (BlackBoxCommand)this.commandList.elementAt(this.commandIdx);
+/* 240 */ if (c.startTime <= elapsedTime) {
+/* 241 */ c.execute(this);
+/* */ }
+/* 243 */ Pilot p = Pilot.getActive();
+/* 244 */ if ((p instanceof HoloPilot)) {
+/* 245 */ HoloPilot hp = (HoloPilot)p;
+/* 246 */ Drone d = hp.getInternalDrone();
+/* 247 */ if (d != null) {
+/* 248 */ d.interpolate(e.time, 2000, p);
+/* 249 */ p.setZ(p.getPosition().z +
+/* 250 */ hp.getSmoothDriver().getEyeHeight());
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* 255 */ return false;
+/* */ }
+/* */
+/* */ public boolean isRecording() {
+/* 259 */ return this.state == 1;
+/* */ }
+/* */
+/* */ public boolean isPlaying() {
+/* 263 */ return this.state == 0;
+/* */ }
+/* */
+/* */ public void submitEvent(BlackBoxCommand c) {
+/* 267 */ if (this.disable) {
+/* 268 */ return;
+/* */ }
+/* 270 */ if (!isRecording()) {
+/* 271 */ return;
+/* */ }
+/* 273 */ c.timestamp(this.basetime);
+/* 274 */ this.commandList.addElement(c);
+/* */ }
+/* */
+/* */ public synchronized void stop() {
+/* 278 */ this.pendingCommand = 3;
+/* */ }
+/* */
+/* */ private void doStop() {
+/* 282 */ if (this.state == 2) {
+/* 283 */ return;
+/* */ }
+/* 285 */ if (isRecording()) {
+/* 286 */ save();
+/* */ }
+/* */
+/* 289 */ if (isPlaying())
+/* */ {
+/* 291 */ ArmyOfZombies.instance().killZombies();
+/* */
+/* 293 */ Pilot p = Pilot.getActive();
+/* 294 */ if ((p instanceof HoloPilot)) {
+/* 295 */ HoloPilot hp = (HoloPilot)p;
+/* 296 */ hp.returnSmoothDriver();
+/* */ }
+/* */
+/* */
+/* 300 */ Console c = Console.getActive();
+/* 301 */ if ((c instanceof DefaultConsole)) {
+/* 302 */ DefaultConsole dc = (DefaultConsole)c;
+/* 303 */ dc.getGalaxy().localForceOnline();
+/* 304 */ dc.getGalaxy().waitForConnection(dc);
+/* */ }
+/* */ }
+/* */
+/* 308 */ this.state = 2;
+/* */ }
+/* */
+/* */
+/* */ private void save()
+/* */ {
+/* 314 */ Frame parent = Console.getFrame();
+/* */
+/* 316 */ Properties p = System.getProperties();
+/* 317 */ String oldDir = p.getProperty("user.dir");
+/* */
+/* 319 */ FileDialog fd = new FileDialog(parent,
+/* 320 */ Console.message("Save-recording"), 1);
+/* 321 */ fd.setFile("record.rec");
+/* 322 */ fd.setVisible(true);
+/* */
+/* 324 */ String fname = fd.getFile();
+/* 325 */ String path = fd.getDirectory();
+/* */
+/* 327 */ p.remove("user.dir");
+/* 328 */ p.put("user.dir", oldDir);
+/* 329 */ System.setProperties(p);
+/* */
+/* 331 */ if (fname == null) {
+/* 332 */ return;
+/* */ }
+/* 334 */ File f = new File(path, fname);
+/* */ try {
+/* 336 */ FileOutputStream fos = new FileOutputStream(f);
+/* 337 */ DataOutputStream dos = new DataOutputStream(fos);
+/* 338 */ dos.writeInt(1);
+/* */
+/* 340 */ Enumeration<BlackBoxCommand> e = this.commandList.elements();
+/* 341 */ while (e.hasMoreElements()) {
+/* 342 */ BlackBoxCommand cmd = (BlackBoxCommand)e.nextElement();
+/* 343 */ cmd.save(dos);
+/* */ }
+/* */
+/* 346 */ dos.close();
+/* 347 */ fos.close();
+/* */ } catch (Exception e) {
+/* 349 */ System.out.println(e);
+/* */ }
+/* */ }
+/* */
+/* */ private boolean restore() {
+/* 354 */ if (this.autoFile != null) {
+/* 355 */ restoreFile(new File(this.autoFile));
+/* 356 */ this.autoFile = null;
+/* 357 */ return true;
+/* */ }
+/* */
+/* 360 */ Frame parent = Console.getFrame();
+/* */
+/* 362 */ Properties p = System.getProperties();
+/* 363 */ String oldDir = p.getProperty("user.dir");
+/* 364 */ FileDialog fd = new FileDialog(parent,
+/* 365 */ Console.message("Load-recording"), 0);
+/* */
+/* 367 */ fd.setVisible(true);
+/* */
+/* 369 */ String filename = fd.getFile();
+/* 370 */ String directory = fd.getDirectory();
+/* */
+/* 372 */ p.remove("user.dir");
+/* 373 */ p.put("user.dir", oldDir);
+/* 374 */ System.setProperties(p);
+/* */
+/* 376 */ if (filename == null) {
+/* 377 */ return false;
+/* */ }
+/* 379 */ File f = new File(directory, filename);
+/* */
+/* 381 */ restoreFile(f);
+/* */
+/* 383 */ return true;
+/* */ }
+/* */
+/* */ private void restoreFile(File f) {
+/* 387 */ this.commandList.removeAllElements();
+/* */ try
+/* */ {
+/* 390 */ FileInputStream fis = new FileInputStream(f);
+/* 391 */ DataInputStream dis = new DataInputStream(fis);
+/* 392 */ int version = dis.readInt();
+/* 393 */ dis.close();
+/* 394 */ if (version != 1) {
+/* 395 */ Console.println("Invalid recorder file.");
+/* 396 */ return;
+/* */ }
+/* */ try
+/* */ {
+/* */ for (;;) {
+/* 401 */ int cmdId = dis.readInt();
+/* */
+/* 403 */ BlackBoxCommand cmd = null;
+/* */
+/* 405 */ switch (cmdId)
+/* */ {
+/* */ case 1:
+/* 408 */ cmd = new BBTeleportCommand();
+/* 409 */ break;
+/* */
+/* */
+/* */ case 3:
+/* 413 */ cmd = new BBMoveDroneCommand();
+/* 414 */ break;
+/* */
+/* */
+/* */ case 4:
+/* 418 */ cmd = new BBWObjClickedCommand();
+/* 419 */ break;
+/* */
+/* */
+/* */ case 5:
+/* 423 */ cmd = new BBAppearDroneCommand();
+/* 424 */ break;
+/* */
+/* */
+/* */ case 6:
+/* 428 */ cmd = new BBDisappearDroneCommand();
+/* 429 */ break;
+/* */
+/* */
+/* */ case 7:
+/* 433 */ cmd = new BBDroneBitmapCommand();
+/* 434 */ break;
+/* */
+/* */
+/* */ case 8:
+/* 438 */ cmd = new BBDroneDeltaPosCommand();
+/* 439 */ break;
+/* */
+/* */
+/* */ case 0:
+/* 443 */ cmd = new BBChatCommand();
+/* 444 */ break;
+/* */
+/* */ case 9:
+/* 447 */ cmd = new BBAnimateDroneCommand();
+/* 448 */ break;
+/* */ case 2:
+/* */ default:
+/* 451 */ System.out.println("Error! Unknown command type.");
+/* */ }
+/* */
+/* */
+/* 455 */ if (cmd != null) {
+/* 456 */ cmd.load(dis);
+/* 457 */ this.commandList.addElement(cmd);
+/* */ }
+/* */ }
+/* */ } catch (EOFException e) {
+/* 461 */ dis.close();
+/* 462 */ fis.close();
+/* */ }
+/* */ return;
+/* 465 */ } catch (Exception e) { System.out.println(e);
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\BlackBox.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file