Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

356 Neutral

About DavW

  • Rank
  1. Or perhaps more usefully (a messy example but you get the idea) class Inventory { public: std::list<Item *> items; ~Inventory() { for (std::list<Item *>::iterator i=items.begin();i!=items.end();i++) { delete (*i); } } }; class Player { ... Inventory _inventory; ... some_method() { ... _inventory.push_back(new Weapon("Sword")); _inventory.push_back(new Armor(100)); ... } }; That way the inventory list will deallocate all inventory items when the player is deallocated or falls out of scope. You will have to make sure that you do not keep any other pointers to the same inventory in a part of the program where the player may not continue to exist. A more general solution (with a small amount of extra syntax/libraries) would be to use a templated reference counting pointer class like the shared_ptr available in the boost libraries.
  2. That's a fair point actually, must've slipped my mind when I was writing them. I'll be sure to add some comments tonight.
  3. For those who are interested, I've just put up some new beginner tutorials on my website about setting up Eclipse with MinGW and SDL, and the basics of writing an SDL program. I'm also looking for any ideas or suggestions for new tutorials to write. davw.nfshost.com
  4. DavW

    Overcoming 'Sterility'

    One technique i like to use incorporating synths with ambient-style tracks is to set up 2 mics (for stereo effect) at the opposite side of the room to the computer, then record the synth tracks playing from the computer speakers through the mics. Using this mixed in fairly quietly will add some natural subtle reverb and ambience to the sound of the synths. Variations on this can also be used creatively for more unusual sounds; I once attached a speaker to length of drainpipe and placed a mic at the other end and the resulting sound was almost like a slapback delay with many reflections but little interference between them. People often undestimate or overlook the creative power of a speaker, a mic and household objects as effects processors.
  5. DavW

    How to use inverse of sin?

    just as a point of interest, the a in asin and acos etc stands for "arc" as in the alternate names for the inverse trigonometrical functions. arcsin and arccos are less common names but they remove the amibiguity between f^-1(x) and 1/f(x)
  6. DavW

    Extracting the decimal

    double number=35.049; double decimal=number-(float)((int)number); //decimal= 0.049 Would that work? edit: just looked up the modf function as described above and it seems like a better solution.
  7. I would be very interested to see a UML (class diagram) of a finished or partially-finished game project. Does anyone have one they wouldn't mind sharing or know of a source of one for study?
  8. DavW

    Skype and VoIP

    Ive just started using Skype after meaning to for ages, and I have to say I'm impressed with the system, but as usual with this kind of thing, it's usefulness grows with it's userbase. Do you think VoIP will ever become popular enough to be used exclusively instead of traditional phone systems? If so, where's the money going to come from? Skype supports itself mainly on premium services to connect to the standard phone network, and without these I'm sure it cannot be profitable.
  9. DavW

    File reading/writing problem.

    is the readfile function ever called?
  10. DavW

    Random numbers

    #include <cstdlib> int randomNumber(int min, int max) { return rand() % (max-min+1) + min; } The % operator gives you the remainder from an integer divide, and rand() gives you a random number from 0 to RAND_MAX. By combining them you can get a random number within a limit. If you want this explaining better let me know. I know it wasn't very clear.
  11. DavW

    File reading/writing problem.

    sourceified and readabilitified #include <stdio.h> #include <string.h> #include <stdlib.h> int readfile(char *filename,char *uservar,char *uservalue) { FILE* conffile; char temprow[1024]; char row[1024][1024]; char newrow[1024]; char var[512]; char value[512]; char *prow; int rown=0; int charn=0; int rowtotal=0; conffile = fopen(filename,"r"); while(fgets(temprow,1023,conffile)!=NULL) { prow=&row[rown][charn]; if(temprow[0]=='/' && temprow[1]=='/') { strcpy(prow,temprow); } else { sscanf(temprow,"%[^:]: %s",var,value); if (strcmp(var,uservar)==0) { snprintf(newrow,99,"%s: %s\n",var,uservalue); strcpy(prow,newrow); printf("%s",newrow); } else { strcpy(prow,temprow); } } printf("%s",prow); charn=0; rown++; rowtotal++; } charn=0; //Go back to char 1. rown = 0; //Go back to row 1. fclose(conffile); unlink(filename); conffile = fopen(filename,"w+"); while(rown<rowtotal) { prow=&row[rown][charn]; fprintf(conffile,"%s",prow); charn=0; rown++; } fclose(conffile); printf("File updated.\n"); return 0; } int main() { char ufilename[25]; char var[25]; char value[25]; printf("Please type the filename you wish to edit.\n"); scanf("%[^\n]",ufilename); system("cls"); printf("Please type your chosen variable, followed by a space, followed by your requested value.\n"); scanf("%24[^ ] %s",var,value); system("cls"); readbexp(ufilename,var,value); system("pause"); return 0; }
  12. DavW

    Where to start with graphics (Windows)?

    OpenGL is cross-platform, which gives it a big advantage over DirectX IMO. SDL is a fairly low level abstraction of video hardware under almost any OS, and is a good choice for 2d graphical apps. However, it lacks several basic functions like text and primitive drawing that you might find in another library or OpenGL. You can even combine the 2 and use OpenGL in an SDL window, to provide a cross platform canvas for OpenGL display. There are a couple of relevant tutorials at My Website
  13. short tutorial on iostreams in now online Where's the best place to announce these things? They are definately beginner-relevant, but maybe it should be in "Your announcements"
  14. DavW

    distributing a program

    I've used clickteam install creator before (linkyfied above) and it seemed to work ok, but I've never tried NSIS.
  15. First tutorial is online, I have a couple more sections to add but I'd like some feedback on style & understandibility etc. Handy maths-related concepts for game programmers
  • 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!