Пример #1
0
void SF2Reader::readList(SimpleArray<T, E>& a, const chunkHeader& h) {
    size_t n = h.chunkSize;
    if(n%sizeof(T)!=0)
        throw ReadError("list "+std::string(h.chunkId, 4)+" not a multiple of record size");
    Assert(n/sizeof(T)>=E);
    a.resize(n/sizeof(T)-E);
    readArray(a.begin(), a.size()+E);
}
Пример #2
0
//-------------------------------------------------------------------
// SimpleString replacedata contains data to replace with.
bool ReplaceDlg::replace_selected_data(HWindow *pDlg)
{
    if (!bSelected)
    {
        MessageBox(pDlg, GetLangString(IDS_REPL_NO_DATA), MB_ICONERROR);
        return false;
    }
    int i = iGetStartOfSelection();
    int n = iGetEndOfSelection() - i + 1;
    SimpleArray<BYTE> olddata(n, &m_dataArray[i]);
    if (strReplaceWithData.IsEmpty())
    {
        // Selected data is to be deleted, since replace-with data is empty string.
        if (!m_dataArray.Replace(i, n, 0, 0))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_CANT_DELETE), MB_ICONERROR);
            return FALSE;
        }
        push_undorecord(i, olddata, olddata.GetLength(), NULL, 0);
        bSelected = false;
        iCurByte = iStartOfSelection;
    }
    else if (bPasteAsText)
    {
        // Replace with non-zero-length data.
        if (!m_dataArray.Replace(i, n, (const BYTE *)(const char *)strReplaceWithData, strReplaceWithData.StrLen()))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_FAILED), MB_ICONERROR);
            return false;
        }
        push_undorecord(i, olddata, olddata.GetLength(), (const BYTE *)(const char *)strReplaceWithData, strReplaceWithData.StrLen());
        iEndOfSelection = iStartOfSelection + strReplaceWithData.StrLen() - 1;
    }
    else
    {
        // Input string contains special-syntax-coded binary data.
        SimpleArray<BYTE> out;
        if (!transl_text_to_binary(out))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_CANNOT_CONVERT), MB_ICONERROR);
            return false;
        }
        if (!m_dataArray.Replace(i, n, out, out.GetLength()))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_FAILED), MB_ICONERROR);
            return false;
        }
        push_undorecord(i, olddata, olddata.GetLength(), out, out.GetLength());
        iEndOfSelection = iStartOfSelection + out.GetLength() - 1;
    }
    bFilestatusChanged = true;
    return true;
}
Пример #3
0
BOOL Game::checkForCollisions()
{
	// NOTE: Things happen here in a specific order.  Collisions between non-wall objects
	// MUST MUST MUST happen before wall collisions.  The reason is that the player could
	// collide with a dragon and thus bounce off.  If this were to occur after wall collisions were
	// calculated, the player would more easily bounce through a wall.

    UINT i;
	SimpleArray *walls = itsPlayer->getRoom()->getWalls();
	GameObject *bridge = itsPlayer->getRoom()->searchRoom(GameObject::GAMEOBJECT_TYPE_BRIDGE);

	// TODO: clean this up
    SimpleArray *objects = itsWorld->getObjects();
    for (i=0;i<objects->length();i++)
    {
		GameObject *object = (GameObject *)(objects->elementAt(i));
		
		if (object->getType() == GameObject::GAMEOBJECT_TYPE_WALL)
			continue;

		for (UINT j=1;j<objects->length();j++)
		{
			GameObject *object2 = (GameObject *)(objects->elementAt(j));
			if (object2->getType() == GameObject::GAMEOBJECT_TYPE_WALL)
				continue;

			if (object->isColliding(object2))
			{
				object->collision(itsLastTickTime,object2);
				object2->collision(itsLastTickTime,object);
			}
		}
    }

	RECT playerRect;
	itsPlayer->getRect(&playerRect);

	BOOL onBridge = FALSE;
	for (i=0;i<walls->length();i++)
	{
	    Wall *thisWall = (Wall *)(walls->elementAt(i));
		if (thisWall->isColliding(itsPlayer))
		{
			// If the player's rect is colliding with the bridge, but not their actual pixels
			// (in other words, inside the bridge's rect, but not touching the bridge itself)
			if ( (bridge != NULL) && (ON_BRIDGE(bridge,itsPlayer,playerRect)) )
			{
				onBridge = TRUE;
			}
			else
			{
				itsPlayer->collision(itsLastTickTime,thisWall);
			}
		}
	}
	itsPlayer->setOnBridge(onBridge);

    return TRUE;
}
Пример #4
0
/**\brief Add copied entities/sets recursively
 *
 * Helper function for process_ce_sets. This adds any entities directly
 * contained in the current set to the dest set and then loops through the
 * contained sets and adds the children if they are also CE sets. If not, it
 * adds the entities in the child set and recurses down a level.
 * \param imeshImpl the iMesh instance handle
 * \param src the source set
 * \param current the child set to examine (start with current == src)
 * \param local_tag the tag relating source and target sets
 */
static
void process_ce_subsets(iMesh_Instance imeshImpl, iBase_EntitySetHandle src,
                        iBase_EntitySetHandle current,
                        const std::set<iBase_EntitySetHandle> &cesets,
                        iBase_TagHandle local_tag) 
{
  int err;
  iBase_EntitySetHandle dest;

  // First, add entities directly contained in this set.
  std::vector<iBase_EntityHandle> tmp_tags;
  get_copied_ents(imeshImpl, current, local_tag, tmp_tags);

  if (!tmp_tags.empty()) {
    get_dest_set(imeshImpl, local_tag, src, &dest);
    iMesh_addEntArrToSet(imeshImpl, &tmp_tags[0], tmp_tags.size(), dest,
                         &err);
    check_error(imeshImpl, err);
  }

  // Next, start looking at children.
  SimpleArray<iBase_EntitySetHandle> children;
  iMesh_getEntSets(imeshImpl, current, 1, ARRAY_INOUT(children), &err);
  check_error(imeshImpl, err);

  for (int i = 0; i < children.size(); i++) {

    // If this child set is one of our cesets, add just the set...
    if (cesets.find(children[i]) != cesets.end()) {
      get_dest_set(imeshImpl, local_tag, src, &dest);
      if (src == dest) continue;

      iMesh_addEntSet(imeshImpl, children[i], dest, &err);
      check_error(imeshImpl, err);
    }

    // ... otherwise, add the entities and recurse into the next level of
    // children.
    else {
      process_ce_subsets(imeshImpl, src, children[i], cesets, local_tag);
    }
  }
}
Пример #5
0
//-------------------------------------------------------------------
// Translate the text in the string to binary data and store in the array.
int ReplaceDlg::transl_text_to_binary(SimpleArray<BYTE> &out)
{
    BYTE *pcOut;
    int destlen = create_bc_translation(&pcOut,
                                        strReplaceWithData, strReplaceWithData.StrLen(),
                                        iCharacterSet, iBinaryMode);
    if (destlen)
        out.Adopt(pcOut, destlen - 1, destlen);
    return destlen;
}
Пример #6
0
/**
 * @brief Create translation of bytecode-string.
 * @param [in] sa Array where the string is added.
 * @param [in] charmode ANSI/OEM character set.
 * @param [in] binmode BIG/LITTLE endian.
 * @return TRUE if translation succeeded, FALSE otherwise.
 */
int Text2BinTranslator::GetTrans2Bin(SimpleArray<BYTE>& sa, int charmode, int binmode)
{
	sa.ClearAll();

	int destlen = iLengthOfTransToBin(m_str.c_str(), m_str.length());
	if (destlen > 0)
	{
		sa.SetSize(destlen);
		sa.ExpandToSize();
		iCreateBcTranslation((BYTE*) sa, m_str.c_str(), m_str.length(), charmode, binmode);
		return TRUE;
	}
	else
	{
		// Empty input string => don't allocate anything and return 0.
		return FALSE;
	}

	return TRUE;
}
Пример #7
0
// Performs a reverse topological traversal, starting from the exit block and
// following back-edges.  The dominator is serialized before any predecessors,
// which guarantees that all blocks are serialized after their dominator and
// before their post-dominator (because it's a reverse topological traversal).
// ID should be initially set to 0.
//
// This sort assumes that (1) dominators have been computed, (2) there are no
// critical edges, and (3) the entry block is reachable from the exit block
// and no blocks are accessible via traversal of back-edges from the exit that
// weren't accessible via forward edges from the entry.
unsigned BasicBlock::topologicalFinalSort(SimpleArray<BasicBlock *> &Blocks,
                                          unsigned ID) {
  // Visited is assumed to have been set by the topologicalSort.  This pass
  // assumes !Visited means that we've visited this node before.
  if (!Visited) return ID;
  Visited = false;
  if (DominatorNode.Parent)
    ID = DominatorNode.Parent->topologicalFinalSort(Blocks, ID);
  for (auto *Pred : Predecessors)
    ID = Pred->topologicalFinalSort(Blocks, ID);
  assert(static_cast<size_t>(ID) < Blocks.size());
  BlockID = ID++;
  Blocks[BlockID] = this;
  return ID;
}
Пример #8
0
Boolean operator == (const SimpleArray<T>& Obj1_, const SimpleArray<T>& Obj2_)
{
  return (Obj1_.IsEqual(Obj2_));
}
Пример #9
0
Boolean operator <= (const SimpleArray<T>& Obj1_, const SimpleArray<T>& Obj2_)
{
  return (Obj1_.IsEqual(Obj2_) || Obj1_.IsLesser(Obj2_));
}
Пример #10
0
SimpleArrayIter<T>::SimpleArrayIter(SimpleArray<T>& a):
_Target(a),
_ElemFirst(a.Base()),
_ElemLast(a.Base() + a.GetCount() - 1),
_ElemPtr(a.Base())
{}
Пример #11
0
Boolean operator >= (const SimpleArray<T>& Obj1_, const SimpleArray<T>& Obj2_)
{
  return (Obj1_.IsEqual(Obj2_) || Obj1_.IsGreater(Obj2_));
}
Пример #12
0
void Discretize_Geometric_Model(GeomMesh &geomesh)
{
    char *options = NULL;
    int optlen = 0;
    int err;

    iMesh_Instance mesh = geomesh.mesh;
    iGeom_Instance geom = geomesh.geom;
    iRel_Instance assoc = geomesh.assoc;
    iRel_RelationHandle relation00 = geomesh.relation00;

    iBase_EntitySetHandle geomRootSet = geomesh.geomRootSet;

    ///////////////////////////////////////////////////////////////////////////////
    // Step I: Collect all the feature nodes in Geometry:
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoNodes;
    iGeom_getEntities(geom, geomRootSet, iBase_VERTEX, ARRAY_INOUT(geoNodes), &err);

    double x, y, z;
    iBase_EntityHandle newHandle;
    for (int i = 0; i < geoNodes.size(); i++)
    {
        iGeom_getVtxCoord(geom, geoNodes[i], &x, &y, &z, &err);
        iMesh_createVtx(mesh, x, y, z, &newHandle, &err);
        iRel_setEntEntAssociation(assoc, relation00, geoNodes[i], newHandle, &err);
    }

    ///////////////////////////////////////////////////////////////////////////////
    // Step II: Collect all the geometric edges and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoEdges;
    iGeom_getEntities(geom, geomRootSet, iBase_EDGE, ARRAY_INOUT(geoEdges), &err);

    int numGeoEdges = geoEdges.size();

    vector<double> elen(numGeoEdges);
    for (int i = 0; i < numGeoEdges; i++) {
        elen[i] = get_geom_edge_length(geom, geoEdges[i]);
    }
    vector<double> tmpelen;
    tmpelen = elen;
    sort( tmpelen.begin(), tmpelen.end() );
    double mean_edge_length = tmpelen[numGeoEdges/2];

    cout << " Minimum Edge Length : " << *min_element( elen.begin(), elen.end() ) << endl;
    cout << " Maximum Edge Length : " << *max_element( elen.begin(), elen.end() ) << endl;
    cout << " Mean Length         : " <<  mean_edge_length << endl;

    double spacing = mean_edge_length /(double) 10.0;

    int numEdges;
    EdgeMesher *edgeMesher = geomesh.edgeMesher;
    for (int i = 0; i < numGeoEdges; i++) {
        if( elen[i] < 0.5*mean_edge_length) 
            numEdges = 1;
        else
            numEdges = elen[i]/ spacing;

        edgeMesher->discretize(geomesh, geoEdges[i], numEdges);
    }
    //return;
   
    ///////////////////////////////////////////////////////////////////////////////
    //Step III: Collect all the geometric faces and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoFaces;
    iGeom_getEntities(geom, geomRootSet, iBase_FACE, ARRAY_INOUT(geoFaces), &err);

    int numGeomFaces = geoFaces.size();

    SurfaceMesher *surfMesher = geomesh.surfMesher;
    for (int i = 2; i < numGeomFaces; i++) {
        surfMesher->discretize(geomesh, geoFaces[i]);
        //exit(0);
    }

    //return ;

    ///////////////////////////////////////////////////////////////////////////////
    //Step IV: Collect all the geometric regions and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoCells;
    iGeom_getEntities(geom, geomRootSet, iBase_REGION, ARRAY_INOUT(geoCells), &err);

    VolumeMesher *volMesher = geomesh.volMesher;
    for (int i = 0; i < geoCells.size(); i++)
        volMesher->discretize(geomesh, geoCells[i]);

    ///////////////////////////////////////////////////////////////////////////////
    //Step V: Generate Spectral (Higher order) elements:
    ///////////////////////////////////////////////////////////////////////////////
    //generate_spectral_elements(geomesh, 10); // 10 noded tetrahedra.
}
Пример #13
0
STDMETHODIMP CDropTarget::Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
{
#ifdef _DEBUG
	printf("IDropTarget::Drop\n");
#endif //_DEBUG

	DWORD dwOKEffects = *pdwEffect;
	{
		//We do this because grfKeyState will always have the mouse button used off
		DWORD temp = LastKeyState;
		//Get the position of the drop
		DragOver(grfKeyState, pt, pdwEffect);
		LastKeyState = temp;
	}
	//Remove the effects
	pDataObj = NULL;
	DragLeave();

	bool copying = (*pdwEffect & DROPEFFECT_COPY) != 0;

	size_t totallen = 0;
	BYTE *data = NULL;
	bool gotdata = false;

	UINT *formats = NULL;
	UINT numformats = 0;

	FORMATETC *fel = NULL;
	UINT numfe = 0;

	bool NeedToChooseFormat = true;
	int IndexOfDataToInsert = -1;
	bool NeedToChooseMoveorCopy = (LastKeyState | grfKeyState) & (MK_MBUTTON | MK_RBUTTON) || hexwnd.always_pick_move_copy;

	if (hexwnd.dragging) // Internal data
	{
		hexwnd.dragging = FALSE;
		if (NeedToChooseMoveorCopy)
		{
			int choice = PopupDropMenu(pt);
			if (choice == 0)
			{
				pDataObject->Release();
				*pdwEffect = DROPEFFECT_NONE;
				return S_OK;
			}
			copying = choice != 1;
		}
		int iMove1stEnd = hexwnd.iGetStartOfSelection();
		int iMove2ndEndorLen = hexwnd.iGetEndOfSelection();
		int iMovePosOrg = hexwnd.new_pos;
		if (!copying && hexwnd.new_pos > iMove2ndEndorLen)
			hexwnd.new_pos += iMove1stEnd - iMove2ndEndorLen - 1;
		iMovePos = hexwnd.new_pos;
		iMoveOpTyp = copying ? OPTYP_COPY : OPTYP_MOVE;
		SimpleArray<BYTE> olddata;
		const int len = iMove2ndEndorLen - iMove1stEnd + 1;
		if (grfKeyState & MK_SHIFT) // Overwrite
		{
			if (copying)
			{
				//Just [realloc &] memmove
				if (iMovePos + len > hexwnd.m_dataArray.GetLength()) // Need more space
				{
					olddata.AppendArray(&hexwnd.m_dataArray[iMovePos], hexwnd.m_dataArray.GetLength() - iMovePos);
					if (hexwnd.m_dataArray.SetSize(iMovePos + len))
					{
						hexwnd.m_dataArray.ExpandToSize();
						memmove(&hexwnd.m_dataArray[iMovePos], &hexwnd.m_dataArray[iMove1stEnd], len);
					}
				}
				else // Enough space
				{
					olddata.AppendArray(&hexwnd.m_dataArray[iMovePos], len);
					memmove(&hexwnd.m_dataArray[iMovePos], &hexwnd.m_dataArray[iMove1stEnd], len);
				}
				hexwnd.push_undorecord(iMovePos, olddata, olddata.GetLength(), &hexwnd.m_dataArray[iMovePos], len);
			}
			else //Moving
			{
				if (iMovePos > iMove1stEnd) //Forward
				{
					olddata.AppendArray(&hexwnd.m_dataArray[iMove1stEnd], iMovePosOrg + len - iMove1stEnd);
					hexwnd.move_copy_sub(iMove1stEnd, iMove2ndEndorLen, 0);
					hexwnd.m_dataArray.RemoveAt(iMovePos+len,len);
					hexwnd.push_undorecord(iMove1stEnd, olddata, olddata.GetLength(), &hexwnd.m_dataArray[iMove1stEnd], iMovePosOrg - iMove1stEnd);
				}
				else //Backward
				{
					if (iMove1stEnd-iMovePos>=len)
					{
						olddata.AppendArray(&hexwnd.m_dataArray[iMovePos], iMove1stEnd + len - iMovePos);
						memmove(&hexwnd.m_dataArray[iMovePos],&hexwnd.m_dataArray[iMove1stEnd],len);
						hexwnd.m_dataArray.RemoveAt(iMove1stEnd,len);
					}
					else
					{
						olddata.AppendArray(&hexwnd.m_dataArray[iMovePos], iMove1stEnd + len - (iMovePos + len - iMove1stEnd) - iMovePos);
						memmove(&hexwnd.m_dataArray[iMovePos],&hexwnd.m_dataArray[iMove1stEnd],len);
						hexwnd.m_dataArray.RemoveAt(iMovePos+len,len-(iMovePos + len - iMove1stEnd));
					}
					hexwnd.push_undorecord(iMovePos, olddata, olddata.GetLength(), &hexwnd.m_dataArray[iMovePos], iMove1stEnd - iMovePos);
				}
			}
			hexwnd.iStartOfSelection = iMovePos;
			hexwnd.iEndOfSelection = iMovePos+len-1;
			hexwnd.bFilestatusChanged = true;
			hexwnd.bSelected = true;
			hexwnd.resize_window();
		}
		else // Insert
		{
			hexwnd.CMD_move_copy(iMove1stEnd, iMove2ndEndorLen, 1);
		}
	}
	else // External data
	{
		STGMEDIUM stm;
		HRESULT err = E_UNEXPECTED;

		//Get the formats enumerator
		IEnumFORMATETC *iefe = 0;
		pDataObject->EnumFormatEtc(DATADIR_GET, &iefe);
		if (iefe == 0)
		{
#ifdef _DEBUG
			printf("Unable to create a drag-drop data enumerator\n");
#endif //_DEBUG
			goto ERR;
		}
		iefe->Reset();

		//Get the available formats
		for(;;)
		{
			void *temp = realloc(fel, (numfe + 1) * sizeof(FORMATETC));
			if (temp != NULL)
			{
				fel = (FORMATETC*) temp;
				temp = NULL;
				int r;
				r = iefe->Next(1, &fel[numfe], NULL);
				if (r != S_OK)
					break;//No more formats
				numfe++;
			}
			else if (fel == NULL)
			{
				//We only go here if nothing could be allocated
#ifdef _DEBUG
				printf("Not enough memory for the drag-drop format list\n");
#endif //_DEBUG
				goto ERR_ENUM;
			}
		}
		UINT i;
		/*Check which format should be inserted according to user preferences*/
		if (numfe == 0)
		{
			MessageBox(hexwnd.pwnd, GetLangString(IDS_DD_NO_DATA), MB_OK);
			err = S_OK;
			*pdwEffect = DROPEFFECT_NONE;
			goto ERR_ENUM;
		}
		if (hexwnd.prefer_CF_HDROP)
		{
			for (i = 0 ; i < numfe ; i++)
			{
				if (fel[i].cfFormat == CF_HDROP)
				{
					//Return no effect & let shell32 handle it
					if (S_OK == pDataObject->GetData(&fel[i], &stm))
					{
						hexwnd.dropfiles((HDROP)stm.hGlobal);
					}
					err = S_OK;
					*pdwEffect = DROPEFFECT_NONE;
					goto ERR_ENUM;
				}
			}
		}
		if (numfe == 1)
		{
			IndexOfDataToInsert = 0;
		}
		else if (hexwnd.prefer_CF_BINARYDATA)
		{
			for (i = 0 ; i < numfe ; i++)
			{
				if (fel[i].cfFormat == CF_BINARYDATA)
				{
					NeedToChooseFormat = false;
					IndexOfDataToInsert = i;
					break;
				}
			}
		}
		else if (hexwnd.prefer_CF_TEXT)
		{
			for (i = 0 ; i < numfe ; i++)
			{
				if (fel[i].cfFormat == CF_TEXT)
				{
					NeedToChooseFormat = false;
					IndexOfDataToInsert = i;
					break;
				}
			}
		}
		if (NeedToChooseFormat)
		{
			dialog<DragDropDlg> params;
			params.allowable_effects = dwOKEffects & (DROPEFFECT_COPY | DROPEFFECT_MOVE);
			params.effect = copying;
			params.formatetcs = fel;
			params.numformatetcs = numfe;
			params.formats = NULL;
			params.numformats = 0;
			int ret = params.DoModal(hexwnd.pwnd);
			if (ret < 0)
			{
				//An error occured or the user canceled the operation
				err = S_OK;
				*pdwEffect = DROPEFFECT_NONE;
				goto ERR_ENUM;
			}
			numformats = params.numformats;
			formats = params.formats;
			copying = params.effect;
		}
		else if (NeedToChooseMoveorCopy)
		{
			int choice = PopupDropMenu(pt);
			if (choice == 0)
			{
				err = S_OK;
				*pdwEffect = DROPEFFECT_NONE;
				goto ERR_ENUM;
			}
			copying = choice != 1;
		}

		if (IndexOfDataToInsert >= 0 && formats == NULL)
		{
			formats = (UINT*)&IndexOfDataToInsert;
			numformats = 1;
		}

		//for each selected format
		for (i = 0 ; i < numformats ; i++)
		{
			FORMATETC fe = fel[formats[i]];
			/*It is important that when debugging (with M$VC at least) you do not step __into__ the below GetData call
			  If you do the app providing the data source will die & GetData will return OLE_E_NOTRUNNING or E_FAIL
			  The solution is to step over the call
			  It is also possible that a debugger will be opened & attach itself to the data provider
			*/
			if (pDataObject->GetData(&fe, &stm) == S_OK)
			{
				//Get len
				size_t len = 0;
				switch (stm.tymed)
				{
					case TYMED_HGLOBAL:
						len = GlobalSize(stm.hGlobal);
						break;
#ifndef __CYGWIN__
					case TYMED_FILE:
					{
						int fh = _wopen(stm.lpszFileName, _O_BINARY | _O_RDONLY);
						if (fh != -1)
						{
							len = _filelength(fh);
							if (len == (size_t)-1)
								len = 0;
							_close(fh);
						}
					} break;
#endif //__CYGWIN__
					case TYMED_ISTREAM:
						{
							STATSTG stat;
							if (S_OK == stm.pstm->Stat(&stat, STATFLAG_NONAME))
								len = (size_t)stat.cbSize.LowPart;
						}
						break;
					//This case is going to be a bitch to implement so it can wait for a while
					//It will need to be a recursive method that stores the STATSTG structures (+ the name), contents/the bytes of data in streams/property sets
					case TYMED_ISTORAGE:
						{
							MessageBox(hexwnd.pwnd, GetLangString(IDS_DD_TYMED_NOTSUP), MB_OK);
						} 
						break; // IStorage*
					case TYMED_GDI:
						{
							len = GetObject(stm.hBitmap, 0, NULL);
							if (len)
							{
								DIBSECTION t;
								GetObject(stm.hBitmap, len, &t);
								len += t.dsBm.bmHeight*t.dsBm.bmWidthBytes*t.dsBm.bmPlanes;
							}
						}
						break; // HBITMAP
					case TYMED_MFPICT:
						{
							len = GlobalSize(stm.hMetaFilePict);
							METAFILEPICT *pMFP = (METAFILEPICT*)GlobalLock(stm.hMetaFilePict);
							if (pMFP)
							{
								len += GetMetaFileBitsEx(pMFP->hMF, 0, NULL);
								GlobalUnlock(stm.hMetaFilePict);
							}
						}
						break; // HMETAFILE
#ifndef __CYGWIN__
					case TYMED_ENHMF:
						{
							len = GetEnhMetaFileHeader(stm.hEnhMetaFile, 0, NULL);
							DWORD n = GetEnhMetaFileDescriptionW(stm.hEnhMetaFile, 0, NULL);
							if (n && n != GDI_ERROR)
								len += sizeof(WCHAR) * n;
							len += GetEnhMetaFileBits(stm.hEnhMetaFile, 0, NULL);
							n = GetEnhMetaFilePaletteEntries(stm.hEnhMetaFile, 0, NULL);
							if (n && n != GDI_ERROR)
								len += sizeof(LOGPALETTE) + (n - 1) * sizeof(PALETTEENTRY);
						}
						break; // HENHMETAFILE
#endif //__CYGWIN__
					//case TYMED_NULL:break;
				}
				if (!len)
					continue;

				/*Malloc
				We do this so that if the data access fails we only need free(data)
				and don't need to mess around with the m_dataArray.
				Perhaps in the future the m_dataArray can support undoable actions.*/
				BYTE* t = (BYTE*)realloc(data, len);
				if (!t)
					continue;
				data = t;
				memset(data, 0, len);

				//Get data
				switch (stm.tymed)
				{
					case TYMED_HGLOBAL:
						{
							if (LPVOID pmem = GlobalLock(stm.hGlobal))
							{
								memcpy(data, pmem, len);
								gotdata = true;
								GlobalUnlock(stm.hGlobal);
							}
						}
						break;
#ifndef __CYGWIN__
					case TYMED_FILE:
						{
							int fh = _wopen(stm.lpszFileName, _O_BINARY | _O_RDONLY);
							if (fh != -1)
							{
								if (0 < _read(fh, data, len))
									gotdata = true;
								_close(fh);
							}
						}
						break;
#endif //__CYGWIN__
					case TYMED_ISTREAM:
						{
							LARGE_INTEGER zero = { 0 };
							ULARGE_INTEGER pos;
							if (S_OK == stm.pstm->Seek(zero, STREAM_SEEK_CUR, &pos))
							{
								stm.pstm->Seek(zero, STREAM_SEEK_SET, NULL);
								if (S_OK == stm.pstm->Read(data, len, NULL))
									gotdata = true;
								stm.pstm->Seek(*(LARGE_INTEGER*)&pos, STREAM_SEEK_SET, NULL);
							}
						}
						break;
					//This case is going to be a bitch to implement so it can wait for a while
					//It will need to be a recursive method that stores the STATSTG structures (+ the name), contents/the bytes of data in streams/property sets
					case TYMED_ISTORAGE:
						{
							MessageBox(hexwnd.pwnd, GetLangString(IDS_DD_TYMED_NOTSUP), MB_OK);
							goto ERR_ENUM;
						}
						break;//IStorage*
					case TYMED_GDI:
						{
							int l = GetObject(stm.hBitmap, len, data);
							if (l)
							{
								BITMAP* bm = (BITMAP*)data;
								if (bm->bmBits)
									memcpy(&data[l], bm->bmBits, len-l);
								else
									GetBitmapBits(stm.hBitmap, len-l, &data[l]);
								gotdata = true;
							}
						} break; // HBITMAP
					case TYMED_MFPICT:
						{
							if (METAFILEPICT *pMFP = (METAFILEPICT *)GlobalLock(stm.hMetaFilePict))
							{
								memcpy(data, pMFP, sizeof *pMFP);
								GetMetaFileBitsEx(pMFP->hMF, len - sizeof(*pMFP), &data[sizeof(*pMFP)]);
								GlobalUnlock(stm.hMetaFilePict);
								gotdata = true;
							}
						} break;//HMETAFILE
#ifndef __CYGWIN__
					case TYMED_ENHMF:
						{
							DWORD i = 0, n = 0, l = len;
							n = GetEnhMetaFileHeader(stm.hEnhMetaFile, l, (ENHMETAHEADER*)&data[i]);
							l -= n;
							i += n;
							n = GetEnhMetaFileDescriptionW(stm.hEnhMetaFile,
									l / sizeof(WCHAR), (LPWSTR)&data[i]);
							if (n && n != GDI_ERROR)
							{
								n *= sizeof(WCHAR);l -= n; i += n;
							}
							n = GetEnhMetaFileBits(stm.hEnhMetaFile, l, &data[i]);
							l -= n; i += n;
							n = GetEnhMetaFilePaletteEntries(stm.hEnhMetaFile, 0, NULL);
							if (n && n != GDI_ERROR)
							{
								LOGPALETTE* lp = (LOGPALETTE*)&data[i];
								lp->palVersion = 0x300;
								lp->palNumEntries = (USHORT)n;
								l -= sizeof(lp->palVersion) + sizeof(lp->palNumEntries);
								n = GetEnhMetaFilePaletteEntries(stm.hEnhMetaFile,
										l / sizeof(PALETTEENTRY), &lp->palPalEntry[0]);
								i += n*sizeof(PALETTEENTRY);
							}
							if (i)
								gotdata = true;
						} break; // HENHMETAFILE
#endif //__CYGWIN__
					//case TYMED_NULL:break;
				}

				ReleaseStgMedium(&stm);

				if (gotdata)
				{
					BYTE* DataToInsert = data;
					if (fe.cfFormat == CF_BINARYDATA)
					{
						len = *(DWORD*)data;
						DataToInsert += 4;
					}
					else if (fe.cfFormat == CF_TEXT || fe.cfFormat == CF_OEMTEXT)
					{
						len = strlen((char*)data);
					}
					else if (fe.cfFormat == CF_UNICODETEXT)
					{
						len = sizeof(wchar_t)*wcslen((wchar_t*)data);
					}

					// Insert/overwrite data into m_dataArray
					if (grfKeyState&MK_SHIFT)
					{
						/* Overwite */
						SimpleArray<BYTE> olddata;
						DWORD upper = 1 + hexwnd.m_dataArray.GetUpperBound();
						if (hexwnd.new_pos+len > upper)
						{
							olddata.AppendArray(&hexwnd.m_dataArray[hexwnd.new_pos + (int)totallen], upper - hexwnd.new_pos + (int)totallen);
							/* Need more space */
							if (hexwnd.m_dataArray.SetSize(hexwnd.new_pos + totallen + len))
							{
								hexwnd.m_dataArray.ExpandToSize();
								memcpy(&hexwnd.m_dataArray[hexwnd.new_pos +
										(int)totallen], DataToInsert, len);
								hexwnd.push_undorecord(hexwnd.new_pos + totallen, olddata, olddata.GetLength(), DataToInsert, len);
								gotdata = true;
								totallen += len;
							}
						}
						else
						{
							/* Enough space */
							olddata.AppendArray(&hexwnd.m_dataArray[hexwnd.new_pos + (int)totallen], len);
							memcpy(&hexwnd.m_dataArray[hexwnd.new_pos +
									(int)totallen], DataToInsert, len);
							hexwnd.push_undorecord(hexwnd.new_pos + totallen, olddata, olddata.GetLength(), DataToInsert, len);
							gotdata = true;
							totallen += len;
						}
					}
					else if (hexwnd.m_dataArray.InsertAtGrow(hexwnd.new_pos + totallen, DataToInsert, 0, len))
					{
						/* Insert */
						hexwnd.push_undorecord(hexwnd.new_pos + totallen, NULL, 0, DataToInsert, len);
						gotdata = true;
						totallen += len;
					}
				}
			}

		} // For each selected format

		// Release the data
		free(data);
		data = NULL;
		if (IndexOfDataToInsert < 0)
		{
			free(formats);
			formats = NULL;
		}

		if (gotdata)
		{
			hexwnd.iStartOfSelection = hexwnd.new_pos;
			hexwnd.iEndOfSelection = hexwnd.new_pos + totallen - 1;
			hexwnd.bFilestatusChanged = true;
			hexwnd.bSelected = true;
			hexwnd.resize_window();
			hexwnd.synch_sibling();
		}

		*pdwEffect = copying  ? DROPEFFECT_COPY : DROPEFFECT_MOVE;

		err = S_OK;

ERR_ENUM:
		iefe->Release();
		free(fel);
ERR:
		pDataObject->Release();
		return err;
	}
	pDataObject->Release();

	return S_OK;
}
Пример #14
0
/**
 * @brief Paste the bytes.
 * @param [in] hDlg Handle to dialog.
 * @return TRUE if paste succeeded, FALSE if failed.
 */
BOOL PasteDlg::Apply(HWindow *pDlg)
{
	bPasteAsText = pDlg->IsDlgButtonChecked(IDC_PASTE_BINARY) == BST_CHECKED;
	iPasteTimes = pDlg->GetDlgItemInt(IDC_PASTE_TIMES);
	if (iPasteTimes <= 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_ATLEAST_ONCE), MB_ICONERROR);
		return FALSE;
	}
	iPasteSkip = pDlg->GetDlgItemInt(IDC_PASTE_SKIPBYTES);
	HEdit *pwndEdit1 = static_cast<HEdit *>(pDlg->GetDlgItem(IDC_PASTE_CLIPBOARD));
	int destlen = pwndEdit1->GetWindowTextLength() + 1;
	char *pcPastestring = new char[destlen];
	destlen = pwndEdit1->GetWindowTextA(pcPastestring, destlen);
	if (!bPasteAsText)
	{
		char *pc = 0;
		destlen = create_bc_translation((BYTE **)&pc, pcPastestring,
			static_cast<int>(strlen(pcPastestring)), iCharacterSet, iBinaryMode);
		delete [] pcPastestring;
		pcPastestring = pc;
	}
	if (destlen == 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_WAS_EMPTY), MB_ICONERROR);
		delete [] pcPastestring;
		return FALSE;
	}
	WaitCursor wc1;
	SimpleArray<BYTE> olddata;
	if (bSelected || pDlg->IsDlgButtonChecked(IDC_PASTE_INSERT))
	{
		// Insert at iCurByte. Bytes there will be pushed up.
		if (bSelected)
		{
			iCurByte = iGetStartOfSelection();
			int iEndByte = iGetEndOfSelection();
			olddata.AppendArray(&m_dataArray[iCurByte], iEndByte - iCurByte + 1 + (iPasteTimes - 1) * iPasteSkip);
			m_dataArray.RemoveAt(iCurByte, iEndByte - iCurByte + 1);//Remove extraneous data
			bSelected = false; // Deselect
		}
		else
		{
			olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * iPasteSkip);
		}
		int i = iCurByte;
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			if (!m_dataArray.InsertAtGrow(i, (BYTE*)pcPastestring, 0, destlen))
			{
				MessageBox(pDlg, GetLangString(IDS_PASTE_NO_MEM), MB_ICONERROR);
				break;
			}
			i += destlen + iPasteSkip;
		}
		bFilestatusChanged = true;
		resize_window();
	}
	else
	{
		// Overwrite.
		// Enough space for writing?
		// m_dataArray.GetLength()-iCurByte = number of bytes from including curbyte to end.
		if (m_dataArray.GetLength() - iCurByte < (iPasteSkip + destlen) * iPasteTimes)
		{
			MessageBox(pDlg, GetLangString(IDS_PASTE_NO_SPACE), MB_ICONERROR);
			delete [] pcPastestring;
			return TRUE;
		}
		olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
		// Overwrite data.
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			for (int i = 0 ; i < destlen ; i++)
			{
				m_dataArray[iCurByte + k * (iPasteSkip + destlen) + i] = pcPastestring[i];
			}
		}
		bFilestatusChanged = true;
		repaint();
	}
	push_undorecord(iCurByte, olddata, olddata.GetLength(), &m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
	delete [] pcPastestring;
	return TRUE;
}
Пример #15
0
BOOL Game::update()
{
	BOOL updateObjects = FALSE;
	BOOL checkForWinning = FALSE;
	BOOL checkForLosing = FALSE;
	BOOL checkCollisions = FALSE;
	BOOL stopMovement = TRUE;

	switch (itsCurrentState)
	{
		case GAMESTATE_PREGAME :
			// since the pregame section is so different, we will call our own method
			pregameUpdate();
			break;
		case GAMESTATE_INPROGRESS :
			updateObjects = TRUE;
			checkForWinning = TRUE;
			checkForLosing = TRUE;
			checkCollisions = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_WON :
		{
			updateObjects = TRUE;
			Room *room = itsPlayer->getRoom();
			// we need to change the walls a color for that ending flashiness
			if (itsLastTickTime - itsWinTime >= theWinAnimationLength)
			{	
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(FALSE);
				}
			}
			else
			{
				// since the player will be holding the chalice, we can tell
				// the walls to change colors, and they will change to the color
				// of the chalice, which will make them appear to animate
				for (UINT i=0;i<room->getWalls()->length();i++)
				{
					Wall *wall = (Wall *)(room->getWalls()->elementAt(i));
					wall->setChangesColor(TRUE,1);
				}
			}
			// hack to put the player in the right place for the ending
			itsPlayer->setX(Game::theScreenHeight-64);
			itsPlayer->setY(Game::theScreenWidth/2-16);
		}
		break;
		case GAMESTATE_LOST :
			updateObjects = TRUE;
			stopMovement = FALSE;
			break;
		case GAMESTATE_PAUSED :
			stopMovement = FALSE;
			break;
	}

	theEventDispatcher.update(itsLastTickTime);


	if (updateObjects)
	{
		SimpleArray *objects = NULL;
		if (itsWorld != NULL)
		objects = itsWorld->getObjects();
		for (UINT i=0;i<objects->length();i++)
		{
			((GameObject *)(objects->elementAt(i)))->update(itsLastTickTime);
			if (stopMovement)
			{
				((GameObject *)(objects->elementAt(i)))->stopMoving(itsLastTickTime);
			}
		}
		for (i=0;i<itsWorld->getRooms()->length();i++)
		{
			((Room *)(itsWorld->getRooms()->elementAt(i)))->checkForObjectsLeaving();
		}
	}
	if (checkForWinning && gameWon())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_WON;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkForLosing && gameLost())
	{
		itsNewStateRequest.itsNewState = GAMESTATE_LOST;
		itsNewStateRequest.isActiveRequest = TRUE;
	}
	if (checkCollisions)
		return checkForCollisions();
	else
		return TRUE;
}