Results 1 to 11 of 11

Thread: Adding a Custom Component to Proton SDK

  1. #1

    Default Adding a Custom Component to Proton SDK

    Hi!
    I've to add a custom component to the SDK. The component has to move any entity (like an overlay entity or button entity)
    from the top of the screen to bottom and from bottom top(i.e wrap over) for ever. What are the steps to add a custom component?
    How to move an entity from top to bottom and bottom to top forever?

    I'm doing some thing like this inside the OnAdd() function my entity:

    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));

    But it didn't do anything. Inserting the above code inside a infinite loop like for( ;; ) is also not working.
    What to do?
    Last edited by rtr_18; 01-13-2012 at 09:22 AM.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,340

    Default

    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    Quote Originally Posted by Seth View Post
    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    I need a component any how. I used the following code:

    if((pEnt->GetVar("pos2d")->GetVector2().y < GetScreenSizeY()) && (pEnt->GetVar("pos2d")->GetVector2().y >= 0))
    {
    //m_bDirForward = true;
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    }
    else
    if((pEnt->GetVar("pos2d")->GetVector2().y > 0) && (pEnt->GetVar("pos2d")->GetVector2().y == GetScreenSizeY()))
    {
    //m_bDirForward = false;
    GetMessageManager()->SetEntityVariable(pEnt, 6000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    }
    But the entity is moved out of the window(my requirement is: it has to be moved to the bottom first and then to the top once it reaches the bottom).
    This has to be done repeatedly for the entity.

  4. #4

    Default Adding Custom Component to Proton SDK

    Quote Originally Posted by Seth View Post
    Code:
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    Hmm... this would wait 3 seconds, and then instant teleport the entity to the bottom of the screen, and then top, in the same tick. Probably not what you wanted.

    Have you worked through this tutorial? This shows how to move entities around and uses a technique that doesn't require making a new Component - check it out, should give you a good idea of how to do it.
    Hi!
    I've used the following code:

    if((pEnt->GetVar("pos2d")->GetVector2().y < GetScreenSizeY()) && (pEnt->GetVar("pos2d")->GetVector2().y >= 0))
    {
    //m_bDirForward = true;
    GetMessageManager()->SetEntityVariable(pEnt, 3000, "pos2d", CL_Vec2f(GetScreenSizeX()/2, GetScreenSizeY()));
    }
    else
    if((pEnt->GetVar("pos2d")->GetVector2().y > 0) && (pEnt->GetVar("pos2d")->GetVector2().y == GetScreenSizeY()))
    {
    //m_bDirForward = false;
    GetMessageManager()->SetEntityVariable(pEnt, 6000, "pos2d", CL_Vec2f(GetScreenSizeX()/2,0));
    }

    But it waits for 3 seconds and moved the entity out of the screen. What modifications has to be done to move it to the bottom first and then to top then to bottom continuously?

  5. #5
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,340

    Default

    Ok, first, I would wire up your OnUpdate in your component so it gets called every frame. Then do your movement in there, and don't bother with MessageManager.

    Untested code:

    Code:
    //Some where in your OnAdd you need something like this so it will get called:
    
    GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&MyComponent::OnUpdate, this, _1));
    
    
    void MyComponent::OnUpdate(VariantList *pVList)
    {
         LogMsg("If you don't see this message every frame, something is wrong!");
    
        float speed = 3;
        m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    
       if (m_pPos2d->y > GetScreenSizeYf())
       {
      //move it back to the top of the screen
       m_pPos2d->y = 0;
       }
    
    }
    Something like that. Note that this assumes this entity has an OverlayRenderComponent added to its entity as a sibling to this component, otherwise moving the position like that won't matter, as nothing would be rendering.
    Seth A. Robinson
    Robinson Technologies

  6. #6

    Default

    Quote Originally Posted by Seth View Post
    Ok, first, I would wire up your OnUpdate in your component so it gets called every frame. Then do your movement in there, and don't bother with MessageManager.

    Untested code:

    Code:
    //Some where in your OnAdd you need something like this so it will get called:
    
    GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&MyComponent::OnUpdate, this, _1));
    
    
    void MyComponent::OnUpdate(VariantList *pVList)
    {
         LogMsg("If you don't see this message every frame, something is wrong!");
    
        float speed = 3;
        m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    
       if (m_pPos2d->y > GetScreenSizeYf())
       {
      //move it back to the top of the screen
       m_pPos2d->y = 0;
       }
    
    }
    Something like that. Note that this assumes this entity has an OverlayRenderComponent added to its entity as a sibling to this component, otherwise moving the position like that won't matter, as nothing would be rendering.

    Only the top to bottom movement is working now also. Here's the code modified by me.
    Code:
       
        float speed = 0.3;
        
    	if((m_pPos2d->y >= 0) && (m_pPos2d->y <= GetScreenSizeYf()))
    	{
    		m_pPos2d->y += speed*GetBaseApp()->GetGameDeltaTick();  //fps independendent speed
    	}
    	if ((m_pPos2d->y >= GetScreenSizeYf()) && (m_pPos2d->y < 0))
    	{
    		//move it back to the top of the screen
    		m_pPos2d->y = 0;//speed*GetBaseApp()->GetGameDeltaTick();
    	}

  7. #7
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,340

    Default

    Your code:

    Code:
    if ((m_pPos2d->y >= GetScreenSizeYf()) && (m_pPos2d->y < 0))
    	{
    		//move it back to the top of the screen
    		m_pPos2d->y = 0;//speed*GetBaseApp()->GetGameDeltaTick();
    	}
    So, you want to move your y to 0 if y is > GetScreenSizeYf() *AND* if y is less than 0?

    It's impossible for both of things to be true at the same time. Why did you add the m_pPos2d->y < 0 part?
    Seth A. Robinson
    Robinson Technologies

  8. #8

    Default

    Quote Originally Posted by Seth View Post
    Your code:

    Code:
    if ((m_pPos2d->y >= GetScreenSizeYf()) && (m_pPos2d->y < 0))
    	{
    		//move it back to the top of the screen
    		m_pPos2d->y = 0;//speed*GetBaseApp()->GetGameDeltaTick();
    	}
    So, you want to move your y to 0 if y is > GetScreenSizeYf() *AND* if y is less than 0?

    It's impossible for both of things to be true at the same time. Why did you add the m_pPos2d->y < 0 part?
    Thanks for pointing it out. Now it's working.But the direction is not from bottom to top. It's restarting from top once it reached the bottom.
    I tried this:

    Code:
    m_pPos2d->y -= speed*GetBaseApp()->GetGameDeltaTick();
    But my entity is not moved at all after reaching the bottom. What to do?

    More over I need two clarifications:

    Code:
    m_pPlayCount = &GetVar("playCount")->GetUINT32();
    m_pVarTarget = GetVar("target");
    (1)In the above code where do the arguments("playCount" and "target") come from?
    I searched the code I could not find. I'm following only RTSimpleApp.

    (2) Already existing components like TouchHandlerComponent and OverlayRendererComponent need no header files of them
    to be included in the App.cpp file to use it. But my custom component needs the header file to be included to use it. Do I have missed some thing?
    Do I need to register my component some where?
    Last edited by rtr_18; 01-14-2012 at 11:11 AM. Reason: Additional doubts on the SDK architecture

  9. #9
    Peasant
    Join Date
    Dec 2011
    Location
    Indonesia
    Posts
    9

    Talking maybe..

    Hi, maybe i could point out something, i had the learning curve just like you did and we should just consult the source code as there would be the aanswer lying,

    for
    Code:
    m_pPlayCount = &GetVar("playCount")->GetUINT32();
    m_pVarTarget = GetVar("target");
    for the case
    Code:
    m_pVarTarget = GetVar("target");
    we should consult here : shared/Manager/VariantDB.cpp line 67, if vardb could not find the requested variant, it will create one

    and for the case
    Code:
    m_pPlayCount = &GetVar("playCount")->GetUINT32();
    we should consult shared/util/Variant.h line , same with above, if there are none then the system will create one for you..

    Yes, this dynamics and references would take time to grasp, but as soon as you grasp the concept.. it really is totally rocks your programming world

    hope that would give some enlightenment about the Variant and the VariantDB concept

    and for the bouncing problem you had, maybe you would consider adding a direction parameter?
    when the y reach <= 0 then dir = 10
    when the y reach >= GetScreenYf then dir =-10
    on your OnUpdate routine?

  10. #10

    Question Where to add Direction parameter?

    Quote Originally Posted by yohanip View Post
    Hi, maybe i could point out something, i had the learning curve just like you did and we should just consult the source code as there would be the aanswer lying,

    for
    Code:
    m_pPlayCount = &GetVar("playCount")->GetUINT32();
    m_pVarTarget = GetVar("target");
    for the case
    Code:
    m_pVarTarget = GetVar("target");
    we should consult here : shared/Manager/VariantDB.cpp line 67, if vardb could not find the requested variant, it will create one

    and for the case
    Code:
    m_pPlayCount = &GetVar("playCount")->GetUINT32();
    we should consult shared/util/Variant.h line , same with above, if there are none then the system will create one for you..

    Yes, this dynamics and references would take time to grasp, but as soon as you grasp the concept.. it really is totally rocks your programming world

    hope that would give some enlightenment about the Variant and the VariantDB concept

    and for the bouncing problem you had, maybe you would consider adding a direction parameter?
    when the y reach <= 0 then dir = 10
    when the y reach >= GetScreenYf then dir =-10
    on your OnUpdate routine?
    Sorry for the late reply. I was on leave for the last two weeks. Can you tell me where to add this direction parameter? Is it like "m_pPos2d"
    in the previous post of Mr. Seth or Do I've to add some where else?

  11. #11
    Peasant
    Join Date
    Dec 2011
    Location
    Indonesia
    Posts
    9

    Default

    Quote Originally Posted by rtr_18 View Post
    Sorry for the late reply. I was on leave for the last two weeks. Can you tell me where to add this direction parameter? Is it like "m_pPos2d"
    in the previous post of Mr. Seth or Do I've to add some where else?
    Since you implements a component to handle your needs, you might want to put that direction parameter on your entity, or on your component
    if on your entity, you would use this code
    PHP Code:
    m_dir = &GetParent()->GetVar("my_direction")->getfloat(); 
    if you would like to have that variable only visible at your component level
    PHP Code:
    m_dir = &GetVar("my_direction")->getfloat() 
    IMO, where you put that variable it's just the matter of your usage and taste

    maybe you would like to use GetVarWithDefault instead of GetVar
    put that on your "Component::OnAdd" function

    now on your "Component::OnUpdate" function, you would put your constraints to the "*m_dir" field

    Cheer

Similar Threads

  1. Adding a full 360 screen rotation
    By Roadkill in forum Tanked
    Replies: 4
    Last Post: 11-28-2011, 02:03 AM
  2. Adding clanlib dependencies to a project
    By Topi in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 10-21-2011, 08:28 PM
  3. adding FPS Key and mouse controls to RT3DApp
    By BigBMan in forum Proton SDK
    Replies: 2
    Last Post: 11-11-2010, 06:49 AM
  4. New example in ClanLib 2.0: Custom GUI Component
    By sphair in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-19-2009, 02:08 PM
  5. Adding Di-Mart Guns
    By in forum Funeral Quest
    Replies: 5
    Last Post: 03-28-2005, 09:18 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •