Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ env:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '16'
java-version: '24'
cache: gradle
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
Expand All @@ -22,12 +24,14 @@ jobs:
- run: gradle assemble --no-daemon
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '16'
java-version: '24'
cache: gradle
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
Expand All @@ -43,7 +47,7 @@ jobs:
- uses: actions/setup-java@master
with:
distribution: 'temurin'
java-version: '16'
java-version: '24'
cache: gradle
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '16'
java-version: '24'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ repositories {
}

compileJava {
options.release = 19
options.release = 24
}

jacoco {
toolVersion = "0.8.8"
toolVersion = "0.8.13"
}

jacocoTestReport {
Expand All @@ -28,7 +28,7 @@ jacocoTestReport {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(19)
languageVersion = JavaLanguageVersion.of(24)
}
withSourcesJar()
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/suga/engine/GameEngine.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package suga.engine;

import suga.engine.game.Game;
import suga.engine.graphics.GraphicsPanel;
import suga.engine.input.keyboard.GameKeyListener;
import suga.engine.input.mouse.GameMouseListener;
import suga.engine.logger.GeneralLogger;
import suga.engine.logger.Logger;
import suga.engine.threads.GameLogicThread;
import suga.engine.threads.GraphicsThread;
import suga.engine.threads.SugaThread;
import suga.engine.input.keyboard.GameKeyListener;
import suga.engine.game.Game;

import javax.swing.*;
import java.awt.*;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/suga/engine/game/BasicGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import suga.engine.game.objects.GameObject;
import suga.engine.graphics.DrawListener;
import suga.engine.graphics.GraphicsPanel;
import suga.engine.input.keyboard.GameKeyListener;
import suga.engine.input.keyboard.KeyValue;
import suga.engine.input.mouse.BasicMouseListener;
import suga.engine.input.mouse.GameMouseListener;
import suga.engine.logger.Level;
import suga.engine.physics.BasicPhysicsEngine;
import suga.engine.physics.PhysicsEngine;
import suga.engine.physics.collidables.Collidable;
import suga.engine.threads.SugaThread;
import suga.engine.input.keyboard.GameKeyListener;
import suga.engine.input.keyboard.KeyValue;

import java.awt.event.MouseEvent;
import java.util.*;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/suga/engine/game/BasicScene.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package suga.engine.game;

import suga.engine.input.keyboard.KeyValue;

import java.awt.*;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/suga/engine/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import suga.engine.game.objects.GameObject;
import suga.engine.graphics.DrawListener;
import suga.engine.graphics.GraphicsPanel;
import suga.engine.input.keyboard.GameKeyListener;
import suga.engine.input.mouse.GameMouseListener;
import suga.engine.threads.SugaThread;
import suga.engine.input.keyboard.GameKeyListener;

/**
* Games require a main game loop to run along with game components that need to be run every game cycle.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package suga.engine.game.objects;

import suga.engine.graphics.GraphicsPanel;
import suga.engine.graphics.DrawListener;
import suga.engine.graphics.GraphicsPanel;
import suga.engine.physics.BasicPhysical;
import suga.engine.physics.Vector;
import suga.engine.physics.collidables.Collidable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ public interface GraphicsPanelInterface {
* @param image The image to draw to the screen.
*/
void addImage (int x, int y, int width, int height, BufferedImage image);

/**
* Called each frame by the GraphicsThread. This method should be inherited from JComponent but is defined in
* Component.
*/
void repaint ();
}
5 changes: 4 additions & 1 deletion src/main/java/suga/engine/sound/JavaxSoundManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import suga.engine.logger.Level;

import javax.sound.sampled.*;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/suga/engine/threads/AbstractThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package suga.engine.threads;

import suga.engine.GameEngine;
import suga.engine.logger.Level;

/**
* The AbstractThread implements most of the common elements between threads including setters/getters for pausing,
* frame rate and more.
*
* @author Sugaku
*/
public abstract class AbstractThread extends Thread implements SugaThread {

/**
* Whether to exit the thread.
*/
protected boolean stopped = false;

/**
* Whether to simulate game logic or not.
*/
protected boolean paused = false;

/**
* The target frame rate for this thread.
*/
protected int frameRate;

/**
* The time that this graphics thread was started. Used in calculating average frame rate.
*/
protected long startTime = 0;

/**
* The number of frames that have been rendered since the thread started.
*/
protected long frames = 0;


/**
* Creates a new thread with the given target rate.
*
* @param frameRate The target frequency to draw frames at.
*/
protected AbstractThread (int frameRate) {
this.frameRate = frameRate;
}

/**
* Sets the target frame rate of this GraphicsThread.
*
* @param val The new value for the target frame rate.
*/
public void setFrameRate (int val) {
if (val <= 0) {
GameEngine.getInstance().getLogger().log(this.getClass().toString().replaceAll(".+\\.", "") + ": " + val + ". Only natural numbers (no zero) allowed.", Level.EXCEPTION);
return;
}
this.frameRate = val;
}

/**
* Accessor method for the current target frame rate of the thread.
*
* @return The current target thread refresh rate.
*/
public int getFrameRate () {
return frameRate;
}

/**
* Sets whether the thread is paused or not.
*
* @param val Whether the thread should be paused or not.
*/
public void setPaused (boolean val) {
paused = val;
}

/**
* Accessor method for the current status of the thread.
*
* @return Whether the thread is paused currently or not.
*/
public boolean getPaused () {
return paused;
}

/**
* Sets whether the thread is stopped or not.
*
* @param val Whether the thread should be stopped.
*/
public void setStopped (boolean val) {
stopped = val;
}

/**
* Accessor method for the current status of the thread.
*
* @return Whether this thread has been stopped or not.
*/
public boolean getStopped () {
return stopped;
}

/**
* Returns the average frame rate while this GraphicsThread has been running.
*
* @return The average frame rate of this thread since starting.
*/
public double getFPS () {
return (frames * 1.0) / ((System.currentTimeMillis() - startTime) / 1000.0);
}
}
Loading