Light package different for JPCT-AE

Started by 3d, March 19, 2013, 04:45:52 PM

Previous topic - Next topic

3d

I was trying to make common scene code that would run equally on JPCT and JPCT-AE (with a small platform-specific layer). One difference is the package of the Light class: com.threed.jpct.util for JPCT and com.threed.jpct for JPCT-AE. This will be an issue for a cross-platform source if imports are explicitly declared.

I am trying to understand the rationale: this seems to be the same Light object, but not clear why different packages between platforms. Moreover, the com.threed.jpct.util still exists in JPCT-AE.

For now the workaround is to move Light to the platform-specific area.

EgonOlsen

The reason for this strange difference is historical. In former versions (long before jPCT-AE existed), there was no Light-class in jPCT. The only way to add lights was to use the methods that exist in World for that. But i never felt satisfied with these methods, because the way they work feels clunky and slightly wrong. So i decided to add a little more OOish way of doing it, but i didn't want to break existing code, so i added the Light class. I put this into the util-package, because it was just that: A helper class that eases handling lights. The general rule for stuff in the util-package is, that it eases the handling for some things but it doesn't add anything that wouldn't be possible without it.
When doing jPCT-AE, i took the chance to hide/modify the light-related methods in World and rely on the Light class only. But now, the precondition that everything in util is just a helper to ease things that could be done with the classes in the core package wasn't true anymore. So i had to move Light into the core.
I've been bitten by this decision myself and i might move Light into the core in jPCT one day. Until then, this is what i do: I split my project into three parts. One contains the common stuff and will be compiled against jPCT-AE. The other two are platform specific for desktop and Android and include the common package. In the desktop part, i add this class:


package com.threed.jpct;

/**
*
* @author EgonOlsen
*
*/
public class Light extends com.threed.jpct.util.Light {

private static final long serialVersionUID = 1L;

public Light(World arg0) {
super(arg0);
setAttenuation(-1);
}

public SimpleVector getPosition(SimpleVector store) {
store.set(super.getPosition());
return store;
}

}

3d

The background makes sense, and along the lines I imagined.

To correct my initial workaround idea, as you illustrate, it has to be a sub-class. A good idea to just define it in the other API, as opposed to creating a generic one in both.

QuoteI split my project into three parts. One contains the common stuff and will be compiled against jPCT-AE

I split in two projects, each having two source folders. The the common folder in project part is linked to a source folder in the other part. So one project is self-contained (JPCT-AE), the other borrows the common folder.