Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Modding API - changes in modding interface

Discussion in 'Modding API' started by joeblack616, Oct 22, 2014.

Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.
  1. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi fellow modders,
    I created this topic to let you know about changes in existing modding API. I will post what was added/deleted/changed here to let you know in advance and prepare you to changes that could break your scripts.

    There is lot of developers here and I already requested them to let me know about their changes into Modding API and I will try to track their changes on my own, but It could happen that there will be some change that I will not know. If you will find any new/changed/deleted method in interface please write it here to let me and other developers know. You can also ask here for replacement of methods that were removed in past.

    Also you can ask about information what is method doing here and I will try to explain to you.

    Thanks.
     
    Last edited by a moderator: Oct 22, 2014
  2. fabricator77 Apprentice Engineer

    Messages:
    399
    Need a replacement for MyAPIGateway.Players.AllPlayers as used in Mission01 example.


    MyAPIGateway.Players.GetPlayers is not a replacement as it only retrieves active players, and not inactive/NPC players.
    Basically need a way to read the Identities list.
     
    Last edited by a moderator: Oct 22, 2014
  3. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi, I will add you new method for getting all identities. It should be in next update.
     
  4. joeblack616 Apprentice Engineer

    Messages:
    225
    Added new interface :
    public interface IMyIdentity
    {
    long PlayerId { get; }
    string DisplayName { get; }
    string Model { get; }
    Vector3? ColorMask { get; }
    bool IsDead { get; }
    }

    Added new method :
    void IMyPlayerCollection.GetAllIdentites(List<Sandbox.ModAPI.IMyIdentity> identities)

    It should be in next public release.
     
  5. tyrsis Junior Engineer

    Messages:
    862
    IMyEntity.OnPositionChanged is gone as of last update. Can this be brought back please?
     
  6. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi, please use IMyEntity.PositionComp.OnPositionChanged
     
  7. tyrsis Junior Engineer

    Messages:
    862
    Can you add SteamId to this for quick conversion of steamId -> playerId or back again?

    Also to keep with the theme of how other Gets work, why not do a GetIdentities(List<IMyIdentity>, Func<IMyIdentity, bool> collect) like the other get functions?
     
    Last edited by a moderator: Oct 22, 2014
  8. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi also, all floats will be converted to doubles, please check your mods for this.
    Basically you need to replace float structs with theirs "D" replacements. E.g. Vector3 is now Vector3D , ray is rayD, there are some structs that doesn't have double equivalents, so you need to manually cast to floats right now. (mainly object builders to be able load older saves.)
     
    Last edited by a moderator: Oct 24, 2014
  9. Ravenal Apprentice Engineer

    Messages:
    362
    So we are switching from Vector3 to Vector3D? Is there a specific reason why?
     
  10. joeblack616 Apprentice Engineer

    Messages:
    225
    Yes, after next update you shall use Vector3D.
     
  11. Ravenal Apprentice Engineer

    Messages:
    362
    Okay, I assume the reason for this is for better precision in a 3D Space environment and for 3D Sounds?
     
  12. shaftm Trainee Engineer

    Messages:
    3
    It's because Vector3D allows double the precision of Vector3
     
  13. Gwindalmir Senior Engineer

    Messages:
    1,006
    Why not just change the internal structure elements to be double?
    If this weren't alpha, I'd say do what you did. However since it is...

    If you did that, it would mean less changes for mods. None, assuming there was no typecasting to float. Not to mention the confusion with Vector3 vs Vector3D. I saw that already before and had no idea what that was, so I ignored it.
     
    Last edited by a moderator: Oct 25, 2014
  14. Ravenal Apprentice Engineer

    Messages:
    362
    Vector3 in terms of Gaming has always been 3 float values. x, y, z. Vector3D (I knew what this means) is 3 double values x,y,z. The difference between a float and double is VERY different, and double allows way more precision and accurate positioning.


    Good notes of the difference between the two.

    Single Precision
    The IEEE single precision floating point standard representation requires a 32 bit word, which may be represented as numbered from 0 to 31, left to right.
    • The first bit is the sign bit, S,
    • the next eight bits are the exponent bits, 'E', and
    • the final 23 bits are the fraction 'F':
    Code:
    S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF0 1      8 9                    31
    

    The value V represented by the word may be determined as follows:
    • If E=255 and F is nonzero, then V=NaN ("Not a number")
    • If E=255 and F is zero and S is 1, then V=-Infinity
    • If E=255 and F is zero and S is 0, then V=Infinity
    • If <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">0&lt;E&lt;255</code> then <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">V=(-1)**S * 2 ** (E-127) * (1.F)</code> where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point.
    • If E=0 and F is nonzero, then <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">V=(-1)**S * 2 ** (-126) * (0.F)</code>. These are "unnormalized" values.
    • If E=0 and F is zero and S is 1, then V=-0
    • If E=0 and F is zero and S is 0, then V=0
    In particular,

    Code:
    0 00000000 00000000000000000000000 = 0
    1 00000000 00000000000000000000000 = -0
    0 11111111 00000000000000000000000 = Infinity
    1 11111111 00000000000000000000000 = -Infinity
    0 11111111 00000100000000000000000 = NaN
    1 11111111 00100010001001010101010 = NaN
    0 10000000 00000000000000000000000 = +1 * 2**(128-127) * 1.0 = 2
    0 10000001 10100000000000000000000 = +1 * 2**(129-127) * 1.101 = 6.5
    1 10000001 10100000000000000000000 = -1 * 2**(129-127) * 1.101 = -6.5
    0 00000001 00000000000000000000000 = +1 * 2**(1-127) * 1.0 = 2**(-126)
    0 00000000 10000000000000000000000 = +1 * 2**(-126) * 0.1 = 2**(-127) 
    0 00000000 00000000000000000000001 = +1 * 2**(-126) * 
                                         0.00000000000000000000001 = 
                                         2**(-149)  (Smallest positive value)
    
    Double Precision
    The IEEE double precision floating point standard representation requires a 64 bit word, which may be represented as numbered from 0 to 63, left to right.
    • The first bit is the sign bit, S,
    • the next eleven bits are the exponent bits, 'E', and
    • the final 52 bits are the fraction 'F':
    Code:
    S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
    0 1        11 12                                                63
    
    The value V represented by the word may be determined as follows:
    • If E=2047 and F is nonzero, then V=NaN ("Not a number")
    • If E=2047 and F is zero and S is 1, then V=-Infinity
    • If E=2047 and F is zero and S is 0, then V=Infinity
    • If <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">0&lt;E&lt;2047</code> then <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">V=(-1)**S * 2 ** (E-1023) * (1.F)</code> where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point.
    • If E=0 and F is nonzero, then <code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; white-space: pre-wrap; background: #eeeeee;">V=(-1)**S * 2 ** (-1022) * (0.F)</code> These are "unnormalized" values.
    • If E=0 and F is zero and S is 1, then V=-0
    • If E=0 and F is zero and S is 0, then V=0
    Source: http://stackoverflow.com/a/801146/506391
     
  15. joeblack616 Apprentice Engineer

    Messages:
    225
    In next update ApiGateway should be initialized on DS after load of session
     
  16. tyrsis Junior Engineer

    Messages:
    862
    Just a heads up to mod makers. You must properly check MyAPIGateway when this changes, otherwise you will crash dedicated servers.

    MyAPIGateway has no Player, or controller, etc on dedicated servers as is to be expected. So make sure you do your null checks ;)
     
    Last edited by a moderator: Oct 27, 2014
  17. Ravenal Apprentice Engineer

    Messages:
    362
    Thanks for the heads up
     
  18. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    added bool IsDedicated { get; } into IMyUtilities
    added second non mandatory parameter into void GetAllIdentites(List&lt;IMyIdentity> identities, Func&lt;IMyIdentity, bool> collect = null) in IMyPlayerCollection
     
  19. Malware Master Engineer

    Messages:
    9,860
    To be quite honest, as a many years experienced C# user I would much rather have a proper IEnumerable&lt;IMyIdentity> Identities() function or property that I can run Linq (.Where, .Select etc) queries on than this solution. It shouldn't affect performance any. I find that I very rarely use the list argument.

    Using the 'yield return' and 'yield break' functionality rather than identities.Add would do the trick.
     
    Last edited by a moderator: Oct 30, 2014
  20. joeblack616 Apprentice Engineer

    Messages:
    225
    Added method Run into IMyControllableEntity
     
  21. Gwindalmir Senior Engineer

    Messages:
    1,006
    While I appreciate the detailed information, I did know the difference between float and double. :)

    I'm a developer, but not a gaming developer. So I didn't know that Vector3 had a specific meaning in that context. Thanks for clarifying that.

    Regardless, I'm glad they switched to doubles, more precision is good!
     
    Last edited by a moderator: Oct 31, 2014
  22. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi all, it's related directly to ModAPI but : Renamed MyTextsWrapper.GetFormatString to GetString .
    It will change in next update, please check for this change in your scripts.
     
    Last edited by a moderator: Oct 31, 2014
  23. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi all,
    please have in mind that System.IO.TextReader ReadFileInGlobalStorage(string file);
    System.IO.TextReader ReadFileInLocalStorage(string file, Type callingType);
    System.IO.TextWriter WriteFileInGlobalStorage(string file);
    System.IO.TextWriter WriteFileInLocalStorage(string file, Type callingType);

    Can (and will) throw exceptions. Please adjust your mods for this.
     
  24. Ravenal Apprentice Engineer

    Messages:
    362
    We need the ability to then check to see if files exists or not so that they don't crash the server if it throws an exception for that. Currently I do have it wrapped in try/catch statements.
     
  25. joeblack616 Apprentice Engineer

    Messages:
    225
    added :
    string SerializeToXML&lt;T>(T objToSerialize);
    T SerializeFromXML&lt;T>(string buffer);
    void InvokeOnGameThread(Action action);

    into utilities. I will provide you small script that can save/load cubegrid so you can see how can you serialize/deserialize cubegrids.
     
  26. joeblack616 Apprentice Engineer

    Messages:
    225
    added :

    public interface IMyParallelTask
    {
    Task StartBackground(IWork work, Action completionCallback);
    Task StartBackground(IWork work);
    Task StartBackground(Action action);
    Task StartBackground(Action action, Action completionCallback);
    void Do(IWork a, IWork b);
    void Do(params IWork[] work);
    void Do(Action action1, Action action2);
    void Do(params Action[] actions);
    void For(int startInclusive, int endExclusive, Action&lt;int> body);
    void For(int startInclusive, int endExclusive, Action&lt;int> body, int stride);
    void ForEach&lt;T>(IEnumerable&lt;T> collection, Action&lt;T> action);
    Task Start(Action action, WorkOptions options, Action completionCallback);
    Task Start(Action action, WorkOptions options);
    Task Start(Action action, Action completionCallback);
    Task Start(Action action);
    Task Start(IWork work, Action completionCallback);
    Task Start(IWork work);
    }
    into utilities

    please have in mind that MyAPIGateway calls are not thread safe !.
     
    Last edited by a moderator: Nov 4, 2014
  27. Ravenal Apprentice Engineer

    Messages:
    362
    Does this mean that lock and Interlocked be opened with? will work too? That will be a critical thread-safe thing needed. I assume stuff in VRage.Library (ParallelTasks) will be accessible?

    What if we want to stop the worker is there a way to do this?
     
  28. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    only IWork and Task will be accessible from ParallelTasks, you should have access to VRage.FastResourceLock right now. I will clarify stopping the worker.
     
  29. Ravenal Apprentice Engineer

    Messages:
    362
    Hmm okay, thanks, I am not sure how to use that fast resource lock is there any example that you can provide eventually?
     
  30. Derthmonuter Trainee Engineer

    Messages:
    44
    Thank you! If this works, this is truly amazing and you really did just open up a huge amount of modding possibility. I look forward to the script. :)
     
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.