I saw at the Wiki where there's two releases, one just for C# and one for with unity stuff. I was wondering if the C# stuff could be used outside of Unity, so I was trying to integrate it into MonoGame. Although I ran into a problem where it seemed intuitive in Unity, the code generation is triggered by clicking on generate. How would i be able to do something similar in say Mono Game?
Hi,
yes Entitas also works without Unity. Here's an example on how you can use the code generator outside of Unity
https://github.com/sschmid/Entitas-CSharp/blob/develop/Entitas.CodeGenerator/Program.cs
You have to make sure to add the generated files to your project, but I guess you can automate this, too.
Hey, I updated the wiki and added a new page
"Install Entitas and first steps"
https://github.com/sschmid/Entitas-CSharp/wiki/Install-Entitas-and-first-steps
That might help
Hi. I'm new here too. I don't see how this gets my own component into the system. I created a new console project, added the generation/entitas code in it, I call your generation code from the wiki yet the generated types do not have my PositionComponent listed. What do I need to do exactly to hook all this up?
When you generate new files be created. The code generator doesn't add them to the *.csproj file. This means your IDE is not aware of those files. Try to add sth like this to your *.csproj file
<ItemGroup>
<Compile Include="path/to/generated/folder/**" />
</ItemGroup>
If that doesn't work we should try to find a way to automatically add those generated files to the project. We figured out a way with roslyn for windows already, but it doesn't work on mac yet.
My generated output folder does not have any code related to my component class I made. It just has pool classes.
My component class in my generator project
namespace EntitasCodeGeneration
{
public class PositionComponent :IComponent
{
public int X;
public int Y;
public int Z;
}
}
If I use your sample code. This does not cause my component to suddenly be generated
Generator project (which has the component class in it)
static void Main(string[] args)
{
Console.WriteLine("Building SadConsole entities");
// All code generators that should be used
var codeGenerators = new ICodeGenerator[] {
new ComponentIndicesGenerator(),
new ComponentExtensionsGenerator(),
new PoolAttributesGenerator(),
new PoolsGenerator(),
new BlueprintsGenerator()
};
// Specify all pools
var poolNames = new[] { "Core" };
// Specify all blueprints
var blueprintNames = new string[0];
var assembly = Assembly.GetAssembly(typeof(SadConsole.Game.Entitas.Entity)); // I compiled entitas into a library which I reference in this project.
var provider = new TypeReflectionProvider(assembly.GetTypes(), poolNames, blueprintNames);
const string path = "./Generated/";
var files = CodeGenerator.Generate(provider, path, codeGenerators);
foreach (var file in files)
{
Console.WriteLine(file.generatorName + ": " + file.fileName);
}
Console.WriteLine("Done. Press any key...");
Console.Read();
}
I looked a bit more into it and I figured out why it doesn't generate anything for me. I changed the namespace of all the entitas code and you do a type.fullname == "Entitas.xxxx" check on things 馃槥 How come the code generator doesn't do a type == typeof(Entitas.xxx) instead?
I plan to provide the code generator as an executable in the future. As a first step it was necessary to check for the type with string comparison, since the executable doesn't contain Entitas.IComponent etc. I want to move the code generator to a separate project since the ultimate master plan is to offer a roslyn based code generator (or to basically enable any kind of source parsing, e.g. reflection, roslyn, json or etc)
That sounds awesome. Especially because people could generate into other languages. I still voice my opinion for a good example of a non-unity project as an example though :)
One thing you _could_ do is have a init system where the consumer provides all the types you know the generator needs.
I'd love a straight C#/Monogame example as well. I can't get this working. It generates the files, and those files show up in my project, but the component list has zero components and none of their code is generated. Generating code in Unity worked fine for me.
Is there something I'm missing or should I wait for the executable generator?
I'll have to check. So far I used Entitas mainly with Unity, but I like to keep it working for c# only projects, too.
Just want to add support for a nice MonoGame example. I'm having the same problem as others where no component code is actually generated. I'm excited to try this, but unable to proceed. Thanks for any help you can provide.
@mike991166 It may be the difference in methodology. It seems that you don't create an "entitas.dll" library and reference that. You include the entire code base in your game project. I have two projects:
Both projects have the entire entitas code base. The generation project includes my component files from my main project. When the generation project runs, it outputs the generated files into a folder for my main project. Then back in my main project I exclude the "generated" folder and include it again to pick up all the new files.
Thanks, that did it.
@mike991166 I just wanted to comment that I played around with this for a while and I find it very hard to use in a non-unity project. I've now started to test thelinuxlich/artemis_CSharp and it seems to play really nice with MonoGame. The tutorial website is simple and gets you started. However, there is also a sample MonoGame game where you can explore a full implementation of it.
So far I really like it, however, I really, really, love the entitas way building out the entity to have the components built in and miss that.
I updated the wiki Install-Entitas-and-first-steps.
I created a simple C# project for you with the code generator already set up.
This should help getting started.
https://github.com/sschmid/EntitasPure
Have fun! :)