Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 179 180 [181] 182 183 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887932 times)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2700 on: July 25, 2012, 11:00:16 pm »

Whoops, don't know how I missed that. I think you also need to define an operator==, but I think you should also change the <= to < in operator<.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2701 on: July 25, 2012, 11:04:48 pm »

Whoops, don't know how I missed that. I think you also need to define an operator==, but I think you should also change the <= to < in operator<.

Tried both of those, it doesn't work. With either < or <=, sometimes it works, but it usually produces bogus results.
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2702 on: July 25, 2012, 11:12:24 pm »

RulerOfNothing, that was a little over my head, but ok, SO
I have the function

SetWindowPos();

would it be something like this?

SetWindowPos(SDL_GetWMInfo(SDL_SysWMinfo *window), HWND_TOP, progx, progy, progw, progh);

where progx/y is the position of the window and w/h are the width and height of the window.
or am I just completely wrong on that?

I'm thinking about just taking off the noframe tag,  seems like it's going to be more trouble than it's worth. or idk, I might keep it, either way I'd like to know how it's done in case I ever need to in the future.

Also, i'm on SDL 1.2.15  should I switch to a newer version?
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

eerr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2703 on: July 25, 2012, 11:19:16 pm »

Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2704 on: July 26, 2012, 01:44:28 am »

Valid_Dark, I believe switching to version 2.0 might be a good idea, but with SetWindowPos you want to use it like this:
SDL_SysWMinfo info;
SDL_GetWMInfo(&info);
SetWindowPos(info.window,HWND_TOP,progx,progy,progw,progh,0);
Logged

Mini

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2705 on: July 26, 2012, 01:53:46 am »

Hey, I've come across yet another problem that makes no sense at all. multimap::count is returning bogus values, and it's probably because of a custom class being used as the keys. I'm supposed to give the class an operator< function, but I'm not sure what to do with it. Everything I try either fails in most situations or produces a crash.

Spoiler: entire program (click to show/hide)
What you need to do is put the operator overload inside the class. See http://www.cplusplus.com/doc/tutorial/classes2/.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2706 on: July 26, 2012, 03:03:11 am »

Hey, I've come across yet another problem that makes no sense at all. multimap::count is returning bogus values, and it's probably because of a custom class being used as the keys. I'm supposed to give the class an operator< function, but I'm not sure what to do with it. Everything I try either fails in most situations or produces a crash.

Spoiler: entire program (click to show/hide)
You have to overload the < operator inside the class definition of the custom class your multimap has to use. Also, your comparison algorithm was faulty. Try this:
Code: (C++) [Select]
#include <map>

using namespace std;


struct SimpleVec3{

float x , y , z;

SimpleVec3(float _x , float _y , float _z): x(_x), y(_y), z(_z) {};

bool operator <(const SimpleVec3& b) {
return x < b.x || (x == b.x && y < b.y) || (x = b.x && y = b.y && z < b.z);
}
};

int main(){

unsigned int count;


multimap<SimpleVec3 , float> mmap;
count = mmap.count(SimpleVec3(-1 , -1 , 1));
// count is now 0

mmap.insert(pair<SimpleVec3 , float>(SimpleVec3(0 , 55 , -0.1f) , 42.0f));
count = mmap.count(SimpleVec3(-1 , -1 , 1));
// count is now 1, but it should be 0


return 0;

}
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2707 on: July 26, 2012, 04:32:38 am »

When I move the < operator inside the class, I get a massive compile error:
Code: [Select]
error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const SimpleVec3' (or there is no acceptable conversion)I was getting this error before, when I had it inside the class, and that's why I moved it outside of the class.


Code: [Select]
return x < b.x || (x == b.x && y < b.y) || (x == b.x && y == b.y && z < b.z);

This comparison algorithm is the only thing I changed, and it seems to work perfectly now. I don't understand what's going on, but it works! Thanks. :S
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2708 on: July 26, 2012, 04:41:47 am »

I'm not sure about it either, but I believe that multimap has some logical requirements that any comparison function of key values must fulfill. Incidentally, there is apparently something called an unordered_multimap that probably would have allowed you to avoid all this trouble (not sure how I missed that earlier).
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2709 on: July 26, 2012, 06:23:25 am »

I'm about to go to sleep, so instead of looking up what i'm going to be working on, I figured I'd just ask so I don't waste an hour or so looking it up.
Ok, so I have 2 RGB surfaces, each with a BMP loaded to them, and I have a PNG alphamap loaded to a third surface. I need to apply the alpha levels of the PNG to one of the other surfaces, then convert the whole thing into a BMP.

ok, so I convert one of the RGB to RGBA, but how would I apply the alpha level of the PNG to the surface?
and only the alpha level, and not the RGB values.
and while I'm at it, how do I convert the RGB to RGBA?

When I wake up in 8-10 hours i'll check here before looking it up, so feel free to save me some time. 
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2710 on: July 26, 2012, 06:43:22 am »

To convert a RGB surface to a RGBA surface, use SDL_ConvertSurface which takes 3 parameters: the surface to be converted, the format you want to convert to, and flags for the new surface, and returns a copy of the input surface in the new format. To extract alpha-channel information from a surface, you need to use the pixels member of the surface (you may need to lock the surface before doing this) and take out the part of the pixel data that is the alpha using something like this:
Code: [Select]
SDL_PixelFormat *fmt;
SDL_Surface *surface;
Uint32 temp, pixel;
Uint8 alpha;
fmt=surface->format;
SDL_LockSurface(surface);
pixel=*((Uint32*)surface->pixels)
SDL_UnlockSurface(surface);
temp=pixel&fmt->Amask; /* Isolate alpha component */
temp=temp>>fmt->Ashift;/* Shift it down to 8-bit */
temp=temp<<fmt->Aloss; /* Expand to a full 8-bit number */
alpha=(Uint8)temp;
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2711 on: July 26, 2012, 05:14:33 pm »

I'm not sure I understand that, I've never used or even seen half of that stuff, I'm still very new to SDL, and really new to programming in general.
Can you help me write it as a function?


I'm sorry for being so dumb and not understanding things, you make it sound so easy,
also, check your PM's.
Thank you again for all your help.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2712 on: July 26, 2012, 07:49:51 pm »

Finally got it working, here is the function to copy the alpha level of one surface onto another,
Spoiler (click to show/hide)
Thank you again RulerOfNothing.
« Last Edit: July 27, 2012, 04:24:30 am by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2713 on: July 26, 2012, 08:09:44 pm »

I'm finally getting to program at work. It's fun, and challenging, because I have to program under certain limits. Those limits being only Python, and only the standard library. The task? Retrieve web pages and parse their contents, putting the valuable bits into a text file.

Regex ho!

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2714 on: July 27, 2012, 12:56:59 am »

Which is considered a valuable bit though? 0? 1?
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.
Pages: 1 ... 179 180 [181] 182 183 ... 796