Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Vortez

Member Since 15 Jun 2007
Offline Last Active Nov 20 2014 05:42 PM

Topics I've Started

Something odd about set_difference()

06 September 2014 - 01:13 PM

Hi, i've just refactored a class that originally used a STL set in order to keep track of the possibles values for each cell in my sudoku solver, by using a WORD instead to store values from 1 to 9, since i used the exact same interface(almost), no code changes we're required elsewhere.

 

Everything worked fine the first shoot except for the set difference operation. I got it to work, but something is puzzling me. First, let me show you the old code

/***************************************************************************************************************/
// Perform a difference operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator-=(Possibles &s)
{
	Possibles TmpSet = *this;
	possibles.clear();

	set_difference(TmpSet.GetSet()->begin(), TmpSet.GetSet()->end(), s.GetSet()->begin(), s.GetSet()->end(), inserter(possibles, possibles.begin()));
	return *this;
}

/***************************************************************************************************************/
// Perform an union operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator+=(Possibles &s)
{
	Possibles TmpSet = *this;
	possibles.clear();

	set_union(TmpSet.GetSet()->begin(), TmpSet.GetSet()->end(), s.GetSet()->begin(), s.GetSet()->end(), inserter(possibles, possibles.begin()));
	return *this;
}

/***************************************************************************************************************/
// Perform an intersection operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator|=(Possibles &s)
{
	Possibles TmpSet = *this;
	possibles.clear();

	set_intersection(TmpSet.GetSet()->begin(), TmpSet.GetSet()->end(), s.GetSet()->begin(), s.GetSet()->end(), inserter(possibles, possibles.begin()));
	return *this;
}

(NOTE: not sure i used the right operator sign...)

 

Then, when i emulated this with a WORD, the code looked like this:

/***************************************************************************************************************/
// Perform an union operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator+=(Possibles &s)
{
	p |= s.Get();
	return *this;
}

/***************************************************************************************************************/
// Perform a difference operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator-=(Possibles &s)
{
	p ^= s.Get();
	return *this;
}

/***************************************************************************************************************/
// Perform an intersection operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator|=(Possibles &s)
{
	p &= s.Get();
	return *this;
}

All worked fine except the -= operator.

 

For example, the first code only added the difference IN THE FIRST SET instead of both (wich is the required behavior for my game), but the 2nd example added the difference in BOTH set, wich is normal but not what i wanted. So, to fix it, i had to write some ugly code like this:

/***************************************************************************************************************/
// Perform a difference operation on the set
/***************************************************************************************************************/
Possibles Possibles::operator-=(Possibles &s)
{
	WORD w1 = p;
	WORD w2 = s.Get();
	WORD res = 0;

	for(int i = 0; i < 9; i++){
		if(((w1 & (1<<i)) > 0) && ((w2 & (1<<i)) == 0))
			res |= (1<<i);
	}
	p = res;

	return *this;
}

That way, everything work fine except the code is not like the other 2 functions, and i was simply wondering why is that? To be more clear, why can i use simple bitwise operation for 2 of the 3 operation but not the 3rd???

 

EDIT: I might not be able to respond to this thread for a few days.


My future on gamedev

31 May 2014 - 08:09 AM

Hi all, i just wanted to say that i might not be able to come here as often as i was able before, im currently looking for another place to live since my landlord is taking is appartment block back, so i have to move. I dunno if im gonna be able to have the internet after this but, we'll see.

 

When you say that an house hypoteque is lower than renting a 2 1/2 there's something seriously wrong with the economy.......


fix the tabs issue?

26 April 2014 - 04:59 AM

Something that annoy me when posting code is, when you press tab, instead of making a tab, you loose the keyboard/mouse focus instead.

 

Could this be fixed? And if you fix it, should as well do like vs and make it work on multiples selected lines as well, i find this feature incredibly usefull in visual studio.

But i would set up for a regular tab if that's fesable.

 

Just saying smile.png


How to get rid of this?

26 April 2014 - 02:48 AM

Hiya, i was wondering if someone could help me with a design flaw in my library's vector and matrice code. See, like i posted here, i always need to access the x,y,z part of the vector by the letter v, and m for matrices.

 

Another example would be

ApplyMatrixToVector(&p->ThrustVector.v, &p->JetMatrix.m);

It's kinda annoying to have those v and m letters appended everywhere, but im affraid to modify the code since it work perfectly well.

 

Also, I know the ApplyMatrixToVector() should be done by overriding the '*' operator but it's already overloaded for something else i think.

 

Here the source:

 

vector.h

vector.cpp

Matrix.h

Matrix.cpp

 

Thx

 

EDIT: Humm, i know the the header file look a bit strange, it was done that way to compile the library either normally or in dll for multiples languages, just don't mind the #defines (another thing to fix, i need to remove this, but that i dont need help with :) )


Need help to draw cursor properly

15 April 2014 - 09:34 AM

I noticed a small bug in my remote desktop application related to drawing the cursor of the remote machine and im not sure how to solve it. The problem is that sometime, the cursor is not drawn at the proper location depending on the cursor. Also im using a weird hack to make it work for windows 7 and above and i don't think that's the right way to do it.

 

Here's the code im using right now:

void CScreenshot::DrawScreenCursor(HDC hDC)
{
    CURSORINFO CursorInfo;
    CursorInfo.cbSize = sizeof(CURSORINFO);
    GetCursorInfo(&CursorInfo);

    static DWORD Version = WinVer.DetectWindowsVersion();
    //static HCURSOR hCur = LoadCursor(NULL, IDC_ARROW);

    DWORD CursorWidth = GetSystemMetrics(SM_CXCURSOR);
    DWORD CursorHeight = GetSystemMetrics(SM_CYCURSOR);

    POINT CursorPos;
    GetCursorPos(&CursorPos);

    // Needed for XP or older windows
    if(Version < _WIN_VISTA_){
        CursorPos.x -= CursorWidth >> 2;
        CursorPos.y -= CursorHeight >> 2;
    }

    DrawIconEx(hDC, CursorPos.x, CursorPos.y, CursorInfo.hCursor, CursorWidth, CursorHeight, 0, NULL, DI_NORMAL);
}

If the cursor is the default arrow, this work fine, but if the cursor change for, let say, the resize cursor, then it's offset a little.

 

Now, after reading this post, im pretty sure this function could solve my problem, but im not sure how to do it.

 

The question is, how do i get the icon from the current cursor (so i can call GetIconInfo() with the right cursor)?


And, why do i need to divide the cursor width by 4 in recent version of windows? It's like i have all the pieces of the puzzle but i don't know how to make them fit togeter... Maybe if i could debug this or something that could help a lot.

 

Note: The mouse click always happen at the right spot, it's just the cursor that's offset a little.

 

EDIT: I just realised im already getting the cursor from GetCursorInfo(), but im still lost on how to solve the problem. Maybe the width and height im getting are wrong?

 

Any help appreciated.


PARTNERS