Jump to content

  • Log In with Google      Sign In   
  • Create Account


Nanook

Member Since 12 Apr 2006
Offline Last Active Jul 28 2014 07:37 AM
-----

Topics I've Started

lua vs v8

17 December 2013 - 01:54 PM

I'm been working on a engine for about 3 years, but had a break from it for some months now. Diving back into it now and I'm going to embed some scripting language for it. I thought I had decided on JavaScript with V8, but now I'm thinking maybe I want to use Lua instead. I'm having trouble making up my mind.

 

I'm intrested to hear from people using either of them and why you chose the one you did. Does someone know of some engines that uses either of them that I can look at some examples on how it used?

 

 


CG Technique doesnt validate on linux

12 December 2012 - 09:59 AM

I have a really simple cgfx file.. On windows it works fine with both OpenGL and DirectX, but on linux it doesn't validate.

cgGetErrorString says: "Invalid technique handle."

If I run the cgfx file through cgc specifying fp40 and vp40 which is the profiles of the basic_textured_ogl_40 technique I get 0 errors..

This is the code that loads the technique..

m_cgEffect = cgCreateEffect(cgContext, data, NULL);
m_cgTechnique = cgGetFirstTechnique(m_cgEffect);
while (m_cgEffect && cgValidateTechnique(m_cgTechnique) == CG_FALSE)
{
		std::cout << "Technique " << cgGetTechniqueName(m_cgTechnique) << " did not validate" << std::endl;
		m_cgTechnique = cgGetNextTechnique(m_cgTechnique);
}
if (!m_cgTechnique)
{
		std::clog << "Your GPU does not support any of the techniques available" << std::endl;
		exit(1);
}

The cgfx file:

void mainVS(float4 position : ATTR0,
   float3 normal  : ATTR2,
   float2 texCoord : ATTR8,
   out float4 oPosition : POSITION,
   out float2 oTexCoord : TEXCOORD0,
   uniform float4x4 viewProjection,
   uniform float4x4 world)
{
	   oPosition = mul(world, position);
	   oPosition = mul(viewProjection, oPosition);
	   oTexCoord = texCoord;
}
void mainFS(float2 texCoord : TEXCOORD0,
   out float4 color  : COLOR,
   uniform sampler2D texSampler0)
{
	   color = tex2D(texSampler0, texCoord);
}

float4x4 world : World;
float4x4 viewProjection : ViewProjection;

sampler2D texSampler0 = sampler_state {
	generateMipMap = true;
	MinFilter = LinearMipMapLinear;
	MagFilter = Linear;
	WrapS = Repeat;
	WrapT = Repeat;
};
technique basic_textured_dx_40
{
	pass
	{
		  FragmentProgram = compile ps_4_0 mainFS(texSampler0);
		  VertexProgram = compile vs_4_0 mainVS(viewProjection, world);
		  DepthTestEnable = true;
		  DepthMask = true;
	}
}
technique basic_textured_ogl_40
{
	pass
	{
		  FragmentProgram = compile fp40 mainFS(texSampler0);
		  VertexProgram = compile vp40 mainVS(viewProjection, world);
		  DepthTestEnable = true;
		  DepthMask = true;
	}
}

std::chrono::hige_resolution_clock for timer?

07 December 2012 - 04:37 PM

Can I use std::chrone::high_resolution_clock to get the time to calculate my fixed time step?

Or should I use the platform specific functions like QueryPerformanceCounter ?

Acceptable input lag

23 November 2012 - 01:16 PM

Whats acceptable input lag?

I'm implementing a threaded engine.. but thinking about how I would handle input when its networked.

At the moment its not networked and it goes like this(n is frame number):
n=0: Platform input is read at start of frame. Input system handles the input and sends the results off to the physics system
n=1: Physics system would calculate the new positions
n=2: Render system renders the new position.

Would this be acceptable?

I could make the render system dependent on the physics system and the render system dependent on the input system so the tasks of each system would all run on the same frame, but then if the other threads on my engine are really fast I would defeat the purpose of doing it multi threaded anyways. Whats more realistic would be to make the physics system dependent on the input system so I would reduce it to just one frame lag.

What I'm thinking for a networked game:
n=0: Platform input is read. Then its sent to the server. On the server its also checks if there's incoming input before it starts running any of the threaded tasks. Input system handles the input and sends the results off to the physics system
n=1: Physics system on the server would calculate the new positions.
n=2: Network system on server sends the new positions to clients. Network system on the clients receives the new positions
n=3: Render system renders the new position

There could also be network lag on frame 0 and 2 here so the input lag would be variable. Is this acceptable or do I need some kind of synchronization?

Now with this I could do some of the same dependency tricks to reduce it. I could get the physics update into n=0 and maybe even make the render system dependent on the network system so it is run before the rendering task can start. Reducing it to either;
n=0: input
n=2: render
or;
n0: input
n=1: render

+ the network lag of course..

I guess I want as little lag as possible, but since I will reduce concurrency with this whats acceptable?

Got a lot of answers just by writing this post, but still need some more opinions on this.. Hopefully its readable and clear enough :)

DX11 gives me a invalid window warning

27 October 2012 - 03:12 AM

I'm getting a warning when I'm creating my swap chain and nothing is drawn.. It was working, I don't think I've changed anything in the code below, but what else could it be?

DXGI WARNING: IDXGIFactory::CreateSwapChain: DXGI_SWAP_CHAIN_DESC.OutputWindow is not a valid window handle. [ MISCELLANEOUS WARNING #65: ]

CreateSwapChain code:
void TE::Context::APIContext::CreateSwapChain(Platform::PlatformWindow& platformWindow)
{
HRESULT hr = S_OK;
unsigned createDeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
  D3D_DRIVER_TYPE_HARDWARE,
  D3D_DRIVER_TYPE_WARP,
  D3D_DRIVER_TYPE_REFERENCE,
};
unsigned numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
  //D3D_FEATURE_LEVEL_11_1,
  D3D_FEATURE_LEVEL_11_0,
  D3D_FEATURE_LEVEL_10_1,
  D3D_FEATURE_LEVEL_10_0,
};
unsigned numFeatureLevels = ARRAYSIZE( featureLevels );
D3D_DRIVER_TYPE driverType;
for( U32 driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
  driverType = driverTypes[driverTypeIndex];
 
  ID3D11Device* device;
  ID3D11DeviceContext* deviceContext;
  hr = D3D11CreateDevice(NULL,
   driverType,
   nullptr,
   createDeviceFlags,
   featureLevels,
   numFeatureLevels,
   D3D11_SDK_VERSION,
   &device,
   &m_d3dFeatureLevel,
   &deviceContext);
  if( SUCCEEDED( hr ) )
  {
   m_d3dDevice = static_cast<ID3D11Device1*>(device);
   m_d3dDeviceContext = static_cast<ID3D11DeviceContext1*>(deviceContext);
   break;
  }
}
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Stereo = false;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.Flags = 0;
// Use automatic sizing.
swapChainDesc.Width = 0;
swapChainDesc.Height = 0;
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferCount = 2;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
IDXGIDevice2* dxgiDevice;
m_d3dDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&dxgiDevice);
dxgiDevice->SetMaximumFrameLatency(1);
IDXGIAdapter* dxgiAdapter;
dxgiDevice->GetAdapter(&dxgiAdapter);
IDXGIFactory2* dxgiFactory;
dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory));

hr = dxgiFactory->CreateSwapChainForHwnd(m_d3dDevice,
  platformWindow.GetHWND(),
  &swapChainDesc,
  nullptr,
  nullptr,
  &m_d3dSwapChain);
if( FAILED( hr ) )
  //LOG FATAL ERROR
  exit(0);
}

Create window code:
void TE::Platform::PlatformWindow::Initialize()
{
if (!m_externalWindow)
{
  m_hInstance = (HINSTANCE)GetWindowLong(NULL,GWL_HINSTANCE);
  WNDCLASSEX wcex  = {};
  wcex.cbSize = sizeof( WNDCLASSEX );
  wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  wcex.lpfnWndProc = WndProc;
  wcex.cbClsExtra = 0;
  wcex.cbWndExtra = 0;
  wcex.hInstance = m_hInstance;
  wcex.hIcon = NULL;
  wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
  wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
  wcex.lpszMenuName = NULL;
  wcex.lpszClassName = "TEngine";
  wcex.hIconSm = NULL;
  if(!RegisterClassEx (&wcex))
   //LOG FATAL ERROR
   exit(0);
  I32 posx = 0;
  I32 posy = 0;
  I32 width = m_width;
  I32 height = m_height;
  RECT rc =
  {
   posx, posy,
   posx + width,
   posy + height
  };
  AdjustWindowRect(&rc, m_dwWindowStyle, false);
  m_hWnd = CreateWindow(
   m_windowName.c_str(),
   m_windowName.c_str(),
   m_dwWindowStyle | WS_CAPTION | WS_SYSMENU, //| WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
   //WS_OVERLAPPEDWINDOW,
   CW_USEDEFAULT, CW_USEDEFAULT,
   rc.right - rc.left, rc.bottom - rc.top,
   NULL, NULL, m_hInstance, NULL );
  if (!m_hWnd)
   //LOG FATAL ERROR
   exit(0);
  s_hwndPlatformWindowMap.insert(std::make_pair(m_hWnd, this));
  ShowWindow(m_hWnd, SW_SHOWNORMAL);
  SetFocus(m_hWnd);
}
m_hdc = GetDC(m_hWnd);
}

PARTNERS