daily update on 20240610 by nitload youmu
This commit is contained in:
@@ -43,6 +43,11 @@ namespace StgSharp.Controls
|
||||
{
|
||||
public class BattleField : ControllingItem
|
||||
{
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get ;
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class KeyboardButtonGroup : ControllingItem
|
||||
{
|
||||
private List<TriggerButton> buttonList;
|
||||
|
||||
private TriggerButton current;
|
||||
|
||||
public KeyboardButtonGroup()
|
||||
{
|
||||
buttonList = new List<TriggerButton>();
|
||||
}
|
||||
|
||||
public void AddButton(TriggerButton button)
|
||||
{
|
||||
buttonList.Add(button);
|
||||
}
|
||||
|
||||
public TriggerButton CurrentButton
|
||||
{
|
||||
get => current;
|
||||
}
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void MoveLeft()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void MoveRight()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void MoveUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void MoveDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Confirm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
foreach (var item in buttonList)
|
||||
{
|
||||
yield return item.Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,13 @@ namespace StgSharp.Controls
|
||||
private char defaultChar;
|
||||
|
||||
Dictionary<char, PlainGeometryMesh> texIndex;
|
||||
|
||||
PlainGeometryMesh _tittleMesh;
|
||||
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void Display(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
@@ -35,7 +39,6 @@ namespace StgSharp.Controls
|
||||
displayIndex = result.ToCharArray();
|
||||
}
|
||||
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return _tittleMesh;
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace StgSharp.Controls
|
||||
public vec2d Position { get; set; }
|
||||
|
||||
public Rectangle BoundingBox { get; set; }
|
||||
public abstract vec4d[] TextureBox { get; }
|
||||
|
||||
|
||||
public abstract IEnumerator<PlainGeometryMesh> GetEnumerator();
|
||||
|
||||
|
||||
@@ -13,12 +13,17 @@ namespace StgSharp.Controls
|
||||
{
|
||||
private PlainGeometryMesh renderMesh;
|
||||
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get => renderMesh.TextureCoord;
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return renderMesh;
|
||||
}
|
||||
|
||||
public DecorationBox(Rectangle bound, Image texture, vec2d[] texCoord)
|
||||
public DecorationBox(Rectangle bound, Image texture, vec4d[] texCoord)
|
||||
{
|
||||
renderMesh = new PlainGeometryMesh(BoundingBox, texture, texCoord);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,14 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.Controls
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class MarkingLabel : ControllingItem
|
||||
{
|
||||
public vec2d Position { get; set; }
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get => marker.TextureCoord;
|
||||
}
|
||||
|
||||
private vec2d _currentPosition, _movementVec;
|
||||
|
||||
@@ -40,7 +43,7 @@ namespace StgSharp.Controlling.Controls
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
yield return marker;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="TriggerButton.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controls
|
||||
{
|
||||
public class TriggerButton : ControllingItem
|
||||
{
|
||||
private AnimationBuilder switchAnimationBuilder;
|
||||
|
||||
#nullable enable
|
||||
private Action? enableAction;
|
||||
private Action? disableAction;
|
||||
private Action? confirmAction;
|
||||
#nullable restore
|
||||
|
||||
public override vec4d[] TextureBox
|
||||
{
|
||||
get { return switchAnimationBuilder.TextureFrame.VertexStream; }
|
||||
}
|
||||
|
||||
public bool IsHighLighted { get; internal set; }
|
||||
public bool IsDisabled { get; internal set; }
|
||||
|
||||
public event Action EnableEvent
|
||||
{
|
||||
add { enableAction += value; }
|
||||
remove { enableAction -= value; }
|
||||
}
|
||||
|
||||
public event Action DisableEvent
|
||||
{
|
||||
add { disableAction += value; }
|
||||
remove { disableAction -= value; }
|
||||
}
|
||||
|
||||
public event Action ConfirmEvent
|
||||
{
|
||||
add { confirmAction += value; }
|
||||
remove { confirmAction -= value; }
|
||||
}
|
||||
|
||||
public void Enable(AnimationBuilder animation)
|
||||
{
|
||||
if (!IsDisabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if( enableAction != null)enableAction();
|
||||
}
|
||||
|
||||
public void Disable(AnimationBuilder animation)
|
||||
{
|
||||
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if (disableAction != null) disableAction();
|
||||
}
|
||||
|
||||
public void Highlight(AnimationBuilder animation)
|
||||
{
|
||||
if (switchAnimationBuilder == null || switchAnimationBuilder.IsComplete)
|
||||
{
|
||||
switchAnimationBuilder = animation;
|
||||
}
|
||||
if (confirmAction != null) confirmAction();
|
||||
}
|
||||
|
||||
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
|
||||
{
|
||||
yield return new PlainGeometryMesh(this.BoundingBox, switchAnimationBuilder.GetAnimationFrame(),
|
||||
this.TextureBox);
|
||||
}
|
||||
|
||||
}//----------------------------------- End of class --------------------------------------------
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
@@ -8,12 +11,62 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewDesigner
|
||||
public class ViewPortDesigner
|
||||
{
|
||||
private KeyboardButtonGroup currentButtonGroup;
|
||||
|
||||
private List<ControllingItem> _controlList;
|
||||
|
||||
public ViewPortDesigner()
|
||||
{
|
||||
_controlList = new List<ControllingItem>();
|
||||
}
|
||||
|
||||
public KeyboardButtonGroup CreateKeyboardButtonGroup(
|
||||
ITrigger leftBidning,
|
||||
ITrigger rightBinding,
|
||||
ITrigger upBinding,
|
||||
ITrigger downBinding,
|
||||
ITrigger confirmBinding
|
||||
)
|
||||
{
|
||||
var ret = new KeyboardButtonGroup();
|
||||
_controlList.Add(ret);
|
||||
currentButtonGroup = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TriggerButton CreateKeyboardButton(
|
||||
Rectangle bonding, AnimationBuilder defaultAnimation, bool isEnable
|
||||
)
|
||||
{
|
||||
var ret = new TriggerButton();
|
||||
ret.BoundingBox = bonding;
|
||||
if (isEnable)
|
||||
{
|
||||
ret.IsDisabled = false;
|
||||
ret.Enable(defaultAnimation);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.IsDisabled = true;
|
||||
ret.Disable(defaultAnimation);
|
||||
}
|
||||
currentButtonGroup.AddButton(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CharacterLineIndexImage CreateCharacterLine(
|
||||
int length, char blankFilling, PlainGeometryMesh tittle, IEnumerable<(char,PlainGeometryMesh)> charList
|
||||
)
|
||||
{
|
||||
var ret = new CharacterLineIndexImage(length, blankFilling,tittle,charList);
|
||||
_controlList.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}//---------------------------------- End of Class -----------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ using StgSharp.Math;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class ViewModel
|
||||
public partial class View
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -44,9 +44,9 @@ namespace StgSharp.Graphics
|
||||
/// <param name="form"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static KeyStatus GetKeyStatus(ViewModel form, KeyboardKey key)
|
||||
public static KeyStatus GetKeyStatus(ViewModelBase form, KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(form.id, (int)key);
|
||||
return InternalIO.glfwGetKey(form.WindowID, (int)key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace StgSharp
|
||||
NumPad8 = 328,
|
||||
NumPad9 = 329,
|
||||
NumPadDec = 330,
|
||||
NumPadSiv = 331,
|
||||
NumPadDiv = 331,
|
||||
NumPadMul = 332,
|
||||
NumPadSub = 333,
|
||||
NumPadAdd = 334,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public interface ITrigger
|
||||
{
|
||||
public int TargetKeyOrButtonID { get; }
|
||||
public KeyStatus TriggeredStatus { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
public struct JoystickTrigger : ITrigger, IEquatable<JoystickTrigger>
|
||||
{
|
||||
public Joystick Stick;
|
||||
|
||||
private KeyStatus _triggeredStat;
|
||||
|
||||
public int TargetKeyOrButtonID => (int)Stick;
|
||||
|
||||
public KeyStatus TriggeredStatus => _triggeredStat;
|
||||
|
||||
public JoystickTrigger(Joystick targetKey)
|
||||
{
|
||||
this.Stick = targetKey;
|
||||
}
|
||||
|
||||
public static bool operator ==(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return left._triggeredStat == right._triggeredStat && left.Stick == right.Stick;
|
||||
}
|
||||
|
||||
public static bool operator !=(JoystickTrigger left, JoystickTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)Stick + 17 * (int)_triggeredStat;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {Stick} triggered when {_triggeredStat}";
|
||||
}
|
||||
|
||||
bool IEquatable<JoystickTrigger>.Equals(JoystickTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Controlling.UsrActivity
|
||||
{
|
||||
|
||||
public struct KeyTrigger: ITrigger,IEquatable<KeyTrigger>
|
||||
{
|
||||
public KeyboardKey TargetKey;
|
||||
private KeyStatus _triggerStat;
|
||||
|
||||
int ITrigger.TargetKeyOrButtonID => (int)TargetKey;
|
||||
|
||||
KeyStatus ITrigger.TriggeredStatus => _triggerStat;
|
||||
|
||||
public KeyTrigger(KeyboardKey targetKey)
|
||||
{
|
||||
this.TargetKey = targetKey;
|
||||
}
|
||||
|
||||
public static bool operator ==(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return left._triggerStat == right._triggerStat && left.TargetKey == right.TargetKey;
|
||||
}
|
||||
|
||||
public static bool operator !=(KeyTrigger left, KeyTrigger right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (int)TargetKey + 17 * (int)_triggerStat;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Key {TargetKey} triggered when {_triggerStat}";
|
||||
}
|
||||
|
||||
bool IEquatable<KeyTrigger>.Equals(KeyTrigger other)
|
||||
{
|
||||
return other == this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,8 @@ namespace StgSharp.Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if NET5_0_OR_GREATER
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -13,70 +13,8 @@ namespace StgSharp.Data
|
||||
/// Contains several <see cref="SSD"/> files reference as virtual disc.
|
||||
/// Data is actually stored in <see cref="SSD"/>s in certain RAID mode.
|
||||
/// </summary>
|
||||
public partial class Area:SSDFolder
|
||||
public partial class Area
|
||||
{
|
||||
private byte _id;
|
||||
private List<SSD> discList;
|
||||
|
||||
public Area()
|
||||
{
|
||||
_id = StgSharp.NewArea();
|
||||
}
|
||||
|
||||
public SSDSegment FindSegment(int id, byte SSD)
|
||||
{
|
||||
return discList[SSD].FindSegment(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="head"></param>
|
||||
/// <returns></returns>
|
||||
public static SSDraw AnalyzeHead(SSDrawHead head)
|
||||
{
|
||||
if (head._head.globalID == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SSDraw ret = new SSDraw();
|
||||
foreach ((int, int) item in head)
|
||||
{
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SSDraw FindFile(string route, SerializableTypeCode typeCode)
|
||||
{
|
||||
int id = 0;
|
||||
if (route.Contains('/'))
|
||||
{
|
||||
if (route.Contains(Serializer.GetNameTail(typeCode)))
|
||||
{
|
||||
route += Serializer.GetNameTail(typeCode);
|
||||
}
|
||||
id = idIndex[route];
|
||||
return this.files[id];
|
||||
}
|
||||
if (route.Contains(Serializer.GetNameTail(typeCode)))
|
||||
{
|
||||
route += Serializer.GetNameTail(typeCode);
|
||||
}
|
||||
string[] folderRoute = route.Split('/');
|
||||
int index = 0;
|
||||
if (folderRoute[0] != ".")
|
||||
{
|
||||
index = 1;
|
||||
}
|
||||
SSDFolder temp = this;
|
||||
for (; index < folderRoute.Length - 1; index++)
|
||||
{
|
||||
id = temp.idIndex[folderRoute[index]];
|
||||
temp = temp.folders[id];
|
||||
}
|
||||
id = idIndex[folderRoute[folderRoute.Length-1]];
|
||||
return temp.files[id];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,29 +41,24 @@ namespace StgSharp.Data
|
||||
{
|
||||
private SSDrawHead head;
|
||||
|
||||
private Dictionary<string, int> idDict;
|
||||
private Dictionary<int,SSDraw> fileList;
|
||||
private Dictionary<int, SSDraw> drawList;
|
||||
private Dictionary<string, SSDraw> fileList;
|
||||
|
||||
private List<SSDSegment> segments;
|
||||
private FileStream file; //很多时候
|
||||
private FileStream file;
|
||||
|
||||
|
||||
public SSDSegment FindSegment(int id)
|
||||
public SSD()
|
||||
{
|
||||
SSDSegment s = segments[id];
|
||||
if (s.ID != id)
|
||||
{
|
||||
foreach (var item in segments)
|
||||
{
|
||||
if (item.ID == id)
|
||||
{
|
||||
s = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
}
|
||||
|
||||
public SSD(FileStream fileStream)
|
||||
{
|
||||
fileList = new Dictionary<string, SSDraw>();
|
||||
file = fileStream;
|
||||
}
|
||||
|
||||
public static SSD FromFile(string fileRoute)
|
||||
{
|
||||
return new SSD(new FileStream(fileRoute, FileMode.Open, FileAccess.Read)) { };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,131 +37,48 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
public class SSDFolder : SSDSerializable, IEnumerable<SSDSegmentHead>
|
||||
public class SSDFolder : ISSDSerializable
|
||||
{
|
||||
private Area local;
|
||||
private SSDrawHead _head;
|
||||
internal int _folderID;
|
||||
internal string _name;
|
||||
internal Dictionary<int, SSDraw> files;
|
||||
internal Dictionary<int, SSDFolder> folders;
|
||||
internal Dictionary<string, int> idIndex;
|
||||
internal Dictionary<string, SSDFolder> folders;
|
||||
|
||||
internal SSDFolder()
|
||||
{
|
||||
folders = new Dictionary<int, SSDFolder>();
|
||||
files = new Dictionary<int, SSDraw>();
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
internal SSDFolder(string name)
|
||||
{
|
||||
if (name == "root")
|
||||
{
|
||||
throw new ArgumentNullException(
|
||||
throw new ArgumentException(
|
||||
"Name cannot be root," +
|
||||
"it is preserved for root file indexer.");
|
||||
}
|
||||
if (name == "default")
|
||||
{
|
||||
throw new ArgumentNullException(
|
||||
throw new ArgumentException(
|
||||
"Name cannot be default," +
|
||||
"it is preserved for default file id provider.");
|
||||
}
|
||||
_name = name;
|
||||
folders = new Dictionary<int, SSDFolder>();
|
||||
files = new Dictionary<int, SSDraw>();
|
||||
folders = new Dictionary<string, SSDFolder>();
|
||||
}
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
|
||||
|
||||
/// <summary>
|
||||
/// Check out if this virtual folder contains certain file.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the file</param>
|
||||
/// <param name="type">Type code defined as <see cref="SerializableTypeCode"/></param>
|
||||
/// <returns>Id of the file in its virtual disc</returns>
|
||||
public int FindFileId(string name, SerializableTypeCode type)
|
||||
{
|
||||
int fileid = 0;
|
||||
if (idIndex.TryGetValue($"{name}{Serializer.GetNameTail(type)}"
|
||||
, out fileid) && !(type == SerializableTypeCode.VirtualFolder))
|
||||
{
|
||||
return fileid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check out if this virtual folder contains certain file.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the file</param>
|
||||
/// <returns>Id of the folder in its virtual disc</returns>
|
||||
public int FindFolderId(string name)
|
||||
{
|
||||
int folderid = 0;
|
||||
if (idIndex.TryGetValue($"{name}_f", out folderid))
|
||||
{
|
||||
return folderid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public SSDraw CreateFile(string name, SerializableTypeCode type)
|
||||
{
|
||||
SSDraw ret = new SSDraw(name + Serializer.GetNameTail(type));
|
||||
ret.ID = local.NewID();
|
||||
return ret;
|
||||
}
|
||||
|
||||
//TODO 虚拟文件夹的GetBytes好难写
|
||||
public override byte[] GetBytes()
|
||||
{
|
||||
List<byte> rawBytes = new List<byte>();
|
||||
byte[] size = new byte[5];
|
||||
List<int> fileid = new List<int>();
|
||||
fileid.Add(4);
|
||||
foreach (var item in files)
|
||||
{
|
||||
fileid.Add(item.Value.ID);
|
||||
}
|
||||
return rawBytes.ToArray();
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(out int length)
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal override void BuildFromByteStream(byte[] stream)
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
foreach (var f in files)
|
||||
{
|
||||
yield return f.Value.Head._head;
|
||||
}
|
||||
foreach (var f in folders)
|
||||
{
|
||||
yield return f.Value._head._head;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<SSDSegmentHead> IEnumerable<SSDSegmentHead>.GetEnumerator()
|
||||
{
|
||||
foreach (var f in files)
|
||||
{
|
||||
yield return f.Value.Head._head;
|
||||
}
|
||||
foreach (var f in folders)
|
||||
{
|
||||
yield return f.Value._head._head;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+12
-234
@@ -47,250 +47,28 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
public class SSDraw
|
||||
{
|
||||
private byte[] data;
|
||||
|
||||
public const string FileType = "ssdraw";
|
||||
public const int SegmentCapacity = 16 * (StgSharp.ssdSegmentLength - 1);
|
||||
|
||||
private Area home;
|
||||
private int previousHash;
|
||||
private List<SSDSegment> segments;
|
||||
|
||||
private SSDrawHead _head;
|
||||
private SSDSegment currentSegment;
|
||||
private string _name;
|
||||
|
||||
internal SSDraw()
|
||||
public SSDraw(string name, Stream streamSource)
|
||||
{
|
||||
segments = new List<SSDSegment>();
|
||||
}
|
||||
|
||||
public SSDraw(string name)
|
||||
{
|
||||
_name = name;
|
||||
segments = new List<SSDSegment>();
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get => _head._head.globalID;
|
||||
set => _head._head.globalID = value;
|
||||
}
|
||||
|
||||
internal SSDrawHead Head => _head;
|
||||
|
||||
public SSDSegment[] GetSegments()
|
||||
{
|
||||
SSDSegment[] ret = segments.ToArray();
|
||||
Array.Resize(ref ret, ret.Length + 1);
|
||||
ret[ret.Length - 1] = Head.Data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void CreateRawFile(string outputFolder, bool rewrite)
|
||||
{
|
||||
string route = (outputFolder == string.Empty) ? ($"{_name}.{FileType}") :
|
||||
($"{outputFolder} \\ {_name}.{FileType}");
|
||||
if (File.Exists(route) && !rewrite)
|
||||
if ((streamSource == null) || (streamSource.Length == 0))
|
||||
{
|
||||
throw new Exception("This SSDRAW has already existed.");
|
||||
throw new ArgumentNullException(nameof(streamSource));
|
||||
}
|
||||
using (File.Create(route)) { }
|
||||
using (File.Open(route, FileMode.Truncate)) { }
|
||||
FileStream f = File.Open(route, FileMode.Open);
|
||||
foreach (SSDSegment _head in segments)
|
||||
{
|
||||
f.Write(_head.GetBytes(), 0, 18 * 16);
|
||||
}
|
||||
f.Close();
|
||||
}
|
||||
|
||||
|
||||
public static SSDraw readRaw(string route)
|
||||
{
|
||||
string[] routeFolders = route.Split('\\');
|
||||
if (!routeFolders.Last().Contains($".{FileType}"))
|
||||
{
|
||||
throw new Exception($"File to open is not a {FileType} file.");
|
||||
}
|
||||
byte[] dataStream= new byte[16 * StgSharp.ssdSegmentLength];
|
||||
SSDraw ret = new SSDraw();
|
||||
using (FileStream stream = File.Open(route, FileMode.Open))
|
||||
{
|
||||
int offset = 0;
|
||||
offset += stream.Read(dataStream,offset,16);
|
||||
ret._head = new SSDrawHead(dataStream);
|
||||
while (offset < stream.Length)
|
||||
{
|
||||
offset += stream.Read(dataStream, offset, 16);
|
||||
ret.segments.Add(SSDSegment.FromStream(dataStream));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void WriteRaw(byte[] dataStream)
|
||||
{
|
||||
previousHash = BuildRawHead(0);
|
||||
currentSegment = new SSDSegment(previousHash);
|
||||
int t = 0;
|
||||
for (int i = 0; i < dataStream.Length; i++, t++)
|
||||
{
|
||||
if (t == SegmentCapacity)
|
||||
{
|
||||
currentSegment.GetDataHash();
|
||||
currentSegment.Head.Size = 256;
|
||||
currentSegment.Head.globalID = i;
|
||||
segments.Add(currentSegment);
|
||||
previousHash = currentSegment.GetHashCode();
|
||||
currentSegment = new SSDSegment(previousHash);
|
||||
t = 0;
|
||||
}
|
||||
currentSegment[i] = dataStream[i];
|
||||
}
|
||||
currentSegment.FillRandomBytes(t);
|
||||
currentSegment.GetDataHash();
|
||||
currentSegment.Head.Size = t;
|
||||
segments.Add(currentSegment);
|
||||
|
||||
}
|
||||
|
||||
private int BuildRawHead(int beginID)
|
||||
{
|
||||
SSDrawHead rawHead = new SSDrawHead(_name);
|
||||
_head = rawHead;
|
||||
return rawHead.GetHashCode();
|
||||
Name = name;
|
||||
data = new byte[streamSource.Length];
|
||||
streamSource.Read(data.AsSpan());
|
||||
}
|
||||
|
||||
public SSDrawHead Head { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public unsafe class SSDrawHead : IEnumerable<(int, int)>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 32 * 16)]
|
||||
public unsafe struct SSDrawHead
|
||||
{
|
||||
|
||||
private SSDSegment segmentData;
|
||||
private string name;
|
||||
|
||||
internal SSDrawHead(byte[] data)
|
||||
{
|
||||
if (data.Length != 16* StgSharp.ssdSegmentLength)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
segmentData = new SSDSegment();
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
segmentData.Head.data = *(M128*)bptr;
|
||||
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
|
||||
{
|
||||
segmentData.WriteData<M128>(i - 1,*(M128*)(bptr + 16 * i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal SSDrawHead(string name)
|
||||
{
|
||||
int hash;
|
||||
this.name = name;
|
||||
using (SHA256 sha256Hash = SHA256.Create())
|
||||
{
|
||||
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(name));
|
||||
|
||||
hash = BitConverter.ToInt32(bytes, 0);
|
||||
}
|
||||
_head.previousHash = hash;
|
||||
}
|
||||
|
||||
public SSDrawHead()
|
||||
{
|
||||
}
|
||||
|
||||
internal SSDSegment Data
|
||||
{
|
||||
get => segmentData;
|
||||
}
|
||||
|
||||
public (int begin, int end) this[byte index]
|
||||
{
|
||||
get => segmentData.ReadData<(int, int)>(index);
|
||||
set => segmentData.WriteData<(int, int)>(index, value);
|
||||
}
|
||||
|
||||
public unsafe string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] bytes = new byte[(StgSharp.ssdSegmentLength - 1)* 16];
|
||||
fixed (byte* bptr = segmentData.Data)
|
||||
{
|
||||
Marshal.Copy(
|
||||
source: (IntPtr)bptr,
|
||||
destination: bytes,
|
||||
(StgSharp.ssdSegmentLength) * 16, (StgSharp.ssdSegmentLength - 1) * 16);
|
||||
}
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
set
|
||||
{
|
||||
byte[] namecode = Encoding.UTF8.GetBytes(value);
|
||||
fixed (byte* bptr = segmentData.Data)
|
||||
{
|
||||
Marshal.Copy(
|
||||
source: namecode,
|
||||
startIndex: 0,
|
||||
destination: (IntPtr)(bptr + (StgSharp.ssdSegmentLength) * 16),
|
||||
length: (StgSharp.ssdSegmentLength - 1) * 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte TypeCode
|
||||
{
|
||||
get => _head.selfDefine_1;
|
||||
internal set => _head.selfDefine_1 = value;
|
||||
}
|
||||
|
||||
internal ref SSDSegmentHead _head
|
||||
{
|
||||
get => ref segmentData.Head;
|
||||
}
|
||||
|
||||
internal byte pairCount
|
||||
{
|
||||
get => (byte)(_head.size / 8);
|
||||
set
|
||||
{
|
||||
if (value > 32)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
_head.size = (byte)(value * 8);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
return segmentData.GetBytes();
|
||||
}
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < pairCount; i++)
|
||||
{
|
||||
yield return segmentData.ReadData<(int, int)>(i);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<(int, int)> IEnumerable<(int, int)>.GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < pairCount; i++)
|
||||
{
|
||||
yield return segmentData.ReadData<(int, int)>(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,15 +7,13 @@ using System.Threading.Tasks;
|
||||
namespace StgSharp.Data
|
||||
{
|
||||
|
||||
public abstract class SSDSerializable
|
||||
public interface ISSDSerializable
|
||||
{
|
||||
public abstract SerializableTypeCode SSDTypeCode { get; }
|
||||
public SerializableTypeCode SSDTypeCode { get; }
|
||||
|
||||
public abstract byte[] GetBytes();
|
||||
public byte[] GetBytes();
|
||||
|
||||
public abstract byte[] GetBytes(out int length);
|
||||
|
||||
internal abstract void BuildFromByteStream(byte[] stream);
|
||||
internal void FromBytes(byte[] stream);
|
||||
}
|
||||
|
||||
public enum SerializableTypeCode
|
||||
@@ -28,21 +26,20 @@ namespace StgSharp.Data
|
||||
Shader = 5,
|
||||
Text = 6,
|
||||
RawData = 7,
|
||||
VirtualFolder = 8,
|
||||
|
||||
VirtualFolder = int.MaxValue,
|
||||
}
|
||||
|
||||
public static partial class Serializer
|
||||
{
|
||||
public static byte[] Serialize(SSDSerializable serializableObject)
|
||||
public static byte[] Serialize(ISSDSerializable serializableObject)
|
||||
{
|
||||
return serializableObject.GetBytes();
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(byte[] stream)where T : SSDSerializable
|
||||
public static T Deserialize<T>(byte[] stream)where T : ISSDSerializable
|
||||
{
|
||||
T serializableObject = (T)Activator.CreateInstance<T>();
|
||||
serializableObject.BuildFromByteStream(stream);
|
||||
serializableObject.FromBytes(stream);
|
||||
return serializableObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace StgSharp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sensor used for cheking out if a bullet hit a player or something else
|
||||
/// A sensor used for checking out if a bullet hit a player or something else
|
||||
/// </summary>
|
||||
public Sensor<PlainGeometry> CollisionSensor
|
||||
{
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public abstract class CoordinationBase
|
||||
{
|
||||
private CoordinationBase localCoordination;
|
||||
private Matrix44 coordMat;
|
||||
private bool globalCoordAvailable;
|
||||
|
||||
|
||||
public CoordinationBase(
|
||||
CoordinationBase localCoordination)
|
||||
{
|
||||
this.localCoordination = localCoordination;
|
||||
coordMat = new Matrix44();
|
||||
}
|
||||
|
||||
public virtual Point LocalOrigin
|
||||
{
|
||||
get => new Point( coordMat.colum3.XYZ);
|
||||
internal set => coordMat.colum3.XYZ = value.Coord;
|
||||
}
|
||||
|
||||
public virtual vec3d LocalX
|
||||
{
|
||||
get => coordMat.colum0.XYZ;
|
||||
internal set => coordMat.colum0.XYZ = value;
|
||||
}
|
||||
|
||||
public virtual vec3d LocalY
|
||||
{
|
||||
get => coordMat.colum1.XYZ;
|
||||
internal set => coordMat.colum1.XYZ = value;
|
||||
}
|
||||
|
||||
public virtual vec3d LocalZ
|
||||
{
|
||||
get => coordMat.colum2.XYZ;
|
||||
set => coordMat.colum2.XYZ = value;
|
||||
}
|
||||
|
||||
protected ref Matrix44 CoordMat
|
||||
{
|
||||
get => ref coordMat;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -37,31 +37,30 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class PlainCoordinate : ICoord
|
||||
public class PlainCoordinate : CoordinationBase
|
||||
{
|
||||
|
||||
public PlainCoordinate(
|
||||
vec3d origin,
|
||||
CoordinationBase local,
|
||||
Point origin,
|
||||
vec3d xAxis,
|
||||
vec3d yAxis
|
||||
)
|
||||
) : base(local)
|
||||
{
|
||||
CoordMat = Matrix44.Unit;
|
||||
Linear.Orthogonalize(ref xAxis, ref yAxis);
|
||||
|
||||
CoordMat.colum0 = new vec4d(xAxis, 0);
|
||||
CoordMat.colum1 = new vec4d(yAxis, 0);
|
||||
CoordMat.colum2 = new vec4d(Vec3d.Cross(xAxis, yAxis), 0);
|
||||
CoordMat.colum2 = new vec4d(Linear.Normalize(Vec3d.Cross(xAxis, yAxis)), 0);
|
||||
|
||||
Origin = origin;
|
||||
LocalOrigin = origin;
|
||||
}
|
||||
|
||||
private static PlainCoordinate statndardPlainCoordination = new PlainCoordinate(
|
||||
null, new Point(0,0,0),
|
||||
new vec3d(1,0,0),
|
||||
new vec3d(0, 1, 0)
|
||||
);
|
||||
|
||||
public new vec3d Z_axis
|
||||
{
|
||||
get => Vec3d.Cross(X_axis, Y_axis);
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public static PlainCoordinate StandardPlainCoordination => statndardPlainCoordination;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Class1.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class SpaceCoordinate : CoordinationBase
|
||||
{
|
||||
public SpaceCoordinate(
|
||||
CoordinationBase localCoordination, Point origin,
|
||||
vec3d xAxis, vec3d yAxis, vec3d zAxis
|
||||
) : base(localCoordination)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public class StreamLocalCoordinate : ICoord
|
||||
/*
|
||||
public class StreamLocalCoordinate : CoordinationBase
|
||||
{
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="GemoryException.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
public unsafe class ToUpperDimensionException : Exception
|
||||
{
|
||||
|
||||
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
public ToUpperDimensionException()
|
||||
{
|
||||
}
|
||||
|
||||
public ToUpperDimensionException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
|
||||
/// </summary>
|
||||
public class UnusedVertexException : Exception
|
||||
{
|
||||
|
||||
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
public UnusedVertexException()
|
||||
{
|
||||
}
|
||||
|
||||
public UnusedVertexException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public UnusedVertexException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,9 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public interface IGeometry
|
||||
{
|
||||
public CoordinationBase Coordination { get; }
|
||||
|
||||
public vec4d this[int index]
|
||||
public Point this[int index]
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
||||
@@ -46,13 +46,13 @@ namespace StgSharp.Geometries
|
||||
public int BufferId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d CenterPositionGlobal
|
||||
{
|
||||
get;
|
||||
set;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
|
||||
@@ -16,14 +16,16 @@ namespace StgSharp.Geometries
|
||||
public bool CollideWith(IPlainEntity entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class PlainEntity:IPlainEntity
|
||||
{
|
||||
private PlainGeometry _shape;
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => throw new NotImplementedException();
|
||||
set => throw new NotImplementedException();
|
||||
get => _shape.Coordination.LocalOrigin.Coord.XY;
|
||||
set => throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public PlainEntity(PlainGeometry shape)
|
||||
|
||||
@@ -76,7 +76,13 @@ namespace StgSharp.Geometries
|
||||
get;
|
||||
set;
|
||||
}
|
||||
vec2d IPlainEntity.CenterPosition { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
vec2d IPlainEntity.CenterPosition
|
||||
{
|
||||
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
bool IPlainEntity.CollideWith(IPlainEntity entity)
|
||||
{
|
||||
|
||||
@@ -42,19 +42,19 @@ namespace StgSharp.Geometries
|
||||
public abstract class PlainGeometry : IGeometry
|
||||
{
|
||||
protected vec4d[] vertexMat;
|
||||
internal ICoord coordinate;
|
||||
internal CoordinationBase coordinate;
|
||||
|
||||
public PlainGeometry()
|
||||
internal PlainGeometry(CoordinationBase coordination)
|
||||
{
|
||||
coordinate = coordination;
|
||||
}
|
||||
|
||||
public vec4d this[int index]
|
||||
public Point this[int index]
|
||||
{
|
||||
get => vertexMat[index];
|
||||
set => vertexMat[index] = value;
|
||||
get => new Point(vertexMat[index]);
|
||||
set => vertexMat[index].vec = value.coordVec;
|
||||
}
|
||||
|
||||
public ICoord ReferenceCoordinate => this.coordinate;
|
||||
|
||||
public int VertexCount => this.vertexMat.Length;
|
||||
|
||||
@@ -62,9 +62,11 @@ namespace StgSharp.Geometries
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public vec4d[] VertexStream => vertexMat;
|
||||
#pragma warning restore CA1819
|
||||
|
||||
public CoordinationBase Coordination => this.coordinate;
|
||||
#pragma warning restore CA1819
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -38,32 +38,53 @@ namespace StgSharp.Geometries
|
||||
public class Parallelogram : Polygon4
|
||||
{
|
||||
|
||||
internal readonly Func<int, vec3d> movCenterOperation =
|
||||
new Func<int, vec3d>(GeometryOperation.DefaultMotion);
|
||||
|
||||
internal Point center;
|
||||
|
||||
internal readonly Func<int,vec3d> movCenterOperation =
|
||||
new Func<int,vec3d>(GeometryOperation.DefaultMotion);
|
||||
|
||||
public Parallelogram(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z,
|
||||
float v3x, float v3y, float v3z
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(
|
||||
v0x, v0y, v0z,
|
||||
v1x, v1y, v1z,
|
||||
v2x, v2y, v2z,
|
||||
v3x, v3y, v3z
|
||||
v0x, v0y, v1x, v1y,
|
||||
v2x, v2y, v3x, v3y
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (
|
||||
this[0] + this[2] !=
|
||||
this[1] + this[3]
|
||||
this[0].Coord + this[2].Coord !=
|
||||
this[1].Coord + this[3].Coord
|
||||
)
|
||||
{
|
||||
InternalIO.InternalWriteLog("Init of geometry item failed, because four vertices cannot form a rectangle.", LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public Parallelogram(
|
||||
PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(coordination,
|
||||
v0x, v0y, v1x, v1y,
|
||||
v2x, v2y, v3x, v3y
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
if (
|
||||
this[0].Coord + this[2].Coord !=
|
||||
this[1].Coord + this[3].Coord
|
||||
)
|
||||
{
|
||||
InternalIO.InternalWriteLog("Init of geometry item failed, because four vertices cannot form a rectangle.", LogType.Warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ namespace StgSharp.Geometries
|
||||
|
||||
public Plain(Point p1, Point p2, Point p3)
|
||||
{
|
||||
vec3d origin = p1.Position;
|
||||
vec3d v1 = p2.Position - origin;
|
||||
vec3d v2 = p3.Position - origin;
|
||||
vec3d origin = p1.Coord;
|
||||
vec3d v1 = p2.Coord - origin;
|
||||
vec3d v2 = p3.Coord - origin;
|
||||
|
||||
|
||||
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //计算平面在xz平面上的方向投影
|
||||
|
||||
@@ -40,48 +40,80 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
protected static int[] Indices = [0, 1, 2, 0, 2, 3];
|
||||
|
||||
internal Polygon4()
|
||||
internal Polygon4():base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[4];
|
||||
}
|
||||
|
||||
public Polygon4(ICoord coordinate,
|
||||
vec3d topLeft,
|
||||
vec3d topRight,
|
||||
vec3d bottomRight,
|
||||
vec3d bottomLeft
|
||||
)
|
||||
internal Polygon4(vec4d[] rawCoord):
|
||||
base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this.coordinate = coordinate;
|
||||
this[0] = new vec4d(topLeft.vec);
|
||||
this[1] = new vec4d(topRight.vec);
|
||||
this[2] = new vec4d(bottomRight.vec);
|
||||
this[3] = new vec4d(bottomLeft.vec);
|
||||
|
||||
Vector4 maxCoord = this[0].vec;
|
||||
Vector4 minCoord = this[0].vec;
|
||||
|
||||
maxCoord = Vector4.Max(maxCoord, this[1].vec);
|
||||
maxCoord = Vector4.Max(maxCoord, this[2].vec);
|
||||
maxCoord = Vector4.Max(maxCoord, this[3].vec);
|
||||
|
||||
minCoord = Vector4.Min(minCoord, this[1].vec);
|
||||
minCoord = Vector4.Min(minCoord, this[2].vec);
|
||||
minCoord = Vector4.Min(minCoord, this[3].vec);
|
||||
if (rawCoord.Length != 4)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(rawCoord));
|
||||
}
|
||||
vertexMat = rawCoord;
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z,
|
||||
float v3x, float v3y, float v3z
|
||||
)
|
||||
Point topLeft,
|
||||
Point topRight,
|
||||
Point bottomRight,
|
||||
Point bottomLeft
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[4];
|
||||
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
this[3] = new vec4d(v3x, v3y, v3z, 0);
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
|
||||
public Polygon4(CoordinationBase coordinate,
|
||||
PlainCoordinate coordination,
|
||||
Point topLeft,
|
||||
Point topRight,
|
||||
Point bottomRight,
|
||||
Point bottomLeft
|
||||
) : base(coordinate)
|
||||
{
|
||||
this[0] = topLeft;
|
||||
this[1] = topRight;
|
||||
this[2] = bottomRight;
|
||||
this[3] = bottomLeft;
|
||||
|
||||
}
|
||||
|
||||
public Polygon4(
|
||||
PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(coordination)
|
||||
{
|
||||
vertexMat = new vec4d[4];
|
||||
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
}
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
@@ -39,25 +39,42 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Polygon5 : PlainGeometry
|
||||
{
|
||||
|
||||
public unsafe Polygon5()
|
||||
public unsafe Polygon5():base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z,
|
||||
float v3x, float v3y, float v3z,
|
||||
float v4x, float v4y, float v4z
|
||||
)
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y,
|
||||
float v4x, float v4y
|
||||
):base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
this[3] = new vec4d(v3x, v3y, v3z, 0);
|
||||
this[4] = new vec4d(v4x, v4y, v4z, 0);
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
public Polygon5(
|
||||
PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y,
|
||||
float v4x, float v4y
|
||||
):base(coordination)
|
||||
{
|
||||
vertexMat = new vec4d[5];
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
this[3] = new Point(v3x, v3y, 0);
|
||||
this[4] = new Point(v4x, v4y, 0);
|
||||
}
|
||||
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4 ];
|
||||
|
||||
@@ -38,11 +38,32 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
public class Polygon6 : PlainGeometry
|
||||
{
|
||||
public Polygon6()
|
||||
public Polygon6():base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[6];
|
||||
}
|
||||
|
||||
public Polygon6(
|
||||
PlainCoordinate coordination,
|
||||
vec2d vert0,
|
||||
vec2d vert1,
|
||||
vec2d vert2,
|
||||
vec2d vert3,
|
||||
vec2d vert4,
|
||||
vec2d vert5,
|
||||
vec2d vert6
|
||||
) : base(coordination)
|
||||
{
|
||||
vertexMat = new vec4d[6];
|
||||
vertexMat[0].vec = vert0.vec;
|
||||
vertexMat[1].vec = vert1.vec;
|
||||
vertexMat[2].vec = vert2.vec;
|
||||
vertexMat[3].vec = vert3.vec;
|
||||
vertexMat[4].vec = vert4.vec;
|
||||
vertexMat[5].vec = vert5.vec;
|
||||
vertexMat[6].vec = vert6.vec;
|
||||
}
|
||||
|
||||
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
@@ -38,20 +38,44 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
|
||||
public Rectangle(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z,
|
||||
float v3x, float v3y, float v3z
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(
|
||||
v0x, v0y, v0z,
|
||||
v1x, v1y, v1z,
|
||||
v2x, v2y, v2z,
|
||||
v3x, v3y, v3z
|
||||
v0x, v0y,
|
||||
v1x, v1y,
|
||||
v2x, v2y,
|
||||
v3x, v3y
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
vec2d side0 = (this[0] - this[1]).XY;
|
||||
vec2d side1 = (this[2] - this[1]).XY;
|
||||
vec2d side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
vec2d side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public Rectangle(
|
||||
PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y
|
||||
) : base(coordination,
|
||||
v0x, v0y,
|
||||
v1x, v1y,
|
||||
v2x, v2y,
|
||||
v3x, v3y
|
||||
)
|
||||
{
|
||||
#if DEBUG
|
||||
vec2d side0 = (this[0].Coord - this[1].Coord).XY;
|
||||
vec2d side1 = (this[2].Coord - this[1].Coord).XY;
|
||||
if (side0.Cross(side1) == 0)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
|
||||
@@ -42,14 +42,14 @@ namespace StgSharp.Geometries
|
||||
{
|
||||
|
||||
public Square(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z,
|
||||
float v3x, float v3y, float v3z)
|
||||
: base(v0x, v0y, v0z,
|
||||
v1x, v1y, v1z,
|
||||
v2x, v2y, v2z,
|
||||
v3x, v3y, v3z)
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y,
|
||||
float v3x, float v3y)
|
||||
: base(v0x, v0y,
|
||||
v1x, v1y,
|
||||
v2x, v2y,
|
||||
v3x, v3y)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
|
||||
@@ -42,33 +42,54 @@ namespace StgSharp.Geometries
|
||||
public unsafe class Triangle : PlainGeometry
|
||||
{
|
||||
|
||||
public Triangle()
|
||||
public Triangle():base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
vertexMat = new vec4d[3];
|
||||
}
|
||||
|
||||
public Triangle(
|
||||
vec3d vertex01,
|
||||
vec3d vertex02,
|
||||
vec3d vertex03
|
||||
)
|
||||
Point vertex01,
|
||||
Point vertex02,
|
||||
Point vertex03
|
||||
) : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = new vec4d( vertex01.vec);
|
||||
this[1] = new vec4d( vertex02.vec);
|
||||
this[2] = new vec4d( vertex03.vec);
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(
|
||||
float v0x, float v0y, float v0z,
|
||||
float v1x, float v1y, float v1z,
|
||||
float v2x, float v2y, float v2z
|
||||
)
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y
|
||||
) : base(PlainCoordinate.StandardPlainCoordination)
|
||||
{
|
||||
this[0] = new vec4d(v0x, v0y, v0z, 0);
|
||||
this[1] = new vec4d(v1x, v1y, v1z, 0);
|
||||
this[2] = new vec4d(v2x, v2y, v2z, 0);
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination,
|
||||
Point vertex01,
|
||||
Point vertex02,
|
||||
Point vertex03
|
||||
) : base(coordination)
|
||||
{
|
||||
this[0] = vertex01;
|
||||
this[1] = vertex02;
|
||||
this[2] = vertex03;
|
||||
}
|
||||
|
||||
public Triangle(PlainCoordinate coordination,
|
||||
float v0x, float v0y,
|
||||
float v1x, float v1y,
|
||||
float v2x, float v2y
|
||||
) : base(coordination)
|
||||
{
|
||||
this[0] = new Point(v0x, v0y, 0);
|
||||
this[1] = new Point(v1x, v1y, 0);
|
||||
this[2] = new Point(v2x, v2y, 0);
|
||||
}
|
||||
internal static int[] Indices = [ 0, 1, 2 ];
|
||||
|
||||
public override ReadOnlySpan<int> VertexIndices => Indices;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Geometries
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16)]
|
||||
public struct Point
|
||||
{
|
||||
[FieldOffset(0)] private vec3d coord;
|
||||
[FieldOffset(0)] internal Vector4 coordVec;
|
||||
|
||||
public Point(float x, float y, float z)
|
||||
{
|
||||
coordVec = new Vector4(x,y,z,1);
|
||||
}
|
||||
|
||||
public Point(vec3d coord)
|
||||
{
|
||||
Coord = coord;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
internal Point(vec4d vector)
|
||||
{
|
||||
coordVec = vector.vec;
|
||||
coordVec.W = 1;
|
||||
}
|
||||
|
||||
public vec3d Coord
|
||||
{
|
||||
get => coord;
|
||||
set { coord = value; coordVec.W = 1; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Geometries;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
@@ -35,23 +37,29 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public delegate Image BuildAnimationDelegate(float time, out Polygon4 texutreFrame);
|
||||
|
||||
public sealed class AnimationBuilder: IImageProvider
|
||||
{
|
||||
|
||||
private Image cache;
|
||||
|
||||
private Polygon4 textureFrame;
|
||||
private TimeFunction time;
|
||||
|
||||
public AnimationBuilder(
|
||||
Func<float, Image> builderFunc,
|
||||
BuildAnimationDelegate builderFunc,
|
||||
TimeFunction timeline
|
||||
)
|
||||
{
|
||||
textureFrame = new Polygon4();
|
||||
time = timeline;
|
||||
BuilderFunc = builderFunc;
|
||||
cache = BuilderFunc(time.Calculate(), out textureFrame);
|
||||
}
|
||||
|
||||
public Func<float, Image> BuilderFunc { get; set; }
|
||||
public Polygon4 TextureFrame { get => textureFrame; }
|
||||
|
||||
public BuildAnimationDelegate BuilderFunc { get; set; }
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
@@ -62,7 +70,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
if (!time.IsComplete)
|
||||
{
|
||||
cache = BuilderFunc(time.Calculate());
|
||||
cache = BuilderFunc(time.Calculate(),out textureFrame);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
@@ -428,17 +428,6 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void MakeContextCurrent(ViewModel form)
|
||||
{
|
||||
if (form.WindowID == IntPtr.Zero)
|
||||
{
|
||||
InternalIO.InternalWriteLog($"From {nameof(form)} is not inited.", LogType.Warning);
|
||||
return;
|
||||
}
|
||||
InternalIO.glfwMakeContextCurrent(form.id);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
|
||||
where T : struct
|
||||
|
||||
@@ -60,14 +60,14 @@ namespace StgSharp.Graphics.GL
|
||||
}
|
||||
}
|
||||
|
||||
public class Shader : SSDSerializable
|
||||
public class Shader : ISSDSerializable
|
||||
{
|
||||
|
||||
private readonly IntPtr context;
|
||||
internal readonly glHandleSet handle;
|
||||
public readonly ShaderType type;
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.Shader;
|
||||
|
||||
internal unsafe Shader(glHandleSet handle, ShaderType usage)
|
||||
{
|
||||
@@ -126,27 +126,26 @@ namespace StgSharp.Graphics.GL
|
||||
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
|
||||
}
|
||||
|
||||
//TODO shader 的序列化究极麻烦,原因是shader的架构问题
|
||||
public override byte[] GetBytes()
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public void CheckStatus(int index, ShaderStatus status)
|
||||
{
|
||||
string log = glFunc.GetShaderStatus(this,index, (int)status);
|
||||
if (log != "")
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
throw new Exception($"Shader Error\n{status}\n" + log);
|
||||
throw new Exception($"Shader Error \t{status}\n" + log);
|
||||
}
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(out int length)
|
||||
public byte[] GetBytes(out int length)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal override void BuildFromByteStream(byte[] stream)
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@@ -175,7 +174,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe Uniform<T> GetUniform<T>(string name) where T : struct
|
||||
@@ -187,7 +186,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U> GetUniform<T, U>(string name)
|
||||
where T : struct
|
||||
@@ -200,7 +199,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V> GetUniform<T, U, V>(string name)
|
||||
where T : struct
|
||||
@@ -213,7 +212,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// Get a uniform form current shader,
|
||||
/// the value type of the uniform should be provided.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the Uniform in shader code</param>
|
||||
/// <param name="name">ContextName of the Uniform in shader code</param>
|
||||
/// <returns></returns>
|
||||
public unsafe Uniform<T, U, V, W> GetUniform<T, U, V, W>(string name)
|
||||
where T : struct
|
||||
|
||||
@@ -56,15 +56,15 @@ namespace StgSharp.Graphics.GL
|
||||
private static string glExtensionList;
|
||||
|
||||
/// <summary>
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewModel"/> context.
|
||||
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> context.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="ViewModel"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this glRenderStream stream)
|
||||
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL context</param>
|
||||
public static unsafe void LoadGLapi(this ViewPort vp)
|
||||
{
|
||||
GLcontext* context = (GLcontext*)stream.ContextHandle;
|
||||
GLcontext* context = (GLcontext*)vp.GraphicHandle;
|
||||
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
|
||||
#pragma warning disable CS8909
|
||||
if (((GLcontext*)stream.ContextHandle)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
if (context->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
|
||||
#pragma warning restore CS8909
|
||||
{
|
||||
return;
|
||||
@@ -102,25 +102,25 @@ namespace StgSharp.Graphics.GL
|
||||
{
|
||||
#region load_core_gl
|
||||
|
||||
LoadGLcore10((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore11((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore12((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore13((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore14((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore15((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore20((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore21((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore30((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore31((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore32((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore33((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore40((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore41((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore42((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore43((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore44((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore45((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore46((GLcontext*)stream.ContextHandle, loader);
|
||||
LoadGLcore10(context, loader);
|
||||
LoadGLcore11(context, loader);
|
||||
LoadGLcore12(context, loader);
|
||||
LoadGLcore13(context, loader);
|
||||
LoadGLcore14(context, loader);
|
||||
LoadGLcore15(context, loader);
|
||||
LoadGLcore20(context, loader);
|
||||
LoadGLcore21(context, loader);
|
||||
LoadGLcore30(context, loader);
|
||||
LoadGLcore31(context, loader);
|
||||
LoadGLcore32(context, loader);
|
||||
LoadGLcore33(context, loader);
|
||||
LoadGLcore40(context, loader);
|
||||
LoadGLcore41(context, loader);
|
||||
LoadGLcore42(context, loader);
|
||||
LoadGLcore43(context, loader);
|
||||
LoadGLcore44(context, loader);
|
||||
LoadGLcore45(context, loader);
|
||||
LoadGLcore46(context, loader);
|
||||
|
||||
#endregion load_core_gl
|
||||
}
|
||||
@@ -777,7 +777,7 @@ namespace StgSharp.Graphics.GL
|
||||
/// <summary>
|
||||
/// Get the function pointer of given OpenGL api name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the OpenGL api</param>
|
||||
/// <param name="name">ContextName of the OpenGL api</param>
|
||||
/// <returns>The funtion pointer of the api in stream of <see cref="IntPtr"/></returns>
|
||||
public static IntPtr LoadGLfunc(string name)
|
||||
{
|
||||
|
||||
@@ -45,17 +45,14 @@ namespace StgSharp.Graphics.GL
|
||||
public abstract partial class glRenderStream : RenderStream
|
||||
{
|
||||
|
||||
protected glRenderStream(RenderStreamConstructArgs args) : base(args)
|
||||
{
|
||||
}
|
||||
protected glRenderStream(RenderStreamConstructArgs args,bool isSharing) : base(args,isSharing)
|
||||
protected glRenderStream(ViewPort v, (int,int,int) cube) : base(v,cube)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected IntPtr glContextHandle
|
||||
{
|
||||
get { return ContextHandle; }
|
||||
set { ContextHandle = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,14 +84,6 @@ namespace StgSharp.Graphics.GL
|
||||
InternalIO.glfwSetWindowSizeLimits(this.CanvasHandle, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
internal override sealed unsafe void CreateCanvas()
|
||||
{
|
||||
byte[] nameCode = Encoding.UTF8.GetBytes(Name);
|
||||
CanvasHandle = InternalIO.glfwCreateWindow(
|
||||
Width, Height, nameCode, Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
|
||||
internal override sealed void InternalDraw(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output)
|
||||
@@ -106,9 +95,8 @@ namespace StgSharp.Graphics.GL
|
||||
|
||||
internal override sealed void InternalInit()
|
||||
{
|
||||
CreateCanvas();
|
||||
MakeAsCurrentContext();
|
||||
this.LoadGLapi();
|
||||
this.Port.LoadGLapi();
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class Image : SSDSerializable, IImageProvider
|
||||
public class Image : ISSDSerializable, IImageProvider
|
||||
{
|
||||
internal byte[] data;
|
||||
internal ImageInfo info;
|
||||
@@ -74,7 +74,7 @@ namespace StgSharp.Graphics
|
||||
get => (info.Width, info.Height);
|
||||
}
|
||||
|
||||
public override SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
|
||||
public int Width => info.Width;
|
||||
|
||||
public static unsafe Image FromFile(string route, ImageLoader loader)
|
||||
@@ -111,7 +111,7 @@ namespace StgSharp.Graphics
|
||||
return new glArrayHandle(data);
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes()
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
@@ -139,40 +139,9 @@ namespace StgSharp.Graphics
|
||||
return data;
|
||||
}
|
||||
|
||||
public override unsafe byte[] GetBytes(out int length)
|
||||
public void FromBytes(byte[] stream)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
int size = Width * Height * ChannelCount;
|
||||
data = new byte[size];
|
||||
int i = 0;
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
byte* pptr = bptr;
|
||||
for (; i < size; i += 16)
|
||||
{
|
||||
*(M128*)(pptr + i) = *(M128*)(info.StreamPtr + i);
|
||||
}
|
||||
for (; i < size; i++)
|
||||
{
|
||||
*(pptr + i) = *(byte*)(info.StreamPtr + i);
|
||||
}
|
||||
}
|
||||
fixed (ImageInfo* pptr = &info)
|
||||
{
|
||||
InternalIO.InternalUnloadImage(pptr);
|
||||
}
|
||||
info.StreamPtr = IntPtr.Zero;
|
||||
}
|
||||
length = data.Length;
|
||||
return data;
|
||||
}
|
||||
|
||||
internal override unsafe void BuildFromByteStream(byte[] stream)
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
$"{($"{typeof(Image).Name} does not support BuildFromByteStream,")}{($"please use Image.FromMemory instead.")}"
|
||||
);
|
||||
}
|
||||
|
||||
public Image ProvideImage()
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public class PlainGeometryMesh
|
||||
{
|
||||
private IGeometry _shape;
|
||||
private PlainGeometry _shape;
|
||||
private Image _texture;
|
||||
private vec2d[] textureCoord;
|
||||
private vec4d[] textureCoord;
|
||||
|
||||
public PlainGeometryMesh(
|
||||
IGeometry shape, Image texture, IEnumerable<vec2d> texCoord
|
||||
PlainGeometry shape, Image texture, vec4d[] texCoord
|
||||
)
|
||||
{
|
||||
if (shape==null)
|
||||
@@ -28,31 +28,30 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
_shape = shape;
|
||||
textureCoord = new vec2d[shape.VertexCount];
|
||||
_texture = texture;
|
||||
if (texCoord is not vec2d[] source)
|
||||
{
|
||||
source = texCoord.ToArray();
|
||||
}
|
||||
if (textureCoord.Length > source.Length)
|
||||
if (shape.VertexCount > texCoord.Length)
|
||||
{
|
||||
throw new ArgumentException(paramName: nameof(texCoord), message: "Amount of texture coordination is too less");
|
||||
}
|
||||
Array.Copy(sourceArray: source, textureCoord, textureCoord.Length);
|
||||
textureCoord = texCoord;
|
||||
return;
|
||||
}
|
||||
|
||||
public PlainGeometryMesh Resize(PlainGeometry newShape)
|
||||
{
|
||||
return new PlainGeometryMesh(newShape, _texture, textureCoord);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<int> MeshIndices => _shape.VertexIndices;
|
||||
|
||||
public vec4d[] VertexArray => _shape.VertexStream;
|
||||
|
||||
public Image Texture
|
||||
public Image TextureImage
|
||||
{
|
||||
get => _texture;
|
||||
internal set => _texture = value;
|
||||
}
|
||||
|
||||
public vec2d[] TextureCoord => textureCoord;
|
||||
public vec4d[] TextureCoord => textureCoord;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,34 +45,41 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public abstract class RenderStream : IConvertableToBlueprintNode
|
||||
{
|
||||
private ViewPort primeArgs;
|
||||
|
||||
private protected (int x, int y, int z) _coordStretch;
|
||||
|
||||
private protected RenderStreamConstructArgs primeArgs;
|
||||
|
||||
private Camera nativeCamera;
|
||||
|
||||
private IntPtr canvasHandle;
|
||||
private IntPtr contextHandle;
|
||||
public ViewPort Port => primeArgs;
|
||||
|
||||
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
|
||||
|
||||
|
||||
internal IntPtr ContextHandle
|
||||
{
|
||||
get => primeArgs.GraphicHandle;
|
||||
private protected set => primeArgs.GraphicHandle = value;
|
||||
}
|
||||
|
||||
private IntPtr monitor;
|
||||
private IntPtr sharedCanvas;
|
||||
|
||||
internal TimeSpanProvider timeProvider;
|
||||
|
||||
protected RenderStream(RenderStreamConstructArgs args, bool isSharing)
|
||||
/*
|
||||
protected RenderStream(View v, bool isSharing)
|
||||
{
|
||||
if (args == null)
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
if (isSharing)
|
||||
{
|
||||
primeArgs = args;
|
||||
primeArgs = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
View? newArgs = args.Clone() as View;
|
||||
primeArgs = newArgs;
|
||||
}
|
||||
|
||||
@@ -80,32 +87,21 @@ namespace StgSharp.Graphics
|
||||
_coordStretch = args.UnitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
/**/
|
||||
|
||||
public RenderStream(RenderStreamConstructArgs args)
|
||||
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
|
||||
{
|
||||
if (args == null)
|
||||
if (v == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
throw new ArgumentNullException(nameof(v));
|
||||
}
|
||||
RenderStreamConstructArgs? newArgs = args.Clone() as RenderStreamConstructArgs;
|
||||
primeArgs = newArgs;
|
||||
primeArgs = v;
|
||||
|
||||
monitor = newArgs!.Monitor;
|
||||
_coordStretch = newArgs.UnitCubeSize;
|
||||
monitor = v!.Monitor;
|
||||
_coordStretch = unitCubeSize;
|
||||
NativeCamera = new Camera();
|
||||
}
|
||||
|
||||
public IntPtr CanvasHandle
|
||||
{
|
||||
get => canvasHandle;
|
||||
internal set => canvasHandle = value;
|
||||
}
|
||||
|
||||
public IntPtr ContextHandle
|
||||
{
|
||||
get => contextHandle;
|
||||
internal set => contextHandle = value;
|
||||
}
|
||||
|
||||
public FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
@@ -124,7 +120,7 @@ namespace StgSharp.Graphics
|
||||
internal set
|
||||
{
|
||||
primeArgs.Height = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +133,6 @@ namespace StgSharp.Graphics
|
||||
public string Name
|
||||
{
|
||||
get => primeArgs.Name;
|
||||
internal set => primeArgs.Name = value;
|
||||
}
|
||||
|
||||
public IntPtr SharedCanvas
|
||||
@@ -153,7 +148,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
primeArgs.Height = value.width;
|
||||
primeArgs.Width = value.height;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +158,7 @@ namespace StgSharp.Graphics
|
||||
internal set
|
||||
{
|
||||
primeArgs.Width = value;
|
||||
InternalIO.glfwSetWindowSize(this.canvasHandle, Width, Height);
|
||||
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +200,7 @@ namespace StgSharp.Graphics
|
||||
where TSource : RenderStream
|
||||
where TTarget : RenderStream
|
||||
{
|
||||
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, true) as TTarget;
|
||||
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
|
||||
if (target == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
@@ -213,16 +208,11 @@ namespace StgSharp.Graphics
|
||||
);
|
||||
}
|
||||
target.timeProvider = source.timeProvider;
|
||||
target.canvasHandle = source.canvasHandle;
|
||||
target.contextHandle = source.contextHandle;
|
||||
target.Init();
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal abstract void CreateCanvas();
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
|
||||
|
||||
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
|
||||
@@ -239,7 +229,7 @@ namespace StgSharp.Graphics
|
||||
/// so do not ignore return value of this method.
|
||||
/// </summary>
|
||||
/// <param name="source">Shader using this camera</param>
|
||||
/// <param name="name">Name of projection camera named in shader</param>
|
||||
/// <param name="name">ContextName of projection camera named in shader</param>
|
||||
/// <returns>
|
||||
/// <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) representing
|
||||
/// projection matrix in shader program.
|
||||
@@ -277,25 +267,4 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
public class RenderStreamConstructArgs : ICloneable
|
||||
{
|
||||
|
||||
public int Height { get; set; }
|
||||
public IntPtr Monitor { get; set; }
|
||||
public string Name { get; set; }
|
||||
public (int x, int y, int z) UnitCubeSize { get; set; }
|
||||
public int Width { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
RenderStreamConstructArgs ret = new RenderStreamConstructArgs();
|
||||
ret.Height = Height;
|
||||
ret.Width = Width;
|
||||
ret.Monitor = Monitor;
|
||||
ret.Name = Name;
|
||||
ret.UnitCubeSize = UnitCubeSize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="FormThreading.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
using StgSharp.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public partial class View
|
||||
{
|
||||
internal Blueprint localLogic;
|
||||
|
||||
/*
|
||||
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
|
||||
{
|
||||
if (methods.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
|
||||
{
|
||||
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
|
||||
if (attr == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
|
||||
{
|
||||
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
|
||||
}
|
||||
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
|
||||
FrameAsyncThread thread = new(s, attr._priority);
|
||||
//singleFrameAsyncThreadList.Add(thread);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="View.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public unsafe partial class View
|
||||
{
|
||||
|
||||
private (int w, int h) sizeCache;
|
||||
private (int x, int y, int z) unitCubeSize;
|
||||
|
||||
private ViewPort context;
|
||||
|
||||
private ViewPortDesigner design;
|
||||
|
||||
public ViewPort Port
|
||||
{
|
||||
get => context;
|
||||
}
|
||||
|
||||
public View(ViewPort vp, ViewPortDesigner design)
|
||||
{
|
||||
context = vp;
|
||||
sizeCache = (0, 0);
|
||||
unitCubeSize = (1, 1, 1);
|
||||
localLogic = new Logic.Blueprint();
|
||||
this.design = design;
|
||||
SelfName = string.Empty;
|
||||
}
|
||||
|
||||
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
|
||||
{
|
||||
context = vp;
|
||||
sizeCache = (0, 0);
|
||||
unitCubeSize = cubeSize;
|
||||
localLogic = new Logic.Blueprint();
|
||||
}
|
||||
|
||||
public bool Activated { get; internal set; }
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
if (context.Height != sizeCache.h)
|
||||
{
|
||||
sizeCache.h = context.Height;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
return sizeCache.h;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
sizeCache.h = value;
|
||||
context.Height = value;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Monitor => context.Monitor;
|
||||
|
||||
public IntPtr ViewHandle => context.ViewPortID;
|
||||
|
||||
public string ContextName => context.Name;
|
||||
|
||||
public string SelfName { get; set; }
|
||||
|
||||
public (int x, int y, int z) UnitCubeSize
|
||||
{
|
||||
get => unitCubeSize;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
if (context.Width != sizeCache.w)
|
||||
{
|
||||
sizeCache.w = context.Width;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
return sizeCache.h;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
sizeCache.w = value;
|
||||
context.Width = value;
|
||||
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
{
|
||||
public class ViewPort
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public IntPtr Monitor { get; internal set; }
|
||||
|
||||
public IntPtr ViewPortID { get; private set; }
|
||||
public IntPtr GraphicHandle { get; internal set; }
|
||||
|
||||
internal ViewPort()
|
||||
{
|
||||
Height = 800;
|
||||
Width = 600;
|
||||
Name = new StackFrame(1, false).
|
||||
GetMethod()!.DeclaringType!.Name;
|
||||
Monitor = IntPtr.Zero;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(Width,Height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
|
||||
public ViewPort(vec2d size,string name, IntPtr monitor)
|
||||
{
|
||||
Height = (int) size.Y;
|
||||
Width = (int) size.X;
|
||||
Name = name;
|
||||
Monitor = monitor;
|
||||
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
|
||||
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,14 +125,11 @@ namespace StgSharp.Logic
|
||||
{
|
||||
do
|
||||
{
|
||||
try
|
||||
BlueprintNode node;
|
||||
while (RequestNextNode(out node))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
RequestNextNode().Run();
|
||||
}
|
||||
node.Run();
|
||||
}
|
||||
catch (NodeClearException) { }
|
||||
} while (!terminate());
|
||||
}
|
||||
|
||||
@@ -199,16 +196,18 @@ namespace StgSharp.Logic
|
||||
beginNode.InputData = parameters;
|
||||
}
|
||||
|
||||
private BlueprintNode RequestNextNode()
|
||||
private bool RequestNextNode(out BlueprintNode node)
|
||||
{
|
||||
if (currentNodeIndex < nodeList.Count)
|
||||
{
|
||||
BlueprintNode ret = nodeList[currentNodeIndex];
|
||||
Interlocked.Increment(ref currentNodeIndex);
|
||||
return ret;
|
||||
node = ret;
|
||||
return true;
|
||||
}
|
||||
Interlocked.Exchange(ref currentNodeIndex, 0);
|
||||
throw new NodeClearException();
|
||||
node = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName
|
||||
|
||||
@@ -69,14 +69,14 @@ namespace StgSharp.Logic
|
||||
|
||||
public void CompleteAndSkip()
|
||||
{
|
||||
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
|
||||
//Console.WriteLine($"Complete\t{former.ContextName}\t->\t{after.ContextName}");
|
||||
formerCompleteSemaphore.Release();
|
||||
}
|
||||
|
||||
public void CompleteAndWriteData(BlueprintPipelineArgs args)
|
||||
{
|
||||
this.args = args;
|
||||
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
|
||||
//Console.WriteLine($"Complete\t{former.ContextName}\t->\t{after.ContextName}");
|
||||
formerCompleteSemaphore.Release();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace StgSharp.Logic
|
||||
|
||||
public void WaitForStart()
|
||||
{
|
||||
//Console.WriteLine($"Waiting \t{former.Name}\t->\t{after.Name}");
|
||||
//Console.WriteLine($"Waiting \t{former.ContextName}\t->\t{after.ContextName}");
|
||||
formerCompleteSemaphore.Wait();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,13 @@ namespace StgSharp
|
||||
{
|
||||
public class TimeFunction
|
||||
{
|
||||
|
||||
private float _beginning, _ending;
|
||||
private Func<float, float> _timeRelatedCalculation;
|
||||
private TimeSpanProvider _timeProvider;
|
||||
|
||||
internal TimeFunction() { }
|
||||
|
||||
public TimeFunction(
|
||||
TimeSpanProvider timeSpanProvider,
|
||||
Func<float, float> timeRelatedCalculation,
|
||||
@@ -55,13 +58,16 @@ namespace StgSharp
|
||||
_ending = _timeProvider.CurrentSecond + range;
|
||||
}
|
||||
|
||||
internal TimeFunction() { }
|
||||
|
||||
public bool IsComplete
|
||||
public virtual bool IsComplete
|
||||
{
|
||||
get => _timeProvider.CurrentSecond > _ending;
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public Func<float, float> TimeRelatedCalculation
|
||||
{
|
||||
get { return _timeRelatedCalculation; }
|
||||
@@ -74,7 +80,7 @@ namespace StgSharp
|
||||
set { _timeProvider = value; }
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
public virtual float Calculate()
|
||||
{
|
||||
if (_timeProvider.CurrentSecond < _ending)
|
||||
{
|
||||
@@ -83,64 +89,66 @@ namespace StgSharp
|
||||
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
public TimeFunction Renew(Func<float,float> func,float range)
|
||||
{
|
||||
return new TimeFunction(_timeProvider,func,range);
|
||||
}
|
||||
|
||||
public TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public static TimeFunction Proportional(TimeSpanProvider time,float begin, float range)
|
||||
public static TimeFunction Proportional(TimeSpanProvider time, float begin, float range)
|
||||
{
|
||||
return new TimeFunction(
|
||||
time, (float t) => t + begin, range
|
||||
);
|
||||
}
|
||||
|
||||
public virtual TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
|
||||
}
|
||||
|
||||
public virtual TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
return new TimeFunction(_timeProvider, func, range);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
_beginning = _timeProvider.CurrentSecond;
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class TimeFunctionOne : TimeFunction
|
||||
public sealed class TimeFunctionOne : TimeFunction
|
||||
{
|
||||
|
||||
internal TimeFunctionOne() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public new bool IsCompleted
|
||||
public override bool IsComplete
|
||||
{
|
||||
get => true;
|
||||
}
|
||||
|
||||
public new void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
public new TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public new TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public float Calculate()
|
||||
public override float Calculate()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override TimeFunction Renew((Func<float, float> func, float range) funcPair)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override TimeFunction Renew(Func<float, float> func, float range)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
#pragma warning disable CA1822
|
||||
public new void Reset()
|
||||
#pragma warning restore CA1822
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
public void ShowViewPort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Blueprint renderLogic;
|
||||
|
||||
public Blueprint RenderLogic
|
||||
{
|
||||
get => renderLogic;
|
||||
set => renderLogic = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init this form and render it on screen, and respond with operation
|
||||
/// </summary>
|
||||
public unsafe void Show()
|
||||
{
|
||||
while(0 == InternalIO.glfwWindowShouldClose(this.context.ViewPortID))
|
||||
{
|
||||
renderLogic.RunRepeatedly(() => ShouldClose);
|
||||
frameTimeProvider.WaitNextSpan();
|
||||
Interlocked.Add(ref _frameCount, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public T BuildNewRenderStream<T>(View arg, (int x, int y, int z) unitCubeSize) where T : RenderStream
|
||||
{
|
||||
if (arg.ContextName == this.Name)
|
||||
{
|
||||
|
||||
}
|
||||
T? ret = Activator.CreateInstance(typeof(T), arg) as T;
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
|
||||
}
|
||||
ret!.InternalInit();
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.GL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public partial class ViewModelBase
|
||||
{
|
||||
private List<View> allView;
|
||||
|
||||
public View BuildNewView(
|
||||
ViewPortDesigner designer, (int x, int y, int z) unitCubeSize
|
||||
)
|
||||
{
|
||||
View ret = new View(this.context, designer,unitCubeSize);
|
||||
allView.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T BuildRenderStream<T>(View v, (int, int, int) cube) where T : RenderStream
|
||||
{
|
||||
T ret = Activator.CreateInstance(typeof(T), v.Port, cube) as T ??
|
||||
throw new InvalidOperationException("Cannot build new render stream.");
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
ret.InternalInit();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewModel.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
|
||||
private int _frameCount;
|
||||
private int _frameSpeed;
|
||||
private ViewPort context;
|
||||
|
||||
internal IntPtr monitor;
|
||||
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected ViewModelBase(int frameSpeed)
|
||||
{
|
||||
context = new ViewPort();
|
||||
allView = new List<View>();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
};
|
||||
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
public ViewModelBase(ViewPort vbinding, int framespeed)
|
||||
{
|
||||
context = vbinding;
|
||||
allView = new List<View>();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
};
|
||||
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
|
||||
|
||||
public int FrameSpeed => _frameSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// Height of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get => context.Height;
|
||||
set { context.Height = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => context.Name;
|
||||
}
|
||||
|
||||
public bool ShouldClose
|
||||
{
|
||||
get => InternalIO.glfwWindowShouldClose(context.ViewPortID) != 0;
|
||||
set => InternalIO.glfwSetWindowShouldClose(context.ViewPortID, value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public vec2d Size
|
||||
{
|
||||
get => new vec2d(Width, Height);
|
||||
set
|
||||
{
|
||||
Width = (int)value.X;
|
||||
Height = (int)value.Y;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(context.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get => context.Width;
|
||||
set
|
||||
{
|
||||
context.Width = value;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(context.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe IntPtr WindowID
|
||||
{
|
||||
get => context.ViewPortID;
|
||||
}
|
||||
|
||||
|
||||
#pragma warning disable CA1044
|
||||
protected FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
|
||||
InternalIO.glfwSetFramebufferSizeCallback(context.ViewPortID, handlerPtr);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1044
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resize the current form
|
||||
/// </summary>
|
||||
/// <param name="size">
|
||||
/// A <see cref="vec2d"/> (width,height) representing the new size of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSize(vec2d size)
|
||||
{
|
||||
this.Size = size;
|
||||
InternalIO.glfwSetWindowSize(this.context.ViewPortID, (int)size.X, (int)size.Y);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minSize">
|
||||
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
/// <param name="maxSize">
|
||||
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(vec2d minSize, vec2d maxSize)
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(
|
||||
this.context.ViewPortID,
|
||||
(int)minSize.X,
|
||||
(int)minSize.Y,
|
||||
(int)maxSize.X,
|
||||
(int)maxSize.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minWidth">Minimum width of current form</param>
|
||||
/// <param name="minHeight">Minimum height of current form</param>
|
||||
/// <param name="maxWidth">Maximum width of current form</param>
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
//TODO 重做form的尺寸极限控制
|
||||
InternalIO.glfwSetWindowSizeLimits(this.context.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
#region Key Control
|
||||
|
||||
protected KeyStatus CheckKey(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Mouse key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID, (int)key);
|
||||
}
|
||||
|
||||
protected KeyStatus CheckKey(Joystick key)
|
||||
{
|
||||
return InternalIO.glfwGetKey(this.WindowID, (int)key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -108,7 +108,7 @@ namespace StgSharp.Graphics
|
||||
/// </summary>
|
||||
/// <param name="source">Shader program requires this camera.</param>
|
||||
/// <param name="uniformName">
|
||||
/// Name of all related uniforms.
|
||||
/// ContextName of all related uniforms.
|
||||
/// If you fallow form from <see cref="IglConvertable.DisplayGLtypeDefinition"/>
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
internal class Coordination
|
||||
{
|
||||
}
|
||||
|
||||
public enum CoordinatePlain
|
||||
{
|
||||
XY,
|
||||
|
||||
@@ -200,6 +200,18 @@ namespace StgSharp.Math
|
||||
return v;
|
||||
}
|
||||
|
||||
public unsafe vec2d XY
|
||||
{
|
||||
get => new vec2d(this.vec);
|
||||
set
|
||||
{
|
||||
fixed (Vector3* vptr = &v)
|
||||
{
|
||||
*(Vector2*)vptr = value.v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Vec3d
|
||||
|
||||
@@ -75,23 +75,23 @@ namespace StgSharp.Stg
|
||||
VertexBuffer vbo;
|
||||
ElementBuffer ebo;
|
||||
|
||||
public OneDimensionalCollisionTexture2D(RenderStreamConstructArgs args) : base(args)
|
||||
public OneDimensionalCollisionTexture2D(ViewPort args) : base(args,(1,1,1))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Collision TextureGL unit cannot share context with other render stream or set as mainstream of a form,{($"and cannot be inited by {typeof(RenderStreamConstructArgs).Name} as well.")}"
|
||||
$"Collision TextureGL unit cannot share context with other render stream or set as mainstream of a form," +
|
||||
$"and cannot be inited by {typeof(ViewPort).Name} as well."
|
||||
);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
public OneDimensionalCollisionTexture2D(Radius angleStride, string name) :
|
||||
#pragma warning restore CS8618
|
||||
base(new RenderStreamConstructArgs
|
||||
base( new ViewPort()
|
||||
{
|
||||
Height = 1,
|
||||
Width = (int)((new Radius(Scaler.Pi)) / angleStride),
|
||||
UnitCubeSize = (1, 1, 1),
|
||||
Name = name
|
||||
})
|
||||
Name = name,
|
||||
},(1, 1, 1))
|
||||
{
|
||||
InternalInit();
|
||||
}
|
||||
|
||||
@@ -11,17 +11,16 @@ namespace StgSharp.Stg.Touhou
|
||||
{
|
||||
|
||||
|
||||
|
||||
public static ViewModel BuildTouhouWorld()
|
||||
/*
|
||||
public static View BuildTouhouWorld()
|
||||
{
|
||||
|
||||
TouhouForm form = new TouhouForm();
|
||||
|
||||
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,5 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Touhou
|
||||
{
|
||||
public class TouhouForm:ViewModel
|
||||
{
|
||||
public TouhouForm():
|
||||
base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,10 +120,6 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
||||
</Target>
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5033a6d50b041e22258ab96cddca5dbf1fc55aac")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c0093f7b5c77291172cde7e3e38beabb126adf08")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user