Forum
I never expected it to come down to this, but the real culprit is ... Gosu::Font#draw!
The #draw calls take one second during start... That's ridiculous.
Okay, here's the deal:
All my font objects used the Gosu::default_font_name font. As you see above it's insanely slow.
Then I changed to "Droid Sans" and there it is... ~0.2 seconds. I *could* imagine that has something to do with
them, because
I installed them recently and they basically touch everything font related.
Well, now I have wasted a day for something stupid again. :P
Happy new year!
Hi, thanks for the reply.
Okay, I tried MethodProfiler, but it doesn't go "deep" enough.
It tells me that:
+----------------------+-----------+------------+--------------+-------------+-------------+
| Method | Min Time | Max Time | Average Time | Total Time | Total Calls |
+----------------------+-----------+------------+--------------+-------------+-------------+
| #draw | 1.879 ms | 990.261 ms | 14.404 ms | 4148.327 ms | 288 |
takes the longest. Even though only the first time? I already got this far before. However, I don't know why.
What does draw call to be that slow?
Edit: ruby-prof gives a lot more output. I'll give it a closer look.
I need an easy way to determine how long my methods take, because some parts of my game became really slow and I want to know where the bottleneck is.
I already wrapped a few methods with t = Time.now ; puts Time.now - t, but I want/need it for every method call. Is it possible without touching everything?
I also have problems with crashes and always thought it's ashtons fault. :P
I applied your hack and have my gl code running since 5 minutes without a crash. Looks good. I'll let it run another 30 minutes or so.
Edit: Still running like a boss. :)
This reminds me of my unfinished quest (game icon) :( Don't release 0.7.50 before it's finished and merged! :P
RubyMine has one and it's pretty good.
Your code doesn't make any sense, because you always return nil.
Either remove the redundant return (well, not in your case) or move the true/false next to return.
Example:
if top1 > bottom2
false
return
end
becomes
if top1 > bottom2
return false
end
and so on.
^This. py-sdl2 is really cool.
But no matter how hard I try, I always come back to Ruby/gosu. :)
Heh!
Finally got it working with SWIG_ConvertPtr without #to_blob.
What now? Pull request and you look over the code or do you don't want to see the code in gosu? :'(
(Will do it tomorrow, time to sleep.)
Yes, then it would be a no-op. But that's a problem of Windows. :P
Posted almost simultaneously. :P
Why is it wrong to set the icon in code? The title is also set in code. And because of the #ifdef magic it's only Linux anyway, so it's not even possible to set the icon in Windows.
My code lies within the Ruby_Gosuwrapper.cxx thingie and I mostly copied from your other methods, so I guess it should be legal to cast to Gosu::Window.
Okay, let's assume I use to_blob, how would the cast to Gosu::Bitmap look like?
Simple as reinterpret_cast<Gosu::Bitmap *>(VALUE)?
I don't want to spend the whole night on trial and error again... :)
The function setIcon(image) works (in C++), but the wrapper doesn't. I get the bitmap of an image from image.getData().toBitmap() thus I don't need to_blob.
Huh, Windows API?
^ No. (But I did now, and the result is the same as below).
I think I give up. :D Can't get it to work.
Calling toBitmap() on the imagedata of my image results in a crash.
(I simplified the code)
SWIGINTERN VALUE
_wrap_Window_icone___(int argc, VALUE *argv, VALUE self) {
Gosu::Window *arg1 = (Gosu::Window *) 0 ;
Gosu::Image *icon = (Gosu::Image *) 0;
arg1 = reinterpret_cast< Gosu::Window * >(argp1);
icon = reinterpret_cast< Gosu::Image *>(argv[0]);
// Gives me a return value
std::cout << sizeof(icon->getData().toBitmap()) << std::endl;
// FAILS, ruby interpreter crashes
(arg1)->setIcon(icon->getData().toBitmap());
// same
Gosu::Bitmap bmp = getData().toBitmap());
}
I could provide the stacktrace, but it's useless. My Ruby code looks like this:
gem "gosu", ">9.0.00"
require 'gosu'
class Test < Gosu::Window
def initialize
super(640, 480, false)
bitmap = Gosu::Image.new(self, "./icon.png", false)
self.icon = bitmap # <= apocalypse
end
# ...
end
Okay, I need Gosu::Bitmap in Ruby or a way to get either the bitmap or the pixels of a Gosu::Image.
If you don't have a better idea, then I'm trying to wrap the Bitmap class.
I need access to the pixels of the icon in my current implementation. Gosu::Image doesn't provide that I just noticed. :S
And lol @GosusDarkSide. :P
It happens in code, similar to setCaption(). A Windows implementation isn't much work, I just cannot test it. (Imo better than having to rely on third party programs)
How do I create a gem from gosu source? Just run rake?
I finally managed to compile gosu!
Now I implemented icon support for games running in a X window.
I think the implementation is still a bit ugly and may have bugs and is C++ only at the moment, but omfg it's working after countless hours of despair.
My next goal is the Ruby implementation and maybe Windows/Mac(uses X?) support.
Time to get some sleep!
Interesting. I'll keep an eye on it. :)
Nah. I'm stuck after make install. CMake won't find gosu with the snippet provided in the wiki (gosu is located at /usr/local/lib). That's where I lost all hope and interest in C++ again.
I already tried to play around with the gosu source code, but failed hard trying with cmake to link gosu.
Would be cool if you could elaborate on that part in the wiki or show me a working example.
Thanks!
Nevermind. :P
I would be interested in helping. Let me know when you have more concrete plans and time.
I was browsing some other libraries wikis and found this:
http://www.sfml-dev.org/tutorials/2.1/window-window.phpThis got me interested in why gosu doesn't support more complex window operations like resizing or hiding the titlebar.
It would be cool to have a more complex functionality in gosu.
What exactly makes it so difficult to run Ruby under Android?
Ocra is not an option, because it's not cross-platform. I only use Linux.
I'll give Releasy a look.
Greetings from hot Germany...
I searched the forum, read the entire (Ruby) documentation of Gosu, but couldn't find a way for my Game to have a nice application icon.
Unless I missed something (most likely) is it just not implemented or not doable because-of-some-api-restrictions?
Install the package libx11-dev and try again.
Wut? I'm running Gosu with ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] on Arch Linux.
That must be a Windows issue.
YEEEEEEEEEES- after hours of trying it's finally working.
The solution looks more or less like this now:
def update
# ...
if @environment.allAnimationsDone
# prevent animation from showing
elsif @animation.nil?
startAnimation(@environment.getNextAnimation)
elsif !@environment.activeAnimation.nil?
if @animation.shown
if @environment.activeAnimation.state == :DONE
startAnimation(@environment.getNextAnimation)
else
endAnimation(@environment.activeAnimation)
end
end
end
# ...
end
:)
Hello,
I'm showing an animation and want to wait until it's done.
I have battler objects and each of them releases an animation which I just call by iterating over them.
But the second battler shall only show his animation when the first one is done and the third when the second is done.
Okay, that's actually not that difficult. But somehow, my code seems to has a flaw.
My environment that draws the animation has a animation object, it's nil until I iterate over those battlers.
http://pastebin.kde.org/749792/class Environment
def initialize
@animation = nil
@battlers = [Battler.new("some"), Battler.new("ordinary"), Battler.new("objects")]
end
def update
@battlers.each {|battler| battler.update}
end
def draw
@battlers.each {|battler| battler.draw}
if not @animation.nil?
if not @animation.shown
@animation.draw
end
end
end
def performAnimations
@battlers.each do |battler|
# some stuff
@animation = Animation.new(battler.highOugiAnimation)
# wait until animation finished
waitAnimation
end
end
def waitAnimation
if not @animation.nil?
while not @animation.shown
update
draw
end
end
end
end
class Animation
attr_reader :shown
def initialize(animation)
@animation = animation
@shown = false
@pseudoTimer = 0
@pseudoNumber = 1500
end
def draw
@animation.draw(24, 24, 24)
@pseudoTimer += 1
if @pseudoTimer > @pseudoNumber
@shown = true
end
end
end
I expect the animation to be shown, during that period the draw and update works normally, but "feels" like a wait.
But what happens instead is that the animation is NOT drawn, everything freezes up during the waitAnimation call and
I have no clue WHY it happens.
Please, I need your advice...
Which OS? Under Linux you should be careful, when installing gems as root... they may be installed where your user's path doesn't look.
Awesome. Ashton::Shader(fragment: :fade) provides everything I need. Though, the syntax is a bit special and the Ashton source files doesn't really help.
However, I got what I asked for. Thousand thanks. :-)
Thanks for the fast answer.
Pitty it's the first time I hear about it. I'll report back, once I tried it out.
Hello,
I need a blink effect (or called flash?) like the one used here:
http://www.youtube.com/watch?v=go7rlvyI7YsI tried it using Texplay, but it's kinda limited. I coulnd't find a way to turn my image all white and slowly change it back.
My approach then was to copy my image, draw it over my original image and make it from white to 100% opacity. But
I noticed that's not the best performant way and I wasn't even able to turn my image white or change it's opacity... instead I drew a reddish rectangle on top
of my CLONED image. Then I switch between those two images every x frames to simulate a blink effect. Well, ...
can anyone suggest a better way to implement a blink using Texplay?
Yes, -w -d are my interpreter arguments.
And as of yesterday my game also uses TexPlay - same error.
I guess there's no other way than to tolerate the error?
Hello,
I never paid attention to the following error, but I got curious why it happens, because it happens everytime. No matter the environment (Though I didn't try it on Windows).
Each time I launch my game I get the following error:
Exception `LoadError' at /usr/lib64/ruby/1.9.1/rubygems/custom_require.rb:36 - cannot load such file -- gosu
I know that it doesn't affect my game at all, but I still want to know if it's possible to get rid of it. :)
Topic IDE
By SPK
Date 2013-04-10 18:25
Sublime Text 2 is all I need.
spk@skuld:~> sudo gem update gosu
root's password:
Updating installed gems
Updating gosu
Fetching: gosu-0.7.47.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed gosu-0.7.47.1
file 'README.txt' not found
file 'COPYING' not found
file 'reference/gosu.rb' not found
file 'reference/Drawing_with_Colors.rdoc' not found
file 'reference/Order_of_Corners.rdoc' not found
file 'reference/Tileability.rdoc' not found
file 'reference/Z_Ordering.rdoc' not found
Installing ri documentation for gosu-0.7.47.1
Installing darkfish documentation for gosu-0.7.47.1
Gems updated: gosu
Working! Thousand thanks! :)
Quick response. :P
Unfortunately I installed 0.7.47.
Trying to update my gem gives me the following error:
RubyGosu_wrap.cxx: In function ‘void Init_gosu()’:
RubyGosu_wrap.cxx:11479:74: error: ‘kbRightMeta’ is not a member of ‘Gosu’
In file included from ../Gosu/Bitmap.hpp:9:0,
from ../Gosu/Gosu.hpp:14,
from RubyGosu_wrap.cxx:2227:
Edit: In Button.hpp#48-58
kbLeftAlt = 0x38,
#if defined(GOSU_IS_WIN)
kbRightAlt = 0xb8,
kbLeftMeta = 0xdb,
kbRightMeta = 0xdc,
#elif defined(GOSU_IS_X)
kbRightAlt = 0x64,
kbLeftMeta = 0x7d,
#else
# error this should not happen
#endif
The kbRightMeta is missing for X. It seems you merged ButtonsX and ButtonsWin. I looked at the ButtonsX but cannot determine the hex value for
kbRightMeta = XK_Meta_R. If I had to guess I would say 0x7e :)
Hello,
what's the most effective and easiest way to deploy a game written in Ruby for Linux?
Let's pretend the target machine has nothing pre installed to launch the game.
You are right. That's easier to manage.
Thanks for the help.
It's so much fun with gosu. :)
Meh.
Well, thanks for your reply. :)
Guess I will have to use names like font25, font30 etc.
So I was wondering, why is the height of a font read only?
It would be cool to write ;
Font.draw("Hello", x, y, z, size1)
Font.draw("World", x, y, z, size2)
factor_x isn't really helpful and I don't want to initialize the same font with another size.
Ah, ok. I put it in my menu class.
So that's the flaw. Now it works.
Again, big thanks.
I tried it, but nothing happens.
Where does id come from by the way?
Thanks for your replies.
This :
def update
if button_down?(KbDown) and !@pressed
@index+=1
@pressed=true
elsif not button_down?(KbDown)
@pressed=nil
end
end
and then I call @menu.update in my gosu::window update method and everything works. Great!
But I still don't understand when to use button_down(id)
When I replace my update method with button_down(id) and adjust it to the example above,
it isn't working.
As far as I understood Gosu calls button_down without any doing from my side, or?
If I put this inside my menu instead of the update snippet from above:
def button_down(id)
if id == Gosu::KbDown and !@pressed
@index+=1
@pressed=true
elsif not id == Gosu::KbDown
@pressed=nil
end
end
Nothing happens. Where do I have to put this method for Gosu to call it?
Leaving it alone in my menu doesn't seem to work.
But since button_down? works I don't mind.
Hey,
currently I'm working on a menu, which works, except that the
button_down?(key) method is called too often during the update interval.
That means if the KbUp button is pressed the index doesn't move one time, it moves
3 - 4 times.
I tried it with button_down instead of button_down?, but it ignores all input.
How can I avoid this problem?
I can't believe it. My project runs as it's supposed to do. :)
Big thanks. :)
I love rvm. <3
This is my setup now:
$ gem -v
1.8.10
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
$ which ruby
/home/spk/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
$ gem which gosu
/home/spk/.rvm/gems/ruby-1.9.2-p290/gems/gosu-0.7.37/lib/gosu.rb
Important note is that the gem has to be installed with rvm gem install gosu.
gem install gosu didn't worked for me even after changing GEM_HOME.
I tried it with and without rubygems.
There's no difference.
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill