Python Mugen runtime

Started by Samson, March 19, 2011, 11:06:00 AM

Previous topic - Next topic

Samson

First of all, let's start with a screenshot:

(I hope the image survives for a few days.)
That is a Mugen runtime written in Python I started years ago, but with long interruptions in-between. At that time Elecbyte was not active, and I don't think many alternative engines existed at that point. It is written in pure Python, with OpenGL/pygame for graphics. All the .inf files are parsed, and the state code is internally compiled into a python script before execution. It is surprisingly fast, though converting textures takes a moment. Opposed to ShugenDo the goal is not a next-generation engine, but to target various retro console platforms (eventually, if I can focus for long enough). That'll require compiling all the state code into machine code, but that's a small problem.

So the reason I post here is this: Has anyone worked out in detail which part of the game, especially working out combos, blocks, hit response, etc. are hardwired into the main game, and how much is controlled through character/common1.cns? Based on the state code some of it is done in the script, but I can't find all of it. I'm sure people who actively develop their games on Mugen have some experience on this.

So far my search for tutorials and faqs always came up with the same handful of documents, and I don't really want to rip-off the other engines.

Cyanide

It's not really stuff we memorise tbh. Here's some of the obvious.

Direction keys are hardcoded to send you to states 40, 20, 10 and if you're already jumping, 45. If you're inguarddist and have ctrl back is hardcoded to send you into state 120. 5120 is hardcoded to give you invulnerability if liedown time is < 10. Passing of guard damage is also hardcoded. There is no known way to directly access that number. Turn is hard coded to happen if p2 passes you.

If you are hit dependant on your state type the state you go to is predefined by the engine. You can't tell a standing hit to send p2 to a lying down hitstate etc.

I can't think of much else right now.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.

Samson

Thank you, I already worked out 10, 20 and 40, but I didn't know the rest. Is there any character programming tutorial/FAQ/Wiki that contains this information, or is there a well documented character that people use as starting point? (other than kfm?)

MirageAtoli

Quote from: Samson on March 19, 2011, 11:06:00 AM
but to target various retro console platforms (eventually, if I can focus for long enough).

Which retro consoles did you have in mind for targeting?

Quote from: Samson on March 19, 2011, 11:06:00 AM
That'll require compiling all the state code into machine code, but that's a small problem.

This sounds really cool, if I am reading it correctly. You will end up with characters, etc compiled into a bytecode and not have a CNS interpreter correct?
Quote from: Titiln on December 31, 2007, 10:46:10 PM
i think we should call it an "engine" so we don't look like total idiots because otherwise we'd be arguing about a "game" and that would be somehow "dumber" than arguing about an "engine" on the "internet" for countless hours

Quote from: Beatrice on March 01, 2010, 06:55:03 PM
Quote from: Iced
I for one, do not enjoy round corners!  :bigcry:
But they hurt much less when we accidentally hit them!  :S

Samson

Quote from: MirageAtoli on March 27, 2011, 01:19:27 AM
Which retro consoles did you have in mind for targeting?
Nothing specific, yet. I've got some ideas how to do it for things like NeoGeo or Jaguar, and exploring some more ideas for things like 3DO or N64. I only have some fragments of a background converter for NeoGeo, yet. I'm starting out with getting everything working on my Mac using the Python runtime.
Quote
This sounds really cool, if I am reading it correctly. You will end up with characters, etc compiled into a bytecode and not have a CNS interpreter correct?
Yes. I could create bytecode, but it would be a lot more efficient to create C code that gets translated into machine code. What I'm doing right now is build a huge string with a python equivalent of all CNS code, "import" that from the game code, and then directly jump to the state code when updating a character.
So for example:

[State 5210, 1] ;Blink white
type = PalFX
trigger1 = Time = 0
time = 3
add = 128,128,128 ;256,256,256

[State 5210, 1]
type = PosFreeze
trigger1 = Time = 0
value = 4

[State 5210, 2] ;Turn if not facing opponent
type = Turn
trigger1 = Time = 0
trigger1 = p2dist X < -20

[State 5210, 1]
type = VelMul
trigger1 = Time = 4
x = .8
y = .8

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
y = -4.5

[State 5210, 1]
type = VelMul
trigger1 = Time = 4
trigger1 = Vel Y > 0
y = .5

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
trigger1 = Vel Y > -3
y = -2

[State 5210, 1]
type = VelAdd
trigger1 = Time = 4
trigger1 = Vel Y > -2
y = -1

[State 5210, 2] ;Go up
type = VelAdd
trigger1 = Time = 4
trigger1 = Command = "holdup"
y = -2

[State 5210, 2] ;Go down
type = VelAdd
trigger1 = Time = 4
trigger1 = Command = "holddown"
y = 1.5

[State 5210, 2] ;Go fwd
type = VelMul
trigger1 = Time = 4
trigger1 = Command = "holdfwd"
x = 1

[State 5210, 2] ;Go back
type = VelAdd
trigger1 = Time = 4
trigger1 = Command = "holdback"
x = -1

[State 5210, 3]
type = NotHitBy
trigger1 = Time = 0
value = SCA
time = 15

[State 5210, 4]
type = CtrlSet
trigger1 = Time = 20
value = 1

[State 5210, 5]
type = VelAdd;Gravity
trigger1 = Time >= 4
y = .35

[State 5210, 5] ;Land on ground
type = ChangeState
trigger1 = Vel Y > 0
trigger1 = Pos Y >= 0
value = 52 ;JUMP_LAND
ctrl = 1

gets translated into:
Code (python) Select

def state5210Update(character):
# 1
if (character.time == 0):
character.palfx(time=3, add=(128, 128, 128))
# 1
if (character.time == 0):
character.posfreeze(4)
# 2
if ((character.time == 0) and (character.p2dist_x() < -20)):
character.turn()
# 1
if (character.time == 4):
character.vel_x *= 0.800000
character.vel_y *= 0.800000
# 1
if (character.time == 4):
character.vel_y += -4.500000
# 1
if ((character.time == 4) and (character.vel_y > 0)):
character.vel_y *= 0.500000
# 1
if ((character.time == 4) and (character.vel_y > -3)):
character.vel_y += -2
# 1
if ((character.time == 4) and (character.vel_y > -2)):
character.vel_y += -1
# 2
if ((character.time == 4) and character.command("holdup")):
character.vel_y += -2
# 2
if ((character.time == 4) and character.command("holddown")):
character.vel_y += 1.500000
# 2
if ((character.time == 4) and character.command("holdfwd")):
character.vel_x *= 1
# 2
if ((character.time == 4) and character.command("holdback")):
character.vel_x += -1
# 3
if (character.time == 0):
character.nothitby(0, 15, "sca", [])
# 4
if (character.time == 20):
character.ctrlset(1)
# 5
if (character.time >= 4):
character.vel_y += 0.350000
# 5
if ((character.vel_y > 0) and (character.pos_y >= 0)):
character.ctrlset(1)
character.changestate(52)
return

The difficulty I have left is finishing it up with all the framework code that is handled inside the engine.