Game server logic module processing framework

Source: Internet
Author: User

When the game server starts, the server loads the dynamic link library of each game logic processing module based on the information in the configuration file, and then calls the dllcreate function of the module to initialize the module.

The configuration file can be as follows:

Modulecount = 30

Module1 = battlesys

Module2 = equipsys

Module3 = friendsys

Module4 = shopsys

Module5 = skilllsys

......

The prototype of the dllcreate function in the module may be as follows:

Imodule * dllcreate ()

{

Return new cmodule ();

}

 

 

The return value of a function is a pointer to the imodule interface class. This interface class is required by each game logic processing module, in addition, each module has a specific class cmodule that continues from the imodule interface class.

 

The returned imodule is saved to the game logic management class clogicmanager.

STD: Map <imodule *> mapallmodule;

 

After fully loaded modules, call the imodule: init function. The pseudo code is as follows:

Foreach imodule * P in mapallmodule

P-> Init (ilogicmanager *) This );

 

At this time, the initialization function of each module will be called. In the initialization function, each module registers the message numbers of interest to ilogicmanager and saves them

STD: hash_multimap <msgid, imodule *> mapmsghandler;

 

After initialization, the network module of the server sends the message to ilogicmanager whenever it receives the message. Then ilogicmanager finds the relevant imodule in mapmsghandler;

 

Imodule: recvmessage (MSG * PMSG, player * pplayer );

 

Each module receives messages of interest in cmodule: recvmessage. Then, you can generate the corresponding message processor cxxxhandler Based on the typeid in MSG, and then process the message.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.