use EventBus instead of ResolutionChangeListener
This commit is contained in:
parent
ec39392689
commit
54b1b3bb1c
|
@ -30,12 +30,12 @@ import org.newdawn.slick.opengl.InternalTextureLoader;
|
|||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.opengl.renderer.SGL;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.errorhandling.ErrorDumpable;
|
||||
import yugecin.opsudance.events.ResolutionChangedEvent;
|
||||
import yugecin.opsudance.utils.GLHelper;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static yugecin.opsudance.kernel.Entrypoint.sout;
|
||||
|
||||
|
@ -46,9 +46,10 @@ public class DisplayContainer implements ErrorDumpable {
|
|||
|
||||
private static SGL GL = Renderer.get();
|
||||
|
||||
public final EventBus eventBus;
|
||||
public final Demux demux;
|
||||
|
||||
private final DisplayMode nativeDisplayMode;
|
||||
private final List<ResolutionChangeListener> resolutionChangeListeners;
|
||||
|
||||
private Graphics graphics;
|
||||
private Input input;
|
||||
|
@ -70,19 +71,15 @@ public class DisplayContainer implements ErrorDumpable {
|
|||
private String glVendor;
|
||||
|
||||
@Inject
|
||||
public DisplayContainer(Demux demux) {
|
||||
public DisplayContainer(Demux demux, EventBus eventBus) {
|
||||
this.demux = demux;
|
||||
this.eventBus = eventBus;
|
||||
this.nativeDisplayMode = Display.getDisplayMode();
|
||||
this.resolutionChangeListeners = new LinkedList<>();
|
||||
targetRenderInterval = 16; // ~60 fps
|
||||
targetBackgroundRenderInterval = 41; // ~24 fps
|
||||
lastFrame = getTime();
|
||||
}
|
||||
|
||||
public void addResolutionChangeListener(ResolutionChangeListener listener) {
|
||||
resolutionChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
public void run() throws LWJGLException {
|
||||
while(!(Display.isCloseRequested() && demux.onCloseRequest())) {
|
||||
delta = getDelta();
|
||||
|
@ -170,9 +167,7 @@ public class DisplayContainer implements ErrorDumpable {
|
|||
|
||||
initGL();
|
||||
|
||||
for (ResolutionChangeListener resolutionChangeListener : resolutionChangeListeners) {
|
||||
resolutionChangeListener.onDisplayResolutionChanged(width, height);
|
||||
}
|
||||
eventBus.post(new ResolutionChangedEvent(this.width, this.height));
|
||||
|
||||
if (displayMode.getBitsPerPixel() == 16) {
|
||||
InternalTextureLoader.get().set16BitMode();
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
package yugecin.opsudance.core.state;
|
||||
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.ResolutionChangeListener;
|
||||
import yugecin.opsudance.core.events.EventListener;
|
||||
import yugecin.opsudance.events.ResolutionChangedEvent;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
public abstract class BaseOpsuState implements OpsuState, ResolutionChangeListener {
|
||||
public abstract class BaseOpsuState implements OpsuState, EventListener<ResolutionChangedEvent> {
|
||||
|
||||
protected final DisplayContainer displayContainer;
|
||||
|
||||
|
@ -34,14 +35,14 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangeListen
|
|||
|
||||
public BaseOpsuState(DisplayContainer displayContainer) {
|
||||
this.displayContainer = displayContainer;
|
||||
displayContainer.addResolutionChangeListener(this);
|
||||
displayContainer.eventBus.subscribe(ResolutionChangedEvent.class, this);
|
||||
}
|
||||
|
||||
protected void revalidate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayResolutionChanged(int width, int height) {
|
||||
public void onEvent(ResolutionChangedEvent event) {
|
||||
if (isCurrentState) {
|
||||
revalidate();
|
||||
return;
|
||||
|
|
|
@ -15,10 +15,16 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package yugecin.opsudance.core;
|
||||
package yugecin.opsudance.events;
|
||||
|
||||
public interface ResolutionChangeListener {
|
||||
public class ResolutionChangedEvent {
|
||||
|
||||
void onDisplayResolutionChanged(int width, int height);
|
||||
public final int width;
|
||||
public final int height;
|
||||
|
||||
public ResolutionChangedEvent(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import com.google.inject.AbstractModule;
|
|||
import yugecin.opsudance.PreStartupInitializer;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.Demux;
|
||||
import yugecin.opsudance.core.events.EventBus;
|
||||
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
|
||||
import yugecin.opsudance.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.states.EmptyRedState;
|
||||
|
@ -31,6 +32,8 @@ import yugecin.opsudance.core.state.transitions.FadeOutTransitionState;
|
|||
public class OpsuDanceModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(EventBus.class).asEagerSingleton();
|
||||
|
||||
bind(InstanceContainer.class).to(InstanceResolver.class);
|
||||
bind(PreStartupInitializer.class).asEagerSingleton();
|
||||
bind(Demux.class).asEagerSingleton();
|
||||
|
|
Loading…
Reference in New Issue
Block a user