Need help on how to use GsSortBg

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Need help on how to use GsSortBg

Post by LameGuy64 » September 22nd, 2013, 4:02 pm

This is a prototype of a 2D game engine that I'm currently working on for a 2D platformer game project. The problem is, I can't seem to get GsSortBg to work properly. I was able to get it to draw a single tile but it only takes tile 3 in the tile sheet and I don't know how to setup a proper GsMAP tile array without crashing the system.

Code: Select all

#include <sys/types.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <stdio.h>


#define OT_LENGTH 10
#define PACKETMAX 2048
#define PACKETMAX2 PACKETMAX*24


typedef struct {
	float x;
	float xMove;
	float y;
	float yMove;
} CameraStruct;


GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];

int ActiveBuffer=0;
CameraStruct Camera;

#include "tiles.h"



// Prototypes
void init(void);
int main(void);

GsIMAGE LoadTIM(u_long *tMemAddress);


void init(void)
{

	// Init 320x240 mode
	GsInitGraph(320, 240, GsNONINTER|GsOFSGPU, 1, 0);

	// Prepare display buffers
	GsDefDispBuff(0, 0, 0, 240);

	// Prepare ordering tables
	myOT[0].length = OT_LENGTH;
	myOT[1].length = OT_LENGTH;
	myOT[0].org = myOT_TAG[0];
	myOT[1].org = myOT_TAG[1];

	GsClearOt(0, 0, &myOT[0]);
	GsClearOt(0, 0, &myOT[1]);

	// Some more things to set
	ResetGraph(0);
	SetVideoMode(MODE_NTSC);
	SetGraphDebug(0);

	// Setup debug font
	FntLoad(960, 256);
	FntOpen(0, 0, 320, 240, 0, 512);

	PadInit(0);

}


int main(void)
{

	GsIMAGE tim_info;
	
	GsCELL BGcell[64];
	GsMAP BGmap;
	GsBG BGparams;

	int tx,ty,index;
	int PadStatus;


	init();


	// Load the tiles into the framebuffer
	tim_info = LoadTIM((u_long*)&tim_tiles[0]);


	// Prepare the cell entries
	for (ty=0; ty<8; ty=ty+1)
	{
		for (tx=0; tx<8; tx=tx+1)
		{
			
			index = tx + (8 * ty);

			BGcell[index].u 	= 16 * tx;
			BGcell[index].v 	= 16 * ty;
			BGcell[index].cba 	= GetClut(tim_info.cx, tim_info.cy);
			BGcell[index].flag 	= 0;
			BGcell[index].tpage 	= GetTPage((tim_info.pmode & 3), 0, tim_info.px, tim_info.py);

		};
	};


	// Setup a 1x1 tile map
	BGmap.cellw 	= 16;
	BGmap.cellh 	= 16;
	BGmap.ncellw 	= 1;
	BGmap.ncellh 	= 1;
	BGmap.base 	= &BGcell[0]; // Only seems to take tile 3 instead of 0
	BGmap.index 	= 0;


	// Setup struct for GsSortBg
	BGparams.attribute = (tim_info.pmode & 3) << 24;
	BGparams.x = 0;
	BGparams.y = 0;

	BGparams.w = 320;
	BGparams.h = 240;

	BGparams.scrollx = BGparams.scrolly = 0;
	BGparams.r = BGparams.g = BGparams.b = 128;

	BGparams.map = &BGmap;

	BGparams.mx = 0;
	BGparams.my = 0;
	BGparams.scalex = BGparams.scaley = ONE;
	BGparams.rotate = 0;


	// Setup camera
	Camera.x = 0;
	Camera.xMove = 0;
	Camera.y = 0;
	Camera.yMove = 0;
	

	while (1)
	{

		// Prepare the display buffer for drawing
		ActiveBuffer = GsGetActiveBuff();
		GsSetWorkBase((PACKET*)GPUPacketArea[ActiveBuffer]);
		GsClearOt(0, 0, &myOT[ActiveBuffer]);


		// Do controls
		PadStatus = PadRead(0);

		if (PadStatus & PADLup)
			Camera.yMove = Camera.yMove - 0.8f;
		if (PadStatus & PADLdown)
			Camera.yMove = Camera.yMove + 0.8f;
		if (PadStatus & PADLleft)
			Camera.xMove = Camera.xMove - 0.8f;
		if (PadStatus & PADLright)
			Camera.xMove = Camera.xMove + 0.8f;


		// Handle camera coords
		Camera.x = Camera.x + Camera.xMove;
		Camera.y = Camera.y + Camera.yMove;

		Camera.xMove = Camera.xMove * 0.8f;
		Camera.yMove = Camera.yMove * 0.8f;


		// Sort the BG
		BGparams.scrollx = Camera.x;
		BGparams.scrolly = Camera.y;
		GsSortBg(&BGparams, &myOT[ActiveBuffer], 0);


		// Display the crap
		FntFlush(-1);
		DrawSync(0);
		VSync(0);

		// Then swap display buffers
		GsSwapDispBuff();
		GsSortClear(0, 0, 0, &myOT[ActiveBuffer]);
		GsDrawOt(&myOT[ActiveBuffer]);

	};

}


GsIMAGE LoadTIM(u_long *tMemAddress)
{

	RECT tRect;
	GsIMAGE tTim;

	DrawSync(0);
	tMemAddress++;
	GsGetTimInfo(tMemAddress, &tTim);	// SAVE TIM-Info in TIM

	tRect.x = tTim.px;
	tRect.y = tTim.py;
	tRect.w = tTim.pw;
	tRect.h = tTim.ph;
	LoadImage(&tRect, tTim.pixel);		// Load TIM-DATA into VideoRam
	DrawSync(0);

	if ((tTim.pmode >> 3) & 0x01)
	{

		tRect.x = tTim.cx;
		tRect.y = tTim.cy;
		tRect.w = tTim.cw;
		tRect.h = tTim.ch;
		LoadImage(&tRect, tTim.clut);	// load CLUT into VideoRam

	}

	DrawSync(0);				// wait until GPU is ready
	return tTim;

}
Attached are some files that you'll need to compile the code.

Any help will be appreciated...
- Lameguy64
You do not have the required permissions to view the files attached to this post.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

isufje
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 64
Joined: Apr 11, 2012

Post by isufje » September 23rd, 2013, 2:22 pm

My suggestion to you is don't use GsSortBg at all. It's so CPU-Intensive that it's not even worth it. Instead, use GsSortSprite and make your own Background tile function with it. You'll be much happier u did, trust me.

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » September 23rd, 2013, 5:02 pm

isufje wrote:My suggestion to you is don't use GsSortBg at all. It's so CPU-Intensive that it's not even worth it. Instead, use GsSortSprite and make your own Background tile function with it. You'll be much happier u did, trust me.
I've been thinking about that recently...Now I know that GsSortBg is total crap being that its also hard to use.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Orion_
Verified
Legendary Programmer
Legendary Programmer
Posts: 240
Joined: Aug 13, 2012
I am a: Programmer
PlayStation Model: Net Yaroze
Location: France
Contact:

Post by Orion_ » September 23rd, 2013, 8:41 pm

I use it in my lib, check the BG.c file http://onorisoft.free.fr/rdl.php?url=ps ... psxlib.zip
I use GsSortFastBg because it's faster that GsSortBg, but you have much more possibilities with GsSortBg (rotation, scaling)
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest