├── .gitignore
├── 01 - Sending and Receiving Packets
├── Example.tmproj
├── Net.h
├── Node.cpp
├── Simple.cpp
├── Test.cpp
├── addresses.txt
├── makefile
└── vs2012
│ ├── Node.vcxproj
│ ├── Node.vcxproj.filters
│ ├── Simple.vcxproj
│ ├── Simple.vcxproj.filters
│ ├── Test.vcxproj
│ ├── Test.vcxproj.filters
│ ├── addresses.txt
│ └── sendreceive.sln
├── 02 - Virtual Connection over UDP
├── Client.cpp
├── Example.tmproj
├── Net.h
├── Server.cpp
├── Test.cpp
├── makefile
└── vs2012
│ ├── Client.vcxproj
│ ├── Client.vcxproj.filters
│ ├── Server.vcxproj
│ ├── Server.vcxproj.filters
│ ├── Test.vcxproj
│ ├── Test.vcxproj.filters
│ └── VirtualConnectionUDP.sln
├── 03 - Reliability and Flow Control
├── Example.cpp
├── Example.tmproj
├── Net.h
├── Test.cpp
├── makefile
└── vs2012
│ ├── FlowControl.vcxproj
│ ├── FlowControl.vcxproj.filters
│ ├── ReliabilityFlowControl.sln
│ ├── Test.vcxproj
│ └── Test.vcxproj.filters
├── 04 - Building a Node Mesh
├── Client.cpp
├── Example.tmproj
├── Net.h
├── Node.cpp
├── Server.cpp
├── Test.cpp
├── makefile
└── vs2012
│ ├── Client
│ ├── Client.vcxproj
│ └── Client.vcxproj.filters
│ ├── Node
│ ├── node.vcxproj
│ └── node.vcxproj.filters
│ ├── NodeMesh.sln
│ ├── Server
│ ├── Server.vcxproj
│ └── Server.vcxproj.filters
│ └── Test
│ ├── Test.vcxproj
│ └── Test.vcxproj.filters
├── 05 - LAN Matchmaking
├── Beacon.cpp
├── Example.tmproj
├── Net.h
├── makefile
└── vs2012
│ ├── Beacon
│ ├── Beacon.vcxproj
│ └── Beacon.vcxproj.filters
│ └── LanMatchmake.sln
├── 06 - Real World Networking
├── Client.cpp
├── Example.tmproj
├── Lobby.cpp
├── NetFlowControl.h
├── NetPlatform.h
├── NetTransport.cpp
├── NetTransport.h
├── Server.cpp
├── Test.cpp
├── lan
│ ├── NetAddress.h
│ ├── NetBeacon.h
│ ├── NetConnection.h
│ ├── NetNodeMesh.h
│ ├── NetReliability.h
│ └── NetSockets.h
├── makefile
└── vs2012
│ ├── RealWorldNetwork.sln
│ └── Test
│ ├── Test.vcxproj
│ └── Test.vcxproj.filters
├── 07 - Reading and Writing Packets
├── Example.cpp
├── Example.tmproj
├── NetStream.h
├── Test.cpp
└── makefile
├── README.md
├── XX - Authority Management
├── Authority.cpp
├── Authority.tmproj
├── Display.h
├── Mathematics.h
├── NetStream.h
├── Platform.h
├── makefile
└── ode
│ ├── collision.h
│ ├── collision_space.h
│ ├── common.h
│ ├── compatibility.h
│ ├── config.h
│ ├── contact.h
│ ├── error.h
│ ├── export-dif.h
│ ├── libode.a
│ ├── mass.h
│ ├── matrix.h
│ ├── memory.h
│ ├── misc.h
│ ├── objects.h
│ ├── ode.h
│ ├── ode.lib
│ ├── odemath.h
│ ├── rotation.h
│ └── timer.h
├── XX - Drop-In COOP for Open World Games
├── Client.cpp
├── Common.h
├── Components.rb
├── Database.rb
├── Display.h
├── Game.rb
├── GameObject.h
├── Math.rb
├── Mathematics.h
├── Net.h
├── Net.rb
├── OpenWorld.tmproj
├── Platform.h
├── Properties.rb
├── Render.h
├── RubyNative.h
├── Sandbox.cpp
├── Scene.rb
├── Server
├── Simulation.h
├── Simulation.rb
├── makefile.apple
├── makefile.linux
├── ode
│ ├── collision.h
│ ├── collision_space.h
│ ├── common.h
│ ├── compatibility.h
│ ├── config.h
│ ├── contact.h
│ ├── error.h
│ ├── export-dif.h
│ ├── libode.a
│ ├── mass.h
│ ├── matrix.h
│ ├── memory.h
│ ├── misc.h
│ ├── objects.h
│ ├── ode.h
│ ├── ode.lib
│ ├── odemath.h
│ ├── rotation.h
│ └── timer.h
└── scene.xml
└── XX - Fiedler's Cubes
├── Activation.h
├── AuthorityDemo.h
├── Config.h
├── CorrectionsDemo.h
├── Cubes.h
├── Demo.cpp
├── Engine.h
├── Game.h
├── Hypercube.h
├── Hypercube.tmproj
├── InterpolationDemo.h
├── Mathematics.h
├── Network.h
├── Platform.h
├── Render.h
├── Simulation.h
├── SingleplayerDemo.h
├── StateReplicationDemo.h
├── UnitTest++
├── AssertException.h
├── CheckMacros.h
├── Checks.h
├── Config.h
├── CurrentTest.h
├── DeferredTestReporter.h
├── DeferredTestResult.h
├── ExecuteTest.h
├── MemoryOutStream.h
├── Posix
│ ├── SignalTranslator.h
│ └── TimeHelpers.h
├── ReportAssert.h
├── Test.h
├── TestDetails.h
├── TestList.h
├── TestMacros.h
├── TestReporter.h
├── TestReporterStdout.h
├── TestResults.h
├── TestRunner.h
├── TestSuite.h
├── TimeConstraint.h
├── TimeHelpers.h
├── UnitTest++.h
├── Win32
│ └── TimeHelpers.h
└── XmlTestReporter.h
├── View.h
├── ViewObject.h
├── license.html
├── license.txt
├── makefile
├── makefile.apple
├── stdint.h
├── todo.txt
└── vs2008
├── FiedlersCubes.sln
└── FiedlersCubes.vcproj
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 | *.publishproj
131 |
132 | # NuGet Packages Directory
133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
134 | #packages/
135 |
136 | # Windows Azure Build Output
137 | csx
138 | *.build.csdef
139 |
140 | # Windows Store app package directory
141 | AppPackages/
142 |
143 | # Others
144 | sql/
145 | *.Cache
146 | ClientBin/
147 | [Ss]tyle[Cc]op.*
148 | ~$*
149 | *~
150 | *.dbmdl
151 | *.[Pp]ublish.xml
152 | *.pfx
153 | *.publishsettings
154 |
155 | # RIA/Silverlight projects
156 | Generated_Code/
157 |
158 | # Backup & report files from converting an old project file to a newer
159 | # Visual Studio version. Backup files are not needed, because we have git ;-)
160 | _UpgradeReport_Files/
161 | Backup*/
162 | UpgradeLog*.XML
163 | UpgradeLog*.htm
164 |
165 | # SQL Server files
166 | App_Data/*.mdf
167 | App_Data/*.ldf
168 |
169 | #############
170 | ## Windows detritus
171 | #############
172 |
173 | # Windows image file caches
174 | Thumbs.db
175 | ehthumbs.db
176 |
177 | # Folder config file
178 | Desktop.ini
179 |
180 | # Recycle Bin used on file shares
181 | $RECYCLE.BIN/
182 |
183 | # Mac crap
184 | .DS_Store
185 |
186 |
187 | #############
188 | ## Python
189 | #############
190 |
191 | *.py[cod]
192 |
193 | # Packages
194 | *.egg
195 | *.egg-info
196 | dist/
197 | build/
198 | eggs/
199 | parts/
200 | var/
201 | sdist/
202 | develop-eggs/
203 | .installed.cfg
204 |
205 | # Installer logs
206 | pip-log.txt
207 |
208 | # Unit test / coverage reports
209 | .coverage
210 | .tox
211 |
212 | #Translations
213 | *.mo
214 |
215 | #Mr Developer
216 | .mr.developer.cfg
217 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Net.h
7 | documents
8 |
9 |
10 | filename
11 | Net.h
12 | lastUsed
13 | 2008-11-11T16:27:26Z
14 | selected
15 |
16 |
17 |
18 | filename
19 | Node.cpp
20 | lastUsed
21 | 2008-10-25T06:14:13Z
22 |
23 |
24 | filename
25 | Simple.cpp
26 | lastUsed
27 | 2008-10-25T06:14:13Z
28 |
29 |
30 | filename
31 | Test.cpp
32 | lastUsed
33 | 2008-10-25T06:14:13Z
34 |
35 |
36 | filename
37 | addresses.txt
38 | lastUsed
39 | 2008-10-25T06:14:13Z
40 |
41 |
42 | filename
43 | makefile
44 | lastUsed
45 | 2008-10-25T06:14:13Z
46 |
47 |
48 | fileHierarchyDrawerWidth
49 | 200
50 | metaData
51 |
52 | Net.h
53 |
54 | caret
55 |
56 | column
57 | 0
58 | line
59 | 68
60 |
61 | firstVisibleColumn
62 | 0
63 | firstVisibleLine
64 | 28
65 |
66 |
67 | openDocuments
68 |
69 | Net.h
70 |
71 | showFileHierarchyDrawer
72 |
73 | windowFrame
74 | {{203, 4}, {1075, 774}}
75 |
76 |
77 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/Node.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Sending and Receiving Packets Example
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | int main( int argc, char * argv[] )
18 | {
19 | // initialize socket layer
20 |
21 | if (!InitializeSockets())
22 | {
23 | printf( "failed to initialize sockets\n" );
24 | return 1;
25 | }
26 |
27 | // create socket
28 |
29 | int port = 30000;
30 |
31 | if ( argc == 2 )
32 | port = atoi( argv[1] );
33 |
34 | printf( "creating socket on port %d\n", port );
35 |
36 | Socket socket;
37 | if ( !socket.Open( port ) )
38 | {
39 | printf( "failed to create socket!\n" );
40 | return 1;
41 | }
42 |
43 | // read in addresses.txt to get the set of addresses we will send packets to
44 |
45 | vector addresses;
46 |
47 | string line;
48 | ifstream file;
49 | file.open( "addresses.txt");
50 | if ( file.fail() )
51 | {
52 | printf( "failed to open 'addresses.txt'\n" );
53 | return 1;
54 | }
55 |
56 | while ( !file.eof() )
57 | {
58 | getline( file, line );
59 | int a,b,c,d,port;
60 | if ( sscanf( line.c_str(), "%d.%d.%d.%d:%d", &a, &b, &c, &d, &port ) == 5 )
61 | addresses.push_back( Address( a,b,c,d,port ) );
62 | }
63 |
64 | file.close();
65 |
66 | // send and receive packets until the user ctrl-breaks...
67 |
68 | while ( true )
69 | {
70 | const char data[] = "hello world!";
71 | for ( int i = 0; i < (int) addresses.size(); ++i )
72 | socket.Send( addresses[i], data, sizeof( data ) );
73 |
74 | while ( true )
75 | {
76 | Address sender;
77 | unsigned char buffer[256];
78 | int bytes_read = socket.Receive( sender, buffer, sizeof( buffer ) );
79 | if ( !bytes_read )
80 | break;
81 |
82 | printf( "received packet from %d.%d.%d.%d:%d (%d bytes)\n", sender.GetA(), sender.GetB(), sender.GetC(), sender.GetD(), sender.GetPort(), bytes_read );
83 | }
84 |
85 | wait_seconds( 1.0f );
86 | }
87 |
88 | // shutdown socket layer
89 |
90 | ShutdownSockets();
91 | return 0;
92 | }
93 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/Simple.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Sending and Receiving Packets Example
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | int main( int argc, char * argv[] )
18 | {
19 | // initialize socket layer
20 |
21 | if ( !InitializeSockets() )
22 | {
23 | printf( "failed to initialize sockets\n" );
24 | return 1;
25 | }
26 |
27 | // create socket
28 |
29 | int port = 30000;
30 |
31 | printf( "creating socket on port %d\n", port );
32 |
33 | Socket socket;
34 |
35 | if ( !socket.Open( port ) )
36 | {
37 | printf( "failed to create socket!\n" );
38 | return 1;
39 | }
40 |
41 | // send and receive packets to ourself until the user ctrl-breaks...
42 |
43 | while ( true )
44 | {
45 | const char data[] = "hello world!";
46 |
47 | socket.Send( Address(127,0,0,1,port), data, sizeof(data) );
48 |
49 | while ( true )
50 | {
51 | Address sender;
52 | unsigned char buffer[256];
53 | int bytes_read = socket.Receive( sender, buffer, sizeof( buffer ) );
54 | if ( !bytes_read )
55 | break;
56 | printf( "received packet from %d.%d.%d.%d:%d (%d bytes)\n",
57 | sender.GetA(), sender.GetB(), sender.GetC(), sender.GetD(),
58 | sender.GetPort(), bytes_read );
59 | }
60 |
61 | wait_seconds( 0.25f );
62 | }
63 |
64 | // shutdown socket layer
65 |
66 | ShutdownSockets();
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/Test.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Sending and Receiving Packets Example
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | #ifdef DEBUG
18 | #define check assert
19 | #else
20 | #define check(n) if ( !(n) ) { printf( "check failed\n" ); exit(1); }
21 | #endif
22 |
23 | void test_address()
24 | {
25 | printf( "-----------------------------------------------------\n" );
26 | printf( "test address\n" );
27 | printf( "-----------------------------------------------------\n" );
28 |
29 | printf( "defaults\n" );
30 | {
31 | Address address;
32 | check( address.GetA() == 0 );
33 | check( address.GetB() == 0 );
34 | check( address.GetC() == 0 );
35 | check( address.GetD() == 0 );
36 | check( address.GetPort() == 0 );
37 | check( address.GetAddress() == 0 );
38 | }
39 |
40 | printf( "a,b,c,d,port\n" );
41 | {
42 | const unsigned char a = 100;
43 | const unsigned char b = 110;
44 | const unsigned char c = 50;
45 | const unsigned char d = 12;
46 | const unsigned short port = 10000;
47 | Address address( a, b, c, d, port );
48 | check( a == address.GetA() );
49 | check( b == address.GetB() );
50 | check( c == address.GetC() );
51 | check( d == address.GetD() );
52 | check( port == address.GetPort() );
53 | }
54 |
55 | printf( "equality/inequality\n");
56 | {
57 | Address x(100,110,0,1,50000);
58 | Address y(101,210,6,5,50002);
59 | check( x != y );
60 | check( y == y );
61 | check( x == x );
62 | }
63 | }
64 |
65 | void test_socket()
66 | {
67 | printf( "-----------------------------------------------------\n" );
68 | printf( "test socket\n" );
69 | printf( "-----------------------------------------------------\n" );
70 |
71 | printf( "open/close\n" );
72 | {
73 | Socket socket;
74 | check( !socket.IsOpen() );
75 | check( socket.Open( 30000 ) );
76 | check( socket.IsOpen() );
77 | socket.Close();
78 | check( !socket.IsOpen() );
79 | check( socket.Open( 30000 ) );
80 | check( socket.IsOpen() );
81 | }
82 |
83 | printf( "fails on same port\n" );
84 | {
85 | Socket a,b;
86 | check( a.Open( 30000 ) );
87 | check( !b.Open( 30000 ) );
88 | check( a.IsOpen() );
89 | check( !b.IsOpen() );
90 | }
91 |
92 | printf( "send and receive packets\n" );
93 | {
94 | Socket a,b;
95 | check( a.Open( 30000 ) );
96 | check( b.Open( 30001 ) );
97 | const char packet[] = "packet data";
98 | bool a_received_packet = false;
99 | bool b_received_packet = false;
100 | while ( !a_received_packet && !b_received_packet )
101 | {
102 | check( a.Send( Address(127,0,0,1,30000), packet, sizeof(packet) ) );
103 | check( b.Send( Address(127,0,0,1,30000), packet, sizeof(packet) ) );
104 |
105 | while ( true )
106 | {
107 | Address sender;
108 | char buffer[256];
109 | int bytes_read = a.Receive( sender, buffer, sizeof(buffer) );
110 | if ( bytes_read == 0 )
111 | break;
112 | if ( bytes_read == sizeof(packet) && strcmp(buffer,packet) == 0 )
113 | a_received_packet = true;
114 | }
115 |
116 | while ( true )
117 | {
118 | Address sender;
119 | char buffer[256];
120 | int bytes_read = b.Receive( sender, buffer, sizeof(buffer) );
121 | if ( bytes_read == 0 )
122 | break;
123 | if ( bytes_read == sizeof(packet) && strcmp(buffer,packet) == 0 )
124 | b_received_packet = true;
125 | }
126 | }
127 | }
128 | }
129 |
130 | void tests()
131 | {
132 | test_address();
133 | test_socket();
134 |
135 | printf( "-----------------------------------------------------\n" );
136 | printf( "passed!\n" );
137 | }
138 |
139 | int main( int argc, char * argv[] )
140 | {
141 | if ( !InitializeSockets() )
142 | {
143 | printf( "failed to initialize sockets\n" );
144 | return 1;
145 | }
146 |
147 | tests();
148 |
149 | ShutdownSockets();
150 |
151 | return 0;
152 | }
153 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/addresses.txt:
--------------------------------------------------------------------------------
1 | 127.0.0.1:30000
2 | 127.0.0.1:30001
3 | 127.0.0.1:30002
4 | 127.0.0.1:30003
5 | 127.0.0.1:30004
6 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -DDEBUG # -O3
4 |
5 | % : %.cpp Net.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Test Simple Node
9 |
10 | test : Test
11 | ./Test
12 |
13 | node : Node
14 | ./Node
15 |
16 | simple : Simple
17 | ./Simple
18 |
19 | clean:
20 | rm -f Test Node Simple
21 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/vs2012/Node.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/vs2012/Simple.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/vs2012/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/vs2012/addresses.txt:
--------------------------------------------------------------------------------
1 | 127.0.0.1:30000
2 | 127.0.0.1:30001
3 | 127.0.0.1:30002
4 | 127.0.0.1:30003
5 | 127.0.0.1:30004
6 |
--------------------------------------------------------------------------------
/01 - Sending and Receiving Packets/vs2012/sendreceive.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Node", "Node.vcxproj", "{10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Simple", "Simple.vcxproj", "{5B927FCB-5BB4-4FFF-B69E-B10F5D199E66}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{4051A828-2363-4E80-93EF-D3BBB0004C06}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Release|Win32 = Release|Win32
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Debug|Win32.ActiveCfg = Debug|Win32
17 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Debug|Win32.Build.0 = Debug|Win32
18 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Release|Win32.ActiveCfg = Release|Win32
19 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Release|Win32.Build.0 = Release|Win32
20 | {5B927FCB-5BB4-4FFF-B69E-B10F5D199E66}.Debug|Win32.ActiveCfg = Debug|Win32
21 | {5B927FCB-5BB4-4FFF-B69E-B10F5D199E66}.Debug|Win32.Build.0 = Debug|Win32
22 | {5B927FCB-5BB4-4FFF-B69E-B10F5D199E66}.Release|Win32.ActiveCfg = Release|Win32
23 | {5B927FCB-5BB4-4FFF-B69E-B10F5D199E66}.Release|Win32.Build.0 = Release|Win32
24 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Debug|Win32.ActiveCfg = Debug|Win32
25 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Debug|Win32.Build.0 = Debug|Win32
26 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Release|Win32.ActiveCfg = Release|Win32
27 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Release|Win32.Build.0 = Release|Win32
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/Client.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Client using Virtual Connection over UDP
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int ServerPort = 30000;
18 | const int ClientPort = 30001;
19 | const int ProtocolId = 0x99887766;
20 | const float DeltaTime = 0.25f;
21 | const float SendRate = 0.25f;
22 | const float TimeOut = 10.0f;
23 |
24 | int main( int argc, char * argv[] )
25 | {
26 | if ( !InitializeSockets() )
27 | {
28 | printf( "failed to initialize sockets\n" );
29 | return 1;
30 | }
31 |
32 | Connection connection( ProtocolId, TimeOut );
33 |
34 | if ( !connection.Start( ClientPort ) )
35 | {
36 | printf( "could not start connection on port %d\n", ClientPort );
37 | return 1;
38 | }
39 |
40 | connection.Connect( Address(127,0,0,1,ServerPort ) );
41 |
42 | bool connected = false;
43 |
44 | while ( true )
45 | {
46 | if ( !connected && connection.IsConnected() )
47 | {
48 | printf( "client connected to server\n" );
49 | connected = true;
50 | }
51 |
52 | if ( !connected && connection.ConnectFailed() )
53 | {
54 | printf( "connection failed\n" );
55 | break;
56 | }
57 |
58 | unsigned char packet[] = "client to server";
59 | connection.SendPacket( packet, sizeof( packet ) );
60 |
61 | while ( true )
62 | {
63 | unsigned char packet[256];
64 | int bytes_read = connection.ReceivePacket( packet, sizeof(packet) );
65 | if ( bytes_read == 0 )
66 | break;
67 | printf( "received packet from server\n" );
68 | }
69 |
70 | connection.Update( DeltaTime );
71 |
72 | wait_seconds( DeltaTime );
73 | }
74 |
75 | ShutdownSockets();
76 |
77 | return 0;
78 | }
79 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Net.h
7 | documents
8 |
9 |
10 | filename
11 | Net.h
12 | lastUsed
13 | 2008-11-11T16:29:06Z
14 | selected
15 |
16 |
17 |
18 | filename
19 | Test.cpp
20 | lastUsed
21 | 2008-10-25T20:46:35Z
22 |
23 |
24 | filename
25 | Client.cpp
26 | lastUsed
27 | 2008-10-21T03:11:52Z
28 |
29 |
30 | filename
31 | Server.cpp
32 | lastUsed
33 | 2008-11-11T16:29:06Z
34 |
35 |
36 | filename
37 | makefile
38 | lastUsed
39 | 2008-10-25T20:46:35Z
40 |
41 |
42 | fileHierarchyDrawerWidth
43 | 200
44 | metaData
45 |
46 | Client.cpp
47 |
48 | caret
49 |
50 | column
51 | 14
52 | line
53 | 71
54 |
55 | firstVisibleColumn
56 | 0
57 | firstVisibleLine
58 | 37
59 |
60 | Net.h
61 |
62 | caret
63 |
64 | column
65 | 0
66 | line
67 | 42
68 |
69 | columnSelection
70 |
71 | firstVisibleColumn
72 | 0
73 | firstVisibleLine
74 | 20
75 | selectFrom
76 |
77 | column
78 | 0
79 | line
80 | 40
81 |
82 | selectTo
83 |
84 | column
85 | 0
86 | line
87 | 42
88 |
89 |
90 | Server.cpp
91 |
92 | caret
93 |
94 | column
95 | 0
96 | line
97 | 0
98 |
99 | firstVisibleColumn
100 | 0
101 | firstVisibleLine
102 | 0
103 |
104 |
105 | openDocuments
106 |
107 | Server.cpp
108 | Net.h
109 | Client.cpp
110 |
111 | showFileHierarchyDrawer
112 |
113 | windowFrame
114 | {{203, 4}, {1075, 774}}
115 |
116 |
117 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/Server.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Server using Virtual Connection over UDP
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int ServerPort = 30000;
18 | const int ClientPort = 30001;
19 | const int ProtocolId = 0x99887766;
20 | const float DeltaTime = 0.25f;
21 | const float SendRate = 0.25f;
22 | const float TimeOut = 10.0f;
23 |
24 | int main( int argc, char * argv[] )
25 | {
26 | if ( !InitializeSockets() )
27 | {
28 | printf( "failed to initialize sockets\n" );
29 | return 1;
30 | }
31 |
32 | Connection connection( ProtocolId, TimeOut );
33 |
34 | if ( !connection.Start( ServerPort ) )
35 | {
36 | printf( "could not start connection on port %d\n", ServerPort );
37 | return 1;
38 | }
39 |
40 | connection.Listen();
41 |
42 | while ( true )
43 | {
44 | if ( connection.IsConnected() )
45 | {
46 | unsigned char packet[] = "server to client";
47 | connection.SendPacket( packet, sizeof( packet ) );
48 | }
49 |
50 | while ( true )
51 | {
52 | unsigned char packet[256];
53 | int bytes_read = connection.ReceivePacket( packet, sizeof(packet) );
54 | if ( bytes_read == 0 )
55 | break;
56 | printf( "received packet from client\n" );
57 | }
58 |
59 | connection.Update( DeltaTime );
60 |
61 | wait_seconds( DeltaTime );
62 | }
63 |
64 | ShutdownSockets();
65 |
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -g -DDEBUG # -O3
4 |
5 | % : %.cpp Net.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Client Server Test
9 |
10 | test : Test
11 | ./Test
12 |
13 | server : Server
14 | ./Server
15 |
16 | client : Client
17 | ./Client
18 |
19 | clean:
20 | rm -f Client Server Test
21 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/vs2012/Client.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/vs2012/Server.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/vs2012/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/02 - Virtual Connection over UDP/vs2012/VirtualConnectionUDP.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{4051A828-2363-4E80-93EF-D3BBB0004C06}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client.vcxproj", "{10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server.vcxproj", "{F6EB9892-DF30-4F5C-ACB1-EE7EEA08029E}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Release|Win32 = Release|Win32
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Debug|Win32.ActiveCfg = Debug|Win32
17 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Debug|Win32.Build.0 = Debug|Win32
18 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Release|Win32.ActiveCfg = Release|Win32
19 | {4051A828-2363-4E80-93EF-D3BBB0004C06}.Release|Win32.Build.0 = Release|Win32
20 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Debug|Win32.ActiveCfg = Debug|Win32
21 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Debug|Win32.Build.0 = Debug|Win32
22 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Release|Win32.ActiveCfg = Release|Win32
23 | {10A5456C-8EAF-4DDD-BC2D-7503E011C6ED}.Release|Win32.Build.0 = Release|Win32
24 | {F6EB9892-DF30-4F5C-ACB1-EE7EEA08029E}.Debug|Win32.ActiveCfg = Debug|Win32
25 | {F6EB9892-DF30-4F5C-ACB1-EE7EEA08029E}.Debug|Win32.Build.0 = Debug|Win32
26 | {F6EB9892-DF30-4F5C-ACB1-EE7EEA08029E}.Release|Win32.ActiveCfg = Release|Win32
27 | {F6EB9892-DF30-4F5C-ACB1-EE7EEA08029E}.Release|Win32.Build.0 = Release|Win32
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/03 - Reliability and Flow Control/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Net.h
7 | documents
8 |
9 |
10 | filename
11 | Net.h
12 | lastUsed
13 | 2008-11-11T16:29:33Z
14 | selected
15 |
16 |
17 |
18 | filename
19 | Test.cpp
20 | lastUsed
21 | 2008-10-21T22:38:31Z
22 |
23 |
24 | filename
25 | Example.cpp
26 | lastUsed
27 | 2008-10-21T22:38:31Z
28 |
29 |
30 | filename
31 | makefile
32 | lastUsed
33 | 2008-10-20T22:50:29Z
34 |
35 |
36 | fileHierarchyDrawerWidth
37 | 146
38 | metaData
39 |
40 | Net.h
41 |
42 | caret
43 |
44 | column
45 | 0
46 | line
47 | 43
48 |
49 | firstVisibleColumn
50 | 0
51 | firstVisibleLine
52 | 19
53 |
54 |
55 | openDocuments
56 |
57 | Net.h
58 |
59 | showFileHierarchyDrawer
60 |
61 | windowFrame
62 | {{157, 4}, {1121, 774}}
63 |
64 |
65 |
--------------------------------------------------------------------------------
/03 - Reliability and Flow Control/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -g -DDEBUG # -O3
4 |
5 | % : %.cpp Net.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Example Test
9 |
10 | test : Test
11 | ./Test
12 |
13 | server : Example
14 | ./Example
15 |
16 | client : Example
17 | ./Example 127.0.0.1
18 |
19 | clean:
20 | rm -f Test Example
21 |
22 |
--------------------------------------------------------------------------------
/03 - Reliability and Flow Control/vs2012/FlowControl.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/03 - Reliability and Flow Control/vs2012/ReliabilityFlowControl.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcxproj", "{E958AB6C-1E61-419E-811D-6F4830D56A28}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FlowControl", "FlowControl.vcxproj", "{6A03EA65-0096-4002-BF0C-0765196E3BEF}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {E958AB6C-1E61-419E-811D-6F4830D56A28}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {E958AB6C-1E61-419E-811D-6F4830D56A28}.Debug|Win32.Build.0 = Debug|Win32
16 | {E958AB6C-1E61-419E-811D-6F4830D56A28}.Release|Win32.ActiveCfg = Release|Win32
17 | {E958AB6C-1E61-419E-811D-6F4830D56A28}.Release|Win32.Build.0 = Release|Win32
18 | {6A03EA65-0096-4002-BF0C-0765196E3BEF}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {6A03EA65-0096-4002-BF0C-0765196E3BEF}.Debug|Win32.Build.0 = Debug|Win32
20 | {6A03EA65-0096-4002-BF0C-0765196E3BEF}.Release|Win32.ActiveCfg = Release|Win32
21 | {6A03EA65-0096-4002-BF0C-0765196E3BEF}.Release|Win32.Build.0 = Release|Win32
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/03 - Reliability and Flow Control/vs2012/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/Client.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Client Example using Node Mesh
3 | From "Networking for Game Programmers" - http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int MaxNodes = 4;
18 | const int MeshPort = 30000;
19 | const int ProtocolId = 0x12341234;
20 | const float DeltaTime = 0.25f;
21 | const float SendRate = 0.25f;
22 | const float TimeOut = 10.0f;
23 |
24 | int main( int argc, char * argv[] )
25 | {
26 | if ( !InitializeSockets() )
27 | {
28 | printf( "failed to initialize sockets\n" );
29 | return 1;
30 | }
31 |
32 | Node node( ProtocolId, SendRate, TimeOut );
33 | if ( !node.Start( 0 ) )
34 | {
35 | printf( "failed to start node\n" );
36 | return 1;
37 | }
38 |
39 | node.Join( Address(127,0,0,1,MeshPort) );
40 |
41 | bool connected = false;
42 |
43 | while ( true )
44 | {
45 | if ( node.IsConnected() )
46 | {
47 | if ( !connected )
48 | {
49 | printf( "connected as client %d\n", node.GetLocalNodeId() );
50 | connected = true;
51 | }
52 |
53 | unsigned char packet[] = "client to server";
54 | node.SendPacket( 0, packet, sizeof(packet) );
55 |
56 | while ( true )
57 | {
58 | int nodeId = -1;
59 | unsigned char packet[256];
60 | int bytes_read = node.ReceivePacket( nodeId, packet, sizeof(packet) );
61 | if ( bytes_read == 0 )
62 | break;
63 | assert( nodeId == 0 );
64 | printf( "client received packet from server\n" );
65 | }
66 | }
67 |
68 | if ( !connected && node.JoinFailed() || connected && !node.IsConnected() )
69 | break;
70 |
71 | node.Update( DeltaTime );
72 |
73 | wait_seconds( DeltaTime );
74 | }
75 |
76 | ShutdownSockets();
77 |
78 | return 0;
79 | }
80 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Net.h
7 | documents
8 |
9 |
10 | filename
11 | Net.h
12 | lastUsed
13 | 2008-11-11T16:30:04Z
14 | selected
15 |
16 |
17 |
18 | filename
19 | Test.cpp
20 | lastUsed
21 | 2008-10-23T20:31:32Z
22 |
23 |
24 | filename
25 | Client.cpp
26 | lastUsed
27 | 2008-10-23T20:31:33Z
28 |
29 |
30 | filename
31 | Server.cpp
32 | lastUsed
33 | 2008-10-23T20:31:33Z
34 |
35 |
36 | filename
37 | Node.cpp
38 | lastUsed
39 | 2008-10-23T20:31:33Z
40 |
41 |
42 | filename
43 | makefile
44 | lastUsed
45 | 2008-10-21T20:07:13Z
46 |
47 |
48 | fileHierarchyDrawerWidth
49 | 200
50 | metaData
51 |
52 | Net.h
53 |
54 | caret
55 |
56 | column
57 | 0
58 | line
59 | 42
60 |
61 | firstVisibleColumn
62 | 0
63 | firstVisibleLine
64 | 23
65 |
66 |
67 | openDocuments
68 |
69 | Net.h
70 |
71 | showFileHierarchyDrawer
72 |
73 | windowFrame
74 | {{205, 4}, {1075, 774}}
75 |
76 |
77 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/Node.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Peer-to-Peer Example using Node Mesh
3 | From "Networking for Game Programmers" - http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int MaxNodes = 4;
18 | const int MeshPort = 40000;
19 | const int MasterNodePort = 40001;
20 | const int ProtocolId = 0x80808080;
21 | const float DeltaTime = 0.25f;
22 | const float SendRate = 0.25f;
23 | const float TimeOut = 10.0f;
24 |
25 | int main( int argc, char * argv[] )
26 | {
27 | if ( !InitializeSockets() )
28 | {
29 | printf( "failed to initialize sockets\n" );
30 | return 1;
31 | }
32 |
33 | const bool masterNode = argc == 2 && strcmp( argv[1], "master" ) == 0;
34 |
35 | Mesh mesh( ProtocolId, MaxNodes, SendRate, TimeOut );
36 |
37 | if ( masterNode )
38 | {
39 | if ( !mesh.Start( MeshPort ) )
40 | {
41 | printf( "failed to start mesh on port %d\n", MeshPort );
42 | return 1;
43 | }
44 | mesh.Reserve( 0, Address(127,0,0,1,MasterNodePort) );
45 | }
46 |
47 | Node node( ProtocolId, SendRate, TimeOut );
48 | const int port = masterNode ? MasterNodePort : 0;
49 | if ( !node.Start( port ) )
50 | {
51 | printf( "failed to start node on port %d\n", port );
52 | return 1;
53 | }
54 |
55 | node.Join( Address(127,0,0,1,MeshPort) );
56 |
57 | bool connected = false;
58 |
59 | while ( true )
60 | {
61 | if ( node.IsConnected() )
62 | {
63 | connected = true;
64 |
65 | const int localNodeId = node.GetLocalNodeId();
66 |
67 | for ( int i = 0; i < node.GetMaxAllowedNodes(); ++i )
68 | {
69 | if ( i != localNodeId && node.IsNodeConnected(i) )
70 | {
71 | unsigned char packet[] = "peer to peer";
72 | node.SendPacket( i, packet, sizeof(packet) );
73 | }
74 | }
75 |
76 | while ( true )
77 | {
78 | int nodeId = -1;
79 | unsigned char packet[256];
80 | int bytes_read = node.ReceivePacket( nodeId, packet, sizeof(packet) );
81 | if ( bytes_read == 0 )
82 | break;
83 | printf( "received packet from node %d\n", nodeId );
84 | }
85 | }
86 |
87 | if ( !masterNode && ( !connected && node.JoinFailed() || connected && !node.IsConnected() ) )
88 | break;
89 |
90 | node.Update( DeltaTime );
91 |
92 | if ( masterNode )
93 | mesh.Update( DeltaTime );
94 |
95 | wait_seconds( DeltaTime );
96 | }
97 |
98 | if ( masterNode )
99 | mesh.Stop();
100 |
101 | ShutdownSockets();
102 |
103 | return 0;
104 | }
105 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/Server.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Server Example using Node Mesh
3 | From "Networking for Game Programmers" - http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int MaxNodes = 4;
18 | const int MeshPort = 30000;
19 | const int NodePort = 30001;
20 | const int ProtocolId = 0x12341234;
21 | const float DeltaTime = 0.25f;
22 | const float SendRate = 0.25f;
23 | const float TimeOut = 10.0f;
24 |
25 | int main( int argc, char * argv[] )
26 | {
27 | if ( !InitializeSockets() )
28 | {
29 | printf( "failed to initialize sockets\n" );
30 | return 1;
31 | }
32 |
33 | Mesh mesh( ProtocolId, MaxNodes, SendRate, TimeOut );
34 |
35 | if ( !mesh.Start( MeshPort ) )
36 | {
37 | printf( "failed to start mesh on port %d\n", MeshPort );
38 | return 1;
39 | }
40 |
41 | Node node( ProtocolId, SendRate, TimeOut );
42 | if ( !node.Start( NodePort ) )
43 | {
44 | printf( "failed to start node on port %d\n", NodePort );
45 | return 1;
46 | }
47 |
48 | mesh.Reserve( 0, Address(127,0,0,1,NodePort) );
49 | node.Join( Address(127,0,0,1,MeshPort) );
50 |
51 | while ( true )
52 | {
53 | if ( node.IsConnected() )
54 | {
55 | assert( node.GetLocalNodeId() == 0 );
56 | for ( int i = 1; i < node.GetMaxAllowedNodes(); ++i )
57 | {
58 | if ( node.IsNodeConnected(i) )
59 | {
60 | unsigned char packet[] = "server to client";
61 | node.SendPacket( i, packet, sizeof(packet) );
62 | }
63 | }
64 |
65 | while ( true )
66 | {
67 | int nodeId = -1;
68 | unsigned char packet[256];
69 | int bytes_read = node.ReceivePacket( nodeId, packet, sizeof(packet) );
70 | if ( bytes_read == 0 )
71 | break;
72 | assert( nodeId > 0 );
73 | printf( "server received packet from client %d\n", nodeId - 1 );
74 | }
75 | }
76 |
77 | node.Update( DeltaTime );
78 | mesh.Update( DeltaTime );
79 |
80 | wait_seconds( DeltaTime );
81 | }
82 |
83 | mesh.Stop();
84 |
85 | ShutdownSockets();
86 |
87 | return 0;
88 | }
89 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -g -DDEBUG # -O3
4 |
5 | % : %.cpp Net.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Test Server Client Node
9 |
10 | test : Test
11 | ./Test
12 |
13 | server : Server
14 | ./Server
15 |
16 | client : Client
17 | ./Client
18 |
19 | node : Node
20 | ./Node
21 |
22 | clean:
23 | rm -f Test Server Client Node
24 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Client/Client.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {F93EA237-852A-4746-AD8D-676939563EE0}
15 | Client
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 |
48 |
49 | true
50 |
51 |
52 |
53 |
54 | Level3
55 | MaxSpeed
56 | true
57 | true
58 | true
59 |
60 |
61 | true
62 | true
63 | true
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Client/Client.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Node/node.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {A91FAD77-CF39-4136-8362-D2D468E031DE}
15 | node
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 |
48 |
49 | true
50 | $(OutDir)$(TargetName)$(TargetExt)
51 |
52 |
53 |
54 |
55 | Level3
56 | MaxSpeed
57 | true
58 | true
59 | true
60 |
61 |
62 | true
63 | true
64 | true
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Node/node.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/NodeMesh.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Node", "node\node.vcxproj", "{A91FAD77-CF39-4136-8362-D2D468E031DE}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{3055B280-5D08-407E-9F86-5D542A55438B}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{F93EA237-852A-4746-AD8D-676939563EE0}"
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj", "{7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Win32 = Debug|Win32
15 | Release|Win32 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {A91FAD77-CF39-4136-8362-D2D468E031DE}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {A91FAD77-CF39-4136-8362-D2D468E031DE}.Debug|Win32.Build.0 = Debug|Win32
20 | {A91FAD77-CF39-4136-8362-D2D468E031DE}.Release|Win32.ActiveCfg = Release|Win32
21 | {A91FAD77-CF39-4136-8362-D2D468E031DE}.Release|Win32.Build.0 = Release|Win32
22 | {3055B280-5D08-407E-9F86-5D542A55438B}.Debug|Win32.ActiveCfg = Debug|Win32
23 | {3055B280-5D08-407E-9F86-5D542A55438B}.Debug|Win32.Build.0 = Debug|Win32
24 | {3055B280-5D08-407E-9F86-5D542A55438B}.Release|Win32.ActiveCfg = Release|Win32
25 | {3055B280-5D08-407E-9F86-5D542A55438B}.Release|Win32.Build.0 = Release|Win32
26 | {F93EA237-852A-4746-AD8D-676939563EE0}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {F93EA237-852A-4746-AD8D-676939563EE0}.Debug|Win32.Build.0 = Debug|Win32
28 | {F93EA237-852A-4746-AD8D-676939563EE0}.Release|Win32.ActiveCfg = Release|Win32
29 | {F93EA237-852A-4746-AD8D-676939563EE0}.Release|Win32.Build.0 = Release|Win32
30 | {7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}.Debug|Win32.ActiveCfg = Debug|Win32
31 | {7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}.Debug|Win32.Build.0 = Debug|Win32
32 | {7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}.Release|Win32.ActiveCfg = Release|Win32
33 | {7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}.Release|Win32.Build.0 = Release|Win32
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Server/Server.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {3055B280-5D08-407E-9F86-5D542A55438B}
15 | Server
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 |
48 |
49 | true
50 |
51 |
52 |
53 |
54 | Level3
55 | MaxSpeed
56 | true
57 | true
58 | true
59 |
60 |
61 | true
62 | true
63 | true
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Server/Server.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Test/Test.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {7B5328D1-A54C-4E88-ABDE-8E6E3A755A4E}
15 | Test
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 |
48 |
49 | true
50 |
51 |
52 |
53 |
54 | Level3
55 | MaxSpeed
56 | true
57 | true
58 | true
59 |
60 |
61 | true
62 | true
63 | true
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/04 - Building a Node Mesh/vs2012/Test/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/Beacon.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Beacon Example for LAN Matchmaking
3 | From "Networking for Game Programmers" - http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Net.h"
13 |
14 | using namespace std;
15 | using namespace net;
16 |
17 | const int ServerPort = 30000;
18 | const int ClientPort = 30001;
19 | const int BeaconPort = 40000;
20 | const int ListenerPort = 40001;
21 | const int ProtocolId = 0x31337;
22 | const float DeltaTime = 0.25f;
23 | const float TimeOut = 10.0f;
24 |
25 | int main( int argc, char * argv[] )
26 | {
27 | // initialize sockets
28 |
29 | if ( !InitializeSockets() )
30 | {
31 | printf( "failed to initialize sockets\n" );
32 | return 1;
33 | }
34 |
35 | // process command line
36 |
37 | char hostname[64+1] = "hostname";
38 | gethostname( hostname, 64 );
39 | hostname[64] = '\0';
40 |
41 | if ( argc == 2 )
42 | {
43 | strncpy( hostname, argv[1], 64 );
44 | hostname[64] = '\0';
45 | }
46 |
47 | // create beacon (sends broadcast packets to the LAN...)
48 |
49 | Beacon beacon( hostname, ProtocolId, ListenerPort, ServerPort );
50 |
51 | if ( !beacon.Start( BeaconPort ) )
52 | {
53 | printf( "could not start beacon\n" );
54 | return 1;
55 | }
56 |
57 | // create listener (listens for packets sent from beacons on the LAN...)
58 |
59 | Listener listener( ProtocolId, TimeOut );
60 |
61 | if ( !listener.Start( ListenerPort ) )
62 | {
63 | printf( "could not start listener\n" );
64 | return 1;
65 | }
66 |
67 | // main loop
68 |
69 | float accumulator = 0.0f;
70 |
71 | while ( true )
72 | {
73 | accumulator += DeltaTime;
74 | while ( accumulator >= 1.5f )
75 | {
76 | printf( "---------------------------------------------\n" );
77 | const int entryCount = listener.GetEntryCount();
78 | for ( int i = 0; i < entryCount; ++i )
79 | {
80 | const ListenerEntry & entry = listener.GetEntry( i );
81 | printf( "%d.%d.%d.%d:%d -> %s\n",
82 | entry.address.GetA(), entry.address.GetB(),
83 | entry.address.GetC(), entry.address.GetD(),
84 | entry.address.GetPort(), entry.name );
85 | }
86 | printf( "---------------------------------------------\n" );
87 | accumulator -= 1.5f;
88 | }
89 |
90 | beacon.Update( DeltaTime );
91 | listener.Update( DeltaTime );
92 |
93 | wait_seconds( DeltaTime );
94 | }
95 |
96 | ShutdownSockets();
97 |
98 | return 0;
99 | }
100 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Net.h
7 | documents
8 |
9 |
10 | filename
11 | Net.h
12 | lastUsed
13 | 2008-11-11T16:30:56Z
14 | selected
15 |
16 |
17 |
18 | filename
19 | Beacon.cpp
20 | lastUsed
21 | 2008-10-23T20:56:06Z
22 |
23 |
24 | filename
25 | makefile
26 | lastUsed
27 | 2008-10-17T17:36:06Z
28 |
29 |
30 | fileHierarchyDrawerWidth
31 | 200
32 | metaData
33 |
34 | Net.h
35 |
36 | caret
37 |
38 | column
39 | 0
40 | line
41 | 42
42 |
43 | firstVisibleColumn
44 | 0
45 | firstVisibleLine
46 | 11
47 |
48 |
49 | openDocuments
50 |
51 | Net.h
52 |
53 | showFileHierarchyDrawer
54 |
55 | windowFrame
56 | {{205, 4}, {1075, 774}}
57 |
58 |
59 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -DDEBUG # -O3
4 |
5 | % : %.cpp Net.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Beacon
9 |
10 | beacon : Beacon
11 | ./Beacon
12 |
13 | clean:
14 | rm -f Beacon
15 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/vs2012/Beacon/Beacon.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}
21 | Beacon
22 |
23 |
24 |
25 | Application
26 | true
27 | v110
28 | MultiByte
29 |
30 |
31 | Application
32 | false
33 | v110
34 | true
35 | MultiByte
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Level3
51 | Disabled
52 | true
53 |
54 |
55 | true
56 |
57 |
58 |
59 |
60 | Level3
61 | MaxSpeed
62 | true
63 | true
64 | true
65 |
66 |
67 | true
68 | true
69 | true
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/vs2012/Beacon/Beacon.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/05 - LAN Matchmaking/vs2012/LanMatchmake.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Beacon", "Beacon\Beacon.vcxproj", "{B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}.Debug|Win32.Build.0 = Debug|Win32
14 | {B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}.Release|Win32.ActiveCfg = Release|Win32
15 | {B818BBC9-F3F0-4CED-8BE0-FADB5115F4B8}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/06 - Real World Networking/Client.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Server Example using Transport Layer
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "NetPlatform.h"
13 | #include "NetTransport.h"
14 |
15 | using namespace std;
16 | using namespace net;
17 |
18 | int main( int argc, char * argv[] )
19 | {
20 | // initialize and create transport
21 |
22 | TransportType type = Transport_LAN;
23 |
24 | if ( !Transport::Initialize( Transport_LAN ) )
25 | {
26 | printf( "failed to initialize transport layer\n" );
27 | return 1;
28 | }
29 |
30 | Transport * transport = Transport::Create();
31 |
32 | if ( !transport )
33 | {
34 | printf( "could not create transport\n" );
35 | return 1;
36 | }
37 |
38 | // connect to server (transport specific)
39 |
40 | switch ( type )
41 | {
42 | case Transport_LAN:
43 | {
44 | TransportLAN * lan_transport = dynamic_cast( transport );
45 | if ( argc >= 2 )
46 | lan_transport->ConnectClient( argv[1] );
47 | else
48 | {
49 | char hostname[64+1];
50 | TransportLAN::GetHostName( hostname, sizeof(hostname) );
51 | lan_transport->ConnectClient( hostname );
52 | }
53 | }
54 | break;
55 |
56 | default:
57 | break;
58 | }
59 |
60 | // main loop
61 |
62 | const float DeltaTime = 1.0f / 30.0f;
63 |
64 | bool connected = false;
65 |
66 | while ( true )
67 | {
68 | if ( type == Transport_LAN )
69 | {
70 | TransportLAN * lan_transport = dynamic_cast( transport );
71 | if ( !connected && lan_transport->IsConnected() )
72 | connected = true;
73 | if ( connected && !lan_transport->IsConnected() )
74 | {
75 | printf( "disconnected\n" );
76 | break;
77 | }
78 | if ( lan_transport->ConnectFailed() )
79 | {
80 | printf( "connect failed\n" );
81 | break;
82 | }
83 | }
84 |
85 | transport->Update( DeltaTime );
86 |
87 | wait_seconds( DeltaTime );
88 | }
89 |
90 | // shutdown
91 |
92 | Transport::Destroy( transport );
93 |
94 | Transport::Shutdown();
95 |
96 | return 0;
97 | }
98 |
--------------------------------------------------------------------------------
/06 - Real World Networking/Lobby.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Lobby Example using Transport Layer
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "NetPlatform.h"
13 | #include "NetTransport.h"
14 |
15 | using namespace std;
16 | using namespace net;
17 |
18 | int main( int argc, char * argv[] )
19 | {
20 | // initialize and create transport
21 |
22 | TransportType type = Transport_LAN;
23 |
24 | if ( !Transport::Initialize( Transport_LAN ) )
25 | {
26 | printf( "failed to initialize transport layer\n" );
27 | return 1;
28 | }
29 |
30 | Transport * transport = Transport::Create();
31 |
32 | if ( !transport )
33 | {
34 | printf( "could not create transport\n" );
35 | return 1;
36 | }
37 |
38 | // enter lobby (transport specific)
39 |
40 | switch ( type )
41 | {
42 | case Transport_LAN:
43 | {
44 | TransportLAN * lan_transport = dynamic_cast( transport );
45 | lan_transport->EnterLobby();
46 | }
47 | break;
48 |
49 | default:
50 | break;
51 | }
52 |
53 | // main loop
54 |
55 | const float DeltaTime = 1.0f / 30.0f;
56 |
57 | float accumulator = 0.0f;
58 |
59 | while ( true )
60 | {
61 | accumulator += DeltaTime;
62 |
63 | while ( accumulator >= 1.5f )
64 | {
65 | switch ( type )
66 | {
67 | case Transport_LAN:
68 | {
69 | TransportLAN * lan_transport = dynamic_cast( transport );
70 | printf( "---------------------------------------------\n" );
71 | const int entryCount = lan_transport->GetLobbyEntryCount();
72 | for ( int i = 0; i < entryCount; ++i )
73 | {
74 | TransportLAN::LobbyEntry entry;
75 | if ( lan_transport->GetLobbyEntryAtIndex( i, entry ) )
76 | printf( "%s -> %s\n", entry.name, entry.address );
77 | }
78 | printf( "---------------------------------------------\n" );
79 | }
80 | break;
81 |
82 | default:
83 | break;
84 | }
85 |
86 | accumulator -= 1.5f;
87 | }
88 |
89 | transport->Update( DeltaTime );
90 |
91 | wait_seconds( DeltaTime );
92 | }
93 |
94 | // shutdown
95 |
96 | Transport::Destroy( transport );
97 |
98 | Transport::Shutdown();
99 |
100 | return 0;
101 | }
102 |
--------------------------------------------------------------------------------
/06 - Real World Networking/NetFlowControl.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple Network Library from "Networking for Game Programmers"
3 | http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #ifndef NET_FLOW_CONTROL_H
8 | #define NET_FLOW_CONTROL_H
9 |
10 | namespace net
11 | {
12 | // simple binary flow control
13 | // + two modes of operation: good and bad mode
14 | // + if RTT exceeds 250ms drop to bad mode immediately
15 | // + if RTT is under 250ms for a period of time, return to good mode
16 |
17 | class FlowControl
18 | {
19 | public:
20 |
21 | FlowControl()
22 | {
23 | printf( "flow control initialized\n" );
24 | Reset();
25 | }
26 |
27 | void Reset()
28 | {
29 | mode = Bad;
30 | penalty_time = 4.0f;
31 | good_conditions_time = 0.0f;
32 | penalty_reduction_accumulator = 0.0f;
33 | }
34 |
35 | void Update( float deltaTime, float rtt )
36 | {
37 | const float RTT_Threshold = 250.0f;
38 |
39 | if ( mode == Good )
40 | {
41 | if ( rtt > RTT_Threshold )
42 | {
43 | printf( "*** dropping to bad mode ***\n" );
44 | mode = Bad;
45 | if ( good_conditions_time < 10.0f && penalty_time < 60.0f )
46 | {
47 | penalty_time *= 2.0f;
48 | if ( penalty_time > 60.0f )
49 | penalty_time = 60.0f;
50 | printf( "penalty time increased to %.1f\n", penalty_time );
51 | }
52 | good_conditions_time = 0.0f;
53 | penalty_reduction_accumulator = 0.0f;
54 | return;
55 | }
56 |
57 | good_conditions_time += deltaTime;
58 | penalty_reduction_accumulator += deltaTime;
59 |
60 | if ( penalty_reduction_accumulator > 10.0f && penalty_time > 1.0f )
61 | {
62 | penalty_time /= 2.0f;
63 | if ( penalty_time < 1.0f )
64 | penalty_time = 1.0f;
65 | printf( "penalty time reduced to %.1f\n", penalty_time );
66 | penalty_reduction_accumulator = 0.0f;
67 | }
68 | }
69 |
70 | if ( mode == Bad )
71 | {
72 | if ( rtt <= RTT_Threshold )
73 | good_conditions_time += deltaTime;
74 | else
75 | good_conditions_time = 0.0f;
76 |
77 | if ( good_conditions_time > penalty_time )
78 | {
79 | printf( "*** upgrading to good mode ***\n" );
80 | good_conditions_time = 0.0f;
81 | penalty_reduction_accumulator = 0.0f;
82 | mode = Good;
83 | return;
84 | }
85 | }
86 | }
87 |
88 | float GetSendRate()
89 | {
90 | return mode == Good ? 30.0f : 10.0f;
91 | }
92 |
93 | private:
94 |
95 | enum Mode
96 | {
97 | Good,
98 | Bad
99 | };
100 |
101 | Mode mode;
102 | float penalty_time;
103 | float good_conditions_time;
104 | float penalty_reduction_accumulator;
105 | };
106 | }
107 |
108 | #endif
109 |
--------------------------------------------------------------------------------
/06 - Real World Networking/NetPlatform.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple Network Library from "Networking for Game Programmers"
3 | http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #ifndef NET_PLATFORM_H
8 | #define NET_PLATFORM_H
9 |
10 | // platform detection
11 |
12 | #define PLATFORM_WINDOWS 1
13 | #define PLATFORM_MAC 2
14 | #define PLATFORM_UNIX 3
15 |
16 | #if defined(_WIN32)
17 | #define PLATFORM PLATFORM_WINDOWS
18 | #elif defined(__APPLE__)
19 | #define PLATFORM PLATFORM_MAC
20 | #else
21 | #define PLATFORM PLATFORM_UNIX
22 | #endif
23 |
24 | #ifndef PLATFORM
25 | #error unknown platform!
26 | #endif
27 |
28 | #include
29 | #include
30 |
31 |
32 | namespace net
33 | {
34 | // platform independent wait for n seconds
35 |
36 | #if PLATFORM == PLATFORM_WINDOWS
37 |
38 | #include
39 |
40 | inline void wait_seconds( float seconds )
41 | {
42 | Sleep(seconds * 1000.0f);
43 | }
44 |
45 | #else
46 |
47 | #include
48 |
49 | inline void wait_seconds( float seconds ) { usleep( (int) ( seconds * 1000000.0f ) ); }
50 |
51 | #endif
52 | }
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/06 - Real World Networking/Server.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Server Example using Transport Layer
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "NetPlatform.h"
13 | #include "NetTransport.h"
14 |
15 | using namespace std;
16 | using namespace net;
17 |
18 | int main( int argc, char * argv[] )
19 | {
20 | // initialize and create transport
21 |
22 | TransportType type = Transport_LAN;
23 |
24 | if ( !Transport::Initialize( Transport_LAN ) )
25 | {
26 | printf( "failed to initialize transport layer\n" );
27 | return 1;
28 | }
29 |
30 | Transport * transport = Transport::Create();
31 |
32 | if ( !transport )
33 | {
34 | printf( "could not create transport\n" );
35 | return 1;
36 | }
37 |
38 | // start server (transport specific)
39 |
40 | switch ( type )
41 | {
42 | case Transport_LAN:
43 | {
44 | TransportLAN * lan_transport = dynamic_cast( transport );
45 | char hostname[64+1] = "hostname";
46 | TransportLAN::GetHostName( hostname, sizeof(hostname) );
47 | lan_transport->StartServer( hostname );
48 | }
49 | break;
50 |
51 | default:
52 | break;
53 | }
54 |
55 | // main loop
56 |
57 | const float DeltaTime = 1.0f / 30.0f;
58 |
59 | while ( true )
60 | {
61 | transport->Update( DeltaTime );
62 | wait_seconds( DeltaTime );
63 | }
64 |
65 | // shutdown
66 |
67 | Transport::Destroy( transport );
68 |
69 | Transport::Shutdown();
70 |
71 | return 0;
72 | }
73 |
--------------------------------------------------------------------------------
/06 - Real World Networking/Test.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Unit Tests for Networking Library
3 | From "Networking for Game Programmers" - http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #include "NetTransport.h"
8 |
9 | int main( int argc, char * argv[] )
10 | {
11 | net::TransportLAN::UnitTest();
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/06 - Real World Networking/lan/NetAddress.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple Network Library from "Networking for Game Programmers"
3 | http://www.gafferongames.com/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #ifndef NET_ADDRESS_H
8 | #define NET_ADDRESS_H
9 |
10 | namespace net
11 | {
12 | // internet address
13 |
14 | class Address
15 | {
16 | public:
17 |
18 | Address()
19 | {
20 | address = 0;
21 | port = 0;
22 | }
23 |
24 | Address( unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned short port )
25 | {
26 | this->address = ( a << 24 ) | ( b << 16 ) | ( c << 8 ) | d;
27 | this->port = port;
28 | }
29 |
30 | Address( unsigned int address, unsigned short port )
31 | {
32 | this->address = address;
33 | this->port = port;
34 | }
35 |
36 | unsigned int GetAddress() const
37 | {
38 | return address;
39 | }
40 |
41 | unsigned char GetA() const
42 | {
43 | return ( unsigned char ) ( address >> 24 );
44 | }
45 |
46 | unsigned char GetB() const
47 | {
48 | return ( unsigned char ) ( address >> 16 );
49 | }
50 |
51 | unsigned char GetC() const
52 | {
53 | return ( unsigned char ) ( address >> 8 );
54 | }
55 |
56 | unsigned char GetD() const
57 | {
58 | return ( unsigned char ) ( address );
59 | }
60 |
61 | unsigned short GetPort() const
62 | {
63 | return port;
64 | }
65 |
66 | bool operator == ( const Address & other ) const
67 | {
68 | return address == other.address && port == other.port;
69 | }
70 |
71 | bool operator != ( const Address & other ) const
72 | {
73 | return ! ( *this == other );
74 | }
75 |
76 | bool operator < ( const Address & other ) const
77 | {
78 | // note: this is so we can use address as a key in std::map
79 | if ( address < other.address )
80 | return true;
81 | if ( address > other.address )
82 | return false;
83 | else
84 | return port < other.port;
85 | }
86 |
87 | private:
88 |
89 | unsigned int address;
90 | unsigned short port;
91 | };
92 | }
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/06 - Real World Networking/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -DDEBUG # -O3
4 |
5 | net_headers := $(wildcard *.h)
6 | lan_headers := $(wildcard lan/*.h)
7 |
8 | all : Client Server Test
9 |
10 | NetTransport.o : makefile NetTransport.h NetTransport.cpp NetPlatform.h ${lan_headers}
11 | g++ NetTransport.cpp -c -o NetTransport.o ${flags}
12 |
13 | libtransport.a : NetTransport.o
14 | ar rcs libtransport.a NetTransport.o
15 |
16 | % : %.cpp libtransport.a #{net_headers}
17 | g++ $< -o $@ -L. -ltransport ${flags}
18 |
19 | transport : libtransport.a
20 |
21 | client : Client
22 | ./Client
23 |
24 | server : Server
25 | ./Server
26 |
27 | lobby : Lobby
28 | ./Lobby
29 |
30 | test : Test
31 | ./Test
32 |
33 | clean:
34 | rm -f Client Server Lobby Test *.o *.a
35 |
--------------------------------------------------------------------------------
/06 - Real World Networking/vs2012/RealWorldNetwork.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test\Test.vcxproj", "{8D2D781E-B673-4D04-9EF7-1671D9681A93}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {8D2D781E-B673-4D04-9EF7-1671D9681A93}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {8D2D781E-B673-4D04-9EF7-1671D9681A93}.Debug|Win32.Build.0 = Debug|Win32
14 | {8D2D781E-B673-4D04-9EF7-1671D9681A93}.Release|Win32.ActiveCfg = Release|Win32
15 | {8D2D781E-B673-4D04-9EF7-1671D9681A93}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/06 - Real World Networking/vs2012/Test/Test.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {8D2D781E-B673-4D04-9EF7-1671D9681A93}
15 | Test
16 |
17 |
18 |
19 | Application
20 | true
21 | v110
22 | MultiByte
23 |
24 |
25 | Application
26 | false
27 | v110
28 | true
29 | MultiByte
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Level3
45 | Disabled
46 | true
47 |
48 |
49 | true
50 |
51 |
52 |
53 |
54 | Level3
55 | MaxSpeed
56 | true
57 | true
58 | true
59 |
60 |
61 | true
62 | true
63 | true
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/06 - Real World Networking/vs2012/Test/Test.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 | Header Files
46 |
47 |
48 | Header Files
49 |
50 |
51 |
--------------------------------------------------------------------------------
/07 - Reading and Writing Packets/Example.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Example.cpp
7 | documents
8 |
9 |
10 | filename
11 | makefile
12 | lastUsed
13 | 2008-10-30T17:17:05Z
14 |
15 |
16 | filename
17 | NetStream.h
18 | lastUsed
19 | 2008-11-16T20:46:33Z
20 |
21 |
22 | filename
23 | Test.cpp
24 | lastUsed
25 | 2008-10-30T17:17:05Z
26 |
27 |
28 | filename
29 | Example.cpp
30 | lastUsed
31 | 2008-11-16T20:46:33Z
32 | selected
33 |
34 |
35 |
36 | fileHierarchyDrawerWidth
37 | 142
38 | metaData
39 |
40 | Example.cpp
41 |
42 | caret
43 |
44 | column
45 | 2
46 | line
47 | 290
48 |
49 | firstVisibleColumn
50 | 0
51 | firstVisibleLine
52 | 282
53 |
54 | NetStream.h
55 |
56 | caret
57 |
58 | column
59 | 3
60 | line
61 | 321
62 |
63 | firstVisibleColumn
64 | 0
65 | firstVisibleLine
66 | 309
67 |
68 |
69 | openDocuments
70 |
71 | NetStream.h
72 | Example.cpp
73 |
74 | showFileHierarchyDrawer
75 |
76 | windowFrame
77 | {{153, 4}, {1127, 774}}
78 |
79 |
80 |
--------------------------------------------------------------------------------
/07 - Reading and Writing Packets/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -Wall -DDEBUG # -O3
4 |
5 | % : %.cpp NetStream.h
6 | g++ $< -o $@ ${flags}
7 |
8 | all : Example Test
9 |
10 | example : Example
11 | ./Example
12 |
13 | test : Test
14 | ./Test
15 |
16 | clean:
17 | rm -f Client Server Test
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # netgame
2 | Automatically exported from code.google.com/p/netgame
3 |
4 | The above. Basically a fork from a dead project by Glenn Fiedler at http://gafferongames.com/.
5 | He posted on his site that he no longer has time to monitor and work with the code. He also posted that
6 | his code is Public Domain. I intend to keep this code updated as best I can. It's very useful for games and such.
7 |
8 | Starting with Windows, then Linux (if possible), and ending with Mac (if I can get it).
--------------------------------------------------------------------------------
/XX - Authority Management/Authority.tmproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | currentDocument
6 | Authority.cpp
7 | documents
8 |
9 |
10 | name
11 | ode
12 | regexFolderFilter
13 | !.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
14 | sourceDirectory
15 | ode
16 |
17 |
18 | filename
19 | makefile
20 | lastUsed
21 | 2008-10-31T02:44:09Z
22 |
23 |
24 | filename
25 | Display.h
26 | lastUsed
27 | 2008-11-01T05:08:59Z
28 |
29 |
30 | filename
31 | Platform.h
32 | lastUsed
33 | 2008-11-01T05:08:55Z
34 |
35 |
36 | filename
37 | Mathematics.h
38 | lastUsed
39 | 2008-10-31T02:44:10Z
40 |
41 |
42 | filename
43 | NetStream.h
44 | lastUsed
45 | 2008-10-31T02:44:10Z
46 |
47 |
48 | filename
49 | Authority.cpp
50 | lastUsed
51 | 2008-11-11T16:26:50Z
52 | selected
53 |
54 |
55 |
56 | fileHierarchyDrawerWidth
57 | 142
58 | metaData
59 |
60 | Authority.cpp
61 |
62 | caret
63 |
64 | column
65 | 0
66 | line
67 | 771
68 |
69 | firstVisibleColumn
70 | 0
71 | firstVisibleLine
72 | 748
73 |
74 | Display.h
75 |
76 | caret
77 |
78 | column
79 | 0
80 | line
81 | 767
82 |
83 | firstVisibleColumn
84 | 0
85 | firstVisibleLine
86 | 748
87 |
88 | Platform.h
89 |
90 | caret
91 |
92 | column
93 | 0
94 | line
95 | 0
96 |
97 | firstVisibleColumn
98 | 0
99 | firstVisibleLine
100 | 0
101 |
102 |
103 | openDocuments
104 |
105 | Authority.cpp
106 | Platform.h
107 | Display.h
108 |
109 | showFileHierarchyDrawer
110 |
111 | windowFrame
112 | {{152, 4}, {1127, 774}}
113 |
114 |
115 |
--------------------------------------------------------------------------------
/XX - Authority Management/Platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple Network Library from "Networking for Game Programmers"
3 | http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #ifndef NET_PLATFORM_H
8 | #define NET_PLATFORM_H
9 |
10 | // platform detection
11 |
12 | #define PLATFORM_WINDOWS 1
13 | #define PLATFORM_MAC 2
14 | #define PLATFORM_UNIX 3
15 |
16 | #if defined(_WIN32)
17 | #define PLATFORM PLATFORM_WINDOWS
18 | #elif defined(__APPLE__)
19 | #define PLATFORM PLATFORM_MAC
20 | #else
21 | #define PLATFORM PLATFORM_UNIX
22 | #endif
23 |
24 | #ifndef PLATFORM
25 | #error unknown platform!
26 | #endif
27 |
28 |
29 | #include
30 | #include
31 | #include
32 |
33 | namespace net
34 | {
35 | // platform independent wait for n seconds
36 |
37 | #if PLATFORM == PLATFORM_WINDOWS
38 |
39 | inline void wait_seconds( float seconds )
40 | {
41 | Sleep( (int) ( seconds * 1000.0f ) );
42 | }
43 |
44 | #else
45 |
46 | inline void wait_seconds( float seconds ) { usleep( (int) ( seconds * 1000000.0f ) ); }
47 |
48 | #endif
49 |
50 | // helper functions for reading and writing integer values to packets
51 |
52 | inline void WriteByte( unsigned char * data, unsigned char value )
53 | {
54 | *data = value;
55 | }
56 |
57 | inline void ReadByte( const unsigned char * data, unsigned char & value )
58 | {
59 | value = *data;
60 | }
61 |
62 | inline void WriteShort( unsigned char * data, unsigned short value )
63 | {
64 | data[0] = (unsigned char) ( ( value >> 8 ) & 0xFF );
65 | data[1] = (unsigned char) ( value & 0xFF );
66 | }
67 |
68 | inline void ReadShort( const unsigned char * data, unsigned short & value )
69 | {
70 | value = ( ( (unsigned int)data[0] << 8 ) | ( (unsigned int)data[1] ) );
71 | }
72 |
73 | inline void WriteInteger( unsigned char * data, unsigned int value )
74 | {
75 | data[0] = (unsigned char) ( value >> 24 );
76 | data[1] = (unsigned char) ( ( value >> 16 ) & 0xFF );
77 | data[2] = (unsigned char) ( ( value >> 8 ) & 0xFF );
78 | data[3] = (unsigned char) ( value & 0xFF );
79 | }
80 |
81 | inline void ReadInteger( const unsigned char * data, unsigned int & value )
82 | {
83 | value = ( ( (unsigned int)data[0] << 24 ) | ( (unsigned int)data[1] << 16 ) |
84 | ( (unsigned int)data[2] << 8 ) | ( (unsigned int)data[3] ) );
85 | }
86 | }
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/XX - Authority Management/makefile:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -msse3 -mfpmath=sse -march=prescott -O3 -Wall -Iode
4 | #flags = -Wall -Iode -DDEBUG
5 |
6 | libs = -Lode -lode -lruby
7 | frameworks = -framework Carbon -framework OpenGL -framework AGL
8 |
9 | % : %.cpp Display.h Platform.h Mathematics.h NetStream.h
10 | g++ $< -o $@ ${flags} ${libs} ${frameworks}
11 |
12 | %.app : %
13 | rm -rf $<.app
14 | mkdir $<.app
15 | mkdir $<.app/Contents
16 | mkdir $<.app/Contents/MacOS
17 | cp $< $<.app/Contents/MacOS/
18 |
19 | authority : Authority.app Authority
20 | open Authority.app
21 |
22 | all : authority
23 |
24 | clean:
25 | rm -rf Authority Authority.app
--------------------------------------------------------------------------------
/XX - Authority Management/ode/collision_space.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_COLLISION_SPACE_H_
24 | #define _ODE_COLLISION_SPACE_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | struct dContactGeom;
33 |
34 | /**
35 | * @brief User callback for geom-geom collision testing.
36 | *
37 | * @param data The user data object, as passed to dSpaceCollide.
38 | * @param o1 The first geom being tested.
39 | * @param o2 The second geom being test.
40 | *
41 | * @remarks The callback function can call dCollide on o1 and o2 to generate
42 | * contact points between each pair. Then these contact points may be added
43 | * to the simulation as contact joints. The user's callback function can of
44 | * course chose not to call dCollide for any pair, e.g. if the user decides
45 | * that those pairs should not interact.
46 | *
47 | * @ingroup collide
48 | */
49 | typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
50 |
51 |
52 | ODE_API dSpaceID dSimpleSpaceCreate (dSpaceID space);
53 | ODE_API dSpaceID dHashSpaceCreate (dSpaceID space);
54 | ODE_API dSpaceID dQuadTreeSpaceCreate (dSpaceID space, dVector3 Center, dVector3 Extents, int Depth);
55 |
56 |
57 | // SAP
58 | // Order XZY or ZXY usually works best, if your Y is up.
59 | #define dSAP_AXES_XYZ ((0)|(1<<2)|(2<<4))
60 | #define dSAP_AXES_XZY ((0)|(2<<2)|(1<<4))
61 | #define dSAP_AXES_YXZ ((1)|(0<<2)|(2<<4))
62 | #define dSAP_AXES_YZX ((1)|(2<<2)|(0<<4))
63 | #define dSAP_AXES_ZXY ((2)|(0<<2)|(1<<4))
64 | #define dSAP_AXES_ZYX ((2)|(1<<2)|(0<<4))
65 |
66 | ODE_API dSpaceID dSweepAndPruneSpaceCreate( dSpaceID space, int axisorder );
67 |
68 |
69 |
70 | ODE_API void dSpaceDestroy (dSpaceID);
71 |
72 | ODE_API void dHashSpaceSetLevels (dSpaceID space, int minlevel, int maxlevel);
73 | ODE_API void dHashSpaceGetLevels (dSpaceID space, int *minlevel, int *maxlevel);
74 |
75 | ODE_API void dSpaceSetCleanup (dSpaceID space, int mode);
76 | ODE_API int dSpaceGetCleanup (dSpaceID space);
77 |
78 | ODE_API void dSpaceAdd (dSpaceID, dGeomID);
79 | ODE_API void dSpaceRemove (dSpaceID, dGeomID);
80 | ODE_API int dSpaceQuery (dSpaceID, dGeomID);
81 | ODE_API void dSpaceClean (dSpaceID);
82 | ODE_API int dSpaceGetNumGeoms (dSpaceID);
83 | ODE_API dGeomID dSpaceGetGeom (dSpaceID, int i);
84 |
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/compatibility.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_COMPATIBILITY_H_
24 | #define _ODE_COMPATIBILITY_H_
25 |
26 | /*
27 | * ODE's backward compatibility system ensures that as ODE's API
28 | * evolves, user code will not break.
29 | */
30 |
31 | /*
32 | * These new rotation function names are more consistent with the
33 | * rest of the API.
34 | */
35 | #define dQtoR(q,R) dRfromQ((R),(q))
36 | #define dRtoQ(R,q) dQfromR((q),(R))
37 | #define dWtoDQ(w,q,dq) dDQfromW((dq),(w),(q))
38 |
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/contact.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_CONTACT_H_
24 | #define _ODE_CONTACT_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 |
33 | enum {
34 | dContactMu2 = 0x001,
35 | dContactFDir1 = 0x002,
36 | dContactBounce = 0x004,
37 | dContactSoftERP = 0x008,
38 | dContactSoftCFM = 0x010,
39 | dContactMotion1 = 0x020,
40 | dContactMotion2 = 0x040,
41 | dContactSlip1 = 0x080,
42 | dContactSlip2 = 0x100,
43 |
44 | dContactApprox0 = 0x0000,
45 | dContactApprox1_1 = 0x1000,
46 | dContactApprox1_2 = 0x2000,
47 | dContactApprox1 = 0x3000
48 | };
49 |
50 |
51 | typedef struct dSurfaceParameters {
52 | /* must always be defined */
53 | int mode;
54 | dReal mu;
55 |
56 | /* only defined if the corresponding flag is set in mode */
57 | dReal mu2;
58 | dReal bounce;
59 | dReal bounce_vel;
60 | dReal soft_erp;
61 | dReal soft_cfm;
62 | dReal motion1,motion2;
63 | dReal slip1,slip2;
64 | } dSurfaceParameters;
65 |
66 |
67 | /**
68 | * @brief Describe the contact point between two geoms.
69 | *
70 | * If two bodies touch, or if a body touches a static feature in its
71 | * environment, the contact is represented by one or more "contact
72 | * points", described by dContactGeom.
73 | *
74 | * The convention is that if body 1 is moved along the normal vector by
75 | * a distance depth (or equivalently if body 2 is moved the same distance
76 | * in the opposite direction) then the contact depth will be reduced to
77 | * zero. This means that the normal vector points "in" to body 1.
78 | *
79 | * @ingroup collide
80 | */
81 | typedef struct dContactGeom {
82 | dVector3 pos; ///< contact position
83 | dVector3 normal; ///< normal vector
84 | dReal depth; ///< penetration depth
85 | dGeomID g1,g2; ///< the colliding geoms
86 | int side1,side2; ///< (to be documented)
87 | } dContactGeom;
88 |
89 |
90 | /* contact info used by contact joint */
91 |
92 | typedef struct dContact {
93 | dSurfaceParameters surface;
94 | dContactGeom geom;
95 | dVector3 fdir1;
96 | } dContact;
97 |
98 |
99 | #ifdef __cplusplus
100 | }
101 | #endif
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/error.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* this comes from the `reuse' library. copy any changes back to the source */
24 |
25 | #ifndef _ODE_ERROR_H_
26 | #define _ODE_ERROR_H_
27 |
28 | #include
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* all user defined error functions have this type. error and debug functions
35 | * should not return.
36 | */
37 | typedef void dMessageFunction (int errnum, const char *msg, va_list ap);
38 |
39 | /* set a new error, debug or warning handler. if fn is 0, the default handlers
40 | * are used.
41 | */
42 | ODE_API void dSetErrorHandler (dMessageFunction *fn);
43 | ODE_API void dSetDebugHandler (dMessageFunction *fn);
44 | ODE_API void dSetMessageHandler (dMessageFunction *fn);
45 |
46 | /* return the current error, debug or warning handler. if the return value is
47 | * 0, the default handlers are in place.
48 | */
49 | ODE_API dMessageFunction *dGetErrorHandler(void);
50 | ODE_API dMessageFunction *dGetDebugHandler(void);
51 | ODE_API dMessageFunction *dGetMessageHandler(void);
52 |
53 | /* generate a fatal error, debug trap or a message. */
54 | ODE_API void dError (int num, const char *msg, ...);
55 | ODE_API void dDebug (int num, const char *msg, ...);
56 | ODE_API void dMessage (int num, const char *msg, ...);
57 |
58 |
59 | #ifdef __cplusplus
60 | }
61 | #endif
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/export-dif.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_EXPORT_DIF_
24 | #define _ODE_EXPORT_DIF_
25 |
26 | #include
27 |
28 |
29 | ODE_API void dWorldExportDIF (dWorldID w, FILE *file, const char *world_name);
30 |
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/libode.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Authority Management/ode/libode.a
--------------------------------------------------------------------------------
/XX - Authority Management/ode/memory.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* this comes from the `reuse' library. copy any changes back to the source */
24 |
25 | #ifndef _ODE_MEMORY_H_
26 | #define _ODE_MEMORY_H_
27 |
28 | #include "config.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* function types to allocate and free memory */
35 | typedef void * dAllocFunction (size_t size);
36 | typedef void * dReallocFunction (void *ptr, size_t oldsize, size_t newsize);
37 | typedef void dFreeFunction (void *ptr, size_t size);
38 |
39 | /* set new memory management functions. if fn is 0, the default handlers are
40 | * used. */
41 | ODE_API void dSetAllocHandler (dAllocFunction *fn);
42 | ODE_API void dSetReallocHandler (dReallocFunction *fn);
43 | ODE_API void dSetFreeHandler (dFreeFunction *fn);
44 |
45 | /* get current memory management functions */
46 | ODE_API dAllocFunction *dGetAllocHandler (void);
47 | ODE_API dReallocFunction *dGetReallocHandler (void);
48 | ODE_API dFreeFunction *dGetFreeHandler (void);
49 |
50 | /* allocate and free memory. */
51 | ODE_API void * dAlloc (size_t size);
52 | ODE_API void * dRealloc (void *ptr, size_t oldsize, size_t newsize);
53 | ODE_API void dFree (void *ptr, size_t size);
54 |
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/misc.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* miscellaneous math functions. these are mostly useful for testing */
24 |
25 | #ifndef _ODE_MISC_H_
26 | #define _ODE_MISC_H_
27 |
28 | #include
29 |
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 |
36 | /* return 1 if the random number generator is working. */
37 | ODE_API int dTestRand(void);
38 |
39 | /* return next 32 bit random number. this uses a not-very-random linear
40 | * congruential method.
41 | */
42 | ODE_API unsigned long dRand(void);
43 |
44 | /* get and set the current random number seed. */
45 | ODE_API unsigned long dRandGetSeed(void);
46 | ODE_API void dRandSetSeed (unsigned long s);
47 |
48 | /* return a random integer between 0..n-1. the distribution will get worse
49 | * as n approaches 2^32.
50 | */
51 | ODE_API int dRandInt (int n);
52 |
53 | /* return a random real number between 0..1 */
54 | ODE_API dReal dRandReal(void);
55 |
56 | /* print out a matrix */
57 | #ifdef __cplusplus
58 | ODE_API void dPrintMatrix (const dReal *A, int n, int m, char *fmt = "%10.4f ",
59 | FILE *f=stdout);
60 | #else
61 | ODE_API void dPrintMatrix (const dReal *A, int n, int m, char *fmt, FILE *f);
62 | #endif
63 |
64 | /* make a random vector with entries between +/- range. A has n elements. */
65 | ODE_API void dMakeRandomVector (dReal *A, int n, dReal range);
66 |
67 | /* make a random matrix with entries between +/- range. A has size n*m. */
68 | ODE_API void dMakeRandomMatrix (dReal *A, int n, int m, dReal range);
69 |
70 | /* clear the upper triangle of a square matrix */
71 | ODE_API void dClearUpperTriangle (dReal *A, int n);
72 |
73 | /* return the maximum element difference between the two n*m matrices */
74 | ODE_API dReal dMaxDifference (const dReal *A, const dReal *B, int n, int m);
75 |
76 | /* return the maximum element difference between the lower triangle of two
77 | * n*n matrices */
78 | ODE_API dReal dMaxDifferenceLowerTriangle (const dReal *A, const dReal *B, int n);
79 |
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/ode.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_ODE_H_
24 | #define _ODE_ODE_H_
25 |
26 | /* include *everything* here */
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/ode.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Authority Management/ode/ode.lib
--------------------------------------------------------------------------------
/XX - Authority Management/ode/rotation.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_ROTATION_H_
24 | #define _ODE_ROTATION_H_
25 |
26 | #include
27 | #include
28 |
29 | #ifdef __cplusplus
30 | extern "C" {
31 | #endif
32 |
33 |
34 | ODE_API void dRSetIdentity (dMatrix3 R);
35 |
36 | ODE_API void dRFromAxisAndAngle (dMatrix3 R, dReal ax, dReal ay, dReal az,
37 | dReal angle);
38 |
39 | ODE_API void dRFromEulerAngles (dMatrix3 R, dReal phi, dReal theta, dReal psi);
40 |
41 | ODE_API void dRFrom2Axes (dMatrix3 R, dReal ax, dReal ay, dReal az,
42 | dReal bx, dReal by, dReal bz);
43 |
44 | ODE_API void dRFromZAxis (dMatrix3 R, dReal ax, dReal ay, dReal az);
45 |
46 | ODE_API void dQSetIdentity (dQuaternion q);
47 |
48 | ODE_API void dQFromAxisAndAngle (dQuaternion q, dReal ax, dReal ay, dReal az,
49 | dReal angle);
50 |
51 | /* Quaternion multiplication, analogous to the matrix multiplication routines. */
52 | /* qa = rotate by qc, then qb */
53 | ODE_API void dQMultiply0 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
54 | /* qa = rotate by qc, then by inverse of qb */
55 | ODE_API void dQMultiply1 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
56 | /* qa = rotate by inverse of qc, then by qb */
57 | ODE_API void dQMultiply2 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
58 | /* qa = rotate by inverse of qc, then by inverse of qb */
59 | ODE_API void dQMultiply3 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
60 |
61 | ODE_API void dRfromQ (dMatrix3 R, const dQuaternion q);
62 | ODE_API void dQfromR (dQuaternion q, const dMatrix3 R);
63 | ODE_API void dDQfromW (dReal dq[4], const dVector3 w, const dQuaternion q);
64 |
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/XX - Authority Management/ode/timer.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_TIMER_H_
24 | #define _ODE_TIMER_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 |
33 | /* stop watch objects */
34 |
35 | typedef struct dStopwatch {
36 | double time; /* total clock count */
37 | unsigned long cc[2]; /* clock count since last `start' */
38 | } dStopwatch;
39 |
40 | ODE_API void dStopwatchReset (dStopwatch *);
41 | ODE_API void dStopwatchStart (dStopwatch *);
42 | ODE_API void dStopwatchStop (dStopwatch *);
43 | ODE_API double dStopwatchTime (dStopwatch *); /* returns total time in secs */
44 |
45 |
46 | /* code timers */
47 |
48 | ODE_API void dTimerStart (const char *description); /* pass a static string here */
49 | ODE_API void dTimerNow (const char *description); /* pass a static string here */
50 | ODE_API void dTimerEnd(void);
51 |
52 | /* print out a timer report. if `average' is nonzero, print out the average
53 | * time for each slot (this is only meaningful if the same start-now-end
54 | * calls are being made repeatedly.
55 | */
56 | ODE_API void dTimerReport (FILE *fout, int average);
57 |
58 |
59 | /* resolution */
60 |
61 | /* returns the timer ticks per second implied by the timing hardware or API.
62 | * the actual timer resolution may not be this great.
63 | */
64 | ODE_API double dTimerTicksPerSecond(void);
65 |
66 | /* returns an estimate of the actual timer resolution, in seconds. this may
67 | * be greater than 1/ticks_per_second.
68 | */
69 | ODE_API double dTimerResolution(void);
70 |
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Common.h:
--------------------------------------------------------------------------------
1 | // Common data (avoids coupling)
2 |
3 | #ifndef COMMON_H
4 | #define COMMON_H
5 |
6 | // configuration
7 |
8 | const int DisplayWidth = 640;
9 | const int DisplayHeight = 480;
10 |
11 | const unsigned short ServerPort = 40001;
12 | const unsigned short ClientPort = 40002;
13 |
14 | const int RandomSeed = 21;
15 |
16 | const int MaxCubes = 64;
17 | const float ShadowDistance = 10.0f;
18 | const float ColorChangeTightness = 0.05f;
19 | const float GhostScale = 0.95f;
20 | const float Boundary = 10.0f;
21 |
22 | // simulation configuration
23 |
24 | struct SimulationConfiguration
25 | {
26 | float ERP;
27 | float CFM;
28 | int MaxIterations;
29 | float Gravity;
30 | float Friction;
31 | float Elasticity;
32 | float ContactSurfaceLayer;
33 | float MaximumCorrectingVelocity;
34 | bool QuickStep;
35 | int MaxCubes;
36 |
37 | SimulationConfiguration()
38 | {
39 | ERP = 0.001f;
40 | CFM = 0.001f;
41 | MaxIterations = 32;
42 | MaximumCorrectingVelocity = 100.0f;
43 | ContactSurfaceLayer = 0.001f;
44 | Elasticity = 0.8f;
45 | Friction = 15.0f;
46 | Gravity = 20.0f;
47 | QuickStep = true;
48 | MaxCubes = 32;
49 | }
50 | };
51 |
52 | // abstract render state
53 |
54 | struct RenderState
55 | {
56 | RenderState()
57 | {
58 | numCubes = 0;
59 | }
60 |
61 | struct Cube
62 | {
63 | math::Vector position;
64 | math::Quaternion orientation;
65 | float scale;
66 | float r,g,b,a;
67 | bool operator < ( const Cube & other ) const { return position.y > other.position.y; } // for back to front sort only!
68 | };
69 |
70 | struct HibernationArea
71 | {
72 | HibernationArea()
73 | {
74 | show = false;
75 | }
76 | bool show;
77 | math::Vector origin;
78 | float radius;
79 | float startAngle;
80 | float r,g,b,a;
81 | };
82 |
83 | unsigned int numCubes;
84 | Cube cubes[MaxCubes];
85 | HibernationArea hibernationArea;
86 | };
87 |
88 | // new simulation state
89 |
90 | struct SimulationCubeState
91 | {
92 | SimulationCubeState()
93 | {
94 | position = math::Vector(0,0,0);
95 | orientation = math::Quaternion(1,0,0,0);
96 | linearVelocity = math::Vector(0,0,0);
97 | angularVelocity = math::Vector(0,0,0);
98 | enabled = true;
99 | }
100 |
101 | math::Vector position;
102 | math::Quaternion orientation;
103 | math::Vector linearVelocity;
104 | math::Vector angularVelocity;
105 | bool enabled;
106 | };
107 |
108 | struct SimulationInitialCubeState : public SimulationCubeState
109 | {
110 | SimulationInitialCubeState()
111 | {
112 | scale = 1.0f;
113 | density = 1.0f;
114 | }
115 |
116 | float scale;
117 | float density;
118 | };
119 |
120 | #endif
121 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Database.rb:
--------------------------------------------------------------------------------
1 | require 'mysql'
2 |
3 | begin
4 |
5 | mysql = Mysql.new( 'localhost', 'testuser', 'testpass', 'test' )
6 |
7 | mysql.query "DROP TABLE IF EXISTS test_component"
8 |
9 | mysql.query "CREATE TABLE test_component
10 | (
11 | id INT,
12 | booleanProperty ENUM('true','false'),
13 | integerProperty INT,
14 | floatProperty FLOAT,
15 | vectorProperty_x FLOAT,
16 | vectorProperty_y FLOAT,
17 | vectorProperty_z FLOAT,
18 | quaternionProperty_w FLOAT,
19 | quaternionProperty_x FLOAT,
20 | quaternionProperty_y FLOAT,
21 | quaternionProperty_z FLOAT
22 | )
23 | "
24 | mysql.query "INSERT INTO test_component ( id, booleanProperty, integerProperty, floatProperty, vectorProperty_x, vectorProperty_y, vectorProperty_z, quaternionProperty_w, quaternionProperty_x, quaternionProperty_y, quaternionProperty_z )
25 | VALUES
26 | ( 1, 'true', 10, 1.25, 1,2,3, 1,0,0,0 ),
27 | ( 2, 'false', 15, 0.333, 0,0,1, 0,1,0,0 )
28 | "
29 |
30 | puts "Number of rows inserted: #{mysql.affected_rows}"
31 |
32 | results = mysql.query "SELECT * FROM test_component WHERE id = 1"
33 |
34 | results.each do |row|
35 | puts row.join(',')
36 | end
37 |
38 | puts "Number of rows returned: #{results.num_rows}"
39 |
40 | results.free
41 |
42 | rescue Mysql::Error => e
43 |
44 | puts "Error code: #{e.errno}"
45 | puts "Error message: #{e.error}"
46 | puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
47 |
48 | ensure
49 |
50 | mysql.close if mysql
51 |
52 | end
53 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Math.rb:
--------------------------------------------------------------------------------
1 | # math routines
2 |
3 | def float_quantize_clamp value, minimum, maximum, resolution
4 | value = minimum if value < minimum
5 | value = maximum if value > maximum
6 | index = ( ( value - minimum ) / resolution + 0.000001 ).floor
7 | minimum + resolution * index
8 | end
9 |
10 | class Vector
11 | attr_accessor :x, :y, :z
12 | def initialize x,y,z
13 | @x = x.to_f
14 | @y = y.to_f
15 | @z = z.to_f
16 | end
17 | def clamp min, max
18 | @x = min.x if @x < min.x
19 | @x = max.x if @x > max.x
20 | @y = min.y if @y < min.y
21 | @y = max.y if @y > max.y
22 | @z = min.z if @z < min.z
23 | @z = max.z if @z > max.z
24 | self
25 | end
26 | def quantize_clamp min, max, resolution
27 | @x = float_quantize_clamp @x, min.x, max.x, resolution.x
28 | @y = float_quantize_clamp @y, min.y, max.y, resolution.y
29 | @z = float_quantize_clamp @z, min.z, max.z, resolution.z
30 | self
31 | end
32 | def normalize
33 | lengthSquared = @x*@x + @y*@y + @z*@z
34 | length = Math.sqrt( lengthSquared )
35 | inverseLength = 1.0 / length
36 | @x = @x * inverseLength
37 | @y = @y * inverseLength
38 | @z = @z * inverseLength
39 | self
40 | end
41 | def + other
42 | Vector.new( @x + other.x, @y + other.y, @z + other.z )
43 | end
44 | def - other
45 | Vector.new( @x - other.x, @y - other.y, @z - other.z )
46 | end
47 | def length
48 | Math.sqrt( @x*@x + @y*@y + @z*@z )
49 | end
50 | def length2d
51 | Math.sqrt( @x*@x + @y*@y )
52 | end
53 | def to_s
54 | "(#{@x},#{@y},#{@z})"
55 | end
56 | end
57 |
58 | class Quaternion
59 | attr_accessor :w, :x, :y, :z
60 | def initialize w,x,y,z
61 | @w = w.to_f
62 | @x = x.to_f
63 | @y = y.to_f
64 | @z = z.to_f
65 | end
66 | def normalize
67 | lengthSquared = @w*@w + @x*@x + @y*@y + @z*@z
68 | length = Math.sqrt( lengthSquared )
69 | inverseLength = 1.0 / length
70 | @w = @w * inverseLength
71 | @x = @x * inverseLength
72 | @y = @y * inverseLength
73 | @z = @z * inverseLength
74 | self
75 | end
76 | def to_s
77 | "(#{@w},#{@x},#{@y},#{@z})"
78 | end
79 | end
80 |
81 | def random_float min, max
82 | rand * ( max - min ) + min
83 | end
84 |
85 | def random_vector min, max
86 | Vector.new( random_float( min.x, max.x ), random_float( min.y, max.y ), random_float( min.z, max.z ) )
87 | end
88 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Net.rb:
--------------------------------------------------------------------------------
1 | class Address
2 | attr_reader :a, :b, :c, :d, :port
3 | def initialize a,b,c,d,port
4 | @a = a
5 | @b = b
6 | @c = c
7 | @d = d
8 | @port = port
9 | end
10 | end
11 |
12 | class NetStream
13 | def reading?
14 | false
15 | end
16 | def writing?
17 | true
18 | end
19 | def serializeBoolean value
20 | value
21 | end
22 | def serializeByte value
23 | value
24 | end
25 | def serializeShort value
26 | value
27 | end
28 | def serializeInteger value
29 | value
30 | end
31 | def serializeFloat value
32 | value
33 | end
34 | end
35 |
36 | class NetObject
37 | attr_accessor :ident, :priority
38 | def initialize ident
39 | @ident = ident
40 | @priority = 0.0
41 | end
42 | def print
43 | puts "net object: #{ident} -> #{priority}"
44 | end
45 | end
46 |
47 | class NetObjectSet
48 | def initialize
49 | @map = Hash.new
50 | @objects = Array.new
51 | end
52 | def add object
53 | raise 'object is nil' if object == nil
54 | raise 'object already added' if @map[object.ident]
55 | @objects.push(object)
56 | @map[object.ident] = object
57 | end
58 | def remove object
59 | raise 'object is nil' if object == nil
60 | raise 'object does not exist' if @map[object.ident] == nil
61 | @objects.erase(object.ident)
62 | @map[object.ident] = nil
63 | end
64 | def sort
65 | @objects.sort! { |a,b| b.priority <=> a.priority }
66 | end
67 | def clear
68 | @objects = Array.new
69 | @map = Hash.new
70 | end
71 | def [] ident
72 | @map[ident]
73 | end
74 | def size
75 | @objects.size
76 | end
77 | def each
78 | @objects.each do |object|
79 | yield( object )
80 | end
81 | end
82 | end
83 |
84 | class Cube < NetObject
85 | def initialize ident
86 | super(ident)
87 | @x = 0.0
88 | @y = 0.0
89 | @z = 0.0
90 | end
91 | def print
92 | puts "cube #{ident}: priority = #{priority}"
93 | end
94 | def serialize stream
95 | @x = stream.serializeFloat @x
96 | @y = stream.serializeFloat @y
97 | @z = stream.serializeFloat @z
98 | end
99 | end
100 |
101 | def test_net
102 | a = Cube.new 0
103 | b = Cube.new 1
104 | c = Cube.new 2
105 | a.priority = 0.5
106 | b.priority = 1.0
107 | c.priority = 2.0
108 | objectSet = NetObjectSet.new
109 | objectSet.add a
110 | objectSet.add b
111 | objectSet.add c
112 | objectSet.sort
113 | objectSet.each do |object|
114 | object.print
115 | end
116 | stream = NetStream.new
117 | c.serialize stream
118 | end
119 |
120 | test_net if __FILE__ == $0
121 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Platform.h:
--------------------------------------------------------------------------------
1 | /*
2 | Simple Network Library from "Networking for Game Programmers"
3 | http://www.gaffer.org/networking-for-game-programmers
4 | Author: Glenn Fiedler
5 | */
6 |
7 | #ifndef NET_PLATFORM_H
8 | #define NET_PLATFORM_H
9 |
10 | // platform detection
11 |
12 | #define PLATFORM_WINDOWS 1
13 | #define PLATFORM_MAC 2
14 | #define PLATFORM_UNIX 3
15 |
16 | #if defined(_WIN32)
17 | #define PLATFORM PLATFORM_WINDOWS
18 | #elif defined(__APPLE__)
19 | #define PLATFORM PLATFORM_MAC
20 | #else
21 | #define PLATFORM PLATFORM_UNIX
22 | #endif
23 |
24 | #ifndef PLATFORM
25 | #error unknown platform!
26 | #endif
27 |
28 |
29 | #include
30 | #include
31 | #include
32 |
33 | namespace net
34 | {
35 | // platform independent wait for n seconds
36 |
37 | #if PLATFORM == PLATFORM_WINDOWS
38 |
39 | inline void wait_seconds( float seconds )
40 | {
41 | Sleep( (int) ( seconds * 1000.0f ) );
42 | }
43 |
44 | #else
45 |
46 | inline void wait_seconds( float seconds ) { usleep( (int) ( seconds * 1000000.0f ) ); }
47 |
48 | #endif
49 |
50 | // helper functions for reading and writing integer values to packets
51 |
52 | inline void WriteByte( unsigned char * data, unsigned char value )
53 | {
54 | *data = value;
55 | }
56 |
57 | inline void ReadByte( const unsigned char * data, unsigned char & value )
58 | {
59 | value = *data;
60 | }
61 |
62 | inline void WriteShort( unsigned char * data, unsigned short value )
63 | {
64 | data[0] = (unsigned char) ( ( value >> 8 ) & 0xFF );
65 | data[1] = (unsigned char) ( value & 0xFF );
66 | }
67 |
68 | inline void ReadShort( const unsigned char * data, unsigned short & value )
69 | {
70 | value = ( ( (unsigned int)data[0] << 8 ) | ( (unsigned int)data[1] ) );
71 | }
72 |
73 | inline void WriteInteger( unsigned char * data, unsigned int value )
74 | {
75 | data[0] = (unsigned char) ( value >> 24 );
76 | data[1] = (unsigned char) ( ( value >> 16 ) & 0xFF );
77 | data[2] = (unsigned char) ( ( value >> 8 ) & 0xFF );
78 | data[3] = (unsigned char) ( value & 0xFF );
79 | }
80 |
81 | inline void ReadInteger( const unsigned char * data, unsigned int & value )
82 | {
83 | value = ( ( (unsigned int)data[0] << 24 ) | ( (unsigned int)data[1] << 16 ) |
84 | ( (unsigned int)data[2] << 8 ) | ( (unsigned int)data[3] ) );
85 | }
86 | }
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Server:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Drop-In COOP for Open World Games/Server
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/Simulation.rb:
--------------------------------------------------------------------------------
1 | require 'Math'
2 | require 'Sandbox'
3 |
4 | class SimulationCubeState
5 | attr_accessor :position, :orientation, :linearVelocity, :angularVelocity, :enabled
6 | def initialize
7 | @position = Vector.new(0,0,0)
8 | @orientation = Quaternion.new(1,0,0,0)
9 | @linearVelocity = Vector.new(0,0,0)
10 | @angularVelocity = Vector.new(0,0,0)
11 | @enabled = true
12 | end
13 | end
14 |
15 | class SimulationInitialCubeState < SimulationCubeState
16 | attr_accessor :scale, :density
17 | def initialize
18 | @scale = 1.0
19 | @density = 1.0
20 | super
21 | end
22 | end
23 |
24 | def test_cube_add_remove
25 |
26 | simConfig =
27 | {
28 | :ERP => 0.001,
29 | :CFM => 0.001,
30 | :MaxIterations => 32,
31 | :MaximumCorrectingVelocity => 100.0,
32 | :ContactSurfaceLayer => 0.001,
33 | :Elasticity => 0.8,
34 | :Friction => 15.0,
35 | :Gravity => 20.0,
36 | :QuickStep => true,
37 | :MaxCubes => 32
38 | }
39 |
40 | simulation = Simulation.new simConfig
41 |
42 | simulation.addPlane Vector.new(0,0,1), 0
43 |
44 | puts '-------------------------------'
45 | cubes = Array.new
46 | 5.times do
47 | initialState = SimulationInitialCubeState.new
48 | initialState.position = random_vector Vector.new(-10,-10,2), Vector.new(+10,+10,4)
49 | cubes.push simulation.addCube( initialState )
50 | end
51 | cubes.each { |id| puts "cube id = #{id}" }
52 |
53 | simulation.removeCube 0
54 | simulation.removeCube 1
55 |
56 | puts '-------------------------------'
57 |
58 | cubes.slice!(0,2)
59 | 5.times { cubes.push simulation.addCube( nil ) }
60 | cubes.each { |id| puts "cube id = #{id}" }
61 |
62 | puts '-------------------------------'
63 | 5.times do
64 | simulation.update 1.0 / 60.0
65 | cubeState = simulation.getCubeState 0
66 | puts "update"
67 | end
68 |
69 | puts '-------------------------------'
70 | simulation.reset
71 | cubes = Array.new
72 | 5.times { cubes.push simulation.addCube( nil ) }
73 | cubes.each { |id| puts "cube id = #{id}" }
74 |
75 | puts '-------------------------------'
76 | Simulation.shutdown
77 |
78 | end
79 |
80 | def test_cube
81 |
82 | simConfig =
83 | {
84 | :ERP => 0.001,
85 | :CFM => 0.001,
86 | :MaxIterations => 32,
87 | :MaximumCorrectingVelocity => 100.0,
88 | :ContactSurfaceLayer => 0.001,
89 | :Elasticity => 0.8,
90 | :Friction => 15.0,
91 | :Gravity => 20.0,
92 | :QuickStep => true,
93 | :MaxCubes => 32
94 | }
95 |
96 | simulation = Simulation.new simConfig
97 |
98 | simulation.addPlane Vector.new(0,0,1), 0
99 |
100 | initialState = SimulationInitialCubeState.new
101 | initialState.position = Vector.new(0,0,10)
102 | simulation.addCube initialState
103 |
104 | 40.times do
105 | simulation.update 1.0 / 60.0
106 | cubeState = simulation.getCubeState 0
107 | puts "position = #{cubeState.position}"
108 | end
109 |
110 | Simulation.shutdown
111 |
112 | end
113 |
114 | test_cube if __FILE__ == $0
115 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/makefile.apple:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | flags = -msse3 -mfpmath=sse -march=prescott -O3 -Wall -Iode
4 | #flags = -Wall -Iode -DDEBUG
5 |
6 | headers := $(wildcard *.h)
7 | examples := $(patsubst %.cpp,%,$(wildcard *.cpp))
8 |
9 | libs := -Lode -lode -lruby
10 | frameworks := -framework Carbon -framework OpenGL -framework AGL
11 |
12 | all : ${examples} sandbox Client.app
13 |
14 | % : %.cpp makefile ${headers}
15 | g++ $< -o $@ ${flags} ${libs} ${frameworks}
16 |
17 | %.app : %
18 | rm -rf $<.app
19 | mkdir $<.app
20 | mkdir $<.app/Contents
21 | mkdir $<.app/Contents/MacOS
22 | cp $< $<.app/Contents/MacOS/
23 |
24 | client : Client
25 | ./Client
26 |
27 | client_app : Client.app
28 | open Client.app
29 |
30 | Sandbox.bundle : Sandbox.cpp ${headers}
31 | g++ Sandbox.cpp -dynamiclib -o Sandbox.bundle ${flags} ${libs} ${frameworks}
32 |
33 | sandbox : Sandbox.bundle
34 |
35 | clean:
36 | rm *.bundle
37 | rm -f ${examples}
38 | rm -rf *.app
39 | rm -f *.a
40 | rm game.xml
41 | rm export.xml
42 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/makefile.linux:
--------------------------------------------------------------------------------
1 | # makefile for linux
2 |
3 | flags = -O3 -Wall -Iode
4 | # flags = -Wall -Iode -DDEBUG
5 |
6 | headers := $(wildcard *.h)
7 | source := $(patsubst %.cpp,%,$(wildcard *.cpp))
8 |
9 | libs := -lruby
10 |
11 | % : %.cpp ${headers}
12 | g++ $< -o $@ ${flags} # ${libs}
13 |
14 | clean:
15 | rm -f ${source}
16 | rm -f *.a
17 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/collision_space.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_COLLISION_SPACE_H_
24 | #define _ODE_COLLISION_SPACE_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | struct dContactGeom;
33 |
34 | /**
35 | * @brief User callback for geom-geom collision testing.
36 | *
37 | * @param data The user data object, as passed to dSpaceCollide.
38 | * @param o1 The first geom being tested.
39 | * @param o2 The second geom being test.
40 | *
41 | * @remarks The callback function can call dCollide on o1 and o2 to generate
42 | * contact points between each pair. Then these contact points may be added
43 | * to the simulation as contact joints. The user's callback function can of
44 | * course chose not to call dCollide for any pair, e.g. if the user decides
45 | * that those pairs should not interact.
46 | *
47 | * @ingroup collide
48 | */
49 | typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2);
50 |
51 |
52 | ODE_API dSpaceID dSimpleSpaceCreate (dSpaceID space);
53 | ODE_API dSpaceID dHashSpaceCreate (dSpaceID space);
54 | ODE_API dSpaceID dQuadTreeSpaceCreate (dSpaceID space, dVector3 Center, dVector3 Extents, int Depth);
55 |
56 |
57 | // SAP
58 | // Order XZY or ZXY usually works best, if your Y is up.
59 | #define dSAP_AXES_XYZ ((0)|(1<<2)|(2<<4))
60 | #define dSAP_AXES_XZY ((0)|(2<<2)|(1<<4))
61 | #define dSAP_AXES_YXZ ((1)|(0<<2)|(2<<4))
62 | #define dSAP_AXES_YZX ((1)|(2<<2)|(0<<4))
63 | #define dSAP_AXES_ZXY ((2)|(0<<2)|(1<<4))
64 | #define dSAP_AXES_ZYX ((2)|(1<<2)|(0<<4))
65 |
66 | ODE_API dSpaceID dSweepAndPruneSpaceCreate( dSpaceID space, int axisorder );
67 |
68 |
69 |
70 | ODE_API void dSpaceDestroy (dSpaceID);
71 |
72 | ODE_API void dHashSpaceSetLevels (dSpaceID space, int minlevel, int maxlevel);
73 | ODE_API void dHashSpaceGetLevels (dSpaceID space, int *minlevel, int *maxlevel);
74 |
75 | ODE_API void dSpaceSetCleanup (dSpaceID space, int mode);
76 | ODE_API int dSpaceGetCleanup (dSpaceID space);
77 |
78 | ODE_API void dSpaceAdd (dSpaceID, dGeomID);
79 | ODE_API void dSpaceRemove (dSpaceID, dGeomID);
80 | ODE_API int dSpaceQuery (dSpaceID, dGeomID);
81 | ODE_API void dSpaceClean (dSpaceID);
82 | ODE_API int dSpaceGetNumGeoms (dSpaceID);
83 | ODE_API dGeomID dSpaceGetGeom (dSpaceID, int i);
84 |
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/compatibility.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_COMPATIBILITY_H_
24 | #define _ODE_COMPATIBILITY_H_
25 |
26 | /*
27 | * ODE's backward compatibility system ensures that as ODE's API
28 | * evolves, user code will not break.
29 | */
30 |
31 | /*
32 | * These new rotation function names are more consistent with the
33 | * rest of the API.
34 | */
35 | #define dQtoR(q,R) dRfromQ((R),(q))
36 | #define dRtoQ(R,q) dQfromR((q),(R))
37 | #define dWtoDQ(w,q,dq) dDQfromW((dq),(w),(q))
38 |
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/contact.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_CONTACT_H_
24 | #define _ODE_CONTACT_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 |
33 | enum {
34 | dContactMu2 = 0x001,
35 | dContactFDir1 = 0x002,
36 | dContactBounce = 0x004,
37 | dContactSoftERP = 0x008,
38 | dContactSoftCFM = 0x010,
39 | dContactMotion1 = 0x020,
40 | dContactMotion2 = 0x040,
41 | dContactSlip1 = 0x080,
42 | dContactSlip2 = 0x100,
43 |
44 | dContactApprox0 = 0x0000,
45 | dContactApprox1_1 = 0x1000,
46 | dContactApprox1_2 = 0x2000,
47 | dContactApprox1 = 0x3000
48 | };
49 |
50 |
51 | typedef struct dSurfaceParameters {
52 | /* must always be defined */
53 | int mode;
54 | dReal mu;
55 |
56 | /* only defined if the corresponding flag is set in mode */
57 | dReal mu2;
58 | dReal bounce;
59 | dReal bounce_vel;
60 | dReal soft_erp;
61 | dReal soft_cfm;
62 | dReal motion1,motion2;
63 | dReal slip1,slip2;
64 | } dSurfaceParameters;
65 |
66 |
67 | /**
68 | * @brief Describe the contact point between two geoms.
69 | *
70 | * If two bodies touch, or if a body touches a static feature in its
71 | * environment, the contact is represented by one or more "contact
72 | * points", described by dContactGeom.
73 | *
74 | * The convention is that if body 1 is moved along the normal vector by
75 | * a distance depth (or equivalently if body 2 is moved the same distance
76 | * in the opposite direction) then the contact depth will be reduced to
77 | * zero. This means that the normal vector points "in" to body 1.
78 | *
79 | * @ingroup collide
80 | */
81 | typedef struct dContactGeom {
82 | dVector3 pos; ///< contact position
83 | dVector3 normal; ///< normal vector
84 | dReal depth; ///< penetration depth
85 | dGeomID g1,g2; ///< the colliding geoms
86 | int side1,side2; ///< (to be documented)
87 | } dContactGeom;
88 |
89 |
90 | /* contact info used by contact joint */
91 |
92 | typedef struct dContact {
93 | dSurfaceParameters surface;
94 | dContactGeom geom;
95 | dVector3 fdir1;
96 | } dContact;
97 |
98 |
99 | #ifdef __cplusplus
100 | }
101 | #endif
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/error.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* this comes from the `reuse' library. copy any changes back to the source */
24 |
25 | #ifndef _ODE_ERROR_H_
26 | #define _ODE_ERROR_H_
27 |
28 | #include
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* all user defined error functions have this type. error and debug functions
35 | * should not return.
36 | */
37 | typedef void dMessageFunction (int errnum, const char *msg, va_list ap);
38 |
39 | /* set a new error, debug or warning handler. if fn is 0, the default handlers
40 | * are used.
41 | */
42 | ODE_API void dSetErrorHandler (dMessageFunction *fn);
43 | ODE_API void dSetDebugHandler (dMessageFunction *fn);
44 | ODE_API void dSetMessageHandler (dMessageFunction *fn);
45 |
46 | /* return the current error, debug or warning handler. if the return value is
47 | * 0, the default handlers are in place.
48 | */
49 | ODE_API dMessageFunction *dGetErrorHandler(void);
50 | ODE_API dMessageFunction *dGetDebugHandler(void);
51 | ODE_API dMessageFunction *dGetMessageHandler(void);
52 |
53 | /* generate a fatal error, debug trap or a message. */
54 | ODE_API void dError (int num, const char *msg, ...);
55 | ODE_API void dDebug (int num, const char *msg, ...);
56 | ODE_API void dMessage (int num, const char *msg, ...);
57 |
58 |
59 | #ifdef __cplusplus
60 | }
61 | #endif
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/export-dif.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_EXPORT_DIF_
24 | #define _ODE_EXPORT_DIF_
25 |
26 | #include
27 |
28 |
29 | ODE_API void dWorldExportDIF (dWorldID w, FILE *file, const char *world_name);
30 |
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/libode.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Drop-In COOP for Open World Games/ode/libode.a
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/memory.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* this comes from the `reuse' library. copy any changes back to the source */
24 |
25 | #ifndef _ODE_MEMORY_H_
26 | #define _ODE_MEMORY_H_
27 |
28 | #include "config.h"
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* function types to allocate and free memory */
35 | typedef void * dAllocFunction (size_t size);
36 | typedef void * dReallocFunction (void *ptr, size_t oldsize, size_t newsize);
37 | typedef void dFreeFunction (void *ptr, size_t size);
38 |
39 | /* set new memory management functions. if fn is 0, the default handlers are
40 | * used. */
41 | ODE_API void dSetAllocHandler (dAllocFunction *fn);
42 | ODE_API void dSetReallocHandler (dReallocFunction *fn);
43 | ODE_API void dSetFreeHandler (dFreeFunction *fn);
44 |
45 | /* get current memory management functions */
46 | ODE_API dAllocFunction *dGetAllocHandler (void);
47 | ODE_API dReallocFunction *dGetReallocHandler (void);
48 | ODE_API dFreeFunction *dGetFreeHandler (void);
49 |
50 | /* allocate and free memory. */
51 | ODE_API void * dAlloc (size_t size);
52 | ODE_API void * dRealloc (void *ptr, size_t oldsize, size_t newsize);
53 | ODE_API void dFree (void *ptr, size_t size);
54 |
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/misc.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | /* miscellaneous math functions. these are mostly useful for testing */
24 |
25 | #ifndef _ODE_MISC_H_
26 | #define _ODE_MISC_H_
27 |
28 | #include
29 |
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 |
36 | /* return 1 if the random number generator is working. */
37 | ODE_API int dTestRand(void);
38 |
39 | /* return next 32 bit random number. this uses a not-very-random linear
40 | * congruential method.
41 | */
42 | ODE_API unsigned long dRand(void);
43 |
44 | /* get and set the current random number seed. */
45 | ODE_API unsigned long dRandGetSeed(void);
46 | ODE_API void dRandSetSeed (unsigned long s);
47 |
48 | /* return a random integer between 0..n-1. the distribution will get worse
49 | * as n approaches 2^32.
50 | */
51 | ODE_API int dRandInt (int n);
52 |
53 | /* return a random real number between 0..1 */
54 | ODE_API dReal dRandReal(void);
55 |
56 | /* print out a matrix */
57 | #ifdef __cplusplus
58 | ODE_API void dPrintMatrix (const dReal *A, int n, int m, char *fmt = "%10.4f ",
59 | FILE *f=stdout);
60 | #else
61 | ODE_API void dPrintMatrix (const dReal *A, int n, int m, char *fmt, FILE *f);
62 | #endif
63 |
64 | /* make a random vector with entries between +/- range. A has n elements. */
65 | ODE_API void dMakeRandomVector (dReal *A, int n, dReal range);
66 |
67 | /* make a random matrix with entries between +/- range. A has size n*m. */
68 | ODE_API void dMakeRandomMatrix (dReal *A, int n, int m, dReal range);
69 |
70 | /* clear the upper triangle of a square matrix */
71 | ODE_API void dClearUpperTriangle (dReal *A, int n);
72 |
73 | /* return the maximum element difference between the two n*m matrices */
74 | ODE_API dReal dMaxDifference (const dReal *A, const dReal *B, int n, int m);
75 |
76 | /* return the maximum element difference between the lower triangle of two
77 | * n*n matrices */
78 | ODE_API dReal dMaxDifferenceLowerTriangle (const dReal *A, const dReal *B, int n);
79 |
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/ode.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_ODE_H_
24 | #define _ODE_ODE_H_
25 |
26 | /* include *everything* here */
27 |
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/ode.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Drop-In COOP for Open World Games/ode/ode.lib
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/rotation.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_ROTATION_H_
24 | #define _ODE_ROTATION_H_
25 |
26 | #include
27 | #include
28 |
29 | #ifdef __cplusplus
30 | extern "C" {
31 | #endif
32 |
33 |
34 | ODE_API void dRSetIdentity (dMatrix3 R);
35 |
36 | ODE_API void dRFromAxisAndAngle (dMatrix3 R, dReal ax, dReal ay, dReal az,
37 | dReal angle);
38 |
39 | ODE_API void dRFromEulerAngles (dMatrix3 R, dReal phi, dReal theta, dReal psi);
40 |
41 | ODE_API void dRFrom2Axes (dMatrix3 R, dReal ax, dReal ay, dReal az,
42 | dReal bx, dReal by, dReal bz);
43 |
44 | ODE_API void dRFromZAxis (dMatrix3 R, dReal ax, dReal ay, dReal az);
45 |
46 | ODE_API void dQSetIdentity (dQuaternion q);
47 |
48 | ODE_API void dQFromAxisAndAngle (dQuaternion q, dReal ax, dReal ay, dReal az,
49 | dReal angle);
50 |
51 | /* Quaternion multiplication, analogous to the matrix multiplication routines. */
52 | /* qa = rotate by qc, then qb */
53 | ODE_API void dQMultiply0 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
54 | /* qa = rotate by qc, then by inverse of qb */
55 | ODE_API void dQMultiply1 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
56 | /* qa = rotate by inverse of qc, then by qb */
57 | ODE_API void dQMultiply2 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
58 | /* qa = rotate by inverse of qc, then by inverse of qb */
59 | ODE_API void dQMultiply3 (dQuaternion qa, const dQuaternion qb, const dQuaternion qc);
60 |
61 | ODE_API void dRfromQ (dMatrix3 R, const dQuaternion q);
62 | ODE_API void dQfromR (dQuaternion q, const dMatrix3 R);
63 | ODE_API void dDQfromW (dReal dq[4], const dVector3 w, const dQuaternion q);
64 |
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/ode/timer.h:
--------------------------------------------------------------------------------
1 | /*************************************************************************
2 | * *
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 | * *
6 | * This library is free software; you can redistribute it and/or *
7 | * modify it under the terms of EITHER: *
8 | * (1) The GNU Lesser General Public License as published by the Free *
9 | * Software Foundation; either version 2.1 of the License, or (at *
10 | * your option) any later version. The text of the GNU Lesser *
11 | * General Public License is included with this library in the *
12 | * file LICENSE.TXT. *
13 | * (2) The BSD-style license that is included with this library in *
14 | * the file LICENSE-BSD.TXT. *
15 | * *
16 | * This library is distributed in the hope that it will be useful, *
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20 | * *
21 | *************************************************************************/
22 |
23 | #ifndef _ODE_TIMER_H_
24 | #define _ODE_TIMER_H_
25 |
26 | #include
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 |
33 | /* stop watch objects */
34 |
35 | typedef struct dStopwatch {
36 | double time; /* total clock count */
37 | unsigned long cc[2]; /* clock count since last `start' */
38 | } dStopwatch;
39 |
40 | ODE_API void dStopwatchReset (dStopwatch *);
41 | ODE_API void dStopwatchStart (dStopwatch *);
42 | ODE_API void dStopwatchStop (dStopwatch *);
43 | ODE_API double dStopwatchTime (dStopwatch *); /* returns total time in secs */
44 |
45 |
46 | /* code timers */
47 |
48 | ODE_API void dTimerStart (const char *description); /* pass a static string here */
49 | ODE_API void dTimerNow (const char *description); /* pass a static string here */
50 | ODE_API void dTimerEnd(void);
51 |
52 | /* print out a timer report. if `average' is nonzero, print out the average
53 | * time for each slot (this is only meaningful if the same start-now-end
54 | * calls are being made repeatedly.
55 | */
56 | ODE_API void dTimerReport (FILE *fout, int average);
57 |
58 |
59 | /* resolution */
60 |
61 | /* returns the timer ticks per second implied by the timing hardware or API.
62 | * the actual timer resolution may not be this great.
63 | */
64 | ODE_API double dTimerTicksPerSecond(void);
65 |
66 | /* returns an estimate of the actual timer resolution, in seconds. this may
67 | * be greater than 1/ticks_per_second.
68 | */
69 | ODE_API double dTimerResolution(void);
70 |
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | #endif
77 |
--------------------------------------------------------------------------------
/XX - Drop-In COOP for Open World Games/scene.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/Config.h:
--------------------------------------------------------------------------------
1 | /*
2 | Fiedler's Cubes
3 | Copyright © 2008-2009 Glenn Fiedler
4 | http://www.gafferongames.com/fiedlers-cubes
5 | */
6 |
7 | #ifndef CONFIG_H
8 | #define CONFIG_H
9 |
10 | // platform detection
11 |
12 | #define PLATFORM_WINDOWS 1
13 | #define PLATFORM_MAC 2
14 | #define PLATFORM_UNIX 3
15 | #define PLATFORM_PS3 4
16 |
17 | #if defined(_WIN32)
18 | #define PLATFORM PLATFORM_WINDOWS
19 | #elif defined(__APPLE__)
20 | #define PLATFORM PLATFORM_MAC
21 | #else
22 | #define PLATFORM PLATFORM_UNIX
23 | #endif
24 |
25 | #ifndef PLATFORM
26 | #error unknown platform!
27 | #endif
28 |
29 | // compile time configuration
30 |
31 | #define MULTITHREADED
32 | //#define VISUALIZE_SHADOW_VOLUMES
33 | //#define FRUSTUM_CULLING
34 | //#define USE_SECONDARY_DISPLAY_IF_EXISTS
35 | //#define DISCOVER_KEY_CODES
36 |
37 | const int MaxPlayers = 4;
38 |
39 | const float MaxLinearVelocity = 100;
40 | const float MaxAngularVelocity = 100;
41 | const float PositionResolution = 0.001f;
42 | const float OrientationResolution = 0.001f;
43 | const float LinearVelocityResolution = 0.001f;
44 | const float AngularVelocityResolution = 0.001f;
45 | const float RelativePositionBound = 10.0f;
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/AssertException.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_ASSERTEXCEPTION_H
2 | #define UNITTEST_ASSERTEXCEPTION_H
3 |
4 | #include
5 |
6 |
7 | namespace UnitTest {
8 |
9 | class AssertException : public std::exception
10 | {
11 | public:
12 | AssertException(char const* description, char const* filename, int lineNumber);
13 | virtual ~AssertException() throw();
14 |
15 | virtual char const* what() const throw();
16 |
17 | char const* Filename() const;
18 | int LineNumber() const;
19 |
20 | private:
21 | char m_description[512];
22 | char m_filename[256];
23 | int m_lineNumber;
24 | };
25 |
26 | }
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/Config.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_CONFIG_H
2 | #define UNITTEST_CONFIG_H
3 |
4 | // Standard defines documented here: http://predef.sourceforge.net
5 |
6 | #if defined(_MSC_VER)
7 | #pragma warning(disable:4127) // conditional expression is constant
8 | #pragma warning(disable:4702) // unreachable code
9 | #pragma warning(disable:4722) // destructor never returns, potential memory leak
10 |
11 | #if (_MSC_VER == 1200) // VC6
12 | #pragma warning(disable:4786)
13 | #pragma warning(disable:4290)
14 | #endif
15 | #endif
16 |
17 | #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \
18 | defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
19 | #define UNITTEST_POSIX
20 | #endif
21 |
22 | #if defined(__MINGW32__)
23 | #define UNITTEST_MINGW
24 | #endif
25 |
26 | // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive.
27 | // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream).
28 |
29 | //#define UNITTEST_USE_CUSTOM_STREAMS
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/CurrentTest.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_CURRENTTESTRESULTS_H
2 | #define UNITTEST_CURRENTTESTRESULTS_H
3 |
4 | namespace UnitTest {
5 |
6 | class TestResults;
7 | class TestDetails;
8 |
9 | namespace CurrentTest
10 | {
11 | TestResults*& Results();
12 | const TestDetails*& Details();
13 | }
14 |
15 | }
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/DeferredTestReporter.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_DEFERREDTESTREPORTER_H
2 | #define UNITTEST_DEFERREDTESTREPORTER_H
3 |
4 | #include "TestReporter.h"
5 | #include "DeferredTestResult.h"
6 |
7 | #include
8 |
9 | namespace UnitTest
10 | {
11 |
12 | class DeferredTestReporter : public TestReporter
13 | {
14 | public:
15 | virtual void ReportTestStart(TestDetails const& details);
16 | virtual void ReportFailure(TestDetails const& details, char const* failure);
17 | virtual void ReportTestFinish(TestDetails const& details, float secondsElapsed);
18 |
19 | typedef std::vector< DeferredTestResult > DeferredTestResultList;
20 | DeferredTestResultList& GetResults();
21 |
22 | private:
23 | DeferredTestResultList m_results;
24 | };
25 |
26 | }
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/DeferredTestResult.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_DEFERREDTESTRESULT_H
2 | #define UNITTEST_DEFERREDTESTRESULT_H
3 |
4 | #include
5 | #include
6 |
7 | namespace UnitTest
8 | {
9 |
10 | struct DeferredTestResult
11 | {
12 | DeferredTestResult();
13 | DeferredTestResult(char const* suite, char const* test);
14 |
15 | std::string suiteName;
16 | std::string testName;
17 | std::string failureFile;
18 |
19 | typedef std::pair< int, std::string > Failure;
20 | typedef std::vector< Failure > FailureVec;
21 | FailureVec failures;
22 |
23 | float timeElapsed;
24 | bool failed;
25 | };
26 |
27 | }
28 |
29 | #endif //UNITTEST_DEFERREDTESTRESULT_H
30 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/ExecuteTest.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_EXECUTE_TEST_H
2 | #define UNITTEST_EXECUTE_TEST_H
3 |
4 | #include "TestDetails.h"
5 | #include "MemoryOutStream.h"
6 | #include "AssertException.h"
7 | #include "CurrentTest.h"
8 |
9 | #ifdef UNITTEST_POSIX
10 | #include "Posix/SignalTranslator.h"
11 | #endif
12 |
13 | namespace UnitTest {
14 |
15 | template< typename T >
16 | void ExecuteTest(T& testObject, TestDetails const& details)
17 | {
18 | CurrentTest::Details() = &details;
19 |
20 | try
21 | {
22 | #ifdef UNITTEST_POSIX
23 | UNITTEST_THROW_SIGNALS
24 | #endif
25 | testObject.RunImpl();
26 | }
27 | catch (AssertException const& e)
28 | {
29 | CurrentTest::Results()->OnTestFailure(
30 | TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what());
31 | }
32 | catch (std::exception const& e)
33 | {
34 | MemoryOutStream stream;
35 | stream << "Unhandled exception: " << e.what();
36 | CurrentTest::Results()->OnTestFailure(details, stream.GetText());
37 | }
38 | catch (...)
39 | {
40 | CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!");
41 | }
42 | }
43 |
44 | }
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/MemoryOutStream.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_MEMORYOUTSTREAM_H
2 | #define UNITTEST_MEMORYOUTSTREAM_H
3 |
4 | #include "Config.h"
5 |
6 | #ifndef UNITTEST_USE_CUSTOM_STREAMS
7 |
8 | #include
9 |
10 | namespace UnitTest
11 | {
12 |
13 | class MemoryOutStream : public std::ostringstream
14 | {
15 | public:
16 | MemoryOutStream() {}
17 | char const* GetText() const;
18 |
19 | private:
20 | MemoryOutStream(MemoryOutStream const&);
21 | void operator =(MemoryOutStream const&);
22 |
23 | mutable std::string m_text;
24 | };
25 |
26 | }
27 |
28 | #else
29 |
30 | #include
31 |
32 | namespace UnitTest
33 | {
34 |
35 | class MemoryOutStream
36 | {
37 | public:
38 | explicit MemoryOutStream(int const size = 256);
39 | ~MemoryOutStream();
40 |
41 | char const* GetText() const;
42 |
43 | MemoryOutStream& operator << (char const* txt);
44 | MemoryOutStream& operator << (int n);
45 | MemoryOutStream& operator << (long n);
46 | MemoryOutStream& operator << (unsigned long n);
47 | MemoryOutStream& operator << (float f);
48 | MemoryOutStream& operator << (double d);
49 | MemoryOutStream& operator << (void const* p);
50 | MemoryOutStream& operator << (unsigned int s);
51 |
52 | enum { GROW_CHUNK_SIZE = 32 };
53 | int GetCapacity() const;
54 |
55 | private:
56 | void operator= (MemoryOutStream const&);
57 | void GrowBuffer(int capacity);
58 |
59 | int m_capacity;
60 | char* m_buffer;
61 | };
62 |
63 | }
64 |
65 | #endif
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/Posix/SignalTranslator.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_SIGNALTRANSLATOR_H
2 | #define UNITTEST_SIGNALTRANSLATOR_H
3 |
4 | #include
5 | #include
6 |
7 | namespace UnitTest {
8 |
9 | class SignalTranslator
10 | {
11 | public:
12 | SignalTranslator();
13 | ~SignalTranslator();
14 |
15 | static sigjmp_buf* s_jumpTarget;
16 |
17 | private:
18 | sigjmp_buf m_currentJumpTarget;
19 | sigjmp_buf* m_oldJumpTarget;
20 |
21 | struct sigaction m_old_SIGFPE_action;
22 | struct sigaction m_old_SIGTRAP_action;
23 | struct sigaction m_old_SIGSEGV_action;
24 | struct sigaction m_old_SIGBUS_action;
25 | struct sigaction m_old_SIGABRT_action;
26 | struct sigaction m_old_SIGALRM_action;
27 | };
28 |
29 | #if !defined (__GNUC__)
30 | #define UNITTEST_EXTENSION
31 | #else
32 | #define UNITTEST_EXTENSION __extension__
33 | #endif
34 |
35 | #define UNITTEST_THROW_SIGNALS \
36 | UnitTest::SignalTranslator sig; \
37 | if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \
38 | throw ("Unhandled system exception");
39 |
40 | }
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/Posix/TimeHelpers.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TIMEHELPERS_H
2 | #define UNITTEST_TIMEHELPERS_H
3 |
4 | #include
5 |
6 | namespace UnitTest {
7 |
8 | class Timer
9 | {
10 | public:
11 | Timer();
12 | void Start();
13 | int GetTimeInMs() const;
14 |
15 | private:
16 | struct timeval m_startTime;
17 | };
18 |
19 |
20 | namespace TimeHelpers
21 | {
22 | void SleepMs (int ms);
23 | }
24 |
25 |
26 | }
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/ReportAssert.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_ASSERT_H
2 | #define UNITTEST_ASSERT_H
3 |
4 | namespace UnitTest {
5 |
6 | void ReportAssert(char const* description, char const* filename, int lineNumber);
7 |
8 | }
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/Test.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TEST_H
2 | #define UNITTEST_TEST_H
3 |
4 | #include "TestDetails.h"
5 |
6 | namespace UnitTest {
7 |
8 | class TestResults;
9 | class TestList;
10 |
11 | class Test
12 | {
13 | public:
14 | explicit Test(char const* testName, char const* suiteName = "DefaultSuite", char const* filename = "", int lineNumber = 0);
15 | virtual ~Test();
16 | void Run();
17 |
18 | TestDetails const m_details;
19 | Test* next;
20 | mutable bool m_timeConstraintExempt;
21 |
22 | static TestList& GetTestList();
23 |
24 | virtual void RunImpl() const;
25 |
26 | private:
27 | Test(Test const&);
28 | Test& operator =(Test const&);
29 | };
30 |
31 |
32 | }
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestDetails.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTDETAILS_H
2 | #define UNITTEST_TESTDETAILS_H
3 |
4 | namespace UnitTest {
5 |
6 | class TestDetails
7 | {
8 | public:
9 | TestDetails(char const* testName, char const* suiteName, char const* filename, int lineNumber);
10 | TestDetails(const TestDetails& details, int lineNumber);
11 |
12 | char const* const suiteName;
13 | char const* const testName;
14 | char const* const filename;
15 | int const lineNumber;
16 |
17 | TestDetails(TestDetails const&); // Why is it public? --> http://gcc.gnu.org/bugs.html#cxx_rvalbind
18 | private:
19 | TestDetails& operator=(TestDetails const&);
20 | };
21 |
22 | }
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestList.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTLIST_H
2 | #define UNITTEST_TESTLIST_H
3 |
4 |
5 | namespace UnitTest {
6 |
7 | class Test;
8 |
9 | class TestList
10 | {
11 | public:
12 | TestList();
13 | void Add (Test* test);
14 |
15 | Test* GetHead() const;
16 |
17 | private:
18 | Test* m_head;
19 | Test* m_tail;
20 | };
21 |
22 |
23 | class ListAdder
24 | {
25 | public:
26 | ListAdder(TestList& list, Test* test);
27 | };
28 |
29 | }
30 |
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestReporter.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTREPORTER_H
2 | #define UNITTEST_TESTREPORTER_H
3 |
4 | namespace UnitTest {
5 |
6 | class TestDetails;
7 |
8 | class TestReporter
9 | {
10 | public:
11 | virtual ~TestReporter();
12 |
13 | virtual void ReportTestStart(TestDetails const& test) = 0;
14 | virtual void ReportFailure(TestDetails const& test, char const* failure) = 0;
15 | virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed) = 0;
16 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) = 0;
17 | };
18 |
19 | }
20 | #endif
21 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestReporterStdout.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTREPORTERSTDOUT_H
2 | #define UNITTEST_TESTREPORTERSTDOUT_H
3 |
4 | #include "TestReporter.h"
5 |
6 | namespace UnitTest {
7 |
8 | class TestReporterStdout : public TestReporter
9 | {
10 | private:
11 | virtual void ReportTestStart(TestDetails const& test);
12 | virtual void ReportFailure(TestDetails const& test, char const* failure);
13 | virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed);
14 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
15 | };
16 |
17 | }
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestResults.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTRESULTS_H
2 | #define UNITTEST_TESTRESULTS_H
3 |
4 | namespace UnitTest {
5 |
6 | class TestReporter;
7 | class TestDetails;
8 |
9 | class TestResults
10 | {
11 | public:
12 | explicit TestResults(TestReporter* reporter = 0);
13 |
14 | void OnTestStart(TestDetails const& test);
15 | void OnTestFailure(TestDetails const& test, char const* failure);
16 | void OnTestFinish(TestDetails const& test, float secondsElapsed);
17 |
18 | int GetTotalTestCount() const;
19 | int GetFailedTestCount() const;
20 | int GetFailureCount() const;
21 |
22 | private:
23 | TestReporter* m_testReporter;
24 | int m_totalTestCount;
25 | int m_failedTestCount;
26 | int m_failureCount;
27 |
28 | bool m_currentTestFailed;
29 |
30 | TestResults(TestResults const&);
31 | TestResults& operator =(TestResults const&);
32 | };
33 |
34 | }
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestRunner.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTRUNNER_H
2 | #define UNITTEST_TESTRUNNER_H
3 |
4 | #include "Test.h"
5 | #include "TestList.h"
6 | #include "CurrentTest.h"
7 |
8 | namespace UnitTest {
9 |
10 | class TestReporter;
11 | class TestResults;
12 | class Timer;
13 |
14 | int RunAllTests();
15 |
16 | struct True
17 | {
18 | bool operator()(const Test* const) const
19 | {
20 | return true;
21 | }
22 | };
23 |
24 | class TestRunner
25 | {
26 | public:
27 | explicit TestRunner(TestReporter& reporter);
28 | ~TestRunner();
29 |
30 | template
31 | int RunTestsIf(TestList const& list, char const* suiteName,
32 | const Predicate& predicate, int maxTestTimeInMs) const
33 | {
34 | Test* curTest = list.GetHead();
35 |
36 | while (curTest != 0)
37 | {
38 | if (IsTestInSuite(curTest,suiteName) && predicate(curTest))
39 | {
40 | RunTest(m_result, curTest, maxTestTimeInMs);
41 | }
42 |
43 | curTest = curTest->next;
44 | }
45 |
46 | return Finish();
47 | }
48 |
49 | private:
50 | TestReporter* m_reporter;
51 | TestResults* m_result;
52 | Timer* m_timer;
53 |
54 | int Finish() const;
55 | bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
56 | void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
57 | };
58 |
59 | }
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TestSuite.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TESTSUITE_H
2 | #define UNITTEST_TESTSUITE_H
3 |
4 | namespace UnitTestSuite {
5 |
6 | inline char const* GetSuiteName ()
7 | {
8 | return "DefaultSuite";
9 | }
10 |
11 | }
12 |
13 | #endif
14 |
15 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TimeConstraint.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TIMECONSTRAINT_H
2 | #define UNITTEST_TIMECONSTRAINT_H
3 |
4 | #include "TimeHelpers.h"
5 |
6 | namespace UnitTest {
7 |
8 | class TestResults;
9 | class TestDetails;
10 |
11 | class TimeConstraint
12 | {
13 | public:
14 | TimeConstraint(int ms, TestDetails const& details);
15 | ~TimeConstraint();
16 |
17 | private:
18 | void operator=(TimeConstraint const&);
19 | TimeConstraint(TimeConstraint const&);
20 |
21 | Timer m_timer;
22 | TestDetails const& m_details;
23 | int const m_maxMs;
24 | };
25 |
26 | #define UNITTEST_TIME_CONSTRAINT(ms) \
27 | UnitTest::TimeConstraint unitTest__timeConstraint__(ms, UnitTest::TestDetails(m_details, __LINE__))
28 |
29 | #define UNITTEST_TIME_CONSTRAINT_EXEMPT() do { m_timeConstraintExempt = true; } while (0)
30 |
31 | }
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/TimeHelpers.h:
--------------------------------------------------------------------------------
1 | #include "Config.h"
2 |
3 | #if defined UNITTEST_POSIX
4 | #include "Posix/TimeHelpers.h"
5 | #else
6 | #include "Win32/TimeHelpers.h"
7 | #endif
8 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/UnitTest++.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTESTCPP_H
2 | #define UNITTESTCPP_H
3 |
4 | //lint -esym(1509,*Fixture)
5 |
6 | #include "Config.h"
7 | #include "Test.h"
8 | #include "TestList.h"
9 | #include "TestSuite.h"
10 | #include "TestResults.h"
11 |
12 | #include "TestMacros.h"
13 |
14 | #include "CheckMacros.h"
15 | #include "TestRunner.h"
16 | #include "TimeConstraint.h"
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/Win32/TimeHelpers.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_TIMEHELPERS_H
2 | #define UNITTEST_TIMEHELPERS_H
3 |
4 | #include "../Config.h"
5 |
6 |
7 | #ifdef UNITTEST_MINGW
8 | #ifndef __int64
9 | #define __int64 long long
10 | #endif
11 | #endif
12 |
13 | namespace UnitTest {
14 |
15 | class Timer
16 | {
17 | public:
18 | Timer();
19 | void Start();
20 | int GetTimeInMs() const;
21 |
22 | private:
23 | __int64 GetTime() const;
24 |
25 | void* m_threadHandle;
26 |
27 | #if defined(_WIN64)
28 | unsigned __int64 m_processAffinityMask;
29 | #else
30 | unsigned long m_processAffinityMask;
31 | #endif
32 |
33 | __int64 m_startTime;
34 | __int64 m_frequency;
35 | };
36 |
37 |
38 | namespace TimeHelpers
39 | {
40 | void SleepMs (int ms);
41 | }
42 |
43 |
44 | }
45 |
46 |
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/UnitTest++/XmlTestReporter.h:
--------------------------------------------------------------------------------
1 | #ifndef UNITTEST_XMLTESTREPORTER_H
2 | #define UNITTEST_XMLTESTREPORTER_H
3 |
4 | #include "DeferredTestReporter.h"
5 |
6 | #include
7 |
8 | namespace UnitTest
9 | {
10 |
11 | class XmlTestReporter : public DeferredTestReporter
12 | {
13 | public:
14 | explicit XmlTestReporter(std::ostream& ostream);
15 |
16 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
17 |
18 | private:
19 | XmlTestReporter(XmlTestReporter const&);
20 | XmlTestReporter& operator=(XmlTestReporter const&);
21 |
22 | void AddXmlElement(std::ostream& os, char const* encoding);
23 | void BeginResults(std::ostream& os, int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed);
24 | void EndResults(std::ostream& os);
25 | void BeginTest(std::ostream& os, DeferredTestResult const& result);
26 | void AddFailure(std::ostream& os, DeferredTestResult const& result);
27 | void EndTest(std::ostream& os, DeferredTestResult const& result);
28 |
29 | std::ostream& m_ostream;
30 | };
31 |
32 | }
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/ViewObject.h:
--------------------------------------------------------------------------------
1 | /*
2 | Fiedler's Cubes
3 | Copyright © 2008-2009 Glenn Fiedler
4 | http://www.gafferongames.com/fiedlers-cubes
5 | */
6 |
7 | #ifndef VIEW_OBJECT_H
8 | #define VIEW_OBJECT_H
9 |
10 | const int MaxViewObjects = 1024;
11 |
12 | namespace view
13 | {
14 | struct ObjectState
15 | {
16 | bool pendingDeactivation;
17 | bool enabled;
18 | unsigned int id;
19 | unsigned int owner;
20 | unsigned int authority;
21 | unsigned int framesSinceLastUpdate;
22 | float scale;
23 | math::Vector position;
24 | math::Quaternion orientation;
25 | math::Vector linearVelocity;
26 | math::Vector angularVelocity;
27 |
28 | ObjectState()
29 | {
30 | id = 0;
31 | owner = MaxPlayers;
32 | authority = MaxPlayers;
33 | position = math::Vector(0,0,0);
34 | orientation = math::Quaternion(1,0,0,0);
35 | enabled = true;
36 | linearVelocity = math::Vector(0,0,0);
37 | angularVelocity = math::Vector(0,0,0);
38 | scale = 1.0f;
39 | pendingDeactivation = true;
40 | framesSinceLastUpdate = 0;
41 | }
42 | };
43 |
44 | struct Packet
45 | {
46 | int droppedFrames;
47 | float netTime;
48 | float simTime;
49 | math::Vector origin;
50 | int objectCount;
51 | ObjectState object[MaxViewObjects];
52 |
53 | Packet()
54 | {
55 | droppedFrames = 0;
56 | netTime = 0.0f;
57 | simTime = 0.0f;
58 | origin = math::Vector(0,0,0);
59 | objectCount = 0;
60 | }
61 | };
62 | }
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/license.html:
--------------------------------------------------------------------------------
1 | 
Fiedler's Cubes by Glenn Fiedler is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Permissions beyond the scope of this license may be available at http://www.gafferongames.com/fiedlers-cubes.
2 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/license.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsRobokitty/netgame/b30fe48a0072fa40c45f05f7aa87ccfdd1f55d3f/XX - Fiedler's Cubes/license.txt
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/makefile:
--------------------------------------------------------------------------------
1 | makefile.apple
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/makefile.apple:
--------------------------------------------------------------------------------
1 | # makefile for macosx
2 |
3 | #CFLAGS="-march=core2 -mfpmath=sse -sse3 -O3 " CXXFLAGS="-march=core2 -mfpmath=sse -sse3 -O3 " ./configure --with-trimesh=none --with-drawstuff=none
4 |
5 | #CFLAGS="-Wall -DDEBUG" CXXFLAGS="-Wall -DDEBUG" ./configure --with-trimesh=none --with-drawstuff=none --enable-malloc
6 |
7 | flags = -march=core2 -mfpmath=sse -sse3 -O3 -Iode -ffast-math -fno-exceptions -finline-functions -fomit-frame-pointer -fstrict-aliasing -Wstrict-aliasing=2 -Wall -DNDEBUG -lm
8 |
9 | #flags = -Wall -DDEBUG -lm
10 |
11 | headers := $(wildcard *.h)
12 |
13 | libs := -lode
14 | frameworks := -framework Carbon -framework OpenGL -framework AGL
15 |
16 | all : Demo.app test
17 |
18 | % : %.cpp makefile ${headers}
19 | g++ $< -o $@ ${flags} ${libs} ${frameworks}
20 |
21 | UnitTest : UnitTest.cpp makefile ${headers}
22 | g++ UnitTest.cpp -o UnitTest -Wall -DDEBUG -lm -lUnitTest++ ${libs}
23 |
24 | test : UnitTest
25 | ./UnitTest
26 |
27 | demo : Demo test
28 | ./Demo
29 |
30 | demo_app : Demo.app test
31 | open Demo.app --wait-apps
32 |
33 | Demo.app : Demo
34 | rm -rf $<.app
35 | mkdir $<.app
36 | mkdir $<.app/Contents
37 | mkdir $<.app/Contents/MacOS
38 | cp $< $<.app/Contents/MacOS/
39 |
40 | .PHONY: demo_app
41 | .PHONY: demo
42 | .PHONY: test
43 |
44 | clean:
45 | rm -f UnitTest
46 | rm -f Demo
47 | rm -rf *.app
48 | rm -f *.a
49 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/todo.txt:
--------------------------------------------------------------------------------
1 | TODO
2 |
3 | determinism:
4 | - quantize linear velocity, angular velocity
5 | - send byte for frames at rest
6 |
7 | smoothing:
8 | - change position error reduction to be C2 continuous
9 | - change orientation error reduction to be C2 continuous
10 |
11 | bandwidth:
12 | - compress and serialize data across via stream
13 | - display current bandwidth usage
14 | - throttle objects to fit in 64kbit/sec
15 | - add dynamic selection between various quality levels (64kbit/sec, 128kbit/sec etc, 256kbit/sec...)
16 | - add packet loss simulation % to validate
17 | - add jitter simulation and de-jitter buffering
18 | - add some status display, avg. object updates, # of authority objects etc...
19 |
20 | longer term:
21 | - convert internal functionality inside activation system to fixed point math
22 | - implement world wrapping inside activation and game instance
23 | - add object health value and fade-out objects at zero health
24 | - extend activation system to support object relevancy
25 | - extend to support add/remove objects
26 | - implement dynamic player cube spawn join and leave
27 | - implement layer load/unload
28 | - create/delete objects
29 | - resize activation circle dynamically
30 | - expand activation system to very large active object counts - break O(n) costs
31 | - apply christer's memory optimization techniques to the activation system
32 |
--------------------------------------------------------------------------------
/XX - Fiedler's Cubes/vs2008/FiedlersCubes.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FiedlersCubes", "FiedlersCubes.vcproj", "{9057DE56-AEFE-4DA8-A134-C6826D1BCC38}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {9057DE56-AEFE-4DA8-A134-C6826D1BCC38}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {9057DE56-AEFE-4DA8-A134-C6826D1BCC38}.Debug|Win32.Build.0 = Debug|Win32
14 | {9057DE56-AEFE-4DA8-A134-C6826D1BCC38}.Release|Win32.ActiveCfg = Release|Win32
15 | {9057DE56-AEFE-4DA8-A134-C6826D1BCC38}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------