Jump to content

Furbolg

Members
  • Posts

    243
  • Joined

  • Last visited

Posts posted by Furbolg

  1. You cant do nothing here.

    Because templates are not "dynamic Type", Templates are "choosen Type".

     

    For example:

     

    std::list<string> stringlist;
    std::list<float> floatlist;
    
    // this ok
    stringlist.push_back( "test" );
    floatlist.push_back( 1.0f );
    
    // this wont work
    stringlist.push_back ( 2.0f );
    floatlist.push_back ( "wow" );
    

     

    What you "can" do here right now is using interfaces and inheritance for example:

     

    #include <windows.h>
    #include <iostream>
    #include <vector>
    #include <string>
    #include <sstream>
    #include <list>
    
    class IConsoleOutput
    {
    public:
    virtual std::string getConsoleString() = 0;
    };
    
    class IntOutput : public IConsoleOutput
    {
    public:
    IntOutput(std::string name, int& refvalue) : name(name), value(refvalue)
    {
    }
    
    std::string getConsoleString()
    {
    std::stringstream output;
    output << name << " = " << value << std::endl;
    return output.str();
    }
    
    private:
    std::string name;
    int& value;
    };
    // same for float etc.
    
    int main()
    {
    int a = 0;
    std::vector<IConsoleOutput*> debugstrings;
    IntOutput testint(std::string("simple test"), a);
    debugstrings.push_back( &testint );		 // i normally use IntOutput *bla = new IntOutput(...) but this is simpler and works right now
    
    // output all strings
    for(int i = 0; i < debugstrings.size(); i++)
    {
    std::cout << debugstrings[i]->getConsoleString();
    }
    
    a = 10;
    
    // output all strings
    for(int i = 0; i < debugstrings.size(); i++)
    {
    std::cout << debugstrings[i]->getConsoleString();
    }
    }
    

     

     

    This is just a small example without const correctness and some other design patterns (observer, visitor, factory ....) but i hope this is an idea for you.

  2. Hi Guys!

     

    It has soft bodies, destruction, and scaling now, so I am pretty happy.

     

    So could you make an update for Leadwerks 2.5 to support scaling (in Sandbox) again ?

    Because i think scaling with a external program is not a solution - its a workaround.

    (And besides the major competitors have scaling (unity, unreal, cryengine etc.))

  3. Hey Aggror!

     

    1. You forget a closing bracket at the end.

    2. All Methods and Variables declared without a specific access space are default in private (opposite to struct where all entires automatically public)

     

    So your working class look like this:

     

    #include <sstream>
    class Convert
    {
    public:
    template <class T>
    static inline std::string ToString (const T& t)
    {
     std::stringstream ss;
     ss << t;
     return ss.str();
    }
    };
    

     

     

    Simple Test code from me:

    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    #include "convert.h"
    int main(int argc, char** argv)
    {
    int a = 12345;
    float b = 54321.0f;
    std::cout << Convert::ToString<int>(a) << std::endl;
    std::cout << Convert::ToString<float>(B) << std::endl;
    system("pause");
    return 0;
    }
    

     

    Cheers :)

  4. Benton just means that the less limbs per render is better for fps. Meaning, if you can group several objects together that share only one limb, then this will have less effect on framerate. More limbs means slower framerate. So, it depends on your case, and what you want to achieve. wink.png

    Anyways, nice wall, Roland! smile.png

     

    Cheers

     

    As i said above, depends on the engine architecture :)

  5. Theoretically it doesnt matter if you use 4 models or 1 model... it depends how the engine works internally.

     

    Drawcall is "a function" which gives the drawing information (vertices, textures, shader etc...) to the graphics driver, the count of drawcalls should be as small as possible (its the engine's job to collect them and draw them together).

     

    Todays graphics card can render a whole bunch of polygons (10.000+) but cant handle much drawcalls.

  6. That's somewhat better, but I still don't like this because you always have to have the list and the iterator. Why can't the iterator just remember which list it belongs to?

     

    Whats the problem ? Since the iterator is created on stack, you can just create new instance when you need it.

    • Upvote 1
  7. You do it wrong.

     

    With STL iterators, you have no idea whether an iterator is valid or not:

    std::list<Object*>::iterator it = list.begin();
    list.erase(it);
    //it still hangs around, can't be changed to NULL
    

     

    Do it like this: (MSDN: std::list.erase http://msdn.microsoft.com/en-us/library/1fef72t6%28v=vs.80%29.aspx )

    std::list<Object*> list;
    list.push_back(new Object());
    std::list<Object*>::iterator it = list.begin();
    it = list.erase(it);
    if (it == list.end()) // similiar to == null
    {
       std::cout << "no more entry" << std::endl;
    }
    

     

    ps. Im sorry to refer so much to the MSDN but its the best source for (v)c++ documentation.

  8. The default value of an pointer is undefined (in release mode).

     

    prove

     

    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    int main(int argc, char** argv)
    {
    int* test;
    int* test2 = NULL;
    std::cout << test << std::endl;
    std::cout << test2 << std::endl;
    system("pause");
    return 0;
    }
    

  9. ***************************************

    IMPORTANT

    ***************************************

     

    It seems Roland is right. Well, sometimes. I am getting unreliable behavior when reading with the [] operator, if the key does not exist in the map. I recommend always using find() instead of the [] operator!

     

    I can only suggest to use the MSDN (msdn.microsoft.com)

     

    The MSDN says under "Remarks" the following:

    http://msdn.microsof...ibrary/fe72hft9

     

    If the argument key value is not found, then it is inserted along with the default value of the data type.

     

    operator[] may be used to insert elements into a map m using m[_Key] = DataValue; where DataValue is the value of the mapped_type of the element with a key value of _Key.

     

    When using operator[] to insert elements, the returned reference does not indicate whether an insertion is changing a pre-existing element or creating a new one. The member functions find and insert can be used to determine whether an element with a specified key is already present before an insertion.

  10. Yeah that one is great, but 249$... ouch sad.png

     

    But its worth every dollar, just the better syntax highlighting and there are soo much awesome featues.

     

     

    i am happy as i can buy it as academic license biggrin.png

     

    You are a lucky one cool.png

  11. Josh as you declared your std::list on the stack it should.. no must.. be cleaned up after leaving the scope.

    Are you sure your System::GetMemoryUsage() works correctly ?

     

    To verify it, please check your Ressourcemonitor on the RAM Tab.

     

    **edit**

     

    608cf04afd.png

  12. Virtual isn't just a "placeholder" or "template" and it can (but has not to) be overridden.

     

    In my opinion, the strength of virtual methods is that you can decide which method to use (base, derived) or to define that an specific method has to be implemented by user ( = 0 ). And you can also hide informations from the user.

     

    For example my actual engine iteration has something like this: (pseudo code, does not compile)

     

    class IRenderDevice
    {
     public:
      virtual void Initialise(u16 Width, u16 Height, u8 Bits) = 0;
      virtual void Draw(...) = 0;
      virtual void Terminate() = 0;
    };
    
    class D3D9RenderDevice : public IRenderDevice
    {
     private:
      //some dx9 vars
      LPDIRECT3D9* d3d9;
      LPDIRECT3DDEVICE9* d3d9device;
     public:
      virtual void Initialise(u16 Width, u16 Height, u8 Bits);
      virtual void Draw(...);
      virtual void Terminate();
    };
    

     

    And this is how to use it:

    int main(int argc, char** argv)
    {
    IRenderDevice* mydevice = new D3D9Device();
    mydevice->Initialise(800,600,32);
    // mainloop
    while(true)
    {
       mydevice->Draw(.....);
    }
    mydevice->Terminate();
    };
    

     

    So whats the advantage of this ? I just change "new D3D9Device();" with "new OpenGL33Device();" and it uses OpenGL 3.3.

    To be honest, this is not the full implementation and style but you should get the idea behind this smile.png

     

    In my real code the instances are created by a core class (you can call it factory) and the user of the "engine" has no worries but using directx / opengl by himself. He just uses my interface and classes i provide him.

     

    Of course he could write his own RenderDevice by inheritancing my IRenderDevice and create an instance by himself "new myogrerenderer();" etc.

  13. Here is a link, there are some tests about how "slow" virtual functions really are.

    http://stackoverflow.com/questions/449827/virtual-functions-and-performance-c

     

    On modern CPUs its so fast that you will "feel" a difference at round about 1 million calls.

     

    You can create a whole engine with virtual functions (which is good to hide implementation specific details but i won't write all with virtual functions for example vector3 or matrix etc.) and its run without problems, because to load/draw a model is much (very much) slower then calling virtual functions.

×
×
  • Create New...