Browse Source

Clean up warnings + C89 compliance

Peter Schulman 2 years ago
parent
commit
dc4e3f1cf4

+ 28 - 19
demo/common/nodeeditor/node_type_color.c

@@ -6,8 +6,8 @@ struct node_type_color {
 
 static struct nk_colorf *node_color_eval(struct node* node, int oIndex)
 {
-    NK_ASSERT(oIndex == 0); /* only one output connector */
     struct node_type_color *colornode = (struct node_type_color*)node;
+    NK_ASSERT(oIndex == 0); /* only one output connector */
 
     return &colornode->outputVal;
 }
@@ -19,10 +19,11 @@ static void node_color_draw(struct nk_context *ctx, struct node *node)
     float evalResult; /* Get the values from connected nodes into this so the inputs revert on disconnect */
     char* labels[4] = {"#R:","#G:","B:","A:"};
     float colorVals[4]; /* Because we can't just loop through the struct... */
+    int i;
     nk_layout_row_dynamic(ctx, 25, 1);
     nk_button_color(ctx, nk_rgba_cf(colornode->outputVal));
     
-    for (int i = 0; i < 4; i++) {
+    for (i = 0; i < 4; i++) {
         if (colornode->node.inputs[i].isConnected) {
             evalResult = *(float*)node_editor_eval_connected(node, i);
             evalResult = nk_propertyf(ctx, labels[i], evalResult, evalResult, evalResult, 0.01f, 0.01f);
@@ -34,28 +35,36 @@ static void node_color_draw(struct nk_context *ctx, struct node *node)
         }
     }
 
-    colornode->outputVal = (struct nk_colorf){colorVals[0],colorVals[1],colorVals[2],colorVals[3]};
+    colornode->outputVal.r = colorVals[0];
+    colornode->outputVal.g = colorVals[1];
+    colornode->outputVal.b = colorVals[2];
+    colornode->outputVal.a = colorVals[3];
 }
 
 void node_color_create(struct node_editor *editor, struct nk_vec2 position)
 {
     struct node_type_color *colornode = (struct node_type_color*)node_editor_add(editor, sizeof(struct node_type_color), "Color", nk_rect(position.x, position.y, 180, 190), 4, 1);
-    colornode->node.slot_spacing.in_top = 72.0f;
-    colornode->node.slot_spacing.in_space = 29.0f;
-    colornode->node.slot_spacing.out_top = 42.0f;
-    colornode->node.slot_spacing.out_space = 0.0f;
-
-    for (int i = 0; i < colornode->node.input_count; i++)
-        colornode->node.inputs[i].type = fValue;
-    colornode->node.outputs[0].type = fColor;
-    
-    colornode->inputVal[0] = 
-    colornode->inputVal[1] = 
-    colornode->inputVal[2] = 
-    colornode->inputVal[3] = 1.0f;
+    if (colornode)
+    {
+        int i;
+        struct nk_colorf white = {1.0f, 1.0f, 1.0f, 1.0f};
+        colornode->node.slot_spacing.in_top = 72.0f;
+        colornode->node.slot_spacing.in_space = 29.0f;
+        colornode->node.slot_spacing.out_top = 42.0f;
+        colornode->node.slot_spacing.out_space = 0.0f;
 
-    colornode->outputVal = (struct nk_colorf){1.0f, 1.0f, 1.0f, 1.0f};
+        for (i = 0; i < colornode->node.input_count; i++)
+            colornode->node.inputs[i].type = fValue;
+        colornode->node.outputs[0].type = fColor;
+        
+        colornode->inputVal[0] = 
+        colornode->inputVal[1] = 
+        colornode->inputVal[2] = 
+        colornode->inputVal[3] = 1.0f;
 
-    colornode->node.displayFunc = node_color_draw;
-    colornode->node.evalFunc = node_color_eval;
+        colornode->outputVal = white;
+
+        colornode->node.displayFunc = node_color_draw;
+        colornode->node.evalFunc = (void*(*)(struct node*, int)) node_color_eval;
+    }
 }

+ 8 - 6
demo/common/nodeeditor/node_type_float.c

@@ -6,8 +6,8 @@ struct node_type_float {
 };
 
 static float *node_float_eval(struct node* node, int oIndex) {
-    NK_ASSERT(oIndex == 0);
     struct node_type_float *floatnode = (struct node_type_float*)node;
+    NK_ASSERT(oIndex == 0);
     return &floatnode->outputVal;
 }
 
@@ -19,8 +19,10 @@ static void node_float_draw(struct nk_context *ctx, struct node *node) {
 
 void node_float_create(struct node_editor *editor, struct nk_vec2 position) {
     struct node_type_float *floatnode = (struct node_type_float*)node_editor_add(editor, sizeof(struct node_type_float), "Float", nk_rect(position.x, position.y, 180, 75), 0, 1);
-
-    floatnode->outputVal = 1.0f;
-    floatnode->node.displayFunc = node_float_draw;
-    floatnode->node.evalFunc = node_float_eval;
-}
+    if (floatnode)
+    {
+        floatnode->outputVal = 1.0f;
+        floatnode->node.displayFunc = node_float_draw;
+        floatnode->node.evalFunc = (void*(*)(struct node*, int)) node_float_eval;
+    }
+}

+ 10 - 7
demo/common/nodeeditor/node_type_output.c

@@ -5,8 +5,10 @@ struct node_type_output {
 
 struct nk_colorf *node_output_get(struct node* node) {
     struct node_type_output *outputnode = (struct node_type_output*)node;
-    if (!node->inputs[0].isConnected)
-        outputnode->inputVal = (struct nk_colorf){0.0f, 0.0f, 0.0f, 0.0f};
+    if (!node->inputs[0].isConnected) {
+        struct nk_colorf black = {0.0f, 0.0f, 0.0f, 0.0f};
+        outputnode->inputVal = black;
+    }
     return &outputnode->inputVal;
 }
 
@@ -21,8 +23,9 @@ static void node_output_display(struct nk_context *ctx, struct node *node) {
 
 struct node* node_output_create(struct node_editor *editor, struct nk_vec2 position) {
     struct node_type_output *outputNode = (struct node_type_output*)node_editor_add(editor, sizeof(struct node_type_output), "Output", nk_rect(position.x, position.y, 100, 100), 1, 0);
-    
-    outputNode->node.inputs[0].type = fColor;
-    outputNode->node.displayFunc = node_output_display;
-    return outputNode;
-}
+    if (outputNode){
+        outputNode->node.inputs[0].type = fColor;
+        outputNode->node.displayFunc = node_output_display;
+    }
+    return (struct node*)outputNode;
+}