Beispiel #1
0
int Compression::DoCompression(const char *from, const char *to)
{
	int lenght = 0, lenghtComp; 
	
	SDL_RWops *src = ged_SDL_RWFromFile(from, "rb");
	if(!src) return lenght;
	
	SDL_RWops *dst = ged_SDL_RWFromFile(to, "wb");
	if(!dst) 
	{
		SDL_RWclose(src);
		return lenght;
	}
	
	SDL_RWseek( src, 0, SEEK_END );
	lenght = SDL_RWtell( src );
	SDL_RWseek( src, 0, SEEK_SET );
	
	U8 *in = new U8[lenght];
	U8 *out = new U8[lenght + lenght / 8 + 256];
	
	SDL_RWread(src, in, lenght, 1);
	lenghtComp = DoCompression(in, lenght, out, lenght + lenght / 8 + 256);
	
	if(lenghtComp < lenght)
	{
		SDL_WriteLE32( dst, lenght );
		SDL_WriteLE32( dst, lenghtComp );
		SDL_RWwrite(dst, out, lenghtComp, 1);
	}
	else
	{
		//No compression
		SDL_WriteLE32( dst, lenght );
		SDL_WriteLE32( dst, lenght );
		SDL_RWwrite(dst, in, lenght, 1);
		
		lenghtComp = lenght;
	}
	
	delete [] in;
	delete [] out;
	
	SDL_RWclose(src);
	SDL_RWclose(dst);
	
	return lenghtComp + 2*sizeof(U32);
}
Beispiel #2
0
U8 *Compression::Decompression(const char *from, int &lenght)
{
	U8 *out = NULL;
	int lenghtComp; 
	
	SDL_RWops *src = ged_SDL_RWFromFile(from, "rb");
	if(!src) return NULL;
	
	lenght = SDL_ReadLE32( src );
	lenghtComp = SDL_ReadLE32( src );
	
	out = new U8[lenght];
	
	if(lenghtComp < lenght)
	{
		U8 *in = new U8[lenghtComp];
		
		SDL_RWread(src, in, lenghtComp, 1);
		Decompression(in, lenghtComp, out, lenght, false);
		
		delete [] in;
	}
	else
	{
		SDL_RWread(src, out, lenght, 1);
		lenght;
	}
	
	
	SDL_RWclose(src);
	return out;
}
Beispiel #3
0
void Compression::DoCompression(const char *from, SDL_RWops *dst)
{
	int lenght, lenghtComp; 
	
	SDL_RWops *src = ged_SDL_RWFromFile(from, "rb");
	if(!src) return;
	
	SDL_RWseek( src, 0, SEEK_END );
	lenght = SDL_RWtell( src );
	SDL_RWseek( src, 0, SEEK_SET );
	
	U8 *in = new U8[lenght];
	U8 *out = new U8[2*lenght/*lenght + lenght / 8 + 256*/]; //Solved crash when export Alittlecash_player.ged
	
	SDL_RWread(src, in, lenght, 1);
	lenghtComp = DoCompression(in, lenght, out, 2*lenght/*lenght + lenght / 8 + 256*/);
	
	if(lenghtComp < lenght)
	{
		SDL_WriteLE32( dst, lenght );
		SDL_WriteLE32( dst, lenghtComp );
		SDL_RWwrite(dst, out, lenghtComp, 1);
	}
	else
	{
		//No compression
		SDL_WriteLE32( dst, lenght );
		SDL_WriteLE32( dst, lenght );
		SDL_RWwrite(dst, in, lenght, 1);
	}
	
	
	
	delete [] in;
	delete [] out;
	
	SDL_RWclose(src);	
}
Beispiel #4
0
void GameSettings::OnButton(Button *button, int buttonId)
{
	switch(buttonId)
	{
	case BT_CLOSE:
		{
			delete this;
		}
		break;
	case BT_ADD:
		{	
			int w = atol(editX->GetText().c_str());
			int h = atol(editY->GetText().c_str());
			int fps = atol(editFps->GetText().c_str());
			int smax = atol(editMaxSounds->GetText().c_str());
			int viewSafeArea = 0, port = 0;

			if(gamePort) port = atol(gamePort->GetText().c_str());

			if(editViewSafeMargin)
			{
				viewSafeArea = atol(editViewSafeMargin->GetText().c_str());

				if(viewSafeArea < 0) viewSafeArea = 0;
				else if(viewSafeArea > 2048) viewSafeArea = 2048;
			}

			if(w < 2 || w > 2000 || h < 2 || h > 2000)
			{
				new PanelInfo("Game resolution is invalid");
				return;
			}

			if(fps < 1 || fps > 512)
			{
				new PanelInfo("Frame rate is invalid");
				return;
			}

			if(smax < 1 || smax > 512)
			{
				new PanelInfo("Maximum number of simultaneous sounds is invalid");
				return;
			}

			if(gameID && gameID->GetText().length() > MAX_GAME_ID)
			{
				char s[32];
				sprintf(s, "Maximum game id length is %ld", MAX_GAME_ID);
				new PanelInfo(s);
				return;
			}

			if(gamePort && (port < 0 || port > 65535))
			{
				new PanelInfo("Port number must be a value between 1024 and 65535");
				return;
			}

			

			gedString icon(GameControl::Get()->getIconPath());
			if(iconPath->GetSelectedIndex() >= 0)
			{
				icon = iconPath->GetFullPath();
				
				SDL_RWops *src = ged_SDL_RWFromFile(icon.c_str(), "rb");
				if(src)
				{
					SDL_RWclose(src);
					
					gedString iconExt(icon);
					iconExt.lower();
					if(iconExt.substr(iconExt.length() - 4, 4) != ".ico")
					{
						//Validate only non .ico files
						SDL_Surface* surface = ged_IMG_Load(icon.c_str());
						if(!surface)
						{
							new PanelInfo("This format is not supported or file is corrupted\nPlease, select other file");
							return;
						}
					}
				}
				else
				{
					new PanelInfo("Please, select a file");
					return;
				}
			}
			
			if(gameID)
			{
				if(gameID->GetText() != GameControl::Get()->getGameID())
				{
					PanelQuestion *panel = new PanelQuestion("If you change the ID, this game will be recognized as a different game in the network.\nProceed anyway?");
					if(panel->Wait() != OK_BUTTON)
					{
						delete panel;
						return;
					}

					delete panel;
				}				
			}
			
			bool bStereo = false, bFull = false, bShowMouse = false, bSuspendGameIfLostFocus = false, bUseESCKeyToExit = false, bUseMotionCorrection = false, bUseGameEditorServer = false, bAutoStartNetwork = false;
			if(listStereo->GetText() == "Stereo") bStereo = true;			
			if(listFull->GetText() == "Full screen") bFull = true;
			if(listMouse->GetText() == "Show mouse") bShowMouse = true;
			if(listSuspend && listSuspend->GetText() == "Yes") bSuspendGameIfLostFocus = true;
			if(listAutoStartNetwork && listAutoStartNetwork->GetText() == "Yes") bAutoStartNetwork = true;
			if(listGameServer && listGameServer->GetText() == "Yes") bUseGameEditorServer = true;
			if(listESC && listESC->GetText() == "Yes") bUseESCKeyToExit = true;
			if(listMotion && listMotion->GetText() == "Yes") bUseMotionCorrection = true;

			gedString hz = listHz->GetText();

			if(bFull && (w > 1024 || h > 768))
			{
				PanelQuestion *panel = new PanelQuestion("The selected resolution will be able not to work in full screen in some old computers.\nIf your game must work in old machines, make sure select resolutions below 1024x768.\nUse this resolution anyway?");
				if(panel && panel->Wait() != OK_BUTTON)
				{
					delete panel;
					return;
				}			
				
				delete panel;
			}

			GameControl::Get()->SetGameProperties(w, h, fps, bFull, atol(hz.substr(0, hz.find(" ")).c_str()), bStereo, smax, bShowMouse, icon, gameTitle->GetText(), false, backgroundColor->getColor(), bSuspendGameIfLostFocus, viewSafeArea, bUseESCKeyToExit);
			GameControl::Get()->setFlipPocketPCScreen(bFlipPocketPCScreen);
			GameControl::Get()->setUseMotionCorrection(bUseMotionCorrection);
			GameControl::Get()->setUseGameEditorServer(bUseGameEditorServer);
			GameControl::Get()->setAutoStartNetwork(bAutoStartNetwork);

			if(gameID)
			{				
				GameControl::Get()->setGameID(gameID->GetText());
			}

			if(gamePort)
			{				
				GameControl::Get()->setGamePort(port);
			}

			delete this;
		}
		break;
	}
}