Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide non hook abstraction for custom update #100

Open
Shadowblitz16 opened this issue Jan 7, 2020 · 6 comments
Open

provide non hook abstraction for custom update #100

Shadowblitz16 opened this issue Jan 7, 2020 · 6 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Jan 7, 2020

so I just was messing around with RayLibCS and I really liked how the main loop worked.
it allowed the user to control the flow of the program and draw inside the things like load and update functions.

here is a example..

using Raylib;
using rl = Raylib.Raylib;

static class Program
{
    public static void Main() 
    {
        rl.InitWindow(640, 480, "Hello World");

        while (!rl.WindowShouldClose())
        {
            rl.BeginDrawing();

            rl.ClearBackground(Color.WHITE);
            rl.DrawText("Hello, world!", 12, 12, 20, Color.BLACK);

            rl.EndDrawing();
        }

        rl.CloseWindow();
    }
}

I think Love2d cs should allow something like this even if it was a optional thing.
it Love could update the stuff behind the scenes and allow the user to control the flow of the program.

for example..

using Love = Love.Love;
using MyEvents = MyFramework.MyEvents;

static class Program
{
    public static void Main() 
    {
        Love.InitWindow(640, 480, "Hello World");

        //allow drawing in load
        Love.BeginDraw();
        MyEvents .Load();
        Love.EndDraw();

        while (!Love.IsWindowOpen())
        {
            Love.BeginDraw();
            //my custom logic
            MyEvents.Step();
            MyEvents.Draw(); 
            Love.EndDraw();
        }
        MyEvents.Free(); 
        Love.CloseWindow();
    }
}
@endlesstravel
Copy link
Owner

actually you can do this now:

using System;
using Love;

namespace Project1
{
    class Issue_100: Scene
    {
        bool sholdClosed = false;
        public override bool Quit()
        {
            sholdClosed = true; // mark it as true to break loop
            return false; // return true will lead Application.Exit(); 
        }

        static void Main()
        {
            Boot.Init();
            var scene = new Issue_100();
            while (!scene.sholdClosed)
            {
                Boot.SystemStep(scene);   // poll the event

                Graphics.Clear(); // clean the window
                Graphics.Line(Vector2.Zero, Mouse.GetPosition());
                Graphics.Present();  // show the next frame

                if (Keyboard.IsPressed(KeyConstant.Space)) // update logic
                    scene.sholdClosed = true;

                Window.SetTitle("fps:" + FPSCounter.GetFPS());
            }
            Console.WriteLine("-end-");
        }
    }
}

Dose it can meet your requirements ❓

@Shadowblitz16
Copy link
Author

kinda ya but It would be better if it required less implementation.
I mean I could get around it but something more of what I suggested where you don't need to create a instance of a class.

@endlesstravel
Copy link
Owner

endlesstravel commented Jan 8, 2020

may be you mean:

Main(...)
{
            Boot.Init();
            while (!Boot.QuitFlag)
            {
                Boot.SystemStep();
                // or do this .....
                //Boot.SystemStep(new Boot.SystemStepConfig(){
                //    OnKeyPressed = (k, s, i) => Console.WriteLine(k),
                //});

                Graphics.Clear();
                Graphics.Line(Vector2.Zero, Mouse.GetPosition());
                Graphics.Present();

                if (Keyboard.IsPressed(KeyConstant.Space))
                    Boot.QuitFlag = true;

                Window.SetTitle("fps:" + FPSCounter.GetFPS());
            }
            Console.WriteLine("-end-");
}

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Jan 9, 2020

@endlesstravel yep but Boot.QuitFlag should be a method called Boot.IsRunning()
and Boot.SystemStep(); should a be abstracted so it doesn't need to be called.
also Boot should accept a optional window size and title

Main(...)
{
            Boot.Init(800, 600, "fps:" + FPSCounter.GetFPS());
            ///Window.SetTitle(); //optional Boot.Init() can Initialize window width, height and title.
            while (!Boot.IsRunning())
            {
                // Boot.SystemStep is not needed at all it is updated by Boot.Init(); using a object

                Graphics.Clear();
                Graphics.Line(Vector2.Zero, Mouse.GetPosition());
                Graphics.Present();

                if (Keyboard.IsPressed(KeyConstant.Space))
                    Boot.QuitFlag = true;
            }
            Console.WriteLine("-end-");
}``

@endlesstravel
Copy link
Owner

i will not push the function : Boot.IsRunning()
I think it's confusing. A function should only be as literal as it means, otherwise function name matching is not the actual task.

I had add new way to Boot.SystemStep(new Boot.SystemStepConfig() ...
in version 11.0.45

@Shadowblitz16
Copy link
Author

I'm not sure what you mean by Boot.IsRunning() is confusing.
I agree it is probably not the best class to put it in since something like.. Window.IsOpen() is probably better. also I do agree now that the running check and the events should be separated maybe in something like Window.PollEvents() but idk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants