Update Files
This commit is contained in:
3
Kha/Backends/Java/kha/Blob.hx
Normal file
3
Kha/Backends/Java/kha/Blob.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Blob = kha.internal.BytesBlob;
|
75
Kha/Backends/Java/kha/Display.hx
Normal file
75
Kha/Backends/Java/kha/Display.hx
Normal file
@ -0,0 +1,75 @@
|
||||
package kha;
|
||||
|
||||
class Display {
|
||||
static var instance: Display = new Display();
|
||||
|
||||
function new() {}
|
||||
|
||||
public static function init(): Void {}
|
||||
|
||||
public static var primary(get, never): Display;
|
||||
|
||||
static function get_primary(): Display {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Display>;
|
||||
|
||||
static function get_all(): Array<Display> {
|
||||
return [primary];
|
||||
}
|
||||
|
||||
public var available(get, never): Bool;
|
||||
|
||||
function get_available(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public var name(get, never): String;
|
||||
|
||||
function get_name(): String {
|
||||
return "Display";
|
||||
}
|
||||
|
||||
public var x(get, never): Int;
|
||||
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, never): Int;
|
||||
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return 1920;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return 1080;
|
||||
}
|
||||
|
||||
public var frequency(get, never): Int;
|
||||
|
||||
function get_frequency(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public var pixelsPerInch(get, never): Int;
|
||||
|
||||
function get_pixelsPerInch(): Int {
|
||||
return 96;
|
||||
}
|
||||
|
||||
public var modes(get, never): Array<DisplayMode>;
|
||||
|
||||
function get_modes(): Array<DisplayMode> {
|
||||
return [];
|
||||
}
|
||||
}
|
3
Kha/Backends/Java/kha/Font.hx
Normal file
3
Kha/Backends/Java/kha/Font.hx
Normal file
@ -0,0 +1,3 @@
|
||||
package kha;
|
||||
|
||||
typedef Font = kha.java.Font;
|
162
Kha/Backends/Java/kha/Image.hx
Normal file
162
Kha/Backends/Java/kha/Image.hx
Normal file
@ -0,0 +1,162 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.graphics4.TextureFormat;
|
||||
import kha.graphics4.Usage;
|
||||
import kha.java.Painter;
|
||||
|
||||
@:classCode('
|
||||
public java.awt.image.BufferedImage image;
|
||||
')
|
||||
class Image implements Canvas implements Resource {
|
||||
var painter: Painter;
|
||||
var graphics1: kha.graphics1.Graphics;
|
||||
|
||||
public function new(filename: String) {}
|
||||
|
||||
@:functionCode('
|
||||
image.image = new java.awt.image.BufferedImage(width, height, format == 0 ? 10 : 6);
|
||||
')
|
||||
static function create2(image: Image, width: Int, height: Int, format: Int): Void {}
|
||||
|
||||
public static function create(width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
|
||||
var img = new Image(null);
|
||||
create2(img, width, height, format == TextureFormat.L8 ? 0 : 1);
|
||||
return img;
|
||||
}
|
||||
|
||||
public static function create3D(width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function createRenderTarget(width: Int, height: Int, format: TextureFormat = null, depthStencil: Bool = false,
|
||||
antiAliasingSamples: Int = 1): Image {
|
||||
var img = new Image(null);
|
||||
create2(img, width, height, format == TextureFormat.L8 ? 0 : 1);
|
||||
return img;
|
||||
}
|
||||
|
||||
public static function fromBytes(bytes: Bytes, width: Int, height: Int, format: TextureFormat = null, usage: Usage = null): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function fromBytes3D(bytes: Bytes, width: Int, height: Int, depth: Int, format: TextureFormat = null, usage: Usage = null): Image {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g1(get, never): kha.graphics1.Graphics;
|
||||
|
||||
function get_g1(): kha.graphics1.Graphics {
|
||||
if (graphics1 == null) {
|
||||
graphics1 = new kha.graphics2.Graphics1(this);
|
||||
}
|
||||
return graphics1;
|
||||
}
|
||||
|
||||
public var g2(get, never): kha.graphics2.Graphics;
|
||||
|
||||
@:functionCode('
|
||||
painter.graphics = image.createGraphics();
|
||||
')
|
||||
function initPainter(painter: Painter): Void {}
|
||||
|
||||
function get_g2(): kha.graphics2.Graphics {
|
||||
if (painter == null) {
|
||||
painter = new Painter();
|
||||
initPainter(painter);
|
||||
}
|
||||
return painter;
|
||||
}
|
||||
|
||||
public var g4(get, never): kha.graphics4.Graphics;
|
||||
|
||||
function get_g4(): kha.graphics4.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
@:functionCode('
|
||||
return image.getWidth(null);
|
||||
')
|
||||
function get_width(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
@:functionCode('
|
||||
return image.getHeight(null);
|
||||
')
|
||||
function get_height(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var depth(get, never): Int;
|
||||
|
||||
function get_depth(): Int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public var format(get, never): TextureFormat;
|
||||
|
||||
@:functionCode('
|
||||
return image.getType();
|
||||
')
|
||||
function get_format(): TextureFormat {
|
||||
return TextureFormat.RGBA32;
|
||||
}
|
||||
|
||||
public var realWidth(get, never): Int;
|
||||
|
||||
function get_realWidth(): Int {
|
||||
return width;
|
||||
}
|
||||
|
||||
public var realHeight(get, never): Int;
|
||||
|
||||
function get_realHeight(): Int {
|
||||
return height;
|
||||
}
|
||||
|
||||
public var stride(get, never): Int;
|
||||
|
||||
function get_stride(): Int {
|
||||
return realWidth * 4;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
if (x >= 0 && x < get_width() && y >= 0 && y < get_height()) {
|
||||
int argb = image.getRGB(x, y);
|
||||
return argb >> 24 != 0;
|
||||
}
|
||||
else return false;
|
||||
')
|
||||
public function isOpaque(x: Int, y: Int): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function at(x: Int, y: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function unload(): Void {}
|
||||
|
||||
public function lock(level: Int = 0): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(): Void {}
|
||||
|
||||
public function getPixels(): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateMipmaps(levels: Int): Void {}
|
||||
|
||||
public function setMipmaps(mipmaps: Array<Image>): Void {}
|
||||
|
||||
public function setDepthStencilFrom(image: Image): Void {}
|
||||
|
||||
public function clear(x: Int, y: Int, z: Int, width: Int, height: Int, depth: Int, color: Color): Void {}
|
||||
}
|
122
Kha/Backends/Java/kha/LoaderImpl.hx
Normal file
122
Kha/Backends/Java/kha/LoaderImpl.hx
Normal file
@ -0,0 +1,122 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import kha.Blob;
|
||||
import kha.FontStyle;
|
||||
import java.lang.Byte;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
class LoaderImpl {
|
||||
@:functionCode('
|
||||
String everything = "";
|
||||
try {
|
||||
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader(filename));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
||||
while (line != null) {
|
||||
sb.append(line);
|
||||
sb.append("\\n");
|
||||
line = br.readLine();
|
||||
}
|
||||
everything = sb.toString();
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
catch (java.io.IOException ex) {
|
||||
|
||||
}
|
||||
return everything;
|
||||
')
|
||||
static function loadText(filename: String): String {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static function loadSoundFromDescription(desc: Dynamic, done: kha.Sound->Void, ?failed: AssetError->Void): Void {
|
||||
done(new kha.java.Sound(desc.files[0]));
|
||||
}
|
||||
|
||||
public static function getSoundFormats(): Array<String> {
|
||||
return ["wav"];
|
||||
}
|
||||
|
||||
public static function loadImageFromDescription(desc: Dynamic, done: Image->Void, ?failed: AssetError->Void): Void {
|
||||
var image = new kha.Image(desc.files[0]);
|
||||
loadRealImage(desc.files[0], image);
|
||||
done(image);
|
||||
}
|
||||
|
||||
public static function getImageFormats(): Array<String> {
|
||||
return ["png", "jpg"];
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
try {
|
||||
// getClass().getResource(filename)
|
||||
image.image = javax.imageio.ImageIO.read(new java.io.File("../" + filename));
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
')
|
||||
static function loadRealImage(filename: String, image: Image) {}
|
||||
|
||||
public static function loadBlobFromDescription(desc: Dynamic, done: Blob->Void, ?failed: AssetError->Void): Void {
|
||||
loadRealBlob(desc.files[0], done);
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// java.util.List<Byte> bytes = new java.util.ArrayList<Byte>();
|
||||
// try {
|
||||
// java.io.InputStream in = new java.io.BufferedInputStream(new java.io.FileInputStream(filename));
|
||||
// for (int c; (c = in.read()) != -1;) {
|
||||
// bytes.add((byte)c);
|
||||
// }
|
||||
// in.close();
|
||||
// }
|
||||
// catch (java.io.IOException ex) {
|
||||
// }
|
||||
// byte[] realbytes = new byte[bytes.size()];
|
||||
// for (int i = 0; i < bytes.size(); ++i) realbytes[i] = bytes.get(i);
|
||||
// done.__hx_invoke1_o(0.0, new kha.Blob(new haxe.io.Bytes(bytes.size(), realbytes)));
|
||||
// ')
|
||||
static function loadRealBlob(filename: String, done: Blob->Void, ?failed: AssetError->Void) {
|
||||
var bytes: List<Byte> = new ArrayList<Byte>();
|
||||
try {
|
||||
var input: InputStream = new BufferedInputStream(new FileInputStream("../" + filename));
|
||||
while (true) {
|
||||
var c = input.read();
|
||||
if (c == -1)
|
||||
break;
|
||||
bytes.add(c);
|
||||
}
|
||||
input.close();
|
||||
}
|
||||
catch (ex:IOException) {}
|
||||
var realBytes = Bytes.alloc(bytes.size());
|
||||
for (i in 0...bytes.size())
|
||||
realBytes.set(i, cast bytes.get(i).toByte());
|
||||
done(Blob.fromBytes(realBytes));
|
||||
}
|
||||
|
||||
/*override public function loadFont(desc: Dynamic, style: FontStyle, size: Float): kha.Font {
|
||||
return new Font(name, style, size);
|
||||
}*/
|
||||
public static function loadFontFromDescription(desc: Dynamic, done: Font->Void, ?failed: AssetError->Void): Void {
|
||||
done(new kha.java.Font("Arial", new FontStyle(false, false, false), 12));
|
||||
}
|
||||
|
||||
public static function loadVideoFromDescription(desc: Dynamic, done: Video->Void, ?failed: AssetError->Void): Void {
|
||||
done(null);
|
||||
}
|
||||
|
||||
public static function getVideoFormats(): Array<String> {
|
||||
return [];
|
||||
}
|
||||
}
|
55
Kha/Backends/Java/kha/Storage.hx
Normal file
55
Kha/Backends/Java/kha/Storage.hx
Normal file
@ -0,0 +1,55 @@
|
||||
package kha;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.Path;
|
||||
import haxe.Serializer;
|
||||
import haxe.Unserializer;
|
||||
import kha.Blob;
|
||||
import kha.StorageFile;
|
||||
import sys.io.File;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class JavaStorageFile extends StorageFile {
|
||||
var file: Path;
|
||||
|
||||
public function new(filename: String) {
|
||||
this.file = new Path(filename);
|
||||
// if (file.dir != null) Directory.CreateDirectory(file.dir);
|
||||
}
|
||||
|
||||
override public function read(): Blob {
|
||||
try {
|
||||
if (file == null)
|
||||
return null;
|
||||
if (File.getContent(file.toString()) == null)
|
||||
return null;
|
||||
return Blob.fromBytes(File.getBytes(file.toString()));
|
||||
}
|
||||
catch (e:Dynamic) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
override public function write(data: Blob): Void {
|
||||
var file = File.write(file.toString(), true);
|
||||
file.writeBytes(data.toBytes(), 0, data.toBytes().length);
|
||||
}
|
||||
}
|
||||
|
||||
class Storage {
|
||||
public static function namedFile(name: String): StorageFile {
|
||||
name = name.replace("<", "-(");
|
||||
name = name.replace(">", ")-");
|
||||
name = name.replace(":", "_");
|
||||
name = name.replace("|", ")(");
|
||||
name = name.replace("?", "(Q)");
|
||||
name = name.replace("*", "(+)");
|
||||
name = name.replace("\"", "''");
|
||||
return new JavaStorageFile(name);
|
||||
}
|
||||
|
||||
public static function defaultFile(): StorageFile {
|
||||
return namedFile("default.kha");
|
||||
}
|
||||
}
|
467
Kha/Backends/Java/kha/SystemImpl.hx
Normal file
467
Kha/Backends/Java/kha/SystemImpl.hx
Normal file
@ -0,0 +1,467 @@
|
||||
package kha;
|
||||
|
||||
import kha.System.SystemOptions;
|
||||
import kha.input.Keyboard;
|
||||
import kha.input.KeyCode;
|
||||
import kha.input.Mouse;
|
||||
import kha.java.Graphics;
|
||||
import kha.System;
|
||||
import kha.Window;
|
||||
import java.javax.swing.JFrame;
|
||||
import java.lang.Class;
|
||||
import java.lang.System in Sys;
|
||||
import java.lang.Object;
|
||||
import java.lang.Throwable;
|
||||
import java.NativeArray;
|
||||
|
||||
@:access(kha.System)
|
||||
class JWindow extends JFrame implements java.awt.event.KeyListener implements java.awt.event.MouseListener implements java.awt.event.MouseMotionListener
|
||||
implements java.awt.event.MouseWheelListener {
|
||||
public var instance: JWindow;
|
||||
|
||||
var WIDTH: Int;
|
||||
var HEIGHT: Int;
|
||||
var syncrate = 60;
|
||||
var canvas: java.awt.Canvas;
|
||||
var vsynced = false;
|
||||
var reset = false;
|
||||
var framebuffer: kha.Framebuffer;
|
||||
var painter: kha.java.Painter;
|
||||
|
||||
public static var mouseX: Int;
|
||||
public static var mouseY: Int;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
instance = this;
|
||||
painter = new kha.java.Painter();
|
||||
framebuffer = new kha.Framebuffer(0, null, painter, null);
|
||||
var g1 = new kha.graphics2.Graphics1(framebuffer);
|
||||
framebuffer.init(g1, painter, null);
|
||||
}
|
||||
|
||||
public function start(): Void {
|
||||
createGame();
|
||||
setupWindow();
|
||||
createVSyncedDoubleBuffer();
|
||||
mainLoop();
|
||||
}
|
||||
|
||||
function setupWindow(): Void {
|
||||
setIgnoreRepaint(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
canvas = new java.awt.Canvas();
|
||||
canvas.setIgnoreRepaint(true);
|
||||
canvas.setSize(WIDTH, HEIGHT);
|
||||
canvas.setFocusable(false);
|
||||
add(canvas);
|
||||
setResizable(false);
|
||||
pack();
|
||||
var screen: java.awt.Dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
|
||||
var x = Std.int((screen.width - WIDTH) / 2);
|
||||
var y = Std.int((screen.height - HEIGHT) / 2);
|
||||
setLocation(x, y);
|
||||
setTitle("Game");
|
||||
setVisible(true);
|
||||
addKeyListener(this);
|
||||
canvas.addMouseListener(this);
|
||||
canvas.addMouseMotionListener(this);
|
||||
canvas.addMouseWheelListener(this);
|
||||
}
|
||||
|
||||
function createVSyncedDoubleBuffer(): Void {
|
||||
vsynced = true;
|
||||
canvas.createBufferStrategy(2);
|
||||
var bufferStrategy: java.awt.image.BufferStrategy = canvas.getBufferStrategy();
|
||||
if (bufferStrategy != null) {
|
||||
var caps: java.awt.BufferCapabilities = bufferStrategy.getCapabilities();
|
||||
try {
|
||||
// Class<?>
|
||||
var ebcClass = Class.forName("sun.java2d.pipe.hw.ExtendedBufferCapabilities");
|
||||
var vstClass = Class.forName("sun.java2d.pipe.hw.ExtendedBufferCapabilities$VSyncType");
|
||||
// java.lang.reflect.Constructor<?>
|
||||
// new Class[] { java.awt.BufferCapabilities.class, vstClass }
|
||||
untyped var _class = untyped __java__("java.awt.BufferCapabilities.class");
|
||||
var classes: NativeArray<Class<Dynamic>> = NativeArray.make(_class, vstClass);
|
||||
var ebcConstructor = ebcClass.getConstructor(classes[0]);
|
||||
var vSyncType: Object = vstClass.getField("VSYNC_ON").get(null);
|
||||
// (java.awt.BufferCapabilities)
|
||||
// new Object[]
|
||||
var objs: NativeArray<Object> = NativeArray.make(cast(caps, Object), vSyncType);
|
||||
var newCaps: java.awt.BufferCapabilities = ebcConstructor.newInstance(objs);
|
||||
canvas.createBufferStrategy(2, newCaps);
|
||||
// setCanChangeRefreshRate(false);
|
||||
// setRefreshRate(60);
|
||||
}
|
||||
catch (t:Throwable) {
|
||||
vsynced = false;
|
||||
t.printStackTrace();
|
||||
canvas.createBufferStrategy(2);
|
||||
}
|
||||
}
|
||||
if (vsynced)
|
||||
checkVSync();
|
||||
}
|
||||
|
||||
function checkVSync(): Void {
|
||||
var starttime = Sys.nanoTime();
|
||||
for (i in 0...3) {
|
||||
canvas.getBufferStrategy().show();
|
||||
java.awt.Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
var endtime = Sys.nanoTime();
|
||||
if (endtime - starttime > 1000 * 1000 * 1000 / 60) {
|
||||
vsynced = true;
|
||||
Sys.out.println("VSync enabled.");
|
||||
}
|
||||
else
|
||||
Sys.out.println("VSync not enabled, sorry.");
|
||||
}
|
||||
|
||||
function mainLoop(): Void {
|
||||
var lasttime = Sys.nanoTime();
|
||||
while (true) {
|
||||
if (vsynced)
|
||||
update();
|
||||
else {
|
||||
var time = Sys.nanoTime();
|
||||
while (time >= lasttime + 1000 * 1000 * 1000 / syncrate) {
|
||||
lasttime += 1000 * 1000 * 1000 / syncrate;
|
||||
update();
|
||||
}
|
||||
}
|
||||
render();
|
||||
if (reset)
|
||||
resetGame();
|
||||
}
|
||||
}
|
||||
|
||||
function createGame(): Void {
|
||||
WIDTH = System.windowWidth();
|
||||
HEIGHT = System.windowHeight();
|
||||
}
|
||||
|
||||
function resetGame(): Void {
|
||||
reset = false;
|
||||
createGame();
|
||||
}
|
||||
|
||||
@:overload
|
||||
function update(): Void {
|
||||
Scheduler.executeFrame();
|
||||
}
|
||||
|
||||
function render(): Void {
|
||||
var bf: java.awt.image.BufferStrategy = canvas.getBufferStrategy();
|
||||
var g: java.awt.Graphics2D = null;
|
||||
try {
|
||||
g = cast bf.getDrawGraphics();
|
||||
painter.graphics = g;
|
||||
painter.setRenderHint();
|
||||
System.render([framebuffer]);
|
||||
}
|
||||
catch (e:Any) {
|
||||
trace(e);
|
||||
}
|
||||
g.dispose();
|
||||
bf.show();
|
||||
java.awt.Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public function keyPressed(e: java.awt.event.KeyEvent): Void {
|
||||
// var keyCode: Int = e.getKeyCode();
|
||||
// switch (keyCode) {
|
||||
// case java.awt.event.KeyEvent.VK_RIGHT:
|
||||
// pressKey(keyCode, KeyCode.RIGHT);
|
||||
// case java.awt.event.KeyEvent.VK_LEFT:
|
||||
// pressKey(keyCode, KeyCode.LEFT);
|
||||
// case java.awt.event.KeyEvent.VK_UP:
|
||||
// pressKey(keyCode, KeyCode.UP);
|
||||
// case java.awt.event.KeyEvent.VK_DOWN:
|
||||
// pressKey(keyCode, KeyCode.DOWN);
|
||||
// case java.awt.event.KeyEvent.VK_SPACE:
|
||||
// pressKey(keyCode, KeyCode.BUTTON_1);
|
||||
// case java.awt.event.KeyEvent.VK_CONTROL:
|
||||
// pressKey(keyCode, KeyCode.BUTTON_2);
|
||||
// case java.awt.event.KeyEvent.VK_ENTER:
|
||||
// //pressKey(keyCode, Key.ENTER);
|
||||
// case java.awt.event.KeyEvent.VK_BACK_SPACE:
|
||||
// //pressKey(keyCode, Key.BACKSPACE);
|
||||
// default:
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public function keyReleased(e: java.awt.event.KeyEvent): Void {
|
||||
// var keyCode: Int = e.getKeyCode();
|
||||
// switch (keyCode) {
|
||||
// case java.awt.event.KeyEvent.VK_RIGHT:
|
||||
// releaseKey(keyCode, KeyCode.RIGHT);
|
||||
// case java.awt.event.KeyEvent.VK_LEFT:
|
||||
// releaseKey(keyCode, KeyCode.LEFT);
|
||||
// case java.awt.event.KeyEvent.VK_UP:
|
||||
// releaseKey(keyCode, KeyCode.UP);
|
||||
// case java.awt.event.KeyEvent.VK_DOWN:
|
||||
// releaseKey(keyCode, KeyCode.DOWN);
|
||||
// case java.awt.event.KeyEvent.VK_SPACE:
|
||||
// releaseKey(keyCode, KeyCode.BUTTON_1);
|
||||
// case java.awt.event.KeyEvent.VK_CONTROL:
|
||||
// releaseKey(keyCode, KeyCode.BUTTON_2);
|
||||
// case java.awt.event.KeyEvent.VK_ENTER:
|
||||
// //releaseKey(keyCode, Key.ENTER);
|
||||
// case java.awt.event.KeyEvent.VK_BACK_SPACE:
|
||||
// //releaseKey(keyCode, Key.BACKSPACE);
|
||||
// default:
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public function keyTyped(e: java.awt.event.KeyEvent): Void {
|
||||
// game.charKey(e.getKeyChar());
|
||||
}
|
||||
|
||||
public function getSyncrate(): Int {
|
||||
return syncrate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public function mouseClicked(arg0: java.awt.event.MouseEvent): Void {}
|
||||
|
||||
@Override
|
||||
public function mouseEntered(arg0: java.awt.event.MouseEvent): Void {}
|
||||
|
||||
@Override
|
||||
public function mouseExited(arg0: java.awt.event.MouseEvent): Void {}
|
||||
|
||||
@Override
|
||||
public function mousePressed(arg0: java.awt.event.MouseEvent): Void {
|
||||
mouseX = arg0.getX();
|
||||
mouseY = arg0.getY();
|
||||
|
||||
// if (javax.swing.SwingUtilities.isLeftMouseButton(arg0))
|
||||
// game.mouseDown(arg0.getX(), arg0.getY());
|
||||
// else if (javax.swing.SwingUtilities.isRightMouseButton(arg0))
|
||||
// game.rightMouseDown(arg0.getX(), arg0.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public function mouseReleased(arg0: java.awt.event.MouseEvent): Void {
|
||||
mouseX = arg0.getX();
|
||||
mouseY = arg0.getY();
|
||||
|
||||
// if (javax.swing.SwingUtilities.isLeftMouseButton(arg0))
|
||||
// game.mouseUp(arg0.getX(), arg0.getY());
|
||||
// else if (javax.swing.SwingUtilities.isRightMouseButton(arg0))
|
||||
// game.rightMouseUp(arg0.getX(), arg0.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public function mouseDragged(arg0: java.awt.event.MouseEvent): Void {
|
||||
mouseX = arg0.getX();
|
||||
mouseY = arg0.getY();
|
||||
// game.mouseMove(arg0.getPoint().x, arg0.getPoint().y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public function mouseMoved(arg0: java.awt.event.MouseEvent): Void {
|
||||
mouseX = arg0.getX();
|
||||
mouseY = arg0.getY();
|
||||
// if (game != null) game.mouseMove(arg0.getPoint().x, arg0.getPoint().y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public function mouseWheelMoved(arg0: java.awt.event.MouseWheelEvent): Void {
|
||||
mouseX = arg0.getX();
|
||||
mouseY = arg0.getY();
|
||||
|
||||
// game.mouseWheel(-arg0.getWheelRotation()); //invert
|
||||
}
|
||||
}
|
||||
|
||||
@:allow(kha.SystemImpl.JWindow)
|
||||
class SystemImpl {
|
||||
public static var graphics(default, null): Graphics;
|
||||
static var keyboard: Keyboard;
|
||||
static var mouse: Mouse;
|
||||
static var keyreleased: Array<Bool>;
|
||||
|
||||
public static function init(options: SystemOptions, callback: Window->Void) {
|
||||
init2();
|
||||
Scheduler.init();
|
||||
if (options.width != -1)
|
||||
myPixelWidth = options.width;
|
||||
if (options.height != -1)
|
||||
myPixelHeight = options.height;
|
||||
|
||||
var window = new Window(options.width, options.height);
|
||||
Scheduler.start();
|
||||
callback(window);
|
||||
var jWindow = new JWindow();
|
||||
jWindow.start();
|
||||
}
|
||||
|
||||
public static function initEx(title: String, options: Array<WindowOptions>, windowCallback: Int->Void, callback: Window->Void) {
|
||||
init({title: title, width: options[0].width, height: options[0].height}, callback);
|
||||
}
|
||||
|
||||
static var startTime: Float;
|
||||
|
||||
public static function init2(): Void {
|
||||
graphics = new Graphics();
|
||||
startTime = getTimestamp();
|
||||
mouse = new Mouse();
|
||||
keyboard = new Keyboard();
|
||||
keyreleased = [for (i in 0...256) true];
|
||||
}
|
||||
|
||||
public static function getKeyboard(num: Int): Keyboard {
|
||||
if (num == 0)
|
||||
return keyboard;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getMouse(num: Int): Mouse {
|
||||
if (num == 0)
|
||||
return mouse;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
function pressKey(keyCode: Int, button: KeyCode): Void {
|
||||
if (keyreleased[keyCode]) { // avoid auto-repeat
|
||||
keyreleased[keyCode] = false;
|
||||
keyboard.sendDownEvent(button);
|
||||
}
|
||||
}
|
||||
|
||||
function releaseKey(keyCode: Int, button: KeyCode): Void {
|
||||
keyreleased[keyCode] = true;
|
||||
keyboard.sendUpEvent(button);
|
||||
}
|
||||
|
||||
public static function getFrequency(): Int {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public static function getTimestamp(): Float {
|
||||
return cast java.lang.System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static function getTime(): Float {
|
||||
return (getTimestamp() - startTime) / getFrequency();
|
||||
}
|
||||
|
||||
public static function getScreenRotation(): ScreenRotation {
|
||||
return ScreenRotation.RotationNone;
|
||||
}
|
||||
|
||||
public static function getVsync(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getRefreshRate(): Int {
|
||||
return 60;
|
||||
}
|
||||
|
||||
public static function getSystemId(): String {
|
||||
return "java";
|
||||
}
|
||||
|
||||
public static function vibrate(ms: Int): Void {}
|
||||
|
||||
public static function getLanguage(): String {
|
||||
final lang = java.util.Locale.getDefault().getLanguage();
|
||||
return lang.substr(0, 2).toLowerCase();
|
||||
}
|
||||
|
||||
static var myPixelWidth = 640;
|
||||
static var myPixelHeight = 480;
|
||||
|
||||
public static function windowWidth(id: Int): Int {
|
||||
return myPixelWidth;
|
||||
}
|
||||
|
||||
public static function windowHeight(id: Int): Int {
|
||||
return myPixelHeight;
|
||||
}
|
||||
|
||||
public static function screenDpi(): Int {
|
||||
return 96;
|
||||
}
|
||||
|
||||
public static function changeResolution(width: Int, height: Int): Void {}
|
||||
|
||||
public static function requestShutdown(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canSwitchFullscreen(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isFullscreen(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function requestFullscreen(): Void {}
|
||||
|
||||
public static function exitFullscreen(): Void {}
|
||||
|
||||
public static function notifyOfFullscreenChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public static function removeFromFullscreenChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public function lockMouse(): Void {}
|
||||
|
||||
public function unlockMouse(): Void {}
|
||||
|
||||
public function canLockMouse(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isMouseLocked(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function notifyOfMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public function removeFromMouseLockChange(func: Void->Void, error: Void->Void): Void {}
|
||||
|
||||
public static function setKeepScreenOn(on: Bool): Void {}
|
||||
|
||||
public static function loadUrl(url: String): Void {}
|
||||
|
||||
public static function safeZone(): Float {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public static function waitingForLogin(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function disallowUserChange(): Void {}
|
||||
|
||||
public static function allowUserChange(): Void {}
|
||||
|
||||
public static function login(): Void {}
|
||||
|
||||
public static function automaticSafeZone(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function setSafeZone(value: Float): Void {}
|
||||
|
||||
public static function unlockAchievement(id: Int): Void {}
|
||||
|
||||
public static function getGamepadId(index: Int): String {
|
||||
return "unkown";
|
||||
}
|
||||
|
||||
public static function getGamepadVendor(index: Int): String {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public static function setGamepadRumble(index: Int, leftAmount: Float, rightAmount: Float) {}
|
||||
}
|
134
Kha/Backends/Java/kha/Window.hx
Normal file
134
Kha/Backends/Java/kha/Window.hx
Normal file
@ -0,0 +1,134 @@
|
||||
package kha;
|
||||
|
||||
class Window {
|
||||
static var windows: Array<Window> = [];
|
||||
|
||||
var defaultWidth: Int;
|
||||
var defaultHeight: Int;
|
||||
|
||||
@:noCompletion
|
||||
@:noDoc
|
||||
public function new(defaultWidth: Int, defaultHeight: Int) {
|
||||
windows.push(this);
|
||||
}
|
||||
|
||||
public static function create(win: WindowOptions = null, frame: FramebufferOptions = null): Window {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function destroy(window: Window): Void {}
|
||||
|
||||
public static function get(index: Int): Window {
|
||||
return windows[index];
|
||||
}
|
||||
|
||||
public static var all(get, never): Array<Window>;
|
||||
|
||||
static function get_all(): Array<Window> {
|
||||
return windows;
|
||||
}
|
||||
|
||||
public function resize(width: Int, height: Int): Void {}
|
||||
|
||||
public function move(x: Int, y: Int): Void {}
|
||||
|
||||
public function changeWindowFeatures(features: Int): Void {}
|
||||
|
||||
public function changeFramebuffer(frame: FramebufferOptions): Void {}
|
||||
|
||||
public var x(get, set): Int;
|
||||
|
||||
function get_x(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_x(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var y(get, set): Int;
|
||||
|
||||
function get_y(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_y(value: Int): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var width(get, set): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
function set_width(value: Int): Int {
|
||||
return 800;
|
||||
}
|
||||
|
||||
public var height(get, set): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
function set_height(value: Int): Int {
|
||||
return 600;
|
||||
}
|
||||
|
||||
public var mode(get, set): WindowMode;
|
||||
|
||||
function get_mode(): WindowMode {
|
||||
return Windowed;
|
||||
}
|
||||
|
||||
function set_mode(mode: WindowMode): WindowMode {
|
||||
if (mode == Fullscreen || mode == ExclusiveFullscreen) {
|
||||
if (!isFullscreen()) {
|
||||
requestFullscreen();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isFullscreen()) {
|
||||
exitFullscreen();
|
||||
}
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
function isFullscreen(): Bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
function requestFullscreen(): Void {}
|
||||
|
||||
function exitFullscreen(): Void {}
|
||||
|
||||
public var visible(get, set): Bool;
|
||||
|
||||
function get_visible(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
function set_visible(value: Bool): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public var title(get, set): String;
|
||||
|
||||
function get_title(): String {
|
||||
return "Kha";
|
||||
}
|
||||
|
||||
function set_title(value: String): String {
|
||||
return "Kha";
|
||||
}
|
||||
|
||||
public function notifyOnResize(callback: Int->Int->Void): Void {}
|
||||
|
||||
public var vSynced(get, never): Bool;
|
||||
|
||||
function get_vSynced(): Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
30
Kha/Backends/Java/kha/arrays/Float32Array.hx
Normal file
30
Kha/Backends/Java/kha/arrays/Float32Array.hx
Normal file
@ -0,0 +1,30 @@
|
||||
package kha.arrays;
|
||||
|
||||
import java.NativeArray;
|
||||
|
||||
abstract Float32Array(NativeArray<Float>) {
|
||||
public inline function new(elements: Int) {
|
||||
this = new NativeArray<Float>(elements);
|
||||
}
|
||||
|
||||
public var length(get, never): Int;
|
||||
|
||||
inline function get_length(): Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public function set(index: Int, value: FastFloat): FastFloat {
|
||||
this[index] = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public inline function get(index: Int): FastFloat {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
public inline function data(): NativeArray<Float> {
|
||||
return this;
|
||||
}
|
||||
}
|
41
Kha/Backends/Java/kha/arrays/Int16Array.hx
Normal file
41
Kha/Backends/Java/kha/arrays/Int16Array.hx
Normal file
@ -0,0 +1,41 @@
|
||||
package kha.arrays;
|
||||
|
||||
import java.NativeArray;
|
||||
|
||||
abstract Int16Array(NativeArray<java.Int16>) {
|
||||
public inline function new(elements: Int) {
|
||||
this = new NativeArray<java.Int16>(elements);
|
||||
}
|
||||
|
||||
public var length(get, never): Int;
|
||||
|
||||
inline function get_length(): Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public inline function set(index: Int, value: Int): Int {
|
||||
return this[index] = value;
|
||||
}
|
||||
|
||||
public inline function get(index: Int): Int {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
public inline function data(): NativeArray<java.Int16> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public inline function arrayRead(index: Int): Int {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public inline function arrayWrite(index: Int, value: Int): Int {
|
||||
return this[index] = value;
|
||||
}
|
||||
|
||||
// public inline function subarray(start: Int, ?end: Int): Int16Array {
|
||||
// return cast this.subarray(start, end);
|
||||
// }
|
||||
}
|
41
Kha/Backends/Java/kha/arrays/Int32Array.hx
Normal file
41
Kha/Backends/Java/kha/arrays/Int32Array.hx
Normal file
@ -0,0 +1,41 @@
|
||||
package kha.arrays;
|
||||
|
||||
import java.NativeArray;
|
||||
|
||||
abstract Int32Array(NativeArray<Int>) {
|
||||
public inline function new(elements: Int) {
|
||||
this = new NativeArray<Int>(elements);
|
||||
}
|
||||
|
||||
public var length(get, never): Int;
|
||||
|
||||
inline function get_length(): Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public inline function set(index: Int, value: Int): Int {
|
||||
return this[index] = value;
|
||||
}
|
||||
|
||||
public inline function get(index: Int): Int {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
public inline function data(): NativeArray<Int> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public inline function arrayRead(index: Int): Int {
|
||||
return this[index];
|
||||
}
|
||||
|
||||
@:arrayAccess
|
||||
public inline function arrayWrite(index: Int, value: Int): Int {
|
||||
return this[index] = value;
|
||||
}
|
||||
|
||||
// public inline function subarray(start: Int, ?end: Int): Int16Array {
|
||||
// return cast this.subarray(start, end);
|
||||
// }
|
||||
}
|
13
Kha/Backends/Java/kha/audio1/Audio.hx
Normal file
13
Kha/Backends/Java/kha/audio1/Audio.hx
Normal file
@ -0,0 +1,13 @@
|
||||
package kha.audio1;
|
||||
|
||||
import kha.Sound;
|
||||
|
||||
class Audio {
|
||||
public static function play(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
return new JavaSoundChannel(cast(sound, kha.java.Sound));
|
||||
}
|
||||
|
||||
public static function stream(sound: Sound, loop: Bool = false): kha.audio1.AudioChannel {
|
||||
return new JavaMusicChannel(cast(sound, kha.java.Music), loop);
|
||||
}
|
||||
}
|
55
Kha/Backends/Java/kha/audio1/JavaMusicChannel.hx
Normal file
55
Kha/Backends/Java/kha/audio1/JavaMusicChannel.hx
Normal file
@ -0,0 +1,55 @@
|
||||
package kha.audio1;
|
||||
|
||||
class JavaMusicChannel implements kha.audio1.AudioChannel {
|
||||
var music: kha.java.Music;
|
||||
var loop: Bool;
|
||||
|
||||
public function new(music: kha.java.Music, loop: Bool) {
|
||||
this.music = music;
|
||||
play();
|
||||
}
|
||||
|
||||
public function play(): Void {
|
||||
music.play(loop);
|
||||
}
|
||||
|
||||
public function pause(): Void {
|
||||
music.stop();
|
||||
}
|
||||
|
||||
public function stop(): Void {
|
||||
music.stop();
|
||||
}
|
||||
|
||||
public var length(get, never): Int;
|
||||
|
||||
function get_length(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var position(get, set): Float;
|
||||
|
||||
function get_position(): Float {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
function set_position(value: Float): Float {
|
||||
return value;
|
||||
}
|
||||
|
||||
public var volume(get, set): Float;
|
||||
|
||||
function get_volume(): Float {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function set_volume(value: Float): Float {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public var finished(get, never): Bool;
|
||||
|
||||
function get_finished(): Bool {
|
||||
return false;
|
||||
}
|
||||
}
|
54
Kha/Backends/Java/kha/audio1/JavaSoundChannel.hx
Normal file
54
Kha/Backends/Java/kha/audio1/JavaSoundChannel.hx
Normal file
@ -0,0 +1,54 @@
|
||||
package kha.audio1;
|
||||
|
||||
class JavaSoundChannel implements kha.audio1.AudioChannel {
|
||||
var sound: kha.java.Sound;
|
||||
|
||||
public function new(sound: kha.java.Sound) {
|
||||
this.sound = sound;
|
||||
play();
|
||||
}
|
||||
|
||||
public function play(): Void {
|
||||
sound.play();
|
||||
}
|
||||
|
||||
public function pause(): Void {
|
||||
sound.stop();
|
||||
}
|
||||
|
||||
public function stop(): Void {
|
||||
sound.stop();
|
||||
}
|
||||
|
||||
public var length(get, never): Float;
|
||||
|
||||
function get_length(): Float {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var position(get, set): Float;
|
||||
|
||||
function get_position(): Float {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
function set_position(value: Float): Float {
|
||||
return value;
|
||||
}
|
||||
|
||||
public var volume(get, set): Float;
|
||||
|
||||
function get_volume(): Float {
|
||||
return 1;
|
||||
}
|
||||
|
||||
function set_volume(value: Float): Float {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public var finished(get, never): Bool;
|
||||
|
||||
function get_finished(): Bool {
|
||||
return false;
|
||||
}
|
||||
}
|
47
Kha/Backends/Java/kha/graphics4/CubeMap.hx
Normal file
47
Kha/Backends/Java/kha/graphics4/CubeMap.hx
Normal file
@ -0,0 +1,47 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import haxe.io.Bytes;
|
||||
|
||||
class CubeMap implements Canvas implements Resource {
|
||||
public static function createRenderTarget(size: Int, format: TextureFormat = null, depthStencil: DepthStencilFormat = null): CubeMap {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unload(): Void {}
|
||||
|
||||
public function lock(level: Int = 0): Bytes {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(): Void {}
|
||||
|
||||
public var width(get, never): Int;
|
||||
|
||||
function get_width(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var height(get, never): Int;
|
||||
|
||||
function get_height(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public var g1(get, never): kha.graphics1.Graphics;
|
||||
|
||||
function get_g1(): kha.graphics1.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g2(get, never): kha.graphics2.Graphics;
|
||||
|
||||
function get_g2(): kha.graphics2.Graphics {
|
||||
return null;
|
||||
}
|
||||
|
||||
public var g4(get, never): kha.graphics4.Graphics;
|
||||
|
||||
function get_g4(): kha.graphics4.Graphics {
|
||||
return null;
|
||||
}
|
||||
}
|
7
Kha/Backends/Java/kha/graphics4/FragmentShader.hx
Normal file
7
Kha/Backends/Java/kha/graphics4/FragmentShader.hx
Normal file
@ -0,0 +1,7 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class FragmentShader {
|
||||
public function new(source: Blob) {}
|
||||
}
|
17
Kha/Backends/Java/kha/graphics4/IndexBuffer.hx
Normal file
17
Kha/Backends/Java/kha/graphics4/IndexBuffer.hx
Normal file
@ -0,0 +1,17 @@
|
||||
package kha.graphics4;
|
||||
|
||||
class IndexBuffer {
|
||||
public function new(indexCount: Int, usage: Usage, canRead: Bool = false) {}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): Array<Int> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {}
|
||||
|
||||
public function set(): Void {}
|
||||
|
||||
public function count(): Int {
|
||||
return 0;
|
||||
}
|
||||
}
|
19
Kha/Backends/Java/kha/graphics4/Program.hx
Normal file
19
Kha/Backends/Java/kha/graphics4/Program.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package kha.graphics4;
|
||||
|
||||
class Program {
|
||||
public function new() {}
|
||||
|
||||
public function setVertexShader(shader: VertexShader): Void {}
|
||||
|
||||
public function setFragmentShader(shader: FragmentShader): Void {}
|
||||
|
||||
public function link(structure: VertexStructure): Void {}
|
||||
|
||||
public function getConstantLocation(name: String): ConstantLocation {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getTextureUnit(name: String): TextureUnit {
|
||||
return null;
|
||||
}
|
||||
}
|
19
Kha/Backends/Java/kha/graphics4/VertexBuffer.hx
Normal file
19
Kha/Backends/Java/kha/graphics4/VertexBuffer.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package kha.graphics4;
|
||||
|
||||
class VertexBuffer {
|
||||
public function new(vertexCount: Int, structure: VertexStructure, usage: Usage, canRead: Bool = false) {}
|
||||
|
||||
public function lock(?start: Int, ?count: Int): kha.arrays.Float32Array {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unlock(?count: Int): Void {}
|
||||
|
||||
public function count(): Int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function stride(): Int {
|
||||
return 1;
|
||||
}
|
||||
}
|
7
Kha/Backends/Java/kha/graphics4/VertexShader.hx
Normal file
7
Kha/Backends/Java/kha/graphics4/VertexShader.hx
Normal file
@ -0,0 +1,7 @@
|
||||
package kha.graphics4;
|
||||
|
||||
import kha.Blob;
|
||||
|
||||
class VertexShader {
|
||||
public function new(source: Blob) {}
|
||||
}
|
91
Kha/Backends/Java/kha/java/Font.hx
Normal file
91
Kha/Backends/Java/kha/java/Font.hx
Normal file
@ -0,0 +1,91 @@
|
||||
package kha.java;
|
||||
|
||||
import kha.FontStyle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Font in JFont;
|
||||
|
||||
// @:classCode('
|
||||
// private static java.awt.image.BufferedImage testImage = new java.awt.image.BufferedImage(1, 1, java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
// private static java.awt.Graphics2D testGraphics;
|
||||
// public java.awt.Font font;
|
||||
// static {
|
||||
// testGraphics = testImage.createGraphics();
|
||||
// }
|
||||
// ')
|
||||
class Font implements Resource {
|
||||
static var testImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
static var testGraphics: Graphics2D;
|
||||
|
||||
public var font: JFont;
|
||||
public var myName: String;
|
||||
public var myStyle: FontStyle;
|
||||
public var mySize: Float;
|
||||
|
||||
public function new(name: String, style: FontStyle, size: Float) {
|
||||
if (testGraphics == null)
|
||||
testGraphics = testImage.createGraphics();
|
||||
init(name, style, size);
|
||||
}
|
||||
|
||||
public var name(get, never): String;
|
||||
|
||||
function get_name(): String {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public var style(get, never): FontStyle;
|
||||
|
||||
function get_style(): FontStyle {
|
||||
return myStyle;
|
||||
}
|
||||
|
||||
public var size(get, never): Float;
|
||||
|
||||
function get_size(): Float {
|
||||
return mySize;
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// font = new java.awt.Font(name, 0, (int)size);
|
||||
// myName = name;
|
||||
// myStyle = style;
|
||||
// mySize = size;
|
||||
// ')
|
||||
function init(name: String, style: FontStyle, size: Float) {
|
||||
font = new JFont(name, 0, Std.int(size));
|
||||
myName = name;
|
||||
myStyle = style;
|
||||
mySize = size;
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// return testGraphics.getFontMetrics(font).getHeight();
|
||||
// ')
|
||||
public function height(fontSize: Int): Float {
|
||||
return testGraphics.getFontMetrics(font).getHeight();
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// return testGraphics.getFontMetrics(font).stringWidth(str);
|
||||
// ')
|
||||
public function width(fontSize: Int, str: String): Float {
|
||||
return testGraphics.getFontMetrics(font).stringWidth(str);
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// return testGraphics.getFontMetrics(font).getHeight() - testGraphics.getFontMetrics(font).getLeading();
|
||||
// ')
|
||||
public function baseline(fontSize: Int): Float {
|
||||
return testGraphics.getFontMetrics(font).getHeight() - testGraphics.getFontMetrics(font).getLeading();
|
||||
// return 0;
|
||||
}
|
||||
|
||||
// @:functionCode('
|
||||
// font = null;
|
||||
// ')
|
||||
public function unload(): Void {
|
||||
font = null;
|
||||
}
|
||||
}
|
9
Kha/Backends/Java/kha/java/Graphics.hx
Normal file
9
Kha/Backends/Java/kha/java/Graphics.hx
Normal file
@ -0,0 +1,9 @@
|
||||
package kha.java;
|
||||
|
||||
class Graphics {
|
||||
public function new() {}
|
||||
|
||||
public function maxTextureSize(): Int {
|
||||
return 4096;
|
||||
}
|
||||
}
|
120
Kha/Backends/Java/kha/java/Music.hx
Normal file
120
Kha/Backends/Java/kha/java/Music.hx
Normal file
@ -0,0 +1,120 @@
|
||||
package kha.java;
|
||||
|
||||
import java.lang.Runnable;
|
||||
|
||||
@:classCode('
|
||||
java.io.File file;
|
||||
javax.sound.sampled.AudioInputStream in;
|
||||
javax.sound.sampled.SourceDataLine line;
|
||||
int frameSize;
|
||||
byte[] buffer = new byte [32 * 1024]; // 32k is arbitrary
|
||||
Thread playThread;
|
||||
boolean playing;
|
||||
boolean notYetEOF;
|
||||
')
|
||||
class Music implements Runnable {
|
||||
var loop: Bool = false;
|
||||
|
||||
public function new(filename: String) {
|
||||
init(filename);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
try {
|
||||
//instance = this;
|
||||
java.io.File f = new java.io.File(filename);
|
||||
file = f;
|
||||
in = javax.sound.sampled.AudioSystem.getAudioInputStream (f);
|
||||
javax.sound.sampled.AudioFormat format = in.getFormat();
|
||||
javax.sound.sampled.AudioFormat.Encoding formatEncoding = format.getEncoding();
|
||||
if (!(formatEncoding.equals(javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED) || formatEncoding.equals(javax.sound.sampled.AudioFormat.Encoding.PCM_UNSIGNED)))
|
||||
throw new javax.sound.sampled.UnsupportedAudioFileException(file.getName() + " is not PCM audio");
|
||||
//System.out.println ("got PCM format");
|
||||
frameSize = format.getFrameSize();
|
||||
javax.sound.sampled.DataLine.Info info = new javax.sound.sampled.DataLine.Info(javax.sound.sampled.SourceDataLine.class, format);
|
||||
//System.out.println ("got info");
|
||||
line = (javax.sound.sampled.SourceDataLine)javax.sound.sampled.AudioSystem.getLine(info);
|
||||
//System.out.println ("got line");
|
||||
line.open();
|
||||
//System.out.println ("opened line");
|
||||
playThread = new Thread(this);
|
||||
playing = false;
|
||||
notYetEOF = true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
')
|
||||
function init(filename: String): Void {}
|
||||
|
||||
@:functionCode('
|
||||
int readPoint = 0;
|
||||
int bytesRead = 0;
|
||||
|
||||
try {
|
||||
while (playing) {
|
||||
while (notYetEOF) {
|
||||
if (playing) {
|
||||
bytesRead = in.read(buffer, readPoint, buffer.length - readPoint);
|
||||
if (bytesRead == -1) {
|
||||
notYetEOF = false;
|
||||
break;
|
||||
}
|
||||
// how many frames did we get,
|
||||
// and how many are left over?
|
||||
//int frames = bytesRead / frameSize;
|
||||
int leftover = bytesRead % frameSize;
|
||||
// send to line
|
||||
line.write(buffer, readPoint, bytesRead-leftover);
|
||||
// save the leftover bytes
|
||||
System.arraycopy(buffer, bytesRead, buffer, 0, leftover);
|
||||
readPoint = leftover;
|
||||
}
|
||||
else {
|
||||
// if not playing
|
||||
// Thread.yield();
|
||||
try { Thread.sleep (10);}
|
||||
catch (InterruptedException ie) {}
|
||||
}
|
||||
}
|
||||
//System.out.println ("reached eof");
|
||||
try {
|
||||
in = javax.sound.sampled.AudioSystem.getAudioInputStream(file);
|
||||
}
|
||||
catch (javax.sound.sampled.UnsupportedAudioFileException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (loop) notYetEOF = true;
|
||||
else playing = false;
|
||||
}
|
||||
line.drain();
|
||||
line.stop();
|
||||
}
|
||||
catch (java.io.IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
// line.close();
|
||||
}
|
||||
')
|
||||
public function run(): Void {}
|
||||
|
||||
@:functionCode('
|
||||
this.loop = loop;
|
||||
playing = true;
|
||||
if (!playThread.isAlive())
|
||||
playThread.start();
|
||||
line.start();
|
||||
')
|
||||
function play2(loop: Bool): Void {}
|
||||
|
||||
public function play(loop: Bool = false): Void {
|
||||
play2(loop);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
playing = false;
|
||||
line.stop();
|
||||
')
|
||||
public function stop(): Void {}
|
||||
}
|
131
Kha/Backends/Java/kha/java/Painter.hx
Normal file
131
Kha/Backends/Java/kha/java/Painter.hx
Normal file
@ -0,0 +1,131 @@
|
||||
package kha.java;
|
||||
|
||||
import kha.Color;
|
||||
import kha.Font;
|
||||
import kha.Image;
|
||||
import kha.math.FastMatrix3;
|
||||
import kha.math.Matrix3;
|
||||
import kha.Rotation;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
@:classCode('
|
||||
public float tx = 0;
|
||||
public float ty = 0;
|
||||
|
||||
private static int round(double value) {
|
||||
return (int)Math.round(value);
|
||||
}
|
||||
')
|
||||
class Painter extends kha.graphics2.Graphics {
|
||||
public var graphics: Graphics2D;
|
||||
|
||||
// public var tx: Float = 0;
|
||||
// public var ty: Float = 0;
|
||||
var myColor: Color;
|
||||
var myFont: Font;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
// private static inline function round(value:Float):Int {
|
||||
// return Math.round(value);
|
||||
// }
|
||||
|
||||
@:functionCode('
|
||||
graphics.setBackground(new java.awt.Color(color));
|
||||
graphics.clearRect(0, 0, 2048, 2048);
|
||||
')
|
||||
function clear2(color: Int): Void {}
|
||||
|
||||
override public function clear(color: Color = null): Void {
|
||||
clear2(color != null ? color.value : Color.Black.value);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
graphics.setRenderingHint(java.awt.RenderingHints.KEY_INTERPOLATION, java.awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
')
|
||||
public function setRenderHint(): Void {}
|
||||
|
||||
@:functionCode('
|
||||
graphics.drawImage(img.image, round(tx + x), round(ty + y), null);
|
||||
')
|
||||
override public function drawImage(img: Image, x: Float, y: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
graphics.drawImage(image.image, round(tx + dx), round(ty + dy), round(tx + dx + dw), round(ty + dy + dh), round(sx), round(sy), round(sx + sw), round(sy + sh), null);
|
||||
')
|
||||
override public function drawScaledSubImage(image: Image, sx: Float, sy: Float, sw: Float, sh: Float, dx: Float, dy: Float, dw: Float, dh: Float): Void {}
|
||||
|
||||
override function get_color(): kha.Color {
|
||||
return myColor;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
graphics.setColor(new java.awt.Color(color));
|
||||
')
|
||||
function setColorInternal(color: kha.Color): Void {}
|
||||
|
||||
override function set_color(color: kha.Color): kha.Color {
|
||||
setColorInternal(color);
|
||||
return myColor = color;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
java.awt.Stroke oldStroke = graphics.getStroke();
|
||||
graphics.setStroke(new java.awt.BasicStroke((float)strength));
|
||||
graphics.drawRect(round(tx + x), round(ty + y), round(width), round(height));
|
||||
graphics.setStroke(oldStroke);
|
||||
')
|
||||
function drawRect2(x: Float, y: Float, width: Float, height: Float, strength: Float): Void {}
|
||||
|
||||
override public function drawRect(x: Float, y: Float, width: Float, height: Float, strength: Float = 1.0): Void {
|
||||
drawRect2(x, y, width, height, strength);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
graphics.fillRect(round(tx + x), round(ty + y), round(width), round(height));
|
||||
')
|
||||
override public function fillRect(x: Float, y: Float, width: Float, height: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
graphics.setFont(((kha.java.Font)font).font);
|
||||
')
|
||||
function setFontInternal(font: Font): Void {}
|
||||
|
||||
override function get_font(): kha.Font {
|
||||
return myFont;
|
||||
}
|
||||
|
||||
override function set_font(font: kha.Font): kha.Font {
|
||||
setFontInternal(font);
|
||||
return myFont = font;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
graphics.drawString(text, round(tx + x), round(ty + y));
|
||||
')
|
||||
override public function drawString(text: String, x: Float, y: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
java.awt.Stroke oldStroke = graphics.getStroke();
|
||||
graphics.setStroke(new java.awt.BasicStroke((Float)strength));
|
||||
graphics.drawLine(round(tx + x1), round(ty + y1), round(tx + x2), round(ty + y2));
|
||||
graphics.setStroke(oldStroke);
|
||||
')
|
||||
override public function drawLine(x1: Float, y1: Float, x2: Float, y2: Float, strength: Float = 1.0): Void {}
|
||||
|
||||
@:functionCode('
|
||||
int[] xPoints = new int[]{round(tx + x1), round(tx + x2), round(tx + x3)};
|
||||
int[] yPoints = new int[]{round(ty + y1), round(ty + y2), round(ty + y3)};
|
||||
graphics.fillPolygon(xPoints, yPoints, 3);
|
||||
')
|
||||
override public function fillTriangle(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float): Void {}
|
||||
|
||||
@:functionCode('
|
||||
graphics.setTransform(new java.awt.geom.AffineTransform(
|
||||
((Number)transformation._00).floatValue(), ((Number)transformation._01).floatValue(), ((Number)transformation._10).floatValue(),
|
||||
((Number)transformation._11).floatValue(), ((Number)transformation._20).floatValue(), ((Number)transformation._21).floatValue()));
|
||||
')
|
||||
override function setTransformation(transformation: FastMatrix3): Void {}
|
||||
}
|
161
Kha/Backends/Java/kha/java/Sound.hx
Normal file
161
Kha/Backends/Java/kha/java/Sound.hx
Normal file
@ -0,0 +1,161 @@
|
||||
package kha.java;
|
||||
|
||||
import kha.audio1.AudioChannel;
|
||||
|
||||
@:classCode('
|
||||
class SoundThread implements Runnable {
|
||||
private java.util.ArrayList<Sound> sounds = new java.util.ArrayList<Sound>();
|
||||
private java.util.Queue<Integer> queue = new java.util.ArrayDeque<Integer>();
|
||||
private java.util.ArrayDeque<Sound> soundqueue = new java.util.ArrayDeque<Sound>();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (;;) {
|
||||
boolean notempty;
|
||||
synchronized (this) {
|
||||
notempty = !queue.isEmpty();
|
||||
}
|
||||
while (notempty) {
|
||||
Sound sound;
|
||||
synchronized (this) {
|
||||
int index = queue.remove();
|
||||
sound = sounds.get(index);
|
||||
notempty = !queue.isEmpty();
|
||||
}
|
||||
if (soundqueue.contains(sound)) soundqueue.remove(sound);
|
||||
soundqueue.push(sound);
|
||||
if (!sound.isLoaded()) {
|
||||
if (soundqueue.size() < 30) {
|
||||
try {
|
||||
javax.sound.sampled.Clip clip = javax.sound.sampled.AudioSystem.getClip();
|
||||
sound.load(clip);
|
||||
}
|
||||
catch (javax.sound.sampled.LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
java.util.Iterator<Sound> it = soundqueue.descendingIterator();
|
||||
while (true) {
|
||||
Sound last = it.next();
|
||||
if (last.isLoaded()) {
|
||||
javax.sound.sampled.Clip clip = last.unloadit();
|
||||
sound.load(clip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sound.realplay();
|
||||
}
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int addSound(Sound sound) {
|
||||
sounds.add(sound);
|
||||
return sounds.size() - 1;
|
||||
}
|
||||
|
||||
public synchronized void play(int index) {
|
||||
queue.add(index);
|
||||
notify();
|
||||
}
|
||||
|
||||
public synchronized void stop(int index) {
|
||||
queue.remove(index);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
private static SoundThread thread;
|
||||
private javax.sound.sampled.Clip clip;
|
||||
|
||||
public javax.sound.sampled.Clip unloadit() {
|
||||
javax.sound.sampled.Clip clip = this.clip;
|
||||
this.clip = null;
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void load(javax.sound.sampled.Clip clip) {
|
||||
this.clip = clip;
|
||||
javax.sound.sampled.AudioInputStream stream;
|
||||
try {
|
||||
stream = javax.sound.sampled.AudioSystem.getAudioInputStream(new java.io.File(filename));
|
||||
clip.close();
|
||||
clip.open(stream);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
')
|
||||
@:nativeGen
|
||||
@:keep
|
||||
@:native("kha.java.Sound")
|
||||
class Sound extends kha.Sound {
|
||||
var index: Int;
|
||||
var filename: String;
|
||||
|
||||
public function new(filename: String) {
|
||||
super();
|
||||
init(filename);
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
this.filename = filename;
|
||||
if (thread == null) {
|
||||
thread = new SoundThread();
|
||||
Thread realthread = new Thread(thread);
|
||||
realthread.start();
|
||||
}
|
||||
index = thread.addSound(this);
|
||||
')
|
||||
function init(filename: String) {}
|
||||
|
||||
@:functionCode('
|
||||
thread.play(index);
|
||||
return null;
|
||||
')
|
||||
public function play(): AudioChannel {
|
||||
return null;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
if (clip.isRunning()) {
|
||||
clip.stop();
|
||||
}
|
||||
thread.stop(index);
|
||||
')
|
||||
public function stop(): Void {}
|
||||
|
||||
@:functionCode('
|
||||
return clip != null;
|
||||
')
|
||||
public function isLoaded(): Bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
@:functionCode('
|
||||
if (!clip.isRunning()) {
|
||||
clip.setFramePosition(0);
|
||||
clip.loop(0);
|
||||
}
|
||||
else clip.setFramePosition(0);
|
||||
')
|
||||
public function realplay(): Void {}
|
||||
|
||||
@:functionCode('
|
||||
return clip.isRunning();
|
||||
')
|
||||
public function isRunning(): Bool {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user