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

tnl2_test application now largely works. This is good.

parent 2b445415
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QtGui>
#include "window.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
	window the_window;
	the_window.resize(QSize(800, 400));
	the_window.show();
    return a.exec();
}
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ class building : public net_object
{
	typedef net_object parent;
public:
	declare_dynamic_class()

	/// Mask bits used to determine what states are out of date for this
	/// object and what then represent.
	enum {
+6 −10
Original line number Diff line number Diff line
@@ -6,16 +6,11 @@
class test_connection : public ghost_connection
{
	typedef ghost_connection parent;
	bool _is_initiator;
public:
	test_connection(bool is_initiator = false)
	{
		_is_initiator = is_initiator;
	}
	declare_dynamic_class()

	bool is_initiator()
	test_connection(bool is_initiator = false) : parent(is_initiator)
	{
		return _is_initiator;
	}
	
	/// The player object associated with this connection.
@@ -39,7 +34,7 @@ public:
	
	void on_connection_terminated(bit_stream *the_stream)
	{
		if(is_initiator())
		if(is_connection_initiator())
			((test_net_interface *) get_interface())->_pinging_servers = true;
		else
			delete (player*) _player;
@@ -58,7 +53,8 @@ public:
		// To see how this program performs with 50% packet loss, Try uncommenting the next line :)
		//setSimulatedNetParams(0.5, 0);
		
		if(is_initiator())
		set_type_database(((test_net_interface *) get_interface())->get_game()->get_type_database());
		if(is_connection_initiator())
		{
			set_ghost_from(false);
			set_ghost_to(true);
+49 −16
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@

#include "tomcrypt.h"
#include "platform/platform.h"
#include "torque_sockets_ref.h"
#include "torque_socket_event.h"

namespace core
{
@@ -22,6 +22,8 @@ namespace core
			result = ((result << 8) | (result >> 24)) ^ uint32(*buf++);
		return result;
	}
	int _log_index = 0;

	void logprintf(const char *format, ...)
	{
		char buffer[4096];
@@ -29,8 +31,9 @@ namespace core
		va_list s;
		va_start( s, format );
		int32 len = vsnprintf(buffer + bufferStart, sizeof(buffer) - bufferStart, format, s);
		printf("LOG: %s\n", buffer);
		printf("LOG %d: %s\n", _log_index, buffer);
		va_end(s);
		fflush(stdout);
	}
		
	template <typename signature> uint32 hash_method(signature the_method)
@@ -42,7 +45,7 @@ namespace core
	};
};

#include "torque_sockets_implementation.h"
//#include "torque_sockets_implementation.h"

namespace core
{
@@ -62,35 +65,65 @@ namespace core
		#include "test_net_interface.h"
	};

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

using namespace core;

void init_game()
void restart_games(bool game_1_is_server, bool game_2_is_server)
{
	SOCKADDR interface_bind_address, ping_address;
	ltc_mp = ltm_desc;
	if(game[0])
		delete game[0];
	if(game[1])
		delete game[1];

	SOCKADDR interface_bind_address1, interface_bind_address2, ping_address;
	net::address a;
	a.to_sockaddr(&interface_bind_address);
	a.set_port(28000);
	a.to_sockaddr(&ping_address);
	client_game = new tnl_test::test_game(true, interface_bind_address, ping_address);
	if(game_1_is_server)
		a.to_sockaddr(&interface_bind_address1);
	else
	{
		a.set_port(0);
		a.to_sockaddr(&interface_bind_address1);
	}

void click_game(float x, float y)
	a.set_port(28001);
	if(game_2_is_server)
		a.to_sockaddr(&interface_bind_address2);
	{
		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);
}

void click_game(int game_index, float x, float y)
{
	tnl_test::position p;
	p.x = x;
	p.y = y;
	if(game[game_index])
		game[game_index]->move_my_player_to(p);
}

void tick_game()
void tick_games()
{
	client_game->tick();
	core::_log_index = 0;
	if(game[0])
		game[0]->tick();
	core::_log_index = 1;
	if(game[1])
		game[1]->tick();
}

/// renderFrame is called by the platform windowing code to notify the game
/// that it should render the current world using the specified window area.
void render_game_scene()
void render_game_scene(int game_index)
{
	client_game->render_frame();
	if(game[game_index])
		game[game_index]->render_frame();
}
+21 −1
Original line number Diff line number Diff line
@@ -10,17 +10,32 @@ public:
	safe_ptr<player> _server_player; ///< the player that the server controls
	safe_ptr<player> _client_player; ///< the player that this client controls, if this game is a client
	random_generator _random;
	context _context;
	type_database _type_database;
	
	enum {
		test_connection_identifier_token = 0xBEEF,
	};
	/// Constructor for test_game, determines whether this game will be a client or a server, and what addresses to bind to and ping.  If this game is a server, it will construct 50 random _buildings and 15 random AI _players to populate the "world" with.  test_game also constructs an AsymmetricKey to demonstrate establishing secure connections with clients and servers.
	test_game(bool server, SOCKADDR &interface_bind_address, SOCKADDR &ping_address)
	test_game(bool server, SOCKADDR &interface_bind_address, SOCKADDR &ping_address) : _type_database(&_context)
	{
		_is_server = server;
		_net_interface = new test_net_interface(this, _is_server, interface_bind_address, ping_address);
		_net_interface->add_connection_type<test_connection>(test_connection_identifier_token);

		//TNL::AsymmetricKey *theKey = new TNL::AsymmetricKey(32);
		//_net_interface->setPrivateKey(theKey);
		//_net_interface->setRequiresKeyExchange(true);
		random_generator g;
		
		tnl_begin_class(_type_database, position, empty_type, false)
		tnl_slot(_type_database, position, x, 0)
		tnl_slot(_type_database, position, y, 0)
		tnl_end_class(_type_database)
		
		player::register_class(_type_database);
		building::register_class(_type_database);

		_last_time = time::get_current();
		
		if(_is_server)
@@ -55,6 +70,11 @@ public:
		logprintf("Destroyed a %s...", (this->_is_server ? "server" : "client"));
	}
	
	type_database *get_type_database()
	{
		return &_type_database;
	}
		
	/// Called periodically by the platform windowing code, tick will update all the _players in the simulation as well as tick() the game's network interface.
	void tick()
	{
Loading