Questions on understanding the code

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
jackdw
Engineer
Engineer
Posts: 3
Joined: 01 Aug 2017 04:32

Questions on understanding the code

Post by jackdw »

Hey all, going through the code and trying to understand it, and had a couple of questions.

1)

Code: Select all

_cur.AddSpriteSets(feature, _cur.spriteid, first_set, num_sets, num_ents);
from newgrf.cpp, line 4523 in the code that I have.

Using the zbase base set, I am seeing it call this twice, both times with the first_set = 0. Am I missing something, or does the line

Code: Select all

SpriteSet &set = this->spritesets[feature][first_set + i];
mean it is going to set the same sprites on both calls?

Am I reading this right?

2) ResetNewGrfData

Code: Select all

	/* Reset the objects. */
	ObjectClass::Reset();
	ResetCustomObjects();
	ResetObjects();
Won't the call to ObjectClass::Reset add in the cls_ids for the two objects, and then ResetObjects will just memcpy over it?
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Questions on understanding the code

Post by Eddi »

jackdw wrote: Using the zbase base set, I am seeing it call this twice, both times with the first_set = 0.
I haven't looked at the code, but i'm assuming it's calling once for the 8bpp and once for the 32bpp sprites, as they are defined in separate places in the GRF
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Questions on understanding the code

Post by frosch »

jackdw wrote:it is going to set the same sprites on both calls?

Am I reading this right?
Yes, NewGRF are loaded in multiple stages to resolve dependencies between NewGRF.
This involves quite some magic (https://newgrf-specs.tt-wiki.net/wiki/GrfLoadingStages), but usually you do not need to know the details.

In this case the first call is likely the reservation stage, which is essentially a test-run.
The second call is the activation stage, where stuff is done for real.
jackdw wrote:Won't the call to ObjectClass::Reset add in the cls_ids for the two objects, and then ResetObjects will just memcpy over it?
Hmm, yes, looks weird. Possibly the ObjectSpec->Class mapping is not used for the default objects, so noone noticed.
Would you like to submit a fix via https://github.com/OpenTTD/OpenTTD/pulls ? :)
Eddi wrote:I haven't looked at the code, but i'm assuming it's calling once for the 8bpp and once for the 32bpp sprites, as they are defined in separate places in the GRF
Nope. 8bpp/32bpp sprites may be defined in different places in NML, but they are in the same spot in the compiled NewGRF.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 6 guests