Skip to main content
Added solution
Source Link
PeeS
  • 485
  • 6
  • 15

Let's assume I have a CEntity class that describes every entity within the game.

Each entity class has it's own std::vector of CActions. Each CAction is just an action that the entities can perform, for example CActionFight would have the logic for fighting.

To command my player (or any other entity) to fight all I do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished. Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects. pTargetEntity is invalid and here's my question.

How do you normally handle that in actions?

If a disconnection event of an entity is received on the server side, do you iterate through the actions of all entity in the map and remove these which are related to an entity that has just dropped connection?

EDIT Liked Josh's approach and implemented the solution, sounds very sensible and worked like a charm.

// Example of an action, checking wether Entity is still valid.
void CActionFight::Execute()
{
    m_iCycles--;
    
    if(m_iCycles>0)
    {
        if(m_pTarget->IsValid() == false)
        {
            m_pTarget = NULL;
            m_bValid = false;
        }
        else
        {
            printf("Attacking.%s\n", m_pTarget->GetName().data());
        }
    }
    else m_bValid = false;
}

Let's assume I have a CEntity class that describes every entity within the game.

Each entity class has it's own std::vector of CActions. Each CAction is just an action that the entities can perform, for example CActionFight would have the logic for fighting.

To command my player (or any other entity) to fight all I do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished. Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects. pTargetEntity is invalid and here's my question.

How do you normally handle that in actions?

If a disconnection event of an entity is received on the server side, do you iterate through the actions of all entity in the map and remove these which are related to an entity that has just dropped connection?

Let's assume I have a CEntity class that describes every entity within the game.

Each entity class has it's own std::vector of CActions. Each CAction is just an action that the entities can perform, for example CActionFight would have the logic for fighting.

To command my player (or any other entity) to fight all I do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished. Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects. pTargetEntity is invalid and here's my question.

How do you normally handle that in actions?

If a disconnection event of an entity is received on the server side, do you iterate through the actions of all entity in the map and remove these which are related to an entity that has just dropped connection?

EDIT Liked Josh's approach and implemented the solution, sounds very sensible and worked like a charm.

// Example of an action, checking wether Entity is still valid.
void CActionFight::Execute()
{
    m_iCycles--;
    
    if(m_iCycles>0)
    {
        if(m_pTarget->IsValid() == false)
        {
            m_pTarget = NULL;
            m_bValid = false;
        }
        else
        {
            printf("Attacking.%s\n", m_pTarget->GetName().data());
        }
    }
    else m_bValid = false;
}
deleted 162 characters in body; edited title
Source Link
user1430
user1430

Actions Queue - handling How can I handle the subject of an action disconnecting before the action executes?

Ok i've read couple of these so far on gd stackexchange, but i would like to sum up the approach.

LetsLet's assume iI have an CEntitya CEntity class(this is simplified), that describes every entity within the game. Each Entity

Each entity class has it's own std::vectorstd::vector of CActionsCActions. Each CActionCAction is nothing more thanjust an action that the Entitiesentities can perform, for example

CActionFight -CActionFight would have the logic for fighting (script).

So in order toTo command my player or(or any other entity) to fight all iI do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished (that's for now).

  Imagine player starting to execute the CActionFightCActionFight over pTargetEntitypTargetEntity and suddenly, pTargetEntitypTargetEntity disconnects.

pTargetEntity pTargetEntity is invalid and here's themy question.

How do you normally handle that in actions? If

If a disconnection event of an Entityentity is received on the server side, do you iterate through the actions of all Entitiesentity in the map and remove these which are related to an Entityentity that has just dropped connection?

Actions Queue - handling

Ok i've read couple of these so far on gd stackexchange, but i would like to sum up the approach.

Lets assume i have an CEntity class(this is simplified), that describes every entity within the game. Each Entity class has it's own std::vector of CActions. Each CAction is nothing more than an action that the Entities can perform, for example

CActionFight - would have the logic for fighting (script)

So in order to command my player or any other entity to fight all i do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished (that's for now).

  Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects.

pTargetEntity is invalid and here's the question.

How do you normally handle that in actions? If a disconnection event of an Entity is received on the server side, do you iterate through the actions of all Entities in the map and remove these which are related to an Entity that has just dropped connection?

How can I handle the subject of an action disconnecting before the action executes?

Let's assume I have a CEntity class that describes every entity within the game.

Each entity class has it's own std::vector of CActions. Each CAction is just an action that the entities can perform, for example CActionFight would have the logic for fighting.

To command my player (or any other entity) to fight all I do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished. Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects. pTargetEntity is invalid and here's my question.

How do you normally handle that in actions?

If a disconnection event of an entity is received on the server side, do you iterate through the actions of all entity in the map and remove these which are related to an entity that has just dropped connection?

Source Link
PeeS
  • 485
  • 6
  • 15

Actions Queue - handling

Ok i've read couple of these so far on gd stackexchange, but i would like to sum up the approach.

Lets assume i have an CEntity class(this is simplified), that describes every entity within the game. Each Entity class has it's own std::vector of CActions. Each CAction is nothing more than an action that the Entities can perform, for example

CActionFight - would have the logic for fighting (script)

So in order to command my player or any other entity to fight all i do is:

CActionFight *pActionFight = new CActionFight();
pActionFight->SetTarget(pTargetEntity);
pPlayer->AddAction(pActionFight);

Before this action is started, all other actions queued earlier have to be finished (that's for now).

Imagine player starting to execute the CActionFight over pTargetEntity and suddenly, pTargetEntity disconnects.

pTargetEntity is invalid and here's the question.

How do you normally handle that in actions? If a disconnection event of an Entity is received on the server side, do you iterate through the actions of all Entities in the map and remove these which are related to an Entity that has just dropped connection?