int AddIMSList()
	{
#ifdef _WIN32
		HANDLE File_Hwnd;
		WIN32_FIND_DATAA wfd;

		std::wofstream outFile("midifile.list", std::ios::app);

		if (!outFile.good())
		{
			return NULL;
		}

		BOOL bResult = TRUE;

		File_Hwnd = FindFirstFileA(".\\assets\\*.mid", &wfd);
		if (((DWORD)(File_Hwnd)) == 0xffffffff)
			bResult = FALSE;
		else bResult = TRUE;

		int index = 0;
		while (bResult)
		{
			if ((FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) == 0)
			{
			
				m_mapMid.insert(std::make_pair(index, wfd.cFileName));
				index++;

				outFile << wfd.cFileName << '\n';
			}

			bResult = FindNextFileA(File_Hwnd, &wfd);
		}
		FindClose(File_Hwnd);
		outFile.close();
#else
		SDL_RWops* fp = 0;
		fp = SDL_RWFromFile("assets/midifile.list", "rb");

		if (fp == 0)
			return false;

		char tmp[256] = { 0, };
		int index = 0;
		while (SDL_RWgets(tmp, sizeof(tmp), fp))
		{
			
			trim(tmp);
			std::string str = tmp;
			m_mapMid.insert(std::make_pair(index, str.c_str()));
			index++;
		}
		SDL_RWclose(fp);
#endif
		return true;
	}
Beispiel #2
0
static bool parse_obj(const char *filename, ObjFileData *data) {
	SDL_RWops *rw = vfs_open(filename, VFS_MODE_READ);

	if(!rw) {
		log_error("VFS error: %s", vfs_get_error());
		return false;
	}

	char line[256], *save;
	vec3_noalign buf;
	char mode;
	int linen = 0;

	memset(data, 0, sizeof(ObjFileData));

	while(SDL_RWgets(rw, line, sizeof(line))) {
		linen++;

		char *first;
		first = strtok_r(line, " \n", &save);

		if(strcmp(first, "v") == 0)
			mode = 'v';
		else if(strcmp(first, "vt") == 0)
			mode = 't';
		else if(strcmp(first, "vn") == 0)
			mode = 'n';
		else if(strcmp(first, "f") == 0)
			mode = 'f';
		else
			mode = 0;

		if(mode != 0 && mode != 'f') {
			buf[0] = atof(strtok_r(NULL, " \n", &save));
			char *wtf = strtok_r(NULL, " \n", &save);
			buf[1] = atof(wtf);
			if(mode != 't')
				buf[2] = atof(strtok_r(NULL, " \n", &save));

			switch(mode) {
			case 'v':
				data->xs = realloc(data->xs, sizeof(vec3_noalign)*(++data->xcount));
				memcpy(data->xs[data->xcount-1], buf, sizeof(vec3_noalign));
				break;
			case 't':
				data->texcoords = realloc(data->texcoords, sizeof(vec3_noalign)*(++data->tcount));
				memcpy(data->texcoords[data->tcount-1], buf, sizeof(vec3_noalign));
				break;
			case 'n':
				data->normals = realloc(data->normals, sizeof(vec3_noalign)*(++data->ncount));
				memcpy(data->normals[data->ncount-1], buf, sizeof(vec3_noalign));
				break;
			}
		} else if(mode == 'f') {
			char *segment, *seg;
			int j = 0, jj;
			ivec3_noalign ibuf;
			memset(ibuf, 0, sizeof(ibuf));

			while((segment = strtok_r(NULL, " \n", &save))) {
				seg = segment;
				j++;

				jj = 0;
				while(jj < 3) {
					ibuf[jj] = atoi(seg);
					jj++;

					while(*seg != '\0' && *(++seg) != '/');

					if(*seg == '\0')
						break;
					else
						seg++;
				}

				if(strstr(segment, "//")) {
					ibuf[2] = ibuf[1];
					ibuf[1] = 0;
				}

				if(jj == 0 || jj > 3 || segment[0] == '/') {
					log_error("OBJ file '%s:%d': Parsing error: Corrupt face definition", filename, linen);
					goto fail;
				}

				data->indices = realloc(data->indices, sizeof(ivec3_noalign)*(++data->icount));
				memcpy(data->indices[data->icount-1], ibuf, sizeof(ivec3_noalign));
			}

			if(data->fverts == 0)
				data->fverts = j;

			if(data->fverts != j) {
				log_error("OBJ file '%s:%d': Parsing error: face vertex count must stay the same in the whole file", filename, linen);
				goto fail;
			}

			if(data->fverts != 3) {
				log_error("OBJ file '%s:%d': Parsing error: face vertex count must be 3", filename, linen);
				goto fail;
			}
		}
	}

	SDL_RWclose(rw);
	return true;

fail:
	SDL_RWclose(rw);
	free(data->indices);
	free(data->normals);
	free(data->xs);
	return false;
}
Beispiel #3
0
SWError SWLoadProperties_RW(SWPropertiesPtr properties, SDL_RWops *ops)
{
    char *key, *value, *semi, *s, *p;
    char *section = NULL;
    char line[80];
    SWError err = kNoError;
    
    if (properties != NULL && ops != NULL)
    {
         while(1)
        {
            key = SDL_RWgets(ops, line, sizeof(line));
            if (key == NULL)
                break;
            
            if (key[0] == '#' || line[0] == '/')
                continue;   // comments
  
            semi = strchr(key, ';');
            if (semi != NULL)
                *semi = '\0';   // comment
                
            if (key[0] == '[')  // sections
            {
                key++;
                s = line + strlen(line) - 1;
                while (isspace(*s) && s > key)
                    *s-- = '\0';
                if (*s == ']')
                {
                    *s-- = '\0';
                        // trim whitespace (section)
                    while (isspace(*key) && *key)
                        key++;
                    while (isspace(*s) && s > key)
                        *s-- = '\0';
                
                    if (section != NULL)
                        free(section);
                    section = local_strdup(key);
                    //fprintf(stderr, "SECTION: \"%s\"\n", section);
                    continue;
                }
            }

            value = strchr(line, '=');
            if (value != NULL)
            {
                *value++ = '\0';
            
                    // trim whitespace (key)
                while (isspace(*key) && *key)
                    key++;
                s = value - 2;
                while (isspace(*s) && s > key)
                    *s-- = '\0';
                if (s < key)
                    continue; // empty
                
                    // trim whitespace (value)
                while (isspace(*value) && *value)
                    value++;
                s = value + strlen(value) - 1;
                while (isspace(*s) && s > value)
                    *s-- = '\0';
                if (s < value)
                    continue;
        
                if (section == NULL)
                    err = SWSetPropertyString(properties, key, value);
                else
                {
                    p = malloc(strlen(section) + 1 + strlen(key) + 1);
                    if (p != NULL)
                    {
                        s = p;
                        *s = '\0';
                        strcat(s, section); s += strlen(section);
                        *s++ = '/';
                        *s = '\0';
                        strcat(s, key); s += strlen(key);
                        *s = '\0';
                    
                        err = SWSetPropertyString(properties, p, value);
                        free(p);
                    }
                }
                
                if (err)
                 return err;
            }
        }
    
        if (section != NULL)
           free(section);
                    
        SDL_RWclose(ops);
        return kNoError;
    }
    else
        return kUnknownError;
}
Beispiel #4
0
/* Load a XPM type image from an SDL datasource */
SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src)
{
	SDL_Surface *image;
	char line[1024];
	char *here;
	int index;
	int x, y;
	int w, h, ncolors, cpp;
	int pixels_len;
	char *pixels = NULL;
	int indexed;
	Uint8 *dst;
	struct color_hash *colors;
	SDL_Color *im_colors = NULL;
	char *keystrings, *nextkey;
	char *error = NULL;

	/* Skip to the first string, which describes the image */
	do {
	        here = SDL_RWgets(line, sizeof(line), src);
		if ( !here ) {
			IMG_SetError("Premature end of data");
			return(NULL);
		}
		here = skipspace(here);
	} while(*here != '"');
	/*
	 * The header string of an XPMv3 image has the format
	 *
	 * <width> <height> <ncolors> <cpp> [ <hotspot_x> <hotspot_y> ]
	 *
	 * where the hotspot coords are intended for mouse cursors.
	 * Right now we don't use the hotspots but it should be handled
	 * one day.
	 */
	if(sscanf(here + 1, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4
	   || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) {
		IMG_SetError("Invalid format description");
		return(NULL);
	}

	keystrings = malloc(ncolors * cpp);
	if(!keystrings) {
		IMG_SetError("Out of memory");
		free(pixels);
		return NULL;
	}
	nextkey = keystrings;

	/* Create the new surface */
	if(ncolors <= 256) {
		indexed = 1;
		image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8,
					     0, 0, 0, 0);
		im_colors = image->format->palette->colors;
		image->format->palette->ncolors = ncolors;
	} else {
		indexed = 0;
		image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
					     0xff0000, 0x00ff00, 0x0000ff, 0);
	}
	if(!image) {
		/* Hmm, some SDL error (out of memory?) */
		free(pixels);
		return(NULL);
	}

	/* Read the colors */
	colors = create_colorhash(ncolors);
	if ( ! colors ) {
		error = "Out of memory";
		goto done;
	}
	for(index = 0; index < ncolors; ++index ) {
		char *key;
		int len;

		do {
			here = SDL_RWgets(line, sizeof(line), src);
			if(!here) {
				error = "Premature end of data";
				goto done;
			}
			here = skipspace(here);
		} while(*here != '"');

		++here;
		len = strlen(here);
		if(len < cpp + 7)
			continue;	/* cannot be a valid line */

		key = here;
		key[cpp] = '\0';
		here += cpp + 1;

		/* parse a colour definition */
		for(;;) {
			char nametype;
			char *colname;
			char delim;
			Uint32 rgb;

			here = skipspace(here);
			nametype = *here;
			here = skipnonspace(here);
			here = skipspace(here);
			colname = here;
			while(*here && !isspace((unsigned char)*here)
			      && *here != '"')
				here++;
			if(!*here) {
				error = "color parse error";
				goto done;
			}
			if(nametype == 's')
				continue;      /* skip symbolic colour names */

			delim = *here;
			*here = '\0';
			if(delim)
			    here++;

			if(!color_to_rgb(colname, &rgb))
				continue;

			memcpy(nextkey, key, cpp);
			if(indexed) {
				SDL_Color *c = im_colors + index;
				c->r = rgb >> 16;
				c->g = rgb >> 8;
				c->b = rgb;
				add_colorhash(colors, nextkey, cpp, index);
			} else
				add_colorhash(colors, nextkey, cpp, rgb);
			nextkey += cpp;
			if(rgb == 0xffffffff)
				SDL_SetColorKey(image, SDL_SRCCOLORKEY,
						indexed ? index : rgb);
			break;
		}
	}