Пример #1
0
int ini_read_int(const char *p_file, const char *p_template, int dflt)
{
  FFILE f(NULL, p_file, "r", FALSE);
  if (!f)
    return (dflt);

  int ret = ini_read_int(f, p_template, dflt);
  
  fclose(f);
  return (ret);
}
Пример #2
0
int handle_init(int argc, char **argv, int proc_type)
{
    DEBUG_LOG("%d", ini_read_int("LogInfo", "log_level", 8));
    
    if (proc_type == PROC_MAIN) {
        DEBUG_LOG("PROC_MAIN");
//        setproctitle("-test_server: MAIN");
        return 0;
    } else if (proc_type == PROC_CONN) {
        DEBUG_LOG("PROC_CONN");
//        setproctitle("-test_server: CONN");
        return 0;
    } else if (proc_type == PROC_WORK) {
        DEBUG_LOG("PROC_WORK");
//        setproctitle("-test_server: WORK");
        return 0;
    } else {
        ERROR_LOG("unknown");
        return -1;
    }

}
Пример #3
0
int main()
{
    /* $ export MALLOC_TRACE=malloc.log */
    mtrace();

    ini_t *conf = ini_load("test.ini");
    if (conf == NULL)
        error(1, errno, "ini_load fail");

    char *type;
    ini_read_str(conf, "main", "type", &type, "test");
    puts(type);
    free(type);

    char value[100] = { 0 };
    ini_read_strn(conf, "main", "len", value, sizeof(value), NULL);
    puts(value);

    int i;
    ini_read_int(conf, "int", "int", &i, 0);
    unsigned ui;
    ini_read_unsigned(conf, "int", "unsigned", &ui, 0);
    printf("int: %d, unsigned: %u\n", i, ui);

    int8_t  int8;
    ini_read_int8(conf, "int", "int8", &int8, 0);
    uint8_t uint8;
    ini_read_uint8(conf, "int", "uint8", &uint8, 0);
    printf("int8: %i, uint8: %u\n", int8, uint8);

    int16_t int16;
    ini_read_int16(conf, "int", "int16", &int16, 0);
    uint16_t uint16;
    ini_read_uint16(conf, "int", "uint16", &uint16, 0);
    printf("int16: %i, uint16: %u\n", int16, uint16);

    int32_t int32;
    ini_read_int32(conf, "int", "int32", &int32, 0);
    uint32_t uint32;
    ini_read_uint32(conf, "int", "uint32", &uint32, 0);
    printf("int32: %i, uint32: %u\n", int32, uint32);

    int64_t int64;
    ini_read_int64(conf, "int", "int64", &int64, 0);
    uint64_t uint64;
    ini_read_uint64(conf, "int", "uint64", &uint64, 0);
    printf("int64: %"PRIi64", uint64: %"PRIu64"\n", int64, uint64);

    float f;
    ini_read_float(conf, "float", "float", &f, 0);
    double d;
    ini_read_double(conf, "float", "double", &d, 0);
    printf("float: %f, double: %f\n", f, d);

    struct sockaddr_in addr;
    ini_read_ipv4_addr(conf, "addr", "ipv4", &addr, "127.0.0.1:0");
    printf("%s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));

    char *proc_name = NULL;
    ini_read_str(conf, "global", "proc_name", &proc_name, "test.ini");
    printf("proc_name: %s\n", proc_name);
    free(proc_name);

    char *phone_num = NULL;
    ini_read_str(conf, "damon", "phone num", &phone_num, "123456789");
    printf("phone num: %s\n", phone_num);
    free(phone_num);

    char *city = NULL;
    ini_read_str(conf, "global", "$%^#@!", &city, "shen zhen");
    puts(city);
    free(city);

    char *name = NULL;
    ini_read_str(conf, NULL, "名字", &name, "");
    puts(name);
    free(name);

    ini_free(conf);

    return 0;
}
Пример #4
0
int  get_colors(char *p_ini_file, int default_color_depth)
{ 
  #define INI_COLOR "color_depth"
  return(ini_read_int(p_ini_file, INI_COLOR, default_color_depth));
}
Пример #5
0
bool get_fullscreen(char *p_ini_file)
{  
  #define INI_FULLSCREEN "fullscreen"
  return(ini_read_int(p_ini_file, INI_FULLSCREEN, FALSE));
}
Пример #6
0
void qlevel_load(STRING *filename)
{
	STRING *file = "#256";
	make_path(file, filename);
	if(!file_exists(file))
	{
		error("FIXIT! qlevel_load: File does not exist!");
		return;
	}
		
	level_load(NULL);
	
	int countEntity = ini_read_int(file, "Level Information", "EntityCount", 0);
	int countLight = ini_read_int(file, "Level Information", "LightCount", 0);
	int countFog = ini_read_int(file, "Level Information", "FogCount", 0);
	
	STRING *section = "#64";
	
	int i;
	char buffer[256];
	STRING *strTemp = "#128";
	for(i = 0; i < countEntity; i++)
	{
		diag("\nLoad :");
		str_cpy(section, "Entity ");
		str_cat(section, str_for_int(NULL, i));
		diag(section);
		
		ini_read_buffer(file, section, "Model", "error.mdl", buffer, 256);
		ENTITY *ent = ent_create(buffer, nullvector, qlevel_entity_init);
		ent->group = GROUP_LEVEL;
		ent->x = ini_read_float(file, section, "X", 0);
		ent->y = ini_read_float(file, section, "Y", 0);
		ent->z = ini_read_float(file, section, "Z", 0);
		
		ent->pan = ini_read_float(file, section, "Pan", 0);
		ent->tilt = ini_read_float(file, section, "Tilt", 0);
		ent->roll = ini_read_float(file, section, "Roll", 0);
		
		ent->scale_x = ini_read_float(file, section, "ScaleX", 0);
		ent->scale_y = ini_read_float(file, section, "ScaleY", 0);
		ent->scale_z = ini_read_float(file, section, "ScaleZ", 0);
		
		ent->lightrange = ini_read_float(file, section, "Lightrange", 0);
		
		int iActionCount = ini_read_int(file, section, "ActionCount", 0);
		int iA = 0;
		STRING *actionName = "#64";
		for(iA = 0; iA < iActionCount; iA++)
		{
			str_cpy(actionName, "Action");
			str_cat(actionName, str_for_int(NULL, iA));
			ini_read_buffer(file, section, actionName, "", buffer, 256);
			str_cpy(strTemp, buffer);
			diag("\nTry adding action '");
			diag(strTemp);
			diag("'...");
			if(actinfo_add(ent->string1, strTemp))
			{
				diag(" SUCCESS!\n\tTry getting function pointer...");
				void *fn = action_getptr(strTemp);
				if(fn != NULL)
				{
					diag(" SUCCESS!");
					scheduler_add(fn, ent);
				}
				else
				{
					diag(" FAILED!");				
				}
			}
			else
			{
				diag(" FAILED!");
			}
		}
		diag("\nEntity loaded!");
	}
}
Пример #7
0
void creditsText ()
{
	static char strIni [256];
	sprintf(strIni, "%s\\credits.ini", _chr(work_dir));
	
	// start music and lyrics
	{
		snd_stop(g_fhCreditsSong);
		g_fhCreditsSong = snd_play(g_musicCredits, 100, 0);
		
		lyricsStart(NULL, g_txtCreditsLyrics, g_fhCreditsSong);
	}
	
	int pos = 0;
	int count = ini_read_int(strIni, "Credits", "max", "0");
	var duration = ini_read_int(strIni, "Credits", "duration", "15");
	
	var itemDuration = duration / (var)count;
	
	creditsHead1.flags |= SHOW;
	creditsBody1.flags |= SHOW;
	creditsHead2.flags |= SHOW;
	creditsBody2.flags |= SHOW;
	
	creditsHead2.pos_y = screen_size.y - g_lyricsBarHeight - 150;
	creditsBody2.pos_y = screen_size.y - g_lyricsBarHeight - 100;
		
	int size1 = 300;
	int size2 = 600;
	
	var x = 0;
	var len = 0;
	
	while (snd_playing(g_fhCreditsSong) != 0 && !g_bCreditsAllExplode)
	{
		static char section [256];
		sprintf(section, "Credit%d", pos + 1);

		ini_read(creditsText1Head, strIni, section, "Head1", " ");
		ini_read(creditsText1Body, strIni, section, "Body1", " ");
		ini_read(creditsText2Head, strIni, section, "Head2", " ");
		ini_read(creditsText2Body, strIni, section, "Body2", " ");
		
		str_replaceall(creditsText1Body, "##", "\n");
		str_replaceall(creditsText2Body, "##", "\n");
		
		creditsHead1.pos_x = -size1;
		creditsBody1.pos_x = -size1;
		
		creditsHead2.pos_x = screen_size.x + size2;
		creditsBody2.pos_x = screen_size.x + size2;
		
		var fadetime = 0.22 * itemDuration;
		
		var fade = 0;
		var fadespeed = 16 / fadetime;
		
		for (fade = 0; fade < 100; fade += fadespeed * time_step)
		{
			creditsHead1.pos_x = -size1 + 1.5 * size1 * (1 - pow(1 - 0.01 * fade, 2));
			creditsBody1.pos_x = -size1 + 1.7 * size1 * (1 - pow(1 - 0.01 * fade, 2));
			
			if (g_bCreditsAllExplode)
				break;
			
			wait(1);
		}
		
		for (fade = 0; fade < 100; fade += fadespeed * time_step)
		{
			creditsHead2.pos_x = screen_size.x + size2 - 1.2 * size2 * (1 - pow(1 - 0.01 * fade, 2));
			creditsBody2.pos_x = screen_size.x + size2 - 1.3 * size2 * (1 - pow(1 - 0.01 * fade, 2));
			
			if (g_bCreditsAllExplode)
				break;
			
			wait(1);
		}
		
		var t_id = 0.6 * itemDuration * 16;
		
		while (t_id > 0 && !g_bCreditsAllExplode)
		{
			t_id -= time_step;
			wait(1);
		}
		
		var scrollspeed = 100;
		
		for (fade = 0; fade < 100; fade += fadespeed * time_step)
		{
			creditsHead1.pos_x += scrollspeed * time_step;
			
			if (fade > 20)
				creditsBody1.pos_x += scrollspeed * time_step;
				
			if (g_bCreditsAllExplode)
				break;
				
			wait(1);
		}
		
		for (fade = 0; fade < 100; fade += fadespeed * time_step)
		{
			creditsHead2.pos_x -= scrollspeed * time_step;
			
			if (fade > 20)
				creditsBody2.pos_x -= scrollspeed * time_step;
				
			if (g_bCreditsAllExplode)
				break;
				
			wait(1);
		}
		
		pos += 1;
		
		wait(1);
	} 
	
	snd_stopall(4);
	
	creditsHead1.flags &= ~SHOW;
	creditsBody1.flags &= ~SHOW;
	creditsHead2.flags &= ~SHOW;
	creditsBody2.flags &= ~SHOW;
	
	g_bCreditsAllExplode = true;
	
	creditsFinished = true;
	
	var et = 5 * 16;
	
	while (et > 0)
	{
		camera->tilt += time_step * 0.2;
		camera->arc += time_step * 0.2;
		
		et -= time_step;
		wait(1);
	}
	
	// show space text
	{
		set(g_txtCreditsSpace, SHOW);
		g_txtCreditsSpace->pos_x = screen_size.x / 2;
		g_txtCreditsSpace->pos_y = screen_size.y * 0.8;
		
		on_space = creditsSpace;
	}
}