summaryrefslogtreecommitdiff
path: root/apps/plugin.h
blob: 164a2c9847eab7670599b64388bc1567c93745f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 Björn Stenberg
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#ifndef _PLUGIN_H_
#define _PLUGIN_H_

/* instruct simulator code to not redefine any symbols when compiling plugins.
   (the PLUGIN macro is defined in apps/plugins/Makefile) */
#ifdef PLUGIN
#define NO_REDEFINES_PLEASE
#endif

#ifndef MEM
#define MEM 2
#endif

#include <stdbool.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "system.h"
#include "dir.h"
#include "general.h"
#include "kernel.h"
#include "thread.h"
#include "button.h"
#include "action.h"
#include "usb.h"
#include "font.h"
#include "lcd.h"
#include "id3.h"
#include "sound.h"
#include "mpeg.h"
#include "audio.h"
#include "mp3_playback.h"
#include "talk.h"
#ifdef RB_PROFILE
#include "profile.h"
#endif
#include "misc.h"
#if (CONFIG_CODEC == SWCODEC)
#include "dsp.h"
#include "codecs.h"
#include "playback.h"
#include "metadata.h"
#ifdef HAVE_RECORDING
#include "recording.h"
#endif
#else
#include "mas.h"
#endif /* CONFIG_CODEC == SWCODEC */
#include "settings.h"
#include "timer.h"
#include "playlist.h"
#ifdef HAVE_LCD_BITMAP
#include "scrollbar.h"
#endif
#include "statusbar.h"
#include "menu.h"
#include "rbunicode.h"
#include "list.h"
#include "tree.h"
#include "color_picker.h"
#include "buffering.h"
#include "tagcache.h"

#ifdef HAVE_ALBUMART
#include "albumart.h"
#endif

#ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h"
#endif

#ifdef PLUGIN

#if defined(DEBUG) || defined(SIMULATOR)
#undef DEBUGF
#define DEBUGF  rb->debugf
#undef LDEBUGF
#define LDEBUGF rb->debugf
#else
#define DEBUGF(...)
#define LDEBUGF(...)
#endif

#ifdef ROCKBOX_HAS_LOGF
#undef LOGF
#define LOGF rb->logf
#else
#define LOGF(...)
#endif

#endif

#ifdef SIMULATOR
#define PREFIX(_x_) sim_ ## _x_
#else
#define PREFIX(_x_) _x_
#endif

#define PLUGIN_MAGIC 0x526F634B /* RocK */

/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 99

/* update this to latest version if a change to the api struct breaks
   backwards compatibility (and please take the opportunity to sort in any
   new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 98

/* plugin return codes */
enum plugin_status {
    PLUGIN_OK = 0,
    PLUGIN_USB_CONNECTED,
    PLUGIN_ERROR = -1,
};

/* NOTE: To support backwards compatibility, only add new functions at
         the end of the structure.  Every time you add a new function,
         remember to increase PLUGIN_API_VERSION.  If you make changes to the
         existing APIs then also update PLUGIN_MIN_API_VERSION to current
         version
 */
struct plugin_api {

    /* lcd */
    void (*lcd_set_contrast)(int x);
    void (*lcd_update)(void);
    void (*lcd_clear_display)(void);
    void (*lcd_setmargins)(int x, int y);
    int  (*lcd_getstringsize)(const unsigned char *str, int *w, int *h);
    void (*lcd_putsxy)(int x, int y, const unsigned char *string);
    void (*lcd_puts)(int x, int y, const unsigned char *string);
    void (*lcd_puts_scroll)(int x, int y, const unsigned char* string);
    void (*lcd_stop_scroll)(void);
#ifdef HAVE_LCD_CHARCELLS
    void (*lcd_define_pattern)(unsigned long ucs, const char *pattern);
    unsigned long (*lcd_get_locked_pattern)(void);
    void (*lcd_unlock_pattern)(unsigned long ucs);
    void (*lcd_putc)(int x, int y, unsigned long ucs);
    void (*lcd_put_cursor)(int x, int y, unsigned long ucs);
    void (*lcd_remove_cursor)(void);
    void (*lcd_icon)(int icon, bool enable);
    void (*lcd_double_height)(bool on);
#else
    void (*lcd_set_drawmode)(int mode);
    int  (*lcd_get_drawmode)(void);
    void (*lcd_setfont)(int font);
    void (*lcd_drawpixel)(int x, int y);
    void (*lcd_drawline)(int x1, int y1, int x2, int y2);
    void (*lcd_hline)(int x1, int x2, int y);
    void (*lcd_vline)(int x, int y1, int y2);
    void (*lcd_drawrect)(int x, int y, int width, int height);
    void (*lcd_fillrect)(int x, int y, int width, int height);
    void (*lcd_mono_bitmap_part)(const unsigned char *src, int src_x, int src_y,
                                 int stride, int x, int y, int width, int height);
    void (*lcd_mono_bitmap)(const unsigned char *src, int x, int y,
                            int width, int height);
#if LCD_DEPTH > 1
    void     (*lcd_set_foreground)(unsigned foreground);
    unsigned (*lcd_get_foreground)(void);
    void     (*lcd_set_background)(unsigned foreground);
    unsigned (*lcd_get_background)(void);
    void (*lcd_bitmap_part)(const fb_data *src, int src_x, int src_y,
                            int stride, int x, int y, int width, int height);
    void (*lcd_bitmap)(const fb_data *src, int x, int y, int width,
                       int height);
    fb_data* (*lcd_get_backdrop)(void);
    void (*lcd_set_backdrop)(fb_data* backdrop);
#endif
#if LCD_DEPTH == 16
    void (*lcd_bitmap_transparent_part)(const fb_data *src,
            int src_x, int src_y, int stride,
            int x, int y, int width, int height);
    void (*lcd_bitmap_transparent)(const fb_data *src, int x, int y,
            int width, int height);
#endif
    unsigned short *(*bidi_l2v)( const unsigned char *str, int orientation );
    const unsigned char *(*font_get_bits)( struct font *pf, unsigned short char_code );
    struct font* (*font_load)(const char *path);
    void (*lcd_puts_style)(int x, int y, const unsigned char *str, int style);
    void (*lcd_puts_scroll_style)(int x, int y, const unsigned char* string,
                                  int style);
    fb_data* lcd_framebuffer;
    void (*lcd_blit) (const fb_data* data, int x, int by, int width,
                      int bheight, int stride);
    void (*lcd_update_rect)(int x, int y, int width, int height);
    void (*gui_scrollbar_draw)(struct screen * screen, int x, int y,
                               int width, int height, int items,
                               int min_shown, int max_shown,
                               unsigned flags);
    struct font* (*font_get)(int font);
    int  (*font_getstringsize)(const unsigned char *str, int *w, int *h,
                               int fontnumber);
    int (*font_get_width)(struct font* pf, unsigned short char_code);
    void (*screen_clear_area)(struct screen * display, int xstart, int ystart,
                              int width, int height);
#endif
    void (*backlight_on)(void);
    void (*backlight_off)(void);
    void (*backlight_set_timeout)(int index);
#if CONFIG_CHARGING
    void (*backlight_set_timeout_plugged)(int index);
#endif
    void (*splash)(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);

#ifdef HAVE_REMOTE_LCD
    /* remote lcd */
    void (*lcd_remote_set_contrast)(int x);
    void (*lcd_remote_clear_display)(void);
    void (*lcd_remote_setmargins)(int x, int y);
    void (*lcd_remote_puts)(int x, int y, const unsigned char *string);
    void (*lcd_remote_puts_scroll)(int x, int y, const unsigned char* string);
    void (*lcd_remote_stop_scroll)(void);
    void (*lcd_remote_set_drawmode)(int mode);
    int  (*lcd_remote_get_drawmode)(void);
    void (*lcd_remote_setfont)(int font);
    int  (*lcd_remote_getstringsize)(const unsigned char *str, int *w, int *h);
    void (*lcd_remote_drawpixel)(int x, int y);
    void (*lcd_remote_drawline)(int x1, int y1, int x2, int y2);
    void (*lcd_remote_hline)(int x1, int x2, int y);
    void (*lcd_remote_vline)(int x, int y1, int y2);
    void (*lcd_remote_drawrect)(int x, int y, int nx, int ny);
    void (*lcd_remote_fillrect)(int x, int y, int nx, int ny);
    void (*lcd_remote_mono_bitmap_part)(const unsigned char *src, int src_x,
                                        int src_y, int stride, int x, int y,
                                        int width, int height);
    void (*lcd_remote_mono_bitmap)(const unsigned char *src, int x, int y,
                                   int width, int height);
    void (*lcd_remote_putsxy)(int x, int y, const unsigned char *string);
    void (*lcd_remote_puts_style)(int x, int y, const unsigned char *str, int style);
    void (*lcd_remote_puts_scroll_style)(int x, int y, const unsigned char* string,
                                         int style);
    fb_remote_data* lcd_remote_framebuffer;
    void (*lcd_remote_update)(void);
    void (*lcd_remote_update_rect)(int x, int y, int width, int height);

    void (*remote_backlight_on)(void);
    void (*remote_backlight_off)(void);
#endif
    struct screen* screens[NB_SCREENS];
#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
    void     (*lcd_remote_set_foreground)(unsigned foreground);
    unsigned (*lcd_remote_get_foreground)(void);
    void     (*lcd_remote_set_background)(unsigned background);
    unsigned (*lcd_remote_get_background)(void);
    void (*lcd_remote_bitmap_part)(const fb_remote_data *src, int src_x, int src_y,
                                   int stride, int x, int y, int width, int height);
    void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y, int width,
                              int height);
#endif
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR)
    void (*lcd_grey_phase_blit)(unsigned char *values, unsigned char *phases,
                                int bx, int by, int bwidth, int bheight,
                                int stride);
#endif
#if defined(HAVE_LCD_COLOR)
    void (*lcd_yuv_blit)(unsigned char * const src[3],
                         int src_x, int src_y, int stride,
                         int x, int y, int width, int height);
#endif

#if defined(TOSHIBA_GIGABEAT_F) || defined(SANSA_E200) || defined(SANSA_C200) \
    || defined (IRIVER_H10)
    void (*lcd_yuv_set_options)(unsigned options);
#endif

    /* list */
    void (*gui_synclist_init)(struct gui_synclist * lists,
            list_get_name callback_get_item_name,void * data,
            bool scroll_all,int selected_size);
    void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
    void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists, list_get_icon icon_callback);
    int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
    int  (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
    void (*gui_synclist_draw)(struct gui_synclist * lists);
    void (*gui_synclist_select_item)(struct gui_synclist * lists,
    int item_number);
    void (*gui_synclist_add_item)(struct gui_synclist * lists);
    void (*gui_synclist_del_item)(struct gui_synclist * lists);
    void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
    bool (*gui_synclist_do_button)(struct gui_synclist * lists,
                                         unsigned *action, enum list_wrap wrap);
    void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title, int icon);

    /* button */
    long (*button_get)(bool block);
    long (*button_get_w_tmo)(int ticks);
    int (*button_status)(void);
    void (*button_clear_queue)(void);
    int (*button_queue_count)(void);   
#ifdef HAS_BUTTON_HOLD
    bool (*button_hold)(void);
#endif

    /* file */
    int (*PREFIX(open))(const char* pathname, int flags);
    int (*PREFIX(close))(int fd);
    ssize_t (*PREFIX(read))(int fd, void* buf, size_t count);
    off_t (*PREFIX(lseek))(int fd, off_t offset, int whence);
    int (*PREFIX(creat))(const char *pathname);
    ssize_t (*PREFIX(write))(int fd, const void* buf, size_t count);
    int (*PREFIX(remove))(const char* pathname);
    int (*PREFIX(rename))(const char* path, const char* newname);
    int (*PREFIX(ftruncate))(int fd, off_t length);
    off_t (*PREFIX(filesize))(int fd);
    int (*fdprintf)(int fd, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
    int (*read_line)(int fd, char* buffer, int buffer_size);
    bool (*settings_parseline)(char* line, char** name, char** value);
#ifndef SIMULATOR
    void (*ata_sleep)(void);
    bool (*ata_disk_is_active)(void);
#endif
    void (*ata_spindown)(int seconds);
    void (*reload_directory)(void);
    char *(*create_numbered_filename)(char *buffer, const char *path,
                                      const char *prefix, const char *suffix,
                                      int numberlen IF_CNFN_NUM_(, int *num));

    /* dir */
    DIR* (*opendir)(const char* name);
    int (*closedir)(DIR* dir);
    struct dirent* (*readdir)(DIR* dir);
    int (*mkdir)(const char *name);
    int (*rmdir)(const char *name);

    /* kernel/ system */
    void (*PREFIX(sleep))(int ticks);
    void (*yield)(void);
#ifdef HAVE_PRIORITY_SCHEDULING
    void (*priority_yield)(void);
#endif
    volatile long* current_tick;
    long (*default_event_handler)(long event);
    long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter);
    struct thread_entry* threads;
    struct thread_entry* (*create_thread)(void (*function)(void), void* stack,
                                          int stack_size, unsigned flags,
                                          const char *name
                                          IF_PRIO(, int priority)
					                      IF_COP(, unsigned int core));
    void (*remove_thread)(struct thread_entry *thread);
    void (*reset_poweroff_timer)(void);
#ifndef SIMULATOR
    int (*system_memory_guard)(int newmode);
    long *cpu_frequency;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
#ifdef CPU_BOOST_LOGGING
    void (*cpu_boost_)(bool on_off,char*location,int line);
#else
    void (*cpu_boost)(bool on_off);
#endif
#endif
#endif
    bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
                           long cycles, int int_prio,
                           void (*timer_callback)(void));
    void (*timer_unregister)(void);
    bool (*timer_set_period)(long count);

    void (*queue_init)(struct event_queue *q, bool register_queue);
    void (*queue_delete)(struct event_queue *q);
    void (*queue_post)(struct event_queue *q, long id, intptr_t data);
    void (*queue_wait_w_tmo)(struct event_queue *q, struct queue_event *ev,
            int ticks);
    void (*usb_acknowledge)(long id);
#ifdef RB_PROFILE
    void (*profile_thread)(void);
    void (*profstop)(void);
    void (*profile_func_enter)(void *this_fn, void *call_site);
    void (*profile_func_exit)(void *this_fn, void *call_site);
#endif

#ifdef SIMULATOR
    /* special simulator hooks */
#if defined(HAVE_LCD_BITMAP) && LCD_DEPTH < 8
    void (*sim_lcd_ex_init)(int shades, unsigned long (*getpixel)(int, int));
    void (*sim_lcd_ex_update_rect)(int x, int y, int width, int height);
#endif
#endif

    /* strings and memory */
    int (*snprintf)(char *buf, size_t size, const char *fmt, ...)
                    ATTRIBUTE_PRINTF(3, 4);
    int (*vsnprintf)(char *buf, int size, const char *fmt, va_list ap);
    char* (*strcpy)(char *dst, const char *src);
    char* (*strncpy)(char *dst, const char *src, size_t length);
    size_t (*strlen)(const char *str);
    char * (*strrchr)(const char *s, int c);
    int (*strcmp)(const char *, const char *);
    int (*strncmp)(const char *, const char *, size_t);
    int (*strcasecmp)(const char *, const char *);
    int (*strncasecmp)(const char *s1, const char *s2, size_t n);
    void* (*memset)(void *dst, int c, size_t length);
    void* (*memcpy)(void *out, const void *in, size_t n);
    void* (*memmove)(void *out, const void *in, size_t n);
    const unsigned char *_ctype_;
    int (*atoi)(const char *str);
    char *(*strchr)(const char *s, int c);
    char *(*strcat)(char *s1, const char *s2);
    void *(*memchr)(const void *s1, int c, size_t n);
    int (*memcmp)(const void *s1, const void *s2, size_t n);
    char *(*strcasestr) (const char* phaystack, const char* pneedle);
    char* (*strtok_r)(char *ptr, const char *sep, char **end);
    /* unicode stuff */
    const unsigned char* (*utf8decode)(const unsigned char *utf8, unsigned short *ucs);
    unsigned char* (*iso_decode)(const unsigned char *iso, unsigned char *utf8, int cp, int count);
    unsigned char* (*utf16LEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
    unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, int count);
    unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8);
    unsigned long (*utf8length)(const unsigned char *utf8);
    int (*utf8seek)(const unsigned char* utf8, int offset);

    /* sound */
#if CONFIG_CODEC == SWCODEC
    int (*sound_default)(int setting);
#endif
    void (*sound_set)(int setting, int value);
    int (*sound_min)(int setting);
    int (*sound_max)(int setting);
#ifndef SIMULATOR
    void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, size_t* size));
    void (*mp3_play_pause)(bool play);
    void (*mp3_play_stop)(void);
    bool (*mp3_is_playing)(void);
#if CONFIG_CODEC != SWCODEC
    void (*bitswap)(unsigned char *data, int length);
#endif
#endif /* !SIMULATOR */
#if CONFIG_CODEC == SWCODEC
    const unsigned long *audio_master_sampr_list;
    const unsigned long *hw_freq_sampr;
    void (*pcm_apply_settings)(void);
    void (*pcm_play_data)(pcm_more_callback_type get_more,
            unsigned char* start, size_t size);
    void (*pcm_play_stop)(void);
    void (*pcm_set_frequency)(unsigned int frequency);
    bool (*pcm_is_playing)(void);
    bool (*pcm_is_paused)(void);
    void (*pcm_play_pause)(bool play);
    size_t (*pcm_get_bytes_waiting)(void);
    void (*pcm_calculate_peaks)(int *left, int *right);
#ifdef HAVE_RECORDING
    const unsigned long *rec_freq_sampr;
    void (*pcm_init_recording)(void);
    void (*pcm_close_recording)(void);
    void (*pcm_record_data)(pcm_more_callback_type2 more_ready,
                            void *start, size_t size);
    void (*pcm_record_more)(void *start, size_t size);
    void (*pcm_stop_recording)(void);
    void (*pcm_calculate_rec_peaks)(int *left, int *right);
    void (*audio_set_recording_gain)(int left, int right, int type);
#endif /* HAVE_RECORDING */
#if INPUT_SRC_CAPS != 0
    void (*audio_set_output_source)(int monitor);
    void (*audio_set_input_source)(int source, unsigned flags);
#endif
#endif /* CONFIG_CODEC == SWCODC */

    /* playback control */
    int (*playlist_amount)(void);
    int (*playlist_resume)(void);
    int (*playlist_start)(int start_index, int offset);
    void (*PREFIX(audio_play))(long offset);
    void (*audio_stop)(void);
    void (*audio_pause)(void);
    void (*audio_resume)(void);
    void (*audio_next)(void);
    void (*audio_prev)(void);
    void (*audio_ff_rewind)(long newtime);
    struct mp3entry* (*audio_next_track)(void);
    int (*audio_status)(void);
    bool (*audio_has_changed_track)(void);
    struct mp3entry* (*audio_current_track)(void);
    void (*audio_flush_and_reload_tracks)(void);
    int (*audio_get_file_pos)(void);
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
    unsigned long (*mpeg_get_last_header)(void);
#endif
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) || \
    (CONFIG_CODEC == SWCODEC)
    void (*sound_set_pitch)(int pitch);
#endif

    /* MAS communication */
#if !defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
    int (*mas_readmem)(int bank, int addr, unsigned long* dest, int len);
    int (*mas_writemem)(int bank, int addr, const unsigned long* src, int len);
    int (*mas_readreg)(int reg);
    int (*mas_writereg)(int reg, unsigned int val);
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
    int (*mas_codec_writereg)(int reg, unsigned int val);
    int (*mas_codec_readreg)(int reg);
    void (*i2c_begin)(void);
    void (*i2c_end)(void);
    int  (*i2c_write)(int address, unsigned char* buf, int count );
#endif
#endif

    /* menu */
    int (*do_menu)(const struct menu_item_ex *menu, int *start_selected);

    /* scroll bar */
    struct gui_syncstatusbar *statusbars;
    void (*gui_syncstatusbar_draw)(struct gui_syncstatusbar * bars, bool force_redraw);
    
    /* options */
    const struct settings_list* (*find_setting)(void* variable, int *id);
    bool (*option_screen)(struct settings_list *setting,
                          bool use_temp_var, unsigned char* option_title);
    bool (*set_option)(const char* string, void* variable,
                       enum optiontype type, const struct opt_items* options,
                       int numoptions, void (*function)(int));
    bool (*set_bool_options)(const char* string, bool* variable,
                             const char* yes_str, int yes_voice,
                             const char* no_str, int no_voice,
                             void (*function)(bool));
    bool (*set_int)(const unsigned char* string, const char* unit, int voice_unit,
                    int* variable, void (*function)(int), int step, int min,
                    int max, void (*formatter)(char*, size_t, int, const char*) );
    bool (*set_bool)(const char* string, bool* variable );

#ifdef HAVE_LCD_COLOR
    bool (*set_color)(struct screen *display, char *title, unsigned *color,
                   unsigned banned_color);
#endif
    /* action handling */
    int (*get_custom_action)(int context,int timeout,
                          const struct button_mapping* (*get_context_map)(int));
    int (*get_action)(int context, int timeout);
    bool (*action_userabort)(int timeout);

    /* power */
    int (*battery_level)(void);
    bool (*battery_level_safe)(void);
    int (*battery_time)(void);
#ifndef SIMULATOR
    unsigned int (*battery_voltage)(void);
#endif
#if CONFIG_CHARGING
    bool (*charger_inserted)(void);
# if CONFIG_CHARGING == CHARGING_MONITOR
    bool (*charging_state)(void);
# endif
#endif
#ifdef HAVE_USB_POWER
    bool (*usb_powered)(void);
#endif

    /* misc */
    void (*srand)(unsigned int seed);
    int  (*rand)(void);
    void (*qsort)(void *base, size_t nmemb, size_t size,
                  int(*compar)(const void *, const void *));
    int (*kbd_input)(char* buffer, int buflen);
    struct tm* (*get_time)(void);
    int  (*set_time)(const struct tm *tm);
#if CONFIG_RTC
    time_t (*mktime)(struct tm *t);
#endif
    void* (*plugin_get_buffer)(size_t *buffer_size);
    void* (*plugin_get_audio_buffer)(size_t *buffer_size);
    void (*plugin_tsr)(bool (*exit_callback)(bool reenter));
    char* (*plugin_get_current_filename)(void);
#ifdef PLUGIN_USE_IRAM
    void (*plugin_iram_init)(char *iramstart, char *iramcopy, size_t iram_size,
                             char *iedata, size_t iedata_size);
#endif
#if defined(DEBUG) || defined(SIMULATOR)
    void (*debugf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
#endif
#ifdef ROCKBOX_HAS_LOGF
    void (*logf)(const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
#endif
    struct user_settings* global_settings;
    struct system_status *global_status;
    void (*talk_disable)(bool disable);
#if CONFIG_CODEC == SWCODEC
    int (*codec_load_file)(const char* codec, struct codec_api *api);
    const char *(*get_codec_filename)(int cod_spec);
    bool (*get_metadata)(struct mp3entry* id3, int fd, const char* trackname);
#endif
    bool (*mp3info)(struct mp3entry *entry, const char *filename);
    int (*count_mp3_frames)(int fd, int startpos, int filesize,
                            void (*progressfunc)(int));
    int (*create_xing_header)(int fd, long startpos, long filesize,
            unsigned char *buf, unsigned long num_frames,
            unsigned long rec_time, unsigned long header_template,
            void (*progressfunc)(int), bool generate_toc);
    unsigned long (*find_next_frame)(int fd, long *offset,
            long max_offset, unsigned long last_header);

#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
    unsigned short (*peak_meter_scale_value)(unsigned short val,
                                             int meterwidth);
    void (*peak_meter_set_use_dbfs)(bool use);
    bool (*peak_meter_get_use_dbfs)(void);
#endif
#ifdef HAVE_LCD_BITMAP
    int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize,
                         int format);
    void (*screen_dump_set_hook)(void (*hook)(int fh));
#endif
    int (*show_logo)(void);
    struct tree_context* (*tree_get_context)(void);
    void (*set_current_file)(char* path);
    void (*set_dirfilter)(int l_dirfilter);

#ifdef HAVE_WHEEL_POSITION
    int (*wheel_status)(void);
    void (*wheel_send_events)(bool send);
#endif

#ifdef IRIVER_H100_SERIES
    /* Routines for the iriver_flash -plugin. */
    bool (*detect_original_firmware)(void);
    bool (*detect_flashed_ramimage)(void);
    bool (*detect_flashed_romimage)(void);
#endif

    void (*led)(bool on);

#ifdef CACHE_FUNCTIONS_AS_CALL
    void (*flush_icache)(void);
    void (*invalidate_icache)(void);
#endif

    /* new stuff at the end, sort into place next time
       the API gets incompatible */

#if (CONFIG_CODEC == SWCODEC)
    void (*mutex_init)(struct mutex *m);
    void (*mutex_lock)(struct mutex *m);
    void (*mutex_unlock)(struct mutex *m);
#endif

    void (*thread_wait)(struct thread_entry *thread);

#if (CONFIG_CODEC == SWCODEC)
    size_t (*align_buffer)(void **start, size_t size, size_t align);
#endif

    bool (*file_exists)(const char *file);
    bool (*dir_exists)(const char *path);
    
#ifdef HAVE_REMOTE_LCD
    void (*remote_backlight_set_timeout)(int index);
#if CONFIG_CHARGING
    void (*remote_backlight_set_timeout_plugged)(int index);
#endif
#endif /* HAVE_REMOTE_LCD */

#if (CONFIG_CODEC == SWCODEC)
    int (*bufopen)(const char *file, size_t offset, enum data_type type);
    int (*bufalloc)(const void *src, size_t size, enum data_type type);
    bool (*bufclose)(int handle_id);
    int (*bufseek)(int handle_id, size_t newpos);
    int (*bufadvance)(int handle_id, off_t offset);
    ssize_t (*bufread)(int handle_id, size_t size, void *dest);
    ssize_t (*bufgetdata)(int handle_id, size_t size, void **data);
    ssize_t (*bufgettail)(int handle_id, size_t size, void **data);
    ssize_t (*bufcuttail)(int handle_id, size_t size);

    ssize_t (*buf_get_offset)(int handle_id, void *ptr);
    ssize_t (*buf_handle_offset)(int handle_id);
    void (*buf_request_buffer_handle)(int handle_id);
    void (*buf_set_base_handle)(int handle_id);
    size_t (*buf_used)(void);
#endif

#ifdef HAVE_TAGCACHE
    bool (*tagcache_search)(struct tagcache_search *tcs, int tag);
    void (*tagcache_search_set_uniqbuf)(struct tagcache_search *tcs,
           void *buffer, long length);
    bool (*tagcache_search_add_filter)(struct tagcache_search *tcs,
                                    int tag, int seek);
    bool (*tagcache_get_next)(struct tagcache_search *tcs);
    bool (*tagcache_retrieve)(struct tagcache_search *tcs, int idxid,
                           int tag, char *buf, long size);
    void (*tagcache_search_finish)(struct tagcache_search *tcs);
#endif

#ifdef HAVE_ALBUMART
    bool (*find_albumart)(const struct mp3entry *id3, char *buf, int buflen);
    bool (*search_albumart_files)(const struct mp3entry *id3, const char *size_string,
                                  char *buf, int buflen);
#endif

#if CONFIG_CODEC == SWCODEC
    void (*pcm_play_lock)(void);
    void (*pcm_play_unlock)(void);
    void (*queue_enable_queue_send)(struct event_queue *q,
                                    struct queue_sender_list *send);
    bool (*queue_empty)(const struct event_queue *q);
    void (*queue_wait)(struct event_queue *q, struct queue_event *ev);
    intptr_t (*queue_send)(struct event_queue *q, long id,
                           intptr_t data);
    void (*queue_reply)(struct event_queue *q, intptr_t retval);
#ifndef HAVE_FLASH_STORAGE
    void (*ata_spin)(void);
#endif
#ifdef HAVE_SCHEDULER_BOOSTCTRL
    void (*trigger_cpu_boost)(void);
    void (*cancel_cpu_boost)(void);
#endif
    const char * (*sound_unit)(int setting);
    int (*sound_val2phys)(int setting, int value);
    void (*dsp_set_crossfeed)(bool enable);
    void (*dsp_set_eq)(bool enable);
    void (*dsp_dither_enable)(bool enable);
    intptr_t (*dsp_configure)(struct dsp_config *dsp, int setting,
                              intptr_t value);
    int (*dsp_process)(struct dsp_config *dsp, char *dest,
                       const char *src[], int count);
#endif /* CONFIG_CODEC == SWCODEC */
};

/* plugin header */
struct plugin_header {
    unsigned long magic;
    unsigned short target_id;
    unsigned short api_version;
    unsigned char *load_addr;
    unsigned char *end_addr;
    enum plugin_status(*entry_point)(struct plugin_api*, void*);
};

#ifdef PLUGIN
#ifndef SIMULATOR
extern unsigned char plugin_start_addr[];
extern unsigned char plugin_end_addr[];
#define PLUGIN_HEADER \
        const struct plugin_header __header \
        __attribute__ ((section (".header")))= { \
        PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
        plugin_start_addr, plugin_end_addr, plugin_start };
#else /* SIMULATOR */
#define PLUGIN_HEADER \
        const struct plugin_header __header \
        __attribute__((visibility("default"))) = { \
        PLUGIN_MAGIC, TARGET_ID, PLUGIN_API_VERSION, \
        NULL, NULL, plugin_start };
#endif /* SIMULATOR */

#ifdef PLUGIN_USE_IRAM
/* Declare IRAM variables */
#define PLUGIN_IRAM_DECLARE \
    extern char iramcopy[]; \
    extern char iramstart[]; \
    extern char iramend[]; \
    extern char iedata[]; \
    extern char iend[];
/* Initialize IRAM */
#define PLUGIN_IRAM_INIT(api) \
    (api)->plugin_iram_init(iramstart, iramcopy, iramend-iramstart, \
                            iedata, iend-iedata);
#else
#define PLUGIN_IRAM_DECLARE
#define PLUGIN_IRAM_INIT(api)
#endif /* PLUGIN_USE_IRAM */
#endif /* PLUGIN */

int plugin_load(const char* plugin, void* parameter);
void* plugin_get_buffer(size_t *buffer_size);
void* plugin_get_audio_buffer(size_t *buffer_size);
#ifdef PLUGIN_USE_IRAM
void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
                      char *iedata, size_t iedata_size);
#endif

/* plugin_tsr,
    callback returns true to allow the new plugin to load,
    reenter means the currently running plugin is being reloaded */
void plugin_tsr(bool (*exit_callback)(bool reenter));

/* defined by the plugin */
enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter)
    NO_PROF_ATTR;

/* Use this macro in plugins where gcc tries to optimize by calling
 * these functions directly */
#define MEM_FUNCTION_WRAPPERS(api) \
        void *memcpy(void *dest, const void *src, size_t n) \
        { \
            return (api)->memcpy(dest, src, n); \
        } \
        void *memset(void *dest, int c, size_t n) \
        { \
            return (api)->memset(dest, c, n); \
        } \
        void *memmove(void *dest, const void *src, size_t n) \
        { \
            return (api)->memmove(dest, src, n); \
        } \
        int memcmp(const void *s1, const void *s2, size_t n) \
        { \
            return (api)->memcmp(s1, s2, n); \
        }

#ifndef CACHE_FUNCTION_WRAPPERS

#ifdef CACHE_FUNCTIONS_AS_CALL
#define CACHE_FUNCTION_WRAPPERS(api) \
        void flush_icache(void) \
        { \
            (api)->flush_icache(); \
        } \
        void invalidate_icache(void) \
        { \
            (api)->invalidate_icache(); \
        }
#else
#define CACHE_FUNCTION_WRAPPERS(api)
#endif /* CACHE_FUNCTIONS_AS_CALL */

#endif /* CACHE_FUNCTION_WRAPPERS */

#ifndef ALIGN_BUFFER_WRAPPER
#define ALIGN_BUFFER_WRAPPER(api) \
        size_t align_buffer(void **start, size_t size, size_t align) \
        { \
            return (api)->align_buffer(start, size, align); \
        }
#endif /* ALIGN_BUFFER_WRAPPER */

#endif
->z > FixedMul(thing->momx,thing->momx)+FixedMul(thing->momy,thing->momy)) return false; } // the move is ok, // so unlink from the old position and link into the new position P_UnsetThingPosition (thing); oldx = thing->x; oldy = thing->y; thing->floorz = tmfloorz; thing->ceilingz = tmceilingz; thing->dropoffz = tmdropoffz; // killough 11/98: keep track of dropoffs thing->x = x; thing->y = y; P_SetThingPosition (thing); // if any special lines were hit, do the effect if (! (thing->flags&(MF_TELEPORT|MF_NOCLIP)) ) while (numspechit--) if (spechit[numspechit]->special) // see if the line was crossed { int oldside; if ((oldside = P_PointOnLineSide(oldx, oldy, spechit[numspechit])) != P_PointOnLineSide(thing->x, thing->y, spechit[numspechit])) P_CrossSpecialLine(spechit[numspechit], oldside, thing); } return true; } /* * killough 9/12/98: * * Apply "torque" to objects hanging off of ledges, so that they * fall off. It's not really torque, since Doom has no concept of * rotation, but it's a convincing effect which avoids anomalies * such as lifeless objects hanging more than halfway off of ledges, * and allows objects to roll off of the edges of moving lifts, or * to slide up and then back down stairs, or to fall into a ditch. * If more than one linedef is contacted, the effects are cumulative, * so balancing is possible. */ static boolean PIT_ApplyTorque(line_t *ld) { if (ld->backsector && // If thing touches two-sided pivot linedef tmbbox[BOXRIGHT] > ld->bbox[BOXLEFT] && tmbbox[BOXLEFT] < ld->bbox[BOXRIGHT] && tmbbox[BOXTOP] > ld->bbox[BOXBOTTOM] && tmbbox[BOXBOTTOM] < ld->bbox[BOXTOP] && P_BoxOnLineSide(tmbbox, ld) == -1) { mobj_t *mo = tmthing; fixed_t dist = // lever arm + (ld->dx >> FRACBITS) * (mo->y >> FRACBITS) - (ld->dy >> FRACBITS) * (mo->x >> FRACBITS) - (ld->dx >> FRACBITS) * (ld->v1->y >> FRACBITS) + (ld->dy >> FRACBITS) * (ld->v1->x >> FRACBITS); if (dist < 0 ? // dropoff direction ld->frontsector->floorheight < mo->z && ld->backsector->floorheight >= mo->z : ld->backsector->floorheight < mo->z && ld->frontsector->floorheight >= mo->z) { /* At this point, we know that the object straddles a two-sided * linedef, and that the object's center of mass is above-ground. */ fixed_t x = D_abs(ld->dx), y = D_abs(ld->dy); if (y > x) { fixed_t t = x; x = y; y = t; } y = finesine[(tantoangle[FixedDiv(y,x)>>DBITS] + ANG90) >> ANGLETOFINESHIFT]; /* Momentum is proportional to distance between the * object's center of mass and the pivot linedef. * * It is scaled by 2^(OVERDRIVE - gear). When gear is * increased, the momentum gradually decreases to 0 for * the same amount of pseudotorque, so that oscillations * are prevented, yet it has a chance to reach equilibrium. */ dist = FixedDiv(FixedMul(dist, (mo->gear < OVERDRIVE) ? y << -(mo->gear - OVERDRIVE) : y >> +(mo->gear - OVERDRIVE)), x); /* Apply momentum away from the pivot linedef. */ x = FixedMul(ld->dy, dist); y = FixedMul(ld->dx, dist); /* Avoid moving too fast all of a sudden (step into "overdrive") */ dist = FixedMul(x,x) + FixedMul(y,y); while (dist > FRACUNIT*4 && mo->gear < MAXGEAR) ++mo->gear, x >>= 1, y >>= 1, dist >>= 1; mo->momx -= x; mo->momy += y; } } return true; } /* * killough 9/12/98 * * Applies "torque" to objects, based on all contacted linedefs */ void P_ApplyTorque(mobj_t *mo) { int xl = ((tmbbox[BOXLEFT] = mo->x - mo->radius) - bmaporgx) >> MAPBLOCKSHIFT; int xh = ((tmbbox[BOXRIGHT] = mo->x + mo->radius) - bmaporgx) >> MAPBLOCKSHIFT; int yl = ((tmbbox[BOXBOTTOM] = mo->y - mo->radius) - bmaporgy) >> MAPBLOCKSHIFT; int yh = ((tmbbox[BOXTOP] = mo->y + mo->radius) - bmaporgy) >> MAPBLOCKSHIFT; int bx,by,flags = mo->intflags; //Remember the current state, for gear-change tmthing = mo; validcount++; /* prevents checking same line twice */ for (bx = xl ; bx <= xh ; bx++) for (by = yl ; by <= yh ; by++) P_BlockLinesIterator(bx, by, PIT_ApplyTorque); /* If any momentum, mark object as 'falling' using engine-internal flags */ if (mo->momx | mo->momy) mo->intflags |= MIF_FALLING; else // Clear the engine-internal flag indicating falling object. mo->intflags &= ~MIF_FALLING; /* If the object has been moving, step up the gear. * This helps reach equilibrium and avoid oscillations. * * Doom has no concept of potential energy, much less * of rotation, so we have to creatively simulate these * systems somehow :) */ if (!((mo->intflags | flags) & MIF_FALLING)) // If not falling for a while, mo->gear = 0; // Reset it to full strength else if (mo->gear < MAXGEAR) // Else if not at max gear, mo->gear++; // move up a gear } // // P_ThingHeightClip // Takes a valid thing and adjusts the thing->floorz, // thing->ceilingz, and possibly thing->z. // This is called for all nearby monsters // whenever a sector changes height. // If the thing doesn't fit, // the z will be set to the lowest value // and false will be returned. // boolean P_ThingHeightClip (mobj_t* thing) { boolean onfloor; onfloor = (thing->z == thing->floorz); P_CheckPosition (thing, thing->x, thing->y); /* what about stranding a monster partially off an edge? * killough 11/98: Answer: see below (upset balance if hanging off ledge) */ thing->floorz = tmfloorz; thing->ceilingz = tmceilingz; thing->dropoffz = tmdropoffz; /* killough 11/98: remember dropoffs */ if (onfloor) { // walking monsters rise and fall with the floor thing->z = thing->floorz; /* killough 11/98: Possibly upset balance of objects hanging off ledges */ if (thing->intflags & MIF_FALLING && thing->gear >= MAXGEAR) thing->gear = 0; } else { // don't adjust a floating monster unless forced to if (thing->z+thing->height > thing->ceilingz) thing->z = thing->ceilingz - thing->height; } return thing->ceilingz - thing->floorz >= thing->height; } // // SLIDE MOVE // Allows the player to slide along any angled walls. // /* killough 8/2/98: make variables static */ static fixed_t bestslidefrac; static fixed_t secondslidefrac; static line_t* bestslideline; static line_t* secondslideline; static mobj_t* slidemo; static fixed_t tmxmove; static fixed_t tmymove; // // P_HitSlideLine // Adjusts the xmove / ymove // so that the next move will slide along the wall. // If the floor is icy, then you can bounce off a wall. // phares // void P_HitSlideLine (line_t* ld) { int side; angle_t lineangle; angle_t moveangle; angle_t deltaangle; fixed_t movelen; fixed_t newlen; boolean icyfloor; // is floor icy? // phares // | // Under icy conditions, if the angle of approach to the wall // V // is more than 45 degrees, then you'll bounce and lose half // your momentum. If less than 45 degrees, you'll slide along // the wall. 45 is arbitrary and is believable. // Check for the special cases of horz or vert walls. /* killough 10/98: only bounce if hit hard (prevents wobbling) * cph - DEMOSYNC - should only affect players in Boom demos? */ icyfloor = (mbf_features ? P_AproxDistance(tmxmove, tmymove) > 4*FRACUNIT : !compatibility) && variable_friction && // killough 8/28/98: calc friction on demand slidemo->z <= slidemo->floorz && P_GetFriction(slidemo, NULL) > ORIG_FRICTION; if (ld->slopetype == ST_HORIZONTAL) { if (icyfloor && (D_abs(tmymove) > D_abs(tmxmove))) { tmxmove /= 2; // absorb half the momentum tmymove = -tmymove/2; S_StartSound(slidemo,sfx_oof); // oooff! } else tmymove = 0; // no more movement in the Y direction return; } if (ld->slopetype == ST_VERTICAL) { if (icyfloor && (D_abs(tmxmove) > D_abs(tmymove))) { tmxmove = -tmxmove/2; // absorb half the momentum tmymove /= 2; S_StartSound(slidemo,sfx_oof); // oooff! // ^ } // | else // phares tmxmove = 0; // no more movement in the X direction return; } // The wall is angled. Bounce if the angle of approach is // phares // less than 45 degrees. // phares side = P_PointOnLineSide (slidemo->x, slidemo->y, ld); lineangle = R_PointToAngle2 (0,0, ld->dx, ld->dy); if (side == 1) lineangle += ANG180; moveangle = R_PointToAngle2 (0,0, tmxmove, tmymove); // killough 3/2/98: // The moveangle+=10 breaks v1.9 demo compatibility in // some demos, so it needs demo_compatibility switch. if (!demo_compatibility) moveangle += 10; // prevents sudden path reversal due to // phares // rounding error // | deltaangle = moveangle-lineangle; // V movelen = P_AproxDistance (tmxmove, tmymove); if (icyfloor && (deltaangle > ANG45) && (deltaangle < ANG90+ANG45)) { moveangle = lineangle - deltaangle; movelen /= 2; // absorb S_StartSound(slidemo,sfx_oof); // oooff! moveangle >>= ANGLETOFINESHIFT; tmxmove = FixedMul (movelen, finecosine[moveangle]); tmymove = FixedMul (movelen, finesine[moveangle]); } // ^ else // | { // phares if (deltaangle > ANG180) deltaangle += ANG180; // I_Error ("SlideLine: ang>ANG180"); lineangle >>= ANGLETOFINESHIFT; deltaangle >>= ANGLETOFINESHIFT; newlen = FixedMul (movelen, finecosine[deltaangle]); tmxmove = FixedMul (newlen, finecosine[lineangle]); tmymove = FixedMul (newlen, finesine[lineangle]); } // phares } // // PTR_SlideTraverse // boolean PTR_SlideTraverse (intercept_t* in) { line_t* li; if (!in->isaline) I_Error ("PTR_SlideTraverse: not a line?"); li = in->d.line; if ( ! (li->flags & ML_TWOSIDED) ) { if (P_PointOnLineSide (slidemo->x, slidemo->y, li)) return true; // don't hit the back side goto isblocking; } // set openrange, opentop, openbottom. // These define a 'window' from one sector to another across a line P_LineOpening (li); if (openrange < slidemo->height) goto isblocking; // doesn't fit if (opentop - slidemo->z < slidemo->height) goto isblocking; // mobj is too high if (openbottom - slidemo->z > 24*FRACUNIT ) goto isblocking; // too big a step up // this line doesn't block movement return true; // the line does block movement, // see if it is closer than best so far isblocking: if (in->frac < bestslidefrac) { secondslidefrac = bestslidefrac; secondslideline = bestslideline; bestslidefrac = in->frac; bestslideline = li; } return false; // stop } // // P_SlideMove // The momx / momy move is bad, so try to slide // along a wall. // Find the first line hit, move flush to it, // and slide along it // // This is a kludgy mess. // // killough 11/98: reformatted void P_SlideMove(mobj_t *mo) { int hitcount = 3; slidemo = mo; // the object that's sliding do { fixed_t leadx, leady, trailx, traily; if (!--hitcount) goto stairstep; // don't loop forever // trace along the three leading corners if (mo->momx > 0) leadx = mo->x + mo->radius, trailx = mo->x - mo->radius; else leadx = mo->x - mo->radius, trailx = mo->x + mo->radius; if (mo->momy > 0) leady = mo->y + mo->radius, traily = mo->y - mo->radius; else leady = mo->y - mo->radius, traily = mo->y + mo->radius; bestslidefrac = FRACUNIT+1; P_PathTraverse(leadx, leady, leadx+mo->momx, leady+mo->momy, PT_ADDLINES, PTR_SlideTraverse); P_PathTraverse(trailx, leady, trailx+mo->momx, leady+mo->momy, PT_ADDLINES, PTR_SlideTraverse); P_PathTraverse(leadx, traily, leadx+mo->momx, traily+mo->momy, PT_ADDLINES, PTR_SlideTraverse); // move up to the wall if (bestslidefrac == FRACUNIT+1) { // the move must have hit the middle, so stairstep stairstep: /* killough 3/15/98: Allow objects to drop off ledges * * phares 5/4/98: kill momentum if you can't move at all * This eliminates player bobbing if pressed against a wall * while on ice. * * killough 10/98: keep buggy code around for old Boom demos * * cph 2000/09//23: buggy code was only in Boom v2.01 */ if (!P_TryMove(mo, mo->x, mo->y + mo->momy, true)) if (!P_TryMove(mo, mo->x + mo->momx, mo->y, true)) if (compatibility_level == boom_201_compatibility) mo->momx = mo->momy = 0; break; } // fudge a bit to make sure it doesn't hit if ((bestslidefrac -= 0x800) > 0) { fixed_t newx = FixedMul(mo->momx, bestslidefrac); fixed_t newy = FixedMul(mo->momy, bestslidefrac); // killough 3/15/98: Allow objects to drop off ledges if (!P_TryMove(mo, mo->x+newx, mo->y+newy, true)) goto stairstep; } // Now continue along the wall. // First calculate remainder. bestslidefrac = FRACUNIT-(bestslidefrac+0x800); if (bestslidefrac > FRACUNIT) bestslidefrac = FRACUNIT; if (bestslidefrac <= 0) break; tmxmove = FixedMul(mo->momx, bestslidefrac); tmymove = FixedMul(mo->momy, bestslidefrac); P_HitSlideLine(bestslideline); // clip the moves mo->momx = tmxmove; mo->momy = tmymove; /* killough 10/98: affect the bobbing the same way (but not voodoo dolls) * cph - DEMOSYNC? */ if (mo->player && mo->player->mo == mo) { if (D_abs(mo->player->momx) > D_abs(tmxmove)) mo->player->momx = tmxmove; if (D_abs(mo->player->momy) > D_abs(tmymove)) mo->player->momy = tmymove; } } // killough 3/15/98: Allow objects to drop off ledges: while (!P_TryMove(mo, mo->x+tmxmove, mo->y+tmymove, true)); } // // P_LineAttack // mobj_t* linetarget; // who got hit (or NULL) static mobj_t* shootthing; /* killough 8/2/98: for more intelligent autoaiming */ static uint_64_t aim_flags_mask; // Height if not aiming up or down fixed_t shootz; int la_damage; fixed_t attackrange; static fixed_t aimslope; // slopes to top and bottom of target // killough 4/20/98: make static instead of using ones in p_sight.c static fixed_t topslope; static fixed_t bottomslope; // // PTR_AimTraverse // Sets linetaget and aimslope when a target is aimed at. // boolean PTR_AimTraverse (intercept_t* in) { line_t* li; mobj_t* th; fixed_t slope; fixed_t thingtopslope; fixed_t thingbottomslope; fixed_t dist; if (in->isaline) { li = in->d.line; if ( !(li->flags & ML_TWOSIDED) ) return false; // stop // Crosses a two sided line. // A two sided line will restrict // the possible target ranges. P_LineOpening (li); if (openbottom >= opentop) return false; // stop dist = FixedMul (attackrange, in->frac); if (li->frontsector->floorheight != li->backsector->floorheight) { slope = FixedDiv (openbottom - shootz , dist); if (slope > bottomslope) bottomslope = slope; } if (li->frontsector->ceilingheight != li->backsector->ceilingheight) { slope = FixedDiv (opentop - shootz , dist); if (slope < topslope) topslope = slope; } if (topslope <= bottomslope) return false; // stop return true; // shot continues } // shoot a thing th = in->d.thing; if (th == shootthing) return true; // can't shoot self if (!(th->flags&MF_SHOOTABLE)) return true; // corpse or something /* killough 7/19/98, 8/2/98: * friends don't aim at friends (except players), at least not first */ if (th->flags & shootthing->flags & aim_flags_mask && !th->player) return true; // check angles to see if the thing can be aimed at dist = FixedMul (attackrange, in->frac); thingtopslope = FixedDiv (th->z+th->height - shootz , dist); if (thingtopslope < bottomslope) return true; // shot over the thing thingbottomslope = FixedDiv (th->z - shootz, dist); if (thingbottomslope > topslope) return true; // shot under the thing // this thing can be hit! if (thingtopslope > topslope) thingtopslope = topslope; if (thingbottomslope < bottomslope) thingbottomslope = bottomslope; aimslope = (thingtopslope+thingbottomslope)/2; linetarget = th; return false; // don't go any farther } // // PTR_ShootTraverse // boolean PTR_ShootTraverse (intercept_t* in) { fixed_t x; fixed_t y; fixed_t z; fixed_t frac; mobj_t* th; fixed_t slope; fixed_t dist; fixed_t thingtopslope; fixed_t thingbottomslope; if (in->isaline) { line_t *li = in->d.line; if (li->special) P_ShootSpecialLine (shootthing, li); if (li->flags & ML_TWOSIDED) { // crosses a two sided (really 2s) line P_LineOpening (li); dist = FixedMul(attackrange, in->frac); // killough 11/98: simplify if ((li->frontsector->floorheight==li->backsector->floorheight || (slope = FixedDiv(openbottom - shootz , dist)) <= aimslope) && (li->frontsector->ceilingheight==li->backsector->ceilingheight || (slope = FixedDiv (opentop - shootz , dist)) >= aimslope)) return true; // shot continues } // hit line // position a bit closer frac = in->frac - FixedDiv (4*FRACUNIT,attackrange); x = trace.x + FixedMul (trace.dx, frac); y = trace.y + FixedMul (trace.dy, frac); z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange)); if (li->frontsector->ceilingpic == skyflatnum) { // don't shoot the sky! if (z > li->frontsector->ceilingheight) return false; // it's a sky hack wall if (li->backsector && li->backsector->ceilingpic == skyflatnum) // fix bullet-eaters -- killough: // WARNING: Almost all demos will lose sync without this // demo_compatibility flag check!!! killough 1/18/98 if (demo_compatibility || li->backsector->ceilingheight < z) return false; } // Spawn bullet puffs. P_SpawnPuff (x,y,z); // don't go any farther return false; } // shoot a thing th = in->d.thing; if (th == shootthing) return true; // can't shoot self if (!(th->flags&MF_SHOOTABLE)) return true; // corpse or something // check angles to see if the thing can be aimed at dist = FixedMul (attackrange, in->frac); thingtopslope = FixedDiv (th->z+th->height - shootz , dist); if (thingtopslope < aimslope) return true; // shot over the thing thingbottomslope = FixedDiv (th->z - shootz, dist); if (thingbottomslope > aimslope) return true; // shot under the thing // hit thing // position a bit closer frac = in->frac - FixedDiv (10*FRACUNIT,attackrange); x = trace.x + FixedMul (trace.dx, frac); y = trace.y + FixedMul (trace.dy, frac); z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange)); // Spawn bullet puffs or blod spots, // depending on target type. if (in->d.thing->flags & MF_NOBLOOD) P_SpawnPuff (x,y,z); else P_SpawnBlood (x,y,z, la_damage); if (la_damage) P_DamageMobj (th, shootthing, shootthing, la_damage); // don't go any farther return false; } // // P_AimLineAttack // fixed_t P_AimLineAttack(mobj_t* t1,angle_t angle,fixed_t distance, uint_64_t mask) { fixed_t x2; fixed_t y2; angle >>= ANGLETOFINESHIFT; shootthing = t1; x2 = t1->x + (distance>>FRACBITS)*finecosine[angle]; y2 = t1->y + (distance>>FRACBITS)*finesine[angle]; shootz = t1->z + (t1->height>>1) + 8*FRACUNIT; // can't shoot outside view angles topslope = 100*FRACUNIT/160; bottomslope = -100*FRACUNIT/160; attackrange = distance; linetarget = NULL; /* killough 8/2/98: prevent friends from aiming at friends */ aim_flags_mask = mask; P_PathTraverse(t1->x,t1->y,x2,y2,PT_ADDLINES|PT_ADDTHINGS,PTR_AimTraverse); if (linetarget) return aimslope; return 0; } // // P_LineAttack // If damage == 0, it is just a test trace // that will leave linetarget set. // void P_LineAttack (mobj_t* t1, angle_t angle, fixed_t distance, fixed_t slope, int damage) { fixed_t x2; fixed_t y2; angle >>= ANGLETOFINESHIFT; shootthing = t1; la_damage = damage; x2 = t1->x + (distance>>FRACBITS)*finecosine[angle]; y2 = t1->y + (distance>>FRACBITS)*finesine[angle]; shootz = t1->z + (t1->height>>1) + 8*FRACUNIT; attackrange = distance; aimslope = slope; P_PathTraverse(t1->x,t1->y,x2,y2,PT_ADDLINES|PT_ADDTHINGS,PTR_ShootTraverse); } // // USE LINES // mobj_t* usething; boolean PTR_UseTraverse (intercept_t* in) { int side; if (!in->d.line->special) { P_LineOpening (in->d.line); if (openrange <= 0) { S_StartSound (usething, sfx_noway); // can't use through a wall return false; } // not a special line, but keep checking return true; } side = 0; if (P_PointOnLineSide (usething->x, usething->y, in->d.line) == 1) side = 1; // return false; // don't use back side P_UseSpecialLine (usething, in->d.line, side); //WAS can't use for than one special line in a row //jff 3/21/98 NOW multiple use allowed with enabling line flag return (!demo_compatibility && (in->d.line->flags&ML_PASSUSE))? true : false; } // Returns false if a "oof" sound should be made because of a blocking // linedef. Makes 2s middles which are impassable, as well as 2s uppers // and lowers which block the player, cause the sound effect when the // player tries to activate them. Specials are excluded, although it is // assumed that all special linedefs within reach have been considered // and rejected already (see P_UseLines). // // by Lee Killough // boolean PTR_NoWayTraverse(intercept_t* in) { line_t *ld = in->d.line; // This linedef return ld->special || !( // Ignore specials ld->flags & ML_BLOCKING || ( // Always blocking P_LineOpening(ld), // Find openings openrange <= 0 || // No opening openbottom > usething->z+24*FRACUNIT || // Too high it blocks opentop < usething->z+usething->height // Too low it blocks ) ); } // // P_UseLines // Looks for special lines in front of the player to activate. // void P_UseLines (player_t* player) { int angle; fixed_t x1; fixed_t y1; fixed_t x2; fixed_t y2; usething = player->mo; angle = player->mo->angle >> ANGLETOFINESHIFT; x1 = player->mo->x; y1 = player->mo->y; x2 = x1 + (USERANGE>>FRACBITS)*finecosine[angle]; y2 = y1 + (USERANGE>>FRACBITS)*finesine[angle]; // old code: // // P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_UseTraverse ); // // This added test makes the "oof" sound work on 2s lines -- killough: if (P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_UseTraverse )) if (!comp[comp_sound] && !P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_NoWayTraverse )) S_StartSound (usething, sfx_noway); } // // RADIUS ATTACK // static mobj_t *bombsource, *bombspot; static int bombdamage; // // PIT_RadiusAttack // "bombsource" is the creature // that caused the explosion at "bombspot". // boolean PIT_RadiusAttack (mobj_t* thing) { fixed_t dx; fixed_t dy; fixed_t dist; /* killough 8/20/98: allow bouncers to take damage * (missile bouncers are already excluded with MF_NOBLOCKMAP) */ if (!(thing->flags & (MF_SHOOTABLE | MF_BOUNCES))) return true; // Boss spider and cyborg // take no damage from concussion. // killough 8/10/98: allow grenades to hurt anyone, unless // fired by Cyberdemons, in which case it won't hurt Cybers. if (bombspot->flags & MF_BOUNCES ? thing->type == MT_CYBORG && bombsource->type == MT_CYBORG : thing->type == MT_CYBORG || thing->type == MT_SPIDER) return true; dx = D_abs(thing->x - bombspot->x); dy = D_abs(thing->y - bombspot->y); dist = dx>dy ? dx : dy; dist = (dist - thing->radius) >> FRACBITS; if (dist < 0) dist = 0; if (dist >= bombdamage) return true; // out of range if ( P_CheckSight (thing, bombspot) ) { // must be in direct path P_DamageMobj (thing, bombspot, bombsource, bombdamage - dist); } return true; } // // P_RadiusAttack // Source is the creature that caused the explosion at spot. // void P_RadiusAttack(mobj_t* spot,mobj_t* source,int damage) { int x; int y; int xl; int xh; int yl; int yh; fixed_t dist; dist = (damage+MAXRADIUS)<<FRACBITS; yh = (spot->y + dist - bmaporgy)>>MAPBLOCKSHIFT; yl = (spot->y - dist - bmaporgy)>>MAPBLOCKSHIFT; xh = (spot->x + dist - bmaporgx)>>MAPBLOCKSHIFT; xl = (spot->x - dist - bmaporgx)>>MAPBLOCKSHIFT; bombspot = spot; bombsource = source; bombdamage = damage; for (y=yl ; y<=yh ; y++) for (x=xl ; x<=xh ; x++) P_BlockThingsIterator (x, y, PIT_RadiusAttack ); } // // SECTOR HEIGHT CHANGING // After modifying a sectors floor or ceiling height, // call this routine to adjust the positions // of all things that touch the sector. // // If anything doesn't fit anymore, true will be returned. // If crunch is true, they will take damage // as they are being crushed. // If Crunch is false, you should set the sector height back // the way it was and call P_ChangeSector again // to undo the changes. // static boolean crushchange, nofit; // // PIT_ChangeSector // boolean PIT_ChangeSector (mobj_t* thing) { mobj_t* mo; if (P_ThingHeightClip (thing)) return true; // keep checking // crunch bodies to giblets if (thing->health <= 0) { P_SetMobjState (thing, S_GIBS); thing->flags &= ~MF_SOLID; thing->height = 0; thing->radius = 0; return true; // keep checking } // crunch dropped items if (thing->flags & MF_DROPPED) { P_RemoveMobj (thing); // keep checking return true; } /* killough 11/98: kill touchy things immediately */ if (thing->flags & MF_TOUCHY && (thing->intflags & MIF_ARMED || sentient(thing))) { P_DamageMobj(thing, NULL, NULL, thing->health); // kill object return true; // keep checking } if (! (thing->flags & MF_SHOOTABLE) ) { // assume it is bloody gibs or something return true; } nofit = true; if (crushchange && !(leveltime&3)) { int t; P_DamageMobj(thing,NULL,NULL,10); // spray blood in a random direction mo = P_SpawnMobj (thing->x, thing->y, thing->z + thing->height/2, MT_BLOOD); /* killough 8/10/98: remove dependence on order of evaluation */ t = P_Random(pr_crush); mo->momx = (t - P_Random (pr_crush))<<12; t = P_Random(pr_crush); mo->momy = (t - P_Random (pr_crush))<<12; } // keep checking (crush other things) return true; } // // P_ChangeSector // boolean P_ChangeSector(sector_t* sector,boolean crunch) { int x; int y; nofit = false; crushchange = crunch; // ARRGGHHH!!!! // This is horrendously slow!!! // killough 3/14/98 // re-check heights for all things near the moving sector for (x=sector->blockbox[BOXLEFT] ; x<= sector->blockbox[BOXRIGHT] ; x++) for (y=sector->blockbox[BOXBOTTOM];y<= sector->blockbox[BOXTOP] ; y++) P_BlockThingsIterator (x, y, PIT_ChangeSector); return nofit; } // // P_CheckSector // jff 3/19/98 added to just check monsters on the periphery // of a moving sector instead of all in bounding box of the // sector. Both more accurate and faster. // boolean P_CheckSector(sector_t* sector,boolean crunch) { msecnode_t *n; if (comp[comp_floors]) /* use the old routine for old demos though */ return P_ChangeSector(sector,crunch); nofit = false; crushchange = crunch; // killough 4/4/98: scan list front-to-back until empty or exhausted, // restarting from beginning after each thing is processed. Avoids // crashes, and is sure to examine all things in the sector, and only // the things which are in the sector, until a steady-state is reached. // Things can arbitrarily be inserted and removed and it won't mess up. // // killough 4/7/98: simplified to avoid using complicated counter // Mark all things invalid for (n=sector->touching_thinglist; n; n=n->m_snext) n->visited = false; do for (n=sector->touching_thinglist; n; n=n->m_snext) // go through list if (!n->visited) // unprocessed thing found { n->visited = true; // mark thing as processed if (!(n->m_thing->flags & MF_NOBLOCKMAP)) //jff 4/7/98 don't do these PIT_ChangeSector(n->m_thing); // process it break; // exit and start over } while (n); // repeat from scratch until all things left are marked valid return nofit; } // CPhipps - // Use block memory allocator here #include "z_bmalloc.h" IMPLEMENT_BLOCK_MEMORY_ALLOC_ZONE(secnodezone, sizeof(msecnode_t), PU_LEVEL, 32, "SecNodes"); inline static msecnode_t* P_GetSecnode(void) { return (msecnode_t*)Z_BMalloc(&secnodezone); } // P_PutSecnode() returns a node to the freelist. inline static void P_PutSecnode(msecnode_t* node) { Z_BFree(&secnodezone, node); } // phares 3/16/98 // // P_AddSecnode() searches the current list to see if this sector is // already there. If not, it adds a sector node at the head of the list of // sectors this object appears in. This is called when creating a list of // nodes that will get linked in later. Returns a pointer to the new node. msecnode_t* P_AddSecnode(sector_t* s, mobj_t* thing, msecnode_t* nextnode) { msecnode_t* node; node = nextnode; while (node) { if (node->m_sector == s) // Already have a node for this sector? { node->m_thing = thing; // Yes. Setting m_thing says 'keep it'. return(nextnode); } node = node->m_tnext; } // Couldn't find an existing node for this sector. Add one at the head // of the list. node = P_GetSecnode(); // killough 4/4/98, 4/7/98: mark new nodes unvisited. node->visited = 0; node->m_sector = s; // sector node->m_thing = thing; // mobj node->m_tprev = NULL; // prev node on Thing thread node->m_tnext = nextnode; // next node on Thing thread if (nextnode) nextnode->m_tprev = node; // set back link on Thing // Add new node at head of sector thread starting at s->touching_thinglist node->m_sprev = NULL; // prev node on sector thread node->m_snext = s->touching_thinglist; // next node on sector thread if (s->touching_thinglist) node->m_snext->m_sprev = node; s->touching_thinglist = node; return(node); } // P_DelSecnode() deletes a sector node from the list of // sectors this object appears in. Returns a pointer to the next node // on the linked list, or NULL. msecnode_t* P_DelSecnode(msecnode_t* node) { msecnode_t* tp; // prev node on thing thread msecnode_t* tn; // next node on thing thread msecnode_t* sp; // prev node on sector thread msecnode_t* sn; // next node on sector thread if (node) { // Unlink from the Thing thread. The Thing thread begins at // sector_list and not from mobj_t->touching_sectorlist. tp = node->m_tprev; tn = node->m_tnext; if (tp) tp->m_tnext = tn; if (tn) tn->m_tprev = tp; // Unlink from the sector thread. This thread begins at // sector_t->touching_thinglist. sp = node->m_sprev; sn = node->m_snext; if (sp) sp->m_snext = sn; else node->m_sector->touching_thinglist = sn; if (sn) sn->m_sprev = sp; // Return this node to the freelist P_PutSecnode(node); return(tn); } return(NULL); } // phares 3/13/98 // Delete an entire sector list void P_DelSeclist(msecnode_t* node) { while (node) node = P_DelSecnode(node); } // phares 3/14/98 // // PIT_GetSectors // Locates all the sectors the object is in by looking at the lines that // cross through it. You have already decided that the object is allowed // at this location, so don't bother with checking impassable or // blocking lines. boolean PIT_GetSectors(line_t* ld) { if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT] || tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT] || tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM] || tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP]) return true; if (P_BoxOnLineSide(tmbbox, ld) != -1) return true; // This line crosses through the object. // Collect the sector(s) from the line and add to the // sector_list you're examining. If the Thing ends up being // allowed to move to this position, then the sector_list // will be attached to the Thing's mobj_t at touching_sectorlist. sector_list = P_AddSecnode(ld->frontsector,tmthing,sector_list); /* Don't assume all lines are 2-sided, since some Things * like MT_TFOG are allowed regardless of whether their radius takes * them beyond an impassable linedef. * * killough 3/27/98, 4/4/98: * Use sidedefs instead of 2s flag to determine two-sidedness. * killough 8/1/98: avoid duplicate if same sector on both sides * cph - DEMOSYNC? */ if (ld->backsector && ld->backsector != ld->frontsector) sector_list = P_AddSecnode(ld->backsector, tmthing, sector_list); return true; } // phares 3/14/98 // // P_CreateSecNodeList alters/creates the sector_list that shows what sectors // the object resides in. void P_CreateSecNodeList(mobj_t* thing,fixed_t x,fixed_t y) { int xl; int xh; int yl; int yh; int bx; int by; msecnode_t* node; mobj_t* saved_tmthing = tmthing; /* cph - see comment at func end */ fixed_t saved_tmx = tmx, saved_tmy = tmy; /* ditto */ // First, clear out the existing m_thing fields. As each node is // added or verified as needed, m_thing will be set properly. When // finished, delete all nodes where m_thing is still NULL. These // represent the sectors the Thing has vacated. node = sector_list; while (node) { node->m_thing = NULL; node = node->m_tnext; } tmthing = thing; tmx = x; tmy = y; tmbbox[BOXTOP] = y + tmthing->radius; tmbbox[BOXBOTTOM] = y - tmthing->radius; tmbbox[BOXRIGHT] = x + tmthing->radius; tmbbox[BOXLEFT] = x - tmthing->radius; validcount++; // used to make sure we only process a line once xl = (tmbbox[BOXLEFT] - bmaporgx)>>MAPBLOCKSHIFT; xh = (tmbbox[BOXRIGHT] - bmaporgx)>>MAPBLOCKSHIFT; yl = (tmbbox[BOXBOTTOM] - bmaporgy)>>MAPBLOCKSHIFT; yh = (tmbbox[BOXTOP] - bmaporgy)>>MAPBLOCKSHIFT; for (bx=xl ; bx<=xh ; bx++) for (by=yl ; by<=yh ; by++) P_BlockLinesIterator(bx,by,PIT_GetSectors); // Add the sector of the (x,y) point to sector_list. sector_list = P_AddSecnode(thing->subsector->sector,thing,sector_list); // Now delete any nodes that won't be used. These are the ones where // m_thing is still NULL. node = sector_list; while (node) { if (node->m_thing == NULL) { if (node == sector_list) sector_list = node->m_tnext; node = P_DelSecnode(node); } else node = node->m_tnext; } /* cph - * This is the strife we get into for using global variables. tmthing * is being used by several different functions calling * P_BlockThingIterator, including functions that can be called *from* * P_BlockThingIterator. Using a global tmthing is not reentrant. * OTOH for Boom/MBF demos we have to preserve the buggy behavior. * Fun. We restore its previous value unless we're in a Boom/MBF demo. */ if ((compatibility_level < boom_compatibility_compatibility) || (compatibility_level >= prboom_3_compatibility)) tmthing = saved_tmthing; /* And, duh, the same for tmx/y - cph 2002/09/22 * And for tmbbox - cph 2003/08/10 */ if ((compatibility_level < boom_compatibility_compatibility) /* || (compatibility_level >= prboom_4_compatibility) */) { tmx = saved_tmx, tmy = saved_tmy; if (tmthing) { tmbbox[BOXTOP] = tmy + tmthing->radius; tmbbox[BOXBOTTOM] = tmy - tmthing->radius; tmbbox[BOXRIGHT] = tmx + tmthing->radius; tmbbox[BOXLEFT] = tmx - tmthing->radius; } } } /* cphipps 2004/08/30 - * Must clear tmthing at tic end, as it might contain a pointer to a removed thinker, or the level might have ended/been ended and we clear the objects it was pointing too. Hopefully we don't need to carry this between tics for sync. */ void P_MapStart(void) { if (tmthing) I_Error("P_MapStart: tmthing set!"); } void P_MapEnd(void) { tmthing = NULL; }