[Fencommits] libvob: Add initial version of lwjgl API.
Matti J. Katila
majukati at cc.jyu.fi
Tue Feb 7 23:05:12 EET 2006
Sun Feb 5 11:09:44 EET 2006 Matti J. Katila <majukati at cc.jyu.fi>
* Add initial version of lwjgl API.
diff -rN -u libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGLUpdateManager.java libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGLUpdateManager.java
--- libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGLUpdateManager.java 1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGLUpdateManager.java 2006-02-07 22:10:35.000000000 +0200
@@ -0,0 +1,26 @@
+package org.nongnu.libvob.impl.lwjgl;
+
+import org.nongnu.libvob.AbstractUpdateManager;
+
+public class LWJGLUpdateManager extends AbstractUpdateManager {
+
+ public static void startUpdateManager(Runnable r) {
+ LWJGLUpdateManager mgr = new LWJGLUpdateManager(r);
+ new Thread(mgr).start();
+ }
+
+ protected LWJGLUpdateManager(Runnable r) {
+ super(r);
+ }
+
+ protected boolean handleEvents(boolean waitForEvent) {
+
+
+ return false;
+ }
+
+ protected void interruptEventloop() { }
+
+ protected void synchronizeToolkit() { }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_API.java libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_API.java
--- libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_API.java 1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_API.java 2006-02-07 22:10:35.000000000 +0200
@@ -0,0 +1,57 @@
+package org.nongnu.libvob.impl.lwjgl;
+
+import org.nongnu.libvob.GraphicsAPI;
+import org.nongnu.libvob.TextStyle;
+
+public class LWJGL_API extends GraphicsAPI {
+
+ public void startUpdateManager(Runnable r) {
+ LWJGLUpdateManager.startUpdateManager(r);
+ }
+
+ public Window createWindow() {
+ return new LWJGL_Screen(this);
+ }
+
+ public RenderingSurface createStableOffscreen(int w, int h) {
+ return null;
+ }
+
+ public TextStyle getTextStyle(String family, int style, int size) {
+ return new TextStyle(){
+
+ public float getScaleByHeight(float h) {
+ return 0;
+ }
+
+ public TextStyle getScaledStyle(float h) {
+ return this;
+ }
+
+ public float getWidth(String s, float scale) {
+ return 0;
+ }
+
+ public float getWidth(char[] chars, int offs, int len, float scale) {
+ return 0;
+ }
+
+ public float getHeight(float scale) {
+ return 0;
+ }
+
+ public float getAscent(float scale) {
+ return 0;
+ }
+
+ public float getDescent(float scale) {
+ return 0;
+ }
+
+ public float getLeading(float scale) {
+ return 0;
+ }
+ };
+ }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_Screen.java libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_Screen.java
--- libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_Screen.java 1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_Screen.java 2006-02-07 23:05:11.698178493 +0200
@@ -0,0 +1,151 @@
+package org.nongnu.libvob.impl.lwjgl;
+
+import java.awt.Dimension;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.opengl.Display;
+import org.lwjgl.opengl.DisplayMode;
+import org.nongnu.libvob.AbstractUpdateManager;
+import org.nongnu.libvob.Binder;
+import org.nongnu.libvob.ChildVobScene;
+import org.nongnu.libvob.GraphicsAPI;
+import org.nongnu.libvob.VobMap;
+import org.nongnu.libvob.VobScene;
+import org.nongnu.libvob.GraphicsAPI;
+import org.nongnu.libvob.gl.GL;
+import org.nongnu.libvob.gl.GLVobCoorder;
+import org.nongnu.libvob.gl.impl.lwjgl.LwjglCoorder;
+import org.nongnu.libvob.impl.DefaultVobMatcher;
+import org.nongnu.libvob.impl.gl.GLVobMap;
+
+public class LWJGL_Screen extends GraphicsAPI.AbstractRenderingSurface
+ implements GraphicsAPI.Window {
+
+ static public boolean dbg = true;
+
+ static private void p(String s) {
+ System.out.println("LwjglScreen:: " + s);
+ }
+
+ private Object SCREENSIZEKEY = new Object();
+
+ public LWJGL_Screen(GraphicsAPI api) {
+ super(api);
+ try {
+ GL.init();
+ Display.setDisplayMode(new DisplayMode(1, 1));
+ Display.setFullscreen(false);
+ Display.create();
+ Display.setTitle("Grazy Little Window");
+ } catch (LWJGLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void finalize() throws Throwable {
+ super.finalize();
+ Display.destroy();
+ }
+
+ public Dimension getSize() {
+ DisplayMode mode = Display.getDisplayMode();
+ return new Dimension(mode.getWidth(), mode.getHeight());
+ }
+
+ public void renderStill(VobScene vs, float lod) {
+ p("render still");
+
+ LwjglCoorder.getInstance().render(vs.map, null, (GLVobCoorder)vs.coords, null, 0, true, true);
+ }
+
+ public void renderAnim(VobScene prev, VobScene next, float fract, float lod,
+ boolean showFinal) {
+ p("render anim");
+
+ VobScene sc = prev;
+ VobScene osc = next;
+ boolean towardsOther = true;
+ if (fract > AbstractUpdateManager.jumpFract) {
+ sc = next;
+ osc = prev;
+ fract = 1-fract;
+ towardsOther = false;
+ }
+ if(osc == null) osc = sc;
+ if(dbg) {
+ p("Going to render: "+sc+" "+osc+" "+fract);
+ sc.dump();
+ }
+
+ createInterpList(sc, osc, towardsOther);
+
+ LwjglCoorder.getInstance().render(sc.map, interplist,
+ (GLVobCoorder) sc.coords, (GLVobCoorder)osc.coords,
+ fract, true, showFinal);
+
+ }
+
+ VobScene listprev, listnext;
+ int[] interplist;
+
+ protected void createInterpList(VobScene sc, VobScene osc,
+ boolean towardsOther) {
+ if (sc != listprev || osc != listnext) {
+ listprev = sc;
+ listnext = osc;
+ interplist = sc.matcher.interpList(osc.matcher, towardsOther);
+ interplist[0] = interplist.length;
+ }
+ }
+
+ public boolean needInterp(VobScene prev, VobScene next) {
+ createInterpList(prev, next, true);
+ if (interplist == null)
+ return false;
+ return prev.coords.needInterp(next.coords, interplist);
+ }
+
+ public VobScene createVobScene() {
+ return createVobScene(getSize());
+ }
+
+ public VobScene createVobScene(Dimension size) {
+ VobScene vs = new VobScene(new LWJGL_VobMap(this), new GLVobCoorder(),
+ new DefaultVobMatcher(), this.getGraphicsAPI(), this, size);
+
+ // Put the cs no 1, i.e. the screen size
+ vs.boxCS(0, SCREENSIZEKEY, size.width, size.height);
+ return vs;
+ }
+
+ public ChildVobScene createChildVobScene(Dimension size,
+ int numberOfParameterCS) {
+ return null;
+ }
+
+ public int[] readPixels(int x, int y, int w, int h) {
+ return null;
+ }
+
+ public void setLocation(int x, int y, int w, int h) {
+ Display.setLocation(x, y);
+ try {
+ Display.setDisplayMode(new DisplayMode(w, h));
+ } catch (LWJGLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void setCursor(String name) {
+ }
+
+ Binder binder;
+
+ public void registerBinder(Binder s) {
+ binder = s;
+ }
+
+ public void addTimeout(int ms, Object o) {
+ }
+
+}
diff -rN -u libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_VobMap.java libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_VobMap.java
--- libvob-old/org/nongnu/libvob/impl/lwjgl/LWJGL_VobMap.java 1970-01-01 02:00:00.000000000 +0200
+++ libvob-new/org/nongnu/libvob/impl/lwjgl/LWJGL_VobMap.java 2006-02-07 23:05:11.697178644 +0200
@@ -0,0 +1,182 @@
+/*
+GLVobMap.java
+ *
+ * Copyright (c) 2000-2001, Ted Nelson and Tuomas Lukka
+ * 2003, Tuomas J. Lukka
+ * 2004, Matti J. Katila
+ *
+ * This file is part of Gzz.
+ *
+ * Gzz is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gzz is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General
+ * Public License along with Gzz; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ */
+/*
+ * Written by Tuomas Lukka
+ */
+package org.nongnu.libvob.impl.lwjgl;
+import org.nongnu.libvob.*;
+import org.nongnu.libvob.gl.*;
+import javolution.realtime.Realtime;
+import java.awt.*;
+
+public class LWJGL_VobMap implements VobMap {
+ public static boolean dbg = false;
+ private static void p(String s) { System.out.println("GLVobMap:: "+s); }
+
+ LWJGL_Screen screen;
+ VobScene vs;
+
+ public LWJGL_VobMap(LWJGL_Screen screen) {
+ this.screen = screen;
+ if(dbg) p("New GLVobMap for "+screen+": "+this);
+ list = new int[20000];
+ cs = new int[20000];
+ vobs = new Vob[20000];
+ clear();
+ }
+
+ public void setVS(VobScene vs) { this.vs = vs; }
+
+ int[] list;
+ int curs;
+ int[] cs;
+ Object[] vobs;
+ int nvobs;
+
+ public void clear() {
+ for(int i=0; i<curs; i++)
+ list[i] = 0;
+
+ for(int i=0; i<nvobs; i++) {
+ cs[i] = 0;
+
+ if(vobs[i] == null) continue;
+
+ // decrement Javolution reference counter
+ ((Vob)vobs[i]).move(Realtime.ObjectSpace.LOCAL);
+
+ // XXX does this still cause gc and take too much time
+ // even when using Realtime?
+ vobs[i] = null;
+ }
+
+ curs = 0;
+ nvobs = 0;
+ }
+
+ public void put(Vob vob, int[] scs) {
+ if(dbg) p("Add to GLVobMap "+this+": "+vob+" "+cs+" "+cs.length);
+ vob.move(Realtime.ObjectSpace.HOLD);
+ int ind = vob.putGL(vs, cs);
+ if(ind == 0) return;
+ // Now, stash it away.
+ cs[nvobs] = scs[0];
+ vobs[nvobs++] = vob;
+ list[curs++] = (GL.RENDERABLEN | ind);
+ list[curs++] = scs.length;
+ for(int i=0; i<scs.length; i++)
+ list[curs++] = scs[i];
+ }
+ public void put(Vob vob, int coordsys1, int coordsys2, int coordsys3) {
+ if(dbg) p("Add to GLVobMap "+this+": "+vob+" "+coordsys1+" "
+ +coordsys2+" "+coordsys3+" curs: "+curs);
+ vob.move(Realtime.ObjectSpace.HOLD);
+ int ind = vob.putGL(vs, coordsys1, coordsys2, coordsys3);
+ if(ind == 0) return;
+ // Now, stash it away.
+ cs[nvobs] = coordsys1;
+ vobs[nvobs++] = vob;
+ list[curs++] = (GL.RENDERABLE3 | ind);
+ list[curs++] = coordsys1;
+ list[curs++] = coordsys2;
+ list[curs++] = coordsys3;
+ }
+ public void put(Vob vob, int coordsys1, int coordsys2) {
+ if(dbg) p("Add to GLVobMap "+this+": "+vob+" "+coordsys1+" "
+ +coordsys2+" curs: "+curs);
+ vob.move(Realtime.ObjectSpace.HOLD);
+ int ind = vob.putGL(vs, coordsys1, coordsys2);
+ if(ind == 0) return;
+ // Now, stash it away.
+ cs[nvobs] = coordsys1;
+ vobs[nvobs++] = vob;
+ list[curs++] = (GL.RENDERABLE2 | ind);
+ list[curs++] = coordsys1;
+ list[curs++] = coordsys2;
+ }
+ public void put(Vob vob, int coordsys1) {
+ if(dbg) p("Add "+this+": "+vob+" "+coordsys1+
+ " curs: "+curs);
+ vob.move(Realtime.ObjectSpace.HOLD);
+ int ind = vob.putGL(vs, coordsys1);
+ if(ind == 0) return;
+ // Now, stash it away.
+ cs[nvobs] = coordsys1;
+ vobs[nvobs++] = vob;
+ list[curs++] = (GL.RENDERABLE1 | ind);
+ list[curs++] = coordsys1;
+ }
+ public void put(Vob vob) {
+ if(dbg) p("Add "+this+": "+vob+ " curs: "+curs);
+ vob.move(Realtime.ObjectSpace.HOLD);
+ int ind = vob.putGL(vs);
+ if(ind == 0) return;
+ // Now, stash it away.
+ vobs[nvobs++] = vob;
+ list[curs++] = (GL.RENDERABLE0 | ind);
+ }
+ public void dump() {
+ p("GLVobMap");
+ for(int i=0; i<nvobs; i++) {
+ p(cs[i] + " "+vobs[i]);
+ }
+ String s = "";
+ for(int i=0; i<curs; i++) {
+ s = s + " " + list[i];
+ }
+ p(s);
+ }
+ public Vob getVobByCS(int csind) {
+ for(int i=nvobs-1; i>=0; i--) {
+ if(cs[i] == csind)
+ return (Vob)vobs[i];
+ }
+ return null;
+ }
+
+ public int _putChildVobScene(ChildVobScene child, int coorderResult,
+ int[] cs) {
+ if(dbg) p("put child: "+child+", "+this+": "+cs);
+ if(coorderResult == 0) return 0;
+
+ // Now, stash it away.
+ if (true) throw new Error("unimpl.");
+ /*
+ list[curs++] = (GL.RENDERABLE_VS |
+ ((GLChildVobScene)child).childVS.getChildVSId());
+ list[curs++] = coorderResult;
+ */
+ /*
+ list[curs++] = cs.length;
+ for (int i=0; i<cs.length; i++)
+ list[curs++] = cs[i];
+ */
+ return coorderResult;
+ }
+
+}
+
More information about the Fencommits
mailing list