Commit b81e4b96 authored by Mark Frohnmayer's avatar Mark Frohnmayer
Browse files

nacl_test_tnl2 getting very close...

parent 9bd10674
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
*.o
*.nexe
*.a
tnl2_test/moc_*
tnl2_test/tnl2_test.app
tnl2_test/tnl2_test.pro.*
+20 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
		1D38228E1153D404009D94C5 /* tnl2_test_view.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D38228D1153D404009D94C5 /* tnl2_test_view.m */; };
		1DA782FE116058F800FB41C2 /* test_game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1DA782F9116058F800FB41C2 /* test_game.cpp */; };
		1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
		1DE40B5A1197A1B600373D23 /* nacl_test_tnl2.html in Resources */ = {isa = PBXBuildFile; fileRef = 1DE40B581197A1B600373D23 /* nacl_test_tnl2.html */; };
		8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
		8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
		8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
@@ -23,6 +24,9 @@
		089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
		1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
		13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
		1D1536A81197AB490060CE24 /* socket_event_queue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = socket_event_queue.h; path = ../../torque_sockets/torque_sockets/socket_event_queue.h; sourceTree = SOURCE_ROOT; };
		1D1537391197D1CF0060CE24 /* test_tnl2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_tnl2.h; path = ../test_tnl2/test_tnl2.h; sourceTree = SOURCE_ROOT; };
		1D1537871197DCF00060CE24 /* test_game_render_frame_gl_es_2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_game_render_frame_gl_es_2.h; path = ../test_tnl2/test_game_render_frame_gl_es_2.h; sourceTree = SOURCE_ROOT; };
		1D3822241153D0A7009D94C5 /* algorithm_templates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = algorithm_templates.h; path = ../../torque_sockets/core/algorithm_templates.h; sourceTree = SOURCE_ROOT; };
		1D3822251153D0A7009D94C5 /* array.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = array.h; path = ../../torque_sockets/core/array.h; sourceTree = SOURCE_ROOT; };
		1D3822261153D0A7009D94C5 /* assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = assert.h; path = ../../torque_sockets/core/assert.h; sourceTree = SOURCE_ROOT; };
@@ -117,6 +121,8 @@
		1DAD5F8A118E647C008301BF /* prcpucfg_win32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_win32.h; path = ../../torque_sockets/plugin_framework/prcpucfg_win32.h; sourceTree = SOURCE_ROOT; };
		1DAD5F8B118E647C008301BF /* prtypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prtypes.h; path = ../../torque_sockets/plugin_framework/prtypes.h; sourceTree = SOURCE_ROOT; };
		1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
		1DE40B571197A1B600373D23 /* nacl_test_tnl2.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = nacl_test_tnl2.cc; path = ../nacl_test_tnl2/nacl_test_tnl2.cc; sourceTree = SOURCE_ROOT; };
		1DE40B581197A1B600373D23 /* nacl_test_tnl2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = nacl_test_tnl2.html; path = ../nacl_test_tnl2/nacl_test_tnl2.html; sourceTree = SOURCE_ROOT; };
		1DF3DCCB117A822E008F7A78 /* chat_example.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = chat_example.html; path = ../../torque_sockets/products/TorqueSocketsPlugin/chat_example.html; sourceTree = SOURCE_ROOT; };
		29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
		29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
@@ -245,6 +251,7 @@
				1D3822581153D0BE009D94C5 /* time.h */,
				1D3822591153D0BE009D94C5 /* torque_connection.h */,
				1D38225A1153D0BE009D94C5 /* torque_socket.h */,
				1D1536A81197AB490060CE24 /* socket_event_queue.h */,
				1D38225B1153D0BE009D94C5 /* torque_sockets.h */,
				1D38225C1153D0BE009D94C5 /* torque_sockets_c_api.h */,
				1D38225D1153D0BE009D94C5 /* torque_sockets_c_implementation.h */,
@@ -267,6 +274,15 @@
			name = tnl2;
			sourceTree = "<group>";
		};
		1D8E3DF611979B940052219B /* nacl_tnl2_and_pepper */ = {
			isa = PBXGroup;
			children = (
				1DE40B571197A1B600373D23 /* nacl_test_tnl2.cc */,
				1DE40B581197A1B600373D23 /* nacl_test_tnl2.html */,
			);
			name = nacl_tnl2_and_pepper;
			sourceTree = "<group>";
		};
		1DAD5F7E118E645E008301BF /* plugin_framework */ = {
			isa = PBXGroup;
			children = (
@@ -290,6 +306,7 @@
		29B97314FDCFA39411CA2CEA /* tnl2_test_cocoa */ = {
			isa = PBXGroup;
			children = (
				1D8E3DF611979B940052219B /* nacl_tnl2_and_pepper */,
				1DAD5F7E118E645E008301BF /* plugin_framework */,
				1D38227A1153D2B5009D94C5 /* libtommath.a */,
				1D3822781153D2A1009D94C5 /* libtomcrypt.a */,
@@ -309,6 +326,8 @@
		29B97315FDCFA39411CA2CEA /* test_tnl2 */ = {
			isa = PBXGroup;
			children = (
				1D1537871197DCF00060CE24 /* test_game_render_frame_gl_es_2.h */,
				1D1537391197D1CF0060CE24 /* test_tnl2.h */,
				1DA782F7116058F800FB41C2 /* test_building.h */,
				1DA782F8116058F800FB41C2 /* test_connection.h */,
				1DA782F9116058F800FB41C2 /* test_game.cpp */,
@@ -386,6 +405,7 @@
			files = (
				8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
				1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */,
				1DE40B5A1197A1B600373D23 /* nacl_test_tnl2.html in Resources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
+285 −11
Original line number Diff line number Diff line
@@ -26,15 +26,271 @@ public:
	NPDevice* _device3d;
	PGLContext _pgl_context;
	tnl_test::test_game *_game;
	int __moduleReady;
	NPObjectRef socket_instance;
	NPIdentifier *_socket_identifiers;
	zone_allocator _allocator;
	net::socket_event_queue _event_queue;
	
	tnl_test_instance()
	enum socket_method_id {
		socket_bind,
		socket_set_challenge_response,
		socket_send_to,
		socket_connect,
		socket_connect_introduced,
		socket_introduce,
		socket_accept_challenge,
		socket_accept_connection,
		socket_close_connection,
		socket_send_to_connection,
		socket_method_count,
	};
	static NPIdentifier *get_identifier_table()
	{
		_color = 0;
		SOCKADDR addr;
		static NPIdentifier socket_method_identifiers[socket_method_count];
		static const NPUTF8 *socket_method_names[] = {
			"bind",
			"set_challenge_response",
			"send_to",
			"connect",
			"connect_introduced",
			"introduce",
			"accept_challenge",
			"accept_connection",
			"close_connection",
			"send_to_connection",
		};
		static bool loaded = false;
		if(!loaded)
		{
			browser->getstringidentifiers(socket_method_names, socket_method_count, socket_method_identifiers);
			loaded = true;
		}
		return socket_method_identifiers;
	}
	
	static torque_socket_handle nacl_socket_create(bool background_thread, void (*socket_notify)(void *), void *socket_notify_data)
	{
		return socket_notify_data;
	}
	
	static void nacl_socket_destroy(torque_socket_handle the_socket)
	{
	}
	
	static bind_result nacl_socket_bind(torque_socket_handle the_socket, struct sockaddr *bound_interface_address)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		int result;
		string address_string = net::address(*bound_interface_address).to_string();
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_bind], &result, address_string);
	}
	
	static void nacl_socket_allow_incoming_connections(torque_socket_handle the_socket, int allowed)
	{
	}
	
	static void nacl_socket_set_key_pair(torque_socket_handle the_socket, unsigned key_data_size, unsigned char *the_key)
	{
	}
	
	static void nacl_socket_set_challenge_response(torque_socket_handle the_socket, unsigned challenge_response_size, unsigned char *challenge_response)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		empty_type result;
		string challenge_response_string(challenge_response, challenge_response_size);
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_set_challenge_response], &result, challenge_response_string);
	}
	
	static void nacl_socket_write_entropy(torque_socket_handle the_socket, unsigned char entropy[32])
	{
	}
	
	static void nacl_socket_read_entropy(torque_socket_handle the_socket, unsigned char entropy[32])
	{
	}
	
	static int nacl_socket_send_to(torque_socket_handle the_socket, struct sockaddr* remote_host, unsigned data_size, unsigned char *data)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		int result;
		string address_string = net::address(*remote_host).to_string();
		string data_string(data, data_size);
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_send_to], &result, address_string, data_string);
		return result;
	}
	
	static torque_connection_id nacl_socket_connect(torque_socket_handle the_socket, struct sockaddr* remote_host, unsigned connect_data_size, unsigned char *connect_data)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		int result;
		string address_string = net::address(*remote_host).to_string();
		string connect_data_string(connect_data, connect_data_size);
		string protocol_string;

		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_connect], &result, address_string, connect_data_string, protocol_string);
		return result;
	}
	
	static torque_connection_id nacl_socket_connect_introduced(torque_socket_handle the_socket, torque_connection_id introducer, torque_connection_id remote_client_identity, int is_host, unsigned connect_data_size, unsigned char *connect_data)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		int result;
		string connect_data_string(connect_data, connect_data_size);
		int intro = introducer;
		int rcid = remote_client_identity;
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_connect_introduced], &result, intro, rcid, is_host,connect_data_string);
		return result;
	}
	
	static void nacl_socket_introduce(torque_socket_handle the_socket, torque_connection_id initiator, torque_connection_id host)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		empty_type result;
		int the_initiator = initiator;
		int the_host = host;
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_introduce], &result, the_initiator, the_host);
	}
	
	static void nacl_socket_accept_challenge(torque_socket_handle the_socket, torque_connection_id pending_connection)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		empty_type result;
		int pending = pending_connection;
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_accept_challenge], &result, pending);
	}
	
	static void nacl_socket_accept_connection(torque_socket_handle the_socket, torque_connection_id pending_connection)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		empty_type result;
		int pending = pending_connection;
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_accept_connection], &result, pending);
	}
	
	static void nacl_socket_close_connection(torque_socket_handle the_socket, torque_connection_id connection_id, unsigned disconnect_data_size, unsigned char *disconnect_data)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		empty_type result;
		int conn_id = connection_id;
		string disconnect_data_string(disconnect_data, disconnect_data_size);
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_close_connection], &result, conn_id, disconnect_data_string);
	}
	
	static int nacl_socket_send_to_connection(torque_socket_handle the_socket, torque_connection_id connection_id, unsigned datagram_size, unsigned char buffer[torque_sockets_max_datagram_size])
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		int result;
		int conn_id = connection_id;
		string datagram(buffer, datagram_size);
		ti->call_method(ti->socket_instance, ti->_socket_identifiers[socket_send_to_connection], &result, conn_id, datagram);
		return result;
	}
	
	static struct torque_socket_event *nacl_socket_get_next_event(torque_socket_handle the_socket)
	{
		tnl_test_instance *ti = static_cast<tnl_test_instance *>(the_socket);
		return ti->get_next_event();
	}
	
	void on_challenge_response(int connection, string key, string message)
	{
		logprintf("tnl2_test got challenge_response(%d, %s, %s)", connection, key.c_str(), message.c_str());
		torque_socket_event *event = _event_queue.post_event(torque_connection_challenge_response_event_type, connection);
		_event_queue.set_event_key(event, key.data(), key.len());
		_event_queue.set_event_data(event, message.data(), message.len());
	}
	
	void on_connect_request(int connection, string key, string message)
	{
		logprintf("tnl2_test got connect_request(%d, %s, %s)", connection, key.c_str(), message.c_str());
		torque_socket_event *event = _event_queue.post_event(torque_connection_requested_event_type, connection);
		_event_queue.set_event_key(event, key.data(), key.len());
		_event_queue.set_event_data(event, message.data(), message.len());
	}
	
	void on_established(int connection)
	{
		logprintf("tnl2_test got established(%d)", connection);
		_event_queue.post_event(torque_connection_established_event_type, connection);
	}
	
	void on_close(int connection, string message)
	{
		logprintf("tnl2_test got close(%d,%s)", connection,message.c_str());
		torque_socket_event *event = _event_queue.post_event(torque_connection_disconnected_event_type, connection);
		_event_queue.set_event_data(event, message.data(), message.len());
	}
	
		_game = new tnl_test::test_game(true, addr, addr);
	void on_packet(int connection, int sequence, string packet)
	{
		logprintf("tnl2_test got packet(%d,%d,%s)", connection, sequence, packet.c_str());
		torque_socket_event *event = _event_queue.post_event(torque_connection_packet_event_type, connection);
		_event_queue.set_event_data(event, packet.data(), packet.len());
		event->packet_sequence = sequence;
	}
	
	void on_socket_packet(string source_address, string packet)
	{
		logprintf("tnl2_test got socket packet(%s,%s)", source_address.c_str(), packet.c_str());
		torque_socket_event *event = _event_queue.post_event(torque_socket_packet_event_type);
		_event_queue.set_event_data(event, packet.data(), packet.len());
		net::address(source_address.c_str()).to_sockaddr(&event->source_address);
	}
	
	void on_packet_delivery_notify(int connection, int sequence, bool status)
	{
		logprintf("tnl2_test got packet_delivery_notify(%d,%d,%d)", connection, sequence, status);
		torque_socket_event *event = _event_queue.post_event(torque_connection_packet_notify_event_type, connection);
		event->packet_sequence = sequence;
		event->delivered = status;
	}

	torque_socket_event *get_next_event()
	{
		if(!_event_queue.has_event())
		{
			_event_queue.clear();
			return 0;
		}
		return _event_queue.dequeue();
	}
	
	static torque_socket_interface *get_nacl_interface()
	{
		static torque_socket_interface _nacl_interface = 
		{
			nacl_socket_create,
			nacl_socket_destroy,
			nacl_socket_bind,
			nacl_socket_allow_incoming_connections,
			nacl_socket_set_key_pair,
			nacl_socket_set_challenge_response,
			nacl_socket_write_entropy,
			nacl_socket_read_entropy,
			nacl_socket_send_to,
			nacl_socket_connect,
			nacl_socket_connect_introduced,
			nacl_socket_introduce,
			nacl_socket_accept_challenge,
			nacl_socket_accept_connection,
			nacl_socket_close_connection,
			nacl_socket_send_to_connection,
			nacl_socket_get_next_event,
		};
		return &_nacl_interface;
	}
	tnl_test_instance() : _event_queue(&_allocator)
	{
		_socket_identifiers = get_identifier_table();
		__moduleReady = 1;
		_color = 0;
		net::address ping_address(net::address::any, 28000);
		
		SOCKADDR ping_sockaddr;
		ping_address.to_sockaddr(&ping_sockaddr);
		_game = new tnl_test::test_game(false, ping_sockaddr, get_nacl_interface(), this);
	}
	~tnl_test_instance()
	{
		delete _game;
@@ -63,7 +319,6 @@ public:
		
		if(!_pgl_context)
			init_context();
		browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this);
	}
	
	void init_context()
@@ -104,7 +359,6 @@ public:
	{
		_game->tick();
		
		logprintf("hit draw (%d, %d)", _width, _height);
		if(!pglMakeCurrent(_pgl_context) && pglGetError() == PGL_CONTEXT_LOST)
		{
			destroy_context();
@@ -125,7 +379,6 @@ public:
		
		pglSwapBuffers();
		pglMakeCurrent(NULL);
		browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this);
	}
	
	core::int16 handle_event(void *event)
@@ -163,15 +416,34 @@ public:
		return 1;
	}
	
	bool module_ready()
	void activate_socket()
	{
		return true;
		net::address bind_address;
		SOCKADDR bind_sockaddr;
		bind_address.to_sockaddr(&bind_sockaddr);
		_game->_net_interface->bind(bind_sockaddr);
	}
	
	void on_pong(string message)
	{
		logprintf("got pong %s", message.c_str());
	}
	
	static void register_class(type_database &db)
	{
		tnl_begin_class(db, tnl_test_instance, scriptable_object, true);
		tnl_method(db, tnl_test_instance, module_ready);
		tnl_slot(db, tnl_test_instance, socket_instance, 0);
		tnl_slot(db, tnl_test_instance, __moduleReady, 0);
		tnl_method(db, tnl_test_instance, activate_socket);
		tnl_method(db, tnl_test_instance, on_challenge_response);
		tnl_method(db, tnl_test_instance, on_connect_request);
		tnl_method(db, tnl_test_instance, on_established);
		tnl_method(db, tnl_test_instance, on_close);
		tnl_method(db, tnl_test_instance, on_packet);
		tnl_method(db, tnl_test_instance, on_socket_packet);
		tnl_method(db, tnl_test_instance, on_packet_delivery_notify);
		tnl_method(db, tnl_test_instance, on_pong);
		tnl_method(db, tnl_test_instance, tick);
		tnl_end_class(db);
	}
};
@@ -180,6 +452,8 @@ void plugin_initialize()
{
	pglInitialize();
	ltc_mp = ltm_desc;
	core::_log_prefix = "tnl_test";

	tnl_test_instance::register_class(global_type_database());
	global_plugin.add_class(get_global_type_record<tnl_test_instance>());
	global_plugin.set_plugin_class(get_global_type_record<tnl_test_instance>());
+42 −36
Original line number Diff line number Diff line
@@ -6,42 +6,9 @@
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

<script type="text/javascript">
<!--
var nacl_elt;

// Before scripting the loaded module, ensure the Native Client module is loaded.
var startupInterval;

var PostLoadInit = function()
{
	try
	{
		var embed = document.getElementById("embed1");
		var ready = embed.module_ready();
		clearInterval(startupInterval);
		alert('The Native Client plugin is ready');
		return;
	}
	catch(e)
	{
		// do nothing
	}
}

// Init is called when the document has completed loading.  It downloads the
// NativeClient modules.
var Init = function()
{
	startupInterval = setInterval("PostLoadInit()", 100);
}

-->
</script>

</HEAD>
<BODY id="bodyId" onload="Init();" >

<BODY id="bodyId" onload="post_load_init();" >
<object type="application/x-torque-socket" id="torque_socket_plugin" width="0" height="0"> </object>
<h1>test_tnl2 embedded in a web page</h1>
 <p>
  You should a yellow box below, representing a server game world.  Red rectangles represent buildings in 
@@ -51,8 +18,47 @@ var Init = function()
  This demo uses the open source Torque Network Library, which
  provides high performance real-time networking for games and simulations.
 </p>
<embed id="embed1" src="nacl_test_tnl2.nexe" type="application/x-nacl-srpc" width=400 height=400>
<embed id="tnl_test" src="nacl_test_tnl2.nexe" type="application/x-nacl-srpc" width=400 height=400>
<br>
<script type="text/javascript">

var tick_game = function()
{
	var tnl_test = document.getElementById("tnl_test");
	tnl_test.tick();
	setTimeout("tick_game();", 10);
}

// Before scripting the loaded module, ensure the Native Client module is loaded.
var post_load_init = function()
{
	var init_check_timeout = setTimeout("post_load_init();", 100);
	var torque_socket_plugin = document.getElementById("torque_socket_plugin");
	var tnl_test = document.getElementById("tnl_test");
	torque_socket_plugin.message("FOOOOOO!" + tnl_test.__moduleReady);
	if(tnl_test.__moduleReady == 1)
	{
		torque_socket_plugin.message("Module Ready!");
		clearTimeout(init_check_timeout);
		alert('The Native Client plugin is ready');
		
		var socket_instance = torque_socket_plugin.create_torque_socket();
		tnl_test.socket_instance = socket_instance;
		tnl_test.activate_socket();
		socket_instance.on_challenge_response = function(connection, key, message) { tnl_test.on_challenge_response(connection, key, message); }
		socket_instance.on_connect_request = function(connection, key, message) { tnl_test.on_connect_request(connection, key, message); }
		socket_instance.on_established = function(connection) { tnl_test.on_established(connection); }
		socket_instance.on_close = function(connection, reason) { tnl_test.on_close(connection, reason); }
		socket_instance.on_socket_packet = function(address, packet) { tnl_test.on_socket_packet(address, packet); }
		socket_instance.on_packet = function(connection, sequence, packet) { tnl_test.on_packet(connection, sequence, packet); }
		socket_instance.on_packet_delivery_notify = function(connection, send_sequence, delivery_status) { tnl_test.on_packet_delivery_notify(connection, send_sequence, delivery_status); }
		socket_instance.on_pong = function(str) { tnl_test.on_pong(str); }
		socket_instance.ping("FOO ftw");
		setTimeout("tick_game();", 1);
	}
}

</script>

</BODY>
</HTML>
+9 −3
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

#include <OpenGL/gl.h>
#include "test_tnl2.h"
#include "torque_sockets/torque_sockets_c_implementation.h"


tnl_test::test_game *game[2] = { 0, 0 };

@@ -32,8 +34,11 @@ void restart_games(bool game_1_is_server, bool game_2_is_server)
		a.set_port(0);
		a.to_sockaddr(&interface_bind_address2);
	}
	game[0] = new tnl_test::test_game(game_1_is_server, interface_bind_address1, ping_address);
	game[1] = new tnl_test::test_game(game_2_is_server, interface_bind_address2, ping_address);
	game[0] = new tnl_test::test_game(game_1_is_server, ping_address, &g_torque_socket_interface, 0);
	game[0]->_net_interface->bind(interface_bind_address1);
	
	game[1] = new tnl_test::test_game(game_2_is_server, ping_address, &g_torque_socket_interface, 0);
	game[1]->_net_interface->bind(interface_bind_address2);
}

void click_game(int game_index, float x, float y)
@@ -80,7 +85,8 @@ extern "C"
			a.set_port(0);
		a.to_sockaddr(&interface_bind_address);
		
		g = new tnl_test::test_game(server, interface_bind_address, ping_address);
		g = new tnl_test::test_game(server, ping_address, &g_torque_socket_interface, 0);
		g->_net_interface->bind(interface_bind_address);
		return g;
	}
	void shutdown_game(void *game)
Loading