1

I am writing a game in c++ with the v8 javascript engine embedded in it. I have a c++ workflow system I use to tell things how to do specific things. It's nice and I like it, but I need it to work in javascript as well.

The code describes the whole process, but it is asynchronous-ish and only selectively runs the portion of the workflow that is "current". It skips anything that has already been done or anything that doesn't need to be done yet.

I'm not looking for someone to write this code for me. I am looking for someone to point me at javascript language constructs which can be "abused" for writing a domain specific language, especially things related to ES6.

A simplified example of the c++ code to tell a truck to go to a fuel depot and refuel is:

workflow().label("pick fuel storage location").do_once([this](WorkflowCommand & c) {
    auto fuel_storage = /* find a fuel depot */

    /* persist selected fuel depot to workflow */
    c.get_workflow().store("fuelstorage", *fuel_storage);
});
// load that value for easy use - will be the same value every run through
FuelStorage * fuel_storage = workflow.get_stored_values().get_p<FuelStorage>("fuelstorage");

workflow().label("drive truck to fuel tank").do_once([this, fuel_storage](WorkflowCommand & c){
    // generate a path to the fuel depot
    c.get_possessed()->get_object().path_to({fuel_storage->extents.center(), Heading(0.0f)});
  // don't execute anything past here until the fuel truck has arrived
}).wait_for_path_completion();

// run this callback until it returns true
workflow().label("pumping gas").do_until([this, fuel_storage](WorkflowCommand & c) {
    this->fuel_truck.fuel_tank.transfer_from(*fuel_storage->fuel_tank,
                                             fuel_storage->fuel_tank->get_transfer_rate() *
                                                     c.get_time().get_game_delta());
    return this->fuel_truck.fuel_tank.is_full();
});

My javascript version needs to use the same primitives (since it will be calling the c++ behind the scenes, but I can mish mash those primitives any way I want.

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.