Saturday, December 5, 2015

Game Project

     For several months now I have been working on a project much different and much more interesting than any of my previous ones (in my opinion). It has been very challenging (probably because of the way I decided to do it) and presented many obstacles which I needed to over come. This project is essentially a game or more specifically a game engine (a very simple 2D game engine). I started this project about 2 to 3 years ago with the thought of making a Pokemon game just for friends and family to play. That project eventually saw a dark fate when I managed to mess up my computer and lost all my work regarding it. Jump forward a little bit and I have revived that project though it has been altered a bit. I changed it from GDI+ to DX. Got CPU usage from around 15 to 20 percent (8 threaded CPU) down to less than 1 (depending on configuration used). While I still do plan on making a Pokemon game for friends and family I have been working on a type of fighting game as that has presented me the most challenge. The Pokemon game will most likely be my second project relating to games and will most definitely recycle the work done on the fighting game. There are several other features and updates that I have presented since my initial version which was lost but I don't feel they are interesting nor important enough to mention.

     Typically because I do not know if this project will ever amount to anything (or ever completed) I refrained from posting this on here and instead posted updates on my Facebook but I have recently been kicked out and unable to use my Facebook account (because I refused to use my real name nor do I plan on giving it to them). To continue posting updates I will have to resort to posting on here.

     Updates will be posted in oldest last and latest first order. All updates will have a date attributed to them.

[System Tested]
CPU: Intel Core i7 2600K @3.411Ghz
RAM: 8GB DDR3 @ 1600Mhz
GPU: Nvidia GTX 680

[APR 22 2016]
Moving everything over to MonoGame. Will hopefully provide Windows and Linux versions.

[JAN 21 2016]
I have since made some addition/changes but haven't gotten around to posting until now. I have added a "ColorPalette Management System" and a "PixelData Management System" they are in place to eventually replace the current "Sprite Management System" but currently all three are present for testing and debugging. I have worked out how I want to go about storing game assets (graphics in particular and sounds). Sounds will be in AAC format as there are no royalties involved in the usage of AAC media (unlike MP3). Several other formats are supported but AAC is recommended for reasons stated. Graphics Assets will be stored in a custom format/scheme. The game will have "CPT" (Color Palette Table) files which represent the colors of a particular palette and then another format "PID" (Pixel Image Data) which contains the representation of each pixel in bytes. The images are restricted to an Indexed8 depth meaning each sprite can have up to 256 predefined colors (in the CPT file). The two formats are separate because some sprites may share the same palette in which case it makes sense to reuse a palette instead of making a redundant copy in memory. The idea came about when exploring the GIF animated image format. I added a SoftwareRenderOnly mode for whats it's worth. Finally I moved around some things to better organize the project and workflow.

[JAN 12 2016]
Fixed and optimized my XorUInteger and XorULong structures to use for the engine. They are attempts at cheat prevention (for the simpletons but I'm sure the pros will still get around it). It basically works as you would think the name implies. It XORs the value with a randomly generated token so that the exact value is never stored. It also comes with checks to make sure the token is valid and that the return value hasn't been tampered with.
Source XorUInteger:
Source XorULong:

[JAN 11 2016]
Added mouse tracking although it isn't complete. Will have to get mouse tracking to properly scale with the window (Right now it works properly when the window is it's native resolution but any smaller and the tracking goes whack).

[JAN 08 2016]
Added a bit to the audio manager. Its able to stop any instance of audio that has been played. During playback an Instance ID is returned and that ID is used to distinguish that audio instance from the rest. That same ID will be used to stop playback of that audio instance if that instance is still playing, if not nothing will happen. Instances start with ID 1, if an ID of 0 is obtained that means the audio instance failed to play (most likely due to missing audio from collection).

[JAN 06 2016]
Improved the fullscreen, now fullscreening from a maximized windowed to fullscreen works and unfullscreening goes back to maximized bordered if it was previously so. Maximizing from a normal boredered window also maximizes and unmaximizes back to a normal window. With the addition of the new GameTimer I found that resizing the window doesn't impact the game much and so I removed the bit where it blacks the screen and suspends the layout until resize has completed so now you can see the game being resized as you resize it. This also gives the plus effect that the game doesn't blacks out when you move the window around. I fixed a problem with the mouse cursor showing over the game when it was specified not to so not when you want to hide the mouse cursor it wont show up anymore. Deleted some unnecessary functions and cleaned up some variables.

[JAN 05 2016]
I implemented my new GameTimer which provides more accurate control over frame-rate which still provides the low CPU usage of the older GameTimer.
I added a third buffer to try and mitigate some stutter I see.
I also hope that this fixes the inconsistencies between FPS on Intel vs AMD machines but will need more testing.
Source for the new GameTimer can be found here:

OLD GameTimer ex:

NEW GameTimer ex:

[JAN 04 2016]
Game now knows when its in focus or not so to grab inputs or not. Changed a bit of the rendering logic so it doesn't have draw queues (was made irrelevant with the buffers but forgot to take it out).

[DEC 30 2015]
Implemented my sound system. I haven't done too much testing but I know that it works. Essentially it is just my previous sound engine code I made a while back. It can do multiple instances of sounds and so a bunch of sound effects going at once shouldn't be a problem. The loading method is similar to the loading method I use for loading graphic assets. What to work on next I wonder.

[DEC 26 2015]
In addition to scaling I have implemented full screen. Full screen is mapped to F11. I might change it to Alt-Enter sometime later.

[DEC 23 2015]
Messing around with different image formats again and I think I will settle for the old fashion GIF format (or more accurately some of its concepts). GIF has a maximum color palette of 256 colors and so each pixel only takes one byte to represent a color. With about 3000 character sprites loaded into memory I figure that will be about a little over 1GB of memory. Of course this is excluding other things like background and effects as well as sound and game logic but I think its much more manageable now memory-wise. I played a bit with vectors and while memory becomes no longer an issue with simple sprites the more complex ones (ones with many angles) seem to be about the same or in some cases worst (though sprites looked so crisp and sharp, its a shame I couldn't use them). I might still use vectors for some things (large but simple effects) but not sure yet, but surprisingly vectors are pretty resource hungry (because they have to be calculated each time where as with an image it only needs to be drawn I figure).

[DEC 22 2015]
After scaling was implemented I had to center the view port but doing so revealed that everything would render to the edges of the window. I went ahead and implemented a constraint on the view port effectively creating a letterbox effect that has the same aspect ratio as the render resolution.
Ex (16:9 ratio):

[DEC 21 2015]
Got to implement scaling so now changing the size of the window wont crop or letterbox anything, instead everything is scaled up/down relative to the window and internal rendering resolution.

[DEC 13 2015]
Finished/Fixed dead zone correction for EZPAD. Download and source updated below.
Changed a couple things in terms of graphics.
Found a weird behavior where a frame sometimes drew an image out of place and of unspecified size, fixed it by having 2 buffers instead of one (buffer isn't used here in the normal sense of back buffers).

[DEC 12 2015]
Decided to redo the XInput lib for ease of use, flexibility and usage more straight forward.
New one is called EZPAD, Download and source is provided below (VB.NET).
     Imports EZPAD
     Dim NewGamePad As New EZPAD(PLAYER.ONE)
Old XPadMonitor Source:

No comments: