int main() { pthread_t t1, t2; int ret; ret = obj_init(&obj); if (ret != 0) { printf("obj init failed\n"); exit(1); } ret = pthread_create(&t1, NULL, threadFunc1, NULL); if (ret != 0) perror("Pthread Create : "); ret = pthread_create(&t2, NULL, threadFunc2, NULL); if (ret != 0) perror("Pthread Create: "); ret = pthread_join(t1, NULL); if (ret != 0) perror("Pthread Join: "); ret = pthread_join(t2, NULL); if (ret != 0) perror("Pthreaf Join : "); exit(EXIT_SUCCESS); }
void functionobj_init(void) { obj_init(&obj, T_FUNCTION, "function"); obj.hash = hash; obj.same = same; obj.repr = repr; obj.calc2 = calc2; }
void pd_init(void) { mess_init(); obj_init(); conf_init(); glob_init(); garray_init(); }
/* Set up barometer system */ int baro_setup(void) { /* Set up baro_class */ obj_init(&baro_class.obj, system_class.type, "baro"); /* Register baro_class with /system/dev */ register_with_system(&dev_system, &baro_class); return 0; }
void pd_init(void) { if (!pd_this) pd_this = pdinstance_donew(0); mess_init(); obj_init(); conf_init(); glob_init(); garray_init(); }
static void libpmemobj_init(void) { out_init(PMEMOBJ_LOG_PREFIX, PMEMOBJ_LOG_LEVEL_VAR, PMEMOBJ_LOG_FILE_VAR, PMEMOBJ_MAJOR_VERSION, PMEMOBJ_MINOR_VERSION); LOG(3, NULL); util_init(); obj_init(); }
void obj_init(obj_t *obj) { if(!obj) return; obj_init(obj->next); try { obj->init(); } catch(...) { bq_thr_t::stop(); obj_fini(obj->next); throw; } }
void obj_start(char *srcfile) { //printf("obj_start()\n"); rtlsym_reset(); slist_reset(); clearStringTab(); obj_init(&objbuf, srcfile, NULL); el_reset(); cg87_reset(); out_reset(); }
QString LibObject::init() { #ifndef QT_NO_DEBUG if( id().hasLibObject() ) qWarning() << metaObject()->className() << objectName() << "already initialized"; #endif id_.setLibObject(this); if(const char *retv = obj_init()) { id_.setLibObject(0); return QString::fromUtf8(retv); } id_.postAppEvent(new EventObjectCreated(id_)); return QString(); }
/* * Start up by initializing global variables */ void win_start(void) { WNODE *pw; WORD i; win_view(START_VIEW, S_NAME); obj_init(); /* must be called *after* win_view(), because it uses */ /* G.g_iwspc/G.g_ihspc which are set by win_view() */ for (i = 0, G.g_wfirst = pw = G.g_wlist; i < NUM_WNODES; i++, pw++) { pw->w_next = pw + 1; pw->w_id = 0; } (pw-1)->w_next = NULL; G.g_wcnt = 0x0; }
void pd_init(void) { static int initted = 0; if (initted) return; initted = 1; #ifdef PDINSTANCE pd_instances = (t_pdinstance **)getbytes(sizeof(*pd_instances)); pd_instances[0] = &pd_maininstance; pd_ninstances = 1; #endif mess_init(); sys_lock(); obj_init(); conf_init(); glob_init(); garray_init(); sys_unlock(); }
void obj_code (uint4 src_lines, void *checksum_ctx) { int status; rhdtyp rhead; mline *mlx, *mly; var_tabent *vptr; int4 lnr_pad_len; intrpt_state_t prev_intrpt_state; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; assert(!run_time); obj_init(); /* Define the routine name global symbol. */ define_symbol(GTM_MODULE_DEF_PSECT, (mstr *)&int_module_name, 0); memset(&rhead, 0, SIZEOF(rhead)); alloc_reg(); jmp_opto(); curr_addr = SIZEOF(rhdtyp); cg_phase = CGP_APPROX_ADDR; cg_phase_last = CGP_NOSTATE; code_gen(); code_size = curr_addr; cg_phase = CGP_ADDR_OPT; shrink_jmps(); comp_lits(&rhead); if ((cmd_qlf.qlf & CQ_MACHINE_CODE)) { cg_phase = CGP_ASSEMBLY; code_gen(); } if (!(cmd_qlf.qlf & CQ_OBJECT)) return; rhead.ptext_ptr = SIZEOF(rhead); set_rtnhdr_checksum(&rhead, (gtm_rtn_src_chksum_ctx *)checksum_ctx); rhead.vartab_ptr = code_size; rhead.vartab_len = mvmax; code_size += mvmax * SIZEOF(var_tabent); rhead.labtab_ptr = code_size; rhead.labtab_len = mlmax; code_size += mlmax * SIZEOF(lab_tabent); rhead.lnrtab_ptr = code_size; rhead.lnrtab_len = src_lines; rhead.compiler_qlf = cmd_qlf.qlf; if (cmd_qlf.qlf & CQ_EMBED_SOURCE) { rhead.routine_source_offset = TREF(routine_source_offset); rhead.routine_source_length = (uint4)(stringpool.free - stringpool.base) - TREF(routine_source_offset); } rhead.temp_mvals = sa_temps[TVAL_REF]; rhead.temp_size = sa_temps_offset[TCAD_REF]; code_size += src_lines * SIZEOF(int4); lnr_pad_len = PADLEN(code_size, SECTION_ALIGN_BOUNDARY); code_size += lnr_pad_len; DEFER_INTERRUPTS(INTRPT_IN_OBJECT_FILE_COMPILE, prev_intrpt_state); create_object_file(&rhead); ENABLE_INTERRUPTS(INTRPT_IN_OBJECT_FILE_COMPILE, prev_intrpt_state); cg_phase = CGP_MACHINE; code_gen(); /* Variable table: */ vptr = (var_tabent *)mcalloc(mvmax * SIZEOF(var_tabent)); if (mvartab) walktree(mvartab, cg_var, (char *)&vptr); else assert(0 == mvmax); emit_immed((char *)vptr, mvmax * SIZEOF(var_tabent)); /* Label table: */ if (mlabtab) walktree((mvar *)mlabtab, cg_lab, (char *)rhead.lnrtab_ptr); else assert(0 == mlmax); /* External entry definitions: */ emit_immed((char *)&(mline_root.externalentry->rtaddr), SIZEOF(mline_root.externalentry->rtaddr)); /* line 0 */ for (mlx = mline_root.child; mlx; mlx = mly) { if (mlx->table) emit_immed((char *)&(mlx->externalentry->rtaddr), SIZEOF(mlx->externalentry->rtaddr)); if (0 == (mly = mlx->child)) /* note assignment */ if (0 == (mly = mlx->sibling)) /* note assignment */ for (mly = mlx; ; ) { if (0 == (mly = mly->parent)) /* note assignment */ break; if (mly->sibling) { mly = mly->sibling; break; } } } if (0 != lnr_pad_len) /* emit padding so literal text pool starts on proper boundary */ emit_immed(PADCHARS, lnr_pad_len); # if !defined(__MVS__) && !defined(__s390__) /* assert not valid for instructions on OS390 */ assert(code_size == psect_use_tab[GTM_CODE]); # endif emit_literals(); DEFER_INTERRUPTS(INTRPT_IN_OBJECT_FILE_COMPILE, prev_intrpt_state); finish_object_file(); ENABLE_INTERRUPTS(INTRPT_IN_OBJECT_FILE_COMPILE, prev_intrpt_state); CLOSE_OBJECT_FILE(object_file_des, status); if (-1 == status) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_SYSCALL, 5, RTS_ERROR_LITERAL("close()"), CALLFROM, errno); /* Ready to make object visible. Rename from tmp name to real routine name */ RENAME_TMP_OBJECT_FILE(object_file_name); }
int main(int argc, char *argv[]) { int i; float r = 0; Space *space; Entity *cube1,*cube2; char bGameLoopRunning = 1; Vec3D cameraPosition = {-10,3,0}; Vec3D cameraRotation = {180,0,180}; SDL_Event e; Obj *bgobj; Sprite *bgtext; //my variables Ship *playerShip; int specMode; init_logger("gametest3d.log"); if (graphics3d_init(1024,768,1,"gametest3d",33) != 0) { return -1; } model_init(); obj_init(); entity_init(255); initShips(); bgobj = obj_load("models/mountainvillage.obj"); bgtext = LoadSprite("models/mountain_text.png",1024,1024); //cube1 = newCube(vec3d(0,0,0),"Cubert"); //cube2 = newCube(vec3d(10,0,0),"Hobbes"); //cube1->body.velocity.x = 0.1; space = space_new(); space_set_steps(space,100); space_add_body(space,&cube1->body); space_add_body(space,&cube2->body); //my variables specMode = 0; numShips = 0; shipVel = 0; shipRot = 0; turretRot = 0; gunElev = 0; realTurrRot = 0; playerShip = spawnShip(space, vec3d(-10,0,0), 1); while (bGameLoopRunning) { updateAllShipPos(); for (i = 0; i < 100;i++) { space_do_step(space); } updateAllShipComp(); applyGrav(); if(specMode == 0) { cameraPosition.x = playerShip->hull->body.position.x; cameraPosition.y = (playerShip->hull->body.position.y + 5); cameraPosition.z = playerShip->hull->body.position.z; } while ( SDL_PollEvent(&e) ) { if (e.type == SDL_QUIT) { bGameLoopRunning = 0; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_ESCAPE) { bGameLoopRunning = 0; } else if (e.key.keysym.sym == SDLK_SPACE) { cameraPosition.z++; } else if (e.key.keysym.sym == SDLK_z) { cameraPosition.z--; } else if (e.key.keysym.sym == SDLK_w) { vec3d_add( cameraPosition, cameraPosition, vec3d( -sin(cameraRotation.z * DEGTORAD), cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_s) { vec3d_add( cameraPosition, cameraPosition, vec3d( sin(cameraRotation.z * DEGTORAD), -cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_d) { vec3d_add( cameraPosition, cameraPosition, vec3d( cos(cameraRotation.z * DEGTORAD), sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_a) { vec3d_add( cameraPosition, cameraPosition, vec3d( -cos(cameraRotation.z * DEGTORAD), -sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_LEFT) { cameraRotation.y -= 1; } else if (e.key.keysym.sym == SDLK_RIGHT) { cameraRotation.y += 1; } else if (e.key.keysym.sym == SDLK_UP) { cameraRotation.x += 1; } else if (e.key.keysym.sym == SDLK_DOWN) { cameraRotation.x -= 1; } else if (e.key.keysym.sym == SDLK_y && shipVel < 0.4) { shipVel += 0.1; } else if (e.key.keysym.sym == SDLK_h && shipVel > 0.05) { shipVel -= 0.1; } else if (e.key.keysym.sym == SDLK_j) { shipRot += 0.5; if(shipRot >= 360){shipRot -= 360;} } else if (e.key.keysym.sym == SDLK_g) { shipRot -= 0.5; if(shipRot < 0){shipRot += 360;} } else if (e.key.keysym.sym == SDLK_m && turretRot < 135) { turretRot += 1; } else if (e.key.keysym.sym == SDLK_b && turretRot > -135) { turretRot -= 1; } else if (e.key.keysym.sym == SDLK_o && gunElev < 50) { gunElev += 0.5; } else if (e.key.keysym.sym == SDLK_l && gunElev > -5) { gunElev -= 0.5; } else if (e.key.keysym.sym == SDLK_q) { if(specMode == 0){specMode = 1;} else {specMode = 0;} } else if (e.key.keysym.sym == SDLK_p) { fireBullet(space, playerShip->gun->body.position, realTurrRot, gunElev, 0.5, -1); } else if (e.key.keysym.sym == SDLK_x) { fireBullet(space, playerShip->hull->body.position, shipRot, 0, 0, -2); } else if (e.key.keysym.sym == SDLK_1) { startLevel(space, 1); } else if (e.key.keysym.sym == SDLK_2) { startLevel(space, 2); } else if (e.key.keysym.sym == SDLK_3) { startLevel(space, 3); } } } graphics3d_frame_begin(); glPushMatrix(); set_camera( cameraPosition, cameraRotation); entity_draw_all(); //updateAllShipModels(); obj_draw( bgobj, vec3d(0,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), bgtext ); if (r > 360)r -= 360; glPopMatrix(); /* drawing code above here! */ graphics3d_next_frame(); } return 0; }
int main(int argc, char *argv[]) { int i; float r = 0; int f = -15; int g = 0; int l = 0; int y = 0; int u = 15; int q = 0; int gamestate=0; int PlayerHP=15, Bosshealth=30, enemy1health=5, enemy2health=5, Bigtimer=600, CD; int SpawnLemon1=0, SpawnLemon2=0, SpawnLemon3=0, SpawnBigLemon=0, enemybullet=0; float Lemonx1=0, Lemonx2=0, Lemonx3=0, LemonxBig=0, enemybulletx=0; int Lemony1=0, Lemony2=0, Lemony3=0, LemonyBig=0, enemybullety=0; int a=0, b=0, c=0, d=0, count, Goomba_attack1=0, Goomba_attack2=0, Goomba_move1, Goomba_move2; Space *space; Entity *cube1,*cube2, *Actor; char bGameLoopRunning = 1; Vec3D Bosspos = {u, y, 2}; Vec3D enemy1pos = {5, 10, 2}; Vec3D enemy2pos = {5, -10, 2}; Vec3D cameraPosition = {0,0,70.3}; Vec3D cameraRotation = {0,0,360}; SDL_Event e; Obj *megaman,*boss, *mapp, *mape, *lemon, *BossHPBar, *PlayerHPBar, *Goomba; Sprite *megamantexture, *bosstexture, *maptexture1, *maptexture2, *lemontexture, *BosstextureHP, *PlayertextureHP, *Goombatexture; init_logger("gametest3d.log"); if (graphics3d_init(1024,768,1,"gametest3d",33) != 0) { return -1; } model_init(); obj_init(); entity_init(255); //load objects, models here, replace cube with megaman megaman = obj_load("models/MPU.obj"); //load his uv map "texture file" megamantexture = LoadSprite("models/MegaManBody1.png",1024,1024); PlayerHPBar = obj_load("models/cube.obj"); PlayertextureHP = NULL; boss = obj_load("models/Fireman.obj"); bosstexture = LoadSprite("models/FireManBody1.png",1024,1024); BossHPBar = obj_load("models/cube.obj"); BosstextureHP = NULL; Goomba = obj_load("models/goomba.obj"); Goombatexture = LoadSprite("models/goomba_tex.png",1024,1024); mapp = obj_load("models/MidtermMapSingle.obj"); maptexture1 = LoadSprite("models/PlayerTile(Red).png",1024,1024); mape = obj_load("models/MidtermMapSingle.obj"); maptexture2 = LoadSprite("models/BossTile(Blue).png",1024,1024); lemon = obj_load("models/cube.obj"); lemontexture = NULL;//LoadSprite("models/cube_text.png",1024,1024); while (bGameLoopRunning) { entity_think_all(); while ( SDL_PollEvent(&e) ) { if (e.type == SDL_QUIT) { bGameLoopRunning = 0; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_ESCAPE) { bGameLoopRunning = 0; } else if (e.key.keysym.sym == SDLK_x) { cameraPosition.z++; } else if (e.key.keysym.sym == SDLK_z) { cameraPosition.z--; } else if (e.key.keysym.sym == SDLK_h) { vec3d_add( cameraPosition, cameraPosition, vec3d( -sin(cameraRotation.z * DEGTORAD), cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_y) { vec3d_add( cameraPosition, cameraPosition, vec3d( sin(cameraRotation.z * DEGTORAD), -cos(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_j) { vec3d_add( cameraPosition, cameraPosition, vec3d( cos(cameraRotation.z * DEGTORAD), sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_g) { vec3d_add( cameraPosition, cameraPosition, vec3d( -cos(cameraRotation.z * DEGTORAD), -sin(cameraRotation.z * DEGTORAD), 0 )); } else if (e.key.keysym.sym == SDLK_d) { if(f >= -5) { f = -5; } else { f += 10; } } else if (e.key.keysym.sym == SDLK_a) { if(f <= -20) { f = -25; } else { f -= 10; } } else if (e.key.keysym.sym == SDLK_w) { if(g >= 5) { g = 10; } else { g += 10; } } else if (e.key.keysym.sym == SDLK_s) { g -= 10; if(g <= -5) { g = -10; } } else if (e.key.keysym.sym == SDLK_LEFT) { cameraRotation.z += 1; } else if (e.key.keysym.sym == SDLK_RIGHT) { cameraRotation.z -= 1; } else if (e.key.keysym.sym == SDLK_UP) { cameraRotation.x += 1; } else if (e.key.keysym.sym == SDLK_DOWN) { cameraRotation.x -= 1; } else if (e.key.keysym.sym == SDLK_SPACE) { CD = TIME + Bigtimer; } else if (e.key.keysym.sym == SDLK_n) { if (enemy1health <= 0 && enemy2health <= 0) { gamestate=1; } } else if (e.key.keysym.sym == SDLK_n) { if (enemy1health <= 0 && enemy2health <= 0) { gamestate=1; } } } else if (e.type == SDL_KEYUP) { if (e.key.keysym.sym == SDLK_SPACE) { if (TIME >= CD && SpawnBigLemon !=1) { SpawnBigLemon = 1; LemonxBig = f; LemonyBig = g; } else if (SpawnLemon1 != 1) { SpawnLemon1 = 1; Lemonx1 = f; Lemony1 = g; } else if (SpawnLemon2 != 1) { SpawnLemon2 = 1; Lemonx2 = f; Lemony2 = g; } else if (SpawnLemon3 != 1) { SpawnLemon3 = 1; Lemonx3 = f; Lemony3 = g; } } } } graphics3d_frame_begin(); glPushMatrix(); set_camera( cameraPosition, cameraRotation); //entity_draw_all(); if (PlayerHP > 0 ) { //Megaman obj_draw( megaman, vec3d(f, g, 2), vec3d(90,90,0), vec3d(0.5,0.5,0.5), vec4d(1,1,1,1), megamantexture ); //Megaman HP BAR obj_draw( PlayerHPBar, vec3d(-30+PlayerHP/(2),20,2), vec3d(90,-90,0), vec3d(.9,.9,PlayerHP/(2)), vec4d(0,1,0,1), PlayertextureHP ); } //Megaman Projectiles //Lemon1 if (SpawnLemon1 != 0) { obj_draw( lemon, vec3d(Lemonx1 + a*(.4), Lemony1, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); a++; if (Lemonx1 + a*(.4) >=30) { SpawnLemon1 = 0; a=0; } else if (Lemonx1 + a*(.4) == enemy1pos.x && Lemony1 == enemy1pos.y) { SpawnLemon1 = 0; a=0; enemy1health -= 1; //slog("Enemy Health %d",enemy1health); } else if (Lemonx1 + a*(.4) == enemy2pos.x && Lemony1 == enemy2pos.y) { SpawnLemon1 = 0; a=0; enemy2health -= 1; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx1 + a*(.4) == Bosspos.x && Lemony1 == Bosspos.y) { SpawnLemon1 = 0; a=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } //Lemon2 if (SpawnLemon2 != 0) { obj_draw( lemon, vec3d(Lemonx2 + b*(.4), Lemony2, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); b++; if (Lemonx2 + b*(.4) >=30) { SpawnLemon2 = 0; b=0; } else if (Lemonx2 + b*(.4) == enemy1pos.x && Lemony2 == enemy1pos.y) { SpawnLemon2 = 0; b=0; enemy1health -= 1; //slog("Enemy Health %d",enemy1health); } else if (Lemonx2 + b*(.4) == enemy2pos.x && Lemony2 == enemy2pos.y) { SpawnLemon2 = 0; b=0; enemy2health -= 1; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx2 + b*(.4) == Bosspos.x && Lemony2 == Bosspos.y) { SpawnLemon2 = 0; b=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } if (SpawnLemon3 != 0) { obj_draw( lemon, vec3d(Lemonx3 + c*(.4), Lemony3, 4), vec3d(90,90,0), vec3d(1,1,2), vec4d(.95,.89,0,1), lemontexture ); c++; //lemons fly off staege if (Lemonx3 + c*(.4) >=30) { SpawnLemon3 = 0; c=0; } //lemons collide with enemies else if (Lemonx3 + c*(.4) == enemy1pos.x && Lemony3 == enemy1pos.y) { SpawnLemon3 = 0; c=0; enemy1health -= 1; slog("Enemy Health %d",enemy1health); } else if (Lemonx3 + c*(.4) == enemy2pos.x && Lemony3 == enemy2pos.y) { SpawnLemon3 = 0; c=0; enemy2health -= 1; slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && Lemonx3 + c*(.4) == Bosspos.x && Lemony3 == Bosspos.y) { SpawnLemon3 = 0; c=0; Bosshealth -= 1; //slog("Boss Health %d",Bosshealth); } } if (SpawnBigLemon != 0) { obj_draw( lemon, vec3d(LemonxBig + d*(.4), LemonyBig, 4), vec3d(90,90,0), vec3d(2,2,4), vec4d(.9,.3,.1,1), lemontexture ); d++; if (LemonxBig + d*(.4) >=30) { SpawnBigLemon = 0; d=0; } else if (LemonxBig + d*(.4) == enemy1pos.x && LemonyBig == enemy1pos.y) { SpawnBigLemon = 0; d=0; enemy1health -= 5; //slog("Enemy Health %d",enemy1health); } else if (LemonxBig + d*(.4) == enemy2pos.x && LemonyBig == enemy2pos.y) { SpawnBigLemon = 0; d=0; enemy2health -= 5; //slog("Enemy Health %d",enemy2health); } else if (gamestate == 1 && LemonxBig + d*(.4) == Bosspos.x && LemonyBig == Bosspos.y) { SpawnBigLemon = 0; d=0; Bosshealth -= 5; slog("Boss Health %d",Bosshealth); } } //MAP obj_draw( mapp, vec3d(-15,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), maptexture1 ); obj_draw( mape, vec3d(15,0,2), vec3d(90,90,0), vec3d(5,5,5), vec4d(1,1,1,1), maptexture2 ); //Enemies if (gamestate == 0) { if (enemy1health > 0) { //enemy_move(enemypos.x,enemypos.y, &enemypos); //enemy_attack1(Goomba_attack1, &enemy1pos); obj_draw( Goomba, vec3d(enemy1pos.x,enemy1pos.y,2), vec3d(90,-90,0), vec3d(0.1,0.1,0.1), vec4d(1,1,1,1), Goombatexture ); if (Goomba_attack1 == 0) { Goomba_attack1 = rand_ranged( 1, 5); //start to (end - 1) if (Goomba_attack1 == 2) { Goomba_attack1 = 1; } }; if (Goomba_attack1 == 1) { enemy1pos.x -=.1; if (enemy1pos.x <= -30) { Goomba_attack1 = 0; enemy1pos.x = 5; } } } else { enemy1pos.x = 50; enemy1pos.y = 50; } if (enemy2health > 0) { //enemy_move(enemypos.x,enemypos.y, &enemypos); //enemy_attack2(Goomba_attack2, &enemy2pos); obj_draw( Goomba, vec3d(enemy2pos.x,enemy2pos.y,2), vec3d(90,-90,0), vec3d(0.1,0.1,0.1), vec4d(1,1,1,1), Goombatexture ); //bottom Goomba won't attack if (Goomba_attack2 == 0) { Goomba_attack2 = rand_ranged( 1, 5); //start to (end - 1) if (Goomba_attack2 == 2) { Goomba_attack2 = 1; } }; if (Goomba_attack2 == 1) { enemy2pos.x -=.1; if (enemy2pos.x <= -30) { Goomba_attack2 = 0; enemy2pos.x = 5; } } } else { enemy2pos.x = 50; enemy2pos.y = 50; } } if (gamestate != 0) { if (Bosshealth > 0) { Boss_move(Bosspos.x,Bosspos.y, &Bosspos); //Fire man obj_draw( boss, vec3d(Bosspos.x,Bosspos.y,2), vec3d(90,-90,0), vec3d(0.5,0.5,0.5), vec4d(1,1,1,1), bosstexture ); obj_draw( BossHPBar, vec3d(30-Bosshealth/(2.5),20,2), vec3d(90,-90,0), vec3d(.9,.9,Bosshealth/(2.5)), vec4d(1,0,0,1), BosstextureHP ); } else { obj_free(boss); Bosspos.x = 50; Bosspos.y = 50; slog("You WIN!"); } } if (r > 360)r -= 360; glPopMatrix(); /* drawing code above here! */ graphics3d_next_frame(); } return 0; }
void obj_code (uint4 src_lines, uint4 checksum) { rhdtyp rhead; mline *mlx, *mly; var_tabent *vptr; int4 lnr_pad_len; assert(!run_time); obj_init(); /* Define the routine name global symbol. */ define_symbol(GTM_MODULE_DEF_PSECT, (mstr *)&int_module_name, 0); memset(&rhead, 0, SIZEOF(rhead)); alloc_reg(); jmp_opto(); curr_addr = SIZEOF(rhdtyp); cg_phase = CGP_APPROX_ADDR; cg_phase_last = CGP_NOSTATE; code_gen(); code_size = curr_addr; cg_phase = CGP_ADDR_OPT; shrink_jmps(); comp_lits(&rhead); if ((cmd_qlf.qlf & CQ_MACHINE_CODE)) { cg_phase = CGP_ASSEMBLY; code_gen(); } if (!(cmd_qlf.qlf & CQ_OBJECT)) return; rhead.ptext_ptr = SIZEOF(rhead); rhead.checksum = checksum; rhead.vartab_ptr = code_size; rhead.vartab_len = mvmax; code_size += mvmax * SIZEOF(var_tabent); rhead.labtab_ptr = code_size; rhead.labtab_len = mlmax; code_size += mlmax * SIZEOF(lab_tabent); rhead.lnrtab_ptr = code_size; rhead.lnrtab_len = src_lines; rhead.compiler_qlf = cmd_qlf.qlf; rhead.temp_mvals = sa_temps[TVAL_REF]; rhead.temp_size = sa_temps_offset[TCAD_REF]; code_size += src_lines * SIZEOF(int4); lnr_pad_len = PADLEN(code_size, SECTION_ALIGN_BOUNDARY); code_size += lnr_pad_len; create_object_file(&rhead); cg_phase = CGP_MACHINE; code_gen(); /* Variable table: */ vptr = (var_tabent *)mcalloc(mvmax * SIZEOF(var_tabent)); if (mvartab) walktree(mvartab, cg_var, (char *)&vptr); else assert(0 == mvmax); emit_immed((char *)vptr, mvmax * SIZEOF(var_tabent)); /* Label table: */ if (mlabtab) walktree((mvar *)mlabtab, cg_lab, (char *)rhead.lnrtab_ptr); else assert(0 == mlmax); /* External entry definitions: */ emit_immed((char *)&(mline_root.externalentry->rtaddr), SIZEOF(mline_root.externalentry->rtaddr)); /* line 0 */ for (mlx = mline_root.child; mlx; mlx = mly) { if (mlx->table) emit_immed((char *)&(mlx->externalentry->rtaddr), SIZEOF(mlx->externalentry->rtaddr)); if (0 == (mly = mlx->child)) /* note assignment */ if (0 == (mly = mlx->sibling)) /* note assignment */ for (mly = mlx; ; ) { if (0 == (mly = mly->parent)) /* note assignment */ break; if (mly->sibling) { mly = mly->sibling; break; } } } if (0 != lnr_pad_len) /* emit padding so literal text pool starts on proper boundary */ emit_immed(PADCHARS, lnr_pad_len); #if !defined(__MVS__) && !defined(__s390__) /* assert not valid for instructions on OS390 */ assert(code_size == psect_use_tab[GTM_CODE]); #endif emit_literals(); close_object_file(); }
/* create the mempool */ struct rte_mempool * rte_mempool_create(const char *name, unsigned n, unsigned elt_size, unsigned cache_size, unsigned private_data_size, rte_mempool_ctor_t *mp_init, void *mp_init_arg, rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg, int socket_id, unsigned flags) { char mz_name[RTE_MEMZONE_NAMESIZE]; char rg_name[RTE_RING_NAMESIZE]; struct rte_mempool *mp = NULL; struct rte_ring *r; const struct rte_memzone *mz; size_t mempool_size, total_elt_size; int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY; int rg_flags = 0; uint32_t header_size, trailer_size; unsigned i; void *obj; /* compilation-time checks */ RTE_BUILD_BUG_ON((sizeof(struct rte_mempool) & CACHE_LINE_MASK) != 0); #if RTE_MEMPOOL_CACHE_MAX_SIZE > 0 RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_cache) & CACHE_LINE_MASK) != 0); RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, local_cache) & CACHE_LINE_MASK) != 0); #endif #ifdef RTE_LIBRTE_MEMPOOL_DEBUG RTE_BUILD_BUG_ON((sizeof(struct rte_mempool_debug_stats) & CACHE_LINE_MASK) != 0); RTE_BUILD_BUG_ON((offsetof(struct rte_mempool, stats) & CACHE_LINE_MASK) != 0); #endif /* check that we have an initialised tail queue */ if (RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_MEMPOOL, rte_mempool_list) == NULL) { rte_errno = E_RTE_NO_TAILQ; return NULL; } /* asked cache too big */ if (cache_size > RTE_MEMPOOL_CACHE_MAX_SIZE){ rte_errno = EINVAL; return NULL; } /* "no cache align" imply "no spread" */ if (flags & MEMPOOL_F_NO_CACHE_ALIGN) flags |= MEMPOOL_F_NO_SPREAD; /* ring flags */ if (flags & MEMPOOL_F_SP_PUT) rg_flags |= RING_F_SP_ENQ; if (flags & MEMPOOL_F_SC_GET) rg_flags |= RING_F_SC_DEQ; rte_rwlock_write_lock(RTE_EAL_MEMPOOL_RWLOCK); /* allocate the ring that will be used to store objects */ /* Ring functions will return appropriate errors if we are * running as a secondary process etc., so no checks made * in this function for that condition */ rte_snprintf(rg_name, sizeof(rg_name), "MP_%s", name); r = rte_ring_create(rg_name, rte_align32pow2(n+1), socket_id, rg_flags); if (r == NULL) goto exit; /* * In header, we have at least the pointer to the pool, and * optionaly a 64 bits cookie. */ header_size = 0; header_size += sizeof(struct rte_mempool *); /* ptr to pool */ #ifdef RTE_LIBRTE_MEMPOOL_DEBUG header_size += sizeof(uint64_t); /* cookie */ #endif if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) header_size = (header_size + CACHE_LINE_MASK) & (~CACHE_LINE_MASK); /* trailer contains the cookie in debug mode */ trailer_size = 0; #ifdef RTE_LIBRTE_MEMPOOL_DEBUG trailer_size += sizeof(uint64_t); /* cookie */ #endif /* element size is 8 bytes-aligned at least */ elt_size = (elt_size + 7) & (~7); /* expand trailer to next cache line */ if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) { total_elt_size = header_size + elt_size + trailer_size; trailer_size += ((CACHE_LINE_SIZE - (total_elt_size & CACHE_LINE_MASK)) & CACHE_LINE_MASK); } /* * increase trailer to add padding between objects in order to * spread them accross memory channels/ranks */ if ((flags & MEMPOOL_F_NO_SPREAD) == 0) { unsigned new_size; new_size = optimize_object_size(header_size + elt_size + trailer_size); trailer_size = new_size - header_size - elt_size; } /* this is the size of an object, including header and trailer */ total_elt_size = header_size + elt_size + trailer_size; /* reserve a memory zone for this mempool: private data is * cache-aligned */ private_data_size = (private_data_size + CACHE_LINE_MASK) & (~CACHE_LINE_MASK); mempool_size = total_elt_size * n + sizeof(struct rte_mempool) + private_data_size; rte_snprintf(mz_name, sizeof(mz_name), "MP_%s", name); mz = rte_memzone_reserve(mz_name, mempool_size, socket_id, mz_flags); /* * no more memory: in this case we loose previously reserved * space for the as we cannot free it */ if (mz == NULL) goto exit; /* init the mempool structure */ mp = mz->addr; memset(mp, 0, sizeof(*mp)); rte_snprintf(mp->name, sizeof(mp->name), "%s", name); mp->phys_addr = mz->phys_addr; mp->ring = r; mp->size = n; mp->flags = flags; mp->elt_size = elt_size; mp->header_size = header_size; mp->trailer_size = trailer_size; mp->cache_size = cache_size; mp->cache_flushthresh = (uint32_t)(cache_size * CACHE_FLUSHTHRESH_MULTIPLIER); mp->private_data_size = private_data_size; /* call the initializer */ if (mp_init) mp_init(mp, mp_init_arg); /* fill the headers and trailers, and add objects in ring */ obj = (char *)mp + sizeof(struct rte_mempool) + private_data_size; for (i = 0; i < n; i++) { struct rte_mempool **mpp; obj = (char *)obj + header_size; /* set mempool ptr in header */ mpp = __mempool_from_obj(obj); *mpp = mp; #ifdef RTE_LIBRTE_MEMPOOL_DEBUG __mempool_write_header_cookie(obj, 1); __mempool_write_trailer_cookie(obj); #endif /* call the initializer */ if (obj_init) obj_init(mp, obj_init_arg, obj, i); /* enqueue in ring */ rte_ring_sp_enqueue(mp->ring, obj); obj = (char *)obj + elt_size + trailer_size; } RTE_EAL_TAILQ_INSERT_TAIL(RTE_TAILQ_MEMPOOL, rte_mempool_list, mp); exit: rte_rwlock_write_unlock(RTE_EAL_MEMPOOL_RWLOCK); return mp; }
void dht_delete (dht_t * du) { struct dht_object *obj; obj = NULL; if (du->inifile != NULL) { FILE *fp; char temp[8192]; unsigned int len; struct string str; int ret; obj = obj_init (OBJ_TYPE_MAP); if (obj == NULL) { ttdht_err ("create dht object error.\n"); goto ret; } dr_store_cache (du->router, obj); fp = fopen (du->inifile, "wb"); if (fp == NULL) { ttdht_err ("Open bootstrap ini file error.\n"); goto ret; } string_set2 (&str, temp, sizeof temp); ret = object_to_buf (obj, &str); if (ret < 0) { ttdht_err ("Create dht object to buffer error.\n"); fclose (fp); goto ret; } len = str.data - temp; fwrite (temp, len, 1, fp); fclose (fp); } ret: if (du->inifile != NULL) { free (du->inifile); } if (obj != NULL) { obj_cleanup (obj); } dr_stop (du->router); dr_cleanup (du->router); free (du); }
void init(void) { int i = 0; NODE *iproc = NIL, *pname = NIL, *cnd = NIL; FILE *fp; char linebuf[100]; char *sugar; static char sugarlib[100], sugarhelp[100], sugarcsls[100]; #ifdef WIN32 HKEY regKey1, regKey2, regKey3; int got_hklm = 0; char buf[200]; unsigned long int bufsiz; char *envp; #endif readstream = stdin; writestream = stdout; loadstream = stdin; fill_reserve_tank(); oldyoungs = Unbound = newnode(PUNBOUND); #ifdef HAVE_SRANDOM srandom((int)time((time_t *)NULL)); #else srand((int)time((time_t *)NULL)); #endif #ifdef ecma for (i=0; i<128; i++) ecma_array[i] = i; for (i=0; i<ecma_size; i++) ecma_array[(int)special_chars[i]] = ecma_begin+i; i = 0; #endif sugar = getenv("SUGAR_BUNDLE_PATH"); if (sugar != NULL) { strcpy(sugarlib,sugar); strcat(sugarlib,"/logolib"); logolib = sugarlib; fp = fopen(logolib,"r"); if (fp == NULL) goto nosugar; fclose(fp); chdir(getenv("SUGAR_ACTIVITY_ROOT")); chdir("data"); strcpy(sugarhelp,sugar); strcat(sugarhelp,"/helpfiles"); helpfiles = sugarhelp; strcpy(sugarcsls,sugar); strcat(sugarcsls,"/csls"); csls = sugarcsls; } else { nosugar: logolib = getenv("LOGOLIB"); helpfiles = getenv("LOGOHELP"); csls = getenv("CSLS"); } editor = getenv("EDITOR"); #ifdef WIN32 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ, ®Key1) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey1, "UCB", 0, KEY_READ, ®Key2) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey2, "UCBLogo", 0, KEY_READ, ®Key3) == ERROR_SUCCESS) { got_hklm = 1; /* logolib = getenv("LOGOLIB"); */ if (logolib == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "LOGOLIB", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { logolib = malloc(bufsiz); strcpy(logolib, buf); } } /* helpfiles = getenv("LOGOHELP"); */ if (helpfiles == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "HELPFILE", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { helpfiles = malloc(bufsiz); strcpy(helpfiles, buf); } } /* csls = getenv("CSLS"); */ if (csls == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "CSLS", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { csls = malloc(bufsiz); strcpy(csls, buf); } } /* editor = getenv("EDITOR"); */ if (editor == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "EDITOR", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { editor = malloc(bufsiz); strcpy(editor, buf); } } RegCloseKey(regKey3); } RegCloseKey(regKey2); } RegCloseKey(regKey1); } if (!got_hklm && RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, ®Key1) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey1, "UCB", 0, KEY_READ, ®Key2) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey2, "UCBLogo", 0, KEY_READ, ®Key3) == ERROR_SUCCESS) { got_hklm = 1; /* logolib = getenv("LOGOLIB"); */ if (logolib == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "LOGOLIB", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { logolib = malloc(bufsiz); strcpy(logolib, buf); } } /* helpfiles = getenv("LOGOHELP"); */ if (helpfiles == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "HELPFILE", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { helpfiles = malloc(bufsiz); strcpy(helpfiles, buf); } } /* csls = getenv("CSLS"); */ if (csls == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "CSLS", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { csls = malloc(bufsiz); strcpy(csls, buf); } } /* editor = getenv("EDITOR"); */ if (editor == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "EDITOR", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { editor = malloc(bufsiz); strcpy(editor, buf); } } RegCloseKey(regKey3); } RegCloseKey(regKey2); } RegCloseKey(regKey1); } #endif if (logolib == NULL) logolib = libloc; if (helpfiles == NULL) helpfiles = helploc; if (csls == NULL) csls = cslsloc; #ifdef HAVE_WX #ifndef __WXMSW__ // have to do this because we don't have __WXMAC__ in C const char* wxMacGetCslsloc(); const char* wxMacGetHelploc(); const char* wxMacGetLibloc(); char* newlib; char* newcsls; char* newhelp; // check if we are running wxMac newlib = wxMacGetLibloc(); if(newlib) logolib=newlib; //if (helpfiles == NULL) helpfiles = wxMacGetHelploc(); newcsls = wxMacGetCslsloc(); if(newcsls) csls = newcsls; newhelp = wxMacGetHelploc(); if(newhelp) helpfiles = newhelp; #endif #endif #ifdef unix if (editor == NULL) editor = "emacs"; #else if (editor == NULL) editor = "jove"; #endif editorname = strrchr(editor, (int)'/'); if (editorname == NULL) editorname = strrchr(editor, (int)'\\'); #ifdef WIN32 if (editorname == NULL) { putenv("DESCRIBE=CMDS.DOC"); putenv("JOVERC=JOVE.RC"); } else { bufsiz = sprintf(buf, "DESCRIBE=%.*s\\CMDS.DOC", editorname-editor, editor); envp = malloc(bufsiz+1); strcpy(envp, buf); putenv(envp); bufsiz = sprintf(buf, "JOVERC=%.*s\\JOVE.RC", editorname-editor, editor); envp = malloc(bufsiz+1); strcpy(envp, buf); putenv(envp); } #endif if (editorname == NULL) editorname = strrchr(editor, (int)':'); editorname = (editorname ? editorname+1 : editor); tempdir = getenv("TEMP"); if (tempdir == NULL) tempdir = temploc; while (prims[i].name) { if (prims[i].priority == MACRO_PRIORITY) iproc = newnode(MACRO); else if (prims[i].priority <= TAIL_PRIORITY) iproc = newnode(TAILFORM); else if ((prims[i].priority & ~4) == (PREFIX_PRIORITY & ~4)) iproc = newnode(PRIM); /* incl. -- */ else iproc = newnode(INFIX); setprimpri(iproc, prims[i].priority); setprimfun(iproc, prims[i].prim); setprimdflt(iproc, prims[i].defargs); setprimmax(iproc, prims[i].maxargs); setprimmin(iproc, prims[i].minargs); pname = make_static_strnode(prims[i].name); cnd = make_instance(pname, pname); setprocnode__caseobj(cnd, iproc); if (nodetype(iproc) == MACRO) setflag__caseobj(cnd, PROC_MACRO); if (prims[i].minargs < 0) setflag__caseobj(cnd, PROC_SPECFORM); setflag__caseobj(cnd, PERMANENT); i++; } Left_Paren = intern_p(make_static_strnode("(")); Right_Paren = intern_p(make_static_strnode(")")); Minus_Sign = intern_p(make_static_strnode("-")); Minus_Tight = intern_p(make_static_strnode("--")); Query = intern_p(make_static_strnode("?")); Null_Word = intern_p(make_static_strnode("\0")); Redefp = intern_p(make_static_strnode("redefp")); Caseignoredp = intern_p(make_static_strnode("caseignoredp")); Erract = intern_p(make_static_strnode("erract")); Buttonact = intern_p(make_static_strnode("buttonact")); Keyact = intern_p(make_static_strnode("Keyact")); Printdepthlimit = intern_p(make_static_strnode("printdepthlimit")); Printwidthlimit = intern_p(make_static_strnode("printwidthlimit")); LoadNoisily = intern_p(make_static_strnode("loadnoisily")); AllowGetSet = intern_p(make_static_strnode("allowgetset")); Fullprintp = intern_p(make_static_strnode("fullprintp")); UnburyOnEdit = intern_p(make_static_strnode("unburyonedit")); UseAlternateNames = intern_p(make_static_strnode("usealternatenames")); Make = intern_p(make_static_strnode("make")); Listvalue = cons(intern_p(make_static_strnode("value")),NIL); Dotsvalue = make_colon(car(Listvalue)); Pause = intern_p(make_static_strnode("pause")); Startup = intern_p(make_static_strnode("startup")); Startuplg = intern_p(make_static_strnode("startup.lg")); LogoVersion = intern_p(make_static_strnode("logoversion")); LogoPlatform = intern_p(make_static_strnode("logoplatform")); LogoLogo = intern_p(make_static_strnode("logo-logo")); CommandLine = intern_p(make_static_strnode("command.line")); setflag__caseobj(CommandLine, VAL_BURIED); the_generation = cons(NIL, NIL); Not_Enough_Node = cons(NIL, NIL); sprintf(linebuf,"%s%sMessages", logolib, separator); fp = fopen("Messages", "r"); if (fp == NULL) fp = fopen(linebuf, "r"); if (fp == NULL) fp = fopen("C:\\cygwin\\usr\\local\\lib\\logo\\logolib\\Messages", "r"); if (fp == NULL) { printf("Error -- Can't read Messages file.\n"); exit(1); } for (i=0; i<(MAX_MESSAGE+NUM_WORDS); i++) { while (fgets(linebuf, 99, fp) != NULL && linebuf[0] == ';') ; linebuf[strlen(linebuf)-1] = '\0'; message_texts[i] = (char *) malloc(1+strlen(linebuf)); strcpy(message_texts[i], linebuf); } fclose(fp); #define wd_copy(x) \ translations[Name_ ## x].English = intern_p(make_static_strnode(#x)); \ translations[Name_ ## x].Alt = \ intern_p(make_static_strnode(message_texts[MAX_MESSAGE + Name_ ## x])); do_trans(wd_copy); translations[Name_macro].English = intern_p(make_static_strnode(".macro")); #define True translations[Name_true].English #define False translations[Name_false].English setvalnode__caseobj(Caseignoredp, True); setflag__caseobj(Caseignoredp, VAL_BURIED); setvalnode__caseobj(AllowGetSet, True); setflag__caseobj(AllowGetSet, VAL_BURIED); setvalnode__caseobj(Fullprintp, False); setflag__caseobj(Fullprintp, VAL_BURIED); setvalnode__caseobj(UnburyOnEdit, True); setflag__caseobj(UnburyOnEdit, VAL_BURIED); setvalnode__caseobj(UseAlternateNames, False); setflag__caseobj(UseAlternateNames, VAL_BURIED); setvalnode__caseobj(LogoPlatform, make_static_strnode(LogoPlatformName)); setflag__caseobj(LogoPlatform, VAL_BURIED); user_repcount = -1; ift_iff_flag = -1; num_saved_nodes = (NODE **)(&(val_status)) - (NODE **)(&(proc)); Regs_Node = newnode(STACK); Regs_Node->n_car = (NODE *)®s; //hist_inptr = hist_outptr = cmdHistory; #ifdef OBJECTS obj_init(); #endif /* Uncomment these to print debugging messages right away! */ /* setvalnode__caseobj(Redefp, True); setflag__caseobj(Redefp, VAL_BURIED); */ }