Johannes1991

Member
  • Content count

    71
  • Joined

  • Last visited

Community Reputation

441 Neutral

About Johannes1991

  • Rank
    Member

Personal Information

  • Interests
    Art
    Audio
    Design
    DevOps
    Programming
    QA

Social

  • Github
    johannesolsoon@msn.com
  • Steam
    hona_j
  1. I am trying to rotate a vector to a goal vector. My main problem now is that I can't wrap my head on is which way to rotate the vector, so finding the "shortest" way to rotate (clockwise or counter clockwise).
  2. Win32 input crash

    Ok, thanks for the tips. But I want to make the input code separated from the callback function. And I still have no clue why it causes my program to stall from time to time.
  3. Hi I've recently moved from directInput to using win32 for input and I've been experienced some hold ups in my program. The window stops responding for a  split second and works again, And the longer the program runs the longer the stops gets. If the program loses focus and gets it back then the program stops responding completely and has to be terminated. I'm suspecting it's the game loop and/or use of peekmessage()!  GameLoop   MSG msg; bool gameRunning = true; uint lastFrame = frameTimeStamp; while(gameRunning) { lastFrameTimeStamp = frameTimeStamp; frameTimeStamp = timeGetTime(); if(frameTimeStamp - lastFrame > 17) { elapsedTime = (float)(frameTimeStamp - lastFrame) * 0.001f; input.Update(); while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) { gameRunning = false; break; } TranslateMessage(&msg); DispatchMessage(&msg); } game.Update(); game.Render(); lastFrame = frameTimeStamp; } } input class:   void HInput::Update() { if (!wndHandle) return; keyEventCount = 0; mouseEventCount = 0; MSG msg; // shift current keystates to last keystates memcpy(lastKeyStates, currentKeyStates, sizeof(bool) * INPUT_KEY_COUNT); // intercept input messages from the window while (PeekMessage(&msg, wndHandle, WM_KEYFIRST , WM_KEYLAST, PM_REMOVE)) { TranslateMessage(&msg); INPUT_KEY key = TranslateWin32Key(msg.wParam); INPUT_KEY button; int x = GET_X_LPARAM(msg.lParam); int y = GET_Y_LPARAM(msg.lParam); switch(msg.message) { case WM_KEYDOWN: if (key == KEY_UNSUPPORTED) break; SET_KEY(key); AddKeyEvent(key); break; case WM_KEYUP: if (key == KEY_UNSUPPORTED) break; CLEAR_KEY(key); break; case WM_CHAR: AddCharEvent(msg.wParam); break; } } POINT pos; GetCursorPos(&pos); ScreenToClient(wndHandle, &pos); deltaX = pos.x - mouseX; deltaY = pos.y - mouseY; mouseX = pos.x; mouseY = pos.y; while (PeekMessage(&msg, wndHandle, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)) { INPUT_KEY button; int x = GET_X_LPARAM(msg.lParam); int y = GET_Y_LPARAM(msg.lParam); switch(msg.message) { case WM_LBUTTONDOWN: SET_KEY(MOUSE_LMB); AddMouseEvent(IMET_CLICK, MOUSE_LMB, x, y); break; case WM_LBUTTONUP: CLEAR_KEY(MOUSE_LMB); AddMouseEvent(IMET_RELEASE, MOUSE_LMB, x, y); break; case WM_LBUTTONDBLCLK: AddMouseEvent(IMET_DOUBLECLICK, MOUSE_LMB, x, y); break; case WM_RBUTTONDOWN: SET_KEY(MOUSE_RMB); AddMouseEvent(IMET_CLICK, MOUSE_RMB, x, y); break; case WM_RBUTTONUP: CLEAR_KEY(MOUSE_RMB); AddMouseEvent(IMET_RELEASE, MOUSE_RMB, x, y); break; case WM_RBUTTONDBLCLK: AddMouseEvent(IMET_DOUBLECLICK, MOUSE_RMB, x, y); break; case WM_MBUTTONDOWN: SET_KEY(MOUSE_MMB); AddMouseEvent(IMET_CLICK, MOUSE_MMB, x, y); break; case WM_MBUTTONUP: CLEAR_KEY(MOUSE_MMB); AddMouseEvent(IMET_RELEASE, MOUSE_MMB, x, y); break; case WM_MBUTTONDBLCLK: AddMouseEvent(IMET_DOUBLECLICK, MOUSE_MMB, x, y); break; case WM_XBUTTONDOWN: // for both x buttons if (HIWORD(msg.wParam) & XBUTTON1) button = MOUSE_M4B; else if (HIWORD(msg.wParam) & XBUTTON2) button = MOUSE_M5B; SET_KEY(button); AddMouseEvent(IMET_CLICK, button, x, y); break; case WM_XBUTTONUP: if (HIWORD(msg.wParam) & XBUTTON1) button = MOUSE_M4B; else if (HIWORD(msg.wParam) & XBUTTON2) button = MOUSE_M5B; CLEAR_KEY(button); AddMouseEvent(IMET_RELEASE, button, x, y); break; case WM_XBUTTONDBLCLK: if (HIWORD(msg.wParam) & XBUTTON1) button = MOUSE_M4B; else if (HIWORD(msg.wParam) & XBUTTON2) button = MOUSE_M5B; AddMouseEvent(IMET_DOUBLECLICK, button, x, y); break; } } }  
  4. Virtual Texture Terrain

  5. Compile Shader From Memory

    I have started making my own shader loader and of course it's not working! When I read from the shader file i separate the hlsl code and my own code into different strings and when i try to compile the shader code with D3DX11CompileFromMemory() I get this error message: "error X3000: syntax error: unexpected end of file" I have put a null terminator in the end of the string but it doesn't work... So anyone know the reason for this problem? Code: std::fstream file(path, std::ios::in); std::string shaderCode = "", tempBuffer; if(file.is_open()) { while(!file.eof()) { //file.get(tempBuffer); file >> tempBuffer; if(tempBuffer == "ShaderInformation") { int i = 0; i += 0; } else { shaderCode += " " + tempBuffer; } } } shaderCode += '\0'; HRESULT hr; ID3D10Blob *vsBlob, *psBlob, *errorBlob; //Dummy hlsl code const char temp[] = "Texture2D colormap;" "Texture2D lightmap;" "SamplerState fullscreenQuadSampler;" "struct VertexInput" "{" "float3 position : POSITION0;" "float2 uv : TEXCOORD0;" "};" "struct PixelInput" "{" "float4 position : SV_Position;" "float2 uv : TEXCOORD0;" "};" "PixelInput VS(VertexInput input)" "{" "PixelInput output;" "output.position = float4(input.position, 1.0f);" "float2 halfPixel = float2(0.5f / 800.0f, 0.5f / 600.0f);" "output.uv = input.uv;// + halfPixel;" "return output;" "}" "float4 PS(PixelInput input) : SV_Target" "{" "float3 diffuseColor = colormap.Sample(fullscreenQuadSampler, input.uv).rgb;" "float4 lightData = lightmap.Sample(fullscreenQuadSampler, input.uv);" "float3 diffuseLight = lightData.rgb;" "float specularLight = lightData.a;" "return float4(diffuseColor * diffuseLight + specularLight, 1.0f);" "}" "\0"; hr = D3DX11CompileFromMemory(temp, sizeof(temp), "FinalComposition.hlsl", NULL, NULL, "VS", "vs_4_0", D3D10_SHADER_PACK_MATRIX_ROW_MAJOR, NULL, NULL, &vsBlob, &errorBlob, NULL); if(hr != S_OK) { if(!errorBlob) return false; char msg[20000]; strcpy_s(msg, sizeof(msg), (char*)errorBlob->GetBufferPointer()); OutputDebugStringA(msg); MessageBoxA(GetDesktopWindow(), msg, "VertexShader Compilation Failed!", MB_OK | MB_ICONERROR); errorBlob->Release(); return false; }    
  6. CPU lost some pins :(

    Maybe some pictures could help us determine? or it's may just me
  7. How the hell do you answer a phone?

    Here's a perfect example! [img]http://weknowmemes.com/wp-content/uploads/2011/10/hello-yes-this-is-dog.png[/img]
  8. My Server/Client lagging crazy

    Solved it! I was sending to many packages! per second
  9. I've been playing around with winsock now from time to time and i decided to make a test server and client. I got the server up and going and the client works aswell. But there's a delay of 1 - 2 secs, just now i'm only sending the positions back and forth. First when i used send() i set the len paramter with sizeof(package). But it made my client side unstable. But when i set a constant size it became very stable. The code is in c++, Server code,(process package is in the client too): [CODE] bool Server::Initialize_Server(UINT MaxClients) { this->MaxClients = MaxClients; ClientAddresses = new sockaddr_in[MaxClients]; ClientSockets = new SOCKET[MaxClients]; AddressSize = sizeof(sockaddr_in); NumberOfClients = 0; if(WSAStartup(MAKEWORD(2,2), &Winsock) == WSAVERNOTSUPPORTED) { cout << "\n\nCouldn't Start Winsock\n\n"; WSACleanup(); return false; } HostSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(HostSocket == INVALID_SOCKET) { cout << "\n\nServer Socket Couldn't Be Created\n\n"; WSACleanup(); return false; } ZeroMemory(&HostAddress, sizeof(sockaddr_in)); HostAddress.sin_family = AF_INET; HostAddress.sin_port = htons(PortNumber); HostAddress.sin_addr.s_addr = INADDR_ANY; if(bind(HostSocket, (sockaddr *) &HostAddress, sizeof(sockaddr_in)) != 0) { int i = WSAGetLastError(); cout << "Couldn't Bind Socket"; WSACleanup(); return false; } if(listen(HostSocket, MaxClients) != 0) { cout << "Couldn't Listen To Socket"; WSACleanup(); return false; } u_long iMode = 1; ioctlsocket(HostSocket, FIONBIO, &iMode); MultiPlayer_1(); return true; } void Server::Process_Packages() { int PackageSize, PointerPos; char* tempPackage; for(int i = 0; i < NumberOfClients; i++) { PointerPos = PackageSize = 0; ZeroMemory(Buffer, BufferSize); PackageSize = recv(ClientSockets[i], Buffer, BufferSize, NULL); while(PointerPos < PackageSize) { char PackageID = *((char *) (Buffer + PointerPos)); switch(PackageID) { case PackageID_Player: { //tempPackage = Network_Stuff.Check_Complete_Package(sizeof(GroupUnitInfos_Package), &PackageSize, 512, &PointerPos, (char *&) *Buffer); if(!Check_Package_Whole(&ClientSockets[i], &PointerPos, sizeof(Player_Package), &PackageSize, tempPackage)) { Player_Package* temp = (Player_Package *) tempPackage; Player* tempPlayer = (Player *) GameData.ObjectList[temp->Player_ID]; tempPlayer->Set_Position(temp->Position); tempPlayer->Set_Direction(temp->Direction); delete[] tempPackage; }else { Player_Package* temp = (Player_Package *) (Buffer + PointerPos); PointerPos += sizeof(Player_Package); Player* tempPlayer = (Player *) GameData.ObjectList[temp->Player_ID]; tempPlayer->Set_Position(temp->Position); tempPlayer->Set_Direction(temp->Direction); } }break; default: { cout << "\n\nCouldn't Identify Package\nPackage Size: " << PackageSize * 0.001f << "kb\n\n"; PointerPos = PackageSize; } break; } } } } bool Server::Check_Package_Whole(SOCKET* const Socket, int* PointerPos, const int SizeOfPackage, int* RevievedPackageSize, char *& tempBuffer) { if(*RevievedPackageSize - *PointerPos < sizeof(SizeOfPackage)) { int PartSizeInBuffer = *RevievedPackageSize - *PointerPos; tempBuffer = new char[sizeof(SizeOfPackage)]; memcpy(tempBuffer, (char *)(Buffer + *PointerPos), PartSizeInBuffer); *RevievedPackageSize = recv(*Socket, Buffer, BufferSize, NULL); memcpy((char *) (tempBuffer + PartSizeInBuffer), Buffer, sizeof(SizeOfPackage) - PartSizeInBuffer); *PointerPos = sizeof(SizeOfPackage) - PartSizeInBuffer; return false; } else return true; } void Server::Update_Clients() { Player_Package Package; for(int i = 0; i < NumberOfClients; i++) { Package.Player_ID = i; Package.Position = GameData.ObjectList[i]->Get_Position(); Package.Direction = GameData.ObjectList[i]->Get_Direction(); for(int c = 0; c < NumberOfClients; c++) { if(c == i) continue; send(ClientSockets[c], (char *) &Package, BufferSize, NULL); } } } [/CODE]
  10. Turn Object around Point

    I've been trying to rotate a box around a certain point (for the purpose of angular velocity). I Know how to rotate the mesh around a point by changing the origo in mesh space, but the problem is that the i don't know how to rotate the Position variable too. Because if i change the rotation point(and the mesh origor) then the box "jumps" so the new origo in mesh space. Here's a pic for further explanation: [attachment=5856:Pic.png] The Plus is the Box Mesh Origo and the red circle is the Rotation Point. Thanx in advance
  11. Turn Object around Point

    I've been trying to rotate a box around a certain point (for the purpose of angular velocity). I Know how to rotate the mesh around a point by changing the origo in mesh space, but the problem is that the i don't know how to rotate the Position variable too. Because if i change the rotation point(and the mesh origor) then the box "jumps" so the new origo in mesh space. Here's a pic for further explanation: [attachment=5856:Pic.png] The Plus is the Box Mesh Origo and the red circle is the Rotation Point. Thanx in advance
  12. Winsock Questions

    [quote name='ApochPiQ' timestamp='1316711835' post='4864765'] WSAAsyncSelect is evil. I believe the Forum FAQ has a lot of explanations of precisely why. I think you'll have a much easier time of things if you use a different technique for handling your sockets! [/quote] haha ok I'm making a small RTS game so what type of socket would you recommend?
  13. Winsock Questions

    I'm using WSAAsyncSelect with TCP. Then thing about [color=#1C2837][size=2] FD_READ [/size][/color]is that i only get it if recv() have been called. i don't get FD_READ when I KNOW data has been sent to the server.
  14. Winsock Questions

    I've been playing around with Winsock(non blocking) and there are some things that i don't just get 1: I only get a FD_READ message when i've called the function recv() and a package arrive later. Is it suppose to be like that? for example if i call recv() 500 times and 100 packages was recieved. Will it keep checking for those 400 other package till the end of the program? 2: When i send a package that is 16 bytes and the recv() size is 256 then the reading of the package isn't always precise and vice versa. Only if the sizes are equal. So should i have a constant size for all of the packages(even if they are less)?. for example the constant size is 256 but i still send stuff that is 128 bytes, but the first bytes identifies the package so it's used correctly 3: If i should have a constant size then what is the reasonable size?
  15. Host - Clients connection

    [quote name='hplus0603' timestamp='1315858363' post='4860848'] [quote name='Johannes1991' timestamp='1315848307' post='4860760'] [code] while(NumberOfClients < MaxNetworkPlayers) { ClientSockets[NumberOfClients] = accept(Socket, (sockaddr*) &ClientAddresses[NumberOfClients], &AddressSize); if(ClientSockets[NumberOfClients] != SOCKET_ERROR) { NumberOfClients++; } }[/code] [/quote] So, nobody can send or receive any packets until the maximum number of players has joined the game? That doesn't seem right to me. [/quote] I'll thead that bad boy then! ;P