Code Monkey home page Code Monkey logo

svelto.tasks's People

Contributors

blucky87 avatar favoyang avatar pranavsk avatar sebas77 avatar ujinjinjin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svelto.tasks's Issues

How to stop/reset running task

Hi!
This lib is really helpful and I am using it as core of my game components. I have a list of task to run but I cannot stop/reset/clear the current collection of task to run the another one.

the input is: SerialTaskCollection serialTasks (with a list of Itask)
then I run: TaskRunner.Instance.Run (serialTasks);
Now how to stop this long task to start new one ?

Please tell me how!

Duplicated calls inside a while without a `yield return null`

Hi, I have a weird little problem running a Coroutine that has a loop and a yield return new WaitForSeconds inside.
For some reason, if I don't include a yield return null the code inside the loop will be executed twice.

Unity version : 2017.1.2f1

Source code:

public class SimpleMono : MonoBehaviour
{
        private void Start()
        {
            TaskRunner.Instance.Run(TestTwice());
        }

        private IEnumerator TestTwice() 
        {
            Debug.Log("TestTwice Loop: start ");
            int counter = 0;

            while (true) 
            {
                Debug.Log("TestTwice Loop: Time " + Time.time + " C: " + counter);
                counter++;

                yield return new WaitForSeconds(1f);

                // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! 
                // Adding "yield return null"  a loop. 
                // Without this, after execute `yield return new WaitForSeconds` in the loop, everything is executed twice !!! 
                // yield return null;
                // ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !               
            }
        }
}

Output:

TestTwice Loop: start
TestTwice Loop: Time 0 C: 0
TestTwice Loop: Time 1.007233 C: 1
TestTwice Loop: Time 1.007233 C: 2
...

StackTrace of those repeated logs/calls.:

  1. Same Time Counter Value = 1

TestTwice Loop: Time 1.007233C: 1
UnityEngine.Debug:Log(Object)
Presentation.Temporal.FirstLoad.c__Iterator1:MoveNext() (at Assets/Scripts/Presentation/Temporal/FirstLoad/FirstLoadController.cs:88)
Svelto.Tasks.SerialTaskCollection:RunTasks() (at Assets/Plugins/Svelto/TaskRunner/SerialTaskCollection.cs:63)
Svelto.Tasks.SerialTaskCollection:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/SerialTaskCollection.cs:42)
Svelto.Tasks.Internal.CoroutineEx:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/CoroutineEx.cs:33)
Svelto.Tasks.Internal.PausableTask:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/PausableTask.cs:121)
Svelto.Tasks.Internal.c__Iterator0:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/Runners/UnityCoroutineRunner.cs:225)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

  1. Same Time Counter Value = 2

TestTwice Loop: Time 1.007233C: 2
UnityEngine.Debug:Log(Object)
Presentation.Temporal.FirstLoad.c__Iterator1:MoveNext() (at Assets/Scripts/Presentation/Temporal/FirstLoad/FirstLoadController.cs:88)
Svelto.Tasks.SerialTaskCollection:RunTasks() (at Assets/Plugins/Svelto/TaskRunner/SerialTaskCollection.cs:63)
Svelto.Tasks.SerialTaskCollection:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/SerialTaskCollection.cs:42)
Svelto.Tasks.Internal.CoroutineEx:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/CoroutineEx.cs:33)
Svelto.Tasks.Internal.PausableTask:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/PausableTask.cs:121)
Svelto.Tasks.MonoRunner:ExecuteFirstTaskStep(IPausableTask) (at Assets/Plugins/Svelto/TaskRunner/Runners/MonoRunner.cs:55)
Svelto.Tasks.MonoRunner:StartCoroutine(IPausableTask) (at Assets/Plugins/Svelto/TaskRunner/Runners/MonoRunner.cs:44)
Svelto.Tasks.Internal.c__Iterator0:MoveNext() (at Assets/Plugins/Svelto/TaskRunner/Runners/UnityCoroutineRunner.cs:226)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Thanks !

Unexpected mark stack overflow with MultiThreadedParallelTaskCollection

When I use MultiThreadedParallelTaskCollection Unity ends up using an excessive amount of memory and eventually I get the error: "Unexpected mark stack overflow." Am I missing something? I've boiled the code down to next to nothing and tried several different variations, but the result is always the same when MultiThreadedParallelTaskCollection is involved. It runs fine the first hundred times or so, but the memory usage is constantly growing. I've tried several different builds from Dec 1 back.

using System.Collections;
using Svelto.Tasks;
using UnityEngine;

public class Testing : MonoBehaviour
{

    private int counter;

    void Start()
    {
    }

    void Update()
    {
        
        if (counter > 50)
        {
            ParallelMultiThread().RunOnScheduler(StandardSchedulers.updateScheduler);
            counter = 0;
        }
        counter++;
    }

    public IEnumerator ParallelMultiThread()
    {
        yield return null;
        var parallelMultiThread = new MultiThreadedParallelTaskCollection();

        parallelMultiThread.Add(new SlowTask());
        parallelMultiThread.Add(new SlowTask());

        yield return parallelMultiThread;
        //parallelMultiThread.Complete();
    }
}

public class SlowTask : IEnumerator
{
    public object Current { get; private set; }

    public SlowTask()
    {
    }

    public bool MoveNext()
    {
        Debug.Log("Ran");
        return false;
    }

    public void Reset()
    { }
}

MultiThreadedParallelTaskCollection

Hi @sebas77 ,

This is what we discuss on twitter.

I am trying to simulate a slow parallel task, like the example above. I have a SlowTask that takes 1 second for its operation (using Thread.Sleep), so if I use MTPTC, I expect 2 slow tasks will take about 1 second because they are executed parallel, but it not.

Am I right about this?

Here the task:

using System.Collections;

public class SlowTask : IEnumerator
{
    readonly string name;

    public object Current { get; private set; }

    public SlowTask(string name)
    {
        this.name = name;
    }

    public bool MoveNext()
    {
        System.Threading.Thread.Sleep(1000);

        UnityEngine.Debug.Log(name);

        return false;
    }

    public void Reset()
    {
    }
}
using System.Collections;
using UnityEngine;
using Svelto.Tasks;

public class ParalelAndContinuationExample : MonoBehaviour
{
    void Start()
    {
        UnityEngine.Debug.Log("Processor Count : " + System.Environment.ProcessorCount);

        ParalelMultiThread("PMTC").Run();
        ParalelTask("PTC").Run();

        ParalelMultiThread("PMTC on MultiThread Scheduler").RunOnSchedule(StandardSchedulers.multiThreadScheduler);
        ParalelTask("PTC on MultiThread Scheduler").RunOnSchedule(StandardSchedulers.multiThreadScheduler);
    }

    private void OnDisable()
    {
        Svelto.Tasks.TaskRunner.Instance.StopAndCleanupAllDefaultSchedulerTasks();
    }

    IEnumerator ParalelMultiThread(string name)
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        var paralelMultiThread = new MultiThreadedParallelTaskCollection();

        paralelMultiThread.Add(new SlowTask(name + " Task 1"));
        paralelMultiThread.Add(new SlowTask(name + " Task 2"));

        yield return paralelMultiThread;

        sw.Stop();

        UnityEngine.Debug.Log(name + " Finish : " + sw.ElapsedMilliseconds + " ms");

    }

    IEnumerator ParalelTask(string name)
    {
        var sw = System.Diagnostics.Stopwatch.StartNew();

        var paralelTask = new ParallelTaskCollection();

        paralelTask.Add(new SlowTask(name + " Task 1"));
        paralelTask.Add(new SlowTask(name + " Task 2"));

        yield return paralelTask;

        sw.Stop();

        UnityEngine.Debug.Log(name + " Finish : " + sw.ElapsedMilliseconds + " ms");
    }
}

The result:

Processor Count : 4
PTC Finish : 2007 ms
PMTC Finish : 2036 ms
PTC on MultiThread Scheduler Finish : 2008 ms
PMTC on MultiThread Scheduler Finish : 2011 ms

TaskRunner scene crashes in Unity 5.4.2p4

When opening TaskRunner scene in 5.4.2p4, scene hierarchy shows only InGameFrameTimer, rest of the objects in hierarchy have no text.

Unity reports around 87 errors like:
"CheckConsistency: GameObject does not reference component MonoBehaviour. Fixing."
or
"GameObject has multiple Transform components! Merged into single one."
or
"Object GameObject (named '') has multiple entries of the same Object component. Removing it!"

When run, scene crashes whole Unity.

too many threads error,

if you :
for (int j = 0; j < 8000; j++)
{
pt.Add(new LoadSomething(new WWW("www.google.com")));
}
will use
TaskRunner.Instance.AllocateNewTaskRoutine().SetScheduler(_MTRunner).SetEnumerator(pt).Start();
, running unity3d crash;
maybe need limit one time run thread count, this will perfect;

InvalidCastException: Specified cast is not valid.

I just remove the namespace of class "ExampleParallelTasksManagedMT",and modify the name of class "LoadSomething" to "LoadSomething2" ,and construction method also. When i run the demo,i got the error "Specified cast is not valid.".What should i do to solve this problem?Thank you very much for taking time to look at this problem.

image

image

image

error

Svelto.Tasks not functional in UWP Build (Hololens)

I was trying to embed the taskrunner in an UWP application with Unity 5.5.0f3 (64bit) to have it running on Hololens. Unfortunately the somewhat castrated .NET framework used for UWP causes some errors. I wonder if you can somehow work around that (probably by adding a flag that deactivates some of the features for UWP but keeps the main functionality). Here's the error log:


-----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp.dll
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.

Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(23,1): error CS0246: The type or namespace name 'ISerializable' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,7): error CS0246: The type or namespace name 'ISerializable' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs(90,199): error CS0246: The type or namespace name 'RunnerBehaviour' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs(181,25): error CS0246: The type or namespace name 'RunnerBehaviour' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,35): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,7): error CS0538: 'ISerializable' in explicit interface declaration is not an interface
Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(64,32): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs(5,50): error CS0305: Using the generic type 'ParallelTaskCollection' requires 1 type arguments
Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs(19,33): error CS0115: 'ParallelTaskCollection.CheckForToken(object)': no suitable method found to override
Assets\Scripts\Svelto\TaskRunner\TaskYieldsIEnumerableException.cs(21,50): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
Assets\Scripts\Svelto\DataStructures\WeakReference.cs(54,33): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
-----CompilerOutput:-stderr----------
-----EndCompilerOutput---------------

  • Finished compile Library/ScriptAssemblies/Assembly-CSharp.dll
    Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(23,1): error CS0246: The type or namespace name 'ISerializable' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs Line: 23)

Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,7): error CS0246: The type or namespace name 'ISerializable' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs Line: 76)

Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs(90,199): error CS0246: The type or namespace name 'RunnerBehaviour' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs Line: 90)

Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs(181,25): error CS0246: The type or namespace name 'RunnerBehaviour' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\TaskRunner\MonoRunner.cs Line: 181)

Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,35): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs Line: 76)

Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(76,7): error CS0538: 'ISerializable' in explicit interface declaration is not an interface

(Filename: Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs Line: 76)

Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs(64,32): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\DataStructures\SerializableDictionary.cs Line: 64)

Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs(5,50): error CS0305: Using the generic type 'ParallelTaskCollection' requires 1 type arguments

(Filename: Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs Line: 5)

Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs(19,33): error CS0115: 'ParallelTaskCollection.CheckForToken(object)': no suitable method found to override

(Filename: Assets\Scripts\Svelto\TaskRunner\Experimental\ParallelTaskCollection.cs Line: 19)

Assets\Scripts\Svelto\TaskRunner\TaskYieldsIEnumerableException.cs(21,50): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\TaskRunner\TaskYieldsIEnumerableException.cs Line: 21)

Assets\Scripts\Svelto\DataStructures\WeakReference.cs(54,33): error CS0246: The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)

(Filename: Assets\Scripts\Svelto\DataStructures\WeakReference.cs Line: 54)

DisplayProgressNotification: Build Failed
Error building Player because scripts had compiler errors

(Filename: Line: -1)


Gizmos Scheduler

In our project, we are using Svelto.ECS and split Client and Server into different project, both using Unity Engine, Client with UI/Sprite/Mesh, Server without UI/Sprite/Mesh. So for server development, we used gizmos for testing.

For example, we have TroopEntity and TowerEntity, both have detector for detecting enemy in certain radius. So we created :

  • PositionGizmosEngine for drawing position gizmos, which handle PositionGizmosEntity (extend EntityView)
  • EnemyDetectorGizmosEngine for drawing detection radius gizmos, which handle EnemyDetectorGizmosEntity (extend EntityView).

This is very useful for our development process.

I had asked you about gizmos before, but I am still thinking we need it. We need to drawing gizmos using ecs pattern, and our Svelto.ECS need this scheduler to draw gizmos.

This is what we made to handle gizmos. What do you think about integrate it in Svelto.Tasks?
leopripos/Svelto.Tasks/tree/unity-gizmos-scheduler/Svelto.Tasks/Runners/Unity/Gizmos

*sorry about my english :)

when i open in unity2018 has some code error

1.Assets\Svelto.Tasks\Svelto.Tasks\Collections\TaskCollection.cs(91,31): error CS0411: The type arguments for method 'FasterList<TaskCollection.StructFriendlyStack>.ReuseOneSlot()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
2.Assets\Svelto.Tasks\Svelto.Tasks\Collections\TaskCollection.cs(96,31): error CS1061: 'FasterList<TaskCollection.StructFriendlyStack>' does not contain a definition for 'AddRef' and no accessible extension method 'AddRef' accepting a first argument of type 'FasterList<TaskCollection.StructFriendlyStack>' could be found (are you missing a using directive or an assembly reference?)
how to fix it?

Behaviour of Parallel Task Collection

Has been brought to my attention that the PTC should not behave as it does now, as now it runs one iteration of the task in "parallel" but just one per frame, while instead it should do one iteration over all the tasks added on the same frame.

thoughts?

Restructuring Directory

Hello @sebas77,

What do you think about restructuring the directory so we can use Svelto.Tasks as submodule (git submodule) like Svelto.ECS.

My idea is moving all file from ./Assets/Scripts/Svelto/TaskRunner to root of repository.

What is possible or not in Svelto.Tasks ?

Im just diving in to the convoluted world of tasks and threads and im really frustrated of all the limitations and (probably necessary) safety precautions of paralell processing.
I have but one simple problem : i want to push webcamtexture processing to the background thread and recover vector3 array back to the main thread to use it for something fancy.
The thing is that i have no idea if in Svelto.Tasks i have to convert the wecamtex to Color32 array or byte array and then convert it back to process it with external library for cv. Also i have no idea if this will speed the performace up or not.

OneSecondRunner

Hey,

I updated to the last version and noticed that in StandardSchedulers was missing so easy to use StandardSchedulers.oneSecondScheduler
(IEnumerator).RunOnSchedule(StandardSchedulers.oneSecondScheduler);
There are in my project so many oneSecondScheduler before updating.

So what is the best way to take a 1-second Schedule without doing anything special?

Tasks with ecs

Hello,

the current versions of ecs and tasks cannot be used together.
The common sources differ. Is there a work around for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.