Make simulation calculations run at a minimum rate of 60 FPS. Include extra data for maps

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 8be868e463
commit b0be363293
  1. BIN
      maps/world1.map
  2. 2
      src/sig/RabiClone.java
  3. 5
      src/sig/map/Background.java
  4. 68
      src/sig/map/Map.java
  5. 13
      src/sig/map/View.java

Binary file not shown.

@ -60,7 +60,7 @@ public class RabiClone{
while (true) { while (true) {
long timePassed = System.nanoTime()-lastGameTime; long timePassed = System.nanoTime()-lastGameTime;
lastGameTime=System.nanoTime(); lastGameTime=System.nanoTime();
double updateMult = timePassed/1000000000d; double updateMult = Math.min(1/60d,timePassed/1000000000d);
for (int i=0;i<OBJ.size();i++) { for (int i=0;i<OBJ.size();i++) {
OBJ.get(i).update(updateMult); OBJ.get(i).update(updateMult);

@ -0,0 +1,5 @@
package sig.map;
public enum Background {
DEFAULT
}

@ -8,21 +8,62 @@ import java.io.IOException;
public class Map { public class Map {
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map. //Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
//294912 bytes = 294KB of memory storage per map.
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world. //Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
//
//After the map data, the next 1024 bytes will indicate the map view information.
//After that, the next 1024 bytes will indicate the background information.
//After that, the next 1024 bytes will indicate the map color information.
//After that, the next 1024 bytes will indicate the map room type. (Might show checkpoints, warp points, POI, etc)
//
//299008 bytes = 299KB of memory storage per map.
//
final public static int MAP_WIDTH=512; final public static int MAP_WIDTH=512;
final public static int MAP_HEIGHT=288; final public static int MAP_HEIGHT=288;
char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT]; char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT];
byte[] views = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] backgrounds = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] colors = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
byte[] types = new byte[(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT)];
final static byte MAP_DATA = 0;
final static byte VIEW_DATA = 1;
final static byte BACKGROUND_DATA = 2;
final static byte COLOR_DATA = 3;
final static byte TYPE_DATA = 4;
public static Map LoadMap(Maps map) { public static Map LoadMap(Maps map) {
try { try {
Map newMap = new Map(); Map newMap = new Map();
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile())); DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile()));
int marker=0; int marker=0;
int iterationCount=MAP_WIDTH*MAP_HEIGHT;
int readingData = MAP_DATA;
while (stream.available()!=0) { while (stream.available()!=0) {
newMap.tiles[marker++]=stream.readChar(); switch (readingData) {
case MAP_DATA:
newMap.tiles[marker++]=stream.readChar();
break;
case VIEW_DATA:
newMap.views[marker++]=stream.readByte();
break;
case BACKGROUND_DATA:
newMap.backgrounds[marker++]=stream.readByte();
break;
case COLOR_DATA:
newMap.colors[marker++]=stream.readByte();
break;
case TYPE_DATA:
newMap.types[marker++]=stream.readByte();
break;
}
iterationCount--;
if (iterationCount<=0) {
readingData++;
marker=0;
iterationCount=(MAP_WIDTH/Tile.TILE_WIDTH)*(MAP_HEIGHT/Tile.TILE_HEIGHT);
}
} }
stream.close(); stream.close();
return newMap; return newMap;
@ -34,17 +75,32 @@ public class Map {
public static void SaveMap(Maps map) { public static void SaveMap(Maps map) {
try { try {
int marker=0;
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile())); DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile()));
while (marker<map.map.tiles.length) { saveCharData(stream,map.map.tiles);
stream.writeChar(map.map.tiles[marker++]); saveByteData(stream,map.map.views);
} saveByteData(stream,map.map.backgrounds);
saveByteData(stream,map.map.colors);
saveByteData(stream,map.map.types);
stream.close(); stream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void saveCharData(DataOutputStream stream, char[] a) throws IOException {
int marker = 0;
while (marker<a.length) {
stream.writeChar(a[marker++]);
}
}
private static void saveByteData(DataOutputStream stream, byte[] a) throws IOException {
int marker = 0;
while (marker<a.length) {
stream.writeByte(a[marker++]);
}
}
public void ModifyTile(int x,int y,Tile t) { public void ModifyTile(int x,int y,Tile t) {
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal()); tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+"."); //System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");

@ -0,0 +1,13 @@
package sig.map;
public enum View {
DIRECT_FOLLOW, //Follows the player directly.
LIGHT_FOLLOW,
// Follows the player loosely, but makes sure there's
// still a border between the edge of the screen and the player.
FIXED, //Does not follow the player.
LIGHT_HORIZONTAL_FOLLOW,
// Used for rooms that are wide, but only 1 screen tall.
LIGHT_VERTICAL_FOLLOW,
// Used for rooms that are tall, but only 1 screen wide.
}
Loading…
Cancel
Save