Skip to content

Commit

Permalink
解决了js读取模块问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZyndaDeng committed Nov 10, 2021
1 parent fb0d8fe commit 60d6b13
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 396 deletions.
35 changes: 18 additions & 17 deletions sources/engine/Stride.ClearScript/ClearScriptSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Initialize()
engine.DocumentSettings.Loader = loader;
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;

engine.AddHostType("Console", typeof(Console));
engine.AddHostType("MSConsole", typeof(Console));
}

public object Execute()
Expand All @@ -70,11 +70,12 @@ public async Task loadFile(string fileName)
try
{
string source = await streamReader.ReadToEndAsync();
var path = Path.GetDirectoryName(fileName)+Path.DirectorySeparatorChar;
var doc = new DocumentInfo(new Uri(@"\\js"+path));

var script= engine.Evaluate(new DocumentInfo (){
Category = ModuleCategory.Standard
}, source);
Console.WriteLine("------javascript c={0}", script.c);
doc.Category = ModuleCategory.Standard;
var script = engine.Evaluate(doc, source);
// Console.WriteLine("------javascript c={0}", script.c);
}catch(Exception e)
{
Console.WriteLine(e.Message);
Expand All @@ -83,19 +84,19 @@ public async Task loadFile(string fileName)
}
}

public object CreatePromiseForTask<T>(Task<T> task)
{
return engine.CreatePromiseForTask(task);
}
//public object CreatePromiseForTask<T>(Task<T> task)
//{
// return engine.CreatePromiseForTask(task);
//}

public object CreatePromiseForTask(Task task)
{
return engine.CreatePromiseForTask(task);
}
//public object CreatePromiseForTask(Task task)
//{
// return engine.CreatePromiseForTask(task);
//}

public Task<object> CreateTaskForPromise(object promise)
{
return engine.CreateTaskForPromise(promise);
}
//public Task<object> CreateTaskForPromise(object promise)
//{
// return engine.CreateTaskForPromise(promise);
//}
}
}
186 changes: 95 additions & 91 deletions sources/engine/Stride.ClearScript/Components/ClearScriptComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ namespace Stride.ClearScript
[AllowMultipleComponents]
[ComponentOrder(1000)]
[ComponentCategory("ClearScripts")]
public class ClearScriptComponent: EntityComponent, ICollectorHolder
{
public const uint LiveScriptingMask = 128;
public class ClearScriptComponent : EntityComponent, ICollectorHolder
{
public const uint LiveScriptingMask = 128;

/// <summary>
/// The global profiling key for scripts. Activate/deactivate this key to activate/deactivate profiling for all your scripts.
/// </summary>
public static readonly ProfilingKey ScriptGlobalProfilingKey = new ProfilingKey("Script");
/// <summary>
/// The global profiling key for scripts. Activate/deactivate this key to activate/deactivate profiling for all your scripts.
/// </summary>
public static readonly ProfilingKey ScriptGlobalProfilingKey = new ProfilingKey("Script");

private static readonly Dictionary<Type, ProfilingKey> ScriptToProfilingKey = new Dictionary<Type, ProfilingKey>();
private static readonly Dictionary<Type, ProfilingKey> ScriptToProfilingKey = new Dictionary<Type, ProfilingKey>();

private ProfilingKey profilingKey;
private ProfilingKey profilingKey;

//private IGraphicsDeviceService graphicsDeviceService;
private Logger logger;
//private IGraphicsDeviceService graphicsDeviceService;
private Logger logger;

private dynamic scriptObj;

protected ClearScriptComponent()
{
}
protected ClearScriptComponent()
{

}

internal void Initialize(IServiceRegistry registry)
{
Expand Down Expand Up @@ -80,120 +80,124 @@ internal void Initialize(IServiceRegistry registry)
};
scriptObj.Initialize(args);
}
catch(Exception e)
catch (Exception e)
{

}
}

}

protected Entity entity;
public Entity Entity { get=>entity; internal set {
public Entity Entity
{
get => entity; internal set
{
entity = value;
scriptObj.Entity = value;
} }
}
}

/// <summary>
/// Gets the profiling key to activate/deactivate profiling for the current script class.
/// </summary>
[DataMemberIgnore]
public ProfilingKey ProfilingKey
{
get
public ProfilingKey ProfilingKey
{
if (profilingKey != null)
return profilingKey;

var scriptType = GetType();
if (!ScriptToProfilingKey.TryGetValue(scriptType, out profilingKey))
get
{
profilingKey = new ProfilingKey(ScriptGlobalProfilingKey, scriptType.FullName);
ScriptToProfilingKey[scriptType] = profilingKey;
}
if (profilingKey != null)
return profilingKey;

return profilingKey;
var scriptType = GetType();
if (!ScriptToProfilingKey.TryGetValue(scriptType, out profilingKey))
{
profilingKey = new ProfilingKey(ScriptGlobalProfilingKey, scriptType.FullName);
ScriptToProfilingKey[scriptType] = profilingKey;
}

return profilingKey;
}
}
}



/// <summary>
/// Gets the streaming system.
/// </summary>
/// <value>The streaming system.</value>
[DataMemberIgnore]
public StreamingManager Streaming { get; private set; }

/// <summary>
/// Gets the streaming system.
/// </summary>
/// <value>The streaming system.</value>
[DataMemberIgnore]
public StreamingManager Streaming { get; private set; }

[DataMemberIgnore]
public IClearScriptSystem ScriptSystem { get; private set; }

[DataMemberIgnore]
protected Logger Log
{
get
protected Logger Log
{
if (logger != null)
get
{
if (logger != null)
{
return logger;
}

var className = GetType().FullName;
logger = GlobalLogger.GetLogger(className);
return logger;
}

var className = GetType().FullName;
logger = GlobalLogger.GetLogger(className);
return logger;
}
}

private int priority;
private int priority;

/// <summary>
/// The priority this script will be scheduled with (compared to other scripts).
/// </summary>
/// <userdoc>The execution priority for this script. It applies to async, sync and startup scripts. Lower values mean earlier execution.</userdoc>
[DefaultValue(0)]
[DataMember(10000)]
public int Priority
{
get { return priority; }
set { priority = value; PriorityUpdated(); }
}
/// <summary>
/// The priority this script will be scheduled with (compared to other scripts).
/// </summary>
/// <userdoc>The execution priority for this script. It applies to async, sync and startup scripts. Lower values mean earlier execution.</userdoc>
[DefaultValue(0)]
[DataMember(10000)]
public int Priority
{
get { return priority; }
set { priority = value; PriorityUpdated(); }
}

/// <summary>
/// Determines whether the script is currently undergoing live reloading.
/// </summary>
public bool IsLiveReloading { get; internal set; }
/// <summary>
/// Determines whether the script is currently undergoing live reloading.
/// </summary>
public bool IsLiveReloading { get; internal set; }

/// <summary>
/// The object collector associated with this script.
/// </summary>
[DataMemberIgnore]
public ObjectCollector Collector
{
get
/// <summary>
/// The object collector associated with this script.
/// </summary>
[DataMemberIgnore]
public ObjectCollector Collector
{
collector.EnsureValid();
return collector;
get
{
collector.EnsureValid();
return collector;
}
}
}

private ObjectCollector collector;
private ObjectCollector collector;



/// <summary>
/// Called when the script's update loop is canceled.
/// </summary>
public void Cancel()
{
scriptObj.Cancel();
collector.Dispose();
}

public void Start()
/// <summary>
/// Called when the script's update loop is canceled.
/// </summary>
public void Cancel()
{
scriptObj.Cancel();
collector.Dispose();
}

public void Start()
{
scriptObj.Start();
}

internal PriorityQueueNode<SchedulerEntry> UpdateSchedulerNode;
// internal PriorityQueueNode<SchedulerEntry> UpdateSchedulerNode;

public bool hasProperty(string propertyName)
{
Expand All @@ -204,7 +208,7 @@ public bool hasProperty(string propertyName)
/// <summary>
/// Called every frame.
/// </summary>
public void Update()
public void Update()
{
scriptObj.Update();
}
Expand All @@ -224,10 +228,10 @@ public void Update()
/// Called once, as a microthread
/// </summary>
/// <returns></returns>
public Task Execute()
{
//public Task Execute()
//{

}
//}

protected internal void PriorityUpdated()
{
Expand Down
Loading

0 comments on commit 60d6b13

Please sign in to comment.