예제 #1
0
string CViewRenderer::renderFile(const IRenderingContext * context, const string & sourceFile, CDT & data, bool ret) throw (CException)
{
    boost::filesystem::path sourcePath(sourceFile);
    if (!boost::filesystem::exists(sourcePath)) {
        throw CException("View file \"" + sourceFile + "\" does not exist.");
    }
    string viewFile = getViewFile(sourceFile);
    boost::filesystem::path viewPath(viewFile);
    if (!boost::filesystem::exists(viewPath) || boost::filesystem::last_write_time(sourcePath) > boost::filesystem::last_write_time(viewPath)) {
        if (generateViewFile(sourceFile, viewFile)) {
            chmod(viewFile.c_str(), filePermission);
        } else {
            throw CException("Can't generate view file \"" + viewFile + "\" from source file \"" + sourceFile + "\".");
        }
    }

    if (context != 0) {
    	return context->renderInternal(viewFile, data, ret);
    }

	stringstream os;
	StreamOutputCollector outputCollector(os);
    TDynamicTemplateCacheMap::const_iterator found = _templateCache.find(viewFile);

	VMLoader * oLoader = 0;
	if (found == _templateCache.end()) {
		oLoader = new VMFileLoader(viewFile.c_str());
		_templateCache[viewFile.c_str()] = boost::shared_ptr<VMLoader>(oLoader);
	} else {
		oLoader = found->second.get();
	}

	PROFILE_BEGIN("CViewRenderer::rendering template bytecode of \"" + viewFile + "\"")
	UINT_32 iIP = 0;
	VM * vm = Cws::app()->getTemplateEngine()->getVM();
	const VMMemoryCore * pVMMemoryCore = oLoader->GetCore();
	vm->Init(pVMMemoryCore, &outputCollector, 0);
	vm->Run(pVMMemoryCore, &outputCollector, iIP, data, 0);
	PROFILE_END()

	if (ret) {
		return os.str();
	} else {
		Cws::app()->getOutputStack().top()->echo(os.str());
		return "";
	}
}
예제 #2
0
		ReturnValue GraphicsService::Render()
		{
			PostEffect::Begin();

			Render::SetOrthoMode();
			Render::EnableOrthoMode();
			Render::EnableAlphaBlend();

			GL_CHECK( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );

			PROFILE_BEGIN("Batcher");
			Batcher::FlushAll();
			PROFILE_END();

			PostEffect::End();

			Debug::OpenGL::FlushErrors("GraphicsService::Render()");
			return RETURN_VALUE_OK;
		}
예제 #3
0
CDbDataReader CDbCommand::_queryInternal(const CCommandParameterMap & params) throw (CDbException)
{
	mergeParametersWith(params);
	string parametersDump = _makeParametersDump(_params);
#ifdef CWS_DEBUG
	Cws::trace("Executing SQL: " + _text + parametersDump, "system.db.CDbCommand");
#endif

	try {
		SAConnection * connection = _connection->getConnection();
		_saCommand = new SACommand(connection, _text.c_str(), SA_CmdSQLStmt);
		if (connection->Client() == SA_MySQL_Client) {
			_saCommand->setOption("UseStatement") = "TRUE";
		}
		for (CCommandParameterMap::const_iterator iter = _params.begin(); iter != _params.end(); ++iter) {
			iter->second.get()->bind(_saCommand);
		}
		PROFILE_BEGIN("Executing SQL: " + _text + parametersDump);
		_saCommand->Execute();
		PROFILE_END();
		return CDbDataReader(_saCommand);

	} catch (const SAException & e) {

		string message = e.ErrText().GetMultiByteChars();
		stringstream ss;
		ss << "CDbCommand::_queryInternal() failed: " << message
		   << ". Code: " << (int)e.ErrNativeCode();
		Cws::log(
			"CDbCommand::_queryInternal() failed: " + ss.str()
			+ ". The SQL statement executed was: " + _text + "."
		);
#ifdef CWS_DEBUG
		message += ". The SQL statement executed was: " + _text + parametersDump;
#endif
		throw CDbException(
			"CDbCommand failed to execute the SQL statement: " + message,
			(int)e.ErrNativeCode()
		);
	}
}
예제 #4
0
파일: lua_util.cpp 프로젝트: miho/ugcore
lua_State* GetDefaultLuaState()
{
//	if the state has not already been opened then do it now.
	if(!theLuaState)
	{
		PROFILE_BEGIN(CreateLUARegistry);
		if(!g_pRegistry){
		//	store a pointer to the registry and avoid multiple callback registration
			g_pRegistry = &ug::bridge::GetUGRegistry();
			g_pRegistry->add_callback(UpdateScriptAfterRegistryChange);
		}
		
	//	open a lua state
		theLuaState = lua_open();
	//	open standard libs
		luaL_openlibs(theLuaState);

	//	make metatables available in lua script
		lua_register(theLuaState, "ug_get_metatable", UGGetMetatable );

	//	make base class check available in lua script
		lua_register(theLuaState, "ug_is_base_class", UGIsBaseClass);

	//	make dim check available in lua script
		lua_register(theLuaState, "ug_dim_compiled", UGDimCompiled);

	//	make algebra check available in lua script
		lua_register(theLuaState, "ug_algebra_compiled", UGAlgebraCompiled);

	//	make class name available in lua script
		lua_register(theLuaState, "ug_class_name", UGGetClassName);
		lua_register(theLuaState, "ug_class_group", UGGetClassGroup);

	//	create lua bindings for registered functions and objects
		ug::bridge::lua::CreateBindings_LUA(theLuaState, *g_pRegistry);
	}
	
	return theLuaState;
}
예제 #5
0
void RendererCommon::PostRenderBuckets() {
  XTRACE_FUNCTION;

  for (uint i = 0; i < m_OrderedBuckets.Size(); ++i) {
    Bucket* pBucket = m_OrderedBuckets[i];
    pBucket->m_Meshes.Clear();  // TODO: Later, only clear transient meshes,
                                // keep long-term ones around (as defined by a
                                // heuristic)
  }

#if BUILD_DEV
  PROFILE_BEGIN(RendererCommon_DeferredDeleteDebugMeshes);
  const uint NumDeferredDeleteDebugMeshes = m_DeferredDeleteDebugMeshes.Size();
  for (uint DebugMeshIndex = 0; DebugMeshIndex < NumDeferredDeleteDebugMeshes;
       ++DebugMeshIndex) {
    Mesh* pDebugMesh = m_DeferredDeleteDebugMeshes[DebugMeshIndex];
    ASSERT(pDebugMesh);
    SafeDelete(pDebugMesh);
  }
  m_DeferredDeleteDebugMeshes.Clear();
  PROFILE_END;
#endif
}
예제 #6
0
long unsigned int CDbCommand::execute(const CCommandParameterMap & params) throw (CDbException)
{
	mergeParametersWith(params);
	string parametersDump = _makeParametersDump(_params);
#ifdef CWS_DEBUG
	Cws::trace("Executing SQL: " + _text + parametersDump, "system.db.CDbCommand");
#endif
	try {
		SAConnection * connection = _connection->getConnection();
		_saCommand = new SACommand(connection);
		_saCommand->setCommandText(_text.c_str());
		for (CCommandParameterMap::const_iterator iter = _params.begin(); iter != _params.end(); ++iter) {
			iter->second.get()->bind(_saCommand);
		}
		PROFILE_BEGIN("Executing SQL: " + _text + parametersDump);
		_saCommand->Execute();
		connection->Commit();
		PROFILE_END();
		return _saCommand->RowsAffected();

	} catch (const SAException & e) {

		string message = e.ErrText().GetMultiByteChars();
		Cws::log(
			"CDbCommand::execute() failed: " + message
			+ ". The SQL statement executed was: " + _text + "."
		);
#ifdef CWS_DEBUG
		message += ". The SQL statement executed was: " + _text + parametersDump;
#endif
		throw CDbException(
			"CDbCommand failed to execute the SQL statement: " + message,
			(int)e.ErrNativeCode()
		);
	}
	return 0;
}
예제 #7
0
void SweeperStatisticsScene::update(float dt)
{
	int count = CONSTANTS.TicksPerGeneration+1;

	PROFILE_RESET_ALL();

	for (int i=0; i<count; ++i)
	{
		// 满足条件,进入新时代;
		if (m_generationCurrentTicks >= CONSTANTS.TicksPerGeneration)
		{
			// 进入新时代;
			GeneticAlgorithm::instance()->epoch();

			this->startGeneration();

			// 绘制统计图;
			this->drawStatistics();

			PROFILE_PRINT_ALL();

			return;
		}
		++m_generationCurrentTicks;



		// 当前时代更新处理;
		for (auto sweeper : m_sweepers)
		{
			// 获取最近地雷;
			MineObject *pClosestMine = nullptr;
			Fixed closestDistance2 = 9999*9999;
			for (auto mine : m_mines)
			{
				const auto &minePos = mine->getFixedPosition();
				const auto &fixedPosition = sweeper->getFixedPosition();

				auto len2 = minePos.distanceSquared(fixedPosition);
				if (len2 < closestDistance2)
				{
					closestDistance2 = len2;
					pClosestMine = mine;
				}
			}

			// 找不到地雷;
			if (!pClosestMine)
			{
				// TODO: 该怎么做?;
				return;
			}
			const auto &closestPos = pClosestMine->getFixedPosition();

			PROFILE_BEGIN("update nn");
			// 更新神经网络和位置;
			bool ret = sweeper->update(closestPos);
			if (!ret)
			{
				MessageBox("update sweeper error!", "error");
				this->unscheduleAllSelectors();
				return;
			}
			PROFILE_END("update nn");

			// 检查碰撞;
			bool bCollision = sweeper->checkCollision(closestPos);
			if (bCollision)
			{
				// 更新适应值;
				sweeper->increaseFitness();

				// 销毁地雷,并在其他地方产生一个新的地雷;
				pClosestMine->setFixedPosition(this->randomFixedPosition());
			}

		}
	}
}
예제 #8
0
파일: run.cpp 프로젝트: joaormatos/anaconda
void GameManager::draw()
{
    int window_width, window_height;
    platform_get_size(&window_width, &window_height);
    if (window_width <= 0 || window_height <= 0)
        // for some reason, GLFW sets these properties to 0 when minimized.
        return;

#ifdef CHOWDREN_FORCE_REMOTE
    platform_set_remote_value(CHOWDREN_REMOTE_TARGET);
#endif

    PROFILE_FUNC();

    PROFILE_BEGIN(platform_begin_draw);
    platform_begin_draw();
    PROFILE_END();

#ifdef CHOWDREN_USE_SUBAPP
    Frame * render_frame;
    if (SubApplication::current != NULL &&
        SubApplication::current->flags & VISIBLE) {
        render_frame = &SubApplication::current->subapp_frame;
    } else
        render_frame = frame;
#else
    Frame * render_frame = frame;
#endif

    PROFILE_BEGIN(frame_draw);
#ifdef CHOWDREN_IS_WIIU
    int remote_setting = platform_get_remote_value();
    if (remote_setting == CHOWDREN_HYBRID_TARGET) {
        platform_set_display_target(CHOWDREN_REMOTE_TARGET);
        render_frame->draw(CHOWDREN_REMOTE_TARGET);
        draw_fade();
        platform_set_display_target(CHOWDREN_TV_TARGET);
        render_frame->draw(CHOWDREN_TV_TARGET);
        draw_fade();
    } else {
        platform_set_display_target(CHOWDREN_TV_TARGET);
        render_frame->draw(CHOWDREN_HYBRID_TARGET);
        draw_fade();
        if (remote_setting == CHOWDREN_REMOTE_TARGET) {
            platform_clone_buffers();
            platform_set_display_target(CHOWDREN_REMOTE_TARGET);
            render_frame->draw(CHOWDREN_REMOTE_ONLY);
        }
    }
#elif CHOWDREN_IS_3DS
    platform_set_display_target(CHOWDREN_TV_TARGET);
    render_frame->draw(CHOWDREN_TV_TARGET);
    draw_fade();

    // only draw 30 fps on bottom screen
    static int draw_interval = 0;
    if (draw_interval == 0) {
        platform_set_display_target(CHOWDREN_REMOTE_TARGET);
        render_frame->draw(CHOWDREN_REMOTE_TARGET);
        draw_fade();
    }
    draw_interval = (draw_interval + 1) % 3;
#else
    render_frame->draw(CHOWDREN_HYBRID_TARGET);
    draw_fade();
#endif
    PROFILE_END();

    Render::set_offset(0, 0);

#ifdef CHOWDREN_IS_DEMO
    if (show_build_timer > 0.0) {
        std::string date(__DATE__);
        std::string tim(__TIME__);
        std::string val = date + " " + tim;
        glPushMatrix();
        glTranslatef(50, 50, 0);
        glScalef(5, -5, 5);
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        get_font(24)->Render(val.c_str(), val.size(), FTPoint(),
                             FTPoint());
        glPopMatrix();
    }
#endif

    PROFILE_BEGIN(platform_swap_buffers);
    platform_swap_buffers();
    PROFILE_END();
}
예제 #9
0
void CTemplateView::run() throw (CException)
{
	PROFILE_BEGIN("CTemplateView::run(). View file: " + _viewFile);
	Cws::app()->getViewRenderer()->renderFile(0, _viewFile, _data, false);
	PROFILE_END();
}