mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
parent
697835a313
commit
4fa52dcc56
@ -1,58 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build monogame
|
|
||||||
|
|
||||||
package audio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newContextImpl(sampleRate int, initCh chan struct{}) context {
|
|
||||||
return &mockContext{
|
|
||||||
sampleRate: sampleRate,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockContext struct {
|
|
||||||
sampleRate int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*mockContext) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockContext) NewPlayer() io.WriteCloser {
|
|
||||||
return &mockPlayer{
|
|
||||||
sampleRate: m.sampleRate,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockPlayer struct {
|
|
||||||
sampleRate int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockPlayer) Write(bs []byte) (int, error) {
|
|
||||||
bytesPerSec := 4 * m.sampleRate
|
|
||||||
|
|
||||||
n := len(bs)
|
|
||||||
time.Sleep(time.Duration(n) * time.Second / time.Duration(bytesPerSec))
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*mockPlayer) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -12,8 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// +build !monogame
|
|
||||||
|
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
#----------------------------- Global Properties ----------------------------#
|
|
||||||
|
|
||||||
/outputDir:bin/$(Platform)
|
|
||||||
/intermediateDir:obj/$(Platform)
|
|
||||||
/platform:Windows
|
|
||||||
/config:
|
|
||||||
/profile:Reach
|
|
||||||
/compress:False
|
|
||||||
|
|
||||||
#-------------------------------- References --------------------------------#
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
|
||||||
|
|
||||||
#begin Shader.fx
|
|
||||||
/importer:EffectImporter
|
|
||||||
/processor:EffectProcessor
|
|
||||||
/processorParam:DebugMode=Auto
|
|
||||||
/build:Shader.fx
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
// Code generated by file2byteslice. DO NOT EDIT.
|
|
||||||
// (gofmt is fine after generating)
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
var content_mgcb = []byte("\r\n#----------------------------- Global Properties ----------------------------#\r\n\r\n/outputDir:bin/$(Platform)\r\n/intermediateDir:obj/$(Platform)\r\n/platform:Windows\r\n/config:\r\n/profile:Reach\r\n/compress:False\r\n\r\n#-------------------------------- References --------------------------------#\r\n\r\n\r\n#---------------------------------- Content ---------------------------------#\r\n\r\n#begin Shader.fx\r\n/importer:EffectImporter\r\n/processor:EffectProcessor\r\n/processorParam:DebugMode=Auto\r\n/build:Shader.fx\r\n\r\n")
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
//go:generate file2byteslice -package=main -input=gogame.cs -output=gogame.cs.go -var=gogame_cs
|
|
||||||
//go:generate file2byteslice -package=main -input=program.cs -output=program.cs.go -var=program_cs
|
|
||||||
//go:generate file2byteslice -package=main -input=project.csproj -output=project.csproj.go -var=project_csproj
|
|
||||||
//go:generate file2byteslice -package=main -input=content.mgcb -output=content.mgcb.go -var=content_mgcb
|
|
||||||
//go:generate file2byteslice -package=main -input=shader.fx -output=shader.fx.go -var=shader_fx
|
|
||||||
//go:generate gofmt -s -w .
|
|
||||||
|
|
||||||
package main
|
|
@ -1,231 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using Microsoft.Xna.Framework.Input;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
using {{.Namespace}}.AutoGen;
|
|
||||||
|
|
||||||
namespace {{.Namespace}}
|
|
||||||
{
|
|
||||||
// Operation must sync with driver.Operation.
|
|
||||||
enum Operation
|
|
||||||
{
|
|
||||||
Zero,
|
|
||||||
One,
|
|
||||||
SrcAlpha,
|
|
||||||
DstAlpha,
|
|
||||||
OneMinusSrcAlpha,
|
|
||||||
OneMinusDstAlpha,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GoGame : Game
|
|
||||||
{
|
|
||||||
private GraphicsDeviceManager graphics;
|
|
||||||
private IInvokable onUpdate;
|
|
||||||
private IInvokable onDraw;
|
|
||||||
private VertexBuffer vertexBuffer;
|
|
||||||
private IndexBuffer indexBuffer;
|
|
||||||
private Effect effect;
|
|
||||||
|
|
||||||
public GoGame(IInvokable onUpdate, IInvokable onDraw)
|
|
||||||
{
|
|
||||||
this.onUpdate = onUpdate;
|
|
||||||
this.onDraw = onDraw;
|
|
||||||
this.graphics = new GraphicsDeviceManager(this);
|
|
||||||
this.graphics.PreferredBackBufferWidth = 640;
|
|
||||||
this.graphics.PreferredBackBufferHeight = 480;
|
|
||||||
|
|
||||||
this.Content.RootDirectory = "Content";
|
|
||||||
this.IsMouseVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadContent()
|
|
||||||
{
|
|
||||||
VertexElement[] elements = new VertexElement[]
|
|
||||||
{
|
|
||||||
new VertexElement(sizeof(float)*0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0),
|
|
||||||
new VertexElement(sizeof(float)*2, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
|
|
||||||
new VertexElement(sizeof(float)*4, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 1),
|
|
||||||
new VertexElement(sizeof(float)*8, VertexElementFormat.Vector4, VertexElementUsage.Color, 0),
|
|
||||||
};
|
|
||||||
this.vertexBuffer = new DynamicVertexBuffer(
|
|
||||||
this.GraphicsDevice, new VertexDeclaration(elements), 65536, BufferUsage.None);
|
|
||||||
this.GraphicsDevice.SetVertexBuffer(this.vertexBuffer);
|
|
||||||
|
|
||||||
this.indexBuffer = new DynamicIndexBuffer(
|
|
||||||
this.GraphicsDevice, IndexElementSize.SixteenBits, 65536, BufferUsage.None);
|
|
||||||
this.GraphicsDevice.Indices = this.indexBuffer;
|
|
||||||
|
|
||||||
// TODO: Add more shaders for e.g., linear filter.
|
|
||||||
this.effect = Content.Load<Effect>("Shader");
|
|
||||||
|
|
||||||
this.GraphicsDevice.RasterizerState = new RasterizerState()
|
|
||||||
{
|
|
||||||
CullMode = CullMode.None,
|
|
||||||
};
|
|
||||||
|
|
||||||
base.LoadContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetDestination(RenderTarget2D renderTarget2D, int viewportWidth, int viewportHeight)
|
|
||||||
{
|
|
||||||
this.GraphicsDevice.SetRenderTarget(renderTarget2D);
|
|
||||||
this.GraphicsDevice.Viewport = new Viewport(0, 0, viewportWidth, viewportHeight);
|
|
||||||
this.effect.Parameters["ViewportSize"].SetValue(new Vector2(viewportWidth, viewportHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetSource(Texture2D texture2D)
|
|
||||||
{
|
|
||||||
this.effect.Parameters["Texture"].SetValue(texture2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetVertices(byte[] vertices, byte[] indices)
|
|
||||||
{
|
|
||||||
this.vertexBuffer.SetData(vertices, 0, vertices.Length);
|
|
||||||
this.indexBuffer.SetData(indices, 0, indices.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime)
|
|
||||||
{
|
|
||||||
this.onUpdate.Invoke(null);
|
|
||||||
base.Update(gameTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
|
||||||
{
|
|
||||||
this.onDraw.Invoke(null);
|
|
||||||
base.Draw(gameTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void DrawTriangles(int indexLen, int indexOffset, Blend blendSrc, Blend blendDst)
|
|
||||||
{
|
|
||||||
this.GraphicsDevice.BlendState = new BlendState()
|
|
||||||
{
|
|
||||||
AlphaSourceBlend = blendSrc,
|
|
||||||
ColorSourceBlend = blendSrc,
|
|
||||||
AlphaDestinationBlend = blendDst,
|
|
||||||
ColorDestinationBlend = blendDst,
|
|
||||||
};
|
|
||||||
foreach (EffectPass pass in this.effect.CurrentTechnique.Passes)
|
|
||||||
{
|
|
||||||
pass.Apply();
|
|
||||||
this.GraphicsDevice.DrawIndexedPrimitives(
|
|
||||||
PrimitiveType.TriangleList, 0, indexOffset, indexLen / 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This methods are called from Go world. They must not have overloads.
|
|
||||||
class GameGoBinding
|
|
||||||
{
|
|
||||||
private static Blend ToBlend(Operation operation)
|
|
||||||
{
|
|
||||||
switch (operation)
|
|
||||||
{
|
|
||||||
case Operation.Zero:
|
|
||||||
return Blend.Zero;
|
|
||||||
case Operation.One:
|
|
||||||
return Blend.One;
|
|
||||||
case Operation.SrcAlpha:
|
|
||||||
return Blend.SourceAlpha;
|
|
||||||
case Operation.DstAlpha:
|
|
||||||
return Blend.DestinationAlpha;
|
|
||||||
case Operation.OneMinusSrcAlpha:
|
|
||||||
return Blend.InverseSourceAlpha;
|
|
||||||
case Operation.OneMinusDstAlpha:
|
|
||||||
return Blend.InverseDestinationAlpha;
|
|
||||||
}
|
|
||||||
throw new ArgumentOutOfRangeException("operation", operation, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private GoGame game;
|
|
||||||
|
|
||||||
private GameGoBinding(IInvokable onUpdate, IInvokable onDraw)
|
|
||||||
{
|
|
||||||
this.game = new GoGame(onUpdate, onDraw);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.game.Run();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
this.game.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private RenderTarget2D NewRenderTarget2D(double width, double height)
|
|
||||||
{
|
|
||||||
return new RenderTarget2D(this.game.GraphicsDevice, (int)width, (int)height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Dispose(Texture2D texture2D)
|
|
||||||
{
|
|
||||||
texture2D.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReplacePixels(RenderTarget2D renderTarget2D, byte[] pixels, double x, double y, double width, double height)
|
|
||||||
{
|
|
||||||
var rect = new Rectangle((int)x, (int)y, (int)width, (int)height);
|
|
||||||
renderTarget2D.SetData(0, rect, pixels, 0, pixels.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] Pixels(Texture2D texture2D, double width, double height)
|
|
||||||
{
|
|
||||||
Rectangle rect = new Rectangle(0, 0, (int)width, (int)height);
|
|
||||||
byte[] data = new byte[4*(int)width*(int)height];
|
|
||||||
texture2D.GetData(0, rect, data, 0, data.Length);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetDestination(RenderTarget2D renderTarget2D, double viewportWidth, double viewportHeight)
|
|
||||||
{
|
|
||||||
this.game.SetDestination(renderTarget2D, (int)viewportWidth, (int)viewportHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetSource(Texture2D texture2D)
|
|
||||||
{
|
|
||||||
this.game.SetSource(texture2D);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetVertices(byte[] vertices, byte[] indices)
|
|
||||||
{
|
|
||||||
this.game.SetVertices(vertices, indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Draw(double indexLen, double indexOffset, double operationSrc, double operationDst)
|
|
||||||
{
|
|
||||||
this.game.DrawTriangles((int)indexLen, (int)indexOffset, ToBlend((Operation)operationSrc), ToBlend((Operation)operationDst));
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsKeyPressed(string driverKey)
|
|
||||||
{
|
|
||||||
Keys key;
|
|
||||||
switch (driverKey)
|
|
||||||
{
|
|
||||||
case "KeyDown":
|
|
||||||
key = Keys.Down;
|
|
||||||
break;
|
|
||||||
case "KeyLeft":
|
|
||||||
key = Keys.Left;
|
|
||||||
break;
|
|
||||||
case "KeySpace":
|
|
||||||
key = Keys.Space;
|
|
||||||
break;
|
|
||||||
case "KeyRight":
|
|
||||||
key = Keys.Right;
|
|
||||||
break;
|
|
||||||
case "KeyUp":
|
|
||||||
key = Keys.Up;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Keyboard.GetState().IsKeyDown(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
@ -1,268 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/go2dotnet/gowasm2csharp"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ebitenmonogameName = "ebitenmonogame"
|
|
||||||
|
|
||||||
var (
|
|
||||||
flagA bool // -a
|
|
||||||
flagGcflags string // -gcflags
|
|
||||||
flagI bool // -i
|
|
||||||
flagLdflags string // -ldflags
|
|
||||||
flagN bool // -n
|
|
||||||
flagTags string // -tags
|
|
||||||
flagTrimpath bool // -trimpath
|
|
||||||
flagV bool // -v
|
|
||||||
flagWork bool // -work
|
|
||||||
flagX bool // -x
|
|
||||||
|
|
||||||
flagNamespace string // -namespace
|
|
||||||
flagO string // -o
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := checkGOOS(); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s: %v\n", ebitenmonogameName, err)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
var flagset flag.FlagSet
|
|
||||||
flag.Usage = func() {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s [-namespace namespace] [-o output] [build flags] [package]\n", ebitenmonogameName)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
flagset.BoolVar(&flagA, "a", false, "")
|
|
||||||
flagset.StringVar(&flagGcflags, "gcflags", "", "")
|
|
||||||
flagset.BoolVar(&flagI, "i", false, "")
|
|
||||||
flagset.StringVar(&flagLdflags, "ldflags", "", "")
|
|
||||||
flagset.BoolVar(&flagN, "n", false, "")
|
|
||||||
flagset.StringVar(&flagTags, "tags", "", "")
|
|
||||||
flagset.BoolVar(&flagTrimpath, "trimpath", false, "")
|
|
||||||
flagset.BoolVar(&flagV, "v", false, "")
|
|
||||||
flagset.BoolVar(&flagWork, "work", false, "")
|
|
||||||
flagset.BoolVar(&flagX, "x", false, "")
|
|
||||||
|
|
||||||
flagset.StringVar(&flagNamespace, "namespace", "", "")
|
|
||||||
flagset.StringVar(&flagO, "o", "", "")
|
|
||||||
|
|
||||||
flagset.Parse(os.Args[1:])
|
|
||||||
|
|
||||||
if flagNamespace == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "-namespace must be specified")
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
if flagO == "" {
|
|
||||||
fmt.Fprintln(os.Stderr, "-o must be specified")
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
if flagLdflags != "" {
|
|
||||||
flagLdflags += " "
|
|
||||||
}
|
|
||||||
flagLdflags = "-X github.com/hajimehoshi/ebiten/internal/monogame.namespace=" + flagNamespace
|
|
||||||
if flagTags != "" {
|
|
||||||
flagTags += ","
|
|
||||||
}
|
|
||||||
flagTags += "monogame"
|
|
||||||
|
|
||||||
var src string
|
|
||||||
switch srcs := flagset.Args(); len(srcs) {
|
|
||||||
case 0:
|
|
||||||
src = "."
|
|
||||||
case 1:
|
|
||||||
src = srcs[0]
|
|
||||||
default:
|
|
||||||
flag.Usage()
|
|
||||||
}
|
|
||||||
if err := run(src); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s: %v\n", ebitenmonogameName, err)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkGOOS() error {
|
|
||||||
out, err := exec.Command("go", "env", "GOOS").Output()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
goos := strings.TrimSpace(string(out))
|
|
||||||
if goos != "windows" {
|
|
||||||
fmt.Fprintln(os.Stderr, "Warning: The output project is buildable on Windows.")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(src string) error {
|
|
||||||
// TODO: Check src is a main package?
|
|
||||||
|
|
||||||
// Generate a wasm binary.
|
|
||||||
env := []string{
|
|
||||||
"GOOS=js",
|
|
||||||
"GOARCH=wasm",
|
|
||||||
}
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "ebitenmonogame")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if flagWork {
|
|
||||||
fmt.Fprintf(os.Stderr, "The temporary work directory: %s\n", dir)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
os.RemoveAll(dir)
|
|
||||||
}()
|
|
||||||
|
|
||||||
wasmFile := filepath.Join(dir, "tmp.wasm")
|
|
||||||
|
|
||||||
if err := runGo("build", []string{src}, env, "-o", wasmFile); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if flagN {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
autogenDir := filepath.Join(flagO, "autogen")
|
|
||||||
if flagV {
|
|
||||||
fmt.Fprintf(os.Stderr, "Writing %s%s*.cs\n", autogenDir, string(filepath.Separator))
|
|
||||||
}
|
|
||||||
if err := os.MkdirAll(autogenDir, 0755); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := gowasm2csharp.Generate(autogenDir, wasmFile, flagNamespace+".AutoGen"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := writeFile(filepath.Join(flagO, "GoGame.cs"), replaceNamespace(gogame_cs)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := writeFile(filepath.Join(flagO, "Program.cs"), replaceNamespace(program_cs)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
abs, err := filepath.Abs(flagO)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
project := filepath.Base(abs)
|
|
||||||
if err := writeFile(filepath.Join(flagO, project+".csproj"), replaceNamespace(project_csproj)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := writeFile(filepath.Join(flagO, "Content", "Content.mgcb"), replaceNamespace(content_mgcb)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := writeFile(filepath.Join(flagO, "Content", "Shader.fx"), replaceNamespace(shader_fx)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func runGo(subcmd string, srcs []string, env []string, args ...string) error {
|
|
||||||
cmd := exec.Command("go", subcmd)
|
|
||||||
if flagA {
|
|
||||||
cmd.Args = append(cmd.Args, "-a")
|
|
||||||
}
|
|
||||||
if flagGcflags != "" {
|
|
||||||
cmd.Args = append(cmd.Args, "-gcflags", flagGcflags)
|
|
||||||
}
|
|
||||||
if flagI {
|
|
||||||
cmd.Args = append(cmd.Args, "-i")
|
|
||||||
}
|
|
||||||
if flagLdflags != "" {
|
|
||||||
cmd.Args = append(cmd.Args, "-ldflags", flagLdflags)
|
|
||||||
}
|
|
||||||
if flagTags != "" {
|
|
||||||
cmd.Args = append(cmd.Args, "-tags", flagTags)
|
|
||||||
}
|
|
||||||
if flagTrimpath {
|
|
||||||
cmd.Args = append(cmd.Args, "-trimpath")
|
|
||||||
}
|
|
||||||
if flagV {
|
|
||||||
cmd.Args = append(cmd.Args, "-v")
|
|
||||||
}
|
|
||||||
if flagWork {
|
|
||||||
cmd.Args = append(cmd.Args, "-work")
|
|
||||||
}
|
|
||||||
if flagX {
|
|
||||||
cmd.Args = append(cmd.Args, "-x")
|
|
||||||
}
|
|
||||||
cmd.Args = append(cmd.Args, args...)
|
|
||||||
cmd.Args = append(cmd.Args, srcs...)
|
|
||||||
if len(env) > 0 {
|
|
||||||
cmd.Env = append([]string{}, env...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if flagX || flagN {
|
|
||||||
env := strings.Join(cmd.Env, " ")
|
|
||||||
if env != "" {
|
|
||||||
env += " "
|
|
||||||
}
|
|
||||||
fmt.Fprintf(os.Stderr, "%s%s\n", env, strings.Join(cmd.Args, " "))
|
|
||||||
}
|
|
||||||
if flagN {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cmd.Env) > 0 {
|
|
||||||
cmd.Env = append(os.Environ(), cmd.Env...)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
|
||||||
buf.WriteByte('\n')
|
|
||||||
if flagV {
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
} else {
|
|
||||||
cmd.Stdout = buf
|
|
||||||
cmd.Stderr = buf
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return fmt.Errorf("%s failed: %v%s", strings.Join(cmd.Args, " "), err, buf)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeFile(dst string, src []byte) error {
|
|
||||||
if flagV {
|
|
||||||
fmt.Fprintf(os.Stderr, "Writing %s\n", dst)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := ioutil.WriteFile(dst, src, 0644); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func replaceNamespace(src []byte) []byte {
|
|
||||||
return []byte(strings.ReplaceAll(string(src), "{{.Namespace}}", flagNamespace))
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using {{.Namespace}}.AutoGen;
|
|
||||||
|
|
||||||
namespace {{.Namespace}}
|
|
||||||
{
|
|
||||||
public static class Program
|
|
||||||
{
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
Go go = new Go();
|
|
||||||
go.Run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
// Code generated by file2byteslice. DO NOT EDIT.
|
|
||||||
// (gofmt is fine after generating)
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
var program_cs = []byte("\ufeffusing System;\nusing {{.Namespace}}.AutoGen;\n\nnamespace {{.Namespace}}\n{\n public static class Program\n {\n [STAThread]\n static void Main()\n {\n Go go = new Go();\n go.Run();\n }\n }\n}\n")
|
|
@ -1,24 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>net48</TargetFramework>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<MonoGameContentReference Include="**\*.mgcb" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
|
|
||||||
<PackageReference Include="MonoGame.Framework.DesktopGL.Core" Version="3.8.0.13" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,6 +0,0 @@
|
|||||||
// Code generated by file2byteslice. DO NOT EDIT.
|
|
||||||
// (gofmt is fine after generating)
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
var project_csproj = []byte("<Project Sdk=\"Microsoft.NET.Sdk\">\n\n <PropertyGroup>\n <OutputType>WinExe</OutputType>\n <TargetFramework>net48</TargetFramework>\n </PropertyGroup>\n\n <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n </PropertyGroup>\n <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">\n <AllowUnsafeBlocks>true</AllowUnsafeBlocks>\n </PropertyGroup>\n\n <ItemGroup>\n <MonoGameContentReference Include=\"**\\*.mgcb\" />\n </ItemGroup>\n\n <ItemGroup>\n <PackageReference Include=\"MonoGame.Content.Builder\" Version=\"3.7.0.9\" />\n <PackageReference Include=\"MonoGame.Framework.DesktopGL.Core\" Version=\"3.8.0.13\" />\n </ItemGroup>\n\n</Project>\n")
|
|
@ -1,69 +0,0 @@
|
|||||||
#if OPENGL
|
|
||||||
#define SV_POSITION POSITION
|
|
||||||
#define VS_SHADERMODEL vs_3_0
|
|
||||||
#define PS_SHADERMODEL ps_3_0
|
|
||||||
#else
|
|
||||||
#define VS_SHADERMODEL vs_4_0_level_9_1
|
|
||||||
#define PS_SHADERMODEL ps_4_0_level_9_1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Texture2D Texture;
|
|
||||||
float2 ViewportSize;
|
|
||||||
|
|
||||||
SamplerState samplerState
|
|
||||||
{
|
|
||||||
Texture = <Texture>;
|
|
||||||
MinFilter = Point;
|
|
||||||
MagFilter = Point;
|
|
||||||
MipFilter = Point;
|
|
||||||
AddressU = Clamp;
|
|
||||||
AddressV = Clamp;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexShaderInput
|
|
||||||
{
|
|
||||||
float2 Vertex : POSITION0;
|
|
||||||
float2 TexCoord : TEXCOORD0;
|
|
||||||
float4 TexRegion : TEXCOORD1;
|
|
||||||
float4 Color : COLOR0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexShaderOutput
|
|
||||||
{
|
|
||||||
float4 Position : SV_POSITION;
|
|
||||||
float2 TexCoord : TEXCOORD0;
|
|
||||||
float4 Color : COLOR0;
|
|
||||||
};
|
|
||||||
|
|
||||||
VertexShaderOutput MainVS(in VertexShaderInput input)
|
|
||||||
{
|
|
||||||
VertexShaderOutput output = (VertexShaderOutput)0;
|
|
||||||
|
|
||||||
float4x4 projectionMatrix = {
|
|
||||||
2.0 / ViewportSize.x, 0, 0, -1,
|
|
||||||
0, -2.0 / ViewportSize.y, 0, 1,
|
|
||||||
0, 0, 1, 0,
|
|
||||||
0, 0, 0, 1,
|
|
||||||
};
|
|
||||||
output.Position = mul(projectionMatrix, float4(input.Vertex.xy, 0, 1));
|
|
||||||
output.TexCoord = input.TexCoord;
|
|
||||||
output.Color = input.Color.rgba;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
float4 MainPS(VertexShaderOutput input) : COLOR
|
|
||||||
{
|
|
||||||
float4 c = tex2D(samplerState, input.TexCoord.xy).rgba;
|
|
||||||
//float4 c = Texture.Sample(samplerState, input.TexCoord.xy);
|
|
||||||
return c * input.Color.rgba;
|
|
||||||
}
|
|
||||||
|
|
||||||
technique BasicColorDrawing
|
|
||||||
{
|
|
||||||
pass P0
|
|
||||||
{
|
|
||||||
VertexShader = compile VS_SHADERMODEL MainVS();
|
|
||||||
PixelShader = compile PS_SHADERMODEL MainPS();
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,6 +0,0 @@
|
|||||||
// Code generated by file2byteslice. DO NOT EDIT.
|
|
||||||
// (gofmt is fine after generating)
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
var shader_fx = []byte("\ufeff#if OPENGL\n #define SV_POSITION POSITION\n #define VS_SHADERMODEL vs_3_0\n #define PS_SHADERMODEL ps_3_0\n#else\n #define VS_SHADERMODEL vs_4_0_level_9_1\n #define PS_SHADERMODEL ps_4_0_level_9_1\n#endif\n\nTexture2D Texture;\nfloat2 ViewportSize;\n\nSamplerState samplerState\n{\n Texture = <Texture>;\n MinFilter = Point;\n MagFilter = Point;\n MipFilter = Point;\n AddressU = Clamp;\n AddressV = Clamp;\n};\n\nstruct VertexShaderInput\n{\n float2 Vertex : POSITION0;\n float2 TexCoord : TEXCOORD0;\n float4 TexRegion : TEXCOORD1;\n float4 Color : COLOR0;\n};\n\nstruct VertexShaderOutput\n{\n float4 Position : SV_POSITION;\n float2 TexCoord : TEXCOORD0;\n float4 Color : COLOR0;\n};\n\nVertexShaderOutput MainVS(in VertexShaderInput input)\n{\n VertexShaderOutput output = (VertexShaderOutput)0;\n\n float4x4 projectionMatrix = {\n 2.0 / ViewportSize.x, 0, 0, -1,\n 0, -2.0 / ViewportSize.y, 0, 1,\n 0, 0, 1, 0,\n 0, 0, 0, 1,\n };\n output.Position = mul(projectionMatrix, float4(input.Vertex.xy, 0, 1));\n output.TexCoord = input.TexCoord;\n output.Color = input.Color.rgba;\n\n return output;\n}\n\nfloat4 MainPS(VertexShaderOutput input) : COLOR\n{\n float4 c = tex2D(samplerState, input.TexCoord.xy).rgba;\n //float4 c = Texture.Sample(samplerState, input.TexCoord.xy);\n return c * input.Color.rgba;\n}\n\ntechnique BasicColorDrawing\n{\n pass P0\n {\n VertexShader = compile VS_SHADERMODEL MainVS();\n PixelShader = compile PS_SHADERMODEL MainPS();\n }\n};\n")
|
|
3
doc.go
3
doc.go
@ -96,7 +96,4 @@
|
|||||||
// number of graphics commands affects the performance of your game.
|
// number of graphics commands affects the performance of your game.
|
||||||
//
|
//
|
||||||
// `ebitengl` forces to use OpenGL in any environments.
|
// `ebitengl` forces to use OpenGL in any environments.
|
||||||
//
|
|
||||||
// `monogame` changes the build target to MonoGame. This must be used with GOOS=js and GOARCH=wasm. This is
|
|
||||||
// experimental.
|
|
||||||
package ebiten
|
package ebiten
|
||||||
|
@ -1,141 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package monogame
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/monogame"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Graphics struct {
|
|
||||||
game *monogame.Game
|
|
||||||
}
|
|
||||||
|
|
||||||
var theGraphics Graphics
|
|
||||||
|
|
||||||
func Get() *Graphics {
|
|
||||||
return &theGraphics
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) SetGame(game *monogame.Game) {
|
|
||||||
g.game = game
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) SetThread(thread *thread.Thread) {
|
|
||||||
panic("monogame: SetThread is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) Begin() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) End() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) SetTransparent(transparent bool) {
|
|
||||||
panic("monogame: SetTransparent is not implemented yet")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) SetVertices(vertices []float32, indices []uint16) {
|
|
||||||
g.game.SetVertices(vertices, indices)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) NewImage(width, height int) (driver.Image, error) {
|
|
||||||
w, h := graphics.InternalImageSize(width), graphics.InternalImageSize(height)
|
|
||||||
v := g.game.NewRenderTarget2D(w, h)
|
|
||||||
return &Image{
|
|
||||||
v: v,
|
|
||||||
g: g,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) NewScreenFramebufferImage(width, height int) (driver.Image, error) {
|
|
||||||
return &Image{
|
|
||||||
v: &screen{game: g.game},
|
|
||||||
g: g,
|
|
||||||
width: width,
|
|
||||||
height: height,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) Reset() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) Draw(indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) error {
|
|
||||||
g.game.Draw(indexLen, indexOffset, mode, colorM, filter, address)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) SetVsyncEnabled(enabled bool) {
|
|
||||||
panic("monogame: SetVsyncEnabled is not implemented yet")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) FramebufferYDirection() driver.YDirection {
|
|
||||||
return driver.Downward
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) NeedsRestoring() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) IsGL() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) HasHighPrecisionFloat() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Graphics) MaxImageSize() int {
|
|
||||||
// TODO: Implement this
|
|
||||||
return 4096
|
|
||||||
}
|
|
||||||
|
|
||||||
type screen struct {
|
|
||||||
game *monogame.Game
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) SetAsDestination(viewportWidth, viewportHeight int) {
|
|
||||||
s.game.ResetDestination(viewportWidth, viewportHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) SetAsSource() {
|
|
||||||
panic("monogame: SetAsSource on screen is forbidden")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) Pixels(width, height int) ([]byte, error) {
|
|
||||||
panic("monogame: Pixels on screen is forbidden")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
|
||||||
panic("monogame: ReplacePixels on screen is forbidden")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) Dispose() {
|
|
||||||
// Do nothing?
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *screen) IsScreen() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package monogame
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
|
||||||
)
|
|
||||||
|
|
||||||
type RenderTarget2D interface {
|
|
||||||
SetAsDestination(viewportWidth, viewportHeight int)
|
|
||||||
SetAsSource()
|
|
||||||
Pixels(width, height int) ([]byte, error)
|
|
||||||
ReplacePixels(args []*driver.ReplacePixelsArgs)
|
|
||||||
Dispose()
|
|
||||||
IsScreen() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Image struct {
|
|
||||||
v RenderTarget2D
|
|
||||||
g *Graphics
|
|
||||||
width int
|
|
||||||
height int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) Dispose() {
|
|
||||||
i.v.Dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*Image) IsInvalidated() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) Pixels() ([]byte, error) {
|
|
||||||
return i.v.Pixels(i.width, i.height)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) SetAsDestination() {
|
|
||||||
w, h := i.width, i.height
|
|
||||||
if !i.v.IsScreen() {
|
|
||||||
w, h = graphics.InternalImageSize(w), graphics.InternalImageSize(h)
|
|
||||||
}
|
|
||||||
i.v.SetAsDestination(w, h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) SetAsSource() {
|
|
||||||
i.v.SetAsSource()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
|
||||||
i.v.ReplacePixels(args)
|
|
||||||
}
|
|
@ -12,8 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// +build !monogame
|
|
||||||
|
|
||||||
package jsutil
|
package jsutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright 2019 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build monogame
|
|
||||||
|
|
||||||
package jsutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall/js"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TemporaryUint8Array(byteLength int) js.Value {
|
|
||||||
panic("jsutil: TemporaryUint8Array is not implemented on monogame")
|
|
||||||
}
|
|
@ -1,159 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package monogame
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"runtime"
|
|
||||||
"syscall/js"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: This implementation depends on some C# files that are not uploaded yet.
|
|
||||||
// Create 'ebitenmonogame' command to generate C# project for the MonoGame.
|
|
||||||
|
|
||||||
// namespace is C# namespace.
|
|
||||||
//
|
|
||||||
// This is overwritten by -ldflags='-X github.com/hajimehoshi/ebiten/internal/monogame.namespace=NAMESPACE'.
|
|
||||||
var namespace = "Go2DotNet.Example.Ebiten"
|
|
||||||
|
|
||||||
type UpdateDrawer interface {
|
|
||||||
Update() error
|
|
||||||
Draw() error
|
|
||||||
}
|
|
||||||
|
|
||||||
type Game struct {
|
|
||||||
binding js.Value
|
|
||||||
update js.Func
|
|
||||||
draw js.Func
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewGame(ud UpdateDrawer) *Game {
|
|
||||||
update := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
|
||||||
return ud.Update()
|
|
||||||
})
|
|
||||||
|
|
||||||
draw := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
|
|
||||||
return ud.Draw()
|
|
||||||
})
|
|
||||||
|
|
||||||
v := js.Global().Get(".net").Get(namespace+".GameGoBinding").New(update, draw)
|
|
||||||
g := &Game{
|
|
||||||
binding: v,
|
|
||||||
update: update,
|
|
||||||
draw: draw,
|
|
||||||
}
|
|
||||||
runtime.SetFinalizer(g, (*Game).Dispose)
|
|
||||||
return g
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) Dispose() {
|
|
||||||
runtime.SetFinalizer(g, nil)
|
|
||||||
g.update.Release()
|
|
||||||
g.draw.Release()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) Run() {
|
|
||||||
g.binding.Call("Run")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) NewRenderTarget2D(width, height int) *RenderTarget2D {
|
|
||||||
v := g.binding.Call("NewRenderTarget2D", width, height)
|
|
||||||
r := &RenderTarget2D{
|
|
||||||
v: v,
|
|
||||||
binding: g.binding,
|
|
||||||
}
|
|
||||||
runtime.SetFinalizer(r, (*RenderTarget2D).Dispose)
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) SetVertices(vertices []float32, indices []uint16) {
|
|
||||||
var vs, is js.Value
|
|
||||||
{
|
|
||||||
h := (*reflect.SliceHeader)(unsafe.Pointer(&vertices))
|
|
||||||
h.Len *= 4
|
|
||||||
h.Cap *= 4
|
|
||||||
bs := *(*[]byte)(unsafe.Pointer(h))
|
|
||||||
runtime.KeepAlive(vertices)
|
|
||||||
vs = js.Global().Get("Uint8Array").New(len(bs))
|
|
||||||
js.CopyBytesToJS(vs, bs)
|
|
||||||
}
|
|
||||||
{
|
|
||||||
h := (*reflect.SliceHeader)(unsafe.Pointer(&indices))
|
|
||||||
h.Len *= 2
|
|
||||||
h.Cap *= 2
|
|
||||||
bs := *(*[]byte)(unsafe.Pointer(h))
|
|
||||||
runtime.KeepAlive(indices)
|
|
||||||
is = js.Global().Get("Uint8Array").New(len(bs))
|
|
||||||
js.CopyBytesToJS(is, bs)
|
|
||||||
}
|
|
||||||
g.binding.Call("SetVertices", vs, is)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) Draw(indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) {
|
|
||||||
src, dst := mode.Operations()
|
|
||||||
g.binding.Call("Draw", indexLen, indexOffset, int(src), int(dst))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) ResetDestination(viewportWidth, viewportHeight int) {
|
|
||||||
g.binding.Call("SetDestination", nil, viewportWidth, viewportHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *Game) IsKeyPressed(key driver.Key) bool {
|
|
||||||
// Pass a string of the key since both driver.Key value and XNA's key value are not reliable.
|
|
||||||
return g.binding.Call("IsKeyPressed", key.String()).Bool()
|
|
||||||
}
|
|
||||||
|
|
||||||
type RenderTarget2D struct {
|
|
||||||
v js.Value
|
|
||||||
binding js.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) Dispose() {
|
|
||||||
runtime.SetFinalizer(r, nil)
|
|
||||||
r.binding.Call("Dispose", r.v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) Pixels(width, height int) ([]byte, error) {
|
|
||||||
v := r.binding.Call("Pixels", r.v, width, height)
|
|
||||||
bs := make([]byte, v.Length())
|
|
||||||
js.CopyBytesToGo(bs, v)
|
|
||||||
return bs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) ReplacePixels(args []*driver.ReplacePixelsArgs) {
|
|
||||||
for _, a := range args {
|
|
||||||
arr := js.Global().Get("Uint8Array").New(len(a.Pixels))
|
|
||||||
js.CopyBytesToJS(arr, a.Pixels)
|
|
||||||
r.binding.Call("ReplacePixels", r.v, arr, a.X, a.Y, a.Width, a.Height)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) SetAsDestination(viewportWidth, viewportHeight int) {
|
|
||||||
r.binding.Call("SetDestination", r.v, viewportWidth, viewportHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) SetAsSource() {
|
|
||||||
r.binding.Call("SetSource", r.v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RenderTarget2D) IsScreen() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package monogame
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/monogame"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Input struct {
|
|
||||||
game *monogame.Game
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) CursorPosition() (x, y int) {
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadSDLID(id int) string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadName(id int) string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadAxis(id int, axis int) float64 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadAxisNum(id int) int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadButtonNum(id int) int {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) GamepadIDs() []int {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) IsGamepadButtonPressed(id int, button driver.GamepadButton) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) IsKeyPressed(key driver.Key) bool {
|
|
||||||
return i.game.IsKeyPressed(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) IsMouseButtonPressed(button driver.MouseButton) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) RuneBuffer() []rune {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) TouchIDs() []int {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) TouchPosition(id int) (x, y int) {
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Input) Wheel() (xoff, yoff float64) {
|
|
||||||
return 0, 0
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package monogame
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
graphics "github.com/hajimehoshi/ebiten/internal/graphicsdriver/monogame"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/monogame"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UI struct {
|
|
||||||
game *monogame.Game
|
|
||||||
context driver.UIContext
|
|
||||||
input Input
|
|
||||||
}
|
|
||||||
|
|
||||||
var theUI = &UI{}
|
|
||||||
|
|
||||||
func Get() *UI {
|
|
||||||
return theUI
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UI) Run(context driver.UIContext) error {
|
|
||||||
g := monogame.NewGame(context)
|
|
||||||
defer g.Dispose()
|
|
||||||
|
|
||||||
u.game = g
|
|
||||||
u.input.game = g
|
|
||||||
u.context = context
|
|
||||||
u.Graphics().(*graphics.Graphics).SetGame(g)
|
|
||||||
u.updateSize()
|
|
||||||
g.Run()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) RunWithoutMainLoop(context driver.UIContext) {
|
|
||||||
panic("monogame: RunWithoutMainLoop is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) DeviceScaleFactor() float64 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) IsFocused() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) ScreenSizeInFullscreen() (int, int) {
|
|
||||||
// TODO: Implement this
|
|
||||||
return 640, 480
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UI) ResetForFrame() {
|
|
||||||
u.updateSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UI) updateSize() {
|
|
||||||
// TODO: Implement this
|
|
||||||
u.context.Layout(640, 480)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) CursorMode() driver.CursorMode {
|
|
||||||
return driver.CursorModeVisible
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) SetCursorMode(mode driver.CursorMode) {
|
|
||||||
// TODO: Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) IsFullscreen() bool {
|
|
||||||
// TODO: Implement this
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) SetFullscreen(fullscreen bool) {
|
|
||||||
// TODO: Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) IsRunnableOnUnfocused() bool {
|
|
||||||
// TODO: Implement this
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
|
||||||
// TODO: Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) IsVsyncEnabled() bool {
|
|
||||||
// TODO: Implement this
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) SetVsyncEnabled(enabled bool) {
|
|
||||||
// TODO: Implement this
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) IsScreenTransparent() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) SetScreenTransparent(transparent bool) {
|
|
||||||
panic("monogame: SetScreenTransparent is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UI) Input() driver.Input {
|
|
||||||
return &u.input
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) Window() driver.Window {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UI) Graphics() driver.Graphics {
|
|
||||||
return graphics.Get()
|
|
||||||
}
|
|
@ -12,7 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// +build !monogame
|
|
||||||
// +build js
|
// +build js
|
||||||
|
|
||||||
package ebiten
|
package ebiten
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright 2020 The Ebiten Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build monogame
|
|
||||||
// +build js
|
|
||||||
|
|
||||||
package ebiten
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/uidriver/monogame"
|
|
||||||
)
|
|
||||||
|
|
||||||
func uiDriver() driver.UI {
|
|
||||||
return monogame.Get()
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user