Exemplo n.º 1
0
	void Document::_parse()
	{
		if (this->data == NULL)
		{
			if (this->fromResource)
			{
				hresource resource;
				resource.open(this->filename);
				this->_setup(resource, hrdir::normalize(this->filename));
			}
			else
			{
				hfile file;
				file.open(this->filename);
				this->_setup(file, hdir::normalize(this->filename));
			}
		}
		this->document = new rapidxml::xml_document<char>();
		try
		{
			RAPIDXML_DOCUMENT->parse<rapidxml::parse_validate_closing_tags | rapidxml::parse_no_string_terminators | rapidxml::parse_no_data_nodes>(this->data);
		}
		catch (rapidxml::parse_error& e)
		{
			hstr desc = e.what() + hstr(" [") + e.where<char>() + "]";
			delete RAPIDXML_DOCUMENT;
			this->document = NULL;
			throw XMLException(hsprintf("An error occcured parsing XML file '%s': %s", this->realFilename.cStr(), desc.cStr()), NULL);
		}
	}
Exemplo n.º 2
0
	hstr getPackageName()
	{
#ifndef _WINRT
		return hstr(kdGetenv("KD_APP_ID"));
#else
		return _HL_PSTR_TO_HSTR(Windows::ApplicationModel::Package::Current->Id->FamilyName);
#endif
	}
Exemplo n.º 3
0
	hstr Version::toString(int count) const
	{
		hstr result = hstr(this->major);
		if (count > 1)
		{
			result += "." + hstr(this->minor);
			if (count > 2)
			{
				result += "." + hstr(this->revision);
				if (count > 3)
				{
					result += "." + hstr(this->build);
				}
			}
		}
		return result;
	}
Exemplo n.º 4
0
	static void theoraLogMessage(std::string log)
	{
#ifdef _DEBUG
		if (hstr(log.c_str()).contains("dropped"))
			hlog::debug(logTag, log.c_str());
		else
			hlog::write(logTag, log.c_str());
#else
		hlog::write(logTag, log.c_str());
#endif
	}
Exemplo n.º 5
0
Arquivo: Url.cpp Projeto: yexihu/sakit
	hstr Url::getAbsolutePath(bool withPort) const
	{
		hstr result;
		result += HTTP_SCHEME + this->_encodeWwwFormComponent(this->host, HOST_ALLOWED);
		if (withPort && this->port > 0)
		{
			result += ":" + hstr(this->port);
		}
		harray<hstr> paths = this->path.split('/', -1, true);
		foreach (hstr, it, paths)
		{
			result += "/" + this->_encodeWwwFormComponent((*it), PATH_ALLOWED);
		}
	void SelectionContainer::setSelectedIndex(int value)
	{
		if (this->selectedIndex != value)
		{
			int oldIndex = this->selectedIndex;
			this->selectedIndex = (value < this->getItemCount() ? value : -1);
			if (this->selectedIndex != oldIndex)
			{
				this->_updateItem(oldIndex);
				this->_updateItem(this->selectedIndex);
				this->triggerEvent(Event::SelectedChanged, hstr(this->selectedIndex));
			}
		}
	}
Exemplo n.º 7
0
	void VideoObject::updateFrame()
	{
		if (mClip == NULL && mClipName != "")
		{
			_createClip();
		}
		if (mClip)
		{
			TheoraVideoFrame* f = mClip->getNextFrame();
			bool pop = true, restoringTexture = false;
			if (!mTexture->isLoaded())
			{
				restoringTexture = true;
				hlog::write(logTag, this->mClipName + ": Textures unloaded, reloading");
				int i = 1;
				foreach (aprilui::Texture*, it, mTextures)
				{
					hlog::write(logTag, this->mClipName + ": Reloading texture " + hstr(i));
					(*it)->load();
					i++;
				}
				if (!f)
				{
					hlog::write(logTag, this->mClipName + ": Texture restored, waiting for video frame to decode to fill texture.");
					int nReady = mClip->getNumReadyFrames();
					if (nReady == 0)
					{
						mClip->waitForCache();
					}
					f = mClip->getFrameQueue()->getFirstAvailableFrame();
					pop = false;
				}
				else
				{
					hlog::write(logTag, this->mClipName + ": Texture restored, using current frame to fill restored texture content.");
				}
			}
Exemplo n.º 8
0
	Color::Color(const char* hex)
	{
		this->set(hstr(hex));
	}
Exemplo n.º 9
0
	bool TinyXml_Node::_equals(const char* name)
	{
		return (hstr(this->node->Value()) == hstr(name));
	}
Exemplo n.º 10
0
	hstr Property::value()
	{
		return hstr(this->prop->Value());
	}
Exemplo n.º 11
0
	hstr Property::name()
	{
		return hstr(this->prop->Name());
	}
Exemplo n.º 12
0
	void SDL_Window::checkEvents()
	{
		SDL_Event sdlEvent;
		std::basic_string<unsigned int> text;
		while (SDL_PollEvent(&sdlEvent))
		{
			switch (sdlEvent.type)
			{
			case SDL_WINDOWEVENT:
				switch (sdlEvent.window.event)
				{
				case SDL_WINDOWEVENT_RESIZED:
					SDL_SetWindowSize(this->window, sdlEvent.window.data1, sdlEvent.window.data2);
					this->_setRenderSystemResolution(sdlEvent.window.data1, sdlEvent.window.data2, this->fullscreen);
					break;
				case SDL_WINDOWEVENT_FOCUS_GAINED:
					this->handleFocusChangeEvent(true);
					break;
				case SDL_WINDOWEVENT_FOCUS_LOST:
					this->handleFocusChangeEvent(false);
					break;
				case SDL_WINDOWEVENT_ENTER:
					if (this->isCursorVisible() && !this->cursorVisible)
					{
						SDL_ShowCursor(0);
					}
					this->cursorInside = true;
					break;
				case SDL_WINDOWEVENT_LEAVE:
					this->cursorInside = false;
					break;
				default:
					break;
				}
				break;
			case SDL_QUIT:
				if (this->handleQuitRequestEvent(true))
				{
					this->running = false;
				}
				break;
			case SDL_KEYUP:
			case SDL_KEYDOWN:
#ifdef __APPLE__
				// TODO - needs to be changed for SDL 2
				// on mac os, we need to handle command+q
				if (SDL_GetModState() & KMOD_META && (tolower(sdlEvent.key.keysym.unicode) == 'q' || sdlEvent.key.keysym.sym == SDLK_q))
				{
					if (this->handleQuitRequestEvent(true))
					{
						this->running = false;
					}
				}
				else
#elif defined(_WIN32)
				if (SDL_GetModState() & KMOD_ALT && sdlEvent.key.keysym.sym == SDLK_KP_ENTER)
				{
					this->toggleHotkeyFullscreen();
				}
				else
#endif
				{
					this->_handleSDLKeyEvent((sdlEvent.type == SDL_KEYUP ? KEY_UP : KEY_DOWN), sdlEvent.key.keysym.sym, 0);
				}
				break;
			case SDL_TEXTINPUT:
				text = hstr(sdlEvent.text.text).u_str();
				for_itert (unsigned int, i, 0, text.size())
				{
					this->_handleSDLKeyEvent(KEY_DOWN, 0, text[i]);
				}
				break;
			case SDL_TEXTEDITING:
				// TODO - needs to be implemented
				break;
			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEMOTION:
				this->_handleSDLMouseEvent(sdlEvent);
				break;
			default:
				break;
			}
		}
		// TODO - is this still needed in SDL 2?
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
		platform_cursorVisibilityUpdate();
#endif
	}
Exemplo n.º 13
0
Arquivo: twirl.c Projeto: malie/twirl
void
encodeToCNF() {

#define clause2(a,b)				\
  ({add_lit(a); add_lit(b); add_lit(0);})

#define clause3(a,b,c)					\
  ({add_lit(a); add_lit(b); add_lit(c); add_lit(0);})

#define implies(a,b)  clause2(-a, b);
#define implies_or(a,b,c) clause3(-a, b, c);
  
  int f, d, l, t, e, c, r;
  
  for (f = 0; f < S2; f++) {

    clause3(white(f), black(f), nblack(f));
    implies(white(f), -black(f));
    implies(white(f), -nblack(f));
    implies(nblack(f), -black(f));
    implies(nblack(f), -white(f));
    implies(black(f), -white(f));
    implies(black(f), -nblack(f));

    
    implies(white(f), numfield(f));
    implies(nblack(f), xblack(f));
    implies(nblack(f), numfield(f));
    implies(black(f), xblack(f));

    
    implies(white(f), -xblack(f));
    
    implies(black(f), -numfield(f));
    implies(xblack(f), -white(f));
    implies(numfield(f), -black(f));
    implies_or(numfield(f), white(f), nblack(f));
    implies_or(xblack(f), black(f), nblack(f));


    for (d = 0; d < S; d++) {
      implies(num(f,d), numfield(f));

      for (e = 0; e < S; e++) {
	// each digit at most once in each row
	t = same_row_but(f, e);
	if (t != f)
	  implies(num(f, d), -num(t, d));

	// each digit at most once in each column
	t = same_col_but(f, e);
	if (t != f)
	  implies(num(f, d), -num(t, d));

	// only one digit at most in each cell
	if (d != e)
	  implies(num(f, d), -num(f, e));
      }
    }
    // numfield(f) => exists d . num(f,d)
    add_lit(-numfield(f));
    for (d = 0; d < S; d++)
      add_lit(num(f, d));
    add_lit(0);

    // no single white fields
    int c = field_col(f);
    int r = field_row(f);
    add_lit(-white(f));
    if (c >= 1)
      add_lit(-xblack(field(c-1, r)));
    if (c < S-1)
      add_lit(-xblack(field(c+1, r)));
    if (r >= 1)
      add_lit(-xblack(field(c, r-1)));
    if (r < S-1)
      add_lit(-xblack(field(c, r+1)));
    add_lit(0);
  }

  
  
  // Encoding the straights:
  // A constellation like B W W W B is a straight of len 3,
  // when there are no blacks in between.
  // The two B's can also be the border.
  // Only straights of a length >= 2 are interesting.
  // The implications are encoded into clauses like this:
  //    a&b => x
  //    -(a&b) | x
  //    -a | -b | x

  for (f = 0; f < S2; f++) {
    int col = field_col(f);
    int row = field_row(f);
    for (c = col+1; c < S; c++) {
      // col is the first column
      // c is the last column (inclusively)
      int len = c-col+1;
      if (col > 0)
	add_lit(-xblack(same_row_but(f, col-1)));
      if (c <= S-2)
	add_lit(-xblack(same_row_but(f, c+1)));
      for (int s = 0; s < len; s++)
	add_lit(-white(same_row_but(f, col+s)));
      add_lit(hstr(f, len));
      add_lit(0);

      if (col > 0)
	implies(hstr(f,len), xblack(same_row_but(f, col-1)));
      if (c <= S-2)
	implies(hstr(f,len), xblack(same_row_but(f, c+1)));
      for (int s = 0; s < len; s++)
	implies(hstr(f,len), white(same_row_but(f, col+s)));

      // hstr(f,len) => hstrd(f,len,0) | hstrd(f,len,1) ...
      add_lit(-hstr(f, len));
      int largest_mind = S-len;
      for (int mind = 0; mind <= largest_mind; mind++)
	add_lit(hstrd(f, len, mind));
      add_lit(0);

      // hstrd(f,len,d) => num(f,d) | num(f,d+1) ...
      // for all the num()'s in the straight
      for (int sc = col; sc <= c; sc++) {
	int ff = same_row_but(f, sc);
	for (int mind = 0; mind <= largest_mind; mind++) {
	  add_lit(-hstrd(f, len, mind));
	  for (int dig = 0; dig < len; dig++)
	    add_lit(num(ff, mind+dig));
	  add_lit(0);
	}
      }
    }

    for (r = row+1; r < S; r++) {
      int len = r-row+1;
      if (row > 0)
	add_lit(-xblack(same_col_but(f, row-1)));
      if (r <= S-2)
	add_lit(-xblack(same_col_but(f, r+1)));
      for (int s = 0; s < len; s++)
	add_lit(-white(same_col_but(f, row+s)));
      add_lit(vstr(f, len));
      add_lit(0);

      if (row > 0)
	implies(vstr(f,len), xblack(same_col_but(f, row-1)));
      if (r <= S-2)
	implies(vstr(f,len), xblack(same_col_but(f, r+1)));
      for (int s = 0; s < len; s++)
	implies(vstr(f,len), white(same_col_but(f, row+s)));

      
      // and the vstr(f,len) def
      add_lit(-vstr(f, len));
      int largest_mind = S-len;
      for (int mind = 0; mind <= largest_mind; mind++)
	add_lit(vstrd(f, len, mind));
      add_lit(0);

      // vstrd(f,len,d) => num(f,d) | num(f,d+1) ...
      // for all the num()'s in the straight
      for (int sc = row; sc <= r; sc++) {
	int ff = same_col_but(f, sc);
	for (int mind = 0; mind <= largest_mind; mind++) {
	  add_lit(-vstrd(f, len, mind));
	  for (int dig = 0; dig < len; dig++)
	    add_lit(num(ff, mind+dig));
	  add_lit(0);
	}
      }
    }
  }
  printf("encoded into %i clauses\n", clausesptr);
}
Exemplo n.º 14
0
Arquivo: twirl.c Projeto: malie/twirl
void
printResults(PicoSAT *p, int* fields) {
  
  int verbose = 0;
  int y, x, d;
  for (y = 0; y < S; y++) {
    for (x = 0; x < S; x++) {
      int f = field(x, y);

      if (picosat_deref(p, black(f)) == 1)
	printf("B");
      else if (picosat_deref(p, nblack(f)) == 1)
	printf("N");
      /* else if (verbose && picosat_deref(p, numfield(f)) == 1) */
      /* 	printf("#"); */
      else if (verbose && picosat_deref(p, white(f)) == 1)
	printf("w");
      else 
	printf(" ");

      if (fields)
	printf("%c", fields[f] ? '.' : ' ');

      if (verbose) {
	if (picosat_deref(p, xblack(f)) == 1)
	  printf("x");
	else
	  printf(" ");}

      int fo = 0;
      for (d = 0; d < S; d++) {
	if (picosat_deref(p, num(f, d)) == 1) {
	  printf("%i", 1+d);
	  fo++;}}
      if (fo == 0) {
	printf("_");
	fo+=1;}
      while (fo < 2) {
	printf(" ");
	fo++;}
      
      printf(" ");
    }
    printf("\n");
  }
  return;
  for (int row = 0; row < S; row++) {
    for (int col = 0; col < S; col++) {
      for (int len = 2; len < S-col; len++) {
	if (picosat_deref(p, hstr(field(col, row), len)))
	  printf("hstr(field(%i,%i), %i) -> 1\n", col, row, len);
      }
    }
  }
  printf("\n");
  for (int row = 0; row < S; row++) {
    for (int col = 0; col < S; col++) {
      for (int len = 2; len < S-row; len++) {
	if (picosat_deref(p, vstr(field(col, row), len)))
	  printf("vstr(field(%i,%i), %i) -> 1\n", col, row, len);
      }
    }
  }
}
Exemplo n.º 15
0
	void VideoObject::_createClip(bool waitForCache)
	{
		hstr path = getFullPath();
		april::Image::Format textureFormat = _getTextureFormat();
		destroyResources();
		
		if (path.endsWith(".mp4"))
		{
			hstr archive = hresource::getArchive();
			if (archive != "")
			{
				path = hrdir::joinPath(archive, path);
			}
		}
		
		try
		{
			TheoraOutputMode mode = TH_RGBA;

			if (textureFormat == april::Image::FORMAT_RGBA)				mode = TH_RGBA;
			else if (textureFormat == april::Image::FORMAT_RGBX)		mode = TH_RGBX;
			else if (textureFormat == april::Image::FORMAT_BGRA)		mode = TH_BGRA;
			else if (textureFormat == april::Image::FORMAT_BGRX)		mode = TH_BGRX;
			else if (textureFormat == april::Image::FORMAT_ARGB)		mode = TH_ARGB;
			else if (textureFormat == april::Image::FORMAT_XRGB)		mode = TH_XRGB;
			else if (textureFormat == april::Image::FORMAT_ABGR)		mode = TH_ABGR;
			else if (textureFormat == april::Image::FORMAT_XBGR)		mode = TH_XBGR;
			else if (textureFormat == april::Image::FORMAT_RGB)			mode = TH_RGBX;
			else if (textureFormat == april::Image::FORMAT_BGR)			mode = TH_BGRX;
			else if (textureFormat == april::Image::FORMAT_GRAYSCALE)	mode = TH_GREY;
			int ram = april::getSystemInfo().ram;
			int precached = 16;
#if defined(_ANDROID) || defined(_WINRT) && !defined(_WINP8)
			// Android and WinRT libtheoraplayer uses an optimized libtheora which is faster, but still slower than
			// a native hardware accelerated codec. So (for now) we use a larger precache to counter it. Though, WinP8 can't handle this memory-wise.
			if (ram > 512) precached = 32;
#else
			if      (ram < 384) precached = 6;
			else if (ram < 512) precached = 8;
			else if (ram < 1024)
			{
				if (path.contains("lowres")) precached = 16;
				else precached = 8;
			}
#endif
			
			if (path.endsWith("mp4"))
			{
				try
				{
					if (april::window->getName() == "OpenKODE") // because mp4's are opened via apple's api, and that doesn't play nice with OpenKODE dir structure.
						mClip = gVideoManager->createVideoClip(hrdir::joinPath("res", path).cStr(), mode, precached);
					else
						mClip = gVideoManager->createVideoClip(path.cStr(), mode, precached);
				}
				catch (_TheoraGenericException& e)
				{
					// pass the exception further as a hexception so the general system can understand it
					throw Exception(e.getErrorText().c_str());
				}
			}
			else
			{
				if (!path.endsWith(".mp4") && ram > 256)
				{
					hresource r;
					r.open(path);
					unsigned long size = (unsigned long) r.size();
					TheoraDataSource* source;

					// additional performance optimization: preload file in RAM to speed up decoding, every bit counts on Android/WinRT ARM
					// but only for "reasonably" sized files
					if (size < 64 * 1024 * 1024)
					{
						hlog::write(logTag, "Preloading video file to memory: " + path);
						unsigned char* data = new unsigned char[size];
						r.readRaw(data, (int) size);
						source = new TheoraMemoryFileDataSource(data, size, path.cStr());
					}
					else
					{
						source = new AprilVideoDataSource(path);
					}
					
					mClip = gVideoManager->createVideoClip(source, mode, precached);
					r.close();
					hlog::write(logTag, "Created video clip.");
				}
				else
				{
					mClip = gVideoManager->createVideoClip(new AprilVideoDataSource(path), mode, precached);
				}
			}
		}
		catch (_TheoraGenericException& e)
		{
			throw Exception(e.getErrorText().c_str());
		}
		if (mClip->getWidth() == 0) throw Exception("Failed to load video file: " + path);
		mClip->setAutoRestart(mLoop);
		
		int tw = mClip->getWidth();
		int th = mClip->getHeight();
		april::RenderSystem::Caps caps = april::rendersys->getCaps();
		if (!caps.npotTexturesLimited && !caps.npotTextures)
		{
			tw = hpotceil(tw);
			th = hpotceil(th);
		}

		hlog::write(logTag, "Creating video textures for " + mClipName);
		april::Texture* tex;
		for (int i = 0; i < 2; i++)
		{
			tex = april::rendersys->createTexture(tw, th, april::Color::Clear, textureFormat, april::Texture::TYPE_VOLATILE);
			tex->setAddressMode(april::Texture::ADDRESS_CLAMP);
			mTexture = new aprilui::Texture(tex->getFilename() + "_" + hstr(i + 1), tex);

			mVideoImage = new aprilui::Image(mTexture, "video_img_" + hstr(i + 1), grect(mClip->getSubFrameOffsetX(), mClip->getSubFrameOffsetY(), mClip->getSubFrameWidth(), mClip->getSubFrameHeight()));
			mVideoImage->setBlendMode(mBlendMode);

			mTextures += mTexture;
			mVideoImages += mVideoImage;
		}

		if (waitForCache && mInitialPrecacheFactor > 0.0f)
		{
			float factor = hmax(2.0f / mClip->getNumPrecachedFrames(), mInitialPrecacheFactor);
			float precached = (float) mClip->getNumReadyFrames() / mClip->getNumPrecachedFrames();
			if (precached < factor)
			{
				hlog::writef(logTag, "Waiting for cache (%.1f%% / %.1f%%): %s", precached * 100.0f, factor * 100.0f, path.cStr());
				if (factor > 0)
				{
					precached = mClip->waitForCache(factor, mInitialPrecacheTimeout); // better to wait a while then to display an empty image
				}
				if (precached < factor)
				{
					hlog::writef(logTag, "Initial precache cached %.1f%% frames, target precache factor was %.1f%%", precached * 100.0f, factor * 100.0f);
				}
			}
		}

		if (mAudioName != "")
		{
			hstr category = "video";
			if (mAudioName.contains("/"))
			{
				harray<hstr> folders = hrdir::splitPath(mAudioName);
				hstr path_category = folders[folders.size() - 2];
				if (xal::manager->hasCategory(path_category)) category = path_category;
			}
			if (category == "video" && !xal::manager->hasCategory("video"))
			{
#if defined(_WINRT) || defined(_ANDROID)
				xal::manager->createCategory("video", xal::ON_DEMAND, xal::DISK);
#else
				if (april::getSystemInfo().ram >= 512)
				{
					xal::manager->createCategory("video", xal::STREAMED, xal::RAM);
				}
				else
				{
					xal::manager->createCategory("video", xal::STREAMED, xal::DISK);
				}
#endif
			}
			mSound = xal::manager->createSound(hrdir::joinPath(hrdir::joinPath(this->dataset->getFilePath(), "video"), mAudioName), category);
			if (mSound != NULL)
			{
				mAudioPlayer = xal::manager->createPlayer(mSound->getName());
				mTimer = new AudioVideoTimer(this, mAudioPlayer, mAudioSyncOffset);
			}
		}
		if (mTimer == NULL)
		{
			mTimer = new VideoTimer(this);
		}
		mClip->setTimer(mTimer);
		mClip->setPlaybackSpeed(mSpeed);
		update(0); // to grab the first frame.
	}