Projects >> shade >>200ec7885a9ba799169b2357d7699de43511c652

Chunk
Conflicting content
public class GlobalLight implements LightSource {

<<<<<<< HEAD
	private float angle, depth;

	public GlobalLight(float angle) {
		depth = 8;
		this.angle = angle;
	}

	public void render(StateBasedGame game, Graphics g,
			LuminousEntity... entities) {
		LightMask.enableStencil();
		for (LuminousEntity entity : entities) {
			Shape s = entity.castShadow(angle, depth);
			if (s != null) {
				g.fill(s);				
			}
		}
		LightMask.disableStencil();
		
		GameContainer c = game.getContainer();
		g.setColor(Color.black);
		g.fillRect(0, 0, c.getWidth(), c.getHeight());
		g.setColor(Color.white);

		GL11.glDisable(GL11.GL_STENCIL_TEST);
		GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
	}

	public void update(StateBasedGame game, int delta) {
		angle+=0.001f*delta;
	}
=======
    private static final float TRANSITION_TIME = 1 / 7f;
    private static final float TRANSITION_ANGLE = .0001f;
    private static final int SECONDS_PER_DAY = (int) Math.ceil(Math.PI * 2
            / TRANSITION_ANGLE);

    private int timeOfDay;
    private float angle, depth;

    public GlobalLight(float depth, float angle) {
        this.depth = depth;
        this.angle = angle;
    }

    public void render(StateBasedGame game, Graphics g,
                       LuminousEntity... entities) {
        LightMask.enableStencil();
        g.setColor(Color.black);
        for (LuminousEntity entity : entities) {
            Shape s = entity.castShadow(angle, depth);
            if (s != null) {
                g.fill(s);
            }
        }
        LightMask.disableStencil();

        GameContainer c = game.getContainer();
        g.fillRect(0, 0, c.getWidth(), c.getHeight());
        g.setColor(Color.white);

        // TODO where should these lines go??
        GL11.glDisable(GL11.GL_STENCIL_TEST);
        GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
    }

    public void update(StateBasedGame game, int delta) {
        timeOfDay = (timeOfDay + delta) % SECONDS_PER_DAY;
        if (dayOrNight()) {

        }
        angle += .005f;
    }

    private boolean dayOrNight() {
        return (timeOfDay > 1f * SECONDS_PER_DAY * (1 / 2 - TRANSITION_TIME));
    }

    public Shape castShadow(LuminousEntity e) {
        return e.castShadow(angle, depth);
    }
>>>>>>> a53f12951f363fa86f91e4006e74c90f624a9e9f

}
Solution content

public class GlobalLight implements LightSource {

    private static final float TRANSITION_TIME = 1 / 7f;
    private static final float TRANSITION_ANGLE = .0001f;
    private static final int SECONDS_PER_DAY = (int) Math.ceil(Math.PI * 2
            / TRANSITION_ANGLE);

    private int timeOfDay;
    private float angle, depth;

    public GlobalLight(float depth, float angle) {
        this.depth = depth;
        this.angle = angle;
    }

    public void render(StateBasedGame game, Graphics g,
                       LuminousEntity... entities) {
        LightMask.enableStencil();
        g.setColor(Color.black);
        for (LuminousEntity entity : entities) {
            Shape s = entity.castShadow(angle, depth);
            if (s != null) {
                g.fill(s);
            }
        }
        LightMask.disableStencil();

        GameContainer c = game.getContainer();
        g.fillRect(0, 0, c.getWidth(), c.getHeight());
        g.setColor(Color.white);

        // TODO where should these lines go??
        GL11.glDisable(GL11.GL_STENCIL_TEST);
        GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
    }

    public void update(StateBasedGame game, int delta) {
        timeOfDay = (timeOfDay + delta) % SECONDS_PER_DAY;
        if (dayOrNight()) {

        }
        angle += .005f;
    }

    private boolean dayOrNight() {
        return (timeOfDay > 1f * SECONDS_PER_DAY * (1 / 2 - TRANSITION_TIME));
    }

    public Shape castShadow(LuminousEntity e) {
        return e.castShadow(angle, depth);
    }

}
File
GlobalLight.java
Developer's decision
Version 2
Kind of conflict
Attribute
Cast expression
Method declaration
Chunk
Conflicting content
	}
    private int threshold;
 */
public class LightMask {

<<<<<<< HEAD
	protected final static Color SHADE = new Color(0, 0, 0, .5f);

	private LinkedList lights;

	public LightMask() {
		lights = new LinkedList();
	}

	public void add(LightSource light) {
		lights.add(light);
	}

	public void render(StateBasedGame game, Graphics g,
			LuminousEntity[] entities, Image... backgrounds) {
		renderLights(game, g, entities);
		renderBackgrounds(game, g, backgrounds);
		renderEntities(game, g, entities);
	}

	private void renderLights(StateBasedGame game, Graphics g,
			LuminousEntity... entities) {
		for (LightSource light : lights) {
			light.render(game, g, entities);
		}
		GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
		g.setColor(SHADE);
		GameContainer c = game.getContainer();
		g.fillRect(0, 0, c.getWidth(), c.getHeight());
		GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE);
	}

	private void renderBackgrounds(StateBasedGame game, Graphics g,
			Image... backgrounds) {
		// TODO render according to z-index
		// TODO render the obstacles over the shadows...
		GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE);
		for (Image background : backgrounds) {
			background.draw();
		}
	}

	private void renderEntities(StateBasedGame game, Graphics g,
			LuminousEntity... entities) {
		GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE);
		for (LuminousEntity entity : entities) {
			entity.render(game, g);
			entity.setLuminosity(getLuminosityFor(entity, g));
		}
	}

	private float getLuminosityFor(LuminousEntity entity, Graphics g) {
		return g.getPixel((int) entity.getXCenter(), (int) entity.getYCenter()).a;
	}

	/**
	 * Called before drawing the shadows cast by a light.
	 */
	protected static void enableStencil() {
		// write only to the stencil buffer
		GL11.glEnable(GL11.GL_STENCIL_TEST);
		GL11.glColorMask(false, false, false, false);
		GL11.glDepthMask(false);
		GL11.glClearStencil(0);
		// write a one to the stencil buffer everywhere we are about to draw
		GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
		// this is to always pass a one to the stencil buffer where we draw
		GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);

	/**
	 * Called after drawing the shadows cast by a light.
	 */
	protected static void disableStencil() {
		// resume drawing to everything
		GL11.glDepthMask(true);
		GL11.glColorMask(true, true, true, true);
		GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);

		// don't modify the contents of the stencil buffer
		GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
		GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
	}
=======
    protected final static Color SHADE = new Color(0, 0, 0, .3f);

    private LinkedList lights;

    public LightMask(int threshold) {
        this.threshold = threshold;
        lights = new LinkedList();
    }

    public void add(LightSource light) {
        lights.add(light);
    }

    public void render(StateBasedGame game, Graphics g,
                       LuminousEntity[] entities, Image... backgrounds) {
        renderLights(game, g, entities);
        renderBackgrounds(game, g, backgrounds);
        renderEntities(game, g, entities);
    }

    private void renderLights(StateBasedGame game, Graphics g,
                              LuminousEntity... entities) {
        for (LightSource light : lights) {
            light.render(game, g, entities);
        }

        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
        g.setColor(SHADE);
        GameContainer c = game.getContainer();
        g.fillRect(0, 0, c.getWidth(), c.getHeight());
        g.setColor(Color.white);
    }

    private void renderBackgrounds(StateBasedGame game, Graphics g,
                                   Image... backgrounds) {
        GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE);
        for (Image background : backgrounds) {
            background.draw();
        }
    }

    private void renderEntities(StateBasedGame game, Graphics g,
                                LuminousEntity... entities) {
        Arrays.sort(entities);
        int i = 0;

        GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ZERO);
        while (i < entities.length && entities[i].getZIndex() < threshold) {
            entities[i].render(game, g);
            entities[i].setLuminosity(getLuminosityFor(entities[i], g));
            i++;
        }

        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        while (i < entities.length) {
            entities[i].render(game, g);
            entities[i].setLuminosity(getLuminosityFor(entities[i], g));
            i++;
        }
    }

    private float getLuminosityFor(LuminousEntity entity, Graphics g) {
        return g.getPixel((int) entity.getXCenter(), (int) entity.getYCenter()).a;
    }

    /**
     * Called before drawing the shadows cast by a light.
     */
    protected static void enableStencil() {
        // write only to the stencil buffer
        GL11.glEnable(GL11.GL_STENCIL_TEST);
        GL11.glColorMask(false, false, false, false);
        GL11.glDepthMask(false);
        GL11.glClearStencil(0);
        // write a one to the stencil buffer everywhere we are about to draw
        GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
        // this is to always pass a one to the stencil buffer where we draw
        GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);
    }

    /**
     * Called after drawing the shadows cast by a light.
     */
    protected static void disableStencil() {
        // resume drawing to everything
        GL11.glDepthMask(true);
        GL11.glColorMask(true, true, true, true);
        GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);

        // don't modify the contents of the stencil buffer
        GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
    }
>>>>>>> a53f12951f363fa86f91e4006e74c90f624a9e9f

}
Solution content
 */
public class LightMask {


    protected final static Color SHADE = new Color(0, 0, 0, .3f);

    private int threshold;
    private LinkedList lights;

    public LightMask(int threshold) {
        this.threshold = threshold;
        lights = new LinkedList();
    }

    public void add(LightSource light) {
        lights.add(light);
    }

    public void render(StateBasedGame game, Graphics g,
                       LuminousEntity[] entities, Image... backgrounds) {
        renderLights(game, g, entities);
        renderBackgrounds(game, g, backgrounds);
        renderEntities(game, g, entities);
    }

    private void renderLights(StateBasedGame game, Graphics g,
                              LuminousEntity... entities) {
        for (LightSource light : lights) {
            light.render(game, g, entities);
        }

        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
        g.setColor(SHADE);
        GameContainer c = game.getContainer();
        g.fillRect(0, 0, c.getWidth(), c.getHeight());
        g.setColor(Color.white);
    }

    private void renderBackgrounds(StateBasedGame game, Graphics g,
                                   Image... backgrounds) {
        GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ONE);
        for (Image background : backgrounds) {
            background.draw();
        }
    }

    private void renderEntities(StateBasedGame game, Graphics g,
                                LuminousEntity... entities) {
        Arrays.sort(entities);
        int i = 0;

        GL11.glBlendFunc(GL11.GL_DST_ALPHA, GL11.GL_ZERO);
        while (i < entities.length && entities[i].getZIndex() < threshold) {
            entities[i].render(game, g);
            entities[i].setLuminosity(getLuminosityFor(entities[i], g));
            i++;
        }

        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        while (i < entities.length) {
            entities[i].render(game, g);
            entities[i].setLuminosity(getLuminosityFor(entities[i], g));
            i++;
        }
    }

    private float getLuminosityFor(LuminousEntity entity, Graphics g) {
        return g.getPixel((int) entity.getXCenter(), (int) entity.getYCenter()).a;
    }

    /**
     * Called before drawing the shadows cast by a light.
     */
    protected static void enableStencil() {
        // write only to the stencil buffer
        GL11.glEnable(GL11.GL_STENCIL_TEST);
        GL11.glColorMask(false, false, false, false);
        GL11.glDepthMask(false);
        GL11.glClearStencil(0);
        // write a one to the stencil buffer everywhere we are about to draw
        GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
        // this is to always pass a one to the stencil buffer where we draw
        GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);
    }

    /**
     * Called after drawing the shadows cast by a light.
     */
    protected static void disableStencil() {
        // resume drawing to everything
        GL11.glDepthMask(true);
        GL11.glColorMask(true, true, true, true);
        GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);

        // don't modify the contents of the stencil buffer
        GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
    }

}
File
LightMask.java
Developer's decision
Version 2
Kind of conflict
Attribute
Comment
Method declaration
Method invocation