Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_game_manager.cc @ 6190

Last change on this file since 6190 was 6190, checked in by rennerc, 18 years ago

synchronizeable: added sender parameter to writeBytes
network_stream: creates now a network_game_manager
network_game_manager: implemented some functions

File size: 5.2 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: Benjamin Wuest
13   co-programmer: ...
14*/
15
16
17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
19*/
20#define DEBUG_MODULE_NETWORK
21
22#include "factory.h"
23#include "network_stream.h"
24
25/* include your own header */
26#include "network_game_manager.h"
27
28
29/* using namespace std is default, this needs to be here */
30using namespace std;
31
32/*!
33 * Standard constructor
34 */
35NetworkGameManager::NetworkGameManager()
36{
37  /* set the class id for the base object */
38  this->setClassID(CL_ENTITY_MANAGER, "EntityManager");
39}
40
41/*!
42 * Standard destructor
43 */
44NetworkGameManager::~NetworkGameManager()
45{
46  for ( int i = 0; i<inBuffer.size(); i++)
47  {
48    if ( inBuffer[i].buffer )
49      delete inBuffer[i].buffer;
50    if ( outBuffer[i].buffer )
51      delete outBuffer[i].buffer;
52  }
53}
54
55
56void NetworkGameManager::writeBytes(const byte* data, int length, int sender)
57{
58}
59
60int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever)
61{
62}
63
64void NetworkGameManager::writeDebug() const
65{
66}
67
68void NetworkGameManager::readDebug() const
69{
70}
71
72
73/*!
74 * Checks whether this is connected to a server or a client
75 * and afterwards creates the needed entity if possible
76 * @param classID: The ID of the class of which an entity should be created
77 */
78void NetworkGameManager::createEntity(int classID)
79{
80}
81
82/*!
83 * Checks whether this is connected to a server or a client
84 * and afterwards removes the specified entity
85 * @param uniqueID: The ID of the entity object which should be removed
86 */
87void NetworkGameManager::removeEntity(int uniqueID)
88{
89}
90
91
92
93/*!
94 * Creates the needed entity on the server if possible
95 * @param classID: The ID of the class of which an entity should be created
96 */
97void NetworkGameManager::requestCreateEntity(int classID)
98{
99}
100
101/*!
102 * Removes the specified entity on the server
103 * @param uniqueID: The ID of the entity object which should be removed
104 */
105void NetworkGameManager::requestRemoveEntity(int uniqueID)
106{
107}
108
109/*!
110 * Creates the needed entity if possible
111 * This function is called if this is a server
112 * @param classID: The ID of the class of which an entity should be created
113 */
114void NetworkGameManager::executeCreateEntity(int classID)
115{
116}
117
118/*!
119 * Removes the specified entity
120 * This function is called if this is a server
121 * @param uniqueID: The ID of the entity object which should be removed
122 */
123void NetworkGameManager::executeRemoveEntity(int uniqueID)
124{
125}
126
127/*!
128 * Checks whether it is possible to create an entity of a given class
129 * @return: true if the entity can be created, false otherwise
130 */
131bool NetworkGameManager::canCreateEntity(int classID)
132{
133  return true;
134}
135
136/*!
137 * Sends the Entities to the new connected client
138 * @param userID: The ID of the user
139 */
140void NetworkGameManager::sendEntityList( int userID )
141{
142}
143
144/**
145 * Creates a buffer for user n
146 * @param n The ID of the user
147 */
148void NetworkGameManager::resizeBufferVector( int n )
149{
150  for ( int i = inBuffer.size(); i<=n; i++)
151  {
152    clientBuffer inBuf;
153    clientBuffer outBuf;
154
155    inBuf.length = 0;
156    outBuf.length = 0;
157
158    inBuf.maxLength = 5*1014;
159    outBuf.maxLength = 5*1024;
160
161    inBuf.buffer = new byte[5*1014];
162    outBuf.buffer = new byte[5*1014];
163
164    inBuffer.push_back(inBuf);
165    outBuffer.push_back(outBuf);
166  }
167}
168
169/**
170 * Creates the entity on this host
171 * @param classID: ClassID of the entity to create
172 * @param uniqueID: Unique ID to assign to the synchronizeable
173 * @param owner: owner of this synchronizealbe
174 */
175void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
176{
177  BaseObject * b = Factory::fabricate( classID );
178
179  if ( b->isA(CL_SYNCHRONIZEABLE) )
180  {
181    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
182    s->setUniqueID( uniqueID );
183    s->setOwner( owner );
184    this->networkStream->connectSynchronizeable( *s );
185  }
186  else
187  {
188    PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID);
189    delete b;
190  }
191}
192
193/**
194 * Removes a entity on this host
195 * @param uniqueID: unique ID assigned with the entity to remove
196 */
197void NetworkGameManager::doRemoveEntity( int uniqueID )
198{
199  SynchronizeableList::const_iterator it,e;
200  it = this->networkStream->getSyncBegin();
201  e = this->networkStream->getSyncEnd();
202
203  while ( it != e )
204  {
205    if ( (*it)->getUniqueID() == uniqueID )
206    {
207      delete *it;
208      break;
209    }
210  }
211}
212
213/**
214 * Tell the synchronizeable that a user's synchronizeable is out of sync
215 * @param uniqueID: unique ID assigned with the entity which is out of sync
216 * @param userID: user ID who's synchronizeable is out of sync
217 */
218void NetworkGameManager::doRequestSync( int uniqueID, int userID )
219{
220  SynchronizeableList::const_iterator it,e;
221  it = this->networkStream->getSyncBegin();
222  e = this->networkStream->getSyncEnd();
223
224  while ( it != e )
225  {
226    if ( (*it)->getUniqueID() == uniqueID )
227    {
228      (*it)->requestSync( userID );
229      break;
230    }
231  }
232}
Note: See TracBrowser for help on using the repository browser.