diff --git a/pixels/.classpath b/pixels/.classpath new file mode 100644 index 0000000..dfa42f8 --- /dev/null +++ b/pixels/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/pixels/.idea/$PRODUCT_WORKSPACE_FILE$ b/pixels/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..79be354 --- /dev/null +++ b/pixels/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 11 + + + + + + + + \ No newline at end of file diff --git a/pixels/.idea/misc.xml b/pixels/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/pixels/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pixels/.idea/modules.xml b/pixels/.idea/modules.xml new file mode 100644 index 0000000..76afca1 --- /dev/null +++ b/pixels/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pixels/.idea/workspace.xml b/pixels/.idea/workspace.xml new file mode 100644 index 0000000..2c42c43 --- /dev/null +++ b/pixels/.idea/workspace.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1566930672613 + + + + \ No newline at end of file diff --git a/pixels/.project b/pixels/.project new file mode 100644 index 0000000..81e7df1 --- /dev/null +++ b/pixels/.project @@ -0,0 +1,17 @@ + + + pixels + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/pixels/.settings/org.eclipse.jdt.core.prefs b/pixels/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b81b13d --- /dev/null +++ b/pixels/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=10 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=11 diff --git a/pixels/.vscode/launch.json b/pixels/.vscode/launch.json new file mode 100644 index 0000000..1148705 --- /dev/null +++ b/pixels/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Debug (Launch) - Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "Debug (Launch)-Init", + "request": "launch", + "mainClass": "bz.bronze.pixels.Init", + "projectName": "pixels" + } + ] +} \ No newline at end of file diff --git a/pixels/bin/.project b/pixels/bin/.project new file mode 100644 index 0000000..d176cb0 --- /dev/null +++ b/pixels/bin/.project @@ -0,0 +1,17 @@ + + + ge + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/pixels/bin/bz/bronze/pixels/Gameloop.class b/pixels/bin/bz/bronze/pixels/Gameloop.class new file mode 100644 index 0000000..0710e71 Binary files /dev/null and b/pixels/bin/bz/bronze/pixels/Gameloop.class differ diff --git a/pixels/bin/bz/bronze/pixels/Init.class b/pixels/bin/bz/bronze/pixels/Init.class new file mode 100644 index 0000000..07ee485 Binary files /dev/null and b/pixels/bin/bz/bronze/pixels/Init.class differ diff --git a/pixels/bin/bz/bronze/pixels/Renderer.class b/pixels/bin/bz/bronze/pixels/Renderer.class new file mode 100644 index 0000000..a0a2b6e Binary files /dev/null and b/pixels/bin/bz/bronze/pixels/Renderer.class differ diff --git a/pixels/bin/bz/bronze/pixels/Window.class b/pixels/bin/bz/bronze/pixels/Window.class new file mode 100644 index 0000000..e30dc39 Binary files /dev/null and b/pixels/bin/bz/bronze/pixels/Window.class differ diff --git a/pixels/out/production/pixels/bz/bronze/pixels/Gameloop.class b/pixels/out/production/pixels/bz/bronze/pixels/Gameloop.class new file mode 100644 index 0000000..0ae3910 Binary files /dev/null and b/pixels/out/production/pixels/bz/bronze/pixels/Gameloop.class differ diff --git a/pixels/out/production/pixels/bz/bronze/pixels/Init.class b/pixels/out/production/pixels/bz/bronze/pixels/Init.class new file mode 100644 index 0000000..24f6a07 Binary files /dev/null and b/pixels/out/production/pixels/bz/bronze/pixels/Init.class differ diff --git a/pixels/out/production/pixels/bz/bronze/pixels/Renderer.class b/pixels/out/production/pixels/bz/bronze/pixels/Renderer.class new file mode 100644 index 0000000..4ddd175 Binary files /dev/null and b/pixels/out/production/pixels/bz/bronze/pixels/Renderer.class differ diff --git a/pixels/out/production/pixels/bz/bronze/pixels/Window.class b/pixels/out/production/pixels/bz/bronze/pixels/Window.class new file mode 100644 index 0000000..aef1906 Binary files /dev/null and b/pixels/out/production/pixels/bz/bronze/pixels/Window.class differ diff --git a/pixels/pixels.iml b/pixels/pixels.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/pixels/pixels.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pixels/src/bz/bronze/pixels/Gameloop.java b/pixels/src/bz/bronze/pixels/Gameloop.java new file mode 100644 index 0000000..02a4ec6 --- /dev/null +++ b/pixels/src/bz/bronze/pixels/Gameloop.java @@ -0,0 +1,80 @@ +package bz.bronze.pixels; + +public class Gameloop implements Runnable { + + private Thread thread; + private Renderer renderer; + + private boolean running = false; + private final double TPS = 1.0/60.0; + + public void start() { + renderer = new Renderer(); + + thread = new Thread(this); + thread.run(); + } + + public void stop() { + + } + + public void run() { + running = true; + + boolean render = false; + + double firstTime = 0; + double lastTime = System.nanoTime() / 1000000000.0; + double passedTime = 0; + double unprocessedTime = 0; + + double tickTime = 0; + int ticks = 0; + int tps = 0; + + while (running) { + render = false; + + firstTime = System.nanoTime() / 1000000000.0; + passedTime = firstTime - lastTime; + lastTime = firstTime; + + unprocessedTime += passedTime; + tickTime += passedTime; + + while (unprocessedTime >= TPS) { + unprocessedTime -= TPS; + + render = true; + + if (tickTime >= 1.0) { + tickTime = 0; + tps = ticks; + ticks = 0; + } + + System.out.println("TPS: " + tps); + } + + if (render) { + renderer.clear(); + + Window.update(); + ticks++; + } else { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + dispose(); + } + + public void dispose() { + + } +} \ No newline at end of file diff --git a/pixels/src/bz/bronze/pixels/Init.java b/pixels/src/bz/bronze/pixels/Init.java new file mode 100644 index 0000000..7bc7f20 --- /dev/null +++ b/pixels/src/bz/bronze/pixels/Init.java @@ -0,0 +1,23 @@ +package bz.bronze.pixels; + +public class Init { + + static Window window = new Window(); + static Gameloop game = new Gameloop(); + + public static void print(String out) { + System.out.println(out); + } + + public static void init() { + window.create(); + game.start(); + + print("Window Initialized!"); + print("Gameloop Started!"); + } + + public static void main(String[] args) throws Exception { + init(); + } +} \ No newline at end of file diff --git a/pixels/src/bz/bronze/pixels/Renderer.java b/pixels/src/bz/bronze/pixels/Renderer.java new file mode 100644 index 0000000..7499eb7 --- /dev/null +++ b/pixels/src/bz/bronze/pixels/Renderer.java @@ -0,0 +1,20 @@ +package bz.bronze.pixels; + +import java.awt.image.DataBufferInt; + +public class Renderer { + private int pW, pH; + private int[] p; + + public Renderer() { + pW = Window.width; + pH = Window.height; + p = ((DataBufferInt)Window.pixels.getRaster().getDataBuffer()).getData(); + } + + public void clear() { + for (int i = 0; i < p.length; i++) { + p[i] += i; + } + } +} \ No newline at end of file diff --git a/pixels/src/bz/bronze/pixels/Window.java b/pixels/src/bz/bronze/pixels/Window.java new file mode 100644 index 0000000..b3922dc --- /dev/null +++ b/pixels/src/bz/bronze/pixels/Window.java @@ -0,0 +1,49 @@ +package bz.bronze.pixels; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.image.BufferStrategy; +import java.awt.image.BufferedImage; + +import javax.swing.*; + +public class Window { + static JFrame window = new JFrame(); + + static int width = 800; + static int height = 600; + static int scale = 1; + static String title = "pixels | v0.01"; + + static BufferedImage pixels = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + static Canvas viewport = new Canvas(); + static BufferStrategy bs; + static Graphics g; + + public static void update() { + g.drawImage(pixels, 0, 0, width, height, null); + bs.show(); + } + + public void create() { + window.setSize(width, height); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.setLayout(new BorderLayout()); + window.add(viewport, BorderLayout.CENTER); + window.setResizable(false); + window.setLocationRelativeTo(null); + window.setTitle(title); + window.setVisible(true); + + Dimension s = new Dimension(width * scale, height * scale); + viewport.setPreferredSize(s); + viewport.setMaximumSize(s); + viewport.setMinimumSize(s); + + viewport.createBufferStrategy(2); + bs = viewport.getBufferStrategy(); + g = bs.getDrawGraphics(); + } +} \ No newline at end of file