X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_sp%2FGlobals.c;h=ebf59fd6b444a1f76631840bfcc7d15319506a9c;hb=9f688962eb90591205c511c1ae9bf752d276d1f5;hp=36034f5b63ba5159e42c90531836a1063eb5ec90;hpb=0f5b7f63f2d3d75ba646795a3c1ea9fc4cee4845;p=rocksndiamonds.git diff --git a/src/game_sp/Globals.c b/src/game_sp/Globals.c index 36034f5b..ebf59fd6 100644 --- a/src/game_sp/Globals.c +++ b/src/game_sp/Globals.c @@ -66,7 +66,12 @@ byte *DisPlayField; // Public DisplayMin%, DisplayMax%, DisplayWidth%, DisplayHeight% -int TimerVar, RandomSeed; +int TimerVar; +#if 1 +short RandomSeed; +#else +int RandomSeed; +#endif currency DeltaT; // Interval between two frames (in ms) long DeltaTPlay, DeltaTDemo; boolean BlockingSpeed; @@ -324,33 +329,69 @@ int GetStretchY(int si) return GetStretchY; } -void ReadLevel() +void OLD_ReadLevel() { +#if 1 + static char CurPathTEST[1024]; +#endif + // int FNum; FILE *FNum; long i; // byte T; +#if 1 + // CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat"; + +#if 0 + CurPath = "/home/aeglos/projects/rocksndiamonds/supaplex_demo_JENS0001.sp"; + LevelNumber = 1; +#else + +#if 0 + // sprintf(CurPathTEST, "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/test_solutions/%03d.sp", level_nr); + + sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/Set77/77S%03d.SP", level_nr); +#else + sprintf(CurPathTEST, "/home/aeglos/projects/Level_Stuff/SUPAPLEX/SUPAPLEX_LEVELS/solve00/JENS%04d.SP", level_nr); +#endif + + CurPath = CurPathTEST; + LevelNumber = level_nr; +#endif + +#endif + DemoAvailable = False; - if (STRING_IS_LIKE(CurPath, "*.mpx")) + if (STRING_IS_LIKE(CurPath, "*.mpx") || + STRING_IS_LIKE(CurPath, "*.MPX")) { + printf("::: reading MPX file ...\n"); + ReadMPX(); return; } - if (STRING_IS_LIKE(CurPath, "*.sp")) + if (STRING_IS_LIKE(CurPath, "*.sp") || + STRING_IS_LIKE(CurPath, "*.SP")) { + printf("::: reading SP file ...\n"); + ReadDemo(); return; } if (DemoFlag != 0) { + printf("::: reading demo file ...\n"); + ReadDemo(); return; } + printf("::: reading level file ...\n"); + FileMax = 0; FieldWidth = 60; FieldHeight = 24; @@ -366,11 +407,6 @@ void ReadLevel() // --- On Error GoTo ReadLevelEH -#if 1 - CurPath = "/home/aeglos/projects/rocksndiamonds/levels/TEST_supaplex/supaplex/levels.dat"; - LevelNumber = 1; -#endif - printf("::: '%s', %d\n", CurPath, LevelNumber); FNum = fopen(CurPath, "rb"); @@ -381,6 +417,7 @@ void ReadLevel() #else FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8)); #endif + i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize; FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure @@ -426,8 +463,8 @@ void ReadLevel() } #endif - AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 *FieldWidth); - AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 *FieldWidth); + AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth); + AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 * FieldWidth); TerminalState = REDIM_1D(sizeof(byte), FieldWidth, LevelMax - FieldWidth); GravityFlag = LInfo.InitialGravity; @@ -452,34 +489,51 @@ static void ReadDemo() int i; // byte T; + int RecordNumber = LevelNumber; + +#if 1 + RecordNumber = 1; // always "1" for "*.sp" style one level/demo files +#endif + FieldWidth = 60; FieldHeight = 24; HeaderSize = 96; + FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1; LevelMax = (FieldWidth * FieldHeight) - 1; // --- On Error GoTo ReadDemoEH + FileMax = FileLen(CurPath) - 1; + PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax + 1 - 1); DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1); + // FNum = FreeFile(); + FNum = fopen(CurPath, "rb"); - i = (LevelNumber - 1) * ((long)(FieldMax) + 1) + 1; + + i = (RecordNumber - 1) * ((long)(FieldMax) + 1) + 1; #if 1 FILE_GET(FNum, i, PlayField8, FileMax + 1); #else FILE_GET(FNum, i, &PlayField8, sizeof(PlayField8)); #endif - i = (LevelNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize; + + i = (RecordNumber) * ((long)(FieldMax) + 1) + 1 - HeaderSize; FILE_GET(FNum, i, &LInfo, sizeof(LInfo)); // store level info in an extra structure + fclose(FNum); + // --- On Error GoTo 0 if (FieldMax < FileMax) DemoAvailable = True; ReadSignature(); + PlayField16 = REDIM_1D(sizeof(int), -FieldWidth, FieldMax); + for (i = 0; i <= FieldMax; i++) { PlayField16[i] = PlayField8[i]; @@ -487,18 +541,77 @@ static void ReadDemo() PlayField8[i] = 0; } - AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 *FieldWidth); - AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 *FieldWidth); + AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth); + AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 * FieldWidth); TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax + 1 - 1); + DemoPointer = FieldMax + 1; DemoOffset = DemoPointer; DemoKeyRepeatCounter = 0; + // DemoFlag = 1 // DemoAvailable = True + GravityFlag = LInfo.InitialGravity; FreezeZonks = LInfo.InitialFreezeZonks; + +#if 0 + printf("::: Globals.c: ReadDemo(): %d / %d\n", GravityFlag, FreezeZonks); +#endif + + + +#if 0 + /* !!! TESTING BIG / LITTLE ENDIAN STUFF !!! */ + LInfo.DemoRandomSeed = + LowByte(LInfo.DemoRandomSeed) << 8 | + HighByte(LInfo.DemoRandomSeed); + for (i = 0; i < 10; i++) + LInfo.SpecialPort[i].PortLocation = + LowByte(LInfo.SpecialPort[i].PortLocation) << 8 | + HighByte(LInfo.SpecialPort[i].PortLocation); + + printf("::: swapping file bytes for DemoRandomSeed etc.\n"); +#else + printf("::: keeping file bytes in (maybe wrong) 'native' order.\n"); +#endif + +#if 1 + printf("::: LInfo.DemoRandomSeed == %d\n", LInfo.DemoRandomSeed); +#endif + +#if 0 + printf("::: LInfo.SpecialPortCount == %d\n", LInfo.SpecialPortCount); + for (i = 0; i < LInfo.SpecialPortCount; i++) + { + int port_x = (LInfo.SpecialPort[i].PortLocation / 2) % FieldWidth; + int port_y = (LInfo.SpecialPort[i].PortLocation / 2) / FieldWidth; + + printf("::: %d: port_location == %d => (%d, %d)\n", + i, LInfo.SpecialPort[i].PortLocation, port_x, port_y); + } +#endif + RandomSeed = LInfo.DemoRandomSeed; + +#if 0 + printf("::: SpeedByte == %d\n", LInfo.SpeedByte); + printf("::: CheckSumByte == %d\n", LInfo.CheckSumByte); + printf("::: RandomSeed == %d\n", RandomSeed); + +#if 0 + { + int i; + + for (i = 0; i < 10; i++) + printf("::: TEST random number: %d\n", subGetRandomNumber()); + } +#endif + +#endif + LevelLoaded = True; + return; #if 0 @@ -506,3 +619,28 @@ ReadDemoEH: Close(); #endif } + +void ReadLevel() +{ +#if 0 + OLD_ReadLevel(); + + // return; +#endif + + copyInternalEngineVars_SP(); + +#if 1 + SetDisplayRegion(); + SetScrollEdges(); +#endif + + LevelNumber = level_nr; + +#if 0 + if (!DemoFlag || !DemoAvailable) + subRandomize(); +#endif + + LevelLoaded = True; +}