• Content count

  • Joined

  • Last visited

Community Reputation

105 Neutral

About robwenwzrdhat

  • Rank
  1. I am making a game using SDL 1.2 for the cross-platform benefits. I use openGL calls for all the rendering. I have called   SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); before setting SDL video mode, and when I call get_attribute after everything is set up, a "1" is returned for success. In addition, if I manually configure the environment variable via an "export" of the vsync variable, then SDL properly says that the environment variable has overridden SDL settings and that Vsync is on. Everything says that vsync is on and works, but my game still stutters in Linux... In Windows, the game also stuttered until I added the swap_control and it became smooth as butter.   This made me believe that something was wrong fundamentally with my loop, as I read that "A good game loop will provide the delays necessary to make Vsync unnecessary" So I offer to you my delay method:   if((1000/FPS)>(SDL_GetTicks()-start_time)) { SDL_Delay((1000/FPS)-(SDL_GetTicks()-start_time)); //Yay stable framerate! } I had a different one, but clipped this from the internet thinking maybe that was my problem. It changed nothing. the start_time is at the beginning of the while loop, and the FPS is set to 50 or 60, tried both. Below is the code I use to set up my SDL video mode: SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE); I have also tried using HW_ACCEL, SWSURFACE, and several other settings.   The following is just standard setup for 2d opengl glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f); glMatrixMode( GL_MODELVIEW ); glEnable( GL_TEXTURE_2D ); glLoadIdentity(); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glShadeModel(GL_SMOOTH); glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ); This is pretty much all the code that goes into setup. Again, it works beautifully in windows now that I have added the vsync, but it behaves the same in Linux (Ubuntu 12.10) regardless of the vSync being set. Also, I have gone through compiz settings to try enabling vsync, triple buffering, and other opengl options. The enabling and disabling of these options ALL had no effect on my game's small stutter. ----------------------- I'm going to ask this as an aside, but it isn't the main focus of what I want from this post - so please only contribute to this part of the question if you have substantial knowledge of both versions of SDL and can offer an appropriate opinion for a 2d game (platformer).... With the recent release of sdl 2, should I upgrade to it? My engine is set up so that I can replace it without too much trouble and I am at the beginning stages of making my game still. I know nothing at all of SDL2, but am decently familiar with 1.2. I wouldn't even use SDL were it not for the fact that I don't want to deal with wrapping OpenGL for cross platform call. I use SDL right now for event handling, image loading of PNGs and converting them to 32bit ints for gl textures, and I will eventually use it for music.
  2. C++ One header to rule them all

    [size=2]Thank you very much for all of your responses! I knew this was the place to go to. I really appreciate it, and I will avoid using the "include everything" header from now on.[/size][quote] There was one guy who used to hang around here, I forget his handle, who actually advocated this, as long as the master header was a pre-compiled header. He said that it actually improved compile times for large projects even if the pch had to be rebuilt every time anything was modified. I don't agree with him, but there are people out there who think otherwise. Going back to disadvantages, keep in mind that a master header's effects may extend beyond just compile times. Every compilation unit will generate it's own copy of any global variables with internal linkage or inside anonymous namespaces as well as inline function definitions and potentially language support structures such as virtual function tables. Some linkers can merge/discard duplicate copies of some of these, but some cannot and other variables cannot be discard because the language prevents it. One particular case is global variables with creation side-effects designed to work around the static initialization order problems like the Zerob counter. Then there are the inevitable problems with identifier pollution, such as the ever so fun preprocessor definition issues that can arise if you force every single file in your project to include windows.h. Some of the preprocessor changes are well known and easy to avoid, like the regular all-caps identifiers. Some regularly bite even people who know about them like min and max. Others are just obscure out of the blue PITAs like rad0. [/quote] I especially appreciate this response. I was looking for a concrete reason as to why this would be a bad habit, but have been unable to find one. Thank you. I will go and eat crow now! [quote] It is an awful habit, and it's something you should unlearn as soon as possible. The good practice rules are this: For header files: * Minimise the number of includes to the absolute bare minimum (i.e. for base classes and member variable types only). * Forward declare classes as much as possible to reduce the number of includes. * To solve extreme build time problems, consider using the pimpl idiom. For source files: * Include the class header * Only include additional headers as and when they are needed. [/quote] [color=#1C2837][size=2]Thank you for providing me with appropriate practice rules as well. Everybody's experience is much appreciated. [/size][/color]
  3. My question involves header files in C++. I currently have a few different classes and I separate them into a .h and a .cpp (such as regexClass.h and regexClass.cpp) I have one header called theHeader.h and it includes all of my other headers: [code] #pragma once // or I use ifndefs as well here #include <iostream> #include <fstream> #include <string> #include "regexClass.h" #include "classificationClass.h" enum fileType { ZIP = 0x4034b50, GZIP = 0x88b1f, SEVENZIP = 0xafbc7a37, BZIP = 0x39685A42, }; [/code] when I build classifcationClass.cpp it requires access to the regexClass.h...... Instead of including regexClass.h, I just include theHeader.h. [code] #include "theHeader.h" using namespace std; classificationClass::classificationClass() { init(); } classificationClass::init() { regexClass *theRegex = new regexClass(); //I can create a regexClass without having to "#include "regexClass.h" up at the top, since it is already included in "theHeader.h" if(theRegex.match(ZIP, filePath)) cout<<"Victory"<<endl; } [/code] This grants classificationClass.cpp access to regexClass, <iostream>, <string>, etc. without me having to re-include everything all over again. Since the compiler will only include the files once, this code would work and compile just fine. The other crucial element to this working, is the order of file inclusion. classificationClass uses a regexClass object, thus "regexClass.h" is included in "theHeader.h" before "classificationClass.h" is. My coworker stresses to me that this is a bad programming practice, and wants to copy my "theHeader.h" includes into each of my separate class .h files. Is it bad practice to do this? Or am I just that awesome? Thanks