Archetype files

The first thing we need to do is look at how we define our object archetype within a file. The Mach5 Engine uses .ini files for archetypes, levels, and anything related to initialization of the engine. A more standard file format would be XML or JSON if you wanted to keep them as human readable and modifiable. If you didn't want them to be modified by users, the files could always be saved as binary.

We have chosen .ini files because they are easy to read by both humans and a computer program. They only have a few simple rules, so they are easy to explain in just a few sentences. They only contain named sections which are defined by square brackets [ ], and key value pairs in the form of key = value. The only exception is the global section, which doesn't have a name and therefore no square brackets. Let's look at a basic example of an Archetype file. This is an example of Player.ini:

posX       = 0 
posY = 0
velX = 0
velY = 0
scaleX = 10
scaleY = 10
rot = 0
rotVel = 0
components = GfxComponent PlayerInputComponent ColliderComponent

[GfxComponent]
texture = playerShip.tga
drawSpace = world

[PlayerInputComponent]
forwardSpeed = 100
speedDamp = .99
bulletSpeed = 7000
rotationSpeed = 10

[ColliderComponent]
radius = 5

As you can see, the global section of the Player.ini file contains values for everything variable that is defined in M5Object. Except for the components key, everything is read in the FromFile method of the M5Object. In this case, most of our starting values are zero. This is because things like the starting position for the player object will depend on the level, so this data will be modified after creation.

The more important part is the components. The components key contains a list of components that the object will use. These strings will be used by the M5ObjectManager to create a component and then read the specific component data defined in each section. This allows us to reuse components, such as the ColliderComponent, because each object that uses them can have different component data. In this case, the player object will have a radius of 5, but a bullet might have a radius of 1.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.145.82