Advertisement

MORPG Basic logic

Started by February 07, 2015 08:20 PM
3 comments, last by KyungKun Ko 9 years, 9 months ago

Hi guys i'm working on a modest online rpg in javascript with websockets (socket.io) just for fun and i'm wondering about one point.

Okay its very simple , should i send one event containing everything on each game loop of the server or should i send one event everytime something happens ?

Maybe i can send NPC infos in each game loop and player infos when something happens don't really know.

If you guys can help me ! Would be great !

Thank you in advance.

Typically, you send one network packet X times per second, and that packet contains a number of events for everything that's happend inbetween.
If by "event" you mean specifially a socket.io event, then that maps to "packet" in game networking parlance.
So, yes, send one big event with all the things that have happened, every so often. Probably less often than once for each main game loop.
This depends on how fast your game loop runs, and how much latency you can compensate for on the client side.
enum Bool { True, False, FileNotFound };
Advertisement

Some minimum intervaled 'keep alive' messages (both directions) even when the user is AFK so that the app can detect a failing connection and do the appropriate thing (both on client and at server)

Depending on your game's mechanics, might there be TOO MUCH going on at certain times/situations to send it all in one burst? (versus stringing it out over a few fractions of seconds -- most of these games arent 'twitch' and slight delays arent critically bad. If thats true and possibly done then is there a possible classification of priority for certain messages that need to be sent (first in line ) to the client for best operations?

--------------------------------------------[size="1"]Ratings are Opinion, not Fact
normally,You can send an event when it happens.
but this is very abstract and there are a lot of work to do.
for example, a palyer or a NPC information changes (for instance 'HP'), you should send it(using network module organized into a package) when it changed(HP =100 -> HP =50).

Here I have a code in disguise,



NFIObject* pObject = new NFCObject(NFIDENTID(0, 1), pPluginManager);
pObject->GetPropertyManager()->AddProperty(pObject->Self(), "HP", TDATA_STRING, true, true, true, true, 0, "");
pObject->SetPropertyInt("HP", 100);

pObject->AddPropertyCallBack("HP", this, &HelloWorld2::OnPropertyCallBackEvent);


pObject->SetPropertyInt("HP", 50);


int HelloWorld2::OnPropertyCallBackEvent( const NFIDENTID& self, const std::string& strProperty, const NFIDataList& oldVarList, const NFIDataList& newVarList, const NFIDataList& argVarList )
{
    //it will be call when 'HP' has changed, u can send message in this funciton, like this:
  NFMsg::ObjectPropertyInt xPropertyInt;

            NFMsg::Ident* pIdent = xPropertyInt.mutable_player_id();
            *pIdent = NFToPB(self);


            NFMsg::PropertyInt* pDataInt = xPropertyInt.add_property_list();
            pDataInt->set_property_name( strPropertyName );
            pDataInt->set_data( newVar.Int( 0 ) );


            for ( int i = 0; i < valueBroadCaseList.GetCount(); i++ )
            {
                NFIDENTID identOld = valueBroadCaseList.Object( i );
                NF_SHARE_PTR<BaseData> pData = mRoleBaseData.GetElement(identOld);
                if (pData.get())
                {
                    NF_SHARE_PTR<ServerData> pProxyData = mProxyMap.GetElement(pData->nGateID);
                    if (pProxyData.get())
                    {
                        SendMsgPB(NFMsg::EGMI_ACK_PROPERTY_INT, xPropertyInt, pProxyData->nFD, NFIDENTID(0, pData->nFD));
                    }
                }
            }
        }    
    return 0;
 }

this code is my open source engine tutorial code[http://www.yowoyo.com/forum.php?mod=forumdisplay&fid=46]

details you can refer at https://github.com/ketoo/NoahGameFrame

https://github.com/ketoo/NoahGameFrame [A fast, scalable, distributed game server framework for C++]

You should group game events into two groups - time critical and non time critical.

Time critical events usually related to visual quality such as players movement, state change, clothing, and so on. If those packets have too long delay to reach to other player. You game going to look awkward.

You don't need to show hp change immediately(usually. It depends on your game). Environment object's movement if it doesn't interacted with any player.

Moreover, one both cases, you should scale the broadcasting by distance or visibility(if you can) so that your server doesn't blow up.

This topic is closed to new replies.

Advertisement