def __init__(self): """ The AI Repository usually lives on a server and is responsible for server side logic that will handle game objects """ # List of all dc files that are of interest to this AI Repository dcFileNames = ['../direct.dc', 'sample.dc'] # Initialize the repository. We pass it the dc files and as this is an # AI repository the dcSuffix AI. This will make sure any later calls to # createDistributedObject will use the correct version. # The connectMethod ClientRepository.__init__(self, dcFileNames=dcFileNames, dcSuffix='AI', threadedNet=True) # Set the same port as configured on the server to be able to connect # to it tcpPort = ConfigVariableInt('server-port', 4400).getValue() # Set the IP or hostname of the server we want to connect to hostname = ConfigVariableString('server-host', '127.0.0.1').getValue() # Build the URL from the server hostname and port. If your server # doesn't use http you should change it accordingly. Make sure to pass # the connectMethod to the ClientRepository.__init__ call too. # Available connection methods are: # self.CM_HTTP, self.CM_NET and self.CM_NATIVE url = URLSpec('http://{}:{}'.format(hostname, tcpPort)) # Attempt a connection to the server self.connect([url], successCallback=self.connectSuccess, failureCallback=self.connectFailure)
def __init__(self): dcFileNames = ['../direct.dc'] # a distributed object of our game. self.distributedObject = None self.aiDGameObect = None ClientRepository.__init__( self, dcFileNames = dcFileNames, threadedNet = True) # Set the same port as configured on the server to be able to connect # to it tcpPort = ConfigVariableInt('server-port', 4400).getValue() # Set the IP or hostname of the server we want to connect to hostname = ConfigVariableString('server-host', '127.0.0.1').getValue() # Build the URL from the server hostname and port. If your server # uses another protocol then http you should change it accordingly. # Make sure to pass the connectMethod to the ClientRepository.__init__ # call too. Available connection methods are: # self.CM_HTTP, self.CM_NET and self.CM_NATIVE self.url = URLSpec('http://{}:{}'.format(hostname, tcpPort)) # Attempt a connection to the server self.connect([self.url], successCallback = self.connectSuccess, failureCallback = self.connectFailure)
def __init__(self, threadedNet = True): dcFileNames = ['direct.dc', 'tagger.dc'] ClientRepository.__init__(self, dcFileNames = dcFileNames, dcSuffix = 'AI', connectMethod = self.CM_NET, threadedNet = threadedNet) # Need at least 32 bits to receive big picture packets. self.setTcpHeaderSize(4) # Allow some time for other processes. base.setSleep(0.01) taskMgr.setupTaskChain('updateCells', numThreads = 1, threadPriority = TPLow, frameSync = True) taskMgr.doMethodLater(5, self.__checkPosters, 'checkPosters') self.games = [] tcpPort = base.config.GetInt('server-port', Globals.ServerPort) hostname = base.config.GetString('server-host', Globals.ServerHost) if not hostname: hostname = 'localhost' url = URLSpec('g://%s:%s' % (hostname, tcpPort)) self.connect([url], successCallback = self.connectSuccess, failureCallback = self.connectFailure)
def __init__(self, threadedNet=True): dcFileNames = ['direct.dc', 'tagger.dc'] ClientRepository.__init__(self, dcFileNames=dcFileNames, dcSuffix='AI', connectMethod=self.CM_NET, threadedNet=threadedNet) # Need at least 32 bits to receive big picture packets. self.setTcpHeaderSize(4) # Allow some time for other processes. base.setSleep(0.01) taskMgr.setupTaskChain('updateCells', numThreads=1, threadPriority=TPLow, frameSync=True) taskMgr.doMethodLater(5, self.__checkPosters, 'checkPosters') self.games = [] tcpPort = base.config.GetInt('server-port', Globals.ServerPort) hostname = base.config.GetString('server-host', Globals.ServerHost) if not hostname: hostname = 'localhost' url = URLSpec('g://%s:%s' % (hostname, tcpPort)) self.connect([url], successCallback=self.connectSuccess, failureCallback=self.connectFailure)
def __init__(self): dcFileNames = ['direct.dc', 'net.dc'] ClientRepository.__init__(self, dcFileNames = dcFileNames, dcSuffix = 'AI') tcpPort = base.config.GetInt('server-port', 4400) url = URLSpec('http://127.0.0.1:%s' % (tcpPort)) self.connect([url], successCallback = self.connectSuccess, failureCallback = self.connectFailure)
def __init__(self): dcFileNames = ['distributed/direct.dc', 'distributed/net.dc'] ClientRepository.__init__(self, dcFileNames = dcFileNames, dcSuffix = 'AI') tcpPort = base.config.GetInt('server-port', 4400) url = URLSpec('http://127.0.0.1:%s' % (tcpPort)) self.connect([url], successCallback = self.connectSuccess, failureCallback = self.connectFailure)
def __init__(self): print("SETUP AI REPOSITORY") dcFileNames = ["interfaces/direct.dc", "interfaces/gameRoom.dc", "interfaces/chat.dc"] ClientRepository.__init__( self, dcFileNames = dcFileNames, dcSuffix = 'AI', threadedNet = True) hostname = base.serverHost.getValue() print("CONNECT TO:", hostname) url = URLSpec('http://{}'.format(hostname)) self.connect([url], successCallback = self.connectSuccess, failureCallback = self.connectFailure)
def __init__(self, readyCommand, readyCommandArgs, failedCommand, failedCommandArgs): dcFileNames = [ "interfaces/direct.dc", "interfaces/gameRoom.dc", "interfaces/chat.dc" ] ClientRepository.__init__(self, dcFileNames=dcFileNames, threadedNet=True) self.roomManager = None self.readyCommand = readyCommand self.readyCommandArgs = readyCommandArgs self.failedCommand = failedCommand self.failedCommandArgs = failedCommandArgs hostname = base.serverHost.getValue() self.url = URLSpec('http://{}'.format(hostname)) self.connect([self.url], successCallback=self.connectSuccess, failureCallback=self.connectFailure)
def __init__(self): dcFileNames = ['direct.dc', 'net.dc'] ClientRepository.__init__(self, dcFileNames=dcFileNames)
def __init__(self): # list of all needed .dc files dcFileNames = ['distributed/direct.dc', 'distributed/net.dc'] # initialise the client repository on this # machine with the dc filenames ClientRepository.__init__(self, dcFileNames = dcFileNames)
def __init__(self, playerName=None, threadedNet=True): dcFileNames = ["direct.dc", "tagger.dc"] ClientRepository.__init__(self, dcFileNames=dcFileNames, connectMethod=self.CM_NET, threadedNet=threadedNet) base.transitions.FadeModelName = "models/fade" # Need at least 32 bits to receive big picture packets. self.setTcpHeaderSize(4) # Allow some time for other processes. This also allows time # each frame for the network thread to run. base.setSleep(0.01) # If we're using OpenGL, we can enable shaders. (DirectX # shader support is still kind of spotty, even for simple # shaders like these.) if base.pipe and base.pipe.getInterfaceName() == "OpenGL": Globals.EnableShaders = True self.gotMusic = False self.__getMusic() # For the browse button. self.posterDefaultDir = Filename.getHomeDirectory().toOsSpecific() # Load a fun font to be the default text font. labelFont = loader.loadFont("models/amsterdam.ttf", okMissing=True) if labelFont: # Make a fuzzy halo behind the font so it looks kind of # airbrushy labelFont.setOutline(VBase4(0, 0, 0, 1), 2.0, 0.9) TextNode.setDefaultFont(labelFont) base.disableMouse() if base.mouseWatcher: mb = ModifierButtons() mb.addButton(KeyboardButton.control()) base.mouseWatcher.node().setModifierButtons(mb) base.buttonThrowers[0].node().setModifierButtons(mb) taskMgr.setupTaskChain("loadPoster", numThreads=4, threadPriority=TPLow) # taskMgr.setupTaskChain('net', numThreads = 1, threadPriority = TPLow, frameSync = True) # Set up a text property called "tag" that renders using the # tag font, in white, with a shadow. This is used for # rendering the art-painting awards at the end of the round. tpMgr = TextPropertiesManager.getGlobalPtr() tp = TextProperties() tagFont = loader.loadFont("models/one8seven.ttf", okMissing=True) if tagFont: tp.setFont(tagFont) tp.setTextColor(1, 1, 1, 1) tp.setShadow(0.05, 0.05) tp.setTextScale(1.5) tpMgr.setProperties("tag", tp) # If we're running from the web, get the gameInfo block from # the HTML tokens. self.gameInfo = None if base.appRunner: gameInfoName = base.appRunner.getToken("gameInfo") if gameInfoName: self.gameInfo = base.appRunner.evalScript(gameInfoName, needsResponse=True) # Expose the changePoster() method. base.appRunner.main.changePoster = self.changePoster print "self.gameInfo = %s" % (self.gameInfo) # Also be prepared to update the web form with the table of # players and the local player's score. self.playerTable = None self.scoreTable = None if base.appRunner and base.appRunner.dom: self.playerTable = base.appRunner.dom.document.getElementById("playerTable") self.scoreTable = base.appRunner.dom.document.getElementById("scoreTable") print "self.playerTable = %s, scoreTable = %s" % (self.playerTable, self.scoreTable) self.playerList = PlayerList(self.playerTable) self.onscreenScoreLeft = None # When we join a game, we'll prefer to join *this* game. self.nextGameId = 0 self.chooseGameTask = None self.allGames = [] # No game, no avatar (yet). self.robot = None self.game = None self.player = None self.av = None self.avCell = None self.paintThing = None self.keyMap = {} for key in Globals.ControlKeys: self.keyMap[key] = False self.dlnp = render.attachNewNode(DirectionalLight("dlnp")) self.dlnp.node().setColor((0.8, 0.8, 0.8, 1)) render.setLight(self.dlnp) self.alnp = render.attachNewNode(AmbientLight("alnp")) self.alnp.node().setColor((0.2, 0.2, 0.2, 1)) render.setLight(self.alnp) if base.camera: self.dlnp.reparentTo(base.camera) # Set up the poster FSM to switch the poster modes. self.posterFSM = PosterFSM(base.appRunner) # A node to hold all avatars. self.avRoot = render.attachNewNode("avRoot") # The root of the maze. self.mazeRoot = render.attachNewNode("maze") if Globals.EnableShaders: # self.mazeRoot.setShaderAuto() s = loader.loadShader("models/nopaint_normal.sha") self.mazeRoot.setShader(s) self.mazeRoot.setShaderInput("alight0", self.alnp) self.mazeRoot.setShaderInput("dlight0", self.dlnp) # Initial poster data. self.posterData = ("", 0) cvar = ConfigVariableFilename("tag-poster", "") filename = cvar.getValue() if filename: self.readTagPoster(filename) # Choose a bright paint color. h = random.random() s = random.random() * 0.3 + 0.7 v = random.random() * 0.3 + 0.7 self.playerColor = self.hsv2rgb(h, s, v) # Get the player's name. name = playerName if not name: name = getattr(self.gameInfo, "name", None) if not name: name = base.config.GetString("player-name", "") if name: # Use the provided name. self.playerName = name self.startConnect() else: # Prompt the user. # Start with the wall model in the background. wall = loader.loadModel("models/wall") wall.reparentTo(base.camera) wall.setPos(0, 5, -2.5) wall.setScale(10) if Globals.EnableShaders: wall.setShaderAuto() self.nameWall = wall c = self.playerColor self.nameLabel = DirectLabel( text="Enter your street name:", text_align=TextNode.ALeft, text_fg=(c[0], c[1], c[2], 1), text_shadow=(0, 0, 0, 1), pos=(-0.9, 0, 0.45), relief=None, scale=0.2, ) tagFont = loader.loadFont("models/one8seven.ttf") cardModel = loader.loadModel("models/nametag_card") cardTex = cardModel.findTexture("*") self.nameEntry = DirectEntry( pos=(-0.9, 0, 0.1), focus=True, relief=DGG.TEXTUREBORDER, frameColor=(c[0], c[1], c[2], 0.6), frameTexture=cardTex, borderWidth=(0.2, 0.2), pad=(0.0, -0.2), borderUvWidth=(0.1, 0.1), text_font=tagFont, width=12, scale=0.15, command=self.enteredName, ) self.nameButton = DirectButton( text="Enter game", frameColor=(c[0], c[1], c[2], 1), scale=0.15, pos=(0, 0, -0.5), relief=DGG.RAISED, borderWidth=(0.05, 0.05), pad=(0.8, 0.3), command=self.enteredName, )
def __init__(self, playerName = None, threadedNet = True): dcFileNames = ['direct.dc', 'tagger.dc'] ClientRepository.__init__(self, dcFileNames = dcFileNames, connectMethod = self.CM_NET, threadedNet = threadedNet) base.transitions.FadeModelName = 'models/fade' # Need at least 32 bits to receive big picture packets. self.setTcpHeaderSize(4) # Allow some time for other processes. This also allows time # each frame for the network thread to run. base.setSleep(0.01) # If we're using OpenGL, we can enable shaders. (DirectX # shader support is still kind of spotty, even for simple # shaders like these.) if base.pipe and base.pipe.getInterfaceName() == 'OpenGL': Globals.EnableShaders = True self.gotMusic = False self.__getMusic() # For the browse button. self.posterDefaultDir = Filename.getHomeDirectory().toOsSpecific() # Load a fun font to be the default text font. labelFont = loader.loadFont('models/amsterdam.ttf', okMissing = True) if labelFont: # Make a fuzzy halo behind the font so it looks kind of # airbrushy labelFont.setOutline(VBase4(0, 0, 0, 1), 2.0, 0.9) TextNode.setDefaultFont(labelFont) base.disableMouse() if base.mouseWatcher: mb = ModifierButtons() mb.addButton(KeyboardButton.control()) base.mouseWatcher.node().setModifierButtons(mb) base.buttonThrowers[0].node().setModifierButtons(mb) taskMgr.setupTaskChain('loadPoster', numThreads = 4, threadPriority = TPLow) #taskMgr.setupTaskChain('net', numThreads = 1, threadPriority = TPLow, frameSync = True) # Set up a text property called "tag" that renders using the # tag font, in white, with a shadow. This is used for # rendering the art-painting awards at the end of the round. tpMgr = TextPropertiesManager.getGlobalPtr() tp = TextProperties() tagFont = loader.loadFont('models/one8seven.ttf', okMissing = True) if tagFont: tp.setFont(tagFont) tp.setTextColor(1, 1, 1, 1) tp.setShadow(0.05, 0.05) tp.setTextScale(1.5) tpMgr.setProperties('tag', tp) # If we're running from the web, get the gameInfo block from # the HTML tokens. self.gameInfo = None if base.appRunner: gameInfoName = base.appRunner.getToken('gameInfo') if gameInfoName: self.gameInfo = base.appRunner.evalScript(gameInfoName, needsResponse = True) # Expose the changePoster() method. base.appRunner.main.changePoster = self.changePoster print "self.gameInfo = %s" % (self.gameInfo) # Also be prepared to update the web form with the table of # players and the local player's score. self.playerTable = None self.scoreTable = None if base.appRunner and base.appRunner.dom: self.playerTable = base.appRunner.dom.document.getElementById('playerTable') self.scoreTable = base.appRunner.dom.document.getElementById('scoreTable') print "self.playerTable = %s, scoreTable = %s" % (self.playerTable, self.scoreTable) self.playerList = PlayerList(self.playerTable) self.onscreenScoreLeft = None # When we join a game, we'll prefer to join *this* game. self.nextGameId = 0 self.chooseGameTask = None self.allGames = [] # No game, no avatar (yet). self.robot = None self.game = None self.player = None self.av = None self.avCell = None self.paintThing = None self.keyMap = {} for key in Globals.ControlKeys: self.keyMap[key] = False self.dlnp = render.attachNewNode(DirectionalLight('dlnp')) self.dlnp.node().setColor((0.8, 0.8, 0.8, 1)) render.setLight(self.dlnp) self.alnp = render.attachNewNode(AmbientLight('alnp')) self.alnp.node().setColor((0.2, 0.2, 0.2, 1)) render.setLight(self.alnp) if base.camera: self.dlnp.reparentTo(base.camera) # Set up the poster FSM to switch the poster modes. self.posterFSM = PosterFSM(base.appRunner) # A node to hold all avatars. self.avRoot = render.attachNewNode('avRoot') # The root of the maze. self.mazeRoot = render.attachNewNode('maze') if Globals.EnableShaders: #self.mazeRoot.setShaderAuto() s = loader.loadShader('models/nopaint_normal.sha') self.mazeRoot.setShader(s) self.mazeRoot.setShaderInput('alight0', self.alnp) self.mazeRoot.setShaderInput('dlight0', self.dlnp) # Initial poster data. self.posterData = ('', 0) cvar = ConfigVariableFilename('tag-poster', '') filename = cvar.getValue() if filename: self.readTagPoster(filename) # Choose a bright paint color. h = random.random() s = random.random() * 0.3 + 0.7 v = random.random() * 0.3 + 0.7 self.playerColor = self.hsv2rgb(h, s, v) # Get the player's name. name = playerName if not name: name = getattr(self.gameInfo, 'name', None) if not name: name = base.config.GetString('player-name', '') if name: # Use the provided name. self.playerName = name self.startConnect() else: # Prompt the user. # Start with the wall model in the background. wall = loader.loadModel('models/wall') wall.reparentTo(base.camera) wall.setPos(0, 5, -2.5) wall.setScale(10) if Globals.EnableShaders: wall.setShaderAuto() self.nameWall = wall c = self.playerColor self.nameLabel = DirectLabel( text = 'Enter your street name:', text_align = TextNode.ALeft, text_fg = (c[0], c[1], c[2], 1), text_shadow = (0, 0, 0, 1), pos = (-0.9, 0, 0.45), relief = None, scale = 0.2) tagFont = loader.loadFont('models/one8seven.ttf') cardModel = loader.loadModel('models/nametag_card') cardTex = cardModel.findTexture('*') self.nameEntry = DirectEntry( pos = (-0.9, 0, 0.1), focus = True, relief = DGG.TEXTUREBORDER, frameColor = (c[0], c[1], c[2], 0.6), frameTexture = cardTex, borderWidth = (0.2, 0.2), pad = (0.0, -0.2), borderUvWidth = (0.1, 0.1), text_font = tagFont, width = 12, scale = 0.15, command = self.enteredName) self.nameButton = DirectButton( text = 'Enter game', frameColor = (c[0], c[1], c[2], 1), scale = 0.15, pos = (0, 0, -0.5), relief = DGG.RAISED, borderWidth = (0.05, 0.05), pad = (0.8, 0.3), command = self.enteredName)
def __init__(self): dcFileNames = ['direct.dc', 'net.dc'] ClientRepository.__init__(self, dcFileNames = dcFileNames)
def __init__(self): ClientRepository.__init__(self, dcFileNames=[], dcSuffix='AI') PORT = base.config.GetInt('server-port', 6668) self.connect([URLSpec('http://localhost:%s' % PORT)], successCallback=self.connectSuccess, failureCallback=self.connectFailure)
def __init__(self): # list of all needed .dc files dcFileNames = ['distributed/direct.dc', 'distributed/net.dc'] # initialise the client repository on this # machine with the dc filenames ClientRepository.__init__(self, dcFileNames=dcFileNames)