# Temrek

Member

20

122 Neutral

• Rank
Member
1. ## Need ideas for a pathfinding algorithm

While I was thinking of doing an adaption of A*, mainly by adding a large movement cost for turning (To clarify, I mean turns as in changes of direction. The game itself is realtime) but I am unsure if that would not mean certain tiles will be blocked and closed when another possible travel path might need them, resulting in screwy paths or areas blocked off from certain starting points?
2. ## Need ideas for a pathfinding algorithm

Quote:Original post by Palidine A* will always find the shortest path, so that's generally a good place to start. What do you mean by "as few turns as possible". Do you mean as few rounds as possible or do you mean actually make the unit not turn left or right whenever possible? -me The last one. The fewer turns needed, the more resources can be expended on other things. To clarify, free turns and unstable free turns are only done based on terrain.
3. ## Need ideas for a pathfinding algorithm

I need ideas for designing a pathfinding system. The game its for is about giding objects to specifik places and the resource needed for that is turns. So essentially the AI need to do as few turns as possible, the algorithm should also support free turns (these does not count against a players resources) and unstable free turns (these are prefered to regular turns but avoided in favor of no turns if possible or regular free turns). Actually finding the shortest path is less important (but useful) then finding a path with as few turns as possible. Also, it needs to be quick. As it might need to do these pathfinding checks a couple of hundred times in a second (although, between fifty and sixty times is much more common). There is a limit to the amount of turns a player can spend as well (typcially between 3 and 5), so that should help reducing processing time as well. The game is also tilebased. Thank you.
4. ## Cannot draw primitive

I am suspecting that the void pointer is the criminal, am I wrong?
5. ## Cannot draw primitive

Well ok, but keep in mind that I have not really put that much effort into doing things properly as its justa learning exercise. (Set dimensions should go into the contructor, for instance) // include the basic windows header files and the Direct3D header file #include "stdafx.h" #include "RatEngine.h" #include "WndMsgHandler.h" // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // Entry Point int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //The Game engine class RatEngine RE; RE.SetDimensions(1024, 768); //The windows message handler WndMsgHandler WMH; HWND hWd; //The main app window hWd = RE.InitWindow(hInstance); RE.InitDirectX(); //The main game loop while (TRUE) { RE.CreatePlane(); RE.RenderFrame(); RE.KeyChecker(); int nSignal = WMH.IntereptMessage(); //Store any windows message signals //If IntereptMessage tells the app to quit, do so if (nSignal == 1) { RE.DestroyEngine(); break; } } return 0; } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc (hWnd, message, wParam, lParam); } RatEngine.h #include <windows.h> #include <windowsx.h> #define D3D_DEBUG_INFO #include <d3d9.h> #include <d3dx9.h> #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") //Struct prototypes struct VERTEXSTRUCT {FLOAT x, y, z, rhw; DWORD color;}; struct CURRENTGAMESTATE {bool Menu; bool Game;}; //Definations #define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE) #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // Global Pointers LPDIRECT3D9 d3d; // D3D interface pointer LPDIRECT3DDEVICE9 dxDev; // device class pointer LPDIRECT3DVERTEXBUFFER9 dxVB = NULL; // vertex buffer pointer // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); class RatEngine { HWND hWd; //The window to be created public: void SetDimensions(int nX, int nY); HWND InitWindow(HINSTANCE hInstance); int ScreenX; int ScreenY; void InitDirectX(); void RenderFrame(); void DestroyEngine(); void KeyChecker(); void CreatePlane(); }; //This function handles all the intialization code for the main game window HWND RatEngine::InitWindow(HINSTANCE hInstance) { WNDCLASSEX wStr; //The window struct ZeroMemory(&wStr, sizeof(WNDCLASSEX)); //Set the struct to null //Enter struct settings wStr.cbSize = sizeof(WNDCLASSEX); wStr.style = CS_HREDRAW | CS_VREDRAW; wStr.lpfnWndProc = (WNDPROC)WindowProc; wStr.hInstance = hInstance; wStr.hCursor = LoadCursor(NULL, IDC_ARROW); wStr.lpszClassName = L"WindowClass"; RegisterClassEx(&wStr); //Leave the window to windows //Create the window hWd = CreateWindowEx(NULL, L"WindowClass", L"RatsFTW", WS_EX_TOPMOST | WS_POPUP, 0, 0, ScreenX, ScreenY, NULL, NULL, hInstance, NULL); //Display it! ShowWindow(hWd, NULL); return hWd; } //This function handles all the intialization code for DirectX void RatEngine::InitDirectX() { //Create the device d3d = Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS dxStr; //Create the Direct3d data struct ZeroMemory(&dxStr, sizeof(dxStr)); //Clear the data struct //Enter d3d settings dxStr.Windowed = FALSE; dxStr.SwapEffect = D3DSWAPEFFECT_DISCARD; dxStr.hDeviceWindow = hWd; dxStr.BackBufferFormat = D3DFMT_X8R8G8B8; dxStr.BackBufferWidth = ScreenX; dxStr.BackBufferHeight = ScreenY; dxStr.EnableAutoDepthStencil = TRUE; dxStr.AutoDepthStencilFormat = D3DFMT_D16; //Create the device, put in new information and send the struct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dxStr, &dxDev); dxDev->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); dxDev->SetRenderState(D3DRS_LIGHTING, FALSE); dxDev->SetRenderState(D3DRS_ZENABLE, TRUE); return; } //This function renders a single frame void RatEngine::RenderFrame() { dxDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0); dxDev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); dxDev->BeginScene(); // select which vertex format we are using dxDev->SetFVF(CUSTOMFVF); // select the vertex buffer to display dxDev->SetStreamSource(0, dxVB, 0, sizeof(VERTEXSTRUCT)); // copy the vertex buffer to the back buffer dxDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); dxDev->EndScene(); dxDev->Present(NULL, NULL, NULL, NULL); return; } void RatEngine::DestroyEngine() { dxVB->Release(); // Destroy vertex buffer dxDev->Release(); // Destroy Device d3d->Release(); // Destroy Interface pointer return; } //This function checks for any keys that are pressed void RatEngine::KeyChecker() { //Tell the app ti shutdow´nf if a key is pressed if(KEY_DOWN(VK_ESCAPE)) { PostMessage(hWd, WM_DESTROY, 0, 0); } } //Create the basic plane the game takes place on void RatEngine::CreatePlane() { //Define the plane struct VERTEXSTRUCT vsPlane[] = { { 3.0f, 3.0f, 0.0f, 0.5f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 3.0f, 0.0f, 0.5f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 9.0f, 0.0f, 0.5f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 9.0f, 0.0f, 0.5f, D3DCOLOR_XRGB(220, 220, 220), }, }; //Create the vertex buffer dxDev->CreateVertexBuffer(4*sizeof(VERTEXSTRUCT), 0, CUSTOMFVF, D3DPOOL_MANAGED, &dxVB, NULL); VOID* pVoid; // lock t_buffer and load the vertices into it dxVB->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vsPlane, sizeof(vsPlane)); dxVB->Unlock(); return; } //Set the screen resolution void RatEngine::SetDimensions(int nX, int nY) { ScreenX = nX; ScreenY = nY; } WndMsgHandler.h #include <windows.h> #include <windowsx.h> class WndMsgHandler { MSG msg; //This one stores the windows messages. public: int IntereptMessage(); }; // //This function takes a message and interpets it, and returns an INT value that signals //to the main .cpp file what to do. int WndMsgHandler::IntereptMessage() { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { //Tell the main .cpp file to quit. return 1; } TranslateMessage(&msg); DispatchMessage(&msg); } //Tell the main .cpp file to do nothing. return 0; } [/source]

7. ## Cannot draw primitive

I tried it all, nothing seems to fail but it does still not work :( dxDev->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); dxDev->SetRenderState(D3DRS_LIGHTING, FALSE); dxDev->SetRenderState(D3DRS_ZENABLE, TRUE); struct VERTEXSTRUCT vsPlane[] = { { 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 9.0f, 0.0f, D3DCOLOR_XRGB(220, 220, 220), }, { 9.0f, 9.0f, 0.0f, D3DCOLOR_XRGB(220, 220, 220), }, }; struct VERTEXSTRUCT {FLOAT X, Y, Z; DWORD COLOR;};
8. ## Cannot draw primitive

Hi, I am trying to learn to use DirectX and Direct 3d specifically, using various sources. I am working with c++ and I cannot figure out why this c++ code does not work, all I an trying to do is to draw a square. Instead it simply displays a black background with a slightly greenish tone (As its supposed to be). This should be all relevant parts, thank you for any help. while (TRUE) { RE.CreatePlane(); RE.RenderFrame(); } void RatEngine::RenderFrame() { dxDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 26, 0), 1.0f, 0); dxDev->BeginScene(); dxDev->SetFVF(CUSTOMFVF); // select the vertex buffer to display dxDev->SetStreamSource(0, dxVB, 0, sizeof(VERTEXSTRUCT)); // copy the vertex buffer to the back buffer dxDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); dxDev->EndScene(); dxDev->Present(NULL, NULL, NULL, NULL); return; } void RatEngine::CreatePlane() { //Define the plane struct VERTEXSTRUCT vsPlane[] = { { -3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255),},// 1,0,}, { 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0),},// 0,0,}, { -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0),},// 1,1,}, { 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 255),},// 0,1,}, }; //Create the vertex buffer dxDev->CreateVertexBuffer(4*sizeof(VERTEXSTRUCT), 0, CUSTOMFVF, D3DPOOL_MANAGED, &dxVB, NULL); VOID* pVoid; // lock t_buffer and load the vertices into it dxVB->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vsPlane, sizeof(vsPlane)); dxVB->Unlock(); return; } This is the top of the ratengine.h file. #include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h> #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9.lib") //Struct prototypes struct VERTEXSTRUCT { FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag DWORD color; // from the D3DFVF_DIFFUSE flag }; struct CURRENTGAMESTATE {bool Menu; bool Game;}; //Definations #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) //| D3DFVF_TEX1) #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // Global Pointers LPDIRECT3D9 d3d; // D3D interface pointer LPDIRECT3DDEVICE9 dxDev; // device class pointer LPDIRECT3DVERTEXBUFFER9 dxVB = NULL; // vertex buffer pointer // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); ]
9. ## Crash when reading from a file

Hi this piece of code crashes once it gets to the getline function (it prints Test in the console). char* cT; cT ="Test"; cout << cT; file >> cT; cout << cT; Its unlikely that it is the file that causes the error as I can read it to a std::string but I need it as a char* to be able to work with it. I tried copying the data of a std::string into a char* but that also crashes :(
10. ## char array is being assigned a vlaue when it should not.

I meant I write NULL in the file (that data is read but not used, hence null, I could do without not actually writing anything though). By the way I got it to work completly as I want to, thanks for all your help!
11. ## char array is being assigned a vlaue when it should not.

The file looks exactly like engima figured out (except replace something with NULL). I got it to work better now, but it does not work as it is supposed to. BTW I am using structs. It never seems to detect eof. if (file.eof() == true || times == 9) { break; } The output I get is right except it does not stop when it is supposed to.
12. ## char array is being assigned a vlaue when it should not.

Okay, I am trying to get this working but it just refuses to. std::ifstream file(path); bool readCollisionMap = false; //std::vector< Thing > things; file.ignore(500,'/n'); int times = 0; while (true) { std::string collisionMap; file >> collisionMap; cout << collisionMap << endl; if (collisionMap == "FILEEND" || times == 9) { break; } if (!readCollisionMap) { Colitmap = collisionMap; readCollisionMap = true; } file >> TileModels[times].Path; cout << TileModels[times].Path << endl; file >> TileModels[times].x; file >> TileModels[times].y; file >> TileModels[times].z; file >> TileModels[times].scale; file >> TileFX[times].Path; file >> TileFX[times].x; file >> TileFX[times].y; file >> TileFX[times].z; times++; //things.push_back(Thing); } file.close(); the thing crashes without giving any output that I can see, also I cant find anywhere what push_back is supposed to do.
13. ## char array is being assigned a vlaue when it should not.

That piece of code looks promising (much shorter then my newb code :P ) but I wonder what the thing in the vector is suposed to be as well as the Thing thing; ?
14. ## char array is being assigned a vlaue when it should not.

Unfortunatly that does not work :(
15. ## char array is being assigned a vlaue when it should not.

I have tried that strtok did not like it :(
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!