Пример #1
0
void initMap(struct Map * map) {
	// make rooms
	struct Room * hall = createRoom("The Great Hall");
	struct Room * throne = createRoom("The Throne Room");
	struct Room * arena = createRoom("The Arena");
	struct Room * kitchen = createRoom("The Kitchen");

	// link rooms
	hall->north = throne;

	throne->east = kitchen;
	throne->south = hall;
	throne->west = arena;

	arena->east = throne;
	kitchen->west = throne;

	// add minotaur to arena
	arena->bad_guy = createMonster("Minotaur", 12);

	// set starting location
	map->start = hall;
	map->location = map->start;

}
Пример #2
0
int main( int argc, char **argv )
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // construct the viewer.
    osgViewer::Viewer viewer;

    // load the nodes from the commandline arguments.
    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);

    // if not loaded assume no arguments passed in, try use default mode instead.
    if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt");

    // create a room made of foor walls, a floor, a roof, and swinging light fitting.
    osg::Node* rootnode = createRoom(loadedModel);

    // run optimization over the scene graph
    osgUtil::Optimizer optimzer;
    optimzer.optimize(rootnode);

    // add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode );


    // create the windows and run the threads.
    viewer.realize();

    viewer.getCamera()->setCullingMode( viewer.getCamera()->getCullingMode() & ~osg::CullStack::SMALL_FEATURE_CULLING);

    return viewer.run();
}
ChatRoom* ChatManagerImplementation::createRoomByFullPath(const String& path) {
	StringTokenizer tokenizer(path);
	tokenizer.setDelimeter(".");

	String game;
	tokenizer.getStringToken(game);

	ChatRoom* gameRoom = getGameRoom(game);

	if (gameRoom == NULL)
		return NULL;

	String channel;

	ChatRoom* room = gameRoom;
	while (tokenizer.hasMoreTokens()) {
		tokenizer.getStringToken(channel);

		if (room->getSubRoom(channel) == NULL)
			break;
		else
			room = room->getSubRoom(channel);
	}

	if (room == gameRoom)
		return NULL;

	if (room->isPrivate())
		return NULL;

	ChatRoom* newRoom = createRoom(channel, room);
	room->addSubRoom(newRoom);

	return newRoom;
}
Пример #4
0
void SchoolRoom::reset(Ref* sender)
{
	SchoolRoomFactory sf;
	
	auto layer = (cocos2d::Layer *)this->getParent()->getChildByTag(1);
	
	sf.Remove(layer);

	layerNumber++; if (layerNumber > 6) layerNumber = 0;

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto backGround = createRoom(layerNumber);
	backGround->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	layer->addChild(backGround, 0);


	auto resetbotton = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(SchoolRoom::reset, this));

	auto menu = Menu::create(resetbotton, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);
	if (layerNumber > 5) return;
	sf.Init(layer);
}
Пример #5
0
bool SchoolRoom::init()
{
	srand((unsigned)time(NULL));

	if (!Layer::init())
	{
		return false;
	}
	Size WinSize = Director::getInstance()->getWinSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	layerNumber = 0;

	auto backGround = createRoom(layerNumber);

	backGround->setPosition(Vec2(WinSize.width / 2 + origin.x, WinSize.height / 2 + origin.y));

	this->addChild(backGround, 0);
	
	auto resetbotton = MenuItemImage::create(
											 "CloseNormal.png",
										     "CloseSelected.png",
											 CC_CALLBACK_1(SchoolRoom::reset, this));

	auto menu = Menu::create(resetbotton, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);

	return true;
}
Пример #6
0
static Room *initRoom(RoomParsed *roomParsed) {

   int i;
   GList *nextEventHandler;

   GArray *creatureNames = roomParsed->creatures; /* creatures in the room */
   GArray *objectNames = roomParsed->objects;     /* objects in the room */
   Room *room = createRoom(FALSE);                /* actual room object */

   /* list of objects referenced by a name */
   GList *synonymList;

   /* don't free these dstring_t objects when we free the parsed rooms table! */
   room->name = roomParsed->name;
   room->title = roomParsed->title;
   room->description = roomParsed->description;

   /* rooms will be connected later by another function */
   room->north = NULL;
   room->south = NULL;
   room->east  = NULL;
   room->west  = NULL;
   room->in    = NULL;
   room->out   = NULL;
   room->up    = NULL;
   room->down  = NULL;

   room->messages = roomParsed->messages;

   /* add creatures to the room */
   for (i = 0; i < creatureNames->len; i++) {
      room->creatureList = addCreature(room->creatureList, room->creatureByName,
         g_array_index(creatureNames, dstring_t, i));
   }

   /* add objects to the room */
   for (i = 0; i < objectNames->len; i++) {

      dstring_t *objectName = g_array_index(objectNames, dstring_t, i);
      Object *object = g_hash_table_lookup(g_objects, (char *)dstrview(objectName));

      room->objectList = addObject(room->objectList, room->objectByName, objectName);
      object->state.owner.entity = room;
      object->state.owner.type = entity_room;
   }

   /* initialize lua state for room */
   room->L = initLuaState(roomParsed->scripts);

   /* initialize entity-specific event handlers */
   nextEventHandler = roomParsed->eventHandlers;
   while (NULL != nextEventHandler) {
      EventHandlerParsed *handler = (EventHandlerParsed *)nextEventHandler->data;
      addLuaEventHandler(dstrview(handler->event), room->events,
         dstrview(handler->function), room->L);
      nextEventHandler = g_list_next(nextEventHandler);
   }

   return room;
}
void ChatManagerImplementation::initiatePlanetRooms() {
	// Planet Chat
	for (int i = 0; i < server->getZoneCount(); ++i) {
		ManagedReference<Zone*> zone = server->getZone(i);

		if (zone == NULL)
			continue;

		Locker locker(zone);

		ChatRoom* planetRoom = createRoom(zone->getZoneName(), core3Room);
		core3Room->addSubRoom(planetRoom);

		ChatRoom* planetaryChat = createRoom("Planet", planetRoom);
		planetRoom->addSubRoom(planetaryChat);
		zone->setChatRoom( planetaryChat );

	}
}
Пример #8
0
int main()
{
	Interpreter itpr(new UnitTest());
	CommandListNode *nlist = Interpreter::parse("if isset show hoge set show msghoge else set msg piyo end");
	L("test start");
	itpr.execEvent(nlist);
	for ( auto a : *nlist )
	{
		delete a;
	}
	nlist->clear();
	delete nlist;
	nlist = nullptr;
	if ( nlist != NULL ) delete nlist;

	L("start hogepiyo");
	CommandNode *nod = new CommandNode("hoge", "piyo");
	delete nod;

	auto room = createRoom();
	//auto itr = room.find("room_door");
	//auto pair = room->begin();
	//L(pair->second->at(0));
	auto itr = room->find("room_door");
	L(itr->second->at(2));

	L(StrUtil::trim("  hoge    "));

	auto data = "a = b\ntesttest\n\nabc=def ef\nhoge=piyo\n";
	auto amap = StrUtil::makeAssocMap(data);
	L(amap->find("a")->second);
	L(amap->find("abc")->second);
	L(amap->find("hoge")->second);

	std::string hoge;
	L(hoge);
	if ( hoge == "" )
	{
		L("empty");
	}
	hoge += "piyo";
	hoge += ":";
	hoge += "test";
	L(hoge);

	std::string st = "9423175742";
	L(st[2]);
	for ( char ch : st )
	{
		L(atoi(&ch));
	}

	return 0;
}
void Lobby::onCreateRoom()
{
    //FIXME: popup
    //打开房间设置面板
    if(roomSet!= NULL){roomSet->close();}
    roomSet = new RoomSet(logic->getIdentity());
    roomSet->show();
    connect(roomSet, SIGNAL(createRoom()), this, SLOT(onOpenRoom()));
    connect(roomSet, SIGNAL(backToLobby()), this, SLOT(onBackToLobby()));
    this->setEnable(false); //禁用大厅

}
void ChatManagerImplementation::initiateRooms() {
	gameRooms.setNullValue(NULL);

	ChatRoom* mainRoom = createRoom("SWG");
	mainRoom->setPrivate();
	gameRooms.put("SWG", mainRoom);

	core3Room = createRoom(server->getGalaxyName(), mainRoom);
	core3Room->setPrivate();
	mainRoom->addSubRoom(core3Room);

	groupRoom = createRoom("group", core3Room);
	groupRoom->setPrivate();
	core3Room->addSubRoom(groupRoom);

	guildRoom = createRoom("guild", core3Room);
	guildRoom->setPrivate();
	core3Room->addSubRoom(guildRoom);

	auctionRoom = createRoom("Auction", core3Room);
	core3Room->addSubRoom(auctionRoom);

	generalRoom = createRoom("General", core3Room);
	core3Room->addSubRoom(generalRoom);


}
Пример #11
0
HallDialog::HallDialog(MainWindow *main_window)
    :QDialog(main_window), main_window(main_window), room_row(0)
{
    setWindowTitle(tr("Hall"));
    setMinimumSize(434, 432);

    HallDialogInstance = this;

    table = new QTableWidget;
    table->setEditTriggers(QAbstractItemView::NoEditTriggers);
    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->setSelectionMode(QAbstractItemView::SingleSelection);
    table->setColumnCount(3);

    QStringList labels;
    labels << tr("Room ID") << tr("Room Name") << tr("Person");
    table->setHorizontalHeaderLabels(labels);

    QHBoxLayout *hlayout = new QHBoxLayout;
    //QPushButton *prev_button = new QPushButton(tr("Previous"));
    //QPushButton *next_button = new QPushButton(tr("Next"));
    QPushButton *join_button = new QPushButton(tr("Join"));
    QPushButton *create_button = new QPushButton(tr("Create room"));
    QCheckBox *waiting_only = new QCheckBox(tr("Waiting room only"));

    //hlayout->addWidget(prev_button);
    //hlayout->addWidget(next_button);
    hlayout->addStretch();
    hlayout->addWidget(join_button);
    hlayout->addWidget(create_button);
    hlayout->addWidget(waiting_only);

    QVBoxLayout *vlayout = new QVBoxLayout;

    vlayout->addWidget(table);
    vlayout->addLayout(hlayout);
    setLayout(vlayout);

    //connect(prev_button, SIGNAL(clicked()), SLOT(pageUp()));
    //connect(next_button, SIGNAL(clicked()), SLOT(pageDown()));
    connect(join_button, SIGNAL(clicked()), SLOT(join()));
    connect(create_button, SIGNAL(clicked()), SLOT(createRoom()));
    connect(waiting_only, SIGNAL(toggled(bool)), SLOT(toggleDisplay(bool)));

    connect(table, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), SLOT(join()));

    refreshRooms(0);
}
Пример #12
0
void create()
{
  set("short", HIG"北院东头"NOR);
  set("long", @LONG
这里就是比武场了,各路英雄们正大打出手,祝你好运!
当你杀死一个玩家后不要望了将其结果 (finish),踢出比武场。
LONG
  );

  set("exits", ([
		 "west" : __DIR__"bf1e",
		 ]));
  // must have this line
  createRoom();
  setup();
}
Пример #13
0
void PathMachine::experimenting(const SigParseEvent &sigParseEvent)
{
    ParseEvent &event = sigParseEvent.deref();

    std::unique_ptr<Experimenting> exp = nullptr;
    const CommandIdType moveCode = event.getMoveType();

    const auto dir = getDirection(moveCode);
    const Coordinate &move = RoomFactory::exitDir(dir);

    // only create rooms if no properties are skipped and
    // the move coordinate is not 0,0,0

    if (event.getNumSkipped() == 0 && moveCode < CommandIdType::FLEE && !mostLikelyRoom.isFake()
        && !move.isNull()) {
        exp = std::make_unique<Crossover>(paths, dir, params, factory);
        std::set<const Room *> pathEnds{};
        for (auto &path : *paths) {
            const Room *const working = path->getRoom();
            if (pathEnds.find(working) == pathEnds.end()) {
                emit createRoom(sigParseEvent, working->getPosition() + move);
                pathEnds.insert(working);
            }
        }
        emit lookingForRooms(*exp, sigParseEvent);
    } else {
        auto pOneByOne = std::make_unique<OneByOne>(factory, sigParseEvent, params, &signaler);
        {
            auto &tmp = *pOneByOne;
            for (auto &path : *paths) {
                const Room *const working = path->getRoom();
                tmp.addPath(path);
                tryExits(working, tmp, event, true);
                tryExits(working, tmp, event, false);
                tryCoordinate(working, tmp, event);
            }
        }
        exp = static_upcast<Experimenting>(std::exchange(pOneByOne, nullptr));
    }

    paths = exp->evaluate();
    evaluatePaths();
}
Пример #14
0
void Input::processSetupLine(std::vector<int> *token_array) {
    if(token_array->size() == 1) {
        if(this->expected_rooms == -1) {
            this->expected_rooms = token_array->at(0);
            std::cout << "DEBUG - Input - Expecting  " << this->expected_rooms << " rooms." << std::endl;
        } else if(this->expected_creatures == -1) {
            this->expected_creatures = token_array->at(0);
            std::cout << "DEBUG - Input - Expecting " << this->expected_creatures << " creatures." << std::endl;
        } else {
            std::cerr << "Bad Input. Rooms and Creatures have already been set.";
            exit(1);
        }
    } else if(token_array->size() == 2) {
        //std::cout << "DEBUG - Input - Calling Create Creature" << std::endl;
        createCreature(token_array);
    } else if(token_array->size() == 5) {
        //std::cout << "DEBUG - Input - Calling Create Room " << std::endl;
        createRoom(token_array);
    }
}
Пример #15
0
int main(int argc, char **argv) {
   if(argc < 3) {
      printf("%s --- Error:%s Usage: %s IP_ADDRESS PORT.\n", RED, NORMAL, argv[0]);
      exit(0);
   }
  
   signal(SIGINT, sigintHandler);
   
   room_list = NULL;
   registered_users_list = NULL;
   active_users_list = NULL;

   createRoom(&room_list, numRooms, DEFAULT_ROOM_NAME, rooms_mutex);
   RprintList(&room_list, rooms_mutex);

   readUserFile(&registered_users_list, USERS_FILE, registered_users_mutex);
   printList(&registered_users_list, registered_users_mutex);  
   // Open server socket
   chat_serv_sock_fd = get_server_socket(argv[1], argv[2]);
   
   // step 3: get ready to accept connections
   if(start_server(chat_serv_sock_fd, BACKLOG) == -1) {
      printf("start server error\n");
      exit(1);
   }	
   //Main execution loop   
   while(1) {
      //Accept a connection, start a thread
      int new_client = accept_client(chat_serv_sock_fd);
      if(new_client != -1) {
         pthread_t new_client_thread;
         pthread_create(&new_client_thread, NULL, client_receive, (void *)&new_client);
      }
   }
   
   close(chat_serv_sock_fd);
}
Пример #16
0
static int l_createRoom(lua_State *L) {

   Room *newroom;

   char *name        = NULL;
   char *title       = NULL;
   char *description = NULL;

   Room *north = NULL;
   Room *south = NULL;
   Room *east  = NULL;
   Room *west  = NULL;

   int n = lua_gettop(L);

   /* script must provide a name and a table of room properties */
   if (n < 2) {
      lua_pushboolean(L, 0);
      lua_pushstring(L, "Must provide room name and table of its properties");
      return 2;
   }

   name = (char *)lua_tostring(L, 1);

   /* make sure room doesn't already exist */
   if (g_hash_table_lookup(g_rooms, name)) {
      lua_pushboolean(L, 0);
      lua_pushstring(L, "Room already exists!");
      return 2;
   }

   lua_pushnil(L);  /* first key (popped by lua_next) */

   while (lua_next(L, 2) != 0) {

      const char *key = lua_tostring(L, -2);
      const char *value = lua_tostring(L, -1);

      if (0 == strcmp("title", key)) {
         title = (char *)value;
      }

      else if (0 == strcmp("description", key)) {
         description = (char *)value;
      }

      else if (0 == strcmp("north", key)) {
         north = g_hash_table_lookup(g_rooms, value);
         if (NULL == north) {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Room to the north doesn't exist!");
            return 2;
         }
      }

      else if (0 == strcmp("south", key)) {
         south = g_hash_table_lookup(g_rooms, value);
         if (NULL == south) {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Room to the south doesn't exist!");
            return 2;
         }
      }

      else if (0 == strcmp("east", key)) {
         east = g_hash_table_lookup(g_rooms, value);
         if (NULL == east) {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Room to the east doesn't exist!");
            return 2;
         }
      }

      else if (0 == strcmp("west", key)) {
         west = g_hash_table_lookup(g_rooms, value);
         if (NULL == west) {
            lua_pushboolean(L, 0);
            lua_pushstring(L, "Room to the west doesn't exist!");
            return 2;
         }
      }

      else {
         lua_pop(L, 1);
         lua_pushboolean(L, 0);
         lua_pushstring(L, "Invalid property!");
         return 2;
      }

      /* removes 'value'; keeps 'key' for next iteration */
      lua_pop(L, 1);
   }

   if (NULL == title) {
         lua_pushboolean(L, 0);
         lua_pushstring(L, "title property is required");
         return 2;
   }

   else if (NULL == description) {
         lua_pushboolean(L, 0);
         lua_pushstring(L, "description property is required");
         return 2;
   }

   newroom = createRoom(TRUE);

   cstrtodstr(newroom->name, name);
   cstrtodstr(newroom->title, title);
   cstrtodstr(newroom->description, description);   

   newroom->north = north;
   newroom->south = south;
   newroom->east = east;
   newroom->west = west;

   g_hash_table_insert(g_rooms, name, newroom);
   lua_pushboolean(L, 1);
   return 1;
}
Пример #17
0
main()
{
  // ** Program Initialization **
  srand (time(NULL));
  int i, j;  //Variables used for loop iteration

  //Setup filename
  int processId = getpid();
  sprintf(folderName, "mccombn.rooms.%d\0", processId); 

  // ** Main Program Execution **

  //Holds all of the rooms
  room_typ *rooms[DESIRED_ROOM_NO];

  //Loops through and creates all of the rooms (allocating mem too)
  for(i = 0; i < DESIRED_ROOM_NO; i = i + 1){
    rooms[i] = createRoom();
  }
  
  //Connects all of the rooms
  connectRooms(rooms);

  //Creates the folder with the appropriate permissions
  if(!mkdir(folderName, 0770))
    i; //exit(2);
  
  //At this point, we can assume that the correct folder is created,
  //and that it's name is stored in folderName
  
  writeRoomsToFile( rooms, folderName );

  //At this point, all of the information is written to the file, so we 
  //need to erase all of our current information :( and read it back in
  //from the files.
  
  for(i = 0; i < DESIRED_ROOM_NO; i = i + 1){
    free(rooms[i]);
  }

  //For clarity to the grading TA, the name of the retrieved rooms was changed
  //(no copying internal to the program was done, as should be obvious)
  room_typ *gameRooms[DESIRED_ROOM_NO];

  for(i = 0; i < DESIRED_ROOM_NO; i = i + 1){
    gameRooms[i] = readRoomFromFile( i, folderName );
  }

  //TODO: Add code to delete the folder and recreate if it fails to make a folder
  //so that we can make the stuff that is okie dokie
  
  // ** MAIN GAME CODE **
  
  //Game-specific variables
  char  currentRoom = START_ROOM;
  char  userInput[150];  //Holds user input
  char  match;           //Used later to determine if a match was found
  char  userPath[500];   //Massive variable incase the user is having a bad day
        strcpy(userPath, ""); //Init it with an empty string, because of how the
                              //code is written later
  short userPathCount = 0;
  
  //Start the actual game loop

  do{

  printf("CURRENT LOCATION: %s\n", gameRooms[currentRoom]->roomName);

  printf("POSSIBLE CONNECTIONS: ");
  
  match = 0; //Default that we haven't found a match
  
  for(i = 0; i < gameRooms[currentRoom]->connectionCount; i = i + 1){
    printf("%s", gameRooms[currentRoom]->connections[i]);
    if( i == gameRooms[currentRoom]->connectionCount - 1 )
      printf(".\n");
    else
      printf(", ");
  }

  printf("WHERE TO? >");
  
  scanf("%s", userInput);

  //Search for connections:
  for(i = 0; i < gameRooms[currentRoom]->connectionCount; i = i + 1){
    if(!strcmp(userInput, gameRooms[currentRoom]->connections[i])){ //If the user entered a valid match
      //We need to go there, bitch
      match = 1;

      //First record our path
      sprintf(userPath, "%s%s\n", userPath, userInput);

      //Increment path counter
      userPathCount = userPathCount + 1;

      //Move the "current room" pointer
      currentRoom = roomSearch( gameRooms, userInput );

      //Print a newline for spacing
      printf("\n");
    }
    //Else, do nothing!
  }

  if(!match)
    printf("\nHUH? I DON'T UNDERSTAND THAT ROOM. TRY AGAIN.\n\n");

  }while(currentRoom != END_ROOM);

  //Yay! The user won.
  //Now we need to output the ending messages.

  printf("YOU HAVE FOUND THE END ROOM. CONGRATULATIONS!\n");
  printf("YOU TOOK %i STEPS. YOUR PATH TO VICTORY WAS: \n%s", userPathCount, userPath);
  
  // ** Program Cleanup **
  for(i = 0; i < DESIRED_ROOM_NO; i = i + 1){
    free(gameRooms[i]);
  }
  
  exit(0);
}
Пример #18
0
// @author Andre Allan Ponce
Location* Game::makeRoom(int id, int x, int y){
	Location* room = createRoom(id,x,y);
	room->fillArray(roomData.retrieveRoom(id));
	return room;
}
Пример #19
0
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    // uncomment to get error checking (slow)
    //Wt::WGLWidget::enableClientErrorChecks();
    OSGWTApp * w = new OSGWTApp (env);
        
    w->setTitle("osgGeometry");

	Wt::WContainerWidget* glContainer = new Wt::WContainerWidget(w->root());
    glContainer->resize(500, 500);
    glContainer->setInline(false);
    
    osg::ref_ptr<osg::Group> g = new osg::Group();

    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("glider.osgt");

    osg::ref_ptr<osg::Node> rootnode = createRoom(loadedModel);

    // use vertex buffer objects only (no client side arrays are supported by webgl)
    osgUtil::GLObjectsVisitor glov(osgUtil::GLObjectsVisitor::SWITCH_ON_VERTEX_BUFFER_OBJECTS);
    rootnode->accept(glov);
    
    // ReWeb3D: add uniforms for the lights!
    // best solution would be that osg::Light provides these
    {
        osg::Uniform* light0Ambient = new osg::Uniform( "glLightSource0.ambient",Light0->getAmbient() );
        osg::Uniform* light0Diffuse = new osg::Uniform( "glLightSource0.diffuse",Light0->getDiffuse());
        osg::Uniform* light0Specular = new osg::Uniform( "glLightSource0.specular", Light0->getSpecular());
        osg::Uniform* light0SpotExponent = new osg::Uniform( "glLightSource0.spotExponent", Light0->getSpotExponent());
        osg::Uniform* light0SpotCutoff = new osg::Uniform( "glLightSource0.spotCutoff", Light0->getSpotCutoff());
        osg::Uniform* light0linearAttenuation = new osg::Uniform( "glLightSource0.linearAttenuation",Light0->getLinearAttenuation() );
        osg::Uniform* light0constantAttenuation = new osg::Uniform( "glLightSource0.constantAttenuation",Light0->getConstantAttenuation() );
        osg::Uniform* light0quadraticAttenuation = new osg::Uniform( "glLightSource0.quadraticAttenuation",Light0->getQuadraticAttenuation() );
        osg::Uniform* light0spotDirection = new osg::Uniform( "glLightSource0.spotDirection", Light0->getDirection());
        osg::Uniform* light0position = new osg::Uniform( "glLightSource0.position", Light0->getPosition());
        
        osg::Uniform* light1Ambient = new osg::Uniform( "glLightSource1.ambient",Light1->getAmbient() );
        osg::Uniform* light1Diffuse = new osg::Uniform( "glLightSource1.diffuse",Light1->getDiffuse());
        osg::Uniform* light1Specular = new osg::Uniform( "glLightSource1.specular", Light1->getSpecular());
        osg::Uniform* light1SpotExponent = new osg::Uniform( "glLightSource1.spotExponent", Light1->getSpotExponent());
        osg::Uniform* light1SpotCutoff = new osg::Uniform( "glLightSource1.spotCutoff", Light1->getSpotCutoff());
        osg::Uniform* light1linearAttenuation = new osg::Uniform( "glLightSource1.linearAttenuation",Light1->getLinearAttenuation() );
        osg::Uniform* light1constantAttenuation = new osg::Uniform( "glLightSource1.constantAttenuation",Light1->getConstantAttenuation() );
        osg::Uniform* light1quadraticAttenuation = new osg::Uniform( "glLightSource1.quadraticAttenuation",Light1->getQuadraticAttenuation() );
        osg::Uniform* light1spotDirection = new osg::Uniform( "glLightSource1.spotDirection", Light1->getDirection());
        osg::Uniform* light1position = new osg::Uniform( "glLightSource1.position", Light1->getPosition());

        osg::Uniform* materialAmbient = new osg::Uniform( "glMaterial.ambient",osg::Vec4(1.0,1.0,1.0,1.0));
        osg::Uniform* materialDiffuse = new osg::Uniform( "glMaterial.diffuse",osg::Vec4(1.0,1.0,1.0,1.0));
        osg::Uniform* materialSpecular = new osg::Uniform( "glMaterial.specular", osg::Vec4(1.0,1.0,1.0,1.0));
        osg::Uniform* materialShiness = new osg::Uniform( "glMaterial.shiness",(float)32.0 );
        osg::Uniform* materialEmission = new osg::Uniform( "glMaterial.emission", osg::Vec4(0.0,0.0,0.0,0.0));
        
        osg::StateSet* ss = rootnode->getOrCreateStateSet();
        ss->addUniform(light0Ambient);
        ss->addUniform(light0Diffuse);
        ss->addUniform(light0Specular);
        ss->addUniform(light0SpotExponent);
        ss->addUniform(light0SpotCutoff);
        ss->addUniform(light0linearAttenuation);
        ss->addUniform(light0constantAttenuation); 
        ss->addUniform(light0quadraticAttenuation);
        ss->addUniform(light0spotDirection); 
        ss->addUniform(light0position);

        ss->addUniform(light1Ambient);
        ss->addUniform(light1Diffuse);
        ss->addUniform(light1Specular);
        ss->addUniform(light1SpotExponent);
        ss->addUniform(light1SpotCutoff);
        ss->addUniform(light1linearAttenuation);
        ss->addUniform(light1constantAttenuation); 
        ss->addUniform(light1quadraticAttenuation);
        ss->addUniform(light1spotDirection); 
        ss->addUniform(light1position);

        ss->addUniform(materialAmbient);
        ss->addUniform(materialDiffuse);
        ss->addUniform(materialSpecular);
        ss->addUniform(materialShiness);
        ss->addUniform(materialEmission);
    }

    // add shader to OSG scenegraph
    {
        osg::ref_ptr<osg::Shader> vShader = new osg::Shader(
            osg::Shader::VERTEX,
            defaultVertexShader);

        osg::ref_ptr<osg::Shader> fShader = new osg::Shader(
            osg::Shader::FRAGMENT,
            defaultFragmentShader);

        osg::ref_ptr<osg::Program> program = new osg::Program();
        program->addShader(vShader);
        program->addShader(fShader);
        rootnode->getOrCreateStateSet()->setAttribute(program);
		
    }

    osgViewer::Viewer * viewer = new osgViewer::Viewer;

    osgWt::WtOSGWidget * viewWidget = new osgWt::WtOSGWidget(800,600, glContainer);

    // IMPORTANT
    viewWidget->setViewer(viewer);

    // IMPORTANT
    viewer->setUpViewerAsEmbeddedInWindow(100,100,800,600);
    
    viewer->setSceneData(rootnode);
    viewer->setCameraManipulator(new osgGA::TrackballManipulator);

    viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
    viewer->getCamera()->setProjectionMatrixAsPerspective(45,800.0/600.0, 0.5, 100.0);

    viewer->realize();   
    return w;

	////////////// ADDED
}
Пример #20
0
void LevelGenerator::onCreate()
{
    // Make sure we have a parent to attach it to
    auto pParent = getParent();
    if (!pParent) return;

    // Static map data
    struct sMap
    {
        sRoom room;
        sMap()
        {
            room.w = 128;
            room.h = 128;
            room.tiles = new char[room.w * room.h * 2];
        }
    };
    static sMap map;
    memset(map.room.tiles, 0, sizeof(char) * map.room.w * map.room.h * 2);

    // Pick/Place starting room
    auto& startRoom = onut::randv(g_rooms);
    blitRoom(map.room, startRoom, map.room.w / 2 - startRoom.w / 2, map.room.h / 2 - startRoom.h / 2, onut::randi(0, 3));

    // How many rooms we are going to have
    auto roomCount = onut::randi(5, 8) - 1;
    static std::vector<int> doors;
    static std::vector<int> roomDoors;
    for (auto i = 0; i < roomCount; ++i)
    {
        bool bGotIt = false;
        for (auto tries1 = 0; tries1 < 10 && !bGotIt; ++tries1)
        {
            // Find a door emplacement
            findAllDoors(doors, map.room);
            if (doors.empty()) break; // That's it, we're done

            // Pick a random door
            auto door = onut::randv(doors);
            int doorX = door % map.room.w;
            int doorY = door / map.room.w;

            // Find a room that will fit there, and give it a lot of tries
            for (auto tries = 0; tries < 100 && !bGotIt; ++tries)
            {
                auto& room = onut::randv(g_rooms);
                auto rotation = onut::randi(0, 3);
                findAllDoors(roomDoors, room);
                onut::shuffle(roomDoors);
                for (auto roomDoor : roomDoors)
                {
                    int roomDoorX = roomDoor % room.w;
                    int roomDoorY = roomDoor / room.w;
                    int roomOffsetX = 0;
                    int roomOffsetY = 0;

                    switch (rotation)
                    {
                        case 0:
                            roomOffsetX = -roomDoorX;
                            roomOffsetY = -roomDoorY;
                            break;
                        case 1:
                            roomOffsetX = -roomDoorY;
                            roomOffsetY = -(room.h - roomDoorX - 1);
                            break;
                        case 2:
                            roomOffsetX = -(room.w - roomDoorX - 1);
                            roomOffsetY = -(room.h - roomDoorY - 1);
                            break;
                        case 3:
                            roomOffsetX = -(room.w - roomDoorY - 1);
                            roomOffsetY = -roomDoorX;
                            break;
                    }

                    // Check if it fits
                    if (roomFits(map.room, room, doorX + roomOffsetX, doorY + roomOffsetY, rotation))
                    {
                        blitRoom(map.room, room, doorX + roomOffsetX, doorY + roomOffsetY, rotation);
                        map.room.tiles[door * 2] = '.';
                        bGotIt = true;
                        break;
                    }
                }
            }
        }
    }

    pParent->add(createRoom(0, 0, map.room));
}
Пример #21
0
/*
 *Join a chat room
 */
void join(packet *pkt, int fd) {
   int i = 0;
   char *args[16];
   char *tmp = pkt->buf;
   packet ret;

   // Split command args
   args[i] = strsep(&tmp, " \t");
   while ((i < sizeof(args) - 1) && (args[i] != '\0')) {
      args[++i] = strsep(&tmp, " \t");
   }
   if (i > 1 && validRoomname(args[0], fd)) {
      // check if room exists
      printf("Checking if room exists . . .\n");
      if (Rget_ID(&room_list, args[0], rooms_mutex) == -1) {
         // create if it does not exist
         createRoom(&room_list, numRooms, args[0], rooms_mutex);
      }
      RprintList(&room_list, rooms_mutex);
      printf("Receiving room node for requested room.\n");
      Room *newRoom = Rget_roomFNAME(&room_list, args[0], rooms_mutex);

      int currRoomNum = atoi(args[1]);
      // Should check if current room exists
      printf("Receiving room node for users current room.\n");
      Room *currentRoom = Rget_roomFID(&room_list, currRoomNum, rooms_mutex);//pkt->options);
      printf("Getting user node from current room user list.\n");
      if(currentRoom == NULL) {
         printf("Could not remove user: current room is NULL\n");
      }
      else {
         User *currUser = get_user(&(currentRoom->user_list), pkt->username, currentRoom->user_list_mutex);
         printf("Removing user from his current rooms user list\n");
         removeUser(&(currentRoom->user_list), currUser, currentRoom->user_list_mutex);
         printf("User removed from current room\n");
         
         //Create node to add user to other room list.
         Node *new_node = (Node *)malloc(sizeof(Node));
         new_node->data = currUser;
         currUser->roomID = newRoom->ID;
         printf("Inserting user into new rooms user list\n");
         insertUser(&(newRoom->user_list), currUser, newRoom->user_list_mutex);

         RprintList(&room_list, rooms_mutex);

         ret.options = JOINSUC;
         strcpy(ret.realname, SERVER_NAME);
         strcpy(ret.username, SERVER_NAME);
         ret.timestamp = time(NULL);
         sprintf(ret.buf, "%s %d", args[0], newRoom->ID);
         send(fd, (void *)&ret, sizeof(packet), MSG_NOSIGNAL);
         memset(&ret, 0, sizeof(ret));

         ret.options = currRoomNum;
         strcpy(ret.realname, SERVER_NAME);
         strcpy(ret.username, SERVER_NAME);
         strncpy(ret.buf, currUser->real_name, sizeof(currUser->real_name));
         strcat(ret.buf, " has left the room.");
         ret.timestamp = time(NULL);
         send_message(&ret, -1);
         memset(&ret, 0, sizeof(ret));

         ret.options = newRoom->ID;
         strcpy(ret.realname, SERVER_NAME);
         strcpy(ret.username, SERVER_NAME);
         strncpy(ret.buf, currUser->real_name, sizeof(currUser->real_name));
         strcat(ret.buf, " has joined the room.");
         ret.timestamp = time(NULL);
         send_message(&ret, -1);
      }
   }
   else {
      printf("Problem in join.\n");
      sendError("We were unable to put you in that room, sorry.", fd);
   }
}