BOOL C3dMazeEffect::InitScene(HDC hDC) { GLGuarder guarder(hDC); { // init glClearColor(MAZE_GL_BG_COLOR); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); } { // reshape const RECT &client = GetClientArea(); const RECT &wnd = GetWindowArea(); glViewport(client.left, wnd.bottom - client.bottom, client.right - client.left, client.bottom - client.top); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, m_pMaze->GetMazeSize()*MAZE_GL_GRID_SIZE*2); glMatrixMode(GL_MODELVIEW); } { // texture m_tex[MT_WALL] = LoadTexture(hDC, IDBMP_3DM_WALL, 128, 128); m_tex[MT_CROSS_POINT] = LoadTexture(hDC, IDBMP_3DM_CROSS_POINT, 128, 128); glEnable(GL_TEXTURE_2D); } // init lists InitLists(); return TRUE; }
int main( int argc, char *argv[ ] ) { glutInit( &argc, argv ); InitGraphics( ); InitLists( ); InitCL( ); Reset( ); InitGlui( ); glutMainLoop( ); return 0; }
void ScriptManager::InitDlg (HWND dlg) { HWND sci = CreateEditControl(dlg); ShowWindow(sci, SW_SHOW); SetFocus(sci); stec.SetWindow(reinterpret_cast<long>(sci)); if (!edPtr->tData->scripts) { edPtr->tData->scripts = new ScriptSet(mV); edPtr->tData->scripts->Refresh(mV, edPtr); } InitEditor(sci); InitLists(dlg); ScriptManager& sm = ScriptManager::Get(); ResizeSetup(dlg, sm.prefDlgWidth, sm.prefDlgHeight); }
int main( int argc, char *argv[ ] ) { // turn on the glut package: // (do this before checking argc and argv since it might // pull some command line arguments out) glutInit( &argc, argv ); // setup all the graphics stuff: InitGraphics( ); // create the display structures that will not change: InitLists( ); // init all the global variables used by Display( ): // this will also post a redisplay // it is important to call this before InitGlui( ) // so that the variables that glui will control are correct // when each glui widget is created Reset( ); // setup all the user interface stuff: InitGlui( ); // draw the scene once and wait for some interaction: // (this will never return) glutMainLoop( ); // this is here to make the compiler happy: return 0; }
int main( int argc, char *argv[ ] ) { // turn on the glut package: // (do this before checking argc and argv since it might // pull some command line arguments out) glutInit( &argc, argv ); // setup all the graphics stuff: InitGraphics( ); // create the display structures that will not change: InitLists( ); // init all the global variables used by Display( ): // this will also post a redisplay Reset( ); // setup all the user interface stuff: InitMenus( ); // draw the scene once and wait for some interaction: // (this will never return) glutSetWindow( MainWindow ); glutMainLoop( ); // this is here to make the compiler happy: return 0; }
//-------------------------------------------------------------------------------------------- void MainWindow::Init() { CreateArduinoConnector(); InitLists(); //===#### II: 1) Right (Readiness): ####=== PReadiness = new MReadiness(); PReadiness->Init(); //===#### III: 1) Right (Telemetry): ####=== PTelemetry = new MTelemetry(this); PTelemetry->Init(); //===#### ####=== SlotSwitchToReadiness(); //====== connect(PReadiness, SIGNAL(SignalSetTypeModeReadiness()), PArduinoConnector, SLOT(SlotSetTypeModeReadiness())); connect(PTelemetry, SIGNAL(SignalSetTypeModeTelemetry()), PArduinoConnector, SLOT(SlotSetTypeModeTelemetry())); connect(PTelemetry, SIGNAL(SignalGetAllTelemetryValues()), PArduinoConnector, SLOT(SlotGetAllTelemetryValues())); connect(PTelemetry, SIGNAL(SignalStopTakingData()), PArduinoConnector, SLOT(SlotStopTakingData())); }
int ZopfliLengthLimitedCodeLengths( const size_t* frequencies, int n, int maxbits, unsigned* bitlengths) { Node* pool; int i; int numsymbols = 0; /* Amount of symbols with frequency > 0. */ int numBoundaryPMRuns; Node* nodes; unsigned char stack[16]; /* Array of lists of chains. Each list requires only two lookahead chains at a time, so each list is a array of two Node*'s. */ Node* (*lists)[2]; /* One leaf per symbol. Only numsymbols leaves will be used. */ Node* leaves = (Node*)malloc(n * sizeof(*leaves)); /* Initialize all bitlengths at 0. */ for (i = 0; i < n; i++) { bitlengths[i] = 0; } /* Count used symbols and place them in the leaves. */ for (i = 0; i < n; i++) { if (frequencies[i]) { leaves[numsymbols].weight = frequencies[i]; leaves[numsymbols].count = i; /* Index of symbol this leaf represents. */ numsymbols++; } } /* Check special cases and error conditions. */ if ((1 << maxbits) < numsymbols) { free(leaves); return 1; /* Error, too few maxbits to represent symbols. */ } if (numsymbols == 0) { free(leaves); return 0; /* No symbols at all. OK. */ } if (numsymbols == 1) { bitlengths[leaves[0].count] = 1; free(leaves); return 0; /* Only one symbol, give it bitlength 1, not 0. OK. */ } if (numsymbols == 2) { bitlengths[leaves[0].count]++; bitlengths[leaves[1].count]++; free(leaves); return 0; } /* Sort the leaves from lightest to heaviest. Add count into the same variable for stable sorting. */ for (i = 0; i < numsymbols; i++) { if (leaves[i].weight >= ((size_t)1 << (sizeof(leaves[0].weight) * CHAR_BIT - 9))) { free(leaves); return 1; /* Error, we need 9 bits for the count. */ } leaves[i].weight = (leaves[i].weight << 9) | leaves[i].count; } qsort(leaves, numsymbols, sizeof(Node), LeafComparator); for (i = 0; i < numsymbols; i++) { leaves[i].weight >>= 9; } if (numsymbols - 1 < maxbits) { maxbits = numsymbols - 1; } /* Initialize node memory pool. */ nodes = (Node*)malloc(maxbits * 2 * numsymbols * sizeof(Node)); pool = nodes; lists = (Node* (*)[2])malloc(maxbits * sizeof(*lists)); InitLists(pool, leaves, maxbits, lists); pool += 2; /* In the last list, 2 * numsymbols - 2 active chains need to be created. Two are already created in the initialization. Each BoundaryPM run creates one. */ numBoundaryPMRuns = 2 * numsymbols - 4; for (i = 0; i < numBoundaryPMRuns - 1; i++) { /* Performs a Boundary Package-Merge step. Puts a new chain in the given list. The new chain is, depending on the weights, a leaf or a combination of two chains from the previous list. */ unsigned stackpos; stack[0] = maxbits - 1; for (stackpos = 0; ;) { unsigned char index = stack[stackpos]; int lastcount = lists[index][1]->count; /* Count of last chain of list. */ Node* newchain = pool++; Node* oldchain = lists[index][1]; size_t sum; /* These are set up before the recursive calls below, so that there is a list pointing to the new node, to let the garbage collection know it's in use. */ lists[index][0] = oldchain; lists[index][1] = newchain; sum = lists[index - 1][0]->weight + lists[index - 1][1]->weight; if (lastcount < numsymbols && sum > leaves[lastcount].weight) { /* New leaf inserted in list, so count is incremented. */ InitNode(leaves[lastcount].weight, lastcount + 1, oldchain->tail, newchain); } else { InitNode(sum, lastcount, lists[index - 1][1], newchain); /* Two lookahead chains of previous list used up, create new ones. */ if (index == 1) { if (lists[0][1]->count < numsymbols) { lastcount = lists[0][1]->count; lists[0][0] = lists[0][1]; lists[0][1] = pool++; InitNode(leaves[lastcount].weight, lastcount + 1, 0, lists[0][1]); lastcount++; if(lastcount < numsymbols){ lists[0][0] = lists[0][1]; lists[0][1] = pool++; InitNode(leaves[lastcount].weight, lastcount + 1, 0, lists[0][1]); } } } else { stack[stackpos++] = index - 1; stack[stackpos++] = index - 1; } } if (!stackpos--) { break; } } } BoundaryPMFinal(lists, leaves, numsymbols, pool, maxbits - 1); ExtractBitLengths(lists[maxbits - 1][1], leaves, bitlengths); free(lists); free(leaves); free(nodes); return 0; /* OK. */ }
int main(int argc, char *argv[]) { #if !defined DEBUGMODE && !defined DAEMONTOOLS pid_t pid; /* pid of this process */ #endif /* !DEBUGMODE && !DAEMONTOOLS */ #ifdef GDB_DEBUG int GDBAttached = 0; #endif /* GDB_DEBUG */ #if defined GIMMECORE || defined DEBUGMODE struct rlimit rlim; /* resource limits -kre */ #endif /* GIMMECORE || DEBUGMODE */ FILE *pidfile; /* to write our pid */ uid_t uid; /* real user id */ uid_t euid; /* effective user id */ #if defined HAVE_BOEHM_GC GC_INIT(); #endif /* HAVE_BOEHM_GC */ myargv = argv; /* Initialise current TS for services -kre */ TimeStarted = current_ts = time(NULL); /* Be sure, be paranoid, be safe. -kre */ umask(077); fprintf(stderr, "Hybserv2 TS services version %s by Hybserv2 team\n" #if defined __DATE__ && defined __TIME__ "Compiled at %s, %s\n", #endif hVersion #if defined __DATE__ && defined __TIME__ , __DATE__, __TIME__ #endif ); #ifdef GDB_DEBUG while (!GDBAttached) sleep(1); #endif /* GDB_DEBUG */ /* * Load SETPATH (settings.conf) - this must be done * before the config file is loaded, and before any * putlog() calls are made, since LogFile is specified * in settings.conf */ if (LoadSettings(0) == 0) { fprintf(stderr, "Fatal errors encountered parsing %s, exiting\n" "Check logfile %s/%s\n", SETPATH, LogPath ? LogPath : "", LogFile ? LogFile : "*unknown*"); return (0); } /* * If they run ./shownicks or ./showchans rather than ./hybserv * display nicknames/channels */ if (strstr(argv[0], "shownicks")) { #ifdef NICKSERVICES ShowNicknames(argc, argv); #endif /* NICKSERVICES */ return (0); } else if (strstr(argv[0], "showchans")) { #if defined(NICKSERVICES) && defined(CHANNELSERVICES) ShowChannels(argc, argv); #endif /* defined(NICKSERVICES) && defined(CHANNELSERVICES) */ return 0; } /* Check for running services -kre */ if ((pidfile = fopen(PidFile, "r")) == NULL) fprintf(stderr, "WARNING: Unable to read pid file %s\n", PidFile); else { pid_t mypid; char line[MAXLINE + 1]; if (fgets(line, sizeof(line), pidfile) != NULL) { mypid = atoi(line); if (mypid && !kill(mypid, 0)) { fprintf(stderr, "FATAL: Services are already running!\n"); fclose(pidfile); exit(EXIT_FAILURE); } } fclose(pidfile); } uid = getuid(); /* the user id of the user who ran the process */ euid = geteuid(); /* the effective id (different if setuid) */ if (!uid || !euid) { fprintf(stderr, "FATAL: Please don't run services as root. Now exiting.\n"); exit(EXIT_FAILURE); } if (chdir(HPath) != 0) { fprintf(stderr, "HPath is an invalid directory, please check %s\n", SETPATH); exit(EXIT_FAILURE); } putlog(LOG1, "Hybserv2 TS services version %s started", hVersion); /* Get the offset from GMT (London time) */ gmt_offset = GetTZOffset(TimeStarted); /* * the Network list must be initialized before the config * file is loaded */ InitLists(); /* load server, jupe, gline, user, admin info */ LoadConfig(); /* load nick/chan/memo/stat databases */ LoadData(); #ifdef GLOBALSERVICES if (LogonNews) { Network->LogonNewsFile.filename = LogonNews; ReadMessageFile(&Network->LogonNewsFile); } #endif /* GLOBALSERVICES */ if (LocalHostName) SetupVirtualHost(); #if !defined DEBUGMODE && !defined GDB_DEBUG /* Daemontools compatibility stuff */ #ifndef DAEMONTOOLS pid = fork(); if (pid == -1) { printf("Unable to fork(), exiting.\n"); exit(EXIT_FAILURE); } if (pid != 0) { printf("Running in background (pid: %d)\n", (int)pid); exit(EXIT_SUCCESS); } close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); /* Make current process session leader -kre */ if (setsid() == -1) { exit(EXIT_FAILURE); } #else printf("Entering foreground debug mode\n"); #endif /* DEBUGMODE */ #endif /* DAEMONTOOLS */ #if defined GIMMECORE || defined DEBUGMODE printf("Setting corefile limit... "); /* Set corefilesize to maximum - therefore we ensure that core will be * generated, no matter of shell limits -kre */ getrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_CORE, &rlim); printf("done.\n"); #endif /* GIMMECORE || DEBUGMODE */ /* Signals must be set up after fork(), since the parent exits */ InitSignals(); /* Initialise random number generator -kre */ srandom(current_ts); srandom((unsigned int)random()); /* Write our pid to a file */ if ((pidfile = fopen(PidFile, "w")) == NULL) putlog(LOG1, "Unable to open %s", PidFile); else { char line[MAXLINE + 1]; ircsprintf(line, "%d\n", getpid()); fputs(line, pidfile); fclose(pidfile); } /* initialize tcm/user listening ports */ InitListenPorts(); /* initialize hash tables */ ClearHashes(1); #ifdef BLOCK_ALLOCATION InitHeaps(); #endif HubSock = NOSOCKET; CycleServers(); while (1) { /* enter loop waiting for server info */ ReadSocketInfo(); if (Me.hub) SendUmode(OPERUMODE_Y, "*** Disconnected from %s", Me.hub->name); else SendUmode(OPERUMODE_Y, "*** Disconnected from hub server"); if (currenthub) { if (currenthub->realname) { MyFree(currenthub->realname); currenthub->realname = NULL; } currenthub->connect_ts = 0; } close(HubSock); /* There was an error */ HubSock = NOSOCKET; /* * whenever Hybserv connects/reconnects to a server, clear * users, servers, and chans */ ClearUsers(); ClearChans(); ClearServs(); /* * ClearHashes() must be called AFTER ClearUsers(), * or StatServ's unique client counts will be off since * cloneTable[] would be NULL while it was trying to find * clones */ ClearHashes(0); PostCleanup(); } /* while (1) */ return 0; } /* main() */
int // sm: silence warning main(int argc, char **argv) { unsigned long p, iMax; float gMax, lastGMax; ModuleRecPtr mr; ; /* parse argument */ if (argc != 2) { fprintf(stderr, "Usage: KL <input_file>\n"); ; exit(1); } /* prepare the data structures */ ReadNetList(argv[1]); NetsToModules(); ComputeNetCosts(); assert((numModules % 2) == 0); /* initial partition */ InitLists(); lastGMax = 0; /* do until we don't make any progress */ do { #ifndef KS_MODE /* compute the swap costs */ ComputeDs(&(groupA), GroupA, SwappedToA); ComputeDs(&(groupB), GroupB, SwappedToB); #endif /* !KS_MODE */ /* for all pairs of nodes in A,B */ for (p = 0; p<numModules/2; p++) { #ifdef KS_MODE /* compute the swap costs */ ComputeDs(&(groupA), GroupA, SwappedToA); ComputeDs(&(groupB), GroupB, SwappedToB); #endif /* KS_MODE */ /* find the max swap opportunity, and swap */ GP[p] = FindMaxGpAndSwap(); } /* lists should both be empty now */ assert(groupA.head == NULL && groupA.tail == NULL); assert(groupB.head == NULL && groupB.tail == NULL); gMax = FindGMax(&iMax); /* debug/statistics */ if (lastGMax == gMax) fprintf(stdout, "No progress: gMax = %f\n", gMax); lastGMax = gMax; fprintf(stdout, "gMax = %f, iMax = %lu\n", gMax, iMax); if (gMax > 0.0) SwapSubsetAndReset(iMax); PrintResults(0); } while (gMax > 0.0); /* progress made? */ /* all swaps rejected */ groupA = swapToB; for (mr = groupA.head; mr != NULL; mr = (*mr).next) moduleToGroup[(*mr).module] = GroupA; groupB = swapToA; for (mr = groupB.head; mr != NULL; mr = (*mr).next) moduleToGroup[(*mr).module] = GroupB; ; /* all done, show results */ PrintResults(1); #ifdef PLUS_STATS PrintDerefStats(stderr); PrintHeapSize(stderr); #endif /* PLUS_STATS */ exit(0); return 0; // sm: silence warning }
bool CreateGameForm::DoModal(int *pnResult) { // Format the lists. int aidcList[] = { kidcChallengeList, kidcAddOnList }; for (int i = 0; i < ARRAYSIZE(aidcList); i++) { ListControl *plstc = (ListControl *)GetControlPtr(aidcList[i]); m_aplstc[i] = plstc; Rect rc; plstc->GetRect(&rc); Font *pfnt = gapfnt[kifntShadow]; int cxComplete = pfnt->GetTextExtent("Complete"); int xTitle = rc.Width() / 2 - cxComplete * 3 / 2; plstc->SetTabStops(xTitle); plstc->SetTabFlags(kfLstTabEllipsis); plstc->SetFlags(plstc->GetFlags() | kfLstcKeepInteriorPositioning); plstc->Clear(); } if (m_pml == NULL) { m_pml = CreateMissionList(NULL, kmltMultiplayer); } if (m_pml == NULL) { return false; } // If asked to find a certain mission, find it first to // see what type it is, and switch the radio button bar to // that type. int iPack = -1; int iMission = -1; int cLevels = m_pml->GetCount(); for (int nLevel = 0; nLevel < cLevels; nLevel++) { MissionIdentifier miid; m_pml->GetMissionIdentifier(nLevel, &miid); if (memcmp(&miid.packid, &m_miidFind.packid, sizeof(miid.packid)) == 0) { if (iPack == -1) { iPack = nLevel; } if (strcmp(miid.szLvlFilename, m_miidFind.szLvlFilename) == 0) { iMission = nLevel; break; } } } if (iMission == -1) { iMission = iPack; } int iMissionSelect = iMission; // Init the lists MissionType mt = InitLists(iMissionSelect); SwitchToMissionType(mt); // Game Speed m_tGameSpeed = gtGameSpeed; if (m_tGameSpeed < 4) m_tGameSpeed = 4; SliderControl *psldr = (SliderControl *)GetControlPtr(kidcGameSpeed); psldr->SetRange(2, ARRAYSIZE(gatGameSpeeds) - 1 - 3); // bring the extremes in a bit for multiplayer psldr->SetValue(8); for (int i = 0; i < ARRAYSIZE(gatGameSpeeds); i++) { if (gatGameSpeeds[i] == m_tGameSpeed) { psldr->SetValue(i); break; } } // Hide this label. If we're finding an Add-On mission, then // there are add-on missions and this label isn't meant to be visible. GetControlPtr(kidcAddOnMessage)->Show(false); UpdateLabels(); gptra->SetCallback(this); bool fSuccess = ShellForm::DoModal(pnResult); gptra->SetCallback(NULL); delete m_pml; m_pml = NULL; return fSuccess; }
void ZopfliLengthLimitedCodeLengths(const size_t* frequencies, int n, int maxbits, unsigned* bitlengths) { int i; int numsymbols = 0; /* Amount of symbols with frequency > 0. */ /* Array of lists of chains. Each list requires only two lookahead chains at a time, so each list is a array of two Node*'s. */ /* One leaf per symbol. Only numsymbols leaves will be used. */ Node* leaves = (Node*)malloc(n * sizeof(*leaves)); if (!leaves){ exit(1); } /* Initialize all bitlengths at 0. */ memset(bitlengths, 0, n * sizeof(int)); /* Count used symbols and place them in the leaves. */ for (i = 0; i < n; i++) { if (frequencies[i]) { leaves[numsymbols].weight = frequencies[i]; leaves[numsymbols].count = i; /* Index of symbol this leaf represents. */ numsymbols++; } } /* Check special cases and error conditions. */ assert((1 << maxbits) >= numsymbols); /* Error, too few maxbits to represent symbols. */ if (numsymbols == 0) { free(leaves); return; /* No symbols at all. OK. */ } if (numsymbols == 1) { bitlengths[leaves[0].count] = 1; free(leaves); return; /* Only one symbol, give it bitlength 1, not 0. OK. */ } if (numsymbols == 2){ bitlengths[leaves[0].count]++; bitlengths[leaves[1].count]++; free(leaves); return; } /* Sort the leaves from lightest to heaviest. */ qsort(leaves, numsymbols, sizeof(Node), LeafComparator); /* Initialize node memory pool. */ NodePool pool; pool.size = 2 * maxbits * (maxbits + 1); pool.nodes = (Node*)calloc(pool.size, sizeof(*pool.nodes)); if (!pool.nodes){ exit(1); } pool.next = pool.nodes; Node* (*lists)[2] = (Node* (*)[2])malloc(maxbits * sizeof(*lists)); if (!lists || !lists[0] || !lists[1]){ exit(1); } InitLists(&pool, leaves, maxbits, lists); /* In the last list, 2 * numsymbols - 2 active chains need to be created. Two are already created in the initialization. Each BoundaryPM run creates one. */ int numBoundaryPMRuns = 2 * numsymbols - 4; for (i = 0; i < numBoundaryPMRuns - 1; i++) { BoundaryPM(lists, maxbits, leaves, numsymbols, &pool, maxbits - 1); } BoundaryPMfinal(lists, maxbits, leaves, numsymbols, &pool, maxbits - 1); ExtractBitLengths(lists[maxbits - 1][1], leaves, bitlengths); free(lists); free(leaves); free(pool.nodes); return; /* OK. */ }