Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmable Logic Controller #816

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Timfa2112
Copy link

@Timfa2112 Timfa2112 commented Aug 29, 2024

Description

A PLC, or Programmable Logic Controller, which interfaces with the wireless Device Linking system.
Build the PLC, write Spessembly code and have your PLC control and read from any attached devices.

You could use these PLC's to add dynamic behaviour to anything that you can link together with your multitool. Think airlocks that actually pump in or out air before cycling, more complex behaviour in conveyor belts, longer sequences of events when pressing buttons or levers, automating linked devices based on pressure, temperature, time, light intensity, etc. etc.


TODO

  • C# class that can interpret assembly-like code
  • defining input and output registers in the assembly-interpreter
  • complete assembly-like language (working title Spessembly)
  • Creating the boilerplate code needed for the entity to exist and do things in the world
  • connecting Device Linking signals and sending integers over the connection for sensors
  • Sprites!
  • Buildable object via build menu, something simple like steel and lv cable
  • GUI the user can type text in, which also displays console output
  • dynamically adding device linking inputs and outputs

Media

Example Media Embed


Changelog

🆑 Alia Ash

  • add: Added Programmable Logic Controller

possibly not correct yet
@github-actions github-actions bot added the Changes: YML Changes any yml files label Aug 29, 2024
@Timfa2112 Timfa2112 marked this pull request as draft August 29, 2024 06:50
@github-actions github-actions bot added the Changes: C# Changes any cs files label Aug 29, 2024
@BasedUser
Copy link
Contributor

BasedUser commented Aug 29, 2024

no way mlog ss14

image

public const int HIGH = 100;
public const int LOW = 0;

private string[] code = Array.Empty<string>();
Copy link
Contributor

@BasedUser BasedUser Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally these should be non-string as string comparisons can take a LOT of time, something like:

private string code = "";
private string instructions = Array.Empty<PLCInstruction>();

// ...

public class PLCInstruction
{
    // yml hooks??? idfk maybe i'm getting WAY too inspired
    public string Name = "Invalid";
    public string Opcode = "nop";
    
    public virtual void Run(PLCVar[] args)
    {
        //Logger.Info("Ran instruction " + self.Name);
        return;
    }
}

public class AddI : PLCInstruction
{
    Name = "Add";
    Opcode = "add";
    
    public override void Run(PLCVar[] args)
    {
        if (args.Length < 3)
            return;
        args[2].SetValue(args[0].Value() + args[1].Value())
        return;
    }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code[] array is the actual text typed by the player, so I'd need to load it all in and then convert it to a separate array with instructions. Still have to check the strings, but then I do it only once instead of every step.
Probably a good idea, but I'm going to focus on getting it to work, and then optimising it after a working version is achieved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionally throw NMIs instead of returning void lmao

@github-actions github-actions bot added the Changes: Localization Changes any ftl files label Aug 29, 2024
- type: entity
id: PLC
name: plc
description: It's a programmable logic controller.
Copy link
Contributor

@Mnemotechnician Mnemotechnician Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should inherit from BaseStructure. Transform, Clickable, TnteractionOutline, Damageable will all be unnecessary as they are defined in BaseStructure.

Alternatively, you could create a machine board and make this inherit from BaseMachine - in that case you'll need to look into how other machines (e.g. autolathe) do it. It will eliminate the need for this entity to have its own unique construction graph/recipe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention is to keep it simple.
How do I inherit from BaseStructure? Do I just remove those types under components and replace them with one BaseStructure type?

Copy link
Contributor

@Mnemotechnician Mnemotechnician Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, add parent: BaseStructure. Then navigate to the BaseStructure type, look what components it already has that were re-defined in your type, and remove them. If the parent entity defines a component but does not set up all the fields you want, you can still add the same component to the child entity and only set up the fields that were not set up in the parent entity. In that case, The rest of the fields will be inherited from the parent.

@Mnemotechnician
Copy link
Contributor

Is this being worked on?

@Timfa2112
Copy link
Author

Is this being worked on?

I try to figure things out now and then, but I haven't had time in the past few days.
Because I'm still very unfamiliar with how the device linking works, as well as making GUI and ensuring the entity to be placed in the world functions properly, I've attempted to find someone who wants to collaborate on this and fill in the gaps of my knowledge, but I've had no luck with that yet.

So, in short, it's had no progress on a while, but I haven't given up yet :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes: C# Changes any cs files Changes: Localization Changes any ftl files Changes: YML Changes any yml files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants