eugeneloza / decoherence

Project moved to https://gitlab.com/EugeneLoza/decoherence
GNU General Public License v3.0
10 stars 7 forks source link

Entity by alias #505

Open eugeneloza opened 6 years ago

eugeneloza commented 6 years ago

We may try to build absolutely any entity dictionary of TObject to be addressed directly, e.g. from a console script. Also every entity may have an (autogenerated or manual) Alias or several of those. Take advantage of $IF DECLARED(ClassName)}ClassName+'.'+{$ENDIF} stuff to check if the entity has a proper value and raise a warning otherwise. Maybe, should then do DEntity = class(DObject) GetValueByName(ValueName: string); something like that? Hmm... Declared would hardly operate on non-static stuff, however, we can just use a "Static set of those" inside a case input of statement.

ResonantExplosion commented 6 years ago

Doesn't look that simple. Only by virtual function to get a value. Thou raising exceptions is harder, maybe return some default 'error' value.

eugeneloza commented 6 years ago

Looks clean and nice

type DVariant = object
  Value: pointer;
  ValueType: TValueType;
  case ValueType of //(that part won't seem to work, need a better idea here)
     vtInteger: function GetValue: integer; // if Self = nil then log error
     vtString: function GetValue: string;
     ...
  end;
end;
function GetValueByName(aName: string): DVariant;
begin
  Result := nil;
  Result := inherited GetValueByName(aName);
  case aName of
     'hp': Result := ConstructVariant(@Self.hp.Current, vtFloat);
     'direction': Result := ConstructVariant(@Self.Direction, vtVector3);
  end;
end;
eugeneloza commented 6 years ago

DVariant.ToString, DVariant.ToInteger... etc. And yes, check how Variant is implemented in FPC, stop reinventing the wheel.

eugeneloza commented 6 years ago

entities should invoke not only raw fields, but methods too! Maybe use only getters and setters - that'd be a clean approach, but would require nearly duplicating the code, because these getters and setters would operate on different kind of data (raw pointers).

eugeneloza commented 6 years ago

As this is a feature required for scripting engine I'll move it for "later".

eugeneloza commented 6 years ago

Such approach is needed only for a very few entities (accessible from the scripts), e.g. Actors and active World objects. So, no need to make it into anything "global". Just a interface for such objects with GetValueByName, SetValueByName and CallMethodByName will do it perfectly.

eugeneloza commented 6 years ago

This might come in handy: http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.TObject.MethodAddress http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.TObject.FieldAddress Study Published property closer. It seems that TObject already has such functionality. This way making a script engine would be much simpler.