Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    455
  • comments
    639
  • views
    424662

On Java...

Sign in to follow this  
_the_phantom_

100 views

I've finally found something about Java I don't mind... which, given my general level of hostility towards the language/platform as a whole is nothing short of amazing...

However, it starts with a moan; you see I've got until monday to write a 2d graphics project using Java for an assignment. I probably should have started it earlier but meh.

Now, as covered I dislike Java and decided that in order to make this at least amusing for myself I would;
a) write a side scrolling shooter type thing
b) do the logic in Lua and perform some franenstein like melding of Lua and Java.

The latter was a source of great fun to start with when the LuaJava binding, which apprently supports Java 1.4 and up and Lua 5.1, refused to load without throwing a Class format not supported error; which is amusing as I've only just installed Java 1.4.2_13 on my machine. How fun.

In the end I had a copy of LuaJava 1.0 and Lua5.0 knocking around and that worked with no trouble.

So, I set about constructing an application, firstly jumping through some hoops in order to set my screen to 800*600 and make a full screen frame, and then with the Lua bindings themselves.

Now, I'm used to doing this in C++, basically you bind the C++ function to a functor and hand that off so it's called from Lua.

Can't do that in Java; instead in Java we use JavaFunction objects which require an implimented "execute" function in order to work. This is all well and good but it doesn't provide a method to bind these objects to a class instance (or at least I've not found a way).

Enter Reflection and my FunctionProxy object. This is basically the Java version of the C++ functor; just done at runtime instead of compile time.


public class FunctionProxy extends JavaFunction {

Engine engine;
Method callee;
LuaState lua;
public FunctionProxy(String name, Engine e, LuaState l) throws SecurityException, NoSuchMethodException
{
super(l);
engine = e;
lua = l;
Class engineClass = engine.getClass();
callee = engineClass.getMethod(name,null);
}

public int execute() throws LuaException {
// TODO Auto-generated method stub
try {
callee.invoke(engine, nulls);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}

}




Basically, upon creation we take a note of the Lua context we were created with and the class which we were registered in. Next, we perform some funky reflection stuffs in order to extract the correction function call to bind to the given name.

At call time we just call this functor/Method and we are back in the right instance, with Lua data ready and waiting for us.

This is pretty much version 1.0, still I was impressed that I got it up and going so quickly after only bouncing around the docs for a few mins.

Once this is done the general idea is the Java code does the rendering state management and calls to update etc, the Lua code does logic and rendering steps. That should cover the assignments requirements nicely [smile]

In other news;
I noticed today ATI's Vista drivers have the depth-stencil extension exposed. I'm as yet to see how well it works as I'm a tad busy, but if they have finally got it working then it would be nice.

And one of my harddrive really seems to be on the way out; I think it keeps locking up windows [sad]
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!