Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 22 Oct 2009
Offline Last Active Jul 15 2014 09:27 PM

Topics I've Started

In game periodic notice question

15 July 2014 - 08:30 PM

Hi, guys


I m currently designing a in game notice system, which basically broadcasts in game notices to all player periodically.

I have already implemented one and it works but something tells me it's not good enough, so I am seeking some advice to

make it better. Any suggestion would be appreciated


Here is my design

struct Notice
  int        NoticeId;              
  char*      pNoticeContent;         
  time_t     NoticeBeginTime;                 
  time_t     NoticeEndTime;                    
  time_t     NoticeGap;           // every NoticeGap , broadcast Notice Once


struct Timer
  time_t     currentTick;
  time_t     Interval;           

My initial design is assign every Notice a Timer, and update all these Timer.currentTick in the game loop, so when Timer.currentTick is larger than the Timer.Interval(the NoticeGap), it means this notice can be send now.


My question is , when the number of notices increases, There would be more and more Timers to tick, and I do not like this.

How can I use only one Timer to do the same thing?

A mmo related programming issue , unlock game features

25 October 2013 - 03:48 AM

Hi, guys


Currently I am having a tactical issue on some server programming stuff, really would like some suggestions


Basically I want to implement a module to unlock specific game features for players, say unlock blacksmith shop for all players who reach Lv 10. I am doing this by reading server config files.


Considering the following situation: A player reached Lv 8 and went offline and some game designers decide to change the config file during a server upgrade (Note: Now blacksmith shop unlock at Lv.5). So when this player come online again, he will discover that he is never going to unlock the blacksmith shop.


Is there any smart solution to this issue?

Of course I can keep the old config info with player data and compare it with the new data when player goes online, but that's definitely a awful idea since making thousand of players keep a portion of same data would be stupid.









[career] Mobile game server side question.

28 March 2013 - 12:45 AM

Hi guys,


I am pretty excited now because I am going to start my first game making job next week!


As you can see in the post title, I am going to work on a mobile game and basically I will focus on the server side.


The question is I am not sure what exactly I was expected to do!


my main skills are general C++, DirectX9,11 and OO, so I have no idea on networking programming or server tech like any.


Is there any good materials about mobile game/ server side I can refer on? or is there any online tutorial I can learn from?


I would like to do some homework so I might not look that silly on field.


I appereciate any suggestion!





Get error when I try to use XMMATRIX type as an function variable

28 September 2012 - 12:22 AM

Hi gentlemen,

There is a function in my class for some rendering job, and I would like to pass two matrix , view and projection from my Camera class to this external function.

its prototype is like

[source lang="cpp"]Draw(ID3D11Device* device, XMMATRIX view, XMMATRIX projection){ //...... ......//}[/source]

I get error messages like

[source lang="cpp"]Error 10 error C2719: 'view': formal parameter with __declspec(align('16')) won't be aligned[/source]

I 've googled and some say it's a known vector and Align data issue and MS will fix this in VC11.

Any idea How I can fix this?

Thank you and have a nice day!

D3D11DepthStencil doesn't work properly

14 September 2012 - 06:20 PM

Hello, guys, recently I 've got my hand on D3D11, so my question maybe a little Idiotic,but I am going to ask anyway :P
This program renders two cubes, one of them rotates around the central one, you know, basic stuff.
It's works fine except a depth problem which is when the rotating cube should not be rendered when it is "behind" the central cube, however, it was rendered.
I've double checked the depthstencil buffer code, but haven't seen where is gone wrong.
So maybe some nice person can help me out?

Any answer would be greatly appreciated. And here is my code
[source lang="cpp"] #include <windows.h> #include <windowsx.h>#include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h>#include <xnamath.h>// include the Direct3D Library file#pragma comment (lib, "d3d11.lib") #pragma comment (lib, "d3dx11.lib") #pragma comment (lib, "d3dx10.lib")#define SCREEN_WIDTH 800#define SCREEN_HEIGHT 600#define PI 3.14fstruct VERTEX{ FLOAT X, Y, Z; D3DXCOLOR Color;};//new type, updating constant buffer in shader in runtimestruct cbPerObject{ XMMATRIX WVP;};cbPerObject cbPerObj;// global declarationsIDXGISwapChain *swapchain; // the pointer to the swap chain interface ID3D11Device *dev; // the pointer to our Direct3D device interface ID3D11DeviceContext *devcon; // the pointer to our Direct3D device context ID3D11RenderTargetView *backbuffer; //globel declaration *2// function prototypesvoid InitD3D(HWND hWnd); // sets up and initializes Direct3Dvoid CleanD3D(void); // closes Direct3D and releases memoryvoid RenderFrame(void);void InitPipeline(void); // Initialize the rendering pipelinevoid InitGraphics(void);//Initialize the graphic stuffvoid InitDepthStencil(void);//Initialize the depth stencil buffervoid InitCamera(void);// Initialize cameravoid Update(void);// The scene update function//Using ShaderID3D11VertexShader *pVS;ID3D11PixelShader *pPS;//Shader bufferID3D11Buffer *pVertexBuffer;//Indices bufferID3D11Buffer *pIndexBuffer;//Input LayoutID3D11InputLayout *pLayout;//DepthstencilbufferID3D11DepthStencilView* pDepthStencilView;ID3D11Texture2D* pDepthStencilBuffer;//Camera stuffID3D11Buffer* cbPerObjectBuffer;XMMATRIX WVP;XMMATRIX World;XMMATRIX View;XMMATRIX Projection;XMVECTOR CameraPosition;XMVECTOR CameraTarget;XMVECTOR CameraUp;//Transformation stuffXMMATRIX CubeOne;XMMATRIX CubeTwo;XMMATRIX Translate;XMMATRIX Rotate;XMMATRIX Scale;float rot = 0.01f; // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); //wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); RECT wr = {0, 0,800, 600}; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindowEx(NULL, L"WindowClass", L"D3DBasicWindow", WS_OVERLAPPEDWINDOW, SCREEN_HEIGHT, SCREEN_WIDTH, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // set up and initialize Direct3D InitD3D(hWnd); // enter the main loop: MSG msg; while(TRUE) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); if(msg.message == WM_QUIT) break; } else { // Run game code here Update(); RenderFrame(); // ... // ... } } // clean up DirectX and COM CleanD3D(); return msg.wParam; } // this is the main message handler for the program 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); } // this function initializes and prepares Direct3D for use void InitD3D(HWND hWnd) { // create a struct to hold information about the swap chain DXGI_SWAP_CHAIN_DESC scd; // clear out the struct for use ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); // fill the swap chain description struct scd.BufferCount = 1; // one back buffer scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // use 32-bit color scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how swap chain is to be used //Tell dx the screen resolution scd.BufferDesc.Width = SCREEN_WIDTH; // set the back buffer width scd.BufferDesc.Height = SCREEN_HEIGHT; // set the back buffer height //Set DirectX to automatically switch when Alt-Enter is used. scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // allow full-screen switching scd.OutputWindow = hWnd; // the window to be used scd.SampleDesc.Count = 4; // how many multisamples scd.Windowed = TRUE; // windowed/full-screen mode // create a device, device context and swap chain using the information in the scd struct D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &swapchain, &dev, NULL, &devcon); //get the address of backbuffer ID3D11Texture2D *pBackBuffer; swapchain->GetBuffer(0,_uuidof(ID3D11Texture2D),(LPVOID*)&pBackBuffer); //use the backbuffer to create the render target dev->CreateRenderTargetView(pBackBuffer,NULL,&backbuffer); pBackBuffer->Release(); devcon->OMSetRenderTargets(1,&backbuffer,pDepthStencilView); //--Set the Viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; viewport.Height = SCREEN_HEIGHT; viewport.Width = SCREEN_WIDTH; devcon->RSSetViewports(1,&viewport); InitDepthStencil(); InitPipeline(); InitGraphics(); InitCamera(); } void InitPipeline(void) { //Load and compile shaders from file ID3D10Blob *VS, *PS; D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0); D3DX11CompileFromFile(L"shaders.hlsl", 0, 0,"PShader","ps_5_0", 0 , 0, 0, &PS, 0, 0); //Encapsulate shader into shader objects dev->CreateVertexShader(VS->GetBufferPointer(),VS->GetBufferSize(), NULL, &pVS); dev->CreatePixelShader(PS->GetBufferPointer(),PS->GetBufferSize(), NULL, &pPS); //Set shader to be active devcon->VSSetShader(pVS, 0, 0); devcon->PSSetShader(pPS, 0, 0); //Create the inputlayout D3D11_INPUT_ELEMENT_DESC ied[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, }; dev->CreateInputLayout(ied,2,VS->GetBufferPointer(),VS->GetBufferSize(),&pLayout); devcon->IASetInputLayout(pLayout); } void InitGraphics(void) { VERTEX CrossVertices[] = { { -1.0f, -1.0f, -1.0f , D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)},{ -1.0f, 1.0f, -1.0f, D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f) },{ 1.0f, 1.0f, -1.0f , D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)},//ABC {1.0f, -1.0f, -1.0f , D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)},{-1.0f, -1.0f, 1.0f , D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)}, { -1.0f, 1.0f, 1.0f, D3DXCOLOR(0.0f, 0.5f, 0.0f, 1.0f)},//DEF { 1.0f, 1.0f, 1.0f,D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f) },{+1.0f, -1.0f, 1.0f,D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f)},//GH }; // create the vertex buffer D3D11_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(bd)); bd.Usage = D3D11_USAGE_DYNAMIC; // write access access by CPU and GPU bd.ByteWidth = sizeof(VERTEX) * 36; // size is the VERTEX struct * 3 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; // use as a vertex buffer bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; // allow CPU to write in buffer dev->CreateBuffer(&bd, NULL, &pVertexBuffer); // create the buffer // copy the vertices into the buffer D3D11_MAPPED_SUBRESOURCE ms; devcon->Map(pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // map the buffer memcpy(ms.pData, CrossVertices, sizeof(CrossVertices)); // copy the data devcon->Unmap(pVertexBuffer, NULL); // unmap the buffer DWORD indices[ ] = { // front face 0, 1, 2, 0, 2, 3, // back face 4, 6, 5, 4, 7, 6, // left face 4, 5, 1, 4, 1, 0, // right face 3, 2, 6, 3, 6, 7, // top face 1, 5, 6, 1, 6, 2, // bottom face 4, 0, 3, 4, 3, 7 }; D3D11_BUFFER_DESC indexBufferDesc; ZeroMemory( &indexBufferDesc, sizeof(indexBufferDesc) ); indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(DWORD) * 36; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = indices; dev->CreateBuffer(&indexBufferDesc, &iinitData, &pIndexBuffer); devcon->IASetIndexBuffer( pIndexBuffer, DXGI_FORMAT_R32_UINT, 0); } void InitDepthStencil(void) { D3D11_TEXTURE2D_DESC DepthStencilDesc; DepthStencilDesc.Width = SCREEN_WIDTH; DepthStencilDesc.Height = SCREEN_HEIGHT; DepthStencilDesc.MipLevels = 1; DepthStencilDesc.ArraySize = 1; DepthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; DepthStencilDesc.SampleDesc.Count = 1; DepthStencilDesc.SampleDesc.Quality = 0; DepthStencilDesc.Usage = D3D11_USAGE_DEFAULT; DepthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; DepthStencilDesc.CPUAccessFlags = 0; DepthStencilDesc.MiscFlags = 0; //Create Depth Stencil View dev->CreateTexture2D(&DepthStencilDesc,NULL,&pDepthStencilBuffer); dev->CreateDepthStencilView(pDepthStencilBuffer, NULL, &pDepthStencilView); devcon->OMSetRenderTargets(1,&backbuffer,pDepthStencilView); } void InitCamera(void) { D3D11_BUFFER_DESC cbbd; ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC)); cbbd.Usage = D3D11_USAGE_DEFAULT; cbbd.ByteWidth = sizeof(cbPerObject); cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbbd.CPUAccessFlags = 0; cbbd.MiscFlags = 0; dev->CreateBuffer(&cbbd,NULL,&cbPerObjectBuffer); CameraPosition = XMVectorSet(0.0f,0.0f,-5.0f,0.0f); CameraTarget = XMVectorSet(0.0f,0.0f,0.0f,0.0f); CameraUp = XMVectorSet(0.0f,1.0f,0.0f,0.0f); View = XMMatrixLookAtLH(CameraPosition, CameraTarget,CameraUp); //Set the Projection Matrix Projection = XMMatrixPerspectiveFovLH(0.4f*PI, (float)SCREEN_WIDTH/SCREEN_HEIGHT,1.0f,1000.0f); } // this is the function that cleans up Direct3D and COM void CleanD3D(void) { swapchain->SetFullscreenState(FALSE, NULL); // switch to windowed mode // close and release all existing COM objects swapchain->Release(); backbuffer->Release(); dev->Release(); devcon->Release(); //Release shader pVS->Release(); pPS->Release(); //Release VertexBuffer pVertexBuffer->Release(); pIndexBuffer->Release(); pLayout->Release(); //Release Depthstencil pDepthStencilView->Release(); pDepthStencilBuffer->Release(); //Release contant buffer cbPerObjectBuffer->Release(); } void RenderFrame(void) { //clear the back buffer devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f,0.2f,0.5f,1.0f)); //Do other 3D rendering here // select which vertex buffer to display UINT stride = sizeof(VERTEX); UINT offset = 0; devcon->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset); devcon->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0); // select which primtive type we are using devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); WVP = CubeTwo * View * Projection; cbPerObj.WVP = XMMatrixTranspose(WVP); devcon->UpdateSubresource(cbPerObjectBuffer,0,NULL,&cbPerObj,0,0); devcon->VSSetConstantBuffers(0,1,&cbPerObjectBuffer); devcon->DrawIndexed(36,0,0); WVP = CubeOne * View * Projection; cbPerObj.WVP = XMMatrixTranspose(WVP); devcon->UpdateSubresource(cbPerObjectBuffer,0,NULL,&cbPerObj,0,0); devcon->VSSetConstantBuffers(0,1,&cbPerObjectBuffer); devcon->DrawIndexed(36,0,0); //Switch thee backbuffer and the front buffer swapchain->Present(0,0); } void Update() { //Only rotates 2PI rot+=0.001f; if(rot>2*PI) rot = 0.0f; //Reset the cube one world matrix CubeOne = XMMatrixIdentity(); XMVECTOR rotaxis = XMVectorSet(0.0f,1.0f,0.0f,0.0f); Rotate = XMMatrixRotationAxis(rotaxis,rot); Translate = XMMatrixTranslation(0.0f,0.0f,8.0f); Scale = XMMatrixScaling(0.2f,0.2f,0.2f); CubeOne = Translate * Rotate * Scale; //Reset Cube two world matrix CubeTwo = XMMatrixIdentity(); Rotate = XMMatrixRotationAxis(rotaxis,-rot); Scale = XMMatrixScaling(0.5f,0.5f,0.5f); CubeTwo = Rotate * Scale; }[/source]

[source lang="cpp"]cbuffer cbPerObject{ float4x4 WVP;};struct VOut { float4 position : SV_POSITION; float4 color : COLOR; }; VOut VShader(float4 position : POSITION, float4 color : COLOR) { VOut output; output.position = mul(position,WVP); output.color = color; return output; } float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET { return color; }[/source]