Skip to content

Documentation

Garrett Fairburn edited this page Aug 31, 2019 · 1 revision

Engine

The rendascii.interface.Engine class represents one visual world space. This world space is populated by three types of objects: virtual cameras (rendascii.interface.Camera), instances of models (rendascii.interface.ModelInstance), and instances of sprites (rendascii.interface.SpriteInstance). The user directly interacts with these three types of objects. In addition, the engine also maintains three other types of objects which the user does not directly interact with: models, sprites, and colormaps.

When using this package, one of the first things the user should do is create and instance of rendascii.interface.Engine, which has the following constructor signature:

__init__(colormap_dir='', sprite_dir='', model_dir='', material_dir='', num_workers=0)

  • colormap_dir - path to all the colormaps the user intends to load.

  • sprite_dir - path to all the sprites the user intends to load.

  • model_dir - path to all the models the user intends to load.

  • material_dir - path to all the materials the user intends to load.

  • num_workers - number of processes separate from the main process to run in parallel for rendering. If this is given a value of zero, the main process will handle all rendering.

Example

Assume that the user wants to use four processes for rendering in parallel and that their project directory is organized as follows:

my_project
|----resources
|    |----colormaps
|    |    |----base.json
|    |    |----alt.json
|    |----models
|    |    |----tetrahedron.obj
|    |    |----tetrahedron.mtl
|    |    |----building.obj
|    |    |----building.mtl
|    |----sprites
|         |----enemy.ppm
|         |----npc.ppm
|         |----treasure.ppm

They would likely want to use something similar to the following to create an engine:

from rendascii.interface import Engine as REngine

...

res_dir = 'resources/'
r_eng = REngine(
    colormap_dir=res_dir + 'colormaps/',
    sprite_dir=res_dir + 'sprites/',
    model_dir=res_dir + 'models/',
    material_dir=res_dir + 'models/',
    num_workers=4
)

Notice how they don't simply use from rendascii.interface import Engine to import the engine, opting for from rendascii.interface import Engine as REngine instead. Game development typically involves the use of multiple different types of engines such as rendering, physics, and audio. If the user imports the RendASCII rendering engine as is, it might be confusing which engine the imported object Engine refers to. As a result, it's good practice to import it with a more specific name, like REngine, so that there is no confusion which engine it refers to.

Clone this wiki locally