Example #1
0
int main(int argc, char** argv) {
	TheGame game;
	ResourceManager<ResourceImage> resMan("res/");
	GameBoard board;
	Well well = board.getWell();
	ViewGameBoard screen(&resMan, &well);

	game.getEventDispatcher().bind(SDL_KEYDOWN, SDL_SCANCODE_ESCAPE, std::bind(&TheGame::stop, &game, std::placeholders::_1));
	game.getEventDispatcher().bind(SDL_KEYDOWN, SDL_SCANCODE_LEFT, std::bind(&Well::left, &well, std::placeholders::_1));
	game.getEventDispatcher().bind(SDL_KEYDOWN, SDL_SCANCODE_RIGHT, std::bind(&Well::right, &well, std::placeholders::_1));
	game.getEventDispatcher().bind(SDL_KEYDOWN, SDL_SCANCODE_UP, std::bind(&Well::rotate, &well, std::placeholders::_1));
	game.getEventDispatcher().bind(SDL_KEYDOWN, SDL_SCANCODE_DOWN, std::bind(&Well::drop, &well, std::placeholders::_1));

	game.onTick().connect<ViewScreen, &ViewScreen::render>(&screen);

	game.start();

	return 0;
}
Example #2
0
const ADGameDescription *SciMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
	bool foundResMap = false;
	bool foundRes000 = false;

	// Set some defaults
	s_fallbackDesc.extra = "";
	s_fallbackDesc.language = Common::EN_ANY;
	s_fallbackDesc.flags = ADGF_NO_FLAGS;
	s_fallbackDesc.platform = Common::kPlatformPC;	// default to PC platform
	s_fallbackDesc.gameid = "sci";
	s_fallbackDesc.guioptions = Common::GUIO_NONE;

	if (allFiles.contains("resource.map") || allFiles.contains("Data1")
	    || allFiles.contains("resmap.001") || allFiles.contains("resmap.001")) {
		foundResMap = true;
	}

	// Determine if we got a CD version and set the CD flag accordingly, by checking for
	// resource.aud for SCI1.1 CD games, or audio001.002 for SCI1 CD games. We assume that
	// the file should be over 10MB, as it contains all the game speech and is usually
	// around 450MB+. The size check is for some floppy game versions like KQ6 floppy, which
	// also have a small resource.aud file
	if (allFiles.contains("resource.aud") || allFiles.contains("audio001.002")) {
		Common::FSNode file = allFiles.contains("resource.aud") ? allFiles["resource.aud"] :  allFiles["audio001.002"];
		Common::SeekableReadStream *tmpStream = file.createReadStream();
		if (tmpStream->size() > 10 * 1024 * 1024) {
			// We got a CD version, so set the CD flag accordingly
			s_fallbackDesc.flags |= ADGF_CD;
		}
		delete tmpStream;
	}

	if (allFiles.contains("resource.000") || allFiles.contains("resource.001")
		|| allFiles.contains("ressci.000") || allFiles.contains("ressci.001"))
		foundRes000 = true;

	// Data1 contains both map and volume for SCI1.1+ Mac games
	if (allFiles.contains("Data1")) {
		foundResMap = foundRes000 = true;
		 s_fallbackDesc.platform = Common::kPlatformMacintosh;
	}

	// Determine the game platform
	// The existence of any of these files indicates an Amiga game
	if (allFiles.contains("9.pat") || allFiles.contains("spal") ||
		allFiles.contains("patch.005") || allFiles.contains("bank.001"))
			s_fallbackDesc.platform = Common::kPlatformAmiga;

	// The existence of 7.pat or patch.200 indicates a Mac game
	if (allFiles.contains("7.pat") || allFiles.contains("patch.200"))
		s_fallbackDesc.platform = Common::kPlatformMacintosh;

	// The data files for Atari ST versions are the same as their DOS counterparts


	// If these files aren't found, it can't be SCI
	if (!foundResMap && !foundRes000) {
		return 0;
	}

	Common::ScopedPtr<ResourceManager> resMan(new ResourceManager());
	assert(resMan);
	resMan->addAppropriateSources(fslist);
	resMan->init(true);
	// TODO: Add error handling.

#ifndef ENABLE_SCI32
	// Is SCI32 compiled in? If not, and this is a SCI32 game,
	// stop here
	if (getSciVersion() >= SCI_VERSION_2) {
		return (const ADGameDescription *)&s_fallbackDesc;
	}
#endif

	ViewType gameViews = resMan->getViewType();

	// Have we identified the game views? If not, stop here
	// Can't be SCI (or unsupported SCI views). Pinball Creep by sierra also uses resource.map/resource.000 files
	//  but doesnt share sci format at all, if we dont return 0 here we will detect this game as SCI
	if (gameViews == kViewUnknown) {
		return 0;
	}

	// Set the platform to Amiga if the game is using Amiga views
	if (gameViews == kViewAmiga)
		s_fallbackDesc.platform = Common::kPlatformAmiga;

	// Determine the game id
	Common::String sierraGameId = resMan->findSierraGameId();

	// If we don't have a game id, the game is not SCI
	if (sierraGameId.empty()) {
		return 0;
	}

	Common::String gameId = convertSierraGameId(sierraGameId, &s_fallbackDesc.flags, resMan);
	strncpy(s_fallbackGameIdBuf, gameId.c_str(), sizeof(s_fallbackGameIdBuf) - 1);
	s_fallbackGameIdBuf[sizeof(s_fallbackGameIdBuf) - 1] = 0;	// Make sure string is NULL terminated
	s_fallbackDesc.gameid = s_fallbackGameIdBuf;

	// Try to determine the game language
	// Load up text 0 and start looking for "#" characters
	// Non-English versions contain strings like XXXX#YZZZZ
	// Where XXXX is the English string, #Y a separator indicating the language
	// (e.g. #G for German) and ZZZZ is the translated text
	// NOTE: This doesn't work for games which use message instead of text resources
	// (like, for example, Eco Quest 1 and all SCI1.1 games and newer, e.g. Freddy Pharkas).
	// As far as we know, these games store the messages of each language in separate
	// resources, and it's not possible to detect that easily
	// Also look for "%J" which is used in japanese games
	Resource *text = resMan->findResource(ResourceId(kResourceTypeText, 0), 0);
	uint seeker = 0;
	if (text) {
		while (seeker < text->size) {
			if (text->data[seeker] == '#')  {
				if (seeker + 1 < text->size)
					s_fallbackDesc.language = charToScummVMLanguage(text->data[seeker + 1]);
				break;
			}
			if (text->data[seeker] == '%') {
				if ((seeker + 1 < text->size) && (text->data[seeker + 1] == 'J')) {
					s_fallbackDesc.language = charToScummVMLanguage(text->data[seeker + 1]);
					break;
				}
			}
			seeker++;
		}
	}


	// Fill in "extra" field

	// Is this an EGA version that might have a VGA pendant? Then we want
	// to mark it as such in the "extra" field.
	const bool markAsEGA = (gameViews == kViewEga && s_fallbackDesc.platform != Common::kPlatformAmiga
			&& getSciVersion() > SCI_VERSION_1_EGA_ONLY);

	const bool isDemo = (s_fallbackDesc.flags & ADGF_DEMO);
	const bool isCD = (s_fallbackDesc.flags & ADGF_CD);

	if (!isCD)
		s_fallbackDesc.guioptions |= Common::GUIO_NOSPEECH;

	if (gameId.hasSuffix("sci")) {
		s_fallbackDesc.extra = "SCI";

		// Differentiate EGA versions from the VGA ones, where needed
		if (markAsEGA)
			s_fallbackDesc.extra = "SCI/EGA";

		// Mark as demo.
		// Note: This overwrites the 'EGA' info, if it was previously set.
		if (isDemo)
			s_fallbackDesc.extra = "SCI/Demo";
	} else {
		if (markAsEGA)
			s_fallbackDesc.extra = "EGA";

		// Set "CD" and "Demo" as appropriate.
		// Note: This overwrites the 'EGA' info, if it was previously set.
		if (isDemo && isCD)
			s_fallbackDesc.extra = "CD Demo";
		else if (isDemo)
			s_fallbackDesc.extra = "Demo";
		else if (isCD)
			s_fallbackDesc.extra = "CD";
	}

	return (const ADGameDescription *)&s_fallbackDesc;
}
Example #3
0
bool Modules::init()
{
	// Create modules (order is important because of dependencies)
	if( _extensionManager == 0x0 ) _extensionManager = new ExtensionManager();
	if( _engineLog == 0x0 ) _engineLog = new EngineLog();
	if( _engineConfig == 0x0 ) _engineConfig = new EngineConfig();
	if( _sceneManager == 0x0 ) _sceneManager = new SceneManager();
	if( _resourceManager == 0x0 ) _resourceManager = new ResourceManager();
	if( _renderDevice == 0x0 ) _renderDevice = new RenderDevice();
	gRDI = _renderDevice;
	if( _renderer == 0x0 ) _renderer = new Renderer();
	if( _statManager == 0x0 ) _statManager = new StatManager();

	// Init modules
	if( !renderer().init() ) return false;

	// Register resource types
	resMan().registerType( ResourceTypes::SceneGraph, "SceneGraph", 0x0, 0x0,
		SceneGraphResource::factoryFunc );
	resMan().registerType( ResourceTypes::Geometry, "Geometry", GeometryResource::initializationFunc,
		GeometryResource::releaseFunc, GeometryResource::factoryFunc );
	resMan().registerType( ResourceTypes::Animation, "Animation", 0x0, 0x0,
		AnimationResource::factoryFunc );
	resMan().registerType( ResourceTypes::Material, "Material", 0x0, 0x0,
		MaterialResource::factoryFunc );
	resMan().registerType( ResourceTypes::Code, "Code", 0x0, 0x0,
		CodeResource::factoryFunc );
	resMan().registerType( ResourceTypes::Shader, "Shader", 0x0, 0x0,
		ShaderResource::factoryFunc );
	resMan().registerType( ResourceTypes::Texture, "Texture", TextureResource::initializationFunc,
		TextureResource::releaseFunc, TextureResource::factoryFunc );
	resMan().registerType( ResourceTypes::ParticleEffect, "ParticleEffect", 0x0, 0x0,
		ParticleEffectResource::factoryFunc );
	resMan().registerType( ResourceTypes::Pipeline, "Pipeline", 0x0, 0x0,
		PipelineResource::factoryFunc );

	// Register node types
	sceneMan().registerType( SceneNodeTypes::Group, "Group",
		GroupNode::parsingFunc, GroupNode::factoryFunc, 0x0 );
	sceneMan().registerType( SceneNodeTypes::Model, "Model",
		ModelNode::parsingFunc, ModelNode::factoryFunc, 0x0 );
	sceneMan().registerType( SceneNodeTypes::Mesh, "Mesh",
		MeshNode::parsingFunc, MeshNode::factoryFunc, Renderer::drawMeshes );
	sceneMan().registerType( SceneNodeTypes::Joint, "Joint",
		JointNode::parsingFunc, JointNode::factoryFunc, 0x0 );
	sceneMan().registerType( SceneNodeTypes::Light, "Light",
		LightNode::parsingFunc, LightNode::factoryFunc, 0x0 );
	sceneMan().registerType( SceneNodeTypes::Camera, "Camera",
		CameraNode::parsingFunc, CameraNode::factoryFunc, 0x0 );
	sceneMan().registerType( SceneNodeTypes::Emitter, "Emitter",
		EmitterNode::parsingFunc, EmitterNode::factoryFunc, Renderer::drawParticles );
	
	// Install extensions
	installExtensions();

	// Create default resources
	TextureResource *tex2DRes = new TextureResource(
		"$Tex2D", 32, 32, 1, TextureFormats::BGRA8, ResourceFlags::NoTexMipmaps );
	void *image = tex2DRes->mapStream( TextureResData::ImageElem, 0, TextureResData::ImgPixelStream, false, true );
	ASSERT( image != 0x0 );
	for( uint32 i = 0; i < 32*32; ++i ) ((uint32 *)image)[i] = 0xffffffff;
	tex2DRes->unmapStream();
	tex2DRes->addRef();
	resMan().addNonExistingResource( *tex2DRes, false );

	TextureResource *texCubeRes = new TextureResource(
		"$TexCube", 32, 32, 1, TextureFormats::BGRA8, ResourceFlags::TexCubemap | ResourceFlags::NoTexMipmaps );
	for( uint32 i = 0; i < 6; ++i )
	{
		image = texCubeRes->mapStream( TextureResData::ImageElem, i, TextureResData::ImgPixelStream, false, true );
		ASSERT( image != 0x0 );
		for( uint32 j = 0; j < 32*32; ++j ) ((uint32 *)image)[j] = 0xff000000;
		texCubeRes->unmapStream();
	}
	texCubeRes->addRef();
	resMan().addNonExistingResource( *texCubeRes, false );

	TextureResource *tex3DRes = new TextureResource(
		"$Tex3D", 16, 16, 4, TextureFormats::BGRA8, ResourceFlags::NoTexMipmaps );
	image = tex3DRes->mapStream( TextureResData::ImageElem, 0, TextureResData::ImgPixelStream, false, true );
	ASSERT( image != 0x0 );
	for( uint32 i = 0; i < 16*16*4; ++i ) ((uint32 *)image)[i] = 0xffffffff;
	tex3DRes->unmapStream();
	tex3DRes->addRef();
	resMan().addNonExistingResource( *tex3DRes, false );
	
	return true;
}