2018-11-21 13:35:14 +00:00
|
|
|
package allg5
|
2017-10-03 18:38:09 +00:00
|
|
|
|
|
|
|
// #include <allegro5/allegro.h>
|
|
|
|
// #include <allegro5/allegro_font.h>
|
|
|
|
// #include <allegro5/allegro_image.h>
|
|
|
|
// #include <allegro5/allegro_primitives.h>
|
|
|
|
// #include <allegro5/allegro_ttf.h>
|
|
|
|
// bool init() {
|
|
|
|
// return al_init();
|
|
|
|
// }
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2018-02-13 19:59:55 +00:00
|
|
|
"errors"
|
2018-02-17 14:01:58 +00:00
|
|
|
"runtime"
|
2017-10-03 18:38:09 +00:00
|
|
|
)
|
|
|
|
|
2018-02-17 14:01:58 +00:00
|
|
|
func init() {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:38:09 +00:00
|
|
|
type InitConfig struct {
|
|
|
|
Font bool
|
|
|
|
Image bool
|
|
|
|
Primitives bool
|
|
|
|
Keyboard bool
|
|
|
|
Mouse bool
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:13:35 +00:00
|
|
|
var InitAll = InitConfig{true, true, true, true, true}
|
|
|
|
|
2017-10-03 18:38:09 +00:00
|
|
|
// Init initializes the Allegro system
|
|
|
|
func Init(config InitConfig) error {
|
|
|
|
if !bool(C.init()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to initialize Allegro")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Font && !bool(C.al_init_font_addon()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to initialize font addon")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Font && !bool(C.al_init_ttf_addon()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to initialize ttf addon")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Image && !bool(C.al_init_image_addon()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to initialize image addon")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Primitives && !bool(C.al_init_primitives_addon()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to initialize primitives addon")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Keyboard && !bool(C.al_install_keyboard()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to install keyboard")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if config.Mouse && !bool(C.al_install_mouse()) {
|
2018-02-13 19:59:55 +00:00
|
|
|
return errors.New("failed to install mouse")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|