Skip to content

Commit

Permalink
limited to 30fps because of performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythical-Atlas committed May 14, 2020
1 parent d3fd596 commit a587313
Show file tree
Hide file tree
Showing 12 changed files with 1,690 additions and 29 deletions.
Binary file modified Sonic Fan Game/bin/objects/Player.class
Binary file not shown.
Binary file modified Sonic Fan Game/bin/objects/Ring.class
Binary file not shown.
Binary file modified Sonic Fan Game/bin/objects/Spring.class
Binary file not shown.
977 changes: 977 additions & 0 deletions Sonic Fan Game/hs_err_pid63060.log

Large diffs are not rendered by default.

674 changes: 674 additions & 0 deletions Sonic Fan Game/hs_err_pid6880.log

Large diffs are not rendered by default.

34 changes: 19 additions & 15 deletions Sonic Fan Game/src/main/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,27 @@ public void loop() {
float beginTime = Time.getTime();
float endTime = Time.getTime();
float dt = -1.0f;
boolean first = true;

// if the time since the start if the last frame is 1/60 of a second, update

while(!glfwWindowShouldClose(glfwWindow)) {
glfwPollEvents();

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if(dt >= 0) {currentScene.update(dt);}

glFlush();
//glfwSwapBuffers(glfwWindow);

endTime = Time.getTime();
dt = endTime - beginTime;
beginTime = endTime;

//System.out.println("" + (1.0f / dt) + " FPS");
if(Time.getTime() - beginTime >= 1.0f / 30.0f || first) {
dt = Time.getTime() - beginTime;
beginTime = Time.getTime();

glfwPollEvents();

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if(!first) {currentScene.update(dt);}

glFlush();
//glfwSwapBuffers(glfwWindow);

first = false;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sonic Fan Game/src/misc/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public void draw(float dt, Player p, Shader shader, Camera camera) {
SpriteRenderer.add(hud);

ring.draw(xOffset + 7 * SCALE, yOffset + 8 * SCALE, SCALE, SCALE, shader, camera);
ring.update((p.vel.getLength() / 10 + 1) * (dt / (1.0f / 60.0f)));
ring.update((p.vel.getLength() / 10 + 1) * 1/*(dt / (1.0f / 60.0f))*/);
ring.update((p.vel.getLength() / 10 + 1) * 1/*(dt / (1.0f / 60.0f))*/); // 30fps only

drawNumber(28 * SCALE, 3 * SCALE, p.rings, 3, shader, camera);

Expand Down
1 change: 1 addition & 0 deletions Sonic Fan Game/src/objects/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ else if(crouching0) {

public void draw(float dt, Shader shader, Camera camera) {
manageAnimations(dt);
manageAnimations(dt); // 30fps only

/*if(DRAW_MASKS) {
Shape temp;
Expand Down
3 changes: 2 additions & 1 deletion Sonic Fan Game/src/objects/Ring.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void draw(int scaleX, int scaleY, float dt, Shader shader, Camera camera)
}

anim.draw(pos.x, pos.y, scaleX, scaleY, shader, camera);
anim.update(dt / (1.0f / 60.0f));
anim.update(1/*dt / (1.0f / 60.0f)*/);
anim.update(1/*dt / (1.0f / 60.0f)*/); // 30fps only

if(destroy == 2 && anim.finished) {destroy = 3;}
}
Expand Down
4 changes: 3 additions & 1 deletion Sonic Fan Game/src/objects/Spring.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public void draw(int scaleX, int scaleY, float dt, Shader shader, Camera camera)
if(!bouncing) {anim.draw(pos.x, pos.y, scaleX, scaleY, shader, camera);}
else {
anim.draw(pos.x, pos.y, scaleX, scaleY, shader, camera);
anim.update(dt / (1.0f / 60.0f));
anim.update(1/*dt / (1.0f / 60.0f)*/);
anim.update(1/*dt / (1.0f / 60.0f)*/); // 30fps only

if(anim.finished) {
anim.reset();
bouncing = false;
Expand Down
2 changes: 0 additions & 2 deletions Sonic Fan Game/src/rendering/SpriteRenderBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ public void load() {
public void draw(Shader shader, Camera camera) {
if(spriteIndex == 0) {return;}

System.out.println("num sprites = " + spriteIndex);

glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferSubData(GL_ARRAY_BUFFER, 0, vertices);

Expand Down
21 changes: 12 additions & 9 deletions Sonic Fan Game/src/scenes/MainScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,42 +136,45 @@ public void update(float dt) {
checkKeysReleased();

player.update(dt, layer0, layer1, layer2, layer1Triggers, layer2Triggers, platforms, rings, springs);
if(rings != null) {
int[] removals = null;
for(int i = 0; i < rings.length; i++) {if(rings[i].destroy == 3) {removals = append(removals, i);}}
if(removals != null) {for(int i = 0; i < removals.length; i++) {rings = removeIndex(rings, removals[i]);}}
}
moveCamera(dt);

// 30fps only
player.update(dt, layer0, layer1, layer2, layer1Triggers, layer2Triggers, platforms, rings, springs);
if(rings != null) {
int[] removals = null;
for(int i = 0; i < rings.length; i++) {if(rings[i].destroy == 3) {removals = append(removals, i);}}
if(removals != null) {for(int i = 0; i < removals.length; i++) {rings = removeIndex(rings, removals[i]);}}
}
moveCamera(dt);
// 30fps only

/*Loader.leafBG.draw(new int[]{200, 100, 50}, player, graphics);*/

//leafForest1Map.draw(0, SCALE, SCALE, defaultShader, camera);
//leafForest1Map.draw(1, SCALE, SCALE, defaultShader, camera);

/*if(showTileMasks) {
if(layer0 != null) {for(int i = 0; i < layer0.length; i++) {layer0[i].draw(graphics, player.pos.add(-Loader.graphicsWidth / 2, -Loader.graphicsHeight / 2));}}
if(player.layer == 1 && layer1 != null) {for(int i = 0; i < layer1.length; i++) {layer1[i].draw(graphics, player.pos.add(-Loader.graphicsWidth / 2, -Loader.graphicsHeight / 2));}}
if(player.layer == 2 && layer2 != null) {for(int i = 0; i < layer2.length; i++) {layer2[i].draw(graphics, player.pos.add(-Loader.graphicsWidth / 2, -Loader.graphicsHeight / 2));}}
if(platforms != null) {for(int i = 0; i < platforms.length; i++) {platforms[i].draw(graphics, player.pos.add(-Loader.graphicsWidth / 2, -Loader.graphicsHeight / 2));}}
}*/

moveCamera(dt);

//leafLayer1.draw(defaultShader, camera);
//leafLayer2.draw(defaultShader, camera);

leafForest1Map.draw(1, SCALE, SCALE, defaultShader, camera);

if(springs != null) {for(int i = 0; i < springs.length; i++) {springs[i].draw(SCALE, SCALE, dt, defaultShader, camera);}}
if(rings != null) {for(int i = 0; i < rings.length; i++) {rings[i].draw(SCALE, SCALE, dt, defaultShader, camera);}}

player.draw(dt, defaultShader, camera);

if(!showTileMasks) {leafForest1Map.draw(2, SCALE, SCALE, defaultShader, camera);}

hud.draw(dt, player, defaultShader, camera);

SpriteRenderer.draw(spriteShader, camera);

if(!showTileMasks) {leafForest1Map.draw(2, SCALE, SCALE, defaultShader, camera);}
}

public void checkKeysPressed() {
Expand Down

0 comments on commit a587313

Please sign in to comment.