Пример #1
0
int conLoadObj( const char* args, void* reposToSelected)
{
  char model[256];
  char className[256];
  char dir[256];
  char file[256];
  int i;

  memset( dir, 0, 256);
  engObj_s* obj;

  if( splitVals(' ',args, model, className) )
  {
    i=charrpos(model,'/')+1;

    memcpy(dir, model, i);


    strcpy(file, model+i);

    eoPrint("debug: "TXTCOL_CYAN"%s", args);
    eoPrint("ModelDir: "TXTCOL_CYAN"%s "TXTCOL_WHITE" ModelFile: "TXTCOL_CYAN"%s "TXTCOL_WHITE"ClassName: "TXTCOL_GREEN"%s", dir,file,className);
    obj = eoObjCreate( ENGOBJ_MODEL );

    obj->model = eoModelLoad(dir, file);
    if( obj->model )
    {
      obj->className = malloc( sizeof(char)* strlen(className)+1 );
      strcpy( obj->className, className );
      obj->pos = eoCamPosGet();
      editorAddObj(obj);

      if( reposToSelected )
      {
        obj->pos = selectedObj->pos;
      }

    } else {
      eoPrint("File not found.");
      eoObjDel(obj);
    }

  } else {
    eoPrint("Usage: "TXTCOL_RED"add "TXTCOL_CYAN"path/to/modelfile.obj "TXTCOL_GREEN"className");
    eoPrint("Ex: "TXTCOL_RED"add "TXTCOL_CYAN"data/models/coin.obj "TXTCOL_GREEN"goldenCoin");
  }


  return( CON_CALLBACK_HIDE_RETURN_VALUE );
}
Пример #2
0
int packAdd(const char* packDir, int isDLC)
{
  char* buf = malloc(sizeof(char)*2048);
  char* buf2= malloc(sizeof(char)*1024);
  char* val = malloc(sizeof(char)*1024);
  char* set = malloc(sizeof(char)*1024);

  //This block is for playlists
  list_t* playList=0;
  listItem* li=0;
  playListItem* pli=0;
  int i; //Counter

  FILE* f=0;
  packInfoType* ti = malloc(sizeof(packInfoType));
  ti->lives=3; //Default 3 lives, if pack do not define another number.
  ti->isDLC=isDLC;

  //Any levels? (Packs are invalid without a levels folder and atleast one level)
  sprintf(buf, "%s/levels/level000.wzp", packDir);

  //Initialize list for playlist
  playList = listInit(_freePlaylistItem);

  //Open packs/packname/info.ini
  sprintf(buf, "%s/info.ini", packDir);
  f = android_fopen(buf, "r");
  if(f)
  {
    while( fgets(buf, 128, f) )
    {
      stripNewLine(buf);
      if(splitVals('=',buf,set,val))
      {
        if(strcmp("author", set)==0)
        {
          ti->author = malloc( sizeof(char)*(strlen(val)+1+3) );
          sprintf(ti->author, "By %s", val);
        } else
        if(strcmp("packname", set)==0)
        {
          ti->name = malloc( sizeof(char)*(strlen(val)+1) );
          strcpy(ti->name,val);
        } else
        if(strcmp("comment", set)==0)
        {
          ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) );
          sprintf(ti->comment, "-%s", val);
        } else
        if(strcmp("mus", set)==0)
        {
          //mus=00,song
          if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) )
          {
              //val= from buf2=to set=song name
              pli = malloc( sizeof( playListItem ) );
              pli->from=atoi(val);
              pli->to=atoi(buf2);
              pli->song=malloc(sizeof(char)*strlen(set)+1);
              strcpy( pli->song, set );
              listAppendData( playList, (void*)pli );
          } else {
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "   Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n");
          }
        } else
        if(strcmp("lives", set)==0)
        {
          ti->lives = atoi(val);
        }
      } //Found =
    } //reading file

    //Close the info file.
    fclose(f);
  } else {
    //Fall back if no file was found.
    SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf);
    ti->author = malloc( sizeof(char)* 20 );
    strcpy(ti->author, "info.ini not found");
    ti->comment=ti->author;
    ti->name = malloc( sizeof(char)*(strlen(packDir)+1) );
    strcpy(ti->name, packDir);
  }


  //Set path
  ti->path = malloc( sizeof(char)*(strlen(packDir)+1) );
  strcpy(ti->path,packDir);

  //Set pack icon
  sprintf(buf, "%s/icon.png", packDir);
  ti->icon = loadImg(buf);
  if(!ti->icon)
  {
    ti->icon = loadImg( "data/noicon.png" );
  }

  //Check if pack have a "finished" icon.
  sprintf(buf, "%s/finished.png", packDir);

  //Set ps.cp before entering makeLevelist, it makes use of packGetFile
  ps.cp = ti;

  //Add levels.
  ti->levels=0;
  ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/

  //set number of levels in pack
  ti->numLevels = ti->levels->count - 1  ; //The last level does not count (because it is just a "completed" screen).


  //Add to list of packages
  listAppendData( ps.packs, (void*)ti );

  //Increase number of available packages
  ps.numPacks++;

  //Put playlist songs into levelfiles.
  li=&playList->begin;
  while( LISTFWD(playList,li) )
  {
    pli=(playListItem*)li->data;

    for(i=0; i<ti->numLevels;i++)
    {
      if(i >= pli->from && i <= pli->to)
      {
        levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 );
        strcpy(levelInfo(i)->musicFile, pli->song);
      }
    }
  }

  //Clear playlist data
  listFree( playList );

  free(buf);
  free(buf2);
  free(val);
  free(set);

  return(ps.numPacks-1);
}
Пример #3
0
void loadSettings()
{
  char* buf = malloc(sizeof(char)*2048);
  char* set = malloc(sizeof(char)*1024);
  char* val = malloc(sizeof(char)*1024);

  settings.bgPos.x = HSCREENW-160;
  settings.bgPos.y = HSCREENH-120;

  //Set defaults
  settings.soundVol=64;
  settings.musicVol=72;
  settings.wizClock=450;
  settings.showFps=0;
  settings.arcadeMode=0;
  settings.particles=1;
  settings.userMusic=0;
  settings.disableMusic=0;
  settings.wizVol=52;
  settings.glWidth=-1;
  settings.glHeight=-1;
  settings.glEnable=1;
  settings.glFilter=0;
  settings.fullScreen=0;
  settings.showWeb=0;

  //Not written to file
  settings.rift=0;
  settings.scaleFactor=1.0;
  settings.session=0;
  settings.solvedWorldWide=0;
  settings.firstRun=1;
  settings.uploadStats=-1;
  settings.online=0; //This is what will be checked for in the rest of the code
                     //regardless of "uploadStats", it will only be 1 if
                     //"uploadStats" is 1, because the check that can set it 1 is only
                     //executed if it's enabled.


  //Free ptrs.
  if(settings.packDir)
    free(settings.packDir);

  if(settings.playerName)
    free(settings.playerName);

  settings.packDir = malloc(sizeof(char)*(strlen(DATADIR"packs/000_wizznic")+1) );
  strcpy(settings.packDir, DATADIR"packs/000_wizznic");

  settings.playerName = malloc(sizeof(char)*11 );
  strcpy(settings.playerName, "player");

  settings.musicDir = cwd( NULL, 0 );
  if( !settings.musicDir )
    printf("Out of memory, will crash soon.\n");

  sprintf( buf, "%s/settings.ini", getConfigDir() );

  FILE *f = fopen(buf, "r");
  if(f)
  {
    while( fgets(buf, 128, f) )
    {
      stripNewLine(buf);

      if(splitVals('=',buf, set, val))
      {
        if( strcmp("soundvol", set)==0 )
        {
          settings.soundVol = atoi(val);
        } else
        if( strcmp("musicvol", set)==0 )
        {
          settings.musicVol = atoi(val);
        } else
        if( strcmp("wizclock", set)==0 )
        {
          settings.wizClock = atoi(val);
        } else
        if( strcmp("wizvolume", set)==0 )
        {
          settings.wizVol = atoi(val);
        } else
        if( strcmp("showfps", set)==0 )
        {
          settings.showFps = atoi(val);
        } else
        if( strcmp("arcademode", set)==0 )
        {
          settings.arcadeMode = atoi(val);
        } else
        if( strcmp("particles", set)==0 )
        {
          settings.particles = atoi(val);
        } else
        if( strcmp("packdir", set)==0 )
        {
          free(settings.packDir);
          settings.packDir = malloc(sizeof(char)*(strlen(val)+1) );
          strcpy(settings.packDir,val);
        } else
        if( strcmp("playername", set)==0 )
        {
          if( strlen(set) < 11 )
          {
            strcpy(settings.playerName,val);
          } else {
            printf("Error, name: '%s' too long, max length is 10.\n",set);
          }
        } else
        if( strcmp("musicdir", set)==0 )
        {
          //We check if it starts with . it now has to be a full path.
          if( val[0] != '.' )
          {
            free(settings.musicDir);
            settings.musicDir = malloc(sizeof(char)*(strlen(val)+1) );
            strcpy(settings.musicDir, val);
          } else {
            printf("Using '%s' as music directory instead of '%s'.\n", settings.musicDir, val);
          }
        } else
        if( strcmp("usermusic", set)==0 )
        {
          settings.userMusic=atoi(val);
        } else
        if( strcmp("disablemusic",set)==0 )
        {
          settings.disableMusic=atoi(val);
        } else
        if( strcmp("allowonline",set)==0 )
        {
          //Only if the option is in the file, are we sure they had the choice.
          settings.uploadStats=atoi(val);
          if( settings.uploadStats!=-1 )
          {
            settings.firstRun=0;
          }
        } else
        if( strcmp("glwidth",set)==0 )
        {
          settings.glWidth=atoi(val);
        } else
        if( strcmp("glheight",set)==0 )
        {
          settings.glHeight=atoi(val);
        } else
        if( strcmp("glenable",set)==0 )
        {
          settings.glEnable=atoi(val);
        } else
        if( strcmp("glfilter",set)==0 )
        {
          settings.glFilter=atoi(val);
        } else
        if( strcmp("fullscreen",set)==0 )
        {
          settings.fullScreen=atoi(val);
        } else
        if( strcmp("showweb",set)==0 )
        {
          settings.showWeb=atoi(val);
        }


      }
    }
    //Close file
    fclose( f );
  }

  //Free the textbuffers
  free(buf);
  free(set);
  free(val);
}
Пример #4
0
//Returns pointr to levelInfo_t if level successfully opened, returns nullptr if not.
levelInfo_t* mkLevelInfo(const char* fileName)
{
  int gotData=0; //If this is still 0 after the loop, level has no [data]
  FILE *f;
  levelInfo_t* tl; //Temp levelInfo.
  char* buf = malloc(sizeof(char)*256); //Read line buffer
  char* set = malloc(sizeof(char)*128); //Buffer for storing setting
  char* val = malloc(sizeof(char)*128); //Buffer for storing value

  tl=0; //Return null ptr if no file is found (malloc won't get called then)
  f = fopen(fileName, "r");
  if(f)
  {
    //Allocate memory for level info.
    tl=malloc(sizeof(levelInfo_t));

    //Set everything 0.
    memset(tl, 0, sizeof(levelInfo_t));

    //Level file name
    tl->file=malloc( sizeof(char)*( strlen(fileName)+1 ) );
    strcpy(tl->file, fileName);

    //preview file name
    sprintf( buf, "%s.png", fileName);
    tl->imgFile=malloc( sizeof(char)*( strlen(buf)+1 ) );
    strcpy(tl->imgFile, buf);

    //default char map
    strcpy( buf, "charmap" );
    tl->fontName=malloc( sizeof(char)*( strlen(buf)+1) );
    strcpy( tl->fontName, buf );

    //Default cursor
    strcpy( buf, "cursor.png" );
    tl->cursorFile=malloc( sizeof(char)*(strlen(buf)+1) );
    strcpy( tl->cursorFile, buf );

    //start/stop images
    tl->startImg=0;
    tl->stopImg=0;

    //Default brick die time
    tl->brick_die_ticks=500;

    tl->brickDieParticles=1;

    //Initialize teleList
    tl->teleList = initList();

    //Initialize switchlist
    tl->switchList = initList();

    //Loop through file
    while(fgets(buf, 255, f))
    {
      //We don't want \r or \n in the end of the string.
      stripNewLine(buf);
      //Stop reading when we reach [data]
      if(strcmp(buf,"[data]")==0)
      {
        gotData=1;
        break;
      } else {
        //Try and split string at =
        if(splitVals('=',buf, set,val) )
        {
          //Check what we got.
          //Time left?
          if(strcmp("seconds",set)==0)
          {
            tl->time=atoi(val);
          } else
          if(strcmp("bgfile",set)==0)
          {
            tl->bgFile=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->bgFile, val);
          } else
          if(strcmp("tilebase",set)==0)
          {
            tl->tileBase=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->tileBase, val);
          } else
          if(strcmp("explbase",set)==0)
          {
            tl->explBase=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->explBase, val);
          } else
          if(strcmp("wallbase",set)==0)
          {
            tl->wallBase=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->wallBase, val);
          } else
          if(strcmp("author",set)==0)
          {
            tl->author=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->author, val);
          } else
          if(strcmp("levelname",set)==0)
          {
            tl->levelName=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->levelName, val);
          } else
          if(strcmp("sounddir",set)==0)
          {
            tl->soundDir=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->soundDir, val);
          } else
          if(strcmp("charbase",set)==0)
          {
            free(tl->fontName);
            tl->fontName=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->fontName, val);
          } else
          if(strcmp("cursorfile",set)==0)
          {
            free( tl->cursorFile );
            tl->cursorFile=malloc( sizeof(char)*( strlen(val)+1 ) );
            strcpy(tl->cursorFile, val);
          } else
          if(strcmp("startimage",set)==0)
          {
            //Ignore none keyword for start image
            if( strcmp( "none", val) != 0)
            {
              tl->startImg=malloc( sizeof(char)*( strlen(val)+1 ) );
              strcpy(tl->startImg, val);
            }
          } else
          if(strcmp("stopimage", set)==0)
          {
            //Ignore none keyword for stop image
            if( strcmp( "none", val) != 0)
            {
              tl->stopImg=malloc( sizeof(char)*( strlen(val)+1 ) );
              strcpy(tl->stopImg, val);
            }
          } else
          if(strcmp("brickdietime", set)==0)
          {
            tl->brick_die_ticks=atoi(val);
          } else
          if(strcmp("brickdieparticles", set)==0)
          {
            tl->brickDieParticles=atoi(val);
          } else
          if(strcmp("teleport", set)==0)
          {
            teleAddFromString(tl->teleList, val);
          } else
          if(strcmp("switch", set)==0)
          {
            //Yes, it's the same format, how neat.
            teleAddFromString(tl->switchList, val);
          }
        } //Got a = in the line
      } //Not [data]
    } //Reading file
    //Close file
    fclose(f);
  }

  if(!gotData)
  {
    //The reason we don't tell that there's no [data] section is because this
    //function is also used to check for the existance of levels, so it'd always
    //Return "no [data] found for the levelfile name just after the last level in a pack.
    free(tl);
    tl=0;
  }


  free(set);
  free(val);
  free(buf);
  set=0;
  val=0;
  buf=0;

  //Return ptr, is null if file couldnt be opened.
  return(tl);

}
Пример #5
0
void loadSettings()
{
  char* buf = malloc(sizeof(char)*2048);
  char* set = malloc(sizeof(char)*1024);
  char* val = malloc(sizeof(char)*1024);

  settings.bgPos.x = HSCREENW-160;
  settings.bgPos.y = HSCREENH-120;

  //Set defaults
  settings.soundVol=64;
  settings.musicVol=72;
  settings.wizClock=533;
  settings.showFps=0;
  settings.arcadeMode=0;
  settings.particles=1;
  settings.userMusic=0;
  settings.disableMusic=0;
  settings.wizVol=52;
  settings.glWidth=-1;
  settings.glHeight=-1;
  settings.glEnable=1;
  settings.glFilter=0;

  //Not written to file
  settings.scaleFactor=1.0;
  settings.session=0;
  settings.solvedWorldWide=0;
  settings.firstRun=1;
  settings.uploadStats=0;
  settings.online=0; //This is what will be checked for in the rest of the code
                     //regardless of "uploadStats", it will only be 1 if
                     //"uploadStats" is 1, because the check that can set it 1 is only
                     //éxecuted if it's enabled.


  //Free ptrs.
  if(settings.packDir)
    free(settings.packDir);

  if(settings.playerName)
    free(settings.playerName);

  settings.packDir = malloc(sizeof(char)*(strlen("packs/wizznic")+1) );
  strcpy(settings.packDir, "packs/wizznic");

  settings.playerName = malloc(sizeof(char)*11 );
  strcpy(settings.playerName, "player");

  settings.musicDir = (char*)malloc(sizeof(char)*(strlen(".")+1) );
  strcpy(settings.musicDir, ".");

  sprintf( buf, "%s/settings.ini", getConfigDir() );
  FILE *f = fopen(buf, "r");
  if(f)
  {
    while( fgets(buf, 128, f) )
    {
      stripNewLine(buf);

      if(splitVals('=',buf, set, val))
      {
        if( strcmp("soundvol", set)==0 )
        {
          settings.soundVol = atoi(val);
        } else
        if( strcmp("musicvol", set)==0 )
        {
          settings.musicVol = atoi(val);
        } else
        if( strcmp("wizclock", set)==0 )
        {
          settings.wizClock = atoi(val);
        } else
        if( strcmp("wizvolume", set)==0 )
        {
          settings.wizVol = atoi(val);
        } else
        if( strcmp("showfps", set)==0 )
        {
          settings.showFps = atoi(val);
        } else
        if( strcmp("arcademode", set)==0 )
        {
          settings.arcadeMode = atoi(val);
        } else
        if( strcmp("particles", set)==0 )
        {
          settings.particles = atoi(val);
        } else
        if( strcmp("packdir", set)==0 )
        {
          free(settings.packDir);
          settings.packDir = malloc(sizeof(char)*(strlen(val)+1) );
          strcpy(settings.packDir,val);
        } else
        if( strcmp("playername", set)==0 )
        {
          free(settings.playerName);
          settings.playerName = malloc(sizeof(char)*(strlen(val)+1) );
          strcpy(settings.playerName,val);
          settings.playerName[10] = '\0'; //In case user edits file and make a longer than 10 chars name.
        } else
        if( strcmp("musicdir", set)==0 )
        {
          free(settings.musicDir);
          settings.musicDir = malloc(sizeof(char)*(strlen(val)+1) );
          strcpy(settings.musicDir, val);
        } else
        if( strcmp("usermusic", set)==0 )
        {
          settings.userMusic=atoi(val);
        } else
        if( strcmp("disablemusic",set)==0 )
        {
          settings.disableMusic=atoi(val);
        } else
        if( strcmp("uploadstats",set)==0 )
        {
          //Only if the option is in the file, are we sure they had the choice.
          settings.firstRun=0;
          settings.uploadStats=atoi(val);
        } else
        if( strcmp("glwidth",set)==0 )
        {
          settings.glWidth=atoi(val);
        } else
        if( strcmp("glheight",set)==0 )
        {
          settings.glHeight=atoi(val);
        } else
        if( strcmp("glenable",set)==0 )
        {
          settings.glEnable=atoi(val);
        } else
        if( strcmp("glfilter",set)==0 )
        {
          settings.glFilter=atoi(val);
        }

      }
    }
    //Close file
    fclose( f );
  }

  //Free the textbuffers
  free(buf);
  free(set);
  free(val);
}
Пример #6
0
listItem* eoLoadScene( const char* fileName, engObjInitFunc objInit )
{
  char line[2048];
  char set[1024];
  char val[1024];
  listItem* objs = NULL;
  engObj_s* obj = NULL;
  int i=0;
  char **vec;

  FILE* fp = fopen( fileName, "r" );
  //Open file
  if( fp )
  {
    objs = initList();
    eoPrint("Loading %s ...", fileName);
    while( fgets(line, 1023, fp) )
    {
      stripNewLine(line);

      if( strlen(line) > 2 )
      {
        if( strcmp(line,"[model]") == 0 )
        {
          obj = eoObjCreate( ENGOBJ_MODEL );
        } else if( strcmp(line,"[sprite]" ) == 0 )
        {
          eoPrint("Created Sprite entity.");
          obj = eoObjCreate( ENGOBJ_SPRITE );
        } else if( strcmp(line,"[emitter]") == 0 )
        {
          eoPrint("Created Emitter entity.");
          obj = eoObjCreate( ENGOBJ_PAREMIT );
        } else if( strcmp(line, "[sound]" ) == 0 )
        {
          eoPrint("Created Sound entity.");
          obj = eoObjCreate( ENGOBJ_SOUND );
        } else if( strcmp(line,"[end]") == 0 )
        {
          if( objInit )
          {
            objInit(obj);
          }
          listAddData( objs, (void*)obj );
        } else {
          if( splitVals( '=', line, set, val ) )
          {
            if( strcmp(set,"class") == 0 )
            {
              obj->className = malloc(strlen(val)+1);
              strcpy(obj->className,val);
            } else if( strcmp(set,"rot") == 0 )
            {
              vec = explode(',', val, 3);
              obj->rot.x=atof(vec[0]);
              obj->rot.y=atof(vec[1]);
              obj->rot.z=atof(vec[2]);

              free(vec[0]);
              free(vec[1]);
              free(vec[2]);
              free(vec);
            } else if( strcmp(set,"pos") == 0 )
            {
              vec = explode(',', val, 3);
              obj->pos.x=atof(vec[0]);
              obj->pos.y=atof(vec[1]);
              obj->pos.z=atof(vec[2]);

              free(vec[0]);
              free(vec[1]);
              free(vec[2]);
              free(vec);
            } else if( strcmp(set,"file") == 0 )
            {
              //Todo: Cache models
              i=charrpos(val,'/')+1;

              strcpy(set, val+i);
              val[i]=0;
              obj->model = eoModelLoad( val, set );

            } else {
              eoPrint("Unknown data: %s ('%s' and '%s')",line,set,val);
            }

          } else
            eoPrint("Invalid text: %s",line);
        }
    }
    //  free(objName);
    }

  } else {
    eoPrint("Error, could not open file %s for reading...", fileName);
  }

  return(objs);
}