Tagged: C++ Toggle Comment Threads | Keyboard Shortcuts

  • frankiezafe 19:18 on 2017-04-04 Permalink | Reply
    Tags: C++, ,   

    Today, certainly one of the less sexy thing i’ve ever posted…

    How to create a unique key out of two pointers in C++?

    After some investigation and a poor attempt to use boost uint128_t, i found my way using a char array.

    Here is the code:

    SomeClass* a = new SomeClass();
    SomeClass* b = new SomeClass();
    
    unique = new unsigned char[ 16 ]; // room for 64bits pointers
    uintptr_t ta = reinterpret_cast<uintptr_t>(a);
    uintptr_t tb = reinterpret_cast<uintptr_t>(b);
    
    for ( int i = 0; i < 8; ++i ) {
        unique[ i + 8 ] = ta;
        unique[ i ] = tb;
        ta = ta >> 8;
        tb = tb >> 8;
    }
    
    cout << "chars: ";
    for ( int i = 0; i < 16; ++i ) {
        cout << uint16_t( unique[i] ) << " | ";
    }
    cout << endl;
    
    uintptr_t newa = 
            unique[15] << 56 | 
            unique[14] << 48 | 
            unique[13] << 40 |
            unique[12] << 32 |
            unique[11] << 24 |
            unique[10] << 16 |
            unique[9] << 8 |
            unique[8];
    
    uintptr_t newb = 
            unique[7] << 56 | 
            unique[6] << 48 | 
            unique[5] << 40 |
            unique[4] << 32 |
            unique[3] << 24 |
            unique[2] << 16 |
            unique[1] << 8 |
            unique[0];
    
    cout << reinterpret_cast<uintptr_t>(a) << " <> " << newa << endl;
    cout << reinterpret_cast<uintptr_t>(b) << " <> " << newb << endl;
    cout << reinterpret_cast<RoadDot*>(newa) << " <> " << a << endl;
    cout << reinterpret_cast<RoadDot*>(newb) << " <> " << b << endl;
    

    And… done! The pointers are casted into the very useful uintptr_t as a unsigned int, stored in the array in 8 bits chunks. On 64 bits systems, pointers use 64bits… Therefore, the char array needs to have 16 slots ( 128 / 8 = 16 ).

    At the end of the code, the pointers are recreated from the characters and compared to the original values. In my terminal, here is what i saw:

    chars: 96 | 168 | 98 | 1 | 0 | 0 | 0 | 0 | 224 | 130 | 98 | 1 | 0 | 0 | 0 | 0 | 
    23233248 <> 23233248
    23242848 <> 23242848
    0x16282e0 <> 0x16282e0
    0x162a860 <> 0x162a860
    

    I’ll optimise this a bit, mainly by creating the char array based on the size of the uintptr_t * 2.

     
  • frankiezafe 20:34 on 2017-03-11 Permalink | Reply
    Tags: , C++, , , ,   

    flat network (no Z)

    slight Z curvature

    strong Z curvature

    strong Z curvature

    strong Z curvature

    After a bit of struggle with the management of a 3d grid, the advantage is there: it’s now easy to generate a road network in 3D, with automatic connection of the streets while generating them. It’s a simple brute force & unsupervised generation algorithm, but it is memory efficient and error less.

    Just to explain a bit the images above: the cubes are the cells of the road grid. Only the required one are created during road generation. There are connected to each other to speed up the proximity tests once a now road segment is added. I’ll measure the generation time soon, but it’s already quite fast regarding to the first test made several days ago in processing.

     
  • frankiezafe 17:45 on 2017-03-11 Permalink | Reply
    Tags: , C++, ,   

    Generation of a 3d grid of cells, each one of the cells knows who are the surrounding ones. This to speed up searching around the current cell.

    To generate a unique id for each one of the surrounding cell, and quickly find the current cell in the surrounding cell, i used a python that generates a list of enum and a map of opposition. Therefore, when I create a new cell in the grid, its very fast to register it into all the existing ones.

     
  • frankiezafe 22:39 on 2017-02-10 Permalink | Reply
    Tags: , C++, , , ,   

    I’ve learned something really important today: an OpenGL context can be accessed by one and ONLY one thread! See Under what circumstances would glGenBuffers/glGenBuffersARB fail?.

    And this is the first time I feel annoyed by the singleton approach of Ogre3D. In my asset converter util, I use Ogre object, the MeshManager mainly, to convert xml files to .mesh files. Due to the limitation of OpenGL and the singleton pattern, I can’t declare a new OpenGL context in my conversion thread by using the Ogre managers…

    I struggled for several hours with that before find the post on stackoverflow.

    This implies a freeze during mesh conversion, wich prevent me to animate a progress bar and keeping the conversion strickly in background.

    I’ll work on the loading and display of the processed meshes next week.

     
  • eurydice 11:23 on 2017-01-17 Permalink | Reply
    Tags: C++, ,   

    AMazingGameSS0

    AMazingGameSS1

    First little game without pretention done while learning Openframeworks and C++ during my traineeship !

     
  • frankiezafe 21:32 on 2016-09-27 Permalink | Reply
    Tags: C++, , guidelines   

    Superb presentation about “Common C++ Performance Mistakes in Games” by Pete Isensee at GDC 4

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel