Browse Source

add thread

master
jkpete 2 months ago
parent
commit
afe372f849
  1. 17
      Example/UsingTest/Script/EGSaveTest.cs
  2. 9
      addons/EGFramework/EGFramework.cs
  3. 21
      addons/EGFramework/License_Third_Part/QFramework/LICENSE
  4. 48
      addons/EGFramework/Module/NodeExtension/EGThread.cs
  5. 2
      addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs

17
Example/UsingTest/Script/EGSaveTest.cs

@ -1,15 +1,28 @@ @@ -1,15 +1,28 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
using LiteDB;
namespace EGFramework.Examples.Test{
public partial class EGSaveTest : Node,IEGFramework
{
public Label Label { set; get; }
public override void _Ready()
{
base._Ready();
TestCode();
this.Label = this.GetNode<Label>("Label");
this.EGEnabledThread();
TestThread();
//base._Ready();
//TestCode();
}
public async void TestThread(){
await Task.Run(()=>{
this.ExecuteInMainThread(()=>{
this.Label.Text = "Thread Test";
});
});
}
public void TestSqlite(){

9
addons/EGFramework/EGFramework.cs

@ -165,19 +165,16 @@ namespace EGFramework @@ -165,19 +165,16 @@ namespace EGFramework
public struct CustomUnRegister : IUnRegister
{
/// <summary>
/// 委托对象
/// delegate object
/// </summary>
private Action OnUnRegister { get; set; }
/// <summary>
/// 带参构造函数
/// </summary>
/// <param name="onDispose"></param>
public CustomUnRegister(Action onUnRegister)
{
OnUnRegister = onUnRegister;
}
/// <summary>
/// 资源释放
/// release by parent;
/// </summary>
public void UnRegister()
{

21
addons/EGFramework/License_Third_Part/QFramework/LICENSE

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 凉鞋
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.

48
addons/EGFramework/Module/NodeExtension/EGThread.cs

@ -1,26 +1,68 @@ @@ -1,26 +1,68 @@
using Godot;
using static Godot.GD;
using System;
using System.Collections.Generic;
namespace EGFramework{
public partial class EGThread : Node{
public partial class EGThread : Node,IModule,IEGFramework{
public Queue<Action> ActionQueue = new Queue<Action>();
public IOCContainer ActionPool = new IOCContainer();
public void Init()
{
}
public override void _Ready()
{
base._Ready();
}
public override void _Process(double delta)
{
base._Process(delta);
//base._Process(delta);
if(ActionQueue.Count>0){
Action execute = ActionQueue.Dequeue();
execute.Invoke();
execute = null;
}
}
public void ExecuteInMainThread(Action action){
ActionQueue.Enqueue(action);
}
public void ExecuteInMainThread<T>(Action<T> action){
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGThreadExtension
{
public static void ExecuteInMainThread(this Node self, Action action){
//action.Invoke();
self.NodeModule<EGThread>().ExecuteInMainThread(action);
}
public static void ExecuteInMainThread<T>(this Node self, Action<T> action){
//action.Invoke();
}
public static void ExecuteAfterSecond(this Node self, Action action,float delay){
}
public static void ExecuteAfterSecond<T>(this Node self, Action<T> action,float delay){
}
public static void EGEnabledThread(this Node self){
self.NodeModule<EGThread>();
}
}
}

2
addons/EGFramework/Module/ProtocolTools/EGHttpServer.cs

@ -64,7 +64,7 @@ namespace EGFramework{ @@ -64,7 +64,7 @@ namespace EGFramework{
Dictionary<string,string> getDic = data.AllKeys.ToDictionary(k=>k,k=>data[k]);
string getData = JsonConvert.SerializeObject(getDic);
byte[] getBuffer = StringEncoding.GetBytes(getData);
responseKey = "GET:"+this.GetTimeStamp().ToString();
responseKey = "GET:"+this.GetDateTime().ToString();
receivedMsgs = new ResponseMsg(getData,getBuffer,responseKey, ProtocolType.HttpServer);
//GD.Print("Received from "+receivedMsgs.sender+": "+receivedMsgs.stringData);
}

Loading…
Cancel
Save