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
1818 #include "InterfaceActionFactory.h"
1919
2020
21−EntityActionPointer InterfaceActionFactory::factory(EntitySimulation* simulation,
22− EntityActionType type,
23− QUuid id,
24− EntityItemPointer ownerEntity,
25− QVariantMap arguments) {
26− EntityActionPointer action = nullptr;
21+EntityActionPointer interfaceActionFactory(EntityActionType type, QUuid id, EntityItemPointer ownerEntity) {
2722 switch (type) {
2823 case ACTION_TYPE_NONE:
2924 return nullptr;
3025 case ACTION_TYPE_OFFSET:
31− action = (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
32− break;
26+ return (EntityActionPointer) new ObjectActionOffset(id, ownerEntity);
3327 case ACTION_TYPE_SPRING:
34− action = (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
35− break;
28+ return (EntityActionPointer) new ObjectActionSpring(id, ownerEntity);
3629 case ACTION_TYPE_HOLD:
37− action = (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
38− break;
30+ return (EntityActionPointer) new AvatarActionHold(id, ownerEntity);
3931 }
4032
41− bool ok = action->updateArguments(arguments);
42− if (ok) {
43− ownerEntity->addAction(simulation, action);
44− return action;
33+ assert(false);
34+ return nullptr;
35+}
36+
37+
38+EntityActionPointer 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+ }
4550 }
51+ return action;
52+}
53+
54+
55+EntityActionPointer 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);
4666
47− action = nullptr;
67+ action->deserializeFromDataStream(ds);
68+ ownerEntity->addAction(simulation, action);
4869 return action;
4970 }

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