Currently Online

Latest Posts

Topic: Hacking help needed

bothie
Avatar
Joined: 2019-03-04, 14:38
Posts: 1
Ranking
Just found this site
Posted at: 2019-03-04, 15:01

Hi

After years, I decided to come back to widelands, and still some problems exist and so I decided to go on and do some hacking on the game, however, it seems, nothing in the code is really helping newcomers into getting started, and so, I am basicly at the point, that I believe, that I found a bug, but I can't verify anything, because I don't get any useful information.

A few examples:

I have one "DescriptionIndex di" in my hand. It's 96. What is it? I already greped over the source, but since DescriptionIndex is just an int used for everything if I am not mistaken, I have no idea, what to look up. So what is the conversion DescriptionIndex -> std::string so I can get it to stdout in debug messages. Similar problem applies to other types, like "Request * r".

Am I the only coder, who wants to know, what is the content of r in human readable form? Or is there some place in the code, where all this magic already happens?

Basicly, what I need is a way to log(...) the content of a "Request", a "DescriptionIndex" or basicly any other type in a meaningful way.

Any help appreciated and thanks in advance


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 389
Ranking
Tribe Member
Location: 0x55555d3a34c0
Posted at: 2019-03-04, 15:48

Moin bothie and welcome to the forums face-smile.png

Yep, I was also quite confused by the code when I started coding for widelands… face-smile.png It uses a lot of serial numbers to describe concepts such as buildings, workers, wares etc. A DescriptionIndex is such a serial – depending on the context, it may be the serial of a WareDescription, WorkerDescription, BuildingDescription, … Which Index refers to which concept is defined by the order in which they are loaded in the init.lua when starting the game.

Look at src/logic/map_objects/tribes/tribes.h and src/logic/map_objects/world/world.h to find out what XXXDescription a given DescriptionIndex refers to in the current context. (whether it is a ware, worker etc you need to find out from the place you´re obtaining it from.) Then you can do e.g.

log("DescriptionIndex %i means %s.\n", di, egbase.tribes().get_building_descr(di).name().c_str());

Similarly, for a Request* r you can do

if (r->get_type() == wwWARE)
    log("This is a ware request for a %s.\n", egbase.tribes().get_ware_descr(r->get_index()).name().c_str());
else
    log("This is a worker request for a %s.\n", egbase.tribes().get_worker_descr(r->get_index()).name().c_str());

Almost the same "translation" can be applied to nearly all serials. If no EGBase or Game is provided, you can usually obtain an egbase e.g. via something->owner().egbase().

Edited: 2019-03-04, 15:50
Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 2891
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2019-03-05, 11:28

Some objects also have a "log_general_info" function that will log to the console:

  • If you start widelands with the --verbose option or
  • If you open a debug window and click on the object

Please do not hesitate to post any other questions face-smile.png


Busy indexing nil values

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 389
Ranking
Tribe Member
Location: 0x55555d3a34c0
Posted at: 2019-03-10, 21:15

Moin, now I have a question myself face-smile.png

I´m experimenting with a possible new way to show workareas. I´m trying to display the workarea of a building as a plain-color overlay on triangles instead of displaying it on the nodes. This approach has the advantage over the current system that several visible workareas, as well as visible buildhelp icons, don´t obscure anything when overlapping.
Since the height of fields can give the triangles many different shapes, I don´t use images in the datadir but instead create a texture on runtime.

The result is (apart from some minor glitches such as a "grid" and a few missing triangles that will be fairly easy to solve) already more or less what I want:

The code is here: lp:~nordfriese/widelands/workareas

The code (the relevant parts are in wui/interactive_player.cc::draw_map_view and wui/interactive_base.cc::get_workarea_overlays) works basically like this: On every rendering I create a Texture that I initialize with full transparency. For every triangle that needs drawing, I calculate the bounding box. For every pixel in the bounding box, I decide whether it is inside the triangle, and if so, I apply the appropriate RGBAColor to the pixel. When all this is done, the Texture is blitted onto the RenderTarget.

The problem is that my approach is very slow. I already improved performance by using one big Texture for all triangles instead of one small for every single one, but it´s still quite sluggy. Even showing the workarea of a farm reduces the FPS from 29 to 2.9.
I would appreciate suggestions how to improve the performance so much that this could become a feature. Thanks in advance face-smile.png


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 2891
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2019-03-11, 09:05

Maybe you could piggy-back to the code that calculates the drawing of the map terrains? The information which pixels to use is already there, so won't need to go pixel by pixel yourself.

You could then create 1 square of the colored texture in the same size as the base terrain textures and add it as an overlay to the terrain drawing code. Have a look at the player color in the animation class for some color overlay code to poach.

We also need to consider what happens with multiple buildings selected - maybe use an arithmetic middle per overlapping triangle?

Alternatively, using a shader in the terrain program should also work, if you want to get into that.

Edited: 2019-03-11, 09:09

Busy indexing nil values

Top Quote
Tribal-Chief
Avatar
Joined: 2018-12-09, 17:16
Posts: 31
Ranking
Pry about Widelands
Posted at: 2019-03-11, 10:55

The planned change would be a great improvement especially where you have building spaces turned on.

Incidentally the picture above does highlight the fact that all Frisian images have incorrect shadow directions.

Edited: 2019-03-11, 10:55
Top Quote
WorldSavior
Avatar
Joined: 2016-10-15, 04:10
Posts: 1139
Ranking
One Elder of Players
Location: GER
Posted at: 2019-03-11, 12:15

Seeing multiple working areas is a feature. But seeing coordinates thanks to working areas is also a good feature. So what about adding some dot per each field?


“It's a threat to our planet to believe that someone else will save it.” - Robert Swan

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 389
Ranking
Tribe Member
Location: 0x55555d3a34c0
Posted at: 2019-03-11, 15:59

@GunChleoc thans for your suggestion face-smile.png I tried to hack the terrain shader first, but that clashed with the dither layer. Since I don´t want to have to render the overlay twice, I now implemented it as a new (very simplistic) shader:

And it has no negative impact on performance at all! (Unless I open 5+ building windows with workareas at the same time.)

The colors themselves as well as their alpha strength still need some tweaking of course.

We also need to consider what happens with multiple buildings selected - maybe use an arithmetic middle per overlapping triangle?

When deciding the color for a triangle, I currently apply all colors one after the other, and I weight the color components with their individual alpha channels:

uint8_t r = (c1.r * c1.a + c2.r * c2.a) / (c1.a + c2.a);
uint8_t g = (c1.g * c1.a + c2.g * c2.a) / (c1.a + c2.a);
uint8_t b = (c1.b * c1.a + c2.b * c2.a) / (c1.a + c2.a);
uint8_t a = (c1.a + c2.a) / 2;
...
divide through 255.f later

This returns a good-looking result IMHO

Incidentally the picture above does highlight the fact that all Frisian images have incorrect shadow directions.

Um… they´re short and pointing north-northeast… for frisians and all other images…

But seeing coordinates thanks to working areas is also a good feature. So what about adding some dot per each field?

Okay, I´ll re-add some markers…


Top Quote
WorldSavior
Avatar
Joined: 2016-10-15, 04:10
Posts: 1139
Ranking
One Elder of Players
Location: GER
Posted at: 2019-03-11, 16:11

Nordfriese wrote:

But seeing coordinates thanks to working areas is also a good feature. So what about adding some dot per each field?

Okay, I´ll re-add some markers…

Thank you face-smile.png


“It's a threat to our planet to believe that someone else will save it.” - Robert Swan

Top Quote
Tribal-Chief
Avatar
Joined: 2018-12-09, 17:16
Posts: 31
Ranking
Pry about Widelands
Posted at: 2019-03-11, 16:54

Um… they´re short and pointing north-northeast… for frisians and all other images…

but they point in another direction, check against trees or rocks, or buildings of other tribes.


Top Quote