Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Using ClearScript in a video game.

$
0
0
Hey, I was making a video game engine (with SFML.Net) and using JavaScript as the game programming language.

I had been using Jurassic until I saw this, I made a new branch of my code and switched over.

I then ran some performance tests and realized this ClearScript was much slower, even when running V8. The game FPS more than halved under this.

So, here's an example of the game code:
var image = LoadImage("image.png"); // exposes a C# image object from my game enginewhile (!IsAnyKeyPressed()) {
    image.blit(0, 0);
    FlipScreen();
}
In Jurassic the above code had 0 performance penalty and the game ran at over 10000fps, but under ClearScript it's around 7400 fps.

Now, when I do this the fps goes up again, to 11000fps:
var image = LoadImage("image.png");
var blit = image.blit;

while (!IsAnyKeyPressed()) {
    blit(0, 0);
    FlipScreen();
}
I wonder why? Is the host-to-JS that slow? In Jurassic it's cleaner what you say goes into the JS environment, but it seems in ClearScript a lot of 'baggage' is tied to an object. What can I do to make this go faster?

LoadImage just returns a C# instance of an image object (an SFML texture with the ability to draw it to the render window). I feel like there is a way to make this faster, or if it is the case that the 'miracle C#-JS' conversion is slow, then I'm going to have to ditch ClearScript and move back to Jurassic, but I want the power of V8. I need to use a lot of exposed objects. I'm not always running raw JS (which is far faster than Jurassic, btw).

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>