| Re: [AD] mouse pointer colors |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
In reply to Peter Wang <tjaden@xxxxxxxxxx>: >I don't know if it's worth the trouble and mess to remove the >`show_mouse' and `_mouse_screen' references. The solution isn't really that messy. In the patch I have included, I have tried to come up with a consistent way to expose interfaces such that they are only accessible if the user code links in the relevant object file. To this end, I created some structures, and the constructor functions sets up those structures to point at the relevant interface. If the constructor function isn't executed, the interface isn't available. I believe all the dependencies for MIDI and for the mouse routines are now removed, although the patch might be worth looking at to see if it is at least logical :-) Whenever somebody spots another similar dependency, they can either copy this system or get me to do it for them; working in this way, it should be possible to reduce the overall size of Allegro statically-linked executables. Here is the patch:
Index: include/allegro/aintern.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/aintern.h,v
retrieving revision 1.18
diff -u -r1.18 aintern.h
--- include/allegro/aintern.h 2001/02/14 23:34:03 1.18
+++ include/allegro/aintern.h 2001/03/04 18:14:46
@@ -830,9 +831,6 @@
AL_VAR(int, _sound_irq);
-AL_FUNCPTR(int, _midi_init, (void));
-AL_FUNCPTR(void, _midi_exit, (void));
-
AL_FUNC(int, _midi_allocate_voice, (int min, int max));
AL_VAR(volatile long, _midi_tick);
@@ -972,6 +970,20 @@
/* for readbmp.c */
AL_FUNC(void, register_bitmap_file_type_init, (void));
+
+/* for module linking system; see comment in allegro.c */
+struct _AL_LINKER_MIDI {
+ AL_METHOD(int, init, (void));
+ AL_METHOD(void, exit, (void));
+};
+AL_VAR(struct _AL_LINKER_MIDI*, _al_linker_midi);
+
+struct _AL_LINKER_MOUSE {
+ AL_METHOD(void, set_mouse_etc, (void));
+ AL_METHOD(void, show_mouse, (BITMAP*));
+ BITMAP** mouse_screen_ptr;
+};
+AL_VAR(struct _AL_LINKER_MOUSE*, _al_linker_mouse);
#ifdef __cplusplus
}
Index: src/allegro.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/allegro.c,v
retrieving revision 1.7
diff -u -r1.7 allegro.c
--- src/allegro.c 2001/02/15 00:56:33 1.7
+++ src/allegro.c 2001/03/04 18:15:13
@@ -196,6 +196,16 @@
static int (*trace_handler)(AL_CONST char *msg) = NULL;
+/* module linking system stuff: if an object file is linked in, then its
+ * constructor function is executed; this function should fill in the
+ * data structures below (declared in aintern.h). If the module is not
+ * linked in, then the structure pointers will be null, so we don't need
+ * to bother with that bit of code elsewhere.
+ */
+struct _AL_LINKER_MIDI* _al_linker_midi = 0;
+struct _AL_LINKER_MOUSE* _al_linker_mouse = 0;
+
+
/* dynamic registration system for cleanup code */
struct al_exit_func {
void (*funcptr)(void);
@@ -257,9 +267,11 @@
/* call constructor functions manually */
extern void _initialize_datafile_types();
extern void _midi_constructor();
+ extern void _mouse_constructor();
_initialize_datafile_types();
_midi_constructor();
+ _mouse_constructor();
#endif
if (errno_ptr)
Index: src/dispsw.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/dispsw.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 dispsw.c
--- src/dispsw.c 2000/05/14 20:16:54 1.1.1.1
+++ src/dispsw.c 2001/03/04 18:15:19
@@ -341,8 +341,8 @@
if (!screen)
return;
- if (is_same_bitmap(_mouse_screen, screen)) {
- show_mouse(NULL);
+ if (_al_linker_mouse && is_same_bitmap(*(_al_linker_mouse->mouse_screen_ptr), screen)) {
+ _al_linker_mouse->show_mouse(NULL);
hadmouse = TRUE;
}
else
@@ -357,7 +357,7 @@
_dispsw_status = switch_mode;
if (hadmouse)
- show_mouse(screen);
+ _al_linker_mouse->show_mouse(screen);
}
@@ -393,8 +393,8 @@
if (!screen)
return;
- if (is_same_bitmap(_mouse_screen, screen)) {
- show_mouse(NULL);
+ if (_al_linker_mouse && is_same_bitmap(*(_al_linker_mouse->mouse_screen_ptr), screen)) {
+ _al_linker_mouse->show_mouse(NULL);
hadmouse = TRUE;
}
else
@@ -419,7 +419,7 @@
}
if (hadmouse)
- show_mouse(screen);
+ _al_linker_mouse->show_mouse(screen);
_timer_installed = hadtimer;
}
Index: src/graphics.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/graphics.c,v
retrieving revision 1.4
diff -u -r1.4 graphics.c
--- src/graphics.c 2000/12/10 19:16:18 1.4
+++ src/graphics.c 2001/03/04 18:15:24
@@ -380,7 +380,8 @@
/* close down any existing graphics driver */
if (gfx_driver) {
- show_mouse(NULL);
+ if(_al_linker_mouse)
+ _al_linker_mouse->show_mouse(NULL);
while (vram_bitmap_list)
destroy_bitmap(vram_bitmap_list->bmp);
@@ -561,7 +562,10 @@
}
clear(screen);
- _set_mouse_range();
+
+ if (_al_linker_mouse)
+ _al_linker_mouse->set_mouse_etc();
+
LOCK_DATA(gfx_driver, sizeof(GFX_DRIVER));
_register_switch_bitmap(screen, NULL);
Index: src/midi.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/midi.c,v
retrieving revision 1.5
diff -u -r1.5 midi.c
--- src/midi.c 2000/12/05 23:31:16 1.5
+++ src/midi.c 2001/03/04 18:15:34
@@ -1513,9 +1513,13 @@
CONSTRUCTOR_FUNCTION(void _midi_constructor());
#endif
+static struct _AL_LINKER_MIDI midi_linker = {
+ midi_init,
+ midi_exit
+};
+
void _midi_constructor()
{
- _midi_init = midi_init;
- _midi_exit = midi_exit;
+ _al_linker_midi = &midi_linker;
}
Index: src/mouse.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mouse.c,v
retrieving revision 1.6
diff -u -r1.6 mouse.c
--- src/mouse.c 2001/03/03 00:17:28 1.6
+++ src/mouse.c 2001/03/04 18:15:40
@@ -773,11 +773,11 @@
-/* _set_mouse_range:
+/* set_mouse_etc:
* Hook for setting up the motion range, cursor graphic, etc, called by
* the mouse init and whenever we change the graphics mode.
*/
-void _set_mouse_range()
+static void set_mouse_etc(void)
{
if ((!mouse_driver) || (!gfx_driver))
return;
@@ -905,7 +905,7 @@
_mouse_installed = TRUE;
- _set_mouse_range();
+ set_mouse_etc();
_add_exit_func(remove_mouse);
if (mouse_driver->timer_poll)
@@ -955,3 +955,22 @@
_remove_exit_func(remove_mouse);
}
+
+/* _mouse_constructor:
+ * Register mouse functions if this object file is linked in.
+ */
+#ifdef CONSTRUCTOR_FUNCTION
+ CONSTRUCTOR_FUNCTION(void _mouse_constructor());
+#endif
+
+static struct _AL_LINKER_MOUSE mouse_linker = {
+ set_mouse_etc,
+ show_mouse,
+ &_mouse_screen
+};
+
+void _mouse_constructor()
+{
+ _al_linker_mouse = &mouse_linker;
+}
+
Index: src/sound.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/sound.c,v
retrieving revision 1.3
diff -u -r1.3 sound.c
--- src/sound.c 2000/07/29 10:18:44 1.3
+++ src/sound.c 2001/03/04 18:15:49
@@ -153,11 +153,8 @@
static void update_sweeps(void);
static void sound_lock_mem(void);
-int (*_midi_init)(void) = NULL;
-void (*_midi_exit)(void) = NULL;
-
/* read_sound_config:
* Helper for reading the sound hardware configuration data.
*/
@@ -313,8 +310,8 @@
_phys_voice[c].num = -1;
/* initialise the MIDI file player */
- if (_midi_init)
- if (_midi_init() != 0)
+ if (_al_linker_midi)
+ if (_al_linker_midi->init() != 0)
return -1;
usetc(allegro_error, 0);
@@ -360,8 +357,8 @@
digi_driver = digi_drivers[c].driver;
if (!digi_driver->detect(FALSE)) {
digi_driver = &digi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
if (!ugetc(allegro_error))
ustrcpy(allegro_error, get_config_text("Digital sound driver not found"));
return -1;
@@ -402,8 +399,8 @@
if (!midi_driver->detect(FALSE)) {
digi_driver = &digi_none;
midi_driver = &midi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
if (!ugetc(allegro_error))
ustrcpy(allegro_error, get_config_text("MIDI music driver not found"));
return -1;
@@ -452,8 +449,8 @@
usprintf(allegro_error, get_config_text("Insufficient %s voices available"), (digi_voices > DIGI_VOICES) ? get_config_text("digital") : get_config_text("MIDI"));
digi_driver = &digi_none;
midi_driver = &midi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
return -1;
}
@@ -461,8 +458,8 @@
if (digi_driver->init(FALSE, digi_voices) != 0) {
digi_driver = &digi_none;
midi_driver = &midi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
if (!ugetc(allegro_error))
ustrcpy(allegro_error, get_config_text("Failed to init digital sound driver"));
return -1;
@@ -473,8 +470,8 @@
digi_driver->exit(FALSE);
digi_driver = &digi_none;
midi_driver = &midi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
if (!ugetc(allegro_error))
ustrcpy(allegro_error, get_config_text("Failed to init MIDI music driver"));
return -1;
@@ -491,8 +488,8 @@
digi_driver->exit(FALSE);
digi_driver = &digi_none;
midi_driver = &midi_none;
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
return -1;
}
@@ -668,8 +665,8 @@
if (_voice[c].sample)
deallocate_voice(c);
- if (_midi_exit)
- _midi_exit();
+ if (_al_linker_midi)
+ _al_linker_midi->exit();
midi_driver->exit(FALSE);
midi_driver = &midi_none;
Also, a very small change to fix a potential bug in sound.c:
--- sound.old Sun Mar 4 18:21:22 2001 +++ sound.c Sun Mar 4 18:21:40 2001 @@ -113,7 +113,7 @@ int digi_card = DIGI_AUTODETECT; /* current driver ID numbers */ int midi_card = MIDI_AUTODETECT; -int digi_input_card = MIDI_AUTODETECT; +int digi_input_card = DIGI_AUTODETECT; int midi_input_card = MIDI_AUTODETECT; DIGI_DRIVER *digi_driver = &digi_none; /* these things do all the work */
Bye for now,
--
Laurence Withers, lwithers@xxxxxxxxxx
http://www.lwithers.demon.co.uk/
Attachment:
signature.asc
Description: PGP signature
| Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |