/*
 * Push one change to the stream (permanent mode)
 */
void	CCDBSynchronised::pushDeltaPermanent( NLMISC::CBitMemStream& s, CCDBStructNodeLeaf *node, uint32& bitsize )
{
	TCDBDataIndex index = node->getDataIndex();

	// Test if the property type is valid.
	if ( node->type() > ICDBStructNode::UNKNOWN && node->type() < ICDBStructNode::Nb_Prop_Type )
	{
		// Serialize the Property Value according to the Property Type.
		uint64 value;
		value = (uint64)_DataContainer.getValue64( index ); // "delta from 0"

		if ( node->type() == ICDBStructNode::TEXT )
		{
			s.serialAndLog2( value, 32 );
			bitsize += 32;
			if ( VerboseDatabase )
				nldebug( "CDB: Pushing permanent value %"NL_I64"d (TEXT-32) for index %d prop %s", (sint64)value, index, node->buildTextId().toString().c_str() );
		}
		else
		{
			s.serialAndLog2( value, (uint)node->type() );
			bitsize += (uint32)node->type();
			if ( VerboseDatabase )
				nldebug( "CDB: Pushing permanent value %"NL_I64"d (%u bits) for index %d prop %s", (sint64)value, (uint32)node->type(), index, node->buildTextId().toString().c_str() );
		}
	}
	else
		nlwarning("CCDBStructNodeLeaf::writeDeltaPermanent : Property Type Unknown ('%d') -> not serialized.", (uint)node->type());
}
Ejemplo n.º 2
0
/* Pack an action to a bit stream. Set transmitTimestamp=true for server-->client,
 * false for client-->server. If true, set the current gamecycle.
 */
void CActionFactory::pack (CAction *action, NLMISC::CBitMemStream &message, NLMISC::TGameCycle /* currentCycle */ )
{
	//H_BEFORE(FactoryPack);
	//sint32 val = message.getPosInBit ();

	//

	if (action->Code < 4)
	{
		// short code (0 1 2 3)
		bool shortcode = true;
		uint32 code = action->Code;
		message.serialAndLog1 (shortcode);
		message.serialAndLog2 (code, 2);
	}
	else
	{
		bool shortcode = false;
		message.serialAndLog1 (shortcode);
		message.serialAndLog1 (action->Code);
	}

	action->pack (message);
	//H_AFTER(FactoryPack);

	//OLIV: nlassertex (message.getPosInBit () - val == (sint32)CActionFactory::getInstance()->size (action), ("CActionFactory::pack () : action %d packed %u bits, should be %u, size() is wrong", action->Code, message.getPosInBit () - val, CActionFactory::getInstance()->size (action)));

//	nlinfo ("ac:%p pack one action in message %d %hu %u %d", action, action->Code, (uint16)(action->CLEntityId), val, message.getPosInBit()-val);
}
/*
 * Write the id to a bit stream for server-client comms, and return the size of data written
 */
inline sint ICDBStructNode::CBinId::writeToBitMemStream( NLMISC::CBitMemStream& f ) const
{
	sint bitsize = 0;
	for ( uint i=0; i<Ids.size(); i++ )
	{
		uint32& nodeIndex = const_cast<uint32&>(Ids[i].first);
		f.serialAndLog2( nodeIndex, Ids[i].second );
		bitsize += Ids[i].second;
	}
	return bitsize;
}