Example #1
0
// ----------------------------------------------------------------
//	LoadResource
// ----------------------------------------------------------------
bool CMapInfo::LoadResource( ResourceId id )
{
	// TODO: Restore original code.
	SampleData();

	// TODO: Original code.
	//HANDLE	hFile;
	//DWORD	dwBytesRead = 0;
	//DWORD	dwBytesWrite = 0;
	//std::wstring filePath = m_MapType + L".map";

	//hFile = CreateFile( filePath.c_str(),	// file to open
	//	GENERIC_READ,				// open for reading
	//	FILE_SHARE_READ,			// share for reading
	//	NULL,						// default security
	//	OPEN_EXISTING,				// existing file only
	//	FILE_ATTRIBUTE_NORMAL,		// normal file
	//	NULL);						// no attr. template

	//if ( hFile == INVALID_HANDLE_VALUE )
	//{
	//	wprintf( L"Error: unable to open file \"%s\" for read.\n", filePath.c_str() );
	//	return false;
	//}

	//if ( FALSE == ReadFile( hFile, &m_Header, sizeof(m_Header), &dwBytesRead, NULL ) ||
	//	dwBytesRead < sizeof(m_Header) )
	//{
	//	wprintf( L"Error: Unable to read from file.\n" );
	//	CloseHandle(hFile);
	//	return false;
	//}

	//for ( UINT count = 0; count < m_Header.m_TileCount; ++count )
	//{
	//	TileData tileData;

	//	if ( FALSE == ReadFile( hFile, &tileData, sizeof(tileData), &dwBytesRead, NULL ) ||
	//		dwBytesRead < sizeof(tileData) )
	//	{
	//		wprintf( L"Error: Unable to read from file.\n" );
	//		CloseHandle(hFile);
	//		return false;
	//	}

	//	m_Tiles.push_back( tileData );
	//}

	//for ( UINT count = 0; count < m_Header.m_MapCount; ++count )
	//{
	//	CMapData * mapData = new CMapData();
	//	mapData->Read( hFile );

	//	m_Maps.push_back( mapData );
	//}

	//CloseHandle( hFile );

	return true;
}
Example #2
0
void AudioSourceOJM::parseM30()
{
    M30Header Head;
    size_t sizeLeft;
    ifile->read(reinterpret_cast<char*>(&Head), sizeof(M30Header));

    std::vector<char> Buffer(Head.payload_size);
    sizeLeft = Head.payload_size;

    for (int i = 0; i < Head.sample_count; i++)
    {
        if (sizeLeft < 52)
            break; // wrong number of samples

        M30Entry Entry;
        ifile->read(reinterpret_cast<char*>(&Entry), sizeof(M30Entry));
        sizeLeft -= sizeof(M30Entry);

        sizeLeft -= Entry.sample_size;

        int OJMIndex = Entry.ref;
        if (Entry.codec_code == 0)
            OJMIndex += 1000;
        else if (Entry.codec_code != 5) continue; // Unknown sample id type.

        std::vector<char> SampleData(Entry.sample_size);
        ifile->read(&SampleData[0], Entry.sample_size);

        if (Head.encryption_flag & 16)
            NamiXOR(&SampleData[0], Entry.sample_size);
        else if (Head.encryption_flag & 32)
            F412XOR(&SampleData[0], Entry.sample_size);

        // Sample data is done. Now the bits that are specific to raindrop..
        auto NewSample = std::make_shared<SoundSample>();

        SFM30 ToLoad;
        ToLoad.Buffer = std::move(SampleData);
        ToLoad.DataLength = Entry.sample_size;

        OggVorbis_File vf;

        ov_open_callbacks(&ToLoad, &vf, nullptr, 0, M30InterfaceOgg);
        TemporaryState.File = &vf;
        TemporaryState.Info = vf.vi;

        if (vf.vi)
        {
            TemporaryState.Enabled = OJM_OGG;
            NewSample->SetPitch(Speed);
            NewSample->Open(this);
            TemporaryState.Enabled = 0;
        }

        ov_clear(&vf);

        Arr[OJMIndex] = NewSample;
    }
}
Example #3
0
void Measure(OutputChannel *outputs,int numoutputs)
{
	DataSource *sources[numoutputs];
	int numsources=0;

	for(int i=0;i<numoutputs;i++)
	{
		bool found=false;
		for(int j=0;j<numsources;j++)
		{
			if(outputs[i].source==sources[j]) { found=true; break; }
		}

		if(!found)
		{
			sources[numsources]=outputs[i].source;
			numsources++;
		}
	}

	for(;;)
	{
		bool didupdate=false;
		while(!didupdate)
		{
			for(int i=0;i<numsources;i++)
			{
				if(IsDataAvailable(sources[i]))
				{
					SampleData(sources[i]);
					if(IsDataSourceImportant(sources[i])) didupdate=true;

					for(int j=0;j<numoutputs;j++)
					{
						if(outputs[j].source==sources[i] && outputs[j].accumulates)
						{
							double value=GetData(outputs[j].source,outputs[j].channel);
							outputs[j].accumulator+=value;
						}
					}
				}
			}
		}
		FILE *fp;
		fp = fopen("power.log","a");
		for(int i=0;i<numoutputs;i++)
		{
			if(i!=0) printf(",");

			if(outputs[i].accumulates)
			{
				printf(outputs[i].format,outputs[i].accumulator*outputs[i].scalefactor);
				fprintf(fp,outputs[i].format,outputs[i].accumulator*outputs[i].scalefactor);
			}
			else
			{
				double value=GetData(outputs[i].source,outputs[i].channel);
				printf(outputs[i].format,value*outputs[i].scalefactor);
				fprintf(fp,outputs[i].format,value*outputs[i].scalefactor);
			}
		}
		
		printf("\n");
		fprintf(fp,"\n");
		fclose(fp);
	}
}
bool DynamicDriftCorrectionAction::Update(float tpf, const std::shared_ptr<const TabInput> spInput)
{
	// TODO
	// - incoporate raw gaze data

	// ### PREPARATION ###

	// Speed of zooming
	float zoomSpeed = 0.f;

	// Size of page in CEF pixels
	const glm::vec2 cefPixels(_pTab->GetWebViewResolutionX(), _pTab->GetWebViewResolutionY());

	// Function transforms coordinate from relative WebView coordinates to CEFPixel coordinates on page
	const std::function<void(const float&, const glm::vec2&, const glm::vec2&, glm::vec2&)> pageCoordinate 
		= [&](const float& rLogZoom, const glm::vec2& rRelativeZoomCoordinate, const glm::vec2& rRelativeCenterOffset, glm::vec2& rCoordinate)
	{
		// Analogous to shader in WebView
		rCoordinate += rRelativeCenterOffset; // add center offset
		rCoordinate -= rRelativeZoomCoordinate; // move zoom coordinate to origin
		rCoordinate *= rLogZoom; // apply zoom
		rCoordinate += rRelativeZoomCoordinate; // move back
		rCoordinate *= cefPixels; // bring into pixel space of CEF
	};

	// Function calling above function with current values
	const std::function<void(glm::vec2&)> currentPageCoordinate
		= [&](glm::vec2& rCoordinate)
	{
		pageCoordinate(_logZoom, _relativeZoomCoordinate, _relativeCenterOffset, rCoordinate);
	};

	// Current gaze
	glm::vec2 relativeGazeCoordinate = glm::vec2(spInput->webViewRelativeGazeX, spInput->webViewRelativeGazeY); // relative WebView space

	// ### UPDATE ZOOM SPEED, ZOOM CENTER AND CENTER OFFSET ###

	// Only allow zoom in when gaze upon WebView and not yet used
	if (spInput->insideWebView && !spInput->gazeUponGUI) // TODO: gazeUsed really good idea here? Maybe later null pointer?
	{
		switch (_state)
		{
		case State::ZOOM:
		{
			// Update deviation value (fade away deviation)
			_deviation = glm::max(0.f, _deviation - (tpf / DEVIATION_FADING_DURATION));

			// Update zoom coordinate
			if (!_firstUpdate)
			{
				// Caculate delta on page for deviation
				glm::vec2 pixelGazeCoordinate = relativeGazeCoordinate;
				currentPageCoordinate(pixelGazeCoordinate);
				glm::vec2 pixelZoomCoordinate = _relativeZoomCoordinate * cefPixels;
				const float pixelDelta = glm::distance(pixelGazeCoordinate, pixelZoomCoordinate);

				// Set length of delta to deviation if bigger than current deviation
				_deviation = glm::min(1.f, glm::max(pixelDelta / glm::compMax(cefPixels), _deviation));

				// Move zoom coordinate towards new coordinate
				const glm::vec2 relativeDelta =
					(relativeGazeCoordinate + _relativeCenterOffset) // visually, the zoom coordinate is moved by relative center offset. So adapt input to this
					- _relativeZoomCoordinate;
				_relativeZoomCoordinate += relativeDelta * glm::min(1.f, (tpf / MOVE_DURATION));

				// If at the moment a high deviation is given, try to zoom out to give user more overview
				zoomSpeed = ZOOM_SPEED - glm::min(1.f, DEVIATION_WEIGHT * _deviation); // TODO weight deviation more intelligent
			}
			else // first frame of execution
			{
				// Use current gaze coordinate as new coordinate
				_relativeZoomCoordinate = relativeGazeCoordinate;

				// Since only for first frame, do not do it again
				_firstUpdate = false;
			}

			// Calculated center offset. This moves the WebView content towards the center for better gaze precision
			const glm::vec2 clampedRelativeZoom = glm::clamp(_relativeZoomCoordinate, glm::vec2(0.f), glm::vec2(1.f)); // clamp within page for determining relative center offset
			const float zoomWeight = ((1.f - _logZoom) / (1.f - MAX_ORIENTATION_LOG_ZOOM)); // projects zoom level to [0..1]
			_relativeCenterOffset =
				CENTER_OFFSET_MULTIPLIER
				* zoomWeight // weight with zoom (starting at zero) to have more centered version at higher zoom level
				* (clampedRelativeZoom - 0.5f); // vector from WebView center to current zoom coordinate

			// Get out of case
			break;
		}
		case State::DEBUG:
			zoomSpeed = 0.f;
			break;
		}
	}

	// ### UPDATE ZOOM ###

	// Update linear zoom
	_linZoom += tpf * zoomSpeed; // frame rate depended? at least complex

	// Clamp linear zoom (one is standard, everything higher is zoomed)
	_linZoom = glm::max(_linZoom, 1.f);

	// Make zoom better with log function
	_logZoom = 1.f - glm::max(glm::log(_linZoom), 0.f); // log zooming is starting at one and getting smaller with higher _linZoom

	// ### UPDATE ON OUTPUT VALUE ###

	// Decide whether zooming is finished
	bool finished = false;

	// Instant interaction handling
	if (spInput->insideWebView && !spInput->gazeUponGUI && spInput->instantInteraction) // user demands on instant interaction
	{
		// Calculate pixel gaze coordiante on page
		glm::vec2 pixelGazeCoordinate = relativeGazeCoordinate;
		pageCoordinate(_logZoom, _relativeZoomCoordinate, _relativeCenterOffset, pixelGazeCoordinate); // CEFPixel space

		// Set coordinate in output value. Use current gaze position
		SetOutputValue("coordinate", pixelGazeCoordinate);

		// Return success
		finished = true;
	}

	// Update samples
	std::for_each(_sampleData.begin(), _sampleData.end(), [&](SampleData& rSampleData) { rSampleData.lifetime -= tpf; });
	_sampleData.erase(
		std::remove_if(
			_sampleData.begin(),
			_sampleData.end(),
			[&](const SampleData& rSampleData) { return rSampleData.lifetime <= 0.f; }),
		_sampleData.end());

	// Add new sample
	_sampleData.push_back(SampleData(_logZoom, relativeGazeCoordinate, _relativeZoomCoordinate, _relativeCenterOffset));
	
	// Proceed depending on the state
	switch (_state)
	{
		case State::ZOOM:
		{
			// TODO: Reintegrate center offset and filter multiple sample data sets
			// -> All values should be in page coordinates (so relative to page, in pixels)

			// TODO: limit zooming, maybe define maximum zoom level (something bigger than zero)

			if (_logZoom < 0.75f) // wait until some samples exist
			{
				// Choose sample
				SampleData sample = _sampleData.front();

				// Determine movement of zoom coordinate between current and sample
				glm::vec2 zoomCoordinateDeltaVector = (_relativeZoomCoordinate - sample.relativeZoomCoordinate) * cefPixels;
				float zoomCoordinateDelta = glm::length(zoomCoordinateDeltaVector);

				// Current pixel gaze coordinate on page with values as sample was taken
				glm::vec2 pixelGazeCoordinate = relativeGazeCoordinate;
				pageCoordinate(sample.logZoom, sample.relativeZoomCoordinate, sample.relativeCenterOffset, pixelGazeCoordinate);

				// Pixel gaze coordinate on page at time where sample has been taken
				glm::vec2 samplePixelGazeCoordinate = sample.relativeGazeCoordinate;
				pageCoordinate(_logZoom, _relativeZoomCoordinate, _relativeCenterOffset, samplePixelGazeCoordinate);

				// Delta of gaze
				glm::vec2 gazeDeltaVector = pixelGazeCoordinate - samplePixelGazeCoordinate;
				float gazeDelta = glm::length(gazeDeltaVector);

				// Angle between zoomCoordinateDeltaVector and gazeDeltaVector
				float deltaAngle = glm::degrees(glm::angle(glm::normalize(gazeDeltaVector), glm::normalize(zoomCoordinateDeltaVector)));
				LogInfo("DriftAngle: ", deltaAngle); // TODO: which value interval is the angle in?

				// Decide to go directly for zoom coordinate (good calibration) or drift corrected coordinate (poor calibration) or continue zooming
				if (zoomCoordinateDelta < 1.f) // zoom coordinate has not changed in pixels on page
				{
					SetOutputValue("coordinate", _relativeZoomCoordinate * cefPixels);
					// finished = true; // TODO debugging
					_state = State::DEBUG;
					LogInfo("Zoom coordinate used");
				}
				else if (deltaAngle <= 5) // angle of gazing is rather static TODO: should the delta be of some minimal size?
				{
					// Inverse zooms
					float zoom = 1.f / _logZoom;
					float sampleZoom = 1.f / sample.logZoom;

					// Radius where fixated coordinate lies
					float radius = gazeDelta - zoomCoordinateDelta + (zoom * zoomCoordinateDelta);
					radius /= zoom - sampleZoom;

					// Page coordinat of relative zoom coordinate
					glm::vec2 samplePixelZoomCoordinate = sample.relativeZoomCoordinate * glm::vec2(_pTab->GetWebViewResolutionX(), _pTab->GetWebViewResolutionY());

					// Actual fixation point
					glm::vec2 fixation = (glm::normalize(zoomCoordinateDeltaVector) * radius) + samplePixelZoomCoordinate;
					SetOutputValue("coordinate", fixation);

					// finished = true; // TODO debugging
					_state = State::DEBUG;
					LogInfo("Drift corrected coordinate used");
				}
				
				// else continue
			}
			break;
		}
		case State::DEBUG:
		{
			_logZoom = 1.f;
			_relativeCenterOffset = glm::vec2(0, 0);
			break;
		}
	}

	// ### UPDATE WEBVIEW ###

	// Decrement dimming
	_dimming += tpf;
	_dimming = glm::min(_dimming, DIMMING_DURATION);

	// Tell WebView about zoom and dimming
	WebViewParameters webViewParameters;
	webViewParameters.centerOffset = _relativeCenterOffset;
	webViewParameters.zoom = _logZoom;
	webViewParameters.zoomPosition = _relativeZoomCoordinate;
	if (_doDimming) { webViewParameters.dim = DIMMING_VALUE * (_dimming / DIMMING_DURATION); }
	_pTab->SetWebViewParameters(webViewParameters);

    // Return whether finished
    return finished;
}