Update Entity.getIfModified() to distinguish between not present and not modified

Issue #29 resolved
Michael Ludwig
repo owner created an issue

Returning a boolean does not provide enough information to distinguish between if a component has not changed versions, or if it's been completely removed.

This is important if you want to achieve something along the lines of:

int oldVersion; // from somewhere
int newVersion = entity.getIfModified(component, oldVersion);
if (newVersion < 0 && oldVersion >= 0) {
   // handle removal
} else if (newVersion >= 0 && oldVersion < 0) {
  // handle add
} else if (newVersion != oldVersion) {
  // handle change
} else {
  // handle no change

Comments (2)

  1. Michael Ludwig reporter

    An alternative is to provide an enum with values NOT_MODIFIED, MODIFIED, and NOT_PRESENT.

    A strange case would be if the identity of the component changed but they managed to have the same version by the time someone tried to check versions.

    I wonder if versions should exist outside of a specific component's lifetime? I feel like that would be more correct.

  2. Log in to comment