Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef _SESSION_TPL_H_
#define _SESSION_TPL_H_

#include "WorldPacket.h"

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_wiarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio.hpp>
#include <deque>
#include <set>

using boost::asio::deadline_timer;
using boost::asio::ip::tcp;
using boost::asio::ip::udp;

namespace Divide {
//----------------------------------------------------------------------

class subscriber
{
public:
  virtual ~subscriber() {}
  virtual void sendPacket(const WorldPacket& p) = 0;
};

typedef boost::shared_ptr<subscriber> subscriber_ptr;

//----------------------------------------------------------------------

class channel
{
public:
  void join(subscriber_ptr subscriber)
  {
    subscribers_.insert(subscriber);
  }

  void leave(subscriber_ptr subscriber)
  {
    subscribers_.erase(subscriber);
  }

  void sendPacket(const WorldPacket& p)
  {
    std::for_each(subscribers_.begin(), subscribers_.end(),
        boost::bind(&subscriber::sendPacket, _1, boost::ref(p)));
  }

private:
  std::set<subscriber_ptr> subscribers_;
};

///This is a single session handled by the server. It is mapped to a single client
class tcp_session_tpl
  : public subscriber,
    public boost::enable_shared_from_this<tcp_session_tpl>
{
public:
  tcp_session_tpl(boost::asio::io_service& io_service, channel& ch);

  inline tcp::socket& getSocket() {  return socket_; }

  // Called by the server object to initiate the four actors.
  virtual void start();

  //Push a new packet in the output queue
  virtual void sendPacket(const WorldPacket& p);

  //Push a new file in the output queue
  virtual void sendFile(const std::string& fileName);

private:
  virtual void stop();
  virtual bool stopped() const;

  //Read Packet;
  virtual void start_read();
  virtual void handle_read_body(const boost::system::error_code& ec,size_t bytes_transfered);
  virtual void handle_read_packet(const boost::system::error_code& ec,size_t bytes_transfered);

  //Write Packet
  virtual void start_write();
  virtual void handle_write(const boost::system::error_code& ec);

  //Write File
  virtual void handle_write_file(const boost::system::error_code& ec);

  //Update Timers
  virtual void await_output();
  virtual void check_deadline(deadline_timer* deadline);

protected:

    //Define this functions to implement various packet handling (a switch statement for example)
    //switch(p.getOpcode()) { case SMSG_XXXXX: bla bla bla break; case MSG_HEARTBEAT: break;}
    virtual void handlePacket(WorldPacket& p) = 0;

private:
  size_t header;
  channel& channel_;
  tcp::socket socket_;
  boost::asio::streambuf input_buffer_;
  deadline_timer input_deadline_;
  std::deque<WorldPacket> output_queue_;
  std::deque<std::string> output_file_queue_;
  deadline_timer non_empty_output_queue_;
  deadline_timer output_deadline_;
  boost::asio::strand _strand;
  time_t start_time;
};

typedef boost::shared_ptr<tcp_session_tpl> tcp_session_ptr;

//----------------------------------------------------------------------

class udp_broadcaster  : public subscriber
{
public:
  udp_broadcaster(boost::asio::io_service& io_service,const udp::endpoint& broadcast_endpoint);

  inline udp::socket& getSocket() { return socket_; }
  void sendPacket(const WorldPacket& p);
private:

  udp::socket socket_;
};

}; //namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/Libs/includes/DivideNetworking/tcp_session_tpl.h

Diff revisions: vs.
Revision Author Commited Message
318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

304 Diff Diff IonutCava picture IonutCava Sun 10 Aug, 2014 21:10:54 +0000

[Ionut]
- Redesigned the WorldEditor (dummy functions added for every button/option)
- Improved debug rendering performance by using static IMPrimitives for axis gizmo rendering
- Simplified skeleton rendering

171 Diff Diff k1ngp1n picture k1ngp1n Sun 03 Nov, 2013 18:15:06 +0000

-Replaced all tabs with spaces [[BR]]

152 k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]