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.


Messages - t0rento

Pages: [1]
1
General discussions / SFML with gtkmm
« on: October 21, 2011, 08:24:16 am »
I'm sorry I won't be able to offer much assistance with this widget. It has been a long time since I touched GTK and I don't remember the specific conditions or versions that I used when I wrote this widget.

However I do remember that I wrote and tested it under a Linux derivative using gcc. Perhaps the problem is OS dependent?

Other then that I am afraid I can't offer much help.

2
General / Re: Problem with my Game class and const sf::Input
« on: February 22, 2010, 03:19:58 pm »
This is the type of issue a constructor is designed for. Ideally you use an initializer list.

Code: [Select]

class c_Game
{
private:
sf::RenderWindow screen;
sf::Event events;
c_Object player;
c_Object object;
float eTime;
const sf::Input& input;
public:
c_Game() :
        screen(VideoMode(800,600,32), "Hi"),
        player(0,0,100,100,sf::Color(0,255,0,100)),
        object(300,300,100,100,sf::Color(100,100,0,100)),
        input(screen.GetInput())
{
screen->UseVerticalSync(true);
}
.
.
.


That should work.

3
General discussions / SFML with gtkmm
« on: April 28, 2009, 07:11:58 am »
Thanks! Glad it was useful to someone else.

Make sure to let me know if you find any bugs (or even if you fix any problems you encounter)

4
General discussions / SFML with gtkmm
« on: April 27, 2009, 05:03:17 am »
Good idea, once I clean out the testing code I left in I think I will.

Edit:
Added to the Wiki
http://www.sfml-dev.org/wiki/en/sources/gtksfmlwidget

5
General discussions / SFML with gtkmm
« on: April 25, 2009, 07:58:04 pm »
I've been playing around with gtkmm and decided to create a SFML widget, after digging a lot through the documentation of both gtkmm and SFML and also looking at http://www.sfml-dev.org/forum/viewtopic.php?t=282 I managed to stitch something together.

However, I am fairly new to C++, gtkmm and SFML and I do not really understand the internals of SFML so I was wondering if there's any mistakes I've made. Basically I'm just looking for some constructive criticism.

Thank you.

SFMLWidget.h
Code: [Select]

#include <SFML/Graphics.hpp>
#include <gdk/gdkwin32.h>
#include <gdk/gdk.h>
#include <gdkmm/general.h>
#include <gtkmm.h>

class SFMLWidget : public Gtk::Widget, public sf::RenderWindow
{
    private:
        sf::VideoMode m_vMode;

        virtual void on_size_request(Gtk::Requisition* requisition);
        virtual void on_size_allocate(Gtk::Allocation& allocation);
        virtual void on_map();
        virtual void on_unmap();
        virtual void on_realize();
        virtual void on_unrealize();
        virtual bool on_idle();
        virtual bool on_expose_event(GdkEventExpose* event);
        void DrawObjects();

        Glib::RefPtr<Gdk::Window> m_refGdkWindow;

        sf::Image m_tempImage;
        sf::Sprite m_tempSprite;
    public:
        SFMLWidget(sf::VideoMode Mode);
        virtual ~SFMLWidget();
};


SFMLWidget.cpp
Code: [Select]

#include "SFMLWidget.h"
void SFMLWidget::DrawObjects()
{
    this->Draw(m_tempSprite);
}

bool SFMLWidget::on_idle()
{
    if(m_refGdkWindow)
    {
        DrawObjects();
        this->Display();
    }

    return true;
}

SFMLWidget::SFMLWidget(sf::VideoMode Mode)
    : sf::RenderWindow(Mode, "")
{
    set_flags(Gtk::NO_WINDOW);
    m_tempImage.LoadFromFile("gtk_logo.png");
    m_tempSprite.SetImage(m_tempImage);
    m_tempSprite.SetPosition(50, 50);

    Glib::signal_idle().connect( sigc::mem_fun(*this, &SFMLWidget::on_idle) );
}

SFMLWidget::~SFMLWidget()
{
}

void SFMLWidget::on_size_request(Gtk::Requisition* requisition)
{
    *requisition = Gtk::Requisition();

    requisition->width = this->GetWidth();
    requisition->height = this->GetHeight();
}

void SFMLWidget::on_size_allocate(Gtk::Allocation& allocation)
{
    //Do something with the space that we have actually been given:
    //(We will not be given heights or widths less than we have requested, though
    //we might get more)

    this->set_allocation(allocation);

    if(m_refGdkWindow)
    {
        m_refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height() );
        this->SetSize(allocation.get_width(), allocation.get_height());
    }
}

void SFMLWidget::on_map()
{
    Gtk::Widget::on_map();
}

void SFMLWidget::on_unmap()
{
    Gtk::Widget::on_unmap();
}

void SFMLWidget::on_realize()
{
    Gtk::Widget::on_realize();

    if(!m_refGdkWindow)
    {
        //Create the GdkWindow:
        GdkWindowAttr attributes;
        memset(&attributes, 0, sizeof(attributes));

        Gtk::Allocation allocation = get_allocation();

        //Set initial position and size of the Gdk::Window:
        attributes.x = allocation.get_x();
        attributes.y = allocation.get_y();
        attributes.width = allocation.get_width();
        attributes.height = allocation.get_height();

        attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
        attributes.window_type = GDK_WINDOW_CHILD;
        attributes.wclass = GDK_INPUT_OUTPUT;


        m_refGdkWindow = Gdk::Window::create(get_window() /* parent */, &attributes,
                GDK_WA_X | GDK_WA_Y);
        unset_flags(Gtk::NO_WINDOW);
        set_window(m_refGdkWindow);

        //set colors
        modify_bg(Gtk::STATE_NORMAL , Gdk::Color("red"));
        modify_fg(Gtk::STATE_NORMAL , Gdk::Color("blue"));

        //make the widget receive expose events
        m_refGdkWindow->set_user_data(gobj());

        ///Reference: http://www.nabble.com/Win32-HWND-td20494257.html
        ///This is platform specific, compiling on Linux/MacOS will require a different Window Handle
        this->sf::RenderWindow::Create(reinterpret_cast<HWND>(GDK_WINDOW_HWND(m_refGdkWindow->gobj())));
    }
}

void SFMLWidget::on_unrealize()
{
  m_refGdkWindow.clear();

  //Call base class:
  Gtk::Widget::on_unrealize();
}

bool SFMLWidget::on_expose_event(GdkEventExpose* event)
{
    if(m_refGdkWindow)
    {
        DrawObjects();
        this->Display();
    }
    return true;
}

6
SFML projects / SHMUPEH (Game)
« on: March 15, 2009, 09:29:01 pm »
Odd, the menu doesn't raise any errors so you may want to add some in ("#include "Logger.h" and use Logger::log("Message", LOGTYPE_ERROR) )

Hard to tell what is causing it with the current information

Edit:
Did you make sure to include all graphical assets and whatnot in the relevant path, it could be to do with that. Though if an asset didn't load an error would be logged Hmm...

7
SFML projects / SHMUPEH (Game)
« on: March 15, 2009, 06:06:28 am »
Quote from: "Ceylo"
Code: [Select]
_strdate( dateStr);
_strtime( timeStr );

Dunno those functions, and can't build your program only because of those two (everything else is compiles fine).

Looks to be Windows only..
That was a quick screenshot taking hack, if you comment out the surrounding if it should compile fine for both OS's. (Untested though)

8
SFML projects / SHMUPEH (Game)
« on: March 15, 2009, 01:39:47 am »
This is my Australia Year 12 project for my Software Development course, the requirements where just that it had to compile and use an array but I felt like making something remotely fun

The game is called SHMUPEH. It's a simple bullet-dodging enemy shooting game.

Most of the controls are explained when you load the game, except that F5 is used to take a screenshot.

I am using SFML primarily for rendering everything, the game as of now contains no networking, audio or use of any of the other libraries SFML provides. (I would probably be using networking and audio if I wasn't on a time limit to finish the project)

Note:
This code has gone through a lot of revisions and I can't say I'm proud of it. Like any programmer who works on a project for a long time they start to see so many flaws in it that they just want to start again. This project has been remade at least 4 times due to this and I find that if I keep remaking it it never gets done.

As such I cannot say I am happy with this code, however I hope the end result is at least a bit enjoyable.

Screenshots:





Download: http://www.electronicfiles.net/files/11823/Programs/SHMUPEH.rar
Source Code: http://www.electronicfiles.net/files/11823/Programs/SHMUPEH_SOURCE.rar
[Note] The download includes the source code.

Enjoy.

9
Graphics / Image is too large
« on: February 16, 2009, 01:14:52 pm »
Ah I see, so computers with an older OpenGL driver are going to have issues?

10
Graphics / Image is too large
« on: February 16, 2009, 10:32:54 am »
On some machines I get a error in the console "Error image is too large (1024x4320)" but on my own I do not.

What is the cause of this and how can I fix it?

11
General / Flexible Object Manager
« on: February 05, 2009, 05:29:41 am »
Quote from: "e_barroga"
Quote from: "Tank"
e_barroga:
Please read the posts more carefully. :)

Using an object manager class, your code could look like as follows:
Code: [Select]

int main() {
  ObjectManager mgr;

  mgr.addObject( new MyObject ); // MyObject derived from BaseObject
  mgr.addObject( new MyOtherObject ); // MyOtherObject derived from BaseObject

  while( true ) { // Some kind of main loop.
    mgr.processObjects(); // Calls step() for every object.
  }
}


BaseObject has the virtual functions create() and step(). create() can be called in several ways: Either by the constructor or by ObjectManager::addObject(). ObjectManager::processObjects() iterates through all added objects and calls step() on each. I hope it's more clear this time.

Edit:
klusark:
You're implementing some kind of factory pattern. I would either prefer to implement functions like: createPlayer(), create...() instead of comparing type strings (we're using OOP ;) ), or directly pass a pointer to the proper object by using the new statement.
For example something like:
Code: [Select]

objectmanager.register( ObjectFactory::createPlayer(), "an_unique_id" );


Yes, I already know about writing an object manager, but I am having issues writing the method to create instances through arguments.

Code: [Select]

void ObjectManager::addObject ( argument0 ) {
  new argument0;
}


How do I make it create an instance of whatever is defined in argument0?

Oh I see, my old post got what you wanted wrong.

You seem to want to create an object instanced to a name, have a look at std::map

-Explination will be here soon-
Basically, the first thing you want after you've got your base class is an object manager, you want your objects to have names i'm assuming so you do something like this

Code: [Select]

class ObjectManager
{
    private:
        std::map<std::string, BaseClass*> tObjects; //We are making an associative array here, in other words the string will refer to the object
    public:
        void addObject(const std::string& name, BaseClass* data);
        void step();
}

void ObjectManager::addObject(const std::string& name, BaseClass* data)
{
    tObjects[name] = data; //Think of it sorta like a dynamic array that instead of using ints, uses strings, so we set the "Name" position to the "Data"
}

void ObjectManager::step()
{
    for(std::map<std::string, BaseClass*>::iterator mIter = tObjects.begin(); mIter != tObjects.end(); mIter++)
    {
        mIter->second->step();
    }
}


Maybe that is what you are looking for

Another example is the first class I made in SFML, I call it the resource manager, it simple handles Image data for me so that there is never more then one of the same image, while it doesn't use a Base class, it shows you how I associate a std::string to another object. Allowing you to name it as I believe you want to.
Code: [Select]

/// ---------- ResourceManager.hpp -----------
class ResourceManager
{
    private:
        static Logger* Log;
        std::map<std::string, sf::Image*> Images;
    public:
        ~ResourceManager();
        static void setLogger(Logger* a) {Log = a;}

        //Images
        void loadImage(const std::string& name, const std::string& filepath);
        const sf::Image& getImage(const std::string& name);
};
///-------------------------------------------------

///------------ ResourceManager.cpp ----------
Logger* ResourceManager::Log = 0;

ResourceManager::~ResourceManager()
{
    for(std::map<std::string, sf::Image*>::iterator mIter = Images.begin(); mIter != Images.end(); mIter++)
    {
        delete mIter->second;
    }
}

void ResourceManager::loadImage(const std::string& name, const std::string& filepath)
{
    // Test if the key exists
    if(Images.find(name) == Images.end())
    {
        Images[name] = new sf::Image();
        if(!Images[name]->LoadFromFile(filepath))
            Log->log("Error Loading Image: " + name + " at filepath: " + filepath, LOGTYPE_ERROR);
        else
            Log->log("Loaded image " + name, LOGTYPE_EVENT);

        Images[name]->CreateMaskFromColor(sf::Color(255, 255, 255), 0);
    }
    else
    {
        Log->log("Attempt to re-load image " + name + " aborting load", LOGTYPE_ERROR);
    }

const sf::Image& ResourceManager::getImage(const std::string& name)
{
    // Test if the key exists
    if(Images.find(name) == Images.end())
    {
        Log->log("Image " + name + " does not exist, a blank image will be returned", LOGTYPE_ERROR);
    }

    return *Images[name];
}
}
///-------------------------------------------------

Pages: [1]