예제 #1
0
파일: guipage.cpp 프로젝트: imeteora/vdrift
static void ConnectActions(
	const std::string & actionstr,
	const ActionMap & actionmap,
	Signal & signal)
{
	size_t len = actionstr.size();
	size_t pos = 0;
	while (pos < len)
	{
		pos = actionstr.find_first_not_of(' ', pos);
		if (pos >= len)
			break;

		size_t posn = actionstr.find(' ', pos);
		size_t n = actionstr.find(':', pos);
		if (n < posn && n + 1 < len && actionstr[n + 1] == '"')
			posn = actionstr.find('"', n + 2) + 1;

		std::string action = actionstr.substr(pos, posn - pos);
		pos = posn;

		typename ActionMap::const_iterator it = actionmap.find(action);
		if (it != actionmap.end())
			it->second->connect(signal);
	}
}
예제 #2
0
void Club::updateAttackingPlay()
{
	if (!stadium->gameIsOn)	return;

	float stadium_width = stadium->playArea.width;
	float stadium_height = stadium->playArea.height;
	float goalEffect = (onTheRightGoal)?(-1.0):(1.0);
	sf::Vector2f ball_pos = stadium->ball->getPosition2();
	sf::Vector2f relative_ball_pos = ball_pos;
	if (onTheRightGoal) 
	{
		relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x;
		relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y;
	}

	// Update currentDefensiveLine
	currentDefensiveLine = 0.12 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) /
		( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) );
	if(onTheRightGoal) currentDefensiveLine = 1.0 - currentDefensiveLine;
	currentDefensiveLine *= stadium->playArea.width;
	
	// Update currentLeftmost
	float minX = 2.0;
	for (int i=1; i<11; i++)
	{
		if (lineUp[i]->tactical_x<minX) minX = lineUp[i]->tactical_x;
	}
	
	float howFar_defLine = onTheRightGoal?currentDefensiveLine:(stadium->playArea.width-currentDefensiveLine);
	currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (0.9-minX));
	currentWidth = 0.5 + 0.4 * attackingWidth;
	currentUppermost = ball_pos.y * (1.0-currentWidth);
	currentWidth *= stadium_height;

	findClosestPlayer();

	// If someone kicked the ball in the earlier frame, increase the time passed since the ball is kicked.
	if (sinceBallIsPassed>0) 
		sinceBallIsPassed += 1.0/60.0;

	SquadPosition* player;
	for (int j=0; j<11; j++)
	{
		player = lineUp[j];
		ActionMap possibleActions;
		for (int i=0; i<attackingActions.size(); i++)
		{
			float weight = attackingActions[i]->checkPreconditions(player,stadium);
			if (weight>0)
				possibleActions.insert( ActionPair(-1.0*weight,attackingActions[i]) );
		}
		if (possibleActions.size()>0)
			possibleActions.begin()->second->execute(player,stadium);
	}

};
예제 #3
0
   bool Layout::Update(const ActionMap & actions, unsigned int tElapsed)  {
      if (_layoutChanged)  {
         std::vector<Control*>::iterator iter = _children.begin();
         int curWide = _padding, curTall = _padding, maxHeight = 0;

         switch (_layout)  {
            case None:
               // Don't move controls
               _layoutChanged = false;
               break;
            case Grid:
               // Grid of controls
               for (; iter != _children.end(); iter++)  {
                  if (curWide + (*iter)->Width() > width)  {
                     curTall += maxHeight + _padding;
                     curWide = _padding;
                     maxHeight = 0;
                  }

                  if ((*iter)->Height() > static_cast<unsigned int>(maxHeight)) maxHeight = (int) (*iter)->Height();

                  _moveChildRelative(*iter, curWide, curTall);
                  curWide += (*iter)->Width() + _padding;
               }
               
               _layoutChanged = false;
               break;
            case HorizontalLine:
               // Horizontal line of controls
               for (; iter != _children.end(); iter++)  {
                  if (curWide + static_cast<int>((*iter)->Width()) > Right()) break;

                  _moveChildRelative(*iter, curWide, 0);
                  curWide += (*iter)->Width() + _padding;
               }

               _layoutChanged = false;
               break;
            case VerticalLine:
               // Vertical line of controls
               for (; iter != _children.end(); iter++)  {                 
                  if (curTall > Bottom()) break;

                  _moveChildRelative(*iter, 0, curTall);
                  curTall += (*iter)->Height() + _padding;
               }

               _layoutChanged = false;
               break;
         }
      }

      UpdateChildren(actions, tElapsed);

      return Collide(actions.GetInputState()->mouseX, actions.GetInputState()->mouseY);
   }
예제 #4
0
void Club::updateDefendingPlay()
{
	if (!stadium->gameIsOn)
		return;

	findClosestPlayer();

	float stadium_width = stadium->playArea.width;
	float stadium_height = stadium->playArea.height;
	float goalEffect = (onTheRightGoal)?(-1.0):(1.0);
	sf::Vector2f ball_pos = stadium->ball->getPosition2();
	sf::Vector2f relative_ball_pos = ball_pos;
	if (onTheRightGoal) 
	{
		relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x;
		relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y;
	}

	// Update currentDefensiveLine
	currentDefensiveLine = 0.08 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) / ( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) );
	if(onTheRightGoal) currentDefensiveLine = 1 - currentDefensiveLine;
	currentDefensiveLine *= stadium->playArea.width;

	// Update currentLeftmost
	float minX = 2.0;
	for (int i=1; i<11; i++)
	{
		if (lineUp[i]->defending_x<minX) minX = lineUp[i]->defending_x;
	}
	float howFar_defLine = ((onTheRightGoal)?(currentDefensiveLine):(stadium->playArea.width-currentDefensiveLine));
	currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (1.0-minX));

	// Update currentUppermost
	currentWidth = 0.5 + 0.4 * defendingWidth;
	currentUppermost = ball_pos.y * (1.0-currentWidth);
	currentWidth *= stadium_height;

	SquadPosition* player;
	for (int j=0; j<11; j++)
	{
		player = lineUp[j];
		ActionMap possibleActions;
		for (int i=0; i<defendingActions.size(); i++)
		{
			float weight = defendingActions[i]->checkPreconditions(player,stadium);
			if (weight>0)
				possibleActions.insert( ActionPair(-weight,defendingActions[i]) );
		}
		if (possibleActions.size()>0)
			possibleActions.begin()->second->execute(player,stadium);
	}
};
예제 #5
0
void SpriteDef::fixDeadAction()
{
    for (ActionsIter it = mActions.begin(), it_end = mActions.end();
         it != it_end; ++ it)
    {
        ActionMap *d = (*it).second;
        if (!d)
            continue;
        ActionMap::iterator i = d->find(SpriteAction::DEAD);
        ActionMap::iterator i2 = d->find(SpriteAction::STAND);
        // search dead action and check what it not same with stand action
        if (i != d->end() && i->second && i->second != i2->second)
            (i->second)->setLastFrameDelay(0);
    }
}
예제 #6
0
void SpriteDef::substituteAction(std::string complete, std::string with)
{
    for (ActionsConstIter it = mActions.begin(), it_end = mActions.end();
         it != it_end; ++ it)
    {
        ActionMap *d = (*it).second;
        if (!d)
            continue;
        if (d->find(complete) == d->end())
        {
            ActionMap::iterator i = d->find(with);
            if (i != d->end())
                (*d)[complete] = i->second;
        }
    }
}
예제 #7
0
bool InputManager::InvokeActions(Context* context, wxEvent* e, wxWindow* win)
{
    wxEventType eventType(e->GetEventType);

    EventTypeIter i = actions.find(eventType);
    if (i == actions.end()) return;

    ActionMap* actionMap = i->second;

    ActionMapIter j = actionMap->find(context);
    if (j == actionMap.end()) return;

    ActionSet* actionSet = j->second;

    wxString actionname;
    if (actionSet->matchesEvent(e, win, &actionname))
        return InvokeEvent(actionname, win);
    else
        return false;
}
예제 #8
0
void ConsoleState::Update(const ActionMap & actions, unsigned int tElapsed)  {
   const InputState & input = *actions.GetInputState();

   if (input.KeyDown(SDLKey::SDLK_PAGEUP))
      console.ScrollUp(3);

   if (input.KeyDown(SDLKey::SDLK_PAGEDOWN))
      console.ScrollDown(3);

   if (!input.KeyDown(SDLKey::SDLK_BACKQUOTE))
      _input->Update(actions, tElapsed);

   if (input.KeyDown(SDLKey::SDLK_RETURN)) {
      ConsoleCommand c = _parseCommand(_input->GetText());

      if (c.Command == "dumplog")  {

         if (c.Params.size() > 0) 
            console.Write(c.Params.at(0).c_str());
         else
            console.Write("console.log");

         console.AddLine("Successfully wrote console log to file!");

      } else if (c.Command == "showfps")  {

         Preferences.SetValue<bool>("SHOWFPS", !Preferences.GetValue<bool>("SHOWFPS"));
         if (Preferences.GetValue<bool>("SHOWFPS"))
            console.AddLine("Frames per second display on.");
         else
            console.AddLine("Frames per second display off.");

      } else
         console.AddLine(std::string("[echo] ") + _input->GetText());

      _input->SetText(std::string(""));
   }
}
예제 #9
0
void StandardMainLoop::init()
{
   #ifdef TORQUE_DEBUG
   gStartupTimer = PlatformTimer::create();
   #endif
   
   #ifdef TORQUE_DEBUG_GUARD
      Memory::flagCurrentAllocs( Memory::FLAG_Global );
   #endif

   Platform::setMathControlStateKnown();
   
   // Asserts should be created FIRST
   PlatformAssert::create();
   
   ManagedSingleton< ThreadManager >::createSingleton();
   FrameAllocator::init(TORQUE_FRAME_SIZE);      // See comments in torqueConfig.h

   // Yell if we can't initialize the network.
   if(!Net::init())
   {
      AssertISV(false, "StandardMainLoop::initCore - could not initialize networking!");
   }

   _StringTable::create();

   // Set up the resource manager and get some basic file types in it.
   Con::init();
   Platform::initConsole();
   NetStringTable::create();

   // Use debug output logging on the Xbox and OSX builds
#if defined( _XBOX ) || defined( TORQUE_OS_MAC )
   DebugOutputConsumer::init();
#endif

   // init Filesystem first, so we can actually log errors for all components that follow
   Platform::FS::InstallFileSystems(); // install all drives for now until we have everything using the volume stuff
   Platform::FS::MountDefaults();

   // Set our working directory.
   Torque::FS::SetCwd( "game:/" );

   // Set our working directory.
   Platform::setCurrentDirectory( Platform::getMainDotCsDir() );

   Processor::init();
   Math::init();
   Platform::init();    // platform specific initialization
   RedBook::init();
   Platform::initConsole();
   
   ThreadPool::GlobalThreadPool::createSingleton();

   // Initialize modules.
   
   ModuleManager::initializeSystem();
         
   // Initialise ITickable.
#ifdef TORQUE_TGB_ONLY
   ITickable::init( 4 );
#endif

#ifdef TORQUE_ENABLE_VFS
   // [tom, 10/28/2006] Load the VFS here so that it stays loaded
   Zip::ZipArchive *vfs = openEmbeddedVFSArchive();
   gResourceManager->addVFSRoot(vfs);
#endif

   Con::addVariable("timeScale", TypeF32, &ATTS(gTimeScale), "Animation time scale.\n"
	   "@ingroup platform");
   Con::addVariable("timeAdvance", TypeS32, &ATTS(gTimeAdvance), "The speed at which system processing time advances.\n"
	   "@ingroup platform");
   Con::addVariable("frameSkip", TypeS32, &ATTS(gFrameSkip), "Sets the number of frames to skip while rendering the scene.\n"
	   "@ingroup platform");

   Con::setVariable( "defaultGame", StringTable->insert("scripts") );

   Con::addVariable( "_forceAllMainThread", TypeBool, &ThreadPool::getForceAllMainThread(), "Force all work items to execute on main thread. turns this into a single-threaded system. Primarily useful to find whether malfunctions are caused by parallel execution or not.\n"
	   "@ingroup platform" );

#if defined( TORQUE_MINIDUMP ) && defined( TORQUE_RELEASE )
	Con::addVariable("MiniDump::Dir",	TypeString, &gMiniDumpDir);
	Con::addVariable("MiniDump::Exec",	TypeString, &gMiniDumpExec);
	Con::addVariable("MiniDump::Params", TypeString, &gMiniDumpParams);
	Con::addVariable("MiniDump::ExecDir", TypeString, &gMiniDumpExecDir);
#endif
   
   ActionMap* globalMap = new ActionMap;
   globalMap->registerObject("GlobalActionMap");
   Sim::getActiveActionMapSet()->pushObject(globalMap);
   
   // Do this before we init the process so that process notifiees can get the time manager
   tm = new TimeManager;
   tm->timeEvent.notify(&::processTimeEvent);
   
   // Start up the Input Event Manager
   INPUTMGR->start();

   Sampler::init();

   // Hook in for UDP notification
   Net::smPacketReceive.notify(GNet, &NetInterface::processPacketReceiveEvent);

   #ifdef TORQUE_DEBUG_GUARD
      Memory::flagCurrentAllocs( Memory::FLAG_Static );
   #endif
}
예제 #10
0
파일: guipage.cpp 프로젝트: imeteora/vdrift
static void ParseActions(
	const std::string & actions,
	const ActionMap & vactionmap,
	const WidgetMap & widgetmap,
	const WidgetListMap & widgetlistmap,
	ActionValSet & action_val_set,
	ActionValnSet & action_valn_set)
{
	size_t len = actions.size();
	size_t pos = 0;
	while(pos < len)
	{
		pos = actions.find_first_not_of(' ', pos);
		if (pos >= len)
			break;

		// get next action with value
		size_t posn = actions.find(' ', pos);
		size_t n = actions.find(':', pos);
		if (n > posn)
		{
			pos = posn;
			continue;
		}

		if (n + 1 < len && actions[n + 1] == '"')
			posn = actions.find('"', n + 2) + 1;

		std::string action = actions.substr(pos, posn - pos);
		std::string aname = actions.substr(pos, n - pos);

		pos = posn;

		// check if action is in vactionmap
		typename ActionMap::const_iterator vai = vactionmap.find(aname);
		if (vai != vactionmap.end())
		{
			action_val_set.insert(std::make_pair(action, vai->second));
			continue;
		}

		size_t wn = aname.find('.');
		if (wn == 0 || wn == std::string::npos)
			continue;

		std::string wname = aname.substr(0, wn);
		std::string pname = aname.substr(wn + 1);

		// check if action is setting a widget property
		typename WidgetMap::const_iterator wi = widgetmap.find(wname);
		if (wi != widgetmap.end())
		{
			Slot1<const std::string &> * pslot;
			if (wi->second->GetProperty(pname, pslot))
				action_val_set.insert(std::make_pair(action, pslot));
			continue;
		}

		// check if action is setting a widget list property (only valid for control lists)
		typename WidgetListMap::const_iterator wli = widgetlistmap.find(wname);
		if (wli != widgetlistmap.end())
		{
			Slot2<int, const std::string &> * pslot;
			if (wli->second->GetProperty(pname, pslot))
				action_valn_set.insert(std::make_pair(action, pslot));
		}
	}
}
예제 #11
0
void swap (ActionMap& source1, ActionMap& source2)
{
  source1.Swap (source2);
}