Pynolathgeen 19 Light Poster

Hello, I've got a question about the IOCP Thread pooling.

How do I create such pools?
Do I need to create some threads (I know about the 2*CPU rule) with the same function?

Anyone care to explain me some?
I'm new to IOCP, I already have some experience in Network Programming though but that was with just one client at a time.
Now I'm programming a wrapper class for IOCP, for use later on for games and such.

Thanks alot!

Pynolathgeen 19 Light Poster

You can use "atoi" to convert a string to int and "itoa" to convert it from int to string, or the other way around xD.

Look for it on MSDN

Pynolathgeen 19 Light Poster

Hello,

I'm programming an little MMORPG for getting experience in Game Programming.
I need a 2D Camera thing for this game to expand it a lot, since an MMORPG is not only on the same map.

I know the trick of just moving everything to the left or the right depending of the movement, but I dislike using it because it ruins my collision detection things.

I already have a piece of code, and code runs fine but not as it should, the rendering is upside down.

D3DXMatrixOrthoLH(&Ortho2D, 800.0, 600.0, 0.0f, 1.0f);
D3DXMatrixIdentity(&Identity);

Device->SetTransform(D3DTS_PROJECTION, &Ortho2D);
Device->SetTransform(D3DTS_WORLD, &Identity);
Device->SetTransform(D3DTS_VIEW, &Identity);

This is all the code I can provide right now as I am on a different PC.

If you think you can help me, please post one.

Thanks!~

Pynolathgeen 19 Light Poster

This is just an .INI file, like wildgoose said.

This is used for storing settings of the game you are playing

Pynolathgeen 19 Light Poster

Multithreaded Debug DLL is not a problem either. You just need Multithreaded.

Pynolathgeen 19 Light Poster

You need to set your project properties, assuming you use VC++.

Press ALT+7, Click on Configuration Properties, go to C/C++ -> Code Generation.
There is an option called Runtime Library, you should set it to Multi threaded. Be aware that you executable size increases with like 300kb.

~Pyno

Pynolathgeen 19 Light Poster

Hello, I've got a pretty much burning question here.

Its about BitBlt. I have a window that functions as a button but I wanted to do some markup on it. So I the added BS_OWNERDRAW style to the button, and wanted to BitBlt an image on it. I tried it in WM_DRAWITEM first and it did not work. Then I tried it on WM_PAINT and it did work. I could not find anything on Google so maybe I can find more luck here.

This is the code:

HWND hwnd = Button;
BITMAP bm;
PAINTSTRUCT ps;				
LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam;
HBITMAP g_hbmBall = (HBITMAP)LoadImage( NULL, "Test.bmp", IMAGE_BITMAP, 0, 0,
			       LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall);

GetObject(g_hbmBall, sizeof(bm), &bm);

BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
DeleteObject(g_hbmBall);

EndPaint(hwnd, &ps);

There is no checking of variables here, but I did try it, they are all valid.
And I thought if it works in WM_PAINT, it should also work in WM_DRAWITEM.


Thanks

Pynolathgeen 19 Light Poster

As I understood Monsters.size() is monster count in whole map. If it is so - it is very inefficient code. I would do instead something like that:

#define CELL_WIDTH 40
#define CELL_HEIGHT 40
#define M SCREEN_WIDTH/CELL_WIDTH
#define N SCREEN_HEIGHT/CELL_HEIGHT
List* map_grid[M][N];
// in player and monster movement code add this
map_grid[object.grid_row][object.grid_col]->remove(objIndex) // clear wherever object was before
object.grid_row = object.positionX/CELL_WIDTH;
object.grid_col  = object.positionY/CELL_HEIGHT; 
map_grid[object.grid_row][object.grid_col]->append(monster.Index) // aka. your monster index i
/* now after button press 
instead of for(unsigned i = 0; i < Monsters.size(); i++)
do this
*/
for(int i = Player.grid_row-K; i<Player.grid_row+K; i++) {
  for(int j = Player.grid_col-K; j<Player.grid_col+K; j++) {
    for(/*iterate through all monsters at map_grid[i][j]*/) { 
      if(Collision(Monsters.at(currentMonster), Player);
      // ... do what you like here
    }
  }
}
// only think How to set constant K. It can be some small number.
// Or you can program it to be related to maximum possible monster size in terms of grid cell count.

That is. Definitely after implementing this, your program should run faster, because instead of looping through ALL monsters you will loop only through nearest cells (nearest monsters) around player. That's a big difference in perfomance. Also carefully choose container of monsters at cell. It can be that LIST dynamic insertions/removal will compensate some perfomance gain with this solution. So read what container has fast insertions and fast removals - and use it instead of List.

Good luck!

Thank you all guys!

Pynolathgeen 19 Light Poster

No, I mean code which executes Collision() function.

Its called every time a walk-button or attack-button is pushed on the keyboard, its just 2 lines of code, something like this:

switch(Key) {

for(unsigned i = 0; i < Monsters.size(); i++)
if(Collision(Monsters.at(i), Player1) == true)
Player1->Collision[Player1->GetDirection()] = true;

//handle keys here etc.
}

[edit] This is the collision function, if you haven't seen it yet [/edit]

int Collision(CHARACTER* object1, CHARACTER* object2)
{
D3DXVECTOR3 pos1 = object1->GetPosition();
D3DXVECTOR3 pos2 = object2->GetPosition();

RECT a, b, *des;
a.left = pos1.x;
a.right = pos1.x + object1->width;
a.top = pos1.y;
a.bottom = pos1.y + object1->height;

b.left = pos2.x;
b.right = pos2.x + object2->height;
b.top = pos2.;
b.bottom = y2 + object2->height;

return IntersectRect(des, a, b);
}

But the problem is that the character can walk through objects when, for example, pushing left and up right after each other.

~Thanks for your time already :3.

Pynolathgeen 19 Light Poster

It's more interesting to me How you pass objects for collision detection routine ? I'm asking because routine for choosing which objects to pass into

int Collision(CHARACTER* object1, CHARACTER* object2)

this function also very important for perfomance issues. It can be that it is more important than collision detection itself.
Can you put that routine code here?

You mean the CHARACTER class code?

Pynolathgeen 19 Light Poster

I have gotten the Side by Side config problem before. I made a simple program to modify the Windows XP registry Hive files using the Win32 API and it worked fine on my laptop (The comp that I created it on) However on some computers and in a PE enviroment I would get a side by side error. I believe it happens when you dont have the correct C++ runtimes installed, that is just an educated guess though because I actually never figured it out completely

But do you know why it only tells it at certain programs? Might it be InitCommonControls()? o_o.

Pynolathgeen 19 Light Poster

I think it's possible , I made one in visual c++ ;
Tutorial for Visual C++
Progress Bar Tutorial

Oh that is MFC. I forgot to mention I do it in API o_o. I already know how to create it etc. I just want to know if it is possible to paint an image on it ;O.

Pynolathgeen 19 Light Poster

Hello, I'm programming this patcher for my upcoming 2D Game, called Argyus Online. When I compile the patcher it works on my computer but when I execute it to my moms laptop, it give me some error.

I can't translate it to english but I think its something with the Side by Side configuration. Are there any common problem that might be causing it?

Sorry if I've been unclear, I never actually had this before and don't know where to start. I can debug it, but then I have to upload it with a single change in the code and download it at my moms laptop, and that till I found the error, which is pretty unpractical.

Thanks.

Pynolathgeen 19 Light Poster

lol'ed.

Pynolathgeen 19 Light Poster

Hello,
I created a fully working progress bar for my 2D Game patcher.
I have a question,
Is it possible to have an Image painted on the progress bar?
I know its possible in VB but I wanna try it in C++. I could find any results using Google.

Thanks!

Pynolathgeen 19 Light Poster

I don't understand that code, put it between code syntax plox.

Pynolathgeen 19 Light Poster

I know absolutely nothing about win32API and DirectX but...

The keyword "new" generates a pointer to the specified class. How is the variable DirectX defined? Is it some sort of pointer, and if so, is it the correct type of pointer?

DIRECTX* DirectX = 0;

Its defined like that.

You might want to check that SetWindowLong() actually succeeds. And while you are at it, you might switch to SetWindowLongPtr() altogether (it supersedes the former).

Its succeeds.

But I know where the error is, I just don't know WHY it is there. I mean,

DirectX = new DIRECTX(MainWnd);

Should call the constructor. But the constructor is not doing anything yet and it already crashes.

Pynolathgeen 19 Light Poster

The runtime code calls abort() (or perhaps even your own code?).

Which compiler/IDE/OS you are using?

Nah I already found the problem. When outside the debugger, I forgot to initialize some pointer and that it why it crashes. I've not been able to fix it just yet, though.

Pynolathgeen 19 Light Poster

is not calling :


but

DIRECTX::DIRECTX()

so we can't see where the problem is.
There may also be issues in calling your variable & class directX, etc

Woops that is an error. I changed it to test if it maybe calls the DIRECTX::DIRECT() instead of DIRECTX::DIRECTX(HWND Window) =P. -edits-


edit: Damn can't edit the post anymore >_>.
Anyway it has to be

DirectX = new DIRECTX(MainWnd);
Pynolathgeen 19 Light Poster

Well, I don't know if it fixes your error but:

char user[6], pass[6], username[6], passwrd[6], KazzyB;

You declare KazzyB as a char, and pass is an char with a array of 6.

if (pass = KazzyB)

else if (pass != KazzyB)
etc..

You are comparing an char with a char[6].

Pynolathgeen 19 Light Poster

My program keeps crashing when not in debugging mode. So now i'm debugging manually, or well, log everything to find where it is crashing

Oldproc = (PROC)SetWindowLong(Childs[1], GWL_WNDPROC, (DWORD)EditProc);
	cout << "Oldproc\n";
	SetFocus(MainWnd);

	cout << "SetFocus() Done\n";

	cout << "DIRECTX:\n";
	DirectX		= new DIRECTX(); // Creating DirectX
	cout << "DirectX = new DIRECTX(MainWnd);\n";
	Background	= new CHARACTER("Background"); // Creating background
	cout << "background\n";
	Player1		= new CHARACTER("Player"); // Creating Player
	cout << "player1\n";
	Notices		= new CHARACTER("Notice");
	cout << "notice\n";

Due to that, I know that the error is somewhere in the DirectX Class.
But the strange thing is, the last message I get is

DIRECTX:

And no more. I should get some more because it is not possible that the function begins and immidiatly crashes without doing anything:

DIRECTX::DIRECTX(HWND Window) {      
	cout << "DIRECTX::DIRECTX\n";
	this->counter		= 0;
	cout << "DIRECTX::counter\n";
	this->DXWindow		= Window;
	cout << "DIRECTX::DXWindow\n";
	this->Interface		= 0;
	cout << "DIRECTX::Interace\n";
	this->Device		= 0;
	this->Sprite		= 0;

	InitInterface();
	cout << "DIRECTX::InitInterface();\n";
	InitDevice();
	cout << "DIRECTX::InitDevice();\n";
	InitSprite();
	cout << "DIRECTX::InitSprite();\n";

}

Someone got an idea on what is happening? T_T. I'm almost killing myself, but I really want to finish the game before that XD!

Pynolathgeen 19 Light Poster

Its not about the dialog though. I got it more than once in my life and I don't look at it anymore. I just mentioned that I got the error on the commandline instead of the dialog, which I never really had before. Anyway, thanks for you help and I will try to fix it. Well try.. I actually HAVE to xD. I want to publish my game after the spring break or something. Thanks alot!

Pynolathgeen 19 Light Poster

You don't get WHAT dialog?

Nick is correct. The possibilities are endless. You have to track it down somehow. If it's running on a server, it may be harder to find (and it might not). You need to find out exactly where it's happening. If there is some way to use a debugger and stick breakpoints in, do it. If not, I generally take a spray paint can and write "Vern was here 1", "Vern was here 2", Vern was here 3" all over my program until I find that if "Vern was here 2" prints, but not "Vern was here 3", something may have happened between 2 and 3. Then I experiment further till I nail it down.

But there's nothing in the code that jumps out and says "A HA!", at least not to me.

The windows dialog when something crashes. You know, the "Send report, don't send report" thing.
Anyway, I know how to debug so I'm gonna do that then. I was just asking, maybe you had it before and how you fix it.

Thanks alot for your time and ill try to figure it out!

Pynolathgeen 19 Light Poster

Oh btw, it prints the error on the Command line, I don't get that Dialog =P. Maybe it is important to tell?

Pynolathgeen 19 Light Poster

Oh my fucking god.

MyrtleTurtle commented: That wasn't very helpful, was it? +0
Fbody commented: Worthless...If you're going to post, at least try to help. +0
Pynolathgeen 19 Light Poster

I had the same, but in DirectX. In DirectX I can't seem to get the image scaled that it matches the RECT it uses.
First try to get a bigger RECT, increase it if its too small and decrease when too big. (I don't know IF one uses RECT's with Allegro since I don't know Allegro).

Pynolathgeen 19 Light Poster

Dozens of options...
Most commonly:
- Writing in memory you didn't reserve
- deleting memory you didn't claim

But without seeing some code, it's a guessing game.

Ill post the code where I think it is coming from:

case c_Move:
	temp = NULL;
	temp = Client->GetPlayerInfo(args[0]);
	if(temp == NULL)
		cout << "Failed to get info\n";
	else
		try {
			temp->SetPosition( atof(args[1]), atof(args[2]) );
		} catch(exception& e) {
			cout << "Exception in c_Move: " << e.what() << endl;
			}
	break;

// This is the function where it tries to get the PlayerInfo
CHARACTER* CLIENT::GetPlayerInfo(char* Name)
{
	CHARACTER* returN = playerList[Name];
	return returN;
}

// This is the function where it adds an player to the list
map<string, CHARACTER*> CLIENT::AddPlayer(char* Name, CHARACTER* Character_class)
{
	map<string, CHARACTER*> asd;
	Character_class->SetName(Name);
	this->playerList.insert(pair<string, CHARACTER*>(Name, Character_class));
	return asd;
}
Pynolathgeen 19 Light Poster

I'm programming my own game at the moment, its connecting to a server and the server sends some spawn info and eventual other players who are connected.

When a player moves, and an other player is also connected, the client of Player2 crashes. I don't know what is causing this, the only error I get is:

This application has requested the Runtime to terminate it in an unusual way.

So my question is, does anybody know where this is coming from?
I already tried to add an exception there but it doesn't trigger.

Thanks alot!

Pynolathgeen 19 Light Poster

Hi there. Please use code tags from now on, it's much prettier, and makes your code a lot easier to read.

Woops, excuse me for that =P. I normally do that but I forgot it T_T.

I will try your algorithm, and post the result!

Thanks!

Pynolathgeen 19 Light Poster

Hello, I wrote a 2D game with some simple Collision Detection.

I used the function IntersectRect() but I think it's slow.
This is the code right now:

int Collision(CHARACTER* object1, CHARACTER* object2)
{
D3DXVECTOR3 pos1 = object1->GetPosition();
D3DXVECTOR3 pos2 = object2->GetPosition();

RECT a, b, *des;
a.left = pos1.x;
a.right = pos1.x + object1->width;
a.top = pos1.y;
a.bottom = pos1.y + object1->height;

b.left = pos2.x;
b.right = pos2.x + object2->height;
b.top = pos2.;
b.bottom = y2 + object2->height;

return IntersectRect(des, a, b);
}

Do anyone know some algorithm? D:

Pynolathgeen 19 Light Poster

Oh nevermind! I completly understand now!
I really want to thank you!

Thanks alot dude, you helped me out!
~Solved

Salem commented: Thanks, good luck - and enjoy! +19
Pynolathgeen 19 Light Poster

What if I add some kind of delimiter in my packets like ";" or "$" and I scan for that so I know the packet ends, do you think that will work?
I'm trying getting it to work but I wanna know if it is a waste of effort.

Thanks alot!

Pynolathgeen 19 Light Poster

Also why should I make a new one? I check all lengths of packets and they were equal to the strlen's. o-o.

Edit:
Nevermind, I just read your above post. Thanks alot man, if I get this working, ill message you :3.

Pynolathgeen 19 Light Poster

Alright thanks.
Would it be a good way to send every packet, byte by byte?
And receive it, byte by byte?

Pynolathgeen 19 Light Poster

> Recvbuffer[receivedBytes] = 0;
I'm going to take a stab and think that you have char RecvBuffer[1000];
- you're screwed if recv() completely fills the buffer, and the \0 lands out of bounds
- you're screwed if recv returns -1, and you scribble off the other end instead.

They are 255 bytes.

So what you are saying is that I need to redo my Recv() function because it might only get parts of the message?

Pynolathgeen 19 Light Poster

> packet = Client->Recv();
Can you post the code for Recv() and Send()?

Oh sure, here you go.

char* CLIENT::Send(char* Format, ...) 
{
	va_list ap;	      // For arguments
	va_start(ap, Format);
	vsprintf(this->Sendbuffer, Format, ap);
	send(this->Socket, this->Sendbuffer, strlen(this->Sendbuffer), 0 );
	return this->Sendbuffer;
}

char* CLIENT::Recv() 
{
	int receivedBytes = recv(this->Socket, Recvbuffer, 1000, 0);
	Recvbuffer[receivedBytes] = 0;

	return receivedBytes < 0 ? "Disconnected" : this->Recvbuffer;
}

I'm sorry that i'm begging for help guys but I like everything. I thought maybe it is DirectX that manipulates the string itself, but before that I first wanted an second opinion.

Edit:
I forgot to mention that my server is not having any problems with receiving and parsing the packets. It parses the same way.

Pynolathgeen 19 Light Poster

Bump
Does no one know the answer?

Pynolathgeen 19 Light Poster

Screenshot.

Hello, I have a problem already for like a week and I seriously can't get out of it. Take a look at the screen shot.

The server sends a packet to the client to spawn an NPC. If you look to the top commandline-window, the client does recv the packet good and spawns the NPC, at first with the arguments specified. But after that, and I don't know how it comes, the NPC gets a name as PC:100 and the text he says is a "!" if you can see it.
What am I doing wrong?
Here is the code when im parsing the packets.

while(1) {
		packet = Client->Recv();
		LoadTime = GetTickCount();

		command = strtok(packet, ":");

		for(int i = 0; i < 10; i++)
			args[i] = strtok(NULL, ",");


		switch(Commands[command]) 
		{
		case c_Disconnected:
			MessageBox(MainWnd, "Disconnected from the server!", "Error:", 0);
			exit(0);
			break;

		case c_Join: {
			float endtime = (float)(GetTickCount()-LoadTime)/1000;
			cout << "Got packet in " << endtime << " seconds\n" << endl;

			cout << "Received Join\n";
			GUI::AddMessage(FLAG_SYSTEM, "Connection with the server established.");
			cout << "Name was \"" << Player1->GetName() << "\" and is now \"" << Player1->SetName(args[0]) << "\".\n";	
					 }
			break;
			
		case c_Mofd:
			if(!args[0]) {
				Client->Send("NotValid:Mofd,No message of the day specified!");
				break; // If there are some arguments empty, just exit to prevent crashes.
			}
			GUI::AddMessage("Message Of The Day", "%s", args[0]);
			break;

		case c_SpawnNPC:
			if(!args[0] || !args[1] || !args[2] || !args[3] || !args[4] || !args[5]) {
				Client->Send("NotValid:SpawnNPC,%s!", (args[0] == 0) ? "No …
Pynolathgeen 19 Light Poster

O_O!? Wow!

Pynolathgeen 19 Light Poster

Really nice, thank you! I'm programming a simple server for a game of mine and I use it to get arguments from headers :3.