A question requiring programming knowledge about ags animated sprites

Started by majicpotion, Tue 19/08/2014 21:20:53

Previous topic - Next topic

majicpotion

I'm interested in learning about the big picture of how ags works. If you understand how to read the ags source code for the game engine, can you please answer a couple of questions for me?

1. AGS is written using allegro - is this all that is necessary for the graphics capabilities? or are there other extensions to the programming api?

2. In this style of game engine, you click on a point in the screen and your character walks there. The concept is simple, as there is a sprite sheet that is cycled through as the character moves. Can someone explain, not necessarily in actual code (but it helps if you can point it out in the source), how this is done with allegro. How is this motion timed? The heart of a point and click adventure is the ability to move a character on the screen while there are other animated sprites. How does ags actually do it under the hood?

The source code base for ags is huge, so many files, that it's not simple enough for me to figure out where to look for relevant code snippets. I'm not a professional programmer, but I have been looking at animation and animated
sprites and I wanted to know how difficult it would be to actually plan a feature such as this, that is fundamental to point and click adventures. I currently am practicing with visual c# and basic, and I am trying some code
snippets in c and c++.

A little more about me -> I have not completed a point and click adventure yet, and I'm trying out ags. I'm not currently working on a game, just learning about game development. I hope this is the right place to ask.

Crimson Wizard

In AGS character animation is not done using Allegro. Allegro is used only for very low-level routines, such as working with bitmaps and receiving control input.
Additionally, Microsoft's Direct3D9 and OpenGL interfaces are used to render sprites on screen. Depending on user selection, one of the three renderers (Software renderer using just Allegro, Direct3D9 and OpenGL) is working.

I am not sure you should look into AGS for reference: AGS code is very old, has confusing architecture, and not always written in good style and optimal way. If you plan is not about working with AGS code, but writing your own, I'd rather suggest you NOT take AGS as an example, really.
I am dead serious about this, believe me, I am hacking in AGS code for two years now :).
I believe there might be many other games and engine that are much more clear and simplier to comprehend, and will be more use to you, in terms of design and code snippets.



As for animation, it is simplier that it may feel at first.

To describe an animation you need a data structure defining a sequence of frames.
Each frame has at least two properties: a reference to sprite (or part of sprite) and a delay (in time units). Whether the sprites are contained in animation itself, or just referenced is a program design choice.

For every game entity you have a (abstractly speaking) "animation runner" object, that keeps a 1) reference to current animation, 2) reference (e.g. index) of current frame, and 3) the time passed since current frame was selected.

The timing in games is usually processed in the single main loop. Basically, in concept, this looks like:
1. At the start remember current time.
2. Run game logic for single "tick" <--- pass number of milliseconds you want your game process simulate
3. Redraw the current game state
4. Calculate how much time has passed since (2). If it is less than your chosen tick time, then put game into sleep until next tick time is reached.
Some games/engines I knew also could temporarily decrease next tick time, if the previous tick took too long to process for any reason. This helped the game to keep it up with the time (more or less).
5. Repeat from (2), unless user ordered to quit.

The "tick time" you pass to your main logic procedure is passed further into every game object (world, enviroment, characters, objects, GUI, etc etc), so that every thing updates itself by the same amount of time.
This way it comes to the animated object and passed into the "animation runner" I mentioned above.
The "animation runner" summs up time passed since last frame with the "tick time". If the resulting time is equal or bigger than the frame's delay property, then it iterates to the next frame.

When object is drawn on screen, it refers to its "animation runner" to get current sprite, using current animation and frame id.

So it works, in general, although the implementation may vary. This is, abstractly, how AGS does it too.

I hope it is what you were asking for, if not, than pardon me.
Probably other ppl will have what to say too. I know there are forum members around who created their own engines in the past.

majicpotion

Exactly what I was asking about. It's actually the solution that I understood also, except for the part about Alegro. I can't figure something out though. If GDI+ DirectX and OpenGL use the same concept. Is there really a performance gain using DirectX and OpenGL? I was playing around with ags and noticed that character motion is smooth mostly dependent on how well each frame is animated for a walkcycle for example. If I have a static object move around screen, than it just jumps from frame to frame as it walks. Is there a magic timeframe between frames? I never found anything in ags that let me set the frame timing, so I figure it's all static under the hood. Is that right? and is there a good number that is the same between renderers?

Crimson Wizard

Quote from: magicmirror on Tue 19/08/2014 22:12:00
Exactly what I was asking about. It's actually the solution that I understood also, except for the part about Alegro. I can't figure something out though. If GDI+ DirectX and OpenGL use the same concept. Is there really a performance gain using DirectX and OpenGL?
Yes, there is. Same concept does not mean same results. Direct3D9 and OpenGL use hardware acceleration at least for part of drawing, meaning that your graphics card (GPU) will take care of it = more processing power.
Software renderer does everything in the common program code, significantly increasing CPU load. It is not uncommon when high-resolution AGS game uses 90-100% of a single CPU core with software renderer.
Also, scaling is done much faster with hardware acceleration, because D3D & OpenGL work with textures, rather than raw bitmaps that require copying and converting data all the time.

Quote from: magicmirror on Tue 19/08/2014 22:12:00If I have a static object move around screen, than it just jumps from frame to frame as it walks. Is there a magic timeframe between frames? I never found anything in ags that let me set the frame timing, so I figure it's all static under the hood.
If you mean global game frame time, then it is SetGameSpeed script function.
If you mean animation frame, the delays are set in the VIEWs editor. And every character has its own animation speed properties. As for room objects, they are not really designed to play "walking" animation, so some extra scripting may be required.

majicpotion

Ok, you really cleared that up for me. I just discovered, that I had a different and incorrect understanding of some of the concepts. Thanks for that. This gives me a good perspective to try some code snippets.

One more question - You mentioned other engines (not specifically). Can you recommend an open source engine I might look at that has more modern up to date code as you said? That might not be too complex to digest? If it is, I will try anyway.

Alberth

Another reason for having Allegro is the age of the software. It was written before 3D video cards with hardware acceleration were commonly used.

Crimson Wizard

Quote from: magicmirror on Tue 19/08/2014 23:50:10
One more question - You mentioned other engines (not specifically). Can you recommend an open source engine I might look at that has more modern up to date code as you said? That might not be too complex to digest? If it is, I will try anyway.
Hmmm... I don't have much links at hand now, to be honest.
Someone mentioned this open-sourced adventure engine written in Java: http://www.adventuregamestudio.co.uk/forums/index.php?topic=50844.0
Also, here's an arcade game written by AGSer in LUA script language: https://github.com/CalinLeafshade/riseofthefallen
may be interesting, for example, to see how various character states & animations may be implemented. If you don't know Lua syntax, you may look at this as on pseudo-code.

Snarky

Wintermute is open source (see here). No idea about the quality of the code.

SMF spam blocked by CleanTalk