Game has to be fully initialized for Net to work?

11 views
Skip to first unread message

Ruth

unread,
Aug 11, 2017, 1:06:17 PM8/11/17
to PlayN
This code does not work as I hoped:
Platform plat = new JavaPlatform.Headless(new JavaPlatform.Config());
plat.net().get("http://google.com").onSuccess((result) -> System.out.println(result));
plat.start()

It seems loop is noop for Headless but even if I overwrite it, that won't activate Net-functionality:
        JavaPlatform.Headless plat = new JavaPlatform.Headless(new JavaPlatform.Config()) {
            @Override
            protected void loop() {
                while (true) {
                    System.out.println("loop!");
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };




// This code works as expected
Platform plat = new LWJGLPlatform(new LWJGLPlatform.Config());
plat.net().get("http://google.com").onSuccess((result) -> System.out.println(result));
plat.start()



Is there a technical reason to bind services like Net, Json, etc. to a running Platform and not allow Headless?

Ruth

unread,
Aug 11, 2017, 1:19:57 PM8/11/17
to PlayN
In earlier versions of PlayN I used:

new JavaNet(null) or new JsonImpl() as workarounds.

Michael Bayne

unread,
Aug 11, 2017, 1:31:54 PM8/11/17
to pl...@googlegroups.com
There needs to be a game loop running for JavaNet to work. It does the HTTP request on a background thread and then dispatches the result back on the main game thread. But Headless has no game loop because it would not know when to stop the game loop. I guess I could make a separate version of Headless that ran a loop and then you had to manually call stop() on it to say "I'm done."

What's the use case? Unit tests?

On Fri, Aug 11, 2017 at 10:19 AM, 'Ruth' via PlayN <pl...@googlegroups.com> wrote:
In earlier versions of PlayN I used:

new JavaNet(null) or new JsonImpl() as workarounds.

--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Michael Bayne

unread,
Aug 11, 2017, 1:34:14 PM8/11/17
to pl...@googlegroups.com
Also, you can make your hacky version work by calling emitFrame() inside your fake game loop. So maybe that solves your problem?

--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dieter.h...@googlemail.com

unread,
Aug 11, 2017, 5:10:08 PM8/11/17
to PlayN
Yes. Mostly Unit tests but also game-related development of non-graphics parts. Setting up LWJGLPlatform opens an annoying window and it takes quite long for me. About 2 sec.
This slows down development quite a bit and distrubs my thought process, especially when I am "in the flow". The old Java2D mode had a much quicker startup. I guess it probably has its advantages to 'bind' functionality of Net, Json, etc. to the game loop.

I hope you still find time to keep PlayN alive. It is really an impressive piece of software.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ruth

unread,
Aug 11, 2017, 5:43:49 PM8/11/17
to PlayN, dieter.h...@googlemail.com
I only use it for unit tests, that's why I need headless. emitFrames hack fixes it. Thanks!
Reply all
Reply to author
Forward
0 new messages