Bug 18: Refactor and separate Pixel Api and LibGDX and Open Eggbert Core

This commit is contained in:
Robert Vokac 2024-09-20 17:42:55 +02:00
parent 7d88347662
commit 4beb67a03f
No known key found for this signature in database
GPG Key ID: C459E1E4B4A986BB
20 changed files with 219 additions and 91 deletions

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
@ -30,9 +30,9 @@ import com.pixelgamelibrary.api.Platform;
import com.pixelgamelibrary.api.interfaces.App;
import com.pixelgamelibrary.api.game.Game;
import com.pixelgamelibrary.api.PixelFeature;
import com.pixelgamelibrary.api.utils.ClipBoard;
import com.pixelgamelibrary.api.utils.LogLevel;
import com.pixelgamelibrary.api.utils.Preferences;
import com.pixelgamelibrary.api.app.ClipBoard;
import com.pixelgamelibrary.api.app.LogLevel;
import com.pixelgamelibrary.api.app.Preferences;
/**
*

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
@ -49,7 +49,7 @@ public class FilesLibGDXImpl implements Files {
}
@Override
public Storage relative(String absolutePath) {
public Storage relative() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
@ -21,13 +21,12 @@ package com.pixelgamelibrary.backend.libgdx;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.pixelgamelibrary.api.DisplayMode;
import com.pixelgamelibrary.api.ViewMode;
import com.pixelgamelibrary.api.PixelException;
import com.pixelgamelibrary.api.utils.Monitor;
import java.util.Arrays;
import com.pixelgamelibrary.api.graphics.Monitor;
import com.pixelgamelibrary.backend.libgdx.graphics.LibGdxMonitor;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
//import com.pixelgamelibrary.api.interfaces.Graphics;
/**
*
@ -35,69 +34,37 @@ import java.util.stream.Collectors;
*/
public class GraphicsLibGDXImpl implements com.pixelgamelibrary.api.interfaces.Graphics {
@Override
public DisplayMode setDisplayMode(boolean fullscreen, boolean window) {
if (fullscreen) {
Graphics.Monitor currentMonitor = Gdx.graphics.getMonitor();
Graphics.DisplayMode displayModeFromLibGdx = Gdx.graphics.getDisplayMode(currentMonitor);
if (originalDisplayMode == null) {
originalDisplayMode = displayModeFromLibGdx;
}
Graphics.DisplayMode foundVgaDisplayMode = null;
////
// System.out.println("started loading all display modes");
List<Graphics.DisplayMode> vgaDisplayModes = Arrays
.asList(Gdx.graphics.getDisplayModes(currentMonitor))
.stream()
.filter(d -> d.width == 640 && d.height == 480)
.collect(Collectors.toList());
//fixme
// foundVgaDisplayMode = vgaDisplayModes.stream()
// .sorted((a, b) -> Integer.valueOf(a.refreshRate).compareTo(b.refreshRate)).findFirst().get();
// System.out.println("ended loading all display modes");
// System.out.println(foundVgaDisplayMode.refreshRate);
// System.out.println(foundVgaDisplayMode.width);
// System.out.println(foundVgaDisplayMode.height);
////
if (!Gdx.graphics.setFullscreenMode(foundVgaDisplayMode == null ? displayModeFromLibGdx : foundVgaDisplayMode)) {
Gdx.app.error("InitScreen", "Switching to fullscreen mode failed.");
return null;
}
return DisplayMode.FULLSCREEN;
}
if (window) {
setToOriginalDisplayMode();
Gdx.graphics.setWindowedMode(640, 480);
return DisplayMode.WINDOW;
}
throw new PixelException("Unsupported DisplayMode: fullscreen=" + fullscreen + " window=" + window);
}
@Override
public boolean setToOriginalDisplayMode() {
if (originalDisplayMode == null) {
//nothing to do
return true;
}
if (!Gdx.graphics.setFullscreenMode(originalDisplayMode)) {
Gdx.app.error("DefinitiveFrameworkLibGdxImpl", "Switching to original display mode failed.");
return false;
} else {
return true;
}
}
private Graphics.DisplayMode originalDisplayMode = null;
@Override
public List<Monitor> getMonitors() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
List<Monitor> result = new ArrayList<>();
for(Graphics.Monitor m:Gdx.graphics.getMonitors()) {
result.add(new LibGdxMonitor(m));
}
return result;
}
@Override
public Monitor getMonitor() {
return new LibGdxMonitor(Gdx.graphics.getMonitor());
}
@Override
public Monitor getPrimaryMonitor() {
return new LibGdxMonitor(Gdx.graphics.getPrimaryMonitor());
}
@Override
public String getTitle() {
throw new PixelException("Unsupported operation");
}
/**
*
* @param title
*/
@Override
public void setTitle(String title) {
Gdx.graphics.setTitle(title);
}
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -0,0 +1,161 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see
// <https://www.gnu.org/licenses/> or write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
///////////////////////////////////////////////////////////////////////////////////////////////
package com.pixelgamelibrary.backend.libgdx.graphics;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.pixelgamelibrary.api.PixelException;
import com.pixelgamelibrary.api.ViewMode;
import static com.pixelgamelibrary.api.ViewMode.WINDOW;
import com.pixelgamelibrary.api.graphics.Monitor;
import com.pixelgamelibrary.api.graphics.MonitorMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
*
* @author robertvokac
*/
public class LibGdxMonitor implements Monitor {
private final Graphics.Monitor internalMonitor;
public LibGdxMonitor(Graphics.Monitor internalMonitorIn) {
this.internalMonitor = internalMonitorIn;
}
@Override
public String getName() {
return internalMonitor.name;
}
@Override
public int getVirtualWidth() {
return internalMonitor.virtualX;
}
@Override
public int getVirtualHeight() {
return internalMonitor.virtualY;
}
@Override
public MonitorMode getMonitorMode() {
Graphics.DisplayMode displayModeFromLibGdx = Gdx.graphics.getDisplayMode(internalMonitor);
return toMonitorMode(displayModeFromLibGdx);
}
private MonitorMode toMonitorMode(Graphics.DisplayMode displayModeFromLibGdx) {
return new MonitorMode(
displayModeFromLibGdx.width,
displayModeFromLibGdx.height,
displayModeFromLibGdx.refreshRate,
displayModeFromLibGdx.bitsPerPixel);
}
@Override
public List<MonitorMode> listSupportedMonitorModes() {
Graphics.DisplayMode[] displayModesFromLibGdx = Gdx.graphics.getDisplayModes(internalMonitor);
List<MonitorMode> result = new ArrayList<>();
for (Graphics.DisplayMode mode : displayModesFromLibGdx) {
result.add(toMonitorMode(mode));
}
return result;
}
@Override
public boolean setMonitorMode(MonitorMode monitorMode) {
Optional<Graphics.DisplayMode> libGdxDisplayModes = Arrays
.asList(Gdx.graphics.getDisplayModes(internalMonitor))
.stream()
.filter(m
-> m.width == monitorMode.getWidth()
&& m.height == monitorMode.getHeight()
&& m.refreshRate == monitorMode.getRefreshRate()
&& m.bitsPerPixel == monitorMode.getBitsPerPixel()
)
.findFirst();
if (libGdxDisplayModes.isEmpty()) {
throw new PixelException("Unsupported MonitorMode: " + monitorMode.toString());
}
boolean success = Gdx.graphics.setFullscreenMode(libGdxDisplayModes.get());
return success;
}
@Override
public boolean setToOriginalMonitorMode() {
if (originalLibGdxDisplayMode == null) {
//nothing to do
return true;
}
if (!Gdx.graphics.setFullscreenMode(originalLibGdxDisplayMode)) {
Gdx.app.error("DefinitiveFrameworkLibGdxImpl", "Switching to original display mode failed.");
return false;
} else {
return true;
}
}
private Graphics.DisplayMode originalLibGdxDisplayMode = null;
@Override
public void setViewMode(ViewMode viewMode, int width, int height) {
if (!isMonitorInUse() && !isFullscreen()) {
return;
}
switch (viewMode) {
case WINDOW: {
if (width == 0) {
width = 640;
}
if (height == 0) {
height = 480;
}
Gdx.graphics.setWindowedMode(width, height);
}
break;
case FULLSCREEN:
Gdx.graphics.setWindowedMode(width, height);
break;
default:
throw new PixelException("Unsupported ViewMode: " + viewMode);
}
}
@Override
public ViewMode getViewMode() {
return Gdx.graphics.isFullscreen() ? ViewMode.FULLSCREEN : ViewMode.WINDOW;
}
@Override
public boolean isMonitorInUse() {
return this.internalMonitor == Gdx.graphics.getMonitor();
}
@Override
public boolean isMonitorModeChangeSupported() {
return Gdx.graphics.supportsDisplayModeChange();
}
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////////////
// Pixel: Game library.
// Pixel: LibGdx Backend.
// Copyright (C) 2024 the original author or authors.
//
// This program is free software: you can redistribute it and/or

View File

@ -28,9 +28,9 @@ import com.pixelgamelibrary.api.interfaces.Utils;
import com.pixelgamelibrary.api.interfaces.App;
import com.pixelgamelibrary.api.game.Game;
import com.pixelgamelibrary.api.PixelFeature;
import com.pixelgamelibrary.api.utils.ClipBoard;
import com.pixelgamelibrary.api.utils.LogLevel;
import com.pixelgamelibrary.api.utils.Preferences;
import com.pixelgamelibrary.api.app.ClipBoard;
import com.pixelgamelibrary.api.app.LogLevel;
import com.pixelgamelibrary.api.app.Preferences;
class DesktopAndroidStorageTest {