void SceneCullingState::addOccluder( SceneObject* object ) { PROFILE_SCOPE( SceneCullingState_addOccluder ); // If the occluder is itself occluded, don't add it. // // NOTE: We do allow near plane intersections here. Silhouette extraction // should take that into account. if( cullObjects( &object, 1, DontCullRenderDisabled ) != 1 ) return; // If the occluder has already been added, do nothing. Check this // after the culling check since the same occluder can be added by // two separate zones and not be visible in one yet be visible in the // other. if( mAddedOccluderObjects.contains( object ) ) return; mAddedOccluderObjects.push_back( object ); // Let the object build a silhouette. If it doesn't // return one, abort. Vector< Point3F > silhouette; object->buildSilhouette( getCameraState(), silhouette ); if( silhouette.empty() || silhouette.size() < 3 ) return; // Generate the culling volume. SceneCullingVolume volume; if( !createCullingVolume( silhouette.address(), silhouette.size(), SceneCullingVolume::Occluder, volume ) ) return; // Add the frustum to all zones that the object is assigned to. for( SceneObject::ZoneRef* ref = object->_getZoneRefHead(); ref != NULL; ref = ref->nextInObj ) addCullingVolumeToZone( ref->zone, volume ); }
int GameSession::Run(){ // temp int numLobbyPlayer = 0; int numPlayers = 1; // /// MANAGERS LogManager* log = LogManager::GetLogManager(); InputManager* input = InputManager::getInstance(); AudioManager* audioMan = AudioManager::getAudioInstance(); RenderManager* renderMan = RenderManager::getRenderManager(); ResourceManager* resourceMan = ResourceManager::GetResourceManager(); SceneManager* sceneMan = SceneManager::GetSceneManager(); input->update(); ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// /// SYSTEMS SystemNetworkUpdater sysNetwork; SystemRenderUpdater sysRenderer; SystemInputUpdater sysInput; SystemLogicUpdater sysLogic; SystemPhysicsUpdater sysPhysics; SystemClassUpdater sysClass; SystemUIUpdater sysUI; /// ENTITIES PlayerObjectFactory pFactory; MinionObjectFactory mFactory; FeatherObjectFactory fFactory; PlatformObjectFactory plFactory; MidPlatObjectFactory mpFactory; numPlayers = NetworkManager::sInstance->GetPlayerCount(); //std::cout << NetworkManager::sInstance->GetLobbyId() << std::endl; /*for (const auto& iter : NetworkManager::sInstance->lobbyInfoMap){ std::cout << iter.first << std::endl; std::cout << "\tClass:" << iter.second.classType << std::endl; }*/ GameObject * player = NULL; Stats stats; /// try to join a game and give each user a unique character in the game unordered_map< uint64_t, PlayerInfo > lobby = NetworkManager::sInstance->getLobbyInfoMap(); Stats::resetStats(); int i = 0; bool local = true; for (auto &iter : lobby){ int classType = iter.second.classType; std::cout << "classType: " << classType << std::endl; if (iter.first == NetworkManager::sInstance->GetMyPlayerId()){ player = GameObjects.AddObject(pFactory.Spawn(iter.first, (classType % 50) + 1, (i % 2) + 1, local)); Stats::setLocalTeam((i % 2) + 1); Stats::addPlayer(iter.first, (i % 2) + 1); } else{ GameObjects.AddObject(pFactory.Spawn(iter.first, (classType % 50) + 1, (i % 2) + 1, !local)); Stats::addPlayer(iter.first, (i % 2) + 1); } ++i; } ///////////////////////////////////////////////////// /* * * * GAME LOOP * * * */ ///////////////////////////////////////////////////// bool gameloop = true; int var = 0; renderMan->zoom = 0.5; float size = 6; float ratio = 0.7f; int armswing = (int)size; int moveSpd = 1; int pressed = 0; int pressedTime = 3; int rotation = 0; audioMan->playByName("bgmBAAGameplay.ogg"); bool gameEndMusic = false; int mousecounter = 5; renderMan->zoom = 0.6f; SystemUIObjectQueue queue; //World Loading GameSession::LoadWorld(); GameSession::LoadPlayers(); GameSession::LoadHUD(player, queue); ///*auto spawning minion variables int minionCounter = 10000; //crosshair variables SDLRenderObject * crosshair = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 1109, -1000, -1000, -0.05f); SDLRenderObject * crosshairCharging = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 1111, -1000, -1000, -0.05f); crosshairCharging->visible = false; PlayerLogicComponent* playerLogic = dynamic_cast<PlayerLogicComponent*>(player->GetComponent(COMPONENT_LOGIC)); PlayerRenderComponent* playerRend = dynamic_cast<PlayerRenderComponent*>(player->GetComponent(COMPONENT_RENDER)); //midway fountain /* SDLRenderObject * fount = sceneMan->InstantiateObject(sceneMan->findLayer("layer2"), 101004, 40, 150, 0.005f); fount->setScale(0.5f); list<motion> motions; motions.push_back(makeMotion(keyframeAnimate(fount, 0, 15), 0, 1)); Animation * runWater = new Animation(100, motions); int aniCounter = 0; */ LoadBackgroundProps(); int aniCounter = 0; bool firstTime = true; Timing::sInstance.SetCountdownStart(); NetworkManager::sInstance->SetState(NetworkManager::NMS_Playing); std::cout << NetworkManager::sInstance->GetState() << std::endl; clock_t current_ticks, delta_ticks; clock_t fps = 0; string fpscounter = ""; SDLRenderObject * fpsHUD = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), -1, 5, 0, true); fpsHUD->setResourceObject(renderMan->renderText(fpscounter.c_str(), 255, 0, 0, 20, "VT323-Regular")); fpsHUD->setPos(0, 0); SDLRenderObject * leftbaseHUDicon = nullptr; SDLRenderObject * rightbaseHUDicon = nullptr; if (player->team == TEAM_PURPLE){ leftbaseHUDicon = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 7006, 0, 0, true); leftbaseHUDicon->flipH = true; rightbaseHUDicon = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 7005, 0, 0, true); rightbaseHUDicon->flipH = true; } else{ leftbaseHUDicon = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 7005, 0, 0, true); rightbaseHUDicon = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), 7006, 0, 0, true); } leftbaseHUDicon->setPos(-150, 600); string leftBaseHealth = ""; SDLRenderObject * leftbaseHUD = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), -1, 5, 0, true); leftbaseHUD->setResourceObject(renderMan->renderText(leftBaseHealth.c_str(), 255, 0, 0, 60, "VT323-Regular")); leftbaseHUD->setPos(15, 650); rightbaseHUDicon->setPos(1214, 600); string rightBaseHealth = ""; SDLRenderObject * rightbaseHUD = sceneMan->InstantiateObject(sceneMan->findLayer("layer1"), -1, 5, 0, true); rightbaseHUD->setResourceObject(renderMan->renderText(rightBaseHealth.c_str(), 255, 0, 0, 60, "VT323-Regular")); rightbaseHUD->setPos(1281, 650); renderMan->toggleCursor(0); /////////////Flip screen if needed///////////////// if (player->team == TEAM_PURPLE){ std::cout << "flip the screen" << std::endl; renderMan->flippedScreen = true; } ////////////////////////////////////////////////// bool gameEnd = false; inGameStatsRenderComponent inGameStats; while (gameloop) { current_ticks = clock(); if (input->isKeyDown(KEY_TAB)){ inGameStats.updateText(); inGameStats.toggleOn(true); } else{ inGameStats.toggleOn(false); } //std::cout << NetworkManager::sInstance->GetState() << std::endl; /*if (input->isKeyDown(KEY_Q)){ if (renderMan->cameraPoint.z < -5){ renderMan->cameraPoint.z += 1; } } if (input->isKeyDown(KEY_W)){ renderMan->cameraPoint.z -= 1; } if (input->isKeyDown(KEY_E)){ renderMan->flippedScreen = !renderMan->flippedScreen; }*/ /*clock_t t; t = clock();*/ if (input->isKeyDown(KEY_F)){ std::cout << "Number of feathers: " << GameObjects.dead_feathers.size() << std::endl; } if (input->isKeyDown(KEY_M)){ std::cout << "Number of minions: " << GameObjects.dead_minions.size() << std::endl; } if (input->isKeyDown(KEY_L)){ std::cout << "Alive Objects: " << GameObjects.alive_objects.size() << std::endl; } if (input->isKeyDown(KEY_Y)) { renderMan->ShakeScreen(.2f, .5f); } mousecounter++; //////////////////////////////////// if (numPlayers != 1) NetworkManager::sInstance->UpdateDelay(); //CAMERA MOVEMENT - based on player position if (!gameEnd){ if (player){ //Camera Shake if ((!rightBase->isAlive || !leftBase->isAlive) && !endedBaseShake) { endedBaseShake = true; renderMan->ShakeScreen(1, 1); } /*int mousePos = input->getMouseX(); int wid, hei; renderMan->getWindowSize(&wid, &hei); float xRatio = (mousePos - wid / 2) / float(wid / 2); float xPlus = (float)(wid / 4) - 20; //std::cout << xRatio << std::endl; renderMan->setCameraPoint(player->posX + xRatio*xPlus, 0);*/ float mouseX, mouseY; renderMan->windowCoordToWorldCoord(mouseX, mouseY, input->getMouseX(), input->getMouseY()); float cameraX = (player->posX + mouseX) / 2; //next line makes the camera favor staying closer to the player cameraX = (player->posX + cameraX) / 2; renderMan->setCameraPoint(cameraX, 0); } } int length = 20; float loop = (float)(var % length); //crosshair updating float crossX, crossY; renderMan->windowCoordToWorldCoord(crossX, crossY, input->getMouseX(), input->getMouseY()); crosshair->posX = crosshairCharging->posX = crossX; crosshair->posY = crosshairCharging->posY = crossY; float attackCDPercent = Timing::sInstance.GetAttackCooldownRemaining(); float chargePercent = 1.0f - (playerLogic->currChargePercentage > 0.75f ? 0.75f : playerLogic->currChargePercentage); if (chargePercent != 1.0f){ //sets scale during charge //crosshair->setScale(chargePercent); crosshairCharging->visible = false; crosshair->visible = true; playerRend->crosshairRef = crosshair; } else if (chargePercent == 1.0f && Timing::sInstance.AttackCooldownEnded()) { crosshairCharging->visible = false; crosshair->visible = true; crosshair->setScale(1.0f); playerRend->crosshairRef = crosshair; } else {//if(attackCDPercent < 1.0f) { //sets scale during attack cooldown crosshairCharging->setScale(attackCDPercent); crosshairCharging->visible = true; crosshair->visible = false; playerRend->crosshairRef = crosshairCharging; } //physics testing stuff PhysicsListener listener; GameWorld* gameWorld = GameWorld::getInstance(); gameWorld->physicsWorld->SetContactListener(&listener); gameWorld->update(); //update physics world //end physics testing stuff sysInput.InputUpdate(GameObjects.alive_objects); sysRenderer.RenderUpdate(GameObjects.alive_objects); sysLogic.LogicUpdate(GameObjects.alive_objects); sysPhysics.PhysicsUpdate(GameObjects.alive_objects); sysClass.ClassUpdate(GameObjects.alive_objects); sysUI.UIUpdate(queue.alive_objects); if (numPlayers != 1) sysNetwork.NetworkUpdate(GameObjects.alive_objects); //updates all timers Invoke::UpdateTimers(); if (input->isKeyDown(KEY_ESCAPE)) gameloop = false; //OBJECT POOLING - moves recently dead objects to respective dead pool for (unsigned int i = 0; i < GameObjects.alive_objects.size(); i++){ if (!GameObjects.alive_objects[i]->isAlive){ //object has died this last gameloop. send it to the object pool //std::cout << "ID: " << GameObjects.alive_objects[i]->ID << std::endl; if (GameObjects.alive_objects[i]->type == OBJECT_FEATHER){ GameObjects.dead_feathers.push_back(GameObjects.alive_objects[i]); } else if (GameObjects.alive_objects[i]->type == OBJECT_MINION){ GameObjects.dead_minions.push_back(GameObjects.alive_objects[i]); } else { GameObjects.dead_objects.push_back(GameObjects.alive_objects[i]); } GameObjects.alive_objects.erase(GameObjects.alive_objects.begin() + i); } } if (!firstTime) //allows culling to start after all initialization happens cullObjects(); if (NetworkManager::sInstance->IsMasterPeer() && Timing::sInstance.SpawnMinions()){ GameObjects.AddObject(mFactory.Spawn(minionCounter++, -900, 0, TEAM_YELLOW)); GameObjects.AddObject(mFactory.Spawn(minionCounter++, 900, 0, TEAM_PURPLE)); } input->update(); sceneMan->AssembleScene(); //triggers endgame screen if (Timing::sInstance.GetTimeRemainingS() <= 0) { /*if (player->team == TEAM_PURPLE){ std::cout << "flip the screen" << std::endl; renderMan->flippedScreen = false; }*/ gameEnd = true;//so the mouse stops registering int myTeam; for (unsigned int i = 0; i < players.size(); i++){ if (GamerServices::sInstance->GetLocalPlayerId() == players[i]->playerId){ myTeam = players[i]->team; } } std::cout << "END REACHED " << std::endl; //GameEnd end = GameEnd::GameEnd(); //end.runGameEnd(myTeam, leftBase, rightBase); gameloop = false; } if (Timing::sInstance.GetTimeRemainingS() <= 30 && !gameEndMusic){ gameEndMusic = true; audioMan->stopByName("bgmBAAGameplay.ogg"); audioMan->playByName("bgmBAAGameEnd.ogg"); } firstTime = false; delta_ticks = clock() - current_ticks; //the time, in ms, that took to render the scene if (delta_ticks > 0) fps = CLOCKS_PER_SEC / delta_ticks; //std::cout <<" FPS : " << fps << std::endl; fpscounter = std::to_string(fps); //leftBase->health //renderMan->renderText(fpscounter.c_str(), 255, 255, 0, 70, "BowlbyOneSC-Regular"); fpsHUD->setResourceObject(renderMan->renderText(fpscounter.c_str(), 0, 20, 240, 20, "VT323-Regular")); inGameStats.Update(); } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// audioMan->stopByName("bgmBAAGameEnd.ogg"); std::cout << renderMan << std::endl; std::cout << renderMan << std::endl; konamiUnlocked = false; log->close(); //delete surf; //delete fount; //delete runWater; GameWorld::getInstance()->~GameWorld(); return SCENE_GAMEOVER; }