1 /* $Id: macro.c,v 1.8 2005-02-26 10:13:51 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for recording/playing/saving macros
22 static char rcsid[] = "$Id: macro.c,v 1.8 2005-02-26 10:13:51 chris Exp $";
54 #define MAX_NUM_EVENTS 10000
56 UI_EVENT * RecordBuffer;
58 int MacroNumEvents = 0;
61 static char filename[PATH_MAX] = "*.MIN";
65 if ( MacroStatus== UI_STATUS_NORMAL )
67 if (RecordBuffer) d_free( RecordBuffer );
68 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
69 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_MOUSE | UI_RECORD_KEYS );
70 MacroStatus = UI_STATUS_RECORDING;
77 if ( MacroStatus== UI_STATUS_NORMAL )
79 if (RecordBuffer) d_free( RecordBuffer );
80 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
81 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_KEYS );
82 MacroStatus = UI_STATUS_RECORDING;
89 if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
91 ui_set_playback_speed( 1 );
92 ui_play_events_realtime(MacroNumEvents, RecordBuffer);
93 MacroStatus = UI_STATUS_PLAYING;
100 if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
103 ui_play_events_fast(MacroNumEvents, RecordBuffer);
104 MacroStatus = UI_STATUS_FASTPLAY;
112 if (MacroNumEvents < 1 )
114 MessageBox( -2, -2, 1, "No macro has been defined to save!", "Oops" );
118 if (ui_get_filename( filename, "*.MAC", "SAVE MACRO" ))
120 PHYSFS_file *fp = PHYSFS_openWrite(filename);
123 RecordBuffer[0].type = 7;
124 RecordBuffer[0].frame = 0;
125 RecordBuffer[0].data = MacroNumEvents;
126 PHYSFS_write(fp, RecordBuffer, sizeof(UI_EVENT), MacroNumEvents);
134 if (ui_get_filename( filename, "*.MAC", "LOAD MACRO" ))
136 PHYSFS_file *fp = PHYSFS_openRead(filename);
142 d_free( RecordBuffer );
143 length = PHYSFS_fileLength(fp);
144 RecordBuffer = d_malloc(length);
148 PHYSFS_read(fp, RecordBuffer, length, 1);
150 MacroNumEvents = RecordBuffer[0].data;
155 void macro_free_buffer()
158 d_free(RecordBuffer);
164 char * MenuItems[] = { "Play fast",
171 x = MenuX( -1, -1, 6, MenuItems );