bool CVradStaticPropMgr::LoadStudioModelVtx( char const* pModelName, CUtlBuffer& buf )
{
	char tempFileName[256];

	char const* pFileName = ConstructFileName( pModelName );

	strcpy( tempFileName, pFileName );
	char* pTex = strrchr( tempFileName, '.' );
	assert( pTex );
	strcpy( pTex, ".dx80.vtx" );
	
	if (!LoadFile( tempFileName, buf ))
		return false;

	return true;
}
bool LoadStudioCollisionModel( char const* pModelName, CUtlBuffer& buf )
{
	char tmp[1024];
	SetExtension( tmp, pModelName, ".phy" );
	// No luck, gotta build it	
	// Construct the file name...
	char const* pFileName = ConstructFileName( tmp );
	if (!LoadFile( pFileName, buf ))
	{
		// this is not an error, the model simply has no PHY file
		return false;
	}

	phyheader_t *header = (phyheader_t *)buf.PeekGet();

	if ( header->size != sizeof(*header) || header->solidCount <= 0 )
		return false;

	return true;
}
bool LoadStudioModel( char const* pModelName, CUtlBuffer& buf )
{
	// No luck, gotta build it	
	// Construct the file name...
	char const* pFileName = ConstructFileName( pModelName );

	if (!LoadFile( pFileName, buf ))
	{
		Warning("Error! Unable to load model \"%s\"\n", pFileName );
		return false;
	}

	// Check that it's valid
	if (strncmp ((const char *) buf.PeekGet(), "IDST", 4) &&
		strncmp ((const char *) buf.PeekGet(), "IDSQ", 4))
	{
		Warning("Error! Invalid model file \"%s\"\n", pFileName );
		return false;
	}

	studiohdr_t* pHdr = (studiohdr_t*)buf.PeekGet();
	Studio_ConvertStudioHdrToNewVersion( pHdr );
	if (pHdr->version != STUDIO_VERSION)
	{
		Warning("Error! Invalid model version \"%s\"\n", pFileName );
		return false;
	}

	if (!IsStaticProp(pHdr))
	{
		Warning("Error! To use model \"%s\"\n"
			"      as a static prop, it must be compiled with $staticprop!\n", pFileName );
		return false;
	}

	return true;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    char *infile = NULL, fullName[FILENAME_MAX];
    int runFlags = 0;
    int terminalMode = FALSE;
    BoardConfig *config;
    char *port, *board;
    System sys;
    int i;

    /* get the environment settings */
    if (!(port = getenv("PORT")))
        port = DEF_PORT;
    if (!(board = getenv("BOARD")))
        board = DEF_BOARD;

    /* get the arguments */
    for(i = 1; i < argc; ++i) {

        /* handle switches */
        if(argv[i][0] == '-') {
            switch(argv[i][1]) {
            case 'b':   // select a target board
                if (argv[i][2])
                    board = &argv[i][2];
                else if (++i < argc)
                    board = argv[i];
                else
                    Usage();
                break;
            case 'd':
                runFlags |= RUN_PAUSE;
                break;
            case 'p':
                if(argv[i][2])
                    port = &argv[i][2];
                else if(++i < argc)
                    port = argv[i];
                else
                    Usage();
                if (isdigit((int)port[0])) {
#if defined(CYGWIN) || defined(WIN32)
                    static char buf[10];
                    sprintf(buf, "COM%d", atoi(port));
                    port = buf;
#endif
#ifdef LINUX
                    static char buf[10];
                    sprintf(buf, "/dev/ttyUSB%d", atoi(port));
                    port = buf;
#endif
                }
                break;
            case 's':
                runFlags |= RUN_STEP;
                break;
            case 't':
                terminalMode = TRUE;
                break;
            default:
                Usage();
                break;
            }
        }

        /* handle the input filename */
        else {
            if (infile)
                Usage();
            infile = argv[i];
        }
    }
    
    sys.ops = &myOps;
    ParseConfigurationFile(&sys, "xbasic.cfg");

    /* make sure an input file was specified */
    if (!infile)
        Usage();
    ConstructFileName(infile, fullName, ".bai");

    /* setup for the selected board */
    if (!(config = GetBoardConfig(board)))
        Usage();

    /* initialize the serial port */
    if (!InitPort(port)) {
        fprintf(stderr, "error: opening serial port\n");
        return 1;
    }

    /* load the compiled image */
    if (!LoadImage(&sys, config, port, fullName)) {
        fprintf(stderr, "error: load failed\n");
        return 1;
    }
    
    /* run the loaded image */
    if (!RunLoadedProgram(runFlags)) {
        fprintf(stderr, "error: run failed\n");
        return 1;
    }

    /* enter terminal mode if requested */
    if (terminalMode)
        TerminalMode();
    
    return 0;
}