Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (9:22:43 PM) lowerlogic: would the new features in C++ allow you make it possible to treat SCV units similar to deferred objects in Javascript?
- (9:22:47 PM) lowerlogic: like
- (9:22:56 PM) lowerlogic: myScv->build(Barracks,here).onComplete(function(barracks) {barracks->train(Marine)});
- (9:23:09 PM) Heinermann: the 3.7.x version of BWAPI will be used for this year's tournaments
- (9:23:12 PM) Heinermann: hmm no
- (9:23:25 PM) Heinermann: but that seems like a good idea
- (9:23:55 PM) Heinermann: so BWAPI4 branch won't be merged into main until December
- (9:24:02 PM) lowerlogic: k
- (9:25:19 PM) Heinermann: myScv->build(Barracks,here).onComplete( [](Unit *barracks) { barracks->train(Marine) } );
- (9:25:35 PM) Heinermann: that would be the syntax I guess
- (9:26:15 PM) Heinermann: with std::function as a parameter you can use lambdas, classes with operator () overloaded, or a pointer to a function
- (9:27:09 PM) Heinermann: but if it's not a virtual function it's better to use a template so that the std::function construction doesn't happen
- (9:28:35 PM) Heinermann: some brainstorming on possible syntax for what you mentioned
- (9:28:41 PM) lowerlogic: hmm that works
- (9:28:49 PM) lowerlogic: it would be nice to be able to do something like
- (9:28:51 PM) Heinermann: myScv->build(Barracks,here).onComplete( Repeat( Train(UnitTypes::Terran_Marine), 4) );
- (9:28:51 PM) Heinermann: myScv->build(Barracks,here).onComplete( Once( Train(UnitTypes::Terran_Marine) ) );
- (9:29:02 PM) Heinermann: idk
- (9:29:22 PM) lowerlogic: DefferedUnit barracks = myScv->build(Barracks, here);
- (9:29:29 PM) lowerlogic: for (int i=0;i<10;i++) {
- (9:29:48 PM) lowerlogic: barracks.onComplete(function(barracks) { barracks.train(Marine); });
- (9:29:49 PM) lowerlogic: }
- (9:30:09 PM) lowerlogic: hmm im reusing the barracks variable idk if it makes sense
- (9:30:39 PM) lowerlogic: actually
- (9:30:46 PM) lowerlogic: I guess it could be like
- (9:30:58 PM) lowerlogic: for (blah) {
- (9:31:14 PM) Heinermann: we could use a similar thing like the filter composition
- (9:31:21 PM) lowerlogic: idk
- (9:31:49 PM) Heinermann: myScv->build(Barracks,here).onComplete( Once( SetRallyPoint(choke) && Repeat( Train(UnitTypes::Terran_Marine), 10) );
- (9:32:03 PM) lowerlogic: the callbacks attached with onComplete would only be called if/when the barracks actually completes
- (9:32:14 PM) Heinermann: yeah
- (9:32:16 PM) lowerlogic: also if you save the deffered unit object
- (9:32:27 PM) lowerlogic: and you try to attach a callback when the barracks is already complete
- (9:32:32 PM) lowerlogic: it would fire the callback immediately
- (9:33:58 PM) lowerlogic: hmm
- (9:34:08 PM) lowerlogic: actually
- (9:34:26 PM) lowerlogic: it would make more sense to do
- (9:35:18 PM) lowerlogic: myScv->build(Barracks,here).onComplete( [](Unit* scv) { Unit* barracks = scv->getLastBuildUnit(); barracks->train(Marine); });
- (9:35:49 PM) lowerlogic: the callback is called with the argument being the same as the unit that is doing the task
- (9:35:58 PM) Heinermann: hmm
- (9:37:00 PM) Heinermann: maybe 2 onComplete members?
- (9:37:17 PM) Heinermann: .onBuilderComplete(), onStructureComplete()
- (9:37:19 PM) Heinermann: or something
- (9:37:33 PM) Heinermann: ah that's no good
- (9:37:36 PM) lowerlogic: myScv->build(Barracks,here).onComplete( [](Unit* scv) {scv->mine(myMineral); barracks->train(Marine).onComplete( [](Unit* barracks) { barracks.train(Medic); });});
- (9:38:17 PM) Heinermann: that's kinda lengthy and not very user friendly
- (9:38:54 PM) lowerlogic: hmm it would make more sense on multiple lines
- (9:39:20 PM) lowerlogic: i'll make a paste bin with a more complete example of the idea
- (9:39:25 PM) Heinermann: what I did with the Filters thing is add a bunch of "presets", but the user could also use lambdas too if they wanted
- (9:39:29 PM) Heinermann: there should be presets for this
- (9:43:20 PM) Heinermann: also there is Unit::getClosestUnit
- (9:51:51 PM) Myk_ left the room (quit: Quit: Page closed).
- (10:03:24 PM) lowerlogic: ok
- (10:03:41 PM) lowerlogic: Heinermann here's an example: http://pastebin.com/7SEgryyG
- (10:04:05 PM) lowerlogic: we use this sort of way of programming a lot in javascript with asynchronous calls
- (10:04:29 PM) lowerlogic: idk if it makes sense for starcraft actions, but its an interesting idea
- (10:04:42 PM) lowerlogic: the two are similar since they take time to execute
- (10:06:14 PM) lowerlogic: this example in the paste bin tells an scv to make a barracks, and the barracks has a callback loop to continously build marines, only queueing up one at a time
- (10:07:07 PM) lowerlogic: though it also attaches callbacks for onUnitDestroy, onTargetDestroy, and onCancel which are only called if the deferred unit 'resolves' to that state
- (10:08:30 PM) lowerlogic: hmm maybe i could figure out how to do this in c++11 if its possible
- (10:08:56 PM) Heinermann: you could just make attackAndTrain a void function
- (10:09:13 PM) Heinermann: or if you wanted
- (10:09:24 PM) Heinermann: auto attackAndTrain = [](Unit* unit, Unit* target)
- (10:09:38 PM) Heinermann: auto is a new keyword in C++
- (10:09:44 PM) Heinermann: and lambdas don't have a type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement