Example #1
0
OSL_MAP *oslCreateMap(OSL_IMAGE *img, void *map_data, int tileX, int tileY, int mapSizeX, int mapSizeY, int map_format)
{
	OSL_MAP *m;
	m = (OSL_MAP*)malloc(sizeof(OSL_MAP));
	if (!m)
		return NULL;
	if (map_format != OSL_MF_U16 && map_format != OSL_MF_U16_GBA)		{
		oslFatalError("Invalid map format");
		free(m);
		return NULL;
	}
	m->format = map_format;
	//For the GBA format, we set the number of tiles bits to 10 by default. You can increase it up to 14.
	if (map_format == OSL_MF_U16_GBA)
		m->addit1 = 10;

	//By default, the first tile is always transparent
	m->flags = OSL_MF_TILE1_TRANSPARENT;
	//Does the map satisfy criterias to be treated as simple (drawn faster)?
//	if (m->tileX == oslGetNextPower2(m->tileX) && m->tileY == oslGetNextPower2(m->tileY) && m->img->sizeX == oslGetNextPower2(m->img->sizeX))
//		m->flags |= OSL_MF_SIMPLE;

	m->img = img;
	m->map = map_data;
	m->tileX = tileX;
	m->tileY = tileY;
	m->mapSizeX = mapSizeX;
	m->mapSizeY = mapSizeY;
	m->scrollX = m->scrollY = 0;
	m->drawSizeX = -1;
	m->drawSizeY = -1;
	return m;
}
Example #2
0
MainMenuScreen::MainMenuScreen()
{
	gIsMultiplayer = false;
	menubg = oslLoadImageFilePNG(Resource::IMG_MAIN_MENU_BG, OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);

	if (!menubg)
		oslFatalError("At least one file is missing. Please copy all the file in the game directory.");
}
Example #3
0
void frame_factory_init(const char *tex_cfg_file)
{
    if (frame_cache != NULL) {
        return;
    }

    frame_cache = dictionary_new(0);
    if (frame_cache == NULL) {
        oslFatalError("Not enough memory! %s %d", __FILE__, __LINE__);
    }

    texture_cfg = iniparser_load(tex_cfg_file);
    if (texture_cfg == NULL) {
        oslFatalError("can't load texture config!");
    }

    printf("%s\n", iniparser_getstring(texture_cfg, "bg:f", "not found"));
    return;
}
Example #4
0
File: SMS.c Project: wally4000/code
//moment: -1 = avant, 0 = toujours, +1 = après
void MenuOptionsConfigure(int moment)		{
	static MENUPARAMS *m = NULL;
	if (moment == -1)		{
		if (!m)
			m = malloc(sizeof(*m));
		if (!m)
			oslFatalError("MenuOptionsConfigure#1: m == NULL");
		memcpy(m, &menuConfig, sizeof(*m));
	}
	else	{
		if (!m)
			oslFatalError("MenuOptionsConfigure#2: m == NULL");
		if (moment == 0 ||
			m->video.brightnessMode != menuConfig.video.brightnessMode ||
			m->video.gamma != menuConfig.video.gamma || m->video.vibrance != menuConfig.video.vibrance ||
			m->video.renderDepth != menuConfig.video.renderDepth)			{
			int i;

			if (gblMachineType == EM_SMS)
				bitmap.depth  = menuConfig.video.renderDepth;
			else if (gblMachineType == EM_GBC)
				bitmap.depth  = 16;
			bitmap.pitch  = 256 * bitmap.depth / 8;

			for (i=0;i<256;i++)			{
				if (menuConfig.video.brightnessMode == 1)
					//Bright & Fast
					pixel_values[i] = ((i * 232) >> 8) + 24;
				else if (menuConfig.video.brightnessMode == 3)
					//Invert
					pixel_values[i] = 255 - i;
				else
					//Normal
					pixel_values[i] = i;

				//Next: apply gamma correction
				if (menuConfig.video.gamma != 100)
					//Gamma
					pixel_values[i] = ((unsigned char)(255.0f * pow((pixel_values[i] / 255.0f), 1.0f/(((float)menuConfig.video.gamma) / 100.f)))) >> 3;
				else
					//For 15-bit mode
					pixel_values[i] >>= 3;
			}
Example #5
0
frame_t *frame_factory_get(const char *key)
{
    frame_t *frame;
    char *addr_str;
    // try to load frame using config from config cache
    static char key_buf[MAX_TEXTURE_NAME+4+1];
    static char addr_buff[16+1];
    char *file;
    int pf, loc;
    int namelen = strlen(key);

    if (frame_cache == NULL) {
        printf("frame factory not inited!\n");
        return NULL;
    }

    addr_str = dictionary_get(frame_cache, (char *)key, "0x0");
    frame = (frame_t *)(strtol(addr_str, NULL, 0));
    if (frame != 0) {
        return frame;
    }

    if (strlen(key) > MAX_TEXTURE_NAME) {
        oslFatalError("config key too long! %s", key);
    }
    strcpy(key_buf, key);

    strcat(key_buf, ":f");
    file = iniparser_getstring(texture_cfg, key_buf, NULL);
    printf("search key %s, value %s\n", key_buf, file);
    printf("texture cfg %p\n", texture_cfg);

    key_buf[namelen] = '\0';
    strcat(key_buf, ":pf");
    pf = iniparser_getint(texture_cfg, key_buf, OSL_IN_VRAM);

    key_buf[namelen] = '\0';
    strcat(key_buf, ":loc");
    loc = iniparser_getint(texture_cfg, key_buf, TAIKO_PF);

    printf("ok so far!\n");;
    frame = frame_create_simple(file, pf, loc);

    if (frame != NULL) {
        key_buf[namelen] = '\0';
        sprintf(addr_buff, "%d", (int)frame);
        dictionary_set(frame_cache, key_buf, addr_buff);
    }
    return frame;
}
Example #6
0
Tower::Tower(const string &towerName)
{
	//Default Initializers
	mTowerDirName = towerName;
	PspIO::lowerCase(mTowerDirName);

	mIsBuildable = true;
	mTowerName = NULL;
	mTowerDescription = NULL;
	mProjectileType = PT_Arrow;
	mHitsLand = false;
	mHitsFlyer = false;
	mTowerLength = 0;
	mMenuIcon = NULL;
	mTowerImg = NULL;
	mProjectileImg = NULL;
	mFireSound = NULL;
	mHitSound = NULL;

	char temp[256];
	sprintf(temp, "%s/Res/towers/%s/tower.xml", PspIO::getCurrentDirectory().c_str(), mTowerDirName.c_str());

	TiXmlDocument TowerXMLInput;
	TowerXMLInput.LoadFile(temp);

	if (TowerXMLInput.Error())
	{
		oslFatalError("Cannot open: %s", TowerXMLInput.ErrorDesc());
		return;
	}

	TiXmlElement *node = NULL;
	node = TowerXMLInput.FirstChildElement(); //head

	if (!node)
	{
		oslFatalError("No head node in: %s", temp);
		return;
	}

	node = node->FirstChildElement();

	while (node != NULL) //Read all XML file
	{
		string mCurrentLine = node->ValueStr();
		/*
		A função strdup() é usada em situações onde temos que alocar um espaço na memória para copiar determinada string.
		Sem utiliza-lá, teríamos que alocar o espaço antes com malloc(), para em seguida usar strncpy(), por exemplo, para copiar a string.
		A função retorna um ponteiro com a string já alocada (podendo ser liberado com free() depois de seu uso) em caso de sucesso,
		ou ENOMEM como erro caso a memória não tenha sida alocada por insuficiência.		
		*/
		if (mCurrentLine == "Name")
		{
			mTowerName = strdup(node->GetText());
		}
		else if (mCurrentLine == "Description")
		{
			mTowerDescription = strdup(node->GetText());
		}
		/*
		A função atoi() é usada para converter strings em números inteiros.
		*/
		else if (mCurrentLine == "TowerLength")
		{
			mTowerLength = atoi(node->GetText());
		}
		else if (mCurrentLine == "Capability")
		{
			const char* mAttributeText;

			mAttributeText = node->Attribute("HitsLand");
			if (mAttributeText != NULL && !strcmp(mAttributeText,"True")) //strcmp() return 0 if both string be the same.
			{
				mHitsLand = true;
			}

			mAttributeText = node->Attribute("HitsFlyers");
			if (mAttributeText != NULL && !strcmp(mAttributeText,"True")) //strcmp() return 0 if both string be the same.
			{
				mHitsFlyer = true;
			}
		}
		else if (mCurrentLine == "Projectile")
		{
			const char* ProjectileType = node->Attribute("Type");
			if (ProjectileType == NULL)
			{
				oslFatalError("No ProjectileType.");
				return;
			}
			//More Projectile Types goes here.
			if (!strcmp(ProjectileType, "Arrow"))
			{
				mProjectileType = PT_Arrow;
			}
			else if (!strcmp(ProjectileType, "Ice"))
			{
				mProjectileType = PT_Ice;
			}
			else if (!strcmp(ProjectileType, "Fire"))
			{
				mProjectileType = PT_Fire;
			}
			else if (!strcmp(ProjectileType, "Lightning"))
			{
				mProjectileType = PT_Lightning;
			}

			sprintf(temp, "/Res/towers/%s/%s", mTowerDirName.c_str(), node->Attribute("Sprite"));
			mProjectileImg = ProjectileInstance::LoadProjectileImage(mProjectileType, temp);
		}
		else if (mCurrentLine == "TowersLevels")
		{
			TiXmlElement *TowerLevelNode = node->FirstChildElement();
			while (TowerLevelNode != NULL) //read all Towers Levels
			{
				if (TowerLevelNode->ValueStr() != "TowersLevel")
				{
					oslFatalError("TowersLevel Error: %s",TowerLevelNode->Value());
					return;
				}
				mTowerVector.push_back(TowerInfo(TowerLevelNode)); //Insert a element in the end

				TowerLevelNode = TowerLevelNode->NextSiblingElement();
			}
		}
		else if (mCurrentLine == "TowerImg")
		{
			sprintf(temp, "/Res/towers/%s/%s", mTowerDirName.c_str(), node->Attribute("File"));
			mTowerImg = oslLoadImageFilePNG(temp, OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);

			mTowerImg->centerX = (mTowerImg->sizeX/2); //hotspot
			mTowerImg->centerY = (mTowerImg->sizeY/2); //hotspot

			node->QueryIntAttribute("Width", &mTowerWidth);
			node->QueryIntAttribute("Height", &mTowerHeight);
		}
		else if (mCurrentLine == "MenuIcon")
		{
			sprintf(temp, "/Res/towers/%s/%s", mTowerDirName.c_str(), node->Attribute("File"));
			mMenuIcon = oslLoadImageFilePNG(temp, OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
		}
		else if (mCurrentLine == "FireSound")
		{
			sprintf(temp, "/Res/towers/%s/%s", mTowerDirName.c_str(), node->Attribute("File"));
			mFireSound = oslLoadSoundFileWAV (temp, OSL_FMT_NONE);
		}
		else if (mCurrentLine == "HitSound")
		{
			sprintf(temp, "/Res/towers/%s/%s", mTowerDirName.c_str(), node->Attribute("File"));
			mHitSound = oslLoadSoundFileWAV (temp, OSL_FMT_NONE);
		}
		else
		{
			oslFatalError("Bad node, not donout for you: %s",mCurrentLine.c_str());
			return;
		}
		node = node->NextSiblingElement();
	}
}