Skip to content

Commit

Permalink
Fix bug when notification was not displayed correctly (scheme called …
Browse files Browse the repository at this point in the history
…name of icon, not value). Fix issue when antenna manager caused no sound. Fixed cases where math.pow should be used instead of XOR.
  • Loading branch information
Neloreck committed Sep 14, 2023
1 parent 3472e81 commit a2683eb
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 129 deletions.
6 changes: 2 additions & 4 deletions src/engine/core/managers/debug/ProfilingManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { profile_timer } from "xray16";
import { flush, profile_timer } from "xray16";

import { AbstractManager } from "@/engine/core/managers/base/AbstractManager";
import { abort } from "@/engine/core/utils/assertion";
import { executeConsoleCommand } from "@/engine/core/utils/game/game_console";
import { LuaLogger } from "@/engine/core/utils/logging";
import { gameConfig } from "@/engine/lib/configs/GameConfig";
import { consoleCommands } from "@/engine/lib/constants/console_commands";
import { AnyCallable, Optional, ProfileTimer, TCount, TName } from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);
Expand Down Expand Up @@ -168,7 +166,7 @@ export class ProfilingManager extends AbstractManager {
logger.info("==================================================================================================");
logger.pushEmptyLine();

executeConsoleCommand(consoleCommands.flush);
flush();

this.setupHook(this.mode, true);
}
Expand Down
15 changes: 15 additions & 0 deletions src/engine/core/managers/notifications/NotificationManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,21 @@ describe("NotificationManager class", () => {
0
);

notificationManager.onPlayPdaNotificationSound = jest.fn();
notificationManager.onSendGenericNotification = jest.fn();
notificationManager.sendTipNotification("test_simple", "can_resupply", 200, 555, "test");

expect(notificationManager.onPlayPdaNotificationSound).toHaveBeenCalledTimes(1);
expect(notificationManager.onSendGenericNotification).toHaveBeenCalledWith(
false,
"translated_st_tip",
"translated_test_simple",
"ui_inGame2_Pered_zadaniyami_voennih",
200,
555,
0
);

registerStoryLink(registry.actor.id(), "test-sid");

MockAlifeSimulator.addToRegistry(
Expand Down
10 changes: 7 additions & 3 deletions src/engine/core/managers/notifications/NotificationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class NotificationManager extends AbstractManager {
*/
public sendTipNotification(
caption: TLabel,
sender: Optional<TNotificationIcon | ClientObject> = null,
sender: Optional<TNotificationIcon | TNotificationIconKey | ClientObject> = null,
delay: Optional<TDuration> = 0,
showtime: Optional<TTimestamp> = NotificationManager.DEFAULT_NOTIFICATION_SHOW_DURATION,
senderId: Optional<TStringId> = null
Expand Down Expand Up @@ -272,8 +272,12 @@ export class NotificationManager extends AbstractManager {

// If sender is game object, check sender character icon to display instead of generic one.
if (sender !== null) {
notificationIcon =
type(sender) === "string" ? (sender as TNotificationIcon) : (sender as ClientObject).character_icon();
// In case of string check if it is name of icon (original schemas use it) or fallback to just string.
if (type(sender) === "string") {
notificationIcon = notificationsIcons[sender as TNotificationIconKey] || (sender as TNotificationIcon);
} else {
notificationIcon = (sender as ClientObject).character_icon();
}
}

this.onPlayPdaNotificationSound();
Expand Down
199 changes: 94 additions & 105 deletions src/engine/core/managers/psy/PsyAntennaManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import {
TProbability,
TRate,
TSoundObjectType,
TTimestamp,
Vector,
} from "@/engine/lib/types";

const logger: LuaLogger = new LuaLogger($filename);
const logger: LuaLogger = new LuaLogger($filename, { file: "psy" });

/**
* todo;
Expand Down Expand Up @@ -82,11 +83,10 @@ export class PsyAntennaManager extends AbstractManager {
public phantomFov: number = 45;

public hitAmplitude: number = 1.0;
public effTime: number = 0;

public hitTime: TDuration = 0;
public phantomTime: TDuration = 0;
public phantomIdle: TDuration = 0;
public phantomIdle: TDuration = math.random(2000, 5000);

public intensityInertion: TRate = 0.05;
public hitIntensity: TRate = 0;
Expand All @@ -113,19 +113,13 @@ export class PsyAntennaManager extends AbstractManager {
this.soundObjectRight.volume = 0;
}

/**
* todo: Description.
*/
public override initialize(): void {
const eventsManager: EventsManager = EventsManager.getInstance();

eventsManager.registerCallback(EGameEvent.ACTOR_UPDATE, this.update, this);
eventsManager.registerCallback(EGameEvent.ACTOR_DESTROY, this.dispose, this);
}

/**
* todo: Description.
*/
public override destroy(): void {
const eventsManager: EventsManager = EventsManager.getInstance();

Expand All @@ -134,63 +128,42 @@ export class PsyAntennaManager extends AbstractManager {

this.soundObjectRight.stop();
this.soundObjectLeft.stop();

level.set_snd_volume(this.sndVolume);

get_hud().enable_fake_indicators(false);
}

/**
* Dispose current instance in registry.
* Handle disposal of manager on actor destroy.
*/
public dispose(): void {
logger.info("Dispose psy antenna manager");
PsyAntennaManager.dispose();
}

/**
* todo: Description.
*/
public updatePsyHit(dt: number): void {
const hud: GameHud = get_hud();
const customStatic: Optional<StaticDrawableWrapper> = hud.GetCustomStatic("cs_psy_danger");

if (this.hitIntensity > 0.0001) {
if (customStatic === null && !this.noStatic) {
hud.AddCustomStatic("cs_psy_danger", true);
hud.GetCustomStatic("cs_psy_danger")!.wnd().TextControl().SetTextST("st_psy_danger");
}
} else {
if (customStatic !== null) {
hud.RemoveCustomStatic("cs_psy_danger");
}
}
public generatePhantoms(): void {
const now: TTimestamp = time_global();

if (time_global() - this.hitTime > this.hitFreq) {
this.hitTime = time_global();
if (now - this.phantomTime > this.phantomIdle) {
logger.info("Generate phantoms");

const power: number = this.hitAmplitude * this.hitIntensity;
this.phantomTime = now;
this.phantomIdle = math.random(5000, 10000);

if (power > 0.0001) {
if (math.random() < this.phantomSpawnProbability) {
const actor: ClientObject = registry.actor;
const psyHit: Hit = new hit();

psyHit.power = power;
psyHit.direction = createEmptyVector();
psyHit.impulse = 0;
psyHit.draftsman = actor;

const hitValue: TRate = (power <= 1 && power) || 1;

if (this.hitType === "chemical") {
get_hud().update_fake_indicators(2, hitValue);
psyHit.type = hit.chemical_burn;
} else {
get_hud().update_fake_indicators(3, hitValue);
psyHit.type = hit.telepatic;
}
const phantomManager: PhantomManager = PhantomManager.getInstance();

actor.hit(psyHit);
if (phantomManager.phantomsCount < this.phantomMax) {
const radius: TDistance = this.phantomSpawnRadius * (math.random() * 0.5 + 0.5);
const angle: TRate = this.phantomFov * math.random() - this.phantomFov * 0.5;
const direction: Vector = vectorRotateY(actor.direction(), angle);

if (actor.health < 0.0001 && actor.alive()) {
actor.kill(actor);
phantomManager.spawnPhantom(actor.position().add(direction.mul(radius)));
}
}
}
Expand All @@ -199,35 +172,46 @@ export class PsyAntennaManager extends AbstractManager {
/**
* todo: Description.
*/
public generatePhantoms(): void {
if (this.phantomIdle === null) {
this.phantomIdle = math.random(2000, 5000);
}
public override update(delta: TDuration): void {
logger.info("Updating psy antenna manager:", delta);

if (time_global() - this.phantomTime > this.phantomIdle) {
this.phantomTime = time_global();
this.phantomIdle = math.random(5000, 10000);
const updateIntensity = (intensityBase: TRate, intensity: TRate) => {
const di = this.intensityInertion * delta * 0.01;
let ii = intensityBase;

if (math.random() < this.phantomSpawnProbability) {
const actor: ClientObject = registry.actor;
const phantomManager: PhantomManager = PhantomManager.getInstance();
if (math.abs(intensityBase - intensity) >= di) {
ii = intensityBase < intensity ? intensity - di : intensity + di;
}

if (phantomManager.phantomsCount < this.phantomMax) {
const radius: TDistance = this.phantomSpawnRadius * (math.random() / 2.0 + 0.5);
const angle: TRate = this.phantomFov * math.random() - this.phantomFov * 0.5;
const dir: Vector = vectorRotateY(actor.direction(), angle);
return clampNumber(ii, 0.0, 1.0);
};

phantomManager.spawnPhantom(actor.position().add(dir.mul(radius)));
}
this.generatePhantoms();

if (!this.noMumble) {
this.soundIntensity = updateIntensity(this.soundIntensityBase, this.soundIntensity);
this.updateSound();
}

for (const [k, v] of this.postprocess) {
v.intensity = updateIntensity(v.intensityBase, v.intensity);

if (!this.updatePostprocess(v)) {
this.postprocess.delete(k);
}
}

this.updatePsyHit(delta);
}

/**
* todo: Description.
*/
public updateSound(): void {
if (!this.soundInitialized) {
logger.info("Initialize sounds");

this.soundInitialized = true;
this.soundObjectLeft.play_at_pos(
registry.actor,
createVector(-1, 0, 1),
Expand All @@ -240,76 +224,84 @@ export class PsyAntennaManager extends AbstractManager {
0,
(ESoundObjectType.S2D + ESoundObjectType.S3D) as TSoundObjectType
);

this.soundInitialized = true;
}

const vol = 1 - (this.soundIntensity ^ 3) * 0.9;
const volume: TRate = 1 - Math.pow(this.soundIntensity, 3) * 0.9;
const antennaVolume: TRate = 1 / volume - 1;

if (vol < this.muteSoundThreshold) {
level.set_snd_volume(this.muteSoundThreshold);
} else {
level.set_snd_volume(vol);
}
level.set_snd_volume(volume < this.muteSoundThreshold ? this.muteSoundThreshold : volume);

this.soundObjectLeft.volume = 1 / vol - 1;
this.soundObjectRight.volume = 1 / vol - 1;
this.soundObjectLeft.volume = antennaVolume;
this.soundObjectRight.volume = antennaVolume;
}

/**
* todo: Description.
*/
public updatePostprocess(pp: IPsyPostProcessDescriptor): boolean {
if (pp.intensity === 0) {
this.postprocessCount = this.postprocessCount - 1;
this.postprocessCount -= 1;
level.remove_pp_effector(pp.idx);

return false;
}

level.set_pp_effector_factor(pp.idx, pp.intensity, 0.3);
} else {
level.set_pp_effector_factor(pp.idx, pp.intensity, 0.3);

return true;
return true;
}
}

/**
* todo: Description.
*/
public override update(delta: TDuration): void {
this.effTime = this.effTime + delta;

const updateIntensity = (intensityBase: TRate, intensity: TRate) => {
const di = this.intensityInertion * delta * 0.01;
let ii = intensityBase;
public updatePsyHit(delta: number): void {
const hud: GameHud = get_hud();
const customStatic: Optional<StaticDrawableWrapper> = hud.GetCustomStatic("cs_psy_danger");

if (math.abs(intensityBase - intensity) >= di) {
ii = intensityBase < intensity ? intensity - di : intensity + di;
if (this.hitIntensity > 0.0001) {
if (customStatic === null && !this.noStatic) {
hud.AddCustomStatic("cs_psy_danger", true);
hud.GetCustomStatic("cs_psy_danger")!.wnd().TextControl().SetTextST("st_psy_danger");
}
} else {
if (customStatic !== null) {
hud.RemoveCustomStatic("cs_psy_danger");
}
}

return clampNumber(ii, 0.0, 1.0);
};
if (time_global() - this.hitTime > this.hitFreq) {
this.hitTime = time_global();

this.generatePhantoms();
const power: number = this.hitAmplitude * this.hitIntensity;

if (!this.noMumble) {
this.soundIntensity = updateIntensity(this.soundIntensityBase, this.soundIntensity);
this.updateSound();
}
if (power > 0.0001) {
const actor: ClientObject = registry.actor;
const psyHit: Hit = new hit();

for (const [k, v] of this.postprocess) {
v.intensity = updateIntensity(v.intensityBase, v.intensity);
psyHit.power = power;
psyHit.direction = createEmptyVector();
psyHit.impulse = 0;
psyHit.draftsman = actor;

if (!this.updatePostprocess(v)) {
this.postprocess.delete(k);
const hitValue: TRate = (power <= 1 && power) || 1;

if (this.hitType === "chemical") {
get_hud().update_fake_indicators(2, hitValue);
psyHit.type = hit.chemical_burn;
} else {
get_hud().update_fake_indicators(3, hitValue);
psyHit.type = hit.telepatic;
}

actor.hit(psyHit);

if (actor.health < 0.0001 && actor.alive()) {
actor.kill(actor);
}
}
}

this.updatePsyHit(delta);
}

/**
* todo: Description.
*/
public override save(packet: NetPacket): void {
openSaveMarker(packet, PsyAntennaManager.name);

Expand All @@ -334,9 +326,6 @@ export class PsyAntennaManager extends AbstractManager {
closeSaveMarker(packet, PsyAntennaManager.name);
}

/**
* todo: Description.
*/
public override load(reader: NetProcessor): void {
openLoadMarker(reader, PsyAntennaManager.name);

Expand Down
Loading

0 comments on commit a2683eb

Please sign in to comment.