Sunday, April 8, 2007

Structure

Like I said in my last post, I am going to talk about the structure, more specifically about the structure of the engine. I have been a busy working hard on this thing trying to come up with a good structure that's practical and hides away all of our complex code (mainly the OpenGL stuff). I've rolled with Pete's idea because it will work (Pete's idea was to make the engine the core and the game extend it), but what hes done so far tells me doesn't completely understand whats going on with OpenGL, but I can tell hes making sense of different bits and pieces. Earlier when I first implemented the GLDisplay and texturing utilities I made the actual game logic (object) implement the GLEventListener (this is the interface that OpenGL uses for its standard methods like display, reshape, init, etc) which would of given a developer a lot of access to the actual workings of the engine. So today I've been continuing where Pete left off and been busy separating methods and making methods that will be available to the developer and methods that need to be in the engine (tucked away). Below is a dot point list of what I have so far in the engine and game, I'll try to explain the purpose of each section to the best of my ability.

Engine.java - THE GAME ENGINE (Implements GLEventListener)
  • Engine - Constructor. In the constructor the engine sets itself up and activates the sound player, object render and input handler.
  • onStartUp() - ABSTRACT - This function is required for each game developed. It is called when the window is first initialised.
  • onEnd() - ABSTRACT - This function is required for each game developed. It is called when the window is closing.
  • onMouseLeftClick() - ABSTRACT - This function is required for each game developed. This function is called when the left mouse button is clicked. It is up to the developer to decide what occurs when this event happens.
  • onMouseRightClick() - ABSTRACT - This function is required for each game developed. Same as above.
  • onMouseOtherClick() - ABSTRACT - This function is required for each game developed. Same as above.
  • onKeyPress(KeyEvent e) - ABSTRACT - This function is required for each game developed. This function is called whilst a key is being pressed/held down. It is up to the developer to decide what occurs when this event happens.
  • onKeyRelease(KeyEvent e) - ABSTRACT - This function is required for each game developed. This function is the same as above, but it only occurs when the key is released.
  • KeyPress(KeyEvent e) - This is the engines own KeyPress event. When a key is pressed it is handled by the InputHandler which then tells the engine to activate this function. This gives us the developers the oppurtunity to setup some static key binds for things like Pausing or Help (F1) and Escape for quitting, just so that the game developer cannot override these keys with useless code. This function makes a call to the onKeyPress() function.
  • KeyRelease(KeyEvent e) - Same as above. This function makes a call to the onKeyRelease() function.
  • closing() - STATIC - This function is subject to renaming, but it is called when the window has been closed. It gives the engine a chance to stop any threads, sounds, music or input that might be occurring whilst the window is closing.
  • getHeight() - This method is used to retrieve the exact height of the OpenGL canvas. It's used in relation to the mouse axis Y, which needs to be reversed when dealing with coordinates in OpenGL.
  • togglePause() - This function just toggles a boolean between true or false. The paused boolean is setup in other functions to stop the flow of data and bring the game to a halt.
  • convertKey(int Key) - This function was made to work in relation with the InputHandler when registering a new help key. The developer has the option to register a new key in the help overlay so when a player presses F1 they are given a list of working keys. Example of this function in use would be: input.registerKeyStroke(convertKey(KeyEvent.VK_W), "Forward").
  • init - OPENGL - This function is apart of the GLEventListener. It is called when the OpenGL window is in the initialisation stage, it is useful for setting up things like clear colour, perspective and initialising any variables. This function makes a call to the onStartUp() function.
  • display() - OPENGL - This function is apart of the GLEventListener. It is called for each frame that OpenGL renders. When this function is called it sends the data down the pipeline for processing and output to the screen.
  • reshape() - OPENGL - This function is apart of the GLEventListener. It is called when ever the window is reshaped by the user. It is also called after init when the window is displayed on the screen. Its a good place to put concrete setup perspective code.
  • displayChanged() - OPENGL - This function is apart of the GLEventListener. It is called when the display is changed. This function doesn't usually get used and has no purpose in the project.

Well, what do you think? Pretty good aye?

I have done some more coding in some of the little classes Pete threw in but didn't really make use of yet. Because I cut out a lot of code from the actual game class (MissileCommand.java) I'm trying to make use of these classes in the game, just like how a developer making his own game with our engine would do. I've had great success and no real problems so far.

When I was fixing up the Missile class I copied across what we have so far in the laser class and applied to missile. Now at the moment that means the the missile has a line that follows its path, much like a trail, but I thought I would leave it in for now because later on we might replace it with a smoke trail. I added a little primitive block with a point to the render function and applied some basic OpenGL techniques to get the missile to point in the direction of its destination. It was pretty simple really, I made use of one of the methods Pete put together to return the angle in degrees and rotated it accordingly.Below is a picture of the game so far. It has three turrets (white), 4 cities (blue) and missiles that point in the direction of the mouse.




..

No comments: