History

start on code to de/serialize actions

Seth Alves committed 11 years ago

Commit 3c90c851 parent 99afd0712 files · +145 −17Browse files

Showing the changes to interface/src/InterfaceActionFactory.cpp (1 of 12 files). Show all

Unified · Split

interface/src/InterfaceActionFactory.cpp+38−17
@@ -18,32 +18,53 @@ · 17 unmodified lines
18#include "InterfaceActionFactory.h"18#include "InterfaceActionFactory.h"
19 19
20 20
21EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,21EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
22 EntityActionType type,
23 QUuid id,
24 EntityItemPointer ownerEntity,
25 QVariantMap arguments) {
26 EntityActionPointer action = nullptr;
27 switch (type) {22 switch (type) {
28 case ACTION_TYPE_NONE:23 case ACTION_TYPE_NONE:
29 return nullptr;24 return nullptr;
30 case ACTION_TYPE_OFFSET:25 case ACTION_TYPE_OFFSET:
31 action = (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);26 return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
32 break;
33 case ACTION_TYPE_SPRING:27 case ACTION_TYPE_SPRING:
34 action = (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);28 return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
35 break;
36 case ACTION_TYPE_HOLD:29 case ACTION_TYPE_HOLD:
37 action = (EntityActionPointer) new AvatarActionHold(id, ownerEntity);30 return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
38 break;
39 }31 }
40 32
41 bool ok = action->updateArguments(arguments);33 assert(false);
42 if (ok) {34 return nullptr;
43 ownerEntity->addAction(simulation, action);35}
44 return action;36
37
38EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
39 EntityActionType type,
40 QUuid id,
41 EntityItemPointer ownerEntity,
42 QVariantMap arguments) {
43 EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
44 if (action) {
45 bool ok = action->updateArguments(arguments);
46 if (ok) {
47 ownerEntity->addAction(simulation, action);
48 return action;
49 }
45 }50 }
51 return action;
52}
53
54
55EntityActionPointer InterfaceActionFactory::factoryBA(EntitySimulation* simulation,
56 EntityItemPointer ownerEntity,
57 QByteArray data) {
58 QDataStream ds(data);
59 EntityActionType type;
60 QUuid id;
61
62 ds >> type;
63 ds >> id;
64
65 EntityActionPointer action = interfaceActionFactory(type, id, ownerEntity);
46 66
47 action = nullptr;67 action->deserializeFromDataStream(ds);
68 ownerEntity->addAction(simulation, action);
48 return action;69 return action;
49}70}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t