Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #24

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b2550ee
Add Drone IO build
mcgivrer Apr 3, 2023
9ca3d67
feat(storm): Add storm thunder light
mcgivrer Apr 3, 2023
059dea7
feat(storm): Add storm thunder light
mcgivrer Apr 3, 2023
e0cf22f
feat(sound): Add Sound support with new resources
mcgivrer Apr 1, 2023
efcb17a
feat(storm): Add storm thunder light
mcgivrer Apr 3, 2023
3e0f0f1
Merge remote-tracking branch 'gitea/feature/rematsering-particles-and…
mcgivrer Apr 3, 2023
02abfa7
Merge branch 'develop' into feature/add-sound-support
mcgivrer Apr 3, 2023
47cdd24
merge Develop into feature/add-sound-support
mcgivrer Apr 3, 2023
25fdeeb
Merge branch 'feature/add-sound-support' into develop
mcgivrer Apr 3, 2023
4b92df6
Merge branch 'develop' into feature/rematsering-particles-and-behavior
mcgivrer Apr 3, 2023
6af43b4
fix(collisionBox): Add cpllision box for Coins and CoinBehavior.
mcgivrer Apr 3, 2023
96c5a7d
Fix(colorBig):: Add debugColor rendering on attractive coin's area dr…
mcgivrer Apr 3, 2023
feb5e6f
fix(maven): upgrade maven vesion to 3.9.0
mcgivrer Apr 3, 2023
71010b1
update drone.yml file with fix on sdkman
mcgivrer Apr 3, 2023
2682af5
Merge branch 'master' into feature/add-drone-io
mcgivrer Apr 3, 2023
0aad4bb
Merge branch 'feature/rematsering-particles-and-behavior' into develop
mcgivrer Apr 3, 2023
9caa9c3
Merge branch 'feature/add-drone-io' into develop
mcgivrer Apr 3, 2023
8eea2be
fix(TextEntity): Fix getText entity
mcgivrer Apr 5, 2023
3426791
feat(collision): Add Collision detection
mcgivrer Apr 5, 2023
effffa3
fix(try and fix): fix unit tests
mcgivrer Apr 6, 2023
0953ab6
Merge remote-tracking branch 'origin/develop' into develop
mcgivrer Apr 6, 2023
d6de24a
feat(loop): Add a GameLoop interface
mcgivrer Apr 8, 2023
4affce3
feat(loop): Add a GameLoop interface
mcgivrer Apr 9, 2023
68d2f8e
Merge branch 'feature/add-gameloop-interface' into develop
mcgivrer Apr 9, 2023
1c73364
Merge branch 'develop' of http://192.168.1.15:3000/SnapGames/minimal …
mcgivrer Apr 10, 2023
9f86b94
feat(Animations): implements Animations for player entity.
mcgivrer Apr 12, 2023
d5a13b9
feat(rotation): Add Rotation to PhysicEngine
mcgivrer Apr 13, 2023
101e3f4
Merge branch 'develop' into feature/add-rotation
mcgivrer Apr 17, 2023
cba535a
fix(doc): Fixing issue in chapter01
mcgivrer Apr 17, 2023
9444547
feat(animation): Animation implementation fixed
mcgivrer Apr 17, 2023
61cc500
Merge branch 'feature/add-rotation' into develop
mcgivrer Apr 17, 2023
e18fef5
fix(rotation): fix rotation center by adding center of object
mcgivrer Apr 17, 2023
469006f
Merge branch 'feature/implement-animations' into develop
mcgivrer Apr 17, 2023
a6cbe1e
feat(waterlevel): Add water effect behavior
mcgivrer Apr 17, 2023
fca0de7
fix rotation center on GameEntity in the Renderer
mcgivrer Apr 23, 2023
3f5607d
fix(switch) move to new jdk19 switch feature
mcgivrer Apr 23, 2023
bdeb8c4
feat(screenswitch): Add screen Display switching (code)
mcgivrer Apr 28, 2023
818364b
fix(watereffect): add a force corresponding to the water move up/down
mcgivrer Apr 28, 2023
a539a56
Merge branch 'develop' into feature/add-water-effect-behavior
mcgivrer Apr 28, 2023
3896770
feat(WaterLevel): let object drown in water move accordginly
mcgivrer Apr 28, 2023
d8ec078
Merge branch 'develop' of https://github.com/SnapGames/minimal into d…
mcgivrer May 3, 2023
f3e1ae3
feat(waterSim): finalize water level simulation
mcgivrer May 5, 2023
576aa29
Merge branch 'feature/add-water-effect-behavior' into develop
mcgivrer May 5, 2023
89b2767
Merge remote-tracking branch 'next/develop' into develop
mcgivrer May 5, 2023
8de0911
fix(rainVsWater): fix rain collision with WaterLevel.
mcgivrer May 5, 2023
22d6dd4
fix(waterDraw): fix WaterEffectBehavior draw operation.
mcgivrer May 5, 2023
b3df2d3
Merge pull request #25 from SnapGames/bugfix/fix-water-draw
mcgivrer May 5, 2023
fb45159
Update README.md
mcgivrer May 5, 2023
26d8cc7
fix(UT): Fix Unit test execution
mcgivrer May 5, 2023
0338b8a
Merge branch 'bigfix/26-camera-is-not-initialized-after-back-to-title…
mcgivrer May 6, 2023
10c02c8
feat(platform): Add platforms and collision response
mcgivrer May 21, 2023
925606c
fix(playarea): fix play area size in configuration
mcgivrer May 21, 2023
2951182
feat(debugOnWin): Move all debug info to Window's frame
mcgivrer May 22, 2023
04dafb2
Merge branch 'develop' into feature/move-debug-info-to-window-frame
mcgivrer May 22, 2023
f89c42b
Merge pull request 'feature/move-debug-info-to-window-frame' (#1) fro…
mcgivrer May 22, 2023
92af853
fix(debugDrawIssue): try to fix some debug infrmation draw for specif…
mcgivrer May 22, 2023
e9fe4bd
fix(debugScaling): Fix debug info display on window sizing
mcgivrer May 22, 2023
c265f27
fix default main class in JAR in pom.xml
mcgivrer May 22, 2023
0486554
add camera zooming capability
mcgivrer May 22, 2023
70d96ad
Merge remote-tracking branch 'next/develop' into feature/add-animations
mcgivrer May 23, 2023
838fcba
fix rendering hiccup
mcgivrer May 23, 2023
2c0ef16
Merge branch 'bugfix/fix-debug-info-on-screen-resize' into feature/ad…
mcgivrer May 23, 2023
1d5a28e
Merge branch 'feature/add-animations' into feature/add-platform-and-c…
mcgivrer May 23, 2023
50c8776
merge platform and animation
mcgivrer May 23, 2023
03a4629
fix(elasticity): fix bouncing on contact with platform
mcgivrer May 23, 2023
f2ab7a2
Merge pull request 'feature/add-platform-and-collision-response' (#2)…
mcgivrer May 24, 2023
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
10 changes: 10 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pipeline:
build:
image: alpine
pull: true
commands:
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk env install
- mvn clean install

3 changes: 2 additions & 1 deletion .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=19.0.2-zulu
maven=3.8.7
maven=3.9.0

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# README

[![Drone Build Status](http://nextserver02-1/api/badges/SnapGames/minimal/status.svg?ref=refs/heads/master)](http://nextserver02-1/SnapGames/minimal) | [![GitHub Build Status](https://github.com/SnapGames/minimal/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/SnapGames/minimal/actions/workflows/maven.yml)
[![Drone Build Status](http://nextserver02/api/badges/SnapGames/minimal/status.svg?ref=refs/heads/master)](http://nextserver02/SnapGames/minimal)
| [![GitHub Build Status](https://github.com/SnapGames/minimal/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/SnapGames/minimal/actions/workflows/maven.yml)
| [![Reports Cucumber Collection](https://messages.cucumber.io/api/report-collections/3cc52f6b-8997-4a02-9866-aeed7c91f215/badge)](https://reports.cucumber.io/report-collections/3cc52f6b-8997-4a02-9866-aeed7c91f215)

This is a small Minimalistic Game project , based on a master Game Java class, with some subclasses to let keep the code
ass short as possible.
Expand Down Expand Up @@ -46,7 +48,7 @@ $ java -jar target/game-0.0.1-SNAPSHOT-shaded.jar

After starting the latest jar file, the following picture may appear:

![Latest enhanced minimal game framework](docs/docs/illustrations/figure-screenshot-0.0.3.png "Latest enhanced minimal game framework")
![Latest enhanced minimal game framework](docs/docs/illustrations/figure-new-balls-images.png "Latest enhanced minimal game framework")

_figure 1 - Latest enhanced minimal game framework_

Expand Down
181 changes: 110 additions & 71 deletions docs/docs/chapter-01-the_game_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public class Game {
}
```

So, what do you think of my (too?) basic class ? nothing fancy, nothing "bling bling". only useful and mandatory.
So, what do you think of my (too?) basic class ? nothing fancy, nothing fancy. only useful and mandatory.

So yes, as you maybe now, the gameloop is the heart of any old school game. and even some Big game engine keep running
So yes, as you may be now, the game loop is the heart of any old school game. and even some Big game engine keep running
such old loop.
Let's dive into some details.

Expand Down Expand Up @@ -159,27 +159,30 @@ public class Game {
} catch (InterruptedException ie) {
System.err.println("error while trying to wait for sometime");
}
}}
//...
}
}
//...
}
```

So to maintain a sustainable frequency for that loop, I use the default current traditional FPS: 60 frames per second.
So to maintain a sustainable frequency for that loop, I use the default current frame-per-second ratio: 60 frames per
second. here we will get it from the method `getTargetFps()`.

So starting with that , defining the waiting time is a simple calculus.

```java
int timeFrame=1000/60;
int wait=timeFrame-elapsed;

int timeFrame=1000/getTargetFps();
int wait=(int)(elapsed<timeFrame ?timeFrame-elapsed:1);;
```

and the rest of the loop process is simple calls:

```java
elapsed=currentTime-previousTime;
input();
update(elapsed);
render();
input();
update(elapsed);
render();
```

- input() will manage all the player's device input like keyboard, mouse or joystick,
Expand All @@ -203,93 +206,102 @@ an overview of the solution:

_figure 6 - An overview of my implementation_

## The Game interface
## The GameLoop interface

The `Game` interface provides a standard contract to any application which want to be a game.
The `GameLoop` interface provides a standard contract to delegate the loop management to a specialized class
implementation.

Defining a standard lifecycle to a game with:
We will be able to create a Fixed time frame loop, where graphics are rendered in priority , or a Fixed time update loop
where physic and gameplay are prioritized first.

1. `initialize()`,
2. `create()`,
3. and then `loop()` on the created resources,
4. and finally `dispose()` them.
Defining a standard loop to a game with:

1. `input()`,
2. `update()`,
3. and then `draw()` on the screen.

This is exactly what our loop implementation will have to provide.

```java
public interface Game {
void initialize(String[] args);

void create(Game g);
void loop(Map<String, Object> context);

void input(Game g);
boolean isExit();

void update(Game g, double elapsed);
boolean isTestMode();

void render(Game g, int fps);
}
```

default void loop() {
}
Let's have a try with a FixedFrameGameLoop first, where the Game loop update and render everything even if it takes too
long, freezing the game play.

default void run(String[] args) {
### The Fixed Frame Loop

initialize(args);
loop();
dispose();
}
The default loop implementation would be a simple time frame based one. Trying to stick as far as possible to the frame
per second value set. In our sample code, we use a 1000.0/60.0 frame time corresponding to 60 frames per second.

void dispose();
First things first, just initialize our GameLoop for the game :

boolean isPaused();
```java
public interface FixedFrameGameLoop {

boolean isExitRequested();
private final Game game;
double FPS = 60.0;
double fpsDelay = 1000000.0 / 60.0;

public FixedFrameGameLoop(Game game) {
this.game = game;
}
//...
}
```

Inside a loop, the 3 historical game operations are prformed:

- input(),
- update(),
- render().

but let's dive in the loop in the default loop implementation.

### The loop

The default loop implementation would be a simple time frame based one. Trying to stick as far as poosible to the frame
per second value set. In our sample code, we use a 1000.0/60.0 frame time corresponding to 60 frames per second.

And during a loop, we call the 3 parts of the loop : manage `input()`, `update()` all game objects and `render()` all of
those.
And if the loop is during less than a frame time, add a litle wait.
And if the loop is during less than a frame time, add a little wait.

```java
public interface Game {
public interface FixedFrameGameLoop {
//...
default void loop() {
int frames = 0;
int fps = getTargetFps();
double internalTime = 0;
double previousTime = System.currentTimeMillis();
double currentTime = System.currentTimeMillis();
double elapsed = currentTime - previousTime;
create(this);
while (!isExitRequested()) {
currentTime = System.currentTimeMillis();
input(this);
elapsed = currentTime - previousTime;
if (!isPaused()) {
update(this, elapsed);
double start = 0;
double end = 0;
double dt = 0;
// FPS measure
long frames = 0;
long realFPS = 0;

long updates = 0;
long realUPS = 0;
long timeFrame = 0;
long loopCounter = 0;
int maxLoopCounter = (int) game.getConfiguration().get(ConfigAttribute.EXIT_TEST_COUNT_FRAME);
Map<String, Object> loopData = new HashMap<>();
while (!(isExit() || isTestMode() || isMaxLoopCounterReached(loopCounter, maxLoopCounter))) {
start = System.nanoTime() / 1000000.0;
loopCounter++;
game.input();
if (!game.isUpdatePause()) {
game.update(dt * .04);
updates += 1;
}
render(this, fps);

frames += 1;
internalTime += elapsed;
if (internalTime > 1000.0) {
fps = frames;
timeFrame += dt;
if (timeFrame > 1000) {
realFPS = frames;
frames = 0;
internalTime = 0;
realUPS = updates;
updates = 0;
timeFrame = 0;
}
waitUntilNextFrame(elapsed);
previousTime = currentTime;
prepareData(realFPS, realUPS, loopCounter, loopData);

game.draw(loopData);
waitUntilStepEnd(dt);

end = System.nanoTime() / 1000000.0;
dt = end - start;
}
}

Expand All @@ -302,12 +314,39 @@ public interface Game {
System.err.println("error while trying to wait for sometime");
}
}

private void prepareData(long realFPS, long realUPS, long loopCounter, Map<String, Object> loopData) {
loopData.put("cnt", loopCounter);
loopData.put("fps", realFPS);
loopData.put("ups", realUPS);
loopData.put("pause", game.isUpdatePause() ? "ON" : "OFF");
loopData.put("obj", game.getSceneManager().getActiveScene().getEntities().size());
loopData.put("scn", game.getSceneManager().getActiveScene().getName());
loopData.put("dbg", game.getDebug());
}
//...
}
```

And we need to link the exit and pause mode to the game with these 2 methods:

```java
public class FixedFrameGameLoop {
//...
@Override
public boolean isTestMode() {
return game.isTestMode();
}

@Override
public boolean isExit() {
return game.isExitRequested();
}
}
```

You can notice that we also compute the real frame rate (fps) with the `previousTime` and `currentTime` variables, and
maintain an internal `frames` counter.
You can notice that we also compute the real frame rate (`fps`) with the `end` and `start` variables, and
maintain an internal `frames` counter. An `ups` counter is also maintained.

## Conclusion

Expand Down
Loading