Example #1
0
JNIEXPORT jlong JNICALL
    Java_com_sun_media_sound_MixerSourceLine_nOpen(JNIEnv* e, jobject thisObj, jint sampleSizeInBits, jint channels, jfloat sampleRate, jint bufferSize)
{

    STREAM_REFERENCE id = NULL;
    jobject			globalSourceLineObj = NULL;

    // get all the class, method, and field id's ONCE.
    // store a global reference to the java source line class to make sure the id's remain valid.
    // $$kk: 03.22.99: need to make sure we release this reference eventually!

    if (g_mixerSourceLineClass == NULL) 
	{
	    if (!initializeJavaCallbackVars(e, thisObj))
		{
		    ERROR0("Failed to initalized Java callback vars!\n");
		    return GENERAL_BAD;
		}
	}

	
    // $$kk: 03.15.98: GLOBAL REF!  this has definite memory leak potential; need to make sure
    // to release all global refs....
    globalSourceLineObj = (*e)->NewGlobalRef(e, thisObj);

	
    // possible error values: NO_ERR, STREAM_STOP_PLAY, PARAM_ERR, NO_FREE_VOICES, possibly others??, 

    TRACE0("Java_com_sun_media_sound_MixerSourceLine_nOpen.\n");
    TRACE2("e %lx, thisObj %lx\n", e, thisObj);
    TRACE2("bufferSize %lu, sampleRate %d\n", (UINT32)bufferSize, FLOAT_TO_FIXED(sampleRate));
    TRACE2("sampleSizeInBits %d, channels %d\n", (int)sampleSizeInBits, (int)channels);

    TRACE0("Calling GM_AudioStreamSetup\n");

    // we are not handling errors properly here
    id = GM_AudioStreamSetup((void*)e, (void *)globalSourceLineObj, MixerSourceLineCallbackProc,
			     (UINT32)bufferSize,
			     FLOAT_TO_FIXED(sampleRate),
			     (char)sampleSizeInBits, (char)channels);

    TRACE0("Returned from GM_AudioStreamSetup\n");


    if (id != NULL)
	{
	    if (GM_AudioStreamError(id) != NO_ERR)
		{
		    id = NULL;
		}
	}

    TRACE1("Java_com_sun_media_sound_MixerSourceLine_nOpen completed -> new stream id: %lx\n", id);
	
    return (jlong) (INT_PTR) id;
}
Example #2
0
void CRenderer::DrawRect( float x, float y, float w, float h, const CIwColour & color )
{
	int32 nVerts = 5;

	CIwSVec2 *  vertex           = IW_GX_ALLOC(CIwSVec2, nVerts); 
	uint16*     indexStream      = IW_GX_ALLOC(uint16,   nVerts);
	CIwColour*  colour           = IW_GX_ALLOC(CIwColour,nVerts);
	int count = 0;

	for (int i = 0; i < nVerts; i++)
	{
		colour[i]   = color;
		indexStream[count] = count; 
		count++;
	}

	vertex[0].x = FLOAT_TO_FIXED(x);
	vertex[0].y = FLOAT_TO_FIXED(y);

	vertex[1].x = FLOAT_TO_FIXED((x + w));
	vertex[1].y = FLOAT_TO_FIXED(y);

	vertex[2].x = FLOAT_TO_FIXED((x + w));
	vertex[2].y = FLOAT_TO_FIXED((y + h));

	vertex[3].x = FLOAT_TO_FIXED(x);
	vertex[3].y = FLOAT_TO_FIXED((y + h));

	vertex[4] = vertex[0];


	Draw(IW_GX_LINE_STRIP, vertex, NULL, indexStream, colour, nVerts, NULL );
}
Example #3
0
fixed_t FixedHypot(fixed_t x, fixed_t y)
{
#ifdef HAVE_HYPOT
	const float fx = FIXED_TO_FLOAT(x);
	const float fy = FIXED_TO_FLOAT(y);
	float fz;
#ifdef HAVE_HYPOTF
	fz = hypotf(fx, fy);
#else
	fz = (float)hypot(fx, fy);
#endif
	return FLOAT_TO_FIXED(fz);
#else // !HAVE_HYPOT
	fixed_t ax, yx, yx2, yx1;
	if (abs(y) > abs(x)) // |y|>|x|
	{
		ax = abs(y); // |y| => ax
		yx = FixedDiv(x, y); // (x/y)
	}
	else // |x|>|y|
	{
		ax = abs(x); // |x| => ax
		yx = FixedDiv(y, x); // (x/y)
	}
	yx2 = FixedMul(yx, yx); // (x/y)^2
	yx1 = FixedSqrt(1+FRACUNIT + yx2); // (1 + (x/y)^2)^1/2
	return FixedMul(ax, yx1); // |x|*((1 + (x/y)^2)^1/2)
#endif
}
Example #4
0
void update_wall_scale(World *w, int wall_num, fixed xscale, fixed yscale)
{
    Wall *wall;
    Texture *texture;
    fixed wall_length;

    if (wall_num < 0 || wall_num > TABLE_SIZE(w->walls))
        fatal_error("invalid wall number");

    wall = (Wall *) w->walls->table + wall_num;
    texture = wall->surface_texture;

    wall_length =
        FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(wall->vertex2->x -
                                           wall->vertex1->x) *
                            FIXED_TO_FLOAT(wall->vertex2->x -
                                           wall->vertex1->x) +
                            FIXED_TO_FLOAT(wall->vertex2->y -
                                           wall->vertex1->y) *
                            FIXED_TO_FLOAT(wall->vertex2->y -
                                           wall->vertex1->y)));
    wall->yscale = fixmul(yscale, INT_TO_FIXED(texture->height));
    wall->xscale = fixmul(fixmul(xscale, INT_TO_FIXED(texture->width)),
                          wall_length);
}
Example #5
0
void CRenderer::CameraTransform( CIwSVec2 * vertex, int vertexCount )
{
	iwsfixed scale = IW_SFIXED(mDeviceParams.scale);

	CIwSVec2 t( FLOAT_TO_FIXED(mCamera.GetPos().x), FLOAT_TO_FIXED(mCamera.GetPos().y) );
	iwsfixed csacale = IW_SFIXED( mCamera.GetScale() );

	for (int i = 0; i < vertexCount; i++)
	{
		vertex[i] -= t;
		vertex[i].x = IW_FIXED_MUL(vertex[i].x, csacale);
		vertex[i].y = IW_FIXED_MUL(vertex[i].y, csacale);

		vertex[i].x = IW_FIXED_MUL(vertex[i].x, scale) + ((mDeviceParams.offsetX) << 3);
		vertex[i].y = IW_FIXED_MUL(vertex[i].y, scale) + ((mDeviceParams.offsetY) << 3);
	}
}
Example #6
0
fixed_t FixedSqrt(fixed_t x)
{
	const float fx = FIXED_TO_FLOAT(x);
	float fr;
#ifdef HAVE_SQRTF
	fr = sqrtf(fx);
#else
	fr = (float)sqrt(fx);
#endif
	return FLOAT_TO_FIXED(fr);
}
Example #7
0
static void
draw(void)
{
#if USE_FIXED_POINT
   static const GLfixed verts[3][2] = {
      { -65536, -65536 },
      {  65536, -65536 },
      {      0,  65536 }
   };
   static const GLfixed colors[3][4] = {
      { 65536,     0,     0,    65536 },
      {     0, 65536,     0 ,   65536},
      {     0,     0, 65536 ,   65536}
   };
#else
   static const GLfloat verts[3][2] = {
      { -1, -1 },
      {  1, -1 },
      {  0,  1 }
   };
   static const GLfloat colors[3][4] = {
      { 1, 0, 0, 1 },
      { 0, 1, 0, 1 },
      { 0, 0, 1, 1 }
   };
#endif

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   {
#if USE_FIXED_POINT
      glVertexPointer(2, GL_FIXED, 0, verts);
      glColorPointer(4, GL_FIXED, 0, colors);
#else
      glVertexPointer(2, GL_FLOAT, 0, verts);
      glColorPointer(4, GL_FLOAT, 0, colors);
#endif
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);

      /* draw triangle */
      glDrawArrays(GL_TRIANGLES, 0, 3);

      /* draw some points */
      glPointSizex(FLOAT_TO_FIXED(15.5));
      glDrawArrays(GL_POINTS, 0, 3);

      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
   }

   glfwSwapBuffers(window);
}
Example #8
0
Token_type get_real_token(FILE *fp, fixed *f)
{
    double d;
    int c;

    c = skip_whitespace(fp);
    if (c == EOF)
        return Token_EOF;

    ungetc(c, fp);
    if (fscanf(fp, "%lf", &d) != 1)
        parse_error("numeric constant expected");

    *f = FLOAT_TO_FIXED(d);

    return Token_real;
}
Example #9
0
// DoFunction()
// -----------------------------------------------------
//
//
static void PV_DoFunction(int subMenu)
{
	long				slot;
	
	long				tmpLong1, tmpLong2, tmpLong3, tmpLong4, tmpLong5;
	unsigned char		tmpChar1, tmpChar2;
	double				tmpDouble1, tmpDouble2, tmpDouble3;
	BAE_UNSIGNED_FIXED	tmpUFixed;
	BAE_BOOL			tmpBool;
	char				tmpBuffer[256];
	FILE				*filePtr = NULL;
	static void			*bufferPtr = NULL;

	BAEResult			err;
	
	err = BAE_NO_ERROR;

	while (((slot=GetLong("Slot? (0-3) > "))<0) || (slot>=MAX_SLOTS))
	{
		printf("Try again.  Choose a slot between 0 and %d\n", MAX_SLOTS-1);
	}

	switch (subMenu)
	{
		case FUNC_NEW:
		// BAESong_New(BAEMixer mixer);
			{
				if (gSongs[slot])
				{
					printf(": Deleting old song in slot %d...\n", slot);
					BAESong_Delete(gSongs[slot]);
					gSongs[slot] = NULL;
				}
				gSongs[slot] = BAESong_New(gMixer);
				if (gSongs[slot] != NULL)
				{
					printf(": New BAESong in slot %d.\n", slot);
				}
				else
				{
					printf(": BAESong_New() returned NULL\n");
				}
			}
			break;

		case FUNC_DELETE:
		// BAESong_Delete(BAESong song);
			{
				err = BAESong_Delete(gSongs[slot]);
				if (!err) gSongs[slot] = NULL;
			}
			break;
		
		case FUNC_SET_VOLUME:
		// BAESong_SetVolume(BAESong song, BAE_UNSIGNED_FIXED volume);
			{
				tmpDouble1 = GetDouble("Volume (1.0 norm) > ");
				err = BAESong_SetVolume(gSongs[slot], FLOAT_TO_UNSIGNED_FIXED(tmpDouble1));
			}
			break;
		
		case FUNC_GET_VOLUME: 
		// BAESong_GetVolume(BAESong song, BAE_UNSIGNED_FIXED *outVolume);
			{
				err = BAESong_GetVolume(gSongs[slot], &tmpUFixed);
				if (!err) printf(": volume = %g\n", UNSIGNED_FIXED_TO_FLOAT(tmpUFixed));
			}
			break;
		
		case FUNC_DOES_CHANNEL_ALLOW_TRANSPOSE: 
		// BAESong_DoesChannelAllowTranspose(BAESong song, unsigned short int channel, BAE_BOOL *outAllowTranspose);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_DoesChannelAllowTranspose(gSongs[slot], (unsigned short)tmpLong1, &tmpBool);
				if (!err)
				{
					printf(": Channel %ld does ", tmpLong1);
					if (!tmpBool) printf("NOT ");
					printf("allow transpose\n");
				}
			}
			break;
		
		case FUNC_ALLOW_CHANNEL_TRANSPOSE:
		// BAESong_AllowChannelTranspose(BAESong song, unsigned short int channel, BAE_BOOL allowTranspose);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpBool = (BAE_BOOL)GetBool("Allow transpose? (y/n) > ");
				err = BAESong_AllowChannelTranspose(gSongs[slot], (unsigned short)tmpLong1, tmpBool);
			}
			break;
		
		case FUNC_SET_TRANSPOSE:
		// BAESong_SetTranspose(BAESong song, long semitones);
			{
				tmpLong1 = GetLong("Transpose semitones > ");
				err = BAESong_SetTranspose(gSongs[slot], tmpLong1);
			}
			break;
		
		case FUNC_GET_TRANSPOSE:
		// BAESong_GetTranspose(BAESong song, long *outSemitones);
			{
				tmpLong1 = 0;
				err = BAESong_GetTranspose(gSongs[slot], &tmpLong1);
				if (!err) printf(": Transpose = %ld semitones\n", tmpLong1);
			}
			break;
		
		case FUNC_MUTE_CHANNEL:
		// BAESong_MuteChannel(BAESong song, unsigned short int channel);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_MuteChannel(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_UNMUTE_CHANNEL:
		// BAESong_UnmuteChannel(BAESong song, unsigned short int channel);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_UnmuteChannel(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_GET_CHANNEL_MUTE_STATUS:
		// BAESong_GetChannelMuteStatus(BAESong song, BAE_BOOL *outChannels);
			{
				BAE_BOOL result[16];
				int i;

				err = BAESong_GetChannelMuteStatus(gSongs[slot], result);
				if (!err)
				{
					printf("channel:     0123456789ABCDEF\n");
					printf("mute status: ");
					for (i=0; i<16; i++)
					{
						printf("%d", (int)result[i]);
					}
					printf("\n");
				}
			}
			break;

		case FUNC_SOLO_CHANNEL:
		// BAESong_SoloChannel(BAESong song, unsigned short int channel);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_SoloChannel(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_UNSOLO_CHANNEL:
		// BAESong_UnSoloChannel(BAESong song, unsigned short int channel);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_UnSoloChannel(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_GET_CHANNEL_SOLO_STATUS:
		// BAESong_GetChannelSoloStatus(BAESong song, BAE_BOOL *outChannels);
			{
				BAE_BOOL result[16];
				int i;

				err = BAESong_GetChannelSoloStatus(gSongs[slot], result);
				if (!err)
				{
					printf("channel:     0123456789ABCDEF\n");
					printf("solo status: ");
					for (i=0; i<16; i++)
					{
						printf("%d", (int)result[i]);
					}
					printf("\n");
				}
			}
			break;

		case FUNC_LOAD_INSTRUMENT:
		// BAESong_LoadInstrument(BAESong song, BAE_INSTRUMENT instrument);
			{
				tmpLong1 = GetLong("Instrument > ");
				err = BAESong_LoadInstrument(gSongs[slot], tmpLong1);
			}
			break;

		case FUNC_UNLOAD_INSTRUMENT:
		// BAESong_UnloadInstrument(BAESong song, BAE_INSTRUMENT instrument);
			{
				tmpLong1 = GetLong("Instrument > ");
				err = BAESong_UnloadInstrument(gSongs[slot], tmpLong1);
			}
			break;

		case FUNC_IS_INSTRUMENT_LOADED:
		// BAESong_IsInstrumentLoaded(BAESong song, BAE_INSTRUMENT instrument, BAE_BOOL *outIsLoaded);
			{
				tmpLong1 = GetLong("Instrument > ");
				err = BAESong_IsInstrumentLoaded(gSongs[slot], tmpLong1, &tmpBool);
				if (!err) printf(": Is Loaded = %d\n", (int)tmpBool);
			}
			break;

		case FUNC_GET_CONTROL_VALUE:
		// BAESong_GetControlValue(BAESong song, unsigned char channel, unsigned char controller, char *outValue);
			{
				tmpLong1  = GetLong("Channel > ");
				tmpLong2 = GetLong("Controller > ");
				err = BAESong_GetControlValue(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (char *)&tmpChar1);
				if (!err) printf(": Value = %ld\n", tmpChar1);
			}
			break;

		case FUNC_GET_PROGRAM_BANK:
		// BAESong_GetProgramBank(BAESong song, unsigned char channel, unsigned char *outProgram, unsigned char *outBank);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_GetProgramBank(gSongs[slot], (unsigned char)tmpLong1, &tmpChar1, &tmpChar2);
				if (!err) printf(": Program = %ld, bank = %ld\n", tmpChar1, tmpChar2);
			}
			break;

		case FUNC_GET_PITCH_BEND:
		// BAESong_GetPitchBend(BAESong song, unsigned char channel, unsigned char *outLSB, unsigned char *outMSB);
			{
				tmpLong1 = GetLong("Channel > ");
				err = BAESong_GetPitchBend(gSongs[slot], (unsigned char)tmpLong1, &tmpChar1, &tmpChar2);
				if (!err) printf(": LSB = %ld, MSB = %ld\n", tmpChar1, tmpChar2);
			}
			break;

		case FUNC_PARSE_MIDI_DATA:
		// BAESong_ParseMidiData(BAESong song, unsigned char commandByte, unsigned char data1Byte, unsigned char data2Byte, unsigned char data3Byte, unsigned long time);
			{
				tmpLong1 = GetLong("Command byte > ");
				tmpLong2 = GetLong("Data 1 byte > ");
				tmpLong3 = GetLong("Data 2 byte > ");
				tmpLong4 = GetLong("Data 3 byte > ");
				tmpLong5 = GetLong("Time > ");
				err = BAESong_ParseMidiData(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned char)tmpLong4, (unsigned long)tmpLong5);
			}
			break;

		case FUNC_NOTE_OFF:
		// BAESong_NoteOff(BAESong song, unsigned char channel, unsigned char note, unsigned char velocity, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Note > ");
				tmpLong3 = GetLong("Velocity > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_NoteOff(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_NOTE_ON_WITH_LOAD:
		// BAESong_NoteOnWithLoad(BAESong song, unsigned char channel, unsigned char note, unsigned char velocity, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Note > ");
				tmpLong3 = GetLong("Velocity > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_NoteOnWithLoad(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_NOTE_ON:
		// BAESong_NoteOn(BAESong song, unsigned char channel, unsigned char note, unsigned char velocity, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Note > ");
				tmpLong3 = GetLong("Velocity > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_NoteOn(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_KEY_PRESSURE:
		// BAESong_KeyPressure(BAESong song, unsigned char channel, unsigned char note, unsigned char pressure, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Note > ");
				tmpLong3 = GetLong("Pressure > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_KeyPressure(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_CONTROL_CHANGE:
		// BAESong_ControlChange(BAESong song, unsigned char channel, unsigned char controlNumber, unsigned char controlValue, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Control number > ");
				tmpLong3 = GetLong("Control value > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_ControlChange(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_PROGRAM_BANK_CHANGE:
		// BAESong_ProgramBankChange(BAESong song, unsigned char channel, unsigned char programNumber, unsigned char bankNumber, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Program > ");
				tmpLong3 = GetLong("Bank > ");
				tmpLong4 = GetLong("Time > ");
				err = BAESong_ProgramBankChange(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned char)tmpLong3, (unsigned long)tmpLong4);
			}
			break;

		case FUNC_PROGRAM_CHANGE:
		// BAESong_ProgramChange(BAESong song, unsigned char channel, unsigned char programNumber, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Program > ");
				tmpLong3 = GetLong("Time > ");
				err = BAESong_ProgramChange(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned long)tmpLong3);
			}
			break;

		case FUNC_CHANNEL_PRESSURE:
		// BAESong_ChannelPressure(BAESong song, unsigned char channel, unsigned char pressure, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("Pressure > ");
				tmpLong3 = GetLong("Time > ");
				err = BAESong_ChannelPressure(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned long)tmpLong3);
			}
			break;

		case FUNC_PITCH_BEND:
		// BAESong_PitchBend(BAESong song, unsigned char channel, unsigned char lsb, unsigned char msb, unsigned long time);
			{
				tmpLong1 = GetLong("Channel > ");
				tmpLong2 = GetLong("LSB > ");
				tmpLong3 = GetLong("MSB > ");
				err = BAESong_ProgramChange(gSongs[slot], (unsigned char)tmpLong1, (unsigned char)tmpLong2, (unsigned long)tmpLong3);
			}
			break;

		case FUNC_ALL_NOTES_OFF:
		// BAESong_AllNotesOff(BAESong song, unsigned long time);
			{
				tmpLong1 = GetLong("Time > ");
				err = BAESong_AllNotesOff(gSongs[slot], (unsigned long)tmpLong1);
			}
			break;

		case FUNC_LOAD_GROOVOID:
		// BAESong_LoadGroovoid(BAESong song, char *cName, BAE_BOOL ignoreBadInstruments);
			{
				GetLine("Name > ", tmpBuffer, 256);
				tmpBool = GetBool("Ignore bad instruments? (y/n) > ");
				err = BAESong_LoadGroovoid(gSongs[slot], tmpBuffer, tmpBool);
			}
			break;

		case FUNC_LOAD_MIDI_FROM_MEMORY:
		// BAESong_LoadMidiFromMemory(BAESong song, void const* pMidiData, unsigned long midiSize, BAE_BOOL ignoreBadInstruments);
			{
				GetLine("Filepath > ", tmpBuffer, 256);

				if (bufferPtr)
				{
					free(bufferPtr);
					bufferPtr = NULL;
				}
				filePtr = fopen(tmpBuffer, "rb");
				if (filePtr != NULL)
				{
					// Find the length of the file
					fseek(filePtr, 0, SEEK_END);
					tmpLong1 = ftell(filePtr);
					// Return to the beginning
					fseek(filePtr, 0, SEEK_SET);

					// Now blast everything to a malloc'd buffer
					bufferPtr = malloc((size_t) tmpLong1);
					tmpLong2 = fread(bufferPtr, sizeof(char), tmpLong1, filePtr);
					if (tmpLong2 != tmpLong1)
					{
						/// Yikes, we have an anomaly -- could check ferror...
						printf("ERROR: File read error -- not BAE related...\n");
					}
					else
					{
						err = BAESong_LoadMidiFromMemory(gSongs[slot],
														bufferPtr,
														tmpLong2,
														TRUE);
					}
					fclose(filePtr);
				}
				else
				{
					printf("ERROR: Couldn't find file to open into memory -- not BAE related...\n");
				}
			}
			break;

		case FUNC_LOAD_MIDI_FROM_FILE:
		// BAESong_LoadMidiFromFile(BAESong song, BAEPathName filePath, BAE_BOOL ignoreBadInstruments);
			{
				GetLine("Filepath > ", tmpBuffer, 256);
				tmpBool = GetBool("Ignore bad instruments? (y/n) > ");
				err = BAESong_LoadMidiFromFile(gSongs[slot], tmpBuffer, tmpBool);
			}
			break;

		case FUNC_LOAD_RMF_FROM_MEMORY:
		// BAESong_LoadRmfFromMemory(BAESong song, void *pRMFData, unsigned long rmfSize, short int songIndex, BAE_BOOL ignoreBadInstruments);
			{
				GetLine("Filepath > ", tmpBuffer, 256);
				tmpLong3 = GetLong("Song index > ");

				if (bufferPtr)
				{
					free(bufferPtr);
					bufferPtr = NULL;
				}
				filePtr = fopen(tmpBuffer, "rb");
				if (filePtr != NULL)
				{
					// Find the length of the file
					fseek(filePtr, 0, SEEK_END);
					tmpLong1 = ftell(filePtr);
					// Return to the beginning
					fseek(filePtr, 0, SEEK_SET);

					// Now blast everything to a malloc'd buffer
					bufferPtr = malloc((size_t) tmpLong1);
					tmpLong2 = fread(bufferPtr, sizeof(char), tmpLong1, filePtr);
					if (tmpLong2 != tmpLong1)
					{
						/// Yikes, we have an anomaly -- could check ferror...
						printf("ERROR: File read error -- not BAE related...\n");
					}
					else
					{
						err = BAESong_LoadRmfFromMemory(gSongs[slot],
														bufferPtr,
														(unsigned long)tmpLong2,
														(short)tmpLong3,
														TRUE);
					}
					fclose(filePtr);
				}
				else
				{
					printf("ERROR: Couldn't find file to open into memory -- not BAE related...\n");
				}			
			}
			break;

		case FUNC_LOAD_RMF_FROM_FILE:
		// BAESong_LoadRmfFromFile(BAESong song, BAEPathName filePath, short int songIndex, BAE_BOOL ignoreBadInstruments);
			{
				GetLine("Filepath > ", tmpBuffer, 256);
				tmpLong1 = GetLong("Song index > ");
				tmpBool = GetBool("Ignore bad instruments? (y/n) > ");
				err = BAESong_LoadRmfFromFile(gSongs[slot], (BAEPathName)tmpBuffer, (short)tmpLong1, tmpBool);
			}
			break;

		case FUNC_PREROLL:
		// BAESong_Preroll(BAESong song);
			{
				err = BAESong_Preroll(gSongs[slot]);
			}
			break;

		case FUNC_START:
		// BAESong_Start(BAESong song, short int priority);
			{
				tmpLong1 = GetLong("Priority > ");
				err = BAESong_Start(gSongs[slot], (short)tmpLong1);
			}
			break;

		case FUNC_STOP:
		// BAESong_Stop(BAESong song, BAE_BOOL startFade);
			{
				tmpBool = GetBool("Start fade? (y/n) > ");
				err = BAESong_Stop(gSongs[slot], tmpBool);
			}
			break;

		case FUNC_PAUSE:
		// BAESong_Pause(BAESong song);
			{
				err = BAESong_Pause(gSongs[slot]);
			}
			break;

		case FUNC_RESUME:
		// BAESong_Resume(BAESong song);
			{
				err = BAESong_Resume(gSongs[slot]);
			}
			break;

		case FUNC_IS_PAUSED:
		// BAESong_IsPaused(BAESong song, BAE_BOOL *outIsPaused);
			{
				err = BAESong_IsPaused(gSongs[slot], &tmpBool);
				if (!err) printf(": IsPaused = %d\n", (int)tmpBool);
			}
			break;

		case FUNC_FADE:
		// BAESong_Fade(BAESong song, BAE_FIXED sourceVolume, BAE_FIXED destVolume, BAE_FIXED timeInMiliseconds);
			{
				tmpDouble1  = GetDouble("sourceVolume (1.0 norm) > ");
				tmpDouble2 = GetDouble("destVolume (1.0 norm) > ");
				tmpDouble3 = GetDouble("time (msec) > ");
				err = BAESong_Fade(gSongs[slot], FLOAT_TO_FIXED(tmpDouble1), FLOAT_TO_FIXED(tmpDouble2), FLOAT_TO_FIXED(tmpDouble3));
			}
			break;

		case FUNC_IS_DONE:
		// BAESong_IsDone(BAESong song, BAE_BOOL *outIsDone);
			{
				err = BAESong_IsDone(gSongs[slot], &tmpBool);
				if (!err) printf(": IsDone = %d\n", (int)tmpBool);
			}
			break;

		case FUNC_ARE_MIDI_EVENTS_PENDING:
		// BAESong_AreMidiEventsPending(BAESong song, BAE_BOOL *outPending);
			{
				err = BAESong_AreMidiEventsPending(gSongs[slot], &tmpBool);
				if (!err) printf(": Events Pending = %d\n", (int)tmpBool);
			}
			break;

		case FUNC_SET_LOOPS:
		// BAESong_SetLoops(BAESong song, short numLoops);
			{
				tmpLong1 = GetLong("Number of loops (0 = no repeats)> ");
				err = BAESong_SetLoops(gSongs[slot], (short)tmpLong1);
			}
			break;

		case FUNC_GET_LOOPS:
		// BAESong_GetLoops(BAESong song, short int *outNumLoops);
			{
				err = BAESong_GetLoops(gSongs[slot], (short *)&tmpLong1);
				if (!err) printf(": maxLoopCount = %d\n", (short)tmpLong1);
			}
			break;

		case FUNC_SET_LOOP_FLAG:
		// BAESong_SetLoopFlag(BAESong song, BAE_BOOL loop);
			{
//				tmpBool = GetBool("loop? (y/n) > ");
//				err = BAESong_SetLoopFlag(gSongs[slot], tmpBool);

				// NO LONGER SUPPORTED!
				err = BAE_GENERAL_BAD;
			}
			break;

		case FUNC_GET_LOOP_FLAG:
		// BAESong_GetLoopFlag(BAESong song, BAE_BOOL *outLoop);
			{
//				err = BAESong_GetLoopFlag(gSongs[slot], &tmpBool);
//				if (!err) printf(": Loop flag = %d\n", (int)tmpBool);

				// NO LONGER SUPPORTED!
				err = BAE_GENERAL_BAD;
			}
			break;

		case FUNC_SET_MICROSECOND_POSITION:
		// BAESong_SetMicrosecondPosition(BAESong song, unsigned long ticks);
			{
				tmpLong1 = GetLong("Ticks > ");
				err = BAESong_SetMicrosecondPosition(gSongs[slot], (unsigned long)tmpLong1);
			}
			break;

		case FUNC_GET_MICROSECOND_POSITION:
		// BAESong_GetMicrosecondPosition(BAESong song, unsigned long *outTicks);
			{
				err = BAESong_GetMicrosecondPosition(gSongs[slot], (unsigned long *)&tmpLong1);
				if (!err) printf(": Microsecond position = %ul\n", (unsigned long)tmpLong1);
			}
			break;

		case FUNC_GET_MICROSECOND_LENGTH:
		// BAESong_GetMicrosecondLength(BAESong song, unsigned long *outLength);
			{
				err = BAESong_GetMicrosecondLength(gSongs[slot], (unsigned long *)&tmpLong1);
				if (!err) printf(": Length = %ul\n", tmpLong1);
			}
			break;

		case FUNC_SET_MASTER_TEMPO:
		// BAESong_SetMasterTempo(BAESong song, BAE_UNSIGNED_FIXED tempoFactor);
			{
				tmpDouble1 = GetDouble("Tempo factor (1.0 norm) > ");
				err = BAESong_SetMasterTempo(gSongs[slot], FLOAT_TO_UNSIGNED_FIXED(tmpDouble1));
			}
			break;

		case FUNC_GET_MASTER_TEMPO:
		// BAESong_GetMasterTempo(BAESong song, BAE_UNSIGNED_FIXED *outTempoFactor);
			{
				err = BAESong_GetMasterTempo(gSongs[slot], &tmpUFixed);
				if (!err) printf(": Tempo factor = %g\n", UNSIGNED_FIXED_TO_FLOAT(tmpUFixed));
			}
			break;

		case FUNC_MUTE_TRACK:
		// BAESong_MuteTrack(BAESong song, unsigned short int track);
			{
				tmpLong1 = GetLong("Track > ");
				err = BAESong_MuteTrack(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_UNMUTE_TRACK:
		// BAESong_UnmuteTrack(BAESong song, unsigned short int track);
			{
				tmpLong1 = GetLong("Track > ");
				err = BAESong_UnmuteTrack(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_GET_TRACK_MUTE_STATUS:
		// BAESong_GetTrackMuteStatus(BAESong song, BAE_BOOL *outTracks);
			{				
				BAE_BOOL result[65];
				int i,j;

				err = BAESong_GetTrackMuteStatus(gSongs[slot], result);
				if (!err)
				{
					for (j=0; j<4; j++)
					{
						printf("track:       %d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%dA%dB%dC%dD%dE%dF\n",j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j);
						printf("mute status: ");
						for (i=0; i<16; i++)
						{
							printf(" %d", (int)result[j*16 + i]);
						}
						printf("\n\n");
					}
				}
			}
			break;

		case FUNC_SOLO_TRACK:
		// BAESong_SoloTrack(BAESong song, unsigned short int track);
			{
				tmpLong1 = GetLong("Track > ");
				err = BAESong_SoloTrack(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_UNSOLO_TRACK:
		// BAESong_UnSoloTrack(BAESong song, unsigned short int track);
			{
				tmpLong1 = GetLong("Track > ");
				err = BAESong_UnSoloTrack(gSongs[slot], (unsigned short)tmpLong1);
			}
			break;

		case FUNC_GET_SOLO_TRACK_STATUS:
		// BAESong_GetSoloTrackStatus(BAESong song, BAE_BOOL *outTracks);
			{
				BAE_BOOL result[65];
				int i,j;

				err = BAESong_GetSoloTrackStatus(gSongs[slot], result);
				if (!err)
				{
					for (j=0; j<4; j++)
					{
						printf("track:       %d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%dA%dB%dC%dD%dE%dF\n",j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j);
						printf("solo status: ");
						for (i=0; i<16; i++)
						{
							printf(" %d", (int)result[j*16 + i]);
						}
						printf("\n\n");
					}
				}
			}
			break;

		default:
			break;
	}

	if (err)
	{
		printf("\a! Error code: %s (%d)\n", BAEResultToStr(err), (int)err);
	}
	else
	{
		printf("OK.\n");
	}
}
Example #10
0
//
//  3 ___ 4
//   |\  |
//   | \ |
//  2|__\|1
//
//    u   v
//    1   0  4 (right bottom)
//    0   0  3 (left  bottom)
//    0   1  2 (left  top   )
//    1   1  1 (right top   )
//

#define FLOAT_TO_FIXED(x) (long)((x)*65536.0f)
static GLfixed vertices[] = {
    FLOAT_TO_FIXED(1.0),  FLOAT_TO_FIXED(-1.0), FLOAT_TO_FIXED(-1.0),
    FLOAT_TO_FIXED(-1.0), FLOAT_TO_FIXED(-1.0), FLOAT_TO_FIXED(1.0),
    FLOAT_TO_FIXED(1.0),  FLOAT_TO_FIXED(1.0),
};

static GLfloat texcoords[] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
static GLuint progid;

static void draw_texture(GLuint texid) {
  glUseProgram(progid);
  glBindTexture(GL_TEXTURE_2D, texid);
  GLint attriblocation = glGetAttribLocation(progid, "position");
  glEnableVertexAttribArray(attriblocation);
  glVertexAttribPointer(attriblocation, 2, GL_FIXED, 0, 0, vertices);
  attriblocation = glGetAttribLocation(progid, "texcoords");
  glEnableVertexAttribArray(attriblocation);
Example #11
0
int main(int argc, char *argv[])
{
     World *w;
     FILE *fp;
     Boolean quit = False;
     Intent *intent;
     fixed v = FIXED_ZERO;
     double vx = 0.0, vy = 0.0, va = 0.0;
     #ifdef MSDOS
     long       frames;
     time_t     starttime, endtime;
     #endif


     if (argc != 2) {
	  fprintf(stderr, "Usage:  wt <world file>\n");
	  exit(EXIT_FAILURE);
     }

     if ((fp = fopen(argv[1], "r")) == NULL) {
	  perror(argv[1]);
	  exit(EXIT_FAILURE);
     }
     w = read_world_file(fp);
     fclose(fp);

     init_graphics();
     init_renderer(SCREEN_WIDTH, SCREEN_HEIGHT);
     init_input_devices();

     /* setup view */
     view = new_view(fixdiv(FIXED_2PI, INT_TO_FIXED(4)));

     view->x = FIXED_ZERO;
     view->y = FIXED_ZERO;
     view->height = FIXED_ONE;
     view->angle = FIXED_ZERO;

     #ifdef MSDOS
     starttime = time(NULL);
     frames = 0;
     #endif

     while (!quit) {
	  double sin_facing, cos_facing;

	  render(w, view);
      #ifdef MSDOS
      frames++;
      #endif
	  intent = read_input_devices();

	  /* This block code is a hack to do acceleration and deceleration. */
	  if (fabs(vx) > fabs(intent->force_x)) {
	       if (vx < 0.0)
		    vx = MIN(vx + 0.1, intent->force_x);
	       else
		    vx = MAX(vx - 0.1, intent->force_x);
	  } else if (fabs(vx) < fabs(intent->force_x)) {
	       vx += intent->force_x / 5.0;
	       if (fabs(vx) > fabs(intent->force_x))
		    vx = intent->force_x;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  /* Angular deceleration here is weird and unrealistic, but it feels
	  **   right to me.
	  */
	  if (fabs(va) > fabs(intent->force_rotate))
	       va *= 0.6;
	  else if (fabs(va) < fabs(intent->force_rotate)) {
	       va += intent->force_rotate / 8.0;
	       if (fabs(va) > fabs(intent->force_rotate))
		    va = intent->force_rotate;
	  }
	  view->angle += FLOAT_TO_FIXED(0.3 * va);
	  sin_facing = sin(FIXED_TO_FLOAT(view->angle));
	  cos_facing = cos(FIXED_TO_FLOAT(view->angle));

	  view->x += FLOAT_TO_FIXED(0.8 * vx * cos_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vx * sin_facing);
	  view->x += FLOAT_TO_FIXED(0.8 * vy * -sin_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vy * cos_facing);
	  if (view->height > FIXED_ONE)
	       v -= FIXED_ONE / 16;
	  view->height += v;
	  if (view->height < FIXED_ONE) {
	       v = FIXED_ZERO;
	       view->height = FIXED_ONE;
	  }
	  while (intent->n_special--) {
	       if (intent->special[intent->n_special] == INTENT_END_GAME)
		    quit = True;
	       else
		    v = FIXED_ONE / 2;
	  }
     }

     #ifdef MSDOS
     endtime = time(NULL);
     #endif

     end_input_devices();
     end_graphics();

     #ifdef MSDOS
     printf("%li frames in %lu seconds - %.2f frames per second",
        (long) frames, (long) endtime - starttime,
        (float) frames / (float) (endtime-starttime));
     #endif

     return EXIT_SUCCESS;
}
Example #12
0
#define SYSTEM_CONFIG ((cfg_system_t *)0x4000)
#define OUTPUT_CONFIG ((cfg_output_t *)0x4040)

#define SYSTEM_CFG_VERSION 2
#define OUTPUT_CFG_VERSION 1

#define DEFAULT_NAME_STR "Unnamed"

cfg_system_t default_cfg_system = {
	.version = SYSTEM_CFG_VERSION,
	.name = "Unnamed",
	.default_on = 0,
	.output = 0,
	.autocommit = 1,

	.vin_adc = { .a = FLOAT_TO_FIXED(16*3.3/8.0), .b = 0 },
	.vout_adc = { .a = FLOAT_TO_FIXED(3.3/0.073/8.0), .b = FLOAT_TO_FIXED(452) },
	.cout_adc = { .a = FLOAT_TO_FIXED(3.3*1.25/8.0), .b = FLOAT_TO_FIXED(200) },
	.vout_pwm = { .a = FLOAT_TO_FIXED(8*0.073/3.3), .b = FLOAT_TO_FIXED(33) },
	.cout_pwm = { .a = FLOAT_TO_FIXED(8*0.8/3.3), .b = FLOAT_TO_FIXED(160) },
};

cfg_output_t default_cfg_output = {
	OUTPUT_CFG_VERSION,
	5000, // 5V
	500, // 0.5A
	0,
	0,
};

void config_default_system(cfg_system_t *sys)
Example #13
0
// poly : the convex polygon that encloses all child subsectors
static void WalkBSPNode(INT32 bspnum, poly_t *poly, UINT16 *leafnode, fixed_t *bbox)
{
	node_t *bsp;
	poly_t *backpoly, *frontpoly;
	fdivline_t fdivline;
	polyvertex_t *pt;
	INT32 i;

	// Found a subsector?
	if (bspnum & NF_SUBSECTOR)
	{
		if (bspnum == -1)
		{
			// BP: i think this code is useless and wrong because
			// - bspnum==-1 happens only when numsubsectors == 0
			// - it can't happens in bsp recursive call since bspnum is a INT32 and children is UINT16
			// - the BSP is complet !! (there just can have subsector without segs) (i am not sure of this point)

			// do we have a valid polygon ?
			if (poly && poly->numpts > 2)
			{
				DEBPRINT("Adding a new subsector\n");
				if (addsubsector == numsubsectors + NEWSUBSECTORS)
					I_Error("WalkBSPNode: not enough addsubsectors\n");
				else if (addsubsector > 0x7fff)
					I_Error("WalkBSPNode: addsubsector > 0x7fff\n");
				*leafnode = (UINT16)((UINT16)addsubsector | NF_SUBSECTOR);
				extrasubsectors[addsubsector].planepoly = poly;
				addsubsector++;
			}

			//add subsectors without segs here?
			//HWR_SubsecPoly(0, NULL);
		}
		else
		{
			HWR_SubsecPoly(bspnum&(~NF_SUBSECTOR), poly);
			//Hurdler: implement a loading status

			if (ls_count-- <= 0)
			{
				char s[16];
				int x, y;

				I_OsPolling();
				ls_count = numsubsectors/50;
				CON_Drawer();
				sprintf(s, "%d%%", (++ls_percent)<<1);
				x = BASEVIDWIDTH/2;
				y = BASEVIDHEIGHT/2;
				V_DrawFill(0, 0, vid.width, vid.height, 31); // Black background to match fade in effect
				//V_DrawPatchFill(W_CachePatchName("SRB2BACK",PU_CACHE)); // SRB2 background, ehhh too bright.
				M_DrawTextBox(x-58, y-8, 13, 1);
				V_DrawString(x-50, y, V_YELLOWMAP, "Loading...");
				V_DrawString(x+50-V_StringWidth(s), y, V_YELLOWMAP, s);

				// Is this really necessary at this point..?
				V_DrawCenteredString(BASEVIDWIDTH/2, 40, V_YELLOWMAP, "OPENGL MODE IS INCOMPLETE AND MAY");
				V_DrawCenteredString(BASEVIDWIDTH/2, 50, V_YELLOWMAP, "NOT DISPLAY SOME SURFACES.");
				V_DrawCenteredString(BASEVIDWIDTH/2, 70, V_YELLOWMAP, "USE AT SONIC'S RISK.");

				I_UpdateNoVsync();
			}
		}
		M_ClearBox(bbox);
		poly = extrasubsectors[bspnum&~NF_SUBSECTOR].planepoly;

		for (i = 0, pt = poly->pts; i < poly->numpts; i++,pt++)
			M_AddToBox(bbox, FLOAT_TO_FIXED(pt->x), FLOAT_TO_FIXED(pt->y));

		return;
	}

	bsp = &nodes[bspnum];
	SearchDivline(bsp, &fdivline);
	SplitPoly(&fdivline, poly, &frontpoly, &backpoly);
	poly = NULL;

	//debug
	if (!backpoly)
		nobackpoly++;

	// Recursively divide front space.
	if (frontpoly)
	{
		WalkBSPNode(bsp->children[0], frontpoly, &bsp->children[0],bsp->bbox[0]);

		// copy child bbox
		M_Memcpy(bbox, bsp->bbox[0], 4*sizeof (fixed_t));
	}
	else
		I_Error("WalkBSPNode: no front poly?");

	// Recursively divide back space.
	if (backpoly)
	{
		// Correct back bbox to include floor/ceiling convex polygon
		WalkBSPNode(bsp->children[1], backpoly, &bsp->children[1],
			bsp->bbox[1]);

		// enlarge bbox with seconde child
		M_AddToBox(bbox, bsp->bbox[1][BOXLEFT  ],
			bsp->bbox[1][BOXTOP   ]);
		M_AddToBox(bbox, bsp->bbox[1][BOXRIGHT ],
			bsp->bbox[1][BOXBOTTOM]);
	}
}
Example #14
0
int main(int argc, char *argv[])
{
     World *w;
     View *view;
     Intent *intent;
     Graphics_info *ginfo;
     Tcl_Interp *interp;
     Object *me;
     Boolean quit = False;
#if PROFILE
     int fps_count = 0;
     double total_time = 0.0;
     double start_time;
#endif


     interp = Tcl_CreateInterp();
     updater = updater_create(interp);

     if (argc != 2) {
	  fprintf(stderr, "Usage:  %s <world file>\n", argv[0]);
	  exit(EXIT_FAILURE);
     }

     ginfo = init_graphics();
#define TRUECOLOR
#ifdef TRUECOLOR
     set_texture_trans(32, ginfo->palette.color_lookup);
#else
     set_texture_trans(ginfo->palette.rgb_cube_size,
		       ginfo->palette.color_lookup);
#endif
     init_renderer(ginfo->width, ginfo->height);
     init_input_devices();

     /* Initialize the view */
     view = new_view(FLOAT_TO_FIXED(3.14159265 / 2.0));

     w = new_world();

     parser_init(interp, w);
     if (Tcl_EvalFile(interp, WT_INIT_FILENAME) != TCL_OK) {
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0));
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0));
	  exit(1);
     }

     if (Tcl_EvalFile(interp, argv[1]) != TCL_OK) {
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0));
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0));
	  exit(1);
     }


     while (!quit) {
	  double sin_facing, cos_facing;
	  double fx, fy, fz, torque;
	  Framebuffer *fb;
	  int i;


	  start_time = current_time();

	  intent = read_input_devices();
	  
	  me = get_controlled_object();
	  if (me == NULL)
	       fatal_error("No controlled object");

	  for (i = 0; i < intent->n_special; i++) {

	       switch (intent->special[i]) {
		  case INTENT_END_GAME:
		    quit = True;
		    (void) Tcl_Eval(interp, "action_quit");
		    break;

		  case INTENT_JUMP:
		    (void) Tcl_Eval(interp, "action_jump");
		    break;

		  case INTENT_ACTION1:
		    (void) Tcl_Eval(interp, "action_1");
		    break;

		  case INTENT_ACTION2:
		    (void) Tcl_Eval(interp, "action_2");
		    break;

		  case INTENT_ACTION3:
		    (void) Tcl_Eval(interp, "action_3");
		    break;

		  case INTENT_ACTION4:
		    (void) (Tcl_Eval(interp, "action_4") != TCL_OK);
		    break;

		  case INTENT_ACTION5:
		    (void) Tcl_Eval(interp, "action_5");
		    break;

		  default:
		    break;
	       }
	  }

	  /* Determine forces on viewer. */
	  sin_facing = sin(me->angle);
	  cos_facing = cos(me->angle);
	  fx = cos_facing * intent->force_x - sin_facing * intent->force_y;
	  fy = sin_facing * intent->force_x + cos_facing * intent->force_y;
 	  fz = -0.05 * me->mass;  /* gravity */
	  torque = intent->force_rotate;

	  /* Apply the forces. */
	  object_apply_force(me, fx, fy, fz);
	  object_apply_torque(me, torque);
	  object_update(me);
	  if (me->z <= 0.0 && me->dz <= 0.0) {
	       me->z = 0.0;
	       me->dz = 0.0;
	  }

	  /* Determine the view. */
	  me = get_viewpoint_object();
	  if (me == NULL)
	       fatal_error("No viewpoint object");
	  object_view(me, view);

	  updater_run(updater);

	  /* Display the world. */
	  fb = render(w, view);
	  update_screen(fb);
#if PROFILE
	  fps_count++;
	  total_time += current_time() - start_time;
	  if (fps_count == 100) {
	       printf("fps = %3.2f\n", (double) fps_count / total_time);
	       fps_count = 0;
	       total_time = 0.0;
	  }
#endif
     }

     end_input_devices();
     end_graphics();

     return EXIT_SUCCESS;
}
Example #15
0
void parse_wall(FILE *fp, World *w)
{
    Wall wall;
    char texture_name[STRING_TOKEN_MAX_LENGTH];
    int texture_index;
    int front_region, back_region;
    int vertex1, vertex2;
    fixed wall_length;


    /* vertices */
    if (get_integer_token(fp, &vertex1) != Token_integer)
        parse_error("integer expected");
    if (get_integer_token(fp, &vertex2) != Token_integer)
        parse_error("integer expected");
    if (vertex1 < 0 || vertex1 > TABLE_SIZE(w->vertices))
        parse_error("invalid vertex number");
    if (vertex2 < 0 || vertex2 > TABLE_SIZE(w->vertices))
        parse_error("invalid vertex number");
    wall.vertex1 = &WORLD_VERTEX(w, vertex1);
    wall.vertex2 = &WORLD_VERTEX(w, vertex2);

    /* texture */
    if (get_string_token(fp, texture_name) != Token_string)
        parse_error("texture name expected");
    texture_index = get_texture_index(texture_name);
    if (texture_index < 0 || texture_index > TABLE_SIZE(w->textures))
        parse_error("non-existent texture");
    else
        wall.surface_texture = WORLD_TEXTURE(w, texture_index);

    if (strcmp(texture_name, "sky") == 0)
        wall.sky = True;
    else
        wall.sky = False;

    /* front and back regions */
    if (get_integer_token(fp, &front_region) != Token_integer)
        fatal_error("non-existent region");
    if (get_integer_token(fp, &back_region) != Token_integer)
        fatal_error("non-existent region");
    if (front_region < 0 || front_region > TABLE_SIZE(w->regions))
        fatal_error("non-existent region");
    if (back_region < 0 || back_region > TABLE_SIZE(w->regions))
        fatal_error("non-existent region");
    wall.front = &WORLD_REGION(w, front_region);
    wall.back = &WORLD_REGION(w, back_region);

    /* Texture phase and scale.  This code is somewhat more complicated than
    **   you'd expect, since the texture scale must be normalized to the
    **   wall length.
    */
    if (get_real_token(fp, &wall.xscale) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.yscale) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.xphase) != Token_real)
        parse_error("number expected");
    if (get_real_token(fp, &wall.yphase) != Token_real)
        parse_error("number expected");
    wall_length =
        FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(wall.vertex2->x -
                                           wall.vertex1->x) *
                            FIXED_TO_FLOAT(wall.vertex2->x -
                                           wall.vertex1->x) +
                            FIXED_TO_FLOAT(wall.vertex2->y -
                                           wall.vertex1->y) *
                            FIXED_TO_FLOAT(wall.vertex2->y -
                                           wall.vertex1->y)));
    wall.yscale = fixmul(wall.yscale,
                         INT_TO_FIXED(wall.surface_texture->height));
    wall.xscale = fixmul(fixmul(wall.xscale,
                                INT_TO_FIXED(wall.surface_texture->width)),
                         wall_length);

    add_wall(w, &wall);
}
Example #16
0
void MyGDC_TextureRotation(float angle, Vector centrXY, Vector* V, Vector* S)
{
	Vector tv[4];
	
	XGdcColor(&g_stcMyGDC_DrvCTX, GDC_WHITE16);

    XGdcSetAttrSurf(&g_stcMyGDC_DrvCTX, GDC_TEXTURE_SELECT, GDC_SELECT_TEXTURE);
           
    demo_transform(angle, centrXY, V, tv);
    
	XGdcPrimType(&g_stcMyGDC_DrvCTX, GDC_TRIANGLE_FAN);
		XGdcTexCoord2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(S[0].x), FLOAT_TO_FIXED(S[0].y));
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(tv[0].x), FLOAT_TO_FIXED(tv[0].y));
		XGdcTexCoord2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(S[1].x), FLOAT_TO_FIXED(S[01].y));
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(tv[1].x), FLOAT_TO_FIXED(tv[1].y));
		XGdcTexCoord2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(S[2].x), FLOAT_TO_FIXED(S[2].y));
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(tv[2].x), FLOAT_TO_FIXED(tv[2].y));
		XGdcTexCoord2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(S[3].x), FLOAT_TO_FIXED(S[3].y));
		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(tv[3].x), FLOAT_TO_FIXED(tv[3].y));
	XGdcPrimEnd(&g_stcMyGDC_DrvCTX);   	
	
	TransferDisplayList(&g_stcMyGDC_DrvCTX);
	XGdcCancelDisplayList(&g_stcMyGDC_DrvCTX);	
	
	XGdcSetAttrSurf(&g_stcMyGDC_DrvCTX, GDC_TEXTURE_SELECT, GDC_SELECT_PLAIN);		
}
Example #17
0
int wt_input(void)
{
	int quit = False;
	
	  double sin_facing, cos_facing;

	  intent = read_input_devices();

	  /* This block code is a hack to do acceleration and deceleration. */
	  if (fabs(vx) > fabs(intent->force_x)) {
	       if (vx < 0.0)
		    vx = MIN(vx + 0.1, intent->force_x);
	       else
		    vx = MAX(vx - 0.1, intent->force_x);
	  } else if (fabs(vx) < fabs(intent->force_x)) {
	       vx += intent->force_x / 5.0;
	       if (fabs(vx) > fabs(intent->force_x))
		    vx = intent->force_x;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  if (fabs(vy) > fabs(intent->force_y)) {
	       if (vy < 0.0)
		    vy = MIN(vy + 0.1, intent->force_y);
	       else
		    vy = MAX(vy - 0.1, intent->force_y);
	  } else if (fabs(vy) < fabs(intent->force_y)) {
	       vy += intent->force_y / 5.0;
	       if (fabs(vy) > fabs(intent->force_y))
		    vy = intent->force_y;
	  }
	  /* Angular deceleration here is weird and unrealistic, but it feels
	  **   right to me.
	  */
	  if (fabs(va) > fabs(intent->force_rotate))
	       va *= 0.6;
	  else if (fabs(va) < fabs(intent->force_rotate)) {
	       va += intent->force_rotate / 8.0;
	       if (fabs(va) > fabs(intent->force_rotate))
		    va = intent->force_rotate;
	  }
	  view->angle += FLOAT_TO_FIXED(0.3 * va);
	  sin_facing = sin(FIXED_TO_FLOAT(view->angle));
	  cos_facing = cos(FIXED_TO_FLOAT(view->angle));

	  view->x += FLOAT_TO_FIXED(0.8 * vx * cos_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vx * sin_facing);
	  view->x += FLOAT_TO_FIXED(0.8 * vy * -sin_facing);
	  view->y += FLOAT_TO_FIXED(0.8 * vy * cos_facing);
	  if (view->height > FIXED_ONE)
	       v -= FIXED_ONE / 16;
	  view->height += v;
	  if (view->height < FIXED_ONE) {
	       v = FIXED_ZERO;
	       view->height = FIXED_ONE;
	  }
	  while (intent->n_special--) {
	       if (intent->special[intent->n_special] == INTENT_END_GAME)
		    quit = True;
	       else
		    v = FIXED_ONE / 2;
	  }

   return quit;
}
Example #18
0
void MyGDC_DrawSector(Vector centrXY, float radius, float width, float angle_start, float angle_turn, GDC_COLOR32 color, uint8_t pos)
{
	float x = 0;
	float y = 0;
	float angle = 0;
	float angle_temp = 0;
	int i;
	
	XGdcSetAttrSurf(&g_stcMyGDC_DrvCTX, GDC_SHADE_MODE, GDC_SHADE_FLAT);
  	XGdcSetAttrSurf(&g_stcMyGDC_DrvCTX, GDC_DEPTH_TEST, GDC_DISABLE);
  	XGdcSetAttrSurf(&g_stcMyGDC_DrvCTX, GDC_BLEND_MODE,  GDC_BLEND_COPY);

  	
  	//  XGdcSetAttrLine(&DrawContext, GDC_ANTI_ALIAS, GDC_ENABLE);

	XGdcColor(&g_stcMyGDC_DrvCTX, color);
    x = radius;
    y = radius - width;
    /* Set the primitive type to be drawn */
    XGdcPrimType(&g_stcMyGDC_DrvCTX, GDC_TRIANGLE_STRIP);
    i = 2;
    //Режим рисования сектора 
    if (pos == 2)					//Против часовой
    {
    	angle_temp = angle_start;
    }
    else							//По часовой
    {
    	angle_temp = angle_turn;
    	angle_turn = angle_start;	
    }
    
    while (angle_temp < angle_turn)
    {
    /* Set the 2D coordinate and draw a designed object */
    	angle = PI * angle_temp / 180.0f;
    	if (i == 0)
    	{
    		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + x * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - x * (float)sin(angle)));
    		i = 1;
    	}
    	else if (i == 1)
    	{
    		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + y * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - y * (float)sin(angle)));
    		i = 0;    	
    	}
    	else
    	{
    		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + x * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - x * (float)sin(angle)));
    		XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + y * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - y * (float)sin(angle)));	
    		i = 0;
    	}
    	
    	if ((angle_turn - angle_temp) <= 2.5)
    	{
    		angle = PI * angle_turn / 180.0f;
    		if (i ==0)
    		{
    			XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + x * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - x * (float)sin(angle)));
    			XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + y * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - y * (float)sin(angle)));	
    		}
    		else
    		{
    			XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + y * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - y * (float)sin(angle)));	
    			XGdcDrawVertex2D(&g_stcMyGDC_DrvCTX, FLOAT_TO_FIXED(centrXY.x + x * (float)cos(angle)), FLOAT_TO_FIXED(centrXY.y - x * (float)sin(angle)));	
    		}
    	}
    	angle_temp += 2.5;
    }
    /* Stop drawing the primitive */
    XGdcPrimEnd(&g_stcMyGDC_DrvCTX);
    /* Transfer display list and make cancel the current used display list buffer */
	XGdcFlush(&g_stcMyGDC_DrvCTX);
	XGdcCancelDisplayList(&g_stcMyGDC_DrvCTX);
}
Example #19
0
GLbitfield GLAPIENTRY _mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16])
{
    GLfloat matrix[16];
    GLint tmp;
    GLenum currentMode = GL_FALSE;
    GLenum desiredMatrix = GL_FALSE;
    /* The bitfield returns 1 for each component that is invalid (i.e.
     * NaN or Inf).  In case of error, everything is invalid.
     */
    GLbitfield rv;
    register unsigned int i;
    unsigned int bit;

    /* This data structure defines the mapping between the current matrix
     * mode and the desired matrix identifier.
     */
    static struct {
        GLenum currentMode;
        GLenum desiredMatrix;
    } modes[] = {
        {GL_MODELVIEW, GL_MODELVIEW_MATRIX},
        {GL_PROJECTION, GL_PROJECTION_MATRIX},
        {GL_TEXTURE, GL_TEXTURE_MATRIX},
    };

    /* Call Mesa to get the current matrix in floating-point form.  First,
     * we have to figure out what the current matrix mode is.
     */
    _mesa_GetIntegerv(GL_MATRIX_MODE, &tmp);
    currentMode = (GLenum) tmp;

    /* The mode is either GL_FALSE, if for some reason we failed to query
     * the mode, or a given mode from the above table.  Search for the
     * returned mode to get the desired matrix; if we don't find it,
     * we can return immediately, as _mesa_GetInteger() will have
     * logged the necessary error already.
     */
    for (i = 0; i < sizeof(modes)/sizeof(modes[0]); i++) {
        if (modes[i].currentMode == currentMode) {
            desiredMatrix = modes[i].desiredMatrix;
            break;
        }
    }
    if (desiredMatrix == GL_FALSE) {
        /* Early error means all values are invalid. */
        return 0xffff;
    }

    /* Now pull the matrix itself. */
    _mesa_GetFloatv(desiredMatrix, matrix);

    rv = 0;
    for (i = 0, bit = 1; i < 16; i++, bit<<=1) {
        float normalizedFraction;
        int exp;

        switch (fpclassify(matrix[i])) {
            /* A "subnormal" or denormalized number is too small to be
             * represented in normal format; but despite that it's a
             * valid floating point number.  FP_ZERO and FP_NORMAL
             * are both valid as well.  We should be fine treating
             * these three cases as legitimate floating-point numbers.
             */
            case FP_SUBNORMAL:
            case FP_NORMAL:
            case FP_ZERO:
                normalizedFraction = (GLfloat)frexp(matrix[i], &exp);
                mantissa[i] = FLOAT_TO_FIXED(normalizedFraction);
                exponent[i] = (GLint) exp;
                break;

            /* If the entry is not-a-number or an infinity, then the
             * matrix component is invalid.  The invalid flag for
             * the component is already set; might as well set the
             * other return values to known values.  We'll set
             * distinct values so that a savvy end user could determine
             * whether the matrix component was a NaN or an infinity,
             * but this is more useful for debugging than anything else
             * since the standard doesn't specify any such magic
             * values to return.
             */
            case FP_NAN:
                mantissa[i] = INT_TO_FIXED(0);
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;

            case FP_INFINITE:
                /* Return +/- 1 based on whether it's a positive or
                 * negative infinity.
                 */
                if (matrix[i] > 0) {
                    mantissa[i] = INT_TO_FIXED(1);
                }
                else {
                    mantissa[i] = -INT_TO_FIXED(1);
                }
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;

            /* We should never get here; but here's a catching case
             * in case fpclassify() is returnings something unexpected.
             */
            default:
                mantissa[i] = INT_TO_FIXED(2);
                exponent[i] = (GLint) 0;
                rv |= bit;
                break;
        }

    } /* for each component */

    /* All done */
    return rv;
}
Example #20
0
int
checkwalls( World *w, View *v  )
{
  extern fixed view_height;
  Wall   *wall = (Wall *) w->walls->table, *mem_wall;
  double  x1, y1, tmp, min = 512.0;
  int i;

  x1 = FIXED_TO_FLOAT(v->x);
  y1 = FIXED_TO_FLOAT(v->y);

  if ( x1 == x && y1 == y )
    return DONT_INTERSECT;

  for (i = 0; i < TABLE_SIZE(w->walls); i++, wall++ ) {

    /* Check Distance */
    tmp = LineDistance( x1, y1, 
	    FIXED_TO_FLOAT(wall->vertex1->x ), 
	    FIXED_TO_FLOAT(wall->vertex1->y ), 
	    FIXED_TO_FLOAT(wall->vertex2->x ), 
	    FIXED_TO_FLOAT(wall->vertex2->y ) );

    if ( fabs(tmp) < fabs( min ) )
      {
	min      = tmp;
	mem_wall = wall; 
      }

  }

  /* is there any point in checking further. */
  if ( fabs( min ) < VECTOR_LEN  )  
    {
      /* start examine the wall */
      fixed ceiling, floor;

      /* Check the outher side of the object */
      if ( min > 0.0 )
	{
	  floor      = mem_wall->front->floor;
	  ceiling    = mem_wall->front->ceiling;
	}
      else
	{
	  floor      = mem_wall->back->floor;
	  ceiling    = mem_wall->back->ceiling;
	}

      /* if the stair is less than FIXED_ONE_QUARTER and the
	 head has goes free and there are enought room. */
      if ( FIXED_ONE_QUARTER >= (floor-v->height) && ( ceiling > v->height ) &&
	  ( MAN_SIZE <= (ceiling-floor) ) ) {
	if ( s_wall != mem_wall || ( min > 0.0 && side <= 0.0 ) ||
	    (min <= 0.0 && side > 0.0 ) )
	  {
	    if ( min < 0.0 )
	      view_height = mem_wall->front->floor+MAN_SIZE;
	    else
	      view_height = mem_wall->back->floor+MAN_SIZE;

	    s_wall       = mem_wall;
	  }
        }
      else
	/* am i running towards the wall? */
	if ( fabs( min ) < fabs( side ) )
	  {

	     s_wall = mem_wall;
	     slide_wall( &x, &y, x1, y1, side, min );

	     v->x   = FLOAT_TO_FIXED( x );
	     v->y   = FLOAT_TO_FIXED( y );

	     return 0;
	  }  
    }

  side = min;
  x    = x1;
  y    = y1;

  return 0;
}