Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 9 10 [11] 12 13

Author Topic: Party House Experiment > Development on Pause  (Read 18511 times)

Org

  • Bay Watcher
  • Daring Hero
    • View Profile
Re: Party House Experiment > Healing
« Reply #150 on: June 17, 2010, 11:05:43 am »

Okay, so I'm completely better now.

I've been working on a new project for a while,
 and I suppose I'll pitch up a thread for it once it works better.
What is it.
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Party House Experiment > Healing
« Reply #151 on: June 17, 2010, 03:50:23 pm »

I know, but it's a sekrit.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Party House Experiment > Healing
« Reply #152 on: June 18, 2010, 08:04:27 pm »

Well, what if we wanna know what it is? It's no fair to hold out on us.
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Healing
« Reply #153 on: June 20, 2010, 11:00:00 pm »

Okay, so I probably should have mentioned I was going to be off in other lands over the weekend.
Things worked out well, but there were a bunch of adversities,
 so it wasn't as rejuvenating as usual.

I haven't touched the project since last post, but the more I look at it, the more I understand its pitfalls.
I'll grind away tomorrow and see if I can get it working better.

Alfie, didn't I make you my official partner on Cloud Scream last year?
I guess your more of a Footkerchief than anything.
Your permissions extend to all of my projects I suppose.
(not that I can actually enforce things)
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Healing
« Reply #154 on: June 22, 2010, 12:09:05 pm »

This is the code I use to find the distance between (x,y) and (Vx,Vy) :

Code: [Select]
            //get distance
            float difx,dify;
            if(x>Vx){difx = x - Vx;}else{difx = Vx - x;}
            if(y>Vy){dify = y - Vy;}else{dify = Vy - y;}
            float difxsqd = difx * difx;
            float difysqd = dify * dify;
            float sqdtotal = difxsqd + difysqd;
            float dist = sqrt(sqdtotal);
            if(dist>maxradius){maxradius = dist;}

Any reason that wouldn't work?
« Last Edit: June 23, 2010, 12:44:03 pm by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Party House Experiment > Healing
« Reply #155 on: June 22, 2010, 12:29:30 pm »

No, although that isn't the most efficient way to do it...
(You don't need the ifs, as squaring it will have the same result regardless if it is -x or x)
(Also, if you only need to know if it is closer or not, you don't need the sqrt, either)
(Don't worry about making it faster, though, if it would reduce the readability.)
(abs() or fabs() might even be more readable and possibly faster)
(Go with whatever will be easier to understand if you were to forget it existed for a year)
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Healing
« Reply #156 on: June 22, 2010, 04:50:37 pm »

Thank you for your input, I've been using that code in all of my projects.
I will enjoy making it more robust.

------------------------------------

There are a few more functions I want to add to my project before I start asking Bay12 for help.
It is extremely primitive, but something I have never done before, which I have always wanted to.

Everything else is currently on hiatus.
My programming style is changing very rapidly, and until I have leveled back out, I will probably continue to jump around like this.
In my main thread, I've already listed the projects I'm interested in.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #157 on: June 22, 2010, 08:20:52 pm »

I have these:

Code: [Select]
extern const char *globalmessage_dist;
extern const char *globalmessage_x;
extern const char *globalmessage_y;

I'm trying to set those to hold a value that is originally a float.
I don't think this works, and it has something to do with me not understanding pointers.

Code: [Select]
void special::setmessage_float(const char *messagesort,float displayfloat){
    int displayint = displayfloat;
    std::stringstream sstr;
    sstr << displayint;
    std::string str1 = sstr.str();
    messagesort = str1.c_str();
}

Any help?
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Party House Experiment > Hiatus
« Reply #158 on: June 23, 2010, 10:07:45 am »

It might have something to do with your usage of "const", but I haven't messed with that kind of combination of pointers for a while.  Maybe this will be helpful?

http://duramecho.com/ComputerInformation/WhyHowCppConst.html
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

darius

  • Bay Watcher
  • ^^
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #159 on: June 23, 2010, 10:20:44 am »

And why use char* when there is std::string?
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Party House Experiment > Hiatus
« Reply #160 on: June 23, 2010, 10:22:29 am »

I have these:

Code: [Select]
extern const char *globalmessage_dist;
extern const char *globalmessage_x;
extern const char *globalmessage_y;

I'm trying to set those to hold a value that is originally a float.
I don't think this works, and it has something to do with me not understanding pointers.

Code: [Select]
void special::setmessage_float(const char *messagesort,float displayfloat){
    int displayint = displayfloat;
    std::stringstream sstr;
    sstr << displayint;
    std::string str1 = sstr.str();
    messagesort = str1.c_str();
}

Any help?
Yeah, you're trying to let pointer messagesort point to str1. This fails not because the pointer is constant (it would be if it was extern char const  *globalmessage_dist;), but because str1 is deleted when the function ends. Also, the data where c_str points to is deleted as soon as the next call comes along (see: http://www.cplusplus.com/reference/string/string/c_str/). You'll need the "new" operator when working with pointers, and be careful to "delete" data assigned that way as well, if you want to re-assign a new pointer to it, or copy the data into a new pointer array char for char.

I think :)

Can't you use non-pointer std::strings for this?
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #161 on: June 23, 2010, 12:43:34 pm »

I solved that one by setting up an enum with a value to correspond with each const int,
 then used a switch case to decide where to send the value.

There is still a problem with it though.
Here is the code:
Code: [Select]
void special::setmessage_float(int messagesort,float displayfloat){
    int displayint = displayfloat;
    std::stringstream sstr;
    sstr << displayint;
    std::string str1 = sstr.str();
    switch(messagesort){
        case 1:     globalmessage_dist  = str1.c_str(); break;
        case 2:     globalmessage_x     = str1.c_str(); break;
        case 3:     globalmessage_y     = str1.c_str(); break;
        default: break;
    }
}

When I call this function once, it works fine.
If I call it twice consecutively though, the second call seems to overwrite the first.
I am completely stumped.

Here are the calls:
Code: [Select]
S.setmessage_float(2,x);
S.setmessage_float(3,y);

Thank you all for helping me.
« Last Edit: June 23, 2010, 12:47:13 pm by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Party House Experiment > Hiatus
« Reply #162 on: June 23, 2010, 02:39:36 pm »

I can't see anything in that block of code that should be creating any problem....  You might want to try unit-testing this block of code... have it set something other than the global messages, or just output the results directly to the console. I.E.

Code: [Select]
void special::setmessage_float(int messagesort,float displayfloat){
    int displayint = displayfloat;
    std::stringstream sstr;
    sstr << displayint;
    std::string str1 = sstr.str();
    switch(messagesort){
        case 1:     cout << "Dist=" << str1.c_str() << endl; break;
        case 2:     cout << "x="    << str1.c_str() << endl; break;
        case 3:     cout << "y="    << str1.c_str() << endl; break;
        default: break;
    }
}

And see if it works as expected.  If it does, the problem must be somewhere else....
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Party House Experiment > Hiatus
« Reply #163 on: June 23, 2010, 03:24:44 pm »

I'm using SDL, and I'm not sure how to get it to cout things.
I've tried std::cout, but the console window never seems to respond to such things.

EDIT:

SDL makes its own window.
Maybe I have to specifically target the console window to cout stuff to it.
« Last Edit: June 23, 2010, 03:39:38 pm by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Party House Experiment > Hiatus
« Reply #164 on: June 23, 2010, 03:44:47 pm »

You might, or you could just open a temporary text file and output to that.  Whenever working in C++ I keep one global function and one define for just that purpose:

Code: [Select]
/*!< Allows a call to error(string) to include the file name and line it was called from. */
#define error(message) error_(__LINE__, __FILE__, message);


/*!< Prints an error message to the log file. */
void error_(int lineN, string filePath, string message)
{
string fileName;
int nSize = filePath.size();
for ( int i = nSize - 1; i >= 0; i-- )
{
if ( filePath[ i ] == '\\' )
break;
fileName = string( filePath.at(i) + fileName );
}

ofstream error_file( "error_log.txt", ifstream::out|ifstream::app );
error_file << fileName << "(" << lineN << ") : " << message << '\n';
}

I.E. A call "error('dist = ' + str1.c_str());" replacing cout in a file called "set_message.cpp", containing only the definition of the function you showed would add a line to a file called "error_log.txt" that read:
"set_message.cpp(7) : dist = 5"
Where the 5 would be the value passed to the original function.

Occasionally I'll also add a function that clears the file, or clears it and adds a header, although I only have that one in C# at the moment.
« Last Edit: June 23, 2010, 03:48:45 pm by timmeh »
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.
Pages: 1 ... 9 10 [11] 12 13