Reflecting on reflection. Game maps and plugins.

Home Forums General Programming Discussion Reflecting on reflection. Game maps and plugins.

This topic contains 7 replies, has 3 voices, and was last updated by  cocon 2 months, 1 week ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #9755

    Richard Betson
    Participant

    Hi,

    I have been experimenting with Monkey2’s Reflection in an attempt to use it (along with parsing source files) to add game map and plugin support to my Alien Phoenix project.  Before I get to deep into this subject I thought posing a few questions might help me understand what Reflection is best suited for and what limitations/pitfalls I might encounter.

    So, what is a best use case for Reflection? Is a game map or plugin system (source files parsed and processed) suited to use of Reflection? What  issues are going to be limitations or pitfalls when using Reflection in a setting designed to support game maps and plugins.

    Reflection looks interesting and a possible candidate to add game map and plugin support to my Alien Phoenix project. If you can offer some advice please feel free to let me know what you think.

    #9757

    nerobot
    Participant

    I think, you can’t just write new source code and dynamically load it via reflection – recompile code is required.

    If your plugins will use standard lang features, then you can (probably) use it like lua-scripts works.

    This time reflection doesn’t work with generic types (core vec2/3/4 and rect are generic).

    #9759

    Richard Betson
    Participant

    Reflection appeals to me in that when parsing script (more like source code in this case) I can easily invoke a method or function that is exposed to Reflection. This includes all of the public portions of my code as well as included modules and source imports. I have tinkered with scripting a bit and chose to use a contained variable approach where the variables are always included between parentheses even when initializing a variable. Something like myrect:= New Rect becomes CreateRect(Name) in script. This approach makes parsing (I guess tokenizing as well) easy and as long as I have a corresponding method or function ( like CreateRect() ) and handling generic types like Vec2() can be accommodated. In Vec2()’s case I would expect to use Vec2(var-name, va1, var2) in script where var-name is the invoked type (rect for example).

    The downside is features like For/Next loops or adding, subtracting become difficult and more complex to implement. In the case of addition something like Add(var-name,var,var) where var-name is receiving the product of the addition. For loops like For/Next something like this script might work:

    This simple script illustrates my interest in Reflection and why I think it could be useful for scripting. The potential for easy parsing and processing of script using Reflection seems to me to be possible. Combined with an easy to learn and use scripting language I can imagine Reflection making the above possible.

    #9762

    cocon
    Participant

    I have faced a practical use case with reflection in C#, to have the runtime system read the static type system and make some creative uses out of it, for example one real benefit is to avoid silly boilerplate code and gain some dynamism in this side.

    For example if you have this:

    You can iterate the class names (that implement the interface) and store them to a string list, and present them to the user, once you enter the name of the class you want, you can search the class by name and initialize it right away. This technique is used in some programming frameworks where having to manually maintain the descriptions of 100 examples is not a wise choice. 🙂

    #9778

    Richard Betson
    Participant

    I have been working on a scripting framework and at this point in Reflection’s development I’m thinking it’s just easier to encapsulate class types into a separate class (‘s). In addition to nonsupport of generic types there are some other issues for example this is not supported in reflection.

    The absence of generic type support leads to abstracts which support the script. This makes it difficult to support a user type and requires a lot of overhead. I’m still experimenting and I’ll be posting what I come up with, but it’s looking like Reflection at present is a less then perfect option runtime wise.

    #9797

    cocon
    Participant

     

    If Monkey treated datatypes as objects you would do this:

    But now you might try this:

     

    However if is possible to automate anything Reflection I would be interested to learn how is done. 🙂

    #9807

    nerobot
    Participant

    If there is finite number of data types to create then you can write data parser w/o reflection.

    Your own declarative lang 🙂 that will use needed internal functions.

    Each string token produce its action – CreatePlayer return instance of Player and set coord for him and so on.

    #9823

    cocon
    Participant

    For example if I have this simple example, can I use reflection to bypass the Select statement?

     

    Note that this is the most simple example you can get, writing a full interpreter will need more work.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.