コード例 #1
0
ファイル: client.c プロジェクト: naknut/Project-Puzzle
/**
 Author: 	Joel Denke
 Description: 	Init the world by loading map and players
 */
void initWorld()
{
	int i;
	
	mapLoad(&gameWorld, MAP_FILE);
	drawGraphics();
	
	for (i = 0; i < no_players; i++) {
		initPlayer(i, connection);
	}
	
	printWorld();
	state = gRunning;
}
コード例 #2
0
ファイル: testApp.cpp プロジェクト: relaystudio/Stoke
//--------------------------------------------------------------
void testApp::draw(){
    if(edit) ofClear(0);
   // ofSetColor(255);
    ofPushMatrix();
    if(fullscreen) ofScale(1.25, 1.25);
    ofEnableBlendMode(OF_BLENDMODE_ADD);
    if(edit) drawEdit();
    else drawGraphics();
    if(debug) drawDebug();
    ofPopMatrix();
    
    float mult = ofMap(part->getMainVal(), 0.8, 1.0, 0.0, 0.3, true);
    
    ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
    berserk.begin();
    d += 0.1;
    berserk.setUniform1f("t", d);
    berserk.setUniform1fv("multi", &mult);
    ofRect(0,0,ofGetWidth(), ofGetHeight());
    berserk.end();
}
コード例 #3
0
void SpriteFont::Initialize(const wchar *fontName, float fontSize, UINT fontStyle, bool antiAliased, ID3D11Device *device) {
	m_size = fontSize;

	Gdiplus::TextRenderingHint hint = antiAliased ? Gdiplus::TextRenderingHintAntiAliasGridFit : Gdiplus::TextRenderingHintSingleBitPerPixelGridFit;

	// Init GDI+
	ULONG_PTR token = NULL;
	Gdiplus::GdiplusStartupInput startupInput(NULL, true, true);
	Gdiplus::GdiplusStartupOutput startupOutput;
	HR(GdiplusStartup(&token, &startupInput, &startupOutput));

	// Create the font
	Gdiplus::Font font(fontName, fontSize, fontStyle, Gdiplus::UnitPixel, NULL);

	// Check for error during construction
	HR(font.GetLastStatus());

	// Create a temporary Bitmap and Graphics for figuring out the rough size required
	// for drawing all of the characters
	int size = static_cast<int>(fontSize * NumChars * 2) + 1;
	Gdiplus::Bitmap sizeBitmap(size, size, PixelFormat32bppARGB);
	HR(sizeBitmap.GetLastStatus());

	Gdiplus::Graphics sizeGraphics(&sizeBitmap);
	HR(sizeGraphics.GetLastStatus());
	HR(sizeGraphics.SetTextRenderingHint(hint));

	m_charHeight = font.GetHeight(&sizeGraphics) * 1.5f;

	wchar allChars[NumChars + 1];
	for (wchar i = 0; i < NumChars; ++i) {
		allChars[i] = i + StartChar;
	}
	allChars[NumChars] = 0;

	Gdiplus::RectF sizeRect;
	HR(sizeGraphics.MeasureString(allChars, NumChars, &font, Gdiplus::PointF(0, 0), &sizeRect));
	int numRows = static_cast<int>(sizeRect.Width / TexWidth) + 1;
	int texHeight = static_cast<int>(numRows * m_charHeight) + 1;

	// Create a temporary Bitmap and Graphics for drawing the characters one by one
	int tempSize = static_cast<int>(fontSize * 2);
	Gdiplus::Bitmap drawBitmap(tempSize, tempSize, PixelFormat32bppARGB);
	HR(drawBitmap.GetLastStatus());

	Gdiplus::Graphics drawGraphics(&drawBitmap);
	HR(drawGraphics.GetLastStatus());
	HR(drawGraphics.SetTextRenderingHint(hint));

	// Create a temporary Bitmap + Graphics for creating a full character set
	Gdiplus::Bitmap textBitmap(TexWidth, texHeight, PixelFormat32bppARGB);
	HR(textBitmap.GetLastStatus());

	Gdiplus::Graphics textGraphics(&textBitmap);
	HR(textGraphics.GetLastStatus());
	HR(textGraphics.Clear(Gdiplus::Color(0, 255, 255, 255)));
	HR(textGraphics.SetCompositingMode(Gdiplus::CompositingModeSourceCopy));

	// Solid brush for text rendering
	Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255));
	HR(brush.GetLastStatus());

	// Draw all of the characters, and copy them to the full character set
	wchar charString [2];
	charString[1] = 0;
	int currentX = 0;
	int currentY = 0;
	for (uint64 i = 0; i < NumChars; ++i) {
		charString[0] = static_cast<wchar>(i + StartChar);

		// Draw the character
		HR(drawGraphics.Clear(Gdiplus::Color(0, 255, 255, 255)));
		HR(drawGraphics.DrawString(charString, 1, &font, Gdiplus::PointF(0, 0), &brush));

		// Figure out the amount of blank space before the character
		int minX = 0;
		for (int x = 0; x < tempSize; ++x) {
			for (int y = 0; y < tempSize; ++y) {
				Gdiplus::Color color;
				HR(drawBitmap.GetPixel(x, y, &color));
				if (color.GetAlpha() > 0) {
					minX = x;
					x = tempSize;
					break;
				}
			}
		}

		// Figure out the amount of blank space after the character
		int maxX = tempSize - 1;
		for (int x = tempSize - 1; x >= 0; --x) {
			for (int y = 0; y < tempSize; ++y) {
				Gdiplus::Color color;
				HR(drawBitmap.GetPixel(x, y, &color));
				if (color.GetAlpha() > 0) {
					maxX = x;
					x = -1;
					break;
				}
			}
		}

		int charWidth = maxX - minX + 1;

		// Figure out if we need to move to the next row
		if (currentX + charWidth >= TexWidth) {
			currentX = 0;
			currentY += static_cast<int>(m_charHeight) + 1;
		}

		// Fill out the structure describing the character position
		m_charDescs[i].X = static_cast<float>(currentX);
		m_charDescs[i].Y = static_cast<float>(currentY);
		m_charDescs[i].Width = static_cast<float>(charWidth);
		m_charDescs[i].Height = static_cast<float>(m_charHeight);

		// Copy the character over
		int height = static_cast<int>(m_charHeight + 1);
		HR(textGraphics.DrawImage(&drawBitmap, currentX, currentY, minX, 0, charWidth, height, Gdiplus::UnitPixel));

		currentX += charWidth + 1;
	}

	// Figure out the width of a space character
	charString[0] = ' ';
	charString[1] = 0;
	HR(drawGraphics.MeasureString(charString, 1, &font, Gdiplus::PointF(0, 0), &sizeRect));
	m_spaceWidth = sizeRect.Width;

	// Lock the bitmap for direct memory access
	Gdiplus::BitmapData bmData;
	HR(textBitmap.LockBits(&Gdiplus::Rect(0, 0, TexWidth, texHeight), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bmData));

	// Create a D3D texture, initalized with the bitmap data
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = TexWidth;
	texDesc.Height = texHeight;
	texDesc.MipLevels = 1;
	texDesc.ArraySize = 1;
	texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;
	texDesc.Usage = D3D11_USAGE_IMMUTABLE;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA data;
	data.pSysMem = bmData.Scan0;
	data.SysMemPitch = TexWidth * 4;
	data.SysMemSlicePitch = 0;

	HR(device->CreateTexture2D(&texDesc, &data, &m_texture));

	HR(textBitmap.UnlockBits(&bmData));

	// Create the shader resource view
	D3D11_SHADER_RESOURCE_VIEW_DESC srDesc;
	srDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	srDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srDesc.Texture2D.MipLevels = 1;
	srDesc.Texture2D.MostDetailedMip = 0;

	HR(device->CreateShaderResourceView(m_texture, &srDesc, &m_SRV));

	// Shutdown GDI+
	//Gdiplus::GdiplusShutdown(token);
	// TODO: Figure out why this throws exceptions
}
コード例 #4
0
ファイル: client.c プロジェクト: naknut/Project-Puzzle
/**
 * Author: 	 	Joel Denke, Marcus Isaksson
 * Description:		Run the game on client
 */
int main(int argc, char *argv[])
{
	int i, j, no, yb, keysHeld[323] = {0};
	int result = 0;
	SDL_Thread * eventBuffer;
	SDL_Thread * runBuffer;
	struct timer_t2 fps;
	
	char * server_ip = malloc(sizeof(char) * 16);
	char * elem = malloc(sizeof(char) * MESSAGE_SIZE);

	pColor = malloc(sizeof(SDL_Color));
	oColor = malloc(sizeof(SDL_Color));
	connection = malloc(sizeof(connection_data));

	for (i = 0; i < NO_BUFFERS; i++) {
		cb[i] = malloc(sizeof(cBuffer));
		b_lock[i] = SDL_CreateMutex();
	}

	strcpy(server_ip, "127.0.0.1");

	pColor->r = 0;
	pColor->g = 255;
	pColor->b = 255;
	oColor->r = 0;
	oColor->g = 0;
	oColor->b = 255;

	initGraphics();
	initSound();

	printf("Render menu\n");
	graphicsMenu(&gameWorld, server_ip);

	initSlots(cb[0], BUFFER_SIZE);
	initSlots(cb[1], NO_OBJECTS);
	initSlots(cb[2], BUFFER_SIZE);

	state = gStart;

	if (clientConnect(connection, server_ip) == 0)
	{
		eventBuffer = SDL_CreateThread(listenEventBuffer, &connection);

		while (1) {
			switch (state) {
				case gStart:
					runData(2);
					break;
				case gInit:
					timer_start(&fps);
					startDraw();
					drawLoadScr(SCREEN_WIDTH, SCREEN_HEIGHT);
					endDraw();

					initWorld();
					
					if (timer_get_ticks(&fps) < 1000 / FPS)
					{
						//delay the as much time as we need to get desired frames per second
						SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) );
					}
					break;
				case gRunning :
					timer_start(&fps);
					drawGraphics();
					listenInput(keysHeld);

					// i = 0: players; i = 1: objects; i = 2: messages
					for (i = 0; i < NO_BUFFERS; i++) {
						runData(i);
					}

					if (timer_get_ticks(&fps) < 1000 / FPS)
					{
						//delay the as much time as we need to get desired frames per second
						SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) );
					}

					break;
				case gExit :
					//sprintf(string, "%d,quit", connection->client_id);
					printf("Freeing music now\n");
					pauseMusic();
					freeMusic();
					end_session(connection);
					printf("Player is exit game now\n");
					exitClient(eventBuffer);
					break;
				default :
					printf("test\n");
					break;
			}
		}
	} else {
		printf("Misslyckade med att kontakta servern på ip-adress: '%s'\n", server_ip);
		state = gExit;
		pauseMusic();
		freeMusic();
		exitClient(eventBuffer);
	}

	return 0;
}
コード例 #5
0
/*Beginning of processPrint() routine
This function processes the user input. It decides the depth (from every bore hole), that is closest to the user input. 
Then it displays the data at that
depth to the user*/
void processPrint(struct holeStruct holeData[MAX_HOLES],float inputDepth,char label1[50], char label2[50],struct dimenssionStruct*dimenPtr,int choice,int legend)
{


				/*This proceedure takes the user input, loops through holeData[] array and calculates the minimum 
				difference between the user input and  soil depths  (as contained in holeData[..].soilData[..] array) for every bore hole
				This minimum difference is stored in min variable and the index of  depth at which the difference was minimum is stored
				in soilIndex variable.And  Soil Info at this depth is then displayed to the user*/
	
				int holeIndex;
				int soilCounter;
				int min=0;
				int soilIndex=0;
				double diff=0;


	
				//Erase graphics already drawn on the window
				eraseGraphics();
	

	
				//Uses a for loop to display all the bore hole information
				for(holeIndex=0;holeIndex<MAX_HOLES;holeIndex++)
				{
		
								printf("\n-------------------------------------------------------\n");
								printf("\n%s %s\n",label1,label2);
								printf("%s %lf %lf %d\n",holeData[holeIndex].Name,holeData[holeIndex].eastX,holeData[holeIndex].northY, holeData[holeIndex].numSamples);
	
								//Uses this nested for loop to calculate the depth from which soil information should be displayed
								for(soilCounter=0;soilCounter<holeData[holeIndex].numSamples;soilCounter++)
								{
												//Calculates the difference between user input and the actual depth
												diff=abs((holeData[holeIndex].soilData[soilCounter].depth)-(inputDepth));
			
												//If user input is not equal to the actual depth, then below code is executed
												if (holeData[holeIndex].soilData[soilCounter].depth !=inputDepth)
												{
																if(soilCounter==0  )
																{
																				//If this is the first time the loop is executing, assigns the difference to this var.
																				min=diff;
			
																}
																else if((min)>(diff))
																{
																				//If min var is greater than diff var, then min=diff
																				min=diff;
																				soilIndex=soilCounter;
				
			
																}
					
			
				
												}
			
												//If user input is equal to actual depth, then below code is executed
												else if(holeData[holeIndex].soilData[soilCounter].depth ==inputDepth)
												{
																soilIndex=soilCounter;
												}
		
		
			
								}
		
		
		
								//After calculations made above, below code prints the results on the Console
								printf("\n%s",label2);
								printf("%.2f ",holeData[holeIndex].soilData[soilIndex].depth);
		
								switch (choice)
								{
												case 1:
												{
																printf("%s\n",holeData[holeIndex].soilData[soilIndex].type);
																break;
												}
				
												case 2:
												{
																printf("%s\n",holeData[holeIndex].soilData[soilIndex].color);
																break;
												
												}
												case 3:
												{
				
																printf("%s\n",holeData[holeIndex].soilData[soilIndex].strength);
																break;
												}
												case 12:
												{	 
																printf("%s %s\n",holeData[holeIndex].soilData[soilIndex].type,holeData[holeIndex].soilData[soilIndex].color);
																break;
												}
									
												case 13:
												{
																printf("%s %s\n",holeData[holeIndex].soilData[soilIndex].type,holeData[holeIndex].soilData[soilIndex].strength);
																break;
												}
								
												case 23:
												{
				
																printf("%s %s\n",holeData[holeIndex].soilData[soilIndex].color,holeData[holeIndex].soilData[soilIndex].strength);
																break;
												}
								
												case 123:
												{
																printf("%s %s %s\n",holeData[holeIndex].soilData[soilIndex].type,holeData[holeIndex].soilData[soilIndex].color,holeData[holeIndex].soilData[soilIndex].strength);
																break;
												}
								
												default:
												{
												printf("\nInvalid Entry\n");
												break;
												}
			
								}
			
		
								/*After printing the results on the console, drawGraphics routine is called, which
								draws results on the Graphics Window*/
								drawGraphics(holeData,holeIndex,soilIndex,choice,dimenPtr,legend);
		
								legend=0;
				}
	
				printf("\nTotal Number of Bore holes: %d\nMinimum X: %.3lf; Maximum X: %.3lf; Range X: %.3lf\nMinimum Y: %.3lf; Maximum Y: %.3lf\n RangeY: %.3lf\n",MAX_HOLES,dimenPtr->minX,dimenPtr->maxX,dimenPtr->rangeX,dimenPtr->minY,dimenPtr->maxY,dimenPtr->rangeY);
		

}
コード例 #6
0
// drawing callback function
void glutDisplay()
{   
    drawGraphics();
    glutSwapBuffers();
}