Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / demo.cpp
blob5464398bc294b218f9acfa55e74359ee87670db3
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 /////////////
20 // INCLUDE //
21 /////////////
22 #include "stdpch.h"
23 // Client
24 #include "demo.h"
25 #include "entities.h"
26 #include "client_cfg.h"
27 #include "ingame_database_manager.h"
28 #include "user_entity.h"
29 #include "time_client.h"
30 #include "net_manager.h"
31 // MISC
32 #include "nel/misc/sheet_id.h"
35 ///////////
36 // USING //
37 ///////////
38 using namespace NLMISC;
39 using namespace std;
41 ////////////
42 // GLOBAL //
43 ////////////
45 // Hierarchical timer
46 H_AUTO_DECL ( RZ_Client_Update_Demo )
48 ///////////////
49 // FUNCTIONS //
50 ///////////////
51 //-----------------------------------------------
52 // initDemo :
53 // Call a function for a demo to init.
54 //-----------------------------------------------
55 void initDemo()
57 for(uint i = 0; i<ClientCfg.StartCommands.size()/7; ++i)
59 ////////////
60 // CREATE //
61 ////////////
62 // Which slot to use.
63 CLFECOMMON::TCLEntityId entitySlot = i+1;
65 // Try to create the sheet with the parameter as a string.
66 CSheetId sheetId;
67 if(!sheetId.buildSheetId(ClientCfg.StartCommands[i*7]))
69 nlwarning("initDemo: cannot create the entity %d '%s'.", i*7, ClientCfg.StartCommands[i*7].c_str());
70 continue;
73 // Remove the old entity.
74 EntitiesMngr.remove(entitySlot, false);
76 // Create the new entity.
77 TNewEntityInfo emptyEntityInfo;
78 emptyEntityInfo.reset();
79 CEntityCL *entity = EntitiesMngr.create(entitySlot, sheetId.asInt(), emptyEntityInfo);
80 if(entity)
82 double xTmp, yTmp, zTmp;
83 fromString(ClientCfg.StartCommands[i*7+1], xTmp);
84 fromString(ClientCfg.StartCommands[i*7+2], yTmp);
85 fromString(ClientCfg.StartCommands[i*7+3], zTmp);
87 // Compute the position (FIRST POS AFTER CREATE IS THE START POSITION).
88 sint64 x = (sint64)(xTmp*1000.0);
89 sint64 y = (sint64)(yTmp*1000.0);
90 sint64 z = (sint64)(zTmp*1000.0);
92 // Write the position in the DB.
93 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P0", x);
94 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P1", y);
95 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P2", z);
97 // Update the position.
98 uint gameCycle = NetMngr.getCurrentClientTick();
99 uint prop = 0; // 0: Position ; 3: orientation ; 4: mode ; 5: behaviour ; 6: nameId ; 7: target ; 8: visual1 ; 9: visual2
100 EntitiesMngr.updateVisualProperty(gameCycle, entitySlot, prop);
102 // Set the direction
103 float xTmp2, yTmp2, zTmp2;
104 fromString(ClientCfg.StartCommands[i*7+4], xTmp2);
105 fromString(ClientCfg.StartCommands[i*7+5], yTmp2);
106 fromString(ClientCfg.StartCommands[i*7+6], zTmp2);
107 entity->front(CVector(xTmp2, yTmp2, zTmp2));
108 entity->dir(UserEntity->front());
111 //////////
112 // MOVE //
113 //////////
114 gameCycle = NetMngr.getCurrentClientTick()+100; // 10sec later.
115 x = (sint64)((entity->pos().x+UserEntity->front().x*50.0)*1000.0);
116 y = (sint64)((entity->pos().y+UserEntity->front().y*50.0)*1000.0);
117 z = (sint64)((entity->pos().z+UserEntity->front().z*50.0)*1000.0);
118 // Write the position in the DB.
119 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P0", x);
120 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P1", y);
121 IngameDbMngr.setProp("Entities:E" + toString(entitySlot) + ":P2", z);
122 // Update the position.
123 EntitiesMngr.updateVisualProperty(gameCycle, entitySlot, prop);
126 else
127 nldebug("initDemo: entity(%s) in slot %d cannot be created.", sheetId.toString().c_str(), entitySlot);
129 }// initDemo //
131 //-----------------------------------------------
132 // updateDemo :
133 // Call a function for a demo to update.
134 //-----------------------------------------------
135 void updateDemo(double /* timeElapsed */)
137 H_AUTO_USE ( RZ_Client_Update_Demo )
138 }// updateDemo //