Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411504 Posts in 69373 Topics- by 58429 Members - Latest Member: Alternalo

April 25, 2024, 05:06:23 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)I need an adult. SDL and C++
Pages: 1 [2]
Print
Author Topic: I need an adult. SDL and C++  (Read 7988 times)
Corpus
Guest
« Reply #20 on: June 25, 2008, 12:47:42 AM »

Oh man, I programmed like a bajillion variables, each one adhering more strictly to current naming conventions than the last.

I'm not sure there are necessarily certain terms you have to use. Just refer to these things as something that seems vaguely sensible and sound like you know what you're talking about and you'll be all right.

An overall game class would be a good idea if you want to be able to easily reuse this code for other games in the future. Otherwise, though, it isn't really necessary. It's definitely a good idea to do the other things you said, though - for example, in the last engine I worked on, I had a level class which handled entity->level collisions and the loading of level data and tilesets, and which also, uh, I guess, "interfaced" with a tile class which handled the displaying of tiles from the tileset. It may have done some other things, too...

That probably doesn't help at all, but there you have it.
Logged
dmoonfire
Level 3
***



View Profile WWW
« Reply #21 on: June 25, 2008, 05:28:44 AM »

Development wise, I got with the Unix school of thought. One class (for C#/C++) or function that does one thing well. If you have a big monster method, then break it up until it does one thing well.

For the endless iterations of my sprite library (which includes Java, SDL, C#, Gtk#, and Tao.Sdl in various forms), I ended up going with a few classes to handle every little bit. For example, a sprite container which lead into a bounded sprite container (which let you hook the camera up), and then into the box model. A lot of it depends on how you organize things.

I'd recommend you grab a book on design patterns (or use your google-fu mastery) and scroll through them. If you know what you want, then just reading them, you can say "oh, that's what I want!". At least,t hat is how I start some projects.

As for writing, sorry. I'm in writing phase right now, so no codies outside of work. Tongue
Logged
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #22 on: July 01, 2008, 05:44:46 AM »

Hey, I'm back, with a new problem Grin

I have a class Entity, and a subclass MovingObject.  MovingObject obviously has some functions that Entity does not have.

Now I have a function that loops through a vector of Entities, and some of the Entities are MovingObjects.  In this loop, I need to call functions of MovingObject.  This causes a problem.

I tried just putting functions that do nothing in the class Entity that are the same functions as the ones in MovingObject, and I made them virtual... but all I get is completely whacked out errors, usually dealing with the linker.

I've tried looking this up but I cant seem to get a clear answer, or an answer that fixes anything... halp.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #23 on: July 01, 2008, 07:08:17 AM »

Right, you can make these methods virtual, but you have to provide a base implementation even if it's an empty method.

so

Code:
class Base
{
  public:
    virtual void Method() { }
};

class Derived: public Base
{
  public:
    void Method()
    {
      // implementation
    }
}

If you wanted to make them without an implementation, you can do that too, but then you are not allowed to make any instances of the base class:


Code:
class Base
{
  public:
    virtual void Method() = 0; // declare this function as pure virtual
                               // any class derived from Base MUST IMPLEMENT this method
};

class Derived: public Base
{
  public:
    void Method()
    {
      // implementation
    }
};

void Main()
{
  Base object; // compile error: Base is pure virtual
}
Logged

Zaphos
Guest
« Reply #24 on: July 01, 2008, 07:12:25 AM »

You could use dynamic_cast<MovingObject> to cast your more general object to a moving object.

edit: er, so code would look like:

Code:
if (MovingObject *o = dynamic_cast<MovingObject>(generalObject))
{
  // do special moving object stuff
}
Logged
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #25 on: July 01, 2008, 08:24:49 AM »

Ah, many thanks, looks like its working.

Haowan:  I thought I was doing this before, but I guess I wasn't doing it correctly... I didn't know I could just do { } :B

Zaphos:  That looks dandy... I'll have to keep that in my list of mental notes.

On a side note... arrggh, just when I thought my collision detection was safe, objects still get stuck in each other by a pixel.  DARN THE LUCK, DARN.
« Last Edit: July 01, 2008, 08:36:58 AM by xerus » Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #26 on: July 01, 2008, 08:39:10 AM »

Quick note: if you're going to put functionality in the base class implementation, and you want it to be called from the derived class, you need to explicitly call it:

Code:
class Base
{
  public:
    virtual void Method()
    {
      Functionality();
    }

  private:
    void Functionality()
    {
    }
};

class Derived: public Base
{
  public:
    void Method()
    {
      Base::Method();
      // implementation
    }
}

...because it won't get called automatically.
Logged

Corpus
Guest
« Reply #27 on: July 01, 2008, 02:50:54 PM »

Xerus, the way I did collisions last time was to measure the distance that the object had moved into another object in the direction of its motion, and then move it back in the opposite direction by that amount.
Logged
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #28 on: July 01, 2008, 11:15:03 PM »

Xerus, the way I did collisions last time was to measure the distance that the object had moved into another object in the direction of its motion, and then move it back in the opposite direction by that amount.

Yeah, well right now my problem is that collisions work but when a bunch of objects are less than 1 pixel apart and one collides, the other will get stuck inside.  I need to figure out a "push out" method or something.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #29 on: July 02, 2008, 03:34:17 AM »

Xerus, the way I did collisions last time was to measure the distance that the object had moved into another object in the direction of its motion, and then move it back in the opposite direction by that amount.

Yeah, well right now my problem is that collisions work but when a bunch of objects are less than 1 pixel apart and one collides, the other will get stuck inside.  I need to figure out a "push out" method or something.

If you make it so you affect their velocities rather than their positions, it should be OK.

Also, I have a "push" vector for each entity in addition to the velocity, which gets zeroed each frame. So if I need to push something out of another object, I use that. If I need to make an object accelerate the other object, I send the data to the velocity insteadof this "push" value. It works out really well.
Logged

___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #30 on: July 07, 2008, 01:18:34 PM »

Xerus, the way I did collisions last time was to measure the distance that the object had moved into another object in the direction of its motion, and then move it back in the opposite direction by that amount.

Yeah, well right now my problem is that collisions work but when a bunch of objects are less than 1 pixel apart and one collides, the other will get stuck inside.  I need to figure out a "push out" method or something.

If you make it so you affect their velocities rather than their positions, it should be OK.

Also, I have a "push" vector for each entity in addition to the velocity, which gets zeroed each frame. So if I need to push something out of another object, I use that. If I need to make an object accelerate the other object, I send the data to the velocity insteadof this "push" value. It works out really well.

Ah, just modifying the velocity may be all I need actually.  Right now I have something set up that I think is working, but once again I'm sure it will prove me otherwise in a few days.
Logged
___
Vice President of Marketing, Romeo Pie Software
Level 10
*


View Profile
« Reply #31 on: July 08, 2008, 10:40:23 AM »

For now I think I have collisions working.  So now onto my next question... how do I go about assembling what I create for distribution?  what files do I need to include with it... is there special compiling options I need to use?  Halp.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #32 on: July 08, 2008, 11:36:35 PM »

I haven't worked with SDL in C++, but I just bundle the DLLs with the game and it works fine. The trouble is if there are frameworks installed on your machine that are required, the game will run regardless of where you put it on your machine. The best way to test it is to find some other machine with not much installed on it and try it there. In general you'll need your game, your loaded resources, and the DLLs for the libraries you used, unless they're statically linked to your game in the form of .lib files, in which case you'll be fine just to send the game I think.

If you find it's not working when you distribute it, try running it through Dependency Walker.
Logged

Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic