Changeset 7801 for code/trunk
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 80 edited
- 19 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/bin/CMakeLists.txt
r5929 r7801 26 26 27 27 # Create run scripts for Windows to manually add the DLL path when executing 28 SET(RUN_SCRIPTS run standalone client1 client2 server dedicated dedicatedClient )28 SET(RUN_SCRIPTS run standalone client1 client2 server dedicated dedicatedClient masterserver) 29 29 IF(WIN32) 30 30 FOREACH(_script ${RUN_SCRIPTS}) -
code/trunk/data/gui/layouts/AudioMenu.layout
r6746 r7801 113 113 <Property Name="Text" >Theme changes might take 114 114 up to a minute.</Property> 115 <Property Name="TextColours" Value="FF 4444FF" />115 <Property Name="TextColours" Value="FFFFFFFF" /> 116 116 <Property Name="InheritsAlpha" Value="False" /> 117 117 <Property Name="HorzFormatting" Value="HorzCentred" /> -
code/trunk/data/gui/layouts/CreditsMenu.layout
r7732 r7801 32 32 <Property Name="VertScrollPosition" Value="0" /> 33 33 <Window Type="MenuWidgets/StaticText" Name="orxonox/CreditsText" > 34 <Property Name="TextColours" Value="FF 4444FF" />34 <Property Name="TextColours" Value="FFFFFFFF" /> 35 35 <Property Name="InheritsAlpha" Value="False" /> 36 36 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> … … 38 38 <Property Name="VertFormatting" Value="TopAligned" /> 39 39 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> 40 <Property Name="Text">Orxonox version 0.0.3 40 <Property Name="Text">wird sowieso nicht gelesen 41 Orxonox version 0.0.3 41 42 42 43 Programming Language: C++ - lua - tcl … … 45 46 46 47 http://www.orxonox.net 47 n 48 n 49 n 50 n 51 n 52 n 53 n 54 n 55 n </Property> 48 </Property> 56 49 </Window> 57 50 </Window> -
code/trunk/data/gui/layouts/GraphicsMenu.layout
r6746 r7801 15 15 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 16 16 <Property Name="VertFormatting" Value="TopAligned" /> 17 <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2 875,0},{0.75,0},{0.6375,0}}" />17 <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2,0},{0.75,0},{0.6375,0}}" /> 18 18 <Window Type="MenuWidgets/StaticText" Name="orxonox/Resolution" > 19 19 <Property Name="Text" Value="Resolution" /> … … 22 22 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 23 23 <Property Name="VertFormatting" Value="TopAligned" /> 24 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.1 5,0},{0.475,0},{0.92,0}}" />24 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.10,0},{0.475,0},{0.65,0}}" /> 25 25 <Window Type="MenuWidgets/Listbox" Name="orxonox/ResolutionListbox" > 26 26 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 27 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0. 15,0},{0.95,0},{0.95,0}}" />27 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.2,0},{0.95,0},{0.95,0}}" /> 28 28 <Event Name="ItemSelectionChanged" Function="GraphicsMenu.GraphicsResolutionListbox_changed"/> 29 </Window> 30 </Window> 31 <Window Type="MenuWidgets/StaticText" Name="orxonox/Themes" > 32 <Property Name="Text" Value="Themes" /> 33 <Property Name="InheritsAlpha" Value="False" /> 34 <Property Name="HorzFormatting" Value="HorzCentred" /> 35 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 36 <Property Name="VertFormatting" Value="TopAligned" /> 37 <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.10,0},{0.95,0},{0.35,0}}" /> 38 <Window Type="MenuWidgets/Listbox" Name="orxonox/ThemeDropBox" > 39 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 40 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.3,0},{0.95,0},{0.95,0}" /> 41 <Event Name="ItemSelectionChanged" Function="GraphicsMenu.ThemeDropBox_changed"/> 29 42 </Window> 30 43 </Window> … … 35 48 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 36 49 <Property Name="VertFormatting" Value="TopAligned" /> 37 <Property Name="UnifiedAreaRect" Value="{{0. 525,0},{0.15,0},{0.95,0},{0.35,0}}" />50 <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.70,0},{0.475,0},{0.85,0}}" /> 38 51 <Window Type="MenuWidgets/HorizontalScrollbar" Name="orxonox/BrightnessScrollbar" > 39 52 <Property Name="Disabled" Value="true" /> … … 53 66 <Property Name="Text" Value="Fullscreen" /> 54 67 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 55 <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0. 4,0},{0.85,0},{0.475,0}}" />68 <Property Name="UnifiedAreaRect" Value="{{0.65,0},{0.35,0},{0.85,0},{0.425,0}}" /> 56 69 <Event Name="CheckStateChanged" Function="GraphicsMenu.GraphicsFullscreenCheckbox_clicked"/> 57 70 </Window> … … 61 74 settings require 62 75 a game restart.</Property> 63 <Property Name="TextColours" Value="FF 4444FF" />76 <Property Name="TextColours" Value="FFFFFFFF" /> 64 77 <Property Name="InheritsAlpha" Value="False" /> 65 78 <Property Name="HorzFormatting" Value="HorzCentred" /> 66 79 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 67 80 <Property Name="VertFormatting" Value="TopAligned" /> 68 <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0. 525,0},{0.95,0},{0.92,0}}" />81 <Property Name="UnifiedAreaRect" Value="{{0.525,0},{0.425,0},{0.95,0},{0.85,0}}" /> 69 82 </Window> 70 83 </Window> -
code/trunk/data/gui/layouts/InGameMenu.layout
r6746 r7801 10 10 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 11 11 <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.3625,0},{0.6,0},{0.4125,0}}" /> 12 <Property Name="Alpha" Value="0. 7" />12 <Property Name="Alpha" Value="0.9" /> 13 13 <Event Name="Clicked" Function="InGameMenu.button_return_clicked"/> 14 14 </Window> … … 17 17 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 18 18 <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.4625,0},{0.6,0},{0.5125,0}}" /> 19 <Property Name="Alpha" Value="0. 7" />19 <Property Name="Alpha" Value="0.9" /> 20 20 <Event Name="Clicked" Function="InGameMenu.button_mainmenu_clicked"/> 21 21 </Window> … … 24 24 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 25 25 <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.5625,0},{0.6,0},{0.6125,0}}" /> 26 <Property Name="Alpha" Value="0. 7" />26 <Property Name="Alpha" Value="0.9" /> 27 27 <Event Name="Clicked" Function="InGameMenu.button_settings_clicked"/> 28 28 </Window> … … 31 31 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 32 32 <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.6625,0},{0.6,0},{0.7125,0}}" /> 33 <Property Name="Alpha" Value="0. 7" />33 <Property Name="Alpha" Value="0.9" /> 34 34 <Event Name="Clicked" Function="InGameMenu.button_quit_clicked"/> 35 35 </Window> -
code/trunk/data/gui/layouts/MultiplayerMenu.layout
r7732 r7801 32 32 <Event Name="SelectStateChanged" Function="MultiplayerMenu.InternetButton_clicked"/> 33 33 </Window> 34 35 36 34 </Window> 37 35 <Window Type="MenuWidgets/Button" Name="orxonox/MultiplayerBackButton" > -
code/trunk/data/gui/scripts/ChatBox-inputonly.lua
r7163 r7801 1 1 -- ChatBox-inputonly.lua 2 2 3 local P = createMenuSheet("ChatBox-inputonly" )3 local P = createMenuSheet("ChatBox-inputonly", true, TriBool.True, TriBool.Dontcare, false) 4 4 return P 5 5 -
code/trunk/data/gui/scripts/ChatBox.lua
r7612 r7801 1 1 -- ChatBox.lua 2 2 3 local P = createMenuSheet("ChatBox" )3 local P = createMenuSheet("ChatBox", true, TriBool.True, TriBool.Dontcare, false) 4 4 5 5 function P.ChatBoxCloseButton_clicked(e) -
code/trunk/data/gui/scripts/GraphicsMenu.lua
r7689 r7801 4 4 5 5 P.buttonList = {} 6 P.schemeList = {"TaharezGreen", "Orxonox"} 6 7 7 8 function P.onShow() … … 97 98 } 98 99 P.buttonList[1] = item 100 101 local dropbox = winMgr:getWindow("orxonox/ThemeDropBox") 102 local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_") 103 for k,v in pairs(P.schemeList) do 104 local item = CEGUI.createListboxTextItem(P.schemeList[k]) 105 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 106 CEGUI.toListbox(dropbox):addItem(item) 107 if v == scheme then 108 dropbox:setItemSelectState(item, true) 109 end 110 end 111 112 end 113 114 function P.ThemeDropBox_changed(e) 115 local dropbox = winMgr:getWindow("orxonox/ThemeDropBox") 116 local listbox = CEGUI.toListbox(dropbox) 117 local choice = listbox:getFirstSelectedItem() 118 local index = 0 119 if choice ~= nil then 120 index = listbox:getItemIndex(choice) 121 end 122 orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. P.schemeList[index+1]) 99 123 end 100 124 -
code/trunk/data/gui/scripts/InitialiseGUI.lua
r7734 r7801 5 5 winMgr = CEGUI.WindowManager:getSingleton() 6 6 7 local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_") 7 8 -- Load all required skins 8 schemeMgr:loadScheme("TaharezGreenLook.scheme")9 --schemeMgr:loadScheme("OrxonoxLook.scheme")9 --schemeMgr:loadScheme("TaharezGreenLook.scheme") 10 schemeMgr:loadScheme(scheme .. "Look.scheme") 10 11 --schemeMgr:loadScheme("TaharezLook.scheme") 11 12 --schemeMgr:loadScheme("WindowsLook.scheme") … … 16 17 -- By loading a different file (if there is) you can change the skin 17 18 -- of the menus or the HUD independently 18 schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme")19 menuImageSet = "TaharezGreenLook"20 schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme")21 hudImageSet = "TaharezGreenLook"22 --schemeMgr:loadScheme("OrxonoxLookMenuWidgets.scheme")23 --menuImageSet = "OrxonoxLook"24 --schemeMgr:loadScheme("OrxonoxLookHUDWidgets.scheme")25 --hudImageSet = "OrxonoxLook"19 --schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme") 20 --menuImageSet = "TaharezGreenLook" 21 --schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme") 22 --hudImageSet = "TaharezGreenLook" 23 schemeMgr:loadScheme(scheme .. "MenuWidgets.scheme") 24 menuImageSet = scheme .. "Look" 25 schemeMgr:loadScheme(scheme .. "HUDWidgets.scheme") 26 hudImageSet = scheme .. "Look" 26 27 27 28 -- Just a remaining test hack -
code/trunk/data/gui/scripts/MultiplayerMenu.lua
r7732 r7801 6 6 7 7 --joinMode is 1 for choice "LAN" and 2 for "Internet" 8 --initial status 09 P.joinMode = 08 --initial status 1 9 P.joinMode = 1 10 10 11 11 function P.onLoad() … … 33 33 34 34 function P.onShow() 35 P.showServerList()35 --P.showServerList() 36 36 37 37 --indices to iterate through buttonlist 38 38 P.oldindex = -2 39 39 P.index = -1 40 41 if P.joinMode == 1 then 42 local window = winMgr:getWindow("orxonox/MultiplayerLanButton") 43 local button = tolua.cast(window,"CEGUI::RadioButton") 44 button:setSelected(true) 45 end 46 if P.joinMode == 2 then 47 local window = winMgr:getWindow("orxonox/MultiplayerInternetButton") 48 local button = tolua.cast(window,"CEGUI::RadioButton") 49 button:setSelected(true) 50 end 40 51 end 41 52 42 53 function P.LanButton_clicked(e) 54 local we = CEGUI.toWindowEventArgs(e) 55 local button = tolua.cast(we.window,"CEGUI::RadioButton") 43 56 P.joinMode = 1 57 if button:isSelected() == true then 58 P.showServerList() 59 end 44 60 end 45 61 46 62 function P.InternetButton_clicked(e) 63 local we = CEGUI.toWindowEventArgs(e) 64 local button = tolua.cast(we.window,"CEGUI::RadioButton") 47 65 P.joinMode = 2 66 if button:isSelected() == true then 67 P.showServerList() 68 end 48 69 end 49 70 … … 55 76 function P.MultiplayerJoinButton_clicked(e) 56 77 local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() 57 58 if P.joinMode == 2 then 59 if choice then 60 local client = orxonox.Client:getInstance() 61 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 62 client:setDestination( P.serverList[index][2], 55556 ) 63 else 64 return 65 end 66 orxonox.execute("startClient") 67 hideAllMenuSheets() 78 if choice then 79 local client = orxonox.Client:getInstance() 80 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 81 client:setDestination( P.serverList[index][2], 55556 ) 68 82 else 69 --wait for Sandro's function83 return 70 84 end 71 85 orxonox.execute("startClient") 86 hideAllMenuSheets() 72 87 end 73 88 … … 77 92 78 93 function P.showServerList() 79 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 80 CEGUI.toListbox(listbox):resetList() 81 local discovery = orxonox.LANDiscovery:getInstance() 82 discovery:discover() 83 P.serverList = {} 84 local index = 0 85 local servername = "" 86 local serverip = "" 87 while true do 88 servername = discovery:getServerListItemName(index) 89 if servername == "" then 90 break 91 end 92 serverip = discovery:getServerListItemIP(index) 93 if serverip == "" then 94 break 95 end 96 table.insert(P.serverList, {servername, serverip}) 97 index = index + 1 98 end 99 index = 1 100 for k,v in pairs(P.serverList) do 101 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 102 item:setID(index) 103 index = index + 1 104 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 105 CEGUI.toListbox(listbox):addItem(item) 106 end 94 -- LAN Discovery 95 if P.joinMode == 1 then 96 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 97 CEGUI.toListbox(listbox):resetList() 98 local discovery = orxonox.LANDiscovery:getInstance() 99 discovery:discover() 100 P.serverList = {} 101 local index = 0 102 local servername = "" 103 local serverip = "" 104 while true do 105 servername = discovery:getServerListItemName(index) 106 if servername == "" then 107 break 108 end 109 serverip = discovery:getServerListItemIP(index) 110 if serverip == "" then 111 break 112 end 113 table.insert(P.serverList, {servername, serverip}) 114 index = index + 1 115 end 116 index = 1 117 for k,v in pairs(P.serverList) do 118 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 119 item:setID(index) 120 index = index + 1 121 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 122 CEGUI.toListbox(listbox):addItem(item) 123 end 124 -- WAN Discovery 125 elseif P.joinMode == 2 then 126 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 127 CEGUI.toListbox(listbox):resetList() 128 local discovery = orxonox.WANDiscovery:getInstance() 129 cout(0, "discovering.\n" ) 130 discovery:discover() 131 cout(0, "discovered.\n" ) 132 P.serverList = {} 133 local index = 0 134 local servername = "" 135 local serverip = "" 136 while true do 137 servername = discovery:getServerListItemName(index) 138 if servername == "" then 139 break 140 end 141 serverip = discovery:getServerListItemIP(index) 142 if serverip == "" then 143 break 144 end 145 table.insert(P.serverList, {servername, serverip}) 146 index = index + 1 147 end 148 index = 1 149 for k,v in pairs(P.serverList) do 150 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 151 item:setID(index) 152 index = index + 1 153 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 154 CEGUI.toListbox(listbox):addItem(item) 155 end 156 end 157 107 158 end 108 159 -
code/trunk/src/libraries/core/GUIManager.cc
r7709 r7801 59 59 #include "util/Exception.h" 60 60 #include "util/OrxAssert.h" 61 #include "ConfigValueIncludes.h" 61 62 #include "Core.h" 63 #include "CoreIncludes.h" 62 64 #include "GraphicsManager.h" 63 65 #include "LuaState.h" … … 100 102 101 103 GUIManager* GUIManager::singletonPtr_s = 0; 104 /*static*/ const std::string GUIManager::defaultScheme_ = "TaharezGreen"; 102 105 103 106 SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false); … … 118 121 , camera_(NULL) 119 122 { 123 RegisterRootObject(GUIManager); 124 this->setConfigValues(); 125 120 126 using namespace CEGUI; 121 127 … … 175 181 GUIManager::~GUIManager() 176 182 { 183 } 184 185 void GUIManager::setConfigValues(void) 186 { 187 SetConfigValue(guiScheme_, GUIManager::defaultScheme_) .description("Changes the current GUI scheme.") .callback(this, &GUIManager::changedGUIScheme); 188 } 189 190 void GUIManager::changedGUIScheme(void) 191 { 192 177 193 } 178 194 -
code/trunk/src/libraries/core/GUIManager.h
r7648 r7801 49 49 #include "util/Singleton.h" 50 50 #include "input/InputHandler.h" 51 #include "OrxonoxClass.h" 51 52 52 53 // Tolua includes (have to be relative to the current directory) … … 70 71 */ 71 72 class _CoreExport GUIManager // tolua_export 72 : public Singleton<GUIManager>, public InputHandler 73 : public Singleton<GUIManager>, public InputHandler, public OrxonoxClass 73 74 { // tolua_export 74 75 friend class Singleton<GUIManager>; … … 76 77 GUIManager(const std::pair<int, int>& mousePosition); 77 78 ~GUIManager(); 79 80 void setConfigValues(void); 81 void changedGUIScheme(void); 78 82 79 83 void preUpdate(const Clock& time); … … 143 147 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager 144 148 149 // The used CEGUI scheme. 150 static const std::string defaultScheme_; 151 std::string guiScheme_; 152 145 153 }; // tolua_export 146 154 } // tolua_export -
code/trunk/src/libraries/network/CMakeLists.txt
r7490 r7801 28 28 FunctionCallManager.cc 29 29 GamestateManager.cc 30 GamestateClient.cc30 #GamestateClient.cc 31 31 GamestateHandler.cc 32 32 LANDiscoverable.cc 33 33 LANDiscovery.cc 34 WANDiscoverable.cc 35 WANDiscovery.cc 36 MasterServerComm.cc 34 37 NetworkFunction.cc 35 38 Host.cc 36 39 Server.cc 40 MasterServer.cc 41 PeerList.cc 42 ServerList.cc 37 43 ServerConnection.cc 38 44 TrafficControl.cc … … 48 54 FunctionCall.h 49 55 FunctionCallManager.h 50 GamestateClient.h56 #GamestateClient.h 51 57 GamestateHandler.h 52 58 GamestateManager.h … … 54 60 LANDiscoverable.h 55 61 LANDiscovery.h 62 WANDiscoverable.h 63 WANDiscovery.h 64 MasterServerComm.h 56 65 NetworkFunction.h 57 66 NetworkPrecompiledHeaders.h 58 67 NetworkPrereqs.h 59 68 Server.h 69 MasterServer.h 70 PeerList.h 71 ServerList.h 60 72 ServerConnection.h 61 73 TrafficControl.h … … 69 81 Client.h 70 82 LANDiscovery.h 83 WANDiscovery.h 71 84 PCH_FILE 72 85 NetworkPrecompiledHeaders.h -
code/trunk/src/libraries/network/Client.cc
r7495 r7801 64 64 */ 65 65 Client::Client(): 66 gamestate(0),67 66 isSynched_(false), 68 67 gameStateFailure_(false), … … 85 84 { 86 85 Synchronisable::setClient(true); 87 this->gamestate = new GamestateClient();88 86 if( ClientConnection::establishConnection() ) 89 87 { 90 88 Host::setActive(true); 89 GamestateManager::addPeer(NETWORK_PEER_ID_SERVER); 91 90 return true; 92 91 } … … 101 100 bool Client::closeConnection() 102 101 { 103 assert(this->gamestate);104 delete this->gamestate;105 this->gamestate = 0;106 102 Host::setActive(false); 103 GamestateManager::removePeer(NETWORK_PEER_ID_SERVER); 107 104 return ClientConnection::closeConnection(); 108 105 } … … 114 111 } 115 112 116 bool Client::queuePacket(ENetPacket *packet, int clientID) 117 { 118 bool b = ClientConnection::addPacket(packet); 119 assert(b); 120 return b; 113 void Client::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID) 114 { 115 ClientConnection::addPacket(packet, channelID); 121 116 } 122 117 … … 140 135 { 141 136 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 142 return m->send( );137 return m->send(static_cast<Host*>(this)); 143 138 } 144 139 … … 159 154 { 160 155 COUT(4) << "popping partial gamestate: " << std::endl; 161 packet::Gamestate *gs = gamestate->getGamestate(); 156 // packet::Gamestate *gs = GamestateClient::getGamestate(); 157 GamestateManager::update(); 158 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 159 std::vector<packet::Gamestate*>::iterator it; 160 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 161 { 162 (*it)->send( static_cast<Host*>(this) ); 163 } 162 164 //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now 163 if(gs){164 COUT(4) << "client tick: sending gs " << gs << std::endl;165 if( !gs->send() )166 COUT(3) << "Problem adding partial gamestate to queue" << std::endl;167 // gs gets automatically deleted by enet callback168 }169 FunctionCallManager::sendCalls( );165 // if(gs){ 166 // COUT(4) << "client tick: sending gs " << gs << std::endl; 167 // if( !gs->send() ) 168 // COUT(2) << "Problem adding partial gamestate to queue" << std::endl; 169 // // gs gets automatically deleted by enet callback 170 // } 171 FunctionCallManager::sendCalls(static_cast<Host*>(this)); 170 172 } 171 173 } 172 sendPackets(); // flush the enet queue174 // sendPackets(); // flush the enet queue 173 175 174 176 Connection::processQueue(); 175 if( gamestate->processGamestates())177 if(GamestateManager::processGamestates()) 176 178 { 177 179 FunctionCallManager::processBufferedFunctionCalls(); … … 179 181 isSynched_=true; 180 182 } 181 gamestate->cleanup();182 Connection::sendPackets();183 // GamestateManager::cleanup();; 184 // Connection::sendPackets(); 183 185 184 186 return; … … 200 202 Game::getInstance().popState(); 201 203 } 204 205 void Client::processPacket(packet::Packet* packet) 206 { 207 if( packet->isReliable() ) 208 { 209 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 210 packet->process(static_cast<Host*>(this)); 211 else 212 this->packetQueue_.push_back(packet); 213 } 214 else 215 packet->process(static_cast<Host*>(this)); 216 } 217 202 218 203 219 -
code/trunk/src/libraries/network/Client.h
r7163 r7801 45 45 46 46 #include <string> 47 #include <deque> 47 48 48 49 #include "util/UtilPrereqs.h" 49 50 #include "util/Singleton.h" 50 51 #include "ClientConnection.h" 51 #include "GamestateClient.h"52 // #include "GamestateClient.h" 52 53 #include "Host.h" 53 54 #include "LANDiscovery.h" … … 78 79 void setDestination( const std::string& serverAddress, unsigned int port ); // tolua_export 79 80 bool closeConnection(); 80 bool queuePacket(ENetPacket *packet, int clientID); 81 void queuePacket(ENetPacket* packet, int clientID, uint8_t channelID); 82 virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); } 81 83 bool processChat(const std::string& message, unsigned int playerID); 82 84 virtual bool chat(const std::string& message); … … 90 92 Client(const Client& copy); // not used 91 93 virtual bool isServer_(){return false;} 94 void processPacket(packet::Packet* packet); 92 95 93 96 static Client* singletonPtr_s; 94 GamestateClient* gamestate;95 97 bool isSynched_; 98 std::deque<packet::Packet*> packetQueue_; 96 99 97 100 bool gameStateFailure_; -
code/trunk/src/libraries/network/ClientConnection.cc
r7459 r7801 39 39 const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs 40 40 const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 1; 41 const unsigned int NETWORK_CLIENT_CHANNELS = 1;42 41 43 42 … … 71 70 ENetEvent event; 72 71 73 this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0, 0); 72 // create host 73 this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0); 74 74 75 if ( this->host_ == NULL ) 75 76 { … … 78 79 return false; 79 80 } 81 82 // enable compression 83 this->enableCompression(); 84 80 85 assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL ); 81 86 if (this->host_->socket4 == ENET_SOCKET_NULL) … … 86 91 COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl; 87 92 88 this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_C LIENT_CHANNELS, 0);93 this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CHANNEL_COUNT, 0); 89 94 if ( this->server_==NULL ) 90 95 { … … 99 104 { 100 105 this->established_=true; 106 Connection::startCommunicationThread(); 101 107 return true; 102 108 } … … 112 118 return true; 113 119 this->established_ = false; 120 Connection::stopCommunicationThread(); 114 121 enet_peer_disconnect(this->server_, 0); 115 122 for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++) … … 138 145 139 146 140 bool ClientConnection::addPacket(ENetPacket *packet) {147 void ClientConnection::addPacket(ENetPacket *packet, uint8_t channelID) { 141 148 assert( this->server_ ); 142 149 assert( packet ); 143 return Connection::addPacket( packet, this->server_ );150 return Connection::addPacket( packet, this->server_, channelID ); 144 151 } 145 152 … … 153 160 COUT(1) << "Received disconnect Packet from Server!" << endl; 154 161 // server closed the connection 162 this->stopCommunicationThread(); 155 163 this->connectionClosed(); 156 164 } -
code/trunk/src/libraries/network/ClientConnection.h
r6417 r7801 44 44 void setPort( unsigned int port ); 45 45 46 ENetEvent *getEvent();46 // ENetEvent *getEvent(); 47 47 // check wheter the packet queue is empty 48 bool queueEmpty();48 // bool queueEmpty(); 49 49 // create a new listener thread 50 50 virtual bool establishConnection(); 51 51 virtual bool closeConnection(); 52 52 // add a packet to queue for the server 53 bool addPacket(ENetPacket *packet);53 void addPacket(ENetPacket *packet, uint8_t channelID); 54 54 inline bool isConnected(){ return this->established_; } 55 55 protected: -
code/trunk/src/libraries/network/ClientInformation.cc
r7459 r7801 56 56 preve=0; 57 57 nexte=0; 58 partialGamestateID_=GAMESTATEID_INITIAL-1;59 58 synched_=false; 60 59 } … … 133 132 } 134 133 135 bool ClientInformation::setPartialGamestateID(int id){136 if(!this)137 return false;138 partialGamestateID_=id;139 return true;140 }141 142 134 unsigned int ClientInformation::getID() { 143 135 if(!this) … … 154 146 } 155 147 156 int ClientInformation::getFailures(){157 return failures_;158 }159 void ClientInformation::addFailure(){160 failures_++;161 }162 void ClientInformation::resetFailures(){163 failures_=0;164 }165 166 148 uint32_t ClientInformation::getRTT(){ 167 149 return this->peer_->roundTripTime; … … 175 157 if(this) 176 158 return gamestateID_; 177 else178 return static_cast<unsigned int>(-1);179 }180 181 unsigned int ClientInformation::getPartialGamestateID() {182 if(this)183 return partialGamestateID_;184 159 else 185 160 return static_cast<unsigned int>(-1); -
code/trunk/src/libraries/network/ClientInformation.h
r5781 r7801 66 66 bool setPeer(ENetPeer *peer); 67 67 bool setGamestateID(int id); 68 bool setPartialGamestateID(int id);69 68 inline void setShipID(unsigned int id){ShipID_=id;} 70 69 … … 73 72 unsigned int getID(); 74 73 unsigned int getGamestateID(); 75 unsigned int getPartialGamestateID();76 74 ENetPeer *getPeer(); 77 75 78 int getFailures();79 void addFailure();80 void resetFailures();81 76 uint32_t getRTT(); 82 77 double getPacketLoss(); … … 106 101 unsigned int clientID_; 107 102 unsigned int gamestateID_; 108 unsigned int partialGamestateID_;109 103 unsigned int ShipID_; // this is the unique objectID 110 104 bool synched_; 111 unsigned short failures_;112 105 113 106 }; -
code/trunk/src/libraries/network/Connection.cc
r7163 r7801 30 30 31 31 #include <cassert> 32 #include <deque> 32 33 #define WIN32_LEAN_AND_MEAN 33 34 #include <enet/enet.h> 35 #include <boost/thread.hpp> 36 #include <boost/thread/mutex.hpp> 37 #include <boost/date_time.hpp> 38 34 39 #include "packet/Packet.h" 35 40 36 41 namespace orxonox 37 42 { 38 // Connection *Connection::instance_=0;43 const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20); 39 44 40 45 Connection::Connection(): 41 host_(0) 42 { 43 // assert(instance_==0); 44 // Connection::instance_=this; 46 host_(0), bCommunicationThreadRunning_(false) 47 { 45 48 enet_initialize(); 46 49 atexit(enet_deinitialize); 47 } 48 49 Connection::~Connection(){ 50 // Connection::instance_=0; 51 } 52 53 int Connection::service(ENetEvent* event) { 54 return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT ); 55 } 56 57 void Connection::disconnectPeer(ENetPeer *peer) { 58 enet_peer_disconnect(peer, 0); 59 } 60 61 bool Connection::addPacket(ENetPacket *packet, ENetPeer *peer) { 62 if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0) 63 return false; 64 else 65 return true; 66 } 67 68 bool Connection::sendPackets() { 69 if ( /*!Connection::instance_ || */this->host_==NULL ) 70 return false; 71 enet_host_flush(this->host_); 72 return true; 73 } 74 75 void Connection::processQueue() { 50 this->incomingEventsMutex_ = new boost::mutex; 51 this->outgoingEventsMutex_ = new boost::mutex; 52 } 53 54 Connection::~Connection() 55 { 56 delete this->incomingEventsMutex_; 57 delete this->outgoingEventsMutex_; 58 } 59 60 void Connection::startCommunicationThread() 61 { 62 this->bCommunicationThreadRunning_ = true; 63 this->communicationThread_ = new boost::thread(&Connection::communicationThread, this); 64 } 65 66 void Connection::stopCommunicationThread() 67 { 68 this->bCommunicationThreadRunning_ = false; 69 if( !this->communicationThread_->timed_join(NETWORK_COMMUNICATION_THREAD_WAIT_TIME) ) 70 { 71 // force thread to stop 72 this->communicationThread_->interrupt(); 73 } 74 delete this->communicationThread_; 75 } 76 77 78 // int Connection::service(ENetEvent* event) { 79 // return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT ); 80 // } 81 82 void Connection::disconnectPeer(ENetPeer *peer) 83 { 84 assert(peer); 85 outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 }; 86 87 this->outgoingEventsMutex_->lock(); 88 this->outgoingEvents_.push_back(outEvent); 89 this->outgoingEventsMutex_->unlock(); 90 } 91 92 void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID) 93 { 94 assert(peer); 95 outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID }; 96 97 this->outgoingEventsMutex_->lock(); 98 this->outgoingEvents_.push_back(outEvent); 99 this->outgoingEventsMutex_->unlock(); 100 } 101 102 void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID) 103 { 104 outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID }; 105 106 this->outgoingEventsMutex_->lock(); 107 this->outgoingEvents_.push_back(outEvent); 108 this->outgoingEventsMutex_->unlock(); 109 } 110 111 112 void Connection::communicationThread() 113 { 76 114 ENetEvent event; 77 78 assert(this->host_); 79 80 while( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 115 116 while( bCommunicationThreadRunning_ ) 81 117 { 82 switch(event.type){ 118 // Receive all pending incoming Events (such as packets, connects and disconnects) 119 while( enet_host_check_events( this->host_, &event ) > 0 ) 120 { 121 // COUT(0) << "incoming event" << endl; 122 // received an event 123 this->incomingEventsMutex_->lock(); 124 this->incomingEvents_.push_back(event); 125 this->incomingEventsMutex_->unlock(); 126 } 127 128 // Send all waiting outgoing packets 129 this->outgoingEventsMutex_->lock(); 130 uint32_t outgoingEventsCount = this->outgoingEvents_.size(); 131 this->outgoingEventsMutex_->unlock(); 132 while( outgoingEventsCount > 0 ) 133 { 134 // COUT(0) << "outgoing event" << endl; 135 this->outgoingEventsMutex_->lock(); 136 outgoingEvent outEvent = this->outgoingEvents_.front(); 137 this->outgoingEvents_.pop_front(); 138 this->outgoingEventsMutex_->unlock(); 139 140 switch( outEvent.type ) 141 { 142 case outgoingEventType::sendPacket: 143 enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet ); 144 break; 145 case outgoingEventType::disconnectPeer: 146 enet_peer_disconnect(outEvent.peer, 0); 147 break; 148 case outgoingEventType::broadcastPacket: 149 enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet ); 150 break; 151 default: 152 assert(0); 153 } 154 this->outgoingEventsMutex_->lock(); 155 outgoingEventsCount = this->outgoingEvents_.size(); 156 this->outgoingEventsMutex_->unlock(); 157 } 158 159 // Wait for incoming events (at most NETWORK_WAIT_TIMEOUT ms) 160 if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 ) 161 { 162 // COUT(0) << "incoming event after wait" << endl; 163 //received an event 164 this->incomingEventsMutex_->lock(); 165 this->incomingEvents_.push_back(event); 166 this->incomingEventsMutex_->unlock(); 167 } 168 } 169 } 170 171 void Connection::processQueue() 172 { 173 ENetEvent event; 174 175 this->incomingEventsMutex_->lock(); 176 uint32_t incomingEventsCount = this->incomingEvents_.size(); 177 this->incomingEventsMutex_->unlock(); 178 while( incomingEventsCount > 0 ) 179 { 180 packet::Packet* p; 181 this->incomingEventsMutex_->lock(); 182 event = this->incomingEvents_.front(); 183 this->incomingEvents_.pop_front(); 184 this->incomingEventsMutex_->unlock(); 185 186 switch(event.type) 187 { 83 188 // log handling ================ 84 189 case ENET_EVENT_TYPE_CONNECT: … … 89 194 break; 90 195 case ENET_EVENT_TYPE_RECEIVE: 91 processPacket( &event ); 196 // COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl; 197 p = createPacket( &event ); 198 processPacket(p); 92 199 break; 93 200 case ENET_EVENT_TYPE_NONE: 94 201 break; 95 202 } 203 204 this->incomingEventsMutex_->lock(); 205 incomingEventsCount = this->incomingEvents_.size(); 206 this->incomingEventsMutex_->unlock(); 96 207 } 97 208 } 98 209 99 bool Connection::processPacket(ENetEvent* event) { 210 packet::Packet* Connection::createPacket(ENetEvent* event) 211 { 100 212 packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); 101 return p->process(); 102 } 213 return p; 214 // return p->process(); 215 } 216 217 void Connection::enableCompression() 218 { 219 enet_host_compress_with_range_coder( this->host_ ); 220 } 221 103 222 104 223 } -
code/trunk/src/libraries/network/Connection.h
r7163 r7801 43 43 #include "NetworkPrereqs.h" 44 44 45 #include <deque> 46 #include <enet/enet.h> 47 48 namespace boost 49 { 50 class thread; 51 class mutex; 52 } 53 45 54 namespace orxonox 46 55 { 47 const unsigned int NETWORK_PORT = 55556; 48 const unsigned int NETWORK_MAX_CONNECTIONS = 50; 49 const unsigned int NETWORK_WAIT_TIMEOUT = 0; 50 const unsigned int NETWORK_DEFAULT_CHANNEL = 0; 51 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 52 53 class _NetworkExport Connection{ 56 const unsigned int NETWORK_PORT = 55556; 57 const unsigned int NETWORK_MAX_CONNECTIONS = 50; 58 const unsigned int NETWORK_WAIT_TIMEOUT = 1; 59 const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5; 60 61 namespace outgoingEventType 62 { 63 enum Value 64 { 65 sendPacket = 1, 66 disconnectPeer = 2, 67 broadcastPacket = 3 68 }; 69 70 } 71 72 struct _NetworkExport outgoingEvent 73 { 74 ENetPeer* peer; 75 outgoingEventType::Value type; 76 ENetPacket* packet; 77 ENetChannelID channelID; 78 }; 79 80 class _NetworkExport Connection 81 { 54 82 public: 55 83 virtual ~Connection(); 56 84 57 static bool addPacket(ENetPacket *packet, ENetPeer *peer);58 bool sendPackets();59 ENetHost* getHost(){ return this->host_; }85 void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID); 86 void broadcastPacket(ENetPacket* packet, uint8_t channelID); 87 // ENetHost* getHost(){ return this->host_; } 60 88 61 89 protected: … … 63 91 // static Connection* getInstance(){ return Connection::instance_; } 64 92 65 int service(ENetEvent* event); 93 // int service(ENetEvent* event); 94 void startCommunicationThread(); 95 void stopCommunicationThread(); 96 void communicationThread(); 66 97 virtual void disconnectPeer(ENetPeer *peer); 98 99 void enableCompression(); 67 100 68 101 void processQueue(); 69 102 virtual void addPeer(ENetEvent* event)=0; 70 103 virtual void removePeer(ENetEvent* event)=0; 71 virtual bool processPacket(ENetEvent* event); 104 virtual void processPacket( packet::Packet* packet)=0; 105 virtual packet::Packet* createPacket(ENetEvent* event); 72 106 73 ENetHost *host_;107 ENetHost* host_; 74 108 private: 75 ENetAddress *bindAddress_; 109 boost::thread* communicationThread_; 110 bool bCommunicationThreadRunning_; 111 ENetAddress* bindAddress_; 112 std::deque<ENetEvent> incomingEvents_; 113 std::deque<outgoingEvent> outgoingEvents_; 114 boost::mutex* incomingEventsMutex_; 115 boost::mutex* outgoingEventsMutex_; 76 116 77 117 // static Connection *instance_; -
code/trunk/src/libraries/network/FunctionCallManager.cc
r7495 r7801 30 30 #include "packet/FunctionCalls.h" 31 31 #include "core/GameMode.h" 32 #include "GamestateHandler.h" 32 33 33 34 namespace orxonox { 34 35 35 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::s ClientMap_;36 std::vector< FunctionCall> FunctionCallManager::sIncomingFunctionCallBuffer_;36 std::map<uint32_t, packet::FunctionCalls*> FunctionCallManager::sPeerMap_; 37 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > > FunctionCallManager::sIncomingFunctionCallBuffer_; 37 38 38 39 // Static calls 39 40 40 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID)41 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID) 41 42 { 42 if(s ClientMap_.find(clientID)==sClientMap_.end())43 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 43 44 { 44 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;45 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);45 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 46 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 46 47 } 47 FunctionCallManager::s ClientMap_[clientID]->addCallStatic(functionID);48 FunctionCallManager::sPeerMap_[peerID]->addCallStatic(functionID); 48 49 } 49 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1)50 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1) 50 51 { 51 if(s ClientMap_.find(clientID)==sClientMap_.end())52 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 52 53 { 53 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;54 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);54 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 55 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 55 56 } 56 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1);57 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1); 57 58 } 58 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)59 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2) 59 60 { 60 if(s ClientMap_.find(clientID)==sClientMap_.end())61 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 61 62 { 62 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;63 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);63 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 64 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 64 65 } 65 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2);66 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2); 66 67 } 67 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)68 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 68 69 { 69 if(s ClientMap_.find(clientID)==sClientMap_.end())70 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 70 71 { 71 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;72 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);72 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 73 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 73 74 } 74 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3);75 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3); 75 76 } 76 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)77 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 77 78 { 78 if(s ClientMap_.find(clientID)==sClientMap_.end())79 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 79 80 { 80 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;81 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);81 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 82 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 82 83 } 83 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4);84 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4); 84 85 } 85 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)86 void FunctionCallManager::addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 86 87 { 87 if(s ClientMap_.find(clientID)==sClientMap_.end())88 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 88 89 { 89 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;90 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);90 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 91 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 91 92 } 92 FunctionCallManager:: s ClientMap_[clientID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5);93 FunctionCallManager:: sPeerMap_[peerID]->addCallStatic(functionID, &mt1, &mt2, &mt3, &mt4, &mt5); 93 94 } 94 95 … … 96 97 // MemberCalls 97 98 98 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID)99 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID) 99 100 { 100 if(s ClientMap_.find(clientID)==sClientMap_.end())101 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 101 102 { 102 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;103 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);103 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 104 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 104 105 } 105 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID);106 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID); 106 107 } 107 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1)108 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1) 108 109 { 109 if(s ClientMap_.find(clientID)==sClientMap_.end())110 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 110 111 { 111 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;112 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);112 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 113 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 113 114 } 114 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1);115 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1); 115 116 } 116 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2)117 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2) 117 118 { 118 if(s ClientMap_.find(clientID)==sClientMap_.end())119 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 119 120 { 120 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;121 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);121 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 122 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 122 123 } 123 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2);124 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2); 124 125 } 125 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3)126 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3) 126 127 { 127 if(s ClientMap_.find(clientID)==sClientMap_.end())128 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 128 129 { 129 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;130 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);130 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 131 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 131 132 } 132 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3);133 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3); 133 134 } 134 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)135 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4) 135 136 { 136 if(s ClientMap_.find(clientID)==sClientMap_.end())137 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 137 138 { 138 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;139 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);139 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 140 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 140 141 } 141 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4);142 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4); 142 143 } 143 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)144 void FunctionCallManager::addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5) 144 145 { 145 if(s ClientMap_.find(clientID)==sClientMap_.end())146 if(sPeerMap_.find(peerID)==sPeerMap_.end()) 146 147 { 147 FunctionCallManager::s ClientMap_[clientID] = new packet::FunctionCalls;148 FunctionCallManager::s ClientMap_[clientID]->setClientID(clientID);148 FunctionCallManager::sPeerMap_[peerID] = new packet::FunctionCalls; 149 FunctionCallManager::sPeerMap_[peerID]->setPeerID(peerID); 149 150 } 150 FunctionCallManager::s ClientMap_[clientID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5);151 FunctionCallManager::sPeerMap_[peerID]->addCallMember(functionID, objectID, &mt1, &mt2, &mt3, &mt4, &mt5); 151 152 } 152 153 153 154 // Send calls 154 155 155 void FunctionCallManager::sendCalls( )156 void FunctionCallManager::sendCalls(orxonox::Host* host) 156 157 { 157 158 std::map<uint32_t, packet::FunctionCalls*>::iterator it; 158 for (it = FunctionCallManager::s ClientMap_.begin(); it != FunctionCallManager::sClientMap_.end(); ++it )159 for (it = FunctionCallManager::sPeerMap_.begin(); it != FunctionCallManager::sPeerMap_.end(); ++it ) 159 160 { 160 assert(!FunctionCallManager::s ClientMap_.empty());161 it->second->send( );161 assert(!FunctionCallManager::sPeerMap_.empty()); 162 it->second->send(host); 162 163 } 163 FunctionCallManager::s ClientMap_.clear();164 FunctionCallManager::sPeerMap_.clear(); 164 165 } 165 166 166 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall )167 void FunctionCallManager::bufferIncomingFunctionCall(const orxonox::FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID) 167 168 { 168 if( !GameMode::isMaster() ) 169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( fctCall ); 169 FunctionCallManager::sIncomingFunctionCallBuffer_.push_back( std::make_pair(fctCall, std::make_pair(minGamestateID, peerID))); 170 170 } 171 171 172 172 void FunctionCallManager::processBufferedFunctionCalls() 173 173 { 174 std::vector< FunctionCall>::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin();174 std::vector<std::pair<FunctionCall, std::pair<uint32_t, uint32_t> > >::iterator it = FunctionCallManager::sIncomingFunctionCallBuffer_.begin(); 175 175 while( it!=FunctionCallManager::sIncomingFunctionCallBuffer_.end() ) 176 176 { 177 if( it-> execute() )177 if( it->first.execute() ) 178 178 FunctionCallManager::sIncomingFunctionCallBuffer_.erase(it); 179 179 else 180 { 180 181 ++it; 182 } 181 183 } 182 184 } -
code/trunk/src/libraries/network/FunctionCallManager.h
r7495 r7801 34 34 #include <map> 35 35 #include <vector> 36 #include <utility> 36 37 #include "util/UtilPrereqs.h" 37 38 #include "FunctionCall.h" … … 45 46 { 46 47 public: 47 static void addCallStatic(uint32_t functionID, uint32_t clientID);48 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1);49 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);50 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);51 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);52 static void addCallStatic(uint32_t functionID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);48 static void addCallStatic(uint32_t functionID, uint32_t peerID); 49 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1); 50 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2); 51 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3); 52 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 53 static void addCallStatic(uint32_t functionID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 53 54 54 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID);55 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1);56 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2);57 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3);58 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4);59 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t clientID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5);55 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID); 56 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1); 57 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2); 58 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3); 59 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4); 60 static void addCallMember(uint32_t functionID, uint32_t objectID, uint32_t peerID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5); 60 61 61 static void sendCalls( );62 static void sendCalls(orxonox::Host* host); 62 63 63 static void bufferIncomingFunctionCall( const FunctionCall& fctCall );64 static void bufferIncomingFunctionCall( const FunctionCall& fctCall, uint32_t minGamestateID, uint32_t peerID ); 64 65 static void processBufferedFunctionCalls(); 65 66 66 static std::map<uint32_t, packet::FunctionCalls*> sClientMap_;67 static std::vector< FunctionCall>sIncomingFunctionCallBuffer_;67 static std::map<uint32_t, packet::FunctionCalls*> sPeerMap_; 68 static std::vector<std::pair<FunctionCall,std::pair<uint32_t, uint32_t> > > sIncomingFunctionCallBuffer_; 68 69 protected: 69 70 FunctionCallManager(); -
code/trunk/src/libraries/network/GamestateClient.cc
r7401 r7801 39 39 namespace orxonox 40 40 { 41 struct _NetworkExport GameStateItem{ 41 struct _NetworkExport GameStateItem 42 { 42 43 packet::Gamestate *state; 43 44 unsigned int id; 44 45 }; 45 46 46 GamestateClient::GamestateClient() { 47 GamestateClient::GamestateClient() 48 { 47 49 COUT(5) << "this: " << this << std::endl; 48 last _diff_=0;49 last _gamestate_=GAMESTATEID_INITIAL-1;50 lastAckedGamestateID_=GAMESTATEID_INITIAL-1; 51 lastProcessedGamestateID_=GAMESTATEID_INITIAL-1; 50 52 tempGamestate_=NULL; 51 53 } 52 54 53 GamestateClient::~GamestateClient() { 55 GamestateClient::~GamestateClient() 56 { 54 57 std::map<unsigned int, packet::Gamestate *>::iterator it; 55 58 for ( it = this->gamestateMap_.begin(); it != this->gamestateMap_.end(); ++it ) … … 59 62 } 60 63 61 bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){ 64 bool GamestateClient::ackGamestate(unsigned int gamestateID, unsigned int clientID) 65 { 62 66 return true; 63 67 } 64 68 65 bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){ 66 if(tempGamestate_!=NULL){ 69 bool GamestateClient::addGamestate(packet::Gamestate *gs, unsigned int clientID) 70 { 71 if(tempGamestate_!=NULL) 72 { 67 73 //delete the obsolete gamestate 68 74 if(tempGamestate_->getID()>gs->getID()) … … 74 80 } 75 81 76 bool GamestateClient::processGamestates(){ 82 bool GamestateClient::processGamestates() 83 { 77 84 if(tempGamestate_==NULL) 78 85 return false; … … 85 92 NetworkCallbackManager::callCallbacks(); 86 93 87 if (!processed){ 94 if (!processed) 95 { 96 assert(0); 88 97 sendAck(0); 89 98 return false; … … 92 101 tempGamestate_=NULL; 93 102 gamestateMap_[processed->getID()]=processed; 103 lastProcessedGamestateID_ = processed->getID(); 94 104 if(isDiffed) 95 last _diff_ = processed->getBaseID();105 lastAckedGamestateID_ = processed->getBaseID(); 96 106 id = processed->getID(); 97 107 sendAck(id); … … 105 115 * @return iterator pointing to the next object in the list 106 116 */ 107 void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) { 117 void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) 118 { 108 119 ObjectListIterator<Synchronisable> temp=it; 109 120 ++it; … … 111 122 } 112 123 113 packet::Gamestate *GamestateClient::getGamestate(){ 124 packet::Gamestate *GamestateClient::getGamestate() 125 { 114 126 packet::Gamestate *gs = new packet::Gamestate(); 115 if(!gs->collectData(0,0x2)){ 127 if(!gs->collectData(this->getLastProcessedGamestateID(NETWORK_PEER_ID_SERVER), 0x2)) 128 { 116 129 delete gs; 117 130 return 0; … … 120 133 } 121 134 122 void GamestateClient::cleanup(){ 135 void GamestateClient::cleanup() 136 { 123 137 std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin(); 124 while(it!=gamestateMap_.end()){ 125 if(it->first>=last_diff_) 138 while(it!=gamestateMap_.end()) 139 { 140 if(it->first>=lastAckedGamestateID_) 126 141 break; 127 142 // otherwise delete that stuff … … 133 148 } 134 149 135 void GamestateClient::printGamestateMap(){ 150 void GamestateClient::printGamestateMap() 151 { 136 152 std::map<unsigned int, packet::Gamestate*>::iterator it; 137 153 COUT(4) << "gamestates: "; 138 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){ 154 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++) 155 { 139 156 COUT(4) << it->first << ':' << it->second << '|'; 140 157 } … … 143 160 } 144 161 145 bool GamestateClient::sendAck(unsigned int gamestateID){ 162 bool GamestateClient::sendAck(unsigned int gamestateID) 163 { 146 164 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0); 147 if(!ack->send()){ 165 if(!ack->send()) 166 { 148 167 COUT(3) << "could not ack gamestate: " << gamestateID << std::endl; 149 168 return false; 150 169 } 151 else{ 170 else 171 { 152 172 COUT(5) << "acked a gamestate: " << gamestateID << std::endl; 153 173 return true; … … 155 175 } 156 176 157 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 177 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs) 178 { 158 179 if(gs->isCompressed()) 159 180 { -
code/trunk/src/libraries/network/GamestateClient.h
r5781 r7801 57 57 ~GamestateClient(); 58 58 59 bool add(packet::Gamestate *gs, unsigned int clientID); 60 bool ack(unsigned int gamestateID, unsigned int clientID); 59 virtual bool addGamestate(packet::Gamestate *gs, unsigned int clientID); 60 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID); 61 virtual uint32_t getLastProcessedGamestateID(unsigned int clientID=0) { return this->lastProcessedGamestateID_; } 62 virtual uint32_t getCurrentGamestateID(){ return this->lastProcessedGamestateID_; } 61 63 62 64 bool processGamestates(); … … 69 71 bool sendAck(unsigned int gamestateID); 70 72 71 unsigned int last _diff_;72 unsigned int last _gamestate_;73 unsigned int lastAckedGamestateID_; 74 unsigned int lastProcessedGamestateID_; 73 75 std::map<unsigned int, packet::Gamestate *> gamestateMap_; 74 76 packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue -
code/trunk/src/libraries/network/GamestateHandler.cc
r6417 r7801 32 32 namespace orxonox { 33 33 34 GamestateHandler *GamestateHandler::instance_=0;34 // GamestateHandler *GamestateHandler::instance_=0; 35 35 36 36 GamestateHandler::GamestateHandler() 37 37 { 38 assert(instance_==0);39 instance_=this;40 38 } 41 39 … … 43 41 GamestateHandler::~GamestateHandler() 44 42 { 45 instance_=0;46 43 } 47 44 -
code/trunk/src/libraries/network/GamestateHandler.h
r6073 r7801 32 32 #include "NetworkPrereqs.h" 33 33 34 #include <cassert> 35 34 36 namespace orxonox { 35 37 … … 37 39 @author Oliver Scheuss 38 40 */ 39 class _NetworkExport GamestateHandler{ 41 class _NetworkExport GamestateHandler 42 { 40 43 private: 41 virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0;42 virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0;43 44 static GamestateHandler *instance_;45 44 46 45 … … 50 49 51 50 public: 52 static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); } 53 static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); } 51 virtual bool addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0; 52 virtual bool ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0; 53 virtual uint32_t getLastProcessedGamestateID( unsigned int clientID )=0; 54 virtual uint32_t getCurrentGamestateID()=0; 54 55 }; 55 56 -
code/trunk/src/libraries/network/GamestateManager.cc
r7284 r7801 43 43 #include <cassert> 44 44 #include <queue> 45 #include "util/Clock.h"46 45 // #include <boost/thread/mutex.hpp> 47 46 48 #include "util/Debug.h"49 #include "core/ThreadPool.h"50 #include "core/command/Executor.h"51 #include "ClientInformation.h"52 47 #include "packet/Acknowledgement.h" 53 48 #include "packet/Gamestate.h" 54 49 #include "synchronisable/NetworkCallbackManager.h" 55 #include "TrafficControl.h" 50 51 #include "core/ThreadPool.h" 52 #include "core/command/Executor.h" 53 #include "core/GameMode.h" 54 #include "util/Debug.h" 55 #include "util/Clock.h" 56 // #include "TrafficControl.h" 56 57 57 58 namespace orxonox 58 59 { 59 60 GamestateManager::GamestateManager() : 60 reference(0), id_(0)61 { 62 trafficControl_ = new TrafficControl();61 currentGamestate_(0), id_(0) 62 { 63 // trafficControl_ = new TrafficControl(); 63 64 // threadMutex_ = new boost::mutex(); 64 65 // threadPool_ = new ThreadPool(); … … 67 68 GamestateManager::~GamestateManager() 68 69 { 69 if( this-> reference)70 delete this-> reference;std::map<unsigned int, packet::Gamestate*>::iterator it;70 if( this->currentGamestate_ ) 71 delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it; 71 72 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 72 73 delete it->second; 73 std::map<u nsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator it1;74 std::map<u nsigned int, packet::Gamestate*>::iterator it2;75 for( it1 = gamestateMap_.begin(); it1 != gamestateMap_.end(); ++it1)76 { 77 for( it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)78 delete it2->second;79 } 80 this->trafficControl_->destroy();74 std::map<uint32_t, peerInfo>::iterator peerIt; 75 std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt; 76 for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt ) 77 { 78 for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt ) 79 delete gamestateIt->second; 80 } 81 // this->trafficControl_->destroy(); 81 82 // delete this->threadMutex_; 82 83 // delete this->threadPool_; … … 88 89 } 89 90 90 bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){ 91 bool GamestateManager::addGamestate(packet::Gamestate *gs, unsigned int clientID) 92 { 91 93 assert(gs); 92 94 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID); … … 99 101 } 100 102 101 bool GamestateManager::processGamestates(){ 103 bool GamestateManager::processGamestates() 104 { 102 105 if( this->gamestateQueue.empty() ) 103 106 return true; … … 107 110 bool b = processGamestate(it->second); 108 111 assert(b); 112 sendAck( it->second->getID(), it->second->getPeerID() ); 109 113 delete it->second; 110 114 } … … 115 119 return true; 116 120 } 121 122 bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID) 123 { 124 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID); 125 if( !this->sendPacket(ack)) 126 { 127 COUT(3) << "could not ack gamestate: " << gamestateID << std::endl; 128 return false; 129 } 130 else 131 { 132 COUT(5) << "acked a gamestate: " << gamestateID << std::endl; 133 return true; 134 } 135 } 117 136 118 137 119 138 bool GamestateManager::getSnapshot(){ 120 if ( reference != 0 ) 121 delete reference; 122 reference = new packet::Gamestate(); 123 if(!reference->collectData(++id_, 0x1)){ //we have no data to send 124 delete reference; 125 reference=0; 139 if ( currentGamestate_ != 0 ) 140 delete currentGamestate_; 141 currentGamestate_ = new packet::Gamestate(); 142 uint8_t gsMode; 143 if( GameMode::isMaster() ) 144 gsMode = packet::GAMESTATE_MODE_SERVER; 145 else 146 gsMode = packet::GAMESTATE_MODE_CLIENT; 147 uint32_t newID; 148 if( GameMode::isMaster() ) 149 newID = ++id_; 150 else 151 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID; 152 153 if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send 154 delete currentGamestate_; 155 currentGamestate_=0; 126 156 } 127 157 return true; 128 158 } 129 159 130 void GamestateManager::sendGamestates() 131 { 132 ClientInformation *temp = ClientInformation::getBegin(); 133 std::queue<packet::Gamestate*> clientGamestates; 134 while(temp != NULL){ 135 if( !(temp->getSynched()) ){ 160 std::vector<packet::Gamestate*> GamestateManager::getGamestates() 161 { 162 if(!currentGamestate_) 163 return std::vector<packet::Gamestate*>(); 164 std::vector<packet::Gamestate*> peerGamestates; 165 166 std::map<uint32_t, peerInfo>::iterator peerIt; 167 for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt ) 168 { 169 if( !peerIt->second.isSynched ) 170 { 136 171 COUT(5) << "Server: not sending gamestate" << std::endl; 137 temp=temp->next();138 if(!temp)139 break;140 172 continue; 141 173 } 142 COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss()<< std::endl;174 COUT(4) << "client id: " << peerIt->first << std::endl; 143 175 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 144 int cid = temp->getID(); //get client id145 146 unsigned int gID = temp->getGamestateID();147 if(!reference) 148 return;149 150 packet::Gamestate *client=0;151 if(gID != GAMESTATEID_INITIAL){152 assert(gamestateMap_.find(cid)!=gamestateMap_.end());153 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[cid].find(gID);154 if(it!=gamestateMap_[cid].end())155 {156 client = it->second; 157 }158 }159 160 clientGamestates.push(0);161 finishGamestate( cid, clientGamestates.back(), client, reference);176 int peerID = peerIt->first; //get client id 177 178 unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID; 179 180 packet::Gamestate* baseGamestate=0; 181 if(lastAckedGamestateID != GAMESTATEID_INITIAL) 182 { 183 assert(peerMap_.find(peerID)!=peerMap_.end()); 184 std::map<uint32_t, packet::Gamestate*>::iterator it = peerMap_[peerID].gamestates.find(lastAckedGamestateID); 185 assert(it!=peerMap_[peerID].gamestates.end()); 186 baseGamestate = it->second; 187 } 188 189 peerGamestates.push_back(0); // insert an empty gamestate* to change 190 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 191 if( peerGamestates.back()==0 ) 192 // nothing to send to remove pointer from vector 193 peerGamestates.pop_back(); 162 194 //FunctorMember<GamestateManager>* functor = 163 195 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) ); 164 // executor->setDefaultValues( cid, &clientGamestates.back(), client, reference);196 // executor->setDefaultValues( cid, &clientGamestates.back(), client, currentGamestate_ ); 165 197 // (*static_cast<Executor*>(executor))(); 166 198 // this->threadPool_->passFunction( executor, true ); 167 // (*functor)( cid, &(clientGamestates.back()), client, reference ); 168 169 temp = temp->next(); 199 // (*functor)( cid, &(clientGamestates.back()), client, currentGamestate_ ); 170 200 } 171 201 172 202 // threadPool_->synchronise(); 173 203 174 while( !clientGamestates.empty() ) 175 { 176 if(clientGamestates.front()) 177 clientGamestates.front()->send(); 178 clientGamestates.pop(); 179 } 180 } 181 182 183 void GamestateManager::finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 204 return peerGamestates; 205 } 206 207 208 void GamestateManager::finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ) { 184 209 //why are we searching the same client's gamestate id as we searched in 185 210 //Server::sendGameState? … … 194 219 // gs->collectData( id_, 0x1 ); 195 220 // this->threadMutex_->lock(); 196 gamestateMap_[clientID][gamestate->getID()]=gs;221 peerMap_[peerID].gamestates[gamestate->getID()]=gs; 197 222 // this->threadMutex_->unlock(); 198 199 223 Clock clock; 224 clock.capture(); 200 225 201 226 if(base) … … 216 241 217 242 218 bool b = gs->compressData();219 assert(b);220 221 COUT(0) << "difftime: " << clock.getDeltaTime() << endl;243 // bool b = gs->compressData(); 244 // assert(b); 245 clock.capture(); 246 COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl; 222 247 // COUT(5) << "sending gamestate with id " << gs->getID(); 223 248 // if(gamestate->isDiffed()) … … 225 250 // else 226 251 // COUT(5) << endl; 227 gs->set ClientID(clientID);252 gs->setPeerID(peerID); 228 253 destgamestate = gs; 229 254 } 230 255 231 256 232 bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) { 233 ClientInformation *temp = ClientInformation::findClient(clientID); 234 assert(temp); 235 unsigned int curid = temp->getGamestateID(); 257 bool GamestateManager::ackGamestate(unsigned int gamestateID, unsigned int peerID) 258 { 259 // ClientInformation *temp = ClientInformation::findClient(peerID); 260 // assert(temp); 261 std::map<uint32_t, peerInfo>::iterator it = this->peerMap_.find(peerID); 262 assert(it!=this->peerMap_.end()); 263 unsigned int curid = it->second.lastAckedGamestateID; 236 264 237 265 if(gamestateID == ACKID_NACK){ 238 temp->setGamestateID(GAMESTATEID_INITIAL); 266 it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 267 // temp->setGamestateID(GAMESTATEID_INITIAL); 239 268 // now delete all saved gamestates for this client 240 std::map<unsigned int, packet::Gamestate*>::iterator it; 241 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){ 242 delete it->second; 243 244 gamestateMap_[clientID].erase(it++); 245 } 269 std::map<uint32_t, packet::Gamestate*>::iterator it2; 270 for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 271 delete it2->second; 272 } 273 it->second.gamestates.clear(); 246 274 return true; 247 275 } 248 276 249 assert(curid==GAMESTATEID_INITIAL || curid<gamestateID); 250 COUT(5) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 251 std::map<unsigned int, packet::Gamestate*>::iterator it; 252 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){ 253 delete it->second; 254 gamestateMap_[clientID].erase(it++); 255 } 256 temp->setGamestateID(gamestateID); 257 TrafficControl::processAck(clientID, gamestateID); 277 assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); 278 COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 279 std::map<uint32_t, packet::Gamestate*>::iterator it2; 280 for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ) 281 { 282 if( it2->second->getID() < gamestateID ) 283 { 284 delete it2->second; 285 it->second.gamestates.erase(it2++); 286 } 287 else 288 ++it2; 289 } 290 291 // std::map<unsigned int, packet::Gamestate*>::iterator it; 292 // for(it = gamestateMap_[peerID].begin(); it!=gamestateMap_[peerID].end() && it->first<gamestateID; ){ 293 // delete it->second; 294 // gamestateMap_[peerID].erase(it++); 295 // } 296 it->second.lastAckedGamestateID = gamestateID; 297 // temp->setGamestateID(gamestateID); 298 // TrafficControl::processAck(peerID, gamestateID); 258 299 return true; 259 300 } 260 261 void GamestateManager::removeClient(ClientInformation* client){ 262 assert(client); 263 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 264 // first delete all remained gamestates 265 std::map<unsigned int, packet::Gamestate*>::iterator it; 266 for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 267 delete it->second; 268 // now delete the clients gamestatemap 269 gamestateMap_.erase(clientMap); 270 } 271 272 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 301 302 uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID) 303 { 304 assert( this->peerMap_.find(peerID)!=this->peerMap_.end() ); 305 if( this->peerMap_.find(peerID) != this->peerMap_.end() ) 306 return this->peerMap_[peerID].lastProcessedGamestateID; 307 else 308 return GAMESTATEID_INITIAL; 309 } 310 311 312 void GamestateManager::addPeer(uint32_t peerID) 313 { 314 assert(peerMap_.find(peerID)==peerMap_.end()); 315 peerMap_[peerID].peerID = peerID; 316 peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL; 317 peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL; 318 if( GameMode::isMaster() ) 319 peerMap_[peerID].isSynched = false; 320 else 321 peerMap_[peerID].isSynched = true; 322 } 323 324 void GamestateManager::removePeer(uint32_t peerID) 325 { 326 assert(peerMap_.find(peerID)!=peerMap_.end()); 327 std::map<uint32_t, packet::Gamestate*>::iterator peerIt; 328 for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt ) 329 { 330 delete peerIt->second; 331 } 332 peerMap_.erase(peerMap_.find(peerID)); 333 } 334 335 336 // void GamestateManager::removeClient(ClientInformation* client){ 337 // assert(client); 338 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 339 // // first delete all remained gamestates 340 // std::map<unsigned int, packet::Gamestate*>::iterator it; 341 // for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 342 // delete it->second; 343 // // now delete the clients gamestatemap 344 // gamestateMap_.erase(clientMap); 345 // } 346 347 bool GamestateManager::processGamestate(packet::Gamestate *gs) 348 { 273 349 if(gs->isCompressed()) 274 350 { … … 277 353 } 278 354 assert(!gs->isDiffed()); 279 return gs->spreadData(0x1); 355 uint8_t gsMode; 356 if( GameMode::isMaster() ) 357 gsMode = packet::GAMESTATE_MODE_SERVER; 358 else 359 gsMode = packet::GAMESTATE_MODE_CLIENT; 360 if( gs->spreadData(gsMode) ) 361 { 362 this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID(); 363 return true; 364 } 365 else 366 return false; 280 367 } 281 368 -
code/trunk/src/libraries/network/GamestateManager.h
r7163 r7801 46 46 #include "GamestateHandler.h" 47 47 #include "core/CorePrereqs.h" 48 #include "packet/Gamestate.h" 49 #include <boost/concept_check.hpp> 48 50 49 51 namespace orxonox … … 66 68 * @author Oliver Scheuss 67 69 */ 68 class _NetworkExport GamestateManager: public GamestateHandler{ 70 class _NetworkExport GamestateManager: public GamestateHandler 71 { 72 struct peerInfo 73 { 74 uint32_t peerID; 75 uint32_t lastProcessedGamestateID; 76 uint32_t lastAckedGamestateID; 77 bool isSynched; 78 std::map< uint32_t, packet::Gamestate* > gamestates; 79 }; 80 69 81 public: 82 70 83 GamestateManager(); 71 84 ~GamestateManager(); 72 85 73 bool add(packet::Gamestate *gs, unsigned int clientID); 86 virtual bool addGamestate(packet::Gamestate *gs, unsigned int peerID); 87 virtual bool ackGamestate(unsigned int gamestateID, unsigned int peerID); 88 virtual uint32_t getLastProcessedGamestateID( unsigned int peerID ); 89 virtual uint32_t getCurrentGamestateID(){ return currentGamestate_->getID(); } 90 74 91 bool processGamestates(); 92 bool sendAck(unsigned int gamestateID, uint32_t peerID); 75 93 bool update(); 76 void sendGamestates(); 77 // packet::Gamestate *popGameState(unsigned int clientID); 78 void finishGamestate( unsigned int clientID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 94 std::vector<packet::Gamestate*> getGamestates(); 95 void finishGamestate( unsigned int peerID, packet::Gamestate*& destgamestate, packet::Gamestate* base, packet::Gamestate* gamestate ); 79 96 80 97 bool getSnapshot(); 81 98 82 bool ack(unsigned int gamestateID, unsigned int clientID); 83 void removeClient(ClientInformation *client); 99 void addPeer( uint32_t peerID ); 100 void setSynched( uint32_t peerID ) 101 { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; } 102 void removePeer( uint32_t peerID ); 103 // void removeClient(ClientInformation *client); 104 protected: 105 virtual bool sendPacket( packet::Packet* packet ) = 0; 84 106 private: 85 107 bool processGamestate(packet::Gamestate *gs); 86 108 87 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_;109 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 88 110 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 89 packet::Gamestate *reference; 90 TrafficControl *trafficControl_; 111 // std::map<unsigned int, uint32_t> lastProcessedGamestateID_; 112 std::map<uint32_t, peerInfo> peerMap_; 113 packet::Gamestate* currentGamestate_; 114 // TrafficControl *trafficControl_; 91 115 unsigned int id_; 92 116 // boost::mutex* threadMutex_; -
code/trunk/src/libraries/network/Host.cc
r7284 r7801 45 45 // Host* Host::instance_=0; 46 46 uint32_t Host::clientID_s=0; 47 uint32_t Host::shipID_s=-1;47 // uint32_t Host::shipID_s=-1; 48 48 std::vector<Host*> Host::instances_s; 49 49 … … 76 76 * @return success? 77 77 */ 78 bool Host::addPacket(ENetPacket *packet, int clientID)78 void Host::addPacket(ENetPacket *packet, int clientID, uint8_t channelID) 79 79 { 80 bool result = true;81 80 for( std::vector<Host*>::iterator it = instances_s.begin(); it!=instances_s.end(); ++it ) 82 81 { 83 82 if( (*it)->isActive() ) 84 83 { 85 if( !(*it)->queuePacket(packet, clientID) ) 86 result = false; 84 (*it)->queuePacket(packet, clientID, channelID); 87 85 } 88 86 } 89 return result;90 87 } 91 88 -
code/trunk/src/libraries/network/Host.h
r7284 r7801 31 31 32 32 #include "NetworkPrereqs.h" 33 #include "GamestateManager.h" 33 34 #include "core/CorePrereqs.h" 34 35 … … 49 50 * @author Oliver Scheuss 50 51 */ 51 class _NetworkExport Host{ 52 class _NetworkExport Host: public GamestateManager 53 { 52 54 private: 53 55 //TODO add these functions or adequate 54 56 //virtual bool processChat(packet::Chat *message, unsigned int clientID)=0; 55 57 //virtual bool sendChat(packet::Chat *chat)=0; 56 virtual bool queuePacket(ENetPacket *packet, int clientID)=0;58 virtual void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID)=0; 57 59 virtual bool chat(const std::string& message)=0; 58 60 virtual bool broadcast(const std::string& message)=0; … … 71 73 // static Host* getInstance(){ return instance_; } 72 74 static bool running(){ return instances_s.size(); } 73 static bool addPacket(ENetPacket *packet, int clientID=0);75 static void addPacket(ENetPacket* packet, int clientID = NETWORK_PEER_ID_SERVER, uint8_t channelID = 0); 74 76 //static bool chat(std::string& message); 75 77 // static bool receiveChat(packet::Chat *message, unsigned int clientID); 76 78 static unsigned int getPlayerID(){ return clientID_s; } 77 static unsigned int getShipID(){return shipID_s;}78 79 static void setClientID(unsigned int id){ clientID_s = id; } 79 static void setShipID(unsigned int id){ shipID_s = id; }80 80 static bool isServer(); 81 81 static void Chat(const std::string& message); … … 86 86 private: 87 87 static uint32_t clientID_s; 88 static uint32_t shipID_s;89 88 static std::vector<Host*> instances_s; 90 89 bool bIsActive_; -
code/trunk/src/libraries/network/LANDiscoverable.cc
r7459 r7801 45 45 this->host_ = 0; 46 46 this->bActive_ = false; 47 this->setActivity(true);47 // this->setActivity(true); 48 48 } 49 49 -
code/trunk/src/libraries/network/MasterServer.cc
r7786 r7801 280 280 * any input/output bandwidth */ 281 281 this->server = enet_host_create( &this->address, ORX_MSERVER_MAXCONNS, 282 ORX_MSERVER_MAXCHANS, 0, 0 ); 282 ORX_MSERVER_MAXCHANS, 0, 0 ); 283 assert(this->server); 283 284 284 285 /* see if creation worked */ -
code/trunk/src/libraries/network/MasterServer.h
r7786 r7801 30 30 #define _MasterServer_H__ 31 31 32 #include "NetworkPrereqs.h" 33 32 34 /* orxonox includes */ 33 35 #include <enet/enet.h> … … 50 52 { 51 53 /* singleton */ 52 class MasterServer54 class _NetworkExport MasterServer 53 55 { 54 56 public: -
code/trunk/src/libraries/network/MasterServerComm.cc
r7786 r7801 48 48 49 49 /* initialize the event holder */ 50 this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 );50 // this->event = (ENetEvent *)calloc( sizeof(ENetEvent), 1 ); 51 51 52 52 … … 90 90 91 91 /* Wait up to 2 seconds for the connection attempt to succeed. */ 92 if (enet_host_service (this->client, this->event, 2000) > 0 &&93 this->event ->type == ENET_EVENT_TYPE_CONNECT )92 if (enet_host_service (this->client, &this->event, 500) > 0 && 93 this->event.type == ENET_EVENT_TYPE_CONNECT ) 94 94 COUT(3) << "Connection to master server succeeded.\n"; 95 95 else … … 103 103 return 0; 104 104 } 105 106 void MasterServerComm::update() 107 { 108 while( enet_host_service( this->client, &this->event, 1 ) ); 109 } 110 105 111 106 112 int MasterServerComm::disconnect( void ) 107 113 { 114 while( enet_host_service( this->client, &this->event, 1 ) ); 108 115 enet_peer_disconnect( this->peer, 0 ); 109 116 … … 111 118 * and drop any packets received packets. 112 119 */ 113 while (enet_host_service (this->client, this->event, 1000) > 0)120 while (enet_host_service (this->client, &this->event, 1000) > 0) 114 121 { 115 switch (this->event ->type)122 switch (this->event.type) 116 123 { 117 124 case ENET_EVENT_TYPE_RECEIVE: 118 enet_packet_destroy (event ->packet);125 enet_packet_destroy (event.packet); 119 126 break; 120 127 … … 154 161 /* enet_host_service returns 0 if no event occured */ 155 162 /* just newly set below test to >0 from >= 0, to be tested */ 156 if( enet_host_service( this->client, this->event, delayms ) > 0 )163 if( enet_host_service( this->client, &this->event, delayms ) > 0 ) 157 164 { 158 165 /* check what type of event it is and react accordingly */ 159 switch (this->event ->type)166 switch (this->event.type) 160 167 { /* new connection, not supposed to happen. */ 161 168 case ENET_EVENT_TYPE_CONNECT: break; … … 173 180 174 181 /* resolve IP */ 175 enet_address_get_host_ip( &(this->event ->peer->address),182 enet_address_get_host_ip( &(this->event.peer->address), 176 183 addrconv, 49 ); 177 184 178 185 /* DEBUG */ 179 186 COUT(3) << "MasterServer Debug: A packet of length " 180 << this->event ->packet->dataLength181 << " containing " << this->event ->packet->data187 << this->event.packet->dataLength 188 << " containing " << this->event.packet->data 182 189 << " was received from " << addrconv 183 << " on channel " << this->event ->channelID;190 << " on channel " << this->event.channelID; 184 191 /* END DEBUG */ 185 192 186 193 /* call the supplied callback, if any. */ 187 194 if( (*callback) != NULL ) 188 retval = (*callback)( addrconv, (this->event) );195 retval = (*callback)( addrconv, &(this->event) ); 189 196 190 197 /* clean up */ 191 enet_packet_destroy( event ->packet );198 enet_packet_destroy( event.packet ); 192 199 if( addrconv ) 193 200 free( addrconv ); … … 220 227 221 228 /* free the packet */ 222 enet_packet_destroy( packet ); 229 // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees 230 // enet_packet_destroy( packet ); 223 231 224 232 /* all done. */ … … 239 247 /* One could just use enet_host_service() instead. */ 240 248 enet_host_flush( this->client ); 241 enet_packet_destroy( packet ); 249 // PLEASE: never do this, because enet will free the packet once it's delivered. this will cause double frees 250 // enet_packet_destroy( packet ); 242 251 243 252 /* all done. */ -
code/trunk/src/libraries/network/MasterServerComm.h
r7786 r7801 30 30 #define _MasterServerComm_H__ 31 31 32 #include "NetworkPrereqs.h" 33 32 34 #include <cstdlib> 33 35 #include <cstdio> … … 39 41 namespace orxonox 40 42 { 41 class MasterServerComm43 class _NetworkExport MasterServerComm 42 44 { 43 45 public: … … 53 55 */ 54 56 int initialize(); 57 58 void update(); 55 59 56 60 … … 92 96 private: 93 97 /** client handle */ 94 ENetHost *client;98 ENetHost* client; 95 99 96 100 /** event data holder */ 97 ENetEvent *event;101 ENetEvent event; 98 102 99 103 /** address holder */ … … 101 105 102 106 /** peer data holder */ 103 ENetPeer *peer;107 ENetPeer* peer; 104 108 }; 105 109 -
code/trunk/src/libraries/network/NetworkPrereqs.h
r7490 r7801 64 64 namespace orxonox 65 65 { 66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1);67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2);66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2); 68 68 extern const char* LAN_DISCOVERY_MESSAGE; 69 69 extern const char* LAN_DISCOVERY_ACK; 70 static const unsigned int LAN_DISCOVERY_PORT = 55557; 70 static const unsigned int LAN_DISCOVERY_PORT = 55558; 71 static const unsigned int NETWORK_PEER_ID_SERVER = 0; 72 static const unsigned int NETWORK_CHANNEL_DEFAULT = 0; 73 static const unsigned int NETWORK_CHANNEL_UNRELIABLE = 1; 74 static const unsigned int NETWORK_CHANNEL_COUNT = 2; 71 75 } 72 76 … … 83 87 enum Value 84 88 { 85 Reliable = 1,86 Unsequence = 2,87 NoAllocate = 489 Reliable = 1, 90 Unsequenced = 2, 91 NoAllocate = 4 88 92 }; 89 93 } … … 97 101 // from ENet 98 102 struct _ENetPeer; 99 typedef _ENetPeer ENetPeer;103 typedef _ENetPeer ENetPeer; 100 104 struct _ENetPacket; 101 typedef _ENetPacket ENetPacket;105 typedef _ENetPacket ENetPacket; 102 106 struct _ENetEvent; 103 typedef _ENetEvent ENetEvent;107 typedef _ENetEvent ENetEvent; 104 108 struct _ENetHost; 105 typedef _ENetHost ENetHost;109 typedef _ENetHost ENetHost; 106 110 struct _ENetAddress; 107 typedef _ENetAddress ENetAddress; 111 typedef _ENetAddress ENetAddress; 112 typedef uint8_t ENetChannelID; 108 113 109 114 namespace orxonox … … 161 166 } 162 167 168 namespace boost 169 { 170 class mutex; 171 class thread; 172 } 173 163 174 #endif /* _NetworkPrereqs_H__ */ -
code/trunk/src/libraries/network/Server.cc
r7284 r7801 60 60 #include "FunctionCallManager.h" 61 61 #include "GamestateManager.h" 62 #include "WANDiscovery.h" 62 63 63 64 namespace orxonox … … 99 100 } 100 101 102 103 /** helper that connects to the master server */ 104 void Server::helper_ConnectToMasterserver() 105 { 106 // WANDiscovery::getInstance().msc.sendRequest( MSPROTO_GAME_SERVER " " 107 // MSPROTO_REGISTER_SERVER ); 108 } 109 101 110 /** 102 111 * This function opens the server by creating the listener thread … … 107 116 COUT(4) << "opening server" << endl; 108 117 this->openListener(); 118 119 /* make discoverable on LAN */ 109 120 LANDiscoverable::setActivity(true); 121 122 /* make discoverable on WAN */ 123 WANDiscoverable::setActivity(true); 124 /* TODO this needs to be optional, we need a switch from the UI to 125 * enable/disable this 126 */ 127 // helper_ConnectToMasterserver(); 128 129 /* done */ 110 130 return; 111 131 } … … 120 140 this->disconnectClients(); 121 141 this->closeListener(); 142 143 /* tell master server we're closing */ 144 COUT(2) << "disconnecting." << endl; 145 WANDiscoverable::setActivity(false); 146 COUT(2) << "disconnecting done" << endl; 147 122 148 LANDiscoverable::setActivity(false); 123 149 return; … … 130 156 while(temp){ 131 157 chat = new packet::Chat(message, playerID); 132 chat->set ClientID(temp->getID());133 if(!chat->send( ))158 chat->setPeerID(temp->getID()); 159 if(!chat->send( static_cast<Host*>(this) )) 134 160 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 135 161 temp = temp->next(); … … 139 165 } 140 166 167 168 /* handle incoming data */ 169 int rephandler( char *addr, ENetEvent *ev ) 170 { 171 /* reply to pings */ 172 if( !strncmp( (char *)ev->packet->data, MSPROTO_PING_GAMESERVER, 173 MSPROTO_PING_GAMESERVER_LEN ) ) 174 //this->msc.sendRequest( MSPROTO_ACK ); 175 /* NOTE implement this after pollForReply 176 * reimplementation 177 */ 178 return 0; 179 180 /* done handling, return all ok code 0 */ 181 return 0; 182 } 183 184 void Server::helper_HandleMasterServerRequests() 185 { 186 /* poll the master server for replies and see whether something 187 * has to be done or changed. 188 */ 189 //WANDiscovery::getInstance().msc.pollForReply( rhandler, 10 ); 190 } 141 191 142 192 /** … … 149 199 // receive incoming packets 150 200 Connection::processQueue(); 201 151 202 // receive and process incoming discovery packets 152 203 LANDiscoverable::update(); 204 205 // receive and process requests from master server 206 /* todo */ 207 //helper_HandleMasterServerRequests(); 153 208 154 209 if ( ClientInformation::hasClients() ) … … 156 211 // process incoming gamestates 157 212 GamestateManager::processGamestates(); 213 FunctionCallManager::processBufferedFunctionCalls(); 158 214 159 215 // send function calls to clients 160 FunctionCallManager::sendCalls( );216 FunctionCallManager::sendCalls( static_cast<Host*>(this) ); 161 217 162 218 //this steers our network frequency … … 167 223 updateGamestate(); 168 224 } 169 sendPackets(); // flush the enet queue170 } 171 } 172 173 bool Server::queuePacket(ENetPacket *packet, int clientID)174 { 175 return ServerConnection::addPacket(packet, clientID);225 // sendPackets(); // flush the enet queue 226 } 227 } 228 229 void Server::queuePacket(ENetPacket *packet, int clientID, uint8_t channelID) 230 { 231 ServerConnection::addPacket(packet, clientID, channelID); 176 232 } 177 233 … … 209 265 return; 210 266 GamestateManager::update(); 211 COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl;267 // COUT(5) << "Server: one gamestate update complete, goig to sendGameState" << std::endl; 212 268 //std::cout << "updated gamestate, sending it" << std::endl; 213 269 //if(clients->getGamestateID()!=GAMESTATEID_INITIAL) 214 sendGameState ();270 sendGameStates(); 215 271 sendObjectDeletes(); 216 COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl;272 // COUT(5) << "Server: one sendGameState turn complete, repeat in next tick" << std::endl; 217 273 //std::cout << "sent gamestate" << std::endl; 218 274 } 219 275 220 bool Server::processPacket( ENetPacket *packet, ENetPeer *peer ){ 221 packet::Packet *p = packet::Packet::createPacket(packet, peer); 222 return p->process(); 223 } 224 225 /** 226 * sends the gamestate 227 */ 228 bool Server::sendGameState() 229 { 230 // COUT(5) << "Server: starting function sendGameState" << std::endl; 231 // ClientInformation *temp = ClientInformation::getBegin(); 232 // bool added=false; 233 // while(temp != NULL){ 234 // if( !(temp->getSynched()) ){ 235 // COUT(5) << "Server: not sending gamestate" << std::endl; 236 // temp=temp->next(); 237 // if(!temp) 238 // break; 239 // continue; 240 // } 241 // COUT(4) << "client id: " << temp->getID() << " RTT: " << temp->getRTT() << " loss: " << temp->getPacketLoss() << std::endl; 242 // COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 243 // int cid = temp->getID(); //get client id 244 // packet::Gamestate *gs = GamestateManager::popGameState(cid); 245 // if(gs==NULL){ 246 // COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 247 // temp = temp->next(); 248 // continue; 249 // } 250 // //std::cout << "adding gamestate" << std::endl; 251 // gs->setClientID(cid); 252 // if ( !gs->send() ){ 253 // COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 254 // temp->addFailure(); 255 // }else 256 // temp->resetFailures(); 257 // added=true; 258 // temp=temp->next(); 259 // // gs gets automatically deleted by enet callback 260 // } 261 GamestateManager::sendGamestates(); 276 /** 277 * sends the current gamestate to all peers 278 */ 279 bool Server::sendGameStates() 280 { 281 std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates(); 282 std::vector<packet::Gamestate*>::iterator it; 283 for( it = gamestates.begin(); it != gamestates.end(); ++it ) 284 { 285 (*it)->send(static_cast<Host*>(this)); 286 } 262 287 return true; 263 288 } 289 264 290 265 291 bool Server::sendObjectDeletes() … … 286 312 packet::DeleteObjects *cd = new packet::DeleteObjects(*del); 287 313 assert(cd); 288 cd->set ClientID(cid);289 if ( !cd->send( ) )290 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended : " << temp->getFailures()<< std::endl;314 cd->setPeerID(cid); 315 if ( !cd->send( static_cast<Host*>(this) ) ) 316 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl; 291 317 temp=temp->next(); 292 318 // gs gets automatically deleted by enet callback … … 312 338 // inform all the listeners 313 339 ClientConnectionListener::broadcastClientConnected(newid); 340 GamestateManager::addPeer(newid); 314 341 315 342 ++newid; … … 327 354 else 328 355 { 356 GamestateManager::removePeer(client->getID()); 329 357 //ServerConnection::disconnectClient( client ); 330 358 //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now … … 332 360 } 333 361 } 362 363 void Server::processPacket(packet::Packet* packet) 364 { 365 if( packet->isReliable() ) 366 { 367 if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() ) 368 packet->process(static_cast<Host*>(this)); 369 else 370 this->packetQueue_.push_back(packet); 371 } 372 else 373 packet->process(static_cast<Host*>(this)); 374 } 375 334 376 335 377 bool Server::createClient(int clientID) … … 341 383 return false; 342 384 } 343 COUT( 5) << "Con.Man: creating client id: " << temp->getID() << std::endl;385 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 344 386 345 387 // synchronise class ids … … 348 390 // now synchronise functionIDs 349 391 packet::FunctionIDs *fIDs = new packet::FunctionIDs(); 350 fIDs->set ClientID(clientID);351 bool b = fIDs->send( );392 fIDs->setPeerID(clientID); 393 bool b = fIDs->send( static_cast<Host*>(this) ); 352 394 assert(b); 353 395 354 396 temp->setSynched(true); 397 GamestateManager::setSynched(clientID); 398 355 399 COUT(4) << "sending welcome" << std::endl; 356 400 packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID()); 357 w->set ClientID(temp->getID());358 b = w->send( );401 w->setPeerID(temp->getID()); 402 b = w->send( static_cast<Host*>(this) ); 359 403 assert(b); 360 404 packet::Gamestate *g = new packet::Gamestate(); 361 g->setClientID(temp->getID()); 362 b = g->collectData(0,0x1); 405 g->setPeerID(temp->getID()); 406 b = g->collectData(0,packet::GAMESTATE_MODE_SERVER); 407 assert(b); 363 408 if(!b) 364 409 return false; //no data for the client 365 b = g->compressData();366 assert(b);367 b = g->send( );410 // b = g->compressData(); 411 // assert(b); 412 b = g->send( static_cast<Host*>(this) ); 368 413 assert(b); 369 414 return true; … … 373 418 { 374 419 ServerConnection::disconnectClient( client ); 375 GamestateManager::remove Client(client);420 GamestateManager::removePeer(client->getID()); 376 421 // inform all the listeners 377 422 // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now … … 395 440 { 396 441 chat = new packet::Chat(message, clientID); 397 chat->set ClientID(temp->getID());398 if(!chat->send( ))442 chat->setPeerID(temp->getID()); 443 if(!chat->send( static_cast<Host*>(this) )) 399 444 COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl; 400 445 temp = temp->next(); … … 411 456 int failures=0; 412 457 packet::ClassID *classid = new packet::ClassID(); 413 classid->set ClientID(clientID);414 while(!classid->send( ) && failures < 10){458 classid->setPeerID(clientID); 459 while(!classid->send( static_cast<Host*>(this) ) && failures < 10){ 415 460 failures++; 416 461 } -
code/trunk/src/libraries/network/Server.h
r7163 r7801 32 32 #include "NetworkPrereqs.h" 33 33 34 #include <deque> 35 34 36 #include "util/UtilPrereqs.h" 35 37 #include "core/CorePrereqs.h" 36 38 #include "Host.h" 37 #include "GamestateManager.h"39 // #include "GamestateManager.h" 38 40 #include "ServerConnection.h" 39 41 #include "LANDiscoverable.h" 42 #include "WANDiscoverable.h" 43 // #include "MasterServerComm.h" 44 // #include "MasterServerProtocol.h" 45 40 46 41 47 namespace orxonox … … 46 52 * It implements all functions necessary for a Server 47 53 */ 48 class _NetworkExport Server : public Host, public ServerConnection, public GamestateManager, public LANDiscoverable{ 54 class _NetworkExport Server : public Host, public ServerConnection, public LANDiscoverable, public WANDiscoverable 55 { 49 56 public: 50 57 Server(); … … 53 60 ~Server(); 54 61 62 /* helpers */ 63 void helper_ConnectToMasterserver(); 64 void helper_HandleMasterServerRequests(); 65 int replyhandler( char *addr, ENetEvent *ev ); 66 55 67 void open(); 56 68 void close(); 57 69 bool processChat(const std::string& message, unsigned int playerID); 58 bool queuePacket(ENetPacket *packet, int clientID); 70 void queuePacket(ENetPacket *packet, int clientID, uint8_t channelID); 71 virtual bool sendPacket( packet::Packet* packet ){ return packet->send( static_cast<Host*>(this) ); } 59 72 void update(const Clock& time); 60 73 unsigned int getRTT(unsigned int clientID); … … 65 78 private: 66 79 virtual bool isServer_(){return true;} 67 unsigned int shipID(){return 0;}68 80 unsigned int playerID(){return 0;} 69 81 70 82 void addPeer(ENetEvent *event); 71 83 void removePeer(ENetEvent *event); 84 void processPacket(packet::Packet* packet); 72 85 73 86 bool createClient(int clientID); 74 87 void disconnectClient( ClientInformation *client); 75 bool processPacket( ENetPacket *packet, ENetPeer *peer ); 76 bool sendGameState(); 88 bool sendGameStates(); 77 89 bool sendObjectDeletes(); 78 90 virtual bool chat(const std::string& message); … … 82 94 83 95 float timeSinceLastUpdate_; 96 std::deque<packet::Packet*> packetQueue_; 84 97 }; 85 98 -
code/trunk/src/libraries/network/ServerConnection.cc
r7459 r7801 49 49 } 50 50 51 ServerConnection::~ServerConnection(){ 51 ServerConnection::~ServerConnection() 52 { 52 53 if ( this->bListening_ ) 53 54 closeListener(); … … 55 56 } 56 57 57 void ServerConnection::setBindAddress( const std::string& bindAddress ) { 58 void ServerConnection::setBindAddress( const std::string& bindAddress ) 59 { 58 60 if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0) 59 61 COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl; … … 64 66 } 65 67 66 bool ServerConnection::openListener() { 67 this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0); 68 bool ServerConnection::openListener() 69 { 70 // create host 71 this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0); 72 68 73 if ( this->host_ == NULL ) 69 74 { … … 71 76 return false; 72 77 } 78 79 // enable compression 80 this->enableCompression(); 73 81 assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL ); 74 82 if (this->host_->socket4 == ENET_SOCKET_NULL) … … 78 86 else 79 87 COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl; 88 89 // start communication thread 90 Connection::startCommunicationThread(); 80 91 81 92 return true; 82 93 } 83 94 84 bool ServerConnection::closeListener() { 95 bool ServerConnection::closeListener() 96 { 85 97 this->bListening_=false; 86 98 disconnectClients(); 99 Connection::stopCommunicationThread(); 87 100 enet_host_destroy(this->host_); 88 101 return true; 89 102 } 90 103 91 bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) { 104 void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID) 105 { 92 106 if ( clientID == CLIENTID_UNKNOWN ) 93 107 { 94 return addPacketAll(packet);108 broadcastPacket(packet, channelID); 95 109 } 96 110 else … … 99 113 if(!temp){ 100 114 COUT(3) << "C.Man: addPacket findClient failed" << std::endl; 101 return false;102 115 } 103 return Connection::addPacket(packet, temp->getPeer());116 Connection::addPacket(packet, temp->getPeer(), channelID); 104 117 } 105 }106 107 bool ServerConnection::addPacketAll(ENetPacket *packet) {108 // if ( !Connection::getInstance() )109 // return false;110 enet_host_broadcast( Connection::getHost(), 0, packet);111 return true;112 118 } 113 119 … … 117 123 } 118 124 119 void ServerConnection::disconnectClient(int clientID){ 125 void ServerConnection::disconnectClient(int clientID) 126 { 120 127 ClientInformation *client = ClientInformation::findClient(clientID); 121 128 if(client) … … 123 130 } 124 131 125 void ServerConnection::disconnectClients() {126 ENetEvent event;132 void ServerConnection::disconnectClients() 133 { 127 134 ClientInformation *temp = ClientInformation::getBegin(); 128 while(temp!=0){ 135 while(temp!=0) 136 { 129 137 ServerConnection::disconnectClient( temp ); 130 138 temp = temp->next(); 131 }132 temp = ClientInformation::getBegin();133 while( temp!=0 ){134 if( service( &event ) )135 {136 switch (event.type)137 {138 case ENET_EVENT_TYPE_NONE: break;139 case ENET_EVENT_TYPE_CONNECT: break;140 case ENET_EVENT_TYPE_RECEIVE:141 enet_packet_destroy(event.packet);142 break;143 case ENET_EVENT_TYPE_DISCONNECT:144 removePeer( &event );145 temp = ClientInformation::getBegin();146 break;147 }148 }149 139 } 150 140 return; … … 152 142 153 143 154 int ServerConnection::getClientID(ENetPeer* peer) { 144 int ServerConnection::getClientID(ENetPeer* peer) 145 { 155 146 return getClientID(&(peer->address)); 156 147 } 157 148 158 int ServerConnection::getClientID(ENetAddress* address) { 149 int ServerConnection::getClientID(ENetAddress* address) 150 { 159 151 return ClientInformation::findClient(address)->getID(); 160 152 } 161 153 162 ENetPeer *ServerConnection::getClientPeer(int clientID) { 154 ENetPeer *ServerConnection::getClientPeer(int clientID) 155 { 163 156 return ClientInformation::findClient(clientID)->getPeer(); 164 157 } -
code/trunk/src/libraries/network/ServerConnection.h
r7163 r7801 56 56 bool openListener(); 57 57 bool closeListener(); 58 bool addPacket(ENetPacket *packet, unsigned int ID); 59 bool addPacketAll(ENetPacket *packet); 58 void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID); 60 59 virtual void disconnectClient(ClientInformation *client); 61 60 void disconnectClient(int clientID); -
code/trunk/src/libraries/network/WANDiscovery.cc
r7786 r7801 39 39 namespace orxonox 40 40 { 41 ManageScopedSingleton(WANDiscovery, ScopeID:: Root, true);41 ManageScopedSingleton(WANDiscovery, ScopeID::Graphics, true); 42 42 43 43 … … 71 71 * has changed. 72 72 */ 73 SetConfigValue( msaddress, " localhost");73 SetConfigValue( msaddress, "orxonox.net"); 74 74 } 75 75 -
code/trunk/src/libraries/network/packet/Acknowledgement.cc
r6417 r7801 31 31 #include "util/Debug.h" 32 32 #include "network/GamestateHandler.h" 33 #include "network/Host.h" 33 34 34 35 namespace orxonox { … … 39 40 #define _ACKID _PACKETID + sizeof(packet::Type::Value) 40 41 41 Acknowledgement::Acknowledgement( unsigned int id, unsigned int clientID )42 Acknowledgement::Acknowledgement( unsigned int id, unsigned int peerID ) 42 43 : Packet() 43 44 { … … 46 47 *(Type::Value *)(data_ + _PACKETID ) = Type::Acknowledgement; 47 48 *(uint32_t *)(data_ + _ACKID ) = id; 48 clientID_=clientID;49 peerID_=peerID; 49 50 } 50 51 51 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int clientID )52 : Packet(data, clientID)52 Acknowledgement::Acknowledgement( uint8_t *data, unsigned int peerID ) 53 : Packet(data, peerID) 53 54 { 54 55 } … … 62 63 } 63 64 64 bool Acknowledgement::process( ){65 bool Acknowledgement::process(orxonox::Host* host){ 65 66 COUT(5) << "processing ACK with ID: " << getAckID() << endl; 66 bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);67 bool b = host->ackGamestate(getAckID(), peerID_); 67 68 delete this; 68 69 return b; -
code/trunk/src/libraries/network/packet/Acknowledgement.h
r6073 r7801 42 42 { 43 43 public: 44 Acknowledgement( unsigned int id, unsigned int clientID );45 Acknowledgement( uint8_t* data, unsigned int clientID );44 Acknowledgement( unsigned int id, unsigned int peerID ); 45 Acknowledgement( uint8_t* data, unsigned int peerID ); 46 46 ~Acknowledgement(); 47 47 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 unsigned int getAckID(); -
code/trunk/src/libraries/network/packet/Chat.cc
r7163 r7801 80 80 } 81 81 82 bool Chat::process( ){83 bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID));82 bool Chat::process(orxonox::Host* host){ 83 bool b = host->incomingChat(std::string((const char*)data_+_MESSAGE), *(uint32_t *)(data_+_PLAYERID)); 84 84 delete this; 85 85 return b; -
code/trunk/src/libraries/network/packet/Chat.h
r7163 r7801 52 52 53 53 /* process chat message packet and remove it afterwards */ 54 bool process();54 virtual bool process(orxonox::Host* host); 55 55 56 56 /* Get the length of the message (not the full size of the packet) */ -
code/trunk/src/libraries/network/packet/ClassID.cc
r7163 r7801 120 120 121 121 122 bool ClassID::process( ){122 bool ClassID::process(orxonox::Host* host){ 123 123 int nrOfClasses; 124 124 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid -
code/trunk/src/libraries/network/packet/ClassID.h
r6417 r7801 48 48 49 49 uint32_t getSize() const; 50 bool process();50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/trunk/src/libraries/network/packet/DeleteObjects.cc
r6417 r7801 57 57 } 58 58 59 bool DeleteObjects::fetchIDs(){ 59 bool DeleteObjects::fetchIDs() 60 { 60 61 unsigned int number = Synchronisable::getNumberOfDeletedObject(); 61 62 if(number==0) … … 79 80 } 80 81 81 unsigned int DeleteObjects::getSize() const{ 82 unsigned int DeleteObjects::getSize() const 83 { 82 84 assert(data_); 83 85 return _OBJECTIDS + *(uint32_t*)(data_+_QUANTITY)*sizeof(uint32_t); 84 86 } 85 87 86 bool DeleteObjects::process(){ 87 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++){ 88 bool DeleteObjects::process(orxonox::Host* host) 89 { 90 for(unsigned int i=0; i<*(unsigned int *)(data_+_QUANTITY); i++) 91 { 88 92 COUT(4) << "deleting object with id: " << *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) << std::endl; 89 93 Synchronisable::deleteObject( *(uint32_t*)(data_+_OBJECTIDS+i*sizeof(uint32_t)) ); -
code/trunk/src/libraries/network/packet/DeleteObjects.h
r6073 r7801 32 32 #include "Packet.h" 33 33 34 namespace orxonox { 35 namespace packet { 34 namespace orxonox 35 { 36 namespace packet 37 { 36 38 /** 37 39 @author … … 47 49 48 50 inline unsigned int getSize() const; 49 bool process();51 virtual bool process(orxonox::Host* host); 50 52 51 53 private: -
code/trunk/src/libraries/network/packet/FunctionCalls.cc
r7495 r7801 32 32 #include "network/FunctionCall.h" 33 33 #include "network/FunctionCallManager.h" 34 #include "network/GamestateHandler.h" 34 35 35 36 namespace orxonox { … … 40 41 const unsigned int FUNCTIONCALLS_MEM_ALLOCATION = 1000; 41 42 42 FunctionCalls::FunctionCalls() 43 : Packet()43 FunctionCalls::FunctionCalls(): 44 Packet(), minGamestateID_(GAMESTATEID_INITIAL) 44 45 { 45 46 flags_ = flags_ | PACKET_FLAGS_FUNCTIONCALLS; 46 currentSize_ = 2*sizeof(uint32_t); // for packetid and nrOfCalls47 currentSize_ = 3*sizeof(uint32_t); // for packetid, nrOfCalls and minGamestateID_ 47 48 } 48 49 49 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ) 50 : Packet(data, clientID)50 FunctionCalls::FunctionCalls( uint8_t* data, unsigned int clientID ): 51 Packet(data, clientID), minGamestateID_(GAMESTATEID_INITIAL) 51 52 { 52 53 } … … 57 58 58 59 59 bool FunctionCalls::process(){ 60 bool FunctionCalls::process(orxonox::Host* host) 61 { 60 62 assert(isDataENetAllocated()); 61 63 62 64 uint8_t* temp = data_+sizeof(uint32_t); //skip packetid 63 65 uint32_t nrOfCalls = *(uint32_t*)temp; 66 temp += sizeof(uint32_t); 67 this->minGamestateID_ = *(uint32_t*)temp; 64 68 temp += sizeof(uint32_t); 65 69 for( unsigned int i = 0; i<nrOfCalls; i++ ) … … 68 72 fctCall.loadData(temp); 69 73 if( !fctCall.execute() ) 70 FunctionCallManager::bufferIncomingFunctionCall( fctCall ); 74 { 75 FunctionCallManager::bufferIncomingFunctionCall( fctCall, minGamestateID_, this->getPeerID() ); 76 } 71 77 } 72 78 … … 75 81 } 76 82 77 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 83 void FunctionCalls::addCallStatic( uint32_t networkID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 84 { 78 85 assert(!isDataENetAllocated()); 79 86 … … 83 90 } 84 91 85 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5){ 92 void FunctionCalls::addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1, const MultiType* mt2, const MultiType* mt3, const MultiType* mt4, const MultiType* mt5) 93 { 86 94 assert(!isDataENetAllocated()); 87 95 … … 91 99 } 92 100 93 bool FunctionCalls::send( )101 bool FunctionCalls::send(orxonox::Host* host) 94 102 { 103 this->minGamestateID_ = host->getCurrentGamestateID(); 95 104 assert(this->functionCalls_.size()); 96 105 data_=new uint8_t[ currentSize_ ]; 97 106 *(Type::Value *)(data_ + _PACKETID ) = Type::FunctionCalls; // Set the Packet ID 98 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls to 0 99 uint8_t* temp = data_+2*sizeof(uint32_t); 107 *(uint32_t*)(data_+sizeof(uint32_t)) = this->functionCalls_.size(); // set nrOfCalls 108 *(uint32_t*)(data_+2*sizeof(uint32_t)) = this->minGamestateID_; // set minGamestateID_ 109 uint8_t* temp = data_+3*sizeof(uint32_t); 100 110 101 111 while( this->functionCalls_.size() ) … … 107 117 assert( temp==data_+currentSize_ ); 108 118 109 Packet::send( );119 Packet::send(host); 110 120 return true; 111 121 } -
code/trunk/src/libraries/network/packet/FunctionCalls.h
r7490 r7801 54 54 inline unsigned int getSize() const 55 55 { assert(!this->isDataENetAllocated()); return currentSize_; } 56 bool process();56 virtual bool process(orxonox::Host* host); 57 57 58 58 void addCallStatic( uint32_t networkID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 59 59 void addCallMember( uint32_t networkID, uint32_t objectID, const MultiType* mt1=0, const MultiType* mt2=0, const MultiType* mt3=0, const MultiType* mt4=0, const MultiType* mt5=0); 60 virtual bool send( );60 virtual bool send(orxonox::Host* host); 61 61 private: 62 62 std::queue<orxonox::FunctionCall> functionCalls_; 63 63 unsigned int clientID_; 64 uint32_t minGamestateID_; 64 65 uint32_t currentSize_; 65 66 }; -
code/trunk/src/libraries/network/packet/FunctionIDs.cc
r6417 r7801 46 46 47 47 48 FunctionIDs::FunctionIDs( ) : Packet(){ 48 FunctionIDs::FunctionIDs( ) : Packet() 49 { 49 50 unsigned int nrOfFunctions=0; 50 51 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nroffunctions … … 55 56 //calculate total needed size (for all strings and integers) 56 57 ObjectList<NetworkFunctionBase>::iterator it; 57 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it){ 58 for(it = ObjectList<NetworkFunctionBase>::begin(); it; ++it) 59 { 58 60 const std::string& functionname = it->getName(); 59 61 networkID = it->getNetworkID(); … … 76 78 // now save all classids and classnames 77 79 std::pair<uint32_t, std::string> tempPair; 78 while( !tempQueue.empty() ){ 80 while( !tempQueue.empty() ) 81 { 79 82 tempPair = tempQueue.front(); 80 83 tempQueue.pop(); … … 98 101 } 99 102 100 uint32_t FunctionIDs::getSize() const{ 103 uint32_t FunctionIDs::getSize() const 104 { 101 105 assert(this->data_); 102 106 uint8_t *temp = data_+sizeof(uint32_t); // packet identification … … 114 118 115 119 116 bool FunctionIDs::process(){ 120 bool FunctionIDs::process(orxonox::Host* host) 121 { 117 122 int nrOfFunctions; 118 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid … … 127 132 temp += sizeof(uint32_t); 128 133 129 for( int i=0; i<nrOfFunctions; i++){ 134 for( int i=0; i<nrOfFunctions; i++) 135 { 130 136 networkID = *(uint32_t*)temp; 131 137 stringsize = *(uint32_t*)(temp+sizeof(uint32_t)); -
code/trunk/src/libraries/network/packet/FunctionIDs.h
r6417 r7801 47 47 ~FunctionIDs(); 48 48 49 uint32_t getSize() const;50 bool process();49 virtual uint32_t getSize() const; 50 virtual bool process(orxonox::Host* host); 51 51 52 52 private: -
code/trunk/src/libraries/network/packet/Gamestate.cc
r7163 r7801 36 36 #include "network/synchronisable/Synchronisable.h" 37 37 #include "network/GamestateHandler.h" 38 #include "network/Host.h" 38 39 39 40 namespace orxonox { … … 43 44 #define GAMESTATE_START(data) (data + GamestateHeader::getSize()) 44 45 45 #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 46 // #define PACKET_FLAG_GAMESTATE PacketFlag::Reliable 47 #define PACKET_FLAG_GAMESTATE 0 46 48 47 49 inline bool memzero( uint8_t* data, uint32_t datalength) … … 65 67 66 68 Gamestate::Gamestate(): 67 header_( 0)69 header_() 68 70 { 69 71 flags_ = flags_ | PACKET_FLAG_GAMESTATE; … … 72 74 73 75 Gamestate::Gamestate(uint8_t *data, unsigned int clientID): 74 Packet(data, clientID) 76 Packet(data, clientID), header_(data) 75 77 { 76 78 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 77 header_ = new GamestateHeader(data_); 78 } 79 80 81 Gamestate::Gamestate(uint8_t *data)79 } 80 81 82 Gamestate::Gamestate(uint8_t *data): 83 header_(data) 82 84 { 83 85 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 84 86 data_ = data; 85 header_ = new GamestateHeader(data_);86 87 } 87 88 88 89 89 90 Gamestate::Gamestate(const Gamestate& g) : 90 Packet( *(Packet*)&g), nrOfVariables_(0)91 Packet( *(Packet*)&g ), header_(this->data_), nrOfVariables_(0) 91 92 { 92 93 flags_ = flags_ | PACKET_FLAG_GAMESTATE; 93 header_ = new GamestateHeader(data_);94 94 sizes_ = g.sizes_; 95 95 } … … 98 98 Gamestate::~Gamestate() 99 99 { 100 if( header_ )101 delete header_;102 100 } 103 101 … … 105 103 bool Gamestate::collectData(int id, uint8_t mode) 106 104 { 107 assert(this->header_==0); // make sure the header didn't exist before108 105 uint32_t tempsize=0, currentsize=0; 109 106 assert(data_==0); … … 120 117 } 121 118 122 // create the header object 123 assert( header_ == 0 ); 124 header_ = new GamestateHeader(data_); 119 // tell the gamestate header where to store the data 120 header_.setData(this->data_); 125 121 126 122 //start collect data synchronisable by synchronisable … … 142 138 assert(0); // if we don't use multithreading this part shouldn't be neccessary 143 139 // start allocate additional memory 144 COUT(3) << "G .St.Man: need additional memory" << std::endl;140 COUT(3) << "Gamestate: need additional memory" << std::endl; 145 141 ObjectList<Synchronisable>::iterator temp = it; 146 142 uint32_t addsize=tempsize; … … 161 157 162 158 //start write gamestate header 163 header_ ->setDataSize( currentsize );164 header_ ->setID( id );165 header_ ->setBaseID( GAMESTATEID_INITIAL );166 header_ ->setDiffed( false );167 header_ ->setComplete( true );168 header_ ->setCompressed( false );159 header_.setDataSize( currentsize ); 160 header_.setID( id ); 161 header_.setBaseID( GAMESTATEID_INITIAL ); 162 header_.setDiffed( false ); 163 header_.setComplete( true ); 164 header_.setCompressed( false ); 169 165 //stop write gamestate header 170 166 171 COUT(5) << "G .ST.Man: Gamestate size: " << currentsize << std::endl;172 COUT(5) << "G .ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl;167 COUT(5) << "Gamestate: Gamestate size: " << currentsize << std::endl; 168 COUT(5) << "Gamestate: 'estimated' (and corrected) Gamestate size: " << size << std::endl; 173 169 return true; 174 170 } … … 177 173 bool Gamestate::spreadData(uint8_t mode) 178 174 { 179 COUT( 4) << "processing gamestate with id " << header_->getID() << endl;175 COUT(5) << "processing gamestate with id " << header_.getID() << endl; 180 176 assert(data_); 181 assert(!header_ ->isCompressed());177 assert(!header_.isCompressed()); 182 178 uint8_t *mem=data_+GamestateHeader::getSize(); 183 179 Synchronisable *s; 184 180 185 181 // update the data of the objects we received 186 while(mem < data_+GamestateHeader::getSize()+header_ ->getDataSize())182 while(mem < data_+GamestateHeader::getSize()+header_.getDataSize()) 187 183 { 188 184 SynchronisableHeader objectheader(mem); … … 197 193 else 198 194 { 195 // COUT(4) << "not creating object of classid " << objectheader.getClassID() << endl; 199 196 mem += objectheader.getDataSize() + ( objectheader.isDiffed() ? SynchronisableHeaderLight::getSize() : SynchronisableHeader::getSize() ); 200 197 } … … 202 199 else 203 200 { 201 // COUT(4) << "updating object of classid " << objectheader.getClassID() << endl; 204 202 bool b = s->updateData(mem, mode); 205 203 assert(b); 206 204 } 207 205 } 206 assert(mem-data_ == GamestateHeader::getSize()+header_.getDataSize()); 207 208 208 // In debug mode, check first, whether there are no duplicate objectIDs 209 209 #ifndef NDEBUG … … 249 249 { 250 250 assert(data_); 251 if(header_ ->isCompressed())252 return header_ ->getCompSize()+GamestateHeader::getSize();251 if(header_.isCompressed()) 252 return header_.getCompSize()+GamestateHeader::getSize(); 253 253 else 254 254 { 255 return header_ ->getDataSize()+GamestateHeader::getSize();255 return header_.getDataSize()+GamestateHeader::getSize(); 256 256 } 257 257 } … … 271 271 272 272 273 bool Gamestate::process( )274 { 275 return GamestateHandler::addGamestate(this, getClientID());273 bool Gamestate::process(orxonox::Host* host) 274 { 275 return host->addGamestate(this, getPeerID()); 276 276 } 277 277 … … 280 280 { 281 281 assert(data_); 282 assert(!header_ ->isCompressed());283 uLongf buffer = (uLongf)(((header_ ->getDataSize() + 12)*1.01)+1);282 assert(!header_.isCompressed()); 283 uLongf buffer = (uLongf)(((header_.getDataSize() + 12)*1.01)+1); 284 284 if(buffer==0) 285 285 return false; … … 289 289 uint8_t *source = data_ + GamestateHeader::getSize(); 290 290 int retval; 291 retval = compress( dest, &buffer, source, (uLong)(header_ ->getDataSize()) );291 retval = compress( dest, &buffer, source, (uLong)(header_.getDataSize()) ); 292 292 switch ( retval ) 293 293 { … … 299 299 300 300 //copy and modify header 301 GamestateHeader *temp = header_; 302 header_ = new GamestateHeader(ndata, temp); 301 GamestateHeader *temp = new GamestateHeader(data_); 302 header_.setData(ndata); 303 header_ = *temp; 303 304 delete temp; 304 305 //delete old data … … 306 307 //save new data 307 308 data_ = ndata; 308 header_ ->setCompSize( buffer );309 header_ ->setCompressed( true );310 COUT( 0) << "gamestate compress datasize: " << header_->getDataSize() << " compsize: " << header_->getCompSize() << std::endl;309 header_.setCompSize( buffer ); 310 header_.setCompressed( true ); 311 COUT(4) << "gamestate compress datasize: " << header_.getDataSize() << " compsize: " << header_.getCompSize() << std::endl; 311 312 return true; 312 313 } … … 316 317 { 317 318 assert(data_); 318 assert(header_ ->isCompressed());319 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_ ->getID() << ", baseid: " << header_->getBaseID() << ", datasize: " << header_->getDataSize() << ", compsize: " << header_->getCompSize() << std::endl;320 uint32_t datasize = header_ ->getDataSize();321 uint32_t compsize = header_ ->getCompSize();319 assert(header_.isCompressed()); 320 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << header_.getID() << ", baseid: " << header_.getBaseID() << ", datasize: " << header_.getDataSize() << ", compsize: " << header_.getCompSize() << std::endl; 321 uint32_t datasize = header_.getDataSize(); 322 uint32_t compsize = header_.getCompSize(); 322 323 uint32_t bufsize; 323 324 bufsize = datasize; … … 338 339 339 340 //copy over the header 340 GamestateHeader *temp = header_; 341 header_ = new GamestateHeader( data_, header_ ); 341 GamestateHeader* temp = new GamestateHeader( data_ ); 342 header_.setData(ndata); 343 header_ = *temp; 342 344 delete temp; 343 345 … … 357 359 //set new pointers 358 360 data_ = ndata; 359 header_ ->setCompressed( false );360 assert(header_ ->getDataSize()==datasize);361 assert(header_ ->getCompSize()==compsize);361 header_.setCompressed( false ); 362 assert(header_.getDataSize()==datasize); 363 assert(header_.getCompSize()==compsize); 362 364 return true; 363 365 } 364 366 365 367 368 inline void /*Gamestate::*/diffObject( uint8_t*& newDataPtr, uint8_t*& origDataPtr, uint8_t*& baseDataPtr, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 369 { 370 assert( objectHeader.getDataSize() == SynchronisableHeader(baseDataPtr).getDataSize() ); 371 372 uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData 373 // Check whether the whole object stayed the same 374 if( memcmp( origDataPtr+objectOffset, baseDataPtr+objectOffset, objectHeader.getDataSize()) == 0 ) 375 { 376 // COUT(4) << "skip object " << Synchronisable::getSynchronisable(objectHeader.getObjectID())->getIdentifier()->getName() << endl; 377 origDataPtr += objectOffset + objectHeader.getDataSize(); // skip the whole object 378 baseDataPtr += objectOffset + objectHeader.getDataSize(); 379 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 380 } 381 else 382 { 383 // Now start to diff the Object 384 SynchronisableHeaderLight newObjectHeader(newDataPtr); 385 newObjectHeader = objectHeader; // copy over the objectheader 386 VariableID variableID = 0; 387 uint32_t diffedObjectOffset = SynchronisableHeaderLight::getSize(); 388 // iterate through all variables 389 while( objectOffset < objectHeader.getDataSize()+SynchronisableHeader::getSize() ) 390 { 391 // check whether variable changed and write id and copy over variable to the new stream 392 // otherwise skip variable 393 uint32_t varSize = *sizes; 394 assert( varSize == Synchronisable::getSynchronisable(objectHeader.getObjectID())->getVarSize(variableID) ); 395 if ( varSize != 0 ) 396 { 397 if ( memcmp(origDataPtr+objectOffset, baseDataPtr+objectOffset, varSize) != 0 ) 398 { 399 *(VariableID*)(newDataPtr+diffedObjectOffset) = variableID; // copy over the variableID 400 diffedObjectOffset += sizeof(VariableID); 401 memcpy( newDataPtr+diffedObjectOffset, origDataPtr+objectOffset, varSize ); 402 diffedObjectOffset += varSize; 403 objectOffset += varSize; 404 } 405 else 406 { 407 objectOffset += varSize; 408 } 409 } 410 411 ++variableID; 412 ++sizes; 413 } 414 415 // if there are variables from this object with 0 size left in sizes 416 if( Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() != variableID ) 417 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables() - variableID; 418 419 newObjectHeader.setDiffed(true); 420 newObjectHeader.setDataSize(diffedObjectOffset-SynchronisableHeaderLight::getSize()); 421 assert(objectOffset == objectHeader.getDataSize()+SynchronisableHeader::getSize()); 422 assert(newObjectHeader.getDataSize()>0); 423 424 origDataPtr += objectOffset; 425 baseDataPtr += objectOffset; 426 newDataPtr += diffedObjectOffset; 427 } 428 } 429 430 inline void /*Gamestate::*/copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ) 431 { 432 // COUT(4) << "docopy" << endl; 433 // Just copy over the whole Object 434 memcpy( newData, origData, objectHeader.getDataSize()+SynchronisableHeader::getSize() ); 435 SynchronisableHeader(newData).setDiffed(false); 436 437 newData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 438 origData += objectHeader.getDataSize()+SynchronisableHeader::getSize(); 439 // SynchronisableHeader baseHeader( baseData ); 440 // baseData += baseHeader.getDataSize()+SynchronisableHeader::getSize(); 441 // COUT(4) << "copy " << h.getObjectID() << endl; 442 // COUT(4) << "copy " << h.getObjectID() << ":"; 443 sizes += Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); 444 // for( unsigned int i = 0; i < Synchronisable::getSynchronisable(objectHeader.getObjectID())->getNrOfVariables(); ++i ) 445 // { 446 // // COUT(4) << " " << *sizes; 447 // ++sizes; 448 // } 449 // COUT(4) << endl; 450 } 451 452 inline bool findObject(uint8_t*& dataPtr, uint8_t* endPtr, SynchronisableHeader& objectHeader) 453 { 454 // Some assertions to make sure the dataPtr is valid (pointing to a SynchronisableHeader) 455 { 456 SynchronisableHeader htemp2(dataPtr); 457 assert(htemp2.getClassID()<500); 458 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 459 assert(htemp2.isDiffed()==false); 460 } 461 uint32_t objectID = objectHeader.getObjectID(); 462 while ( dataPtr < endPtr ) 463 { 464 SynchronisableHeader htemp(dataPtr); 465 assert( htemp.getDataSize()!=0 ); 466 if ( htemp.getObjectID() == objectID ) 467 { 468 assert( objectHeader.getClassID() == htemp.getClassID() ); 469 assert( objectHeader.getCreatorID() == htemp.getCreatorID() ); 470 return true; 471 } 472 { 473 if( dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize() < endPtr ) 474 { 475 SynchronisableHeader htemp2(dataPtr+htemp.getDataSize()+SynchronisableHeader::getSize()); 476 assert(htemp2.getClassID()<500); 477 assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 478 assert(htemp2.isDiffed()==false); 479 } 480 } 481 dataPtr += htemp.getDataSize()+SynchronisableHeader::getSize(); 482 483 } 484 assert(dataPtr == endPtr); 485 486 return false; 487 } 488 366 489 Gamestate* Gamestate::diffVariables(Gamestate *base) 367 490 { 368 491 assert(this && base); assert(data_ && base->data_); 369 assert(!header_->isCompressed() && !base->header_->isCompressed()); 370 assert(!header_->isDiffed()); 492 assert(!header_.isCompressed() && !base->header_.isCompressed()); 493 assert(!header_.isDiffed()); 494 assert( header_.getDataSize() && base->header_.getDataSize() ); 371 495 372 496 373 497 // *** first do a raw diff of the two gamestates 374 498 375 uint8_t *baseData = GAMESTATE_START(base->data_);376 uint8_t *origData = GAMESTATE_START(this->data_);377 uint 32_t origLength = header_->getDataSize();378 uint 32_t baseLength = base->header_->getDataSize();379 380 assert( origLength && baseLength);381 382 uint8_t *nData = new uint8_t[origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_]; // this is the maximum size needed in the worst case383 uint 8_t *dest = GAMESTATE_START(nData);384 385 uint 32_t baseOffset = 0; //offset in the diffed stream386 uint32_t origOffset = 0; //offset in the new stream with removed 0's 387 std::vector<uint32_t>::iterator sizes = this->sizes_.begin();388 389 while( orig Offset < origLength)499 uint8_t *baseDataPtr = GAMESTATE_START(base->data_); 500 uint8_t *origDataPtr = GAMESTATE_START(this->data_); 501 uint8_t *origDataEnd = origDataPtr + header_.getDataSize(); 502 uint8_t *baseDataEnd = baseDataPtr + base->header_.getDataSize(); 503 // uint32_t origLength = header_.getDataSize(); 504 // uint32_t baseLength = base->header_.getDataSize(); 505 506 // Allocate new space for diffed gamestate 507 uint32_t newDataSize = header_.getDataSize() + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_; 508 uint8_t *newData = new uint8_t[newDataSize]; // this is the maximum size needed in the worst case 509 uint8_t *destDataPtr = GAMESTATE_START(newData); 510 511 std::vector<uint32_t>::iterator sizesIt = this->sizes_.begin(); 512 513 while( origDataPtr < origDataEnd ) 390 514 { 391 515 //iterate through all objects 392 516 393 SynchronisableHeader h(origData+origOffset);517 SynchronisableHeader origHeader(origDataPtr); 394 518 395 519 // Find (if possible) the current object in the datastream of the old gamestate 396 520 // Start at the current offset position 397 if(baseOffset >= baseLength) 398 baseOffset = 0; 399 uint8_t* temp = baseData + baseOffset; 400 uint32_t objectID = h.getObjectID(); 401 assert(temp < baseData+baseLength); 402 assert(dest < nData + origLength + GamestateHeader::getSize() + sizeof(uint32_t)*this->nrOfVariables_); 403 assert(sizes != this->sizes_.end()); 404 while ( temp < baseData+baseLength ) 405 { 406 SynchronisableHeader htemp(temp); 407 assert( htemp.getDataSize()!=0 ); 408 if ( htemp.getObjectID() == objectID ) 409 { 410 assert( h.getClassID() == htemp.getClassID() ); 411 goto DODIFF; 412 } 413 // { 414 // SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize()); 415 // if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength ) 416 // { 417 // assert(htemp2.getClassID()<500); 418 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 419 // assert(htemp2.isDiffed()==false); 420 // } 421 // } 422 temp += htemp.getDataSize()+SynchronisableHeader::getSize(); 521 if(baseDataPtr == baseDataEnd) 522 baseDataPtr = GAMESTATE_START(base->data_); 523 uint8_t* oldBaseDataPtr = baseDataPtr; 524 525 assert(baseDataPtr < baseDataEnd); 526 assert(destDataPtr < newData + newDataSize); 527 assert(sizesIt != this->sizes_.end()); 528 529 assert(Synchronisable::getSynchronisable(origHeader.getObjectID())); 530 assert(ClassByID(origHeader.getClassID())); 531 assert(origHeader.getDataSize() < 500); 532 533 bool diffedObject = false; 534 if( findObject(baseDataPtr, baseDataEnd, origHeader) ) 535 { 536 SynchronisableHeader baseHeader(baseDataPtr); 537 assert(Synchronisable::getSynchronisable(baseHeader.getObjectID())); 538 assert(ClassByID(baseHeader.getClassID())); 539 assert(baseHeader.getDataSize() < 500); 540 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 541 { 542 // COUT(4) << "diffing object in order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 543 diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 544 diffedObject = true; 545 } 546 else 547 { 548 // COUT(4) << "copy object because of different data sizes (1): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 549 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 550 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 551 } 423 552 424 553 } 425 // If not found start looking at the beginning 426 assert( temp==baseData+baseLength ); 427 temp = baseData; 428 // { 429 // SynchronisableHeader htemp2(temp); 430 // if( temp < baseData+baseLength ) 431 // { 432 // assert(htemp2.getClassID()<500); 433 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 434 // assert(htemp2.isDiffed()==false); 435 // } 436 // } 437 while ( temp < baseData+baseOffset ) 438 { 439 SynchronisableHeader htemp(temp); 440 if ( htemp.getObjectID() == objectID ) 441 { 442 assert( h.getClassID() == htemp.getClassID() ); 443 goto DODIFF; 444 } 445 // { 446 // SynchronisableHeader htemp2(temp+htemp.getDataSize()+SynchronisableHeader::getSize()); 447 // if( temp+htemp.getDataSize()+SynchronisableHeader::getSize() < baseData+baseLength ) 448 // { 449 // assert(htemp2.getClassID()<500); 450 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 451 // assert(htemp2.isDiffed()==false); 452 // } 453 // } 454 temp += htemp.getDataSize()+SynchronisableHeader::getSize(); 455 } 456 // Object is new, thus never transmitted -> just copy over 457 goto DOCOPY; 458 459 460 DODIFF: 461 { 462 // COUT(4) << "dodiff" << endl; 463 // if(baseOffset==0) 464 // { 465 // assert(origOffset==0); 466 // } 467 uint32_t objectOffset = SynchronisableHeader::getSize(); // offset inside the object in the origData and baseData 468 // Check whether the whole object stayed the same 469 if( memcmp( origData+origOffset+objectOffset, temp+objectOffset, h.getDataSize()) == 0 ) 470 { 471 // COUT(4) << "skip object" << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl; 472 origOffset += objectOffset+ h.getDataSize(); // skip the whole object 473 baseOffset = temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData; 474 sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); 554 else 555 { 556 assert( baseDataPtr == baseDataEnd ); 557 baseDataPtr = GAMESTATE_START(base->data_); 558 if( findObject(baseDataPtr, oldBaseDataPtr, origHeader) ) 559 { 560 SynchronisableHeader baseHeader(baseDataPtr); 561 assert(Synchronisable::getSynchronisable(baseHeader.getObjectID())); 562 assert(ClassByID(baseHeader.getClassID())); 563 assert(baseHeader.getDataSize() < 500); 564 if( SynchronisableHeader(baseDataPtr).getDataSize()==origHeader.getDataSize() ) 565 { 566 // COUT(4) << "diffing object out of order: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 567 diffObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 568 diffedObject = true; 569 } 570 else 571 { 572 // COUT(4) << "copy object because of different data sizes (2): " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 573 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 574 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 575 } 475 576 } 476 577 else 477 578 { 478 // if( Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() == "Bot" ) 479 // COUT(0) << "blub" << endl; 480 // COUT(4) << "object diff: " << Synchronisable::getSynchronisable(h.getObjectID())->getIdentifier()->getName() << endl; 481 // COUT(4) << "diff " << h.getObjectID() << ":"; 482 // Now start to diff the Object 483 SynchronisableHeaderLight h2(dest); 484 h2 = h; // copy over the objectheader 485 VariableID variableID = 0; 486 uint32_t newObjectOffset = SynchronisableHeaderLight::getSize(); 487 // iterate through all variables 488 while( objectOffset < h.getDataSize()+SynchronisableHeader::getSize() ) 489 { 490 // check whether variable changed and write id and copy over variable to the new stream 491 // otherwise skip variable 492 assert(sizes != this->sizes_.end()); 493 uint32_t varSize = *sizes; 494 assert( varSize == Synchronisable::getSynchronisable(h.getObjectID())->getVarSize(variableID) ); 495 if ( varSize != 0 ) 496 { 497 if ( memcmp(origData+origOffset+objectOffset, temp+objectOffset, varSize) != 0 ) 498 { 499 // COUT(4) << "copy variable" << endl; 500 *(VariableID*)(dest+newObjectOffset) = variableID; // copy over the variableID 501 newObjectOffset += sizeof(VariableID); 502 memcpy( dest+newObjectOffset, origData+origOffset+objectOffset, varSize ); 503 newObjectOffset += varSize; 504 objectOffset += varSize; 505 } 506 else 507 { 508 // COUT(4) << "skip variable" << endl; 509 objectOffset += varSize; 510 } 511 } 512 // else 513 // COUT(4) << "varsize 0" << endl; 514 515 ++variableID; 516 ++sizes; 517 } 518 519 if( Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() != variableID ) 520 sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables() - variableID; 521 // COUT(4) << endl; 522 h2.setDiffed(true); 523 h2.setDataSize(newObjectOffset-SynchronisableHeaderLight::getSize()); 524 assert(objectOffset == h.getDataSize()+SynchronisableHeader::getSize()); 525 origOffset += objectOffset; 526 // baseOffset += temp + h.getDataSize()+SynchronisableHeader::getSize() - baseData; 527 //baseOffset += objectOffset; 528 // SynchronisableHeader htemp(temp); 529 // baseOffset += SynchronisableHeader::getSize() + htemp.getDataSize(); 530 // { 531 // SynchronisableHeader htemp2( baseData+(temp-baseData+objectOffset) ); 532 // if( baseData+(temp-baseData+objectOffset) < baseData+baseLength ) 533 // { 534 // assert(htemp2.getClassID()<500); 535 // assert(htemp2.getDataSize()!=0 && htemp2.getDataSize()<1000); 536 // assert(htemp2.isDiffed()==false); 537 // } 538 // } 539 baseOffset = temp-baseData + objectOffset; 540 dest += newObjectOffset; 541 } 542 543 continue; 544 } 545 546 DOCOPY: 547 { 548 // COUT(4) << "docopy" << endl; 549 // Just copy over the whole Object 550 memcpy( dest, origData+origOffset, h.getDataSize()+SynchronisableHeader::getSize() ); 551 dest += h.getDataSize()+SynchronisableHeader::getSize(); 552 origOffset += h.getDataSize()+SynchronisableHeader::getSize(); 553 assert( Synchronisable::getSynchronisable(h.getObjectID()) ); 554 // COUT(4) << "copy " << h.getObjectID() << endl; 555 // COUT(4) << "copy " << h.getObjectID() << ":"; 556 //sizes += Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); 557 for( unsigned int i = 0; i < Synchronisable::getSynchronisable(h.getObjectID())->getNrOfVariables(); ++i ) 558 { 559 // COUT(4) << " " << *sizes; 560 ++sizes; 561 } 562 // COUT(4) << endl; 563 assert(sizes != this->sizes_.end() || origOffset>=origLength); 564 continue; 565 } 566 } 567 568 569 Gamestate *g = new Gamestate(nData, getClientID()); 570 assert(g->header_); 571 *(g->header_) = *header_; 572 g->header_->setBaseID( base->getID() ); 573 g->header_->setDataSize(dest - nData - GamestateHeader::getSize()); 579 // COUT(4) << "copy object: " << Synchronisable::getSynchronisable(origHeader.getObjectID())->getIdentifier()->getName() << endl; 580 assert(baseDataPtr == oldBaseDataPtr); 581 copyObject(destDataPtr, origDataPtr, baseDataPtr, origHeader, sizesIt); 582 assert(sizesIt != this->sizes_.end() || origDataPtr==origDataEnd); 583 } 584 } 585 } 586 assert(sizesIt==this->sizes_.end()); 587 588 589 Gamestate *g = new Gamestate(newData, getPeerID()); 590 (g->header_) = header_; 591 g->header_.setBaseID( base->getID() ); 592 g->header_.setDataSize(destDataPtr - newData - GamestateHeader::getSize()); 574 593 g->flags_=flags_; 575 594 g->packetDirection_ = packetDirection_; … … 579 598 580 599 581 Gamestate* Gamestate::diffData(Gamestate *base)600 /*Gamestate* Gamestate::diffData(Gamestate *base) 582 601 { 583 602 assert(this && base); assert(data_ && base->data_); 584 assert(!header_ ->isCompressed() && !base->header_->isCompressed());585 assert(!header_ ->isDiffed());603 assert(!header_.isCompressed() && !base->header_.isCompressed()); 604 assert(!header_.isDiffed()); 586 605 587 606 uint8_t *basep = GAMESTATE_START(base->data_); 588 607 uint8_t *gs = GAMESTATE_START(this->data_); 589 uint32_t dest_length = header_ ->getDataSize();608 uint32_t dest_length = header_.getDataSize(); 590 609 591 610 if(dest_length==0) … … 595 614 uint8_t *dest = GAMESTATE_START(ndata); 596 615 597 rawDiff( dest, gs, basep, header_ ->getDataSize(), base->header_->getDataSize() );616 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() ); 598 617 #ifndef NDEBUG 599 618 uint8_t *dest2 = new uint8_t[dest_length]; 600 rawDiff( dest2, dest, basep, header_ ->getDataSize(), base->header_->getDataSize() );619 rawDiff( dest2, dest, basep, header_.getDataSize(), base->header_.getDataSize() ); 601 620 assert( memcmp( dest2, gs, dest_length) == 0 ); 602 621 delete dest2; … … 606 625 assert(g->header_); 607 626 *(g->header_) = *header_; 608 g->header_ ->setDiffed( true );609 g->header_ ->setBaseID( base->getID() );627 g->header_.setDiffed( true ); 628 g->header_.setBaseID( base->getID() ); 610 629 g->flags_=flags_; 611 630 g->packetDirection_ = packetDirection_; … … 619 638 { 620 639 assert(this && base); assert(data_ && base->data_); 621 assert(!header_ ->isCompressed() && !base->header_->isCompressed());622 assert(header_ ->isDiffed());640 assert(!header_.isCompressed() && !base->header_.isCompressed()); 641 assert(header_.isDiffed()); 623 642 624 643 uint8_t *basep = GAMESTATE_START(base->data_); 625 644 uint8_t *gs = GAMESTATE_START(this->data_); 626 uint32_t dest_length = header_ ->getDataSize();645 uint32_t dest_length = header_.getDataSize(); 627 646 628 647 if(dest_length==0) … … 632 651 uint8_t *dest = ndata + GamestateHeader::getSize(); 633 652 634 rawDiff( dest, gs, basep, header_ ->getDataSize(), base->header_->getDataSize() );653 rawDiff( dest, gs, basep, header_.getDataSize(), base->header_.getDataSize() ); 635 654 636 655 Gamestate *g = new Gamestate(ndata, getClientID()); 637 656 assert(g->header_); 638 657 *(g->header_) = *header_; 639 g->header_ ->setDiffed( false );658 g->header_.setDiffed( false ); 640 659 g->flags_=flags_; 641 660 g->packetDirection_ = packetDirection_; … … 670 689 } 671 690 assert(j==datalength); 672 } 673 674 675 Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){691 }*/ 692 693 694 /*Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){ 676 695 assert(data_); 677 696 std::list<obj>::iterator it; 678 697 679 698 // allocate memory for new data 680 uint8_t *gdata = new uint8_t[header_ ->getDataSize()+GamestateHeader::getSize()];699 uint8_t *gdata = new uint8_t[header_.getDataSize()+GamestateHeader::getSize()]; 681 700 // create a gamestate out of it 682 701 Gamestate *gs = new Gamestate(gdata); … … 694 713 695 714 //call TrafficControl 696 TrafficControl::getInstance()->processObjectList( clientID, header_ ->getID(), dataVector_ );715 TrafficControl::getInstance()->processObjectList( clientID, header_.getID(), dataVector_ ); 697 716 698 717 //copy in the zeros … … 725 744 #ifndef NDEBUG 726 745 uint32_t origsize = destsize; 727 while ( origsize < header_ ->getDataSize() )746 while ( origsize < header_.getDataSize() ) 728 747 { 729 748 SynchronisableHeader oldobjectheader(origdata); … … 732 751 origsize += objectsize; 733 752 } 734 assert(origsize==header_ ->getDataSize());753 assert(origsize==header_.getDataSize()); 735 754 assert(destsize!=0); 736 755 #endif 737 gs->header_ ->setDataSize( destsize );756 gs->header_.setDataSize( destsize ); 738 757 return gs; 739 } 740 741 742 uint32_t Gamestate::calcGamestateSize( int32_t id, uint8_t mode)758 }*/ 759 760 761 uint32_t Gamestate::calcGamestateSize(uint32_t id, uint8_t mode) 743 762 { 744 763 uint32_t size = 0; -
code/trunk/src/libraries/network/packet/Gamestate.h
r7163 r7801 42 42 #include "Packet.h" 43 43 44 namespace orxonox { 44 namespace orxonox 45 { 45 46 46 namespace packet { 47 namespace packet 48 { 49 50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1; 51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2; 47 52 48 class _NetworkExport GamestateHeader{ 53 class _NetworkExport GamestateHeader 54 { 49 55 public: 50 GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 51 GamestateHeader(uint8_t *data, GamestateHeader* h) 52 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); } 56 GamestateHeader(){ data_=0; } 57 GamestateHeader(uint8_t* data) 58 { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h) 60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/ 61 void setData(uint8_t* data) 62 { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 53 63 static inline uint32_t getSize() 54 { return 21; }64 { return 21; } 55 65 56 inline int32_t getID() const57 { assert(data_); return *(int32_t*)(data_+4); }58 inline void setID( int32_t id)59 { assert(data_); *(int32_t*)(data_+4) = id; }66 inline uint32_t getID() const 67 { assert(data_); return *(uint32_t*)(data_+4); } 68 inline void setID(uint32_t id) 69 { assert(data_); *(uint32_t*)(data_+4) = id; } 60 70 61 inline int32_t getBaseID() const62 { assert(data_); return *(int32_t*)(data_+8); }63 inline void setBaseID( int32_t id)64 { assert(data_); *(int32_t*)(data_+8) = id; }71 inline uint32_t getBaseID() const 72 { assert(data_); return *(uint32_t*)(data_+8); } 73 inline void setBaseID(uint32_t id) 74 { assert(data_); *(uint32_t*)(data_+8) = id; } 65 75 66 76 inline uint32_t getDataSize() const 67 { assert(data_); return *(uint32_t*)(data_+12); }77 { assert(data_); return *(uint32_t*)(data_+12); } 68 78 inline void setDataSize(uint32_t size) 69 { assert(data_); *(uint32_t*)(data_+12) = size; }79 { assert(data_); *(uint32_t*)(data_+12) = size; } 70 80 71 81 inline uint32_t getCompSize() const … … 75 85 76 86 inline bool isDiffed() const 77 { assert(data_); return *(int8_t*)(data_+20) & 0x1; }87 { assert(data_); return *(int8_t*)(data_+20) & 0x1; } 78 88 inline void setDiffed(bool b) 79 { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }89 { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } 80 90 81 91 inline bool isComplete() const 82 { assert(data_); return *(int8_t*)(data_+20) & 0x2; }92 { assert(data_); return *(int8_t*)(data_+20) & 0x2; } 83 93 inline void setComplete(bool b) 84 { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }94 { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } 85 95 86 96 inline bool isCompressed() const 87 { assert(data_); return *(int8_t*)(data_+20) & 0x4; }97 { assert(data_); return *(int8_t*)(data_+20) & 0x4; } 88 98 inline void setCompressed(bool b) 89 { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }99 { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } 90 100 91 101 inline void operator=(GamestateHeader& h) 92 { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }102 { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); } 93 103 private: 94 uint8_t *data_;104 uint8_t* data_; 95 105 96 106 }; … … 99 109 @author Oliver Scheuss 100 110 */ 101 class _NetworkExport Gamestate: public Packet{ 111 class _NetworkExport Gamestate: public Packet 112 { 102 113 public: 103 114 Gamestate(); … … 110 121 bool collectData(int id, uint8_t mode=0x0); 111 122 bool spreadData( uint8_t mode=0x0); 112 inline int32_t getID() const { return header_->getID(); }113 inline bool isDiffed() const { return header_ ->isDiffed(); }114 inline bool isCompressed() const { return header_ ->isCompressed(); }115 inline int32_t getBaseID() const { return header_ ->getBaseID(); }116 inline uint32_t getDataSize() const { return header_ ->getDataSize(); }123 inline uint32_t getID() const { return header_.getID(); } 124 inline bool isDiffed() const { return header_.isDiffed(); } 125 inline bool isCompressed() const { return header_.isCompressed(); } 126 inline int32_t getBaseID() const { return header_.getBaseID(); } 127 inline uint32_t getDataSize() const { return header_.getDataSize(); } 117 128 Gamestate* diffVariables(Gamestate *base); 118 Gamestate* diffData(Gamestate *base);119 Gamestate *undiff(Gamestate *base);120 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);129 // Gamestate* diffData(Gamestate *base); 130 // Gamestate *undiff(Gamestate *base); 131 // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 121 132 bool compressData(); 122 133 bool decompressData(); … … 125 136 // Packet functions 126 137 private: 127 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);128 inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );138 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 129 140 virtual uint32_t getSize() const; 130 virtual inline bool process(); 131 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 141 virtual bool process(orxonox::Host* host); 142 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 132 145 133 146 std::list<obj> dataVector_; 134 GamestateHeader *header_;147 GamestateHeader header_; 135 148 std::vector<uint32_t> sizes_; 136 149 uint32_t nrOfVariables_; -
code/trunk/src/libraries/network/packet/Packet.cc
r7163 r7801 35 35 #include <enet/enet.h> 36 36 #include <boost/static_assert.hpp> 37 #include <boost/thread/mutex.hpp> 37 38 38 39 #include "util/Debug.h" … … 53 54 54 55 // Make sure we assume the right values 55 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE));56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequence ) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED));57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE));56 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Reliable) == static_cast<int>(ENET_PACKET_FLAG_RELIABLE)); 57 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::Unsequenced) == static_cast<int>(ENET_PACKET_FLAG_UNSEQUENCED)); 58 BOOST_STATIC_ASSERT(static_cast<int>(PacketFlag::NoAllocate) == static_cast<int>(ENET_PACKET_FLAG_NO_ALLOCATE)); 58 59 59 60 #define PACKET_FLAG_DEFAULT PacketFlag::NoAllocate … … 61 62 62 63 std::map<size_t, Packet *> Packet::packetMap_; 64 boost::mutex Packet::packetMapMutex_; 63 65 64 66 Packet::Packet() … … 66 68 flags_ = PACKET_FLAG_DEFAULT; 67 69 packetDirection_ = Direction::Outgoing; 68 clientID_=0;70 peerID_=0; 69 71 data_=0; 70 72 enetPacket_=0; … … 72 74 } 73 75 74 Packet::Packet(uint8_t *data, unsigned int clientID)76 Packet::Packet(uint8_t *data, unsigned int peerID) 75 77 { 76 78 flags_ = PACKET_FLAG_DEFAULT; 77 79 packetDirection_ = Direction::Incoming; 78 clientID_=clientID;80 peerID_=peerID; 79 81 data_=data; 80 82 enetPacket_=0; … … 87 89 flags_=p.flags_; 88 90 packetDirection_ = p.packetDirection_; 89 clientID_ = p.clientID_;91 peerID_ = p.peerID_; 90 92 if(p.data_){ 91 93 data_ = new uint8_t[p.getSize()]; … … 123 125 } 124 126 125 bool Packet::send( ){127 bool Packet::send(orxonox::Host* host){ 126 128 if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){ 127 129 assert(0); … … 142 144 // Assures we don't create a packet and destroy it right after in another thread 143 145 // without having a reference in the packetMap_ 146 Packet::packetMapMutex_.lock(); 144 147 packetMap_[reinterpret_cast<size_t>(enetPacket_)] = this; 148 Packet::packetMapMutex_.unlock(); 145 149 } 146 150 } … … 164 168 // ENetPacket *temp = enetPacket_; 165 169 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 166 if(!Host::addPacket( enetPacket_, clientID_)) 167 enet_packet_destroy(this->enetPacket_); // if we could not add the packet to the enet queue delete it manually 170 if( this->flags_ & PacketFlag::Reliable ) 171 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_DEFAULT); 172 else 173 host->addPacket( enetPacket_, peerID_, NETWORK_CHANNEL_UNRELIABLE); 168 174 return true; 169 175 } … … 172 178 uint8_t *data = packet->data; 173 179 assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer()); 174 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 180 unsigned int peerID = ClientInformation::findClient(&peer->address)->getID(); 181 // HACK 182 if( peerID==static_cast<unsigned int>(-2)) 183 peerID = NETWORK_PEER_ID_SERVER; 175 184 Packet *p = 0; 176 COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;185 // COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl; 177 186 switch( *(Type::Value *)(data + _PACKETID) ) 178 187 { 179 188 case Type::Acknowledgement: 180 COUT(5) << "ack" << std::endl;181 p = new Acknowledgement( data, clientID );189 // COUT(5) << "ack" << std::endl; 190 p = new Acknowledgement( data, peerID ); 182 191 break; 183 192 case Type::Chat: 184 COUT(5) << "chat" << std::endl;185 p = new Chat( data, clientID );193 // COUT(5) << "chat" << std::endl; 194 p = new Chat( data, peerID ); 186 195 break; 187 196 case Type::ClassID: 188 COUT(5) << "classid" << std::endl;189 p = new ClassID( data, clientID );197 // COUT(5) << "classid" << std::endl; 198 p = new ClassID( data, peerID ); 190 199 break; 191 200 case Type::Gamestate: 192 COUT(5) << "gamestate" << std::endl; 193 // TODO: remove brackets 194 p = new Gamestate( data, clientID ); 201 // COUT(5) << "gamestate" << std::endl; 202 p = new Gamestate( data, peerID ); 195 203 break; 196 204 case Type::Welcome: 197 COUT(5) << "welcome" << std::endl;198 p = new Welcome( data, clientID );205 // COUT(5) << "welcome" << std::endl; 206 p = new Welcome( data, peerID ); 199 207 break; 200 208 case Type::DeleteObjects: 201 COUT(5) << "deleteobjects" << std::endl;202 p = new DeleteObjects( data, clientID );209 // COUT(5) << "deleteobjects" << std::endl; 210 p = new DeleteObjects( data, peerID ); 203 211 break; 204 212 case Type::FunctionCalls: 205 COUT(5) << "functionCalls" << std::endl;206 p = new FunctionCalls( data, clientID );213 // COUT(5) << "functionCalls" << std::endl; 214 p = new FunctionCalls( data, peerID ); 207 215 break; 208 216 case Type::FunctionIDs: 209 COUT(5) << "functionIDs" << std::endl;210 p = new FunctionIDs( data, clientID );217 // COUT(5) << "functionIDs" << std::endl; 218 p = new FunctionIDs( data, peerID ); 211 219 break; 212 220 default: 213 assert(0); //TODO: repair this221 assert(0); 214 222 break; 215 223 } … … 229 237 void Packet::deletePacket(ENetPacket *enetPacket){ 230 238 // Get our Packet from a global map with all Packets created in the send() method of Packet. 239 Packet::packetMapMutex_.lock(); 231 240 std::map<size_t, Packet*>::iterator it = packetMap_.find(reinterpret_cast<size_t>(enetPacket)); 232 241 assert(it != packetMap_.end()); … … 235 244 delete it->second; 236 245 packetMap_.erase(it); 237 COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl; 246 Packet::packetMapMutex_.unlock(); 247 // COUT(6) << "PacketMap size: " << packetMap_.size() << std::endl; 238 248 } 239 249 -
code/trunk/src/libraries/network/packet/Packet.h
r7490 r7801 68 68 virtual unsigned char *getData(){ return data_; }; 69 69 virtual unsigned int getSize() const =0; 70 virtual bool process( )=0;70 virtual bool process(orxonox::Host* host)=0; 71 71 inline uint32_t getFlags() 72 72 { return flags_; } 73 inline int getClientID() 74 { return clientID_; } 75 inline void setClientID( int id ) 76 { clientID_ = id; } 73 inline int getPeerID() 74 { return peerID_; } 75 inline void setPeerID( int id ) 76 { peerID_ = id; } 77 inline bool isReliable() 78 { return this->flags_ & PacketFlag::Reliable; } 79 inline uint32_t getRequiredGamestateID() 80 { return this->requiredGamestateID_; } 77 81 78 virtual bool send( );82 virtual bool send(orxonox::Host* host); 79 83 protected: 80 84 Packet(); 81 Packet(uint8_t *data, unsigned int clientID);85 Packet(uint8_t *data, unsigned int peerID); 82 86 // Packet(ENetPacket *packet, ENetPeer *peer); 83 87 inline bool isDataENetAllocated() const … … 85 89 86 90 uint32_t flags_; 87 unsigned int clientID_; 91 unsigned int peerID_; 92 uint32_t requiredGamestateID_; 88 93 Direction::Value packetDirection_; 89 94 /** Pointer to the data. Be careful when deleting it because it might … … 96 101 private: 97 102 static std::map<size_t, Packet *> packetMap_; 103 static boost::mutex packetMapMutex_; 98 104 ENetPacket *enetPacket_; 99 105 }; -
code/trunk/src/libraries/network/packet/ServerInformation.cc
r7461 r7801 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 58 58 char* ack = new char[strlen(LAN_DISCOVERY_ACK)+1]; 59 59 loadAndIncrease((char*&)ack, temp); 60 assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0); 60 61 /* Fabian, what is this used for? it crashes the masterserver, hence commenting it */ 62 // written by Oli: this is just to make sure that loadAndIncrease really writes the whole ACK string into char* ack 63 // assert(strcmp(ack, (const char*)LAN_DISCOVERY_ACK)==0); 64 61 65 // Save Server Name 62 66 loadAndIncrease(this->serverName_, temp); -
code/trunk/src/libraries/network/packet/ServerInformation.h
r7459 r7801 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Oliver Scheuss 24 24 * Co-authors: 25 25 * ... … … 50 50 std::string getServerName() { return this->serverName_; } 51 51 void setServerName(std::string name) { this->serverName_ = name; } 52 void setServerIP( std::string IP ) { this->serverIP_ = IP; } 52 53 uint32_t getServerRTT() { return this->serverRTT_; } 53 54 -
code/trunk/src/libraries/network/packet/Welcome.cc
r5781 r7801 73 73 } 74 74 75 bool Welcome::process( ){75 bool Welcome::process(orxonox::Host* host){ 76 76 uint32_t clientID; 77 77 clientID = *(uint32_t *)(data_ + _CLIENTID ); 78 78 assert(*(uint32_t *)(data_ + _ENDIANTEST ) == 0xFEDC4321); 79 Host::setClientID(clientID);79 host->setClientID(clientID); 80 80 COUT(3) << "Welcome set clientId: " << clientID << endl; 81 81 Synchronisable::setClient(true); -
code/trunk/src/libraries/network/packet/Welcome.h
r6073 r7801 47 47 uint8_t *getData(); 48 48 inline unsigned int getSize() const; 49 bool process();49 virtual bool process(orxonox::Host* host); 50 50 51 51 private: -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r7401 r7801 123 123 { 124 124 SynchronisableHeader header(mem); 125 assert( !header.isDiffed() ); 125 if( header.isDiffed() ) 126 { 127 mem += header.getDataSize() + header.getSize(); 128 return 0; 129 } 130 // assert( !header.isDiffed() ); 126 131 127 132 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; … … 217 222 * length of varx: size saved int syncvarlist 218 223 * @param mem pointer to allocated memory with enough size 219 * @param sizes FIXME - add doc!224 * @param sizes vector containing sizes of all objects in gamestate (to be appended) 220 225 * @param id gamestateid of the gamestate to be saved (important for priorities) 221 226 * @param mode defines the direction in which the data will be send/received 222 227 * 0x1: server->client 223 * 0x2: client->server (not recommended)228 * 0x2: client->server 224 229 * 0x3: bidirectional 225 230 * @return true: if !doSync or if everything was successfully saved … … 265 270 //tempsize += (*i)->getSize( mode ); 266 271 } 272 assert(tempsize!=0); // if this happens an empty object (with no variables) would be transmitted 267 273 // COUT(4) << endl; 268 274 … … 316 322 mem += SynchronisableHeader::getSize(); 317 323 std::vector<SynchronisableVariableBase *>::iterator i; 318 for(i=syncList_.begin(); i!=syncList_.end(); i++)324 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 319 325 { 320 326 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r7163 r7801 65 65 }; 66 66 } 67 68 typedef uint8_t VariableID;69 70 /**71 * @brief: stores information about a Synchronisable72 *73 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)74 * in an emulated bitset.75 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream76 * Bit 32 is a bool and defines whether the variables are stored in diff mode77 * Byte 5 to 8: objectID_78 * Byte 9 to 12: classID_79 * Byte 13 to 16: creatorID_80 */81 class _NetworkExport SynchronisableHeader{82 friend class SynchronisableHeaderLight;83 private:84 uint8_t* data_;85 public:86 SynchronisableHeader(uint8_t* data)87 { data_ = data; }88 inline static uint32_t getSize()89 { return 14; }90 inline uint16_t getDataSize() const91 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits92 inline void setDataSize(uint16_t size)93 { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }94 inline bool isDiffed() const95 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }96 inline void setDiffed( bool b)97 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }98 inline uint32_t getObjectID() const99 { return *(uint32_t*)(data_+2); }100 inline void setObjectID(uint32_t objectID_)101 { *(uint32_t*)(data_+2) = objectID_; }102 inline uint32_t getClassID() const103 { return *(uint32_t*)(data_+6); }104 inline void setClassID(uint32_t classID_)105 { *(uint32_t*)(data_+6) = classID_; }106 inline uint32_t getCreatorID() const107 { return *(uint32_t*)(data_+10); }108 inline void setCreatorID(uint32_t creatorID_)109 { *(uint32_t*)(data_+10) = creatorID_; }110 inline void operator=(SynchronisableHeader& h)111 { memcpy(data_, h.data_, getSize()); }112 };113 67 114 68 /** … … 121 75 * Byte 5 to 8: objectID_ 122 76 */ 123 class _NetworkExport SynchronisableHeaderLight{ 124 private: 77 class _NetworkExport SynchronisableHeaderLight 78 { 79 protected: 125 80 uint8_t* data_; 126 81 public: … … 141 96 inline void setObjectID(uint32_t objectID_) 142 97 { *(uint32_t*)(data_+2) = objectID_; } 98 inline void operator=(SynchronisableHeaderLight& h) 99 { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); } 100 }; 101 102 typedef uint8_t VariableID; 103 104 /** 105 * @brief: stores information about a Synchronisable 106 * 107 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 108 * in an emulated bitset. 109 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 110 * Bit 32 is a bool and defines whether the variables are stored in diff mode 111 * Byte 5 to 8: objectID_ 112 * Byte 9 to 12: classID_ 113 * Byte 13 to 16: creatorID_ 114 */ 115 class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight 116 { 117 public: 118 SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data) 119 {} 120 inline static uint32_t getSize() 121 { return SynchronisableHeaderLight::getSize()+8; } 122 inline uint32_t getClassID() const 123 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); } 124 inline void setClassID(uint32_t classID_) 125 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; } 126 inline uint32_t getCreatorID() const 127 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); } 128 inline void setCreatorID(uint32_t creatorID_) 129 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; } 143 130 inline void operator=(SynchronisableHeader& h) 144 131 { memcpy(data_, h.data_, getSize()); } 145 132 }; 133 134 // inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2) 135 // { 136 // memcpy(h1.data_, h2.data_, h1.getSize()); 137 // } 146 138 147 139 /** -
code/trunk/src/libraries/util/SignalHandler.cc
r7457 r7801 51 51 #include <X11/Xutil.h> 52 52 #include <X11/keysym.h> 53 #include <sys/prctl.h> 53 54 54 55 namespace orxonox … … 137 138 COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl; 138 139 139 int sigPipe[2]; 140 if ( pipe(sigPipe) == -1 ) 141 { 142 perror("pipe failed!\n"); 143 exit(EXIT_FAILURE); 144 } 145 146 int sigPid = fork(); 147 148 if ( sigPid == -1 ) 149 { 150 perror("fork failed!\n"); 151 exit(EXIT_FAILURE); 152 } 153 154 // gdb will be attached to this process 155 if ( sigPid == 0 ) 156 { 157 getInstance().dontCatch(); 158 // wait for message from parent when it has attached gdb 159 int someData; 160 161 read( sigPipe[0], &someData, sizeof(someData) ); 162 163 if ( someData != 0x12345678 ) 164 { 165 COUT(0) << "something went wrong :(" << std::endl; 166 } 167 168 return; 169 } 170 140 141 // First start GDB which will be attached to this process later on 142 171 143 int gdbIn[2]; 172 144 int gdbOut[2]; 173 145 int gdbErr[2]; 174 146 175 147 if ( pipe(gdbIn) == -1 || pipe(gdbOut) == -1 || pipe(gdbErr) == -1 ) 176 148 { 177 149 perror("pipe failed!\n"); 178 kill( sigPid, SIGTERM );179 waitpid( sigPid, NULL, 0 );180 150 exit(EXIT_FAILURE); 181 151 } 182 152 183 153 int gdbPid = fork(); 184 154 // this process will run gdb 185 155 186 156 if ( gdbPid == -1 ) 187 157 { 188 158 perror("fork failed\n"); 189 kill( sigPid, SIGTERM );190 waitpid( sigPid, NULL, 0 );191 159 exit(EXIT_FAILURE); 192 160 } 193 161 194 162 if ( gdbPid == 0 ) 195 163 { 196 164 // start gdb 197 165 198 166 close(gdbIn[1]); 199 167 close(gdbOut[0]); 200 168 close(gdbErr[0]); 201 169 202 170 dup2( gdbIn[0], STDIN_FILENO ); 203 171 dup2( gdbOut[1], STDOUT_FILENO ); 204 172 dup2( gdbErr[1], STDERR_FILENO ); 205 173 206 174 execlp( "sh", "sh", "-c", "gdb", static_cast<void*>(NULL)); 175 } 176 177 178 // Now start a fork of this process on which GDB will be attached on 179 180 int sigPipe[2]; 181 if ( pipe(sigPipe) == -1 ) 182 { 183 perror("pipe failed!\n"); 184 kill( gdbPid, SIGTERM ); 185 waitpid( gdbPid, NULL, 0 ); 186 exit(EXIT_FAILURE); 187 } 188 189 int sigPid = fork(); 190 191 if ( sigPid == -1 ) 192 { 193 perror("fork failed!\n"); 194 kill( gdbPid, SIGTERM ); 195 waitpid( gdbPid, NULL, 0 ); 196 exit(EXIT_FAILURE); 197 } 198 199 // gdb will be attached to this process 200 if ( sigPid == 0 ) 201 { 202 getInstance().dontCatch(); 203 204 // make sure gdb is allowed to attach to our PID even if there are some system restrictions 205 #ifdef PR_SET_PTRACER 206 if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 ) 207 COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl; 208 #endif 209 210 // wait for message from parent when it has attached gdb 211 int someData; 212 213 if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) ) 214 COUT(0) << "something went wrong :(" << std::endl; 215 216 if ( someData != 0x12345678 ) 217 { 218 COUT(0) << "something went wrong :(" << std::endl; 219 } 220 221 return; 207 222 } 208 223 -
code/trunk/src/modules/objects/ForceField.cc
r7677 r7801 60 60 this->setLength(2000); 61 61 this->mode_ = forceFieldMode::tube; 62 63 this->registerVariables(); 62 64 } 63 65 … … 83 85 XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode); 84 86 } 87 88 void ForceField::registerVariables() 89 { 90 registerVariable(this->velocity_, VariableDirection::ToClient); 91 registerVariable(this->radius_, VariableDirection::ToClient); 92 registerVariable(this->halfLength_, VariableDirection::ToClient); 93 registerVariable(this->mode_, VariableDirection::ToClient); 94 } 95 85 96 86 97 /** -
code/trunk/src/modules/objects/ForceField.h
r7678 r7801 88 88 89 89 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML. 90 void registerVariables(); //!< Registers the variables that should get synchronised over the network 90 91 virtual void tick(float dt); //!< A method that is called every tick. 92 91 93 92 94 /** … … 141 143 float radius_; //!< The radius of the ForceField. 142 144 float halfLength_; //!< Half of the length of the ForceField. 143 forceFieldMode::Valuemode_; //!< The mode of the ForceField.145 int mode_; //!< The mode of the ForceField. 144 146 }; 145 147 } -
code/trunk/src/modules/overlays/hud/HUDBar.cc
r7401 r7801 85 85 this->bar_->setMaterialName(materialname); 86 86 87 this->value_ = 1.0f; // initi elize with 1.0f to trigger a change when calling setValue(0.0f) on the line below87 this->value_ = 1.0f; // initialize with 1.0f to trigger a change when calling setValue(0.0f) on the line below 88 88 this->setAutoColour(true); 89 89 this->setValue(0.0f); // <-- … … 161 161 if (this->right2Left_) 162 162 { 163 // backward case w163 // backward case 164 164 this->bar_->setPosition(0.06f + 0.88f * (1 - this->value_), 0.0f); 165 165 this->bar_->setDimensions(0.88f * this->value_, 1.0f); -
code/trunk/src/modules/overlays/hud/HUDNavigation.cc
r7401 r7801 24 24 * Co-authors: 25 25 * Reto Grieder 26 * Oliver Scheuss 26 27 * 27 28 */ … … 410 411 } 411 412 } 412 } 413 414 } -
code/trunk/src/modules/pickup/PickupManager.cc
r7549 r7801 61 61 /*static*/ const std::string PickupManager::guiName_s = "PickupInventory"; 62 62 63 // Register static ne wtork functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly.63 // Register static network functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly. 64 64 registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork); 65 65 registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork); -
code/trunk/src/modules/pickup/PickupSpawner.cc
r7549 r7801 120 120 PickupSpawner::~PickupSpawner() 121 121 { 122 if(this-> selfDestruct_ && this->pickup_ != NULL)122 if(this->isInitialized() && this->selfDestruct_ && this->pickup_ != NULL) 123 123 this->pickup_->destroy(); 124 124 } … … 317 317 assert(pickup); 318 318 assert(target); 319 assert(pickup->pickup(target)); 319 bool pickedUp = pickup->pickup(target); 320 assert(pickedUp); 321 pickedUp = false; // To avoid compiler warning. 320 322 321 323 this->decrementSpawnsRemaining(); -
code/trunk/src/modules/weapons/MuzzleFlash.cc
r7284 r7801 42 42 this->setScale(0.1f); 43 43 44 this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this))); 44 if( GameMode::isMaster() ) 45 this->delayTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&MuzzleFlash::destroy, this))); 45 46 } 46 47 } -
code/trunk/src/orxonox/LevelManager.cc
r7724 r7801 152 152 Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw"); 153 153 // Iterate over all *.oxw level files. 154 COUT(3) << "Loading LevelInfos..." << std::endl; 154 155 for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it) 155 156 { -
code/trunk/src/orxonox/Main.cc
r7431 r7801 54 54 SetCommandLineSwitch(dedicatedClient).information("Start in dedicated client mode"); 55 55 56 /* ADD masterserver command */ 57 SetCommandLineSwitch(masterserver).information("Start in masterserver mode"); 58 56 59 SetCommandLineArgument(generateDoc, "") 57 60 .information("Generates a Doxygen file from things like SetConsoleCommand"); … … 67 70 if (CommandLineParser::getValue("generateDoc").getString().empty()) 68 71 { 72 /* TODO make this clear */ 69 73 game->setStateHierarchy( 70 74 "root" … … 73 77 " standalone,server,client" 74 78 " level" 75 " server,client "79 " server,client,masterserver" 76 80 " level" 77 81 ); … … 90 94 else if (CommandLineParser::getValue("dedicatedClient").getBool()) 91 95 Game::getInstance().requestStates("client, level"); 96 /* ADD masterserver command */ 97 else if (CommandLineParser::getValue("masterserver").getBool()) 98 Game::getInstance().requestStates("masterserver"); 92 99 else 93 100 { -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r7401 r7801 69 69 70 70 this->target_ = 0; 71 this->formationFlight_ = true;71 this->formationFlight_ = false; 72 72 this->passive_ = false; 73 73 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; -
code/trunk/src/orxonox/controllers/NewHumanController.cc
r7284 r7801 375 375 { 376 376 // CCOUT(0) << "testing object as target" << endl; 377 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" /*&& itr->distance > 500*/)377 if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200) 378 378 { 379 379 // Try to cast the user pointer -
code/trunk/src/orxonox/gamestates/CMakeLists.txt
r6105 r7801 6 6 GSRoot.cc 7 7 GSServer.cc 8 GSMasterServer.cc 8 9 GSStandalone.cc 9 10 ) -
code/trunk/src/orxonox/gamestates/GSServer.cc
r7401 r7801 34 34 #include "core/GameMode.h" 35 35 #include "network/Server.h" 36 #include "network/Connection.h" 36 37 37 38 namespace orxonox … … 39 40 DeclareGameState(GSServer, "server", false, false); 40 41 41 SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");42 SetCommandLineArgument(port, NETWORK_PORT).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)"); 42 43 43 44 GSServer::GSServer(const GameStateInfo& info) -
code/trunk/src/orxonox/gametypes/Gametype.cc
r7284 r7801 79 79 else 80 80 this->scoreboard_ = 0; 81 82 /* HACK HACK HACK */ 83 this->dedicatedAddBots_ = createConsoleCommand( "dedicatedAddBots", createExecutor( createFunctor(&Gametype::addBots, this) ) ); 84 this->dedicatedKillBots_ = createConsoleCommand( "dedicatedKillBots", createExecutor( createFunctor(&Gametype::killBots, this) ) ); 85 /* HACK HACK HACK */ 81 86 } 82 87 … … 86 91 { 87 92 this->gtinfo_->destroy(); 93 if( this->dedicatedAddBots_ ) 94 delete this->dedicatedAddBots_; 95 if( this->dedicatedKillBots_ ) 96 delete this->dedicatedKillBots_; 88 97 } 89 98 } -
code/trunk/src/orxonox/gametypes/Gametype.h
r7284 r7801 184 184 // Config Values 185 185 std::string scoreboardTemplate_; 186 187 /* HACK HACK HACK */ 188 ConsoleCommand* dedicatedAddBots_; 189 ConsoleCommand* dedicatedKillBots_; 190 /* HACK HACK HACK */ 186 191 }; 187 192 } -
code/trunk/src/orxonox/infos/Bot.cc
r7673 r7801 86 86 "Alec Trevelyan", 87 87 "Elliot Carver", 88 "Elektra King" 88 "Elektra King", 89 89 "Viktor Zokas", 90 90 "Gustav Graves", -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r7547 r7801 57 57 this->engine_ = 0; 58 58 59 this->boostPower_ = 10.0f; 60 this->initialBoostPower_ = 10.0f; 61 this->boostRate_ = 5.0; 62 this->boostPowerRate_ = 1.0; 63 this->boostCooldownDuration_ = 5.0; 64 this->bBoostCooldown_ = false; 59 65 60 66 this->bInvertYAxis_ = false; … … 86 92 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); 87 93 XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode); 94 XMLPortParamVariable(SpaceShip, "boostPower", initialBoostPower_, xmlelement, mode); 95 XMLPortParamVariable(SpaceShip, "boostPowerRate", boostPowerRate_, xmlelement, mode); 96 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 97 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 88 98 } 89 99 … … 134 144 this->localAngularAcceleration_.setValue(0, 0, 0); 135 145 } 136 } 146 147 if(!this->bBoostCooldown_ && this->boostPower_ < this->initialBoostPower_) 148 { 149 this->boostPower_ += this->boostPowerRate_*dt; 150 } 151 if(this->bBoost_) 152 { 153 this->boostPower_ -=this->boostRate_*dt; 154 if(this->boostPower_ <= 0.0f) 155 { 156 this->bBoost_ = false; 157 this->bBoostCooldown_ = true; 158 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 159 } 160 } 161 } 162 } 163 164 void SpaceShip::boostCooledDown(void) 165 { 166 this->bBoostCooldown_ = false; 137 167 } 138 168 … … 175 205 Pawn::rotateRoll(value); 176 206 } 207 208 // TODO: something seems to call this function every tick, could probably handled a little more efficiently! 209 void SpaceShip::setBoost(bool bBoost) 210 { 211 if(bBoost == this->bBoost_) 212 return; 213 214 if(bBoost) 215 this->boost(); 216 else 217 { 218 this->bBoost_ = false; 219 } 220 } 177 221 178 222 void SpaceShip::fire() … … 182 226 void SpaceShip::boost() 183 227 { 184 this->bBoost_ = true; 228 if(!this->bBoostCooldown_) 229 this->bBoost_ = true; 185 230 } 186 231 -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r7547 r7801 34 34 #include <string> 35 35 #include <LinearMath/btVector3.h> 36 #include "tools/Timer.h" 36 37 #include "util/Math.h" 37 38 #include "Pawn.h" … … 69 70 { return this->steering_; } 70 71 71 inline void setBoost(bool bBoost) 72 { this->bBoost_ = bBoost; } 72 void setBoost(bool bBoost); 73 73 inline bool getBoost() const 74 74 { return this->bBoost_; } … … 89 89 90 90 bool bBoost_; 91 bool bBoostCooldown_; 91 92 bool bPermanentBoost_; 93 float boostPower_; 94 float initialBoostPower_; 95 float boostRate_; 96 float boostPowerRate_; 97 float boostCooldownDuration_; 92 98 Vector3 steering_; 93 99 float primaryThrust_; … … 102 108 103 109 void loadEngineTemplate(); 110 111 void boostCooledDown(void); 104 112 105 113 std::string enginetemplate_; 106 114 Engine* engine_; 115 Timer timer_; 107 116 }; 108 117 }
Note: See TracChangeset
for help on using the changeset viewer.