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

tnl2_test is now fully working both client and server

parent 26cf2bf0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -310,16 +310,16 @@ public:
			//int32 start = bstream.get_bit_position();
			uint32 rpc_index = bstream.read_integer(_rpc_id_bit_size);
			if(rpc_index >= _rpc_count)
				throw tnl_exception_invalid_packet;
				assert(0); //throw tnl_exception_invalid_packet;
			
			rpc_record &the_rpc = rpc_methods[rpc_index];
			
			functor *func = the_rpc.creator->create();
			
			// check if the direction this event moves is a valid direction.
			if(   (the_rpc.direction == rpc_initiator_to_host && is_connection_host())
			   || (the_rpc.direction == rpc_host_to_initiator && is_connection_initiator()) )
				throw tnl_exception_invalid_packet;
			if(   (the_rpc.direction == rpc_initiator_to_host && is_connection_initiator())
			   || (the_rpc.direction == rpc_host_to_initiator && is_connection_host()) )
				assert(0); //throw tnl_exception_invalid_packet;
			func->read(bstream);
			
			if(unguaranteed_phase)
+8 −10
Original line number Diff line number Diff line
@@ -11,18 +11,14 @@ class ghost_connection : public event_connection
public:
	/// ghost_ref tracks an update sent in one packet for the ghost of one net_object.
	///
	/// When we are notified that a pack is sent/lost, this is used to determine what
	/// updates need to be resent and so forth.
	/// When we are notified that a pack is sent/lost, this is used to determine what updates need to be resent and so forth.
	struct ghost_ref
	{
		uint32 mask; ///< The mask of bits that were updated in this packet
		uint32 ghost_info_flags;    ///< ghost_info::Flags bitset, determes if the ghost is in a
		///  special processing mode (created/deleted)
		ghost_info *ghost;      ///< The ghost information for the object on the connection that sent
		///  the packet this ghost_ref is attached to
		uint32 ghost_info_flags; ///< ghost_info::Flags bitset, determes if the ghost is in a special processing mode (created/deleted)
		ghost_info *ghost; ///< The ghost information for the object on the connection that sent the packet this ghost_ref is attached to
		ghost_ref *next_ref; ///< The next ghost updated in this packet
		ghost_ref *update_chain; ///< A pointer to the ghost_ref on the least previous packet that
		///  updated this ghost, or NULL, if no prior packet updated this ghost
		ghost_ref *update_chain; ///< A pointer to the ghost_ref on the least previous packet that updated this ghost, or NULL, if no prior packet updated this ghost
	};
	
	/// Notify structure attached to each packet with information about the ghost updates in the packet
@@ -428,6 +424,7 @@ protected:
					
					if(!obj->on_ghost_add(this))
						throw tnl_exception_ghost_add_failed;
					obj->on_ghost_update(0xFFFFFFFF);
				}
				else
				{
@@ -437,6 +434,7 @@ protected:

					uint32 update_mask = bstream.read_integer(type_rep->max_state_index);
					read_object_update(bstream, object_pointer, type_rep, update_mask);
					_local_ghosts[index]->on_ghost_update(update_mask);
				}
				TorqueLogMessageFormatted(LogGhostConnection, ("ghost_connection %s read GHOST %d", ttr->name.c_str(), bstream.get_bit_position() - start_position));
			}
+14 −3
Original line number Diff line number Diff line
@@ -187,13 +187,18 @@ public:
	/// @note This is a server side call. It has no meaning for ghosts.
	void set_mask_bits(uint32 or_mask)
	{
		if(is_ghost())
			return;
		assert(or_mask != 0);
		//Assert(_dirty_mask_bits == 0 || (_prev_dirty_list != NULL || _next_dirty_list != NULL || _dirty_list == this), "Invalid dirty list state.");
		if(!_dirty_mask_bits && _interface)
		if(_interface)
		{
			if(!_dirty_mask_bits)
				_interface->add_to_dirty_list(this);

			_dirty_mask_bits |= or_mask;
		}
	}
	
	void set_dirty_state(uint32 state_index)
	{
@@ -217,6 +222,12 @@ public:
	{
	}
	
	/// on_ghost_update is called on the ghost when a portion of its states have been updated from the host.  For the initial update this will be called after on_ghost_add
	virtual void on_ghost_update(uint32 mask_bits)
	{

	}

	/// get_net_index returns the index tag used to identify the server copy
	/// of a client ref_object.
	uint32 get_net_index() { return _remote_index; }
+9 −6
Original line number Diff line number Diff line
@@ -24,12 +24,15 @@ public:
		// place the "building" in a random position on the screen
		if(random_gen)
		{
			
			upper_left.x = random_gen->random_unit_float();
			upper_left.y = random_gen->random_unit_float();

			lower_right.x = upper_left.x + random_gen->random_unit_float() * 0.1f + 0.025f;
			lower_right.y = upper_left.y + random_gen->random_unit_float() * 0.1f + 0.025f;
			if(lower_right.x > 1)
				lower_right.x = 1;
			if(lower_right.y > 1)
				lower_right.y = 1;
		}
		else
		{
+26 −0
Original line number Diff line number Diff line
@@ -9,8 +9,34 @@ class test_connection : public ghost_connection
public:
	declare_dynamic_class()

	void rpc_set_control_object(enumeration<ghost_connection::max_ghost_count> player_id)
	{
		logprintf("My player = %d", uint32(player_id));
		net_object *the_object = resolve_ghost(player_id);
		if(the_object)
		{
			player *the_player = dynamic_cast<player *>(the_object);
			if(the_player)
				((test_net_interface *) get_interface())->get_game()->_client_player = the_player;
		}
	}

	void rpc_move_my_player_to(unit_float<12> x, unit_float<12> y)
	{
		position new_position;
		new_position.x = x;
		new_position.y = y;

		logprintf("received new position (%g, %g) from client",
					   float32(new_position.x), float32(new_position.y));
		_player->server_set_position(_player->_render_pos, new_position, 0, 0.2f);
	};


	test_connection(bool is_initiator = false) : parent(is_initiator)
	{
		register_rpc(&test_connection::rpc_set_control_object, rpc_guaranteed_ordered, rpc_host_to_initiator);
		register_rpc(&test_connection::rpc_move_my_player_to, rpc_guaranteed_ordered, rpc_initiator_to_host);
	}
	
	/// The player object associated with this connection.
Loading