Beispiel #1
0
bool PisteInput_Hae_Ohjaimet()
{
	bool ok = false;
	
	for(int ohjain=0; ohjain < PI_MAX_PELIOHJAIMIA; ohjain++)
	{
		if (PI_joysticks[ohjain].available)
		{
			if (FAILED(PI_joysticks[ohjain].lpdijoy->Poll()))
			{
				PisteLog_Kirjoita("[Warning] Piste Input: Lost control of game pad! \n");
				PI_joysticks[ohjain].available = false;
			}

			if (FAILED(PI_joysticks[ohjain].lpdijoy->GetDeviceState(sizeof(DIJOYSTATE),(LPVOID)&PI_joysticks[ohjain].joystick_state)))
			{
				PisteLog_Kirjoita("[Warning] Piste Input: Lost control of game pad! \n");
				PI_joysticks[ohjain].available = false;
			}
			if (PI_joysticks[ohjain].available)
				ok = true;
		}
	}
	return ok;
}
Beispiel #2
0
bool PisteInput_Alusta_Keyboard()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysKeyboard, &PI_lpdikey, NULL))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Create Device failed! \n");
		return false;
	}
	
	if (FAILED(PI_lpdikey->SetCooperativeLevel(PI_main_window_handle, 
		DISCL_BACKGROUND | DISCL_NONEXCLUSIVE /* | DISCL_FOREGROUND*/))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set cooperative level failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->SetDataFormat(&c_dfDIKeyboard))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set data format failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->Acquire())) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Acquire failed! \n");
		return false;
	}

	return true;
}
Beispiel #3
0
int PisteDraw_Paletti_Pyorita(UCHAR eka_vari, UCHAR vika_vari)
{
	UCHAR i;
	
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n");		
		return PD_VIRHE;
	}

	PALETTEENTRY temp_vari;
		
	temp_vari.peRed   = PD_paletti_nyt[vika_vari].peRed;
	temp_vari.peGreen = PD_paletti_nyt[vika_vari].peGreen;
	temp_vari.peBlue  = PD_paletti_nyt[vika_vari].peBlue;

	for (i=vika_vari;i>eka_vari;i--)
	{
		PD_paletti_nyt[i].peRed   = PD_paletti_nyt[i-1].peRed;
		PD_paletti_nyt[i].peGreen = PD_paletti_nyt[i-1].peGreen;
		PD_paletti_nyt[i].peBlue  = PD_paletti_nyt[i-1].peBlue;
	}

	PD_paletti_nyt[eka_vari].peRed   = temp_vari.peRed;
	PD_paletti_nyt[eka_vari].peGreen = temp_vari.peGreen;
	PD_paletti_nyt[eka_vari].peBlue  = temp_vari.peBlue;

	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n");	
		return PD_VIRHE;	
	}
	
	return 0;
}
Beispiel #4
0
bool PisteInput_Alusta_Mouse()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysMouse, &PI_lpdimouse, NULL))) {
		PisteLog_Kirjoita("[Warning] Piste Input: No mouse available! \n");
		PI_mouse_available = false;
	}

	if (PI_mouse_available)
	{
		if (FAILED(PI_lpdimouse->SetCooperativeLevel(PI_main_window_handle,
			DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set cooperative level failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->SetDataFormat(&c_dfDIMouse))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set data format failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->Acquire())) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Acquire failed! \n");
			PI_mouse_available = false;
		}
	}

	return PI_mouse_available;
}
Beispiel #5
0
int PisteInput_Alusta(HWND &main_window_handle, HINSTANCE &hinstance_app)
{
	if (PI_unload) {
	
		PI_main_window_handle = (HWND &) main_window_handle;
		PI_hinstance_app	  = (HINSTANCE &) hinstance_app;

		if (FAILED(DirectInputCreate(PI_hinstance_app, DIRECTINPUT_VERSION, &PI_lpdi, NULL))) {
			PisteLog_Kirjoita("[Error] Piste Input: DirectInputCreate failed! \n");
			return PI_VIRHE;
		}

		/* Näppäimistön asennus */

		if (!PisteInput_Alusta_Keyboard())
			return PI_VIRHE;

		/* Hiiren asennus */

		if (!PisteInput_Alusta_Mouse())
			PI_mouse_available = false;
			//return PI_VIRHE;

		/* Ohjainten asennus */
		
		PisteInput_Alusta_Ohjaimet();

		PI_unload = false;
	}

	return 0;
}
Beispiel #6
0
int PisteDraw_Buffer_Tayta(int i, UCHAR color)
{
	DD_INIT_STRUCT(PD_ddbltfx);
	PD_ddbltfx.dwFillColor = color;	
	IDirectDrawSurface4 *buffer;

	if (i >= MAX_BUFFEREITA)
		return PD_VIRHE;

	if (PD_buffers[i].lpdds == NULL)
		return PD_VIRHE;

	buffer = PD_buffers[i].lpdds;
	
	RECT dest_rect;
	dest_rect.left	 =	0;
	dest_rect.right	 =	PD_buffers[i].leveys;
	dest_rect.top	 =	0;
	dest_rect.bottom =	PD_buffers[i].korkeus;	

	if (FAILED(buffer->Blt(&dest_rect, 
					 	   NULL, 
						   NULL, 
						   DDBLT_COLORFILL | DDBLT_WAIT, 
						   &PD_ddbltfx))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Buffer fill failed!\n");
		return PD_VIRHE;
	}

	return 0;
}
Beispiel #7
0
int PisteDraw_Paletti_Set(void)
{
	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette set failed!\n");
		return PD_VIRHE;	
	}

	return 0;
}
Beispiel #8
0
int PisteDraw_Paletti_Get(PALETTEENTRY *&paletti)
{
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get failed!\n");
		return PD_VIRHE;
	}

	paletti = (PALETTEENTRY *)PD_paletti_nyt;

	return 0;
}
Beispiel #9
0
int PisteDraw_Aseta_Videomode(int leveys, int korkeus, int bpp,
					 int max_colors)
{
	if (FAILED(PD_lpdd->SetDisplayMode(PD_ruudun_leveys, PD_ruudun_korkeus, PD_ruudun_bpp,0,0)))
	{
		strcpy(virhe,"Unable to change video mode!");
		PisteLog_Kirjoita("[Error] Piste Draw: Unable to change video mode! \n");
		return PD_VIRHE;
	}
	return 0;
}
Beispiel #10
0
bool PisteInput_Hae_Hiiri()
{
	if (PI_mouse_available)
	{
		if (FAILED(PI_lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&PI_mouse_state)))
		{
			PisteLog_Kirjoita("[Warning] Piste Input: Lost control of mouse! \n");
			PI_mouse_available = false;
		}
	}
	return PI_mouse_available;
}
Beispiel #11
0
int PisteDraw_Fade_Paletti_Do(int pros)
{
	UCHAR i;
	
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n");
		return PD_VIRHE;
	}

	for (i=0;i<255;i++)
	{
		PD_paletti_nyt[i].peRed   = (PD_paletti[i].peRed   * pros / 100);
		PD_paletti_nyt[i].peGreen = (PD_paletti[i].peGreen * pros / 100);
		PD_paletti_nyt[i].peBlue  = (PD_paletti[i].peBlue  * pros / 100);
	}

	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n");
		return PD_VIRHE;
	}
	
	return 0;
}
Beispiel #12
0
/*

int PisteDraw_Paletti_Pyorita(UCHAR eka_vari, UCHAR vika_vari)
{
	UCHAR i;
	
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt)))
		return PD_VIRHE;

	PALETTEENTRY temp_vari;
		
	temp_vari.peRed   = PD_paletti_nyt[eka_vari].peRed;
	temp_vari.peGreen = PD_paletti_nyt[eka_vari].peGreen;
	temp_vari.peBlue  = PD_paletti_nyt[eka_vari].peBlue;

	for (i=eka_vari;i<vika_vari;i++)
	{
		PD_paletti_nyt[i].peRed   = PD_paletti_nyt[i+1].peRed;
		PD_paletti_nyt[i].peGreen = PD_paletti_nyt[i+1].peGreen;
		PD_paletti_nyt[i].peBlue  = PD_paletti_nyt[i+1].peBlue;
	}

	PD_paletti_nyt[vika_vari].peRed   = temp_vari.peRed;
	PD_paletti_nyt[vika_vari].peGreen = temp_vari.peGreen;
	PD_paletti_nyt[vika_vari].peBlue  = temp_vari.peBlue;

	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt)))
		return PD_VIRHE;	
	
	return 0;
}
*/
int PisteDraw_Fade_Paletti(void)
{
	if ((PD_paletti_fade_pros < 100 && PD_paletti_fade_laskuri > 0) ||
		(PD_paletti_fade_pros > 0 && PD_paletti_fade_laskuri < 0))
	{
		PD_paletti_fade_pros += PD_paletti_fade_laskuri;
		if (PisteDraw_Fade_Paletti_Do(PD_paletti_fade_pros)==PD_VIRHE) {
			PisteLog_Kirjoita("[Error] Piste Draw: Palette fade failed!\n");	
			return PD_VIRHE;
		}
	}	

	return 0;
}
Beispiel #13
0
int PisteDraw_Buffer_Tayta(int i, int vasen, int yla, int oikea, int ala, UCHAR color)
{

	DD_INIT_STRUCT(PD_ddbltfx);
	PD_ddbltfx.dwFillColor = color;	
	IDirectDrawSurface4 *buffer;

	if (i >= MAX_BUFFEREITA)
		return PD_VIRHE;

	if (PD_buffers[i].lpdds == NULL)
		return PD_VIRHE;

	buffer = PD_buffers[i].lpdds;

	vasen += vasen_marginaali;
	oikea += vasen_marginaali;
	yla += yla_marginaali;
	ala += yla_marginaali;

	RECT dest_rect;

	dest_rect.left	 =	(long)vasen;
	dest_rect.right	 =	(long)oikea;
	dest_rect.top	 =	(long)yla;
	dest_rect.bottom =	(long)ala;
	
	if (dest_rect.left < PD_buffers[i].klipperi.left)
		dest_rect.left = PD_buffers[i].klipperi.left;

	if (dest_rect.right > PD_buffers[i].klipperi.right)
		dest_rect.right = PD_buffers[i].klipperi.right;

	if (dest_rect.top < PD_buffers[i].klipperi.top)
		dest_rect.top = PD_buffers[i].klipperi.top;

	if (dest_rect.bottom > PD_buffers[i].klipperi.bottom)
		dest_rect.bottom = PD_buffers[i].klipperi.bottom;

	if (FAILED(buffer->Blt(&dest_rect, 
					  	   NULL, 
						   NULL, 
						   DDBLT_COLORFILL | DDBLT_WAIT, 
						   &PD_ddbltfx))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Buffer fill area failed!\n");
		return PD_VIRHE;
	}

	return 0;
}
Beispiel #14
0
int PisteDraw_Piirto_Lopeta(int i)
{
	if (PD_buffers[i].lukittu)
	{	
		if (FAILED(PD_buffers[i].lpdds->Unlock(NULL)))
		{
			PisteLog_Kirjoita("[Error] Piste Draw: Free draw - surface unlock failed!\n");
			return PD_VIRHE;
		}

		PD_buffers[i].lukittu = false;
	}
	return 0;
}
Beispiel #15
0
int PisteDraw_Font_Uusi(char *polku, char *tiedosto)
{
	int index = 0;
	bool found = false;

	PD_Loki_Kirjoita("PisteDraw_Font_Uusi\n");
	PD_Loki_Kirjoita(polku);
	PD_Loki_Kirjoita(tiedosto);

	PisteLog_Kirjoita("- PisteDraw: Loading a font from file: ");
	PisteLog_Kirjoita(polku);PisteLog_Kirjoita(tiedosto);
	PisteLog_Kirjoita("\n");

	while (index<MAX_FONTTEJA && !found)
	{
		if (PD_fontit[index] == NULL)
		{
			PD_Loki_Kirjoita("Tyhja fontti\n");
			
			PD_fontit[index] = new PisteFont();
			
			if (PD_fontit[index]->LataaTiedostosta(polku,tiedosto) == -1){
				strcpy(virhe,"PisteEngine can't load a font from file!");
				PisteLog_Kirjoita("[Error] Piste Draw: Loading font failed!\n");
				
				PD_Loki_Kirjoita("Lataus epäonnistui\n");

				return PD_VIRHE;
			}

			PD_Loki_Kirjoita("Lataus onnistui\n");

			found = true;
			
			if (PD_fontit[index]->Korkeus() > PD_font_korkein)
			{
				PD_font_korkein = PD_fontit[index]->Korkeus();
				PisteDraw_Buffer_Tuhoa(PD_fontbuffer);
				PD_fontbuffer = PisteDraw_Buffer_Uusi(PD_ruudun_leveys,PD_font_korkein,true,255);
			}

		}
		else
			index++;
	}
	
	if (!found)
	{
		strcpy(virhe,"PisteEngine has run out of free fonts!");
		PisteLog_Kirjoita("[Error] Piste Draw: PisteDraw has run out of free fonts!\n");
		index = PD_VIRHE;
	}

	PD_Loki_Kirjoita("Kaikki ok.\n");

	return index;
}
Beispiel #16
0
int PisteDraw_Piirto_Aloita(int i, UCHAR *&back_buffer, DWORD &lPitch)
{
	if (PD_buffers[i].lukittu)
		if (PisteDraw_Piirto_Lopeta(i)==PD_VIRHE) {
			PisteLog_Kirjoita("[Error] Piste Draw: Can't start free draw: Surface unlock failed!\n");
			return PD_VIRHE;
		}
	
	DD_INIT_STRUCT(PD_ddsd); 
	//PD_piirto_buffer_index = i;

	if (FAILED(PD_buffers[i].lpdds->Lock(NULL, &PD_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
	{
		PisteLog_Kirjoita("[Error] Piste Draw: Can't start free draw: Surface lock failed!\n");
		return PD_VIRHE;
	}	

	back_buffer = (UCHAR *)PD_ddsd.lpSurface;
	lPitch		= (DWORD &)PD_ddsd.lPitch;
		
	PD_buffers[i].lukittu = true;
	
	return 0;
}
Beispiel #17
0
DWORD PisteDraw_Videomuistia_Max()
{
	DDCAPS hel_caps, hal_caps;

	DD_INIT_STRUCT(hel_caps);
	DD_INIT_STRUCT(hal_caps);	
	
	if (FAILED(PD_lpdd->GetCaps(&hal_caps,&hel_caps)))	
	{
		strcpy(virhe,"Cannot aquire system information!");
		PisteLog_Kirjoita("[Error] Piste Draw: Cannot aquire system information! \n");
		return PD_VIRHE;
	}

	return hal_caps.dwVidMemTotal;
}
Beispiel #18
0
bool PisteInput_Hae_Nappaimet()
{
	HRESULT result;
	bool ok = true;
	
	while (result = PI_lpdikey->GetDeviceState(sizeof(PI_keyboard_state),
		   (LPVOID) PI_keyboard_state) == DIERR_INPUTLOST)
	{
		if (FAILED(result = PI_lpdikey->Acquire()))
		{
			PisteLog_Kirjoita("[Warning] Piste Input: Lost control of keyboard! \n");
			ok = false;
		}
	}
	
	return ok;
}
Beispiel #19
0
int PisteDraw_Piirto_Lopeta(void)
{
	int i = 0;

	while (i<MAX_BUFFEREITA /*PD_buffereita_varattu*/)
	{
		if (PD_buffers[i].lpdds != NULL)
			if (PD_buffers[i].lukittu)
			{	
				if (FAILED(PD_buffers[i].lpdds->Unlock(NULL)))
				{
					PisteLog_Kirjoita("[Error] Piste Draw: Free draw - surface unlock failed!\n");
					return PD_VIRHE;
				}

				PD_buffers[i].lukittu = false;
			}
	}
	return 0;
}
Beispiel #20
0
int PisteDraw_Font_Uusi(int buffer_index, int buffer_x, int buffer_y, int leveys, int korkeus, int lkm)
{
	int index = 0;
	bool found = false;

	while (index<MAX_FONTTEJA && !found)
	{
		if (PD_fontit[index] == NULL)
		{
			PD_fontit[index] = new PisteFont(korkeus,leveys,lkm);
			
			UCHAR *buffer = NULL;
			DWORD ruudun_leveys;			
			
			PisteDraw_Piirto_Aloita(buffer_index, *&buffer, (DWORD &) ruudun_leveys);
			PD_fontit[index]->Get_bitmap(buffer_x,buffer_y,ruudun_leveys,buffer);
			PisteDraw_Piirto_Lopeta(buffer_index);
			found = true;
			
			if (korkeus > PD_font_korkein)
			{
				PD_font_korkein = korkeus;
				PisteDraw_Buffer_Tuhoa(PD_fontbuffer);
				PD_fontbuffer = PisteDraw_Buffer_Uusi(PD_ruudun_leveys,korkeus,true,255);
			}

		}
		else
			index++;
	}
	
	if (!found)
	{
		strcpy(virhe,"PisteEngine has run out of free fonts!");
		PisteLog_Kirjoita("[Error] Piste Draw: PisteDraw has run out of free fonts!\n");
		index = PD_VIRHE;
	}

	return index;
}
Beispiel #21
0
int PisteDraw_Buffer_Flip(int i)
{
	DD_INIT_STRUCT(PD_ddsd);
	DD_INIT_STRUCT(PD_ddbltfx);

	RECT dest_rect;
	dest_rect.left	 =	0;
	dest_rect.right	 =	PD_ruudun_leveys;
	dest_rect.top	 =	0;
	dest_rect.bottom =	PD_ruudun_korkeus;

	if (FAILED(PD_buffers[PD_TAUSTABUFFER].lpdds->Blt(&dest_rect, 
										PD_buffers[i].lpdds,
										&dest_rect, 
										(DDBLT_WAIT | DDBLT_KEYSRC),
										NULL)))
	{
		strcpy(virhe,"Unable to flip surface!");
		PisteLog_Kirjoita("[Error] Piste Draw: Unable to flip surface!\n");
		return PD_VIRHE;	
	}
	return 0;
}
Beispiel #22
0
int PisteDraw_Buffer_Flip(int lahde_index, int kohde_index, int x, int y, bool peilaa_x, bool peilaa_y)
{
	DD_INIT_STRUCT(PD_ddsd);				//Alustetaan DirectX pintakuvaus
	DD_INIT_STRUCT(PD_ddbltfx);				//Alustetaan Blittaus tehosteet
	int leveys;								//Apumuuttuja
	int korkeus;							//Apumuuttuja
	RECT dest_rect;							//Alue kohdebufferista josta kopioidaan lähdebufferiin
	RECT source_rect;						//Alue lähdebufferista josta kopioidaan kohdebufferiin
	RECT *klipperi_kohde;					//Pointteri kohdebufferin leikkuriin 
	RECT *klipperi_lahde;					//Pointteri lähdebufferin leikkuriin

	x += vasen_marginaali;
	y += yla_marginaali;

	if (peilaa_x)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT;

	if (peilaa_y)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORUPDOWN;

	if (peilaa_x && peilaa_y)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;

	klipperi_kohde = &PD_buffers[kohde_index].klipperi;	
	klipperi_lahde = &PD_buffers[lahde_index].klipperi;

	int vasen	= klipperi_lahde->left;
	int oikea	= klipperi_lahde->right;
	int yla		= klipperi_lahde->top;
	int ala		= klipperi_lahde->bottom;

	leveys  = oikea - vasen;	// lasketaan apuja
	korkeus = ala - yla; 

	if (x+leveys > klipperi_kohde->right)			//Varmistetaan että ei piirretä kohdebufferin
	{												//rajojen ulkopuolelle
		oikea = vasen + klipperi_kohde->right - x;
	}

	if (x < klipperi_kohde->left)
	{
		vasen = vasen - x + klipperi_kohde->left;
	}

	if (y+korkeus > klipperi_kohde->bottom)
	{
		ala = yla + klipperi_kohde->bottom - y;
	}

	if (y < klipperi_kohde->top)
	{
		yla = yla - y + klipperi_kohde->top;
	}

	if (oikea>vasen && ala>yla)
	{
				
		dest_rect.left		=	vasen+x;
		dest_rect.right		=	oikea+x;
		dest_rect.top		=	yla+y;
		dest_rect.bottom	=	ala+y;		

		source_rect.left	=	vasen;
		source_rect.right	=	oikea;
		source_rect.top		=	yla;
		source_rect.bottom	=	ala;

		if (peilaa_x)
		{
			if (x<klipperi_kohde->left)
			{
				source_rect.left  = klipperi_lahde->left;
				source_rect.right = klipperi_lahde->right - (vasen - klipperi_lahde->left);		
			}
			else
			{
				source_rect.left  = klipperi_lahde->left + (klipperi_lahde->right - oikea);
				source_rect.right = klipperi_lahde->right;
			}
		}

		if (peilaa_y)
		{
			if (y < klipperi_kohde->top)
			{
				source_rect.top    = klipperi_lahde->top;
				source_rect.bottom = klipperi_lahde->bottom - (yla - klipperi_lahde->top);		
			}
			else
			{
				source_rect.top    = klipperi_lahde->top + (klipperi_lahde->bottom - ala);
				source_rect.bottom = klipperi_lahde->bottom;
			}		
		}

		if (FAILED(PD_buffers[kohde_index].lpdds->Blt(&dest_rect, PD_buffers[lahde_index].lpdds, &source_rect,
			(DDBLT_WAIT | DDBLT_KEYSRC | DDBLT_DDFX), &PD_ddbltfx))){
			PisteLog_Kirjoita("[Error] Piste Draw: Unable to flip surface!\n");
			return PD_VIRHE; 
		}
	}

	return 0;
}
Beispiel #23
0
int	PisteDraw_Alusta(HWND &main_window_handle, HINSTANCE &hinstance_app, 
					 int leveys, int korkeus, int bpp,
					 int max_colors)
{

	if (PD_unload) {

		strcpy(virhe,"Uh, oh, I think we have a bug...");

		PD_main_window_handle	= (HWND &)main_window_handle;
		PD_hinstance_app		= (HINSTANCE &)hinstance_app;
		PD_ruudun_leveys		= leveys;
		PD_ruudun_korkeus		= korkeus;
		PD_ruudun_bpp			= bpp;
		PD_max_varit			= max_colors;
		
		LPDIRECTDRAW temp = NULL;				 // väliaikainen rajapinta jolla haetaan uusin versio
		int i;

		if (FAILED(DirectDrawCreate(NULL, &temp, NULL)))	// luo rajapintaosoitin versioon 1.0
		{
			strcpy(virhe,"Cannot initialize DirectDraw!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot initialize DirectDraw! \n");
			return PD_VIRHE;
		}

		if (FAILED(temp->QueryInterface(IID_IDirectDraw4,(LPVOID *)&PD_lpdd))) // osoitin v 4.0
		{
			strcpy(virhe,"Cannot initialize DirectDraw4!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot initialize DirectDraw4! \n");
			return PD_VIRHE;
		}

		temp->Release();	// tuhotaan väliaikainen rajapinta
		temp = NULL;
		
		if (FAILED(PD_lpdd->SetCooperativeLevel(PD_main_window_handle, // Yhteistyö Windowsin kanssa..
											  DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
											  DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
		{
			strcpy(virhe,"Failed to cooperate with Windows!");
			PisteLog_Kirjoita("[Error] Piste Draw: Failed to cooperate with Windows! \n");
			return PD_VIRHE;
		}
		
		if (FAILED(PD_lpdd->SetDisplayMode(PD_ruudun_leveys, PD_ruudun_korkeus, PD_ruudun_bpp,0,0)))
		{
			strcpy(virhe,"Unable to change video mode!");
			PisteLog_Kirjoita("[Error] Piste Draw: Unable to change video mode! \n");
			return PD_VIRHE;
		}

		DD_INIT_STRUCT(PD_ddsd);

		PD_ddsd.dwFlags				=	DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		PD_ddsd.dwBackBufferCount	=	2;				//Kolmoispuskurointi = primary + 2 taustapuskuria
		PD_ddsd.ddsCaps.dwCaps		=	DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
		
		if (FAILED(PD_lpdd->CreateSurface(&PD_ddsd, &PD_lpddsprimary, NULL)))
		{
			strcpy(virhe,"Cannot create primary surface!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot create primary surface! \n");
			return PD_VIRHE;
		}
		
		PD_buffers[PD_TAUSTABUFFER].leveys		= leveys;
		PD_buffers[PD_TAUSTABUFFER].korkeus		= korkeus;
		PisteDraw_Aseta_Klipperi(PD_TAUSTABUFFER,0,0,leveys,korkeus);
		PD_ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
		
		if (FAILED(PD_lpddsprimary->GetAttachedSurface(&PD_ddsd.ddsCaps, &PD_buffers[PD_TAUSTABUFFER].lpdds)))
		{
			strcpy(virhe,"Cannot attach back buffer to primary surface!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot attach back buffer to primary surface! \n");
			return PD_VIRHE;
		}

		PD_buffers[PD_TAUSTABUFFER2].leveys		= leveys;
		PD_buffers[PD_TAUSTABUFFER2].korkeus	= korkeus;
		PisteDraw_Aseta_Klipperi(PD_TAUSTABUFFER2,0,0,leveys,korkeus);

		for (i=1;i<255;i++)							//Luodaan 8-bittinen paletti
		{
			PD_paletti[i].peRed		=	0;
			PD_paletti[i].peGreen	=	0;
			PD_paletti[i].peBlue	=	0;
			PD_paletti[i].peFlags	=	PC_NOCOLLAPSE;
		}

		if (FAILED(PD_lpdd->CreatePalette(DDPCAPS_8BIT |
										DDPCAPS_ALLOW256 |
										DDPCAPS_INITIALIZE,
										PD_paletti,
										&PD_lpddpal,
										NULL)))
		{
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot create 8-bit palette! \n");
			strcpy(virhe,"Cannot create 8-bit palette!");
			return PD_VIRHE;
		}

		if (FAILED(PD_lpddsprimary->SetPalette(PD_lpddpal)))
		{
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot set palette! \n");
			strcpy(virhe,"Cannot set palette!");
			return PD_VIRHE;
		}

		/*LIITETÄÄN KLIPPERI KUVAN REUNOJEN YLIKIRJOITUSTA ESTÄMÄÄN*/

		PD_fontbuffer = PisteDraw_Buffer_Uusi(PD_ruudun_leveys,10,true,255);

		for (i=2;i<MAX_BUFFEREITA;i++)		// alustetaan kuvabufferi taulukko.  
			PD_buffers[i].lpdds = NULL;				// 0 ja 1 on varattu taustapuskureille

		vasen_marginaali = 0;
		yla_marginaali = 0;
	
		PD_unload = false;
	}

	return 0;
}
Beispiel #24
0
int PisteDraw_Buffer_Uusi(int leveys, int korkeus, bool video_muisti, UCHAR color)
{
	int i = 0, 
		varaus;
	bool find = false;

	DDCAPS hel_caps, hal_caps;

	DD_INIT_STRUCT(hel_caps);
	DD_INIT_STRUCT(hal_caps);

	if (FAILED(PD_lpdd->GetCaps(&hal_caps,&hel_caps)))	
	{
		strcpy(virhe,"Cannot aquire system information!");
		PisteLog_Kirjoita("[Error] Piste Draw: Cannot aquire system information to create a new buffer! \n");
		return PD_VIRHE;
	}

	if ((unsigned long)(leveys*korkeus) > hal_caps.dwVidMemFree) {		//tarkastetaan riittääkö videomuistia
		video_muisti = false;
		PisteLog_Kirjoita("[Warning] Piste Draw: Out of video memory - creating a new buffer in system memory! \n");
	}

	if (video_muisti)
	{
		varaus = DDSCAPS_VIDEOMEMORY;
	}
	else
	{
		varaus = DDSCAPS_SYSTEMMEMORY;
	}

	while ((i < MAX_BUFFEREITA) && !find)
	{
		if (PD_buffers[i].lpdds == NULL)	// Onko puskurin pinta jo varattu?
		{
			if ((PD_buffers[i].lpdds = PisteDraw_Create_Surface(leveys, korkeus, varaus, color)) != NULL)
			{
				PD_buffers[i].leveys			= leveys;
				PD_buffers[i].korkeus			= korkeus;
				PD_buffers[i].klipperi.left		= 0;
				PD_buffers[i].klipperi.top		= 0;
				PD_buffers[i].klipperi.right	= leveys;
				PD_buffers[i].klipperi.bottom	= korkeus;
				PD_buffers[i].video_muisti		= video_muisti;
				PD_buffers[i].lukittu			= false;
				find = true;
				PD_buffereita_varattu++;
			}
			else
			{
				i = PD_VIRHE;
				strcpy(virhe,"Cannot create a new DirectDraw surface!");
				PisteLog_Kirjoita("[Error] Piste Draw: Cannot create a new DirectDraw surface! \n");
			}
		}
		else
		{
			i++;
		}
	}
	
	if (!find)
	{
		strcpy(virhe,"PisteEngine has run out of buffers!");
		PisteLog_Kirjoita("[Error] Piste Draw: PisteDraw has run out of buffers! \n");
		i = PD_VIRHE;
	}

	return i;
}
Beispiel #25
0
int PisteDraw_Lataa_Kuva(int index, char *filename, bool lataa_paletti)
{
	BITMAP_FILE		bitmap;

	bool ok = false;

	char paate[4];

	for (int i=0;i<4;i++)
		paate[i] = toupper(filename[strlen(filename)-3+i]);
	paate[4] = '\0';

	if (strcmp(paate,"BMP")==0)
	{
		ok = true;
		if (PD_buffers[index].lpdds)
		{
			if (PisteDraw_Load_Bitmap(&bitmap, filename) != 0)
			{
				strcpy(virhe,"Could not load picture ");
				strcat(virhe,filename);
				strcat(virhe,"!");
				PisteLog_Kirjoita("[Error] Piste Draw: ");
				PisteLog_Kirjoita(virhe);
				PisteLog_Kirjoita("\n");
				return PD_VIRHE;
			}

			DD_INIT_STRUCT(PD_ddsd);
			
			if (FAILED(PD_buffers[index].lpdds->Lock(NULL,&PD_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL)))
			{
				strcpy(virhe,"Could not lock surface after loading a picture!");
				PisteLog_Kirjoita("[Error] Piste Draw: Could not lock surface after loading a picture! \n");
				return PD_VIRHE;
			}

			UCHAR *back_buffer = (UCHAR *)PD_ddsd.lpSurface; 

			int x;
			int y;
			int leveys, korkeus;

			if (bitmap.bitmapinfoheader.biWidth > PD_buffers[index].leveys)
				leveys = PD_buffers[index].leveys;
			else
				leveys = bitmap.bitmapinfoheader.biWidth;

			if (bitmap.bitmapinfoheader.biHeight > PD_buffers[index].korkeus)
				korkeus = PD_buffers[index].korkeus;
			else
				korkeus = bitmap.bitmapinfoheader.biHeight;

			for (y=0; y<korkeus; y++)
			{
				for (x=0; x<leveys; x++)
				{
					back_buffer[x+y*PD_ddsd.lPitch] = bitmap.buffer[x+y*bitmap.bitmapinfoheader.biWidth];
				}
			}

			if (FAILED(PD_buffers[index].lpdds->Unlock(NULL)))
			{
				strcpy(virhe,"Could not unlock surface after loading a picture!");
				PisteLog_Kirjoita("[Error] Piste Draw: Could not unlock surface after loading a picture! \n");
				return PD_VIRHE;
			}


			PisteDraw_Unload_Bitmap_File(&bitmap);
			
			if (lataa_paletti)
			{
			
				if (FAILED(PD_lpddpal->SetEntries(0,0,PD_max_varit, bitmap.paletti)))
				{
					strcpy(virhe,"Could not set palette after loading a picture!");
					PisteLog_Kirjoita("[Error] Piste Draw: Could not set palette after loading a picture! \n");
					return PD_VIRHE;
				}

				for (int pi=0;pi<256;pi++)
				{
					PD_paletti[pi].peBlue  = bitmap.paletti[pi].peBlue;
					PD_paletti[pi].peRed   = bitmap.paletti[pi].peRed;
					PD_paletti[pi].peGreen = bitmap.paletti[pi].peGreen;
					PD_paletti[pi].peFlags = bitmap.paletti[pi].peFlags;
				}

			}

		}
		else
			return PD_VIRHE;
	}

	if (strcmp(paate,"PCX")==0)
	{
		ok = true;
		if (PisteDraw_Lataa_PCX(filename, index, lataa_paletti) == PD_VIRHE) {
			strcpy(virhe,"Could not load picture ");
			strcat(virhe,filename);
			strcat(virhe,"!");
			PisteLog_Kirjoita("[Error] Piste Draw: ");
			PisteLog_Kirjoita(virhe);
			PisteLog_Kirjoita("\n");
			return PD_VIRHE;
		}
	}

	if (!ok)
	{
		strcpy(virhe,"Could not load bitmap file of type ");
		strcat(virhe,paate);
		return PD_VIRHE;
	}

	return 0;
}
Beispiel #26
0
bool PisteInput_Alusta_Ohjaimet()
{
	//LPDIRECTINPUTDEVICE temp;

	if (FAILED(PI_lpdi->EnumDevices(DIDEVTYPE_JOYSTICK, PisteInput_Enum_Ohjaimet, /*&PI_joystickGUID*/NULL, DIEDFL_ATTACHEDONLY))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepads - Enumerating failed! \n");
		return false;
	}

	for (int i=0; i < PI_MAX_PELIOHJAIMIA; i++)
	{
		if (PI_joysticks[i].nimi != NULL)
		{
			if (PisteInput_Alusta_Ohjain(i))
			{
				PI_joysticks[i].available = true;
			}
			else
			{
				PI_joysticks[i].available = false;
			}
		}
		else
			PI_joysticks[i].available = false;
	}

	/*
	if (FAILED(PI_lpdi->CreateDevice(PI_joystickGUID, &temp, NULL)))
		return false;

	if (FAILED(temp->QueryInterface(IID_IDirectInputDevice2,(void**) &PI_lpdijoy)))
		return false;

	if (FAILED(temp->Release()))
		return false;

	if (FAILED(PI_lpdijoy->SetCooperativeLevel(PI_main_window_handle, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE	)))
		return false;

	if (FAILED(PI_lpdijoy->SetDataFormat(&c_dfDIJoystick)))
		return false;

	DIPROPRANGE joy_axis_range;

	//Määritellään x-akseli
	
	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_X;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	//Määritellään y-akseli

	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_Y;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	DIPROPDWORD dead_angle;

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_X;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_Y;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	if (FAILED(PI_lpdijoy->Acquire()))
		return false;
	*/
	return true;
}
Beispiel #27
0
bool PisteInput_Alusta_Ohjain(int index)
{
	LPDIRECTINPUTDEVICE temp;
	
	if (FAILED(PI_lpdi->CreateDevice(PI_joysticks[index].joystickGUID, &temp, NULL))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Create device failed! \n");
		return false;
	}

	if (FAILED(temp->QueryInterface(IID_IDirectInputDevice2,(void**) &PI_joysticks[index].lpdijoy))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Create device failed! \n");
		return false;
	}

	if (FAILED(temp->Release())) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Releasing DirectInputDevice 1 failed! \n");
		return false;
	}

	if (FAILED(PI_joysticks[index].lpdijoy->SetCooperativeLevel(PI_main_window_handle, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE	))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Releasing DirectInputDevice 1 failed! \n");
		return false;
	}

	if (FAILED(PI_joysticks[index].lpdijoy->SetDataFormat(&c_dfDIJoystick))) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Set dataformat failed! \n");
		return false;
	}

	DIPROPRANGE joy_axis_range;

	//Määritellään x-akseli
	
	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_X;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	//Määritellään y-akseli

	joy_axis_range.lMin = -PI_OHJAIN_XY;
	joy_axis_range.lMax =  PI_OHJAIN_XY;
	joy_axis_range.diph.dwSize			= sizeof(DIPROPRANGE);
	joy_axis_range.diph.dwHeaderSize	= sizeof(DIPROPHEADER);
	joy_axis_range.diph.dwObj = DIJOFS_Y;
	joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);

	DIPROPDWORD dead_angle;

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_X;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	dead_angle.diph.dwSize			= sizeof(dead_angle);
	dead_angle.diph.dwHeaderSize	= sizeof(dead_angle.diph);
	dead_angle.diph.dwObj			= DIJOFS_Y;
	dead_angle.diph.dwHow			= DIPH_BYOFFSET;
	dead_angle.dwData				= 5000; //= 10% 
	PI_joysticks[index].lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);

	if (FAILED(PI_joysticks[index].lpdijoy->Acquire())) {
		PisteLog_Kirjoita("[Error] Piste Input: Gamepad - Acquiring device failed! \n");
		return false;
	}

	return true;
}
Beispiel #28
0
int PisteDraw_Buffer_Flip_Nopea(int lahde_index, int kohde_index, int x, int y)
{
	DD_INIT_STRUCT(PD_ddsd);				//Alustetaan DirectX pintakuvaus
	DD_INIT_STRUCT(PD_ddbltfx);				//Alustetaan Blittaus tehosteet
	int leveys;								//Apumuuttuja
	int korkeus;							//Apumuuttuja
	RECT source_rect;						//Alue lähdebufferista josta kopioidaan kohdebufferiin
	RECT *klipperi_kohde;					//Pointteri kohdebufferin leikkuriin 
	RECT *klipperi_lahde;					//Pointteri lähdebufferin leikkuriin

	x += vasen_marginaali;
	y += yla_marginaali;

	klipperi_kohde = &PD_buffers[kohde_index].klipperi;	
	klipperi_lahde = &PD_buffers[lahde_index].klipperi;

	int vasen	= klipperi_lahde->left;
	int oikea	= klipperi_lahde->right;
	int yla		= klipperi_lahde->top;
	int ala		= klipperi_lahde->bottom;

	leveys  = oikea - vasen;	// lasketaan apuja
	korkeus = ala - yla; 

	if (x+leveys > klipperi_kohde->right)			//Varmistetaan että ei piirretä kohdebufferin
	{												//rajojen ulkopuolelle
		oikea = vasen + klipperi_kohde->right - x;
	}

	if (x < klipperi_kohde->left)
	{
		vasen = vasen - x + klipperi_kohde->left;
		x = klipperi_kohde->left;
	}

	if (y+korkeus > klipperi_kohde->bottom)
	{
		ala = yla + klipperi_kohde->bottom - y;
	}

	if (y < klipperi_kohde->top)
	{
		yla = yla - y + klipperi_kohde->top;
		y = klipperi_kohde->top;
	}

	if (oikea>vasen && ala>yla)
	{
		source_rect.left	=	vasen;
		source_rect.right	=	oikea;
		source_rect.top		=	yla;
		source_rect.bottom	=	ala;

		if (FAILED(PD_buffers[kohde_index].lpdds->BltFast(x, y, PD_buffers[lahde_index].lpdds, &source_rect,
			(DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY)))) {			
			PisteLog_Kirjoita("[Error] Piste Draw: BlitFast failed!\n");
			return PD_VIRHE; // blitataan kaikki paitsi läpinäkyvyysväri
		}
	}

	return 0;
}