Jump to content
  • Advertisement

zacaj

Member
  • Content Count

    430
  • Joined

  • Last visited

Everything posted by zacaj

  1. zacaj

    potatoeses or potatoeseses

    If you insist on doing it that way, then malloc is indeed what you want to use if you want to allocate the memory for them without calling the constructors.  You just have to be careful that the first bit of memory in each object doesn't ever end up being zero, otherwise your check wouldn't work.     Alternately, just have an empty constructor.  
  2. zacaj

    Using STL Maps

    Since you didn't allocate them using new there won't be a memory leak
  3. zacaj

    potatoeses or potatoeseses

    If you want to use any inheritance then you need to story individual pointers to objects, so the 4 bytes are required anyway (and it's not like 4 bytes per object will actually make an impact).  If you only have one object then I'd suggest just giving them a bool active variable and then just setting it to zero to show that they're 'dead' or whatever.  As to the unbearableness, it only affects maybe three lines of your code, and besides, you *are* using C++.  What did you expect?     really though, unless there's some big reason why you're using an array like this, I'd recommend you switch to using a std::vector<SomeObject*>
  4. zacaj

    potatoeses or potatoeseses

    Off the top of my head, try SomeObject **so; so = new SomeObject*[max_objects]; An array is a pointer to a block of memory, so in your case you want a pointer to a block of pointers that you can then individually allocate
  5. I'm working on a DOOM-esque game in opengl for 7dfps and I need to make the billboarded pickups and enemies.  Is there somewhere which documents the 'correct' way to rotate the quads and to choose which sprite of the enemy to show?  If not, can someone tell me if there's anything wrong with the algorithms I've come up with?   For billboards: I have made the billboard perpendicular to the player's view angle.  I also tried making it perpendicular to a line pointing at the player's position, but it looked worse.     For enemies: radiansToSide=PI*2/8  (8 is the number of sprites I have for enemy) angle=atan2(enemy.y-player.y,enemy.x-player.x) angle+=radiansToside/2    angle/=PI*2 angle*=8 angle=floor(angle) //angle is now an int 0-7
  6. Try using a union union FloatInt { int i; float f; } FloatInt fi; fread(&fi.i,sizeof(FloatInt),1,fp); Are you sure blender wrote a float and not a double?
  7. class Foo; Foo *foo_pointer; //valid. It's just a pointer, so it only needs to know that Foo is a type (which it does from the forward declaration), it doesn't need to know anything about Foo itself Foo foo; //error. Actually making a variable of type Foo (foo_pointer is of type Foo*, not Foo) can't be done, because we don't know how big Foo is. void accessFoo(Foo *foo) { foo->x=4;//also an error. We don't know what variables Foo contains, so there's no way we could access them } class Foo { public: int x; }; //declaring the type Foo down here doesn't affect the code above it Foo foo2; //this is now valid, because Foo is a fully defined type void main() { foo_pointer=new Foo();//although foo_pointer was declared above the Foo class, since *this* code is below the Foo class, it can access foo_pointer's members foo_pointer->x=8; accessFoo(foo_pointer); }
  8. A.h: class B; //forward declaration class A { //contents } B.h: class A; class B { //contents } A.cpp: #include "A.h" #include "B.h" //code  B.cpp: #include "B.h" #include "A.h" //code This is the safest way.  Basically you can't include a file that includes the first file.     Forward declaring a class allows you to define pointers using that type, but not access them.     So in class A you can have   B* b;   but you can't have an inline constructor that calls a function in b or accesses its variables.   Since you don't usually #include a .cpp file directly, it's safe to just include all the classes .h files in your .cpp files
  9. Been trying to make a little textured raycaster for fun the past few days.  Walls went fine, but I hit a wall when it came to floor texturing.  No idea how to do it.  So I found http://lodev.org/cgtutor/raycasting2.html , and I was able to adapt their floorcasting code quite easily.  It worked, except that it couldn't handle it when I changed the camera height.  Looking at their section on computing the 'currentDist' (from current pixel to floor, I'm assuming vertically), none of what they say makes any sense. "the distance from a pixel in the center of the screen to the floor is infinite"  What? "for the bottom of the screen, you can choose a distance" I'm assuming this would be where my camera elevation goes in "for example, 1" oh, thank god they chose 1 as their magic number.  It's not like that ever comes up anywhere else "the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height."  that wasn't even proper english.  Plus, when they say 'inversely' and then use 1/x I assume the 1 is from standard math, but it's the only place on the page where they make any reference to the camera height which they so helpfully chose as 1 earlier. "you can use this formula" no explanation on how they got that, or anything.   Is it even possible to have different camera elevations with this technique?  
  10. zacaj

    Help with floorcasting

    Ah!  When he was saying "the distance from the projected pixel to the floor" I thought he meant vertical distance!  That makes all of his code make sense, even if I still can't get the floor to render right when I change the camera height.  (I've got it working fine for z=0)   In his tutorial, he renders the floor in vertical spans above and below the wall sections, computing for every pixel.  You seem to be suggesting that I do floor spans horizontally?  Wouldn't that mean I'm going to need some kind of complicated algorithm to figure out the horizontal spans, since the walls are all drawn vertically?
  11. How am I supposed to get a BMP of every character? And by array you mean a BITMAP array?     Oh look what I found on Google:   http://www.dafont.com/perfect-dos-vga-437.font     How am I supposed to use a TTF in SDL? (I know about SDL_ttf() and such.) I'm assuming I make a black BG that takes up the whole screen, then assign a letter in the TTF to each keystroke? That should work, correct?   If you know about SDL_ttf then what's the problem?
  12. Make a console program that prints out each character and then take a screenshot?  
  13. SDL should be enough.  Just get a BMP of all the characters you can print and make an array you can "print" into.
  14. Go over the points in your grid, calculate distance from center point of circle to that point.  If it's less than the radius of the circle, then do point.z+=(1-distance_away/radius)*height_change to get a gradient
  15. zacaj

    Grand Theft Auto 1 Movement

    tank movement/control?
  16. Your code *is* valid.  copy will be an exact copy of the struct, including containing its own copy that points to itself.  
  17. Ah. I was remembering GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS. The 3.3 spec requires the card support 16 textures for each stage.
  18. If your map isn't changing at all it'd probably be better to render all your little tiles to a few bigger tiles and just draw those specialized ones.  My "1000 textures" thing might have been exaggerating a bit, but.  32x32x4bppx1000 is only 4MB of VRAM, and shouldn't really be a problem.  I would recommend doing a spritesheet though.  It should be quite easy to have use glTexSubimage to make a few big 2048x2048 textures and just drop any specific tile loaded into one, keeping track of its coordinates in the larger texture, then just have an array that stores the coordinates for you to look up the tile in when you need it.     Although you have one draw call per tile, are you *really* going to have all 1000 tiles on the screen at one time?  (I mean, I guess you could, but)  I doubt 1000 draw calls is going to be very bad.  For most of these things, the best advice really is to just try it.  Think of the different ways it could be done, and just make sure you have a tile drawing interface that could work with any of those, should you find the need to switch somewhere down the line
  19. 256MB is a very conservative estimate.  Any recent computer is going to have at least 1GB.  Check out the Steam Hardware survey at http://store.steampowered.com/hwsurvey under VRAM.  99% of people have at least 256MB, 91% have 512MB.  I'm not sure how high resolution textures you're using, but I doubt you'd even get close to the 256.  256MB gives you space for a 8192x8192 texture.  If each tile is 16x16, that gives you enough space for 262144 tiles.  If you've got more than 1000 different tiles loaded at once, you might want to reevaluate what you're doing.       When your video card runs out of space, the driver will just start using the regular system ram as "virtual memory", which I know causes major slowdowns, but I don't have any first hand experience there.  Don't forget though, using it as virtual memory is going to be pretty much the same as you just uploading your textures from RAM each time they're used.  I'd assume you can do a much better job of switching out the textures that are least likely to be used than the graphics card can, if by some strange turn of events that actually happens.
  20. You can only have 48 textures bound AT ONCE, which only happens when you're doing crazy shader based multitasking.  You should be fine with using 100s of textures, as long as only one is bound at a time.  You can probably safely assume most people will have at least 256MB of video ram, which means you can probably have at least 200MB of textures loaded at a time.
  21. zacaj

    Far Mesh Become Invisible

    Numbers that big are going to be cut off. The computer can't store them. Because of depth buffer accuracy issues, you should generally never have the far distance be more than a few thousand. I'd recommend you use a smaller unit for your world
  22. zacaj

    Check video ram usage

    There is no universal solution.  You have to use manufacturer/brand/? specific extensions.   If you use this, does it print out either brand? int getFreeVideoMemory() { int availableKB[]={-1,-1,-1,-1}; if(GLEW_NVX_gpu_memory_info) { glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX,&availableKB[0]); printf("NVidia card\n"); } int temp=GLEW_ATI_meminfo; if(GLEW_ATI_meminfo) { glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI,availableKB); printf("ATI card\n"); } return availableKB[0]; }
  • 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!