Skip to content

Commit

Permalink
Fixed mac issues
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Jan 5, 2021
1 parent f70a46e commit 49b92fc
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 81 deletions.
1 change: 1 addition & 0 deletions client-core/src/com/benberi/cadesim/GameContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public void createFurtherScenes(int shipId) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
graphics.setResizable(false);
ScreenManager.getInstance().showScreen(ScreenEnum.GAME, context);
graphics.setTitle("GC: " + myVessel + " (" + myTeam + ")");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.benberi.cadesim.client.packet.in;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

import com.benberi.cadesim.GameContext;
import com.benberi.cadesim.client.codec.util.Packet;
import com.benberi.cadesim.client.packet.ClientPacketExecutor;
Expand All @@ -13,16 +19,22 @@ public RemovePlayerShip(GameContext ctx) {

@Override
public void execute(Packet p) {

String name = p.readByteString();
Vessel vessel = getContext().getEntities().getVesselByName(name);
if (vessel != null) {
getContext().getEntities().remove(vessel);
}
HashSet<Object> seen=new HashSet<>();
getContext().getEntities().vessels.removeIf(e->!seen.add(e.getName()));
}

@Override
public int getSize() {
return -1;
}

public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class EntityManager {
/**
* List of vessel entities in the game
*/
private List<Vessel> vessels = new ArrayList<Vessel>();
public List<Vessel> vessels = new ArrayList<Vessel>();

public EntityManager(GameContext context) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class MapEditorScreen extends AbstractScreen implements InputProcessor {
* The sea texture
*/
private Texture seaTile;

private OrthographicCamera camera;
public MapEditorScreen(GameContext context) {
this.context = context;
}
Expand All @@ -222,6 +222,7 @@ public void buildStage() {
createTiles();
createEmptyMap();
createMenu();
camera = new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
camera.position.x = 0;
camera.position.y = 200;
MapEditorScreen screen = this;
Expand All @@ -232,7 +233,7 @@ public void run() {
multiplexer.addProcessor(stage);
multiplexer.addProcessor(screen);
Gdx.input.setInputProcessor(multiplexer);
// graphics.setTitle("MapEditor - Blank");
graphics.setTitle("MapEditor - Blank");
}
});
update();
Expand All @@ -247,8 +248,8 @@ public void update(){

@Override
public void render(float delta) {
stage.getBatch().setProjectionMatrix(camera.combined);
update();
stage.getBatch().setProjectionMatrix(camera.combined);
drawSea();
// Render the map
renderMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class SeaBattleScreen extends AbstractScreen implements InputProcessor{
/**
* The camera view of the scene
*/
public OrthographicCamera camera;
public OrthographicCamera othercamera;

/**
* Whether the camera follows the vessel
Expand Down Expand Up @@ -168,7 +168,7 @@ private void recountVessels() {

@Override
public void buildStage() {
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 200);
othercamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 200);
Vessel v = Vessel.createVesselByType(context, null, 0, 0, context.myVesselType);
control = new BattleControlComponent(
context,
Expand Down Expand Up @@ -234,10 +234,10 @@ public void setSound_volume(float sound_volume) {

public void update(){
// update the camera
camera.update();
othercamera.update();
//keep user from scrolling to far to black screens
camera.position.x = clamp(camera.position.x, Gdx.graphics.getWidth() , -Gdx.graphics.getWidth() - 100);
camera.position.y = clamp(camera.position.y, Gdx.graphics.getHeight() + 800, -Gdx.graphics.getHeight() + 500);
othercamera.position.x = clamp(othercamera.position.x, Gdx.graphics.getWidth() , -Gdx.graphics.getWidth() - 100);
othercamera.position.y = clamp(othercamera.position.y, Gdx.graphics.getHeight() + 800, -Gdx.graphics.getHeight() + 500);
if (currentSlot > -1) {
if (vesselsCountWithCurrentPhase != vesselsCountNonSinking) { //bug fix-new players joining
MovePhase phase = MovePhase.getNext(currentPhase);
Expand Down Expand Up @@ -474,11 +474,11 @@ else if (vessel.getCurrentPerformingMove() == VesselMovementAnimation.BUMP_PHASE

// let camera move with vessel if it's supposed to
if (cameraFollowsVessel) {
if(camera != null && context.myVessel != null) {
if(othercamera != null && context.myVessel != null) {
Vessel myVessel = context.getEntities().getVesselByName(context.myVessel);
camera.translate(
getIsometricX(myVessel.getX(), myVessel.getY(), myVessel) - camera.position.x,
getIsometricY(myVessel.getX(), myVessel.getY(), myVessel) - camera.position.y
othercamera.translate(
getIsometricX(myVessel.getX(), myVessel.getY(), myVessel) - othercamera.position.x,
getIsometricY(myVessel.getX(), myVessel.getY(), myVessel) - othercamera.position.y
);
}
}
Expand Down Expand Up @@ -539,20 +539,20 @@ else if (vessel.getCurrentPerformingMove() == VesselMovementAnimation.BUMP_PHASE

@Override
public void render(float delta) {
Gdx.gl.glViewport(0,200, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 200);
update();
if(battleMenu.teamTable.isVisible()) {
battleMenu.fillTeamList();
}
stage.getBatch().setProjectionMatrix(camera.combined);
stage.getViewport().setCamera(othercamera);
stage.getBatch().setProjectionMatrix(othercamera.combined);
stage.getViewport().apply();
drawSea();
drawIsland();
// Render the map
renderSeaBattle();
// Render ships
renderEntities();
information.render(delta);
// Render control
control.render(delta);
control.update();
battleMenu.render(delta);
Expand Down Expand Up @@ -593,7 +593,7 @@ private void drawIsland() {
* Renders all entities
*/
private void renderEntities() {
renderer.setProjectionMatrix(camera.combined);
renderer.setProjectionMatrix(othercamera.combined);
if(blockadeMap != null) {
for (int x = BlockadeMap.MAP_WIDTH - 1; x > -1; x--) {
for (int y = BlockadeMap.MAP_HEIGHT - 1; y > -1; y--) {
Expand Down Expand Up @@ -638,7 +638,7 @@ private void renderEntities() {


Vector3 v = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(v, 0, 200, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 200);
othercamera.unproject(v, 0, 200, Gdx.graphics.getWidth(), Gdx.graphics.getHeight() - 200);

float xxx = xx + vessel.getOrientationLocation().getOffsetx();
float yyy = yy + vessel.getOrientationLocation().getOffsety();
Expand Down Expand Up @@ -820,7 +820,7 @@ public void dispose() {
currentSlot = -1;
information.dispose();
recountVessels();
camera = null;
othercamera = null;
}

private void renderSeaBattle() {
Expand Down Expand Up @@ -861,8 +861,8 @@ else if (whirls[i][j] != null) {
}

private boolean canDraw(float x, float y, int width, int height) {
return x + width >= camera.position.x - camera.viewportWidth / 2 && x <= camera.position.x + camera.viewportWidth / 2 &&
y + height >= camera.position.y - camera.viewportHeight / 2 && y <= camera.position.y + camera.viewportHeight / 2;
return x + width >= othercamera.position.x - othercamera.viewportWidth / 2 && x <= othercamera.position.x + othercamera.viewportWidth / 2 &&
y + height >= othercamera.position.y - othercamera.viewportHeight / 2 && y <= othercamera.position.y + othercamera.viewportHeight / 2;
}

public void setTurnExecute() {
Expand All @@ -883,8 +883,8 @@ public BlockadeMap getMap() {

public void initializePlayerCamera(Vessel vessel) {
cameraFollowsVessel = true; // force reset
camera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - camera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - camera.position.y, 0);
camera.update();
othercamera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
othercamera.update();
}

/**
Expand Down Expand Up @@ -954,7 +954,7 @@ public boolean touchDown(int x, int y, int pointer, int button) {
if (battleMenu.touchDown(x, y, pointer, button)) {
return true;
}
if (camera != null && y < camera.viewportHeight && !battleMenu.teamTable.isVisible()) {
if (othercamera != null && y < othercamera.viewportHeight && !battleMenu.teamTable.isVisible()) {
// handle camera not following vessel
cameraFollowsVessel = false;

Expand All @@ -975,16 +975,16 @@ public boolean touchUp(int x, int y, int pointer, int button) {
if (battleMenu.touchUp(x, y, pointer,button)) {
return true;
}
if (camera != null && y < camera.viewportHeight && !battleMenu.teamTable.isVisible()) {
if (othercamera != null && y < othercamera.viewportHeight && !battleMenu.teamTable.isVisible()) {
// handle camera following/not following vessel
if (button == Input.Buttons.RIGHT) {
cameraFollowsVessel = false;
} else {
this.cameraFollowsVessel = true;
try {
Vessel vessel = context.getEntities().getVesselByName(context.myVessel);
camera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - camera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - camera.position.y, 0);
camera.update();
othercamera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
othercamera.update();
}catch(NullPointerException e){
//TO-DO -fix issue with null pointer
}
Expand All @@ -1002,14 +1002,13 @@ public boolean touchDragged(int sx, int sy, int pointer) {
return false;
}
if(!battleMenu.audio_slider.isVisible() && !battleMenu.isSettingsDialogOpen()) {
if (camera != null && sy > camera.viewportHeight) {
if (othercamera != null && sy > othercamera.viewportHeight) {
return false;
}

if (this.canDragMap) {
if (this.canDragMap && sy < Gdx.graphics.getHeight() - 200) {
float x = Gdx.input.getDeltaX(); float y = Gdx.input.getDeltaY();
camera.position.add(-x*1.3f, y*1.3f, 0);
camera.update();
othercamera.position.add(-x*1.3f, y*1.3f, 0);
othercamera.update();
}
if (battleMenu.touchDragged(sx, sy, pointer)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,9 @@ public void update() {
}

public void render(float delta) {
stage.getViewport().setCamera(camera);
stage.getViewport().apply();
stage.getBatch().setProjectionMatrix(stage.getCamera().combined);
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),false);
renderBackground();
renderMoveControl();
renderDisengage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.benberi.cadesim.game.screen.component;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
Expand Down Expand Up @@ -104,20 +103,19 @@ public boolean getIsBreak() {

public void render(float delta) {
int xPlacement = 60 + (longestTeam.length() * 6);
Gdx.gl.glViewport(0,200, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage.getBatch().setProjectionMatrix(stage.getCamera().combined);
stage.getBatch().begin();
stage.getBatch().draw(panel, 5, 5);
stage.getBatch().draw(panel, 5, 205);

// draw defender
fontTeamDefender.draw(stage.getBatch(), defender + ":", 38,120 );
fontPointsDefender.draw(stage.getBatch(), Integer.toString(defenderPoints), xPlacement,118 );
stage.getBatch().draw(areDefender?defenderUs:defenderThem, 18, 105);
fontTeamDefender.draw(stage.getBatch(), defender + ":", 38,320 );
fontPointsDefender.draw(stage.getBatch(), Integer.toString(defenderPoints), xPlacement,318 );
stage.getBatch().draw(areDefender?defenderUs:defenderThem, 18, 305);

// draw attacker
fontTeamAttacker.draw(stage.getBatch(), attacker + ":", 38,97 );
fontPointsAttacker.draw(stage.getBatch(), Integer.toString(attackerPoints), xPlacement,95 );
stage.getBatch().draw(areDefender?attackerThem:attackerUs, 18, 82);
fontTeamAttacker.draw(stage.getBatch(), attacker + ":", 38,297 );
fontPointsAttacker.draw(stage.getBatch(), Integer.toString(attackerPoints), xPlacement,295 );
stage.getBatch().draw(areDefender?attackerThem:attackerUs, 18, 282);

if (timeUntilBreak == 0 && breakTime >= 0)
{
Expand All @@ -130,15 +128,15 @@ public void render(float delta) {
":" +
(seconds < 10 ? "0" + seconds : seconds),
62,
50
350
);

// draw current break info
breakInfoFont.draw(
stage.getBatch(),
"Break",
62,
65
265
);
}
else
Expand All @@ -152,7 +150,7 @@ public void render(float delta) {
":" +
(seconds < 10 ? "0" + seconds : seconds),
62,
50
250
);

// draw next break info
Expand All @@ -167,7 +165,7 @@ public void render(float delta) {
":" +
(breakSeconds < 10 ? "0" + breakSeconds: breakSeconds),
62,
65
365
);
}
else
Expand Down
Loading

0 comments on commit 49b92fc

Please sign in to comment.