Newer
Older
SproutServerMicro / src / main / java / framework / gameMain / AbstractGameState.java
s-bekki on 30 Nov 2017 1 KB initial commit
package framework.gameMain;

import framework.RWT.RWTCanvas3D;
import framework.RWT.RWTContainer;
import framework.RWT.RWTFrame3D;
import framework.RWT.RWTVirtualController;

import javax.media.j3d.GraphicsConfigTemplate3D;
import java.awt.*;

public abstract class AbstractGameState implements IGameState {
	protected RWTContainer container;
	
	public void init(RWTFrame3D frame) {
		if (container == null) {
			container = createContainer();
		}
		frame.setContentPane(container);
		GraphicsConfiguration gc = null;
		if (frame.isShadowCasting()) {
			// 影を付ける場合
			// ステンシルバッファを使用する GraphicsConfiguration の生成
			GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
			GraphicsDevice gd = ge.getDefaultScreenDevice();
			GraphicsConfigTemplate3D gct3D = new GraphicsConfigTemplate3D();
			gct3D.setStencilSize(8);
			gc = gd.getBestConfiguration(gct3D);
		}
		container.build(gc);
	}

	public abstract RWTContainer createContainer();
	/* (non-Javadoc)
	 * @see IGameState#useTimer()
	 */
	public abstract boolean useTimer();
	/* (non-Javadoc)
	 * @see IGameState#progress(RWTVirtualController)
	 */
	public abstract void update(RWTVirtualController virtualController, long interval);
	
	public RWTCanvas3D getRWTCanvas3D() {
		if (container == null) return null;
		return container.getPrimaryRWTCanvas3D();
	}
}