Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_monitor.cc @ 9281

Last change on this file since 9281 was 9281, checked in by patrick, 18 years ago

segfault fix

File size: 2.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#include "glgui.h"
16#include "shell_command.h"
17
18#include "network_stream.h"
19#include "debug.h"
20
21#include "network_monitor.h"
22#include "network_node.h"
23#include "network_stream.h"
24
25
26SHELL_COMMAND(showGUI, NetworkMonitor, showGUI);
27SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI);
28// SHELL_COMMAND(output, MappedWater, saveParams);
29
30
31
32/**
33 * starts a network monitor
34 */
35NetworkMonitor::NetworkMonitor(NetworkStream* networkStream)
36  : Synchronizeable()
37{
38  this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor");
39
40  this->networkStream = networkStream;
41  this->playerNumber = 0;
42  this->setSynchronized(false);
43}
44
45
46/**
47 * deconstructor
48 */
49NetworkMonitor::~NetworkMonitor()
50{}
51
52
53/**
54 * add the network node
55 * @param node to add
56 */
57void NetworkMonitor::addNetworkNode(NetworkNode* node)
58{
59  this->nodeList.push_back(node);
60}
61
62
63/**
64 * add the network node
65 * @param node to add
66 */
67void NetworkMonitor::removeNetworkNode(NetworkNode* node)
68{
69  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
70  for(; it != this->nodeList.end(); it++)
71  {
72    if( *it == node)
73    {
74      this->nodeList.erase(it);
75      this->playerNumber--;
76      return;
77    }
78  }
79}
80
81
82/**
83 * this displays the network monitor gui
84 */
85void NetworkMonitor::showGUI()
86{
87  if (this->box == NULL)
88  {
89    this->box = new OrxGui::GLGuiBox(OrxGui::Vertical);
90    {
91      OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
92      {
93        OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText();
94        waterColorText->setText("NetworkMonitor");
95        waterColorBox->pack(waterColorText);
96      }
97      this->box->pack(waterColorBox);
98    }
99
100    this->box->showAll();
101    this->box->setAbsCoor2D(300, 40);
102    OrxGui::GLGuiHandler::getInstance()->activate();
103//     OrxGui::GLGuiHandler::getInstance()->activateCursor();
104  }
105}
106
107
108/**
109 * hides the network monitor gui again
110 */
111void NetworkMonitor::hideGUI()
112{
113  if( this->box == NULL)
114    return;
115
116  OrxGui::GLGuiHandler::getInstance()->deactivate();
117//   OrxGui::GLGuiHandler::getInstance()->deactivateCursor();
118
119  delete this->box;
120  this->box = NULL;
121}
122
123
124/**
125 * processes the network monitor data
126 */
127void NetworkMonitor::process()
128{
129  this->playerNumber = 0;
130  std::list<NetworkNode*>::iterator it = this->nodeList.begin();
131  for(; it != this->nodeList.end(); it++)
132  {
133    this->playerNumber += (*it)->getPlayerNumber();
134  }
135}
136
Note: See TracBrowser for help on using the repository browser.