void attachDefaultTargetCallbacks(osg::Node* node, Target* target)
	{
		if (!node) {
			osg::notify() << "attachDefaultTargetCallbacks: Can't attach callbacks to NULL node" << std::endl;
			return;
		}

		if (!target) {
			osg::notify() << "attachDefaultTargetCallbacks: Can't attach callbacks with NULL target" << std::endl;
			return;
		}

		addEventCallback(node, new TargetTransformCallback(target));
		addEventCallback(node, new TargetVisibilityCallback(target));
	}
void CodecAwareConduit::registerCallbackByName(string event_name, EventCallback cb){
    scoped_lock lock(conduit_mutex);
    
    if(event_name.size() == 0){
        throw SimpleException("Attempt to register callback for empty event name");
    }
    
    // We can't register a callback by name until we have the remote codec
    waitForRemoteCodec(lock);
    
    callbacks_by_name[event_name] = cb;
    addEventCallback(event_name, cb);
}
void CodecAwareConduit::rebuildEventCallbacks(){
    // This is called internally from methods that already hold conduit_mutex
    
    //std::cerr << "rebuildEventCallbacks called in: " << this << std::endl;
    
    unregisterCallbacks(name_defined_callback_key);
    
    for (map<string, EventCallback>::iterator i = callbacks_by_name.begin(); i != callbacks_by_name.end(); ++i) {
        string evt_name = (*i).first;
        EventCallback cb = (*i).second;
        addEventCallback(evt_name, cb);
    }
    
}
Exemple #4
0
Game::Game(Application *app, Widget *parent) : Widget(parent) {
  this->app = app;

  radius = 3;
  techTree = TechTree::fromFile(res_path("techtree.json"), app->getImgMgr());
  map = Map::fromFile(res_path("map"), app->getImgMgr());

  players.push_back(new Player("Raymond", techTree, map));
  players.push_back(new Player("Jean-Pierre", techTree, map));

  fogTileMap = new TileMap("fow", app->getImgMgr());
  fog = new FoW(map, fogTileMap);
  foglight = new FoW(map, fogTileMap, FoW::LIGHT);

  EventCallback *func;
  func = new EventMethodCallback<Game>(this, &Game::onMousePressed);
  addEventCallback("MousePressed", func);
}
int main() {
	auto armyEngine = ArmyEngine::getInstance();
	armyEngine->addEntity(createCursor());
	armyEngine->addEntity(createButton("Resume", 100, 100));
	/*armyEngine->addEntity(createButton("Restart", 100, 60));
	armyEngine->addEntity(createButton("Quit", 100, 110));
	armyEngine->addEntity(createButton("Other3", 100, 160));
	armyEngine->addEntity(createButton("Other1", 250, 10));
	armyEngine->addEntity(createButton("Other2", 250, 60));
	armyEngine->addEntity(createButton("Other3", 250, 110));
	armyEngine->addEntity(createButton("Other3", 250, 160));
	armyEngine->addEntity(createButton("Other1", 400, 10));
	armyEngine->addEntity(createButton("Other2", 400, 60));
	armyEngine->addEntity(createButton("Other3", 400, 110));
	armyEngine->addEntity(createButton("Other3", 400, 160));
	armyEngine->addEntity(createButton("Other1", 550, 10));
	armyEngine->addEntity(createButton("Other2", 550, 60));
	armyEngine->addEntity(createButton("Other3", 550, 110));
	armyEngine->addEntity(createButton("Other3", 550, 160));
	armyEngine->addEntity(createButton("Other1", 700, 10));
	armyEngine->addEntity(createButton("Other2", 700, 60));
	armyEngine->addEntity(createButton("Other3", 700, 110));
	armyEngine->addEntity(createButton("Other3", 700, 160));*/


	//create the close program event
	armyEngine->addEventCallback(EnumEventType::EVENT_CLOSED, [] (int eventIndex) {
		auto armyEngine = ArmyEngine::getInstance();
		auto window = armyEngine->getWindow();
		window->close();
		return 0;
	});


	armyEngine->runMainLoop();

	return 0;
}