Skip to content

Commit

Permalink
Merge pull request #3 from Jm15itch/main
Browse files Browse the repository at this point in the history
Argument parsing changes + Code changes
  • Loading branch information
mrbid authored Jul 11, 2023
2 parents 2432cda + b26bc5a commit 6defbb9
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 137 deletions.
51 changes: 51 additions & 0 deletions assets/console_menus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef HelpMenu
#define HelpMenu \
"\n" \
" =====================================================\n" \
" | |\n" \
" | TuxPusher.com |\n" \
" | |\n" \
" | James William Fletcher (github.com/mrbid) |\n" \
" | |\n" \
" =====================================================\n\n" \
"\n" \
" -= ARGUMENTS =-\n\n" \
"Access this menu\n" \
" --help\n" \
" -h\n\n" \
"Change MSAA Levels (1, 2, 4, 8, 16)\n" \
" --msaa-level {VALUE}\n" \
" --msaa {VALUE}\n\n" \
"Change VSYNC Settings (-1, 0, 1)\n" \
" --vertical-sync {OPTION}\n" \
" --vs {OPTION}\n\n" \
"Change Game Speed Settings (1-32)\n" \
" --push-speed {VALUE}\n" \
" --ps {VALUE}\n\n" \
"\n" \
" -= CONTROLS =-\n\n" \
"Left Click = Release coin\n" \
"Right Click = Show/hide cursor\n" \
"C = Orthographic/Perspective\n" \
"F = Print the FPS to the console\n" \
"\n\n" \
" -= CREDITS =-\n\n" \
"Tux 3D model by Andy Cuccaro:\n" \
"https://sketchfab.com/3d-models/tux-157de95fa4014050a969a8361a83d366\n" \
"Fonts used in the End Game screen from top to bottom order:\n" \
"1. Fontasy Penguin by FontasyLand\n" \
" https://www.fontspace.com/fontasy-penguin-font-f4848\n" \
"2. Plastic Love by Azkarizki\n" \
" https://www.fontspace.com/plastic-love-font-f49676\n" \
"3. Allay Font by Abahrozi (https://twinletter.com/)\n" \
" https://www.fontspace.com/allay-font-f66225\n" \
"\n\n" \
" -= CONTRIBUTORS =-\n\n" \
"Jm15itch (github.com/Jm15itch)\n\n" \
"\n" \
" -= RULES =-\n\n" \
"- A gold coin in a silver slot rewards you 2x silver coins.\n" \
"- A gold coin in a gold slot rewards you 2x gold coins.\n" \
"- A tux in a slot when you already have the tux gives you 6x gold coins and 6x silver coins.\n" \
"\n\n"
#endif
263 changes: 126 additions & 137 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#include "assets/sa.h"
#include "assets/ga.h"

#include "assets/console_menus.h"

#define uint GLushort // it's a short don't forget that
#define sint GLshort // and this.
#define f32 GLfloat
Expand Down Expand Up @@ -118,7 +120,6 @@ mat modelview;
vec lightpos = {0.f, 10.f, 13.f};
int csp = -1; // current shader program

// models
ESModel mdlPlane;
ESModel mdlGameover;
ESModel mdlScene;
Expand Down Expand Up @@ -938,90 +939,42 @@ void main_loop()
// trophies
for(int i=0; i < 3; i++)
{
if(coins[i].color == 1)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
}
else if(coins[i].color == 2)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlEvil);
glDrawElements(GL_TRIANGLES, evil_numind, GL_UNSIGNED_BYTE, 0);
}
else if(coins[i].color == 3)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.6f);
modelBind3(&mdlKing);
glDrawElements(GL_TRIANGLES, king_numind, GL_UNSIGNED_BYTE, 0);
}
else if(coins[i].color == 4)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

modelBind3(&mdlNinja);
glDrawElements(GL_TRIANGLES, ninja_numind, GL_UNSIGNED_BYTE, 0);
}
else if(coins[i].color == 5)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.4f);
modelBind3(&mdlSurf);
glDrawElements(GL_TRIANGLES, surf_numind, GL_UNSIGNED_SHORT, 0);
}
else if(coins[i].color == 6)
{
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);
mIdent(&model);
mTranslate(&model, coins[i].x, coins[i].y, 0.f);
mMul(&modelview, &model, &view);
glUniformMatrix4fv(modelview_id, 1, GL_FALSE, (f32*) &modelview.m[0][0]);

// Draw the base Tux model, this will be our base to add apparel onto
glUniform1f(opacity_id, 0.148f);
modelBind3(&mdlTux);
glDrawElements(GL_TRIANGLES, tux_numind, GL_UNSIGNED_SHORT, 0);

glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlTrip);
glDrawElements(GL_TRIANGLES, trip_numind, GL_UNSIGNED_SHORT, 0);
// Tux Skin Selection.
switch (coins[i].color) {
case 2:
glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlEvil);
glDrawElements(GL_TRIANGLES, evil_numind, GL_UNSIGNED_BYTE, 0);
break;
case 3:
glUniform1f(opacity_id, 0.6f);
modelBind3(&mdlKing);
glDrawElements(GL_TRIANGLES, king_numind, GL_UNSIGNED_BYTE, 0);
break;
case 4:
modelBind3(&mdlNinja);
glDrawElements(GL_TRIANGLES, ninja_numind, GL_UNSIGNED_BYTE, 0);
break;
case 5:
glUniform1f(opacity_id, 0.4f);
modelBind3(&mdlSurf);
glDrawElements(GL_TRIANGLES, surf_numind, GL_UNSIGNED_SHORT, 0);
break;
case 6:
glUniform1f(opacity_id, 0.5f);
modelBind3(&mdlTrip);
glDrawElements(GL_TRIANGLES, trip_numind, GL_UNSIGNED_SHORT, 0);
break;
}
}

Expand Down Expand Up @@ -1343,42 +1296,87 @@ void printAttrib(SDL_GLattr attr, char* name)
printf("%s: %i\n", name, i);
}
#endif


// A small function to perform djb2 hash algorithm. This is for quick string checking and other hash needs.
// More info here: https://github.com/dim13/djb2/blob/master/docs/hash.md
unsigned int quickHash(const char *string) {
unsigned long hash = 5381;
int c;
while (c = *string++) {
hash = ((hash << 5) + hash) + c;
}
return (unsigned int)hash; // cast into an int so it's usable with switches.
}

int main(int argc, char** argv)
{
// allow custom msaa level
int msaa = 16;
if(argc >= 2){msaa = atoi(argv[1]);}
// set game push speed (global variable)
PUSH_SPEED = 1.6f;

// help
printf("----\n");
printf("TuxPusher.com\n");
printf("----\n");
printf("James William Fletcher (github.com/mrbid)\n");
printf("----\n");
printf("Argv(2): msaa, speed\n");
printf("e.g; ./uc 16 1.6\n");
printf("----\n");
printf("Left Click = Release coin\n");
printf("Right Click = Show/hide cursor\n");
printf("C = Orthographic/Perspective\n");
printf("F = FPS to console\n");
printf("----\n");
printf("Tux 3D model by Andy Cuccaro:\n");
printf("https://sketchfab.com/3d-models/tux-157de95fa4014050a969a8361a83d366\n");
printf("----\n");
printf("Fonts used in the End Game screen from top to bottom order:\n");
printf("1. Fontasy Penguin by FontasyLand\n");
printf(" https://www.fontspace.com/fontasy-penguin-font-f4848\n");
printf("2. Plastic Love by Azkarizki\n");
printf(" https://www.fontspace.com/plastic-love-font-f49676\n");
printf("3. Allay Font by Abahrozi (https://twinletter.com/)\n");
printf(" https://www.fontspace.com/allay-font-f66225\n");
printf("----\n");
printf("Rules:\n");
printf("Getting a gold coin in a silver slot rewards you 2x silver coins.\n");
printf("Getting a gold coin in a gold slot rewards you 2x gold coins.\n");
printf("Getting a tux in a slot when you already have the tux gives you 6x gold coins and 6x silver coins.\n");
printf("----\n");
// msaa level variable
int option_msaa = 16;

// Vertical sync option. 0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for adaptive vsync
int option_vsync = 1;

// Evaluate hashes for comparing arguments later...
const int HASHGEN = 285276507; // --generate-hash
const int TINY_HASHGEN = 193429505; // -gh

const int HELP = 1950366504; // --help
const int TINY_HELP = 5861498; // -h

const int MSAALEVEL = 2444437574; // --msaa-level
const int TINY_MSAALEVEL = 191564340; // -msaa

const int VSYNC = 596612675; // --vertical-sync
const int TINY_VSYNC = 193430011; // -vs

const int PUSHSPEED = 1053346333; // --push-speed
const int TINY_PUSHSPEED = 193429813; // -ps

// Loop through console arguments and adjust program accordingly.
// i starts at one to skip the program name.
for (int i = 1; i < argc; i++) {
switch (quickHash(argv[i])) {
case HASHGEN:
case TINY_HASHGEN:
printf("This tool is designed to generate hashes to compare the console arguments to.\n");
printf("Hashed value: %u\n", quickHash(argv[i+1]));
printf("Prehashed Value: %s\n", argv[i+1]);
exit(0);
case HELP: // Display the help menu and quit
case TINY_HELP:
printf(HelpMenu);
exit(0);
case MSAALEVEL: // Change the MSAA level.
case TINY_MSAALEVEL:
option_msaa = atoi(argv[i+1]);
break;
case VSYNC: // change the Vsync options.
case TINY_VSYNC:
switch (atoi(argv[i+1])) { // sanitizes the vsync options
case -1:
option_vsync = -1;
break;
case 1:
option_vsync = 1;
break;
default:
printf("WARNING: Invalid vsync option, valid options are: -1, 0, 1.");
}
break;
case PUSHSPEED: // Change the push speed of the game.
case TINY_PUSHSPEED:
PUSH_SPEED = atof(argv[i+1]);
if(PUSH_SPEED > 32.f) {
PUSH_SPEED = 32.f;
}
printf("Successfully set Push speed to %f", PUSH_SPEED);
break;
}
}

#ifdef BUILD_GLFW
// init glfw
Expand Down Expand Up @@ -1412,22 +1410,22 @@ int main(int argc, char** argv)
return 1;
}
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, option_msaa);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
wnd = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winw, winh, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
while(wnd == NULL)
{
if(msaa == 0)
if(option_msaa == 0)
{
printf("ERROR: SDL_CreateWindow(): %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa/2);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, option_msaa/2);
wnd = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, winw, winh, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
}
SDL_GL_SetSwapInterval(1); // 0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for adaptive vsync
SDL_GL_SetSwapInterval(option_vsync);
glc = SDL_GL_CreateContext(wnd);
if(glc == NULL)
{
Expand All @@ -1445,21 +1443,6 @@ int main(int argc, char** argv)
SDL_SetWindowIcon(wnd, s_icon);
#endif

// set game push speed
PUSH_SPEED = 1.6f;
if(argc >= 3)
{
PUSH_SPEED = atof(argv[2]);
if(PUSH_SPEED > 32.f){PUSH_SPEED = 32.f;}
char titlestr[256];
sprintf(titlestr, "TuxPusher [%.1f]", PUSH_SPEED);
#ifdef BUILD_GLFW
glfwSetWindowTitle(wnd, titlestr);
#else
SDL_SetWindowTitle(wnd, titlestr);
#endif
}

// debug (cant do this on ES unless >= ES 3.2)
#if defined(GL_DEBUG) && !defined(__MINGW32__) // no need to debug the windows release
esDebug(1);
Expand Down Expand Up @@ -1633,7 +1616,13 @@ int main(int argc, char** argv)
fc++;
}
#else
while(1){main_loop();fc++;}

// Game loop
for (;;) {
main_loop();
fc++;
}

#endif

return 0;
Expand Down

0 comments on commit 6defbb9

Please sign in to comment.