Esempio n. 1
0
dllfunctions *DLLInitialize(hostfunctions *thost) {
#endif
	int problem = 0;

	// Checks if the passed function was received:
	#define checksanity(func, funcname) \
		if (!host->func) { \
			fprintf(stderr, "bmgame:  %s was not received from the host!\n", funcname); \
			problem = -1;\
		}

	// Grab the host functions structure:
	host = thost;
	if (host == NULL) {
		fprintf(stderr, "hwgame:  Did not receive host functions thru GetGameAPI!\n");
		return NULL;
	};

	// Sanity check!
	problem = 0;
	// Are we connected to the engine (devmode == 0) or the editor (devmode == 1)?
	if (host->devmode == 1) {
		// Connected to the map editor:
		// All we need are drawing functions:
		checksanity(put_sprite, "put_sprite()");
		checksanity(put_sprite_hflip, "put_sprite_hflip()");
		checksanity(put_sprite_vflip, "put_sprite_vflip()");
		checksanity(put_sprite_hvflip, "put_sprite_hvflip()");
	} else {
		// Connected to the game engine:
		checksanity(put_sprite, "put_sprite()");
		checksanity(put_sprite_hflip, "put_sprite_hflip()");
		checksanity(put_sprite_vflip, "put_sprite_vflip()");
		checksanity(put_sprite_hvflip, "put_sprite_hvflip()");
		checksanity(put_bgtile, "put_bgtile()");

		checksanity(Draw2x2BGTile, "Draw2x2BGTile()");

		checksanity(e_spawn, "e_spawn()");
		checksanity(e_spawnat, "e_spawnat()");
		checksanity(e_spawnatmap, "e_spawnatmap()");
		checksanity(e_findfirst, "e_findfirst()");
		checksanity(e_findnext, "e_findnext()");
		checksanity(e_kill, "e_kill()");
		checksanity(e_damage, "e_damage()");
		checksanity(control_switch, "control_switch()");
		checksanity(gettileat, "gettileat()");
		checksanity(settileat, "settileat()");

		checksanity(wrap_map_coord_x, "wrap_map_coord_x()");
		checksanity(wrap_map_coord_y, "wrap_map_coord_y()");

		checksanity(LoadLevel, "LoadLevel()");

		checksanity(sndPrecache, "sndPrecache()");
		checksanity(sndFree, "sndFree()");
		checksanity(sndPlay, "sndPlay()");
		checksanity(sndSetVolume, "sndSetVolume()");
		checksanity(sndIsPlaying, "sndIsPlaying()");
		checksanity(sndStop, "sndStop()");

		// Pointers to the original variables:
		checksanity(map, "map structure");

		// Entities:
		checksanity(player, "player variable");
		checksanity(world, "world variable");

		// Game state variables:
		checksanity(screen_mx, "screen_mx variable");
		checksanity(screen_my, "screen_my variable");
		checksanity(old_screen_mx, "old_screen_mx variable");
		checksanity(old_screen_my, "old_screen_my variable");
		checksanity(screen_w, "screen_w variable");
		checksanity(screen_h, "screen_h variable");
		checksanity(scroll_left, "scroll_left variable");
		checksanity(scroll_right, "scroll_right variable");
		checksanity(scroll_top, "scroll_top variable");
		checksanity(scroll_bottom, "scroll_bottom variable");
		checksanity(quit, "quit variable");
		checksanity(game_paused, "game_paused variable");

		player = host->player;
	}

	// Return NULL if any of the above sanity checks failed:
	if (problem == -1) return NULL;

	// First, load the common DLL for common entities, so that we don't re-code them:
	common = GetGameAPI ("game/common", host, &common_library);
	if (common == NULL) {
		fprintf(stderr, "Error loading common dll!\n");
		return NULL;
	}

	game = (dllfunctions *)calloc(sizeof(dllfunctions), 1);
	// Send our functions and variables back:
	game->class_properties = calloc(sizeof(class_properties_t) * NUM_CLASSES, 1);
	if (game->class_properties == NULL) {
		fprintf(stderr, "Could not allocate memory for class_properties!\n");
		return NULL;
	}
	game->spawnflags = malloc(sizeof(Uint32) * NUM_CLASSES);
	if (game->spawnflags == NULL) {
		fprintf(stderr, "Could not allocate memory for spawnflags!\n");
		return NULL;
	}
	memset(game->class_properties, 0, sizeof(class_properties_t) * NUM_CLASSES);
	memset(game->spawnflags, 0, sizeof(Uint32) * NUM_CLASSES);

	#define DEFINE_CLASS(class, props, flags) \
		game->class_properties[class] = &props; \
		game->spawnflags[class] = flags;

	// Copy all common entities over to our list that we will return:
	memcpy(game->class_properties, common->class_properties, sizeof(class_properties_t) * common->numclasses);
	memcpy(game->spawnflags, common->spawnflags, sizeof(Uint32) * common->numclasses);

///---Do not change this line!! It is used by scripts to add new entities!!---
	DEFINE_CLASS(CLASS_KEYHOLEL, ClassProperties_KeyholeL, SPAWNFLAG_MAPSPAWNABLE)
	DEFINE_CLASS(CLASS_KEYHOLER, ClassProperties_KeyholeR, SPAWNFLAG_MAPSPAWNABLE)

	game->numclasses = NUM_CLASSES;
	game->init = init;
	game->pre_render = common->pre_render;
	game->post_render = common->post_render;

	return game;
};
Esempio n. 2
0
int main(int argc, char* argv[]) {

	// Read the input parameters file, named "params.ini" by default.
	// If there is a command line argument, assume that it is the filename for the parameters file.
	string inifileName;
	if (argc > 1)
		inifileName = argv[1];
	else
		inifileName = "params.ini";

	vector<double> icRETS,FI;
	
	// Setup parameters
	setuparams(inifileName);
	
	// Print welcome message to screen
	printwelcome(cout);
		
	// Check that the output directory exists; if not, code will create it
    checkdirexists(cout,outDIR);
	
	// Do a quick sanity check
	int isok = checksanity();
	
	if(isok==0){
		
		// Start timing!
		clock_t startTime = clock();
		
		// Print top-matter (run info)
		printtopmatter(cout);
		
		// Print properties of the object
		printobjectproperties(cout);
		
		// Print a logfile with all parameter info & simulation conditions
		printlog("start",0.0,0.0);

		// Run the solver:
	 
	 	// zero the background density of the source
	 	obj_rhobg = 0.0;
	 
	 	double s1, s2, s3, phi_bg;
	 	//cout << gsl_poly_solve_cubic(-phi_inf, 0.0, -Lparam/phi_mass/phi_mass, &s1, &s2, &s3) << endl;
		int getroots = gsl_poly_solve_cubic(-phi_inf, 0.0, -Lparam/phi_mass/phi_mass, &s1, &s2, &s3);
		cout << "nroots for bg = " << getroots << " ";
		cout << s1 << " " << s2 << " " << s3 << endl;
		if(Lparam > 0)
			phi_bg = s1;
		else
			phi_bg = s3;
		// (0) set the initial conditions
		// argument = phi_bg
		//double phi_bg = phi_inf;
		icRETS = initialconditions(phi_bg);
		totmass = icRETS[0];
		cout << "Object's total mass = " << totmass << endl;
		cout << "Biggest sphere mass = " << icRETS[1] << endl;
		
		// (1) solve 
		// Returns all the force info
		FI = solve();				
		////////////////////////////////////////
		
		// Now we've found some profiles, extract information about them
		// passed back by solve()
		
		// Dump the total mass into the FI vector
		FI.push_back(totmass);	
	
		// Stop timing
		clock_t endTime = clock();
		
		// Compute elapsed time in ms
		double timeinMS = (endTime - startTime) / (double) CLOCKS_PER_SEC * 1000.0;
		
		// Send elapsed time to be printed, along with a polite message	
		printfinalmessage(cout,timeinMS);
		
		// Print the elapsed time to log file
		printlog("end",timeinMS,0.0);
		
	}
	else
		printerror(cout,isok);
		
} // END main