Revisão | 8430dab6a9799bb0e8a52bcf0d760094d94b06ff (tree) |
---|---|
Hora | 2021-07-27 06:26:53 |
Autor | sebastian_bugiu |
Commiter | sebastian_bugiu |
Updating game resources live now works. Seems to cause a crash when updating level events. Must investigate further.
@@ -23,6 +23,7 @@ | ||
23 | 23 | import headwayent.blackholedarksun.exception.GameDataException; |
24 | 24 | import headwayent.blackholedarksun.gamestatedebugger.Frame; |
25 | 25 | import headwayent.blackholedarksun.input.KeyBindings; |
26 | +import headwayent.blackholedarksun.loaders.LevelLoader; | |
26 | 27 | import headwayent.blackholedarksun.loaders.MultiplayerMapCompiler; |
27 | 28 | import headwayent.blackholedarksun.menusystemsimpleview.SimpleViewGameMenuManager; |
28 | 29 | import headwayent.blackholedarksun.menusystemsimpleview.SimpleViewMenuManager; |
@@ -152,6 +153,18 @@ | ||
152 | 153 | } |
153 | 154 | } |
154 | 155 | |
156 | + protected void loadLevelAndMeshData() { | |
157 | + singlePlayerLevelList = LevelLoader.loadLevelList("level_list.txt", getGameResourcesDir()); | |
158 | + | |
159 | + multiPlayerLevelList = LevelLoader.loadLevelList("multiplayer_level_list.txt", getGameResourcesDir()); | |
160 | + | |
161 | + headwayent.blackholedarksun.entitydata.ShipData.MapWithFilenameAndName mappings = headwayent.blackholedarksun.entitydata.ShipData.createShipMappings(); | |
162 | +// filenameShipMap = mappings.filenameShipMap; | |
163 | + nameShipMap = mappings.nameShipMap; | |
164 | + WeaponData.createWeaponMappings(); | |
165 | + asteroidDataMap = AsteroidData.createAsteroidMappings(); | |
166 | + } | |
167 | + | |
155 | 168 | public enum GameMode { |
156 | 169 | SP, MP |
157 | 170 | } |
@@ -179,7 +192,8 @@ | ||
179 | 192 | public static final int GORILLA_DEJAVU_LARGE = 24; |
180 | 193 | public static final String GORILLA_FONT = "dejavu"; |
181 | 194 | public static final String GORRILA_NINE_PATCH_BUTTON = "nine_patch_test"; |
182 | - public static final String BASE_IP = "188.25.39.240";//"http://headwayentertainment.net"; | |
195 | + public static final String BASE_IP = //"188.25.39.240"; | |
196 | + "http://headwayentertainment.net"; | |
183 | 197 | public static final String APP_SERVER_IP = "http://188.26.10.46"; |
184 | 198 | public static final String URL_ADDRESS = BASE_IP + ":80"; |
185 | 199 | private static final String URL_GAMEDATA = MainApp.TEST_DATA ? |
@@ -578,7 +592,7 @@ | ||
578 | 592 | } |
579 | 593 | } |
580 | 594 | |
581 | - public boolean downloadData(String URL, String location, String filename) { | |
595 | + public boolean downloadData(String URL, String location, String filename, boolean overwrite) { | |
582 | 596 | boolean ok = true; |
583 | 597 | // set the path where we want to save the file |
584 | 598 | // in this case, going to save it on the root directory of the |
@@ -596,9 +610,11 @@ | ||
596 | 610 | f.delete(); |
597 | 611 | } |
598 | 612 | }*/ |
599 | - loc.emptyDirectory(); | |
613 | + if (!overwrite) { | |
614 | + loc.emptyDirectory(); | |
600 | 615 | // file.getParentFile().mkdirs(); |
601 | - loc.mkdirs(); | |
616 | + loc.mkdirs(); | |
617 | + } | |
602 | 618 | System.out.println("Downloading: " + file); |
603 | 619 | System.out.println("Downloading game data..."); |
604 | 620 | ok = ENG_NetUtility.downloadFromServer(URL, file, new ENG_NetUtility.ProgressUpdate() { |
@@ -629,14 +645,14 @@ | ||
629 | 645 | |
630 | 646 | boolean unzip = false; |
631 | 647 | if (ok) { |
632 | - unzip = new ENG_Decompress(file.getAbsolutePath(), loc.file() + "/").unzip(); | |
648 | + unzip = new ENG_Decompress(file.getAbsolutePath(), loc.file() + File.separator).unzip(); | |
633 | 649 | } |
634 | 650 | // file.delete(); |
635 | 651 | return unzip; |
636 | 652 | } |
637 | 653 | |
638 | 654 | private boolean downloadData() { |
639 | - return downloadData(URL_GAMEDATA, FOLDER_RAW, (DATA_IN_APK_COMPRESSED ? "hotshot_gamedata.zip" : "hotshot_gamedata")); | |
655 | + return downloadData(URL_GAMEDATA, FOLDER_RAW, (DATA_IN_APK_COMPRESSED ? "hotshot_gamedata.zip" : "hotshot_gamedata"), false); | |
640 | 656 | } |
641 | 657 | |
642 | 658 | public boolean unpackLocalData() { |
@@ -1620,9 +1636,14 @@ | ||
1620 | 1636 | if (newGameResourceVersion != -1) { |
1621 | 1637 | int currentGameResourcesVersion = preferences.getGameResourcesVersion(); |
1622 | 1638 | if (newGameResourceVersion > currentGameResourcesVersion) { |
1623 | - boolean downloadData = downloadData(URL_GAMEDATA_UPDATE, FOLDER_RAW, "hotshot_gamedata_update.zip"); | |
1639 | + // Make sure you overwrite the data in the hotshot_gamedata folder not in the | |
1640 | + // base raw path. | |
1641 | + boolean downloadData = downloadData(URL_GAMEDATA_UPDATE, getGameResourcesDir(), | |
1642 | + "hotshot_gamedata_update.zip", true); | |
1624 | 1643 | if (downloadData) { |
1625 | 1644 | preferences.setGameResourcesVersion(newGameResourceVersion); |
1645 | + loadLevelAndMeshData(); | |
1646 | + WorldManager.getSingleton().reloadLevelDataAndUpdateCurrentEntities(); | |
1626 | 1647 | } |
1627 | 1648 | } |
1628 | 1649 | } else { |
@@ -1723,7 +1744,7 @@ | ||
1723 | 1744 | |
1724 | 1745 | public GetGameDataLocation invoke() { |
1725 | 1746 | loc = Gdx.files.local(location); |
1726 | - file = ENG_FileUtils.getFile(location + File.separator + filename); | |
1747 | + file = ENG_FileUtils.getFile(filename); | |
1727 | 1748 | return this; |
1728 | 1749 | } |
1729 | 1750 | } |
@@ -182,15 +182,7 @@ | ||
182 | 182 | netManager = new NetManager(); |
183 | 183 | |
184 | 184 | // initLevelShipSelectionList(); |
185 | - singlePlayerLevelList = LevelLoader.loadLevelList("level_list.txt", getGameResourcesDir()); | |
186 | - | |
187 | - multiPlayerLevelList = LevelLoader.loadLevelList("multiplayer_level_list.txt", getGameResourcesDir()); | |
188 | - | |
189 | - headwayent.blackholedarksun.entitydata.ShipData.MapWithFilenameAndName mappings = headwayent.blackholedarksun.entitydata.ShipData.createShipMappings(); | |
190 | -// filenameShipMap = mappings.filenameShipMap; | |
191 | - nameShipMap = mappings.nameShipMap; | |
192 | - WeaponData.createWeaponMappings(); | |
193 | - asteroidDataMap = AsteroidData.createAsteroidMappings(); | |
185 | + loadLevelAndMeshData(); | |
194 | 186 | |
195 | 187 | // The movement system must be put before the collision detection system |
196 | 188 | MovementSystem movementSystem = new MovementSystem(MOVEMENT_SYSTEM_INTERVAL); |
@@ -1220,15 +1220,8 @@ | ||
1220 | 1220 | |
1221 | 1221 | netManager = new NetManager(); |
1222 | 1222 | |
1223 | - singlePlayerLevelList = LevelLoader.loadLevelList("level_list.txt", getGameResourcesDir()); | |
1224 | - | |
1225 | - multiPlayerLevelList = LevelLoader.loadLevelList("multiplayer_level_list.txt", getGameResourcesDir()); | |
1223 | + loadLevelAndMeshData(); | |
1226 | 1224 | |
1227 | - headwayent.blackholedarksun.entitydata.ShipData.MapWithFilenameAndName mappings = headwayent.blackholedarksun.entitydata.ShipData.createShipMappings(); | |
1228 | -// filenameShipMap = mappings.filenameShipMap; | |
1229 | - nameShipMap = mappings.nameShipMap; | |
1230 | - WeaponData.createWeaponMappings(); | |
1231 | - asteroidDataMap = AsteroidData.createAsteroidMappings(); | |
1232 | 1225 | ENG_RenderRoot root = ENG_RenderRoot.getRenderRoot(); |
1233 | 1226 | final ENG_SceneManager sceneManager = root.getSceneManager(SCENE_MANAGER); |
1234 | 1227 | initializeWorld(); |
@@ -190,7 +190,7 @@ | ||
190 | 190 | public ShipTeam team; |
191 | 191 | public ShipType shipType; |
192 | 192 | public final ArrayList<WeaponData.WeaponType> weaponTypeList = new ArrayList<>(); |
193 | - public float armor; | |
193 | + public float armor; // Not used yet. Only health in EntityData is used. | |
194 | 194 | public float afterburnerMaxSpeedCoeficient = |
195 | 195 | DEFAULT_AFTERBURNER_MAX_SPEED_COEFICIENT; |
196 | 196 | public long afterburnerTime = DEFAULT_AFTERBURNER_TIME; |
@@ -303,6 +303,7 @@ | ||
303 | 303 | // throw new ENG_MultipleSingletonConstructAttemptException("weapon mappings already created"); |
304 | 304 | // } |
305 | 305 | weaponMappingsCreated = true; |
306 | + weaponMap.clear(); | |
306 | 307 | ArrayList<WeaponData> weaponDataList = new WeaponDataCompiler().compile("weapon_data_list.txt", MainApp.getGame().getGameResourcesDir(), WorldManagerBase.LOAD_FROM_SDCARD); |
307 | 308 | for (WeaponData weapon : weaponDataList) { |
308 | 309 | weaponMap.put(weapon.weaponType, weapon); |
@@ -30,6 +30,9 @@ | ||
30 | 30 | public ArrayList<ShipData> compileImpl(String fileName, String path, boolean fromSDCard) { |
31 | 31 | DataInputStream fp0 = null; |
32 | 32 | try { |
33 | + String fileAsString = ENG_Resource.getFileAsString(fileName, path, fromSDCard); | |
34 | + System.out.println("ship_data_list.txt"); | |
35 | + System.out.println(fileAsString); | |
33 | 36 | fp0 = ENG_Resource.getFileAsStream(fileName, path, fromSDCard); |
34 | 37 | String s; |
35 | 38 | ArrayList<ShipData> shipDataList = new ArrayList<>(); |
@@ -18,11 +18,11 @@ | ||
18 | 18 | private static final GameResourceUpdateChecker singleton = new GameResourceUpdateChecker(); |
19 | 19 | private static final String NET_CHECK_URL = "http://www.headwayentertainment.net/gamedata/gamedata_version"; |
20 | 20 | private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); |
21 | - private final AtomicBoolean gameResouceUpdateAvailable = new AtomicBoolean(true); | |
21 | + private boolean gameResouceUpdateAvailable; | |
22 | 22 | private final GameDataUpdateChecker gamedataUpdateChecker = new GameDataUpdateChecker(); |
23 | 23 | private ScheduledFuture<?> schedule; |
24 | 24 | private final ReentrantLock lock = new ReentrantLock(); |
25 | - private AtomicInteger gamedataVersion = new AtomicInteger(-1); | |
25 | + private int gamedataVersion = -1; | |
26 | 26 | private boolean monitoringActive; |
27 | 27 | |
28 | 28 | private class GameDataUpdateChecker implements Runnable { |
@@ -38,17 +38,27 @@ | ||
38 | 38 | HttpStatus status = httpResponse.getStatus(); |
39 | 39 | String versionStr = httpResponse.getResultAsString(); |
40 | 40 | int version = Integer.parseInt(versionStr); |
41 | - if (version > gamedataVersion.get()) { | |
42 | - gameResouceUpdateAvailable.set(true); | |
43 | - gamedataVersion.set(version); | |
44 | - } else { | |
45 | - gameResouceUpdateAvailable.set(false); | |
41 | + lock.lock(); | |
42 | + try { | |
43 | + if (version > gamedataVersion) { | |
44 | + gameResouceUpdateAvailable = true; | |
45 | + gamedataVersion = version; | |
46 | + } else { | |
47 | + gameResouceUpdateAvailable = false; | |
48 | + } | |
49 | + } finally { | |
50 | + lock.unlock(); | |
46 | 51 | } |
47 | 52 | } |
48 | 53 | |
49 | 54 | @Override |
50 | 55 | public void failed(Throwable t) { |
51 | - gameResouceUpdateAvailable.set(false); | |
56 | + lock.lock(); | |
57 | + try { | |
58 | + gameResouceUpdateAvailable = false; | |
59 | + } finally { | |
60 | + lock.unlock(); | |
61 | + } | |
52 | 62 | } |
53 | 63 | |
54 | 64 | @Override |
@@ -88,11 +98,21 @@ | ||
88 | 98 | } |
89 | 99 | |
90 | 100 | public boolean isGameResourceUpdateAvailable() { |
91 | - return gameResouceUpdateAvailable.get(); | |
101 | + lock.lock(); | |
102 | + try { | |
103 | + return gameResouceUpdateAvailable; | |
104 | + } finally { | |
105 | + lock.unlock(); | |
106 | + } | |
92 | 107 | } |
93 | 108 | |
94 | 109 | public int getGameResourceVersion() { |
95 | - return gamedataVersion.get(); | |
110 | + lock.lock(); | |
111 | + try { | |
112 | + return gamedataVersion; | |
113 | + } finally { | |
114 | + lock.unlock(); | |
115 | + } | |
96 | 116 | } |
97 | 117 | |
98 | 118 | public boolean isGameResourceMonitoringActive() { |
@@ -908,6 +908,8 @@ | ||
908 | 908 | System.out.println("player ship destroyed"); |
909 | 909 | } |
910 | 910 | |
911 | + public abstract void reloadLevelDataAndUpdateCurrentEntities(); | |
912 | + | |
911 | 913 | public abstract void onPlayerShipDestroyedAnimationFinished(); |
912 | 914 | |
913 | 915 | public abstract void onPlayerShipDestroyed(Entity entity, EntityProperties entityProperties, ShipProperties shipProperties, CameraProperties cameraProperties); |
@@ -1152,6 +1152,11 @@ | ||
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | @Override |
1155 | + public void reloadLevelDataAndUpdateCurrentEntities() { | |
1156 | + | |
1157 | + } | |
1158 | + | |
1159 | + @Override | |
1155 | 1160 | public void destroyEntities() { |
1156 | 1161 | gameWorld.getSystem(EntityDestructionSystem.class).process(); |
1157 | 1162 | } |
@@ -16,6 +16,7 @@ | ||
16 | 16 | import headwayent.blackholedarksun.levelresource.LevelBase; |
17 | 17 | import headwayent.blackholedarksun.levelresource.LevelEvent; |
18 | 18 | import headwayent.blackholedarksun.levelresource.LevelObject; |
19 | +import headwayent.blackholedarksun.loaders.LevelLoader; | |
19 | 20 | import headwayent.blackholedarksun.menusystemsimpleview.SimpleViewGameMenuManager; |
20 | 21 | import headwayent.blackholedarksun.parser.ast.Cutscene; |
21 | 22 | import headwayent.blackholedarksun.physics.PhysicsProperties; |
@@ -483,6 +484,56 @@ | ||
483 | 484 | } |
484 | 485 | |
485 | 486 | @Override |
487 | + public void reloadLevelDataAndUpdateCurrentEntities() { | |
488 | + if (getLevelState() != LevelState.STARTED) { | |
489 | + return; | |
490 | + } | |
491 | + int levelNum = getCurrentLevel(); | |
492 | + APP_Game game = MainApp.getGame(); | |
493 | + Level level = (Level) LevelLoader.compileLevel( | |
494 | + levelNum, game.getSinglePlayerLevelList(), false); | |
495 | + gameWorld.setCurrentLevel(level); | |
496 | + for (Entity entity : movableObjectsToEntities.values()) { | |
497 | + EntityProperties entityProperties = entityPropertiesComponentMapper.get(entity); | |
498 | + | |
499 | + LevelObject currentLevelObject = null; | |
500 | + for (LevelObject levelObject : level.levelStart.startObjects) { | |
501 | + if (entityProperties.getName().equals(levelObject.name)) { | |
502 | + currentLevelObject = levelObject; | |
503 | + break; | |
504 | + } | |
505 | + } | |
506 | + if (currentLevelObject == null) { | |
507 | + for (LevelEvent levelEvent : level.levelEventList) { | |
508 | + for (LevelObject levelObject : levelEvent.spawn) { | |
509 | + if (entityProperties.getName().equals(levelObject.name)) { | |
510 | + currentLevelObject = levelObject; | |
511 | + break; | |
512 | + } | |
513 | + } | |
514 | + } | |
515 | + } | |
516 | + | |
517 | + ShipProperties shipProperties = shipPropertiesComponentMapper.getSafe(entity); | |
518 | + if (shipProperties != null) { | |
519 | + | |
520 | + } | |
521 | + CameraProperties cameraProperties = cameraPropertiesComponentMapper.getSafe(entity); | |
522 | + if (cameraProperties != null) { | |
523 | + // We have the player ship. | |
524 | + // Player ship properties is set separately from other ship data. | |
525 | + playerShipData = MainApp.getGame().getNameToShipMap(playerShipData.inGameName); | |
526 | + entityProperties.setHealth(playerShipData.health); | |
527 | + } | |
528 | + WeaponProperties weaponProperties = weaponPropertiesComponentMapper.getSafe(entity); | |
529 | + if (weaponProperties != null) { | |
530 | + | |
531 | + } | |
532 | + } | |
533 | + | |
534 | + } | |
535 | + | |
536 | + @Override | |
486 | 537 | public void createReloaderEntity() { |
487 | 538 | if (getShip(currentReloaderShipId) == null |
488 | 539 | && getEntity(playerShipEntityId) != null |
@@ -15,7 +15,9 @@ | ||
15 | 15 | import java.util.ArrayList; |
16 | 16 | import java.util.zip.GZIPInputStream; |
17 | 17 | |
18 | +import org.apache.commons.io.FileUtils; | |
18 | 19 | import org.apache.commons.io.FilenameUtils; |
20 | +import org.apache.commons.io.IOUtils; | |
19 | 21 | |
20 | 22 | import com.badlogic.gdx.Gdx; |
21 | 23 |
@@ -123,6 +125,19 @@ | ||
123 | 125 | } |
124 | 126 | } |
125 | 127 | |
128 | + public static String getFileAsString(String filename, String path) { | |
129 | + return getFileAsString(filename, path, true); | |
130 | + } | |
131 | + | |
132 | + public static String getFileAsString(String filename, String path, boolean SDCard) { | |
133 | + try { | |
134 | + return FileUtils.readFileToString(getFile(filename, path, SDCard)); | |
135 | + } catch (IOException e) { | |
136 | + e.printStackTrace(); | |
137 | + } | |
138 | + return null; | |
139 | + } | |
140 | + | |
126 | 141 | public static File getFile(String filename, String path) { |
127 | 142 | return getFile(filename, path, true); |
128 | 143 | } |
@@ -26,14 +26,18 @@ | ||
26 | 26 | ZipInputStream zin = new ZipInputStream(fin); |
27 | 27 | ZipEntry ze; |
28 | 28 | byte[] buffer = new byte[1024 * 1024 * 2]; |
29 | + Gdx.app.log("Decompress", "Decompressing from " + _zipFile); | |
29 | 30 | while ((ze = zin.getNextEntry()) != null) { |
30 | - Gdx.app.log("Decompress", "Unzipping " + ze.getName()); | |
31 | + Gdx.app.log("Decompress", "Unzipping " + _location + ze.getName()); | |
31 | 32 | //Log.v("Decompress", "Unzipping " + ze.getName()); |
32 | 33 | |
33 | 34 | if (ze.isDirectory()) { |
34 | 35 | _dirChecker(ze.getName()); |
35 | 36 | } else { |
36 | - boolean newFile = new File(_location + ze.getName()).createNewFile(); | |
37 | + File file = new File(_location + ze.getName()); | |
38 | + boolean delete = file.delete(); | |
39 | + boolean newFile = file.createNewFile(); | |
40 | + System.out.println("file deleted: " + delete + " newFile: " + newFile); | |
37 | 41 | FileOutputStream fout = new FileOutputStream(_location + ze.getName()); |
38 | 42 | int size; |
39 | 43 |
@@ -3,10 +3,10 @@ | ||
3 | 3 | zorder 210 |
4 | 4 | container Panel game_resource_checker_indicator |
5 | 5 | { |
6 | - left 0.1 | |
7 | - top 0.0 | |
8 | - width 0.1 | |
9 | - height 0.1 | |
6 | + left 0.05 | |
7 | + top 0.55 | |
8 | + width 0.95 | |
9 | + height 0.2 | |
10 | 10 | element TextArea game_resource_checker_text |
11 | 11 | { |
12 | 12 | left 0.0 |
@@ -142,7 +142,7 @@ | ||
142 | 142 | team HUMAN |
143 | 143 | ship_type FIGHTER |
144 | 144 | max_speed 400.0f |
145 | - armor 1.0f | |
145 | + armor 100.0f | |
146 | 146 | turn_angle 110.0f |
147 | 147 | max_angular_velocity 1200.0f |
148 | 148 | weight 20.0f |