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

Author Topic: [ODFAEG] (Open Source Development Framework Adapted for Every Game)  (Read 162110 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #60 on: February 22, 2014, 01:24:29 pm »
I've found this : http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern

But I can't combine this design pattern with the type erasure design pattern. (So I conclude that this is really no way to do this)

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #61 on: February 22, 2014, 01:38:30 pm »
Maybe you should use std::function and forget all this headaches :P

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #62 on: February 22, 2014, 02:11:04 pm »
Don't try to convince him, let him try and fail, its not like he is in a hurry for anything :p

He clearly has no idea of how many problems a library like qt signals, libsigc++, or even std::function to a lesser extent solve..

Even if he gets the type issues clean and smooth, there will still be performance optimizations, special case handling for some platforms and tracking premature destruction of the slot object, among other things..

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #63 on: February 22, 2014, 03:41:21 pm »
I'll add the possibility to use an std::function into the fast-delegate class. :P

(But not objects with placeholders)

Because their type is always different and there are not of type std::function.

auto binder = std::bind(&myFunction, _1, "2");
//It'll not work because binder is not of type std::function.
FastDelegate<void>(binder);
 

auto binder = std::bind(&myFunction, "1", "2");
FastDelegate<void>(binder);
 

This one will work because there are no place holders used so binder is of type std::function.
« Last Edit: February 22, 2014, 03:43:16 pm by Lolilolight »

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #64 on: February 22, 2014, 04:45:46 pm »
Because their type is always different and there are not of type std::function.

auto binder = std::bind(&myFunction, _1, "2");
//It'll not work because binder is not of type std::function.
FastDelegate<void>(binder);
 

#include <iostream>
#include <functional>
using namespace std::placeholders;
using namespace std;
struct C
{
    int callback(int a, int b, int c) {
        return a+b+c;
    }
};

int main(int argc, char *argv[])
{
    C myC;
    auto f1 = std::bind(&C::callback, &myC, _1, _2, 42);
    std::cout << "f1(5, 3) = " << f1(5, 3) << std::endl; // = 50
    std::function<int(int,int)> f2 = f1;
    std::cout << "f2(5, 3) = " << f2(5, 3) << std::endl; / = 50
    std::cout << typeid(f2).name() << std::endl; // = std::function

    f2 = std::bind(&C::callback, &myC, _1, _1, _1);
    std::cout << "f2(5, 2354, 4567) = " << f2(5, 3) << std::endl; // = 15
    std::cout << typeid(f2).name() << std::endl; // = std::function

    f2 = std::bind(&C::callback, &myC, 1, 2, 3);
    std::cout << "f2(5, 3) = " << f2(5, 3) << std::endl; // = 6
    std::cout << typeid(f2).name() << std::endl; // = std::function

    return 0;
}
« Last Edit: February 22, 2014, 04:49:25 pm by Lo-X »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #65 on: February 22, 2014, 05:21:47 pm »
It's not so simple like that, I need to store the object f1 in a std:map if I take your example.

But I don't think that it's possible.

PS : with boost it seems that it's possible : http://stackoverflow.com/questions/7757096/how-can-i-store-a-boostbind-object-as-a-class-member
« Last Edit: February 22, 2014, 05:51:21 pm by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #66 on: February 22, 2014, 09:06:38 pm »
I've tried one last thing (just for testing the new c++ features) but the c++11 function style cannot be virtuals :

class Base {
       public :
       virtual auto getType() = 0;
};
template <typename T> class Derived : public base {
      Derived (T t) : t(t) {}
      auto getType() -> Derived<T> {
              return this;
      }
      void function() {
      }
      T t;
};
class Container {
     template <typename T> void create(T t) {
            base = new Derived<T>(t);
     }
     void callFunction() {
            static_cast<decltype(base->getType())>(base)->function();
     }
     Base *base;
};
 

I thought that the compiler would choose the right function to parse base in Derived<T> but it's not the case.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #67 on: February 22, 2014, 09:09:10 pm »
Can you define a pure virtual function with the auto return type? It doesn't make sense to me...

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #68 on: February 22, 2014, 09:23:37 pm »
Quote
Can you define a pure virtual function with the auto return type?

No. ^^

I just tried do something like this :
class Base {
       public :
       virtual auto getType() = 0;
       virtual void* operator();
};
template <typename F, typename ...AV> Bind {
};
template <typename R, typename O, typename... AT, typename ...AV> class Bind<R(O, AT...), AV...> : public Base {
      Bind (R(O::*f)(AT...), AV... vals) : f(f) {
             params1 = std::tuple<AV...>(vals....)
      }
      auto getType() -> Bind<R(O, AT...)> {
              return this;
      }
      template <typename V...> void setParams (V... vals) {
              std::tuple<V...> params2 = std::make_tuple(vals...);
              params3 = std::tuple_cat(params1, params2);
      }
      void* operator()() {
              return f(params3);
      }
     
      std::tuple<AT...> params1;
      std::tuple<AV...> params3;
      (R(O::*f)(AT...);
};
template <typename R=void*> class Binder {
     template <typename R, typename O, typename AT... typename AV...> Binder((R(O::*f)(AT...), AV... vals) {
            base = new Derived<R(O, AT...), AV....>(t);
     }
     template <typename ...AV> void changeParams(AV... vals) {
            static_cast<decltype(base->getType())>(base)->setParams(vals);
     }
     R operator()() {
           return static_cast<R>((*base)());
     }
     Base *base;
};
class Listener {
    std::map<std::string, std::pair<Binder<bool>, Binder<>>> sigslots;
};
 

But, I don't think it's possible, it tells me also that he can't convert R(O::*f)(AT...) to R(*)(AT...). (or comething like this)
« Last Edit: February 22, 2014, 09:49:42 pm by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #69 on: February 23, 2014, 04:18:06 pm »
Hi, I've tried to pass an std::function to a template class but it fails to compile and it's the raison why I don't want to use an std::function.


template <typename ...A> class FastDelegate0 : public Delegate {
        friend class FastDelegate;
        FastDelegate0 (void(*f)(A...)) {
            typedef void(*CB)(Function<void(A...)>, A...);
            CB cb = &callback;
            funct = new Functor<void(Function<void(A...)>, A...)> (cb, Function<void(A...)>(f));
            stdFunct = nullptr;
        }
        FastDelegate0 (std::function<void(A...)> func) {
            typedef void(*CB)(std::function<void(A...)>, A...);
            CB cb = &callback;
            stdFunct = new Functor<void(std::function<void(A...)>, A...)> (cb, func);
            funct = nullptr;
        }
};
 
template <typename R=void> class FastDelegate {
 template <typename ...A> FastDelegate(void(*f)(A...)) {
        delegate = new FastDelegate0<A...>(f);
    }

    template <typename ...A> FastDelegate(std::function<void(A...)> func) {
        delegate = new FastDelegate0<A...>(func);
    }
};
 

std::function<bool(Vector2f)> sigFunc = [](Vector2f mousePos){
                                                            BoundingRectangle br (0, 0, 100, 100);
                                                            if (br.isPointInside(Vec2f(mousePos.x, mousePos.y))) {
                                                                return true;
                                                            }
                                                            return false;};
        std::function<void(Vector2f)> slotFunc = [](Vector2f mousePos){
                                            std::cout<<"Mouse inside : "<<mousePos.x<<" "<<mousePos.y<<std::endl;};
        listener.connect("MouseInside", FastDelegate<bool>(sigFunc), FastDelegate<void>(slotFunc));
 

And I don't want to have an headache anymore with template arguments.
I don't also want to pass the std::function as a template argument, because I need to reduce the template arguments of my FastDelegate class to store my fast delegates objects into an std::map.

The only inconvenient of that it's that annonymous functions could'nt be used for signal and slot but I don't thing that's a real problem anyway. :)

PS : In C# there is a way to do that with the FastDelegate class event with anonymous functions but I really don't know how to do that in c++.




« Last Edit: February 23, 2014, 04:23:10 pm by Lolilolight »

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #70 on: February 24, 2014, 10:30:16 am »
Hi!
I'll take over about the c++11 a bit and I've found an idea for the game that I'll present in this tutorial.

It'll be a shooting game. ^^

But before I need to have a particule system for the projectiles.

I'll take the ones of the thor library, the source code doesn't seems to be very complex.

And then I'll present the example game.  :)

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #71 on: February 25, 2014, 12:47:55 pm »
Hi, I've fixed a bug which causes sometimes a deadlock. (Because the mutex was unlocked twice)
I've updated the git-hub and the version rc is normally stable now. (If you encounter another bugs let me know :) )

But the demo runs without any problems on my PC.

So I'll post an example of game and some videos soon! (Just the time to manage missiles)








Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #72 on: February 25, 2014, 03:16:02 pm »
Here is a first preview of what can we do with ODFAEG. (But I've still to rework the caracter's animation and adding ennemies) :
http://www.youtube.com/watch?v=nkzkRWISFN4&feature=youtu.be

The first exemple of a fully game is coming soon (I've just to add ennemies and projectiles.)

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #73 on: February 25, 2014, 04:28:07 pm »
What exactly are you showing in the video that can't be done with vanilla sfml as quickly? :p

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: [ODFAEG] (Open Source Development Framework Adapted for Every Game)
« Reply #74 on: February 25, 2014, 04:58:19 pm »
The same things can be done with SFML but not so quickly. :P

So I know that the video doesn't show any difference but without a framework you have to all this tasks manually and it takes me a very long time to do all of this :

-Implementing the intersections between lights and walls system yourself.
-Implementing a resource management system into your program yourself.
-Implementing the culling and other optimisations techniques for faster rendering yourself.
-Implementing yourself an entity management system and a scene node system.
-Implementing yourself a collision detection and a particule system.
And implementing yourself a secure network connection with assynchrone message reception.

Maybe should I make another video (a video tutorial) in which I'll show you how I encode all  of this in a fast way ?

It think this would be be most clear. (I think I'll make that)
Once I'll have finished the IA.
« Last Edit: February 25, 2014, 05:04:43 pm by Lolilolight »