Skip to content

Commit 1cad491

Browse files
committed
move some slower init stuff to be once only on level enter
1 parent 168058e commit 1cad491

5 files changed

Lines changed: 144 additions & 127 deletions

File tree

src/game_load.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ std::istream &operator>>(std::istream &in, Bits< Thingp & > my)
443443
shift = 0;
444444
// clang-format off
445445
// begin sort marker2 {
446+
my.t->is_newborn = ((bits64 >> shift) & 1LLU) ? 1LLU : 0LLU; shift++;
446447
my.t->is_activated = ((bits64 >> shift) & 1LLU) ? 1LLU : 0LLU; shift++;
447448
my.t->is_attached = ((bits64 >> shift) & 1LLU) ? 1LLU : 0LLU; shift++;
448449
my.t->is_auto_equip_done = ((bits64 >> shift) & 1LLU) ? 1LLU : 0LLU; shift++;

src/game_save.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ std::ostream &operator<<(std::ostream &out, Bits< const Thingp & > const my)
392392
shift = 0;
393393
// clang-format off
394394
// begin sort marker2 {
395+
bits64 |= (my.t->is_newborn ? 1LLU : 0LLU) << shift; shift++;
395396
bits64 |= (my.t->is_activated ? 1LLU : 0LLU) << shift; shift++;
396397
bits64 |= (my.t->is_attached ? 1LLU : 0LLU) << shift; shift++;
397398
bits64 |= (my.t->is_auto_equip_done ? 1LLU : 0LLU) << shift; shift++;

src/my_thing.hpp

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -192,91 +192,92 @@ typedef class Thing_
192192
// v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v
193193
/////////////////////////////////////////////////////////////////////////
194194
// begin sort marker1 {
195-
uint64_t corpse_cleanup : 1 {}; // Used to remove corpses when eaten or burnt
196-
uint64_t gfx_ascii_animated : 1 {}; // Animated in ascii mode?
197-
uint64_t gfx_pixelart_animated : 1 {}; // Animated in pixelart mode?
198-
uint64_t has_attacked_player : 1 {}; // Has it attacked the precious?
199-
uint64_t has_ever_moved : 1 {}; // Has it ever moved? e.g. a gargoyle
200-
uint64_t has_light : 1 {}; // Has it a light source?
201-
uint64_t has_projectile : 1 {}; // Current projectile being fired
202-
uint64_t has_seen_player_msg_shown : 1 {}; // Seen by player has been shown
203-
uint64_t _is_able_to_be_resurrected : 1 {}; // Can be removed by negation
204-
uint64_t _is_able_to_regenerate : 1 {}; // Can be removed by negation
205-
uint64_t is_activated : 1 {}; // This skill is activated
206-
uint64_t is_attached : 1 {}; // Is attached to the level
207-
uint64_t is_auto_equip_done : 1 {}; // Has initially auto equipped itself
208-
uint64_t is_being_destroyed : 1 {}; // In the process of deleting the thing
209-
uint64_t is_bouncing : 1 {}; // Is graphically bouncing
210-
uint64_t is_burnt : 1 {}; // Burnt by ice and cannot move
211-
uint64_t is_changing_level : 1 {}; // Is in the process of changing level
212-
uint64_t is_dead : 1 {}; // It's dead Jim
213-
uint64_t is_discorded : 1 {}; // Will attack what normally it would not
214-
uint64_t is_discovered : 1 {}; // Can you see that secret door?
215-
uint64_t is_drained : 1 {}; // E.g. enchant or skillstone used up
216-
uint64_t is_dying : 1 {}; // Is currently in the throes of death
217-
uint64_t is_facing_left : 1 {}; // It's in the process of dying
218-
uint64_t is_fadeup : 1 {}; // For text that fades upwards
219-
uint64_t is_falling : 1 {}; // Falling to a new level
220-
uint64_t is_floating_ : 1 {}; // Updated per tick
221-
uint64_t is_frozen : 1 {}; // Frozen by ice and cannot move
222-
uint64_t is_hidden : 1 {}; // Carried perhaps and hence not visible
223-
uint64_t is_hunger_level_gorged : 1 {}; // Hunger levels
224-
uint64_t is_hunger_level_hungry : 1 {}; // Hunger levels
225-
uint64_t is_hunger_level_satiated : 1 {}; // Hunger levels
226-
uint64_t is_hunger_level_starving : 1 {}; // Hunger levels
227-
uint64_t _is_immune_to_acid : 1 {}; // Can be removed by negation
228-
uint64_t _is_immune_to_blinding : 1 {}; // Can be removed by negation
229-
uint64_t _is_immune_to_cold : 1 {}; // Can be removed by negation
230-
uint64_t _is_immune_to_confusion : 1 {}; // Can be removed by negation
231-
uint64_t _is_immune_to_electricity : 1 {}; // Can be removed by negation
232-
uint64_t _is_immune_to_entrancement : 1 {}; // Can be removed by negation
233-
uint64_t _is_immune_to_fire : 1 {}; // Can be removed by negation
234-
uint64_t _is_immune_to_holy_damage : 1 {}; // Can be removed by negation
235-
uint64_t _is_immune_to_lightning : 1 {}; // Can be removed by negation
236-
uint64_t _is_immune_to_magic_drain : 1 {}; // Can be removed by negation
237-
uint64_t _is_immune_to_necrosis : 1 {}; // Can be removed by negation
238-
uint64_t _is_immune_to_negation : 1 {}; // Can be removed by negation
239-
uint64_t _is_immune_to_non_magical_weapons : 1 {}; // Can be removed by negation
240-
uint64_t _is_immune_to_paralysis : 1 {}; // Can be removed by negation
241-
uint64_t _is_immune_to_poison : 1 {}; // Can be removed by negation
242-
uint64_t _is_immune_to_spell_of_beckoning : 1 {}; // Can be removed by negation
243-
uint64_t _is_immune_to_spell_of_holding : 1 {}; // Can be removed by negation
244-
uint64_t _is_immune_to_spell_of_repulsion : 1 {}; // Can be removed by negation
245-
uint64_t _is_immune_to_spell_of_sanctuary : 1 {}; // Can be removed by negation
246-
uint64_t _is_immune_to_spell_of_slowness : 1 {}; // Can be removed by negation
247-
uint64_t _is_immune_to_spiderwebs : 1 {}; // Can be removed by negation
248-
uint64_t _is_immune_to_stamina_drain : 1 {}; // Can be removed by negation
249-
uint64_t _is_immune_to_teleport_attack : 1 {}; // Can be removed by negation
250-
uint64_t _is_immune_to_vorpal_weapons : 1 {}; // Can be removed by negation
251-
uint64_t _is_immune_to_water : 1 {}; // Can be removed by negation
252-
uint64_t is_invisible_ : 1 {}; // Updated per tick
253-
uint64_t is_jumping : 1 {}; // Is mid jump
254-
uint64_t is_key_in_lock : 1 {}; // Key stuck in rusty lock?
255-
uint64_t is_minion_set : 1 {}; // Overrides is_minion in template
256-
uint64_t is_moving : 1 {}; // Is currently moving tiles
257-
uint64_t is_open : 1 {}; // Door or chest is open
258-
uint64_t is_raging_currently : 1 {}; // Is raging currently?
259-
uint64_t is_resurrected : 1 {}; // Has finished resurrecting
260-
uint64_t is_resurrecting : 1 {}; // Is currently resurrecing
261-
uint64_t is_resurrection_blocked : 1 {}; // Blocked from resurrection
262-
uint64_t is_ring2 : 1 {}; // For 2nd rings
263-
uint64_t is_scheduled_for_death : 1 {}; // Will die in next game loop
264-
uint64_t is_scheduled_for_gc : 1 {}; // Scheduled for garbage cleanup
265-
uint64_t is_scheduled_for_jump_end : 1 {}; // Particle for jumping is present
266-
uint64_t is_seen_by_player_msg_shown : 1 {}; // Seen by player message
267-
uint64_t is_sleeping : 1 {}; // Zzz
268-
uint64_t is_teleporting : 1 {}; // Mid teleport
269-
uint64_t is_the_grid_ : 1 {}; // The backbone of the game. cached for speed
270-
uint64_t is_the_player : 1 {}; // Brave player
271-
uint64_t is_visible_to_player : 1 {}; // Can be seen by the player
272-
uint64_t is_waiting : 1 {}; // Is waiting on this tick
273-
uint64_t is_waiting_to_ascend_dungeon : 1 {}; // Temporary state while changing levels
274-
uint64_t is_waiting_to_ascend_sewer : 1 {}; // Temporary state while changing levels
275-
uint64_t is_waiting_to_descend_dungeon : 1 {}; // Temporary state while changing levels
276-
uint64_t is_waiting_to_descend_sewer : 1 {}; // Temporary state while changing levels
277-
uint64_t is_waiting_to_leave_level_has_completed_fall : 1 {}; // Has fallen to the next level
278-
uint64_t is_wounded_msg : 1 {}; // Avoid duplicate messages
279-
uint64_t was_frozen : 1 {}; // Was frozen at the start of the tick
195+
uint64_t corpse_cleanup : 1 {}; // Used to remove corpses when eaten or burnt
196+
uint64_t gfx_ascii_animated : 1 {}; // Animated in ascii mode?
197+
uint64_t gfx_pixelart_animated : 1 {}; // Animated in pixelart mode?
198+
uint64_t has_attacked_player : 1 {}; // Has it attacked the precious?
199+
uint64_t has_ever_moved : 1 {}; // Has it ever moved? e.g. a gargoyle
200+
uint64_t has_light : 1 {}; // Has it a light source?
201+
uint64_t has_projectile : 1 {}; // Current projectile being fired
202+
uint64_t has_seen_player_msg_shown : 1 {}; // Seen by player has been shown
203+
uint64_t _is_able_to_be_resurrected : 1 {}; // Can be removed by negation
204+
uint64_t _is_able_to_regenerate : 1 {}; // Can be removed by negation
205+
uint64_t is_newborn : 1 {1}; // Used to call on_born on level enter
206+
uint64_t is_activated : 1 {}; // This skill is activated
207+
uint64_t is_attached : 1 {}; // Is attached to the level
208+
uint64_t is_auto_equip_done : 1 {}; // Has initially auto equipped itself
209+
uint64_t is_being_destroyed : 1 {}; // In the process of deleting the thing
210+
uint64_t is_bouncing : 1 {}; // Is graphically bouncing
211+
uint64_t is_burnt : 1 {}; // Burnt by ice and cannot move
212+
uint64_t is_changing_level : 1 {}; // Is in the process of changing level
213+
uint64_t is_dead : 1 {}; // It's dead Jim
214+
uint64_t is_discorded : 1 {}; // Will attack what normally it would not
215+
uint64_t is_discovered : 1 {}; // Can you see that secret door?
216+
uint64_t is_drained : 1 {}; // E.g. enchant or skillstone used up
217+
uint64_t is_dying : 1 {}; // Is currently in the throes of death
218+
uint64_t is_facing_left : 1 {}; // It's in the process of dying
219+
uint64_t is_fadeup : 1 {}; // For text that fades upwards
220+
uint64_t is_falling : 1 {}; // Falling to a new level
221+
uint64_t is_floating_ : 1 {}; // Updated per tick
222+
uint64_t is_frozen : 1 {}; // Frozen by ice and cannot move
223+
uint64_t is_hidden : 1 {}; // Carried perhaps and hence not visible
224+
uint64_t is_hunger_level_gorged : 1 {}; // Hunger levels
225+
uint64_t is_hunger_level_hungry : 1 {}; // Hunger levels
226+
uint64_t is_hunger_level_satiated : 1 {}; // Hunger levels
227+
uint64_t is_hunger_level_starving : 1 {}; // Hunger levels
228+
uint64_t _is_immune_to_acid : 1 {}; // Can be removed by negation
229+
uint64_t _is_immune_to_blinding : 1 {}; // Can be removed by negation
230+
uint64_t _is_immune_to_cold : 1 {}; // Can be removed by negation
231+
uint64_t _is_immune_to_confusion : 1 {}; // Can be removed by negation
232+
uint64_t _is_immune_to_electricity : 1 {}; // Can be removed by negation
233+
uint64_t _is_immune_to_entrancement : 1 {}; // Can be removed by negation
234+
uint64_t _is_immune_to_fire : 1 {}; // Can be removed by negation
235+
uint64_t _is_immune_to_holy_damage : 1 {}; // Can be removed by negation
236+
uint64_t _is_immune_to_lightning : 1 {}; // Can be removed by negation
237+
uint64_t _is_immune_to_magic_drain : 1 {}; // Can be removed by negation
238+
uint64_t _is_immune_to_necrosis : 1 {}; // Can be removed by negation
239+
uint64_t _is_immune_to_negation : 1 {}; // Can be removed by negation
240+
uint64_t _is_immune_to_non_magical_weapons : 1 {}; // Can be removed by negation
241+
uint64_t _is_immune_to_paralysis : 1 {}; // Can be removed by negation
242+
uint64_t _is_immune_to_poison : 1 {}; // Can be removed by negation
243+
uint64_t _is_immune_to_spell_of_beckoning : 1 {}; // Can be removed by negation
244+
uint64_t _is_immune_to_spell_of_holding : 1 {}; // Can be removed by negation
245+
uint64_t _is_immune_to_spell_of_repulsion : 1 {}; // Can be removed by negation
246+
uint64_t _is_immune_to_spell_of_sanctuary : 1 {}; // Can be removed by negation
247+
uint64_t _is_immune_to_spell_of_slowness : 1 {}; // Can be removed by negation
248+
uint64_t _is_immune_to_spiderwebs : 1 {}; // Can be removed by negation
249+
uint64_t _is_immune_to_stamina_drain : 1 {}; // Can be removed by negation
250+
uint64_t _is_immune_to_teleport_attack : 1 {}; // Can be removed by negation
251+
uint64_t _is_immune_to_vorpal_weapons : 1 {}; // Can be removed by negation
252+
uint64_t _is_immune_to_water : 1 {}; // Can be removed by negation
253+
uint64_t is_invisible_ : 1 {}; // Updated per tick
254+
uint64_t is_jumping : 1 {}; // Is mid jump
255+
uint64_t is_key_in_lock : 1 {}; // Key stuck in rusty lock?
256+
uint64_t is_minion_set : 1 {}; // Overrides is_minion in template
257+
uint64_t is_moving : 1 {}; // Is currently moving tiles
258+
uint64_t is_open : 1 {}; // Door or chest is open
259+
uint64_t is_raging_currently : 1 {}; // Is raging currently?
260+
uint64_t is_resurrected : 1 {}; // Has finished resurrecting
261+
uint64_t is_resurrecting : 1 {}; // Is currently resurrecing
262+
uint64_t is_resurrection_blocked : 1 {}; // Blocked from resurrection
263+
uint64_t is_ring2 : 1 {}; // For 2nd rings
264+
uint64_t is_scheduled_for_death : 1 {}; // Will die in next game loop
265+
uint64_t is_scheduled_for_gc : 1 {}; // Scheduled for garbage cleanup
266+
uint64_t is_scheduled_for_jump_end : 1 {}; // Particle for jumping is present
267+
uint64_t is_seen_by_player_msg_shown : 1 {}; // Seen by player message
268+
uint64_t is_sleeping : 1 {}; // Zzz
269+
uint64_t is_teleporting : 1 {}; // Mid teleport
270+
uint64_t is_the_grid_ : 1 {}; // The backbone of the game. cached for speed
271+
uint64_t is_the_player : 1 {}; // Brave player
272+
uint64_t is_visible_to_player : 1 {}; // Can be seen by the player
273+
uint64_t is_waiting : 1 {}; // Is waiting on this tick
274+
uint64_t is_waiting_to_ascend_dungeon : 1 {}; // Temporary state while changing levels
275+
uint64_t is_waiting_to_ascend_sewer : 1 {}; // Temporary state while changing levels
276+
uint64_t is_waiting_to_descend_dungeon : 1 {}; // Temporary state while changing levels
277+
uint64_t is_waiting_to_descend_sewer : 1 {}; // Temporary state while changing levels
278+
uint64_t is_waiting_to_leave_level_has_completed_fall : 1 {}; // Has fallen to the next level
279+
uint64_t is_wounded_msg : 1 {}; // Avoid duplicate messages
280+
uint64_t was_frozen : 1 {}; // Was frozen at the start of the tick
280281
// end sort marker1 }
281282

282283
//
@@ -3004,6 +3005,7 @@ typedef class Thing_
30043005
void inherit_from(Thingp it);
30053006
void init_hue(void);
30063007
void init(Levelp, const std::string &name, point at, Thingp owner = nullptr);
3008+
void init_slower_stuff(void);
30073009
void init_lights(void);
30083010
void interpolated_at_set(fpoint v);
30093011
void inventory_particle(Thingp what, int slot);

src/thing_init.cpp

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -278,26 +278,6 @@ void Thing::init(Levelp level, const std::string &name_in, const point born, Thi
278278
return;
279279
}
280280

281-
//
282-
// Create the large player dmap
283-
//
284-
if (is_player()) {
285-
level->player = this;
286-
level->dmap_to_player_update();
287-
}
288-
289-
//
290-
// Add AI ability
291-
//
292-
if (is_monst() || is_player()) {
293-
clear_age_map();
294-
clear_dmap_can_see_old();
295-
clear_interrupt_map();
296-
clear_dmap_can_see();
297-
clear_can_see_currently();
298-
clear_can_see_ever();
299-
}
300-
301281
//
302282
// Start off up to data with the player
303283
//
@@ -323,35 +303,13 @@ void Thing::init(Levelp level, const std::string &name_in, const point born, Thi
323303
bounce(0.3, 1.0, 400 + pcg_random_range(0, 100), 255);
324304
}
325305

326-
//
327-
// Init light sources like torches
328-
//
329-
init_lights();
330-
331-
//
332-
// Initialize random color spread.
333-
//
334-
init_hue();
335-
336306
//
337307
// e.g. staff charges
338308
//
339309
if (unlikely(tpp->charge_count())) {
340310
charge_count_set(tpp->charge_count());
341311
}
342312

343-
//
344-
// Do on born actions.
345-
//
346-
on_born();
347-
348-
//
349-
// In case we carry something here, check for equipping
350-
//
351-
if (is_player() || is_monst()) {
352-
update();
353-
}
354-
355313
//
356314
// Mainly for explosions
357315
//
@@ -402,6 +360,47 @@ void Thing::init(Levelp level, const std::string &name_in, const point born, Thi
402360
}
403361
}
404362

363+
void Thing::init_slower_stuff(void)
364+
{
365+
TRACE_NO_INDENT();
366+
367+
verify(MTYPE_THING, this);
368+
369+
//
370+
// Add AI ability
371+
//
372+
if (is_monst() || is_player()) {
373+
clear_age_map();
374+
clear_dmap_can_see_old();
375+
clear_interrupt_map();
376+
clear_dmap_can_see();
377+
clear_can_see_currently();
378+
clear_can_see_ever();
379+
}
380+
381+
//
382+
// Init light sources like torches
383+
//
384+
init_lights();
385+
386+
//
387+
// Initialize random color spread.
388+
//
389+
init_hue();
390+
391+
//
392+
// In case we carry something here, check for equipping
393+
//
394+
if (is_player() || is_monst()) {
395+
update();
396+
}
397+
398+
//
399+
// Call python if needed
400+
//
401+
on_born();
402+
}
403+
405404
void Thing::reinit(void)
406405
{
407406
TRACE_NO_INDENT();

0 commit comments

Comments
 (0)