Changeset 24962
- Timestamp:
- Feb 28, 2021, 1:16:32 PM (3 years ago)
- Location:
- ps/trunk/source
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/rlinterface/RLInterface.cpp
r24844 r24962 63 63 m_GameMessage = std::move(msg); 64 64 m_MsgApplied.wait(msgLock, [this]() { return m_GameMessage.type == GameMessageType::None; }); 65 return m_ GameState;65 return m_e; 66 66 } 67 67 … … 77 77 m_ScenarioConfig = std::move(scenario); 78 78 return SendGameMessage({ GameMessageType::Reset }); 79 80 81 82 83 84 85 79 86 } 80 87 … … 193 200 stream << gameState.c_str(); 194 201 } 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 195 226 else if (uri == "/templates") 196 227 { … … 275 306 if (m_NeedsGameState && isGameStarted) 276 307 { 277 m_ GameState = GetGameState();308 m_e = GetGameState(); 278 309 m_MsgApplied.notify_one(); 279 310 m_MsgLock.unlock(); … … 319 350 LDR_NonprogressiveLoad(); 320 351 ENSURE(g_Game->ReallyStartGame() == PSRETURN_OK); 321 m_ GameState = GetGameState();352 m_e = GetGameState(); 322 353 m_MsgApplied.notify_one(); 323 354 m_MsgLock.unlock(); … … 343 374 if (!g_Game) 344 375 { 345 m_ GameState = EMPTY_STATE;376 m_e = EMPTY_STATE; 346 377 m_MsgApplied.notify_one(); 347 378 m_MsgLock.unlock(); … … 369 400 g_Game->Update(deltaRealTime); 370 401 371 m_ GameState = GetGameState();402 m_e = GetGameState(); 372 403 m_MsgApplied.notify_one(); 373 404 m_MsgLock.unlock(); 374 405 break; 375 406 } 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 376 425 default: 377 426 break; -
ps/trunk/source/rlinterface/RLInterface.h
r24839 r24962 1 /* Copyright (C) 202 0Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 46 46 Reset, 47 47 Commands, 48 48 49 }; 49 50 … … 72 73 * 0. The game/main thread calls TryApplyMessage() 73 74 * - If no messages are pending, GOTO 0 (the simulation is not advanced). 74 * 1. TryApplyMessage locks m_MsgLock, pulls the message, processes it, advances the simulation, and sets m_ GameState.75 * 1. TryApplyMessage locks m_MsgLock, pulls the message, processes it, advances the simulation, and sets m_e. 75 76 * 2. TryApplyMessage notifies the RL thread that it can carry on and unlocks m_MsgLock. The main thread carries on frame rendering and goes back to 0. 76 * 3. The RL thread locks m_MsgLock, reads m_ GameState, unlocks m_MsgLock, and sends the gamestate as HTTP Response to the RL client.77 * 3. The RL thread locks m_MsgLock, reads m_e, unlocks m_MsgLock, and sends the gamestate as HTTP Response to the RL client. 77 78 * 4. The client processes the response and ultimately sends a new HTTP message to the RL Interface. 78 79 * 5. The RL thread locks m_MsgLock, pushes the message, and starts waiting on the game/main thread to notify it (step 2). … … 87 88 /** 88 89 * Non-blocking call to process any pending messages from the RL client. 89 * Updates m_ GameState to the gamestate after messages have been processed.90 * Updates m_e to the gamestate after messages have been processed. 90 91 */ 91 92 void TryApplyMessage(); … … 106 107 */ 107 108 std::string Reset(ScenarioConfig&& scenario); 109 110 111 112 113 114 108 115 109 116 /** … … 132 139 /** 133 140 * Process any pending messages from the RL client. 134 * Updates m_ GameState to the gamestate after messages have been processed.141 * Updates m_e to the gamestate after messages have been processed. 135 142 */ 136 143 void ApplyMessage(const GameMessage& msg); … … 145 152 GameMessage m_GameMessage; 146 153 ScenarioConfig m_ScenarioConfig; 147 std::string m_ GameState;154 std::string m_e; 148 155 bool m_NeedsGameState = false; 149 156 … … 151 158 std::mutex m_MsgLock; 152 159 std::condition_variable m_MsgApplied; 160 153 161 }; 154 162 -
ps/trunk/source/tools/rlclient/python/tests/test_actions.py
r24816 r24962 79 79 def test_attack(): 80 80 state = game.reset(config) 81 unit s = state.units(owner=1, type='cavalry')81 unit 82 82 target = state.units(owner=2, type='female_citizen')[0] 83 initial_health = target.health() 83 initial_health_target = target.health() 84 initial_health_unit = unit.health() 84 85 85 86 state = game.step([zero_ad.actions.reveal_map()]) 86 87 87 attack = zero_ad.actions.attack( units, target)88 attack = zero_ad.actions.attack(, target) 88 89 state = game.step([attack]) 89 while state.unit(target.id()).health() >= initial_health: 90 while (state.unit(target.id()).health() >= initial_health_target 91 ) and (state.unit(unit.id()).health() >= initial_health_unit): 90 92 state = game.step() 91 93 -
ps/trunk/source/tools/rlclient/python/zero_ad/api.py
r23917 r24962 28 28 response = self.post('templates', post_data) 29 29 return zip(names, response.decode().split('\n')) 30 31 32 33 -
ps/trunk/source/tools/rlclient/python/zero_ad/environment.py
r23917 r24962 25 25 self.current_state = GameState(json.loads(state_json), self) 26 26 return self.current_state 27 28 29 27 30 28 31 def get_template(self, name):
Note:
See TracChangeset
for help on using the changeset viewer.