示例#1
0
    def __init__(self):
        self.enabled = True
        self.cameraSubmerged = False
        self.localAvTouching = WaterNode.Nothing
        self.underwaterFog = [VBase4(0.0, 0.3, 0.7, 1.0), 0.008]
        self.waterNodes = []
        self.hasScenes = False
        
        self.waterNodesQueue = []

        # name to list of textures for each frame
        self.dudvs = {}

        self.underwaterSound = None
        self.wadeSounds = []
        
        sMgr = CIGlobals.getSettingsMgr()
        self.reso = sMgr.ReflectionQuality[sMgr.getSetting("refl").getValue()]
        
        self.reflScene = None
        self.refrScene = None
        self.underwaterRefrScene = None
    def initStuff(self):
        # Precache water bar shader, prevents crash from running out of GPU registers
        loader.loadShader("phase_14/models/shaders/progress_bar.sha")

        self.bspLoader.setWantShadows(metadata.USE_REAL_SHADOWS)

        self.shaderGenerator = BSPShaderGenerator(self.win, self.win.getGsg(),
                                                  self.camera, self.render)
        self.win.getGsg().setShaderGenerator(self.shaderGenerator)
        self.bspLoader.setShaderGenerator(self.shaderGenerator)
        vlg = VertexLitGenericSpec()  # models
        ulg = UnlitGenericSpec()  # ui elements, particles, etc
        lmg = LightmappedGenericSpec()  # brushes, displacements
        unm = UnlitNoMatSpec()  # when there's no material
        csm = CSMRenderSpec()  # renders the shadow scene for CSM
        skb = SkyBoxSpec()  # renders the skybox onto faces
        dcm = DecalModulateSpec()  # blends decals
        self.shaderGenerator.addShader(vlg)
        self.shaderGenerator.addShader(ulg)
        self.shaderGenerator.addShader(unm)
        self.shaderGenerator.addShader(lmg)
        self.shaderGenerator.addShader(csm)
        self.shaderGenerator.addShader(skb)
        self.shaderGenerator.addShader(dcm)

        self.shaderGenerator.setShaderQuality(
            CIGlobals.getSettingsMgr().getSetting("shaderquality").getValue())

        if metadata.USE_REAL_SHADOWS and self.config.GetBool(
                'pssm-debug-cascades', False):
            from panda3d.core import CardMaker, Shader  #, Camera, Trackball
            cm = CardMaker('cm')
            cm.setFrame(-1, 1, -1, 1)
            np = aspect2d.attachNewNode(cm.generate())
            np.setScale(0.3)
            np.setPos(0, -0.7, -0.7)
            np.setShader(
                Shader.load(Shader.SLGLSL,
                            "phase_14/models/shaders/debug_csm.vert.glsl",
                            "phase_14/models/shaders/debug_csm.frag.glsl"))
            np.setShaderInput("cascadeSampler",
                              self.shaderGenerator.getPssmArrayTexture())
            #cam = Camera('csmDbgCam')
            #tb = Trackball('tb')
            #lens = PerspectiveLens()
            #cam.setLens(lens)
            #cam.reparentTo(render)
            #base.openWindow(useCamera = cam)

        #self.shadowCaster.turnOnShadows()

        self.waterReflectionMgr.load()

        self.filters = CIPostProcess()
        self.filters.startup(self.win)
        self.filters.addCamera(self.cam)
        self.filters.setup()

        self.hdr = HDR()
        self.setHDR(self.hdrToggle)
        self.setBloom(self.bloomToggle)
        self.setFXAA(self.fxaaToggle)
        self.setAmbientOcclusion(self.aoToggle)
        #self.filters.setDepthOfField(distance = 10.0, range = 175.0, near = 1.0, far = 1000.0 / (1000.0 - 1.0))

        #from src.coginvasion.globals import BSPUtility
        #BSPUtility.applyUnlitOverride(render)

        # We define this here (naming it cl_ to avoid trying to use the old base.attackMgr)
        # in order to precache attacks. The ClientRepository will then take our self.cl_attackMgr
        # and use it as base.cr.attackMgr.
        from src.coginvasion.attack.AttackManager import AttackManager
        self.cl_attackMgr = AttackManager()

        if self.DebugShaderQualities:
            from libpandabsp import SHADERQUALITY_HIGH, SHADERQUALITY_MEDIUM, SHADERQUALITY_LOW
            self.accept('1', self.shaderGenerator.setShaderQuality,
                        [SHADERQUALITY_LOW])
            self.accept('2', self.shaderGenerator.setShaderQuality,
                        [SHADERQUALITY_MEDIUM])
            self.accept('3', self.shaderGenerator.setShaderQuality,
                        [SHADERQUALITY_HIGH])
    def __init__(self):
        self.bspLoader = Py_CL_BSPLoader()
        self.bspLoader.setGlobalPtr(self.bspLoader)

        if metadata.USE_RENDER_PIPELINE:
            from rpcore import RenderPipeline
            self.pipeline = RenderPipeline()
            self.pipeline.create(self)
        else:
            ShowBase.__init__(self)
            self.loader.destroy()
            self.loader = CogInvasionLoader(self)
            __builtin__.loader = self.loader
            self.graphicsEngine.setDefaultLoader(self.loader.loader)

        self.cam.node().getDisplayRegion(0).setClearDepthActive(1)

        from panda3d.core import RenderAttribRegistry
        from panda3d.core import ShaderAttrib, TransparencyAttrib
        from libpandabsp import BSPMaterialAttrib
        attribRegistry = RenderAttribRegistry.getGlobalPtr()
        attribRegistry.setSlotSort(BSPMaterialAttrib.getClassSlot(), 0)
        attribRegistry.setSlotSort(ShaderAttrib.getClassSlot(), 1)
        attribRegistry.setSlotSort(TransparencyAttrib.getClassSlot(), 2)

        gsg = self.win.getGsg()

        # Let's print out the Graphics information.
        self.notify.info(
            'Graphics Information:\n\tVendor: {0}\n\tRenderer: {1}\n\tVersion: {2}\n\tSupports Cube Maps: {3}\n\tSupports 3D Textures: {4}\n\tSupports Compute Shaders: {5}'
            .format(gsg.getDriverVendor(), gsg.getDriverRenderer(),
                    gsg.getDriverVersion(), str(gsg.getSupportsCubeMap()),
                    str(gsg.getSupports3dTexture()),
                    str(gsg.getSupportsComputeShaders())))

        # Enable shader generation on all of the main scenes
        if gsg.getSupportsBasicShaders() and gsg.getSupportsGlsl():
            render.setShaderAuto()
            render2d.setShaderAuto()
            render2dp.setShaderAuto()
        else:
            # I don't know how this could be possible
            self.notify.error("GLSL shaders unsupported by graphics driver.")
            return

        # Let's disable fog on Intel graphics
        if gsg.getDriverVendor() == "Intel":
            metadata.NO_FOG = 1
            self.notify.info('Applied Intel-specific graphical fix.')

        self.win.disableClears()

        self.camNode.setCameraMask(CIGlobals.MainCameraBitmask)

        from direct.distributed.ClockDelta import globalClockDelta
        __builtin__.globalClockDelta = globalClockDelta

        # Any ComputeNodes should be parented to this node, not render.
        # We isolate ComputeNodes to avoid traversing the same ComputeNodes
        # when doing multi-pass rendering.
        self.computeRoot = NodePath('computeRoot')
        self.computeCam = self.makeCamera(base.win)
        self.computeCam.node().setCullBounds(OmniBoundingVolume())
        self.computeCam.node().setFinal(True)
        self.computeCam.reparentTo(self.computeRoot)

        # Initialized in initStuff()
        self.shaderGenerator = None

        render.hide()

        self.camLens.setNearFar(0.5, 10000)

        self.physicsWorld = BulletWorld()
        # Panda units are in feet, so the gravity is 32 feet per second,
        # not 9.8 meters per second.
        self.physicsWorld.setGravity(Vec3(0, 0, -32.1740))

        self.physicsWorld.setGroupCollisionFlag(7, 1, True)
        self.physicsWorld.setGroupCollisionFlag(7, 2, True)
        self.physicsWorld.setGroupCollisionFlag(7, 3, False)
        self.physicsWorld.setGroupCollisionFlag(7, 4, False)
        self.physicsWorld.setGroupCollisionFlag(7, 8, True)

        self.taskMgr.add(self.__physicsUpdate, "physicsUpdate", sort=30)

        debugNode = BulletDebugNode('Debug')
        self.debugNP = render.attachNewNode(debugNode)
        self.physicsWorld.setDebugNode(self.debugNP.node())

        self.physicsDbgFlag = False
        self.setPhysicsDebug(self.config.GetBool('physics-debug', False))

        #self.shadowCaster = ShadowCaster(Vec3(163, -67, 0))
        #self.shadowCaster.enable()

        self.bspLoader.setGamma(2.2)
        self.bspLoader.setWin(self.win)
        self.bspLoader.setCamera(self.camera)
        self.bspLoader.setRender(self.render)
        self.bspLoader.setMaterialsFile("phase_14/etc/materials.txt")
        #self.bspLoader.setTextureContentsFile("phase_14/etc/texturecontents.txt")
        self.bspLoader.setWantVisibility(True)
        self.bspLoader.setVisualizeLeafs(False)
        self.bspLoader.setWantLightmaps(True)
        #self.bspLoader.setShadowCamPos(Point3(-15, 5, 40))
        #self.bspLoader.setShadowResolution(60 * 2, 1024 * 1)
        self.bspLoader.setPhysicsWorld(self.physicsWorld)
        self.bspLevel = None
        self.materialData = {}
        self.skyBox = None
        self.skyBoxUtil = None

        #self.nmMgr = RNNavMeshManager.get_global_ptr()
        #self.nmMgr.set_root_node_path(self.render)
        #self.nmMgr.get_reference_node_path().reparentTo(self.render)
        #self.nmMgr.start_default_update()
        #self.nmMgr.get_reference_node_path_debug().reparentTo(self.render)
        self.navMeshNp = None

        # Setup 3d audio                                 run before igLoop so 3d positioning doesn't lag behind
        base.audio3d = Audio3DManager(base.sfxManagerList[0], camera, render)
        base.audio3d.setDropOffFactor(0.15)
        base.audio3d.setDopplerFactor(0.15)

        # Setup collision handlers
        base.cTrav = CollisionTraverser()
        base.lifter = CollisionHandlerFloor()
        base.pusher = CollisionHandlerPusher()
        base.queue = CollisionHandlerQueue()

        base.lightingCfg = None

        self.cl_attackMgr = None

        #self.accept('/', self.projectShadows)

        # Let's setup the user input storage system
        uis = UserInputStorage()
        self.inputStore = uis
        self.userInputStorage = uis
        __builtin__.inputStore = uis
        __builtin__.userInputStorage = uis

        self.credits2d = self.render2d.attachNewNode(PGTop("credits2d"))
        self.credits2d.setScale(1.0 / self.getAspectRatio(), 1.0, 1.0)

        self.wakeWaterHeight = -30.0

        self.bloomToggle = False
        self.hdrToggle = False
        self.fxaaToggle = CIGlobals.getSettingsMgr().getSetting(
            "aa").getValue() == "FXAA"
        self.aoToggle = False

        self.music = None
        self.currSongName = None

        render.show(CIGlobals.ShadowCameraBitmask)

        self.avatars = []

        wrm = WaterReflectionManager()
        self.waterReflectionMgr = wrm
        __builtin__.waterReflectionMgr = wrm

        # Let's setup our margins
        base.marginManager = MarginManager()
        base.margins = aspect2d.attachNewNode(
            base.marginManager, DirectGuiGlobals.MIDGROUND_SORT_INDEX + 1)
        base.leftCells = [
            base.marginManager.addCell(0.1, -0.6, base.a2dTopLeft),
            base.marginManager.addCell(0.1, -1.0, base.a2dTopLeft),
            base.marginManager.addCell(0.1, -1.4, base.a2dTopLeft)
        ]
        base.bottomCells = [
            base.marginManager.addCell(0.4, 0.1, base.a2dBottomCenter),
            base.marginManager.addCell(-0.4, 0.1, base.a2dBottomCenter),
            base.marginManager.addCell(-1.0, 0.1, base.a2dBottomCenter),
            base.marginManager.addCell(1.0, 0.1, base.a2dBottomCenter)
        ]
        base.rightCells = [
            base.marginManager.addCell(-0.1, -0.6, base.a2dTopRight),
            base.marginManager.addCell(-0.1, -1.0, base.a2dTopRight),
            base.marginManager.addCell(-0.1, -1.4, base.a2dTopRight)
        ]

        base.mouseWatcherNode.setEnterPattern('mouse-enter-%r')
        base.mouseWatcherNode.setLeavePattern('mouse-leave-%r')
        base.mouseWatcherNode.setButtonDownPattern('button-down-%r')
        base.mouseWatcherNode.setButtonUpPattern('button-up-%r')

        cbm = CullBinManager.getGlobalPtr()
        cbm.addBin('ground', CullBinManager.BTUnsorted, 18)
        # The portal uses the shadow bin by default,
        # but we still want to see it with real shadows.
        cbm.addBin('portal', CullBinManager.BTBackToFront, 19)
        if not metadata.USE_REAL_SHADOWS:
            cbm.addBin('shadow', CullBinManager.BTBackToFront, 19)
        else:
            cbm.addBin('shadow', CullBinManager.BTFixed, -100)
        cbm.addBin('gui-popup', CullBinManager.BTUnsorted, 60)
        cbm.addBin('gsg-popup', CullBinManager.BTFixed, 70)
        self.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
        self.disableMouse()
        self.enableParticles()
        base.camLens.setNearFar(CIGlobals.DefaultCameraNear,
                                CIGlobals.DefaultCameraFar)
        base.transitions = CITransitions(loader)
        base.transitions.IrisModelName = "phase_3/models/misc/iris.bam"
        base.transitions.FadeModelName = "phase_3/models/misc/fade.bam"

        self.accept(self.inputStore.TakeScreenshot,
                    ScreenshotHandler.takeScreenshot)

        #self.accept('u', render.setShaderOff)
        #self.accept('i', render.setShaderOff, [1])
        #self.accept('o', render.setShaderOff, [2])

        # Disabled oobe culling
        #self.accept('o', self.oobeCull)
        #self.accept('c', self.reportCam)

        self.taskMgr.add(self.__updateShadersAndPostProcess,
                         'CIBase.updateShadersAndPostProcess', 47)
        self.taskMgr.add(self.__update3DAudio, 'CIBase.update3DAudio', 59)
示例#4
0
 def chatStompComplete(self, chatString):
     if not self.thoughtInProg and CIGlobals.getSettingsMgr().getSetting(
             "chs").getValue():
         self.playChatSfx(chatString)
示例#5
0
 def __getMouseSensitivity(self):
     return CIGlobals.getSettingsMgr().getSetting('fpmgms').getValue()
示例#6
0
    def cameraMovement(self, task):
        if hasattr(self, 'min_camerap') and hasattr(
                self, 'max_camerap') and base.mouseWatcherNode.hasMouse():
            md = base.win.getPointer(0)
            x = md.getX()
            y = md.getY()
            centerX = base.win.getXSize() / 2
            centerY = base.win.getYSize() / 2

            base.win.movePointer(0, centerX, centerY)

            # Get the mouse sensitivity
            sens = CIGlobals.getSettingsMgr().getSetting("fpmgms").getValue()

            dt = globalClock.getDt()

            # Do some mouse movement
            goalH = self.player_node.getH() - (x - centerX) * sens
            self.player_node.setH(goalH)
            goalP = self.player_node.getP() - (y - centerY) * sens
            if goalP < self.min_camerap:
                goalP = self.min_camerap
            elif goalP > self.max_camerap:
                goalP = self.max_camerap
            self.player_node.setP(goalP)
            self.geomNodeRenderYaw = base.localAvatar.getGeomNode().getH(
                render)

            if base.localAvatar.isMoving():
                # We can turn our character with the mouse while moving.
                oldH = base.localAvatar.getH(render)
                base.localAvatar.walkControls.rotationSpeed = abs(
                    oldH - base.localAvatar.getH(render)) / 1.5
                base.localAvatar.setH(render, self.player_node.getH(render))
                self.player_node.setH(0)

                spine = base.localAvatar.find("**/def_cageA")

                if not spine.isEmpty():
                    spine.setH(0)
                    spine.setP(render, self.player_node.getP(render))
                    spine.setR(0)

                if self.firstTimeMoving:
                    self.firstTimeMoving = False
                    base.localAvatar.getGeomNode().setH(
                        render, self.geomNodeRenderYaw)
                    if self.geomNodeTurnIval:
                        self.geomNodeTurnIval.finish()
                        self.geomNodeTurnIval = None
                    distance = (base.localAvatar.getGeomNode().getH() % 360)
                    if distance > 180:
                        distance = 360 - distance
                    self.geomNodeTurnIval = Sequence(
                        Func(base.localAvatar.setForceRunSpeed, True),
                        LerpHprInterval(
                            base.localAvatar.getGeomNode(),
                            duration=distance / self.GeomNodeTurnSpeed,
                            hpr=(0, 0, 0),
                            startHpr=base.localAvatar.getGeomNode().getHpr()),
                        Func(base.localAvatar.setForceRunSpeed, False))
                    self.geomNodeTurnIval.start()
            elif not base.localAvatar.isMoving(
            ) and base.localAvatar.smartCamera.isOverTheShoulder():
                oldH = base.localAvatar.getH(render)
                base.localAvatar.walkControls.rotationSpeed = abs(
                    oldH - base.localAvatar.getH(render)) / 1.5
                spine = base.localAvatar.find("**/def_cageA")

                if not spine.isEmpty():
                    spine.setH(render, self.player_node.getH(render))
                    spine.setP(render, self.player_node.getP(render))
                    spine.setR(0)

                    discrep = abs(
                        spine.getH(render) - base.localAvatar.getH(render))
                    if discrep > self.MaxSpineLegsDiscrepency:
                        spine.setHpr(0, 0, 0)
                        base.localAvatar.setH(render,
                                              self.player_node.getH(render))
                        self.player_node.setH(0)
            else:
                self.firstTimeMoving = True

        return task.cont
示例#7
0
 def setupControls(self):
     self.walkControls = CILocalControls()
     self.walkControls.setupControls()
     self.walkControls.setMode(
         CIGlobals.getSettingsMgr().getSetting("bpov").getValue())
示例#8
0
    def __init__(self,
                 parent,
                 options,
                 pos=(0, 0, 0),
                 command=None,
                 widgetName="",
                 choiceTextScale=0.08,
                 desc="",
                 settingKeyName=None,
                 mode=AUTO,
                 requirement=None):
        """ 
        Generates an ordered choice widget with the specified parameters.
        
        Parameters:
        
        parent: Pretty much self-explanatory, this is the parent of the widget.
        If an object with a `book` attribute is passed in, it will use that instead.
        
        options: A list of options that the user can select with the GUI.
        
        pos: Pretty much self-explanatory.
        
        command: Function that should be executed whenever a game setting is updated.
        The newly saved choice is passed to the specified function.
        
        widgetName: The label shown to the left of the widget identifying what the widget
        is for.
        
        choiceTextScale: The scale of the text which displays which option the user has
        currently selected.
        
        desc: Optional description of what the choices displayed by this widget are for.
        
        settingKeyName: The name of the key inside of the game settings map that this choice
        widget works with. This MUST be set if trying to simulate a game setting changer widget.
        
        mode: This is the kind of widget this is going to be. Use one of the following:
            - AUTO:
                - The system will attempt to figure out what the type of choices are available.
                    * 2 options automatically looks like a true/false widget *
            - MULTICHOICE:
                - This overrides the system in case there are two options but true/false functionality
                isn't wanted.
            - DEGREE:
                - This means that the choice widget deals with x in front of some sort of degree value that should
                - be stripped away when selecting choices. This is used for the antialiasing choice widget.
        
        """
        self.requirement = requirement
        self.options = options
        self.command = command
        self.currentChoiceIndex = 0
        self.origChoice = None
        self.userChoice = None
        self.settingKeyName = settingKeyName
        self.mode = mode

        # Let's update the options if we specified a setting key name.
        if self.settingKeyName and len(self.settingKeyName) > 0:
            settingsMgr = CIGlobals.getSettingsMgr()
            settingInst = settingsMgr.getSetting(self.settingKeyName)

            if not settingInst:
                raise ValueError("Setting \"{0}\" could not be found!".format(
                    self.settingKeyName))
            else:
                self.options = settingInst.getOptions()
                desc = settingInst.getDescription()

        widgetParent = parent
        if hasattr(parent, 'book'):
            widgetParent = parent.book

        DirectFrame.__init__(self, parent=widgetParent, pos=pos)

        bg = loader.loadModel('phase_3/models/gui/ChatPanel.bam')

        self.selFrame = DirectFrame(pos=(0.4, 0, 0),
                                    frameColor=(1.0, 1.0, 1.0, 1.0),
                                    image=bg,
                                    relief=None,
                                    image_scale=(0.22, 0.11, 0.11),
                                    image_pos=(-0.107, 0.062, 0.062),
                                    parent=self)

        self.choiceText = OnscreenText(text="Hello!",
                                       align=TextNode.ACenter,
                                       parent=self.selFrame,
                                       pos=(0, -0.01),
                                       scale=choiceTextScale)
        self.fwdBtn = CIGlobals.makeDirectionalBtn(1,
                                                   self.selFrame,
                                                   pos=(0.2, 0, 0),
                                                   command=self.__goFwd)
        self.bckBtn = CIGlobals.makeDirectionalBtn(0,
                                                   self.selFrame,
                                                   pos=(-0.2, 0, 0),
                                                   command=self.__goBck)

        self.lbl = OnscreenText(text=widgetName + ":",
                                pos=(-0.7, 0, 0),
                                align=TextNode.ALeft,
                                parent=self)

        if len(desc) > 0:
            self.desc = OnscreenText(text=desc,
                                     pos=(0.0, -0.1, 0.0),
                                     parent=self.selFrame,
                                     scale=0.05,
                                     bg=DESC_BACKGROUND_COLOR,
                                     mayChange=False)
            self.desc.setBin('gui-popup', 40)
            self.desc.hide()

            # Let's bind our events on the selection frame for the description.
            self.selFrame['state'] = DGG.NORMAL
            self.selFrame.bind(DGG.ENTER,
                               self.__setDescVisible,
                               extraArgs=[True])
            self.selFrame.bind(DGG.EXIT,
                               self.__setDescVisible,
                               extraArgs=[False])

        self.initialiseoptions(ChoiceWidget)

        self.reset()

        bg.detachNode()
        del bg
示例#9
0
 def __getCurrentSetting(self):
     return CIGlobals.getSettingsMgr().getSetting(self.settingKeyName)
示例#10
0
def __applyAF(task):
    af = CIGlobals.getSettingsMgr().getSetting("af").getValue()
    for tex in render.findAllTextures():
        if tex.getAnisotropicDegree() != af:
            tex.setAnisotropicDegree(af)
    return task.cont
示例#11
0
 def _setDefaults(self):
     self.origMaspr = CIGlobals.getSettingsMgr().getSetting(
         "maspr").getValue()
     self.masprChoice = self.origMaspr