Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411491 Posts in 69377 Topics- by 58433 Members - Latest Member: graysonsolis

April 29, 2024, 09:36:33 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Post your main function(s)
Pages: 1 2 3 [4] 5
Print
Author Topic: Post your main function(s)  (Read 16548 times)
Squash Monster
Level 0
**



View Profile
« 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
Sepia Toned
Level 10
*****


A master of karate and friendship for everyone.


View Profile
« 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.  WTF

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
Level 5
*****


Click on the eye and something might happen..maybe


View Profile WWW
« Reply #63 on: January 30, 2009, 03:59:19 PM »

From Smiles.

Allegro (obsolete)

Code:
// - ------------------------------------------------------------------------------------------ - //
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

Code:
// - ------------------------------------------------------------------------------------------ - //
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

Code:
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.   Undecided
Logged

Mike Kasprzak | Sykhronics Entertainment - Smiles (HD), PuffBOMB, towlr, Ludum Dare - Blog
increpare
Guest
« Reply #64 on: March 15, 2009, 12:24:26 PM »

variation on one posted earlier...

Code:
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
Level 10
*****


glitch


View Profile WWW
« Reply #65 on: March 15, 2009, 05:26:39 PM »

Heh, okay. main() for Jumpman:

Quote
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

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
increpare
Guest
« Reply #66 on: March 15, 2009, 06:07:49 PM »

sounds like someone needs to do some spring-cleaning to me  Roll Eyes
Logged
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #67 on: March 15, 2009, 06:46:08 PM »

sounds like someone needs to do some spring-cleaning to me  Roll Eyes
...yeah

I should probably admit at this point that the GLUT initialization code in glutStuff was never actually removed, just commented out...
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Ina Vegt
Level 1
*


Girl Game Developer


View Profile
« Reply #68 on: March 15, 2009, 06:59:44 PM »

Code:
(def main (fn [] (
  (var gameInfo initData)
  (var gameState (titleMenu initData))
  (gameLoop gameInfo gameState)
  closeGame
)
Logged
Zaknafein
Level 4
****



View Profile WWW
« Reply #69 on: March 15, 2009, 07:17:29 PM »

variation on one posted earlier...

Code:
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. Hand Thumbs Up Left
Logged

increpare
Guest
« Reply #70 on: March 15, 2009, 07:21:52 PM »

Code:
(def main (fn [] (
  (var gameInfo initData)
  (var gameState (titleMenu initData))
  (gameLoop gameInfo gameState)
  closeGame
)

care to show us the game proper ? Smiley
Logged
gnat
Level 1
*



View Profile WWW
« Reply #71 on: March 15, 2009, 08:54:13 PM »

Code:
#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?

Gentleman
Logged

LAN Party List - The definitive LAN party list. Also Game Jams, etc.
GitHub
Ina Vegt
Level 1
*


Girl Game Developer


View Profile
« Reply #72 on: March 15, 2009, 10:05:46 PM »

Code:
(def main (fn [] (
  (var gameInfo initData)
  (var gameState (titleMenu initData))
  (gameLoop gameInfo gameState)
  closeGame
)

care to show us the game proper ? Smiley

It's not done yet, sorry.
Logged
rogerlevy
Guest
« Reply #73 on: March 16, 2009, 03:52:32 AM »

Code:

: go   gfx poll begin ?togglefs step ?break until (break) ;


Something like that.  This was from memory.
Logged
Eclipse
Level 10
*****


0xDEADC0DE


View Profile WWW
« Reply #74 on: March 16, 2009, 04:38:17 AM »

Quote
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.

Smiley
« 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. Tongue
Logged
AaronAardvark
Level 1
*


Formerly RazputinOleander


View Profile WWW
« Reply #76 on: March 16, 2009, 06:41:08 AM »

Code:
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. Smiley
[/edit]
« Last Edit: March 16, 2009, 09:13:04 AM by RazputinOleander » Logged
TheSpaceMan
Level 1
*



View Profile WWW
« Reply #77 on: March 16, 2009, 09:43:26 AM »

void main()
{
    Engine engine;
    engine.Init();
    while(!engine.quit);
    {
         engine.update();
    }
}
Logged

Follow The Flying Thing, my current project.
http://forums.tigsource.com/index.php?topic=24421.0
David Pittman
Level 2
**


MAEK GAEM


View Profile WWW
« 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.

Code:
int main()
{
Math::SeedGenerator();
g_Renderer.Init();
g_AudioSystem = CreateFMODAudioSystem();
InitContent();

while( g_StartNewGame )
{
ResetEverything();
while( MainLoop() );
}

return 0;
}
Logged

Ryan
Level 1
*



View Profile
« Reply #79 on: March 16, 2009, 10:19:17 AM »

Code:
(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.
 Gentleman

edit: Might as well post my main loop here, although it's not interesting:

Code:
int main(int argc, char* argv[])
{
    Game game;
    game.Run();
    return 0;
}
« Last Edit: March 16, 2009, 12:34:21 PM by Ryan » Logged
Pages: 1 2 3 [4] 5
Print
Jump to:  

Theme orange-lt created by panic