Explorar el Código

Added the functions to specify settings to a device and updated opengl example to use them.

Fredrik Hultin hace 9 años
padre
commit
5682b5d60b
Se han modificado 3 ficheros con 35 adiciones y 3 borrados
  1. 12 2
      examples/opengl/main.c
  2. 1 1
      include/openhmd.h
  3. 22 0
      src/openhmd.c

+ 12 - 2
examples/opengl/main.c

@@ -90,7 +90,17 @@ int main(int argc, char** argv)
 		return 1;
 	}
 
-	ohmd_device* hmd = ohmd_list_open_device(ctx, 0);
+	ohmd_device_settings* settings = ohmd_device_settings_create(ctx);
+
+	// If OHMD_IDS_AUTOMATIC_UPDATE is set to 0, ohmd_ctx_update() must be called manually every frame.
+	// It is enabled by default.
+
+	int auto_update = 1;
+	ohmd_device_settings_seti(settings, OHMD_IDS_AUTOMATIC_UPDATE, &auto_update);
+
+	ohmd_device* hmd = ohmd_list_open_device_s(ctx, 0, settings);
+
+	ohmd_device_settings_destroy(settings);
 	
 	if(!hmd){
 		printf("failed to open device: %s\n", ohmd_ctx_get_error(ctx));
@@ -121,7 +131,7 @@ int main(int argc, char** argv)
 
 	bool done = false;
 	while(!done){
-		ohmd_ctx_update(ctx);
+		// ohmd_ctx_update(ctx); <- must be called if automatic updates are turned off
 
 		SDL_Event event;
 		while(SDL_PollEvent(&event)){

+ 1 - 1
include/openhmd.h

@@ -262,7 +262,7 @@ OHMD_APIENTRYDLL ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context
  * @param key The specefic setting you wish to set.
  * @param value A pointer to an int or int array (containing the expected number of elements) with the value(s) you wish to set.
  **/
-OHMD_APIENTRYDLL void OHMD_APIENTRY ohmd_device_settings_seti(ohmd_device_settings* settings, ohmd_int_settings key, const int* val);
+OHMD_APIENTRYDLL ohmd_status OHMD_APIENTRY ohmd_device_settings_seti(ohmd_device_settings* settings, ohmd_int_settings key, const int* val);
 
 /**
  * Create a device settings instance.

+ 22 - 0
src/openhmd.c

@@ -415,6 +415,28 @@ int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type
 	return ret;
 }
 
+ohmd_status OHMD_APIENTRY ohmd_device_settings_seti(ohmd_device_settings* settings, ohmd_int_settings key, const int* val)
+{
+	switch(key){
+	case OHMD_IDS_AUTOMATIC_UPDATE:
+		settings->automatic_update = val[0] == 0 ? false : true;
+		return OHMD_S_OK;
+    
+	default:
+		return OHMD_S_INVALID_PARAMETER;
+	}
+}
+
+ohmd_device_settings* OHMD_APIENTRY ohmd_device_settings_create(ohmd_context* ctx)
+{
+	return ohmd_alloc(ctx, sizeof(ohmd_device_settings));
+}
+
+void OHMD_APIENTRY ohmd_device_settings_destroy(ohmd_device_settings* settings)
+{
+	free(settings);
+}
+
 void* ohmd_allocfn(ohmd_context* ctx, const char* e_msg, size_t size)
 {
 	void* ret = calloc(1, size);