stride3d / stride-docs

This repository hosts the source code for the Stride documentation. Contributors can follow the build instructions provided to run the website locally.
https://doc.stride3d.net/
MIT License
31 stars 65 forks source link

Godot to Stride docs #128

Open IXLLEGACYIXL opened 12 months ago

IXLLEGACYIXL commented 12 months ago

Godots view, give copyright from the license, just link to it https://github.com/godotengine/godot/blob/master/LICENSE.txt GodotGUI Terminology Godot Stride Scene Entity Tree Inspector Property Grid FileSystem Solution/Asset View Scene view Scene Editor Node Entity Node Script SyncScript, AsyncScript, StartupScript Export Serialize/DataMember GlobalClass DataContract

Folders and files

Assets: In Godot you can store assets everywhere. in Stride Assets are in the Assets Folder

Stride and Godot use the Standard C# Solution Structure. Key difference here is that Stride uses the multi Project architecture which leads to the following Projects

MyPackage.Game contains your source code. MyPackage.Platform contains additional code for the platforms your project supports. Game Studio creates folders for each platform (eg MyPackage.Windows, MyPackage.Linux, etc). These folders are usually small, and only contain the entry point of the program. And any other Subprojects. Stride will scan the Subprojects too like the main Project to get DataContract classes and features into the Editor/Game ( it doesnt matter if its in a subproject or not Bin contains the compiled binaries and data. Stride creates the folder when you build the project, with a subdirectory for each platform. obj contains cached files. Game Studio creates this folder when you build your project. To force a complete asset and code rebuild, delete this folder and build the project again. Resources is a suggested location for files such as images and audio files used by your assets, do not confuse them with godot resources, these dont exist in Stride. Stride has in the Scene Folders ( these can be used in any way ) where you can put classes that would be normally Godot Resources

Open the project directory from Game Studio You can open the project directory from Project > Show in explorer in Game Studio.

Open project directory from Game Studio image

Game settings

Godot® saves global settings in the Project Settings https://docs.godotengine.org/cs/stable/classes/class_projectsettings.html The location is not known to me

Stride saves global settings in a single asset, the Game Settings asset. You can configure:

The default scene Rendering settings Editor settings Texture settings Physics settings Overrides To use the Game Settings asset, in the Asset View, select GameSettings and view its properties in the Property Grid.

Set the default scene You can have multiple scenes in your project. Stride loads the default scene at runtime.

To set the default scene:

In the GameSettings properties, next to Default Scene, click Hand icon (Select an asset). image

The Select an asset window opens.

Select the default scene and click OK.

For more information about scenes, see Scenes. image

Entities vs Nodes

Nodes have a "is a" Behaviour. A Node is what the Script attached to it defines, so there is only one script per Node. Stride uses an Entity Component System which is a "has a" Behaviour. Entities are carriers for components such as transform components, model components, audio components, and so on. So you attach multiple Scripts to the Same entity.

Transform component Each entity in Stride has a Transform component which sets its position, rotation, and scale in the world.

Even empty entities have a Transform component, because every entity in the scene must have a position. To Access the transform Component on a Stride Script ( SyncScript , StartUpScript , AsynScript ) you can use this.Entity.Transform

In Stride, Transform components contain a LocalMatrix and a WorldMatrix that are updated in every Update frame. If you need to force an update sooner than that you can use TranformComponent.UpdateLocalMatrix(), Transform.UpdateWorldMatrix(), or Transform.UpdateLocalFromWorld() to do so, depending on how you need to update the matrix. Godot Stride Position Transform.Position Rotation Transform.Rotation Scale Transform.Scale

Directions

Direction Stride Godot Forward (0, 0, 1) (0, 0, -1) Backward (0, 0, -1) (0, 0, 1) Right (1, 0, 0) (1, 0, 0) Left (-1, 0, 0) (-1, 0, 0) Up (0, 1, 0) (0, 1, 0) Down (0, -1, 0) (0, -1, 0)

Assets

They are the same like in Godot. Each Asset can be edited through double click in the Asset View. Certain Assets open a dedicated Asset Editor For certain types of asset, Game Studio also has dedicated editors:

Like these: prefabs scenes sprite sheets UI pages UI libraries scripts To open the dedicated editor for these types of asset:

double-click the asset, or right-click the asset and select Edit asset, or select the asset and type Ctrl + Enter

The new Editor opens a new Tab like in Godot at the top image

The Gamestudio will update references like Godot does, if you save a change it will update the references.

Resources

Stride doesn't have Resources like Godot has. In Stride you can add Folders to your Scene and add there Entities with your Data. Another approach would be to save your former Resources in a separate Prefab and load it into the scenes that need the Data.

Supported File Formats

Models, animations, skeletons | .dae, .3ds, obj, .blend, .x, .md2, .md3, .dxf, .fbx Sprites, textures, skyboxes | .dds, .jpg, .jpeg, .png, .gif, .bmp, .tga, .psd, .tif, .tiff Audio, Sounds | .wav, .mp3, .ogg, .aac, .aiff, .flac, .m4a, .wma, .mpc Fonts | .ttf, .otf

Prefab Inheritance

The equivalent of Godots inherited Scene would be ArcheTypes. Archetypes are master assets that control the properties of assets you derive from them. Derived assets are useful when you want to create a "remixed" version of an asset. This is similar to prefabs.

For example, imagine we have three sphere entities that share a material asset named Metal. Now imagine we want to change the color of only one sphere, but keep its other properties the same. We could duplicate the material asset, change its color, and then apply the new asset to only one sphere. But if we later want to change a different property across all the spheres, we have to modify both assets. This is time-consuming and leaves room for mistakes.

The better approach is to derive a new asset from the archetype. The derived asset inherits properties from the archetype and lets you override individual properties where you need them. For example, we can derive the sphere's material asset and override its color. Then, if we change the gloss of the archetype, the gloss of all three spheres changes.

Create derived asset image

You can derive an asset from an archetype, then in turn derive another asset from that derived asset. This way you can create different layers of assets to keep your project organized:

Input

In Stride you have the Option to get the Input through Key Strokes like in Godot or through Virtual Buttons, which is similiar to Godots Key Mapping

public override void Update()
{
    // true for one frame in which the space bar was pressed
    if(Input.IsKeyDown(Keys.Space))
    {
        // Do something.
    }

    // true while this joystick button is down
    if (Input.GameControllers[0].IsButtonDown(0))
    {
        // Do something.
    }

    float Horiz = (Input.IsKeyDown(Keys.Left) ? -1f : 0) + (Input.IsKeyDown(Keys.Right) ? 1f : 0);
    float Vert = (Input.IsKeyDown(Keys.Down) ? -1f : 0) + (Input.IsKeyDown(Keys.Up) ? 1f : 0);
    //Do something else.
}

Physics

In Stride you have 3 Types of Colliders static colliders rigidbodies characters

In Godot you can use Signals to react on a collision. In Stride you can add methods in the Start() Method to the Delegate that gets executed when triggered. This Tutorial explains how you can handle collisions in Stride https://www.youtube.com/watch?v=SIy3pfoXfoQ&ab_channel=Stride

GameStudio Editor

Stride has like Godot an Integrated Code Editor, but for C#. This Code Editor is not an high Priority Target in being kept up to date, so it's advised to use dedicated IDEs like Visual Studio Code, Rider and Visual Studio Community

Script Types

In Stride there are 3 Types of Scripts. Unlike in Godot where you inherit from a Class to be able to be that Node. In Stride you would extend Entitys through Adding Scripts and searching for Entities. Instead of Inheriting from CharacterBody3D in Godot, in Stride you would attach a CharacterComponent ( don't forget to attach a Collision Shape to it ) to an entity and in the Scripts you can search for these Components. Which is Delegation over Inheritance principle overall.

  1. StartupScript This Script has only the Start method which is equivalent to Godots _Ready A StartupScript doesn't do much besides that.

    public class BasicMethods : StartupScript
    {
    // Declared public member fields and properties that will appear in the game studio
    public override void Start()
    {
        // Initialization of the script
    }
    
    public override void Cancel()
    {
        // Cleanup of the script
    }     
    } 
  2. SyncScript A SyncScript has a Update() Method which is the equivalent to _Process(double delta) A Key difference is that you don't have Delta as Parameter. this.Game.UpdateTime.Elapses.TotalSeconds Any SyncScript has through its Game Property access to Delta

The Stride Community Toolkit has Extension Methods to obtain it easier. This approach solves the Problem of having to write a float Cast each time when a _Process(double delta) Method is written as you can easier access it through Extension methods

    /// <summary>
    /// Gets the time elapsed since the last game update in seconds as a single-precision floating-point number.
    /// </summary>
    /// <param name="gameTime">The IGame interface providing access to game timing information.</param>
    /// <returns>The time elapsed since the last game update in seconds.</returns>
    public static float DeltaTime(this IGame gameTime)
    {
        return (float)gameTime.UpdateTime.Elapsed.TotalSeconds;
    }
public class BasicMethods : SyncScript
{
    public override void Start() { }
    public override void Cancel() { }        
    public override void Update() { }
}
  1. AsyncScripts To run Code Asynchronous to the Engines Update you can use AsyncScripts which work with async/await

    public class BasicMethods : AsyncScript
    {
    // Declared public member fields and properties that will appear in the game studio
    public override async Task Execute()
    {
        while(Game.IsRunning)
        {
            // Do stuff every new frame
            await Script.NextFrame();
        }
    }
    
    public override void Cancel()
    {
        // Cleanup of the script
    }     
    }

    Add scripts to entities

    In the Entity Tree (on the left by default), or in the scene, select the entity you want to add the script to.

Select an entity image

In the Property Grid (on the right by default), click Add component and select the script you want to add. image

For more information about adding scripts in Stride, see Use a script.

Instantiate Prefabs

In Stride you can Instantiate like this Entities

// Declared public member fields and properties displayed in the Game Studio Property Grid.
public Prefab CarPrefab;
public Vector3 SpawnPosition;
public Quaternion SpawnRotation;

public override void Start()
{
    // Initialization of the script.
    List<Entity> car = CarPrefab.Instantiate();
    SceneSystem.SceneInstance.RootScene.Entities.AddRange(car);
    car[0].Transform.Position = SpawnPosition;
    car[0].Transform.Rotation = SpawnRotation;
    car[0].Name = "MyNewEntity";
}

Serialization

In Godot you need to Inherit an Engines class to be visible in the Editor. Also only known Types to the Godot Engine can be Exported.

Stride has the different approach to be closer to C# The [Stride.Core.DataContract] Attribute enables your class for Serialization in the GameStudio. Then per default public Members get serialized. you can explicitly add [DataMember] ( equivalent to [Export] ) to a class member but it doesn't have to be. to exclude a Member you can add [Stride.Core.DataMemberIgnore] so the Editor will ignore it.

In Godot you have to Export Godot Collections to be visible in the Editor. Stride Supports ICollection classes and IDictionary ( NOTE: only primitives and enums work as key ) implementations You can Serialize any class that is a [DataContract] into the Editor.

You can also Serialize Abstract classes or Interfaces. The Stride Editor will search for types that would fit into these interfaces or abstract classes.

Log Output

In Godot you can GD.Print your message. Log output To see the output, in the Game Studio toolbar, under View, enable Output. image

Enable output image

Game Studio displays in the Output tab (at the bottom of Game Studio by default). you can then Log in Your Code Messages like so System.Diagnostics.Debug.WriteLine("hello");

VaclavElias commented 12 months ago

That is already cool. Let me know when you are done tomorrow or next week and I will process it to a draft. Also, Just make heading in #, so I know exactly what should be a title and subtitle :)

level 1

level 2

level

Te3Que commented 12 months ago

Maybe you could dive into how the two compares in build, as in how the game is presented in files when its built/published and ready to "ship".

IXLLEGACYIXL commented 12 months ago

Maybe you could dive into how the two compares in build, as in how the game is presented in files when its built/published and ready to "ship".

i dont know that much about it, godot just compiles the csproj and combines it into 1 executable file..idk much mroe

VaclavElias commented 11 months ago

I started importing this article to docs. Please don't make any further updates. Once my draft is ready, we can collaborate further there :)

Thank you everyone.