• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

vgmoose/wiiu-space: [Wii U] Homebrew space shooter written with libwiiu

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

vgmoose/wiiu-space

开源软件地址:

https://github.com/vgmoose/wiiu-space

开源编程语言:

C 67.1%

开源软件介绍:

Space Game

This is a Wii U homebrew game. You can run the latest release via Homebrew Launcher. Watch a video of the gameplay in action here!

Through different iterations of Space Game, several branches on this repository have emerged. The four primarily interesting ones are:

  • master - The original userland exploit-based branch of Space Game, which uses libwiiu
  • hbl_elf (default) - A branch designed for HBL to be executed as an elf that uses dimok's dynamic libraries
  • wut_working - The future branch, which uses WUT to generate an RPX (see branch's readme)
  • hbl_elf_v2beta - The development branch that is currently based off hbl_elf, soon to be integrated with wut_working

Logo

Space game is a graphical shooter game on the Wii U! Since it was originally designed to be executed via the .mp4 exploit in 5.5.x, there were several challenges that were imposed on its development in terms of efficiency and storage.

Binary Size Tricks

A main issue with the webkit exploit is that binaries that can be executed in the browser are capped at a certain file size. I hit issues when my binary (code550.bin) exceeded 21,400 bytes. It may not seem like it, but that's not much! I employed a couple of tricks to keep the binary size small:

Compiling with -O1 as a CFLAG

If you look at my Makefile and compare it to other ones for the libwiiu examples, you'll notice a few differences near the top of the file. The most important of these differences is the addition of the -O1 parameter to the CFLAGS variable. This sets the compiler's optimization level and can usually shave off up to 6,000 bytes!

There was one big issue though: I found that, whenever I compiled with -O1, very strangely, calling OSScreenFlipBuffersEx(0) in draw.c caused a crash. This didn't happen with OSScreenFlipBuffersEx(1)! I'm still not sure why this happens. I think, when compiled with -O1, the first screen buffer does not get properly initialized. Since this happens in loader.c, I moved the Makefile around to compile every file except loader.c with -O1. This way, it's all still linked together into one mostly compact binary and won't crash.

Note: I also compiled the https://github.com/wiiudev/libwiiu repo with the -O1 flag.

Compressing Bitmaps

A fair amount of the filesize, even after compression, is due to the bitmap image storing that is employed. Images are stored directly in images.c, with the assistance of this script that converts a bitmap to a compressed C char array. The bitmap is then drawn via modifications to the draw.c library. It does not use GX2 at this time.

My compresion algorithm is a little complicated, but it is detailed at the top of images.c. It tries to store information about streaks of pixels as efficiently as possible. The way I did it only allows for 125 total colors in a palette. The algorithm can also be used to compress arrays, the trick is storing sequences of similar numbers as instructions, such as: {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} becomes {8, 1, 3, 0, 10, 1} (eight ones, three zeroes, ten ones).

Speedup Tricks

Drawing was a pain here, but I found I was able to greatly increase my drawing speed by moving all of the coreinit.rpl function pointers into a struct and passing that around to the drawing library. This is possible because the pointers do not change, so looking them up every time a pixel is drawn is, as far as I can tell, just extra time that could be spent drawing!

I also had to wrap my head around the concept of using flipBuffers. From what I gather, calling "flipBuffers" acts as a sort of "commit" for everything you've previously drawn to appear on screne. Then the next calls you make to draw will be put into the next upcoming buffer that you then flip to again. This is done so that a seamless gameplay can be presented without flickering, despite the entire screen being redrawn every frame.

In game

Issues

If you have any issues with the code here when you try to use it in your own app, feel free to contact me!

If you have any filesize issues when trying to run this app, I suggest you try commenting out the giant logo byte array in images.c.

Misc Math

Trig functions

A big issue I had using this program was with not using the standard math library. I was not able to get it working without the file size shooting way up. As such, I implemented estimations for sin, cos, and arctan in math.h. These are primarly used to calculate angles and spin the spaceship. I found myself drawing many right traingles on paper and reciting SOHCAHTOA over and over again before I finally managed to get it right!

(Pseudo-)Random numbers

This was another area that I struggled with. Fortunately, there's a method to get the current time, so that can be used as a seed. The implementation I ended up going with is based on an older version of glibc's rand().

Matrix multiplication

In order to rotate the bitmap to the angle calculated by the trig functions, I had to use a rotation matrix. This is actually a lot easier than it looks once you have the algorithm to multiply two matrices. What did stump me for a while is that the matrix has to first be translated up and left by half its height and width before rotating, since the rotation happens around the top left point. By translating it, you put the center in the top left, which allows for the rotation to take place around the center. This is then rotated back.

I also make use of a scaling matrix for explosions, which similarly gets multiplied by the bitmap when it's time to blow up

Creating bitmaps

I created my bitmaps in Photoshop using Mode -> Index color. I extracted the palettes manually by using a hex editor. I've provided the three bitmaps that I used in this repo, although the actual image files are not used by the game. There are other ways to create bitmaps like this (I believe older mspaint supports it)

Credits and License

This program is licensed under the MIT license, which grants anyone permission to do pretty much whatever they want as long as the copyright notice stays intact.*

*While the game is free software, the song *cruise* is copyright ©2015 by the band (T-T)b. This license does not permit redistribution or reuse of this song, unless it is embedded within an authorized Space Game binary.

How to Compile and Run

See building the Homebrew Launcher




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap