//
// File: SparkDemo1.cpp
//
// Purpose: Quick-and-dirty integration example for Spark!
//
// Copyright © 2000 Louder Than A Bomb! Software
//
// Include files
#include <iostream.h> // for i/o functions
// include .h for Spark! integration.
//#include "../include/SparkModel.h"
// include the .h for the model we're opening
#include "SparkDemo1.h"
// define the class we want to use...
// the version of the class that we use is dependents on if the compiler we're
// using can import a class from a dll created with MSVC.
// either way the model object will be used EXACTLY the same.
// SparkModelWrapper uses LoadLibrary() and GetProcAddress() to call the
// SparkModel dll functions, SparkModel imports the whole class directly.
// Examine SparkModel.h for the details.
#ifdef _USING_MSVC_
#define SPARKMODEL SparkModel
#else
#define SPARKMODEL SparkModelWrapper
#endif // _USING_MSVC_
// prototypes
void get_values(SPARKMODEL* model);
void set_values(SPARKMODEL* model);
void print_output_vals(SPARKMODEL* model);
int main(int argc, char* argv[]);
int main(int argc, char* argv[])
{
int return_val; // return value from funcs
char option; // var for selection of what user wants to do
SPARKMODEL model;
// load the SparkDemo model
return_val = model.load("../SparkDemo1.spk", true);
if (return_val)
{
// there was an error loading the model...
// if the error is -100 or -200 we had an error in a system call,
// otherwize we can get the error text
if (return_val == -100 || return_val == -200)
{
DWORD err = GetLastError();
cout << "Error calling Load(). GetLastError() returned: " << err << endl;
}
else
{
const char* err = model.get_msg_textA();
cout << "Error calling Load(): " << err << endl;
}
return 1;
} // end if return_val
// Set the values
set_values(&model);
// get the values...
get_values(&model);
// just for fun let's do some event stuff...
HANDLE enemy_dist_event = model.get_var_notification(ENEMY_DISTANCE);
// we'll wait 100 milliseconds for a change...
if (model.wait(enemy_dist_event, 100))
{
cout << "Enemy distance value changed. ";
cout << "Current value is: " << model.get_value(ENEMY_DISTANCE) << endl;
}
else
cout << "Value didn't change!" << endl;
return 0;
} // end main()
void set_values(SPARKMODEL* model)
{
float value;
cout << "Enter value for Enemy Distance: ";
cin >> value;
// set the value...
model->set_value(ENEMY_DISTANCE, value);
cout << "Enter value for Enemy Health: ";
cin >> value;
model->set_value(ENEMY_HEALTH, value);
cout << "Enter value for Our Health: ";
cin >> value;
// set the value...
model->set_value(OUR_HEALTH, value);
print_output_vals(model);
} // end set_values()
void get_values(SPARKMODEL* model)
{
cout << "Enemy Distance: " << model->get_value(ENEMY_DISTANCE) << endl;
cout << "Enemy Health: " << model->get_value(ENEMY_HEALTH) << endl;
cout << "Our Health: " << model->get_value(OUR_HEALTH) << endl;
print_output_vals(model);
} // end get_values()
void print_output_vals(SPARKMODEL* model)
{
int mom_output;
cout << "Output value is: ";
cout << model->get_cog_output() << endl;
mom_output = model->get_mom_output();
cout << "Output result is: ";
if (mom_output == OUTPUT_RUN_AWAY)
cout << "Run Away" << endl;
if (mom_output == OUTPUT_FIGHT_DEFENSIVELY)
cout << "Fight Defensively" << endl;
if (mom_output == OUTPUT_ALL_OUT_ATTACK)
cout << "All Out Attack" << endl;
} // end get_values()
|