Skip to content

Commit

Permalink
Fixed graphic glitches when changing screen
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Oct 23, 2018
1 parent 76d9d77 commit 87151ed
Show file tree
Hide file tree
Showing 113 changed files with 154 additions and 11,660 deletions.
2 changes: 1 addition & 1 deletion Flow
Submodule Flow updated from fc2468 to 59b89e
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ public MarioScreen() {
historyBehavior = HistoryBehavior.ALWAYS_KEEP_IN_HISTORY;
}

@Override
public void graphicInitialized() {
try {
if (MarioScreen.skin == null) {
MarioScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioskin.png");
}
if (MarioScreen.groundskin == null) {
MarioScreen.groundskin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioground.png");
}
if (MarioScreen.gpuTest2 == null) {
try {
MarioScreen.gpuTest2 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest2");
} catch (final Exception ex) {}
}
if (MarioScreen.gpuTest1 == null) {
try {
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest12");
MarioScreen.gpuTest12 = true;
} catch (final Exception ex) {
MarioScreen.gpuTest12 = false;
try {
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest1");
} catch (final Exception ex2) {}
}
}
if (MarioScreen.gpuTest3 == null) {
try {
MarioScreen.gpuTest3 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("N:\\gputest\\font_gputest3.png");
} catch (final Exception ex) {
ex.printStackTrace();
}
}
} catch (final IOException e) {
e.printStackTrace();
}
}

@Override
public void initialized() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ public TetrisScreen() {

@Override
public void initialized() {
StaticVars.windowZoom.onNext(2f);
}

@Override
public void graphicInitialized() {
try {
e = d.engine;
r = d.renderer;
if (TetrisScreen.skin == null) {
TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/tetrisskin.png");
}
StaticVars.windowZoom.onNext(2f);
} catch (final IOException e) {
e.printStackTrace();
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void initialized() throws InterruptedException {

}

@Override
public void graphicInitialized() throws InterruptedException {
// TODO Auto-generated method stub

}

@Override
public void render() {
// TODO Auto-generated method stub
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/it/cavallium/warppi/gui/DisplayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ private void updateCurrentScreen(Screen screen) {
screen.create();
}
this.screen = screen;
screenChange.release();
if (screen.initialized == false) {
screen.initialize();
}
screenChange.release();
} catch (final Exception e) {
e.printStackTrace();
Engine.getPlatform().exit(0);
Expand All @@ -267,10 +267,10 @@ public void replaceScreen(final Screen screen) {
try {
screen.create();
this.screen = screen;
screenChange.release();
if (screen.initialized == false) {
screen.initialize();
}
screenChange.release();
} catch (final Exception e) {
e.printStackTrace();
Engine.getPlatform().exit(0);
Expand Down Expand Up @@ -372,6 +372,13 @@ private void draw_init() {
}
}
}
if (!screen.graphicInitialized) {
try {
screen.initializeGraphic();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
renderer.glClear(engine.getWidth(), engine.getHeight());
}

Expand Down Expand Up @@ -439,7 +446,6 @@ public void loop() {
setScreen(initialScreen);
initialScreen = null;
}
screen.initialize();
} catch (final Exception e) {
e.printStackTrace();
Engine.getPlatform().exit(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

public interface GraphicalInterface {
void create() throws InterruptedException;

void initialize() throws InterruptedException;

void initializeGraphic() throws InterruptedException;

void render();

Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/it/cavallium/warppi/gui/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public abstract class HUD implements GraphicalInterface {
public DisplayManager d;
public boolean created = false;
public boolean graphicInitialized = false;
public boolean initialized = false;
public boolean visible = true;

Expand All @@ -16,6 +17,14 @@ public void initialize() throws InterruptedException {
}
}

@Override
public void initializeGraphic() throws InterruptedException {
if (!graphicInitialized) {
graphicInitialized = true;
graphicInitialized();
}
}

@Override
public void create() throws InterruptedException {
if (!created) {
Expand All @@ -26,6 +35,8 @@ public void create() throws InterruptedException {

public abstract void created() throws InterruptedException;

public abstract void graphicInitialized() throws InterruptedException;

public abstract void initialized() throws InterruptedException;

public abstract void renderBackground();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ public interface Skin {

void use(GraphicEngine d);

/**
* May not be available before initialization
* @return skin width
*/
int getSkinWidth();

/**
* May not be available before initialization
* @return skin height
*/
int getSkinHeight();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public void created() throws InterruptedException {}
@Override
public void initialized() throws InterruptedException {}

@Override
public void graphicInitialized() throws InterruptedException {}

@Override
public void render() {
Utils.getFont(false, true).use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public void created() throws InterruptedException {
@Override
public void initialized() throws InterruptedException {}

@Override
public void graphicInitialized() throws InterruptedException {}

@Override
public void render() {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public void created() throws InterruptedException {}
@Override
public void initialized() throws InterruptedException {}

@Override
public void graphicInitialized() throws InterruptedException {}

@Override
public void render() {
final Renderer renderer = Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void initialized() throws InterruptedException {
Engine.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().hide();
StaticVars.windowZoom.onNext(1f);
}

@Override
public void graphicInitialized() throws InterruptedException {}

@Override
public void beforeRender(final float dt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public void initialized() throws InterruptedException {
/* Fine caricamento */
}

@Override
public void graphicInitialized() throws InterruptedException {
/* Fine caricamento */
}

@Override
public void beforeRender(final float dt) {
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager().error == null) {
Expand Down
29 changes: 29 additions & 0 deletions core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene
public DisplayManager d;
public boolean created = false;
public boolean initialized = false;
public boolean graphicInitialized = false;
public HistoryBehavior historyBehavior = HistoryBehavior.NORMAL;

public static long lastDebugScreenID = 1;
Expand All @@ -19,6 +20,14 @@ public Screen() {
debugScreenID = lastDebugScreenID++;
}

@Override
public void initializeGraphic() throws InterruptedException {
if (!graphicInitialized) {
graphicInitialized = true;
graphicInitialized();
}
}

@Override
public void initialize() throws InterruptedException {
if (!initialized) {
Expand All @@ -35,10 +44,30 @@ public void create() throws InterruptedException {
}
}

/**
* Called when creating the screen
* Called before initialized()
* Called before graphicInitialized()
* @throws InterruptedException
*/
public abstract void created() throws InterruptedException;

/**
* Load everything except skins, etc...
* Called after created()
* Called after graphicInitialized()
* @throws InterruptedException
*/
public abstract void initialized() throws InterruptedException;

/**
* Load skins, etc...
* Called after created()
* Called before initialized()
* @throws InterruptedException
*/
public abstract void graphicInitialized() throws InterruptedException;

@Override
public abstract void render();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public void created() throws InterruptedException {}
@Override
public void initialized() throws InterruptedException {}

@Override
public void graphicInitialized() throws InterruptedException {}

@Override
public void render() {
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public void paintComponent(final Graphics g) {
if (renderingLoop != null) {
renderingLoop.refresh();


final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData();
SwingRenderer.canvas2d = a;
g.clearRect(0, 0, display.r.size[0] * mult, display.r.size[1] * mult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static Texture importTexture(final GL gl, final String string) throws IOExceptio
}

static OpenedTextureData openTexture(final String file, final boolean isResource) throws GLException, IOException {
BufferedImage img = ImageIO.read(isResource ? JOGLRenderer.class.getResource("/" + file) : new File(file).toURI().toURL());
BufferedImage img = ImageIO.read(isResource ? JOGLRenderer.class.getResource(file) : new File(file).toURI().toURL());
File f;
if (isResource) {
f = Files.createTempFile("texture-", ".png").toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ public void display(final GLAutoDrawable glad) {

final boolean linear = windowZoom % (int) windowZoom != 0f;
if (refreshViewport) {
System.err.println("[[[REFVP");
refreshViewport = false;
gl.glViewport(0, 0, realWindowSize[0], realWindowSize[1]);

Expand Down
Loading

0 comments on commit 87151ed

Please sign in to comment.