User:Deldee/objectAnatomyDraft: Difference between revisions

From Ukikipedia
Jump to navigation Jump to search
(Created page with "The following is a draft a full article on the object processes, to help debugging them for newcomers : Rough draft, using goomba as an example: <br> Init - > [https://githu...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


Rough draft, using goomba as an example: <br>
Rough draft, using goomba as an example: <br>
Init - > [https://github.com/n64decomp/sm64/blob/master/data/behavior_data.c data/behavior_data.c]<br>
==Anatomy of an Object Code==
Set OBJ_LIST - > [[Objects#Object_Groups|Object Groups]]<br>
===Initialization===
Set OBJ Flag - > Nothing <br>
To start the object initialization, the object is called via a Macro preset from the level script, which will prompt it initialization with the attached BehaviorScript. The BehaviorScript is then fetched in [https://github.com/n64decomp/sm64/blob/master/data/behavior_data.c data/behavior_data.c] to start initializaing the object.<br>
Load animation or Model - > [[Actor groups]] and [https://github.com/n64decomp/sm64/tree/master/actors Actors list] <br>
''Note : The following order is not consistent over the whole code. The collision data for example is loaded at different point depending on the BehaviorScript in question.
Set  object specific values (Home, physic, drop to floor) - > TODO <br>
===Set Object List===
Call Native Behavior (init behavior) - > [https://github.com/n64decomp/sm64/tree/master/src/game/behaviors Behavior Lists]<br>
The first action of any BehaviorScript is to set the Object List (Or [[Objects#Object_Groups|Object Groups]]) of an object, this categorizes the object in their processing order
* This will also set the hitbox, which is usually a struct defined in the same file, but can be different files (boulder for example)<br>
 
Begin Behavior Loop<br>
===Set Collision data===
* Call loop behavior - > [https://github.com/n64decomp/sm64/tree/master/src/game/behaviors Behavior Lists]<br>
Scripts of the "SURFACE" object group will load their collision data. This collision data is fetched from the level structure. For example, here is the [https://github.com/n64decomp/sm64/blob/master/levels/jrb/falling_pillar_base/collision.inc.c#L2 Falling Pillar collision data].
End Loop
===Set Object Flag===
Another early action is to set the object flags of the object, these typically represent value to constantly take into account at every processing frame or high level operations to execute. For a Goomba, those are OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO, OBJ_FLAG_COMPUTE_DIST_TO_MARIO, OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE. This means that, every frame, the Goomba's Angle to Mario and Distance to Mario will be calculated and that its Yaw and graphical data will be updated
 
===Load Animation or Model===
For objects that are not part of the "SURFACE" group, the animation or model will be loaded. Animations are located in the subfolder of the object in the [https://github.com/n64decomp/sm64/tree/master/actors Actors list]. As an example, for a Goomba, the animation data is located at [https://github.com/n64decomp/sm64/tree/master/actors/goomba/anims /actors/goomba/anims]
 
===Set Object Specific Values===
Set  object specific values (Home, physic, drop to floor) - > [https://github.com/n64decomp/sm64/blob/master/src/engine/behavior_script.c src/engine/behavior_script.c] <br>
For all object, multiple extra operation can and will be done, of which an exhaustive list can be found in [https://github.com/n64decomp/sm64/blob/master/src/engine/behavior_script.c src/engine/behavior_script.c]. The operation done for the Goomba BehaviorScript are:
* Set the object's physics
* Set the object's home
* Drop the object to the floor
 
===Call the Object-specific gameloop behavior===
There are two typically two types of behavior functions located in the behavior file of an object, which are located in [https://github.com/n64decomp/sm64/tree/master/src/game/behaviors src/game/behaviors]. The "initialization" function, which is typically run once when loading the objects. The "loop" function, on the other hand, is the behavior that will run on every processing frames. The main way to distinguish between them is that the latter is surrounded by "BEGIN_LOOP()" and "END_LOOP()" and always comes at the end of the BehaviorScript.

Latest revision as of 16:40, 11 October 2023

The following is a draft a full article on the object processes, to help debugging them for newcomers :

Rough draft, using goomba as an example:

Anatomy of an Object Code

Initialization

To start the object initialization, the object is called via a Macro preset from the level script, which will prompt it initialization with the attached BehaviorScript. The BehaviorScript is then fetched in data/behavior_data.c to start initializaing the object.
Note : The following order is not consistent over the whole code. The collision data for example is loaded at different point depending on the BehaviorScript in question.

Set Object List

The first action of any BehaviorScript is to set the Object List (Or Object Groups) of an object, this categorizes the object in their processing order

Set Collision data

Scripts of the "SURFACE" object group will load their collision data. This collision data is fetched from the level structure. For example, here is the Falling Pillar collision data.

Set Object Flag

Another early action is to set the object flags of the object, these typically represent value to constantly take into account at every processing frame or high level operations to execute. For a Goomba, those are OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO, OBJ_FLAG_COMPUTE_DIST_TO_MARIO, OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE. This means that, every frame, the Goomba's Angle to Mario and Distance to Mario will be calculated and that its Yaw and graphical data will be updated

Load Animation or Model

For objects that are not part of the "SURFACE" group, the animation or model will be loaded. Animations are located in the subfolder of the object in the Actors list. As an example, for a Goomba, the animation data is located at /actors/goomba/anims

Set Object Specific Values

Set object specific values (Home, physic, drop to floor) - > src/engine/behavior_script.c
For all object, multiple extra operation can and will be done, of which an exhaustive list can be found in src/engine/behavior_script.c. The operation done for the Goomba BehaviorScript are:

  • Set the object's physics
  • Set the object's home
  • Drop the object to the floor

Call the Object-specific gameloop behavior

There are two typically two types of behavior functions located in the behavior file of an object, which are located in src/game/behaviors. The "initialization" function, which is typically run once when loading the objects. The "loop" function, on the other hand, is the behavior that will run on every processing frames. The main way to distinguish between them is that the latter is surrounded by "BEGIN_LOOP()" and "END_LOOP()" and always comes at the end of the BehaviorScript.