Giter VIP home page Giter VIP logo

Comments (19)

Doraku avatar Doraku commented on May 10, 2024 2

So just some quick stuff:
Currently there is only 2 Compile which are important (Serialization can be ignored for now)

filter = Expression.Lambda<Predicate<ComponentEnum>>(filterEx, components).Compile();

return Expression.Lambda<Func<World, EntitySetBuilder>>(expression, world).Compile();

(side note, quite funny that they are on the same line number :o)

The first one can be easily converted to a lambda for probably the same performance (with some repetition and ugliness to handle the different cases, variables are withoutFilter, withEitherFilter and withoutEitherFilter so 8 possible checks).
Second one can be converted to slow reflection Invoke, or fallback to constructor definition of the Entity instead of using attributes.

I believe I have read somewhere that a property or something was added to know at runtime if code generation was available or not (instead of hopefully calling Compile and checking the return/catching an exception) but I can't seem to find it.

Anyway theoretically with those changes and the preservation of code for reflection DefaultEcs should work in AoT/iOS settings. Not sure for IL2CPP as I am not well versed in Unity (is reflection allowed? from a quick search it seems so?) but being compatible with Unity would be a big plus for sure.

This would really just be a quick win while waiting for a full code generation at compile time solution using fody/roslyn, and for people who do not want to deal with extra tools in the build chain.

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024 1

The first one can be easily converted to a lambda for probably the same performance (with some repetition and ugliness to handle the different cases, variables are withoutFilter, withEitherFilter and withoutEitherFilter so 8 possible checks).

This is the way frameworks are written :)

Second one can be converted to slow reflection Invoke, or fallback to constructor definition of the Entity instead of using attributes.

Can do both? Could create items for Fody or Roslyn generation either.

I believe I have read somewhere that a property or something was added to know at runtime if code generation was available or not (instead of hopefully calling Compile and checking the return/catching an exception) but I can't seem to find it.

Have heard same, do not recall name. So you may use exception with TODO to get that handled by others.

Anyway theoretically with those changes and the preservation of code for reflection DefaultEcs should work in AoT/iOS settings. Not sure for IL2CPP as I am not well versed in Unity (is reflection allowed? from a quick search it seems so?) but being compatible with Unity would be a big plus for sure.

People will send you example or pull with link.xml to prevent AOT code stripping, but that is fine - usual process. Unity is .NET Standard 2.0 and will be 2.1. But no Compile or Emit. Unity has HUGE game market share. Design of your ECS seems novel(at least for C#) - uses modern C# features.

This would really just be a quick win while waiting for a full code generation at compile time solution using fody/roslyn, and for people who do not want to deal with extra tools in the build chain.

Yep.

from defaultecs.

shimkovich avatar shimkovich commented on May 10, 2024 1

As was mentioned google already restricts build to necessarily support 64bit archs what forces to use IL2CPP for me. I can check il2cpp demo build and see if there still any issues.
Defenetely want to give a try to the framework.

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

Same for other place of Compile usage.

Consider maxing out using generics and types, like type policy pattern and build stuff from delegates. Or split AOT vs non AOT code. Unity for iOS is no way for now without AOT.

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

If I am not mistaken, the reason it might have trouble with AoT compilation is because of the code stripping that goes with it. I guess it should be possible to add a config file so AoT compilation will not remove any code from this dll? Looking around quickly I found this, could this be a solution?

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

Main reason that secure platforms (like iOS) do not allow JIT. Also they may prevent this because of start up time and batter consumption. So event for Android people do AOT. So call to Compile will fail to work as there is no possibility to create new executable code while program is running. I.e. ECS is not usable by most of mobile games.

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

Solution you have found helps with reflection, but not with compilation.

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

Entitas does work on AOT.
So I guess some Compile can be replaced with generic delegates combination and builder somewhere. Or doing Roslyn codegen.

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

Hum I see. It should be possible to replace this runtime code generation by static code with some checks but not everywhere. Roslyn codegen might be a good replacement. I will try to look more into that when I am back from my holidays.

from defaultecs.

logixworx avatar logixworx commented on May 10, 2024

So this is a deal-breaker for DefaultECS on mobile?

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

At least it works on Android as it is my target but I haven't tested it on ios yet (nor windows phone if that's your thing though).

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

Compile compiles code. On iOS as as far as I know you cannot create executable data regions during run time.

Compile can do interpretation, but it is slow and buggy (better write code manually and use cached reflection). Interpretation may require use third party lib either.

On Android Unity IL2CPP Compile does not work either even if Android does not preclude run time code gen. IL2CPP(not mono) is for performance. And probably something related to new Google guidelines or new CPU archs.

from defaultecs.

dzmitry-lahoda avatar dzmitry-lahoda commented on May 10, 2024

For code gen, I know these:

  1. https://github.com/ltrzesniewski/InlineIL.Fody https://gist.github.com/dadhi/604d82b884b76b30095d05cce79bf525

  2. And https://github.com/dotnet/orleans has nice Roslyn Code Gen

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

So the first has been taken care of, for the same performance (but more code obviously). Hopefully with the new switch syntax and pattern matching it can be ironed out a little. I still need to do some benchmarks.

But I am having conflicting reading on the second one. From what I get reflection to invoke generic methods should work correctly if the code is not trimmed but for IL2CPP I think it's not enough (something about only working for reference generic type parameter for now?)? Then again isn't there some directive for unity to keep the code as c#? After all the is just for the initialisation, not the hot path.

from defaultecs.

logixworx avatar logixworx commented on May 10, 2024

I am using it with Unity. Or at least, trying to. :)

from defaultecs.

arakon5 avatar arakon5 commented on May 10, 2024

@shimkovich , I was just wondering if you had any results from an il2cpp build? I'm interested in this framework as well, and would be targeting Unity also. Thanks

from defaultecs.

shimkovich avatar shimkovich commented on May 10, 2024

@arakon5 Sorry, I deffered the project related to the framework, though I still interested in it, maybe @logixworx tried it out with il2cpp.

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

I might install Unity to check it since this question has been open for so long haha even if I have no clue how to use it.
From what I gathered

  • DefaultEcs.Serialization will not work because of runtime code generation
  • DefaultEcs.Command will not work because of reflection to check for unmanged type Set command (I will have to see what can be done here)
  • DefaultEcs.System attribute to auto generate the EntitySet in AEntitySystem (WithAttribute, WithoutAttribute, ...) will not work because of reflection use in EntitySetBuilderExtension (but you can force code generation at compile by having EntitySetBuilder.With<> ... explicit call for all the component types you want to use I guess?), building EntitySet yourself should work with the latest preview package since I removed reflection from there
  • everything else should work, Unity is supposed to be compatible with c#7.3

from defaultecs.

Doraku avatar Doraku commented on May 10, 2024

Tested on Unity 2020.2.3f1 with version DefaultEcs 0.15.1, Windows platform with IL2CPP runtime.

from defaultecs.

Related Issues (20)

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.