Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 5

Author Topic: LCS Programming Discussion Topic  (Read 10610 times)

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
LCS Programming Discussion Topic
« on: September 26, 2012, 09:36:14 pm »

We've been posting a lot of programming stuff in the download thread, so I'm creating this topic to try to siphon off some of the discussion. Feel free to ask questions about any programming related stuff in this thread.
Logged

addictgamer

  • Bay Watcher
  • Penguin Developer
    • View Profile
    • Github
Re: LCS Programming Discussion Topic
« Reply #1 on: September 26, 2012, 09:53:08 pm »

Hehe, thanks.

I don't mind the switch statement bit, but it can be fixed in other ways if it's problematic. For example:

Code: [Select]
   char* flavorText;
   switch(LCSrandom(4))
   {
   case 0:
      flavorText = "You keep the gas floored!";
      break;
   case 1:
      flavorText = "You swerve around the next corner!";
      break;
   case 2:
      flavorText = "You screech through an empty lot to the next street!";
      break;
   case 3:
      if(yourworst>15)
         flavorText = "You boldly weave through oncoming traffic!";
      else
         flavorText = "You make obscene gestures at the pursuers!";
      break;
   }

   addstr(flavorText, gamelog);
   gamelog.newline();

True. Good idea. I'll keep it in mind for future switch statements.
I see a couple issues with merging the gamelog.newline() call into addstr:

1. Curses already has a bunch of boggling variants on addstr, like mvwaddnstr.

To me, addstrl looks to me like it should affect how the text is displayed, or at least give me additional options in the parameter list about how I want the text displayed. If it has no impact on the parameter list or on displaying text, that will likely be unintuitive to people who have past experience with Curses.

To me, it's obvious it does more than just display something due to the log parameter.

2. The difference between addstrl and addstr isn't self-documenting.

When I'm assessing how to best integrate logging into the current system for displaying text, I'm worried about code readability. If I'm a new developer to the project, pulling up the source code, how will I know when I should use addstr and when should I use addstrl? I won't be able to figure out what that function does from seeing its name or how it's used -- I won't even know that the difference has something to do with logging rather than displaying text. I will likely be confused, because they appear to do the same thing. There's a good chance that I'll code and use one when they should have used the other, thus creating minor bugs in the logger that other programmers will have to clean up later.

Code: [Select]
addstr(cr->name, log);
addstr(" turns the tables on ", log);
addstr(a->name, log);
addstrl("!", log); // It's not obvious what the difference is here

addstr(a->name, log);
addstr(" has been tainted with wisdom!", log);
gamelog.endmessage(); // This leads to point #3...

Good points. The log parameter does add the realm of possibility that addstrl would effect the log, which only would make the situation more confusing due to even more possibilities.

3. You will need a variant for double newlines as well.

Both of the above concerns get worse when you have a distinction between endmessage() and newline(), and are trying to represent both with single-character variations on addstr's function name.

I hadn't thought of that. That's true.


Personally, I never/rarely come across the first two issues pointed out because I *almost* always check the definition of the function before using it.
That's why I didn't think of those two issues until you pointed them out.

Oh well. Like I said, I can float the code either way.
« Last Edit: September 26, 2012, 09:57:33 pm by addictgamer »
Logged
I'm patiently waiting for the ability to mine and construct palaces in adventure mode.
Barony. A 3D, multiplayer roguelike I am developing.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #2 on: September 26, 2012, 11:08:33 pm »

One thing that seems to be missing is a flush command for gamelog. Here's an example:

Code: [Select]
for(int p=0;p<pool.size();p++)
{
if(!pool[p]->alive)
{
addstr("The Liberal " , gamelog);
addstr(pool[p].name , gamelog);
addstr(" is dead!" , gamelog);
gamelog.newline();
}

}

gamelog.newline();
// Need a flush function here.

adstr("Something happens!");
gamelog.nextMessage();

There should be a flush function between the "x is dead!" lines and "Something happens!". None of the logs are written to gamelog.txt until the final gamelog.nextMessage() call. This example doesn't seem like much, but in the part of siege.cpp I'm in, it could be a long time before gamelog.nextMessage() is called somewhere and the buffer is finally flushed.

Actually, a better idea would be to make gamelog.newLine() write the buffer to the file. There isn't anything wrong with that, is there?
Logged

addictgamer

  • Bay Watcher
  • Penguin Developer
    • View Profile
    • Github
Re: LCS Programming Discussion Topic
« Reply #3 on: September 26, 2012, 11:56:26 pm »

Actually, a better idea would be to make gamelog.newLine() write the buffer to the file. There isn't anything wrong with that, is there?

Yes, I noticed that too in chase.cpp. I'll go ahead and add a flush function and update the newLine function to flush.
Logged
I'm patiently waiting for the ability to mine and construct palaces in adventure mode.
Barony. A 3D, multiplayer roguelike I am developing.

addictgamer

  • Bay Watcher
  • Penguin Developer
    • View Profile
    • Github
Re: LCS Programming Discussion Topic
« Reply #4 on: September 27, 2012, 02:50:19 am »

Nevermind about the flush function, it was both redundant and a bad idea. I did modify newline to flush the log, though. It seems to be working nicely.
I've also finished with chase.cpp. Chases should now be logging!

Before anybody asks, yes, keep logging the way prescribed thus far. This update does not effect the use of the logger. It's an internal change only.

I'll see what other files I add logging to tomorrow. Probably the kidnap/hostage file in the combat folder.
Logged
I'm patiently waiting for the ability to mine and construct palaces in adventure mode.
Barony. A 3D, multiplayer roguelike I am developing.

addictgamer

  • Bay Watcher
  • Penguin Developer
    • View Profile
    • Github
Re: LCS Programming Discussion Topic
« Reply #5 on: September 27, 2012, 12:33:44 pm »

I've added logging for combat/haulkidnap.cpp

I'm going to do daily/activities.cpp next.
Logged
I'm patiently waiting for the ability to mine and construct palaces in adventure mode.
Barony. A 3D, multiplayer roguelike I am developing.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #6 on: September 27, 2012, 10:18:43 pm »

I've been working on an update to make sieges generally better, such as making them go on longer (less 1 day sieges, now). It makes safehouse improvements and rations much more important. I also made starving more lethal, and made it so people can die properly from it, and it shows a message. I'm also trying to gracefully fix the bug where there's a siege on an empty safehouse.

I've added logging to siege.cpp, and it's looking good. I'm starting on fight.cpp now.

Spoiler: siege log (click to show/hide)




EDIT: Why is the random seed saved with the game? I noticed it after I kept reloading. (I added an incredibly useful debug define to disable saving.) Everything always happened the same. It was like Groundhog Day.
« Last Edit: September 27, 2012, 10:27:47 pm by dreadmullet »
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS Programming Discussion Topic
« Reply #7 on: September 28, 2012, 12:11:19 am »

EDIT: Why is the random seed saved with the game? I noticed it after I kept reloading. (I added an incredibly useful debug define to disable saving.) Everything always happened the same. It was like Groundhog Day.

That's often done in strategy games, since it discourages reloading for superior random outcomes. Civilization V, for example, saves the RNG seed unless you go into your new game options and specifically check the box to disable that.

Being able to load a save game and repeat the same steps to get the same outcome is also handy for reproducing bugs.
Logged

Dagun

  • Escaped Lunatic
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #8 on: September 28, 2012, 08:13:31 am »

Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.
« Last Edit: September 28, 2012, 08:15:23 am by Dagun »
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #9 on: September 28, 2012, 08:45:28 am »

Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.

I use VC++ 2010 and it works fine for me. I had to convert it, as you did, and it did break some stuff. I managed to work around it by fiddling with the project settings.

Hmm... I doubt that many people still use VC++ 6 or whatever the .sln version is in trunk. Would it be a good idea to add a 2010 solution file but keep the old one as default? People could just rename the two files and use the 2010 .sln.
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS Programming Discussion Topic
« Reply #10 on: September 28, 2012, 11:22:32 am »

Hi gents, programming related query for you.

The main thread seems to indicate that i need VC++2010, but VC++2010 doesn't seem to recognize the project solution and instead thinks it's from an older VC++ and thus wants to convert it. However converting it breaks a great deal of configuration to the extent where it becomes unusable. Just to check do i indeed need VC++2010 and not an older version? Also is the SVN link in the main thread still correct, perhaps i'm checking out the wrong SVN?

Also since express 2012 came out, your VC++2010 link no longer works, not sure if you noticed.

I use VC++ 2010 and it works fine for me. I had to convert it, as you did, and it did break some stuff. I managed to work around it by fiddling with the project settings.

Hmm... I doubt that many people still use VC++ 6 or whatever the .sln version is in trunk. Would it be a good idea to add a 2010 solution file but keep the old one as default? People could just rename the two files and use the 2010 .sln.

Are you calling my IDE old and busted? You people wound me! And after I upgraded to Visual Studio 2008 and everything... :P

I suppose that I should at least upgrade to 2010. If 2012 express is out, is there a good reason to not just use that? I guess there's probably still a lot of people running XP and Vista.
Logged

Dagun

  • Escaped Lunatic
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #11 on: September 29, 2012, 04:58:15 am »

-snip for tidyness-

Are you calling my IDE old and busted? You people wound me! And after I upgraded to Visual Studio 2008 and everything... :P

I suppose that I should at least upgrade to 2010. If 2012 express is out, is there a good reason to not just use that? I guess there's probably still a lot of people running XP and Vista.

Aside from the 40 minute install time and no compatibility for XP + vista, nope. Source on compatibility. I also don't believe you can install individual visual studio parts now, and instead have to download the whole studio. (Or at least i did, i downloaded the VC++2012 and it plugged it in with basic and another. >:( )

Not trying to force you into a decision or anything, but xp + vista still appears to make up ~50% of net users, so you might be cutting off a lot of potential people.  :( (Source. Not sure how much faith you want to put into the source, but it's up to date and seems plausible.)
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS Programming Discussion Topic
« Reply #12 on: September 29, 2012, 04:15:12 pm »

My question was partially rhetorical; I agree that the XP/Vista compatibility issue (which I pointed out in the next sentence) is enough to kill the prospect.

I realize it might be seen as a disadvantage if you know you want to use only one language, and want to limit the amount of hard drive space used, but installing Visual Studio parts separately was a drawback of earlier Express versions rather than a feature. Even aside from the inconvenience of installing multiple copies of the same IDE to support different languages, Express crippled the ability of users to handle larger projects that incorporated multiple languages in the same program.
Logged

Vherid

  • Bay Watcher
  • [CREATURE:SLARK]
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #13 on: October 02, 2012, 08:25:32 am »

I had some interesting ideas that I was going to code myself or at least try to in my LCS mod, I'm gonna have to dig around and see if I can remember what I was going to do. I am interested in trying to get back into it again, I'd prefer to not be super rusty in programming again even though I learned java.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: LCS Programming Discussion Topic
« Reply #14 on: October 03, 2012, 07:07:17 pm »

I've been working on organizing the fight logs. If I just used gamelog.nextMessage() after every message, it would be really disorganized. I decided to make it so that it makes a blank line between rounds.

Spoiler: example fight log (click to show/hide)
Logged
Pages: [1] 2 3 ... 5