Allegro.cc - Online Community

Allegro.cc Forums » The Depot » A framework thingy with animations and stuff and yummy XML seutp

This thread is locked; no one can reply to it. rss feed Print
A framework thingy with animations and stuff and yummy XML seutp
Neil Walker
Member #210
April 2000
avatar

Hello,
If anyone's interested I've just finished the third and final part to my AXL project, the Framework. The framework contains a graphics repository, animation playback (looping, fading, countdown, etc), sound management, allegro startup, configuration control, management and control of a FPS based loop. It supports triple/double buffering, paging, video/system/memory bitmaps transparently and a few other things, all with just a teeny weeny amount of coding required. Most things are initially managed via XML. Anyway, if you want to read before you try, http://retrospec.sgn.net/users/nwalker/axl/

As an example, assume I have a sprite with a series of animated frames and I want to animate it at 60FPS. I also want the program to run with triple buffering and I want the Framework to control the whole thing, calling everything at the right time. I also want it to intelligently load the graphics (such as stop VRAM->MEM transfers, obtain the best graphics mode if triple buffering isn't supported, etc). The code avoid error handling, etc. has been omitted.

1#include "axl_framework.h"
2using namespace AXL_Projects;
3 
4static Framework* GameFramework;
5static AnimationLibrary* GameLibrary;
6static Animation* BillyTheFish;
7 
8int main()
9{
10 //this constructor loads up the graphics and configurations
11 //it also starts up allegro and initialises the buffers, etc
12 GameFramework=new Framework("config.xml","animations.xml");
13
14 GameLibrary=GameFramework->GetGraphicsLibrary(); //link to the graphics
15 BillyTheFish=new Animation(GameLibrary,"billy");
16 
17 //this tells the framework to run everything for us
18 //the parameters are the hooks I'm using
19 GameFramework->StartGameLoop( LogicGame,DrawingGame, NULL, NULL, NULL, NULL,true));
20 
21 //after this the game has quit
22 delete BillyTheFish;
23 delete GameFramework;
24}
25 
26//these are our callback hooks and the Framework calls these when it needs to
27bool LogicGame()
28{
29 //does everything like update the animation, faders, countdowntimers, etc.
30 BillyTheFish->NextMove();
31}
32bool DrawingGame()
33{
34 //drawingsurface is the drawing buffer we always draw to
35 clear_to_color(GameFramework->DrawingSurface,makecol(0,0,0));
36 //after nextmove the currentitem is the correct modified bitmap for this object
37 blit(BillyTheFish->CurrentItem,GameFramework->DrawingSurface,0,0,0,0,w,h);
38}

And that's it for a complete timer based loop with little allegro coding.

You can find the download at:
http://retrospec.sgn.net/game.php?link=axl

It's quite simple and there are samples for all the three parts, with make files for devcpp and msvc

If anyone's interested in what exactly goes on in the configuration config.xml file that sets everything up:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <system fps="60" debugon="1" autowritemain="0" autowritecustom="0" 
    enablejoystick="0" enablekeyboard="1" enablemouse="1" enablesound="1" enablemidi="1"
    matchrefreshrate="1"
  />
    <graphics vsync="0" graphicsmode="3" depthpreferred="32" depthfallback="16" capbmptype="0"
  />
    <window width="640" height="480" autodetect="windowed" />
    <sound maxvoicearray="32" samplevolume="150" musicvolume="128" />
    <custom name="message" valuestring="Hi Mam" />
</config>

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

nonnus29
Member #2,606
August 2002
avatar

I'm very interested in this project, but I'm not coding anything with allegro (or c/c++) at the moment. I would like to try it one day though.

This would be an ideal resource to use in the upcoming TINS.

Rodrigo Monteiro
Member #4,373
February 2004
avatar

You can't use it on TINS, actually, because of the time availability rule. If you COULD, then I'd also want to upload an updated version of Halley, which is my framework, and part of the reason that I probably won't join TINS (I don't want to use the outdated one)

_____________________________
a.k.a amz, a.k.a. ArchMage ZeratuL
[Aegisub] - [TINS05: Lord of the Stars] [SH05: Bunkermaster] [SH07: Fury of the Sky God] [TINS08: All Yar Base Arr Belong To Us (with codnik)] [SH09: Xtreme Programming: The Literal Game]

Marcello
Member #1,860
January 2002
avatar

Rodrigo: Apparently you can, for libraries. The 4 week thing is for code you don't release, I believe.

Marcello

Rodrigo Monteiro
Member #4,373
February 2004
avatar

Well, amarillion said "available in the depot", which Halley isn't. I guess I'll need to ask him.

_____________________________
a.k.a amz, a.k.a. ArchMage ZeratuL
[Aegisub] - [TINS05: Lord of the Stars] [SH05: Bunkermaster] [SH07: Fury of the Sky God] [TINS08: All Yar Base Arr Belong To Us (with codnik)] [SH09: Xtreme Programming: The Literal Game]

Neil Walker
Member #210
April 2000
avatar

Well, my AXL project has been in the depot for a while now, before TINS was even mentioned. This last release is just a code increment ;)

So this 4 week thing is quite interesting - what happens if, say, you use FBlend (from about 2002) but Bob puts up a newer version a few days before TINS to make stuff faster and add a few extra blenders? does this mean you have to use the earlier version only?

If anyone's interested I'm knocking up a demo game (a tile based racing game based on an old game called TranzAm) and have saved the incremental versions, if anyone is interested in a tutorial on making a simple tile based scrolling game?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

CGamesPlay
Member #2,559
July 2002
avatar

Does it have a facility to use a different file system handler? I want to be able to load from Allegro packfiles, as well as from a custom VFS I have :)

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Neil Walker
Member #210
April 2000
avatar

No, just bitmap files. I only ever wanted it to read graphics from single and sheet files to make the XML file simple. Adding other formats would mean a much more complicated XML format.

Although saying that, ultimately the file you specify in the XML just gets passed into a load_bmp type function, and don't these functions support stuff like "file.dat#graphic" ?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

CGamesPlay
Member #2,559
July 2002
avatar

Yes, but I'd be more interested in being able to install hooks. If the library will only ever load bitmap files, then I'd like to be able to give XML configuration via a const char* (or const std::string&) paramter, and a BITMAP* (*my_load)(const char*) parameter.

Framework::Framework(const std::string& config, const std::string& animations, BITMAP* (*load)(const char*))

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Neil Walker
Member #210
April 2000
avatar

At the minute, at the graphic frame level I do this:

this->Image=load_bmp(filename.c_str(),NULL);

Is your change simply a matter of

if(load)
this->Image=load(.....);
else
this->Image=load_bmp(filename.c_str(),NULL);

where "load" is your function pointer

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Rick
Member #3,572
June 2003
avatar

When I try to extract I get and error:

There is a CRC error on file: axl.h and axl_animations.cpp

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

Neil Walker
Member #210
April 2000
avatar

I've just tried it and it works fine, there's been a few downloads and no one else has mentioned it.

Maybe it was corruption on downloading? try it again, it should work. I zipped it using winrar and all the default settings and have tried it on winrar and 7-z and both download ok.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Rodrigo Monteiro
Member #4,373
February 2004
avatar

Well, if by "the depot" they mean this forum, then I guess I can update Halley.

_____________________________
a.k.a amz, a.k.a. ArchMage ZeratuL
[Aegisub] - [TINS05: Lord of the Stars] [SH05: Bunkermaster] [SH07: Fury of the Sky God] [TINS08: All Yar Base Arr Belong To Us (with codnik)] [SH09: Xtreme Programming: The Literal Game]

CGamesPlay
Member #2,559
July 2002
avatar

No, my code would be a new overload. I want to be able to do something like...

1BITMAP* my_load(const char* filename);
2 
3const char* config = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
4"<config>"
5" <system fps=\"60\" debugon=\"1\" autowritemain=\"0\" autowritecustom=\"0\" "
6" enablejoystick=\"0\" enablekeyboard=\"1\" enablemouse=\"1\" enablesound=\"1\" enablemidi=\"1\""
7" matchrefreshrate=\"1\""
8" />"
9" <graphics vsync=\"0\" graphicsmode=\"3\" depthpreferred=\"32\" depthfallback=\"16\" capbmptype=\"0\""
10" />"
11" <window width=\"640\" height=\"480\" autodetect=\"windowed\" />"
12" <sound maxvoicearray=\"32\" samplevolume=\"150\" musicvolume=\"128\" />"
13" <custom name=\"message\" valuestring=\"Hi Mam\" />"
14"</config>";
15 
16const char* animation = "<?xml version=\"you know\" ?>";
17 
18new Framework(config, animation, my_load);

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Neil Walker
Member #210
April 2000
avatar

Actually, that's a really good idea as one of the axl constructors lets you initialise the library without setting up the system so you can override any changes someone makes to the XML before continuing. Your suggestion takes it one step further.

tinyXML has a nice little function TiXmlDocument::Parse that effectively does what you want - it reads from a character stream rather than a file - so that'll avoid having to hard code override values but allows you to not have to distribute XML files.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

CGamesPlay
Member #2,559
July 2002
avatar

Super. Including it will also open up a nice world of possibilities such as reading from zipfiles, and any other interface allegro packfiles have been wrapped around.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

BAF
Member #2,981
December 2002
avatar

How about a more OOP interface, ie, instead of :

 BillyTheFish=new Animation(GameLibrary,"billy");

you do:

 BillyTheFish = GameLibrary->GetAnimation("billy");

CGamesPlay
Member #2,559
July 2002
avatar

Because GameLibrary doesn't need to be a factory for Animation objects? You method isn't more OOP, it just adds extra code to the Framework class for instantiating Animations. Arguably it's even less OOP, because it requires objects to know more about others.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Marcello
Member #1,860
January 2002
avatar

It's a different approach. BAF's suggestion would imply that animation objects are more static (you don't have multiple animation objects for a particular animation), and theoretically it could be optimized in the sense that GetAnimation may simply do a lookup and return an existing class, whereas new Animation makes a new animation. I would say that a more oop method with the same functionality would be GameLibrary.new Animation("billy"), but that's just me. ;)

However, I haven't even looked at the project itself, so I'm not making a comment on which approach is best.

Marcello

Neil Walker
Member #210
April 2000
avatar

Hello,
The answer is quite simple. The Animation class and the Cofigurator class can be used without the Framework. You can just delete the framework files and they still work.

The reason is that you might want a class to handle graphics and animation but not necessarily a full framework for game control, paging, etc.

Similarly the Configurator class can be used by itself for managing an XML configuration file and starting up Allegro.

As for OOP, there are quite a few public data members which of course everyone knows are bad. But there is a choice to be made between hiding everything and making it fast and simple. I chose the latter.

Neil.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Go to: