OSMTrafficSim icon indicating copy to clipboard operation
OSMTrafficSim copied to clipboard

Any chance for an update to the newer API?

Open MostHated opened this issue 5 years ago • 11 comments

Hey there, Great work on this, it looks awesome. I was wondering if there was any possibility you might be updating this to the newer API? Some nice but also important changes have come, such as there is a hybrid renderer package, [inject] has been deprecated and replaced with a new better way of doing things, etc. I would definitely love to be able to look this over using the current API!

Thanks again for all the time and effort you put into this, it is greatly appreciated! -MH

MostHated avatar Feb 16 '19 02:02 MostHated

Thanks for your advice! I will take time upgrade the project.

maajor avatar Feb 16 '19 04:02 maajor

Thank you, that is very much appreciated! And again, great work. I hope to learn a lot from this. : D

MostHated avatar Feb 16 '19 18:02 MostHated

Hi! Already add unity.rendering.hybrid package and start to use RenderMesh. Replace [inject] with ComponentGroup and IJobProcessComponentData. Some document says that ComponentDataArray will be deprecated, but I did not find better alternatives, so I will leave it unchanged until I can find more explanation.

maajor avatar Feb 21 '19 15:02 maajor

Hey man, awesome news. Can't wait to give it a look over when I get home. I actually just literally came across some information on ComponentDataArray, too. Instead of that, it seems like you need to just use chunk iteration itself, which I believe ComponentDataArray was going under the hood, but also some other not-so-performant things. I saw some info on it here.

https://forum.unity.com/threads/how-to-iterate-through-all-chunks.624616/#post-4183453

Thanks again for taking the time out to go back through things. A few other systems in which I had looked at in the past seemed great, but the creators didn't care to make any adjustments after the initial commit or soon after, so I definitely appreciate it.

MostHated avatar Feb 21 '19 16:02 MostHated

Cool! Thanks for your information!

maajor avatar Feb 22 '19 01:02 maajor

hey maajor - great project - very cool use of ECS. I was reviewing your code and adapted your randomization stuff for my own project, but discovered that the randomizer was showing artifacts for lots of regular entities. I remembered another project I did with randomization for ECS that seems to give better random vals - i mention it because it might be interesting to you -

The trick is to create a single randomizer per thread, and then make sure to not throw it away after each use so its state is preserved:

There is a utility function

`

   public static NativeArray<Random> GetRandomizerPerThread()
    {
        var randomizers = new NativeArray<Random>(JobsUtility.MaxJobThreadCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
        for (int i = 0; i < JobsUtility.MaxJobThreadCount; i++)
        {
            randomizers[i] = new Random((uint)UnityEngine.Random.Range(int.MinValue, int.MaxValue));
        }

        return randomizers;
    }

`

This will be used by a member on your system:

private NativeArray<Random> _rngs; ... _rngs = Utility.GetRandomizerPerThread();

Pass this into your job struct, then, use this handy attribute to get the current thread id:

`

        [NativeSetThreadIndex]
        int threadId;

...

        var threadRandom = randomizers[threadId];

` just remember to reassign to the nativearray:

randomizers[threadId] = threadRandom; // preserve state

Maybe this is useful to you - anyway, thanks for your great example

ajaxlex avatar Mar 25 '19 19:03 ajaxlex

Hi ajaxlex! Thanks for your code, I'll take time investigate it!

maajor avatar Mar 31 '19 15:03 maajor

Hi, I found ECS APIs in 2019.1 are a lot different from 2018.3, I have upgraded to new version. and thanks @ajaxlex your approach is elegant, I have adopted your code in this project. Thank you very much.

maajor avatar Apr 27 '19 11:04 maajor

Hi, I found ECS APIs in 2019.1 are a lot different from 2018.3, I have upgraded to new version. and thanks @ajaxlex your approach is elegant, I have adopted your code in this project. Thank you very much.

i was trying to upgrade this to 2019.3 but was failing. i have learned a lot from this project and thank you for that but was wondering if you were going to upgrade it because i have failed

tredpro avatar Dec 30 '19 00:12 tredpro

Hi @tredpro I have upgrade it to 2019.3 as its official version is released, please have a look at if it works now.

maajor avatar Jan 31 '20 08:01 maajor

Add some upgrading note from 2019.1 to 2019.3

  1. OnCreateManager and OnDestroyManager is renamed to OnCreate and OnDestroy
  2. NativeMultiHashmap.Concurrent is renamed to NativeMultiHashmap.ParallelWritter
  3. IShareComponent need to extend IEquatable interface
  4. Use GetEntityQuery instead of EntityManager.CreateEntityQuery to create entity query

maajor avatar Jan 31 '20 08:01 maajor