Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

139 Neutral

About Sceletor

  • Rank
  1. Im working on a game project for quite a while now and now Ive finally come to the point where I need to design its networking layer. As always, the dreaded UDP or TCP question arises, and before I waste too much time due to wrong design decision, Id like to present my thoughts here and gather some feedback from you guys... Up until now, I had a monolithic application, where the server was only a bundle of gamelogic classes, but for several different reasons, Im planning to make the game online only, with a central server in the web and downloadable clients. I experimented already with a small network layer using UDP for testing in my LAN, but since package loss became apparent I have to decide now which way Ill go with networking in general. Right now I think trying to make my own reliability layer with UDP is the way to go, but the reasons against that are equally important as the reasons in favor of it. The following listing is ordered by importance. Pros UDP: [indent=1]- The engine I wrote which is used by my game is more flexible and therefore better usable by future game projects [indent=1]- With UDP, sending and listening is the same on client and server, which makes it easier to develop [indent=1]- No separate threads for connected clients or accepting connections in the server [indent=1]- I dont need to worry about message fragmentation [indent=1]- I dont need to dump my network layer.. Its tiny, but at least its doing its job so far Cons UDP: [indent=1]- My current game is a turn based strat game, which is THE standard use case for TCP in gaming [indent=1]- Reliability and ordering is provided, doing this myself in UDP might be a terrible amount of work Do you think this is the right decision or did I misjudge some points here? Using an already existing library (raknet or such) isnt really what I want to do, since I would like to write it myself (yeah, Im mad, I know..).
  2. Sceletor

    problems with random numbers

    After reading a little about random number generators and seeing that rand() is absolutely not useful for my needs, I decided to switch to boost::random, since I already have some experience with boost and am quite satisfied with it( except for the documentation, of course). @Ridynare: Theres just one project in my workspace, with only one main(), so theres no risk.. @F1N1TY: My game consist of (very) roughly estimated 50 classes, and I dont think it would help to post all the code here, so please apologize that I made a selection of what I regarded neccessary to see my problem. @ALL: I wil shift to boost::random, and so there is no need for all you nice guys to think about my problem with rand() anymore. But many thanks for all your help and suggestions!!!
  3. Sceletor

    problems with random numbers

    Quote:Original post by Rydinare I'm assuming framework.cpp is called from another main() without seeding the random # generator before calling, which is why the two values match the two pre-seeded values in the other main(). At the risk of stating the obvious, have you tried searching Google for some freely available random number generator already developed? Check out Boost.Random: Boost.Random P.S.: It appears Boost 1.35 was just released. Woohoo! [smile] Ahem... another main()? In case I get you right, there is only one main() in my project, which does seed the random generator. The two quotes in my frist post were both parts of the same stdout.txt file. @CProgrammer: I used now std::rand() and std::srand(), and I cannot see why two different kinds of rand() should be called, although my output is suggesting that. I hoped anyone here could give me an explanation for this behaviour. Oh, and one more thing: the framework class is a singleton class, maybe there are some issues with rand() in singletons?? @others: Ill check out boost::random and the other proposals after I tried to get rand() working correctly for, lets say, a day or so. Your proposals are really good, but I dont like switching over to something else as soon as I encounter a problem while programming.
  4. Im currently trying to build a random number generator for my game, and before I did it, I read a little about rand(). One of the first things I found out was that I need to call srand() with time(null) in order to pass a seed to rand(), so it doesnt return always the same order of values. After reading this, I tried to build my random number generator, but there seems to be an important point I missed, and so I wanted to ask you people here whats going wrong. My idea was to call srand() right in the main method of my game (actually as the first thing I do at all) and then have a generate_random_number(int lowerbound, int upper_bound) function in my FrameWork class. The strange thing is now, that if I call rand() in my main.cpp right after calling srand(), it returns numbers, but rather simply increasing ones, not randomly small or big.. If I call rand() now in my function in the framework class, it simply returns always the same order of random numbers, just like I never called srand(). I already searched my code for other occurences of srand(), but there are none. Code in main.cpp: #include <string> #include <cstdlib> #include <cstdio> #include <ctime> int main (int argc, char *argv[]) { std::cout << "[Main]time is: " << (unsigned int) time(NULL) << std::endl; printf ("First number: %d\n", rand() ); printf ("Second number: %d\n", rand()); srand((unsigned int) (time(NULL))); printf ("random number: %d\n", rand()); } output: Quote:[Main]time is: 1206836264 First number: 41 Second number: 18467 random number: 12108 //this is maybe 12132 the next time I run my game Code in framework.cpp: Uint32 Framework::random_generator(Uint32 lower_bound, Uint32 upper_bound) { unsigned int random_number = (unsigned int) std::rand(); printf ("[FrameWork]random number: %d\n", random_number); Uint32 dest_range = upper_bound - lower_bound; Uint32 return_value = Uint32 (lower_bound + ((Uint32) random_number % dest_range)); } output: Quote: [FrameWork]random number: 41 [FrameWork]random number: 18467 Notice that 41 and 18467 are the first numbers rand() returns without seed or seed 1... And I shortened the code and the output, so dont try to correct syntax errors, pls.
  5. Im currently using the SDL Eventsystem for my own game and I chose to create my own Message structs, which are added to an SDL_UserEvent and then pushed to the queue using SDL_PushEvent and processed in another thread (client to server or vice versa). Until now I had no problems doing so, but I started to create some classes for networking which should do all the sending stuff (locally via SDL_Events, remote via UDP) and when I try to push an Event on the Queue in these classes, the message which is part of the Event somehow changes its type: Quote:[ClientSender]Sending message of type: 0 [ClientSender]Sending message of type: 5 [Server]Received message of type: 20 [Server]Received message of type: 1 Those message types were transmitted correctly when the SDL_events containig them were pushed in class Client, but when they are passed to class ClientSender and pushed there they change their type AFTER they are pushed (I already checked their type before). The receiving class Server didnt change at all, so this leads me to the conclusion that this is some issue with the SDL_EventSystem rather than with my code. Does anybody have an idea what is causing this? I would be very grateful.
  6. Sceletor

    Eventsystem with SDL

    Has anyone here written and custom eventsystem based on SDL_UserEvent? I have several threads in my game, the most important ones are client (containing the main loop and processing all userinput and graphics) and server (doing only gamelogic stuff). What Im currently doing is writing message structs which I can put into a SDL_UserEvent and also easily serialize to send them over the internet. My question now is whats the best way for threads other than the mainloop in the client (which uses SDL_PollEvent and a gigantic switch case for everything) to check for SDL_UserEvents. My best guess is using SDL_PeepEvent in the other threads, and pushing all events that arent processed in the thread back in the queue. SDL_EventFilters seems not to be the right choice, for it doesnt filter events which were pushed manually with SDL_PushEvent. So this would be something like: //client thread while(client_running) { SDL_Event event; SDL_PollEvent(&event); if(event.user.code == 2) // 2 is client event { //further proceed the event } else { SDL_PushEvent(event); //event is not for the client, so push it back } } //server thread while(server_running) { SDL_Event event; SDL_PeepEvent(&event,1,SDL_GETEVENT,SDL_EVENTMASK(SDL_UserEvent)); if(event.user.code == 1) //1 is server event { //further proceed the event } else { SDL_PushEvent(event); //event is not for the server, so push it back } Is this an efficient way to do this? Or did I get something in the SDL documentation wrong?
  7. Sceletor

    SDL_CreateThread() and Memberfunctions

    First of all, thank you both for your replies. If I get rip-offs idea right, I'll create a class Thread which has the thread_proxy() and run() functions, and every class which has a thread has to derive from it. Do I get this right so far? And has the thread_proxy function to be in a nameless namespace?
  8. Im trying to use SDL_CreateThread() in order to have multiple threads running in my game at once. I noticed that there is a problem with calling a member function of a class, seems like SDL_CreateThread only likes global functions.... Is there a way to use some thing like void Server::server_thread(void* data) { ... } as a function for a SDL Thread? Also, can I somehow use namespaces, for instance, server::Server::server_thread() as thread function?
  9. Something trivial, just as I suspected [grin] Thx for your help!
  10. Hi, Im using SDL for a project of mine and since Im now going for networking with SDL_net, I started to wonder how I can convert normal ints to Uint16 or such and vice versa. Something like this returns really strange results, and Id like to be able to check occasionally what value a variable has [wink] Uint8 temp = 500; int another_temp = temp; std::cout << temp << std::endl; std::cout << another_temp << std:endl; I already tried static_cast<int>, but without success. Seems like this matter is so easy that Im overlooking something trivial...
  11. Im just playing aroung with some code I got from an interesting book on game programming and Im trying to adapt it for my compiler and my code style. So far I spend some time on debugging it, but since there are numerous new things that I didnt know so far in the code, I got an error which I can´t explain. The whole thing should be an event system, and the core class is the Messenger, inheriting (or implementing) the interface "IMessenger". #ifndef IMESSENGER_HPP_ #define IMESSENGER_HPP_ #include "Message.hpp" #include "IMessageListener.hpp" #include "MessageType.hpp" typedef boost::shared_ptr<IMessageListener> MessageListenerPtr; typedef boost::shared_ptr<Message> MessagePtr; class IMessenger { public: IMessenger (char const* const new_name); virtual ~IMessenger (); virtual int add_listener (MessageListenerPtr const &listener, MessageType const &type) = 0; virtual int rem_listener (MessageListenerPtr const &listener, MessageType const &type) = 0; virtual int trigger (Message const &new_message) = 0; virtual int queue_message (Message const &new_message) = 0; virtual int abort_message (MessageType const &new_type, bool all = false) = 0; virtual int tick (unsigned long max_millsec = 4294967295UL) = 0; virtual int validate_type (MessageType const &new_type) const = 0; private: }; #endif #ifndef MESSENGER_HPP_ #define MESSENGER_HPP_ #include <set> #include <list> #include <map> #include <vector> #include "IMessenger.hpp" #include "IMessageData.hpp" typedef std::vector<MessageListenerPtr> MessageListenerList; typedef std::vector<MessageType> MessageTypeList; class Messenger : public IMessenger { public: Messenger (char const* const new_name); ~Messenger (); int add_listener (MessageListenerPtr const &listener, MessageType const &type); int rem_listener (MessageListenerPtr const &listener, MessageType const &type); int trigger (Message const &new_message); int queue_message (Message const &new_message); int abort_message (MessageType const &new_type, bool all = false); int tick (unsigned long max_millsec = 4294967295UL); int validate_type (MessageType const &new_type) const; MessageListenerList get_listener_list (MessageType const &new_type) const; MessageTypeList get_type_list (void) const; private: typedef std::set<MessageType> MessageTypeSet; typedef std::pair<MessageTypeSet::iterator, bool> MessageTypeSetResult; typedef std::list<MessageListenerPtr> MessageListenerTable; typedef std::map<unsigned int, MessageListenerTable> MessageListenerMap; typedef std::pair<unsigned int, MessageListenerTable> MessageListenerMapEntry; typedef std::pair<MessageListenerMap::iterator, bool> MessageListenerMapResult; typedef std::list<MessagePtr> MessageQueue; int num_queues; MessageTypeSet type_list; MessageListenerMap registry; MessageQueue queues[2]; int active_queue_nr; }; #endif When I try to imlement the functions like this: #include "Messenger.hpp" Messenger::Messenger(char const* const new_name) : IMessenger(new_name), active_queue_nr(0), num_queues(2) { } Messenger::~Messenger() { active_queue_nr = 0; } I get the following errors: Quote:Messenger.cpp:4: undefined reference to `IMessenger::IMessenger(char const*)' Messenger.cpp:9: undefined reference to `IMessenger::~IMessenger()' Can anyone explain me whats causing this and how I can solve the problem?
  12. Im currently thinking about the network and event structure of my game (I read that event driven games make it very easy to make them multiplayer) but since Im new to these two topics, Id like some advice on how to implement it from you guys. My biggest problem at the moment is that my classes are full of pointers, which are invalid if I send them over the net, since the target machine doesnt have the same memory layout. For example, Id like to know how I could send the information stored in the map contained in this class (the map contains pointers to lists) over to another machine. I already figured out that I need a "mapinfo-event" or something like that, but I really got no idea on how to actually implement it so that I can transfer it via TCP.. And if someone knows some examples on networking with events, please tell me where I can find them (sourcecode would be good). In my books there are only vague and general examples of how to implement this, but I just lack the concept on how to design the events ... namespace server { class GalaxyMap { typedef std::map<Coordinate, std::list<Stellarobject*>, Coordcompare > Galaxy_map; typedef std::list<Stellarobject*> Stellar_list; typedef Galaxy_map::value_type map_type; public: GalaxyMap(GameInfo *new_info); virtual ~GalaxyMap(); void set_size(int new_size_width, int new_size_height); void add_item(Stellarobject *new_stellar, int new_x_pos, int new_y_pos); void remove_item(Stellarobject *curr_stellar, int x_pos, int y_pos); void create_starsystems(int number); void delete_starsystems(); bool check_pos(int x_pos, int y_pos); Stellar_list &get_list(int x_pos, int y_pos); private: GameInfo *curr_info; int size_width; int size_height; Galaxy_map curr_map; bool system_highlighted; }; }
  13. Sceletor

    Different screen resolutions in SDL

    I see, thanks for your help.
  14. Sceletor

    Different screen resolutions in SDL

    Quote:Original post by shotgunnutter Its very difficult. You can, however, easily convert from vector into normal (raster) and then blit the screen as usual. Well, that doesnt answer my question... [sad] I just red on wikipedia on vector graphics, but at first glance corel draw is the only program I know which uses vector graphics. Right now I got all my sprites as .png files, so has anyone here some idea on if I had to redo all my sprites for using vectors or is there some (comfortable) way to convert?
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!