• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Wipe

funcdef inside shared interface; "interface already implement" warning

14 posts in this topic

1st thing--

// module 1
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

// module 2
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

class celement : ielement
{
    Func@ fdef;

    Func@ get_f()
    {
       return( this.fdef ); 
    }
    void set_f( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Used that way, makes  "Missing implementation of ..." error for both, getter and setter. So i tried to use "normal" functions.
 

// module 1
 
funcdef void Func();

shared interface ielement
{
     Func@ fGet();
     void fSet( Func@ );
}

// module 2

funcdef void Func();

shared interface ielement
{
    Func@ fGet();
    void fSet( Func@ );
}

class celement : ielement
{
    Func@ fdef;

    Func@ fGet()
    {
       return( this.fdef ); 
    }

    void fSet( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Error changed to " Shared type 'ielement' doesn't match the original declaration in other module"
 
----

2nd thing--

shared interface ielement
{
   void dummy1();
}

shared interface isprite : ielement
{
    void dummy2();
}

class celement : ielement
{
   void dummy1() {}
}

class csprite : celement, isprite
{
    csprite()
    {
        super();
    }

    void dummy2() {}
}

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away? smile.png

EDIT: everything was tested with r1563

Edited by Andreas Jonsson
0

Share this post


Link to post
Share on other sites

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away?

 

I am wondering why this warning is even needed. We have:

1. Multiple inheritance for interfaces, i.e. abstract classes.

2. Single inheritance for regular classes.

3. All inheritance is virtual anyway.

 

This is a nice setup, and we can't ever suffer from the diamond problem. However,

4. It's impossible to decouple class declaration from its implementation (notwithstanding the shared keyword).

 

Because of 4. it's still reasonable to create otherwise superfluous interfaces, if only to make script headers more readable. For now I don't see a reason to report that an interface is already implemented as it manifests itself in typical and practical situations. But maybe I don't see the entire picture (how do mixin classes come into this?).

 

edit: this might be interesting:

 

interface I
{
    void f();
}

interface J : I
{
}

mixin class M1 : I
{
    void f() { x = 1; }
};

mixin class M2 : I
{
    void f() { x = 2; }
};

class T : M1, M2
{
    X() { x = 0; }
    int x;
};

This does not generate any warning, but it does if I change "mixin class M : I" to "mixin class M : J". But in both cases T inherits I along two paths.

 

edit2: Another issue:

 

mixin class M1
{
    void f() { x = 1; }
};

mixin class M2
{
    void f() { x = 2; }
};

class T : M1, M2
{
    T() { x = 0; }
    void g()
    {
        f(); // cannot use qualified names: M1::f() or M2::f()
    }
    int x;
};

There is no warning that T inherits f() twice (but g() calls f() in M1, the closest base class, I assume this is correct) and maybe this actually should warrant a warning, since it's actually a real function being inherited, not just an an interface method. Especially since there appers to be no way to explicitly call f() from the other base class, M2 (is this at all intended?).

Edited by TheAtom
0

Share this post


Link to post
Share on other sites

I'll look into the problems reported.

 

As for mixin classes; they are not really inherited. When including a mixin class only the parts that are not already in the class will be included, for example, if the class already has a property that is also in the mixin class, the version from the mixin class won't be included again. The same goes for methods and implemented interfaces.

 

You can think of mixin classes as macros for providing default implementations. 

0

Share this post


Link to post
Share on other sites

Hm, looks like there are still problems when loading from bytecode (shared type doesn't match the original declaration).

Edited by Wipe
0

Share this post


Link to post
Share on other sites

That's strange. I fixed that too yesterday. Loading from bytecode had the same problem as compiling the script in the first place, in that the funcdef didn't get the same type in both modules.

 

What script is failing to load from bytecode? I'll have to do some further investigation on it.

0

Share this post


Link to post
Share on other sites
Two modules with same code; both need to be loaded from bytecode or error won't show up.
funcdef void fdef();

shared interface iface
{
	fdef@ dummy();
}
0

Share this post


Link to post
Share on other sites

You were right (of course). My previous test didn't catch this problem because I loaded the bytecode right after having compiled the script from source. Only when loading the bytecode into a fresh engine did the problem appear.

 

The bug was a bit more complex than I had imagined, but it should now be fixed in revision 1574.

0

Share this post


Link to post
Share on other sites
Another dark secrets of funcdefs found, sorry! ;) We call start() function and expect to reach end().
 
Let's start from crash in cfuncdef1_1::crashme().
[spoiler]
 
funcdef void funcdef1( ifuncdef1_1& i );

shared interface ifuncdef1_1
{
    ifuncdef1_2@ events { get; set; }
    void crashme();
}

shared interface ifuncdef1_2
{
    funcdef1@ f { get; set; }
}

class cfuncdef1_1 : ifuncdef1_1
{
    ifuncdef1_2@ _events_;

    cfuncdef1_1() { @this._events_ = cfuncdef1_2(); }

    ifuncdef1_2@ get_events() { return( this._events_ ); }
    void set_events( ifuncdef1_2@ events ) { @this._events_ = events; }

    void crashme()
    {
         if( @this._events_ != null && @this._events_.f != null )
            this.events.f( this );

    }
}

class cfuncdef1_2 : ifuncdef1_2
{
    funcdef1@ ff;

    cfuncdef1_2() { @ff = null; }

    funcdef1@ get_f() { return( @this.ff ); }
    void set_f( funcdef1@ _f ) { @this.ff = _f; }
}

void start()
{
    ifuncdef1_1@ i = cfuncdef1_1();
    i.events.f = end;
    i.crashme();
}

void end( ifuncdef1_1& i  )
{
    Log( "you win!" );
}
[/spoiler]
 
If we change crashme() a bit, everything looks like it works without any problems (we can reach end()), but generated bytecode cannot be loaded (LoadByteCode() returns -1).
 
    void crashme()
    {
        if( @this._events_ != null && @this._events_.f != null )
        {
            funcdef1@ crash = this.events.f;
            crash( this );
        }
    }
 
And finally, different edit makes "GC cannot free an object of type '_builtin_function_', it is kept alive by the application." error show up.
cfuncdef1_1() { @this._events_ = null; }
Edited by Wipe
0

Share this post


Link to post
Share on other sites

No problem. At least you're able to provide examples that makes it easy for me to reproduce the problems for the investigation.

 

I'll look into this. Hopefully I'll have the fix tonight.

0

Share this post


Link to post
Share on other sites

I believe the problem is actually with virtual property accessors, and not function pointers here.

 

By manually calling the get functions everything works.

 

 
                void crashme() 
                { 
                     if( @this._events_ != null && @this._events_.f != null ) 
                     { 
//                      this.events.f( this ); 
                        this.get_events().get_f()( this ); 
                     } 
                }
0

Share this post


Link to post
Share on other sites

The crash has been fixed in revision 1575.

 

The memory leak upon the null pointer access exception is still there. I'm still investigating that, but it looks like a problem in the clean up of the callstack after an exception.

0

Share this post


Link to post
Share on other sites

Indeed. The memory leak is a bug with the logic for cleaning up the callstack after an exception. The problem happens when attempting to call a class method on a null pointer and the method takes a handle as argument. The cleanup of the callstack doesn't release that handle in this situation, thus causing the leak.

 

I know what is causing the leak, but I'll have to work on the fix at a later time as it's getting late and this won't be a trivial change with just a couple of lines that needs to change.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0