Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!

Ferg posted:

Alright I've got yet another licensing question. I decided to utilize the GameStateManagement example that's provided on the XNA website as a framework for my game's state management. I've basically plugged my game into the GameplayScreen object, and tweaked the hell out of every other screen (removed some, tweaked others). But lets say down the line I want to distribute my game. What obligations do I have as far as licensing for these huge chunks of code that I used from Microsoft? Can I just keep the MS branding at the top and add my licensing as well? Can I license it with my own license at all?

I'd say with all the code added from the example it's a good 15%-20% of the game right now is code that I didn't entirely write, and I'd like to submit this to community games come winter.

Wasn't that put out under the Microsoft Permissive License? If so:

quote:

(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.

But you should NOT leave any microsoft branding int there, as those are registered Microsoft trademarks, and you haven't been given permission to use them.

Adbot
ADBOT LOVES YOU

Ferg
May 6, 2007

Lipstick Apathy

Pfhreak posted:

Wasn't that put out under the Microsoft Permissive License? If so:


But you should NOT leave any microsoft branding int there, as those are registered Microsoft trademarks, and you haven't been given permission to use them.

So I remove the MS branding, and I don't have to worry about distribution. Now can I apply my own license to the code then?

Jake Armitage
Dec 11, 2004

+69 Pimp

Ferg posted:

So I remove the MS branding, and I don't have to worry about distribution. Now can I apply my own license to the code then?

What do you mean by "apply my own license?" Do you mean open source it under a different license? Because you can't do that.

Ms-PL posted:

(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.

You can distribute it, compiled, and charge for it, though. I wouldn't be surprised if 50% of the games submitted to the XNA community games will be extensions of the GSM sample.

Ferg
May 6, 2007

Lipstick Apathy

stromdotcom posted:

What do you mean by "apply my own license?" Do you mean open source it under a different license? Because you can't do that.

That's what I figured.

heeen
May 14, 2005

CAT NEVER STOPS
What's wrong with this shader?
Some vertices seem to move with the camera view.

code:
#version 120 
#extension GL_EXT_geometry_shader4 : enable
#extension GL_EXT_gpu_shader4 : enable
 
varying in vec3 norm[3];
 
void main() 
{ 
 
		gl_Position=gl_PositionIn[0];
		gl_Position.xyz+=norm[0];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		gl_Position=gl_PositionIn[1];
		gl_Position.xyz+=norm[1];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		gl_Position=gl_PositionIn[2];
		gl_Position.xyz+=norm[2];
		gl_Position=gl_ModelViewMatrix*gl_Position;
		gl_Position=gl_ProjectionMatrix*gl_Position;
		EmitVertex(); 
		EndPrimitive();
 
 
}

haveblue
Aug 15, 2005



Toilet Rascal
I'm not really familiar with GLSL, but I have a hunch it's reacting badly to in-place editing of inputs. What happens if you copy gl_Position to a temp before messing with it?

heeen
May 14, 2005

CAT NEVER STOPS

HB posted:

I'm not really familiar with GLSL, but I have a hunch it's reacting badly to in-place editing of inputs. What happens if you copy gl_Position to a temp before messing with it?

Came here to post that this worked.

HauntedRobot
Jun 22, 2002

an excellent mod
a simple map to my heart
now give me tilt shift
It's been a while since I replied to this thread, but I wanted to say thanks to the people who replied to my questions so far.

Work on my game engine continues. I spent a good deal of time learning about shaders, only to find my development laptop can't cope with them so I'm shelving any use of them until more of the game's done. A hell of a compromise, but there's no real need for me to use them for this game, and coding in Starbucks/on the beach is too much of a draw.

I've also inadvertently emulated a decent portion of javascript in getting my UI code up and running. Overkill, again, but something I can use a lot later down the line and being able to play around with UI elements in a simple XML file without having to do a load of recoding is well worth it.

Sapozhnik
Jan 2, 2005

Nap Ghost
This has been doing my head in for most of a day so far. Can anyone please tell me why this minimal Direct3D app is chewing nearly 100% of my CPU? IDirect3DDevice9::Present() is the culprit, but it shouldn't be spinning like that. I've fiddled with practically every line of code and I'm at my wits' end here...

Thanks

code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <d3d9.h>

static void Panic(HWND parent, LPTSTR msg)
{
	MessageBox(parent, msg, _T("Fatal Error"), MB_ICONERROR | MB_OK);
	ExitProcess(-1);
}

static LRESULT WINAPI WndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch (msg)
	{
	case WM_KEYDOWN:
		if (wparam == VK_ESCAPE) PostQuitMessage(0);
		return TRUE;

	default:
		return DefWindowProc(wnd, msg, wparam, lparam);
	}
}

int WINAPI _tWinMain(HINSTANCE inst, HINSTANCE prevInst, LPTSTR cmdline, int show)
{
	IDirect3D9 *api;
	IDirect3DDevice9 *dev;
	D3DPRESENT_PARAMETERS pp;
	WNDCLASSEX wcx;
	HRESULT hr;
	HWND wnd;
	MSG msg;

	ZeroMemory(&wcx, sizeof(wcx));
	wcx.cbSize = sizeof(wcx);
	wcx.cbClsExtra = 0;
	wcx.cbWndExtra = 0;
	wcx.hbrBackground = NULL;
	wcx.hCursor = NULL;
	wcx.hIcon = NULL;
	wcx.hInstance = inst;
	wcx.lpfnWndProc = WndProc;
	wcx.lpszClassName = _T("WndClass");
	wcx.style = CS_OWNDC;

	RegisterClassEx(&wcx);
	wnd = CreateWindowEx(0, _T("WndClass"), _T("testd3d"), WS_POPUP | WS_VISIBLE, 
		0, 0, 640, 480, NULL, NULL, inst, NULL);
	ShowCursor(FALSE);

	ZeroMemory(&pp, sizeof(pp));
	pp.BackBufferCount = 0;
	pp.BackBufferFormat = D3DFMT_X8R8G8B8;
	pp.BackBufferWidth = 640;
	pp.BackBufferHeight = 480;
	pp.FullScreen_RefreshRateInHz = 0;
	pp.hDeviceWindow = wnd;
	pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	pp.SwapEffect = D3DSWAPEFFECT_DISCARD;

	api = Direct3DCreate9(DIRECT3D_VERSION);
	hr = api->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &dev);
	
	if (FAILED(hr)) Panic(wnd, _T("CreateDevice failed"));

	ZeroMemory(&msg, sizeof(msg));

	while (msg.message != WM_QUIT) {
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		hr = dev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0);
		if (FAILED(hr)) Panic(wnd, _T("Clear failed"));

		hr = dev->BeginScene();
		if (FAILED(hr)) Panic(wnd, _T("BeginScene failed"));

		hr = dev->EndScene();
		if (FAILED(hr)) Panic(wnd, _T("EndScene failed"));

		hr = dev->Present(NULL, NULL, NULL, NULL);
		if (FAILED(hr)) Panic(wnd, _T("Present failed"));
	}

	return 0;
}

krysmopompas
Jan 17, 2004
hi

Mr Dog posted:

This has been doing my head in for most of a day so far. Can anyone please tell me why this minimal Direct3D app is chewing nearly 100% of my CPU? IDirect3DDevice9::Present() is the culprit, but it shouldn't be spinning like that. I've fiddled with practically every line of code and I'm at my wits' end here...
Just off the top of my head, D3DPRESENT_INTERVAL_ONE uses a higher precision timer than blah_DEFAULT which will lead to higher cpu usage, or possibly your driver settings are overriding the setting and forcing it to blah_IMMEDIATE.

Sapozhnik
Jan 2, 2005

Nap Ghost

krysmopompas posted:

Just off the top of my head, D3DPRESENT_INTERVAL_ONE uses a higher precision timer than blah_DEFAULT which will lead to higher cpu usage, or possibly your driver settings are overriding the setting and forcing it to blah_IMMEDIATE.

Sadly, I've already tried using _DEFAULT instead, and that didn't seem to help. Also, I've asked a few other people to run an EXE that I built out of this code, and they all observed the same thing :\

krysmopompas
Jan 17, 2004
hi

Mr Dog posted:

Sadly, I've already tried using _DEFAULT instead, and that didn't seem to help. Also, I've asked a few other people to run an EXE that I built out of this code, and they all observed the same thing :\
At the same time, it's not like you're yielding the thread at all, do you really expect it to use less than 100%?

There's nothing in d3d that says the vsync wait has to actually sleep or anything.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

krysmopompas posted:

At the same time, it's not like you're yielding the thread at all, do you really expect it to use less than 100%?

There's nothing in d3d that says the vsync wait has to actually sleep or anything.

yeah, from what it looks like, you're running the while loop as fast as possible

tyrelhill
Jul 30, 2006

Nuke Mexico posted:

yeah, from what it looks like, you're running the while loop as fast as possible

A Sleep(1) would help it go down, but thats something you don't want in any game loop.

krysmopompas
Jan 17, 2004
hi

tyrelhill posted:

A Sleep(1) would help it go down, but thats something you don't want in any game loop.
Sure you would.

In general with vsync on, you want to run the game at even multiples of the refresh rate, say 60/30/15 if we were targeting NTSC, and not ping pong all over the place since it leads to a pretty jerky, inconsistent experience for the player. You may also need to run fixed multiples for your physics to behave nicely as well, especially in a networked situation.

Besides, idling the cpu as much as possible is a way to play nice with laptop users.

ehnus
Apr 16, 2003

Now you're thinking with portals!

krysmopompas posted:

Sure you would.

Using Sleep() to enforce specific game refresh rates operates on two incorrect assumptions. First, it assumes that the computer runs faster than the game loop -- if you have assumptions in place that your game updates at 60Hz but the computer can only execute the game loop at 40Hz then you have a problem. Second, it assumes that it will sleep for that exact amount of time which is incorrect because you're at the mercy of the OS's thread scheduler.

Try wrapping various calls to Sleep() with a high resolution timer, you may be surprised with what you see.

krysmopompas
Jan 17, 2004
hi

ehnus posted:

Using Sleep() to enforce specific game refresh rates operates on two incorrect assumptions. First, it assumes that the computer runs faster than the game loop -- if you have assumptions in place that your game updates at 60Hz but the computer can only execute the game loop at 40Hz then you have a problem. Second, it assumes that it will sleep for that exact amount of time which is incorrect because you're at the mercy of the OS's thread scheduler.

Try wrapping various calls to Sleep() with a high resolution timer, you may be surprised with what you see.
That's not at all what I was saying. What I was saying was to clamp framerates at some multiple of the vsync, not hardcode some call to sleep. If you're running at 40hz, then you'd lock yourself down to 30hz, but then you wouldn't go back up to 60hz until you've crossed some threshold count of frames that exceeded 60hz.

Replace Sleep with whatever doesn't suck on your platform, or only calling sleep for 'safe' thresholds and spinning the rest off with high res timers, the idea is the same.

krysmopompas fucked around with this message at 06:51 on Apr 14, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one

Mr Dog posted:

This has been doing my head in for most of a day so far. Can anyone please tell me why this minimal Direct3D app is chewing nearly 100% of my CPU?
Is it actually chewing 100% of your CPU, or is it just being reported as using 100% of CPU by Task Manager.

Try doing a few other things whilst the app is running. If other apps run okay whilst yours is going, then the problem is just with the way Task Manager reports usage and not the app itself.

Our old PC engine used to do exactly that - it would 'expand' to claim all unused CPU in the Task Manager display, but it would back off whenever other stuff was going on, down to the actual usage level.

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha

TSDK posted:

Our old PC engine used to do exactly that - it would 'expand' to claim all unused CPU in the Task Manager display, but it would back off whenever other stuff was going on, down to the actual usage level.

My little tetris game had this problem, couldn't get it to back off the 100% cpu usage. Sucks because 100% cpu usage BURNS through battery on a laptop.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...
The "right" way to solve this (in my opinion) is to have two threads, one your "game update" thread and the other your "graphics update" thread, which run, at most, at your desired framerate (say 10 hz and 60 hz respectively), and yield time by using a "Sleep(0)" call wrapped with a high resolution timer at the end. Of course, this is somewhat complicated, especially when you have to deal with data protection. A good alternative is to structure your code something like this:

code:
while (!quit)
{
    frameTime = GetTime();
    if (frameTime > lastLogicUpdate + logicUpdateTime)
    {
        UpdateGameLogic(frameTime - lastLogicUpdate);
        lastLogicUpdate = frameTime;
    }

    if (frameTime > lastGraphicsUpdate + graphicsUpdateTime)
    {
        UpdateGamePhysics(frameTime - lastGraphicsUpdate);
        RenderFrame();
    }

    Sleep(0);
}
Each loop through, you (a) update the 'desire'/interactions of your game objects if a certain time limit has passed, (b) update the physical location/graphical properties of your game objects and render them if a certain time limit has passed, and (c) yield the thread to avoid a busy loop.

heeen
May 14, 2005

CAT NEVER STOPS

TSDK posted:

Is it actually chewing 100% of your CPU, or is it just being reported as using 100% of CPU by Task Manager.

Try doing a few other things whilst the app is running. If other apps run okay whilst yours is going, then the problem is just with the way Task Manager reports usage and not the app itself.

Our old PC engine used to do exactly that - it would 'expand' to claim all unused CPU in the Task Manager display, but it would back off whenever other stuff was going on, down to the actual usage level.

Your engine actually used 100% cpu, its just the premptive scheduler dividing the cpu up on all tasks when you start another one.
A task that uses 100% cpu AND is lagging the rest of the system has usually trouble with side effects like swapping to the hard drive or some driver issue.

edit: I just remembered: Mr. Dog are you running debug or release builds? debug can easily chew 90% more cpu than release. My little opengl project runs at around 100fps in debug and 1200fps in release which leads to 60% cpu ves 5% cpu when clamped to 60fps.

heeen fucked around with this message at 13:20 on Apr 14, 2008

TSDK
Nov 24, 2003

I got a wooden uploading this one

heeen posted:

Your engine actually used 100% cpu, its just the premptive scheduler dividing the cpu up on all tasks when you start another one.
No, it wasn't. Each update loop was more or less a constant cost, and when setting other tasks running (which at one point was also anther instance of the game when we were testing certain features) then neither the other tasks, nor the game suffered any slowdown from normal operation.

If it were actually using 100% of the CPU, then you'd expect it to slow down when other tasks kick in.


EDIT: On second thoughts, I suppose it could have been the sound thread doing some sort of retarded busy-wait. Our sound guy wasn't exactly the best programmer in the world, and he did do ridiculous things like setting his thread priority so high that it stopped the keyboard drivers from working properly on the low-end spec...

TSDK fucked around with this message at 14:14 on Apr 14, 2008

tyrelhill
Jul 30, 2006

TSDK posted:

he did do ridiculous things like setting his thread priority so high

Oh my god... He needs to get smacked.

cronio
Feb 15, 2002
Drifter
Sleep(0) only yields time to other threads in the same process, so it will still use 100% of a CPU if you're looping like that.

ceebee
Feb 12, 2004
What's the easiest language and engine an artist can learn/use?

I'm looking for the most minimal thing I can use to make a game either 2D or 3D (Preferably 3D) based around grappling hooks.

I was thinking actionscript but that's just because I remember a tiny bit about it when I used to make flash animations.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

cronio posted:

Sleep(0) only yields time to other threads in the same process, so it will still use 100% of a CPU if you're looping like that.

Ahh, you know I never read the spec that way but you're absolutely right. It says it will yield to other threads, but that doesn't necessarily mean other processes. Huh.

cronio
Feb 15, 2002
Drifter

Nuke Mexico posted:

Ahh, you know I never read the spec that way but you're absolutely right. It says it will yield to other threads, but that doesn't necessarily mean other processes. Huh.

Strange -- I looked it up a few months ago to make sure, and I could've sworn it explicitly mentioned Sleep(0) as only yielding time to other threads in your own process.

I do know that it will cause 100% CPU, but it looks like it's probably because of this:

MSDN posted:

If you specify 0 milliseconds, the thread will relinquish the remainder of its time slice but remain ready.

So it will still expand to use whatever resources are available, it just won't be as greedy as without the Sleep(0).

PnP Bios
Oct 24, 2005
optional; no images are allowed, only text
Mr. Dog, it's because your program is using PeekMessage instead of WaitMessage. Instead of waiting for input, you are polling for it, which means your program is going to cycle through regardless of what's in the message, so your process running at 100% is perfectly normal.

If CPU usage is that important to you, you may consider using waitMessage, and periodically forcing the window invalidation and using that as an indication as when to redraw the window.

POKEMAN SAM
Jul 8, 2004

cronio posted:

Strange -- I looked it up a few months ago to make sure, and I could've sworn it explicitly mentioned Sleep(0) as only yielding time to other threads in your own process.

Eh, looking at MSDN's paper on scheduling priorities, all scheduling is based strictly on threads, not on processes at all, except that a thread is by default prioritized based on its process's priority.

http://msdn2.microsoft.com/en-us/library/ms685100(VS.85).aspx

You'd think that if they allocated time to processes and then subdivided that into threads they would've specifically mentioned something like that.

TSDK
Nov 24, 2003

I got a wooden uploading this one

PnP Bios posted:

Mr. Dog, it's because your program is using PeekMessage instead of WaitMessage. Instead of waiting for input, you are polling for it, which means your program is going to cycle through regardless of what's in the message, so your process running at 100% is perfectly normal.
No it's not. Using present parameters of either ONE or DEFAULT should be causing the loop to sync with the refresh rate of the monitor. If it's not, then either the window is minimised, or (another random thought) the drivers have been told to ignore vsync.

Unless you're writing a turn based non-realtime game, using WaitMessage in a game loop is mostly retarded.

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

cronio posted:

So it will still expand to use whatever resources are available, it just won't be as greedy as without the Sleep(0).

Right, and more-over if there are no other threads waiting, the thread will immediately resume and the Sleep will essentially be a no-op

So, basically,

code:
while(true)
{
    Sleep(0);
}
Will still peg your CPU at 100%, but won't bog down other applications if they're running as well.

PnP Bios
Oct 24, 2005
optional; no images are allowed, only text

TSDK posted:

No it's not. Using present parameters of either ONE or DEFAULT should be causing the loop to sync with the refresh rate of the monitor. If it's not, then either the window is minimised, or (another random thought) the drivers have been told to ignore vsync.

Unless you're writing a turn based non-realtime game, using WaitMessage in a game loop is mostly retarded.

He was worried about it running at 100%. Anything polling the event loop is going to be running at 100%. I agree about using WaitMessage being mostly retarded, but that's a way to make it not run at 100%.

vanjalolz
Oct 31, 2006

Ha Ha Ha HaHa Ha

PnP Bios posted:

He was worried about it running at 100%. Anything polling the event loop is going to be running at 100%. I agree about using WaitMessage being mostly retarded, but that's a way to make it not run at 100%.

..but he's waiting for vsync? Sure he won't be blocked in WaixMessage, but he *will* be blocked in wait for vsync, right?

I agree with the 'driver ignoring vsync' idea. Check your control panel settings.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.

HB posted:

Pretty much. You already have the current camera orientation as a quat. You take the natural Y axis and rotate it with this quat, so that from the camera's perspective it's where the Y axis should be. Then you rotate the camera around this new axis by the amount the user inputted.

This is still absolutely destroying my head.

http://code.bulix.org/9mib1o-66195

Using the code above, the camera twists slightly after yaw right+pitch up+yaw left+pitch down or any combination as such. The camera will end up twisted like 5-10 degrees from its initial orientation.

Is this just a function of quaternions, or is something in my code horribly wrong?

For clarification, playership.m_x/y/z are floats representing user input last frame, a toggle. playership.m_camera is the rotation quaternion stored each frame. I use a quaternion to store axis/angle information in the bottom 3 functions simply because it's an appropriate datatype (vector+scalar).

Kibbles n Shits
Apr 8, 2006

burgerpug.png


Fun Shoe
edit: Never mind, I see the light now.

Kibbles n Shits fucked around with this message at 01:24 on Apr 19, 2008

duck monster
Dec 15, 2004

Re NeHe, I taught myself GL based on his stuff, and it was fine. Although in fairness I already had a pretty spot on knowledge of trig and matrix.

Some of it is garbage however, and I'm fairly convinced his explanation of portalling was plain wrong, although the code was roughly right.

Moetic Justice
Feb 14, 2004

by Fistgrrl
nm; this belongs in the C thread

Moetic Justice fucked around with this message at 01:29 on Apr 22, 2008

Heisenberg1276
Apr 13, 2007
Does anyone have any links to article or just any advice on generating maps for a 2d tile based game?

It is a top down RPG and the terrain will be a natural island so will need to have rocks beaches forrest grass rivers etc. I'm struggling with the theory of how to decide what goes next to what. There must be an article on it somewhere? I've googled with no luck

Hubis
May 18, 2003

Boy, I wish we had one of those doomsday machines...

DBFT posted:

Does anyone have any links to article or just any advice on generating maps for a 2d tile based game?

It is a top down RPG and the terrain will be a natural island so will need to have rocks beaches forrest grass rivers etc. I'm struggling with the theory of how to decide what goes next to what. There must be an article on it somewhere? I've googled with no luck

What exactly do you mean by "Generating maps"?

Adbot
ADBOT LOVES YOU

Heisenberg1276
Apr 13, 2007
Apologies if I was vague

I mean procedurally generating the terrain (the grass, water, rock, etc)

If water is 0, grass is 1, rock is 2, tree is 3 and I have an array of integers 50x50 I need to go through that and assign it a value which makes the map look "natural". The joins between different terrain types etc is to be handled seperately so right now I only need to generate what type the terrain is.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply