Coder Social home page Coder Social logo

dallegro5's People

Contributors

amarillion avatar bbasile avatar damianday avatar emlai avatar lmbarros avatar rcorre avatar rikkimax avatar siegelord avatar siegelordex avatar simonn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dallegro5's Issues

al_get_pixel should be @nogc nothrow

Most of DAllegro5 is wonderfully annotated @nogc nothrow extern(C) en block.

But al_get_pixel comes from mixin magic, this sits outside even of @nogc nothrow. Expected instead: I can call al_get_pixel from @nogc nothrow usercode.

Missing ALLEGRO_ constants

There are missing constants that I've had to look up in the Allegro headers and define myself. For example:

int ALLEGRO_PIXEL_FORMAT_ANY = 0;
int ALLEGRO_VSYNC = 26;
int ALLEGRO_MAX_BITMAP_SIZE = 27;

(p.s. Thanks for the hard work!)

al_get_pixel corrupts stack, Windows, 64-bit LDC

  1. Windows 7 (but probably all Windowses)
  2. Install LDC 64-bit for Windows, version 1.13.0-beta1 or newer.
  3. Install to LDC's bin and lib dirs the NuGet Allegro 5 64-bit DLLs and LIBs.
  4. Write a test program that calls al_get_pixel. (Its source really be here in this issue, for convenience)
  5. Build test program with LDC 64-bit.
  6. Run test progam in a debugger and examine the crash: It's a corrupted stack.
[New Thread 4672.0x2e4] [New Thread 4672.0x5e0] [New Thread 4672.0x828] [New Thread 4672.0x1238] [New Thread 4672.0x13a4] 
Thread 1 received signal SIGSEGV, Segmentation fault.
0x000000013f6ee829 in ?? ()
(gdb) bt
#0  0x000000013f6ee829 in ?? ()
#1  0x3f5d172d00000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Speculation: DAllegro5 inserts extra assembler for MinGW (checked with a version statement) to fix MinGW 4.5's bizarre calling convention. Since LDC now relies on MinGW but apparently doesn't need that extra assembler, the extra assembler will corrupt the call stack instead of fix the call stack.

LDC 1.13.0-beta1 release notes
LDC readme for this change to MinGW

Workaround: Remove all ColorWrapper mixins, instead declare all functions normally as @nogc nothrow extern(C). The downside of that solution is that it removes the assembler even on systems where (the hack around MinGW 4.5's calling convention) is required.

A better solution should instead have a version statement that doesn't insert the assembler with LDC.

Bonus issue (that should really be a separate issue, but is related): DAllegro's al_get_pixel are wrappers, not bindings, even on systems where no anti-bizarrity is needed. I'd like it to be only a binding wherever possible, then we don't have to link against an unneeded library allegro_color.

OSX

I now mainly use Mac now.

I don't know how to install allegro to work with DAllegro any more.

I get this:
Joels-MacBook-Pro:DAllegro5 joelcnz$ ./build_example_dmd.sh
ld: library not found for -lallegro
clang: error: linker command failed with exit code 1 (use -v to see invocation)
--- errorlevel 1

with installing Allegro:
CMake Error at cmake_install.cmake:54 (FILE):
file INSTALL cannot copy file
"/Users/joelcnz/jpro/dpro2/OtherPeoples/allegro/include/allegro5/allegro5.h"
to "/usr/local/include/allegro5/allegro5.h".

example with the -v flag thing:
Joels-MacBook-Pro:DAllegro5 joelcnz$ vim build_example_dmd.sh
Joels-MacBook-Pro:DAllegro5 joelcnz$ ./build_example_dmd.sh
binary dmd
version v2.065
config /usr/bin/dmd.conf
parse example
importall a5test
import object (/usr/share/dmd/src/druntime/import/object.di)
import std.stdio (/usr/share/dmd/src/phobos/std/stdio.d)
import core.stdc.stdio (/usr/share/dmd/src/druntime/import/core/stdc/stdio.d)
import core.stdc.config (/usr/share/dmd/src/druntime/import/core/stdc/config.d)
import core.stdc.stddef (/usr/share/dmd/src/druntime/import/core/stdc/stddef.d)
import core.stdc.stdarg (/usr/share/dmd/src/druntime/import/core/stdc/stdarg.d)
import core.stdc.stdint (/usr/share/dmd/src/druntime/import/core/stdc/stdint.d)
import core.stdc.signal (/usr/share/dmd/src/druntime/import/core/stdc/signal.d)
import core.stdc.wchar_ (/usr/share/dmd/src/druntime/import/core/stdc/wchar_.d)
import core.stdc.time (/usr/share/dmd/src/druntime/import/core/stdc/time.d)
import std.string (/usr/share/dmd/src/phobos/std/string.d)
import core.exception (/usr/share/dmd/src/druntime/import/core/exception.d)
import core.vararg (/usr/share/dmd/src/druntime/import/core/vararg.d)
import core.stdc.stdlib (/usr/share/dmd/src/druntime/import/core/stdc/stdlib.d)
import core.stdc.string (/usr/share/dmd/src/druntime/import/core/stdc/string.d)
import std.algorithm (/usr/share/dmd/src/phobos/std/algorithm.d)
import std.functional (/usr/share/dmd/src/phobos/std/functional.d)
import std.traits (/usr/share/dmd/src/phobos/std/traits.d)
import std.typetuple (/usr/share/dmd/src/phobos/std/typetuple.d)
import std.conv (/usr/share/dmd/src/phobos/std/conv.d)
import std.array (/usr/share/dmd/src/phobos/std/array.d)
import core.memory (/usr/share/dmd/src/druntime/import/core/memory.d)
import core.bitop (/usr/share/dmd/src/druntime/import/core/bitop.d)
import std.ascii (/usr/share/dmd/src/phobos/std/ascii.d)
import std.exception (/usr/share/dmd/src/phobos/std/exception.d)
import std.c.string (/usr/share/dmd/src/phobos/std/c/string.d)
import std.range (/usr/share/dmd/src/phobos/std/range.d)
import std.typecons (/usr/share/dmd/src/phobos/std/typecons.d)
import core.stdc.errno (/usr/share/dmd/src/druntime/import/core/stdc/errno.d)
import std.uni (/usr/share/dmd/src/phobos/std/uni.d)
import std.internal.unicode_tables (/usr/share/dmd/src/phobos/std/internal/unicode_tables.d)
import std.math (/usr/share/dmd/src/phobos/std/math.d)
import core.stdc.math (/usr/share/dmd/src/druntime/import/core/stdc/math.d)
import std.utf (/usr/share/dmd/src/phobos/std/utf.d)
import std.format (/usr/share/dmd/src/phobos/std/format.d)
import std.bitmanip (/usr/share/dmd/src/phobos/std/bitmanip.d)
import std.system (/usr/share/dmd/src/phobos/std/system.d)
import std.c.stdio (/usr/share/dmd/src/phobos/std/c/stdio.d)
import std.stdiobase (/usr/share/dmd/src/phobos/std/stdiobase.d)
import core.sys.posix.fcntl (/usr/share/dmd/src/druntime/import/core/sys/posix/fcntl.d)
import core.sys.posix.config (/usr/share/dmd/src/druntime/import/core/sys/posix/config.d)
import core.sys.posix.sys.types (/usr/share/dmd/src/druntime/import/core/sys/posix/sys/types.d)
import core.sys.posix.sys.stat (/usr/share/dmd/src/druntime/import/core/sys/posix/sys/stat.d)
import core.sys.posix.time (/usr/share/dmd/src/druntime/import/core/sys/posix/time.d)
import core.sys.posix.signal (/usr/share/dmd/src/druntime/import/core/sys/posix/signal.d)
import core.sys.posix.stdio (/usr/share/dmd/src/druntime/import/core/sys/posix/stdio.d)
import allegro5.allegro (allegro5/allegro.d)
import allegro5.base (allegro5/base.d)
import allegro5.altime (allegro5/altime.d)
import allegro5.bitmap (allegro5/bitmap.d)
import allegro5.color (allegro5/color.d)
import allegro5.internal.da5 (allegro5/internal/da5.d)
import allegro5.color_ret (allegro5/color_ret.d)
import allegro5.bitmap_draw (allegro5/bitmap_draw.d)
import allegro5.bitmap_io (allegro5/bitmap_io.d)
import allegro5.bitmap_lock (allegro5/bitmap_lock.d)
import allegro5.blender (allegro5/blender.d)
import allegro5.config (allegro5/config.d)
import allegro5.file (allegro5/file.d)
import allegro5.path (allegro5/path.d)
import allegro5.utf8 (allegro5/utf8.d)
import allegro5.al_debug (allegro5/al_debug.d)
import allegro5.display (allegro5/display.d)
import allegro5.events (allegro5/events.d)
import allegro5.joystick (allegro5/joystick.d)
import allegro5.keyboard (allegro5/keyboard.d)
import allegro5.keycodes (allegro5/keycodes.d)
import allegro5.mouse (allegro5/mouse.d)
import allegro5.timer (allegro5/timer.d)
import std.stdint (/usr/share/dmd/src/phobos/std/stdint.d)
import allegro5.drawing (allegro5/drawing.d)
import allegro5.error (allegro5/error.d)
import allegro5.fixed (allegro5/fixed.d)
import allegro5.fshook (allegro5/fshook.d)
import allegro5.fullscreen_mode (allegro5/fullscreen_mode.d)
import allegro5.memory (allegro5/memory.d)
import allegro5.monitor (allegro5/monitor.d)
import allegro5.mouse_cursor (allegro5/mouse_cursor.d)
import allegro5.system (allegro5/system.d)
import core.thread (/usr/share/dmd/src/druntime/import/core/thread.di)
import core.time (/usr/share/dmd/src/druntime/import/core/time.d)
import core.sys.posix.sys.time (/usr/share/dmd/src/druntime/import/core/sys/posix/sys/time.d)
import core.sys.posix.sys.select (/usr/share/dmd/src/druntime/import/core/sys/posix/sys/select.d)
import core.sys.osx.mach.kern_return (/usr/share/dmd/src/druntime/import/core/sys/osx/mach/kern_return.d)
import core.sys.posix.unistd (/usr/share/dmd/src/druntime/import/core/sys/posix/unistd.d)
import core.sys.posix.inttypes (/usr/share/dmd/src/druntime/import/core/sys/posix/inttypes.d)
import core.stdc.inttypes (/usr/share/dmd/src/druntime/import/core/stdc/inttypes.d)
import allegro5.threads (allegro5/threads.d)
import allegro5.tls (allegro5/tls.d)
import allegro5.transformations (allegro5/transformations.d)
import allegro5.allegro_primitives (allegro5/allegro_primitives.d)
import allegro5.allegro_image (allegro5/allegro_image.d)
import allegro5.allegro_font (allegro5/allegro_font.d)
import allegro5.allegro_ttf (allegro5/allegro_ttf.d)
import allegro5.allegro_color (allegro5/allegro_color.d)
import allegro5.allegro_color_ret (allegro5/allegro_color_ret.d)
semantic a5test
library dallegro5
library allegro
library allegro_primitives
library allegro_image
library allegro_font
library allegro_ttf
library allegro_color
library allegro
import core.sys.posix.pthread (/usr/share/dmd/src/druntime/import/core/sys/posix/pthread.d)
import core.sys.posix.sched (/usr/share/dmd/src/druntime/import/core/sys/posix/sched.d)
library allegro_primitives
library allegro_image
library allegro_font
library allegro_ttf
library allegro_color
entry main example.d
semantic2 a5test
semantic3 a5test
code a5test
function D main
function a5test.main.__lambda2
function std.stdio.writefln!(string, float, float, float, float).writefln
function std.stdio.File.writefln!(char, float, float, float, float).writefln
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda8
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda9
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda10
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda11
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda12
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda13
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda14
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__lambda15
function std.format.formattedWrite!(LockingTextWriter, char, float, float, float, float).formattedWrite.__dgliteral16
function std.format.formatGeneric!(LockingTextWriter, float, char).formatGeneric
function std.format.formatValue!(LockingTextWriter, float, char).formatValue
function std.format.formatValue!(LockingTextWriter, float, char).formatValue.__lambda4
function std.format.formatValue!(LockingTextWriter, float, char).formatValue.__dgliteral5
function std.format.formatValue!(LockingTextWriter, float, char).formatValue.__dgliteral6
function std.range.put!(LockingTextWriter, const(char)).put
function std.range.doPut!(LockingTextWriter, const(char)).doPut
function std.stdio.File.LockingTextWriter.put!(const(char)).put
function std.array.popFront!(immutable(char)).popFront
function std.utf.decode!string.decode
function std.utf.decodeImpl!(true, string).decodeImpl
function std.utf.decodeImpl!(true, string).decodeImpl.invalidUTF
function std.utf.decodeImpl!(true, string).decodeImpl.outOfBounds
function std.utf.decodeImpl!(true, string).decodeImpl.exception!string.exception
function std.array.save!(immutable(char)).save
function std.array.popBack!(immutable(char)).popBack
function std.utf.strideBack!string.strideBack
function std.array.back!(immutable(char)).back
function std.algorithm.find!("a == b", string, char).find
function std.algorithm.find!("a == b", string, char).find.trustedMemchr
function std.algorithm.find!("a == b", string, char).find.trustedFindRR
function std.utf.canSearchInCodeUnits!char.canSearchInCodeUnits
function std.array.popFront!char.popFront
function std.utf.decode!(char[]).decode
function std.utf.decodeImpl!(true, char[]).decodeImpl
function std.utf.decodeImpl!(true, char[]).decodeImpl.invalidUTF
function std.utf.decodeImpl!(true, char[]).decodeImpl.outOfBounds
function std.utf.decodeImpl!(true, char[]).decodeImpl.exception!(char[]).exception
function std.array.save!char.save
function std.functional.binaryFun!("a == b").binaryFun!(dchar, dchar).binaryFun
function std.algorithm.find!("a == b", string, char[]).find
function std.array.empty!ubyte.empty
function std.array.popFront!ubyte.popFront
function std.array.front!ubyte.front
function std.array.save!ubyte.save
function std.functional.binaryFun!("a == b").binaryFun!(ubyte, ubyte).binaryFun
function std.array.popBack!ubyte.popBack
function std.array.back!ubyte.back
function std.algorithm.find!("a == b", ubyte[], ubyte[]).find
function std.range.walkLength!(ubyte[]).walkLength
function std.algorithm.startsWith!("a == b", ubyte[], ubyte[]).startsWith
function std.range.put!(LockingTextWriter, char[]).put
function std.range.doPut!(LockingTextWriter, char[]).doPut
function std.stdio.File.LockingTextWriter.put!(char[]).put
function std.stdio.File.LockingTextWriter.put!(char[]).put.__dgliteral2
function std.stdio.File.LockingTextWriter.put!(char[]).put.__foreachbody3
function std.exception.errnoEnforce!(int, "/usr/share/dmd/src/phobos/std/stdio.d", 1940LU).errnoEnforce
function std.stdio.File.LockingTextWriter.put!dchar.put
function std.format.FormatSpec!char.FormatSpec.writeUpToNextSpec!(LockingTextWriter).writeUpToNextSpec
function std.format.FormatSpec!char.FormatSpec.writeUpToNextSpec!(LockingTextWriter).writeUpToNextSpec.__dgliteral2
function std.range.put!(LockingTextWriter, const(char)[]).put
function std.range.doPut!(LockingTextWriter, const(char)[]).doPut
function std.utf.decode!(const(char)[]).decode
function std.utf.decodeImpl!(true, const(char)[]).decodeImpl
function std.utf.decodeImpl!(true, const(char)[]).decodeImpl.invalidUTF
function std.utf.decodeImpl!(true, const(char)[]).decodeImpl.outOfBounds
function std.utf.decodeImpl!(true, const(char)[]).decodeImpl.exception!(const(char)[]).exception
function std.stdio.File.LockingTextWriter.put!(const(char)[]).put
function std.stdio.File.LockingTextWriter.put!(const(char)[]).put.__dgliteral2
function std.stdio.File.LockingTextWriter.put!(const(char)[]).put.__foreachbody3
function std.format.getNthInt!(float, float, float, float).getNthInt
function std.format.getNthInt!(float, float, float).getNthInt
function std.format.getNthInt!(float, float).getNthInt
function std.format.getNthInt!(float).getNthInt
function std.format.getNthInt!().getNthInt
function std.conv.to!int.to!(int).to
function std.conv.toImpl!(int, int).toImpl
function std.format.formatNth!(LockingTextWriter, char, float, float, float, float).formatNth
function std.format.formatNth!(LockingTextWriter, char, float, float, float, float).formatNth.gencode!4LU.gencode
function std.conv.to!string.to!(ulong).to
function std.conv.toImpl!(string, ulong).toImpl
function std.conv.toImpl!(string, ulong).toImpl
function std.conv.toImpl!(string, ulong).toImpl.__dgliteral4
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!(25LU, 10, true).toStringRadixConvert
function std.conv.unsigned!ulong.unsigned
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!(24LU, 10).toStringRadixConvert
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!(16LU, 16).toStringRadixConvert
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!(64LU, 2).toStringRadixConvert
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!(24LU, 8).toStringRadixConvert
function std.conv.toImpl!(string, ulong).toImpl.toStringRadixConvert!48LU.toStringRadixConvert
function std.stdio.File.LockingTextWriter.put!char.put
gcc example.o -o example -m64 -L. -L/usr/share/dmd/lib -ldallegro5 -lallegro -lallegro_primitives -lallegro_image -lallegro_font -lallegro_ttf -lallegro_color -lphobos2 -lpthread -lm
ld: library not found for -lallegro
clang: error: linker command failed with exit code 1 (use -v to see invocation)
--- errorlevel 1
Joels-MacBook-Pro:DAllegro5 joelcnz$

ALLEGRO_SAMPLE issue.

I was getting compiler problems (D2.057) with ALLEGRO_SAMPLE in allegro_audio.d, due to it
being a forward reference of a unidentified struct, simply changing it solves this.

Note: When i was using pointers to ALLEGRO_SAMPLE i was not having a issue, this only cropped up
when i was trying to use them in an array.

old:
struct ALLEGRO_SAMPLE;

new:
struct ALLEGRO_SAMPLE { }

Doesn't compile on Mac OS X 10.8.2

When trying to compile I get the following error message:
allegro5/file.d(25): Error: module freebsd is in file 'std/c/freebsd/freebsd.d' which cannot be read
import path[0] = /usr/local/Cellar/dmd/2.060/src/phobos
import path[1] = /usr/local/Cellar/dmd/2.060/src/druntime/import

Neither of these two modules paths exist on my system.

in both std/c/freebsd/ and std/c/osx/ there is only one file called socket.d

I'v got allegro 5.0.7 and dmd 2.060 (both from the Homebrew repositories) installed

al_create_display crash on 5.1 branch

example.d crashes on al_create_display on the 5.1 branch.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b3bb7f in al_create_display () from /usr/lib/liballegro.so.5.1
(gdb) bt
#0  0x00007ffff7b3bb7f in al_create_display () from /usr/lib/liballegro.so.5.1
#1  0x000000000042ea54 in a5test.main(char[][]).__lambda2() ()
#2  0x0000000000434638 in allegro5.system.al_run_allegro(scope int() delegate).main_runner(int, char**) ()
#3  0x000000000043461d in allegro5.system.al_run_allegro(scope int() delegate) ()
#4  0x000000000042ea25 in D main ()

The C demos included with allegro 5.1 all run fine for me, so I don't think its an issue with allegro itself.
I can try to compile allegro5.1 in debug mode if that would help get more information on where in al_create_display its crashing.

Platform is Archlinux x86_64, using allegro master branch.

link error (dub windows)

What do I put for this - using dub?

lld-link: error: could not open '+..\DAllegro5\lib': no such file or directory
...
Then it lists a whole bunch of lib files not existing.

I have DAllegro source files and lib files there.

Executing example Ubuntu 12.04

I've installed Allegro 5.0.7 for C, (eg the examples there work). But when I try to run the example for DAllegro5 I get this:

./example: error while loading shared libraries: liballegro.so.5.0: cannot open shared object file: No such file or directory

I don't know if it's because I'm running Ubuntu in a virtual machine in OSX.

`in`-Parameters in `extern(C)`: Many Warnings Since DMD 2.104.0

DAllegro5 4.0.4 for Allegro 5.2.0

The D keyword in for function parameters means scope const ref and DMD 2.104.0, released 2023-06-01, is beginning to warn about using in during extern(C). More information:

Using DMD 2.104.0, DAllegro5 now builds with many warnings:

Starting Performing "unittest" build using /usr/bin/dmd for x86_64.
Building allegro 4.0.4+5.2.0: building configuration [allegro-test-no-libs]
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `expr` declared as `in` here
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `file` declared as `in` here
allegro5/al_debug.d(5,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(5,7):        parameter `func` declared as `in` here
allegro5/al_debug.d(6,7): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/al_debug.d(6,7):        parameter `__anonymous_param` declared as `in` here
allegro5/bitmap_io.d(18,2): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/bitmap_io.d(18,2):        parameter `filename` declared as `in` here
allegro5/bitmap_io.d(20,2): Deprecation: using `in` parameters with `extern(C)` functions is deprecated
allegro5/bitmap_io.d(20,2):        parameter `filename` declared as `in` here
[... many more of these ...]

Unsafe with macOS

With just the example program (build dmd one, though I was testing my own program separately). It can interrupt the OS, having just the mouse pointer moving and having to reset the computer (holding down the power button on the machine).

New tag for warning fixes

It would be nice to have a new tag (or tags, for 5.0/5.1) for the fix introduced by aebafd3.

Tagged versions are a bit nicer to use with dub (dub complains about branch version specifications).

lib files

I can't get the right lib files.

I've downloaded MSVC 11 files from allegro.cc website. I tried the lib files from MSVC, and got 'Error 43: Not a Valid Library File'. 'create_import_libs.bat' doesn't seem to do any thing.

Thanks for any help.

Zero-cost const D wrapping of non-const C function, sane?

Consider al_get_bitmap_width(ALLEGRO_BITMAP* b). This function doesn't mutate b and should ideally be callable with a const(ALLEGRO_BITMAP)* in usercode.

Allegro 5 doesn't offer a const-correct API, but DAllegro5 has C linkage which looks only at the function's name. const is merely a noble compile-time check in C. :-P I've abused this, and changed my local DAllegro5 to declare like this:

nothrow @nogc extern (C) {
    al_get_bitmap_width(in ALLGERO_BITMAP* b);
}

mixin(ColorWrapper("allegro5.color_ret.", "al_get_pixel",
    "const(ALLEGRO_BITMAP)* bitmap, int x, int y",
    "cast(ALLEGRO_BITMAP*) bitmap, x, y"));

I.e., I added in before the bitmap arguments.

Problems: I assume A5 will never modify *b. A5 doesn't promise this (it is not const-correct) and the wrapper has no chance to detect an eventual change in A5, even though this is unlikely. I didn't get linker errors (Arch 64-bit, building with dmd), that makes me very happy, but who knows if some system out there will check more harshly.

Would you consider such a modification sane for production? Or should const-correct user code cast its const bitmaps to mutable bitmaps before calling DAllegro5?

If this is sane, what functions would be OK to call with const bitmaps to not break any D const promises? Getting height and width, most likely. Maybe also drawing from const bitmap to nonconst bitmap?

Handy stuff

The functions and stuff below are handy so you can put in your main program loop, for example:

poll_input();
if (key[ALLEGRO_KEY_Q])
    return 0;

I found them in an Allegro demo that came with the library, and made them work in D.

import std.stdio;
import std.range;
import core.stdc.string;

const MAX_KEYBUF = 16;

int[ALLEGRO_KEY_MAX] key;
static int[MAX_KEYBUF] keybuf;
static int keybuf_len = 0;
static ALLEGRO_MUTEX* keybuf_mutex;

/**
 * Eg.
 * ---
 * scope(exit) Deinit();
 * ---
*/
void Deinit( string message = "" ) {
	shutdown_input;

	if ( ! message.empty )
		writeln( message );
}

/** initialises the input emulation */
void init_input()
{
   keybuf_len = 0;
   keybuf_mutex = al_create_mutex();
   assert(keybuf_mutex);
}

/** closes down the input emulation */
void shutdown_input()
{
	scope( success )
		writeln( "shutdown_input successfully" );
   al_destroy_mutex(keybuf_mutex);
   keybuf_mutex = null;

   g_queue = null;
}

/** helper function to add a keypress to a buffer */
static void add_key(ALLEGRO_KEYBOARD_EVENT* event)
{
   if ((event.unichar == 0) || (event.unichar > 255))
      return;

   al_lock_mutex(keybuf_mutex);

   if (keybuf_len < MAX_KEYBUF) {
      keybuf[keybuf_len] = event.unichar | ((event.keycode << 8) & 0xff00);
      keybuf_len++;
   }

   al_unlock_mutex(keybuf_mutex);
}

/** emulate poll_keyboard() and poll_joystick() combined */
void poll_input()
{
   ALLEGRO_EVENT event;

   while (al_get_next_event(g_queue, &event)) {

      switch (event.type) {

	 case ALLEGRO_EVENT_KEY_DOWN:
	    key[event.keyboard.keycode] = 1;
	    break;

	 case ALLEGRO_EVENT_KEY_UP:
	    key[event.keyboard.keycode] = 0;
	    break;

	 case ALLEGRO_EVENT_KEY_CHAR:
	    add_key(&event.keyboard);
	    break;

	 case ALLEGRO_EVENT_TIMER:
	    /* retrace_count incremented */
	    break;

	 case ALLEGRO_EVENT_DISPLAY_EXPOSE:
	    break;
	  default:
	  break;
      }
   }
}

/** blocking version of poll_input(), also wakes on retrace_count */
void poll_input_wait()
{
   al_wait_for_event(g_queue, null );
   poll_input();
}

/** emulate keypressed() */
int keypressed()
{
   poll_input();

   return keybuf_len > 0;
}

//#works differently than I was expecting
/** emulate readkey(), except this version never blocks */
int readkey()
{
   int c = 0;

   poll_input();

   al_lock_mutex(keybuf_mutex);

   if (keybuf_len > 0) {
      c = keybuf[0];
      keybuf_len--;
      
      memmove(keybuf.ptr, keybuf.ptr + 1, keybuf[0].sizeof * keybuf_len);
   }

   al_unlock_mutex(keybuf_mutex);

   return c;
}

/** emulate clear_keybuf() */
void clear_keybuf()
{
   al_lock_mutex(keybuf_mutex);

   keybuf_len = 0;

   al_unlock_mutex(keybuf_mutex);
}

update to allegro 5.2?

What does it take to update the bindings to 5.2?

For the record, I've just tried taking 5.1 branch and changing the version number.
Then, the little functionality I use worked as before against 5.2.0 binaries.

segfault ubuntu + ldc2

I just downloaded a fresh LDC2, compiled it, and then tried both DAlleg and DAlleg unstable, and they both compile fine but segfault when running the example program.

Program received signal SIGSEGV, Segmentation fault.

al_create_display (w=500, h=500) at /home/[USER]/Downloads/allegro-5.1.11/src/display.c:47

47 driver = system->vt->get_display_driver();

(gdb) bt
#0 al_create_display (w=500, h=500) at /home/[USER]/Downloads/allegro-5.1.11/src/display.c:47
#1 0x0000000000402c3a in a5test.main() ()
#2 0x0000000000425c1e in allegro5.system.al_run_allegro() ()
#3 0x0000000000425bf4 in allegro5.system.al_run_allegro() ()
#4 0x0000000000402bee in D main ()
#5 0x0000000000414814 in _d_run_main ()
#6 0x0000000000409a98 in main ()

---> It appears that al_init() is returning 0 and the example program does not check for this condition. Of course, why it's failing on my system is huge question.

I have a 5.1.11 Allegro 5 program compiling and running just fine on my system. (Just checked again to be sure.)

[edit] I added a version writefln statement. It reports 5.1.11.1. Which is the exact same version I'm compiling my C++ one in.

[edit] Okay, I'm stepping through with gdb and it looks like:

83888641 - version
83954433 - library version

But in my C++ program it reports:

83954433
83954433

Strange indeed...

Perhaps DAlleg has slightly older Allegro headers?

Bigger programs crashing in OSX

Smaller programs work, (though seem to be slower and sound lag, compared to Windows).

I think it's todo with the version of GCC, it's old. But I'm not sure what I can do about it.

I head some thing about problems with returning structs. I used a different method to make colours.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.