diff options
author | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
---|---|---|
committer | Hans Lambermont <hans@lambermont.dyndns.org> | 2002-10-12 15:37:38 +0400 |
commit | 12315f4d0e0ae993805f141f64cb8c73c5297311 (patch) | |
tree | 59b45827cd8293cfb727758989c7a74b40183974 /source/gameengine/Network/LoopBackNetwork |
Initial revisionv2.25
Diffstat (limited to 'source/gameengine/Network/LoopBackNetwork')
3 files changed, 222 insertions, 0 deletions
diff --git a/source/gameengine/Network/LoopBackNetwork/Makefile b/source/gameengine/Network/LoopBackNetwork/Makefile new file mode 100644 index 00000000000..19fe362b8f7 --- /dev/null +++ b/source/gameengine/Network/LoopBackNetwork/Makefile @@ -0,0 +1,44 @@ +# +# $Id$ +# +# ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. The Blender +# Foundation also sells licenses for use in proprietary software under +# the Blender License. See http://www.blender.org/BL/ for information +# about this. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +# All rights reserved. +# +# The Original Code is: all of this file. +# +# Contributor(s): none yet. +# +# ***** END GPL/BL DUAL LICENSE BLOCK ***** +# +# + +LIBNAME = LoopBackNetwork +DIR = $(OCGDIR)/gameengine/Network/$(LIBNAME) + +include nan_compile.mk + +CCFLAGS += $(LEVEL_1_CPP_WARNINGS) + +CPPFLAGS += -I$(NAN_STRING)/include +CPPFLAGS += -I.. +CPPFLAGS += -I../../../kernel/gen_system + diff --git a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp new file mode 100644 index 00000000000..9d4069bcac6 --- /dev/null +++ b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp @@ -0,0 +1,110 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + * LoopbackNetworkDeviceInterface derived from NG_NetworkDeviceInterface + */ + +#include "NG_LoopBackNetworkDeviceInterface.h" +#include "NG_NetworkMessage.h" + +// temporary debugging printf's +#ifdef NAN_NET_DEBUG + #include <stdio.h> +#endif + +NG_LoopBackNetworkDeviceInterface::NG_LoopBackNetworkDeviceInterface() +{ + m_currentQueue=0; + Online(); // LoopBackdevices are 'online' immediately +} + +NG_LoopBackNetworkDeviceInterface::~NG_LoopBackNetworkDeviceInterface() +{ +} + +// perhaps this should go to the shared/common implementation too +void NG_LoopBackNetworkDeviceInterface::NextFrame() +{ + // Release reference to the messages while emptying the queue + while (m_messages[m_currentQueue].size() > 0) { + // Should do assert(m_events[0]); + m_messages[m_currentQueue][0]->Release(); + m_messages[m_currentQueue].pop_front(); + } + //m_messages[m_currentQueue].clear(); + + m_currentQueue=1-m_currentQueue; +} + +STR_String NG_LoopBackNetworkDeviceInterface::GetNetworkVersion() +{ + return LOOPBACK_NETWORK_VERSION; +} + +void NG_LoopBackNetworkDeviceInterface::SendNetworkMessage(NG_NetworkMessage* nwmsg) +{ +#ifdef NAN_NET_DEBUG + printf("NG_LBNDI::SendNetworkMessage '%s'->'%s' '%s' '%s'\n", + nwmsg->GetDestinationName().ReadPtr(), + nwmsg->GetSenderName().ReadPtr(), + nwmsg->GetSubject().ReadPtr(), + nwmsg->GetMessageText().ReadPtr()); +#endif + int backqueue = 1-m_currentQueue; + + nwmsg->AddRef(); + m_messages[backqueue].push_back(nwmsg); +} + +vector<NG_NetworkMessage*> NG_LoopBackNetworkDeviceInterface::RetrieveNetworkMessages() +{ + vector<NG_NetworkMessage*> messages; + + std::deque<NG_NetworkMessage*>::iterator mesit=m_messages[m_currentQueue].begin(); + for (; !(mesit == m_messages[m_currentQueue].end());mesit++) + { + + // We don't increase the reference count for these messages. We + // are passing a vector of messages in the interface and not + // explicitily storing the messgaes for long term usage + + messages.push_back(*mesit); + +#ifdef NAN_NET_DEBUG + printf("NG_LBNDI::RetrieveNetworkMessages '%s'->'%s' '%s' '%s'\n", + (*mesit)->GetDestinationName().ReadPtr(), + (*mesit)->GetSenderName().ReadPtr(), + (*mesit)->GetSubject().ReadPtr(), + (*mesit)->GetMessageText().ReadPtr()); +#endif + } + return messages; +} + diff --git a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h new file mode 100644 index 00000000000..ad87b232794 --- /dev/null +++ b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + * LoopbackNetworkDeviceInterface derived from NG_NetworkDeviceInterface + */ +#ifndef NG_LOOPBACKNETWORKDEVICEINTERFACE_H +#define NG_LOOPBACKNETWORKDEVICEINTERFACE_H + +#include <deque> +#include "NG_NetworkDeviceInterface.h" + +class NG_LoopBackNetworkDeviceInterface : public NG_NetworkDeviceInterface +{ + enum { + LOOPBACK_NETWORK_VERSION=28022001 + }; + + std::deque<NG_NetworkMessage*> m_messages[2]; + int m_currentQueue; + +public: + NG_LoopBackNetworkDeviceInterface(); + virtual ~NG_LoopBackNetworkDeviceInterface(); + + /** + * Clear message buffer + */ + virtual void NextFrame(); + + bool Connect(char *address, unsigned int port, char *password, + unsigned int localport, unsigned int timeout) { + return true;} + bool Disconnect(void) {return true;} + + virtual void SendNetworkMessage(class NG_NetworkMessage* msg); + virtual vector<NG_NetworkMessage*> RetrieveNetworkMessages(); + + STR_String GetNetworkVersion(); +}; + +#endif //NG_LOOPBACKNETWORKDEVICEINTERFACE_H |