0x416c616e / 2d_game_redo

2D game written in Java/OpenJFX
1 stars 0 forks source link

New ideas to address performance issues #4

Open 0x416c616e opened 3 years ago

0x416c616e commented 3 years ago
  1. Don't load map from XML. This is too slow. Instead, hard-code each level. This is worse in every way except for performance, which is important. Of course, there's no guarantee that hard-coded levels will be faster. But I'm pretty sure they will be. Current loadMap() takes about 20 seconds, and keep in mind that this is with the minimalist implementation and only for 720p too, which is not good.
  2. Delete all current classes except for Main and Player. Tiles should be redone for the new hard-coded method.
  3. Don't use loadMap(). Make new levels for loadMap0_0, loadMap0_1, and so on. And the values for the image, event, collision, etc. should be hard-coded, not from XML. For performance reasons.
0x416c616e commented 3 years ago

Also, the movement will be where the player moves, but the screen doesn't. Map loading is the weakest link in this game, so the idea of keeping the player in the center of the screen and re-loading XML/tiles/etc for every movement lambda is not possible.

0x416c616e commented 3 years ago

Still use XML for the player's save file, but not for map data.

0x416c616e commented 3 years ago

Current objectives:

  1. Get rid of all bad map-loading code
  2. Get rid of map1 XML
  3. Get rid of map template XML
  4. Get rid of all classes aside from Main and Player
  5. Make new Tile class, where is has bottomLevel, midLevel, topLevel, and event attributes
  6. make an Event class
  7. Make new WorldMap class
  8. Make method for putting tiles on the map, like loadMap() except maybe put it into the WorldMap class instead of Main. Takes args for resolution, touchscreenOrNot, mainMenu Pane, etc. In loadMap, if touchscreen controls are enabled, after rendering the map, it needs to put touchscreen controls on top.
  9. Make a method in Main for loading a level, i.e. map_0_0 or something. it should put the WorldMap object in a pane that gets added to the mainMenu pane, and then when the player loads a new map, it does remove() on the old one, and sets it to null and calls System.gc().
  10. Make Player show up on screen
  11. Make lambdas for keyboard movement
  12. Make events for moving to another screen

Event class: attributes: String eventType; //can be movement, dialogue, fight, randomEncounter, treasure, or shop int eventX; int eventY; int items[10]; String dialogue[10]; String monsterName; int encounterChance; //1-100 int goldAmount;

Later I will need to make classes for Monster, Fight, Treasure, Dialogue, Inventory, InGameMenu, etc. Things get put into a new Pane which gets put into the mainMenu Pane, and when the event is over, the pane is removed and set to null and then System.gc() gets called.


Handling different resolutions: Maybe for 720p and 800p, have the same useful tiles, but for 800p, it just has two extra rows of useless tiles at the bottom. For 1080P, maybe make the tiles bigger to have the same number of tiles, even if it doesn't perfectly fit into 1920 and 1080 (i.e. if it multiplies to 1060 or something).

0x416c616e commented 3 years ago

Finished items 1-7 on the above comment, currently working on #8.