Jump to content

I need other feedback than my own.


Prosper

Recommended Posts

I create particles with random positions and accelerations. I set mass too but won't be using it for a while.
 
So after giving the particle a position and an acceleration it accelerates from its position.
 
At every frame after i've collected data from the faces of the cube, I have to clear the faces of the cube by reseting their values to false. Every face has an 8x8 grid of boolean values that are triggered true depending on if a particle hits . Only the parts of the grid that are hit are triggered true.
 
I give 5 seconds for the particles do what they are going to do, then i remove them and make a new particle list.
 
The reason i haven't enabled collision now is I like to watch them pass through each other, if they collided you get totally different results. Collisions can be costly too.
 
BUT MEN YOU SAY, WHAT IS THE PURPOSE?
By extracting particle information from space-time in the way I have, I hope to use the bit states to feed another application. Such as shoveling the bits as bytecode through a VM causing potential functionality.
 
If I get really good i might be able to do to things at once. Not just a physics simulation but also get other things accomplished. I'm taking in PRNG data right now, but you can imagine how adjusting the seeds at the right 5 second intervals might just be enough for me to succeed.
 
 
Here is the source code.
 
#include <iostream>
#include <vector>
using namespace std;
 
 
unsigned int xor128()
{
    static unsigned int x = 8584732;
    static unsigned int y = 6525464;
    static unsigned int z = 3711115;
    static unsigned int w = 9032831;
    unsigned int t;
 
    t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = w ^ (w >> 19) ^ (t ^ (t >> );
}
 
unsigned int GetRandomNumber()
{
    return xor128();
}
 
bool*** g_Cells = 0;
 
const unsigned int g_nSquaresInARow = 8;
const unsigned int g_nCenterOfARow = 4;
const unsigned int g_nFaces = 6;
const unsigned int g_nUnitSize = 10;
 
void InitCells()
{
 
    g_Cells = new bool**[g_nFaces];
 
    for (unsigned int yyy = 0; yyy < g_nSquaresInARow; ++yyy)
    {
        g_Cells[yyy] = new bool*[g_nSquaresInARow];
        for (unsigned int xxx = 0; xxx < g_nSquaresInARow; ++xxx)
        {
            g_Cells[yyy][xxx] = new bool[g_nSquaresInARow];
            for (unsigned int iii = 0; iii < g_nSquaresInARow; ++iii)
            {
                g_Cells[yyy][xxx][iii] = false;
            }
        }
    }
 
 
}
 
void DeInitCells()
{
    for (unsigned int yyy = 0; yyy < g_nSquaresInARow; ++yyy)
    {
        for (unsigned int xxx = 0; xxx < g_nSquaresInARow; ++xxx)
        {
            delete [] g_Cells[yyy][xxx];
            g_Cells[yyy][xxx] = 0;
        }
    }
 
    for (unsigned int yyy = 0; yyy < g_nSquaresInARow; ++yyy)
    {
        delete [] g_Cells[yyy];
        g_Cells[yyy] = 0;
    }
 
    delete [] g_Cells;
    g_Cells = 0;
}
 
void ResetCells()
{
    for (unsigned int zzz = 0; zzz < g_nFaces; ++zzz)
    {
        for (unsigned int yyy = 0; yyy < g_nSquaresInARow; ++yyy)
        {
            for (unsigned int xxx = 0; xxx < g_nSquaresInARow; ++xxx)
            {
                g_Cells[zzz][yyy][xxx] = false;
            }
        }
    }
}
 
struct Point3D
{
    unsigned int X;
    unsigned int Y;
    unsigned int Z;
    Point3D();
};
 
 
 
Point3D::Point3D() : X(g_nCenterOfARow), Y(g_nCenterOfARow), Z(g_nCenterOfARow)
{
}
 
 
class Object
{
public:
    Object();
    void setPos(Point3D position);
    Point3D getPos();
    void update();
    void amendAcceleration(signed int nVal);
    void setMass(unsigned int nVal);
    unsigned int getMass();
 
private:
    Point3D m_position;
    unsigned int m_nMass;
    signed int m_nAcceleration;
};
 
Object::Object() : m_nMass(1), m_nAcceleration(1)
{
}
 
void Object::setPos(Point3D position)
{
    m_position = position;
}
 
Point3D Object::getPos()
{
    return m_position;
}
 
void Object::update()
{
    m_position.X = m_position.X + m_nAcceleration;
    m_position.Y = m_position.Y + m_nAcceleration;
    m_position.Z = m_position.Z + m_nAcceleration;
}
 
void Object::amendAcceleration(signed int nVal)
{
    m_nAcceleration = m_nAcceleration + nVal;
}
void Object::setMass(unsigned int nVal)
{
    m_nMass = nVal;
}
 
unsigned int Object::getMass()
{
    return m_nMass;
}
 
std::vector<Object> g_objects;
 
void MakeObjects()
{
    for (unsigned int iii = 0; iii < 25; ++iii)
    {
        Object object;
        Point3D point;
        point.X = GetRandomNumber();
        point.Y = GetRandomNumber();
        point.Z = GetRandomNumber();
 
        object.setPos(point);
        object.setMass(GetRandomNumber() % ;
 
        signed int nVal = GetRandomNumber() % 3;
        if (GetRandomNumber() % 2 == 1)
        {
            nVal = -nVal;
        }
 
        object.amendAcceleration(nVal);
    }
}
 
void BoundaryCheck(Point3D point)
{
 
 
    unsigned int maxZ = g_nUnitSize * g_nSquaresInARow;
    unsigned int minZ = 0;
    unsigned int maxY = g_nUnitSize * g_nSquaresInARow;
    unsigned int minY = 0;
    unsigned int maxX = g_nUnitSize * g_nSquaresInARow;
    unsigned int minX = 0;
 
 
    if (point.Z >= maxZ || point.Z <= minZ)
    {
    }
    else if (point.Y >= maxY || point.Y <= minY)
    {
    }
    else if (point.X >= maxX || point.X <= minX)
    {
    }
    else
    {
        return;
    }
 
    g_Cells[point.Z % g_nSquaresInARow][point.Y % g_nSquaresInARow][point.X % g_nSquaresInARow] = true;
 
}
 
void Collide()
{
    /*
    for (unsigned int iii = 0; iii < g_objects.size(); ++iii)
    {
        for (unsigned int jjj = 0; jjj < g_objects.size(); ++jjj)
        {
            if (iii == jjj)
            {
                continue;
            }
        }
    }
    */
}
 
void Test()
{
    MakeObjects();
    InitCells();
    unsigned int nMaxIters = 100;
    unsigned int nIters = 0;
    float fTimeElapsed = 0.0f;
    while (nIters < nMaxIters)
    {
        for (unsigned int iii = 0; iii < g_objects.size(); ++iii)
        {
            g_objects[iii].update();
            BoundaryCheck(g_objects[iii].getPos());
            Collide();
 
            // TODO make objects collide
            // TODO process the g_Cells boolean values as instructions for VM
 
        }
 
 
        if (fTimeElapsed >= 5.0f)
        {
            g_objects.clear();
            MakeObjects();
            ++nIters;
            fTimeElapsed = 0.0f;
        }
        ResetCells();
        fTimeElapsed = fTimeElapsed + 1.0f;

    }
    DeInitCells();
}
 
int main()
{
    Test();
    return 0;
}

 

 

I want to clarify one thing. Assuming you had a game without physics, by adding physics you won't magically be better off. What i'm considering is what optimizations can be done for those games that already do have physics so we can recapture some of that. sure it would be cool to make games run on byproducts of simulation but IS NOT necessarily useful. But I just started this.

Edited by Prosper

redacted

Link to comment
Share on other sites

 

I want to clarify one thing. Assuming you had a game without physics, by adding physics you won't magically be better off. What i'm considering is what optimizations can be done for those games that already do have physics so we can recapture some of that. sure it would be cool to make games run on byproducts of simulation but IS NOT necessarily useful. But I just started this.

 

 

I'm not exactly sure what you're asking for feedback on here  :blink:

 

Also, your simulation is taking huge time steps. You're sampling 5 times per reset, which, if your purpose is to gather data, is not very many samples.

https://twitter.com/IridiumGameDev

Ex-Obsidian Senior Programmer

Link to comment
Share on other sites

 

 

I want to clarify one thing. Assuming you had a game without physics, by adding physics you won't magically be better off. What i'm considering is what optimizations can be done for those games that already do have physics so we can recapture some of that. sure it would be cool to make games run on byproducts of simulation but IS NOT necessarily useful. But I just started this.

 

 

I'm not exactly sure what you're asking for feedback on here  :blink:

 

Also, your simulation is taking huge time steps. You're sampling 5 times per reset, which, if your purpose is to gather data, is not very many samples.

 

 

Thanks Burke! Didn't account for unit size where I should have. There are many other problems too. Like modulolololing to 8 rather than 9. but further more if i have 6 faces each with 8x8 grid the 6x8x8 booleans are enough but i have no idea how to properly place a point like that. it be better if i went 8x8x8 first.

 

With this addition I am no longer just checking the faces of the cube for a collision. I will look into transforming into 6x8x8.

http://codepad.org/k2KFEhhV

Edited by Prosper

redacted

Link to comment
Share on other sites

​Just as a general programming question, is there any reason why you have 6 nested loops instead of combining them into a single loop? They are using the same indices and the assignment values are not dependent on previous iterations. 

 

This is probably more efficient and it is much easier to read: 

 
    for (unsigned int iii = 0; iii < g_nSquaresInARow; ++iii)
    {
        for (unsigned int jjj = 0; jjj < g_nSquaresInARow; ++jjj)
        {
            for (unsigned int lll = 0; lll < g_nSquaresInARow; ++lll)
            {
                Left[iii][jjj] = cells[iii][jjj][0];
                Right[iii][jjj] = cells[iii][jjj][g_nSquaresInARow - 1];
                Top[iii][jjj] = cells[g_nSquaresInARow - 1][jjj][lll];
                Bottom[iii][jjj] = cells[0][jjj][lll];
                Front[iii][jjj] = cells[iii][0][lll];
                Back[iii][jjj] = cells[iii][g_nSquaresInARow-1][lll];
            }
        }
    }

https://twitter.com/IridiumGameDev

Ex-Obsidian Senior Programmer

Link to comment
Share on other sites

Good catch men!  Also I was modding to 9 which gives <= 8. But 8 is an index that accesses outside of an 8 length array. I made some other mistakes too. Here's the source code also runs with irrlicht3d now.

 

http://codepad.org/F7qOhi8j

 

Also changed acceleration to have a variable offset for each axis. amendAcceleration no longer adds onto existing acceleration value.  Many other things have changed too.

 

 

 

 

A video showing the particles.

  • Like 1

redacted

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...