• Content count

  • Joined

  • Last visited

Community Reputation

1366 Excellent

About wannabeprogrammer

  • Rank
  1. Is this C code using pointers valid?

    Damn, 1 little asterisk breaks it. Thanks for pointing that out. Not sure how it worked as expected anyway! I did try using array notation but couldn't get it to work, so guess I need to read up about that a bit more unless someone is kind enough to show a quick example.   I tagged it as C as I didn't want people suggesting the use of new/delete or vector class etc. I'm using Visual C++ compiler so I confess it may not be *pure C* but for the purposes of this post it served its purpose.   FRex, I'm not sure what you mean by the following points   This code may read freed memory. - I don't access the pointer again after the call to free This code may double free. - Not sure how\where I'm doing this?   Thanks for the replies and suggestions :)
  2. Hi all.   I'm trying to write a C function that returns a dynamic list of servers. My pointer memory is a bit rusty so I just wanted to check if the code below is correct. Although the output is as expected, i.e. 3 servers with IP & name, and there appears to be no memory leaks (used Visual Leak Detector) I just want to triple check. Note, I'm just interested in knowing if the pointer usage is correct rather than actual logic or error checking. I'm using VS 2013 express. Thanks in advance. #include "stdafx.h" #include <stdio.h> #include <string.h> #include <stdlib.h> struct serverInfo { char serverName[50]; char serverIP[20]; }; int getServerListTest(serverInfo** pServers); int _tmain(int argc, _TCHAR* argv[]) { serverInfo *serverList = (serverInfo*)calloc(1, sizeof(serverInfo)); serverInfo **serverListPtr = &serverList; int serverCount = getServerListTest(serverListPtr); for (int i = 0; i < serverCount; i++) { printf("ip:%s name:%s\n", (*serverListPtr+i)->serverIP, (*serverListPtr+i)->serverName); } free(serverList); serverListPtr = NULL; getchar(); return 0; } int getServerListTest(serverInfo** pServers) { serverInfo* current = NULL; int serverCount= 0; char serverNo[5]; for (int i = 0; i < 3; i++) { if (serverCount > 0) { current = (serverInfo*)realloc((*pServers), sizeof(serverInfo) * (serverCount+1)); if (current) { pServers = &current; } else { return -1; } } _itoa(serverCount+1, serverNo, 10); strcpy((*pServers + serverCount)->serverIP, ""); strcat((*pServers + serverCount)->serverIP, serverNo); strcpy((*pServers + serverCount)->serverName, "Server"); strcat((*pServers + serverCount)->serverName, serverNo); serverCount++; } return serverCount; }
  3. Nothing is drawn

    I think there is something wrong with these lines vbd.ByteWidth = sizeof(pyramid_vertices); ibd.ByteWidth = sizeof(pyramid_indices);
  4. [DirectX9] 2D Camera transformation sidescroller

    Post your code where you update your camera position/target vectors.
  5. Advice on... Everything.

    Your only hope is to get a copy of QBASIC, learn some ASM and conquer Mode 13!   I'm intrigued, what is the spec of your PC?
  6. Rotation in 3D

    Below is some very rough code from a test app I did a few months back. Haven't got round to tidying it up or putting it in a camera class but it works like a Quake 3 spectator camera. No Z rotation. I hope thats what you mean by freelook. Note this is not a full working code post, just snippets.   // Globals int g_ScreenWidth,g_ScreenHeight; XMVECTOR g_CamEye; XMVECTOR g_CamAt; XMVECTOR g_CamUp; XMVECTOR g_CamOrigTarget; XMVECTOR g_CamOrigUp; float g_CamAngleYaw, g_CamAnglePitch, g_CamAngleRoll; // Init g_World = XMMatrixIdentity(); g_CamAngleYaw = g_CamAnglePitch = g_CamAngleRoll = 0; g_CamOrigTarget = XMVectorSet(0, 0, 1.0f, 0.0f); g_CamOrigUp = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); g_CamEye = XMVectorSet( 0.0f, 1.0f, -1.0f, 0.0f ); g_CamAt = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); g_CamUp = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); g_View = XMMatrixLookAtLH( g_CamEye, g_CamAt, g_CamUp ); g_Projection = XMMatrixPerspectiveFovLH( XM_PIDIV2, width / (FLOAT)height, 0.01f, 1000.0f ); // Render loop UpdateCamera(); ConstantBuffer cb; cb.mWorld = XMMatrixTranspose( g_World ); cb.mView = XMMatrixTranspose( g_View ); cb.mProjection = XMMatrixTranspose( g_Projection ); g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, NULL, &cb, 0, 0 ); // Call this in winmain message loop // Uses DXInput, init code not included void ProcessInput() { // Up Arrow if(g_KeyboardState[DIK_W] & 0x80) { XMVECTOR v_Dir = XMVectorSet( 0.0f, 0.0f, 1.0f, 1.0f ); MoveCamera(v_Dir); } // Down Arrow if(g_KeyboardState[DIK_S] & 0x80) { XMVECTOR v_Dir = XMVectorSet( 0.0f, 0.0f, -1.0f, 1.0f ); MoveCamera(v_Dir); } // Left Arrow if(g_KeyboardState[DIK_A] & 0x80) { UpdateCameraYaw(-0.1f,0.0f); } // Right Arrow if(g_KeyboardState[DIK_D] & 0x80) { UpdateCameraYaw(0.1f,0.0f); } // Look Up if(g_KeyboardState[DIK_PGUP] & 0x80) { UpdateCameraPitch(-0.1f); } // Look Down if(g_KeyboardState[DIK_PGDN] & 0x80) { UpdateCameraPitch(0.1f); } return; } // Camera functions void UpdateCamera() { XMMATRIX CamRot = XMMatrixRotationX(XMConvertToRadians(g_CamAnglePitch)) * XMMatrixRotationY(XMConvertToRadians(g_CamAngleYaw)); XMVECTOR CamTarget = g_CamEye + XMVector3Transform(g_CamOrigTarget, CamRot); g_View = XMMatrixLookAtLH( g_CamEye, CamTarget, g_CamUp ); } void MoveCamera(XMVECTOR in_Vec) { XMMATRIX CamRot = XMMatrixRotationX(XMConvertToRadians(g_CamAnglePitch)) * XMMatrixRotationY(XMConvertToRadians(g_CamAngleYaw)); g_CamEye += 0.01f * XMVector3Transform(in_Vec, CamRot); } void UpdateCameraYaw(float in_Amt, bool in_SetAmt) { if (in_SetAmt) { g_CamAngleYaw = in_Amt; } else { g_CamAngleYaw += in_Amt; } } void UpdateCameraPitch(float in_Amt) { g_CamAnglePitch += in_Amt; if (g_CamAnglePitch < -80) g_CamAnglePitch = -80; if (g_CamAnglePitch > 80) g_CamAnglePitch = 80; }
  7. Deadly Walkers: Zombie Game (PC/Mac)

    Hi   This game looks promising. I hope the kickstarter page describes the game in more detail and prices are realistic.   I don't think you posted it here but I think your website had a new video. I quite like it, would've liked to see more. Voice over man was good. Using same music as 28 days?   Have some questions if you can answer them.   1. What size map will this game have? 2. When will you be releasing more gameplay details, e.g. going into buildings, driving vehicles, single player story/objective? 3. How many in your team? 4. Where are you based?   gl with kickstarter :)
  8. How to escape a prison cell?

    You have ruled out a lot of things, which makes escaping pretty hard. The only ways I've seen someone escape from prison are; a weakness in the structure, outside help, magic or attacking guard walking past. Oh and of course getting a dog to help, ala monkey island   I would find it totally unrealistic to make a lockpick from grinding stones. Has this been done in a film/another game?   However, what about if you could find some rat bones under your bed that could be used for lock picking. Move bed, search area, find bones, pick correct combination of bones to pick lock.   From what I've read I also don't think you have mentioned how the pow gets fed and where he, er, does his business if you know what I mean. This info could maybe help in coming up with more suggestions.
  9. XNA window as a windows forms MDI child possible?

    I would try the controls from this article[url="http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1"] http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1[/url] I've not used them in a mdi app but they might work.
  10. .XNA design Question

    From the basic description you've presented I think you should only use 1 class, calling it player or character. These things you mention weapon type, different movespeed, different texture, animation would then be the members for the class and would change depending on the character. You would set these when you make an instance of you character object. You would then have your moving, collision detection, firing, etc methods that make use of these variables. However, if these methods vary greatly between the different characters then you should consider inheritance. You don't really provide enough information to give a complete answer.
  11. XNA starter

    [url="http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Starting_a_project.php"]http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Starting_a_project.php[/url] might be a good starting point. Website layout is a bit of a mess but the tutorials are ok and should help you get started.
  12. XNA 2D Grid Collision

    [font=arial,helvetica,sans-serif][size=3]1. Your map tiles are 64x64 but your player is 32x32 so a movement by 1 unit is not going to work. [/size][/font] [font=arial,helvetica,sans-serif][size=3]2. You do no boundary checks which will result in index out of range errors.[/size][/font] [font=arial,helvetica,sans-serif][size=3]3. In your player Move method you have the following line but the X and Y is the wrong way round. Plus adding 1 here is not a very good idea due to point 2 above[/size][/font] [font=arial,helvetica,sans-serif][size=3] if (map.grid[X, Y + 1] != 2) 4. You are only checking for water when the down arrow is pressed. Try changing your player to 64x64 and use the following code in your player move method[/size][/font]. [CODE] newstate = Keyboard.GetState(); int TmpX = X; int TmpY = Y; if (newstate.IsKeyDown(Keys.Down) && oldstate.IsKeyUp(Keys.Down)) { TmpY += 1; } if (newstate.IsKeyDown(Keys.Up) && oldstate.IsKeyUp(Keys.Up)) { TmpY -= 1; } if (newstate.IsKeyDown(Keys.Left) && oldstate.IsKeyUp(Keys.Left)) { TmpX -= 1; } if (newstate.IsKeyDown(Keys.Right) && oldstate.IsKeyUp(Keys.Right)) { TmpX += 1; } if (TmpX < 0) TmpX = 0; if (TmpX > map.mapWidth) TmpX = map.mapWidth; if (TmpY < 0) TmpY = 0; if (TmpY > map.mapHeight) TmpY = map.mapHeight; if (map.grid[TmpY, TmpX] != 2) { X = TmpX; Y = TmpY; } oldstate = newstate; [/CODE]