Jump to content
  • Advertisement

Thar

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

103 Neutral

About Thar

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. Thar

    C++ 2 independent while loops

    Threading can be a good thing if you really need it, be careful though as it is a daunting prospect to place into your game and many can run perfectly fine without the complexity needed. A lot of times, placing things like your draw function in its own thread *can* be dangerous if it is not timed properly, especially upon exit of your program, so be conscious of what is happening in your main thread versus your other threads at any given time. This one is a good foundation to get started.... http://www.devarticl...threading-in-C/ ... and since multi-threading, especially when dealing with manipulation of shared variables and the like require locking down, you will need to learn about mutexes as well. http://www.paulbridger.com/mutexes/ Just a quick google search brought up both of these for me when I was looking, but I bookmarked them because they helped me. Multi-threading requires a lot of planning and understanding of the data you are manipulating, less you come up with errors or worse, cause your program to deadlock.
  2. Hey Erik, thank you for the reply. You mentioned to "include winsock2.h before winalleg.h", I cannot do that or I get the errors listed below. The people on the other thread I was looking at advised the same thing to the other person and they got these errors as well. When it is put in the order I have them in, it actually compiles and runs perfectly fine. Regardless, I think I understand what you are saying in regards to how the includes work. I just am not sure what about that define causes it not to be included twice but will accept it as 'it is just how it is.' Thanks! [font="Consolas"][size="1"][font="Consolas"][size="1"]c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(581): error C2371: 'BITMAP' : redefinition; different basic types c:\allegro_sdk\include\allegro\gfx.h(258) : see declaration of 'BITMAP' c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(4338): error C2229: struct 'tagDIBSECTION' has an illegal zero-sized array gui.cpp c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(581): error C2371: 'BITMAP' : redefinition; different basic types c:\allegro_sdk\include\allegro\gfx.h(258) : see declaration of 'BITMAP' c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(4338): error C2229: struct 'tagDIBSECTION' has an illegal zero-sized array gameHandler.cpp c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(581): error C2371: 'BITMAP' : redefinition; different basic types c:\allegro_sdk\include\allegro\gfx.h(258) : see declaration of 'BITMAP' c:\program files\microsoft sdks\windows\v7.0a\include\wingdi.h(4338): error C2229: struct 'tagDIBSECTION' has an illegal zero-sized array [/font][/font]
  3. Hey there, Details: C++, Allegro 4.2 utilizing multi-threading and network sockets through WinSock. Visual Studio C++ 2010 My overall question is why does the addition of the #define _WINSOCKAPI_ line make my program work? I found the solution on a website but I cannot figure out for the life of me what makes this define actually cause my code not to explode. #include "allegro.h" #define _WINSOCKAPI_ #include <winalleg.h> #include <WinSock2.h> This only seemed to happen when I included both Allegro and Winsock2 together. My game server does not use Allegro at all and runs fine (Since it just handles messaging and data control). My client code, though, uses both Allegro and Winsock and has this problem. The code works positively fine now, with the #define line. I found the solution on a website but they did not explain why it worked (I am sure it is something very basic that I just cannot place.) The original problem, without that line, blows up with the following: c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(91): warning C4005: 'AF_IPX' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(460) : see previous definition of 'AF_IPX' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(131): warning C4005: 'AF_MAX' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(479) : see previous definition of 'AF_MAX' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(168): warning C4005: 'SO_DONTLINGER' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(402) : see previous definition of 'SO_DONTLINGER' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(212): error C2011: 'sockaddr' : 'struct' type redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(485) : see declaration of 'sockaddr' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(390): error C2059: syntax error : 'constant' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(390): error C3805: 'constant': unexpected token, expected either '}' or a ',' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(524): warning C4005: 'IN_CLASSA' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(287) : see previous definition of 'IN_CLASSA' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(530): warning C4005: 'IN_CLASSB' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(293) : see previous definition of 'IN_CLASSB' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(536): warning C4005: 'IN_CLASSC' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(299) : see previous definition of 'IN_CLASSC' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(547): warning C4005: 'INADDR_ANY' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(304) : see previous definition of 'INADDR_ANY' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(549): warning C4005: 'INADDR_BROADCAST' : macro redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(306) : see previous definition of 'INADDR_BROADCAST' c:\program files\microsoft sdks\windows\v7.0a\include\ws2def.h(583): error C2011: 'sockaddr_in' : 'struct' type redefinition c:\program files\microsoft sdks\windows\v7.0a\include\winsock.h(312) : see declaration of 'sockaddr_in' ... plus many, many more. Thank you in advance for your help! John
  4. Thar

    C++ Text Input

    Okay, so in case anyone else is looking into this problem, I wanted to take a few moments to explain this one as it took me just a bit to figure out. First of all, if you are using Allegro 4.something, you can find examples of the code under ..Allegro/examples/ and they will be in the two files "exgui.c" and "excustom.c" While I did not look very hard through the files in higher versions, like 5, those two files do not exist (which is what the manual points to) Anyway! I wanted to go over a little bit how this works because I was stumped for a bit until I figured it out and how it behaves. I am going to use the code that they supply as an example: #include "allegro.h" #define LEN 32 char the_string[(LEN + 1) * 6] = "Change Me!"; DIALOG the_dialog[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ // { d_clear_proc, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, NULL, NULL, NULL }, { d_edit_proc, 12, 82, 256, 48, 255, 0, 0, 0, LEN, 0, the_string, NULL, NULL }, // { d_check_proc, 12, 12, 161, 49, 255, 0, 't', 0, 0, 0, "&Toggle Me", NULL, NULL }, // { clock_proc, 242, 12, 64, 64, 255, 0, 0, 0, 0, 0, NULL, NULL, NULL }, // { change_font_proc, 12, 142, 141, 49, 255, 0, 'f', D_EXIT, 0, 0, "Change &Font", NULL, NULL }, // { d_button_proc, 162, 142, 141, 49, 255, 0, 0, D_EXIT, 0, 0, "Exit", NULL, NULL }, { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; This is the setup for it. While the example shows one of each of the buttons (You can see them built into the_dialog), I have notated out all the ones I was not using. According to the help files, the last one is terminating the array. (The one titled NULL) Each of the ones I have commented out are actually other objects. Each of those values are positions, colors, and values to display. This is where I had to do a bit of learning. Unfortunately their example really only works if you want the text box to mess everything else up allegro does. They advise utilizing "do_dialog( )" by itself in the example and this just did not work for me. What I learned is that when the text box is active, until it is finished (by the esc key) or it is manually shut down, it will persist and stop the program. I assume you could do some kind of multithreading for this if you really wanted to, but yeah. Too convoluted, instead they offer additional support through other functions that they do not warn you about until you peck around: int main(void) { // Make sure you initialize allegro as well as your mouse. DIALOG_PLAYER *dPlayer = init_dialog(the_dialog, -1); if(!update_dialog(dPlayer)) { // Do what you will with the input data shutdown_dialog(dPlayer); } } This is in comparison to the way the examples display it as: int main(void) { // Make sure you initialize allegro as well as your mouse. do_dialog(dPlayer, -1); } This of course works, to an extent and maybe if I was more savvy with these things I could figure out a way to utilize it, but without the shutdown_dialog() being called, I found that both mouse pointers (I have my own custom cursor) was being displayed and that the box itself would not disappear from the screen. Calling init_dialog and shutdown_dialog seemed to be the way to go. You can add more objects on your screen by adding more lines to the "the_dialog" array. Hope this helps someone else that might be looking for this at some point and thank you everyone again for your very fast help. John Edit: PS: I am not presuming to say Allegro, the examples, or the manuals are bad! Just that I did not understand them completely in my early beginnings of programming. I re-read my post and thought it might have sounded snobbish, was not meant to be! I would have gotten no where without the manual, examples and help from people here and examples through google searches.
  5. Thar

    C++ Text Input

    SimonForsman, Thank you very much. I would have never found that one by the name on my own. I have been wracking my brain for a while. Much nicer than my big ugly block of code that I can now delete. I really appreciate it. Yewbie, Thanks for your reply as well. If I have trouble with the bit from Allegro, I will totally push on to yours. I see a lot of form data in there which I am not using at all (Though I am using windows, so I could build around it. I am not too worried about multi-platform support yet! John
  6. Thar

    C++ Text Input

    Hi there! Brand new to the forum, but I have been using the tutorials here for a while. I am building a game completely in C++ utilizing the Allegro libraries. I have had a rather successful run but I have run into a little roadblock I was hoping someone might be able to help me with. I have created a client-server style game utilizing winsock and I am to the point where I have been building player data that is saved, due to the fact that multiple players will be logging in at once and since I want them to have their data persist in the world, I want to give each player their own unique login. I have set all of that up in the backend. So getting them to enter it right now is a very ugly, blocky group of code that I have that basically works but I figured there must be something more simplistic out there, but not as simplistic as CIN >> ... Think of this like when you log into a MMO like World of Warcraft, they have those two little text boxes were you can manipulate them with mouse clicks and such. I have seen windows forms, but was unsure that would be an acceptable approach as I am not utilizing forms, my entire game is built displaying bitmaps and the like. So, my question is this: Does anyone know of anything, utilizing C++, that they can point me to that I might be able to use in regards to a clickable, manipulatable textbox akin to those that you could build with any standard windows form (Like in Access) or... can a textbox just be placed utilizing windows forms without overlaying everything else with some kind of windows-looking box? Sorry if this is convoluted and I appreciate the help ahead of time!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!