New Animations/positions. And a question about wiring.

#1
Unsure if you have or haven't thought of it yet, however having the ability to crouch or crawl. Generally any other position then stand would be pretty useful, and also widen the verity of the types of ships that could be built too. Crawl spaces for example, to save room for storage, or more important areas. Maybe if someone wanted to make a sub with tight corridors, and such.

I myself haven't done alot of wiring with the gates, however a friend of mine is complaining about the gates not functioning, or functioning properly? Is it a known bug, or is there a specific way to use them such as needing power to operate and things.

Re: New Animations/positions. And a question about wiring.

#2
Immun1ty wrote:Unsure if you have or haven't thought of it yet, however having the ability to crouch or crawl. Generally any other position then stand would be pretty useful, and also widen the verity of the types of ships that could be built too. Crawl spaces for example, to save room for storage, or more important areas. Maybe if someone wanted to make a sub with tight corridors, and such.
I've actually added that already: doctors needed the ability to crouch in order to perform CPR and use syringes on unconscious/stunned players, but it will definitely be useful from sub design perspective as well. It also makes it possible to attach devices (like water detectors) at the bottom of a room.
Immun1ty wrote:I myself haven't done alot of wiring with the gates, however a friend of mine is complaining about the gates not functioning, or functioning properly? Is it a known bug, or is there a specific way to use them such as needing power to operate and things.
They don't need power to operate. I don't think I can help if your friend can't provide more info about the problems he's having. It could be that he's somehow misunderstood how some of the logic gates work - in that case taking a look at how the wiring is done in the vanilla subs might help.

Re: New Animations/positions. And a question about wiring.

#4
Making an account was a pain, but I needed to in order to explain the issues with the logical wiring system.

So the issue is the wiring system is using a "trigger" system, That is every time a signal is "pulsed" it "triggers" the component it is wired into.
Now all of the "logical" components i've found compute the logic using the pulses.
Ex:
AND gate - Two Signals pulse in a set amount of time, it computes the logic corresponding.

Problem with this system beyond the obvious, "Pulses shouldn't dictate logic" is if you loop components.
Now I created a few Actual logic gates using the fantastic Signal Check component. I can create AND, and OR gates dependent on if the values are 1's or 0's;
However I cannot create "state" logical components like latches because if you take the output of a component and loop it back into and input of a component that is used to produce its own output it creates an infinite loop.
Ex:
I have two NOR gates with inputs A,B and output of O that will be denoted A1,B1,O1,A2,B2 and O2.
A1 and A2 are inputs for the SR latch.
B1 connects to O2, B2 connects to O1.

Now what'll happen is A1 will trigger NOR1 which will trigger O1 to then trigger B2 which triggers NOR2 which triggers O2, that triggers B1 which triggers NOR1.
Start the infinite loops.


Simple solution:
only allow each component to trigger ONCE per TICK.

Better solution:
Continue to only allow each component to trigger ONCE per TICK, and actually use a logic system based off of the VALUES of the signal and only use the Pulse to recalculate the logic in a component.


As for the power system and all that, you're fine.
I really like the game, but the logic errks me to no end.

Re: New Animations/positions. And a question about wiring.

#5
Thanks for the clarification, the infinite loops are an obvious bug that I'll have to fix. However, I don't really understand what you mean by
LordZZT wrote:Continue to only allow each component to trigger ONCE per TICK, and actually use a logic system based off of the VALUES of the signal and only use the Pulse to recalculate the logic in a component.
The logic system does work based off the the values of the signal. For example, AND components check whether both of the signals equal to "1" (or actually any non-zero signal).

Re: New Animations/positions. And a question about wiring.

#6
I didn't realize it was a logical and gate, i never got it to work correctly; plus as for an and gate having a time stipulation doesn't make alot of sense.

As far as only triggering once per tick i'll clarify.
Start by having a Tick count. Create a variable call it Tick and initialize it to 0 on server start. Every logic tick increment the tick (tick++ depending on lang).
Now only calculate a components output once per tick, How?
I'll do it in Java:

Code: Select all

public class logicComponent {
    int lastRan = 0;
    int value = 0;
    
    HashMap<String,logicComponent> inputs = new HashMap<String,logicComponent>();
    HashMap<String,logicComponent> outputs = new HashMap<String,logicComponent>();
    
    public void triggerInput(String key) {
        int curTick = Server.getTick();
        
        if(curTick == lastRan){
            return;
        }
        
        triggerOutput();
    }
    
    public void triggerOuput(){
        computeValue();
        
        logicComponent chip;
        
        for(String key : values.keys()){
            chip = outputs.get(key);
            
            if(chip != None){
                chip.triggerInput(key);
            }
        }
    }
    
    public void computeValue(){
        //Do Nothing
    }
    
    public int getValue(String inputKey){
        logicComponent chip = inputs.get(inputKey);
        
        if(chip == None){
            return 0;
        }
        
        return chip.value;
    }
}

public class GateAND extends logicComponent {
    @Override
    public void computeValue(){
        value = ((getValue("A") != 0) && (getValue("B') != 0)) ? 1 : 0;
    }
}

public class GateOR extends logicComponent {
    @Override
    public void computeValue(){
        value = ((getValue("A") != 0) || (getValue("B') != 0)) ? 1 : 0;
    }
}
Basically boils down to Any time an input is changed, or even pulsed the gate will recalculate (triggering other gate's inputs) only if it hasn't been recalculated this frame(tick).
This simple solution however does have a draw back, and that is if more then one input is triggered per tick, the gate will not recalculate next tick unless an input is triggered again.
I'll outline:

Tick 1, Time 0ms: AndGate.inputA = 1; inputA = 1, inputB = 0;
Tick 1, Time 0ms: AndGate recalculate(); AndGate.output = 0;
Tick 1, Time 1ms: AndGate.inputB = 1; inputA = 1, inputB = 1;
//The gate does not recalculate because it is still on Tick 1
Tick 2, Time 2ms: AndGate.inputA = 1; inputA = 1, inputB = 1;//AKA the inputs are still the same but it forces the gate to recalculate.
Tick 2, Time 2ms: AndGate recalculate(); AndGate.output = 1;
Tick 3, Time 4ms: AndGate.inputB = 0; inputA = 1, inputB = 0;
Tick 3, Time 4ms: AndGate recalculate(); AndGate.output = 0;


Solution for this problem? Create a "Must Recalculate Que", That is, Every time a gate is NOT recalculated due to the tick issue; Put it into the "Must Recalculate Que".
Now at the start of every logic tick first remove the component from the Que, Then trigger its Input, Then move on to the next component in the Que.
The way this will work is pretty cooly, It will recalculate a bunch of components, and if any of the components should need to be calculated next tick they will automatically have re-added themselves to the "Must Recalculate Que".

If you wanted, I could write all the fixes you need, but I'd need an outline, and the language it needs to be written in.

Re: New Animations/positions. And a question about wiring.

#8
Sounds good to me, My only concern with that is doesn't that mean there could be a situation where it would create an infinite loop that wouldn't crash the game, but it would prevent the other components from running?

Also, Please Please PLEASE, can we have more components in addition to removing the time frame stipulation from the AND component.
Add, Sub, Mul, Div, Constant Value (Just has a set value)
Greater Than, Less Than, Greater Equal Than,Less Equal Then
Bitwise And, Bitwise Or

Re: New Animations/positions. And a question about wiring.

#9
LordZZT wrote:Sounds good to me, My only concern with that is doesn't that mean there could be a situation where it would create an infinite loop that wouldn't crash the game, but it would prevent the other components from running?

Also, Please Please PLEASE, can we have more components in addition to removing the time frame stipulation from the AND component.
Add, Sub, Mul, Div, Constant Value (Just has a set value)
Greater Than, Less Than, Greater Equal Than,Less Equal Then
Bitwise And, Bitwise Or
I think at that point it would be a good idea to group all the logic components into a single item

Re: New Animations/positions. And a question about wiring.

#10
True it'd be better that way, and I'd like to point you in the direction of Garrysmod's Wiremod for that, but that sort of thing would require allot of attention.
A simple solution is to had a few arithmetic gates.

In my case, my sub is alittle heavy.
When I drive it I have to pull up about 1/4th of the way so that I don't sink, Now it would be nice if I could just adjust the Yvalue before it leaves the cockpit or w/e, but otherwise If i had a simple ADD component I could fix the problem.