public static void enableExtensions(final GL10 pGL, final RenderOptions pRenderOptions) { final String version = pGL.glGetString(GL10.GL_VERSION); final String renderer = pGL.glGetString(GL10.GL_RENDERER); final String extensions = pGL.glGetString(GL10.GL_EXTENSIONS); Debug.d("RENDERER: " + renderer); Debug.d("VERSION: " + version); Debug.d("EXTENSIONS: " + extensions); final boolean isOpenGL10 = version.contains("1.0"); final boolean isOpenGL2X = version.contains("2."); final boolean isSoftwareRenderer = renderer.contains("PixelFlinger"); final boolean isVBOCapable = extensions.contains("_vertex_buffer_object"); final boolean isDrawTextureCapable = extensions.contains("draw_texture"); final boolean isTextureNonPowerOfTwoCapable = extensions.contains("texture_npot"); GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS = !pRenderOptions.isDisableExtensionVertexBufferObjects() && !isSoftwareRenderer && (isVBOCapable || !isOpenGL10); GLHelper.EXTENSIONS_DRAWTEXTURE = !pRenderOptions.isDisableExtensionVertexBufferObjects() && (isDrawTextureCapable || !isOpenGL10); GLHelper.EXTENSIONS_TEXTURE_NON_POWER_OF_TWO = isTextureNonPowerOfTwoCapable || isOpenGL2X; GLHelper.hackBrokenDevices(); Debug.d("EXTENSIONS_VERXTEXBUFFEROBJECTS = " + GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS); Debug.d("EXTENSIONS_DRAWTEXTURE = " + GLHelper.EXTENSIONS_DRAWTEXTURE); }
@Override public void onException( final SocketServerDiscoveryServer<DefaultDiscoveryData> pSocketServerDiscoveryServer, final Throwable pThrowable) { Debug.e(pThrowable); MultiplayerServerDiscoveryExample.this.toast("DiscoveryServer: Exception: " + pThrowable); }
@Override public void onException( final SocketServer<SocketConnectionClientConnector> pSocketServer, final Throwable pThrowable) { Debug.e(pThrowable); MultiplayerServerDiscoveryExample.this.toast("Server: Exception: " + pThrowable); }
private void initServer() { this.mSocketServer = new SocketServer<SocketConnectionClientConnector>( SERVER_PORT, new ExampleClientConnectorListener(), new ExampleServerStateListener()) { @Override protected SocketConnectionClientConnector newClientConnector( final SocketConnection pSocketConnection) throws IOException { return new SocketConnectionClientConnector(pSocketConnection); } }; this.mSocketServer.start(); try { final byte[] wifiIPv4Address = WifiUtils.getWifiIPv4AddressRaw(this); this.mSocketServerDiscoveryServer = new SocketServerDiscoveryServer<DefaultDiscoveryData>( DISCOVERY_PORT, new ExampleSocketServerDiscoveryServerListener()) { @Override protected DefaultDiscoveryData onCreateDiscoveryResponse() { return new DefaultDiscoveryData(wifiIPv4Address, SERVER_PORT); } }; this.mSocketServerDiscoveryServer.start(); } catch (final Throwable t) { Debug.e(t); } }
@Override protected void onDestroy() { if (this.mSocketServer != null) { try { this.mSocketServer.sendBroadcastServerMessage(new ConnectionCloseServerMessage()); } catch (final IOException e) { Debug.e(e); } this.mSocketServer.terminate(); } if (this.mSocketServerDiscoveryServer != null) { this.mSocketServerDiscoveryServer.terminate(); } if (this.mServerConnector != null) { this.mServerConnector.terminate(); } if (this.mSocketServerDiscoveryClient != null) { this.mSocketServerDiscoveryClient.terminate(); } super.onDestroy(); }
public Animations(JSONObject animationObject) { characterAnimations = new ArrayList<long[]>(); try { characterAnimations.add( characterAnimationArrayInitializer(animationObject.getJSONArray("animationFacingUp"))); characterAnimations.add( characterAnimationArrayInitializer(animationObject.getJSONArray("animationFacingDown"))); characterAnimations.add( characterAnimationArrayInitializer(animationObject.getJSONArray("animationFacingRight"))); characterAnimations.add( characterAnimationArrayInitializer(animationObject.getJSONArray("animationFacingLeft"))); characterAnimations.add( characterAnimationArrayInitializer( animationObject.getJSONArray("animationFacingUpWalking"))); characterAnimations.add( characterAnimationArrayInitializer( animationObject.getJSONArray("animationFacingDownWalking"))); characterAnimations.add( characterAnimationArrayInitializer( animationObject.getJSONArray("animationFacingRightWalking"))); characterAnimations.add( characterAnimationArrayInitializer( animationObject.getJSONArray("animationFacingLeftWalking"))); } catch (JSONException e) { Debug.e("Malformed JSON: ", e); } }
private void initClient(final String pIPAddress, final int pPort) { try { this.mServerConnector = new SocketConnectionServerConnector( new SocketConnection(new Socket(pIPAddress, pPort)), new ExampleServerConnectorListener()); this.mServerConnector.registerServerMessage( FLAG_MESSAGE_SERVER_CONNECTION_CLOSE, ConnectionCloseServerMessage.class, new IServerMessageHandler<SocketConnection>() { @Override public void onHandleMessage( final ServerConnector<SocketConnection> pServerConnector, final IServerMessage pServerMessage) throws IOException { MultiplayerServerDiscoveryExample.this.finish(); } }); this.mServerConnector.registerServerMessage( FLAG_MESSAGE_SERVER_ADD_FACE, AddFaceServerMessage.class, new IServerMessageHandler<SocketConnection>() { @Override public void onHandleMessage( final ServerConnector<SocketConnection> pServerConnector, final IServerMessage pServerMessage) throws IOException { final AddFaceServerMessage addFaceServerMessage = (AddFaceServerMessage) pServerMessage; MultiplayerServerDiscoveryExample.this.addFace( addFaceServerMessage.mID, addFaceServerMessage.mX, addFaceServerMessage.mY); } }); this.mServerConnector.registerServerMessage( FLAG_MESSAGE_SERVER_MOVE_FACE, MoveFaceServerMessage.class, new IServerMessageHandler<SocketConnection>() { @Override public void onHandleMessage( final ServerConnector<SocketConnection> pServerConnector, final IServerMessage pServerMessage) throws IOException { final MoveFaceServerMessage moveFaceServerMessage = (MoveFaceServerMessage) pServerMessage; MultiplayerServerDiscoveryExample.this.moveFace( moveFaceServerMessage.mID, moveFaceServerMessage.mX, moveFaceServerMessage.mY); } }); this.mServerConnector.getConnection().start(); } catch (final Throwable t) { Debug.e(t); } }
private void initServerDiscovery() { try { this.mSocketServerDiscoveryClient = new SocketServerDiscoveryClient<DefaultDiscoveryData>( WifiUtils.getBroadcastIPAddressRaw(this), DISCOVERY_PORT, LOCAL_PORT, DefaultDiscoveryData.class, new ISocketServerDiscoveryClientListener<DefaultDiscoveryData>() { @Override public void onDiscovery( final SocketServerDiscoveryClient<DefaultDiscoveryData> pSocketServerDiscoveryClient, final DefaultDiscoveryData pDiscoveryData) { try { final String ipAddressAsString = IPUtils.ipAddressToString(pDiscoveryData.getServerIP()); MultiplayerServerDiscoveryExample.this.toast( "DiscoveryClient: Server discovered at: " + ipAddressAsString + ":" + pDiscoveryData.getServerPort()); MultiplayerServerDiscoveryExample.this.initClient( ipAddressAsString, pDiscoveryData.getServerPort()); } catch (final UnknownHostException e) { MultiplayerServerDiscoveryExample.this.toast( "DiscoveryClient: IPException: " + e); } } @Override public void onTimeout( final SocketServerDiscoveryClient<DefaultDiscoveryData> pSocketServerDiscoveryClient, final SocketTimeoutException pSocketTimeoutException) { Debug.e(pSocketTimeoutException); MultiplayerServerDiscoveryExample.this.toast( "DiscoveryClient: Timeout: " + pSocketTimeoutException); } @Override public void onException( final SocketServerDiscoveryClient<DefaultDiscoveryData> pSocketServerDiscoveryClient, final Throwable pThrowable) { Debug.e(pThrowable); MultiplayerServerDiscoveryExample.this.toast( "DiscoveryClient: Exception: " + pThrowable); } }); this.mSocketServerDiscoveryClient.discoverAsync(); } catch (final Throwable t) { Debug.e(t); } }
@Override public void onLoadResources() { /* Load the font we are going to use. */ FontFactory.setAssetBasePath("font/"); this.mFontTexture = new BitmapTextureAtlas(512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA); this.mFont = FontFactory.createFromAsset(this.mFontTexture, this, "Plok.ttf", 32, true, Color.WHITE); this.mEngine.getTextureManager().loadTexture(this.mFontTexture); this.getFontManager().loadFont(this.mFont); /* Load all the textures this game needs. */ this.mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA); BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); this.mHeadTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "snake_head.png", 0, 0, 3, 1); this.mTailPartTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset( this.mBitmapTextureAtlas, this, "snake_tailpart.png", 96, 0); this.mFrogTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset( this.mBitmapTextureAtlas, this, "frog.png", 0, 64, 3, 1); this.mBackgroundTexture = new BitmapTextureAtlas(1024, 512, TextureOptions.DEFAULT); this.mBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset( this.mBackgroundTexture, this, "snake_background.png", 0, 0); this.mOnScreenControlTexture = new BitmapTextureAtlas(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA); this.mOnScreenControlBaseTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset( this.mOnScreenControlTexture, this, "onscreen_control_base.png", 0, 0); this.mOnScreenControlKnobTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset( this.mOnScreenControlTexture, this, "onscreen_control_knob.png", 128, 0); this.mEngine .getTextureManager() .loadTextures( this.mBackgroundTexture, this.mBitmapTextureAtlas, this.mOnScreenControlTexture); /* Load all the sounds this game needs. */ try { SoundFactory.setAssetBasePath("mfx/"); this.mGameOverSound = SoundFactory.createSoundFromAsset(this.getSoundManager(), this, "game_over.ogg"); this.mMunchSound = SoundFactory.createSoundFromAsset(this.getSoundManager(), this, "munch.ogg"); } catch (final IOException e) { Debug.e(e); } }
private void initServerAndClient() { this.initServer(); /* Wait some time after the server has been started, so it actually can start up. */ try { Thread.sleep(500); } catch (final Throwable t) { Debug.e(t); } this.initServerDiscovery(); }
private void acquireWakeLock(final WakeLockOptions pWakeLockOptions) { if (pWakeLockOptions == WakeLockOptions.SCREEN_ON) { ActivityUtils.keepScreenOn(this); } else { final PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); this.mWakeLock = pm.newWakeLock(pWakeLockOptions.getFlag() | PowerManager.ON_AFTER_RELEASE, "AndEngine"); try { this.mWakeLock.acquire(); } catch (final SecurityException e) { Debug.e( "You have to add\n\t<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>\nto your AndroidManifest.xml !", e); } } }
private void log(final String pMessage) { Debug.d(pMessage); }