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. zacaj

    zacaj.screens

  • 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!