Пример #1
0
def main():
    last_fps_write = time_in_seconds()
    server = GameServer(Settings.DefaultMod, Settings.DefaultMap, 1337, 32)
    done = False
    time_delta = 0.001  #just assume 1 millisecond for the first frame
    while not done:
        last_tick = time_in_seconds()
        server.update(time_delta)
        time_delta = time_in_seconds() - last_tick
        if time_in_seconds() - last_fps_write > 2:
            print 'FPS:', 1.0 / time_delta
            last_fps_write = time_in_seconds()
Пример #2
0
def main():
    last_fps_write = time_in_seconds()
    server = GameServer( Settings.DefaultMod, Settings.DefaultMap, 1337, 32)
    done = False
    time_delta = 0.001 #just assume 1 millisecond for the first frame
    while not done:
        last_tick  = time_in_seconds()
        server.update(time_delta)
        time_delta = time_in_seconds() - last_tick
        if time_in_seconds() - last_fps_write > 2:
            print 'FPS:', 1.0/time_delta
            last_fps_write = time_in_seconds()
Пример #3
0
def mainloop(app):
    time_delta = 0.00001
    last_tick = 0
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
            elif event.type == pygame.KEYDOWN: app.handleKeyDownEvent( event )
            elif event.type == pygame.KEYUP: app.handleKeyUpEvent( event )
        last_tick  = time_in_seconds()
        app.update(time_delta)
        app.drawScreen()
        time_delta = time_in_seconds() - last_tick
    del app
Пример #4
0
def mainloop(app):
    time_delta = 0.00001
    last_tick = 0
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
            elif event.type == pygame.KEYDOWN: app.handleKeyDownEvent(event)
            elif event.type == pygame.KEYUP: app.handleKeyUpEvent(event)
        last_tick = time_in_seconds()
        app.update(time_delta)
        app.drawScreen()
        time_delta = time_in_seconds() - last_tick
    del app
Пример #5
0
    def onConnect(self, connection, event):
        print "Accepted connection from:", event.peer.address

        #construct spawn ent messages
        print "making spawn packets"

        def makepacket(ent):
            assert ent.entID is not None
            return str(
                GameProtocol.SpawnEnt(asUnixPath(ent.typeInfo.typePath),
                                      ent.scriptname, ent.entID,
                                      ent.location.x, ent.location.y,
                                      ent.location.z, ent.q4.x, ent.q4.y,
                                      ent.q4.z, ent.q4.w))

        packets = [
            makepacket(x) for x in self.world.scene.dynamicEnts if x.serverside
        ]

        print "made packets"
        #send out the packets
        for packet in packets:
            connection.send(packet)
        connection.lastMoveUpdate = time_in_seconds()
        print "packets sent"
Пример #6
0
    def onConnect(self, connection, event):
        print "Accepted connection from:", event.peer.address

        #construct spawn ent messages
        print "making spawn packets"
        def makepacket(ent):
            assert ent.entID is not None
            return str(GameProtocol.SpawnEnt(
                                         asUnixPath(ent.typeInfo.typePath),
                                         ent.scriptname,
                                         ent.entID,
                                         ent.location.x,
                                         ent.location.y,
                                         ent.location.z,
                                         ent.q4.x,
                                         ent.q4.y,
                                         ent.q4.z,
                                         ent.q4.w))
        packets = [ makepacket(x) for x in self.world.scene.dynamicEnts
                    if x.serverside ]

        print "made packets"
        #send out the packets
        for packet in packets:
            connection.send( packet )
        connection.lastMoveUpdate = time_in_seconds()
        print "packets sent"
Пример #7
0
 def __init__(self, ent, packet, ping):
     l = vec3(packet.x, packet.y, packet.z)
     v = vec3(packet.vx, packet.vy, packet.vz)
     self.moveStartTime = time_in_seconds()
     self.moveEndTime  = self.packetReceived + ping
     self.initialLocation = ent.location
     self.initialVelocity = ent.velocity
     self.finalLocation = l + v * (0.5*ping)
     self.finalVelocity = v
Пример #8
0
    def load(self):
        self.keyDown   = {}
        self.fps       = 0
        self.right_btn = False
        #initialize the screen/window
        self.size = self.width, self.height = Settings.Resolution
        self.fullscreen = Settings.Fullscreen
        self.resetVideoMode()

        #init network variable thingy
        self.network = None

        #create console
        self.console = Console.Console( Graphics.Rectangle( 20, 20, self.width-20, self.height-20) )
        self.console.setAsStdOut()
        self.console.onInput = self.onConsoleInput

        #initialize some basic opengl states
        GraphicsCard.enable( 'depth_test')
        GraphicsCard.setDepthFunc('less')
        GraphicsCard.setShadeModel( 'smooth' )
        GraphicsCard.setScreenProjection( float(self.width/self.height), 0.1, 5000.0 )

        self.font    = Font.TextureFont( '../base/fonts/tahoma.fnt' )
        self.bigfont = Font.TextureFont( '../base/fonts/tahoma_20.fnt' )
        FontManager.GetFont( Settings.ConsoleFont )
        loadscreen = TextureManager.GetTexture( '../base/art/ui/facehatlogo.png' )

        #Draw loading screen
        GraphicsCard.clearDepth(1.0)
        GraphicsCard.clearColor( (1, 1, 1, 1) )
        GraphicsCard.clear()
        #glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
        GraphicsCard.setBlendFunction( 'src_alpha', 'one_minus_src_alpha' )
        GraphicsCard.enable( 'blend', 'texture_2d')
        gl2D.start2D()
        gl2D.drawTexture2D( loadscreen, self.width/2-256, self.height/2-256, 512, 512 )
        self.bigfont.draw(self.width/2, self.height/2-280, "Loading..." )
        gl2D.end2D()
        pygame.display.flip()

        #hide/show cursor
        if Settings.GrabMouse:
            pygame.mouse.set_visible(False)
            pygame.event.set_grab(True)
        else:
            pygame.mouse.set_visible(True)
            pygame.event.set_grab(False)

        #Initialize OpenGL extensions
        GraphicsCard.initExtensions()

        #check for OpenGL 2.0
        if Settings.UseShaders and GraphicsCard.hasShaders():
            print "Shader Support Present"
            Settings.UseShaders = True
        else:
            print "Warning: No shader support, or shaders disabled"
            Settings.UseShaders = False
        print "Max Anisotropy:", GraphicsCard.getMaxAnisotropy()

        ###load the map
        if Settings.SinglePlayer:
            self.world = World.World( Settings.DefaultMod, Settings.DefaultMap, is_server=True, graphics_enabled=True )
        else:
            self.world = World.World( Settings.DefaultMod, Settings.DefaultMap, is_server=False, graphics_enabled=True )
        self.world.initGraphics()
        self.lastjump = time_in_seconds()

        #setup lighting
        n = vec3(0, 1, 0 )
        glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0] )
        glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, [0.9, 0.9, 0.9, 1.0] )
        glLightfv( GL_LIGHT0, GL_AMBIENT,  [0.0, 0.0, 0.0, 1.0 ] )
        glLightfv( GL_LIGHT0, GL_DIFFUSE,  [1.0, 1.0, 1.0, 1.0 ] )
        glLightfv( GL_LIGHT0, GL_POSITION, [n.x, n.y, n.z, 0] )
        GraphicsCard.clearColor((0.0, 0.0, 1.0, 0.0))
        GraphicsCard.enable('light0')
Пример #9
0
    def update(self, timedelta):
        """Updates the game state"""
        if timedelta:
            self.fps = 1.0/timedelta
        cameraMoveVector = vec3(0,0,0)
        jump_force = 0
        mx, my = 0, 0
        if Settings.RunPhysics:
            move_speed = 100
            max_jump_force = 200
        else:
            move_speed = 5
            max_jump_force = 5
        if isinstance( self.world.camera, Camera.Freecam ):
            move_speed = 5
            max_jump_force = 5

        if not self.consoleVisible:
            if self._isKeyDown(pygame.K_LEFT): mx = -6
            if self._isKeyDown(pygame.K_RIGHT): mx = 6
            if self._isKeyDown(pygame.K_UP): my = -6
            if self._isKeyDown(pygame.K_DOWN): my = 6
            if self._isKeyDown(pygame.K_w): cameraMoveVector.z = 1
            if self._isKeyDown(pygame.K_s): cameraMoveVector.z = -1
            if self._isKeyDown(pygame.K_a): cameraMoveVector.x = -1
            if self._isKeyDown(pygame.K_d): cameraMoveVector.x =  1
            if self._isKeyDown(pygame.K_x): self.world.frustrum_camera = self.world.camera.asFreecam()
            if self._isKeyDown(pygame.K_SPACE):
                #if time_in_seconds() - self.lastjump > 0.5:
                jump_force = max_jump_force
                self.lastjump = time_in_seconds()
            if cameraMoveVector.length():
                cameraMoveVector = cameraMoveVector.normalize()
                cameraMoveVector = cameraMoveVector * move_speed

            left_btn, middle_btn, right_btn = pygame.mouse.get_pressed()

            if right_btn or Settings.GrabMouse:
                mx, my = pygame.mouse.get_rel()
            else:
                pygame.mouse.get_rel()
            self.right_btn = right_btn
            self.world.camera.turn( degreeToRadian( -mx*0.2 ),
                                    degreeToRadian( -my*0.2 ),
                                    0 )

        #move the camera
        cameraMoveVector.y = jump_force
        self.world.camera.move( cameraMoveVector )

        px = self.world.camera.position.x
        py = self.world.camera.position.y
        pz = self.world.camera.position.z
        yaw = self.world.camera.yaw
        DebugDisplay.update('world_position', (int(px), int(py), int(pz)) )
        DebugDisplay.update('opacity',
                            self.world.lightIntensityAt( px, pz) )

        #update world
        self.world.update( timedelta )

        if self.network: self.network.update()

        #update debug display
        DebugDisplay.step( timedelta )
Пример #10
0
    def load(self):
        self.keyDown = {}
        self.fps = 0
        self.right_btn = False
        #initialize the screen/window
        self.size = self.width, self.height = Settings.Resolution
        self.fullscreen = Settings.Fullscreen
        self.resetVideoMode()

        #init network variable thingy
        self.network = None

        #create console
        self.console = Console.Console(
            Graphics.Rectangle(20, 20, self.width - 20, self.height - 20))
        self.console.setAsStdOut()
        self.console.onInput = self.onConsoleInput

        #initialize some basic opengl states
        GraphicsCard.enable('depth_test')
        GraphicsCard.setDepthFunc('less')
        GraphicsCard.setShadeModel('smooth')
        GraphicsCard.setScreenProjection(float(self.width / self.height), 0.1,
                                         5000.0)

        self.font = Font.TextureFont('../base/fonts/tahoma.fnt')
        self.bigfont = Font.TextureFont('../base/fonts/tahoma_20.fnt')
        FontManager.GetFont(Settings.ConsoleFont)
        loadscreen = TextureManager.GetTexture(
            '../base/art/ui/facehatlogo.png')

        #Draw loading screen
        GraphicsCard.clearDepth(1.0)
        GraphicsCard.clearColor((1, 1, 1, 1))
        GraphicsCard.clear()
        #glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
        GraphicsCard.setBlendFunction('src_alpha', 'one_minus_src_alpha')
        GraphicsCard.enable('blend', 'texture_2d')
        gl2D.start2D()
        gl2D.drawTexture2D(loadscreen, self.width / 2 - 256,
                           self.height / 2 - 256, 512, 512)
        self.bigfont.draw(self.width / 2, self.height / 2 - 280, "Loading...")
        gl2D.end2D()
        pygame.display.flip()

        #hide/show cursor
        if Settings.GrabMouse:
            pygame.mouse.set_visible(False)
            pygame.event.set_grab(True)
        else:
            pygame.mouse.set_visible(True)
            pygame.event.set_grab(False)

        #Initialize OpenGL extensions
        GraphicsCard.initExtensions()

        #check for OpenGL 2.0
        if Settings.UseShaders and GraphicsCard.hasShaders():
            print "Shader Support Present"
            Settings.UseShaders = True
        else:
            print "Warning: No shader support, or shaders disabled"
            Settings.UseShaders = False
        print "Max Anisotropy:", GraphicsCard.getMaxAnisotropy()

        ###load the map
        if Settings.SinglePlayer:
            self.world = World.World(Settings.DefaultMod,
                                     Settings.DefaultMap,
                                     is_server=True,
                                     graphics_enabled=True)
        else:
            self.world = World.World(Settings.DefaultMod,
                                     Settings.DefaultMap,
                                     is_server=False,
                                     graphics_enabled=True)
        self.world.initGraphics()
        self.lastjump = time_in_seconds()

        #setup lighting
        n = vec3(0, 1, 0)
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.9, 0.9, 0.9, 1.0])
        glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0])
        glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
        glLightfv(GL_LIGHT0, GL_POSITION, [n.x, n.y, n.z, 0])
        GraphicsCard.clearColor((0.0, 0.0, 1.0, 0.0))
        GraphicsCard.enable('light0')
Пример #11
0
    def update(self, timedelta):
        """Updates the game state"""
        if timedelta:
            self.fps = 1.0 / timedelta
        cameraMoveVector = vec3(0, 0, 0)
        jump_force = 0
        mx, my = 0, 0
        if Settings.RunPhysics:
            move_speed = 100
            max_jump_force = 200
        else:
            move_speed = 5
            max_jump_force = 5
        if isinstance(self.world.camera, Camera.Freecam):
            move_speed = 5
            max_jump_force = 5

        if not self.consoleVisible:
            if self._isKeyDown(pygame.K_LEFT): mx = -6
            if self._isKeyDown(pygame.K_RIGHT): mx = 6
            if self._isKeyDown(pygame.K_UP): my = -6
            if self._isKeyDown(pygame.K_DOWN): my = 6
            if self._isKeyDown(pygame.K_w): cameraMoveVector.z = 1
            if self._isKeyDown(pygame.K_s): cameraMoveVector.z = -1
            if self._isKeyDown(pygame.K_a): cameraMoveVector.x = -1
            if self._isKeyDown(pygame.K_d): cameraMoveVector.x = 1
            if self._isKeyDown(pygame.K_x):
                self.world.frustrum_camera = self.world.camera.asFreecam()
            if self._isKeyDown(pygame.K_SPACE):
                #if time_in_seconds() - self.lastjump > 0.5:
                jump_force = max_jump_force
                self.lastjump = time_in_seconds()
            if cameraMoveVector.length():
                cameraMoveVector = cameraMoveVector.normalize()
                cameraMoveVector = cameraMoveVector * move_speed

            left_btn, middle_btn, right_btn = pygame.mouse.get_pressed()

            if right_btn or Settings.GrabMouse:
                mx, my = pygame.mouse.get_rel()
            else:
                pygame.mouse.get_rel()
            self.right_btn = right_btn
            self.world.camera.turn(degreeToRadian(-mx * 0.2),
                                   degreeToRadian(-my * 0.2), 0)

        #move the camera
        cameraMoveVector.y = jump_force
        self.world.camera.move(cameraMoveVector)

        px = self.world.camera.position.x
        py = self.world.camera.position.y
        pz = self.world.camera.position.z
        yaw = self.world.camera.yaw
        DebugDisplay.update('world_position', (int(px), int(py), int(pz)))
        DebugDisplay.update('opacity', self.world.lightIntensityAt(px, pz))

        #update world
        self.world.update(timedelta)

        if self.network: self.network.update()

        #update debug display
        DebugDisplay.step(timedelta)