Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Groogy

Pages: 1 2 3 [4] 5
46
System / SFML2 Utf template is kinda confusing
« on: January 06, 2011, 11:09:28 pm »
Aight So I'm currently working on my engine where it is going to convert the event values into javascript values. And I were stopped at TextEntered. I wanted to convert the value given to a string in javascript but the v8::String seem to only support up to Utf-16 so I thought I could use SFML to convert it but when I reached the documentation page... it was all way too confusing.

Hoped you could help me out explaining how you use it?

V8 String Documentation: http://bespin.cz/~ondras/html/classv8_1_1String.html

You create a new instance trough the  v8::String::New methods.

*EDIT*
For now I did this, but I think I loose potential data(I usually don't work with these kind of stuff):
Code: [Select]
int Script::Converters::ConvertTextEnteredSignal(const SignalBase &aSignal, v8::Handle<v8::Value> *someArguments)
{
const TextEnteredSignal &signal = static_cast<const TextEnteredSignal &>(aSignal);

// <-- Where I try to convert the char but in a bad way -->
sf::String str = signal.GetChar(); // Returns the sf::Uint32
someArguments[0] = v8::String::New(str.ToAnsiString().c_str(), str.GetSize());
// <-- And here it ends -->

v8::Handle<v8::Object> windowWrapper = localWindowTemplate->NewInstance();
windowWrapper->SetInternalField(0, v8::External::New(signal.GetWindow()));
someArguments[1] = windowWrapper;
return 2;
}

47
Graphics / SFML2 PNG difference
« on: December 28, 2010, 01:07:01 am »
I just noticed a thing when I tried to render a PNG image. What I expected was this image:

But what I got was this:


Don't mind the red background, just me trying something out.
Anyway I don't understand why the transparency doesn't work and why the edges are cut off? Is it something I've done wrong?

I noticed this when I for the first time tried rendering something trough my game engine. The code for my test class looks like this:
Code: [Select]
class ImageEntity : public GraphicalEntity
{
public:
static ImageEntity *New()
{
ImageEntity *object = new ImageEntity();
object->Init();
return object;
}

protected:
void Init()
{
GraphicalEntity::Init();
myImage.LoadFromFile("data/test.png");
mySprite.SetImage(myImage);
}

void InitReceiver()
{
myReceiver = new ImageReceiver(*this);
}

void Render(sf::RenderTarget &target, sf::Renderer &renderer) const
{
target.Draw(mySprite);
}

sf::Image myImage;
sf::Sprite mySprite;
};


There's a lot of more code involved but the engine is getting quite huge and has a asynchronous design so it's kinda hard to show all the relevant code.

48
General / SFML2 and VS2008 warning: LNK4098
« on: December 24, 2010, 01:37:25 pm »
Hi! Just something that has been bugging me when I link statically and I've been trying to fix it myself but can't seem to manage to do it.

It's just a simple warning and it doesn't crash anything but it bugs me that there's a warning. The warning is:
Quote
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library


I tried adding the /NODEFAULTLIB to all SFML modules but didn't help. Anyone more experienced with VS that can help me out?

And merry Christmas! :D

49
SFML wiki / Smart Resource manager
« on: December 22, 2010, 02:33:51 pm »
Aight I've made a "smart" resource manager that knows when a resource is in use and will unload the resources if it's getting short on space(the max space you can set yourself but it defaults to the size of 10 000 resources).

Wiki article: http://www.sfml-dev.org/wiki/en/sources/smart_resource_manager

Anyway here's a example of it in use:
Code: [Select]
class ImageManager : public ResourceManager<sf::Image, std::string, 100>
{
protected:
bool Load(sf::Image &resource, const std::string &path) const
{
return resource.LoadFromFile(path);
}
};

typedef Resource<sf::Image, std::string, 100> ImageResource;

int main()
{
std::string paths[1000] = {/* Define a 1000 paths */};
ImageManager manager;
for(unsigned int index = 0; index < 1000; index++)
{
ImageResource test = manager.Get(paths[index]);
std::cout << test->GetWidth() << ", " << test->GetHeight() << std::endl;
sf::Sprite sprite(*test);
}
return 0;
}


This manager will hold the images and can only contain 100 of them but if we look at the for-loop we distinctively can see that we will load all images specified by the array paths. The image is loaded and kept track of, then returned trough it's Resource handle. We can interact with the image just like if the resource handle was a pointer to the image. And at the end of the for-loop the resource object will be destructed and the only reference to it terminated. And thus the memory is free'd up for grabs again if we need it. In reality the image will stay in memory until we run out of space which we will at image 100. If we would have saved another handle outside the for-loop that doesn't get destructed then the image can't be loaded out of memory until that resource handle is also gone thus giving us the "smart" in this resource manager.

50
Feature requests / Thread management or the like in SFML2
« on: December 16, 2010, 11:57:59 am »
How would adding methods like sf::Thread::Suspend and sf::Thread::Resume to the thread class? Currently the only way to simulate this yourself is:

Code: [Select]
void MyThreadFunc()
{
        /* Some code */
        while(isSuspended)
        {
                sf::Sleep(0.1f);
        }
        /* more code */
}


But it's not the same, it's not ideal for when you want to make a Master/Worker model for your threads or use the threads as tasks. Then you would like to:
Code: [Select]
void MyThreadFunc()
{
        while(shouldExecute)
        {
                /* do work */
                Suspend(); // Wait until the master wants me again.
        }
}


It should be a simple wrap around on functions like SuspendThread in Windows.

51
Window / I've done something really weird to sf::Window
« on: December 15, 2010, 12:44:31 am »
Well I don't understand it. The application is runnable and everything exits fine. Anyway from NOWHERE the destructor for WglContext is run and it tries to run line 103 which is: DestroyWindow(myWindow);

But I destroyed it long time ago, I don't have any window allocated on the stack. Also the call-stack looks really funny. The function called before(and only) the destructor is called 90909090().

I'm probably doing something very funky which makes this happen. It didn't appear before but now it does. All I did was extend my messaging system to make the main thread and renderer thread work more asynchronous. I'll be committing the code to here: https://github.com/Groogy/Ascension/tree/development
Though it's a lot so don't think anyone would want to read trough it. If someone could give me a pointer to as of why this could have happened then that would be great to help me give concerning code.

Misc: Currently working in Visual Studio 2008 with SFML2 in debug mode. SFML is linked statically with the debug libraries and I have defined SFML_STATIC. Since I use static libraries I get this warning:
"Warning   1   warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library   Ascension"
Just in case if it matters.

PS: Also according to the bugger, the WglContext this pointer is not even correct.

52
System / sf::RenderWindow create in one thread, display in another.
« on: December 14, 2010, 09:23:02 pm »
I'm having a problem and I think it has something to do with my topic. Basically I send a "start" signal to my Renderer and when it receives that signal it will create the window and launch the thread that will handle the rendering. Then in the rendering thread, so far all it does is call Display on the window. I've checked and all values are correct so it's no invalid pointers or something like that. Also debugging it showed me that the threads are running like they should.

The error message I get is "Failed to activate the window's context" when I call Display.
What am I missing?

Anyway here's concerning code:

Code: [Select]
void RendererReceiver::OnStart(const SignalBase &signal)
{
const RendererStartSignal &start = static_cast<const RendererStartSignal &>(signal);
myController.InitTarget(start.GetWindow(), start.GetMode(), start.GetTitle(), start.GetStyle(), start.GetSettings());
myController.LaunchThread();
}

void RendererController::InitTarget(sf::RenderWindow *window, const sf::VideoMode &mode, const std::string &title, const unsigned long style, const sf::ContextSettings &settings)
{
myTarget = window;
window->Create(mode, title, style, settings);
window->SetFramerateLimit(MaxFrameRate);
window->Clear();
window->Display();
}

void RendererController::Run()
{
sf::Sleep(0.1f);
while(myContinueExecutionFlag == true)
{
myReceiver->ProcessSignals();
myTarget->Display();
}
}


Forgot to say that this is with SFML2 and a thought is that in Windows a window handle or opengl context or whatever is the problem might not be capable of being shared between threads? Or me missing something important.

53
System / sf::String and std::string::c_str in SFML2
« on: December 12, 2010, 03:45:24 am »
Just wondering, is this intended behavior? I had this code:

Code: [Select]
const char * cString = string.ToAnsiString().c_str();
FILE * file = fopen(cString, "rb");

Opening the file would fail and when I debugged and looked at cString it would contain junk data. But if I skip the middle hand cString pointer and only write:
Code: [Select]

FILE * file = fopen(string.ToAnsiString().c_str(), "rb");

the file is actually opened and apparently it contains the proper characters.

Is this how it is intended to be designed or is std::string messing with me?

54
General / MessageBox class in SFML Wiki
« on: December 05, 2010, 01:36:38 am »
Well I thought we should place something there to show what the rbSFML library can do. It's not much but I feel it's really useful. Here's a link: http://www.sfml-dev.org/wiki/en/sources/messagebox

Here's for instance my main file for my current project:
Code: [Select]
#!/usr/bin/env ruby
# Copyright (c) 2010 Henrik Valter Vogelius Hansson
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
#   1. The origin of this software must not be misrepresented; you must not
#   claim that you wrote the original software. If you use this software
#   in a product, an acknowledgment in the product documentation would be
#   appreciated but is not required.
#
#   2. Altered source versions must be plainly marked as such, and must not be
#   misrepresented as being the original software.
#
#   3. This notice may not be removed or altered from any source
#   distribution.

require './src/scripts/config.rb'

begin
  System::Application.init
rescue Exception => error
  message = error.message + '\n'
  message += error.backtrace.join( '\n' )
  MessageBox.show( error.class.toString + " error!", message )
end

55
General / Rect#intersects
« on: November 29, 2010, 09:10:21 am »
While I was playing around with intersects on SFML::Rect I noticed that it seamed like it intersected even though it shouldn't. For instance I have the rect: [0, 0, 44, 16] and when I call intersects with [0, -35, 42, 34] it returns [0, 0, 44, 16]

I must have done something wrong unless I misunderstand intersects. Here's the original C++ code:
Code: [Select]
template <typename T>
bool Rect<T>::Intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
{
    // Compute the intersection boundaries
    T left   = std::max(Left,         rectangle.Left);
    T top    = std::max(Top,          rectangle.Top);
    T right  = std::min(Left + Width, rectangle.Left + rectangle.Width);
    T bottom = std::min(Top + Height, rectangle.Top + rectangle.Height);

    // If the intersection is valid (positive non zero area), then there is an intersection
    if ((left < right) && (top < bottom))
    {
        intersection = Rect<T>(left, top, right - left, bottom - top);
        return true;
    }
    else
    {
        intersection = Rect<T>(0, 0, 0, 0);
        return false;
    }
}


And here's the original ruby code(with added comments to show what's what):
Code: [Select]

/* call-seq:
 *   rect.intersects( rectangle ) -> intersection rectangel or nil
 *
 * Check the intersection between two rectangles.
 *
 * This method returns the overlapped rectangle if intersecting otherwise nil.
 */
static VALUE Rect_Intersects( VALUE self, VALUE aRect )
{
VALUE selfLeft = rb_funcall( self, rb_intern( "left" ), 0 );
VALUE selfTop = rb_funcall( self, rb_intern( "top" ), 0 );
VALUE selfWidth  = rb_funcall( self, rb_intern( "width" ), 0 );
VALUE selfHeight = rb_funcall( self, rb_intern( "height" ), 0 );
VALUE selfRight  = rb_funcall( selfLeft, rb_intern( "+" ), 1, selfWidth );
VALUE selfBottom = rb_funcall( selfTop, rb_intern( "+" ), 1, selfHeight );
VALUE rectLeft = rb_funcall( aRect, rb_intern( "left" ), 0 );
VALUE rectTop = rb_funcall( aRect, rb_intern( "top" ), 0 );
VALUE rectWidth  = rb_funcall( aRect, rb_intern( "width" ), 0 );
VALUE rectHeight = rb_funcall( aRect, rb_intern( "height" ), 0 );
VALUE rectRight  = rb_funcall( rectLeft, rb_intern( "+" ), 1, rectWidth );
VALUE rectBottom = rb_funcall( rectTop, rb_intern( "+" ), 1, rectHeight );

VALUE left, top, right, bottom;

        // T left   = std::max(Left,         rectangle.Left);
if( rb_funcall( selfLeft, rb_intern( ">" ), 1, rectLeft ) == Qtrue )
{
left = selfLeft;
}
else
{
left = rectLeft;
}

// T top = std::max(Top,         rectangle.Top);
if( rb_funcall( selfTop, rb_intern( ">" ), 1, rectTop ) == Qtrue )
{
top = selfTop;
}
else
{
top = rectTop;
}

// T right  = std::min(Left + Width, rectangle.Left + rectangle.Width);
if( rb_funcall( selfRight , rb_intern( ">" ), 1, rectRight ) == Qtrue )
{
right = selfRight;
}
else
{
right = rectRight;
}

// T bottom = std::min(Top + Height, rectangle.Top + rectangle.Height);
if( rb_funcall( selfBottom , rb_intern( ">" ), 1, rectBottom ) == Qtrue )
{
bottom = selfBottom;
}
else
{
bottom = rectBottom;
}

// if ((left < right) && (top < bottom))
if( rb_funcall( left, rb_intern( "<" ), 1, right) == Qtrue && rb_funcall( top, rb_intern( "<" ), 1, bottom) == Qtrue )
{
// intersection = Rect<T>(left, top, right - left, bottom - top);
VALUE newWidth  = rb_funcall( right, rb_intern( "-" ), 1, left );
VALUE newHeight = rb_funcall( bottom, rb_intern( "-" ), 1, top );
return rb_funcall( globalRectClass, rb_intern( "new" ), 4, left, top, newWidth, newHeight );
}
else
{
// return false
return Qnil;
}
}


from what I understand, those two rects shouldn't intersect and thus the intersects method should return the ruby value nil. But I must have missed something somewhere in the algorithm. Does anybody see it?

56
Graphics / DRM_IOCTL_GEM_CLOSe error on SFML2
« on: November 26, 2010, 12:14:39 am »
Well I found a previous post but there was no answer there.

I get a: "DRM_IOCTL_GEM_CLOSE 18 failed (region): Bad file descriptor"
every time I close the application after I have drawn a resource it seems like (though not with shapes!).

Is this a known error in SFML2 or am I just doing something very wrong in my rbSFML library? Cause I didn't notice this at my workstation. It appeared when I got home...

57
Audio / sf::SoundStream::OnGetData
« on: November 25, 2010, 04:41:14 pm »
Hi! Just wondering here in this example:

Code: [Select]
class CustomStream : public sf::SoundStream
 {
 public :

     bool Open(const std::string& location)
     {
         // Open the source and get audio settings
         ...
         unsigned int channelsCount = ...;
         unsigned int sampleRate = ...;

         // Initialize the stream -- important!
         Initialize(channelsCount, sampleRate);
     }

 private :

     virtual bool OnGetData(Chunk& data)
     {
         // Fill the chunk with audio data from the stream source
         data.Samples = ...;
         data.NbSamples = ...;

         // Return true to continue playing
         return true;
     }

     virtual void OnSeek(float timeOffset)
     {
         // Change the current position in the stream source
         ...
     }
 }

 // Usage
 CustomStream stream;
 stream.Open("path/to/stream");
 stream.Play();


Will the stream free the allocated Samples data or will you have to do that yourself? Or does it maybe copy the data to an internal array?

What I'm referring to is the Chunk::Samples sf::Int16 pointer.

58
Feature requests / Mouse Delta on Input
« on: November 06, 2010, 10:20:56 pm »
Is it too much to ask after a "GetMouseDeltaX" or something in the Input class? :D
 The delta could be as simple as "currentX - lastFrameX".

59
SFML website / RSS Feed
« on: November 05, 2010, 10:13:03 am »
I'm just wondering if it's possible for you to add like a kind of RSS feed plugin to the forum?

I'm already following the development trough RSS of SFML 2.0 ^^
Would be nice to have a quick way to see if there's new messages on the forum too.

60
General / rbSFML
« on: November 01, 2010, 11:20:54 pm »
Long time since I was at this forum :)

Well I need a project to work on in between my assignments while at my university so I choose this if the previous maintainer don't mind.
Anyway I started today and already got the sfml-system library done. I will try to make the library conform with the conventions of the SFML library as much as possible but I will also let the library conform to the Ruby conventions. I can't estimate any time as of when this will be completed but I can estimate that I'll work around 1-2 hours each day with this between my assignments.

The task list for rbSFML can be found here: http://taks.groogy.se

Any updates to the library will be edited into this post.

Example code:
Code: [Select]

require 'sfml/system'
require 'sfml/window'
require 'sfml/graphics'
require 'sfml/audio'

app = SFML::Window.new [800, 600], "My Ruby SFML"

# Load a sprite to display
image = SFML::Image.new
image.load_from_file  "cute_image.jpg"
sprite  = SFML::Sprite.new image
 
# Create a graphical string to display
arial = SFML::Font.new
arial.load_from_file "arial.ttf"
text = SFML::String.new "Hello SFML", arial, 50
 
# Load a music to play
music = SFML::Music.open_from_file "nice_music.ogg"
# Play the music
music.play
 
# Start the game loop
while app.open?
  # Process events
  while event = app.get_event
    # Close window : exit
    if event.type == SFML::Event::Closed
      app.close
    end
  end
 
  # Clear screen
  app.clear
 
  # Draw the sprite
  app.draw sprite
 
  # Draw the string
  app.draw text
 
  # Update the window
  app.display
end


These classes has been excluded from the library:
Code: [Select]

Thread
Lock
Mutex
Randomizer
Sleep
Unicode
RenderTarget ( Not the same as SFML::RenderTarget )

Why these has been excluded is because the core of Ruby already does these for us. But I also want to go into more detail on Thread, Lock and Mutex. It's true that Ruby does provide this functionality for us but it's still incomplete. The threading in ruby works natively but ruby got a global lock which will always only let one thread run at the same time. So this also made my choice, since if we allow SFML threading it might mess up the internal workings of Ruby. So my choice is to wait with implementing this and let Ruby's threading "mature".

Pages: 1 2 3 [4] 5
anything