Squash Monster
|
|
« Reply #60 on: January 27, 2009, 10:20:31 PM » |
|
O_O
Although I actually used to know a guy in the Ohrrpgce community who didn't know how to use functions, so he put his entire game in one function.
My current project is for the Java4k competition, so I'm actually doing this right now. It's quite the jump, going from my usual main code (which is just a window constructor) to this.
|
|
|
Logged
|
|
|
|
Chris Whitman
|
|
« Reply #61 on: January 27, 2009, 10:50:31 PM » |
|
The parentheses are part of the return value expression and basically have no effect when used here since there's no ambiguity in the order of evaluation that you need to resolve. Personally I'd stay away from the usage since it's confusing. I suppose that's a good idea. Actually, wasn't 'return(0);' preferred coding style for ANSI C back in the day? I'm sure I used to see that usage all over the place, even though it is, of course, redundant.
|
|
|
Logged
|
Formerly "I Like Cake."
|
|
|
increpare
Guest
|
|
« Reply #62 on: January 27, 2009, 11:04:39 PM » |
|
Actually, wasn't 'return(0);' preferred coding style for ANSI C back in the day? I'm sure I used to see that usage all over the place, even though it is, of course, redundant.
I don't see it mentioned in the standards
|
|
|
Logged
|
|
|
|
PoV
|
|
« Reply #63 on: January 30, 2009, 03:59:19 PM » |
|
From Smiles. Allegro (obsolete) // - ------------------------------------------------------------------------------------------ - // int main( int argc, char* argv[] ) { gfxInit( 480, 320, false, 2 ); do { cGame Game; while( !gfxHasShutdown() ) { gfxClearBuffer( RGB(70,0,0) ); Mouse.Update(); Camera.Update();
// Reset Hack // if ( key[KEY_TAB] ) break; // if ( mouse_b == 2 ) { // gfxAddCameraPos( -(Mouse.Diff() * gfxGetCameraScale()) ); // } // gfxConstrainCamera( Game.GetBounds().Vertex[0], Game.GetBounds().Vertex[1] ); // if ( Mouse.WheelDiff() ) { // gfxAddCameraScale( Real(Mouse.WheelDiff()) * Real(0.1) ); // gfxConstrainCameraScale( Real::One, Real(4) ); // } // Step the game // Game.Step();
// Prior to drawing, set the current matrix to suit drawing relative to the camera // gfxSetCameraMatrix(); // Draw the game // Game.Draw(); // Draw cursors and hud stuffs in screen space, as opposed to camera space // gfxSetScreenMatrix(); // gfxDrawCross( Vector2D::Zero, 4 ); // Draw the cursor (last, so it's on top of everything) // if ( Mouse.Button(1) ) { gfxDrawCircleFill( Mouse.Pos, 3, RGB_BLACK ); gfxDrawCircleFill( Mouse.Pos, 2, RGB_YELLOW ); } else { gfxDrawCircleFill( Mouse.Pos, 2, RGB_BLACK ); gfxDrawCircleFill( Mouse.Pos, 1, RGB_WHITE ); } // // Freezing Hack // // while( key[KEY_SPACE] ) {} // Swap display buffer to screen // gfxSwapBuffer(); } } while( key[KEY_TAB] ); gfxExit(); return 0; } END_OF_MAIN(); // - ------------------------------------------------------------------------------------------ - //
SDL+GL and Custom GFX Library hybrid // - ------------------------------------------------------------------------------------------ - // int main( int argc, char* argv[] ) { #ifndef NIX_BUILD gfxInit( 480, 320, false, 2 );
// Disable Vertical Sync // // { // typedef void (APIENTRY * WGLSWAPINTERVALEXT) ( int ) ; // // WGLSWAPINTERVALEXT wglSwapIntervalEXT = (WGLSWAPINTERVALEXT) SDL_GL_GetProcAddress( "wglSwapIntervalEXT" ) ; // if ( wglSwapIntervalEXT != 0 ) { // // Disable vertical synchronisation : // wglSwapIntervalEXT( 0 ) ; // } // } #else gfxInit( 480, 320, false, 1 ); #endif // NIX_BUILD // FramerateConstant = 60; CurrentTime = GetTime();
sndInit(); { cGame Game; while( !gfxHasShutdown() ) { // First Run Clear the Screen // if ( Game.FirstRun ) { gfxDisableBlending(); gfxClearBuffer( RGB_WHITE ); }
#ifdef NIX_BUILD timeval TimeDiff = SubtractTime( GetTime(), CurrentTime ); int Frames = GetFrames( TimeDiff ); //printf("Fr: %i\n", Frames ); timeval Sixty; Sixty.tv_sec = 0; Sixty.tv_usec = 1000000 / FramerateConstant; #else int TimeDiff = GetTime() - CurrentTime; int Frames = TimeDiff / (1000/60);
#endif // NIX_BUILD // for( int idx = 0; idx < Frames; idx++ ) { MessageLoop(); Mouse.Update(); Camera.Update();
Game.Step(); #ifdef NIX_BUILD CurrentTime = AddTime( CurrentTime, Sixty ); #else CurrentTime += 1000/60; #endif // NIX_BUILD // } if ( Frames > 0 ) { // Draw the game // Game.Draw(); // If Capture was enabled, capture the screen, and draw again // if ( Game.Capture ) { gfxCapture(); Game.Capture = false; Game.Draw(); } if ( Game.FirstRun ) { Game.Capture = true; Game.FirstRun = false; } }
// Swap display buffer to screen // gfxSwapBuffer(); } Game.SaveGameState(); Game.SaveHighScores(); Game.SaveAchievements(); } if ( Buffer ) { SDL_FreeSurface( Buffer ); } sndFree(); gfxExit(); return 0; } // - ------------------------------------------------------------------------------------------ - //
iPhone int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } I know, lame 'eh.
|
|
|
Logged
|
|
|
|
increpare
Guest
|
|
« Reply #64 on: March 15, 2009, 12:24:26 PM » |
|
variation on one posted earlier... int main(int argc, char *argv[]) { init(); loop<IntroLoop>(); playmusic(1); while (!quit) { loop<TitleLoop>(); loop<PrefaceLoop>(); loop<GameLoop>(); loop<GameOverLoop>(); } return 0; }
|
|
|
Logged
|
|
|
|
mcc
|
|
« Reply #65 on: March 15, 2009, 05:26:39 PM » |
|
Heh, okay. main() for Jumpman: int main(int argc, char*argv[]) { { time_t rawtime; time ( &rawtime ); srand(rawtime); }
cpInitChipmunk(); uiSpace = cpSpaceNew(); hiddenControlsSpace = cpSpaceNew(); if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0 ) { REALERR("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; // WINDOWS VISTA CROSSCOMPILE HATES exit() SO I NO LONGER CALL IT?!? } sdl_init();
glutStuff(argc, (const char**)argv); Loop(); return 0; } Amusingly (?) the function named glutStuff() hasn't actually contained any GLUT since I switched to SDL like a week after starting the program, I just initialize OpenGL there.
|
|
|
Logged
|
|
|
|
increpare
Guest
|
|
« Reply #66 on: March 15, 2009, 06:07:49 PM » |
|
sounds like someone needs to do some spring-cleaning to me
|
|
|
Logged
|
|
|
|
mcc
|
|
« Reply #67 on: March 15, 2009, 06:46:08 PM » |
|
sounds like someone needs to do some spring-cleaning to me ...yeah I should probably admit at this point that the GLUT initialization code in glutStuff was never actually removed, just commented out...
|
|
|
Logged
|
|
|
|
Ina Vegt
Level 1
Girl Game Developer
|
|
« Reply #68 on: March 15, 2009, 06:59:44 PM » |
|
(def main (fn [] ( (var gameInfo initData) (var gameState (titleMenu initData)) (gameLoop gameInfo gameState) closeGame )
|
|
|
Logged
|
|
|
|
Zaknafein
|
|
« Reply #69 on: March 15, 2009, 07:17:29 PM » |
|
variation on one posted earlier... int main(int argc, char *argv[]) { init(); loop<IntroLoop>(); playmusic(1); while (!quit) { loop<TitleLoop>(); loop<PrefaceLoop>(); loop<GameLoop>(); loop<GameOverLoop>(); } return 0; } That's pretty awesome. I dig the cleanness.
|
|
|
Logged
|
|
|
|
increpare
Guest
|
|
« Reply #70 on: March 15, 2009, 07:21:52 PM » |
|
(def main (fn [] ( (var gameInfo initData) (var gameState (titleMenu initData)) (gameLoop gameInfo gameState) closeGame ) care to show us the game proper ?
|
|
|
Logged
|
|
|
|
gnat
|
|
« Reply #71 on: March 15, 2009, 08:54:13 PM » |
|
#include "master.h"
int main(int argc, char *argv[]) { initialize(); loadData(); void (*doLogic)(); void (*doDrawing)();
doLogic = screenGameplayLogic; doDrawing = screenGameplayDrawing; while(running) { doLogic(); doDrawing(); blitScreen(); }
shutdown(); return 0; } Why use a screen manager at all when function pointers are so simple to use?
|
|
|
Logged
|
|
|
|
Ina Vegt
Level 1
Girl Game Developer
|
|
« Reply #72 on: March 15, 2009, 10:05:46 PM » |
|
(def main (fn [] ( (var gameInfo initData) (var gameState (titleMenu initData)) (gameLoop gameInfo gameState) closeGame ) care to show us the game proper ? It's not done yet, sorry.
|
|
|
Logged
|
|
|
|
rogerlevy
Guest
|
|
« Reply #73 on: March 16, 2009, 03:52:32 AM » |
|
: go gfx poll begin ?togglefs step ?break until (break) ;
Something like that. This was from memory.
|
|
|
Logged
|
|
|
|
Eclipse
|
|
« Reply #74 on: March 16, 2009, 04:38:17 AM » |
|
int main() { device = createDevice( "AkomDeviceWin32", resX, resY); renderer = createRenderer( device, "AkomRendererD3D9"); //renderer = createRenderer( device, "AkomRendererOpenGL");
input = createInputManager(device,"AkomInputManagerDI8");
game->run();
return 0; }
PS Akom is our engine, aka A Kind Of Magic. The stuff like "AkomDeviceX11" ect are modules, the base ones are device and renderer (for application\os related stuff and window management and rendering). But we're doing input, audio and physics crossplatform modules too.
|
|
« Last Edit: March 16, 2009, 04:54:49 AM by Eclipse »
|
Logged
|
<Powergloved_Andy> I once fapped to Dora the Explorer
|
|
|
mirosurabu
Guest
|
|
« Reply #75 on: March 16, 2009, 06:11:49 AM » |
|
My fancy new way of coding main functions.
|
|
|
Logged
|
|
|
|
AaronAardvark
Level 1
Formerly RazputinOleander
|
|
« Reply #76 on: March 16, 2009, 06:41:08 AM » |
|
sub main { # ----------------------------------------------------------------------------- my $window = Window->new('cfg/window.cfg'); my $input = Input->new(); my $scene = Scene->new('cfg/scene.cfg');
# The main game loop. while (1) { $window->update(); $input->update();
if ($window->ready()) { $scene->update(); }
# Handle input. $scene->handle($input->events()); } }
[edit] Updated main function. [/edit]
|
|
« Last Edit: March 16, 2009, 09:13:04 AM by RazputinOleander »
|
Logged
|
|
|
|
TheSpaceMan
|
|
« Reply #77 on: March 16, 2009, 09:43:26 AM » |
|
void main() { Engine engine; engine.Init(); while(!engine.quit); { engine.update(); } }
|
|
|
Logged
|
|
|
|
David Pittman
|
|
« Reply #78 on: March 16, 2009, 09:44:18 AM » |
|
My main for CC1984. I could have stuffed all the initialization calls into a single function to make it even cleaner. Oh well. int main() { Math::SeedGenerator(); g_Renderer.Init(); g_AudioSystem = CreateFMODAudioSystem(); InitContent();
while( g_StartNewGame ) { ResetEverything(); while( MainLoop() ); }
return 0; }
|
|
|
Logged
|
|
|
|
Ryan
Level 1
|
|
« Reply #79 on: March 16, 2009, 10:19:17 AM » |
|
(def main (fn [] ( (var gameInfo initData) (var gameState (titleMenu initData)) (gameLoop gameInfo gameState) closeGame ) What lisp dialect is this? Or is it a part of some custom scripting environment? Looks interesting. edit: Might as well post my main loop here, although it's not interesting: int main(int argc, char* argv[]) { Game game; game.Run(); return 0; }
|
|
« Last Edit: March 16, 2009, 12:34:21 PM by Ryan »
|
Logged
|
|
|
|
|