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.

Ingame Programming missing API and functions and known issues

Discussion in 'Programming (In-game)' started by mexmer, Apr 23, 2015.

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

    Ooooh..... IDisposable. I forgot to call ".Dispose()". Whoops. :)
    Actually, I missed fact IEnumerator is inherits IDisposable.
  2. Inflex Developer Staff

    I can see that you are putting a lot of effort into optimizing your code, but still, I can see some major flaws that costs you quite a lot on performance.
    Please, don't take this as a criticism of any kind. I would just like to show you some things so you can become better coder and ultimately provide better scripts for community, maybe.

    Fist of all, as opposed to C++ `std::string`, `strings` in C# are not mutable. That means, that every call to `+=` operator needs to allocate new `string` object along with entirely new internal buffer for actual content, copy all the data from old buffer to new one, add new characters into new buffer and assign new `string` object to your reference. GC will also have to collect all the old `strings` at some point in the future. Something like this is deadly for any performance oriented code:

    Use `StringBuilder` instead. As the name suggests, it's data structure dedicated to building large strings, piece after piece, without need to reallocate internal buffer after every attempt to append new data.

    Lambdas are very powerful tools, but they cost. In this case, it's performance. You actually pay this price twice.
    Fist time it's when you allocate the lambda delegate and pass it to some method. Each time you do that, new object is allocated on heap and it also needs to be collected later. There are some optimizations compiler can do to avoid some allocations, but it's not possible when your lambda needs to capture something, which is happening quite often in your code.
    Second time, it's when you invoke the lambda delegate, as the compiler nor Jitter can't simply inline given lambda call which is quite important optimization for small functions/methods.

    Another thing, rather minor compared to those above, I've noticed in your code is this dictionary lookup

    You can actually reduce it to simple array access by index. Enums are just named constants, usually represented by zero based integers during runtime, when you don't specify otherwise, so you can treat them as such and cast them to simple `int` which you can use then to access element in array directly, without need for sophisticated logic of dictionary.

    I hope you'll take something from my hints and have fun coding!
    • Informative Informative x 2
  3. krypt-lynx Apprentice Engineer

    First of all, I don't think criticism is bad. Criticism is useful, it gives feedback about troubles.

    I'm developer also, but Objective-C/Swift one. iOS and so on. Space Engineers is a virtual Arduino for me :)
    And.. What's up with C# and allocations? Obj-C runtime does not uses bytecode, but architecture is quite similar. Main difference is ARC (automatic reference counting, 100% deterministic) instead of GC. Yes, you can make temporary objects generated for lambdas to leak, but in my experience extra allocations itself never was a real *performance* killing problem there.

    > Second time, it's when you invoke the lambda delegate, as the compiler nor Jitter can't simply inline given lambda call which is quite important optimization for small functions/methods.
    I used lambdas there to avoid code duplication. Looks like I need to unfold it back :(

    Also looks like my *main* trouble is inattentiveness, because I used StringBuilder, for example, there: https://github.com/krypt-lynx/SE-Sequencer2/blob/master/Sequencer2/Lib/neighbours/Serializer.cs
    And there is no .Dispose() also.

    > You can actually reduce it to simple array access by index.
    Well... It more about readability and probability to have a bug there. I prefer to not have relations declared only by order. If I will insert new state, but don't sync list - it will cause a bug. Also dictionary is selfexplanatory.
    --- Automerge ---
    By the way:
    This is CharEnumerator. And it does works.
    --- Automerge ---
    Funny fact: After changing Strings to StringBuilders used instructions count does not changed.
    Or profiler counting method call instead of instructions ether compiler is smart enough to replace String to StringBuilder
  4. Justbeast11 Trainee Engineer

    Hey guys! I'm fairly new to space engineers and have recently started modding the game, I have created a pirate antenna spawn and everything works right but when the drones spawn they don't move, they just sit still and shoot. I saw a post earlier today where they said change the <FlightMode> to the value 2, but that didn't change anything, if anyone has experienced this bug and has any advice it would be greatly appreciated.
  5. Malware Master Engineer

    You're in the wrong section :) This is for ingame scripting, not modding.
  6. Justbeast11 Trainee Engineer

    Okay, sorry!
  7. krypt-lynx Apprentice Engineer

    Some weird stuff is going on:
    My scripts randomly hitting "Too Complex Exception" with no apparent reason. Probably reason inside my scripts, but I don;t see it. Also, in previous version they worked much more stable.

    DebugSrv v2: http://steamcommunity.com/sharedfiles/filedetails/?id=784906165
    Sequencer v2: http://steamcommunity.com/sharedfiles/filedetails/?id=1085402845
    --- Automerge ---
    Oh, my ingame script just crashed the game.
    --- Automerge ---
    Also looks like Taleden's Inventory Manager (http://steamcommunity.com/sharedfiles/filedetails/?id=546825757) is affected
    --- Automerge ---
    Looks like last update broke Digi's Control Module mod. This mod was the reason of those exceptions.
    Or not, just throwed again, but mod is disabled
  8. Wicorel Senior Engineer

    There is a new inventory item (canvas) added with the Parachute block. It may be that the code is seeing an 'unknown' object type and having exceptions.
  9. krypt-lynx Apprentice Engineer

    For TIM i must not be trouble. For this script it looks like unknown modded item.
  10. itchydani3l Trainee Engineer

    Hey, I was wondering if you could elaborate on the limitations on GPS access for in-game scripting.
    I'm planning on writing some scripts for friendly and neutral drones and I think being able to access GPS would be really nice.

    Basically, the idea I had was not to take GPS from a player, but to copy the script that the player uses to detect GPS.
    So far, I've found MyHudGpsMarkers.cs, MyGps.cs.

    MyGps.cs has a method .Coords which appears to give a Vector3D of the location of the GPS signal, which is basically what I want. Is this one of the broken methods in the in-game API?

    Basically, I kind of want to know which specific classes and methods are broken regarding GPS so I can see if I can find a work around.
  11. Georgik Apprentice Engineer

    Hey, does anybody read this? If so, I have a simple question, did I misunderstand something or we have explicitly whitelisted System.Type.GetFields(System.Reflection.BindingFlags) method but not System.Reflection.BindingFlags? Cause therefore we can't use this method anyway. (There are more of these)
  12. Inflex Developer Staff

    Hello, the mentioned function was whitelisted by accident long time ago. We don't want you have to access to this method for obvious reasons ;)
    Since you can't use it due to blacklisted `BindingFlags`, it's not really an explicit security problem and it's scheduled to be removed from whitelist in it's next update along with some other insecure and obsolete garbage.

    If you have some other suspects, please let us know so we can shoot them down in case they represent any possible source of issues.
    Thanks for your report.
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.