PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX * amx) { static bool bFirst = false; if(!bFirst) { bFirst = true; // Get pNetGame int (*pfn_GetNetGame)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_NETGAME]; pNetGame = (CNetGame*)pfn_GetNetGame(); // Get pConsole int (*pfn_GetConsole)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_CONSOLE]; pConsole = (void*)pfn_GetConsole(); // Get pRakServer int (*pfn_GetRakServer)(void) = (int(*)(void))ppPluginData[PLUGIN_DATA_RAKSERVER]; pRakServer = (RakServer*)pfn_GetRakServer(); } return InitScripting(amx); }
int InitOpcodeTraps(DISZ80 *d) { int err; char buf[_MAX_PATH + 64]; if (d->scriptFileName[0]) { if (d->pTrapMap == NULL) { if ((d->pTrapMap = AllocateMap(d, "Couldn't allocate memory for the opcode trap map.", 256)) == NULL) { DisZ80CleanUp(d); return DERR_OUTOFMEM; } } err = InitScripting(d); if (err != DERR_NONE) return err; err = lua_dofile(d->ls, d->scriptFileName); if (err) { switch(err) { case 2: sprintf(buf, "Couldn't open the script file \"%s\"", d->scriptFileName); dZ80_Error(d, buf); return DERR_COULDNTOPENFILE; default: return DERR_SCRIPTERROR; } } } return DERR_NONE; }
void Init(const CmdLineArgs& args, int UNUSED(flags)) { h_mgr_init(); // Do this as soon as possible, because it chdirs // and will mess up the error reporting if anything // crashes before the working directory is set. InitVfs(args); // This must come after VFS init, which sets the current directory // (required for finding our output log files). g_Logger = new CLogger; // Special command-line mode to dump the entity schemas instead of running the game. // (This must be done after loading VFS etc, but should be done before wasting time // on anything else.) if (args.Has("dumpSchema")) { CSimulation2 sim(NULL, NULL); sim.LoadDefaultScripts(); std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc); f << sim.GenerateSchema(); std::cout << "Generated entity.rng\n"; exit(0); } // override ah_translate with our i18n code. AppHooks hooks = {0}; hooks.translate = psTranslate; hooks.translate_free = psTranslateFree; app_hooks_update(&hooks); // Set up the console early, so that debugging // messages can be logged to it. (The console's size // and fonts are set later in InitPs()) g_Console = new CConsole(); CNetHost::Initialize(); new CProfileViewer; new CProfileManager; // before any script code g_ScriptStatsTable = new CScriptStatsTable; g_ProfileViewer.AddRootTable(g_ScriptStatsTable); #if CONFIG2_AUDIO CSoundManager::CreateSoundManager(); #endif InitScripting(); // before GUI // g_ConfigDB, command line args, globals CONFIG_Init(args); // Optionally start profiler HTTP output automatically // (By default it's only enabled by a hotkey, for security/performance) bool profilerHTTPEnable = false; CFG_GET_VAL("profiler2.http.autoenable", Bool, profilerHTTPEnable); if (profilerHTTPEnable) g_Profiler2.EnableHTTP(); if (!g_Quickstart) g_UserReporter.Initialize(); // after config PROFILE2_EVENT("Init finished"); }
int main(int argc, char *argv[]) { enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN; char *remote_address = NULL; int remote_port; int i; if (argc < 2) { printf("Penguin Warrior\n"); printf("Usage: pw [ mode ] [ option ... ]\n"); printf(" Game modes (choose one):\n"); printf(" --computer\n"); printf(" --client <remote ip address>\n"); printf(" --server <port number>\n"); printf(" Display options, for tweaking and experimenting:\n"); printf(" --fullscreen\n"); printf(" --hwsurface (use an SDL hardware surface if possible)\n"); printf(" --doublebuf (use SDL double buffering if possible)\n"); printf(" The display options default to a windowed, software buffer.\n"); exit(EXIT_FAILURE); } /* Process command line arguments. There are plenty of libraries for command line processing, but our needs are simple in this case. */ for (i = 0; i < argc; i++) { /* Networked or scripted opponent? */ if (!strcmp(argv[i], "--computer")) { game_type = GAME_COMPUTER; continue; } else if (!strcmp(argv[i], "--client")) { game_type = GAME_NETWORK; if (i + 2 >= argc) { printf("You must supply an IP address "\ "and port number for network games.\n"); exit(EXIT_FAILURE); } remote_address = argv[i+1]; remote_port = atoi(argv[i+2]); i++; continue; } else if (!strcmp(argv[i], "--server")) { game_type = GAME_NETWORK; if (++i >= argc) { printf("You must supply a port number "\ "for --server.\n"); exit(EXIT_FAILURE); } remote_port = atoi(argv[i]); continue; /* Display-related options */ } else if (!strcmp(argv[i], "--hwsurface")) { hwsurface = 1; } else if (!strcmp(argv[i], "--doublebuf")) { doublebuf = 1; } else if (!strcmp(argv[i], "--fullscreen")) { fullscreen = 1; } } /* If this is a network game, make a connection. */ if (game_type == GAME_NETWORK) { /* If there's no remote address, the user selected server mode. */ if (remote_address == NULL) { if (WaitNetgameConnection(remote_port, &netlink) != 0) { printf("Unable to receive connection.\n"); exit(EXIT_FAILURE); } } else { if (ConnectToNetgame(remote_address, remote_port, &netlink) != 0) { printf("Unable to connect.\n"); exit(EXIT_FAILURE); } } opponent_type = OPP_NETWORK; printf("Playing in network game against %s.\n", netlink.dotted_ip); } else if (game_type == GAME_COMPUTER) { opponent_type = OPP_COMPUTER; printf("Playing against the computer.\n"); } else { printf("No game type selected.\n"); exit(EXIT_FAILURE); } /* Initialize our random number generator. */ initrandom(); /* Create a mutex to protect the player data. */ player_mutex = SDL_CreateMutex(); if (player_mutex == NULL) { fprintf(stderr, "Unable to create mutex: %s\n", SDL_GetError()); } /* Start our scripting engine. */ InitScripting(); if (LoadGameScript("pw.tcl") != 0) { fprintf(stderr, "Exiting due to script error.\n"); exit(EXIT_FAILURE); } /* Fire up SDL. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); /* Set an appropriate 16-bit video mode. */ if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) | (doublebuf ? SDL_DOUBLEBUF : 0) | (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Save the screen pointer for later use. */ screen = SDL_GetVideoSurface(); /* Set the window caption to the name of the game. */ SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior"); /* Hide the mouse pointer. */ SDL_ShowCursor(0); /* Initialize the status display. */ if (InitStatusDisplay() < 0) { printf("Unable to initialize status display.\n"); exit(EXIT_FAILURE); } /* Start the OpenAL-based audio system. */ InitAudio(); /* Initialize music and give the music system a file. */ InitMusic(); if (LoadMusic("reflux.ogg") < 0) { /* If that failed, don't worry about it. */ printf("Unable to load reflux.ogg.\n"); } /* Load the game's data into globals. */ LoadGameData(); /* Initialize the background starfield. */ InitBackground(); /* Start the network thread. */ if (game_type == GAME_NETWORK) { network_thread = SDL_CreateThread(NetworkThread, NULL); if (network_thread == NULL) { printf("Unable to start network thread: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } } /* Play! */ InitPlayer(&player); InitPlayer(&opponent); PlayGame(); /* Kill the network thread. */ if (game_type == GAME_NETWORK) { SDL_KillThread(network_thread); } /* Close the network connection. */ if (game_type == GAME_NETWORK) CloseNetgameLink(&netlink); /* Unhide the mouse pointer. */ SDL_ShowCursor(1); /* Clean up the status display. */ CleanupStatusDisplay(); /* Unload data. */ UnloadGameData(); /* Shut down our scripting engine. */ CleanupScripting(); /* Get rid of the mutex. */ SDL_DestroyMutex(player_mutex); /* Shut down audio. */ CleanupMusic(); CleanupAudio(); return 0; }
int main(int argc, char **argv) { int i; int res; int one = 1; int option_index = 0; int c; char *main_script = NULL; // adding default include paths add_include_path("."); // TODO: once ordinary installation is available, add /usr/share/kbd-mangler/js or something while (1) { c = getopt_long(argc, argv, "r:w:I:", long_options, &option_index); if (c == -1) break; switch (c) { case 'r': { // preparing input device int input_fd = open(optarg, O_RDONLY); if (input_fd < 0) { fprintf(stderr, "could not open input device %s: %s\n", optarg, strerror(errno)); exit(2); } if (ioctl(input_fd, EVIOCGRAB, (void *)1) < 0) { fprintf (stderr, "unable to grab device '%s' : %s\n", optarg, strerror(errno)); } if (ioctl(input_fd, FIONBIO, (void *)&one) < 0) { fprintf (stderr, "unable to set device '%s' to non-blocking mode : %s\n", optarg, strerror(errno)); } if (input_count < MAX_INPUTS) { input_fds[input_count++] = input_fd; } else { fprintf (stderr, "Maximum number of input devices exceeded (%d)\n", MAX_INPUTS); exit(1); } break; } case 'w': if (uinput_fd >= 0) { fprintf(stderr, "multiple -w options are not allowed\n"); usage(); exit(1); } init_uinput(optarg); break; case 'I': add_include_path(optarg); break; case '?': break; default: fprintf(stderr, "getopt returned unexpectd char code: 0%o\n", c); exit(1); } } if (uinput_fd == -1) { usage(); } // script name left if (argc - optind != 1) usage(); res = InitScripting(argv[optind]); // custom main script if (res) { main_loop(); } else { fprintf(stderr, "Error initializing scripting\n"); } DestroyScripting(); for (i = 0; i < input_count; i++) close(input_fds[i]); close(uinput_fd); }
int main(int argc, char *argv[]) { enum { GAME_COMPUTER, GAME_NETWORK, GAME_UNKNOWN } game_type = GAME_UNKNOWN; char *remote_address; int i; if (argc < 2) { printf("Penguin Warrior\n"); printf("Usage: pw [ mode ] [ option ... ]\n"); printf(" Game modes (choose one):\n"); printf(" --computer\n"); printf(" --net <remote ip address>\n"); printf(" Display options, for tweaking and experimenting:\n"); printf(" --fullscreen\n"); printf(" --hwsurface (use an SDL hardware surface if possible)\n"); printf(" --doublebuf (use SDL double buffering if possible)\n"); printf(" The display options default to a windowed, software buffer.\n"); return 1; } /* Process command line arguments. There are plenty of libraries for command line processing, but our needs are simple in this case. */ for (i = 0; i < argc; i++) { /* Networked or scripted opponent? */ if (!strcmp(argv[i], "--computer")) { game_type = GAME_COMPUTER; continue; } else if (!strcmp(argv[i], "--net")) { game_type = GAME_NETWORK; if (++i >= argc) { printf("You must supply an IP address for --net.\n"); return 1; } remote_address = argv[i]; continue; /* Display-related options */ } else if (!strcmp(argv[i], "--hwsurface")) { hwsurface = 1; } else if (!strcmp(argv[i], "--doublebuf")) { doublebuf = 1; } else if (!strcmp(argv[i], "--fullscreen")) { fullscreen = 1; } } switch (game_type) { case GAME_COMPUTER: opponent_type = OPP_COMPUTER; printf("Playing against the computer.\n"); break; case GAME_NETWORK: printf("Sorry, network play is not implemented... yet!\n"); return 1; default: printf("You must select a game type.\n"); return 1; } /* Initialize our random number generator. */ initrandom(); /* Start our scripting engine. */ InitScripting(); if (LoadGameScript("pw.tcl") != 0) { fprintf(stderr, "Exiting due to script error.\n"); return 1; } /* Fire up SDL. */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); /* Set an appropriate 16-bit double buffered video mode. */ if (SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, (hwsurface ? SDL_HWSURFACE : SDL_SWSURFACE) | (doublebuf ? SDL_DOUBLEBUF : 0) | (fullscreen ? SDL_FULLSCREEN : 0)) == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } /* Save the screen pointer for later use. */ screen = SDL_GetVideoSurface(); /* Set the window caption to the name of the game. */ SDL_WM_SetCaption("Penguin Warrior", "Penguin Warrior"); /* Hide the mouse pointer. */ SDL_ShowCursor(0); /* Load the game's data into globals. */ LoadGameData(); /* Initialize the background starfield. */ InitBackground(); /* Play! */ InitPlayer(); InitOpponent(); PlayGame(); /* Unhide the mouse pointer. */ SDL_ShowCursor(1); /* Unload data. */ UnloadGameData(); /* Shut down our scripting engine. */ CleanupScripting(); return 0; }