void CFlowGraphModule::RemoveCompletedInstances() { for (TInstanceList::iterator it = m_instances.begin(), end = m_instances.end(); it != end; ++it) { if (!it->bUsed) { *it = SInstance(MODULEINSTANCE_INVALID); } } stl::find_and_erase_all(m_instances, SInstance(MODULEINSTANCE_INVALID)); if (m_instances.size() == 0) m_nextInstanceId = 0; }
dl_error_t dl_internal_convert_no_header( dl_ctx_t dl_ctx, unsigned char* packed_instance, unsigned char* packed_instance_base, unsigned char* out_instance, size_t out_instance_size, size_t* needed_size, dl_endian_t src_endian, dl_endian_t out_endian, dl_ptr_size_t src_ptr_size, dl_ptr_size_t out_ptr_size, const SDLType* root_type, size_t base_offset ) { dl_binary_writer writer; dl_binary_writer_init( &writer, out_instance, out_instance_size, out_instance == 0x0, src_endian, out_endian, out_ptr_size ); SConvertContext ConvCtx( src_endian, out_endian, src_ptr_size, out_ptr_size ); ConvCtx.m_lInstances.Add(SInstance(packed_instance, root_type, 0x0, dl_type_t(DL_TYPE_ATOM_POD | DL_TYPE_STORAGE_STRUCT))); dl_error_t err = dl_internal_convert_collect_instances(dl_ctx, root_type, packed_instance, packed_instance_base, ConvCtx); // TODO: we need to sort the instances here after their offset! SInstance* insts = ConvCtx.m_lInstances.GetBasePtr(); std::sort( insts, insts + ConvCtx.m_lInstances.Len(), dl_internal_sort_pred ); for(unsigned int i = 0; i < ConvCtx.m_lInstances.Len(); ++i) { err = dl_internal_convert_write_instance( dl_ctx, ConvCtx.m_lInstances[i], &ConvCtx.m_lInstances[i].m_OffsetAfterPatch, ConvCtx, &writer ); if(err != DL_ERROR_OK) return err; } if(out_instance != 0x0) // no need to patch data if we are only calculating size { for(unsigned int i = 0; i < ConvCtx.m_lPatchOffset.Len(); ++i) { SConvertContext::PatchPos& PP = ConvCtx.m_lPatchOffset[i]; // find new offset pint NewOffset = pint(-1); for(unsigned int j = 0; j < ConvCtx.m_lInstances.Len(); ++j ) { pint OldOffset = ConvCtx.m_lInstances[j].m_pAddress - packed_instance_base; if(OldOffset == PP.m_OldOffset) { NewOffset = ConvCtx.m_lInstances[j].m_OffsetAfterPatch; break; } } DL_ASSERT(NewOffset != pint(-1) && "We should have found the instance!"); dl_binary_writer_seek_set( &writer, PP.m_Pos ); dl_binary_writer_write_ptr( &writer, NewOffset + base_offset ); } } dl_binary_writer_seek_end( &writer ); *needed_size = (unsigned int)dl_binary_writer_tell( &writer ); return err; }
static dl_error_t dl_internal_convert_collect_instances( dl_ctx_t dl_ctx, const SDLType* type, const uint8* data, const uint8* base_data, SConvertContext& convert_ctx ) { for(uint32 iMember = 0; iMember < type->member_count; ++iMember) { const SDLMember& Member = type->members[iMember]; const uint8* pMemberData = data + Member.offset[convert_ctx.m_SourcePtrSize]; dl_type_t AtomType = Member.AtomType(); dl_type_t StorageType = Member.StorageType(); switch(AtomType) { case DL_TYPE_ATOM_POD: { switch( StorageType ) { case DL_TYPE_STORAGE_STR: { pint Offset = DLInternalReadPtrData( pMemberData, convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize ); convert_ctx.m_lInstances.Add(SInstance(base_data + Offset, 0x0, 1337, Member.type)); } break; case DL_TYPE_STORAGE_PTR: { const SDLType* pSubType = dl_internal_find_type(dl_ctx, Member.type_id); if(pSubType == 0x0) return DL_ERROR_TYPE_NOT_FOUND; pint Offset = DLInternalReadPtrData(pMemberData, convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize); const uint8* pPtrData = base_data + Offset; if(Offset != DL_NULL_PTR_OFFSET[convert_ctx.m_SourcePtrSize] && !convert_ctx.IsSwapped(pPtrData)) { convert_ctx.m_lInstances.Add(SInstance(pPtrData, pSubType, 0, Member.type)); dl_internal_convert_collect_instances(dl_ctx, pSubType, base_data + Offset, base_data, convert_ctx); } } break; case DL_TYPE_STORAGE_STRUCT: { const SDLType* pSubType = dl_internal_find_type(dl_ctx, Member.type_id); if(pSubType == 0x0) return DL_ERROR_TYPE_NOT_FOUND; dl_internal_convert_collect_instances(dl_ctx, pSubType, pMemberData, base_data, convert_ctx); } break; default: break; } } break; case DL_TYPE_ATOM_INLINE_ARRAY: { switch(StorageType) { case DL_TYPE_STORAGE_STRUCT: { const SDLType* pSubType = dl_internal_find_type(dl_ctx, Member.type_id); if(pSubType == 0x0) return DL_ERROR_TYPE_NOT_FOUND; for (pint ElemOffset = 0; ElemOffset < Member.size[convert_ctx.m_SourcePtrSize]; ElemOffset += pSubType->size[convert_ctx.m_SourcePtrSize]) dl_internal_convert_collect_instances(dl_ctx, pSubType, pMemberData + ElemOffset, base_data, convert_ctx); } break; case DL_TYPE_STORAGE_STR: { // TODO: This might be optimized if we look at all the data in i inline-array of strings as 1 instance continious in memory. // I am not sure if that is true for all cases right now! uint32 PtrSize = (uint32)dl_internal_ptr_size(convert_ctx.m_SourcePtrSize); uint32 Count = Member.size[convert_ctx.m_SourcePtrSize] / PtrSize; for (pint iElem = 0; iElem < Count; ++iElem) { pint Offset = DLInternalReadPtrData(data + (iElem * PtrSize), convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize); convert_ctx.m_lInstances.Add(SInstance(base_data + Offset, 0x0, Count, dl_type_t(DL_TYPE_ATOM_POD | DL_TYPE_STORAGE_STR))); } } break; default: DL_ASSERT(Member.IsSimplePod() || StorageType == DL_TYPE_STORAGE_ENUM); // ignore } } break; case DL_TYPE_ATOM_ARRAY: { pint Offset = 0; uint32 Count = 0; dl_internal_read_array_data( pMemberData, &Offset, &Count, convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize ); if(Offset == DL_NULL_PTR_OFFSET[convert_ctx.m_SourcePtrSize]) { DL_ASSERT( Count == 0 ); break; } switch(StorageType) { case DL_TYPE_STORAGE_STR: { // TODO: This might be optimized if we look at all the data in i inline-array of strings as 1 instance continious in memory. // I am not sure if that is true for all cases right now! uint32 PtrSize = (uint32)dl_internal_ptr_size(convert_ctx.m_SourcePtrSize); const uint8* pArrayData = base_data + Offset; convert_ctx.m_lInstances.Add(SInstance(base_data + Offset, 0x0, Count, Member.type)); for (pint iElem = 0; iElem < Count; ++iElem) { pint ElemOffset = DLInternalReadPtrData(pArrayData + (iElem * PtrSize), convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize); convert_ctx.m_lInstances.Add(SInstance(base_data + ElemOffset, 0x0, Count, dl_type_t(DL_TYPE_ATOM_POD | DL_TYPE_STORAGE_STR))); } } break; case DL_TYPE_STORAGE_STRUCT: { dl_internal_read_array_data( pMemberData, &Offset, &Count, convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize ); const uint8* pArrayData = base_data + Offset; const SDLType* pSubType = dl_internal_find_type(dl_ctx, Member.type_id); if(pSubType == 0x0) return DL_ERROR_TYPE_NOT_FOUND; convert_ctx.m_lInstances.Add(SInstance(pArrayData, pSubType, Count, Member.type)); for (pint ElemOffset = 0; ElemOffset < pSubType->size[convert_ctx.m_SourcePtrSize] * Count; ElemOffset += pSubType->size[convert_ctx.m_SourcePtrSize]) dl_internal_convert_collect_instances(dl_ctx, pSubType, pArrayData + ElemOffset, base_data, convert_ctx); } break; default: { DL_ASSERT(Member.IsSimplePod() || StorageType == DL_TYPE_STORAGE_ENUM); dl_internal_read_array_data( pMemberData, &Offset, &Count, convert_ctx.m_SourceEndian, convert_ctx.m_SourcePtrSize ); convert_ctx.m_lInstances.Add(SInstance(base_data + Offset, 0x0, Count, Member.type)); } break; } } break; case DL_TYPE_ATOM_BITFIELD: // ignore break; default: DL_ASSERT(false && "Invalid ATOM-type!"); } } return DL_ERROR_OK; }