question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Making it easier to work under multiple contexts

See original GitHub issue

Hi,

One of the annoyances of having multiple contexts is having logical entities that are decomposed across two or more contexts, two examples that spring to mind are:

  • An enemy in an NPC context having a Player character from a PC context as its attack target.
  • Player Chracters, NPCs, Projectiles are each a context, and they are represented on the map in a Tiles context

Handling these kinds of relationships require lots of boiler-plate code, and it would be nice if code generation could be utilized to avoid it. It could be nice to have something like:

class MetaEntity
{
    public EnemyEntity enemy;
    public PlayerCharacterEntity target;
    public ProjectileEntity hittingProjectile;
}

class MetaSytem<MetaEntity> 
{
    ....

    public void Execute(MetaEntity entity) 
    {
    }

    ...
}

Generating the code to create the MetaEntity and MetaSystem would be trivial if the relationship between all three entities would be formalized by indexes or some other component annotation. It would really make working with multiple contexts easier and more worthwhile.

WDYT?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
svanderweelecommented, Feb 18, 2018

I agree with this, being able to use contexts to organise my code better would be incredible.

0reactions
thygrrrcommented, Feb 20, 2018

I only kind of agree.

The only problem is in having an entity that contains a bunch of references to other entities.

I solve this with extensions to ContextEntity, which minimizes boilerplate. So if I have an InputEntity e, that has a GameEntity associated with it, through an extension, I can do e.game.hasWhateverGameComponent.

It will obviously throw errors (as it should!) if e doesn’t have a GameLinkComponent or whatever I call it.

Some boilerplate persists when cleaning these puppies up. At times I wish I could get the Component that was removed one last time in some kind of GraveyardSystem. (I wrote that once using delegates, but it wasn’t really worth it, and it broke the timing of the systems). The inability to get the data of a removed component one last time in a System means that you end up with hacky secondary entities “destroyGameLink”, that have their own system.

However, until that triggers, you can’t reuse your original component. Meaning you might need to wait until the next tick (with everything that entails…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying Learning in Multiple Contexts
Work with multiples of numbers via a video or animation showing the progression of size of objects increasing by percentages (or exponentially).
Read more >
Adopting new practices in multiple contexts
Knowing that people have to face multiple contexts in their work, we have to make sure that new practices and tools are enablers...
Read more >
React - What is the Best Way to use Multiple createContexts?
I've just learned about the createContext hook and I'm wondering what's the best approach to using multiple contexts globally throughout the ...
Read more >
5 diagrams that show how context switching saps your ...
Moving between topics but staying at the same depth of thinking or doing can start to be taxing because it requires a little...
Read more >
Any downsides to using the same table for multiple contexts?
Contexts depending on each other defeats the decoupling. If you need two contexts to do some job, those are probably one context. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found