Jump to content

  • Log In with Google      Sign In   
  • Create Account

Nickie

Member Since 10 Jul 2012
Offline Last Active Sep 23 2014 03:57 AM

#5068461 distributing my program

Posted by Nickie on 09 June 2013 - 12:58 PM

Find an option in VS project settings where the default is Multi-Threaded DLL or Debug Multu-threaded dll. Change it to simple "Multy-Threaded". That should work.




#5068375 Using the message loop in another source file?

Posted by Nickie on 09 June 2013 - 01:14 AM

Hello there!

For some reason I don't really understand what you mean but I will try to answer your question...

 

What is you framework? How is everything working?

+There are many good articles about stuff like this: http://www.gamedev.net/page/resources/_/technical/game-programming/how-to-structure-a-game-r3113

for example... Just pick 2 and read them.

 

I assume you don't want yout whole game to be in one file and you want to split the things up. First it makes common sence the core game's main loop to be after the initialization function. I wouldn't spli them up. Though every other component would get its own file. I'll give an example on how to do this.

 

objects.h

#pragma once

class Entity
{
public:
   virtual void update(float deltaTime) = 0;
   virtaul void render(/* render context */) = 0;
};

class Player : public Entity
{
public:
   void update(float deltaTime);
   void render(/* render context */);
};

//... and so on...

objects.cpp

#include "objects.h"

void Player::update(float deltaTime)
{
   if(key_pressed('W')) {
      move_forward();
   }
  //... and everything else you would like to see in your player
}
void Player::render(/* context */)
{
   if(player_visible()) {
      context->render(get_player_vertex_data());
   }
}

 

main.cpp

#include "objects.h"



void init()
{
}

std::list<Entity*> objs;

void loop()
{
   while(1)
   {
      //handle events
      while(there are messages)
      {   }
      for(auto i = objs.begin(); i != objs.end(); ++i)
      {
         (*i)->update(time);
         (*i)->render(context);
      }
   }
}

void kill()
{
}

int main()
{
   init();
   loop();
   kill();
   return 0;
}

Everthing declared can be used, if it is defined somewhere in any of the .cpp files




#5030661 ANN an alternative to evolving multiple instances

Posted by Nickie on 10 February 2013 - 05:13 AM

There is one really good backprop tutorial. I needed 3 days to figure out what is happening, then I found it. Just from one read I implemented ANN library.

 

http://clemens.bytehammer.com/papers/BackProp/index.html

 

Good luck :)




#4993694 Create a Game Engine

Posted by Nickie on 24 October 2012 - 11:48 PM

Creating a game engine is really hard task. Especially for someone that hasn't got enough experience. I wated around 1 year before I start my engine(after this idea first came into my mind). During this time I read all books which had the keywords "engine" and "programming" in their titles(If I could find them in PDF, i would really like to buy some of them however not everyone has money).
And I can say, it would be better if I had waited a little more.
The result was: 5 months working on engine. And then give up, and start it from the very beginning. WHY? Well, books don't tell how you should struct your code. They can just show the way. I also coun't make a plan for my project. I mean I couln't plan my features. This two mistakes bring me down. However I do not regret, I learned how to plan my future projects and how to make my code right with minimal effort.(under struct I meant const correctness, design, naming, etc.)
If you are going to start it now... well, happy debugging. The choise is yours.


#4978550 Strange Memory Leaks...

Posted by Nickie on 10 September 2012 - 06:15 AM

Ok. I fixed my destruction method of the hierarchies. -500 lines of memory leaks. Still 2000 left. Hmh.. I'll review my whole design for more of these circulars, however it will take time. I'll write here as soon as I'm done. Thanks.(I hope there won't be memory leaks after fixing them Posted Image)


I managed to take the memory leaks to 400 lines. I was actually right. It is thinking about my globals as memory leaks.
I have made a table like this:
ID, STRING, REF Count
And I'm actually keeping just the id in the strings. This gives really fast comparing.
And I have made for example a new actor event:

static const RE_String new_actor = "NewActor"; // this way the lookup for id is done just once at init

Strange. Maybe here comes this? What is beeing used for?:

I've seen this code:
#define new new (_FILE_, _LINE_, _LINE);

Any suggestions?


#4974443 D3D9 Is not rendering the whole mesh

Posted by Nickie on 29 August 2012 - 08:47 AM

Right after I post it I found my mistake. I was not setting proper size of the index buffer... Didn't notice it take size instead of count. After whole day debugging.
Posted Image

So this is the result. I'm trying to render a cube.(The cube has 3x3x2 triangles each face, but it is rendering only first row from top. (If culling = none -> it renders also the bottom of the cube, but still half top and walls are missing)
Cube is loaded from .ASE file. (I've made simple level editor loading ASE files a year ago. it could render the cube as it shoud. => file is OK. NOTE: I'm using effects for first time. The shader is just taking matrix(WolrdViewProj) and multiply it to the vertex. Then pixel shader just returns white color)
I've have tripple checked the data I put into the buffers. It is ok.
I think I'm not passing the right parameter somewhere. The whole source code, like always, can be found here: http://code.google.c.../ random-engine
However, I have tried to extract the code which I think is the problem, to make people's life easier:
D3DVERTEXELEMENT9 VertexPosElements[] =
{
		{0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
		D3DDECL_END()
};   // I'm using array of D3DXVECTOR3 for the vertices
void CALLBACK RandomEngineApp::OnRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void *pUserContext )
{
Mat4x4 proj, view, world, rot; static float r = 0; r+= 0.007;
world = Mat4x4::g_Identity;
D3DXMatrixRotationY(&rot, r);
Vec4 v(3,2,3,1);
D3DXVec4Transform(&v, &v, &rot);
D3DXMatrixLookAtLH( &view, &Vec3(v.x,v.y,v.z), &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,1,0) );
D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI / 4, 1.33f, 0.01f , 1000.0f);

g_pApp->m_Renderer->VSetProjMatrix(&proj);
g_pApp->m_Renderer->VSetViewMatrix(&view);
g_pApp->m_Renderer->VSetWorldMatrix(&world);
g_pApp->m_Renderer->VClear();
g_pApp->m_Renderer->VBeginScene();
//g_pApp->GetLogic()->VOnRender();//this will be used later when I know what I am doing
g_pApp->GetRenderer()->VSetDeclaration(VertexPosElements); // vertex element declaration, this is something I have no idea if I'm doing it right
AssetDataPtr mesh(AssetManager::Get()->GetAssetData(Resource("box.ase\\box.ase"))->front()); // get the first mesh, found in box.ase, don't worry it is not parsing or loading it here
g_pApp->m_Renderer->VDrawMesh(dynamic_cast<RE_Mesh*>(mesh.get()));
g_pApp->m_Renderer->VEndScene();
}
void Renderer9::VSetDeclaration(D3DVERTEXELEMENT9 * vd)
{
IDirect3DVertexDeclaration9 * vdp;
DXUTGetD3D9Device()->CreateVertexDeclaration(vd, &vdp);
DXUTGetD3D9Device()->SetVertexDeclaration(vdp);
vdp->Release();
}
void Renderer9::VBeginScene()
{
DXUTGetD3D9Device()->BeginScene();
}
void Renderer9::VEndScene()
{
DXUTGetD3D9Device()->EndScene();
}

void Renderer9::VDrawMesh(RE_Mesh * mesh)
{
HRESULT hr;
D3DXMATRIXA16 WorldViewProj = m_World * m_View * m_Proj;
unsigned int passes;
hr = m_pREffect->SetTechnique("SimpleRender");
hr = m_pREffect->SetMatrix("c_WorldViewProj", &WorldViewProj);
hr = DXUTGetD3D9Device()->SetIndices(mesh->m_IB9);
hr = DXUTGetD3D9Device()->SetStreamSource(0, mesh->m_VB9, 0, sizeof(D3DXVECTOR3));
hr = m_pREffect->Begin(&passes, 0);
for(unsigned int iPass = 0; iPass < passes; iPass++)
{
  hr = m_pREffect->BeginPass(iPass);
  hr = ::DXUTGetD3D9Device()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->m_Vertices.size(), 0, mesh->m_Indeces.size() / 3);

  hr = m_pREffect->EndPass();
}
hr = m_pREffect->End();
}

void Renderer9::VUpdateIndexBuffer(RE_Mesh * mesh)
{
HRESULT hr;
if(mesh->m_IB9 == NULL)
{
  hr = DXUTGetD3D9Device()->CreateIndexBuffer(mesh->m_Indeces.size(), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &mesh->m_IB9, 0);
}
unsigned int * indeces = NULL;
mesh->m_IB9->Lock(0, mesh->m_Indeces.size(), (void **)&indeces, 0);
std::copy( mesh->m_Indeces.begin(), mesh->m_Indeces.end(), indeces);
mesh->m_IB9->Unlock();
}
void Renderer9::VUpdateVertexBuffer(RE_Mesh * mesh)
{
HRESULT hr;
if(mesh->m_VB9 == NULL)
{
  hr = DXUTGetD3D9Device()->CreateVertexBuffer(mesh->m_Vertices.size() * sizeof(Vec3), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mesh->m_VB9, 0);
}
Vec3 * vertices = NULL;
mesh->m_VB9->Lock(0, mesh->m_Vertices.size() * sizeof(Vec3), (void **)&vertices, 0);
std::copy( mesh->m_Vertices.begin(), mesh->m_Vertices.end(), vertices);
mesh->m_VB9->Unlock();
}
also RE_Mesh is keeping the indeces and vertices in std::vector,
If someone need more information and do not want to check the source cuz of the mess just ask. Thanks.


#4959624 Need tips on collision response for a 2D ball hitting another 2D ball that is...

Posted by Nickie on 16 July 2012 - 09:56 AM

I'm not really experienced programmer but heres' what I would do:
1. I would find the center of the ball and the radius

2. When a ball move I would loop through all balls and check if the ball 1's radius + ball 2's radius < magnitute(ball 2's pos - ball 1's pos)
3. If the balls are moving with speed higher than ball 1's diameter + ball 2's diameter, I would make the same checks like in 2 but this time with half the current speed (creating temp location and then checking for collisions... also this is bad idea to be hard coded. I mean divide ur speed by the diameter to find out how many checks u need and use loop to check all needed positions so u are sure u won't miss the ball)
4. if collision occurs ( 2. returns true ), get the reverse vector and find out the best position so they don't overlap.

Posted Image
Lame try to show u whats in my mind..


#4957550 Pathfinding algorithm

Posted by Nickie on 10 July 2012 - 02:33 AM

Hello,
My teacher( we're studing programming in the engineering school ) said its really hard to find a way without recursion so I wrote this in C when I was 9th grade; I hope it will help you, its console app:
1. You enter your starting and ending position; X >= 0, X <= 24, Y >=0, Y < 25. Yeah I know its fixed but I was too lazy that day xD
2. FIll in the closed boxes; Places where you can't use to reach the final destination
3. It will print you a 25x25 grid where 5 is your start position, 6 is your destination, 1 is the generated way, 2 are the "locked" boxes, and 0 is the free space where you could walk but u actually didn't

Please don't jungle me for not using const and references ;/

[source lang="cpp"]#include <stdio.h>#include <math.h>typedef struct _COORD{ int x, y;}COORD;typedef struct _BOX{int info, list;float g, h;COORD parent;}BOX;COORD bestNode();void CheckNeighbours(COORD cp);float magnitute(COORD a, COORD b);//global varsBOX grid[25][25]; // main mazeCOORD ep; // end postion. ( where u must reach )void printmaze(int clear){ //clear flag -> if 1 then it will clear the grid and set it to 0 //else -> jsut print its current state int i, z; for(i = 0; i < 25; i++) { for(z = 0; z < 25; z++) { if(clear == 1) { grid[i][z].info = 0; } printf("%i", grid[i][z].info); } printf("\n"); } printf("\n");}int main(){ COORD cp, sp; int e; COORD ctemp; e = 0; printf("Start point. X: / 0-24 / "); scanf("%i", &sp.y); printf("Start point. Y: / 0-24 / "); scanf("%i", &sp.x); printf("End point. X: / 0-24 / "); scanf("%i", &ep.y); printf("End point. Y: / 0-24 / "); scanf("%i", &ep.x); printmaze(1); //add closed printf("Add a closed block? Yes = 1, No = everything else: "); scanf("%i", &e); while(e == 1) { printf("Closed Block. X: / 0-24 / "); scanf("%i", &cp.y); printf("Closed Block. Y: / 0-24 / "); scanf("%i", &cp.x); grid[cp.x][cp.y].list = 2; grid[cp.x][cp.y].info = 2; // with 2 I've marked the closed postions where u can't go printf("Add a closed block? Yes = 1, No = everything else: "); scanf("%i", &e); } grid[sp.x][sp.y].info = 5; // start point on the grid grid[ep.x][ep.y].info = 6; // end point on the grid printf("\n"); // find best way cp.x = sp.x; cp.y = sp.y; //add to open list; grid[cp.x][cp.y].list = 1; grid[cp.x][cp.y].g = 0; grid[cp.x][cp.y].h = magnitute(cp, ep); while(!(cp.x == ep.x && cp.y == ep.y)) // while we have not reached the target {// current postion.x == end postion.x ... //check best node from open list; cp = bestNode(); printf("checking %i-%i \n", cp.x, cp.y); //check out neighbours; if(cp.x == -25000 || cp.y == -25000) // my grid is fix sized from 0-24 so I use -25000 as a flag { printf("There is no way."); cp.x = ep.x; cp.y = ep.y; }else{ CheckNeighbours(cp); grid[cp.x][cp.y].list = 2; // closed list } } while(!(cp.x == sp.x && cp.y == sp.y)) { cp = grid[cp.x][cp.y].parent; grid[cp.x][cp.y].info = 1; if(cp.x == sp.x && cp.y == sp.y) grid[cp.x][cp.y].info = 5; } printf("\n"); printmaze(2); printf("End. \n"); scanf("%i", &e); return 0;}void CheckNeighbours(COORD cp){ int i, z; COORD ctemp; for(i = -1; i < 2; i++) { for(z = -1; z < 2; z++) { //check if alive; if(cp.x + i >= 0 && cp.x + i < 25 && cp.y + z >= 0 && cp.y + z < 25) { if(!(i == 0 && z == 0)) { if(grid[cp.x + i][cp.y + z].list != 1 && grid[cp.x + i][cp.y + z].list != 2) { //if open list or closed grid[cp.x + i][cp.y + z].list = 1; grid[cp.x + i][cp.y + z].parent.x = cp.x; grid[cp.x + i][cp.y + z].parent.y = cp.y; //record h value ctemp.x = cp.x + i; ctemp.y = cp.y + z; grid[cp.x + i][cp.y + z].h = magnitute(ctemp, ep); grid[cp.x + i][cp.y + z].g = magnitute(ctemp, cp) + grid[cp.x][cp.y].g; printf("new neighbour: %i - %i \n", cp.x + i, cp.y + z); }else if(grid[cp.x + i][cp.y + z].list == 1) { ctemp.x = cp.x + i; ctemp.y = cp.y + z; if( grid[cp.x + i][cp.y + z].g > grid[cp.x][cp.y].g + magnitute(cp, ctemp)) { grid[cp.x + i][cp.y + z].parent = cp; grid[cp.x + i][cp.y + z].g = magnitute(ctemp, cp) + grid[cp.x][cp.y].g; } } } // end if mid } // end if alive } // end for z } return;}COORD bestNode(){ int i, z; int bestf = -25000; int a = 0; COORD bestNode; for(i = 0; i < 25; i++) { for(z = 0; z < 25; z++) { if(grid[i][z].list == 1) { if(a == 0) { a = 1; bestf = grid[i][z].g + grid[i][z].h; bestNode.x = i; bestNode.y = z; } else { if(bestf > grid[i][z].g + grid[i][z].h) { bestf = grid[i][z].g + grid[i][z].h; bestNode.x = i; bestNode.y = z; } } } } } if(a == 0) { bestNode.x = -25000; bestNode.y = -25000; } return bestNode;}float magnitute(COORD a, COORD b){ COORD toret; float ab; if(a.x > b.x) { toret.x = a.x - b.x; }else { toret.x = b.x - a.x; } if(a.y > b.y) { toret.y = a.y - b.y; }else { toret.y = b.y - a.y; } ab = toret.x * toret.x + toret.y * toret.y; ab = sqrt(ab); return ab;}[/source]


PARTNERS