Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (290)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Fast scripting...  (Read 1789 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Posted 2009-11-15 03:24:00 »

I'm looking into scripting for my game.

I've taken a look at Java's javax.script.* package, and it just sucks in regards of speed. I've also taken a look at Groovy, and it's better, runs fast with few objects (100'ish) but not fast enough with 500+.

Here's an example of 500 images being rotated:

1. Java's javax.script package/Rhino: under 10 fps.

2. Groovy: 90 fps.

3. Just plain old Java: 480 fps.


I know scripting isn't as fast, but I wasn't expecting this.

What am I doing wrong?


Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline noblemaster

JGO Ninja


Medals: 15
Projects: 7


Age of Conquest makes your day!


« Reply #1 - Posted 2009-11-15 04:00:46 »

How about Pnuts?

Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #2 - Posted 2009-11-15 04:43:48 »

I'd be interested to see how Pnuts performs for you in relation to the others. Make sure the scripts are being compiled and not interpreted. Setting up your context like this should work:

1  
2  
3  
4  
Context context = new Context();
//context.setVerbose(true);
context.setImplementation(new CachedPnutsImpl());
context.setWriter(new PrintWriter(System.out, true));

Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline CommanderKeith
« Reply #3 - Posted 2009-11-15 05:07:48 »

Use janino, it's a scripting language which compiles the script to JVM bytecode so it's just as fast as java  Cool

Offline appel

JGO Ninja


Medals: 35
Projects: 5


I always win!


« Reply #4 - Posted 2009-11-15 05:37:21 »

How about Pnuts?

Refactored how I do things. instead of creating a new script for each object I only use one but reset the bindings between objects. Here's the results between Groovy and Pnuts:

@500 rotating objects:
- Groovy: 240-340 fps
- Pnuts: 240-340 fps
- Java: 360-500 fps

(The framerate seems to change between runs)

However, when I increase to 1000 rotating objects:

@1000 rotating objects:
- Groovie: 60-120 fps
- Pnuts: 120-130 fps
- Java: 270-280 fps


Groovie seems to be more memory intensive than Pnuts, I notice it takes a bit longer to start with.


Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #5 - Posted 2009-11-15 07:56:00 »

Yay! Glad to see Pnuts win. Cheesy

FWIW, CachedPnutsImpl compiles and caches scripts (using WeakHashMap) for reuse when you call load(script, context). Avoiding loading the script each time is much better though. If you don't need CachedPnutsImpl you should use context.setImplementation(new CompilerPnutsImpl()); to have scripts compiled to bytecode. If you don't call setImplementation then it will use PnutsImpl, which is a pure interpreter.

Groovy is quite a mess of a language. I personally would rather not have such wildly different syntax. Weird that its performance varied so much.

Use janino, it's a scripting language which compiles the script to JVM bytecode so it's just as fast as java  Cool
Many JVM languages can be compiled to bytecode. They are generally still slower though, as they are usually doing more per line of code to support fancy language features.

Offline CommanderKeith
« Reply #6 - Posted 2009-11-15 08:04:16 »

Many JVM languages can be compiled to bytecode. They are generally still slower though, as they are usually doing more per line of code to support fancy language features.

Yeah I don't know why all the scripting languages deviate from the java syntax so much. That's why janino's so cool, it uses the exact java syntax. The only downside is that it doesn't support generics or var-args yet. But janino is as quick as java (once you 'cook' it in the compiler).

Offline princec
« League of Dukes »

JGO Kernel


Medals: 195
Projects: 3


Eh? Who? What? ... Me?


« Reply #7 - Posted 2009-11-15 12:24:21 »

What about JavaFX?

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #8 - Posted 2009-11-21 19:07:47 »

The thing with Janino is... it isn't really a scripting language. It's a very fast on-the-fly Java compiler. That's why you get the usual Java speed.

弾幕 ☆ @mahonnaiseblog
Offline zingbat

Senior Member




Java games rock!


« Reply #9 - Posted 2009-11-21 22:45:43 »

It means it's a better solution than using a scripting language.
Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline princec
« League of Dukes »

JGO Kernel


Medals: 195
Projects: 3


Eh? Who? What? ... Me?


« Reply #10 - Posted 2009-11-22 12:37:51 »

I dunno, I thought one of the benefits of scripting was to be free of the shackles of up front design... y'know, like ditching type declarations, the addition of top level functions, sensible overloading of the == operator, and nifty direct syntax for various types of collection...?

Cas Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (60 views)
2013-05-17 21:29:12

alaslipknot (69 views)
2013-05-16 21:24:48

gouessej (99 views)
2013-05-16 00:53:38

gouessej (98 views)
2013-05-16 00:17:58

theagentd (107 views)
2013-05-15 15:01:13

theagentd (98 views)
2013-05-15 15:00:54

StreetDoggy (144 views)
2013-05-14 15:56:26

kutucuk (167 views)
2013-05-12 17:10:36

kutucuk (166 views)
2013-05-12 15:36:09

UnluckyDevil (175 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.129 seconds with 20 queries.