yake-svn Mailing List for Yake Engine (Page 22)
Status: Beta
Brought to you by:
psyclonist
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(17) |
Sep
(51) |
Oct
(2) |
Nov
(18) |
Dec
(66) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(44) |
Feb
(13) |
Mar
(73) |
Apr
(61) |
May
|
Jun
(4) |
Jul
(19) |
Aug
(50) |
Sep
(47) |
Oct
(7) |
Nov
(7) |
Dec
(14) |
2008 |
Jan
(2) |
Feb
|
Mar
(4) |
Apr
(4) |
May
(5) |
Jun
(7) |
Jul
(4) |
Aug
|
Sep
(5) |
Oct
|
Nov
(1) |
Dec
(4) |
2009 |
Jan
|
Feb
(22) |
Mar
(12) |
Apr
(1) |
May
(1) |
Jun
(4) |
Jul
(4) |
Aug
|
Sep
|
Oct
(17) |
Nov
(3) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
(12) |
Apr
(11) |
May
|
Jun
(5) |
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <psy...@us...> - 2006-12-03 00:46:44
|
Revision: 1512 http://svn.sourceforge.net/yake/?rev=1512&view=rev Author: psyclonist Date: 2006-12-02 16:46:45 -0800 (Sat, 02 Dec 2006) Log Message: ----------- refactored and moved code into netsvc component Modified Paths: -------------- trunk/yake/yake/samples/net/common/commonEvents.h trunk/yake/yake/samples/net/common/roCommon.h trunk/yake/yake/samples/net/roclient/ROClient.h trunk/yake/yake/samples/net/roserver/ROServer.h Modified: trunk/yake/yake/samples/net/common/commonEvents.h =================================================================== --- trunk/yake/yake/samples/net/common/commonEvents.h 2006-12-03 00:45:59 UTC (rev 1511) +++ trunk/yake/yake/samples/net/common/commonEvents.h 2006-12-03 00:46:45 UTC (rev 1512) @@ -174,8 +174,6 @@ } return in; } -#define YAKE_FOR_EACH(ITER_TYPE,ITER_NAME,CTR) \ - for (ITER_TYPE ITER_NAME = CTR.begin(); ITER_NAME != CTR.end(); ++ITER_NAME) template<typename _Ty, typename _Pr, typename _Alloc> inline yake::net::obitstream& operator << (yake::net::obitstream& out, const std::map<_Ty,_Pr,_Alloc>& ctr) Modified: trunk/yake/yake/samples/net/common/roCommon.h =================================================================== --- trunk/yake/yake/samples/net/common/roCommon.h 2006-12-03 00:45:59 UTC (rev 1511) +++ trunk/yake/yake/samples/net/common/roCommon.h 2006-12-03 00:46:45 UTC (rev 1512) @@ -6,144 +6,7 @@ namespace yake { namespace ro { - struct IServiceHost; - /** Represents a service that can be plugged added to and managed by an IServiceHost. - */ - struct IService : public boost::noncopyable - { - virtual ~IService() {} - /** Callback is triggered when the service should start and - has to be overridden by derived classes. - @note An IServiceHost may decide to start and stop services - under various circumstances. - */ - virtual void onStart(IServiceHost&) = 0; - /** Callback is triggered when the service should stop and - has to be overridden by derived classes. - @note An IServiceHost may decide to start and stop services - under various circumstances. - */ - virtual void onStop(IServiceHost&) = 0; - }; - /** Shared pointer managing an IService pointer. */ - typedef SharedPtr<IService> IServicePtr; - - namespace detail { - /** Implementation specific object managing - a number of services. - @todo Move into private area (i.e. where library users cannot see it). - */ - struct ServiceManager : public boost::noncopyable - { - void addService(IServicePtr, const std::string& tag = ""); - IServicePtr removeService(IServicePtr); - IServicePtr removeService(const std::string&); - void removeAllServices(); - IServicePtr getService(const std::string& tag) const; - private: - typedef std::set<IServicePtr> ServiceList; - public: - typedef ServiceList::const_iterator const_service_iterator; - const_service_iterator begin() const; - const_service_iterator end() const; - private: - typedef std::map<std::string,IServicePtr> TagMap; - TagMap tag2service_; - ServiceList services_; - }; - } // namespace detail - typedef SharedPtr<net::INetEventConnection> NetEventConnectionPtr; - /** Base class for objects that have control over packet and event connections - and manage a number of attachable services. - */ - struct IServiceHost : public boost::noncopyable - { - protected: - IServiceHost(); - public: - virtual ~IServiceHost() {} - - /** Start the IServiceHost and all registered services. - @note Services can be added after the IServiceHost has been started. - */ - bool start(); - /** Stop the IServiceHost and all registered services. - */ - void stop(); - - virtual NetEventConnectionPtr getEventConnection() const = 0; - //virtual net::IPacketConnection* getPacketConnection() const = 0; - //virtual net::IClientPacketConnection* getClientPacketConnection() const = 0; - //virtual net::IServerPacketConnection* getServerPacketConnection() const = 0; - - // mirror detail::ServiceManager interface (internally forwarded) - - /** Adds a service to the host. The host takes control over - starting and stopping the service. - @note The service should not have been started when it is passed to addService()! - @remarks Services can be added before or after starting the IServiceHost. - If an IService is added before start() has been called, then its onStart() - callback will be called when start() is finally called. - If an IService is added after start() has been called, then its onStart() - callback will be immediately called from within the addService() method. - */ - void addService(IServicePtr, const std::string& tag = ""); - /** Removes the given service. - @note The service is stopped if it's running. - */ - IServicePtr removeService(IServicePtr); - /** Removes the service identified by the given tag. - @note The service is stopped if it's running. - */ - IServicePtr removeService(const std::string&); - /** Removes all services. - @note Services are stopped if they're running. - */ - void removeAllServices(); - /** Returns a pointer to the service identified by the given tag. - */ - IServicePtr getService(const std::string& tag) const; - - typedef net::INetEventConnection::EvtProcessEventFn EvtProcessEventFn; - /** Use this method to subscribe to certain net events on a specific channel. - */ - SignalConnection subscribeToNetEvent( - const net::NetEvent::id_type, const net::ChannelId, const EvtProcessEventFn& fn); - - /** Use this method to subscribe to all net events on a specific channel. - */ - SignalConnection subscribeToNetEventChannel( - const net::ChannelId, const EvtProcessEventFn& fn); - private: - virtual bool onStart() = 0; - virtual void onStop() = 0; - protected: - /** Returns true if the IServiceHost has been started, otherwise false. - */ - bool running() const; - /** Dispatches received net events to registered listeners. - @see subscribeToNetEvent - @see subscribeToNetEventChannel - */ - void dispatchNetEvent(const net::PeerId, const net::NetEvent&, const net::ChannelId); - private: - detail::ServiceManager serviceMgr_; - volatile bool running_; - mutable boost::mutex runningMtx_; - - typedef SignalX<void(const net::PeerId, const net::NetEvent&, const net::ChannelId)> ProcessEventSig; - typedef SharedPtr<ProcessEventSig> ProcessEventSigPtr; - - typedef std::pair<net::ChannelId,net::NetEvent::id_type> ChannelEventIdPair; - typedef std::map<ChannelEventIdPair,ProcessEventSigPtr> SigMap; - - struct EventIdEntry - { - ProcessEventSigPtr sig_; - }; - SigMap sigMap_; - }; } // namespace ro } // namespace yake Modified: trunk/yake/yake/samples/net/roclient/ROClient.h =================================================================== --- trunk/yake/yake/samples/net/roclient/ROClient.h 2006-12-03 00:45:59 UTC (rev 1511) +++ trunk/yake/yake/samples/net/roclient/ROClient.h 2006-12-03 00:46:45 UTC (rev 1512) @@ -1,6 +1,7 @@ #ifndef RO_CLIENT_H #define RO_CLIENT_H +#include <yake/netsvc/netSvc.h> #include <yake/samples/net/common/common.h> #include <yake/samples/net/common/commonEvents.h> #include <yake/samples/net/common/roCommon.h> @@ -8,13 +9,13 @@ namespace yake { namespace ro { - struct client : public IServiceHost + struct client : public net::IServiceHost { public: client(const net::Address&); ~client(); - virtual NetEventConnectionPtr getEventConnection() const + virtual net::NetEventConnectionPtr getEventConnection() const { return evtConn_; } void setObjectManager(yake::ent::ObjectManager*); Modified: trunk/yake/yake/samples/net/roserver/ROServer.h =================================================================== --- trunk/yake/yake/samples/net/roserver/ROServer.h 2006-12-03 00:45:59 UTC (rev 1511) +++ trunk/yake/yake/samples/net/roserver/ROServer.h 2006-12-03 00:46:45 UTC (rev 1512) @@ -1,6 +1,7 @@ #ifndef RO_SERVER_H #define RO_SERVER_H +#include <yake/netsvc/netSvc.h> #include <yake/samples/net/common/common.h> #include <yake/samples/net/common/commonEvents.h> #include <yake/samples/net/common/roCommon.h> @@ -11,7 +12,7 @@ class client; } - struct server : public IServiceHost + struct server : public net::IServiceHost { public: server(); @@ -21,7 +22,7 @@ void setInterface(const net::Address&); // implement IServiceHost interface - virtual NetEventConnectionPtr getEventConnection() const + virtual net::NetEventConnectionPtr getEventConnection() const { return this->evtConn_; } // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:46:00
|
Revision: 1511 http://svn.sourceforge.net/yake/?rev=1511&view=rev Author: psyclonist Date: 2006-12-02 16:45:59 -0800 (Sat, 02 Dec 2006) Log Message: ----------- added YAKE_FOR_EACH, updated version info Modified Paths: -------------- trunk/yake/yake/base/yake.h trunk/yake/yake/base/yakePrerequisites.h Modified: trunk/yake/yake/base/yake.h =================================================================== --- trunk/yake/yake/base/yake.h 2006-12-03 00:45:15 UTC (rev 1510) +++ trunk/yake/yake/base/yake.h 2006-12-03 00:45:59 UTC (rev 1511) @@ -48,7 +48,7 @@ { extern YAKE_BASE_API Version linktime; -const Version compiletime ( 0, 3, 0 ); +const Version compiletime ( 0, 6, 0 ); } // base } // yake Modified: trunk/yake/yake/base/yakePrerequisites.h =================================================================== --- trunk/yake/yake/base/yakePrerequisites.h 2006-12-03 00:45:15 UTC (rev 1510) +++ trunk/yake/yake/base/yakePrerequisites.h 2006-12-03 00:45:59 UTC (rev 1511) @@ -146,6 +146,9 @@ #define YAKE_DECLARE_GLOBAL YAKE_DECLARE_CLASS( global ) #define YAKE_DECLARE_FUNCTION(name) static const char * yake_private_currentFunction = #name "()"; +#define YAKE_FOR_EACH(ITER_TYPE,ITER_NAME,CTR) \ + for (ITER_TYPE ITER_NAME = CTR.begin(); ITER_NAME != CTR.end(); ++ITER_NAME) + #include <boost/function.hpp> #endif // YAKE_BASE_PREREQUISITES_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:45:15
|
Revision: 1510 http://svn.sourceforge.net/yake/?rev=1510&view=rev Author: psyclonist Date: 2006-12-02 16:45:15 -0800 (Sat, 02 Dec 2006) Log Message: ----------- added netsvc component Added Paths: ----------- trunk/yake/scripts/msvc8/netSvc.vcproj trunk/yake/src/yake/netsvc/ trunk/yake/src/yake/netsvc/netService.cpp trunk/yake/src/yake/netsvc/netServiceHost.cpp trunk/yake/src/yake/netsvc/netSvc.cpp trunk/yake/src/yake/netsvc/pch.cpp trunk/yake/yake/netsvc/ trunk/yake/yake/netsvc/netPrerequisites.h trunk/yake/yake/netsvc/netService.h trunk/yake/yake/netsvc/netServiceHost.h trunk/yake/yake/netsvc/netSvc.h trunk/yake/yake/netsvc/pch.h Added: trunk/yake/scripts/msvc8/netSvc.vcproj =================================================================== --- trunk/yake/scripts/msvc8/netSvc.vcproj (rev 0) +++ trunk/yake/scripts/msvc8/netSvc.vcproj 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,255 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="netSvc" + ProjectGUID="{E50171E1-18D3-495B-9942-D99DF08E1040}" + RootNamespace="netSvc" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="../../common/bin/debug" + IntermediateDirectory="../../common/obj/debug/$(ProjectName)" + ConfigurationType="2" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../../;../../dependencies/boost/;../../dependencies/ttl/;..dependencies/tinyxml" + PreprocessorDefinitions="_STLP_DEBUG;WIN32;_DEBUG;_WINDOWS;_USRDLL;YAKE_NETSVC_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + RuntimeTypeInfo="true" + UsePrecompiledHeader="2" + PrecompiledHeaderThrough="yake/netsvc/pch.h" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="base.lib" + OutputFile="$(OutDir)/yake_$(ProjectName)-vc80-d.dll" + LinkIncremental="2" + AdditionalLibraryDirectories="../../common/lib;../../common/lib/debug;../../dependencies/lib" + GenerateDebugInformation="true" + ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb" + SubSystem="2" + ImportLibrary="../../common/lib/$(TargetName).lib" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="../../common/bin/release" + IntermediateDirectory="../../common/obj/release/$(ProjectName)" + ConfigurationType="2" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="../../;../../dependencies/boost/;../../dependencies/ttl/;..dependencies/tinyxml" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;YAKE_NETSVC_EXPORTS" + RuntimeLibrary="2" + RuntimeTypeInfo="true" + UsePrecompiledHeader="2" + PrecompiledHeaderThrough="yake/netsvc/pch.h" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="base.lib" + OutputFile="$(OutDir)/yake_$(ProjectName)-vc80.dll" + LinkIncremental="1" + AdditionalLibraryDirectories="../../common/lib;../../common/lib/release;../../dependencies/lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + ImportLibrary="../../common/lib/release/$(TargetName).lib" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="src" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{1441AE57-C6D0-4c49-BE0F-31522C92DE6C}" + > + <File + RelativePath="..\..\src\yake\netsvc\netService.cpp" + > + </File> + <File + RelativePath="..\..\src\yake\netsvc\netServiceHost.cpp" + > + </File> + <File + RelativePath="..\..\src\yake\netsvc\netSvc.cpp" + > + </File> + <File + RelativePath="..\..\src\yake\netsvc\pch.cpp" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + </File> + </Filter> + <Filter + Name="inc" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{EAA8A4D1-68D3-40d3-8FA1-8ABB03609AF8}" + > + <File + RelativePath="..\..\yake\netsvc\netPrerequisites.h" + > + </File> + <File + RelativePath="..\..\yake\netsvc\netService.h" + > + </File> + <File + RelativePath="..\..\yake\netsvc\netServiceHost.h" + > + </File> + <File + RelativePath="..\..\yake\netsvc\netSvc.h" + > + </File> + <File + RelativePath="..\..\yake\netsvc\pch.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: trunk/yake/src/yake/netsvc/netService.cpp =================================================================== --- trunk/yake/src/yake/netsvc/netService.cpp (rev 0) +++ trunk/yake/src/yake/netsvc/netService.cpp 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,9 @@ +#include <yake/netsvc/pch.h> +#include <yake/netsvc/netService.h> +#include <yake/netsvc/netServiceHost.h> + +namespace yake { +namespace net { + +} // namespace net +} // namespace yake Added: trunk/yake/src/yake/netsvc/netServiceHost.cpp =================================================================== --- trunk/yake/src/yake/netsvc/netServiceHost.cpp (rev 0) +++ trunk/yake/src/yake/netsvc/netServiceHost.cpp 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,185 @@ +#include <yake/netsvc/pch.h> +#include <yake/netsvc/netService.h> +#include <yake/netsvc/netServiceHost.h> + +namespace yake { +namespace net { + + //----------------------------------------------------------------------------- + IServiceHost::IServiceHost() : running_(false) + { + } + bool IServiceHost::running() const + { + boost::mutex::scoped_lock lck(runningMtx_); + return running_; + } + bool IServiceHost::start() + { + bool succ = this->onStart(); + if (!succ) + return false; + + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = true; + } + + // start services + YAKE_FOR_EACH(detail::ServiceManager::const_service_iterator,it,serviceMgr_) + { + (*it)->onStart(*this); + } + + return true; + } + void IServiceHost::stop() + { + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = false; + } + + // stop services + YAKE_FOR_EACH(detail::ServiceManager::const_service_iterator,it,serviceMgr_) + { + (*it)->onStop(*this); + } + + // stop the rest + this->onStop(); + } + void IServiceHost::addService(IServicePtr service, const std::string& tag) + { + serviceMgr_.addService( service, tag ); + if (this->running()) + service->onStart(*this); + } + void IServiceHost::removeAllServices() + { + serviceMgr_.removeAllServices(); + } + IServicePtr IServiceHost::removeService(const std::string & tag) + { + IServicePtr service = serviceMgr_.removeService( tag ); + if (service && this->running()) + service->onStop(*this); + return service; + } + IServicePtr IServiceHost::removeService(IServicePtr service) + { + serviceMgr_.removeService( service ); + if (service && this->running()) + service->onStop(*this); + return service; + } + IServicePtr IServiceHost::getService(const std::string& tag) const + { + return serviceMgr_.getService( tag ); + } + void IServiceHost::dispatchNetEvent(const net::PeerId pId, const net::NetEvent& evt, const net::ChannelId cId) + { + // find catch-all for this channel (ignore event id) + { + SigMap::const_iterator it = sigMap_.find( ChannelEventIdPair(cId,net::NetEvent::EVTID_NONE) ); + if (it != sigMap_.end()) + (*it->second)(pId,evt,cId); + } + + // find signal for this channel and event id: + SigMap::const_iterator it = sigMap_.find( ChannelEventIdPair(cId,evt.id()) ); + if (it == sigMap_.end()) + return; + (*it->second)(pId,evt,cId); + } + SignalConnection IServiceHost::subscribeToNetEvent( + const net::NetEvent::id_type eId, const net::ChannelId cId, const EvtProcessEventFn& fn) + { + const ChannelEventIdPair idPair(cId,eId); + + SigMap::iterator it = sigMap_.find( idPair ); + if (it == sigMap_.end()) + { + ProcessEventSigPtr sig( new ProcessEventSig() ); + sigMap_[ idPair ] = sig; + return sig->connect( fn ); + } + return it->second->connect(fn); + } + SignalConnection IServiceHost::subscribeToNetEventChannel( + const net::ChannelId cId, const EvtProcessEventFn& fn) + { + const ChannelEventIdPair idPair(cId,net::NetEvent::EVTID_NONE); + + SigMap::iterator it = sigMap_.find( idPair ); + if (it == sigMap_.end()) + { + ProcessEventSigPtr sig( new ProcessEventSig() ); + sigMap_[ idPair ] = sig; + return sig->connect( fn ); + } + return it->second->connect(fn); + } + +//----------------------------------------------------------------------------- +namespace detail { + + void ServiceManager::addService(IServicePtr service, const std::string& tag) + { + YAKE_ASSERT( service ); + if (!service) + return; + + services_.insert( service ); + if (!tag.empty()) + { + YAKE_ASSERT( tag2service_.find(tag) == tag2service_.end() ).debug("duplicate tag!"); + tag2service_[ tag ] = service; + } + } + IServicePtr ServiceManager::getService(const std::string& tag) const + { + TagMap::const_iterator itFind = tag2service_.find(tag); + return (itFind == tag2service_.end() ? IServicePtr() : itFind->second); + } + IServicePtr ServiceManager::removeService(const std::string& tag) + { + TagMap::iterator itFind = tag2service_.find(tag); + if (itFind == tag2service_.end()) + return IServicePtr(); + IServicePtr service = itFind->second; + tag2service_.erase( itFind ); + services_.erase( service ); + return service; + } + IServicePtr ServiceManager::removeService(const IServicePtr service) + { + YAKE_FOR_EACH(TagMap::iterator,itFind,tag2service_) + { + if (itFind->second == service) + { + tag2service_.erase( itFind ); + break; + } + } + services_.erase( service ); + return service; + } + void ServiceManager::removeAllServices() + { + tag2service_.clear(); + services_.clear(); + } + ServiceManager::const_service_iterator ServiceManager::begin() const + { + return services_.begin(); + } + ServiceManager::const_service_iterator ServiceManager::end() const + { + return services_.end(); + } + +} // namespace detail + +} // namespace net +} // namespace yake Added: trunk/yake/src/yake/netsvc/netSvc.cpp =================================================================== --- trunk/yake/src/yake/netsvc/netSvc.cpp (rev 0) +++ trunk/yake/src/yake/netsvc/netSvc.cpp 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,9 @@ +#include <yake/netsvc/pch.h> +#include <yake/netsvc/netService.h> +#include <yake/netsvc/netServiceHost.h> + +namespace yake { +namespace net { + +} // namespace net +} // namespace yake Added: trunk/yake/src/yake/netsvc/pch.cpp =================================================================== --- trunk/yake/src/yake/netsvc/pch.cpp (rev 0) +++ trunk/yake/src/yake/netsvc/pch.cpp 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1 @@ +#include <yake/netsvc/pch.h> Added: trunk/yake/yake/netsvc/netPrerequisites.h =================================================================== --- trunk/yake/yake/netsvc/netPrerequisites.h (rev 0) +++ trunk/yake/yake/netsvc/netPrerequisites.h 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,30 @@ +#ifndef YAKE_NETSVC_PREREQUISITES_H +#define YAKE_NETSVC_PREREQUISITES_H + +#include <yake/base/yakePrerequisites.h> +#include <yake/base/yake.h> +#include <yake/net/net.h> + +#define YAKE_NETSVC_DLL + +#ifdef YAKE_NETSVC_EXPORTS +# ifdef YAKE_NETSVC_DLL +# define NETSVC_API DLLEXPORT +# else +# define NETSVC_API +# endif +#else +# ifdef YAKE_NETSVC_DLL +# define NETSVC_API DLLIMPORT +# else +# define NETSVC_API +# endif +# if defined( _DEBUG ) +# pragma comment(lib,"yake_netsvc-vc80-d.lib") +# else +# pragma comment(lib,"yake_netsvc-vc80.lib") +# endif +#endif + +#endif + Added: trunk/yake/yake/netsvc/netService.h =================================================================== --- trunk/yake/yake/netsvc/netService.h (rev 0) +++ trunk/yake/yake/netsvc/netService.h 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,41 @@ +#ifndef YAKE_NETSVC_SERVICE_H +#define YAKE_NETSVC_SERVICE_H + +#include "netPrerequisites.h" +//#include "netCommon.h" + +#pragma warning(push) +#pragma warning(disable: 4275) // C4275: non dll-interface class 'X' used as base for dll-interface 'Y' + +namespace yake { +namespace net { + + struct IServiceHost; + /** Represents a service that can be plugged added to and managed by an IServiceHost. + */ + struct NETSVC_API IService : public boost::noncopyable + { + virtual ~IService() {} + + /** Callback is triggered when the service should start and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ + virtual void onStart(IServiceHost&) = 0; + /** Callback is triggered when the service should stop and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ + virtual void onStop(IServiceHost&) = 0; + }; + /** Shared pointer managing an IService pointer. */ + typedef SharedPtr<IService> IServicePtr; + +} // namespace net +} // namespace yake + +#pragma warning(pop) + +#endif Added: trunk/yake/yake/netsvc/netServiceHost.h =================================================================== --- trunk/yake/yake/netsvc/netServiceHost.h (rev 0) +++ trunk/yake/yake/netsvc/netServiceHost.h 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,135 @@ +#ifndef YAKE_NETSVC_SERVICEHOST_H +#define YAKE_NETSVC_SERVICEHOST_H + +#include <boost/thread/mutex.hpp> +#include "netPrerequisites.h" +#include "netService.h" + +#pragma warning(push) +#pragma warning(disable: 4275) // C4275: non dll-interface class 'X' used as base for dll-interface 'Y' + +namespace yake { +namespace net { + + namespace detail { + /** Implementation specific object managing + a number of services. + @todo Move into private area (i.e. where library users cannot see it). + */ + struct NETSVC_API ServiceManager : public boost::noncopyable + { + void addService(IServicePtr, const std::string& tag = ""); + IServicePtr removeService(IServicePtr); + IServicePtr removeService(const std::string&); + void removeAllServices(); + IServicePtr getService(const std::string& tag) const; + private: + typedef std::set<IServicePtr> ServiceList; + public: + typedef ServiceList::const_iterator const_service_iterator; + const_service_iterator begin() const; + const_service_iterator end() const; + private: + typedef std::map<std::string,IServicePtr> TagMap; + TagMap tag2service_; + ServiceList services_; + }; + } // namespace detail + typedef SharedPtr<net::INetEventConnection> NetEventConnectionPtr; + /** Base class for objects that have control over packet and event connections + and manage a number of attachable services. + */ + struct NETSVC_API IServiceHost : public boost::noncopyable + { + protected: + IServiceHost(); + public: + virtual ~IServiceHost() {} + + /** Start the IServiceHost and all registered services. + @note Services can be added after the IServiceHost has been started. + */ + bool start(); + /** Stop the IServiceHost and all registered services. + */ + void stop(); + + virtual NetEventConnectionPtr getEventConnection() const = 0; + //virtual net::IPacketConnection* getPacketConnection() const = 0; + //virtual net::IClientPacketConnection* getClientPacketConnection() const = 0; + //virtual net::IServerPacketConnection* getServerPacketConnection() const = 0; + + // mirror detail::ServiceManager interface (internally forwarded) + + /** Adds a service to the host. The host takes control over + starting and stopping the service. + @note The service should not have been started when it is passed to addService()! + @remarks Services can be added before or after starting the IServiceHost. + If an IService is added before start() has been called, then its onStart() + callback will be called when start() is finally called. + If an IService is added after start() has been called, then its onStart() + callback will be immediately called from within the addService() method. + */ + void addService(IServicePtr, const std::string& tag = ""); + /** Removes the given service. + @note The service is stopped if it's running. + */ + IServicePtr removeService(IServicePtr); + /** Removes the service identified by the given tag. + @note The service is stopped if it's running. + */ + IServicePtr removeService(const std::string&); + /** Removes all services. + @note Services are stopped if they're running. + */ + void removeAllServices(); + /** Returns a pointer to the service identified by the given tag. + */ + IServicePtr getService(const std::string& tag) const; + + typedef net::INetEventConnection::EvtProcessEventFn EvtProcessEventFn; + /** Use this method to subscribe to certain net events on a specific channel. + */ + SignalConnection subscribeToNetEvent( + const net::NetEvent::id_type, const net::ChannelId, const EvtProcessEventFn& fn); + + /** Use this method to subscribe to all net events on a specific channel. + */ + SignalConnection subscribeToNetEventChannel( + const net::ChannelId, const EvtProcessEventFn& fn); + private: + virtual bool onStart() = 0; + virtual void onStop() = 0; + protected: + /** Returns true if the IServiceHost has been started, otherwise false. + */ + bool running() const; + /** Dispatches received net events to registered listeners. + @see subscribeToNetEvent + @see subscribeToNetEventChannel + */ + void dispatchNetEvent(const net::PeerId, const net::NetEvent&, const net::ChannelId); + private: + detail::ServiceManager serviceMgr_; + volatile bool running_; + mutable boost::mutex runningMtx_; + + typedef SignalX<void(const net::PeerId, const net::NetEvent&, const net::ChannelId)> ProcessEventSig; + typedef SharedPtr<ProcessEventSig> ProcessEventSigPtr; + + typedef std::pair<net::ChannelId,net::NetEvent::id_type> ChannelEventIdPair; + typedef std::map<ChannelEventIdPair,ProcessEventSigPtr> SigMap; + + struct EventIdEntry + { + ProcessEventSigPtr sig_; + }; + SigMap sigMap_; + }; + +} // namespace net +} // namespace yake + +#pragma warning(pop) + +#endif Added: trunk/yake/yake/netsvc/netSvc.h =================================================================== --- trunk/yake/yake/netsvc/netSvc.h (rev 0) +++ trunk/yake/yake/netsvc/netSvc.h 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,152 @@ +#ifndef YAKE_NETSVC_H +#define YAKE_NETSVC_H + +#include "netPrerequisites.h" +//#include "netCommon.h" + +namespace yake { +namespace net { + + struct IServiceHost; + /** Represents a service that can be plugged added to and managed by an IServiceHost. + */ + struct IService : public boost::noncopyable + { + virtual ~IService() {} + + /** Callback is triggered when the service should start and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ + virtual void onStart(IServiceHost&) = 0; + /** Callback is triggered when the service should stop and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ + virtual void onStop(IServiceHost&) = 0; + }; + /** Shared pointer managing an IService pointer. */ + typedef SharedPtr<IService> IServicePtr; + + namespace detail { + /** Implementation specific object managing + a number of services. + @todo Move into private area (i.e. where library users cannot see it). + */ + struct ServiceManager : public boost::noncopyable + { + void addService(IServicePtr, const std::string& tag = ""); + IServicePtr removeService(IServicePtr); + IServicePtr removeService(const std::string&); + void removeAllServices(); + IServicePtr getService(const std::string& tag) const; + private: + typedef std::set<IServicePtr> ServiceList; + public: + typedef ServiceList::const_iterator const_service_iterator; + const_service_iterator begin() const; + const_service_iterator end() const; + private: + typedef std::map<std::string,IServicePtr> TagMap; + TagMap tag2service_; + ServiceList services_; + }; + } // namespace detail + typedef SharedPtr<net::INetEventConnection> NetEventConnectionPtr; + /** Base class for objects that have control over packet and event connections + and manage a number of attachable services. + */ + struct IServiceHost : public boost::noncopyable + { + protected: + IServiceHost(); + public: + virtual ~IServiceHost() {} + + /** Start the IServiceHost and all registered services. + @note Services can be added after the IServiceHost has been started. + */ + bool start(); + /** Stop the IServiceHost and all registered services. + */ + void stop(); + + virtual NetEventConnectionPtr getEventConnection() const = 0; + //virtual net::IPacketConnection* getPacketConnection() const = 0; + //virtual net::IClientPacketConnection* getClientPacketConnection() const = 0; + //virtual net::IServerPacketConnection* getServerPacketConnection() const = 0; + + // mirror detail::ServiceManager interface (internally forwarded) + + /** Adds a service to the host. The host takes control over + starting and stopping the service. + @note The service should not have been started when it is passed to addService()! + @remarks Services can be added before or after starting the IServiceHost. + If an IService is added before start() has been called, then its onStart() + callback will be called when start() is finally called. + If an IService is added after start() has been called, then its onStart() + callback will be immediately called from within the addService() method. + */ + void addService(IServicePtr, const std::string& tag = ""); + /** Removes the given service. + @note The service is stopped if it's running. + */ + IServicePtr removeService(IServicePtr); + /** Removes the service identified by the given tag. + @note The service is stopped if it's running. + */ + IServicePtr removeService(const std::string&); + /** Removes all services. + @note Services are stopped if they're running. + */ + void removeAllServices(); + /** Returns a pointer to the service identified by the given tag. + */ + IServicePtr getService(const std::string& tag) const; + + typedef net::INetEventConnection::EvtProcessEventFn EvtProcessEventFn; + /** Use this method to subscribe to certain net events on a specific channel. + */ + SignalConnection subscribeToNetEvent( + const net::NetEvent::id_type, const net::ChannelId, const EvtProcessEventFn& fn); + + /** Use this method to subscribe to all net events on a specific channel. + */ + SignalConnection subscribeToNetEventChannel( + const net::ChannelId, const EvtProcessEventFn& fn); + private: + virtual bool onStart() = 0; + virtual void onStop() = 0; + protected: + /** Returns true if the IServiceHost has been started, otherwise false. + */ + bool running() const; + /** Dispatches received net events to registered listeners. + @see subscribeToNetEvent + @see subscribeToNetEventChannel + */ + void dispatchNetEvent(const net::PeerId, const net::NetEvent&, const net::ChannelId); + private: + detail::ServiceManager serviceMgr_; + volatile bool running_; + mutable boost::mutex runningMtx_; + + typedef SignalX<void(const net::PeerId, const net::NetEvent&, const net::ChannelId)> ProcessEventSig; + typedef SharedPtr<ProcessEventSig> ProcessEventSigPtr; + + typedef std::pair<net::ChannelId,net::NetEvent::id_type> ChannelEventIdPair; + typedef std::map<ChannelEventIdPair,ProcessEventSigPtr> SigMap; + + struct EventIdEntry + { + ProcessEventSigPtr sig_; + }; + SigMap sigMap_; + }; + +} // namespace net +} // namespace yake + +#endif Added: trunk/yake/yake/netsvc/pch.h =================================================================== --- trunk/yake/yake/netsvc/pch.h (rev 0) +++ trunk/yake/yake/netsvc/pch.h 2006-12-03 00:45:15 UTC (rev 1510) @@ -0,0 +1,7 @@ +#ifndef YAKE_NET_PCH_H +#define YAKE_NET_PCH_H + +#include <yake/base/yake.h> + +#endif + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:19:23
|
Revision: 1509 http://svn.sourceforge.net/yake/?rev=1509&view=rev Author: psyclonist Date: 2006-12-02 16:19:23 -0800 (Sat, 02 Dec 2006) Log Message: ----------- removed deprecated ConfigFile/ConfigNode code, added Configuration class based on boost::property_tree Modified Paths: -------------- trunk/yake/yake/base/yakeConfigFile.h Modified: trunk/yake/yake/base/yakeConfigFile.h =================================================================== --- trunk/yake/yake/base/yakeConfigFile.h 2006-12-03 00:18:45 UTC (rev 1508) +++ trunk/yake/yake/base/yakeConfigFile.h 2006-12-03 00:19:23 UTC (rev 1509) @@ -27,121 +27,219 @@ #ifndef YAKE_BASE_CONFIGFILE_H #define YAKE_BASE_CONFIGFILE_H -//============================================================================ -// IMPLEMENTATION HEADERS -//============================================================================ // Standard headers #ifndef YAKE_BASE_PREREQUISITES_H # include <yake/base/yakePrerequisites.h> #endif -//============================================================================ -// INTERFACE STRUCTURES / UTILITY CLASSES -//============================================================================ -namespace yake -{ -namespace base -{ +// for Configuration +#include <boost/property_tree/ptree.hpp> +#include <boost/property_tree/xml_parser.hpp> +#include <boost/property_tree/info_parser.hpp> -/** Represents node in a hierarchical configuration file. -* \todo Modify it to use 'weak ptr'. -*/ -class YAKE_BASE_API ConfigNode -{ -// Types -public: - typedef std::map< String, String > KeyValueMap; - typedef std::map< String, ConfigNode* > ConfigNodeList; +// Undef min and max macros on Windows. They're defined in windef.h. +// And unfortunately, the property_tree includes pull them in. +#if (YAKE_PLATFORM == PLATFORM_WIN32) + #ifdef min + #undef min + #endif + #ifdef max + #undef max + #endif +#endif -// Class -private: - ConfigNode( const ConfigNode& ); -public: - ConfigNode() : mName( "" ) {} +namespace yake { +namespace base { -// Methods -public: - /** C'tor, specifying node name. - \param name the name of this configuration node. - \return - */ - ConfigNode( const String& rName ); - ~ConfigNode(); + struct Configuration + { + // types + typedef boost::property_tree::ptree tree_type; + typedef SharedPtr<tree_type> tree_ptr; + typedef tree_type::const_iterator const_iterator; + typedef tree_type::value_type value_type; - /** Get this node's name. - \return this configuration node's name. - */ - String getName() const; + /** Construct empty configuration object. */ + Configuration() : tree_( new tree_type() ) + { + } + /** Copy-construct configuration object. + @note Both Configurations share the data! + */ + Configuration(const Configuration& other) : tree_(other.tree_), prefix_(other.prefix_) + { + } + /** Copy configuration data. + @note Both Configurations share the data! + */ + Configuration& operator=(const Configuration& rhs) + { + if (this == &rhs) + return *this; + tree_ = rhs.tree_; + prefix_ = rhs.prefix_; + return *this; + } + /** Copy-construct configuration but with optional offset into the hierarchy (i.e. path != ""). + */ + Configuration(const Configuration& cfg, const String& path) : tree_( cfg.tree_ ), prefix_(path) + { + if (!prefix_.empty()) + { + // make sure there's a trailing '/' + if (prefix_.at( prefix_.size() -1 ) != '/') + prefix_ += '/'; + } + } + void copyFrom(const Configuration& other) + { + tree_.reset( new tree_type() ); + if (other.tree_) + *tree_ = *other.tree_; + prefix_ = other.prefix_; + } + ~Configuration() + { + } - /** Return the value associated to the key <key>. - \param key The key for which the value shall be returned. - \return the string containing the value associated with <key>. - */ - String getValue( const String& rKey ); - - /** Adds a key-value pair to the configuration node. - One key can be associated with one value. - \param key the key string. - \param value the associated value string. - */ - void addKeyValuePair( const String& rKey, const String& rValue ); + /** Returns iterator to the first of any children. + */ + const_iterator begin(const String& path = "") const + { + try { + return tree_->get_child('/',prefix_+path).begin(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + /** Returns iterator to one element beyond the last of any children. + */ + const_iterator end(const String& path = "") const + { + try { + return tree_->get_child('/',prefix_+path).end(); + } + catch (boost::property_tree::ptree_error&) + { + return tree_->end(); + } + } + bool exists(const String& path) const + { + try { + tree_->get_child('/',prefix_+path); + return true; + } + catch (boost::property_tree::ptree_error&) + { + return false; + } + } - /** Get a child by its name. - \param name the child node's name. - \return a pointer to the child node or 0 if there's no child with the given name. - */ - ConfigNode* getNodeByName( const String& rName ); - - /** Adds a configuration node to the node's list of child nodes. - Ownership transfers to this node. - \param node a pointer to free configuration node. - */ - void addNode( ConfigNode* rNode ); + /** Returns the value for the given path. + @note Throws if node does not exist! + */ + template<typename T> + T get(const String& pathToValue) + { + tree_->get<T>('/',prefix_+pathToValue); + } + /** Returns either value for the given path, or the default value if the path does not exist + or if the type conversion failed. + */ + String get(const String& pathToValue, const String& defaultValue) + { + try { + return tree_->get<String>('/',prefix_+pathToValue); + } + catch (...) + { + return defaultValue; + } + } + /** Returns either value for the given path, or the default value if the path does not exist + or if the type conversion failed. + @note Type conversion is done automatically. + */ + template<typename T> + T get(const String& pathToValue, const T& defaultValue) + { + try { + return tree_->get<T>('/',prefix_+pathToValue); + } + catch (...) + { + return defaultValue; + } + } -// Data -protected: - KeyValueMap mKeyValueMap; - ConfigNodeList mChildren; - String mName; -}; + /** Sets the value at the given path. + Creates entry at the path if necessary. + */ + template<typename T> + void set(const String& pathToValue, const T& newValue) + { + tree_->put('/',prefix_+pathToValue,newValue); + } -/** Represents a hierarchical configuration file. -* \todo Modify it to use 'weak ptr'. -*/ -class YAKE_BASE_API ConfigFile -{ -// Class -private: - ConfigFile( const ConfigFile& ); -public: - ConfigFile( const String& rFile = "" ); - ~ConfigFile(); + /** Overwrites existing configuration values if conflicts appear! + */ + void readFromFile(const String& fn, const String& insertAt = "") + { + assert( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_info(in,*tree_); + } + /** Overwrites existing configuration values if conflicts appear! + */ + void readFromXML(const String& fn, const String& insertAt = "") + { + assert( insertAt.empty() && "not yet supported" ); + std::ifstream in(fn.c_str()); + if (!in.is_open()) + return; //@todo + boost::property_tree::read_xml(in,*tree_); + } + /** + @note Ignores any set offset/prefix! + */ + void writeToFile(const String& fn, const String& startAt = "") + { + assert( startAt.empty() && "not yet supported" ); + boost::property_tree::write_info(cout,*tree_); -// Methods -public: - /** Load a configuration file. If <file> is empty - then the filename specified at construction time - will be used. If it was empty, too, no configuration - file will be loaded. - \param file configuration file name - \return true on success, false on error. - */ - bool load( const String& rFile = "" ); + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_info(out,*tree_); + } + /** + @note Ignores any set offset/prefix! + */ + void writeToXML(const String& fn, const String& startAt = "") + { + assert( startAt.empty() && "not yet supported" ); + boost::property_tree::write_xml(cout,*tree_); - /** Get a pointer to the root node of the configuration node tree. - There can be only one root. - Ownership is _not_ transferred. - \return pointer to the configuration tree's root node. - */ - RefPtr<ConfigNode> getRootNode(); + std::ofstream out(fn.c_str()); + if (!out.is_open()) + return; //@todo + boost::property_tree::write_xml(out,*tree_); + } -// Data -protected: - String filename_; - RefPtr<ConfigNode> mRootNode; -}; + private: + tree_ptr tree_; + String prefix_; + }; } // base + + // pull in type + typedef base::Configuration Configuration; } // yake #endif // YAKE_BASE_CONFIGFILE_H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:18:46
|
Revision: 1508 http://svn.sourceforge.net/yake/?rev=1508&view=rev Author: psyclonist Date: 2006-12-02 16:18:45 -0800 (Sat, 02 Dec 2006) Log Message: ----------- added ro::server::setInterface(), added debug output Modified Paths: -------------- trunk/yake/src/yake/samples/net/roclient/ROClient.cpp trunk/yake/src/yake/samples/net/roserver/ROServer.cpp trunk/yake/yake/samples/net/roserver/ROServer.h Modified: trunk/yake/src/yake/samples/net/roclient/ROClient.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-12-03 00:17:33 UTC (rev 1507) +++ trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-12-03 00:18:45 UTC (rev 1508) @@ -34,6 +34,7 @@ conn_->addStartedCallback( boost::bind(&client::onClientStarted,this) ); // attempt to connect to server + COUTLN("trying to connect to '" << serverAddr_.ip() << ":" << serverAddr_.port() << "' ..."); /* conn_->connect( serverAddr_, true, 2000 ); */ Modified: trunk/yake/src/yake/samples/net/roserver/ROServer.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-12-03 00:17:33 UTC (rev 1507) +++ trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-12-03 00:18:45 UTC (rev 1508) @@ -243,13 +243,17 @@ //----------------------------------------------------------------------------- - server::server() : packetConnStarted_(false) + server::server() : packetConnStarted_(false), bindInterface_("127.0.0.1:40000") { } server::~server() { stop(); } + void server::setInterface(const net::Address& bindInterface) + { + bindInterface_ = bindInterface; + } /* void server::queueEvent(const net::PeerId id, net::NetEvent* evt, const net::ChannelId cId) { @@ -284,7 +288,6 @@ if (conn_) return true; - const uint16 port = 40000; const size_t maxClients = 32; conn_.reset( net::createServerPacketConnection() ); @@ -294,8 +297,8 @@ conn_->addPacketReceivedCallback( boost::bind(&server::onReceivePacket,this,_1,_2,_3) ); conn_->addClientDisconnectedCallback( boost::bind(&server::onClientDisconnected,this,_1) ); - COUTLN("starting server at port " << port << " with max. " << maxClients << " clients..."); - conn_->start( net::Address(port), maxClients ); + COUTLN("starting server at '" << bindInterface_.ip() << ":" << bindInterface_.port() << "' with max. " << maxClients << " clients..."); + conn_->start( bindInterface_, maxClients ); // wait until net object is up while (!packetConnStarted_) Modified: trunk/yake/yake/samples/net/roserver/ROServer.h =================================================================== --- trunk/yake/yake/samples/net/roserver/ROServer.h 2006-12-03 00:17:33 UTC (rev 1507) +++ trunk/yake/yake/samples/net/roserver/ROServer.h 2006-12-03 00:18:45 UTC (rev 1508) @@ -17,6 +17,9 @@ server(); ~server(); + // Call before start() + void setInterface(const net::Address&); + // implement IServiceHost interface virtual NetEventConnectionPtr getEventConnection() const { return this->evtConn_; } @@ -69,6 +72,7 @@ private: // internal callback void onClientSimStarted(iclient&); private: + net::Address bindInterface_; // volatile bool packetConnStarted_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:17:36
|
Revision: 1507 http://svn.sourceforge.net/yake/?rev=1507&view=rev Author: psyclonist Date: 2006-12-02 16:17:33 -0800 (Sat, 02 Dec 2006) Log Message: ----------- remove assertion Modified Paths: -------------- trunk/yake/src/yake/net/detail/netInternal.cpp Modified: trunk/yake/src/yake/net/detail/netInternal.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netInternal.cpp 2006-12-03 00:17:13 UTC (rev 1506) +++ trunk/yake/src/yake/net/detail/netInternal.cpp 2006-12-03 00:17:33 UTC (rev 1507) @@ -43,7 +43,7 @@ } void UpdateThread::destroy() { - NET_ASSERT( instance_ ); + //NET_ASSERT( instance_ ); if (instance_) { instance_->requestQuit(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:17:13
|
Revision: 1506 http://svn.sourceforge.net/yake/?rev=1506&view=rev Author: psyclonist Date: 2006-12-02 16:17:13 -0800 (Sat, 02 Dec 2006) Log Message: ----------- fix: use event name Modified Paths: -------------- trunk/yake/src/yake/plugins/entLua/entLua.cpp Modified: trunk/yake/src/yake/plugins/entLua/entLua.cpp =================================================================== --- trunk/yake/src/yake/plugins/entLua/entLua.cpp 2006-12-03 00:16:51 UTC (rev 1505) +++ trunk/yake/src/yake/plugins/entLua/entLua.cpp 2006-12-03 00:17:13 UTC (rev 1506) @@ -103,10 +103,7 @@ Entity* ent = Entity::cast(&obj); if (ent) { - if (evt == "spawn") - ent->getFsmVM()->execute("event.on_spawn()"); - else if (evt == "die") - ent->getFsmVM()->execute("event.on_die()"); + ent->getFsmVM()->execute("event.on_" + evt + "()"); } } void LuaFsmObjectListener::onFsmEnterState(Object& obj,/*const std::string& fsmName, */const object_fsm&, const object_fsm::state_type& state) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:16:50
|
Revision: 1505 http://svn.sourceforge.net/yake/?rev=1505&view=rev Author: psyclonist Date: 2006-12-02 16:16:51 -0800 (Sat, 02 Dec 2006) Log Message: ----------- alternative c'tor that extracts ip and port from a single string (e.g. "127.0.0.1:40000") Modified Paths: -------------- trunk/yake/yake/net/netCommon.h Modified: trunk/yake/yake/net/netCommon.h =================================================================== --- trunk/yake/yake/net/netCommon.h 2006-12-03 00:16:25 UTC (rev 1504) +++ trunk/yake/yake/net/netCommon.h 2006-12-03 00:16:51 UTC (rev 1505) @@ -84,8 +84,12 @@ /** Initializes the IP with "127.0.0.1". */ Address(const uint16 port); + /** Initialize IP and port from string. */ + Address(const std::string& ipAndPort = std::string("127.0.0.1:0")); + /** Initialize IP. */ - Address(const std::string& ip = std::string("127.0.0.1"), const uint16 port = 0); + Address(const std::string& ip, const uint16 port); + /** Initializes with data from another address. */ Address(const Address&); ~Address(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:16:25
|
Revision: 1504 http://svn.sourceforge.net/yake/?rev=1504&view=rev Author: psyclonist Date: 2006-12-02 16:16:25 -0800 (Sat, 02 Dec 2006) Log Message: ----------- alternative c'tor that extracts ip and port from a single string (e.g. "127.0.0.1:40000") Modified Paths: -------------- trunk/yake/src/yake/net/detail/netCommon.cpp Modified: trunk/yake/src/yake/net/detail/netCommon.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netCommon.cpp 2006-12-03 00:15:33 UTC (rev 1503) +++ trunk/yake/src/yake/net/detail/netCommon.cpp 2006-12-03 00:16:25 UTC (rev 1504) @@ -2,6 +2,7 @@ #include <sstream> #include <yake/net/net.h> #include <yake/base/native/yakeNative.h> +#include <boost/lexical_cast.hpp> // Modify the following defines if you have to target a platform prior to the ones specified below. // Refer to MSDN for the latest info on corresponding values for different platforms. @@ -84,6 +85,14 @@ Address::Address(const uint16 port) : ip_("127.0.0.1"), port_(port) {} + Address::Address(const std::string& ipAndPort) : port_(0) + { + const Vector<std::string> ret = split<std::string>(ipAndPort,":"); + if (ret.size() > 0) + ip_ = ret.at(0); + if (ret.size() > 1) + port_ = boost::lexical_cast<int>(ret.at(1)); + } Address::Address(const std::string& ip, const uint16 port) : ip_(ip), port_(port) {} Address::Address(const Address& other) : ip_(other.ip_), port_(other.port_) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-03 00:15:33
|
Revision: 1503 http://svn.sourceforge.net/yake/?rev=1503&view=rev Author: psyclonist Date: 2006-12-02 16:15:33 -0800 (Sat, 02 Dec 2006) Log Message: ----------- new options "server/bind" and "client/server" Modified Paths: -------------- trunk/yake/common/bin/debug/rodemo.cfg trunk/yake/common/bin/debug/rodemo_client.cfg Modified: trunk/yake/common/bin/debug/rodemo.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo.cfg 2006-12-02 20:17:23 UTC (rev 1502) +++ trunk/yake/common/bin/debug/rodemo.cfg 2006-12-03 00:15:33 UTC (rev 1503) @@ -3,6 +3,7 @@ server { start 1 + bind 192.168.1.33:40000 } client { Modified: trunk/yake/common/bin/debug/rodemo_client.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo_client.cfg 2006-12-02 20:17:23 UTC (rev 1502) +++ trunk/yake/common/bin/debug/rodemo_client.cfg 2006-12-03 00:15:33 UTC (rev 1503) @@ -6,6 +6,7 @@ } client { + server 192.168.1.33:40000 count 1 } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-12-02 20:17:24
|
Revision: 1502 http://svn.sourceforge.net/yake/?rev=1502&view=rev Author: psyclonist Date: 2006-12-02 12:17:23 -0800 (Sat, 02 Dec 2006) Log Message: ----------- It is now possible to add and remove listeners when messages are processed Modified Paths: -------------- trunk/yake/yake/msg/listener_mgr.h Modified: trunk/yake/yake/msg/listener_mgr.h =================================================================== --- trunk/yake/yake/msg/listener_mgr.h 2006-11-28 22:41:28 UTC (rev 1501) +++ trunk/yake/yake/msg/listener_mgr.h 2006-12-02 20:17:23 UTC (rev 1502) @@ -107,6 +107,7 @@ namespace detail { /** Internal base class providing listener management and a hook for derived routers/processors. + @note It is possible to add and remove listeners while messages are processed. */ template<typename source_type,typename target_type> struct msg_listener_mgr @@ -148,6 +149,8 @@ YAKE_ASSERT( source != traits_type::kAnySource ); // should be kNoSource if there's no source. YAKE_ASSERT( target != traits_type::kAnyTarget ); // should be kBroadcastTarget. + listener_list listenerCache; + // find 'kAnySource' source typename source_map::const_iterator itSource = sources_.find(traits_type::kAnySource); if (itSource != sources_.end()) @@ -155,47 +158,56 @@ // find listeners for specified target typename target_map::const_iterator itTarget = itSource->second.find(msg->target()); if (itTarget != itSource->second.end()) - _processListeners( msg, itTarget->second ); + _cacheListeners( msg->msgTypeName(), itTarget->second, listenerCache ); // find listeners for special 'kAnyTarget' itTarget = itSource->second.find(traits<source_type,target_type>::kAnyTarget); if (itTarget != itSource->second.end()) - _processListeners( msg, itTarget->second ); + _cacheListeners( msg->msgTypeName(), itTarget->second, listenerCache ); } // find source itSource = sources_.find(source); - if (itSource == sources_.end()) - return; + if (itSource != sources_.end()) + { + const target_map& targets = itSource->second; - const target_map& targets = itSource->second; + // process listeners that have subscribed to all messages of this source + typename target_map::const_iterator itAnyTargetListeners = targets.find(traits_type::kAnyTarget); + if (itAnyTargetListeners != targets.end()) + _cacheListeners( msg->msgTypeName(), itAnyTargetListeners->second, listenerCache ); - // process listeners that have subscribed to all messages of this source - typename target_map::const_iterator itAnyTargetListeners = targets.find(traits_type::kAnyTarget); - if (itAnyTargetListeners != targets.end()) - _processListeners( msg, itAnyTargetListeners->second ); - - // broadcast or targeted message? - if (target == traits<source_type,target_type>::kBroadcastTarget) - { - // broadcasting - iterate over all targets: - typename target_map::const_iterator itEnd = targets.end(); - for (typename target_map::const_iterator itTarget = targets.begin(); itTarget != itEnd; ++itTarget) + // broadcast or targeted message? + if (target == traits<source_type,target_type>::kBroadcastTarget) { - if (itTarget->first == traits<source_type,target_type>::kAnyTarget) // We already have processed them above. - continue; - _processListeners( msg, itTarget->second ); + // broadcasting - iterate over all targets: + typename target_map::const_iterator itEnd = targets.end(); + for (typename target_map::const_iterator itTarget = targets.begin(); itTarget != itEnd; ++itTarget) + { + if (itTarget->first == traits<source_type,target_type>::kAnyTarget) // We already have processed them above. + continue; + _cacheListeners( msg->msgTypeName(), itTarget->second, listenerCache ); + } } - } - else + else + { + // targetted message - find target: + typename target_map::const_iterator itTarget = targets.find(msg->target()); + if (itTarget != targets.end()) + { + // find message type & process message if found. + _cacheListeners( msg->msgTypeName(), itTarget->second, listenerCache ); + } + } + } // source + + // process + for(listener_list::iterator itListener = listenerCache.begin(); itListener != listenerCache.end(); ++itListener) { - // targetted message - find target: - typename target_map::const_iterator itTarget = targets.find(msg->target()); - if (itTarget == targets.end()) - return; - // find message type & process message if found. - _processListeners( msg, itTarget->second ); + (*itListener)->execute(*msg); } + listenerCache.clear(); + // clean up MSG_NAMESPACE::destroyMessage(msg); } @@ -242,6 +254,16 @@ for (typename listener_list::const_iterator it = l.begin(); it != l.end(); ++it) (*it)->execute(*msg); } + void _cacheListeners(const String& msgTypeName, const listener_map& listeners, listener_list& listenerCache) + { + // find message type + typename listener_map::const_iterator itMsgType = listeners.find(msgTypeName); + if (itMsgType == listeners.end()) + return; + // find listeners + const listener_list& l = itMsgType->second; + std::copy(l.begin(),l.end(),std::back_inserter(listenerCache)); + } protected: void setProcessing(const bool yes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-28 22:41:30
|
Revision: 1501 http://svn.sourceforge.net/yake/?rev=1501&view=rev Author: psyclonist Date: 2006-11-28 14:41:28 -0800 (Tue, 28 Nov 2006) Log Message: ----------- added documentation, added net::Timer::set(), added common PING/PONG events Modified Paths: -------------- trunk/yake/src/yake/net/detail/netCommon.cpp trunk/yake/yake/net/netCommon.h trunk/yake/yake/net/netEvent.h trunk/yake/yake/samples/net/common/commonEvents.h trunk/yake/yake/samples/net/common/roCommon.h Modified: trunk/yake/src/yake/net/detail/netCommon.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netCommon.cpp 2006-11-23 22:10:30 UTC (rev 1500) +++ trunk/yake/src/yake/net/detail/netCommon.cpp 2006-11-28 22:41:28 UTC (rev 1501) @@ -225,6 +225,10 @@ Timer::~Timer() { } + void Timer::set(const double time) + { + YAKE_ASSERT(0); + } void Timer::start() { start_ = ::yake::native::getTime(); Modified: trunk/yake/yake/net/netCommon.h =================================================================== --- trunk/yake/yake/net/netCommon.h 2006-11-23 22:10:30 UTC (rev 1500) +++ trunk/yake/yake/net/netCommon.h 2006-11-28 22:41:28 UTC (rev 1501) @@ -14,25 +14,26 @@ /** Used to identify network peers. */ typedef uint32 PeerId; + /** Special ID reserved to indicate the 'broadcast target'. */ const PeerId PEERID_BROADCAST = 0xffffffff; - /** Specifies the reliability method a packet will be transferred with. */ + /** Specifies the reliability method a packet can be transferred with. */ enum Reliability { R_RELIABLE = 0, R_UNRELIABLE }; - /** Specifies the ordering method a packet will be transferred with. */ + + /** Specifies the ordering method a packet can be transferred with. */ enum Ordering { O_ORDERED = 0, O_UNORDERED }; - /** Represents a specifically configured set of options. - It used for specifying additional information and hints - when sending data/packets. - Usage example: conn.send(buf.data(),buf.size(), SendOptions().setOrdering(O_ORDERED).setReliability(R_RELIABLED)); + /** Represents a specifically configured set of options and hints used for + sending one or more packets. + Usage example: conn.send(buf.data(),buf.size(), SendOptions().ordered().reliable()); */ struct NET_API SendOptions { @@ -45,17 +46,28 @@ @Remarks This setting is ignored by broadcast functions! */ SendOptions& peerId(const PeerId); + /** Set reliability method. */ SendOptions& reliability(const Reliability); + /** Set reliability method to R_RELIABLE. */ SendOptions& reliable(); + /** Set reliability method to R_UNRELIABLE. */ SendOptions& unreliable(); + /** Set ordering method. */ SendOptions& ordering(const Ordering); + /** Set ordering method to O_ORDERED. */ SendOptions& ordered(); + /** Set ordering method to O_UNORDERED. */ SendOptions& unordered(); + /** Set the channel to use. */ SendOptions& channel(const ChannelId); + /** Returns the target peer id (can also be special value like PEERID_BROADCAST). */ PeerId getPeerId() const; + /** Returns reliability method to be used for sending. */ Reliability getReliability() const; + /** Returns Ordering method to be used for sending. */ Ordering getOrdering() const; + /** Returns the channel to be used for sending. */ ChannelId getChannel() const; private: PeerId peerId_; @@ -64,20 +76,29 @@ ChannelId channelId_; }; - /** Represents a network address (IP + port pair). + /** Represents a network address (IP/host name and port pair). + IP/host name is represented as a string. */ struct NET_API Address { /** Initializes the IP with "127.0.0.1". */ Address(const uint16 port); + + /** Initialize IP. */ Address(const std::string& ip = std::string("127.0.0.1"), const uint16 port = 0); + /** Initializes with data from another address. */ Address(const Address&); ~Address(); + /** Assigns data from another address to this one. */ Address& operator=(const Address&); + /** Sets the IP or host name. */ void setIp(const std::string& ip); + /** Returns the IP or host name. */ const std::string& ip() const; + /** Sets the port number. */ void setPort(const uint16 port); + /** Returns the port number. */ const uint16 port() const; private: std::string ip_; @@ -92,7 +113,7 @@ namespace native { /** Sleeps the active thread for a certain number of milliseconds. This also yields the thread! (For example, a Win32 implementation - may use ::Sleep().) + may use ::Sleep() internally.) */ NET_API void sleep(const uint32 ms); } // namespace native @@ -102,6 +123,7 @@ { Exception(const std::string& msg, const char* file = 0, const int line = 0); virtual ~Exception() throw() {} + /** Return a descriptive string with details on the exception. */ virtual const char* what() const throw(); private: std::string msg_; @@ -114,12 +136,19 @@ public: Timer(); ~Timer(); + /** Starts timing. */ void start(); + /** Stops timing. Use start() to restart. */ void stop(); + /** Pauses timing. Use resume() to continue. */ void pause(); + /** Resumes timing after pause() has been called. */ void resume(); + /** Reset time to 0. */ void reset(); + /** Returns the total elapsed time in seconds. */ double getTime() const; + void set(const double); private: double start_; mutable double time_; @@ -128,6 +157,8 @@ typedef uint8 byte; typedef byte* byte_ptr; + /** Represents a chunk of data with functionality for resizing. + */ struct NET_API DataChunk { public: @@ -206,16 +237,22 @@ size_t dataSize_; }; + /** Represents a packet for sending and receiving. + */ struct NET_API Packet : boost::noncopyable { + /** Construct packet, optionally copying existing data. */ Packet(const void* dataPtr = 0, const size_t dataSize = 0); //SendOptions& options(); //const SendOptions& options() const; + + /** Access packet payload (the contained information). */ const DataChunk& payload() const; private: DataChunk payload_; //SendOptions opt_; }; + /** Shared pointer for packets is used for flexible lifetime control. */ typedef yake::SharedPtr<Packet> PacketPtr; } // namespace net Modified: trunk/yake/yake/net/netEvent.h =================================================================== --- trunk/yake/yake/net/netEvent.h 2006-11-23 22:10:30 UTC (rev 1500) +++ trunk/yake/yake/net/netEvent.h 2006-11-28 22:41:28 UTC (rev 1501) @@ -14,13 +14,25 @@ typedef ByteVectorSink bitstream_sink; typedef ByteVectorSource bitstream_source; + /** Base class for event objects that can be sent and received via + INetEventConnections. + @see INetEventConnection + */ class NET_API NetEvent { public: virtual ~NetEvent() {} + /** Type to identify events. */ typedef uint8 id_type; + /** Special value used in certain circumstances. + It is defined as 0xff. + */ static const id_type EVTID_NONE; + /** Direction events can travel. + @todo replace with DIR_OUTGOING and DIR_INCOMING instead of + DIR_CLIENT_TO_SERVER and DIR_SERVER_TO_CLIENT. + */ enum Direction { DIR_ANY, DIR_CLIENT_TO_SERVER, //@todo make DIR_OUTGOING @@ -35,10 +47,17 @@ NetEvent(const id_type); public: + /** Returns the ID of this event. */ id_type id() const; void setId(const id_type id); //@really needed? + /** Serialize event information into the bitstream. + @note It is not necessary to serialize the event id. + */ virtual bool pack(obitstream&) const = 0; + /** Deserialize event information. + @note Format has to match the one used in pack() obviously. + */ virtual bool unpack(ibitstream&) = 0; //NetEvent* clone(); Modified: trunk/yake/yake/samples/net/common/commonEvents.h =================================================================== --- trunk/yake/yake/samples/net/common/commonEvents.h 2006-11-23 22:10:30 UTC (rev 1500) +++ trunk/yake/yake/samples/net/common/commonEvents.h 2006-11-28 22:41:28 UTC (rev 1501) @@ -340,4 +340,61 @@ } std::string cId_; }; +struct s2cEvtPing : public yake::net::NetEvent +{ + DECLARE_EVENT( s2cEvtPing, 40 ); + s2cEvtPing(const yake::uint32 serverTime) : + yake::net::NetEvent(ID), serverTime_(serverTime) + {} + virtual bool pack(yake::net::obitstream& out) const + { + out << serverTime_; + return true; + } + virtual bool unpack(yake::net::ibitstream& in) + { + in >> serverTime_; + return true; + } + yake::uint32 serverTime_; +}; +struct c2sEvtPong : public yake::net::NetEvent +{ + DECLARE_EVENT( c2sEvtPong, 41 ); + c2sEvtPong(const yake::uint32 clientTime, const yake::uint32 serverTime) : + yake::net::NetEvent(ID), clientTime_(clientTime), serverTime_(serverTime) + {} + virtual bool pack(yake::net::obitstream& out) const + { + out << serverTime_ << clientTime_; + return true; + } + virtual bool unpack(yake::net::ibitstream& in) + { + in >> serverTime_ >> clientTime_; + return true; + } + yake::uint32 serverTime_; + yake::uint32 clientTime_; +}; +struct s2cEvtPong : public yake::net::NetEvent +{ + DECLARE_EVENT( s2cEvtPong, 42 ); + s2cEvtPong(const yake::uint32 serverTime2_, const yake::uint32 clientTime, const yake::uint32 serverTime) : + yake::net::NetEvent(ID), clientTime_(clientTime), serverTime_(serverTime), serverTime2_(serverTime_) + {} + virtual bool pack(yake::net::obitstream& out) const + { + out << serverTime_ << clientTime_ << serverTime2_; + return true; + } + virtual bool unpack(yake::net::ibitstream& in) + { + in >> serverTime_ >> clientTime_ >> serverTime2_; + return true; + } + yake::uint32 serverTime_; + yake::uint32 serverTime2_; + yake::uint32 clientTime_; +}; #endif Modified: trunk/yake/yake/samples/net/common/roCommon.h =================================================================== --- trunk/yake/yake/samples/net/common/roCommon.h 2006-11-23 22:10:30 UTC (rev 1500) +++ trunk/yake/yake/samples/net/common/roCommon.h 2006-11-28 22:41:28 UTC (rev 1501) @@ -7,17 +7,33 @@ namespace yake { namespace ro { struct IServiceHost; + /** Represents a service that can be plugged added to and managed by an IServiceHost. + */ struct IService : public boost::noncopyable { virtual ~IService() {} + /** Callback is triggered when the service should start and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ virtual void onStart(IServiceHost&) = 0; + /** Callback is triggered when the service should stop and + has to be overridden by derived classes. + @note An IServiceHost may decide to start and stop services + under various circumstances. + */ virtual void onStop(IServiceHost&) = 0; }; + /** Shared pointer managing an IService pointer. */ typedef SharedPtr<IService> IServicePtr; namespace detail { - //@todo private/impl + /** Implementation specific object managing + a number of services. + @todo Move into private area (i.e. where library users cannot see it). + */ struct ServiceManager : public boost::noncopyable { void addService(IServicePtr, const std::string& tag = ""); @@ -38,6 +54,9 @@ }; } // namespace detail typedef SharedPtr<net::INetEventConnection> NetEventConnectionPtr; + /** Base class for objects that have control over packet and event connections + and manage a number of attachable services. + */ struct IServiceHost : public boost::noncopyable { protected: @@ -45,7 +64,12 @@ public: virtual ~IServiceHost() {} + /** Start the IServiceHost and all registered services. + @note Services can be added after the IServiceHost has been started. + */ bool start(); + /** Stop the IServiceHost and all registered services. + */ void stop(); virtual NetEventConnectionPtr getEventConnection() const = 0; @@ -54,22 +78,54 @@ //virtual net::IServerPacketConnection* getServerPacketConnection() const = 0; // mirror detail::ServiceManager interface (internally forwarded) + + /** Adds a service to the host. The host takes control over + starting and stopping the service. + @note The service should not have been started when it is passed to addService()! + @remarks Services can be added before or after starting the IServiceHost. + If an IService is added before start() has been called, then its onStart() + callback will be called when start() is finally called. + If an IService is added after start() has been called, then its onStart() + callback will be immediately called from within the addService() method. + */ void addService(IServicePtr, const std::string& tag = ""); + /** Removes the given service. + @note The service is stopped if it's running. + */ IServicePtr removeService(IServicePtr); + /** Removes the service identified by the given tag. + @note The service is stopped if it's running. + */ IServicePtr removeService(const std::string&); + /** Removes all services. + @note Services are stopped if they're running. + */ void removeAllServices(); + /** Returns a pointer to the service identified by the given tag. + */ IServicePtr getService(const std::string& tag) const; typedef net::INetEventConnection::EvtProcessEventFn EvtProcessEventFn; + /** Use this method to subscribe to certain net events on a specific channel. + */ SignalConnection subscribeToNetEvent( const net::NetEvent::id_type, const net::ChannelId, const EvtProcessEventFn& fn); + + /** Use this method to subscribe to all net events on a specific channel. + */ SignalConnection subscribeToNetEventChannel( const net::ChannelId, const EvtProcessEventFn& fn); private: virtual bool onStart() = 0; virtual void onStop() = 0; protected: + /** Returns true if the IServiceHost has been started, otherwise false. + */ bool running() const; + /** Dispatches received net events to registered listeners. + @see subscribeToNetEvent + @see subscribeToNetEventChannel + */ void dispatchNetEvent(const net::PeerId, const net::NetEvent&, const net::ChannelId); private: detail::ServiceManager serviceMgr_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-23 22:10:41
|
Revision: 1500 http://svn.sourceforge.net/yake/?rev=1500&view=rev Author: psyclonist Date: 2006-11-23 14:10:30 -0800 (Thu, 23 Nov 2006) Log Message: ----------- set version to 0.6.0dev, added yake/raf to API docs script Modified Paths: -------------- trunk/yake/documentation/api/DoxySfile trunk/yake/documentation/api/docMainPage.h Modified: trunk/yake/documentation/api/DoxySfile =================================================================== --- trunk/yake/documentation/api/DoxySfile 2006-11-18 22:21:57 UTC (rev 1499) +++ trunk/yake/documentation/api/DoxySfile 2006-11-23 22:10:30 UTC (rev 1500) @@ -4,9 +4,9 @@ # General configuration options #--------------------------------------------------------------------------- PROJECT_NAME = YAKE -PROJECT_NUMBER = 0.5.0-dev +PROJECT_NUMBER = 0.6.0-dev #INPUT = yake/msg -INPUT = documentation/api yake/base/math yake/base/mpl yake/base/native yake/base/templates yake/base yake/audio yake/data yake/ent yake/file yake/graphics yake/input yake/net yake/object yake/physics yake/prop yake/scripting yake/statemachine yake/msg yake/model +INPUT = documentation/api yake/base/math yake/base/mpl yake/base/native yake/base/templates yake/base yake/audio yake/data yake/ent yake/file yake/graphics yake/input yake/net yake/object yake/physics yake/prop yake/scripting yake/statemachine yake/msg yake/model yapp/raf OUTPUT_DIRECTORY = documentation/api/html GENERATE_DOXYS_HELP = YES HTML_FILE_EXTENSION = .html @@ -214,7 +214,7 @@ # - # This could be handy for archiving the generated documentation or # - # if some version control system is used. # - -# - PROJECT_NUMBER = 0.5.0-dev +# - PROJECT_NUMBER = 0.6.0-dev # - # - # The INPUT tag can be used to specify the files and/or directories that contain # - # documented source files. You may enter file names like "myfile.cpp" or Modified: trunk/yake/documentation/api/docMainPage.h =================================================================== --- trunk/yake/documentation/api/docMainPage.h 2006-11-18 22:21:57 UTC (rev 1499) +++ trunk/yake/documentation/api/docMainPage.h 2006-11-23 22:10:30 UTC (rev 1500) @@ -1,6 +1,6 @@ -/** \mainpage "YAKE 0.5.0dev API" +/** \mainpage "YAKE 0.6.0dev API" -!!! YAKE 0.5.0dev API Documentation +!!! YAKE 0.6.0dev API Documentation !! What is this? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-18 22:21:58
|
Revision: 1499 http://svn.sourceforge.net/yake/?rev=1499&view=rev Author: psyclonist Date: 2006-11-18 14:21:57 -0800 (Sat, 18 Nov 2006) Log Message: ----------- added net::scoped_lock, added documentation Modified Paths: -------------- trunk/yake/src/yake/net/detail/netInternal.cpp trunk/yake/src/yake/net/net.cpp trunk/yake/yake/net/net.h trunk/yake/yake/net/netEvent.h trunk/yake/yake/net/netPacket.h Modified: trunk/yake/src/yake/net/detail/netInternal.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-18 21:07:23 UTC (rev 1498) +++ trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-18 22:21:57 UTC (rev 1499) @@ -5,10 +5,29 @@ #include <boost/thread/mutex.hpp> namespace yake { namespace net { + namespace detail { + struct scoped_lock_impl : public boost::noncopyable + { + scoped_lock_impl() + { + lck_.reset( new boost::mutex::scoped_lock(s_mtx_) ); + } + private: + SharedPtr<boost::mutex::scoped_lock> lck_; + static boost::mutex s_mtx_; + }; + boost::mutex scoped_lock_impl::s_mtx_; + } // namespace impl + scoped_lock::scoped_lock() + { + impl_.reset( new detail::scoped_lock_impl() ); + } + scoped_lock::~scoped_lock() + { + } void update() { - static boost::mutex s_mtx; - boost::mutex::scoped_lock lck(s_mtx); + scoped_lock lck; impl::UpdateThread::instance().__update__(); } namespace impl { @@ -79,7 +98,10 @@ return; } - for (UpdateFnMap::iterator it = fns_.begin(); it != fns_.end(); ++it) + // Create a copy of the registered functions in case that + // callbacks modify fns_ (which could/would invalidate the iterator). + UpdateFnMap tmpFns = fns_; + for (UpdateFnMap::iterator it = tmpFns.begin(); it != tmpFns.end(); ++it) { it->second(); } Modified: trunk/yake/src/yake/net/net.cpp =================================================================== --- trunk/yake/src/yake/net/net.cpp 2006-11-18 21:07:23 UTC (rev 1498) +++ trunk/yake/src/yake/net/net.cpp 2006-11-18 22:21:57 UTC (rev 1499) @@ -36,7 +36,8 @@ bool initialize() { - if (enet_initialize() < 0) + scoped_lock lck; + if (::enet_initialize() < 0) { fprintf(stderr, "An error occurred while initializing ENet.\n"); return false; @@ -46,8 +47,9 @@ } void shutdown() { + scoped_lock lck; impl::UpdateThread::destroy(); - enet_deinitialize(); + ::enet_deinitialize(); } } // namespace net Modified: trunk/yake/yake/net/net.h =================================================================== --- trunk/yake/yake/net/net.h 2006-11-18 21:07:23 UTC (rev 1498) +++ trunk/yake/yake/net/net.h 2006-11-18 22:21:57 UTC (rev 1499) @@ -9,10 +9,60 @@ namespace yake { namespace net { + /** One-time initialization function. + @remarks Call it once per application prior to accessing anything else + in yake::net. + @note If called, the corresponding shutdown() function has to be called, too. + @note This function is thread-safe. + @note NEVER call this function when a net::scoped_lock exists / is active! + @see update() + @see shutdown() + @see scoped_lock + */ NET_API bool initialize(); + + /** Service network processing. + Should be called regularly to service the networking objects (receiving, sending, callbacks). + @note This function is thread-safe. + @note NEVER call this function when a net::scoped_lock exists / is active! + @see initialize() + @see shutdown() + @see scoped_lock + */ NET_API void update(); + + /** Cleanup yake::net. + @note This function is thread-safe. + @note NEVER call this function when a net::scoped_lock exists / is active! + @see scoped_lock + @see initialize() + @see update() + */ NET_API void shutdown(); +#pragma warning(push) +#pragma warning(disable: 4275) // 'T' used as base for dll-interface class 'X' + namespace detail { + struct scoped_lock_impl; + } // namespace detail + /** This objects allows to acquire a lock to the global mutex used + by the networking library. + @note By default, only initialize(), update() and shutdown() are synchronized and thread-safe. + Other objects are not! + You may need to make other parts of your application thread-safe with regards to + accessing yake::net objects. In this case, you can use scoped_lock to acquire the lock. + @note NEVER call initialize(), update() or shutdown() if a scoped_lock is active/exists! + At a minimum, this will cause the calling thread to hang as initialize(), update() or + shutdown() wait indefinitely for the mutex to be unlocked! + */ + struct NET_API scoped_lock : public boost::noncopyable + { + scoped_lock(); + ~scoped_lock(); + private: + SharedPtr<detail::scoped_lock_impl> impl_; + }; +#pragma warning(pop) } // namespace net } // namespace yake Modified: trunk/yake/yake/net/netEvent.h =================================================================== --- trunk/yake/yake/net/netEvent.h 2006-11-18 21:07:23 UTC (rev 1498) +++ trunk/yake/yake/net/netEvent.h 2006-11-18 22:21:57 UTC (rev 1499) @@ -23,14 +23,15 @@ static const id_type EVTID_NONE; enum Direction { DIR_ANY, - DIR_CLIENT_TO_SERVER, - DIR_SERVER_TO_CLIENT + DIR_CLIENT_TO_SERVER, //@todo make DIR_OUTGOING + DIR_SERVER_TO_CLIENT //@todo make DIR_INCOMING }; - private: + private: // no default c'tor (so hide it) NetEvent(); + private: // non-copyable: NetEvent(const NetEvent&); NetEvent& operator=(const NetEvent&); - protected: + protected: // c'tor callable by derived types: NetEvent(const id_type); public: @@ -142,36 +143,73 @@ impl::EventConnection* owner_; }; + /** + @note Only registered events can be sent or received. Use registerEvent() before + receiving or sending events of the specified type. + @note Use createEventConnection(). + */ class NET_API INetEventConnection { public: virtual ~INetEventConnection(); + /** Sets the packet connection to be used for sending and receiving events. + @note The packet connection has to be set prior to calling start(). + */ virtual void setPacketConnection(IPacketConnection*,const NetEvent::Direction) = 0; + + /** @todo */ virtual void setMaxEventErrors(const size_t) = 0; + /** Start the event processing. */ virtual bool start() = 0; + /** Stop event processing. */ virtual void stop() = 0; typedef boost::function<NetEvent*(const NetEvent::id_type)> CreateEventFn; typedef boost::function<void(NetEvent*)> DestroyEventFn; + /** Registers an event for use with this event connection object. + @todo Only registered events can be sent or received. + */ virtual void registerEvent(const NetEvent::id_type, const NetEvent::Direction, const CreateEventFn& fnCreate, const DestroyEventFn& fnDestroy) = 0; + /** Broadcasts the event (if its id has been registered!). */ virtual void sendEvent(const NetEvent&, const SendOptions& opt = SendOptions()) = 0; + /** Sends the event (if its id has been registered!). */ virtual void sendEvent(const PeerId, const NetEvent&, const SendOptions& opt = SendOptions()) = 0; + /** @deprecated */ virtual void setAllowedIncomingEventIds(const std::vector<NetEvent::id_type>&) = 0; + /** Activates/Deactivates manual polling. + If activated, poll() should be called regularly to process pending events. + If not activated, every call to net::update() will automatically process events. + */ virtual void setPolling(const bool manualPolling = false) = 0; + + /** Processes pending events and forwards them to registered handlers. + @todo Should only be called when manual polling is used! + @see setPolling(bool) + */ virtual void poll() = 0; typedef boost::function<void(const PeerId, const NetEvent&, const ChannelId)> EvtProcessEventFn; typedef boost::function<void(void)> EvtDisconnectFn; - /** Pass 0 to disable. */ + /** Sets the event callback function. + @todo Pass 0 to disable. + */ virtual void setProcessEventCallback(const EvtProcessEventFn&) = 0; + /** Sets the disconnect callback function. + @todo pass 0 to disable. + */ virtual void setDisconnectCallback(const EvtDisconnectFn&) = 0; }; + /** Creates an event connection. + The caller takes over ownership and has to make sure + the connection object is destroyed prior to calling net::shutdown(). + @todo Move into INetEventConnection::create() ? + */ NET_API INetEventConnection* createEventConnection(); } // namespace net Modified: trunk/yake/yake/net/netPacket.h =================================================================== --- trunk/yake/yake/net/netPacket.h 2006-11-18 21:07:23 UTC (rev 1498) +++ trunk/yake/yake/net/netPacket.h 2006-11-18 22:21:57 UTC (rev 1499) @@ -17,7 +17,15 @@ { public: virtual ~IPacketSender() {} + /** Sends a packet to all registered peers. + @note On client connections there is only one registered peer: the server. + In this case both send() methods work identical. + */ virtual void send(const PacketPtr&, const SendOptions& opt = SendOptions()) = 0; + /** Sends a packet to the specified, registered peer. + @note On client connections there is only one registered peer: the server. + In this case both send() methods work identical. + */ virtual void send(const PeerId, const PacketPtr&, const SendOptions& opt = SendOptions()) = 0; }; @@ -66,6 +74,7 @@ public: typedef boost::function<void(void)> OnStartedFn; typedef boost::function<void(void)> OnTimeOutFn; + /** Set the callback that will be called as soon as the connection is up. */ virtual void addStartedCallback(const OnStartedFn&) = 0; }; @@ -77,8 +86,10 @@ { public: - /*** @Remarks May throw exception. */ - virtual void start( const Address&, const size_t ) = 0; + /** @Remarks May throw exception. + @param maxClients The maximum number of clients that may be connected at one time. + */ + virtual void start( const Address&, const size_t maxClients ) = 0; /** Disconnects all clients and shuts down the packet connection. @Remarks This function blocks for a short time in order to allow @@ -87,9 +98,17 @@ */ virtual void stop() = 0; + /** Set whitelist of allowed ips. + Clients with ips not in the list will not be allowed to connect. + If the list is empty (which is also the default when this function + does not get called) all client ips are allowed. + */ virtual void setAllowedClientIps(const std::vector<std::string>&) = 0; //virtual void setAllowedClientIps(const std::vector<uint32>&) = 0; + /** Returns the number of clients that are connected. + @todo Clients that are currently connecting or disconnecting are not included! + */ virtual size_t getNumConnectedClients() const = 0; /** Disconnects the client. @@ -101,10 +120,12 @@ typedef boost::function<void(const PeerId, const Address&)> OnClientConnectedFn; typedef boost::function<void(const PeerId)> OnClientDisconnectedFn; - /** Not thread-safe! Call only before calling start()! */ + /** Set callback to be called when a client successfully connected. */ virtual void addClientConnectedCallback(const OnClientConnectedFn&) = 0; + /** Set callback to be called when a client disconnected. */ virtual void addClientDisconnectedCallback(const OnClientDisconnectedFn&) = 0; }; + /** A packet connection interface specific to packet clients. Packet clients manage a single connection to a packet server. @see IClientPacketConnection @@ -112,14 +133,26 @@ class NET_API IClientPacketConnection : public IPacketConnection { public: + /** Connect to the given server. + If doBlock is false, the call returns immediately, otherwise it waits + until the connection attempt succeeded or the timeout of 'timeOut' milliseconds + is reached. + The 'started' and 'timeout' callbacks should be used to handle error cases. + @note Use disconnect() to close the connection. + */ virtual void connect( const Address&, const bool doBlock = false, const uint32 timeOut = 2000 ) = 0; + /** Disconnect from the server. + @note As the connection tries to gracefully disconnect from the server, this function + may block for short time (up to 1 second). + */ virtual void disconnect() = 0; + /** Set the callback to be called when a connection attempt times out. */ virtual void addTimeOutCallback(const OnTimeOutFn&) = 0; }; - /** @Remarks User code is responsible for destroying the connection objects!*/ + /** @Remarks User code is responsible for destroying connection objects!*/ NET_API IServerPacketConnection* createServerPacketConnection(); - /** @Remarks User code is responsible for destroying the connection objects!*/ + /** @Remarks User code is responsible for destroying connection objects!*/ NET_API IClientPacketConnection* createClientPacketConnection(); } // namespace net This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-18 21:07:25
|
Revision: 1498 http://svn.sourceforge.net/yake/?rev=1498&view=rev Author: psyclonist Date: 2006-11-18 13:07:23 -0800 (Sat, 18 Nov 2006) Log Message: ----------- provided additional object and class management functionality Modified Paths: -------------- trunk/yake/yake/ent/object_mgr.h trunk/yake/yake/object/ObjectManager.h trunk/yake/yake/object/ObjectManager.inl Modified: trunk/yake/yake/ent/object_mgr.h =================================================================== --- trunk/yake/yake/ent/object_mgr.h 2006-11-18 21:06:21 UTC (rev 1497) +++ trunk/yake/yake/ent/object_mgr.h 2006-11-18 21:07:23 UTC (rev 1498) @@ -51,14 +51,24 @@ */ Object* makeObject(const ClassId clsId); + /** Creates an Object for the given object id. + If the ClassId isn't known (i.e. unregistered) then 0 is returned. + If the ObjectId is already in use then 0 is returned. + */ + Object* makeObject(const ObjectId objId); + /** Creates an Object for the given clsId. - If the ClassId isn't known (i.e. unregistered) then 0 is returned. + If the ClassId isn't known (i.e. unregistered) then 0 is returned. */ Object* makeObject(const String strClsId); /** Destroys the given Object. */ void destroyObject(Object*); + /** Returns the Object for the given id or ObjectId::kNull if the lookup failed. + */ + Object* getObject(const ObjectId objId) const; + /** @todo Replace with "tick" message? */ void tick(); @@ -77,6 +87,7 @@ if (ret.first == object::RC_OK) { objClsOptions_[ name ] = options; + clsNameIdMap_[ name ] = ret.second; } return ret; } @@ -130,19 +141,42 @@ while (it.hasMoreElements()) postMessage( it.getNext(), msg, source ); } - protected: + typedef AssocVector<String,ClassId> ClassNameIdMap; + /** @todo filter by networked/local + */ + const ClassNameIdMap& getClassNamesAndIds() const + { return clsNameIdMap_; } + + typedef std::pair<bool,ClassId> ClassIdLookupResult; + ClassIdLookupResult getClassId(const String& clsName) const + { + std::pair<object::ResultCode,ClassId> ret = objMgr_.getClassId(clsName); + return ClassIdLookupResult((ret.first == object::RC_OK),ret.second); + } + /** Register class alias to registered class using string class id. + @Remarks One *cannot* create an alias to an alias. + Furthermore "aliasName" shall not be the string id of a registered class! + */ + bool registerClassAlias(const String& aliasName, const ClassId targetClsId); + bool registerClassAlias(const ClassId aliasClsId, const ClassId targetClsId); + void setClassIdGenerationRange(const ClassId min, const ClassId max); + private: // typedef ListenerManager<ObjectManagerListener> listener_mgr_type; void listeners_onObjectCreated(Object* obj); void listeners_onObjectInitialized(Object* obj); void listeners_onDestroyObject(Object* obj); private: + void setupObjectPostCreate(Object*); + typedef std::deque<Object*> object_ptr_list; object_ptr_list objs_; typedef object::ObjectManager<Object> obj_mgr_type; obj_mgr_type objMgr_; + ClassNameIdMap clsNameIdMap_; + typedef AssocVector<String,StringMap> class_option_map; class_option_map objClsOptions_; Modified: trunk/yake/yake/object/ObjectManager.h =================================================================== --- trunk/yake/yake/object/ObjectManager.h 2006-11-18 21:06:21 UTC (rev 1497) +++ trunk/yake/yake/object/ObjectManager.h 2006-11-18 21:07:23 UTC (rev 1498) @@ -72,7 +72,7 @@ ResultCode registerClassAlias(const ClassId aliasClsId, const ClassId targetClsId); /** Register class alias to registered class using string class id. @Remarks One *cannot* create an alias to an alias. - Furthermore "aliasId" shall not be the string id of a registered class! + Furthermore "aliasName" shall not be the string id of a registered class! */ ResultCode registerClassAlias(const String& aliasName, const ClassId targetClsId); @@ -87,6 +87,7 @@ object_type* createObject(const String&, const ObjectId& userObjId = ObjectId::kNull); void destroyObject(object_type*); void destroyAllObjects(); + object_type* getObject(const ObjectId) const; protected: virtual void onObjectCreated(object_type*) {} Modified: trunk/yake/yake/object/ObjectManager.inl =================================================================== --- trunk/yake/yake/object/ObjectManager.inl 2006-11-18 21:06:21 UTC (rev 1497) +++ trunk/yake/yake/object/ObjectManager.inl 2006-11-18 21:07:23 UTC (rev 1498) @@ -156,8 +156,16 @@ // check for existing alias assert( !util::map_contains(strIdAliases_,aliasName) ); - if (util::map_contains(strIdAliases_,aliasName)) + StringToClassIdMap::const_iterator itFindAlias = strIdAliases_.find( aliasName ); + if (itFindAlias != strIdAliases_.end()) + { + // Alias is already registered but with the same ClassId. => Return success. + if (itFindAlias->second == targetClsId) + return RC_OK; + + // Alias already exists but with different ClassId. => Return error. return RC_ALREADY_EXISTS; + } // register alias strIdAliases_.insert( std::make_pair( aliasName, targetClsId ) ); @@ -196,6 +204,12 @@ return this->idAliases_; } template<typename obj_type, typename objectid_type> + obj_type* ObjectManager<obj_type,objectid_type>::getObject(const ObjectId id) const + { + IdObjMap::const_iterator it = objs_.find( id ); + return ( it == objs_.end() ? 0 : it->second ); + } + template<typename obj_type, typename objectid_type> void ObjectManager<obj_type,objectid_type>::destroyAllObjects() { IdObjMap objs = objs_; // copy! This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-18 21:06:25
|
Revision: 1497 http://svn.sourceforge.net/yake/?rev=1497&view=rev Author: psyclonist Date: 2006-11-18 13:06:21 -0800 (Sat, 18 Nov 2006) Log Message: ----------- provided output-to-stream operator for Vector<T> Modified Paths: -------------- trunk/yake/yake/base/templates/yakeVector.h Modified: trunk/yake/yake/base/templates/yakeVector.h =================================================================== --- trunk/yake/yake/base/templates/yakeVector.h 2006-11-18 21:05:38 UTC (rev 1496) +++ trunk/yake/yake/base/templates/yakeVector.h 2006-11-18 21:06:21 UTC (rev 1497) @@ -301,6 +301,24 @@ return result; } + template<class _Value,class _Alloc> + inline std::ostream& operator << (std::ostream& out, + const Vector<_Value,_Alloc>& rhs) + { + out << "Vector"; + //out << "<" << typeid(_Value).name() << ">"; + out << "[" << int(rhs.size()) << "]"; + out << "("; + typedef Vector<_Value,_Alloc> ctr_type; + for (ctr_type::const_iterator it = rhs.begin(); it != rhs.end(); ++it) + { + if (it != rhs.begin()) + out << ", "; + out << *it; + } + out << ")"; + return out; + } } // yake This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-18 21:05:48
|
Revision: 1496 http://svn.sourceforge.net/yake/?rev=1496&view=rev Author: psyclonist Date: 2006-11-18 13:05:38 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Modified Paths: -------------- trunk/yake/scripts/msvc8/plugins/physics/terrainPhysMgr.vcproj Modified: trunk/yake/scripts/msvc8/plugins/physics/terrainPhysMgr.vcproj =================================================================== --- trunk/yake/scripts/msvc8/plugins/physics/terrainPhysMgr.vcproj 2006-11-18 21:03:56 UTC (rev 1495) +++ trunk/yake/scripts/msvc8/plugins/physics/terrainPhysMgr.vcproj 2006-11-18 21:05:38 UTC (rev 1496) @@ -4,6 +4,7 @@ Version="8,00" Name="terrainPhysMgr" ProjectGUID="{6FC81A1C-0463-45EB-94F9-F7D084E3C169}" + RootNamespace="terrainPhysMgr" Keyword="Win32Proj" > <Platforms> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-18 21:03:58
|
Revision: 1495 http://svn.sourceforge.net/yake/?rev=1495&view=rev Author: psyclonist Date: 2006-11-18 13:03:56 -0800 (Sat, 18 Nov 2006) Log Message: ----------- new demo for demonstrating remoting objects, improved net component (interface, functionality, docs) Modified Paths: -------------- trunk/yake/common/bin/debug/yake.graphics.ogre_resources.cfg trunk/yake/scripts/msvc8/net.vcproj trunk/yake/src/yake/ent/object_mgr.cpp trunk/yake/src/yake/net/detail/netCommon.cpp trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp trunk/yake/src/yake/net/detail/netEventConnection.cpp trunk/yake/src/yake/net/detail/netInternal.cpp trunk/yake/src/yake/net/net.cpp trunk/yake/src/yake/samples/net/packet/demo.cpp trunk/yake/src/yake/samples/net/roclient/ROClient.cpp trunk/yake/src/yake/samples/net/roserver/ROServer.cpp trunk/yake/yake/net/detail/netEnetClientPacketConnection.h trunk/yake/yake/net/detail/netEnetServerPacketConnection.h trunk/yake/yake/net/detail/netEventConnection.h trunk/yake/yake/net/detail/netInternal.h trunk/yake/yake/net/net.h trunk/yake/yake/net/netBitstream.h trunk/yake/yake/net/netBitstream.inl trunk/yake/yake/net/netBitstreamAdapters.h trunk/yake/yake/net/netCommon.h trunk/yake/yake/net/netEvent.h trunk/yake/yake/net/netPacket.h trunk/yake/yake/net/netPrerequisites.h trunk/yake/yake/net/netTypes.h trunk/yake/yake/samples/net/common/commonEvents.h trunk/yake/yake/samples/net/common/config.h trunk/yake/yake/samples/net/roclient/ROClient.h trunk/yake/yake/samples/net/roserver/ROServer.h Added Paths: ----------- trunk/yake/common/bin/debug/rodemo.cfg trunk/yake/common/bin/debug/rodemo_client.cfg trunk/yake/common/bin/debug/rodemo_server.cfg trunk/yake/common/bin/debug/rodemo_serverclient.cfg trunk/yake/common/bin/release/rodemo.cfg trunk/yake/common/bin/release/rodemo_client.cfg trunk/yake/common/bin/release/rodemo_server.cfg trunk/yake/common/bin/release/rodemo_serverclient.cfg trunk/yake/scripts/msvc8/samples/net/sampleRoInprocess.vcproj trunk/yake/src/yake/net/detail/netDataChunk.cpp trunk/yake/src/yake/net/detail/netPacket.cpp trunk/yake/src/yake/samples/net/roinprocess/ trunk/yake/src/yake/samples/net/roinprocess/pch.cpp trunk/yake/yake/samples/net/common/roCommon.h Added: trunk/yake/common/bin/debug/rodemo.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo.cfg (rev 0) +++ trunk/yake/common/bin/debug/rodemo.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 0 + } +} Added: trunk/yake/common/bin/debug/rodemo_client.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo_client.cfg (rev 0) +++ trunk/yake/common/bin/debug/rodemo_client.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 0 + } + client + { + count 1 + } +} Added: trunk/yake/common/bin/debug/rodemo_server.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo_server.cfg (rev 0) +++ trunk/yake/common/bin/debug/rodemo_server.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 0 + } +} Added: trunk/yake/common/bin/debug/rodemo_serverclient.cfg =================================================================== --- trunk/yake/common/bin/debug/rodemo_serverclient.cfg (rev 0) +++ trunk/yake/common/bin/debug/rodemo_serverclient.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 1 + } +} Modified: trunk/yake/common/bin/debug/yake.graphics.ogre_resources.cfg =================================================================== --- trunk/yake/common/bin/debug/yake.graphics.ogre_resources.cfg 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/common/bin/debug/yake.graphics.ogre_resources.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -22,3 +22,4 @@ FileSystem=../../media/gui.cegui.fonts/ FileSystem=../../media/gui.cegui.layouts/ Zip=../../media/skybox.zip +FileSystem=C:/Programme/Autodesk/3dsMax8/OSM/ Added: trunk/yake/common/bin/release/rodemo.cfg =================================================================== --- trunk/yake/common/bin/release/rodemo.cfg (rev 0) +++ trunk/yake/common/bin/release/rodemo.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 0 + } +} Added: trunk/yake/common/bin/release/rodemo_client.cfg =================================================================== --- trunk/yake/common/bin/release/rodemo_client.cfg (rev 0) +++ trunk/yake/common/bin/release/rodemo_client.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 0 + } + client + { + count 1 + } +} Added: trunk/yake/common/bin/release/rodemo_server.cfg =================================================================== --- trunk/yake/common/bin/release/rodemo_server.cfg (rev 0) +++ trunk/yake/common/bin/release/rodemo_server.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 0 + } +} Added: trunk/yake/common/bin/release/rodemo_serverclient.cfg =================================================================== --- trunk/yake/common/bin/release/rodemo_serverclient.cfg (rev 0) +++ trunk/yake/common/bin/release/rodemo_serverclient.cfg 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,11 @@ +rodemo +{ + server + { + start 1 + } + client + { + count 1 + } +} Modified: trunk/yake/scripts/msvc8/net.vcproj =================================================================== --- trunk/yake/scripts/msvc8/net.vcproj 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/scripts/msvc8/net.vcproj 2006-11-18 21:03:56 UTC (rev 1495) @@ -222,6 +222,10 @@ > </File> <File + RelativePath="..\..\src\yake\net\detail\netDataChunk.cpp" + > + </File> + <File RelativePath="..\..\src\yake\net\detail\netEnetClientPacketConnection.cpp" > </File> @@ -237,6 +241,10 @@ RelativePath="..\..\src\yake\net\detail\netInternal.cpp" > </File> + <File + RelativePath="..\..\src\yake\net\detail\netPacket.cpp" + > + </File> </Filter> <Filter Name="enet" Added: trunk/yake/scripts/msvc8/samples/net/sampleRoInprocess.vcproj =================================================================== --- trunk/yake/scripts/msvc8/samples/net/sampleRoInprocess.vcproj (rev 0) +++ trunk/yake/scripts/msvc8/samples/net/sampleRoInprocess.vcproj 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,244 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="sampleRoInprocess" + ProjectGUID="{8CB64BC3-7D11-484F-8D10-17DC105701F6}" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="../../../../common/bin/debug" + IntermediateDirectory="../../../../common/obj/debug/$(ProjectName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../../../../;../../../../dependencies/boost/;../../../../dependencies/ttl/" + PreprocessorDefinitions="_STLP_DEBUG;WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + RuntimeTypeInfo="true" + UsePrecompiledHeader="2" + PrecompiledHeaderThrough="yake/samples/net/roinprocess/pch.h" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="base.lib graphics.lib physics.lib audio.lib data.lib input.lib yapp.lib scripting.lib ent.lib" + OutputFile="$(OutDir)/$(ProjectName).exe" + LinkIncremental="2" + AdditionalLibraryDirectories="../../../../common/lib;../../../../common/lib/debug;../../../../dependencies/lib" + GenerateDebugInformation="true" + ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="../../../../common/bin/release" + IntermediateDirectory="../../../../common/obj/release/$(ProjectName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="2" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="../../../../;../../../../dependencies/boost/;../../../../dependencies/ttl/" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="2" + RuntimeTypeInfo="true" + UsePrecompiledHeader="2" + PrecompiledHeaderThrough="yake/samples/net/roinprocess/pch.h" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="base.lib graphics.lib physics.lib audio.lib data.lib input.lib yapp.lib scripting.lib ent.lib" + OutputFile="$(OutDir)/$(ProjectName).exe" + LinkIncremental="1" + AdditionalLibraryDirectories="../../../../common/lib;../../../../common/lib/release;../../../../dependencies/lib" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="inc" + > + <File + RelativePath="..\..\..\..\yake\samples\net\roinprocess\pch.h" + > + </File> + <File + RelativePath="..\..\..\..\yake\samples\net\roclient\ROClient.h" + > + </File> + <File + RelativePath="..\..\..\..\yake\samples\net\common\roCommon.h" + > + </File> + <File + RelativePath="..\..\..\..\yake\samples\net\roserver\ROServer.h" + > + </File> + </Filter> + <Filter + Name="src" + > + <File + RelativePath="..\..\..\..\src\yake\samples\net\roinprocess\demo.cpp" + > + </File> + <File + RelativePath="..\..\..\..\src\yake\samples\net\roinprocess\pch.cpp" + > + <FileConfiguration + Name="Debug|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCLCompilerTool" + UsePrecompiledHeader="1" + /> + </FileConfiguration> + </File> + <File + RelativePath="..\..\..\..\src\yake\samples\net\roclient\ROClient.cpp" + > + </File> + <File + RelativePath="..\..\..\..\src\yake\samples\net\roserver\ROServer.cpp" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Modified: trunk/yake/src/yake/ent/object_mgr.cpp =================================================================== --- trunk/yake/src/yake/ent/object_mgr.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/ent/object_mgr.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -37,11 +37,9 @@ YAKE_ASSERT( ret.first == object::RC_OK )(ret.first)(ret.second); return makeObject( ret.second ); } - Object* ObjectManager::makeObject(const ClassId clsId) + void ObjectManager::setupObjectPostCreate(Object* obj) { - Object* obj = objMgr_.createObject(clsId); - YAKE_ASSERT( obj )(clsId); - objs_.push_back( obj ); + YAKE_ASSERT( obj ); obj->registerMessageListeners(msgRouter_); @@ -50,9 +48,27 @@ obj->init(); listeners_onObjectInitialized(obj); + } + Object* ObjectManager::makeObject(const ObjectId objId) + { + Object* obj = objMgr_.createObject(objId.classId(),objId); + YAKE_ASSERT( obj )(objId); + objs_.push_back( obj ); + this->setupObjectPostCreate(obj); + return obj; } + Object* ObjectManager::makeObject(const ClassId clsId) + { + Object* obj = objMgr_.createObject(clsId); + YAKE_ASSERT( obj )(clsId); + objs_.push_back( obj ); + + this->setupObjectPostCreate(obj); + + return obj; + } void ObjectManager::destroyObject(Object* obj) { YAKE_ASSERT( obj ); @@ -114,7 +130,24 @@ msg->setTarget( MessageTraits::kBroadcastTarget ); msgRouter_.post( msg ); } + void ObjectManager::setClassIdGenerationRange(const ClassId min, const ClassId max) + { + objMgr_.setClassIdGenerationRange( min, max ); + } + bool ObjectManager::registerClassAlias(const String& aliasName, const ClassId targetClsId) + { + object::ResultCode ret = objMgr_.registerClassAlias( aliasName, targetClsId ); + return (ret == object::RC_OK); + } + bool ObjectManager::registerClassAlias(const ClassId aliasClsId, const ClassId targetClsId) + { + object::ResultCode ret = objMgr_.registerClassAlias( aliasClsId, targetClsId ); + return (ret == object::RC_OK); + } + Object* ObjectManager::getObject(const ObjectId objId) const + { + return objMgr_.getObject( objId ); + } } } - Modified: trunk/yake/src/yake/net/detail/netCommon.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netCommon.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/detail/netCommon.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -25,6 +25,7 @@ // Windows Header Files: #include <windows.h> +namespace yake { namespace net { //------------------------------------------------------------------------- @@ -89,7 +90,7 @@ {} Address::~Address() {} - Address& Address::operator =(const net::Address& rhs) + Address& Address::operator =(const Address& rhs) { if (this == &rhs) return *this; @@ -167,11 +168,31 @@ reliability_ = rel; return *this; } + SendOptions& SendOptions::reliable() + { + reliability_ = R_RELIABLE; + return *this; + } + SendOptions& SendOptions::unreliable() + { + reliability_ = R_UNRELIABLE; + return *this; + } SendOptions& SendOptions::ordering(const Ordering ord) { ordering_ = ord; return *this; } + SendOptions& SendOptions::ordered() + { + ordering_ = O_ORDERED; + return *this; + } + SendOptions& SendOptions::unordered() + { + ordering_ = O_UNORDERED; + return *this; + } SendOptions& SendOptions::channel(const ChannelId id) { channelId_ = id; @@ -237,3 +258,4 @@ } } // namespace net +} // namespace yake Added: trunk/yake/src/yake/net/detail/netDataChunk.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netDataChunk.cpp (rev 0) +++ trunk/yake/src/yake/net/detail/netDataChunk.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,85 @@ +#include <yake/net/pch.h> +#include <yake/net/netCommon.h> + +namespace yake { +namespace net { + + DataChunk::DataChunk(const void* data, const size_t len) : buf_(0), bufSize_(0), dataSize_(0) + { + if (data && len) + this->reset( data, len ); + } + DataChunk::~DataChunk() + { + this->clear(); + } + const void* DataChunk::data() const + { + return buf_; + } + void* DataChunk::data() + { + return buf_; + } + size_t DataChunk::size() const + { + return dataSize_; + } + size_t DataChunk::capacity() const + { + return bufSize_; + } + void DataChunk::reset(const void* dataPtr, const size_t dataSize) + { + this->resize(dataSize,kThrowAwayData); + if (dataSize_) + { + assert( dataSize_ == dataSize ); + assert( bufSize_ >= dataSize ); + memcpy( buf_, dataPtr, dataSize_ ); + } + } + void DataChunk::resize(size_t newDataSize, ResizeMode keepData) + { + if (newDataSize <= bufSize_) + { + dataSize_ = newDataSize; + return; + } + if (keepData == kThrowAwayData || !buf_) + { + if (buf_) + delete [] buf_; + buf_ = new byte[newDataSize]; + bufSize_ = newDataSize; + dataSize_ = newDataSize; + return; + } + else if (keepData == kKeepData) + { + byte_ptr newBuf = new byte[newDataSize]; + assert( buf_ ); + memcpy( newBuf, buf_, std::min(newDataSize,dataSize_) ); + delete [] buf_; + buf_ = newBuf; + bufSize_ = newDataSize; + dataSize_ = newDataSize; + return; + } + else + throw std::runtime_error("DataChunk::resize(): unhandled ResizeMode"); + } + void DataChunk::shrink() + { + if (buf_ && (bufSize_ > dataSize_)) + { + byte_ptr newBuf = new byte[dataSize_]; + memcpy( newBuf, buf_, dataSize_ ); + delete [] buf_; + buf_ = newBuf; + bufSize_ = dataSize_; + } + } + +} // namespace net +} // namespace yake Modified: trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -4,6 +4,7 @@ #include <yake/net/detail/netInternal.h> #include <yake/net/detail/netEnetClientPacketConnection.h> +namespace yake { namespace net { IClientPacketConnection* createClientPacketConnection() { @@ -76,7 +77,7 @@ } m_address.port = addr.port(); - m_peer = enet_host_connect( m_host, &m_address, 2 /*channel count*/ ); + m_peer = enet_host_connect( m_host, &m_address, 4 /*channel count*/ ); if (!m_peer) { NET_ERROR("Could not connect to server!"); @@ -115,16 +116,18 @@ if (m_serverPeer) enet_peer_disconnect( m_serverPeer, 0 /*@todo data*/ ); - /*@todo handle graceful disconnects... + // handle graceful disconnects... Timer timer; timer.start(); - while (timer.getTime() < 1) + // now wait until either disconnected or we time out. + while (m_serverPeer && timer.getTime() < 1) { net::update(); - net::native::sleep(10); + this->update(); + net::native::sleep(0); } - */ + // hard disconnect enet_peer_reset( m_peer ); enet_host_destroy( m_host ); m_host = 0; @@ -170,7 +173,7 @@ m_serverIp = ipToString( host ); const uint8 tmp = 0x7F; - this->send(&tmp,1,SendOptions().reliability(R_RELIABLE)); + this->send(PacketPtr(new Packet(&tmp,1)),SendOptions().reliability(R_RELIABLE)); } break; case ENET_EVENT_TYPE_RECEIVE: @@ -186,7 +189,8 @@ } else if (event.packet) { - this->fireCallback_PacketReceived(0,event.packet->data,event.packet->dataLength,ChannelId(event.channelID)); + this->fireCallback_PacketReceived( + 0,PacketPtr(new Packet(event.packet->data,event.packet->dataLength)),ChannelId(event.channelID)); } { //boost::mutex::scoped_lock enetLock(getEnetMtx()); @@ -203,18 +207,38 @@ break; }; } + // Send queued packets: + this->sendOutgoingPacketQ(); } - void EnetClientPacketConnection::send( const void* dataPtr, const size_t dataSize, const net::SendOptions& opt ) + void EnetClientPacketConnection::sendOutgoingPacketQ() { - this->sendBroadcast( dataPtr, dataSize, opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + for (OutgoingPacketQ::const_iterator it = m_outgoingPacketQ.begin(); it != m_outgoingPacketQ.end(); ++it) + { + const SendOptions& opt = it->opt_; + const PacketPtr& pckt = it->pckt_; + YAKE_ASSERT( pckt.get() ); + this->sendBroadcast( pckt->payload().data(), pckt->payload().size(), + opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + } + m_outgoingPacketQ.clear(); } - void EnetClientPacketConnection::send(const PeerId, const void* dataPtr, const size_t dataSize, const SendOptions& opt ) + void EnetClientPacketConnection::send( const PacketPtr& pckt, const SendOptions& opt ) { - this->sendBroadcast( dataPtr, dataSize, opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + YAKE_ASSERT( pckt ); + if (!pckt) + return; + OutgoingPacket pcktEntry; + pcktEntry.opt_ = opt; + pcktEntry.pckt_ = pckt; + m_outgoingPacketQ.push_back( pcktEntry ); } + void EnetClientPacketConnection::send(const PeerId, const PacketPtr& pckt, const SendOptions& opt ) + { + this->send( pckt, opt ); + } void EnetClientPacketConnection::sendTo(const PeerId clientId, const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering ord, const ChannelId channel) { - sendBroadcast(dataPtr,dataSize,rel,ord,channel); + this->sendBroadcast(dataPtr,dataSize,rel,ord,channel); } void EnetClientPacketConnection::sendBroadcast(const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering, const ChannelId channel) { @@ -237,3 +261,4 @@ } // namespace impl } // namespace net +} // namespace yake Modified: trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -4,6 +4,7 @@ #include <yake/net/detail/netInternal.h> #include <yake/net/detail/netEnetServerPacketConnection.h> +namespace yake { namespace net { IServerPacketConnection* createServerPacketConnection() { @@ -122,21 +123,35 @@ NET_ASSERT( m_host ); if (m_host) { - if (m_host->peerCount > 0) + if (!m_clients.empty()) { + for (PeerToClientMap::iterator itClient = m_clients.begin(); + itClient != m_clients.end(); ++itClient) + { + if (itClient->second->state != CS_DEAD && + itClient->second->state != CS_CONNECTED) + { + itClient->second->state = CS_DISCONNECTING; + } + } + // try to gracefully disconnect clients for (size_t i=0; i<m_host->peerCount; ++i) + { enet_peer_disconnect( &m_host->peers[i], 0 /*@todo data*/ ); + } - /** @todo handle graceful disconnects... + // handle graceful disconnects... Timer timer; timer.start(); - while (timer.getTime() < 2) // wait 2 seconds for acknowledgement + // wait max 2 seconds for disconnect acknowledgement from client. + // or stop waiting when client count reaches 0. + while (!m_clients.empty() && timer.getTime() < 2) { net::update(); - net::native::sleep(10); + this->update(); + net::native::sleep(0); } - */ // forcefully disconnect remaining clients if (m_host->peerCount > 0) @@ -173,6 +188,7 @@ return; // set client state itFindClient->second->state = CS_DISCONNECTING; + itFindClient->second->timeLeft_ = 2.; // 2 seconds for graceful disconnect // disconnect enet client { //boost::mutex::scoped_lock enetLock(getEnetMtx()); @@ -300,13 +316,14 @@ } const uint8 tmp = 0x7F; - this->send(peerId,&tmp,1,SendOptions().reliability(R_RELIABLE)); + this->send(peerId,PacketPtr(new Packet(&tmp,1)),SendOptions().reliability(R_RELIABLE)); } break; case ENET_EVENT_TYPE_RECEIVE: NET_ASSERT( event.packet ); NET_ASSERT( event.peer ); - NET_ASSERT( event.peer->data ); + //NET_ASSERT( event.peer->data ); + if (event.peer->data) { const ClientState cs = getClientState( event.peer ); if (cs == CS_CONNECTING) @@ -335,7 +352,9 @@ peerId = (reinterpret_cast<Client*>(event.peer->data))->id; } - fireCallback_PacketReceived(peerId,event.packet->data,event.packet->dataLength,event.channelID); + // This copies the packet data, at the moment. @todo optimize copy away + fireCallback_PacketReceived(peerId, + PacketPtr(new Packet(event.packet->data,event.packet->dataLength)),event.channelID); } { // destroy enet packet @@ -374,21 +393,49 @@ break; }; } + // Send any queued packets. + this->sendOutgoingPacketQ(); } - void EnetServerPacketConnection::send( const void* dataPtr, const size_t dataSize, const net::SendOptions& opt ) + void EnetServerPacketConnection::sendOutgoingPacketQ() { - const PeerId peerId = opt.getPeerId(); - if (peerId != PEERID_BROADCAST) - this->sendTo( peerId, dataPtr, dataSize, opt.getReliability(), opt.getOrdering(), opt.getChannel() ); - else - this->sendBroadcast( dataPtr, dataSize, opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + for (OutgoingPacketQ::const_iterator it = m_outgoingPacketQ.begin(); it != m_outgoingPacketQ.end(); ++it) + //YAKE_FOR_EACH(OutgoingPacketQ::const_iterator,it,m_outgoingPacketQ) + { + const SendOptions& opt = it->opt_; + const PacketPtr& pckt = it->pckt_; + YAKE_ASSERT( pckt.get() ); + if (it->target_ == PEERID_BROADCAST) + this->sendBroadcast( pckt->payload().data(), pckt->payload().size(), + opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + else + this->sendTo( it->target_, pckt->payload().data(), pckt->payload().size(), + opt.getReliability(), opt.getOrdering(), opt.getChannel() ); + } + m_outgoingPacketQ.clear(); } - void EnetServerPacketConnection::send(const PeerId peerId, const void* dataPtr, const size_t dataSize, const SendOptions& opt ) + void EnetServerPacketConnection::send( const PacketPtr& pckt, const SendOptions& opt ) { - SendOptions options = opt; - options.peerId( peerId ); - send( dataPtr, dataSize, options ); + YAKE_ASSERT( pckt ); + if (!pckt) + return; + OutgoingPacket pcktEntry; + pcktEntry.opt_ = opt; + pcktEntry.pckt_ = pckt; + pcktEntry.target_ = opt.getPeerId(); + m_outgoingPacketQ.push_back( pcktEntry ); } + void EnetServerPacketConnection::send(const PeerId peerId, const PacketPtr& pckt, const SendOptions& opt ) + { + YAKE_ASSERT( pckt ); + if (!pckt) + return; + OutgoingPacket pcktEntry; + pcktEntry.opt_ = opt; + pcktEntry.opt_.peerId( peerId ); + pcktEntry.pckt_ = pckt; + pcktEntry.target_ = opt.getPeerId(); + m_outgoingPacketQ.push_back( pcktEntry ); + } void EnetServerPacketConnection::sendTo(const PeerId clientId, const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering, const ChannelId channel) { NET_ASSERT( dataSize > 0 ); @@ -406,8 +453,9 @@ // send //boost::mutex::scoped_lock clientsLock(m_clientsMtx); IdToClientMap::const_iterator it = m_id2client.find( clientId ); - NET_ASSERT( it != m_id2client.end() ); - enet_peer_send( it->second->peer, channel, packet ); + NET_ASSERT( it != m_id2client.end() )( clientId ).warning("unknown client id"); + if (it != m_id2client.end()) + enet_peer_send( it->second->peer, channel, packet ); } } void EnetServerPacketConnection::sendBroadcast(const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering, const ChannelId channel) @@ -430,3 +478,4 @@ } // namespace impl } // namespace net +} // namespace yake Modified: trunk/yake/src/yake/net/detail/netEventConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEventConnection.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/detail/netEventConnection.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -5,6 +5,7 @@ #include <yake/net/detail/netInternal.h> #include <yake/net/detail/netEventConnection.h> +namespace yake { namespace net { const NetEvent::id_type NetEvent::EVTID_NONE = 0xff; NetEvent::NetEvent(const id_type id) : id_(id) @@ -97,7 +98,7 @@ } if (conn_) { - conn_->addPacketReceivedCallback( boost::bind(&EventConnection::onReceivePacket,this,_1,_2,_3,_4) ); + conn_->addPacketReceivedCallback( boost::bind(&EventConnection::onReceivePacket,this,_1,_2,_3) ); started_ = true; } return started_; @@ -152,10 +153,18 @@ out.flush(); NET_LOG("EvtConn: sending " << int(data.size()) << " bytes to '" << int(opt.getPeerId()) << "'."); - conn_->send( &data.front(), data.size(), opt ); + conn_->send( PacketPtr(new Packet(&data.front(), data.size() )), opt ); //@todo optimize copy out! } - void EventConnection::onReceivePacket(const PeerId peerId, const void* dataPtr, const size_t dataLen, const ChannelId channel) + void EventConnection::onReceivePacket(const PeerId peerId, const PacketPtr& pckt, const ChannelId channel) { + NET_ASSERT( pckt ); + if (!pckt) + { + NET_LOG("EvtConn: handling invalid packet object from '" << int(peerId) << "'."); + return; + } + const void* dataPtr = pckt->payload().data(); + const size_t dataLen = pckt->payload().size(); NET_LOG("EvtConn: received " << int(dataLen) << " bytes from '" << int(peerId) << "'."); NET_ASSERT( dataPtr && dataLen > 0 ); NET_ASSERT( dataLen >= sizeof(event_id) ); @@ -275,7 +284,9 @@ if (!processEventFn_.empty()) processEventFn_( it->peerId_, *it->evt_, it->channel_ ); it->fnDestroy_( it->evt_ ); + ++stats_.numEventsProcessed; } } } // namespace impl } // namespace net +} // namespace yake Modified: trunk/yake/src/yake/net/detail/netInternal.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -2,9 +2,13 @@ #include <yake/net/net.h> #include <yake/net/detail/netInternal.h> +#include <boost/thread/mutex.hpp> +namespace yake { namespace net { void update() { + static boost::mutex s_mtx; + boost::mutex::scoped_lock lck(s_mtx); impl::UpdateThread::instance().__update__(); } namespace impl { @@ -121,3 +125,4 @@ } // namespace impl } // namespace net +} // namespace yake Added: trunk/yake/src/yake/net/detail/netPacket.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netPacket.cpp (rev 0) +++ trunk/yake/src/yake/net/detail/netPacket.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1,16 @@ +#include <yake/net/pch.h> +#include <yake/net/netCommon.h> + +namespace yake { +namespace net { + + Packet::Packet(const void* dataPtr, const size_t dataSize) : payload_(dataPtr,dataSize) + { + } + const DataChunk& Packet::payload() const + { + return payload_; + } + +} // namespace net +} // namespace yake Modified: trunk/yake/src/yake/net/net.cpp =================================================================== --- trunk/yake/src/yake/net/net.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/net/net.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -31,6 +31,7 @@ #endif // PLATFORM_WIN32 +namespace yake { namespace net { bool initialize() @@ -50,4 +51,4 @@ } } // namespace net - +} // namespace yake Modified: trunk/yake/src/yake/samples/net/packet/demo.cpp =================================================================== --- trunk/yake/src/yake/samples/net/packet/demo.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/samples/net/packet/demo.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -92,13 +92,13 @@ YAKE_ASSERT( conn_ ); YAKE_ASSERT( started_ ); std::string hello("hello!"); - conn_->send( hello.c_str(), hello.size(), net::SendOptions().reliability(net::R_RELIABLE) ); + conn_->send( hello.c_str(), hello.size(), net::SendOptions().reliable() ); COUTLN("server:broadcastHello() " << conn_->getNumConnectedClients() << " client(s)"); } void client_onPacketReceived(const net::PeerId peerId, const void* data, const size_t len, const net::ChannelId channel) { - COUTLN(" client " << peerId << " packet(size=" << len << ") on channel " << channel << "\n"); + COUTLN(" client " << peerId << " packet(size=" << len << ") on channel " << int(channel) << "\n"); } int main(int argc, char* argv[]) Modified: trunk/yake/src/yake/samples/net/roclient/ROClient.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -1,29 +1,32 @@ -#include <yake/samples/net/roclient/pch.h> +#include <yake/samples/net/roinprocess/pch.h> #include <yake/base/yake.h> +#include <yake/object/yakeObjects.h> +#include <yake/ent/ent.h> #include <yake/net/net.h> #include <yake/samples/net/common/common.h> #include <yake/samples/net/common/commonEvents.h> #include <yake/samples/net/roclient/ROClient.h> +namespace yake { namespace ro { - client::client() : - timedOut_(false), running_(false), stage_(CS_JOINING) + client::client(const net::Address& serverAddr) : + timedOut_(false), stage_(CS_JOINING), objMgr_(0), serverAddr_(serverAddr), packetConnStarted_(false) { } client::~client() { stop(); } - bool client::running() const + void client::setObjectManager(ent::ObjectManager* objMgr) { - boost::mutex::scoped_lock lck(runningMtx_); - return running_; + objMgr_ = objMgr; } - bool client::start(const net::Address& serverAddr) + bool client::onStart() { try { // create connection & register callbacks + packetConnStarted_ = false; conn_.reset( net::createClientPacketConnection() ); assert( conn_ ); @@ -31,8 +34,15 @@ conn_->addStartedCallback( boost::bind(&client::onClientStarted,this) ); // attempt to connect to server - conn_->connect( serverAddr ); + /* + conn_->connect( serverAddr_, true, 2000 ); + */ + conn_->connect( serverAddr_ ); + this->waitForStart(); + if (timedOut_.getCopy()) + return false; + return true; } catch (const net::Exception& e) @@ -44,9 +54,9 @@ } void client::waitForStart() { - while (!timedOut_.getCopy() && !running()) + while (!timedOut_.getCopy() && !packetConnStarted_) { - net::native::sleep(10); + net::native::sleep(0); net::update(); } if (timedOut_.getCopy()) @@ -64,9 +74,11 @@ evtConn_->registerEvent( s2cEvtJoinReqReply::ID, net::NetEvent::DIR_ANY, s2cEvtJoinReqReply::create, s2cEvtJoinReqReply::destroy ); evtConn_->registerEvent( s2cEvtClassTable::ID, net::NetEvent::DIR_ANY, - s2cEvtClassTable::create, s2cEvtClassTable::destroy ); + s2cEvtClassTable::create, s2cEvtClassTable::destroy ); + evtConn_->registerEvent( s2cEvtCreateObject::ID, net::NetEvent::DIR_ANY, + s2cEvtCreateObject::create, s2cEvtCreateObject::destroy ); - evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); + evtConn_->setProcessEventCallback( boost::bind(&client::onProcessEvent,this,_1,_2,_3) ); evtConn_->setPacketConnection( conn_.get(), net::NetEvent::DIR_ANY ); evtConn_->start(); @@ -86,30 +98,32 @@ evt.setId( 23 ); // invalid id! evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); + + currEvtProcessFn_ = boost::bind(&client::init_onProcessEvent,this,_1,_2,_3); + /* while (stage_ == CS_JOINING) { evtConn_->poll(); net::update(); net::native::sleep(0); } + */ } void client::step() { if (!running()) return; - evtConn_->poll(); + assert( evtConn_.get() ); + if (evtConn_.get()) + evtConn_->poll(); if (stage_ == CS_RUNNING) { } } - void client::stop() + void client::onStop() { - { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = false; - } // clean up if (evtConn_) { @@ -120,16 +134,13 @@ { conn_->disconnect(); conn_.reset(); + packetConnStarted_ = false; } } void client::onClientStarted() { COUTLN("client started."); - - { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = true; - } + packetConnStarted_ = true; } void client::onTimeOut() { @@ -145,8 +156,68 @@ COUTLN("client (running) received event (" << (int)evt.id() << ")."); if (evt.id() == s2cEvtClassTable::ID) { - COUTLN("starting sim " << evt.id()); + COUTLN("client: starting sim " << int(evt.id())); + const s2cEvtClassTable& reply = static_cast<const s2cEvtClassTable&>( evt ); + COUTLN(" " << int(reply.globalClassIds_.size()) << " class(es)"); + for (std::map<std::string,ent::ClassId>::const_iterator it = reply.globalClassIds_.begin(); + it != reply.globalClassIds_.end(); ++it) + { + const std::string& clsName = it->first; + const ent::ClassId globalClsId = it->second; + COUTLN(" ['" << clsName << "'] = " << int(globalClsId)); + if (!objMgr_) + { + COUTLN(" -> no object manager"); + } + else + { + ent::ObjectManager::ClassIdLookupResult ret = objMgr_->getClassId( clsName ); + if (ret.first) + { + const ent::ClassId localClsId = ret.second; + if (localClsId != it->second) + { + if (objMgr_->registerClassAlias( globalClsId, localClsId )) + { + COUTLN(" -> successfully registered alias"); + } + else + { + COUTLN(" -> failed to register alias"); + } + } + else + { + COUTLN(" -> no need to register an alias (global id = local id; and names match)"); + } + } + else + { + COUTLN(" -> class with this name not registered locally!"); + } + } + } } + else if (evt.id() == s2cEvtCreateObject::ID) + { + COUTLN("client: creating object"); + const s2cEvtCreateObject& reply = static_cast<const s2cEvtCreateObject&>( evt ); + COUTLN(" object class='" << int(reply.objId_.classId()) << "' serNo='" << int(reply.objId_.serialNo()) << "'"); + if (objMgr_) + { + ent::Object* o = objMgr_->makeObject( reply.objId_ ); + if (o) + { + COUTLN(" successfully created! (class='" << o->isA()->name() << "')"); + objMgr_->destroyObject( o ); + } + else + COUTLN(" failed to create!"); + } + } + //else if (evt.id() == s2cUpdateObject::ID) + { + } } void client::init_onProcessEvent(const net::PeerId, const net::NetEvent& evt, const net::ChannelId) { @@ -158,18 +229,26 @@ const s2cEvtJoinReqReply& reply = static_cast<const s2cEvtJoinReqReply&>( evt ); if (reply.accepted) { - COUTLN("CONNECTED TO SERVER."); + COUTLN("client: CONNECTED TO SERVER."); stage_ = CS_RUNNING; + currEvtProcessFn_ = boost::bind(&client::running_onProcessEvent,this,_1,_2,_3); } else { - COUTLN("SERVER DENIED ACCESS!"); + COUTLN("client: SERVER DENIED ACCESS!"); stage_ = CS_DEAD; - evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); + currEvtProcessFn_ = boost::bind(&client::init_onProcessEvent,this,_1,_2,_3); } } } } + void client::onProcessEvent(const net::PeerId pId, const net::NetEvent& evt, const net::ChannelId cId) + { + COUTLN("client (dispatcher) received event (" << (int)evt.id() << ")."); + if (!currEvtProcessFn_.empty()) + currEvtProcessFn_(pId,evt,cId); + this->dispatchNetEvent(pId,evt,cId); + } } // namespace ro - +} // namespace yake Added: trunk/yake/src/yake/samples/net/roinprocess/pch.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roinprocess/pch.cpp (rev 0) +++ trunk/yake/src/yake/samples/net/roinprocess/pch.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -0,0 +1 @@ +#include <yake/samples/net/roinprocess/pch.h> Modified: trunk/yake/src/yake/samples/net/roserver/ROServer.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-11-18 21:03:56 UTC (rev 1495) @@ -1,15 +1,201 @@ -#include <yake/samples/net/roserver/pch.h> +#include <yake/samples/net/roinprocess/pch.h> +#include <yake/object/yakeObjects.h> +#include <yake/ent/ent.h> #include <yake/net/net.h> #include <yake/samples/net/common/common.h> #include <yake/samples/net/common/commonEvents.h> #include <yake/samples/net/roserver/ROServer.h> +namespace yake { namespace ro { //----------------------------------------------------------------------------- + IServiceHost::IServiceHost() : running_(false) + { + } + bool IServiceHost::running() const + { + boost::mutex::scoped_lock lck(runningMtx_); + return running_; + } + bool IServiceHost::start() + { + bool succ = this->onStart(); + if (!succ) + return false; + + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = true; + } + + // start services + YAKE_FOR_EACH(detail::ServiceManager::const_service_iterator,it,serviceMgr_) + { + (*it)->onStart(*this); + } + + return true; + } + void IServiceHost::stop() + { + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = false; + } + + // stop services + YAKE_FOR_EACH(detail::ServiceManager::const_service_iterator,it,serviceMgr_) + { + (*it)->onStop(*this); + } + + // stop the rest + this->onStop(); + } + void IServiceHost::addService(IServicePtr service, const std::string& tag) + { + serviceMgr_.addService( service, tag ); + if (this->running()) + service->onStart(*this); + } + void IServiceHost::removeAllServices() + { + serviceMgr_.removeAllServices(); + } + IServicePtr IServiceHost::removeService(const std::string & tag) + { + IServicePtr service = serviceMgr_.removeService( tag ); + if (service && this->running()) + service->onStop(*this); + return service; + } + IServicePtr IServiceHost::removeService(IServicePtr service) + { + serviceMgr_.removeService( service ); + if (service && this->running()) + service->onStop(*this); + return service; + } + IServicePtr IServiceHost::getService(const std::string& tag) const + { + return serviceMgr_.getService( tag ); + } + void IServiceHost::dispatchNetEvent(const net::PeerId pId, const net::NetEvent& evt, const net::ChannelId cId) + { + // find catch-all for this channel (ignore event id) + { + SigMap::const_iterator it = sigMap_.find( ChannelEventIdPair(cId,net::NetEvent::EVTID_NONE) ); + if (it != sigMap_.end()) + (*it->second)(pId,evt,cId); + } + + // find signal for this channel and event id: + SigMap::const_iterator it = sigMap_.find( ChannelEventIdPair(cId,evt.id()) ); + if (it == sigMap_.end()) + return; + (*it->second)(pId,evt,cId); + } + SignalConnection IServiceHost::subscribeToNetEvent( + const net::NetEvent::id_type eId, const net::ChannelId cId, const EvtProcessEventFn& fn) + { + const ChannelEventIdPair idPair(cId,eId); + + SigMap::iterator it = sigMap_.find( idPair ); + if (it == sigMap_.end()) + { + ProcessEventSigPtr sig( new ProcessEventSig() ); + sigMap_[ idPair ] = sig; + return sig->connect( fn ); + } + return it->second->connect(fn); + } + SignalConnection IServiceHost::subscribeToNetEventChannel( + const net::ChannelId cId, const EvtProcessEventFn& fn) + { + const ChannelEventIdPair idPair(cId,net::NetEvent::EVTID_NONE); + + SigMap::iterator it = sigMap_.find( idPair ); + if (it == sigMap_.end()) + { + ProcessEventSigPtr sig( new ProcessEventSig() ); + sigMap_[ idPair ] = sig; + return sig->connect( fn ); + } + return it->second->connect(fn); + } + + //----------------------------------------------------------------------------- + namespace detail { + + void ServiceManager::addService(IServicePtr service, const std::string& tag) + { + YAKE_ASSERT( service ); + if (!service) + return; + + services_.insert( service ); + if (!tag.empty()) + { + YAKE_ASSERT( tag2service_.find(tag) == tag2service_.end() ).debug("duplicate tag!"); + tag2service_[ tag ] = service; + } + } + IServicePtr ServiceManager::getService(const std::string& tag) const + { + TagMap::const_iterator itFind = tag2service_.find(tag); + return (itFind == tag2service_.end() ? IServicePtr() : itFind->second); + } + IServicePtr ServiceManager::removeService(const std::string& tag) + { + TagMap::iterator itFind = tag2service_.find(tag); + if (itFind == tag2service_.end()) + return IServicePtr(); + IServicePtr service = itFind->second; + tag2service_.erase( itFind ); + services_.erase( service ); + return service; + } + IServicePtr ServiceManager::removeService(const IServicePtr service) + { + YAKE_FOR_EACH(TagMap::iterator,itFind,tag2service_) + { + if (itFind->second == service) + { + tag2service_.erase( itFind ); + break; + } + } + services_.erase( service ); + return service; + } + void ServiceManager::removeAllServices() + { + tag2service_.clear(); + services_.clear(); + } + ServiceManager::const_service_iterator ServiceManager::begin() const + { + return services_.begin(); + } + ServiceManager::const_service_iterator ServiceManager::end() const + { + return services_.end(); + } + + } // namespace detail + //----------------------------------------------------------------------------- namespace server_impl { - class client + class client : public server::iclient { public: + + virtual void sendEvent(const net::NetEvent& evt, + const net::SendOptions& opt = net::SendOptions().channel(CHANNELID_CONTROL)) + { + YAKE_ASSERT( evtConn ); + evtConn->sendEvent( evt, opt ); + } + enum stage_t { CS_WAIT_FOR_REQ = 1, // waiting for "req join" @@ -22,15 +208,24 @@ AM_REGULAR, AM_SPECTATOR }; - net::PeerId id; - stage_t stage; - access_mode_t accessMode; - net::INetEventConnection* evtConn; + net::PeerId id; + stage_t stage; + access_mode_t accessMode; + SharedPtr<net::INetEventConnection> evtConn; + server& svr; - client() : id(net::NetEvent::EVTID_NONE), stage(CS_DEAD), accessMode(AM_REGULAR), evtConn(0) + client(server& svrObj) : + id(net::NetEvent::EVTID_NONE), + stage(CS_DEAD), + accessMode(AM_REGULAR), + svr(svrObj) { processEventFn_ = boost::bind(&client::init_onProcessEvent,this,_1,_2); } + virtual net::PeerId getPeerId() const + { + return this->id; + } void onProcessEvent(const net::NetEvent& evt, const net::ChannelId channel) { YAKE_ASSERT( !processEventFn_.empty() ); @@ -48,58 +243,86 @@ //----------------------------------------------------------------------------- - server::server() : conn_(0), running_(false), evtConn_(0) + server::server() : packetConnStarted_(false) { } server::~server() { stop(); } - bool server::start() + /* + void server::queueEvent(const net::PeerId id, net::NetEvent* evt, const net::ChannelId cId) { + SOF_ASSERT( evt ); + if (!evt) + return; + outEvtQ_.push_back( EventQEntry(id,evt,cId) ); + } + */ + SignalConnection server::subscribeToClientSimulationStarted(const ClientSimulationStartedSignal::slot_type& slot) + { + return sigClientSimulationStarted_.connect(slot); + } + SignalConnection server::subscribeToClientDisconnected(const ClientDisconnectedSignal::slot_type& slot) + { + return sigClientDisconnected_.connect(slot); + } + const s2cEvtClassTable& server::getClassTableMessage() const + { + return evtClassTbl_; + } + void server::onClientSimStarted(iclient&c) + { + sigClientSimulationStarted_(c); + } + void server::setClassTableMessage(const s2cEvtClassTable& msg) + { + msg.copyTo( evtClassTbl_ ); + } + bool server::onStart() + { if (conn_) return true; - const net::uint16 port = 40000; + const uint16 port = 40000; const size_t maxClients = 32; - conn_ = net::createServerPacketConnection(); + conn_.reset( net::createServerPacketConnection() ); YAKE_ASSERT( conn_ ); conn_->addStartedCallback( boost::bind(&server::onServerStarted,this) ); - conn_->addPacketReceivedCallback( boost::bind(&server::onReceivePacket,this,_1,_2,_3,_4) ); + conn_->addPacketReceivedCallback( boost::bind(&server::onReceivePacket,this,_1,_2,_3) ); + conn_->addClientDisconnectedCallback( boost::bind(&server::onClientDisconnected,this,_1) ); COUTLN("starting server at port " << port << " with max. " << maxClients << " clients..."); conn_->start( net::Address(port), maxClients ); - while (!running()) + // wait until net object is up + while (!packetConnStarted_) { //conn_->update(); ->@todo net::update(); - net::native::sleep(10); + net::native::sleep(0); } - return true; } - void server::stop() + void server::onStop() { + // shutdown net resources + if (evtConn_) { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = false; + evtConn_->stop(); + evtConn_.reset(); } - clients_.clear(); if (conn_) { conn_->stop(); - delete conn_; - conn_ = 0; + conn_.reset(); + packetConnStarted_ = false; } - if (evtConn_) - { - evtConn_->stop(); - delete evtConn_; - evtConn_ = 0; - } + + // disconnect/destroy remaining clients + clients_.clear(); } void server::step() { @@ -108,21 +331,12 @@ if (evtConn_) evtConn_->poll(); } - bool server::running() const - { - boost::mutex::scoped_lock lck(runningMtx_); - return running_; - } void server::onServerStarted() { - COUTLN("server started."); - { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = true; - } + COUTLN("server packet connection started."); COUTLN("server: starting event connection..."); YAKE_ASSERT( !evtConn_ ); - evtConn_ = net::createEventConnection(); + evtConn_.reset( net::createEventConnection() ); YAKE_ASSERT( evtConn_ ); evtConn_->setPolling(true); @@ -131,14 +345,17 @@ evtConn_->registerEvent( s2cEvtJoinReqReply::ID, net::NetEvent::DIR_ANY, s2cEvtJoinReqReply::create, s2cEvtJoinReqReply::destroy ); evtConn_->registerEvent( s2cEvtClassTable::ID, net::NetEvent::DIR_ANY, s2cEvtClassTable::create, s2cEvtClassTable::destroy ); evtConn_->registerEvent( c2sEvtSimOk::ID, net::NetEvent::DIR_ANY, c2sEvtSimOk::create, c2sEvtSimOk::destroy ); + evtConn_->registerEvent( s2cEvtCreateObject::ID, net::NetEvent::DIR_ANY, s2cEvtCreateObject::create, s2cEvtCreateObject::destroy ); evtConn_->setProcessEventCallback( boost::bind(&server::onProcessEvent,this,_1,_2,_3) ); - evtConn_->setPacketConnection( conn_, net::NetEvent::DIR_ANY ); + evtConn_->setPacketConnection( conn_.get(), net::NetEvent::DIR_ANY ); evtConn_->start(); COUTLN("server: event connection started."); + + packetConnStarted_ = true; } - void server::onReceivePacket(const net::PeerId peerId, const void* data, const size_t len, const net::ChannelId channel) + void server::onReceivePacket(const net::PeerId peerId, const net::PacketPtr&, const net::ChannelId channel) { COUTLN("server received packet."); //echoing... @@ -149,7 +366,7 @@ try { COUTLN("server received event (" << (int)evt.id() << ")."); - // Let client object handle the event. If no client object exists + // 1. Let client object handle the event. If no client object exists // for this peer, create it. // get client object @@ -157,7 +374,7 @@ ClientPtrMap::iterator it = clients_.find( peerId ); if (it == clients_.end()) { - c.reset( new Client() ); + c.reset( new Client(*this) ); c->id = peerId; c->stage = Client::CS_WAIT_FOR_REQ; c->evtConn = evtConn_; @@ -168,12 +385,25 @@ // handle event c->onProcessEvent( evt, channel ); + + // 2. Let services handle event + this->dispatchNetEvent( peerId, evt, channel ); } catch (...) { COUTLN("server: CAUGHT UNHANDLED EXCEPTION!\n"); } } + void server::onClientDisconnected(const net::PeerId pId) + { + COUTLN("ro::server: client '" << pId << "' disconnected."); + ClientPtrMap::iterator it = this->clients_.find( pId ); + YAKE_ASSERT(it != this->clients_.end())(pId).warning("unknown client disconnected. lookup failed."); + if (it == this->clients_.end()) + return; + this->sigClientDisconnected_( *it->second ); + this->clients_.erase( it ); + } //----------------------------------------------------------------------------- namespace server_impl { @@ -185,28 +415,29 @@ if (evt.id() == c2sEvtJoinReq::ID) { const c2sEvtJoinReq& evtJoinReq = static_cast<const c2sEvtJoinReq&>(evt); - COUTLN(" evt: Join Request"); + COUTLN("server: evt: Join Request"); // send reply: OK - COUTLN(" => accepted"); + COUTLN("server: accepted join request by client"); s2cEvtJoinReqReply joinReply; joinReply.accepted = true; - evtConn->sendEvent( this->id, joinReply, net::SendOptions().channel(CHANNELID_CONTROL) ); + evtConn->sendEvent( this->id, joinReply, net::SendOptions().channel(CHANNELID_CONTROL).ordered().reliable() ); #if NET_STRESS_TEST_LEVEL >= 1 for (size_t i=0; i<3; ++i) evtConn->sendEvent( this->id, joinReply, net::SendOptions().channel(CHANNELID_CONTROL) ); #endif - // - s2cEvtClassTable clsTbl; - clsTbl.globalClassIds_["test"] = 42; - clsTbl.globalClassIds_["player"] = 56; - evtConn->sendEvent( this->id, clsTbl, net::SendOptions().channel(CHANNELID_CONTROL) ); + // replicate class table + evtConn->sendEvent( this->id, this->svr.getClassTableMessage(), + net::SendOptions().channel(CHANNELID_CONTROL).ordered().reliable() ); // use different event callback for the CS_RUNNING stage: - COUTLN(" => RUNNING"); + COUTLN("server: => CLIENT: RUNNING"); processEventFn_ = boost::bind(&client::running_onProcessEvent,this,_1,_2); this->stage = CS_RUNNING; + + // replicate objects + this->svr.onClientSimStarted( *this ); } } void client::running_onProcessEvent(const net::NetEvent& evt, const net::ChannelId channel) @@ -215,9 +446,7 @@ YAKE_ASSERT( stage == CS_RUNNING ); if (stage != CS_RUNNING) return; - //// send class table & start sim - //s2cEvtClassTable evtClassTbl; - //evtConn->sendEvent( this->id, evtClassTbl, net::SendOptions().channel(CHANNELID_SIMCTRL) ); } } // namespace server_impl } // namespace ro +} // namespace yake Modified: trunk/yake/yake/net/detail/netEnetClientPacketConnection.h =================================================================== --- trunk/yake/yake/net/detail/netEnetClientPacketConnection.h 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/yake/net/detail/netEnetClientPacketConnection.h 2006-11-18 21:03:56 UTC (rev 1495) @@ -1,11 +1,12 @@ -#ifndef NET_ENETCLIENTPACKETCONNECTION_H -#define NET_ENETCLIENTPACKETCONNECTION_H +#ifndef YAKE_NET_ENETCLIENTPACKETCONNECTION_H +#define YAKE_NET_ENETCLIENTPACKETCONNECTION_H +namespace yake { namespace net { namespace impl { //-------------------------------------------------------------------------- - class EnetClientPacketConnection : public ::net::IClientPacketConnection + class EnetClientPacketConnection : public IClientPacketConnection { public: EnetClientPacketConnection(); @@ -14,8 +15,8 @@ virtual void connect( const Address&, const bool doBlock, const uint32 timeOut ); virtual void disconnect(); - virtual void send(const void*, const size_t, const SendOptions& opt = SendOptions()); - virtual void send(const PeerId, const void*, const size_t, const SendOptions& opt = SendOptions()); + virtual void send(const PacketPtr& pckt, const SendOptions& opt = SendOptions()); + virtual void send(const PeerId, const PacketPtr& pckt, const SendOptions& opt = SendOptions()); virtual void addStartedCallback(const OnStartedFn&); virtual CallbackConnection addPacketReceivedCallback( const OnPacketReceivedFn&); @@ -40,17 +41,18 @@ for (OnStartedFnList::const_iterator it = startedFnList_.begin(); it != startedFnList_.end(); ++it) (*it)(); } - void fireCallback_PacketReceived(const PeerId peerId, const void* data, const size_t dataLen, const ChannelId channel) + void fireCallback_PacketReceived(const PeerId peerId, const PacketPtr& pckt, const ChannelId channel) { //boost::mutex::scoped_lock lck(packetReceivedFnListMtx_); for (OnPacketReceivedFnList::const_iterator it = packetReceivedFnList_.begin(); it != packetReceivedFnList_.end(); ++it) - (it->second)(peerId,data,dataLen,channel); + (it->second)(peerId,pckt,channel); } void fireCallback_TimeOut() { for (OnTimeOutFnList::const_iterator it = timeOutFnList_.begin(); it != timeOutFnList_.end(); ++it) (*it)(); } + void sendOutgoingPacketQ(); private: typedef std::deque<OnStartedFn> OnStartedFnList; typedef std::map<CallbackHandle,OnPacketReceivedFn> OnPacketReceivedFnList; @@ -71,9 +73,19 @@ bool m_waitingForConnect; std::string m_serverIp; Timer m_connTimer; + + struct OutgoingPacket + { + //PeerId target_; + PacketPtr pckt_; + SendOptions opt_; + }; + typedef std::deque<OutgoingPacket> OutgoingPacketQ; + OutgoingPacketQ m_outgoingPacketQ; }; } // namespace impl } // namespace net +} // namespace yake #endif Modified: trunk/yake/yake/net/detail/netEnetServerPacketConnection.h =================================================================== --- trunk/yake/yake/net/detail/netEnetServerPacketConnection.h 2006-11-01 15:25:54 UTC (rev 1494) +++ trunk/yake/yake/net/detail/netEnetServerPacketConnection.h 2006-11-18 21:03:56 UTC (rev 1495) @@ -1,11 +1,12 @@ -#ifndef NET_ENETSERVERPACKETCONNECTION_H -#define NET_ENETSERVERPACKETCONNECTION_H +#ifndef YAKE_NET_ENETSERVERPACKETCONNECTION_H +#define YAKE_NET_ENETSERVERPACKETCONNECTION_H +namespace yake { namespace net { namespace impl { //-------------------------------------------------------------------------- - class EnetServerPacketConnection : public ::net::IServerPacketConnection + class EnetServerPacketConnection : public IServerPacketConnection { public: EnetServerPacketConnection(); @@ -30,8 +31,8 @@ virtual void disconnect( const PeerId client ); - virtual void send(const void*, const size_t, const SendOptions& opt = SendOptions()); - virtual void send(const PeerId, const void*, const size_t, const SendOptions& opt = SendOptions()); + virtual void send(const PacketPtr&, const SendOptions& opt = SendOptions()); + virtual void send(const PeerId, const PacketPtr&, const SendOptions& opt = SendOptions()); virtual void addStartedCallback(const OnStartedFn&); virtual void addClientConnectedCallback(const OnClientConnectedFn&); @@ -55,6 +56,7 @@ size_t numMaxLiveClients_; }; private: + // send via enet void sendTo(const PeerId clientId, const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering, const ChannelId channel); void sendBroadcast(const void* dataPtr, const size_t dataSize, const Reliability rel, const Ordering, const Cha... [truncated message content] |
From: <psy...@us...> - 2006-11-01 15:26:02
|
Revision: 1494 http://svn.sourceforge.net/yake/?rev=1494&view=rev Author: psyclonist Date: 2006-11-01 07:25:54 -0800 (Wed, 01 Nov 2006) Log Message: ----------- early-out in step() in case that no stepping is needed to avoid triggering signals unnecessarily, set default frequency to 1/50s Modified Paths: -------------- trunk/yake/src/yake/plugins/physicsODE/OdeWorld.cpp Modified: trunk/yake/src/yake/plugins/physicsODE/OdeWorld.cpp =================================================================== --- trunk/yake/src/yake/plugins/physicsODE/OdeWorld.cpp 2006-11-01 15:24:33 UTC (rev 1493) +++ trunk/yake/src/yake/plugins/physicsODE/OdeWorld.cpp 2006-11-01 15:25:54 UTC (rev 1494) @@ -45,7 +45,7 @@ { //TODO make these settings configurable for user //simulation - mStepSize = real( 1./20. ); + mStepSize = real( 1./50. ); mOdeWorld = new dWorld(); YAKE_ASSERT( mOdeWorld ); @@ -369,8 +369,10 @@ void OdeWorld::step( const real timeElapsed ) { mTimeOverflow += timeElapsed; + //std::cout << "physics.step() @ time=" << mTime << " overflow=" << mTimeOverflow << " dt=" << timeElapsed << " step=" << mStepSize << "\n"; - std::cout << "physics.step() @ time=" << mTime << " overflow=" << mTimeOverflow << " dt=" << timeElapsed << " step=" << mStepSize << "\n"; + if (mTimeOverflow < mStepSize) + return; firePreStep(); real steppedTime = 0.; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:24:43
|
Revision: 1493 http://svn.sourceforge.net/yake/?rev=1493&view=rev Author: psyclonist Date: 2006-11-01 07:24:33 -0800 (Wed, 01 Nov 2006) Log Message: ----------- formatting Modified Paths: -------------- trunk/yake/src/yake/model/yakePhysicalCreator.cpp Modified: trunk/yake/src/yake/model/yakePhysicalCreator.cpp =================================================================== --- trunk/yake/src/yake/model/yakePhysicalCreator.cpp 2006-11-01 15:19:39 UTC (rev 1492) +++ trunk/yake/src/yake/model/yakePhysicalCreator.cpp 2006-11-01 15:24:33 UTC (rev 1493) @@ -141,6 +141,7 @@ ctx.getModel().addComponent( new Physical(), name ); } + } // namespace model } // namespace yake This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:20:33
|
Revision: 1492 http://svn.sourceforge.net/yake/?rev=1492&view=rev Author: psyclonist Date: 2006-11-01 07:19:39 -0800 (Wed, 01 Nov 2006) Log Message: ----------- refactored yake::net Modified Paths: -------------- trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp trunk/yake/src/yake/net/detail/netEventConnection.cpp trunk/yake/src/yake/net/detail/netInternal.cpp trunk/yake/src/yake/samples/net/packet/demo.cpp trunk/yake/src/yake/samples/net/roclient/ROClient.cpp trunk/yake/src/yake/samples/net/roclient/demo.cpp trunk/yake/src/yake/samples/net/roserver/ROServer.cpp trunk/yake/yake/net/netEvent.h trunk/yake/yake/net/netPacket.h trunk/yake/yake/samples/net/common/commonEvents.h trunk/yake/yake/samples/net/roclient/ROClient.h trunk/yake/yake/samples/net/roserver/ROServer.h Modified: trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/net/detail/netEnetClientPacketConnection.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -113,10 +113,9 @@ if (m_host) { if (m_serverPeer) - { - //boost::mutex::scoped_lock enetLock(getEnetMtx()); enet_peer_disconnect( m_serverPeer, 0 /*@todo data*/ ); - } + + /*@todo handle graceful disconnects... Timer timer; timer.start(); while (timer.getTime() < 1) @@ -124,17 +123,14 @@ net::update(); net::native::sleep(10); } - { - //boost::mutex::scoped_lock enetLock(getEnetMtx()); - enet_peer_reset( m_peer ); - enet_host_destroy( m_host ); - m_host = 0; - } + */ + + enet_peer_reset( m_peer ); + enet_host_destroy( m_host ); + m_host = 0; } - { - m_ready = false; - m_serverIp = ""; - } + m_ready = false; + m_serverIp = ""; m_serverPeer = 0; } void EnetClientPacketConnection::update() Modified: trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/net/detail/netEnetServerPacketConnection.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -124,12 +124,11 @@ { if (m_host->peerCount > 0) { - { - //boost::mutex::scoped_lock enetLock(getEnetMtx()); - // try to gracefully disconnect clients - for (size_t i=0; i<m_host->peerCount; ++i) - enet_peer_disconnect( &m_host->peers[i], 0 /*@todo data*/ ); - } + // try to gracefully disconnect clients + for (size_t i=0; i<m_host->peerCount; ++i) + enet_peer_disconnect( &m_host->peers[i], 0 /*@todo data*/ ); + + /** @todo handle graceful disconnects... Timer timer; timer.start(); while (timer.getTime() < 2) // wait 2 seconds for acknowledgement @@ -137,6 +136,8 @@ net::update(); net::native::sleep(10); } + */ + // forcefully disconnect remaining clients if (m_host->peerCount > 0) { @@ -145,11 +146,8 @@ enet_peer_reset( &m_host->peers[i] ); } } - { - //boost::mutex::scoped_lock enetLock(getEnetMtx()); - enet_host_destroy( m_host ); - m_host = 0; - } + enet_host_destroy( m_host ); + m_host = 0; } } m_ip2string.clear(); @@ -214,7 +212,8 @@ const double deltaT = max(currT - m_timeOfLastUpdate, 0.0001); NET_ASSERT( deltaT > 0. )(deltaT); PeerToClientMap::iterator itEnd = m_clients.end(); - for (PeerToClientMap::iterator it = m_clients.begin(); it != itEnd; ++it) + PeerToClientMap::iterator it = m_clients.begin(); + while (it != itEnd) { Client* c = it->second; NET_ASSERT(c); @@ -227,6 +226,27 @@ this->disconnect( c->id ); } } + else if (c->state == CS_DISCONNECTING) // graceful disconnections + { + c->timeLeft_ -= deltaT; + if (c->timeLeft_ < 0.) + { + NET_LOG("net_packet_server: client could not be gracefully disconnected. => killed."); + enet_peer_reset( c->peer ); + c->state = CS_DEAD; + PeerToClientMap::iterator itnext = it; + ++itnext; + m_id2client.erase( m_id2client.find( c->id ) ); + m_clients.erase( it ); + it = itnext; + fireCallback_ClientDisconnected( c->id ); + delete c; + c = 0; + continue; + } + } + // next + ++it; } m_timeOfLastUpdate = currT; } Modified: trunk/yake/src/yake/net/detail/netEventConnection.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netEventConnection.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/net/detail/netEventConnection.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -145,18 +145,24 @@ out.write( evt.id(), sizeof(NetEvent::id_type)*8 ) ; if (!evt.pack( out )) + { + NET_LOG("EvtConn: failed to pack event with id '" << int(evt.id()) << "'."); return; //@FIXME: inform user + } out.flush(); + NET_LOG("EvtConn: sending " << int(data.size()) << " bytes to '" << int(opt.getPeerId()) << "'."); conn_->send( &data.front(), data.size(), opt ); } void EventConnection::onReceivePacket(const PeerId peerId, const void* dataPtr, const size_t dataLen, const ChannelId channel) { + NET_LOG("EvtConn: received " << int(dataLen) << " bytes from '" << int(peerId) << "'."); NET_ASSERT( dataPtr && dataLen > 0 ); NET_ASSERT( dataLen >= sizeof(event_id) ); if (dataLen < sizeof(event_id)) { ++stats_.numInvalidPackets; + NET_LOG("EvtConn: invalid packet"); return; //@FIXME increase error count !? } @@ -171,18 +177,20 @@ ibitstream in(&dataSource); // extract event id - event_id evtId = NetEvent::EVTID_NONE; + event_id evtId = 0; in.read( evtId, sizeof(NetEvent::id_type)*8 ); // check event id EventIdMap::const_iterator it = eventIds_.find( evtId ); if (it == eventIds_.end()) { + NET_LOG("EvtConn: received unregistered event id '" << int(evtId) << "'."); ++stats_.numUnregisteredEventIds; return; } if (evtId == NetEvent::EVTID_NONE) { + NET_LOG("EvtConn: received invalid event id '" << int(evtId) << "'."); ++stats_.numInvalidEventIds; return; } @@ -192,6 +200,7 @@ { if (!contains(allowedEventIds_,evtId)) { + NET_LOG("EvtConn: blocked event id '" << int(evtId) << "'."); ++stats_.numBlockedEventIds; return; } @@ -204,6 +213,7 @@ { if (dir_ == evtDir) { + NET_LOG("EvtConn: wrong direction for event id '" << int(evtId) << "'."); ++stats_.numWrongEventDirection; return; } @@ -220,6 +230,7 @@ if (!evt->unpack(in)) { fnDestroy(evt); + NET_LOG("EvtConn: failed to unpack event with id '" << int(evtId) << "'."); ++stats_.numInvalidEvents; return; } Modified: trunk/yake/src/yake/net/detail/netInternal.cpp =================================================================== --- trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/net/detail/netInternal.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -80,7 +80,7 @@ it->second(); } } - native::sleep(10); + native::sleep(0); } } uint32 UpdateThread::add( const UpdateFn& fn ) Modified: trunk/yake/src/yake/samples/net/packet/demo.cpp =================================================================== --- trunk/yake/src/yake/samples/net/packet/demo.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/samples/net/packet/demo.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -24,8 +24,12 @@ } private: void onStarted(); + bool started() const + { + return started_; + } private: - safe_var<bool> started_; + bool started_; net::Address addr_; net::uint32 maxClients_; net::IServerPacketConnection* conn_; @@ -48,7 +52,7 @@ } bool server::start() { - YAKE_ASSERT( !started_.getCopy() ); + YAKE_ASSERT( !started_ ); YAKE_ASSERT( !conn_ ); YAKE_LOG("creating server...\n"); @@ -67,7 +71,7 @@ YAKE_SAFE_DELETE( conn_ ); return false; } - while (!started_.getCopy()) + while (!started_) { net::native::sleep(10); net::update(); @@ -86,7 +90,7 @@ void server::broadcastHello() { YAKE_ASSERT( conn_ ); - YAKE_ASSERT( started_.getCopy() ); + YAKE_ASSERT( started_ ); std::string hello("hello!"); conn_->send( hello.c_str(), hello.size(), net::SendOptions().reliability(net::R_RELIABLE) ); COUTLN("server:broadcastHello() " << conn_->getNumConnectedClients() << " client(s)"); @@ -114,9 +118,9 @@ { net::IClientPacketConnection* client = net::createClientPacketConnection(); YAKE_ASSERT( client ); - client->connect(net::Address(4000), false /*true=block until connection established or timeout.*/); client->addPacketReceivedCallback( client_onPacketReceived ); clients.push_back( yake::SharedPtr<net::IClientPacketConnection>(client) ); + client->connect(net::Address(4000), false /*true=block until connection established or timeout.*/); } //net::native::sleep(500); // unfortunately, this is still necessary... @@ -128,7 +132,9 @@ { net::native::sleep(10); net::update(); - if (!sentHello && theServer.numConnectedClients() > 0) + + // send hello when at least 3 clients have connected... + if (!sentHello && theServer.numConnectedClients() >= 3) { theServer.broadcastHello(); sentHello = true; Modified: trunk/yake/src/yake/samples/net/roclient/ROClient.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/samples/net/roclient/ROClient.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -7,175 +7,169 @@ namespace ro { -client::client() : timedOut_(false), conn_(false), running_(false), evtConn_(0), stage_(CS_JOINING) -{ -} -client::~client() -{ - stop(); -} -bool client::running() const -{ - boost::mutex::scoped_lock lck(runningMtx_); - return running_; -} -bool client::start(const net::Address& serverAddr) -{ - try { - // create connection & register callbacks - conn_ = net::createClientPacketConnection(); - assert( conn_ ); + client::client() : + timedOut_(false), running_(false), stage_(CS_JOINING) + { + } + client::~client() + { + stop(); + } + bool client::running() const + { + boost::mutex::scoped_lock lck(runningMtx_); + return running_; + } + bool client::start(const net::Address& serverAddr) + { + try { + // create connection & register callbacks + conn_.reset( net::createClientPacketConnection() ); + assert( conn_ ); - conn_->addTimeOutCallback( boost::bind(&client::onTimeOut,this) ); - conn_->addStartedCallback( boost::bind(&client::onClientStarted,this) ); + conn_->addTimeOutCallback( boost::bind(&client::onTimeOut,this) ); + conn_->addStartedCallback( boost::bind(&client::onClientStarted,this) ); - // attempt to connect to server - conn_->connect( serverAddr ); + // attempt to connect to server + conn_->connect( serverAddr ); - return true; - } - catch (const net::Exception& e) - { - COUTLN("Caught net exception: " << e.what()); - if (conn_) + return true; + } + catch (const net::Exception& e) { - delete conn_; - conn_ = 0; + COUTLN("Caught net exception: " << e.what()); + conn_.reset(); } + return false; } - return false; -} -void client::waitForStart() -{ - while (!timedOut_.getCopy() && !running()) + void client::waitForStart() { - net::native::sleep(10); - net::update(); - } - if (timedOut_.getCopy()) - return; - // set up event connection - assert( conn_ ); - assert( !evtConn_ ); - evtConn_ = net::createEventConnection(); - assert( evtConn_ ); + while (!timedOut_.getCopy() && !running()) + { + net::native::sleep(10); + net::update(); + } + if (timedOut_.getCopy()) + return; + // set up event connection + assert( conn_ ); + assert( !evtConn_ ); + evtConn_.reset( net::createEventConnection() ); + assert( evtConn_ ); - evtConn_->setPolling( true ); + evtConn_->setPolling( true ); - evtConn_->registerEvent( c2sEvtJoinReq::ID, net::NetEvent::DIR_ANY, - c2sEvtJoinReq::create, c2sEvtJoinReq::destroy ); - evtConn_->registerEvent( s2cEvtJoinReqReply::ID, net::NetEvent::DIR_ANY, - s2cEvtJoinReqReply::create, s2cEvtJoinReqReply::destroy ); - evtConn_->registerEvent( s2cEvtClassTable::ID, net::NetEvent::DIR_ANY, - s2cEvtClassTable::create, s2cEvtClassTable::destroy ); + evtConn_->registerEvent( c2sEvtJoinReq::ID, net::NetEvent::DIR_ANY, + c2sEvtJoinReq::create, c2sEvtJoinReq::destroy ); + evtConn_->registerEvent( s2cEvtJoinReqReply::ID, net::NetEvent::DIR_ANY, + s2cEvtJoinReqReply::create, s2cEvtJoinReqReply::destroy ); + evtConn_->registerEvent( s2cEvtClassTable::ID, net::NetEvent::DIR_ANY, + s2cEvtClassTable::create, s2cEvtClassTable::destroy ); - evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); - evtConn_->setPacketConnection( conn_, net::NetEvent::DIR_ANY ); + evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); + evtConn_->setPacketConnection( conn_.get(), net::NetEvent::DIR_ANY ); - evtConn_->start(); + evtConn_->start(); - // initiate "join" sequence - this->stage_ = CS_JOINING; + // initiate "join" sequence + this->stage_ = CS_JOINING; - c2sEvtJoinReq evt; - evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); - -#if NET_STRESS_TEST_LEVEL >= 1 - // send a second time to test our server logic :) - for (size_t i=0; i<3; ++i) + c2sEvtJoinReq evt; evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); -#endif - evt.setId( 23 ); // invalid id! - evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); + #if NET_STRESS_TEST_LEVEL >= 1 + // send a second time to test our server logic :) + for (size_t i=0; i<3; ++i) + evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); + #endif - while (stage_ == CS_JOINING) + evt.setId( 23 ); // invalid id! + evtConn_->sendEvent( evt, net::SendOptions().channel(CHANNELID_CONTROL) ); + + while (stage_ == CS_JOINING) + { + evtConn_->poll(); + net::update(); + net::native::sleep(0); + } + } + void client::step() { + if (!running()) + return; + evtConn_->poll(); - net::update(); - net::native::sleep(1); - } -} -void client::step() -{ - if (!running()) - return; - evtConn_->poll(); - - if (stage_ == CS_RUNNING) - { + if (stage_ == CS_RUNNING) + { + } } -} -void client::stop() -{ + void client::stop() { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = false; + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = false; + } + // clean up + if (evtConn_) + { + evtConn_->stop(); + evtConn_.reset(); + } + if (conn_) + { + conn_->disconnect(); + conn_.reset(); + } } - // clean up - if (evtConn_) + void client::onClientStarted() { - evtConn_->stop(); - delete evtConn_; - evtConn_ = 0; + COUTLN("client started."); + + { + boost::mutex::scoped_lock lck(runningMtx_); + running_ = true; + } } - if (conn_) + void client::onTimeOut() { - conn_->disconnect(); - delete conn_; - conn_ = 0; - } -} -void client::onClientStarted() -{ - COUTLN("client started."); + COUTLN("client could not connect to server. destroying connection object."); - { - boost::mutex::scoped_lock lck(runningMtx_); - running_ = true; + // Do NOT destroy the connection object here! It may still be inside the callback loop! + // We can call disconnect(), though. + timedOut_ = true; + //conn->disconnect(); } -} -void client::onTimeOut() -{ - COUTLN("client could not connect to server. destroying connection object."); - - // Do NOT destroy the connection object here! It may still be inside the callback loop! - // We can call disconnect(), though. - timedOut_ = true; - //conn->disconnect(); -} -void client::running_onProcessEvent(const net::PeerId, const net::NetEvent& evt, const net::ChannelId) -{ - COUTLN("client (running) received event (" << (int)evt.id() << ")."); - if (evt.id() == s2cEvtClassTable::ID) + void client::running_onProcessEvent(const net::PeerId, const net::NetEvent& evt, const net::ChannelId) { - COUTLN("starting sim " << evt.id()); + COUTLN("client (running) received event (" << (int)evt.id() << ")."); + if (evt.id() == s2cEvtClassTable::ID) + { + COUTLN("starting sim " << evt.id()); + } } -} -void client::init_onProcessEvent(const net::PeerId, const net::NetEvent& evt, const net::ChannelId) -{ - COUTLN("client (init) received event (" << (int)evt.id() << ")."); - if (stage_ == CS_JOINING) + void client::init_onProcessEvent(const net::PeerId, const net::NetEvent& evt, const net::ChannelId) { - if (evt.id() == s2cEvtJoinReqReply::ID) + COUTLN("client (init) received event (" << (int)evt.id() << ")."); + if (stage_ == CS_JOINING) { - const s2cEvtJoinReqReply& reply = static_cast<const s2cEvtJoinReqReply&>( evt ); - if (reply.accepted) + if (evt.id() == s2cEvtJoinReqReply::ID) { - COUTLN("CONNECTED TO SERVER."); - stage_ = CS_RUNNING; + const s2cEvtJoinReqReply& reply = static_cast<const s2cEvtJoinReqReply&>( evt ); + if (reply.accepted) + { + COUTLN("CONNECTED TO SERVER."); + stage_ = CS_RUNNING; + } + else + { + COUTLN("SERVER DENIED ACCESS!"); + stage_ = CS_DEAD; + evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); + } } - else - { - COUTLN("SERVER DENIED ACCESS!"); - stage_ = CS_DEAD; - evtConn_->setProcessEventCallback( boost::bind(&client::init_onProcessEvent,this,_1,_2,_3) ); - } } } -} - } // namespace ro Modified: trunk/yake/src/yake/samples/net/roclient/demo.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roclient/demo.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/samples/net/roclient/demo.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -30,4 +30,3 @@ net::shutdown(); return 0; } - Modified: trunk/yake/src/yake/samples/net/roserver/ROServer.cpp =================================================================== --- trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/src/yake/samples/net/roserver/ROServer.cpp 2006-11-01 15:19:39 UTC (rev 1492) @@ -13,7 +13,6 @@ enum stage_t { CS_WAIT_FOR_REQ = 1, // waiting for "req join" - CS_JOINED, // server acknowledged "join" request & sent ... CS_RUNNING, CS_DEAD }; @@ -75,6 +74,7 @@ while (!running()) { + //conn_->update(); ->@todo net::update(); net::native::sleep(10); } @@ -87,6 +87,7 @@ boost::mutex::scoped_lock lck(runningMtx_); running_ = false; } + clients_.clear(); if (conn_) { conn_->stop(); @@ -119,6 +120,7 @@ boost::mutex::scoped_lock lck(runningMtx_); running_ = true; } + COUTLN("server: starting event connection..."); YAKE_ASSERT( !evtConn_ ); evtConn_ = net::createEventConnection(); YAKE_ASSERT( evtConn_ ); @@ -134,6 +136,7 @@ evtConn_->setPacketConnection( conn_, net::NetEvent::DIR_ANY ); evtConn_->start(); + COUTLN("server: event connection started."); } void server::onReceivePacket(const net::PeerId peerId, const void* data, const size_t len, const net::ChannelId channel) { @@ -146,14 +149,17 @@ try { COUTLN("server received event (" << (int)evt.id() << ")."); + // Let client object handle the event. If no client object exists + // for this peer, create it. + // get client object - client* c = 0; + ClientPtr c; ClientPtrMap::iterator it = clients_.find( peerId ); if (it == clients_.end()) { - c = new client(); + c.reset( new Client() ); c->id = peerId; - c->stage = client::CS_WAIT_FOR_REQ; + c->stage = Client::CS_WAIT_FOR_REQ; c->evtConn = evtConn_; clients_.insert(std::make_pair(peerId,c)); } @@ -165,6 +171,7 @@ } catch (...) { + COUTLN("server: CAUGHT UNHANDLED EXCEPTION!\n"); } } //----------------------------------------------------------------------------- @@ -189,8 +196,13 @@ for (size_t i=0; i<3; ++i) evtConn->sendEvent( this->id, joinReply, net::SendOptions().channel(CHANNELID_CONTROL) ); #endif - this->stage = CS_JOINED; + // + s2cEvtClassTable clsTbl; + clsTbl.globalClassIds_["test"] = 42; + clsTbl.globalClassIds_["player"] = 56; + evtConn->sendEvent( this->id, clsTbl, net::SendOptions().channel(CHANNELID_CONTROL) ); + // use different event callback for the CS_RUNNING stage: COUTLN(" => RUNNING"); processEventFn_ = boost::bind(&client::running_onProcessEvent,this,_1,_2); @@ -203,7 +215,6 @@ YAKE_ASSERT( stage == CS_RUNNING ); if (stage != CS_RUNNING) return; - //@todo put events in a queue - it is then processed in the main simulation thread! //// send class table & start sim //s2cEvtClassTable evtClassTbl; //evtConn->sendEvent( this->id, evtClassTbl, net::SendOptions().channel(CHANNELID_SIMCTRL) ); Modified: trunk/yake/yake/net/netEvent.h =================================================================== --- trunk/yake/yake/net/netEvent.h 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/yake/net/netEvent.h 2006-11-01 15:19:39 UTC (rev 1492) @@ -155,7 +155,6 @@ typedef boost::function<NetEvent*(const NetEvent::id_type)> CreateEventFn; typedef boost::function<void(NetEvent*)> DestroyEventFn; - /** NB fnCreate and fnDestroy have to be threadsafe when manual polling is used! */ virtual void registerEvent(const NetEvent::id_type, const NetEvent::Direction, const CreateEventFn& fnCreate, const DestroyEventFn& fnDestroy) = 0; virtual void sendEvent(const NetEvent&, const SendOptions& opt = SendOptions()) = 0; Modified: trunk/yake/yake/net/netPacket.h =================================================================== --- trunk/yake/yake/net/netPacket.h 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/yake/net/netPacket.h 2006-11-01 15:19:39 UTC (rev 1492) @@ -7,7 +7,7 @@ /** Interface for packet sending objects. */ - class NET_API IPacketSender + class NET_API IPacketSender : public boost::noncopyable { public: virtual ~IPacketSender() {} @@ -35,13 +35,22 @@ /** Interface for packet receiving objects. */ - class NET_API IPacketReceiver + class NET_API IPacketReceiver : public boost::noncopyable { public: virtual ~IPacketReceiver() {} typedef boost::function<void(const PeerId, const void*, const size_t, const ChannelId)> OnPacketReceivedFn; - virtual CallbackConnection addPacketReceivedCallback( const OnPacketReceivedFn&) = 0; + // catch-all + virtual CallbackConnection addPacketReceivedCallback( const OnPacketReceivedFn& ) = 0; + /* + // catch for a channel + virtual CallbackConnection addPacketReceivedCallback( const OnPacketReceivedFn&, const ChannelId ) = 0; + // catch for a peer + virtual CallbackConnection addPacketReceivedCallback( const PeerId, const OnPacketReceivedFn& ) = 0; + // catch for peer and channel + virtual CallbackConnection addPacketReceivedCallback( const PeerId, const OnPacketReceivedFn&, const ChannelId ) = 0; + */ }; /** Interface for packet sending and receiving objects (connections). Modified: trunk/yake/yake/samples/net/common/commonEvents.h =================================================================== --- trunk/yake/yake/samples/net/common/commonEvents.h 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/yake/samples/net/common/commonEvents.h 2006-11-01 15:19:39 UTC (rev 1492) @@ -61,11 +61,58 @@ CLASS() : net::NetEvent(ID) \ {} +inline net::ibitstream& operator >> (net::ibitstream& in, net::uint8& rhs) +{ + in.read( rhs ); + return in; +} +inline net::obitstream& operator << (net::obitstream& out, const net::uint8 rhs) +{ + out.write( rhs ); + return out; +} +inline net::ibitstream& operator >> (net::ibitstream& in, net::uint16& rhs) +{ + in.read( rhs ); + return in; +} +inline net::obitstream& operator << (net::obitstream& out, const net::uint16 rhs) +{ + out.write( rhs ); + return out; +} +inline net::ibitstream& operator >> (net::ibitstream& in, net::uint32& rhs) +{ + in.read( rhs ); + return in; +} +inline net::obitstream& operator << (net::obitstream& out, const net::uint32 rhs) +{ + out.write( rhs ); + return out; +} +inline net::ibitstream& operator >> (net::ibitstream& in, int& rhs) +{ + in.read( rhs ); + return in; +} +inline net::obitstream& operator << (net::obitstream& out, const int rhs) +{ + out.write( rhs ); + return out; +} + struct version_t { net::uint8 ver[3]; - version_t(const net::uint8 maj = 0, const net::uint8 min = 0, const net::uint8 b = 0) + version_t() { + ver[0] = 0; + ver[1] = 0; + ver[2] = 0; + } + version_t(const net::uint8 maj, const net::uint8 min, const net::uint8 b) + { ver[0] = maj; ver[1] = min; ver[2] = b; @@ -101,26 +148,77 @@ } version_t version; }; +inline net::obitstream& operator << (net::obitstream& out, const std::string& rhs) +{ + out.write(int(rhs.length())); + if (!rhs.empty()) + out.write( rhs.c_str(), (rhs.size()*sizeof(std::string::value_type)*8) ); + return out; +} +inline net::ibitstream& operator >> (net::ibitstream& in, std::string& rhs) +{ + int len = 0; + in.read(len); + assert(len < 10000); // enforce upper limit + rhs.clear(); + rhs.reserve(len); + while (len>0) + { + char c = 0; + in.read(c); + rhs += c; + len--; + } + return in; +} +#define YAKE_FOR_EACH(ITER_TYPE,ITER_NAME,CTR) \ + for (ITER_TYPE ITER_NAME = CTR.begin(); ITER_NAME != CTR.end(); ++ITER_NAME) + +template<typename _Ty, typename _Pr, typename _Alloc> +inline net::obitstream& operator << (net::obitstream& out, const std::map<_Ty,_Pr,_Alloc>& ctr) +{ + out.write(net::uint32(ctr.size())); + typedef std::map<_Ty,_Pr,_Alloc> map_type; + typedef typename map_type::const_iterator iter_type; + YAKE_FOR_EACH(iter_type,it,ctr) + out << it->first << it->second; + return out; +} +template<typename _Ty, typename _Pr, typename _Alloc> +inline net::ibitstream& operator >> (net::ibitstream& in, std::map<_Ty,_Pr,_Alloc>& ctr) +{ + ctr.clear(); + net::uint32 count = 0; + in.read(count); + //@todo safe-guard count + typedef std::map<_Ty,_Pr,_Alloc> map_type; + typedef typename map_type::const_iterator iter_type; + for (size_t i=0; i<count; ++i) + { + std::pair<_Ty,_Pr> data; + in >> data.first; + in >> data.second; + ctr.insert( data ); + } + return in; +} struct s2cEvtJoinReqReply : public net::NetEvent { DECLARE_EVENT( s2cEvtJoinReqReply, 2 ); virtual bool pack(net::obitstream& out) const { out.write( accepted ); - std::string msg("blah burp!"); - out.write( msg.c_str(), msg.size()+1 ); + std::string msg("i wanna join!"); + out << msg; return true; } virtual bool unpack(net::ibitstream& in) { in.read( accepted ); + std::string msg; - net::uint8 c = 0; - while (in.read(c,8)) - { - msg += c; - } - COUTLN("MSG " << msg.c_str()); + in >> msg; + COUTLN("MSG: " << msg.c_str()); return true; } bool accepted; @@ -130,12 +228,18 @@ DECLARE_EVENT( s2cEvtClassTable, 10 ); virtual bool pack(net::obitstream& out) const { - //out << globalClassIds_; + std::map<int,int> c; + c[1] = 2; + c[3] = 46; + out << c; + out << globalClassIds_; return true; } virtual bool unpack(net::ibitstream& in) { - //in >> globalClassIds_; + std::map<int,int> c; + in >> c; + in >> globalClassIds_; return true; } //uint8 numClassIdBits_; Modified: trunk/yake/yake/samples/net/roclient/ROClient.h =================================================================== --- trunk/yake/yake/samples/net/roclient/ROClient.h 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/yake/samples/net/roclient/ROClient.h 2006-11-01 15:19:39 UTC (rev 1492) @@ -14,12 +14,12 @@ bool running() const; void step(); private: - net::IClientPacketConnection* conn_; - safe_var<bool> timedOut_; - net::INetEventConnection* evtConn_; + yake::SharedPtr<net::IClientPacketConnection> conn_; + safe_var<bool> timedOut_; + yake::SharedPtr<net::INetEventConnection> evtConn_; bool running_; - mutable boost::mutex runningMtx_; + mutable boost::mutex runningMtx_; enum stage_t { CS_DEAD = 1, @@ -37,42 +37,3 @@ } // namespace ro #endif -#ifndef RO_CLIENT_H -#define RO_CLIENT_H - -namespace ro { - - struct client - { - public: - client(); - ~client(); - bool start( const net::Address& ); - void waitForStart(); - void stop(); - bool running() const; - void step(); - private: - net::IClientPacketConnection* conn_; - safe_var<bool> timedOut_; - net::INetEventConnection* evtConn_; - - bool running_; - mutable boost::mutex runningMtx_; - - enum stage_t { - CS_DEAD = 1, - CS_JOINING, - CS_RUNNING - }; - stage_t stage_; - private: - void onClientStarted(); - void onTimeOut(); - void running_onProcessEvent(const net::PeerId, const net::NetEvent& , const net::ChannelId); - void init_onProcessEvent(const net::PeerId, const net::NetEvent& , const net::ChannelId); - }; - -} // namespace ro - -#endif Modified: trunk/yake/yake/samples/net/roserver/ROServer.h =================================================================== --- trunk/yake/yake/samples/net/roserver/ROServer.h 2006-11-01 15:18:35 UTC (rev 1491) +++ trunk/yake/yake/samples/net/roserver/ROServer.h 2006-11-01 15:19:39 UTC (rev 1492) @@ -17,11 +17,14 @@ void queueEvent(const net::PeerId, net::NetEvent*, const net::ChannelId); void queueEventBroadcast(net::NetEvent*, const net::ChannelId); private: + server(const server&); + server& operator=(const server&); + private: void onServerStarted(); void onReceivePacket(const net::PeerId, const void*, const size_t, const net::ChannelId); void onProcessEvent(const net::PeerId, const net::NetEvent&, const net::ChannelId); private: - bool running_; + volatile bool running_; mutable boost::mutex runningMtx_; bool running() const; @@ -30,9 +33,10 @@ net::IServerPacketConnection* conn_; net::INetEventConnection* evtConn_; - typedef server_impl::client client; + typedef server_impl::client Client; + typedef yake::SharedPtr<Client> ClientPtr; - typedef std::map<net::PeerId,client*> ClientPtrMap; + typedef std::map<net::PeerId,ClientPtr> ClientPtrMap; ClientPtrMap clients_; //@todo put into specialized object "NetEventQueue" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:18:46
|
Revision: 1491 http://svn.sourceforge.net/yake/?rev=1491&view=rev Author: psyclonist Date: 2006-11-01 07:18:35 -0800 (Wed, 01 Nov 2006) Log Message: ----------- Modified Paths: -------------- trunk/yake/scripts/msvc8/physics.vcproj Modified: trunk/yake/scripts/msvc8/physics.vcproj =================================================================== --- trunk/yake/scripts/msvc8/physics.vcproj 2006-11-01 15:17:49 UTC (rev 1490) +++ trunk/yake/scripts/msvc8/physics.vcproj 2006-11-01 15:18:35 UTC (rev 1491) @@ -250,12 +250,18 @@ > <FileConfiguration Name="Debug|Win32" - ExcludedFromBuild="true" > <Tool Name="VCCustomBuildTool" /> </FileConfiguration> + <FileConfiguration + Name="Release|Win32" + > + <Tool + Name="VCCustomBuildTool" + /> + </FileConfiguration> </File> <File RelativePath="..\..\yake\physics\yakePhysicsAvatar.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:18:00
|
Revision: 1490 http://svn.sourceforge.net/yake/?rev=1490&view=rev Author: psyclonist Date: 2006-11-01 07:17:49 -0800 (Wed, 01 Nov 2006) Log Message: ----------- enabled OSM Modified Paths: -------------- trunk/yake/yake/plugins/graphicsOgre/yakeGraphicsSystem.h Modified: trunk/yake/yake/plugins/graphicsOgre/yakeGraphicsSystem.h =================================================================== --- trunk/yake/yake/plugins/graphicsOgre/yakeGraphicsSystem.h 2006-11-01 15:16:34 UTC (rev 1489) +++ trunk/yake/yake/plugins/graphicsOgre/yakeGraphicsSystem.h 2006-11-01 15:17:49 UTC (rev 1490) @@ -40,7 +40,7 @@ #endif #if YAKE_PLATFORM == PLATFORM_WIN32 -//# define YAKE_USE_OSM +# define YAKE_USE_OSM # pragma message("Compiling graphicsOGRE with OSM support.") #else # pragma message("Compiling graphicsOGRE without OSM support.") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:16:43
|
Revision: 1489 http://svn.sourceforge.net/yake/?rev=1489&view=rev Author: psyclonist Date: 2006-11-01 07:16:34 -0800 (Wed, 01 Nov 2006) Log Message: ----------- enabled OSM Modified Paths: -------------- trunk/yake/scripts/msvc8/plugins/graphics/graphicsOgre.vcproj Modified: trunk/yake/scripts/msvc8/plugins/graphics/graphicsOgre.vcproj =================================================================== --- trunk/yake/scripts/msvc8/plugins/graphics/graphicsOgre.vcproj 2006-11-01 15:16:08 UTC (rev 1488) +++ trunk/yake/scripts/msvc8/plugins/graphics/graphicsOgre.vcproj 2006-11-01 15:16:34 UTC (rev 1489) @@ -285,7 +285,6 @@ > <FileConfiguration Name="Debug|Win32" - ExcludedFromBuild="true" > <Tool Name="VCCLCompilerTool" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <psy...@us...> - 2006-11-01 15:16:19
|
Revision: 1488 http://svn.sourceforge.net/yake/?rev=1488&view=rev Author: psyclonist Date: 2006-11-01 07:16:08 -0800 (Wed, 01 Nov 2006) Log Message: ----------- fixed memory leak Modified Paths: -------------- trunk/yake/src/yapp/raf/yakeRtApplicationState.cpp Modified: trunk/yake/src/yapp/raf/yakeRtApplicationState.cpp =================================================================== --- trunk/yake/src/yapp/raf/yakeRtApplicationState.cpp 2006-11-01 15:15:05 UTC (rev 1487) +++ trunk/yake/src/yapp/raf/yakeRtApplicationState.cpp 2006-11-01 15:16:08 UTC (rev 1488) @@ -96,9 +96,9 @@ while (!quitRequested()) { const real now = native::getTime(); - real elapsed = now - lastTime; - if (elapsed < real(0.0001)) - elapsed = real(0.01); + const real elapsed = std::min( real(0.5), (now - lastTime) ); + if (elapsed < 0.) + continue; if (getApp().getInputSystem()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |