int main(int argc, char** argv)
{
    FILE* outputFile;
    GLSLShader result;
    GLLang language = LANG_DEFAULT;
	int returnValue = 0;//EXIT_SUCCESS
    Timer_t timer;
    int compiledOK = 0;
    double crossCompileTime = 0;
    double glslCompileTime = 0;

    printf("args: bytecode-file [output-file] [language override - es100 es300 120 130 etc.]\n");

    if(argc < 2 || !fileExists(argv[1]))
    {
        printf("Bad args. Supply a valid shader path, optionaly followed by the output path\n");
        return 1;//EXIT_FAILURE
    }

    if(argc > 3)
    {
        language = LanguageFromString(argv[3]);
    }

    InitTimer(&timer);

    ResetTimer(&timer);
    compiledOK = TranslateHLSLFromFile(argv[1], 0, language, NULL, &result);
    crossCompileTime = ReadTimer(&timer);

    if(compiledOK)
    {
        printf("cc time: %.2f us\n", crossCompileTime);

        if(argc > 2)
        {
            //Dump to file
            outputFile = fopen(argv[2], "w");
            fprintf(outputFile, result.sourceCode);
            fclose(outputFile);
        }

#if defined(VALIDATE_OUTPUT)
        compiledOK = TryCompileShader(result.shaderType, (argc > 2) ? argv[2] : "", result.sourceCode, &glslCompileTime);
        
        if(!compiledOK)
		{
			returnValue = 1;//EXIT_FAILURE
		}
        else
        {
            printf("glsl time: %.2f us\n", glslCompileTime);
        }
#endif

        bcstrfree(result.sourceCode);
    }

	return returnValue;
}
示例#2
0
    void Stopwatch::Reset()
    {
        _elapsed = TimeSpan();

        if (_isRunning)
            _start = ReadTimer();
    }
示例#3
0
 void Stopwatch::Stop()
 {
     if (_isRunning)
     {
         _isRunning = false;
         _elapsed += ReadTimer() - _start;
     }
 }
示例#4
0
 void Stopwatch::Start()
 {
     if (!_isRunning)
     {
         _isRunning = true;
         _start = ReadTimer();
     }
 }
示例#5
0
    const TimeSpan Stopwatch::Elapsed() const
    {
        TimeSpan elapsed = _elapsed;

        if (_isRunning)
            elapsed += ReadTimer() - _start;

        return elapsed;
    }
int TryCompileShader(GLenum eGLSLShaderType, char* inFilename, char* shader, double* pCompileTime)
{
    GLint iCompileStatus;
    GLuint hShader;
    Timer_t timer;

    InitTimer(&timer);

    InitOpenGL();

    hShader = glCreateShaderObjectARB(eGLSLShaderType);
    glShaderSourceARB(hShader, 1, (const char **)&shader, NULL);

    ResetTimer(&timer);
    glCompileShaderARB(hShader);
    *pCompileTime = ReadTimer(&timer);

    /* Check it compiled OK */
    glGetObjectParameterivARB (hShader, GL_OBJECT_COMPILE_STATUS_ARB, &iCompileStatus);

    if (iCompileStatus != GL_TRUE)
    {
        FILE* errorFile;
        GLint iInfoLogLength = 0;
        char* pszInfoLog;
		bstring filename = bfromcstr(inFilename);
		char* cstrFilename;

        glGetObjectParameterivARB (hShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &iInfoLogLength);

        pszInfoLog = malloc(iInfoLogLength);

        printf("Error: Failed to compile GLSL shader\n");

		glGetInfoLogARB (hShader, iInfoLogLength, NULL, pszInfoLog);

        printf(pszInfoLog);

		bcatcstr(filename, "_compileErrors.txt");

		cstrFilename = bstr2cstr(filename, '\0');

        //Dump to file
        errorFile = fopen(cstrFilename, "w");
        fprintf(errorFile, pszInfoLog);
        fclose(errorFile);

		bdestroy(filename);
		free(cstrFilename);
        free(pszInfoLog);

        return 0;
    }

    return 1;
}
int TryCompileShader(GLenum eGLSLShaderType, const char* inFilename, char* shader, double* pCompileTime)
{
    GLint iCompileStatus;
    GLuint hShader;
    Timer_t timer;

    InitTimer(&timer);

    InitOpenGL();

    hShader = glCreateShaderObjectARB(eGLSLShaderType);
    glShaderSourceARB(hShader, 1, (const char **)&shader, NULL);

    ResetTimer(&timer);
    glCompileShaderARB(hShader);
    *pCompileTime = ReadTimer(&timer);

    /* Check it compiled OK */
    glGetObjectParameterivARB (hShader, GL_OBJECT_COMPILE_STATUS_ARB, &iCompileStatus);

    FILE* errorFile;
    GLint iInfoLogLength = 0;
    char* pszInfoLog;
	std::string filename;

    filename += inFilename;

    glGetObjectParameterivARB (hShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &iInfoLogLength);

	if (iInfoLogLength > 1)
	{
		pszInfoLog = new char[iInfoLogLength];

		if (iCompileStatus != GL_TRUE)
			printf("Error: Failed to compile GLSL shader\n");

		glGetInfoLogARB(hShader, iInfoLogLength, NULL, pszInfoLog);

		printf(pszInfoLog);

		filename += "_compileErrors.txt";

		//Dump to file
		errorFile = fopen(filename.c_str(), "w");
		fprintf(errorFile, pszInfoLog);
		fclose(errorFile);

		delete[] pszInfoLog;
	}
    return iCompileStatus == GL_TRUE ? 1 : 0;

}
示例#8
0
文件: app.c 项目: RorschachUK/Trakr
//start the game
void InitialiseGame() {
	srand(ReadTimer());
	mode=1;
	score=0;
	InitialiseWorld();
	refreshCount=0;
	resetCount=50;
	behaviourCount=0;
	ResetArrow();
	arrowRefAngle=0;
	cameraPos=CreatePoint(0.0,5.0,0.0);
	cameraAngle=CreatePoint(0.0,0.0,0.0);
	blocked=0;
	lives=3;

	DrawHUD();
}
示例#9
0
int CIFStaticFortuna::ReadData(QSettings& set)
{
    ReadDev(set);
    ReadCompany(set);
    ReadOperator(set);
    ReadNetwork(set);
    ReadFtp(set);
    ReadLotbox(set);
    ReadPrize(set);
    ReadNotein(set);
    ReadNoteout(set);
    ReadCoiner(set);
    ReadTimer(set);
    ReadUps(set);
    ReadRedeembox(set);

    return 1;
}
示例#10
0
文件: app.c 项目: RorschachUK/Trakr
//Main program loop - Run gets called until it returns false
bool Run() {
  	//Main loop - get keypresses and interpret them
  	keystate=GetRemoteKeys();
	if(keystate & KEY_HOME) {
		return false;
	}
	switch(mode) {
		case 0: {	//Splash screen
			if (keystate & KEY_INPUT2) { //Button B
				//Start game
				InitialiseGame();
				PlaySound(SOUND_BEEP);
			}

			if (keystate & KEY_INPUT1) { //Button A
				//show help
				ShowHelp();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 2: {	//Help - wait for 'OK' press
			if (keystate & KEY_INPUT2) { //Button B
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 1: {	//Game
			if (keystate & KEY_INPUT1) { //Button A
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
			}
			if (keystate & KEY_RUN) { //Go button
				//Fire!
				PlaySound(SOUND_SHOOT);
				refreshCount = 0;
				int hit;
				hit = LineHitsObject(cameraPos, cameraAngle);
				if (hit == tankObjectIndex) {
					//we hit the tank!
					score += 100;
					CloseGraphics();
					OpenGraphics();
					DrawWorld(&world, cameraPos, cameraAngle);
					DrawHUD();
					DrawExplosion();
					DrawArrow(cameraAngle.y);
					DrawRadarDots(true);
					DrawRadarArm(sweepAngle * sweepStepCount++);
					DrawRadarDots(false);

					SetTextColor(CYAN);
					DrawText(6,100,"Quit");
					Show();
					PlaySound(SOUND_EXPLOSION);
					PlaceTank(cameraPos, cameraAngle);
				}
			}

			//Have the movement sticks changed? This bit doesn't care about buttons
			if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) {

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				arrowRefAngle=cameraAngle.y;
				baselinePos=cameraPos;

				ResetTimer();
				oldKeystate = keystate;
				if (keystate==0) //we've just stopped moving
					refreshCount=0;
			}

			if (mode==1) {
				if (sweepStepCount == SWEEPSTEPS)
					sweepStepCount=0;

				if (--behaviourCount<0)
					ChooseBehaviour();

				MoveTank();

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				//is it time to reset the tank model?  Otherwise it gradually gets distorted
				if (--resetCount<0) {
					//Refresh the tank model which is prone to getting distorted
					//due to cumulative inaccuracies of sin/cos approximations
					Point3d angle=world.objects[tankObjectIndex].heading;
					Point3d tankPos=world.objects[tankObjectIndex].centre;
					world.objects[tankObjectIndex]=tank;
					MoveObject(&(world.objects[tankObjectIndex]), tankPos);
					RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y);
					resetCount=50;
				}

				//Is it time to redraw the world?
				if (--refreshCount<0) {
					//Seems a bit brutal to have to close graphics but it's
					//the only way to clear the screen that'll let us draw
					//on it properly again - ClearScreen or ClearRectangle mess up
					CloseGraphics();
					OpenGraphics();

					DrawWorld(&world, cameraPos, cameraAngle);

					DrawHUD();
					refreshCount=2;
				}
				DrawArrow(cameraAngle.y);
				DrawRadarDots(true);
				DrawRadarArm(sweepAngle * sweepStepCount++);
				DrawRadarDots(false);

				SetTextColor(CYAN);
				DrawText(6,100,"Quit");
				Show();

				//just in case we changed mode...
				if (mode==0)
					Splash();
			}
		}
	}
	Sleep(50);
	return true;
}
示例#11
0
文件: main.c 项目: elhobbs/hexen2
int main(int argc, char **argv)
{
    int bytesLeft, nRead, err, offset, outOfData, eofReached;
    unsigned char readBuf[READBUF_SIZE], *readPtr;
    short outBuf[MAX_NCHAN * MAX_NGRAN * MAX_NSAMP];
    FILE *infile, *outfile;
    MP3FrameInfo mp3FrameInfo;
    HMP3Decoder hMP3Decoder;
    int startTime, endTime, diffTime, totalDecTime, nFrames;
#ifdef ARM_ADS
    float audioSecs;
#endif

    if (argc != 3) {
        printf("usage: mp3dec infile.mp3 outfile.pcm\n");
        return -1;
    }
    infile = fopen(argv[1], "rb");
    if (!infile) {
        printf("file open error\n");
        return -1;
    }

    if (strcmp(argv[2], "nul")) {
        outfile = fopen(argv[2], "wb");
        if (!outfile) {
            printf("file open error\n");
            return -1;
        }
    } else {
        outfile = 0;	/* nul output */
    }

    DebugMemCheckInit();
    InitTimer();

    DebugMemCheckStartPoint();

    if ( (hMP3Decoder = MP3InitDecoder()) == 0 )
        return -2;

    DebugMemCheckEndPoint();

    bytesLeft = 0;
    outOfData = 0;
    eofReached = 0;
    readPtr = readBuf;
    nRead = 0;
    totalDecTime = 0;
    nFrames = 0;
    do {
        /* somewhat arbitrary trigger to refill buffer - should always be enough for a full frame */
        if (bytesLeft < 2*MAINBUF_SIZE && !eofReached) {
            nRead = FillReadBuffer(readBuf, readPtr, READBUF_SIZE, bytesLeft, infile);
            bytesLeft += nRead;
            readPtr = readBuf;
            if (nRead == 0)
                eofReached = 1;
        }

        /* find start of next MP3 frame - assume EOF if no sync found */
        offset = MP3FindSyncWord(readPtr, bytesLeft);
        if (offset < 0) {
            outOfData = 1;
            break;
        }
        readPtr += offset;
        bytesLeft -= offset;


        /* decode one MP3 frame - if offset < 0 then bytesLeft was less than a full frame */
        startTime = ReadTimer();
        err = MP3Decode(hMP3Decoder, &readPtr, &bytesLeft, outBuf, 0);
        nFrames++;

        endTime = ReadTimer();
        diffTime = CalcTimeDifference(startTime, endTime);
        totalDecTime += diffTime;

#if defined ARM_ADS && defined MAX_ARM_FRAMES
        printf("frame %5d  start = %10d, end = %10d elapsed = %10d ticks\r",
               nFrames, startTime, endTime, diffTime);
        fflush(stdout);
#endif

        if (err) {
            /* error occurred */
            switch (err) {
            case ERR_MP3_INDATA_UNDERFLOW:
                outOfData = 1;
                break;
            case ERR_MP3_MAINDATA_UNDERFLOW:
                /* do nothing - next call to decode will provide more mainData */
                break;
            case ERR_MP3_FREE_BITRATE_SYNC:
            default:
                outOfData = 1;
                break;
            }
        } else {
            /* no error */
            MP3GetLastFrameInfo(hMP3Decoder, &mp3FrameInfo);
            if (outfile)
                fwrite(outBuf, mp3FrameInfo.bitsPerSample / 8, mp3FrameInfo.outputSamps, outfile);
        }

#if defined ARM_ADS && defined MAX_ARM_FRAMES
        if (nFrames >= MAX_ARM_FRAMES)
            break;
#endif
    } while (!outOfData);


#ifdef ARM_ADS
    MP3GetLastFrameInfo(hMP3Decoder, &mp3FrameInfo);
    audioSecs = ((float)nFrames * mp3FrameInfo.outputSamps) / ( (float)mp3FrameInfo.samprate * mp3FrameInfo.nChans);
    printf("\nTotal clock ticks = %d, MHz usage = %.2f\n", totalDecTime, ARMULATE_MUL_FACT * (1.0f / audioSecs) * totalDecTime * GetClockDivFactor() / 1e6f);
    printf("nFrames = %d, output samps = %d, sampRate = %d, nChans = %d\n", nFrames, mp3FrameInfo.outputSamps, mp3FrameInfo.samprate, mp3FrameInfo.nChans);
#endif

    MP3FreeDecoder(hMP3Decoder);

    fclose(infile);
    if (outfile)
        fclose(outfile);

    FreeTimer();
    DebugMemCheckFree();

    return 0;
}
示例#12
-1
文件: app.c 项目: RorschachUK/Trakr
bool Run()
{
  	//Main loop - get keypresses and interpret them
  	keystate=GetRemoteKeys();
  	if(keystate != oldKeystate) {
	  	oldKeystate = keystate;

	  	if(keystate & KEY_HOME) {
		  	return false;
	  	}
		if (mode == 1 || mode == 2) { //menu navigation is only relevant to menu modes
			if(keystate & KEY_LEFT_BACK) {
				//Menu down
				if (menuItem<MAXMENU) {
					menuItem++;
					if(menuItem==3 || menuItem==4) {
						menuNum=6;
					} else if (menuItem == 5) {
						menuNum=3;
					} else {
						menuNum=1;
					}
				}
			}

			if(keystate & KEY_LEFT_FORWARD) {
				//Menu up
				if (menuItem>1) {
					menuItem--;
					if(menuItem==3 || menuItem==4) {
						menuNum=6;
					} else if (menuItem == 5) {
						menuNum=3;
					} else {
						menuNum=1;
					}
				}
			}
		}
		if (mode == 1) {
			if(keystate & KEY_RIGHT_FORWARD) {
				//Menu down
				if (menuNum<24) {
					menuNum++;
				}
			}

			if(keystate & KEY_RIGHT_BACK) {
				//Menu up
				if (menuNum>1) {
					menuNum--;
				}
			}

			if(keystate & KEY_INPUT1) {
				//Clear
				PlaySound(SOUND_FIRE);
				steps=0;
				menuItem=1;
				menuNum=1;
				mode=1;
				OpenMotors();
			}

			if(keystate & KEY_INPUT2) {
				//Menu select
				if(steps+1<MAXSTEPS) {
					steps++;
					moveList[steps].cmd=menuItem;
					moveList[steps].num=menuNum;
					PlaySound(SOUND_BEEP);
				}
			}
			if(keystate & KEY_MENU) {
				//Switch to second menu
				mode=2;
				menuItem=1;
				menuNum=1;
				PlaySound(SOUND_BEEP);
			}
		} else if (mode == 2) {
			if(keystate & KEY_INPUT1) {
				//Switch back to first menu
				mode=1;
				menuItem=1;
				menuNum=1;
				PlaySound(SOUND_BEEP);
			}
			if (keystate & KEY_INPUT2) {
				//Menu select
				switch(menuItem) {
					case 1: { //Free Roam
						mode=4;
						PlaySound(SOUND_BEEP);
						CloseMotors();
					} break;
					case 2: { //Load route
						LoadRoute();
						ClearScreen();
						PlaySound(SOUND_BEEP);
						SetTextColor(white);
						DrawText(5, 65, "Loading...");
						Show();
						Sleep(500); //Just so they notice...
						mode=2;
					} break;
					case 3: { //Save route
						PlaySound(SOUND_BEEP);
						SaveRoute();
						ClearScreen();
						SetTextColor(white);
						DrawText(5, 65, "Saving...");
						Show();
						Sleep(500); //Just so they notice...
						mode=2;
					} break;
					case 4: { //Recalibrate
						PlaySound(SOUND_BEEP);
						mode=3;		//Recalibration mode
						menuNum=1;	//Use menuNum as steps throught the process - 1=ready, 2=working
					} break;
					case 5: { //About
						PlaySound(SOUND_GO);
						mode=5;
						CloseMotors();
					} break;
				}
			}

			if(keystate & KEY_MENU) {
				//Switch back to first menu
				mode=1;
				menuItem=1;
				menuNum=1;
				PlaySound(SOUND_BEEP);
			}
		} else if (mode==3) {
			//Recalibrate.
			if(keystate & KEY_INPUT1) {
				//Cancel
				PlaySound(SOUND_BEEP);
				SetMotors(0,0);
				mode=2;
				menuItem=4;
				menuNum=1;
			}
			if (keystate & KEY_INPUT2) {
				//Start/Stop
				PlaySound(SOUND_BEEP);
				switch (menuNum) {
					case 1: { //Start
						menuNum=2;
						ResetTimer();
						SetMotors(10000,-10000);
					}
					break;
					case 2: { //Stop
						rotateSleep = ReadTimer() / 24;
						SetMotors(0,0);
						mode=2;
						menuItem=4;
						menuNum=1;
						SaveCalibration();
					}
				}
			}
		} else if (mode==4 || mode==5) {
			if(keystate & KEY_MENU) {
				//Switch back to first menu
				PlaySound(SOUND_BEEP);
				mode=2;
				menuItem=1;
				menuNum=1;
				OpenMotors();
			}
			if (keystate & KEY_INPUT1) {
				IRState = !IRState;
				SetIR(IRState);
			}

			if (keystate & KEY_INPUT2) {
				PlaySound(SOUND_BEEP);
				mode=2;
				menuItem=1;
				menuNum=1;
				OpenMotors();
			}
		}

	  	if(keystate & KEY_RUN) {
		  	//Go
		  	ClearScreen();
		  	Show();
		  	PlaySound(SOUND_GO);

		  	//Cycle through steps and execute
		  	int count;
		  	SetTextColor(green);
		  	for(count=1; count<=steps;count++) {
				switch(moveList[count].cmd) {
				  	case 1: { //Forward
						ClearScreen();
						DrawText(5, 100, "%d: Forward %d",count, moveList[count].num);
						Show();
						SetMotors(10000,10000);
						Sleep(FORWARDSLEEP * moveList[count].num);
						SetMotors(0,0);
					}
					break;
				  	case 2: { //Back
						ClearScreen();
						DrawText(5, 100, "%d: Back %d",count, moveList[count].num);
						Show();
						SetMotors(-10000,-10000);
						Sleep(FORWARDSLEEP * moveList[count].num);
						SetMotors(0,0);
					}
					break;
				  	case 3: { //Right
						ClearScreen();
						DrawText(5, 100, "%d: Right %d",count, moveList[count].num * 15);
						Show();
						SetMotors(10000,-10000);
						Sleep(rotateSleep * moveList[count].num);
						SetMotors(0,0);
					}
					break;
				  	case 4: { //Left
						ClearScreen();
						DrawText(5, 100, "%d: Left %d",count, moveList[count].num * 15);
						Show();
						SetMotors(-10000,10000);
						Sleep(rotateSleep * moveList[count].num);
						SetMotors(0,0);
					}
					break;
					case 5: { //Fire
						ClearScreen();
						SetTextColor(red);
						DrawText(10, 45, "PEW! PEW! PEW!");
						SetTextColor(green);
						DrawText(5, 100, "%d: Fire %d",count, moveList[count].num);
						Show();
						int fireCount;
						for(fireCount=0; fireCount<moveList[count].num; fireCount++) {
							PlaySound(SOUND_FIRE);
						}
					}
				}
			}
			//reset menu pointer
			menuItem=1;
			menuNum=1;
			PlaySound(SOUND_GO);
	  	}

	  	DrawMenu();
  	}
  	Sleep(50); //to stop the radio being on full time
  	return true;
}