• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By wobbegong_
      I am taking an absolute beginner's game development course and we have just finished game jams in small groups. Our current assignment is to get feedback from people working in any aspect of game development. I would very much appreciate any feedback! The game is up on itchi.io (sound warning) https://wobbegong.itch.io/zombie-shooter It's essentially a very basic PvE.
      I also have some things I'm wondering about, but you don't necessarily have to answer these. 
      1. Do you have any tips on working with physics? My group wrestled a bit with Rigidbody physics not totally working the way we wanted to -- jumping ended up kind of floaty and inclines seem to mess up movement. Alternatively... how can I build terrains with depth that won't result in wonky physics?
      2. How can I keep up the level of challenge in an interesting way as the player progresses through the waves?
      3. What are some of your personal guidelines for creating title screens?
      Thank you very much in advance!
    • By ethancodes
      I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console. 
      This is my current code for this part of the program, it is attached to the bricks:
      void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags. 
       
      Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
    • By Sandman Academy
      Downloadable at:
      https://virva.itch.io/sandman-academy
      https://gamejolt.com/games/sandmanacademy/329088
      https://www.indiexpo.net/en/games/sandman-academy
      https://www.gamefront.com/@sandmanacademy
      http://www.indiedb.com/games/sandman-academy
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity Specialisation of template parameter as another template class.

This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. In a previous question (Templates, Namespaces, Linking.) I asked about explicit template specialisation for a unique class. However, I now need to use specialisation where the explicit parameter is itself a template class. Description: template class CZug<T> contains a function bam() that calls template function bar<T>(). template function foo<T>() is declared but not defined except via specialisation. template function bar<T>(), by default calls template function foo<T>(). but bar<T>(), when T = template class CMup<T>, does nothing, thus avoiding the need to define foo<CMup<T> >(). Thus calling bam() on a CZug<CMup<int> > should compile. Unfortunately, I can't deduce the syntax for explicit specialisation using a template. Do I still use template <>?
namespace a {
    namespace b {

        template <typename T> void foo(T item);

    }
}

namespace a {
    namespace c {

        template <typename T> inline void bar(T item);

    }
}

template <typename T>
inline void a::c::bar(T item) {
    a::b::foo(item);
}


namespace a {

    template <typename T>
    class CZug {
      public:
        T m_item;
        void bam();
    };

}


template <typename T>
void a::CZug<T>::bam() {
    a::c::bar(m_item);
}



namespace a {
    namespace d {

        template <typename T>
        class CMup {
          public:
            T m_item;
        };

    }

    namespace c {

        //--------------------------------------------------------//
        // THE PROBLEM IS HERE: YOU CAN POSSIBLY IGNORE THE REST. //
        //--------------------------------------------------------//

        //template <> // error: too many template-parameter-lists.
        template <typename T>
        //template <> // invalid explicit specialization before '>' token.
        inline void bar(d::CMup<T> item);

    }
}

// template <>.
template <typename T>
// template <>.
inline void a::c::bar(a::d::CMup<T> item) { // <-- THIS FUNCTION SHOULD BE CALLED.
    // Do Nothing.
}

// Test routine.
int main() {
    a::CZug<a::d::CMup<int> > test;

    test.bam();
}

COMPILER ERROR: <code>void a::c::bar<a::d::CMup<int> >(a::d::CMup<int>*)]+0x11): undefined reference to `void a::b::foo<a::d::CMup<int> >(a::d::CMup<int>&)'</code> Any idea how I should write the declaration of void a::c::bar(d::CMup<T> item)?? NOTE: Again with the namespaces: These exist in the code I am writing (with different names of course). But if I remove them on the test code it compiles fine. ENVIRONMENT: Compiled using "GNU GCC Compiler" from "Code::Blocks" on Ubuntu (Breezy Badger) Linux, AMD64 version. Thanks for all assistance.

Share this post


Link to post
Share on other sites
Advertisement
Seems like an instantiation issue due to having CZug's implementation before the partial specialization you want it to use. This was discovered by accident simply simplifying your code to get rid of this gawdy "namespace a { ... } namespace a { ... } namespace a { ... }" junk.

Observe that commenting out the "#define DO_SPECIAL_AFTER" line will cause this code to work correctly (note: I have placed spaces after the backslashes to prevent the source tags from eating them up - remove the spaces to compile!):

#define SPECIAL_STUFF                     \ 
template <typename T> \
inline void bar(d::CMup<T> item); \
template <typename T> \
inline void bar(a::d::CMup<T> item) {}

#define DO_SPECIAL_AFTER

namespace a {
namespace b {
template <typename T> void foo(T item);
}
namespace d {
template <typename T>
class CMup {
public:
T m_item;
};
}
namespace c {
template <typename T> inline void bar(T item);
template <typename T>
inline void bar(T item) {
a::b::foo(item);
}
#ifndef DO_SPECIAL_AFTER
SPECIAL_STUFF
#endif
}
template <typename T>
class CZug {
public:
T m_item;
void bam();
};
template <typename T>
void CZug<T>::bam() {
a::c::bar(m_item);
}
namespace c {
#ifdef DO_SPECIAL_AFTER
SPECIAL_STUFF
#endif
}
}


// Test routine.
int main() {
a::CZug<a::d::CMup<int> > test;

test.bam();
}


Share this post


Link to post
Share on other sites
Thanks.

Seems odd, I reckon you should be able to do this properly somehow.

I just decided to make CMup non-template and use a cast. Might look back later and see if I can fix it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement