My game compiles in MSVC and gcc on Windows so I tried to see if it would compile in Linux. I'm running Ubuntu 9.04, gcc 4.3.3, allegro 4.2. The hello world compiled and ran so I confirmed Allegro was working however when compiling my program it came up with 4 errors compiling Mappy.c. I didn't change Mappy or anything just downloaded it and using it as is. The 4 errors I got were:
error: lvalue required as left operand of assignment
error: lvalue required as left operand of assignment
error: lvalue required as left operand of assignment
error: lvalue required as left operand of assignment
I don't fully understand what the error means; anyone care to help me re-write this so it'll compile or is something more difficult then re-writing these 4 lines of code? Thanks!
It seems that the result of a cast (to non-reference type) is not a left-value, i.e something that you can assign to (although some compilers may disagree, particularly MSVC is known for its relaxedness regarding templates and lvalues/rvalues). A possible solution: declare a pointer, so you won't have to cast in the assignment, or cast to reference to pointer?
You should cast the rvalue to be of the same type as the lvalue pointer, not the other way around as in that code.
if you're using C++ then I'd recommend you use the 'combined' playback library (http://www.tilemap.co.uk/mappy.php) as it's C++ and separates the core of mappy from the graphics library. This won't have the issue as it is this now:
myblkstrpt->bgoff = (int) abmTiles[myblkstrpt->bgoff];
So do what Evert says, which is essentially what the above code does.
For anyone's reference,
bgoff is a long int
abmTiles is a BITMAP**
Hmm... so is that code assuming that a pointer will fit in a long int? In general, that is a bad (unsafe) assumption to make... although it happens to work properly for the time being.
The newer version has it as just an int, hence the cast in my suggested solution. Whether this (long to int) makes it worse or better, I don't know.
@Neil- are you the same Neil from the tilemap.co.uk forum? I'm using C and not C++... is there any other way?
@anonymous- Thank you I'll try your suggestion
Thank you so much for responding everyone!
Update:
@Neil - is this what you meant?
I changed the 4 errors from this:
((BITMAP *) myblkstrpt->fgoff) = abmTiles[myblkstrpt->fgoff];
To this (respectively):
(myblkstrpt->fgoff) = (int)abmTiles[myblkstrpt->fgoff];
It compiled and the mappy demo worked; however my game did not. I get a segmentation fault. This didn't have in MSVC 9 or gcc 3.4.5 on Windows but I tracked it down to a variable not being initialized (because it was NULL) and then passed to draw_sprite. This has been fixed and now the game works just fine with the exception of not having any sound. The .wav files play just fine in ubuntu but are not playing in allegro. I'll have to research this more and post a question later if I can't find a resolution.
Thanks again for eveyone's suggestions!