Jump to content
  • Advertisement
Sign in to follow this  
POLSKASH

Design Worries

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make my first game, pong. So far, I'm just trying to get the windows code operational, and set up the directX stuff. After changing a few things from 8 to 9, I get this error: c:\documents and settings\owner\desktop\pong\pong\ponggame.cpp(20) : error C2039: 'FullScreen_PresentationInterval' : is not a member of '_D3DPRESENT_PARAMETERS_' Is this just something different between 8 and 9 that's causing the problem? I didn't change anything else. Workspace: www.geocities.com/pszlachetka/Programming/Pong.zip Now for the design part. I've uploaded my workspace that I have in VC++ 6. I basically have a Windows class that handles most of the windows stuff separately. I have an important question about this message handler. What is the point of the message handler declared in my windows.h and the switch statement in my TitleScreen.cpp class? One is WM_DESTROY and the other is WM_QUIT, I'm just not understanding it. Then I have a PongGame class which contains all the levels in the game, and has the direct3D object and device, which are sent out when the currently level is destroyed and a new one is created. This is basically the meat of my state processing, and I'm hoping it's good enough for what I need:
bool PongGame::Run()
{
	if(!currentState->Run())
	{
		switch(purpose)
		{
		case -1:
			delete currentState;
			return false;
			break;

		case 0:
			delete currentState;
			currentState = new TitleScreen(hWnd, D3D, D3D_device, &purpose);
			return true;
			break;
		//case 1:
		//	delete currentState;
		//	currentState = new OnePlayer(hWnd, D3D, D3D_device, &purpose);
		//	return true;
		//	break;
		};
	}
	return true;
}
Basically, an integer pointer is sent to every new state that is created, and sometime in that state, the integer is changed to another number, controlling the flow of the game. For instance, the point is sent into the one player state, when that state is finished, the value pointed to by the pointer is changed to 0, which tells this switch function to change the current state to a title screen. However, these are my current errors, and I have no idea what it's talking about. I clearly have the <windows.h> header being included into the file, yet it doesn't know what Msg is. Here are the errors: c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2065: 'Msg' : undeclared identifier c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2228: left of '.message' must have class/struct/union type c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2065: 'isPlaying' : undeclared identifier c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : fatal error C1903: unable to recover from previous error(s); stopping compilation Error executing cl.exe. Once I get my current errors figured out, I'm trying to decide how to add the game objects to each level. I'm thinking about making separate class for the paddle and ball of course, and adding pointers of those types in each of the state class. So the class OnePlayerMode would also have pointers to Paddles and Ball. Is this a good way of doing this? There's not much code, so if anyone could glance over it and give me some good advice on anything, it would help me tremendously. I have to get these basics right before I can move on to something bigger. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Finally some one who posts some decently indented source code in the beginners forum. Hooray!

As for the presentation parameters, look at the documentation. In the 'Changes in DX9' section:

Renamed D3DPRESENT_PARAMETERS.FullScreen_PresentationInterval to PresentationIntervals.


For the windows messages look them up on MSDN. WM_DESTROY and WM_QUIT are different (the first one says you ought to destroy the window and the second says you ought to kill the application).

Greetz,

Illco

Share this post


Link to post
Share on other sites
Does anyone know what's the deal with these four errors though?

documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2065: 'Msg' : undeclared identifier
c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2228: left of '.message' must have class/struct/union type
c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : error C2065: 'isPlaying' : undeclared identifier
c:\documents and settings\owner\desktop\pong\pong\titlescreen.cpp(13) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

Here's the relevant source code:

TitleScreen.cpp

#include "TitleScreen.h"

TitleScreen::TitleScreen(HWND hWnd, IDirect3D9* d3d, IDirect3DDevice9* device, int* purp)
{
isPlaying = true;
purpose = purp;
D3D = d3d;
D3D_device = device;
}

bool GameState::Run()
{
while(Msg.message != WM_QUIT && isPlaying)
{
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
}
}
return false;
}



TitleScreen.h

#include "GameState.h"

class TitleScreen : public GameState
{
public:
TitleScreen(HWND hWnd, IDirect3D9* d3d, IDirect3DDevice9* device, int* purp);
//bool Run();

private:
IDirect3D9* D3D;
IDirect3DDevice9* D3D_device;
MSG Msg;
bool isPlaying;
IDirect3DTexture9* bg;
int* purpose;
};



GameState.h

#include <windows.h>
#include <D3DX9.h>

class GameState
{
public:
virtual bool Run();

private:

};



How can it not know what MSG Msg; is?

Share this post


Link to post
Share on other sites
Because MSG Msg; is a member specific to TitleScreens, but it's used to implement the general GameState::Run(). Ditto isPlaying.

As for the state machine design, you might find it more flexible to let the current state make the decision about what state is next (and tell it the 'purpose' so that it can make the decision). Something like:

bool PongGame::Run() {
if (!currentState) return false;
GameState* nextState = currentState->Run(purpose);
if (nextState != currentState) {
// there was a change to a newly created state, so delete the old one
delete currentState;
currentState = nextState;
} // if no change, don't delete! otherwise the object is toast
return true;
}

// and then for each GameState derived class we implement
// virtual GameState* Whatever::Run(int purpose);

This is just as tricky WRT the memory management, though. If you can arrange such that you only need one instance of each type of GameState, then things become a lot simpler - you just create all those instances, and return the pointer to the one you want to use next.

Share this post


Link to post
Share on other sites
You use "Msg", and "isPlaying" in your GameState::Run function, but these variables are not members of the GameState class. Instead, you have both of these declared as members of your TitleScreen class, so to fix this you either need to make both variables members of the base class, or you need to put this code into TitleScreen::Run instead.

TitleScreen inherits from GameState, but that doesn't mean that GameState has access to TitleScreen's private data.

I hope that makes some sense. Good luck!

Edit: bah! Beaten and then some :P

Share this post


Link to post
Share on other sites
Titlescreen inherits from Gamestate, not the other way around. Inheritance is one way, you get genes from your parents, they don't get genes from you.

class TitleScreen : public GameState
... means Titlescreen can access public and protected members of Gamestate.
The run() in Gamestate can't see the Msg in Titlescreen

You need to either move run() to Titlescreen or your variables to Gamestate(or both!). It is hard to say which would be best without knowing more about your program.

Share this post


Link to post
Share on other sites
That's an interesting suggestion, but I'm gonna try mine first zahlman. As you can see, I'm redefining the Run() method in the GameState class, but I need for that Run() method to have access to stuff that will be in the TitleScreen class. I'm trying to figure out how to get the Run() method in the GameState class to call the Run() method in the TitleScreen class, or whatever state is inherited from GameState, so that I can have access to that state's variables. I can't figure out a way to do it. Maybe a function pointer? I don't the this pointer will work for me here.

Share this post


Link to post
Share on other sites
N/m...a little research goes a long way. Looks like I have to brush up on the more advanced C++ concepts ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!