예제 #1
0
파일: langsel.c 프로젝트: gradha/multitet
static char *_get_lang_name_from_file(const char *file_name, char *lang_code)
{
   char *line;
   char buf1[256], buf2[256];

   ASSERT(file_name);
   ASSERT(*file_name);
   ASSERT(lang_code);

   lang_code[0] = file_name[0];
   lang_code[1] = file_name[1];
   lang_code[2] = 0;

   get_executable_name(buf1, sizeof(buf1));
   replace_filename(buf2, buf1, file_name, sizeof(buf2));

   push_config_state();
   set_config_file(buf2);

   line = m_strdup(get_config_string(0, "language_name", ""));
   
   pop_config_state();

   if (*line)
      return line;

   free(line);
   return 0;
}
예제 #2
0
/* fs_elist_proc:
  *  Dialog procedure for the file selector disk list.
  */
static int fs_elist_proc(int msg, DIALOG *d, int c)
{
    int ret;
    int sel = d->d1;
    char *s, *tok;
    char tmp[80], ext[80];
    static char ext_tokens[] = " ,;";
    
    s = (char *) file_selector[FS_EDIT].dp;
    
    if(msg == MSG_START)
    {
        d->d2 = 0;
    }
    
    ret = jwin_droplist_proc(msg, d, c);
    
    if((sel != d->d1) || (ret & D_CLOSE))
    {
        // change the extension(s)
        fext = fext_list[d->d1].ext;
//    if (fext)// && ugetc(fext))
        {
            parse_extension_string(fext);
        }
        
        // check whether the extension on the current file name is still valid
        if((fext) && (strlen(get_filename(s))))
        {
            strcpy(tmp, fext);
            strcpy(ext, get_extension(s));
            tok = strtok(tmp, ext_tokens);
            
            while(tok)
            {
                if(stricmp(ext, tok) == 0)
                    break;
                    
                tok = strtok(NULL, ext_tokens);
            }
            
            // not valid, replace file name
            if(!tok)
                replace_filename(s, flist->dir, "", 256);
        }
        
        scare_mouse();
        SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0);
        SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0);
        SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0);
        SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0);
        unscare_mouse();
        
        if(ret & D_CLOSE)
            return (ret | SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0)) & ~D_CLOSE;
    }
    
    return ret;
}
예제 #3
0
std::string redir(const std::string &filename)
{
  char exe[1024], buf[1024];

  get_executable_name(exe, sizeof(exe));
  replace_filename(buf, exe, filename.c_str(), sizeof(buf));

  return std::string(buf);
}
예제 #4
0
void ResourceFinder::findInBinDir(const char* filename)
{
  char buf[1024], path[1024];

  get_executable_name(path, sizeof(path));
  replace_filename(buf, path, filename, sizeof(buf));

  addPath(buf);
}
예제 #5
0
// Run an NSF, or a MIDI if the NSF is missing somehow.
bool try_zcmusic(char *filename, int track, int midi)
{
    ZCMUSIC *newzcmusic = NULL;
    
    // Try the ZC directory first
    {
        char exepath[2048];
        char musicpath[2048];
        get_executable_name(exepath, 2048);
        replace_filename(musicpath, exepath, filename, 2048);
        newzcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath);
    }
    
    // Not in ZC directory, try the quest directory
    if(newzcmusic==NULL)
    {
        char musicpath[2048];
        replace_filename(musicpath, qstpath, filename, 2048);
        newzcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath);
    }
    
    // Found it
    if(newzcmusic!=NULL)
    {
        zcmusic_stop(zcmusic);
        zcmusic_unload_file(zcmusic);
        stop_midi();
        
        zcmusic=newzcmusic;
        zcmusic_play(zcmusic, emusic_volume);
        
        if(track>0)
            zcmusic_change_track(zcmusic,track);
            
        return true;
    }
    
    // Not found, play MIDI - unless this was called by a script (yay, magic numbers)
    else if(midi>-1000)
        jukebox(midi);
        
    return false;
}
예제 #6
0
파일: gSonido.cpp 프로젝트: riseven/JRK
Sonido::Sonido(string nombreFichero)
{
    sample = NULL ;
    char buf[256] ;
    replace_filename(buf, Interfaz::Configuracion::GetNombreDirectorio().c_str(), nombreFichero.c_str(), sizeof(buf));
    sample = load_sample(buf);
    
    if ( !sample )
    {
        throw Error::ExcepcionParametro("Graficos::Sonido::Sonido(string)", 1);
    }
}    
예제 #7
0
파일: gImagen.cpp 프로젝트: riseven/JRK
BITMAP *
Imagen::CargarBitmap(string nombreFichero)
{
    BITMAP *bitmap = NULL ;;
    char buf[256] ;
    replace_filename(buf, Interfaz::Configuracion::GetNombreDirectorio().c_str(), nombreFichero.c_str(), sizeof(buf));
    bitmap = load_bitmap(buf, NULL);
    
    if (!bitmap)
    {
        throw Error::ExcepcionFichero(nombreFichero);
    }
    return bitmap ;
}
예제 #8
0
파일: erl.c 프로젝트: Airon2014/otp
static void get_parameters(void)
{
    wchar_t buffer[MAX_PATH];
    wchar_t *ini_filename;
    HANDLE module = GetModuleHandle(NULL);
    InitFile *inif;
    InitSection *inis;
    char *utf8dir;
    int len;


    if (module = NULL) {
        error("Cannot GetModuleHandle()");
    }

    if (GetModuleFileNameW(module,buffer,MAX_PATH) == 0) {
        error("Could not GetModuleFileName");
    }

    ini_filename = replace_filename(buffer,INI_FILENAME);

    if ((inif = load_init_file(ini_filename)) == NULL) {
	erlexec_dir = find_erlexec_dir(ini_filename);
	SetEnvironmentVariableW(L"ERLEXEC_DIR", erlexec_dir);
    } else {

      if ((inis = lookup_init_section(inif,INI_SECTION)) == NULL) {
	error("Could not find section %s in init file %S",
	      INI_SECTION, ini_filename);
      }
      
      utf8dir = do_lookup_in_section(inis, "Bindir", INI_SECTION, ini_filename);
      len = MultiByteToWideChar(CP_UTF8, 0, utf8dir, -1, NULL, 0);
      erlexec_dir = malloc(len*sizeof(wchar_t));
      MultiByteToWideChar(CP_UTF8, 0, utf8dir, -1, erlexec_dir, len);
      if(len == 0) {
	  error("Bindir is not a valid utf8 '%s' in init file %S",
		utf8dir, ini_filename);
      }
      free_init_file(inif);
    }
    
    erlexec_name = malloc((wcslen(erlexec_dir) + wcslen(ERLEXEC_BASENAME) + 2)*sizeof(wchar_t));
    wcscpy(erlexec_name,erlexec_dir);
    wcscat(erlexec_name, L"\\" ERLEXEC_BASENAME);
    
    free(ini_filename);
}
예제 #9
0
void load_options(void)
{
	{
		char ef[256], cf[256];

		get_executable_name(ef, 256);
		replace_filename(cf, ef, "studio.ini", 256);

		set_config_file(cf);
	}

	opt.gfx_w = get_config_int("options", "gfx_w", DEF_GFX_W);
	opt.gfx_h = get_config_int("options", "gfx_h", DEF_GFX_H);

	atexit(&save_options);
}
예제 #10
0
int main(int argc, char *argv[])
{
   PALETTE my_palette;
   BITMAP *scr_buffer;
   char pcx_name[256];

   if (allegro_init() != 0)
      return 1;
   install_keyboard();

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   replace_filename(pcx_name, argv[0], "mysha.pcx", sizeof(pcx_name));
   scr_buffer = load_pcx(pcx_name, my_palette);
   if (!scr_buffer) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", pcx_name);
      return 1;
   }

   set_palette(my_palette);
   blit(scr_buffer, screen, 0, 0, 0, 0, scr_buffer->w, scr_buffer->h);

   while (!keypressed()) {
      stretch_blit(scr_buffer, screen, 0, 0, AL_RAND()%scr_buffer->w,
		   AL_RAND()%scr_buffer->h, AL_RAND()%SCREEN_W, AL_RAND()%SCREEN_H,
		   AL_RAND()%SCREEN_W, AL_RAND()%SCREEN_H);
      vsync();
   }

   destroy_bitmap(scr_buffer);
   return 0;
}
예제 #11
0
파일: 3ds.cpp 프로젝트: jchristi/ta3d
    MODEL *load_3ds( const String &filename, float scale )
    {
        FILE *src_3ds = fopen( filename.c_str(), "rb" );
        MODEL *model_3ds = new MODEL;
        if (src_3ds)
        {
            TA3D_3DS_CHUNK_DATA	chunk;
            OBJECT *cur_obj = NULL;
            OBJECT *read_obj = NULL;
            TA3D_3DS_MATERIAL	*material = NULL;
            Vector3D local[4];
            while( fread( &chunk.ID, sizeof( chunk.ID ), 1, src_3ds ) )
            {
                if( fread( &chunk.length, sizeof( chunk.length ), 1, src_3ds ) == 0 )	break;
                switch( chunk.ID )
                {
                    case MAIN3DS:
                        //				printf("MAIN3DS (%d,%d)\n", chunk.ID, chunk.length);
                        break;
                    case EDIT3DS:
                        //					printf("-EDIT3DS (%d,%d)\n", chunk.ID, chunk.length);
                        break;
                    case EDIT_MATERIAL:
                        //						printf("--EDIT_MATERIAL (%d,%d)\n", chunk.ID, chunk.length);
                        {
                            TA3D_3DS_MATERIAL	*new_mat = new TA3D_3DS_MATERIAL;
                            new_mat->next = material;
                            material = new_mat;
                        }
                        break;
                    case MAT_NAME:
                        //							printf("---MAT_NAME (%d,%d)\n", chunk.ID, chunk.length);
                        {
                            String name = read_ASCIIZ( src_3ds );
                            //								printf( "name = %s\n", name );
                            if( material )
                                material->NAME = name;
                        }
                        break;
                    case MAT_AMBIENT:
                        //							printf("---MAT_AMBIENT (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            read_color_chunk( material->AMBIENT, src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_DIFFUSE:
                        //							printf("---MAT_DIFFUSE (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            read_color_chunk( material->DIFFUSE, src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_SPECULAR:
                        //							printf("---MAT_SPECULAR (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            read_color_chunk( material->SPECULAR, src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_SHININESS:
                        //							printf("---MAT_SHININESS (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            material->SHININESS = read_percent_chunk( src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_SHIN2PCT:
                        //							printf("---MAT_SHIN2PCT (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            material->SHIN2PCT = read_percent_chunk( src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_SHIN3PCT:
                        //							printf("---MAT_SHIN3PCT (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            material->SHIN3PCT = read_percent_chunk( src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_TRANSPARENCY:
                        //							printf("---MAT_TRANSPARENCY (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            material->TRANSPARENCY = read_percent_chunk( src_3ds );
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_TWO_SIDE:
                        //							printf("---MAT_TWO_SIDE (%d,%d)\n", chunk.ID, chunk.length);
                        if( material )
                            material->TWO_SIDE = true;
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case MAT_TEXMAP:
                        //							printf("---MAT_TEXMAP (%d,%d)\n", chunk.ID, chunk.length);
                        if( material ) {
                            uint16 n_id;
                            fread( &n_id, 2, 1, src_3ds );
                            fseek( src_3ds, -2, SEEK_CUR );
                            if( n_id == MAT_MAPNAME ) {
                                material->MAPNAME = read_MAT_MAPNAME_chunk( src_3ds );
                                material->TEXMAP = read_percent_chunk( src_3ds );
                            }
                            else {
                                material->TEXMAP = read_percent_chunk( src_3ds );
                                material->MAPNAME = read_MAT_MAPNAME_chunk( src_3ds );
                            }
                            char *full_name = new char[2048];
                            replace_filename( full_name, filename.c_str(), material->MAPNAME.c_str(), 2048 );
                            material->MAPNAME = full_name;
                            delete[] full_name;
                        }
                        else
                            fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_CONFIG1:
                        //						printf("--EDIT_CONFIG1 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_CONFIG2:
                        //						printf("--EDIT_CONFIG2 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_VIEW_P1:
                        //						printf("--EDIT_VIEW_P1 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_VIEW_P2:
                        //						printf("--EDIT_VIEW_P2 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_VIEW_P3:
                        //						printf("--EDIT_VIEW_P2 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_VIEW1:
                        //						printf("--EDIT_VIEW1 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_BACKGR:
                        //						printf("--EDIT_BACKGR (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_AMBIENT:
                        //						printf("--EDIT_AMBIENT (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case EDIT_OBJECT:
                        //						printf("--EDIT_OBJECT (%d,%d)\n", chunk.ID, chunk.length);
                        {
                            OBJECT	*n_obj = new OBJECT;
                            n_obj->next = cur_obj;
                            cur_obj = n_obj;
                        }
                        cur_obj->name = read_ASCIIZ( src_3ds );		// Read the object's name
                        read_obj = cur_obj;
                        break;
                    case OBJ_LIGHT:
                        //							printf("---OBJ_LIGHT (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case OBJ_CAMERA:
                        //							printf("---OBJ_CAMERA (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case OBJ_UNKNWN01:
                        //							printf("---OBJ_UNKNWN01 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case OBJ_UNKNWN02:
                        //							printf("---OBJ_UNKNWN02 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case OBJ_TRIMESH:
                        //							printf("---OBJ_TRIMESH (%d,%d)\n", chunk.ID, chunk.length);
                        if( read_obj->nb_vtx > 0 ) {		// Add a sub object
                            read_obj->child = new OBJECT;
                            read_obj = read_obj->child;
                            read_obj->init();
                            read_obj->name = cur_obj->name;
                        }
                        local[0].x = 1.0f;		local[0].y = 0.0f;		local[0].z = 0.0f;
                        local[1].x = 0.0f;		local[1].y = 1.0f;		local[1].z = 0.0f;
                        local[2].x = 0.0f;		local[2].y = 0.0f;		local[2].z = 1.0f;
                        local[3].x = 0.0f;		local[3].y = 0.0f;		local[3].z = 0.0f;
                        break;
                    case TRI_VERTEXL:
                        //								printf("----TRI_VERTEXL (%d,%d)\n", chunk.ID, chunk.length);
                        fread( &read_obj->nb_vtx, 2, 1, src_3ds );
                        read_obj->points = new Vector3D[read_obj->nb_vtx];
                        read_obj->N = new Vector3D[read_obj->nb_vtx];
                        if( read_obj->tcoord == NULL )
                        {
                            read_obj->tcoord = new float[read_obj->nb_vtx * 2];
                            for( int i = 0 ; i < read_obj->nb_vtx ; i++ )
                            {
                                read_obj->tcoord[ i << 1 ] = 0.0f;
                                read_obj->tcoord[ (i << 1) + 1 ] = 0.0f;
                            }
                        }
                        fread( read_obj->points, sizeof( Vector3D ), read_obj->nb_vtx, src_3ds );
                        for( int i = 0 ; i < read_obj->nb_vtx ; i++ ) {
                            read_obj->points[ i ] = read_obj->points[ i ].x * local[ 0 ] + read_obj->points[ i ].y * local[ 1 ] + read_obj->points[ i ].z * local[ 2 ] + local[ 3 ];
                            read_obj->points[ i ].x *= scale;
                            read_obj->points[ i ].y *= scale;
                            read_obj->points[ i ].z *= scale;
                            read_obj->N[ i ].x = read_obj->N[ i ].y = read_obj->N[ i ].z = 0.0f;
                        }
                        break;
                    case TRI_FACEL2:
                        //								printf("----TRI_FACEL2 (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case TRI_MATERIAL:
                        //								printf("----TRI_MATERIAL (%d,%d)\n", chunk.ID, chunk.length);
                        {
                            String material_name = read_ASCIIZ( src_3ds );
                            //									printf("material name = %s\n", material_name );

                            TA3D_3DS_MATERIAL	*cur_mat = (material != NULL) ? material->find( material_name ) : NULL ;

                            if (cur_mat)
                            {
                                //										printf("material found\n");
                                read_obj->surface.Flag |= SURFACE_ADVANCED | SURFACE_LIGHTED;
                                if (!cur_mat->MAPNAME.empty())
                                {
                                    //											printf("loading texture %s\n", cur_mat->MAPNAME );
                                    read_obj->surface.Flag |= SURFACE_TEXTURED;
                                    read_obj->surface.NbTex = 1;
                                    cHPIHandler *backup = HPIManager;
                                    HPIManager = NULL;
                                    read_obj->surface.gltex[ 0 ] = gfx->load_texture( cur_mat->MAPNAME );
                                    HPIManager = backup;
                                }
                                if (cur_mat->TRANSPARENCY > 0.0f)
                                {
                                    read_obj->surface.Flag |= SURFACE_BLENDED;
                                    read_obj->surface.Color[ 3 ] = cur_mat->TRANSPARENCY;
                                }
                            }
                            else
                                printf("WARNING: material not found!!\n");

                            uint16	nb_faces;
                            fread( &nb_faces, 2, 1, src_3ds );
                            for( int i = 0 ; i < nb_faces ; i++ ) {
                                uint16 cur_face;
                                fread( &cur_face, 2, 1, src_3ds );
                            }
                        }
                        break;
                    case TRI_MAPPING:
                        //								printf("----TRI_MAPPING (%d,%d)\n", chunk.ID, chunk.length);
                        {
                            uint16	nb_vtx;
                            fread( &nb_vtx, 2, 1, src_3ds );
                            if( read_obj->tcoord == NULL )
                                read_obj->tcoord = new float[2 * nb_vtx];
                            fread( read_obj->tcoord, 2 * sizeof( float ), nb_vtx, src_3ds );
                            for( int i = 0 ; i < nb_vtx ; i++ )
                                read_obj->tcoord[ i * 2 + 1 ] = 1.0f - read_obj->tcoord[ i * 2 + 1 ];
                        }
                        break;
                    case TRI_FACEL1:
                        //								printf("----TRI_FACEL1 (%d,%d)\n", chunk.ID, chunk.length);
                        fread( &read_obj->nb_t_index, 2, 1, src_3ds );
                        read_obj->t_index = new GLushort[read_obj->nb_t_index * 3];
                        read_obj->nb_t_index *= 3;
                        for( int i = 0 ; i < read_obj->nb_t_index ; i+=3 ) {
                            fread( &(read_obj->t_index[ i ]), 2, 3, src_3ds );
                            if( read_obj->points ) {
                                Vector3D AB,AC;
                                AB = read_obj->points[ read_obj->t_index[ i + 1 ] ] - read_obj->points[ read_obj->t_index[ i ] ];
                                AC = read_obj->points[ read_obj->t_index[ i + 2 ] ] - read_obj->points[ read_obj->t_index[ i ] ];
                                AB = AB * AC;
                                AB.unit();
                                read_obj->N[ read_obj->t_index[ i ] ] = read_obj->N[ read_obj->t_index[ i ] ] + AB;
                                read_obj->N[ read_obj->t_index[ i + 1 ] ] = read_obj->N[ read_obj->t_index[ i + 1 ] ] + AB;
                                read_obj->N[ read_obj->t_index[ i + 2 ] ] = read_obj->N[ read_obj->t_index[ i + 2 ] ] + AB;
                            }
                            uint16 face_info;
                            fread( &face_info, 2, 1, src_3ds );
                        }
                        if( read_obj->points )
                            for( int i = 0 ; i < read_obj->nb_vtx ; i++ )
                                read_obj->N[ i ].unit();
                        break;
                    case TRI_SMOOTH:
                        //								printf("----TRI_SMOOTH (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    case TRI_LOCAL:
                        //								printf("----TRI_LOCAL (%d,%d)\n", chunk.ID, chunk.length);
                        fread( &(local[0]), sizeof( Vector3D ), 1, src_3ds );		// X
                        fread( &(local[1]), sizeof( Vector3D ), 1, src_3ds );		// Y
                        fread( &(local[2]), sizeof( Vector3D ), 1, src_3ds );		// Z
                        fread( &(local[3]), sizeof( Vector3D ), 1, src_3ds );		// local origin
                        break;
                    case TRI_VISIBLE:
                        //								printf("----TRI_VISIBLE (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                        break;
                    default:
                        //				printf("unknown (%d,%d)\n", chunk.ID, chunk.length);
                        fseek( src_3ds, chunk.length - 6, SEEK_CUR );
                }
            }
            if( material )
                delete material;
            if (cur_obj)
            {
                model_3ds->obj = *cur_obj;
                cur_obj->init();
                delete cur_obj;
            }
            fclose( src_3ds );
        }
        return model_3ds;
    }
예제 #12
0
int eof_add_silence_recode_mp3(char * oggfn, unsigned long ms)
{
	char sys_command[1024] = {0};
	char backupfn[1024] = {0};
	char wavfn[1024] = {0};
	char soggfn[1024] = {0};
	char mp3fn[1024] = {0};
	SAMPLE * decoded = NULL;
	SAMPLE * combined = NULL;
	int bits;
	int stereo;
	int freq;
	unsigned long samples;
	int channels;
	unsigned long ctr,index;

 	eof_log("eof_add_silence_recode_mp3() entered", 1);

	if(!oggfn || (ms == 0) || eof_silence_loaded)
	{
		return 21;	//Return error:  Invalid parameters
	}
	set_window_title("Adjusting Silence...");

	/* back up original file */
	(void) snprintf(backupfn, sizeof(backupfn) - 1, "%s.backup", oggfn);
	if(!exists(backupfn))
	{
		(void) eof_copy_file(oggfn, backupfn);
	}

	/* decode MP3 */
	(void) replace_filename(wavfn, eof_song_path, "decode.wav", 1024);
	(void) replace_filename(mp3fn, eof_song_path, "original.mp3", 1024);
	(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "lame --decode \"%s\" \"%s\"", mp3fn, wavfn);
	(void) eof_system(sys_command);

	/* insert silence */
	decoded = load_sample(wavfn);
	if(!decoded)
	{
		allegro_message("Error opening file.\nMake sure there are no Unicode or extended ASCII characters in this chart's file path.");
		return 22;	//Return failure:  Could not load decoded MP3 file
	}
	bits = decoded->bits;
	stereo = decoded->stereo;
	freq = decoded->freq;
	samples = (decoded->freq * ms) / 1000;	//Calculate this manually instead of using msec_to_samples() because that function assumes the sample rate matches the current chart audio, and this may not be the case with the original MP3 file the user provided
	channels = stereo ? 2 : 1;
	combined = create_sample(bits,stereo,freq,samples+decoded->len);	//Create a sample array long enough for the silence and the OGG file
	if(combined == NULL)
	{
		destroy_sample(decoded);
		return 23;	//Return failure:  Could not create a sample array for the combined audio
	}
	/* Add the PCM data for the silence */
	if(bits == 8)
	{	//Create 8 bit PCM data
		for(ctr=0,index=0;ctr < samples * channels;ctr++)
		{
			((unsigned char *)(combined->data))[index++] = 0x80;
		}
	}
	else
	{	//Create 16 bit PCM data
		for(ctr=0,index=0;ctr < samples * channels;ctr++)
		{
			((unsigned short *)(combined->data))[index++] = 0x8000;
		}
	}
	/* Add the decoded OGG PCM data*/
	if(bits == 8)
	{	//Copy 8 bit PCM data
		for(ctr=0;ctr < decoded->len * channels;ctr++)
		{
			((unsigned char *)(combined->data))[index++] = ((unsigned char *)(decoded->data))[ctr];
		}
	}
	else
	{	//Copy 16 bit PCM data
		for(ctr=0;ctr < decoded->len * channels;ctr++)
		{
			((unsigned short *)(combined->data))[index++] = ((unsigned short *)(decoded->data))[ctr];
		}
	}

	/* save combined WAV */
	(void) replace_filename(wavfn, eof_song_path, "encode.wav", 1024);
	if(!save_wav(wavfn, combined))
	{
		destroy_sample(decoded);	//This is no longer needed
		destroy_sample(combined);	//This is no longer needed
		return 24;	//Return failure:  Could not create the combined audio WAV file
	}

	/* destroy samples */
	destroy_sample(decoded);	//This is no longer needed
	destroy_sample(combined);	//This is no longer needed

	/* encode the audio */
	printf("%s\n%s\n", eof_song_path, wavfn);
	(void) replace_filename(soggfn, eof_song_path, "encode.ogg", 1024);
	#ifdef ALLEGRO_WINDOWS
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn);
	#else
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn);
	#endif

	(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tCalling oggenc as follows:  %s", sys_command);
	eof_log(eof_log_string, 1);
	if(eof_system(sys_command))
	{	//If oggenc failed, retry again by specifying a quality level (specifying bitrate can fail in some circumstances)
		eof_log("\t\toggenc failed.  Retrying by specifying a quality level instead of a target bitrate", 1);
		#ifdef ALLEGRO_WINDOWS
			(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -q 9 \"%s\"", soggfn, wavfn);
		#else
			(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -q 9 \"%s\"", soggfn, wavfn);
		#endif
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tCalling oggenc as follows:  %s", sys_command);
		eof_log(eof_log_string, 1);
		if(eof_system(sys_command))
		{	//If oggenc failed again
			char tempfname[30] = {0};
			char redirect[35] = {0};

			if(eof_validate_temp_folder())
			{	//Ensure the correct working directory and presence of the temporary folder
				eof_log("\tCould not validate working directory and temp folder", 1);
				return 25;	//Return failure:  Could not validate cwd and temp folder
			}

			(void) snprintf(tempfname, sizeof(tempfname) - 1, "%soggenc.log", eof_temp_path_s);
			(void) snprintf(redirect, sizeof(redirect) - 1, " 2> %s", tempfname);
			(void) ustrzcat(sys_command, (int) sizeof(sys_command) - 1, redirect);	//Append a redirection to the command to capture the output of oggenc
			if(eof_system(sys_command))
			{	//Run one last time to catch the error output
				(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tOggenc failed.  Please see %s for any errors it gave.", tempfname);
				eof_log(eof_log_string, 1);
				eof_fix_window_title();
				return 26;	//Return failure:  Could not encode combined audio
			}
		}
	}

	/* replace the current OGG file with the new file */
	(void) eof_copy_file(soggfn, oggfn);	//Copy encode.ogg to the filename of the original OGG

	/* clean up */
	(void) replace_filename(wavfn, eof_song_path, "decode.wav", 1024);
	(void) delete_file(wavfn);		//Delete decode.wav
	(void) replace_filename(wavfn, eof_song_path, "encode.wav", 1024);
	(void) delete_file(wavfn);		//Delete encode.wav
	(void) delete_file(soggfn);	//Delete encode.ogg
	if(eof_load_ogg(oggfn, 0))
	{	//If the combined audio was loaded
		eof_fix_waveform_graph();
		eof_fix_spectrogram();
		eof_fix_window_title();
		eof_chart_length = eof_music_length;
		return 0;	//Return success
	}
	eof_fix_window_title();

	return 27;	//Return error:  Could not load new audio
}
예제 #13
0
int eof_add_silence_recode(char * oggfn, unsigned long ms)
{
	char sys_command[1024] = {0};
	char backupfn[1024] = {0};
	char wavfn[1024] = {0};
	char soggfn[1024] = {0};
	ALOGG_OGG *oggfile = NULL;
	SAMPLE *decoded = NULL, *combined = NULL;
	int bits;
	int stereo;
	int freq;
	unsigned long samples;
	int channels;
	unsigned long ctr,index;
	void * oggbuffer = NULL;
	int bitrate;

 	eof_log("eof_add_silence_recode() entered", 1);

	if(!oggfn || (ms == 0) || eof_silence_loaded)
	{
		return 41;	//Return failure:  Invalid parameters
	}
	set_window_title("Adjusting Silence...");

	/* back up original file */
	(void) snprintf(backupfn, sizeof(backupfn) - 1, "%s.backup", oggfn);
	if(!exists(backupfn))
	{
		(void) eof_copy_file(oggfn, backupfn);
	}

	/* Decode the OGG file into memory */
	//Load OGG file into memory
	oggbuffer = eof_buffer_file(oggfn, 0);	//Decode the OGG from buffer instead of from file because the latter cannot support special characters in the file path due to limitations with fopen()
	if(!oggbuffer)
	{
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tError reading OGG:  \"%s\"", strerror(errno));	//Get the Operating System's reason for the failure
		eof_log(eof_log_string, 1);
		return 42;	//Return failure:  Could not buffer chart audio into memory
	}
	oggfile=alogg_create_ogg_from_buffer(oggbuffer, (int)file_size_ex(oggfn));
	if(oggfile == NULL)
	{
		eof_log("ALOGG failed to open input audio file", 1);
		free(oggbuffer);
		return 43;	//Return failure:  Could not process buffered chart audio
	}

	//Decode OGG into memory
	decoded=alogg_create_sample_from_ogg(oggfile);
	if(decoded == NULL)
	{
		alogg_destroy_ogg(oggfile);
		free(oggbuffer);
		return 44;	//Return failure:  Could not decode chart audio to memory
	}

	/* Create a SAMPLE array large enough for the leading silence and the decoded OGG */
	bits = alogg_get_wave_bits_ogg(oggfile);
	stereo = alogg_get_wave_is_stereo_ogg(oggfile);
	freq = alogg_get_wave_freq_ogg(oggfile);
	alogg_destroy_ogg(oggfile);	//This is no longer needed
	oggfile = NULL;
	samples = msec_to_samples(ms);
	channels = stereo ? 2 : 1;
	combined = create_sample(bits,stereo,freq,samples+decoded->len);	//Create a sample array long enough for the silence and the OGG file
	if(combined == NULL)
	{
		destroy_sample(decoded);
		return 45;	//Return failure:  Could not create a sample array for the combined audio
	}

	/* Add the PCM data for the silence */
	if(bits == 8)
	{	//Create 8 bit PCM data
		for(ctr=0,index=0;ctr < samples * channels;ctr++)
		{
			((unsigned char *)(combined->data))[index++] = 0x80;
		}
	}
	else
	{	//Create 16 bit PCM data
		for(ctr=0,index=0;ctr < samples * channels;ctr++)
		{
			((unsigned short *)(combined->data))[index++] = 0x8000;
		}
	}

	/* Add the decoded OGG PCM data*/
	if(bits == 8)
	{	//Copy 8 bit PCM data
		for(ctr=0;ctr < decoded->len * channels;ctr++)
		{
			((unsigned char *)(combined->data))[index++] = ((unsigned char *)(decoded->data))[ctr];
		}
	}
	else
	{	//Copy 16 bit PCM data
		for(ctr=0;ctr < decoded->len * channels;ctr++)
		{
			((unsigned short *)(combined->data))[index++] = ((unsigned short *)(decoded->data))[ctr];
		}
	}

	/* encode the audio */
	destroy_sample(decoded);	//This is no longer needed
	free(oggbuffer);
	(void) replace_filename(wavfn, eof_song_path, "encode.wav", 1024);
	(void) save_wav(wavfn, combined);
	destroy_sample(combined);	//This is no longer needed
	(void) replace_filename(soggfn, eof_song_path, "encode.ogg", 1024);
	bitrate = alogg_get_bitrate_ogg(eof_music_track) / 1000;
	if(!bitrate)
	{	//A user found that in an audio file with a really high sample rate (ie. 96KHz), alogg_get_bitrate_ogg() may return zero instead of an expected value
		bitrate = 256;	//In case this happens, use a bitrate of 256Kbps, which should be good enough for a very high quality file
	}
	#ifdef ALLEGRO_WINDOWS
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -b %d \"%s\"", soggfn, bitrate, wavfn);
	#else
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -b %d \"%s\"", soggfn, bitrate, wavfn);
	#endif

	(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tCalling oggenc as follows:  %s", sys_command);
	eof_log(eof_log_string, 1);
	if(eof_system(sys_command))
	{	//If oggenc failed, retry again by specifying a quality level (specifying bitrate can fail in some circumstances)
		eof_log("\t\toggenc failed.  Retrying by specifying a quality level instead of a target bitrate", 1);
		#ifdef ALLEGRO_WINDOWS
			(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -q 9 \"%s\"", soggfn, wavfn);
		#else
			(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -q 9 \"%s\"", soggfn, wavfn);
		#endif
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tCalling oggenc as follows:  %s", sys_command);
		eof_log(eof_log_string, 1);
		if(eof_system(sys_command))
		{	//If oggenc failed again
			char tempfname[30] = {0};
			char redirect[35] = {0};

			if(eof_validate_temp_folder())
			{	//Ensure the correct working directory and presence of the temporary folder
				eof_log("\tCould not validate working directory and temp folder", 1);
				return 46;	//Return failure:  Could not validate cwd and temp folder
			}

			(void) snprintf(tempfname, sizeof(tempfname) - 1, "%soggenc.log", eof_temp_path_s);
			(void) snprintf(redirect, sizeof(redirect) - 1, " 2> %s", tempfname);
			(void) ustrzcat(sys_command, (int) sizeof(sys_command) - 1, redirect);	//Append a redirection to the command to capture the output of oggenc
			if(eof_system(sys_command))
			{	//Run one last time to catch the error output
				(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tOggenc failed.  Please see %s for any errors it gave.", tempfname);
				eof_log(eof_log_string, 1);
				eof_fix_window_title();
				return 47;	//Return failure:  Could not encode combined audio
			}
		}
	}

	/* replace the current OGG file with the new file */
	(void) eof_copy_file(soggfn, oggfn);	//Copy encode.ogg to the filename of the original OGG

	/* clean up */
	(void) delete_file(soggfn);	//Delete encode.ogg
	(void) delete_file(wavfn);		//Delete encode.wav
	if(eof_load_ogg(oggfn, 0))
	{	//If the combined audio was loaded
		eof_fix_waveform_graph();
		eof_fix_spectrogram();
		eof_fix_window_title();
		eof_chart_length = eof_music_length;
		return 0;	//Return success
	}
	eof_fix_window_title();

	return 48;	//Return error:  Could not load new audio
}
예제 #14
0
int eof_add_silence(char * oggfn, unsigned long ms)
{
	char sys_command[1024] = {0};
	char backupfn[1024] = {0};	//The file path of the backup of the target audio file
	char wavfn[1024] = {0};		//The file path of the silent WAV file created
	char soggfn[1024] = {0};	//The file path of the silent OGG file created
	char oggcfn[1024] = {0};	//The file path to the oggCat utility
	char old_wd[1024] = {0};	//Store working directory before changing it so we can get back
	char *rel_oggfn;			//Relative file path to the target audio file
	char *rel_backupfn;			//Relative file path to the backup of the target audio file
	SAMPLE * silence_sample;
	int retval;

	if(!oggfn || (ms == 0) || eof_silence_loaded)
	{
		return 1;	//Return error:  Invalid parameters
	}

 	eof_log("eof_add_silence() entered", 1);

	set_window_title("Adjusting Silence...");

	/* back up original file */
	(void) snprintf(backupfn, sizeof(backupfn) - 1, "%s.backup", oggfn);
	if(!exists(backupfn))
	{
		(void) eof_copy_file(oggfn, backupfn);
	}
	(void) delete_file(oggfn);

	silence_sample = create_silence_sample(ms);
	if(!silence_sample)
	{
		eof_fix_window_title();
		return 2;	//Return error:  Couldn't create silent audio
	}
	(void) replace_filename(wavfn, eof_song_path, "silence.wav", 1024);
	(void) save_wav(wavfn, silence_sample);
	destroy_sample(silence_sample);
	(void) replace_filename(soggfn, eof_song_path, "silence.ogg", 1024);
	#ifdef ALLEGRO_WINDOWS
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc2 -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn);
	#else
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "oggenc -o \"%s\" -b %d \"%s\"", soggfn, alogg_get_bitrate_ogg(eof_music_track) / 1000, wavfn);
	#endif
	if(eof_system(sys_command))
	{
		eof_fix_window_title();
		return 3;	//Return error:  Could not encode silent audio
	}

	/* stitch the original file to the silence file */
	if(!getcwd(old_wd, 1024))
	{	//If the current working directory could not be obtained
		eof_fix_window_title();
		return 4;	//Return error:  Could not obtain current working directory
	}

	(void) eof_chdir(eof_song_path);	//Change directory to the project's folder, since oggCat does not support paths that have any Unicode/extended ASCII, relative paths will be given
	#ifdef ALLEGRO_WINDOWS
		get_executable_name(oggcfn, 1024);
		(void) replace_filename(oggcfn, oggcfn, "oggCat.exe", 1024);	//Build the full path to oggCat
	#else
		ustrzcpy(oggcfn, 1024, "oggCat");
	#endif
	rel_oggfn = get_filename(oggfn);		//Get the relative path to the target OGG file
	rel_backupfn = get_filename(backupfn);	//Get the relative path to the backup of the target OGG file
	//Call oggCat while the current working directory is the project folder.  This way, if the project folder's path contains any Unicode or extended ASCII, oggCat won't fail
	#ifdef ALLEGRO_WINDOWS
		//For some reason, the Windows build needs extra quotation marks to enclose the entire command if the command begins with a full executable path in quote marks
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "\"\"%s\" \"%s\" \"silence.ogg\" \"%s\"\"", oggcfn, rel_oggfn, rel_backupfn);
	#else
		(void) uszprintf(sys_command, (int) sizeof(sys_command) - 1, "\"%s\" \"%s\" \"silence.ogg\" \"%s\"", oggcfn, rel_oggfn, rel_backupfn);	//Use oggCat to overwrite the target OGG file with the silent audio concatenated with the backup of the target OGG file
	#endif
	retval = eof_system(sys_command);

	/* change back to the program folder */
	if(eof_chdir(old_wd))
	{
		allegro_message("Could not change directory to EOF's program folder!\n%s", backupfn);
		return 5;	//Return error:  Could not set working directory
	}

	if(retval)
	{	//If the command failed
		(void) snprintf(eof_log_string, sizeof(eof_log_string) - 1, "\tError issuing command \"%s\" from path \"%s\"", sys_command, eof_song_path);
		eof_log(eof_log_string, 1);
		(void) eof_copy_file(backupfn, oggfn);	//Restore the original OGG file
		eof_fix_window_title();
		return 6;	//Return error:  oggCat failed
	}

	/* clean up */
	(void) delete_file(wavfn);	//Delete silence.wav
	(void) delete_file(soggfn);	//Delete silence.ogg
	if(eof_load_ogg(oggfn, 0))
	{	//If the combined audio was loaded
		eof_fix_waveform_graph();
		eof_fix_spectrogram();
		eof_fix_window_title();
		eof_chart_length = eof_music_length;
		return 0;	//Return success
	}
	eof_fix_window_title();

	//If this part of the function is reached, the OGG failed to load
	if(exists(oggfn))
		return 7;	//Return error:  Could not load new audio, but audio file exists

	return 8;	//Return error:  Could not load new audio, file does not exist
}
예제 #15
0
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image;
   BITMAP *page[2];
   BITMAP *vimage;
   IMAGE images[MAX_IMAGES];
   int num_images = 4;
   int page_num = 1;
   int done = FALSE;
   int i;

   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_timer();

   /* see comments in exflip.c */
#ifdef ALLEGRO_VRAM_SINGLE_SURFACE
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 2 * 768 + 200) != 0) {
#else
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
#endif
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting graphics mode\n%s\n", allegro_error);
      return 1;
   }

   /* read in the source graphic */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image = load_bitmap(buf, pal);
   if (!image) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   set_palette(pal);

   /* initialise the images to random positions */
   for (i=0; i<MAX_IMAGES; i++)
      init_image(images+i);

   /* create two video memory bitmaps for page flipping */
   page[0] = create_video_bitmap(SCREEN_W, SCREEN_H);
   page[1] = create_video_bitmap(SCREEN_W, SCREEN_H);

   /* create a video memory bitmap to store our picture */
   vimage = create_video_bitmap(image->w, image->h);

   if ((!page[0]) || (!page[1]) || (!vimage)) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Not enough video memory (need two 1024x768 pages "
		      "and a 320x200 image)\n");
      return 1;
   }

   /* copy the picture into offscreen video memory */
   blit(image, vimage, 0, 0, 0, 0, image->w, image->h);

   while (!done) {
      acquire_bitmap(page[page_num]);

      /* clear the screen */
      clear_bitmap(page[page_num]);

      /* draw onto it */
      for (i=0; i<num_images; i++)
	 blit(vimage, page[page_num], 0, 0, images[i].x, images[i].y,
	      vimage->w, vimage->h);

      textprintf_ex(page[page_num], font, 0, 0, 255, -1,
		    "Images: %d (arrow keys to change)", num_images);

      /* tell the user which functions are being done in hardware */
      if (gfx_capabilities & GFX_HW_FILL)
	 textout_ex(page[page_num], font, "Clear: hardware accelerated",
		    0, 16, 255, -1);
      else
	 textout_ex(page[page_num], font, "Clear: software (urgh, this "
		    "is not good!)", 0, 16, 255, -1);

      if (gfx_capabilities & GFX_HW_VRAM_BLIT)
	 textout_ex(page[page_num], font, "Blit: hardware accelerated",
		    0, 32, 255, -1);
      else
	 textout_ex(page[page_num], font, "Blit: software (urgh, this program "
		    "will run too sloooooowly without hardware acceleration!)",
		    0, 32, 255, -1);

      release_bitmap(page[page_num]);

      /* page flip */
      show_video_bitmap(page[page_num]);
      page_num = 1-page_num;

      /* deal with keyboard input */
      while (keypressed()) {
	 switch (readkey()>>8) {

	    case KEY_UP:
	    case KEY_RIGHT:
	       if (num_images < MAX_IMAGES)
		  num_images++;
	       break;

	    case KEY_DOWN:
	    case KEY_LEFT:
	       if (num_images > 0)
		  num_images--;
	       break;

	    case KEY_ESC:
	       done = TRUE;
	       break;
	 }
      }

      /* bounce the images around the screen */
      for (i=0; i<num_images; i++)
	 update_image(images+i);
   }

   destroy_bitmap(image);
   destroy_bitmap(vimage);
   destroy_bitmap(page[0]);
   destroy_bitmap(page[1]);

   return 0;
}

END_OF_MAIN()
예제 #16
0
void ReadConfiguration(char* argv0)
{
    char buf[512];
    char keyword[512], value[512];
    FILE *f;
    int v;

#ifdef __linux__
    snprintf(buf, sizeof(buf), "%s/.staxrc", getenv("HOME"));
#else
    replace_filename(buf, argv0, "stax.cfg", sizeof(buf));
#endif

    f = fopen(buf, "r");
    if (!f)
        return;

    while (fgets(buf, sizeof(buf), f)) {
        if (buf[0] == '#')
            continue;
        if (sscanf(buf, "%s %s", keyword, value) == 2) {
            v = atoi(value);
            if (!strcasecmp(keyword, "game")) {
                if (v < 0 || v >= NUMBER_OF_GAME_TYPES)
                    v = 0;
                configuration.game_type = (GameType)v;
            }
            else if (!strcasecmp(keyword, "input1")) {
                if (v <= 0 || v >= NUMBER_OF_INPUT_TYPES)
                    v = 1;
                configuration.input_type_1 = (InputType)v;
            }
            else if (!strcasecmp(keyword, "input2")) {
                if (v < 0 || v >= NUMBER_OF_INPUT_TYPES)
                    v = 0;
                configuration.input_type_2 = (InputType)v;
            }
            else if (!strcasecmp(keyword, "blocks")) {
                if (v < 2 || v > 5)
                    v = 4;
                configuration.number_of_block_types = v;
            }
            else if (!strcasecmp(keyword, "height")) {
                if (v < 1 || v > 15)
                    v = 5;
                configuration.initial_height = v;
            }
            else if (!strcasecmp(keyword, "mode")) {
                if (v < 0 || v > 1)
                    v = 0;
                if (v == 0)
                    configuration.graphics_driver = GFX_AUTODETECT_WINDOWED;
                else
                    configuration.graphics_driver = GFX_AUTODETECT_FULLSCREEN;
            }
            else if (!strcasecmp(keyword, "digi_driver")) {
                configuration.sound_driver = v;
            }
            else if (!strcasecmp(keyword, "midi_driver")) {
                configuration.midi_driver = v;
            }
            else if (!strcasecmp(keyword, "digi_volume")) {
                if (v < 0 || v > 255)
                    v = 255;
                configuration.sound_volume = v;
            }
            else if (!strcasecmp(keyword, "midi_volume")) {
                if (v < 0 || v > 255)
                    v = 255;
                configuration.music_volume = v;
            }
            else if (!strcasecmp(keyword, "depth")) {
                if (v != 24 && v != 16 && v != 15)
                    v = 32;
                configuration.color_depth = v;
            }
            else if (!strcasecmp(keyword, "sw")) {
                configuration.screen_width = v;
            }
            else if (!strcasecmp(keyword, "sh")) {
                configuration.screen_height = v;
            }
        }
    }

    if (configuration.input_type_1 == configuration.input_type_2) {
        configuration.input_type_1 = INPUT_RIGHT_KEYBOARD;
        configuration.input_type_2 = INPUT_NONE;
    }

    fclose(f);
}
예제 #17
0
void WriteConfiguration(char* argv0)
{
    FILE *f;
    char filename[512];

#ifdef __linux__
    snprintf(filename, sizeof(filename), "%s/.staxrc", getenv("HOME"));
#else
    replace_filename(filename, argv0, "stax.cfg", sizeof(filename));
#endif

    f = fopen(filename, "w");
    if (!f)
        return;

    fprintf(f,
            "# Default Game Type:\n"
            "#\n"
            "# 0 = Sucker\n"
            "# 1 = SpringShot\n"
            "# 2 = Shifty\n"
           );
    fprintf(f, "game %d\n", (int)configuration.game_type);
    fprintf(f, "\n");
    fprintf(f,
            "# Input (Player 1 and 2):\n"
            "#\n"
            "# 0 = Keys 1 (Arrows)\n"
            "# 1 = Keys 2 (WASD)\n"
            "# 2 = Joystick 1\n"
            "# 3 = Joystick 2\n\n"
           );
    fprintf(f, "input1 %d\n", (int)configuration.input_type_1);
    fprintf(f, "input2 %d\n", (int)configuration.input_type_2);
    fprintf(f, "\n");
    fprintf(f, "# Number of different block types\n");
    fprintf(f, "blocks %d\n", configuration.number_of_block_types);
    fprintf(f, "\n");
    fprintf(f, "# Initial height of the blocks\n");
    fprintf(f, "height %d\n", configuration.initial_height);
    fprintf(f, "\n");
    fprintf(f,
            "# Graphics mode:\n"
            "#\n"
            "# 0 = Windowed\n"
            "# 1 = Full screen\n"
            "\n"
           );
    int mode;
    if (configuration.graphics_driver == GFX_AUTODETECT_WINDOWED)
        mode = 0;
    else
        mode = 1;
    fprintf(f, "mode %d\n", mode);
    fprintf(f, "\n");
    fprintf(f, "# Sound driver (system dependant, see Allegro docs)\n");
    fprintf(f, "digi_driver %d\n", configuration.sound_driver);
    fprintf(f, "# MIDI driver (system dependant, see Allegro docs)\n");
    fprintf(f, "midi_driver %d\n", configuration.midi_driver);
    fprintf(f, "# Sound volume\n");
    fprintf(f, "digi_volume %d\n", configuration.sound_volume);
    fprintf(f, "# MIDI volume\n");
    fprintf(f, "midi_volume %d\n", configuration.music_volume);
    fprintf(f, "# Color depth\n");
    fprintf(f, "depth %d\n", configuration.color_depth);
    fprintf(f, "# Screen width\n");
    fprintf(f, "sw %d\n", configuration.screen_width);
    fprintf(f, "# Screen height\n");
    fprintf(f, "sh %d\n", configuration.screen_height);

    fclose(f);
}
예제 #18
0
void play_DmapMusic()
{
    static char tfile[2048];
    static int ttrack=0;
    bool domidi=false;
    
    // Seems like this ought to call try_zcmusic()...
    
    if(DMaps[currdmap].tmusic[0]!=0)
    {
        if(zcmusic==NULL ||
           strcmp(zcmusic->filename,DMaps[currdmap].tmusic)!=0 ||
           (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[currdmap].tmusictrack))
        {
            if(zcmusic != NULL)
            {
                zcmusic_stop(zcmusic);
                zcmusic_unload_file(zcmusic);
                zcmusic = NULL;
            }
            
            // Try the ZC directory first
            {
                char exepath[2048];
                char musicpath[2048];
                get_executable_name(exepath, 2048);
                replace_filename(musicpath, exepath, DMaps[currdmap].tmusic, 2048);
                zcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath);
            }
            
            // Not in ZC directory, try the quest directory
            if(zcmusic==NULL)
            {
                char musicpath[2048];
                replace_filename(musicpath, qstpath, DMaps[currdmap].tmusic, 2048);
                zcmusic=(ZCMUSIC*)zcmusic_load_file(musicpath);
            }
            
            if(zcmusic!=NULL)
            {
                stop_midi();
                strcpy(tfile,DMaps[currdmap].tmusic);
                zcmusic_play(zcmusic, emusic_volume);
                int temptracks=0;
                temptracks=zcmusic_get_tracks(zcmusic);
                temptracks=(temptracks<2)?1:temptracks;
                ttrack = vbound(DMaps[currdmap].tmusictrack,0,temptracks-1);
                zcmusic_change_track(zcmusic,ttrack);
            }
            else
            {
                tfile[0] = 0;
                domidi=true;
            }
        }
    }
    else
    {
        domidi=true;
    }
    
    if(domidi)
    {
        int m=DMaps[currdmap].midi;
        
        switch(m)
        {
        case 1:
            jukebox(ZC_MIDI_OVERWORLD);
            break;
            
        case 2:
            jukebox(ZC_MIDI_DUNGEON);
            break;
            
        case 3:
            jukebox(ZC_MIDI_LEVEL9);
            break;
            
        default:
            if(m>=4 && m<4+MAXCUSTOMMIDIS)
                jukebox(m-4+ZC_MIDI_COUNT);
            else
                music_stop();
        }
    }
}
예제 #19
0
int main(int argc, char *argv[])
{
   DATAFILE *data;
   FONT *f;
   BITMAP *buffer;
   int i, j, k, height;
   char buf[256], tmp[256], tmp2[256];
   int counter = 0, drawn = 0;
   int scroll_w, scroll_h;
   int background_color;

   /* set the text encoding format BEFORE initializing the library */
   set_uformat(U_UNICODE);

   /*  past this point, every string that we pass to or retrieve
    *  from any Allegro API call must be in 16-bit Unicode format
    */

   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();

   /* load the datafile containing the Unicode font */
   replace_filename(buf, uconvert_ascii(argv[0], tmp), uconvert_ascii(DATAFILE_NAME, tmp2), sizeof(buf));
   data = load_datafile(buf);
   if (!data) {
      allegro_message(uconvert_ascii("Unable to load %s\n", tmp), buf);
      return -1;
   }

   /* set the graphics mode */
   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message(uconvert_ascii("Unable to set any graphic mode\n%s\n", tmp), allegro_error);
	 return 1;
      }
   }

   /* set the window title for windowed modes */
   set_window_title(uconvert_ascii("Unicode example program", tmp));

   /* create a buffer for drawing */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* get a handle to the Unicode font */
   f = data[0].dat;
   height = text_height(f);

   /* The are for the text messages. If it gets too crowded once we have more
    * languages, this can be increased.
    */
   scroll_w = SCREEN_W * 2;
   scroll_h = SCREEN_H + height;

   /* one of the bright colors in the default palette */
   background_color = 56 + AL_RAND() % 48;

   /* prepare the messages */
   for (i = 0; i < NLANGUAGES; i++) {

      /* the regular Standard C string manipulation functions don't work
       * with 16-bit Unicode, so we use the Allegro Unicode API
       */
      message[i].str = malloc(ustrsize(message[i].data) + ustrsizez(allegro_str));

      if (message[i].prefix_allegro) {
         ustrcpy(message[i].str, allegro_str);
         ustrcat(message[i].str, message[i].data);
      }
      else {
         ustrcpy(message[i].str, message[i].data);
         ustrcat(message[i].str, allegro_str);
      }

      message[i].w = text_length(f, message[i].str);
      message[i].h = text_height(f);

      /* one of the dark colors in the default palette */
      message[i].c = 104 + AL_RAND() % 144;

      message[i].dx *= 1 + AL_RAND() % 4;
      message[i].dy = AL_RAND() % 3 - 1;

      /* find not-overlapped position, try 1000 times */
      for (k = 0; k < 1000; k++) {
         message[i].x = AL_RAND() % scroll_w;
         /* make sure the message is not sliced by a screen edge */
         message[i].y = 10 + AL_RAND() % (SCREEN_H - height - 20);
         for (j = 0; j < i; j++) {
            if (overlap(i, j, 10))
               break;
         }
         if (j == i)
            break;
      }
   }

   install_int_ex(ticker, BPS_TO_TIMER(30));
   /* do the scrolling */
   while (!keypressed()) {
      /* Animation. */
      while (counter <= ticks) {
         for (i = 0; i < NLANGUAGES; i++) {
            message[i].x += message[i].dx;
            if (message[i].x >= scroll_w)
               message[i].x -= scroll_w;
            if (message[i].x < 0)
               message[i].x += scroll_w;
            message[i].y += message[i].dy;
            if (message[i].y >= scroll_h)
               message[i].y -= scroll_h;
            if (message[i].y < 0)
               message[i].y += scroll_h;
         }
         counter++;
      }

      /* Draw current frame. */
      if (drawn < counter) {
         clear_to_color(buffer, background_color);
         for (i = 0; i < NLANGUAGES; i++) {
            char *str = message[i].str;
            int x = message[i].x;
            int y = message[i].y;
            int c = message[i].c;
            /* draw it 4 times to get the wrap-around effect */
            textout_ex(buffer, f, str, x, y, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y, c, -1);
            textout_ex(buffer, f, str, x, y - scroll_h, c, -1);
            textout_ex(buffer, f, str, x - scroll_w, y - scroll_h, c, -1);
         }
         blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
         drawn = counter;
      }
      else {
         rest(10); /* We are too fast, give time to the OS. */
      }
   }

   destroy_bitmap(buffer);

   unload_datafile(data);

   return 0;
}
예제 #20
0
int main(int argc, char *argv[])
{
   char buf[256];
   int i;

   /* initialise everything */
   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_mouse();
   install_timer();

   if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
	 return 1;
      }
   }

   /* load the datafile */
   replace_filename(buf, argv[0], "example.dat", sizeof(buf));
   datafile = load_datafile(buf);
   if (!datafile) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s!\n", buf);
      return 1;
   }

   set_palette(datafile[THE_PALETTE].dat);

   /* set up colors */
   gui_fg_color = makecol(0, 0, 0);
   gui_mg_color = makecol(128, 128, 128);
   gui_bg_color = makecol(200, 240, 200);
   set_dialog_color(the_dialog, gui_fg_color, gui_bg_color);

   /* white color for d_clear_proc and the d_?text_procs */
   the_dialog[0].bg = makecol(255, 255, 255);
   for (i = 4; the_dialog[i].proc; i++) {
      if (the_dialog[i].proc == d_text_proc ||
          the_dialog[i].proc == d_ctext_proc ||
          the_dialog[i].proc == d_rtext_proc)
      {
         the_dialog[i].bg = the_dialog[0].bg;
      }
   }
   
   /* fill in bitmap pointers */
   the_dialog[BITMAP_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   the_dialog[ICON_OBJECT].dp = datafile[SILLY_BITMAP].dat;
   
   /* shift the dialog 2 pixels away from the border */
   position_dialog(the_dialog, 2, 2);
   
   /* do the dialog */
   do_dialog(the_dialog, -1);

   unload_datafile(datafile);
   
   return 0;
}
예제 #21
0
const FileItemList& FileItem::getChildren()
{
  // Is the file-item a folder?
  if (IS_FOLDER(this) &&
      // if the children list is empty, or the file-system version
      // change (it's like to say: the current this->children list
      // is outdated)...
      (this->children.empty() ||
       current_file_system_version > this->version)) {
    FileItemList::iterator it;
    FileItem* child;

    // we have to mark current items as deprecated
    for (it=this->children.begin();
         it!=this->children.end(); ++it) {
      child = static_cast<FileItem*>(*it);
      child->removed = true;
    }

    //PRINTF("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname);
#ifdef USE_PIDLS
    {
      IShellFolder* pFolder = NULL;

      if (this == rootitem)
        pFolder = shl_idesktop;
      else
        shl_idesktop->BindToObject(this->fullpidl,
                                   NULL,
                                   IID_IShellFolder,
                                   (LPVOID *)&pFolder);

      if (pFolder != NULL) {
        IEnumIDList *pEnum = NULL;
        ULONG c, fetched;

        /* get the interface to enumerate subitems */
        pFolder->EnumObjects(win_get_window(),
                             SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);

        if (pEnum != NULL) {
          LPITEMIDLIST itempidl[256];
          SFGAOF attribs[256];

          /* enumerate the items in the folder */
          while (pEnum->Next(256, itempidl, &fetched) == S_OK && fetched > 0) {
            /* request the SFGAO_FOLDER attribute to know what of the
               item is a folder */
            for (c=0; c<fetched; ++c) {
              attribs[c] = SFGAO_FOLDER;
              pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c);
            }

            /* generate the FileItems */
            for (c=0; c<fetched; ++c) {
              LPITEMIDLIST fullpidl = concat_pidl(this->fullpidl,
                                                  itempidl[c]);

              child = get_fileitem_by_fullpidl(fullpidl, false);
              if (!child) {
                child = new FileItem(this);

                child->pidl = itempidl[c];
                child->fullpidl = fullpidl;
                child->attrib = attribs[c];

                update_by_pidl(child);
                put_fileitem(child);
              }
              else {
                ASSERT(child->parent == this);
                free_pidl(fullpidl);
                free_pidl(itempidl[c]);
              }

              this->insertChildSorted(child);
            }
          }

          pEnum->Release();
        }

        if (pFolder != shl_idesktop)
          pFolder->Release();
      }
    }
#else
    {
      char buf[MAX_PATH], path[MAX_PATH], tmp[32];

      ustrcpy(path, this->filename.c_str());
      put_backslash(path);

      replace_filename(buf,
                       path,
                       uconvert_ascii("*.*", tmp),
                       sizeof(buf));

#ifdef WORKAROUND_64BITS_SUPPORT
      // we cannot use the for_each_file's 'param' to wrap a 64-bits pointer
      for_each_child_callback_param = this;
      for_each_file(buf, FA_TO_SHOW, for_each_child_callback, 0);
#else
      for_each_file(buf, FA_TO_SHOW,
                    for_each_child_callback,
                    (int)this);
#endif
  }
#endif

    // check old file-items (maybe removed directories or file-items)
    for (it=this->children.begin();
         it!=this->children.end(); ) {
      child = static_cast<FileItem*>(*it);
      if (child->removed) {
        it = this->children.erase(it);

        fileitems_map->erase(fileitems_map->find(child->keyname));
        delete child;
      }
      else
        ++it;
    }

    // now this file-item is updated
    this->version = current_file_system_version;
  }

  return this->children;
}
예제 #22
0
int main(int argc, char *argv[])
{
   PALETTE pal;
   BITMAP *buffer;
   BITMAP *planet;
   char buf[256];

   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_mouse();

   if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 240, 0, 0) != 0) {
	 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	 allegro_message("Unable to set any graphic mode\n%s\n",
			 allegro_error);
	 return 1;
      }
   }

   replace_filename(buf, argv[0], "planet.pcx", sizeof(buf));

   planet = load_bitmap(buf, pal);
   if (!planet) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s\n", buf);
      return 1;
   }

   buffer = create_bitmap(SCREEN_W, SCREEN_H);
   clear_bitmap(buffer);

   set_palette(pal);

   create_rgb_table(&rgb_table, pal, NULL);
   rgb_map = &rgb_table;

   create_light_table(&light_table, pal, 0, 0, 0, NULL);
   color_map = &light_table;

   set_trans_blender(0, 0, 0, 128);

   do {
      poll_mouse();

      draw_gouraud_sprite(buffer, planet, SCREEN_W/2, SCREEN_H/2,
			  distance(SCREEN_W/2, SCREEN_H/2, mouse_x, mouse_y),
			  distance(SCREEN_W/2 + planet->w, SCREEN_H/2,
				   mouse_x, mouse_y),
			  distance(SCREEN_W/2 + planet->w,
				   SCREEN_H/2 + planet->h, mouse_x, mouse_y),
			  distance(SCREEN_W/2, SCREEN_H/2 + planet->h,
				   mouse_x, mouse_y));

      textout_ex(buffer, font, "Gouraud Shaded Sprite Demo", 0, 0,
		 palette_color[10], -1);

      show_mouse(buffer);
      blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
      show_mouse(NULL);

   } while (!keypressed());

   destroy_bitmap(planet);
   destroy_bitmap(buffer);

   return 0;
}
예제 #23
0
int CGame::SetupGame(char *argv[]) {

	int bpp = 32; //bits per pixel (truecolor)
	
	//buffers for filename manipulation
	char fullpath[255];
	char filename[10]; 

	int ret; //catches return values for processing
	int i;  //universal loop counter

	//initialise allegro stuff
	allegro_init(); 
	install_keyboard(); 
	install_mouse(); 
	install_timer();

	set_color_depth(bpp);
	
	/* Lets play the color depth game!  tries 32, 24, then 16 bit color modes */
	// set resolution to play intro movie
	ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);
		
		bpp = 24;
		set_color_depth(bpp);
		
		// set resolution
		ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
		/* did the video mode set properly? */
		if (ret != 0) {
			set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
			allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error);

			bpp = 16;
			set_color_depth(bpp);

			// set resolution
			ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
			/* did the video mode set properly? */
			if (ret != 0) {
				set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
				allegro_message("Error setting %d bit graphics mode\n%s\nIm all out of options. Exiting", bpp, allegro_error);
				return 1;
			}
		}
	}
	
	// Load data from data.dat into memory
	textout_centre(screen,font,"NOW LOADING",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255));

	sprintf(filename,"data.dat");
	replace_filename(fullpath, argv[0], filename, sizeof(fullpath));
    data = load_datafile(fullpath);
	if (!data) { 
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Cant load file %s for some reason.\nIt should be in the same directory as the .exe\n"
		"If you have deleted the debug directory to mark this then\ncopy all files from the \"required files\""
		"directory into the directory with the .exe\n\nThanks. Scarbble will now crash horribly", filename);
		return 1;
	}

	//make smaller copy of all tiles
	for (i=0;i<27;i++) {
		smalltiles[i] = create_bitmap(29,29);
		rotate_scaled_sprite(smalltiles[i], (WINDOWS_BITMAP *)data[i].dat, 0,0, 0, ftofix(0.8));
	}
		
	PlayIntro();

	AddPlayers();

	//stuff that cant be done in the players constructor
	InitialisePlayers();
	
	//set video mode to play game
	ret = set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0);
	/* did the video mode set properly? */
	if (ret != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Error setting %d bit graphics mode\n%s\n", bpp, allegro_error);
		return 1;
	}
	
	//initialise the 'background' screen buffer
	background = create_bitmap(SCREEN_W, SCREEN_H);
	clear(background); //clear to black
	boardcolor = makecol(206,206,90);

	show_mouse(screen);
		
	return 0;
}
예제 #24
0
int main(int argc, char **argv)
{
   SPRITE sprites[SPRITE_COUNT];
   BITMAP *buffer;
   BITMAP *pic;
   BITMAP *tmp;
   char buf[1024];
   char *filename;
   int mode = 0;
   int hold_space = 0;
   char *msg;
   int i;

   /* standard init */
   if (allegro_init() != 0)
      return 1;
   install_timer();
   install_keyboard();

   /* setting graphics mode */
   set_color_depth(16);
   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
         allegro_message("Unable to set any graphic mode\n%s\n",
                 allegro_error);
         return 1;
      }
   }

   /* set initial position, direction and drawing for all sprites */
   for (i = 0; i < SPRITE_COUNT; i++)
      setup_sprite(&sprites[i], i);

   /* sort the sprites by drawing level */
   qsort(sprites, SPRITE_COUNT, sizeof(SPRITE), sprite_compare);

   /* locate the bitmap we will use */
   replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf));
   filename = buf;

   /* load the bitmap and stretch it */
   tmp = load_bitmap(filename, NULL);
   pic = create_bitmap(64, 64);
   stretch_blit(tmp, pic, 0, 0, tmp->w, tmp->h, 0, 0, pic->w, pic->h);
   destroy_bitmap(tmp);

   /* we are using double buffer mode, so create the back buffer */
   buffer = create_bitmap(screen->w, screen->h);

   set_trans_blender(128, 0, 64, 128);

   /* exit on Esc key */
   while (!key[KEY_ESC]) {
      /* move every sprite and draw it on the back buffer */
      for (i = 0; i < SPRITE_COUNT; i++) {
         SPRITE *s = &sprites[i];
         move_sprite(s);
         draw_sprite_ex(buffer, pic, s->x, s->y, s->draw_type, mode);
      }

      /* handle the space key */
      if (key[KEY_SPACE] && !hold_space) {
         hold_space = 1;
         /* switch to next flipping mode */
         switch (mode) {
            case DRAW_SPRITE_H_FLIP:
               mode = DRAW_SPRITE_V_FLIP;
               break;
            case DRAW_SPRITE_V_FLIP:
               mode = DRAW_SPRITE_VH_FLIP;
               break;
            case DRAW_SPRITE_VH_FLIP:
               mode = DRAW_SPRITE_NO_FLIP;
               break;
            case DRAW_SPRITE_NO_FLIP:
               mode = DRAW_SPRITE_H_FLIP;
               break;
         }
      }
      if (!key[KEY_SPACE]) {
         hold_space = 0;
      }

      /* set the title according to the flipping mode used */
      if (mode == DRAW_SPRITE_VH_FLIP) {
         msg = "horizontal and vertical flip";
      } else if (mode == DRAW_SPRITE_H_FLIP) {
         msg = "horizontal flip";
      } else if (mode == DRAW_SPRITE_V_FLIP) {
         msg = "vertical flip";
      } else {
         msg = "no flipping";
      }
      textprintf_ex(buffer, font, 1, 1, makecol(255, 255, 255), -1, msg);

      /* finally blit the back buffer on the screen */
      blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
      clear_bitmap(buffer);

      /* reduce CPU usage */
      rest(20);
   }

   /* clean up */
   destroy_bitmap(pic);
   destroy_bitmap(buffer);

   return 0;
}
예제 #25
0
/* fs_flist_proc:
  *  Dialog procedure for the file selector list.
  */
static int fs_flist_proc(int msg, DIALOG *d, int c)
{
    static int recurse_flag = 0;
    char *s = (char *) file_selector[FS_EDIT].dp;
    char tmp[32];
    /* of s (in bytes) */
    int size = (file_selector[FS_EDIT].d1 + 1) * uwidth_max(U_CURRENT);
    int sel = d->d1;
    int i, ret;
    int ch, count;
    
    if(msg == MSG_START)
    {
        if(!flist)
        {
            flist = (FLIST *) zc_malloc(sizeof(FLIST));
            
            if(!flist)
            {
                *allegro_errno = ENOMEM;
                return D_CLOSE;
            }
        }
        else
        {
            for(i=0; i<flist->size; i++)
                if(flist->name[i])
                    zc_free(flist->name[i]);
        }
        
        flist->size = 0;
        
        replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir));
        
        /* The semantics of the attributes passed to file_select_ex() is
          * different from that of for_each_file_ex() in one case: when
          * the 'd' attribute is not mentioned in the set of characters,
          * the other attributes are not taken into account for directories,
          * i.e the directories are all included. So we can't filter with
          * for_each_file_ex() in that case.
          */
        if(attrb_state[ATTRB_DIREC] == ATTRB_ABSENT)
            /* accept all dirs */
            for_each_file_ex(flist->dir, 0 , FA_LABEL, fs_flist_putter, (void *)1UL /* check */);
        else
            /* don't check */
            for_each_file_ex(flist->dir, build_attrb_flag(ATTRB_SET), build_attrb_flag(ATTRB_UNSET) | FA_LABEL, fs_flist_putter, (void *)0UL);
            
        usetc(get_filename(flist->dir), 0);
        d->d1 = d->d2 = 0;
        sel = 0;
    }
    
    if(msg == MSG_END)
    {
        if(flist)
        {
            for(i=0; i<flist->size; i++)
                if(flist->name[i])
                    zc_free(flist->name[i]);
                    
            zc_free(flist);
            flist = NULL;
        }
    }
    
    recurse_flag++;
    ret = jwin_abclist_proc(msg,d,c);                         /* call the parent procedure */
    
    recurse_flag--;
    
    if(((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0))
    {
        replace_filename(s, flist->dir, flist->name[d->d1], size);
        
        /* check if we want to `cd ..' */
        if((!ustrncmp(flist->name[d->d1], uconvert_ascii("..", tmp), 2)) && (ret == D_CLOSE))
        {
            /* let's remember the previous directory */
            usetc(updir, 0);
            i = ustrlen(flist->dir);
            count = 0;
            
            while(i>0)
            {
                ch = ugetat(flist->dir, i);
                
                if((ch == '/') || (ch == OTHER_PATH_SEPARATOR))
                {
                    if(++count == 2)
                        break;
                }
                
                uinsert(updir, 0, ch);
                i--;
            }
            
            /* ok, we have the dirname in updir */
        }
        else
        {
            usetc(updir, 0);
        }
        
        object_message(file_selector+FS_EDIT, MSG_START, 0);
        object_message(file_selector+FS_EDIT, MSG_DRAW, 0);
        
        if(ret == D_CLOSE)
            return object_message(file_selector+FS_EDIT, MSG_KEY, 0);
    }
    
    return ret;
}
예제 #26
0
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image1;
   BITMAP *image2;
   BITMAP *buffer;
   int r, g, b, a;
   int x, y, w, h;
   int x1, y1, x2, y2;
   int prevx1, prevy1, prevx2, prevy2;
   int timer;
   int bpp = -1;
   int ret = -1;

   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_timer();

   /* what color depth should we use? */
   if (argc > 1) {
      if ((argv[1][0] == '-') || (argv[1][0] == '/'))
	 argv[1]++;
      bpp = atoi(argv[1]);
      if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) {
	 allegro_message("Invalid color depth '%s'\n", argv[1]);
	 return 1;
      }
   }

   if (bpp > 0) {
      /* set a user-requested color depth */
      set_color_depth(bpp);
      ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
   }
   else {
      /* autodetect what color depths are available */
      static int color_depths[] = { 16, 15, 32, 24, 0 };
      for (a=0; color_depths[a]; a++) {
	 bpp = color_depths[a];
	 set_color_depth(bpp);
	 ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	 if (ret == 0)
	    break;
      }
   }

   /* did the video mode set properly? */
   if (ret != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting %d bit graphics mode\n%s\n", bpp,
		      allegro_error);
      return 1;
   }

   /* specify that images should be loaded in a truecolor pixel format */
   set_color_conversion(COLORCONV_TOTAL);

   /* load the first picture */
   replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf));
   image1 = load_bitmap(buf, pal);
   if (!image1) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* load the second picture */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image2 = load_bitmap(buf, pal);
   if (!image2) {
      destroy_bitmap(image1);
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* create a double buffer bitmap */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* Note that because we loaded the images as truecolor bitmaps, we don't
    * need to bother setting the palette, and we can display both on screen
    * at the same time even though the source files use two different 256
    * color palettes...
    */

   prevx1 = prevy1 = prevx2 = prevy2 = 0;

   textprintf_ex(screen, font, 0, SCREEN_H-8, makecol(255, 255, 255), 0,
		 "%d bpp", bpp);

   while (!keypressed()) {
      timer = retrace_count;
      clear_bitmap(buffer);

      /* the first image moves in a slow circle while being tinted to 
       * different colors...
       */
      x1= 160+fixtoi(fixsin(itofix(timer)/16)*160);
      y1= 140-fixtoi(fixcos(itofix(timer)/16)*140);
      r = 127-fixtoi(fixcos(itofix(timer)/6)*127);
      g = 127-fixtoi(fixcos(itofix(timer)/7)*127);
      b = 127-fixtoi(fixcos(itofix(timer)/8)*127);
      a = 127-fixtoi(fixcos(itofix(timer)/9)*127);
      set_trans_blender(r, g, b, 0);
      draw_lit_sprite(buffer, image1, x1, y1, a);
      textprintf_ex(screen, font, 0, 0, makecol(r, g, b), 0, "light: %d ", a);

      /* the second image moves in a faster circle while the alpha value
       * fades in and out...
       */
      x2= 160+fixtoi(fixsin(itofix(timer)/10)*160);
      y2= 140-fixtoi(fixcos(itofix(timer)/10)*140);
      a = 127-fixtoi(fixcos(itofix(timer)/4)*127);
      set_trans_blender(0, 0, 0, a);
      draw_trans_sprite(buffer, image2, x2, y2);
      textprintf_ex(screen, font, 0, 8, makecol(a, a, a), 0, "alpha: %d ", a);

      /* copy the double buffer across to the screen */
      vsync();

      x = MIN(x1, prevx1);
      y = MIN(y1, prevy1);
      w = MAX(x1, prevx1) + 320 - x;
      h = MAX(y1, prevy1) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      x = MIN(x2, prevx2);
      y = MIN(y2, prevy2);
      w = MAX(x2, prevx2) + 320 - x;
      h = MAX(y2, prevy2) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      prevx1 = x1;
      prevy1 = y1;
      prevx2 = x2;
      prevy2 = y2;
   }

   clear_keybuf();

   destroy_bitmap(image1);
   destroy_bitmap(image2);
   destroy_bitmap(buffer);

   return 0;
}
예제 #27
0
파일: fonttxt.c 프로젝트: Skiles/aseprite
/* load_txt_font:
 *  Loads a scripted font.
 */
FONT *load_txt_font(AL_CONST char *filename, RGB *pal, void *param)
{
   char buf[1024], *font_str, *start_str = 0, *end_str = 0;
   char font_filename[1024];
   FONT *f, *f2, *f3, *f4;
   PACKFILE *pack;
   int begin, end, glyph_pos=32;

   pack = pack_fopen(filename, F_READ);
   if (!pack) 
      return NULL;

   f = f2 = f3 = f4 = NULL;

   while(pack_fgets(buf, sizeof(buf)-1, pack)) {
      font_str = strtok(buf, " \t");
      if (font_str) 
         start_str = strtok(0, " \t");
      if (start_str) 
         end_str = strtok(0, " \t");

      if (!font_str || !start_str) {
         if (f)
            destroy_font(f);
         if (f2)
            destroy_font(f2);

         pack_fclose(pack);

         return NULL;
      }

      if(font_str[0] == '-')
         font_str[0] = '\0';

      begin = strtol(start_str, 0, 0);

      if (end_str)
         end = strtol(end_str, 0, 0);
      else 
         end = -1;

      if(begin <= 0 || (end > 0 && end < begin)) {
         if (f)
            destroy_font(f);
         if (f2)
            destroy_font(f2);

         pack_fclose(pack);

         return NULL;
      }

      /* Load the font that needs to be merged with the current font */
      if (font_str[0]) {
         if (f2)
            destroy_font(f2);
         if (exists(font_str)) {
            f2 = load_font(font_str, pal, param);
         } else if (is_relative_filename(font_str)) {
            replace_filename(font_filename, filename, font_str,
                             sizeof(font_filename));
            f2 = load_font(font_filename, pal, param);
         }
         else {
            f2 = NULL;
         }
         if (f2)
            glyph_pos=get_font_range_begin(f2, -1);
      }

      if (!f2) {
         if (f)
            destroy_font(f);
         pack_fclose(pack);
         return NULL;
      }

      if (end == -1)
         end = begin + get_font_range_end(f2,-1) - glyph_pos;

      /* transpose the font to the range given in the .txt file */
      f4=extract_font_range(f2,glyph_pos,glyph_pos + (end - begin));

      if (f4 && (begin != glyph_pos)) {
         transpose_font(f4, begin - glyph_pos);
      }
      glyph_pos += (end - begin) + 1;

      /* FIXME: More efficient way than to repeatedely merge into a new font? */
      if (f && f4) {
         f3 = f;
         f = merge_fonts(f4, f3);
         destroy_font(f4);
         destroy_font(f3);
      }
      else {
         f = f4;
      }
      f3=f4=NULL;
   }
   if (f2)
      destroy_font(f2);

   pack_fclose(pack);
   return f;
}
예제 #28
0
파일: rfsel.c 프로젝트: albinoz/raine
/* fs_flist_proc:
 *  Dialog procedure for the file selector list.
 */
static int fs_flist_proc(int msg, DIALOG *d, int c)
{
   static int recurse_flag = 0;
   char *s = file_selector[FS_EDIT].dp;
   char tmp[32];
   int sel = d->d1;
   int i, ret;
   int ch, count;

   if (msg == MSG_START) {
      if (!flist) {
	 flist = malloc(sizeof(FLIST));

	 if (!flist) {
	    *allegro_errno = ENOMEM;
	    return D_CLOSE;
	 }
      }
      else {
	 for (i=0; i<flist->size; i++)
	    if (flist->name[i])
	       free(flist->name[i]);
      }

      flist->size = 0;

      replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir));

      for_each_file(flist->dir, FA_RDONLY | FA_DIREC | FA_ARCH | FA_HIDDEN | FA_SYSTEM, fs_flist_putter, 0);

      if (*allegro_errno)
	 raine_alert("", "Disk error", NULL, NULL,  "OK", NULL, 13, 0);

      usetc(get_filename(flist->dir), 0);
      d->d1 = d->d2 = 0;
      sel = 0;
   }

   if (msg == MSG_END) {
      if (flist) {
	 for (i=0; i<flist->size; i++)
	    if (flist->name[i])
	       free(flist->name[i]);
	 free(flist);
	 flist = NULL;
      }
   }

   recurse_flag++;
   ret = d_text_list_proc(msg, d, c);     /* call the parent procedure */
   recurse_flag--;

   if (((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0)) {
      replace_filename(s, flist->dir, flist->name[d->d1], 512);
      /* check if we want to `cd ..' */
      if ((!ustrncmp(flist->name[d->d1], "..", 2)) && (ret == D_CLOSE)) {
	 /* let's remember the previous directory */
	 ustrcpy(updir, empty_string);
	 i = ustrlen(flist->dir);
	 count = 0;
	 while (i>0) {
	    ch = ugetat(flist->dir, i);
	    if ((ch == '/') || (ch == OTHER_PATH_SEPARATOR)) {
	       if (++count == 2)
		  break;
	    }
	    uinsert(updir, 0, ch);
	    i--;
	 }
	 /* ok, we have the dirname in updir */
      }
      else {
	 ustrcpy(updir, empty_string);
      }
      scare_mouse();
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0);
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0);
      unscare_mouse();

      if (ret == D_CLOSE)
	 return SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0);
   }

   return ret;
}
예제 #29
0
int main(int argc, char *argv[])
{
   int c, w, h;
   char buf[256], buf2[256];
   ANIMATION_TYPE type;

   for (c = 1; c < argc; c++) {
      if (stricmp(argv[c], "-cheat") == 0)
         cheat = TRUE;

      if (stricmp(argv[c], "-jumpstart") == 0)
         jumpstart = TRUE;
   }

   /* The fonts we are using don't contain the full latin1 charset (not to
    * mention Unicode), so in order to display correctly author names in
    * the credits with 8-bit characters, we will convert them down to 7
    * bits with a custom mapping table. Fortunately, Allegro comes with a
    * default custom mapping table which reduces Latin-1 and Extended-A
    * characters to 7 bits. We don't even need to call set_ucodepage()!
    */
   set_uformat(U_ASCII_CP);
   
   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();
   install_mouse();

   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound\n%s\n", allegro_error);
      install_sound(DIGI_NONE, MIDI_NONE, NULL);
   }

   if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
      allegro_message("Error initialising joystick\n%s\n", allegro_error);
      install_joystick(JOY_TYPE_NONE);
   }

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
         allegro_message("Unable to set any graphic mode\n%s\n",
                         allegro_error);
         return 1;
      }
   }

   get_executable_name(buf, sizeof(buf));
   replace_filename(buf2, buf, "demo.dat", sizeof(buf2));
   set_color_conversion(COLORCONV_NONE);
   data = load_datafile(buf2);
   if (!data) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s\n", buf2);
      exit(1);
   }

   if (!jumpstart) {
      intro_screen();
   }

   clear_bitmap(screen);
   set_gui_colors();
   set_mouse_sprite(NULL);

   if (!gfx_mode_select(&c, &w, &h))
      exit(1);

   if (pick_animation_type(&type) < 0)
      exit(1);

   init_display(c, w, h, type);

   generate_explosions();

   //stop_sample(data[INTRO_SPL].dat);

   clear_bitmap(screen);

   while (title_screen())
      play_game();

   destroy_display();

   destroy_explosions();

   stop_midi();

   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   end_title();

   unload_datafile(data);

   allegro_exit();

   return 0;
}
예제 #30
0
static void get_parameters(int argc, char** argv)
{
    char *p;
    char buffer[MAX_PATH];
    char *ini_filename;
    HANDLE module = GetModuleHandle(NULL); /* This might look strange, but we want the erl.ini 
					      that resides in the same dir as erl.exe, not 
					      an erl.ini in our directory */
    InitFile *inif;
    InitSection *inis;

    if (module == NULL) {
        error("Cannot GetModuleHandle()");
    }

    if (GetModuleFileName(module,buffer,MAX_PATH) == 0) {
        error("Could not GetModuleFileName");
    }

    ini_filename = replace_filename(buffer,INI_FILENAME);

    if ((inif = load_init_file(ini_filename)) == NULL) {
	/* Assume that the path is absolute and that
	   it does not contain any symbolic link */
	
	char buffer[MAX_PATH];
	
	/* Determine bindir */
	if (GetEnvironmentVariable("ERLEXEC_DIR", buffer, MAX_PATH) == 0) {
	    strcpy(buffer, ini_filename);
	    for (p = buffer+strlen(buffer)-1; p >= buffer && *p != '\\'; --p)
		;
	    *p ='\0';
	}
	bindir = path_massage(buffer);

	/* Determine rootdir */
	for (p = buffer+strlen(buffer)-1; p >= buffer && *p != '\\'; --p)
	    ;
	p--;
	for (;p >= buffer && *p != '\\'; --p)
	    ;
	*p ='\0';
	rootdir = path_massage(buffer);

	/* Hardcoded progname */
	progname = strsave(DEFAULT_PROGNAME);
    } else {
	if ((inis = lookup_init_section(inif,INI_SECTION)) == NULL) {
	    error("Could not find section %s in init file %s",
		  INI_SECTION, ini_filename);
	}

	bindir = do_lookup_in_section(inis, "Bindir", INI_SECTION, ini_filename,1);
	rootdir = do_lookup_in_section(inis, "Rootdir", INI_SECTION, 
				       ini_filename,1);
	progname = do_lookup_in_section(inis, "Progname", INI_SECTION, 
					ini_filename,0);
	free_init_file(inif);
    }

    emu = EMULATOR_EXECUTABLE;
    start_emulator_program = strsave(argv[0]);

    free(ini_filename);
}