示例#1
0
void grinliz::StrTokenize( const GLString& in, CDynArray<StrToken>* tokens, bool append )
{
	const char* p = in.c_str();
	p = SkipWhiteSpace( p );
	const char* q = FindWhiteSpace( p );

	if ( !append ) {
		tokens->Clear();
	}

	while ( p && *p && q ) {
		StrToken token;

		GLString str;
		str.append( p, q-p );

		if ( isalpha( *p ) ) {
			token.InitString( str );
		}
		else if (    isdigit( *p ) 
			      || *p == '-' 
				  || *p == '+' ) {
			token.InitNumber( atof( str.c_str() ) );
		}
		tokens->Push( token );

		p = SkipWhiteSpace( q );
		q = FindWhiteSpace( p );
	}
}
示例#2
0
void LumosGame::CopyFile(const char* src, const char* target)
{
	GLString srcPath;
	GetSystemPath(GAME_APP_DIR, src, &srcPath);

	GLString targetPath;
	GetSystemPath(GAME_SAVE_DIR, target, &targetPath);

	FILE* fp = fopen(srcPath.c_str(), "rb");
	GLASSERT(fp);
	if (fp) {
		FILE* tp = fopen(targetPath.c_str(), "wb");
		GLASSERT(tp);

		if (tp) {
			CDynArray<U8> buf;
			fseek(fp, 0, SEEK_END);
			size_t size = ftell(fp);
			buf.PushArr(size);

			fseek(fp, 0, SEEK_SET);
			size_t didRead = fread(&buf[0], 1, size, fp);
			GLASSERT(didRead == 1);
			if (didRead == 1) {
				fwrite(buf.Mem(), 1, size, tp);
			}

			fclose(tp);
		}
		fclose(fp);
	}
}
示例#3
0
void GLString::append( const GLString& str )
{
	ensureSize( str.size() + size() );
	if ( str.size() )
		memcpy( m_buf+size(), str.m_buf, str.size() );
	m_size += str.size();
	m_buf[m_size] = 0;
	validate();
}
示例#4
0
void grinliz::StrFillBuffer( const GLString& str, char* buffer, int bufferSize )
{
	StrNCpy( buffer, str.c_str(), bufferSize );

	if ( bufferSize - 1 - (int)str.size() > 0 ) {
		memset( buffer + str.size() + 1, 0, bufferSize - str.size() - 1 );
	}
	GLASSERT( buffer[bufferSize-1] == 0 );
}
示例#5
0
void Game::DeleteFile( const char* path )
{
	GLString fullpath;
	GetSystemPath(GAME_SAVE_DIR, path, &fullpath);

	FILE* fp = fopen(fullpath.c_str(), "w");
	if ( fp ) {
		fclose( fp );
	}
}
示例#6
0
void GLLabel::setString(const GLString& newString)
	{
	/* Replace the string, but use the current font: */
	GLString::setString(newString.getString(),newString.getString()+newString.getLength(),*font);
	
	/* Increment the version number: */
	++version;
	
	/* Update the label box size: */
	labelBox.size=font->calcStringSize(texelWidth);
	}
示例#7
0
void GLString::init( const GLString& rhs ) 
{
	if ( m_buf != nullBuf ) delete [] m_buf;
	m_buf = (char*)nullBuf;
	m_allocated = 0;
	m_size = 0;

	ensureSize( rhs.size() );
	m_size = rhs.size();
	if ( m_size )
		memcpy( m_buf, rhs.m_buf, m_size );
	m_buf[m_size] = 0;
	validate();
}
示例#8
0
GLString GLString::substr( unsigned pos, unsigned n ) const
{
	GLString str;
	if ( pos < size()-1 ) {
		if ( pos + n > size() ) {
			n = size() - pos;
		}
		str.ensureSize(n);
		if ( n )
			memcpy( str.m_buf, m_buf+pos, n );
		str.m_buf[n] = 0;
		str.m_size = n;
	}
	validate();
	return str;
}
示例#9
0
bool Game::HasFile( const char* path ) const
{
	bool result = false;

	GLString fullpath;
	GetSystemPath(GAME_SAVE_DIR, path, &fullpath);

	FILE* fp = fopen( fullpath.c_str(), "rb" );
	if ( fp ) {
		fseek( fp, 0, SEEK_END );
		long d = ftell( fp );
		if ( d > 10 ) {	// has to be something there: sanity check
			result = true;
		}
		fclose( fp );
	}
	return result;
}
示例#10
0
Game::Game( int width, int height, int rotation, int uiHeight ) :
	screenport( width, height, uiHeight ),
	aiDebugLog(false),
	markFrameTime( 0 ),
	frameCountsSinceMark( 0 ),
	framesPerSecond( 0 ),
	debugUI( false ), 
	debugText( false ),
	perfText( false ),
	perfFrameCount( 0 ),
	renderUI( true ),
	previousTime( 0 ),
	isDragging( false )
{
	CHECK_GL_ERROR;
	IStringConst::Init();

#ifdef DEBUG
	Matrix4::Test();
	ChitBag::Test();
	NewsEvent::Test();
#endif

	scenePopQueued = false;
	surface.Set( TEX_RGBA16, 256, 256 );

	// Load the database.
	char buffer[260];
	int offset;
	int length;
	PathToDatabase(buffer, 260, &offset, &length);
	database0 = new gamedb::Reader();
	database0->Init( 0, buffer, offset );
	xenoAudio = new XenoAudio(database0, buffer);
	xenoAudio->SetAudio(true);

	GLOUTPUT(( "Game::Init Database initialized.\n" ));

	GLOUTPUT_REL(( "Game::Init stage 10\n" ));
	TextureManager::Create( database0 );
	ImageManager::Create( database0 );
	ModelResourceManager::Create();
	AnimationResourceManager::Create();

	GLString settingsPath;
	GetSystemPath(GAME_SAVE_DIR, "settings2.xml", &settingsPath );
	SettingsManager::Create(settingsPath.c_str());
	SettingsManager* settings = SettingsManager::Instance();
	debugUI = settings->DebugUI();

	LoadTextures();
	modelLoader = new ModelLoader();
	LoadModels();
	LoadPalettes();
	AnimationResourceManager::Instance()->Load( database0 );

	delete modelLoader;
	modelLoader = 0;

	// Load font:
	GLString fontPath = "./res/";
	FontSingleton* bridge = FontSingleton::Instance();
	{
		XMLDocument doc;
		doc.LoadFile("./res/font.xml");
		XMLElement* ele = doc.FirstChildElement("Font");
		GLASSERT(ele && ele->Attribute("name"));
		if (ele && ele->Attribute("name")) {
			fontPath += ele->Attribute("name");
		}
		bridge->Init(fontPath.c_str());

		int spacing = 0, height = 0, ascent = 0, descent = 0;
		ele->QueryAttribute("spacing", &spacing);
		ele->QueryAttribute("height", &height);
		ele->QueryAttribute("ascent", &ascent);
		ele->QueryAttribute("descent", &descent);
		
		bridge->SetAscentDelta(ascent);
		bridge->SetDescentDelta(descent);
		bridge->SetHeightDelta(height);
		bridge->SetLineSpacingDelta(spacing);
	}
	
	Texture* textTexture = TextureManager::Instance()->GetTexture( "fixedfont" );
	GLASSERT( textTexture );
	UFOText::Create(textTexture);

	itemDefDB = new ItemDefDB();
	itemDefDB->Load( "./res/itemdef.xml" );
	itemDefDB->DumpWeaponStats();

	GLOUTPUT(( "Game::Init complete.\n" ));
}
示例#11
0
void TitleScene::Resize()
{
	const Screenport& port = game->GetScreenport();

	// Dowside of a local Engine: need to resize it.
	if (engine) {
		engine->GetScreenportMutable()->Resize(port.PhysicalWidth(), port.PhysicalHeight());
		for (int i = 0; i < NUM_MODELS; ++i) {
			if (model[i])
				model[i]->SetFlag(Model::MODEL_INVISIBLE);
		}
	}
	background.SetPos( 0, 0 );

	float aspect = gamui2D.AspectRatio();
	float factor = 0.5;
	if ( aspect >= 0.5f ) {
		background.SetSize(gamui2D.Width()*factor, gamui2D.Width()*0.5f*factor);
	}
	else {
		background.SetSize(gamui2D.Height()*2.0f*factor, gamui2D.Height()*factor);
	}
	background.SetCenterPos(gamui2D.Width()*0.5f, gamui2D.Height()*0.5f*factor);

	bool visible = game->GetDebugUI();
	LayoutCalculator layout = DefaultLayout();
	int c = 0;
	for( int i=0; i<NUM_TESTS; ++i ) {
		testScene[i].SetVisible( visible );

		int y = c / TESTS_PER_ROW;
		int x = c - y*TESTS_PER_ROW;
		layout.PosAbs( &testScene[i], x, y );
		++c;
	}
	layout.SetSize( LAYOUT_SIZE_X, LAYOUT_SIZE_Y );

	layout.PosAbs(&gameScene[GENERATE_WORLD], -2, -1, 2, 1);
	layout.PosAbs(&gameScene[CONTINUE], 0, -1, 2, 1);

	gameScene[CONTINUE].SetEnabled( false );
//	const char* datPath = game->GamePath( "game", 0, "dat" );
	const char* mapPath = game->GamePath( "map",  0, "dat" );

	GLString fullpath;
	GetSystemPath(GAME_SAVE_DIR, mapPath, &fullpath);
	FILE* fp = fopen(fullpath.c_str(), "rb");
	if (fp) {
		StreamReader reader(fp);
		if (reader.Version() == CURRENT_FILE_VERSION) {
			gameScene[CONTINUE].SetEnabled(true);
		}
		fclose(fp);
	}

	layout.PosAbs( &note, 0, -2 );
	note.SetVisible(!visible);
	note.SetBounds( gamui2D.Width() -(layout.GutterX() * 2.0f), 0 );

	layout.PosAbs(&audioButton, -1, 0);
	layout.PosAbs(&mouseTouchButton, -2, 0);
	layout.PosAbs(&creditsButton, -3, 0);

	testCanvas.SetPos(gamui2D.Width() - 100, gamui2D.Height() - 100);
	testCanvas.SetVisible(false);
}
示例#12
0
void XenoAudio::Play(const IString& iSound, const Vector3F* pos)
{
	if (!audioOn) return;

	// The listener will get updated at the end of the frame,
	// so this isn't quite correct. But hopefully good enough
	// to prevent saturating the game with sounds all
	// over the world.
	if (   pos 
		&& (*pos - listenerPos).LengthSquared() > (MAX_DISTANCE*MAX_DISTANCE)) 
	{
		return;
	}

	Mix_Chunk* chunk = 0;
	chunks.Query(iSound, &chunk);

	if (!chunk) {
		const gamedb::Item* data = database->Root()->Child("data");
		const gamedb::Item* item = data->Child(iSound.c_str());
		SDL_RWops* fp = 0;
		bool needClose = false;

#if 0
		// Search external path first.
		GLString path;
		GLString inPath = "res/";
		inPath.append(iSound.c_str());
		inPath.append(".wav");
		GetSystemPath(GAME_APP_DIR, inPath.c_str(), &path);

		fp = SDL_RWFromFile(path.c_str(), "rb");
		if (fp) {
			needClose = true;
		}
#endif
		// Now check the database
		if (!fp) {
			int size = 0;
			const void* mem = database->AccessData(item, "binary", &size);
			GLASSERT(mem);
			fp = SDL_RWFromConstMem(mem, size);
			needClose = true;
		}
		if (fp) {
			//U8* buf = 0;
			//U32 len = 0;
			chunk = Mix_LoadWAV_RW(fp, false);
			if (!chunk) {
				GLOUTPUT(("Audio error: %s\n", Mix_GetError()));
			}
			else {
				chunks.Add(iSound, chunk);
			}
			if (needClose) {
				SDL_RWclose(fp);
			}
		}
	}
	GLASSERT(chunk);
	if (chunk) {
		int channel = Mix_PlayChannel(-1, chunk, 0);
		if (channel >= 0 && channel < CHANNELS ) {
			sounds[channel].channel = channel;
			sounds[channel].pos.Zero();
			if (pos) {
				sounds[channel].pos = *pos;
			}
			SetChannelPos(channel);
		}
	}
}
示例#13
0
void grinliz::StrSplitFilename(	const GLString& fullPath, 
								GLString* base,
								GLString* name,
								GLString* extension )
{
	GLString path = fullPath;
	if ( base )
		*base = "";
	if ( name )
		*name = "";
	if ( extension )
		*extension = "";

	unsigned dotPos = path.rfind( '.' );
	if ( dotPos < path.size() ) {
		if ( extension )
			*extension = path.substr( dotPos, path.size() );
		path = path.substr( 0, dotPos );
	}

	unsigned slashPos = path.rfind( '/' );
	unsigned backPos = path.rfind( '\\' );
	unsigned colonPos = path.rfind( ':' );

	unsigned pos = 0;
	bool found = false;
	if ( slashPos < path.size() && slashPos > pos ) {
		pos = slashPos;
		found = true;
	}
	if ( backPos < path.size() && backPos > pos ) {
		pos = backPos;
		found = true;
	}
	if ( colonPos < path.size() && colonPos > pos ) {
		pos = colonPos;
		found = true;
	}
	if ( found && pos < path.size() ) {
		if ( base )
			*base = path.substr( 0, pos+1 );
		path = path.substr( pos+1, path.size() );
	}
	if ( name )
		*name = path;
}