<FromGitter>
<j8r> I think I've understand what you mean, you wan to check if the method in inherited or not?
<FromGitter>
<faultyserver> you could upcast whatever object you have to that abstract type
<FromGitter>
<faultyserver> then crystal's type checking won't allow any method calls that aren't declared on that abstract type
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<faultyserver> unrelated: does anyone have an idea of how to crash a fiber from another fiber?
<FromGitter>
<bew> not possible I think
<FromGitter>
<faultyserver> that's what I'm learning :/
<FromGitter>
<faultyserver> I've got a cheating solution where I just remove the fiber from ever getting queued again, but that doesn't play well with pretty much anything else
<FromGitter>
<faultyserver> i.e., pending events will cause segfaults after the fiber gets freed, file descriptors and such won't be closed, etc
<FromGitter>
<bew> you want fiber preemption ? Don't think that'll be ever possible / wanted
<FromGitter>
<bew> what are you trying to do?
<FromGitter>
<faultyserver> I'm not super concerned about pre-emption. Working cooperatively is fine for the most part
<FromGitter>
<faultyserver> I'm trying to implement an erlang-like supervisor. One of the main features is the ability to restart all "processes" managed by the supervisor if one of them crashes
<FromGitter>
<faultyserver> with OS processes and threads, that's fairly simple
<FromGitter>
<faultyserver> you can just use signals or `pthread_cancel`
<FromGitter>
<faultyserver> but fibers are proving much more difficult to handle properly
<FromGitter>
<faultyserver> since it's all in the same thread/process
<FromGitter>
<girng> so it won't run on release mode?
<FromGitter>
<girng> is there a way to do an alias for puts or something. so i can just do that once. instead of wrapping it around wherever puts is at lol
<FromGitter>
<faultyserver> you could make a top-level `debug` macro
<FromGitter>
<faultyserver> it's might be treating it recursively
<FromGitter>
<faultyserver> name the macro something else
<FromGitter>
<girng> but i want i tto be called `puts` that's the entire point haha
<FromGitter>
<faultyserver> why? If it's just meant to be shown for debugging, calling it `debug` makes a lot more sense
<FromGitter>
<faultyserver> otherwise it's not obvious that it won't happen in production environments
<FromGitter>
<girng> because personal preference?
<FromGitter>
<girng> why shouldi remember debug
<FromGitter>
<girng> when puts is engrained in my head
<FromGitter>
<girng> more shit to remember
<FromGitter>
<faultyserver> imo it's the same as remembering that you have this macro defined in the first place
<FromGitter>
<girng> i mean i guess you have a point
<FromGitter>
<faultyserver> i don't think `previous_def` works in macros, fwiw
<FromGitter>
<faultyserver> so I don't think it's even possible
<FromGitter>
<faultyserver> without just copy-pasting the implementation of the `puts` macro
<FromGitter>
<girng> yeah your right
<FromGitter>
<girng> i should use `debug`
<FromGitter>
<bew> you can just not use a macro, override the definition of the global `puts` method, and call `STDOUT.puts *args` in it, *but please don't do that* !!
<FromGitter>
<faultyserver> in other news: I figured out a cheap way of removing fibers remotely
<FromGitter>
<faultyserver> by rewriting `Fiber#resume`to exit based on an instance variable
<FromGitter>
<faultyserver> monkey patching is fantastic /s
<FromGitter>
<bararchy> Well, I don't think we tested on Mac, but unrelated what Linux distro is the container running?
<FromGitter>
<bararchy> Ubuntu, fedora, Debian?
Nathanaelle has joined #crystal-lang
robacarp has quit [*.net *.split]
dannyAAM_ has quit [*.net *.split]
andersh has quit [*.net *.split]
andersh has joined #crystal-lang
dannyAAM has joined #crystal-lang
robacarp has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
<FromGitter>
<bararchy> oprypin I think I'm getting the hang of crSFML, mostly thank to your great tutorials and examples, I managed to separate event handling and drawing into two different Fibers though it means a lot of Fiber.yield all around :)
<FromGitter>
<bararchy> Maybe a yielding loop should be introduced into the language , something like loop(fiber_action: :yield) do
<FromGitter>
<oprypin> @bew
<FromGitter>
<oprypin> oops stupid gitter omg
<FromGitter>
<oprypin> @bararchy i don't think doing separate fibers is a good idea!
<FromGitter>
<oprypin> it's good that you separated the code, now just put rendering directly after event handling and you're done
<FromGitter>
<oprypin> none of these are IO-bound
<FromGitter>
<oprypin> so it's just causing mess without any advantage
<FromGitter>
<bararchy> @oprypin its what I wanted to do in the beginning, but, I just ended up calling `draw` all around , because it have the general event loop, then, small loops for continues movements and actions etc.. So unless I render inside each loop only one thing will happen at a time (player moving but NPC stuck) etc..
<FromGitter>
<Qwerp-Derp> Is it possible to do something like this in Crystal?
<FromGitter>
<bew> Yes but using modules instead of classes
<FromGitter>
<Qwerp-Derp> I have to use `include` with those, right?
<FromGitter>
<bew> Yes
<FromGitter>
<hmans> @girng Regarding your question about servers and databases... if your #1 goal is scalability, you probably do not want your database to keep run-time state, but rather model all state in memory and periodically persist it to a RDBMS to be able to recover from crashes.
<FromGitter>
<hmans> OTOH, databases can deal with quite a bit of load, so depending on the type of games your servers are powering, they may be well enough.
<FromGitter>
<hmans> If your servers do 15 ticks per second (right?), synchronously writing updates to the database 15 times per second will get you intro trouble at some point, though.
That_Guy_Anon has quit [Quit: Leaving]
<FromGitter>
<Qwerp-Derp> @bew `module`s don't really want what I want to achieve though, is there a workaround for this?
<FromGitter>
<hmans> @Qwerp-Derp What *do* you want to achieve?
<FromGitter>
<Qwerp-Derp> @hmans I provided a code sample above on what I want to do, it might be impossible though
<FromGitter>
<bararchy> @oprypin Now i'm stcuk on figuring how to do multiple-views (main view, and stats\player info on the side)
<FromGitter>
<bararchy> I pass both views, but I don't get what i'm missing
<crystal-gh>
[crystal] S-YOU opened pull request #6058: replace / to . on fun_literal_name (master...safe_mangling_slash) https://git.io/vpaMa
alex`` has quit [Ping timeout: 265 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Client Quit]
alex`` has joined #crystal-lang
<FromGitter>
<hmans> @Qwerp-Derp But how do modules/mixins not do what you want to achieve?
<FromGitter>
<hmans> Modules is how Ruby and Crystal do what you would do with multiple inheritance in other languages. Composition over inheritance.
<FromGitter>
<yxhuvud> sure, but including modules is just another way of doing inheritance.
<FromGitter>
<hmans> Of course. I'm just wondering where @Qwerp-Derp wants to go with his question
<FromGitter>
<Qwerp-Derp> I currently have two classes right now, `Hedron::Control` and `Hedron::Container` for my library. `Hedron::Control` is for low-level stuff (C binding), while `Hedron::Container` is a class that should be extended, since I want users to make their own UI "containers" using them.
<FromGitter>
<Qwerp-Derp> I want to have every low-level class in `Hedron` inherit from both `Control` and `Container`, since that would be the easiest way to do things, but that's not possible in either Crystal or Ruby
<FromGitter>
<Qwerp-Derp> I figured my problem out in the end
<FromGitter>
<hmans> Consider that inheriting everything from one or more god classes because it's easier isn't necessarily good design. (I don't want to tick you off, but there's a larger discussion behind Composition over Inheritance)
hightower2 has joined #crystal-lang
<hightower2>
Did IRC - Gitter connection stop working recently (8 hours?)
<hightower2>
Hm, works now, I se the message
<hightower2>
@faultyserver: regarding upcasting and making sure only methods defined in abstract interfaces are getting called, did you mean something like myobj.as(AbstractClass).some_method ?
<FromGitter>
<codenoid> yeah, i still sublime too <3 @girng
<FromGitter>
<hmans> I'm undecided on whether I should feel dirty about it or not
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> @Qwerp-Derp how does modules not work for you?
<FromGitter>
<Qwerp-Derp> @bew Never mind, I figured it out in the end
<oprypin>
hightower2, there was no downtime, really just nobody writing on irc
<hightower2>
oprypin, oh, then my messages didn't get through
<hightower2>
I'm looking on the clarification of faultyserver's message "you could upcast whatever object you have to that abstract type. then crystal's type checking won't allow any method calls that aren't declared on that abstract type"
<hightower2>
Does that mean doing myobj.as(AbstractClass).some_method() ?
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
shalmezad has joined #crystal-lang
<FromGitter>
<faultyserver> yeah, just like that
<FromGitter>
<faultyserver> also yeah, I didn't see any messages from you yesterday after your question
greengriminal has joined #crystal-lang
<FromGitter>
<faultyserver> Also, assuming this is in some method where `myobj` is a parameter, you should be able to just add a type restriction to it using the abstract class
That_Guy_Anon has joined #crystal-lang
<crystal-gh>
[crystal] ysbaddaden opened pull request #6060: Fix: always close signal handler pipe in fork/exec (master...fix-system-blocks-further-signal-handlers) https://git.io/vpVGp
duane has joined #crystal-lang
That_Guy_Anon has quit [Read error: Connection reset by peer]
That_Guy_Anon has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
That_Guy_Anon has quit [Ping timeout: 265 seconds]
rohitpaulk has quit [Ping timeout: 260 seconds]
<crystal-gh>
[crystal] S-YOU closed pull request #6058: replace / to . on fun_literal_name (master...safe_mangling_slash) https://git.io/vpaMa
hightower2 has quit [Ping timeout: 240 seconds]
That_Guy_Anon has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter>
<hmans> Has Gitter died, or is it really just a very quiet day?
<FromGitter>
<bararchy> I guess it's quiet
<FromGitter>
<hmans> ;'(
duane has quit [Ping timeout: 268 seconds]
<FromGitter>
<DRVTiny> Hello, everybody! :)
<FromGitter>
<DRVTiny> Is passing the Slice(T) - is only way to pass Int32 by reference?
<FromGitter>
<DRVTiny> I know, i can use pointers too. But this is very unfriendly, i think...
<Yxhuvud>
the reference in your case would not be to the int32 but to the slice.
<Yxhuvud>
which is basically equivalent to creating an class with an int32 instance variable, except that you will waste extra space
<FromGitter>
<bararchy> An instance var is much easier to handle no?
<FromGitter>
<bararchy> Or you need that for C to Crystal
<FromGitter>
<hmans> \o/ @girng \o/
<FromGitter>
<girng> @hmans Thanks Hendrik. The 15 tick rate is just for player movement / monster AI. I'm not really doing any updates that fast. I'm only updating whenever a user does certain things. 1) moves an item in their inventory, loots and item, trades an items, allocates a skill/passive point, completes a quest, etc. These are all protected by flood protection internally too. (For example, a user can't move items in their
<FromGitter>
... inventory around < 30ms, that's just not really normal). But if players were to send dirty packets to the server to try to crash server, they'd get dropped. Which is good. ⏎ ⏎ Your fist paragraph completely went over my head a bit. I am not sure if any of my mysql stuff is persistent. I'm just curious whether to connect ... [https://gitter.im/crystal-lang/crystal?at=5aec8912db299d4004d037bc]
<FromGitter>
<DRVTiny> No, i dont need an instance var to pass some value by reference. It is like choke nails with a microscope
<FromGitter>
<hmans> @girng It's not an easy question to answer since there are so many variables to take into account, including your own priorities regarding your project's architecture.
<FromGitter>
<hmans> A separation of concerns -- where only your master server knows there's a MySQL database, and only it talks to it -- can have advantages, but also disadvantages (complexity, premature optimization, ...)
<FromGitter>
<girng> @hmans I was leaning towards the game instance server just sending a message through tcp, to the tell master server about what happened in-game and update the database accordingly. Since I already make an authentication between them and have that open line of communication. Should I just do that for now? I'm sure it'll be fine
<FromGitter>
<hmans> @girng It's definitely not a wrong direction to move into.
<FromGitter>
<hmans> If anything, it will allows you to refactor how your master server handles data later on without having to change the slaves.
<FromGitter>
<DRVTiny> Anybody knows how to define global macro variable near the begin of the file and use it somewhere near the end of the file?
<FromGitter>
<girng> I just wanted to discuss it with someone cause I wasn't sure if I was out in left field or not :P I appreciate you replying and making me re-think this more and more.
<FromGitter>
<hmans> @DRVTiny Not sure if I understand the question?
<FromGitter>
<girng> @DRVTiny just define it at top anywhere, it can be used anywhere
<FromGitter>
<hmans> @girng If you really want to dive in deep, there's a cool book that talks about application design in Elixir/OTP. It's not Crystal, but you would be able to transfer most of its insights back into Crystalland.
<FromGitter>
<DRVTiny> If i use {%begin %} {% var=value %} {% end %} - than i cant use var anywhere else except that begin..end
<FromGitter>
<hmans> @DRVTiny You could just use a plain macro that emits the value, right?
<FromGitter>
<DRVTiny> But if i define var without {% begin %} ... {% end %} - i cant use it at all: say, {% puts var %} will tell me that macro variable var is not defined
<FromGitter>
<hmans> There are probably also some good books specifically on game networking design, but I'm afraid I can't recommend anything specific
greengriminal has joined #crystal-lang
<FromGitter>
<girng> yeah. this way will work nicely. i can horizontally scale, but only to the point where it reaches the maximum # of queries per second on the master database. whch tbh, will be FAR more than the amount of players i will get for my game lol
<FromGitter>
<girng> i tihnk i'll be alright :D
<FromGitter>
<hmans> Yeah, that's what I meant earlier -- MySQL can take quite a beating. The larger risk at hand is that *if* there is a slow query for whatever reason, your game server will immediately start stalling
<FromGitter>
<girng> wait, does 1 bad query block MYSQL?
<FromGitter>
<hmans> Well, depends on the query ;-)
Ven`` has joined #crystal-lang
<FromGitter>
<girng> i better not write bad quries and make sure each one is behind a flood provention
<FromGitter>
<girng> lol
<FromGitter>
<girng> protection*
<FromGitter>
<hmans> If MySQL decides it needs to wait for some lock created earlier to release, it could bust your 15 ticks/sec pretty quickly. Also, network congestion, etc...
<FromGitter>
<hmans> What kind of game are we talking about? Real-time something?
<FromGitter>
<girng> lol, the 15 ticks/s is just tcp messages per second basically. not writing to the db that fast :P
<FromGitter>
<girng> the tick rate only effects other players in that game. it basically just sends out the player's movement x, y
<FromGitter>
<girng> at that interval. im not doing any db updates for that
<FromGitter>
<girng> real time WASD. if you go http://play.treasurearena.com/ on chromium browser. and look at the websocket data. mine is similar
<FromGitter>
<hmans> @veelenga block.call works just fine: https://play.crystal-lang.org/#/r/401z - you may need to be more specific in your method signature
<FromGitter>
<hmans> @DRVTiny As far as I remember, variables assigned to within a macro are considered local. I'm assuming that will also apply to @ivars.
<FromGitter>
<hmans> Your `reset_structs` could just be a private def
<crystal-gh>
[crystal] RX14 opened pull request #6061: Fix libressl/openssl version detection - again (master...bugfix/openssl-linking-again) https://git.io/vpVXb
<crystal-gh>
[crystal] RX14 closed pull request #6061: Fix libressl/openssl version detection - again (master...bugfix/openssl-linking-again) https://git.io/vpVXb
<FromGitter>
<everdev> is there a best practice in Crystal for handling DB access? i've seen some tutorials use a global variable and others pass the DB object down to each function
<RX14>
depends on your app
<RX14>
like is it even an app
<FromGitter>
<girng> i use a property called db in my MasterServer class
<RX14>
sometimes you're a library and a global var just doesn't work
<RX14>
if you're an an app then a global var might hinder testing
<RX14>
well not global var
<RX14>
class_property I guess
<RX14>
or a constant
<crystal-gh>
[crystal] RX14 opened pull request #6062: Revert "Fixed OpenSSL bindings to recognize LibreSSL (#5676)" (master...bugfix/remove-libressl) https://git.io/vpVMl
<FromGitter>
<everdev> yes, it's a web app
greengriminal has joined #crystal-lang
<FromGitter>
<girng> i thought crystal doesn't have global vars
<FromGitter>
<DRVTiny> Anybody knows, are there any web servers for Crystal that forks worker processes?
<FromGitter>
<DRVTiny> Amethyst cant do this, Kemal cant do this too, Amber, Lucky - to the same bucket...
<FromGitter>
<girng> is the performance vastly different with the forked processors though? i mean is it enough to make a decision not to use crystal?
<FromGitter>
<girng> because if you look at the websocket kemal benchmarks. it's mountains ahead of a nodejs one
<FromGitter>
<girng> crystal still performs pretty darn fast even without forking
faustinoaq has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 265 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
cskb has joined #crystal-lang
cskb has quit [Client Quit]
<FromGitter>
<hmans> @girng Classes are instances of the class Class
<FromGitter>
<fridgerator> @DRVTiny what do you mean by fork worker processes? Multiple servers listening on the same port?
<FromGitter>
<hmans> @everdev One common pattern is to group all database access in a module or class that keeps whatever references to db connections it needs within its own state.
<FromGitter>
<hmans> If you're doing anything more complex than trivial database access, I would recommend going through some sort of ORM library or similar. (I use Crecto in a project and am enjoying it.)
<FromGitter>
<fridgerator> thanks @hmans
<FromGitter>
<hmans> @fridgerator \o/
<FromGitter>
<everdev> thanks @hmans i went with the class approach and it's working well so far
<FromGitter>
<girng> @fridgerator i think they mean like multiple crystal services. like cluster modulein nodejs
<FromGitter>
<hmans> I'm off to bed. Night everyone!
<FromGitter>
<girng> gn hmans ty for help
<baweaver>
I have a bit of an out there one for macros, and it's more of an "is this possible, or even a good idea?" type of question
<baweaver>
I've made a pattern matching library in Ruby named Qo, and I was looking for a good way to bridge the speed gap between it and vanilla Ruby
<baweaver>
What I've done so far is used binding and eval to "unfold" conditional loop checks (conditions.all?(match)) into a flat boolean statement (condition1 && condition2 && ...) which gets me around 10-20% speed parity.
<baweaver>
I was wondering if macros would make sense for something like this in a more language-level sense for a native extension to Ruby
<baweaver>
Nice thing is it's actually faster than vanilla not written as performance-minded as possible, so you can get some good wins over normally written Ruby and get more expressiveness to boot.
<baweaver>
Been playing with the idea of a native extension in C and Rust when havenwood mentioned Crystal and macros, so more of seeing if any of this even makes sense
<FromGitter>
<Sjoerrdd> Hi :\
<FromGitter>
<bararchy> My game is coming along :) ⏎ got the "views" under control atlast, and movment is fully working, now to figure out intercations and battle mode, long way ahead , can't belive I started a game, a dream comes true hahah ⏎ https://github.com/bararchy/rapid_mutation
<FromGitter>
<bararchy> Thanks oprypin for crSFML
<oprypin>
:)
hightower2 has quit [Ping timeout: 248 seconds]
<FromGitter>
<codenoid> hi @bararchy can you add some screenshot in README ?
<FromGitter>
<xmonader> @codenoid cool avatar!
<FromGitter>
<Sjoerrdd> Hello o/
<FromGitter>
<j8r> Hello @Sjoerrdd
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter>
<girng> hello
<FromGitter>
<girng> @bararchy cool little project u got there
<FromGitter>
<girng> glad to see crystal used in gamedev
hightower2 has joined #crystal-lang
duane_ has quit [Ping timeout: 255 seconds]
<hightower2>
What's the approach I could take if I'd like to see a list of all shards like crystalshards.org and crystalshards.xyz do, but all in one list?
<FromGitter>
<codenoid> cool avatar !, a linux wizard <3 @xmonader
<FromGitter>
<xmonader> thanks ^_^ is it frm madocka magica or something else?
<FromGitter>
<PlayLights_twitter> GUYS , exist any way on crystal to generate a Hex random number?