diff --git a/pom.xml b/pom.xml index 4388cf9d..18108bde 100644 --- a/pom.xml +++ b/pom.xml @@ -144,6 +144,16 @@ + + com.google.inject + guice + 4.1.0 + + + com.google.inject.extensions + guice-assistedinject + 4.1.0 + org.jcraft jorbis diff --git a/src/yugecin/opsudance/OpsuDance.java b/src/yugecin/opsudance/OpsuDance.java new file mode 100644 index 00000000..1ce075c4 --- /dev/null +++ b/src/yugecin/opsudance/OpsuDance.java @@ -0,0 +1,44 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance; + +import com.google.inject.Inject; +import org.newdawn.slick.SlickException; +import yugecin.opsudance.core.Container; +import yugecin.opsudance.core.Demux; + +public class OpsuDance { + + private final Demux stateDemultiplexer; + private final Container container; + + @Inject + public OpsuDance(Demux stateDemultiplexer, Container container) { + this.stateDemultiplexer = stateDemultiplexer; + this.container = container; + } + + public void start() { + try { + container.start(); + } catch (SlickException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/yugecin/opsudance/PreStartupInitializer.java b/src/yugecin/opsudance/PreStartupInitializer.java new file mode 100644 index 00000000..e9326e4b --- /dev/null +++ b/src/yugecin/opsudance/PreStartupInitializer.java @@ -0,0 +1,67 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance; + +import com.google.inject.Inject; +import itdelatrisu.opsu.NativeLoader; +import itdelatrisu.opsu.Options; +import itdelatrisu.opsu.Utils; +import org.newdawn.slick.util.FileSystemLocation; +import org.newdawn.slick.util.Log; +import org.newdawn.slick.util.ResourceLoader; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; + +public class PreStartupInitializer { + + @Inject + public PreStartupInitializer() { + // load natives + File nativeDir; + if (!Utils.isJarRunning() && ( + (nativeDir = new File("./target/natives/")).isDirectory() || + (nativeDir = new File("./build/natives/")).isDirectory())) + ; + else { + nativeDir = Options.NATIVE_DIR; + try { + new NativeLoader(nativeDir).loadNatives(); + } catch (IOException e) { + Log.error("Error loading natives.", e); + } + } + System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath()); + System.setProperty("java.library.path", nativeDir.getAbsolutePath()); + try { + // Workaround for "java.library.path" property being read-only. + // http://stackoverflow.com/a/24988095 + Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths"); + fieldSysPath.setAccessible(true); + fieldSysPath.set(null, null); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + Log.warn("Failed to set 'sys_paths' field.", e); + } + + // set the resource paths + ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/"))); + + } + +} diff --git a/src/yugecin/opsudance/core/Container.java b/src/yugecin/opsudance/core/Container.java new file mode 100644 index 00000000..8057d3ab --- /dev/null +++ b/src/yugecin/opsudance/core/Container.java @@ -0,0 +1,67 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.core; + +import com.google.inject.Inject; +import org.lwjgl.opengl.Display; +import org.newdawn.slick.AppGameContainer; +import org.newdawn.slick.SlickException; + +/** + * based on itdelatrisu.opsu.Container + */ +public class Container extends AppGameContainer { + + @Inject + public Container(Demux demux) throws SlickException { + super(demux); + } + + @Override + public void start() throws SlickException { + try { + setup(); + getDelta(); + while (running()) + gameLoop(); + } catch (Exception e) { + } + destroy(); + } + + @Override + protected void gameLoop() throws SlickException { + int delta = getDelta(); + if (!Display.isVisible() && updateOnlyOnVisible) { + try { Thread.sleep(100); } catch (Exception e) {} + } else { + try { + updateAndRender(delta); + } catch (SlickException e) { + running = false; + return; + } + } + updateFPS(); + Display.update(); + if (Display.isCloseRequested()) { + if (game.closeRequested()) + running = false; + } + } +} diff --git a/src/yugecin/opsudance/core/ContainerWrapper.java b/src/yugecin/opsudance/core/ContainerWrapper.java new file mode 100644 index 00000000..2f2dc7f3 --- /dev/null +++ b/src/yugecin/opsudance/core/ContainerWrapper.java @@ -0,0 +1,23 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.core; + +public class ContainerWrapper { + + +} diff --git a/src/yugecin/opsudance/core/Demux.java b/src/yugecin/opsudance/core/Demux.java new file mode 100644 index 00000000..e00db535 --- /dev/null +++ b/src/yugecin/opsudance/core/Demux.java @@ -0,0 +1,65 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.core; + +import com.google.inject.Inject; +import org.newdawn.slick.Game; +import org.newdawn.slick.GameContainer; +import org.newdawn.slick.Graphics; +import org.newdawn.slick.SlickException; +import yugecin.opsudance.kernel.InstanceContainer; +import yugecin.opsudance.states.EmptyState; +import yugecin.opsudance.states.GameState; + +public class Demux implements Game { + + private final InstanceContainer instanceContainer; + + private GameState currentState; + + @Inject + public Demux(InstanceContainer instanceContainer) { + this.instanceContainer = instanceContainer; + } + + @Override + public void init(GameContainer container) throws SlickException { + currentState = instanceContainer.provide(EmptyState.class); + } + + @Override + public void update(GameContainer container, int delta) throws SlickException { + currentState.update(delta); + } + + @Override + public void render(GameContainer container, Graphics g) throws SlickException { + currentState.render(g); + } + + @Override + public boolean closeRequested() { + return false; + } + + @Override + public String getTitle() { + return "opsu!dance"; + } + +} diff --git a/src/yugecin/opsudance/kernel/Entrypoint.java b/src/yugecin/opsudance/kernel/Entrypoint.java new file mode 100644 index 00000000..66ea43b5 --- /dev/null +++ b/src/yugecin/opsudance/kernel/Entrypoint.java @@ -0,0 +1,28 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.kernel; + +import yugecin.opsudance.OpsuDance; + +public class Entrypoint { + + public static void main(String[] args) { + InstanceContainerImpl.initialize().provide(OpsuDance.class).start(); + } + +} diff --git a/src/yugecin/opsudance/kernel/InstanceContainer.java b/src/yugecin/opsudance/kernel/InstanceContainer.java new file mode 100644 index 00000000..b82251be --- /dev/null +++ b/src/yugecin/opsudance/kernel/InstanceContainer.java @@ -0,0 +1,24 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.kernel; + +public interface InstanceContainer { + + T provide(Class type); + +} diff --git a/src/yugecin/opsudance/kernel/InstanceContainerImpl.java b/src/yugecin/opsudance/kernel/InstanceContainerImpl.java new file mode 100644 index 00000000..ed1f7dcc --- /dev/null +++ b/src/yugecin/opsudance/kernel/InstanceContainerImpl.java @@ -0,0 +1,47 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.kernel; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class InstanceContainerImpl implements InstanceContainer { + + private static InstanceContainer instance; + + private Injector injector; + + private InstanceContainerImpl() { + injector = Guice.createInjector(new OpsuDanceModule()); + } + + public static InstanceContainer initialize() { + return instance = new InstanceContainerImpl(); + } + + @Deprecated + public static InstanceContainer get() { + return instance; + } + + @Override + public T provide(Class type) { + return injector.getInstance(type); + } + +} diff --git a/src/yugecin/opsudance/kernel/InstanceResolver.java b/src/yugecin/opsudance/kernel/InstanceResolver.java new file mode 100644 index 00000000..ed6780cd --- /dev/null +++ b/src/yugecin/opsudance/kernel/InstanceResolver.java @@ -0,0 +1,28 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.kernel; + +@SuppressWarnings("deprecation") +public class InstanceResolver implements InstanceContainer { + + @Override + public T provide(Class type) { + return InstanceContainerImpl.get().provide(type); + } + +} diff --git a/src/yugecin/opsudance/kernel/OpsuDanceModule.java b/src/yugecin/opsudance/kernel/OpsuDanceModule.java new file mode 100644 index 00000000..884c8d98 --- /dev/null +++ b/src/yugecin/opsudance/kernel/OpsuDanceModule.java @@ -0,0 +1,34 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.kernel; + +import com.google.inject.AbstractModule; +import yugecin.opsudance.PreStartupInitializer; +import yugecin.opsudance.core.Container; +import yugecin.opsudance.core.Demux; + +public class OpsuDanceModule extends AbstractModule { + + protected void configure() { + bind(InstanceContainer.class).to(InstanceResolver.class); + bind(PreStartupInitializer.class).asEagerSingleton(); + bind(Demux.class).asEagerSingleton(); + bind(Container.class).asEagerSingleton(); + } + +} diff --git a/src/yugecin/opsudance/states/EmptyState.java b/src/yugecin/opsudance/states/EmptyState.java new file mode 100644 index 00000000..2bc4d825 --- /dev/null +++ b/src/yugecin/opsudance/states/EmptyState.java @@ -0,0 +1,50 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.states; + +import com.google.inject.Inject; +import org.newdawn.slick.Graphics; + +public class EmptyState implements GameState { + + @Inject + public EmptyState() { + + } + + @Override + public void update(int delta) { + System.out.println("updatin' " + delta); + } + + @Override + public void render(Graphics g) { + System.out.println("renderin'"); + } + + @Override + public void enter() { + System.out.println("entered"); + } + + @Override + public void leave() { + System.out.println("left"); + } + +} diff --git a/src/yugecin/opsudance/states/GameState.java b/src/yugecin/opsudance/states/GameState.java new file mode 100644 index 00000000..ea679cf1 --- /dev/null +++ b/src/yugecin/opsudance/states/GameState.java @@ -0,0 +1,29 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance 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 3 of the License, or + * (at your option) any later version. + * + * opsu!dance 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 opsu!dance. If not, see . + */ +package yugecin.opsudance.states; + +import org.newdawn.slick.Graphics; + +public interface GameState { + + void update(int delta); + void render(Graphics g); + void enter(); + void leave(); + +}