⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 world.cpp

📁 网络游戏通用架构, 这是基于boost和libevent写的一个程序
💻 CPP
字号:
#include "world.h"


World::World( int ___argc, char* ___argv[] )
{
    _argc= __argc;
    _argv= __argv;
    _msg_router.setWorld( this );
    _network.setWorld( this );
    _scene= NULL;
}


World::~World()
{
    delete _scene;
}


int World::main(void)
{
    int ret= 0;
    try{
        ret= init();
    }catch( exception& e ){
        cerr << "Init failed: " << e.what() << endl;
        moduleShutdown();
    }catch( ... ){        cerr << "Init failed: " << "Unknown exception" << endl;
        moduleShutdown();
    }    if( ret ){//error occurs        moduleShutdown();        return ret;    }else{
        (*this)();
        return _state;
    }
}


int World::init(void){    string typetab_filename;    string cfgfilename;    string entry_filename;    string entry_scene_classname;    bool threaded_msg_router;    bool threaded_network;    bool threaded_scene;    options_description opt_desc( "Allowed options" );
    positional_options_description p_opt_desc;    opt_desc.add_options()
        ( "help,h", "Display help message" )
        ( "version,v", "print version string" )
        ( "EntrySceneClassName,c", value<string>(&entry_scene_classname)->default_value("EntryScene"), "The name of the Class to begin with" )
        ( "ThreadedMsgRouter", value<bool>(&threaded_msg_router)->default_value(false), "Whether run the MsgRouter in a separate thread" )        ( "ThreadedNetwork", value<bool>(&threaded_network)->default_value(false), "Whether run the Network in a separate thread" )        ( "ThreadedScene", value<bool>(&threaded_scene)->default_value(false), "Whether run the Scene in a separate thread" )
    ;    #ifndef _WIN32//POSIX
        opt_desc.add_options()
            ( "EntryFileName,f", value<string>(&entry_filename)->default_value("~/.mmo/mmo.so"), "The DLL file to be load" )
            ( "typetab", value<string>(&typetab_filename)->default_value("~/.mmo/typetab.cfg"), "The type table file to be load" )
            ( "config", value<string>(&cfgfilename)->default_value("~/.mmo/config.cfg"), "The config file to be load" )
        ;
    #else//Win32
        opt_desc.add_options()
            ( "EntryFileName,f", value<string>(&entry_filename)->default_value("mmo.dll"), "The DLL file to be load" )
            ( "typetab", value<string>(&typetab_filename)->default_value("typetab.cfg"), "The type table file to be load" )
            ( "config", value<string>(&cfgfilename)->default_value("config.cfg"), "The config file to be load" )
        ;
    #endif    try{        store( command_line_parser(_argc, _argv).options(opt_desc).positional(p_opt_desc).run(), _options );        notify( _options );    }catch( exception& e ){
        cerr << "command line parsing error: " << e.what() << endl;
    }catch( ... ){        cerr << "command line parsing error: " << "Unknown exception" << endl;    }    ifstream cfgfile( cfgfilename.c_str() );    if( cfgfile.good() ){        try{            store( parse_config_file(cfgfile, opt_desc), _options );
            notify( _options );        }catch( exception& e ){
            cerr << "config file parsing error: " << e.what() << endl;
        }catch( ... ){            cerr << "config file parsing error: " << "Unknown exception" << endl;        }    }else{        cerr<< "Can't open config file: " << cfgfilename << endl;    }    if( _options.count("help") ){
        cout << opt_desc << endl;
        setState( SHUT_DOWN );
        return 0;
    }
    if( _options.count("version") ){
        cout << "no version info" << endl;
        setState( SHUT_DOWN );
        return 0;
    }    _network.setThreaded( threaded_network );    if( load( &_network ) ){        return -1;    }    _msg_router.setThreaded( threaded_msg_router );    if( load( &_msg_router ) ){        return -1;    }    if( _factory.loadFactory( entry_filename ) ){        _factory.parse_types( typetab_filename );        _scene= static_cast<Scene*>( _factory.newInstance( entry_scene_classname ) );        if( _scene ){            int ret= 0;            _scene->setWorld( this );            _scene->setThreaded( threaded_scene );            ret= load( _scene );            if( ret ){//error occurs                return ret;            }            _factory.parse_types( typetab_filename );        }else{            cerr << "Can't find EntrySceneClass: " << entry_scene_classname << " In EntryFile: " << entry_filename << endl;            return -1;        }    }else{        cerr << "Can't load EntryFile: " << entry_filename << endl;        return -1;    }    return 0;}void World::breathe(void){    _timer.breathe();}void World::shutdown(void){}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -