// **************************************************** // Setup the screen and screen variables for each frame // **************************************************** void RenderStart() { currentBuffer = GsGetActiveBuff(); // Determine which buffer is to be used GsClearOt(0, 0, &OTable_Header[currentBuffer]); // Clear out OTable sorting info GsSetWorkBase((PACKET*)Packet_Memory[currentBuffer]); // Set scratchpad area for the OT } // ******************* // Draw all the screen // ******************* void RenderWorld() { DrawBackground(); // DrawMiddleground(); DrawForeground(); DrawObjects(); DrawPlayer(); DrawSync(0); // Wait for completion of all output ScreenDrawTiming = VSync(0); // Wait for blank and time it ScreenMin = MIN(ScreenMin, ScreenDrawTiming); ScreenMax = MAX(ScreenMax, ScreenDrawTiming); FntPrint(FntOne, "Frame: %d, Min: %d, Max: %d", ScreenDrawTiming, ScreenMin, ScreenMax); GsSwapDispBuff(); // Swap buffer information GsSortClear(66, 82, 49, &OTable_Header[currentBuffer]); // Send a request to clear the screen // To the ordering table GsDrawOt(&OTable_Header[currentBuffer]); // Draw commands in queue FntFlush(FntOne); // Output any text onto the screen } // ***************************** // Control drawing of background // ***************************** void DrawBackground() { DrawMountains(); DrawClouds(); DrawTreeTops(); } // ************** // Draw mountains // ************** void DrawMountains() { long t1, t2, t3; for (t1 = 0; t1 < 4; t1++) { for (t2 = 0; t2 < 21; t2++) { t3 = Mountains[(t2 + (XScreen >> 6)) % 20][t1]; MountainsSprite[t3].x = t2 * 16 - (XScreen >> 2) % 16; MountainsSprite[t3].y = t1 * 16 + 96 - (YScreen >> 2); MountainsSprite[t3].r = MountainsSprite[t3].g = 128; GsSortFastSprite(&MountainsSprite[t3], &OTable_Header[currentBuffer], 9); MountainsSprite[t3].y =182 - t1 * 16 - (YScreen >> 2); MountainsSprite[t3].scaley = -ONE * ((abs(((Counter + t1 * 32) % 64) - 32)) / 2 + 8) / 15; MountainsSprite[t3].r = MountainsSprite[t3].g = 110; GsSortSprite(&MountainsSprite[t3], &OTable_Header[currentBuffer], 10); } } } // *********** // Draw clouds // *********** void DrawClouds() { long t1, t2, t3, t4, t5; t5 = (XScreen + Counter * 2) >> 4; for (t1 = 0; t1 < 12; t1++) { t4 = t1 * 16 - (YScreen >> 2) - 96; // Work out Y coordinate if (t4 > -16) // Only calculate and put in ordering table { // if they are visible for (t2 = 0; t2 < 21; t2++) { t3 = Clouds[(t2 + (t5 >> 4)) % 16][t1]; CloudSprite[t3].x = t2 * 16 - (t5 % 16); CloudSprite[t3].y = t4; GsSortFastSprite(&CloudSprite[t3], &OTable_Header[currentBuffer], 8); } } } } // ************* // Draw treetops // ************* void DrawTreeTops() { long t1, t2, t3, t4; GsBOXF tRect1; tRect1.attribute = 0; tRect1.x = 0; tRect1.y = 186 - (YScreen >> 2); tRect1.w = 320; tRect1.h = 16; tRect1.r = 66; tRect1.g = 82; tRect1.b = 49; GsSortBoxFill(&tRect1, &OTable_Header[currentBuffer], 7); for (t1 = 0; t1 < 2; t1++) { t2 = t1 * 16 - (YScreen >> 2) + 154; if (t2 <= 224) { for (t3 = 0; t3 < 21; t3++) { t4 = ((XScreen >> 5) + t3) % 2 + t1 * 2; TreeTopSprite[t4].x = t3 * 16 - (XScreen >> 1) % 16; TreeTopSprite[t4].y = t2; GsSortFastSprite(&TreeTopSprite[t4], &OTable_Header[currentBuffer], 7); } } } } // ***************** // Draw middleground // ***************** void DrawMiddleground() { MiddlegroundBG.scrollx = (XScreen * 3) / 4; MiddlegroundBG.scrolly = (YScreen * 3) / 4; GsSortFixBg16(&MiddlegroundBG, &MiddlegroundBGWork[0], &OTable_Header[currentBuffer], 6); } // *************** // Draw foreground // *************** void DrawForeground() { long t1, t2, t3; for (t1 = 0; t1 < 17; t1++) { for (t2 = 0; t2 < 21; t2++) { t3 = Foreground[t2 + (XScreen >> 4)][t1 + (YScreen >> 4)]; if (t3 != 0) { ForegroundSprite[t3].x = t2 * 16 - XScreen % 16; ForegroundSprite[t3].y = t1 * 16 - YScreen % 16; ForegroundSprite[t3].r = 127; ForegroundSprite[t3].g = 127; ForegroundSprite[t3].b = 127; GsSortFastSprite(&ForegroundSprite[t3], &OTable_Header[currentBuffer], 4); } } } } // *********** // Draw player // *********** void DrawPlayer() { long t1; if (PSpeed == 0) { t1 = 10; } else { t1 = (Counter / 2) % 30; if (PSpeed > 0) { PRun[t1].scalex = ONE; } else { PRun[t1].scalex = -1 * ONE; } } PRun[t1].x = (PXPos >> 2) - XScreen + 16; PRun[t1].y = (PYPos >> 2) - YScreen + 33; GsSortSprite(&PRun[t1], &OTable_Header[currentBuffer], 5); } // ************ // Draw objects // ************ void DrawObjects() { long t1, t2, t3; for (t1 = 0; t1<200; t1++) { if (Objects[t1].type > 0) { t2 = (Objects[t1].x >> 2) - XScreen; t3 = (Objects[t1].y >> 2) - YScreen; if (t2 < 400) { if (t2 > -100) { if (t3 < 350) { if (t3 > -100) { switch(Objects[t1].type) { case 1: ForegroundSprite[1].x = t2; ForegroundSprite[1].y = t3; ForegroundSprite[1].r = Objects[t1].d; ForegroundSprite[1].g = 127; ForegroundSprite[1].b = 255; break; case 2: ForegroundSprite[1].x = t2; ForegroundSprite[1].y = t3; ForegroundSprite[1].r = Objects[t1].d; ForegroundSprite[1].g = 255; ForegroundSprite[1].b = 0; break; } GsSortFastSprite(&ForegroundSprite[1], &OTable_Header[currentBuffer], 5); } } } } } } }