Beispiel #1
0
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCGUIObject::Serialize(const char *address, char *buffer, int bufsize) {
    GUIObject *guio = (GUIObject*)address;
    StartSerialize(buffer);
    SerializeInt(guio->guin);
    SerializeInt(guio->objn);
    return EndSerialize();
}
Beispiel #2
0
void SerializeAI(XFILE *fp, int mode, ai_info *aip)
{
	SerializeInt(fp, mode, aip->shipnum);
	SerializeInt(fp, mode, aip->type);
	SerializeInt(fp, mode, aip->wing);
//MWA --	SerializeInt(fp, mode, aip->current_waypoint);
}
Beispiel #3
0
int ScriptOverlay::Serialize(const char *address, char *buffer, int bufsize) {
  StartSerialize(buffer);
  SerializeInt(overlayId);
  SerializeInt(borderWidth);
  SerializeInt(borderHeight);
  SerializeInt(isBackgroundSpeech);
  return EndSerialize();
}
// Writes a WebM BlockGroup with DiscardPadding. The structure is as follows:
// Indentation shows sub-levels
// BlockGroup
//  Block
//    Data
//  DiscardPadding
uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer,
                                    const uint8* data,
                                    uint64 length,
                                    int64 discard_padding,
                                    uint64 track_number,
                                    int64 timecode,
                                    uint64 is_key) {
    if (!data || length < 1 || discard_padding <= 0)
        return 0;

    const uint64 block_payload_size = 4 + length;
    const uint64 block_elem_size = EbmlMasterElementSize(kMkvBlock,
                                   block_payload_size) +
                                   block_payload_size;
    const uint64 discard_padding_elem_size = EbmlElementSize(kMkvDiscardPadding,
            discard_padding);
    const uint64 block_group_payload_size = block_elem_size +
                                            discard_padding_elem_size;
    const uint64 block_group_elem_size = EbmlMasterElementSize(
            kMkvBlockGroup,
            block_group_payload_size) +
                                         block_group_payload_size;

    if (!WriteEbmlMasterElement(writer, kMkvBlockGroup,
                                block_group_payload_size))
        return 0;

    if (!WriteEbmlMasterElement(writer, kMkvBlock, block_payload_size))
        return 0;

    if (WriteUInt(writer, track_number))
        return 0;

    if (SerializeInt(writer, timecode, 2))
        return 0;

    uint64 flags = 0;
    if (is_key)
        flags |= 0x80;
    if (SerializeInt(writer, flags, 1))
        return 0;

    if (writer->Write(data, static_cast<uint32>(length)))
        return 0;

    if (WriteID(writer, kMkvDiscardPadding))
        return 0;

    const uint64 size = GetUIntSize(discard_padding);
    if (WriteUInt(writer, size))
        return false;

    if (SerializeInt(writer, discard_padding, static_cast<int32>(size)))
        return false;

    return block_group_elem_size;
}
uint64 WriteSimpleBlock(IMkvWriter* writer,
                        const uint8* data,
                        uint64 length,
                        uint64 track_number,
                        int64 timecode,
                        uint64 is_key) {
    if (!writer)
        return false;

    if (!data || length < 1)
        return false;

    //  Here we only permit track number values to be no greater than
    //  126, which the largest value we can store having a Matroska
    //  integer representation of only 1 byte.

    if (track_number < 1 || track_number > 126)
        return false;

    //  Technically the timestamp for a block can be less than the
    //  timestamp for the cluster itself (remember that block timestamp
    //  is a signed, 16-bit integer).  However, as a simplification we
    //  only permit non-negative cluster-relative timestamps for blocks.

    if (timecode < 0 || timecode > kMaxBlockTimecode)
        return false;

    if (WriteID(writer, kMkvSimpleBlock))
        return 0;

    const int32 size = static_cast<int32>(length) + 4;
    if (WriteUInt(writer, size))
        return 0;

    if (WriteUInt(writer, static_cast<uint64>(track_number)))
        return 0;

    if (SerializeInt(writer, timecode, 2))
        return 0;

    uint64 flags = 0;
    if (is_key)
        flags |= 0x80;

    if (SerializeInt(writer, flags, 1))
        return 0;

    if (writer->Write(data, static_cast<uint32>(length)))
        return 0;

    const uint64 element_size =
        GetUIntSize(kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 + length;

    return element_size;
}
Beispiel #6
0
void cfile_serialize_editor(XFILE *fp, int flag)
{
	//	Editor only stuff
	SerializeMatrix(fp, flag, &view_orient);
	SerializeVector(fp, flag, &view_pos);
	
	SerializeInt(fp, flag, Control_mode);
	SerializeInt(fp, flag, cur_object_index);
	SerializeInt(fp, flag, cur_wing);

	SerializeGrid(fp, flag, The_grid);

}
Beispiel #7
0
void SerializeGrid(XFILE *fp, int mode, grid *gridp)
{
	int	i;

	SerializeInt(fp, mode, gridp->nrows);
	SerializeInt(fp, mode, gridp->ncols);
	SerializeMatrix(fp, mode, &gridp->gmatrix);
	SerializePhysicsInfo(fp, mode, &gridp->physics);
	SerializeFloat(fp, mode, gridp->square_size);
	SerializeFloat(fp, mode, gridp->planeD);
	
	for (i=0; i<MAX_GRID_POINTS; i++)
		SerializeVector(fp, mode, &gridp->gpoints[i]);

}
Beispiel #8
0
bool MRISerializable::SerializeString( const std::string& value, char*& buffer, int& buffer_size, int& ser_size )
{
	const char* char_array = value.c_str();
	int string_length = (int)strlen( char_array );

	// serialize string size
	if( !SerializeInt( string_length, buffer, buffer_size, ser_size ) )
	{
		GIRLogger::LogError( "MRISerializable::SerializeString -> SerializeInt failed, serialize failed!\n" );
		return false;
	}

	// serialize char array
	if( buffer_size < string_length )
	{
		GIRLogger::LogError( "MRISerializable::SerializeString -> buffer too small for char array, serialize failed!\n" );
		return false;
	}
	memcpy( buffer, char_array, string_length );

	buffer += string_length;
	ser_size += string_length;
	buffer_size -= string_length;

	return true;
}
int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
    if (!writer || size < 0 || size > 8)
        return -1;

    if (size > 0) {
        const uint64 bit = 1LL << (size * 7);

        if (value > (bit - 2))
            return -1;

        value |= bit;
    } else {
        size = 1;
        int64 bit;

        for (;;) {
            bit = 1LL << (size * 7);
            const uint64 max = bit - 2;

            if (value <= max)
                break;

            ++size;
        }

        if (size > 8)
            return false;

        value |= bit;
    }

    return SerializeInt(writer, value, size);
}
Beispiel #10
0
int ScriptDrawingSurface::Serialize(const char *address, char *buffer, int bufsize) {
  StartSerialize(buffer);
  SerializeInt(roomBackgroundNumber);
  SerializeInt(dynamicSpriteNumber);
  SerializeInt(dynamicSurfaceNumber);
  SerializeInt(currentColour);
  SerializeInt(currentColourScript);
  SerializeInt(highResCoordinates);
  SerializeInt(modified);
  SerializeInt(hasAlphaChannel);
  SerializeInt(isLinkedBitmapOnly ? 1 : 0);
  return EndSerialize();
}
int32 WriteID(IMkvWriter* writer, uint64 type) {
    if (!writer)
        return -1;

    writer->ElementStartNotify(type, writer->Position());

    const int32 size = GetUIntSize(type);

    return SerializeInt(writer, type, size);
}
Beispiel #12
0
void SerializePhysicsInfo(XFILE *fp, int mode, physics_info *pi)
{
	SerializeFloat(fp, mode, pi->mass);
	SerializeFloat(fp, mode, pi->drag);
	SerializeVector(fp, mode, &pi->max_thrust);
	SerializeVector(fp, mode, &pi->max_rotthrust);
	SerializeFloat(fp, mode, pi->turnroll);
	SerializeInt(fp, mode, pi->flags);
	SerializeVector(fp, mode, &pi->velocity);
	SerializeVector(fp, mode, &pi->rotvel);
	SerializeVector(fp, mode, &pi->thrust);
	SerializeVector(fp, mode, &pi->rotthrust);
}
Beispiel #13
0
int ScriptDateTime::Serialize(const char *address, char *buffer, int bufsize) {
  StartSerialize(buffer);
  SerializeInt(year);
  SerializeInt(month);
  SerializeInt(day);
  SerializeInt(hour);
  SerializeInt(minute);
  SerializeInt(second);
  SerializeInt(rawUnixTime);
  return EndSerialize();
}
Beispiel #14
0
bool MRISerializable::SerializeMRIDimensions( MRIDimensions& dimensions, char*& buffer, int& buffer_size, int& ser_size  )
{
	// serialize each dimension
	for( int i = 0; i < dimensions.GetNumDims() ; i++ )
	{
		int dim_size = 0;
		if( !dimensions.GetDim( i, dim_size ) || !SerializeInt( dim_size, buffer, buffer_size, ser_size ) )
		{
			GIRLogger::LogError( "MRISerializable::SerializeMRIDimensions -> SerializeInt failed!\n" );
			return false;
		}
	}
	return true;
}
Beispiel #15
0
/////////////////////////////////////////////////////////////////////////////
// CFREDDoc serialization
void SerializeObject(XFILE *fp, int mode, object *objp)
{
	SerializeInt(fp, mode, objp->signature);
	SerializeInt(fp, mode, objp->type);
	SerializeInt(fp, mode, objp->parent);
	SerializeInt(fp, mode, objp->parent_sig);
	SerializeInt(fp, mode, objp->parent_type);
	SerializeInt(fp, mode, objp->instance);
	SerializeInt(fp, mode, objp->flags);
	SerializeInt(fp, mode, objp->flags2);	// Goober5000 - code is obsolete, but I added this just in case
	SerializeFloat(fp, mode, objp->radius);
//	SerializeInt(fp, mode, objp->wing);
	SerializePhysicsInfo(fp, mode, &objp->phys_info);
	SerializeVector(fp, mode, &objp->pos);
	SerializeMatrix(fp, mode, &objp->orient);
}
Beispiel #16
0
void SerializeShip(XFILE *fp, int mode, ship *shipp)
{
	SerializeInt(fp, mode, shipp->objnum);
	SerializeInt(fp, mode, shipp->ai_index);
	SerializeInt(fp, mode, shipp->subtype);
	SerializeInt(fp, mode, shipp->modelnum);
	SerializeInt(fp, mode, shipp->hits);
	SerializeInt(fp, mode, shipp->dying);
}
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value) {
  if (!writer)
    return false;

  if (WriteID(writer, type))
    return false;

  if (WriteUInt(writer, kDateElementSize))
    return false;

  if (SerializeInt(writer, value, kDateElementSize))
    return false;

  return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value) {
    if (!writer)
        return false;

    if (WriteID(writer, type))
        return false;

    const uint64 size = GetUIntSize(value);
    if (WriteUInt(writer, size))
        return false;

    if (SerializeInt(writer, value, static_cast<int32>(size)))
        return false;

    return true;
}
Beispiel #19
0
/////////////////////////////////////////////////////////////////////////////
// CFREDDoc serialization
void SerializeObject(XFILE *fp, int mode, object *objp)
{
	SerializeInt(fp, mode, objp->signature);
	SerializeInt(fp, mode, objp->type);
	SerializeInt(fp, mode, objp->parent);
	SerializeInt(fp, mode, objp->parent_sig);
	SerializeInt(fp, mode, objp->parent_type);
	SerializeInt(fp, mode, objp->instance);
	SerializeInt(fp, mode, objp->flags);
	SerializeFloat(fp, mode, objp->radius);
//	SerializeInt(fp, mode, objp->wing);
	SerializePhysicsInfo(fp, mode, &objp->phys_info);
	SerializeVector(fp, mode, &objp->pos);
	SerializeMatrix(fp, mode, &objp->orient);
}
// We must write the metadata (key)frame as a BlockGroup element,
// because we need to specify a duration for the frame.  The
// BlockGroup element comprises the frame itself and its duration,
// and is laid out as follows:
//
//   BlockGroup tag
//   BlockGroup size
//     Block tag
//     Block size
//     (the frame is the block payload)
//     Duration tag
//     Duration size
//     (duration payload)
//
uint64 WriteMetadataBlock(IMkvWriter* writer,
                          const uint8* data,
                          uint64 length,
                          uint64 track_number,
                          int64 timecode,
                          uint64 duration) {
    // We don't backtrack when writing to the stream, so we must
    // pre-compute the BlockGroup size, by summing the sizes of each
    // sub-element (the block and the duration).

    // We use a single byte for the track number of the block, which
    // means the block header is exactly 4 bytes.

    // TODO(matthewjheaney): use EbmlMasterElementSize and WriteEbmlMasterElement

    const uint64 block_payload_size = 4 + length;
    const int32 block_size = GetCodedUIntSize(block_payload_size);
    const uint64 block_elem_size = 1 + block_size + block_payload_size;

    const int32 duration_payload_size = GetUIntSize(duration);
    const int32 duration_size = GetCodedUIntSize(duration_payload_size);
    const uint64 duration_elem_size = 1 + duration_size + duration_payload_size;

    const uint64 blockg_payload_size = block_elem_size + duration_elem_size;
    const int32 blockg_size = GetCodedUIntSize(blockg_payload_size);
    const uint64 blockg_elem_size = 1 + blockg_size + blockg_payload_size;

    if (WriteID(writer, kMkvBlockGroup))  // 1-byte ID size
        return 0;

    if (WriteUInt(writer, blockg_payload_size))
        return 0;

    //  Write Block element

    if (WriteID(writer, kMkvBlock))  // 1-byte ID size
        return 0;

    if (WriteUInt(writer, block_payload_size))
        return 0;

    // Byte 1 of 4

    if (WriteUInt(writer, track_number))
        return 0;

    // Bytes 2 & 3 of 4

    if (SerializeInt(writer, timecode, 2))
        return 0;

    // Byte 4 of 4

    const uint64 flags = 0;

    if (SerializeInt(writer, flags, 1))
        return 0;

    // Now write the actual frame (of metadata)

    if (writer->Write(data, static_cast<uint32>(length)))
        return 0;

    // Write Duration element

    if (WriteID(writer, kMkvBlockDuration))  // 1-byte ID size
        return 0;

    if (WriteUInt(writer, duration_payload_size))
        return 0;

    if (SerializeInt(writer, duration, duration_payload_size))
        return 0;

    // Note that we don't write a reference time as part of the block
    // group; no reference time(s) indicates that this block is a
    // keyframe.  (Unlike the case for a SimpleBlock element, the header
    // bits of the Block sub-element of a BlockGroup element do not
    // indicate keyframe status.  The keyframe status is inferred from
    // the absence of reference time sub-elements.)

    return blockg_elem_size;
}
void Object2Serialize( GameObject *obj, FILE *fp )
{
  SerializeInt( obj->id, fp );
  SerializeInt( CAST( obj, Object2 )->counter, fp );
}
Beispiel #22
0
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCHotspot::Serialize(const char *address, char *buffer, int bufsize) {
    ScriptHotspot *shh = (ScriptHotspot*)address;
    StartSerialize(buffer);
    SerializeInt(shh->id);
    return EndSerialize();
}
Beispiel #23
0
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCCharacter::Serialize(const char *address, char *buffer, int bufsize) {
    CharacterInfo *chaa = (CharacterInfo*)address;
    StartSerialize(buffer);
    SerializeInt(chaa->index_id);
    return EndSerialize();
}
// Writes a WebM BlockGroup with BlockAdditional data. The structure is as
// follows:
// Indentation shows sub-levels
// BlockGroup
//  Block
//    Data
//  BlockAdditions
//    BlockMore
//      BlockAddID
//        1 (Denotes Alpha)
//      BlockAdditional
//        Data
uint64 WriteBlockWithAdditional(IMkvWriter* writer,
                                const uint8* data,
                                uint64 length,
                                const uint8* additional,
                                uint64 additional_length,
                                uint64 add_id,
                                uint64 track_number,
                                int64 timecode,
                                uint64 is_key) {
    if (!data || !additional || length < 1 || additional_length < 1)
        return 0;

    const uint64 block_payload_size = 4 + length;
    const uint64 block_elem_size = EbmlMasterElementSize(kMkvBlock,
                                   block_payload_size) +
                                   block_payload_size;
    const uint64 block_additional_elem_size = EbmlElementSize(kMkvBlockAdditional,
            additional,
            additional_length);
    const uint64 block_addid_elem_size = EbmlElementSize(kMkvBlockAddID, add_id);

    const uint64 block_more_payload_size = block_addid_elem_size +
                                           block_additional_elem_size;
    const uint64 block_more_elem_size = EbmlMasterElementSize(
                                            kMkvBlockMore,
                                            block_more_payload_size) +
                                        block_more_payload_size;
    const uint64 block_additions_payload_size = block_more_elem_size;
    const uint64 block_additions_elem_size = EbmlMasterElementSize(
                kMkvBlockAdditions,
                block_additions_payload_size) +
            block_additions_payload_size;
    const uint64 block_group_payload_size = block_elem_size +
                                            block_additions_elem_size;
    const uint64 block_group_elem_size = EbmlMasterElementSize(
            kMkvBlockGroup,
            block_group_payload_size) +
                                         block_group_payload_size;

    if (!WriteEbmlMasterElement(writer, kMkvBlockGroup,
                                block_group_payload_size))
        return 0;

    if (!WriteEbmlMasterElement(writer, kMkvBlock, block_payload_size))
        return 0;

    if (WriteUInt(writer, track_number))
        return 0;

    if (SerializeInt(writer, timecode, 2))
        return 0;

    uint64 flags = 0;
    if (is_key)
        flags |= 0x80;
    if (SerializeInt(writer, flags, 1))
        return 0;

    if (writer->Write(data, static_cast<uint32>(length)))
        return 0;

    if (!WriteEbmlMasterElement(writer, kMkvBlockAdditions,
                                block_additions_payload_size))
        return 0;

    if (!WriteEbmlMasterElement(writer, kMkvBlockMore, block_more_payload_size))
        return 0;

    if (!WriteEbmlElement(writer, kMkvBlockAddID, add_id))
        return 0;

    if (!WriteEbmlElement(writer, kMkvBlockAdditional,
                          additional, additional_length))
        return 0;

    return block_group_elem_size;
}
Beispiel #25
0
void cfile_serialize(XFILE *fp, int flag)
{
	int	i;
	int	highest_object_index = 0, highest_ship_index = 0, highest_ai_index = 0;

	Assert((flag == 0) || (flag == 1));

//	fp = cfopen(filename, flag ? "wb" : "rb");
//	if (!fp)
//		MessageBox(NULL, strerror(errno), "File Open Error!", MB_ICONSTOP);

	//	Find highest used object if writing.
	if (flag == 1) {
		for (i=MAX_OBJECTS-1; i>0; i--)
			if (Objects[i].type != OBJ_NONE) {
				highest_object_index = i;
				break;
			}
	}

	if (flag == 0) {
		num_ships = 0;
		num_objects = 0;
	}

	SerializeInt(fp, flag, highest_object_index);

	for (i=1; i<=highest_object_index; i++) {
		SerializeObject(fp, flag, &Objects[i]);
		if (flag == 0)
			if (Objects[i].type != OBJ_NONE)
				num_objects++;
	}

	//	Read/write ships
	if (flag == 1) {
		for (i=MAX_SHIPS-1; i>0; i--)
			if (Ships[i].objnum) {
				highest_ship_index = i;
				break;
			}
	}

	SerializeInt(fp, flag, highest_ship_index);

	for (i=1; i<=highest_ship_index; i++) {
		SerializeShip(fp, flag, &Ships[i]);
		if (flag == 0)
			if (Ships[i].objnum)
				num_ships++;
	}

	// Read/write AI info
	if (flag == 1) {
		for (i=MAX_AI_INFO-1; i>0; i--)
			if (Ai_info[i].shipnum) {
				highest_ai_index = i;
				break;
			}
	}

	SerializeInt(fp, flag, highest_ai_index);
	
	for (i=1; i<=highest_ai_index; i++)
		SerializeAI(fp, flag, &Ai_info[i]);
}
Beispiel #26
0
// serialize the object into BUFFER (which is BUFSIZE bytes)
// return number of bytes used
int CCRegion::Serialize(const char *address, char *buffer, int bufsize) {
  ScriptRegion *shh = (ScriptRegion*)address;
  StartSerialize(buffer);
  SerializeInt(shh->id);
  return EndSerialize();
}
Beispiel #27
0
int CCAudioChannel::Serialize(const char *address, char *buffer, int bufsize) {
  ScriptAudioChannel *ach = (ScriptAudioChannel*)address;
  StartSerialize(buffer);
  SerializeInt(ach->id);
  return EndSerialize();
}