Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Coroutines for Java  (Read 4010 times)
0 Members and 1 Guest are viewing this topic.
Offline MatthiasM

JGO n00b
*

Posts: 2



« on: 2008-04-10 18:18:20 »

Hi,

I wrote a small (<10KB) library which adds Coroutines to Java Smiley

A article and the library itself can be found here

Ciao Matthias
Offline jezek2

Sr. Member
**

Posts: 357
Medals: 3



« Reply #1 on: 2008-04-11 05:55:54 »

It's a very nice library, thanks for sharing. Smiley I've already integrated it into my engine for game code (and replaced JavaFlow that I used previously).
Offline brackeen

Full Member
**

Posts: 247



« Reply #2 on: 2008-04-11 13:52:53 »

Very interesting. So, I'm trying to grok it. What exactly does the preprocessing do? Can you show what happens to the TestIterator example?
Games published by our own members! Go get 'em!
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #3 on: 2008-04-11 14:30:44 »

Isn't this like software threading, with 'breakpoints' scattered through the bytecodes allowing you to suspend a method, do some other stuff and then continue where you left? Is it? Grin

I'm not too fond of something manipulating my bytecodes, but I guess in AI it's very convenient - my state machines often turn into a steaming pile.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline MatthiasM

JGO n00b
*

Posts: 2



« Reply #4 on: 2008-04-11 19:46:15 »

Well Smiley

I could attach a javap dump of the example - which is long (at least too long for this forum) - but it's very easy to generate - after running the JUnit tests all class files have been instrumented.

The resulting code is similar to the "standard Java example" on the website - except that the state is not stored as member variables - to allow for recursive calls - but instead in a thread local instance of the Stack class which is managed by the Coroutine class.

The bytecode gets more complex if you have exception handling using finally in your methods - even to the point where it will be impossible to write it using Java itself (without duplicating a lot of code).

Riven: Look at the possibilities that bytecode instrumentation offers ....

Ciao Matthias
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.11 seconds with 21 queries.