}
@Override
public void display(GLAutoDrawable drawable) {
try {
final GL3 gl = drawable.getGL().getGL3();
shaderState.bind(gl);
vao.bind(gl);
int spaceshipLoc = gl.glGetUniformLocation(shaderProgram.program(), "spaceshipTex");
gl.glUniform1i(spaceshipLoc, 0);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glBindTexture(GL.GL_TEXTURE_2D, spaceshipTex.getTextureObject(gl));
int explosionLoc = gl.glGetUniformLocation(shaderProgram.program(), "explosionTex");
gl.glUniform1i(explosionLoc, 1);
gl.glActiveTexture(GL.GL_TEXTURE0 + 1);
gl.glBindTexture(GL.GL_TEXTURE_2D, explosionTex.getTextureObject(gl));
vertices.clear();
colors.clear();
final FloatBuffer verticesb = (FloatBuffer) vertices.getBuffer();
final FloatBuffer colorsb = (FloatBuffer) colors.getBuffer();
long now = global.now();
long clock = System.currentTimeMillis();
fixPort(clock, true);
MutableAABB currentPort = getCurrentPort(clock);
portToMvMatrix(currentPort);
double margins = WIDTH_MARGINS;
final int n;
if (clock - lastQueryTime > SB_QUERY_RATE) {
n = query(now, SpatialQueries.contained(AABB.create(currentPort.min(X) - margins, currentPort.max(X) + margins, currentPort.min(Y) - margins, currentPort.max(Y) + margins)));
lastQueryTime = clock;
} else {
n = indexGen.get();
lastDispTime = clock;
}
int countInPort = 0;
for (Record<SpaceshipState> s : ships.slice(0, n)) {
long extrapolationTime = global.extrapolate ? Math.min(now, s.get($lastMoved) + MAX_EXTRAPOLATION_DURATION) : s.get($lastMoved);
Spaceship.getCurrentLocation(s, extrapolationTime, verticesb);
if (s.get($blowTime) > 0) // 0.01 - start blow animation, 1.0 - end of animation
colorsb.put(Math.min(1.0f, (now - s.get($blowTime)) / EXPLOSION_DURATION));
else
colorsb.put(0); // ship isn't blowing up
colorsb.put((float) Spaceship.getCurrentHeading(s, extrapolationTime));
// put the shotLength (0 for ship that's not firing)
colorsb.put(now - s.get($timeFired) < SHOOT_DURATION ? (float) s.get($shotLength) : 0f);
if (portContains(s.get($x), s.get($y)))
countInPort++;
}
setTitle((glxNode >= 0 ? "Node " + glxNode + ": " : "")
+ countInPort + " Spaceships "
+ (int) (port.max(X) - port.min(X)) + "x" + (int) (port.max(Y) - port.min(Y)));
vertices.flip();
colors.flip();
int numElems = verticesb.limit() / 2;
vertices.write(gl, 0, numElems);
colors.write(gl, 0, numElems);
shaderState.setUniform(gl, "in_Matrix", 4, 4, pmv.glGetMvMatrixf());
gl.glClear(GL3.GL_COLOR_BUFFER_BIT);
gl.glDrawArrays(GL3.GL_POINTS, 0, numElems);
vao.unbind(gl);
shaderState.unbind(gl);
} catch (Throwable t) {
System.err.println("XXXXXX");