Example #1
0
triChar* triAliasRegister( const triChar* name, const triChar* cmd )
{
	// Don't allow aliases with same name as commands or cvars
	if (triCmdFind( name ) || triCVarFind( name )) return("Name already used.");
	
	triCmdAlias* alias = triAliasFind( name );
	
	if (alias==0)
		alias = triMalloc(sizeof(triCmdAlias));
	else
	{
		triFree(alias->name);
		triFree(alias->cmd);
	}
	
	if (alias==0) return("Couldn't create alias.");
	
	alias->name = triMalloc(strlen(name)+1);
	strcpy( alias->name, name );
	alias->cmd = triMalloc(strlen(cmd)+1);
	strcpy( alias->cmd, cmd );
	
	alias->next = triAliases;
	triAliases = alias;
	
	return(0);
}
Example #2
0
// Create a new alias or change an existing one
triChar* cmd_alias()
{

	triCmdAlias* alias = triAliasFind( triCmdArgv(1) );
	
	if (alias==0)
	{
		if (triCmdArgc()<3)
			return("Alias not found.");
		return triAliasRegister( triCmdArgv(1), triCmdArgv(2) );
	}
	
	static triChar triReturnString[256];
	// Alias exists? We change it, or print the current commands
	if (triCmdArgc()<3)
	{
		snprintf( triReturnString, 256, "Current commands:\n\"%s\" \"%s\"", alias->name, alias->cmd );
		return triReturnString;
	}
	else
	{
		triFree( alias->cmd );
		alias->cmd = triMalloc(strlen(triCmdArgv(2))+1);
		strcpy( alias->cmd, triCmdArgv(2) );
	}
	
	return(0);
}
Example #3
0
void triCVarSet( const triChar* name, const triChar* value )
{
	triCVar* res = triCVarFind( name );
	
	if (res==0) return;
	
	if (res->flags&TRI_CVAR_RDONLY)
	{
		triConsolePrintf("CVar is read-only.\n");
		return;
	}
	
	res->fvalue = triatof( value );
	
	if (res->flags&TRI_CVAR_ALLOC)
		if (res->svalue) triFree(res->svalue);
	
	if (res->fvalue!=TRI_INVALID_VAL)
	{
		res->svalue = triMalloc( 33 );
		snprintf( res->svalue, 33, "%f", res->fvalue );
	}
	else
	{
		res->svalue = triMalloc( strlen(value)+1 );
		strcpy( res->svalue, value );
	}
	res->flags |= TRI_CVAR_ALLOC;
}
Example #4
0
triVoid triAt3Free()
{
	triAt3Stop();
	AT3_Loaded = 0;
	
	sceKernelDelayThread(50000);
	sceAudioChRelease(AT3_Channel);
	sceAudiocodecReleaseEDRAM(AT3_Codec_Buffer);
	sceKernelWaitThreadEnd(AT3_ThreadID, NULL);
	sceKernelTerminateDeleteThread(AT3_ThreadID);
	
	if(Tune)
		triFree(Tune);
}
Example #5
0
TRenum binaryDetachEncoder(TRStreamCodec* codec, TRStreamEncoder* encoder)
{
    TR_UNUSED(codec);
    
    if (encoder->handle)
    {
        BinaryEncoder* enc = (BinaryEncoder*)encoder->handle;
        {
            TRArray* values = triDictGetValues(enc->phrasebook);

            TR_FOR_EACH(Phrase*, p, values)
            {
                if (p)
                {
                    triFree(enc->state, p->data);
                    triFree(enc->state, p);
                }
            }
            triDestroyArray(values);
            triDestroyDict(enc->phrasebook);
        }
        triDestroyDict(enc->stringPool);
        triFree(triGetState(), enc);
    }
Example #6
0
static TRbool freeStringPoolEntry(TRDict* dict, TRDictNode* node, void* arg)
{
    BinaryEncoder* enc = (BinaryEncoder*)arg;
    TRuint          id = (TRuint)node->value;
    Phrase*     phrase = (Phrase*)triIntDictGet(enc->phrasebook, id);
    TR_UNUSED(dict);
    
    if (phrase)
    {
        /* Delete this entry and stop the iteration */
        triFree(enc->state, phrase->data);
        triStrDictRemove(enc->stringPool, node->key);
        TR_ASSERT(triIntDictRemove(enc->phrasebook, id));
        return TR_FALSE;
    }
    return TR_TRUE;
}
Example #7
0
triChar* cmd_exec()
{
	triChar* file = triCmdArgv(1);
	
	FILE* fp = fopen( file, "r" );
	if (fp==0) return("Error opening file.");
	
	fseek(fp,0,SEEK_END);
	triS32 sz = ftell(fp);
	fseek(fp,0,SEEK_SET);
	
	triChar* buffer = triMalloc(sz+1);
	if (buffer==0) return("Error allocating script buffer.");
	fread( buffer, 1, sz, fp );
	fclose(fp);
	
	triCmdExecute( buffer );
	triFree(buffer);
	return(0);
}
Example #8
0
void triCVarSetf( const triChar* name, const float value )
{
	triCVar* res = triCVarFind( name );
	
	if (res==0) return;
	
	if (res->flags&TRI_CVAR_RDONLY)
	{
		triConsolePrintf("CVar is read-only.\n");
		return;
	}
	
	res->fvalue = value;
	if (res->flags&TRI_CVAR_ALLOC)
		if (res->svalue) triFree(res->svalue);

	res->svalue = triMalloc( 33 );
	snprintf( res->svalue, 33, "%f", value );
	res->flags |= TRI_CVAR_ALLOC;
}
Example #9
0
// Execute an alias
triS32 triAliasCmd()
{
	triCmdAlias* alias = triAliasFind( triCmdArgv(0) );
	
	if (alias==0)	return(0);

	if (triCmdArgc()<2)
	{
		triCmdExecute( alias->cmd );
		return (1);
	}
	
	// Allow aliases to to be fed with arguments, making things like 'alias @ echo;@ "aliased echo output"' possible
	triS32 len = strlen(alias->cmd)+1;
	triS32 i = 1;
	for (;i<triCmdArgc();i++)
		len += strlen(triCmdArgv(i))+1;
	
	triChar* buffer = triMalloc(len);
	if (buffer==0)
		triCmdExecute( alias->cmd );
	else
	{
		sprintf( buffer, "%s ", alias->cmd );
		len = strlen(alias->cmd)+1;
		i = 1;
		for (;i<triCmdArgc();i++)
		{
			sprintf( buffer+len, "%s ", triCmdArgv(i) );
			len += strlen(triCmdArgv(i))+1;
		}
		buffer[len-1] = 0;
		triCmdExecute( buffer );
		triFree( buffer );
	}

	return(1);
}
Example #10
0
void triConsoleClose()
{
	// triFree all current command argument buffers
	if (triCmdCurArgs)
	{
		triFree(triCmdCurArgs);
		triCmdCurArgs = 0;
	}
	triS32 i = 0;
	for (;i<MAXARGS;i++)
		if (triCmdCurArgv[i])
		{
			triFree(triCmdCurArgv[i]);
			triCmdCurArgv[i] = 0;
		}

	// triFree all aliases
	triCmdAlias* list = triAliases;
	while (list!=0)
	{
		triCmdAlias* next = list->next;
		triFree(list->name);
		triFree(list->cmd);
		triFree(list);
		list = next;
	}

	// triFree all alloc'd CVars
	triCVar* var = triCVars;
	while (var!=0)
	{
		triCVar* next = var->next;
		if (var->flags&TRI_CVAR_ALLOC)
			triFree( var->svalue );
		var = next;
	}
}
Example #11
0
// Tokenize the string line until either a ;, \n or \0 is found and return pointer to that position
// ; and spaces may be included in single arguments by encapsulating in quotes ""
// spaces may be included in single arguments by encapsulating in round brackets ()
// This allows things like "cl_backcolor (1.0 0.7 0.1)"
triChar* triCmdTokenize( triChar* line )
{
	// triFree all current command argument buffers
	if (triCmdCurArgs)
	{
		triFree(triCmdCurArgs);
		triCmdCurArgs = 0;
	}
	triS32 i = 0;
	for (;i<MAXARGS;i++)
		if (triCmdCurArgv[i])
		{
			triFree(triCmdCurArgv[i]);
			triCmdCurArgv[i] = 0;
		}
	
	i = 0;
	// strip whitespaces
	while (*line && *line<=' ') line++;
	triCmdCurArgc = 0;
	triS32 quotes = 0;
	triS32 brackets = 0;
	triChar* args = 0;
	
	while (1)
	{
		if (line[i]=='"') quotes++;
		if (line[i]=='(') brackets++;
		if (line[i]==')') if (brackets) brackets--;
		if ((!(quotes&1) && !brackets && line[i]==' ') ||
		    (!(quotes&1) && line[i]==';') ||
		    (line[i]=='\n') ||
		    (line[i]==0) ||
		    (!(quotes&1) && line[i]=='"'))
		{
			// Save arguments start
			if (triCmdCurArgc==0)
				args = line;
			
			// Strip quotes
			if (line[0]=='"' || line[0]=='\'')
			{
				i--;
				line++;
			}
			triCmdCurArgv[triCmdCurArgc] = triMalloc(i+1);
			if (triCmdCurArgv[triCmdCurArgc]==0)
			{
				triLogError("ERROR ALLOCATING ARGV BUFFER!\n");
				return(0);
			}
			strncpy( triCmdCurArgv[triCmdCurArgc], line, i );
			triCmdCurArgv[triCmdCurArgc][i] = 0;
			if (triCmdCurArgv[triCmdCurArgc][i-1]=='"') triCmdCurArgv[triCmdCurArgc][i-1]=0;
			triCmdCurArgc++;
			if (line[i]==0 || line[i]=='\n')
				break;
			if (!(quotes&1) && line[i]==';')
				break;
			if (line[i]!=0) i++;
			line += i;
			i = 0;
			continue;
		}
		i++;
	}
	
	// Create args string	
	if (triCmdCurArgc>1)
	{
		triCmdCurArgs = triMalloc(&line[i]-args+1);
		strncpy( triCmdCurArgs, args, &line[i]-args );
	}
	return &line[i];
}
Example #12
0
triVoid triWavFree(triWav *theWav)
{
	if (triRefcountRelease( theWav )!=0) return;
	if(theWav != NULL)
		triFree(theWav);
}
Example #13
0
static TRenum readToken(TRStreamDecoder* decoder, TRint expectedToken, TRVariant* value)
{
    BinaryDecoder* dec = (BinaryDecoder*)decoder->handle;
    TRubyte token;
    TRint   param;
    
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
    /*triLogMessage(dec->state, "[binary] Looking for token 0x%x.", expectedToken);*/
#endif

    do
    {
        if (decoder->stream->ops->read(decoder->stream, (TRbyte*)&token, sizeof(TRubyte)) != 1)
        {
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
            triLogMessage(dec->state, "[binary] End of stream encountered.");
#endif                
            return TR_NOT_FOUND;
        }
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
        /*triLogMessage(dec->state, "[binary] Reading token 0x%x.", token);*/
#endif                
        param = readInt(decoder);
        
        switch (token)
        {
        case TOK_DEFINE:
            {
                TRint id       = readInt(decoder);
                TRint size     = readInt(decoder);
                TRbyte type    = readByte(decoder);
                TRuint length  = param - (2 * sizeof(TRint) + sizeof(TRbyte));
                Phrase* phrase;
                TRhandle objectNs = 0;
                const TRClass* objectClass = 0;

                /* If this is an array of objects, read the class and namespace information */
                if (type == TR_OBJECT)
                {
                    const TRbyte* className = (const TRbyte*)lookupPhrase(decoder, readInt(decoder));
                    objectNs = readPointer(decoder);
                    objectClass = triGetClassByName(dec->state, className);
                    length -= sizeof(TRint) + sizeof(TRhandle);
                    TR_ASSERT(objectClass);
                }
                
                TR_ASSERT(size >= length);
                TR_UNUSED(type);

#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                triLogMessage(dec->state, "[binary] DEFINE %p = %d bytes (%d bytes defined)", id, size, length);
#endif                
                
                /* Replace any previous phrase under this id */
                phrase = triIntDictGet(dec->phrasebook, id);
                
                /* Clear the existing entry if this is a zero-length phrase */
                if (phrase && phrase->data && size == 0)
                {
                    triFree(dec->state, phrase->data);
                    triFree(dec->state, phrase);
                    triIntDictSet(dec->phrasebook, id, 0);
                    /* No need to read the rest of the data since there is none */
                    continue;
                }
                
                if (!phrase)
                {
                    /* Allocate the new phrase */
                    phrase       = triMalloc(dec->state, sizeof(Phrase));
                    TR_ASSERT(phrase);
                    phrase->data = triMalloc(dec->state, size);
                    phrase->size = size;
                    
                    /* Terminate the data with zeros if needed */
                    triMemSet(&phrase->data[length], 0, size - length);
                }
                else
                {
                    /* Make sure the allocated phrase is big enough */
                    TR_ASSERT(phrase->size >= size);
                }
                
                if (!phrase->data)
                {
                    return TR_OUT_OF_MEMORY;
                }
                
                /* Read the phrase contents */
                if (decoder->stream->ops->read(decoder->stream, phrase->data, length) != length)
                {
                    return TR_INVALID_OPERATION;
                }

                /* For object arrays, translate the references to live objects */
                if (type == TR_OBJECT)
                {
                    int i;
                    TRhandle* array = (TRhandle*)phrase->data;

                    for (i = 0; i < length / sizeof(TRhandle); i++)
                    {
                        array[i] = triGetObject(dec->state, objectClass->id, objectNs, array[i], array[i]);
                    }
                }
                
                /* Store it in the phrasebook */
                triIntDictSet(dec->phrasebook, id, phrase);
            }
        break;
        case TOK_EVENT:
            {
                /* TODO: dictionary lookup */
                const TRbyte* name         = (const TRbyte*)lookupPhrase(decoder, readInt(decoder));
                dec->event->function       = triLookupFunction(dec->state, dec->event->api, name);
                dec->event->sequenceNumber = readInt(decoder);
                dec->event->timestamp      = readInt(decoder);
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                triLogMessage(dec->state, "[binary] EVENT %s (%p), seq = %d, ts = %d", name, dec->event->function,
                              dec->event->sequenceNumber, (TRint)dec->event->timestamp);
#endif
            }
        break;
        case TOK_VALUE:
            {
                TRint nameId   = readInt(decoder);
                TRbyte type    = readByte(decoder);

                TR_UNUSED(nameId);
                
                if (type & TR_PHRASE_BIT)
                {
                    value->p = lookupPhrase(decoder, readInt(decoder));
                }
                else
                {
                    switch (type)
                    {
                    case TR_BYTE:
                        value->b = readByte(decoder);
                    break;
                    case TR_SHORT:
                        value->s = readShort(decoder);
                    break;
                    case TR_INTEGER:
                        value->i = readInt(decoder);
                    break;
                    case TR_LONG:
                        value->l = readLong(decoder);
                    break;
                    case TR_FLOAT:
                        value->f = readFloat(decoder);
                    break;
                    case TR_DOUBLE:
                        value->d = readDouble(decoder);
                    break;
                    case TR_OBJECT:
                    {
                        const TRbyte* className = (const TRbyte*)lookupPhrase(decoder, readInt(decoder));
                        const TRhandle       ns = readPointer(decoder);
                        const TRhandle   handle = readPointer(decoder);
                        const TRClass*        c = triGetClassByName(dec->state, className);

                        if (!c)
                        {
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                            triLogMessage(dec->state, "[binary] Bad class name: %s", className);
#endif
                        }
                        else
                        {
                            /* Translate the reference to a live pointer */
                            value->o.cls    = c;
                            value->o.ns     = ns;
                            value->o.handle = triGetObject(dec->state, c->id, ns, handle, handle);
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                            triLogMessage(dec->state, "[binary] %s instance at %p mapped to %p", c->name, handle, value->o.handle);
#endif
                        }
                    }
                    break;
                    default:
                        TR_ASSERT(!"Corrupted binary stream: Bad value type.");
                    break;
                    }
                }
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                {
                    const TRbyte* name = (const TRbyte*)lookupPhrase(decoder, nameId);
                    triLogMessage(dec->state, "[binary] VALUE %s = %d (%f, %p)", name, value->i, value->f, value->p);
                }
#endif
            }
        break;
        case TOK_API:
            dec->event->api = param;
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
            triLogMessage(dec->state, "[binary] API %d", dec->event->api);
#endif
        break;
        case TOK_DURATION:
            dec->event->callTime = param;
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
            triLogMessage(dec->state, "[binary] DURATION %d", (TRint)dec->event->callTime);
#endif
        break;
        case TOK_BEGIN_OBJECT:
            {
                const TRbyte*    className = (const TRbyte*)lookupPhrase(decoder, readInt(decoder));
                TRhandle                ns = readPointer(decoder);
                TRhandle            handle = readPointer(decoder);
                const TRClass* objectClass = triGetClassByName(dec->state, className);

#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                triLogMessage(dec->state, "[binary] BEGIN_OBJECT %s", className);
#endif

                if (!objectClass)
                {
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
                    triLogMessage(dec->state, "[binary] Bad class name: %s", className);
#endif
                }
                else if (handle)
                {
                    triUnserializeObject(dec->state, objectClass->id, ns, handle);
                }
                /* Skip to the end of the object data */
                readToken(decoder, TOK_END_OBJECT, value);
            }
            break;
        case TOK_END_OBJECT:
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
            triLogMessage(dec->state, "[binary] END_OBJECT");
#endif
            break;
        default:
#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
            triLogMessage(dec->state, "[binary] Bad token: 0x%x", token);
#endif
            /* Skip it */
            while (!(token & TOK_TINY_TOKEN_BIT) && param--)
            {
                readByte(decoder);
            }
        break;
        }
    } while (token != expectedToken);

#if defined(TRACER_PLAYER_VERBOSE_LOGGING)
    /*triLogMessage(dec->state, "[binary] Found our token.");*/
#endif
    return TR_NO_ERROR;
}
Example #14
0
void triPlatformExit(TRState* state)
{
    UnixPlatformData* d = (UnixPlatformData*)state->platformData;
    pthread_mutex_destroy(&d->lock);
    triFree(state, state->platformData);
}
Example #15
0
void triPlatformExit(TRState* state)
{
    AndroidPlatformData* d = (AndroidPlatformData*)state->platformData;
    triFree(state, state->platformData);
}
Example #16
0
/* Simple thread */
int main(int argc, char **argv)
{
	SetupCallbacks();
	
	triLogInit();
	triInit( GU_PSM_8888, 1 );
	tri3dInit();
	triInputInit();
	
	// FIXME: This is not the right way to do as it will cause the particle manager to try and free pointers from inside the array
	partSys = triMalloc( sizeof(triParticleSystem)*4 );
	partEm = triMalloc( sizeof(triParticleEmitter)*4 );
	
	triS32 PsID0 = triParticleManagerLoadScript( "watersprinkle.txt" );
	
	triParticleSystemConstructor( &partSys[0] );
	triParticleSystemConstructor( &partSys[1] );
	triParticleSystemConstructor( &partSys[2] );
	partSys[0].render = renderParticle;
	partSys[2].renderMode = GU_TRIANGLES;
	partSys[2].blendMode = TRI_BLEND_MODE_ALPHA;
	//triParticleSystemConstructor( &partSys[3] );
	//partSys[3].renderMode = GU_TRIANGLES;

	triParticleEmitterConstructor( &partEm[0], TRI_EMITTER_SPRINKLE );
	triParticleEmitterConstructor( &partEm[1], TRI_EMITTER_FIRE );
	triParticleEmitterConstructor( &partEm[2], TRI_EMITTER_SMOKE );
	//triParticleEmitterConstructor( &partEm[3], TRI_EMITTER_EXPLOSION );
	partEm[0].pos.z = -10.0f;
	partEm[0].pos.x = -5.0f;
	partEm[0].velRand.w = 1.f;
	partEm[0].max = 64;
	partEm[1].pos.z = -10.0f;
	partEm[1].pos.x = 5.0f;
	partEm[1].vel.y += 1.5f;
	partEm[1].binding = 0.0f;		// particles are bound to the emitter
	partEm[1].loosen = 0.85f;		// particles loosen from the emitter with age
	partEm[1].life = 0.8f;
	partEm[1].growth = -0.7f/partEm[1].life;
	partEm[1].max = 512;
	partEm[1].rate = partEm[1].max/(partEm[1].life*1.2);
	partEm[1].lastpos = partEm[1].pos;
	partEm[1].vortexRange = 0.6f;
	partEm[1].vortexDirRand = 2.5f;
	partEm[2].pos.z -= 3.0;
	partEm[2].pos.x += 2.0;
	partEm[2].maxVortex = 16;
	partEm[2].rateVortex = 2;
	partEm[2].max = 256;
	partEm[2].life = 10.f;
	partEm[2].lifetime = 0;
	partEm[2].vortexDir = 0.f;
	partEm[2].vortexDirRand = 1.2f;
	partEm[2].vortexRange = 0.5f;
	partEm[2].rate = partEm[2].max/(partEm[2].life);
	//partEm[3].pos.z -= 5.0;
	
	partSys[1].textureID = triTextureLoad( "sprite.tga" );
	partSys[2].textureID = triTextureLoad( "smoke32.tga" );
	
	//triParticleManagerAdd( &partSys[0], &partEm[0] );
	triParticleManagerAdd( &partSys[1], &partEm[1] );
	triParticleManagerAdd( &partSys[2], &partEm[2] );
	//triParticleManagerAdd( &partSys[3], &partEm[3] );
	
	cam = triCameraCreate( 0.0f, 0.0f, -10.0f );

	// Do additional setup in immediate mode
	triBegin();
	tri3dPerspective( 45.0f );
	sceGuFrontFace(GU_CW);
	triClear( 0x330000 );
	triEnable(TRI_VBLANK);
	triEnd();
	//triSync();
	triTimer* frametimer = triTimerCreate();
	triTimer* demotimer = triTimerCreate();
	triS32 vblank = 0;
	
	#define SPEED 0.05f
	
	while (isrunning)
	{
		triBegin();
		tri3dClear( 1,0,1 );

		triInputUpdate ();

		if (triInputHeld (PSP_CTRL_UP))
		{
			triCameraRotate( cam, SCE_DEG_TO_RAD(3.2f), &triXAxis );
		}
		if (triInputHeld (PSP_CTRL_DOWN))
		{
			triCameraRotate( cam, SCE_DEG_TO_RAD(-3.2f), &triXAxis );
		}
		if (triInputHeld (PSP_CTRL_LEFT))
		{
			triCameraRotate( cam, SCE_DEG_TO_RAD(3.2f), &triYAxis );
		}
		if (triInputHeld (PSP_CTRL_RIGHT))
		{
			triCameraRotate( cam, SCE_DEG_TO_RAD(-3.2f), &triYAxis );
		}
		if (triInputHeld (PSP_CTRL_LTRIGGER))
		{
			triCameraMove( cam, 0.0f, 0.0f, SPEED );
		}
		if (triInputHeld (PSP_CTRL_RTRIGGER))
		{
			triCameraMove( cam, 0.0f, 0.0f, -SPEED );
		}
		if (triInputPressed (PSP_CTRL_SELECT))
		{
			vblank ^= 1;
			if (vblank)
				triEnable(TRI_VBLANK);
			else
				triDisable(TRI_VBLANK);
		}
		triCameraUpdateMatrix( cam );
		sceGumMatrixMode	(GU_MODEL);
		sceGumLoadIdentity	();
		triTimerUpdate(frametimer);
		triParticleManagerUpdateRender( cam, triTimerGetDeltaTime(frametimer) );
		
		partEm[1].pos.z = sinf( 30*triTimerPeekDeltaTime(demotimer)*SCE_PI/180.0f )*5.0f - 10.0f;
		partEm[1].pos.x = cosf( 30*triTimerPeekDeltaTime(demotimer)*SCE_PI/180.0f )*5.0f;
		
		triFontActivate(0);
		triFontPrintf( 0, 0, 0xFFFFFFFF, "CAM: dir <%.3f, %.3f, %.3f> pos <%.3f, %.3f, %.3f>\n", cam->dir.x, cam->dir.y, cam->dir.z, cam->pos.x, cam->pos.y, cam->pos.z);
		triFontPrintf( 0,10, 0xFFFFFFFF, "FPS: %.2f - CPU: %.0f GPU: %.0f\n", triFps(), triCPULoad(), triGPULoad());
		/*if (partEm[3].age>=partEm[3].lifetime && (rand()%100<5))
		{
			triParticleEmitterConstructor( &partEm[3], TRI_EMITTER_EXPLOSION );
			partEm[3].pos.x = 3.0f * (rand()%65537 - 32768)/32768.0f;
			partEm[3].pos.y = 3.0f * (rand()%65537 - 32768)/32768.0f;
			partEm[3].pos.z = -15.0f + 3.0f * (rand()%65537 - 32768)/32768.0f;
		}*/
		triEnd();
		triSwapbuffers();
	}


	triTextureUnload( partSys[1].textureID );
	triTextureUnload( partSys[2].textureID );
	triParticleManagerDestroy();
	triFree( partSys );
	triFree( partEm );
	
	triTimerFree(frametimer);
	triTimerFree(demotimer);
	triFree( cam );
	triInputShutdown();
	triClose();
	tri3dClose();
	triMemoryShutdown();
	sceKernelExitGame();

	return 0;
}
Example #17
0
triWav *triWavLoad(const triChar *filename)
{
	triLogPrint("triWav: Loading %s\r\n", filename);
	
	triUInt filelen;
	triU32 channels;
	triU32 samplerate;
	triU32 blocksize;
	triU32 bitpersample;
	triU32 datalength;
	triU32 samplecount;
	triChar *wavfile;
	triWav *theWav;
	
	if ((theWav=triRefcountRetain( filename ))!=0)
		return theWav;
	
	FILE *pFile = fopen(filename , "rb");
	
	if(pFile == NULL)
	{
		triLogError("triWav: File not found %s\r\n", filename);
		return NULL;
	}
	
	triS32 lSize;

	fseek(pFile , 0, SEEK_END);
	lSize = ftell(pFile);
	rewind(pFile);
	
	theWav = triMalloc(lSize + sizeof(triWav));
	triRefcountCreate( filename, theWav );
	wavfile = (triChar*)(theWav) + sizeof(triWav);
	
	filelen = fread(wavfile, 1, lSize, pFile);
	
	fclose(pFile);
	
	if (memcmp(wavfile, "RIFF", 4) != 0)
	{
		triLogError("triWav: format error not RIFF\r\n");
		triFree(theWav);
		return NULL;
	}
	
	/*if (memcmp(wavfile + 8, "WAVEfmt \x10\x00\x00\x00\x01\x00", 14) != 0)
	{
		triLogError("triWav: format error no WAVEfmt string\r\n");
		triFree(theWav);
		return NULL;
	}*/
	
	channels = *(triS16 *)(wavfile + 0x16);
	samplerate = *(triS32 *)(wavfile + 0x18);
	blocksize = *(triS16 *)(wavfile + 0x20);
	bitpersample = *(triS16 *)(wavfile + 0x22);

	triSInt i;
	
	for(i = 0; memcmp(wavfile + 0x24 + i, "data", 4) != 0; i++)
	{
		if (i == 0xFF)
		{
			triLogError("triWav: no data chunk found\r\n");
			triFree(theWav);
			return NULL;
		}
	}

	datalength = readU32(wavfile, 0x28+i); //*(triU32 *)(wavfile + 0x28 + i);
	
	if (datalength + 0x2c > filelen)
	{
		triLogError("triWav: buffer is supposed to be bigger than this\r\n");
		triFree(theWav);
		return NULL;
	}
	
	if (channels != 2 && channels != 1)
	{
		triLogError("triWav: not Mono or Stereo sample\r\n");
		triFree(theWav);
		return NULL;
	}
	
	if (samplerate > 100000 || samplerate < 2000)
	{
		triLogError("triWav: sample rate is wrong\r\n");
		triFree(theWav);
		return NULL;
	}
	
	/*if (blocksize != channels*2)
	{
		triLogError("triWav: BLOCKSIZE MISMATCH\r\n");
		triFree(theWav);
		return NULL;
	}*/
	
	/*if (bitpersample != 16 || bitpersample != 8)
	{
		triLogError("triWav: Bits Per Sample Error\r\n");
		triFree(theWav);
		return NULL;
	}*/

	if (channels == 2)
	{
		samplecount = datalength/(bitpersample/4);
	}
	else
	{
		samplecount = datalength/((bitpersample/4)/2);
	}
	
	if (samplecount <= 0)
	{
		triLogError("triWav: no samples\r\n");
		triFree(theWav);
		return NULL;
	}
	
	theWav->channels = channels;
	theWav->sampleRate = samplerate;
	theWav->sampleCount = samplecount;
	theWav->dataLength = datalength;
	theWav->data = wavfile + 0x2c + i;
	theWav->rateRatio = (samplerate*0x4000)/11025;
	theWav->playPtr = 0;
	theWav->playPtr_frac= 0;
	theWav->loop = 0;
	id++;
	theWav->id = id;
	theWav->bitPerSample = bitpersample;

	return theWav;
}