Quick Programming Q & A

For discussion of the code running behind the game

Moderator: Staff

User avatar
Jormuny
Newbie
Posts: 10
Joined: Mon Aug 22, 2016 8:37 pm

Re: Quick Programming Q & A

Postby Jormuny » Mon Sep 19, 2016 9:27 pm

So is is failing to compile, run, or attach a debugger?
If it doesn't compile now, there's an unrelated problem. If it doesn't run, it is also probably unrelated to the debugger. If when you press Debug/Continue it runs but the debugger does not attach, you can try to manually attach it via Debug -> Attach to Process, where you enter the Process ID (which I suspect you can find by opening the Task Manager while the Debug build of the game is running)


Roots, C::B does indeed completely ignore the whole autotools deal - while it can be configured to use a makefile, there is no need to :) It was mostly configured for Linux when I first checked it, I just had to disable forcing build for 32bits because zlib. After that it builds fine from inside C::B.
Lordakius
Junior Member
Posts: 26
Joined: Thu May 26, 2016 9:22 pm

Re: Quick Programming Q & A

Postby Lordakius » Thu Sep 22, 2016 6:24 pm

What exactly do you mean with attach? Sorry, I'm not that much in the matter :D

*edit: When I debug allacrost I go into the key settings menu and press an unmapped key. When using F1 to leave the help menu (btw, what is it called in the code? _welcome_window?), the game crashes and I get the error

Code: Select all

In __cxa_throw () ()
126   ../src/main/windows/SDL_windows_main.c: No such file or directory.
#10 0x00575c4f in main_utf8 (argv=0x1d0008, argc=<optimized out>) at ../src/main/windows/SDL_windows_main.c:126


__cxa_throw ? anyone idea what that is?

*edit²: just moved on via next line and got another message, maybe it helps:

Code: Select all

Cannot open file: ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c:126
Cannot open file: ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c:128


Maybe it has something to do with the debugger, as you suggested. unfortunately, I don't know how the debugger works. I'll try to look into it ..
Lordakius
Junior Member
Posts: 26
Joined: Thu May 26, 2016 9:22 pm

Re: Quick Programming Q & A

Postby Lordakius » Mon Sep 26, 2016 7:50 pm

*To the problem with the breakpoints:
I don't think it's a problem of the debugger since when I tried to set a breakpoint in another project it worked perfectly.

Anyway, since I want to finish the issue I am working on, following question/ inquiry:
(for those who don't know the issue: When reassigning a key in the options menu, while waiting for an input, the help screen opens, which doesn't let the user change actual settings)

-What is this "waiting for key input"- event called in the code/where can I find it?
-how to generally find such things (since breakpoints aren't working :/). Asking those, who had to work into foreign code before. When you don't know the code (not written yourself), is there a solid way to find things like this input event without asking the creator?

-> here my actual idea for the fix:
in boot.cpp line 286

Code: Select all

   if(InputManager->UnmappedKeyPress() == true)
   {
        _welcome_window->Show();
        return;
   }


I would insert another if-clause. bool KeyInputExpected() be the input function(in the options menu)

Code: Select all

   if(InputManager->UnmappedKeyPress() == true)
   {
   if(KeyInputExpected() == 0)
        _welcome_window->Show();
        return;
   }


Hope you have comprehension for a beginner :shrug:
User avatar
Roots
Dictator
Posts: 8659
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Quick Programming Q & A

Postby Roots » Mon Sep 26, 2016 8:15 pm

Lordakius wrote:-What is this "waiting for key input"- event called in the code/where can I find it?
-how to generally find such things (since breakpoints aren't working :/). Asking those, who had to work into foreign code before. When you don't know the code (not written yourself), is there a solid way to find things like this input event without asking the creator?


Look at the comments in the header files to understand all the methods and members available. Our header files are commented very well, and gives you an idea of how a class is built. You can also try reading the code documentation page on the wiki, but that mostly covers how things work architecturally, and doesn't dive too deep into implementation details.

You can also use grep to look through the source tree quickly if you are searching for a specific term or name. (I realize you use Windows, and probably don't have access to a powerful command prompt like in Linux). For example, if I'm looking for all instances of the phrase "battle" in the map code, I'd just run `grep -nir battle src/modes/map/*"


I took a quick look at the code and found some things. In boot.h:

Code: Select all

   //! \brief A pointer to the function to call when a key has been pressed when we're waiting for one
   void (BootMode::*_key_setting_function)(const SDL_Keycode &);


boot.cpp:

Code: Select all

   if (_key_setting_function != NULL)
   {
      if (InputManager->AnyKeyPress() && ev.type == SDL_KEYDOWN)
      {
         (this->*_key_setting_function)(InputManager->GetMostRecentEvent().key.keysym.sym);
         _key_setting_function = NULL;
         _has_modified_settings = true;
         _RefreshKeySettings();
         _message_window.Hide();
      }
      if (InputManager->CancelPress())
      {
         _key_setting_function = NULL;
         _message_window.Hide();
      }
      return;
   }


That's the logic that does the key remapping. I think that all you need to do for your fix is replace "if (KeyInputExpected() == 0)" with "if (_key_setting_function != NULL)" and it should work. Only issue that might happen is if the key remapping code doesn't work correctly anymore since we upgraded to SDL2 very recently. If you find your key isn't mapped correctly, open another bug task. The task you are working on should just be to stop the help window from popping up during key bindings.
Image
Lordakius
Junior Member
Posts: 26
Joined: Thu May 26, 2016 9:22 pm

Re: Quick Programming Q & A

Postby Lordakius » Wed Feb 01, 2017 11:00 am

Currently writing the scripts in a01_sand_dock_departure.lua and wondering, why there are functions multiple times in a01.harrvah_capital_aftermath.lua.
i.e. function Draw() is once in line 130 and in line 952. Is there a specific reason for that?
User avatar
Roots
Dictator
Posts: 8659
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Quick Programming Q & A

Postby Roots » Mon Feb 06, 2017 3:00 pm

That's a mistake. There should only be one definition of these functions. Otherwise (I think) one will overwrite the other. Typically the way I've been organizing map files is to have all of the "setup" type functions at the top, then all "update" functions, then all "draw" functions. Although currently we don't have much in terms of draw code in map scripts.
Image
Lordakius
Junior Member
Posts: 26
Joined: Thu May 26, 2016 9:22 pm

Re: Quick Programming Q & A

Postby Lordakius » Mon Feb 06, 2017 4:13 pm

hmm, do you want me to delete the multiple occurrences of those functions in afthermath.lua and write those only once in sand docks or keep it the way we have it in aftermath?

other question:
how do I change the GameMode on a specific event? My idea was to have a guard at the end of the port to be talked to and then change to bootmode (for testing, i have no clue how to implement the last scene with his family). Will we have another GameMode, like Credits or just jump into the BootMode?
User avatar
Roots
Dictator
Posts: 8659
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Quick Programming Q & A

Postby Roots » Sun Feb 12, 2017 5:59 am

Naw, leave the aftermath alone and I'll take care of cleaning it up.

You should be able to create an instance of BootMode in your Lua script. You can kind of see an example at the bottom of the capital_attack.lua map script:

Code: Select all

functions["MapEndTransition"] = function()
   local mode = hoa_custom.CustomMode("lua/scripts/custom/screen_display.lua");
   mode:AddOption("text1", "Several days later...");
   mode:AddOption("initial_time", "1000");
   mode:AddOption("display_time", "2000");
   mode:AddOption("map", "lua/scripts/maps/a01_harrvah_capital_aftermath.lua");
   Map:TransitionToNewMode(mode, true);
end


In this case, MapMode has it's own built-in ability to seamlessly transition to a new mode, because simply pushing the new mode on top of the stack would change things instantly.


My thought for the transition from the final scene was just to create a custom mode with the text "To be continued...", then go to boot mode and roll the credits from there. We don't need anything super complicated right now though, so I would just to the custom mode with that text, then back into boot mode.

In the final release, we'll want to grant the user the ability to save after the final scene, so that when the second chapter is released, they can use their saved game file and pick up right where they left off. Again though, that's not something we need to worry about doing just yet.
Image
Lordakius
Junior Member
Posts: 26
Joined: Thu May 26, 2016 9:22 pm

Re: Quick Programming Q & A

Postby Lordakius » Mon Feb 13, 2017 10:30 am

Alright, that's exactly what I had in mind when I thought about the transition. Still have to figure out how to actually do it ^^

Don't expect anything from me the next weeks, since I am having exams, soon. After that, I'll be working hard on the script, so we can have some progress again ;) Would be awesome to have some real-time chat with you then (either on discord or irc, whatever fits most), but I guess we can figure that out later, too. (specially with the different time zones and I guess you are busy with other stuff as well ;))
User avatar
Roots
Dictator
Posts: 8659
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Quick Programming Q & A

Postby Roots » Sat Feb 18, 2017 4:54 am

Yeah, sorry I haven't been around hardly at all lately. Just a lot of stuff going on in my life at the moment.
Image

Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests