joo
joo
Explore posts from servers
CC#
Created by joo on 12/2/2024 in #help
Source code generation not working with partial record, only with partial class
Using a basic incremental source code generator to generate some serializer-like functionality.
c#
[Generators.Pkt]
public partial record/class ChatMsgReq
{
public int Ticks { get; set; }
public required string Msg { get; set; }
public bool OnlyBalloon { get; set; }
}
c#
[Generators.Pkt]
public partial record/class ChatMsgReq
{
public int Ticks { get; set; }
public required string Msg { get; set; }
public bool OnlyBalloon { get; set; }
}
Generated Code: * Record:
c#

// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
c#

// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial record ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
* Class:
c#
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
c#
// <auto-generated/>

using System;
using System.Collections.Generic;

using A.Net;

namespace A.Proto;

public partial class ChatMsgReq : IDecodePacket<ChatMsgReq>, IEncodePacket
{
public static ChatMsgReq DecodePacket(ref PacketReader r)
{
return new ChatMsgReq
{
Ticks = r.ReadInt(),
Msg = r.ReadString(),
OnlyBalloon = r.ReadBool(),
};
}

public void EncodePacket(ref PacketWriter w)
{
w.WriteInt(Ticks);
w.WriteString(Msg);
w.WriteBool(OnlyBalloon);
}
}
With class I can access DecodePacket and EncodePacket just fine, however for the record I'm unable to access It. Also If I copy the partial record without any source code just below the original record It works fine aswell. Any Idea why this isn't working for records?
9 replies
DDeno
Created by joo on 9/22/2023 in #help
'Spawn' multiple promises from the same module
I'm trying to use Deno for scripted npcs in a game, the main issue that the npc has to await user action so I've used a mpsc Channel for this with an async fn op which works fine. However since the npcs exists on the server side I need to be able to call the same npc multiple times on the same runtime. My current test script looks like this
// actor would be the current actor object
async function npc_action_1000(actor) {
Deno.core.print("Started script for player " + actor + "\n");
let action = await Deno.core.ops.op_wait_action(actor);
if(action === "0") {
Deno.core.print("First selection\n");
} else {
Deno.core.print("Other selection\n");
}
}

globalThis.npc_action_1000 = npc_action_1000;
// actor would be the current actor object
async function npc_action_1000(actor) {
Deno.core.print("Started script for player " + actor + "\n");
let action = await Deno.core.ops.op_wait_action(actor);
if(action === "0") {
Deno.core.print("First selection\n");
} else {
Deno.core.print("Other selection\n");
}
}

globalThis.npc_action_1000 = npc_action_1000;
The problem I'm facing right now, I'd like to load the module once, remove the await in the end and then spawn multiple npc_actions while the event loop is running. So far I was only able to get a Local reference to the function, but when I call It I can no longer run the ev loop because the scope references the runtime. What would be the best way to approach that?
4 replies