|
Ever worked with window styles?
Any time you have to deal with a bit mask, you will have to use the bit operators.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Actually i havent done much with window styles. But, im learning what i need to make an Engine that will help me program a game, and it will be in windows. "I guess ill give it a shot "
Also,...
If i was programming an engine in windows, do i have to use mfc? "I dont think so, my opinion, but what would be easiest, or better?"
Thanks for your help!
~Silvershalkin
|
|
|
|
|
No you don't have to program your engine in MFC.
Actually your game engine IMO should be done in C for performance reasons. C++ allows easier/better implementation and design, but less performance i'd think anyway.
Depends on what your engine is gonna do...?
Flight simulator...? IMO....absolutely C and maybe even inline where you feel comfortable.
Board games like tic tac toe or battle ship, something with less intensive AI, Graphics and such...MFC would suffice.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
Actually your game engine IMO should be done in C for performance reasons. C++ allows easier/better implementation and design, but less performance i'd think anyway
C++ can be slower than C, but not always. For instance, if you use virtual functions it will slow down your application. But IMHO you should not give up classes, templates etc. If nothing, you can use C++ "as better C".
I vote pro drink
|
|
|
|
|
I agree for the most part, unless performance is a serious issue...I had no idea what kind of game was being developed so I couldn't really give a definte answer.
I've personally experienced code which was totally enhanced when converted to C++ because you think in a different mindset when OOP as compared to procedural C.
As far as the game is concerned I suppose it's a matter of opinion...if you like the safety and clarity of C++ and don't mind losing a few clocks it's definetly the way to go.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Other than the "this" issue (which in many cases can improve speed given that it is passed around in ECX instead of on the stack and if you don't run out of registers during optimization), I have to agree that C++ can gernerally slow things down.
In some cases it is sloppy code such as using the C3dVector + operator between two vectors when all you really need to do is add a single value to one of the coordinates.
But I have also seen other performance problems usually involving templates. (Hint, those STL algorithms that some people love and adore can be drastically slower than hand-written loops. And I am not talking about hand optimized loops either.)
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
When i say engine, i mean, i use it to build the game "I know you know that." like use it to build a 2D game. its not a first person shootup or anything, "i would use c++ to do that"
So,.. your opinion on, should i use MFC or not, i think i should "personaly"
Thanks
~SilverShalkin
Cant think bad when it comes to learning
|
|
|
|
|
If your game is just a single window I would avoid MFC, because it's not really nessecary and still carries quite a bit of overhead.
I imagine you save a bit of time avoiding the
CDC, CString etc...classes and just use SDK handles and such without much more effort on your part.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
I imagine you save a bit of time avoiding the
CDC, CString etc...classes and just use SDK handles and such without much more effort on your part.
What exactly is the SDK? "I am new, not stupid, just havent learned it yet"
But if you could tell me, i can look it up and learn how,
Thanks!
~SilverShalkin
The color swirl black on blue
Tips of white, like angels hue
touch is soft and full of life
The Rose lay still, on thee ice
Dustin Tigner
|
|
|
|
|
It stands for System (or Software) Developer's Kit. In this context, it refers to the native API (Application Programming Interface) handles (like HDC, HPEN, etc.) and functions.
|
|
|
|
|
SDK-Software development kit
It's ummm basically the generic windows functions stored in the user32/gdi32/kernel dll's (i think).
Using C and the SDK will allow more direct control over what goes on around you. One abstraction level lower than what MFC provides (I think is how you would describe it) someone will coreect me if i'm wrong.
MFC is slower and clunky because it does it's own tests and such before calling the windows API(SDK) functions.
Once you understand what MFC is and how to use it...it makes sense in most cases, but for single window apps...I would say go will C/SDK programming. However if all you've done is use Classwizard and tools, creating your message pump and handler function and class registration might be a little more verbose than what your used to.
Try looking for simple SDK examples and you'll see what I mean.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
very important for working with 'non-uniform' variable sizes through your code. For instance, if you want to combine two 8 bit chars into a 16 bit int you could use the MAKEWORD (a,b) macro provided in win32. But if you look at the source for this macro it uses bitwise operators to do so (actually uses a SHIFT and an OR):
WORD MAKEWORD(
BYTE bLow,
BYTE bHigh
);
MAKEWORD(a, b) \
((WORD) (((BYTE) (a)) | ((WORD) ((BYTE) (b))) << 8))
And many many other important uses.
- Merle
|
|
|
|
|
I can't make the my Activex control get focus in Word/Excel while using Normal view. When I turn view mode to design view it works.
Any suggestions ?
|
|
|
|
|
|
Declare variable once in .cpp file:
int g_Var;
and define it in h-file:
extern int g_Var;
Variable will be available in the file where it is declared and in all .cpp files where h-file is included.
If you include h-file with extern definition to .cpp file with the same variable, it's OK for compiler:
extern int g_Var;
int g_Var;
The same with functions:
// .cpp file:
void MyFunction()
{
// ...
}
// .h file:
extern void MyFunction();
|
|
|
|
|
Hi all,
I am attempting to use a deque as a frame buffer reading data from a serial port. When the entire frame is received, I want to use the frame buffer (the deque) to write the contents of the deque to a file, enpty the deque and start collecting data for the next frame.
The problem I am having is in writing the contents of the deque to a file. I have some experience writing to files, but I am unsure how to do this using a deque. How do I write the contents of the deque to a file??
If anyone has done this before (which I'm sure many have) could you give me a few hints.
Thanks
Merle
|
|
|
|
|
This writes a deque of int s to a file, one int per line. The extension to other types is straightworward (define the corresponding operator << ):
deque<int> dq;
...
ofstream ofs("whatever.out");
for(deque<int>::const_iterator it=dq.begin();it!=dq.end();++it){
ofs<<(*it)<<endl;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
PS: There are other, more STL-intensive ways to do this, involving inserters and stuff like that. I hope Christian will cover these subjects in his upcoming STL tutorials.
|
|
|
|
|
Or, you can use copy
ostream_iterator <int> OsIt(ofs, " ");
copy (dq.begin(), dq.end(), OsIt);
I vote pro drink
|
|
|
|
|
so nice!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks.
Actually, whenever a loop is involved with STL, chances are that there is a generic alghoritm that would do the job.
I vote pro drink
|
|
|
|
|
Heh, just being annoying
FILE *fp = fopen ("whatever.out", "w");
for (deque<int>::const_iterator it=dq.begin();it!=dq.end();++it)
fprintf (fp, "%d\n", *(it));
fclose (fp);
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Heh, just being annoying
You never are
What's the point of your code? This solution doesn't extend naturally to user-defined types. The iostream approach, on the other hand, could even be cast into a template function.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Why should it?
You are only needing to serialize integers, not the world.
Use the right tool for the job.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
You are only needing to serialize integers, not the world.
I meant to use integers just as an exmple. The guy didn't specify which kind of data he's trying to serialize. As far as I know, his "frames" could be modelled by some user-defined type.
Use the right tool for the job.
I completely agree with you. But if you're accostumed to iostream library, printf -style functions add hardly any value or ease of use. Plus, they're more inefficient.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Doh, you are right. You were the one who started talking about integers, not him.
But, he never said he wanted to use iostreams either. I use STL, but have never used iostreams because I have yet to see the benefits. I see the problem they are trying to correct with iostreams, but you tend to just trade one set of problems for another set.
As far as speed, iostreams are just a bit faster than fprintfs (1512ms compared to 1402ms). At least that is using the copy version. You can chop another 50ms off the iostream version by using a hand-written loop. However, if you don't use fprintf and just use a temporary scratch buffer formatting with itol, the time it takes to do it using fwrite drops to 781ms. Much faster than iostreams. Now, if you use the same trick with iostreams and pre-format the number into a temp buffer, the iostreams version only takes 591ms. Now, we are getting down to measuring each methods underlying performance. It seems that iostreams might have a better buffering system. Or is it. If you change the code slightly and print each integer on one line using endl and include an fflush in the fwrite version to be fair, the fwrite version now takes 3956ms where the iostreams version takes 17595ms.
So, how do the two methods compare? With the fprintf version, half your time is taken up with that fancy formatting string parsing and deciding how to format the value. In the case of iostreams there still seems to be an excessive amount of overhead just deciding how to format the value. When you compare the two, the extra overhead of parsing the fprintf format string is significant. Next, with the iostream version, it turns out those fancy STL algorithm bite us in the butt when it comes to performance. In this case we took around a 3-4% hit using them. This is consistent with other cases I have seen.
When you take all the fancy formatting out of the picture and just write raw strings to the file, performance for both the fprintf/fwrite version and the iostream version jumps significantly. However, the iostream version is still beating the fprintf/fwrite version. Or is it? It is important to remember that iostreams and fwrite operate slightly differently. If you have a case where you want to make sure the output is displayed on the screen, you have to use some type of flush (i.e. endl) with iostreams. Doing so incurs a huge hit in performance.
So, which one is faster? Neither. Depending on your application, fprintf/fwrite can be a bit slower or significantly faster. But it is also important to remember that in a real world application, the speed of the disk IO will greatly overshadow any differences in these two implementations. That is unless you do a lot of endls in iostreams when you really just need a CR. That flush can be a nasty killer.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|