コード例 #1
0
	bool Instance::process_movement() {
		FL_DBG(_log, "Moving...");
		ActionInfo* info = m_activity->m_actioninfo;
		// timeslice for this movement
		unsigned int timedelta = m_activity->m_timeprovider->getGameTime() - info->m_prev_call_time;
		FL_DBG(_log, LMsg("timedelta ") <<  timedelta << " prevcalltime " << info->m_prev_call_time);
		// how far we can travel
		double distance_to_travel = (static_cast<double>(timedelta) / 1000.0) * info->m_speed;
		FL_DBG(_log, LMsg("dist ") <<  distance_to_travel);

		Location nextLocation = m_location;
		info->m_pather_session_id = info->m_pather->getNextLocation(
			this, *info->m_target,
			distance_to_travel, nextLocation, *m_facinglocation,
			info->m_pather_session_id);
		m_location.getLayer()->getInstanceTree()->removeInstance(this);
		m_location = nextLocation;
		//ExactModelCoordinate a = nextLocation.getMapCoordinates();
		//ExactModelCoordinate b = m_actioninfo->m_target->getMapCoordinates();
		m_location.getLayer()->getInstanceTree()->addInstance(this);
		// return if we are close enough to target to stop
		if (info->m_pather_session_id == -1) {
			return true;
		}
		return false;
	}
コード例 #2
0
ファイル: dat2.cpp プロジェクト: Creepinevil/fifengine
	DAT2::DAT2(VFS* vfs, const std::string& file)
		: VFSSource(vfs), m_datpath(file), m_data(vfs->open(file)), m_filelist() {

		FL_LOG(_log, LMsg("MFFalloutDAT2")
			<< "loading: " << file
			<< " filesize: " << m_data->getDataLength());

		m_data->setIndex(m_data->getDataLength() - 8);
		uint32_t fileListLength = m_data->read32Little();
		uint32_t archiveSize = m_data->read32Little();

		FL_LOG(_log, LMsg("MFFalloutDAT2")
			<< "FileListLength: " << fileListLength
			<< " ArchiveSize: " << archiveSize);

		if (archiveSize != m_data->getDataLength())
			throw InvalidFormat("size mismatch");

		m_data->setIndex( archiveSize - fileListLength - 8);
		m_filecount = m_data->read32Little();
		m_currentIndex = m_data->getCurrentIndex();

		FL_LOG(_log, LMsg("MFFalloutDAT2 FileCount: ") << m_filecount);

		// Do not read the complete file list at startup.
		// Instead read a chunk each frame.
		m_timer.setInterval(0);
		m_timer.setCallback( boost::bind( &DAT2::readFileEntry, this) );
		m_timer.start();
	}
コード例 #3
0
	void SoundManager::init() {
		m_device = alcOpenDevice(NULL);

		if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Could not open audio device - deactivating audio module");
			m_device = NULL;
			return;
		}

		m_context = alcCreateContext(m_device, NULL);
		if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't create audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		alcMakeContextCurrent(m_context);
		if (alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't change current audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		// set listener position
		alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
		ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		alListenerfv(AL_ORIENTATION, vec1);

		// set volume
		alListenerf(AL_GAIN, m_volume);
	}
コード例 #4
0
ファイル: vfs.cpp プロジェクト: fifengine/fifengine
	VFSSource* VFS::createSource(const std::string& path) {

		if (hasSource(path)) {
			FL_WARN(_log, LMsg(path) << " is already used as VFS source");
			return 0;
		}

		type_providers::const_iterator end = m_providers.end();
		for (type_providers::const_iterator i = m_providers.begin(); i != end; ++i) {
			VFSSourceProvider* provider = *i;
			if (!provider->isReadable(path))
				continue;

			try {
				VFSSource* source = provider->createSource(path);
				return source;
			} catch (const Exception& ex) {
				FL_WARN(_log, LMsg(provider->getName()) << " thought it could load " << path << " but didn't succeed (" << ex.what() << ")");
				continue;
			} catch (...) {
				FL_WARN(_log, LMsg(provider->getName()) << " thought it could load " << path << " but didn't succeed (unknown exception)");
				continue;
			}
		}

		FL_WARN(_log, LMsg("no provider for ") << path << " found");
		return 0;
	}
コード例 #5
0
ファイル: dat1.cpp プロジェクト: karottenreibe/FIFE
	DAT1::DAT1(VFS* vfs, const std::string& file) : VFSSource(vfs), m_datpath(file), m_data(vfs->open(file))  {
		FL_LOG(_log, LMsg("MFFalloutDAT1") 
			<< "loading: " << file 
			<< " filesize: " << m_data->getDataLength());

		m_data->setIndex(0);

		const uint32_t dircount = m_data->read32Big();
		m_data->moveIndex(4*3);

		FL_LOG(_log, LMsg("MFFalloutDAT1") 
			<< "number of directories " << dircount);

		// Sanity check. Each dir entry needs min. 16 bytes.
		if( dircount*16 > m_data->getDataLength() ) {
			throw InvalidFormat("directory count larger than filesize.");
		}

		std::list<std::string> dir_names;
		for (uint32_t i = 0; i < dircount; ++i) {
			std::string name = readString();
			if (name == ".") {
				name = "";
			}
			dir_names.push_back(name);
		}

		for(std::list<std::string>::iterator i= dir_names.begin(); i!= dir_names.end(); ++i)
			loadFileList(*i);
	}
コード例 #6
0
	HexGrid::HexGrid(bool allow_diagonals): CellGrid(allow_diagonals) {
		FL_DBG(_log, "Constructing new HexGrid");
		FL_DBG(_log, LMsg("HEX_WIDTH ") << HEX_WIDTH);
		FL_DBG(_log, LMsg("HEX_TO_EDGE ") << HEX_TO_EDGE);
		FL_DBG(_log, LMsg("HEX_TO_CORNER ") << HEX_TO_CORNER);
		FL_DBG(_log, LMsg("HEX_EDGE_HALF ") << HEX_EDGE_HALF);
		FL_DBG(_log, LMsg("VERTICAL_MULTIP ") << VERTICAL_MULTIP);
	}
コード例 #7
0
ファイル: hexgrid.cpp プロジェクト: Beliaar/fifengine
	HexGrid::HexGrid(bool axial):
		CellGrid(),
		m_axial(axial) {
		FL_DBG(_log, "Constructing new HexGrid");
		FL_DBG(_log, LMsg("HEX_WIDTH ") << HEX_WIDTH);
		FL_DBG(_log, LMsg("HEX_TO_EDGE ") << HEX_TO_EDGE);
		FL_DBG(_log, LMsg("HEX_TO_CORNER ") << HEX_TO_CORNER);
		FL_DBG(_log, LMsg("HEX_EDGE_HALF ") << HEX_EDGE_HALF);
		FL_DBG(_log, LMsg("VERTICAL_MULTIP ") << VERTICAL_MULTIP);
	}
コード例 #8
0
ファイル: mark.c プロジェクト: meh/screen
void MarkRoutine()
{
	int x, y;

	if (InitOverlayPage(sizeof(*markdata), &MarkLf, 1))
		return;
	flayer->l_encoding = fore->w_encoding;
	flayer->l_mode = 1;
	markdata = (struct markdata *)flayer->l_data;
	markdata->md_user = D_user;	/* XXX: Correct? */
	markdata->md_window = fore;
	markdata->second = 0;
	markdata->rep_cnt = 0;
	markdata->append_mode = 0;
	markdata->write_buffer = 0;
	markdata->nonl = 0;
	markdata->left_mar = 0;
	markdata->right_mar = fore->w_width - 1;
	markdata->hist_offset = fore->w_histheight;
	x = fore->w_x;
	y = D2W(fore->w_y);
	if (x >= fore->w_width)
		x = fore->w_width - 1;

	LGotoPos(flayer, x, W2D(y));
	LMsg(0, "Copy mode - Column %d Line %d(+%d) (%d,%d)",
	     x + 1, W2D(y + 1), fore->w_histheight, fore->w_width, fore->w_height);
	markdata->cx = markdata->x1 = x;
	markdata->cy = markdata->y1 = y;
	flayer->l_x = x;
	flayer->l_y = W2D(y);
}
コード例 #9
0
ファイル: dat2.cpp プロジェクト: Creepinevil/fifengine
	void DAT2::readFileEntry() const {
		assert( m_filecount != 0);

		// Load more items per call,
		// otherwise it takes _ages_ until everything is in.
		uint32_t load_per_cycle = 50;
		if( load_per_cycle > m_filecount )
			load_per_cycle = m_filecount;
		m_filecount -= load_per_cycle;

		// Save the old index in an exception save way.
		IndexSaver isaver(m_data.get());

		// Move index to file list and read the entries.
		m_data->setIndex(m_currentIndex);
		RawDataDAT2::s_info info;
		while( load_per_cycle-- ) {
			uint32_t namelen = m_data->read32Little();
			info.name = fixPath(m_data->readString(namelen));

			info.type = m_data->read8();
			info.unpackedLength = m_data->read32Little();
			info.packedLength = m_data->read32Little();
			info.offset = m_data->read32Little();

			m_filelist.insert(std::make_pair(info.name, info));
		}
		m_currentIndex = m_data->getCurrentIndex();

		// Finally log on completion and stop the timer.
		if( m_filecount == 0 ) {
			FL_LOG(_log, LMsg("MFFalloutDAT2, All file entries in '") << m_datpath << "' loaded.");
			m_timer.stop();
		}
	}
コード例 #10
0
ファイル: dat2.cpp プロジェクト: Creepinevil/fifengine
	DAT2::type_filelist::const_iterator DAT2::findFileEntry(const std::string& path) const {

		// Either the normalization is bogus, or we have to do
		// it here, too. Otherwise we can't load the files returned
		// by listFiles.

		std::string name = path;

		// Normalize the path
		if (name.find("./") == 0) {
			name.erase(0, 2);
		}

		type_filelist::const_iterator i = m_filelist.find(name);

		// We might have another chance to find the file
		// if the number of file entries not zero.
		if ( m_filecount && i == m_filelist.end()) {
			FL_LOG(_log, LMsg("MFFalloutDAT2")
				<< "Missing '" << name
				<< "' in partially(" << m_filecount <<") loaded "<< m_datpath);
			while( m_filecount && i == m_filelist.end()) {
				readFileEntry();
				i = m_filelist.find(name);
			}
		}
		return i;
	}
コード例 #11
0
ファイル: hexgrid.cpp プロジェクト: Beliaar/fifengine
	ExactModelCoordinate HexGrid::toExactLayerCoordinates(const ExactModelCoordinate& map_coord) {
		ExactModelCoordinate layer_coords = m_inverse_matrix * map_coord;
		layer_coords.y /= VERTICAL_MULTIP;
		layer_coords.x -= getXZigzagOffset(layer_coords.y);
		FL_DBG(_log, LMsg("mapcoords ") << map_coord << " converted to layer: " << layer_coords);
		return layer_coords;
	}
コード例 #12
0
ファイル: hexgrid.cpp プロジェクト: Beliaar/fifengine
	ExactModelCoordinate HexGrid::toMapCoordinates(const ExactModelCoordinate& layer_coords) {
		ExactModelCoordinate tranformed_coords(layer_coords);
		tranformed_coords.x += getXZigzagOffset(layer_coords.y);
		tranformed_coords.y *= VERTICAL_MULTIP;
		ExactModelCoordinate result = m_matrix * tranformed_coords;
		FL_DBG(_log, LMsg("layercoords ") << layer_coords << " converted to map: " << result);
		return result;
	}
コード例 #13
0
ファイル: vfs.cpp プロジェクト: fifengine/fifengine
	void VFS::addNewSource(const std::string& path) {
		VFSSource* source = createSource(path);
		if (source) {
			addSource(source);
		} else {
			FL_WARN(_log, LMsg("Failed to add new VFS source: ") << path);
		}
	}
コード例 #14
0
	void Instance::move(const std::string& action_name, const Location& target, const double speed) {
		initializeChanges();
		initializeAction(action_name);
		m_activity->m_actioninfo->m_target = new Location(target);
		m_activity->m_actioninfo->m_speed = speed;
		setFacingLocation(target);
		FL_DBG(_log, LMsg("starting action ") <<  action_name << " from" << m_location << " to " << target << " with speed " << speed);
	}
コード例 #15
0
ファイル: cellgrid.cpp プロジェクト: fifengine/fifengine
	bool CellGrid::ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3) {
		double o1 = orientation(pt1, pt2, pt);
		double o2 = orientation(pt2, pt3, pt);
		double o3 = orientation(pt3, pt1, pt);
		bool result = (o1 == o2) && (o2 == o3);
		FL_DBG(_log, LMsg("ptInTriangle, pt=") << pt << " pt1=" << pt1 << " pt2=" << pt2 << " pt3=" << pt3 << " in=" << result);
		return result;
	}
コード例 #16
0
ファイル: renderbackendsdl.cpp プロジェクト: m64/PEG
	Image* RenderBackendSDL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) {
		Uint32 flags = 0;
		if (fs) {
			flags |= SDL_FULLSCREEN;
		}

		if(icon != "") {
			SDL_Surface *img = IMG_Load(icon.c_str());
			if(img != NULL) {
				SDL_WM_SetIcon(img, 0);
			}
		}

		SDL_Surface* screen = NULL;

		if( 0 == bitsPerPixel ) {
			/// autodetect best mode
			unsigned char possibleBitsPerPixel[] = {16, 24, 32, 0};
			int i = 0;
			while( true ) {
				bitsPerPixel = possibleBitsPerPixel[i];
				if( !bitsPerPixel ) {
					// Last try, sometimes VideoModeOK seems to lie.
					// Try bpp=0
					screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
					if( !screen ) {
						throw SDLException("Videomode not available");
					}
					break;
				}
				bitsPerPixel = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
				if ( bitsPerPixel ) {
					screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
					if( screen ) {
						break;
					}
				}
				++i;
			}
		} else {
			if ( !SDL_VideoModeOK(width, height, bitsPerPixel, flags) ) {
				throw SDLException("Videomode not available");
			}
			screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
		}
		FL_LOG(_log, LMsg("RenderBackendSDL")
			<< "Videomode " << width << "x" << height
			<< " at " << int(screen->format->BitsPerPixel) << " bpp");

		SDL_WM_SetCaption(title.c_str(), NULL);

		if (!screen) {
			throw SDLException(SDL_GetError());
		}

		m_screen = new SDLImage(screen);
		return m_screen;
	}
コード例 #17
0
ファイル: rawdata.cpp プロジェクト: Creepinevil/fifengine
	void RawData::readInto(uint8_t* buffer, size_t len) {
		if (m_index_current + len > getDataLength()) {
			FL_LOG(_log, LMsg("RawData") << m_index_current << " : " << len << " : " << getDataLength());
			throw IndexOverflow(__FUNCTION__);
		}

		m_datasource->readInto(buffer, m_index_current, len);
		m_index_current += len;
	}
コード例 #18
0
ファイル: imagemanager.cpp プロジェクト: fifengine/fifengine
	ImagePtr ImageManager::create(const std::string& name, IResourceLoader* loader){
		if (exists(name)) {
			FL_WARN(_log, LMsg("ImageManager::create(std::string, IResourceLoader* loader) - ") << "Resource name " << name << " was previously created.  Returning original Image...");
			return getPtr(name);
		}

		Image* ptr = RenderBackend::instance()->createImage(name, loader);
		return add(ptr);
	}
コード例 #19
0
ファイル: vfs.cpp プロジェクト: fifengine/fifengine
	RawData* VFS::open(const std::string& path) {
		FL_DBG(_log, LMsg("Opening: ") << path);

		VFSSource* source = getSourceForFile(path);
		if (!source)
			throw NotFound(path);

		return source->open(path);
	}
コード例 #20
0
	SoundClipPtr SoundClipManager::create(const std::string& name, IResourceLoader* loader){
		if (exists(name)) {
			FL_WARN(_log, LMsg("SoundClipManager::create(std::string, IResourceLoader* loader) - ") << "Resource name " << name << " was previously created.  Returning original SoundClip...");
			return get(name);
		}

		SoundClip* ptr = new SoundClip(name, loader);
		return add(ptr);
	}
コード例 #21
0
ファイル: vfs.cpp プロジェクト: fifengine/fifengine
	VFSSource* VFS::getSourceForFile(const std::string& file) const {
		type_sources::const_iterator i = std::find_if(m_sources.begin(), m_sources.end(),
										 boost::bind2nd(boost::mem_fun(&VFSSource::fileExists), file));
		if (i == m_sources.end()) {
			FL_WARN(_log, LMsg("no source for ") << file << " found");
			return 0;
		}

		return *i;
	}
コード例 #22
0
ファイル: rawdata.cpp プロジェクト: Creepinevil/fifengine
	bool RawData::littleEndian() {
		static int32_t endian = 2;
		if (endian == 2) {
			uint32_t value = 0x01;
			endian = reinterpret_cast<uint8_t*>(&value)[0];
			FL_LOG(_log, LMsg("RawData") << "we are on a " << (endian == 1 ? "little endian" : "big endian") << " machine");
		}

		return endian == 1;
	}
コード例 #23
0
	ResourceHandle SoundClipManager::getResourceHandle(const std::string& name) {
		SoundClipNameMapIterator nit = m_sclipNameMap.find(name);
		if (nit != m_sclipNameMap.end()) {
			return nit->second->getHandle();
		}

		FL_WARN(_log, LMsg("SoundClipManager::getResourceHandle(std::string) - ") << "Resource " << name << " is undefined.");

		return 0;
	}
コード例 #24
0
ファイル: imagemanager.cpp プロジェクト: fifengine/fifengine
	ImagePtr ImageManager::getPtr(ResourceHandle handle) {
		ImageHandleMapConstIterator it = m_imgHandleMap.find(handle);
		if (it != m_imgHandleMap.end()) {
			return it->second;
		}

		FL_WARN(_log, LMsg("ImageManager::getPtr(ResourceHandle) - ") << "Resource handle " << handle << " is undefined.");

		return ImagePtr();
	}
コード例 #25
0
	void Instance::follow(const std::string& action_name, Instance* leader, const double speed) {
		initializeChanges();
		initializeAction(action_name);
		m_activity->m_actioninfo->m_target = new Location(leader->getLocationRef());
		m_activity->m_actioninfo->m_speed = speed;
		m_activity->m_actioninfo->m_leader = leader;
		leader->addDeleteListener(this);
		setFacingLocation(*m_activity->m_actioninfo->m_target);
		FL_DBG(_log, LMsg("starting action ") <<  action_name << " from" << m_location << " to " << *m_activity->m_actioninfo->m_target << " with speed " << speed);
	}
コード例 #26
0
	void SoundClipManager::removeAll() {
		//should always be equal
		assert (m_sclipHandleMap.size() == m_sclipNameMap.size());

		size_t count = m_sclipHandleMap.size();

		m_sclipHandleMap.clear();
		m_sclipNameMap.clear();

		FL_DBG(_log, LMsg("SoundClipManager::removeAll() - ") << "Removed all " << count << " resources.");
	}
コード例 #27
0
	void SoundClipManager::free(ResourceHandle handle) {
		SoundClipHandleMapConstIterator it = m_sclipHandleMap.find(handle);
		if (it != m_sclipHandleMap.end()) {
			if ( it->second->getState() == IResource::RES_LOADED) {
				it->second->free();
			}
			return;
		}

		FL_WARN(_log, LMsg("SoundClipManager::free(ResourceHandle) - ") << "Resource handle " << handle << " not found.");
	}
コード例 #28
0
ファイル: imagemanager.cpp プロジェクト: fifengine/fifengine
	ImagePtr ImageManager::getPtr(const std::string& name) {
		ImageNameMapIterator nit = m_imgNameMap.find(name);

		if (nit != m_imgNameMap.end()) {
			return nit->second;
		}

		FL_WARN(_log, LMsg("ImageManager::getPtr(std::string) - ") << "Resource " << name << " is undefined.");

		return ImagePtr();
	}
コード例 #29
0
	void SoundClipManager::free(const std::string& name) {
		SoundClipNameMapIterator nit = m_sclipNameMap.find(name);

		if (nit != m_sclipNameMap.end()) {
			if ( nit->second->getState() == IResource::RES_LOADED) {
				nit->second->free();
			}
			return;
		}

		FL_WARN(_log, LMsg("SoundClipManager::free(std::string) - ") << "Resource name " << name << " not found.");
	}
コード例 #30
0
ファイル: enginesettings.cpp プロジェクト: LilMouse/fifengine
	void EngineSettings::setLightingModel(uint32_t lighting) {
		if (lighting <= 2) {
			m_lighting = lighting;
			return;
		}

		FL_WARN(_log, LMsg("EngineSettings::setLightingModel() - ")
			<< lighting << " is not a valid lighting model." <<
			".  Setting the lighting model to the default value of 0 (off)");

		m_lighting = 0;
	}