void drawMap(float x,float y,float z) { entity *testmap; testmap = newentity(); testmap->model = LoadModel("models/buildi.obj", 0,20.0f); if(testmap->model != NULL) testmap->shown = 1; else testmap->shown = 0; testmap->texture = LoadModelTexture("images/build.png",2048,2048); testmap->self = testmap; testmap->shown = 1; testmap->alpha = 255; testmap->sprite_model = 2; testmap->scale.x = 1.0f; testmap->scale.y = 1.0f; testmap->scale.z = 1.0f; testmap->s.x = x; testmap->s.y = y; testmap->s.z = z; testmap->frame=0; testmap->totalframes=10; testmap->keyframe=0; testmap->nextkeyframe=1; }
int parse_url_entity(xmlDocPtr *doc, xmlNode *node, entity **ent, status *st){ xmlNode *url_attr = node->children; char *url = NULL; while(url_attr){ if(!xmlStrcmp(url_attr->name,(const xmlChar *)"url")){ url = xmlNodeListGetString(*doc, url_attr->xmlChildrenNode, 1); } url_attr = url_attr->next; } if(!url) return -1; *ent = newentity(); (*ent)->type = ENTITY_TYPE_URL; (*ent)->data = NULL; int start = atoi((char *)xmlGetProp(node,"start")); int end = atoi((char *)xmlGetProp(node,"end")); (*ent)->text = malloc((end-start+1)*sizeof(wchar_t)); memcpy((*ent)->text,st->wtext+start,(end-start)*sizeof(wchar_t)); (*ent)->text[end-start] = '\0'; (*ent)->start = start; (*ent)->end = end; return 0; }
int parse_mention_entity(xmlDocPtr *doc, xmlNode *node, entity **ent, status *st){ user *usr = NULL; xmlNode *mention_attr = node->children; while(mention_attr){ if(!xmlStrcmp(mention_attr->name,(const xmlChar *)"id")){ char *id = xmlNodeListGetString(*doc, mention_attr->xmlChildrenNode, 1); if(!id) break; /* pthread_mutex_lock(&user_map_mutex); usr = g_hash_table_lookup(user_map,id); pthread_mutex_unlock(&user_map_mutex); */ if(!usr){ usr = newuser(); usr->id = strdup(id); /* pthread_mutex_lock(&user_map_mutex); g_hash_table_insert(user_map,usr->id,usr); pthread_mutex_unlock(&user_map_mutex); */ } } else if(!xmlStrcmp(mention_attr->name,(const xmlChar *)"screen_name")){ if(!usr) break; if(!(usr->screen_name)){ char *screen_name = xmlNodeListGetString(*doc, mention_attr->xmlChildrenNode, 1); usr->screen_name = strdup(screen_name); } } else if(!xmlStrcmp(mention_attr->name,(const xmlChar *)"name")){ if(!usr) break; if(!(usr->name)){ char *name = xmlNodeListGetString(*doc, mention_attr->xmlChildrenNode, 1); usr->name = strdup(name); } } mention_attr = mention_attr->next; } if(!usr) return -1; *ent = newentity(); (*ent)->type = ENTITY_TYPE_MENTION; (*ent)->data = usr; int start = atoi((char *)xmlGetProp(node,"start")); int end = atoi((char *)xmlGetProp(node,"end")); (*ent)->text = malloc((end-start+1)*sizeof(wchar_t)); memcpy((*ent)->text,st->wtext+start,(end-start)*sizeof(wchar_t)); (*ent)->text[end-start] = '\0'; (*ent)->start = start; (*ent)->end = end; return 0; }
void spawnPlayer(float x,float y,float z) { entity *player; player = newentity(); player->model = LoadModel(playerModel, 3,playerModelScale); if(player->model != NULL) player->shown = 1; else player->shown = 0; player->shaderTexture = loadShader("Shader.txt"); player->self = player; player->sprite_model = 7; SetupTangentSpace(player->model); player->scale.x = 1.0f; player->scale.y = 1.0f; player->scale.z = 1.0f; player->modelColor[0] = playerColor.x; player->modelColor[1] = playerColor.y; player->modelColor[2] = playerColor.z; player->modelColor[3] = 1.0f; player->s.x = x; player->s.y = y; player->s.z = z; player->think=playerThink; player->update=playerupdate; player->touch=playertouch; player->frame=0; player->totalframes=10; player->keyframe=0; player->nextkeyframe=0; player->rotation.x=0.0f; player->rotation.y=0.0f; player->rotation.z=0.0f; player->solid=1; player->type=PLAYER; player->targetType = ENEMY; player->health=1; player->state = IDLE; player->box.w = 1; player->box.h = 1; player->box.d = 1; player->deadcool=60; player->lives = playerlives; player->NextThink=0; player->bigcooldown=0; score= 0; }
void spawnenemyBullet(float x,float y,float z, float dir) { entity *bullet; bullet = newentity(); bullet->model = LoadModel("models/ebullet.obj", 0,3.0f); if(bullet->model != NULL) bullet->shown = 1; else bullet->shown = 0; bullet->shaderTexture = loadShader("Shader.txt"); bullet->self = bullet; bullet->sprite_model = 6; bullet->scale.x = 1.0f; bullet->scale.y = 1.0f; bullet->scale.z = 1.0f; bullet->modelColor[0] = 1.0f; bullet->modelColor[1] = 0.0f; bullet->modelColor[2] = 0.0f; bullet->modelColor[3] = 0.8f; bullet->rotation.x=0.0f; bullet->rotation.y=0.0f; bullet->rotation.z=0.0f; bullet->s.x = x; bullet->s.y = y; bullet->s.z = z; bullet->v.y = dir; bullet->think=enemybulletThink; bullet->touch=ebullettouch; bullet->frame=0; bullet->totalframes=10; bullet->keyframe=0; bullet->nextkeyframe=0; bullet->solid = 1; bullet->health = 1; bullet->state = 1; bullet->type = EBULLET; bullet->targetType2 =-1; bullet->targetType = PLAYER; bullet->box.x = bullet->model->center[0]; bullet->box.y = bullet->model->center[1]; bullet->box.z = bullet->model->center[2]; bullet->box.w = bullet->model->dimensions[0]; bullet->box.h = bullet->model->dimensions[1]; bullet->box.d = bullet->model->dimensions[2]; }
void spawnEnemy1(float x,float y,float z) { entity *player; player = newentity(); player->model = LoadModel(enemy1model, 0,enemy1modelScale); if(player->model != NULL) player->shown = 1; else player->shown = 0; player->shaderTexture = loadShader("Shader.txt"); player->self = player; player->sprite_model = 6; player->scale.x = 1.0f; player->scale.y = 1.0f; player->scale.z = 1.0f; player->modelColor[0] = enemy1Color.x; player->modelColor[1] = enemy1Color.y; player->modelColor[2] = enemy1Color.z; player->modelColor[3] = 1.0f; player->rotation.z = 180.0f; player->s.x = x; player->s.y = y; player->s.z = z; player->think=enemy1Think; player->ThinkRate=0; player->frame=0; player->totalframes=200; player->keyframe=1; player->nextkeyframe=2; player->health=enemy1health; player->rotation.x=0.0f; player->rotation.y=0.0f; player->solid = 1; player->type= ENEMY; player->state = -1; player->state2=0; player->cooldown=0; player->box.x = player->model->center[0]; player->box.y = player->model->center[1]; player->box.z = player->model->center[2]; player->box.w = player->model->dimensions[0]; player->box.h = player->model->dimensions[1]; player->box.d = player->model->dimensions[2]; }
void SpawnPlayer(float x,float y,float z) { entity *testmap; testmap = newentity(); testmap->model = LoadModel("models/ship.obj", 0,0.4f); if(testmap->model != NULL) testmap->shown = 1; else testmap->shown = 0; testmap->texture = LoadModelTexture("models/ship.png",256,256); testmap->self = testmap; testmap->shown = 1; testmap->alpha = 255; testmap->sprite_model = 2; testmap->scale.x = 1.0f; testmap->scale.y = 1.0f; testmap->scale.z = 1.0f; testmap->s.x = x; testmap->s.y = y; testmap->s.z = z; testmap->v.x = 1; testmap->box.x = testmap->model->center[0]; testmap->box.y = testmap->model->center[1]; testmap->box.z = testmap->model->center[2]; testmap->box.w = testmap->model->dimensions[0]; testmap->box.h = testmap->model->dimensions[1]; testmap->box.d = testmap->model->dimensions[2]; testmap->state=0; testmap->think = tileThink; testmap->touch = PlayerTouch; testmap->frame=0; testmap->health=1; testmap->solid=1; testmap->totalframes=10; testmap->keyframe=0; testmap->nextkeyframe=1; playdead=0; }
void SpawnMine(float x,float y,float z, float vx, float vy, float vz, float side) { entity *testmap; testmap = newentity(); testmap->model = LoadModel("models/mine.obj", 0,1.0f); if(testmap->model != NULL) testmap->shown = 1; else testmap->shown = 0; testmap->texture = LoadModelTexture("models/mine.png",256,256); testmap->self = testmap; testmap->shown = 1; testmap->alpha = 255; testmap->sprite_model = 4; testmap->scale.x = 1.0f; testmap->scale.y = 1.0f; testmap->scale.z = 1.0f; testmap->s.x = x; testmap->s.y = y; testmap->s.z = z; testmap->v.x = vx; testmap->v.y = vy; testmap->v.z = vz; testmap->state=side; testmap->box.x = testmap->model->center[0]; testmap->box.y = testmap->model->center[1]; testmap->box.z = testmap->model->center[2]; testmap->box.w = testmap->model->dimensions[0]; testmap->box.h = testmap->model->dimensions[1]; testmap->box.d = testmap->model->dimensions[2]; testmap->think = mineThink; testmap->frame=0; testmap->solid=1; testmap->totalframes=10; testmap->keyframe=0; testmap->nextkeyframe=1; }
int parse_hashtag_entity(xmlDocPtr *doc, xmlNode *node, entity **ent, status *st){ xmlNode *hashtag_attr = node->children; while(hashtag_attr){ if(!xmlStrcmp(hashtag_attr->name,(const xmlChar *)"text")){ char *hashtagstr = xmlNodeListGetString(*doc, hashtag_attr->xmlChildrenNode, 1); } hashtag_attr = hashtag_attr->next; } *ent = newentity(); (*ent)->type = ENTITY_TYPE_HASHTAG; (*ent)->data = NULL; int start = atoi((char *)xmlGetProp(node,"start")); int end = atoi((char *)xmlGetProp(node,"end")); (*ent)->text = malloc((end-start+1)*sizeof(wchar_t)); memcpy((*ent)->text,st->wtext+start,(end-start)*sizeof(wchar_t)); (*ent)->text[end-start] = '\0'; (*ent)->start = start; (*ent)->end = end; return 0; }
void playergraphic(float x,float y,float z) { entity *player; player = newentity(); player->model = LoadModel(playerModel, 3,playerModelScale); if(player->model != NULL) player->shown = 1; else player->shown = 0; player->shaderTexture = loadShader("Shader.txt"); player->self = player; player->sprite_model = 7; player->scale.x = 8.0f; player->scale.y = 8.0f; player->scale.z = 8.0f; player->modelColor[0] = playerColor.x; player->modelColor[1] = playerColor.y; player->modelColor[2] = playerColor.z; player->modelColor[3] = 1.0f; player->s.x = x; player->s.y = y; player->s.z = z; player->think=graplayerupdate; player->frame=0; player->totalframes=10; player->keyframe=0; player->nextkeyframe=0; player->rotation.x=0.0f; player->rotation.y=0.0f; player->rotation.z=0.0f; }
int parse_status_json(json_t *status_root, status **status_ptr){ json_t *idstr = json_object_get(status_root, "id_str"); if(!json_is_string(idstr)) return -1; json_t *textstr = json_object_get(status_root, "text"); if(!json_is_string(textstr)) return -1; status *st = newstatus(); st->id = strdup(json_string_value(idstr)); //json_decref(idstr); const char *text = json_string_value(textstr); st->wtext = malloc(sizeof(wchar_t)*(TWEET_MAX_LEN+1)); mbstowcs(st->wtext, text, TWEET_MAX_LEN+1); //json_decref(textstr); st->length = wcslen(st->wtext); parse_user_json(json_object_get(status_root, "user"),&(st->composer)); //printf("\n@%s -- %ls\n", st->composer->screen_name, st->wtext); json_t *entities = json_object_get(status_root, "entities"); if(!entities) return -1; entity *prev = NULL; for(int i = 0; i < ENTITY_TYPE_COUNT; i++){ json_t *entities_array = json_object_get(entities,entities_keys[i]); if(json_is_array(entities_array) && json_array_size(entities_array) > 0){ for(int j = 0; j < json_array_size(entities_array); ++j){ json_t *entity_root = json_array_get(entities_array, j); if(!entity_root) continue; entity *et = newentity(); et->type = entity_types[i]; if(parse_entity_json(entity_root,et,st) < 0) destroy_entity(et); else{ st->entity_count ++; if(!(st->entities)) st->entities = et; else prev->next = et; prev = et; } } } } split_status_entities(st); json_t *retweeted_status_root = json_object_get(status_root,"retweeted_status"); if(retweeted_status_root){ int result = parse_status_json(retweeted_status_root,&(st->retweeted_status)); if(result == -1) st->retweeted_status = NULL; } /* for(entity *et = st->entities;et;et=et->next) printf("%ls ",et->text); printf("\n"); */ *status_ptr = st; return 0; }