Comments (19)
So just some quick stuff:
Currently there is only 2 Compile
which are important (Serialization can be ignored for now)
(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.
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.
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.
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.
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.
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.
Solution you have found helps with reflection, but not with compilation.
from defaultecs.
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.
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.
So this is a deal-breaker for DefaultECS on mobile?
from defaultecs.
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.
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.
For code gen, I know these:
-
https://github.com/ltrzesniewski/InlineIL.Fody https://gist.github.com/dadhi/604d82b884b76b30095d05cce79bf525
-
And https://github.com/dotnet/orleans has nice Roslyn Code Gen
from defaultecs.
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.
I am using it with Unity. Or at least, trying to. :)
from defaultecs.
@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.
@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.
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.
Tested on Unity 2020.2.3f1 with version DefaultEcs 0.15.1, Windows platform with IL2CPP runtime.
from defaultecs.
Related Issues (20)
- Disabled entities still publish ComponentChangedMessage HOT 5
- System.Reflection.Emit-using code causes Unity3D IL2CPP compilation fail HOT 3
- Removing a component seems to modify Entity parameter HOT 4
- Second rules query returns same entities as previous query HOT 2
- ComponentAddedHandler or ComponentChangedHandler are not called for Components of the world HOT 1
- Cannot create EntitySet with both WhenAdded and WhenRemoved HOT 2
- Calling Has<T> after Dispose HOT 3
- TextSerializer is not culture invariant HOT 1
- Disposing an entity currently being processed by an AEntitySetSystem HOT 2
- A non generic ISystem HOT 3
- Issue when disposing an entity from Update(TState state, in Entity entity) HOT 2
- WhenAdded / WhenChanged not updating for World component HOT 1
- Some issues of framework HOT 4
- Setting new value of shared component disconnects sharing HOT 3
- How to use Hierarchy and Child extension. HOT 1
- Make EntityRecord and WorldRecord implement all interfaces of Entity and World
- EntityCommandRecorder sets components on entity after it is disposed
- World Names
- Is it ok to use list in component?
- Sometimes when creating a new entity, the components on a previously disposed entity with the same ID are still present HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defaultecs.