Пример #1
0
bool WCachedParticles::Attempt(const string& filename, int submode, int & error)
{

    JFileSystem* fileSys = JFileSystem::GetInstance();

    if (!fileSys->OpenFile(WResourceManager::Instance()->graphicsFile(filename)))
    {
        error = CACHE_ERROR_404;
        return false;
    }

    SAFE_DELETE(particles);

    particles = NEW hgeParticleSystemInfo;
    // We Skip reading the pointer as it may be larger than 4 bytes in the structure
    void *dummyPointer;
    fileSys->ReadFile(&dummyPointer, 4);
    // we're actually trying to read more than the file size now, but it's no problem.
    // Note that this fix is only to avoid the largest problems, filling a structure
    // by directly reading a file, is really a bad idea ...
    fileSys->ReadFile(&(particles->nEmission), sizeof(hgeParticleSystemInfo) - sizeof(void*));
    fileSys->CloseFile();

    particles->sprite = NULL;
    error = CACHE_ERROR_NONE;
    return true;
}
Пример #2
0
bool JSpline::Load(const char *filename, float xscale, float yscale)
{
	JFileSystem *fileSystem = JFileSystem::GetInstance();

	if (fileSystem == NULL) return false;
	if (!fileSystem->OpenFile(filename)) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	mCount = 0;

	mMidPoints.clear();
	mPixels.clear();


	TiXmlNode* node = 0;
	//TiXmlElement* todoElement = 0;
	TiXmlElement* element;

	node = doc.RootElement();

	float xx, yy;

	for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
	{
		xx = 0.0f;
		yy = 0.0f;
		element->QueryFloatAttribute("x", &xx);
		element->QueryFloatAttribute("y", &yy);

		Point pt(xx*xscale, yy*yscale);
		AddControlPoint(pt);
		
	}

	fileSystem->CloseFile();
	delete[] xmlBuffer;

	return true;
}
Пример #3
0
bool JResourceManager::LoadResource(const string& resourceName)
{
	string path = /*mResourceRoot + */resourceName;

//	TiXmlDocument doc(path.c_str());
//	
//	if (!doc.LoadFile()) return false;
	
	JGE *engine = JGE::GetInstance();
	if (engine == NULL) return false;

	JFileSystem *fileSystem = JFileSystem::GetInstance();
	if (fileSystem == NULL) return false;

	if (!fileSystem->OpenFile(path.c_str())) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	TiXmlNode* resource = 0;
	TiXmlNode* node = 0;
	TiXmlElement* element = 0;

	resource = doc.FirstChild("resource"); 
	if (resource)
	{
		element = resource->ToElement();
		printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

		for (node = resource->FirstChild(); node; node = node->NextSibling())
		{
			element = node->ToElement();
			if (element != NULL)
			{
				if (strcmp(element->Value(), "texture")==0)
				{
					CreateTexture(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "quad")==0)
				{
					string quadName = element->Attribute("name");
					string textureName = element->Attribute("texture");
					float x = 0.0f;
					float y = 0.0f;
					float width = 16.0f;
					float height = 16.0f;
					float value;
					float hotspotX = 0.0f;
					float hotspotY = 0.0f;
					
					if (element->QueryFloatAttribute("x", &value) == TIXML_SUCCESS)
						x = value;
					
					if (element->QueryFloatAttribute("y", &value) == TIXML_SUCCESS)
						y = value;

					if (element->QueryFloatAttribute("width", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("height", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("w", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("h", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("hotspot.x", &value) == TIXML_SUCCESS)
						hotspotX = value;
					else
						hotspotX = width/2;

					if (element->QueryFloatAttribute("hotspot.y", &value) == TIXML_SUCCESS)
						hotspotY = value;
					else
						hotspotY = height/2;

// 					if (element->QueryFloatAttribute("regx", &value) == TIXML_SUCCESS)
// 						hotspotX = width/2;
// 
// 					if (element->QueryFloatAttribute("regy", &value) == TIXML_SUCCESS)
// 						hotspotY = height/2;
				
					int id = CreateQuad(quadName, textureName, x, y, width, height);
					if (id != INVALID_ID)
					{
						GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
					}
				}
				else if (strcmp(element->Value(), "font")==0)
				{
				}
				else if (strcmp(element->Value(), "music")==0)
				{
					LoadMusic(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "sample")==0)
				{
					LoadSample(element->Attribute("name"));
				}
// 				else if (strcmp(element->Value(), "effect")==0)
// 				{
// 					RegisterParticleEffect(element->Attribute("name"));
// 				}
// 				else if (strcmp(element->Value(), "motion_emitter")==0)
// 				{
// 					RegisterMotionEmitter(element->Attribute("name"));
// 				}
			}
		}
		
	}
	
	fileSystem->CloseFile();
	delete[] xmlBuffer;
//	JGERelease();

	return true;
}
Пример #4
0
void GameApp::Create()
{
    srand((unsigned int) time(0)); // initialize random
#if !defined(QT_CONFIG) && !defined(IOS)
#if defined (WIN32)
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#elif defined (PSP)
    pspFpuSetEnable(0); //disable FPU Exceptions until we find where the FPU errors come from
    pspDebugScreenPrintf("Wagic:Loading resources...");
#endif
#endif //QT_CONFIG
    //_CrtSetBreakAlloc(368);
    LOG("starting Game");

    string systemFolder = "Res/";
    string foldersRoot = "";

    //Find the Res folder
    ifstream mfile("Res.txt");
    string resPath;
    if (mfile)
    {
        bool found = false;
        while (!found && std::getline(mfile, resPath))
        {
            if (resPath[resPath.size() - 1] == '\r')
                resPath.erase(resPath.size() - 1); //Handle DOS files
            string testfile = resPath + systemFolder;
            testfile.append("graphics/simon.dat");
            ifstream tempfile(testfile.c_str());
            if (tempfile)
            {
                found = true;
                tempfile.close();
                foldersRoot = resPath;
            }
        }
        mfile.close();
    }
    LOG("init Res Folder at " + foldersRoot);
    JFileSystem::init(foldersRoot + "User/", foldersRoot + systemFolder);

    
    // Create User Folders (for write access) if they don't exist
    {
        const char* folders[] = { "ai", "ai/baka", "ai/baka/stats", "campaigns", "graphics", "lang", "packs", "player", "player/stats", "profiles", "rules", "sets", "settings", "sound", "sound/sfx", "themes", "test"};

        for (size_t i = 0; i < sizeof(folders)/sizeof(folders[0]); ++i)
        {
            JFileSystem::GetInstance()->MakeDir(string(folders[i]));
        }
    }

    LOG("Loading Modrules");
    //Load Mod Rules before everything else
    gModRules.load("rules/modrules.xml");

    LOG("Loading Unlockables");
    //Load awards (needs to be loaded before any option are accessed)
    Unlockable::load();

    //Link this to our settings manager.
    options.theGame = this;

    //Ensure that options are partially loaded before loading files.
    LOG("options.reloadProfile()");
    options.reloadProfile();


    //Setup Cache before calling any gfx/sfx functions
	WResourceManager::Instance()->ResetCacheLimits();


    LOG("Checking for music files");
    //Test for Music files presence
    JFileSystem * jfs = JFileSystem::GetInstance();
    HasMusic = jfs->FileExists(WResourceManager::Instance()->musicFile("Track0.mp3")) && jfs->FileExists(WResourceManager::Instance()->musicFile("Track1.mp3"));
    
    LOG("Init Collection");
    MTGAllCards::getInstance();

    LOG("Loading rules");
    Rules::loadAllRules();


    LOG("Loading Textures");
    LOG("--Loading menuicons.png");
    WResourceManager::Instance()->RetrieveTexture("menuicons.png", RETRIEVE_MANAGE);
#if !defined (PSP)
    WResourceManager::Instance()->RetrieveTexture("miconslarge.png", RETRIEVE_MANAGE);
#endif
    LOG("---Gettings menuicons.png quads");
   
    //Load all icons from gModRules and save in manaIcons -> todo. Change the icons positions on menuicons.png to avoid use item->mColorId
    vector<ModRulesBackGroundCardGuiItem *>items = gModRules.cardgui.background;
    for(size_t i= 0; i < items.size(); i ++)
    {
        
        ModRulesBackGroundCardGuiItem * item = items[i];
        if (item->mMenuIcon == 1)
        {
            manaIcons.push_back(WResourceManager::Instance()->RetrieveQuad("menuicons.png", 2 + (float)item->mColorId * 36, 38, 32, 32, "c_" + item->MColorName, RETRIEVE_MANAGE));
            Constants::MTGColorStrings.push_back(item->MColorName.c_str());
        }
    }
    Constants::NB_Colors = (int)Constants::MTGColorStrings.size();
    
    items.erase(items.begin(),items.end());
    

    for (int i = manaIcons.size()-1; i >= 0; --i)
        if (manaIcons[i].get())
            manaIcons[i]->SetHotSpot(16, 16);

    LOG("--Loading back.jpg");
    WResourceManager::Instance()->RetrieveTexture("back.jpg", RETRIEVE_MANAGE);
    JQuadPtr jq = WResourceManager::Instance()->RetrieveQuad("back.jpg", 0, 0, 0, 0, kGenericCardID, RETRIEVE_MANAGE);
    if (jq.get())
        jq->SetHotSpot(jq->mWidth / 2, jq->mHeight / 2);

    WResourceManager::Instance()->RetrieveTexture("back_thumb.jpg", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveQuad("back_thumb.jpg", 0, 0, MTG_MINIIMAGE_WIDTH, MTG_MINIIMAGE_HEIGHT, kGenericCardThumbnailID, RETRIEVE_MANAGE);

    LOG("--Loading particles.png");
    WResourceManager::Instance()->RetrieveTexture("particles.png", RETRIEVE_MANAGE);
    jq = WResourceManager::Instance()->RetrieveQuad("particles.png", 0, 0, 32, 32, "particles", RETRIEVE_MANAGE);
    if (jq)
        jq->SetHotSpot(16, 16);
    jq = WResourceManager::Instance()->RetrieveQuad("particles.png", 64, 0, 32, 32, "stars", RETRIEVE_MANAGE);
    if (jq)
        jq->SetHotSpot(16, 16);

    LOG("--Loading fonts");
    string lang = options[Options::LANG].str;
    std::transform(lang.begin(), lang.end(), lang.begin(), ::tolower);
    WResourceManager::Instance()->InitFonts(lang);
    Translator::GetInstance()->init();
    // The translator is ready now.

    LOG("--Loading various textures");
    // Load in this function only textures that are used frequently throughout the game. These textures will constantly stay in Ram, so be frugal
    WResourceManager::Instance()->RetrieveTexture("phasebar.png", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("wood.png", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("gold.png", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("goldglow.png", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("backdrop.jpg", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("handback.png", RETRIEVE_MANAGE);
    WResourceManager::Instance()->RetrieveTexture("shadows.png", RETRIEVE_MANAGE);

    jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 2, 2, 16, 16, "white", RETRIEVE_MANAGE);
    if (jq)
        jq->SetHotSpot(8, 8);
    jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 20, 2, 16, 16, "shadow", RETRIEVE_MANAGE);
    if (jq)
        jq->SetHotSpot(8, 8);
    jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 38, 2, 16, 16, "extracostshadow", RETRIEVE_MANAGE);
    if (jq)
        jq->SetHotSpot(8, 8);

    jq = WResourceManager::Instance()->RetrieveQuad("phasebar.png", 0, 0, 0, 0, "phasebar", RETRIEVE_MANAGE);



    LOG("Creating Game States");
    mGameStates[GAME_STATE_DECK_VIEWER] = NEW GameStateDeckViewer(this);
    mGameStates[GAME_STATE_DECK_VIEWER]->Create();

    mGameStates[GAME_STATE_MENU] = NEW GameStateMenu(this);
    mGameStates[GAME_STATE_MENU]->Create();

    mGameStates[GAME_STATE_DUEL] = NEW GameStateDuel(this);
    mGameStates[GAME_STATE_DUEL]->Create();

    mGameStates[GAME_STATE_SHOP] = NEW GameStateShop(this);
    mGameStates[GAME_STATE_SHOP]->Create();

    mGameStates[GAME_STATE_OPTIONS] = NEW GameStateOptions(this);
    mGameStates[GAME_STATE_OPTIONS]->Create();

    mGameStates[GAME_STATE_AWARDS] = NEW GameStateAwards(this);
    mGameStates[GAME_STATE_AWARDS]->Create();

    mGameStates[GAME_STATE_STORY] = NEW GameStateStory(this);
    mGameStates[GAME_STATE_STORY]->Create();

    mGameStates[GAME_STATE_TRANSITION] = NULL;

    mCurrentState = NULL;
    mNextState = mGameStates[GAME_STATE_MENU];

    //Set Audio volume
    JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
    JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);

    DebugTrace("size of MTGCardInstance: " << sizeof(MTGCardInstance));
    DebugTrace("size of MTGCard: "<< sizeof(MTGCard));
    DebugTrace("size of CardPrimitive: "<< sizeof(CardPrimitive));
    DebugTrace("size of ExtraCost: " << sizeof(ExtraCost));
    DebugTrace("size of ManaCost: " << sizeof(ManaCost));

    LOG("Game Creation Done.");
}
Пример #5
0
bool JGBKFont::Init(const char* engFileName, const char* chnFileName, int fontsize, bool smallEnglishFont)
{
	mSmallEnglishFont = smallEnglishFont;
	mFontSize = fontsize;

	mCacheImageWidth = 256;
	mCacheImageHeight = 256;

	mBytesPerRow = (mFontSize+7)/8;
	mBytesPerChar = mBytesPerRow*mFontSize;

	mCol = mCacheImageWidth/mFontSize;
	mRow = mCacheImageHeight/mFontSize;
	mCacheSize = mCol*mRow;

	mSprites = new JQuad*[mCacheSize];
	mGBCode = new int[mCacheSize];

#if defined (WIN32) || defined (LINUX)
	mCharBuffer = new DWORD[mFontSize*mFontSize];
#endif

	mTexture = mRenderer->CreateTexture(mCacheImageWidth, mCacheImageHeight, true);

	int index = 0;
	for (int y=0;y<mRow;y++)
	{
		for (int x=0;x<mCol;x++)
		{
			mGBCode[index] = -1;

			mSprites[index] = new JQuad(mTexture, 
                                        static_cast<float>(x*mFontSize),
                                        static_cast<float>(y*mFontSize),
                                        static_cast<float>(mFontSize),
                                        static_cast<float>(mFontSize));
			mSprites[index]->SetHotSpot(static_cast<float>(mFontSize/2), static_cast<float>(mFontSize/2));

			index++;
		}
	}

	int size;

	JFileSystem *fileSys = JFileSystem::GetInstance();
	if (!fileSys->OpenFile(engFileName))
		return false;

	size = fileSys->GetFileSize();
	mEngFont = new BYTE[size];

	fileSys->ReadFile(mEngFont, size);
	fileSys->CloseFile();


	if (!fileSys->OpenFile(chnFileName))
		return false;

	size = fileSys->GetFileSize();

	mChnFont = new BYTE[size];

	fileSys->ReadFile(mChnFont, size);
	fileSys->CloseFile();

	return true;
}
Пример #6
0
bool JParticleEffect::Load(const char* filename)
{
	mX = 0.0f;
	mY = 0.0f;

	mEmitterCount = 0;


	JFileSystem *fileSystem = JFileSystem::GetInstance();
	if (fileSystem == NULL) return false;

	if (!fileSystem->OpenFile(filename)) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	
	doc.Parse(xmlBuffer);

	
	TiXmlNode* effect = 0;
	TiXmlNode* emitter = 0;
	TiXmlNode* param = 0;
	TiXmlNode* key = 0;
	
	TiXmlElement* element = 0;

	float keyTime;
	float value;
	float baseValue;
	int int_value;
// 	
// 	enum ParticleField
// 	{
// 		FIELD_SPEED,
// 		FIELD_SIZE,
// 		FIELD_ROTATION,
// 		FIELD_ALPHA,
// 		FIELD_RED,
// 		FIELD_GREEN,
// 		FIELD_BLUE,
// 		FIELD_COUNT
// 	};

	char* lifeValues[] =
	{
		"speed",
		"size",
		"rotation",
		"alpha",
		"red",
		"green",
		"blue",
		"radial_accel",
		"tangential_accel",
		"gravity"
	};

	char* typeNames[] =
	{
		"POINT",
		"AREA",
		"HORIZONTAL",
		"VERTICAL",
		"CIRCLE"
	};

	char* modeNames[] =
	{
		"REPEAT",
		"ONCE",
		"NTIMES",
		"CONTINUOUS"
	};

	int i;
	
	//////////////////////////////////////////////////////////////////////////
	// One effect per file only, well, we may extend it later to permit 
	// multiple effect definitions:
	//
	// for (effect = doc.FirstChild("effect"); effect; effect  = effect->NextSibling())
	// 
	//////////////////////////////////////////////////////////////////////////

	effect = doc.FirstChild("effect"); 
	if (effect)
	{
		element = effect->ToElement();
		printf("%s:%s\n", element->Value(), element->Attribute("name"));


		for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
		{

			mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
			element = emitter->ToElement();

			if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
				mParticleEmitters[mEmitterCount]->mLife = value;

			for (param = emitter->FirstChild(); param; param = param->NextSibling())
			{
				element = param->ToElement();
				
				if (strcmp(element->Attribute("name"), "settings")==0)
				{
					
					if (strcmp(element->Attribute("blend"), "NORMAL")==0)
						mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
					else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
						mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
					
					for (i=0;i<sizeof(modeNames)/sizeof(char*);i++)
					{
						if (strcmp(element->Attribute("mode"), modeNames[i])==0)
						{
							mParticleEmitters[mEmitterCount]->mEmitterMode = i;
							#if defined (_DEBUG)
								printf("emitter mode:%s\n", modeNames[i]);
							#endif
							break;
						}
					}
					for (i=0;i<sizeof(typeNames)/sizeof(char*);i++)
					{
						if (strcmp(element->Attribute("type"), typeNames[i])==0)
						{
							mParticleEmitters[mEmitterCount]->mType = i;
							#if defined (_DEBUG)
								printf("emitter type:%s\n", typeNames[i]);
							#endif
							break;
						}
					}

					string quadName = element->Attribute("image");
					JQuad* quad = mResourceManager->GetQuad(quadName);
					if (quad != NULL)
						mParticleEmitters[mEmitterCount]->SetQuad(quad);
					
// 					if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
// 					{
// 						mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
// 
// 					}
					if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mWidth = int_value;

					}
					if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mHeight = int_value;

					}

					if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mId = int_value;

					}

					if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;

					}
				}
				else if (strcmp(element->Attribute("name"), "quantity")==0)
				{
					for (key = param->FirstChild(); key; key = key->NextSibling())
					{
						element = key->ToElement();

						if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
							element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
						{
							mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
						}
						
					}
				}
				else if (strcmp(element->Attribute("name"), "lifex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
						mParticleEmitters[mEmitterCount]->mLifeMax= value;	
					}
				}
				else if (strcmp(element->Attribute("name"), "anglex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
						mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;	
					}
				}
				else if (strcmp(element->Attribute("name"), "speedx")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
						mParticleEmitters[mEmitterCount]->mSpeedMax= value;	
					}
				}
				else if (strcmp(element->Attribute("name"), "sizex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
						mParticleEmitters[mEmitterCount]->mSizeMax= value;	
					}
				}
				else 
				{
					for (int i=0;i<FIELD_COUNT;i++)
					{
						if (strcmp(element->Attribute("name"), lifeValues[i])==0)
						{
							for (key = param->FirstChild(); key; key = key->NextSibling())
							{
								element = key->ToElement();

								if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
									element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
								{
									if (i==FIELD_ROTATION)
										value *= DEG2RAD;
									
									mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
								}

							}
							break;
						}
					}

				}


			}

			mEmitterCount++;
		}
	}

	fileSystem->CloseFile();
	delete[] xmlBuffer;

	return true;
}
Пример #7
0
string ResourceManagerImpl::cardFile(const string& filename)
{
    char buf[512];
    string::size_type i = 0;
    string set;
    JFileSystem* fs = JFileSystem::GetInstance();

    //Check the theme folder.
    string theme = options[Options::ACTIVE_THEME].str;

    if (theme != "" && theme != "Default")
    {
        //Does this theme use custom cards?
        if (bThemedCards)
        {
            //Check zipped first. Discover set name.
            for (i = 0; i < filename.size(); i++)
            {
                if (filename[i] == '\\' || filename[i] == '/') break;
            }

            if (i != filename.size()) set = filename.substr(0, i);

            if (set.size())
            {
                char zipname[512];
                sprintf(zipname, "themes/%s/sets/%s/%s.zip", theme.c_str(), set.c_str(), set.c_str());
                if (fs->AttachZipFile(zipname)) return filename.substr(i + 1);
            }

            sprintf(buf, "themes/%s/sets/%s", theme.c_str(), filename.c_str());
            if (fileOK(buf)) return buf; //Themed, unzipped.
        }
    }

    //FIXME Put back when we're using modes.
    /*
    //Failure. Check mode
    string mode = options[Options::ACTIVE_MODE].str;

    if(mode != "" && mode != "Default"){
    sprintf(buf,"modes/%s/sets/%s",mode.c_str(),filename.c_str());
    if(fileOK(buf,true))
    return buf;
    }
    */
    //Failure. Assume it's in a zip file?
    if (!set.size())
    {   //Didn't fill "set" string, so do it now.
        for (i = 0; i < filename.size(); i++)
        {
            if (filename[i] == '\\' || filename[i] == '/') break;
        }

        if (i != filename.size()) set = filename.substr(0, i);
    }

    if (set.size())
    {
        char zipname[512];
        sprintf(zipname, "sets/%s/%s.zip", set.c_str(), set.c_str());
        if (fs->AttachZipFile(zipname)) return filename.substr(i + 1);
    }

    //Failure. Check for unzipped file in sets
    char defdir[512];
    sprintf(defdir, "sets/%s", filename.c_str());
    if (fileOK(defdir)) return defdir;

    //Complete failure.
    return "";
}
Пример #8
0
bool JOBJModel::Load(const char *modelName, const char *textureName)
{

	JFileSystem* fileSys = JFileSystem::GetInstance();
	if (!fileSys->OpenFile(modelName))
		return false;

	int size = fileSys->GetFileSize();
	char *buffer = new char[size];

	fileSys->ReadFile(buffer, size);
	fileSys->CloseFile();

	Vector3D vert;

	vector<Face> faceList;
	vector<Vector3D> normalList;
	vector<Vector3D> texList;
	vector<Vector3D> vertList;

	normalList.reserve(32);
	texList.reserve(32);
	vertList.reserve(32);
	faceList.reserve(32);

	int filePtr = 0;

	char tmpLine[256];
	char s1[256];
	
	int count;

    while (filePtr < size)
    {
		filePtr = ReadLine(tmpLine, buffer, filePtr, size);
        {

			if ((tmpLine[0] == '#') || (strlen(tmpLine)  < 3))
			{
			}
			else if (tmpLine[0] == 'v')
			{
				count = sscanf(tmpLine, "%s  %f %f %f", s1, &vert.x, &vert.y, &vert.z);

				if (count == 4)
				{
					if (strcmp(s1, "vn") == 0)
						normalList.push_back(vert);
					else if (strcmp(s1, "vt") == 0)
						texList.push_back(vert);
					else if (strcmp(s1, "v") == 0)
						vertList.push_back(vert);
				}
				else if (count == 3)
				{
					if (strcmp(s1, "vt") == 0)
						texList.push_back(vert);
				}
	             
			}
			else if (tmpLine[0] == 'f')
			{
				Face face;
				face.mVertCount = 0;

				char *p = strchr(tmpLine, ' ');
				char *pNext = p;

				int vertIdx, texIdx, norIdx;
				
				while (p != NULL)
				{
					while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
						++p;
					strcpy(s1, p);
					count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
					if (count == 3)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = texIdx - 1;
							face.mNormalIdx[face.mVertCount] = norIdx - 1;
							face.mVertCount++;
						}
					}
					else if (count == 2)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = texIdx - 1;
							face.mNormalIdx[face.mVertCount] = 0;
							face.mVertCount++;
						}
					}
					else if (count == 1)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = 0;
							face.mNormalIdx[face.mVertCount] = 0;
							face.mVertCount++;
						}
					}
					
					pNext = strchr(p, ' ');
					p = pNext;
				}
			
				if (face.mVertCount == 3)		// we do triangles only ;)
					faceList.push_back(face);
			}
			else if (tmpLine[0] == 'g')
			{
				
			}
			else if (tmpLine[0] == 'u')
			{
			}

		}
	}

	mPolycount = faceList.size();
	mPolygons = new Vertex3D[mPolycount*3];

	int idx = 0;
	for (int i=0;i<mPolycount;i++)
	{
		
		for (int j=0;j<3;j++)
		{
			mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
			mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
			mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
			mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
			mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
			idx++;
		}
		
		/*
		mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
		idx++;
		mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
		idx++;
		mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
		idx++;
		*/
	}
   

	if (textureName != NULL)
		mTexture = JRenderer::GetInstance()->LoadTexture(textureName);

    return true;

}
Пример #9
0
JLBFont::JLBFont(const char *fontname, int lineheight, bool useVideoRAM)
{
	mRenderer = JRenderer::GetInstance();
	 
	mHeight = 0;
	mScale = 1.0f;
	mRotation = mSpacing = 0.0f;
	mTracking = 0.0f;
	mColor = ARGB(255,255,255,255);

	mTexture = NULL;
	mQuad = NULL;
	mBase = 0;
	
	char filename[256];
	short buffer[1024];
	 
      
	sprintf(filename, "%s.dat", fontname);
	 
	//FILE *file;
	JFileSystem *fileSys = JFileSystem::GetInstance();
	if (!fileSys->OpenFile(filename)) return;

	fileSys->ReadFile((u8 *)buffer, 2048);
	fileSys->CloseFile();
 	
    sprintf(filename, "%s.png", fontname);
	mTexture = mRenderer->LoadTexture(filename, useVideoRAM);

	if (mTexture == NULL) return;
	
	mHeight = (float) lineheight;
	
	mQuad = new JQuad(mTexture, 0.0f, 0.0f, 16.0f, mHeight);

	float a, b, c;

    float y = 0.0f;
	float x;

	// there are 16x16 characters in the texture map.
	float cellHeight = mTexture->mHeight/16.0f;
	
	int n = 0;
	for (int i=0;i<16;i++)
	{
		for (int j=0;j<16;j++)
		{
			x = (float)buffer[n*4];			// x offset
			a = (float)buffer[n*4+1];		// character width
			b = (float)buffer[n*4+2];
			c = (float)buffer[n*4+3];
		  
			mXPos[n] = x;
			mYPos[n] = y;
			mCharWidth[n] = a+b+c;

			n++;
		}

		y += cellHeight;
	}
      
}
Пример #10
0
bool JAnimator::Load(const char* scriptFile)
{

    JFileSystem *fileSystem = JFileSystem::GetInstance();
    if (fileSystem == NULL) return false;

    if (!fileSystem->OpenFile(scriptFile)) return false;

    int size = fileSystem->GetFileSize();
    char *xmlBuffer = new char[size];
    fileSystem->ReadFile(xmlBuffer, size);

    TiXmlDocument doc;
    doc.Parse(xmlBuffer);

    TiXmlNode* script = 0;
    TiXmlNode* frame = 0;
    TiXmlNode* obj = 0;
    TiXmlNode* param = 0;
    TiXmlElement* element = 0;

    float defaultTime = 0.033f;

    script = doc.FirstChild("script");
    if (script)
    {
        element = script->ToElement();
        printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

        char *type[] =
        {
            "ANIMATION_TYPE_LOOPING",
            "ANIMATION_TYPE_ONCE_AND_STAY",
            "ANIMATION_TYPE_ONCE_AND_BACK",
            "ANIMATION_TYPE_ONCE_AND_GONE",
            "ANIMATION_TYPE_PINGPONG"
        };

        const char* aniType = element->Attribute("type");
        for (int i=0; i<5; i++)
            if (strcmp(type[i], aniType)==0)
            {
                SetAnimationType(i);
                break;
            }

        float fps;
        if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
            fps = 30.0f;

        defaultTime = 1/fps;

        for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
        {
            JAnimatorFrame *aniFrame = new JAnimatorFrame(this);

            float duration;
            element = frame->ToElement();
            if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
                duration = defaultTime;
            aniFrame->SetFrameTime(duration);

            for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
            {
                for (param = obj->FirstChild(); param; param = param->NextSibling())
                {

                    element = param->ToElement();
                    if (element != NULL)
                    {
                        if (strcmp(element->Value(), "settings")==0)
                        {
                            const char* quadName = element->Attribute("quad");
                            JQuad* quad = mResource->GetQuad(quadName);

                            float x, y;
                            float vsize, hsize;
                            float angle;
                            int a, r, g, b;
                            int value;
                            bool flipped = false;

                            if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
                                x = 0.0f;

                            if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
                                y = 0.0f;

                            if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
                                hsize = 1.0f;

                            if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
                                vsize = 1.0f;

                            if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
                                angle = 0.0f;

                            if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
                                a = 255;

                            if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
                                r = 255;

                            if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
                                g = 255;

                            if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
                                b = 255;

                            if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
                                flipped = (value==1);


                            JAnimatorObject *object = new JAnimatorObject();
                            object->SetQuad(quad);
                            object->SetPosition(x, y);
                            object->SetHScale(hsize);
                            object->SetVScale(vsize);
                            object->SetRotation(angle);
                            object->SetColor(ARGB(a,r,g,b));
                            object->SetFlip(flipped);

                            aniFrame->AddObject(object);

                        }
                    }
                }

            }

            mFrames.push_back(aniFrame);
        }

    }

    fileSystem->CloseFile();
    delete[] xmlBuffer;

    return true;

}
Пример #11
0
//-------------------------------------------------------------------------------------------------
// loads MD2 model
bool JMD2Model::Load(char *filename, char *textureName)
{

	//FILE *filePtr;						// file pointer
	int fileLen;						// length of model file
    char *buffer;						// file buffer
		
	modelHeader_t *modelHeader;			// model header

	stIndex_t *stPtr;					// texture data
    frame_t *frame;						// frame data
	Vector3D *pointListPtr;				// index variable
    mesh_t *triIndex, *bufIndexPtr;		// index variables
    int i, j;							// index variables

	// open the model file

	JFileSystem* fileSystem = JFileSystem::GetInstance();
	if (!fileSystem->OpenFile(filename))
		return false;
	//filePtr = fopen(filename, "rb");
	//if (filePtr == NULL)
	//	return false;

	// find length of file
    //fseek(filePtr, 0, SEEK_END);
    //fileLen = ftell(filePtr);
    //fseek(filePtr, 0, SEEK_SET);

	fileLen = fileSystem->GetFileSize();
	
    // read entire file into buffer
    buffer = (char*)malloc(fileLen + 1);
    //fread(buffer, sizeof(char), fileLen, filePtr);
	fileSystem->ReadFile(buffer, fileLen);
	fileSystem->CloseFile();

	// extract model file header from buffer
    modelHeader = (modelHeader_t*)buffer;

	// allocate memory for model data
   	mModel = (modelData_t*)malloc(sizeof(modelData_t));
	if (mModel == NULL)
		return false;

	// allocate memory for all vertices used in model, including animations
    mModel->pointList = (Vector3D *)malloc(sizeof(Vector3D)*modelHeader->numXYZ * modelHeader->numFrames);

	// store vital model data
    mModel->numPoints = modelHeader->numXYZ;
    mModel->numFrames = modelHeader->numFrames;
	mModel->frameSize = modelHeader->framesize;

    // loop number of frames in model file
    for(j = 0; j < modelHeader->numFrames; j++)
    {
       // offset to the points in this frame
       frame = (frame_t*)&buffer[modelHeader->offsetFrames + modelHeader->framesize * j];

	   // calculate the point positions based on frame details
       pointListPtr = (Vector3D *)&mModel->pointList[modelHeader->numXYZ * j];
       for(i = 0; i < modelHeader->numXYZ; i++)
       {
          pointListPtr[i].x = frame->scale[0] * frame->fp[i].v[0] + frame->translate[0];
          pointListPtr[i].y = frame->scale[1] * frame->fp[i].v[1] + frame->translate[1];
          pointListPtr[i].z = frame->scale[2] * frame->fp[i].v[2] + frame->translate[2];
       }
    }
			 
	JTexture *tex = mRenderer->LoadTexture(textureName);
	if (tex)
		mModel->modelTex = tex;
	else
	{
		free(mModel);
		mModel = NULL;
		
		free(buffer);
		return false;
	}

	float texWidth = (float)tex->mWidth;
	float texHeight = (float)tex->mHeight;


    // allocate memory for the model texture coordinates
    mModel->st = (texCoord_t*)malloc(sizeof(texCoord_t)*modelHeader->numST);

	// store number of texture coordinates
    mModel->numST = modelHeader->numST;

	// set texture pointer to texture coordinate offset
    stPtr = (stIndex_t*)&buffer[modelHeader->offsetST];

	// calculate and store the texture coordinates for the model
    for (i = 0; i < modelHeader->numST; i++)
    {
		mModel->st[i].s = (float)stPtr[i].s / texWidth;
        mModel->st[i].t = (float)stPtr[i].t / texHeight;
    }

	// allocate an index of triangles
	triIndex = (mesh_t*)malloc(sizeof(mesh_t) * modelHeader->numTris);

	// set total number of triangles
	mModel->numTriangles = modelHeader->numTris;
	mModel->triIndex = triIndex;
	
	// point to triangle indexes in buffer
	bufIndexPtr = (mesh_t*)&buffer[modelHeader->offsetTris];

	// create a mesh (triangle) list
	for (j = 0; j < mModel->numFrames; j++)		
	{
		// for all triangles in each frame
		for(i = 0; i < modelHeader->numTris; i++)
		{
		   triIndex[i].meshIndex[0] = bufIndexPtr[i].meshIndex[0];
		   triIndex[i].meshIndex[1] = bufIndexPtr[i].meshIndex[1];
		   triIndex[i].meshIndex[2] = bufIndexPtr[i].meshIndex[2];
		   triIndex[i].stIndex[0] = bufIndexPtr[i].stIndex[0];
		   triIndex[i].stIndex[1] = bufIndexPtr[i].stIndex[1];
		   triIndex[i].stIndex[2] = bufIndexPtr[i].stIndex[2];
		}
	}

	// close file and free memory
	//fclose(filePtr);
    free(buffer);

	mModel->currentFrame = 0;
	mModel->nextFrame = 1;
	mModel->interpol = 0.0;

	CheckNextState();

    return true;
}
Пример #12
0
char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad)  // WAVE加载, memLoad-是否加载至内存
{

	JFileSystem* fileSystem = JFileSystem::GetInstance();
	if (!fileSystem->OpenFile(fileName)) 
		return 0;
		
	memset(p_wav, 0, sizeof(WAVDATA));
	//SceUID fd = sceIoOpen(fileName, PSP_O_RDONLY, 0777);
	char head[256];
	memset(head, 0, 256);
	//sceIoRead(fd, head, 20);
	fileSystem->ReadFile(head, 20);
	char string[8];
	memset(string, 0, 8);
	memcpy(string, head, 4);
	if (0!=strcmp(string, "RIFF"))
	{
		//sceIoClose(fd);
		fileSystem->CloseFile();
		return 0;
	}
	memset(string, 0, 8);
	memcpy(string, head+8, 4);
	if (0!=strcmp(string, "WAVE"))
	{
		//sceIoClose(fd);
		fileSystem->CloseFile();
		return 0;
	}
	memset(string, 0, 8);
	memcpy(string, head+12, 3);
	if (0!=strcmp(string, "fmt"))
	{
		//sceIoClose(fd);
		fileSystem->CloseFile();
		return 0;
	}
	int fmtSize = 0;
	memcpy(&fmtSize, head+16, 4);
	//sceIoRead(fd, head+20, fmtSize);
	fileSystem->ReadFile(head+20,fmtSize );
	p_wav->headSize = 20+fmtSize;
	while (1)
	{
		//sceIoRead(fd, head+p_wav->headSize, 4);
		fileSystem->ReadFile(head+p_wav->headSize, 4);
		memset(string, 0, 8);
		memcpy(string, head+p_wav->headSize, 4);
		p_wav->headSize += 4;
		if (0!=strcmp(string, "data"))
		{
			//sceIoRead(fd, head+p_wav->headSize, 4);
			fileSystem->ReadFile(head+p_wav->headSize, 4);
			memcpy(&fmtSize, head+p_wav->headSize, 4);
			p_wav->headSize += 4;
			//sceIoRead(fd, head+p_wav->headSize, fmtSize);
			fileSystem->ReadFile(head+p_wav->headSize, fmtSize);
			p_wav->headSize += fmtSize;
		}
		else
		{
			//sceIoRead(fd, head+p_wav->headSize, 4);
			fileSystem->ReadFile(head+p_wav->headSize, 4);
			p_wav->headSize += 4;
			break;
		}
		if (p_wav->headSize>191)
		{
			//sceIoClose(fd);
			fileSystem->CloseFile();
			return 0;
		}
	}
	strcpy(p_wav->fullName, fileName);
	memcpy(&p_wav->fileSize, head+4, 4);
	memcpy(&p_wav->format, head+20, 2);
	memcpy(&p_wav->channelCount, head+22, 2);
	if (p_wav->channelCount!=1 && p_wav->channelCount!=2)
	{
		//sceIoClose(fd);
		fileSystem->CloseFile();
		return 0;
	}
	memcpy(&p_wav->samplePerSecond, head+24, 4);
	memcpy(&p_wav->bytePerSecond, head+28, 4);
	memcpy(&p_wav->bytePerSample, head+32, 2);
	p_wav->bytePerSample = p_wav->bytePerSample / p_wav->channelCount;
	if (p_wav->bytePerSample!=1 && p_wav->bytePerSample!=2)
	{
		//sceIoClose(fd);
		fileSystem->CloseFile();
		return 0;
	}
	p_wav->nSample = 44100 / p_wav->samplePerSecond;
	p_wav->sizeStep = 4096 / p_wav->nSample * p_wav->channelCount / 2 * p_wav->bytePerSample / 2;
	memcpy(&p_wav->soundSize, head+p_wav->headSize-4, 4);
	if (memLoad)
	{
		if (p_wav->soundSize>4096000)
		{
			//sceIoClose(fd);
			fileSystem->CloseFile();
			return 0;
		}
		p_wav->buffer = (char*)malloc(p_wav->soundSize);
		memset(p_wav->buffer, 0, p_wav->soundSize);
		//sceIoRead(fd, p_wav->buffer, p_wav->soundSize);
		fileSystem->ReadFile(p_wav->buffer, p_wav->soundSize);
		p_wav->bytePosition = 0;
		p_wav->fd = -1;
		//sceIoClose(fd);
		fileSystem->CloseFile();
	}
	else
	{
		p_wav->bytePosition = p_wav->headSize;
		//p_wav->fd = fd;	// no file mode...
		p_wav->fd = -1;
	}
	return 1;
}