Ejemplo n.º 1
0
bool doBind(jw_stream *stream, jw_dom_node *node)
{
    if (findBind(node))
    { 
        jw_event_bind(
            jw_stream_event(stream, JW_STREAM_EVENT_ELEMRECV), 
            onBindElementsReceived, NULL, NULL);

        jw_err err;
        jw_dom_node *sendNode = createBind();
        if (!jw_stream_send(stream, sendNode, &err))
        {
            jw_log_err(JW_LOG_ERROR, &err, "could not send bind dom");
            return false;
        }

        return true;
    }

    return false;
}
Ejemplo n.º 2
0
int interpret( int cmdArgc, char **cmdArgv )
{
    int i,r;
    long offset;

    /* initialize */
    argCountStack = newStack(32);	/* count of parameters */
    blockStack = newStack(32);		/* control block stack */
    lineStack = newStack(32);		/* current line number */
    sharedStack = newStack(128);	/* list of shared variables */
    currentScope = NULL;            	/* routine being defined */
    oldScopeP=0;			/* intial oldScope=0 */
    oldScope[oldScopeP]=currentScope;	/*oldScope0 =NULL */
    currentType = NULL;             	/* no type being defined */
    initKeywords();                 	/* builtin keywords */
    initBuiltins();                 	/* builtin functions */
    initConsts();                   	/* builtin constants */



    // if name of executable <> sdlBrt =autoboot
    r=strlen(cmdArgv[0]);

#ifdef UNIX
    if (strncasecmp(cmdArgv[0]+(r-6),"sdlbrt",6)!=0 ){
#else
    if (strnicmp(cmdArgv[0]+(r-10),"sdlbrt.exe",10)!=0 && strnicmp(cmdArgv[0]+(r-6),"sdlbrt",6)!=0 ){
#endif
	/* load the bindfile */
	offset=findBind( cmdArgv[0]);
	if (offset!=0){
	    if (!pushIncludeFile( cmdArgv[0], offset )){
		ePrintf( Init, "File not found\n");
		return -1;
	    }
	}
	else{
#ifdef UNIX
	    cmdArgv[cmdArgc]=(char *)malloc(strlen(cmdArgv[0])+16);
	    strcpy(cmdArgv[cmdArgc],cmdArgv[0]);
	    strcat(cmdArgv[cmdArgc],".sdlbas\0");
#else
	    cmdArgv[cmdArgc]=(char *)malloc(strlen(cmdArgv[0])+16);
	    strncpy(cmdArgv[cmdArgc],cmdArgv[0],strlen(cmdArgv[0])-4 );
	    strcat(cmdArgv[cmdArgc],".sdlbas\0");
#endif
	    if (!pushIncludeFile( cmdArgv[cmdArgc], 0 )){
		ePrintf( Init, "File not found\n");
		return -1;
	    }
	}

	/* shift args over by 1 */
        cmdArgc++;
        for ( i = cmdArgc; i > 0; i-- ) {
            cmdArgv[i] = cmdArgv[i-1];
        }
        /* first arg is "sdlbrt" */
        strcpy(cmdArgv[0] ,"sdlBrt" );
    }
    else{
	if(cmdArgc>1){
	    if (!fileExist(cmdArgv[1]) ){
		ePrintf( Init,"%s: file not found ....\n",cmdArgv[1]);
		exit(2);
	    }
	}
	/* load the file */
	if (!pushIncludeFile( cmdArgv[1], 0 )) {
	    ePrintf( Init, "File not found\n");
	    return -1;
	}
    }

    /* parse the file */
    yyparse();

    /* deferred? */
    if (deferredCode != NULL) {
        eval( deferredCode );
        freeNode( deferredCode );
    }
    return 0;
}

//____________________________________________________________________________________________________________________

int main(int argc, char **argv)
{
    int r,r1;
    char *curdir;
    int audio,socket,debug,defaults;


    /* default settings */
    audio=1;
    socket=1;
    defaults=1;
    debug=0;

    remove("sdlBasic.err");

    /* the command line param */
    r1=0;
    for (r=0;r<argc;r++){
	cmdArgv[r1]=eCopyString(argv[r]);
#ifdef UNIX
	if (strcasecmp(cmdArgv[r1],"--nodebug")==0)
	{
		printf("debugger disabled\n");
	    nodebug=1;
	}

	if (strcasecmp(cmdArgv[r1],"--nodefaults")==0)
	    defaults=0;
	if (strcasecmp(cmdArgv[r1],"--nosound")==0)
	    audio=0;
	if (strcasecmp(cmdArgv[r1],"--nosocket")==0)
	    socket=0;
	if (strcasecmp(cmdArgv[r1],"--debug")==0)
	    debug=1;
	if (strcasecmp(cmdArgv[r1],"--version")==0){
	    printf( "sdlBasic runtime(sdlBrt) release  %s\n", RELEASE);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--license")==0){
	    printf( "%s\n", LICENSE);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--copyright")==0){
	    printf(  "%s: see documentation for all contributors \n", COPYRIGHT);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--help")==0){
	    printf(  "sdlBasic runtime(sdlBrt) release  %s\n syntax: sdlBrt [option] foo.sdlbas \n Options:\n --nosound  : disable sound\n --nosocket : disable socket commands\n --nodefaults : disable creation of default display\n --debug    : start the program step by step\n --version  : software version\n --license  : license of software\n --copyright: credits of software\n --help     : this help\n",RELEASE );
	    exit(0);
	}
#else
	if (stricmp(cmdArgv[r1],"--nodefaults")==0)
	    defaults=0;
	if (stricmp(cmdArgv[r1],"--nosound")==0)
	    audio=0;
	if (stricmp(cmdArgv[r1],"--nosocket")==0)
	    socket=0;
	if (stricmp(cmdArgv[r1],"--debug")==0)
	    debug=1;
	if (stricmp(cmdArgv[r1],"--version")==0){
	    printf( "sdlBasic runtime(sdlBrt) release  %s\n", RELEASE);
	    exit(0);
	}
	if (stricmp(cmdArgv[r1],"--license")==0){
	    printf( "%s\n", LICENSE);
	    exit(0);
	}
	if (stricmp(cmdArgv[r1],"--copyright")==0){
	    printf(  "%s: see documentation for all contributors \n", COPYRIGHT);
	    exit(0);
	}
	if (strcasecmp(cmdArgv[r1],"--help")==0){
	    printf(  "sdlBasic runtime(sdlBrt) release  %s\n syntax: sdlBrt [option] foo.sdlbas \n Options:\n --nosound  : disable sound\n --nosocket : disable socket commands\n --nodefaults : disable creation of default display\n --debug    : start the program step by step\n --version  : software version\n --license  : license of software\n --copyright: credits of software\n --help     : this help\n",RELEASE );
	    exit(0);
	}
#endif
	if (cmdArgv[r1][0]!='-')
	    r1++;
	else
	    eFree(cmdArgv[r1]);
    }
    cmdArgc=r1;

    r=strlen(cmdArgv[0]);
#ifdef UNIX
    if (strncasecmp(cmdArgv[0]+(r-6),"sdlbrt",6)==0 ){
#else
    if (strnicmp(cmdArgv[0]+(r-10),"sdlbrt.exe",10)==0 || strnicmp(cmdArgv[0]+(r-6),"sdlbrt",6)==0 ){
#endif
	// if missing file name return a little message of the syntax
	if (cmdArgc <= 1) {
	   printf("sdlBasic runtime (sdlBrt) syntax: sdlBrt program.sdlbas\n");
	return 0;
	}
    }


    /*initializing SDLengine module */
    r=initialize(audio,socket,defaults);


/* gp2x Problem with allocation strings ??? */
#if defined(WIN32)
	fontPath=(char *)malloc(256);
	strcpy(fontPath,getenv("WINDIR"));
	strcat(fontPath,"\\fonts\\DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath=".\\DejaVuSans.ttf";
#else
	fontPath=(char *) malloc(256);
	strcpy(fontPath, font_prefix);
	strcat(fontPath,"/dejavu/DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath="./DejaVuSans.ttf";
#endif


/*
#if defined(WIN32)
	fontPath=(char *)malloc(256);
	strcpy(fontPath,getenv("WINDIR"));
	strcat(fontPath,"\\fonts\\DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath=".\\DejaVuSans.ttf";
#else
	fontPath=(char *) malloc(256);
	strcpy(fontPath,font_prefix);
	strcat(fontPath,"/dejavu/DejaVuSans.ttf\0");
	if (!fileExist(fontPath))fontPath="./DejaVuSans.ttf";
#endif
*/



    if (r != 0){
	ePrintf( Init,"error number %d. Please reinstall sdlBasic.\n",r);
	return -1;
    }
    /*initialize basic data function buffer */
    init_data();

    /* initialize lvldir */
    lvldir=0;

    /* initialize sistem memory bank */
    init_membank();

    if (cmdArgc<=1  ){
	cmdArgv[1]=cmdArgv[0];
    }
    /* autochange directory */
#ifdef UNIX
    if(cmdArgv[1][0]=='/'){
	r=strlen(cmdArgv[1]);
	curdir=(char *)malloc(r+1);
	while(cmdArgv[1][r]!='/')r--;
	strncpy(curdir,cmdArgv[1],r);
	chdir(curdir);
    }
#else
    if(cmdArgv[1][2]=='\\'){
	r=strlen(cmdArgv[1]);
	curdir=(char *)malloc(r+1);
	while(cmdArgv[1][r]!='\\')r--;
	strncpy(curdir,cmdArgv[1],r);
	chdir(curdir);
    }
#endif

    /* starting interpreter */
    r= interpret(cmdArgc, cmdArgv);
    /* terminate SDLengine */
    terminate();
    return r;
}
void
ColladaGeometry::handleBindMaterial(
    const GeoInfo &geoInfo, Geometry *geo, ColladaInstanceGeometry *colInstGeo)
{
    typedef ColladaInstanceGeometry::MaterialMap        MaterialMap;
    typedef ColladaInstanceGeometry::MaterialMapConstIt MaterialMapConstIt;

    const MaterialMap       &matMap        = colInstGeo->getMaterialMap();
    MaterialMapConstIt       mmIt          = matMap.find(geoInfo._matSymbol);
    Material                *material      = NULL;
    ColladaInstanceMaterial *colInstMat    = NULL;
    ColladaInstanceEffect   *colInstEffect = NULL;

    if(mmIt != matMap.end())
    {
        colInstMat = mmIt->second;

        OSG_ASSERT(colInstMat                  != NULL);
        OSG_ASSERT(colInstMat->getTargetElem() != NULL);

        ColladaInstInfoRefPtr colInstInfo =
            ColladaMaterial::ColladaMaterialInstInfo::create(this, colInstMat);

        material      =
            colInstMat->getTargetElem()->createInstance(colInstInfo);
        colInstEffect = colInstMat->getInstanceEffect();
    }
    else
    {
        SWARNING << "ColladaGeometry::handleBindMaterial: No material found "
                 << "for symbol [" << geoInfo._matSymbol << "]."
                 << std::endl;

        geo->setMaterial(getDefaultMaterial());
        return;
    }

    const BindStore       &bindStore       = colInstMat->getBindStore      ();
    const BindVertexStore &bindVertexStore = colInstMat->getBindVertexStore();

    PropStoreConstIt       psIt            = geoInfo._propStore .begin();
    PropStoreConstIt       psEnd           = geoInfo._propStore .end  ();
    IndexStoreConstIt      isIt            = geoInfo._indexStore.begin();
    IndexStoreConstIt      isEnd           = geoInfo._indexStore.end  ();

    // for every property in geoInfo we need to check if it gets remapped by a
    // <bind> or <bind_vertex_input>

    for(UInt32 i = 0; psIt != psEnd && isIt != isEnd; ++psIt, ++isIt, ++i)
    {
        if(psIt->_prop == NULL || *isIt == NULL)
            continue;

        bool   handledProperty  = false;
        UInt32 bindOffset       = 0;
        UInt32 bindVertexOffset = 0;

        const BindInfo       *bi  = findBind      (bindStore,
                                                   psIt->_semantic, bindOffset );
        const BindVertexInfo *bvi = findBindVertex(bindVertexStore,
                                                   psIt->_semantic, psIt->_set,
                                                   bindVertexOffset            );

        // there may be multiple consumers for a property, keep looping
        // until no more consumers are found
        while(bi != NULL || bvi != NULL)
        {
            UInt32 mappedProp = i;

            if(bi != NULL && bvi != NULL)
            {
                // is it a problem if there is a <bind> AND a
                // <bind_vertex_input> for the same property ??

                SWARNING << "ColladaGeometry::handleBindMaterial: "
                         << "Found <bind> AND <bind_vertex_input> for "
                         << "semantic [" << bi->semantic
                         << "] target/inSemantic [" << bi->target << "/"
                         << bvi->inSemantic << "] inSet [" << bvi->inSet
                         << "]" << std::endl;
            }

            if(bi != NULL)
            {
                if(colInstEffect->findTC(bi->target, mappedProp) == true)
                {
                    OSG_COLLADA_LOG(("ColladaGeometry::handleBindMaterial: "
                                     "Resolved <bind> semantic [%s] "
                                     "target [%s] to property [%d]\n",
                                     bi->semantic.c_str(), bi->target.c_str(),
                                     mappedProp));

                    geo->setProperty( psIt->_prop, mappedProp);
                    geo->setIndex   (*isIt,        mappedProp);

                    handledProperty = true;
                }
                else
                {
                    SWARNING << "ColladaGeometry::handleBindMaterial: "
                             << "Failed to resolve <bind> semantic ["
                             << bi->semantic << "] target [" << bi->target
                             << "]." << std::endl;
                }
            }
            else if(bvi != NULL)
            {
                if(colInstEffect->findTC(bvi->semantic, mappedProp) == true)
                {
                    OSG_COLLADA_LOG(("ColladaGeometry::handleBindMaterial: "
                                     "Resolved <bind_vertex_input> "
                                     "inSemantic [%s] inSet [%d] semantic [%s] "
                                     "to property [%d]\n",
                                     bvi->inSemantic.c_str(), bvi->inSet,
                                     bvi->semantic.c_str(), mappedProp));

                    geo->setProperty( psIt->_prop, mappedProp);
                    geo->setIndex   (*isIt,        mappedProp);
                    handledProperty = true;
                }
                else
                {
                    SWARNING << "ColladaGeometry::handleBindMaterial: "
                             << "Failed to resolve <bind_vertex_input> "
                             << "inSemantic ["
                             << bvi->inSemantic << "] inSet [" << bvi->inSet
                             << "] semantic [" << bvi->semantic
                             << "]." << std::endl;
                }
            }

            // find next consumers if any
            ++bindOffset;
            ++bindVertexOffset;

            bi  = findBind      (bindStore,       psIt->_semantic,
                                 bindOffset                       );
            bvi = findBindVertex(bindVertexStore, psIt->_semantic,
                                 psIt->_set,      bindVertexOffset);
        }

        // if the property is not remapped by <bind> or <bind_vertex_input>
        // we just put it at the location it received at read time
        // this is for properties that are not of interest to the material
        // directly (e.g. positions, normals)
        if(handledProperty == false)
        {
            OSG_COLLADA_LOG(("ColladaGeometry::handleBindMaterial: "
                             "Setting property [%d] (semantic [%s] set [%d]) "
                             "without <bind>/<bind_vertex_input> mapping.\n",
                             i, psIt->_semantic.c_str(), psIt->_set));

            geo->setProperty( psIt->_prop, i);
            geo->setIndex   (*isIt,        i);
        }
    }

    if(material != NULL)
    {
        geo->setMaterial(material);
    }
    else
    {
        SWARNING << "ColladaGeometry::handleBindMaterial: No material created "
                 << "for symbol [" << geoInfo._matSymbol << "]."
                 << std::endl;

        geo->setMaterial(getDefaultMaterial());
    }
}