NewoAsteroids v3 PostMortem (programming)
Page is part of Articles in which you can submit an article
written by owen on 2019-Dec-26.
Black and White wireframe
Colours are randomized each restart. However there are no guarantees that you will get a cool combination
Debugging
Menu Interface
Fake cellshading
I had some free-ish time so I dug into my old #wii homebrew asteroids clone/game nicknamed NewoAsteroids (NA) since I had not looked at seriously in over 7 years since its initial release on wiibrew.org. The game is entirely written in the C programming language which took me like 2 years to written initially and another 7 years to get good at.
NA happens to be my most complete #wii #homebrew game mostly because it was a easy game to code. Being easy to code allows me to dig in at a level which allows feature creep to flourish at exorbitant levels - I have muzzle flashes on the spaceship that you cannot even see. The easier it is to code something the more time you have to add polish like online leaderboards, achievements, multi-languages and a background planet with 3 moons orbiting it.
So I took it up again and started to make small changes while live blogging it on gbatemp planning to move from version 2.98 to a new version 3 major release. This is a summary of the events leading up to the 3.0 release.
Brief History
NewoAsteroids 1 (video) was originally released in 2012 after I had just "finished" NewoShooter. The achievements system was added a month later (source code available) after much online research and coming up with nothing but API traps. Seven months later in July2013 I added a online leader board which makes use of Joyent Http-parser. By Feb2014 I added auto-update, pthreaded loading screen and a php front-end for the leaderboard statistics using JavaScript and Google Charts. Besides those major additions where a lot of bug fixes, experimenting and research for how to implement the features in C.
Version 3 code sprint
Now in 2019 I wanted to fix some long standing bugs. One such bug occurred when a player has disabled the online leaderboard then restarted the game and then tried to view the leaderboard. This error occurred because the code that setup the leaderboard only ran at the start of the game during the loading screen so if you tried to enable the leaderboard during the game it would fail to a blank screen. kids this is what happens when you do not do TDD.
There is a popular app in the wii homebrew scene called the Homebrew Browser which has a old version of my application 2.6 which sucks because it is pre "auto-update" code and the HBB is no longer updated so its stuck. There is no real way to fix the HBB - the only solution is to build something new which is out of scope so I will just have to leave it alone. This annoys me because I like having everyone playing the game on the same version for quality of life reasons - (not a obsession with control and deprecation that modern programmers tend to have).
Between the release of the original NA and now I had released 6 new homebrew. In every new thing I make I learn new and useful programming tricks. Tools such as procedural generation (NewoSky), fast line drawing (CityDemo), smooth camera interpolation + explosion particle management + colour transitioning (NewoFox), 3d triangle based AABB collision detection (NewoEscape), path following (NewoTokyo).
Most of these new tricks were implemented into NA leading to better explosions, faster collisions, colour mixing and more debug options. The camera was a bit trickier to implement - a floating camera added a whole new level of problems around easing and micro movements that occurred when the ship in NA would drift by small fractions causing the camera to stutter.
As I write this I am still working on the multiplayer portion of the game. I might implement it at launch or I might not (eventually scrapped it - not enough time). It depends on if I hit up on any walls.
In terms of the particle effects in the original NA I was drawing circles but circles are computationally expensive which is why I switched to a square made of a 4 point line strip which I nicknamed the "frame". Square particle effects and gradient backgrounds were inspired by Super Space Club.
Another optimization involved using line primitives for bullets instead of quads. A quad cube is made up of 6 quads which are 24 vertices while a line is simply 2 vertices. I increase the thickness of the line to improve its visibility. I added a point at the end of the line inorder to better indicate its direction. So in total I saved 21 GPU hits per bullet.
Not all fun and games
It was not all fun and games with the bullets however because some bullets for example lasers/wave beams required special treatment. Lazers for example need to be longer than regular bullets. This was fixed by making the leading end of the line travel for a certain distance before the tail follows. The wave gun on the other hand required me to change from a fixed frame step simulation to a fractional frame step.
The fixed bullet step worked in the past because all bullet movement was tied to the framerate. When the wave gun was implemented slower bullets would create smaller waves. Enemy wave bullets would ending up looking different in comparison to when the same bullet was fired by the player. The time based wave animation required more detail. The simplest way to implement this was to apply more draw steps to faster bullets. Of course this is a sub frame animation. At some point in the future I might go full variable frame rate but I am not going down that rabbit hole today.
I also rebuilt the entire settings engine which means if you had settings from an old version they will be lost. The new settings engine uses string keys for indexes so it is more future proof than the old version which is a ordered list of numbers. I also added a lot of new settings which is why changing the settings engine was a necessary move. The new settings API allows me to add menu options and other settings quickly without needing to add them to the end of the array.
Probably the biggest change is fixing my displaylists which gave the game approximately 40% boast in draw efficiency (source code). of course this improvement is invisible to the player as the game was already running at 60fps but it allows the engine to run at higher stress levels than ever before. I can now run the game with all my debugging options turned on at 60fps - not that I need to but I can lol.
Conclusion
It was a good 3 month code sprint, with the help of Mr Reaper(@tinyvast) I added a background story, fixed a tonne of UI issues, refined some game play mechanics and I published the new version on Dec 21 2019 right before the holidays trying to make the most of the people who dust off their game consoles on the holidays. It is fun working on something so simple yet with so much room to grow. I look forward to the next time I am able to pick it up again and through some more brain power at it.
Addendum
Raz0red seems to have cracked the WiiU problem that I have been experiencing with all my homebrew. NA might just be working on the vWii now. He is creating a trailer for the game as well.
This is the new timer code in C;
static u64 startTime = 0;
u64 timer_get_time() {
if(startTime==0) startTime = gettime() / TB_TIMER_CLOCK;
return (gettime() / TB_TIMER_CLOCK) - startTime; //ticks_to_millisecs(gettick());
}u64 timer_temp;
bool timer( float wait_time, u64 *current_time ) { //CRITICAL //return true if currtime < (ct + wt) has elapsed
//function to determine if a certain amount of time has passed in relation to current_time. updates current time
timer_temp=timer_get_time(); //hmmm I could save some by doing this outside
if( *current_time==0 ) { *current_time=timer_temp; return false; }//prevent firing on first check
if( timer_temp > ( *current_time + wait_time ) ) { // changed it from >= to > to try to fix possible vwii-u speed issue
*current_time=timer_temp;//time(NULL);
return true;
}
return false;
}
I have a background in web developement so the layout of this article is a custom CSS theme that is called "article_thumbgrid". You can click on the images to make them bigger if you are on a large screen monitor. If you are on a phone you pretty much get what you get.
Finished gameplay video trailer.
permanent link. Find similar posts in Articles.
comments
Comment list is empty. You should totally be the first to Post your comments on this article.