stride3d / stride

Stride Game Engine (formerly Xenko)
https://stride3d.net
MIT License
6.34k stars 919 forks source link

Add a code-only sample #80

Open Kryptos-FR opened 5 years ago

Kryptos-FR commented 5 years ago

All samples assume the use of the editor to make a game. We should provide at least one sample (let's call it code template) of a simple scene where everything is done programmatically.

tebjan commented 5 years ago

That would be awesome! Xenko is alread quite programmer friendly, so it would also be a good learning source to understand the basic parts of the engine.

xen2 commented 5 years ago

Code-only sample = sample without assets/xkpkg?

The new Xenko as PackageReference approach should help a lot with that, since project can be created on VS. Note that few issues such as #58 or #12 might make code-only sample even easier/smoother to create.

Kryptos-FR commented 5 years ago

@xen2 Yes that's exactly the idea.

It shows that the editor is optional, and that it is possible to build on top of Xenko's engine without the need to support the whole asset system.

For example use Xenko as a backend to a customized (eventually commercial) engine.

Hopefully that would widen our audience and bring more talents.

microdee commented 5 years ago

We managed to make some dirty resizable WinForms app which creates a Game instance and uses Xenko.Graphics to render a black triangle:

https://discourse.vvvv.org/t/link-topics-2-3d-engine/16544/23?u=microdee

here's the repo: https://github.com/microdee/xenko-window-from-code

rds1983 commented 5 years ago

I'd suggest adding xenko project template(s) to the nuget. So one could install it through dotnet new -i Xenko.Game.Template and use through dotnet new xenkogame

Kryptos-FR commented 5 years ago

Starting point if someone wants to investigate further to make sure it works for all platforms/configurations: Xnk.zip.

tebjan commented 5 years ago

added a repo, the game is currently empty and only opens a black window. would be interesting to add some content in order to make it useful. but here it is for reference: https://github.com/tebjan/Xenko.CodeOnlyGame

xen2 commented 5 years ago

Created https://github.com/xen2/Xenko.CodeOnlySample Just need to update the doc so people can find it (and possibly move it to xenko3d github)

tebjan commented 5 years ago

great, made the other repo obsolete and linked the new one...

rds1983 commented 5 years ago

I've tried to build Xenko.CodeOnlySample from the console using dotnet and it failed: image

Is it a bug? Or did I do something wrong? It builds in VS2017 without problems.

Kryptos-FR commented 5 years ago

@rds1983 It is not a dotnet application, but .net framework.

xen2 commented 5 years ago

@Kryptos-FR I have added a dotnet app too @rds1983 this is fixed, will be part of next Xenko beta. You can build from VS in the meantime

rds1983 commented 5 years ago

Thanks! The new Xenko release "3.1.0.1-beta01-0396" allows to build Xenko.CodeOnlySample from the command line using "dotnet build".

Enzojz commented 5 years ago

That's will be cool if we have such thing, build from familiar IDE is a better way to let programmer who has already 3d knowladges.

tebjan commented 5 years ago

@Enzojz a xenko game is already a normal .NET solution that you can open with visual studio. just press the visual studio button in the game studio menu.

xen2 commented 5 years ago

Now the only question is where to host and advertise it. I might move it to xenko3d org, and add it to the doc and/or wiki.

CharlesWoodhill commented 5 years ago

is it possible to add a code only example like this? is it even possible with xenco? if there are other ways to achieve something like this, how is it done?

`
public class PseucdoCodeExample { Game simulation = null;

    struct UserData
    {
        Xenko.OS.OsWindow splashOsWindow;
    }: userData;

    void EntryPoint()
    {
        // simple use delegates
        simulation.OnInit = OnInit;
        simulation.OnStart = OnStart;
        simulation.OnUpdate = OnUpdate;
        simulation.OnPhysicsUpdate = OnPhysicsUpdate;
        simulation.Run(); //or
        simulation.RunAsync();
    }

    void OnInit()
    {
        // display splash

        //create os window myself or use of xenko helper
        userData.splashOsWindow = new Xenko.OS.Windows.CreateOsWindow(settings); // or
        userData.splashOsWindow = new Xenko.OS.Windows.BindToExistingOsWindow(settings, hWnd);

        // get a texture
        Texture tex = Texture.CreateFromImageFile("file/location/splash.png", opts); // eventuell windows only (asset compiler?)
        Texture tex = Texture.Load("file/location/splash.xTexture?"); // an already compiled? texture (done with gamestudio or batch-created)

        Scene splashScene = new Scene();
        splashScene.Entities.Add(new TexturePanel(..., tex) );

        OsViewPort viewPort = new ViewPort(..., expand.all); // viewport os specific?
        viewPort.RootScene = splashScene;
        userData.splashOsWindow.Components.Add(viewPort);

        userData.splashOsWindow.Show(); // display splash, while doin some work

        hWnd = createOsWindow();
        Xenko.OS.OsWindow mainOsWindow = new Xenko.OS.Windows.BindToExistingOsWindow(settings, hWnd);

        // 2 viewports (for ease just top/bottom :) )
        OsViewPort topViewport = new ViewPortComponent(name: "TopViewPort", ...); // resizeable if window is resized or toggle-fullscreen
        OsViewPort bottomViewport = new ViewPortComponent(name: "BottomViewPort", ...);

        mainOsWindow.Components.Add(topViewport);
        mainOsWindow.Components.Add(bottomViewport);

        // create main windows scene (mostly gui i think) 
        Scene mainViewTopScene = new Scene();
        //....
        topViewport.rootScene = mainViewTopScene;

        // bottom Viewport displays results and stays empty for now

        // setup mvvm or whatever

        userData.splashOsWindow.Free(); // or hide ...
        mainOsWindow.Show();
    }`
NicusorN5 commented 1 month ago

Since https://github.com/stride3d/stride/issues/1295 is already finished, and the code only approach works fine, should this thread be closed?

VaclavElias commented 1 month ago

Maybe, a console like template should be added to our example Stride projects to showcase this? It shouldn't reference the toolkit but use the same-ish code to demo how to do it and anyone could do whatever they want to do with that. Continue or switch to toolkit if desired.

NicusorN5 commented 1 month ago

What about a toolkit and non-toolkit samples?

VaclavElias commented 1 month ago

If we are talking about this yes. Not sure if it should be under samples or templates?

image

Non-toolkit sample would be ok, because the code shouldn't change that frequently.

I would recommened a toolkit sample once the toolkit is stable so we don't have to keep updating the template 🤣.

IXLLEGACYIXL commented 1 month ago

If we are talking about this yes. Not sure if it should be under samples or templates?

image

Non-toolkit sample would be ok, because the code shouldn't change that frequently.

I would recommened a toolkit sample once the toolkit is stable so we don't have to keep updating the template 🤣.

yes as it may be possible we have to separate code only from the toolkit at some point for example with the skybox problem so the state is currently unknown of the toolkit

VaclavElias commented 1 month ago

Also, wasn't there another PR (reversed) for another kind of code-only option?