Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. (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?
  2. (9:22:47 PM) lowerlogic: like
  3. (9:22:56 PM) lowerlogic: myScv->build(Barracks,here).onComplete(function(barracks) {barracks->train(Marine)});
  4. (9:23:09 PM) Heinermann: the 3.7.x version of BWAPI will be used for this year's tournaments
  5. (9:23:12 PM) Heinermann: hmm no
  6. (9:23:25 PM) Heinermann: but that seems like a good idea
  7. (9:23:55 PM) Heinermann: so BWAPI4 branch won't be merged into main until December
  8. (9:24:02 PM) lowerlogic: k
  9. (9:25:19 PM) Heinermann: myScv->build(Barracks,here).onComplete( [](Unit *barracks) { barracks->train(Marine) } );
  10. (9:25:35 PM) Heinermann: that would be the syntax I guess
  11. (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
  12. (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
  13. (9:28:35 PM) Heinermann: some brainstorming on possible syntax for what you mentioned
  14. (9:28:41 PM) lowerlogic: hmm that works
  15. (9:28:49 PM) lowerlogic: it would be nice to be able to do something like
  16. (9:28:51 PM) Heinermann: myScv->build(Barracks,here).onComplete( Repeat( Train(UnitTypes::Terran_Marine), 4) );
  17. (9:28:51 PM) Heinermann: myScv->build(Barracks,here).onComplete( Once( Train(UnitTypes::Terran_Marine) ) );
  18. (9:29:02 PM) Heinermann: idk
  19. (9:29:22 PM) lowerlogic: DefferedUnit barracks = myScv->build(Barracks, here);
  20. (9:29:29 PM) lowerlogic: for (int i=0;i<10;i++) {
  21. (9:29:48 PM) lowerlogic: barracks.onComplete(function(barracks) { barracks.train(Marine); });
  22. (9:29:49 PM) lowerlogic: }
  23. (9:30:09 PM) lowerlogic: hmm im reusing the barracks variable idk if it makes sense
  24. (9:30:39 PM) lowerlogic: actually
  25. (9:30:46 PM) lowerlogic: I guess it could be like
  26. (9:30:58 PM) lowerlogic: for (blah) {
  27. (9:31:14 PM) Heinermann: we could use a similar thing like the filter composition
  28. (9:31:21 PM) lowerlogic: idk
  29. (9:31:49 PM) Heinermann: myScv->build(Barracks,here).onComplete( Once( SetRallyPoint(choke) && Repeat( Train(UnitTypes::Terran_Marine), 10) );
  30. (9:32:03 PM) lowerlogic: the callbacks attached with onComplete would only be called if/when the barracks actually completes
  31. (9:32:14 PM) Heinermann: yeah
  32. (9:32:16 PM) lowerlogic: also if you save the deffered unit object
  33. (9:32:27 PM) lowerlogic: and you try to attach a callback when the barracks is already complete
  34. (9:32:32 PM) lowerlogic: it would fire the callback immediately
  35. (9:33:58 PM) lowerlogic: hmm
  36. (9:34:08 PM) lowerlogic: actually
  37. (9:34:26 PM) lowerlogic: it would make more sense to do
  38. (9:35:18 PM) lowerlogic: myScv->build(Barracks,here).onComplete( [](Unit* scv) { Unit* barracks = scv->getLastBuildUnit(); barracks->train(Marine); });
  39. (9:35:49 PM) lowerlogic: the callback is called with the argument being the same as the unit that is doing the task
  40. (9:35:58 PM) Heinermann: hmm
  41. (9:37:00 PM) Heinermann: maybe 2 onComplete members?
  42. (9:37:17 PM) Heinermann: .onBuilderComplete(), onStructureComplete()
  43. (9:37:19 PM) Heinermann: or something
  44. (9:37:33 PM) Heinermann: ah that's no good
  45. (9:37:36 PM) lowerlogic: myScv->build(Barracks,here).onComplete( [](Unit* scv) {scv->mine(myMineral); barracks->train(Marine).onComplete( [](Unit* barracks) { barracks.train(Medic); });});
  46. (9:38:17 PM) Heinermann: that's kinda lengthy and not very user friendly
  47. (9:38:54 PM) lowerlogic: hmm it would make more sense on multiple lines
  48. (9:39:20 PM) lowerlogic: i'll make a paste bin with a more complete example of the idea
  49. (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
  50. (9:39:29 PM) Heinermann: there should be presets for this
  51. (9:43:20 PM) Heinermann: also there is Unit::getClosestUnit
  52. (9:51:51 PM) Myk_ left the room (quit: Quit: Page closed).
  53. (10:03:24 PM) lowerlogic: ok
  54. (10:03:41 PM) lowerlogic: Heinermann here's an example: http://pastebin.com/7SEgryyG
  55. (10:04:05 PM) lowerlogic: we use this sort of way of programming a lot in javascript with asynchronous calls
  56. (10:04:29 PM) lowerlogic: idk if it makes sense for starcraft actions, but its an interesting idea
  57. (10:04:42 PM) lowerlogic: the two are similar since they take time to execute
  58. (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
  59. (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
  60. (10:08:30 PM) lowerlogic: hmm maybe i could figure out how to do this in c++11 if its possible
  61. (10:08:56 PM) Heinermann: you could just make attackAndTrain a void function
  62. (10:09:13 PM) Heinermann: or if you wanted
  63. (10:09:24 PM) Heinermann: auto attackAndTrain = [](Unit* unit, Unit* target)
  64. (10:09:38 PM) Heinermann: auto is a new keyword in C++
  65. (10:09:44 PM) Heinermann: and lambdas don't have a type
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement