Fixed IPC provide gameconfig hedgeroid
authorXeli
Tue, 09 Aug 2011 20:54:56 +0200
branchhedgeroid
changeset 5508 dcf1b3645af6
parent 5506 2b0c4fcde4c6
child 5510 4510cf730fbf
Fixed IPC provide gameconfig
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/EngineProtocolNetwork.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/GameConfig.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Map.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Scheme.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Weapon.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/EngineProtocolNetwork.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/EngineProtocolNetwork.java	Tue Aug 09 20:54:56 2011 +0200
@@ -7,8 +7,6 @@
 import java.net.Socket;
 import java.net.UnknownHostException;
 
-import android.util.Log;
-
 public class EngineProtocolNetwork implements Runnable{
 
 	public static final String GAMEMODE_LOCAL = "TL";
@@ -46,10 +44,6 @@
 		/*else if (mode == MODE_GAME)*/ gameIPC();
 	}
 	
-	private void genLandPreviewIPC(){
-		
-	}
-	
 	private void gameIPC(){
 		try{
 			Socket sock = serverSocket.accept();
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/GameConfig.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/GameConfig.java	Tue Aug 09 20:54:56 2011 +0200
@@ -1,7 +1,6 @@
 package org.hedgewars.mobile.EngineProtocol;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.UUID;
 
@@ -20,7 +19,7 @@
 	public String mission = null;
 	public String seed = null;
 	
-	public ArrayList<Team> teams = new ArrayList<Team>(8);
+	public ArrayList<Team> teams = new ArrayList<Team>();
 	
 	public GameConfig(){
 		
@@ -34,7 +33,7 @@
 	
 	public void sendToEngine(EngineProtocolNetwork epn) throws IOException{
 		Log.d("HW_Frontend", "Sending Gameconfig...");
-		int teamCount = 8;
+		int teamCount = 4;
 		epn.sendToEngine("TL"); //Write game mode
 		if(mission != null) epn.sendToEngine(mission);
 		
@@ -47,17 +46,15 @@
 		//mapgen_command
 		//mazesize_command
 		
-		//epn.sendToEngine(String.format("etheme %s", theme));
+		epn.sendToEngine(String.format("etheme %s", theme));
 		
-		//scheme.sendToEngine(epn);
+		scheme.sendToEngine(epn);
 		
-		//weapon.sendToEngine(os, teamCount);
+		weapon.sendToEngine(epn, teamCount);
 		
 		for(Team t : teams){
-			//t.sendToEngine(os, teamCount, 50, 0);
+			if(t != null)t.sendToEngine(epn, teamCount, 50);
 		}
-		
-		
 	}
 	
 	public int describeContents() {
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Map.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Map.java	Tue Aug 09 20:54:56 2011 +0200
@@ -2,7 +2,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.OutputStream;
 
 import android.content.Context;
 import android.graphics.drawable.Drawable;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Scheme.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Scheme.java	Tue Aug 09 20:54:56 2011 +0200
@@ -6,7 +6,6 @@
 import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashMap;
@@ -40,8 +39,8 @@
 		readFromParcel(in);
 	}
 
-	public void sendToEngine(OutputStream os)throws IOException{ 
-		os.write(String.format("e$gmflags %d", gamemod).getBytes());
+	public void sendToEngine(EngineProtocolNetwork epn)throws IOException{ 
+		epn.sendToEngine(String.format("e$gmflags %d", gamemod));
 
 		for(int pos = 0; pos < basic.size(); pos++){
 			LinkedHashMap<String, ?> basicflag = basicflags.get(pos);
@@ -55,9 +54,8 @@
 			if(checkOverMax && value >= max) value = max;
 			if(times1000) value *= 1000;
 			
-			os.write(String.format("%s %d", command, value).getBytes());
+			epn.sendToEngine(String.format("%s %d", command, value));
 		}
-		os.flush();
 	}
 	public String toString(){
 		return name;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Weapon.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/Weapon.java	Tue Aug 09 20:54:56 2011 +0200
@@ -5,7 +5,6 @@
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 
@@ -55,17 +54,15 @@
 		return name;
 	}
 	
-	public void sendToEngine(OutputStream os, int teamsCount) throws IOException{
-		os.write(QT.getBytes());//command prefix is already in string 
-		os.write(prob.getBytes());
-		os.write(delay.getBytes());
-		os.write(crate.getBytes());
+	public void sendToEngine(EngineProtocolNetwork epn, int teamsCount) throws IOException{
+		epn.sendToEngine(QT);//command prefix is already in string 
+		epn.sendToEngine(prob);
+		epn.sendToEngine(delay);
+		epn.sendToEngine(crate);
 		
-		byte[] ammstore = "eammstore".getBytes();
 		for(int i = 0; i < teamsCount; i++){
-			os.write(ammstore);
+			epn.sendToEngine("eammstore");
 		}
-		os.flush();
 	}
 	
 	public static final int STATE_START = 0;
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Tue Aug 09 20:53:37 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Tue Aug 09 20:54:56 2011 +0200
@@ -273,6 +273,7 @@
 		EngineProtocolNetwork ipc = new EngineProtocolNetwork(config);
 
 		String path = Utils.getDownloadPath(SDLActivity.mSingleton);
+		//path = path.substring(0, path.length()-1);//remove the trailing '/'
 
 		SDLActivity.nativeInit(new String[] { String.valueOf(ipc.port),
 				String.valueOf(surfaceWidth), String.valueOf(surfaceHeight),