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

Added: Pull request for "fsensor" and "contrtrol" dedicated control theory OOP #75

Merged
merged 39 commits into from
Nov 18, 2019

Conversation

dvdvideo1234
Copy link
Contributor

Added: "fsensor" as a general environment sensor for obtaining process data
Added: "contrtrol" for creating a OOP process variable controller that can me tuned using various methods

Based on: #59

…heory OOP

Added: "fsensor" as a general environment sensor for obtaining process data
Added: "contrtrol" for creating a OOP process variable controller that can me tuned using various methods
@dvdvideo1234
Copy link
Contributor Author

@thegrb93 FYI

Tell me if you need some adjustments. The addon is updated to the latest version from my personal machine. It includes the all recent modifications. You can test it if you like 👍

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 1, 2019

Firstly get rid of all the concatenation in the e2 description file unless there's a really good reason for it. Should be a simple replace-all.

Once I can actually read the functions' descriptions then I can review them.

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 1, 2019

The idea is if something is gonna get changed in the future, it will be an update of only one value.
You can read them here: https://github.com/dvdvideo1234/ControlSystemsE2/wiki

This wiki is automatically generated from the description ;). Every OOP class has a dedicated table. The links are not stored in the description. Only the overhead text.

FSensor: https://github.com/dvdvideo1234/ControlSystemsE2/wiki/FSensor
StControl: https://github.com/dvdvideo1234/ControlSystemsE2/wiki/StControl

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 1, 2019

Exported and replaced to ease you out fsensor_descr.txt and stcontrol_descr.txt. Using this method I can dynamically generate the documentation by adding overhead to the file and compiling it 💃 The line local DSC = E2Helper.Descriptions is a micro-optimization

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 1, 2019

I'd say if you really needed to change anything, a find-replace-all would be just as easy. I'll look at your wiki page for now. My main concern is code bloat i.e. adding functions nobody will ever use and just get in the way, or functions that are just as easy to make inside e2 itself. I'll look tonight.

@Divran
Copy link
Contributor

Divran commented Aug 1, 2019

@thegrb93 keep in mind that this is wire extras, where we don't need to care as much about bloat and such. Still care a little, just not as much as the normal wire repo

@dvdvideo1234
Copy link
Contributor Author

Done. Just tell me how you like 'em ok ;)

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 2, 2019

That looks better, flash sensor needs a new name though. I had no idea what it was until I read the wiki page. It's Trace structure basically, right? Just call it a Trace structure.

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 2, 2019

Don't do manual collectgarbage()'s

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 2, 2019

Gotta leave them to the game collector then. Is it ok for ftrace, ftracer or sttrace ( Personally I like ftracer, ftrace more. Wanted to be kinda like wire rangers, but with different name. That's why I chose sensor as it is generally not measuring just distance but all sorts of things. Most of the Gmod community is English speaking instead of датчик in Russian/Bulgarian ) ?

I want my repo and the wire code to be the same as the OOP related files are concerned. The description I can generate any time in any format, so it's not big of an issue ;)

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 2, 2019

Removing the collectgarbage calls can be done only by removing the flag from remValue so I will do just that. Thanks !

Edit:
come to think of it if that is the case, then I don't need such check because it will never be used.
if(bCall) then collectgarbage() end

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 2, 2019

That looks better, flash sensor needs a new name though. I had no idea what it was until I read the wiki page. It's Trace structure basically, right? Just call it a Trace structure.

Basically, an OOP wich traces and retrieves trace result. Later you can read every aspect of this trace result. Kinda like ranger data, but not need to calculate positions directions, filters and all that stuff in every E2 tick to create a RD class. My tracer is initialized only once and uses this stuff internally ;)

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 5, 2019

Get rid of outError and outPrint or make them singleplayer only.

@dvdvideo1234
Copy link
Contributor Author

@thegrb93

What I should replace them with ? print() / error() ?

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 5, 2019

Either nothing or the core print function.

@dvdvideo1234
Copy link
Contributor Author

How can I output an error then ?

@Divran
Copy link
Contributor

Divran commented Aug 5, 2019

All E2 functions fail silently and/or return a zero equivalent value whenever there's an error. If you call the lua error function you shut down the entire chip, which is something that E2 tries to avoid.
Other E2 functions that can error, and where the error message is important (such as json decode or whatever) always have a "get error" function that you can check after.
There's very very few things in E2 that break this rule, and arguably some of them could also be changed to follow it.

The print function seems fine, but pointless. You're using the standard lua print function, and since E2 runs serverside, the user of the E2 will never see those prints. So for example the dumpConsole function literally does nothing.

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 6, 2019

Can I Leave the print statement then, to be intended for singleplayer?
Could you please tell me what I need to call to print in the console?
Or I just return 0 or nil when something fails and that's it?

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 6, 2019

Look in the debug.lua for how e2 printing works https://github.com/wiremod/wire/blob/master/lua/entities/gmod_wire_expression2/core/debug.lua

@bigdogmat
Copy link
Member

bigdogmat commented Aug 6, 2019

Or I just return 0 or nil when something fails and that's it?

Depends on the type, it's whatever you think a good default is for the value. e.g. number = 0, string = "", entity = NULL

Don't return something that isn't of the type

Also I've noticed you make fsensor nil when it's invalid, I'd recommend against that.

@dvdvideo1234
Copy link
Contributor Author

Thank you @thegrb93 @bigdogmat. I have to test how the different prints behave in my home machine because I want to be able to tell the user that something happened.

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 6, 2019

Ok. I was able to replace every occurrence of fsensor with ftracer because seems more correct that way. The OOP is basically an object that does internal tracing and gathers environment data. I've updated the wiki too. It must correspond to the code.

@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 7, 2019

Which of these will be better to replace the printing functions:

  1. Wire's Addnotify - The addon will show messages in the notification area, but the chip will not halt
  2. Player char print - Output errors in the chat area, which may be skipped by the user if the server relies on chat communication.
  3. Player print message - This seems to be a great alternative to (2.) but with more output options.

So far I'd like to use option (1.), but if the chip execution does not stop will be more likely has to be (3.), because the screen will be flooded with hint messages otherwise. What do you guys think ?

@thegrb93
Copy link
Contributor

thegrb93 commented Aug 7, 2019

Chatprint probably.

Updated: CS E2 to the latest version
@dvdvideo1234
Copy link
Contributor Author

dvdvideo1234 commented Aug 8, 2019

@thegrb93
Hello, the lasted version has been merged. I removed outPrint and outError as you sugested from both classes and replaced them with logStatus which just prints the error messages to various outputs ( def. CHAT ) without halting the E2.

-- sMsg > Message to be printed
-- oSelf > Self reference of the E2
-- nPos > Where to print the message ( HUD_% ). Defaults to chat
local function logStatus(sMsg, oSelf, nPos, ...)
  if(varEnStatus:GetBool()) then
    local nPos = tonumber(nPos) or gtPrintName[gsDefPrint]
    local oPly, oEnt = oSelf.player, oSelf.entity
    local sNam, sEID = oPly:Nick() , tostring(oEnt:EntIndex())
    local sTxt = "E2{"..sEID.."}{"..sNam.."}:ftracer:"..tostring(sMsg)
    oPly:PrintMessage(nPos, sTxt:sub(1, 200))
  end; return ...
end

@thegrb93
Copy link
Contributor

Ok. I'll look again

@dvdvideo1234
Copy link
Contributor Author

I also updated the line endings to CR-LF ( Windows ) to match the other files

@dvdvideo1234
Copy link
Contributor Author

Updated the wiki accordingly: https://github.com/dvdvideo1234/ControlSystemsE2/wiki/FTrace

thegrb93 referenced this pull request in thegrb93/wire Nov 8, 2019
@dvdvideo1234
Copy link
Contributor Author

@thegrb93 I will be able to tes it today and will show you the example code. Thanks !

@thegrb93
Copy link
Contributor

Ok

@dvdvideo1234
Copy link
Contributor Author

@thegrb93 Tested and updated with 2 bug fixes. You can find the sample code here:
https://github.com/dvdvideo1234/ControlSystemsE2/tree/master/data/Expression2

Fixed: Array to key conversion not trimming spaces in method names
@dvdvideo1234
Copy link
Contributor Author

Hello, @thegrb93, the source is ready to be merged on my side ;)

@thegrb93 thegrb93 merged commit 56a3fce into wiremod:master Nov 18, 2019
@dvdvideo1234 dvdvideo1234 deleted the control_theory branch November 18, 2019 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants