summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-05-12 17:04:29 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-05-12 17:04:29 (GMT)
commitee962dc8bb679a47e11456cedf24013de4594b64 (patch)
tree4cf67f301d0fb6c96b033835449a88b4381f169e /src
parent59bd280fad8ede2ab81d26156dcb7da81c3b0e7d (diff)
downloadpowder-ee962dc8bb679a47e11456cedf24013de4594b64.zip
powder-ee962dc8bb679a47e11456cedf24013de4594b64.tar.gz
Newtonian gravity toggle, disabled by default
Diffstat (limited to 'src')
-rw-r--r--src/interface.c8
-rw-r--r--src/main.c52
2 files changed, 43 insertions, 17 deletions
diff --git a/src/interface.c b/src/interface.c
index 2cc3031..8947424 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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())
{
diff --git a/src/main.c b/src/main.c
index 5ec1f94..28fa4db 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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,17 +1573,19 @@ int main(int argc, char *argv[])
if (bsy<0)
bsy = 0;
- pthread_mutex_lock(&gravmutex);
- result = grav_ready;
- if(result) //Did the gravity thread finish?
- {
- memcpy(th_gravmap, gravmap, sizeof(gravmap)); //Move our current gravmap to be processed other thread
- memcpy(gravy, th_gravy, sizeof(gravy)); //Hmm, Gravy
- memcpy(gravx, th_gravx, sizeof(gravx)); //Move the processed velocity maps to be used
- if (!sys_pause||framerender) //Only update if not paused
- grav_ready = 0; //Tell the other thread that we're ready for it to continue
+ if(ngrav_enable){
+ pthread_mutex_lock(&gravmutex);
+ result = grav_ready;
+ if(result) //Did the gravity thread finish?
+ {
+ memcpy(th_gravmap, gravmap, sizeof(gravmap)); //Move our current gravmap to be processed other thread
+ memcpy(gravy, th_gravy, sizeof(gravy)); //Hmm, Gravy
+ memcpy(gravx, th_gravx, sizeof(gravx)); //Move the processed velocity maps to be used
+ if (!sys_pause||framerender) //Only update if not paused
+ grav_ready = 0; //Tell the other thread that we're ready for it to continue
+ }
+ pthread_mutex_unlock(&gravmutex);
}
- pthread_mutex_unlock(&gravmutex);
if (!sys_pause||framerender) //Only update if not paused
memset(gravmap, 0, sizeof(gravmap)); //Clear the old gravmap