Newtonian gravity toggle, disabled by default

This commit is contained in:
Simon Robertshaw
2011-05-12 18:04:29 +01:00
parent 59bd280fad
commit ee962dc8bb
3 changed files with 45 additions and 17 deletions

View File

@@ -204,4 +204,6 @@ void clear_sim(void);
void del_stamp(int d);
void sdl_seticon(void);
void play_sound(char *file);
void start_grav_async(void);
void stop_grav_async(void);
#endif

View File

@@ -4568,7 +4568,13 @@ void simulation_ui(pixel * vid_buf)
}
legacy_enable = !cb.checked;
ngrav_enable = cb2.checked;
if(ngrav_enable != cb2.checked)
{
if(cb2.checked)
start_grav_async();
else
stop_grav_async();
}
while (!sdl_poll())
{

View File

@@ -171,7 +171,7 @@ int do_open = 0;
int sys_pause = 0;
int sys_shortcuts = 1;
int legacy_enable = 0; //Used to disable new features such as heat, will be set by save.
int ngrav_enable = 1; //Newtonian gravity, will be set by save TODO: Make this actually do something
int ngrav_enable = 0; //Newtonian gravity, will be set by save
int death = 0, framerender = 0;
int amd = 1;
int FPSB = 0;
@@ -1233,6 +1233,28 @@ void update_grav_async()
}
}
void start_grav_async()
{
if(!ngrav_enable){
/*pthread_mutexattr_t gma; //I do not know why this is here
pthread_mutexattr_init(&gma);*/
pthread_mutex_init (&gravmutex, NULL);
pthread_create(&gravthread, NULL, update_grav_async, NULL); //Start asynchronous gravity simulation
ngrav_enable = 1;
}
}
void stop_grav_async()
{
if(ngrav_enable){
pthread_cancel(gravthread); //Terminate the thread, we don't really care if it finished or not
pthread_mutex_destroy(&gravmutex); //Destroy the mutex
memset(gravy, 0, sizeof(gravy)); //Clear the grav velocities
memset(gravx, 0, sizeof(gravx)); //Clear the grav velocities
ngrav_enable = 0;
}
}
#ifdef RENDERER
int main(int argc, char *argv[])
{
@@ -1514,11 +1536,7 @@ int main(int argc, char *argv[])
http_session_check = http_async_req_start(NULL, "http://" SERVER "/Login.api?Action=CheckSession", NULL, 0, 0);
http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id);
}
pthread_mutexattr_t gma;
pthread_mutexattr_init(&gma);
pthread_mutex_init (&gravmutex, NULL);
pthread_create(&gravthread, NULL, update_grav_async, NULL); //Asynchronous gravity simulation //(void *) &thread_args[i]);
while (!sdl_poll()) //the main loop
{
frameidx++;
@@ -1555,6 +1573,7 @@ int main(int argc, char *argv[])
if (bsy<0)
bsy = 0;
if(ngrav_enable){
pthread_mutex_lock(&gravmutex);
result = grav_ready;
if(result) //Did the gravity thread finish?
@@ -1566,6 +1585,7 @@ int main(int argc, char *argv[])
grav_ready = 0; //Tell the other thread that we're ready for it to continue
}
pthread_mutex_unlock(&gravmutex);
}
if (!sys_pause||framerender) //Only update if not paused
memset(gravmap, 0, sizeof(gravmap)); //Clear the old gravmap